@slopus/happy-agent-base 0.0.6 → 0.0.7
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 +49 -11
- package/dist/Agent.d.ts +24 -22
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +113 -111
- package/dist/Agent.js.map +1 -1
- package/dist/AgentBase.d.ts +18 -14
- package/dist/AgentBase.d.ts.map +1 -1
- package/dist/AgentBase.js +476 -122
- package/dist/AgentBase.js.map +1 -1
- package/dist/AgentBaseHooks.d.ts +41 -28
- package/dist/AgentBaseHooks.d.ts.map +1 -1
- package/dist/AgentBasePending.d.ts +6 -2
- package/dist/AgentBasePending.d.ts.map +1 -1
- package/dist/AgentBasePending.js +7 -0
- package/dist/AgentBasePending.js.map +1 -1
- package/dist/AgentConfig.d.ts +9 -9
- package/dist/AgentConfig.d.ts.map +1 -1
- package/dist/AgentConfig.js +8 -8
- package/dist/AgentConfig.js.map +1 -1
- package/dist/AgentContexts.d.ts +18 -1
- package/dist/AgentContexts.d.ts.map +1 -1
- package/dist/AgentContexts.js +24 -1
- package/dist/AgentContexts.js.map +1 -1
- package/dist/AgentDatabase.d.ts +35 -0
- package/dist/AgentDatabase.d.ts.map +1 -0
- package/dist/AgentDatabase.js +30 -0
- package/dist/AgentDatabase.js.map +1 -0
- package/dist/AgentKV.d.ts +19 -6
- package/dist/AgentKV.d.ts.map +1 -1
- package/dist/AgentKV.js +110 -43
- package/dist/AgentKV.js.map +1 -1
- package/dist/AgentMessageAcceptance.d.ts +14 -0
- package/dist/AgentMessageAcceptance.d.ts.map +1 -0
- package/dist/AgentMessageAcceptance.js +2 -0
- package/dist/AgentMessageAcceptance.js.map +1 -0
- package/dist/AgentMetadata.d.ts +3 -3
- package/dist/AgentMetadata.js +3 -3
- package/dist/AgentModule.d.ts +209 -0
- package/dist/AgentModule.d.ts.map +1 -0
- package/dist/AgentModule.js +2 -0
- package/dist/AgentModule.js.map +1 -0
- package/dist/{AgentFeatureAction.d.ts → AgentModuleAction.d.ts} +2 -2
- package/dist/AgentModuleAction.d.ts.map +1 -0
- package/dist/AgentModuleAction.js +2 -0
- package/dist/AgentModuleAction.js.map +1 -0
- package/dist/AgentPermissionMode.d.ts +1 -1
- package/dist/AgentPermissionMode.js +1 -1
- package/dist/AgentPersistence.d.ts +7 -4
- package/dist/AgentPersistence.d.ts.map +1 -1
- package/dist/AgentPersistenceDrizzle.d.ts +31 -0
- package/dist/AgentPersistenceDrizzle.d.ts.map +1 -0
- package/dist/AgentPersistenceDrizzle.js +99 -0
- package/dist/AgentPersistenceDrizzle.js.map +1 -0
- package/dist/AgentRef.d.ts +12 -9
- package/dist/AgentRef.d.ts.map +1 -1
- package/dist/AgentRef.js +8 -8
- package/dist/AgentRef.js.map +1 -1
- package/dist/AgentStorage.d.ts +33 -13
- package/dist/AgentStorage.d.ts.map +1 -1
- package/dist/AgentStorage.js +174 -3
- package/dist/AgentStorage.js.map +1 -1
- package/dist/AgentSystem.d.ts +10 -7
- package/dist/AgentSystem.d.ts.map +1 -1
- package/dist/AgentSystemContext.d.ts +3 -3
- package/dist/AgentSystemContext.d.ts.map +1 -1
- package/dist/AgentSystemContext.js +4 -4
- package/dist/AgentSystemContext.js.map +1 -1
- package/dist/AgentSystemLocal.d.ts +17 -14
- package/dist/AgentSystemLocal.d.ts.map +1 -1
- package/dist/AgentSystemLocal.js +120 -29
- package/dist/AgentSystemLocal.js.map +1 -1
- package/dist/AgentSystemRef.d.ts +9 -7
- package/dist/AgentSystemRef.d.ts.map +1 -1
- package/dist/AgentSystemRef.js +17 -4
- package/dist/AgentSystemRef.js.map +1 -1
- package/dist/AgentTool.d.ts +16 -1
- package/dist/AgentTool.d.ts.map +1 -1
- package/dist/AgentTool.js.map +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/dist/AgentFeature.d.ts +0 -184
- package/dist/AgentFeature.d.ts.map +0 -1
- package/dist/AgentFeature.js +0 -2
- package/dist/AgentFeature.js.map +0 -1
- package/dist/AgentFeatureAction.d.ts.map +0 -1
- package/dist/AgentFeatureAction.js +0 -2
- package/dist/AgentFeatureAction.js.map +0 -1
package/dist/AgentConfig.d.ts
CHANGED
|
@@ -6,12 +6,12 @@ export declare const agentPlatformSchema: import("@sinclair/typebox").TUnion<[im
|
|
|
6
6
|
/** The TypeScript type inferred from {@link agentPlatformSchema}. */
|
|
7
7
|
export type AgentPlatform = Static<typeof agentPlatformSchema>;
|
|
8
8
|
/**
|
|
9
|
-
* The settings one
|
|
9
|
+
* The settings one module was configured with. The agent never looks inside: a module owns
|
|
10
10
|
* the shape of its own entry and validates it against its own schema.
|
|
11
11
|
*/
|
|
12
|
-
export declare const
|
|
13
|
-
/** The TypeScript type inferred from {@link
|
|
14
|
-
export type
|
|
12
|
+
export declare const agentModuleConfigSchema: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>;
|
|
13
|
+
/** The TypeScript type inferred from {@link agentModuleConfigSchema}. */
|
|
14
|
+
export type AgentModuleConfig = Static<typeof agentModuleConfigSchema>;
|
|
15
15
|
/**
|
|
16
16
|
* The machine an agent works on. It is all or nothing: an agent either knows its environment
|
|
17
17
|
* completely or not at all, so nothing it is told about the machine is ever half-true.
|
|
@@ -30,7 +30,7 @@ export declare const agentEnvironmentSchema: import("@sinclair/typebox").TObject
|
|
|
30
30
|
export type AgentEnvironment = Static<typeof agentEnvironmentSchema>;
|
|
31
31
|
/**
|
|
32
32
|
* What an agent was created with: the environment it works on, when it has one, one opaque
|
|
33
|
-
* settings map per
|
|
33
|
+
* settings map per module, and descriptive metadata. Environment and module settings stay
|
|
34
34
|
* fixed; metadata changes only through the agent metadata API, which shallow-merges updates and
|
|
35
35
|
* persists the resulting complete configuration.
|
|
36
36
|
*/
|
|
@@ -46,8 +46,8 @@ export declare const agentConfigSchema: import("@sinclair/typebox").TObject<{
|
|
|
46
46
|
/** The shell the agent's commands run in, such as `/bin/zsh`. */
|
|
47
47
|
shell: import("@sinclair/typebox").TString;
|
|
48
48
|
}>>;
|
|
49
|
-
/** Per-
|
|
50
|
-
|
|
49
|
+
/** Per-module settings, keyed by module name; each entry is opaque to the agent. */
|
|
50
|
+
modules: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>>>;
|
|
51
51
|
/** Immutable descriptive metadata, replaced only through a merged metadata update. */
|
|
52
52
|
metadata: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TObject<{
|
|
53
53
|
title: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
@@ -69,6 +69,6 @@ export declare function agentConfig(ctx: Context): AgentConfig | undefined;
|
|
|
69
69
|
export declare function agentEnvironment(ctx: Context): AgentEnvironment | undefined;
|
|
70
70
|
/** The immutable metadata describing the agent owning this context, when it has any. */
|
|
71
71
|
export declare function agentMetadata(ctx: Context): AgentMetadata | undefined;
|
|
72
|
-
/** The opaque settings the named
|
|
73
|
-
export declare function
|
|
72
|
+
/** The opaque settings the named module was configured with, if it was configured at all. */
|
|
73
|
+
export declare function agentModuleConfig(ctx: Context, name: string): AgentModuleConfig | undefined;
|
|
74
74
|
//# sourceMappingURL=AgentConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentConfig.d.ts","sourceRoot":"","sources":["../sources/AgentConfig.ts"],"names":[],"mappings":"AAEA,OAAO,EAAQ,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAA0B,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE1E,OAAO,EAAyC,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE/F,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,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Ae,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAE1E;AAED,iFAAiF;AACjF,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,WAAW,GAAG,SAAS,CAEjE;AAED,sFAAsF;AACtF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,GAAG,SAAS,CAE3E;AAED,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,aAAa,GAAG,SAAS,CAErE;AAED,6FAA6F;AAC7F,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAE3F"}
|
package/dist/AgentConfig.js
CHANGED
|
@@ -18,10 +18,10 @@ export const agentPlatformSchema = Type.Union([
|
|
|
18
18
|
Type.Literal("win32"),
|
|
19
19
|
]);
|
|
20
20
|
/**
|
|
21
|
-
* The settings one
|
|
21
|
+
* The settings one module was configured with. The agent never looks inside: a module owns
|
|
22
22
|
* the shape of its own entry and validates it against its own schema.
|
|
23
23
|
*/
|
|
24
|
-
export const
|
|
24
|
+
export const agentModuleConfigSchema = Type.Record(Type.String(), Type.Unknown());
|
|
25
25
|
/**
|
|
26
26
|
* The machine an agent works on. It is all or nothing: an agent either knows its environment
|
|
27
27
|
* completely or not at all, so nothing it is told about the machine is ever half-true.
|
|
@@ -38,15 +38,15 @@ export const agentEnvironmentSchema = Type.Object({
|
|
|
38
38
|
});
|
|
39
39
|
/**
|
|
40
40
|
* What an agent was created with: the environment it works on, when it has one, one opaque
|
|
41
|
-
* settings map per
|
|
41
|
+
* settings map per module, and descriptive metadata. Environment and module settings stay
|
|
42
42
|
* fixed; metadata changes only through the agent metadata API, which shallow-merges updates and
|
|
43
43
|
* persists the resulting complete configuration.
|
|
44
44
|
*/
|
|
45
45
|
export const agentConfigSchema = Type.Object({
|
|
46
46
|
/** The machine this agent was told it works on, when it was told anything at all. */
|
|
47
47
|
environment: Type.Optional(agentEnvironmentSchema),
|
|
48
|
-
/** Per-
|
|
49
|
-
|
|
48
|
+
/** Per-module settings, keyed by module name; each entry is opaque to the agent. */
|
|
49
|
+
modules: Type.Optional(Type.Record(Type.String(), agentModuleConfigSchema)),
|
|
50
50
|
/** Immutable descriptive metadata, replaced only through a merged metadata update. */
|
|
51
51
|
metadata: Type.Optional(agentMetadataSchema),
|
|
52
52
|
});
|
|
@@ -94,8 +94,8 @@ export function agentEnvironment(ctx) {
|
|
|
94
94
|
export function agentMetadata(ctx) {
|
|
95
95
|
return configNamespace.get(ctx)?.metadata;
|
|
96
96
|
}
|
|
97
|
-
/** The opaque settings the named
|
|
98
|
-
export function
|
|
99
|
-
return configNamespace.get(ctx)?.
|
|
97
|
+
/** The opaque settings the named module was configured with, if it was configured at all. */
|
|
98
|
+
export function agentModuleConfig(ctx, name) {
|
|
99
|
+
return configNamespace.get(ctx)?.modules?.[name];
|
|
100
100
|
}
|
|
101
101
|
//# sourceMappingURL=AgentConfig.js.map
|
package/dist/AgentConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentConfig.js","sourceRoot":"","sources":["../sources/AgentConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,OAAO,EAAE,IAAI,EAAe,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAgB,MAAM,oBAAoB,CAAC;AAE1E,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAsB,MAAM,oBAAoB,CAAC;AAE/F,uEAAuE;AACvE,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC,KAAK,CAAC;IAC1C,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;IACnB,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;IACvB,IAAI,C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CAAC"}
|
package/dist/AgentContexts.d.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import type { SessionReasoningEffort, SessionServiceTier } from "@slopus/happy-providers";
|
|
2
2
|
import { type Context } from "@steve.kite/stdlib";
|
|
3
|
+
import type { AgentDatabase } from "./AgentDatabase.js";
|
|
3
4
|
import type { AgentKV } from "./AgentKV.js";
|
|
4
5
|
import { type AgentPermissionMode } from "./AgentPermissionMode.js";
|
|
6
|
+
/** Storage-owned identity and lifetime of an active transaction facade. */
|
|
7
|
+
export interface AgentStorageTransactionContext {
|
|
8
|
+
readonly database: AgentDatabase;
|
|
9
|
+
readonly lifetime: AbortSignal;
|
|
10
|
+
readonly owner: object;
|
|
11
|
+
}
|
|
5
12
|
/**
|
|
6
13
|
* Derive the agent's context carrying its ID, provider ID, model, effort, service tier, and
|
|
7
14
|
* permission mode — all serializable values. The agent applies this once at construction, so hooks
|
|
8
15
|
* and tool executions can read the values back through the accessors below. The ID is what lets one
|
|
9
|
-
*
|
|
16
|
+
* module instance serve every agent in a collection: a shared module learns which agent a hook is
|
|
10
17
|
* running for from the context rather than from something it was constructed with.
|
|
11
18
|
*/
|
|
12
19
|
export declare function withAgentContext(ctx: Context, values: {
|
|
@@ -51,4 +58,14 @@ export declare function agentKV(ctx: Context): AgentKV | undefined;
|
|
|
51
58
|
export declare function withAgentRunKV(ctx: Context, kv: AgentKV): Context;
|
|
52
59
|
/** The run's own store carried on this context, when the agent attached one. */
|
|
53
60
|
export declare function agentRunKV(ctx: Context): AgentKV | undefined;
|
|
61
|
+
/** Carry the active Drizzle database or transaction facade on a derived context. */
|
|
62
|
+
export declare function withAgentDatabase(ctx: Context, database: AgentDatabase): Context;
|
|
63
|
+
/** The active Drizzle database or transaction facade, when this work has durable storage. */
|
|
64
|
+
export declare function agentDatabase(ctx: Context): AgentDatabase | undefined;
|
|
65
|
+
/** Install the active facade and its owning storage for the duration of one transaction callback. */
|
|
66
|
+
export declare function withAgentStorageTransaction(ctx: Context, transaction: AgentStorageTransactionContext): Context;
|
|
67
|
+
/** The storage transaction carried by this context, including its ended state when retained. */
|
|
68
|
+
export declare function agentStorageTransaction(ctx: Context): AgentStorageTransactionContext | undefined;
|
|
69
|
+
/** Drop a caller's transaction lifetime when creating independently owned agent work. */
|
|
70
|
+
export declare function withoutAgentStorageTransaction(ctx: Context): Context;
|
|
54
71
|
//# sourceMappingURL=AgentContexts.d.ts.map
|
|
@@ -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,EAA0B,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE1E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAiC,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;
|
|
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,EAA0B,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE1E,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;AAgCnG,2EAA2E;AAC3E,MAAM,WAAW,8BAA8B;IAC3C,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CAC1B;AAKD;;;;;;GAMG;AACH,wBAAgB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;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,GAAG,OAAO,CAEjE;AAED,gFAAgF;AAChF,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAE5D;AAED,oFAAoF;AACpF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAEhF;AAED,6FAA6F;AAC7F,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,aAAa,GAAG,SAAS,CAErE;AAED,qGAAqG;AACrG,wBAAgB,2BAA2B,CACvC,GAAG,EAAE,OAAO,EACZ,WAAW,EAAE,8BAA8B,GAC5C,OAAO,CAKT;AAED,gGAAgG;AAChG,wBAAgB,uBAAuB,CACnC,GAAG,EAAE,OAAO,GACb,8BAA8B,GAAG,SAAS,CAE5C;AAED,yFAAyF;AACzF,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAEpE"}
|
package/dist/AgentContexts.js
CHANGED
|
@@ -16,11 +16,14 @@ 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
|
+
/** Backing storage for the active Drizzle database or transaction facade. */
|
|
20
|
+
const databaseNamespace = createContextNamespace("agentDatabase", undefined);
|
|
21
|
+
const storageTransactionNamespace = createContextNamespace("agentStorageTransaction", undefined);
|
|
19
22
|
/**
|
|
20
23
|
* Derive the agent's context carrying its ID, provider ID, model, effort, service tier, and
|
|
21
24
|
* permission mode — all serializable values. The agent applies this once at construction, so hooks
|
|
22
25
|
* and tool executions can read the values back through the accessors below. The ID is what lets one
|
|
23
|
-
*
|
|
26
|
+
* module instance serve every agent in a collection: a shared module learns which agent a hook is
|
|
24
27
|
* running for from the context rather than from something it was constructed with.
|
|
25
28
|
*/
|
|
26
29
|
export function withAgentContext(ctx, values) {
|
|
@@ -87,4 +90,24 @@ export function withAgentRunKV(ctx, kv) {
|
|
|
87
90
|
export function agentRunKV(ctx) {
|
|
88
91
|
return runKVNamespace.get(ctx);
|
|
89
92
|
}
|
|
93
|
+
/** Carry the active Drizzle database or transaction facade on a derived context. */
|
|
94
|
+
export function withAgentDatabase(ctx, database) {
|
|
95
|
+
return databaseNamespace.set(ctx, database);
|
|
96
|
+
}
|
|
97
|
+
/** The active Drizzle database or transaction facade, when this work has durable storage. */
|
|
98
|
+
export function agentDatabase(ctx) {
|
|
99
|
+
return databaseNamespace.get(ctx);
|
|
100
|
+
}
|
|
101
|
+
/** Install the active facade and its owning storage for the duration of one transaction callback. */
|
|
102
|
+
export function withAgentStorageTransaction(ctx, transaction) {
|
|
103
|
+
return storageTransactionNamespace.set(withAgentDatabase(ctx, transaction.database), transaction);
|
|
104
|
+
}
|
|
105
|
+
/** The storage transaction carried by this context, including its ended state when retained. */
|
|
106
|
+
export function agentStorageTransaction(ctx) {
|
|
107
|
+
return storageTransactionNamespace.get(ctx);
|
|
108
|
+
}
|
|
109
|
+
/** Drop a caller's transaction lifetime when creating independently owned agent work. */
|
|
110
|
+
export function withoutAgentStorageTransaction(ctx) {
|
|
111
|
+
return storageTransactionNamespace.set(ctx, undefined);
|
|
112
|
+
}
|
|
90
113
|
//# 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,EAAgB,MAAM,oBAAoB,CAAC;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from "drizzle-orm/pg-core";
|
|
3
|
+
import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core";
|
|
4
|
+
import type { Context } from "@steve.kite/stdlib";
|
|
5
|
+
/**
|
|
6
|
+
* Any asynchronous Drizzle SQLite database or transaction. The erased schema and result types
|
|
7
|
+
* deliberately preserve the complete Drizzle query-builder surface without choosing a driver.
|
|
8
|
+
*/
|
|
9
|
+
export type AgentSQLiteDatabase = BaseSQLiteDatabase<"async", any, any, any>;
|
|
10
|
+
/**
|
|
11
|
+
* Any Drizzle PostgreSQL database or transaction, including PGlite. The concrete module generic
|
|
12
|
+
* retains the caller's exact database type when a module needs its own typed schema.
|
|
13
|
+
*/
|
|
14
|
+
export type AgentPostgresDatabase = PgDatabase<any, any, any>;
|
|
15
|
+
/** A supported engine-agnostic Drizzle database or active transaction facade. */
|
|
16
|
+
export type AgentDatabase = AgentSQLiteDatabase | AgentPostgresDatabase;
|
|
17
|
+
/**
|
|
18
|
+
* The schema-aware Drizzle surface shared by a concrete root database and its transaction.
|
|
19
|
+
* Driver-only root members such as `batch` and `$client` are intentionally absent.
|
|
20
|
+
*/
|
|
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
|
+
/** One ordered, durably tracked module migration. */
|
|
23
|
+
export type AgentModuleMigration<Database extends AgentDatabase = AgentDatabase> = readonly [
|
|
24
|
+
key: string,
|
|
25
|
+
migrate: (ctx: Context, database: AgentDatabaseFacade<Database>) => void | Promise<void>
|
|
26
|
+
];
|
|
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
|
+
/** Whether a supported facade belongs to Drizzle's SQLite family. */
|
|
30
|
+
export declare function isAgentSQLiteDatabase(database: AgentDatabase): database is AgentSQLiteDatabase;
|
|
31
|
+
/** Run a query that returns rows on either supported Drizzle engine. */
|
|
32
|
+
export declare function agentDatabaseRows<Row>(database: AgentDatabase, query: SQL): Promise<readonly Row[]>;
|
|
33
|
+
/** Run a statement that does not need its returned rows. */
|
|
34
|
+
export declare function agentDatabaseRun(database: AgentDatabase, query: SQL): Promise<void>;
|
|
35
|
+
//# sourceMappingURL=AgentDatabase.d.ts.map
|
|
@@ -0,0 +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,EA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
|
4
|
+
/** Whether a supported facade belongs to Drizzle's SQLite family. */
|
|
5
|
+
export function isAgentSQLiteDatabase(database) {
|
|
6
|
+
return is(database, BaseSQLiteDatabase);
|
|
7
|
+
}
|
|
8
|
+
/** Run a query that returns rows on either supported Drizzle engine. */
|
|
9
|
+
export async function agentDatabaseRows(database, query) {
|
|
10
|
+
if (isAgentSQLiteDatabase(database)) {
|
|
11
|
+
return await database.all(query);
|
|
12
|
+
}
|
|
13
|
+
const result = await database.execute(query);
|
|
14
|
+
if (Array.isArray(result))
|
|
15
|
+
return result;
|
|
16
|
+
const rows = Reflect.get(result, "rows");
|
|
17
|
+
if (!Array.isArray(rows)) {
|
|
18
|
+
throw new Error("The PostgreSQL Drizzle query did not return a row collection.");
|
|
19
|
+
}
|
|
20
|
+
return rows;
|
|
21
|
+
}
|
|
22
|
+
/** Run a statement that does not need its returned rows. */
|
|
23
|
+
export async function agentDatabaseRun(database, query) {
|
|
24
|
+
if (isAgentSQLiteDatabase(database)) {
|
|
25
|
+
await database.run(query);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
await database.execute(query);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=AgentDatabase.js.map
|
|
@@ -0,0 +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;AAgD7D,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/AgentKV.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { type Context } from "@steve.kite/stdlib";
|
|
1
|
+
import { type AsyncLock, type Context } from "@steve.kite/stdlib";
|
|
2
2
|
import type { AgentPersistence } from "./AgentPersistence.js";
|
|
3
3
|
/**
|
|
4
4
|
* A key-value store scoped under one prefix of the agent's sorted store. The agent carries a
|
|
5
|
-
* session-scoped instance on its context, and narrows it for each caller: a
|
|
5
|
+
* session-scoped instance on its context, and narrows it for each caller: a module works
|
|
6
6
|
* under its own name, a tool execution under its call ID. Keys are always relative to the
|
|
7
7
|
* scope — a holder can neither see nor touch anything outside it. Segments join with `.`.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* Every operation runs on the context it is given, so that context decides which transaction a
|
|
10
|
+
* write joins. Most handles also take their lifetime from that context; explicitly bounded
|
|
11
|
+
* handles, such as a tool call's KV, additionally become unusable when their owner ends.
|
|
12
12
|
*/
|
|
13
13
|
export declare class AgentKV {
|
|
14
14
|
#private;
|
|
15
15
|
/** The absolute key prefix of this scope, ending with the separator. */
|
|
16
16
|
readonly prefix: string;
|
|
17
17
|
/** Build a scope over `prefix` of `persistence`. */
|
|
18
|
-
constructor(persistence: AgentPersistence, prefix: string);
|
|
18
|
+
constructor(persistence: AgentPersistence, prefix: string, available?: () => boolean, lock?: AsyncLock);
|
|
19
19
|
/**
|
|
20
20
|
* A narrower store under `segments` within this scope. Each segment is exactly one level:
|
|
21
21
|
* a dot inside a segment is escaped, so the scope `alpha.beta` cannot be reached through
|
|
@@ -23,6 +23,12 @@ export declare class AgentKV {
|
|
|
23
23
|
* their segment lists differ.
|
|
24
24
|
*/
|
|
25
25
|
scoped(...segments: readonly string[]): AgentKV;
|
|
26
|
+
/**
|
|
27
|
+
* A handle to this exact scope that becomes permanently unusable when `signal` aborts.
|
|
28
|
+
* Narrower scopes inherit the same bound. Agent base uses this for call KV so no context can
|
|
29
|
+
* recreate invocation state after the winning result erases it.
|
|
30
|
+
*/
|
|
31
|
+
until(signal: AbortSignal, available?: () => boolean): AgentKV;
|
|
26
32
|
/** The stored value, or undefined when the key is absent. */
|
|
27
33
|
read(ctx: Context, key: string): Promise<unknown>;
|
|
28
34
|
/** Every entry under the scope — or under `prefix` within it — with scope-relative keys. */
|
|
@@ -38,6 +44,13 @@ export declare class AgentKV {
|
|
|
38
44
|
* updater that throws leaves the stored value untouched.
|
|
39
45
|
*/
|
|
40
46
|
update<Value>(ctx: Context, key: string, updater: (current: unknown) => Value | Promise<Value>): Promise<Value>;
|
|
47
|
+
/**
|
|
48
|
+
* Return the durable value already stored under `key`, or create and store it exactly once.
|
|
49
|
+
* The read and possible write share one persistence transaction, and an existing outer
|
|
50
|
+
* transaction is reused. A tool can use this on its call-bound KV for retry-stable operation
|
|
51
|
+
* identities without coupling them to a provider call ID.
|
|
52
|
+
*/
|
|
53
|
+
getOrCreate<Value>(ctx: Context, key: string, create: () => Value | Promise<Value>): Promise<Value>;
|
|
41
54
|
/**
|
|
42
55
|
* Run work as one atomic step of the underlying store: everything it writes commits together,
|
|
43
56
|
* and a thrown error leaves the store exactly as it was. The work is given this same scope and
|
package/dist/AgentKV.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentKV.d.ts","sourceRoot":"","sources":["../sources/AgentKV.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"AgentKV.d.ts","sourceRoot":"","sources":["../sources/AgentKV.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,SAAS,EAAE,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE3F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;;;;;;;GASG;AACH,qBAAa,OAAO;;IAChB,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IASxB,oDAAoD;IACpD,YACI,WAAW,EAAE,gBAAgB,EAC7B,MAAM,EAAE,MAAM,EACd,SAAS,gBAAa,EACtB,IAAI,CAAC,EAAE,SAAS,EAMnB;IAkBD;;;;;OAKG;IACH,MAAM,CAAC,GAAG,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAU9C;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,gBAAa,GAAG,OAAO,CAO1D;IAED,6DAA6D;IACvD,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMtD;IAED,4FAA4F;IACtF,IAAI,CACN,GAAG,EAAE,OAAO,EACZ,MAAM,SAAK,GACZ,OAAO,CAAC,SAAS;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC,CAQvE;IAED,wEAAwE;IAClE,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAIpE;IAED;;;;OAIG;IACG,MAAM,CAAC,KAAK,EACd,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GACtD,OAAO,CAAC,KAAK,CAAC,CAShB;IAED;;;;;OAKG;IACG,WAAW,CAAC,KAAK,EACnB,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GACrC,OAAO,CAAC,KAAK,CAAC,CAoBhB;IAED;;;;;OAKG;IACG,WAAW,CAAC,MAAM,EACpB,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,GACvD,OAAO,CAAC,MAAM,CAAC,CAWjB;IAED;;;;;OAKG;IACG,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAOvC;IAED,mDAAmD;IAC7C,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIrD;CAwBJ"}
|
package/dist/AgentKV.js
CHANGED
|
@@ -1,35 +1,39 @@
|
|
|
1
|
-
import { withLifetime } from "@steve.kite/stdlib";
|
|
2
|
-
/**
|
|
3
|
-
* Refuse a store operation whose context has already ended. What a holder of a store may do is
|
|
4
|
-
* decided by the context it is given rather than by the object: a store used inside a transaction,
|
|
5
|
-
* or handed to a tool for the length of its turn, keeps working exactly as long as that work
|
|
6
|
-
* does. Using it afterwards is a mistake in the caller, and says so instead of quietly writing
|
|
7
|
-
* into a transaction that has committed or a turn that was cancelled.
|
|
8
|
-
*/
|
|
9
|
-
function assertLive(ctx) {
|
|
10
|
-
if (ctx.lifetime?.aborted === true) {
|
|
11
|
-
throw new Error("The store cannot be used: the work its context belongs to has ended.");
|
|
12
|
-
}
|
|
13
|
-
}
|
|
1
|
+
import { asyncLock, withLifetime } from "@steve.kite/stdlib";
|
|
14
2
|
/**
|
|
15
3
|
* A key-value store scoped under one prefix of the agent's sorted store. The agent carries a
|
|
16
|
-
* session-scoped instance on its context, and narrows it for each caller: a
|
|
4
|
+
* session-scoped instance on its context, and narrows it for each caller: a module works
|
|
17
5
|
* under its own name, a tool execution under its call ID. Keys are always relative to the
|
|
18
6
|
* scope — a holder can neither see nor touch anything outside it. Segments join with `.`.
|
|
19
7
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
8
|
+
* Every operation runs on the context it is given, so that context decides which transaction a
|
|
9
|
+
* write joins. Most handles also take their lifetime from that context; explicitly bounded
|
|
10
|
+
* handles, such as a tool call's KV, additionally become unusable when their owner ends.
|
|
23
11
|
*/
|
|
24
12
|
export class AgentKV {
|
|
25
13
|
/** The absolute key prefix of this scope, ending with the separator. */
|
|
26
14
|
prefix;
|
|
27
15
|
/** The append-only store this scope reads and writes through. */
|
|
28
16
|
#persistence;
|
|
17
|
+
/** An object-owned lifetime used by bounded stores such as one tool invocation's KV. */
|
|
18
|
+
#available;
|
|
19
|
+
/** Serializes this scope tree so disposal always follows every write that already started. */
|
|
20
|
+
#lock;
|
|
29
21
|
/** Build a scope over `prefix` of `persistence`. */
|
|
30
|
-
constructor(persistence, prefix) {
|
|
22
|
+
constructor(persistence, prefix, available = () => true, lock) {
|
|
31
23
|
this.#persistence = persistence;
|
|
32
24
|
this.prefix = prefix;
|
|
25
|
+
this.#available = available;
|
|
26
|
+
this.#lock = lock;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A handle to this scope whose operations serialize with all descendants derived from it.
|
|
30
|
+
* Agent base uses this only for one tool call, so disposal can drain writes already in flight
|
|
31
|
+
* without serializing unrelated module and agent stores.
|
|
32
|
+
*
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
serialized() {
|
|
36
|
+
return new AgentKV(this.#persistence, this.prefix, this.#available, asyncLock({ reentry: "block" }));
|
|
33
37
|
}
|
|
34
38
|
/**
|
|
35
39
|
* A narrower store under `segments` within this scope. Each segment is exactly one level:
|
|
@@ -39,25 +43,39 @@ export class AgentKV {
|
|
|
39
43
|
*/
|
|
40
44
|
scoped(...segments) {
|
|
41
45
|
const escaped = segments.map((segment) => segment.replaceAll("%", "%25").replaceAll(".", "%2E"));
|
|
42
|
-
return new AgentKV(this.#persistence, `${this.prefix}${escaped.join(".")}
|
|
46
|
+
return new AgentKV(this.#persistence, `${this.prefix}${escaped.join(".")}.`, this.#available, this.#lock);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A handle to this exact scope that becomes permanently unusable when `signal` aborts.
|
|
50
|
+
* Narrower scopes inherit the same bound. Agent base uses this for call KV so no context can
|
|
51
|
+
* recreate invocation state after the winning result erases it.
|
|
52
|
+
*/
|
|
53
|
+
until(signal, available = () => true) {
|
|
54
|
+
return new AgentKV(this.#persistence, this.prefix, () => this.#available() && !signal.aborted && available(), this.#lock);
|
|
43
55
|
}
|
|
44
56
|
/** The stored value, or undefined when the key is absent. */
|
|
45
57
|
async read(ctx, key) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
return await this.#locked(ctx, async (lockCtx) => {
|
|
59
|
+
const full = `${this.prefix}${key}`;
|
|
60
|
+
const entries = await this.#persistence.readValues(lockCtx, full);
|
|
61
|
+
return entries.find((entry) => entry.key === full)?.value;
|
|
62
|
+
});
|
|
50
63
|
}
|
|
51
64
|
/** Every entry under the scope — or under `prefix` within it — with scope-relative keys. */
|
|
52
65
|
async list(ctx, prefix = "") {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
66
|
+
return await this.#locked(ctx, async (lockCtx) => {
|
|
67
|
+
const entries = await this.#persistence.readValues(lockCtx, `${this.prefix}${prefix}`);
|
|
68
|
+
return entries.map(({ key, value }) => ({
|
|
69
|
+
key: key.slice(this.prefix.length),
|
|
70
|
+
value,
|
|
71
|
+
}));
|
|
72
|
+
});
|
|
56
73
|
}
|
|
57
74
|
/** Store the value under `key`, replacing whatever was there before. */
|
|
58
75
|
async write(ctx, key, value) {
|
|
59
|
-
|
|
60
|
-
|
|
76
|
+
await this.#locked(ctx, async (lockCtx) => {
|
|
77
|
+
await this.#persistence.writeValue(lockCtx, `${this.prefix}${key}`, value);
|
|
78
|
+
});
|
|
61
79
|
}
|
|
62
80
|
/**
|
|
63
81
|
* Read, decide, and write, so the value the updater sees is exactly the value it replaces.
|
|
@@ -65,13 +83,39 @@ export class AgentKV {
|
|
|
65
83
|
* updater that throws leaves the stored value untouched.
|
|
66
84
|
*/
|
|
67
85
|
async update(ctx, key, updater) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
86
|
+
return await this.#locked(ctx, async (lockCtx) => {
|
|
87
|
+
const full = `${this.prefix}${key}`;
|
|
88
|
+
const entries = await this.#persistence.readValues(lockCtx, full);
|
|
89
|
+
const current = entries.find((entry) => entry.key === full)?.value;
|
|
90
|
+
const next = await updater(current);
|
|
91
|
+
await this.#persistence.writeValue(lockCtx, full, next);
|
|
92
|
+
return next;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Return the durable value already stored under `key`, or create and store it exactly once.
|
|
97
|
+
* The read and possible write share one persistence transaction, and an existing outer
|
|
98
|
+
* transaction is reused. A tool can use this on its call-bound KV for retry-stable operation
|
|
99
|
+
* identities without coupling them to a provider call ID.
|
|
100
|
+
*/
|
|
101
|
+
async getOrCreate(ctx, key, create) {
|
|
102
|
+
return await this.#locked(ctx, async (lockCtx) => {
|
|
103
|
+
return await this.#persistence.transaction(lockCtx, async (txCtx) => {
|
|
104
|
+
const full = `${this.prefix}${key}`;
|
|
105
|
+
const entries = await this.#persistence.readValues(txCtx, full);
|
|
106
|
+
const existing = entries.find((entry) => entry.key === full);
|
|
107
|
+
if (existing !== undefined)
|
|
108
|
+
return existing.value;
|
|
109
|
+
const value = await create();
|
|
110
|
+
if (await this.#persistence.writeValueIfAbsent(txCtx, full, value))
|
|
111
|
+
return value;
|
|
112
|
+
const winner = (await this.#persistence.readValues(txCtx, full)).find((entry) => entry.key === full);
|
|
113
|
+
if (winner === undefined) {
|
|
114
|
+
throw new Error("The durable get-or-create value disappeared before it was read.");
|
|
115
|
+
}
|
|
116
|
+
return winner.value;
|
|
117
|
+
});
|
|
118
|
+
});
|
|
75
119
|
}
|
|
76
120
|
/**
|
|
77
121
|
* Run work as one atomic step of the underlying store: everything it writes commits together,
|
|
@@ -80,7 +124,7 @@ export class AgentKV {
|
|
|
80
124
|
* cannot be written into after it has committed.
|
|
81
125
|
*/
|
|
82
126
|
async transaction(ctx, work) {
|
|
83
|
-
assertLive(ctx);
|
|
127
|
+
this.#assertLive(ctx);
|
|
84
128
|
return await this.#persistence.transaction(ctx, async (txCtx) => {
|
|
85
129
|
const committed = new AbortController();
|
|
86
130
|
const liveCtx = withLifetime(txCtx, committed.signal);
|
|
@@ -99,16 +143,39 @@ export class AgentKV {
|
|
|
99
143
|
* write.
|
|
100
144
|
*/
|
|
101
145
|
async clear(ctx) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
146
|
+
await this.#locked(ctx, async (lockCtx) => {
|
|
147
|
+
const entries = await this.#persistence.readValues(lockCtx, this.prefix);
|
|
148
|
+
for (const entry of entries) {
|
|
149
|
+
await this.#persistence.deleteValue(lockCtx, entry.key);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
107
152
|
}
|
|
108
153
|
/** Remove the entry stored under `key`, if any. */
|
|
109
154
|
async delete(ctx, key) {
|
|
110
|
-
|
|
111
|
-
|
|
155
|
+
await this.#locked(ctx, async (lockCtx) => {
|
|
156
|
+
await this.#persistence.deleteValue(lockCtx, `${this.prefix}${key}`);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/** Re-check availability only after every earlier operation in this scope tree has finished. */
|
|
160
|
+
async #locked(ctx, work) {
|
|
161
|
+
if (this.#lock === undefined) {
|
|
162
|
+
this.#assertLive(ctx);
|
|
163
|
+
return await work(ctx);
|
|
164
|
+
}
|
|
165
|
+
return await this.#lock.runInLock(ctx, async (lockCtx) => {
|
|
166
|
+
this.#assertLive(lockCtx);
|
|
167
|
+
return await work(lockCtx);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Refuse a store operation when either its caller-owned context or this bounded handle has
|
|
172
|
+
* ended. The latter is what makes call KV stay erased even if retained code supplies a fresh
|
|
173
|
+
* unrelated context after commit.
|
|
174
|
+
*/
|
|
175
|
+
#assertLive(ctx) {
|
|
176
|
+
if (ctx.lifetime?.aborted === true || !this.#available()) {
|
|
177
|
+
throw new Error("The store cannot be used: the work its context belongs to has ended.");
|
|
178
|
+
}
|
|
112
179
|
}
|
|
113
180
|
}
|
|
114
181
|
//# sourceMappingURL=AgentKV.js.map
|
package/dist/AgentKV.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentKV.js","sourceRoot":"","sources":["../sources/AgentKV.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"AgentKV.js","sourceRoot":"","sources":["../sources/AgentKV.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAgC,MAAM,oBAAoB,CAAC;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B,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,GAAY;QACpB,IAAI,GAAG,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;YACvD,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;QAC5F,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The outcome of offering one caller-identified message to an agent. */
|
|
2
|
+
export interface AgentMessageAcceptance {
|
|
3
|
+
/** The caller-supplied or Base-generated cuid2 identity. */
|
|
4
|
+
readonly id: string;
|
|
5
|
+
/** Which delivery queue accepted the message. */
|
|
6
|
+
readonly delivery: "send" | "steer";
|
|
7
|
+
/**
|
|
8
|
+
* Whether this identity was inserted now or was already known. This is the durable result
|
|
9
|
+
* unless the caller explicitly requests non-waiting delivery; in that mode Base returns the
|
|
10
|
+
* current process's immediate reservation. The target's own loop always uses that mode.
|
|
11
|
+
*/
|
|
12
|
+
readonly accepted: "created" | "existing";
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=AgentMessageAcceptance.d.ts.map
|