@slopus/happy-agent-base 0.0.5 → 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.
Files changed (92) hide show
  1. package/README.md +62 -9
  2. package/dist/Agent.d.ts +27 -22
  3. package/dist/Agent.d.ts.map +1 -1
  4. package/dist/Agent.js +120 -110
  5. package/dist/Agent.js.map +1 -1
  6. package/dist/AgentBase.d.ts +27 -13
  7. package/dist/AgentBase.d.ts.map +1 -1
  8. package/dist/AgentBase.js +657 -151
  9. package/dist/AgentBase.js.map +1 -1
  10. package/dist/AgentBaseHooks.d.ts +58 -32
  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 +20 -13
  17. package/dist/AgentConfig.d.ts.map +1 -1
  18. package/dist/AgentConfig.js +32 -12
  19. package/dist/AgentConfig.js.map +1 -1
  20. package/dist/AgentContexts.d.ts +18 -1
  21. package/dist/AgentContexts.d.ts.map +1 -1
  22. package/dist/AgentContexts.js +24 -1
  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 +37 -0
  37. package/dist/AgentMetadata.d.ts.map +1 -0
  38. package/dist/AgentMetadata.js +74 -0
  39. package/dist/AgentMetadata.js.map +1 -0
  40. package/dist/AgentModule.d.ts +209 -0
  41. package/dist/AgentModule.d.ts.map +1 -0
  42. package/dist/AgentModule.js +2 -0
  43. package/dist/AgentModule.js.map +1 -0
  44. package/dist/{AgentFeatureAction.d.ts → AgentModuleAction.d.ts} +7 -2
  45. package/dist/AgentModuleAction.d.ts.map +1 -0
  46. package/dist/AgentModuleAction.js +2 -0
  47. package/dist/AgentModuleAction.js.map +1 -0
  48. package/dist/AgentPermissionMode.d.ts +1 -1
  49. package/dist/AgentPermissionMode.js +1 -1
  50. package/dist/AgentPersistence.d.ts +20 -7
  51. package/dist/AgentPersistence.d.ts.map +1 -1
  52. package/dist/AgentPersistenceDrizzle.d.ts +31 -0
  53. package/dist/AgentPersistenceDrizzle.d.ts.map +1 -0
  54. package/dist/AgentPersistenceDrizzle.js +99 -0
  55. package/dist/AgentPersistenceDrizzle.js.map +1 -0
  56. package/dist/AgentRef.d.ts +17 -9
  57. package/dist/AgentRef.d.ts.map +1 -1
  58. package/dist/AgentRef.js +16 -9
  59. package/dist/AgentRef.js.map +1 -1
  60. package/dist/AgentStorage.d.ts +33 -13
  61. package/dist/AgentStorage.d.ts.map +1 -1
  62. package/dist/AgentStorage.js +174 -3
  63. package/dist/AgentStorage.js.map +1 -1
  64. package/dist/AgentSystem.d.ts +34 -12
  65. package/dist/AgentSystem.d.ts.map +1 -1
  66. package/dist/AgentSystemContext.d.ts +3 -3
  67. package/dist/AgentSystemContext.d.ts.map +1 -1
  68. package/dist/AgentSystemContext.js +4 -4
  69. package/dist/AgentSystemContext.js.map +1 -1
  70. package/dist/AgentSystemLocal.d.ts +30 -21
  71. package/dist/AgentSystemLocal.d.ts.map +1 -1
  72. package/dist/AgentSystemLocal.js +226 -59
  73. package/dist/AgentSystemLocal.js.map +1 -1
  74. package/dist/AgentSystemRef.d.ts +21 -10
  75. package/dist/AgentSystemRef.d.ts.map +1 -1
  76. package/dist/AgentSystemRef.js +41 -9
  77. package/dist/AgentSystemRef.js.map +1 -1
  78. package/dist/AgentTool.d.ts +16 -1
  79. package/dist/AgentTool.d.ts.map +1 -1
  80. package/dist/AgentTool.js.map +1 -1
  81. package/dist/index.d.ts +10 -7
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +9 -6
  84. package/dist/index.js.map +1 -1
  85. package/package.json +4 -3
  86. package/dist/AgentFeature.d.ts +0 -177
  87. package/dist/AgentFeature.d.ts.map +0 -1
  88. package/dist/AgentFeature.js +0 -2
  89. package/dist/AgentFeature.js.map +0 -1
  90. package/dist/AgentFeatureAction.d.ts.map +0 -1
  91. package/dist/AgentFeatureAction.js +0 -2
  92. package/dist/AgentFeatureAction.js.map +0 -1
