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

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.
Files changed (73) hide show
  1. package/README.md +5 -3
  2. package/dist/codex.d.ts +11 -2
  3. package/dist/codex.js +16 -8
  4. package/dist/context.action-calls.d.ts +48 -0
  5. package/dist/context.action-calls.js +123 -0
  6. package/dist/context.action.d.ts +55 -0
  7. package/dist/context.action.js +25 -0
  8. package/dist/context.builder.d.ts +71 -43
  9. package/dist/context.builder.js +123 -28
  10. package/dist/context.config.d.ts +2 -1
  11. package/dist/context.config.js +8 -3
  12. package/dist/context.contract.d.ts +2 -4
  13. package/dist/context.contract.js +3 -9
  14. package/dist/context.d.ts +3 -2
  15. package/dist/context.engine.d.ts +60 -52
  16. package/dist/context.engine.js +506 -297
  17. package/dist/context.events.js +28 -87
  18. package/dist/context.js +1 -0
  19. package/dist/context.part-identity.d.ts +40 -0
  20. package/dist/context.part-identity.js +270 -0
  21. package/dist/context.parts.d.ts +389 -164
  22. package/dist/context.parts.js +343 -218
  23. package/dist/context.registry.d.ts +1 -1
  24. package/dist/context.runtime.d.ts +14 -4
  25. package/dist/context.runtime.js +21 -3
  26. package/dist/context.step-stream.d.ts +16 -2
  27. package/dist/context.step-stream.js +58 -16
  28. package/dist/context.store.d.ts +55 -10
  29. package/dist/context.stream.d.ts +14 -4
  30. package/dist/context.stream.js +31 -3
  31. package/dist/domain.d.ts +1 -0
  32. package/dist/domain.js +1 -0
  33. package/dist/index.d.ts +13 -10
  34. package/dist/index.js +7 -6
  35. package/dist/react.context-event-parts.d.ts +18 -0
  36. package/dist/react.context-event-parts.js +509 -0
  37. package/dist/react.d.ts +7 -42
  38. package/dist/react.js +4 -87
  39. package/dist/react.step-stream.d.ts +39 -0
  40. package/dist/react.step-stream.js +625 -0
  41. package/dist/react.types.d.ts +121 -0
  42. package/dist/react.types.js +2 -0
  43. package/dist/react.use-context.d.ts +7 -0
  44. package/dist/react.use-context.js +867 -0
  45. package/dist/reactors/ai-sdk.chunk-map.d.ts +1 -0
  46. package/dist/reactors/ai-sdk.chunk-map.js +56 -5
  47. package/dist/reactors/ai-sdk.reactor.d.ts +8 -9
  48. package/dist/reactors/ai-sdk.reactor.js +6 -9
  49. package/dist/reactors/ai-sdk.step.d.ts +4 -5
  50. package/dist/reactors/ai-sdk.step.js +24 -17
  51. package/dist/reactors/scripted.reactor.d.ts +7 -4
  52. package/dist/reactors/types.d.ts +19 -10
  53. package/dist/runtime.d.ts +6 -0
  54. package/dist/runtime.js +9 -0
  55. package/dist/runtime.step.js +1 -1
  56. package/dist/schema.d.ts +268 -2
  57. package/dist/schema.js +4 -9
  58. package/dist/steps/do-context-stream-step.js +4 -4
  59. package/dist/steps/durable.steps.d.ts +28 -0
  60. package/dist/steps/durable.steps.js +34 -0
  61. package/dist/steps/store.steps.d.ts +64 -22
  62. package/dist/steps/store.steps.js +192 -35
  63. package/dist/steps/stream.steps.d.ts +32 -0
  64. package/dist/steps/stream.steps.js +124 -6
  65. package/dist/steps/trace.steps.d.ts +4 -4
  66. package/dist/steps/trace.steps.js +21 -6
  67. package/dist/stores/instant.store.d.ts +11 -11
  68. package/dist/stores/instant.store.js +136 -6
  69. package/dist/tools-to-model-tools.d.ts +4 -2
  70. package/dist/tools-to-model-tools.js +30 -11
  71. package/package.json +18 -7
  72. package/dist/context.toolcalls.d.ts +0 -60
  73. package/dist/context.toolcalls.js +0 -117
