@deepagents/experimental 7.0.2 → 7.1.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/README.md +8 -4
- package/dist/coding-agent-reminders/evaluate.d.ts.map +1 -1
- package/dist/coding-agent-reminders/index.js +2 -2
- package/dist/coding-agent-reminders/index.js.map +2 -2
- package/dist/index.js +230 -172
- package/dist/index.js.map +3 -3
- package/dist/providers/account-tokens.d.ts +47 -0
- package/dist/providers/account-tokens.d.ts.map +1 -0
- package/dist/providers/claude/accounts.d.ts +59 -0
- package/dist/providers/claude/accounts.d.ts.map +1 -0
- package/dist/providers/claude/errors.d.ts +7 -0
- package/dist/providers/claude/errors.d.ts.map +1 -0
- package/dist/providers/claude/index.d.ts +2 -0
- package/dist/providers/claude/index.d.ts.map +1 -1
- package/dist/providers/claude/index.js +550 -43
- package/dist/providers/claude/index.js.map +4 -4
- package/dist/providers/claude/local-credentials.d.ts.map +1 -1
- package/dist/providers/claude/oauth.d.ts +3 -0
- package/dist/providers/claude/oauth.d.ts.map +1 -0
- package/dist/providers/claude/provider.d.ts +4 -0
- package/dist/providers/claude/provider.d.ts.map +1 -0
- package/dist/providers/codex/accounts.d.ts +39 -0
- package/dist/providers/codex/accounts.d.ts.map +1 -0
- package/dist/providers/codex/errors.d.ts +7 -0
- package/dist/providers/codex/errors.d.ts.map +1 -0
- package/dist/providers/codex/index.d.ts +2 -0
- package/dist/providers/codex/index.d.ts.map +1 -1
- package/dist/providers/codex/index.js +482 -159
- package/dist/providers/codex/index.js.map +4 -4
- package/dist/providers/codex/provider.d.ts +3 -0
- package/dist/providers/codex/provider.d.ts.map +1 -0
- package/dist/providers/request-signal.d.ts +2 -0
- package/dist/providers/request-signal.d.ts.map +1 -0
- package/dist/zukhruf/control-plane/agent-control-plane.d.ts.map +1 -1
- package/dist/zukhruf/control-plane/agent-history-forker.d.ts.map +1 -1
- package/dist/zukhruf/index.js +228 -170
- package/dist/zukhruf/index.js.map +3 -3
- package/dist/zukhruf/mailbox/coordinator.d.ts.map +1 -1
- package/dist/zukhruf/mailbox/sqlite.store.d.ts.map +1 -1
- package/dist/zukhruf/mailbox/types.d.ts +4 -4
- package/dist/zukhruf/mailbox/types.d.ts.map +1 -1
- package/dist/zukhruf/plugins/conversation-scheduling/conversation-scheduler.d.ts.map +1 -1
- package/dist/zukhruf/plugins/conversation-scheduling/index.js +17 -2
- package/dist/zukhruf/plugins/conversation-scheduling/index.js.map +2 -2
- package/dist/zukhruf/plugins/http/index.js +16 -17
- package/dist/zukhruf/plugins/http/index.js.map +3 -3
- package/dist/zukhruf/plugins/http/validator.d.ts +14 -44
- package/dist/zukhruf/plugins/http/validator.d.ts.map +1 -1
- package/dist/zukhruf/plugins/schedules/http.d.ts.map +1 -1
- package/dist/zukhruf/plugins/schedules/http.js +22 -22
- package/dist/zukhruf/plugins/schedules/http.js.map +3 -3
- package/dist/zukhruf/plugins/schedules/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/schedules/index.js +172 -51
- package/dist/zukhruf/plugins/schedules/index.js.map +3 -3
- package/dist/zukhruf/plugins/schedules/scheduled-tasks.d.ts +3 -0
- package/dist/zukhruf/plugins/schedules/scheduled-tasks.d.ts.map +1 -1
- package/dist/zukhruf/plugins/uploads/http.js +17 -20
- package/dist/zukhruf/plugins/uploads/http.js.map +3 -3
- package/dist/zukhruf/plugins/uploads/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/uploads/index.js +1 -3
- package/dist/zukhruf/plugins/uploads/index.js.map +2 -2
- package/dist/zukhruf/queue/pg-boss-notifications.d.ts.map +1 -1
- package/dist/zukhruf/queue/pg-boss.turn-queue.d.ts.map +1 -1
- package/dist/zukhruf/render-turn.d.ts.map +1 -1
- package/dist/zukhruf/runtime/agent-runtime.d.ts +3 -0
- package/dist/zukhruf/runtime/agent-runtime.d.ts.map +1 -1
- package/dist/zukhruf/runtime/agent-turn-executor.d.ts.map +1 -1
- package/dist/zukhruf/runtime/compaction.d.ts +4 -4
- package/dist/zukhruf/runtime/compaction.d.ts.map +1 -1
- package/dist/zukhruf/runtime/conversation-status/projector.d.ts.map +1 -1
- package/dist/zukhruf/runtime/plugin/plugin-bindings.d.ts.map +1 -1
- package/dist/zukhruf/runtime/plugin/plugin-manager.d.ts.map +1 -1
- package/dist/zukhruf/tool.d.ts +1 -1
- package/dist/zukhruf/tool.d.ts.map +1 -1
- package/package.json +6 -5
package/dist/zukhruf/index.js
CHANGED
|
@@ -189,6 +189,7 @@ function defineInstructions(...fragments) {
|
|
|
189
189
|
|
|
190
190
|
// packages/experimental/src/zukhruf/mailbox/sqlite.store.ts
|
|
191
191
|
import { DatabaseSync } from "node:sqlite";
|
|
192
|
+
import { z } from "zod";
|
|
192
193
|
|
|
193
194
|
// packages/experimental/src/zukhruf/mailbox/store.ts
|
|
194
195
|
var MailboxStore = class {
|
|
@@ -196,11 +197,11 @@ var MailboxStore = class {
|
|
|
196
197
|
|
|
197
198
|
// packages/experimental/src/zukhruf/mailbox/types.ts
|
|
198
199
|
import { randomUUID } from "node:crypto";
|
|
199
|
-
var
|
|
200
|
+
var MessageDeliveryModes = {
|
|
200
201
|
QueueOnly: "queue-only",
|
|
201
202
|
TriggerTurn: "trigger-turn"
|
|
202
203
|
};
|
|
203
|
-
var
|
|
204
|
+
var InterAgentCommunicationTypes = {
|
|
204
205
|
Message: "MESSAGE",
|
|
205
206
|
NewTask: "NEW_TASK",
|
|
206
207
|
FinalAnswer: "FINAL_ANSWER"
|
|
@@ -209,7 +210,7 @@ function createInterAgentCommunication(communication) {
|
|
|
209
210
|
const value = {
|
|
210
211
|
...communication,
|
|
211
212
|
id: communication.id ?? randomUUID(),
|
|
212
|
-
type: communication.type ??
|
|
213
|
+
type: communication.type ?? InterAgentCommunicationTypes.Message,
|
|
213
214
|
otherRecipients: communication.otherRecipients ?? [],
|
|
214
215
|
triggerTurn: false
|
|
215
216
|
};
|
|
@@ -220,7 +221,7 @@ function assertCommunication(communication) {
|
|
|
220
221
|
if (!communication.id.trim()) {
|
|
221
222
|
throw new Error("inter-agent communication id cannot be empty");
|
|
222
223
|
}
|
|
223
|
-
if (!Object.values(
|
|
224
|
+
if (!Object.values(InterAgentCommunicationTypes).includes(communication.type)) {
|
|
224
225
|
throw new Error("inter-agent communication type is invalid");
|
|
225
226
|
}
|
|
226
227
|
assertConversationId(communication.author, "author");
|
|
@@ -276,6 +277,26 @@ var DDL = `
|
|
|
276
277
|
);
|
|
277
278
|
`;
|
|
278
279
|
var BUSY_TIMEOUT_MS = 5e3;
|
|
280
|
+
var conversationIdSchema = z.object({
|
|
281
|
+
chatId: z.string(),
|
|
282
|
+
userId: z.string()
|
|
283
|
+
});
|
|
284
|
+
var communicationSchema = z.object({
|
|
285
|
+
id: z.string(),
|
|
286
|
+
type: z.enum(InterAgentCommunicationTypes),
|
|
287
|
+
author: conversationIdSchema,
|
|
288
|
+
recipient: conversationIdSchema,
|
|
289
|
+
otherRecipients: z.array(conversationIdSchema),
|
|
290
|
+
content: z.string(),
|
|
291
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
292
|
+
triggerTurn: z.boolean()
|
|
293
|
+
});
|
|
294
|
+
var mailboxItemRowsSchema = z.array(
|
|
295
|
+
z.object({
|
|
296
|
+
sequence: z.number(),
|
|
297
|
+
communication: z.string().transform((text) => JSON.parse(text)).pipe(communicationSchema)
|
|
298
|
+
})
|
|
299
|
+
);
|
|
279
300
|
var SqliteMailboxStore = class extends MailboxStore {
|
|
280
301
|
#database;
|
|
281
302
|
#closed = false;
|
|
@@ -299,7 +320,7 @@ var SqliteMailboxStore = class extends MailboxStore {
|
|
|
299
320
|
}
|
|
300
321
|
async enqueue(communication) {
|
|
301
322
|
return this.#transaction(() => {
|
|
302
|
-
const consumedTerminal = communication.type ===
|
|
323
|
+
const consumedTerminal = communication.type === InterAgentCommunicationTypes.FinalAnswer && this.#hasConsumedTerminal(communication.id);
|
|
303
324
|
if (!consumedTerminal) {
|
|
304
325
|
this.#database.prepare(
|
|
305
326
|
`INSERT OR IGNORE INTO zukhruf_mailbox_items (
|
|
@@ -372,17 +393,15 @@ var SqliteMailboxStore = class extends MailboxStore {
|
|
|
372
393
|
}
|
|
373
394
|
#drain(recipient, leadingQueueOnly) {
|
|
374
395
|
return this.#transaction(() => {
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
communication: JSON.parse(row.communication)
|
|
385
|
-
}));
|
|
396
|
+
const items = mailboxItemRowsSchema.parse(
|
|
397
|
+
this.#database.prepare(
|
|
398
|
+
`SELECT sequence, communication
|
|
399
|
+
FROM zukhruf_mailbox_items
|
|
400
|
+
WHERE recipient_chat_id = ?
|
|
401
|
+
AND recipient_user_id = ?
|
|
402
|
+
ORDER BY sequence`
|
|
403
|
+
).all(recipient.chatId, recipient.userId)
|
|
404
|
+
);
|
|
386
405
|
const firstTrigger = leadingQueueOnly ? items.findIndex(({ communication }) => communication.triggerTurn) : -1;
|
|
387
406
|
const consumed = firstTrigger === -1 ? items : items.slice(0, firstTrigger);
|
|
388
407
|
const lastConsumed = consumed.at(-1);
|
|
@@ -393,7 +412,7 @@ var SqliteMailboxStore = class extends MailboxStore {
|
|
|
393
412
|
VALUES (?)`
|
|
394
413
|
);
|
|
395
414
|
for (const { communication } of consumed) {
|
|
396
|
-
if (communication.type ===
|
|
415
|
+
if (communication.type === InterAgentCommunicationTypes.FinalAnswer) {
|
|
397
416
|
tombstone.run(communication.id);
|
|
398
417
|
}
|
|
399
418
|
}
|
|
@@ -433,6 +452,8 @@ var SqliteMailboxStore = class extends MailboxStore {
|
|
|
433
452
|
|
|
434
453
|
// packages/experimental/src/zukhruf/queue/pg-boss.turn-queue.ts
|
|
435
454
|
import { v7 as uuidv7 } from "uuid";
|
|
455
|
+
import { z as z2 } from "zod";
|
|
456
|
+
import { isRecord } from "@deepagents/context";
|
|
436
457
|
|
|
437
458
|
// packages/experimental/src/zukhruf/queue/turn-queue.ts
|
|
438
459
|
var TurnQueue = class {
|
|
@@ -440,6 +461,7 @@ var TurnQueue = class {
|
|
|
440
461
|
|
|
441
462
|
// packages/experimental/src/zukhruf/queue/pg-boss.turn-queue.ts
|
|
442
463
|
var MAX_TIMEOUT_MS = 2147483647;
|
|
464
|
+
var queueCatalogRowSchema = z2.object({ table: z2.string() });
|
|
443
465
|
var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
444
466
|
#boss;
|
|
445
467
|
#queue;
|
|
@@ -457,7 +479,8 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
457
479
|
super();
|
|
458
480
|
this.#boss = boss;
|
|
459
481
|
this.#queue = options.queue ?? "zukhruf-turns";
|
|
460
|
-
const
|
|
482
|
+
const db = boss.getDb();
|
|
483
|
+
const configuredSchema = "config" in db && isRecord(db.config) ? db.config.schema : void 0;
|
|
461
484
|
const bossSchema = typeof configuredSchema === "string" ? configuredSchema : void 0;
|
|
462
485
|
this.#schema = options.schema ?? bossSchema ?? "pgboss";
|
|
463
486
|
if (options.schema === void 0 && bossSchema === void 0) {
|
|
@@ -509,7 +532,8 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
509
532
|
WHERE name = $1`,
|
|
510
533
|
[this.#queue]
|
|
511
534
|
);
|
|
512
|
-
|
|
535
|
+
const catalogRow = queueCatalogRowSchema.safeParse(catalog.rows[0]);
|
|
536
|
+
if (catalog.rows.length !== 1 || !catalogRow.success || catalogRow.data.table !== this.#table) {
|
|
513
537
|
throw new Error("queue catalog does not match");
|
|
514
538
|
}
|
|
515
539
|
await this.#boss.getDb().executeSql(`SELECT 1 FROM ${this.#relation()} WHERE false`);
|
|
@@ -699,7 +723,7 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
699
723
|
Math.min(MAX_TIMEOUT_MS, Math.max(1, nextExpiry - Date.now()))
|
|
700
724
|
);
|
|
701
725
|
this.#cancelIntentExpiryTimer = timer;
|
|
702
|
-
timer.unref
|
|
726
|
+
timer.unref();
|
|
703
727
|
}
|
|
704
728
|
async #deleteIfStillQueued(ids) {
|
|
705
729
|
if (!this.#table) {
|
|
@@ -751,6 +775,7 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
751
775
|
|
|
752
776
|
// packages/experimental/src/zukhruf/render-turn.ts
|
|
753
777
|
import { styleText } from "node:util";
|
|
778
|
+
import { isRecord as isRecord2 } from "@deepagents/context";
|
|
754
779
|
var dim = (text) => styleText("dim", text);
|
|
755
780
|
var red = (text) => styleText("red", text);
|
|
756
781
|
function oneLine(value, max = 88) {
|
|
@@ -758,7 +783,7 @@ function oneLine(value, max = 88) {
|
|
|
758
783
|
return text.length > max ? `${text.slice(0, max - 1)}\u2026` : text;
|
|
759
784
|
}
|
|
760
785
|
function describeToolCall(toolName, input) {
|
|
761
|
-
const args = input
|
|
786
|
+
const args = isRecord2(input) ? input : {};
|
|
762
787
|
switch (toolName) {
|
|
763
788
|
case "spawn_agent":
|
|
764
789
|
return `\u21C4 spawn ${args.agent_type} "${args.task_name}" \u2014 ${args.message}`;
|
|
@@ -1128,7 +1153,7 @@ var AgentHistoryForker = class {
|
|
|
1128
1153
|
await this.#store.updateChat(child.conversation.chatId, (chat2) => {
|
|
1129
1154
|
const metadata = chat2.metadata;
|
|
1130
1155
|
const zukhruf = metadata?.zukhruf;
|
|
1131
|
-
if (!
|
|
1156
|
+
if (!isRecord3(zukhruf)) {
|
|
1132
1157
|
throw new Error(
|
|
1133
1158
|
`spawn_agent: child chat "${child.conversation.chatId}" is missing Zukhruf metadata`
|
|
1134
1159
|
);
|
|
@@ -1205,14 +1230,14 @@ var AgentHistoryForker = class {
|
|
|
1205
1230
|
const storedMessages = await Promise.all(
|
|
1206
1231
|
sourceMessageIds.map((id) => this.#store.getMessage(id))
|
|
1207
1232
|
);
|
|
1208
|
-
|
|
1209
|
-
(message
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1233
|
+
const stored = storedMessages.map((message) => {
|
|
1234
|
+
if (message === void 0 || message.chatId !== parent.conversation.chatId) {
|
|
1235
|
+
throw new Error(
|
|
1236
|
+
"spawn_agent: persisted parent-history snapshot is unavailable"
|
|
1237
|
+
);
|
|
1238
|
+
}
|
|
1239
|
+
return message;
|
|
1240
|
+
});
|
|
1216
1241
|
const messages = await validateUIMessages({
|
|
1217
1242
|
messages: stored.map((message) => message.data)
|
|
1218
1243
|
});
|
|
@@ -1234,7 +1259,7 @@ var AgentHistoryForker = class {
|
|
|
1234
1259
|
await this.#store.updateChat(child.conversation.chatId, (chat2) => {
|
|
1235
1260
|
const metadata = chat2.metadata;
|
|
1236
1261
|
const zukhruf = metadata?.zukhruf;
|
|
1237
|
-
if (!
|
|
1262
|
+
if (!isRecord3(zukhruf)) {
|
|
1238
1263
|
throw new Error(
|
|
1239
1264
|
`spawn_agent: child chat "${child.conversation.chatId}" is missing Zukhruf metadata`
|
|
1240
1265
|
);
|
|
@@ -1326,12 +1351,12 @@ function isForkTurnBoundary(message) {
|
|
|
1326
1351
|
return interAgentCommunication(message)?.triggerTurn ?? true;
|
|
1327
1352
|
}
|
|
1328
1353
|
function interAgentCommunication(message) {
|
|
1329
|
-
if (!
|
|
1354
|
+
if (!isRecord3(message.metadata)) return void 0;
|
|
1330
1355
|
if (!Object.hasOwn(message.metadata, "interAgentCommunication")) {
|
|
1331
1356
|
return void 0;
|
|
1332
1357
|
}
|
|
1333
1358
|
const communication = message.metadata.interAgentCommunication;
|
|
1334
|
-
if (!
|
|
1359
|
+
if (!isRecord3(communication) || typeof communication.triggerTurn !== "boolean") {
|
|
1335
1360
|
throw new Error(
|
|
1336
1361
|
`spawn_agent: message "${message.id}" has invalid inter-agent metadata`
|
|
1337
1362
|
);
|
|
@@ -1339,7 +1364,7 @@ function interAgentCommunication(message) {
|
|
|
1339
1364
|
return { triggerTurn: communication.triggerTurn };
|
|
1340
1365
|
}
|
|
1341
1366
|
function parseHistoryForkRecord(value) {
|
|
1342
|
-
if (!
|
|
1367
|
+
if (!isRecord3(value)) {
|
|
1343
1368
|
throw new Error("spawn_agent: invalid persisted history-fork metadata");
|
|
1344
1369
|
}
|
|
1345
1370
|
const { forkTurns, parentChatId, parentHeadMessageId, sourceMessageIds } = value;
|
|
@@ -1358,11 +1383,11 @@ function parseHistoryForkRecord(value) {
|
|
|
1358
1383
|
function isForkTurns(value) {
|
|
1359
1384
|
return value === "none" || value === "all" || typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
1360
1385
|
}
|
|
1361
|
-
function
|
|
1386
|
+
function isRecord3(value) {
|
|
1362
1387
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1363
1388
|
}
|
|
1364
1389
|
function isEmptyAssistantPlaceholder(value) {
|
|
1365
|
-
return
|
|
1390
|
+
return isRecord3(value) && typeof value.id === "string" && value.role === "assistant" && Array.isArray(value.parts) && value.parts.length === 0;
|
|
1366
1391
|
}
|
|
1367
1392
|
function arraysEqual(left, right) {
|
|
1368
1393
|
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
@@ -1370,17 +1395,17 @@ function arraysEqual(left, right) {
|
|
|
1370
1395
|
|
|
1371
1396
|
// packages/experimental/src/zukhruf/control-plane/agent-status-projector.ts
|
|
1372
1397
|
import { isTextUIPart } from "ai";
|
|
1373
|
-
import { z } from "zod";
|
|
1398
|
+
import { z as z3 } from "zod";
|
|
1374
1399
|
import {
|
|
1375
1400
|
ContextEngine
|
|
1376
1401
|
} from "@deepagents/context";
|
|
1377
|
-
var listedAgentStatusSchema =
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1402
|
+
var listedAgentStatusSchema = z3.union([
|
|
1403
|
+
z3.enum(["pending_init", "running", "interrupted", "shutdown", "not_found"]),
|
|
1404
|
+
z3.object({ completed: z3.string().nullable() }).strict(),
|
|
1405
|
+
z3.object({ errored: z3.string() }).strict()
|
|
1381
1406
|
]);
|
|
1382
|
-
var listedAgentSchema =
|
|
1383
|
-
agent_name:
|
|
1407
|
+
var listedAgentSchema = z3.object({
|
|
1408
|
+
agent_name: z3.string(),
|
|
1384
1409
|
agent_status: listedAgentStatusSchema
|
|
1385
1410
|
}).strict();
|
|
1386
1411
|
var AgentStatusProjector = class _AgentStatusProjector {
|
|
@@ -1447,7 +1472,7 @@ var AgentStatusProjector = class _AgentStatusProjector {
|
|
|
1447
1472
|
await this.#mailbox.deliver(
|
|
1448
1473
|
createInterAgentCommunication({
|
|
1449
1474
|
id: `zukhruf:child-terminal:${turn.streamId}`,
|
|
1450
|
-
type:
|
|
1475
|
+
type: InterAgentCommunicationTypes.FinalAnswer,
|
|
1451
1476
|
author: thread.conversation,
|
|
1452
1477
|
recipient: {
|
|
1453
1478
|
chatId: thread.parentChatId,
|
|
@@ -1461,7 +1486,7 @@ var AgentStatusProjector = class _AgentStatusProjector {
|
|
|
1461
1486
|
status: stream.status
|
|
1462
1487
|
}
|
|
1463
1488
|
}),
|
|
1464
|
-
|
|
1489
|
+
MessageDeliveryModes.QueueOnly
|
|
1465
1490
|
);
|
|
1466
1491
|
return { finishedAt: stream.finishedAt, status: stream.status };
|
|
1467
1492
|
}
|
|
@@ -1681,15 +1706,15 @@ var AgentControlPlane = class _AgentControlPlane {
|
|
|
1681
1706
|
}
|
|
1682
1707
|
async sendMessage(actor, input) {
|
|
1683
1708
|
return this.#deliverAgentMessage(actor, input, {
|
|
1684
|
-
type:
|
|
1685
|
-
mode:
|
|
1709
|
+
type: InterAgentCommunicationTypes.Message,
|
|
1710
|
+
mode: MessageDeliveryModes.QueueOnly,
|
|
1686
1711
|
rejectRoot: false
|
|
1687
1712
|
});
|
|
1688
1713
|
}
|
|
1689
1714
|
async followupTask(actor, input) {
|
|
1690
1715
|
return this.#deliverAgentMessage(actor, input, {
|
|
1691
|
-
type:
|
|
1692
|
-
mode:
|
|
1716
|
+
type: InterAgentCommunicationTypes.NewTask,
|
|
1717
|
+
mode: MessageDeliveryModes.TriggerTurn,
|
|
1693
1718
|
rejectRoot: true
|
|
1694
1719
|
});
|
|
1695
1720
|
}
|
|
@@ -1764,7 +1789,7 @@ var AgentControlPlane = class _AgentControlPlane {
|
|
|
1764
1789
|
"followup_task: the root agent cannot receive a follow-up"
|
|
1765
1790
|
);
|
|
1766
1791
|
}
|
|
1767
|
-
if (options.mode ===
|
|
1792
|
+
if (options.mode === MessageDeliveryModes.TriggerTurn && await this.#queue.getTurnActivity(target.conversation) !== "running" && !await this.#hasExecutionCapacity(actor.thread)) {
|
|
1768
1793
|
throw new Error("collab tool failed: agent thread limit reached");
|
|
1769
1794
|
}
|
|
1770
1795
|
const message = createInterAgentCommunication({
|
|
@@ -1780,7 +1805,7 @@ var AgentControlPlane = class _AgentControlPlane {
|
|
|
1780
1805
|
await this.#mailbox.deliver(message, options.mode);
|
|
1781
1806
|
await this.#recordActivity(target.path.isRoot ? actor.thread : target, {
|
|
1782
1807
|
id: message.id,
|
|
1783
|
-
type: options.mode ===
|
|
1808
|
+
type: options.mode === MessageDeliveryModes.TriggerTurn ? "followup" : "message",
|
|
1784
1809
|
at: Date.now(),
|
|
1785
1810
|
actorPath: actor.thread.path.toString(),
|
|
1786
1811
|
targetPath: target.path.toString(),
|
|
@@ -1822,8 +1847,8 @@ var MailboxCoordinator = class {
|
|
|
1822
1847
|
async deliver(communication, mode) {
|
|
1823
1848
|
const delivered = {
|
|
1824
1849
|
...communication,
|
|
1825
|
-
type: mode ===
|
|
1826
|
-
triggerTurn: mode ===
|
|
1850
|
+
type: mode === MessageDeliveryModes.TriggerTurn ? InterAgentCommunicationTypes.NewTask : communication.type,
|
|
1851
|
+
triggerTurn: mode === MessageDeliveryModes.TriggerTurn
|
|
1827
1852
|
};
|
|
1828
1853
|
assertCommunication(delivered);
|
|
1829
1854
|
const { recipientActive } = await this.#store.enqueue(delivered);
|
|
@@ -1957,7 +1982,7 @@ function resolveMultiAgentHostConfig(input = {}) {
|
|
|
1957
1982
|
}
|
|
1958
1983
|
if (toolNamespace !== void 0) validateToolNamespace(toolNamespace);
|
|
1959
1984
|
const codeMode = input.nonCodeModeOnly === false;
|
|
1960
|
-
const
|
|
1985
|
+
const tool7 = (name) => codeMode ? `tools.${name}` : toolNamespace === void 0 ? name : `${toolNamespace}.${name}`;
|
|
1961
1986
|
const collaborationTools = [
|
|
1962
1987
|
"spawn_agent",
|
|
1963
1988
|
"send_message",
|
|
@@ -1965,7 +1990,7 @@ function resolveMultiAgentHostConfig(input = {}) {
|
|
|
1965
1990
|
"wait_agent",
|
|
1966
1991
|
"interrupt_agent",
|
|
1967
1992
|
"list_agents"
|
|
1968
|
-
].map((name) => `\`${
|
|
1993
|
+
].map((name) => `\`${tool7(name)}\``).join(", ");
|
|
1969
1994
|
const shared = codeMode ? `Call ${collaborationTools} from \`code_mode\`.
|
|
1970
1995
|
|
|
1971
1996
|
All agents share the same workspace, current working directory, and filesystem.` : `Call ${collaborationTools} directly. They are intentionally unavailable inside nested code execution.
|
|
@@ -1977,8 +2002,8 @@ All agents share the same workspace, current working directory, and filesystem.`
|
|
|
1977
2002
|
maxWaitTimeoutMs,
|
|
1978
2003
|
maxConcurrentThreadsPerSession,
|
|
1979
2004
|
usageHintText: nonEmptyText(input.usageHintText),
|
|
1980
|
-
rootAgentUsageHintText: input.rootAgentUsageHintText === void 0 ? defaultRootUsageHint(
|
|
1981
|
-
subagentUsageHintText: input.subagentUsageHintText === void 0 ? defaultSubagentUsageHint(
|
|
2005
|
+
rootAgentUsageHintText: input.rootAgentUsageHintText === void 0 ? defaultRootUsageHint(tool7, shared, maxConcurrentThreadsPerSession) : nonEmptyText(input.rootAgentUsageHintText),
|
|
2006
|
+
subagentUsageHintText: input.subagentUsageHintText === void 0 ? defaultSubagentUsageHint(tool7, shared, maxConcurrentThreadsPerSession) : nonEmptyText(input.subagentUsageHintText),
|
|
1982
2007
|
toolNamespace,
|
|
1983
2008
|
codeMode
|
|
1984
2009
|
};
|
|
@@ -2001,12 +2026,12 @@ function nonEmptyText(value) {
|
|
|
2001
2026
|
if (value === void 0) return void 0;
|
|
2002
2027
|
return value.length === 0 ? void 0 : value;
|
|
2003
2028
|
}
|
|
2004
|
-
function defaultRootUsageHint(
|
|
2029
|
+
function defaultRootUsageHint(tool7, shared, maxConcurrency) {
|
|
2005
2030
|
return `You are \`/root\`, the primary agent in a team of agents collaborating to fulfill the user's goals.
|
|
2006
2031
|
|
|
2007
2032
|
At the start of your turn, you are the active agent. You can spawn sub-agents to handle subtasks, and those agents can recursively spawn their own declared sub-agents. All agents are equally capable and receive the tools declared for their agent type.
|
|
2008
2033
|
|
|
2009
|
-
Use \`${
|
|
2034
|
+
Use \`${tool7("spawn_agent")}\` to create an agent, \`${tool7("followup_task")}\` to assign a new task and trigger a turn, and \`${tool7("send_message")}\` to queue a message without triggering a turn. Every spawn must set \`fork_turns\` to \`none\`, \`all\`, or a positive count of recent turns.
|
|
2010
2035
|
|
|
2011
2036
|
Child messages arrive as \`MESSAGE\` or \`FINAL_ANSWER\` mailbox envelopes with their task name, sender, and payload preserved.
|
|
2012
2037
|
|
|
@@ -2016,10 +2041,10 @@ ${WAIT_AGENT_USAGE_HINT_TEXT}
|
|
|
2016
2041
|
|
|
2017
2042
|
${concurrencySlotsText(maxConcurrency)}`;
|
|
2018
2043
|
}
|
|
2019
|
-
function defaultSubagentUsageHint(
|
|
2044
|
+
function defaultSubagentUsageHint(tool7, shared, maxConcurrency) {
|
|
2020
2045
|
return `You are an agent in a team collaborating to complete a task.
|
|
2021
2046
|
|
|
2022
|
-
You can spawn declared sub-agents recursively. All agents are equally capable and receive the tools declared for their agent type. Use \`${
|
|
2047
|
+
You can spawn declared sub-agents recursively. All agents are equally capable and receive the tools declared for their agent type. Use \`${tool7("spawn_agent")}\` to create one, \`${tool7("followup_task")}\` to assign a new task and trigger a turn, and \`${tool7("send_message")}\` to queue a message for another agent.
|
|
2023
2048
|
|
|
2024
2049
|
Your final response is delivered automatically to your parent agent. Mailbox messages arrive as \`NEW_TASK\`, \`MESSAGE\`, or \`FINAL_ANSWER\` envelopes with their task name, sender, and payload preserved.
|
|
2025
2050
|
|
|
@@ -2058,7 +2083,7 @@ import {
|
|
|
2058
2083
|
modelMessageSchema as modelMessageSchema2
|
|
2059
2084
|
} from "ai";
|
|
2060
2085
|
import { createHash, randomUUID as randomUUID2 } from "node:crypto";
|
|
2061
|
-
import { z as
|
|
2086
|
+
import { z as z4 } from "zod";
|
|
2062
2087
|
|
|
2063
2088
|
// packages/compaction/dist/index.js
|
|
2064
2089
|
import {
|
|
@@ -2260,25 +2285,25 @@ ${options.instructions}` : SUMMARY_PROMPT,
|
|
|
2260
2285
|
}
|
|
2261
2286
|
|
|
2262
2287
|
// packages/experimental/src/zukhruf/runtime/compaction.ts
|
|
2263
|
-
var checkpointSchema =
|
|
2264
|
-
sourceCount:
|
|
2265
|
-
sourceHash:
|
|
2266
|
-
replacement:
|
|
2288
|
+
var checkpointSchema = z4.object({
|
|
2289
|
+
sourceCount: z4.number().int().positive(),
|
|
2290
|
+
sourceHash: z4.string(),
|
|
2291
|
+
replacement: z4.array(z4.unknown()).transform(
|
|
2267
2292
|
(messages) => messages.map((message) => modelMessageSchema2.parse(message))
|
|
2268
2293
|
)
|
|
2269
2294
|
});
|
|
2270
|
-
var cacheObservationSchema =
|
|
2271
|
-
scope:
|
|
2272
|
-
prefixLength:
|
|
2273
|
-
prefixHash:
|
|
2274
|
-
startedAt:
|
|
2275
|
-
retentionMs:
|
|
2295
|
+
var cacheObservationSchema = z4.object({
|
|
2296
|
+
scope: z4.string(),
|
|
2297
|
+
prefixLength: z4.number().int().nonnegative(),
|
|
2298
|
+
prefixHash: z4.string(),
|
|
2299
|
+
startedAt: z4.number().int().nonnegative(),
|
|
2300
|
+
retentionMs: z4.number().int().positive().optional()
|
|
2276
2301
|
});
|
|
2277
|
-
var inputUsageSchema = cacheObservationSchema.pick({ scope: true, prefixLength: true, prefixHash: true }).extend({ inputTokens:
|
|
2302
|
+
var inputUsageSchema = cacheObservationSchema.pick({ scope: true, prefixLength: true, prefixHash: true }).extend({ inputTokens: z4.number().int().nonnegative() });
|
|
2278
2303
|
function hash(value) {
|
|
2279
2304
|
return createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
2280
2305
|
}
|
|
2281
|
-
function
|
|
2306
|
+
function isRecord4(value) {
|
|
2282
2307
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2283
2308
|
}
|
|
2284
2309
|
function cacheRetentionMs(step) {
|
|
@@ -2290,14 +2315,14 @@ function cacheRetentionMs(step) {
|
|
|
2290
2315
|
return void 0;
|
|
2291
2316
|
}
|
|
2292
2317
|
}
|
|
2293
|
-
if (!
|
|
2318
|
+
if (!isRecord4(body)) return void 0;
|
|
2294
2319
|
const provider = step.model.provider;
|
|
2295
2320
|
const routed = provider === "openrouter" || provider === "openrouter.chat";
|
|
2296
2321
|
const upstream = routed ? step.providerMetadata?.openrouter?.provider : void 0;
|
|
2297
2322
|
if (provider === "openai.responses" || provider === "openai.chat" || routed && upstream === "OpenAI") {
|
|
2298
2323
|
const options = body.prompt_cache_options;
|
|
2299
|
-
if (options !== void 0 && !
|
|
2300
|
-
if (
|
|
2324
|
+
if (options !== void 0 && !isRecord4(options)) return void 0;
|
|
2325
|
+
if (isRecord4(options) && options.ttl !== void 0) {
|
|
2301
2326
|
return options.ttl === "30m" ? 30 * 6e4 : void 0;
|
|
2302
2327
|
}
|
|
2303
2328
|
const version = /^(?:openai\/)?gpt-(\d+)(?:\.(\d+))?(?:-|$)/.exec(
|
|
@@ -2317,18 +2342,18 @@ function cacheRetentionMs(step) {
|
|
|
2317
2342
|
}
|
|
2318
2343
|
const windows = [];
|
|
2319
2344
|
for (const block of blocks) {
|
|
2320
|
-
if (!
|
|
2345
|
+
if (!isRecord4(block)) continue;
|
|
2321
2346
|
if (Array.isArray(block.content)) blocks.push(...block.content);
|
|
2322
2347
|
const control = block.cache_control;
|
|
2323
2348
|
if (control === void 0) continue;
|
|
2324
|
-
if (!
|
|
2349
|
+
if (!isRecord4(control) || control.type !== "ephemeral") return void 0;
|
|
2325
2350
|
if (control.ttl === void 0 || control.ttl === "5m")
|
|
2326
2351
|
windows.push(5 * 6e4);
|
|
2327
2352
|
else if (control.ttl === "1h") windows.push(60 * 6e4);
|
|
2328
2353
|
else return void 0;
|
|
2329
2354
|
}
|
|
2330
2355
|
const creation = step.usage.raw?.cache_creation;
|
|
2331
|
-
if (
|
|
2356
|
+
if (isRecord4(creation)) {
|
|
2332
2357
|
if (typeof creation.ephemeral_1h_input_tokens === "number" && creation.ephemeral_1h_input_tokens > 0)
|
|
2333
2358
|
return 60 * 6e4;
|
|
2334
2359
|
if (step.usage.inputTokenDetails.cacheReadTokens === 0 && creation.ephemeral_1h_input_tokens === 0 && typeof creation.ephemeral_5m_input_tokens === "number" && creation.ephemeral_5m_input_tokens > 0)
|
|
@@ -2351,20 +2376,21 @@ function createCompaction(config, engine, store, signal, onEvent) {
|
|
|
2351
2376
|
settings = input;
|
|
2352
2377
|
};
|
|
2353
2378
|
const envelope = async (input) => {
|
|
2379
|
+
const toolsContext = input.toolsContext;
|
|
2354
2380
|
const tools = settings.tools === void 0 ? [] : await Promise.all(
|
|
2355
2381
|
Object.entries(settings.tools).filter(
|
|
2356
2382
|
([name]) => settings.activeTools === void 0 || settings.activeTools.includes(name)
|
|
2357
|
-
).map(async ([name,
|
|
2383
|
+
).map(async ([name, tool7]) => [
|
|
2358
2384
|
name,
|
|
2359
|
-
|
|
2360
|
-
typeof
|
|
2361
|
-
context:
|
|
2385
|
+
tool7.type === "provider" ? [tool7.id, tool7.args] : [
|
|
2386
|
+
typeof tool7.description === "function" ? tool7.description({
|
|
2387
|
+
context: toolsContext[name],
|
|
2362
2388
|
experimental_sandbox: input.experimental_sandbox
|
|
2363
|
-
}) :
|
|
2364
|
-
await asSchema(
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2389
|
+
}) : tool7.description,
|
|
2390
|
+
await asSchema(tool7.inputSchema).jsonSchema,
|
|
2391
|
+
tool7.providerOptions,
|
|
2392
|
+
tool7.inputExamples,
|
|
2393
|
+
tool7.strict
|
|
2368
2394
|
]
|
|
2369
2395
|
])
|
|
2370
2396
|
);
|
|
@@ -2403,10 +2429,10 @@ function createCompaction(config, engine, store, signal, onEvent) {
|
|
|
2403
2429
|
if (!initialized) {
|
|
2404
2430
|
const chat2 = await store.getChat(engine.chatId);
|
|
2405
2431
|
const metadata = chat2?.metadata?.zukhruf;
|
|
2406
|
-
const saved =
|
|
2407
|
-
const savedCache =
|
|
2432
|
+
const saved = isRecord4(metadata) ? metadata.compaction : void 0;
|
|
2433
|
+
const savedCache = isRecord4(metadata) ? metadata.promptCache : void 0;
|
|
2408
2434
|
baseline = inputUsageSchema.safeParse(
|
|
2409
|
-
|
|
2435
|
+
isRecord4(metadata) ? metadata.inputUsage : void 0
|
|
2410
2436
|
).data ?? null;
|
|
2411
2437
|
if (savedCache !== void 0) {
|
|
2412
2438
|
cache = cacheObservationSchema.nullable().parse(savedCache);
|
|
@@ -2513,7 +2539,7 @@ function createCompaction(config, engine, store, signal, onEvent) {
|
|
|
2513
2539
|
metadata: {
|
|
2514
2540
|
...metadata,
|
|
2515
2541
|
zukhruf: {
|
|
2516
|
-
...
|
|
2542
|
+
...isRecord4(metadata?.zukhruf) ? metadata.zukhruf : {},
|
|
2517
2543
|
compaction: checkpoint,
|
|
2518
2544
|
inputUsage: null
|
|
2519
2545
|
}
|
|
@@ -2548,7 +2574,7 @@ function createCompaction(config, engine, store, signal, onEvent) {
|
|
|
2548
2574
|
const onStepEnd = async (step) => {
|
|
2549
2575
|
if (signal.aborted || step.finishReason === "error") return;
|
|
2550
2576
|
const iterations = step.usage.raw?.iterations;
|
|
2551
|
-
const ambiguous = iterations != null && (!Array.isArray(iterations) || iterations.length !== 1 || !
|
|
2577
|
+
const ambiguous = iterations != null && (!Array.isArray(iterations) || iterations.length !== 1 || !isRecord4(iterations[0]) || iterations[0].type !== "message") || step.content.some(
|
|
2552
2578
|
(part) => part.type === "custom" && part.kind === "openai.compaction" || part.type === "text" && part.providerMetadata?.anthropic?.type === "compaction"
|
|
2553
2579
|
);
|
|
2554
2580
|
const nextBaseline = ambiguous ? null : inputUsageSchema.safeParse({
|
|
@@ -2563,7 +2589,7 @@ function createCompaction(config, engine, store, signal, onEvent) {
|
|
|
2563
2589
|
metadata: {
|
|
2564
2590
|
...metadata,
|
|
2565
2591
|
zukhruf: {
|
|
2566
|
-
...
|
|
2592
|
+
...isRecord4(metadata?.zukhruf) ? metadata.zukhruf : {},
|
|
2567
2593
|
promptCache: next,
|
|
2568
2594
|
inputUsage: nextBaseline
|
|
2569
2595
|
}
|
|
@@ -3014,7 +3040,7 @@ var AgentTurnExecutor = class {
|
|
|
3014
3040
|
if (turn.kind === "message" && turn.elements !== void 0) {
|
|
3015
3041
|
const declared = turn.elements;
|
|
3016
3042
|
await this.#store.updateChat(turn.chatId, ({ metadata }) => {
|
|
3017
|
-
const zukhruf =
|
|
3043
|
+
const zukhruf = isRecord5(metadata?.zukhruf) ? metadata.zukhruf : {};
|
|
3018
3044
|
if (isDeepStrictEqual(zukhruf.elements, declared)) return void 0;
|
|
3019
3045
|
return {
|
|
3020
3046
|
metadata: {
|
|
@@ -3044,7 +3070,7 @@ var AgentTurnExecutor = class {
|
|
|
3044
3070
|
available = persisted;
|
|
3045
3071
|
return void 0;
|
|
3046
3072
|
}
|
|
3047
|
-
const zukhruf =
|
|
3073
|
+
const zukhruf = isRecord5(metadata?.zukhruf) ? metadata.zukhruf : {};
|
|
3048
3074
|
return {
|
|
3049
3075
|
metadata: {
|
|
3050
3076
|
...metadata,
|
|
@@ -3114,7 +3140,7 @@ ${communication.content}`;
|
|
|
3114
3140
|
};
|
|
3115
3141
|
function readElements(metadata) {
|
|
3116
3142
|
const zukhruf = metadata?.zukhruf;
|
|
3117
|
-
if (!
|
|
3143
|
+
if (!isRecord5(zukhruf) || !Object.hasOwn(zukhruf, "elements")) {
|
|
3118
3144
|
return void 0;
|
|
3119
3145
|
}
|
|
3120
3146
|
const parsed = elementsSchema.safeParse(zukhruf.elements);
|
|
@@ -3125,7 +3151,7 @@ function readElements(metadata) {
|
|
|
3125
3151
|
}
|
|
3126
3152
|
function readSkills(metadata) {
|
|
3127
3153
|
const zukhruf = metadata?.zukhruf;
|
|
3128
|
-
if (!
|
|
3154
|
+
if (!isRecord5(zukhruf) || !Object.hasOwn(zukhruf, "skills")) {
|
|
3129
3155
|
return void 0;
|
|
3130
3156
|
}
|
|
3131
3157
|
if (!Array.isArray(zukhruf.skills) || !zukhruf.skills.every(isSkill)) {
|
|
@@ -3134,9 +3160,9 @@ function readSkills(metadata) {
|
|
|
3134
3160
|
return zukhruf.skills;
|
|
3135
3161
|
}
|
|
3136
3162
|
function isSkill(value) {
|
|
3137
|
-
return
|
|
3163
|
+
return isRecord5(value) && typeof value.name === "string" && typeof value.description === "string" && typeof value.path === "string";
|
|
3138
3164
|
}
|
|
3139
|
-
function
|
|
3165
|
+
function isRecord5(value) {
|
|
3140
3166
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3141
3167
|
}
|
|
3142
3168
|
|
|
@@ -3255,8 +3281,8 @@ var ApprovalController = class _ApprovalController {
|
|
|
3255
3281
|
(part) => isToolUIPart(part) && part.state === "approval-responded" && part.approval.approved === true
|
|
3256
3282
|
);
|
|
3257
3283
|
const retryable = approved.length > 0 && approved.every((part) => {
|
|
3258
|
-
const
|
|
3259
|
-
return
|
|
3284
|
+
const tool7 = tools[getToolName(part)];
|
|
3285
|
+
return tool7?.recovery === "idempotent" && typeof tool7.execute === "function";
|
|
3260
3286
|
});
|
|
3261
3287
|
if (!retryable) return false;
|
|
3262
3288
|
await this.#queue.push({
|
|
@@ -3302,25 +3328,31 @@ import {
|
|
|
3302
3328
|
} from "@deepagents/context";
|
|
3303
3329
|
|
|
3304
3330
|
// packages/experimental/src/zukhruf/runtime/conversation-status/child-progress.ts
|
|
3305
|
-
import { z as
|
|
3306
|
-
var childActivitySchema =
|
|
3307
|
-
id:
|
|
3308
|
-
type:
|
|
3309
|
-
at:
|
|
3310
|
-
actorPath:
|
|
3311
|
-
targetPath:
|
|
3312
|
-
streamId:
|
|
3313
|
-
outcome:
|
|
3331
|
+
import { z as z5 } from "zod";
|
|
3332
|
+
var childActivitySchema = z5.object({
|
|
3333
|
+
id: z5.string(),
|
|
3334
|
+
type: z5.enum(["spawn", "message", "followup", "interrupt", "completion"]),
|
|
3335
|
+
at: z5.number(),
|
|
3336
|
+
actorPath: z5.string(),
|
|
3337
|
+
targetPath: z5.string(),
|
|
3338
|
+
streamId: z5.string(),
|
|
3339
|
+
outcome: z5.enum(["completed", "failed", "cancelled"]).optional()
|
|
3314
3340
|
});
|
|
3315
|
-
var childActivitiesSchema =
|
|
3341
|
+
var childActivitiesSchema = z5.partialRecord(
|
|
3316
3342
|
childActivitySchema.shape.type,
|
|
3317
3343
|
childActivitySchema
|
|
3318
3344
|
);
|
|
3319
|
-
var childActivityMetadataSchema =
|
|
3345
|
+
var childActivityMetadataSchema = z5.looseObject({
|
|
3320
3346
|
childActivities: childActivitiesSchema.default({})
|
|
3321
3347
|
});
|
|
3322
3348
|
|
|
3323
3349
|
// packages/experimental/src/zukhruf/runtime/conversation-status/projector.ts
|
|
3350
|
+
var ProjectorEventDelivery = class {
|
|
3351
|
+
event;
|
|
3352
|
+
constructor(event) {
|
|
3353
|
+
this.event = event;
|
|
3354
|
+
}
|
|
3355
|
+
};
|
|
3324
3356
|
var ConversationStatusProjector = class _ConversationStatusProjector {
|
|
3325
3357
|
#store;
|
|
3326
3358
|
#streams;
|
|
@@ -3445,10 +3477,12 @@ var ConversationStatusProjector = class _ConversationStatusProjector {
|
|
|
3445
3477
|
return {
|
|
3446
3478
|
async *[Symbol.asyncIterator]() {
|
|
3447
3479
|
try {
|
|
3448
|
-
for await (const
|
|
3449
|
-
const
|
|
3450
|
-
if (
|
|
3451
|
-
|
|
3480
|
+
for await (const args of events) {
|
|
3481
|
+
const [delivery] = args;
|
|
3482
|
+
if (!(delivery instanceof ProjectorEventDelivery)) continue;
|
|
3483
|
+
const { event } = delivery;
|
|
3484
|
+
if (event.type === "error") throw event.error;
|
|
3485
|
+
yield event;
|
|
3452
3486
|
}
|
|
3453
3487
|
} finally {
|
|
3454
3488
|
await detach();
|
|
@@ -3492,7 +3526,7 @@ var ConversationStatusProjector = class _ConversationStatusProjector {
|
|
|
3492
3526
|
}
|
|
3493
3527
|
if (isDeepStrictEqual2(this.#last.get(key), change)) return false;
|
|
3494
3528
|
this.#last.set(key, change);
|
|
3495
|
-
this.#
|
|
3529
|
+
this.#emit(change);
|
|
3496
3530
|
return true;
|
|
3497
3531
|
}
|
|
3498
3532
|
async #attachRemote() {
|
|
@@ -3529,13 +3563,13 @@ var ConversationStatusProjector = class _ConversationStatusProjector {
|
|
|
3529
3563
|
ready.resolve();
|
|
3530
3564
|
for await (const event of events) {
|
|
3531
3565
|
if (event.type === "reset") {
|
|
3532
|
-
this.#
|
|
3566
|
+
this.#emit(event);
|
|
3533
3567
|
} else {
|
|
3534
3568
|
await this.#reconcile(event.conversation);
|
|
3535
3569
|
}
|
|
3536
3570
|
}
|
|
3537
3571
|
if (!remote.abort.signal.aborted) {
|
|
3538
|
-
this.#
|
|
3572
|
+
this.#emit({
|
|
3539
3573
|
type: "error",
|
|
3540
3574
|
error: new Error("Conversation status change source ended")
|
|
3541
3575
|
});
|
|
@@ -3543,15 +3577,15 @@ var ConversationStatusProjector = class _ConversationStatusProjector {
|
|
|
3543
3577
|
} catch (error) {
|
|
3544
3578
|
if (!connected) ready.reject(error);
|
|
3545
3579
|
if (connected && !(error instanceof Error && error.name === "AbortError")) {
|
|
3546
|
-
this.#
|
|
3547
|
-
type: "error",
|
|
3548
|
-
error
|
|
3549
|
-
});
|
|
3580
|
+
this.#emit({ type: "error", error });
|
|
3550
3581
|
}
|
|
3551
3582
|
} finally {
|
|
3552
3583
|
if (this.#remote === remote) this.#remote = void 0;
|
|
3553
3584
|
}
|
|
3554
3585
|
}
|
|
3586
|
+
#emit(event) {
|
|
3587
|
+
this.#emitter.emit("event", new ProjectorEventDelivery(event));
|
|
3588
|
+
}
|
|
3555
3589
|
static #key({ chatId, userId }) {
|
|
3556
3590
|
return JSON.stringify([chatId, userId]);
|
|
3557
3591
|
}
|
|
@@ -3595,13 +3629,13 @@ var StatusPublishingTurnQueue = class extends TurnQueue {
|
|
|
3595
3629
|
|
|
3596
3630
|
// packages/experimental/src/zukhruf/collaboration/interrupt-agent.ts
|
|
3597
3631
|
import { tool as tool2 } from "ai";
|
|
3598
|
-
import { z as
|
|
3599
|
-
var interruptAgentInputSchema =
|
|
3600
|
-
target:
|
|
3632
|
+
import { z as z6 } from "zod";
|
|
3633
|
+
var interruptAgentInputSchema = z6.object({
|
|
3634
|
+
target: z6.string().trim().min(1).describe(
|
|
3601
3635
|
"The canonical /root/... path, or a descendant-relative target name."
|
|
3602
3636
|
)
|
|
3603
3637
|
});
|
|
3604
|
-
var interruptAgentOutputSchema =
|
|
3638
|
+
var interruptAgentOutputSchema = z6.object({ previous_status: listedAgentStatusSchema }).strict();
|
|
3605
3639
|
var interruptAgentTool = tool2({
|
|
3606
3640
|
description: "Interrupt an agent's current turn, if any, and return its previous status. The agent remains available for messages and follow-up tasks.",
|
|
3607
3641
|
inputSchema: interruptAgentInputSchema,
|
|
@@ -3611,13 +3645,13 @@ var interruptAgentTool = tool2({
|
|
|
3611
3645
|
|
|
3612
3646
|
// packages/experimental/src/zukhruf/collaboration/list-agents.ts
|
|
3613
3647
|
import { tool as tool3 } from "ai";
|
|
3614
|
-
import { z as
|
|
3615
|
-
var listAgentsInputSchema =
|
|
3616
|
-
path_prefix:
|
|
3648
|
+
import { z as z7 } from "zod";
|
|
3649
|
+
var listAgentsInputSchema = z7.object({
|
|
3650
|
+
path_prefix: z7.string().trim().min(1).describe(
|
|
3617
3651
|
"Task-path prefix without a trailing slash. Omit to list the whole tree."
|
|
3618
3652
|
).optional()
|
|
3619
3653
|
});
|
|
3620
|
-
var listAgentsOutputSchema =
|
|
3654
|
+
var listAgentsOutputSchema = z7.object({ agents: z7.array(listedAgentSchema) }).strict();
|
|
3621
3655
|
var listAgentsTool = tool3({
|
|
3622
3656
|
description: "List live agents in the current root thread tree. Optionally filter by task-path prefix.",
|
|
3623
3657
|
inputSchema: listAgentsInputSchema,
|
|
@@ -3627,12 +3661,12 @@ var listAgentsTool = tool3({
|
|
|
3627
3661
|
|
|
3628
3662
|
// packages/experimental/src/zukhruf/collaboration/message-tools.ts
|
|
3629
3663
|
import { tool as tool4 } from "ai";
|
|
3630
|
-
import { z as
|
|
3631
|
-
var agentMessageInputSchema =
|
|
3632
|
-
target:
|
|
3664
|
+
import { z as z8 } from "zod";
|
|
3665
|
+
var agentMessageInputSchema = z8.object({
|
|
3666
|
+
target: z8.string().trim().min(1).describe(
|
|
3633
3667
|
"The canonical /root/... path, or a descendant-relative target name."
|
|
3634
3668
|
),
|
|
3635
|
-
message:
|
|
3669
|
+
message: z8.string().trim().min(1).describe("The message or follow-up task.")
|
|
3636
3670
|
});
|
|
3637
3671
|
var sendMessageTool = tool4({
|
|
3638
3672
|
description: "Queue a message for another agent. Address siblings with their canonical /root/... path.",
|
|
@@ -3653,7 +3687,7 @@ var followupTaskTool = tool4({
|
|
|
3653
3687
|
|
|
3654
3688
|
// packages/experimental/src/zukhruf/collaboration/spawn-agent.ts
|
|
3655
3689
|
import { tool as tool5 } from "ai";
|
|
3656
|
-
import { z as
|
|
3690
|
+
import { z as z9 } from "zod";
|
|
3657
3691
|
|
|
3658
3692
|
// packages/experimental/src/zukhruf/control-plane/fork-turns.ts
|
|
3659
3693
|
var forkTurnsError = "fork_turns must be `none`, `all`, or a positive integer string";
|
|
@@ -3666,18 +3700,18 @@ function parseForkTurns(value) {
|
|
|
3666
3700
|
}
|
|
3667
3701
|
|
|
3668
3702
|
// packages/experimental/src/zukhruf/collaboration/spawn-agent.ts
|
|
3669
|
-
var spawnAgentInputSchema =
|
|
3670
|
-
agent_type:
|
|
3671
|
-
task_name:
|
|
3703
|
+
var spawnAgentInputSchema = z9.object({
|
|
3704
|
+
agent_type: z9.string().trim().min(1).describe("The name of one available subagent declaration."),
|
|
3705
|
+
task_name: z9.string().trim().min(1).refine(
|
|
3672
3706
|
(value) => value !== "." && value !== ".." && !value.includes("/"),
|
|
3673
3707
|
"task_name must be one non-empty path segment"
|
|
3674
3708
|
).describe("One path segment naming this independent agent task."),
|
|
3675
|
-
message:
|
|
3676
|
-
fork_turns:
|
|
3709
|
+
message: z9.string().refine((value) => value.trim().length > 0, "message cannot be empty").describe("The initial task for the spawned agent."),
|
|
3710
|
+
fork_turns: z9.string().trim().refine((value) => parseForkTurns(value) !== void 0, forkTurnsError).describe(
|
|
3677
3711
|
"Required number of parent turns to fork. Use `none`, `all`, or a positive integer string such as `3`."
|
|
3678
3712
|
)
|
|
3679
3713
|
});
|
|
3680
|
-
var spawnAgentOutputSchema =
|
|
3714
|
+
var spawnAgentOutputSchema = z9.object({ task_name: z9.string() }).strict();
|
|
3681
3715
|
function createSpawnAgentTool(options) {
|
|
3682
3716
|
return tool5({
|
|
3683
3717
|
description: ({ context }) => {
|
|
@@ -3706,11 +3740,11 @@ function createSpawnAgentTool(options) {
|
|
|
3706
3740
|
|
|
3707
3741
|
// packages/experimental/src/zukhruf/collaboration/wait-agent.ts
|
|
3708
3742
|
import { tool as tool6 } from "ai";
|
|
3709
|
-
import { z as
|
|
3710
|
-
var waitAgentOutputSchema =
|
|
3743
|
+
import { z as z10 } from "zod";
|
|
3744
|
+
var waitAgentOutputSchema = z10.object({ message: z10.string(), timed_out: z10.boolean() }).strict();
|
|
3711
3745
|
function createWaitAgentTool(options) {
|
|
3712
|
-
const waitAgentInputSchema =
|
|
3713
|
-
timeout_ms:
|
|
3746
|
+
const waitAgentInputSchema = z10.object({
|
|
3747
|
+
timeout_ms: z10.number().int().max(options.maxTimeoutMs).optional().describe("Maximum time to wait in milliseconds.")
|
|
3714
3748
|
});
|
|
3715
3749
|
return tool6({
|
|
3716
3750
|
description: "Wait for pending mail addressed to this agent without consuming it.",
|
|
@@ -3925,7 +3959,7 @@ var PluginAgentComposition = class {
|
|
|
3925
3959
|
|
|
3926
3960
|
// packages/experimental/src/zukhruf/runtime/plugin/plugin-bindings.ts
|
|
3927
3961
|
var PluginBindings = class {
|
|
3928
|
-
#
|
|
3962
|
+
#bindings;
|
|
3929
3963
|
constructor(definitions, bindings) {
|
|
3930
3964
|
const pluginNames = /* @__PURE__ */ new Set();
|
|
3931
3965
|
const capabilities = /* @__PURE__ */ new Map();
|
|
@@ -3979,7 +4013,7 @@ var PluginBindings = class {
|
|
|
3979
4013
|
}
|
|
3980
4014
|
}
|
|
3981
4015
|
}
|
|
3982
|
-
this.#
|
|
4016
|
+
this.#bindings = /* @__PURE__ */ new Map();
|
|
3983
4017
|
const bindingNames = /* @__PURE__ */ new Set();
|
|
3984
4018
|
if (bindings) {
|
|
3985
4019
|
for (const binding of bindings) {
|
|
@@ -3995,7 +4029,7 @@ var PluginBindings = class {
|
|
|
3995
4029
|
`AgentRuntime: unused binding for capability "${binding.capability.name}"`
|
|
3996
4030
|
);
|
|
3997
4031
|
}
|
|
3998
|
-
this.#
|
|
4032
|
+
this.#bindings.set(binding.capability, binding);
|
|
3999
4033
|
}
|
|
4000
4034
|
}
|
|
4001
4035
|
}
|
|
@@ -4003,7 +4037,7 @@ var PluginBindings = class {
|
|
|
4003
4037
|
const declared = new Set(definition.capabilities);
|
|
4004
4038
|
if (definition.capabilities) {
|
|
4005
4039
|
for (const capability of definition.capabilities) {
|
|
4006
|
-
if (!this.#
|
|
4040
|
+
if (!this.#bindings.has(capability)) {
|
|
4007
4041
|
throw new Error(
|
|
4008
4042
|
`AgentRuntime: plugin "${definition.name}" requires missing capability "${capability.name}"`
|
|
4009
4043
|
);
|
|
@@ -4017,7 +4051,13 @@ var PluginBindings = class {
|
|
|
4017
4051
|
`AgentRuntime: plugin "${definition.name}" did not declare capability "${capability.name}"`
|
|
4018
4052
|
);
|
|
4019
4053
|
}
|
|
4020
|
-
|
|
4054
|
+
const binding = this.#bindings.get(capability);
|
|
4055
|
+
if (!binding) {
|
|
4056
|
+
throw new Error(
|
|
4057
|
+
`AgentRuntime: plugin "${definition.name}" requires missing capability "${capability.name}"`
|
|
4058
|
+
);
|
|
4059
|
+
}
|
|
4060
|
+
return capability.read(binding);
|
|
4021
4061
|
}
|
|
4022
4062
|
};
|
|
4023
4063
|
}
|
|
@@ -4049,7 +4089,7 @@ var PluginToolComposition = class {
|
|
|
4049
4089
|
this.#owners = new Map(reservedNames.map((name) => [name, "the runtime"]));
|
|
4050
4090
|
}
|
|
4051
4091
|
add(plugin, tools) {
|
|
4052
|
-
for (const [name,
|
|
4092
|
+
for (const [name, tool7] of Object.entries(tools)) {
|
|
4053
4093
|
const owner = this.#owners.get(name);
|
|
4054
4094
|
if (owner) {
|
|
4055
4095
|
throw new Error(
|
|
@@ -4057,7 +4097,7 @@ var PluginToolComposition = class {
|
|
|
4057
4097
|
);
|
|
4058
4098
|
}
|
|
4059
4099
|
this.#owners.set(name, `plugin "${plugin}"`);
|
|
4060
|
-
this.#tools[name] =
|
|
4100
|
+
this.#tools[name] = tool7;
|
|
4061
4101
|
}
|
|
4062
4102
|
}
|
|
4063
4103
|
compose(declarations) {
|
|
@@ -4077,6 +4117,9 @@ var PluginToolComposition = class {
|
|
|
4077
4117
|
};
|
|
4078
4118
|
|
|
4079
4119
|
// packages/experimental/src/zukhruf/runtime/plugin/plugin-manager.ts
|
|
4120
|
+
function createdFrom(plugin, definition) {
|
|
4121
|
+
return plugin.definition === definition;
|
|
4122
|
+
}
|
|
4080
4123
|
var PluginManager = class {
|
|
4081
4124
|
collaborationTools;
|
|
4082
4125
|
declarations;
|
|
@@ -4140,7 +4183,7 @@ var PluginManager = class {
|
|
|
4140
4183
|
}
|
|
4141
4184
|
get(definition) {
|
|
4142
4185
|
const plugin = this.#plugins.find(
|
|
4143
|
-
(
|
|
4186
|
+
(candidate) => createdFrom(candidate, definition)
|
|
4144
4187
|
);
|
|
4145
4188
|
if (!plugin) {
|
|
4146
4189
|
throw new Error(
|
|
@@ -4201,11 +4244,25 @@ var PluginManager = class {
|
|
|
4201
4244
|
// packages/experimental/src/zukhruf/runtime/agent-runtime.ts
|
|
4202
4245
|
var AgentPluginCapability = class {
|
|
4203
4246
|
name;
|
|
4247
|
+
/** Each value this capability bound, keyed by the binding that carries it. */
|
|
4248
|
+
#bound = /* @__PURE__ */ new WeakMap();
|
|
4204
4249
|
constructor(name) {
|
|
4205
4250
|
this.name = name;
|
|
4206
4251
|
}
|
|
4207
4252
|
bind(value) {
|
|
4208
|
-
|
|
4253
|
+
const binding = { capability: this, value };
|
|
4254
|
+
this.#bound.set(binding, { value });
|
|
4255
|
+
return binding;
|
|
4256
|
+
}
|
|
4257
|
+
/** Reads the value of a binding this capability created with `bind`. */
|
|
4258
|
+
read(binding) {
|
|
4259
|
+
const bound = this.#bound.get(binding);
|
|
4260
|
+
if (!bound) {
|
|
4261
|
+
throw new Error(
|
|
4262
|
+
`AgentRuntime: binding for capability "${this.name}" was not created by its bind()`
|
|
4263
|
+
);
|
|
4264
|
+
}
|
|
4265
|
+
return bound.value;
|
|
4209
4266
|
}
|
|
4210
4267
|
};
|
|
4211
4268
|
var AgentObservation = class {
|
|
@@ -4612,6 +4669,7 @@ var RuntimeHost = class {
|
|
|
4612
4669
|
|
|
4613
4670
|
// packages/experimental/src/zukhruf/queue/pg-boss-notifications.ts
|
|
4614
4671
|
import { EventEmitter as EventEmitter2, on as on2 } from "node:events";
|
|
4672
|
+
var RESET = /* @__PURE__ */ Symbol("reset");
|
|
4615
4673
|
async function pgBossNotifications(boss, channel, parse, signal) {
|
|
4616
4674
|
signal.throwIfAborted();
|
|
4617
4675
|
const db = boss.getDb();
|
|
@@ -4625,13 +4683,10 @@ async function pgBossNotifications(boss, channel, parse, signal) {
|
|
|
4625
4683
|
const handle = await listen(
|
|
4626
4684
|
channel,
|
|
4627
4685
|
(payload) => {
|
|
4628
|
-
|
|
4629
|
-
if (value !== void 0) {
|
|
4630
|
-
emitter.emit("notification", { type: "change", value });
|
|
4631
|
-
}
|
|
4686
|
+
emitter.emit("notification", payload);
|
|
4632
4687
|
},
|
|
4633
4688
|
() => {
|
|
4634
|
-
if (ready) emitter.emit("notification",
|
|
4689
|
+
if (ready) emitter.emit("notification", RESET);
|
|
4635
4690
|
}
|
|
4636
4691
|
);
|
|
4637
4692
|
ready = true;
|
|
@@ -4642,8 +4697,14 @@ async function pgBossNotifications(boss, channel, parse, signal) {
|
|
|
4642
4697
|
return {
|
|
4643
4698
|
async *[Symbol.asyncIterator]() {
|
|
4644
4699
|
try {
|
|
4645
|
-
for await (const
|
|
4646
|
-
|
|
4700
|
+
for await (const event of notifications) {
|
|
4701
|
+
const [payload] = event;
|
|
4702
|
+
if (payload === RESET) {
|
|
4703
|
+
yield { type: "reset" };
|
|
4704
|
+
} else if (typeof payload === "string") {
|
|
4705
|
+
const value = parse(payload);
|
|
4706
|
+
if (value !== void 0) yield { type: "change", value };
|
|
4707
|
+
}
|
|
4647
4708
|
}
|
|
4648
4709
|
} finally {
|
|
4649
4710
|
await handle.close();
|
|
@@ -4728,11 +4789,8 @@ function defineSandbox(createBackend, options) {
|
|
|
4728
4789
|
}
|
|
4729
4790
|
|
|
4730
4791
|
// packages/experimental/src/zukhruf/tool.ts
|
|
4731
|
-
import {
|
|
4732
|
-
tool as tool7
|
|
4733
|
-
} from "ai";
|
|
4734
4792
|
function defineTool(definition) {
|
|
4735
|
-
return
|
|
4793
|
+
return definition;
|
|
4736
4794
|
}
|
|
4737
4795
|
export {
|
|
4738
4796
|
AgentObservation,
|
|
@@ -4741,9 +4799,9 @@ export {
|
|
|
4741
4799
|
AgentRuntime,
|
|
4742
4800
|
AgentThread,
|
|
4743
4801
|
DEFAULT_CONVERSATION_STATUS_CHANNEL,
|
|
4744
|
-
|
|
4802
|
+
InterAgentCommunicationTypes,
|
|
4745
4803
|
MailboxStore,
|
|
4746
|
-
|
|
4804
|
+
MessageDeliveryModes,
|
|
4747
4805
|
PgBossConversationStatusChangeSource,
|
|
4748
4806
|
PgBossTurnQueue,
|
|
4749
4807
|
SqliteMailboxStore,
|