@openrouter/agent 0.7.1 → 0.8.0
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 +248 -17
- package/esm/index.d.ts +8 -5
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +12 -4
- package/esm/index.js.map +1 -1
- package/esm/inner-loop/call-model.d.ts +8 -5
- package/esm/inner-loop/call-model.d.ts.map +1 -1
- package/esm/inner-loop/call-model.js +16 -6
- package/esm/inner-loop/call-model.js.map +1 -1
- package/esm/lib/async-params.d.ts +25 -6
- package/esm/lib/async-params.d.ts.map +1 -1
- package/esm/lib/async-params.js +3 -1
- package/esm/lib/async-params.js.map +1 -1
- package/esm/lib/conversation-state.d.ts +44 -1
- package/esm/lib/conversation-state.d.ts.map +1 -1
- package/esm/lib/conversation-state.js +111 -0
- package/esm/lib/conversation-state.js.map +1 -1
- package/esm/lib/hooks-emit.d.ts +50 -0
- package/esm/lib/hooks-emit.d.ts.map +1 -0
- package/esm/lib/hooks-emit.js +307 -0
- package/esm/lib/hooks-emit.js.map +1 -0
- package/esm/lib/hooks-manager.d.ts +141 -0
- package/esm/lib/hooks-manager.d.ts.map +1 -0
- package/esm/lib/hooks-manager.js +282 -0
- package/esm/lib/hooks-manager.js.map +1 -0
- package/esm/lib/hooks-matchers.d.ts +12 -0
- package/esm/lib/hooks-matchers.d.ts.map +1 -0
- package/esm/lib/hooks-matchers.js +26 -0
- package/esm/lib/hooks-matchers.js.map +1 -0
- package/esm/lib/hooks-resolve.d.ts +17 -0
- package/esm/lib/hooks-resolve.d.ts.map +1 -0
- package/esm/lib/hooks-resolve.js +42 -0
- package/esm/lib/hooks-resolve.js.map +1 -0
- package/esm/lib/hooks-schemas.d.ts +188 -0
- package/esm/lib/hooks-schemas.d.ts.map +1 -0
- package/esm/lib/hooks-schemas.js +184 -0
- package/esm/lib/hooks-schemas.js.map +1 -0
- package/esm/lib/hooks-types.d.ts +174 -0
- package/esm/lib/hooks-types.d.ts.map +1 -0
- package/esm/lib/hooks-types.js +45 -0
- package/esm/lib/hooks-types.js.map +1 -0
- package/esm/lib/model-result.d.ts +209 -9
- package/esm/lib/model-result.d.ts.map +1 -1
- package/esm/lib/model-result.js +1397 -348
- package/esm/lib/model-result.js.map +1 -1
- package/esm/lib/reusable-stream.d.ts +6 -0
- package/esm/lib/reusable-stream.d.ts.map +1 -1
- package/esm/lib/reusable-stream.js +8 -0
- package/esm/lib/reusable-stream.js.map +1 -1
- package/esm/lib/tool-executor.d.ts.map +1 -1
- package/esm/lib/tool-executor.js +11 -1
- package/esm/lib/tool-executor.js.map +1 -1
- package/esm/lib/tool-orchestrator.d.ts.map +1 -1
- package/esm/lib/tool-orchestrator.js +4 -1
- package/esm/lib/tool-orchestrator.js.map +1 -1
- package/esm/lib/tool-types.d.ts +137 -45
- package/esm/lib/tool-types.d.ts.map +1 -1
- package/esm/lib/tool-types.js +13 -0
- package/esm/lib/tool-types.js.map +1 -1
- package/esm/lib/tool.d.ts +35 -25
- package/esm/lib/tool.d.ts.map +1 -1
- package/esm/lib/tool.js +19 -0
- package/esm/lib/tool.js.map +1 -1
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -82,9 +82,14 @@ for await (const delta of result.getReasoningStream()) {
|
|
|
82
82
|
process.stdout.write(delta);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
// Stream tool
|
|
85
|
+
// Stream tool-call argument deltas (plus preliminary results from generator tools)
|
|
86
86
|
for await (const event of result.getToolStream()) {
|
|
87
|
-
console.log(event);
|
|
87
|
+
console.log(event); // { type: 'delta', content: '...' } | { type: 'preliminary_result', ... }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Stream all response events, including tool execution results
|
|
91
|
+
for await (const event of result.getFullResponsesStream()) {
|
|
92
|
+
// includes tool.result / tool.call_output events
|
|
88
93
|
}
|
|
89
94
|
|
|
90
95
|
// Stream structured tool calls
|
|
@@ -96,6 +101,17 @@ for await (const toolCall of result.getToolCallsStream()) {
|
|
|
96
101
|
const toolCalls = await result.getToolCalls();
|
|
97
102
|
```
|
|
98
103
|
|
|
104
|
+
What each stream emits:
|
|
105
|
+
|
|
106
|
+
| Method | Emits |
|
|
107
|
+
|---|---|
|
|
108
|
+
| `getTextStream()` | assistant text deltas |
|
|
109
|
+
| `getReasoningStream()` | reasoning deltas |
|
|
110
|
+
| `getToolStream()` | tool-call **argument deltas**; `preliminary_result` events for generator tools — *not* execution results |
|
|
111
|
+
| `getToolCallsStream()` | parsed tool calls as they complete |
|
|
112
|
+
| `getItemsStream()` | all output items (messages, function calls, …) |
|
|
113
|
+
| `getFullResponsesStream()` | every response event, including `tool.result` / `tool.call_output` execution events |
|
|
114
|
+
|
|
99
115
|
### Tool Types
|
|
100
116
|
|
|
101
117
|
The `tool()` factory creates type-safe tools with full Zod schema inference. Three tool types are supported:
|
|
@@ -171,8 +187,12 @@ Built-in stop conditions:
|
|
|
171
187
|
|
|
172
188
|
**Final response after stop**
|
|
173
189
|
|
|
174
|
-
When `stopWhen` fires while the model is still emitting tool calls,
|
|
175
|
-
|
|
190
|
+
When `stopWhen` fires while the model is still emitting tool calls, the
|
|
191
|
+
loop makes one more model turn with `toolChoice: 'none'` so the run ends
|
|
192
|
+
with a natural-language answer instead of a half-finished tool call.
|
|
193
|
+
Tools stay in the request — only calling is forbidden — which preserves
|
|
194
|
+
the prompt-cache prefix. **This is on by default**; `allowFinalResponse`
|
|
195
|
+
tunes it:
|
|
176
196
|
|
|
177
197
|
```typescript
|
|
178
198
|
callModel(client, {
|
|
@@ -180,15 +200,22 @@ callModel(client, {
|
|
|
180
200
|
input: 'Research this topic',
|
|
181
201
|
tools: [searchTool] as const,
|
|
182
202
|
stopWhen: stepCountIs(5),
|
|
183
|
-
|
|
184
|
-
//
|
|
203
|
+
// default (omitted or `true`): appends DEFAULT_FINAL_RESPONSE_DIRECTIVE
|
|
204
|
+
// as a final user message so the model writes an answer instead of
|
|
205
|
+
// attempting another tool call
|
|
206
|
+
|
|
207
|
+
// override the directive wording:
|
|
208
|
+
// allowFinalResponse: 'Please summarize what you found.',
|
|
209
|
+
// append no message (turn still happens, calls still forbidden):
|
|
210
|
+
// allowFinalResponse: '',
|
|
211
|
+
// disable the final turn entirely:
|
|
212
|
+
// allowFinalResponse: false,
|
|
185
213
|
});
|
|
186
214
|
```
|
|
187
215
|
|
|
188
216
|
The pending tool calls from the halted turn are executed first so they
|
|
189
217
|
have real outputs in the input, then the full conversation and the
|
|
190
|
-
original `instructions` are sent
|
|
191
|
-
non-empty string value is appended as a final `user` message. Any
|
|
218
|
+
original `instructions` are sent with `toolChoice: 'none'`. Any
|
|
192
219
|
non-executable (manual) tool calls in the halted turn are paired with
|
|
193
220
|
synthesized stub `function_call_output` items so the input is well-formed.
|
|
194
221
|
|
|
@@ -224,6 +251,195 @@ const result = callModel(client, {
|
|
|
224
251
|
});
|
|
225
252
|
```
|
|
226
253
|
|
|
254
|
+
### Lifecycle Hooks
|
|
255
|
+
|
|
256
|
+
Observe and control the agent loop with typed lifecycle hooks — inspect or
|
|
257
|
+
block tool calls, mutate inputs, gate approvals programmatically, intercept
|
|
258
|
+
prompts, and run audit/telemetry work. Inspired by the Claude Agent SDK hooks
|
|
259
|
+
pattern.
|
|
260
|
+
|
|
261
|
+
> [!NOTE]
|
|
262
|
+
> Lifecycle hooks are distinct from the SDK **transport** hooks
|
|
263
|
+
> (`SDKHooks`, `BeforeRequestHook`, `HookContext`, …), which intercept
|
|
264
|
+
> HTTP requests. Lifecycle hooks fire on agent-loop events.
|
|
265
|
+
|
|
266
|
+
**Two usage modes.** Pass a plain object for quick setup, or a `HooksManager`
|
|
267
|
+
instance for custom hooks, dynamic registration, and programmatic emit:
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
// Inline config — built-in hooks only
|
|
271
|
+
const result = callModel(client, {
|
|
272
|
+
model: 'openai/gpt-4o',
|
|
273
|
+
input: 'Clean up the temp directory',
|
|
274
|
+
tools: [shellTool] as const,
|
|
275
|
+
hooks: {
|
|
276
|
+
PreToolUse: [
|
|
277
|
+
{
|
|
278
|
+
matcher: 'run_shell', // string | RegExp | (toolName) => boolean
|
|
279
|
+
handler: ({ toolName, toolInput }) => {
|
|
280
|
+
if (String(toolInput.command).includes('rm -rf /')) {
|
|
281
|
+
return { block: 'Refusing to run a destructive command' };
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
PostToolUse: [
|
|
287
|
+
{ handler: ({ toolName, durationMs }) => console.log(toolName, durationMs) },
|
|
288
|
+
],
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
// HooksManager — full control
|
|
295
|
+
import { HooksManager } from '@openrouter/agent';
|
|
296
|
+
|
|
297
|
+
const hooks = new HooksManager();
|
|
298
|
+
|
|
299
|
+
const unsubscribe = hooks.on('PreToolUse', {
|
|
300
|
+
matcher: /^db_/,
|
|
301
|
+
filter: (payload) => Object.keys(payload.toolInput).length > 0, // optional predicate on the payload
|
|
302
|
+
handler: ({ toolInput }, ctx) => {
|
|
303
|
+
console.log(`[${ctx.sessionId}] intercepting db tool`); // session id lives on the context
|
|
304
|
+
return {
|
|
305
|
+
// Replace the tool's input before execution (mutation piping)
|
|
306
|
+
mutatedInput: { ...toolInput, dryRun: true },
|
|
307
|
+
};
|
|
308
|
+
},
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
const result = callModel(client, { model, input, tools, hooks });
|
|
312
|
+
|
|
313
|
+
// Later: unsubscribe(), hooks.off(...), hooks.removeAll(...)
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
**Built-in hooks**
|
|
317
|
+
|
|
318
|
+
| Hook | Fires | Result fields |
|
|
319
|
+
|---|---|---|
|
|
320
|
+
| `PreToolUse` | Before every client-tool execution (auto, approval-resume, and hook-allowed paths) | `mutatedInput` replaces the tool's arguments; `block: true \| string` skips execution and reports the reason as the tool's error output |
|
|
321
|
+
| `PostToolUse` | After a successful tool execution (payload includes `toolOutput`, `durationMs`) | none (void) |
|
|
322
|
+
| `PostToolUseFailure` | After a tool execution throws or returns an error. Not fired when a tool never ran (`PermissionRequest` deny, user rejection, `PreToolUse` block) — observe those via the gating hooks themselves | none (void) |
|
|
323
|
+
| `UserPromptSubmit` | Before the initial API request, with the user prompt string | `mutatedPrompt` replaces the prompt; `reject: true \| string` aborts the call with an error |
|
|
324
|
+
| `PermissionRequest` | When a tool requires approval, before pausing for the human gate | `decision: 'allow'` skips the gate (the tool runs once via the normal round), `'deny'` synthesizes a rejected result without executing, `'ask_user'` (default) falls through to the approval flow. Last handler wins. Payload includes a `riskLevel` derived from the approval gate's shape (`'high'` for tool- or call-level functions, `'medium'` for blanket `true`) |
|
|
325
|
+
| `Stop` | When a `stopWhen` condition halts the loop (`reason: 'max_turns'`) | `forceResume: true` continues the loop (capped at 3 consecutive overrides without tool progress — a bare `forceResume` that changes no state will typically re-trigger the stop condition immediately and burn through the cap, so pair it with `appendPrompt` or external state the stop condition observes); `appendPrompt` injects a user message for the next turn (honored independently of `forceResume`). Blocked/rejected tool outputs count as progress for the cap: the model receives that feedback, and each round costs a full request, so the loop cannot spin hot |
|
|
326
|
+
| `SessionStart` | Once per run, before the initial request. `config` summarizes the session (`hasTools`, `hasApproval`, `hasState`) | none (void) |
|
|
327
|
+
| `SessionEnd` | Once per run, on every exit path — completion, approval pause, interruption, error, and the no-tools streaming paths. `reason` is `'complete' \| 'error' \| 'max_turns' \| 'user'`. When at least one model call completed, `totalUsage` aggregates tokens/cost across all of them (`modelCalls`, `inputTokens`, `outputTokens`, `totalTokens`, `cachedTokens`, `reasoningTokens`, and `cost` when the server reported it) | none (void) |
|
|
328
|
+
| `PostModelCall` | Once per completed model response, on **every** request the loop makes — initial, each tool-round follow-up, the empty-final retry, the `allowFinalResponse` final turn, and approval-resume requests. Payload: `responseId` (the OpenRouter generation id), `model`, `durationMs` (dispatch → fully materialized response, including stream consumption), `turnType` (`'initial' \| 'resume' \| 'tool_round' \| 'final' \| 'retry'`), `turnNumber`, and `usage` (`inputTokens`, `outputTokens`, `totalTokens`, `cachedTokens`, `reasoningTokens`, `cost?`) when the server reported usage accounting. Purely observational — the telemetry primitive for tracing/benchmark consumers: one span per model call | none (void) |
|
|
329
|
+
|
|
330
|
+
Notes on lifecycle pairing: `SessionEnd` only fires when a matching
|
|
331
|
+
`SessionStart` succeeded, and at most once per run. Pending async hook work is
|
|
332
|
+
always drained on teardown — including on paths that skip `SessionStart`,
|
|
333
|
+
such as resuming from a tool approval. A throwing `SessionEnd` handler never
|
|
334
|
+
masks the run's original error (teardown failures are logged as warnings).
|
|
335
|
+
|
|
336
|
+
On no-tools streaming paths the initial response is only materialized when the
|
|
337
|
+
stream is consumed, so `PostModelCall` for that response fires during session
|
|
338
|
+
teardown (before `SessionEnd`). A stream that fails or errors before producing
|
|
339
|
+
a materialized response emits no `PostModelCall`; a `response.incomplete`
|
|
340
|
+
response (e.g. truncated at `max_output_tokens`) **does** emit — it carries a
|
|
341
|
+
real generation id and consumed tokens. Note `usage.cost` is only present when
|
|
342
|
+
the request had usage accounting enabled server-side.
|
|
343
|
+
Every handler receives `(payload, context)` — `context` carries the
|
|
344
|
+
`sessionId` (the single source of session identity; payloads do not repeat
|
|
345
|
+
it), the `hookName`, and an `AbortSignal` for cooperative cancellation. The
|
|
346
|
+
engine threads the session id into each emit's context, so a single
|
|
347
|
+
`HooksManager` instance can be shared safely across concurrent `callModel`
|
|
348
|
+
runs — each run's handlers see that run's id. (If you call `emit()` yourself
|
|
349
|
+
on a shared manager, pass `{ sessionId }` in the emit context; the
|
|
350
|
+
`setSessionId()` default is a single mutable field and is last-writer-wins.)
|
|
351
|
+
|
|
352
|
+
**Handler chain semantics**
|
|
353
|
+
|
|
354
|
+
Handlers for a hook run sequentially in registration order.
|
|
355
|
+
|
|
356
|
+
- **Matchers** (`matcher`) scope a handler to tool names — exact string,
|
|
357
|
+
`RegExp` (stateful `/g`//`/y` flags are handled safely), or a predicate
|
|
358
|
+
function (truthy/falsy returns are coerced to boolean). Matchers fail
|
|
359
|
+
closed: a matcher-scoped handler is skipped when the emit has no tool name.
|
|
360
|
+
- **Filters** (`filter`) are arbitrary predicates on the payload.
|
|
361
|
+
- **Mutation piping**: a handler's `mutatedInput`/`mutatedPrompt` replaces the
|
|
362
|
+
corresponding payload field for all subsequent handlers in the chain, and
|
|
363
|
+
for the tool/request itself. A blocking handler's mutation still lands
|
|
364
|
+
before the short-circuit.
|
|
365
|
+
- **Short-circuit**: `block`/`reject` with `true` or a non-empty string stops
|
|
366
|
+
the chain (empty strings do not block).
|
|
367
|
+
- **Error policy**: by default a throwing handler — or a throwing
|
|
368
|
+
matcher/filter — is logged as a warning and skipped, and the chain
|
|
369
|
+
continues. Construct the manager with
|
|
370
|
+
`new HooksManager(custom, { throwOnHandlerError: true })` to propagate
|
|
371
|
+
errors instead (useful in tests).
|
|
372
|
+
|
|
373
|
+
**Async fire-and-forget handlers**
|
|
374
|
+
|
|
375
|
+
A handler can detach background work (telemetry, audit writes) without
|
|
376
|
+
blocking the loop by returning an `AsyncOutput` signal:
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
hooks.on('PostToolUse', {
|
|
380
|
+
handler: (payload, ctx) => ({
|
|
381
|
+
async: true,
|
|
382
|
+
work: sendTelemetry(payload, { signal: ctx.signal }),
|
|
383
|
+
asyncTimeout: 5_000, // default 30_000
|
|
384
|
+
}),
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
// On shutdown: abort in-flight handlers, then wait for detached work
|
|
388
|
+
hooks.abortInflight('shutdown');
|
|
389
|
+
await hooks.drain();
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
`drain()` waits for all detached work, bounded per-handler by `asyncTimeout`.
|
|
393
|
+
On timeout the emit's `ctx.signal` is aborted and a warning is logged — the
|
|
394
|
+
work itself cannot be forcibly cancelled, so handlers should observe
|
|
395
|
+
`ctx.signal` to stop cooperatively. `abortInflight()` reaches detached work
|
|
396
|
+
even after the originating `emit()` has returned. The signal object must have
|
|
397
|
+
**exactly** the `AsyncOutput` shape (`async: true` plus optional `work`/
|
|
398
|
+
`asyncTimeout`); a return value carrying any other field is treated as a
|
|
399
|
+
regular result so mutations/blocks are never silently discarded. The
|
|
400
|
+
`isAsyncOutput` type guard is exported.
|
|
401
|
+
|
|
402
|
+
**Custom hooks**
|
|
403
|
+
|
|
404
|
+
Define your own hooks with Zod schema pairs and full type inference, then emit
|
|
405
|
+
them from your own code:
|
|
406
|
+
|
|
407
|
+
```typescript
|
|
408
|
+
import { HooksManager } from '@openrouter/agent';
|
|
409
|
+
import { z } from 'zod/v4';
|
|
410
|
+
|
|
411
|
+
const hooks = new HooksManager({
|
|
412
|
+
DeploymentGate: {
|
|
413
|
+
payload: z.object({ environment: z.string(), version: z.string() }),
|
|
414
|
+
result: z.object({ approved: z.boolean() }),
|
|
415
|
+
},
|
|
416
|
+
AuditLog: {
|
|
417
|
+
payload: z.object({ event: z.string() }),
|
|
418
|
+
result: z.void(), // side-effect only: results are not validated
|
|
419
|
+
},
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
hooks.on('DeploymentGate', {
|
|
423
|
+
handler: ({ environment }) => ({ approved: environment !== 'production' }),
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
const { results } = await hooks.emit('DeploymentGate', {
|
|
427
|
+
environment: 'staging',
|
|
428
|
+
version: '1.2.3',
|
|
429
|
+
});
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
Payloads and results are validated against the schemas on every `emit`.
|
|
433
|
+
Schemas with `.transform()`, `.default()`, or `.coerce` are honored: handlers
|
|
434
|
+
receive the parsed **output** values, matching the inferred TypeScript types.
|
|
435
|
+
Custom hook names must be non-empty and must not collide with built-in names.
|
|
436
|
+
Custom hooks do not participate in mutation piping or blocking (those are
|
|
437
|
+
built-in-only behaviors); the inline config surface only accepts built-in
|
|
438
|
+
hooks — unknown names are warned about and skipped.
|
|
439
|
+
|
|
440
|
+
A payload validation failure follows the same error policy as handlers:
|
|
441
|
+
logged and skipped by default, thrown in strict mode.
|
|
442
|
+
|
|
227
443
|
### Tool Context
|
|
228
444
|
|
|
229
445
|
Provide typed context data to tools without passing it through the model:
|
|
@@ -234,7 +450,8 @@ const dbTool = tool({
|
|
|
234
450
|
inputSchema: z.object({ sql: z.string() }),
|
|
235
451
|
contextSchema: z.object({ connectionString: z.string() }),
|
|
236
452
|
execute: async ({ sql }, ctx) => {
|
|
237
|
-
|
|
453
|
+
// Tool context is available on ctx.local
|
|
454
|
+
const db = connect(ctx?.local.connectionString);
|
|
238
455
|
return db.query(sql);
|
|
239
456
|
},
|
|
240
457
|
});
|
|
@@ -267,13 +484,22 @@ const result = callModel(client, {
|
|
|
267
484
|
|
|
268
485
|
### Conversation State Management
|
|
269
486
|
|
|
270
|
-
Persist multi-turn conversations with full state tracking
|
|
487
|
+
Persist multi-turn conversations with full state tracking. The `state`
|
|
488
|
+
option takes a `StateAccessor` — a `{ load, save }` pair over any storage
|
|
489
|
+
backend (memory, SQLite, Redis, …). The loop calls `load` before the run and
|
|
490
|
+
`save` as the conversation progresses:
|
|
271
491
|
|
|
272
492
|
```typescript
|
|
273
|
-
import {
|
|
274
|
-
|
|
275
|
-
//
|
|
276
|
-
let
|
|
493
|
+
import { callModel, type ConversationState, type StateAccessor } from '@openrouter/agent';
|
|
494
|
+
|
|
495
|
+
// Any storage backend — here, a simple in-memory holder
|
|
496
|
+
let stored: ConversationState | null = null;
|
|
497
|
+
const state: StateAccessor = {
|
|
498
|
+
load: async () => stored,
|
|
499
|
+
save: async (s) => {
|
|
500
|
+
stored = s;
|
|
501
|
+
},
|
|
502
|
+
};
|
|
277
503
|
|
|
278
504
|
// First turn
|
|
279
505
|
const result1 = callModel(client, {
|
|
@@ -282,11 +508,12 @@ const result1 = callModel(client, {
|
|
|
282
508
|
tools: [searchTool] as const,
|
|
283
509
|
state,
|
|
284
510
|
});
|
|
511
|
+
await result1.getText();
|
|
285
512
|
|
|
286
|
-
//
|
|
287
|
-
|
|
513
|
+
// Read the updated state (messages, tool calls, status, metadata)
|
|
514
|
+
const snapshot = await result1.getState();
|
|
288
515
|
|
|
289
|
-
// Continue the conversation
|
|
516
|
+
// Continue the conversation — the accessor loads the saved history
|
|
290
517
|
const result2 = callModel(client, {
|
|
291
518
|
model: 'openai/gpt-4o',
|
|
292
519
|
input: 'Now summarize what you found',
|
|
@@ -295,6 +522,9 @@ const result2 = callModel(client, {
|
|
|
295
522
|
});
|
|
296
523
|
```
|
|
297
524
|
|
|
525
|
+
`ConversationState` is plain JSON — `JSON.stringify`/`JSON.parse` it into any
|
|
526
|
+
store (this is how serverless/cold-start resume works).
|
|
527
|
+
|
|
298
528
|
### Dynamic Parameters Between Turns
|
|
299
529
|
|
|
300
530
|
Adjust model parameters dynamically based on tool execution:
|
|
@@ -336,6 +566,7 @@ For tree-shaking or targeted imports, the package provides granular subpath expo
|
|
|
336
566
|
import { callModel } from '@openrouter/agent/call-model';
|
|
337
567
|
import { tool } from '@openrouter/agent/tool';
|
|
338
568
|
import { ModelResult } from '@openrouter/agent/model-result';
|
|
569
|
+
import { HooksManager } from '@openrouter/agent/hooks-manager';
|
|
339
570
|
import { stepCountIs, maxCost } from '@openrouter/agent/stop-conditions';
|
|
340
571
|
import { toClaudeMessage } from '@openrouter/agent/anthropic-compat';
|
|
341
572
|
import { toChatMessage } from '@openrouter/agent/chat-compat';
|
package/esm/index.d.ts
CHANGED
|
@@ -10,19 +10,22 @@ export { hasAsyncFunctions, resolveAsyncFunctions } from './lib/async-params.js'
|
|
|
10
10
|
export { fromChatMessages, toChatMessage } from './lib/chat-compat.js';
|
|
11
11
|
export { ClaudeContentBlockType, NonClaudeMessageRole } from './lib/claude-constants.js';
|
|
12
12
|
export { isClaudeStyleMessages } from './lib/claude-type-guards.js';
|
|
13
|
-
export { appendToMessages, createInitialState, createRejectedResult, createUnsentResult, generateConversationId, partitionToolCalls, toolRequiresApproval, updateState, } from './lib/conversation-state.js';
|
|
13
|
+
export { appendToMessages, CONVERSATION_STATE_VERSION, createInitialState, createRejectedResult, createUnsentResult, deserializeConversationState, generateConversationId, InvalidStateError, partitionToolCalls, serializeConversationState, toolRequiresApproval, UnsupportedStateVersionError, updateState, } from './lib/conversation-state.js';
|
|
14
|
+
export { HooksManager } from './lib/hooks-manager.js';
|
|
15
|
+
export type { AsyncOutput, BuiltInHookDefinitions, EmitResult, HookDefinition, HookEntry, HookHandler, HookRegistry, HookReturn, HooksManagerOptions, InlineHookConfig, LifecycleHookContext, ModelCallUsage, PermissionRequestPayload, PermissionRequestResult, PostModelCallPayload, PostToolUseFailurePayload, PostToolUsePayload, PreToolUsePayload, PreToolUseResult, SessionEndPayload, SessionStartPayload, SessionUsageTotals, StopPayload, StopResult, ToolMatcher, UserPromptSubmitPayload, UserPromptSubmitResult, } from './lib/hooks-types.js';
|
|
16
|
+
export { HookName, isAsyncOutput } from './lib/hooks-types.js';
|
|
14
17
|
export type { GetResponseOptions } from './lib/model-result.js';
|
|
15
|
-
export { ModelResult } from './lib/model-result.js';
|
|
18
|
+
export { DEFAULT_FINAL_RESPONSE_DIRECTIVE, ModelResult } from './lib/model-result.js';
|
|
16
19
|
export { applyNextTurnParamsToRequest, buildNextTurnParamsContext, executeNextTurnParamsFunctions, } from './lib/next-turn-params.js';
|
|
17
20
|
export { finishReasonIs, hasToolCall, isStopConditionMet, maxCost, maxTokensUsed, stepCountIs, } from './lib/stop-conditions.js';
|
|
18
21
|
export type { StreamableOutputItem } from './lib/stream-transformers.js';
|
|
19
22
|
export { extractUnsupportedContent, getUnsupportedContentSummary, hasUnsupportedContent, } from './lib/stream-transformers.js';
|
|
20
|
-
export { serverTool, tool } from './lib/tool.js';
|
|
23
|
+
export { markMcp, serverTool, tool } from './lib/tool.js';
|
|
21
24
|
export type { ContextInput } from './lib/tool-context.js';
|
|
22
25
|
export { buildToolExecuteContext, ToolContextStore } from './lib/tool-context.js';
|
|
23
26
|
export { ToolEventBroadcaster } from './lib/tool-event-broadcaster.js';
|
|
24
|
-
export type { ChatStreamEvent, ClientTool, ConversationState, ConversationStatus, HasApprovalTools, HITLTool, HITLToolFunction, InferToolEvent, InferToolEventsUnion, InferToolInput, InferToolOutput, InferToolOutputsUnion, ManualTool, NextTurnParamsContext, NextTurnParamsFunctions, ParsedToolCall, PartialResponse, ResponseStreamEvent, ResponseStreamEvent as EnhancedResponseStreamEvent, ServerTool, ServerToolConfig, ServerToolResultItem, ServerToolType, StateAccessor, StepResult, StopCondition, StopWhen, ToModelOutputFunction, ToModelOutputResult, Tool, ToolApprovalCheck, ToolCallOutputEvent, ToolExecutionResult, ToolExecutionResultUnion, ToolHasApproval, ToolOutputContentItem, ToolPreliminaryResultEvent, ToolResultEvent, ToolResultItem, ToolStreamEvent, ToolWithExecute, ToolWithGenerator, TurnContext, TurnEndEvent, TurnStartEvent, TypedToolCall, TypedToolCallUnion, UnsentToolResult, Warning, } from './lib/tool-types.js';
|
|
25
|
-
export { hasApprovalRequiredTools, hasExecuteFunction, isAutoResolvableTool, isClientTool, isGeneratorTool, isHITLTool, isManualTool, isRegularExecuteTool, isServerTool, isToolCallOutputEvent, isToolPreliminaryResultEvent, isToolResultEvent, isTurnEndEvent, isTurnStartEvent, ToolType, toolHasApprovalConfigured, } from './lib/tool-types.js';
|
|
27
|
+
export type { ChatStreamEvent, ClientTool, ConversationState, ConversationStatus, HasApprovalTools, HITLTool, HITLToolFunction, InferToolEvent, InferToolEventsUnion, InferToolInput, InferToolOutput, InferToolOutputsUnion, ManualTool, McpBranded, NextTurnParamsContext, NextTurnParamsFunctions, ParsedToolCall, PartialResponse, ResponseStreamEvent, ResponseStreamEvent as EnhancedResponseStreamEvent, ServerTool, ServerToolConfig, ServerToolResultItem, ServerToolType, StateAccessor, StepResult, StopCondition, StopWhen, ToModelOutputFunction, ToModelOutputResult, Tool, ToolApprovalCheck, ToolCallOutputEvent, ToolExecutionResult, ToolExecutionResultUnion, ToolHasApproval, ToolOutputContentItem, ToolPreliminaryResultEvent, ToolResultEvent, ToolResultItem, ToolStreamEvent, ToolWithExecute, ToolWithGenerator, TurnContext, TurnEndEvent, TurnStartEvent, TypedToolCall, TypedToolCallUnion, UnsentToolResult, Warning, } from './lib/tool-types.js';
|
|
28
|
+
export { hasApprovalRequiredTools, hasExecuteFunction, isAutoResolvableTool, isClientTool, isGeneratorTool, isHITLTool, isManualTool, isMcpTool, isRegularExecuteTool, isServerTool, isToolCallOutputEvent, isToolPreliminaryResultEvent, isToolResultEvent, isTurnEndEvent, isTurnStartEvent, ToolType, toolHasApprovalConfigured, } from './lib/tool-types.js';
|
|
26
29
|
export { buildTurnContext, normalizeInputToArray } from './lib/turn-context.js';
|
|
27
30
|
export type { Hook, OpenRouterOptions, SDKOptions } from './openrouter.js';
|
|
28
31
|
export { OpenRouter } from './openrouter.js';
|
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,0BAA0B,EAC1B,uBAAuB,EACvB,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,WAAW,GACZ,MAAM,6BAA6B,CAAC;AACrC,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/D,YAAY,EAEV,eAAe,EAEf,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,EAChB,iCAAiC,EACjC,6BAA6B,EAC7B,yBAAyB,EAEzB,UAAU,EACV,gBAAgB,EAChB,sBAAsB,EAEtB,UAAU,EACV,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,UAAU,EACV,8BAA8B,EAC9B,mBAAmB,EAEnB,wBAAwB,EACxB,sBAAsB,EACtB,WAAW,EACX,WAA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E,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAChF,YAAY,EAAE,IAAI,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
package/esm/index.js
CHANGED
|
@@ -12,20 +12,28 @@ export { fromChatMessages, toChatMessage } from './lib/chat-compat.js';
|
|
|
12
12
|
export { ClaudeContentBlockType, NonClaudeMessageRole } from './lib/claude-constants.js';
|
|
13
13
|
export { isClaudeStyleMessages } from './lib/claude-type-guards.js';
|
|
14
14
|
// Conversation state helpers
|
|
15
|
-
export { appendToMessages, createInitialState, createRejectedResult, createUnsentResult, generateConversationId, partitionToolCalls, toolRequiresApproval, updateState, } from './lib/conversation-state.js';
|
|
16
|
-
|
|
15
|
+
export { appendToMessages, CONVERSATION_STATE_VERSION, createInitialState, createRejectedResult, createUnsentResult, deserializeConversationState, generateConversationId, InvalidStateError, partitionToolCalls, serializeConversationState, toolRequiresApproval, UnsupportedStateVersionError, updateState, } from './lib/conversation-state.js';
|
|
16
|
+
// Lifecycle hooks system (PreToolUse, PostToolUse, Stop, SessionStart, ...).
|
|
17
|
+
// Distinct from the SDK transport hooks re-exported above (SDKHooks,
|
|
18
|
+
// BeforeRequestHook, HookContext, ...), which intercept HTTP requests.
|
|
19
|
+
// Internals (matchesTool, resolveHooks, BUILT_IN_HOOKS, raw Zod schemas) are
|
|
20
|
+
// deliberately NOT exported: everything here is semver surface, and the raw
|
|
21
|
+
// schema objects are mutable.
|
|
22
|
+
export { HooksManager } from './lib/hooks-manager.js';
|
|
23
|
+
export { HookName, isAsyncOutput } from './lib/hooks-types.js';
|
|
24
|
+
export { DEFAULT_FINAL_RESPONSE_DIRECTIVE, ModelResult } from './lib/model-result.js';
|
|
17
25
|
// Next turn params helpers
|
|
18
26
|
export { applyNextTurnParamsToRequest, buildNextTurnParamsContext, executeNextTurnParamsFunctions, } from './lib/next-turn-params.js';
|
|
19
27
|
// Stop condition helpers
|
|
20
28
|
export { finishReasonIs, hasToolCall, isStopConditionMet, maxCost, maxTokensUsed, stepCountIs, } from './lib/stop-conditions.js';
|
|
21
29
|
export { extractUnsupportedContent, getUnsupportedContentSummary, hasUnsupportedContent, } from './lib/stream-transformers.js';
|
|
22
30
|
// Tool creation helpers
|
|
23
|
-
export { serverTool, tool } from './lib/tool.js';
|
|
31
|
+
export { markMcp, serverTool, tool } from './lib/tool.js';
|
|
24
32
|
// Tool context helpers
|
|
25
33
|
export { buildToolExecuteContext, ToolContextStore } from './lib/tool-context.js';
|
|
26
34
|
// Real-time tool event broadcasting
|
|
27
35
|
export { ToolEventBroadcaster } from './lib/tool-event-broadcaster.js';
|
|
28
|
-
export { hasApprovalRequiredTools, hasExecuteFunction, isAutoResolvableTool, isClientTool, isGeneratorTool, isHITLTool, isManualTool, isRegularExecuteTool, isServerTool, isToolCallOutputEvent, isToolPreliminaryResultEvent, isToolResultEvent, isTurnEndEvent, isTurnStartEvent, ToolType, toolHasApprovalConfigured, } from './lib/tool-types.js';
|
|
36
|
+
export { hasApprovalRequiredTools, hasExecuteFunction, isAutoResolvableTool, isClientTool, isGeneratorTool, isHITLTool, isManualTool, isMcpTool, isRegularExecuteTool, isServerTool, isToolCallOutputEvent, isToolPreliminaryResultEvent, isToolResultEvent, isTurnEndEvent, isTurnStartEvent, ToolType, toolHasApprovalConfigured, } from './lib/tool-types.js';
|
|
29
37
|
// Turn context helpers
|
|
30
38
|
export { buildTurnContext, normalizeInputToArray } from './lib/turn-context.js';
|
|
31
39
|
export { OpenRouter } from './openrouter.js';
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,iEAAiE;AAEjE,yDAAyD;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AA2EvD,uCAAuC;AAEvC,2BAA2B;AAC3B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;AACvB,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEhF,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -64,11 +64,14 @@ export type { CallModelInput } from '../lib/async-params.js';
|
|
|
64
64
|
*
|
|
65
65
|
* **Final Response After Stop:**
|
|
66
66
|
*
|
|
67
|
-
* When `stopWhen` fires while the model is still emitting tool calls,
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* than a half-finished tool call.
|
|
71
|
-
*
|
|
67
|
+
* When `stopWhen` fires while the model is still emitting tool calls, the
|
|
68
|
+
* loop makes one final model turn with `toolChoice: 'none'` (tools stay in
|
|
69
|
+
* the request to preserve the prompt cache) so the run ends with a
|
|
70
|
+
* natural-language answer rather than a half-finished tool call. This is
|
|
71
|
+
* the default; `allowFinalResponse` tunes it: `true`/omitted appends a
|
|
72
|
+
* default final-answer directive as a user message, a non-empty string
|
|
73
|
+
* replaces the wording, `''` appends nothing, `false` disables the final
|
|
74
|
+
* turn entirely.
|
|
72
75
|
*/
|
|
73
76
|
export declare function callModel<TTools extends readonly Tool[], TSharedSchema extends $ZodObject<$ZodShape> | undefined = undefined, TShared extends Record<string, unknown> = TSharedSchema extends $ZodObject<$ZodShape> ? zodInfer<TSharedSchema> : Record<string, never>>(client: OpenRouterCore, request: CallModelInput<TTools, TShared> & {
|
|
74
77
|
sharedContextSchema?: TSharedSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call-model.d.ts","sourceRoot":"","sources":["../../src/inner-loop/call-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"call-model.d.ts","sourceRoot":"","sources":["../../src/inner-loop/call-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAGjD,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,wBAAgB,SAAS,CACvB,MAAM,SAAS,SAAS,IAAI,EAAE,EAC9B,aAAa,SAAS,UAAU,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG,SAAS,EACnE,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,SAAS,UAAU,CAAC,SAAS,CAAC,GACjF,QAAQ,CAAC,aAAa,CAAC,GACvB,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEzB,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACzC,mBAAmB,CAAC,EAAE,aAAa,CAAC;CACrC,EACD,OAAO,CAAC,EAAE,cAAc,GACvB,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAuF9B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveHooks } from '../lib/hooks-resolve.js';
|
|
1
2
|
import { ModelResult } from '../lib/model-result.js';
|
|
2
3
|
import { convertToolsToAPIFormat } from '../lib/tool-executor.js';
|
|
3
4
|
/**
|
|
@@ -59,15 +60,18 @@ import { convertToolsToAPIFormat } from '../lib/tool-executor.js';
|
|
|
59
60
|
*
|
|
60
61
|
* **Final Response After Stop:**
|
|
61
62
|
*
|
|
62
|
-
* When `stopWhen` fires while the model is still emitting tool calls,
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* than a half-finished tool call.
|
|
66
|
-
*
|
|
63
|
+
* When `stopWhen` fires while the model is still emitting tool calls, the
|
|
64
|
+
* loop makes one final model turn with `toolChoice: 'none'` (tools stay in
|
|
65
|
+
* the request to preserve the prompt cache) so the run ends with a
|
|
66
|
+
* natural-language answer rather than a half-finished tool call. This is
|
|
67
|
+
* the default; `allowFinalResponse` tunes it: `true`/omitted appends a
|
|
68
|
+
* default final-answer directive as a user message, a non-empty string
|
|
69
|
+
* replaces the wording, `''` appends nothing, `false` disables the final
|
|
70
|
+
* turn entirely.
|
|
67
71
|
*/
|
|
68
72
|
export function callModel(client, request, options) {
|
|
69
73
|
// Destructure state management options along with tools and stopWhen
|
|
70
|
-
const { tools, stopWhen, state, requireApproval, approveToolCalls, rejectToolCalls, context, sharedContextSchema, onTurnStart, onTurnEnd, allowFinalResponse, ...apiRequest } = request;
|
|
74
|
+
const { tools, stopWhen, state, requireApproval, approveToolCalls, rejectToolCalls, context, sharedContextSchema, onTurnStart, onTurnEnd, allowFinalResponse, strictFinalResponse, hooks, ...apiRequest } = request;
|
|
71
75
|
// Convert tools to API format - no cast needed now that convertToolsToAPIFormat accepts readonly
|
|
72
76
|
const apiTools = tools ? convertToolsToAPIFormat(tools) : undefined;
|
|
73
77
|
// Build the request with converted tools
|
|
@@ -123,6 +127,12 @@ export function callModel(client, request, options) {
|
|
|
123
127
|
...(allowFinalResponse !== undefined && {
|
|
124
128
|
allowFinalResponse,
|
|
125
129
|
}),
|
|
130
|
+
...(strictFinalResponse !== undefined && {
|
|
131
|
+
strictFinalResponse,
|
|
132
|
+
}),
|
|
133
|
+
...(hooks !== undefined && {
|
|
134
|
+
hooks: resolveHooks(hooks),
|
|
135
|
+
}),
|
|
126
136
|
});
|
|
127
137
|
}
|
|
128
138
|
//# sourceMappingURL=call-model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call-model.js","sourceRoot":"","sources":["../../src/inner-loop/call-model.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"call-model.js","sourceRoot":"","sources":["../../src/inner-loop/call-model.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAMlE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,MAAM,UAAU,SAAS,CAOvB,MAAsB,EACtB,OAEC,EACD,OAAwB;IAExB,qEAAqE;IACrE,MAAM,EACJ,KAAK,EACL,QAAQ,EACR,KAAK,EACL,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,OAAO,EACP,mBAAmB,EACnB,WAAW,EACX,SAAS,EACT,kBAAkB,EAClB,mBAAmB,EACnB,KAAK,EACL,GAAG,UAAU,EACd,GAAG,OAAO,CAAC;IAEZ,iGAAiG;IACjG,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAEpE,yCAAyC;IACzC,iFAAiF;IACjF,0GAA0G;IAC1G,MAAM,YAAY,GAA4B;QAC5C,GAAG,UAAU;KACd,CAAC;IAEF,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,YAAY,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC;IACnC,CAAC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C"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type * as models from '@openrouter/sdk/models';
|
|
2
2
|
import type { OpenResponsesResult } from '@openrouter/sdk/models';
|
|
3
|
+
import type { HooksManager } from './hooks-manager.js';
|
|
4
|
+
import type { InlineHookConfig } from './hooks-types.js';
|
|
3
5
|
import type { Item } from './item-types.js';
|
|
4
6
|
import type { ContextInput } from './tool-context.js';
|
|
5
7
|
import type { ParsedToolCall, StateAccessor, StopWhen, Tool, ToolContextMapWithShared, TurnContext } from './tool-types.js';
|
|
@@ -37,13 +39,22 @@ type BaseCallModelInput<TTools extends readonly Tool[] = readonly Tool[], TShare
|
|
|
37
39
|
/**
|
|
38
40
|
* When the loop exits because `stopWhen` was met and the last response
|
|
39
41
|
* still contained tool calls, execute those pending tool calls (so they
|
|
40
|
-
* have matching outputs) and then make one more model request with
|
|
41
|
-
*
|
|
42
|
+
* have matching outputs) and then make one more model request with
|
|
43
|
+
* `toolChoice: 'none'` so the model produces a final text response.
|
|
44
|
+
* Tools stay in the request — only calling is forbidden — so the
|
|
45
|
+
* prompt-cache prefix is preserved.
|
|
42
46
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* -
|
|
46
|
-
*
|
|
47
|
+
* **Default: on.** Omitting the option behaves like `true`.
|
|
48
|
+
*
|
|
49
|
+
* - `true` / omitted — re-prompt with the accumulated conversation and a
|
|
50
|
+
* default final-answer directive appended as a user message
|
|
51
|
+
* (`DEFAULT_FINAL_RESPONSE_DIRECTIVE`). Without the directive, models
|
|
52
|
+
* that emit tool-call syntax as text may leak an unparsed tool call
|
|
53
|
+
* into the final content.
|
|
54
|
+
* - non-empty string — append that string as the final user message
|
|
55
|
+
* instead of the default (e.g. `"Please summarize what you've learned"`).
|
|
56
|
+
* - `''` — no final user message; tool calls are still forbidden.
|
|
57
|
+
* - `false` — no final turn; the run ends on the halted tool-call turn.
|
|
47
58
|
*
|
|
48
59
|
* The full accumulated input array and the original `instructions` are
|
|
49
60
|
* sent. Manual (non-executable) tool calls in the halted turn are paired
|
|
@@ -52,6 +63,14 @@ type BaseCallModelInput<TTools extends readonly Tool[] = readonly Tool[], TShare
|
|
|
52
63
|
* (HITL pause, approval pause, interruption, or natural completion).
|
|
53
64
|
*/
|
|
54
65
|
allowFinalResponse?: boolean | string;
|
|
66
|
+
/**
|
|
67
|
+
* When true, throw if the final response has an empty `output` array even
|
|
68
|
+
* after completed tool rounds (legacy behavior). Default false: empty
|
|
69
|
+
* finals after tool work are retried once, then accepted with empty text.
|
|
70
|
+
*/
|
|
71
|
+
strictFinalResponse?: boolean;
|
|
72
|
+
/** Hook system for lifecycle events. Accepts inline config or a HooksManager instance. */
|
|
73
|
+
hooks?: InlineHookConfig | HooksManager;
|
|
55
74
|
};
|
|
56
75
|
/**
|
|
57
76
|
* Approval params when state is provided (allows approve/reject)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-params.d.ts","sourceRoot":"","sources":["../../src/lib/async-params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,wBAAwB,EACxB,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AA6B5C;;GAEG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,WAAW,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAErF;;GAEG;AACH,KAAK,kBAAkB,CACrB,MAAM,SAAS,SA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,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAC7D,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,GACrC,CAAC,uBAAuB,CAAC,MAAM,CAAC,GAAG,0BAA0B,CAAC,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,uBAAuB,CACjC,MAAM,SAAS,SAAS,IAAI,EAAE,GAAG,SAAS,IAAI,EAAE,EAChD,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAC7D,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;AAE1E;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG;IACvF,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,SAAS,SAAS,IAAI,EAAE,GAAG,SAAS,IAAI,EAAE,EAC1F,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,EAC7B,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,sBAAsB,CAAC,CA2DjC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAKzD"}
|
package/esm/lib/async-params.js
CHANGED
|
@@ -47,7 +47,9 @@ export async function resolveAsyncFunctions(input, context) {
|
|
|
47
47
|
'sharedContextSchema', // Client-side schema for shared context validation
|
|
48
48
|
'onTurnStart', // Client-side turn start callback
|
|
49
49
|
'onTurnEnd', // Client-side turn end callback
|
|
50
|
-
'allowFinalResponse', // Client-side:
|
|
50
|
+
'allowFinalResponse', // Client-side: tunes the default toolChoice:'none' final turn when stopWhen breaks the loop
|
|
51
|
+
'strictFinalResponse', // Client-side: restore throw on empty final after tool rounds
|
|
52
|
+
'hooks', // Client-side hook system
|
|
51
53
|
]);
|
|
52
54
|
// Iterate over all keys in the input
|
|
53
55
|
for (const [key, value] of Object.entries(input)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-params.js","sourceRoot":"","sources":["../../src/lib/async-params.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"async-params.js","sourceRoot":"","sources":["../../src/lib/async-params.ts"],"names":[],"mappings":"AAkBA;;;GAGG;AACH,SAAS,mBAAmB,CAC1B,KAAc;IAEd,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC,CAAC;AAED;;;GAGG;AACH,SAAS,oBAAoB,CAC3B,OAKC;IAED,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAExC,OAAO,GAAoC,CAAC;AAC9C,CAAC;AAqID;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,KAA6B,EAC7B,OAAoB;IAEpB,kCAAkC;IAClC,MAAM,eAAe,GAKjB,EAAE,CAAC;IAEP,+DAA+D;IAC/D,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;QAC/B,UAAU,EAAE,oCAAoC;QAChD,OAAO,EAAE,+BAA+B;QACxC,iBAAiB,EAAE,sCAAsC;QACzD,kBAAkB,EAAE,iCAAiC;QACrD,iBAAiB,EAAE,kCAAkC;QACrD,SAAS,EAAE,yDAAyD;QACpE,qBAAqB,EAAE,mDAAmD;QAC1E,aAAa,EAAE,kCAAkC;QACjD,WAAW,EAAE,gCAAgC;QAC7C,oBAAoB,EAAE,4FAA4F;QAClH,qBAAqB,EAAE,8DAA8D;QACrF,OAAO,EAAE,0BAA0B;KACpC,CAAC,CAAC;IAEH,qCAAqC;IACrC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAA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