@slopus/happy-agent-base 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +49 -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 +476 -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 +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 +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 +31 -0
  51. package/dist/AgentPersistenceDrizzle.d.ts.map +1 -0
  52. package/dist/AgentPersistenceDrizzle.js +99 -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 +33 -13
  59. package/dist/AgentStorage.d.ts.map +1 -1
  60. package/dist/AgentStorage.js +174 -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 +3 -3
  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 +16 -1
  77. package/dist/AgentTool.d.ts.map +1 -1
  78. package/dist/AgentTool.js.map +1 -1
  79. package/dist/index.d.ts +8 -6
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +7 -5
  82. package/dist/index.js.map +1 -1
  83. package/package.json +4 -3
  84. package/dist/AgentFeature.d.ts +0 -184
  85. package/dist/AgentFeature.d.ts.map +0 -1
  86. package/dist/AgentFeature.js +0 -2
  87. package/dist/AgentFeature.js.map +0 -1
  88. package/dist/AgentFeatureAction.d.ts.map +0 -1
  89. package/dist/AgentFeatureAction.js +0 -2
  90. package/dist/AgentFeatureAction.js.map +0 -1
package/dist/AgentRef.js CHANGED
@@ -2,15 +2,15 @@ import { agentId } from "./AgentContexts.js";
2
2
  /**
3
3
  * Whether this caller may be told that `agentId` durably accepted a message. Acceptance is a
4
4
  * queue write under that agent's own persistence lock, so waiting for it is safe from anywhere
5
- * except inside that agent's loop, which is holding the lock the write needs. The proof is the
6
- * caller's context naming a different agent; a context naming none proves nothing.
5
+ * except inside that agent's loop, which is holding the lock the write needs. A caller naming no
6
+ * agent is an external host and may wait; only the target agent itself cannot.
7
7
  */
8
8
  export function acceptanceIsWaitable(ctx, target) {
9
9
  const caller = agentId(ctx);
10
- return caller !== undefined && caller !== target;
10
+ return caller !== target;
11
11
  }
12
12
  /**
13
- * A reference to an agent for code that runs inside one — a feature hook, or a tool the run loop
13
+ * A reference to an agent for code that runs inside one — a module hook, or a tool the run loop
14
14
  * is waiting on. No operation here waits for a run loop: `compact` and `abort` are requests that
15
15
  * resolve once they have been made, and there is no `close`, `waitForIdle` or `start`, each of
16
16
  * which is whole-agent lifetime owned by whoever created the agent and nothing *but* the wait
@@ -21,8 +21,8 @@ export function acceptanceIsWaitable(ctx, target) {
21
21
  * agent's conversation and reject when the write fails, so a caller routing work elsewhere knows
22
22
  * whether it arrived. Addressed to the agent the caller is running inside — whose loop would have
23
23
  * to perform that write — the message is queued and not waited for. The context decides, since it
24
- * names the agent the caller is in; a context that names none proves nothing and waits for
25
- * nothing.
24
+ * names the agent the caller is in; a context that names none is an external host and receives
25
+ * the durable acceptance result.
26
26
  */
27
27
  export class AgentRef {
28
28
  /** The agent this reference wraps. */
@@ -39,14 +39,14 @@ export class AgentRef {
39
39
  }
40
40
  /** Queue a message that injects as soon as the current response and its tool batch finish. */
41
41
  async steer(ctx, message, options) {
42
- await this.#agent.steer(ctx, message, {
42
+ return await this.#agent.steer(ctx, message, {
43
43
  ...options,
44
44
  await: acceptanceIsWaitable(ctx, this.#agent.id),
45
45
  });
46
46
  }
47
47
  /** Queue a message that injects when the agent would otherwise stop. */
48
48
  async send(ctx, message, options) {
49
- await this.#agent.send(ctx, message, {
49
+ return await this.#agent.send(ctx, message, {
50
50
  ...options,
51
51
  await: acceptanceIsWaitable(ctx, this.#agent.id),
52
52
  });
