@slopus/happy-agent-base 0.0.2 → 0.0.4

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 (46) hide show
  1. package/README.md +20 -635
  2. package/dist/Agent.d.ts +7 -0
  3. package/dist/Agent.d.ts.map +1 -1
  4. package/dist/Agent.js +20 -2
  5. package/dist/Agent.js.map +1 -1
  6. package/dist/AgentBase.d.ts +15 -17
  7. package/dist/AgentBase.d.ts.map +1 -1
  8. package/dist/AgentBase.js +237 -270
  9. package/dist/AgentBase.js.map +1 -1
  10. package/dist/AgentBaseHooks.d.ts +43 -5
  11. package/dist/AgentBaseHooks.d.ts.map +1 -1
  12. package/dist/AgentBasePending.d.ts +3 -8
  13. package/dist/AgentBasePending.d.ts.map +1 -1
  14. package/dist/AgentBasePending.js +4 -13
  15. package/dist/AgentBasePending.js.map +1 -1
  16. package/dist/AgentFeature.d.ts +29 -2
  17. package/dist/AgentFeature.d.ts.map +1 -1
  18. package/dist/AgentKV.d.ts +0 -5
  19. package/dist/AgentKV.d.ts.map +1 -1
  20. package/dist/AgentKV.js +0 -8
  21. package/dist/AgentKV.js.map +1 -1
  22. package/dist/AgentPersistence.d.ts +0 -30
  23. package/dist/AgentPersistence.d.ts.map +1 -1
  24. package/dist/AgentProviders.d.ts +19 -9
  25. package/dist/AgentProviders.d.ts.map +1 -1
  26. package/dist/AgentProviders.js +15 -12
  27. package/dist/AgentProviders.js.map +1 -1
  28. package/dist/AgentStorage.d.ts +20 -0
  29. package/dist/AgentStorage.d.ts.map +1 -1
  30. package/dist/AgentStorage.js +33 -0
  31. package/dist/AgentStorage.js.map +1 -1
  32. package/dist/AgentSystem.d.ts +2 -0
  33. package/dist/AgentSystem.d.ts.map +1 -1
  34. package/dist/AgentSystemLocal.d.ts +12 -11
  35. package/dist/AgentSystemLocal.d.ts.map +1 -1
  36. package/dist/AgentSystemLocal.js +186 -67
  37. package/dist/AgentSystemLocal.js.map +1 -1
  38. package/dist/index.d.ts +3 -3
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +2 -2
  41. package/dist/index.js.map +1 -1
  42. package/package.json +2 -2
  43. package/dist/AgentBaseStoreLock.d.ts +0 -16
  44. package/dist/AgentBaseStoreLock.d.ts.map +0 -1
  45. package/dist/AgentBaseStoreLock.js +0 -37
  46. package/dist/AgentBaseStoreLock.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"AgentKV.js","sourceRoot":"","sources":["../sources/AgentKV.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,MAAM,oBAAoB,CAAC;AAIhE;;;;;;GAMG;AACH,SAAS,UAAU,CAAC,GAAY;IAC5B,IAAI,GAAG,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;IAC5F,CAAC;AACL,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,OAAO,OAAO;IAChB,wEAAwE;IAC/D,MAAM,CAAS;IAExB,iEAAiE;IACxD,YAAY,CAAmB;IAExC,oDAAoD;IACpD,YAAY,WAA6B,EAAE,MAAc;QACrD,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,GAAG,QAA2B;QACjC,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CACrC,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CACxD,CAAC;QACF,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjF,CAAC;IAED,6DAA6D;IAC7D,KAAK,CA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ACtB,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,KAAK,CAAC,GAAY;QACpB,UAAU,CAAC,GAAG,CAAC,CAAC;QAChB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACrE,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC1B,MAAM,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;QACxD,CAAC;IACL,CAAC;IAED,mDAAmD;IACnD,KAAK,CAAC,MAAM,CAAC,GAAY,EAAE,GAAW;QAClC,UAAU,CAAC,GAAG,CAAC,CAAC;QAChB,MAAM,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC,CAAC;IACrE,CAAC;CACJ"}
