@ekairos/events 1.22.41-beta.development.0 → 1.22.43-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.
@@ -21,11 +21,11 @@ export type TraceEventKind = (typeof TRACE_EVENT_KINDS)[number];
21
21
  export declare const STREAM_LIFECYCLE_CHUNK_TYPES: readonly ["chunk.start", "chunk.start_step", "chunk.finish_step", "chunk.finish"];
22
22
  export declare const STREAM_TEXT_CHUNK_TYPES: readonly ["chunk.text_start", "chunk.text_delta", "chunk.text_end"];
23
23
  export declare const STREAM_REASONING_CHUNK_TYPES: readonly ["chunk.reasoning_start", "chunk.reasoning_delta", "chunk.reasoning_end"];
24
- export declare const STREAM_ACTION_CHUNK_TYPES: readonly ["chunk.action_input_start", "chunk.action_input_delta", "chunk.action_input_available", "chunk.action_output_available", "chunk.action_output_error"];
24
+ export declare const STREAM_ACTION_CHUNK_TYPES: readonly ["chunk.action_started", "chunk.action_input_delta", "chunk.action_completed", "chunk.action_failed"];
25
25
  export declare const STREAM_SOURCE_CHUNK_TYPES: readonly ["chunk.source_url", "chunk.source_document", "chunk.file"];
26
26
  export declare const STREAM_METADATA_CHUNK_TYPES: readonly ["chunk.message_metadata", "chunk.response_metadata"];
27
27
  export declare const STREAM_ERROR_CHUNK_TYPES: readonly ["chunk.error", "chunk.unknown"];
28
- export declare const CONTEXT_STREAM_CHUNK_TYPES: readonly ["chunk.start", "chunk.start_step", "chunk.finish_step", "chunk.finish", "chunk.text_start", "chunk.text_delta", "chunk.text_end", "chunk.reasoning_start", "chunk.reasoning_delta", "chunk.reasoning_end", "chunk.action_input_start", "chunk.action_input_delta", "chunk.action_input_available", "chunk.action_output_available", "chunk.action_output_error", "chunk.source_url", "chunk.source_document", "chunk.file", "chunk.message_metadata", "chunk.response_metadata", "chunk.error", "chunk.unknown"];
28
+ export declare const CONTEXT_STREAM_CHUNK_TYPES: readonly ["chunk.start", "chunk.start_step", "chunk.finish_step", "chunk.finish", "chunk.text_start", "chunk.text_delta", "chunk.text_end", "chunk.reasoning_start", "chunk.reasoning_delta", "chunk.reasoning_end", "chunk.action_started", "chunk.action_input_delta", "chunk.action_completed", "chunk.action_failed", "chunk.source_url", "chunk.source_document", "chunk.file", "chunk.message_metadata", "chunk.response_metadata", "chunk.error", "chunk.unknown"];
29
29
  export type ContextStreamChunkType = (typeof CONTEXT_STREAM_CHUNK_TYPES)[number];
30
30
  export declare function isContextStreamChunkType(value: string): value is ContextStreamChunkType;
31
31
  export type ContextTransition = Transition<"open_idle" | "open_streaming" | "closed", "open_idle" | "open_streaming" | "closed">;
@@ -41,11 +41,10 @@ export const STREAM_REASONING_CHUNK_TYPES = [
41
41
  "chunk.reasoning_end",
42
42
  ];
43
43
  export const STREAM_ACTION_CHUNK_TYPES = [
44
- "chunk.action_input_start",
44
+ "chunk.action_started",
45
45
  "chunk.action_input_delta",
46
- "chunk.action_input_available",
47
- "chunk.action_output_available",
48
- "chunk.action_output_error",
46
+ "chunk.action_completed",
47
+ "chunk.action_failed",
49
48
  ];
