@ekairos/events 1.22.41-beta.development.0 → 1.22.42-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.
- package/dist/context.engine.js +117 -0
- package/package.json +2 -2
package/dist/context.engine.js
CHANGED
|
@@ -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_output_available"
|
|
119
|
+
: "chunk.action_output_error";
|
|
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_output_available"
|
|
155
|
+
: "action_output_error",
|
|
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_output_available"
|
|
174
|
+
: "action_output_error",
|
|
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) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ekairos/events",
|
|
3
|
-
"version": "1.22.
|
|
3
|
+
"version": "1.22.42-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.
|
|
130
|
+
"@ekairos/domain": "^1.22.42-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",
|