@slopus/happy-agent-base 0.0.6 → 0.0.8

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.
Files changed (94) hide show
  1. package/README.md +52 -11
  2. package/dist/Agent.d.ts +24 -22
  3. package/dist/Agent.d.ts.map +1 -1
  4. package/dist/Agent.js +113 -111
  5. package/dist/Agent.js.map +1 -1
  6. package/dist/AgentBase.d.ts +18 -14
  7. package/dist/AgentBase.d.ts.map +1 -1
  8. package/dist/AgentBase.js +486 -122
  9. package/dist/AgentBase.js.map +1 -1
  10. package/dist/AgentBaseHooks.d.ts +41 -28
  11. package/dist/AgentBaseHooks.d.ts.map +1 -1
  12. package/dist/AgentBasePending.d.ts +6 -2
  13. package/dist/AgentBasePending.d.ts.map +1 -1
  14. package/dist/AgentBasePending.js +7 -0
  15. package/dist/AgentBasePending.js.map +1 -1
  16. package/dist/AgentConfig.d.ts +9 -9
  17. package/dist/AgentConfig.d.ts.map +1 -1
  18. package/dist/AgentConfig.js +8 -8
  19. package/dist/AgentConfig.js.map +1 -1
  20. package/dist/AgentContexts.d.ts +25 -1
  21. package/dist/AgentContexts.d.ts.map +1 -1
  22. package/dist/AgentContexts.js +46 -2
  23. package/dist/AgentContexts.js.map +1 -1
  24. package/dist/AgentDatabase.d.ts +35 -0
  25. package/dist/AgentDatabase.d.ts.map +1 -0
  26. package/dist/AgentDatabase.js +30 -0
  27. package/dist/AgentDatabase.js.map +1 -0
  28. package/dist/AgentKV.d.ts +19 -6
  29. package/dist/AgentKV.d.ts.map +1 -1
  30. package/dist/AgentKV.js +110 -43
  31. package/dist/AgentKV.js.map +1 -1
  32. package/dist/AgentMessageAcceptance.d.ts +14 -0
  33. package/dist/AgentMessageAcceptance.d.ts.map +1 -0
  34. package/dist/AgentMessageAcceptance.js +2 -0
  35. package/dist/AgentMessageAcceptance.js.map +1 -0
  36. package/dist/AgentMetadata.d.ts +3 -3
  37. package/dist/AgentMetadata.js +3 -3
  38. package/dist/AgentModule.d.ts +209 -0
  39. package/dist/AgentModule.d.ts.map +1 -0
  40. package/dist/AgentModule.js +2 -0
  41. package/dist/AgentModule.js.map +1 -0
  42. package/dist/{AgentFeatureAction.d.ts → AgentModuleAction.d.ts} +2 -2
  43. package/dist/AgentModuleAction.d.ts.map +1 -0
  44. package/dist/AgentModuleAction.js +2 -0
  45. package/dist/AgentModuleAction.js.map +1 -0
  46. package/dist/AgentPermissionMode.d.ts +1 -1
  47. package/dist/AgentPermissionMode.js +1 -1
  48. package/dist/AgentPersistence.d.ts +7 -4
  49. package/dist/AgentPersistence.d.ts.map +1 -1
  50. package/dist/AgentPersistenceDrizzle.d.ts +29 -0
  51. package/dist/AgentPersistenceDrizzle.d.ts.map +1 -0
  52. package/dist/AgentPersistenceDrizzle.js +112 -0
  53. package/dist/AgentPersistenceDrizzle.js.map +1 -0
  54. package/dist/AgentRef.d.ts +12 -9
  55. package/dist/AgentRef.d.ts.map +1 -1
  56. package/dist/AgentRef.js +8 -8
  57. package/dist/AgentRef.js.map +1 -1
  58. package/dist/AgentStorage.d.ts +26 -12
  59. package/dist/AgentStorage.d.ts.map +1 -1
  60. package/dist/AgentStorage.js +90 -3
  61. package/dist/AgentStorage.js.map +1 -1
  62. package/dist/AgentSystem.d.ts +10 -7
  63. package/dist/AgentSystem.d.ts.map +1 -1
  64. package/dist/AgentSystemContext.d.ts +5 -4
  65. package/dist/AgentSystemContext.d.ts.map +1 -1
  66. package/dist/AgentSystemContext.js +4 -4
  67. package/dist/AgentSystemContext.js.map +1 -1
  68. package/dist/AgentSystemLocal.d.ts +17 -14
  69. package/dist/AgentSystemLocal.d.ts.map +1 -1
  70. package/dist/AgentSystemLocal.js +120 -29
  71. package/dist/AgentSystemLocal.js.map +1 -1
  72. package/dist/AgentSystemRef.d.ts +9 -7
  73. package/dist/AgentSystemRef.d.ts.map +1 -1
  74. package/dist/AgentSystemRef.js +17 -4
  75. package/dist/AgentSystemRef.js.map +1 -1
  76. package/dist/AgentTool.d.ts +24 -2
  77. package/dist/AgentTool.d.ts.map +1 -1
  78. package/dist/AgentTool.js.map +1 -1
  79. package/dist/inTx.d.ts +17 -0
  80. package/dist/inTx.d.ts.map +1 -0
  81. package/dist/inTx.js +65 -0
  82. package/dist/inTx.js.map +1 -0
  83. package/dist/index.d.ts +9 -6
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +8 -5
  86. package/dist/index.js.map +1 -1
  87. package/package.json +4 -3
  88. package/dist/AgentFeature.d.ts +0 -184
  89. package/dist/AgentFeature.d.ts.map +0 -1
  90. package/dist/AgentFeature.js +0 -2
  91. package/dist/AgentFeature.js.map +0 -1
  92. package/dist/AgentFeatureAction.d.ts.map +0 -1
  93. package/dist/AgentFeatureAction.js +0 -2
  94. package/dist/AgentFeatureAction.js.map +0 -1