50
49
  export const STREAM_SOURCE_CHUNK_TYPES = [
51
50
  "chunk.source_url",
@@ -4,6 +4,8 @@ import { applyToolExecutionResultToParts } from "./context.toolcalls.js";
4
4
  import { isContextPartEnvelope, normalizePartsForPersistence, } from "./context.parts.js";
5
5
  import { createAiSdkReactor, } from "./context.reactor.js";
6
6
  import { abortPersistedContextStepStream, closeContextStream, createPersistedContextStepStreamForRuntime, finalizePersistedContextStepStreamForRuntime, } from "./steps/stream.steps.js";
7
+ import { createContextStepStreamChunk, encodeContextStepStreamChunk, } from "./context.step-stream.js";
8
+ import { resolveContextPartChunkIdentity } from "./context.part-identity.js";
7
9
  import { completeExecution, createContextStep, finalizeReactionStep, getContextItems, initializeContext, openReactionStep, saveTriggerAndCreateExecution, saveContextPartsAndUpdateReaction, saveContextPartsStep, updateContextContent, updateContextReactor, updateContextStatus, updateItem, updateContextStep, } from "./steps/store.steps.js";
8
10
  import { getClientResumeHookUrl, toolApprovalHookToken, toolApprovalWebhookToken, } from "./context.hooks.js";
9
11
  import { getContextDurableWorkflow } from "./context.durable.js";
@@ -86,6 +88,112 @@ function summarizePartPreview(part) {
86
88
  async function emitContextEvents(params) {
87
89
  void params;
88
90
  }
91
+ function toJsonSafeRecord(value) {
92
+ if (typeof value === "undefined")
93
+ return undefined;
94
+ try {
95
+ const json = JSON.parse(JSON.stringify(value));
96
+ return json && typeof json === "object"
97
+ ? json
98
+ : { value: json };
99
+ }
100
+ catch {
101
+ return undefined;
102
+ }
103
+ }
104
+ async function writeActionResultPartChunks(params) {
105
+ if (!params.session || params.actionResults.length === 0)
106
+ return;
107
+ const writer = params.session.stream.getWriter();
108
+ const events = [];
109
+ const sequenceBase = Date.now();
110
+ try {
111
+ for (let index = 0; index < params.actionResults.length; index += 1) {
112
+ const result = params.actionResults[index];
113
+ const actionRef = String(result.actionRequest.actionRef || "");
114
+ const actionName = String(result.actionRequest.actionName || "");
115
+ if (!actionRef || !actionName)
116
+ continue;
117
+ const chunkType = result.success
118
+ ? "chunk.action_completed"
119
+ : "chunk.action_failed";
120
+ const identity = resolveContextPartChunkIdentity({
121
+ stepId: params.session.stepId,
122
+ provider: "ekairos",
123
+ providerPartId: actionRef,
124
+ chunkType,
125
+ });
126
+ if (!identity)
127
+ continue;
128
+ const data = result.success
129
+ ? {
130
+ toolCallId: actionRef,
131
+ toolName: actionName,
132
+ output: toJsonSafeRecord(result.output),
133
+ }
134
+ : {
135
+ toolCallId: actionRef,
136
+ toolName: actionName,
137
+ error: {
138
+ message: String(result.errorText || "Action failed."),
139
+ },
140
+ };
141
+ const at = nowIso();
142
+ const sequence = sequenceBase + index;
143
+ const persistedChunk = createContextStepStreamChunk({
144
+ at,
145
+ sequence,
146
+ chunkType,
147
+ stepId: params.session.stepId,
148
+ partId: identity.partId,
149
+ providerPartId: identity.providerPartId,
150
+ partType: identity.partType,
151
+ partSlot: identity.partSlot,
152
+ provider: "ekairos",
153
+ providerChunkType: result.success
154
+ ? "action_completed"
155
+ : "action_failed",
156
+ actionRef,
157
+ data,
158
+ });
159
+ await writer.write(encodeContextStepStreamChunk(persistedChunk, {
160
+ stepId: params.session.stepId,
161
+ }));
162
+ events.push({
163
+ type: "chunk.emitted",
164
+ at,
165
+ chunkType,
166
+ contextId: params.contextId,
167
+ executionId: params.executionId,
168
+ stepId: params.session.stepId,
169
+ itemId: params.itemId,
170
+ sequence,
171
+ provider: "ekairos",
172
+ providerChunkType: result.success
173
+ ? "action_completed"
174
+ : "action_failed",
175
+ actionRef,
176
+ partId: identity.partId,
177
+ providerPartId: identity.providerPartId,
178
+ partType: identity.partType,
179
+ partSlot: identity.partSlot,
180
+ data,
181
+ });
182
+ }
183
+ }
184
+ finally {
185
+ if (typeof writer?.releaseLock === "function") {
186
+ writer.releaseLock();
187
+ }
188
+ }
189
+ if (events.length > 0) {
190
+ await emitContextEvents({
191
+ silent: params.silent ?? false,
192
+ writable: params.writable,
193
+ events,
194
+ });
195
+ }
196
+ }
89
197
  async function measureBenchmark(benchmark, name, run) {
90
198
  if (!benchmark)
91
199
  return await run();
@@ -960,6 +1068,15 @@ export class ContextEngine {
960
1068
  };
961
1069
  }
962
1070
  })));
