@deepagents/experimental 7.7.1 → 7.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +336 -128
- package/dist/index.js.map +4 -4
- package/dist/zukhruf/control-plane/agent-directory.d.ts.map +1 -1
- package/dist/zukhruf/control-plane/conversation-not-found-error.d.ts +9 -0
- package/dist/zukhruf/control-plane/conversation-not-found-error.d.ts.map +1 -0
- package/dist/zukhruf/index.d.ts +2 -0
- package/dist/zukhruf/index.d.ts.map +1 -1
- package/dist/zukhruf/index.js +336 -128
- package/dist/zukhruf/index.js.map +4 -4
- 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/index.js.map +2 -2
- package/dist/zukhruf/plugins/http/index.d.ts.map +1 -1
- package/dist/zukhruf/plugins/http/index.js +16 -0
- package/dist/zukhruf/plugins/http/index.js.map +2 -2
- package/dist/zukhruf/plugins/schedules/http.js.map +2 -2
- package/dist/zukhruf/plugins/schedules/index.js.map +2 -2
- package/dist/zukhruf/plugins/uploads/http.js.map +2 -2
- package/dist/zukhruf/runtime/agent-runtime.d.ts.map +1 -1
- package/package.json +19 -10
package/dist/zukhruf/index.js
CHANGED
|
@@ -182,53 +182,32 @@ var AgentThread = class _AgentThread {
|
|
|
182
182
|
}
|
|
183
183
|
};
|
|
184
184
|
|
|
185
|
+
// packages/experimental/src/zukhruf/control-plane/conversation-not-found-error.ts
|
|
186
|
+
var ConversationNotFoundError = class extends Error {
|
|
187
|
+
name = "ConversationNotFoundError";
|
|
188
|
+
chatId;
|
|
189
|
+
constructor(chatId) {
|
|
190
|
+
super(`chat "${chatId}" does not exist`);
|
|
191
|
+
this.chatId = chatId;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
function assertConversationOwner(conversation, storedUserId) {
|
|
195
|
+
if (storedUserId !== conversation.userId) {
|
|
196
|
+
throw new ConversationNotFoundError(conversation.chatId);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
185
200
|
// packages/experimental/src/zukhruf/instructions.ts
|
|
186
201
|
function defineInstructions(...fragments) {
|
|
187
202
|
return fragments;
|
|
188
203
|
}
|
|
189
204
|
|
|
190
|
-
// packages/experimental/src/zukhruf/mailbox/
|
|
191
|
-
import {
|
|
192
|
-
import {
|
|
193
|
-
import { transaction } from "@zukhruf/sqlite-transaction";
|
|
194
|
-
import { z } from "zod";
|
|
195
|
-
|
|
196
|
-
// packages/experimental/src/zukhruf/mailbox/ddl.sqlite.ts
|
|
197
|
-
var SETUP = `
|
|
198
|
-
PRAGMA synchronous = NORMAL;
|
|
199
|
-
`;
|
|
200
|
-
var statements = [
|
|
201
|
-
`CREATE TABLE zukhruf_mailbox_items (
|
|
202
|
-
sequence INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
203
|
-
recipient_chat_id TEXT NOT NULL,
|
|
204
|
-
recipient_user_id TEXT NOT NULL,
|
|
205
|
-
communication TEXT NOT NULL
|
|
206
|
-
)`,
|
|
207
|
-
`CREATE TABLE zukhruf_mailbox_activity (
|
|
208
|
-
recipient_chat_id TEXT NOT NULL,
|
|
209
|
-
recipient_user_id TEXT NOT NULL,
|
|
210
|
-
turn_id TEXT NOT NULL,
|
|
211
|
-
PRIMARY KEY (recipient_chat_id, recipient_user_id)
|
|
212
|
-
)`,
|
|
213
|
-
`CREATE TABLE zukhruf_mailbox_consumed_terminal_ids (
|
|
214
|
-
communication_id TEXT PRIMARY KEY
|
|
215
|
-
)`,
|
|
216
|
-
`CREATE INDEX zukhruf_mailbox_recipient_sequence
|
|
217
|
-
ON zukhruf_mailbox_items (
|
|
218
|
-
recipient_chat_id,
|
|
219
|
-
recipient_user_id,
|
|
220
|
-
sequence
|
|
221
|
-
)`,
|
|
222
|
-
// enqueue relies on this index through INSERT OR IGNORE.
|
|
223
|
-
`CREATE UNIQUE INDEX zukhruf_mailbox_communication_id
|
|
224
|
-
ON zukhruf_mailbox_items (
|
|
225
|
-
json_extract(communication, '$.id')
|
|
226
|
-
)`
|
|
227
|
-
];
|
|
205
|
+
// packages/experimental/src/zukhruf/mailbox/postgres.store.ts
|
|
206
|
+
import { z as z2 } from "zod";
|
|
207
|
+
import { lockSchemaDDL, postgresTransaction } from "@deepagents/context";
|
|
228
208
|
|
|
229
|
-
// packages/experimental/src/zukhruf/mailbox/
|
|
230
|
-
|
|
231
|
-
};
|
|
209
|
+
// packages/experimental/src/zukhruf/mailbox/communication-schema.ts
|
|
210
|
+
import { z } from "zod";
|
|
232
211
|
|
|
233
212
|
// packages/experimental/src/zukhruf/mailbox/types.ts
|
|
234
213
|
import { randomUUID } from "node:crypto";
|
|
@@ -276,8 +255,7 @@ function assertConversationId(value, label) {
|
|
|
276
255
|
}
|
|
277
256
|
}
|
|
278
257
|
|
|
279
|
-
// packages/experimental/src/zukhruf/mailbox/
|
|
280
|
-
var tables = new Declaration(statements, { rows: "keep" });
|
|
258
|
+
// packages/experimental/src/zukhruf/mailbox/communication-schema.ts
|
|
281
259
|
var conversationIdSchema = z.object({
|
|
282
260
|
chatId: z.string(),
|
|
283
261
|
userId: z.string()
|
|
@@ -292,10 +270,249 @@ var communicationSchema = z.object({
|
|
|
292
270
|
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
293
271
|
triggerTurn: z.boolean()
|
|
294
272
|
});
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
273
|
+
|
|
274
|
+
// packages/experimental/src/zukhruf/mailbox/ddl.postgres.ts
|
|
275
|
+
function mailboxDDL(schema) {
|
|
276
|
+
return `
|
|
277
|
+
CREATE SCHEMA IF NOT EXISTS "${schema}";
|
|
278
|
+
|
|
279
|
+
CREATE TABLE IF NOT EXISTS "${schema}"."zukhruf_mailbox_items" (
|
|
280
|
+
sequence BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
281
|
+
communication_id TEXT NOT NULL UNIQUE,
|
|
282
|
+
recipient_chat_id TEXT NOT NULL,
|
|
283
|
+
recipient_user_id TEXT NOT NULL,
|
|
284
|
+
communication JSONB NOT NULL
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
CREATE INDEX IF NOT EXISTS "zukhruf_mailbox_recipient_sequence"
|
|
288
|
+
ON "${schema}"."zukhruf_mailbox_items" (recipient_chat_id, recipient_user_id, sequence);
|
|
289
|
+
|
|
290
|
+
CREATE TABLE IF NOT EXISTS "${schema}"."zukhruf_mailbox_activity" (
|
|
291
|
+
recipient_chat_id TEXT NOT NULL,
|
|
292
|
+
recipient_user_id TEXT NOT NULL,
|
|
293
|
+
turn_id TEXT NOT NULL,
|
|
294
|
+
PRIMARY KEY (recipient_chat_id, recipient_user_id)
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
CREATE TABLE IF NOT EXISTS "${schema}"."zukhruf_mailbox_consumed_terminal_ids" (
|
|
298
|
+
communication_id TEXT PRIMARY KEY
|
|
299
|
+
);
|
|
300
|
+
`;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// packages/experimental/src/zukhruf/mailbox/store.ts
|
|
304
|
+
var MailboxStore = class {
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
// packages/experimental/src/zukhruf/mailbox/postgres.store.ts
|
|
308
|
+
var mailboxItemRowsSchema = z2.array(
|
|
309
|
+
z2.object({
|
|
310
|
+
sequence: z2.string(),
|
|
311
|
+
communication: communicationSchema
|
|
312
|
+
})
|
|
313
|
+
);
|
|
314
|
+
var existsRowsSchema = z2.tuple([z2.object({ exists: z2.boolean() })]);
|
|
315
|
+
var PostgresMailboxStore = class _PostgresMailboxStore extends MailboxStore {
|
|
316
|
+
#pool;
|
|
317
|
+
#schema;
|
|
318
|
+
constructor(pool, schema) {
|
|
319
|
+
super();
|
|
320
|
+
this.#pool = pool;
|
|
321
|
+
this.#schema = schema;
|
|
322
|
+
}
|
|
323
|
+
/** Opens the store: creates its schema objects before it returns. */
|
|
324
|
+
static async create(options) {
|
|
325
|
+
const schema = options.schema ?? "public";
|
|
326
|
+
await options.pool.query(lockSchemaDDL(mailboxDDL(schema), schema));
|
|
327
|
+
return new _PostgresMailboxStore(options.pool, schema);
|
|
328
|
+
}
|
|
329
|
+
#t(name) {
|
|
330
|
+
return `"${this.#schema}"."${name}"`;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Runs `fn` while holding the recipient's lock, so enqueue, drain and turn
|
|
334
|
+
* handoff on one mailbox take turns across every worker, as SQLite's
|
|
335
|
+
* immediate transactions do.
|
|
336
|
+
*/
|
|
337
|
+
#forRecipient(recipient, fn) {
|
|
338
|
+
return postgresTransaction(this.#pool, async (client) => {
|
|
339
|
+
await client.query(
|
|
340
|
+
"SELECT pg_advisory_xact_lock(hashtextextended($1, 0))",
|
|
341
|
+
[
|
|
342
|
+
`zukhruf:mailbox:${JSON.stringify([this.#schema, recipient.chatId, recipient.userId])}`
|
|
343
|
+
]
|
|
344
|
+
);
|
|
345
|
+
return fn(client);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
async beginTurn(recipient, turnId) {
|
|
349
|
+
await this.#forRecipient(
|
|
350
|
+
recipient,
|
|
351
|
+
(client) => client.query(
|
|
352
|
+
`INSERT INTO ${this.#t("zukhruf_mailbox_activity")}
|
|
353
|
+
(recipient_chat_id, recipient_user_id, turn_id)
|
|
354
|
+
VALUES ($1, $2, $3)
|
|
355
|
+
ON CONFLICT (recipient_chat_id, recipient_user_id)
|
|
356
|
+
DO UPDATE SET turn_id = EXCLUDED.turn_id`,
|
|
357
|
+
[recipient.chatId, recipient.userId, turnId]
|
|
358
|
+
)
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
enqueue(communication) {
|
|
362
|
+
const { recipient } = communication;
|
|
363
|
+
return this.#forRecipient(recipient, async (client) => {
|
|
364
|
+
const consumedTerminal = communication.type === InterAgentCommunicationTypes.FinalAnswer && await this.#exists(
|
|
365
|
+
client,
|
|
366
|
+
`SELECT EXISTS (
|
|
367
|
+
SELECT 1 FROM ${this.#t("zukhruf_mailbox_consumed_terminal_ids")}
|
|
368
|
+
WHERE communication_id = $1)`,
|
|
369
|
+
[communication.id]
|
|
370
|
+
);
|
|
371
|
+
if (!consumedTerminal) {
|
|
372
|
+
await client.query(
|
|
373
|
+
`INSERT INTO ${this.#t("zukhruf_mailbox_items")}
|
|
374
|
+
(communication_id, recipient_chat_id, recipient_user_id, communication)
|
|
375
|
+
VALUES ($1, $2, $3, $4::jsonb)
|
|
376
|
+
ON CONFLICT (communication_id) DO NOTHING`,
|
|
377
|
+
[
|
|
378
|
+
communication.id,
|
|
379
|
+
recipient.chatId,
|
|
380
|
+
recipient.userId,
|
|
381
|
+
JSON.stringify(communication)
|
|
382
|
+
]
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
return { recipientActive: await this.#isTurnActive(client, recipient) };
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
endTurn(recipient, turnId) {
|
|
389
|
+
return this.#forRecipient(recipient, async (client) => {
|
|
390
|
+
const ended = await client.query(
|
|
391
|
+
`DELETE FROM ${this.#t("zukhruf_mailbox_activity")}
|
|
392
|
+
WHERE recipient_chat_id = $1
|
|
393
|
+
AND recipient_user_id = $2
|
|
394
|
+
AND turn_id = $3`,
|
|
395
|
+
[recipient.chatId, recipient.userId, turnId]
|
|
396
|
+
);
|
|
397
|
+
return {
|
|
398
|
+
hasPending: await this.#hasPending(client, recipient),
|
|
399
|
+
turnEnded: ended.rowCount === 1
|
|
400
|
+
};
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
hasPending(recipient) {
|
|
404
|
+
return this.#hasPending(this.#pool, recipient);
|
|
405
|
+
}
|
|
406
|
+
drain(recipient) {
|
|
407
|
+
return this.#drain(recipient, false);
|
|
408
|
+
}
|
|
409
|
+
drainLeadingQueueOnly(recipient) {
|
|
410
|
+
return this.#drain(recipient, true);
|
|
411
|
+
}
|
|
412
|
+
#drain(recipient, leadingQueueOnly) {
|
|
413
|
+
return this.#forRecipient(recipient, async (client) => {
|
|
414
|
+
const items = mailboxItemRowsSchema.parse(
|
|
415
|
+
(await client.query(
|
|
416
|
+
`SELECT sequence, communication
|
|
417
|
+
FROM ${this.#t("zukhruf_mailbox_items")}
|
|
418
|
+
WHERE recipient_chat_id = $1
|
|
419
|
+
AND recipient_user_id = $2
|
|
420
|
+
ORDER BY sequence`,
|
|
421
|
+
[recipient.chatId, recipient.userId]
|
|
422
|
+
)).rows
|
|
423
|
+
);
|
|
424
|
+
const firstTrigger = leadingQueueOnly ? items.findIndex(({ communication }) => communication.triggerTurn) : -1;
|
|
425
|
+
const consumed = firstTrigger === -1 ? items : items.slice(0, firstTrigger);
|
|
426
|
+
if (consumed.length === 0) return [];
|
|
427
|
+
await client.query(
|
|
428
|
+
`INSERT INTO ${this.#t("zukhruf_mailbox_consumed_terminal_ids")} (communication_id)
|
|
429
|
+
SELECT unnest($1::text[])
|
|
430
|
+
ON CONFLICT (communication_id) DO NOTHING`,
|
|
431
|
+
[
|
|
432
|
+
consumed.flatMap(
|
|
433
|
+
({ communication }) => communication.type === InterAgentCommunicationTypes.FinalAnswer ? [communication.id] : []
|
|
434
|
+
)
|
|
435
|
+
]
|
|
436
|
+
);
|
|
437
|
+
await client.query(
|
|
438
|
+
`DELETE FROM ${this.#t("zukhruf_mailbox_items")}
|
|
439
|
+
WHERE sequence = ANY($1::bigint[])`,
|
|
440
|
+
[consumed.map(({ sequence }) => sequence)]
|
|
441
|
+
);
|
|
442
|
+
return consumed.map(({ communication }) => communication);
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
#hasPending(queryable, recipient) {
|
|
446
|
+
return this.#exists(
|
|
447
|
+
queryable,
|
|
448
|
+
`SELECT EXISTS (
|
|
449
|
+
SELECT 1 FROM ${this.#t("zukhruf_mailbox_items")}
|
|
450
|
+
WHERE recipient_chat_id = $1 AND recipient_user_id = $2)`,
|
|
451
|
+
[recipient.chatId, recipient.userId]
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
#isTurnActive(client, recipient) {
|
|
455
|
+
return this.#exists(
|
|
456
|
+
client,
|
|
457
|
+
`SELECT EXISTS (
|
|
458
|
+
SELECT 1 FROM ${this.#t("zukhruf_mailbox_activity")}
|
|
459
|
+
WHERE recipient_chat_id = $1 AND recipient_user_id = $2)`,
|
|
460
|
+
[recipient.chatId, recipient.userId]
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
async #exists(queryable, sql, params) {
|
|
464
|
+
const [{ exists }] = existsRowsSchema.parse(
|
|
465
|
+
(await queryable.query(sql, params)).rows
|
|
466
|
+
);
|
|
467
|
+
return exists;
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
// packages/experimental/src/zukhruf/mailbox/sqlite.store.ts
|
|
472
|
+
import { Declaration } from "@zukhruf/sqlite-drift";
|
|
473
|
+
import { open } from "@zukhruf/sqlite-open";
|
|
474
|
+
import { transaction } from "@zukhruf/sqlite-transaction";
|
|
475
|
+
import { z as z3 } from "zod";
|
|
476
|
+
|
|
477
|
+
// packages/experimental/src/zukhruf/mailbox/ddl.sqlite.ts
|
|
478
|
+
var SETUP = `
|
|
479
|
+
PRAGMA synchronous = NORMAL;
|
|
480
|
+
`;
|
|
481
|
+
var statements = [
|
|
482
|
+
`CREATE TABLE zukhruf_mailbox_items (
|
|
483
|
+
sequence INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
484
|
+
recipient_chat_id TEXT NOT NULL,
|
|
485
|
+
recipient_user_id TEXT NOT NULL,
|
|
486
|
+
communication TEXT NOT NULL
|
|
487
|
+
)`,
|
|
488
|
+
`CREATE TABLE zukhruf_mailbox_activity (
|
|
489
|
+
recipient_chat_id TEXT NOT NULL,
|
|
490
|
+
recipient_user_id TEXT NOT NULL,
|
|
491
|
+
turn_id TEXT NOT NULL,
|
|
492
|
+
PRIMARY KEY (recipient_chat_id, recipient_user_id)
|
|
493
|
+
)`,
|
|
494
|
+
`CREATE TABLE zukhruf_mailbox_consumed_terminal_ids (
|
|
495
|
+
communication_id TEXT PRIMARY KEY
|
|
496
|
+
)`,
|
|
497
|
+
`CREATE INDEX zukhruf_mailbox_recipient_sequence
|
|
498
|
+
ON zukhruf_mailbox_items (
|
|
499
|
+
recipient_chat_id,
|
|
500
|
+
recipient_user_id,
|
|
501
|
+
sequence
|
|
502
|
+
)`,
|
|
503
|
+
// enqueue relies on this index through INSERT OR IGNORE.
|
|
504
|
+
`CREATE UNIQUE INDEX zukhruf_mailbox_communication_id
|
|
505
|
+
ON zukhruf_mailbox_items (
|
|
506
|
+
json_extract(communication, '$.id')
|
|
507
|
+
)`
|
|
508
|
+
];
|
|
509
|
+
|
|
510
|
+
// packages/experimental/src/zukhruf/mailbox/sqlite.store.ts
|
|
511
|
+
var tables = new Declaration(statements, { rows: "keep" });
|
|
512
|
+
var mailboxItemRowsSchema2 = z3.array(
|
|
513
|
+
z3.object({
|
|
514
|
+
sequence: z3.number(),
|
|
515
|
+
communication: z3.string().transform((text) => JSON.parse(text)).pipe(communicationSchema)
|
|
299
516
|
})
|
|
300
517
|
);
|
|
301
518
|
var SqliteMailboxStore = class extends MailboxStore {
|
|
@@ -408,7 +625,7 @@ var SqliteMailboxStore = class extends MailboxStore {
|
|
|
408
625
|
return transaction(
|
|
409
626
|
this.#database,
|
|
410
627
|
() => {
|
|
411
|
-
const items =
|
|
628
|
+
const items = mailboxItemRowsSchema2.parse(
|
|
412
629
|
this.#database.prepare(
|
|
413
630
|
`SELECT sequence, communication
|
|
414
631
|
FROM zukhruf_mailbox_items
|
|
@@ -454,7 +671,7 @@ var SqliteMailboxStore = class extends MailboxStore {
|
|
|
454
671
|
|
|
455
672
|
// packages/experimental/src/zukhruf/queue/pg-boss.turn-queue.ts
|
|
456
673
|
import { v7 as uuidv7 } from "uuid";
|
|
457
|
-
import { z as
|
|
674
|
+
import { z as z4 } from "zod";
|
|
458
675
|
import { isRecord } from "@deepagents/context";
|
|
459
676
|
|
|
460
677
|
// packages/experimental/src/zukhruf/queue/turn-queue.ts
|
|
@@ -463,7 +680,7 @@ var TurnQueue = class {
|
|
|
463
680
|
|
|
464
681
|
// packages/experimental/src/zukhruf/queue/pg-boss.turn-queue.ts
|
|
465
682
|
var MAX_TIMEOUT_MS = 2147483647;
|
|
466
|
-
var queueCatalogRowSchema =
|
|
683
|
+
var queueCatalogRowSchema = z4.object({ table: z4.string() });
|
|
467
684
|
function deadLetterQueueOf(queue) {
|
|
468
685
|
return `${queue}-dead`;
|
|
469
686
|
}
|
|
@@ -857,14 +1074,14 @@ var AgentDirectory = class _AgentDirectory {
|
|
|
857
1074
|
async assertOwnerIfExists(conversation) {
|
|
858
1075
|
const chat2 = await this.#store.getChat(conversation.chatId);
|
|
859
1076
|
if (!chat2) return;
|
|
860
|
-
|
|
1077
|
+
assertConversationOwner(conversation, chat2.userId);
|
|
861
1078
|
const thread = this.#threadFromMetadata(conversation, chat2.metadata);
|
|
862
1079
|
if (thread) await this.#assertValidParent(thread);
|
|
863
1080
|
}
|
|
864
1081
|
async load(conversation) {
|
|
865
1082
|
const chat2 = await this.#store.getChat(conversation.chatId);
|
|
866
|
-
if (chat2) this.#assertOwner(conversation, chat2.userId);
|
|
867
1083
|
if (!chat2) return void 0;
|
|
1084
|
+
assertConversationOwner(conversation, chat2.userId);
|
|
868
1085
|
const thread = this.#threadFromMetadata(conversation, chat2.metadata);
|
|
869
1086
|
if (thread) await this.#assertValidParent(thread);
|
|
870
1087
|
return thread;
|
|
@@ -877,7 +1094,7 @@ var AgentDirectory = class _AgentDirectory {
|
|
|
877
1094
|
let thread;
|
|
878
1095
|
let adopted = false;
|
|
879
1096
|
await this.#store.updateChat(conversation.chatId, (chat2) => {
|
|
880
|
-
|
|
1097
|
+
assertConversationOwner(conversation, chat2.userId);
|
|
881
1098
|
const existing = this.#threadFromMetadata(conversation, chat2.metadata);
|
|
882
1099
|
if (existing) {
|
|
883
1100
|
thread = existing;
|
|
@@ -974,12 +1191,6 @@ var AgentDirectory = class _AgentDirectory {
|
|
|
974
1191
|
uuidv5.URL
|
|
975
1192
|
);
|
|
976
1193
|
}
|
|
977
|
-
#assertOwner(conversation, storedUserId) {
|
|
978
|
-
if (storedUserId === conversation.userId) return;
|
|
979
|
-
throw new Error(
|
|
980
|
-
`chat "${conversation.chatId}" belongs to user "${storedUserId}", not "${conversation.userId}"`
|
|
981
|
-
);
|
|
982
|
-
}
|
|
983
1194
|
#threadFromMetadata(conversation, metadata) {
|
|
984
1195
|
const thread = AgentThread.fromMetadata(conversation, metadata);
|
|
985
1196
|
if (!thread && AgentThread.hasReservedMetadata(metadata)) {
|
|
@@ -1017,7 +1228,7 @@ var AgentDirectory = class _AgentDirectory {
|
|
|
1017
1228
|
async #updateLatestTurn(conversation, streamId, ...expected) {
|
|
1018
1229
|
let result;
|
|
1019
1230
|
await this.#store.updateChat(conversation.chatId, (chat2) => {
|
|
1020
|
-
|
|
1231
|
+
assertConversationOwner(conversation, chat2.userId);
|
|
1021
1232
|
const thread = this.#threadFromMetadata(conversation, chat2.metadata);
|
|
1022
1233
|
if (!thread) {
|
|
1023
1234
|
throw new Error(
|
|
@@ -1350,17 +1561,17 @@ function arraysEqual(left, right) {
|
|
|
1350
1561
|
|
|
1351
1562
|
// packages/experimental/src/zukhruf/control-plane/agent-status-projector.ts
|
|
1352
1563
|
import { isTextUIPart } from "ai";
|
|
1353
|
-
import { z as
|
|
1564
|
+
import { z as z5 } from "zod";
|
|
1354
1565
|
import {
|
|
1355
1566
|
ContextEngine
|
|
1356
1567
|
} from "@deepagents/context";
|
|
1357
|
-
var listedAgentStatusSchema =
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1568
|
+
var listedAgentStatusSchema = z5.union([
|
|
1569
|
+
z5.enum(["pending_init", "running", "interrupted", "shutdown", "not_found"]),
|
|
1570
|
+
z5.object({ completed: z5.string().nullable() }).strict(),
|
|
1571
|
+
z5.object({ errored: z5.string() }).strict()
|
|
1361
1572
|
]);
|
|
1362
|
-
var listedAgentSchema =
|
|
1363
|
-
agent_name:
|
|
1573
|
+
var listedAgentSchema = z5.object({
|
|
1574
|
+
agent_name: z5.string(),
|
|
1364
1575
|
agent_status: listedAgentStatusSchema
|
|
1365
1576
|
}).strict();
|
|
1366
1577
|
var AgentStatusProjector = class _AgentStatusProjector {
|
|
@@ -2032,7 +2243,7 @@ import {
|
|
|
2032
2243
|
modelMessageSchema as modelMessageSchema2
|
|
2033
2244
|
} from "ai";
|
|
2034
2245
|
import { hash, randomUUID as randomUUID2 } from "node:crypto";
|
|
2035
|
-
import { z as
|
|
2246
|
+
import { z as z6 } from "zod";
|
|
2036
2247
|
|
|
2037
2248
|
// packages/compaction/dist/index.js
|
|
2038
2249
|
import {
|
|
@@ -2236,21 +2447,21 @@ ${options.instructions}` : SUMMARY_PROMPT,
|
|
|
2236
2447
|
}
|
|
2237
2448
|
|
|
2238
2449
|
// packages/experimental/src/zukhruf/runtime/compaction.ts
|
|
2239
|
-
var checkpointSchema =
|
|
2240
|
-
sourceCount:
|
|
2241
|
-
sourceHash:
|
|
2242
|
-
replacement:
|
|
2450
|
+
var checkpointSchema = z6.object({
|
|
2451
|
+
sourceCount: z6.number().int().positive(),
|
|
2452
|
+
sourceHash: z6.string(),
|
|
2453
|
+
replacement: z6.array(z6.unknown()).transform(
|
|
2243
2454
|
(messages) => messages.map((message) => modelMessageSchema2.parse(message))
|
|
2244
2455
|
)
|
|
2245
2456
|
});
|
|
2246
|
-
var cacheObservationSchema =
|
|
2247
|
-
scope:
|
|
2248
|
-
prefixLength:
|
|
2249
|
-
prefixHash:
|
|
2250
|
-
startedAt:
|
|
2251
|
-
retentionMs:
|
|
2457
|
+
var cacheObservationSchema = z6.object({
|
|
2458
|
+
scope: z6.string(),
|
|
2459
|
+
prefixLength: z6.number().int().nonnegative(),
|
|
2460
|
+
prefixHash: z6.string(),
|
|
2461
|
+
startedAt: z6.number().int().nonnegative(),
|
|
2462
|
+
retentionMs: z6.number().int().positive().optional()
|
|
2252
2463
|
});
|
|
2253
|
-
var inputUsageSchema = cacheObservationSchema.pick({ scope: true, prefixLength: true, prefixHash: true }).extend({ inputTokens:
|
|
2464
|
+
var inputUsageSchema = cacheObservationSchema.pick({ scope: true, prefixLength: true, prefixHash: true }).extend({ inputTokens: z6.number().int().nonnegative() });
|
|
2254
2465
|
function jsonDigest(value) {
|
|
2255
2466
|
return hash("sha256", JSON.stringify(value));
|
|
2256
2467
|
}
|
|
@@ -3329,21 +3540,21 @@ import {
|
|
|
3329
3540
|
} from "@deepagents/context";
|
|
3330
3541
|
|
|
3331
3542
|
// packages/experimental/src/zukhruf/runtime/conversation-status/child-progress.ts
|
|
3332
|
-
import { z as
|
|
3333
|
-
var childActivitySchema =
|
|
3334
|
-
id:
|
|
3335
|
-
type:
|
|
3336
|
-
at:
|
|
3337
|
-
actorPath:
|
|
3338
|
-
targetPath:
|
|
3339
|
-
streamId:
|
|
3340
|
-
outcome:
|
|
3543
|
+
import { z as z7 } from "zod";
|
|
3544
|
+
var childActivitySchema = z7.object({
|
|
3545
|
+
id: z7.string(),
|
|
3546
|
+
type: z7.enum(["spawn", "message", "followup", "interrupt", "completion"]),
|
|
3547
|
+
at: z7.number(),
|
|
3548
|
+
actorPath: z7.string(),
|
|
3549
|
+
targetPath: z7.string(),
|
|
3550
|
+
streamId: z7.string(),
|
|
3551
|
+
outcome: z7.enum(["completed", "failed", "cancelled"]).optional()
|
|
3341
3552
|
});
|
|
3342
|
-
var childActivitiesSchema =
|
|
3553
|
+
var childActivitiesSchema = z7.partialRecord(
|
|
3343
3554
|
childActivitySchema.shape.type,
|
|
3344
3555
|
childActivitySchema
|
|
3345
3556
|
);
|
|
3346
|
-
var childActivityMetadataSchema =
|
|
3557
|
+
var childActivityMetadataSchema = z7.looseObject({
|
|
3347
3558
|
childActivities: childActivitiesSchema.default({})
|
|
3348
3559
|
});
|
|
3349
3560
|
|
|
@@ -3637,13 +3848,13 @@ var StatusPublishingTurnQueue = class extends TurnQueue {
|
|
|
3637
3848
|
|
|
3638
3849
|
// packages/experimental/src/zukhruf/collaboration/interrupt-agent.ts
|
|
3639
3850
|
import { tool as tool2 } from "ai";
|
|
3640
|
-
import { z as
|
|
3641
|
-
var interruptAgentInputSchema =
|
|
3642
|
-
target:
|
|
3851
|
+
import { z as z8 } from "zod";
|
|
3852
|
+
var interruptAgentInputSchema = z8.object({
|
|
3853
|
+
target: z8.string().trim().min(1).describe(
|
|
3643
3854
|
"The canonical /root/... path, or a descendant-relative target name."
|
|
3644
3855
|
)
|
|
3645
3856
|
});
|
|
3646
|
-
var interruptAgentOutputSchema =
|
|
3857
|
+
var interruptAgentOutputSchema = z8.object({ previous_status: listedAgentStatusSchema }).strict();
|
|
3647
3858
|
var interruptAgentTool = tool2({
|
|
3648
3859
|
description: "Interrupt an agent's current turn, if any, and return its previous status. The agent remains available for messages and follow-up tasks.",
|
|
3649
3860
|
inputSchema: interruptAgentInputSchema,
|
|
@@ -3653,13 +3864,13 @@ var interruptAgentTool = tool2({
|
|
|
3653
3864
|
|
|
3654
3865
|
// packages/experimental/src/zukhruf/collaboration/list-agents.ts
|
|
3655
3866
|
import { tool as tool3 } from "ai";
|
|
3656
|
-
import { z as
|
|
3657
|
-
var listAgentsInputSchema =
|
|
3658
|
-
path_prefix:
|
|
3867
|
+
import { z as z9 } from "zod";
|
|
3868
|
+
var listAgentsInputSchema = z9.object({
|
|
3869
|
+
path_prefix: z9.string().trim().min(1).describe(
|
|
3659
3870
|
"Task-path prefix without a trailing slash. Omit to list the whole tree."
|
|
3660
3871
|
).optional()
|
|
3661
3872
|
});
|
|
3662
|
-
var listAgentsOutputSchema =
|
|
3873
|
+
var listAgentsOutputSchema = z9.object({ agents: z9.array(listedAgentSchema) }).strict();
|
|
3663
3874
|
var listAgentsTool = tool3({
|
|
3664
3875
|
description: "List live agents in the current root thread tree. Optionally filter by task-path prefix.",
|
|
3665
3876
|
inputSchema: listAgentsInputSchema,
|
|
@@ -3669,12 +3880,12 @@ var listAgentsTool = tool3({
|
|
|
3669
3880
|
|
|
3670
3881
|
// packages/experimental/src/zukhruf/collaboration/message-tools.ts
|
|
3671
3882
|
import { tool as tool4 } from "ai";
|
|
3672
|
-
import { z as
|
|
3673
|
-
var agentMessageInputSchema =
|
|
3674
|
-
target:
|
|
3883
|
+
import { z as z10 } from "zod";
|
|
3884
|
+
var agentMessageInputSchema = z10.object({
|
|
3885
|
+
target: z10.string().trim().min(1).describe(
|
|
3675
3886
|
"The canonical /root/... path, or a descendant-relative target name."
|
|
3676
3887
|
),
|
|
3677
|
-
message:
|
|
3888
|
+
message: z10.string().trim().min(1).describe("The message or follow-up task.")
|
|
3678
3889
|
});
|
|
3679
3890
|
var sendMessageTool = tool4({
|
|
3680
3891
|
description: "Queue a message for another agent. Address siblings with their canonical /root/... path.",
|
|
@@ -3695,7 +3906,7 @@ var followupTaskTool = tool4({
|
|
|
3695
3906
|
|
|
3696
3907
|
// packages/experimental/src/zukhruf/collaboration/spawn-agent.ts
|
|
3697
3908
|
import { tool as tool5 } from "ai";
|
|
3698
|
-
import { z as
|
|
3909
|
+
import { z as z11 } from "zod";
|
|
3699
3910
|
|
|
3700
3911
|
// packages/experimental/src/zukhruf/control-plane/fork-turns.ts
|
|
3701
3912
|
var forkTurnsError = "fork_turns must be `none`, `all`, or a positive integer string";
|
|
@@ -3708,18 +3919,18 @@ function parseForkTurns(value) {
|
|
|
3708
3919
|
}
|
|
3709
3920
|
|
|
3710
3921
|
// packages/experimental/src/zukhruf/collaboration/spawn-agent.ts
|
|
3711
|
-
var spawnAgentInputSchema =
|
|
3712
|
-
agent_type:
|
|
3713
|
-
task_name:
|
|
3922
|
+
var spawnAgentInputSchema = z11.object({
|
|
3923
|
+
agent_type: z11.string().trim().min(1).describe("The name of one available subagent declaration."),
|
|
3924
|
+
task_name: z11.string().trim().min(1).refine(
|
|
3714
3925
|
(value) => value !== "." && value !== ".." && !value.includes("/"),
|
|
3715
3926
|
"task_name must be one non-empty path segment"
|
|
3716
3927
|
).describe("One path segment naming this independent agent task."),
|
|
3717
|
-
message:
|
|
3718
|
-
fork_turns:
|
|
3928
|
+
message: z11.string().refine((value) => value.trim().length > 0, "message cannot be empty").describe("The initial task for the spawned agent."),
|
|
3929
|
+
fork_turns: z11.string().trim().refine((value) => parseForkTurns(value) !== void 0, forkTurnsError).describe(
|
|
3719
3930
|
"Required number of parent turns to fork. Use `none`, `all`, or a positive integer string such as `3`."
|
|
3720
3931
|
)
|
|
3721
3932
|
});
|
|
3722
|
-
var spawnAgentOutputSchema =
|
|
3933
|
+
var spawnAgentOutputSchema = z11.object({ task_name: z11.string() }).strict();
|
|
3723
3934
|
function createSpawnAgentTool(options) {
|
|
3724
3935
|
return tool5({
|
|
3725
3936
|
description: ({ context }) => {
|
|
@@ -3748,11 +3959,11 @@ function createSpawnAgentTool(options) {
|
|
|
3748
3959
|
|
|
3749
3960
|
// packages/experimental/src/zukhruf/collaboration/wait-agent.ts
|
|
3750
3961
|
import { tool as tool6 } from "ai";
|
|
3751
|
-
import { z as
|
|
3752
|
-
var waitAgentOutputSchema =
|
|
3962
|
+
import { z as z12 } from "zod";
|
|
3963
|
+
var waitAgentOutputSchema = z12.object({ message: z12.string(), timed_out: z12.boolean() }).strict();
|
|
3753
3964
|
function createWaitAgentTool(options) {
|
|
3754
|
-
const waitAgentInputSchema =
|
|
3755
|
-
timeout_ms:
|
|
3965
|
+
const waitAgentInputSchema = z12.object({
|
|
3966
|
+
timeout_ms: z12.number().int().max(options.maxTimeoutMs).optional().describe("Maximum time to wait in milliseconds.")
|
|
3756
3967
|
});
|
|
3757
3968
|
return tool6({
|
|
3758
3969
|
description: "Wait for pending mail addressed to this agent without consuming it.",
|
|
@@ -4477,10 +4688,13 @@ var RuntimeHost = class {
|
|
|
4477
4688
|
subscribeConversationStatus: (signal) => this.subscribeConversationStatus(signal),
|
|
4478
4689
|
// Borrows the root declaration's sandbox directly: resolving the
|
|
4479
4690
|
// conversation through the control plane would create its root thread.
|
|
4480
|
-
sandbox: (conversation) =>
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4691
|
+
sandbox: async (conversation) => {
|
|
4692
|
+
await this.#directory.assertOwnerIfExists(conversation);
|
|
4693
|
+
return sandboxes.acquire(this.#root, {
|
|
4694
|
+
chatId: conversation.chatId,
|
|
4695
|
+
userId: conversation.userId
|
|
4696
|
+
});
|
|
4697
|
+
}
|
|
4484
4698
|
};
|
|
4485
4699
|
resources.use(this.#workers);
|
|
4486
4700
|
}
|
|
@@ -4537,21 +4751,13 @@ var RuntimeHost = class {
|
|
|
4537
4751
|
}
|
|
4538
4752
|
async #readConversationMetadata(conversation) {
|
|
4539
4753
|
const chat2 = await this.#store.getChat(conversation.chatId);
|
|
4540
|
-
if (!chat2) throw new
|
|
4541
|
-
|
|
4542
|
-
throw new Error(
|
|
4543
|
-
`chat "${conversation.chatId}" belongs to user "${chat2.userId}", not "${conversation.userId}"`
|
|
4544
|
-
);
|
|
4545
|
-
}
|
|
4754
|
+
if (!chat2) throw new ConversationNotFoundError(conversation.chatId);
|
|
4755
|
+
assertConversationOwner(conversation, chat2.userId);
|
|
4546
4756
|
return chat2.metadata;
|
|
4547
4757
|
}
|
|
4548
4758
|
async #updateConversationMetadata(conversation, update) {
|
|
4549
4759
|
await this.#store.updateChat(conversation.chatId, (chat2) => {
|
|
4550
|
-
|
|
4551
|
-
throw new Error(
|
|
4552
|
-
`chat "${conversation.chatId}" belongs to user "${chat2.userId}", not "${conversation.userId}"`
|
|
4553
|
-
);
|
|
4554
|
-
}
|
|
4760
|
+
assertConversationOwner(conversation, chat2.userId);
|
|
4555
4761
|
return { metadata: update(chat2.metadata) };
|
|
4556
4762
|
});
|
|
4557
4763
|
}
|
|
@@ -4810,12 +5016,14 @@ export {
|
|
|
4810
5016
|
AgentPluginCapability,
|
|
4811
5017
|
AgentRuntime,
|
|
4812
5018
|
AgentThread,
|
|
5019
|
+
ConversationNotFoundError,
|
|
4813
5020
|
DEFAULT_CONVERSATION_STATUS_CHANNEL,
|
|
4814
5021
|
InterAgentCommunicationTypes,
|
|
4815
5022
|
MailboxStore,
|
|
4816
5023
|
MessageDeliveryModes,
|
|
4817
5024
|
PgBossConversationStatusChangeSource,
|
|
4818
5025
|
PgBossTurnQueue,
|
|
5026
|
+
PostgresMailboxStore,
|
|
4819
5027
|
SqliteMailboxStore,
|
|
4820
5028
|
TurnQueue,
|
|
4821
5029
|
assertCommunication,
|