@@ -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 feature was configured with. The agent never looks inside: a feature owns
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 agentFeatureConfigSchema: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>;
13
- /** The TypeScript type inferred from {@link agentFeatureConfigSchema}. */
14
- export type AgentFeatureConfig = Static<typeof agentFeatureConfigSchema>;
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 feature, and descriptive metadata. Environment and feature settings stay
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-feature settings, keyed by feature name; each entry is opaque to the agent. */
50
- features: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>>>;
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 feature was configured with, if it was configured at all. */
73
- export declare function agentFeatureConfig(ctx: Context, name: string): AgentFeatureConfig | undefined;
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,kjBAY9B,CAAC;AAEH,qEAAqE;AACrE,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE/D;;;GAGG;AACH,eAAO,MAAM,wBAAwB,gHAA6C,CAAC;AAEnF,0EAA0E;AAC1E,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAEzE;;;GAGG;AACH,eAAO,MAAM,sBAAsB;IAC/B,wEAAwE;;IAExE,8CAA8C;;IAE9C,uDAAuD;;IAEvD,iEAAiE;;EAEnE,CAAC;AAEH,wEAAwE;AACxE,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAErE;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB;IAC1B,qFAAqF;;QApBrF,wEAAwE;;QAExE,8CAA8C;;QAE9C,uDAAuD;;QAEvD,iEAAiE;;;IAgBjE,sFAAsF;;IAEtF,sFAAsF;;;;EAExF,CAAC;AAEH,mEAAmE;AACnE,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAe3D;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,gBAAgB,CAQ1D;AAQD,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,G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,8CAA8C;;QAE9C,uDAAuD;;QAEvD,iEAAiE;;;IAgBjE,oFAAoF;;IAEpF,sFAAsF;;;;EAExF,CAAC;AAEH,mEAAmE;AACnE,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAe3D;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,gBAAgB,CAQ1D;AAQD,kFAAkF;AAClF,wBAAgB,eAAe,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"}
@@ -18,10 +18,10 @@ export const agentPlatformSchema = Type.Union([
18
18
  Type.Literal("win32"),
19
19
  ]);
20
20
  /**
21
- * The settings one feature was configured with. The agent never looks inside: a feature owns
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 agentFeatureConfigSchema = Type.Record(Type.String(), Type.Unknown());
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 feature, and descriptive metadata. Environment and feature settings stay
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-feature settings, keyed by feature name; each entry is opaque to the agent. */
49
- features: Type.Optional(Type.Record(Type.String(), agentFeatureConfigSchema)),
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 feature was configured with, if it was configured at all. */
98
- export function agentFeatureConfig(ctx, name) {
99
- return configNamespace.get(ctx)?.features?.[name];
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
@@ -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,IAA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
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 root: AgentDatabase;
10
+ readonly lifetime: AbortSignal;
11
+ }
12
+ declare global {
13
+ namespace stdlib {
14
+ interface ContextExtensions {
15
+ readonly db: AgentDatabase;
16
+ }
17
+ }
18
+ }
5
19
  /**
6
20
  * Derive the agent's context carrying its ID, provider ID, model, effort, service tier, and
7
21
  * permission mode — all serializable values. The agent applies this once at construction, so hooks
8
22
  * and tool executions can read the values back through the accessors below. The ID is what lets one
9
- * feature instance serve every agent in a collection: a shared feature learns which agent a hook is
23
+ * module instance serve every agent in a collection: a shared module learns which agent a hook is
10
24
  * running for from the context rather than from something it was constructed with.
11
25
  */
