@slopus/happy-agent-base 0.0.0 → 0.0.2

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 (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +640 -15
  3. package/dist/Agent.d.ts +86 -0
  4. package/dist/Agent.d.ts.map +1 -0
  5. package/dist/Agent.js +326 -0
  6. package/dist/Agent.js.map +1 -0
  7. package/dist/AgentBase.d.ts +340 -0
  8. package/dist/AgentBase.d.ts.map +1 -0
  9. package/dist/AgentBase.js +2295 -0
  10. package/dist/AgentBase.js.map +1 -0
  11. package/dist/AgentBaseHooks.d.ts +156 -0
  12. package/dist/AgentBaseHooks.d.ts.map +1 -0
  13. package/dist/AgentBaseHooks.js +2 -0
  14. package/dist/AgentBaseHooks.js.map +1 -0
  15. package/dist/AgentBasePending.d.ts +49 -0
  16. package/dist/AgentBasePending.d.ts.map +1 -0
  17. package/dist/AgentBasePending.js +73 -0
  18. package/dist/AgentBasePending.js.map +1 -0
  19. package/dist/AgentBaseState.d.ts +13 -0
  20. package/dist/AgentBaseState.d.ts.map +1 -0
  21. package/dist/AgentBaseState.js +2 -0
  22. package/dist/AgentBaseState.js.map +1 -0
  23. package/dist/AgentBaseStoreLock.d.ts +16 -0
  24. package/dist/AgentBaseStoreLock.d.ts.map +1 -0
  25. package/dist/AgentBaseStoreLock.js +37 -0
  26. package/dist/AgentBaseStoreLock.js.map +1 -0
  27. package/dist/AgentConfig.d.ts +67 -0
  28. package/dist/AgentConfig.d.ts.map +1 -0
  29. package/dist/AgentConfig.js +81 -0
  30. package/dist/AgentConfig.js.map +1 -0
  31. package/dist/AgentContexts.d.ts +40 -0
  32. package/dist/AgentContexts.d.ts.map +1 -0
  33. package/dist/AgentContexts.js +70 -0
  34. package/dist/AgentContexts.js.map +1 -0
  35. package/dist/AgentFeature.d.ts +119 -0
  36. package/dist/AgentFeature.d.ts.map +1 -0
  37. package/dist/AgentFeature.js +2 -0
  38. package/dist/AgentFeature.js.map +1 -0
  39. package/dist/AgentFeatureAction.d.ts +16 -0
  40. package/dist/AgentFeatureAction.d.ts.map +1 -0
  41. package/dist/AgentFeatureAction.js +2 -0
  42. package/dist/AgentFeatureAction.js.map +1 -0
  43. package/dist/AgentKV.d.ts +63 -0
  44. package/dist/AgentKV.d.ts.map +1 -0
  45. package/dist/AgentKV.js +122 -0
  46. package/dist/AgentKV.js.map +1 -0
  47. package/dist/AgentModel.d.ts +17 -0
  48. package/dist/AgentModel.d.ts.map +1 -0
  49. package/dist/AgentModel.js +2 -0
  50. package/dist/AgentModel.js.map +1 -0
  51. package/dist/AgentPersistence.d.ts +95 -0
  52. package/dist/AgentPersistence.d.ts.map +1 -0
  53. package/dist/AgentPersistence.js +2 -0
  54. package/dist/AgentPersistence.js.map +1 -0
  55. package/dist/AgentProviders.d.ts +22 -0
  56. package/dist/AgentProviders.d.ts.map +1 -0
  57. package/dist/AgentProviders.js +35 -0
  58. package/dist/AgentProviders.js.map +1 -0
  59. package/dist/AgentRef.d.ts +41 -0
  60. package/dist/AgentRef.d.ts.map +1 -0
  61. package/dist/AgentRef.js +60 -0
  62. package/dist/AgentRef.js.map +1 -0
  63. package/dist/AgentStorage.d.ts +19 -0
  64. package/dist/AgentStorage.d.ts.map +1 -0
  65. package/dist/AgentStorage.js +16 -0
  66. package/dist/AgentStorage.js.map +1 -0
  67. package/dist/AgentSystem.d.ts +50 -0
  68. package/dist/AgentSystem.d.ts.map +1 -0
  69. package/dist/AgentSystem.js +2 -0
  70. package/dist/AgentSystem.js.map +1 -0
  71. package/dist/AgentSystemContext.d.ts +15 -0
  72. package/dist/AgentSystemContext.d.ts.map +1 -0
  73. package/dist/AgentSystemContext.js +20 -0
  74. package/dist/AgentSystemContext.js.map +1 -0
  75. package/dist/AgentSystemLocal.d.ts +103 -0
  76. package/dist/AgentSystemLocal.d.ts.map +1 -0
  77. package/dist/AgentSystemLocal.js +282 -0
  78. package/dist/AgentSystemLocal.js.map +1 -0
  79. package/dist/AgentSystemRef.d.ts +56 -0
  80. package/dist/AgentSystemRef.d.ts.map +1 -0
  81. package/dist/AgentSystemRef.js +75 -0
  82. package/dist/AgentSystemRef.js.map +1 -0
  83. package/dist/AgentTaskContext.d.ts +17 -0
  84. package/dist/AgentTaskContext.d.ts.map +1 -0
  85. package/dist/AgentTaskContext.js +26 -0
  86. package/dist/AgentTaskContext.js.map +1 -0
  87. package/dist/AgentTool.d.ts +87 -0
  88. package/dist/AgentTool.d.ts.map +1 -0
  89. package/dist/AgentTool.js +5 -0
  90. package/dist/AgentTool.js.map +1 -0
  91. package/dist/index.d.ts +24 -1
  92. package/dist/index.d.ts.map +1 -1
  93. package/dist/index.js +31 -1
  94. package/dist/index.js.map +1 -1
  95. package/dist/models.d.ts +62 -0
  96. package/dist/models.d.ts.map +1 -0
  97. package/dist/models.js +185 -0
  98. package/dist/models.js.map +1 -0
  99. package/package.json +44 -37
@@ -0,0 +1,282 @@
1
+ import { createId } from "@paralleldrive/cuid2";
2
+ import { Value } from "@sinclair/typebox/value";
3
+ import { asyncLock } from "@steve.kite/stdlib";
4
+ import { Agent } from "./Agent.js";
5
+ import {} from "./AgentBase.js";
6
+ import { agentBaseWithStoreStill } from "./AgentBaseStoreLock.js";
7
+ import { agentConfigSchema, withAgentConfig } from "./AgentConfig.js";
8
+ import { withAgentSystem } from "./AgentSystemContext.js";
9
+ import { AgentSystemRef } from "./AgentSystemRef.js";
10
+ /**
11
+ * The `AgentSystem` backed by this process: it lazily builds and owns the `Agent` instances for
12
+ * the identities its storage holds. Concurrent resolutions of the same ID share one load, while a
13
+ * failed load is forgotten so a later resolution can retry.
14
+ *
15
+ * Identity is durable and shared, so more than one live collection can be working over one
16
+ * storage. Everything below therefore serializes per agent rather than per collection — a
17
+ * collection-wide lock would make one agent's feature load block every other agent, including one
18
+ * that load itself resolves — and treats storage, not memory, as the authority on who exists.
19
+ *
20
+ * This is the owner's handle, and some of what it offers waits for an agent to reach a point only
21
+ * that agent's run loop can bring it to. Hand an `AgentSystemRef` to anything running inside an
22
+ * agent instead.
23
+ */
24
+ export class AgentSystemLocal {
25
+ /** The models this collection offers its agents. */
26
+ models;
27
+ /**
28
+ * What this collection looks like from inside one of its agents, and the only form of it a
29
+ * derived context ever carries.
30
+ */
31
+ #ref = new AgentSystemRef(this);
32
+ /** The collection's feature instances, every one of them serving every agent it builds. */
33
+ #features;
34
+ /** Where the collection's identities, configuration, and per-agent state are durable. */
35
+ #storage;
36
+ /** The registry providers are resolved from when an agent is built. */
37
+ #providers;
38
+ /** The registry ID of the provider new agents are created with. */
39
+ #provider;
40
+ /** The configuration each identity was created with. */
41
+ #configs;
42
+ /**
43
+ * The root of the store features share across the collection. Each feature works under its
44
+ * own scope of it, which is where anything outliving one agent's conversation belongs.
45
+ */
46
+ #sharedFeatureKV;
47
+ /** The live `Agent` instances this process has built, keyed by identity. */
48
+ #agents = new Map();
49
+ // One agent has one store for the life of the collection, so inspecting an agent's durable
50
+ // work and running that agent never end up looking at two different stores.
51
+ #persistences = new Map();
52
+ /** Per-agent locks handed out by `#lockFor`, created lazily the first time an ID is touched. */
53
+ #locks = new Map();
54
+ /**
55
+ * Bring up a collection over one storage and carry on where the last process left off.
56
+ *
57
+ * A collection is not a passive registry that happens to be asked for agents later: whatever
58
+ * was running when the previous process ended is still owed an answer, and this is what
59
+ * makes it happen. Every identity the storage holds is examined, and each one that owes work
60
+ * is resolved and resumed, so by the time this returns the collection is not merely built
61
+ * but running. An identity another owner is still creating is left alone, since until that
62
+ * creation commits there is no agent to resume.
63
+ */
64
+ static async create(ctx, storage, config) {
65
+ const system = new AgentSystemLocal(storage, config);
66
+ await system.#start(ctx);
67
+ return system;
68
+ }
69
+ /**
70
+ * Wire this collection to its storage, providers, and feature configuration, without reading
71
+ * any of it. Private: a collection is brought up by `create`, which also resumes the work
72
+ * the storage was left holding — building one without that is building half of it.
73
+ */
74
+ constructor(storage, options) {
75
+ this.#features = options.features ?? [];
76
+ this.#storage = storage;
77
+ this.#providers = options.providers;
78
+ this.#provider = options.provider;
79
+ this.models = [...options.models];
80
+ this.#configs = storage.kv.scoped("config");
81
+ this.#sharedFeatureKV = storage.kv.scoped("features");
82
+ }
83
+ /**
84
+ * Create an agent with the configuration it keeps for its whole life, and resolve it. The
85
+ * identity is allocated here and nowhere else: it is a cuid2, globally unique, so a new
86
+ * agent never lands on an identity that already exists or on a store something else wrote.
87
+ * The configuration is persisted before the agent runs, so every later process resolves the
88
+ * agent exactly as it was created.
89
+ *
90
+ * Nothing here is ever undone: an agent whose features refuse to load leaves an identity
91
+ * that exists, is resolvable, and will be built the next time something wants it. The
92
+ * alternative — writing a provisional identity and taking it back when the build fails —
93
+ * has to get the taking-back right in the presence of crashes and other owners, and a
94
+ * compensation that can itself fail is not a guarantee.
95
+ */
96
+ async create(ctx, config, initialContext) {
97
+ const agentId = createId();
98
+ if (!Value.Check(agentConfigSchema, config)) {
99
+ throw new Error(`The configuration for agent "${agentId}" is not valid.`);
100
+ }
101
+ // The caller keeps its own object, and may go on editing it. What was created is what
102
+ // was passed at this moment, so storage and this agent's context both get a copy.
103
+ const owned = structuredClone(config);
104
+ return await this.#lockFor(agentId).runInLock(ctx, async (lockCtx) => {
105
+ await this.#configs.write(lockCtx, agentId, owned);
106
+ if (initialContext !== undefined) {
107
+ await this.#seedInitialContext(lockCtx, agentId, initialContext.messages);
108
+ }
109
+ const agent = await this.#instantiate(lockCtx, agentId, owned);
110
+ if (agent === undefined)
111
+ throw new Error(`Agent "${agentId}" could not be built.`);
112
+ return agent;
113
+ });
114
+ }
115
+ /**
116
+ * Close an agent and release its identity, so the same ID can be created again. Used to undo
117
+ * a creation whose follow-up work failed; an ID that was never created is left alone.
118
+ *
119
+ * What the agent wrote is left where it is. The close finishes first, so the store holds a
120
+ * whole conversation rather than a truncated one, and that record is worth more here than the
121
+ * space it takes: whoever deleted the agent may still want to know what it did. The next
122
+ * identity created under this ID starts from an empty store all the same, because creation is
123
+ * what clears it.
124
+ */
125
+ async delete(ctx, agentId) {
126
+ await this.#lockFor(agentId).runInLock(ctx, async (lockCtx) => {
127
+ const agent = this.#agents.get(agentId);
128
+ this.#agents.delete(agentId);
129
+ await agent?.close();
130
+ await this.#configs.delete(lockCtx, agentId);
131
+ this.#persistences.delete(agentId);
132
+ });
133
+ }
134
+ /** Install a projected conversation before the new agent is started. */
135
+ async #seedInitialContext(ctx, agentId, messages) {
136
+ if (messages.length === 0)
137
+ return;
138
+ const persistence = this.#persistenceFor(agentId);
139
+ await agentBaseWithStoreStill(ctx, persistence, (storeCtx) => persistence.transaction(storeCtx, async (txCtx) => {
140
+ await persistence.append(txCtx, {
141
+ type: "compaction",
142
+ messages: structuredClone(messages),
143
+ });
144
+ }));
145
+ }
146
+ /** The configuration an agent was created with, or undefined when there is no such agent. */
147
+ async config(ctx, agentId) {
148
+ const stored = await this.#configs.read(ctx, agentId);
149
+ if (stored === undefined)
150
+ return undefined;
151
+ if (!Value.Check(agentConfigSchema, stored)) {
152
+ throw new Error(`The stored configuration of agent "${agentId}" is not valid.`);
153
+ }
154
+ return stored;
155
+ }
156
+ /**
157
+ * The live agent for an ID, loading and starting it if this process has not seen it yet.
158
+ * Concurrent resolutions of the same ID share one load.
159
+ */
160
+ async resolve(ctx, agentId) {
161
+ const existing = this.#agents.get(agentId);
162
+ if (existing !== undefined)
163
+ return existing;
164
+ return await this.#lockFor(agentId).runInLock(ctx, async (lockCtx) => {
165
+ const resolved = this.#agents.get(agentId);
166
+ if (resolved !== undefined)
167
+ return resolved;
168
+ const config = await this.config(lockCtx, agentId);
169
+ if (config === undefined) {
170
+ throw new Error(`Agent "${agentId}" has not been created.`);
171
+ }
172
+ const agent = await this.#instantiate(lockCtx, agentId, config);
173
+ if (agent === undefined)
174
+ throw new Error(`Agent "${agentId}" could not be built.`);
175
+ // Building an agent takes as long as its features do, and identity is not this
176
+ // collection's to hold still for that: another owner may have deleted the ID, or a
177
+ // creation this resolution overtook may have rolled it back. Handing back an agent
178
+ // for an identity that no longer exists strands its caller with a live object no
179
+ // restart would ever reproduce, so the answer is checked before it is given.
180
+ if ((await this.config(lockCtx, agentId)) === undefined) {
181
+ this.#agents.delete(agentId);
182
+ await agent.close();
183
+ throw new Error(`Agent "${agentId}" was deleted while it was being resolved.`);
184
+ }
185
+ return agent;
186
+ });
187
+ }
188
+ /**
189
+ * Build one agent and put it to work. Called with the agent's lock held, and only for an ID
190
+ * that has no live instance yet.
191
+ */
192
+ async #instantiate(ctx, agentId, config, onlyIfActive = false) {
193
+ const agentCtx = withAgentConfig(withAgentSystem(ctx, this.#ref), config);
194
+ const options = {
195
+ id: agentId,
196
+ providers: this.#providers,
197
+ provider: this.#provider,
198
+ persistence: this.#persistenceFor(agentId),
199
+ sharedKV: this.#sharedFeatureKV,
200
+ // The collection's features come first, so the instructions they contribute — the
201
+ // system prompt above all — open every agent's prompt.
202
+ features: this.#features,
203
+ };
204
+ // An identity built here may already have durable state — this is the path a restart
205
+ // resolves through — so the agent is loaded rather than created, and knows whether it
206
+ // has work left before anything asks it. Bringing a collection up asks only for the
207
+ // agents that do; anything else resolving an agent wants it whether it owes work or not.
208
+ const agent = onlyIfActive
209
+ ? await Agent.loadActive(agentCtx, options)
210
+ : await Agent.load(agentCtx, options);
211
+ if (agent === undefined)
212
+ return undefined;
213
+ agent.start();
214
+ this.#agents.set(agentId, agent);
215
+ return agent;
216
+ }
217
+ /**
218
+ * Resolve and resume every agent that has work left from before this process started.
219
+ *
220
+ * The active index is a fast answer, not the authority. It is written by a live run and can
221
+ * Every identity the storage holds is asked whether it has work left, and the ones that do
222
+ * are built and set going. The question is one key in the agent's own store, and only the
223
+ * agent answers it: the collection keeps no index of its own to go stale, and an identity is
224
+ * never dismissed on the strength of something written about it elsewhere.
225
+ *
226
+ * Building the agent is all this does. An agent picks its own work back up when it is
227
+ * loaded, so the collection has only to bring the right ones into existence.
228
+ */
229
+ async #start(ctx) {
230
+ const created = await this.#configs.list(ctx);
231
+ await Promise.all(created.map(async ({ key: agentId, value }) => {
232
+ if (!Value.Check(agentConfigSchema, value))
233
+ return;
234
+ await this.#lockFor(agentId).runInLock(ctx, async (lockCtx) => {
235
+ if (this.#agents.has(agentId))
236
+ return;
237
+ await this.#instantiate(lockCtx, agentId, value, true);
238
+ });
239
+ }));
240
+ }
241
+ /** The durable store for one agent, created once and reused for the life of the collection. */
242
+ #persistenceFor(agentId) {
243
+ const existing = this.#persistences.get(agentId);
244
+ if (existing !== undefined)
245
+ return existing;
246
+ const created = this.#storage.persistence(agentId);
247
+ this.#persistences.set(agentId, created);
248
+ return created;
249
+ }
250
+ /**
251
+ * The lock serializing this collection's work on one identity. It is per agent because the
252
+ * work it guards — building an agent, which loads every feature — may itself resolve another
253
+ * agent from this same collection, and a collection-wide lock would deadlock on it.
254
+ */
255
+ #lockFor(agentId) {
256
+ const existing = this.#locks.get(agentId);
257
+ if (existing !== undefined)
258
+ return existing;
259
+ const created = asyncLock({ reentry: "block" });
260
+ this.#locks.set(agentId, created);
261
+ return created;
262
+ }
263
+ /** Queue a steered message for an agent. */
264
+ async steer(ctx, agentId, message, options) {
265
+ const agent = await this.resolve(ctx, agentId);
266
+ await agent.steer(ctx, message, options);
267
+ }
268
+ /** Queue a message for an agent. */
269
+ async send(ctx, agentId, message, options) {
270
+ const agent = await this.resolve(ctx, agentId);
271
+ await agent.send(ctx, message, options);
272
+ }
273
+ /** Cancel an agent's active turn, leaving its queued messages durable for the next one. */
274
+ async abort(ctx, agentId, options) {
275
+ await (await this.resolve(ctx, agentId)).abort(ctx, options);
276
+ }
277
+ /** Ask an agent for its conversation to be replaced by the provider's summary of it. */
278
+ async compact(ctx, agentId, options) {
279
+ await (await this.resolve(ctx, agentId)).compact(ctx, options);
280
+ }
281
+ }
282
+ //# sourceMappingURL=AgentSystemLocal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentSystemLocal.js","sourceRoot":"","sources":["../sources/AgentSystemLocal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAA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AO,CAAC,GAAY,EAAE,OAAe,EAAE,OAA+B;QACxE,MAAM,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACnE,CAAC;CACJ"}
@@ -0,0 +1,56 @@
1
+ import type { SessionUserMessage } from "@slopus/happy-providers";
2
+ import type { Context } from "@steve.kite/stdlib";
3
+ import type { AgentBaseMessageOptions } from "./AgentBase.js";
4
+ import type { AgentConfig } from "./AgentConfig.js";
5
+ import type { AgentModel } from "./AgentModel.js";
6
+ import { AgentRef } from "./AgentRef.js";
7
+ import type { AgentInitialContext, AgentSystem } from "./AgentSystem.js";
8
+ /**
9
+ * A reference to a collection of agents that cannot deadlock, for code that runs inside an agent
10
+ * — a feature hook, or a tool the run loop is waiting on. Every operation returns without
11
+ * waiting for any agent's loop to reach a particular point.
12
+ *
13
+ * What is missing is missing on purpose. `delete` closes an agent and `start` resumes whole
14
+ * agents; both are the owning caller's business, and both would wait for a loop that may be
15
+ * waiting for the very code asking. Agents come back as `AgentRef` for the same reason — handing
16
+ * out the real `Agent` would hand back `close` and `waitForIdle` along with the `await: true`
17
+ * that waits for a compaction or an unwound turn.
18
+ *
19
+ * A message is the one thing a caller here may be told about, because accepting one is a durable
20
+ * queue write rather than a turn: `steer` and `send` resolve once the message is safely part of
21
+ * the target agent's conversation, and reject when that write fails, so a caller routing work to
22
+ * another agent knows whether it arrived. The exception is the caller's own agent, whose loop is
23
+ * what would have to perform that write — asked for itself, the message is queued and not waited
24
+ * for. That is decided from the context, which names the agent the caller is running inside; a
25
+ * context that names none proves nothing, so nothing is waited for there either.
26
+ */
27
+ export declare class AgentSystemRef {
28
+ #private;
29
+ /** Wrap a collection as the deadlock-free reference given to code running inside it. */
30
+ constructor(system: AgentSystem);
31
+ /** The models this collection offers its agents. */
32
+ get models(): readonly AgentModel[];
33
+ /** Create an agent with a new system-generated cuid2 identity. */
34
+ create(ctx: Context, config: AgentConfig, initialContext?: AgentInitialContext): Promise<AgentRef>;
35
+ /** A reference to an existing agent; resolving one that was never created is an error. */
36
+ resolve(ctx: Context, agentId: string): Promise<AgentRef>;
37
+ /** The configuration an agent was created with, or undefined when there is no such agent. */
38
+ config(ctx: Context, agentId: string): Promise<AgentConfig | undefined>;
39
+ /**
40
+ * Queue a steered message. For another agent this resolves once the message is durably
41
+ * accepted and rejects when that write fails; for the caller's own agent it resolves as soon
42
+ * as the agent has taken the request on.
43
+ */
44
+ steer(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions): Promise<void>;
45
+ /**
46
+ * Queue a sent message. For another agent this resolves once the message is durably accepted
47
+ * and rejects when that write fails; for the caller's own agent it resolves as soon as the
48
+ * agent has taken the request on.
49
+ */
50
+ send(ctx: Context, agentId: string, message: SessionUserMessage, options?: AgentBaseMessageOptions): Promise<void>;
51
+ /** Ask an agent to compact, and resolve once it has been asked. */
52
+ compact(ctx: Context, agentId: string): Promise<void>;
53
+ /** Cancel an agent's active turn, and resolve once the cancellation has been signalled. */
54
+ abort(ctx: Context, agentId: string): Promise<void>;
55
+ }
56
+ //# sourceMappingURL=AgentSystemRef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentSystemRef.d.ts","sourceRoot":"","sources":["../sources/AgentSystemRef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAwB,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,WAAW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ot deadlock, for code that runs inside an agent
4
+ * — a feature hook, or a tool the run loop is waiting on. Every operation returns without
5
+ * waiting for any agent's loop to reach a particular point.
6
+ *
7
+ * What is missing is missing on purpose. `delete` closes an agent and `start` resumes whole
8
+ * agents; both are the owning caller's business, and both would wait for a loop that may be
9
+ * waiting for the very code asking. Agents come back as `AgentRef` for the same reason — handing
10
+ * out the real `Agent` would hand back `close` and `waitForIdle` along with the `await: true`
11
+ * that waits for a compaction or an unwound turn.
12
+ *
13
+ * A message is the one thing a caller here may be told about, because accepting one is a durable
14
+ * queue write rather than a turn: `steer` and `send` resolve once the message is safely part of
15
+ * the target agent's conversation, and reject when that write fails, so a caller routing work to
16
+ * another agent knows whether it arrived. The exception is the caller's own agent, whose loop is
17
+ * what would have to perform that write — asked for itself, the message is queued and not waited
18
+ * for. That is decided from the context, which names the agent the caller is running inside; a
19
+ * context that names none proves nothing, so nothing is waited for there either.
20
+ */
21
+ export class AgentSystemRef {
22
+ /** The collection this reference forwards every operation to without waiting on its loops. */
23
+ #system;
24
+ /** Wrap a collection as the deadlock-free reference given to code running inside it. */
25
+ constructor(system) {
26
+ this.#system = system;
27
+ }
28
+ /** The models this collection offers its agents. */
29
+ get models() {
30
+ return this.#system.models;
31
+ }
32
+ /** Create an agent with a new system-generated cuid2 identity. */
33
+ async create(ctx, config, initialContext) {
34
+ return new AgentRef(await this.#system.create(ctx, config, initialContext));
35
+ }
36
+ /** A reference to an existing agent; resolving one that was never created is an error. */
37
+ async resolve(ctx, agentId) {
38
+ return new AgentRef(await this.#system.resolve(ctx, agentId));
39
+ }
40
+ /** The configuration an agent was created with, or undefined when there is no such agent. */
41
+ async config(ctx, agentId) {
42
+ return await this.#system.config(ctx, agentId);
43
+ }
44
+ /**
45
+ * Queue a steered message. For another agent this resolves once the message is durably
46
+ * accepted and rejects when that write fails; for the caller's own agent it resolves as soon
47
+ * as the agent has taken the request on.
48
+ */
49
+ async steer(ctx, agentId, message, options) {
50
+ await this.#system.steer(ctx, agentId, message, {
51
+ ...options,
52
+ await: acceptanceIsWaitable(ctx, agentId),
53
+ });
54
+ }
55
+ /**
56
+ * Queue a sent message. For another agent this resolves once the message is durably accepted
57
+ * and rejects when that write fails; for the caller's own agent it resolves as soon as the
58
+ * agent has taken the request on.
59
+ */
60
+ async send(ctx, agentId, message, options) {
61
+ await this.#system.send(ctx, agentId, message, {
62
+ ...options,
63
+ await: acceptanceIsWaitable(ctx, agentId),
64
+ });
65
+ }
66
+ /** Ask an agent to compact, and resolve once it has been asked. */
67
+ async compact(ctx, agentId) {
68
+ await (await this.resolve(ctx, agentId)).compact(ctx);
69
+ }
70
+ /** Cancel an agent's active turn, and resolve once the cancellation has been signalled. */
71
+ async abort(ctx, agentId) {
72
+ await (await this.resolve(ctx, agentId)).abort(ctx);
73
+ }
74
+ }
75
+ //# sourceMappingURL=AgentSystemRef.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentSystemRef.js","sourceRoot":"","sources":["../sources/AgentSystemRef.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG/D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,cAAc;IACvB,8FAA8F;IACrF,OAAO,CAAc;IAE9B,wFAAwF;IACxF,YAAY,MAAmB;QAC3B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAED,oDAAoD;IACpD,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED,kEAAkE;IAClE,KAAK,CAAC,MAAM,CACR,GAAY,EACZ,MAAmB,EACnB,cAAoC;QAEpC,OAAO,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;IAChF,CAAC;IAED,0FAA0F;IAC1F,KAAK,CAAC,OAAO,CAAC,GAAY,EAAE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0,0 +1,17 @@
1
+ import type { SessionMessage } from "@slopus/happy-providers";
2
+ import { type Context } from "@steve.kite/stdlib";
3
+ /**
4
+ * Carry the parent conversation that existed before the assistant response containing the
5
+ * current tool call. The snapshot is immutable caller context: collaboration can fork it without
6
+ * gaining a general-purpose history-reading capability.
7
+ */
8
+ export declare function withAgentTaskContext(ctx: Context, messages: readonly SessionMessage[]): Context;
9
+ /** The pre-tool-call parent conversation available to the current tool execution. */
10
+ export declare function agentTaskContext(ctx: Context): readonly SessionMessage[];
11
+ /**
12
+ * Select everything before the assistant response that issued `callId`. Removing the complete
13
+ * response follows Codex's fork boundary and prevents sibling calls, reasoning, or prefatory
14
+ * assistant text from leaking into a child while that response is still being settled.
15
+ */
16
+ export declare function taskContextBeforeToolCall(messages: readonly SessionMessage[], callId: string): readonly SessionMessage[];
17
+ //# sourceMappingURL=AgentTaskContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentTaskContext.d.ts","sourceRoot":"","sources":["../sources/AgentTaskContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAA0B,KAAK,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAQ1E;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,cAAc,EAAE,GAAG,OAAO,CAE/F;AAED,qFAAqF;AACrF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,cAAc,EAAE,CAExE;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACrC,QAAQ,EAAE,SAAS,cAAc,EAAE,EACnC,MAAM,EAAE,MAAM,GACf,SAAS,cAAc,EAAE,CAO3B"}
@@ -0,0 +1,26 @@
1
+ import { createContextNamespace } from "@steve.kite/stdlib";
2
+ /** Backing storage for `agentTaskContext`: the parent conversation before a tool call. */
3
+ const taskContextNamespace = createContextNamespace("happyAgent.taskContext", undefined);
4
+ /**
5
+ * Carry the parent conversation that existed before the assistant response containing the
6
+ * current tool call. The snapshot is immutable caller context: collaboration can fork it without
7
+ * gaining a general-purpose history-reading capability.
8
+ */
9
+ export function withAgentTaskContext(ctx, messages) {
10
+ return taskContextNamespace.set(ctx, structuredClone(messages));
11
+ }
12
+ /** The pre-tool-call parent conversation available to the current tool execution. */
13
+ export function agentTaskContext(ctx) {
14
+ return structuredClone(taskContextNamespace.get(ctx) ?? []);
15
+ }
16
+ /**
17
+ * Select everything before the assistant response that issued `callId`. Removing the complete
18
+ * response follows Codex's fork boundary and prevents sibling calls, reasoning, or prefatory
19
+ * assistant text from leaking into a child while that response is still being settled.
20
+ */
21
+ export function taskContextBeforeToolCall(messages, callId) {
22
+ const boundary = messages.findIndex((message) => message.role === "assistant" &&
23
+ message.content.some((block) => block.type === "tool_call" && block.callId === callId));
24
+ return structuredClone(boundary < 0 ? messages : messages.slice(0, boundary));
25
+ }
26
+ //# sourceMappingURL=AgentTaskContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentTaskContext.js","sourceRoot":"","sources":["../sources/AgentTaskContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAgB,MAAM,oBAAoB,CAAC;AAE1E,0FAA0F;AAC1F,MAAM,oBAAoB,GAAG,sBAAsB,CAC/C,wBAAwB,EACxB,SAAS,CACZ,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAY,EAAE,QAAmC;IAClF,OAAO,oBAAoB,CAAC,GAAG,CAAC,GAAG,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC;AACpE,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,gBAAgB,CAAC,GAAY;IACzC,OAAO,eAAe,CAAC,oBAAoB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;AAChE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACrC,QAAmC,EACnC,MAAc;IAEd,MAAM,QAAQ,GAAG,QAAQ,CAAC,SAAS,CAC/B,CAAC,OAAO,EAAE,EAAE,CACR,OAAO,CAAC,IAAI,KAAK,WAAW;QAC5B,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,CAC7F,CAAC;IACF,OAAO,eAAe,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;AAClF,CAAC"}
@@ -0,0 +1,87 @@
1
+ import type { SessionOutputBlock, SessionToolLarkGrammar } from "@slopus/happy-providers";
2
+ import type { Static, TSchema } from "@sinclair/typebox";
3
+ import type { Context } from "@steve.kite/stdlib";
4
+ /** A tool-owned decision about one invocation while the agent is in Auto mode. */
5
+ export type AgentToolAutoPermissionPredicate<Args> = {
6
+ bivarianceHack(args: Args, ctx: Context): boolean | Promise<boolean>;
7
+ }["bivarianceHack"];
8
+ /** Human-readable description of the exact action an Auto reviewer is deciding on. */
9
+ export type AgentToolAutoPermissionActionDescriber<Args> = {
10
+ bivarianceHack(args: Args, ctx: Context): string;
11
+ }["bivarianceHack"];
12
+ /**
13
+ * An executable tool with TypeBox-typed arguments and structured result. The descriptor fields
14
+ * mirror the provider session tool. The agent validates arguments against `parameters` before
15
+ * execute runs and the result against `returnType` after; `toLLM` renders the structured result
16
+ * into model-facing content. A thrown execute, an invalid result, or `isError` returning true
17
+ * becomes an error tool result for the model rather than failing the run.
18
+ */
19
+ export interface AgentTool<Args extends TSchema = TSchema, Result extends TSchema = TSchema> {
20
+ /** The tool name the model calls. */
21
+ readonly name: string;
22
+ /** Optional grouping the tool is exposed under, such as an MCP server name. */
23
+ readonly namespace?: string;
24
+ /** Description of the containing namespace, when this tool is namespaced. */
25
+ readonly namespaceDescription?: string;
26
+ /**
27
+ * Exact native tool descriptor for a call the provider owns and settles inside its response.
28
+ * Absence means the agent owns execution.
29
+ */
30
+ readonly server?: {
31
+ readonly type: string;
32
+ readonly [key: string]: unknown;
33
+ };
34
+ /** Model-facing explanation of what the tool does and when to use it. */
35
+ readonly description?: string;
36
+ /** TypeBox schema the model's arguments are validated against before execute runs. */
37
+ readonly parameters?: Args;
38
+ /** TypeBox schema the structured result is validated against after execute runs. */
39
+ readonly returnType: Result;
40
+ /** Provider-neutral request to expose this tool through native tool discovery. */
41
+ readonly defer?: boolean;
42
+ /** Ignored by providers that do not support grammar-based tools. */
43
+ readonly grammar?: SessionToolLarkGrammar;
44
+ /**
45
+ * Provider-shaped guidance shown only in Auto mode. Use this for fields the model must set
46
+ * when it intentionally requests review or Full access.
47
+ */
48
+ readonly autoPermissionInstructions?: string;
49
+ /**
50
+ * Describes the exact action and boundary an Auto reviewer is deciding on. A tool whose
51
+ * `shouldReviewInAutoMode` can return true must provide this description.
52
+ */
53
+ readonly describeAutoPermissionAction?: AgentToolAutoPermissionActionDescriber<Static<Args>>;
54
+ /**
55
+ * The tool cannot be contained by Rig's local restricted modes, so it is available only in
56
+ * Auto or Full access. This does not itself approve an Auto invocation.
57
+ */
58
+ readonly requiresAutoOrFullAccess?: boolean;
59
+ /**
60
+ * Whether this exact invocation requires an Auto review. Every tool owns this decision;
61
+ * routine tools state that explicitly with a predicate that returns false.
62
+ */
63
+ readonly shouldReviewInAutoMode: AgentToolAutoPermissionPredicate<Static<Args>>;
64
+ /**
65
+ * Whether an approved invocation must temporarily run in Full access. Review and elevation
66
+ * are deliberately separate decisions; omission means the current sandbox remains active.
67
+ */
68
+ readonly shouldRunInFullAccessInAutoMode?: AgentToolAutoPermissionPredicate<Static<Args>>;
69
+ /**
70
+ * A durable tool is safe to execute again, so an interrupted call is retried when the agent
71
+ * restarts. A non-durable call interrupted by a restart becomes an error tool result instead.
72
+ */
73
+ readonly durable?: boolean;
74
+ /**
75
+ * The context's lifetime aborts when the turn is aborted, so a long-running tool can
76
+ * observe cancellation and stop its own work.
77
+ */
78
+ execute(ctx: Context, args: Static<Args>): Promise<Static<Result>>;
79
+ /** Renders a validated result into the content blocks the model actually sees. */
80
+ toLLM(result: Static<Result>): readonly SessionOutputBlock[];
81
+ /** Whether a structured result should be reported to the model as an error. */
82
+ isError?(result: Static<Result>): boolean;
83
+ }
84
+ export type AnyAgentTool = AgentTool<any, any>;
85
+ /** Define a tool with TypeBox-inferred argument and result types. */
86
+ export declare function defineAgentTool<const Args extends TSchema, const Result extends TSchema>(tool: AgentTool<Args, Result>): AgentTool<Args, Result>;
87
+ //# sourceMappingURL=AgentTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentTool.d.ts","sourceRoot":"","sources":["../sources/AgentTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,kFAAkF;AAClF,MAAM,MAAM,gCAAgC,CAAC,IAAI,IAAI;IACjD,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACxE,CAAC,gBAAgB,CAAC,CAAC;AAEpB,sFAAsF;AACtF,MAAM,MAAM,sCAAsC,CAAC,IAAI,IAAI;IACvD,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM,CAAC;CACpD,CAAC,gBAAgB,CAAC,CAAC;AAEpB;;;;;;GAMG;AACH,MAAM,WAAW,SAAS,CAAC,IAAI,SAAS,OAAO,GAAG,OAAO,EAAE,MAAM,SAAS,OAAO,GAAG,OAAO;IAC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AI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IACnE,kFAAkF;IAClF,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,SAAS,kBAAkB,EAAE,CAAC;IAC7D,+EAA+E;IAC/E,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC;CAC7C;AAMD,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAE/C,qEAAqE;AACrE,wBAAgB,eAAe,CAAC,KAAK,CAAC,IAAI,SAAS,OAAO,EAAE,KAAK,CAAC,MAAM,SAAS,OAAO,EACpF,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,GAC9B,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,CAEzB"}
@@ -0,0 +1,5 @@
1
+ /** Define a tool with TypeBox-inferred argument and result types. */
2
+ export function defineAgentTool(tool) {
3
+ return tool;
4
+ }
5
+ //# sourceMappingURL=AgentTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentTool.js","sourceRoot":"","sources":["../sources/AgentTool.ts"],"names":[],"mappings":"AA0FA,qEAAqE;AACrE,MAAM,UAAU,eAAe,CAC3B,IAA6B;IAE7B,OAAO,IAAI,CAAC;AAChB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,25 @@
1
- export {};
1
+ /** Public surface of `@slopus/happy-agent-base`, re-exported by concern. */
2
+ export { Agent, type AgentOptions } from "./Agent.js";
3
+ export { type AgentSystem } from "./AgentSystem.js";
4
+ export { type AgentInitialContext } from "./AgentSystem.js";
5
+ export { AgentSystemLocal, type AgentSystemLocalOptions } from "./AgentSystemLocal.js";
6
+ export { AgentSystemRef } from "./AgentSystemRef.js";
7
+ export { AgentRef } from "./AgentRef.js";
8
+ export { agentSystem, withAgentSystem } from "./AgentSystemContext.js";
9
+ export { agentConfig, agentConfigSchema, agentFeatureConfig, agentEnvironment, agentEnvironmentSchema, agentFeatureConfigSchema, agentPlatformSchema, currentAgentEnvironment, withAgentConfig, type AgentConfig, type AgentEnvironment, type AgentFeatureConfig, type AgentPlatform, } from "./AgentConfig.js";
10
+ export { AgentStorage, type AgentStorageOptions } from "./AgentStorage.js";
11
+ export { type AgentModel } from "./AgentModel.js";
12
+ export { knownModels, type Model } from "./models.js";
13
+ export { AgentBase, type AgentBaseAwaitOptions, type AgentBaseMessageOptions, type AgentBaseOptions, type AgentBaseQueueMode, } from "./AgentBase.js";
14
+ export { agentEffort, agentId, agentKV, agentModel, agentProvider, agentRunKV, agentServiceTier, withAgentContext, withAgentKV, withAgentRunKV, } from "./AgentContexts.js";
15
+ export { agentTaskContext, taskContextBeforeToolCall, withAgentTaskContext, } from "./AgentTaskContext.js";
16
+ export { AgentKV } from "./AgentKV.js";
17
+ export { type AgentBaseHooks, type AgentBaseInference, type AgentBaseModelChange, type AgentBaseToolExecution, type AgentBaseTurn, type AgentBaseTurnStart, type MaybePromise, } from "./AgentBaseHooks.js";
18
+ export { type AgentPersistence, type AgentRecord } from "./AgentPersistence.js";
19
+ export { agentBasePendingStateOf, agentBaseStoreOwesWork, AGENT_BASE_PENDING_KEY, type AgentBasePendingStage, type AgentBasePendingState, } from "./AgentBasePending.js";
20
+ export { type AgentBaseState } from "./AgentBaseState.js";
21
+ export { type AgentFeature, type AgentFeatureAgent, type AgentFeatureScope, } from "./AgentFeature.js";
22
+ export { type AgentFeatureAction } from "./AgentFeatureAction.js";
23
+ export { AgentProviders } from "./AgentProviders.js";
24
+ export { defineAgentTool, type AgentTool, type AgentToolAutoPermissionActionDescriber, type AgentToolAutoPermissionPredicate, type AnyAgentTool, } from "./AgentTool.js";
2
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../sources/index.ts"],"names":[],"mappings":"AAAA,OAA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