@slopus/happy-agent-base 0.0.1 → 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 (95) hide show
  1. package/README.md +434 -34
  2. package/dist/Agent.d.ts +64 -9
  3. package/dist/Agent.d.ts.map +1 -1
  4. package/dist/Agent.js +247 -40
  5. package/dist/Agent.js.map +1 -1
  6. package/dist/AgentBase.d.ts +270 -23
  7. package/dist/AgentBase.d.ts.map +1 -1
  8. package/dist/AgentBase.js +1728 -342
  9. package/dist/AgentBase.js.map +1 -1
  10. package/dist/AgentBaseHooks.d.ts +108 -20
  11. package/dist/AgentBaseHooks.d.ts.map +1 -1
  12. package/dist/AgentBasePending.d.ts +49 -0
  13. package/dist/AgentBasePending.d.ts.map +1 -0
  14. package/dist/AgentBasePending.js +73 -0
  15. package/dist/AgentBasePending.js.map +1 -0
  16. package/dist/AgentBaseState.d.ts +2 -0
  17. package/dist/AgentBaseState.d.ts.map +1 -1
  18. package/dist/AgentBaseStoreLock.d.ts +16 -0
  19. package/dist/AgentBaseStoreLock.d.ts.map +1 -0
  20. package/dist/AgentBaseStoreLock.js +37 -0
  21. package/dist/AgentBaseStoreLock.js.map +1 -0
  22. package/dist/AgentConfig.d.ts +67 -0
  23. package/dist/AgentConfig.d.ts.map +1 -0
  24. package/dist/AgentConfig.js +81 -0
  25. package/dist/AgentConfig.js.map +1 -0
  26. package/dist/AgentContexts.d.ts +40 -0
  27. package/dist/AgentContexts.d.ts.map +1 -0
  28. package/dist/AgentContexts.js +70 -0
  29. package/dist/AgentContexts.js.map +1 -0
  30. package/dist/AgentFeature.d.ts +105 -15
  31. package/dist/AgentFeature.d.ts.map +1 -1
  32. package/dist/AgentKV.d.ts +63 -0
  33. package/dist/AgentKV.d.ts.map +1 -0
  34. package/dist/AgentKV.js +122 -0
  35. package/dist/AgentKV.js.map +1 -0
  36. package/dist/AgentModel.d.ts +17 -0
  37. package/dist/AgentModel.d.ts.map +1 -0
  38. package/dist/AgentModel.js +2 -0
  39. package/dist/AgentModel.js.map +1 -0
  40. package/dist/AgentPersistence.d.ts +95 -0
  41. package/dist/AgentPersistence.d.ts.map +1 -0
  42. package/dist/AgentPersistence.js +2 -0
  43. package/dist/AgentPersistence.js.map +1 -0
  44. package/dist/AgentProviders.d.ts +5 -0
  45. package/dist/AgentProviders.d.ts.map +1 -1
  46. package/dist/AgentProviders.js +6 -0
  47. package/dist/AgentProviders.js.map +1 -1
  48. package/dist/AgentRef.d.ts +41 -0
  49. package/dist/AgentRef.d.ts.map +1 -0
  50. package/dist/AgentRef.js +60 -0
  51. package/dist/AgentRef.js.map +1 -0
  52. package/dist/AgentStorage.d.ts +19 -0
  53. package/dist/AgentStorage.d.ts.map +1 -0
  54. package/dist/AgentStorage.js +16 -0
  55. package/dist/AgentStorage.js.map +1 -0
  56. package/dist/AgentSystem.d.ts +50 -0
  57. package/dist/AgentSystem.d.ts.map +1 -0
  58. package/dist/AgentSystem.js +2 -0
  59. package/dist/AgentSystem.js.map +1 -0
  60. package/dist/AgentSystemContext.d.ts +15 -0
  61. package/dist/AgentSystemContext.d.ts.map +1 -0
  62. package/dist/AgentSystemContext.js +20 -0
  63. package/dist/AgentSystemContext.js.map +1 -0
  64. package/dist/AgentSystemLocal.d.ts +103 -0
  65. package/dist/AgentSystemLocal.d.ts.map +1 -0
  66. package/dist/AgentSystemLocal.js +282 -0
  67. package/dist/AgentSystemLocal.js.map +1 -0
  68. package/dist/AgentSystemRef.d.ts +56 -0
  69. package/dist/AgentSystemRef.d.ts.map +1 -0
  70. package/dist/AgentSystemRef.js +75 -0
  71. package/dist/AgentSystemRef.js.map +1 -0
  72. package/dist/AgentTaskContext.d.ts +17 -0
  73. package/dist/AgentTaskContext.d.ts.map +1 -0
  74. package/dist/AgentTaskContext.js +26 -0
  75. package/dist/AgentTaskContext.js.map +1 -0
  76. package/dist/AgentTool.d.ts +40 -0
  77. package/dist/AgentTool.d.ts.map +1 -1
  78. package/dist/AgentTool.js.map +1 -1
  79. package/dist/index.d.ts +20 -6
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +23 -2
  82. package/dist/index.js.map +1 -1
  83. package/dist/models.d.ts +62 -0
  84. package/dist/models.d.ts.map +1 -0
  85. package/dist/models.js +185 -0
  86. package/dist/models.js.map +1 -0
  87. package/package.json +5 -3
  88. package/dist/AgentBaseContext.d.ts +0 -22
  89. package/dist/AgentBaseContext.d.ts.map +0 -1
  90. package/dist/AgentBaseContext.js +0 -33
  91. package/dist/AgentBaseContext.js.map +0 -1
  92. package/dist/AgentBasePersistence.d.ts +0 -60
  93. package/dist/AgentBasePersistence.d.ts.map +0 -1
  94. package/dist/AgentBasePersistence.js +0 -2
  95. package/dist/AgentBasePersistence.js.map +0 -1
