@openrouter/sdk 1.5.56 → 1.5.58

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 (105) 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/decisionsresponse.d.ts +12 -0
  16. package/esm/models/decisionsresponse.js +5 -0
  17. package/esm/models/decisionsscorequestion.d.ts +4 -4
  18. package/esm/models/decisionsscorequestion.js +1 -5
  19. package/esm/models/imagegenerationproviderpreferences.d.ts +6 -0
  20. package/esm/models/imagegenerationproviderpreferences.js +1 -0
  21. package/esm/models/imagegenerationrequest.d.ts +1 -1
  22. package/esm/models/index.d.ts +6 -0
  23. package/esm/models/index.js +6 -0
  24. package/esm/models/mcpapprovalrequestitem.d.ts +7 -0
  25. package/esm/models/mcpapprovalrequestitem.js +19 -1
  26. package/esm/models/mcpcallitem.d.ts +17 -1
  27. package/esm/models/mcpcallitem.js +18 -0
  28. package/esm/models/mcpservertool.d.ts +78 -69
  29. package/esm/models/mcpservertool.js +135 -105
  30. package/esm/models/mcpservertoolopenrouter.d.ts +28 -0
  31. package/esm/models/mcpservertoolopenrouter.js +20 -0
  32. package/esm/models/mcpservertoolparameters.d.ts +152 -0
  33. package/esm/models/mcpservertoolparameters.js +134 -0
  34. package/esm/models/openairesponsestoolchoiceunion.d.ts +3 -2
  35. package/esm/models/openairesponsestoolchoiceunion.js +3 -0
  36. package/esm/models/operations/listbyokkeys.d.ts +1 -0
  37. package/esm/models/operations/listbyokkeys.js +1 -0
  38. package/esm/models/outputitemmcpapprovalrequest.d.ts +14 -0
  39. package/esm/models/outputitemmcpapprovalrequest.js +23 -0
  40. package/esm/models/outputitemmcpcall.d.ts +74 -0
  41. package/esm/models/outputitemmcpcall.js +94 -0
  42. package/esm/models/outputitemmcplisttools.d.ts +25 -0
  43. package/esm/models/outputitemmcplisttools.js +37 -0
  44. package/esm/models/outputitems.d.ts +3 -0
  45. package/esm/models/outputitems.js +2 -0
  46. package/esm/models/providername.d.ts +1 -0
  47. package/esm/models/providername.js +1 -0
  48. package/esm/models/provideroptions.d.ts +6 -0
  49. package/esm/models/provideroptions.js +1 -0
  50. package/esm/models/providerresponse.d.ts +1 -0
  51. package/esm/models/providerresponse.js +1 -0
  52. package/esm/models/responsesrequest.d.ts +9 -0
  53. package/esm/models/responsesrequest.js +3 -0
  54. package/esm/models/toolchoicemcp.d.ts +33 -0
  55. package/esm/models/toolchoicemcp.js +42 -0
  56. package/esm/models/toolsearchoutputitem.d.ts +5 -4
  57. package/esm/models/toolsearchoutputitem.js +3 -0
  58. package/esm/models/updateworkspacerequest.d.ts +1 -0
  59. package/esm/models/updateworkspacerequest.js +1 -0
  60. package/esm/models/videogenerationrequest.d.ts +6 -0
  61. package/esm/models/videogenerationrequest.js +1 -0
  62. package/esm/sdk/sdk.d.ts +0 -9
  63. package/esm/sdk/sdk.js +1 -7
  64. package/jsr.json +1 -1
  65. package/package.json +8 -8
  66. package/esm/funcs/call-model.d.ts +0 -67
  67. package/esm/funcs/call-model.js +0 -98
  68. package/esm/lib/anthropic-compat.d.ts +0 -51
  69. package/esm/lib/anthropic-compat.js +0 -222
  70. package/esm/lib/async-params.d.ts +0 -107
  71. package/esm/lib/async-params.js +0 -88
  72. package/esm/lib/chat-compat.d.ts +0 -47
  73. package/esm/lib/chat-compat.js +0 -111
  74. package/esm/lib/claude-constants.d.ts +0 -22
  75. package/esm/lib/claude-constants.js +0 -20
  76. package/esm/lib/claude-type-guards.d.ts +0 -10
  77. package/esm/lib/claude-type-guards.js +0 -70
  78. package/esm/lib/conversation-state.d.ts +0 -63
  79. package/esm/lib/conversation-state.js +0 -210
  80. package/esm/lib/model-result.d.ts +0 -373
  81. package/esm/lib/model-result.js +0 -1414
  82. package/esm/lib/next-turn-params.d.ts +0 -30
  83. package/esm/lib/next-turn-params.js +0 -135
  84. package/esm/lib/reusable-stream.d.ts +0 -39
  85. package/esm/lib/reusable-stream.js +0 -192
  86. package/esm/lib/stop-conditions.d.ts +0 -80
  87. package/esm/lib/stop-conditions.js +0 -104
  88. package/esm/lib/stream-transformers.d.ts +0 -118
  89. package/esm/lib/stream-transformers.js +0 -852
  90. package/esm/lib/stream-type-guards.d.ts +0 -49
  91. package/esm/lib/stream-type-guards.js +0 -85
  92. package/esm/lib/tool-context.d.ts +0 -68
  93. package/esm/lib/tool-context.js +0 -175
  94. package/esm/lib/tool-event-broadcaster.d.ts +0 -44
  95. package/esm/lib/tool-event-broadcaster.js +0 -146
  96. package/esm/lib/tool-executor.d.ts +0 -74
  97. package/esm/lib/tool-executor.js +0 -267
  98. package/esm/lib/tool-orchestrator.d.ts +0 -52
  99. package/esm/lib/tool-orchestrator.js +0 -180
  100. package/esm/lib/tool-types.d.ts +0 -573
  101. package/esm/lib/tool-types.js +0 -80
  102. package/esm/lib/tool.d.ts +0 -108
  103. package/esm/lib/tool.js +0 -74
  104. package/esm/lib/turn-context.d.ts +0 -52
  105. package/esm/lib/turn-context.js +0 -59
