@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/index.js
CHANGED
|
@@ -325,12 +325,14 @@ __export(zukhruf_exports, {
|
|
|
325
325
|
AgentPluginCapability: () => AgentPluginCapability,
|
|
326
326
|
AgentRuntime: () => AgentRuntime,
|
|
327
327
|
AgentThread: () => AgentThread,
|
|
328
|
+
ConversationNotFoundError: () => ConversationNotFoundError,
|
|
328
329
|
DEFAULT_CONVERSATION_STATUS_CHANNEL: () => DEFAULT_CONVERSATION_STATUS_CHANNEL,
|
|
329
330
|
InterAgentCommunicationTypes: () => InterAgentCommunicationTypes,
|
|
330
331
|
MailboxStore: () => MailboxStore,
|
|
331
332
|
MessageDeliveryModes: () => MessageDeliveryModes,
|
|
332
333
|
PgBossConversationStatusChangeSource: () => PgBossConversationStatusChangeSource,
|
|
333
334
|
PgBossTurnQueue: () => PgBossTurnQueue,
|
|
335
|
+
PostgresMailboxStore: () => PostgresMailboxStore,
|
|
334
336
|
SqliteMailboxStore: () => SqliteMailboxStore,
|
|
335
337
|
TurnQueue: () => TurnQueue,
|
|
336
338
|
assertCommunication: () => assertCommunication,
|
|
@@ -526,53 +528,32 @@ var AgentThread = class _AgentThread {
|
|
|
526
528
|
}
|
|
527
529
|
};
|
|
528
530
|
|
|
531
|
+
// packages/experimental/src/zukhruf/control-plane/conversation-not-found-error.ts
|
|
532
|
+
var ConversationNotFoundError = class extends Error {
|
|
533
|
+
name = "ConversationNotFoundError";
|
|
534
|
+
chatId;
|
|
535
|
+
constructor(chatId) {
|
|
536
|
+
super(`chat "${chatId}" does not exist`);
|
|
537
|
+
this.chatId = chatId;
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
function assertConversationOwner(conversation, storedUserId) {
|
|
541
|
+
if (storedUserId !== conversation.userId) {
|
|
542
|
+
throw new ConversationNotFoundError(conversation.chatId);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
529
546
|
// packages/experimental/src/zukhruf/instructions.ts
|
|
530
547
|
function defineInstructions(...fragments) {
|
|
531
548
|
return fragments;
|
|
532
549
|
}
|
|
533
550
|
|
|
534
|
-
// packages/experimental/src/zukhruf/mailbox/
|
|
535
|
-
import {
|
|
536
|
-
import {
|
|
537
|
-
import { transaction } from "@zukhruf/sqlite-transaction";
|
|
538
|
-
import { z } from "zod";
|
|
539
|
-
|
|
540
|
-
// packages/experimental/src/zukhruf/mailbox/ddl.sqlite.ts
|
|
541
|
-
var SETUP = `
|
|
542
|
-
PRAGMA synchronous = NORMAL;
|
|
543
|
-
`;
|
|
544
|
-
var statements = [
|
|
545
|
-
`CREATE TABLE zukhruf_mailbox_items (
|
|
546
|
-
sequence INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
547
|
-
recipient_chat_id TEXT NOT NULL,
|
|
548
|
-
recipient_user_id TEXT NOT NULL,
|
|
549
|
-
communication TEXT NOT NULL
|
|
550
|
-
)`,
|
|
551
|
-
`CREATE TABLE zukhruf_mailbox_activity (
|
|
552
|
-
recipient_chat_id TEXT NOT NULL,
|
|
553
|
-
recipient_user_id TEXT NOT NULL,
|
|
554
|
-
turn_id TEXT NOT NULL,
|
|
555
|
-
PRIMARY KEY (recipient_chat_id, recipient_user_id)
|
|
556
|
-
)`,
|
|
557
|
-
`CREATE TABLE zukhruf_mailbox_consumed_terminal_ids (
|
|
558
|
-
communication_id TEXT PRIMARY KEY
|
|
559
|
-
)`,
|
|
560
|
-
`CREATE INDEX zukhruf_mailbox_recipient_sequence
|
|
561
|
-
ON zukhruf_mailbox_items (
|
|
562
|
-
recipient_chat_id,
|
|
563
|
-
recipient_user_id,
|
|
564
|
-
sequence
|
|
565
|
-
)`,
|
|
566
|
-
// enqueue relies on this index through INSERT OR IGNORE.
|
|
567
|
-
`CREATE UNIQUE INDEX zukhruf_mailbox_communication_id
|
|
568
|
-
ON zukhruf_mailbox_items (
|
|
569
|
-
json_extract(communication, '$.id')
|
|
570
|
-
)`
|
|
571
|
-
];
|
|
551
|
+
// packages/experimental/src/zukhruf/mailbox/postgres.store.ts
|
|
552
|
+
import { z as z2 } from "zod";
|
|
553
|
+
import { lockSchemaDDL, postgresTransaction } from "@deepagents/context";
|
|
572
554
|
|
|
573
|
-
// packages/experimental/src/zukhruf/mailbox/
|
|
574
|
-
|
|
575
|
-
};
|
|
555
|
+
// packages/experimental/src/zukhruf/mailbox/communication-schema.ts
|
|
556
|
+
import { z } from "zod";
|
|
576
557
|
|
|
577
558
|
// packages/experimental/src/zukhruf/mailbox/types.ts
|
|
578
559
|
import { randomUUID } from "node:crypto";
|
|
@@ -620,8 +601,7 @@ function assertConversationId(value, label) {
|
|
|
620
601
|
}
|
|
621
602
|
}
|
|
622
603
|
|
|
623
|
-
// packages/experimental/src/zukhruf/mailbox/
|
|
624
|
-
var tables = new Declaration(statements, { rows: "keep" });
|
|
604
|
+
// packages/experimental/src/zukhruf/mailbox/communication-schema.ts
|
|
625
605
|
var conversationIdSchema = z.object({
|
|
626
606
|
chatId: z.string(),
|
|
627
607
|
userId: z.string()
|
|
@@ -636,10 +616,249 @@ var communicationSchema = z.object({
|
|
|
636
616
|
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
637
617
|
triggerTurn: z.boolean()
|
|
638
618
|
});
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
619
|
+
|
|
620
|
+
// packages/experimental/src/zukhruf/mailbox/ddl.postgres.ts
|
|
621
|
+
function mailboxDDL(schema) {
|
|
622
|
+
return `
|
|
623
|
+
CREATE SCHEMA IF NOT EXISTS "${schema}";
|
|
624
|
+
|
|
625
|
+
CREATE TABLE IF NOT EXISTS "${schema}"."zukhruf_mailbox_items" (
|
|
626
|
+
sequence BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
627
|
+
communication_id TEXT NOT NULL UNIQUE,
|
|
628
|
+
recipient_chat_id TEXT NOT NULL,
|
|
629
|
+
recipient_user_id TEXT NOT NULL,
|
|
630
|
+
communication JSONB NOT NULL
|
|
631
|
+
);
|
|
632
|
+
|
|
633
|
+
CREATE INDEX IF NOT EXISTS "zukhruf_mailbox_recipient_sequence"
|
|
634
|
+
ON "${schema}"."zukhruf_mailbox_items" (recipient_chat_id, recipient_user_id, sequence);
|
|
635
|
+
|
|
636
|
+
CREATE TABLE IF NOT EXISTS "${schema}"."zukhruf_mailbox_activity" (
|
|
637
|
+
recipient_chat_id TEXT NOT NULL,
|
|
638
|
+
recipient_user_id TEXT NOT NULL,
|
|
639
|
+
turn_id TEXT NOT NULL,
|
|
640
|
+
PRIMARY KEY (recipient_chat_id, recipient_user_id)
|
|
641
|
+
);
|
|
642
|
+
|
|
643
|
+
CREATE TABLE IF NOT EXISTS "${schema}"."zukhruf_mailbox_consumed_terminal_ids" (
|
|
644
|
+
communication_id TEXT PRIMARY KEY
|
|
645
|
+
);
|
|
646
|
+
`;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// packages/experimental/src/zukhruf/mailbox/store.ts
|
|
650
|
+
var MailboxStore = class {
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
// packages/experimental/src/zukhruf/mailbox/postgres.store.ts
|
|
654
|
+
var mailboxItemRowsSchema = z2.array(
|
|
655
|
+
z2.object({
|
|
656
|
+
sequence: z2.string(),
|
|
657
|
+
communication: communicationSchema
|
|
658
|
+
})
|
|
659
|
+
);
|
|
660
|
+
var existsRowsSchema = z2.tuple([z2.object({ exists: z2.boolean() })]);
|
|
661
|
+
var PostgresMailboxStore = class _PostgresMailboxStore extends MailboxStore {
|
|
662
|
+
#pool;
|
|
663
|
+
#schema;
|
|
664
|
+
constructor(pool, schema) {
|
|
665
|
+
super();
|
|
666
|
+
this.#pool = pool;
|
|
667
|
+
this.#schema = schema;
|
|
668
|
+
}
|
|
669
|
+
/** Opens the store: creates its schema objects before it returns. */
|
|
670
|
+
static async create(options) {
|
|
671
|
+
const schema = options.schema ?? "public";
|
|
672
|
+
await options.pool.query(lockSchemaDDL(mailboxDDL(schema), schema));
|
|
673
|
+
return new _PostgresMailboxStore(options.pool, schema);
|
|
674
|
+
}
|
|
675
|
+
#t(name) {
|
|
676
|
+
return `"${this.#schema}"."${name}"`;
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Runs `fn` while holding the recipient's lock, so enqueue, drain and turn
|
|
680
|
+
* handoff on one mailbox take turns across every worker, as SQLite's
|
|
681
|
+
* immediate transactions do.
|
|
682
|
+
*/
|
|
683
|
+
#forRecipient(recipient, fn) {
|
|
684
|
+
return postgresTransaction(this.#pool, async (client) => {
|
|
685
|
+
await client.query(
|
|
686
|
+
"SELECT pg_advisory_xact_lock(hashtextextended($1, 0))",
|
|
687
|
+
[
|
|
688
|
+
`zukhruf:mailbox:${JSON.stringify([this.#schema, recipient.chatId, recipient.userId])}`
|
|
689
|
+
]
|
|
690
|
+
);
|
|
691
|
+
return fn(client);
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
async beginTurn(recipient, turnId) {
|
|
695
|
+
await this.#forRecipient(
|
|
696
|
+
recipient,
|
|
697
|
+
(client) => client.query(
|
|
698
|
+
`INSERT INTO ${this.#t("zukhruf_mailbox_activity")}
|
|
699
|
+
(recipient_chat_id, recipient_user_id, turn_id)
|
|
700
|
+
VALUES ($1, $2, $3)
|
|
701
|
+
ON CONFLICT (recipient_chat_id, recipient_user_id)
|
|
702
|
+
DO UPDATE SET turn_id = EXCLUDED.turn_id`,
|
|
703
|
+
[recipient.chatId, recipient.userId, turnId]
|
|
704
|
+
)
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
enqueue(communication) {
|
|
708
|
+
const { recipient } = communication;
|
|
709
|
+
return this.#forRecipient(recipient, async (client) => {
|
|
710
|
+
const consumedTerminal = communication.type === InterAgentCommunicationTypes.FinalAnswer && await this.#exists(
|
|
711
|
+
client,
|
|
712
|
+
`SELECT EXISTS (
|
|
713
|
+
SELECT 1 FROM ${this.#t("zukhruf_mailbox_consumed_terminal_ids")}
|
|
714
|
+
WHERE communication_id = $1)`,
|
|
715
|
+
[communication.id]
|
|
716
|
+
);
|
|
717
|
+
if (!consumedTerminal) {
|
|
718
|
+
await client.query(
|
|
719
|
+
`INSERT INTO ${this.#t("zukhruf_mailbox_items")}
|
|
720
|
+
(communication_id, recipient_chat_id, recipient_user_id, communication)
|
|
721
|
+
VALUES ($1, $2, $3, $4::jsonb)
|
|
722
|
+
ON CONFLICT (communication_id) DO NOTHING`,
|
|
723
|
+
[
|
|
724
|
+
communication.id,
|
|
725
|
+
recipient.chatId,
|
|
726
|
+
recipient.userId,
|
|
727
|
+
JSON.stringify(communication)
|
|
728
|
+
]
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
return { recipientActive: await this.#isTurnActive(client, recipient) };
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
endTurn(recipient, turnId) {
|
|
735
|
+
return this.#forRecipient(recipient, async (client) => {
|
|
736
|
+
const ended = await client.query(
|
|
737
|
+
`DELETE FROM ${this.#t("zukhruf_mailbox_activity")}
|
|
738
|
+
WHERE recipient_chat_id = $1
|
|
739
|
+
AND recipient_user_id = $2
|
|
740
|
+
AND turn_id = $3`,
|
|
741
|
+
[recipient.chatId, recipient.userId, turnId]
|
|
742
|
+
);
|
|
743
|
+
return {
|
|
744
|
+
hasPending: await this.#hasPending(client, recipient),
|
|
745
|
+
turnEnded: ended.rowCount === 1
|
|
746
|
+
};
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
hasPending(recipient) {
|
|
750
|
+
return this.#hasPending(this.#pool, recipient);
|
|
751
|
+
}
|
|
752
|
+
drain(recipient) {
|
|
753
|
+
return this.#drain(recipient, false);
|
|
754
|
+
}
|
|
755
|
+
drainLeadingQueueOnly(recipient) {
|
|
756
|
+
return this.#drain(recipient, true);
|
|
757
|
+
}
|
|
758
|
+
#drain(recipient, leadingQueueOnly) {
|
|
759
|
+
return this.#forRecipient(recipient, async (client) => {
|
|
760
|
+
const items = mailboxItemRowsSchema.parse(
|
|
761
|
+
(await client.query(
|
|
762
|
+
`SELECT sequence, communication
|
|
763
|
+
FROM ${this.#t("zukhruf_mailbox_items")}
|
|
764
|
+
WHERE recipient_chat_id = $1
|
|
765
|
+
AND recipient_user_id = $2
|
|
766
|
+
ORDER BY sequence`,
|
|
767
|
+
[recipient.chatId, recipient.userId]
|
|
768
|
+
)).rows
|
|
769
|
+
);
|
|
770
|
+
const firstTrigger = leadingQueueOnly ? items.findIndex(({ communication }) => communication.triggerTurn) : -1;
|
|
771
|
+
const consumed = firstTrigger === -1 ? items : items.slice(0, firstTrigger);
|
|
772
|
+
if (consumed.length === 0) return [];
|
|
773
|
+
await client.query(
|
|
774
|
+
`INSERT INTO ${this.#t("zukhruf_mailbox_consumed_terminal_ids")} (communication_id)
|
|
775
|
+
SELECT unnest($1::text[])
|
|
776
|
+
ON CONFLICT (communication_id) DO NOTHING`,
|
|
777
|
+
[
|
|
778
|
+
consumed.flatMap(
|
|
779
|
+
({ communication }) => communication.type === InterAgentCommunicationTypes.FinalAnswer ? [communication.id] : []
|
|
780
|
+
)
|
|
781
|
+
]
|
|
782
|
+
);
|
|
783
|
+
await client.query(
|
|
784
|
+
`DELETE FROM ${this.#t("zukhruf_mailbox_items")}
|
|
785
|
+
WHERE sequence = ANY($1::bigint[])`,
|
|
786
|
+
[consumed.map(({ sequence }) => sequence)]
|
|
787
|
+
);
|
|
788
|
+
return consumed.map(({ communication }) => communication);
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
#hasPending(queryable, recipient) {
|
|
792
|
+
return this.#exists(
|
|
793
|
+
queryable,
|
|
794
|
+
`SELECT EXISTS (
|
|
795
|
+
SELECT 1 FROM ${this.#t("zukhruf_mailbox_items")}
|
|
796
|
+
WHERE recipient_chat_id = $1 AND recipient_user_id = $2)`,
|
|
797
|
+
[recipient.chatId, recipient.userId]
|
|
798
|
+
);
|
|
799
|
+
}
|
|
800
|
+
#isTurnActive(client, recipient) {
|
|
801
|
+
return this.#exists(
|
|
802
|
+
client,
|
|
803
|
+
`SELECT EXISTS (
|
|
804
|
+
SELECT 1 FROM ${this.#t("zukhruf_mailbox_activity")}
|
|
805
|
+
WHERE recipient_chat_id = $1 AND recipient_user_id = $2)`,
|
|
806
|
+
[recipient.chatId, recipient.userId]
|
|
807
|
+
);
|
|
808
|
+
}
|
|
809
|
+
async #exists(queryable, sql, params) {
|
|
810
|
+
const [{ exists }] = existsRowsSchema.parse(
|
|
811
|
+
(await queryable.query(sql, params)).rows
|
|
812
|
+
);
|
|
813
|
+
return exists;
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
// packages/experimental/src/zukhruf/mailbox/sqlite.store.ts
|
|
818
|
+
import { Declaration } from "@zukhruf/sqlite-drift";
|
|
819
|
+
import { open } from "@zukhruf/sqlite-open";
|
|
820
|
+
import { transaction } from "@zukhruf/sqlite-transaction";
|
|
821
|
+
import { z as z3 } from "zod";
|
|
822
|
+
|
|
823
|
+
// packages/experimental/src/zukhruf/mailbox/ddl.sqlite.ts
|
|
824
|
+
var SETUP = `
|
|
825
|
+
PRAGMA synchronous = NORMAL;
|
|
826
|
+
`;
|
|
827
|
+
var statements = [
|
|
828
|
+
`CREATE TABLE zukhruf_mailbox_items (
|
|
829
|
+
sequence INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
830
|
+
recipient_chat_id TEXT NOT NULL,
|
|
831
|
+
recipient_user_id TEXT NOT NULL,
|
|
832
|
+
communication TEXT NOT NULL
|
|
833
|
+
)`,
|
|
834
|
+
`CREATE TABLE zukhruf_mailbox_activity (
|
|
835
|
+
recipient_chat_id TEXT NOT NULL,
|
|
836
|
+
recipient_user_id TEXT NOT NULL,
|
|
837
|
+
turn_id TEXT NOT NULL,
|
|
838
|
+
PRIMARY KEY (recipient_chat_id, recipient_user_id)
|
|
839
|
+
)`,
|
|
840
|
+
`CREATE TABLE zukhruf_mailbox_consumed_terminal_ids (
|
|
841
|
+
communication_id TEXT PRIMARY KEY
|
|
842
|
+
)`,
|
|
843
|
+
`CREATE INDEX zukhruf_mailbox_recipient_sequence
|
|
844
|
+
ON zukhruf_mailbox_items (
|
|
845
|
+
recipient_chat_id,
|
|
846
|
+
recipient_user_id,
|
|
847
|
+
sequence
|
|
848
|
+
)`,
|
|
849
|
+
// enqueue relies on this index through INSERT OR IGNORE.
|
|
850
|
+
`CREATE UNIQUE INDEX zukhruf_mailbox_communication_id
|
|
851
|
+
ON zukhruf_mailbox_items (
|
|
852
|
+
json_extract(communication, '$.id')
|
|
853
|
+
)`
|
|
854
|
+
];
|
|
855
|
+
|
|
856
|
+
// packages/experimental/src/zukhruf/mailbox/sqlite.store.ts
|
|
857
|
+
var tables = new Declaration(statements, { rows: "keep" });
|
|
858
|
+
var mailboxItemRowsSchema2 = z3.array(
|
|
859
|
+
z3.object({
|
|
860
|
+
sequence: z3.number(),
|
|
861
|
+
communication: z3.string().transform((text) => JSON.parse(text)).pipe(communicationSchema)
|
|
643
862
|
})
|
|
644
863
|
);
|
|
645
864
|
var SqliteMailboxStore = class extends MailboxStore {
|
|
@@ -752,7 +971,7 @@ var SqliteMailboxStore = class extends MailboxStore {
|
|
|
752
971
|
return transaction(
|
|
753
972
|
this.#database,
|
|
754
973
|
() => {
|
|
755
|
-
const items =
|
|
974
|
+
const items = mailboxItemRowsSchema2.parse(
|
|
756
975
|
this.#database.prepare(
|
|
757
976
|
`SELECT sequence, communication
|
|
758
977
|
FROM zukhruf_mailbox_items
|
|
@@ -798,7 +1017,7 @@ var SqliteMailboxStore = class extends MailboxStore {
|
|
|
798
1017
|
|
|
799
1018
|
// packages/experimental/src/zukhruf/queue/pg-boss.turn-queue.ts
|
|
800
1019
|
import { v7 as uuidv7 } from "uuid";
|
|
801
|
-
import { z as
|
|
1020
|
+
import { z as z4 } from "zod";
|
|
802
1021
|
import { isRecord } from "@deepagents/context";
|
|
803
1022
|
|
|
804
1023
|
// packages/experimental/src/zukhruf/queue/turn-queue.ts
|
|
@@ -807,7 +1026,7 @@ var TurnQueue = class {
|
|
|
807
1026
|
|
|
808
1027
|
// packages/experimental/src/zukhruf/queue/pg-boss.turn-queue.ts
|
|
809
1028
|
var MAX_TIMEOUT_MS = 2147483647;
|
|
810
|
-
var queueCatalogRowSchema =
|
|
1029
|
+
var queueCatalogRowSchema = z4.object({ table: z4.string() });
|
|
811
1030
|
function deadLetterQueueOf(queue) {
|
|
812
1031
|
return `${queue}-dead`;
|
|
813
1032
|
}
|
|
@@ -1201,14 +1420,14 @@ var AgentDirectory = class _AgentDirectory {
|
|
|
1201
1420
|
async assertOwnerIfExists(conversation) {
|
|
1202
1421
|
const chat2 = await this.#store.getChat(conversation.chatId);
|
|
1203
1422
|
if (!chat2) return;
|
|
1204
|
-
|
|
1423
|
+
assertConversationOwner(conversation, chat2.userId);
|
|
1205
1424
|
const thread = this.#threadFromMetadata(conversation, chat2.metadata);
|
|
1206
1425
|
if (thread) await this.#assertValidParent(thread);
|
|
1207
1426
|
}
|
|
1208
1427
|
async load(conversation) {
|
|
1209
1428
|
const chat2 = await this.#store.getChat(conversation.chatId);
|
|
1210
|
-
if (chat2) this.#assertOwner(conversation, chat2.userId);
|
|
1211
1429
|
if (!chat2) return void 0;
|
|
1430
|
+
assertConversationOwner(conversation, chat2.userId);
|
|
1212
1431
|
const thread = this.#threadFromMetadata(conversation, chat2.metadata);
|
|
1213
1432
|
if (thread) await this.#assertValidParent(thread);
|
|
1214
1433
|
return thread;
|
|
@@ -1221,7 +1440,7 @@ var AgentDirectory = class _AgentDirectory {
|
|
|
1221
1440
|
let thread;
|
|
1222
1441
|
let adopted = false;
|
|
1223
1442
|
await this.#store.updateChat(conversation.chatId, (chat2) => {
|
|
1224
|
-
|
|
1443
|
+
assertConversationOwner(conversation, chat2.userId);
|
|
1225
1444
|
const existing = this.#threadFromMetadata(conversation, chat2.metadata);
|
|
1226
1445
|
if (existing) {
|
|
1227
1446
|
thread = existing;
|
|
@@ -1318,12 +1537,6 @@ var AgentDirectory = class _AgentDirectory {
|
|
|
1318
1537
|
uuidv5.URL
|
|
1319
1538
|
);
|
|
1320
1539
|
}
|
|
1321
|
-
#assertOwner(conversation, storedUserId) {
|
|
1322
|
-
if (storedUserId === conversation.userId) return;
|
|
1323
|
-
throw new Error(
|
|
1324
|
-
`chat "${conversation.chatId}" belongs to user "${storedUserId}", not "${conversation.userId}"`
|
|
1325
|
-
);
|
|
1326
|
-
}
|
|
1327
1540
|
#threadFromMetadata(conversation, metadata) {
|
|
1328
1541
|
const thread = AgentThread.fromMetadata(conversation, metadata);
|
|
1329
1542
|
if (!thread && AgentThread.hasReservedMetadata(metadata)) {
|
|
@@ -1361,7 +1574,7 @@ var AgentDirectory = class _AgentDirectory {
|
|
|
1361
1574
|
async #updateLatestTurn(conversation, streamId, ...expected) {
|
|
1362
1575
|
let result;
|
|
1363
1576
|
await this.#store.updateChat(conversation.chatId, (chat2) => {
|
|
1364
|
-
|
|
1577
|
+
assertConversationOwner(conversation, chat2.userId);
|
|
1365
1578
|
const thread = this.#threadFromMetadata(conversation, chat2.metadata);
|
|
1366
1579
|
if (!thread) {
|
|
1367
1580
|
throw new Error(
|
|
@@ -1694,17 +1907,17 @@ function arraysEqual(left, right) {
|
|
|
1694
1907
|
|
|
1695
1908
|
// packages/experimental/src/zukhruf/control-plane/agent-status-projector.ts
|
|
1696
1909
|
import { isTextUIPart } from "ai";
|
|
1697
|
-
import { z as
|
|
1910
|
+
import { z as z5 } from "zod";
|
|
1698
1911
|
import {
|
|
1699
1912
|
ContextEngine
|
|
1700
1913
|
} from "@deepagents/context";
|
|
1701
|
-
var listedAgentStatusSchema =
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1914
|
+
var listedAgentStatusSchema = z5.union([
|
|
1915
|
+
z5.enum(["pending_init", "running", "interrupted", "shutdown", "not_found"]),
|
|
1916
|
+
z5.object({ completed: z5.string().nullable() }).strict(),
|
|
1917
|
+
z5.object({ errored: z5.string() }).strict()
|
|
1705
1918
|
]);
|
|
1706
|
-
var listedAgentSchema =
|
|
1707
|
-
agent_name:
|
|
1919
|
+
var listedAgentSchema = z5.object({
|
|
1920
|
+
agent_name: z5.string(),
|
|
1708
1921
|
agent_status: listedAgentStatusSchema
|
|
1709
1922
|
}).strict();
|
|
1710
1923
|
var AgentStatusProjector = class _AgentStatusProjector {
|
|
@@ -2376,7 +2589,7 @@ import {
|
|
|
2376
2589
|
modelMessageSchema as modelMessageSchema2
|
|
2377
2590
|
} from "ai";
|
|
2378
2591
|
import { hash, randomUUID as randomUUID2 } from "node:crypto";
|
|
2379
|
-
import { z as
|
|
2592
|
+
import { z as z6 } from "zod";
|
|
2380
2593
|
|
|
2381
2594
|
// packages/compaction/dist/index.js
|
|
2382
2595
|
import {
|
|
@@ -2580,21 +2793,21 @@ ${options.instructions}` : SUMMARY_PROMPT,
|
|
|
2580
2793
|
}
|
|
2581
2794
|
|
|
2582
2795
|
// packages/experimental/src/zukhruf/runtime/compaction.ts
|
|
2583
|
-
var checkpointSchema =
|
|
2584
|
-
sourceCount:
|
|
2585
|
-
sourceHash:
|
|
2586
|
-
replacement:
|
|
2796
|
+
var checkpointSchema = z6.object({
|
|
2797
|
+
sourceCount: z6.number().int().positive(),
|
|
2798
|
+
sourceHash: z6.string(),
|
|
2799
|
+
replacement: z6.array(z6.unknown()).transform(
|
|
2587
2800
|
(messages) => messages.map((message) => modelMessageSchema2.parse(message))
|
|
2588
2801
|
)
|
|
2589
2802
|
});
|
|
2590
|
-
var cacheObservationSchema =
|
|
2591
|
-
scope:
|
|
2592
|
-
prefixLength:
|
|
2593
|
-
prefixHash:
|
|
2594
|
-
startedAt:
|
|
2595
|
-
retentionMs:
|
|
2803
|
+
var cacheObservationSchema = z6.object({
|
|
2804
|
+
scope: z6.string(),
|
|
2805
|
+
prefixLength: z6.number().int().nonnegative(),
|
|
2806
|
+
prefixHash: z6.string(),
|
|
2807
|
+
startedAt: z6.number().int().nonnegative(),
|
|
2808
|
+
retentionMs: z6.number().int().positive().optional()
|
|
2596
2809
|
});
|
|
2597
|
-
var inputUsageSchema = cacheObservationSchema.pick({ scope: true, prefixLength: true, prefixHash: true }).extend({ inputTokens:
|
|
2810
|
+
var inputUsageSchema = cacheObservationSchema.pick({ scope: true, prefixLength: true, prefixHash: true }).extend({ inputTokens: z6.number().int().nonnegative() });
|
|
2598
2811
|
function jsonDigest(value) {
|
|
2599
2812
|
return hash("sha256", JSON.stringify(value));
|
|
2600
2813
|
}
|
|
@@ -3673,21 +3886,21 @@ import {
|
|
|
3673
3886
|
} from "@deepagents/context";
|
|
3674
3887
|
|
|
3675
3888
|
// packages/experimental/src/zukhruf/runtime/conversation-status/child-progress.ts
|
|
3676
|
-
import { z as
|
|
3677
|
-
var childActivitySchema =
|
|
3678
|
-
id:
|
|
3679
|
-
type:
|
|
3680
|
-
at:
|
|
3681
|
-
actorPath:
|
|
3682
|
-
targetPath:
|
|
3683
|
-
streamId:
|
|
3684
|
-
outcome:
|
|
3889
|
+
import { z as z7 } from "zod";
|
|
3890
|
+
var childActivitySchema = z7.object({
|
|
3891
|
+
id: z7.string(),
|
|
3892
|
+
type: z7.enum(["spawn", "message", "followup", "interrupt", "completion"]),
|
|
3893
|
+
at: z7.number(),
|
|
3894
|
+
actorPath: z7.string(),
|
|
3895
|
+
targetPath: z7.string(),
|
|
3896
|
+
streamId: z7.string(),
|
|
3897
|
+
outcome: z7.enum(["completed", "failed", "cancelled"]).optional()
|
|
3685
3898
|
});
|
|
3686
|
-
var childActivitiesSchema =
|
|
3899
|
+
var childActivitiesSchema = z7.partialRecord(
|
|
3687
3900
|
childActivitySchema.shape.type,
|
|
3688
3901
|
childActivitySchema
|
|
3689
3902
|
);
|
|
3690
|
-
var childActivityMetadataSchema =
|
|
3903
|
+
var childActivityMetadataSchema = z7.looseObject({
|
|
3691
3904
|
childActivities: childActivitiesSchema.default({})
|
|
3692
3905
|
});
|
|
3693
3906
|
|
|
@@ -3981,13 +4194,13 @@ var StatusPublishingTurnQueue = class extends TurnQueue {
|
|
|
3981
4194
|
|
|
3982
4195
|
// packages/experimental/src/zukhruf/collaboration/interrupt-agent.ts
|
|
3983
4196
|
import { tool as tool2 } from "ai";
|
|
3984
|
-
import { z as
|
|
3985
|
-
var interruptAgentInputSchema =
|
|
3986
|
-
target:
|
|
4197
|
+
import { z as z8 } from "zod";
|
|
4198
|
+
var interruptAgentInputSchema = z8.object({
|
|
4199
|
+
target: z8.string().trim().min(1).describe(
|
|
3987
4200
|
"The canonical /root/... path, or a descendant-relative target name."
|
|
3988
4201
|
)
|
|
3989
4202
|
});
|
|
3990
|
-
var interruptAgentOutputSchema =
|
|
4203
|
+
var interruptAgentOutputSchema = z8.object({ previous_status: listedAgentStatusSchema }).strict();
|
|
3991
4204
|
var interruptAgentTool = tool2({
|
|
3992
4205
|
description: "Interrupt an agent's current turn, if any, and return its previous status. The agent remains available for messages and follow-up tasks.",
|
|
3993
4206
|
inputSchema: interruptAgentInputSchema,
|
|
@@ -3997,13 +4210,13 @@ var interruptAgentTool = tool2({
|
|
|
3997
4210
|
|
|
3998
4211
|
// packages/experimental/src/zukhruf/collaboration/list-agents.ts
|
|
3999
4212
|
import { tool as tool3 } from "ai";
|
|
4000
|
-
import { z as
|
|
4001
|
-
var listAgentsInputSchema =
|
|
4002
|
-
path_prefix:
|
|
4213
|
+
import { z as z9 } from "zod";
|
|
4214
|
+
var listAgentsInputSchema = z9.object({
|
|
4215
|
+
path_prefix: z9.string().trim().min(1).describe(
|
|
4003
4216
|
"Task-path prefix without a trailing slash. Omit to list the whole tree."
|
|
4004
4217
|
).optional()
|
|
4005
4218
|
});
|
|
4006
|
-
var listAgentsOutputSchema =
|
|
4219
|
+
var listAgentsOutputSchema = z9.object({ agents: z9.array(listedAgentSchema) }).strict();
|
|
4007
4220
|
var listAgentsTool = tool3({
|
|
4008
4221
|
description: "List live agents in the current root thread tree. Optionally filter by task-path prefix.",
|
|
4009
4222
|
inputSchema: listAgentsInputSchema,
|
|
@@ -4013,12 +4226,12 @@ var listAgentsTool = tool3({
|
|
|
4013
4226
|
|
|
4014
4227
|
// packages/experimental/src/zukhruf/collaboration/message-tools.ts
|
|
4015
4228
|
import { tool as tool4 } from "ai";
|
|
4016
|
-
import { z as
|
|
4017
|
-
var agentMessageInputSchema =
|
|
4018
|
-
target:
|
|
4229
|
+
import { z as z10 } from "zod";
|
|
4230
|
+
var agentMessageInputSchema = z10.object({
|
|
4231
|
+
target: z10.string().trim().min(1).describe(
|
|
4019
4232
|
"The canonical /root/... path, or a descendant-relative target name."
|
|
4020
4233
|
),
|
|
4021
|
-
message:
|
|
4234
|
+
message: z10.string().trim().min(1).describe("The message or follow-up task.")
|
|
4022
4235
|
});
|
|
4023
4236
|
var sendMessageTool = tool4({
|
|
4024
4237
|
description: "Queue a message for another agent. Address siblings with their canonical /root/... path.",
|
|
@@ -4039,7 +4252,7 @@ var followupTaskTool = tool4({
|
|
|
4039
4252
|
|
|
4040
4253
|
// packages/experimental/src/zukhruf/collaboration/spawn-agent.ts
|
|
4041
4254
|
import { tool as tool5 } from "ai";
|
|
4042
|
-
import { z as
|
|
4255
|
+
import { z as z11 } from "zod";
|
|
4043
4256
|
|
|
4044
4257
|
// packages/experimental/src/zukhruf/control-plane/fork-turns.ts
|
|
4045
4258
|
var forkTurnsError = "fork_turns must be `none`, `all`, or a positive integer string";
|
|
@@ -4052,18 +4265,18 @@ function parseForkTurns(value) {
|
|
|
4052
4265
|
}
|
|
4053
4266
|
|
|
4054
4267
|
// packages/experimental/src/zukhruf/collaboration/spawn-agent.ts
|
|
4055
|
-
var spawnAgentInputSchema =
|
|
4056
|
-
agent_type:
|
|
4057
|
-
task_name:
|
|
4268
|
+
var spawnAgentInputSchema = z11.object({
|
|
4269
|
+
agent_type: z11.string().trim().min(1).describe("The name of one available subagent declaration."),
|
|
4270
|
+
task_name: z11.string().trim().min(1).refine(
|
|
4058
4271
|
(value) => value !== "." && value !== ".." && !value.includes("/"),
|
|
4059
4272
|
"task_name must be one non-empty path segment"
|
|
4060
4273
|
).describe("One path segment naming this independent agent task."),
|
|
4061
|
-
message:
|
|
4062
|
-
fork_turns:
|
|
4274
|
+
message: z11.string().refine((value) => value.trim().length > 0, "message cannot be empty").describe("The initial task for the spawned agent."),
|
|
4275
|
+
fork_turns: z11.string().trim().refine((value) => parseForkTurns(value) !== void 0, forkTurnsError).describe(
|
|
4063
4276
|
"Required number of parent turns to fork. Use `none`, `all`, or a positive integer string such as `3`."
|
|
4064
4277
|
)
|
|
4065
4278
|
});
|
|
4066
|
-
var spawnAgentOutputSchema =
|
|
4279
|
+
var spawnAgentOutputSchema = z11.object({ task_name: z11.string() }).strict();
|
|
4067
4280
|
function createSpawnAgentTool(options) {
|
|
4068
4281
|
return tool5({
|
|
4069
4282
|
description: ({ context }) => {
|
|
@@ -4092,11 +4305,11 @@ function createSpawnAgentTool(options) {
|
|
|
4092
4305
|
|
|
4093
4306
|
// packages/experimental/src/zukhruf/collaboration/wait-agent.ts
|
|
4094
4307
|
import { tool as tool6 } from "ai";
|
|
4095
|
-
import { z as
|
|
4096
|
-
var waitAgentOutputSchema =
|
|
4308
|
+
import { z as z12 } from "zod";
|
|
4309
|
+
var waitAgentOutputSchema = z12.object({ message: z12.string(), timed_out: z12.boolean() }).strict();
|
|
4097
4310
|
function createWaitAgentTool(options) {
|
|
4098
|
-
const waitAgentInputSchema =
|
|
4099
|
-
timeout_ms:
|
|
4311
|
+
const waitAgentInputSchema = z12.object({
|
|
4312
|
+
timeout_ms: z12.number().int().max(options.maxTimeoutMs).optional().describe("Maximum time to wait in milliseconds.")
|
|
4100
4313
|
});
|
|
4101
4314
|
return tool6({
|
|
4102
4315
|
description: "Wait for pending mail addressed to this agent without consuming it.",
|
|
@@ -4821,10 +5034,13 @@ var RuntimeHost = class {
|
|
|
4821
5034
|
subscribeConversationStatus: (signal) => this.subscribeConversationStatus(signal),
|
|
4822
5035
|
// Borrows the root declaration's sandbox directly: resolving the
|
|
4823
5036
|
// conversation through the control plane would create its root thread.
|
|
4824
|
-
sandbox: (conversation) =>
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
5037
|
+
sandbox: async (conversation) => {
|
|
5038
|
+
await this.#directory.assertOwnerIfExists(conversation);
|
|
5039
|
+
return sandboxes.acquire(this.#root, {
|
|
5040
|
+
chatId: conversation.chatId,
|
|
5041
|
+
userId: conversation.userId
|
|
5042
|
+
});
|
|
5043
|
+
}
|
|
4828
5044
|
};
|
|
4829
5045
|
resources.use(this.#workers);
|
|
4830
5046
|
}
|
|
@@ -4881,21 +5097,13 @@ var RuntimeHost = class {
|
|
|
4881
5097
|
}
|
|
4882
5098
|
async #readConversationMetadata(conversation) {
|
|
4883
5099
|
const chat2 = await this.#store.getChat(conversation.chatId);
|
|
4884
|
-
if (!chat2) throw new
|
|
4885
|
-
|
|
4886
|
-
throw new Error(
|
|
4887
|
-
`chat "${conversation.chatId}" belongs to user "${chat2.userId}", not "${conversation.userId}"`
|
|
4888
|
-
);
|
|
4889
|
-
}
|
|
5100
|
+
if (!chat2) throw new ConversationNotFoundError(conversation.chatId);
|
|
5101
|
+
assertConversationOwner(conversation, chat2.userId);
|
|
4890
5102
|
return chat2.metadata;
|
|
4891
5103
|
}
|
|
4892
5104
|
async #updateConversationMetadata(conversation, update) {
|
|
4893
5105
|
await this.#store.updateChat(conversation.chatId, (chat2) => {
|
|
4894
|
-
|
|
4895
|
-
throw new Error(
|
|
4896
|
-
`chat "${conversation.chatId}" belongs to user "${chat2.userId}", not "${conversation.userId}"`
|
|
4897
|
-
);
|
|
4898
|
-
}
|
|
5106
|
+
assertConversationOwner(conversation, chat2.userId);
|
|
4899
5107
|
return { metadata: update(chat2.metadata) };
|
|
4900
5108
|
});
|
|
4901
5109
|
}
|