@@ -8,5 +8,6 @@ export type MapAiSdkChunkToContextEventParams = {
8
8
  itemId?: string;
9
9
  provider?: string;
10
10
  sequence: number;
11
+ actionNameByRef?: Map<string, string>;
11
12
  };
12
13
  export declare function mapAiSdkChunkToContextEvent(params: MapAiSdkChunkToContextEventParams): ChunkEmittedEvent;
@@ -1,3 +1,4 @@
1
+ import { resolveContextPartChunkIdentity } from "../context.part-identity.js";
1
2
  const REDACT_KEY = /token|authorization|cookie|secret|api[_-]?key|password/i;
2
3
  function asRecord(value) {
3
4
  if (!value || typeof value !== "object")
@@ -64,7 +65,7 @@ function mapAiSdkChunkType(providerChunkType) {
64
65
  return "chunk.reasoning_end";
65
66
  case "tool-input-start":
66
67
  case "tool-call-start":
67
- return "chunk.action_input_start";
68
+ return "chunk.action_started";
68
69
  case "tool-input-delta":
69
70
  case "tool-call-delta":
70
71
  return "chunk.action_input_delta";
@@ -72,11 +73,11 @@ function mapAiSdkChunkType(providerChunkType) {
72
73
  case "tool-input-end":
73
74
  case "tool-call":
74
75
  case "tool-call-end":
75
- return "chunk.action_input_available";
76
+ return "chunk.action_started";
76
77
  case "tool-output-available":
77
- return "chunk.action_output_available";
78
+ return "chunk.action_completed";
78
79
  case "tool-output-error":
79
- return "chunk.action_output_error";
80
+ return "chunk.action_failed";
80
81
  case "source-url":
81
82
  return "chunk.source_url";
82
83
  case "source-document":
@@ -99,9 +100,15 @@ function buildNormalizedData(chunk) {
99
100
  "id",
100
101
  "text",
101
102
  "delta",
103
+ "inputTextDelta",
104
+ "outputTextDelta",
102
105
  "state",
106
+ "actionName",
103
107
  "toolName",
104
108
  "toolCallId",
109
+ "input",
110
+ "output",
111
+ "error",
105
112
  "finishReason",
106
113
  "url",
107
114
  "title",
@@ -119,12 +126,52 @@ function buildNormalizedData(chunk) {
119
126
  }
120
127
  return toJsonSafe(normalized) ?? {};
121
128
  }
129
+ function readProviderPartId(chunk, chunkType) {
130
+ if (chunkType.startsWith("chunk.action_")) {
131
+ return readString(chunk, "toolCallId") ?? readString(chunk, "id");
132
+ }
133
+ if (chunkType.startsWith("chunk.text_") || chunkType.startsWith("chunk.reasoning_")) {
134
+ return readString(chunk, "id");
135
+ }
136
+ if (chunkType.startsWith("chunk.source_")) {
137
+ return readString(chunk, "sourceId");
138
+ }
139
+ if (chunkType === "chunk.file") {
140
+ return readString(chunk, "id") ?? readString(chunk, "url");
141
+ }
142
+ return undefined;
143
+ }
122
144
  export function mapAiSdkChunkToContextEvent(params) {
123
145
  const chunk = asRecord(params.chunk);
124
146
  const providerChunkType = readString(chunk, "type") ?? "unknown";
125
147
  const chunkType = mapAiSdkChunkType(providerChunkType);
148
+ const providerPartId = readProviderPartId(chunk, chunkType);
149
+ const identity = resolveContextPartChunkIdentity({
150
+ stepId: params.stepId,
151
+ provider: params.provider ?? "ai-sdk",
152
+ providerPartId,
153
+ chunkType,
154
+ });
126
155
  const actionRef = readString(chunk, "toolCallId") ??
127
156
  readString(chunk, "id");
157
+ let data = buildNormalizedData(chunk);
158
+ if (chunkType.startsWith("chunk.action_") && actionRef) {
159
+ const observedActionName = readString(chunk, "actionName") ??
160
+ readString(chunk, "toolName") ??
161
+ readString(data, "actionName") ??
162
+ readString(data, "toolName");
163
+ if (observedActionName) {
164
+ params.actionNameByRef?.set(actionRef, observedActionName);
165
+ }
166
+ const knownActionName = observedActionName ?? params.actionNameByRef?.get(actionRef);
167
+ if (knownActionName) {
168
+ data = {
169
+ ...data,
170
+ actionName: readString(data, "actionName") ?? knownActionName,
171
+ toolName: readString(data, "toolName") ?? knownActionName,
172
+ };
173
+ }
174
+ }
128
175
  return {
129
176
  type: "chunk.emitted",
130
177
  at: new Date().toISOString(),
@@ -133,11 +180,15 @@ export function mapAiSdkChunkToContextEvent(params) {
133
180
  executionId: params.executionId,
134
181
  stepId: params.stepId,
135
182
  itemId: params.itemId,
183
+ partId: identity?.partId,
184
+ providerPartId: identity?.providerPartId,
185
+ partType: identity?.partType,
186
+ partSlot: identity?.partSlot,
136
187
  actionRef: chunkType.startsWith("chunk.action_") ? actionRef : undefined,
137
188
  provider: params.provider,
138
189
  providerChunkType,
139
190
  sequence: params.sequence,
140
- data: buildNormalizedData(chunk),
191
+ data,
141
192
  raw: sanitizeRaw(chunk),
142
193
  };
143
194
  }
@@ -1,12 +1,13 @@
1
1
  import type { ContextEnvironment } from "../context.config.js";
2
- import type { ContextRuntime } from "../context.runtime.js";
2
+ import type { DomainLike } from "@ekairos/domain";
3
+ import type { ContextRuntime, ContextRuntimeHandleForDomain } from "../context.runtime.js";
3
4
  import type { ContextModelInit } from "../context.engine.js";
4
5
  import type { ContextIdentifier, StoredContext, ContextItem } from "../context.store.js";
6
+ import { eventsDomain } from "../schema.js";
5
7
  import type { ContextReactor } from "./types.js";
6
- export type CreateAiSdkReactorOptions<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, Config = unknown> = {
8
+ export type CreateAiSdkReactorOptions<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>, Config = unknown> = {
7
9
  resolveConfig?: (params: {
8
- runtime: ContextRuntime<Env>;
9
- env: Env;
10
+ runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>;
10
11
  context: StoredContext<Context>;
11
12
  contextIdentifier: ContextIdentifier;
12
13
  triggerEvent: ContextItem;
@@ -18,20 +19,18 @@ export type CreateAiSdkReactorOptions<Context = unknown, Env extends ContextEnvi
18
19
  iteration: number;
19
20
  }) => Promise<Config> | Config;
20
21
  selectModel?: (params: {
21
- runtime: ContextRuntime<Env>;
22
- env: Env;
22
+ runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>;
23
23
  context: StoredContext<Context>;
24
24
  triggerEvent: ContextItem;
25
25
  baseModel: ContextModelInit;
26
26
  config: Config;
27
27
  }) => Promise<ContextModelInit> | ContextModelInit;
28
28
  selectMaxModelSteps?: (params: {
29
- runtime: ContextRuntime<Env>;
30
- env: Env;
29
+ runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>;
31
30
  context: StoredContext<Context>;
32
31
  triggerEvent: ContextItem;
33
32
  baseMaxModelSteps: number;
34
33
  config: Config;
35
34
  }) => Promise<number> | number;
36
35
  };
37
- export declare function createAiSdkReactor<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, Config = unknown>(options?: CreateAiSdkReactorOptions<Context, Env, Config>): ContextReactor<Context, Env>;
36
+ export declare function createAiSdkReactor<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>, Config = unknown>(options?: CreateAiSdkReactorOptions<Context, Env, RequiredDomain, Runtime, Config>): ContextReactor<Context, Env, RequiredDomain, Runtime>;
@@ -1,11 +1,11 @@
1
1
  import { executeAiSdkReaction } from "./ai-sdk.step.js";
2
+ import { actionsToActionSpecs } from "../tools-to-model-tools.js";
2
3
  export function createAiSdkReactor(options) {
3
4
  return async (params) => {
4
5
  let config;
5
6
  if (options?.resolveConfig) {
6
7
  config = await options.resolveConfig({
7
8
  runtime: params.runtime,
8
- env: params.env,
9
9
  context: params.context,
10
10
  contextIdentifier: params.contextIdentifier,
11
11
  triggerEvent: params.triggerEvent,
@@ -20,7 +20,6 @@ export function createAiSdkReactor(options) {
20
20
  const model = options?.selectModel && config !== undefined
21
21
  ? await options.selectModel({
22
22
  runtime: params.runtime,
23
- env: params.env,
24
23
  context: params.context,
25
24
  triggerEvent: params.triggerEvent,
26
25
  baseModel: params.model,
@@ -30,7 +29,6 @@ export function createAiSdkReactor(options) {
30
29
  const maxSteps = options?.selectMaxModelSteps && config !== undefined
31
30
  ? await options.selectMaxModelSteps({
32
31
  runtime: params.runtime,
33
- env: params.env,
34
32
  context: params.context,
35
33
  triggerEvent: params.triggerEvent,
36
34
  baseMaxModelSteps: params.maxModelSteps,
@@ -39,16 +37,15 @@ export function createAiSdkReactor(options) {
39
37
  : params.maxModelSteps;
40
38
  const result = await executeAiSdkReaction({
41
39
  runtime: params.runtime,
42
- env: params.env,
43
40
  contextIdentifier: params.contextIdentifier,
41
+ events: params.events,
44
42
  model,
45
43
  system: params.systemPrompt,
46
- tools: params.actionSpecs,
44
+ tools: actionsToActionSpecs(params.actions),
47
45
  eventId: params.eventId,
48
46
  iteration: params.iteration,
49
47
  maxSteps,
50
48
  sendStart: params.sendStart,
51
- silent: params.silent,
52
49
  contextStepStream: params.contextStepStream,
53
50
  writable: params.writable,
54
51
  executionId: params.executionId,
@@ -57,9 +54,9 @@ export function createAiSdkReactor(options) {
57
54
  });
58
55
  return {
59
56
  assistantEvent: result.assistantEvent,
60
- actionRequests: result.toolCalls.map((entry) => ({
61
- actionRef: String(entry.toolCallId),
62
- actionName: String(entry.toolName),
57
+ actionRequests: result.actionCalls.map((entry) => ({
58
+ actionRef: String(entry.actionCallId),
59
+ actionName: String(entry.actionName),
63
60
  input: entry.args,
64
61
  })),
65
62
  messagesForModel: result.messagesForModel,
@@ -13,10 +13,10 @@ import { type SerializableActionSpec } from "../tools-to-model-tools.js";
13
13
  * - map provider chunks to the Context stream contract
14
14
  * - emit UI chunks and persist step stream chunks
15
15
  */
16
- export declare function executeAiSdkReaction(params: {
17
- runtime: import("../context.runtime.js").ContextRuntime<ContextEnvironment>;
18
- env: ContextEnvironment;
16
+ export declare function executeAiSdkReaction<Env extends ContextEnvironment = ContextEnvironment>(params: {
17
+ runtime: import("../context.runtime.js").ContextRuntimeServiceHandle;
19
18
  contextIdentifier: ContextIdentifier;
19
+ events?: ContextItem[];
20
20
  model: ContextModelInit;
21
21
  system: string;
22
22
  tools: Record<string, SerializableActionSpec>;
@@ -24,7 +24,6 @@ export declare function executeAiSdkReaction(params: {
24
24
  iteration?: number;
25
25
  maxSteps: number;
26
26
  sendStart?: boolean;
27
- silent?: boolean;
28
27
  contextStepStream?: WritableStream<string>;
29
28
  writable?: WritableStream<UIMessageChunk>;
30
29
  executionId?: string;
@@ -32,7 +31,7 @@ export declare function executeAiSdkReaction(params: {
32
31
  stepId?: string;
33
32
  }): Promise<{
34
33
  assistantEvent: ContextItem;
35
- toolCalls: any[];
34
+ actionCalls: any[];
36
35
  messagesForModel: ModelMessage[];
37
36
  llm?: {
38
37
  provider?: string;
@@ -13,7 +13,7 @@ async function readWorkflowMetadata() {
13
13
  return null;
14
14
  }
15
15
  }
16
- async function resolveWorkflowRunId(env, executionId) {
16
+ async function resolveWorkflowRunId(runtime, executionId) {
17
17
  let runId = "";
18
18
  const meta = await readWorkflowMetadata();
19
19
  if (meta && meta.workflowRunId !== undefined && meta.workflowRunId !== null) {
@@ -21,9 +21,7 @@ async function resolveWorkflowRunId(env, executionId) {
21
21
  }
22
22
  if (!runId && executionId) {
23
23
  try {
24
- const { getContextRuntime } = await import("../runtime.js");
25
- const runtime = await getContextRuntime(env);
26
- const db = runtime?.db;
24
+ const db = await runtime.db();
27
25
  if (db) {
28
26
  const q = await db.query({
29
27
  event_executions: {
@@ -85,13 +83,15 @@ function safeErrorJson(error) {
85
83
  export async function executeAiSdkReaction(params) {
86
84
  "use step";
87
85
  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;
86
+ let events = Array.isArray(params.events) ? params.events : [];
87
+ if (events.length === 0) {
88
+ try {
89
+ events = await store.getItems(params.contextIdentifier);
90
+ }
91
+ catch (error) {
92
+ console.error("[ekairos/story] ai-sdk.step store.getItems failed");
93
+ throw error;
94
+ }
95
95
  }
96
96
  let messagesForModel;
97
97
  try {
@@ -102,7 +102,7 @@ export async function executeAiSdkReaction(params) {
102
102
  throw error;
103
103
  }
104
104
  const { jsonSchema, gateway, smoothStream, stepCountIs, streamText } = await import("ai");
105
- const { extractToolCallsFromParts } = await import("../context.toolcalls.js");
105
+ const { extractActionCallsFromParts } = await import("../context.action-calls.js");
106
106
  const resolvedModel = typeof params.model === "string"
107
107
  ? gateway(params.model)
108
108
  : typeof params.model === "function"
@@ -133,8 +133,9 @@ export async function executeAiSdkReaction(params) {
133
133
  rejectFinish = reject;
134
134
  });
135
135
  const modelId = typeof params.model === "string" ? params.model : "";
136
- const mappedProvider = modelId.includes("/") ? modelId.split("/")[0] : undefined;
136
+ const mappedProvider = modelId.includes("/") ? modelId.split("/")[0] || "ai-sdk" : "ai-sdk";
137
137
  const contextStepStreamWriter = params.contextStepStream?.getWriter();
138
+ const actionNameByRef = new Map();
138
139
  try {
139
140
  const uiStream = result
140
141
  .toUIMessageStream({
@@ -173,11 +174,17 @@ export async function executeAiSdkReaction(params) {
173
174
  itemId: params.eventId,
174
175
  provider: mappedProvider,
175
176
  sequence: ++chunkSequence,
177
+ actionNameByRef,
176
178
  });
177
179
  const persistedChunk = createContextStepStreamChunk({
178
180
  at: mapped.at,
179
181
  sequence: mapped.sequence,
180
182
  chunkType: mapped.chunkType,
183
+ stepId: params.stepId,
184
+ partId: mapped.partId,
185
+ providerPartId: mapped.providerPartId,
186
+ partType: mapped.partType,
187
+ partSlot: mapped.partSlot,
181
188
  provider: mapped.provider,
182
189
  providerChunkType: mapped.providerChunkType,
183
190
  actionRef: mapped.actionRef,
@@ -226,7 +233,7 @@ export async function executeAiSdkReaction(params) {
226
233
  }
227
234
  const assistantEvent = await finishPromise;
228
235
  const finishedAtMs = Date.now();
229
- const toolCalls = extractToolCallsFromParts(assistantEvent?.content?.parts);
236
+ const actionCalls = extractActionCallsFromParts(assistantEvent?.content?.parts);
230
237
  const latencyMs = Math.max(0, finishedAtMs - startedAtMs);
231
238
  let usage = undefined;
232
239
  let providerMetadata = undefined;
@@ -292,10 +299,10 @@ export async function executeAiSdkReaction(params) {
292
299
  rawProviderMetadata: providerMetadataJson,
293
300
  };
294
301
  try {
295
- const runId = await resolveWorkflowRunId(params.env, params.executionId);
302
+ const runId = await resolveWorkflowRunId(params.runtime, params.executionId);
296
303
  if (runId && llm) {
297
304
  await writeContextTraceEvents({
298
- env: params.env,
305
+ runtime: params.runtime,
299
306
  events: [
300
307
  {
301
308
  workflowRunId: runId,
@@ -340,5 +347,5 @@ export async function executeAiSdkReaction(params) {
340
347
  catch {
341
348
  // tracing must not break reaction
342
349
  }
343
- return { assistantEvent, toolCalls, messagesForModel, llm };
350
+ return { assistantEvent, actionCalls, messagesForModel, llm };
344
351
  }
@@ -1,6 +1,9 @@
1
1
  import type { ModelMessage } from "ai";
2
+ import type { DomainLike } from "@ekairos/domain";
2
3
  import type { ContextEnvironment } from "../context.config.js";
4
+ import type { ContextRuntime } from "../context.runtime.js";
3
5
  import type { ContextItem } from "../context.store.js";
6
+ import { eventsDomain } from "../schema.js";
4
7
  import type { ContextReactionLLM, ContextActionRequest, ContextReactor, ContextReactorParams } from "./types.js";
5
8
  type ScriptedReactionPayload = {
6
9
  assistantEvent?: Partial<ContextItem>;
@@ -8,10 +11,10 @@ type ScriptedReactionPayload = {
8
11
  messagesForModel?: ModelMessage[];
9
12
  llm?: ContextReactionLLM;
10
13
  };
11
- export type ScriptedReactorStep<Context = unknown, Env extends ContextEnvironment = ContextEnvironment> = ScriptedReactionPayload | ((params: ContextReactorParams<Context, Env>) => Promise<ScriptedReactionPayload> | ScriptedReactionPayload);
12
- export type CreateScriptedReactorOptions<Context = unknown, Env extends ContextEnvironment = ContextEnvironment> = {
13
- steps: ScriptedReactorStep<Context, Env>[];
14
+ export type ScriptedReactorStep<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = ScriptedReactionPayload | ((params: ContextReactorParams<Context, Env, RequiredDomain, Runtime>) => Promise<ScriptedReactionPayload> | ScriptedReactionPayload);
15
+ export type CreateScriptedReactorOptions<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>> = {
16
+ steps: ScriptedReactorStep<Context, Env, RequiredDomain, Runtime>[];
14
17
  repeatLast?: boolean;
15
18
  };
16
- export declare function createScriptedReactor<Context = unknown, Env extends ContextEnvironment = ContextEnvironment>(options: CreateScriptedReactorOptions<Context, Env>): ContextReactor<Context, Env>;
19
+ export declare function createScriptedReactor<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = ContextRuntime<Env>>(options: CreateScriptedReactorOptions<Context, Env, RequiredDomain, Runtime>): ContextReactor<Context, Env, RequiredDomain, Runtime>;
17
20
  export {};
@@ -1,10 +1,12 @@
1
1
  import type { ModelMessage, UIMessageChunk } from "ai";
2
+ import type { DomainLike } from "@ekairos/domain";
2
3
  import type { ContextEnvironment } from "../context.config.js";
3
- import type { ContextRuntime } from "../context.runtime.js";
4
+ import type { ContextTool } from "../context.action.js";
5
+ import type { ContextRuntime, ContextRuntimeHandleForDomain } from "../context.runtime.js";
4
6
  import type { ContextModelInit } from "../context.engine.js";
5
- import type { ContextIdentifier, StoredContext, ContextItem } from "../context.store.js";
7
+ import type { ContextIdentifier, StoredContext, StoredContextResource, ContextItem } from "../context.store.js";
6
8
  import type { ContextSkillPackage } from "../context.skill.js";
7
- import type { SerializableActionSpec } from "../tools-to-model-tools.js";
9
+ import { eventsDomain } from "../schema.js";
8
10
  export type ContextActionRequest = {
9
11
  actionRef: string;
10
12
  actionName: string;
@@ -32,16 +34,24 @@ export type ContextReactionResult = {
32
34
  state?: Record<string, unknown> | null;
33
35
  };
34
36
  };
35
- export type ContextReactorParams<Context = unknown, Env extends ContextEnvironment = ContextEnvironment> = {
36
- runtime: ContextRuntime<Env>;
37
- env: Env;
37
+ export type ContextReactorParams<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = any> = {
38
+ runtime: ContextRuntimeHandleForDomain<Env, RequiredDomain>;
38
39
  context: StoredContext<Context>;
39
40
  contextIdentifier: ContextIdentifier;
41
+ resources: StoredContextResource[];
42
+ /**
43
+ * Context items after the engine-level expansion stage.
44
+ *
45
+ * Reactors should prefer these over fetching raw items when constructing
46
+ * model/runtime input. Expanders must return regular ContextItems whose
47
+ * parts follow the shared context part contract, so this is not tied to any
48
+ * specific model provider.
49
+ */
50
+ events: ContextItem[];
40
51
  triggerEvent: ContextItem;
41
52
  model: ContextModelInit;
42
53
  systemPrompt: string;
43
- actions: Record<string, unknown>;
44
- actionSpecs: Record<string, SerializableActionSpec>;
54
+ actions: Record<string, ContextTool<Context, Env, RequiredDomain, Runtime>>;
45
55
  skills: ContextSkillPackage[];
46
56
  eventId: string;
47
57
  executionId: string;
@@ -50,9 +60,8 @@ export type ContextReactorParams<Context = unknown, Env extends ContextEnvironme
50
60
  iteration: number;
51
61
  maxModelSteps: number;
52
62
  sendStart: boolean;
53
- silent: boolean;
54
63
  contextStepStream?: WritableStream<string>;
55
64
  writable?: WritableStream<UIMessageChunk>;
56
65
  persistReactionParts?: (parts: any[]) => Promise<void>;
57
66
  };
58
- export type ContextReactor<Context = unknown, Env extends ContextEnvironment = ContextEnvironment> = (params: ContextReactorParams<Context, Env>) => Promise<ContextReactionResult>;
67
+ export type ContextReactor<Context = unknown, Env extends ContextEnvironment = ContextEnvironment, RequiredDomain extends DomainLike = typeof eventsDomain, Runtime extends ContextRuntime<Env> = any> = (params: ContextReactorParams<Context, Env, RequiredDomain, Runtime>) => Promise<ContextReactionResult>;
package/dist/runtime.d.ts CHANGED
@@ -8,6 +8,12 @@
8
8
  * - Do NOT import this entrypoint from client/browser code.
9
9
  * - Keep `@ekairos/events` main entrypoint safe to import from schema/domain modules.
10
10
  */
11
+ import "./reactors/ai-sdk.step.js";
12
+ import "./runtime.step.js";
13
+ import "./steps/durable.steps.js";
14
+ import "./steps/store.steps.js";
15
+ import "./steps/stream.steps.js";
16
+ import "./steps/trace.steps.js";
11
17
  export { getContextRuntime, } from "./runtime.step.js";
12
18
  export { createContextStepStreamClientId, createPersistedContextStepStream, readPersistedContextStepStream, resolveContextExecutionStreamPointer, waitForContextExecutionStreamPointer, } from "./steps/stream.steps.js";
13
19
  export type { ContextEnvironment, ContextRuntime } from "./context.config.js";
package/dist/runtime.js CHANGED
@@ -20,6 +20,15 @@ if (typeof globalThis.Event === "undefined") {
20
20
  ;
21
21
  globalThis.Event = NodeEvent;
22
22
  }
23
+ // Workflow bundles only register `use step` functions that are reachable from a
24
+ // workflow/runtime entrypoint. Keep the internal context steps reachable whenever
25
+ // apps import `@ekairos/events/runtime` to configure durable context execution.
26
+ import "./reactors/ai-sdk.step.js";
27
+ import "./runtime.step.js";
28
+ import "./steps/durable.steps.js";
29
+ import "./steps/store.steps.js";
30
+ import "./steps/stream.steps.js";
31
+ import "./steps/trace.steps.js";
23
32
  export { getContextRuntime, } from "./runtime.step.js";
24
33
  export { createContextStepStreamClientId, createPersistedContextStepStream, readPersistedContextStepStream, resolveContextExecutionStreamPointer, waitForContextExecutionStreamPointer, } from "./steps/stream.steps.js";
25
34
  export { registerContextEnv, getContextEnv } from "./env.js";
@@ -3,5 +3,5 @@ import { eventsDomain } from "./schema.js";
3
3
  export async function getContextRuntime(env) {
4
4
  const { resolveRuntime } = await import("@ekairos/domain/runtime");
5
5
  const resolved = await resolveRuntime(eventsDomain, env);
6
- return await coerceContextRuntime(resolved);
6
+ return await coerceContextRuntime(resolved, env);
7
7
  }