package/esm/lib/tool.d.ts DELETED
@@ -1,108 +0,0 @@
1
- import type { $ZodObject, $ZodShape, $ZodType, infer as zodInfer } from 'zod/v4/core';
2
- import { type Tool, type ToolExecuteContext, type ToolWithExecute, type ToolWithGenerator, type ManualTool, type NextTurnParamsFunctions, type ToolApprovalCheck } from "./tool-types.js";
3
- /**
4
- * Configuration for a regular tool with outputSchema
5
- */
6
- type RegularToolConfigWithOutput<TInput extends $ZodObject<$ZodShape>, TOutput extends $ZodType, TContext extends Record<string, unknown> = Record<string, unknown>, TName extends string = string> = {
7
- name: TName;
8
- description?: string;
9
- inputSchema: TInput;
10
- outputSchema: TOutput;
11
- eventSchema?: undefined;
12
- /** Zod schema declaring the context data this tool needs */
13
- contextSchema?: $ZodObject<$ZodShape>;
14
- nextTurnParams?: NextTurnParamsFunctions<zodInfer<TInput>>;
15
- requireApproval?: boolean | ToolApprovalCheck<zodInfer<TInput>>;
16
- execute: (params: zodInfer<TInput>, context?: ToolExecuteContext<TName, TContext>) => Promise<zodInfer<TOutput>> | zodInfer<TOutput>;
17
- };
18
- /**
19
- * Configuration for a regular tool without outputSchema (infers return type from execute)
20
- */
21
- type RegularToolConfigWithoutOutput<TInput extends $ZodObject<$ZodShape>, TReturn, TContext extends Record<string, unknown> = Record<string, unknown>, TName extends string = string> = {
22
- name: TName;
23
- description?: string;
24
- inputSchema: TInput;
25
- outputSchema?: undefined;
26
- eventSchema?: undefined;
27
- /** Zod schema declaring the context data this tool needs */
28
- contextSchema?: $ZodObject<$ZodShape>;
29
- nextTurnParams?: NextTurnParamsFunctions<zodInfer<TInput>>;
30
- requireApproval?: boolean | ToolApprovalCheck<zodInfer<TInput>>;
31
- execute: (params: zodInfer<TInput>, context?: ToolExecuteContext<TName, TContext>) => Promise<TReturn> | TReturn;
32
- };
33
- /**
34
- * Configuration for a generator tool (with eventSchema)
35
- */
36
- type GeneratorToolConfig<TInput extends $ZodObject<$ZodShape>, TEvent extends $ZodType, TOutput extends $ZodType, TContext extends Record<string, unknown> = Record<string, unknown>, TName extends string = string> = {
37
- name: TName;
38
- description?: string;
39
- inputSchema: TInput;
40
- eventSchema: TEvent;
41
- outputSchema: TOutput;
42
- /** Zod schema declaring the context data this tool needs */
43
- contextSchema?: $ZodObject<$ZodShape>;
44
- nextTurnParams?: NextTurnParamsFunctions<zodInfer<TInput>>;
45
- requireApproval?: boolean | ToolApprovalCheck<zodInfer<TInput>>;
46
- execute: (params: zodInfer<TInput>, context?: ToolExecuteContext<TName, TContext>) => AsyncGenerator<zodInfer<TEvent> | zodInfer<TOutput>>;
47
- };
48
- /**
49
- * Configuration for a manual tool (execute: false, no eventSchema or outputSchema)
50
- */
51
- type ManualToolConfig<TInput extends $ZodObject<$ZodShape>> = {
52
- name: string;
53
- description?: string;
54
- inputSchema: TInput;
55
- /** Zod schema declaring the context data this tool needs */
56
- contextSchema?: $ZodObject<$ZodShape>;
57
- nextTurnParams?: NextTurnParamsFunctions<zodInfer<TInput>>;
58
- requireApproval?: boolean | ToolApprovalCheck<zodInfer<TInput>>;
59
- execute: false;
60
- };
61
- /**
62
- * Loose config type for the `tool<TShared>()` overload.
63
- * Accepts any valid tool config while typing `ctx.shared` from TShared.
64
- */
65
- type ToolConfigWithSharedContext<TShared extends Record<string, unknown>> = {
66
- name: string;
67
- description?: string;
68
- inputSchema: $ZodObject<$ZodShape>;
69
- outputSchema?: $ZodType;
70
- eventSchema?: $ZodType;
71
- contextSchema?: $ZodObject<$ZodShape>;
72
- nextTurnParams?: NextTurnParamsFunctions<Record<string, unknown>>;
73
- requireApproval?: boolean | ToolApprovalCheck<Record<string, unknown>>;
74
- execute: ((params: Record<string, unknown>, context?: ToolExecuteContext<string, Record<string, unknown>, TShared>) => unknown) | ((params: Record<string, unknown>, context?: ToolExecuteContext<string, Record<string, unknown>, TShared>) => AsyncGenerator<unknown>) | false;
75
- };
76
- /**
77
- * Creates a tool with full type inference from Zod schemas.
78
- *
79
- * The tool type is automatically determined based on the configuration:
80
- * - **Generator tool**: When `eventSchema` is provided
81
- * - **Regular tool**: When `execute` is a function (no `eventSchema`)
82
- * - **Manual tool**: When `execute: false` is set
83
- *
84
- * Shared context typing: Pass a type parameter to type `ctx.shared`
85
- * in the execute callback. Runtime validation happens at callModel
86
- * via `sharedContextSchema`.
87
- *
88
- * @example Regular tool with typed shared context:
89
- * ```typescript
90
- * type SharedCtx = z.infer<typeof SharedContextSchema>;
91
- *
92
- * const execTool = tool<SharedCtx>({
93
- * name: "sandbox_exec",
94
- * inputSchema: z.object({ command: z.string() }),
95
- * execute: async (params, ctx) => {
96
- * ctx?.shared._sessionId; // string | undefined
97
- * return { output: '...' };
98
- * },
99
- * });
100
- * ```
101
- */
102
- export declare function tool<TInput extends $ZodObject<$ZodShape>, TEvent extends $ZodType, TOutput extends $ZodType, TContext extends Record<string, unknown> = Record<string, unknown>, TName extends string = string>(config: GeneratorToolConfig<TInput, TEvent, TOutput, TContext, TName>): ToolWithGenerator<TInput, TEvent, TOutput, TContext>;
103
- export declare function tool<TInput extends $ZodObject<$ZodShape>>(config: ManualToolConfig<TInput>): ManualTool<TInput>;
104
- export declare function tool<TInput extends $ZodObject<$ZodShape>, TOutput extends $ZodType, TContext extends Record<string, unknown> = Record<string, unknown>, TName extends string = string>(config: RegularToolConfigWithOutput<TInput, TOutput, TContext, TName>): ToolWithExecute<TInput, TOutput, TContext>;
105
- export declare function tool<TInput extends $ZodObject<$ZodShape>, TReturn, TContext extends Record<string, unknown> = Record<string, unknown>, TName extends string = string>(config: RegularToolConfigWithoutOutput<TInput, TReturn, TContext, TName>): ToolWithExecute<TInput, $ZodType<TReturn>, TContext>;
106
- export declare function tool<TShared extends Record<string, unknown>>(config: ToolConfigWithSharedContext<TShared>): Tool;
107
- export {};
108
- //# sourceMappingURL=tool.d.ts.map
package/esm/lib/tool.js DELETED
@@ -1,74 +0,0 @@
1
- import { ToolType, SHARED_CONTEXT_KEY, } from "./tool-types.js";
2
- // Implementation
3
- export function tool(config) {
4
- // 'shared' is reserved for shared context — forbid it as a tool name
5
- if (config.name === SHARED_CONTEXT_KEY) {
6
- throw new Error(`Tool name "${SHARED_CONTEXT_KEY}" is reserved for shared context. Choose a different name.`);
7
- }
8
- // Check for manual tool first (execute === false)
9
- if (config.execute === false) {
10
- const fn = {
11
- name: config.name,
12
- inputSchema: config.inputSchema,
13
- };
14
- if (config.description !== undefined) {
15
- fn.description = config.description;
16
- }
17
- if (config.contextSchema !== undefined) {
18
- fn.contextSchema = config.contextSchema;
19
- }
20
- if (config.nextTurnParams !== undefined) {
21
- fn.nextTurnParams = config.nextTurnParams;
22
- }
23
- if (config.requireApproval !== undefined) {
24
- fn.requireApproval = config.requireApproval;
25
- }
26
- return {
27
- type: ToolType.Function,
28
- function: fn,
29
- };
30
- }
31
- // Check for generator tool (has eventSchema)
32
- if ('eventSchema' in config && config.eventSchema !== undefined) {
33
- const fn = {
34
- name: config.name,
35
- inputSchema: config.inputSchema,
36
- eventSchema: config.eventSchema,
37
- outputSchema: config.outputSchema,
38
- execute: config.execute,
39
- };
40
- if (config.description !== undefined) {
41
- fn.description = config.description;
42
- }
43
- if (config.contextSchema !== undefined) {
44
- fn.contextSchema = config.contextSchema;
45
- }
46
- if (config.nextTurnParams !== undefined) {
47
- fn.nextTurnParams = config.nextTurnParams;
48
- }
49
- if (config.requireApproval !== undefined) {
50
- fn.requireApproval = config.requireApproval;
51
- }
52
- return {
53
- type: ToolType.Function,
54
- function: fn,
55
- };
56
- }
57
- // Regular tool (has execute function, no eventSchema)
58
- const functionObj = {
59
- name: config.name,
60
- inputSchema: config.inputSchema,
61
- execute: config.execute,
62
- ...(config.description !== undefined && { description: config.description }),
63
- ...(config.outputSchema !== undefined && { outputSchema: config.outputSchema }),
64
- ...(config.contextSchema !== undefined && { contextSchema: config.contextSchema }),
65
- ...(config.nextTurnParams !== undefined && { nextTurnParams: config.nextTurnParams }),
66
- ...(config.requireApproval !== undefined && { requireApproval: config.requireApproval }),
67
- };
68
- return {
69
- type: ToolType.Function,
70
- function: functionObj,
71
- };
72
- }
73
- //#endregion
74
- //# sourceMappingURL=tool.js.map
@@ -1,52 +0,0 @@
1
- import type { FunctionCallItem } from '../models/functioncallitem.js';
2
- import type { InputsUnion, InputsUnion1 } from '../models/inputsunion.js';
3
- import type { ResponsesRequest } from '../models/responsesrequest.js';
4
- import type { TurnContext } from './tool-types.js';
5
- /**
6
- * Options for building a turn context
7
- */
8
- export interface BuildTurnContextOptions {
9
- /** Number of turns so far (1-indexed for tool execution, 0 for initial request) */
10
- numberOfTurns: number;
11
- /** The specific tool call being executed (optional for initial/async resolution contexts) */
12
- toolCall?: FunctionCallItem;
13
- /** The full request being sent to the API (optional for initial/async resolution contexts) */
14
- turnRequest?: ResponsesRequest;
15
- }
16
- /**
17
- * Build a turn context for tool execution or async parameter resolution
18
- *
19
- * @param options - Options for building the context
20
- * @returns A TurnContext object
21
- *
22
- * @example
23
- * ```typescript
24
- * // For tool execution with full context
25
- * const context = buildTurnContext({
26
- * numberOfTurns: 1,
27
- * toolCall: rawToolCall,
28
- * turnRequest: currentRequest,
29
- * });
30
- *
31
- * // For async parameter resolution (partial context)
32
- * const context = buildTurnContext({
33
- * numberOfTurns: 0,
34
- * });
35
- * ```
36
- */
37
- export declare function buildTurnContext(options: BuildTurnContextOptions): TurnContext;
38
- /**
39
- * Normalize OpenResponsesInput to an array format
40
- * Converts string input to array with single user message
41
- *
42
- * @param input - The input to normalize
43
- * @returns Array format of the input
44
- *
45
- * @example
46
- * ```typescript
47
- * const arrayInput = normalizeInputToArray("Hello!");
48
- * // Returns: [{ role: "user", content: "Hello!" }]
49
- * ```
50
- */
51
- export declare function normalizeInputToArray(input: InputsUnion): Array<InputsUnion1>;
52
- //# sourceMappingURL=turn-context.d.ts.map
@@ -1,59 +0,0 @@
1
- import { EasyInputMessageRoleUser } from '../models/easyinputmessage.js';
2
- /**
3
- * Build a turn context for tool execution or async parameter resolution
4
- *
5
- * @param options - Options for building the context
6
- * @returns A TurnContext object
7
- *
8
- * @example
9
- * ```typescript
10
- * // For tool execution with full context
11
- * const context = buildTurnContext({
12
- * numberOfTurns: 1,
13
- * toolCall: rawToolCall,
14
- * turnRequest: currentRequest,
15
- * });
16
- *
17
- * // For async parameter resolution (partial context)
18
- * const context = buildTurnContext({
19
- * numberOfTurns: 0,
20
- * });
21
- * ```
22
- */
23
- export function buildTurnContext(options) {
24
- const context = {
25
- numberOfTurns: options.numberOfTurns,
26
- };
27
- if (options.toolCall !== undefined) {
28
- context.toolCall = options.toolCall;
29
- }
30
- if (options.turnRequest !== undefined) {
31
- context.turnRequest = options.turnRequest;
32
- }
33
- return context;
34
- }
35
- /**
36
- * Normalize OpenResponsesInput to an array format
37
- * Converts string input to array with single user message
38
- *
39
- * @param input - The input to normalize
40
- * @returns Array format of the input
41
- *
42
- * @example
43
- * ```typescript
44
- * const arrayInput = normalizeInputToArray("Hello!");
45
- * // Returns: [{ role: "user", content: "Hello!" }]
46
- * ```
47
- */
48
- export function normalizeInputToArray(input) {
49
- if (typeof input === 'string') {
50
- // Construct object with all required fields - type is optional
51
- const message = {
52
- role: EasyInputMessageRoleUser.User,
53
- content: input,
54
- };
55
- return [message];
56
- }
57
- return input;
58
- }
59
- //# sourceMappingURL=turn-context.js.map