@ekairos/events 1.22.34-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 (74) hide show
  1. package/README.md +58 -83
  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 +75 -46
  16. package/dist/context.engine.js +538 -302
  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 +21 -0
  25. package/dist/context.runtime.js +39 -0
  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 +63 -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 -5
  48. package/dist/reactors/ai-sdk.reactor.js +10 -9
  49. package/dist/reactors/ai-sdk.step.d.ts +6 -6
  50. package/dist/reactors/ai-sdk.step.js +32 -24
  51. package/dist/reactors/scripted.reactor.d.ts +7 -4
  52. package/dist/reactors/types.d.ts +23 -8
  53. package/dist/runtime.d.ts +6 -0
  54. package/dist/runtime.js +9 -0
  55. package/dist/runtime.step.js +2 -2
  56. package/dist/schema.d.ts +268 -2
  57. package/dist/schema.js +5 -9
  58. package/dist/steps/do-context-stream-step.d.ts +2 -2
  59. package/dist/steps/do-context-stream-step.js +6 -8
  60. package/dist/steps/durable.steps.d.ts +28 -0
  61. package/dist/steps/durable.steps.js +34 -0
  62. package/dist/steps/store.steps.d.ts +121 -39
  63. package/dist/steps/store.steps.js +266 -111
  64. package/dist/steps/stream.steps.d.ts +36 -3
  65. package/dist/steps/stream.steps.js +137 -14
  66. package/dist/steps/trace.steps.d.ts +4 -2
  67. package/dist/steps/trace.steps.js +26 -8
  68. package/dist/stores/instant.store.d.ts +15 -11
  69. package/dist/stores/instant.store.js +155 -6
  70. package/dist/tools-to-model-tools.d.ts +39 -3
  71. package/dist/tools-to-model-tools.js +63 -6
  72. package/package.json +20 -6
  73. package/dist/context.toolcalls.d.ts +0 -60
  74. package/dist/context.toolcalls.js +0 -117