1071
+ await measureBenchmark(params.__benchmark, `${stagePrefix}.writeActionResultPartChunksMs`, async () => await writeActionResultPartChunks({
1072
+ session: currentStepStream,
1073
+ writable,
1074
+ silent,
1075
+ contextId: String(currentContext.id),
1076
+ executionId,
1077
+ itemId: reactionEventId,
1078
+ actionResults: actionResults,
1079
+ }));
963
1080
  // Merge action results into persisted parts (so next LLM call can see them)
964
1081
  let finalizedStepParts = Array.isArray(stepParts) ? [...stepParts] : [];
965
1082
  for (const r of actionResults) {
@@ -146,11 +146,10 @@ export function resolveContextStreamPartType(chunkType) {
146
146
  if (chunkType === "chunk.source_url" || chunkType === "chunk.source_document") {
147
147
  return "source";
148
148
  }
149
- if (chunkType === "chunk.action_input_start" ||
149
+ if (chunkType === "chunk.action_started" ||
150
150
  chunkType === "chunk.action_input_delta" ||
151
- chunkType === "chunk.action_input_available" ||
152
- chunkType === "chunk.action_output_available" ||
153
- chunkType === "chunk.action_output_error") {
151
+ chunkType === "chunk.action_completed" ||
152
+ chunkType === "chunk.action_failed") {
154
153
  return "action";
155
154
  }
156
155
  return undefined;
@@ -163,9 +162,9 @@ export function resolveContextStreamPartSlot(chunkType, partType = resolveContex
163
162
  if (partType === "source")
164
163
  return "source";
165
164
  if (partType === "action") {
166
- if (chunkType === "chunk.action_output_error")
165
+ if (chunkType === "chunk.action_failed")
167
166
  return "action:failed";
168
- if (chunkType === "chunk.action_output_available")
167
+ if (chunkType === "chunk.action_completed")
169
168
  return "action:completed";
170
169
  return "action:started";
171
170
  }
@@ -65,7 +65,7 @@ function mapAiSdkChunkType(providerChunkType) {
65
65
  return "chunk.reasoning_end";
66
66
  case "tool-input-start":
67
67
  case "tool-call-start":
68
- return "chunk.action_input_start";
68
+ return "chunk.action_started";
69
69
  case "tool-input-delta":
70
70
  case "tool-call-delta":
71
71
  return "chunk.action_input_delta";
@@ -73,11 +73,11 @@ function mapAiSdkChunkType(providerChunkType) {
73
73
  case "tool-input-end":
74
74
  case "tool-call":
75
75
  case "tool-call-end":
76
- return "chunk.action_input_available";
76
+ return "chunk.action_started";
77
77
  case "tool-output-available":
78
- return "chunk.action_output_available";
78
+ return "chunk.action_completed";
79
79
  case "tool-output-error":
80
- return "chunk.action_output_error";
80
+ return "chunk.action_failed";
81
81
  case "source-url":
82
82
  return "chunk.source_url";
83
83
  case "source-document":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekairos/events",
3
- "version": "1.22.41-beta.development.0",
3
+ "version": "1.22.43-beta.development.0",
4
4
  "description": "Ekairos Events - Context-first workflow runtime",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -127,7 +127,7 @@
127
127
  },
128
128
  "dependencies": {
129
129
  "@ai-sdk/openai": "^2.0.52",
130
- "@ekairos/domain": "^1.22.41-beta.development.0",
130
+ "@ekairos/domain": "^1.22.43-beta.development.0",
131
131
  "@instantdb/admin": "0.22.158",
132
132
  "@instantdb/core": "0.22.142",
133
133
  "@vercel/mcp-adapter": "^1.0.0",