@@ -24,13 +24,6 @@ export type AgentRecord = {
24
24
  } | {
25
25
  readonly type: "compaction";
26
26
  readonly messages: readonly SessionMessage[];
27
- /**
28
- * Whether inference should continue from the replacement's tail. A summary is not a
29
- * request however it happens to end, but a replacement also preserves messages that
30
- * joined after its snapshot. The rewrite is the only place that knows whether its tail
31
- * came from the summary or that live suffix.
32
- */
33
- readonly continuesInference?: boolean;
34
27
  };
35
28
  /**
36
29
  * Storage for one agent: an append-only main context store plus a sorted key-value store held
@@ -66,30 +59,7 @@ export interface AgentPersistence {
66
59
  }[]>;
67
60
  /** Store the value under `key`, replacing whatever was there before. */
68
61
  writeValue(ctx: Context, key: string, value: unknown): Promise<void>;
69
- /**
70
- * Write the value only if the key is absent, and report whether this call is the one that
71
- * wrote it. The check and the write are a single atomic step, so of two writers racing for
72
- * the same key exactly one is told it won — which is what makes a durable identity, such as
73
- * an agent's creation record, safe to claim from more than one owner at a time.
74
- */
75
- writeValueIfAbsent(ctx: Context, key: string, value: unknown): Promise<boolean>;
76
- /**
77
- * Write the value only if the stored one is still what the caller decided from, and report
78
- * whether this call is the one that wrote it. The comparison and the write are a single
79
- * atomic step, so a read-decide-write sequence can be made safe against another owner who
80
- * decided from the same value: the loser is told it lost and decides again, instead of
81
- * overwriting a decision it never saw. Absence is a value like any other, and matches an
82
- * expectation of `undefined`.
83
- */
84
- writeValueIfUnchanged(ctx: Context, key: string, expected: unknown, value: unknown): Promise<boolean>;
85
62
  /** Remove the entry stored under `key`, if any. */
86
63
  deleteValue(ctx: Context, key: string): Promise<void>;
87
- /**
88
- * Delete the key and report whether this call is the one that removed it. The check and the
89
- * deletion are a single atomic step and take effect at once — a transaction that later rolls
90
- * back restores the entry. This is how a durable queue entry is claimed: of several owners
91
- * over one store racing to consume the same message, exactly one is told it won.
92
- */
93
- deleteValueIfPresent(ctx: Context, key: string): Promise<boolean>;
94
64
  }
95
65
  //# sourceMappingURL=AgentPersistence.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AgentPersistence.d.ts","sourceRoot":"","sources":["../sources/AgentPersistence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,qBAAqB,EACrB,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACxB,kBAAkB,EACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GACjB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAA;CAAE,GAC/D;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAA;CAAE,GACjE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAA;CAAE,GACrE;IAAE,QAAQ,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CAAC;CAChD,CAAC;AAER;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAgB;IAC7B;;;;;OAKG;IACH,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5F,+DAA+D;IAC/D,IAAI,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,WAAW,EAAE,CAAC,CAAC;IACpD,gEAAgE;IAChE,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzD;;;;OAIG;IACH,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,0EAA0E;IAC1E,UAAU,CACN,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE,MAAM,GACf,OAAO,CAAC,SAAS;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAE,CAAC,CAAC;IACzE,wEAAwE;IACxE,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrE,mDAAmD;IACnD,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD"}
@@ -1,19 +1,29 @@
1
1
  import type { BaseProvider, ProviderModelCompatibilityType } from "@slopus/happy-providers";
