@deepagents/experimental 7.8.0 → 7.8.1
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/README.md +16 -5
- package/dist/index.js +140 -120
- package/dist/index.js.map +4 -4
- package/dist/zukhruf/control-plane/agent-control-plane.d.ts.map +1 -1
- package/dist/zukhruf/control-plane/agent-thread-limit-error.d.ts +6 -0
- package/dist/zukhruf/control-plane/agent-thread-limit-error.d.ts.map +1 -0
- package/dist/zukhruf/control-plane/agent-turn-id.d.ts +3 -0
- package/dist/zukhruf/control-plane/agent-turn-id.d.ts.map +1 -1
- package/dist/zukhruf/control-plane/stale-turn-error.d.ts +7 -0
- package/dist/zukhruf/control-plane/stale-turn-error.d.ts.map +1 -0
- package/dist/zukhruf/control-plane/turn-not-found-error.d.ts +7 -0
- package/dist/zukhruf/control-plane/turn-not-found-error.d.ts.map +1 -0
- package/dist/zukhruf/index.d.ts +3 -0
- package/dist/zukhruf/index.d.ts.map +1 -1
- package/dist/zukhruf/index.js +140 -120
- package/dist/zukhruf/index.js.map +4 -4
- package/dist/zukhruf/is-named-error.d.ts +7 -0
- package/dist/zukhruf/is-named-error.d.ts.map +1 -0
- package/dist/zukhruf/plugins/conversation-scheduling/conversation-scheduler.d.ts +1 -1
- package/dist/zukhruf/plugins/conversation-scheduling/conversation-scheduler.d.ts.map +1 -1
- package/dist/zukhruf/plugins/conversation-scheduling/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/conversation-scheduling/index.js +142 -136
- package/dist/zukhruf/plugins/conversation-scheduling/index.js.map +3 -3
- package/dist/zukhruf/plugins/http/index.d.ts +2 -2
- package/dist/zukhruf/plugins/http/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/http/index.js +72 -17
- package/dist/zukhruf/plugins/http/index.js.map +4 -4
- package/dist/zukhruf/plugins/schedules/http.d.ts.map +1 -1
- package/dist/zukhruf/plugins/schedules/http.js +44 -32
- package/dist/zukhruf/plugins/schedules/http.js.map +4 -4
- package/dist/zukhruf/plugins/schedules/index.d.ts +2 -2
- package/dist/zukhruf/plugins/schedules/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/schedules/index.js +138 -143
- package/dist/zukhruf/plugins/schedules/index.js.map +3 -3
- package/dist/zukhruf/plugins/uploads/http.js +30 -19
- package/dist/zukhruf/plugins/uploads/http.js.map +4 -4
- package/dist/zukhruf/plugins/uploads/index.d.ts +2 -2
- package/dist/zukhruf/plugins/uploads/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/uploads/index.js +48 -55
- package/dist/zukhruf/plugins/uploads/index.js.map +2 -2
- package/dist/zukhruf/queue/pg-boss.turn-queue.d.ts +4 -1
- package/dist/zukhruf/queue/pg-boss.turn-queue.d.ts.map +1 -1
- package/dist/zukhruf/runtime/agent-runtime.d.ts +19 -11
- package/dist/zukhruf/runtime/agent-runtime.d.ts.map +1 -1
- package/dist/zukhruf/runtime/plugin/plugin-manager.d.ts +4 -4
- package/dist/zukhruf/runtime/plugin/plugin-manager.d.ts.map +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -137,13 +137,24 @@ mount at its chosen path: create or continue sessions with idempotent `POST`
|
|
|
137
137
|
calls, receive the durable `turnId`, check or cancel a specific turn, cancel the
|
|
138
138
|
active session turn, stream durable UI-message output, and read runtime info
|
|
139
139
|
plus health checks. `GET /info` advertises mount-relative
|
|
140
|
-
`capabilities.history.href` and `capabilities.chat.href`.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
entries, while a future
|
|
140
|
+
`capabilities.history.href` and `capabilities.chat.href`. A runtime plugin's
|
|
141
|
+
`initialize(host)` returns its typed transport-neutral running phase, which
|
|
142
|
+
`host.plugin(definition)` returns. Transport packages bind those exact running
|
|
143
|
+
phases explicitly: `projectHttp(definition, project)` produces HTTP-owned
|
|
144
|
+
`publicRoutes`, `authenticatedRoutes`, and discovery entries, while a future
|
|
145
|
+
gRPC package can project the same running phase into
|
|
145
146
|
services and streaming without changing core. The HTTP transport plugin rejects
|
|
146
147
|
duplicate capability names and relative paths.
|
|
148
|
+
Runtime refusals keep their meaning over HTTP, and no answer names another user
|
|
149
|
+
or session: a session the caller does not own answers 404
|
|
150
|
+
`zukhruf/session-not-found`, a turn the session never issued (including a
|
|
151
|
+
regenerate of a message that never ran) answers 404
|
|
152
|
+
`zukhruf/session-turn-not-found`, an approval continuation for a turn the
|
|
153
|
+
session has moved past answers 409 `zukhruf/session-turn-stale`, and a
|
|
154
|
+
sub-agent turn whose tree has no free agent slot answers 429
|
|
155
|
+
`zukhruf/agent-thread-limit`. Hosts that call the runtime directly catch the
|
|
156
|
+
same refusals as `ConversationNotFoundError`, `TurnNotFoundError`,
|
|
157
|
+
`StaleTurnError` and `AgentThreadLimitError` from the main entry.
|
|
147
158
|
Plugins may also contribute one AI SDK telemetry integration per turn through
|
|
148
159
|
`telemetry(context)`; the runtime applies every contribution with the agent's
|
|
149
160
|
declaration-local telemetry policy.
|
package/dist/index.js
CHANGED
|
@@ -325,6 +325,7 @@ __export(zukhruf_exports, {
|
|
|
325
325
|
AgentPluginCapability: () => AgentPluginCapability,
|
|
326
326
|
AgentRuntime: () => AgentRuntime,
|
|
327
327
|
AgentThread: () => AgentThread,
|
|
328
|
+
AgentThreadLimitError: () => AgentThreadLimitError,
|
|
328
329
|
ConversationNotFoundError: () => ConversationNotFoundError,
|
|
329
330
|
DEFAULT_CONVERSATION_STATUS_CHANNEL: () => DEFAULT_CONVERSATION_STATUS_CHANNEL,
|
|
330
331
|
InterAgentCommunicationTypes: () => InterAgentCommunicationTypes,
|
|
@@ -334,6 +335,8 @@ __export(zukhruf_exports, {
|
|
|
334
335
|
PgBossTurnQueue: () => PgBossTurnQueue,
|
|
335
336
|
PostgresMailboxStore: () => PostgresMailboxStore,
|
|
336
337
|
SqliteMailboxStore: () => SqliteMailboxStore,
|
|
338
|
+
StaleTurnError: () => StaleTurnError,
|
|
339
|
+
TurnNotFoundError: () => TurnNotFoundError,
|
|
337
340
|
TurnQueue: () => TurnQueue,
|
|
338
341
|
assertCommunication: () => assertCommunication,
|
|
339
342
|
createInterAgentCommunication: () => createInterAgentCommunication,
|
|
@@ -528,6 +531,14 @@ var AgentThread = class _AgentThread {
|
|
|
528
531
|
}
|
|
529
532
|
};
|
|
530
533
|
|
|
534
|
+
// packages/experimental/src/zukhruf/control-plane/agent-thread-limit-error.ts
|
|
535
|
+
var AgentThreadLimitError = class extends Error {
|
|
536
|
+
name = "AgentThreadLimitError";
|
|
537
|
+
constructor() {
|
|
538
|
+
super("agent thread limit reached");
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
|
|
531
542
|
// packages/experimental/src/zukhruf/control-plane/conversation-not-found-error.ts
|
|
532
543
|
var ConversationNotFoundError = class extends Error {
|
|
533
544
|
name = "ConversationNotFoundError";
|
|
@@ -543,6 +554,26 @@ function assertConversationOwner(conversation, storedUserId) {
|
|
|
543
554
|
}
|
|
544
555
|
}
|
|
545
556
|
|
|
557
|
+
// packages/experimental/src/zukhruf/control-plane/stale-turn-error.ts
|
|
558
|
+
var StaleTurnError = class extends Error {
|
|
559
|
+
name = "StaleTurnError";
|
|
560
|
+
turnId;
|
|
561
|
+
constructor(turnId) {
|
|
562
|
+
super(`turn "${turnId}" is not the latest turn`);
|
|
563
|
+
this.turnId = turnId;
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
// packages/experimental/src/zukhruf/control-plane/turn-not-found-error.ts
|
|
568
|
+
var TurnNotFoundError = class extends Error {
|
|
569
|
+
name = "TurnNotFoundError";
|
|
570
|
+
turnId;
|
|
571
|
+
constructor(turnId) {
|
|
572
|
+
super(`turn "${turnId}" does not exist`);
|
|
573
|
+
this.turnId = turnId;
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
|
|
546
577
|
// packages/experimental/src/zukhruf/instructions.ts
|
|
547
578
|
function defineInstructions(...fragments) {
|
|
548
579
|
return fragments;
|
|
@@ -1025,7 +1056,6 @@ var TurnQueue = class {
|
|
|
1025
1056
|
};
|
|
1026
1057
|
|
|
1027
1058
|
// packages/experimental/src/zukhruf/queue/pg-boss.turn-queue.ts
|
|
1028
|
-
var MAX_TIMEOUT_MS = 2147483647;
|
|
1029
1059
|
var queueCatalogRowSchema = z4.object({ table: z4.string() });
|
|
1030
1060
|
function deadLetterQueueOf(queue) {
|
|
1031
1061
|
return `${queue}-dead`;
|
|
@@ -1040,13 +1070,13 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
1040
1070
|
#active = /* @__PURE__ */ new Map();
|
|
1041
1071
|
/** Cancels that arrived before a local worker runs the turn; each expires on its own timer. */
|
|
1042
1072
|
#cancelIntents = /* @__PURE__ */ new Map();
|
|
1043
|
-
constructor(boss, settings,
|
|
1073
|
+
constructor(boss, settings, opened) {
|
|
1044
1074
|
super();
|
|
1045
1075
|
this.#boss = boss;
|
|
1046
1076
|
this.#queue = settings.queue;
|
|
1047
1077
|
this.#schema = settings.schema;
|
|
1048
|
-
this.#table = table;
|
|
1049
|
-
this.#cancelIntentTtlMs =
|
|
1078
|
+
this.#table = opened.table;
|
|
1079
|
+
this.#cancelIntentTtlMs = opened.expireInSeconds * 1e3;
|
|
1050
1080
|
this.#pollingIntervalSeconds = settings.pollingIntervalSeconds;
|
|
1051
1081
|
}
|
|
1052
1082
|
/**
|
|
@@ -1055,20 +1085,13 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
1055
1085
|
*/
|
|
1056
1086
|
static async create(boss, options = {}) {
|
|
1057
1087
|
const settings = _PgBossTurnQueue.#settings(boss, options);
|
|
1058
|
-
const
|
|
1059
|
-
return new _PgBossTurnQueue(boss, settings,
|
|
1088
|
+
const opened = await _PgBossTurnQueue.#openQueue(boss, settings);
|
|
1089
|
+
return new _PgBossTurnQueue(boss, settings, opened);
|
|
1060
1090
|
}
|
|
1061
1091
|
static #settings(boss, options) {
|
|
1062
1092
|
const db = boss.getDb();
|
|
1063
1093
|
const configuredSchema = "config" in db && isRecord(db.config) ? db.config.schema : void 0;
|
|
1064
1094
|
const bossSchema = typeof configuredSchema === "string" ? configuredSchema : void 0;
|
|
1065
|
-
const expireInSeconds = options.expireInSeconds ?? 3600;
|
|
1066
|
-
const cancelIntentTtlMs = expireInSeconds * 1e3;
|
|
1067
|
-
if (!Number.isFinite(expireInSeconds) || expireInSeconds <= 0 || !Number.isSafeInteger(cancelIntentTtlMs) || cancelIntentTtlMs > Number.MAX_SAFE_INTEGER - Date.now()) {
|
|
1068
|
-
throw new Error(
|
|
1069
|
-
"PgBossTurnQueue expireInSeconds must be a finite positive duration"
|
|
1070
|
-
);
|
|
1071
|
-
}
|
|
1072
1095
|
if (options.schema === void 0 && bossSchema === void 0) {
|
|
1073
1096
|
throw new Error(
|
|
1074
1097
|
"PgBossTurnQueue cannot read the schema from a custom PgBoss database adapter; pass the PgBoss schema in options.schema"
|
|
@@ -1082,12 +1105,12 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
1082
1105
|
return {
|
|
1083
1106
|
queue: options.queue ?? "zukhruf-turns",
|
|
1084
1107
|
schema: options.schema ?? bossSchema ?? "pgboss",
|
|
1085
|
-
expireInSeconds,
|
|
1108
|
+
expireInSeconds: options.expireInSeconds ?? 3600,
|
|
1086
1109
|
heartbeatSeconds: options.heartbeatSeconds ?? 30,
|
|
1087
1110
|
pollingIntervalSeconds: options.pollingIntervalSeconds ?? 1
|
|
1088
1111
|
};
|
|
1089
1112
|
}
|
|
1090
|
-
/** Creates the queues when they are missing; returns the turn queue
|
|
1113
|
+
/** Creates the queues when they are missing; returns the turn queue as stored. */
|
|
1091
1114
|
static async #openQueue(boss, settings) {
|
|
1092
1115
|
const deadLetterQueue = deadLetterQueueOf(settings.queue);
|
|
1093
1116
|
if (!await boss.getQueue(deadLetterQueue)) {
|
|
@@ -1105,10 +1128,10 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
1105
1128
|
});
|
|
1106
1129
|
queue = await boss.getQueue(settings.queue);
|
|
1107
1130
|
}
|
|
1108
|
-
if (!queue) {
|
|
1131
|
+
if (!queue?.expireInSeconds) {
|
|
1109
1132
|
throw new Error(`Queue "${settings.queue}" was not initialized`);
|
|
1110
1133
|
}
|
|
1111
|
-
const { table } = queue;
|
|
1134
|
+
const { table, expireInSeconds } = queue;
|
|
1112
1135
|
try {
|
|
1113
1136
|
const catalog = await boss.getDb().executeSql(
|
|
1114
1137
|
`SELECT table_name AS "table"
|
|
@@ -1129,7 +1152,7 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
1129
1152
|
{ cause }
|
|
1130
1153
|
);
|
|
1131
1154
|
}
|
|
1132
|
-
return table;
|
|
1155
|
+
return { table, expireInSeconds };
|
|
1133
1156
|
}
|
|
1134
1157
|
get queue() {
|
|
1135
1158
|
return this.#queue;
|
|
@@ -1170,10 +1193,10 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
1170
1193
|
async cancel(streamId) {
|
|
1171
1194
|
this.#rememberCancelIntent(streamId);
|
|
1172
1195
|
this.#abortLocal(streamId);
|
|
1173
|
-
const
|
|
1174
|
-
data: { streamId }
|
|
1175
|
-
|
|
1176
|
-
|
|
1196
|
+
const queued = (await this.#boss.findJobs(this.#queue, {
|
|
1197
|
+
data: { streamId },
|
|
1198
|
+
queued: true
|
|
1199
|
+
})).map((job) => job.id);
|
|
1177
1200
|
if (queued.length > 0) await this.#deleteIfStillQueued(queued);
|
|
1178
1201
|
this.#abortLocal(streamId);
|
|
1179
1202
|
const remaining = await this.#boss.findJobs(this.#queue, {
|
|
@@ -1289,18 +1312,15 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
1289
1312
|
}
|
|
1290
1313
|
#rememberCancelIntent(streamId) {
|
|
1291
1314
|
this.#forgetCancelIntent(streamId);
|
|
1292
|
-
this.#armCancelIntent(streamId, Date.now() + this.#cancelIntentTtlMs);
|
|
1293
|
-
}
|
|
1294
|
-
#armCancelIntent(streamId, expiresAt) {
|
|
1295
1315
|
const timer = globalThis.setTimeout(
|
|
1296
|
-
() =>
|
|
1297
|
-
|
|
1298
|
-
else this.#cancelIntents.delete(streamId);
|
|
1299
|
-
},
|
|
1300
|
-
Math.min(MAX_TIMEOUT_MS, Math.max(1, expiresAt - Date.now()))
|
|
1316
|
+
() => this.#cancelIntents.delete(streamId),
|
|
1317
|
+
this.#cancelIntentTtlMs
|
|
1301
1318
|
);
|
|
1302
1319
|
timer.unref();
|
|
1303
|
-
this.#cancelIntents.set(streamId, {
|
|
1320
|
+
this.#cancelIntents.set(streamId, {
|
|
1321
|
+
expiresAt: Date.now() + this.#cancelIntentTtlMs,
|
|
1322
|
+
timer
|
|
1323
|
+
});
|
|
1304
1324
|
}
|
|
1305
1325
|
#hasCancelIntent(streamId) {
|
|
1306
1326
|
const intent = this.#cancelIntents.get(streamId);
|
|
@@ -2033,9 +2053,14 @@ var AgentStatusProjector = class _AgentStatusProjector {
|
|
|
2033
2053
|
};
|
|
2034
2054
|
|
|
2035
2055
|
// packages/experimental/src/zukhruf/control-plane/agent-turn-id.ts
|
|
2036
|
-
import { v5 as uuidv53 } from "uuid";
|
|
2056
|
+
import { v5 as uuidv53, validate as validateUuid } from "uuid";
|
|
2057
|
+
import { z as z6 } from "zod";
|
|
2058
|
+
var prefix = "zukhruf-turn";
|
|
2059
|
+
var agentTurnIdSchema = z6.string().refine((value) => {
|
|
2060
|
+
const [head, scope, turn, ...rest] = value.split(":");
|
|
2061
|
+
return head === prefix && rest.length === 0 && validateUuid(scope) && validateUuid(turn);
|
|
2062
|
+
});
|
|
2037
2063
|
var AgentTurnId = class _AgentTurnId {
|
|
2038
|
-
static #prefix = "zukhruf-turn";
|
|
2039
2064
|
#value;
|
|
2040
2065
|
constructor(value) {
|
|
2041
2066
|
this.#value = value;
|
|
@@ -2045,19 +2070,15 @@ var AgentTurnId = class _AgentTurnId {
|
|
|
2045
2070
|
throw new Error("turn id cannot be empty");
|
|
2046
2071
|
}
|
|
2047
2072
|
const scope = conversationNamespace(conversation);
|
|
2048
|
-
return new _AgentTurnId(
|
|
2049
|
-
`${_AgentTurnId.#prefix}:${scope}:${uuidv53(requestId, scope)}`
|
|
2050
|
-
);
|
|
2073
|
+
return new _AgentTurnId(`${prefix}:${scope}:${uuidv53(requestId, scope)}`);
|
|
2051
2074
|
}
|
|
2052
2075
|
static random(conversation) {
|
|
2053
2076
|
return _AgentTurnId.fromRequest(conversation, crypto.randomUUID());
|
|
2054
2077
|
}
|
|
2055
2078
|
static assertOwner(conversation, streamId) {
|
|
2056
|
-
const expectedPrefix = `${
|
|
2079
|
+
const expectedPrefix = `${prefix}:${conversationNamespace(conversation)}:`;
|
|
2057
2080
|
if (!streamId.startsWith(expectedPrefix)) {
|
|
2058
|
-
throw new
|
|
2059
|
-
`stream "${streamId}" does not belong to conversation "${conversation.chatId}"`
|
|
2060
|
-
);
|
|
2081
|
+
throw new TurnNotFoundError(streamId);
|
|
2061
2082
|
}
|
|
2062
2083
|
}
|
|
2063
2084
|
toString() {
|
|
@@ -2117,13 +2138,12 @@ var AgentControlPlane = class _AgentControlPlane {
|
|
|
2117
2138
|
await this.#directory.assertOwnerIfExists(conversation);
|
|
2118
2139
|
const thread = await this.#directory.load(conversation);
|
|
2119
2140
|
if (thread && !thread.path.isRoot && await this.#queue.getTurnActivity(conversation) !== "running" && !await this.#hasExecutionCapacity(thread)) {
|
|
2120
|
-
throw new
|
|
2141
|
+
throw new AgentThreadLimitError();
|
|
2121
2142
|
}
|
|
2122
2143
|
const streamId = message.role === "assistant" ? await this.#continuationStreamId(conversation, message) : AgentTurnId.fromRequest(conversation, message.id).toString();
|
|
2123
2144
|
if (message.role === "assistant" || turn.trigger === "regenerate-message") {
|
|
2124
2145
|
const status = await this.#streams.store.getStreamStatus(streamId);
|
|
2125
|
-
if (status === void 0)
|
|
2126
|
-
throw new Error("enqueue: continuation stream does not exist");
|
|
2146
|
+
if (status === void 0) throw new TurnNotFoundError(streamId);
|
|
2127
2147
|
if (status === "queued" || status === "running") return streamId;
|
|
2128
2148
|
await this.#streams.reopen(streamId);
|
|
2129
2149
|
} else {
|
|
@@ -2140,12 +2160,7 @@ var AgentControlPlane = class _AgentControlPlane {
|
|
|
2140
2160
|
}
|
|
2141
2161
|
async #continuationStreamId(conversation, message) {
|
|
2142
2162
|
const streamId = (await this.#directory.load(conversation))?.lastTurnId;
|
|
2143
|
-
if (
|
|
2144
|
-
throw new Error("enqueue: assistant continuation has no previous turn");
|
|
2145
|
-
if (message.id !== streamId)
|
|
2146
|
-
throw new Error(
|
|
2147
|
-
"enqueue: assistant continuation must update the current assistant message"
|
|
2148
|
-
);
|
|
2163
|
+
if (message.id !== streamId) throw new StaleTurnError(message.id);
|
|
2149
2164
|
return streamId;
|
|
2150
2165
|
}
|
|
2151
2166
|
recordLatestTurn(conversation, streamId) {
|
|
@@ -2231,11 +2246,11 @@ var AgentControlPlane = class _AgentControlPlane {
|
|
|
2231
2246
|
});
|
|
2232
2247
|
}
|
|
2233
2248
|
async listAgents(actor, pathPrefix) {
|
|
2234
|
-
const
|
|
2249
|
+
const prefix2 = pathPrefix ? actor.thread.path.resolve(pathPrefix) : void 0;
|
|
2235
2250
|
const threads = await this.#directory.listTree(actor.thread);
|
|
2236
2251
|
const agents = await Promise.all(
|
|
2237
2252
|
threads.flatMap((thread) => {
|
|
2238
|
-
if (
|
|
2253
|
+
if (prefix2 && !prefix2.contains(thread.path)) return [];
|
|
2239
2254
|
return [this.#statusProjector.projectListedAgent(actor.turn, thread)];
|
|
2240
2255
|
})
|
|
2241
2256
|
);
|
|
@@ -2589,7 +2604,7 @@ import {
|
|
|
2589
2604
|
modelMessageSchema as modelMessageSchema2
|
|
2590
2605
|
} from "ai";
|
|
2591
2606
|
import { hash, randomUUID as randomUUID2 } from "node:crypto";
|
|
2592
|
-
import { z as
|
|
2607
|
+
import { z as z7 } from "zod";
|
|
2593
2608
|
|
|
2594
2609
|
// packages/compaction/dist/index.js
|
|
2595
2610
|
import {
|
|
@@ -2793,21 +2808,21 @@ ${options.instructions}` : SUMMARY_PROMPT,
|
|
|
2793
2808
|
}
|
|
2794
2809
|
|
|
2795
2810
|
// packages/experimental/src/zukhruf/runtime/compaction.ts
|
|
2796
|
-
var checkpointSchema =
|
|
2797
|
-
sourceCount:
|
|
2798
|
-
sourceHash:
|
|
2799
|
-
replacement:
|
|
2811
|
+
var checkpointSchema = z7.object({
|
|
2812
|
+
sourceCount: z7.number().int().positive(),
|
|
2813
|
+
sourceHash: z7.string(),
|
|
2814
|
+
replacement: z7.array(z7.unknown()).transform(
|
|
2800
2815
|
(messages) => messages.map((message) => modelMessageSchema2.parse(message))
|
|
2801
2816
|
)
|
|
2802
2817
|
});
|
|
2803
|
-
var cacheObservationSchema =
|
|
2804
|
-
scope:
|
|
2805
|
-
prefixLength:
|
|
2806
|
-
prefixHash:
|
|
2807
|
-
startedAt:
|
|
2808
|
-
retentionMs:
|
|
2818
|
+
var cacheObservationSchema = z7.object({
|
|
2819
|
+
scope: z7.string(),
|
|
2820
|
+
prefixLength: z7.number().int().nonnegative(),
|
|
2821
|
+
prefixHash: z7.string(),
|
|
2822
|
+
startedAt: z7.number().int().nonnegative(),
|
|
2823
|
+
retentionMs: z7.number().int().positive().optional()
|
|
2809
2824
|
});
|
|
2810
|
-
var inputUsageSchema = cacheObservationSchema.pick({ scope: true, prefixLength: true, prefixHash: true }).extend({ inputTokens:
|
|
2825
|
+
var inputUsageSchema = cacheObservationSchema.pick({ scope: true, prefixLength: true, prefixHash: true }).extend({ inputTokens: z7.number().int().nonnegative() });
|
|
2811
2826
|
function jsonDigest(value) {
|
|
2812
2827
|
return hash("sha256", JSON.stringify(value));
|
|
2813
2828
|
}
|
|
@@ -2947,9 +2962,9 @@ function createCompaction(config, engine, store, signal, onEvent) {
|
|
|
2947
2962
|
}
|
|
2948
2963
|
if (saved !== void 0) {
|
|
2949
2964
|
const checkpoint2 = checkpointSchema.parse(saved);
|
|
2950
|
-
const
|
|
2951
|
-
if (
|
|
2952
|
-
source =
|
|
2965
|
+
const prefix2 = messages.slice(0, checkpoint2.sourceCount);
|
|
2966
|
+
if (prefix2.length === checkpoint2.sourceCount && jsonDigest(prefix2) === checkpoint2.sourceHash) {
|
|
2967
|
+
source = prefix2;
|
|
2953
2968
|
replacement = checkpoint2.replacement;
|
|
2954
2969
|
messages = [
|
|
2955
2970
|
...replacement,
|
|
@@ -3886,21 +3901,21 @@ import {
|
|
|
3886
3901
|
} from "@deepagents/context";
|
|
3887
3902
|
|
|
3888
3903
|
// packages/experimental/src/zukhruf/runtime/conversation-status/child-progress.ts
|
|
3889
|
-
import { z as
|
|
3890
|
-
var childActivitySchema =
|
|
3891
|
-
id:
|
|
3892
|
-
type:
|
|
3893
|
-
at:
|
|
3894
|
-
actorPath:
|
|
3895
|
-
targetPath:
|
|
3896
|
-
streamId:
|
|
3897
|
-
outcome:
|
|
3904
|
+
import { z as z8 } from "zod";
|
|
3905
|
+
var childActivitySchema = z8.object({
|
|
3906
|
+
id: z8.string(),
|
|
3907
|
+
type: z8.enum(["spawn", "message", "followup", "interrupt", "completion"]),
|
|
3908
|
+
at: z8.number(),
|
|
3909
|
+
actorPath: z8.string(),
|
|
3910
|
+
targetPath: z8.string(),
|
|
3911
|
+
streamId: z8.string(),
|
|
3912
|
+
outcome: z8.enum(["completed", "failed", "cancelled"]).optional()
|
|
3898
3913
|
});
|
|
3899
|
-
var childActivitiesSchema =
|
|
3914
|
+
var childActivitiesSchema = z8.partialRecord(
|
|
3900
3915
|
childActivitySchema.shape.type,
|
|
3901
3916
|
childActivitySchema
|
|
3902
3917
|
);
|
|
3903
|
-
var childActivityMetadataSchema =
|
|
3918
|
+
var childActivityMetadataSchema = z8.looseObject({
|
|
3904
3919
|
childActivities: childActivitiesSchema.default({})
|
|
3905
3920
|
});
|
|
3906
3921
|
|
|
@@ -4194,13 +4209,13 @@ var StatusPublishingTurnQueue = class extends TurnQueue {
|
|
|
4194
4209
|
|
|
4195
4210
|
// packages/experimental/src/zukhruf/collaboration/interrupt-agent.ts
|
|
4196
4211
|
import { tool as tool2 } from "ai";
|
|
4197
|
-
import { z as
|
|
4198
|
-
var interruptAgentInputSchema =
|
|
4199
|
-
target:
|
|
4212
|
+
import { z as z9 } from "zod";
|
|
4213
|
+
var interruptAgentInputSchema = z9.object({
|
|
4214
|
+
target: z9.string().trim().min(1).describe(
|
|
4200
4215
|
"The canonical /root/... path, or a descendant-relative target name."
|
|
4201
4216
|
)
|
|
4202
4217
|
});
|
|
4203
|
-
var interruptAgentOutputSchema =
|
|
4218
|
+
var interruptAgentOutputSchema = z9.object({ previous_status: listedAgentStatusSchema }).strict();
|
|
4204
4219
|
var interruptAgentTool = tool2({
|
|
4205
4220
|
description: "Interrupt an agent's current turn, if any, and return its previous status. The agent remains available for messages and follow-up tasks.",
|
|
4206
4221
|
inputSchema: interruptAgentInputSchema,
|
|
@@ -4210,13 +4225,13 @@ var interruptAgentTool = tool2({
|
|
|
4210
4225
|
|
|
4211
4226
|
// packages/experimental/src/zukhruf/collaboration/list-agents.ts
|
|
4212
4227
|
import { tool as tool3 } from "ai";
|
|
4213
|
-
import { z as
|
|
4214
|
-
var listAgentsInputSchema =
|
|
4215
|
-
path_prefix:
|
|
4228
|
+
import { z as z10 } from "zod";
|
|
4229
|
+
var listAgentsInputSchema = z10.object({
|
|
4230
|
+
path_prefix: z10.string().trim().min(1).describe(
|
|
4216
4231
|
"Task-path prefix without a trailing slash. Omit to list the whole tree."
|
|
4217
4232
|
).optional()
|
|
4218
4233
|
});
|
|
4219
|
-
var listAgentsOutputSchema =
|
|
4234
|
+
var listAgentsOutputSchema = z10.object({ agents: z10.array(listedAgentSchema) }).strict();
|
|
4220
4235
|
var listAgentsTool = tool3({
|
|
4221
4236
|
description: "List live agents in the current root thread tree. Optionally filter by task-path prefix.",
|
|
4222
4237
|
inputSchema: listAgentsInputSchema,
|
|
@@ -4226,12 +4241,12 @@ var listAgentsTool = tool3({
|
|
|
4226
4241
|
|
|
4227
4242
|
// packages/experimental/src/zukhruf/collaboration/message-tools.ts
|
|
4228
4243
|
import { tool as tool4 } from "ai";
|
|
4229
|
-
import { z as
|
|
4230
|
-
var agentMessageInputSchema =
|
|
4231
|
-
target:
|
|
4244
|
+
import { z as z11 } from "zod";
|
|
4245
|
+
var agentMessageInputSchema = z11.object({
|
|
4246
|
+
target: z11.string().trim().min(1).describe(
|
|
4232
4247
|
"The canonical /root/... path, or a descendant-relative target name."
|
|
4233
4248
|
),
|
|
4234
|
-
message:
|
|
4249
|
+
message: z11.string().trim().min(1).describe("The message or follow-up task.")
|
|
4235
4250
|
});
|
|
4236
4251
|
var sendMessageTool = tool4({
|
|
4237
4252
|
description: "Queue a message for another agent. Address siblings with their canonical /root/... path.",
|
|
@@ -4252,7 +4267,7 @@ var followupTaskTool = tool4({
|
|
|
4252
4267
|
|
|
4253
4268
|
// packages/experimental/src/zukhruf/collaboration/spawn-agent.ts
|
|
4254
4269
|
import { tool as tool5 } from "ai";
|
|
4255
|
-
import { z as
|
|
4270
|
+
import { z as z12 } from "zod";
|
|
4256
4271
|
|
|
4257
4272
|
// packages/experimental/src/zukhruf/control-plane/fork-turns.ts
|
|
4258
4273
|
var forkTurnsError = "fork_turns must be `none`, `all`, or a positive integer string";
|
|
@@ -4265,18 +4280,18 @@ function parseForkTurns(value) {
|
|
|
4265
4280
|
}
|
|
4266
4281
|
|
|
4267
4282
|
// packages/experimental/src/zukhruf/collaboration/spawn-agent.ts
|
|
4268
|
-
var spawnAgentInputSchema =
|
|
4269
|
-
agent_type:
|
|
4270
|
-
task_name:
|
|
4283
|
+
var spawnAgentInputSchema = z12.object({
|
|
4284
|
+
agent_type: z12.string().trim().min(1).describe("The name of one available subagent declaration."),
|
|
4285
|
+
task_name: z12.string().trim().min(1).refine(
|
|
4271
4286
|
(value) => value !== "." && value !== ".." && !value.includes("/"),
|
|
4272
4287
|
"task_name must be one non-empty path segment"
|
|
4273
4288
|
).describe("One path segment naming this independent agent task."),
|
|
4274
|
-
message:
|
|
4275
|
-
fork_turns:
|
|
4289
|
+
message: z12.string().refine((value) => value.trim().length > 0, "message cannot be empty").describe("The initial task for the spawned agent."),
|
|
4290
|
+
fork_turns: z12.string().trim().refine((value) => parseForkTurns(value) !== void 0, forkTurnsError).describe(
|
|
4276
4291
|
"Required number of parent turns to fork. Use `none`, `all`, or a positive integer string such as `3`."
|
|
4277
4292
|
)
|
|
4278
4293
|
});
|
|
4279
|
-
var spawnAgentOutputSchema =
|
|
4294
|
+
var spawnAgentOutputSchema = z12.object({ task_name: z12.string() }).strict();
|
|
4280
4295
|
function createSpawnAgentTool(options) {
|
|
4281
4296
|
return tool5({
|
|
4282
4297
|
description: ({ context }) => {
|
|
@@ -4305,11 +4320,11 @@ function createSpawnAgentTool(options) {
|
|
|
4305
4320
|
|
|
4306
4321
|
// packages/experimental/src/zukhruf/collaboration/wait-agent.ts
|
|
4307
4322
|
import { tool as tool6 } from "ai";
|
|
4308
|
-
import { z as
|
|
4309
|
-
var waitAgentOutputSchema =
|
|
4323
|
+
import { z as z13 } from "zod";
|
|
4324
|
+
var waitAgentOutputSchema = z13.object({ message: z13.string(), timed_out: z13.boolean() }).strict();
|
|
4310
4325
|
function createWaitAgentTool(options) {
|
|
4311
|
-
const waitAgentInputSchema =
|
|
4312
|
-
timeout_ms:
|
|
4326
|
+
const waitAgentInputSchema = z13.object({
|
|
4327
|
+
timeout_ms: z13.number().int().max(options.maxTimeoutMs).optional().describe("Maximum time to wait in milliseconds.")
|
|
4313
4328
|
});
|
|
4314
4329
|
return tool6({
|
|
4315
4330
|
description: "Wait for pending mail addressed to this agent without consuming it.",
|
|
@@ -4682,7 +4697,7 @@ var PluginToolComposition = class {
|
|
|
4682
4697
|
};
|
|
4683
4698
|
|
|
4684
4699
|
// packages/experimental/src/zukhruf/runtime/plugin/plugin-manager.ts
|
|
4685
|
-
function
|
|
4700
|
+
function initializedFrom(plugin, definition) {
|
|
4686
4701
|
return plugin.definition === definition;
|
|
4687
4702
|
}
|
|
4688
4703
|
var PluginManager = class {
|
|
@@ -4695,6 +4710,7 @@ var PluginManager = class {
|
|
|
4695
4710
|
#plugins;
|
|
4696
4711
|
#toolComposition;
|
|
4697
4712
|
#resources = new AsyncDisposableStack();
|
|
4713
|
+
#running = [];
|
|
4698
4714
|
constructor(root, bindings, multiAgent) {
|
|
4699
4715
|
let configuredRoot = root;
|
|
4700
4716
|
const pluginBindings = new PluginBindings(root.plugins, bindings);
|
|
@@ -4747,15 +4763,20 @@ var PluginManager = class {
|
|
|
4747
4763
|
return this.#resources.disposeAsync();
|
|
4748
4764
|
}
|
|
4749
4765
|
get(definition) {
|
|
4750
|
-
|
|
4751
|
-
|
|
4766
|
+
if (!this.#plugins.some((plugin2) => plugin2.definition === definition)) {
|
|
4767
|
+
throw new Error(
|
|
4768
|
+
`AgentRuntime: plugin "${definition.name}" does not belong to this runtime`
|
|
4769
|
+
);
|
|
4770
|
+
}
|
|
4771
|
+
const plugin = this.#running.find(
|
|
4772
|
+
(candidate) => initializedFrom(candidate, definition)
|
|
4752
4773
|
);
|
|
4753
4774
|
if (!plugin) {
|
|
4754
4775
|
throw new Error(
|
|
4755
|
-
`AgentRuntime: plugin "${definition.name}"
|
|
4776
|
+
`AgentRuntime: plugin "${definition.name}" has no running phase, since its initialize() returned nothing`
|
|
4756
4777
|
);
|
|
4757
4778
|
}
|
|
4758
|
-
return plugin.
|
|
4779
|
+
return plugin.running;
|
|
4759
4780
|
}
|
|
4760
4781
|
configureTelemetry(context, telemetry) {
|
|
4761
4782
|
const integrations = [];
|
|
@@ -4765,20 +4786,21 @@ var PluginManager = class {
|
|
|
4765
4786
|
return integrations.length === 0 ? telemetry : { ...telemetry, integrations };
|
|
4766
4787
|
}
|
|
4767
4788
|
get reconcilesAvailability() {
|
|
4768
|
-
return this.#
|
|
4769
|
-
({
|
|
4789
|
+
return this.#running.some(
|
|
4790
|
+
({ running }) => Boolean(running.conversationAvailable)
|
|
4770
4791
|
);
|
|
4771
4792
|
}
|
|
4772
|
-
async startWorkers(
|
|
4773
|
-
for (const {
|
|
4774
|
-
if (
|
|
4793
|
+
async startWorkers(workers, waitForActive) {
|
|
4794
|
+
for (const { running } of this.#running) {
|
|
4795
|
+
if (running.work) workers.use(await running.work(waitForActive));
|
|
4775
4796
|
}
|
|
4776
4797
|
}
|
|
4777
4798
|
async initialize(host) {
|
|
4778
4799
|
for (const { definition, instance } of this.#plugins) {
|
|
4779
4800
|
const initialized = await instance.initialize?.(host);
|
|
4780
4801
|
if (!initialized) continue;
|
|
4781
|
-
this.#
|
|
4802
|
+
this.#running.push({ definition, running: initialized });
|
|
4803
|
+
this.#resources.defer(() => initialized[Symbol.asyncDispose]?.());
|
|
4782
4804
|
if (initialized.tools) {
|
|
4783
4805
|
this.#toolComposition.add(definition.name, initialized.tools);
|
|
4784
4806
|
}
|
|
@@ -4788,11 +4810,11 @@ var PluginManager = class {
|
|
|
4788
4810
|
this.#toolComposition.compose(this.declarations.values())
|
|
4789
4811
|
);
|
|
4790
4812
|
}
|
|
4791
|
-
async conversationAvailable(
|
|
4813
|
+
async conversationAvailable(conversation) {
|
|
4792
4814
|
const errors = [];
|
|
4793
|
-
for (const {
|
|
4815
|
+
for (const { running } of this.#running) {
|
|
4794
4816
|
try {
|
|
4795
|
-
await
|
|
4817
|
+
await running.conversationAvailable?.(conversation);
|
|
4796
4818
|
} catch (error) {
|
|
4797
4819
|
errors.push(error);
|
|
4798
4820
|
}
|
|
@@ -5050,6 +5072,7 @@ var RuntimeHost = class {
|
|
|
5050
5072
|
[Symbol.asyncDispose]() {
|
|
5051
5073
|
return this.#resources.disposeAsync();
|
|
5052
5074
|
}
|
|
5075
|
+
/** The running phase `initialize(host)` returned for `definition`. */
|
|
5053
5076
|
plugin(definition) {
|
|
5054
5077
|
return this.#plugins.get(definition);
|
|
5055
5078
|
}
|
|
@@ -5080,7 +5103,7 @@ var RuntimeHost = class {
|
|
|
5080
5103
|
read: () => this.#conversationStatus.read(conversation),
|
|
5081
5104
|
publish: () => this.#conversationStatus.publish(conversation)
|
|
5082
5105
|
},
|
|
5083
|
-
() => this.#plugins.conversationAvailable(
|
|
5106
|
+
() => this.#plugins.conversationAvailable(conversation)
|
|
5084
5107
|
);
|
|
5085
5108
|
}
|
|
5086
5109
|
/**
|
|
@@ -5148,7 +5171,7 @@ var RuntimeHost = class {
|
|
|
5148
5171
|
}
|
|
5149
5172
|
async #startWorkers(options) {
|
|
5150
5173
|
await using workers = new AsyncDisposableStack();
|
|
5151
|
-
await this.#plugins.startWorkers(
|
|
5174
|
+
await this.#plugins.startWorkers(workers, true);
|
|
5152
5175
|
const reconcilesAvailability = this.#plugins.reconcilesAvailability;
|
|
5153
5176
|
workers.use(
|
|
5154
5177
|
await this.#queue.consume(this.#executor.execute.bind(this.#executor), {
|
|
@@ -5158,10 +5181,7 @@ var RuntimeHost = class {
|
|
|
5158
5181
|
onSettled: async ({ chatId, userId }) => {
|
|
5159
5182
|
await this.#conversationStatus.publish({ chatId, userId });
|
|
5160
5183
|
if (reconcilesAvailability) {
|
|
5161
|
-
await this.#plugins.conversationAvailable(
|
|
5162
|
-
chatId,
|
|
5163
|
-
userId
|
|
5164
|
-
});
|
|
5184
|
+
await this.#plugins.conversationAvailable({ chatId, userId });
|
|
5165
5185
|
}
|
|
5166
5186
|
}
|
|
5167
5187
|
})
|