12
26
  export declare function withAgentContext(ctx: Context, values: {
@@ -51,4 +65,14 @@ export declare function agentKV(ctx: Context): AgentKV | undefined;
51
65
  export declare function withAgentRunKV(ctx: Context, kv: AgentKV): Context;
52
66
  /** The run's own store carried on this context, when the agent attached one. */
53
67
  export declare function agentRunKV(ctx: Context): AgentKV | undefined;
68
+ /** Carry the active Drizzle database or transaction facade on a derived context. */
69
+ export declare function withAgentDatabase(ctx: Context, database: AgentDatabase): Context;
70
+ /** The active Drizzle database or transaction facade, when this work has durable storage. */
71
+ export declare function agentDatabase(ctx: Context): AgentDatabase | undefined;
72
+ /** Install the active facade for the duration of one transaction callback. */
73
+ export declare function withAgentStorageTransaction(ctx: Context, transaction: AgentStorageTransactionContext): Context;
74
+ /** The storage transaction carried by this context, including its ended state when retained. */
75
+ export declare function agentStorageTransaction(ctx: Context): AgentStorageTransactionContext | undefined;
76
+ /** Drop a caller's transaction lifetime when creating independently owned agent work. */
77
+ export declare function withoutAgentStorageTransaction(ctx: Context): Context;
54
78
  //# 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;AA4BnG;;;;;;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,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IACtD,QAAQ,CAAC,cAAc,EAAE,mBAAmB,CAAC;CAChD,GACF,OAAO,CAOT;AAED,+CAA+C;AAC/C,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAExD;AAED,gFAAgF;AAChF,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAE3D;AAED,2FAA2F;AAC3F,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,sBAAsB,GAAG,SAAS,CAE5E;AAED,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAE9D;AAED,uFAAuF;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G,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,GAAG,OAAO,CAE9D;AAED,uFAAuF;AACvF,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAEzD;AAED;;;;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,CAShF;AAED,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"}
@@ -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,11 +16,23 @@ 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
+ const databaseNamespace = createContextNamespace("agentDatabase", undefined);
20
+ const storageTransactionNamespace = createContextNamespace("agentStorageTransaction", undefined);
21
+ registerContextExtension("db", (ctx) => {
22
+ const transaction = storageTransactionNamespace.get(ctx);
23
+ if (transaction?.lifetime.aborted === true) {
24
+ throw new Error("The agent storage transaction carried by this context has ended.");
25
+ }
26
+ const database = databaseNamespace.get(ctx);
27
+ if (database === undefined)
28
+ throw new Error("Context has no agent database.");
29
+ return database;
30
+ });
19
31
  /**
20
32
  * Derive the agent's context carrying its ID, provider ID, model, effort, service tier, and
21
33
  * permission mode — all serializable values. The agent applies this once at construction, so hooks
22
34
  * and tool executions can read the values back through the accessors below. The ID is what lets one
23
- * feature instance serve every agent in a collection: a shared feature learns which agent a hook is
35
+ * module instance serve every agent in a collection: a shared module learns which agent a hook is
24
36
  * running for from the context rather than from something it was constructed with.
25
37
  */
26
38
  export function withAgentContext(ctx, values) {
@@ -87,4 +99,36 @@ export function withAgentRunKV(ctx, kv) {
87
99
  export function agentRunKV(ctx) {
88
100
  return runKVNamespace.get(ctx);
89
101
  }
102
+ /** Carry the active Drizzle database or transaction facade on a derived context. */
103
+ export function withAgentDatabase(ctx, database) {
104
+ const transaction = storageTransactionNamespace.get(ctx);
105
+ if (transaction !== undefined &&
106
+ (database === transaction.database || database === transaction.root)) {
107
+ return ctx;
108
+ }
109
+ return databaseNamespace.set(storageTransactionNamespace.set(ctx, undefined), database);
110
+ }
111
+ /** The active Drizzle database or transaction facade, when this work has durable storage. */
112
+ export function agentDatabase(ctx) {
113
+ return databaseNamespace.get(ctx);
114
+ }
115
+ /** Install the active facade for the duration of one transaction callback. */
116
+ export function withAgentStorageTransaction(ctx, transaction) {
117
+ if (databaseNamespace.get(ctx) !== transaction.root) {
118
+ throw new Error("A transaction context cannot be used with another agent storage.");
119
+ }
120
+ return storageTransactionNamespace.set(databaseNamespace.set(ctx, transaction.database), transaction);
121
+ }
122
+ /** The storage transaction carried by this context, including its ended state when retained. */
123
+ export function agentStorageTransaction(ctx) {
124
+ return storageTransactionNamespace.get(ctx);
125
+ }
126
+ /** Drop a caller's transaction lifetime when creating independently owned agent work. */
127
+ export function withoutAgentStorageTransaction(ctx) {
128
+ const transaction = storageTransactionNamespace.get(ctx);
129
+ const withoutTransaction = storageTransactionNamespace.set(ctx, undefined);
130
+ return transaction === undefined
131
+ ? withoutTransaction
132
+ : databaseNamespace.set(withoutTransaction, transaction.root);
133
+ }
90
134
  //# 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;AAG1E,OAAO,EAAE,6BAA6B,EAA4B,MAAM,0BAA0B,CAAC;AAEnG,2EAA2E;AAC3E,MAAM,WAAW,GAAG,sBAAsB,CAAqB,SAAS,EAAE,SAAS,CAAC,CAAC;AACrF,8FAA8F;AAC9F,MAAM,cAAc,GAAG,sBAAsB,CAAqB,YAAY,EAAE,SAAS,CAAC,CAAC;AAC3F,4FAA4F;AAC5F,MAAM,eAAe,GAAG,sBAAsB,CAC1C,aAAa,EACb,SAAS,CACZ,CAAC;AACF,6FAA6F;AAC7F,MAAM,iBAAiB,GAAG,sBAAsB,CAAqB,eAAe,EAAE,SAAS,CAAC,CAAC;AACjG,6FAA6F;AAC7F,MAAM,oBAAoB,GAAG,sBAAsB,CAC/C,kBAAkB,EAClB,SAAS,CACZ,CAAC;AACF,2FAA2F;AAC3F,MAAM,uBAAuB,GAAG,sBAAsB,CAClD,qBAAqB,EACrB,6BAA6B,CAChC,CAAC;AACF,sFAAsF;AACtF,MAAM,WAAW,GAAG,sBAAsB,CAAsB,SAAS,EAAE,SAAS,CAAC,CAAC;AACtF,4FAA4F;AAC5F,MAAM,cAAc,GAAG,sBAAsB,CAAsB,YAAY,EAAE,SAAS,CAAC,CAAC;AAE5F;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,C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E,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,2BAA2B,CAAC,GAAG,CAClC,iBAAiB,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW,CAAC,QAAQ,CAAC,EAChD,WAAW,CACd,CAAC;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"}
@@ -0,0 +1,35 @@
1
+ import { type SQL } from "drizzle-orm";
2
+ import { PgDatabase } 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,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,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"}
@@ -0,0 +1,30 @@
1
+ import { is } from "drizzle-orm";
2
+ import { PgDatabase } from "drizzle-orm/pg-core";
3
+ import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core";
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 feature works
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
- * The object is nothing but a scope: every operation runs on the context it is given, so which
10
- * transaction a write joins and how long the handle stays usable are both decided by that
11
- * context and never by the handle.
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
@@ -1 +1 @@
1
- {"version":3,"file":"AgentKV.d.ts","sourceRoot":"","sources":["../sources/AgentKV.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAe9D;;;;;;;;;GASG;AACH,qBAAa,OAAO;;IAChB,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAKxB,oDAAoD;IACpD,YAAY,WAAW,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAGxD;IAED;;;;;OAKG;IACH,MAAM,CAAC,GAAG,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAK9C;IAED,6DAA6D;IACvD,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAKtD;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,CAIvE;IAED,wEAAwE;IAClE,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAGpE;IAED;;;;OAIG;IACG,MAAM,CAAC,KAAK,EACd,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,CAAC,OAAO,EAA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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 feature works
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
- * The object is nothing but a scope: every operation runs on the context it is given, so which
21
- * transaction a write joins and how long the handle stays usable are both decided by that
22
- * context and never by the handle.
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
- assertLive(ctx);
47
- const full = `${this.prefix}${key}`;
48
- const entries = await this.#persistence.readValues(ctx, full);
49
- return entries.find((entry) => entry.key === full)?.value;
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
- assertLive(ctx);
54
- const entries = await this.#persistence.readValues(ctx, `${this.prefix}${prefix}`);
55
- return entries.map(({ key, value }) => ({ key: key.slice(this.prefix.length), value }));
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
- assertLive(ctx);
60
- await this.#persistence.writeValue(ctx, `${this.prefix}${key}`, value);
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
- assertLive(ctx);
69
- const full = `${this.prefix}${key}`;
70
- const entries = await this.#persistence.readValues(ctx, full);
71
- const current = entries.find((entry) => entry.key === full)?.value;
72
- const next = await updater(current);
73
- await this.#persistence.writeValue(ctx, full, next);
74
- return next;
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
- assertLive(ctx);
103
- const entries = await this.#persistence.readValues(ctx, this.prefix);
104
- for (const entry of entries) {
105
- await this.#persistence.deleteValue(ctx, entry.key);
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
- assertLive(ctx);
111
- await this.#persistence.deleteValue(ctx, `${this.prefix}${key}`);
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