package/dist/Agent.d.ts CHANGED
@@ -1,31 +1,86 @@
1
1
  import type { SessionUserMessage } from "@slopus/happy-providers";
2
2
  import type { Context } from "@steve.kite/stdlib";
3
- import { type AgentBaseMessageOptions, type AgentBaseOptions } from "./AgentBase.js";
3
+ import { type AgentBaseAwaitOptions, type AgentBaseMessageOptions, type AgentBaseOptions } from "./AgentBase.js";
4
4
  import type { AgentBaseState } from "./AgentBaseState.js";
5
5
  import type { AgentFeature } from "./AgentFeature.js";
6
+ import type { AgentKV } from "./AgentKV.js";
6
7
  import type { AnyAgentTool } from "./AgentTool.js";
8
+ /**
9
+ * Everything `AgentBase` is constructed with, except its hooks: an agent's behavior comes from
10
+ * its features, and the singular hooks the base runs with are merged from them.
11
+ */
7
12
  export interface AgentOptions<Tool extends AnyAgentTool = AnyAgentTool> extends Omit<AgentBaseOptions, "hooks"> {
8
13
  /** Independent capabilities whose hook implementations are merged, in array order. */
9
14
  readonly features?: readonly AgentFeature<Tool>[];
15
+ /**
16
+ * The store features share with every other agent built over the same storage. Each feature
17
+ * is handed its own scope of it, which is where anything outliving one conversation belongs.
18
+ */
19
+ readonly sharedKV: AgentKV;
10
20
  }
11
21
  /**
12
22
  * A thin wrapper around `AgentBase` that assembles its behavior from features. Each feature
13
23
  * implements any subset of the agent hooks on its own; the agent merges them into the singular
14
- * private hooks its internal base runs with. Observing hooks fan out to every feature in array
15
- * order, instructions concatenate, tools concatenate, lifecycle actions concatenate, and the
16
- * first feature to answer a reset injection wins.
24
+ * private hooks its internal base runs with.
25
+ *
26
+ * Features are independent. Observing hooks events and lifecycle brackets — fan out to every
27
+ * feature in array order with per-feature isolation, so one throwing feature never silences the
28
+ * others, and lifecycle actions concatenate across features with a failing feature losing only
29
+ * its own actions. Correctness hooks are loud instead: instructions and tools concatenate in
30
+ * feature order — extending the base state, which `AgentBase` puts first — and a failure there
31
+ * fails the turn rather than running with a wrong configuration. For a model change, every
32
+ * feature observes the change, the first returned handoff wins, and a feature failure during an
33
+ * incompatible change rejects the switch so the history survives.
17
34
  */