@@ -1,5 +1,6 @@
1
1
  import { Type } from "@sinclair/typebox";
2
2
  import { Value } from "@sinclair/typebox/value";
3
+ import { cuid2Schema } from "./AgentMetadata.js";
3
4
  /**
4
5
  * The one key an agent's outstanding work lives under, in the agent's own store. It is a single
5
6
  * key rather than a prefix of many, because what it records is one fact — that this agent has
@@ -19,6 +20,8 @@ export const AgentBasePendingStage = Type.Union([
19
20
  Type.Literal("tools"),
20
21
  /** The conversation is being replaced by the provider's summary of it. */
21
22
  Type.Literal("compaction"),
23
+ /** The loop has ended and its durable settlement transaction remains to commit. */
24
+ Type.Literal("settlement"),
22
25
  ]);
23
26
  /**
24
27
  * The agent's outstanding work, as the run itself recorded it. Its presence is the whole of the
@@ -28,6 +31,10 @@ export const AgentBasePendingStage = Type.Union([
28
31
  */
29
32
  export const AgentBasePendingState = Type.Object({
30
33
  stage: AgentBasePendingStage,
34
+ loopId: cuid2Schema,
35
+ turnId: Type.Optional(cuid2Schema),
36
+ inferenceId: Type.Optional(cuid2Schema),
37
+ settlementId: Type.Optional(cuid2Schema),
31
38
  });
32
39
  /**
33
40
  * Read one store's pending state, or undefined when it holds none. Anything stored under the key
@@ -1 +1 @@
1
- {"version":3,"file":"AgentBasePending.js","sourceRoot":"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,CAAC,WAAW,CAAC;IACvC,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;CAC3C,CAAC,CAAC;AAGH;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CACzC,GAAY,EACZ,WAA6B;IAE7B,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,sBAAsB,CAAC,CAAC;IAC1E,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,sBAAsB,CAAC,EAAE,KAAK,CAAC;IACpF,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC3C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,qBAAqB,EAAE,MAAM,CAAC;QAAE,OAAO,SAAS,CAAC;IAClE,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CACxC,GAAY,EACZ,WAA6B;IAE7B,IAAI,CAAC,MAAM,uBAAuB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACjF,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACrC,OAAO,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC;AAClF,CAAC"}
@@ -1,16 +1,17 @@
1
1
  import { type Static } from "@sinclair/typebox";
2
2
  import { type Context } from "@steve.kite/stdlib";
3
+ import { type AgentMetadata } from "./AgentMetadata.js";
3
4
  /** The operating systems Node reports, mirroring `NodeJS.Platform`. */
4
5
  export declare const agentPlatformSchema: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"aix">, import("@sinclair/typebox").TLiteral<"android">, import("@sinclair/typebox").TLiteral<"cygwin">, import("@sinclair/typebox").TLiteral<"darwin">, import("@sinclair/typebox").TLiteral<"freebsd">, import("@sinclair/typebox").TLiteral<"haiku">, import("@sinclair/typebox").TLiteral<"linux">, import("@sinclair/typebox").TLiteral<"netbsd">, import("@sinclair/typebox").TLiteral<"openbsd">, import("@sinclair/typebox").TLiteral<"sunos">, import("@sinclair/typebox").TLiteral<"win32">]>;
5
6
  /** The TypeScript type inferred from {@link agentPlatformSchema}. */
6
7
  export type AgentPlatform = Static<typeof agentPlatformSchema>;
7
8
  /**
8
- * 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
9
10
  * the shape of its own entry and validates it against its own schema.
10
11
  */
11
- export declare const agentFeatureConfigSchema: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>;
12
- /** The TypeScript type inferred from {@link agentFeatureConfigSchema}. */
13
- 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>;
14
15
  /**
15
16
  * The machine an agent works on. It is all or nothing: an agent either knows its environment
16
17
  * completely or not at all, so nothing it is told about the machine is ever half-true.
@@ -28,10 +29,10 @@ export declare const agentEnvironmentSchema: import("@sinclair/typebox").TObject
28
29
  /** The TypeScript type inferred from {@link agentEnvironmentSchema}. */
29
30
  export type AgentEnvironment = Static<typeof agentEnvironmentSchema>;
30
31
  /**
31
- * What an agent was created with: the environment it works on, when it has one, and one opaque
32
- * settings map per feature, keyed by the feature's name. The configuration is static for the
33
- * agent's whole life and is persisted when the agent is created, so a later process resolves
34
- * the very same agent it was created as.
32
+ * What an agent was created with: the environment it works on, when it has one, one opaque
33
+ * settings map per module, and descriptive metadata. Environment and module settings stay
34
+ * fixed; metadata changes only through the agent metadata API, which shallow-merges updates and
35
+ * persists the resulting complete configuration.
35
36
  */
