@truefoundry/trueforge-core 0.0.0 → 0.1.0-rc.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/LICENSE +21 -0
- package/dist/agent-session/ITurnResourceResolver.d.ts +69 -0
- package/dist/agent-session/ITurnResourceResolver.d.ts.map +1 -0
- package/dist/agent-session/ITurnResourceResolver.js +19 -0
- package/dist/agent-session/ITurnResourceResolver.js.map +1 -0
- package/dist/agent-session/ITurnResourceResolver.mjs +1 -0
- package/dist/agent-session/ITurnResourceResolver.mjs.map +1 -0
- package/dist/agent-session/SessionHandle.d.ts +81 -0
- package/dist/agent-session/SessionHandle.d.ts.map +1 -0
- package/dist/agent-session/SessionHandle.js +392 -0
- package/dist/agent-session/SessionHandle.js.map +1 -0
- package/dist/agent-session/SessionHandle.mjs +371 -0
- package/dist/agent-session/SessionHandle.mjs.map +1 -0
- package/dist/agent-session/Sessions.d.ts +25 -0
- package/dist/agent-session/Sessions.d.ts.map +1 -0
- package/dist/agent-session/Sessions.js +71 -0
- package/dist/agent-session/Sessions.js.map +1 -0
- package/dist/agent-session/Sessions.mjs +46 -0
- package/dist/agent-session/Sessions.mjs.map +1 -0
- package/dist/agent-session/TurnHandle.d.ts +88 -0
- package/dist/agent-session/TurnHandle.d.ts.map +1 -0
- package/dist/agent-session/TurnHandle.js +490 -0
- package/dist/agent-session/TurnHandle.js.map +1 -0
- package/dist/agent-session/TurnHandle.mjs +469 -0
- package/dist/agent-session/TurnHandle.mjs.map +1 -0
- package/dist/agent-session/TurnResourceResolver.d.ts +154 -0
- package/dist/agent-session/TurnResourceResolver.d.ts.map +1 -0
- package/dist/agent-session/TurnResourceResolver.js +178 -0
- package/dist/agent-session/TurnResourceResolver.js.map +1 -0
- package/dist/agent-session/TurnResourceResolver.mjs +153 -0
- package/dist/agent-session/TurnResourceResolver.mjs.map +1 -0
- package/dist/agent-session/builtinsFromSpec.d.ts +19 -0
- package/dist/agent-session/builtinsFromSpec.d.ts.map +1 -0
- package/dist/agent-session/builtinsFromSpec.js +73 -0
- package/dist/agent-session/builtinsFromSpec.js.map +1 -0
- package/dist/agent-session/builtinsFromSpec.mjs +48 -0
- package/dist/agent-session/builtinsFromSpec.mjs.map +1 -0
- package/dist/agent-session/index.d.ts +29 -0
- package/dist/agent-session/index.d.ts.map +1 -0
- package/dist/agent-session/index.js +117 -0
- package/dist/agent-session/index.js.map +1 -0
- package/dist/agent-session/index.mjs +84 -0
- package/dist/agent-session/index.mjs.map +1 -0
- package/dist/agent-session/models/SessionRecord.d.ts +34 -0
- package/dist/agent-session/models/SessionRecord.d.ts.map +1 -0
- package/dist/agent-session/models/SessionRecord.js +19 -0
- package/dist/agent-session/models/SessionRecord.js.map +1 -0
- package/dist/agent-session/models/SessionRecord.mjs +1 -0
- package/dist/agent-session/models/SessionRecord.mjs.map +1 -0
- package/dist/agent-session/models/TurnRecord.d.ts +37 -0
- package/dist/agent-session/models/TurnRecord.d.ts.map +1 -0
- package/dist/agent-session/models/TurnRecord.js +31 -0
- package/dist/agent-session/models/TurnRecord.js.map +1 -0
- package/dist/agent-session/models/TurnRecord.mjs +6 -0
- package/dist/agent-session/models/TurnRecord.mjs.map +1 -0
- package/dist/agent-session/schemas/agentSpec.d.ts +142 -0
- package/dist/agent-session/schemas/agentSpec.d.ts.map +1 -0
- package/dist/agent-session/schemas/agentSpec.js +170 -0
- package/dist/agent-session/schemas/agentSpec.js.map +1 -0
- package/dist/agent-session/schemas/agentSpec.mjs +154 -0
- package/dist/agent-session/schemas/agentSpec.mjs.map +1 -0
- package/dist/agent-session/schemas/events.d.ts +1037 -0
- package/dist/agent-session/schemas/events.d.ts.map +1 -0
- package/dist/agent-session/schemas/events.js +80 -0
- package/dist/agent-session/schemas/events.js.map +1 -0
- package/dist/agent-session/schemas/events.mjs +69 -0
- package/dist/agent-session/schemas/events.mjs.map +1 -0
- package/dist/agent-session/schemas/pagination.d.ts +9 -0
- package/dist/agent-session/schemas/pagination.d.ts.map +1 -0
- package/dist/agent-session/schemas/pagination.js +36 -0
- package/dist/agent-session/schemas/pagination.js.map +1 -0
- package/dist/agent-session/schemas/pagination.mjs +11 -0
- package/dist/agent-session/schemas/pagination.mjs.map +1 -0
- package/dist/agent-session/schemas/session.d.ts +319 -0
- package/dist/agent-session/schemas/session.d.ts.map +1 -0
- package/dist/agent-session/schemas/session.js +58 -0
- package/dist/agent-session/schemas/session.js.map +1 -0
- package/dist/agent-session/schemas/session.mjs +30 -0
- package/dist/agent-session/schemas/session.mjs.map +1 -0
- package/dist/agent-session/schemas/turn.d.ts +494 -0
- package/dist/agent-session/schemas/turn.d.ts.map +1 -0
- package/dist/agent-session/schemas/turn.js +131 -0
- package/dist/agent-session/schemas/turn.js.map +1 -0
- package/dist/agent-session/schemas/turn.mjs +102 -0
- package/dist/agent-session/schemas/turn.mjs.map +1 -0
- package/dist/agent-session/store/ISessionStore.d.ts +310 -0
- package/dist/agent-session/store/ISessionStore.d.ts.map +1 -0
- package/dist/agent-session/store/ISessionStore.js +19 -0
- package/dist/agent-session/store/ISessionStore.js.map +1 -0
- package/dist/agent-session/store/ISessionStore.mjs +1 -0
- package/dist/agent-session/store/ISessionStore.mjs.map +1 -0
- package/dist/agent-session/store/InMemorySessionStore.d.ts +55 -0
- package/dist/agent-session/store/InMemorySessionStore.d.ts.map +1 -0
- package/dist/agent-session/store/InMemorySessionStore.js +475 -0
- package/dist/agent-session/store/InMemorySessionStore.js.map +1 -0
- package/dist/agent-session/store/InMemorySessionStore.mjs +461 -0
- package/dist/agent-session/store/InMemorySessionStore.mjs.map +1 -0
- package/dist/agent-session/store/OffsetPageToken.d.ts +13 -0
- package/dist/agent-session/store/OffsetPageToken.d.ts.map +1 -0
- package/dist/agent-session/store/OffsetPageToken.js +60 -0
- package/dist/agent-session/store/OffsetPageToken.js.map +1 -0
- package/dist/agent-session/store/OffsetPageToken.mjs +32 -0
- package/dist/agent-session/store/OffsetPageToken.mjs.map +1 -0
- package/dist/agent-session/store/PageToken.d.ts +4 -0
- package/dist/agent-session/store/PageToken.d.ts.map +1 -0
- package/dist/agent-session/store/PageToken.js +45 -0
- package/dist/agent-session/store/PageToken.js.map +1 -0
- package/dist/agent-session/store/PageToken.mjs +19 -0
- package/dist/agent-session/store/PageToken.mjs.map +1 -0
- package/dist/agent-session/store/SessionEventPageToken.d.ts +14 -0
- package/dist/agent-session/store/SessionEventPageToken.d.ts.map +1 -0
- package/dist/agent-session/store/SessionEventPageToken.js +70 -0
- package/dist/agent-session/store/SessionEventPageToken.js.map +1 -0
- package/dist/agent-session/store/SessionEventPageToken.mjs +42 -0
- package/dist/agent-session/store/SessionEventPageToken.mjs.map +1 -0
- package/dist/agent-session/store/SessionListPageToken.d.ts +24 -0
- package/dist/agent-session/store/SessionListPageToken.d.ts.map +1 -0
- package/dist/agent-session/store/SessionListPageToken.js +66 -0
- package/dist/agent-session/store/SessionListPageToken.js.map +1 -0
- package/dist/agent-session/store/SessionListPageToken.mjs +38 -0
- package/dist/agent-session/store/SessionListPageToken.mjs.map +1 -0
- package/dist/agent-session/store/SessionStoreErrors.d.ts +43 -0
- package/dist/agent-session/store/SessionStoreErrors.d.ts.map +1 -0
- package/dist/agent-session/store/SessionStoreErrors.js +126 -0
- package/dist/agent-session/store/SessionStoreErrors.js.map +1 -0
- package/dist/agent-session/store/SessionStoreErrors.mjs +92 -0
- package/dist/agent-session/store/SessionStoreErrors.mjs.map +1 -0
- package/dist/agent-session/store/assertCreateTurnThreadDelta.d.ts +18 -0
- package/dist/agent-session/store/assertCreateTurnThreadDelta.d.ts.map +1 -0
- package/dist/agent-session/store/assertCreateTurnThreadDelta.js +67 -0
- package/dist/agent-session/store/assertCreateTurnThreadDelta.js.map +1 -0
- package/dist/agent-session/store/assertCreateTurnThreadDelta.mjs +42 -0
- package/dist/agent-session/store/assertCreateTurnThreadDelta.mjs.map +1 -0
- package/dist/core/InstructionBuilder.d.ts +71 -0
- package/dist/core/InstructionBuilder.d.ts.map +1 -0
- package/dist/core/InstructionBuilder.js +95 -0
- package/dist/core/InstructionBuilder.js.map +1 -0
- package/dist/core/InstructionBuilder.mjs +69 -0
- package/dist/core/InstructionBuilder.mjs.map +1 -0
- package/dist/core/capabilities/AgentCapability.d.ts +32 -0
- package/dist/core/capabilities/AgentCapability.d.ts.map +1 -0
- package/dist/core/capabilities/AgentCapability.js +19 -0
- package/dist/core/capabilities/AgentCapability.js.map +1 -0
- package/dist/core/capabilities/AgentCapability.mjs +1 -0
- package/dist/core/capabilities/AgentCapability.mjs.map +1 -0
- package/dist/core/capabilities/AgentContextProcessor.d.ts +30 -0
- package/dist/core/capabilities/AgentContextProcessor.d.ts.map +1 -0
- package/dist/core/capabilities/AgentContextProcessor.js +19 -0
- package/dist/core/capabilities/AgentContextProcessor.js.map +1 -0
- package/dist/core/capabilities/AgentContextProcessor.mjs +1 -0
- package/dist/core/capabilities/AgentContextProcessor.mjs.map +1 -0
- package/dist/core/capabilities/ToolResponseProcessor.d.ts +12 -0
- package/dist/core/capabilities/ToolResponseProcessor.d.ts.map +1 -0
- package/dist/core/capabilities/ToolResponseProcessor.js +19 -0
- package/dist/core/capabilities/ToolResponseProcessor.js.map +1 -0
- package/dist/core/capabilities/ToolResponseProcessor.mjs +1 -0
- package/dist/core/capabilities/ToolResponseProcessor.mjs.map +1 -0
- package/dist/core/capabilities/builtins/AskUserQuestion.d.ts +11 -0
- package/dist/core/capabilities/builtins/AskUserQuestion.d.ts.map +1 -0
- package/dist/core/capabilities/builtins/AskUserQuestion.js +90 -0
- package/dist/core/capabilities/builtins/AskUserQuestion.js.map +1 -0
- package/dist/core/capabilities/builtins/AskUserQuestion.mjs +64 -0
- package/dist/core/capabilities/builtins/AskUserQuestion.mjs.map +1 -0
- package/dist/core/capabilities/builtins/ContextCompaction.d.ts +23 -0
- package/dist/core/capabilities/builtins/ContextCompaction.d.ts.map +1 -0
- package/dist/core/capabilities/builtins/ContextCompaction.js +235 -0
- package/dist/core/capabilities/builtins/ContextCompaction.js.map +1 -0
- package/dist/core/capabilities/builtins/ContextCompaction.mjs +208 -0
- package/dist/core/capabilities/builtins/ContextCompaction.mjs.map +1 -0
- package/dist/core/capabilities/builtins/CurrentDateTime.d.ts +17 -0
- package/dist/core/capabilities/builtins/CurrentDateTime.d.ts.map +1 -0
- package/dist/core/capabilities/builtins/CurrentDateTime.js +75 -0
- package/dist/core/capabilities/builtins/CurrentDateTime.js.map +1 -0
- package/dist/core/capabilities/builtins/CurrentDateTime.mjs +47 -0
- package/dist/core/capabilities/builtins/CurrentDateTime.mjs.map +1 -0
- package/dist/core/capabilities/builtins/DynamicSubAgents.d.ts +39 -0
- package/dist/core/capabilities/builtins/DynamicSubAgents.d.ts.map +1 -0
- package/dist/core/capabilities/builtins/DynamicSubAgents.js +176 -0
- package/dist/core/capabilities/builtins/DynamicSubAgents.js.map +1 -0
- package/dist/core/capabilities/builtins/DynamicSubAgents.mjs +134 -0
- package/dist/core/capabilities/builtins/DynamicSubAgents.mjs.map +1 -0
- package/dist/core/capabilities/builtins/LargeToolResponse.d.ts +40 -0
- package/dist/core/capabilities/builtins/LargeToolResponse.d.ts.map +1 -0
- package/dist/core/capabilities/builtins/LargeToolResponse.js +225 -0
- package/dist/core/capabilities/builtins/LargeToolResponse.js.map +1 -0
- package/dist/core/capabilities/builtins/LargeToolResponse.mjs +186 -0
- package/dist/core/capabilities/builtins/LargeToolResponse.mjs.map +1 -0
- package/dist/core/capabilities/builtins/OpenUI.d.ts +31 -0
- package/dist/core/capabilities/builtins/OpenUI.d.ts.map +1 -0
- package/dist/core/capabilities/builtins/OpenUI.js +376 -0
- package/dist/core/capabilities/builtins/OpenUI.js.map +1 -0
- package/dist/core/capabilities/builtins/OpenUI.mjs +326 -0
- package/dist/core/capabilities/builtins/OpenUI.mjs.map +1 -0
- package/dist/core/errors.d.ts +33 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +88 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/errors.mjs +57 -0
- package/dist/core/errors.mjs.map +1 -0
- package/dist/core/events/PassthroughEvents.d.ts +30 -0
- package/dist/core/events/PassthroughEvents.d.ts.map +1 -0
- package/dist/core/events/PassthroughEvents.js +19 -0
- package/dist/core/events/PassthroughEvents.js.map +1 -0
- package/dist/core/events/PassthroughEvents.mjs +1 -0
- package/dist/core/events/PassthroughEvents.mjs.map +1 -0
- package/dist/core/events/schema.d.ts +1103 -0
- package/dist/core/events/schema.d.ts.map +1 -0
- package/dist/core/events/schema.js +337 -0
- package/dist/core/events/schema.js.map +1 -0
- package/dist/core/events/schema.mjs +283 -0
- package/dist/core/events/schema.mjs.map +1 -0
- package/dist/core/index.d.ts +60 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +209 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/index.mjs +144 -0
- package/dist/core/index.mjs.map +1 -0
- package/dist/core/llm/ILLM.d.ts +15 -0
- package/dist/core/llm/ILLM.d.ts.map +1 -0
- package/dist/core/llm/ILLM.js +19 -0
- package/dist/core/llm/ILLM.js.map +1 -0
- package/dist/core/llm/ILLM.mjs +1 -0
- package/dist/core/llm/ILLM.mjs.map +1 -0
- package/dist/core/llm/LLMTypes.d.ts +369 -0
- package/dist/core/llm/LLMTypes.d.ts.map +1 -0
- package/dist/core/llm/LLMTypes.js +170 -0
- package/dist/core/llm/LLMTypes.js.map +1 -0
- package/dist/core/llm/LLMTypes.mjs +133 -0
- package/dist/core/llm/LLMTypes.mjs.map +1 -0
- package/dist/core/llm/VercelAILLM.d.ts +228 -0
- package/dist/core/llm/VercelAILLM.d.ts.map +1 -0
- package/dist/core/llm/VercelAILLM.js +1042 -0
- package/dist/core/llm/VercelAILLM.js.map +1 -0
- package/dist/core/llm/VercelAILLM.mjs +999 -0
- package/dist/core/llm/VercelAILLM.mjs.map +1 -0
- package/dist/core/llm/openaiSchemas.d.ts +190 -0
- package/dist/core/llm/openaiSchemas.d.ts.map +1 -0
- package/dist/core/llm/openaiSchemas.js +144 -0
- package/dist/core/llm/openaiSchemas.js.map +1 -0
- package/dist/core/llm/openaiSchemas.mjs +107 -0
- package/dist/core/llm/openaiSchemas.mjs.map +1 -0
- package/dist/core/llm/responseFormat.d.ts +25 -0
- package/dist/core/llm/responseFormat.d.ts.map +1 -0
- package/dist/core/llm/responseFormat.js +58 -0
- package/dist/core/llm/responseFormat.js.map +1 -0
- package/dist/core/llm/responseFormat.mjs +32 -0
- package/dist/core/llm/responseFormat.mjs.map +1 -0
- package/dist/core/llm/toOpenAIChatMessage.d.ts +11 -0
- package/dist/core/llm/toOpenAIChatMessage.d.ts.map +1 -0
- package/dist/core/llm/toOpenAIChatMessage.js +95 -0
- package/dist/core/llm/toOpenAIChatMessage.js.map +1 -0
- package/dist/core/llm/toOpenAIChatMessage.mjs +70 -0
- package/dist/core/llm/toOpenAIChatMessage.mjs.map +1 -0
- package/dist/core/llm/usage.d.ts +4 -0
- package/dist/core/llm/usage.d.ts.map +1 -0
- package/dist/core/llm/usage.js +52 -0
- package/dist/core/llm/usage.js.map +1 -0
- package/dist/core/llm/usage.mjs +26 -0
- package/dist/core/llm/usage.mjs.map +1 -0
- package/dist/core/mcp/ClientSideTool.d.ts +10 -0
- package/dist/core/mcp/ClientSideTool.d.ts.map +1 -0
- package/dist/core/mcp/ClientSideTool.js +56 -0
- package/dist/core/mcp/ClientSideTool.js.map +1 -0
- package/dist/core/mcp/ClientSideTool.mjs +31 -0
- package/dist/core/mcp/ClientSideTool.mjs.map +1 -0
- package/dist/core/mcp/IMCPServer.d.ts +78 -0
- package/dist/core/mcp/IMCPServer.d.ts.map +1 -0
- package/dist/core/mcp/IMCPServer.js +63 -0
- package/dist/core/mcp/IMCPServer.js.map +1 -0
- package/dist/core/mcp/IMCPServer.mjs +33 -0
- package/dist/core/mcp/IMCPServer.mjs.map +1 -0
- package/dist/core/mcp/LocalToolMCP.d.ts +39 -0
- package/dist/core/mcp/LocalToolMCP.d.ts.map +1 -0
- package/dist/core/mcp/LocalToolMCP.js +121 -0
- package/dist/core/mcp/LocalToolMCP.js.map +1 -0
- package/dist/core/mcp/LocalToolMCP.mjs +98 -0
- package/dist/core/mcp/LocalToolMCP.mjs.map +1 -0
- package/dist/core/mcp/RemoteMCP.d.ts +67 -0
- package/dist/core/mcp/RemoteMCP.d.ts.map +1 -0
- package/dist/core/mcp/RemoteMCP.js +244 -0
- package/dist/core/mcp/RemoteMCP.js.map +1 -0
- package/dist/core/mcp/RemoteMCP.mjs +222 -0
- package/dist/core/mcp/RemoteMCP.mjs.map +1 -0
- package/dist/core/mcp/ToolSelectorPolicy.d.ts +52 -0
- package/dist/core/mcp/ToolSelectorPolicy.d.ts.map +1 -0
- package/dist/core/mcp/ToolSelectorPolicy.js +108 -0
- package/dist/core/mcp/ToolSelectorPolicy.js.map +1 -0
- package/dist/core/mcp/ToolSelectorPolicy.mjs +90 -0
- package/dist/core/mcp/ToolSelectorPolicy.mjs.map +1 -0
- package/dist/core/mcp/ToolSet.d.ts +31 -0
- package/dist/core/mcp/ToolSet.d.ts.map +1 -0
- package/dist/core/mcp/ToolSet.js +119 -0
- package/dist/core/mcp/ToolSet.js.map +1 -0
- package/dist/core/mcp/ToolSet.mjs +98 -0
- package/dist/core/mcp/ToolSet.mjs.map +1 -0
- package/dist/core/mcp/convertMCPServers.d.ts +22 -0
- package/dist/core/mcp/convertMCPServers.d.ts.map +1 -0
- package/dist/core/mcp/convertMCPServers.js +89 -0
- package/dist/core/mcp/convertMCPServers.js.map +1 -0
- package/dist/core/mcp/convertMCPServers.mjs +64 -0
- package/dist/core/mcp/convertMCPServers.mjs.map +1 -0
- package/dist/core/mcp/executeToolCalls.d.ts +31 -0
- package/dist/core/mcp/executeToolCalls.d.ts.map +1 -0
- package/dist/core/mcp/executeToolCalls.js +168 -0
- package/dist/core/mcp/executeToolCalls.js.map +1 -0
- package/dist/core/mcp/executeToolCalls.mjs +149 -0
- package/dist/core/mcp/executeToolCalls.mjs.map +1 -0
- package/dist/core/mcp/pagination.d.ts +11 -0
- package/dist/core/mcp/pagination.d.ts.map +1 -0
- package/dist/core/mcp/pagination.js +49 -0
- package/dist/core/mcp/pagination.js.map +1 -0
- package/dist/core/mcp/pagination.mjs +24 -0
- package/dist/core/mcp/pagination.mjs.map +1 -0
- package/dist/core/mcp/remoteMcpClient.d.ts +36 -0
- package/dist/core/mcp/remoteMcpClient.d.ts.map +1 -0
- package/dist/core/mcp/remoteMcpClient.js +138 -0
- package/dist/core/mcp/remoteMcpClient.js.map +1 -0
- package/dist/core/mcp/remoteMcpClient.mjs +112 -0
- package/dist/core/mcp/remoteMcpClient.mjs.map +1 -0
- package/dist/core/mcp/toolNames.d.ts +6 -0
- package/dist/core/mcp/toolNames.d.ts.map +1 -0
- package/dist/core/mcp/toolNames.js +59 -0
- package/dist/core/mcp/toolNames.js.map +1 -0
- package/dist/core/mcp/toolNames.mjs +33 -0
- package/dist/core/mcp/toolNames.mjs.map +1 -0
- package/dist/core/mcp/toolSelectors.d.ts +28 -0
- package/dist/core/mcp/toolSelectors.d.ts.map +1 -0
- package/dist/core/mcp/toolSelectors.js +113 -0
- package/dist/core/mcp/toolSelectors.js.map +1 -0
- package/dist/core/mcp/toolSelectors.mjs +78 -0
- package/dist/core/mcp/toolSelectors.mjs.map +1 -0
- package/dist/core/runtime/AgentDefinition.d.ts +23 -0
- package/dist/core/runtime/AgentDefinition.d.ts.map +1 -0
- package/dist/core/runtime/AgentDefinition.js +19 -0
- package/dist/core/runtime/AgentDefinition.js.map +1 -0
- package/dist/core/runtime/AgentDefinition.mjs +1 -0
- package/dist/core/runtime/AgentDefinition.mjs.map +1 -0
- package/dist/core/runtime/AgentThread.d.ts +64 -0
- package/dist/core/runtime/AgentThread.d.ts.map +1 -0
- package/dist/core/runtime/AgentThread.js +1065 -0
- package/dist/core/runtime/AgentThread.js.map +1 -0
- package/dist/core/runtime/AgentThread.mjs +1062 -0
- package/dist/core/runtime/AgentThread.mjs.map +1 -0
- package/dist/core/runtime/AgentThread.types.d.ts +123 -0
- package/dist/core/runtime/AgentThread.types.d.ts.map +1 -0
- package/dist/core/runtime/AgentThread.types.js +46 -0
- package/dist/core/runtime/AgentThread.types.js.map +1 -0
- package/dist/core/runtime/AgentThread.types.mjs +20 -0
- package/dist/core/runtime/AgentThread.types.mjs.map +1 -0
- package/dist/core/runtime/AgentThreadOrchestrator.d.ts +35 -0
- package/dist/core/runtime/AgentThreadOrchestrator.d.ts.map +1 -0
- package/dist/core/runtime/AgentThreadOrchestrator.js +433 -0
- package/dist/core/runtime/AgentThreadOrchestrator.js.map +1 -0
- package/dist/core/runtime/AgentThreadOrchestrator.mjs +418 -0
- package/dist/core/runtime/AgentThreadOrchestrator.mjs.map +1 -0
- package/dist/core/runtime/CreateDynamicSubAgentThread.d.ts +11 -0
- package/dist/core/runtime/CreateDynamicSubAgentThread.d.ts.map +1 -0
- package/dist/core/runtime/CreateDynamicSubAgentThread.js +19 -0
- package/dist/core/runtime/CreateDynamicSubAgentThread.js.map +1 -0
- package/dist/core/runtime/CreateDynamicSubAgentThread.mjs +1 -0
- package/dist/core/runtime/CreateDynamicSubAgentThread.mjs.map +1 -0
- package/dist/core/runtime/DeferredTool.d.ts +34 -0
- package/dist/core/runtime/DeferredTool.d.ts.map +1 -0
- package/dist/core/runtime/DeferredTool.js +321 -0
- package/dist/core/runtime/DeferredTool.js.map +1 -0
- package/dist/core/runtime/DeferredTool.mjs +287 -0
- package/dist/core/runtime/DeferredTool.mjs.map +1 -0
- package/dist/core/runtime/OpenToolCallCloser.d.ts +21 -0
- package/dist/core/runtime/OpenToolCallCloser.d.ts.map +1 -0
- package/dist/core/runtime/OpenToolCallCloser.js +92 -0
- package/dist/core/runtime/OpenToolCallCloser.js.map +1 -0
- package/dist/core/runtime/OpenToolCallCloser.mjs +66 -0
- package/dist/core/runtime/OpenToolCallCloser.mjs.map +1 -0
- package/dist/core/runtime/UserInputMessage.d.ts +16 -0
- package/dist/core/runtime/UserInputMessage.d.ts.map +1 -0
- package/dist/core/runtime/UserInputMessage.js +183 -0
- package/dist/core/runtime/UserInputMessage.js.map +1 -0
- package/dist/core/runtime/UserInputMessage.mjs +157 -0
- package/dist/core/runtime/UserInputMessage.mjs.map +1 -0
- package/dist/core/runtime/contextUsage.d.ts +17 -0
- package/dist/core/runtime/contextUsage.d.ts.map +1 -0
- package/dist/core/runtime/contextUsage.js +56 -0
- package/dist/core/runtime/contextUsage.js.map +1 -0
- package/dist/core/runtime/contextUsage.mjs +28 -0
- package/dist/core/runtime/contextUsage.mjs.map +1 -0
- package/dist/core/runtime/contextUtils.d.ts +30 -0
- package/dist/core/runtime/contextUtils.d.ts.map +1 -0
- package/dist/core/runtime/contextUtils.js +198 -0
- package/dist/core/runtime/contextUtils.js.map +1 -0
- package/dist/core/runtime/contextUtils.mjs +148 -0
- package/dist/core/runtime/contextUtils.mjs.map +1 -0
- package/dist/core/runtime/metrics.d.ts +22 -0
- package/dist/core/runtime/metrics.d.ts.map +1 -0
- package/dist/core/runtime/metrics.js +89 -0
- package/dist/core/runtime/metrics.js.map +1 -0
- package/dist/core/runtime/metrics.mjs +61 -0
- package/dist/core/runtime/metrics.mjs.map +1 -0
- package/dist/core/sandbox/Sandbox.d.ts +121 -0
- package/dist/core/sandbox/Sandbox.d.ts.map +1 -0
- package/dist/core/sandbox/Sandbox.js +572 -0
- package/dist/core/sandbox/Sandbox.js.map +1 -0
- package/dist/core/sandbox/Sandbox.mjs +536 -0
- package/dist/core/sandbox/Sandbox.mjs.map +1 -0
- package/dist/core/sandbox/SandboxErrors.d.ts +30 -0
- package/dist/core/sandbox/SandboxErrors.d.ts.map +1 -0
- package/dist/core/sandbox/SandboxErrors.js +102 -0
- package/dist/core/sandbox/SandboxErrors.js.map +1 -0
- package/dist/core/sandbox/SandboxErrors.mjs +71 -0
- package/dist/core/sandbox/SandboxErrors.mjs.map +1 -0
- package/dist/core/sandbox/SandboxNatsBridge.d.ts +33 -0
- package/dist/core/sandbox/SandboxNatsBridge.d.ts.map +1 -0
- package/dist/core/sandbox/SandboxNatsBridge.js +222 -0
- package/dist/core/sandbox/SandboxNatsBridge.js.map +1 -0
- package/dist/core/sandbox/SandboxNatsBridge.mjs +201 -0
- package/dist/core/sandbox/SandboxNatsBridge.mjs.map +1 -0
- package/dist/core/sandbox/constants.d.ts +10 -0
- package/dist/core/sandbox/constants.d.ts.map +1 -0
- package/dist/core/sandbox/constants.js +37 -0
- package/dist/core/sandbox/constants.js.map +1 -0
- package/dist/core/sandbox/constants.mjs +10 -0
- package/dist/core/sandbox/constants.mjs.map +1 -0
- package/dist/core/sandbox/provider/DaytonaProvider.d.ts +80 -0
- package/dist/core/sandbox/provider/DaytonaProvider.d.ts.map +1 -0
- package/dist/core/sandbox/provider/DaytonaProvider.js +346 -0
- package/dist/core/sandbox/provider/DaytonaProvider.js.map +1 -0
- package/dist/core/sandbox/provider/DaytonaProvider.mjs +326 -0
- package/dist/core/sandbox/provider/DaytonaProvider.mjs.map +1 -0
- package/dist/core/sandbox/provider/Provider.d.ts +83 -0
- package/dist/core/sandbox/provider/Provider.d.ts.map +1 -0
- package/dist/core/sandbox/provider/Provider.js +43 -0
- package/dist/core/sandbox/provider/Provider.js.map +1 -0
- package/dist/core/sandbox/provider/Provider.mjs +17 -0
- package/dist/core/sandbox/provider/Provider.mjs.map +1 -0
- package/dist/core/sandbox/provider/TFYSandboxProvider.d.ts +41 -0
- package/dist/core/sandbox/provider/TFYSandboxProvider.d.ts.map +1 -0
- package/dist/core/sandbox/provider/TFYSandboxProvider.js +180 -0
- package/dist/core/sandbox/provider/TFYSandboxProvider.js.map +1 -0
- package/dist/core/sandbox/provider/TFYSandboxProvider.mjs +147 -0
- package/dist/core/sandbox/provider/TFYSandboxProvider.mjs.map +1 -0
- package/dist/core/sandbox/sandboxImage.d.ts +6 -0
- package/dist/core/sandbox/sandboxImage.d.ts.map +1 -0
- package/dist/core/sandbox/sandboxImage.js +31 -0
- package/dist/core/sandbox/sandboxImage.js.map +1 -0
- package/dist/core/sandbox/sandboxImage.mjs +6 -0
- package/dist/core/sandbox/sandboxImage.mjs.map +1 -0
- package/dist/core/sandbox/sandboxScripts.gen.d.ts +5 -0
- package/dist/core/sandbox/sandboxScripts.gen.d.ts.map +1 -0
- package/dist/core/sandbox/sandboxScripts.gen.js +343 -0
- package/dist/core/sandbox/sandboxScripts.gen.js.map +1 -0
- package/dist/core/sandbox/sandboxScripts.gen.mjs +318 -0
- package/dist/core/sandbox/sandboxScripts.gen.mjs.map +1 -0
- package/dist/core/sandbox/skills/ISkillMounter.d.ts +7 -0
- package/dist/core/sandbox/skills/ISkillMounter.d.ts.map +1 -0
- package/dist/core/sandbox/skills/ISkillMounter.js +19 -0
- package/dist/core/sandbox/skills/ISkillMounter.js.map +1 -0
- package/dist/core/sandbox/skills/ISkillMounter.mjs +1 -0
- package/dist/core/sandbox/skills/ISkillMounter.mjs.map +1 -0
- package/dist/core/sandbox/skills/SkillMounter.d.ts +17 -0
- package/dist/core/sandbox/skills/SkillMounter.d.ts.map +1 -0
- package/dist/core/sandbox/skills/SkillMounter.js +73 -0
- package/dist/core/sandbox/skills/SkillMounter.js.map +1 -0
- package/dist/core/sandbox/skills/SkillMounter.mjs +48 -0
- package/dist/core/sandbox/skills/SkillMounter.mjs.map +1 -0
- package/dist/core/sandbox/skills/constants.d.ts +10 -0
- package/dist/core/sandbox/skills/constants.d.ts.map +1 -0
- package/dist/core/sandbox/skills/constants.js +56 -0
- package/dist/core/sandbox/skills/constants.js.map +1 -0
- package/dist/core/sandbox/skills/constants.mjs +28 -0
- package/dist/core/sandbox/skills/constants.mjs.map +1 -0
- package/dist/core/sandbox/skills/index.d.ts +5 -0
- package/dist/core/sandbox/skills/index.d.ts.map +1 -0
- package/dist/core/sandbox/skills/index.js +40 -0
- package/dist/core/sandbox/skills/index.js.map +1 -0
- package/dist/core/sandbox/skills/index.mjs +11 -0
- package/dist/core/sandbox/skills/index.mjs.map +1 -0
- package/dist/core/tracing/AgentTracing.d.ts +38 -0
- package/dist/core/tracing/AgentTracing.d.ts.map +1 -0
- package/dist/core/tracing/AgentTracing.js +19 -0
- package/dist/core/tracing/AgentTracing.js.map +1 -0
- package/dist/core/tracing/AgentTracing.mjs +1 -0
- package/dist/core/tracing/AgentTracing.mjs.map +1 -0
- package/dist/core/tracing/NoopAgentTracing.d.ts +3 -0
- package/dist/core/tracing/NoopAgentTracing.d.ts.map +1 -0
- package/dist/core/tracing/NoopAgentTracing.js +79 -0
- package/dist/core/tracing/NoopAgentTracing.js.map +1 -0
- package/dist/core/tracing/NoopAgentTracing.mjs +54 -0
- package/dist/core/tracing/NoopAgentTracing.mjs.map +1 -0
- package/dist/core/util/abort.d.ts +2 -0
- package/dist/core/util/abort.d.ts.map +1 -0
- package/dist/core/util/abort.js +38 -0
- package/dist/core/util/abort.js.map +1 -0
- package/dist/core/util/abort.mjs +13 -0
- package/dist/core/util/abort.mjs.map +1 -0
- package/dist/core/util/errorLogFields.d.ts +6 -0
- package/dist/core/util/errorLogFields.d.ts.map +1 -0
- package/dist/core/util/errorLogFields.js +36 -0
- package/dist/core/util/errorLogFields.js.map +1 -0
- package/dist/core/util/errorLogFields.mjs +11 -0
- package/dist/core/util/errorLogFields.mjs.map +1 -0
- package/dist/core/util/promiseUtils.d.ts +7 -0
- package/dist/core/util/promiseUtils.d.ts.map +1 -0
- package/dist/core/util/promiseUtils.js +82 -0
- package/dist/core/util/promiseUtils.js.map +1 -0
- package/dist/core/util/promiseUtils.mjs +55 -0
- package/dist/core/util/promiseUtils.mjs.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +8 -0
- package/dist/index.mjs.map +1 -0
- package/dist/package.json +3 -0
- package/dist/request-reply/client.d.ts +21 -0
- package/dist/request-reply/client.d.ts.map +1 -0
- package/dist/request-reply/client.js +92 -0
- package/dist/request-reply/client.js.map +1 -0
- package/dist/request-reply/client.mjs +67 -0
- package/dist/request-reply/client.mjs.map +1 -0
- package/dist/request-reply/errors.d.ts +23 -0
- package/dist/request-reply/errors.d.ts.map +1 -0
- package/dist/request-reply/errors.js +66 -0
- package/dist/request-reply/errors.js.map +1 -0
- package/dist/request-reply/errors.mjs +39 -0
- package/dist/request-reply/errors.mjs.map +1 -0
- package/dist/request-reply/executor.d.ts +70 -0
- package/dist/request-reply/executor.d.ts.map +1 -0
- package/dist/request-reply/executor.js +267 -0
- package/dist/request-reply/executor.js.map +1 -0
- package/dist/request-reply/executor.mjs +232 -0
- package/dist/request-reply/executor.mjs.map +1 -0
- package/dist/request-reply/index.d.ts +16 -0
- package/dist/request-reply/index.d.ts.map +1 -0
- package/dist/request-reply/index.js +47 -0
- package/dist/request-reply/index.js.map +1 -0
- package/dist/request-reply/index.mjs +16 -0
- package/dist/request-reply/index.mjs.map +1 -0
- package/dist/request-reply/router.d.ts +20 -0
- package/dist/request-reply/router.d.ts.map +1 -0
- package/dist/request-reply/router.js +55 -0
- package/dist/request-reply/router.js.map +1 -0
- package/dist/request-reply/router.mjs +30 -0
- package/dist/request-reply/router.mjs.map +1 -0
- package/dist/request-reply/types.d.ts +25 -0
- package/dist/request-reply/types.d.ts.map +1 -0
- package/dist/request-reply/types.js +54 -0
- package/dist/request-reply/types.js.map +1 -0
- package/dist/request-reply/types.mjs +28 -0
- package/dist/request-reply/types.mjs.map +1 -0
- package/dist/request-reply/utils.d.ts +9 -0
- package/dist/request-reply/utils.d.ts.map +1 -0
- package/dist/request-reply/utils.js +51 -0
- package/dist/request-reply/utils.js.map +1 -0
- package/dist/request-reply/utils.mjs +22 -0
- package/dist/request-reply/utils.mjs.map +1 -0
- package/package.json +127 -6
- package/README.md +0 -4
- package/index.js +0 -1
|
@@ -0,0 +1,999 @@
|
|
|
1
|
+
// src/core/llm/VercelAILLM.ts
|
|
2
|
+
import { createAlibaba } from "@ai-sdk/alibaba";
|
|
3
|
+
import { createAnthropic } from "@ai-sdk/anthropic";
|
|
4
|
+
import { createGoogle } from "@ai-sdk/google";
|
|
5
|
+
import { createMoonshotAI } from "@ai-sdk/moonshotai";
|
|
6
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
7
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
8
|
+
import { APICallError, jsonSchema, Output, streamText } from "ai";
|
|
9
|
+
import { extractErrorLogFields } from "../util/errorLogFields.mjs";
|
|
10
|
+
import {
|
|
11
|
+
getEmptyUsage
|
|
12
|
+
} from "./LLMTypes.mjs";
|
|
13
|
+
var VERCEL_AI_PROVIDER_NAMES = [
|
|
14
|
+
"openai",
|
|
15
|
+
"anthropic",
|
|
16
|
+
"google-gemini",
|
|
17
|
+
"fireworks",
|
|
18
|
+
"zai",
|
|
19
|
+
"moonshot",
|
|
20
|
+
"alibaba",
|
|
21
|
+
"together",
|
|
22
|
+
"custom"
|
|
23
|
+
];
|
|
24
|
+
function isPlainObject(v) {
|
|
25
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
26
|
+
}
|
|
27
|
+
function isFunctionTool(tool) {
|
|
28
|
+
return tool.type === "function";
|
|
29
|
+
}
|
|
30
|
+
function isFunctionToolCall(toolCall) {
|
|
31
|
+
return toolCall.type === "function";
|
|
32
|
+
}
|
|
33
|
+
function compatibleModel(config) {
|
|
34
|
+
const { provider, model, apiKey, headers, baseUrl } = config;
|
|
35
|
+
if (baseUrl === void 0) {
|
|
36
|
+
throw new Error(`Provider "${provider.type}" requires a baseUrl`);
|
|
37
|
+
}
|
|
38
|
+
const client = createOpenAICompatible({
|
|
39
|
+
name: provider.type,
|
|
40
|
+
baseURL: baseUrl,
|
|
41
|
+
apiKey,
|
|
42
|
+
// Without this the adapter silently downgrades json_schema to a schema-less json_object.
|
|
43
|
+
supportsStructuredOutputs: true,
|
|
44
|
+
// These endpoints omit token counts from streamed responses unless asked.
|
|
45
|
+
includeUsage: true,
|
|
46
|
+
...Object.keys(headers).length > 0 ? { headers } : {}
|
|
47
|
+
});
|
|
48
|
+
return client(model.id);
|
|
49
|
+
}
|
|
50
|
+
function buildLanguageModel(config) {
|
|
51
|
+
const { provider, model, baseUrl, apiKey, headers } = config;
|
|
52
|
+
const extraHeaders = Object.keys(headers).length > 0 ? headers : void 0;
|
|
53
|
+
switch (provider.type) {
|
|
54
|
+
case "openai": {
|
|
55
|
+
const client = createOpenAI({
|
|
56
|
+
apiKey,
|
|
57
|
+
...baseUrl !== void 0 ? { baseURL: baseUrl } : {},
|
|
58
|
+
...extraHeaders !== void 0 ? { headers: extraHeaders } : {}
|
|
59
|
+
});
|
|
60
|
+
return client.responses(model.id);
|
|
61
|
+
}
|
|
62
|
+
case "anthropic": {
|
|
63
|
+
const client = createAnthropic({
|
|
64
|
+
apiKey,
|
|
65
|
+
...baseUrl !== void 0 ? { baseURL: baseUrl } : {},
|
|
66
|
+
...extraHeaders !== void 0 ? { headers: extraHeaders } : {}
|
|
67
|
+
});
|
|
68
|
+
return client(model.id);
|
|
69
|
+
}
|
|
70
|
+
case "google-gemini": {
|
|
71
|
+
const client = createGoogle({
|
|
72
|
+
apiKey,
|
|
73
|
+
...baseUrl !== void 0 ? { baseURL: baseUrl } : {},
|
|
74
|
+
...extraHeaders !== void 0 ? { headers: extraHeaders } : {}
|
|
75
|
+
});
|
|
76
|
+
return client(model.id);
|
|
77
|
+
}
|
|
78
|
+
case "moonshot": {
|
|
79
|
+
const client = createMoonshotAI({
|
|
80
|
+
apiKey,
|
|
81
|
+
...baseUrl !== void 0 ? { baseURL: baseUrl } : {},
|
|
82
|
+
...extraHeaders !== void 0 ? { headers: extraHeaders } : {}
|
|
83
|
+
});
|
|
84
|
+
return client(model.id);
|
|
85
|
+
}
|
|
86
|
+
case "alibaba": {
|
|
87
|
+
if (baseUrl === void 0) {
|
|
88
|
+
throw new Error(`Provider "alibaba" requires a baseUrl`);
|
|
89
|
+
}
|
|
90
|
+
const client = createAlibaba({
|
|
91
|
+
apiKey,
|
|
92
|
+
baseURL: baseUrl,
|
|
93
|
+
...extraHeaders !== void 0 ? { headers: extraHeaders } : {}
|
|
94
|
+
});
|
|
95
|
+
return client(model.id);
|
|
96
|
+
}
|
|
97
|
+
case "fireworks":
|
|
98
|
+
case "zai":
|
|
99
|
+
case "together":
|
|
100
|
+
case "custom": {
|
|
101
|
+
return compatibleModel(config);
|
|
102
|
+
}
|
|
103
|
+
default: {
|
|
104
|
+
const _exhaustive = provider.type;
|
|
105
|
+
throw new Error(`Unknown provider "${String(_exhaustive)}"`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
var COMMON_REASONING_LEVELS = [
|
|
110
|
+
"none",
|
|
111
|
+
"minimal",
|
|
112
|
+
"low",
|
|
113
|
+
"medium",
|
|
114
|
+
"high",
|
|
115
|
+
"xhigh"
|
|
116
|
+
];
|
|
117
|
+
var VERCEL_AI_REASONING_LEVELS = [
|
|
118
|
+
"provider-default",
|
|
119
|
+
...COMMON_REASONING_LEVELS
|
|
120
|
+
];
|
|
121
|
+
function isReasoningLevel(v) {
|
|
122
|
+
return VERCEL_AI_REASONING_LEVELS.some((level) => level === v);
|
|
123
|
+
}
|
|
124
|
+
var EFFORT_ALIASES = { max: "xhigh" };
|
|
125
|
+
var SUPPORTED_REASONING_EFFORTS = [...COMMON_REASONING_LEVELS, "max"];
|
|
126
|
+
function toReasoningLevel(reasoningEffort) {
|
|
127
|
+
if (reasoningEffort === void 0) {
|
|
128
|
+
return void 0;
|
|
129
|
+
}
|
|
130
|
+
const aliased = EFFORT_ALIASES[reasoningEffort];
|
|
131
|
+
if (aliased !== void 0) {
|
|
132
|
+
return aliased;
|
|
133
|
+
}
|
|
134
|
+
return isReasoningLevel(reasoningEffort) ? reasoningEffort : void 0;
|
|
135
|
+
}
|
|
136
|
+
function maxEffortOption(reasoningEffort) {
|
|
137
|
+
return reasoningEffort === "max" ? { reasoningEffort: "max" } : {};
|
|
138
|
+
}
|
|
139
|
+
function toStructuredOutputSpec(responseFormat) {
|
|
140
|
+
if (responseFormat === void 0 || responseFormat.type === "text") {
|
|
141
|
+
return { mode: "text" };
|
|
142
|
+
}
|
|
143
|
+
if (responseFormat.type === "json_object") {
|
|
144
|
+
return { mode: "json" };
|
|
145
|
+
}
|
|
146
|
+
const { json_schema } = responseFormat;
|
|
147
|
+
return {
|
|
148
|
+
mode: "json_schema",
|
|
149
|
+
schema: json_schema.schema ?? { type: "object", properties: {} },
|
|
150
|
+
name: json_schema.name,
|
|
151
|
+
description: json_schema.description,
|
|
152
|
+
strict: json_schema.strict ?? void 0
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function buildOutput(spec) {
|
|
156
|
+
switch (spec.mode) {
|
|
157
|
+
case "text":
|
|
158
|
+
return void 0;
|
|
159
|
+
case "json":
|
|
160
|
+
return Output.json();
|
|
161
|
+
case "json_schema":
|
|
162
|
+
return Output.object({
|
|
163
|
+
schema: jsonSchema(spec.schema),
|
|
164
|
+
name: spec.name,
|
|
165
|
+
...spec.description !== void 0 ? { description: spec.description } : {}
|
|
166
|
+
});
|
|
167
|
+
default: {
|
|
168
|
+
const _exhaustive = spec;
|
|
169
|
+
throw new Error(`Unknown structured output mode: ${JSON.stringify(_exhaustive)}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function readBodyField({ rawBody, key }) {
|
|
174
|
+
const val = Reflect.get(Object(rawBody), key);
|
|
175
|
+
return val !== void 0 ? val : void 0;
|
|
176
|
+
}
|
|
177
|
+
function openaiProviderOptions({
|
|
178
|
+
rawBody,
|
|
179
|
+
strictJsonSchema,
|
|
180
|
+
reasoningEffort
|
|
181
|
+
}) {
|
|
182
|
+
const serviceTier = readBodyField({ rawBody, key: "service_tier" });
|
|
183
|
+
const user = readBodyField({ rawBody, key: "user" });
|
|
184
|
+
const promptCacheKey = readBodyField({ rawBody, key: "prompt_cache_key" });
|
|
185
|
+
const parallelToolCalls = readBodyField({ rawBody, key: "parallel_tool_calls" });
|
|
186
|
+
const reasoningSummary = readBodyField({ rawBody, key: "reasoning_summary" });
|
|
187
|
+
return {
|
|
188
|
+
store: false,
|
|
189
|
+
include: ["reasoning.encrypted_content"],
|
|
190
|
+
reasoningSummary: "auto",
|
|
191
|
+
// gpt-5.6 serves both xhigh and max, so the aliased top-level level asks for one rung less.
|
|
192
|
+
...maxEffortOption(reasoningEffort),
|
|
193
|
+
...reasoningSummary !== void 0 ? { reasoningSummary } : {},
|
|
194
|
+
...strictJsonSchema !== void 0 ? { strictJsonSchema } : {},
|
|
195
|
+
...serviceTier !== void 0 ? { serviceTier } : {},
|
|
196
|
+
...user !== void 0 ? { user } : {},
|
|
197
|
+
...promptCacheKey !== void 0 ? { promptCacheKey } : {},
|
|
198
|
+
...parallelToolCalls !== void 0 ? { parallelToolCalls } : {}
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function anthropicProviderOptions(rawBody) {
|
|
202
|
+
const cacheControl = readBodyField({ rawBody, key: "cache_control" }) ?? { type: "ephemeral" };
|
|
203
|
+
const disableParallelToolUse = readBodyField({ rawBody, key: "disable_parallel_tool_use" });
|
|
204
|
+
const thinking = readBodyField({ rawBody, key: "thinking" });
|
|
205
|
+
const effort = readBodyField({ rawBody, key: "effort" });
|
|
206
|
+
const opts = {
|
|
207
|
+
cacheControl,
|
|
208
|
+
...disableParallelToolUse !== void 0 ? { disableParallelToolUse } : {},
|
|
209
|
+
...thinking !== void 0 ? { thinking } : {},
|
|
210
|
+
...effort !== void 0 ? { effort } : {}
|
|
211
|
+
};
|
|
212
|
+
return opts;
|
|
213
|
+
}
|
|
214
|
+
function googleGeminiThinkingConfig({
|
|
215
|
+
rawBody,
|
|
216
|
+
reasoningRequested
|
|
217
|
+
}) {
|
|
218
|
+
const fromBody = readBodyField({ rawBody, key: "thinking_config" });
|
|
219
|
+
if (!reasoningRequested) {
|
|
220
|
+
return fromBody;
|
|
221
|
+
}
|
|
222
|
+
if (typeof fromBody === "object" && fromBody !== null && !Array.isArray(fromBody)) {
|
|
223
|
+
return { includeThoughts: true, ...fromBody };
|
|
224
|
+
}
|
|
225
|
+
return { includeThoughts: true };
|
|
226
|
+
}
|
|
227
|
+
function googleGeminiProviderOptions({
|
|
228
|
+
rawBody,
|
|
229
|
+
reasoningRequested
|
|
230
|
+
}) {
|
|
231
|
+
const safetySettings = readBodyField({ rawBody, key: "safety_settings" });
|
|
232
|
+
const thinkingConfig = googleGeminiThinkingConfig({ rawBody, reasoningRequested });
|
|
233
|
+
const cachedContent = readBodyField({ rawBody, key: "cached_content" });
|
|
234
|
+
const opts = {
|
|
235
|
+
...safetySettings !== void 0 ? { safetySettings } : {},
|
|
236
|
+
...thinkingConfig !== void 0 ? { thinkingConfig } : {},
|
|
237
|
+
...cachedContent !== void 0 ? { cachedContent } : {}
|
|
238
|
+
};
|
|
239
|
+
return Object.keys(opts).length > 0 ? opts : void 0;
|
|
240
|
+
}
|
|
241
|
+
function moonshotProviderOptions({
|
|
242
|
+
rawBody,
|
|
243
|
+
reasoningEffort
|
|
244
|
+
}) {
|
|
245
|
+
const thinking = readBodyField({ rawBody, key: "thinking" });
|
|
246
|
+
const reasoningHistory = readBodyField({ rawBody, key: "reasoning_history" });
|
|
247
|
+
const opts = {
|
|
248
|
+
// Moonshot's own ceiling is `max`; the aliased `xhigh` is not one of its levels.
|
|
249
|
+
...maxEffortOption(reasoningEffort),
|
|
250
|
+
...thinking !== void 0 ? { thinking } : {},
|
|
251
|
+
...reasoningHistory !== void 0 ? { reasoningHistory } : {}
|
|
252
|
+
};
|
|
253
|
+
return Object.keys(opts).length > 0 ? opts : void 0;
|
|
254
|
+
}
|
|
255
|
+
function alibabaProviderOptions(rawBody) {
|
|
256
|
+
const enableThinking = readBodyField({ rawBody, key: "enable_thinking" });
|
|
257
|
+
const thinkingBudget = readBodyField({ rawBody, key: "thinking_budget" });
|
|
258
|
+
const parallelToolCalls = readBodyField({ rawBody, key: "parallel_tool_calls" });
|
|
259
|
+
const opts = {
|
|
260
|
+
...enableThinking !== void 0 ? { enableThinking } : {},
|
|
261
|
+
...thinkingBudget !== void 0 ? { thinkingBudget } : {},
|
|
262
|
+
...parallelToolCalls !== void 0 ? { parallelToolCalls } : {}
|
|
263
|
+
};
|
|
264
|
+
return Object.keys(opts).length > 0 ? opts : void 0;
|
|
265
|
+
}
|
|
266
|
+
var COMPATIBLE_BODY_FIELDS = [
|
|
267
|
+
"service_tier",
|
|
268
|
+
"user",
|
|
269
|
+
"prompt_cache_key",
|
|
270
|
+
"parallel_tool_calls",
|
|
271
|
+
"thinking",
|
|
272
|
+
"thinking_budget",
|
|
273
|
+
"enable_thinking",
|
|
274
|
+
"reasoning_history"
|
|
275
|
+
];
|
|
276
|
+
function compatibleProviderOptions({
|
|
277
|
+
strictJsonSchema,
|
|
278
|
+
reasoningEffort,
|
|
279
|
+
rawBody
|
|
280
|
+
}) {
|
|
281
|
+
const forwarded = Object.fromEntries(
|
|
282
|
+
COMPATIBLE_BODY_FIELDS.flatMap((key) => {
|
|
283
|
+
const value = readBodyField({ rawBody, key });
|
|
284
|
+
return value === void 0 ? [] : [[key, value]];
|
|
285
|
+
})
|
|
286
|
+
);
|
|
287
|
+
const opts = {
|
|
288
|
+
// These endpoints discard an effort they do not recognise, and `xhigh` is one of those.
|
|
289
|
+
...maxEffortOption(reasoningEffort),
|
|
290
|
+
...forwarded,
|
|
291
|
+
...strictJsonSchema !== void 0 ? { strictJsonSchema } : {}
|
|
292
|
+
};
|
|
293
|
+
return Object.keys(opts).length > 0 ? opts : void 0;
|
|
294
|
+
}
|
|
295
|
+
function buildProviderOptions({
|
|
296
|
+
config,
|
|
297
|
+
reasoningEffort,
|
|
298
|
+
structuredOutputSpec,
|
|
299
|
+
rawBody
|
|
300
|
+
}) {
|
|
301
|
+
const strictJsonSchema = structuredOutputSpec.mode === "json_schema" ? structuredOutputSpec.strict : void 0;
|
|
302
|
+
if (config.provider.type === "openai") {
|
|
303
|
+
return { openai: openaiProviderOptions({ rawBody, strictJsonSchema, reasoningEffort }) };
|
|
304
|
+
} else if (config.provider.type === "anthropic") {
|
|
305
|
+
const anthropic = anthropicProviderOptions(rawBody);
|
|
306
|
+
return anthropic !== void 0 ? { anthropic } : {};
|
|
307
|
+
} else if (config.provider.type === "google-gemini") {
|
|
308
|
+
const google = googleGeminiProviderOptions({ rawBody, reasoningRequested: reasoningEffort !== void 0 });
|
|
309
|
+
return google !== void 0 ? { google } : {};
|
|
310
|
+
} else if (config.provider.type === "moonshot") {
|
|
311
|
+
const moonshotai = moonshotProviderOptions({ rawBody, reasoningEffort });
|
|
312
|
+
return moonshotai !== void 0 ? { moonshotai } : {};
|
|
313
|
+
} else if (config.provider.type === "alibaba") {
|
|
314
|
+
const alibaba = alibabaProviderOptions(rawBody);
|
|
315
|
+
return alibaba !== void 0 ? { alibaba } : {};
|
|
316
|
+
} else {
|
|
317
|
+
const compatible = compatibleProviderOptions({ strictJsonSchema, reasoningEffort, rawBody });
|
|
318
|
+
return compatible !== void 0 ? { [config.provider.type]: compatible } : {};
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
function resolveMaxOutputTokens(body) {
|
|
322
|
+
const limit = body.max_completion_tokens ?? Reflect.get(body, "max_tokens");
|
|
323
|
+
return typeof limit === "number" ? limit : void 0;
|
|
324
|
+
}
|
|
325
|
+
function parseMimeFromDataUri(uri) {
|
|
326
|
+
const match = /^data:([^;,]+)/.exec(uri);
|
|
327
|
+
return match?.[1];
|
|
328
|
+
}
|
|
329
|
+
function toFilePart(file) {
|
|
330
|
+
const { file_data, filename } = file;
|
|
331
|
+
if (!file_data) return void 0;
|
|
332
|
+
const mediaType = parseMimeFromDataUri(file_data) ?? "application/octet-stream";
|
|
333
|
+
return {
|
|
334
|
+
type: "file",
|
|
335
|
+
data: file_data,
|
|
336
|
+
mediaType,
|
|
337
|
+
...filename !== void 0 ? { filename } : {}
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
function toUserContent(content) {
|
|
341
|
+
if (typeof content === "string") {
|
|
342
|
+
return content;
|
|
343
|
+
}
|
|
344
|
+
const parts = [];
|
|
345
|
+
for (const part of content) {
|
|
346
|
+
if (part.type === "text") {
|
|
347
|
+
parts.push({ type: "text", text: part.text });
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
if (part.type === "image_url") {
|
|
351
|
+
const url = part.image_url.url;
|
|
352
|
+
const mediaType = parseMimeFromDataUri(url) ?? "image/*";
|
|
353
|
+
parts.push({ type: "file", data: url, mediaType });
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
if (part.type === "file") {
|
|
357
|
+
const filePart = toFilePart(part.file);
|
|
358
|
+
if (filePart !== void 0) {
|
|
359
|
+
parts.push(filePart);
|
|
360
|
+
}
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return parts;
|
|
365
|
+
}
|
|
366
|
+
function toAssistantModelMessage({
|
|
367
|
+
msg,
|
|
368
|
+
provider,
|
|
369
|
+
providerName,
|
|
370
|
+
logger
|
|
371
|
+
}) {
|
|
372
|
+
const parts = [];
|
|
373
|
+
const rawThinking = Reflect.get(msg, "thinking_blocks");
|
|
374
|
+
const attachSignature = shouldAttachReasoningSignature({
|
|
375
|
+
source: Reflect.get(msg, "source"),
|
|
376
|
+
provider,
|
|
377
|
+
providerName,
|
|
378
|
+
logger
|
|
379
|
+
});
|
|
380
|
+
if (Array.isArray(rawThinking) && provider !== "alibaba") {
|
|
381
|
+
const blocks = rawThinking;
|
|
382
|
+
for (const tb of blocks) {
|
|
383
|
+
if (typeof tb === "object" && tb !== null && "type" in tb && "thinking" in tb && tb.type === "thinking" && typeof tb.thinking === "string") {
|
|
384
|
+
const signature = "signature" in tb && typeof tb.signature === "string" ? tb.signature : void 0;
|
|
385
|
+
let reasoningProviderOptions;
|
|
386
|
+
if (signature !== void 0 && attachSignature) {
|
|
387
|
+
if (provider === "openai") {
|
|
388
|
+
reasoningProviderOptions = { openai: { reasoningEncryptedContent: signature } };
|
|
389
|
+
} else if (provider === "anthropic") {
|
|
390
|
+
reasoningProviderOptions = { anthropic: { signature } };
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
const reasoningPart = {
|
|
394
|
+
type: "reasoning",
|
|
395
|
+
text: tb.thinking,
|
|
396
|
+
...reasoningProviderOptions !== void 0 ? { providerOptions: reasoningProviderOptions } : {}
|
|
397
|
+
};
|
|
398
|
+
parts.push(reasoningPart);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
const rawContent = msg.content;
|
|
403
|
+
if (rawContent) {
|
|
404
|
+
const text = typeof rawContent === "string" ? rawContent : rawContent.filter((p) => p.type === "text").map((p) => p.text).join("");
|
|
405
|
+
if (text) {
|
|
406
|
+
const textPart = { type: "text", text };
|
|
407
|
+
parts.push(textPart);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (msg.tool_calls?.length) {
|
|
411
|
+
for (const tc of msg.tool_calls) {
|
|
412
|
+
if (!isFunctionToolCall(tc)) {
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
let input = {};
|
|
416
|
+
try {
|
|
417
|
+
const parsed = JSON.parse(tc.function.arguments);
|
|
418
|
+
if (isPlainObject(parsed)) {
|
|
419
|
+
input = parsed;
|
|
420
|
+
}
|
|
421
|
+
} catch {
|
|
422
|
+
}
|
|
423
|
+
const rawProviderFields = Reflect.get(tc, "provider_specific_fields");
|
|
424
|
+
const thoughtSignature = isPlainObject(rawProviderFields) && typeof rawProviderFields["thought_signature"] === "string" ? rawProviderFields["thought_signature"] : void 0;
|
|
425
|
+
const toolCallPart = {
|
|
426
|
+
type: "tool-call",
|
|
427
|
+
toolCallId: tc.id,
|
|
428
|
+
toolName: tc.function.name,
|
|
429
|
+
input,
|
|
430
|
+
...thoughtSignature !== void 0 ? { providerOptions: { google: { thoughtSignature } } } : {}
|
|
431
|
+
};
|
|
432
|
+
parts.push(toolCallPart);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return {
|
|
436
|
+
role: "assistant",
|
|
437
|
+
content: parts.length > 0 ? parts : [{ type: "text", text: "" }]
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
function parseAssistantMessageSource(source) {
|
|
441
|
+
const [providerType, providerName, modelName, ...rest] = source.split("/");
|
|
442
|
+
if (rest.length > 0 || !providerType || !providerName || !modelName) {
|
|
443
|
+
return void 0;
|
|
444
|
+
}
|
|
445
|
+
return { providerType, providerName, modelName };
|
|
446
|
+
}
|
|
447
|
+
function shouldAttachReasoningSignature({
|
|
448
|
+
source,
|
|
449
|
+
provider,
|
|
450
|
+
providerName,
|
|
451
|
+
logger
|
|
452
|
+
}) {
|
|
453
|
+
if (source === void 0) {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
if (typeof source !== "string") {
|
|
457
|
+
logger?.warn("Ignoring non-string assistant message source; skipping reasoning signature replay", { source });
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
const parsed = parseAssistantMessageSource(source);
|
|
461
|
+
if (parsed === void 0) {
|
|
462
|
+
logger?.warn("Ignoring malformed assistant message source; skipping reasoning signature replay", { source });
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
return parsed.providerType === provider && parsed.providerName === providerName;
|
|
466
|
+
}
|
|
467
|
+
function convertMessages({
|
|
468
|
+
messages,
|
|
469
|
+
provider,
|
|
470
|
+
providerName,
|
|
471
|
+
logger
|
|
472
|
+
}) {
|
|
473
|
+
const toolNameById = /* @__PURE__ */ new Map();
|
|
474
|
+
for (const msg of messages) {
|
|
475
|
+
if (msg.role === "assistant" && msg.tool_calls) {
|
|
476
|
+
for (const tc of msg.tool_calls) {
|
|
477
|
+
if (!isFunctionToolCall(tc)) {
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
toolNameById.set(tc.id, tc.function.name);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
const systemParts = [];
|
|
485
|
+
const result = [];
|
|
486
|
+
for (const msg of messages) {
|
|
487
|
+
if (msg.role === "system") {
|
|
488
|
+
const content = typeof msg.content === "string" ? msg.content : msg.content.map((p) => p.text).join("");
|
|
489
|
+
systemParts.push(content);
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
if (msg.role === "user") {
|
|
493
|
+
result.push({ role: "user", content: toUserContent(msg.content) });
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
if (msg.role === "assistant") {
|
|
497
|
+
result.push(toAssistantModelMessage({ msg, provider, providerName, logger }));
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
if (msg.role === "tool") {
|
|
501
|
+
const toolName = toolNameById.get(msg.tool_call_id) ?? "";
|
|
502
|
+
const toolContent = [
|
|
503
|
+
{
|
|
504
|
+
type: "tool-result",
|
|
505
|
+
toolCallId: msg.tool_call_id,
|
|
506
|
+
toolName,
|
|
507
|
+
output: {
|
|
508
|
+
type: "text",
|
|
509
|
+
value: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
];
|
|
513
|
+
result.push({ role: "tool", content: toolContent });
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return { instructions: systemParts.length > 0 ? systemParts.join("\n\n") : void 0, messages: result };
|
|
518
|
+
}
|
|
519
|
+
function convertTools(tools) {
|
|
520
|
+
if (!tools?.length) {
|
|
521
|
+
return void 0;
|
|
522
|
+
}
|
|
523
|
+
const toolSet = {};
|
|
524
|
+
for (const t of tools) {
|
|
525
|
+
if (!isFunctionTool(t)) {
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
toolSet[t.function.name] = {
|
|
529
|
+
inputSchema: jsonSchema(t.function.parameters ?? { type: "object", properties: {} }),
|
|
530
|
+
...t.function.description !== void 0 ? { description: t.function.description } : {}
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
return Object.keys(toolSet).length > 0 ? toolSet : void 0;
|
|
534
|
+
}
|
|
535
|
+
function buildStreamTextArgs(input) {
|
|
536
|
+
const {
|
|
537
|
+
model,
|
|
538
|
+
instructions,
|
|
539
|
+
messages,
|
|
540
|
+
tools,
|
|
541
|
+
reasoning,
|
|
542
|
+
providerOptions,
|
|
543
|
+
maxOutputTokens,
|
|
544
|
+
temperature,
|
|
545
|
+
topP,
|
|
546
|
+
topK,
|
|
547
|
+
presencePenalty,
|
|
548
|
+
frequencyPenalty,
|
|
549
|
+
stopSequences,
|
|
550
|
+
seed,
|
|
551
|
+
abortSignal
|
|
552
|
+
} = input;
|
|
553
|
+
return {
|
|
554
|
+
model,
|
|
555
|
+
...instructions !== void 0 ? { instructions } : {},
|
|
556
|
+
messages,
|
|
557
|
+
...tools !== void 0 ? { tools } : {},
|
|
558
|
+
...reasoning !== void 0 ? { reasoning } : {},
|
|
559
|
+
...maxOutputTokens !== void 0 ? { maxOutputTokens } : {},
|
|
560
|
+
...temperature != null ? { temperature } : {},
|
|
561
|
+
...topP != null ? { topP } : {},
|
|
562
|
+
...topK != null ? { topK } : {},
|
|
563
|
+
...presencePenalty != null ? { presencePenalty } : {},
|
|
564
|
+
...frequencyPenalty != null ? { frequencyPenalty } : {},
|
|
565
|
+
...stopSequences != null ? { stopSequences } : {},
|
|
566
|
+
...seed != null ? { seed } : {},
|
|
567
|
+
...Object.keys(providerOptions).length > 0 ? { providerOptions } : {},
|
|
568
|
+
...abortSignal !== void 0 ? { abortSignal } : {},
|
|
569
|
+
maxRetries: 0
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
function normalizeUsage(usage) {
|
|
573
|
+
const input = usage.inputTokens ?? 0;
|
|
574
|
+
const output = usage.outputTokens ?? 0;
|
|
575
|
+
const costInUsd = usage.raw?.["costInUSD"];
|
|
576
|
+
return {
|
|
577
|
+
input_tokens: input,
|
|
578
|
+
output_tokens: output,
|
|
579
|
+
total_tokens: input + output,
|
|
580
|
+
cache_read_tokens: usage.inputTokenDetails.cacheReadTokens ?? void 0,
|
|
581
|
+
cache_write_tokens: usage.inputTokenDetails.cacheWriteTokens ?? void 0,
|
|
582
|
+
reasoning_tokens: usage.outputTokenDetails.reasoningTokens ?? void 0,
|
|
583
|
+
cost_in_usd: typeof costInUsd === "number" && costInUsd >= 0 ? costInUsd : void 0
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
function describeStreamError(raw) {
|
|
587
|
+
if (APICallError.isInstance(raw)) {
|
|
588
|
+
if (raw.statusCode != null) {
|
|
589
|
+
return `Request failed (${String(raw.statusCode)}): ${raw.message}`;
|
|
590
|
+
}
|
|
591
|
+
return raw.message;
|
|
592
|
+
}
|
|
593
|
+
if (typeof raw !== "object" || raw === null) {
|
|
594
|
+
return String(raw);
|
|
595
|
+
}
|
|
596
|
+
const message = Reflect.get(raw, "message");
|
|
597
|
+
if (typeof message === "string" && message.length > 0) {
|
|
598
|
+
return message;
|
|
599
|
+
}
|
|
600
|
+
try {
|
|
601
|
+
return JSON.stringify(raw);
|
|
602
|
+
} catch {
|
|
603
|
+
return `unserialisable provider error (${Object.keys(raw).join(", ")})`;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
function mapFinishReason(reason) {
|
|
607
|
+
switch (reason) {
|
|
608
|
+
case "stop":
|
|
609
|
+
return "stop";
|
|
610
|
+
case "length":
|
|
611
|
+
return "length";
|
|
612
|
+
case "tool-calls":
|
|
613
|
+
return "tool_calls";
|
|
614
|
+
case "content-filter":
|
|
615
|
+
return "content_filter";
|
|
616
|
+
// No harness equivalent for these — fall back to 'stop'.
|
|
617
|
+
case "error":
|
|
618
|
+
case "other":
|
|
619
|
+
return "stop";
|
|
620
|
+
default: {
|
|
621
|
+
const _exhaustive = reason;
|
|
622
|
+
throw new Error(`Unknown finish reason: ${String(_exhaustive)}`);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
function applyReasoningSignature({
|
|
627
|
+
block,
|
|
628
|
+
providerMetadata
|
|
629
|
+
}) {
|
|
630
|
+
if (providerMetadata === void 0) {
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
for (const meta of Object.values(providerMetadata)) {
|
|
634
|
+
if ("reasoningEncryptedContent" in meta && typeof meta["reasoningEncryptedContent"] === "string") {
|
|
635
|
+
block.signature = meta["reasoningEncryptedContent"];
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if ("signature" in meta && typeof meta["signature"] === "string") {
|
|
639
|
+
block.signature = meta["signature"];
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
function reasoningItemId(providerMetadata) {
|
|
645
|
+
if (providerMetadata === void 0) {
|
|
646
|
+
return void 0;
|
|
647
|
+
}
|
|
648
|
+
for (const meta of Object.values(providerMetadata)) {
|
|
649
|
+
if ("itemId" in meta && typeof meta["itemId"] === "string") {
|
|
650
|
+
return meta["itemId"];
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return void 0;
|
|
654
|
+
}
|
|
655
|
+
function describeCallWarning(warning) {
|
|
656
|
+
switch (warning.type) {
|
|
657
|
+
case "unsupported":
|
|
658
|
+
case "compatibility":
|
|
659
|
+
return warning.details !== void 0 ? `${warning.type}: ${warning.feature} (${warning.details})` : `${warning.type}: ${warning.feature}`;
|
|
660
|
+
case "deprecated":
|
|
661
|
+
return `deprecated: ${warning.setting} - ${warning.message}`;
|
|
662
|
+
case "other":
|
|
663
|
+
return `other: ${warning.message}`;
|
|
664
|
+
default: {
|
|
665
|
+
const _exhaustive = warning;
|
|
666
|
+
throw new Error(`Unknown call warning: ${JSON.stringify(_exhaustive)}`);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
async function* mapStreamToChunks({
|
|
671
|
+
stream,
|
|
672
|
+
chunkMeta
|
|
673
|
+
}) {
|
|
674
|
+
const makeBase = () => ({
|
|
675
|
+
id: chunkMeta.id,
|
|
676
|
+
object: "chat.completion.chunk",
|
|
677
|
+
created: chunkMeta.created,
|
|
678
|
+
model: chunkMeta.model
|
|
679
|
+
});
|
|
680
|
+
const toolCallStates = /* @__PURE__ */ new Map();
|
|
681
|
+
let nextToolIndex = 0;
|
|
682
|
+
let accumulatedText = "";
|
|
683
|
+
const accumulatedThinking = [];
|
|
684
|
+
const thinkingByReasoningItem = /* @__PURE__ */ new Map();
|
|
685
|
+
let currentThinkingBlock = null;
|
|
686
|
+
const openThinkingBlock = (providerMetadata) => {
|
|
687
|
+
const itemId = reasoningItemId(providerMetadata);
|
|
688
|
+
const started = itemId !== void 0 ? thinkingByReasoningItem.get(itemId) : void 0;
|
|
689
|
+
if (started !== void 0) {
|
|
690
|
+
if (started.thinking.length > 0) {
|
|
691
|
+
started.thinking += "\n\n";
|
|
692
|
+
}
|
|
693
|
+
return started;
|
|
694
|
+
}
|
|
695
|
+
const block = { type: "thinking", thinking: "" };
|
|
696
|
+
accumulatedThinking.push(block);
|
|
697
|
+
if (itemId !== void 0) {
|
|
698
|
+
thinkingByReasoningItem.set(itemId, block);
|
|
699
|
+
}
|
|
700
|
+
return block;
|
|
701
|
+
};
|
|
702
|
+
let finalUsage = getEmptyUsage();
|
|
703
|
+
let finalFinishReason = "stop";
|
|
704
|
+
for await (const part of stream) {
|
|
705
|
+
switch (part.type) {
|
|
706
|
+
case "text-delta": {
|
|
707
|
+
accumulatedText += part.text;
|
|
708
|
+
yield {
|
|
709
|
+
...makeBase(),
|
|
710
|
+
choices: [
|
|
711
|
+
{
|
|
712
|
+
index: 0,
|
|
713
|
+
delta: { content: part.text, role: "assistant" },
|
|
714
|
+
finish_reason: null,
|
|
715
|
+
logprobs: null
|
|
716
|
+
}
|
|
717
|
+
]
|
|
718
|
+
};
|
|
719
|
+
break;
|
|
720
|
+
}
|
|
721
|
+
case "reasoning-start": {
|
|
722
|
+
currentThinkingBlock = openThinkingBlock(part.providerMetadata);
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
case "reasoning-delta": {
|
|
726
|
+
currentThinkingBlock ??= openThinkingBlock(part.providerMetadata);
|
|
727
|
+
currentThinkingBlock.thinking += part.text;
|
|
728
|
+
applyReasoningSignature({ block: currentThinkingBlock, providerMetadata: part.providerMetadata });
|
|
729
|
+
yield {
|
|
730
|
+
...makeBase(),
|
|
731
|
+
choices: [
|
|
732
|
+
{
|
|
733
|
+
index: 0,
|
|
734
|
+
delta: {
|
|
735
|
+
thinking_blocks: [{ type: "thinking", thinking: part.text }],
|
|
736
|
+
reasoning_content: part.text
|
|
737
|
+
},
|
|
738
|
+
finish_reason: null,
|
|
739
|
+
logprobs: null
|
|
740
|
+
}
|
|
741
|
+
]
|
|
742
|
+
};
|
|
743
|
+
break;
|
|
744
|
+
}
|
|
745
|
+
case "reasoning-end": {
|
|
746
|
+
if (currentThinkingBlock !== null) {
|
|
747
|
+
applyReasoningSignature({ block: currentThinkingBlock, providerMetadata: part.providerMetadata });
|
|
748
|
+
}
|
|
749
|
+
currentThinkingBlock = null;
|
|
750
|
+
break;
|
|
751
|
+
}
|
|
752
|
+
case "tool-input-start": {
|
|
753
|
+
const idx = nextToolIndex++;
|
|
754
|
+
const googleMeta = part.providerMetadata?.["google"];
|
|
755
|
+
const thoughtSignature = googleMeta !== void 0 && typeof googleMeta["thoughtSignature"] === "string" ? googleMeta["thoughtSignature"] : void 0;
|
|
756
|
+
toolCallStates.set(part.id, {
|
|
757
|
+
index: idx,
|
|
758
|
+
id: part.id,
|
|
759
|
+
name: part.toolName,
|
|
760
|
+
arguments: "",
|
|
761
|
+
thoughtSignature
|
|
762
|
+
});
|
|
763
|
+
yield {
|
|
764
|
+
...makeBase(),
|
|
765
|
+
choices: [
|
|
766
|
+
{
|
|
767
|
+
index: 0,
|
|
768
|
+
delta: {
|
|
769
|
+
tool_calls: [
|
|
770
|
+
{
|
|
771
|
+
index: idx,
|
|
772
|
+
id: part.id,
|
|
773
|
+
type: "function",
|
|
774
|
+
function: { name: part.toolName, arguments: "" }
|
|
775
|
+
}
|
|
776
|
+
]
|
|
777
|
+
},
|
|
778
|
+
finish_reason: null,
|
|
779
|
+
logprobs: null
|
|
780
|
+
}
|
|
781
|
+
]
|
|
782
|
+
};
|
|
783
|
+
break;
|
|
784
|
+
}
|
|
785
|
+
case "tool-input-delta": {
|
|
786
|
+
const state = toolCallStates.get(part.id);
|
|
787
|
+
if (state === void 0) {
|
|
788
|
+
break;
|
|
789
|
+
}
|
|
790
|
+
state.arguments += part.delta;
|
|
791
|
+
yield {
|
|
792
|
+
...makeBase(),
|
|
793
|
+
choices: [
|
|
794
|
+
{
|
|
795
|
+
index: 0,
|
|
796
|
+
delta: {
|
|
797
|
+
tool_calls: [{ index: state.index, function: { arguments: part.delta } }]
|
|
798
|
+
},
|
|
799
|
+
finish_reason: null,
|
|
800
|
+
logprobs: null
|
|
801
|
+
}
|
|
802
|
+
]
|
|
803
|
+
};
|
|
804
|
+
break;
|
|
805
|
+
}
|
|
806
|
+
case "finish-step": {
|
|
807
|
+
finalUsage = normalizeUsage(part.usage);
|
|
808
|
+
finalFinishReason = mapFinishReason(part.finishReason);
|
|
809
|
+
yield {
|
|
810
|
+
...makeBase(),
|
|
811
|
+
choices: [
|
|
812
|
+
{
|
|
813
|
+
index: 0,
|
|
814
|
+
delta: {},
|
|
815
|
+
finish_reason: finalFinishReason,
|
|
816
|
+
logprobs: null
|
|
817
|
+
}
|
|
818
|
+
],
|
|
819
|
+
usage: finalUsage
|
|
820
|
+
};
|
|
821
|
+
break;
|
|
822
|
+
}
|
|
823
|
+
case "error": {
|
|
824
|
+
const raw = part.error;
|
|
825
|
+
const message = describeStreamError(raw);
|
|
826
|
+
const cause = raw instanceof Error ? raw : new Error(message);
|
|
827
|
+
throw new Error(message, { cause });
|
|
828
|
+
}
|
|
829
|
+
case "abort": {
|
|
830
|
+
const aborted = new Error("LLM stream aborted");
|
|
831
|
+
aborted.name = "AbortError";
|
|
832
|
+
throw aborted;
|
|
833
|
+
}
|
|
834
|
+
case "start":
|
|
835
|
+
case "text-start":
|
|
836
|
+
case "text-end":
|
|
837
|
+
case "custom":
|
|
838
|
+
case "tool-input-end":
|
|
839
|
+
case "source":
|
|
840
|
+
case "file":
|
|
841
|
+
case "reasoning-file":
|
|
842
|
+
case "tool-call":
|
|
843
|
+
case "tool-result":
|
|
844
|
+
case "tool-error":
|
|
845
|
+
case "tool-output-denied":
|
|
846
|
+
case "tool-approval-request":
|
|
847
|
+
case "tool-approval-response":
|
|
848
|
+
case "start-step":
|
|
849
|
+
case "finish":
|
|
850
|
+
case "raw":
|
|
851
|
+
break;
|
|
852
|
+
default: {
|
|
853
|
+
const _exhaustive = part;
|
|
854
|
+
throw new Error(`Unknown stream part type: ${JSON.stringify(_exhaustive)}`);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
const toolCalls = [...toolCallStates.values()].sort((a, b) => a.index - b.index).map((tc) => ({
|
|
859
|
+
id: tc.id,
|
|
860
|
+
type: "function",
|
|
861
|
+
function: { name: tc.name, arguments: tc.arguments },
|
|
862
|
+
...tc.thoughtSignature !== void 0 ? { provider_specific_fields: { thought_signature: tc.thoughtSignature } } : {}
|
|
863
|
+
}));
|
|
864
|
+
const output = {
|
|
865
|
+
role: "assistant",
|
|
866
|
+
content: accumulatedText || null,
|
|
867
|
+
...accumulatedThinking.length > 0 ? { thinking_blocks: accumulatedThinking } : {},
|
|
868
|
+
...toolCalls.length > 0 ? { tool_calls: toolCalls } : {}
|
|
869
|
+
};
|
|
870
|
+
return { usage: finalUsage, output, finish_reason: finalFinishReason };
|
|
871
|
+
}
|
|
872
|
+
var VercelAILLM = class {
|
|
873
|
+
config;
|
|
874
|
+
logger;
|
|
875
|
+
signal;
|
|
876
|
+
constructor(config) {
|
|
877
|
+
this.config = config;
|
|
878
|
+
this.logger = config.logger;
|
|
879
|
+
this.signal = config.signal;
|
|
880
|
+
}
|
|
881
|
+
async *create(body) {
|
|
882
|
+
const { providerConfig } = this.config;
|
|
883
|
+
const languageModel = buildLanguageModel(providerConfig);
|
|
884
|
+
const { provider, model } = providerConfig;
|
|
885
|
+
const { instructions, messages } = convertMessages({
|
|
886
|
+
messages: body.messages,
|
|
887
|
+
provider: provider.type,
|
|
888
|
+
providerName: provider.name,
|
|
889
|
+
logger: this.logger
|
|
890
|
+
});
|
|
891
|
+
const tools = convertTools(body.tools ?? void 0);
|
|
892
|
+
const structuredOutputSpec = toStructuredOutputSpec(body.response_format);
|
|
893
|
+
const output = buildOutput(structuredOutputSpec);
|
|
894
|
+
const rawReasoningEffort = Reflect.get(body, "reasoning_effort");
|
|
895
|
+
const reasoningEffort = typeof rawReasoningEffort === "string" ? rawReasoningEffort : void 0;
|
|
896
|
+
const providerOptions = buildProviderOptions({
|
|
897
|
+
config: providerConfig,
|
|
898
|
+
reasoningEffort,
|
|
899
|
+
structuredOutputSpec,
|
|
900
|
+
rawBody: body
|
|
901
|
+
});
|
|
902
|
+
const reasoning = toReasoningLevel(reasoningEffort);
|
|
903
|
+
const rawTopK = Reflect.get(body, "top_k");
|
|
904
|
+
const rawSeed = Reflect.get(body, "seed");
|
|
905
|
+
const streamTextArgs = buildStreamTextArgs({
|
|
906
|
+
model: languageModel,
|
|
907
|
+
instructions,
|
|
908
|
+
messages,
|
|
909
|
+
tools,
|
|
910
|
+
reasoning,
|
|
911
|
+
providerOptions,
|
|
912
|
+
maxOutputTokens: resolveMaxOutputTokens(body),
|
|
913
|
+
temperature: body.temperature,
|
|
914
|
+
topP: body.top_p,
|
|
915
|
+
topK: typeof rawTopK === "number" ? rawTopK : null,
|
|
916
|
+
presencePenalty: body.presence_penalty,
|
|
917
|
+
frequencyPenalty: body.frequency_penalty,
|
|
918
|
+
stopSequences: typeof body.stop === "string" ? [body.stop] : body.stop ?? null,
|
|
919
|
+
seed: typeof rawSeed === "number" ? rawSeed : null,
|
|
920
|
+
abortSignal: this.signal
|
|
921
|
+
});
|
|
922
|
+
let streamResult;
|
|
923
|
+
try {
|
|
924
|
+
streamResult = streamText({
|
|
925
|
+
...streamTextArgs,
|
|
926
|
+
...output !== void 0 ? { output } : {}
|
|
927
|
+
});
|
|
928
|
+
} catch (error) {
|
|
929
|
+
if (this.signal?.aborted) {
|
|
930
|
+
this.logger.debug("LLM call aborted", extractErrorLogFields(error));
|
|
931
|
+
} else {
|
|
932
|
+
this.logger.error("Error creating streaming chat completion", extractErrorLogFields(error));
|
|
933
|
+
}
|
|
934
|
+
throw error;
|
|
935
|
+
}
|
|
936
|
+
void streamResult.warnings.then(
|
|
937
|
+
(warnings) => {
|
|
938
|
+
if (warnings !== void 0 && warnings.length > 0) {
|
|
939
|
+
this.logger.warn("Provider adjusted the request", {
|
|
940
|
+
model: providerConfig.name,
|
|
941
|
+
warnings: warnings.map(describeCallWarning)
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
},
|
|
945
|
+
(reason) => {
|
|
946
|
+
this.logger.debug("Provider warnings unavailable", extractErrorLogFields(reason));
|
|
947
|
+
}
|
|
948
|
+
);
|
|
949
|
+
const chunkMeta = {
|
|
950
|
+
id: `vc-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`,
|
|
951
|
+
created: Math.floor(Date.now() / 1e3),
|
|
952
|
+
model: providerConfig.name
|
|
953
|
+
};
|
|
954
|
+
try {
|
|
955
|
+
const result = yield* mapStreamToChunks({ stream: streamResult.stream, chunkMeta });
|
|
956
|
+
result.output.source = `${provider.type}/${provider.name}/${model.name}`;
|
|
957
|
+
return result;
|
|
958
|
+
} catch (error) {
|
|
959
|
+
if (this.signal?.aborted) {
|
|
960
|
+
this.logger.debug("LLM stream aborted", extractErrorLogFields(error));
|
|
961
|
+
} else {
|
|
962
|
+
this.logger.error("Error reading LLM stream", extractErrorLogFields(error));
|
|
963
|
+
}
|
|
964
|
+
throw error;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
async createNonStream(body) {
|
|
968
|
+
const llmStream = this.create({ ...body, stream: true });
|
|
969
|
+
let result = await llmStream.next();
|
|
970
|
+
while (!result.done) {
|
|
971
|
+
result = await llmStream.next();
|
|
972
|
+
}
|
|
973
|
+
return result.value;
|
|
974
|
+
}
|
|
975
|
+
};
|
|
976
|
+
export {
|
|
977
|
+
SUPPORTED_REASONING_EFFORTS,
|
|
978
|
+
VERCEL_AI_PROVIDER_NAMES,
|
|
979
|
+
VercelAILLM,
|
|
980
|
+
buildLanguageModel,
|
|
981
|
+
buildProviderOptions,
|
|
982
|
+
buildStreamTextArgs,
|
|
983
|
+
convertMessages,
|
|
984
|
+
convertTools,
|
|
985
|
+
describeCallWarning,
|
|
986
|
+
describeStreamError,
|
|
987
|
+
mapFinishReason,
|
|
988
|
+
mapStreamToChunks,
|
|
989
|
+
normalizeUsage,
|
|
990
|
+
parseMimeFromDataUri,
|
|
991
|
+
resolveMaxOutputTokens,
|
|
992
|
+
shouldAttachReasoningSignature,
|
|
993
|
+
toAssistantModelMessage,
|
|
994
|
+
toFilePart,
|
|
995
|
+
toReasoningLevel,
|
|
996
|
+
toStructuredOutputSpec,
|
|
997
|
+
toUserContent
|
|
998
|
+
};
|
|
999
|
+
//# sourceMappingURL=VercelAILLM.mjs.map
|