@copilotkit/runtime 2.0.0-rc.60 → 2.0.0-rc.62
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/agent.cjs +1 -0
- package/dist/agent.cjs.map +1 -1
- package/dist/agent.d.cts +10 -0
- package/dist/agent.d.cts.map +1 -1
- package/dist/agent.d.mts +10 -0
- package/dist/agent.d.mts.map +1 -1
- package/dist/agent.mjs +1 -0
- package/dist/agent.mjs.map +1 -1
- package/dist/index.cjs +4 -0
- package/dist/index.d.cts +4 -3
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +3 -2
- package/dist/runtime/core/channel-manager.cjs +51 -162
- package/dist/runtime/core/channel-manager.cjs.map +1 -1
- package/dist/runtime/core/channel-manager.d.cts +1 -1
- package/dist/runtime/core/channel-manager.d.cts.map +1 -1
- package/dist/runtime/core/channel-manager.d.mts +1 -1
- package/dist/runtime/core/channel-manager.d.mts.map +1 -1
- package/dist/runtime/core/channel-manager.mjs +51 -162
- package/dist/runtime/core/channel-manager.mjs.map +1 -1
- package/dist/runtime/core/fetch-cors.cjs +4 -2
- package/dist/runtime/core/fetch-cors.cjs.map +1 -1
- package/dist/runtime/core/fetch-cors.mjs +4 -2
- package/dist/runtime/core/fetch-cors.mjs.map +1 -1
- package/dist/runtime/core/package-info.cjs +1 -1
- package/dist/runtime/core/package-info.mjs +1 -1
- package/dist/runtime/core/runtime.cjs +3 -1
- package/dist/runtime/core/runtime.cjs.map +1 -1
- package/dist/runtime/core/runtime.d.cts +36 -7
- package/dist/runtime/core/runtime.d.cts.map +1 -1
- package/dist/runtime/core/runtime.d.mts +36 -7
- package/dist/runtime/core/runtime.d.mts.map +1 -1
- package/dist/runtime/core/runtime.mjs +3 -1
- package/dist/runtime/core/runtime.mjs.map +1 -1
- package/dist/runtime/core/thread-run.cjs +459 -0
- package/dist/runtime/core/thread-run.cjs.map +1 -0
- package/dist/runtime/core/thread-run.d.cts +201 -0
- package/dist/runtime/core/thread-run.d.cts.map +1 -0
- package/dist/runtime/core/thread-run.d.mts +201 -0
- package/dist/runtime/core/thread-run.d.mts.map +1 -0
- package/dist/runtime/core/thread-run.mjs +456 -0
- package/dist/runtime/core/thread-run.mjs.map +1 -0
- package/dist/runtime/event-transforms/open-generative-ui-middleware.cjs +6 -7
- package/dist/runtime/event-transforms/open-generative-ui-middleware.cjs.map +1 -1
- package/dist/runtime/event-transforms/open-generative-ui-middleware.d.cts.map +1 -1
- package/dist/runtime/event-transforms/open-generative-ui-middleware.d.mts.map +1 -1
- package/dist/runtime/event-transforms/open-generative-ui-middleware.mjs +6 -7
- package/dist/runtime/event-transforms/open-generative-ui-middleware.mjs.map +1 -1
- package/dist/runtime/handlers/get-runtime-info.cjs +2 -1
- package/dist/runtime/handlers/get-runtime-info.cjs.map +1 -1
- package/dist/runtime/handlers/get-runtime-info.mjs +2 -1
- package/dist/runtime/handlers/get-runtime-info.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/run.cjs +0 -1
- package/dist/runtime/handlers/intelligence/run.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/run.mjs +0 -1
- package/dist/runtime/handlers/intelligence/run.mjs.map +1 -1
- package/dist/runtime/handlers/intelligence/thread-names.cjs +43 -70
- package/dist/runtime/handlers/intelligence/thread-names.cjs.map +1 -1
- package/dist/runtime/handlers/intelligence/thread-names.mjs +43 -70
- package/dist/runtime/handlers/intelligence/thread-names.mjs.map +1 -1
- package/dist/runtime/index.d.cts +3 -2
- package/dist/runtime/index.d.mts +3 -2
- package/dist/runtime/intelligence-platform/client.cjs +20 -2
- package/dist/runtime/intelligence-platform/client.cjs.map +1 -1
- package/dist/runtime/intelligence-platform/client.d.cts +13 -0
- package/dist/runtime/intelligence-platform/client.d.cts.map +1 -1
- package/dist/runtime/intelligence-platform/client.d.mts +13 -0
- package/dist/runtime/intelligence-platform/client.d.mts.map +1 -1
- package/dist/runtime/intelligence-platform/client.mjs +20 -2
- package/dist/runtime/intelligence-platform/client.mjs.map +1 -1
- package/dist/runtime/runner/index.d.cts +1 -1
- package/dist/runtime/runner/index.d.mts +1 -1
- package/dist/runtime/runner/index.mjs +1 -1
- package/dist/runtime/runner/intelligence.cjs +107 -23
- package/dist/runtime/runner/intelligence.cjs.map +1 -1
- package/dist/runtime/runner/intelligence.d.cts +51 -2
- package/dist/runtime/runner/intelligence.d.cts.map +1 -1
- package/dist/runtime/runner/intelligence.d.mts +51 -2
- package/dist/runtime/runner/intelligence.d.mts.map +1 -1
- package/dist/runtime/runner/intelligence.mjs +108 -25
- package/dist/runtime/runner/intelligence.mjs.map +1 -1
- package/dist/v2/index.d.cts +18 -0
- package/dist/v2/index.d.mts +18 -0
- package/package.json +9 -9
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
const require_learning = require('./learning.cjs');
|
|
2
2
|
const require_client = require('../intelligence-platform/client.cjs');
|
|
3
3
|
const require_telemetry_client = require('../telemetry/telemetry-client.cjs');
|
|
4
|
+
const require_thread_run = require('./thread-run.cjs');
|
|
4
5
|
const require_channel_activation_config = require('./channel-activation-config.cjs');
|
|
5
|
-
const require_thread_lock_heartbeat = require('../intelligence-platform/thread-lock-heartbeat.cjs');
|
|
6
|
-
const require_web_crypto = require('./web-crypto.cjs');
|
|
7
6
|
let rxjs = require("rxjs");
|
|
8
7
|
let _ag_ui_client = require("@ag-ui/client");
|
|
9
8
|
let _ag_ui_mcp_middleware = require("@ag-ui/mcp-middleware");
|
|
@@ -133,7 +132,7 @@ async function defaultActivateChannel(config, channel, importChannelsIntelligenc
|
|
|
133
132
|
userId: appUserId,
|
|
134
133
|
channelDeliveryId: deliveryId
|
|
135
134
|
});
|
|
136
|
-
return Promise.all(history.messages.map((message) => toAgentMessage(message, services.intelligence)));
|
|
135
|
+
return Promise.all(history.messages.map((message) => require_thread_run.toAgentMessage(message, services.intelligence)));
|
|
137
136
|
}
|
|
138
137
|
});
|
|
139
138
|
}
|
|
@@ -217,127 +216,64 @@ async function runCanonicalChannelAgent(runner, intelligence, lockTtlSeconds, lo
|
|
|
217
216
|
userId: args.userId,
|
|
218
217
|
deliveryId: args.deliveryId
|
|
219
218
|
});
|
|
220
|
-
const lockRequestedAt = Date.now();
|
|
221
|
-
const lock = await intelligence.ɵacquireThreadLock({
|
|
222
|
-
threadId: args.threadId,
|
|
223
|
-
runId: args.runId,
|
|
224
|
-
userId: args.userId,
|
|
225
|
-
agentId: args.agentId,
|
|
226
|
-
channelDeliveryId: args.deliveryId,
|
|
227
|
-
requestId: args.deliveryId,
|
|
228
|
-
...learningContainerId !== void 0 ? { learningContainerId } : {},
|
|
229
|
-
ttlSeconds: lockTtlSeconds,
|
|
230
|
-
...lockKeyPrefix !== void 0 ? { lockKeyPrefix } : {}
|
|
231
|
-
});
|
|
232
|
-
const canonicalThreadId = lock.threadId;
|
|
233
|
-
const canonicalRunId = lock.runId;
|
|
234
219
|
let result = {
|
|
235
220
|
iterations: 0,
|
|
236
221
|
interrupted: false
|
|
237
222
|
};
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
});
|
|
243
|
-
let stopPromise;
|
|
244
|
-
let heartbeatError;
|
|
245
|
-
let stoppedByDelivery = false;
|
|
246
|
-
const stopCanonicalRun = () => {
|
|
247
|
-
stopPromise ??= Promise.resolve().then(() => runner.stop({
|
|
248
|
-
threadId: canonicalThreadId,
|
|
249
|
-
runId: canonicalRunId
|
|
250
|
-
})).catch(() => false);
|
|
251
|
-
};
|
|
252
|
-
const abortCanonicalRun = () => {
|
|
253
|
-
stoppedByDelivery = true;
|
|
254
|
-
try {
|
|
255
|
-
args.agent.abortRun();
|
|
256
|
-
} catch {}
|
|
257
|
-
stopCanonicalRun();
|
|
258
|
-
};
|
|
259
|
-
args.signal?.addEventListener("abort", abortCanonicalRun, { once: true });
|
|
260
|
-
const heartbeat = require_thread_lock_heartbeat.startThreadLockHeartbeat({
|
|
261
|
-
renew: (signal) => intelligence.ɵrenewThreadLock({
|
|
262
|
-
threadId: canonicalThreadId,
|
|
263
|
-
runId: canonicalRunId,
|
|
223
|
+
const outcome = await require_thread_run.runWithThreadLock({
|
|
224
|
+
runner,
|
|
225
|
+
intelligence,
|
|
226
|
+
lock: {
|
|
264
227
|
ttlSeconds: lockTtlSeconds,
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
228
|
+
heartbeatIntervalSeconds: lockHeartbeatIntervalSeconds,
|
|
229
|
+
...lockKeyPrefix !== void 0 ? { keyPrefix: lockKeyPrefix } : {}
|
|
230
|
+
},
|
|
231
|
+
acquire: {
|
|
232
|
+
threadId: args.threadId,
|
|
233
|
+
runId: args.runId,
|
|
234
|
+
userId: args.userId,
|
|
235
|
+
agentId: args.agentId,
|
|
236
|
+
channelDeliveryId: args.deliveryId,
|
|
237
|
+
requestId: args.deliveryId,
|
|
238
|
+
...learningContainerId !== void 0 ? { learningContainerId } : {}
|
|
239
|
+
},
|
|
240
|
+
...args.signal ? { signal: args.signal } : {},
|
|
241
|
+
start: ({ threadId: canonicalThreadId }) => {
|
|
242
|
+
attachChannelMemory(args.agent, intelligence, args.memory);
|
|
243
|
+
return {
|
|
244
|
+
agent: new ChannelOuterAgent(args.agent, canonicalThreadId, async (subscriber, canonicalRun) => {
|
|
245
|
+
result = await args.execute(subscriber, canonicalRun);
|
|
246
|
+
return result;
|
|
247
|
+
}),
|
|
248
|
+
input,
|
|
249
|
+
persistedInputMessages: args.persistedInputMessages
|
|
250
|
+
};
|
|
278
251
|
}
|
|
279
252
|
});
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
let terminalError;
|
|
283
|
-
runner.run({
|
|
284
|
-
threadId: canonicalThreadId,
|
|
285
|
-
agent: outer,
|
|
286
|
-
input: {
|
|
287
|
-
...input,
|
|
288
|
-
threadId: canonicalThreadId,
|
|
289
|
-
runId: canonicalRunId
|
|
290
|
-
},
|
|
291
|
-
persistedInputMessages: args.persistedInputMessages,
|
|
292
|
-
recordStop: (signal) => stoppedByDelivery ? intelligence.ɵrecordRunStop({
|
|
293
|
-
threadId: canonicalThreadId,
|
|
294
|
-
runId: canonicalRunId,
|
|
295
|
-
userId: args.userId,
|
|
296
|
-
agentId: args.agentId,
|
|
297
|
-
signal
|
|
298
|
-
}) : Promise.resolve()
|
|
299
|
-
}).subscribe({
|
|
300
|
-
next: (event) => {
|
|
301
|
-
if (event.type !== _ag_ui_client.EventType.RUN_ERROR || terminalError) return;
|
|
302
|
-
const message = "message" in event && typeof event.message === "string" ? event.message : "Canonical Channel agent run failed";
|
|
303
|
-
const details = safeChannelRunErrorDetails(event);
|
|
304
|
-
terminalError = new Error(message, details ? { cause: details } : void 0);
|
|
305
|
-
terminalError.name = "ChannelCanonicalRunError";
|
|
306
|
-
if ("code" in event && typeof event.code === "string" && event.code.length > 0) terminalError.code = event.code;
|
|
307
|
-
if (details) {
|
|
308
|
-
terminalError.category = details.category;
|
|
309
|
-
terminalError.provider = details.provider;
|
|
310
|
-
terminalError.operation = details.operation;
|
|
311
|
-
terminalError.effectKind = details.effectKind;
|
|
312
|
-
terminalError.providerCode = details.providerCode;
|
|
313
|
-
terminalError.validationMessages = details.validationMessages;
|
|
314
|
-
terminalError.retryable = details.retryable;
|
|
315
|
-
terminalError.deliveryId = details.deliveryId;
|
|
316
|
-
terminalError.details = details;
|
|
317
|
-
}
|
|
318
|
-
},
|
|
319
|
-
error: reject,
|
|
320
|
-
complete: () => {
|
|
321
|
-
if (terminalError) reject(terminalError);
|
|
322
|
-
else resolve();
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
if (args.signal?.aborted) abortCanonicalRun();
|
|
326
|
-
});
|
|
327
|
-
} finally {
|
|
328
|
-
args.signal?.removeEventListener("abort", abortCanonicalRun);
|
|
329
|
-
heartbeat.stop();
|
|
330
|
-
await intelligence.ɵcleanupThreadLock({
|
|
331
|
-
threadId: canonicalThreadId,
|
|
332
|
-
runId: canonicalRunId
|
|
333
|
-
}).catch(() => void 0);
|
|
334
|
-
}
|
|
335
|
-
if (heartbeatError !== void 0) {
|
|
336
|
-
await stopPromise;
|
|
337
|
-
throw heartbeatError;
|
|
338
|
-
}
|
|
253
|
+
if (outcome.runError) throw channelRunError(outcome.runError);
|
|
254
|
+
if (outcome.lockLost) throw outcome.lockLost.error;
|
|
339
255
|
return result;
|
|
340
256
|
}
|
|
257
|
+
/** The error a Channel run that ended with `RUN_ERROR` rejects with. */
|
|
258
|
+
function channelRunError(event) {
|
|
259
|
+
const message = "message" in event && typeof event.message === "string" ? event.message : "Canonical Channel agent run failed";
|
|
260
|
+
const details = safeChannelRunErrorDetails(event);
|
|
261
|
+
const error = new Error(message, details ? { cause: details } : void 0);
|
|
262
|
+
error.name = "ChannelCanonicalRunError";
|
|
263
|
+
if ("code" in event && typeof event.code === "string" && event.code.length > 0) error.code = event.code;
|
|
264
|
+
if (details) {
|
|
265
|
+
error.category = details.category;
|
|
266
|
+
error.provider = details.provider;
|
|
267
|
+
error.operation = details.operation;
|
|
268
|
+
error.effectKind = details.effectKind;
|
|
269
|
+
error.providerCode = details.providerCode;
|
|
270
|
+
error.validationMessages = details.validationMessages;
|
|
271
|
+
error.retryable = details.retryable;
|
|
272
|
+
error.deliveryId = details.deliveryId;
|
|
273
|
+
error.details = details;
|
|
274
|
+
}
|
|
275
|
+
return error;
|
|
276
|
+
}
|
|
341
277
|
function safeChannelRunErrorDetails(event) {
|
|
342
278
|
if (!("details" in event) || typeof event.details !== "object" || event.details === null || Array.isArray(event.details)) return;
|
|
343
279
|
const details = event.details;
|
|
@@ -357,53 +293,6 @@ function safeChannelRunErrorDetails(event) {
|
|
|
357
293
|
function boundedString(value, maxLength) {
|
|
358
294
|
return typeof value === "string" && value.length > 0 && value.length <= maxLength;
|
|
359
295
|
}
|
|
360
|
-
/** Convert canonical Intelligence history into AG-UI messages. */
|
|
361
|
-
async function toAgentMessage(message, intelligence) {
|
|
362
|
-
const content = await hydrateManagedContent(message.content, intelligence);
|
|
363
|
-
return {
|
|
364
|
-
id: message.id,
|
|
365
|
-
role: message.role,
|
|
366
|
-
content: content ?? "",
|
|
367
|
-
...message.activityType ? { activityType: message.activityType } : {},
|
|
368
|
-
...message.toolCalls ? { toolCalls: message.toolCalls.map((call) => ({
|
|
369
|
-
id: call.id,
|
|
370
|
-
type: "function",
|
|
371
|
-
function: {
|
|
372
|
-
name: call.name,
|
|
373
|
-
arguments: call.args
|
|
374
|
-
}
|
|
375
|
-
})) } : {},
|
|
376
|
-
...message.toolCallId ? { toolCallId: message.toolCallId } : {}
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
/** Resolves managed asset references only at the authorized Runtime boundary. */
|
|
380
|
-
async function hydrateManagedContent(content, intelligence) {
|
|
381
|
-
if (Array.isArray(content)) return Promise.all(content.map(async (part) => {
|
|
382
|
-
if (typeof part !== "object" || part === null || !("source" in part) || typeof part.source !== "object" || part.source === null || !("value" in part.source) || typeof part.source.value !== "string" || !part.source.value.startsWith("cpki-asset://")) return part;
|
|
383
|
-
const assetId = part.source.value.slice(13);
|
|
384
|
-
const asset = await intelligence.ɵgetManagedChannelAsset(assetId);
|
|
385
|
-
return {
|
|
386
|
-
...part,
|
|
387
|
-
source: {
|
|
388
|
-
type: "data",
|
|
389
|
-
value: require_web_crypto.bytesToBase64(asset.bytes),
|
|
390
|
-
mimeType: asset.mimeType ?? ("mimeType" in part.source && typeof part.source.mimeType === "string" ? part.source.mimeType : "application/octet-stream")
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
}));
|
|
394
|
-
if (typeof content === "object" && content !== null && "assetId" in content && typeof content.assetId === "string") {
|
|
395
|
-
const asset = await intelligence.ɵgetManagedChannelAsset(content.assetId);
|
|
396
|
-
return {
|
|
397
|
-
...content,
|
|
398
|
-
source: {
|
|
399
|
-
type: "data",
|
|
400
|
-
value: require_web_crypto.bytesToBase64(asset.bytes),
|
|
401
|
-
mimeType: asset.mimeType ?? ("mimeType" in content && typeof content.mimeType === "string" ? content.mimeType : "application/octet-stream")
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
return content;
|
|
406
|
-
}
|
|
407
296
|
/** Whether `err` signals a missing managed provider rather than a hard failure. */
|
|
408
297
|
function isSetupRequired(err) {
|
|
409
298
|
return err instanceof ChannelSetupRequiredError || typeof err === "object" && err !== null && err.code === "SETUP_REQUIRED";
|