36
37
  export declare const agentConfigSchema: import("@sinclair/typebox").TObject<{
37
38
  /** The machine this agent was told it works on, when it was told anything at all. */
@@ -45,8 +46,12 @@ export declare const agentConfigSchema: import("@sinclair/typebox").TObject<{
45
46
  /** The shell the agent's commands run in, such as `/bin/zsh`. */
46
47
  shell: import("@sinclair/typebox").TString;
47
48
  }>>;
48
- /** Per-feature settings, keyed by feature name; each entry is opaque to the agent. */
49
- 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
+ /** Immutable descriptive metadata, replaced only through a merged metadata update. */
52
+ metadata: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TIntersect<[import("@sinclair/typebox").TObject<{
53
+ title: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
54
+ }>, import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TRecursive<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TString, import("@sinclair/typebox").TNumber, import("@sinclair/typebox").TBoolean, import("@sinclair/typebox").TNull, import("@sinclair/typebox").TArray<import("@sinclair/typebox").TThis>, import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TThis>]>>>]>>;
50
55
  }>;
51
56
  /** The TypeScript type inferred from {@link agentConfigSchema}. */
52
57
  export type AgentConfig = Static<typeof agentConfigSchema>;
@@ -56,12 +61,14 @@ export type AgentConfig = Static<typeof agentConfigSchema>;
56
61
  * than slipping into a persisted configuration; an unset `SHELL` reports as no shell at all.
57
62
  */
58
63
  export declare function currentAgentEnvironment(): AgentEnvironment;
59
- /** Carry the configuration an agent was created with; every hook and tool reads it back. */
64
+ /** Carry the agent's current configuration; every hook and tool reads it back. */
60
65
  export declare function withAgentConfig(ctx: Context, config: AgentConfig): Context;
61
66
  /** The configuration of the agent owning this context, when one was attached. */
62
67
  export declare function agentConfig(ctx: Context): AgentConfig | undefined;
63
68
  /** The environment of the agent owning this context, when it was created with one. */
64
69
  export declare function agentEnvironment(ctx: Context): AgentEnvironment | undefined;
65
- /** The opaque settings the named feature was configured with, if it was configured at all. */
66
- export declare function agentFeatureConfig(ctx: Context, name: string): AgentFeatureConfig | undefined;
70
+ /** The immutable metadata describing the agent owning this context, when it has any. */
71
+ export declare function agentMetadata(ctx: Context): AgentMetadata | 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;
67
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;AACtD,OAAO,EAA0B,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE1E,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,kBAA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IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAE3F"}
@@ -1,6 +1,8 @@
1
1
  import { release } from "node:os";
2
2
  import { Type } from "@sinclair/typebox";
3
+ import { Value } from "@sinclair/typebox/value";
3
4
  import { createContextNamespace } from "@steve.kite/stdlib";
5
+ import { agentMetadataSchema, ownAgentMetadata } from "./AgentMetadata.js";
4
6
  /** The operating systems Node reports, mirroring `NodeJS.Platform`. */