package/dist/schema.d.ts CHANGED
@@ -1,2 +1,268 @@
1
- import { type DomainSchemaResult } from "@ekairos/domain";
2
- export declare const eventsDomain: DomainSchemaResult;
1
+ export declare const eventsDomain: import("@ekairos/domain").DomainSchemaResult<{
2
+ event_contexts: import("@instantdb/core").EntityDef<{
3
+ createdAt: import("@instantdb/core").DataAttrDef<Date, true, false, false>;
4
+ updatedAt: import("@instantdb/core").DataAttrDef<Date, false, false, false>;
5
+ key: import("@instantdb/core").DataAttrDef<string, false, true, true>;
6
+ name: import("@instantdb/core").DataAttrDef<string, false, false, false>;
7
+ status: import("@instantdb/core").DataAttrDef<string, false, true, false>;
8
+ content: import("@instantdb/core").DataAttrDef<any, false, false, false>;
9
+ description: import("@instantdb/core").DataAttrDef<string, false, false, false>;
10
+ goal: import("@instantdb/core").DataAttrDef<string, false, false, false>;
11
+ resources: import("@instantdb/core").DataAttrDef<any, false, false, false>;
12
+ reactor: import("@instantdb/core").DataAttrDef<any, false, false, false>;
13
+ }, {}, unknown>;
14
+ event_items: import("@instantdb/core").EntityDef<{
15
+ channel: import("@instantdb/core").DataAttrDef<string, true, true, false>;
16
+ createdAt: import("@instantdb/core").DataAttrDef<Date, true, true, false>;
17
+ type: import("@instantdb/core").DataAttrDef<string, false, true, false>;
18
+ content: import("@instantdb/core").DataAttrDef<any, false, false, false>;
19
+ status: import("@instantdb/core").DataAttrDef<string, false, true, false>;
20
+ }, {}, unknown>;
21
+ event_executions: import("@instantdb/core").EntityDef<{
22
+ createdAt: import("@instantdb/core").DataAttrDef<Date, true, false, false>;
23
+ updatedAt: import("@instantdb/core").DataAttrDef<Date, false, false, false>;
24
+ status: import("@instantdb/core").DataAttrDef<string, false, true, false>;
25
+ workflowRunId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
26
+ activeStreamId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
27
+ activeStreamClientId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
28
+ lastStreamId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
29
+ lastStreamClientId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
30
+ }, {}, unknown>;
31
+ event_steps: import("@instantdb/core").EntityDef<{
32
+ createdAt: import("@instantdb/core").DataAttrDef<Date, true, true, false>;
33
+ updatedAt: import("@instantdb/core").DataAttrDef<Date, false, false, false>;
34
+ status: import("@instantdb/core").DataAttrDef<string, false, true, false>;
35
+ iteration: import("@instantdb/core").DataAttrDef<number, true, true, false>;
36
+ errorText: import("@instantdb/core").DataAttrDef<string, false, false, false>;
37
+ streamId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
38
+ streamClientId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
39
+ streamStartedAt: import("@instantdb/core").DataAttrDef<Date, false, true, false>;
40
+ streamFinishedAt: import("@instantdb/core").DataAttrDef<Date, false, true, false>;
41
+ streamAbortReason: import("@instantdb/core").DataAttrDef<string, false, false, false>;
42
+ }, {}, unknown>;
43
+ event_parts: import("@instantdb/core").EntityDef<{
44
+ key: import("@instantdb/core").DataAttrDef<string, true, true, true>;
45
+ stepId: import("@instantdb/core").DataAttrDef<string, true, true, false>;
46
+ idx: import("@instantdb/core").DataAttrDef<number, true, true, false>;
47
+ type: import("@instantdb/core").DataAttrDef<string, false, true, false>;
48
+ part: import("@instantdb/core").DataAttrDef<any, false, false, false>;
49
+ metadata: import("@instantdb/core").DataAttrDef<any, false, false, false>;
50
+ updatedAt: import("@instantdb/core").DataAttrDef<Date, false, false, false>;
51
+ }, {}, unknown>;
52
+ event_trace_events: import("@instantdb/core").EntityDef<{
53
+ key: import("@instantdb/core").DataAttrDef<string, true, true, true>;
54
+ workflowRunId: import("@instantdb/core").DataAttrDef<string, true, true, false>;
55
+ seq: import("@instantdb/core").DataAttrDef<number, true, true, false>;
56
+ eventId: import("@instantdb/core").DataAttrDef<string, true, true, false>;
57
+ eventKind: import("@instantdb/core").DataAttrDef<string, true, true, false>;
58
+ eventAt: import("@instantdb/core").DataAttrDef<Date, false, false, false>;
59
+ ingestedAt: import("@instantdb/core").DataAttrDef<Date, false, false, false>;
60
+ orgId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
61
+ projectId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
62
+ contextKey: import("@instantdb/core").DataAttrDef<string, false, true, false>;
63
+ contextId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
64
+ executionId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
65
+ stepId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
66
+ contextEventId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
67
+ toolCallId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
68
+ partKey: import("@instantdb/core").DataAttrDef<string, false, true, false>;
69
+ partIdx: import("@instantdb/core").DataAttrDef<number, false, true, false>;
70
+ spanId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
71
+ parentSpanId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
72
+ isDeleted: import("@instantdb/core").DataAttrDef<boolean, false, false, false>;
73
+ aiProvider: import("@instantdb/core").DataAttrDef<string, false, true, false>;
74
+ aiModel: import("@instantdb/core").DataAttrDef<string, false, true, false>;
75
+ promptTokens: import("@instantdb/core").DataAttrDef<number, false, false, false>;
76
+ promptTokensCached: import("@instantdb/core").DataAttrDef<number, false, false, false>;
77
+ promptTokensUncached: import("@instantdb/core").DataAttrDef<number, false, false, false>;
78
+ completionTokens: import("@instantdb/core").DataAttrDef<number, false, false, false>;
79
+ totalTokens: import("@instantdb/core").DataAttrDef<number, false, false, false>;
80
+ latencyMs: import("@instantdb/core").DataAttrDef<number, false, false, false>;
81
+ cacheCostUsd: import("@instantdb/core").DataAttrDef<number, false, false, false>;
82
+ computeCostUsd: import("@instantdb/core").DataAttrDef<number, false, false, false>;
83
+ costUsd: import("@instantdb/core").DataAttrDef<number, false, false, false>;
84
+ payload: import("@instantdb/core").DataAttrDef<any, false, false, false>;
85
+ }, {}, unknown>;
86
+ event_trace_runs: import("@instantdb/core").EntityDef<{
87
+ workflowRunId: import("@instantdb/core").DataAttrDef<string, true, true, true>;
88
+ orgId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
89
+ projectId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
90
+ firstEventAt: import("@instantdb/core").DataAttrDef<Date, false, true, false>;
91
+ lastEventAt: import("@instantdb/core").DataAttrDef<Date, false, true, false>;
92
+ lastIngestedAt: import("@instantdb/core").DataAttrDef<Date, false, true, false>;
93
+ eventsCount: import("@instantdb/core").DataAttrDef<number, false, false, false>;
94
+ status: import("@instantdb/core").DataAttrDef<string, false, true, false>;
95
+ payload: import("@instantdb/core").DataAttrDef<any, false, false, false>;
96
+ }, {}, unknown>;
97
+ event_trace_spans: import("@instantdb/core").EntityDef<{
98
+ spanId: import("@instantdb/core").DataAttrDef<string, true, true, true>;
99
+ parentSpanId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
100
+ workflowRunId: import("@instantdb/core").DataAttrDef<string, true, true, false>;
101
+ executionId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
102
+ stepId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
103
+ kind: import("@instantdb/core").DataAttrDef<string, false, true, false>;
104
+ name: import("@instantdb/core").DataAttrDef<string, false, true, false>;
105
+ status: import("@instantdb/core").DataAttrDef<string, false, true, false>;
106
+ startedAt: import("@instantdb/core").DataAttrDef<Date, false, true, false>;
107
+ endedAt: import("@instantdb/core").DataAttrDef<Date, false, true, false>;
108
+ durationMs: import("@instantdb/core").DataAttrDef<number, false, false, false>;
109
+ payload: import("@instantdb/core").DataAttrDef<any, false, false, false>;
110
+ }, {}, unknown>;
111
+ document_documents: import("@instantdb/core").EntityDef<{
112
+ name: import("@instantdb/core").DataAttrDef<string, false, true, false>;
113
+ mimeType: import("@instantdb/core").DataAttrDef<string, false, false, false>;
114
+ size: import("@instantdb/core").DataAttrDef<number, false, false, false>;
115
+ ownerId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
116
+ orgId: import("@instantdb/core").DataAttrDef<string, false, true, false>;
117
+ createdAt: import("@instantdb/core").DataAttrDef<Date, false, true, false>;
118
+ processedAt: import("@instantdb/core").DataAttrDef<Date, false, true, false>;
119
+ updatedAt: import("@instantdb/core").DataAttrDef<Date, false, false, false>;
120
+ lastJobId: import("@instantdb/core").DataAttrDef<string, false, false, false>;
121
+ content: import("@instantdb/core").DataAttrDef<any, false, false, false>;
122
+ }, {}, unknown>;
123
+ }, {
124
+ contextItemsContext: {
125
+ readonly forward: {
126
+ readonly on: "event_items";
127
+ readonly has: "one";
128
+ readonly label: "context";
129
+ };
130
+ readonly reverse: {
131
+ readonly on: "event_contexts";
132
+ readonly has: "many";
133
+ readonly label: "items";
134
+ };
135
+ };
136
+ contextExecutionsContext: {
137
+ readonly forward: {
138
+ readonly on: "event_executions";
139
+ readonly has: "one";
140
+ readonly label: "context";
141
+ };
142
+ readonly reverse: {
143
+ readonly on: "event_contexts";
144
+ readonly has: "many";
145
+ readonly label: "executions";
146
+ };
147
+ };
148
+ contextCurrentExecution: {
149
+ readonly forward: {
150
+ readonly on: "event_contexts";
151
+ readonly has: "one";
152
+ readonly label: "currentExecution";
153
+ };
154
+ readonly reverse: {
155
+ readonly on: "event_executions";
156
+ readonly has: "one";
157
+ readonly label: "currentOf";
158
+ };
159
+ };
160
+ contextExecutionsTrigger: {
161
+ readonly forward: {
162
+ readonly on: "event_executions";
163
+ readonly has: "one";
164
+ readonly label: "trigger";
165
+ };
166
+ readonly reverse: {
167
+ readonly on: "event_items";
168
+ readonly has: "many";
169
+ readonly label: "executionsAsTrigger";
170
+ };
171
+ };
172
+ contextExecutionsReaction: {
173
+ readonly forward: {
174
+ readonly on: "event_executions";
175
+ readonly has: "one";
176
+ readonly label: "reaction";
177
+ };
178
+ readonly reverse: {
179
+ readonly on: "event_items";
180
+ readonly has: "many";
181
+ readonly label: "executionsAsReaction";
182
+ };
183
+ };
184
+ contextStepsExecution: {
185
+ readonly forward: {
186
+ readonly on: "event_steps";
187
+ readonly has: "one";
188
+ readonly label: "execution";
189
+ };
190
+ readonly reverse: {
191
+ readonly on: "event_executions";
192
+ readonly has: "many";
193
+ readonly label: "steps";
194
+ };
195
+ };
196
+ contextExecutionItems: {
197
+ readonly forward: {
198
+ readonly on: "event_items";
199
+ readonly has: "one";
200
+ readonly label: "execution";
201
+ };
202
+ readonly reverse: {
203
+ readonly on: "event_executions";
204
+ readonly has: "many";
205
+ readonly label: "items";
206
+ };
207
+ };
208
+ contextPartsStep: {
209
+ readonly forward: {
210
+ readonly on: "event_parts";
211
+ readonly has: "one";
212
+ readonly label: "step";
213
+ };
214
+ readonly reverse: {
215
+ readonly on: "event_steps";
216
+ readonly has: "many";
217
+ readonly label: "parts";
218
+ };
219
+ };
220
+ contextStepStream: {
221
+ readonly forward: {
222
+ readonly on: "event_steps";
223
+ readonly has: "one";
224
+ readonly label: "stream";
225
+ };
226
+ readonly reverse: {
227
+ readonly on: "$streams";
228
+ readonly has: "many";
229
+ readonly label: "step";
230
+ };
231
+ };
232
+ contextExecutionActiveStream: {
233
+ readonly forward: {
234
+ readonly on: "event_executions";
235
+ readonly has: "one";
236
+ readonly label: "activeStream";
237
+ };
238
+ readonly reverse: {
239
+ readonly on: "$streams";
240
+ readonly has: "many";
241
+ readonly label: "activeOf";
242
+ };
243
+ };
244
+ contextExecutionLastStream: {
245
+ readonly forward: {
246
+ readonly on: "event_executions";
247
+ readonly has: "one";
248
+ readonly label: "lastStream";
249
+ };
250
+ readonly reverse: {
251
+ readonly on: "$streams";
252
+ readonly has: "many";
253
+ readonly label: "lastOf";
254
+ };
255
+ };
256
+ documentFile: {
257
+ readonly forward: {
258
+ readonly on: "document_documents";
259
+ readonly has: "one";
260
+ readonly label: "file";
261
+ };
262
+ readonly reverse: {
263
+ readonly on: "$files";
264
+ readonly has: "one";
265
+ readonly label: "document";
266
+ };
267
+ };
268
+ }, import("@instantdb/core").RoomsDef, {}, "events", "events">;
package/dist/schema.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { i } from "@instantdb/core";
2
2
  import { domain } from "@ekairos/domain";
