@slopus/happy-agent-base 0.0.7 → 0.0.9
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 +18 -15
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +1 -3
- package/dist/Agent.js.map +1 -1
- package/dist/AgentBase.d.ts.map +1 -1
- package/dist/AgentBase.js +12 -2
- package/dist/AgentBase.js.map +1 -1
- package/dist/AgentContexts.d.ts +9 -2
- package/dist/AgentContexts.d.ts.map +1 -1
- package/dist/AgentContexts.js +45 -8
- package/dist/AgentContexts.js.map +1 -1
- package/dist/AgentDatabase.d.ts +5 -3
- package/dist/AgentDatabase.d.ts.map +1 -1
- package/dist/AgentDatabase.js.map +1 -1
- package/dist/AgentModule.d.ts +5 -7
- package/dist/AgentModule.d.ts.map +1 -1
- package/dist/AgentPersistenceDrizzle.d.ts +2 -4
- package/dist/AgentPersistenceDrizzle.d.ts.map +1 -1
- package/dist/AgentPersistenceDrizzle.js +18 -5
- package/dist/AgentPersistenceDrizzle.js.map +1 -1
- package/dist/AgentStorage.d.ts +4 -10
- package/dist/AgentStorage.d.ts.map +1 -1
- package/dist/AgentStorage.js +16 -100
- package/dist/AgentStorage.js.map +1 -1
- package/dist/AgentSystemContext.d.ts +2 -1
- package/dist/AgentSystemContext.d.ts.map +1 -1
- package/dist/AgentSystemContext.js.map +1 -1
- package/dist/AgentSystemLocal.d.ts.map +1 -1
- package/dist/AgentSystemLocal.js +3 -5
- package/dist/AgentSystemLocal.js.map +1 -1
- package/dist/AgentTool.d.ts +8 -1
- package/dist/AgentTool.d.ts.map +1 -1
- package/dist/AgentTool.js.map +1 -1
- package/dist/inTx.d.ts +17 -0
- package/dist/inTx.d.ts.map +1 -0
- package/dist/inTx.js +91 -0
- package/dist/inTx.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentContexts.d.ts","sourceRoot":"","sources":["../sources/AgentContexts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,
|
|
1
|
+
{"version":3,"file":"AgentContexts.d.ts","sourceRoot":"","sources":["../sources/AgentContexts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,EAAoD,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAEpG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAiC,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AA2BnG,2EAA2E;AAC3E,MAAM,WAAW,8BAA8B;IAC3C,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;CAClC;AAWD,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM,CAAC;QACb,UAAU,iBAAiB;YACvB,QAAQ,CAAC,EAAE,EAAE,aAAa,CAAC;SAC9B;KACJ;CACJ;AAwCD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC5B,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE;IACJ,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,MAAM,CAAC,EAAE,sBAAsB,GAAG,SAAS,CAAC;IACrD,QAAQ,CAAC,WAAW,CA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6FAA6F;AAC7F,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,aAAa,GAAG,SAAS,CAErE;AAED,8EAA8E;AAC9E,wBAAgB,2BAA2B,CACvC,GAAG,EAAE,OAAO,EACZ,WAAW,EAAE,8BAA8B,GAC5C,OAAO,CAQT;AAED,gGAAgG;AAChG,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,GAAG,8BAA8B,GAAG,SAAS,CAEhG;AAED,yFAAyF;AACzF,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAMpE"}
|
package/dist/AgentContexts.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContextNamespace } from "@steve.kite/stdlib";
|
|
1
|
+
import { createContextNamespace, registerContextExtension } from "@steve.kite/stdlib";
|
|
2
2
|
import { DEFAULT_AGENT_PERMISSION_MODE } from "./AgentPermissionMode.js";
|
|
3
3
|
/** Backing storage for `agentId`: the ID of the agent owning a context. */
|
|
4
4
|
const idNamespace = createContextNamespace("agentId", undefined);
|
|
@@ -16,9 +16,34 @@ const permissionModeNamespace = createContextNamespace("agentPermissionMode", DE
|
|
|
16
16
|
const kvNamespace = createContextNamespace("agentKV", undefined);
|
|
17
17
|
/** Backing storage for `agentRunKV`: the run's own store, erased when the agent settles. */
|
|
18
18
|
const runKVNamespace = createContextNamespace("agentRunKV", undefined);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
// Development loaders and Vitest can evaluate this module again while stdlib's extension registry
|
|
20
|
+
// remains shared. Reuse the namespaces as well as the registration because the getter closes over
|
|
21
|
+
// them and reloaded callers must keep writing to the same context slots.
|
|
22
|
+
const databaseContextRegistryKey = Symbol.for("@slopus/happy-agent-base/database-context-registry/v1");
|
|
23
|
+
const existingDatabaseContextRegistry = Reflect.get(globalThis, databaseContextRegistryKey);
|
|
24
|
+
const databaseContextRegistry = existingDatabaseContextRegistry ?? new WeakMap();
|
|
25
|
+
if (existingDatabaseContextRegistry === undefined) {
|
|
26
|
+
Reflect.set(globalThis, databaseContextRegistryKey, databaseContextRegistry);
|
|
27
|
+
}
|
|
28
|
+
const stdlibRegistryIdentity = registerContextExtension;
|
|
29
|
+
let databaseContextState = databaseContextRegistry.get(stdlibRegistryIdentity);
|
|
30
|
+
if (databaseContextState === undefined) {
|
|
31
|
+
const databaseNamespace = createContextNamespace("agentDatabase", undefined);
|
|
32
|
+
const storageTransactionNamespace = createContextNamespace("agentStorageTransaction", undefined);
|
|
33
|
+
registerContextExtension("db", (ctx) => {
|
|
34
|
+
const transaction = storageTransactionNamespace.get(ctx);
|
|
35
|
+
if (transaction?.lifetime.aborted === true) {
|
|
36
|
+
throw new Error("The agent storage transaction carried by this context has ended.");
|
|
37
|
+
}
|
|
38
|
+
const database = databaseNamespace.get(ctx);
|
|
39
|
+
if (database === undefined)
|
|
40
|
+
throw new Error("Context has no agent database.");
|
|
41
|
+
return database;
|
|
42
|
+
});
|
|
43
|
+
databaseContextState = { databaseNamespace, storageTransactionNamespace };
|
|
44
|
+
databaseContextRegistry.set(stdlibRegistryIdentity, databaseContextState);
|
|
45
|
+
}
|
|
46
|
+
const { databaseNamespace, storageTransactionNamespace } = databaseContextState;
|
|
22
47
|
/**
|
|
23
48
|
* Derive the agent's context carrying its ID, provider ID, model, effort, service tier, and
|
|
24
49
|
* permission mode — all serializable values. The agent applies this once at construction, so hooks
|
|
@@ -92,15 +117,23 @@ export function agentRunKV(ctx) {
|
|
|
92
117
|
}
|
|
93
118
|
/** Carry the active Drizzle database or transaction facade on a derived context. */
|
|
94
119
|
export function withAgentDatabase(ctx, database) {
|
|
95
|
-
|
|
120
|
+
const transaction = storageTransactionNamespace.get(ctx);
|
|
121
|
+
if (transaction !== undefined &&
|
|
122
|
+
(database === transaction.database || database === transaction.root)) {
|
|
123
|
+
return ctx;
|
|
124
|
+
}
|
|
125
|
+
return databaseNamespace.set(storageTransactionNamespace.set(ctx, undefined), database);
|
|
96
126
|
}
|
|
97
127
|
/** The active Drizzle database or transaction facade, when this work has durable storage. */
|
|
98
128
|
export function agentDatabase(ctx) {
|
|
99
129
|
return databaseNamespace.get(ctx);
|
|
100
130
|
}
|
|
101
|
-
/** Install the active facade
|
|
131
|
+
/** Install the active facade for the duration of one transaction callback. */
|
|
102
132
|
export function withAgentStorageTransaction(ctx, transaction) {
|
|
103
|
-
|
|
133
|
+
if (databaseNamespace.get(ctx) !== transaction.root) {
|
|
134
|
+
throw new Error("A transaction context cannot be used with another agent storage.");
|
|
135
|
+
}
|
|
136
|
+
return storageTransactionNamespace.set(databaseNamespace.set(ctx, transaction.database), transaction);
|
|
104
137
|
}
|
|
105
138
|
/** The storage transaction carried by this context, including its ended state when retained. */
|
|
106
139
|
export function agentStorageTransaction(ctx) {
|
|
@@ -108,6 +141,10 @@ export function agentStorageTransaction(ctx) {
|
|
|
108
141
|
}
|
|
109
142
|
/** Drop a caller's transaction lifetime when creating independently owned agent work. */
|
|
110
143
|
export function withoutAgentStorageTransaction(ctx) {
|
|
111
|
-
|
|
144
|
+
const transaction = storageTransactionNamespace.get(ctx);
|
|
145
|
+
const withoutTransaction = storageTransactionNamespace.set(ctx, undefined);
|
|
146
|
+
return transaction === undefined
|
|
147
|
+
? withoutTransaction
|
|
148
|
+
: databaseNamespace.set(withoutTransaction, transaction.root);
|
|
112
149
|
}
|
|
113
150
|
//# sourceMappingURL=AgentContexts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentContexts.js","sourceRoot":"","sources":["../sources/AgentContexts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAgB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"AgentContexts.js","sourceRoot":"","sources":["../sources/AgentContexts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAgB,MAAM,oBAAoB,CAAC;AAIpG,OAAO,EAAE,6BAA6B,EAA4B,MAAM,0BAA0B,CAAC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AAC;AACN,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,uBAAuB,CAAC,GAAY;IAChD,OAAO,2BAA2B,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAChD,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,8BAA8B,CAAC,GAAY;IACvD,MAAM,WAAW,GAAG,2BAA2B,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACzD,MAAM,kBAAkB,GAAG,2BAA2B,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAC3E,OAAO,WAAW,KAAK,SAAS;QAC5B,CAAC,CAAC,kBAAkB;QACpB,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,kBAAkB,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;AACtE,CAAC"}
|
package/dist/AgentDatabase.d.ts
CHANGED
|
@@ -19,13 +19,15 @@ export type AgentDatabase = AgentSQLiteDatabase | AgentPostgresDatabase;
|
|
|
19
19
|
* Driver-only root members such as `batch` and `$client` are intentionally absent.
|
|
20
20
|
*/
|
|
21
21
|
export type AgentDatabaseFacade<Database extends AgentDatabase> = Database extends BaseSQLiteDatabase<infer ResultKind, infer RunResult, infer FullSchema, infer Schema> ? BaseSQLiteDatabase<ResultKind, RunResult, FullSchema, Schema> : Database extends PgDatabase<infer QueryResult, infer FullSchema, infer Schema> ? PgDatabase<QueryResult, FullSchema, Schema> : never;
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* One ordered, durably tracked module migration. The context carries the active facade in
|
|
24
|
+
* `ctx.db`; the same facade is also passed explicitly so the migration retains its exact
|
|
25
|
+
* engine-specific type.
|
|
26
|
+
*/
|
|
23
27
|
export type AgentModuleMigration<Database extends AgentDatabase = AgentDatabase> = readonly [
|
|
24
28
|
key: string,
|
|
25
29
|
migrate: (ctx: Context, database: AgentDatabaseFacade<Database>) => void | Promise<void>
|
|
26
30
|
];
|
|
27
|
-
/** Work run inside the caller's outer transaction integration. */
|
|
28
|
-
export type AgentStorageTransaction<Database extends AgentDatabase = AgentDatabase> = <Result>(ctx: Context, work: (ctx: Context, database: AgentDatabaseFacade<Database>) => Promise<Result>) => Promise<Result>;
|
|
29
31
|
/** Whether a supported facade belongs to Drizzle's SQLite family. */
|
|
30
32
|
export declare function isAgentSQLiteDatabase(database: AgentDatabase): database is AgentSQLiteDatabase;
|
|
31
33
|
/** Run a query that returns rows on either supported Drizzle engine. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentDatabase.d.ts","sourceRoot":"","sources":["../sources/AgentDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,KAAK,GAAG,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;GAGG;AAEH,MAAM,MAAM,mBAAmB,GAAG,kBAAkB,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAE7E;;;GAGG;AAEH,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAE9D,iFAAiF;AACjF,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG,qBAAqB,CAAC;AAExE;;;GAGG;AACH,MAAM,MAAM,mBAAmB,CAAC,QAAQ,SAAS,aAAa,IAC1D,QAAQ,SAAS,kBAAkB,CAC/B,MAAM,UAAU,EAChB,MAAM,SAAS,EACf,MAAM,UAAU,EAChB,MAAM,MAAM,CACf,GACK,kBAAkB,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,GAC7D,QAAQ,SAAS,UAAU,CAAC,MAAM,WAAW,EAAE,MAAM,UAAU,EAAE,MAAM,MAAM,CAAC,GAC5E,UAAU,C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AAE,mBAAmB,CAAC,QAAQ,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAC3F,CAAC;AAEF,qEAAqE;AACrE,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,aAAa,GAAG,QAAQ,IAAI,mBAAmB,CAE9F;AAED,wEAAwE;AACxE,wBAAsB,iBAAiB,CAAC,GAAG,EACvC,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,GAAG,GACX,OAAO,CAAC,SAAS,GAAG,EAAE,CAAC,CAWzB;AAED,4DAA4D;AAC5D,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAMzF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentDatabase.js","sourceRoot":"","sources":["../sources/AgentDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAY,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"AgentDatabase.js","sourceRoot":"","sources":["../sources/AgentDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAY,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AA8C7D,qEAAqE;AACrE,MAAM,UAAU,qBAAqB,CAAC,QAAuB;IACzD,OAAO,EAAE,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;AAC5C,CAAC;AAED,wEAAwE;AACxE,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACnC,QAAuB,EACvB,KAAU;IAEV,IAAI,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClC,OAAO,MAAM,QAAQ,CAAC,GAAG,CAAM,KAAK,CAAC,CAAC;IAC1C,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC7C,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,MAAe,CAAC;IAClD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,MAAgB,EAAE,MAAM,CAAC,CAAC;IACnD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,IAAa,CAAC;AACzB,CAAC;AAED,4DAA4D;AAC5D,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,QAAuB,EAAE,KAAU;IACtE,IAAI,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClC,MAAM,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC1B,OAAO;IACX,CAAC;IACD,MAAM,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC"}
|
package/dist/AgentModule.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ProviderModelCompatibilityType, SessionEvent, SessionReasoningEffort, SessionServiceTier, SessionSystemMessage, SessionToolCallBlock, SessionToolResultMessage } from "@slopus/happy-providers";
|
|
2
2
|
import type { Context } from "@steve.kite/stdlib";
|
|
3
|
-
import type { AgentDatabase,
|
|
3
|
+
import type { AgentDatabase, AgentModuleMigration } from "./AgentDatabase.js";
|
|
4
4
|
import type { AgentBaseAcceptedMessage, AgentBaseInference, AgentBaseInferenceStart, AgentBaseLoop, AgentBaseModelChange, AgentBasePermissionModeChange, AgentBasePersistedEvent, AgentBaseToolCall, AgentBaseToolCallDecision, AgentBaseToolOutcome, AgentBaseSettlement, AgentBaseTurn, AgentBaseTurnStart, MaybePromise } from "./AgentBaseHooks.js";
|
|
5
5
|
import type { AgentModuleAction } from "./AgentModuleAction.js";
|
|
6
6
|
import type { AgentKV } from "./AgentKV.js";
|
|
@@ -42,14 +42,13 @@ export interface AgentModuleAgent {
|
|
|
42
42
|
/**
|
|
43
43
|
* What every hook of a module is handed alongside the context: which agent it is running for,
|
|
44
44
|
* and the three stores it may write to, each with its own lifetime.
|
|
45
|
+
* Database work uses the active root or transaction facade carried by `ctx.db`.
|
|
45
46
|
*
|
|
46
47
|
* They are passed rather than read off the context because a module's own dependencies are not
|
|
47
48
|
* ambient state to be looked up: a hook is given exactly what it is entitled to, and cannot be
|
|
48
49
|
* handed a context that quietly means a different agent.
|
|
49
50
|
*/
|
|
50
|
-
export interface AgentModuleScope<
|
|
51
|
-
/** The active Drizzle database or transaction facade for this hook. */
|
|
52
|
-
readonly database: AgentDatabaseFacade<Database>;
|
|
51
|
+
export interface AgentModuleScope<_Database extends AgentDatabase = AgentDatabase> {
|
|
53
52
|
/** The agent this hook is running for, and the selection it is running on. */
|
|
54
53
|
readonly agent: AgentModuleAgent;
|
|
55
54
|
/**
|
|
@@ -78,7 +77,6 @@ export interface AgentModuleAgentLifecycle {
|
|
|
78
77
|
}
|
|
79
78
|
/** System-owned capabilities handed to module lifecycle observers. */
|
|
80
79
|
export interface AgentModuleSystemScope<Database extends AgentDatabase = AgentDatabase> {
|
|
81
|
-
readonly database: AgentDatabaseFacade<Database>;
|
|
82
80
|
readonly agents: AgentSystemRef<Database>;
|
|
83
81
|
readonly sharedKV: AgentKV;
|
|
84
82
|
}
|
|
@@ -107,12 +105,12 @@ export interface AgentModule<Tool extends AnyAgentTool = AnyAgentTool, Database
|
|
|
107
105
|
* store lock and before any agent is restored or started. Every module initializes
|
|
108
106
|
* concurrently, and agent work begins only after all of them settle successfully.
|
|
109
107
|
*/
|
|
110
|
-
readonly beforeStart?: (ctx: Context, agents: AgentSystemRef<Database
|
|
108
|
+
readonly beforeStart?: (ctx: Context, agents: AgentSystemRef<Database>) => MaybePromise<void>;
|
|
111
109
|
/**
|
|
112
110
|
* Called once after every durable-active agent has been restored and started. Every module
|
|
113
111
|
* runs concurrently, and system creation resolves only after all of them settle successfully.
|
|
114
112
|
*/
|
|
115
|
-
readonly afterStart?: (ctx: Context, agents: AgentSystemRef<Database
|
|
113
|
+
readonly afterStart?: (ctx: Context, agents: AgentSystemRef<Database>) => MaybePromise<void>;
|
|
116
114
|
readonly agentCreatedTransact?: (ctx: Context, scope: AgentModuleSystemScope<Database>, agent: AgentModuleAgentLifecycle) => MaybePromise<void>;
|
|
117
115
|
readonly agentCreated?: (ctx: Context, scope: AgentModuleSystemScope<Database>, agent: AgentModuleAgentLifecycle) => MaybePromise<void>;
|
|
118
116
|
readonly agentRestoredTransact?: (ctx: Context, scope: AgentModuleSystemScope<Database>, agent: AgentModuleAgentLifecycle) => MaybePromise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentModule.d.ts","sourceRoot":"","sources":["../sources/AgentModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,8BAA8B,EAC9B,YAAY,EACZ,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EAC3B,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,KAAK,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"AgentModule.d.ts","sourceRoot":"","sources":["../sources/AgentModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,8BAA8B,EAC9B,YAAY,EACZ,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EAC3B,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC9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Z,KAAK,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EACjC,UAAU,EAAE,mBAAmB,KAC9B,YAAY,CAAC,IAAI,CAAC,CAAC;IACxB,8EAA8E;IAC9E,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CACzB,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EACjC,UAAU,EAAE,mBAAmB,KAC9B,YAAY,CAAC,IAAI,CAAC,CAAC;CAC3B"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { Context } from "@steve.kite/stdlib";
|
|
2
|
-
import { type AgentDatabase
|
|
2
|
+
import { type AgentDatabase } from "./AgentDatabase.js";
|
|
3
3
|
import type { AgentPersistence, AgentRecord } from "./AgentPersistence.js";
|
|
4
|
-
/** The database
|
|
4
|
+
/** The database shared by every persistence scope in one AgentStorage. */
|
|
5
5
|
export interface AgentPersistenceDrizzleOptions<Database extends AgentDatabase = AgentDatabase> {
|
|
6
6
|
readonly database: Database;
|
|
7
|
-
readonly owner: object;
|
|
8
|
-
readonly transaction: AgentStorageTransaction<Database>;
|
|
9
7
|
}
|
|
10
8
|
/**
|
|
11
9
|
* Drizzle-backed records and key-value entries for either the collection root or one agent.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentPersistenceDrizzle.d.ts","sourceRoot":"","sources":["../sources/AgentPersistenceDrizzle.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAGH,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"AgentPersistenceDrizzle.d.ts","sourceRoot":"","sources":["../sources/AgentPersistenceDrizzle.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAGH,KAAK,aAAa,EAErB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,gBAAgB,EAA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CAapF;IAEK,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ1D;CAgCJ"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { sql } from "drizzle-orm";
|
|
2
2
|
import { agentDatabaseRows, agentDatabaseRun, } from "./AgentDatabase.js";
|
|
3
|
-
import { agentStorageTransaction } from "./AgentContexts.js";
|
|
3
|
+
import { agentStorageTransaction, withAgentDatabase } from "./AgentContexts.js";
|
|
4
|
+
import { inTx } from "./inTx.js";
|
|
4
5
|
/**
|
|
5
6
|
* Drizzle-backed records and key-value entries for either the collection root or one agent.
|
|
6
7
|
* Tables are shared by every instance; `ownerId` is empty for collection state and the cuid2
|
|
@@ -17,7 +18,7 @@ export class AgentPersistenceDrizzle {
|
|
|
17
18
|
return this.#options.database;
|
|
18
19
|
}
|
|
19
20
|
async transaction(ctx, work) {
|
|
20
|
-
return await this.#
|
|
21
|
+
return await inTx(this.#bound(ctx), work);
|
|
21
22
|
}
|
|
22
23
|
async load(ctx) {
|
|
23
24
|
return await this.#operation(ctx, async (database) => {
|
|
@@ -86,14 +87,26 @@ export class AgentPersistenceDrizzle {
|
|
|
86
87
|
if (transaction.lifetime.aborted) {
|
|
87
88
|
throw new Error("The agent storage transaction carried by this context has ended.");
|
|
88
89
|
}
|
|
89
|
-
if (transaction.
|
|
90
|
+
if (transaction.root !== this.#options.database) {
|
|
90
91
|
throw new Error("A transaction context cannot be used with another agent storage.");
|
|
91
92
|
}
|
|
92
93
|
return await work(transaction.database);
|
|
93
94
|
}
|
|
94
|
-
return await this.#options.
|
|
95
|
-
return await work(
|
|
95
|
+
return await inTx(withAgentDatabase(ctx, this.#options.database), async (txCtx) => {
|
|
96
|
+
return await work(txCtx.db);
|
|
96
97
|
});
|
|
97
98
|
}
|
|
99
|
+
#bound(ctx) {
|
|
100
|
+
const transaction = agentStorageTransaction(ctx);
|
|
101
|
+
if (transaction === undefined)
|
|
102
|
+
return withAgentDatabase(ctx, this.#options.database);
|
|
103
|
+
if (transaction.lifetime.aborted) {
|
|
104
|
+
throw new Error("The agent storage transaction carried by this context has ended.");
|
|
105
|
+
}
|
|
106
|
+
if (transaction.root !== this.#options.database) {
|
|
107
|
+
throw new Error("A transaction context cannot be used with another agent storage.");
|
|
108
|
+
}
|
|
109
|
+
return ctx;
|
|
110
|
+
}
|
|
98
111
|
}
|
|
99
112
|
//# sourceMappingURL=AgentPersistenceDrizzle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentPersistenceDrizzle.js","sourceRoot":"","sources":["../sources/AgentPersistenceDrizzle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGlC,OAAO,EACH,iBAAiB,EACjB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"AgentPersistenceDrizzle.js","sourceRoot":"","sources":["../sources/AgentPersistenceDrizzle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGlC,OAAO,EACH,iBAAiB,EACjB,gBAAgB,GAGnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEhF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAOjC;;;;GAIG;AACH,MAAM,OAAO,uBAAuB;IAGvB,QAAQ,CAA2C;IACnD,QAAQ,CAAS;IAE1B,YAAY,OAAiD,EAAE,OAAe;QAC1E,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC5B,CAAC;IAED,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAClC,CAAC;IAED,KAAK,CAAC,WAAW,CACb,GAAY,EACZ,IAAuC;QAEvC,OAAO,MAAM,IAAI,CAAC,IAAI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AQ,CAAC,OAAO,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;QACxF,CAAC;QACD,IAAI,WAAW,CAAC,IAAI,KAAK,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;QACxF,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;CACJ"}
|
package/dist/AgentStorage.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type AgentDatabase, type AgentDatabaseFacade
|
|
1
|
+
import type { Context } from "@steve.kite/stdlib";
|
|
2
|
+
import { type AgentDatabase, type AgentDatabaseFacade } from "./AgentDatabase.js";
|
|
3
3
|
import type { AgentModule } from "./AgentModule.js";
|
|
4
4
|
import { AgentKV } from "./AgentKV.js";
|
|
5
5
|
import type { AgentPersistence } from "./AgentPersistence.js";
|
|
@@ -19,16 +19,10 @@ interface AgentStorageCommonOptions {
|
|
|
19
19
|
*/
|
|
20
20
|
readonly acquireLock: (ctx: Context) => Promise<AgentStorageLock>;
|
|
21
21
|
}
|
|
22
|
-
/** Drizzle-owned storage
|
|
22
|
+
/** Drizzle-owned storage. */
|
|
23
23
|
export type AgentStorageOptions<Database extends AgentDatabase = AgentDatabase> = AgentStorageCommonOptions & {
|
|
24
24
|
/** The engine-specific Drizzle facade; the same object is passed through to modules. */
|
|
25
25
|
readonly database: Database;
|
|
26
|
-
/**
|
|
27
|
-
* Host transaction integration. It must pass the active Drizzle transaction facade and a
|
|
28
|
-
* context carrying the host transaction's stdlib `afterCommit` scope to `work`. Omission
|
|
29
|
-
* uses the Drizzle facade's own transaction method and installs that scope automatically.
|
|
30
|
-
*/
|
|
31
|
-
readonly transaction?: AgentStorageTransaction<Database>;
|
|
32
26
|
};
|
|
33
27
|
/** Storage roots and Drizzle persistence shared by an `AgentSystemLocal` collection. */
|
|
34
28
|
export declare class AgentStorage<Database extends AgentDatabase = AgentDatabase> {
|
|
@@ -46,7 +40,7 @@ export declare class AgentStorage<Database extends AgentDatabase = AgentDatabase
|
|
|
46
40
|
acquireLock(ctx: Context): Promise<AgentStorageLock>;
|
|
47
41
|
/** The isolated persistence for the given agent. */
|
|
48
42
|
persistence(agentId: string): AgentPersistence;
|
|
49
|
-
/** Run work in this storage's
|
|
43
|
+
/** Run work in this storage's internally managed transaction. */
|
|
50
44
|
transaction<Result>(ctx: Context, work: (ctx: Context, database: AgentDatabaseFacade<Database>) => Promise<Result>): Promise<Result>;
|
|
51
45
|
/**
|
|
52
46
|
* Install the base schema and every module's ordered keyed migrations. Each migration and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentStorage.d.ts","sourceRoot":"","sources":["../sources/AgentStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AgentStorage.d.ts","sourceRoot":"","sources":["../sources/AgentStorage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAGH,KAAK,aAAa,EAClB,KAAK,mBAAmB,EAE3B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC7B,kFAAkF;IAClF,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC;AAED,UAAU,yBAAyB;IAC/B;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACrE;AAED,6BAA6B;AAC7B,MAAM,MAAM,mBAAmB,CAAC,QAAQ,SAAS,aAAa,GAAG,aAAa,IAC1E,yBAAyB,GAAG;IACxB,wFAAwF;IACxF,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC/B,CAAC;AAEN,wFAAwF;AACxF,qBAAa,YAAY,CAAC,QAAQ,SAAS,aAAa,GAAG,aAAa;;IACpE,+BAA+B;IAC/B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,mEAAmE;IACnE,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IAUrB,YAAY,OAAO,EAAE,mBAAmB,CAAC,QAAQ,CAAC,EASjD;IAED;;;;OAIG;IACG,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAmBzD;IAED,oDAAoD;IACpD,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAE7C;IAED,iEAAiE;IAC3D,WAAW,CAAC,MAAM,EACpB,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,GACjF,OAAO,CAAC,MAAM,CAAC,CAKjB;IAED;;;;OAIG;IACG,OAAO,CACT,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE,SAAS,WAAW,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAE,GACxD,OAAO,CAAC,IAAI,CAAC,CA6Cf;CAgDJ"}
|
package/dist/AgentStorage.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
1
|
import { sql } from "drizzle-orm";
|
|
3
|
-
import {
|
|
4
|
-
import { agentDatabaseRows, agentDatabaseRun, isAgentSQLiteDatabase, } from "./AgentDatabase.js";
|
|
5
|
-
import { agentStorageTransaction, withAgentStorageTransaction, } from "./AgentContexts.js";
|
|
2
|
+
import { agentDatabaseRows, agentDatabaseRun, } from "./AgentDatabase.js";
|
|
6
3
|
import { AgentKV } from "./AgentKV.js";
|
|
7
|
-
import { AgentPersistenceDrizzle
|
|
8
|
-
const storageTransactions = new AsyncLocalStorage();
|
|
4
|
+
import { AgentPersistenceDrizzle } from "./AgentPersistenceDrizzle.js";
|
|
9
5
|
/** Storage roots and Drizzle persistence shared by an `AgentSystemLocal` collection. */
|
|
10
6
|
export class AgentStorage {
|
|
11
7
|
/** The root Drizzle facade. */
|
|
@@ -16,22 +12,18 @@ export class AgentStorage {
|
|
|
16
12
|
#acquireLock;
|
|
17
13
|
/** Produces the isolated persistence used by one agent. */
|
|
18
14
|
#persistence;
|
|
19
|
-
/**
|
|
15
|
+
/** Root persistence used for storage-wide transactions and key-value state. */
|
|
20
16
|
#drizzle;
|
|
21
17
|
/** Prevents two systems from sharing even one AgentStorage instance. */
|
|
22
18
|
#owned = false;
|
|
23
19
|
constructor(options) {
|
|
24
20
|
this.#acquireLock = options.acquireLock;
|
|
25
21
|
this.database = options.database;
|
|
26
|
-
const owner = {};
|
|
27
|
-
const rawTransaction = options.transaction ?? defaultTransactionIntegration(options.database);
|
|
28
22
|
const integration = {
|
|
29
23
|
database: options.database,
|
|
30
|
-
owner,
|
|
31
|
-
transaction: storageTransactionIntegration(owner, rawTransaction),
|
|
32
24
|
};
|
|
33
|
-
this.#drizzle = integration;
|
|
34
|
-
this.kv = new AgentKV(
|
|
25
|
+
this.#drizzle = new AgentPersistenceDrizzle(integration, "");
|
|
26
|
+
this.kv = new AgentKV(this.#drizzle, "agentSystem.");
|
|
35
27
|
this.#persistence = (agentId) => new AgentPersistenceDrizzle(integration, agentId);
|
|
36
28
|
}
|
|
37
29
|
/**
|
|
@@ -66,9 +58,9 @@ export class AgentStorage {
|
|
|
66
58
|
persistence(agentId) {
|
|
67
59
|
return this.#persistence(agentId);
|
|
68
60
|
}
|
|
69
|
-
/** Run work in this storage's
|
|
61
|
+
/** Run work in this storage's internally managed transaction. */
|
|
70
62
|
async transaction(ctx, work) {
|
|
71
|
-
return await this.#drizzle.transaction(ctx, work);
|
|
63
|
+
return await this.#drizzle.transaction(ctx, async (txCtx) => await work(txCtx, txCtx.db));
|
|
72
64
|
}
|
|
73
65
|
/**
|
|
74
66
|
* Install the base schema and every module's ordered keyed migrations. Each migration and
|
|
@@ -80,8 +72,8 @@ export class AgentStorage {
|
|
|
80
72
|
if (names.includes("@happy-agent-base") || new Set(names).size !== names.length) {
|
|
81
73
|
throw new Error("Module names must be unique and cannot use the agent-base owner.");
|
|
82
74
|
}
|
|
83
|
-
await this.#drizzle.transaction(ctx, async (txCtx
|
|
84
|
-
await agentDatabaseRun(
|
|
75
|
+
await this.#drizzle.transaction(ctx, async (txCtx) => {
|
|
76
|
+
await agentDatabaseRun(txCtx.db, sql `CREATE TABLE IF NOT EXISTS happy_agent_migrations (
|
|
85
77
|
module_key TEXT NOT NULL,
|
|
86
78
|
migration_key TEXT NOT NULL,
|
|
87
79
|
position BIGINT NOT NULL,
|
|
@@ -117,10 +109,10 @@ export class AgentStorage {
|
|
|
117
109
|
if (keys.some((key) => key.length === 0) || new Set(keys).size !== keys.length) {
|
|
118
110
|
throw new Error(`Module "${module}" has an empty or duplicate migration key.`);
|
|
119
111
|
}
|
|
120
|
-
const applied = await
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
112
|
+
const applied = await this.#drizzle.transaction(ctx, async (txCtx) => agentDatabaseRows(txCtx.db, sql `SELECT migration_key, position
|
|
113
|
+
FROM happy_agent_migrations
|
|
114
|
+
WHERE module_key = ${module}
|
|
115
|
+
ORDER BY position`));
|
|
124
116
|
for (let index = 0; index < applied.length; index += 1) {
|
|
125
117
|
if (applied[index]?.migration_key !== keys[index] ||
|
|
126
118
|
Number(applied[index]?.position) !== index) {
|
|
@@ -132,89 +124,13 @@ export class AgentStorage {
|
|
|
132
124
|
if (migration === undefined)
|
|
133
125
|
continue;
|
|
134
126
|
const [key, run] = migration;
|
|
135
|
-
await this.#drizzle.transaction(ctx, async (txCtx
|
|
136
|
-
await run(txCtx,
|
|
137
|
-
await agentDatabaseRun(
|
|
127
|
+
await this.#drizzle.transaction(ctx, async (txCtx) => {
|
|
128
|
+
await run(txCtx, txCtx.db);
|
|
129
|
+
await agentDatabaseRun(txCtx.db, sql `INSERT INTO happy_agent_migrations
|
|
138
130
|
(module_key, migration_key, position)
|
|
139
131
|
VALUES (${module}, ${key}, ${index})`);
|
|
140
132
|
});
|
|
141
133
|
}
|
|
142
134
|
}
|
|
143
135
|
}
|
|
144
|
-
function defaultTransactionIntegration(database) {
|
|
145
|
-
const transactionLock = isAgentSQLiteDatabase(database) ? asyncLock() : undefined;
|
|
146
|
-
const commitTransaction = async (ctx, work) => {
|
|
147
|
-
let runAfterCommit;
|
|
148
|
-
const result = await runDrizzleTransaction(database, async (activeDatabase) => {
|
|
149
|
-
const [commitCtx, drainAfterCommit] = withAfterCommit(ctx);
|
|
150
|
-
runAfterCommit = drainAfterCommit;
|
|
151
|
-
return await work(commitCtx, activeDatabase);
|
|
152
|
-
});
|
|
153
|
-
return [result, runAfterCommit];
|
|
154
|
-
};
|
|
155
|
-
const transaction = async (ctx, work) => {
|
|
156
|
-
const [result, runAfterCommit] = transactionLock === undefined
|
|
157
|
-
? await commitTransaction(ctx, work)
|
|
158
|
-
: await transactionLock.runInLock(ctx, async (lockCtx) => {
|
|
159
|
-
return await commitTransaction(lockCtx, work);
|
|
160
|
-
});
|
|
161
|
-
try {
|
|
162
|
-
await runAfterCommit();
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
process.emitWarning(new AggregateError([error], "Agent storage committed, but post-commit work failed."));
|
|
166
|
-
}
|
|
167
|
-
return result;
|
|
168
|
-
};
|
|
169
|
-
return transaction;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Own transaction identity and nesting independently of the supplied database integration.
|
|
173
|
-
* A normal context from another storage remains a normal context, while an actual foreign
|
|
174
|
-
* transaction can neither leak its facade into this store nor silently open a second commit.
|
|
175
|
-
*/
|
|
176
|
-
function storageTransactionIntegration(owner, transaction) {
|
|
177
|
-
return async (ctx, work) => {
|
|
178
|
-
const carried = agentStorageTransaction(ctx);
|
|
179
|
-
const ambient = storageTransactions.getStore();
|
|
180
|
-
if (ambient !== undefined && !ambient.lifetime.aborted) {
|
|
181
|
-
if (ambient.owner === owner && carried === ambient) {
|
|
182
|
-
return await work(ctx, ambient.database);
|
|
183
|
-
}
|
|
184
|
-
throw new Error("Work started inside an agent storage transaction must use that transaction's context.");
|
|
185
|
-
}
|
|
186
|
-
if (carried !== undefined) {
|
|
187
|
-
if (carried.lifetime.aborted) {
|
|
188
|
-
throw new Error("The agent storage transaction carried by this context has ended.");
|
|
189
|
-
}
|
|
190
|
-
if (carried.owner !== owner) {
|
|
191
|
-
throw new Error("A transaction context cannot be used with another agent storage.");
|
|
192
|
-
}
|
|
193
|
-
return await work(ctx, carried.database);
|
|
194
|
-
}
|
|
195
|
-
return await transaction(ctx, async (txCtx, database) => {
|
|
196
|
-
const lifetime = new AbortController();
|
|
197
|
-
const state = {
|
|
198
|
-
database,
|
|
199
|
-
lifetime: lifetime.signal,
|
|
200
|
-
owner,
|
|
201
|
-
};
|
|
202
|
-
const activeCtx = withAgentStorageTransaction(txCtx, state);
|
|
203
|
-
try {
|
|
204
|
-
return await storageTransactions.run(state, async () => {
|
|
205
|
-
return await work(activeCtx, database);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
finally {
|
|
209
|
-
lifetime.abort();
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
async function runDrizzleTransaction(database, work) {
|
|
215
|
-
if (isAgentSQLiteDatabase(database)) {
|
|
216
|
-
return await database.transaction(async (transaction) => await work(transaction));
|
|
217
|
-
}
|
|
218
|
-
return await database.transaction(async (transaction) => await work(transaction));
|
|
219
|
-
}
|
|
220
136
|
//# sourceMappingURL=AgentStorage.js.map
|
package/dist/AgentStorage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentStorage.js","sourceRoot":"","sources":["../sources/AgentStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"AgentStorage.js","sourceRoot":"","sources":["../sources/AgentStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGlC,OAAO,EACH,iBAAiB,EACjB,gBAAgB,GAInB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AA0BvE,wFAAwF;AACxF,MAAM,OAAO,YAAY;IACrB,+BAA+B;IACtB,QAAQ,CAAW;IAC5B,mEAAmE;IAC1D,EAAE,CAAU;IACrB,kEAAkE;IACzD,YAAY,CAA8C;IACnE,2DAA2D;IAClD,YAAY,CAAwC;IAC7D,+EAA+E;IACtE,QAAQ,CAAoC;IACrD,wEAAwE;IACxE,MAAM,GAAG,KAAK,CAAC;IAEf,YAAY,OAAsC;QAC9C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;QACxC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,MAAM,WAAW,GAAG;YAChB,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC7B,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,IAAI,uBAAuB,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAC7D,IAAI,CAAC,EAAE,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QACrD,IAAI,CAAC,YAAY,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,uBAAuB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACvF,CAAC;IAED;;;;OAIG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,CAAC;CACJ"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Context } from "@steve.kite/stdlib";
|
|
2
|
+
import type { AgentDatabase } from "./AgentDatabase.js";
|
|
2
3
|
import type { AgentSystemRef } from "./AgentSystemRef.js";
|
|
3
4
|
/**
|
|
4
5
|
* Carry the collection that owns an agent and its modules, as a reference.
|
|
@@ -9,7 +10,7 @@ import type { AgentSystemRef } from "./AgentSystemRef.js";
|
|
|
9
10
|
* every context it derives, and agents come back from it as `AgentRef`, so nothing reached
|
|
10
11
|
* through a context can wait for the loop that is waiting for it.
|
|
11
12
|
*/
|
|
12
|
-
export declare function withAgentSystem(ctx: Context, value: AgentSystemRef): Context;
|
|
13
|
+
export declare function withAgentSystem<Database extends AgentDatabase>(ctx: Context, value: AgentSystemRef<Database>): Context;
|
|
13
14
|
/** The collection owning the current module or agent operation. */
|
|
14
15
|
export declare function agentSystem(ctx: Context): AgentSystemRef | undefined;
|
|
15
16
|
//# sourceMappingURL=AgentSystemContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentSystemContext.d.ts","sourceRoot":"","sources":["../sources/AgentSystemContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQ1D;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"AgentSystemContext.d.ts","sourceRoot":"","sources":["../sources/AgentSystemContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQ1D;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,QAAQ,SAAS,aAAa,EAC1D,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,cAAc,CAAC,QAAQ,CAAC,GAChC,OAAO,CAET;AAED,mEAAmE;AACnE,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,GAAG,SAAS,CAEpE"}
|