@ekairos/events 1.22.35-beta.development.0 → 1.22.37-beta.development.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -69,7 +69,11 @@ export interface ContextStreamOptions {
69
69
  */
70
70
  export type ContextModelInit = string | (() => Promise<any>);
71
71
  export type ContextReactParams<Env extends ContextEnvironment = ContextEnvironment> = {
72
- runtime: ContextRuntime<Env>;
72
+ runtime?: ContextRuntime<Env>;
73
+ /**
74
+ * Backward-compatible runtime selector. New callers should pass `runtime`.
75
+ */
76
+ env?: Env;
73
77
  /**
74
78
  * Context selector (exclusive: `{ id }` OR `{ key }`).
75
79
  * - `{ id }` resolves a concrete context id.
@@ -11,6 +11,30 @@ import { getContextDurableWorkflow } from "./context.durable.js";
11
11
  export async function runContextReactionDirect(context, triggerEvent, params) {
12
12
  return await ContextEngine.runDirect(context, triggerEvent, params);
13
13
  }
14
+ async function legacyRuntimeFromEnv(env) {
15
+ const { getContextRuntime } = await import("./runtime.step.js");
16
+ const legacy = (await getContextRuntime(env));
17
+ return {
18
+ env,
19
+ db: async () => legacy.db,
20
+ resolve: async () => ({
21
+ db: legacy.db,
22
+ meta: () => ({
23
+ domain: legacy.domain,
24
+ }),
25
+ }),
26
+ meta: () => ({
27
+ domain: legacy.domain,
28
+ }),
29
+ };
30
+ }
31
+ async function resolveReactRuntime(params) {
32
+ if (params.runtime)
33
+ return params.runtime;
34
+ if (params.env)
35
+ return await legacyRuntimeFromEnv(params.env);
36
+ throw new Error("ContextEngine.react requires either runtime or env.");
37
+ }
14
38
  export { toolApprovalHookToken, toolApprovalWebhookToken, getClientResumeHookUrl };
15
39
  function nowIso() {
16
40
  return new Date().toISOString();
@@ -330,8 +354,9 @@ export class ContextEngine {
330
354
  return await ContextEngine.runDirect(this, triggerEvent, params);
331
355
  }
332
356
  static async prepareExecutionShell(story, triggerEvent, params) {
333
- const env = params.runtime.env;
334
- const ops = await measureBenchmark(params.__benchmark, "react.resolveOpsMs", async () => await getContextEngineOps(params.runtime, params.__benchmark));
357
+ const runtimeHandle = await resolveReactRuntime(params);
358
+ const env = runtimeHandle.env;
359
+ const ops = await measureBenchmark(params.__benchmark, "react.resolveOpsMs", async () => await getContextEngineOps(runtimeHandle, params.__benchmark));
335
360
  const silent = params.options?.silent ?? false;
336
361
  const ctxResult = await measureBenchmark(params.__benchmark, "react.initializeContextMs", async () => await ops.initializeContext(params.context ?? null, { silent }));
337
362
  let currentContext = ctxResult.context;
@@ -357,7 +382,8 @@ export class ContextEngine {
357
382
  };
358
383
  }
359
384
  static async startDurable(story, triggerEvent, params) {
360
- const env = params.runtime.env;
385
+ const runtimeHandle = await resolveReactRuntime(params);
386
+ const env = runtimeHandle.env;
361
387
  if (params.options?.writable) {
362
388
  throw new Error("ContextEngine.react: durable runs manage their own workflow stream");
363
389
  }
@@ -378,7 +404,7 @@ export class ContextEngine {
378
404
  const startedRun = await start(workflow, [
379
405
  {
380
406
  contextKey,
381
- runtime: params.runtime,
407
+ runtime: runtimeHandle,
382
408
  context: params.context ?? null,
383
409
  triggerEvent,
384
410
  options: {
@@ -401,7 +427,7 @@ export class ContextEngine {
401
427
  status: startedRun.status,
402
428
  returnValue: startedRun.returnValue,
403
429
  };
404
- const runtime = await createRuntimeOps(params.runtime);
430
+ const runtime = await createRuntimeOps(runtimeHandle);
405
431
  await runtime.db.transact([
406
432
  runtime.db.tx.event_executions[shell.execution.id].update({
407
433
  workflowRunId: startedRun.runId,
@@ -410,7 +436,7 @@ export class ContextEngine {
410
436
  ]);
411
437
  }
412
438
  catch (error) {
413
- const ops = await getContextEngineOps(params.runtime, params.__benchmark);
439
+ const ops = await getContextEngineOps(runtimeHandle, params.__benchmark);
414
440
  await ops.completeExecution(shell.contextSelector, shell.execution.id, "failed").catch(() => null);
415
441
  throw error;
416
442
  }
@@ -423,8 +449,9 @@ export class ContextEngine {
423
449
  };
424
450
  }
425
451
  static async runDirect(story, triggerEvent, params) {
426
- const env = params.runtime.env;
427
- const ops = await measureBenchmark(params.__benchmark, "react.resolveOpsMs", async () => await getContextEngineOps(params.runtime, params.__benchmark));
452
+ const runtimeHandle = await resolveReactRuntime(params);
453
+ const env = runtimeHandle.env;
454
+ const ops = await measureBenchmark(params.__benchmark, "react.resolveOpsMs", async () => await getContextEngineOps(runtimeHandle, params.__benchmark));
428
455
  const maxIterations = params.options?.maxIterations ?? 20;
429
456
  const maxModelSteps = params.options?.maxModelSteps ?? 1;
430
457
  const preventClose = params.options?.preventClose ?? false;
@@ -499,7 +526,7 @@ export class ContextEngine {
499
526
  }));
500
527
  currentStepId = stepCreate.stepId;
501
528
  currentStepStream = await createPersistedContextStepStream({
502
- runtime: params.runtime,
529
+ runtime: runtimeHandle,
503
530
  executionId,
504
531
  stepId: stepCreate.stepId,
505
532
  });
@@ -575,7 +602,7 @@ export class ContextEngine {
575
602
  }, { executionId, contextId: String(currentContext.id) });
576
603
  };
577
604
  const reactionResult = await measureBenchmark(params.__benchmark, `${stagePrefix}.reactorMs`, async () => await reactor({
578
- runtime: params.runtime,
605
+ runtime: runtimeHandle,
579
606
  env,
580
607
  context: updatedContext,
581
608
  contextIdentifier: activeContextSelector,
@@ -673,7 +700,7 @@ export class ContextEngine {
673
700
  }
674
701
  if (currentStepStream) {
675
702
  await closePersistedContextStepStream({
676
- runtime: params.runtime,
703
+ runtime: runtimeHandle,
677
704
  session: currentStepStream,
678
705
  });
679
706
  currentStepStream = null;
@@ -853,7 +880,7 @@ export class ContextEngine {
853
880
  }
854
881
  }
855
882
  const output = await toolDef.execute(actionInput, {
856
- runtime: params.runtime,
883
+ runtime: runtimeHandle,
857
884
  env,
858
885
  context: updatedContext,
859
886
  contextIdentifier: activeContextSelector,
@@ -1060,7 +1087,7 @@ export class ContextEngine {
1060
1087
  if (currentStepStream) {
1061
1088
  try {
1062
1089
  await abortPersistedContextStepStream({
1063
- runtime: params.runtime,
1090
+ runtime: runtimeHandle,
1064
1091
  session: currentStepStream,
1065
1092
  reason: error instanceof Error ? error.message : String(error),
1066
1093
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekairos/events",
3
- "version": "1.22.35-beta.development.0",
3
+ "version": "1.22.37-beta.development.0",
4
4
  "description": "Ekairos Events - Context-first workflow runtime",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -117,7 +117,7 @@
117
117
  },
118
118
  "dependencies": {
119
119
  "@ai-sdk/openai": "^2.0.52",
120
- "@ekairos/domain": "^1.22.35-beta.development.0",
120
+ "@ekairos/domain": "^1.22.37-beta.development.0",
121
121
  "@instantdb/admin": "0.22.158",
122
122
  "@instantdb/core": "0.22.142",
123
123
  "@vercel/mcp-adapter": "^1.0.0",