@openrouter/agent 0.3.2 → 0.4.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/esm/index.d.ts +7 -5
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +4 -2
- package/esm/index.js.map +1 -1
- package/esm/lib/conversation-state.d.ts.map +1 -1
- package/esm/lib/conversation-state.js +16 -4
- package/esm/lib/conversation-state.js.map +1 -1
- package/esm/lib/model-result.d.ts +19 -1
- package/esm/lib/model-result.d.ts.map +1 -1
- package/esm/lib/model-result.js +186 -16
- package/esm/lib/model-result.js.map +1 -1
- package/esm/lib/next-turn-params.d.ts.map +1 -1
- package/esm/lib/next-turn-params.js +3 -1
- package/esm/lib/next-turn-params.js.map +1 -1
- package/esm/lib/stream-transformers.d.ts +84 -5
- package/esm/lib/stream-transformers.d.ts.map +1 -1
- package/esm/lib/stream-transformers.js +8 -15
- package/esm/lib/stream-transformers.js.map +1 -1
- package/esm/lib/stream-type-guards.d.ts +29 -0
- package/esm/lib/stream-type-guards.d.ts.map +1 -1
- package/esm/lib/stream-type-guards.js +37 -0
- package/esm/lib/stream-type-guards.js.map +1 -1
- package/esm/lib/tool-executor.d.ts +10 -6
- package/esm/lib/tool-executor.d.ts.map +1 -1
- package/esm/lib/tool-executor.js +21 -12
- package/esm/lib/tool-executor.js.map +1 -1
- package/esm/lib/tool-types.d.ts +120 -4
- package/esm/lib/tool-types.d.ts.map +1 -1
- package/esm/lib/tool-types.js +34 -0
- package/esm/lib/tool-types.js.map +1 -1
- package/esm/lib/tool.d.ts +24 -1
- package/esm/lib/tool.d.ts.map +1 -1
- package/esm/lib/tool.js +28 -0
- package/esm/lib/tool.js.map +1 -1
- package/esm/openrouter.d.ts +10 -4
- package/esm/openrouter.d.ts.map +1 -1
- package/esm/openrouter.js +41 -2
- package/esm/openrouter.js.map +1 -1
- package/package.json +2 -2
package/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
export { SDKHooks } from '@openrouter/sdk/hooks/hooks';
|
|
2
|
+
export type { AfterErrorContext, AfterErrorHook, AfterSuccessContext, AfterSuccessHook, BeforeCreateRequestContext, BeforeCreateRequestHook, BeforeRequestContext, BeforeRequestHook, HookContext, SDKInitHook, } from '@openrouter/sdk/hooks/types';
|
|
1
3
|
export type { RequestOptions } from '@openrouter/sdk/lib/sdks';
|
|
2
|
-
export type { BaseInputsUnion, ChatAssistantMessage, ChatMessages, EasyInputMessage, EasyInputMessageContentInputImage, EasyInputMessageContentUnion1, EasyInputMessageRoleUnion, ErrorEvent, FunctionCallItem, FunctionCallOutputItem, InputAudio, InputFile, InputImage, InputMessageItem, InputsUnion, InputText, InputVideo, OpenAIResponsesToolChoiceUnion, OpenResponsesResult, OutputFileSearchCallItem, OutputFunctionCallItem, OutputImageGenerationCallItem, OutputInputImage, OutputMessage, OutputReasoningItem, OutputWebSearchCallItem, ResponseOutputText, ResponsesRequest, StreamEvents, Usage, } from '@openrouter/sdk/models';
|
|
4
|
+
export type { BaseInputsUnion, ChatAssistantMessage, ChatMessages, EasyInputMessage, EasyInputMessageContentInputImage, EasyInputMessageContentUnion1, EasyInputMessageRoleUnion, ErrorEvent, FunctionCallItem, FunctionCallOutputItem, InputAudio, InputFile, InputImage, InputMessageItem, InputsUnion, InputText, InputVideo, OpenAIResponsesToolChoiceUnion, OpenResponsesResult, OutputFileSearchCallItem, OutputFunctionCallItem, OutputImageGenerationCallItem, OutputInputImage, OutputItems, OutputMessage, OutputReasoningItem, OutputWebSearchCallItem, ResponseOutputText, ResponsesRequest, ResponsesRequestToolUnion, StreamEvents, Usage, } from '@openrouter/sdk/models';
|
|
3
5
|
export type { AssistantMessageItem, CallFileSearchItem, CallFunctionToolItem, CallImageGenerationItem, CallWebSearchItem, DeveloperMessageItem, ErrorItem, FunctionProgressItem, FunctionResultItem, Item, NewUserMessageItem, ReasoningItem, SystemMessageItem, UserMessageItem, } from './lib/item-types.js';
|
|
4
6
|
export { callModel } from './inner-loop/call-model.js';
|
|
5
7
|
export { fromClaudeMessages, toClaudeMessage } from './lib/anthropic-compat.js';
|
|
@@ -15,13 +17,13 @@ export { applyNextTurnParamsToRequest, buildNextTurnParamsContext, executeNextTu
|
|
|
15
17
|
export { finishReasonIs, hasToolCall, isStopConditionMet, maxCost, maxTokensUsed, stepCountIs, } from './lib/stop-conditions.js';
|
|
16
18
|
export type { StreamableOutputItem } from './lib/stream-transformers.js';
|
|
17
19
|
export { extractUnsupportedContent, getUnsupportedContentSummary, hasUnsupportedContent, } from './lib/stream-transformers.js';
|
|
18
|
-
export { tool } from './lib/tool.js';
|
|
20
|
+
export { serverTool, tool } from './lib/tool.js';
|
|
19
21
|
export type { ContextInput } from './lib/tool-context.js';
|
|
20
22
|
export { buildToolExecuteContext, ToolContextStore } from './lib/tool-context.js';
|
|
21
23
|
export { ToolEventBroadcaster } from './lib/tool-event-broadcaster.js';
|
|
22
|
-
export type { ChatStreamEvent, ConversationState, ConversationStatus, HasApprovalTools, InferToolEvent, InferToolEventsUnion, InferToolInput, InferToolOutput, InferToolOutputsUnion, ManualTool, NextTurnParamsContext, NextTurnParamsFunctions, ParsedToolCall, PartialResponse, ResponseStreamEvent, ResponseStreamEvent as EnhancedResponseStreamEvent, StateAccessor, StepResult, StopCondition, StopWhen, ToModelOutputFunction, ToModelOutputResult, Tool, ToolApprovalCheck, ToolCallOutputEvent, ToolExecutionResult, ToolExecutionResultUnion, ToolHasApproval, ToolOutputContentItem, ToolPreliminaryResultEvent, ToolResultEvent, ToolStreamEvent, ToolWithExecute, ToolWithGenerator, TurnContext, TurnEndEvent, TurnStartEvent, TypedToolCall, TypedToolCallUnion, UnsentToolResult, Warning, } from './lib/tool-types.js';
|
|
23
|
-
export { hasApprovalRequiredTools, hasExecuteFunction, isGeneratorTool, isRegularExecuteTool, isToolCallOutputEvent, isToolPreliminaryResultEvent, isToolResultEvent, isTurnEndEvent, isTurnStartEvent, ToolType, toolHasApprovalConfigured, } from './lib/tool-types.js';
|
|
24
|
+
export type { ChatStreamEvent, ClientTool, ConversationState, ConversationStatus, HasApprovalTools, 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, isClientTool, isGeneratorTool, isRegularExecuteTool, isServerTool, isToolCallOutputEvent, isToolPreliminaryResultEvent, isToolResultEvent, isTurnEndEvent, isTurnStartEvent, ToolType, toolHasApprovalConfigured, } from './lib/tool-types.js';
|
|
24
26
|
export { buildTurnContext, normalizeInputToArray } from './lib/turn-context.js';
|
|
25
|
-
export type { SDKOptions } from './openrouter.js';
|
|
27
|
+
export type { Hook, OpenRouterOptions, SDKOptions } from './openrouter.js';
|
|
26
28
|
export { OpenRouter } from './openrouter.js';
|
|
27
29
|
//# sourceMappingURL=index.d.ts.map
|
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
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,c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AU,EACV,aAAa,EACb,QAAQ,EACR,qBAAqB,EACrB,mBAAmB,EACnB,IAAI,EACJ,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,EACxB,eAAe,EACf,qBAAqB,EACrB,0BAA0B,EAC1B,eAAe,EACf,cAAc,EACd,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,OAAO,GACR,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,oBAAoB,EACpB,YAAY,EACZ,qBAAqB,EACrB,4BAA4B,EAC5B,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,QAAQ,EACR,yBAAyB,GAC1B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,gBAAgB,EAAE,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
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// SDK type re-exports — every SDK type used in this package's public API
|
|
2
2
|
// so consumers don't need to depend on @openrouter/sdk directly.
|
|
3
|
+
// Hooks — interception points for requests and responses
|
|
4
|
+
export { SDKHooks } from '@openrouter/sdk/hooks/hooks';
|
|
3
5
|
// Message format compatibility helpers
|
|
4
6
|
// High-level model calling
|
|
5
7
|
export { callModel } from './inner-loop/call-model.js';
|
|
@@ -18,12 +20,12 @@ export { applyNextTurnParamsToRequest, buildNextTurnParamsContext, executeNextTu
|
|
|
18
20
|
export { finishReasonIs, hasToolCall, isStopConditionMet, maxCost, maxTokensUsed, stepCountIs, } from './lib/stop-conditions.js';
|
|
19
21
|
export { extractUnsupportedContent, getUnsupportedContentSummary, hasUnsupportedContent, } from './lib/stream-transformers.js';
|
|
20
22
|
// Tool creation helpers
|
|
21
|
-
export { tool } from './lib/tool.js';
|
|
23
|
+
export { serverTool, tool } from './lib/tool.js';
|
|
22
24
|
// Tool context helpers
|
|
23
25
|
export { buildToolExecuteContext, ToolContextStore } from './lib/tool-context.js';
|
|
24
26
|
// Real-time tool event broadcasting
|
|
25
27
|
export { ToolEventBroadcaster } from './lib/tool-event-broadcaster.js';
|
|
26
|
-
export { hasApprovalRequiredTools, hasExecuteFunction, isGeneratorTool, isRegularExecuteTool, isToolCallOutputEvent, isToolPreliminaryResultEvent, isToolResultEvent, isTurnEndEvent, isTurnStartEvent, ToolType, toolHasApprovalConfigured, } from './lib/tool-types.js';
|
|
28
|
+
export { hasApprovalRequiredTools, hasExecuteFunction, isClientTool, isGeneratorTool, isRegularExecuteTool, isServerTool, isToolCallOutputEvent, isToolPreliminaryResultEvent, isToolResultEvent, isTurnEndEvent, isTurnStartEvent, ToolType, toolHasApprovalConfigured, } from './lib/tool-types.js';
|
|
27
29
|
// Turn context helpers
|
|
28
30
|
export { buildTurnContext, normalizeInputToArray } from './lib/turn-context.js';
|
|
29
31
|
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;
|
|
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;AA0EvD,uCAAuC;AAEvC,2BAA2B;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAMhF,OAAO,EAAE,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AAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEhF,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-state.d.ts","sourceRoot":"","sources":["../../src/lib/conversation-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,IAAI,EACJ,WAAW,EACX,gBAAgB,EACjB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"conversation-state.d.ts","sourceRoot":"","sources":["../../src/lib/conversation-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,IAAI,EACJ,WAAW,EACX,gBAAgB,EACjB,MAAM,iBAAiB,CAAC;AAyCzB;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,CAM/C;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,SAAS,SAAS,IAAI,EAAE,GAAG,SAAS,IAAI,EAAE,EACjF,EAAE,CAAC,EAAE,MAAM,GACV,iBAAiB,CAAC,MAAM,CAAC,CAS3B;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,SAAS,SAAS,IAAI,EAAE,GAAG,SAAS,IAAI,EAAE,EAC1E,KAAK,EAAE,iBAAiB,CAAC,MAAM,CAAC,EAChC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,IAAI,GAAG,WAAW,GAAG,WAAW,CAAC,CAAC,GAClF,iBAAiB,CAAC,MAAM,CAAC,CAM3B;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,CAAC,WAAW,EAC3B,QAAQ,EAAE,M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AAS,IAAI,EAAE,EACnF,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,GACd,gBAAgB,CAAC,MAAM,CAAC,CAW1B;AAsBD;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,MAAM,CAAC,sBAAsB,EAAE,CAsBjC;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,CAAC,mBAAmB,GAAG,MAAM,CAuBpF;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,SAAS,SAAS,IAAI,EAAE,EACzE,QAAQ,EAAE,MAAM,CAAC,mBAAmB,GACnC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CA4ClC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isClientTool } from './tool-types.js';
|
|
1
2
|
import { normalizeInputToArray } from './turn-context.js';
|
|
2
3
|
/**
|
|
3
4
|
* Type guard to verify an object is a valid UnsentToolResult
|
|
@@ -83,19 +84,30 @@ export async function toolRequiresApproval(toolCall, tools, context, callLevelCh
|
|
|
83
84
|
if (callLevelCheck) {
|
|
84
85
|
return callLevelCheck(toolCall, context);
|
|
85
86
|
}
|
|
86
|
-
// Fall back to tool-level setting
|
|
87
|
-
const tool = tools.find((t) => t.function.name === toolCall.name);
|
|
87
|
+
// Fall back to tool-level setting (server tools never require approval)
|
|
88
|
+
const tool = tools.find((t) => isClientTool(t) && t.function.name === toolCall.name);
|
|
88
89
|
if (!tool) {
|
|
89
90
|
return false;
|
|
90
91
|
}
|
|
91
92
|
const requireApproval = tool.function.requireApproval;
|
|
92
|
-
// If it's a function, call it with the tool's arguments and context
|
|
93
|
+
// If it's a function, call it with the tool's arguments and context.
|
|
94
|
+
// Arguments have already been parsed and validated against the tool's
|
|
95
|
+
// Zod inputSchema (a ZodObject), so the runtime shape is always a
|
|
96
|
+
// record here. A non-record value signals a real upstream bug — surface
|
|
97
|
+
// it rather than substituting an empty object.
|
|
93
98
|
if (typeof requireApproval === 'function') {
|
|
94
|
-
|
|
99
|
+
const rawArgs = toolCall.arguments;
|
|
100
|
+
if (!isRecord(rawArgs)) {
|
|
101
|
+
throw new Error(`toolCall.arguments for "${toolCall.name}" must be an object after Zod validation, got ${rawArgs === null ? 'null' : Array.isArray(rawArgs) ? 'array' : typeof rawArgs}`);
|
|
102
|
+
}
|
|
103
|
+
return requireApproval(rawArgs, context);
|
|
95
104
|
}
|
|
96
105
|
// Otherwise treat as boolean
|
|
97
106
|
return requireApproval ?? false;
|
|
98
107
|
}
|
|
108
|
+
function isRecord(value) {
|
|
109
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
110
|
+
}
|
|
99
111
|
/**
|
|
100
112
|
* Partition tool calls into those requiring approval and those that can auto-execute
|
|
101
113
|
* @param toolCalls - Tool calls to partition
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-state.js","sourceRoot":"","sources":["../../src/lib/conversation-state.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"conversation-state.js","sourceRoot":"","sources":["../../src/lib/conversation-state.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D;;GAEG;AACH,SAAS,uBAAuB,CAC9B,GAAY;IAEZ,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,CACL,QAAQ,IAAI,GAAG;QACf,OAAO,GAAG,CAAC,MAAM,KAAK,QAAQ;QAC9B,MAAM,IAAI,GAAG;QACb,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ;QAC5B,QAAQ,IAAI,GAAG,CAChB,CAAC;AACJ,CAAC;AAED;;G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AAE,CAAC,CAAC;QAC5E,CAAC;QACD,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -295,7 +295,25 @@ export declare class ModelResult<TTools extends readonly Tool[], TShared extends
|
|
|
295
295
|
* - image_generation_call: Image generation operations
|
|
296
296
|
* - function_call_output: Results from executed tools
|
|
297
297
|
*/
|
|
298
|
-
getItemsStream(): AsyncIterableIterator<StreamableOutputItem
|
|
298
|
+
getItemsStream(): AsyncIterableIterator<StreamableOutputItem<TTools>>;
|
|
299
|
+
/**
|
|
300
|
+
* Compute the runtime allow-list of item types that `getItemsStream()`
|
|
301
|
+
* may yield, derived from the tools actually passed to callModel. The
|
|
302
|
+
* three return modes correspond to the compile-time narrowing:
|
|
303
|
+
*
|
|
304
|
+
* - `acceptAll: true` — no tools or fully-unconstrained TTools; the
|
|
305
|
+
* yielded union is the widest `StreamableOutputItem`.
|
|
306
|
+
* - Specific `allowed` set — client tools contribute
|
|
307
|
+
* `function_call` / `function_call_output`; mapped server tools
|
|
308
|
+
* contribute their SDK output item type literal
|
|
309
|
+
* (`web_search_call`, `file_search_call`, `image_generation_call`).
|
|
310
|
+
* - `acceptGenericServerItem: true` — at least one server tool has a
|
|
311
|
+
* type the agent SDK does not have a dedicated output mapping for
|
|
312
|
+
* (e.g. `openrouter:datetime`, `mcp`, new SDK additions). Any
|
|
313
|
+
* non-client item type is accepted because these items pass through
|
|
314
|
+
* as `OutputServerToolItem`, whose `type` field is an open `string`.
|
|
315
|
+
*/
|
|
316
|
+
private computeItemStreamScope;
|
|
299
317
|
/**
|
|
300
318
|
* @deprecated Use `getItemsStream()` instead. This method only streams messages,
|
|
301
319
|
* while `getItemsStream()` streams all output item types (messages, function_calls,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-result.d.ts","sourceRoot":"","sources":["../../src/lib/model-result.ts"],"names":[],"mappings":"AAAA,OAAO,KA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MAAM,CAAC,CAAC,EAAE,CAAC;IAgB/D;;;OAGG;IACH,kBAAkB,IAAI,qBAAqB,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAgB3E;;;;;;;;;;;OAWG;IACI,iBAAiB,IAAI,cAAc,CAAC,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IA4DrF;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAU7B;;;OAGG;IACG,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC;IAY1C;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;IAWtE;;;;;OAKG;IACG,QAAQ,IAAI,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;CAgBrD"}
|
package/esm/lib/model-result.js
CHANGED
|
@@ -5,16 +5,22 @@ import { applyNextTurnParamsToRequest, executeNextTurnParamsFunctions, } from '.
|
|
|
5
5
|
import { ReusableReadableStream } from './reusable-stream.js';
|
|
6
6
|
import { isStopConditionMet, stepCountIs } from './stop-conditions.js';
|
|
7
7
|
import { buildItemsStream, buildResponsesMessageStream, buildToolCallStream, consumeStreamForCompletion, extractReasoningDeltas, extractResponsesMessageFromResponse, extractTextDeltas, extractTextFromResponse, extractToolCallsFromResponse, extractToolDeltas, itemsStreamHandlers, streamTerminationEvents, } from './stream-transformers.js';
|
|
8
|
-
import { hasTypeProperty, isFunctionCallItem, isOutputTextDeltaEvent, isReasoningDeltaEvent, isResponseCompletedEvent, isResponseFailedEvent, isResponseIncompleteEvent, } from './stream-type-guards.js';
|
|
8
|
+
import { hasTypeProperty, isFunctionCallItem, isFunctionCallOutputItem, isOutputTextDeltaEvent, isReasoningDeltaEvent, isResponseCompletedEvent, isResponseFailedEvent, isResponseIncompleteEvent, isServerToolResultItem, } from './stream-type-guards.js';
|
|
9
9
|
import { resolveContext, ToolContextStore } from './tool-context.js';
|
|
10
10
|
import { ToolEventBroadcaster } from './tool-event-broadcaster.js';
|
|
11
11
|
import { executeTool } from './tool-executor.js';
|
|
12
|
-
import { hasExecuteFunction, isToolCallOutputEvent } from './tool-types.js';
|
|
12
|
+
import { hasExecuteFunction, isClientTool, isServerTool, isToolCallOutputEvent, } from './tool-types.js';
|
|
13
13
|
/**
|
|
14
14
|
* Default maximum number of tool execution steps if no stopWhen is specified.
|
|
15
15
|
* This prevents infinite loops in tool execution.
|
|
16
16
|
*/
|
|
17
17
|
const DEFAULT_MAX_STEPS = 5;
|
|
18
|
+
/**
|
|
19
|
+
* Typeguard for plain-object records (non-null, non-array).
|
|
20
|
+
*/
|
|
21
|
+
function isRecord(value) {
|
|
22
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
23
|
+
}
|
|
18
24
|
/**
|
|
19
25
|
* Type guard for stream event with toReadableStream method
|
|
20
26
|
* Checks constructor name, prototype, and method availability
|
|
@@ -350,17 +356,23 @@ export class ModelResult {
|
|
|
350
356
|
: [
|
|
351
357
|
stopWhen,
|
|
352
358
|
];
|
|
359
|
+
const isFunctionCallOutput = (tr) => tr.type === 'function_call_output';
|
|
360
|
+
const isServerToolResult = (tr) => tr.type !== 'function_call_output';
|
|
353
361
|
return isStopConditionMet({
|
|
354
362
|
stopConditions,
|
|
355
363
|
steps: this.allToolExecutionRounds.map((round) => ({
|
|
356
364
|
stepType: 'continue',
|
|
357
365
|
text: extractTextFromResponse(round.response),
|
|
358
366
|
toolCalls: round.toolCalls,
|
|
359
|
-
|
|
367
|
+
// `toolResults` is client-tool-centric; server-tool output items are
|
|
368
|
+
// surfaced on `serverToolResults` so stop conditions can react to
|
|
369
|
+
// either class of result.
|
|
370
|
+
toolResults: round.toolResults.filter(isFunctionCallOutput).map((tr) => ({
|
|
360
371
|
toolCallId: tr.callId,
|
|
361
372
|
toolName: round.toolCalls.find((tc) => tc.id === tr.callId)?.name ?? '',
|
|
362
373
|
result: typeof tr.output === 'string' ? JSON.parse(tr.output) : tr.output,
|
|
363
374
|
})),
|
|
375
|
+
serverToolResults: round.toolResults.filter(isServerToolResult),
|
|
364
376
|
response: round.response,
|
|
365
377
|
usage: round.response.usage,
|
|
366
378
|
finishReason: undefined,
|
|
@@ -376,12 +388,12 @@ export class ModelResult {
|
|
|
376
388
|
*/
|
|
377
389
|
hasExecutableToolCalls(toolCalls) {
|
|
378
390
|
return toolCalls.some((toolCall) => {
|
|
379
|
-
const tool = this.options.tools?.find((t) => t.function.name === toolCall.name);
|
|
391
|
+
const tool = this.options.tools?.find((t) => isClientTool(t) && t.function.name === toolCall.name);
|
|
380
392
|
return tool && hasExecuteFunction(tool);
|
|
381
393
|
});
|
|
382
394
|
}
|
|
383
395
|
isManualToolCall(item) {
|
|
384
|
-
const tool = this.options.tools?.find((t) => t.function.name === item.name);
|
|
396
|
+
const tool = this.options.tools?.find((t) => isClientTool(t) && t.function.name === item.name);
|
|
385
397
|
return !!tool && !hasExecuteFunction(tool);
|
|
386
398
|
}
|
|
387
399
|
/**
|
|
@@ -393,7 +405,7 @@ export class ModelResult {
|
|
|
393
405
|
*/
|
|
394
406
|
async executeAutoApproveTools(toolCalls, turnContext) {
|
|
395
407
|
const toolCallPromises = toolCalls.map(async (tc) => {
|
|
396
|
-
const tool = this.options.tools?.find((t) => t.function.name === tc.name);
|
|
408
|
+
const tool = this.options.tools?.find((t) => isClientTool(t) && t.function.name === tc.name);
|
|
397
409
|
if (!tool || !hasExecuteFunction(tool)) {
|
|
398
410
|
return null;
|
|
399
411
|
}
|
|
@@ -474,7 +486,7 @@ export class ModelResult {
|
|
|
474
486
|
*/
|
|
475
487
|
async executeToolRound(toolCalls, turnContext) {
|
|
476
488
|
const toolCallPromises = toolCalls.map(async (toolCall) => {
|
|
477
|
-
const tool = this.options.tools?.find((t) => t.function.name === toolCall.name);
|
|
489
|
+
const tool = this.options.tools?.find((t) => isClientTool(t) && t.function.name === toolCall.name);
|
|
478
490
|
if (!tool || !hasExecuteFunction(tool)) {
|
|
479
491
|
return null;
|
|
480
492
|
}
|
|
@@ -574,10 +586,20 @@ export class ModelResult {
|
|
|
574
586
|
});
|
|
575
587
|
}
|
|
576
588
|
else if (value.tool.function.toModelOutput) {
|
|
577
|
-
// toModelOutput exists - call it (may throw, which surfaces the error)
|
|
589
|
+
// toModelOutput exists - call it (may throw, which surfaces the error).
|
|
590
|
+
// Arguments have already been validated upstream by the tool's Zod
|
|
591
|
+
// inputSchema (which must be a ZodObject), so the runtime shape is
|
|
592
|
+
// always a record here. The `Tool` union widening loses the specific
|
|
593
|
+
// InferToolInput type, so we re-narrow defensively — a non-record
|
|
594
|
+
// value here signals a real upstream bug we want surfaced, not a
|
|
595
|
+
// case to paper over with `{}`.
|
|
596
|
+
const rawArgs = value.toolCall.arguments;
|
|
597
|
+
if (!isRecord(rawArgs)) {
|
|
598
|
+
throw new Error(`toolCall.arguments for "${value.toolCall.name}" must be an object after Zod validation, got ${rawArgs === null ? 'null' : Array.isArray(rawArgs) ? 'array' : typeof rawArgs}`);
|
|
599
|
+
}
|
|
578
600
|
const modelOutputResult = await value.tool.function.toModelOutput({
|
|
579
601
|
output: value.result.result,
|
|
580
|
-
input:
|
|
602
|
+
input: rawArgs,
|
|
581
603
|
});
|
|
582
604
|
outputForModel =
|
|
583
605
|
modelOutputResult.type === 'content'
|
|
@@ -901,7 +923,7 @@ export class ModelResult {
|
|
|
901
923
|
if (!toolCall) {
|
|
902
924
|
continue;
|
|
903
925
|
}
|
|
904
|
-
const tool = this.options.tools?.find((t) => t.function.name === toolCall.name);
|
|
926
|
+
const tool = this.options.tools?.find((t) => isClientTool(t) && t.function.name === toolCall.name);
|
|
905
927
|
if (!tool || !hasExecuteFunction(tool)) {
|
|
906
928
|
// Can't execute, create error result
|
|
907
929
|
unsentResults.push(createRejectedResult(callId, String(toolCall.name), 'Tool not found or not executable'));
|
|
@@ -1083,12 +1105,35 @@ export class ModelResult {
|
|
|
1083
1105
|
await this.resolveAsyncFunctionsForTurn(turnContext);
|
|
1084
1106
|
// Execute tools
|
|
1085
1107
|
const toolResults = await this.executeToolRound(currentToolCalls, turnContext);
|
|
1108
|
+
// Server-tool output items are already-executed results in the
|
|
1109
|
+
// response; collect them so toolResults presents a unified list.
|
|
1110
|
+
const serverToolItems = [];
|
|
1111
|
+
for (const item of currentResponse.output) {
|
|
1112
|
+
if (!hasTypeProperty(item)) {
|
|
1113
|
+
continue;
|
|
1114
|
+
}
|
|
1115
|
+
if (item.type === 'message' ||
|
|
1116
|
+
item.type === 'reasoning' ||
|
|
1117
|
+
item.type === 'function_call') {
|
|
1118
|
+
continue;
|
|
1119
|
+
}
|
|
1120
|
+
// Everything else is a server-tool output item (web_search_call,
|
|
1121
|
+
// image_generation_call, file_search_call, or generic
|
|
1122
|
+
// OutputServerToolItem covering openrouter:datetime and any new
|
|
1123
|
+
// SDK server tool types).
|
|
1124
|
+
if (isServerToolResultItem(item)) {
|
|
1125
|
+
serverToolItems.push(item);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1086
1128
|
// Track execution round
|
|
1087
1129
|
this.allToolExecutionRounds.push({
|
|
1088
1130
|
round: currentRound,
|
|
1089
1131
|
toolCalls: currentToolCalls,
|
|
1090
1132
|
response: currentResponse,
|
|
1091
|
-
toolResults
|
|
1133
|
+
toolResults: [
|
|
1134
|
+
...toolResults,
|
|
1135
|
+
...serverToolItems,
|
|
1136
|
+
],
|
|
1092
1137
|
});
|
|
1093
1138
|
// Save tool results to state
|
|
1094
1139
|
await this.saveToolResultsToState(toolResults);
|
|
@@ -1208,6 +1253,30 @@ export class ModelResult {
|
|
|
1208
1253
|
* - function_call_output: Results from executed tools
|
|
1209
1254
|
*/
|
|
1210
1255
|
getItemsStream() {
|
|
1256
|
+
// Build the allowed-item-type scope from the tools actually passed to
|
|
1257
|
+
// callModel, mirroring the compile-time rules that produce
|
|
1258
|
+
// StreamableOutputItem<TTools>. A runtime predicate then drops items
|
|
1259
|
+
// whose type isn't reachable in the narrowed union. The predicate's
|
|
1260
|
+
// claim (`item is StreamableOutputItem<TTools>`) is sound because:
|
|
1261
|
+
// - `allowed` is constructed from the same tools that produced TTools
|
|
1262
|
+
// - `OutputServerToolItem.type` is `string` (open), so any non-client
|
|
1263
|
+
// item type is structurally assignable to it, covering generic /
|
|
1264
|
+
// unmapped server-tool outputs.
|
|
1265
|
+
const scope = this.computeItemStreamScope();
|
|
1266
|
+
const isInScope = (item) => {
|
|
1267
|
+
if (scope.acceptAll) {
|
|
1268
|
+
return true;
|
|
1269
|
+
}
|
|
1270
|
+
if (scope.allowed.has(item.type)) {
|
|
1271
|
+
return true;
|
|
1272
|
+
}
|
|
1273
|
+
if (scope.acceptGenericServerItem &&
|
|
1274
|
+
item.type !== 'function_call' &&
|
|
1275
|
+
item.type !== 'function_call_output') {
|
|
1276
|
+
return true;
|
|
1277
|
+
}
|
|
1278
|
+
return false;
|
|
1279
|
+
};
|
|
1211
1280
|
return async function* () {
|
|
1212
1281
|
await this.initStream();
|
|
1213
1282
|
if (!this.reusableStream && !this.finalResponse) {
|
|
@@ -1216,7 +1285,11 @@ export class ModelResult {
|
|
|
1216
1285
|
// No tools — stream single turn directly (no broadcaster needed)
|
|
1217
1286
|
if (!this.options.tools?.length) {
|
|
1218
1287
|
if (this.reusableStream) {
|
|
1219
|
-
|
|
1288
|
+
for await (const item of buildItemsStream(this.reusableStream)) {
|
|
1289
|
+
if (isInScope(item)) {
|
|
1290
|
+
yield item;
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1220
1293
|
}
|
|
1221
1294
|
return;
|
|
1222
1295
|
}
|
|
@@ -1228,7 +1301,9 @@ export class ModelResult {
|
|
|
1228
1301
|
for await (const event of consumer) {
|
|
1229
1302
|
// Tool call outputs → yield directly as function_call_output items
|
|
1230
1303
|
if (isToolCallOutputEvent(event)) {
|
|
1231
|
-
|
|
1304
|
+
if (isInScope(event.output)) {
|
|
1305
|
+
yield event.output;
|
|
1306
|
+
}
|
|
1232
1307
|
continue;
|
|
1233
1308
|
}
|
|
1234
1309
|
// Stream termination → reset items map for next turn
|
|
@@ -1243,7 +1318,7 @@ export class ModelResult {
|
|
|
1243
1318
|
const handler = itemsStreamHandlers[event.type];
|
|
1244
1319
|
if (handler) {
|
|
1245
1320
|
const result = handler(event, itemsInProgress);
|
|
1246
|
-
if (result) {
|
|
1321
|
+
if (result && isInScope(result)) {
|
|
1247
1322
|
yield result;
|
|
1248
1323
|
}
|
|
1249
1324
|
}
|
|
@@ -1252,6 +1327,98 @@ export class ModelResult {
|
|
|
1252
1327
|
await executionPromise;
|
|
1253
1328
|
}.call(this);
|
|
1254
1329
|
}
|
|
1330
|
+
/**
|
|
1331
|
+
* Compute the runtime allow-list of item types that `getItemsStream()`
|
|
1332
|
+
* may yield, derived from the tools actually passed to callModel. The
|
|
1333
|
+
* three return modes correspond to the compile-time narrowing:
|
|
1334
|
+
*
|
|
1335
|
+
* - `acceptAll: true` — no tools or fully-unconstrained TTools; the
|
|
1336
|
+
* yielded union is the widest `StreamableOutputItem`.
|
|
1337
|
+
* - Specific `allowed` set — client tools contribute
|
|
1338
|
+
* `function_call` / `function_call_output`; mapped server tools
|
|
1339
|
+
* contribute their SDK output item type literal
|
|
1340
|
+
* (`web_search_call`, `file_search_call`, `image_generation_call`).
|
|
1341
|
+
* - `acceptGenericServerItem: true` — at least one server tool has a
|
|
1342
|
+
* type the agent SDK does not have a dedicated output mapping for
|
|
1343
|
+
* (e.g. `openrouter:datetime`, `mcp`, new SDK additions). Any
|
|
1344
|
+
* non-client item type is accepted because these items pass through
|
|
1345
|
+
* as `OutputServerToolItem`, whose `type` field is an open `string`.
|
|
1346
|
+
*/
|
|
1347
|
+
computeItemStreamScope() {
|
|
1348
|
+
const tools = this.options.tools ?? [];
|
|
1349
|
+
if (tools.length === 0) {
|
|
1350
|
+
// No tools passed: runtime only emits message/reasoning, but the
|
|
1351
|
+
// widest StreamableOutputItem<readonly Tool[]> includes every item
|
|
1352
|
+
// type. Accept all so the default unconstrained case matches its
|
|
1353
|
+
// compile-time union.
|
|
1354
|
+
return {
|
|
1355
|
+
acceptAll: true,
|
|
1356
|
+
allowed: new Set(),
|
|
1357
|
+
acceptGenericServerItem: false,
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
const allowed = new Set([
|
|
1361
|
+
'message',
|
|
1362
|
+
'reasoning',
|
|
1363
|
+
]);
|
|
1364
|
+
let acceptGenericServerItem = false;
|
|
1365
|
+
for (const tool of tools) {
|
|
1366
|
+
if (isClientTool(tool)) {
|
|
1367
|
+
allowed.add('function_call');
|
|
1368
|
+
allowed.add('function_call_output');
|
|
1369
|
+
continue;
|
|
1370
|
+
}
|
|
1371
|
+
if (!isServerTool(tool)) {
|
|
1372
|
+
continue;
|
|
1373
|
+
}
|
|
1374
|
+
const requestType = tool.config.type;
|
|
1375
|
+
switch (requestType) {
|
|
1376
|
+
case 'web_search':
|
|
1377
|
+
case 'web_search_2025_08_26':
|
|
1378
|
+
case 'web_search_preview':
|
|
1379
|
+
case 'web_search_preview_2025_03_11':
|
|
1380
|
+
allowed.add('web_search_call');
|
|
1381
|
+
break;
|
|
1382
|
+
case 'openrouter:web_search':
|
|
1383
|
+
// Defensive: OpenRouter's web_search variant may emit either the
|
|
1384
|
+
// standard OutputWebSearchCallItem (type='web_search_call') OR be
|
|
1385
|
+
// wrapped in OutputServerToolItem with type='openrouter:web_search'.
|
|
1386
|
+
// Accept both literals so the runtime filter doesn't silently drop
|
|
1387
|
+
// valid items. Do NOT set acceptGenericServerItem — we know the
|
|
1388
|
+
// tool type and want the filter narrow.
|
|
1389
|
+
allowed.add('web_search_call');
|
|
1390
|
+
allowed.add('openrouter:web_search');
|
|
1391
|
+
break;
|
|
1392
|
+
case 'file_search':
|
|
1393
|
+
allowed.add('file_search_call');
|
|
1394
|
+
break;
|
|
1395
|
+
case 'image_generation':
|
|
1396
|
+
allowed.add('image_generation_call');
|
|
1397
|
+
break;
|
|
1398
|
+
case 'openrouter:datetime':
|
|
1399
|
+
// Known server tool whose SDK output item uses the same literal
|
|
1400
|
+
// as the request type. Mirrors `KnownServerToolOutputs` in
|
|
1401
|
+
// stream-transformers.ts so the runtime filter stays as narrow
|
|
1402
|
+
// as the compile-time union (no acceptGenericServerItem widening).
|
|
1403
|
+
allowed.add('openrouter:datetime');
|
|
1404
|
+
break;
|
|
1405
|
+
default:
|
|
1406
|
+
// Unknown / generic server tool — at runtime its output items
|
|
1407
|
+
// pass through as the request-type literal or as the SDK's
|
|
1408
|
+
// OutputServerToolItem wrapper. Accept the literal plus the
|
|
1409
|
+
// generic fallback. See `StreamableOutputItem` narrowing in
|
|
1410
|
+
// stream-transformers.ts for the matching type-level rules.
|
|
1411
|
+
allowed.add(requestType);
|
|
1412
|
+
acceptGenericServerItem = true;
|
|
1413
|
+
break;
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
return {
|
|
1417
|
+
acceptAll: false,
|
|
1418
|
+
allowed,
|
|
1419
|
+
acceptGenericServerItem,
|
|
1420
|
+
};
|
|
1421
|
+
}
|
|
1255
1422
|
/**
|
|
1256
1423
|
* @deprecated Use `getItemsStream()` instead. This method only streams messages,
|
|
1257
1424
|
* while `getItemsStream()` streams all output item types (messages, function_calls,
|
|
@@ -1286,9 +1453,12 @@ export class ModelResult {
|
|
|
1286
1453
|
yield item;
|
|
1287
1454
|
}
|
|
1288
1455
|
}
|
|
1289
|
-
// Then yield the function_call_output results
|
|
1456
|
+
// Then yield the function_call_output results (client tools only;
|
|
1457
|
+
// server-tool output items are surfaced through getItemsStream).
|
|
1290
1458
|
for (const toolResult of round.toolResults) {
|
|
1291
|
-
|
|
1459
|
+
if (isFunctionCallOutputItem(toolResult)) {
|
|
1460
|
+
yield toolResult;
|
|
1461
|
+
}
|
|
1292
1462
|
}
|
|
1293
1463
|
}
|
|
1294
1464
|
// Yield manual tool function_call items from finalResponse, skipping duplicates
|