@minpeter/pss-runtime 0.1.0-next.2 → 0.1.0-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +172 -85
- package/dist/agent-host-session-store.js +2 -4
- package/dist/agent-host-session-store.js.map +1 -1
- package/dist/agent-loop.js +9 -8
- package/dist/agent-loop.js.map +1 -1
- package/dist/agent-namespace.js +3 -7
- package/dist/agent-namespace.js.map +1 -1
- package/dist/agent-options.d.ts +4 -19
- package/dist/agent-options.js +2 -8
- package/dist/agent-options.js.map +1 -1
- package/dist/agent-resume.js +2 -82
- package/dist/agent-resume.js.map +1 -1
- package/dist/agent-session-entry.d.ts +1 -1
- package/dist/agent.d.ts +4 -4
- package/dist/agent.js +19 -89
- package/dist/agent.js.map +1 -1
- package/dist/cloudflare/cloudflare-agent-context.d.ts +40 -0
- package/dist/cloudflare/cloudflare-agent-context.js +37 -0
- package/dist/cloudflare/cloudflare-agent-context.js.map +1 -0
- package/dist/cloudflare/cloudflare-alarm-budget.d.ts +18 -0
- package/dist/cloudflare/cloudflare-alarm-budget.js +77 -0
- package/dist/cloudflare/cloudflare-alarm-budget.js.map +1 -0
- package/dist/cloudflare/cloudflare-alarm-drainer.d.ts +45 -0
- package/dist/cloudflare/cloudflare-alarm-drainer.js +103 -0
- package/dist/cloudflare/cloudflare-alarm-drainer.js.map +1 -0
- package/dist/cloudflare/cloudflare-alarm-run-drain.d.ts +13 -0
- package/dist/cloudflare/cloudflare-alarm-run-drain.js +81 -0
- package/dist/cloudflare/cloudflare-alarm-run-drain.js.map +1 -0
- package/dist/cloudflare/cloudflare-alarm-work.js +110 -0
- package/dist/cloudflare/cloudflare-alarm-work.js.map +1 -0
- package/dist/cloudflare/cloudflare-checkpoint-store.js +39 -0
- package/dist/cloudflare/cloudflare-checkpoint-store.js.map +1 -0
- package/dist/cloudflare/cloudflare-durable-object-fetch.d.ts +21 -0
- package/dist/cloudflare/cloudflare-durable-object-fetch.js +11 -0
- package/dist/cloudflare/cloudflare-durable-object-fetch.js.map +1 -0
- package/dist/cloudflare/cloudflare-event-store.js +33 -0
- package/dist/cloudflare/cloudflare-event-store.js.map +1 -0
- package/dist/cloudflare/cloudflare-execution-session-store.js +40 -0
- package/dist/cloudflare/cloudflare-execution-session-store.js.map +1 -0
- package/dist/cloudflare/cloudflare-execution-store.js +35 -0
- package/dist/cloudflare/cloudflare-execution-store.js.map +1 -0
- package/dist/cloudflare/cloudflare-host.d.ts +61 -0
- package/dist/cloudflare/cloudflare-host.js +113 -0
- package/dist/cloudflare/cloudflare-host.js.map +1 -0
- package/dist/cloudflare/cloudflare-notification-store.js +59 -0
- package/dist/cloudflare/cloudflare-notification-store.js.map +1 -0
- package/dist/cloudflare/cloudflare-run-store.js +81 -0
- package/dist/cloudflare/cloudflare-run-store.js.map +1 -0
- package/dist/cloudflare/cloudflare-store-utils.js +43 -0
- package/dist/cloudflare/cloudflare-store-utils.js.map +1 -0
- package/dist/cloudflare/durable-object-storage.d.ts +20 -0
- package/dist/cloudflare/durable-object-storage.js +76 -0
- package/dist/cloudflare/durable-object-storage.js.map +1 -0
- package/dist/cloudflare/index.d.ts +7 -0
- package/dist/cloudflare/index.js +6 -0
- package/dist/execution/capabilities.d.ts +40 -0
- package/dist/execution/host.d.ts +9 -0
- package/dist/execution/host.js +49 -1
- package/dist/execution/host.js.map +1 -1
- package/dist/execution/index.d.ts +3 -1
- package/dist/execution/index.js +2 -1
- package/dist/execution/memory.js +1 -1
- package/dist/execution/memory.js.map +1 -1
- package/dist/execution/types.d.ts +5 -10
- package/dist/index.d.ts +9 -5
- package/dist/index.js +6 -2
- package/dist/llm-tool-execution.js.map +1 -1
- package/dist/llm.d.ts +1 -21
- package/dist/llm.js +12 -14
- package/dist/llm.js.map +1 -1
- package/dist/plugins.d.ts +27 -5
- package/dist/plugins.js +35 -6
- package/dist/plugins.js.map +1 -1
- package/dist/session/delegate-input.d.ts +9 -0
- package/dist/session/delegate-input.js +16 -0
- package/dist/session/delegate-input.js.map +1 -0
- package/dist/session/events.d.ts +43 -25
- package/dist/session/events.js +41 -0
- package/dist/session/events.js.map +1 -0
- package/dist/session/input-meta-types.d.ts +10 -0
- package/dist/session/input-meta.d.ts +13 -0
- package/dist/session/input-meta.js +45 -0
- package/dist/session/input-meta.js.map +1 -0
- package/dist/session/input.d.ts +4 -0
- package/dist/session/mapping.js +4 -2
- package/dist/session/mapping.js.map +1 -1
- package/dist/session/runtime-input-emit.js +41 -0
- package/dist/session/runtime-input-emit.js.map +1 -0
- package/dist/session/runtime-input.js +5 -1
- package/dist/session/runtime-input.js.map +1 -1
- package/dist/session/session-events.js +20 -6
- package/dist/session/session-events.js.map +1 -1
- package/dist/session/session-notification.js +3 -2
- package/dist/session/session-notification.js.map +1 -1
- package/dist/session/session-runtime-drain.js +3 -9
- package/dist/session/session-runtime-drain.js.map +1 -1
- package/dist/session/session-turn-processor.js +10 -20
- package/dist/session/session-turn-processor.js.map +1 -1
- package/dist/session/session.js +15 -8
- package/dist/session/session.js.map +1 -1
- package/package.json +6 -1
- package/dist/agent-child-runs.js +0 -16
- package/dist/agent-child-runs.js.map +0 -1
- package/dist/agent-host-capabilities.js +0 -9
- package/dist/agent-host-capabilities.js.map +0 -1
- package/dist/agent-validation.js +0 -35
- package/dist/agent-validation.js.map +0 -1
- package/dist/child-session-cleanups.js +0 -61
- package/dist/child-session-cleanups.js.map +0 -1
- package/dist/execution/run.js +0 -55
- package/dist/execution/run.js.map +0 -1
- package/dist/subagent-background-child-run-state.js +0 -51
- package/dist/subagent-background-child-run-state.js.map +0 -1
- package/dist/subagent-background-child-run.js +0 -103
- package/dist/subagent-background-child-run.js.map +0 -1
- package/dist/subagent-background-in-process.js +0 -98
- package/dist/subagent-background-in-process.js.map +0 -1
- package/dist/subagent-background-notification-inbox.js +0 -106
- package/dist/subagent-background-notification-inbox.js.map +0 -1
- package/dist/subagent-background-notify.js +0 -136
- package/dist/subagent-background-notify.js.map +0 -1
- package/dist/subagent-background-resume-group.js +0 -99
- package/dist/subagent-background-resume-group.js.map +0 -1
- package/dist/subagent-background-runner.js +0 -115
- package/dist/subagent-background-runner.js.map +0 -1
- package/dist/subagent-background-schedule.js +0 -43
- package/dist/subagent-background-schedule.js.map +0 -1
- package/dist/subagent-child-run.js +0 -68
- package/dist/subagent-child-run.js.map +0 -1
- package/dist/subagent-job-cancel.js +0 -84
- package/dist/subagent-job-cancel.js.map +0 -1
- package/dist/subagent-job-observer.js +0 -19
- package/dist/subagent-job-observer.js.map +0 -1
- package/dist/subagent-job-output.js +0 -87
- package/dist/subagent-job-output.js.map +0 -1
- package/dist/subagent-job-state.js +0 -66
- package/dist/subagent-job-state.js.map +0 -1
- package/dist/subagent-jobs.js +0 -96
- package/dist/subagent-jobs.js.map +0 -1
- package/dist/subagent-prompt-schema.js +0 -114
- package/dist/subagent-prompt-schema.js.map +0 -1
- package/dist/subagent-run.js +0 -111
- package/dist/subagent-run.js.map +0 -1
- package/dist/subagents.js +0 -125
- package/dist/subagents.js.map +0 -1
package/README.md
CHANGED
|
@@ -50,19 +50,18 @@ consume the events for the run to progress. This is what lets code react to
|
|
|
50
50
|
created.
|
|
51
51
|
|
|
52
52
|
`model` is the single public constructor key for model execution. Pass an AI SDK
|
|
53
|
-
`LanguageModel`
|
|
54
|
-
`
|
|
55
|
-
adapter yourself:
|
|
53
|
+
`LanguageModel` object and configure runtime-owned prompting through
|
|
54
|
+
`instructions`, `tools`, and `toolChoice`:
|
|
56
55
|
|
|
57
56
|
```ts
|
|
58
|
-
import {
|
|
57
|
+
import { openai } from "@ai-sdk/openai";
|
|
58
|
+
import { Agent } from "@minpeter/pss-runtime";
|
|
59
59
|
|
|
60
|
-
const
|
|
61
|
-
{ role: "assistant", content: `Seen ${history.length} messages.` },
|
|
62
|
-
];
|
|
60
|
+
const model = openai("gpt-4.1-mini");
|
|
63
61
|
|
|
64
62
|
const agent = new Agent({
|
|
65
|
-
|
|
63
|
+
instructions: "Answer with concise operational notes.",
|
|
64
|
+
model,
|
|
66
65
|
});
|
|
67
66
|
```
|
|
68
67
|
|
|
@@ -116,69 +115,154 @@ The public transcript protocol is `AgentEvent`: live runs emit runtime-defined
|
|
|
116
115
|
events through `run.events()`. Provider/model message history is internal
|
|
117
116
|
continuation state, not a public history API.
|
|
118
117
|
|
|
119
|
-
##
|
|
118
|
+
## Delegation
|
|
120
119
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
delegate tools.
|
|
120
|
+
Delegation is app-owned. Build ordinary tools that call another `Agent`,
|
|
121
|
+
`session.send(...)`, `session.notify(...)`, or host-owned background work, then
|
|
122
|
+
return the compact result shape your product wants the model to see.
|
|
125
123
|
|
|
126
124
|
```ts
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
description: "Researches facts and returns concise evidence.",
|
|
125
|
+
const reader = new Agent({
|
|
126
|
+
instructions: "Read knowledge-base files and cite paths.",
|
|
130
127
|
model,
|
|
131
|
-
|
|
128
|
+
namespace: "reader",
|
|
132
129
|
});
|
|
133
130
|
|
|
134
131
|
const coordinator = new Agent({
|
|
132
|
+
instructions: "Coordinate work and delegate knowledge-base reads.",
|
|
135
133
|
model,
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
namespace: "coordinator",
|
|
135
|
+
tools: {
|
|
136
|
+
delegate_to_reader: tool({
|
|
137
|
+
description: "Ask the reader agent to inspect the knowledge base.",
|
|
138
|
+
execute: async ({ prompt }) => {
|
|
139
|
+
const run = await reader.session("kb").send(prompt);
|
|
140
|
+
const text: string[] = [];
|
|
141
|
+
for await (const event of run.events()) {
|
|
142
|
+
if (event.type === "assistant-text") {
|
|
143
|
+
text.push(event.text);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return { result: text.join("\n") };
|
|
147
|
+
},
|
|
148
|
+
inputSchema,
|
|
149
|
+
}),
|
|
150
|
+
},
|
|
138
151
|
});
|
|
139
152
|
```
|
|
140
153
|
|
|
141
|
-
For
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
154
|
+
For background delegation, let your host own task ids, scheduling, output
|
|
155
|
+
storage, and notification resume. The runtime provides generic execution stores,
|
|
156
|
+
notifications, `Agent.resume(...)`, and `run.events()`; it does not generate
|
|
157
|
+
delegation tools or own child-agent lifecycle semantics. See
|
|
158
|
+
the sync and background example packages for app-owned blocking and background
|
|
159
|
+
delegation patterns.
|
|
160
|
+
|
|
161
|
+
## Plugins
|
|
162
|
+
|
|
163
|
+
Pass `plugins: [...]` on `Agent` to observe or intercept runtime events. Each
|
|
164
|
+
plugin exposes one handler:
|
|
148
165
|
|
|
149
166
|
```ts
|
|
150
|
-
|
|
151
|
-
|
|
167
|
+
import type { AgentPlugin } from "@minpeter/pss-runtime";
|
|
168
|
+
import { Agent } from "@minpeter/pss-runtime";
|
|
169
|
+
|
|
170
|
+
const tracePlugin: AgentPlugin = {
|
|
171
|
+
name: "trace",
|
|
172
|
+
on: ({ event }) => {
|
|
173
|
+
if (event.type === "turn-end") {
|
|
174
|
+
console.log("turn finished");
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const agent = new Agent({
|
|
180
|
+
model,
|
|
181
|
+
plugins: [tracePlugin],
|
|
152
182
|
});
|
|
153
183
|
```
|
|
154
184
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
185
|
+
### Observe vs intercept
|
|
186
|
+
|
|
187
|
+
For most events, `on` is observe-only: return nothing (or `{ action: "continue" }`)
|
|
188
|
+
and the runtime emits the event unchanged.
|
|
189
|
+
|
|
190
|
+
Three input event types support intercept returns:
|
|
191
|
+
|
|
192
|
+
- `user-text`
|
|
193
|
+
- `user-message`
|
|
194
|
+
- `runtime-input`
|
|
195
|
+
|
|
196
|
+
Return one of:
|
|
197
|
+
|
|
198
|
+
- `{ action: "continue" }` — emit the current event (default when omitted)
|
|
199
|
+
- `{ action: "transform", event }` — emit a replacement input event
|
|
200
|
+
- `{ action: "handled" }` — skip emit; for `session.send`, close the run without
|
|
201
|
+
starting a turn
|
|
202
|
+
|
|
203
|
+
Plugins run in registration order. Each `transform` updates the event seen by
|
|
204
|
+
later plugins, so transforms chain sequentially.
|
|
205
|
+
|
|
206
|
+
### Input `meta.source`
|
|
207
|
+
|
|
208
|
+
The runtime attaches `meta` on input events at API boundaries. Plugins can route
|
|
209
|
+
on `event.meta?.source`:
|
|
210
|
+
|
|
211
|
+
| `source` | Boundary |
|
|
212
|
+
|----------|----------|
|
|
213
|
+
| `send` | `session.send()` / `agent.send()` |
|
|
214
|
+
| `steer` | `session.steer()` and drained steering queue |
|
|
215
|
+
| `notify` | `session.notify()` runtime input |
|
|
216
|
+
| `delegate` | parent `delegate_to_*` child `session.send()` |
|
|
217
|
+
|
|
218
|
+
`meta` appears on `run.events()` for input events but is stripped before session
|
|
219
|
+
history persistence and model mapping. It never reaches the LLM prompt.
|
|
220
|
+
|
|
221
|
+
### Delegate prompt wrapping
|
|
222
|
+
|
|
223
|
+
Child agents receive delegated prompts with `meta.source === "delegate"`. Wrap or
|
|
224
|
+
rewrite them with a plugin instead of agent-level prompt shims:
|
|
161
225
|
|
|
162
226
|
```ts
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
run_in_background: true,
|
|
166
|
-
});
|
|
227
|
+
import type { AgentPlugin, UserText } from "@minpeter/pss-runtime";
|
|
228
|
+
import { Agent } from "@minpeter/pss-runtime";
|
|
167
229
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
230
|
+
const pokeTagsPlugin: AgentPlugin = {
|
|
231
|
+
name: "poke-tags",
|
|
232
|
+
on: ({ event }) => {
|
|
233
|
+
if (event.type !== "user-text" || event.meta?.source !== "delegate") {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const text =
|
|
238
|
+
typeof event.text === "string" ? event.text : event.text.join("\n");
|
|
239
|
+
|
|
240
|
+
return {
|
|
241
|
+
action: "transform",
|
|
242
|
+
event: {
|
|
243
|
+
...event,
|
|
244
|
+
text: `<poke>\n${text}\n</poke>`,
|
|
245
|
+
} satisfies UserText,
|
|
246
|
+
};
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const executionAgent = new Agent({
|
|
251
|
+
namespace: "execution",
|
|
252
|
+
plugins: [pokeTagsPlugin],
|
|
253
|
+
model,
|
|
254
|
+
});
|
|
171
255
|
```
|
|
172
256
|
|
|
173
|
-
The parent
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
257
|
+
The parent coordinator stays unchanged; only the nested child agent carries the
|
|
258
|
+
plugin.
|
|
259
|
+
|
|
260
|
+
### Migration
|
|
261
|
+
|
|
262
|
+
- **`plugins[].events.on`** — deprecated. Use top-level `plugins[].on`. The legacy
|
|
263
|
+
handler still receives every event but intercept returns are ignored (observe-only).
|
|
264
|
+
- **`wrapDelegatePrompt`** — removed. Use a child `plugins[].on` handler that checks
|
|
265
|
+
`meta.source === "delegate"` and returns `transform`, as above.
|
|
182
266
|
|
|
183
267
|
## Send, Host Resume, and Steer
|
|
184
268
|
|
|
@@ -268,9 +352,9 @@ const agent = new Agent({
|
|
|
268
352
|
});
|
|
269
353
|
```
|
|
270
354
|
|
|
271
|
-
For durable sessions, use the exported file POC. Set a stable `namespace`
|
|
272
|
-
|
|
273
|
-
|
|
355
|
+
For durable sessions, use the exported file POC. Set a stable `namespace` so
|
|
356
|
+
reconstructed agents map the same app-owned session keys back to the same
|
|
357
|
+
transcripts:
|
|
274
358
|
|
|
275
359
|
```ts
|
|
276
360
|
import { FileSessionStore } from "@minpeter/pss-runtime/session-store/file";
|
|
@@ -284,15 +368,20 @@ const agent = new Agent({
|
|
|
284
368
|
});
|
|
285
369
|
```
|
|
286
370
|
|
|
287
|
-
Hosts that need durable runs pass `host:` into `Agent`.
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
371
|
+
Hosts that need durable runs pass `host:` into `Agent`. The execution subpath
|
|
372
|
+
keeps the durable surface split by responsibility, so hosts can implement only
|
|
373
|
+
the capabilities they need: `SessionHost`, `RunHost`, `CheckpointHost`,
|
|
374
|
+
`EventHost`, `NotificationHost`, `BackgroundSchedulerHost`, and
|
|
375
|
+
`ExecutionTransactionHost`. `ExecutionHost` remains the aggregate contract for
|
|
376
|
+
in-process or full-store hosts, while `DurableBackgroundHost` and
|
|
377
|
+
`DurableNotificationResumeHost` describe the smaller durable surfaces required
|
|
378
|
+
for background scheduling and notification resume.
|
|
291
379
|
|
|
292
380
|
```ts
|
|
293
381
|
import { Agent } from "@minpeter/pss-runtime";
|
|
294
382
|
import {
|
|
295
383
|
createInMemoryExecutionHost,
|
|
384
|
+
type DurableBackgroundHost,
|
|
296
385
|
type ExecutionHost,
|
|
297
386
|
} from "@minpeter/pss-runtime/execution";
|
|
298
387
|
|
|
@@ -304,10 +393,15 @@ const agent = new Agent({
|
|
|
304
393
|
namespace: "support-agent",
|
|
305
394
|
});
|
|
306
395
|
|
|
307
|
-
const durableHost:
|
|
308
|
-
capabilities: {
|
|
309
|
-
|
|
310
|
-
|
|
396
|
+
const durableHost: DurableBackgroundHost = {
|
|
397
|
+
capabilities: {},
|
|
398
|
+
backgroundScheduler,
|
|
399
|
+
checkpointStore,
|
|
400
|
+
eventStore,
|
|
401
|
+
notificationInbox,
|
|
402
|
+
runStore,
|
|
403
|
+
sessionStore,
|
|
404
|
+
transaction,
|
|
311
405
|
};
|
|
312
406
|
```
|
|
313
407
|
|
|
@@ -315,25 +409,20 @@ const durableHost: ExecutionHost = {
|
|
|
315
409
|
|
|
316
410
|
The runtime supports both long-running Node.js processes and edge hosts that
|
|
317
411
|
reconstruct runtime objects between turns. The same public DX stays centered on
|
|
318
|
-
`new Agent({
|
|
412
|
+
`new Agent({ model, tools, host })`; host-specific durability and scheduling live
|
|
319
413
|
behind the `host` boundary.
|
|
320
414
|
|
|
321
415
|
Long-running Node.js can keep an `Agent` and `SessionHandle` alive across turns.
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
available while that process owns the work. `FileSessionStore` persists session
|
|
325
|
-
snapshots only; it does not make background work durable by itself.
|
|
416
|
+
`FileSessionStore` persists session snapshots only; app-owned background work
|
|
417
|
+
needs its own durable task/output storage if it must survive process restarts.
|
|
326
418
|
|
|
327
419
|
Cloudflare Durable Objects and similar edge hosts should reconstruct `Agent`
|
|
328
|
-
objects per turn and persist opaque session state through
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
See `examples/cloudflare-edge-subagent` for an edge-hosted turn loop with a
|
|
335
|
-
Worker/Durable Object-shaped host, and `examples/subagent` for a long-running
|
|
336
|
-
local background subagent flow.
|
|
420
|
+
objects per turn and persist opaque session state through a durable
|
|
421
|
+
`sessionStore`.
|
|
422
|
+
Use `@minpeter/pss-runtime/cloudflare` for the packaged Cloudflare Durable
|
|
423
|
+
Object adapter. See the sync example package for blocking app-owned delegation
|
|
424
|
+
and the background example package for durable background delegation in a local
|
|
425
|
+
interactive CLI.
|
|
337
426
|
|
|
338
427
|
The same core API supports room/user/session routing through stable session keys.
|
|
339
428
|
|
|
@@ -348,11 +437,10 @@ storage is durable across hibernation/restores, while in-memory state remains
|
|
|
348
437
|
request-local. Do not store canonical agent session or run state in memory
|
|
349
438
|
attachments.
|
|
350
439
|
|
|
351
|
-
Durable background
|
|
352
|
-
|
|
353
|
-
notifications. The Cloudflare
|
|
354
|
-
|
|
355
|
-
resumes work through `Agent.resume(...)`.
|
|
440
|
+
Durable background workflows require host-owned task ids, attempts, leases,
|
|
441
|
+
checkpoints, cancellation, scheduling, session snapshots, and completion
|
|
442
|
+
notifications. The Cloudflare adapter persists scheduled runs and session
|
|
443
|
+
prompts, sets alarms, and resumes work through `Agent.resume(...)`.
|
|
356
444
|
|
|
357
445
|
## Checkpoints and Cancellation
|
|
358
446
|
|
|
@@ -368,14 +456,13 @@ calls. Tools are checkpointed before and after execution and receive stable
|
|
|
368
456
|
`attempt`, `idempotencyKey`, `retryPolicy`, `signal`, and public `toolCallId`
|
|
369
457
|
values. The `@minpeter/pss-runtime/execution` entrypoint also exposes the same
|
|
370
458
|
low-level tool execution checkpoint types for custom resume runners built
|
|
371
|
-
directly on `
|
|
459
|
+
directly on AI SDK `LanguageModel` objects.
|
|
372
460
|
|
|
373
461
|
These checkpoints are rollback boundaries, not a complete host adapter by
|
|
374
462
|
themselves. Edge hosts still need durable scheduling, leases, resume workers,
|
|
375
463
|
and notification resume handling; externally visible side-effect tools still need
|
|
376
464
|
idempotent execution or a manual recovery flow.
|
|
377
465
|
|
|
378
|
-
Cancellation is persisted before aborting active work.
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
new parent notifications.
|
|
466
|
+
Cancellation is persisted before aborting active work. `delete()` and `dispose()`
|
|
467
|
+
stop the current session's in-process work; durable hosts remain responsible for
|
|
468
|
+
any app-owned background run cancellation, cleanup, and notification policy.
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sessionHost } from "./execution/host.js";
|
|
2
2
|
import { MemorySessionStore } from "./session/store/memory.js";
|
|
3
3
|
//#region src/agent-host-session-store.ts
|
|
4
4
|
function sessionStoreForHost(host) {
|
|
5
|
-
|
|
6
|
-
const hostExecution = executionHost(host);
|
|
7
|
-
return hostExecution ? hostExecution.store.sessions : new MemorySessionStore();
|
|
5
|
+
return sessionHost(host).sessionStore ?? new MemorySessionStore();
|
|
8
6
|
}
|
|
9
7
|
//#endregion
|
|
10
8
|
export { sessionStoreForHost };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-host-session-store.js","names":[],"sources":["../src/agent-host-session-store.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"agent-host-session-store.js","names":[],"sources":["../src/agent-host-session-store.ts"],"sourcesContent":["import { sessionHost } from \"./execution/host\";\nimport type { AgentHost } from \"./execution/types\";\nimport { MemorySessionStore } from \"./session/store/memory\";\nimport type { SessionStore } from \"./session/store/types\";\n\nexport function sessionStoreForHost(host: AgentHost): SessionStore {\n return sessionHost(host).sessionStore ?? new MemorySessionStore();\n}\n"],"mappings":";;;AAKA,SAAgB,oBAAoB,MAA+B;CACjE,OAAO,YAAY,IAAI,EAAE,gBAAgB,IAAI,mBAAmB;AAClE"}
|
package/dist/agent-loop.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { modelMessageToAgentEvents } from "./session/mapping.js";
|
|
2
|
+
import { generateModelStep } from "./llm.js";
|
|
2
3
|
//#region src/agent-loop.ts
|
|
3
|
-
async function runAgentLoop({ captureObserverEvents = captureNoObserverEvents, emit, history,
|
|
4
|
+
async function runAgentLoop({ captureObserverEvents = captureNoObserverEvents, emit, history, model, signal = new AbortController().signal, toolExecution }) {
|
|
4
5
|
while (true) {
|
|
5
6
|
if (signal.aborted) return "aborted";
|
|
6
7
|
if (await emitBoundary({
|
|
@@ -8,9 +9,9 @@ async function runAgentLoop({ captureObserverEvents = captureNoObserverEvents, e
|
|
|
8
9
|
event: { type: "step-start" },
|
|
9
10
|
signal
|
|
10
11
|
}) === "aborted") return "aborted";
|
|
11
|
-
const capturedOutput = await captureObserverEvents(() =>
|
|
12
|
+
const capturedOutput = await captureObserverEvents(() => readModelOutput({
|
|
12
13
|
history,
|
|
13
|
-
|
|
14
|
+
model,
|
|
14
15
|
signal,
|
|
15
16
|
toolExecution
|
|
16
17
|
}));
|
|
@@ -65,10 +66,11 @@ async function captureNoObserverEvents(callback) {
|
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
68
|
function releaseNoObserverEvents() {}
|
|
68
|
-
async function
|
|
69
|
+
async function readModelOutput({ history, model, signal, toolExecution }) {
|
|
69
70
|
try {
|
|
70
|
-
return await
|
|
71
|
+
return await generateModelStep({
|
|
71
72
|
history: history.modelSnapshot(),
|
|
73
|
+
...model,
|
|
72
74
|
signal,
|
|
73
75
|
toolExecution
|
|
74
76
|
});
|
|
@@ -122,9 +124,8 @@ async function appendStepOutput({ emit, history, observerEvents, output, signal
|
|
|
122
124
|
await flushObserverEvents();
|
|
123
125
|
return shouldContinue ? "continue" : "completed";
|
|
124
126
|
}
|
|
125
|
-
function isLaunchOrBlockingObserverEvent(
|
|
126
|
-
|
|
127
|
-
return !(event.type === "subagent-job-end" && event.task_id);
|
|
127
|
+
function isLaunchOrBlockingObserverEvent(_event) {
|
|
128
|
+
return true;
|
|
128
129
|
}
|
|
129
130
|
//#endregion
|
|
130
131
|
export { runAgentLoop };
|
package/dist/agent-loop.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-loop.js","names":[],"sources":["../src/agent-loop.ts"],"sourcesContent":["import type { ModelMessage } from \"ai\";\nimport type
|
|
1
|
+
{"version":3,"file":"agent-loop.js","names":[],"sources":["../src/agent-loop.ts"],"sourcesContent":["import type { ModelMessage } from \"ai\";\nimport {\n generateModelStep,\n type ModelGenerationOptions,\n type ModelStepOutput,\n} from \"./llm\";\nimport type { RuntimeToolExecutionContext } from \"./llm-tool-execution\";\nimport type { AgentEvent } from \"./session/events\";\nimport { modelMessageToAgentEvents } from \"./session/mapping\";\n\ninterface ModelHistory {\n appendModelMessage(message: ModelMessage): void;\n modelSnapshot(): ModelMessage[];\n}\n\ninterface RunAgentLoopOptions {\n captureObserverEvents?: ObserverEventCapture;\n emit: AgentLoopEventListener;\n history: ModelHistory;\n model: ModelGenerationOptions;\n signal?: AbortSignal;\n toolExecution?: RuntimeToolExecutionContext;\n}\n\ntype AgentLoopResult = \"completed\" | \"aborted\";\ntype AgentLoopBoundaryEvent = Extract<\n AgentEvent,\n { type: \"step-end\" } | { type: \"step-start\" }\n>;\ninterface AgentLoopBoundaryDecision {\n readonly runtimeInputAdded?: boolean;\n}\ntype AgentLoopEventListener = (\n event: AgentEvent\n) =>\n | AgentLoopBoundaryDecision\n | Promise<AgentLoopBoundaryDecision | undefined>\n | undefined;\ntype StepOutputResult = \"aborted\" | \"completed\" | \"continue\";\ninterface ObserverEventCaptureResult<T> {\n readonly events: AgentEvent[];\n readonly release: () => void;\n readonly value: T;\n}\ntype ObserverEventCapture = <T>(\n callback: () => Promise<T>\n) => Promise<ObserverEventCaptureResult<T>>;\n\nexport async function runAgentLoop({\n captureObserverEvents = captureNoObserverEvents,\n emit,\n history,\n model,\n signal = new AbortController().signal,\n toolExecution,\n}: RunAgentLoopOptions): Promise<AgentLoopResult> {\n while (true) {\n if (signal.aborted) {\n return \"aborted\";\n }\n\n const stepStartDecision = await emitBoundary({\n emit,\n event: { type: \"step-start\" },\n signal,\n });\n\n if (stepStartDecision === \"aborted\") {\n return \"aborted\";\n }\n\n const capturedOutput = await captureObserverEvents(() =>\n readModelOutput({ history, model, signal, toolExecution })\n );\n const output = capturedOutput.value;\n\n if (output === \"aborted\") {\n return \"aborted\";\n }\n\n const result = await appendCapturedStepOutput({\n capturedOutput,\n emit,\n history,\n output,\n signal,\n });\n\n if (result === \"aborted\") {\n return \"aborted\";\n }\n\n const stepEndDecision = await emitBoundary({\n emit,\n event: { type: \"step-end\" },\n signal,\n });\n\n if (stepEndDecision === \"aborted\") {\n return \"aborted\";\n }\n\n // Runtime input after step-end intentionally forces another inference step,\n // even after final-looking assistant text. Unconditional insertion on every\n // step-end can create an unbounded loop.\n if (result === \"completed\" && !stepEndDecision?.runtimeInputAdded) {\n return \"completed\";\n }\n }\n}\n\nasync function emitBoundary({\n emit,\n event,\n signal,\n}: Pick<RunAgentLoopOptions, \"emit\"> & {\n event: AgentLoopBoundaryEvent;\n signal: AbortSignal;\n}): Promise<AgentLoopBoundaryDecision | \"aborted\" | undefined> {\n if (signal.aborted) {\n return \"aborted\";\n }\n\n const abort = createAbortBoundary(signal);\n try {\n return await Promise.race([Promise.resolve(emit(event)), abort.promise]);\n } catch (error) {\n if (signal.aborted) {\n return \"aborted\";\n }\n\n throw error;\n } finally {\n abort.dispose();\n }\n}\n\nfunction createAbortBoundary(signal: AbortSignal): {\n dispose: () => void;\n promise: Promise<\"aborted\">;\n} {\n let dispose: () => void = () => undefined;\n\n const promise = new Promise<\"aborted\">((resolve) => {\n const onAbort = () => resolve(\"aborted\");\n dispose = () => signal.removeEventListener(\"abort\", onAbort);\n signal.addEventListener(\"abort\", onAbort, { once: true });\n });\n\n return { dispose, promise };\n}\n\nasync function captureNoObserverEvents<T>(callback: () => Promise<T>): Promise<{\n readonly events: AgentEvent[];\n readonly release: () => void;\n readonly value: T;\n}> {\n return {\n events: [],\n release: releaseNoObserverEvents,\n value: await callback(),\n };\n}\n\nfunction releaseNoObserverEvents(): void {\n return;\n}\n\nasync function readModelOutput({\n history,\n model,\n signal,\n toolExecution,\n}: Pick<RunAgentLoopOptions, \"history\" | \"model\"> & {\n signal: AbortSignal;\n toolExecution?: RuntimeToolExecutionContext;\n}): Promise<ModelStepOutput | \"aborted\"> {\n try {\n return await generateModelStep({\n history: history.modelSnapshot(),\n ...model,\n signal,\n toolExecution,\n });\n } catch (error) {\n if (signal.aborted) {\n return \"aborted\";\n }\n\n throw error;\n }\n}\n\nasync function appendCapturedStepOutput({\n capturedOutput,\n emit,\n history,\n output,\n signal,\n}: Pick<RunAgentLoopOptions, \"emit\"> & { history: ModelHistory } & {\n capturedOutput: ObserverEventCaptureResult<ModelStepOutput | \"aborted\">;\n output: ModelStepOutput;\n signal: AbortSignal;\n}): Promise<StepOutputResult> {\n try {\n return await appendStepOutput({\n emit,\n history,\n observerEvents: capturedOutput.events,\n output,\n signal,\n });\n } finally {\n capturedOutput.release();\n }\n}\n\nasync function appendStepOutput({\n emit,\n history,\n observerEvents,\n output,\n signal,\n}: Pick<RunAgentLoopOptions, \"emit\"> & { history: ModelHistory } & {\n observerEvents: AgentEvent[];\n output: ModelStepOutput;\n signal: AbortSignal;\n}): Promise<StepOutputResult> {\n if (signal.aborted) {\n return \"aborted\";\n }\n\n let shouldContinue = false;\n const pendingObserverEvents = observerEvents;\n const flushObserverEvents = async (\n shouldFlush: (event: AgentEvent) => boolean = () => true\n ) => {\n for (let index = 0; index < pendingObserverEvents.length; ) {\n const event = pendingObserverEvents[index];\n if (!(event && shouldFlush(event))) {\n index += 1;\n continue;\n }\n pendingObserverEvents.splice(index, 1);\n await emit(event);\n }\n };\n\n for (const message of output) {\n if (signal.aborted) {\n return \"aborted\";\n }\n\n history.appendModelMessage(message);\n const events = modelMessageToAgentEvents(message);\n const hasToolResult = events.some((event) => event.type === \"tool-result\");\n\n for (const event of events) {\n await emit(event);\n if (event.type === \"tool-call\") {\n shouldContinue = true;\n await flushObserverEvents(isLaunchOrBlockingObserverEvent);\n }\n }\n\n if (hasToolResult) {\n await flushObserverEvents();\n }\n }\n\n await flushObserverEvents();\n\n return shouldContinue ? \"continue\" : \"completed\";\n}\n\nfunction isLaunchOrBlockingObserverEvent(_event: AgentEvent): boolean {\n return true;\n}\n"],"mappings":";;;AAgDA,eAAsB,aAAa,EACjC,wBAAwB,yBACxB,MACA,SACA,OACA,SAAS,IAAI,gBAAgB,EAAE,QAC/B,iBACgD;CAChD,OAAO,MAAM;EACX,IAAI,OAAO,SACT,OAAO;EAST,IAAI,MAN4B,aAAa;GAC3C;GACA,OAAO,EAAE,MAAM,aAAa;GAC5B;EACF,CAAC,MAEyB,WACxB,OAAO;EAGT,MAAM,iBAAiB,MAAM,4BAC3B,gBAAgB;GAAE;GAAS;GAAO;GAAQ;EAAc,CAAC,CAC3D;EACA,MAAM,SAAS,eAAe;EAE9B,IAAI,WAAW,WACb,OAAO;EAGT,MAAM,SAAS,MAAM,yBAAyB;GAC5C;GACA;GACA;GACA;GACA;EACF,CAAC;EAED,IAAI,WAAW,WACb,OAAO;EAGT,MAAM,kBAAkB,MAAM,aAAa;GACzC;GACA,OAAO,EAAE,MAAM,WAAW;GAC1B;EACF,CAAC;EAED,IAAI,oBAAoB,WACtB,OAAO;EAMT,IAAI,WAAW,eAAe,CAAC,iBAAiB,mBAC9C,OAAO;CAEX;AACF;AAEA,eAAe,aAAa,EAC1B,MACA,OACA,UAI6D;CAC7D,IAAI,OAAO,SACT,OAAO;CAGT,MAAM,QAAQ,oBAAoB,MAAM;CACxC,IAAI;EACF,OAAO,MAAM,QAAQ,KAAK,CAAC,QAAQ,QAAQ,KAAK,KAAK,CAAC,GAAG,MAAM,OAAO,CAAC;CACzE,SAAS,OAAO;EACd,IAAI,OAAO,SACT,OAAO;EAGT,MAAM;CACR,UAAU;EACR,MAAM,QAAQ;CAChB;AACF;AAEA,SAAS,oBAAoB,QAG3B;CACA,IAAI,gBAA4B,KAAA;CAEhC,MAAM,UAAU,IAAI,SAAoB,YAAY;EAClD,MAAM,gBAAgB,QAAQ,SAAS;EACvC,gBAAgB,OAAO,oBAAoB,SAAS,OAAO;EAC3D,OAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;CAC1D,CAAC;CAED,OAAO;EAAE;EAAS;CAAQ;AAC5B;AAEA,eAAe,wBAA2B,UAIvC;CACD,OAAO;EACL,QAAQ,CAAC;EACT,SAAS;EACT,OAAO,MAAM,SAAS;CACxB;AACF;AAEA,SAAS,0BAAgC,CAEzC;AAEA,eAAe,gBAAgB,EAC7B,SACA,OACA,QACA,iBAIuC;CACvC,IAAI;EACF,OAAO,MAAM,kBAAkB;GAC7B,SAAS,QAAQ,cAAc;GAC/B,GAAG;GACH;GACA;EACF,CAAC;CACH,SAAS,OAAO;EACd,IAAI,OAAO,SACT,OAAO;EAGT,MAAM;CACR;AACF;AAEA,eAAe,yBAAyB,EACtC,gBACA,MACA,SACA,QACA,UAK4B;CAC5B,IAAI;EACF,OAAO,MAAM,iBAAiB;GAC5B;GACA;GACA,gBAAgB,eAAe;GAC/B;GACA;EACF,CAAC;CACH,UAAU;EACR,eAAe,QAAQ;CACzB;AACF;AAEA,eAAe,iBAAiB,EAC9B,MACA,SACA,gBACA,QACA,UAK4B;CAC5B,IAAI,OAAO,SACT,OAAO;CAGT,IAAI,iBAAiB;CACrB,MAAM,wBAAwB;CAC9B,MAAM,sBAAsB,OAC1B,oBAAoD,SACjD;EACH,KAAK,IAAI,QAAQ,GAAG,QAAQ,sBAAsB,SAAU;GAC1D,MAAM,QAAQ,sBAAsB;GACpC,IAAI,EAAE,SAAS,YAAY,KAAK,IAAI;IAClC,SAAS;IACT;GACF;GACA,sBAAsB,OAAO,OAAO,CAAC;GACrC,MAAM,KAAK,KAAK;EAClB;CACF;CAEA,KAAK,MAAM,WAAW,QAAQ;EAC5B,IAAI,OAAO,SACT,OAAO;EAGT,QAAQ,mBAAmB,OAAO;EAClC,MAAM,SAAS,0BAA0B,OAAO;EAChD,MAAM,gBAAgB,OAAO,MAAM,UAAU,MAAM,SAAS,aAAa;EAEzE,KAAK,MAAM,SAAS,QAAQ;GAC1B,MAAM,KAAK,KAAK;GAChB,IAAI,MAAM,SAAS,aAAa;IAC9B,iBAAiB;IACjB,MAAM,oBAAoB,+BAA+B;GAC3D;EACF;EAEA,IAAI,eACF,MAAM,oBAAoB;CAE9B;CAEA,MAAM,oBAAoB;CAE1B,OAAO,iBAAiB,aAAa;AACvC;AAEA,SAAS,gCAAgC,QAA6B;CACpE,OAAO;AACT"}
|
package/dist/agent-namespace.js
CHANGED
|
@@ -8,17 +8,13 @@ function agentNamespace(namespace) {
|
|
|
8
8
|
function namespacePart(value) {
|
|
9
9
|
return encodeURIComponent(value);
|
|
10
10
|
}
|
|
11
|
-
function parentSessionNamespace({ generation, sessionKey, sessionNamespace }) {
|
|
12
|
-
return `${sessionNamespace}:session:${namespacePart(sessionKey)}:generation:${generation}`;
|
|
13
|
-
}
|
|
14
11
|
function ownsAgentNamespace(ownerNamespace, sessionNamespace) {
|
|
15
12
|
return ownerNamespace === sessionNamespace || ownerNamespace?.startsWith(`${sessionNamespace}:session:`) === true;
|
|
16
13
|
}
|
|
17
|
-
function stableAgentNamespace({
|
|
18
|
-
|
|
19
|
-
return stableNamespace ? agentNamespace(stableNamespace) : randomAgentNamespace();
|
|
14
|
+
function stableAgentNamespace({ namespace }) {
|
|
15
|
+
return namespace ? agentNamespace(namespace) : randomAgentNamespace();
|
|
20
16
|
}
|
|
21
17
|
//#endregion
|
|
22
|
-
export { ownsAgentNamespace,
|
|
18
|
+
export { ownsAgentNamespace, stableAgentNamespace };
|
|
23
19
|
|
|
24
20
|
//# sourceMappingURL=agent-namespace.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-namespace.js","names":[],"sources":["../src/agent-namespace.ts"],"sourcesContent":["export function randomAgentNamespace(): string {\n return agentNamespace(crypto.randomUUID());\n}\n\nexport function agentNamespace(namespace: string): string {\n return `agent:${namespacePart(namespace)}`;\n}\n\nexport function namespacePart(value: string): string {\n return encodeURIComponent(value);\n}\n\nexport function parentSessionNamespace({\n generation,\n sessionKey,\n sessionNamespace,\n}: {\n readonly generation: number;\n readonly sessionKey: string;\n readonly sessionNamespace: string;\n}): string {\n return `${sessionNamespace}:session:${namespacePart(\n sessionKey\n )}:generation:${generation}`;\n}\n\nexport function ownsAgentNamespace(\n ownerNamespace: string | undefined,\n sessionNamespace: string\n): boolean {\n return (\n ownerNamespace === sessionNamespace ||\n ownerNamespace?.startsWith(`${sessionNamespace}:session:`) === true\n );\n}\n\nexport function stableAgentNamespace({\n
|
|
1
|
+
{"version":3,"file":"agent-namespace.js","names":[],"sources":["../src/agent-namespace.ts"],"sourcesContent":["export function randomAgentNamespace(): string {\n return agentNamespace(crypto.randomUUID());\n}\n\nexport function agentNamespace(namespace: string): string {\n return `agent:${namespacePart(namespace)}`;\n}\n\nexport function namespacePart(value: string): string {\n return encodeURIComponent(value);\n}\n\nexport function parentSessionNamespace({\n generation,\n sessionKey,\n sessionNamespace,\n}: {\n readonly generation: number;\n readonly sessionKey: string;\n readonly sessionNamespace: string;\n}): string {\n return `${sessionNamespace}:session:${namespacePart(\n sessionKey\n )}:generation:${generation}`;\n}\n\nexport function ownsAgentNamespace(\n ownerNamespace: string | undefined,\n sessionNamespace: string\n): boolean {\n return (\n ownerNamespace === sessionNamespace ||\n ownerNamespace?.startsWith(`${sessionNamespace}:session:`) === true\n );\n}\n\nexport function stableAgentNamespace({\n namespace,\n}: {\n readonly namespace?: string;\n}): string {\n return namespace ? agentNamespace(namespace) : randomAgentNamespace();\n}\n"],"mappings":";AAAA,SAAgB,uBAA+B;CAC7C,OAAO,eAAe,OAAO,WAAW,CAAC;AAC3C;AAEA,SAAgB,eAAe,WAA2B;CACxD,OAAO,SAAS,cAAc,SAAS;AACzC;AAEA,SAAgB,cAAc,OAAuB;CACnD,OAAO,mBAAmB,KAAK;AACjC;AAgBA,SAAgB,mBACd,gBACA,kBACS;CACT,OACE,mBAAmB,oBACnB,gBAAgB,WAAW,GAAG,iBAAiB,UAAU,MAAM;AAEnE;AAEA,SAAgB,qBAAqB,EACnC,aAGS;CACT,OAAO,YAAY,eAAe,SAAS,IAAI,qBAAqB;AACtE"}
|
package/dist/agent-options.d.ts
CHANGED
|
@@ -1,35 +1,20 @@
|
|
|
1
|
-
import { AgentToolChoice
|
|
1
|
+
import { AgentToolChoice } from "./llm.js";
|
|
2
2
|
import { AgentHost } from "./execution/types.js";
|
|
3
3
|
import { AgentPlugin } from "./plugins.js";
|
|
4
|
-
import { Agent } from "./agent.js";
|
|
5
4
|
import { LanguageModel, ToolSet } from "ai";
|
|
6
5
|
|
|
7
6
|
//#region src/agent-options.d.ts
|
|
8
7
|
interface AgentLanguageModelOptions {
|
|
9
|
-
readonly description?: string;
|
|
10
8
|
readonly host?: AgentHost;
|
|
11
9
|
readonly instructions?: string;
|
|
12
10
|
readonly model: LanguageModel;
|
|
13
|
-
readonly name?: string;
|
|
14
11
|
readonly namespace?: string;
|
|
15
12
|
readonly plugins?: readonly AgentPlugin[];
|
|
16
|
-
readonly subagents?: readonly Agent[];
|
|
17
13
|
readonly toolChoice?: AgentToolChoice;
|
|
18
14
|
readonly tools?: ToolSet;
|
|
19
15
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
readonly host?: AgentHost;
|
|
23
|
-
readonly instructions?: never;
|
|
24
|
-
readonly model: RuntimeLlm;
|
|
25
|
-
readonly name?: string;
|
|
26
|
-
readonly namespace?: string;
|
|
27
|
-
readonly plugins?: readonly AgentPlugin[];
|
|
28
|
-
readonly subagents?: never;
|
|
29
|
-
readonly toolChoice?: never;
|
|
30
|
-
readonly tools?: never;
|
|
31
|
-
}
|
|
32
|
-
type AgentOptions = AgentLanguageModelOptions | AgentRuntimeModelOptions;
|
|
16
|
+
type AgentOptions = AgentLanguageModelOptions;
|
|
17
|
+
type AgentConstructionOptions = AgentOptions;
|
|
33
18
|
//#endregion
|
|
34
|
-
export { AgentOptions };
|
|
19
|
+
export { AgentConstructionOptions, AgentOptions };
|
|
35
20
|
//# sourceMappingURL=agent-options.d.ts.map
|
package/dist/agent-options.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
//#region src/agent-options.ts
|
|
2
2
|
function assertAgentOptions(options) {
|
|
3
3
|
if (options === null || typeof options !== "object") throw new TypeError("Agent options are required. Provide { model }.");
|
|
4
|
-
if ("sessions" in options) throw new TypeError("Agent: unsupported options.sessions. Use host: { sessionStore } and namespace instead.");
|
|
5
|
-
if ("runtime" in options) throw new TypeError("Agent: unsupported options.runtime. Use host.");
|
|
6
|
-
if ("llm" in options) throw new TypeError("Agent: unsupported options.llm. Use model for both AI SDK models and custom RuntimeLlm functions.");
|
|
7
4
|
if (!("model" in options && options.model != null)) throw new TypeError("Agent: missing options.model.");
|
|
8
|
-
if (typeof options.model !== "
|
|
9
|
-
}
|
|
10
|
-
function hasRuntimeModel(options) {
|
|
11
|
-
return typeof options.model === "function";
|
|
5
|
+
if (typeof options.model !== "object" || options.model === null) throw new TypeError("Agent: invalid options.model.");
|
|
12
6
|
}
|
|
13
7
|
//#endregion
|
|
14
|
-
export { assertAgentOptions
|
|
8
|
+
export { assertAgentOptions };
|
|
15
9
|
|
|
16
10
|
//# sourceMappingURL=agent-options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-options.js","names":[],"sources":["../src/agent-options.ts"],"sourcesContent":["import type { LanguageModel, ToolSet } from \"ai\";\nimport type {
|
|
1
|
+
{"version":3,"file":"agent-options.js","names":[],"sources":["../src/agent-options.ts"],"sourcesContent":["import type { LanguageModel, ToolSet } from \"ai\";\nimport type { AgentHost } from \"./execution/types\";\nimport type { AgentToolChoice } from \"./llm\";\nimport type { AgentPlugin } from \"./plugins\";\n\nexport interface AgentLanguageModelOptions {\n readonly host?: AgentHost;\n readonly instructions?: string;\n readonly model: LanguageModel;\n readonly namespace?: string;\n readonly plugins?: readonly AgentPlugin[];\n readonly toolChoice?: AgentToolChoice;\n readonly tools?: ToolSet;\n}\n\nexport type AgentModelOptions = Pick<\n AgentLanguageModelOptions,\n \"instructions\" | \"model\" | \"toolChoice\" | \"tools\"\n>;\nexport type AgentOptions = AgentLanguageModelOptions;\n\nexport type AgentConstructionOptions = AgentOptions;\n\nexport function assertAgentOptions(\n options: unknown\n): asserts options is AgentConstructionOptions {\n if (options === null || typeof options !== \"object\") {\n throw new TypeError(\"Agent options are required. Provide { model }.\");\n }\n\n const hasModel = \"model\" in options && options.model != null;\n\n if (!hasModel) {\n throw new TypeError(\"Agent: missing options.model.\");\n }\n\n if (typeof options.model !== \"object\" || options.model === null) {\n throw new TypeError(\"Agent: invalid options.model.\");\n }\n}\n"],"mappings":";AAuBA,SAAgB,mBACd,SAC6C;CAC7C,IAAI,YAAY,QAAQ,OAAO,YAAY,UACzC,MAAM,IAAI,UAAU,gDAAgD;CAKtE,IAAI,EAFa,WAAW,WAAW,QAAQ,SAAS,OAGtD,MAAM,IAAI,UAAU,+BAA+B;CAGrD,IAAI,OAAO,QAAQ,UAAU,YAAY,QAAQ,UAAU,MACzD,MAAM,IAAI,UAAU,+BAA+B;AAEvD"}
|