(
functionRef: string,
key: string,
effectConfig: JsonValue
)
| 1250 | }, |
| 1251 | |
| 1252 | createEffect( |
| 1253 | functionRef: string, |
| 1254 | key: string, |
| 1255 | effectConfig: JsonValue |
| 1256 | ): boolean { |
| 1257 | const manifestKey = manifestEffectKey(functionRef, key) |
| 1258 | const created = wakeSession.registerManifestEntry({ |
| 1259 | kind: `effect`, |
| 1260 | key: manifestKey, |
| 1261 | id: key, |
| 1262 | function_ref: functionRef, |
| 1263 | config: effectConfig, |
| 1264 | }) |
| 1265 | if (!created) return false |
| 1266 | |
| 1267 | if (!inSetup) { |
| 1268 | const effects = (definition as Record<string, unknown> | undefined) |
| 1269 | ?.effects as |
| 1270 | | Record< |
| 1271 | string, |
| 1272 | ( |
| 1273 | ctx: unknown, |
| 1274 | config: JsonValue |
| 1275 | ) => EffectConfig | Promise<EffectConfig> |
| 1276 | > |
| 1277 | | undefined |
| 1278 | const effectFactory = effects?.[functionRef] |
| 1279 | if (!effectFactory) { |
| 1280 | throw new Error( |
| 1281 | `[agent-runtime] Unknown effect '${functionRef}'. Was it removed from the definition?` |
| 1282 | ) |
| 1283 | } |
| 1284 | const factoryResult = effectFactory(ctx_ref, effectConfig) |
| 1285 | const registerEffect = (ec: EffectConfig) => |
| 1286 | effectScope.register(manifestKey, ec) |
| 1287 | if (factoryResult instanceof Promise) { |
| 1288 | factoryResult.then(registerEffect) |
| 1289 | } else { |
| 1290 | registerEffect(factoryResult) |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | return true |
| 1295 | }, |
| 1296 | |
| 1297 | mkdb<TSchema extends SharedStateSchemaMap>( |
| 1298 | id: string, |
no test coverage detected