@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.
- package/README.md +62 -9
- package/dist/Agent.d.ts +27 -22
- package/dist/Agent.d.ts.map +1 -1
- package/dist/Agent.js +120 -110
- package/dist/Agent.js.map +1 -1
- package/dist/AgentBase.d.ts +27 -13
- package/dist/AgentBase.d.ts.map +1 -1
- package/dist/AgentBase.js +657 -151
- package/dist/AgentBase.js.map +1 -1
- package/dist/AgentBaseHooks.d.ts +58 -32
- package/dist/AgentBaseHooks.d.ts.map +1 -1
- package/dist/AgentBasePending.d.ts +6 -2
- package/dist/AgentBasePending.d.ts.map +1 -1
- package/dist/AgentBasePending.js +7 -0
- package/dist/AgentBasePending.js.map +1 -1
- package/dist/AgentConfig.d.ts +20 -13
- package/dist/AgentConfig.d.ts.map +1 -1
- package/dist/AgentConfig.js +32 -12
- package/dist/AgentConfig.js.map +1 -1
- package/dist/AgentContexts.d.ts +18 -1
- package/dist/AgentContexts.d.ts.map +1 -1
- package/dist/AgentContexts.js +24 -1
- package/dist/AgentContexts.js.map +1 -1
- package/dist/AgentDatabase.d.ts +35 -0
- package/dist/AgentDatabase.d.ts.map +1 -0
- package/dist/AgentDatabase.js +30 -0
- package/dist/AgentDatabase.js.map +1 -0
- package/dist/AgentKV.d.ts +19 -6
- package/dist/AgentKV.d.ts.map +1 -1
- package/dist/AgentKV.js +110 -43
- package/dist/AgentKV.js.map +1 -1
- package/dist/AgentMessageAcceptance.d.ts +14 -0
- package/dist/AgentMessageAcceptance.d.ts.map +1 -0
- package/dist/AgentMessageAcceptance.js +2 -0
- package/dist/AgentMessageAcceptance.js.map +1 -0
- package/dist/AgentMetadata.d.ts +37 -0
- package/dist/AgentMetadata.d.ts.map +1 -0
- package/dist/AgentMetadata.js +74 -0
- package/dist/AgentMetadata.js.map +1 -0
- package/dist/AgentModule.d.ts +209 -0
- package/dist/AgentModule.d.ts.map +1 -0
- package/dist/AgentModule.js +2 -0
- package/dist/AgentModule.js.map +1 -0
- package/dist/{AgentFeatureAction.d.ts → AgentModuleAction.d.ts} +7 -2
- package/dist/AgentModuleAction.d.ts.map +1 -0
- package/dist/AgentModuleAction.js +2 -0
- package/dist/AgentModuleAction.js.map +1 -0
- package/dist/AgentPermissionMode.d.ts +1 -1
- package/dist/AgentPermissionMode.js +1 -1
- package/dist/AgentPersistence.d.ts +20 -7
- package/dist/AgentPersistence.d.ts.map +1 -1
- package/dist/AgentPersistenceDrizzle.d.ts +31 -0
- package/dist/AgentPersistenceDrizzle.d.ts.map +1 -0
- package/dist/AgentPersistenceDrizzle.js +99 -0
- package/dist/AgentPersistenceDrizzle.js.map +1 -0
- package/dist/AgentRef.d.ts +17 -9
- package/dist/AgentRef.d.ts.map +1 -1
- package/dist/AgentRef.js +16 -9
- package/dist/AgentRef.js.map +1 -1
- package/dist/AgentStorage.d.ts +33 -13
- package/dist/AgentStorage.d.ts.map +1 -1
- package/dist/AgentStorage.js +174 -3
- package/dist/AgentStorage.js.map +1 -1
- package/dist/AgentSystem.d.ts +34 -12
- package/dist/AgentSystem.d.ts.map +1 -1
- package/dist/AgentSystemContext.d.ts +3 -3
- package/dist/AgentSystemContext.d.ts.map +1 -1
- package/dist/AgentSystemContext.js +4 -4
- package/dist/AgentSystemContext.js.map +1 -1
- package/dist/AgentSystemLocal.d.ts +30 -21
- package/dist/AgentSystemLocal.d.ts.map +1 -1
- package/dist/AgentSystemLocal.js +226 -59
- package/dist/AgentSystemLocal.js.map +1 -1
- package/dist/AgentSystemRef.d.ts +21 -10
- package/dist/AgentSystemRef.d.ts.map +1 -1
- package/dist/AgentSystemRef.js +41 -9
- package/dist/AgentSystemRef.js.map +1 -1
- package/dist/AgentTool.d.ts +16 -1
- package/dist/AgentTool.d.ts.map +1 -1
- package/dist/AgentTool.js.map +1 -1
- package/dist/index.d.ts +10 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/dist/AgentFeature.d.ts +0 -177
- package/dist/AgentFeature.d.ts.map +0 -1
- package/dist/AgentFeature.js +0 -2
- package/dist/AgentFeature.js.map +0 -1
- package/dist/AgentFeatureAction.d.ts.map +0 -1
- package/dist/AgentFeatureAction.js +0 -2
- package/dist/AgentFeatureAction.js.map +0 -1
package/dist/AgentStorage.js
CHANGED
|
@@ -1,17 +1,38 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
package/dist/AgentStorage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentStorage.js","sourceRoot":"","sources":["../sources/AgentStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AgentStorage.js","sourceRoot":"","sources":["../sources/AgentStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAgB,MAAM,oBAAoB,CAAC;AAE9E,OAAO,EACH,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,GAKxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACH,uBAAuB,EACvB,2BAA2B,GAE9B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,EACH,uBAAuB,GAE1B,MAAM,8BAA8B,CAAC;AAgCtC,MAAM,mBAAmB,GAAG,IAAI,iBAAiB,EAAkC,CAAC;AAEpF,wFAAwF;AACxF,MAAM,OAAO,YAAY;IACrB,+BAA+B;IACtB,QAAQ,CAAW;IAC5B,mEAAmE;IAC1D,EAAE,CAAU;IACrB,kEAAkE;IACzD,YAAY,CAA8C;IACnE,2DAA2D;IAClD,YAAY,CAAwC;IAC7D,+EAA+E;IACtE,QAAQ,CAA2C;IAC5D,wEAAwE;IACxE,MAAM,GAAG,KAAK,CAAC;IAEf,YAAY,OAAsC;QAC9C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;QACxC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,MAAM,KAAK,GAAG,EAAE,CAAC;QACjB,MAAM,cAAc,GAChB,OAAO,CAAC,WAAW,IAAI,6BAA6B,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC3E,MAAM,WAAW,GAA6C;YAC1D,QAA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E,QAAQ,EAAE,EAAE;YACpD,MAAM,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAC;YACvC,MAAM,KAAK,GAAmC;gBAC1C,QAAQ;gBACR,QAAQ,EAAE,QAAQ,CAAC,MAAM;gBACzB,KAAK;aACR,CAAC;YACF,MAAM,SAAS,GAAG,2BAA2B,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAC5D,IAAI,CAAC;gBACD,OAAO,MAAM,mBAAmB,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"}
|
package/dist/AgentSystem.d.ts
CHANGED
|
@@ -3,47 +3,69 @@ 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";
|
|
7
|
+
import type { AgentMetadata } from "./AgentMetadata.js";
|
|
8
|
+
import type { AgentMessageAcceptance } from "./AgentMessageAcceptance.js";
|
|
6
9
|
import type { AgentModel } from "./AgentModel.js";
|
|
10
|
+
import type { AnyAgentTool } from "./AgentTool.js";
|
|
7
11
|
/** Conversation state installed atomically before a newly created agent starts. */
|
|
8
12
|
export interface AgentInitialContext {
|
|
9
13
|
/** The conversation installed as the agent's history before its first turn runs. */
|
|
10
14
|
readonly messages: readonly SessionMessage[];
|
|
11
15
|
}
|
|
16
|
+
/** Optional identity, ancestry, and conversation supplied while creating one agent. */
|
|
17
|
+
export interface AgentCreateOptions {
|
|
18
|
+
/** Client-chosen cuid2 identity; generated when omitted. */
|
|
19
|
+
readonly id?: string;
|
|
20
|
+
/** The conversation installed before the agent's first turn. */
|
|
21
|
+
readonly initialContext?: AgentInitialContext;
|
|
22
|
+
/**
|
|
23
|
+
* The parent agent. Omission inherits the creating reference or calling agent, `null` creates
|
|
24
|
+
* a root, and an explicit ID must already exist.
|
|
25
|
+
*/
|
|
26
|
+
readonly parent?: string | null;
|
|
27
|
+
}
|
|
12
28
|
/**
|
|
13
29
|
* A collection of agents addressed by ID: what an owner can ask of the agents it runs. An agent
|
|
14
|
-
* exists only once it has been created with its configuration
|
|
15
|
-
*
|
|
30
|
+
* exists only once it has been created with its persisted configuration; resolving one that was
|
|
31
|
+
* never created is an error. Environment and module settings stay fixed, while metadata changes
|
|
32
|
+
* through a transactional shallow merge.
|
|
16
33
|
*
|
|
17
34
|
* This is the full surface, including the operations that wait for an agent's run loop to reach a
|
|
18
35
|
* particular point — `delete`, and anything reached through the returned `Agent`. Those are for
|
|
19
|
-
* the caller that owns the agents' lifetime. Code running *inside* an agent, such as a
|
|
36
|
+
* the caller that owns the agents' lifetime. Code running *inside* an agent, such as a module
|
|
20
37
|
* hook or a tool, is waited for by that loop and must not wait for it in turn: it should hold an
|
|
21
38
|
* `AgentSystemRef`, whose every operation returns without waiting for a loop.
|
|
22
39
|
*/
|
|
23
|
-
export interface AgentSystem {
|
|
40
|
+
export interface AgentSystem<Database extends AgentDatabase = AgentDatabase> {
|
|
24
41
|
/** The models this collection offers its agents. */
|
|
25
42
|
readonly models: readonly AgentModel[];
|
|
26
43
|
/** Stop every agent and release this system's exclusive ownership of its durable store. */
|
|
27
44
|
close(ctx: Context): Promise<void>;
|
|
28
45
|
/**
|
|
29
|
-
* Create an agent with a
|
|
30
|
-
*
|
|
31
|
-
* the agent runs; a creation that fails to produce an agent leaves no identity behind.
|
|
46
|
+
* Create an agent with a generated or caller-supplied cuid2 identity. Configuration,
|
|
47
|
+
* parentage, and optional initial context are persisted before it runs.
|
|
32
48
|
*/
|
|
33
|
-
create(ctx: Context, config: AgentConfig,
|
|
49
|
+
create(ctx: Context, config: AgentConfig, options?: AgentCreateOptions): Promise<Agent<AnyAgentTool, Database>>;
|
|
34
50
|
/** Close an agent and release its identity, so the same ID can be created again. */
|
|
35
51
|
delete(ctx: Context, agentId: string): Promise<void>;
|
|
36
|
-
/** The configuration an agent
|
|
52
|
+
/** The current configuration of an agent, or undefined when there is no such agent. */
|
|
37
53
|
config(ctx: Context, agentId: string): Promise<AgentConfig | undefined>;
|
|
54
|
+
/** Shallow-merge fields into an agent's immutable metadata. */
|
|
55
|
+
updateMetadata(ctx: Context, agentId: string, update: AgentMetadata): Promise<void>;
|
|
56
|
+
/** The direct children of an agent, in durable key order. */
|
|
57
|
+
childOf(ctx: Context, agentId: string): Promise<readonly string[]>;
|
|
58
|
+
/** The parent of an agent, or `null` when it is a root. */
|
|
59
|
+
parentOf(ctx: Context, agentId: string): Promise<string | null>;
|
|
38
60
|
/** The live agent for an ID, loading it if this process has not seen it yet. */
|
|
39
|
-
resolve(ctx: Context, agentId: string): Promise<Agent
|
|
61
|
+
resolve(ctx: Context, agentId: string): Promise<Agent<AnyAgentTool, Database>>;
|
|
40
62
|
/**
|
|
41
63
|
* Queue a user message for an agent, injected as soon as its current response and tool batch
|
|
42
64
|
* finish.
|
|
43
65
|
*/
|
|
44
|
-
steer(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<
|
|
66
|
+
steer(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<AgentMessageAcceptance>;
|
|
45
67
|
/** Queue a user message for an agent that injects only when the agent would otherwise stop. */
|
|
46
|
-
send(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<
|
|
68
|
+
send(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<AgentMessageAcceptance>;
|
|
47
69
|
/** Cancel an agent's active turn, leaving its queued messages durable for the next one. */
|
|
48
70
|
abort(ctx: Context, agentId: string, options?: AgentBaseAwaitOptions): Promise<void>;
|
|
49
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,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
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;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,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
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
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,21 +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 {
|
|
7
|
+
import type { AgentModule } from "./AgentModule.js";
|
|
8
|
+
import { type AgentMetadata } from "./AgentMetadata.js";
|
|
9
|
+
import type { AgentMessageAcceptance } from "./AgentMessageAcceptance.js";
|
|
7
10
|
import type { AgentModel } from "./AgentModel.js";
|
|
8
11
|
import type { AgentProviders } from "./AgentProviders.js";
|
|
9
12
|
import type { AgentStorage } from "./AgentStorage.js";
|
|
10
|
-
import type {
|
|
13
|
+
import type { AgentCreateOptions, AgentSystem } from "./AgentSystem.js";
|
|
14
|
+
import type { AnyAgentTool } from "./AgentTool.js";
|
|
11
15
|
/** Everything `AgentSystemLocal` needs to build and run the agents in its collection. */
|
|
12
|
-
export interface AgentSystemLocalOptions {
|
|
16
|
+
export interface AgentSystemLocalOptions<Database extends AgentDatabase = AgentDatabase> {
|
|
13
17
|
/**
|
|
14
|
-
* The
|
|
18
|
+
* The modules every agent in this collection runs with, given as instances the caller has
|
|
15
19
|
* already built and ready to serve. One instance serves the whole collection: a hook is told
|
|
16
|
-
* which agent it is running for by the scope it is handed, so any per-agent state a
|
|
20
|
+
* which agent it is running for by the scope it is handed, so any per-agent state a module
|
|
17
21
|
* keeps in memory has to be keyed by that ID rather than held as a single value.
|
|
18
22
|
*/
|
|
19
|
-
readonly
|
|
23
|
+
readonly modules?: readonly AgentModule<AnyAgentTool, Database>[];
|
|
20
24
|
/** The registry providers are resolved from when an agent is built. */
|
|
21
25
|
readonly providers: AgentProviders;
|
|
22
26
|
/** The registry ID of the provider new agents are created with. */
|
|
@@ -30,13 +34,13 @@ export interface AgentSystemLocalOptions {
|
|
|
30
34
|
* failed load is forgotten so a later resolution can retry.
|
|
31
35
|
*
|
|
32
36
|
* Work serializes per agent rather than per collection: a collection-wide lock would make one
|
|
33
|
-
* agent's
|
|
37
|
+
* agent's module load block every other agent, including one that load itself resolves.
|
|
34
38
|
*
|
|
35
39
|
* This is the owner's handle, and some of what it offers waits for an agent to reach a point only
|
|
36
40
|
* that agent's run loop can bring it to. Hand an `AgentSystemRef` to anything running inside an
|
|
37
41
|
* agent instead.
|
|
38
42
|
*/
|
|
39
|
-
export declare class AgentSystemLocal implements AgentSystem {
|
|
43
|
+
export declare class AgentSystemLocal<Database extends AgentDatabase = AgentDatabase> implements AgentSystem<Database> {
|
|
40
44
|
#private;
|
|
41
45
|
/** The models this collection offers its agents. */
|
|
42
46
|
readonly models: readonly AgentModel[];
|
|
@@ -49,9 +53,9 @@ export declare class AgentSystemLocal implements AgentSystem {
|
|
|
49
53
|
* is resolved and resumed, so by the time this returns the collection is not merely built
|
|
50
54
|
* but running.
|
|
51
55
|
*/
|
|
52
|
-
static create(ctx: Context, storage: AgentStorage
|
|
56
|
+
static create<Database extends AgentDatabase>(ctx: Context, storage: AgentStorage<Database>, config: AgentSystemLocalOptions<Database>): Promise<AgentSystemLocal<Database>>;
|
|
53
57
|
/**
|
|
54
|
-
* Wire this collection to its storage, providers, and
|
|
58
|
+
* Wire this collection to its storage, providers, and module configuration, without reading
|
|
55
59
|
* any of it. Private: a collection is brought up by `create`, which also resumes the work
|
|
56
60
|
* the storage was left holding — building one without that is building half of it.
|
|
57
61
|
*/
|
|
@@ -62,18 +66,17 @@ export declare class AgentSystemLocal implements AgentSystem {
|
|
|
62
66
|
*/
|
|
63
67
|
close(ctx: Context): Promise<void>;
|
|
64
68
|
/**
|
|
65
|
-
* Create an agent
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* agent exactly as it was created.
|
|
69
|
+
* Create and resolve an agent. Its identity is either a validated caller-supplied cuid2 or
|
|
70
|
+
* allocated here, and the transaction refuses an existing identity rather than overwriting
|
|
71
|
+
* it. Configuration and parentage are persisted before the agent runs, so every later process
|
|
72
|
+
* resolves the same agent; only its metadata may subsequently change.
|
|
70
73
|
*
|
|
71
|
-
* Nothing here is undone: an agent whose
|
|
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,
|
|
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.
|
|
@@ -85,17 +88,23 @@ export declare class AgentSystemLocal implements AgentSystem {
|
|
|
85
88
|
* what clears it.
|
|
86
89
|
*/
|
|
87
90
|
delete(ctx: Context, agentId: string): Promise<void>;
|
|
88
|
-
/** The configuration an agent
|
|
91
|
+
/** The current configuration of an agent, or undefined when there is no such agent. */
|
|
89
92
|
config(ctx: Context, agentId: string): Promise<AgentConfig | undefined>;
|
|
93
|
+
/** Shallow-merge fields into one agent's immutable metadata. */
|
|
94
|
+
updateMetadata(ctx: Context, agentId: string, update: AgentMetadata): Promise<void>;
|
|
95
|
+
/** The direct children of an existing agent, in durable key order. */
|
|
96
|
+
childOf(ctx: Context, agentId: string): Promise<readonly string[]>;
|
|
97
|
+
/** The parent of an existing agent, or `null` when it is a root. */
|
|
98
|
+
parentOf(ctx: Context, agentId: string): Promise<string | null>;
|
|
90
99
|
/**
|
|
91
100
|
* The live agent for an ID, loading and starting it if this process has not seen it yet.
|
|
92
101
|
* Concurrent resolutions of the same ID share one load.
|
|
93
102
|
*/
|
|
94
|
-
resolve(ctx: Context, agentId: string): Promise<Agent
|
|
103
|
+
resolve(ctx: Context, agentId: string): Promise<Agent<AnyAgentTool, Database>>;
|
|
95
104
|
/** Queue a steered message for an agent. */
|
|
96
|
-
steer(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<
|
|
105
|
+
steer(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<AgentMessageAcceptance>;
|
|
97
106
|
/** Queue a message for an agent. */
|
|
98
|
-
send(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<
|
|
107
|
+
send(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<AgentMessageAcceptance>;
|
|
99
108
|
/** Cancel an agent's active turn, leaving its queued messages durable for the next one. */
|
|
100
109
|
abort(ctx: Context, agentId: string, options?: AgentBaseAwaitOptions): Promise<void>;
|
|
101
110
|
/** Ask an agent for its conversation to be replaced by the provider's summary of it. */
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"AgentSystemLocal.d.ts","sourceRoot":"","sources":["../sources/AgentSystemLocal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGlF,OAAO,EAKH,KAAK,OAAO,EACf,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAQ1F,OAAO,KAAK,EAAE,aAAa,EAAuB,MAAM,oBAAoB,CAAC;AAG7E,OAAO,EAIH,KAAK,WAAW,EACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACR,WAAW,EAGd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAiC,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGxE,OAAO,KAAK,EAAE,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