18
35
  export declare class Agent<Tool extends AnyAgentTool = AnyAgentTool> {
19
36
  #private;
20
- constructor(ctx: Context, options: AgentOptions<Tool>);
37
+ /**
38
+ * A new agent over a fresh identity, with its features' hooks merged into one set. Touches
39
+ * no storage.
40
+ */
41
+ static create<Tool extends AnyAgentTool = AnyAgentTool>(ctx: Context, options: AgentOptions<Tool>): Promise<Agent<Tool>>;
42
+ /**
43
+ * An agent over an identity that may already have durable state, with that state's one
44
+ * externally meaningful fact — whether it has work left — read before it is handed back.
45
+ */
46
+ static load<Tool extends AnyAgentTool = AnyAgentTool>(ctx: Context, options: AgentOptions<Tool>): Promise<Agent<Tool>>;
47
+ /**
48
+ * Load the agent and set it going again if it has work left, or answer with nothing when it
49
+ * has none — how an owner coming up carries on what an earlier process was in the middle of.
50
+ */
51
+ static loadActive<Tool extends AnyAgentTool = AnyAgentTool>(ctx: Context, options: AgentOptions<Tool>): Promise<Agent<Tool> | undefined>;
52
+ /**
53
+ * Wrap an already-built base. Private, because an agent is made by `create` or by `load`,
54
+ * and which of the two the caller means is worth saying.
55
+ */
56
+ private constructor();
57
+ /** The stable session identity this agent was created with. */
21
58
  get id(): string;
59
+ /**
60
+ * The feature this agent runs under `name`, when it has one. An individual feature holds the
61
+ * state of the single agent it was built for, so this is how that agent's owner reaches what
62
+ * belongs to it — a goal to pause, for instance. A shared feature is answered here too, but
63
+ * it is the collection's instance, serving every agent at once.
64
+ */
65
+ feature(name: string): AgentFeature<Tool> | undefined;
66
+ /**
67
+ * The base's mutable instructions and tools, which every inference reads and every feature's
68
+ * own contribution extends.
69
+ */
22
70
  get state(): AgentBaseState;
23
- steer(ctx: Context, message: SessionUserMessage, options?: AgentBaseMessageOptions): Promise<void>;
24
- send(ctx: Context, message: SessionUserMessage, options?: AgentBaseMessageOptions): Promise<void>;
71
+ /** Queue a user message that injects as soon as the current response and tool batch finish. */
72
+ steer(ctx: Context, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<void>;
73
+ /** Queue a user message that injects only when the agent would otherwise stop. */
74
+ send(ctx: Context, message: SessionUserMessage, options?: AgentBaseMessageOptions & AgentBaseAwaitOptions): Promise<void>;
75
+ /** Start the loop without a new message, continuing a turn an earlier run left unfinished. */
25
76
  start(): void;
77
+ /** Wait until the agent has nothing left to do, including work it accepted but never began. */
26
78
  waitForIdle(): Promise<void>;
27
- compact(ctx: Context): Promise<void>;
28
- abort(): Promise<void>;
79
+ /** Ask for the conversation to be replaced by the provider's summary of it. */
80
+ compact(ctx: Context, options?: AgentBaseAwaitOptions): Promise<void>;
81
+ /** Cancel the active turn, leaving queued messages durable for the next one. */
82
+ abort(ctx: Context, options?: AgentBaseAwaitOptions): Promise<void>;
83
+ /** Finish everything already accepted, then destroy the provider session. */
29
84
  close(): Promise<void>;
30
85
  }
31
86
  //# sourceMappingURL=Agent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Agent.d.ts","sourceRoot":"","sources":["../sources/Agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwB,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AACxF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAA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1
- import { AgentBase } from "./AgentBase.js";
1
+ import { AgentBase, } from "./AgentBase.js";
2
+ import { agentEffort, agentKV, agentModel, agentProvider, agentRunKV, agentServiceTier, withAgentKV, withAgentRunKV, } from "./AgentContexts.js";
2
3
  /**
3
4
  * A thin wrapper around `AgentBase` that assembles its behavior from features. Each feature
4
5
  * implements any subset of the agent hooks on its own; the agent merges them into the singular
5
- * private hooks its internal base runs with. Observing hooks fan out to every feature in array
6
- * order, instructions concatenate, tools concatenate, lifecycle actions concatenate, and the
7
- * first feature to answer a reset injection wins.
6
+ * private hooks its internal base runs with.
7
+ *
8
+ * Features are independent. Observing hooks events and lifecycle brackets — fan out to every
9
+ * feature in array order with per-feature isolation, so one throwing feature never silences the
10
+ * others, and lifecycle actions concatenate across features with a failing feature losing only
11
+ * its own actions. Correctness hooks are loud instead: instructions and tools concatenate in
12
+ * feature order — extending the base state, which `AgentBase` puts first — and a failure there
13
+ * fails the turn rather than running with a wrong configuration. For a model change, every
14
+ * feature observes the change, the first returned handoff wins, and a feature failure during an
15
+ * incompatible change rejects the switch so the history survives.
8
16
  */
9
17
  export class Agent {
18
+ /** The session this agent is a facade over; every operation delegates straight to it. */
10
19
  #base;
11
- constructor(ctx, options) {
12
- const { features, ...base } = options;
13
- this.#base = new AgentBase(ctx, {
14
- ...base,
15
- hooks: mergeFeatures(features ?? []),
16
- });
20
+ /** The features whose hooks were merged into the base, kept in the order they were given. */
21
+ #features;
22
+ /**
23
+ * A new agent over a fresh identity, with its features' hooks merged into one set. Touches
24
+ * no storage.
25
+ */
26
+ static async create(ctx, options) {
27
+ const { features, base } = split(options);
28
+ return new Agent(await AgentBase.create(ctx, base), features);
17
29
  }
30
+ /**
31
+ * An agent over an identity that may already have durable state, with that state's one
32
+ * externally meaningful fact — whether it has work left — read before it is handed back.
33
+ */
34
+ static async load(ctx, options) {
35
+ const { features, base } = split(options);
36
+ return new Agent(await AgentBase.load(ctx, base), features);
37
+ }
38
+ /**
39
+ * Load the agent and set it going again if it has work left, or answer with nothing when it
40
+ * has none — how an owner coming up carries on what an earlier process was in the middle of.
41
+ */
42
+ static async loadActive(ctx, options) {
43
+ const { features, base } = split(options);
44
+ const loaded = await AgentBase.loadActive(ctx, base);
45
+ return loaded === undefined ? undefined : new Agent(loaded, features);
46
+ }
47
+ /**
48
+ * Wrap an already-built base. Private, because an agent is made by `create` or by `load`,
49
+ * and which of the two the caller means is worth saying.
50
+ */
51
+ constructor(base, features) {
52
+ this.#features = features;
53
+ this.#base = base;
54
+ }
55
+ /** The stable session identity this agent was created with. */
18
56
  get id() {
19
57
  return this.#base.id;
20
58
  }
59
+ /**
60
+ * The feature this agent runs under `name`, when it has one. An individual feature holds the
61
+ * state of the single agent it was built for, so this is how that agent's owner reaches what
62
+ * belongs to it — a goal to pause, for instance. A shared feature is answered here too, but
63
+ * it is the collection's instance, serving every agent at once.
64
+ */
65
+ feature(name) {
66
+ return this.#features.find((feature) => feature.name === name);
67
+ }
68
+ /**
69
+ * The base's mutable instructions and tools, which every inference reads and every feature's
70
+ * own contribution extends.
71
+ */
21
72
  get state() {
22
73
  return this.#base.state;
23
74
  }
75
+ /** Queue a user message that injects as soon as the current response and tool batch finish. */
24
76
  async steer(ctx, message, options) {
25
77
  await this.#base.steer(ctx, message, options);
26
78
  }
79
+ /** Queue a user message that injects only when the agent would otherwise stop. */
27
80
  async send(ctx, message, options) {
28
81
  await this.#base.send(ctx, message, options);
29
82
  }
83
+ /** Start the loop without a new message, continuing a turn an earlier run left unfinished. */
30
84
  start() {
31
85
  this.#base.start();
32
86
  }
87
+ /** Wait until the agent has nothing left to do, including work it accepted but never began. */
33
88
  async waitForIdle() {
34
89
  await this.#base.waitForIdle();
35
90
  }
36
- async compact(ctx) {
37
- await this.#base.compact(ctx);
91
+ /** Ask for the conversation to be replaced by the provider's summary of it. */
92
+ async compact(ctx, options) {
93
+ await this.#base.compact(ctx, options);
38
94
  }
39
- async abort() {
40
- await this.#base.abort();
95
+ /** Cancel the active turn, leaving queued messages durable for the next one. */
96
+ async abort(ctx, options) {
97
+ await this.#base.abort(ctx, options);
41
98
  }
99
+ /** Finish everything already accepted, then destroy the provider session. */
42
100
  async close() {
43
101
  await this.#base.close();
44
102
  }
45
103
  }
46
104
  /**
47
105
  * Merge every feature's hook implementations into one `AgentBaseHooks`. A hook is provided only
48
- * when at least one feature implements it, so the base's own fallbackssuch as the mutable
49
- * state for instructions and tools — stay in effect otherwise.
106
+ * when at least one feature implements it, so the base's own behaviorthe mutable state alone
107
+ * for instructions and tools — stays in effect otherwise.
50
108
  */
51
- function mergeFeatures(features) {
109
+ /**
110
+ * Separate the features from the options the base is built with, and merge their hooks into the
111
+ * one set the base observes the run through. Both factories need exactly this, and the merge has
112
+ * to happen before the base exists.
113
+ */
114
+ function split(options) {
115
+ const { features, sharedKV, ...rest } = options;
116
+ const resolved = features ?? [];
117
+ return {
118
+ features: resolved,
119
+ base: { ...rest, hooks: mergeFeatures(resolved, options, sharedKV) },
120
+ };
121
+ }
122
+ function mergeFeatures(features, options, sharedKV) {
123
+ /** What one feature's hook is handed alongside the context, for this call. */
124
+ const scopeOf = (ctx, feature) => featureScope(ctx, feature, options, sharedKV);
52
125
  const withInstructions = features.filter((feature) => feature.instructions !== undefined);
53
126
  const withTools = features.filter((feature) => feature.tools !== undefined);
127
+ const withToolExecution = features.filter((feature) => feature.aroundToolExecution !== undefined);
54
128
  const withModelChanged = features.filter((feature) => feature.modelChanged !== undefined);
129
+ const withEvents = features.filter((feature) => feature.onEvent !== undefined);
130
+ // Observing hooks fan out with per-feature isolation: one throwing feature must never
131
+ // prevent the features after it from observing.
55
132
  const fanOut = (pick) => {
56
133
  const implemented = features.filter((feature) => pick(feature) !== undefined);
57
134
  if (implemented.length === 0)
58
135
  return undefined;
59
- return (ctx) => {
60
- for (const feature of implemented)
61
- pick(feature)?.(ctx);
136
+ return async (ctx, ...args) => {
137
+ for (const feature of implemented) {
138
+ try {
139
+ await pick(feature)?.(featureCtx(ctx, feature), scopeOf(ctx, feature), ...args);
140
+ }
141
+ catch {
142
+ // Features observe independently; one failing never silences the rest.
143
+ }
144
+ }
62
145
  };
63
146
  };
147
+ // Transactional hooks run in order inside one transaction, and a failure propagates: the
148
+ // features here are writing alongside the fact being committed, so containing one feature's
149
+ // failure would commit a conclusion the rest of the transaction contradicts.
150
+ const chain = (pick) => {
151
+ const implemented = features.filter((feature) => pick(feature) !== undefined);
152
+ if (implemented.length === 0)
153
+ return undefined;
154
+ return async (ctx) => {
155
+ for (const feature of implemented) {
156
+ await pick(feature)?.(featureCtx(ctx, feature), scopeOf(ctx, feature));
157
+ }
158
+ };
159
+ };
160
+ // Action hooks concatenate what every feature asks for; a failing feature loses only its
161
+ // own actions.
64
162
  const collect = (pick) => {
65
163
  const implemented = features.filter((feature) => pick(feature) !== undefined);
66
164
  if (implemented.length === 0)
67
165
  return undefined;
68
- return (ctx) => implemented.flatMap((feature) => pick(feature)?.(ctx) ?? []);
166
+ return async (ctx, ...args) => {
167
+ const actions = [];
168
+ for (const feature of implemented) {
169
+ try {
170
+ actions.push(...((await pick(feature)?.(featureCtx(ctx, feature), scopeOf(ctx, feature), ...args)) ?? []));
171
+ }
172
+ catch {
173
+ // Features act independently; one failing never discards the rest.
174
+ }
175
+ }
176
+ return actions;
177
+ };
69
178
  };
70
- const onEvent = fanOutEvent(features);
71
179
  return {
72
- ...(onEvent === undefined ? {} : { onEvent }),
180
+ ...(withEvents.length === 0
181
+ ? {}
182
+ : {
183
+ onEvent: ((ctx, event) => {
184
+ for (const feature of withEvents) {
185
+ try {
186
+ feature.onEvent?.(featureCtx(ctx, feature), scopeOf(ctx, feature), event);
187
+ }
188
+ catch {
189
+ // Features observe independently; one failing never silences
190
+ // the rest.
191
+ }
192
+ }
193
+ }),
194
+ }),
73
195
  ...(withInstructions.length === 0
74
196
  ? {}
75
197
  : {
76
- instructions: (ctx) => withInstructions
77
- .map((feature) => feature.instructions?.(ctx) ?? "")
78
- .filter((text) => text.length > 0)
79
- .join("\n\n"),
198
+ // Correctness hook: a failing feature propagates and fails the turn.
199
+ instructions: async (ctx) => {
200
+ const texts = [];
201
+ for (const feature of withInstructions) {
202
+ texts.push((await feature.instructions?.(featureCtx(ctx, feature), scopeOf(ctx, feature))) ?? "");
203
+ }
204
+ return texts.filter((text) => text.length > 0).join("\n\n");
205
+ },
80
206
  }),
81
207
  ...(withTools.length === 0
82
208
  ? {}
83
209
  : {
84
- tools: (ctx) => withTools.flatMap((feature) => [...(feature.tools?.(ctx) ?? [])]),
210
+ // Correctness hook: a failing feature propagates and fails the turn; the
211
+ // base validates the merged list against duplicate names.
212
+ tools: async (ctx) => {
213
+ const tools = [];
214
+ for (const feature of withTools) {
215
+ tools.push(...((await feature.tools?.(featureCtx(ctx, feature), scopeOf(ctx, feature))) ?? []));
216
+ }
217
+ return tools;
218
+ },
219
+ }),
220
+ ...(withToolExecution.length === 0
221
+ ? {}
222
+ : {
223
+ // Correctness middleware: the first feature is the outermost wrapper, and a
224
+ // failure propagates to the base so it becomes this call's error result.
225
+ aroundToolExecution: async (ctx, execution) => {
226
+ const invoke = async (index) => {
227
+ const feature = withToolExecution[index];
228
+ if (feature === undefined)
229
+ return await execution.execute();
230
+ let continued;
231
+ return await feature.aroundToolExecution?.(featureCtx(ctx, feature), scopeOf(ctx, feature), {
232
+ ...execution,
233
+ // A wrapper may inspect the continuation from more than one
234
+ // code path; every call joins the same downstream execution.
235
+ execute: () => (continued ??= invoke(index + 1)),
236
+ });
237
+ };
238
+ return await invoke(0);
239
+ },
85
240
  }),
86
241
  ...(withModelChanged.length === 0
87
242
  ? {}
88
243
  : {
89
- modelChanged: (ctx, change) => {
244
+ modelChanged: async (ctx, change) => {
90
245
  let injected;
91
- // Every feature observes the change; the first returned message wins.
246
+ let failed = false;
247
+ let failure;
248
+ // Every feature observes the change even when an earlier one fails;
249
+ // the first returned handoff wins.
92
250
  for (const feature of withModelChanged) {
93
- const message = feature.modelChanged?.(ctx, change);
94
- injected ??= message;
251
+ try {
252
+ const message = await feature.modelChanged?.(featureCtx(ctx, feature), scopeOf(ctx, feature), change);
253
+ injected ??= message;
254
+ }
255
+ catch (error) {
256
+ if (!failed) {
257
+ failed = true;
258
+ failure = error;
259
+ }
260
+ }
95
261
  }
262
+ // A failing feature during an incompatible change rejects the switch,
263
+ // preserving the history; on a compatible change it merely observed.
264
+ if (failed && change.wasReset)
265
+ throw failure;
96
266
  return injected;
97
267
  },
98
268
  }),
99
269
  ...spread("beforeAgentLoop", fanOut((feature) => feature.beforeAgentLoop)),
100
- ...spread("beforeTurn", fanOut((feature) => feature.beforeTurn)),
270
+ ...spread("beforeTurn", collect((feature) => feature.beforeTurn)),
101
271
  ...spread("beforeInference", fanOut((feature) => feature.beforeInference)),
102
272
  ...spread("afterInference", fanOut((feature) => feature.afterInference)),
103
273
  ...spread("afterTurn", collect((feature) => feature.afterTurn)),
104
274
  ...spread("afterAgentLoop", collect((feature) => feature.afterAgentLoop)),
275
+ ...spread("afterAgentSettledTransact", chain((feature) => feature.afterAgentSettledTransact)),
276
+ ...spread("afterAgentSettled", fanOut((feature) => feature.afterAgentSettled)),
105
277
  };
106
278
  }
107
- function fanOutEvent(features) {
108
- const implemented = features.filter((feature) => feature.onEvent !== undefined);
109
- if (implemented.length === 0)
110
- return undefined;
111
- return (ctx, event) => {
112
- for (const feature of implemented)
113
- feature.onEvent?.(ctx, event);
279
+ /**
280
+ * The context a feature's hooks run on: the agent's context with both key-value stores narrowed
281
+ * to the feature's own name, so features never see each other's persisted entries — and neither
282
+ * does a tool one of them runs.
283
+ */
284
+ function featureCtx(ctx, feature) {
285
+ const kv = agentKV(ctx);
286
+ const runKV = agentRunKV(ctx);
287
+ const scoped = kv === undefined ? ctx : withAgentKV(ctx, kv.scoped("feature", feature.name));
288
+ return runKV === undefined
289
+ ? scoped
290
+ : withAgentRunKV(scoped, runKV.scoped("feature", feature.name));
291
+ }
292
+ /**
293
+ * What a feature's hook is handed alongside the context: the agent it is serving, and its own
294
+ * scope of each of the three stores. The selection comes from the context the agent derived for
295
+ * this call, so a hook always sees the model, effort, and tier the work is actually running on
296
+ * rather than the ones the agent was built with.
297
+ */
298
+ function featureScope(ctx, feature, options, sharedKV) {
299
+ const kv = agentKV(ctx);
300
+ const runKV = agentRunKV(ctx);
301
+ if (kv === undefined || runKV === undefined) {
302
+ throw new Error(`The feature "${feature.name}" was called on a context carrying no agent stores.`);
303
+ }
304
+ const provider = agentProvider(ctx) ?? options.provider;
305
+ return {
306
+ agent: {
307
+ id: options.id,
308
+ provider,
309
+ providerKind: options.providers.typeOf(provider) ?? undefined,
310
+ model: agentModel(ctx) ?? options.model,
311
+ effort: agentEffort(ctx) ?? options.effort,
312
+ tier: agentServiceTier(ctx) ?? options.serviceTier,
313
+ },
314
+ kv: kv.scoped("feature", feature.name),
315
+ sharedKV: sharedKV.scoped(feature.name),
316
+ runKV: runKV.scoped("feature", feature.name),
114
317
  };
115
318
  }
319
+ /**
320
+ * One optional entry to spread into the merged hooks: the key when a merged implementation
321
+ * exists, and nothing at all when no feature implemented it, so the base keeps its own behavior.
322
+ */
116
323
  function spread(key, value) {
117
324
  return value === undefined ? {} : { [key]: value };
118
325
  }
package/dist/Agent.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Agent.js","sourceRoot":"","sources":["../sources/Agent.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAuD,MAAM,gBAAgB,CAAC;AAahG;;;;;;GAMG;AACH,MAAM,OAAO,KAAK;IACL,KAAK,CAAY;IAE1B,YAAY,GAAY,EAAE,OAA2B;QACjD,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;QACtC,IAAI,CAAC,KAAK,GAAG,IAAI,SAAS,CAAC,GAAG,EAAE;YAC5B,GAAG,IAAI;YACP,KAAK,EAAE,aAAa,CAAC,QAAQ,IAAI,EAAE,CAAC;SACvC,CAAC,CAAC;IACP,CAAC;IAED,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,EA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