3
3
  export const eventsDomain = domain("events")
4
- .schema({
4
+ .withSchema({
5
5
  entities: {
6
6
  event_contexts: i.entity({
7
7
  createdAt: i.date(),
@@ -10,6 +10,10 @@ export const eventsDomain = domain("events")
10
10
  name: i.string().optional(),
11
11
  status: i.string().optional().indexed(), // open_idle | open_streaming | closed
12
12
  content: i.any().optional(),
13
+ description: i.string().optional(),
14
+ goal: i.string().optional(),
15
+ resources: i.any().optional(),
16
+ reactor: i.json().optional(),
13
17
  }),
14
18
  event_items: i.entity({
15
19
  channel: i.string().indexed(),
@@ -33,14 +37,6 @@ export const eventsDomain = domain("events")
33
37
  updatedAt: i.date().optional(),
34
38
  status: i.string().optional().indexed(), // running | completed | failed
35
39
  iteration: i.number().indexed(),
36
- kind: i.string().optional().indexed(), // message | action_execute | action_result
37
- actionName: i.string().optional().indexed(),
38
- actionInput: i.any().optional(),
39
- actionOutput: i.any().optional(),
40
- actionError: i.string().optional(),
41
- actionRequests: i.any().optional(),
42
- actionResults: i.any().optional(),
43
- continueLoop: i.boolean().optional(),
44
40
  errorText: i.string().optional(),
45
41
  streamId: i.string().optional().indexed(),
46
42
  streamClientId: i.string().optional().indexed(),
@@ -1,6 +1,6 @@
1
1
  import type { ModelMessage } from "ai";
2
2
  import type { ContextItem } from "../context.store.js";
3
- import type { SerializableToolForModel } from "../tools-to-model-tools.js";
3
+ import { type SerializableActionSpec } from "../tools-to-model-tools.js";
4
4
  import type { ContextModelInit } from "../context.engine.js";
5
5
  /**
6
6
  * Runs a single LLM streaming step as a Workflow step.
@@ -13,7 +13,7 @@ export declare function doContextStreamStep(params: {
13
13
  model: ContextModelInit;
14
14
  system: string;
15
15
  messages: ModelMessage[];
16
- tools: Record<string, SerializableToolForModel>;
16
+ tools: Record<string, SerializableActionSpec>;
17
17
  eventId: string;
18
18
  maxSteps: number;
19
19
  /**
@@ -1,4 +1,5 @@
1
1
  import { OUTPUT_ITEM_TYPE } from "../context.events.js";
2
+ import { actionSpecToAiSdkTool, } from "../tools-to-model-tools.js";
2
3
  /**
3
4
  * Runs a single LLM streaming step as a Workflow step.
4
5
  *
@@ -11,7 +12,7 @@ export async function doContextStreamStep(params) {
11
12
  const { getWritable } = await import("workflow");
12
13
  const writable = getWritable();
13
14
  const { jsonSchema, gateway, smoothStream, stepCountIs, streamText } = await import("ai");
14
- const { extractToolCallsFromParts } = await import("../context.toolcalls.js");
15
+ const { extractActionCallsFromParts } = await import("../context.action-calls.js");
15
16
  // Match DurableAgent's model init behavior:
16
17
  // - string => AI Gateway model id, resolved via `gateway(...)` in the step runtime
17
18
  // - function => model factory (should be a `"use step"` function for workflow serialization)
@@ -28,10 +29,7 @@ export async function doContextStreamStep(params) {
28
29
  // `jsonSchema(...)` so the AI SDK does not attempt Zod conversion at runtime.
29
30
  const toolsForStreamText = {};
30
31
  for (const [name, t] of Object.entries(params.tools)) {
31
- toolsForStreamText[name] = {
32
- description: t?.description,
33
- inputSchema: jsonSchema(t.inputSchema),
34
- };
32
+ toolsForStreamText[name] = actionSpecToAiSdkTool(name, t, jsonSchema);
35
33
  }
36
34
  const result = streamText({
37
35
  model: resolvedModel,
@@ -84,9 +82,9 @@ export async function doContextStreamStep(params) {
84
82
  }));
85
83
  await uiStream.pipeTo(writable, { preventClose: true });
86
84
  const assistantEvent = await finishPromise;
87
- const actionRequests = extractToolCallsFromParts(assistantEvent?.content?.parts).map((entry) => ({
88
- actionRef: String(entry.toolCallId),
89
- actionName: String(entry.toolName),
85
+ const actionRequests = extractActionCallsFromParts(assistantEvent?.content?.parts).map((entry) => ({
86
+ actionRef: String(entry.actionCallId),
87
+ actionName: String(entry.actionName),
90
88
  input: entry.args,
91
89
  }));
92
90
  return {
@@ -0,0 +1,28 @@
1
+ import type { ContextDurableWorkflowPayload, ContextReactFinalResult } from "../context.engine.js";
2
+ export type ContextDurableWorkflowStatus = "pending" | "running" | "completed" | "failed" | "cancelled";
3
+ export type ContextReturnValueHookPayload<Context = any> = {
4
+ ok: true;
5
+ result: ContextReactFinalResult<Context>;
6
+ } | {
7
+ ok: false;
8
+ error: {
9
+ name?: string;
10
+ message: string;
11
+ stack?: string;
12
+ };
13
+ };
14
+ export declare function startContextDurableWorkflow(params: {
15
+ payload: ContextDurableWorkflowPayload<any, any, any>;
16
+ }): Promise<{
17
+ runId: string;
18
+ }>;
19
+ export declare function readContextDurableWorkflowStatus(params: {
20
+ runId: string;
21
+ }): Promise<ContextDurableWorkflowStatus>;
22
+ export declare function readContextDurableWorkflowReturnValue(params: {
23
+ runId: string;
24
+ }): Promise<ContextReactFinalResult<any>>;
25
+ export declare function resumeContextReturnValueHook(params: {
26
+ token: string;
27
+ payload: ContextReturnValueHookPayload;
28
+ }): Promise<void>;
@@ -0,0 +1,34 @@
1
+ import { getContextDurableWorkflow } from "../context.durable.js";
2
+ export async function startContextDurableWorkflow(params) {
3
+ "use step";
4
+ const workflow = getContextDurableWorkflow();
5
+ if (typeof workflow !== "function") {
6
+ const contextKey = String(params.payload.contextKey || "(missing)");
7
+ throw new Error([
8
+ "ContextEngine.react(..., { durable: true }) needs a registered durable context workflow.",
9
+ "Call configureContextDurableWorkflow(contextDurableWorkflow) during server/workflow bootstrap.",
10
+ "If you want inline execution inside the current workflow step, pass durable: false.",
11
+ `Context key: ${contextKey}.`,
12
+ ].join(" "));
13
+ }
14
+ const { start } = await import("workflow/api");
15
+ const run = await start(workflow, [params.payload]);
16
+ return { runId: String(run.runId) };
17
+ }
18
+ export async function readContextDurableWorkflowStatus(params) {
19
+ "use step";
20
+ const { getRun } = await import("workflow/api");
21
+ const run = getRun(params.runId);
22
+ return (await run.status);
23
+ }
24
+ export async function readContextDurableWorkflowReturnValue(params) {
25
+ "use step";
26
+ const { getRun } = await import("workflow/api");
27
+ const run = getRun(params.runId);
28
+ return (await run.returnValue);
29
+ }
30
+ export async function resumeContextReturnValueHook(params) {
31
+ "use step";
32
+ const { resumeHook } = await import("workflow/api");
33
+ await resumeHook(params.token, params.payload);
34
+ }
@@ -1,27 +1,62 @@
1
- import type { UIMessageChunk } from "ai";
2
1
  import type { ContextEnvironment } from "../context.config.js";
3
- import type { ContextExecution, ContextItem, ContextIdentifier, StoredContext, ContextStatus } from "../context.store.js";
2
+ import type { ContextRuntime } from "../context.runtime.js";
3
+ import type { ContextExecution, ContextItem, ContextIdentifier, ContextResource, StoredContextResource, StoredContext, ContextStatus } from "../context.store.js";
4
+ import type { ContextStreamEvent } from "../context.stream.js";
5
+ import { type ContextActionResultForStream, type PersistedContextStepStreamSession } from "./stream.steps.js";
6
+ type RuntimeParams<Env extends ContextEnvironment = ContextEnvironment> = {
7
+ runtime: ContextRuntime<Env>;
8
+ };
4
9
  export type ContextReviewRequest = {
5
10
  toolCallId: string;
6
11
  toolName?: string;
7
12
  };
13
+ type ContextStepPatch = {
14
+ status?: "running" | "completed" | "failed";
15
+ errorText?: string;
16
+ };
8
17
  /**
9
18
  * Initializes/ensures the story context exists.
10
19
  *
11
20
  * This is the "context init" boundary for the story engine.
12
21
  */
13
- export declare function initializeContext<C>(env: ContextEnvironment, contextIdentifier: ContextIdentifier | null, opts?: {
14
- silent?: boolean;
15
- writable?: WritableStream<UIMessageChunk>;
22
+ export declare function initializeContext<C>(params: RuntimeParams & {
23
+ contextIdentifier: ContextIdentifier | null;
16
24
  }): Promise<{
17
25
  context: StoredContext<C>;
18
26
  isNew: boolean;
19
27
  }>;
20
- export declare function updateContextContent<C>(env: ContextEnvironment, contextIdentifier: ContextIdentifier, content: C): Promise<StoredContext<C>>;
21
- export declare function updateContextStatus(env: ContextEnvironment, contextIdentifier: ContextIdentifier, status: ContextStatus): Promise<void>;
22
- export declare function saveTriggerItem(env: ContextEnvironment, contextIdentifier: ContextIdentifier, event: ContextItem): Promise<ContextItem>;
23
- export declare function saveTriggerAndCreateExecution(params: {
24
- env: ContextEnvironment;
28
+ export declare function updateContextContent<C>(params: RuntimeParams & {
29
+ contextIdentifier: ContextIdentifier;
30
+ content: C;
31
+ }): Promise<StoredContext<C>>;
32
+ export declare function updateContextDefinition<C>(params: RuntimeParams & {
33
+ contextIdentifier: ContextIdentifier;
34
+ definition: {
35
+ description?: string | null;
36
+ goal?: string | null;
37
+ };
38
+ }): Promise<StoredContext<C>>;
39
+ export declare function upsertContextResources(params: RuntimeParams & {
40
+ contextIdentifier: ContextIdentifier;
41
+ resources: ContextResource[];
42
+ }): Promise<StoredContextResource[]>;
43
+ export declare function updateContextReactor<C>(params: RuntimeParams & {
44
+ contextIdentifier: ContextIdentifier;
45
+ reactor: {
46
+ kind: string;
47
+ state?: Record<string, unknown> | null;
48
+ };
49
+ }): Promise<StoredContext<C>>;
50
+ export declare function updateContextStatus(params: RuntimeParams & {
51
+ contextIdentifier: ContextIdentifier;
52
+ status: ContextStatus;
53
+ }): Promise<void>;
54
+ export declare function saveTriggerItem(params: RuntimeParams & {
55
+ contextIdentifier: ContextIdentifier;
56
+ event: ContextItem;
57
+ }): Promise<ContextItem>;
58
+ export declare function openExecution(params: {
59
+ runtime: ContextRuntime<ContextEnvironment>;
25
60
  contextIdentifier: ContextIdentifier;
26
61
  triggerEvent: ContextItem;
27
62
  }): Promise<{
@@ -29,68 +64,115 @@ export declare function saveTriggerAndCreateExecution(params: {
29
64
  reactionEvent: ContextItem;
30
65
  execution: ContextExecution;
31
66
  }>;
32
- export declare function saveReactionItem(env: ContextEnvironment, contextIdentifier: ContextIdentifier, event: ContextItem, opts?: {
33
- executionId?: string;
34
- contextId?: string;
35
- reviewRequests?: ContextReviewRequest[];
67
+ export declare function saveReactionItem(params: RuntimeParams & {
68
+ contextIdentifier: ContextIdentifier;
69
+ event: ContextItem;
70
+ opts?: {
71
+ executionId?: string;
72
+ contextId?: string;
73
+ reviewRequests?: ContextReviewRequest[];
74
+ };
36
75
  }): Promise<ContextItem>;
37
- export declare function updateItem(env: ContextEnvironment, eventId: string, event: ContextItem, opts?: {
38
- executionId?: string;
39
- contextId?: string;
76
+ export declare function getContextItems(params: RuntimeParams & {
77
+ contextIdentifier: ContextIdentifier;
78
+ }): Promise<ContextItem[]>;
79
+ export declare function updateItem(params: RuntimeParams & {
80
+ eventId: string;
81
+ event: ContextItem;
82
+ opts?: {
83
+ executionId?: string;
84
+ contextId?: string;
85
+ };
40
86
  }): Promise<ContextItem>;
41
- export declare function createExecution(env: ContextEnvironment, contextIdentifier: ContextIdentifier, triggerEventId: string, reactionEventId: string): Promise<{
87
+ export declare function createExecution(params: RuntimeParams & {
88
+ contextIdentifier: ContextIdentifier;
89
+ triggerEventId: string;
90
+ reactionEventId: string;
91
+ }): Promise<{
42
92
  id: string;
43
93
  }>;
44
94
  export declare function createReactionItem(params: {
45
- env: ContextEnvironment;
95
+ runtime: ContextRuntime<ContextEnvironment>;
46
96
  contextIdentifier: ContextIdentifier;
47
97
  triggerEventId: string;
48
98
  }): Promise<{
49
99
  reactionEventId: string;
50
100
  executionId: string;
51
101
  }>;
52
- export declare function completeExecution(env: ContextEnvironment, contextIdentifier: ContextIdentifier, executionId: string, status: "completed" | "failed"): Promise<void>;
102
+ export declare function completeExecution(params: RuntimeParams & {
103
+ contextIdentifier: ContextIdentifier;
104
+ executionId: string;
105
+ status: "completed" | "failed";
106
+ contextId?: string;
107
+ reactionEventId?: string;
108
+ reactionEvent?: ContextItem;
109
+ }): Promise<{
110
+ reactionEvent?: ContextItem;
111
+ }>;
53
112
  export declare function updateExecutionWorkflowRun(params: {
54
- env: ContextEnvironment;
113
+ runtime: ContextRuntime<ContextEnvironment>;
55
114
  executionId: string;
56
115
  workflowRunId: string;
57
116
  }): Promise<void>;
117
+ export declare function openExecutionStep<C>(params: {
118
+ runtime: ContextRuntime<ContextEnvironment>;
119
+ contextIdentifier: ContextIdentifier;
120
+ content: C;
121
+ executionId: string;
122
+ iteration: number;
123
+ }): Promise<{
124
+ stepId: string;
125
+ stream: PersistedContextStepStreamSession;
126
+ context: StoredContext<C>;
127
+ events: ContextItem[];
128
+ }>;
58
129
  export declare function createContextStep(params: {
59
- env: ContextEnvironment;
130
+ runtime: ContextRuntime<ContextEnvironment>;
60
131
  executionId: string;
61
132
  iteration: number;
62
133
  }): Promise<{
63
134
  stepId: string;
64
135
  }>;
65
136
  export declare function updateContextStep(params: {
66
- env: ContextEnvironment;
137
+ runtime: ContextRuntime<ContextEnvironment>;
67
138
  stepId: string;
68
139
  executionId?: string;
69
140
  contextId?: string;
70
141
  iteration?: number;
71
- patch: {
72
- status?: "running" | "completed" | "failed";
73
- kind?: "message" | "action_execute" | "action_result";
74
- actionName?: string;
75
- actionInput?: unknown;
76
- actionOutput?: unknown;
77
- actionError?: string;
78
- actionRequests?: any;
79
- actionResults?: any;
80
- continueLoop?: boolean;
81
- errorText?: string;
82
- };
142
+ patch: ContextStepPatch;
83
143
  }): Promise<void>;
144
+ export declare function completeExecutionStep(params: {
145
+ runtime: ContextRuntime<ContextEnvironment>;
146
+ session?: PersistedContextStepStreamSession | null;
147
+ stepId: string;
148
+ executionId?: string;
149
+ contextId?: string;
150
+ iteration?: number;
151
+ parts?: any[];
152
+ actionResults?: ContextActionResultForStream[];
153
+ stepStatus?: ContextStepPatch["status"];
154
+ errorText?: string;
155
+ reactionEventId?: string;
156
+ reactionEvent?: ContextItem;
157
+ }): Promise<{
158
+ reactionEvent?: ContextItem;
159
+ actionResultChunkEvents: ContextStreamEvent[];
160
+ }>;
84
161
  export declare function linkItemToExecutionStep(params: {
85
- env: ContextEnvironment;
162
+ runtime: ContextRuntime<ContextEnvironment>;
86
163
  itemId: string;
87
164
  executionId: string;
88
165
  }): Promise<void>;
89
- export declare function saveContextPartsStep(params: {
90
- env: ContextEnvironment;
166
+ export declare function saveExecutionStepOutput(params: {
167
+ runtime: ContextRuntime<ContextEnvironment>;
91
168
  stepId: string;
92
169
  executionId?: string;
93
170
  contextId?: string;
94
171
  iteration?: number;
95
172
  parts: any[];
96
- }): Promise<void>;
173
+ reactionEventId: string;
174
+ reactionEvent: ContextItem;
175
+ }): Promise<{
176
+ reactionEvent: ContextItem;
177
+ }>;
178
+ export {};