@deepagents/experimental 7.7.2 → 7.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -5
- package/dist/index.js +400 -177
- package/dist/index.js.map +4 -4
- package/dist/zukhruf/control-plane/agent-control-plane.d.ts.map +1 -1
- package/dist/zukhruf/control-plane/agent-thread-limit-error.d.ts +6 -0
- package/dist/zukhruf/control-plane/agent-thread-limit-error.d.ts.map +1 -0
- package/dist/zukhruf/control-plane/agent-turn-id.d.ts +3 -0
- package/dist/zukhruf/control-plane/agent-turn-id.d.ts.map +1 -1
- package/dist/zukhruf/control-plane/stale-turn-error.d.ts +7 -0
- package/dist/zukhruf/control-plane/stale-turn-error.d.ts.map +1 -0
- package/dist/zukhruf/control-plane/turn-not-found-error.d.ts +7 -0
- package/dist/zukhruf/control-plane/turn-not-found-error.d.ts.map +1 -0
- package/dist/zukhruf/index.d.ts +4 -0
- package/dist/zukhruf/index.d.ts.map +1 -1
- package/dist/zukhruf/index.js +400 -177
- package/dist/zukhruf/index.js.map +4 -4
- package/dist/zukhruf/is-named-error.d.ts +7 -0
- package/dist/zukhruf/is-named-error.d.ts.map +1 -0
- package/dist/zukhruf/mailbox/communication-schema.d.ts +26 -0
- package/dist/zukhruf/mailbox/communication-schema.d.ts.map +1 -0
- package/dist/zukhruf/mailbox/ddl.postgres.d.ts +2 -0
- package/dist/zukhruf/mailbox/ddl.postgres.d.ts.map +1 -0
- package/dist/zukhruf/mailbox/postgres.store.d.ts +23 -0
- package/dist/zukhruf/mailbox/postgres.store.d.ts.map +1 -0
- package/dist/zukhruf/mailbox/sqlite.store.d.ts.map +1 -1
- package/dist/zukhruf/plugins/conversation-scheduling/conversation-scheduler.d.ts +1 -1
- package/dist/zukhruf/plugins/conversation-scheduling/conversation-scheduler.d.ts.map +1 -1
- package/dist/zukhruf/plugins/conversation-scheduling/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/conversation-scheduling/index.js +142 -136
- package/dist/zukhruf/plugins/conversation-scheduling/index.js.map +3 -3
- package/dist/zukhruf/plugins/http/index.d.ts +2 -2
- package/dist/zukhruf/plugins/http/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/http/index.js +72 -17
- package/dist/zukhruf/plugins/http/index.js.map +4 -4
- package/dist/zukhruf/plugins/schedules/http.d.ts.map +1 -1
- package/dist/zukhruf/plugins/schedules/http.js +44 -32
- package/dist/zukhruf/plugins/schedules/http.js.map +4 -4
- package/dist/zukhruf/plugins/schedules/index.d.ts +2 -2
- package/dist/zukhruf/plugins/schedules/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/schedules/index.js +138 -143
- package/dist/zukhruf/plugins/schedules/index.js.map +3 -3
- package/dist/zukhruf/plugins/uploads/http.js +30 -19
- package/dist/zukhruf/plugins/uploads/http.js.map +4 -4
- package/dist/zukhruf/plugins/uploads/index.d.ts +2 -2
- package/dist/zukhruf/plugins/uploads/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/uploads/index.js +48 -55
- package/dist/zukhruf/plugins/uploads/index.js.map +2 -2
- package/dist/zukhruf/queue/pg-boss.turn-queue.d.ts +4 -1
- package/dist/zukhruf/queue/pg-boss.turn-queue.d.ts.map +1 -1
- package/dist/zukhruf/runtime/agent-runtime.d.ts +19 -11
- package/dist/zukhruf/runtime/agent-runtime.d.ts.map +1 -1
- package/dist/zukhruf/runtime/plugin/plugin-manager.d.ts +4 -4
- package/dist/zukhruf/runtime/plugin/plugin-manager.d.ts.map +1 -1
- package/package.json +20 -11
package/dist/zukhruf/index.js
CHANGED
|
@@ -182,6 +182,14 @@ var AgentThread = class _AgentThread {
|
|
|
182
182
|
}
|
|
183
183
|
};
|
|
184
184
|
|
|
185
|
+
// packages/experimental/src/zukhruf/control-plane/agent-thread-limit-error.ts
|
|
186
|
+
var AgentThreadLimitError = class extends Error {
|
|
187
|
+
name = "AgentThreadLimitError";
|
|
188
|
+
constructor() {
|
|
189
|
+
super("agent thread limit reached");
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
185
193
|
// packages/experimental/src/zukhruf/control-plane/conversation-not-found-error.ts
|
|
186
194
|
var ConversationNotFoundError = class extends Error {
|
|
187
195
|
name = "ConversationNotFoundError";
|
|
@@ -197,53 +205,37 @@ function assertConversationOwner(conversation, storedUserId) {
|
|
|
197
205
|
}
|
|
198
206
|
}
|
|
199
207
|
|
|
208
|
+
// packages/experimental/src/zukhruf/control-plane/stale-turn-error.ts
|
|
209
|
+
var StaleTurnError = class extends Error {
|
|
210
|
+
name = "StaleTurnError";
|
|
211
|
+
turnId;
|
|
212
|
+
constructor(turnId) {
|
|
213
|
+
super(`turn "${turnId}" is not the latest turn`);
|
|
214
|
+
this.turnId = turnId;
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// packages/experimental/src/zukhruf/control-plane/turn-not-found-error.ts
|
|
219
|
+
var TurnNotFoundError = class extends Error {
|
|
220
|
+
name = "TurnNotFoundError";
|
|
221
|
+
turnId;
|
|
222
|
+
constructor(turnId) {
|
|
223
|
+
super(`turn "${turnId}" does not exist`);
|
|
224
|
+
this.turnId = turnId;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
200
228
|
// packages/experimental/src/zukhruf/instructions.ts
|
|
201
229
|
function defineInstructions(...fragments) {
|
|
202
230
|
return fragments;
|
|
203
231
|
}
|
|
204
232
|
|
|
205
|
-
// packages/experimental/src/zukhruf/mailbox/
|
|
206
|
-
import {
|
|
207
|
-
import {
|
|
208
|
-
import { transaction } from "@zukhruf/sqlite-transaction";
|
|
209
|
-
import { z } from "zod";
|
|
210
|
-
|
|
211
|
-
// packages/experimental/src/zukhruf/mailbox/ddl.sqlite.ts
|
|
212
|
-
var SETUP = `
|
|
213
|
-
PRAGMA synchronous = NORMAL;
|
|
214
|
-
`;
|
|
215
|
-
var statements = [
|
|
216
|
-
`CREATE TABLE zukhruf_mailbox_items (
|
|
217
|
-
sequence INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
218
|
-
recipient_chat_id TEXT NOT NULL,
|
|
219
|
-
recipient_user_id TEXT NOT NULL,
|
|
220
|
-
communication TEXT NOT NULL
|
|
221
|
-
)`,
|
|
222
|
-
`CREATE TABLE zukhruf_mailbox_activity (
|
|
223
|
-
recipient_chat_id TEXT NOT NULL,
|
|
224
|
-
recipient_user_id TEXT NOT NULL,
|
|
225
|
-
turn_id TEXT NOT NULL,
|
|
226
|
-
PRIMARY KEY (recipient_chat_id, recipient_user_id)
|
|
227
|
-
)`,
|
|
228
|
-
`CREATE TABLE zukhruf_mailbox_consumed_terminal_ids (
|
|
229
|
-
communication_id TEXT PRIMARY KEY
|
|
230
|
-
)`,
|
|
231
|
-
`CREATE INDEX zukhruf_mailbox_recipient_sequence
|
|
232
|
-
ON zukhruf_mailbox_items (
|
|
233
|
-
recipient_chat_id,
|
|
234
|
-
recipient_user_id,
|
|
235
|
-
sequence
|
|
236
|
-
)`,
|
|
237
|
-
// enqueue relies on this index through INSERT OR IGNORE.
|
|
238
|
-
`CREATE UNIQUE INDEX zukhruf_mailbox_communication_id
|
|
239
|
-
ON zukhruf_mailbox_items (
|
|
240
|
-
json_extract(communication, '$.id')
|
|
241
|
-
)`
|
|
242
|
-
];
|
|
233
|
+
// packages/experimental/src/zukhruf/mailbox/postgres.store.ts
|
|
234
|
+
import { z as z2 } from "zod";
|
|
235
|
+
import { lockSchemaDDL, postgresTransaction } from "@deepagents/context";
|
|
243
236
|
|
|
244
|
-
// packages/experimental/src/zukhruf/mailbox/
|
|
245
|
-
|
|
246
|
-
};
|
|
237
|
+
// packages/experimental/src/zukhruf/mailbox/communication-schema.ts
|
|
238
|
+
import { z } from "zod";
|
|
247
239
|
|
|
248
240
|
// packages/experimental/src/zukhruf/mailbox/types.ts
|
|
249
241
|
import { randomUUID } from "node:crypto";
|
|
@@ -291,8 +283,7 @@ function assertConversationId(value, label) {
|
|
|
291
283
|
}
|
|
292
284
|
}
|
|
293
285
|
|
|
294
|
-
// packages/experimental/src/zukhruf/mailbox/
|
|
295
|
-
var tables = new Declaration(statements, { rows: "keep" });
|
|
286
|
+
// packages/experimental/src/zukhruf/mailbox/communication-schema.ts
|
|
296
287
|
var conversationIdSchema = z.object({
|
|
297
288
|
chatId: z.string(),
|
|
298
289
|
userId: z.string()
|
|
@@ -307,10 +298,249 @@ var communicationSchema = z.object({
|
|
|
307
298
|
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
308
299
|
triggerTurn: z.boolean()
|
|
309
300
|
});
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
301
|
+
|
|
302
|
+
// packages/experimental/src/zukhruf/mailbox/ddl.postgres.ts
|
|
303
|
+
function mailboxDDL(schema) {
|
|
304
|
+
return `
|
|
305
|
+
CREATE SCHEMA IF NOT EXISTS "${schema}";
|
|
306
|
+
|
|
307
|
+
CREATE TABLE IF NOT EXISTS "${schema}"."zukhruf_mailbox_items" (
|
|
308
|
+
sequence BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
309
|
+
communication_id TEXT NOT NULL UNIQUE,
|
|
310
|
+
recipient_chat_id TEXT NOT NULL,
|
|
311
|
+
recipient_user_id TEXT NOT NULL,
|
|
312
|
+
communication JSONB NOT NULL
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
CREATE INDEX IF NOT EXISTS "zukhruf_mailbox_recipient_sequence"
|
|
316
|
+
ON "${schema}"."zukhruf_mailbox_items" (recipient_chat_id, recipient_user_id, sequence);
|
|
317
|
+
|
|
318
|
+
CREATE TABLE IF NOT EXISTS "${schema}"."zukhruf_mailbox_activity" (
|
|
319
|
+
recipient_chat_id TEXT NOT NULL,
|
|
320
|
+
recipient_user_id TEXT NOT NULL,
|
|
321
|
+
turn_id TEXT NOT NULL,
|
|
322
|
+
PRIMARY KEY (recipient_chat_id, recipient_user_id)
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
CREATE TABLE IF NOT EXISTS "${schema}"."zukhruf_mailbox_consumed_terminal_ids" (
|
|
326
|
+
communication_id TEXT PRIMARY KEY
|
|
327
|
+
);
|
|
328
|
+
`;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// packages/experimental/src/zukhruf/mailbox/store.ts
|
|
332
|
+
var MailboxStore = class {
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
// packages/experimental/src/zukhruf/mailbox/postgres.store.ts
|
|
336
|
+
var mailboxItemRowsSchema = z2.array(
|
|
337
|
+
z2.object({
|
|
338
|
+
sequence: z2.string(),
|
|
339
|
+
communication: communicationSchema
|
|
340
|
+
})
|
|
341
|
+
);
|
|
342
|
+
var existsRowsSchema = z2.tuple([z2.object({ exists: z2.boolean() })]);
|
|
343
|
+
var PostgresMailboxStore = class _PostgresMailboxStore extends MailboxStore {
|
|
344
|
+
#pool;
|
|
345
|
+
#schema;
|
|
346
|
+
constructor(pool, schema) {
|
|
347
|
+
super();
|
|
348
|
+
this.#pool = pool;
|
|
349
|
+
this.#schema = schema;
|
|
350
|
+
}
|
|
351
|
+
/** Opens the store: creates its schema objects before it returns. */
|
|
352
|
+
static async create(options) {
|
|
353
|
+
const schema = options.schema ?? "public";
|
|
354
|
+
await options.pool.query(lockSchemaDDL(mailboxDDL(schema), schema));
|
|
355
|
+
return new _PostgresMailboxStore(options.pool, schema);
|
|
356
|
+
}
|
|
357
|
+
#t(name) {
|
|
358
|
+
return `"${this.#schema}"."${name}"`;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Runs `fn` while holding the recipient's lock, so enqueue, drain and turn
|
|
362
|
+
* handoff on one mailbox take turns across every worker, as SQLite's
|
|
363
|
+
* immediate transactions do.
|
|
364
|
+
*/
|
|
365
|
+
#forRecipient(recipient, fn) {
|
|
366
|
+
return postgresTransaction(this.#pool, async (client) => {
|
|
367
|
+
await client.query(
|
|
368
|
+
"SELECT pg_advisory_xact_lock(hashtextextended($1, 0))",
|
|
369
|
+
[
|
|
370
|
+
`zukhruf:mailbox:${JSON.stringify([this.#schema, recipient.chatId, recipient.userId])}`
|
|
371
|
+
]
|
|
372
|
+
);
|
|
373
|
+
return fn(client);
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
async beginTurn(recipient, turnId) {
|
|
377
|
+
await this.#forRecipient(
|
|
378
|
+
recipient,
|
|
379
|
+
(client) => client.query(
|
|
380
|
+
`INSERT INTO ${this.#t("zukhruf_mailbox_activity")}
|
|
381
|
+
(recipient_chat_id, recipient_user_id, turn_id)
|
|
382
|
+
VALUES ($1, $2, $3)
|
|
383
|
+
ON CONFLICT (recipient_chat_id, recipient_user_id)
|
|
384
|
+
DO UPDATE SET turn_id = EXCLUDED.turn_id`,
|
|
385
|
+
[recipient.chatId, recipient.userId, turnId]
|
|
386
|
+
)
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
enqueue(communication) {
|
|
390
|
+
const { recipient } = communication;
|
|
391
|
+
return this.#forRecipient(recipient, async (client) => {
|
|
392
|
+
const consumedTerminal = communication.type === InterAgentCommunicationTypes.FinalAnswer && await this.#exists(
|
|
393
|
+
client,
|
|
394
|
+
`SELECT EXISTS (
|
|
395
|
+
SELECT 1 FROM ${this.#t("zukhruf_mailbox_consumed_terminal_ids")}
|
|
396
|
+
WHERE communication_id = $1)`,
|
|
397
|
+
[communication.id]
|
|
398
|
+
);
|
|
399
|
+
if (!consumedTerminal) {
|
|
400
|
+
await client.query(
|
|
401
|
+
`INSERT INTO ${this.#t("zukhruf_mailbox_items")}
|
|
402
|
+
(communication_id, recipient_chat_id, recipient_user_id, communication)
|
|
403
|
+
VALUES ($1, $2, $3, $4::jsonb)
|
|
404
|
+
ON CONFLICT (communication_id) DO NOTHING`,
|
|
405
|
+
[
|
|
406
|
+
communication.id,
|
|
407
|
+
recipient.chatId,
|
|
408
|
+
recipient.userId,
|
|
409
|
+
JSON.stringify(communication)
|
|
410
|
+
]
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
return { recipientActive: await this.#isTurnActive(client, recipient) };
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
endTurn(recipient, turnId) {
|
|
417
|
+
return this.#forRecipient(recipient, async (client) => {
|
|
418
|
+
const ended = await client.query(
|
|
419
|
+
`DELETE FROM ${this.#t("zukhruf_mailbox_activity")}
|
|
420
|
+
WHERE recipient_chat_id = $1
|
|
421
|
+
AND recipient_user_id = $2
|
|
422
|
+
AND turn_id = $3`,
|
|
423
|
+
[recipient.chatId, recipient.userId, turnId]
|
|
424
|
+
);
|
|
425
|
+
return {
|
|
426
|
+
hasPending: await this.#hasPending(client, recipient),
|
|
427
|
+
turnEnded: ended.rowCount === 1
|
|
428
|
+
};
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
hasPending(recipient) {
|
|
432
|
+
return this.#hasPending(this.#pool, recipient);
|
|
433
|
+
}
|
|
434
|
+
drain(recipient) {
|
|
435
|
+
return this.#drain(recipient, false);
|
|
436
|
+
}
|
|
437
|
+
drainLeadingQueueOnly(recipient) {
|
|
438
|
+
return this.#drain(recipient, true);
|
|
439
|
+
}
|
|
440
|
+
#drain(recipient, leadingQueueOnly) {
|
|
441
|
+
return this.#forRecipient(recipient, async (client) => {
|
|
442
|
+
const items = mailboxItemRowsSchema.parse(
|
|
443
|
+
(await client.query(
|
|
444
|
+
`SELECT sequence, communication
|
|
445
|
+
FROM ${this.#t("zukhruf_mailbox_items")}
|
|
446
|
+
WHERE recipient_chat_id = $1
|
|
447
|
+
AND recipient_user_id = $2
|
|
448
|
+
ORDER BY sequence`,
|
|
449
|
+
[recipient.chatId, recipient.userId]
|
|
450
|
+
)).rows
|
|
451
|
+
);
|
|
452
|
+
const firstTrigger = leadingQueueOnly ? items.findIndex(({ communication }) => communication.triggerTurn) : -1;
|
|
453
|
+
const consumed = firstTrigger === -1 ? items : items.slice(0, firstTrigger);
|
|
454
|
+
if (consumed.length === 0) return [];
|
|
455
|
+
await client.query(
|
|
456
|
+
`INSERT INTO ${this.#t("zukhruf_mailbox_consumed_terminal_ids")} (communication_id)
|
|
457
|
+
SELECT unnest($1::text[])
|
|
458
|
+
ON CONFLICT (communication_id) DO NOTHING`,
|
|
459
|
+
[
|
|
460
|
+
consumed.flatMap(
|
|
461
|
+
({ communication }) => communication.type === InterAgentCommunicationTypes.FinalAnswer ? [communication.id] : []
|
|
462
|
+
)
|
|
463
|
+
]
|
|
464
|
+
);
|
|
465
|
+
await client.query(
|
|
466
|
+
`DELETE FROM ${this.#t("zukhruf_mailbox_items")}
|
|
467
|
+
WHERE sequence = ANY($1::bigint[])`,
|
|
468
|
+
[consumed.map(({ sequence }) => sequence)]
|
|
469
|
+
);
|
|
470
|
+
return consumed.map(({ communication }) => communication);
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
#hasPending(queryable, recipient) {
|
|
474
|
+
return this.#exists(
|
|
475
|
+
queryable,
|
|
476
|
+
`SELECT EXISTS (
|
|
477
|
+
SELECT 1 FROM ${this.#t("zukhruf_mailbox_items")}
|
|
478
|
+
WHERE recipient_chat_id = $1 AND recipient_user_id = $2)`,
|
|
479
|
+
[recipient.chatId, recipient.userId]
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
#isTurnActive(client, recipient) {
|
|
483
|
+
return this.#exists(
|
|
484
|
+
client,
|
|
485
|
+
`SELECT EXISTS (
|
|
486
|
+
SELECT 1 FROM ${this.#t("zukhruf_mailbox_activity")}
|
|
487
|
+
WHERE recipient_chat_id = $1 AND recipient_user_id = $2)`,
|
|
488
|
+
[recipient.chatId, recipient.userId]
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
async #exists(queryable, sql, params) {
|
|
492
|
+
const [{ exists }] = existsRowsSchema.parse(
|
|
493
|
+
(await queryable.query(sql, params)).rows
|
|
494
|
+
);
|
|
495
|
+
return exists;
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
// packages/experimental/src/zukhruf/mailbox/sqlite.store.ts
|
|
500
|
+
import { Declaration } from "@zukhruf/sqlite-drift";
|
|
501
|
+
import { open } from "@zukhruf/sqlite-open";
|
|
502
|
+
import { transaction } from "@zukhruf/sqlite-transaction";
|
|
503
|
+
import { z as z3 } from "zod";
|
|
504
|
+
|
|
505
|
+
// packages/experimental/src/zukhruf/mailbox/ddl.sqlite.ts
|
|
506
|
+
var SETUP = `
|
|
507
|
+
PRAGMA synchronous = NORMAL;
|
|
508
|
+
`;
|
|
509
|
+
var statements = [
|
|
510
|
+
`CREATE TABLE zukhruf_mailbox_items (
|
|
511
|
+
sequence INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
512
|
+
recipient_chat_id TEXT NOT NULL,
|
|
513
|
+
recipient_user_id TEXT NOT NULL,
|
|
514
|
+
communication TEXT NOT NULL
|
|
515
|
+
)`,
|
|
516
|
+
`CREATE TABLE zukhruf_mailbox_activity (
|
|
517
|
+
recipient_chat_id TEXT NOT NULL,
|
|
518
|
+
recipient_user_id TEXT NOT NULL,
|
|
519
|
+
turn_id TEXT NOT NULL,
|
|
520
|
+
PRIMARY KEY (recipient_chat_id, recipient_user_id)
|
|
521
|
+
)`,
|
|
522
|
+
`CREATE TABLE zukhruf_mailbox_consumed_terminal_ids (
|
|
523
|
+
communication_id TEXT PRIMARY KEY
|
|
524
|
+
)`,
|
|
525
|
+
`CREATE INDEX zukhruf_mailbox_recipient_sequence
|
|
526
|
+
ON zukhruf_mailbox_items (
|
|
527
|
+
recipient_chat_id,
|
|
528
|
+
recipient_user_id,
|
|
529
|
+
sequence
|
|
530
|
+
)`,
|
|
531
|
+
// enqueue relies on this index through INSERT OR IGNORE.
|
|
532
|
+
`CREATE UNIQUE INDEX zukhruf_mailbox_communication_id
|
|
533
|
+
ON zukhruf_mailbox_items (
|
|
534
|
+
json_extract(communication, '$.id')
|
|
535
|
+
)`
|
|
536
|
+
];
|
|
537
|
+
|
|
538
|
+
// packages/experimental/src/zukhruf/mailbox/sqlite.store.ts
|
|
539
|
+
var tables = new Declaration(statements, { rows: "keep" });
|
|
540
|
+
var mailboxItemRowsSchema2 = z3.array(
|
|
541
|
+
z3.object({
|
|
542
|
+
sequence: z3.number(),
|
|
543
|
+
communication: z3.string().transform((text) => JSON.parse(text)).pipe(communicationSchema)
|
|
314
544
|
})
|
|
315
545
|
);
|
|
316
546
|
var SqliteMailboxStore = class extends MailboxStore {
|
|
@@ -423,7 +653,7 @@ var SqliteMailboxStore = class extends MailboxStore {
|
|
|
423
653
|
return transaction(
|
|
424
654
|
this.#database,
|
|
425
655
|
() => {
|
|
426
|
-
const items =
|
|
656
|
+
const items = mailboxItemRowsSchema2.parse(
|
|
427
657
|
this.#database.prepare(
|
|
428
658
|
`SELECT sequence, communication
|
|
429
659
|
FROM zukhruf_mailbox_items
|
|
@@ -469,7 +699,7 @@ var SqliteMailboxStore = class extends MailboxStore {
|
|
|
469
699
|
|
|
470
700
|
// packages/experimental/src/zukhruf/queue/pg-boss.turn-queue.ts
|
|
471
701
|
import { v7 as uuidv7 } from "uuid";
|
|
472
|
-
import { z as
|
|
702
|
+
import { z as z4 } from "zod";
|
|
473
703
|
import { isRecord } from "@deepagents/context";
|
|
474
704
|
|
|
475
705
|
// packages/experimental/src/zukhruf/queue/turn-queue.ts
|
|
@@ -477,8 +707,7 @@ var TurnQueue = class {
|
|
|
477
707
|
};
|
|
478
708
|
|
|
479
709
|
// packages/experimental/src/zukhruf/queue/pg-boss.turn-queue.ts
|
|
480
|
-
var
|
|
481
|
-
var queueCatalogRowSchema = z2.object({ table: z2.string() });
|
|
710
|
+
var queueCatalogRowSchema = z4.object({ table: z4.string() });
|
|
482
711
|
function deadLetterQueueOf(queue) {
|
|
483
712
|
return `${queue}-dead`;
|
|
484
713
|
}
|
|
@@ -492,13 +721,13 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
492
721
|
#active = /* @__PURE__ */ new Map();
|
|
493
722
|
/** Cancels that arrived before a local worker runs the turn; each expires on its own timer. */
|
|
494
723
|
#cancelIntents = /* @__PURE__ */ new Map();
|
|
495
|
-
constructor(boss, settings,
|
|
724
|
+
constructor(boss, settings, opened) {
|
|
496
725
|
super();
|
|
497
726
|
this.#boss = boss;
|
|
498
727
|
this.#queue = settings.queue;
|
|
499
728
|
this.#schema = settings.schema;
|
|
500
|
-
this.#table = table;
|
|
501
|
-
this.#cancelIntentTtlMs =
|
|
729
|
+
this.#table = opened.table;
|
|
730
|
+
this.#cancelIntentTtlMs = opened.expireInSeconds * 1e3;
|
|
502
731
|
this.#pollingIntervalSeconds = settings.pollingIntervalSeconds;
|
|
503
732
|
}
|
|
504
733
|
/**
|
|
@@ -507,20 +736,13 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
507
736
|
*/
|
|
508
737
|
static async create(boss, options = {}) {
|
|
509
738
|
const settings = _PgBossTurnQueue.#settings(boss, options);
|
|
510
|
-
const
|
|
511
|
-
return new _PgBossTurnQueue(boss, settings,
|
|
739
|
+
const opened = await _PgBossTurnQueue.#openQueue(boss, settings);
|
|
740
|
+
return new _PgBossTurnQueue(boss, settings, opened);
|
|
512
741
|
}
|
|
513
742
|
static #settings(boss, options) {
|
|
514
743
|
const db = boss.getDb();
|
|
515
744
|
const configuredSchema = "config" in db && isRecord(db.config) ? db.config.schema : void 0;
|
|
516
745
|
const bossSchema = typeof configuredSchema === "string" ? configuredSchema : void 0;
|
|
517
|
-
const expireInSeconds = options.expireInSeconds ?? 3600;
|
|
518
|
-
const cancelIntentTtlMs = expireInSeconds * 1e3;
|
|
519
|
-
if (!Number.isFinite(expireInSeconds) || expireInSeconds <= 0 || !Number.isSafeInteger(cancelIntentTtlMs) || cancelIntentTtlMs > Number.MAX_SAFE_INTEGER - Date.now()) {
|
|
520
|
-
throw new Error(
|
|
521
|
-
"PgBossTurnQueue expireInSeconds must be a finite positive duration"
|
|
522
|
-
);
|
|
523
|
-
}
|
|
524
746
|
if (options.schema === void 0 && bossSchema === void 0) {
|
|
525
747
|
throw new Error(
|
|
526
748
|
"PgBossTurnQueue cannot read the schema from a custom PgBoss database adapter; pass the PgBoss schema in options.schema"
|
|
@@ -534,12 +756,12 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
534
756
|
return {
|
|
535
757
|
queue: options.queue ?? "zukhruf-turns",
|
|
536
758
|
schema: options.schema ?? bossSchema ?? "pgboss",
|
|
537
|
-
expireInSeconds,
|
|
759
|
+
expireInSeconds: options.expireInSeconds ?? 3600,
|
|
538
760
|
heartbeatSeconds: options.heartbeatSeconds ?? 30,
|
|
539
761
|
pollingIntervalSeconds: options.pollingIntervalSeconds ?? 1
|
|
540
762
|
};
|
|
541
763
|
}
|
|
542
|
-
/** Creates the queues when they are missing; returns the turn queue
|
|
764
|
+
/** Creates the queues when they are missing; returns the turn queue as stored. */
|
|
543
765
|
static async #openQueue(boss, settings) {
|
|
544
766
|
const deadLetterQueue = deadLetterQueueOf(settings.queue);
|
|
545
767
|
if (!await boss.getQueue(deadLetterQueue)) {
|
|
@@ -557,10 +779,10 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
557
779
|
});
|
|
558
780
|
queue = await boss.getQueue(settings.queue);
|
|
559
781
|
}
|
|
560
|
-
if (!queue) {
|
|
782
|
+
if (!queue?.expireInSeconds) {
|
|
561
783
|
throw new Error(`Queue "${settings.queue}" was not initialized`);
|
|
562
784
|
}
|
|
563
|
-
const { table } = queue;
|
|
785
|
+
const { table, expireInSeconds } = queue;
|
|
564
786
|
try {
|
|
565
787
|
const catalog = await boss.getDb().executeSql(
|
|
566
788
|
`SELECT table_name AS "table"
|
|
@@ -581,7 +803,7 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
581
803
|
{ cause }
|
|
582
804
|
);
|
|
583
805
|
}
|
|
584
|
-
return table;
|
|
806
|
+
return { table, expireInSeconds };
|
|
585
807
|
}
|
|
586
808
|
get queue() {
|
|
587
809
|
return this.#queue;
|
|
@@ -622,10 +844,10 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
622
844
|
async cancel(streamId) {
|
|
623
845
|
this.#rememberCancelIntent(streamId);
|
|
624
846
|
this.#abortLocal(streamId);
|
|
625
|
-
const
|
|
626
|
-
data: { streamId }
|
|
627
|
-
|
|
628
|
-
|
|
847
|
+
const queued = (await this.#boss.findJobs(this.#queue, {
|
|
848
|
+
data: { streamId },
|
|
849
|
+
queued: true
|
|
850
|
+
})).map((job) => job.id);
|
|
629
851
|
if (queued.length > 0) await this.#deleteIfStillQueued(queued);
|
|
630
852
|
this.#abortLocal(streamId);
|
|
631
853
|
const remaining = await this.#boss.findJobs(this.#queue, {
|
|
@@ -741,18 +963,15 @@ var PgBossTurnQueue = class _PgBossTurnQueue extends TurnQueue {
|
|
|
741
963
|
}
|
|
742
964
|
#rememberCancelIntent(streamId) {
|
|
743
965
|
this.#forgetCancelIntent(streamId);
|
|
744
|
-
this.#armCancelIntent(streamId, Date.now() + this.#cancelIntentTtlMs);
|
|
745
|
-
}
|
|
746
|
-
#armCancelIntent(streamId, expiresAt) {
|
|
747
966
|
const timer = globalThis.setTimeout(
|
|
748
|
-
() =>
|
|
749
|
-
|
|
750
|
-
else this.#cancelIntents.delete(streamId);
|
|
751
|
-
},
|
|
752
|
-
Math.min(MAX_TIMEOUT_MS, Math.max(1, expiresAt - Date.now()))
|
|
967
|
+
() => this.#cancelIntents.delete(streamId),
|
|
968
|
+
this.#cancelIntentTtlMs
|
|
753
969
|
);
|
|
754
970
|
timer.unref();
|
|
755
|
-
this.#cancelIntents.set(streamId, {
|
|
971
|
+
this.#cancelIntents.set(streamId, {
|
|
972
|
+
expiresAt: Date.now() + this.#cancelIntentTtlMs,
|
|
973
|
+
timer
|
|
974
|
+
});
|
|
756
975
|
}
|
|
757
976
|
#hasCancelIntent(streamId) {
|
|
758
977
|
const intent = this.#cancelIntents.get(streamId);
|
|
@@ -1359,17 +1578,17 @@ function arraysEqual(left, right) {
|
|
|
1359
1578
|
|
|
1360
1579
|
// packages/experimental/src/zukhruf/control-plane/agent-status-projector.ts
|
|
1361
1580
|
import { isTextUIPart } from "ai";
|
|
1362
|
-
import { z as
|
|
1581
|
+
import { z as z5 } from "zod";
|
|
1363
1582
|
import {
|
|
1364
1583
|
ContextEngine
|
|
1365
1584
|
} from "@deepagents/context";
|
|
1366
|
-
var listedAgentStatusSchema =
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1585
|
+
var listedAgentStatusSchema = z5.union([
|
|
1586
|
+
z5.enum(["pending_init", "running", "interrupted", "shutdown", "not_found"]),
|
|
1587
|
+
z5.object({ completed: z5.string().nullable() }).strict(),
|
|
1588
|
+
z5.object({ errored: z5.string() }).strict()
|
|
1370
1589
|
]);
|
|
1371
|
-
var listedAgentSchema =
|
|
1372
|
-
agent_name:
|
|
1590
|
+
var listedAgentSchema = z5.object({
|
|
1591
|
+
agent_name: z5.string(),
|
|
1373
1592
|
agent_status: listedAgentStatusSchema
|
|
1374
1593
|
}).strict();
|
|
1375
1594
|
var AgentStatusProjector = class _AgentStatusProjector {
|
|
@@ -1485,9 +1704,14 @@ var AgentStatusProjector = class _AgentStatusProjector {
|
|
|
1485
1704
|
};
|
|
1486
1705
|
|
|
1487
1706
|
// packages/experimental/src/zukhruf/control-plane/agent-turn-id.ts
|
|
1488
|
-
import { v5 as uuidv53 } from "uuid";
|
|
1707
|
+
import { v5 as uuidv53, validate as validateUuid } from "uuid";
|
|
1708
|
+
import { z as z6 } from "zod";
|
|
1709
|
+
var prefix = "zukhruf-turn";
|
|
1710
|
+
var agentTurnIdSchema = z6.string().refine((value) => {
|
|
1711
|
+
const [head, scope, turn, ...rest] = value.split(":");
|
|
1712
|
+
return head === prefix && rest.length === 0 && validateUuid(scope) && validateUuid(turn);
|
|
1713
|
+
});
|
|
1489
1714
|
var AgentTurnId = class _AgentTurnId {
|
|
1490
|
-
static #prefix = "zukhruf-turn";
|
|
1491
1715
|
#value;
|
|
1492
1716
|
constructor(value) {
|
|
1493
1717
|
this.#value = value;
|
|
@@ -1497,19 +1721,15 @@ var AgentTurnId = class _AgentTurnId {
|
|
|
1497
1721
|
throw new Error("turn id cannot be empty");
|
|
1498
1722
|
}
|
|
1499
1723
|
const scope = conversationNamespace(conversation);
|
|
1500
|
-
return new _AgentTurnId(
|
|
1501
|
-
`${_AgentTurnId.#prefix}:${scope}:${uuidv53(requestId, scope)}`
|
|
1502
|
-
);
|
|
1724
|
+
return new _AgentTurnId(`${prefix}:${scope}:${uuidv53(requestId, scope)}`);
|
|
1503
1725
|
}
|
|
1504
1726
|
static random(conversation) {
|
|
1505
1727
|
return _AgentTurnId.fromRequest(conversation, crypto.randomUUID());
|
|
1506
1728
|
}
|
|
1507
1729
|
static assertOwner(conversation, streamId) {
|
|
1508
|
-
const expectedPrefix = `${
|
|
1730
|
+
const expectedPrefix = `${prefix}:${conversationNamespace(conversation)}:`;
|
|
1509
1731
|
if (!streamId.startsWith(expectedPrefix)) {
|
|
1510
|
-
throw new
|
|
1511
|
-
`stream "${streamId}" does not belong to conversation "${conversation.chatId}"`
|
|
1512
|
-
);
|
|
1732
|
+
throw new TurnNotFoundError(streamId);
|
|
1513
1733
|
}
|
|
1514
1734
|
}
|
|
1515
1735
|
toString() {
|
|
@@ -1569,13 +1789,12 @@ var AgentControlPlane = class _AgentControlPlane {
|
|
|
1569
1789
|
await this.#directory.assertOwnerIfExists(conversation);
|
|
1570
1790
|
const thread = await this.#directory.load(conversation);
|
|
1571
1791
|
if (thread && !thread.path.isRoot && await this.#queue.getTurnActivity(conversation) !== "running" && !await this.#hasExecutionCapacity(thread)) {
|
|
1572
|
-
throw new
|
|
1792
|
+
throw new AgentThreadLimitError();
|
|
1573
1793
|
}
|
|
1574
1794
|
const streamId = message.role === "assistant" ? await this.#continuationStreamId(conversation, message) : AgentTurnId.fromRequest(conversation, message.id).toString();
|
|
1575
1795
|
if (message.role === "assistant" || turn.trigger === "regenerate-message") {
|
|
1576
1796
|
const status = await this.#streams.store.getStreamStatus(streamId);
|
|
1577
|
-
if (status === void 0)
|
|
1578
|
-
throw new Error("enqueue: continuation stream does not exist");
|
|
1797
|
+
if (status === void 0) throw new TurnNotFoundError(streamId);
|
|
1579
1798
|
if (status === "queued" || status === "running") return streamId;
|
|
1580
1799
|
await this.#streams.reopen(streamId);
|
|
1581
1800
|
} else {
|
|
@@ -1592,12 +1811,7 @@ var AgentControlPlane = class _AgentControlPlane {
|
|
|
1592
1811
|
}
|
|
1593
1812
|
async #continuationStreamId(conversation, message) {
|
|
1594
1813
|
const streamId = (await this.#directory.load(conversation))?.lastTurnId;
|
|
1595
|
-
if (
|
|
1596
|
-
throw new Error("enqueue: assistant continuation has no previous turn");
|
|
1597
|
-
if (message.id !== streamId)
|
|
1598
|
-
throw new Error(
|
|
1599
|
-
"enqueue: assistant continuation must update the current assistant message"
|
|
1600
|
-
);
|
|
1814
|
+
if (message.id !== streamId) throw new StaleTurnError(message.id);
|
|
1601
1815
|
return streamId;
|
|
1602
1816
|
}
|
|
1603
1817
|
recordLatestTurn(conversation, streamId) {
|
|
@@ -1683,11 +1897,11 @@ var AgentControlPlane = class _AgentControlPlane {
|
|
|
1683
1897
|
});
|
|
1684
1898
|
}
|
|
1685
1899
|
async listAgents(actor, pathPrefix) {
|
|
1686
|
-
const
|
|
1900
|
+
const prefix2 = pathPrefix ? actor.thread.path.resolve(pathPrefix) : void 0;
|
|
1687
1901
|
const threads = await this.#directory.listTree(actor.thread);
|
|
1688
1902
|
const agents = await Promise.all(
|
|
1689
1903
|
threads.flatMap((thread) => {
|
|
1690
|
-
if (
|
|
1904
|
+
if (prefix2 && !prefix2.contains(thread.path)) return [];
|
|
1691
1905
|
return [this.#statusProjector.projectListedAgent(actor.turn, thread)];
|
|
1692
1906
|
})
|
|
1693
1907
|
);
|
|
@@ -2041,7 +2255,7 @@ import {
|
|
|
2041
2255
|
modelMessageSchema as modelMessageSchema2
|
|
2042
2256
|
} from "ai";
|
|
2043
2257
|
import { hash, randomUUID as randomUUID2 } from "node:crypto";
|
|
2044
|
-
import { z as
|
|
2258
|
+
import { z as z7 } from "zod";
|
|
2045
2259
|
|
|
2046
2260
|
// packages/compaction/dist/index.js
|
|
2047
2261
|
import {
|
|
@@ -2245,21 +2459,21 @@ ${options.instructions}` : SUMMARY_PROMPT,
|
|
|
2245
2459
|
}
|
|
2246
2460
|
|
|
2247
2461
|
// packages/experimental/src/zukhruf/runtime/compaction.ts
|
|
2248
|
-
var checkpointSchema =
|
|
2249
|
-
sourceCount:
|
|
2250
|
-
sourceHash:
|
|
2251
|
-
replacement:
|
|
2462
|
+
var checkpointSchema = z7.object({
|
|
2463
|
+
sourceCount: z7.number().int().positive(),
|
|
2464
|
+
sourceHash: z7.string(),
|
|
2465
|
+
replacement: z7.array(z7.unknown()).transform(
|
|
2252
2466
|
(messages) => messages.map((message) => modelMessageSchema2.parse(message))
|
|
2253
2467
|
)
|
|
2254
2468
|
});
|
|
2255
|
-
var cacheObservationSchema =
|
|
2256
|
-
scope:
|
|
2257
|
-
prefixLength:
|
|
2258
|
-
prefixHash:
|
|
2259
|
-
startedAt:
|
|
2260
|
-
retentionMs:
|
|
2469
|
+
var cacheObservationSchema = z7.object({
|
|
2470
|
+
scope: z7.string(),
|
|
2471
|
+
prefixLength: z7.number().int().nonnegative(),
|
|
2472
|
+
prefixHash: z7.string(),
|
|
2473
|
+
startedAt: z7.number().int().nonnegative(),
|
|
2474
|
+
retentionMs: z7.number().int().positive().optional()
|
|
2261
2475
|
});
|
|
2262
|
-
var inputUsageSchema = cacheObservationSchema.pick({ scope: true, prefixLength: true, prefixHash: true }).extend({ inputTokens:
|
|
2476
|
+
var inputUsageSchema = cacheObservationSchema.pick({ scope: true, prefixLength: true, prefixHash: true }).extend({ inputTokens: z7.number().int().nonnegative() });
|
|
2263
2477
|
function jsonDigest(value) {
|
|
2264
2478
|
return hash("sha256", JSON.stringify(value));
|
|
2265
2479
|
}
|
|
@@ -2399,9 +2613,9 @@ function createCompaction(config, engine, store, signal, onEvent) {
|
|
|
2399
2613
|
}
|
|
2400
2614
|
if (saved !== void 0) {
|
|
2401
2615
|
const checkpoint2 = checkpointSchema.parse(saved);
|
|
2402
|
-
const
|
|
2403
|
-
if (
|
|
2404
|
-
source =
|
|
2616
|
+
const prefix2 = messages.slice(0, checkpoint2.sourceCount);
|
|
2617
|
+
if (prefix2.length === checkpoint2.sourceCount && jsonDigest(prefix2) === checkpoint2.sourceHash) {
|
|
2618
|
+
source = prefix2;
|
|
2405
2619
|
replacement = checkpoint2.replacement;
|
|
2406
2620
|
messages = [
|
|
2407
2621
|
...replacement,
|
|
@@ -3338,21 +3552,21 @@ import {
|
|
|
3338
3552
|
} from "@deepagents/context";
|
|
3339
3553
|
|
|
3340
3554
|
// packages/experimental/src/zukhruf/runtime/conversation-status/child-progress.ts
|
|
3341
|
-
import { z as
|
|
3342
|
-
var childActivitySchema =
|
|
3343
|
-
id:
|
|
3344
|
-
type:
|
|
3345
|
-
at:
|
|
3346
|
-
actorPath:
|
|
3347
|
-
targetPath:
|
|
3348
|
-
streamId:
|
|
3349
|
-
outcome:
|
|
3555
|
+
import { z as z8 } from "zod";
|
|
3556
|
+
var childActivitySchema = z8.object({
|
|
3557
|
+
id: z8.string(),
|
|
3558
|
+
type: z8.enum(["spawn", "message", "followup", "interrupt", "completion"]),
|
|
3559
|
+
at: z8.number(),
|
|
3560
|
+
actorPath: z8.string(),
|
|
3561
|
+
targetPath: z8.string(),
|
|
3562
|
+
streamId: z8.string(),
|
|
3563
|
+
outcome: z8.enum(["completed", "failed", "cancelled"]).optional()
|
|
3350
3564
|
});
|
|
3351
|
-
var childActivitiesSchema =
|
|
3565
|
+
var childActivitiesSchema = z8.partialRecord(
|
|
3352
3566
|
childActivitySchema.shape.type,
|
|
3353
3567
|
childActivitySchema
|
|
3354
3568
|
);
|
|
3355
|
-
var childActivityMetadataSchema =
|
|
3569
|
+
var childActivityMetadataSchema = z8.looseObject({
|
|
3356
3570
|
childActivities: childActivitiesSchema.default({})
|
|
3357
3571
|
});
|
|
3358
3572
|
|
|
@@ -3646,13 +3860,13 @@ var StatusPublishingTurnQueue = class extends TurnQueue {
|
|
|
3646
3860
|
|
|
3647
3861
|
// packages/experimental/src/zukhruf/collaboration/interrupt-agent.ts
|
|
3648
3862
|
import { tool as tool2 } from "ai";
|
|
3649
|
-
import { z as
|
|
3650
|
-
var interruptAgentInputSchema =
|
|
3651
|
-
target:
|
|
3863
|
+
import { z as z9 } from "zod";
|
|
3864
|
+
var interruptAgentInputSchema = z9.object({
|
|
3865
|
+
target: z9.string().trim().min(1).describe(
|
|
3652
3866
|
"The canonical /root/... path, or a descendant-relative target name."
|
|
3653
3867
|
)
|
|
3654
3868
|
});
|
|
3655
|
-
var interruptAgentOutputSchema =
|
|
3869
|
+
var interruptAgentOutputSchema = z9.object({ previous_status: listedAgentStatusSchema }).strict();
|
|
3656
3870
|
var interruptAgentTool = tool2({
|
|
3657
3871
|
description: "Interrupt an agent's current turn, if any, and return its previous status. The agent remains available for messages and follow-up tasks.",
|
|
3658
3872
|
inputSchema: interruptAgentInputSchema,
|
|
@@ -3662,13 +3876,13 @@ var interruptAgentTool = tool2({
|
|
|
3662
3876
|
|
|
3663
3877
|
// packages/experimental/src/zukhruf/collaboration/list-agents.ts
|
|
3664
3878
|
import { tool as tool3 } from "ai";
|
|
3665
|
-
import { z as
|
|
3666
|
-
var listAgentsInputSchema =
|
|
3667
|
-
path_prefix:
|
|
3879
|
+
import { z as z10 } from "zod";
|
|
3880
|
+
var listAgentsInputSchema = z10.object({
|
|
3881
|
+
path_prefix: z10.string().trim().min(1).describe(
|
|
3668
3882
|
"Task-path prefix without a trailing slash. Omit to list the whole tree."
|
|
3669
3883
|
).optional()
|
|
3670
3884
|
});
|
|
3671
|
-
var listAgentsOutputSchema =
|
|
3885
|
+
var listAgentsOutputSchema = z10.object({ agents: z10.array(listedAgentSchema) }).strict();
|
|
3672
3886
|
var listAgentsTool = tool3({
|
|
3673
3887
|
description: "List live agents in the current root thread tree. Optionally filter by task-path prefix.",
|
|
3674
3888
|
inputSchema: listAgentsInputSchema,
|
|
@@ -3678,12 +3892,12 @@ var listAgentsTool = tool3({
|
|
|
3678
3892
|
|
|
3679
3893
|
// packages/experimental/src/zukhruf/collaboration/message-tools.ts
|
|
3680
3894
|
import { tool as tool4 } from "ai";
|
|
3681
|
-
import { z as
|
|
3682
|
-
var agentMessageInputSchema =
|
|
3683
|
-
target:
|
|
3895
|
+
import { z as z11 } from "zod";
|
|
3896
|
+
var agentMessageInputSchema = z11.object({
|
|
3897
|
+
target: z11.string().trim().min(1).describe(
|
|
3684
3898
|
"The canonical /root/... path, or a descendant-relative target name."
|
|
3685
3899
|
),
|
|
3686
|
-
message:
|
|
3900
|
+
message: z11.string().trim().min(1).describe("The message or follow-up task.")
|
|
3687
3901
|
});
|
|
3688
3902
|
var sendMessageTool = tool4({
|
|
3689
3903
|
description: "Queue a message for another agent. Address siblings with their canonical /root/... path.",
|
|
@@ -3704,7 +3918,7 @@ var followupTaskTool = tool4({
|
|
|
3704
3918
|
|
|
3705
3919
|
// packages/experimental/src/zukhruf/collaboration/spawn-agent.ts
|
|
3706
3920
|
import { tool as tool5 } from "ai";
|
|
3707
|
-
import { z as
|
|
3921
|
+
import { z as z12 } from "zod";
|
|
3708
3922
|
|
|
3709
3923
|
// packages/experimental/src/zukhruf/control-plane/fork-turns.ts
|
|
3710
3924
|
var forkTurnsError = "fork_turns must be `none`, `all`, or a positive integer string";
|
|
@@ -3717,18 +3931,18 @@ function parseForkTurns(value) {
|
|
|
3717
3931
|
}
|
|
3718
3932
|
|
|
3719
3933
|
// packages/experimental/src/zukhruf/collaboration/spawn-agent.ts
|
|
3720
|
-
var spawnAgentInputSchema =
|
|
3721
|
-
agent_type:
|
|
3722
|
-
task_name:
|
|
3934
|
+
var spawnAgentInputSchema = z12.object({
|
|
3935
|
+
agent_type: z12.string().trim().min(1).describe("The name of one available subagent declaration."),
|
|
3936
|
+
task_name: z12.string().trim().min(1).refine(
|
|
3723
3937
|
(value) => value !== "." && value !== ".." && !value.includes("/"),
|
|
3724
3938
|
"task_name must be one non-empty path segment"
|
|
3725
3939
|
).describe("One path segment naming this independent agent task."),
|
|
3726
|
-
message:
|
|
3727
|
-
fork_turns:
|
|
3940
|
+
message: z12.string().refine((value) => value.trim().length > 0, "message cannot be empty").describe("The initial task for the spawned agent."),
|
|
3941
|
+
fork_turns: z12.string().trim().refine((value) => parseForkTurns(value) !== void 0, forkTurnsError).describe(
|
|
3728
3942
|
"Required number of parent turns to fork. Use `none`, `all`, or a positive integer string such as `3`."
|
|
3729
3943
|
)
|
|
3730
3944
|
});
|
|
3731
|
-
var spawnAgentOutputSchema =
|
|
3945
|
+
var spawnAgentOutputSchema = z12.object({ task_name: z12.string() }).strict();
|
|
3732
3946
|
function createSpawnAgentTool(options) {
|
|
3733
3947
|
return tool5({
|
|
3734
3948
|
description: ({ context }) => {
|
|
@@ -3757,11 +3971,11 @@ function createSpawnAgentTool(options) {
|
|
|
3757
3971
|
|
|
3758
3972
|
// packages/experimental/src/zukhruf/collaboration/wait-agent.ts
|
|
3759
3973
|
import { tool as tool6 } from "ai";
|
|
3760
|
-
import { z as
|
|
3761
|
-
var waitAgentOutputSchema =
|
|
3974
|
+
import { z as z13 } from "zod";
|
|
3975
|
+
var waitAgentOutputSchema = z13.object({ message: z13.string(), timed_out: z13.boolean() }).strict();
|
|
3762
3976
|
function createWaitAgentTool(options) {
|
|
3763
|
-
const waitAgentInputSchema =
|
|
3764
|
-
timeout_ms:
|
|
3977
|
+
const waitAgentInputSchema = z13.object({
|
|
3978
|
+
timeout_ms: z13.number().int().max(options.maxTimeoutMs).optional().describe("Maximum time to wait in milliseconds.")
|
|
3765
3979
|
});
|
|
3766
3980
|
return tool6({
|
|
3767
3981
|
description: "Wait for pending mail addressed to this agent without consuming it.",
|
|
@@ -4134,7 +4348,7 @@ var PluginToolComposition = class {
|
|
|
4134
4348
|
};
|
|
4135
4349
|
|
|
4136
4350
|
// packages/experimental/src/zukhruf/runtime/plugin/plugin-manager.ts
|
|
4137
|
-
function
|
|
4351
|
+
function initializedFrom(plugin, definition) {
|
|
4138
4352
|
return plugin.definition === definition;
|
|
4139
4353
|
}
|
|
4140
4354
|
var PluginManager = class {
|
|
@@ -4147,6 +4361,7 @@ var PluginManager = class {
|
|
|
4147
4361
|
#plugins;
|
|
4148
4362
|
#toolComposition;
|
|
4149
4363
|
#resources = new AsyncDisposableStack();
|
|
4364
|
+
#running = [];
|
|
4150
4365
|
constructor(root, bindings, multiAgent) {
|
|
4151
4366
|
let configuredRoot = root;
|
|
4152
4367
|
const pluginBindings = new PluginBindings(root.plugins, bindings);
|
|
@@ -4199,15 +4414,20 @@ var PluginManager = class {
|
|
|
4199
4414
|
return this.#resources.disposeAsync();
|
|
4200
4415
|
}
|
|
4201
4416
|
get(definition) {
|
|
4202
|
-
|
|
4203
|
-
|
|
4417
|
+
if (!this.#plugins.some((plugin2) => plugin2.definition === definition)) {
|
|
4418
|
+
throw new Error(
|
|
4419
|
+
`AgentRuntime: plugin "${definition.name}" does not belong to this runtime`
|
|
4420
|
+
);
|
|
4421
|
+
}
|
|
4422
|
+
const plugin = this.#running.find(
|
|
4423
|
+
(candidate) => initializedFrom(candidate, definition)
|
|
4204
4424
|
);
|
|
4205
4425
|
if (!plugin) {
|
|
4206
4426
|
throw new Error(
|
|
4207
|
-
`AgentRuntime: plugin "${definition.name}"
|
|
4427
|
+
`AgentRuntime: plugin "${definition.name}" has no running phase, since its initialize() returned nothing`
|
|
4208
4428
|
);
|
|
4209
4429
|
}
|
|
4210
|
-
return plugin.
|
|
4430
|
+
return plugin.running;
|
|
4211
4431
|
}
|
|
4212
4432
|
configureTelemetry(context, telemetry) {
|
|
4213
4433
|
const integrations = [];
|
|
@@ -4217,20 +4437,21 @@ var PluginManager = class {
|
|
|
4217
4437
|
return integrations.length === 0 ? telemetry : { ...telemetry, integrations };
|
|
4218
4438
|
}
|
|
4219
4439
|
get reconcilesAvailability() {
|
|
4220
|
-
return this.#
|
|
4221
|
-
({
|
|
4440
|
+
return this.#running.some(
|
|
4441
|
+
({ running }) => Boolean(running.conversationAvailable)
|
|
4222
4442
|
);
|
|
4223
4443
|
}
|
|
4224
|
-
async startWorkers(
|
|
4225
|
-
for (const {
|
|
4226
|
-
if (
|
|
4444
|
+
async startWorkers(workers, waitForActive) {
|
|
4445
|
+
for (const { running } of this.#running) {
|
|
4446
|
+
if (running.work) workers.use(await running.work(waitForActive));
|
|
4227
4447
|
}
|
|
4228
4448
|
}
|
|
4229
4449
|
async initialize(host) {
|
|
4230
4450
|
for (const { definition, instance } of this.#plugins) {
|
|
4231
4451
|
const initialized = await instance.initialize?.(host);
|
|
4232
4452
|
if (!initialized) continue;
|
|
4233
|
-
this.#
|
|
4453
|
+
this.#running.push({ definition, running: initialized });
|
|
4454
|
+
this.#resources.defer(() => initialized[Symbol.asyncDispose]?.());
|
|
4234
4455
|
if (initialized.tools) {
|
|
4235
4456
|
this.#toolComposition.add(definition.name, initialized.tools);
|
|
4236
4457
|
}
|
|
@@ -4240,11 +4461,11 @@ var PluginManager = class {
|
|
|
4240
4461
|
this.#toolComposition.compose(this.declarations.values())
|
|
4241
4462
|
);
|
|
4242
4463
|
}
|
|
4243
|
-
async conversationAvailable(
|
|
4464
|
+
async conversationAvailable(conversation) {
|
|
4244
4465
|
const errors = [];
|
|
4245
|
-
for (const {
|
|
4466
|
+
for (const { running } of this.#running) {
|
|
4246
4467
|
try {
|
|
4247
|
-
await
|
|
4468
|
+
await running.conversationAvailable?.(conversation);
|
|
4248
4469
|
} catch (error) {
|
|
4249
4470
|
errors.push(error);
|
|
4250
4471
|
}
|
|
@@ -4502,6 +4723,7 @@ var RuntimeHost = class {
|
|
|
4502
4723
|
[Symbol.asyncDispose]() {
|
|
4503
4724
|
return this.#resources.disposeAsync();
|
|
4504
4725
|
}
|
|
4726
|
+
/** The running phase `initialize(host)` returned for `definition`. */
|
|
4505
4727
|
plugin(definition) {
|
|
4506
4728
|
return this.#plugins.get(definition);
|
|
4507
4729
|
}
|
|
@@ -4532,7 +4754,7 @@ var RuntimeHost = class {
|
|
|
4532
4754
|
read: () => this.#conversationStatus.read(conversation),
|
|
4533
4755
|
publish: () => this.#conversationStatus.publish(conversation)
|
|
4534
4756
|
},
|
|
4535
|
-
() => this.#plugins.conversationAvailable(
|
|
4757
|
+
() => this.#plugins.conversationAvailable(conversation)
|
|
4536
4758
|
);
|
|
4537
4759
|
}
|
|
4538
4760
|
/**
|
|
@@ -4600,7 +4822,7 @@ var RuntimeHost = class {
|
|
|
4600
4822
|
}
|
|
4601
4823
|
async #startWorkers(options) {
|
|
4602
4824
|
await using workers = new AsyncDisposableStack();
|
|
4603
|
-
await this.#plugins.startWorkers(
|
|
4825
|
+
await this.#plugins.startWorkers(workers, true);
|
|
4604
4826
|
const reconcilesAvailability = this.#plugins.reconcilesAvailability;
|
|
4605
4827
|
workers.use(
|
|
4606
4828
|
await this.#queue.consume(this.#executor.execute.bind(this.#executor), {
|
|
@@ -4610,10 +4832,7 @@ var RuntimeHost = class {
|
|
|
4610
4832
|
onSettled: async ({ chatId, userId }) => {
|
|
4611
4833
|
await this.#conversationStatus.publish({ chatId, userId });
|
|
4612
4834
|
if (reconcilesAvailability) {
|
|
4613
|
-
await this.#plugins.conversationAvailable(
|
|
4614
|
-
chatId,
|
|
4615
|
-
userId
|
|
4616
|
-
});
|
|
4835
|
+
await this.#plugins.conversationAvailable({ chatId, userId });
|
|
4617
4836
|
}
|
|
4618
4837
|
}
|
|
4619
4838
|
})
|
|
@@ -4814,6 +5033,7 @@ export {
|
|
|
4814
5033
|
AgentPluginCapability,
|
|
4815
5034
|
AgentRuntime,
|
|
4816
5035
|
AgentThread,
|
|
5036
|
+
AgentThreadLimitError,
|
|
4817
5037
|
ConversationNotFoundError,
|
|
4818
5038
|
DEFAULT_CONVERSATION_STATUS_CHANNEL,
|
|
4819
5039
|
InterAgentCommunicationTypes,
|
|
@@ -4821,7 +5041,10 @@ export {
|
|
|
4821
5041
|
MessageDeliveryModes,
|
|
4822
5042
|
PgBossConversationStatusChangeSource,
|
|
4823
5043
|
PgBossTurnQueue,
|
|
5044
|
+
PostgresMailboxStore,
|
|
4824
5045
|
SqliteMailboxStore,
|
|
5046
|
+
StaleTurnError,
|
|
5047
|
+
TurnNotFoundError,
|
|
4825
5048
|
TurnQueue,
|
|
4826
5049
|
assertCommunication,
|
|
4827
5050
|
createInterAgentCommunication,
|