@ekairos/events 1.22.37-beta.development.0 → 1.22.39-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.
@@ -5,7 +5,7 @@ import { isContextPartEnvelope, normalizePartsForPersistence, } from "./context.
5
5
  import { actionsToActionSpecs } from "./tools-to-model-tools.js";
6
6
  import { createAiSdkReactor, } from "./context.reactor.js";
7
7
  import { abortPersistedContextStepStream, closePersistedContextStepStream, createPersistedContextStepStream, closeContextStream, } from "./steps/stream.steps.js";
8
- import { completeExecution, createContextStep, initializeContext, saveTriggerAndCreateExecution, saveContextPartsStep, updateContextContent, updateContextReactor, updateContextStatus, updateItem, updateContextStep, } from "./steps/store.steps.js";
8
+ import { completeExecution, createContextStep, getContextItems, initializeContext, saveTriggerAndCreateExecution, saveContextPartsStep, updateContextContent, updateContextReactor, updateContextStatus, updateItem, updateContextStep, } from "./steps/store.steps.js";
9
9
  import { getClientResumeHookUrl, toolApprovalHookToken, toolApprovalWebhookToken, } from "./context.hooks.js";
10
10
  import { getContextDurableWorkflow } from "./context.durable.js";
11
11
  export async function runContextReactionDirect(context, triggerEvent, params) {
@@ -257,6 +257,7 @@ async function createRuntimeOps(runtimeHandle, benchmark) {
257
257
  saveContextPartsStep: async (params) => {
258
258
  await store.saveStepParts({ stepId: params.stepId, parts: params.parts });
259
259
  },
260
+ getItems: async (contextIdentifier) => await store.getItems(contextIdentifier),
260
261
  updateItem: async (itemId, item) => {
261
262
  await instrumentedDb.transact([instrumentedDb.tx.event_items[itemId].update(item)]);
262
263
  return {
@@ -290,6 +291,7 @@ async function createWorkflowOps(runtime) {
290
291
  createContextStep: async ({ executionId, iteration }) => await createContextStep({ runtime, executionId, iteration }),
291
292
  updateContextStep: async (params) => await updateContextStep({ runtime, ...params }),
292
293
  saveContextPartsStep: async (params) => await saveContextPartsStep({ runtime, ...params }),
294
+ getItems: async (contextIdentifier) => await getContextItems({ runtime, contextIdentifier }),
293
295
  updateItem: async (itemId, item, opts) => await updateItem({ runtime, eventId: itemId, event: item, opts }),
294
296
  completeExecution: async (contextIdentifier, executionId, status) => await completeExecution({ runtime, contextIdentifier, executionId, status }),
295
297
  };
@@ -564,6 +566,8 @@ export class ContextEngine {
564
566
  // Hook: Context DSL `actions()` (implemented by subclasses via `buildTools()`)
565
567
  const toolsAll = await measureBenchmark(params.__benchmark, `${stagePrefix}.actionsMs`, async () => await story.buildTools(updatedContext, env));
566
568
  const skillsAll = await measureBenchmark(params.__benchmark, `${stagePrefix}.skillsMs`, async () => await story.buildSkills(updatedContext, env));
569
+ const rawEvents = await measureBenchmark(params.__benchmark, `${stagePrefix}.loadEventsMs`, async () => await ops.getItems(activeContextSelector));
570
+ const expandedEvents = await measureBenchmark(params.__benchmark, `${stagePrefix}.expandEventsMs`, async () => await story.expandEvents(rawEvents, updatedContext, env));
567
571
  // IMPORTANT: step args must be serializable.
568
572
  // Match DurableAgent behavior: convert tool input schemas to plain JSON Schema in workflow context.
569
573
  const actionSpecs = actionsToActionSpecs(toolsAll);
@@ -606,6 +610,7 @@ export class ContextEngine {
606
610
  env,
607
611
  context: updatedContext,
608
612
  contextIdentifier: activeContextSelector,
613
+ events: expandedEvents,
609
614
  triggerEvent,
610
615
  model: story.getModel(updatedContext, env),
611
616
  systemPrompt,
@@ -879,20 +884,21 @@ export class ContextEngine {
879
884
  actionInput = approval.args;
880
885
  }
881
886
  }
882
- const output = await toolDef.execute(actionInput, {
883
- runtime: runtimeHandle,
884
- env,
885
- context: updatedContext,
886
- contextIdentifier: activeContextSelector,
887
- toolCallId: actionRequest.actionRef,
888
- messages: messagesForModel,
889
- eventId: reactionEventId,
890
- executionId,
891
- triggerEventId,
892
- contextId: currentContext.id,
893
- stepId: String(stepCreate.stepId),
894
- iteration: iter,
895
- });
887
+ const executeAction = toolDef.execute;
888
+ const output = await Reflect.apply(executeAction, undefined, [actionInput, {
889
+ runtime: runtimeHandle,
890
+ env,
891
+ context: updatedContext,
892
+ contextIdentifier: activeContextSelector,
893
+ toolCallId: actionRequest.actionRef,
894
+ messages: messagesForModel,
895
+ eventId: reactionEventId,
896
+ executionId,
897
+ triggerEventId,
898
+ contextId: currentContext.id,
899
+ stepId: String(stepCreate.stepId),
900
+ iteration: iter,
901
+ }]);
896
902
  return { actionRequest, success: true, output };
897
903
  }
898
904
  catch (e) {
@@ -41,6 +41,7 @@ export function createAiSdkReactor(options) {
41
41
  runtime: params.runtime,
42
42
  env: params.env,
43
43
  contextIdentifier: params.contextIdentifier,
44
+ events: params.events,
44
45
  model,
45
46
  system: params.systemPrompt,
46
47
  tools: params.actionSpecs,
@@ -17,6 +17,7 @@ export declare function executeAiSdkReaction(params: {
17
17
  runtime: import("../context.runtime.js").ContextRuntime<ContextEnvironment>;
18
18
  env: ContextEnvironment;
19
19
  contextIdentifier: ContextIdentifier;
20
+ events?: ContextItem[];
20
21
  model: ContextModelInit;
21
22
  system: string;
22
23
  tools: Record<string, SerializableActionSpec>;
@@ -85,13 +85,15 @@ function safeErrorJson(error) {
85
85
  export async function executeAiSdkReaction(params) {
86
86
  "use step";
87
87
  const { store } = await getContextRuntimeServices(params.runtime);
88
- let events;
89
- try {
90
- events = await store.getItems(params.contextIdentifier);
91
- }
92
- catch (error) {
93
- console.error("[ekairos/story] ai-sdk.step store.getItems failed");
94
- throw error;
88
+ let events = Array.isArray(params.events) ? params.events : [];
89
+ if (events.length === 0) {
90
+ try {
91
+ events = await store.getItems(params.contextIdentifier);
92
+ }
93
+ catch (error) {
94
+ console.error("[ekairos/story] ai-sdk.step store.getItems failed");
95
+ throw error;
96
+ }
95
97
  }
96
98
  let messagesForModel;
97
99
  try {
@@ -37,6 +37,15 @@ export type ContextReactorParams<Context = unknown, Env extends ContextEnvironme
37
37
  env: Env;
38
38
  context: StoredContext<Context>;
39
39
  contextIdentifier: ContextIdentifier;
40
+ /**
41
+ * Context items after the engine-level expansion stage.
42
+ *
43
+ * Reactors should prefer these over fetching raw items when constructing
44
+ * model/runtime input. Expanders must return regular ContextItems whose
45
+ * parts follow the shared context part contract, so this is not tied to any
46
+ * specific model provider.
47
+ */
48
+ events: ContextItem[];
40
49
  triggerEvent: ContextItem;
41
50
  model: ContextModelInit;
42
51
  systemPrompt: string;
@@ -61,6 +61,9 @@ export declare function saveReactionItem(params: RuntimeParams & {
61
61
  reviewRequests?: ContextReviewRequest[];
62
62
  };
63
63
  }): Promise<ContextItem>;
64
+ export declare function getContextItems(params: RuntimeParams & {
65
+ contextIdentifier: ContextIdentifier;
66
+ }): Promise<ContextItem[]>;
64
67
  export declare function updateItem(params: RuntimeParams & {
65
68
  eventId: string;
66
69
  event: ContextItem;
@@ -417,6 +417,11 @@ export async function saveReactionItem(params) {
417
417
  }
418
418
  return saved;
419
419
  }
420
+ export async function getContextItems(params) {
421
+ "use step";
422
+ const { runtime } = await getRuntimeAndEnv(params);
423
+ return await runtime.store.getItems(params.contextIdentifier);
424
+ }
420
425
  export async function updateItem(params) {
421
426
  "use step";
422
427
  const { runtime, env } = await getRuntimeAndEnv(params);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekairos/events",
3
- "version": "1.22.37-beta.development.0",
3
+ "version": "1.22.39-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.37-beta.development.0",
120
+ "@ekairos/domain": "^1.22.39-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",
@@ -139,7 +139,7 @@
139
139
  "@types/node": "^24.5.0",
140
140
  "@types/react": "^19.2.2",
141
141
  "dotenv": "^17.2.3",
142
- "vitest": "^3.2.4",
142
+ "vitest": "^4.0.8",
143
143
  "typescript": "^5.9.2"
144
144
  }
145
145
  }