5
7
  export const agentPlatformSchema = Type.Union([
6
8
  Type.Literal("aix"),
@@ -16,10 +18,10 @@ export const agentPlatformSchema = Type.Union([
16
18
  Type.Literal("win32"),
17
19
  ]);
18
20
  /**
19
- * 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
20
22
  * the shape of its own entry and validates it against its own schema.
21
23
  */
22
- export const agentFeatureConfigSchema = Type.Record(Type.String(), Type.Unknown());
24
+ export const agentModuleConfigSchema = Type.Record(Type.String(), Type.Unknown());
23
25
  /**
24
26
  * The machine an agent works on. It is all or nothing: an agent either knows its environment
25
27
  * completely or not at all, so nothing it is told about the machine is ever half-true.
@@ -35,17 +37,31 @@ export const agentEnvironmentSchema = Type.Object({
35
37
  shell: Type.String(),
36
38
  });
37
39
  /**
38
- * What an agent was created with: the environment it works on, when it has one, and one opaque
39
- * settings map per feature, keyed by the feature's name. The configuration is static for the
40
- * agent's whole life and is persisted when the agent is created, so a later process resolves
41
- * the very same agent it was created as.
40
+ * What an agent was created with: the environment it works on, when it has one, one opaque
41
+ * settings map per module, and descriptive metadata. Environment and module settings stay
42
+ * fixed; metadata changes only through the agent metadata API, which shallow-merges updates and
43
+ * persists the resulting complete configuration.
42
44
  */
43
45
  export const agentConfigSchema = Type.Object({
44
46
  /** The machine this agent was told it works on, when it was told anything at all. */
45
47
  environment: Type.Optional(agentEnvironmentSchema),
46
- /** Per-feature settings, keyed by feature name; each entry is opaque to the agent. */
47
- 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
+ /** Immutable descriptive metadata, replaced only through a merged metadata update. */
51
+ metadata: Type.Optional(agentMetadataSchema),
48
52
  });
53
+ /** @internal Validate and own one configuration while deeply freezing its metadata. */
54
+ export function ownAgentConfig(config) {
55
+ if (!Value.Check(agentConfigSchema, config)) {
56
+ throw new Error("The agent configuration is not valid.");
57
+ }
58
+ const cloned = structuredClone(config);
59
+ const metadata = ownAgentMetadata(cloned.metadata);
60
+ return {
61
+ ...cloned,
62
+ ...(metadata === undefined ? {} : { metadata }),
63
+ };
64
+ }
49
65
  /**
50
66
  * The environment this process is running in, ready to be handed to an agent at creation. The
51
67
  * platform is typed, so a Node release reporting an unknown platform fails to compile rather
@@ -62,7 +78,7 @@ export function currentAgentEnvironment() {
62
78
  }
63
79
  /** The context slot the agent's configuration is carried in, unset until an agent attaches one. */
64
80
  const configNamespace = createContextNamespace("happyAgentBase.agentConfig", undefined);
65
- /** Carry the configuration an agent was created with; every hook and tool reads it back. */
81
+ /** Carry the agent's current configuration; every hook and tool reads it back. */
66
82
  export function withAgentConfig(ctx, config) {
67
83
  return configNamespace.set(ctx, config);
68
84
  }
@@ -74,8 +90,12 @@ export function agentConfig(ctx) {
74
90
  export function agentEnvironment(ctx) {
75
91
  return configNamespace.get(ctx)?.environment;
76
92
  }
77
- /** The opaque settings the named feature was configured with, if it was configured at all. */
78
- export function agentFeatureConfig(ctx, name) {
79
- return configNamespace.get(ctx)?.features?.[name];
93
+ /** The immutable metadata describing the agent owning this context, when it has any. */
94
+ export function agentMetadata(ctx) {
95
+ return configNamespace.get(ctx)?.metadata;
96
+ }
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];
80
100
  }
81
101
  //# sourceMappingURL=AgentConfig.js.map
@@ -1 +1 @@
1
- {"version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I,EAAE;KACjC,CAAC;AACN,CAAC;AAED,mGAAmG;AACnG,MAAM,eAAe,GAAG,sBAAsB,CAC1C,4BAA4B,EAC5B,SAAS,CACZ,CAAC;AAEF,kFAAkF;AAClF,MAAM,UAAU,eAAe,CAAC,GAAY,EAAE,MAAmB;IAC7D,OAAO,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAC5C,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,WAAW,CAAC,GAAY;IACpC,OAAO,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,gBAAgB,CAAC,GAAY;IACzC,OAAO,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC;AACjD,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,aAAa,CAAC,GAAY;IACtC,OAAO,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC;AAC9C,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,iBAAiB,CAAC,GAAY,EAAE,IAAY;IACxD,OAAO,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;AACrD,CAAC"}
@@ -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
- * feature instance serve every agent in a collection: a shared feature learns which agent a hook is
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;AA4BnG;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC5B,GAAG,EAAE,OA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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"}
@@ -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
- * feature instance serve every agent in a collection: a shared feature learns which agent a hook is
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;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,CAC5B,GAAY,EACZ,MAOC;IAED,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CA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AAuB;IACnE,OAAO,iBAAiB,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAChD,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,aAAa,CAAC,GAAY;IACtC,OAAO,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC;AAED,qGAAqG;AACrG,MAAM,UAAU,2BAA2B,CACvC,GAAY,EACZ,WAA2C;IAE3C,OAAO,2BAA2B,CAAC,GAAG,CAClC,iBAAiB,CAAC,GAAG,EAAE,WAAW,CAAC,QAAQ,CAAC,EAC5C,WAAW,CACd,CAAC;AACN,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,uBAAuB,CACnC,GAAY;IAEZ,OAAO,2BAA2B,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAChD,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,8BAA8B,CAAC,GAAY;IACvD,OAAO,2BAA2B,CAAC,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;AAC3D,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,kBAAk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Aa,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"}
@@ -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,O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