@openrouter/sdk 1.5.55 → 1.5.57

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 (104) hide show
  1. package/esm/lib/config.d.ts +2 -2
  2. package/esm/lib/config.js +2 -2
  3. package/esm/models/additionaltoolsitem.d.ts +5 -4
  4. package/esm/models/additionaltoolsitem.js +3 -0
  5. package/esm/models/alignmentresponsesrejected.d.ts +4 -1
  6. package/esm/models/alignmentresponsesrejected.js +6 -0
  7. package/esm/models/byokproviderslug.d.ts +1 -0
  8. package/esm/models/byokproviderslug.js +1 -0
  9. package/esm/models/createworkspacerequest.d.ts +1 -0
  10. package/esm/models/createworkspacerequest.js +1 -0
  11. package/esm/models/decisionschoicequestion.d.ts +4 -4
  12. package/esm/models/decisionschoicequestion.js +1 -5
  13. package/esm/models/decisionsnoulquestion.d.ts +12 -12
  14. package/esm/models/decisionsnoulquestion.js +3 -7
  15. package/esm/models/decisionsscorequestion.d.ts +4 -4
  16. package/esm/models/decisionsscorequestion.js +1 -5
  17. package/esm/models/imagegenerationproviderpreferences.d.ts +6 -0
  18. package/esm/models/imagegenerationproviderpreferences.js +1 -0
  19. package/esm/models/imagegenerationrequest.d.ts +51 -4
  20. package/esm/models/imagegenerationrequest.js +32 -1
  21. package/esm/models/index.d.ts +6 -0
  22. package/esm/models/index.js +6 -0
  23. package/esm/models/mcpapprovalrequestitem.d.ts +7 -0
  24. package/esm/models/mcpapprovalrequestitem.js +19 -1
  25. package/esm/models/mcpcallitem.d.ts +17 -1
  26. package/esm/models/mcpcallitem.js +18 -0
  27. package/esm/models/mcpservertool.d.ts +78 -69
  28. package/esm/models/mcpservertool.js +135 -105
  29. package/esm/models/mcpservertoolopenrouter.d.ts +28 -0
  30. package/esm/models/mcpservertoolopenrouter.js +20 -0
  31. package/esm/models/mcpservertoolparameters.d.ts +152 -0
  32. package/esm/models/mcpservertoolparameters.js +134 -0
  33. package/esm/models/openairesponsestoolchoiceunion.d.ts +3 -2
  34. package/esm/models/openairesponsestoolchoiceunion.js +3 -0
  35. package/esm/models/operations/listbyokkeys.d.ts +1 -0
  36. package/esm/models/operations/listbyokkeys.js +1 -0
  37. package/esm/models/outputitemmcpapprovalrequest.d.ts +14 -0
  38. package/esm/models/outputitemmcpapprovalrequest.js +23 -0
  39. package/esm/models/outputitemmcpcall.d.ts +74 -0
  40. package/esm/models/outputitemmcpcall.js +94 -0
  41. package/esm/models/outputitemmcplisttools.d.ts +25 -0
  42. package/esm/models/outputitemmcplisttools.js +37 -0
  43. package/esm/models/outputitems.d.ts +3 -0
  44. package/esm/models/outputitems.js +2 -0
  45. package/esm/models/providername.d.ts +1 -0
  46. package/esm/models/providername.js +1 -0
  47. package/esm/models/provideroptions.d.ts +6 -0
  48. package/esm/models/provideroptions.js +1 -0
  49. package/esm/models/providerresponse.d.ts +1 -0
  50. package/esm/models/providerresponse.js +1 -0
  51. package/esm/models/responsesrequest.d.ts +9 -0
  52. package/esm/models/responsesrequest.js +3 -0
  53. package/esm/models/toolchoicemcp.d.ts +33 -0
  54. package/esm/models/toolchoicemcp.js +42 -0
  55. package/esm/models/toolsearchoutputitem.d.ts +5 -4
  56. package/esm/models/toolsearchoutputitem.js +3 -0
  57. package/esm/models/updateworkspacerequest.d.ts +1 -0
  58. package/esm/models/updateworkspacerequest.js +1 -0
  59. package/esm/models/videogenerationrequest.d.ts +6 -0
  60. package/esm/models/videogenerationrequest.js +1 -0
  61. package/esm/sdk/sdk.d.ts +0 -9
  62. package/esm/sdk/sdk.js +1 -7
  63. package/jsr.json +1 -1
  64. package/package.json +5 -5
  65. package/esm/funcs/call-model.d.ts +0 -67
  66. package/esm/funcs/call-model.js +0 -98
  67. package/esm/lib/anthropic-compat.d.ts +0 -51
  68. package/esm/lib/anthropic-compat.js +0 -222
  69. package/esm/lib/async-params.d.ts +0 -107
  70. package/esm/lib/async-params.js +0 -88
  71. package/esm/lib/chat-compat.d.ts +0 -47
  72. package/esm/lib/chat-compat.js +0 -111
  73. package/esm/lib/claude-constants.d.ts +0 -22
  74. package/esm/lib/claude-constants.js +0 -20
  75. package/esm/lib/claude-type-guards.d.ts +0 -10
  76. package/esm/lib/claude-type-guards.js +0 -70
  77. package/esm/lib/conversation-state.d.ts +0 -63
  78. package/esm/lib/conversation-state.js +0 -210
  79. package/esm/lib/model-result.d.ts +0 -373
  80. package/esm/lib/model-result.js +0 -1414
  81. package/esm/lib/next-turn-params.d.ts +0 -30
  82. package/esm/lib/next-turn-params.js +0 -135
  83. package/esm/lib/reusable-stream.d.ts +0 -39
  84. package/esm/lib/reusable-stream.js +0 -192
  85. package/esm/lib/stop-conditions.d.ts +0 -80
  86. package/esm/lib/stop-conditions.js +0 -104
  87. package/esm/lib/stream-transformers.d.ts +0 -118
  88. package/esm/lib/stream-transformers.js +0 -852
  89. package/esm/lib/stream-type-guards.d.ts +0 -49
  90. package/esm/lib/stream-type-guards.js +0 -85
  91. package/esm/lib/tool-context.d.ts +0 -68
  92. package/esm/lib/tool-context.js +0 -175
  93. package/esm/lib/tool-event-broadcaster.d.ts +0 -44
  94. package/esm/lib/tool-event-broadcaster.js +0 -146
  95. package/esm/lib/tool-executor.d.ts +0 -74
  96. package/esm/lib/tool-executor.js +0 -267
  97. package/esm/lib/tool-orchestrator.d.ts +0 -52
  98. package/esm/lib/tool-orchestrator.js +0 -180
  99. package/esm/lib/tool-types.d.ts +0 -573
  100. package/esm/lib/tool-types.js +0 -80
  101. package/esm/lib/tool.d.ts +0 -108
  102. package/esm/lib/tool.js +0 -74
  103. package/esm/lib/turn-context.d.ts +0 -52
  104. package/esm/lib/turn-context.js +0 -59
