@deepagents/experimental 7.1.2 → 7.1.4
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 +69 -66
- package/dist/index.js.map +2 -2
- package/dist/zukhruf/index.js +69 -66
- package/dist/zukhruf/index.js.map +2 -2
- package/dist/zukhruf/mailbox/sqlite.store.d.ts.map +1 -1
- package/dist/zukhruf/plugins/schedules/index.js +2 -1
- package/dist/zukhruf/plugins/schedules/index.js.map +2 -2
- package/dist/zukhruf/plugins/schedules/scheduled-tasks.d.ts.map +1 -1
- package/package.json +13 -12
package/dist/index.js
CHANGED
|
@@ -532,6 +532,7 @@ function defineInstructions(...fragments) {
|
|
|
532
532
|
}
|
|
533
533
|
|
|
534
534
|
// packages/experimental/src/zukhruf/mailbox/sqlite.store.ts
|
|
535
|
+
import { transaction } from "@zukhruf/sqlite-transaction";
|
|
535
536
|
import { DatabaseSync } from "node:sqlite";
|
|
536
537
|
import { z } from "zod";
|
|
537
538
|
|
|
@@ -649,52 +650,64 @@ var SqliteMailboxStore = class extends MailboxStore {
|
|
|
649
650
|
this.#database.exec(DDL);
|
|
650
651
|
}
|
|
651
652
|
async beginTurn(recipient, turnId) {
|
|
652
|
-
|
|
653
|
-
this.#database
|
|
654
|
-
|
|
653
|
+
transaction(
|
|
654
|
+
this.#database,
|
|
655
|
+
() => {
|
|
656
|
+
this.#database.prepare(
|
|
657
|
+
`INSERT INTO zukhruf_mailbox_activity (
|
|
655
658
|
recipient_chat_id,
|
|
656
659
|
recipient_user_id,
|
|
657
660
|
turn_id
|
|
658
661
|
) VALUES (?, ?, ?)
|
|
659
662
|
ON CONFLICT (recipient_chat_id, recipient_user_id)
|
|
660
663
|
DO UPDATE SET turn_id = excluded.turn_id`
|
|
661
|
-
|
|
662
|
-
|
|
664
|
+
).run(recipient.chatId, recipient.userId, turnId);
|
|
665
|
+
},
|
|
666
|
+
{ mode: "immediate" }
|
|
667
|
+
);
|
|
663
668
|
}
|
|
664
669
|
async enqueue(communication) {
|
|
665
|
-
return
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
this.#
|
|
669
|
-
|
|
670
|
+
return transaction(
|
|
671
|
+
this.#database,
|
|
672
|
+
() => {
|
|
673
|
+
const consumedTerminal = communication.type === InterAgentCommunicationTypes.FinalAnswer && this.#hasConsumedTerminal(communication.id);
|
|
674
|
+
if (!consumedTerminal) {
|
|
675
|
+
this.#database.prepare(
|
|
676
|
+
`INSERT OR IGNORE INTO zukhruf_mailbox_items (
|
|
670
677
|
recipient_chat_id,
|
|
671
678
|
recipient_user_id,
|
|
672
679
|
communication
|
|
673
680
|
) VALUES (?, ?, ?)`
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
681
|
+
).run(
|
|
682
|
+
communication.recipient.chatId,
|
|
683
|
+
communication.recipient.userId,
|
|
684
|
+
JSON.stringify(communication)
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
return {
|
|
688
|
+
recipientActive: this.#isTurnActive(communication.recipient)
|
|
689
|
+
};
|
|
690
|
+
},
|
|
691
|
+
{ mode: "immediate" }
|
|
692
|
+
);
|
|
684
693
|
}
|
|
685
694
|
async endTurn(recipient, turnId) {
|
|
686
|
-
return
|
|
687
|
-
|
|
688
|
-
|
|
695
|
+
return transaction(
|
|
696
|
+
this.#database,
|
|
697
|
+
() => {
|
|
698
|
+
const result = this.#database.prepare(
|
|
699
|
+
`DELETE FROM zukhruf_mailbox_activity
|
|
689
700
|
WHERE recipient_chat_id = ?
|
|
690
701
|
AND recipient_user_id = ?
|
|
691
702
|
AND turn_id = ?`
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
703
|
+
).run(recipient.chatId, recipient.userId, turnId);
|
|
704
|
+
return {
|
|
705
|
+
hasPending: this.#hasPending(recipient),
|
|
706
|
+
turnEnded: result.changes > 0
|
|
707
|
+
};
|
|
708
|
+
},
|
|
709
|
+
{ mode: "immediate" }
|
|
710
|
+
);
|
|
698
711
|
}
|
|
699
712
|
async hasPending(recipient) {
|
|
700
713
|
return this.#hasPending(recipient);
|
|
@@ -735,53 +748,43 @@ var SqliteMailboxStore = class extends MailboxStore {
|
|
|
735
748
|
return this.#drain(recipient, true);
|
|
736
749
|
}
|
|
737
750
|
#drain(recipient, leadingQueueOnly) {
|
|
738
|
-
return
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
751
|
+
return transaction(
|
|
752
|
+
this.#database,
|
|
753
|
+
() => {
|
|
754
|
+
const items = mailboxItemRowsSchema.parse(
|
|
755
|
+
this.#database.prepare(
|
|
756
|
+
`SELECT sequence, communication
|
|
742
757
|
FROM zukhruf_mailbox_items
|
|
743
758
|
WHERE recipient_chat_id = ?
|
|
744
759
|
AND recipient_user_id = ?
|
|
745
760
|
ORDER BY sequence`
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
761
|
+
).all(recipient.chatId, recipient.userId)
|
|
762
|
+
);
|
|
763
|
+
const firstTrigger = leadingQueueOnly ? items.findIndex(({ communication }) => communication.triggerTurn) : -1;
|
|
764
|
+
const consumed = firstTrigger === -1 ? items : items.slice(0, firstTrigger);
|
|
765
|
+
const lastConsumed = consumed.at(-1);
|
|
766
|
+
if (lastConsumed) {
|
|
767
|
+
const tombstone = this.#database.prepare(
|
|
768
|
+
`INSERT OR IGNORE
|
|
754
769
|
INTO zukhruf_mailbox_consumed_terminal_ids (communication_id)
|
|
755
770
|
VALUES (?)`
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
771
|
+
);
|
|
772
|
+
for (const { communication } of consumed) {
|
|
773
|
+
if (communication.type === InterAgentCommunicationTypes.FinalAnswer) {
|
|
774
|
+
tombstone.run(communication.id);
|
|
775
|
+
}
|
|
760
776
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
`DELETE FROM zukhruf_mailbox_items
|
|
777
|
+
this.#database.prepare(
|
|
778
|
+
`DELETE FROM zukhruf_mailbox_items
|
|
764
779
|
WHERE recipient_chat_id = ?
|
|
765
780
|
AND recipient_user_id = ?
|
|
766
781
|
AND sequence <= ?`
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
this.#database.exec("BEGIN IMMEDIATE");
|
|
774
|
-
try {
|
|
775
|
-
const result = operation();
|
|
776
|
-
this.#database.exec("COMMIT");
|
|
777
|
-
return result;
|
|
778
|
-
} catch (error) {
|
|
779
|
-
try {
|
|
780
|
-
this.#database.exec("ROLLBACK");
|
|
781
|
-
} catch {
|
|
782
|
-
}
|
|
783
|
-
throw error;
|
|
784
|
-
}
|
|
782
|
+
).run(recipient.chatId, recipient.userId, lastConsumed.sequence);
|
|
783
|
+
}
|
|
784
|
+
return consumed.map(({ communication }) => communication);
|
|
785
|
+
},
|
|
786
|
+
{ mode: "immediate" }
|
|
787
|
+
);
|
|
785
788
|
}
|
|
786
789
|
close() {
|
|
787
790
|
if (!this.#database.isOpen) return;
|