@deepagents/experimental 7.0.2 → 7.1.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 +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 +233 -180
- package/dist/index.js.map +3 -3
- package/dist/providers/account-tokens.d.ts +45 -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 +540 -52
- 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 +472 -168
- package/dist/providers/codex/index.js.map +4 -4
- package/dist/providers/codex/local-credentials.d.ts.map +1 -1
- 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 +231 -178
- 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 +18 -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 +173 -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 +10 -10
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({
|
|
@@ -3295,6 +3321,7 @@ var ApprovalController = class _ApprovalController {
|
|
|
3295
3321
|
};
|
|
3296
3322
|
|
|
3297
3323
|
// packages/experimental/src/zukhruf/runtime/conversation-status/projector.ts
|
|
3324
|
+
import { MemoryStore, Mutex } from "@zukhruf/mutex";
|
|
3298
3325
|
import { EventEmitter, on } from "node:events";
|
|
3299
3326
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
3300
3327
|
import {
|
|
@@ -3302,25 +3329,31 @@ import {
|
|
|
3302
3329
|
} from "@deepagents/context";
|
|
3303
3330
|
|
|
3304
3331
|
// 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:
|
|
3332
|
+
import { z as z5 } from "zod";
|
|
3333
|
+
var childActivitySchema = z5.object({
|
|
3334
|
+
id: z5.string(),
|
|
3335
|
+
type: z5.enum(["spawn", "message", "followup", "interrupt", "completion"]),
|
|
3336
|
+
at: z5.number(),
|
|
3337
|
+
actorPath: z5.string(),
|
|
3338
|
+
targetPath: z5.string(),
|
|
3339
|
+
streamId: z5.string(),
|
|
3340
|
+
outcome: z5.enum(["completed", "failed", "cancelled"]).optional()
|
|
3314
3341
|
});
|
|
3315
|
-
var childActivitiesSchema =
|
|
3342
|
+
var childActivitiesSchema = z5.partialRecord(
|
|
3316
3343
|
childActivitySchema.shape.type,
|
|
3317
3344
|
childActivitySchema
|
|
3318
3345
|
);
|
|
3319
|
-
var childActivityMetadataSchema =
|
|
3346
|
+
var childActivityMetadataSchema = z5.looseObject({
|
|
3320
3347
|
childActivities: childActivitiesSchema.default({})
|
|
3321
3348
|
});
|
|
3322
3349
|
|
|
3323
3350
|
// packages/experimental/src/zukhruf/runtime/conversation-status/projector.ts
|
|
3351
|
+
var ProjectorEventDelivery = class {
|
|
3352
|
+
event;
|
|
3353
|
+
constructor(event) {
|
|
3354
|
+
this.event = event;
|
|
3355
|
+
}
|
|
3356
|
+
};
|
|
3324
3357
|
var ConversationStatusProjector = class _ConversationStatusProjector {
|
|
3325
3358
|
#store;
|
|
3326
3359
|
#streams;
|
|
@@ -3329,7 +3362,7 @@ var ConversationStatusProjector = class _ConversationStatusProjector {
|
|
|
3329
3362
|
#changeSource;
|
|
3330
3363
|
#emitter = new EventEmitter();
|
|
3331
3364
|
#last = /* @__PURE__ */ new Map();
|
|
3332
|
-
#publishing =
|
|
3365
|
+
#publishing = new Mutex(new MemoryStore());
|
|
3333
3366
|
#subscribers = 0;
|
|
3334
3367
|
#remote;
|
|
3335
3368
|
constructor(options) {
|
|
@@ -3445,10 +3478,12 @@ var ConversationStatusProjector = class _ConversationStatusProjector {
|
|
|
3445
3478
|
return {
|
|
3446
3479
|
async *[Symbol.asyncIterator]() {
|
|
3447
3480
|
try {
|
|
3448
|
-
for await (const
|
|
3449
|
-
const
|
|
3450
|
-
if (
|
|
3451
|
-
|
|
3481
|
+
for await (const args of events) {
|
|
3482
|
+
const [delivery] = args;
|
|
3483
|
+
if (!(delivery instanceof ProjectorEventDelivery)) continue;
|
|
3484
|
+
const { event } = delivery;
|
|
3485
|
+
if (event.type === "error") throw event.error;
|
|
3486
|
+
yield event;
|
|
3452
3487
|
}
|
|
3453
3488
|
} finally {
|
|
3454
3489
|
await detach();
|
|
@@ -3464,13 +3499,7 @@ var ConversationStatusProjector = class _ConversationStatusProjector {
|
|
|
3464
3499
|
}
|
|
3465
3500
|
#serialize(conversation, step) {
|
|
3466
3501
|
const key = _ConversationStatusProjector.#key(conversation);
|
|
3467
|
-
|
|
3468
|
-
const next = previous.then(() => step(key));
|
|
3469
|
-
this.#publishing.set(key, next);
|
|
3470
|
-
void next.finally(() => {
|
|
3471
|
-
if (this.#publishing.get(key) === next) this.#publishing.delete(key);
|
|
3472
|
-
});
|
|
3473
|
-
return next;
|
|
3502
|
+
return this.#publishing.acquire(key, () => step(key));
|
|
3474
3503
|
}
|
|
3475
3504
|
async #project(conversation, key) {
|
|
3476
3505
|
let change;
|
|
@@ -3492,7 +3521,7 @@ var ConversationStatusProjector = class _ConversationStatusProjector {
|
|
|
3492
3521
|
}
|
|
3493
3522
|
if (isDeepStrictEqual2(this.#last.get(key), change)) return false;
|
|
3494
3523
|
this.#last.set(key, change);
|
|
3495
|
-
this.#
|
|
3524
|
+
this.#emit(change);
|
|
3496
3525
|
return true;
|
|
3497
3526
|
}
|
|
3498
3527
|
async #attachRemote() {
|
|
@@ -3529,13 +3558,13 @@ var ConversationStatusProjector = class _ConversationStatusProjector {
|
|
|
3529
3558
|
ready.resolve();
|
|
3530
3559
|
for await (const event of events) {
|
|
3531
3560
|
if (event.type === "reset") {
|
|
3532
|
-
this.#
|
|
3561
|
+
this.#emit(event);
|
|
3533
3562
|
} else {
|
|
3534
3563
|
await this.#reconcile(event.conversation);
|
|
3535
3564
|
}
|
|
3536
3565
|
}
|
|
3537
3566
|
if (!remote.abort.signal.aborted) {
|
|
3538
|
-
this.#
|
|
3567
|
+
this.#emit({
|
|
3539
3568
|
type: "error",
|
|
3540
3569
|
error: new Error("Conversation status change source ended")
|
|
3541
3570
|
});
|
|
@@ -3543,15 +3572,15 @@ var ConversationStatusProjector = class _ConversationStatusProjector {
|
|
|
3543
3572
|
} catch (error) {
|
|
3544
3573
|
if (!connected) ready.reject(error);
|
|
3545
3574
|
if (connected && !(error instanceof Error && error.name === "AbortError")) {
|
|
3546
|
-
this.#
|
|
3547
|
-
type: "error",
|
|
3548
|
-
error
|
|
3549
|
-
});
|
|
3575
|
+
this.#emit({ type: "error", error });
|
|
3550
3576
|
}
|
|
3551
3577
|
} finally {
|
|
3552
3578
|
if (this.#remote === remote) this.#remote = void 0;
|
|
3553
3579
|
}
|
|
3554
3580
|
}
|
|
3581
|
+
#emit(event) {
|
|
3582
|
+
this.#emitter.emit("event", new ProjectorEventDelivery(event));
|
|
3583
|
+
}
|
|
3555
3584
|
static #key({ chatId, userId }) {
|
|
3556
3585
|
return JSON.stringify([chatId, userId]);
|
|
3557
3586
|
}
|
|
@@ -3595,13 +3624,13 @@ var StatusPublishingTurnQueue = class extends TurnQueue {
|
|
|
3595
3624
|
|
|
3596
3625
|
// packages/experimental/src/zukhruf/collaboration/interrupt-agent.ts
|
|
3597
3626
|
import { tool as tool2 } from "ai";
|
|
3598
|
-
import { z as
|
|
3599
|
-
var interruptAgentInputSchema =
|
|
3600
|
-
target:
|
|
3627
|
+
import { z as z6 } from "zod";
|
|
3628
|
+
var interruptAgentInputSchema = z6.object({
|
|
3629
|
+
target: z6.string().trim().min(1).describe(
|
|
3601
3630
|
"The canonical /root/... path, or a descendant-relative target name."
|
|
3602
3631
|
)
|
|
3603
3632
|
});
|
|
3604
|
-
var interruptAgentOutputSchema =
|
|
3633
|
+
var interruptAgentOutputSchema = z6.object({ previous_status: listedAgentStatusSchema }).strict();
|
|
3605
3634
|
var interruptAgentTool = tool2({
|
|
3606
3635
|
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
3636
|
inputSchema: interruptAgentInputSchema,
|
|
@@ -3611,13 +3640,13 @@ var interruptAgentTool = tool2({
|
|
|
3611
3640
|
|
|
3612
3641
|
// packages/experimental/src/zukhruf/collaboration/list-agents.ts
|
|
3613
3642
|
import { tool as tool3 } from "ai";
|
|
3614
|
-
import { z as
|
|
3615
|
-
var listAgentsInputSchema =
|
|
3616
|
-
path_prefix:
|
|
3643
|
+
import { z as z7 } from "zod";
|
|
3644
|
+
var listAgentsInputSchema = z7.object({
|
|
3645
|
+
path_prefix: z7.string().trim().min(1).describe(
|
|
3617
3646
|
"Task-path prefix without a trailing slash. Omit to list the whole tree."
|
|
3618
3647
|
).optional()
|
|
3619
3648
|
});
|
|
3620
|
-
var listAgentsOutputSchema =
|
|
3649
|
+
var listAgentsOutputSchema = z7.object({ agents: z7.array(listedAgentSchema) }).strict();
|
|
3621
3650
|
var listAgentsTool = tool3({
|
|
3622
3651
|
description: "List live agents in the current root thread tree. Optionally filter by task-path prefix.",
|
|
3623
3652
|
inputSchema: listAgentsInputSchema,
|
|
@@ -3627,12 +3656,12 @@ var listAgentsTool = tool3({
|
|
|
3627
3656
|
|
|
3628
3657
|
// packages/experimental/src/zukhruf/collaboration/message-tools.ts
|
|
3629
3658
|
import { tool as tool4 } from "ai";
|
|
3630
|
-
import { z as
|
|
3631
|
-
var agentMessageInputSchema =
|
|
3632
|
-
target:
|
|
3659
|
+
import { z as z8 } from "zod";
|
|
3660
|
+
var agentMessageInputSchema = z8.object({
|
|
3661
|
+
target: z8.string().trim().min(1).describe(
|
|
3633
3662
|
"The canonical /root/... path, or a descendant-relative target name."
|
|
3634
3663
|
),
|
|
3635
|
-
message:
|
|
3664
|
+
message: z8.string().trim().min(1).describe("The message or follow-up task.")
|
|
3636
3665
|
});
|
|
3637
3666
|
var sendMessageTool = tool4({
|
|
3638
3667
|
description: "Queue a message for another agent. Address siblings with their canonical /root/... path.",
|
|
@@ -3653,7 +3682,7 @@ var followupTaskTool = tool4({
|
|
|
3653
3682
|
|
|
3654
3683
|
// packages/experimental/src/zukhruf/collaboration/spawn-agent.ts
|
|
3655
3684
|
import { tool as tool5 } from "ai";
|
|
3656
|
-
import { z as
|
|
3685
|
+
import { z as z9 } from "zod";
|
|
3657
3686
|
|
|
3658
3687
|
// packages/experimental/src/zukhruf/control-plane/fork-turns.ts
|
|
3659
3688
|
var forkTurnsError = "fork_turns must be `none`, `all`, or a positive integer string";
|
|
@@ -3666,18 +3695,18 @@ function parseForkTurns(value) {
|
|
|
3666
3695
|
}
|
|
3667
3696
|
|
|
3668
3697
|
// packages/experimental/src/zukhruf/collaboration/spawn-agent.ts
|
|
3669
|
-
var spawnAgentInputSchema =
|
|
3670
|
-
agent_type:
|
|
3671
|
-
task_name:
|
|
3698
|
+
var spawnAgentInputSchema = z9.object({
|
|
3699
|
+
agent_type: z9.string().trim().min(1).describe("The name of one available subagent declaration."),
|
|
3700
|
+
task_name: z9.string().trim().min(1).refine(
|
|
3672
3701
|
(value) => value !== "." && value !== ".." && !value.includes("/"),
|
|
3673
3702
|
"task_name must be one non-empty path segment"
|
|
3674
3703
|
).describe("One path segment naming this independent agent task."),
|
|
3675
|
-
message:
|
|
3676
|
-
fork_turns:
|
|
3704
|
+
message: z9.string().refine((value) => value.trim().length > 0, "message cannot be empty").describe("The initial task for the spawned agent."),
|
|
3705
|
+
fork_turns: z9.string().trim().refine((value) => parseForkTurns(value) !== void 0, forkTurnsError).describe(
|
|
3677
3706
|
"Required number of parent turns to fork. Use `none`, `all`, or a positive integer string such as `3`."
|
|
3678
3707
|
)
|
|
3679
3708
|
});
|
|
3680
|
-
var spawnAgentOutputSchema =
|
|
3709
|
+
var spawnAgentOutputSchema = z9.object({ task_name: z9.string() }).strict();
|
|
3681
3710
|
function createSpawnAgentTool(options) {
|
|
3682
3711
|
return tool5({
|
|
3683
3712
|
description: ({ context }) => {
|
|
@@ -3706,11 +3735,11 @@ function createSpawnAgentTool(options) {
|
|
|
3706
3735
|
|
|
3707
3736
|
// packages/experimental/src/zukhruf/collaboration/wait-agent.ts
|
|
3708
3737
|
import { tool as tool6 } from "ai";
|
|
3709
|
-
import { z as
|
|
3710
|
-
var waitAgentOutputSchema =
|
|
3738
|
+
import { z as z10 } from "zod";
|
|
3739
|
+
var waitAgentOutputSchema = z10.object({ message: z10.string(), timed_out: z10.boolean() }).strict();
|
|
3711
3740
|
function createWaitAgentTool(options) {
|
|
3712
|
-
const waitAgentInputSchema =
|
|
3713
|
-
timeout_ms:
|
|
3741
|
+
const waitAgentInputSchema = z10.object({
|
|
3742
|
+
timeout_ms: z10.number().int().max(options.maxTimeoutMs).optional().describe("Maximum time to wait in milliseconds.")
|
|
3714
3743
|
});
|
|
3715
3744
|
return tool6({
|
|
3716
3745
|
description: "Wait for pending mail addressed to this agent without consuming it.",
|
|
@@ -3925,7 +3954,7 @@ var PluginAgentComposition = class {
|
|
|
3925
3954
|
|
|
3926
3955
|
// packages/experimental/src/zukhruf/runtime/plugin/plugin-bindings.ts
|
|
3927
3956
|
var PluginBindings = class {
|
|
3928
|
-
#
|
|
3957
|
+
#bindings;
|
|
3929
3958
|
constructor(definitions, bindings) {
|
|
3930
3959
|
const pluginNames = /* @__PURE__ */ new Set();
|
|
3931
3960
|
const capabilities = /* @__PURE__ */ new Map();
|
|
@@ -3979,7 +4008,7 @@ var PluginBindings = class {
|
|
|
3979
4008
|
}
|
|
3980
4009
|
}
|
|
3981
4010
|
}
|
|
3982
|
-
this.#
|
|
4011
|
+
this.#bindings = /* @__PURE__ */ new Map();
|
|
3983
4012
|
const bindingNames = /* @__PURE__ */ new Set();
|
|
3984
4013
|
if (bindings) {
|
|
3985
4014
|
for (const binding of bindings) {
|
|
@@ -3995,7 +4024,7 @@ var PluginBindings = class {
|
|
|
3995
4024
|
`AgentRuntime: unused binding for capability "${binding.capability.name}"`
|
|
3996
4025
|
);
|
|
3997
4026
|
}
|
|
3998
|
-
this.#
|
|
4027
|
+
this.#bindings.set(binding.capability, binding);
|
|
3999
4028
|
}
|
|
4000
4029
|
}
|
|
4001
4030
|
}
|
|
@@ -4003,7 +4032,7 @@ var PluginBindings = class {
|
|
|
4003
4032
|
const declared = new Set(definition.capabilities);
|
|
4004
4033
|
if (definition.capabilities) {
|
|
4005
4034
|
for (const capability of definition.capabilities) {
|
|
4006
|
-
if (!this.#
|
|
4035
|
+
if (!this.#bindings.has(capability)) {
|
|
4007
4036
|
throw new Error(
|
|
4008
4037
|
`AgentRuntime: plugin "${definition.name}" requires missing capability "${capability.name}"`
|
|
4009
4038
|
);
|
|
@@ -4017,7 +4046,13 @@ var PluginBindings = class {
|
|
|
4017
4046
|
`AgentRuntime: plugin "${definition.name}" did not declare capability "${capability.name}"`
|
|
4018
4047
|
);
|
|
4019
4048
|
}
|
|
4020
|
-
|
|
4049
|
+
const binding = this.#bindings.get(capability);
|
|
4050
|
+
if (!binding) {
|
|
4051
|
+
throw new Error(
|
|
4052
|
+
`AgentRuntime: plugin "${definition.name}" requires missing capability "${capability.name}"`
|
|
4053
|
+
);
|
|
4054
|
+
}
|
|
4055
|
+
return capability.read(binding);
|
|
4021
4056
|
}
|
|
4022
4057
|
};
|
|
4023
4058
|
}
|
|
@@ -4049,7 +4084,7 @@ var PluginToolComposition = class {
|
|
|
4049
4084
|
this.#owners = new Map(reservedNames.map((name) => [name, "the runtime"]));
|
|
4050
4085
|
}
|
|
4051
4086
|
add(plugin, tools) {
|
|
4052
|
-
for (const [name,
|
|
4087
|
+
for (const [name, tool7] of Object.entries(tools)) {
|
|
4053
4088
|
const owner = this.#owners.get(name);
|
|
4054
4089
|
if (owner) {
|
|
4055
4090
|
throw new Error(
|
|
@@ -4057,7 +4092,7 @@ var PluginToolComposition = class {
|
|
|
4057
4092
|
);
|
|
4058
4093
|
}
|
|
4059
4094
|
this.#owners.set(name, `plugin "${plugin}"`);
|
|
4060
|
-
this.#tools[name] =
|
|
4095
|
+
this.#tools[name] = tool7;
|
|
4061
4096
|
}
|
|
4062
4097
|
}
|
|
4063
4098
|
compose(declarations) {
|
|
@@ -4077,6 +4112,9 @@ var PluginToolComposition = class {
|
|
|
4077
4112
|
};
|
|
4078
4113
|
|
|
4079
4114
|
// packages/experimental/src/zukhruf/runtime/plugin/plugin-manager.ts
|
|
4115
|
+
function createdFrom(plugin, definition) {
|
|
4116
|
+
return plugin.definition === definition;
|
|
4117
|
+
}
|
|
4080
4118
|
var PluginManager = class {
|
|
4081
4119
|
collaborationTools;
|
|
4082
4120
|
declarations;
|
|
@@ -4140,7 +4178,7 @@ var PluginManager = class {
|
|
|
4140
4178
|
}
|
|
4141
4179
|
get(definition) {
|
|
4142
4180
|
const plugin = this.#plugins.find(
|
|
4143
|
-
(
|
|
4181
|
+
(candidate) => createdFrom(candidate, definition)
|
|
4144
4182
|
);
|
|
4145
4183
|
if (!plugin) {
|
|
4146
4184
|
throw new Error(
|
|
@@ -4201,11 +4239,25 @@ var PluginManager = class {
|
|
|
4201
4239
|
// packages/experimental/src/zukhruf/runtime/agent-runtime.ts
|
|
4202
4240
|
var AgentPluginCapability = class {
|
|
4203
4241
|
name;
|
|
4242
|
+
/** Each value this capability bound, keyed by the binding that carries it. */
|
|
4243
|
+
#bound = /* @__PURE__ */ new WeakMap();
|
|
4204
4244
|
constructor(name) {
|
|
4205
4245
|
this.name = name;
|
|
4206
4246
|
}
|
|
4207
4247
|
bind(value) {
|
|
4208
|
-
|
|
4248
|
+
const binding = { capability: this, value };
|
|
4249
|
+
this.#bound.set(binding, { value });
|
|
4250
|
+
return binding;
|
|
4251
|
+
}
|
|
4252
|
+
/** Reads the value of a binding this capability created with `bind`. */
|
|
4253
|
+
read(binding) {
|
|
4254
|
+
const bound = this.#bound.get(binding);
|
|
4255
|
+
if (!bound) {
|
|
4256
|
+
throw new Error(
|
|
4257
|
+
`AgentRuntime: binding for capability "${this.name}" was not created by its bind()`
|
|
4258
|
+
);
|
|
4259
|
+
}
|
|
4260
|
+
return bound.value;
|
|
4209
4261
|
}
|
|
4210
4262
|
};
|
|
4211
4263
|
var AgentObservation = class {
|
|
@@ -4612,6 +4664,7 @@ var RuntimeHost = class {
|
|
|
4612
4664
|
|
|
4613
4665
|
// packages/experimental/src/zukhruf/queue/pg-boss-notifications.ts
|
|
4614
4666
|
import { EventEmitter as EventEmitter2, on as on2 } from "node:events";
|
|
4667
|
+
var RESET = /* @__PURE__ */ Symbol("reset");
|
|
4615
4668
|
async function pgBossNotifications(boss, channel, parse, signal) {
|
|
4616
4669
|
signal.throwIfAborted();
|
|
4617
4670
|
const db = boss.getDb();
|
|
@@ -4625,13 +4678,10 @@ async function pgBossNotifications(boss, channel, parse, signal) {
|
|
|
4625
4678
|
const handle = await listen(
|
|
4626
4679
|
channel,
|
|
4627
4680
|
(payload) => {
|
|
4628
|
-
|
|
4629
|
-
if (value !== void 0) {
|
|
4630
|
-
emitter.emit("notification", { type: "change", value });
|
|
4631
|
-
}
|
|
4681
|
+
emitter.emit("notification", payload);
|
|
4632
4682
|
},
|
|
4633
4683
|
() => {
|
|
4634
|
-
if (ready) emitter.emit("notification",
|
|
4684
|
+
if (ready) emitter.emit("notification", RESET);
|
|
4635
4685
|
}
|
|
4636
4686
|
);
|
|
4637
4687
|
ready = true;
|
|
@@ -4642,8 +4692,14 @@ async function pgBossNotifications(boss, channel, parse, signal) {
|
|
|
4642
4692
|
return {
|
|
4643
4693
|
async *[Symbol.asyncIterator]() {
|
|
4644
4694
|
try {
|
|
4645
|
-
for await (const
|
|
4646
|
-
|
|
4695
|
+
for await (const event of notifications) {
|
|
4696
|
+
const [payload] = event;
|
|
4697
|
+
if (payload === RESET) {
|
|
4698
|
+
yield { type: "reset" };
|
|
4699
|
+
} else if (typeof payload === "string") {
|
|
4700
|
+
const value = parse(payload);
|
|
4701
|
+
if (value !== void 0) yield { type: "change", value };
|
|
4702
|
+
}
|
|
4647
4703
|
}
|
|
4648
4704
|
} finally {
|
|
4649
4705
|
await handle.close();
|
|
@@ -4728,11 +4784,8 @@ function defineSandbox(createBackend, options) {
|
|
|
4728
4784
|
}
|
|
4729
4785
|
|
|
4730
4786
|
// packages/experimental/src/zukhruf/tool.ts
|
|
4731
|
-
import {
|
|
4732
|
-
tool as tool7
|
|
4733
|
-
} from "ai";
|
|
4734
4787
|
function defineTool(definition) {
|
|
4735
|
-
return
|
|
4788
|
+
return definition;
|
|
4736
4789
|
}
|
|
4737
4790
|
export {
|
|
4738
4791
|
AgentObservation,
|
|
@@ -4741,9 +4794,9 @@ export {
|
|
|
4741
4794
|
AgentRuntime,
|
|
4742
4795
|
AgentThread,
|
|
4743
4796
|
DEFAULT_CONVERSATION_STATUS_CHANNEL,
|
|
4744
|
-
|
|
4797
|
+
InterAgentCommunicationTypes,
|
|
4745
4798
|
MailboxStore,
|
|
4746
|
-
|
|
4799
|
+
MessageDeliveryModes,
|
|
4747
4800
|
PgBossConversationStatusChangeSource,
|
|
4748
4801
|
PgBossTurnQueue,
|
|
4749
4802
|
SqliteMailboxStore,
|