@deepagents/experimental 7.8.1 → 7.9.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/README.md +27 -10
- package/dist/index.js +601 -54
- package/dist/index.js.map +4 -4
- package/dist/zukhruf/index.d.ts +4 -0
- package/dist/zukhruf/index.d.ts.map +1 -1
- package/dist/zukhruf/index.js +601 -54
- package/dist/zukhruf/index.js.map +4 -4
- package/dist/zukhruf/mailbox/postgres.store.d.ts +9 -1
- package/dist/zukhruf/mailbox/postgres.store.d.ts.map +1 -1
- package/dist/zukhruf/mailbox/sqlite.store.d.ts +3 -1
- package/dist/zukhruf/mailbox/sqlite.store.d.ts.map +1 -1
- package/dist/zukhruf/mailbox/store.d.ts +4 -0
- package/dist/zukhruf/mailbox/store.d.ts.map +1 -1
- package/dist/zukhruf/plugins/conversation-scheduling/index.js.map +1 -1
- package/dist/zukhruf/plugins/schedules/index.js.map +1 -1
- package/dist/zukhruf/queue/pg-boss.turn-queue.d.ts +14 -1
- package/dist/zukhruf/queue/pg-boss.turn-queue.d.ts.map +1 -1
- package/dist/zukhruf/queue/turn-queue.d.ts +2 -0
- package/dist/zukhruf/queue/turn-queue.d.ts.map +1 -1
- package/dist/zukhruf/runtime/agent-runtime.d.ts +6 -7
- package/dist/zukhruf/runtime/agent-runtime.d.ts.map +1 -1
- package/dist/zukhruf/storage/agent-storage.d.ts +41 -0
- package/dist/zukhruf/storage/agent-storage.d.ts.map +1 -0
- package/dist/zukhruf/storage/embedded-agent-storage.d.ts +63 -0
- package/dist/zukhruf/storage/embedded-agent-storage.d.ts.map +1 -0
- package/dist/zukhruf/storage/postgres-agent-storage.d.ts +56 -0
- package/dist/zukhruf/storage/postgres-agent-storage.d.ts.map +1 -0
- package/dist/zukhruf/storage/sqlite-admission-gate.d.ts +29 -0
- package/dist/zukhruf/storage/sqlite-admission-gate.d.ts.map +1 -0
- package/dist/zukhruf/storage/turn-outbox.d.ts +65 -0
- package/dist/zukhruf/storage/turn-outbox.d.ts.map +1 -0
- package/package.json +6 -6
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PgBoss } from 'pg-boss';
|
|
2
|
-
import { type
|
|
2
|
+
import { type PostgresTransaction } from '@deepagents/context';
|
|
3
|
+
import { type ConsumeContext, type ConsumeOptions, type TransactionalTurnQueue, type TurnActivity, TurnQueue, type TurnRef } from './turn-queue.ts';
|
|
3
4
|
export interface PgBossTurnQueueOptions {
|
|
4
5
|
queue?: string;
|
|
5
6
|
/** Required for custom DB adapters; must match the PgBoss schema. */
|
|
@@ -50,8 +51,20 @@ export declare class PgBossTurnQueue extends TurnQueue {
|
|
|
50
51
|
static create(boss: PgBoss, options?: PgBossTurnQueueOptions): Promise<PgBossTurnQueue>;
|
|
51
52
|
get queue(): string;
|
|
52
53
|
get deadLetterQueue(): string;
|
|
54
|
+
/**
|
|
55
|
+
* A view whose `push` and `getTurnActivity` run inside `tx`: a pushed turn
|
|
56
|
+
* reaches workers only if `tx` commits, and activity counts what `tx` has
|
|
57
|
+
* pushed so far. `tx` must be on the database PgBoss uses.
|
|
58
|
+
*/
|
|
59
|
+
bind(tx: PostgresTransaction): TransactionalTurnQueue;
|
|
53
60
|
push(turn: TurnRef): Promise<void>;
|
|
54
61
|
getTurnActivity(conversation: Pick<TurnRef, 'chatId' | 'userId'>): Promise<TurnActivity>;
|
|
62
|
+
/**
|
|
63
|
+
* Pushes `turn` as the job `id`, a UUID. While pg-boss holds a job with that
|
|
64
|
+
* id, a second push of it adds nothing. Ids that grow with push order (UUIDv7)
|
|
65
|
+
* keep FIFO across timestamp ties.
|
|
66
|
+
*/
|
|
67
|
+
pushAs(id: string, turn: TurnRef): Promise<void>;
|
|
55
68
|
getCurrentTurn(conversation: Pick<TurnRef, 'chatId' | 'userId'>): Promise<TurnRef | undefined>;
|
|
56
69
|
cancel(streamId: string): Promise<void>;
|
|
57
70
|
consume(handler: (turn: TurnRef, context: ConsumeContext) => Promise<void>, options: ConsumeOptions): Promise<AsyncDisposable>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pg-boss.turn-queue.d.ts","sourceRoot":"","sources":["../../../src/zukhruf/queue/pg-boss.turn-queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"pg-boss.turn-queue.d.ts","sourceRoot":"","sources":["../../../src/zukhruf/queue/pg-boss.turn-queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAuB,MAAM,EAAE,MAAM,SAAS,CAAC;AAI3D,OAAO,EAAE,KAAK,mBAAmB,EAAY,MAAM,qBAAqB,CAAC;AAEzE,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,SAAS,EACT,KAAK,OAAO,EACb,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,wEAAwE;IACxE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AAwBD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,eAAgB,SAAQ,SAAS;;IAc5C,OAAO;IAcP;;;OAGG;WACU,MAAM,CACjB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC,eAAe,CAAC;IAiG3B,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED;;;;OAIG;IACH,IAAI,CAAC,EAAE,EAAE,mBAAmB,GAAG,sBAAsB;IAWrD,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzB,eAAe,CACtB,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,QAAQ,CAAC,GAC/C,OAAO,CAAC,YAAY,CAAC;IAIxB;;;;OAIG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IA6CvC,cAAc,CAC3B,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,QAAQ,CAAC,GAC/C,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IAehB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA4BhD,OAAO,CACX,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,EAClE,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC;IAsGrB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAkHlD"}
|
|
@@ -115,4 +115,6 @@ export declare abstract class TurnQueue {
|
|
|
115
115
|
abstract consume(handler: (turn: TurnRef, context: ConsumeContext) => Promise<void>, options: ConsumeOptions): Promise<AsyncDisposable>;
|
|
116
116
|
abstract resumeParked(chatId: string): Promise<void>;
|
|
117
117
|
}
|
|
118
|
+
/** The part of the queue that writes and reads inside a caller's transaction. */
|
|
119
|
+
export type TransactionalTurnQueue = Pick<TurnQueue, 'push' | 'getTurnActivity'>;
|
|
118
120
|
//# sourceMappingURL=turn-queue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turn-queue.d.ts","sourceRoot":"","sources":["../../../src/zukhruf/queue/turn-queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,KAAK,EAAE,aAAa,EAAE,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,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,8BAAsB,SAAS;IAC7B,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAE3C,+EAA+E;IAC/E,QAAQ,CAAC,eAAe,CACtB,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,QAAQ,CAAC,GAC/C,OAAO,CAAC,YAAY,CAAC;IAExB,2EAA2E;IAC3E,QAAQ,CAAC,cAAc,CACrB,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,QAAQ,CAAC,GAC/C,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IAE/B,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAEhD,QAAQ,CAAC,OAAO,CACd,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,EAClE,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC;IAE3B,QAAQ,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CACrD;AAED,iFAAiF;AACjF,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACvC,SAAS,EACT,MAAM,GAAG,iBAAiB,CAC3B,CAAC"}
|
|
@@ -2,10 +2,10 @@ import type { Telemetry } from 'ai';
|
|
|
2
2
|
import { ContextEngine, type ContextStore, type StreamManager, type StreamPart, type StreamStatus } from '@deepagents/context';
|
|
3
3
|
import type { AgentDeclaration, ZukhrufSandbox } from '../agent.ts';
|
|
4
4
|
import { AgentDirectory } from '../control-plane/agent-directory.ts';
|
|
5
|
-
import type { MailboxStore } from '../mailbox/store.ts';
|
|
6
5
|
import type { ConversationId, InterAgentCommunication, MessageDeliveryMode } from '../mailbox/types.ts';
|
|
7
6
|
import { type MultiAgentHostConfig } from '../multi-agent-config.ts';
|
|
8
7
|
import type { TurnQueue, TurnRequest } from '../queue/turn-queue.ts';
|
|
8
|
+
import type { AgentStorage } from '../storage/agent-storage.ts';
|
|
9
9
|
import type { ZukhrufToolSet } from '../tool.ts';
|
|
10
10
|
import type { ConversationStatusChangeSource } from './conversation-status/change-source.ts';
|
|
11
11
|
import type { ChildProgress } from './conversation-status/child-progress.ts';
|
|
@@ -138,12 +138,11 @@ export declare class AgentObservation {
|
|
|
138
138
|
}
|
|
139
139
|
/** A reusable recipe. Register only resources the returned host should own. */
|
|
140
140
|
export type AgentStack = (resources: AsyncDisposableStack) => Promise<{
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
mailboxStore: MailboxStore;
|
|
141
|
+
/**
|
|
142
|
+
* Conversations, streams, turns and mail on one database. The host
|
|
143
|
+
* borrows it: register a storage the host should close on `resources`.
|
|
144
|
+
*/
|
|
145
|
+
storage: AgentStorage;
|
|
147
146
|
/** Codex-compatible multi-agent host guidance and tool configuration. */
|
|
148
147
|
multiAgent?: MultiAgentHostConfig;
|
|
149
148
|
/** Host implementations for capabilities required by root-owned plugins. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-runtime.d.ts","sourceRoot":"","sources":["../../../src/zukhruf/runtime/agent-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAEpC,OAAO,EACL,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,YAAY,EAClB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAUrE,OAAO,KA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B,OAAO,CAAC,aAAa,CAAC,uBAAuB,CAAC,CAAC;IAkC5C,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,gBAAgB,EAAE,CAAC;IA+BxE,IAAI,CAAC,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,eAAe,CAAC;CAyHlE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ContextStore, StreamManager, StreamStore } from '@deepagents/context';
|
|
2
|
+
import type { MailboxStore, TransactionalMailboxStore } from '../mailbox/store.ts';
|
|
3
|
+
import type { TransactionalTurnQueue, TurnQueue } from '../queue/turn-queue.ts';
|
|
4
|
+
/** An agent tree: the root conversation and every sub-agent under it. */
|
|
5
|
+
export interface AgentTree {
|
|
6
|
+
userId: string;
|
|
7
|
+
/** The root conversation's chat id. */
|
|
8
|
+
treeId: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The storage parts as one admission sees them: every read and write lands
|
|
12
|
+
* in one unit, which commits when `work` resolves and leaves nothing when it
|
|
13
|
+
* throws or its process dies.
|
|
14
|
+
*/
|
|
15
|
+
export interface AdmissionScope {
|
|
16
|
+
store: ContextStore;
|
|
17
|
+
streams: StreamStore;
|
|
18
|
+
mailboxStore: TransactionalMailboxStore;
|
|
19
|
+
queue: TransactionalTurnQueue;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Where a runtime keeps its conversations, streams, turns and mail, and how
|
|
23
|
+
* it admits work to an agent tree. A storage builds its parts on one
|
|
24
|
+
* database, so `admit` can bind all of them to one transaction; there is no
|
|
25
|
+
* way to hand it parts that live elsewhere.
|
|
26
|
+
*/
|
|
27
|
+
export declare abstract class AgentStorage {
|
|
28
|
+
abstract readonly store: ContextStore;
|
|
29
|
+
/** Stream subsystem over this storage's stream store. */
|
|
30
|
+
abstract readonly streams: StreamManager;
|
|
31
|
+
abstract readonly queue: TurnQueue;
|
|
32
|
+
/** Durable pending inter-agent input. Distinct from the TurnQueue scheduler. */
|
|
33
|
+
abstract readonly mailboxStore: MailboxStore;
|
|
34
|
+
/**
|
|
35
|
+
* Runs `work` while no other admission to `tree` runs, on any worker that
|
|
36
|
+
* shares this storage's database, with the parts bound to one unit.
|
|
37
|
+
* Resolves with what `work` returned once that unit has committed.
|
|
38
|
+
*/
|
|
39
|
+
abstract admit<T>(tree: AgentTree, work: (scope: AdmissionScope) => Promise<T>): Promise<T>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=agent-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-storage.d.ts","sourceRoot":"","sources":["../../../src/zukhruf/storage/agent-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EACV,YAAY,EACZ,yBAAyB,EAC1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEhF,yEAAyE;AACzE,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,YAAY,CAAC;IACpB,OAAO,EAAE,WAAW,CAAC;IACrB,YAAY,EAAE,yBAAyB,CAAC;IACxC,KAAK,EAAE,sBAAsB,CAAC;CAC/B;AAED;;;;;GAKG;AACH,8BAAsB,YAAY;IAChC,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IACtC,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IACzC,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IACnC,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IAE7C;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,CAAC,EACd,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,GAC1C,OAAO,CAAC,CAAC,CAAC;CACd"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { PGlite } from '@electric-sql/pglite';
|
|
2
|
+
import { PgBoss } from 'pg-boss';
|
|
3
|
+
import { type ContextStore, StreamManager } from '@deepagents/context';
|
|
4
|
+
import type { MailboxStore } from '../mailbox/store.ts';
|
|
5
|
+
import { type PgBossTurnQueueOptions } from '../queue/pg-boss.turn-queue.ts';
|
|
6
|
+
import type { TurnQueue } from '../queue/turn-queue.ts';
|
|
7
|
+
import { type AdmissionScope, AgentStorage, type AgentTree } from './agent-storage.ts';
|
|
8
|
+
export interface EmbeddedAgentStorageOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Where the storage keeps its files: `zukhruf.sqlite` (conversations,
|
|
11
|
+
* streams, mail and the turn outbox) and `zukhruf.queue` (the PGlite
|
|
12
|
+
* database of pg-boss), and `zukhruf.lock`, which the open storage holds.
|
|
13
|
+
* Created when missing. One storage at a time: a second open rejects with
|
|
14
|
+
* `EmbeddedAgentStorageInUseError`.
|
|
15
|
+
*/
|
|
16
|
+
directory: string;
|
|
17
|
+
/** Default: `pollingIntervalSeconds: 0.5`. */
|
|
18
|
+
queue?: Omit<PgBossTurnQueueOptions, 'schema'>;
|
|
19
|
+
}
|
|
20
|
+
/** `open` found the directory held by another open storage, in this process or another. */
|
|
21
|
+
export declare class EmbeddedAgentStorageInUseError extends Error {
|
|
22
|
+
readonly name = "EmbeddedAgentStorageInUseError";
|
|
23
|
+
readonly directory: string;
|
|
24
|
+
constructor(directory: string);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Agent storage for one process: the context, stream and mailbox stores on
|
|
28
|
+
* one SQLite connection, and the turn queue on pg-boss over PGlite, all under
|
|
29
|
+
* one directory, which the storage owns and closes.
|
|
30
|
+
*
|
|
31
|
+
* An admission is one SQLite `BEGIN IMMEDIATE` transaction that holds the
|
|
32
|
+
* connection alone, so admissions run one at a time, for every tree. A turn
|
|
33
|
+
* pushed inside it becomes an outbox row of the same transaction; after the
|
|
34
|
+
* commit a relay pushes the row to pg-boss as a job whose id is the row's, and
|
|
35
|
+
* deletes the row. `open` pushes the rows a stopped process left.
|
|
36
|
+
*/
|
|
37
|
+
export declare class EmbeddedAgentStorage extends AgentStorage implements AsyncDisposable {
|
|
38
|
+
#private;
|
|
39
|
+
readonly store: ContextStore;
|
|
40
|
+
readonly streams: StreamManager;
|
|
41
|
+
readonly queue: TurnQueue;
|
|
42
|
+
readonly mailboxStore: MailboxStore;
|
|
43
|
+
/** Started and owned; a host may bind it to plugins that keep jobs beside the turns. */
|
|
44
|
+
readonly boss: PgBoss;
|
|
45
|
+
/** The PGlite database pg-boss runs on, for transactions of such plugins. */
|
|
46
|
+
readonly queueDatabase: PGlite;
|
|
47
|
+
private constructor();
|
|
48
|
+
/**
|
|
49
|
+
* Opens the storage in `directory` and pushes the turns its outbox still
|
|
50
|
+
* holds. Rejects with `EmbeddedAgentStorageInUseError` while another storage
|
|
51
|
+
* has the directory open.
|
|
52
|
+
*/
|
|
53
|
+
static open(options: EmbeddedAgentStorageOptions): Promise<EmbeddedAgentStorage>;
|
|
54
|
+
/**
|
|
55
|
+
* Runs `work` in one SQLite transaction while no other admission, to any
|
|
56
|
+
* tree, runs. Resolves once it has committed; the relay then pushes the
|
|
57
|
+
* turns it outboxed.
|
|
58
|
+
*/
|
|
59
|
+
admit<T>(_tree: AgentTree, work: (scope: AdmissionScope) => Promise<T>): Promise<T>;
|
|
60
|
+
/** Waits for the relay, stops pg-boss, and closes both databases. */
|
|
61
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=embedded-agent-storage.d.ts.map
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AAC;IAM/B,OAAO;IAyBP;;;;OAIG;WACU,IAAI,CACf,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,oBAAoB,CAAC;IAkEhC;;;;OAIG;IACG,KAAK,CAAC,CAAC,EACX,KAAK,EAAE,SAAS,EAChB,IAAI,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,GAC1C,OAAO,CAAC,CAAC,CAAC;IAQb,qEAAqE;IAC/D,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7C"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Pool } from 'pg';
|
|
2
|
+
import type { PgBoss } from 'pg-boss';
|
|
3
|
+
import { PostgresContextStore, type StreamChangeSource, StreamManager } from '@deepagents/context';
|
|
4
|
+
import { PostgresMailboxStore } from '../mailbox/postgres.store.ts';
|
|
5
|
+
import { PgBossTurnQueue, type PgBossTurnQueueOptions } from '../queue/pg-boss.turn-queue.ts';
|
|
6
|
+
import { type AdmissionScope, AgentStorage, type AgentTree } from './agent-storage.ts';
|
|
7
|
+
/** One PostgreSQL database: its name on one server, told apart by the cluster's system identifier. */
|
|
8
|
+
export interface PostgresDatabaseIdentity {
|
|
9
|
+
database: string;
|
|
10
|
+
systemIdentifier: string;
|
|
11
|
+
}
|
|
12
|
+
/** The pool and PgBoss reach different databases, so one transaction cannot hold both. */
|
|
13
|
+
export declare class AgentStorageDatabaseMismatchError extends Error {
|
|
14
|
+
readonly name = "AgentStorageDatabaseMismatchError";
|
|
15
|
+
readonly pool: PostgresDatabaseIdentity;
|
|
16
|
+
readonly boss: PostgresDatabaseIdentity;
|
|
17
|
+
constructor(pool: PostgresDatabaseIdentity, boss: PostgresDatabaseIdentity);
|
|
18
|
+
}
|
|
19
|
+
export interface PostgresAgentStorageOptions {
|
|
20
|
+
/** Borrowed: the host owns the pool and ends it after the storage is disposed. */
|
|
21
|
+
pool: Pool;
|
|
22
|
+
/** Borrowed and started: the host stops it. It must use the pool's database. */
|
|
23
|
+
boss: PgBoss;
|
|
24
|
+
/** PostgreSQL schema of the context, stream and mailbox tables. Default: `public`. */
|
|
25
|
+
schema?: string;
|
|
26
|
+
queue?: PgBossTurnQueueOptions;
|
|
27
|
+
/**
|
|
28
|
+
* Wakes stream readers. Borrowed when given. Default: a
|
|
29
|
+
* `PostgresNotifyChangeSource` on the pool, which the storage closes.
|
|
30
|
+
*/
|
|
31
|
+
changeSource?: StreamChangeSource;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Agent storage on one PostgreSQL database: the context, stream and mailbox
|
|
35
|
+
* stores on the host's pool and the turn queue on PgBoss, which must reach
|
|
36
|
+
* the same database. An admission is one transaction under a per-tree
|
|
37
|
+
* advisory lock, so a session that dies mid-admission leaves nothing.
|
|
38
|
+
*
|
|
39
|
+
* Dispose it before ending the pool: it closes the change source it opened.
|
|
40
|
+
*/
|
|
41
|
+
export declare class PostgresAgentStorage extends AgentStorage implements AsyncDisposable {
|
|
42
|
+
#private;
|
|
43
|
+
readonly store: PostgresContextStore;
|
|
44
|
+
readonly streams: StreamManager;
|
|
45
|
+
readonly queue: PgBossTurnQueue;
|
|
46
|
+
readonly mailboxStore: PostgresMailboxStore;
|
|
47
|
+
private constructor();
|
|
48
|
+
/**
|
|
49
|
+
* Opens the storage: checks that the pool and PgBoss reach one database,
|
|
50
|
+
* then creates the tables and the turn queue.
|
|
51
|
+
*/
|
|
52
|
+
static create(options: PostgresAgentStorageOptions): Promise<PostgresAgentStorage>;
|
|
53
|
+
admit<T>(tree: AgentTree, work: (scope: AdmissionScope) => Promise<T>): Promise<T>;
|
|
54
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=postgres-agent-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-agent-storage.d.ts","sourceRoot":"","sources":["../../../src/zukhruf/storage/postgres-agent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AChC,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAC;IAM5C,OAAO;IAqBP;;;OAGG;WACU,MAAM,CACjB,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,oBAAoB,CAAC;IAsChC,KAAK,CAAC,CAAC,EACL,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,GAC1C,OAAO,CAAC,CAAC,CAAC;IAcP,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7C"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
/** A storage part was called inside an admission: the admission's work must use its scope. */
|
|
3
|
+
export declare class AdmissionScopeError extends Error {
|
|
4
|
+
readonly name = "AdmissionScopeError";
|
|
5
|
+
constructor();
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Shares one SQLite connection between the storage's parts and its
|
|
9
|
+
* admissions. A transaction on a connection holds every statement the
|
|
10
|
+
* connection runs, so while an admission's `BEGIN IMMEDIATE` is open no other
|
|
11
|
+
* call may reach the connection: its writes would commit or roll back with
|
|
12
|
+
* the admission, and its reads would see rows the admission may still roll
|
|
13
|
+
* back. Each call through `view` and each admission therefore holds the
|
|
14
|
+
* connection alone, in the order they came. A call's body runs synchronously
|
|
15
|
+
* on node:sqlite, so taking turns costs no concurrency SQLite would allow.
|
|
16
|
+
*
|
|
17
|
+
* Admissions run one at a time, for every tree: SQLite has one writer per database.
|
|
18
|
+
*/
|
|
19
|
+
export declare class SqliteAdmissionGate {
|
|
20
|
+
#private;
|
|
21
|
+
constructor(database: DatabaseSync);
|
|
22
|
+
/** `part` with every method run through `call`. */
|
|
23
|
+
view<Part extends object>(part: Part): Part;
|
|
24
|
+
/** Runs `operation` while it holds the connection alone. */
|
|
25
|
+
call<T>(operation: () => Promise<T>): Promise<T>;
|
|
26
|
+
/** Runs `work` in one `BEGIN IMMEDIATE` transaction: commits when it resolves, rolls back when it throws. */
|
|
27
|
+
admit<T>(work: () => Promise<T>): Promise<T>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=sqlite-admission-gate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-admission-gate.d.ts","sourceRoot":"","sources":["../../../src/zukhruf/storage/sqlite-admission-gate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,8FAA8F;AAC9F,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,SAAkB,IAAI,yBAAyB;;CAOhD;AAOD;;;;;;;;;;;GAWG;AACH,qBAAa,mBAAmB;;gBAKlB,QAAQ,EAAE,YAAY;IAIlC,mDAAmD;IACnD,IAAI,CAAC,IAAI,SAAS,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI;IAW3C,4DAA4D;IACtD,IAAI,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAKtD,6GAA6G;IACvG,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CA8BnD"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { DatabaseSync } from 'node:sqlite';
|
|
2
|
+
import type { PgBossTurnQueue } from '../queue/pg-boss.turn-queue.ts';
|
|
3
|
+
import { type ConsumeContext, type ConsumeOptions, type TransactionalTurnQueue, type TurnActivity, TurnQueue, type TurnRef } from '../queue/turn-queue.ts';
|
|
4
|
+
import type { SqliteAdmissionGate } from './sqlite-admission-gate.ts';
|
|
5
|
+
type Conversation = Pick<TurnRef, 'chatId' | 'userId'>;
|
|
6
|
+
interface OutboxedTurn {
|
|
7
|
+
/** The pg-boss job id the relay pushes the turn as. */
|
|
8
|
+
jobId: string;
|
|
9
|
+
turn: TurnRef;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Turns committed in SQLite and not yet pushed to pg-boss. Each method runs
|
|
13
|
+
* synchronously on the storage's connection, so inside an admission it reads
|
|
14
|
+
* and writes in the admission's transaction.
|
|
15
|
+
*/
|
|
16
|
+
export declare class TurnOutbox {
|
|
17
|
+
#private;
|
|
18
|
+
constructor(database: DatabaseSync);
|
|
19
|
+
add(turn: TurnRef): void;
|
|
20
|
+
oldest(): OutboxedTurn | undefined;
|
|
21
|
+
oldestOf(conversation: Conversation): TurnRef | undefined;
|
|
22
|
+
holds(conversation: Conversation): boolean;
|
|
23
|
+
remove(jobId: string): void;
|
|
24
|
+
removeStream(streamId: string): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Pushes outboxed turns to pg-boss in outbox order, one at a time, each as
|
|
28
|
+
* the job id the outbox gave it, and deletes a row only after its push. A
|
|
29
|
+
* process that dies between the two leaves the row, and the next drain pushes
|
|
30
|
+
* it again as the same job.
|
|
31
|
+
*/
|
|
32
|
+
export declare class OutboxRelay {
|
|
33
|
+
#private;
|
|
34
|
+
constructor(gate: SqliteAdmissionGate, outbox: TurnOutbox, queue: PgBossTurnQueue);
|
|
35
|
+
/** Resolves once every row added before the call has reached pg-boss. */
|
|
36
|
+
drain(): Promise<void>;
|
|
37
|
+
/** Runs `operation` while no drain runs. */
|
|
38
|
+
between<T>(operation: () => Promise<T>): Promise<T>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The embedded storage's turn queue: every push lands in the outbox and the
|
|
42
|
+
* relay moves it to pg-boss, so turns of one chat reach pg-boss in push order
|
|
43
|
+
* whether or not an admission pushed them. A conversation with a turn in the
|
|
44
|
+
* outbox reports `queued`.
|
|
45
|
+
*/
|
|
46
|
+
export declare class OutboxTurnQueue extends TurnQueue {
|
|
47
|
+
#private;
|
|
48
|
+
constructor(parts: {
|
|
49
|
+
gate: SqliteAdmissionGate;
|
|
50
|
+
outbox: TurnOutbox;
|
|
51
|
+
relay: OutboxRelay;
|
|
52
|
+
queue: PgBossTurnQueue;
|
|
53
|
+
});
|
|
54
|
+
/** The view an admission pushes and counts through: its pushes are outbox rows of its transaction. */
|
|
55
|
+
scope(): TransactionalTurnQueue;
|
|
56
|
+
/** Resolves once the turn is in pg-boss. */
|
|
57
|
+
push(turn: TurnRef): Promise<void>;
|
|
58
|
+
getTurnActivity(conversation: Conversation): Promise<TurnActivity>;
|
|
59
|
+
getCurrentTurn(conversation: Conversation): Promise<TurnRef | undefined>;
|
|
60
|
+
cancel(streamId: string): Promise<void>;
|
|
61
|
+
consume(handler: (turn: TurnRef, context: ConsumeContext) => Promise<void>, options: ConsumeOptions): Promise<AsyncDisposable>;
|
|
62
|
+
resumeParked(chatId: string): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
export {};
|
|
65
|
+
//# sourceMappingURL=turn-outbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-outbox.d.ts","sourceRoot":"","sources":["../../../src/zukhruf/storage/turn-outbox.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,SAAS,EACT,KAAK,OAAO,EACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAsBtE,KAAK,YAAY,GAAG,IAAI,CAAC,OAAO,EAAE,QAAQ,GAAG,QAAQ,CAAC,CAAC;AAEvD,UAAU,YAAY;IACpB,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;CACf;AAQD;;;;GAIG;AACH,qBAA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EAAE,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,EAClE,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC;IAI3B,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG5C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepagents/experimental",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -106,14 +106,16 @@
|
|
|
106
106
|
"@ai-sdk/openai": "^4.0.111",
|
|
107
107
|
"@ai-sdk/provider": "^4.0.37",
|
|
108
108
|
"@ai-sdk/provider-utils": "^5.0.76",
|
|
109
|
-
"@deepagents/compaction": "7.
|
|
110
|
-
"@deepagents/context": "7.
|
|
111
|
-
"@deepagents/elements": "7.
|
|
109
|
+
"@deepagents/compaction": "7.9.0",
|
|
110
|
+
"@deepagents/context": "7.9.0",
|
|
111
|
+
"@deepagents/elements": "7.9.0",
|
|
112
|
+
"@electric-sql/pglite": "^0.5.4",
|
|
112
113
|
"@iarna/toml": "^2.2.5",
|
|
113
114
|
"@napi-rs/keyring": "^2.1.0",
|
|
114
115
|
"@opencoredev/loginwithchatgpt-core": "^0.2.0",
|
|
115
116
|
"@sdk-it/hono": "^0.46.7",
|
|
116
117
|
"@zukhruf/async": "^0.8.41",
|
|
118
|
+
"@zukhruf/fs": "^0.8.41",
|
|
117
119
|
"@zukhruf/mutex": "^0.8.41",
|
|
118
120
|
"@zukhruf/sqlite-drift": "^0.8.41",
|
|
119
121
|
"@zukhruf/sqlite-open": "^0.8.41",
|
|
@@ -135,10 +137,8 @@
|
|
|
135
137
|
},
|
|
136
138
|
"devDependencies": {
|
|
137
139
|
"@ai-sdk/provider": "^4.0.37",
|
|
138
|
-
"@electric-sql/pglite": "^0.5.4",
|
|
139
140
|
"@sinonjs/fake-timers": "^15.4.0",
|
|
140
141
|
"@types/pg": "^8.20.0",
|
|
141
|
-
"@zukhruf/fs": "^0.8.41",
|
|
142
142
|
"just-bash": "^3.6.0",
|
|
143
143
|
"msw": "^3.0.3",
|
|
144
144
|
"undici": "^8.12.4"
|