@@ -1 +1 @@
1
- {"version":3,"file":"AgentRef.js","sourceRoot":"","sources":["../sources/AgentRef.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAG7C;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAY,EAAE,MAAc;IAC7D,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,OAAO,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,MAAM,CAAC;AACrD,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,QAAQ;IACjB,sCAAsC;IAC7B,MAAM,CAAQ;IACvB,0FAA0F;IACjF,MAAM,CAAgB;IAE/B,YAAY,KAAY,EAAE,MAAM,GAAkB,IAAI;QAClD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,8BAA8B;IAC9B,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;IAC1B,CAAC;IAED,8FAA8F;IAC9F,KAAK,CA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AAC,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,sCAAsC;IACtC,KAAK,CAAC,KAAK,CAAC,GAAY;QACpB,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACnD,CAAC;CACJ"}
@@ -1,32 +1,43 @@
1
- import type { Context } from "@steve.kite/stdlib";
2
- import type { AgentKV } from "./AgentKV.js";
1
+ import { type Context } from "@steve.kite/stdlib";
2
+ import { type AgentDatabase, type AgentDatabaseFacade, type AgentStorageTransaction } from "./AgentDatabase.js";
3
+ import type { AgentModule } from "./AgentModule.js";
4
+ import { AgentKV } from "./AgentKV.js";
3
5
  import type { AgentPersistence } from "./AgentPersistence.js";
6
+ import type { AnyAgentTool } from "./AgentTool.js";
4
7
  /**
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.
8
+ * The exclusive ownership of one durable agent store. A host sharing its database between
9
+ * processes should back this with the same hard process-level lock as the database itself.
7
10
  */
8
11
  export interface AgentStorageLock {
9
12
  /** Release the hard lock after the owning AgentSystem has stopped every agent. */
10
13
  release(ctx: Context): Promise<void>;
11
14
  }
12
- /** What an `AgentStorage` is built from. */
13
- export interface AgentStorageOptions {
15
+ interface AgentStorageCommonOptions {
14
16
  /**
15
17
  * Acquire exclusive ownership of the whole store. This must fail while any other process or
16
18
  * AgentSystem owns the same durable store.
17
19
  */
18
20
  readonly acquireLock: (ctx: Context) => Promise<AgentStorageLock>;
19
- /** Shared key-value storage used for state spanning all agents. */
20
- readonly kv: AgentKV;
21
- /** Produce the isolated persistence used by one agent. */
22
- readonly persistence: (agentId: string) => AgentPersistence;
23
21
  }
24
- /** Storage roots shared by an `AgentSystemLocal` collection. */
25
- export declare class AgentStorage {
22
+ /** Drizzle-owned storage with optional host transaction integration. */
23
+ export type AgentStorageOptions<Database extends AgentDatabase = AgentDatabase> = AgentStorageCommonOptions & {
24
+ /** The engine-specific Drizzle facade; the same object is passed through to modules. */
25
+ readonly database: Database;
26
+ /**
27
+ * Host transaction integration. It must pass the active Drizzle transaction facade and a
28
+ * context carrying the host transaction's stdlib `afterCommit` scope to `work`. Omission
29
+ * uses the Drizzle facade's own transaction method and installs that scope automatically.
30
+ */
31
+ readonly transaction?: AgentStorageTransaction<Database>;
32
+ };
33
+ /** Storage roots and Drizzle persistence shared by an `AgentSystemLocal` collection. */
34
+ export declare class AgentStorage<Database extends AgentDatabase = AgentDatabase> {
26
35
  #private;
36
+ /** The root Drizzle facade. */
37
+ readonly database: Database;
27
38
  /** Shared key-value storage used for state spanning all agents. */
28
39
  readonly kv: AgentKV;
29
- constructor(options: AgentStorageOptions);
40
+ constructor(options: AgentStorageOptions<Database>);
30
41
  /**
31
42
  * Acquire exclusive ownership until the returned lock is released. The adapter's lock
32
43
  * enforces this across processes; the local guard also rejects accidental reuse of this
@@ -35,5 +46,14 @@ export declare class AgentStorage {
35
46
  acquireLock(ctx: Context): Promise<AgentStorageLock>;
36
47
  /** The isolated persistence for the given agent. */
37
48
  persistence(agentId: string): AgentPersistence;
49
+ /** Run work in this storage's default or host-supplied transaction integration. */
50
+ transaction<Result>(ctx: Context, work: (ctx: Context, database: AgentDatabaseFacade<Database>) => Promise<Result>): Promise<Result>;
51
+ /**
52
+ * Install the base schema and every module's ordered keyed migrations. Each migration and
53
+ * its success marker commit atomically. Applied keys must remain an exact prefix, so inserting
54
+ * or reordering historical migrations fails instead of silently changing their meaning.
55
+ */
56
+ migrate(ctx: Context, modules: readonly AgentModule<AnyAgentTool, Database>[]): Promise<void>;
38
57
  }
58
+ export {};
39
59
  //# sourceMappingURL=AgentStorage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AgentStorage.d.ts","sourceRoot":"","sources":["../sources/AgentStorage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM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CAAC,MAAM,CAAC,CAEjB;IAED;;;;OAIG;IACG,OAAO,CACT,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE,SAAS,WAAW,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAE,GACxD,OAAO,CAAC,IAAI,CAAC,CA6Cf;CA8CJ"}
@@ -1,17 +1,38 @@
1
- /** Storage roots shared by an `AgentSystemLocal` collection. */
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { sql } from "drizzle-orm";
3
+ import { asyncLock, withAfterCommit } from "@steve.kite/stdlib";
4
+ import { agentDatabaseRows, agentDatabaseRun, isAgentSQLiteDatabase, } from "./AgentDatabase.js";
5
+ import { agentStorageTransaction, withAgentStorageTransaction, } from "./AgentContexts.js";
6
+ import { AgentKV } from "./AgentKV.js";
7
+ import { AgentPersistenceDrizzle, } from "./AgentPersistenceDrizzle.js";
8
+ const storageTransactions = new AsyncLocalStorage();
9
+ /** Storage roots and Drizzle persistence shared by an `AgentSystemLocal` collection. */
2
10
  export class AgentStorage {
11
+ /** The root Drizzle facade. */
12
+ database;
3
13
  /** Shared key-value storage used for state spanning all agents. */
4
14
  kv;
5
15
  /** Acquires the database-backed exclusive lock for this store. */
6
16
  #acquireLock;
7
17
  /** Produces the isolated persistence used by one agent. */
8
18
  #persistence;
19
+ /** Drizzle transaction integration shared by every owned persistence scope. */
20
+ #drizzle;
9
21
  /** Prevents two systems from sharing even one AgentStorage instance. */
10
22
  #owned = false;
11
23
  constructor(options) {
12
- this.kv = options.kv;
13
24
  this.#acquireLock = options.acquireLock;
14
- this.#persistence = options.persistence;
25
+ this.database = options.database;
26
+ const owner = {};
27
+ const rawTransaction = options.transaction ?? defaultTransactionIntegration(options.database);
28
+ const integration = {
29
+ database: options.database,
30
+ owner,
31
+ transaction: storageTransactionIntegration(owner, rawTransaction),
32
+ };
33
+ this.#drizzle = integration;
34
+ this.kv = new AgentKV(new AgentPersistenceDrizzle(integration, ""), "agentSystem.");
35
+ this.#persistence = (agentId) => new AgentPersistenceDrizzle(integration, agentId);
15
36
  }
16
37
  /**
17
38
  * Acquire exclusive ownership until the returned lock is released. The adapter's lock
@@ -45,5 +66,155 @@ export class AgentStorage {
45
66
  persistence(agentId) {
46
67
  return this.#persistence(agentId);
47
68
  }
69
+ /** Run work in this storage's default or host-supplied transaction integration. */
70
+ async transaction(ctx, work) {
71
+ return await this.#drizzle.transaction(ctx, work);
72
+ }
73
+ /**
74
+ * Install the base schema and every module's ordered keyed migrations. Each migration and
75
+ * its success marker commit atomically. Applied keys must remain an exact prefix, so inserting
76
+ * or reordering historical migrations fails instead of silently changing their meaning.
77
+ */
78
+ async migrate(ctx, modules) {
79
+ const names = modules.map((module) => module.name);
80
+ if (names.includes("@happy-agent-base") || new Set(names).size !== names.length) {
81
+ throw new Error("Module names must be unique and cannot use the agent-base owner.");
82
+ }
83
+ await this.#drizzle.transaction(ctx, async (txCtx, database) => {
84
+ await agentDatabaseRun(database, sql `CREATE TABLE IF NOT EXISTS happy_agent_migrations (
85
+ module_key TEXT NOT NULL,
86
+ migration_key TEXT NOT NULL,
87
+ position BIGINT NOT NULL,
88
+ PRIMARY KEY (module_key, migration_key),
89
+ UNIQUE (module_key, position)
90
+ )`);
91
+ });
92
+ await this.#migrateModule(ctx, "@happy-agent-base", [
93
+ [
94
+ "001-core-storage",
95
+ async (_migrationCtx, database) => {
96
+ await agentDatabaseRun(database, sql `CREATE TABLE happy_agent_records (
97
+ owner_id TEXT NOT NULL,
98
+ position BIGINT NOT NULL,
99
+ record_json TEXT NOT NULL,
100
+ PRIMARY KEY (owner_id, position)
101
+ )`);
102
+ await agentDatabaseRun(database, sql `CREATE TABLE happy_agent_values (
103
+ owner_id TEXT NOT NULL,
104
+ key TEXT NOT NULL,
105
+ value_json TEXT NOT NULL,
106
+ PRIMARY KEY (owner_id, key)
107
+ )`);
108
+ },
109
+ ],
110
+ ]);
111
+ for (const module of modules) {
112
+ await this.#migrateModule(ctx, module.name, module.migrations ?? []);
113
+ }
114
+ }
115
+ async #migrateModule(ctx, module, migrations) {
116
+ const keys = migrations.map(([key]) => key);
117
+ if (keys.some((key) => key.length === 0) || new Set(keys).size !== keys.length) {
118
+ throw new Error(`Module "${module}" has an empty or duplicate migration key.`);
119
+ }
120
+ const applied = await agentDatabaseRows(this.#drizzle.database, sql `SELECT migration_key, position
121
+ FROM happy_agent_migrations
122
+ WHERE module_key = ${module}
123
+ ORDER BY position`);
124
+ for (let index = 0; index < applied.length; index += 1) {
125
+ if (applied[index]?.migration_key !== keys[index] ||
126
+ Number(applied[index]?.position) !== index) {
127
+ throw new Error(`The applied migrations for module "${module}" are not a prefix of its current migrations.`);
128
+ }
129
+ }
130
+ for (let index = applied.length; index < migrations.length; index += 1) {
131
+ const migration = migrations[index];
132
+ if (migration === undefined)
133
+ continue;
134
+ const [key, run] = migration;
135
+ await this.#drizzle.transaction(ctx, async (txCtx, database) => {
136
+ await run(txCtx, database);
137
+ await agentDatabaseRun(database, sql `INSERT INTO happy_agent_migrations
138
+ (module_key, migration_key, position)
139
+ VALUES (${module}, ${key}, ${index})`);
140
+ });
141
+ }
142
+ }
143
+ }
144
+ function defaultTransactionIntegration(database) {
145
+ const transactionLock = isAgentSQLiteDatabase(database) ? asyncLock() : undefined;
146
+ const commitTransaction = async (ctx, work) => {
147
+ let runAfterCommit;
148
+ const result = await runDrizzleTransaction(database, async (activeDatabase) => {
149
+ const [commitCtx, drainAfterCommit] = withAfterCommit(ctx);
150
+ runAfterCommit = drainAfterCommit;
151
+ return await work(commitCtx, activeDatabase);
152
+ });
153
+ return [result, runAfterCommit];
154
+ };
155
+ const transaction = async (ctx, work) => {
156
+ const [result, runAfterCommit] = transactionLock === undefined
157
+ ? await commitTransaction(ctx, work)
158
+ : await transactionLock.runInLock(ctx, async (lockCtx) => {
159
+ return await commitTransaction(lockCtx, work);
160
+ });
161
+ try {
162
+ await runAfterCommit();
163
+ }
164
+ catch (error) {
165
+ process.emitWarning(new AggregateError([error], "Agent storage committed, but post-commit work failed."));
166
+ }
167
+ return result;
168
+ };
169
+ return transaction;
170
+ }
171
+ /**
172
+ * Own transaction identity and nesting independently of the supplied database integration.
173
+ * A normal context from another storage remains a normal context, while an actual foreign
174
+ * transaction can neither leak its facade into this store nor silently open a second commit.
175
+ */
176
+ function storageTransactionIntegration(owner, transaction) {
177
+ return async (ctx, work) => {
178
+ const carried = agentStorageTransaction(ctx);
179
+ const ambient = storageTransactions.getStore();
180
+ if (ambient !== undefined && !ambient.lifetime.aborted) {
181
+ if (ambient.owner === owner && carried === ambient) {
182
+ return await work(ctx, ambient.database);
183
+ }
184
+ throw new Error("Work started inside an agent storage transaction must use that transaction's context.");
185
+ }
186
+ if (carried !== undefined) {
187
+ if (carried.lifetime.aborted) {
188
+ throw new Error("The agent storage transaction carried by this context has ended.");
189
+ }
190
+ if (carried.owner !== owner) {
191
+ throw new Error("A transaction context cannot be used with another agent storage.");
192
+ }
193
+ return await work(ctx, carried.database);
194
+ }
195
+ return await transaction(ctx, async (txCtx, database) => {
196
+ const lifetime = new AbortController();
197
+ const state = {
198
+ database,
199
+ lifetime: lifetime.signal,
200
+ owner,
201
+ };
202
+ const activeCtx = withAgentStorageTransaction(txCtx, state);
203
+ try {
204
+ return await storageTransactions.run(state, async () => {
205
+ return await work(activeCtx, database);
206
+ });
207
+ }
208
+ finally {
209
+ lifetime.abort();
210
+ }
211
+ });
212
+ };
213
+ }
214
+ async function runDrizzleTransaction(database, work) {
215
+ if (isAgentSQLiteDatabase(database)) {
216
+ return await database.transaction(async (transaction) => await work(transaction));
217
+ }
218
+ return await database.transaction(async (transaction) => await work(transaction));
48
219
  }
49
220
  //# sourceMappingURL=AgentStorage.js.map
@@ -1 +1 @@
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,2DA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BAAmB,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,IAAI,EAAE;oBACnD,OAAO,MAAM,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;gBAC3C,CAAC,CAAC,CAAC;YACP,CAAC;oBAAS,CAAC;gBACP,QAAQ,CAAC,KAAK,EAAE,CAAC;YACrB,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC;AAED,KAAK,UAAU,qBAAqB,CAChC,QAAuB,EACvB,IAAkD;IAElD,IAAI,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClC,OAAO,MAAM,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IACtF,CAAC;IACD,OAAO,MAAM,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;AACtF,CAAC"}
@@ -3,8 +3,11 @@ import type { Context } from "@steve.kite/stdlib";
3
3
  import type { Agent } from "./Agent.js";
4
4
  import type { AgentBaseAwaitOptions, AgentBaseMessageOptions } from "./AgentBase.js";
5
5
  import type { AgentConfig } from "./AgentConfig.js";
6
+ import type { AgentDatabase } from "./AgentDatabase.js";
6
7
  import type { AgentMetadata } from "./AgentMetadata.js";
8
+ import type { AgentMessageAcceptance } from "./AgentMessageAcceptance.js";
7
9
  import type { AgentModel } from "./AgentModel.js";
10
+ import type { AnyAgentTool } from "./AgentTool.js";
8
11
  /** Conversation state installed atomically before a newly created agent starts. */
9
12
  export interface AgentInitialContext {
10
13
  /** The conversation installed as the agent's history before its first turn runs. */
@@ -25,16 +28,16 @@ export interface AgentCreateOptions {
25
28
  /**
26
29
  * A collection of agents addressed by ID: what an owner can ask of the agents it runs. An agent
27
30
  * exists only once it has been created with its persisted configuration; resolving one that was
28
- * never created is an error. Environment and feature settings stay fixed, while metadata changes
31
+ * never created is an error. Environment and module settings stay fixed, while metadata changes
29
32
  * through a transactional shallow merge.
30
33
  *
31
34
  * This is the full surface, including the operations that wait for an agent's run loop to reach a
32
35
  * particular point — `delete`, and anything reached through the returned `Agent`. Those are for
33
- * the caller that owns the agents' lifetime. Code running *inside* an agent, such as a feature
36
+ * the caller that owns the agents' lifetime. Code running *inside* an agent, such as a module
34
37
  * hook or a tool, is waited for by that loop and must not wait for it in turn: it should hold an
35
38
  * `AgentSystemRef`, whose every operation returns without waiting for a loop.
36
39
  */
37
- export interface AgentSystem {
40
+ export interface AgentSystem<Database extends AgentDatabase = AgentDatabase> {
38
41
  /** The models this collection offers its agents. */
39
42
  readonly models: readonly AgentModel[];
40
43
  /** Stop every agent and release this system's exclusive ownership of its durable store. */
@@ -43,7 +46,7 @@ export interface AgentSystem {
43
46
  * Create an agent with a generated or caller-supplied cuid2 identity. Configuration,
44
47
  * parentage, and optional initial context are persisted before it runs.
45
48
  */
46
- create(ctx: Context, config: AgentConfig, options?: AgentCreateOptions): Promise<Agent>;
49
+ create(ctx: Context, config: AgentConfig, options?: AgentCreateOptions): Promise<Agent<AnyAgentTool, Database>>;
47
50
  /** Close an agent and release its identity, so the same ID can be created again. */
48
51
  delete(ctx: Context, agentId: string): Promise<void>;
49
52
  /** The current configuration of an agent, or undefined when there is no such agent. */
@@ -55,14 +58,14 @@ export interface AgentSystem {
55
58
  /** The parent of an agent, or `null` when it is a root. */
56
59
  parentOf(ctx: Context, agentId: string): Promise<string | null>;
57
60
  /** The live agent for an ID, loading it if this process has not seen it yet. */
58
- resolve(ctx: Context, agentId: string): Promise<Agent>;
61
+ resolve(ctx: Context, agentId: string): Promise<Agent<AnyAgentTool, Database>>;
59
62
  /**
60
63
  * Queue a user message for an agent, injected as soon as its current response and tool batch
61
64
  * finish.
62
65
  */
63
- steer(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<void>;
66
+ steer(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<AgentMessageAcceptance>;
64
67
  /** Queue a user message for an agent that injects only when the agent would otherwise stop. */
65
- send(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<void>;
68
+ send(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<AgentMessageAcceptance>;
66
69
  /** Cancel an agent's active turn, leaving its queued messages durable for the next one. */
67
70
  abort(ctx: Context, agentId: string, options?: AgentBaseAwaitOptions): Promise<void>;
68
71
  /** Ask an agent for its conversation to be replaced by the provider's summary of it. */
@@ -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,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,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,uFAAuF;AACvF,MAAM,WAAW,kBAAkB;IAC/B,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,QAAQ,CAAC,cAAc,CAAC,EAAE,mBAA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7D,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;IAEnE,2DAA2D;IAC3D,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAEhE,gFAAgF;IAChF,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE/E;;;OAGG;IACH,KAAK,CACD,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,kBAAkB,EAC3B,OAAO,CAAC,EAAE,uBAAuB,GAAG,qBAAqB,GAC1D,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAEnC,+FAA+F;IAC/F,IAAI,CACA,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,kBAAkB,EAC3B,OAAO,CAAC,EAAE,uBAAuB,GAAG,qBAAqB,GAC1D,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAEnC,2FAA2F;IAC3F,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErF,wFAAwF;IACxF,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1F"}
@@ -1,15 +1,15 @@
1
1
  import { type Context } from "@steve.kite/stdlib";
2
2
  import type { AgentSystemRef } from "./AgentSystemRef.js";
3
3
  /**
4
- * Carry the collection that owns an agent and its features, as a reference.
4
+ * Carry the collection that owns an agent and its modules, as a reference.
5
5
  *
6
- * Only the reference travels on a context. Everything that reads one — a feature hook, a tool —
6
+ * Only the reference travels on a context. Everything that reads one — a module hook, a tool —
7
7
  * is code some run loop is waiting for, while the owner's surface holds the operations that wait
8
8
  * for a loop to reach a particular point. A collection therefore puts an `AgentSystemRef` on
9
9
  * every context it derives, and agents come back from it as `AgentRef`, so nothing reached
10
10
  * through a context can wait for the loop that is waiting for it.
11
11
  */
12
12
  export declare function withAgentSystem(ctx: Context, value: AgentSystemRef): Context;
13
- /** The collection owning the current feature or agent operation. */
13
+ /** The collection owning the current module or agent operation. */
14
14
  export declare function agentSystem(ctx: Context): AgentSystemRef | undefined;
15
15
  //# sourceMappingURL=AgentSystemContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AgentSystemContext.d.ts","sourceRoot":"","sources":["../sources/AgentSystemContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQ1D;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO,CAE5E;AAED,oEAAoE;AACpE,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,GAAG,SAAS,CAEpE"}
1
+ {"version":3,"file":"AgentSystemContext.d.ts","sourceRoot":"","sources":["../sources/AgentSystemContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQ1D;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO,CAE5E;AAED,mEAAmE;AACnE,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,GAAG,SAAS,CAEpE"}
@@ -1,10 +1,10 @@
1
1
  import { createContextNamespace } from "@steve.kite/stdlib";
2
- /** The context slot that carries the collection owning the current agent or feature operation. */
2
+ /** The context slot that carries the collection owning the current agent or module operation. */
3
3
  const agentSystemNamespace = createContextNamespace("happyAgent.agentSystem", undefined);
4
4
  /**
5
- * Carry the collection that owns an agent and its features, as a reference.
5
+ * Carry the collection that owns an agent and its modules, as a reference.
6
6
  *
7
- * Only the reference travels on a context. Everything that reads one — a feature hook, a tool —
7
+ * Only the reference travels on a context. Everything that reads one — a module hook, a tool —
8
8
  * is code some run loop is waiting for, while the owner's surface holds the operations that wait
9
9
  * for a loop to reach a particular point. A collection therefore puts an `AgentSystemRef` on
10
10
  * every context it derives, and agents come back from it as `AgentRef`, so nothing reached
@@ -13,7 +13,7 @@ const agentSystemNamespace = createContextNamespace("happyAgent.agentSystem", un
13
13
  export function withAgentSystem(ctx, value) {
14
14
  return agentSystemNamespace.set(ctx, value);
15
15
  }
16
- /** The collection owning the current feature or agent operation. */
16
+ /** The collection owning the current module or agent operation. */
17
17
  export function agentSystem(ctx) {
18
18
  return agentSystemNamespace.get(ctx);
19
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AgentSystemContext.js","sourceRoot":"","sources":["../sources/AgentSystemContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAgB,MAAM,oBAAoB,CAAC;AAI1E,kGAAkG;AAClG,MAAM,oBAAoB,GAAG,sBAAsB,CAC/C,wBAAwB,EACxB,SAAS,CACZ,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,GAAY,EAAE,KAAqB;IAC/D,OAAO,oBAAoB,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AAChD,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,WAAW,CAAC,GAAY;IACpC,OAAO,oBAAoB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACzC,CAAC"}
1
+ {"version":3,"file":"AgentSystemContext.js","sourceRoot":"","sources":["../sources/AgentSystemContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAgB,MAAM,oBAAoB,CAAC;AAI1E,iGAAiG;AACjG,MAAM,oBAAoB,GAAG,sBAAsB,CAC/C,wBAAwB,EACxB,SAAS,CACZ,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,GAAY,EAAE,KAAqB;IAC/D,OAAO,oBAAoB,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AAChD,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,WAAW,CAAC,GAAY;IACpC,OAAO,oBAAoB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACzC,CAAC"}
@@ -2,22 +2,25 @@ import type { SessionUserMessage } from "@slopus/happy-providers";
2
2
  import { type Context } from "@steve.kite/stdlib";
3
3
  import { Agent } from "./Agent.js";
4
4
  import { type AgentBaseAwaitOptions, type AgentBaseMessageOptions } from "./AgentBase.js";
5
+ import type { AgentDatabase } from "./AgentDatabase.js";
5
6
  import { type AgentConfig } from "./AgentConfig.js";
6
- import type { AgentFeature } from "./AgentFeature.js";
7
+ import type { AgentModule } from "./AgentModule.js";
7
8
  import { type AgentMetadata } from "./AgentMetadata.js";
9
+ import type { AgentMessageAcceptance } from "./AgentMessageAcceptance.js";
8
10
  import type { AgentModel } from "./AgentModel.js";
9
11
  import type { AgentProviders } from "./AgentProviders.js";
10
12
  import type { AgentStorage } from "./AgentStorage.js";
11
13
  import type { AgentCreateOptions, AgentSystem } from "./AgentSystem.js";
14
+ import type { AnyAgentTool } from "./AgentTool.js";
12
15
  /** Everything `AgentSystemLocal` needs to build and run the agents in its collection. */
13
- export interface AgentSystemLocalOptions {
16
+ export interface AgentSystemLocalOptions<Database extends AgentDatabase = AgentDatabase> {
14
17
  /**
15
- * The features every agent in this collection runs with, given as instances the caller has
18
+ * The modules every agent in this collection runs with, given as instances the caller has
16
19
  * already built and ready to serve. One instance serves the whole collection: a hook is told
17
- * which agent it is running for by the scope it is handed, so any per-agent state a feature
20
+ * which agent it is running for by the scope it is handed, so any per-agent state a module
18
21
  * keeps in memory has to be keyed by that ID rather than held as a single value.
19
22
  */
20
- readonly features?: readonly AgentFeature[];
23
+ readonly modules?: readonly AgentModule<AnyAgentTool, Database>[];
21
24
  /** The registry providers are resolved from when an agent is built. */
22
25
  readonly providers: AgentProviders;
23
26
  /** The registry ID of the provider new agents are created with. */
@@ -31,13 +34,13 @@ export interface AgentSystemLocalOptions {
31
34
  * failed load is forgotten so a later resolution can retry.
32
35
  *
33
36
  * Work serializes per agent rather than per collection: a collection-wide lock would make one
34
- * agent's feature load block every other agent, including one that load itself resolves.
37
+ * agent's module load block every other agent, including one that load itself resolves.
35
38
  *
36
39
  * This is the owner's handle, and some of what it offers waits for an agent to reach a point only
37
40
  * that agent's run loop can bring it to. Hand an `AgentSystemRef` to anything running inside an
38
41
  * agent instead.
39
42
  */
40
- export declare class AgentSystemLocal implements AgentSystem {
43
+ export declare class AgentSystemLocal<Database extends AgentDatabase = AgentDatabase> implements AgentSystem<Database> {
41
44
  #private;
42
45
  /** The models this collection offers its agents. */
43
46
  readonly models: readonly AgentModel[];
@@ -50,9 +53,9 @@ export declare class AgentSystemLocal implements AgentSystem {
50
53
  * is resolved and resumed, so by the time this returns the collection is not merely built
51
54
  * but running.
52
55
  */
53
- static create(ctx: Context, storage: AgentStorage, config: AgentSystemLocalOptions): Promise<AgentSystemLocal>;
56
+ static create<Database extends AgentDatabase>(ctx: Context, storage: AgentStorage<Database>, config: AgentSystemLocalOptions<Database>): Promise<AgentSystemLocal<Database>>;
54
57
  /**
55
- * Wire this collection to its storage, providers, and feature configuration, without reading
58
+ * Wire this collection to its storage, providers, and module configuration, without reading
56
59
  * any of it. Private: a collection is brought up by `create`, which also resumes the work
57
60
  * the storage was left holding — building one without that is building half of it.
58
61
  */
@@ -68,12 +71,12 @@ export declare class AgentSystemLocal implements AgentSystem {
68
71
  * it. Configuration and parentage are persisted before the agent runs, so every later process
69
72
  * resolves the same agent; only its metadata may subsequently change.
70
73
  *
71
- * Nothing here is undone: an agent whose features refuse to load leaves an identity that
74
+ * Nothing here is undone: an agent whose modules refuse to load leaves an identity that
72
75
  * exists, is resolvable, and will be built the next time something wants it. Taking a
73
76
  * provisional identity back after a failed build would add a compensation that can itself
74
77
  * fail.
75
78
  */
76
- create(ctx: Context, config: AgentConfig, options?: AgentCreateOptions): Promise<Agent>;
79
+ create(ctx: Context, config: AgentConfig, options?: AgentCreateOptions): Promise<Agent<AnyAgentTool, Database>>;
77
80
  /**
78
81
  * Close an agent and release its identity, so the same ID can be created again. Used to undo
79
82
  * a creation whose follow-up work failed; an ID that was never created is left alone.
@@ -97,11 +100,11 @@ export declare class AgentSystemLocal implements AgentSystem {
97
100
  * The live agent for an ID, loading and starting it if this process has not seen it yet.
98
101
  * Concurrent resolutions of the same ID share one load.
99
102
  */
100
- resolve(ctx: Context, agentId: string): Promise<Agent>;
103
+ resolve(ctx: Context, agentId: string): Promise<Agent<AnyAgentTool, Database>>;
101
104
  /** Queue a steered message for an agent. */
102
- steer(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<void>;
105
+ steer(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<AgentMessageAcceptance>;
103
106
  /** Queue a message for an agent. */
104
- send(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<void>;
107
+ send(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<AgentMessageAcceptance>;
105
108
  /** Cancel an agent's active turn, leaving its queued messages durable for the next one. */
106
109
  abort(ctx: Context, agentId: string, options?: AgentBaseAwaitOptions): Promise<void>;
107
110
  /** Ask an agent for its conversation to be replaced by the provider's summary of it. */
@@ -1 +1 @@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