2
+ /** The serializable provider/model selection a provider source resolves. */
3
+ export interface AgentProviderSelection {
4
+ /** The caller-defined registration ID of the provider. */
5
+ readonly id: string;
6
+ /** The model whose provider instance is needed, if the agent selected one. */
7
+ readonly model: string | undefined;
8
+ }
9
+ /**
10
+ * Either one provider suitable for every selected model or a lazy model-aware provider factory.
11
+ * Providers own no session lifetime; each AgentBase owns and destroys the sessions it opens.
12
+ */
13
+ export type AgentProviderSource = BaseProvider | ((selection: AgentProviderSelection) => BaseProvider | Promise<BaseProvider>);
2
14
  /**
3
- * Mutable registry of happy-providers instances keyed by a caller-supplied provider ID, so the
4
- * same provider class can be registered under several IDs (for example per credential). Each
5
- * entry carries its compatibility type, which decides how far a model change can go before the
6
- * conversation must reset. Providers can be added and removed while the process runs; lookups
7
- * return the live reference or null when absent.
15
+ * Mutable registry of model-aware provider sources keyed by caller-supplied IDs. Each entry carries
16
+ * its compatibility type, which decides how far a model change can go before the conversation
17
+ * must reset.
8
18
  */
9
19
  export declare class AgentProviders {
10
20
  #private;
11
- /** Register a provider under `id`. Throws if that ID is already registered. */
12
- add(id: string, provider: BaseProvider, type: ProviderModelCompatibilityType): void;
21
+ /** Register a provider source under `id`. Throws if that ID is already registered. */
22
+ add(id: string, source: AgentProviderSource, type: ProviderModelCompatibilityType): void;
13
23
  /** Unregister the provider at `id`. Returns whether one was actually removed. */
14
24
  remove(id: string): boolean;
15
- /** The live provider instance registered at `id`, or null when none is registered. */
16
- get(id: string): BaseProvider | null;
25
+ /** Resolve the provider suitable for `model`, or null when `id` is not registered. */
26
+ resolve(id: string, model: string | undefined): Promise<BaseProvider | null>;
17
27
  /** The compatibility type the provider at `id` was registered with, or null when absent. */
18
28
  typeOf(id: string): ProviderModelCompatibilityType | null;
19
29
  /** Every currently registered provider ID. */
@@ -1 +1 @@
1
- {"version":3,"file":"AgentProviders.d.ts","sourceRoot":"","sources":["../sources/AgentProviders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAE5F;;;;;;GAMG;AACH,qBAAa,cAAc;;IAOvB,+EAA+E;IAC/E,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EA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8B,GAAG,IAAI,CAExD;IAED,8CAA8C;IAC9C,IAAI,GAAG,IAAI,SAAS,MAAM,EAAE,CAE3B;CACJ"}
@@ -1,27 +1,30 @@
1
1
  /**
2
- * Mutable registry of happy-providers instances keyed by a caller-supplied provider ID, so the
3
- * same provider class can be registered under several IDs (for example per credential). Each
4
- * entry carries its compatibility type, which decides how far a model change can go before the
5
- * conversation must reset. Providers can be added and removed while the process runs; lookups
6
- * return the live reference or null when absent.
2
+ * Mutable registry of model-aware provider sources keyed by caller-supplied IDs. Each entry carries
3
+ * its compatibility type, which decides how far a model change can go before the conversation
4
+ * must reset.
7
5
  */
8
6
  export class AgentProviders {
9
- /** Registered providers keyed by their caller-supplied ID, alongside their compatibility type. */
7
+ /** Registered provider sources keyed by their caller-supplied ID and compatibility type. */
10
8
  #providers = new Map();
11
- /** Register a provider under `id`. Throws if that ID is already registered. */
12
- add(id, provider, type) {
9
+ /** Register a provider source under `id`. Throws if that ID is already registered. */
10
+ add(id, source, type) {
13
11
  if (this.#providers.has(id)) {
14
12
  throw new Error(`Provider "${id}" is already registered.`);
15
13
  }
16
- this.#providers.set(id, { provider, type });
14
+ this.#providers.set(id, { source, type });
17
15
  }
18
16
  /** Unregister the provider at `id`. Returns whether one was actually removed. */
19
17
  remove(id) {
20
18
  return this.#providers.delete(id);
21
19
  }
22
- /** The live provider instance registered at `id`, or null when none is registered. */
23
- get(id) {
24
- return this.#providers.get(id)?.provider ?? null;
20
+ /** Resolve the provider suitable for `model`, or null when `id` is not registered. */
21
+ async resolve(id, model) {
22
+ const entry = this.#providers.get(id);
23
+ if (entry === undefined)
24
+ return null;
25
+ return typeof entry.source === "function"
26
+ ? await entry.source({ id, model })
27
+ : entry.source;
25
28
  }
26
29
  /** The compatibility type the provider at `id` was registered with, or null when absent. */
27
30
  typeOf(id) {
@@ -1 +1 @@
1
- {"version":3,"file":"AgentProviders.js","sourceRoot":"","sources":["../sources/AgentProviders.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG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AC;YAC1B,MAAM,IAAI,KAAK,CAAC,aAAa,EAAE,0BAA0B,CAAC,CAAC;QAC/D,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,iFAAiF;IACjF,MAAM,CAAC,EAAU;QACb,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACtC,CAAC;IAED,sFAAsF;IACtF,KAAK,CAAC,OAAO,CAAC,EAAU,EAAE,KAAyB;QAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACtC,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QACrC,OAAO,OAAO,KAAK,CAAC,MAAM,KAAK,UAAU;YACrC,CAAC,CAAC,MAAM,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;YACnC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,4FAA4F;IAC5F,MAAM,CAAC,EAAU;QACb,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,IAAI,IAAI,IAAI,CAAC;IACjD,CAAC;IAED,8CAA8C;IAC9C,IAAI,GAAG;QACH,OAAO,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;CACJ"}
@@ -1,7 +1,21 @@
1
+ import type { Context } from "@steve.kite/stdlib";
1
2
  import type { AgentKV } from "./AgentKV.js";
2
3
  import type { AgentPersistence } from "./AgentPersistence.js";
4
+ /**
5
+ * The exclusive ownership of one durable agent store. The storage adapter must back this with
6
+ * the database's hard process-level lock rather than an in-memory convention.
7
+ */
8
+ export interface AgentStorageLock {
9
+ /** Release the hard lock after the owning AgentSystem has stopped every agent. */
10
+ release(ctx: Context): Promise<void>;
11
+ }
3
12
  /** What an `AgentStorage` is built from. */
4
13
  export interface AgentStorageOptions {
14
+ /**
15
+ * Acquire exclusive ownership of the whole store. This must fail while any other process or
16
+ * AgentSystem owns the same durable store.
17
+ */
18
+ readonly acquireLock: (ctx: Context) => Promise<AgentStorageLock>;
5
19
  /** Shared key-value storage used for state spanning all agents. */
6
20
  readonly kv: AgentKV;
7
21
  /** Produce the isolated persistence used by one agent. */
@@ -13,6 +27,12 @@ export declare class AgentStorage {
13
27
  /** Shared key-value storage used for state spanning all agents. */
14
28
  readonly kv: AgentKV;
15
29
  constructor(options: AgentStorageOptions);
30
+ /**
31
+ * Acquire exclusive ownership until the returned lock is released. The adapter's lock
32
+ * enforces this across processes; the local guard also rejects accidental reuse of this
33
+ * object.
34
+ */
35
+ acquireLock(ctx: Context): Promise<AgentStorageLock>;
16
36
  /** The isolated persistence for the given agent. */
17
37
  persistence(agentId: string): AgentPersistence;
18
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AgentStorage.d.ts","sourceRoot":"","sources":["../sources/AgentStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IAChC,mEAAmE;IACnE,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,0DAA0D;IAC1D,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,gBAAgB,CAAC;CAC/D;AAED,gEAAgE;AAChE,qBAAa,YAAY;;IACrB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IAIrB,YAAY,OAAO,EAAE,mBAAmB,EAGvC;IAED,oDAAoD;IACpD,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAE7C;CACJ"}
1
+ {"version":3,"file":"AgentStorage.d.ts","sourceRoot":"","sources":["../sources/AgentStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC7B,kFAAkF;IAClF,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC;AAED,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IAChC;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAClE,mEAAmE;IACnE,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,0DAA0D;IAC1D,QAAQ,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,gBAAgB,CAAC;CAC/D;AAED,gEAAgE;AAChE,qBAAa,YAAY;;IACrB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IAQrB,YAAY,OAAO,EAAE,mBAAmB,EAIvC;IAED;;;;OAIG;IACG,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAmBzD;IAED,oDAAoD;IACpD,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAE7C;CACJ"}
@@ -2,12 +2,45 @@
2
2
  export class AgentStorage {
3
3
  /** Shared key-value storage used for state spanning all agents. */
4
4
  kv;
5
+ /** Acquires the database-backed exclusive lock for this store. */
6
+ #acquireLock;
5
7
  /** Produces the isolated persistence used by one agent. */
6
8
  #persistence;
9
+ /** Prevents two systems from sharing even one AgentStorage instance. */
10
+ #owned = false;
7
11
  constructor(options) {
8
12
  this.kv = options.kv;
13
+ this.#acquireLock = options.acquireLock;
9
14
  this.#persistence = options.persistence;
10
15
  }
16
+ /**
17
+ * Acquire exclusive ownership until the returned lock is released. The adapter's lock
18
+ * enforces this across processes; the local guard also rejects accidental reuse of this
19
+ * object.
20
+ */
21
+ async acquireLock(ctx) {
22
+ if (this.#owned)
23
+ throw new Error("The agent store is already owned by another system.");
24
+ this.#owned = true;
25
+ let lock;
26
+ try {
27
+ lock = await this.#acquireLock(ctx);
28
+ }
29
+ catch (error) {
30
+ this.#owned = false;
31
+ throw error;
32
+ }
33
+ let released = false;
34
+ return {
35
+ release: async (releaseCtx) => {
36
+ if (released)
37
+ return;
38
+ await lock.release(releaseCtx);
39
+ released = true;
40
+ this.#owned = false;
41
+ },
42
+ };
43
+ }
11
44
  /** The isolated persistence for the given agent. */
12
45
  persistence(agentId) {
13
46
  return this.#persistence(agentId);
@@ -1 +1 @@
1
- {"version":3,"file":"AgentStorage.js","sourceRoot":"","sources":["../sources/AgentStorage.ts"],"names":[],"mappings":"AAWA,gEAAgE;AAChE,MAAM,OAAO,YAAY;IACrB,mEAAmE;IAC1D,EAAE,CAAU;IACrB,2DAA2D;IAClD,YAAY,CAAwC;IAE7D,YAAY,OAA4B;QACpC,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IAC5C,CAAC;IAED,oDAAoD;IACpD,WAAW,CAAC,OAAe;QACvB,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;CACJ"}
1
+ {"version":3,"file":"AgentStorage.js","sourceRoot":"","sources":["../sources/AgentStorage.ts"],"names":[],"mappings":"AA2BA,gEAAgE;AAChE,MAAM,OAAO,YAAY;IACrB,mEAAmE;IAC1D,EAAE,CAAU;IACrB,kEAAkE;IACzD,YAAY,CAA8C;IACnE,2DAA2D;IAClD,YAAY,CAAwC;IAC7D,wEAAwE;IACxE,MAAM,GAAG,KAAK,CAAC;IAEf,YAAY,OAA4B;QACpC,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;QACxC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW,CAAC,GAAY;QAC1B,IAAI,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACxF,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,IAAsB,CAAC;QAC3B,IAAI,CAAC;YACD,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QACxC,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;YACpB,MAAM,KAAK,CAAC;QAChB,CAAC;QACD,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,OAAO;YACH,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE;gBAC1B,IAAI,QAAQ;oBAAE,OAAO;gBACrB,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;gBAC/B,QAAQ,GAAG,IAAI,CAAC;gBAChB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;YACxB,CAAC;SACJ,CAAC;IACN,CAAC;IAED,oDAAoD;IACpD,WAAW,CAAC,OAAe;QACvB,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;CACJ"}
@@ -23,6 +23,8 @@ export interface AgentInitialContext {
23
23
  export interface AgentSystem {
24
24
  /** The models this collection offers its agents. */
25
25
  readonly models: readonly AgentModel[];
26
+ /** Stop every agent and release this system's exclusive ownership of its durable store. */
27
+ close(ctx: Context): Promise<void>;
26
28
  /**
27
29
  * Create an agent with a new system-generated cuid2 identity and the configuration it keeps
28
30
  * for its whole life. The configuration and optional initial context are persisted before
@@ -1 +1 @@
1
- {"version":3,"file":"AgentSystem.d.ts","sourceRoot":"","sources":["../sources/AgentSystem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,mFAAmF;AACnF,MAAM,WAAW,mBAAmB;IAChC,oFAAoF;IACpF,QAAQ,CAAC,QAAQ,EAAE,SAAS,cAAc,EAAE,CAAC;CAChD;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,WAAW;IACxB,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC;IAEvC;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,cAAc,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAEhG,oFAAoF;IACpF,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErD,6FAA6F;IAC7F,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAExE,gFAAgF;IAChF,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAEvD;;;OAGG;IACH,K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E,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1F"}
@@ -29,10 +29,8 @@ export interface AgentSystemLocalOptions {
29
29
  * the identities its storage holds. Concurrent resolutions of the same ID share one load, while a
30
30
  * failed load is forgotten so a later resolution can retry.
31
31
  *
32
- * Identity is durable and shared, so more than one live collection can be working over one
33
- * storage. Everything below therefore serializes per agent rather than per collection a
34
- * collection-wide lock would make one agent's feature load block every other agent, including one
35
- * that load itself resolves — and treats storage, not memory, as the authority on who exists.
32
+ * Work serializes per agent rather than per collection: a collection-wide lock would make one
33
+ * agent's feature load block every other agent, including one that load itself resolves.
36
34
  *
37
35
  * This is the owner's handle, and some of what it offers waits for an agent to reach a point only
38
36
  * that agent's run loop can bring it to. Hand an `AgentSystemRef` to anything running inside an
@@ -49,8 +47,7 @@ export declare class AgentSystemLocal implements AgentSystem {
49
47
  * was running when the previous process ended is still owed an answer, and this is what
50
48
  * makes it happen. Every identity the storage holds is examined, and each one that owes work
51
49
  * is resolved and resumed, so by the time this returns the collection is not merely built
52
- * but running. An identity another owner is still creating is left alone, since until that
53
- * creation commits there is no agent to resume.
50
+ * but running.
54
51
  */
55
52
  static create(ctx: Context, storage: AgentStorage, config: AgentSystemLocalOptions): Promise<AgentSystemLocal>;
56
53
  /**
@@ -59,6 +56,11 @@ export declare class AgentSystemLocal implements AgentSystem {
59
56
  * the storage was left holding — building one without that is building half of it.
60
57
  */
61
58
  private constructor();
59
+ /**
60
+ * Stop every live agent, wait for operations already admitted by this owner, and only then
61
+ * release the database lock. Repeated callers join the same shutdown.
62
+ */
63
+ close(ctx: Context): Promise<void>;
62
64
  /**
63
65
  * Create an agent with the configuration it keeps for its whole life, and resolve it. The
64
66
  * identity is allocated here and nowhere else: it is a cuid2, globally unique, so a new
@@ -66,11 +68,10 @@ export declare class AgentSystemLocal implements AgentSystem {
66
68
  * The configuration is persisted before the agent runs, so every later process resolves the
67
69
  * agent exactly as it was created.
68
70
  *
69
- * Nothing here is ever undone: an agent whose features refuse to load leaves an identity
70
- * that exists, is resolvable, and will be built the next time something wants it. The
71
- * alternative writing a provisional identity and taking it back when the build fails —
72
- * has to get the taking-back right in the presence of crashes and other owners, and a
73
- * compensation that can itself fail is not a guarantee.
71
+ * Nothing here is undone: an agent whose features refuse to load leaves an identity that
72
+ * exists, is resolvable, and will be built the next time something wants it. Taking a
73
+ * provisional identity back after a failed build would add a compensation that can itself
74
+ * fail.
74
75
  */
75
76
  create(ctx: Context, config: AgentConfig, initialContext?: AgentInitialContext): Promise<Agent>;
76
77
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"AgentSystemLocal.d.ts","sourceRoot":"","sources":["../sources/AgentSystemLocal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElF,OAAO,EAA6B,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7E,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAI1F,OAAO,EAAsC,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACxF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAIzE,yFAAyF;AACzF,MAAM,WAAW,uBAAuB;IACpC;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAC5C,uEAAu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