@@ -1,573 +0,0 @@
1
- import type { $ZodObject, $ZodShape, $ZodType, infer as zodInfer } from 'zod/v4/core';
2
- import type { FunctionCallItem } from '../models/functioncallitem.js';
3
- import type { FunctionCallOutputItem } from '../models/functioncalloutputitem.js';
4
- import type { InputsUnion } from '../models/inputsunion.js';
5
- import type { OpenResponsesResult, Usage } from '../models/openresponsesresult.js';
6
- import type { ResponsesRequest } from '../models/responsesrequest.js';
7
- import type { StreamEvents } from '../models/streamevents.js';
8
- import type { ModelResult } from './model-result.js';
9
- /**
10
- * Tool type enum for enhanced tools
11
- */
12
- export declare enum ToolType {
13
- Function = "function"
14
- }
15
- /**
16
- * Turn context passed to tool execute functions and async parameter resolution
17
- * Contains information about the current conversation state
18
- */
19
- export interface TurnContext {
20
- /** The specific tool call being executed (only available during tool execution) */
21
- toolCall?: FunctionCallItem;
22
- /** Number of tool execution turns so far (1-indexed: first turn = 1, 0 = initial request) */
23
- numberOfTurns: number;
24
- /** The full request being sent to the API (only available during tool execution) */
25
- turnRequest?: ResponsesRequest;
26
- }
27
- /**
28
- * Extract context schema type from a tool definition
29
- * Returns the inferred type of the tool's contextSchema, or empty object if none
30
- */
31
- export type InferToolContext<T> = T extends {
32
- function: {
33
- contextSchema: infer S;
34
- };
35
- } ? S extends $ZodType ? zodInfer<S> : Record<string, never> : Record<string, never>;
36
- /**
37
- * Extract tool name from a tool definition
38
- */
39
- type InferToolName<T> = T extends {
40
- function: {
41
- name: infer N extends string;
42
- };
43
- } ? N : string;
44
- /**
45
- * Flat execute context passed as the second argument to tool execute functions.
46
- * Merges TurnContext fields with a `local` getter (own tool context) and `setContext()`.
47
- *
48
- * @template TName - The tool's literal name string
49
- * @template TContext - The shape of the tool's contextSchema
50
- * @template TShared - The shape of the sharedContextSchema
51
- */
52
- export type ToolExecuteContext<TName extends string = string, TContext extends Record<string, unknown> = Record<string, unknown>, TShared extends Record<string, unknown> = Record<string, unknown>> = TurnContext & {
53
- /** The tool's name (type-level only, for generic inference) */
54
- readonly _toolName?: TName;
55
- /** This tool's own context (reads from the store, frozen snapshot) */
56
- local: Readonly<TContext>;
57
- /** Mutate this tool's context in the shared store (persists across turns) */
58
- setContext(partial: Partial<TContext>): void;
59
- /** Shared context visible to all tools */
60
- shared: Readonly<TShared>;
61
- /** Mutate the shared context in the store (persists across turns) */
62
- setSharedContext(partial: Partial<TShared>): void;
63
- };
64
- /**
65
- * Context map keyed by tool name for callModel's `context` option.
66
- * Each key is a tool's name, each value is that tool's inferred context type.
67
- */
68
- export type ToolContextMap<T extends readonly Tool[]> = {
69
- [K in T[number] as InferToolName<K>]: InferToolContext<K>;
70
- };
71
- /**
72
- * Context map with an optional `shared` key for shared context.
73
- * When TShared is provided (non-empty), a `shared` key is added to the map.
74
- */
75
- export type ToolContextMapWithShared<T extends readonly Tool[], TShared extends Record<string, unknown> = Record<string, never>> = ToolContextMap<T> & (TShared extends Record<string, never> ? {} : {
76
- shared: TShared;
77
- });
78
- /**
79
- * Reserved key in the context store for shared context data.
80
- * The tool name 'shared' is forbidden — it's reserved for this purpose.
81
- */
82
- export declare const SHARED_CONTEXT_KEY: "shared";
83
- /**
84
- * Context passed to nextTurnParams functions
85
- * Contains current request state for parameter computation
86
- * Allows modification of key request parameters between turns
87
- */
88
- export type NextTurnParamsContext = {
89
- /** Current input (messages) */
90
- input: InputsUnion;
91
- /** Current model selection */
92
- model: string;
93
- /** Current models array */
94
- models: string[];
95
- /** Current temperature */
96
- temperature: number | null;
97
- /** Current maxOutputTokens */
98
- maxOutputTokens: number | null;
99
- /** Current topP */
100
- topP: number | null;
101
- /** Current topK */
102
- topK?: number | undefined;
103
- /** Current instructions */
104
- instructions: string | null;
105
- };
106
- /**
107
- * Functions to compute next turn parameters
108
- * Each function receives the tool's input params and current request context
109
- */
110
- export type NextTurnParamsFunctions<TInput> = {
111
- [K in keyof NextTurnParamsContext]?: (params: TInput, context: NextTurnParamsContext) => NextTurnParamsContext[K] | Promise<NextTurnParamsContext[K]>;
112
- };
113
- /**
114
- * Tool-level approval check function type
115
- * Receives the tool's input params and turn context
116
- * Returns true if approval is required, false otherwise
117
- */
118
- export type ToolApprovalCheck<TInput> = (params: TInput, context: TurnContext) => boolean | Promise<boolean>;
119
- /**
120
- * Base tool function interface with inputSchema
121
- * @template TInput - Zod schema for tool input
122
- */
123
- export interface BaseToolFunction<TInput extends $ZodObject<$ZodShape>> {
124
- name: string;
125
- description?: string;
126
- inputSchema: TInput;
127
- /** Zod schema declaring the context data this tool needs */
128
- contextSchema?: $ZodObject<$ZodShape>;
129
- nextTurnParams?: NextTurnParamsFunctions<zodInfer<TInput>>;
130
- /**
131
- * Whether this tool requires human approval before execution
132
- * Can be a boolean or an async function that receives the tool's input params and context
133
- */
134
- requireApproval?: boolean | ToolApprovalCheck<zodInfer<TInput>>;
135
- }
136
- /**
137
- * Regular tool with synchronous or asynchronous execute function and optional outputSchema
138
- * @template TContext - Shape of the tool's context (inferred from contextSchema)
139
- * @template TName - The tool's literal name string
140
- */
141
- export interface ToolFunctionWithExecute<TInput extends $ZodObject<$ZodShape>, TOutput extends $ZodType = $ZodType<unknown>, TContext extends Record<string, unknown> = Record<string, unknown>, TName extends string = string> extends BaseToolFunction<TInput> {
142
- outputSchema?: TOutput;
143
- execute: (params: zodInfer<TInput>, context?: ToolExecuteContext<TName, TContext>) => Promise<zodInfer<TOutput>> | zodInfer<TOutput>;
144
- }
145
- /**
146
- * Generator-based tool with async generator execute function
147
- * Emits preliminary events (validated by eventSchema) during execution
148
- * and a final output (validated by outputSchema) as the last emission
149
- *
150
- * The generator can yield both events and the final output.
151
- * All yields are validated against eventSchema (which should be a union of event and output types),
152
- * and the last yield is additionally validated against outputSchema.
153
- *
154
- * @example
155
- * ```typescript
156
- * {
157
- * eventSchema: z.object({ status: z.string() }), // For progress events
158
- * outputSchema: z.object({ result: z.number() }), // For final output
159
- * execute: async function* (params) {
160
- * yield { status: "processing..." }; // Event
161
- * yield { status: "almost done..." }; // Event
162
- * yield { result: 42 }; // Final output (must be last)
163
- * }
164
- * }
165
- * ```
166
- */
167
- export interface ToolFunctionWithGenerator<TInput extends $ZodObject<$ZodShape>, TEvent extends $ZodType = $ZodType<unknown>, TOutput extends $ZodType = $ZodType<unknown>, TContext extends Record<string, unknown> = Record<string, unknown>, TName extends string = string> extends BaseToolFunction<TInput> {
168
- eventSchema: TEvent;
169
- outputSchema: TOutput;
170
- execute: (params: zodInfer<TInput>, context?: ToolExecuteContext<TName, TContext>) => AsyncGenerator<zodInfer<TEvent> | zodInfer<TOutput>, zodInfer<TOutput> | void>;
171
- }
172
- /**
173
- * Manual tool without execute function - requires manual handling by developer
174
- */
175
- export interface ManualToolFunction<TInput extends $ZodObject<$ZodShape>, TOutput extends $ZodType = $ZodType<unknown>> extends BaseToolFunction<TInput> {
176
- outputSchema?: TOutput;
177
- }
178
- /**
179
- * Tool with execute function (regular or generator)
180
- */
181
- export type ToolWithExecute<TInput extends $ZodObject<$ZodShape> = $ZodObject<$ZodShape>, TOutput extends $ZodType = $ZodType<unknown>, TContext extends Record<string, unknown> = Record<string, unknown>> = {
182
- type: ToolType.Function;
183
- function: ToolFunctionWithExecute<TInput, TOutput, TContext>;
184
- };
185
- /**
186
- * Tool with generator execute function
187
- */
188
- export type ToolWithGenerator<TInput extends $ZodObject<$ZodShape> = $ZodObject<$ZodShape>, TEvent extends $ZodType = $ZodType<unknown>, TOutput extends $ZodType = $ZodType<unknown>, TContext extends Record<string, unknown> = Record<string, unknown>> = {
189
- type: ToolType.Function;
190
- function: ToolFunctionWithGenerator<TInput, TEvent, TOutput, TContext>;
191
- };
192
- /**
193
- * Tool without execute function (manual handling)
194
- */
195
- export type ManualTool<TInput extends $ZodObject<$ZodShape> = $ZodObject<$ZodShape>, TOutput extends $ZodType = $ZodType<unknown>> = {
196
- type: ToolType.Function;
197
- function: ManualToolFunction<TInput, TOutput>;
198
- };
199
- /**
200
- * Union type of all enhanced tool types
201
- */
202
- export type Tool = ToolWithExecute<$ZodObject<$ZodShape>, $ZodType<unknown>> | ToolWithGenerator<$ZodObject<$ZodShape>, $ZodType<unknown>, $ZodType<unknown>> | ManualTool<$ZodObject<$ZodShape>, $ZodType<unknown>>;
203
- /**
204
- * Extracts the input type from a tool definition
205
- */
206
- export type InferToolInput<T> = T extends {
207
- function: {
208
- inputSchema: infer S;
209
- };
210
- } ? S extends $ZodType ? zodInfer<S> : unknown : unknown;
211
- /**
212
- * Extracts the output type from a tool definition
213
- */
214
- export type InferToolOutput<T> = T extends {
215
- function: {
216
- outputSchema: infer S;
217
- };
218
- } ? S extends $ZodType ? zodInfer<S> : unknown : unknown;
219
- /**
220
- * A tool call with typed arguments based on the tool's inputSchema
221
- */
222
- export type TypedToolCall<T extends Tool> = {
223
- id: string;
224
- name: T extends {
225
- function: {
226
- name: infer N;
227
- };
228
- } ? N : string;
229
- arguments: InferToolInput<T>;
230
- };
231
- /**
232
- * Union of typed tool calls for a tuple of tools
233
- */
234
- export type TypedToolCallUnion<T extends readonly Tool[]> = {
235
- [K in keyof T]: T[K] extends Tool ? TypedToolCall<T[K]> : never;
236
- }[number];
237
- /**
238
- * Union of typed tool execution results for a tuple of tools
239
- */
240
- export type ToolExecutionResultUnion<T extends readonly Tool[]> = {
241
- [K in keyof T]: T[K] extends Tool ? ToolExecutionResult<T[K]> : never;
242
- }[number];
243
- /**
244
- * Union of output types for all tools in a tuple
245
- * Used for typing tool result events
246
- */
247
- export type InferToolOutputsUnion<T extends readonly Tool[]> = {
248
- [K in keyof T]: T[K] extends Tool ? InferToolOutput<T[K]> : never;
249
- }[number];
250
- /**
251
- * Extracts the event type from a generator tool definition
252
- * Returns `never` for non-generator tools
253
- */
254
- export type InferToolEvent<T> = T extends {
255
- function: {
256
- eventSchema: infer S;
257
- };
258
- } ? S extends $ZodType ? zodInfer<S> : never : never;
259
- /**
260
- * Union of event types for all generator tools in a tuple
261
- * Filters out non-generator tools (which return `never`)
262
- */
263
- export type InferToolEventsUnion<T extends readonly Tool[]> = {
264
- [K in keyof T]: T[K] extends Tool ? InferToolEvent<T[K]> : never;
265
- }[number];
266
- /**
267
- * Type guard to check if a tool has an execute function
268
- */
269
- export declare function hasExecuteFunction(tool: Tool): tool is ToolWithExecute | ToolWithGenerator;
270
- /**
271
- * Type guard to check if a tool uses a generator (has eventSchema)
272
- */
273
- export declare function isGeneratorTool(tool: Tool): tool is ToolWithGenerator;
274
- /**
275
- * Type guard to check if a tool is a regular execution tool (not generator)
276
- */
277
- export declare function isRegularExecuteTool(tool: Tool): tool is ToolWithExecute;
278
- /**
279
- * Type guard to check if a tool is a manual tool (no execute function)
280
- */
281
- export declare function isManualTool(tool: Tool): tool is ManualTool;
282
- /**
283
- * Parsed tool call from API response
284
- * @template T - The tool type to infer argument types from
285
- */
286
- export interface ParsedToolCall<T extends Tool> {
287
- id: string;
288
- name: T extends {
289
- function: {
290
- name: infer N;
291
- };
292
- } ? N : string;
293
- arguments: InferToolInput<T>;
294
- }
295
- /**
296
- * Result of tool execution
297
- * @template T - The tool type to infer result types from
298
- */
299
- export interface ToolExecutionResult<T extends Tool> {
300
- toolCallId: string;
301
- toolName: string;
302
- result: T extends ToolWithExecute<$ZodObject<$ZodShape>, infer O> | ToolWithGenerator<$ZodObject<$ZodShape>, $ZodType<unknown>, infer O> ? zodInfer<O> : unknown;
303
- preliminaryResults?: T extends ToolWithGenerator<$ZodObject<$ZodShape>, infer E> ? zodInfer<E>[] : undefined;
304
- error?: Error;
305
- }
306
- /**
307
- * Warning from step execution
308
- */
309
- export interface Warning {
310
- type: string;
311
- message: string;
312
- }
313
- /**
314
- * Result of a single step in the tool execution loop
315
- * Compatible with Vercel AI SDK pattern
316
- */
317
- export interface StepResult<TTools extends readonly Tool[] = readonly Tool[]> {
318
- readonly stepType: 'initial' | 'continue';
319
- readonly text: string;
320
- readonly toolCalls: TypedToolCallUnion<TTools>[];
321
- readonly toolResults: ToolExecutionResultUnion<TTools>[];
322
- readonly response: OpenResponsesResult;
323
- readonly usage?: Usage | null | undefined;
324
- readonly finishReason?: string | undefined;
325
- readonly warnings?: Warning[] | undefined;
326
- readonly experimental_providerMetadata?: Record<string, unknown> | undefined;
327
- }
328
- /**
329
- * A condition function that determines whether to stop tool execution
330
- * Returns true to STOP execution, false to CONTINUE
331
- * (Matches Vercel AI SDK semantics)
332
- */
333
- export type StopCondition<TTools extends readonly Tool[] = readonly Tool[]> = (options: {
334
- readonly steps: ReadonlyArray<StepResult<TTools>>;
335
- }) => boolean | Promise<boolean>;
336
- /**
337
- * Stop condition configuration
338
- * Can be a single condition or array of conditions
339
- */
340
- export type StopWhen<TTools extends readonly Tool[] = readonly Tool[]> = StopCondition<TTools> | ReadonlyArray<StopCondition<TTools>>;
341
- /**
342
- * Result of executeTools operation
343
- */
344
- export interface ExecuteToolsResult<TTools extends readonly Tool[]> {
345
- finalResponse: ModelResult<TTools>;
346
- allResponses: ModelResult<TTools>[];
347
- toolResults: Map<string, {
348
- result: unknown;
349
- preliminaryResults?: unknown[];
350
- }>;
351
- }
352
- /**
353
- * Standard tool format for OpenRouter API (JSON Schema based)
354
- * Matches ResponsesRequestToolFunction structure
355
- */
356
- export interface APITool {
357
- type: 'function';
358
- name: string;
359
- description?: string | null;
360
- strict?: boolean | null;
361
- parameters: {
362
- [k: string]: unknown;
363
- } | null;
364
- }
365
- /**
366
- * Tool preliminary result event emitted during generator tool execution
367
- * @template TEvent - The event type from the tool's eventSchema
368
- */
369
- export type ToolPreliminaryResultEvent<TEvent = unknown> = {
370
- type: 'tool.preliminary_result';
371
- toolCallId: string;
372
- result: TEvent;
373
- timestamp: number;
374
- };
375
- /**
376
- * Tool result event emitted when a tool execution completes
377
- * Contains the final result and any preliminary results that were emitted
378
- * @template TResult - The result type from the tool's outputSchema
379
- * @template TPreliminaryResults - The event type from generator tools' eventSchema
380
- */
381
- export type ToolResultEvent<TResult = unknown, TPreliminaryResults = unknown> = {
382
- type: 'tool.result';
383
- toolCallId: string;
384
- result: TResult;
385
- timestamp: number;
386
- preliminaryResults?: TPreliminaryResults[];
387
- };
388
- /**
389
- * Tool call output event carrying the fully-formed FunctionCallOutputItem.
390
- * Broadcast by executeToolRound so passive consumers (getItemsStream) can yield
391
- * tool results in real-time without owning tool execution.
392
- */
393
- export type ToolCallOutputEvent = {
394
- type: 'tool.call_output';
395
- output: FunctionCallOutputItem;
396
- timestamp: number;
397
- };
398
- /**
399
- * Turn start event emitted at the beginning of each API turn
400
- * Turn 0 is the initial request, subsequent turns follow tool execution
401
- */
402
- export type TurnStartEvent = {
403
- type: 'turn.start';
404
- turnNumber: number;
405
- timestamp: number;
406
- };
407
- /**
408
- * Turn end event emitted at the end of each API turn
409
- */
410
- export type TurnEndEvent = {
411
- type: 'turn.end';
412
- turnNumber: number;
413
- timestamp: number;
414
- };
415
- /**
416
- * Enhanced stream event types for getFullResponsesStream
417
- * Extends StreamEvents with tool preliminary results, tool results,
418
- * and turn delimiter events for multi-turn streaming
419
- * @template TEvent - The event type from generator tools
420
- * @template TResult - The result type from tool execution
421
- */
422
- export type ResponseStreamEvent<TEvent = unknown, TResult = unknown> = StreamEvents | ToolPreliminaryResultEvent<TEvent> | ToolResultEvent<TResult, TEvent> | ToolCallOutputEvent | TurnStartEvent | TurnEndEvent;
423
- /**
424
- * Type guard to check if an event is a tool preliminary result event
425
- */
426
- export declare function isToolPreliminaryResultEvent<TEvent = unknown>(event: ResponseStreamEvent<TEvent>): event is ToolPreliminaryResultEvent<TEvent>;
427
- /**
428
- * Type guard to check if an event is a tool result event
429
- */
430
- export declare function isToolResultEvent<TResult = unknown, TPreliminaryResults = unknown>(event: ResponseStreamEvent<TPreliminaryResults, TResult>): event is ToolResultEvent<TResult, TPreliminaryResults>;
431
- /**
432
- * Type guard to check if an event is a tool call output event
433
- */
434
- export declare function isToolCallOutputEvent(event: ResponseStreamEvent): event is ToolCallOutputEvent;
435
- /**
436
- * Type guard to check if an event is a turn start event
437
- */
438
- export declare function isTurnStartEvent(event: ResponseStreamEvent): event is TurnStartEvent;
439
- /**
440
- * Type guard to check if an event is a turn end event
441
- */
442
- export declare function isTurnEndEvent(event: ResponseStreamEvent): event is TurnEndEvent;
443
- /**
444
- * Tool stream event types for getToolStream
445
- * Includes both argument deltas and preliminary results
446
- * @template TEvent - The event type from generator tools
447
- */
448
- export type ToolStreamEvent<TEvent = unknown> = {
449
- type: 'delta';
450
- content: string;
451
- } | {
452
- type: 'preliminary_result';
453
- toolCallId: string;
454
- result: TEvent;
455
- };
456
- /**
457
- * Chat stream event types for getFullChatStream
458
- * Includes content deltas, completion events, and tool preliminary results
459
- * @template TEvent - The event type from generator tools
460
- */
461
- export type ChatStreamEvent<TEvent = unknown> = {
462
- type: 'content.delta';
463
- delta: string;
464
- } | {
465
- type: 'message.complete';
466
- response: OpenResponsesResult;
467
- } | {
468
- type: 'tool.preliminary_result';
469
- toolCallId: string;
470
- result: TEvent;
471
- } | {
472
- type: string;
473
- event: StreamEvents;
474
- };
475
- /**
476
- * Result of a tool execution that hasn't been sent to the model yet
477
- * Used for interrupted or awaiting approval states
478
- * @template TTools - The tools array type for proper type inference
479
- */
480
- export interface UnsentToolResult<TTools extends readonly Tool[] = readonly Tool[]> {
481
- /** The ID of the tool call this result is for */
482
- callId: string;
483
- /** The name of the tool that was executed */
484
- name: TTools[number]['function']['name'];
485
- /** The output of the tool execution */
486
- output: unknown;
487
- /** Error message if the tool call was rejected or failed */
488
- error?: string;
489
- }
490
- /**
491
- * Partial response captured during interruption
492
- * @template TTools - The tools array type for proper type inference
493
- */
494
- export interface PartialResponse<TTools extends readonly Tool[] = readonly Tool[]> {
495
- /** Partial text response accumulated before interruption */
496
- text?: string;
497
- /** Tool calls that were in progress when interrupted */
498
- toolCalls?: Array<ParsedToolCall<TTools[number]>>;
499
- }
500
- /**
501
- * Status of a conversation state
502
- */
503
- export type ConversationStatus = 'complete' | 'interrupted' | 'awaiting_approval' | 'in_progress';
504
- /**
505
- * State for multi-turn conversations with persistence and approval gates
506
- * @template TTools - The tools array type for proper type inference
507
- */
508
- export interface ConversationState<TTools extends readonly Tool[] = readonly Tool[]> {
509
- /** Unique identifier for this conversation */
510
- id: string;
511
- /** Full message history */
512
- messages: InputsUnion;
513
- /** Previous response ID for chaining (OpenRouter server-side optimization) */
514
- previousResponseId?: string;
515
- /** Tool calls awaiting human approval */
516
- pendingToolCalls?: Array<ParsedToolCall<TTools[number]>>;
517
- /** Tool results executed but not yet sent to the model */
518
- unsentToolResults?: Array<UnsentToolResult<TTools>>;
519
- /** Partial response data captured during interruption */
520
- partialResponse?: PartialResponse<TTools>;
521
- /** Signal from a new request to interrupt this conversation */
522
- interruptedBy?: string;
523
- /** Current status of the conversation */
524
- status: ConversationStatus;
525
- /** Creation timestamp (Unix ms) */
526
- createdAt: number;
527
- /** Last update timestamp (Unix ms) */
528
- updatedAt: number;
529
- }
530
- /**
531
- * State accessor for loading and saving conversation state
532
- * Enables any storage backend (memory, Redis, database, etc.)
533
- * @template TTools - The tools array type for proper type inference
534
- */
535
- export interface StateAccessor<TTools extends readonly Tool[] = readonly Tool[]> {
536
- /** Load the current conversation state, or null if none exists */
537
- load: () => Promise<ConversationState<TTools> | null>;
538
- /** Save the conversation state */
539
- save: (state: ConversationState<TTools>) => Promise<void>;
540
- }
541
- /**
542
- * Check if a single tool has approval configured (non-false, non-undefined)
543
- * Returns true if the tool definitely requires approval,
544
- * false if it definitely doesn't, or boolean if it's uncertain
545
- */
546
- export type ToolHasApproval<T extends Tool> = T extends {
547
- function: {
548
- requireApproval: true | ToolApprovalCheck<unknown>;
549
- };
550
- } ? true : T extends {
551
- function: {
552
- requireApproval: false;
553
- };
554
- } ? false : T extends {
555
- function: {
556
- requireApproval: undefined;
557
- };
558
- } ? false : boolean;
559
- /**
560
- * Check if ANY tool in an array has approval configured
561
- * Returns true if at least one tool might require approval
562
- */
563
- export type HasApprovalTools<TTools extends readonly Tool[]> = TTools extends readonly [infer First extends Tool, ...infer Rest extends Tool[]] ? ToolHasApproval<First> extends true ? true : HasApprovalTools<Rest> : false;
564
- /**
565
- * Type guard to check if a tool has approval configured at runtime
566
- */
567
- export declare function toolHasApprovalConfigured(tool: Tool): boolean;
568
- /**
569
- * Type guard to check if any tools in array have approval configured at runtime
570
- */
571
- export declare function hasApprovalRequiredTools(tools: readonly Tool[]): boolean;
572
- export {};
573
- //# sourceMappingURL=tool-types.d.ts.map
@@ -1,80 +0,0 @@
1
- /**
2
- * Tool type enum for enhanced tools
3
- */
4
- export var ToolType;
5
- (function (ToolType) {
6
- ToolType["Function"] = "function";
7
- })(ToolType || (ToolType = {}));
8
- /**
9
- * Reserved key in the context store for shared context data.
10
- * The tool name 'shared' is forbidden — it's reserved for this purpose.
11
- */
12
- export const SHARED_CONTEXT_KEY = 'shared';
13
- /**
14
- * Type guard to check if a tool has an execute function
15
- */
16
- export function hasExecuteFunction(tool) {
17
- return 'execute' in tool.function && typeof tool.function.execute === 'function';
18
- }
19
- /**
20
- * Type guard to check if a tool uses a generator (has eventSchema)
21
- */
22
- export function isGeneratorTool(tool) {
23
- return 'eventSchema' in tool.function;
24
- }
25
- /**
26
- * Type guard to check if a tool is a regular execution tool (not generator)
27
- */
28
- export function isRegularExecuteTool(tool) {
29
- return hasExecuteFunction(tool) && !isGeneratorTool(tool);
30
- }
31
- /**
32
- * Type guard to check if a tool is a manual tool (no execute function)
33
- */
34
- export function isManualTool(tool) {
35
- return !('execute' in tool.function);
36
- }
37
- /**
38
- * Type guard to check if an event is a tool preliminary result event
39
- */
40
- export function isToolPreliminaryResultEvent(event) {
41
- return event.type === 'tool.preliminary_result';
42
- }
43
- /**
44
- * Type guard to check if an event is a tool result event
45
- */
46
- export function isToolResultEvent(event) {
47
- return event.type === 'tool.result';
48
- }
49
- /**
50
- * Type guard to check if an event is a tool call output event
51
- */
52
- export function isToolCallOutputEvent(event) {
53
- return event.type === 'tool.call_output';
54
- }
55
- /**
56
- * Type guard to check if an event is a turn start event
57
- */
58
- export function isTurnStartEvent(event) {
59
- return event.type === 'turn.start';
60
- }
61
- /**
62
- * Type guard to check if an event is a turn end event
63
- */
64
- export function isTurnEndEvent(event) {
65
- return event.type === 'turn.end';
66
- }
67
- /**
68
- * Type guard to check if a tool has approval configured at runtime
69
- */
70
- export function toolHasApprovalConfigured(tool) {
71
- const requireApproval = tool.function.requireApproval;
72
- return requireApproval === true || typeof requireApproval === 'function';
73
- }
74
- /**
75
- * Type guard to check if any tools in array have approval configured at runtime
76
- */
77
- export function hasApprovalRequiredTools(tools) {
78
- return tools.some(toolHasApprovalConfigured);
79
- }
80
- //# sourceMappingURL=tool-types.js.map