@openrouter/sdk 0.3.2 → 0.3.10
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/.zed/settings.json +10 -0
- package/_speakeasy/.github/action-inputs-config.json +53 -0
- package/_speakeasy/.github/action-security-config.json +88 -0
- package/esm/core.js +1 -0
- package/esm/funcs/analyticsGetUserActivity.js +1 -0
- package/esm/funcs/apiKeysCreate.js +1 -0
- package/esm/funcs/apiKeysDelete.js +1 -0
- package/esm/funcs/apiKeysGet.js +1 -0
- package/esm/funcs/apiKeysGetCurrentKeyMetadata.js +1 -0
- package/esm/funcs/apiKeysList.js +1 -0
- package/esm/funcs/apiKeysUpdate.js +1 -0
- package/esm/funcs/betaResponsesSend.js +1 -0
- package/esm/funcs/call-model.d.ts +118 -0
- package/esm/funcs/call-model.js +137 -0
- package/esm/funcs/chatSend.js +1 -0
- package/esm/funcs/completionsGenerate.js +1 -0
- package/esm/funcs/creditsCreateCoinbaseCharge.js +1 -0
- package/esm/funcs/creditsGetCredits.js +1 -0
- package/esm/funcs/embeddingsGenerate.js +1 -0
- package/esm/funcs/embeddingsListModels.js +1 -0
- package/esm/funcs/endpointsList.js +1 -0
- package/esm/funcs/endpointsListZdrEndpoints.js +1 -0
- package/esm/funcs/generationsGetGeneration.js +1 -0
- package/esm/funcs/modelsCount.js +1 -0
- package/esm/funcs/modelsList.js +1 -0
- package/esm/funcs/modelsListForUser.js +1 -0
- package/esm/funcs/oAuthCreateAuthCode.js +1 -0
- package/esm/funcs/oAuthExchangeAuthCodeForAPIKey.js +1 -0
- package/esm/funcs/parametersGetParameters.js +1 -0
- package/esm/funcs/providersList.js +1 -0
- package/esm/hooks/hooks.js +1 -0
- package/esm/hooks/index.js +1 -0
- package/esm/hooks/types.js +1 -0
- package/esm/index.d.ts +20 -5
- package/esm/index.js +21 -4
- package/esm/lib/anthropic-compat.d.ts +50 -0
- package/esm/lib/anthropic-compat.js +223 -0
- package/esm/lib/anthropic-compat.test.d.ts +2 -0
- package/esm/lib/anthropic-compat.test.js +479 -0
- package/esm/lib/async-params.d.ts +53 -0
- package/esm/lib/async-params.js +76 -0
- package/esm/lib/base64.js +1 -0
- package/esm/lib/chat-compat.d.ts +46 -0
- package/esm/lib/chat-compat.js +112 -0
- package/esm/lib/chat-compat.test.d.ts +2 -0
- package/esm/lib/chat-compat.test.js +282 -0
- package/esm/lib/claude-constants.d.ts +22 -0
- package/esm/lib/claude-constants.js +20 -0
- package/esm/lib/claude-type-guards.d.ts +10 -0
- package/esm/lib/claude-type-guards.js +70 -0
- package/esm/lib/config.d.ts +2 -2
- package/esm/lib/config.js +3 -2
- package/esm/lib/dlv.js +1 -0
- package/esm/lib/encodings.js +1 -0
- package/esm/lib/env.js +1 -0
- package/esm/lib/event-streams.js +1 -0
- package/esm/lib/files.js +1 -0
- package/esm/lib/http.js +1 -0
- package/esm/lib/is-plain-object.js +1 -0
- package/esm/lib/logger.js +1 -0
- package/esm/lib/matchers.js +1 -0
- package/esm/lib/{response-wrapper.d.ts → model-result.d.ts} +29 -43
- package/esm/lib/{response-wrapper.js → model-result.js} +146 -175
- package/esm/lib/next-turn-params.d.ts +30 -0
- package/esm/lib/next-turn-params.js +129 -0
- package/esm/lib/primitives.js +1 -0
- package/esm/lib/retries.js +1 -0
- package/esm/lib/reusable-stream.js +10 -10
- package/esm/lib/schemas.js +1 -0
- package/esm/lib/sdks.js +1 -0
- package/esm/lib/security.js +1 -0
- package/esm/lib/stop-conditions.d.ts +80 -0
- package/esm/lib/stop-conditions.js +104 -0
- package/esm/lib/stream-transformers.d.ts +30 -4
- package/esm/lib/stream-transformers.js +467 -98
- package/esm/lib/stream-type-guards.d.ts +29 -0
- package/esm/lib/stream-type-guards.js +109 -0
- package/esm/lib/tool-executor.d.ts +7 -6
- package/esm/lib/tool-executor.js +4 -0
- package/esm/lib/tool-orchestrator.d.ts +7 -7
- package/esm/lib/tool-orchestrator.js +38 -10
- package/esm/lib/tool-types.d.ts +163 -29
- package/esm/lib/tool-types.js +6 -0
- package/esm/lib/tool.d.ts +99 -0
- package/esm/lib/tool.js +71 -0
- package/esm/lib/turn-context.d.ts +50 -0
- package/esm/lib/turn-context.js +59 -0
- package/esm/lib/url.js +1 -0
- package/esm/models/activityitem.js +1 -0
- package/esm/models/assistantmessage.js +1 -0
- package/esm/models/badgatewayresponseerrordata.js +1 -0
- package/esm/models/badrequestresponseerrordata.js +1 -0
- package/esm/models/chatcompletionfinishreason.js +1 -0
- package/esm/models/chaterror.js +1 -0
- package/esm/models/chatgenerationparams.js +1 -0
- package/esm/models/chatgenerationtokenusage.js +1 -0
- package/esm/models/chatmessagecontentitem.js +1 -0
- package/esm/models/chatmessagecontentitemaudio.js +1 -0
- package/esm/models/chatmessagecontentitemcachecontrol.js +1 -0
- package/esm/models/chatmessagecontentitemimage.js +1 -0
- package/esm/models/chatmessagecontentitemtext.js +1 -0
- package/esm/models/chatmessagecontentitemvideo.js +1 -0
- package/esm/models/chatmessagetokenlogprob.js +1 -0
- package/esm/models/chatmessagetokenlogprobs.js +1 -0
- package/esm/models/chatmessagetoolcall.js +1 -0
- package/esm/models/chatresponse.js +1 -0
- package/esm/models/chatresponsechoice.js +1 -0
- package/esm/models/chatstreamingchoice.js +1 -0
- package/esm/models/chatstreamingmessagechunk.js +1 -0
- package/esm/models/chatstreamingmessagetoolcall.js +1 -0
- package/esm/models/chatstreamingresponsechunk.js +1 -0
- package/esm/models/chatstreamoptions.js +1 -0
- package/esm/models/claude-message.d.ts +218 -0
- package/esm/models/claude-message.js +6 -0
- package/esm/models/completionchoice.js +1 -0
- package/esm/models/completioncreateparams.js +1 -0
- package/esm/models/completionlogprobs.js +1 -0
- package/esm/models/completionresponse.js +1 -0
- package/esm/models/completionusage.js +1 -0
- package/esm/models/createchargerequest.js +1 -0
- package/esm/models/datacollection.js +1 -0
- package/esm/models/defaultparameters.js +1 -0
- package/esm/models/edgenetworktimeoutresponseerrordata.js +1 -0
- package/esm/models/endpointstatus.js +1 -0
- package/esm/models/errors/badgatewayresponseerror.js +1 -0
- package/esm/models/errors/badrequestresponseerror.js +1 -0
- package/esm/models/errors/chaterror.js +1 -0
- package/esm/models/errors/edgenetworktimeoutresponseerror.js +1 -0
- package/esm/models/errors/forbiddenresponseerror.js +1 -0
- package/esm/models/errors/httpclienterrors.js +1 -0
- package/esm/models/errors/index.js +1 -0
- package/esm/models/errors/internalserverresponseerror.js +1 -0
- package/esm/models/errors/notfoundresponseerror.js +1 -0
- package/esm/models/errors/openrouterdefaulterror.js +1 -0
- package/esm/models/errors/openroutererror.js +1 -0
- package/esm/models/errors/payloadtoolargeresponseerror.js +1 -0
- package/esm/models/errors/paymentrequiredresponseerror.js +1 -0
- package/esm/models/errors/provideroverloadedresponseerror.js +1 -0
- package/esm/models/errors/requesttimeoutresponseerror.js +1 -0
- package/esm/models/errors/responsevalidationerror.js +1 -0
- package/esm/models/errors/sdkvalidationerror.js +1 -0
- package/esm/models/errors/serviceunavailableresponseerror.js +1 -0
- package/esm/models/errors/toomanyrequestsresponseerror.js +1 -0
- package/esm/models/errors/unauthorizedresponseerror.js +1 -0
- package/esm/models/errors/unprocessableentityresponseerror.js +1 -0
- package/esm/models/filecitation.js +1 -0
- package/esm/models/filepath.js +1 -0
- package/esm/models/forbiddenresponseerrordata.js +1 -0
- package/esm/models/imagegenerationstatus.js +1 -0
- package/esm/models/index.d.ts +1 -0
- package/esm/models/index.js +2 -0
- package/esm/models/inputmodality.js +1 -0
- package/esm/models/instructtype.js +1 -0
- package/esm/models/internalserverresponseerrordata.js +1 -0
- package/esm/models/jsonschemaconfig.js +1 -0
- package/esm/models/listendpointsresponse.js +1 -0
- package/esm/models/message.js +1 -0
- package/esm/models/model.js +1 -0
- package/esm/models/modelarchitecture.js +1 -0
- package/esm/models/modelgroup.js +1 -0
- package/esm/models/modelscountresponse.js +1 -0
- package/esm/models/modelslistresponse.js +1 -0
- package/esm/models/namedtoolchoice.js +1 -0
- package/esm/models/notfoundresponseerrordata.js +1 -0
- package/esm/models/openairesponsesannotation.js +1 -0
- package/esm/models/openairesponsesincludable.js +1 -0
- package/esm/models/openairesponsesincompletedetails.js +1 -0
- package/esm/models/openairesponsesinputunion.js +1 -0
- package/esm/models/openairesponsesprompt.js +1 -0
- package/esm/models/openairesponsesreasoningconfig.js +1 -0
- package/esm/models/openairesponsesreasoningeffort.js +1 -0
- package/esm/models/openairesponsesrefusalcontent.js +1 -0
- package/esm/models/openairesponsesresponsestatus.js +1 -0
- package/esm/models/openairesponsesservicetier.js +1 -0
- package/esm/models/openairesponsestoolchoiceunion.js +1 -0
- package/esm/models/openairesponsestruncation.js +1 -0
- package/esm/models/openresponseseasyinputmessage.js +1 -0
- package/esm/models/openresponseserrorevent.js +1 -0
- package/esm/models/openresponsesfunctioncalloutput.js +1 -0
- package/esm/models/openresponsesfunctiontoolcall.js +1 -0
- package/esm/models/openresponsesimagegencallcompleted.js +1 -0
- package/esm/models/openresponsesimagegencallgenerating.js +1 -0
- package/esm/models/openresponsesimagegencallinprogress.js +1 -0
- package/esm/models/openresponsesimagegencallpartialimage.js +1 -0
- package/esm/models/openresponsesinput.js +1 -0
- package/esm/models/openresponsesinputmessageitem.js +1 -0
- package/esm/models/openresponseslogprobs.js +1 -0
- package/esm/models/openresponsesnonstreamingresponse.js +1 -0
- package/esm/models/openresponsesreasoning.js +1 -0
- package/esm/models/openresponsesreasoningconfig.js +1 -0
- package/esm/models/openresponsesreasoningdeltaevent.js +1 -0
- package/esm/models/openresponsesreasoningdoneevent.js +1 -0
- package/esm/models/openresponsesreasoningsummarypartaddedevent.js +1 -0
- package/esm/models/openresponsesreasoningsummarytextdeltaevent.js +1 -0
- package/esm/models/openresponsesreasoningsummarytextdoneevent.js +1 -0
- package/esm/models/openresponsesrequest.js +1 -0
- package/esm/models/openresponsesresponsetext.js +1 -0
- package/esm/models/openresponsesstreamevent.js +1 -0
- package/esm/models/openresponsestoplogprobs.js +1 -0
- package/esm/models/openresponsesusage.js +1 -0
- package/esm/models/openresponseswebsearch20250826tool.js +1 -0
- package/esm/models/openresponseswebsearchpreview20250311tool.js +1 -0
- package/esm/models/openresponseswebsearchpreviewtool.js +1 -0
- package/esm/models/openresponseswebsearchtool.js +1 -0
- package/esm/models/operations/createauthkeyscode.js +1 -0
- package/esm/models/operations/createcoinbasecharge.js +1 -0
- package/esm/models/operations/createembeddings.js +1 -0
- package/esm/models/operations/createkeys.js +1 -0
- package/esm/models/operations/createresponses.js +1 -0
- package/esm/models/operations/deletekeys.js +1 -0
- package/esm/models/operations/exchangeauthcodeforapikey.js +1 -0
- package/esm/models/operations/getcredits.js +1 -0
- package/esm/models/operations/getcurrentkey.js +1 -0
- package/esm/models/operations/getgeneration.js +1 -0
- package/esm/models/operations/getkey.js +1 -0
- package/esm/models/operations/getmodels.js +1 -0
- package/esm/models/operations/getparameters.js +1 -0
- package/esm/models/operations/getuseractivity.js +1 -0
- package/esm/models/operations/index.js +1 -0
- package/esm/models/operations/list.js +1 -0
- package/esm/models/operations/listendpoints.js +1 -0
- package/esm/models/operations/listendpointszdr.js +1 -0
- package/esm/models/operations/listmodelsuser.js +1 -0
- package/esm/models/operations/listproviders.js +1 -0
- package/esm/models/operations/sendchatcompletionrequest.js +1 -0
- package/esm/models/operations/updatekeys.js +1 -0
- package/esm/models/outputitemimagegenerationcall.js +1 -0
- package/esm/models/outputmessage.js +1 -0
- package/esm/models/outputmodality.js +1 -0
- package/esm/models/parameter.js +1 -0
- package/esm/models/payloadtoolargeresponseerrordata.js +1 -0
- package/esm/models/paymentrequiredresponseerrordata.js +1 -0
- package/esm/models/pdfparserengine.js +1 -0
- package/esm/models/pdfparseroptions.js +1 -0
- package/esm/models/perrequestlimits.js +1 -0
- package/esm/models/providername.js +1 -0
- package/esm/models/provideroverloadedresponseerrordata.js +1 -0
- package/esm/models/providerpreferences.js +1 -0
- package/esm/models/providersort.js +1 -0
- package/esm/models/providersortconfig.js +1 -0
- package/esm/models/providersortunion.js +1 -0
- package/esm/models/publicendpoint.js +1 -0
- package/esm/models/publicpricing.js +1 -0
- package/esm/models/quantization.js +1 -0
- package/esm/models/reasoningsummarytext.js +1 -0
- package/esm/models/reasoningsummaryverbosity.js +1 -0
- package/esm/models/reasoningtextcontent.js +1 -0
- package/esm/models/requesttimeoutresponseerrordata.js +1 -0
- package/esm/models/responseformatjsonschema.js +1 -0
- package/esm/models/responseformattextconfig.js +1 -0
- package/esm/models/responseformattextgrammar.js +1 -0
- package/esm/models/responseinputaudio.js +1 -0
- package/esm/models/responseinputfile.js +1 -0
- package/esm/models/responseinputimage.js +1 -0
- package/esm/models/responseinputtext.js +1 -0
- package/esm/models/responseoutputtext.js +1 -0
- package/esm/models/responseserrorfield.js +1 -0
- package/esm/models/responsesformatjsonobject.js +1 -0
- package/esm/models/responsesformattext.js +1 -0
- package/esm/models/responsesformattextjsonschemaconfig.js +1 -0
- package/esm/models/responsesimagegenerationcall.js +1 -0
- package/esm/models/responsesoutputitem.js +1 -0
- package/esm/models/responsesoutputitemfilesearchcall.js +1 -0
- package/esm/models/responsesoutputitemfunctioncall.js +1 -0
- package/esm/models/responsesoutputitemreasoning.js +1 -0
- package/esm/models/responsesoutputmessage.js +1 -0
- package/esm/models/responsessearchcontextsize.js +1 -0
- package/esm/models/responseswebsearchcalloutput.js +1 -0
- package/esm/models/responseswebsearchuserlocation.js +1 -0
- package/esm/models/responsetextconfig.js +1 -0
- package/esm/models/schema0.js +1 -0
- package/esm/models/schema3.js +1 -0
- package/esm/models/security.js +1 -0
- package/esm/models/serviceunavailableresponseerrordata.js +1 -0
- package/esm/models/systemmessage.js +1 -0
- package/esm/models/toolcallstatus.js +1 -0
- package/esm/models/tooldefinitionjson.js +1 -0
- package/esm/models/toolresponsemessage.js +1 -0
- package/esm/models/toomanyrequestsresponseerrordata.js +1 -0
- package/esm/models/topproviderinfo.js +1 -0
- package/esm/models/unauthorizedresponseerrordata.js +1 -0
- package/esm/models/unprocessableentityresponseerrordata.js +1 -0
- package/esm/models/urlcitation.js +1 -0
- package/esm/models/usermessage.js +1 -0
- package/esm/models/websearchengine.js +1 -0
- package/esm/models/websearchpreviewtooluserlocation.js +1 -0
- package/esm/models/websearchstatus.js +1 -0
- package/esm/sdk/analytics.js +1 -0
- package/esm/sdk/apikeys.js +1 -0
- package/esm/sdk/beta.js +1 -0
- package/esm/sdk/chat.js +1 -0
- package/esm/sdk/completions.js +1 -0
- package/esm/sdk/credits.js +1 -0
- package/esm/sdk/embeddings.js +1 -0
- package/esm/sdk/endpoints.js +1 -0
- package/esm/sdk/generations.js +1 -0
- package/esm/sdk/index.js +1 -0
- package/esm/sdk/models.js +1 -0
- package/esm/sdk/oauth.js +1 -0
- package/esm/sdk/parameters.js +1 -0
- package/esm/sdk/providers.js +1 -0
- package/esm/sdk/responses.js +1 -0
- package/esm/sdk/sdk.d.ts +4 -10
- package/esm/sdk/sdk.js +2 -1
- package/esm/types/async.js +1 -0
- package/esm/types/blobs.js +1 -0
- package/esm/types/constdatetime.js +1 -0
- package/esm/types/discriminatedUnion.js +1 -0
- package/esm/types/enums.js +1 -0
- package/esm/types/fp.js +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/operations.js +1 -0
- package/esm/types/rfcdate.js +1 -0
- package/esm/types/streams.js +1 -0
- package/esm/types/unrecognized.js +1 -0
- package/jsr.json +1 -1
- package/package.json +6 -3
- package/esm/funcs/callModel.d.ts +0 -87
- package/esm/funcs/callModel.js +0 -215
package/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
4
|
-
export type {
|
|
5
|
-
export
|
|
1
|
+
export type { CallModelInput, FieldOrAsyncFunction, ResolvedCallModelInput, } from './lib/async-params.js';
|
|
2
|
+
export type { Fetcher, HTTPClientOptions } from './lib/http.js';
|
|
3
|
+
export type { ChatStreamEvent, ResponseStreamEvent as EnhancedResponseStreamEvent, InferToolEvent, InferToolEventsUnion, InferToolInput, InferToolOutput, ManualTool, NextTurnParamsContext, NextTurnParamsFunctions, ParsedToolCall, StepResult, StopCondition, StopWhen, Tool, ToolExecutionResult, ToolExecutionResultUnion, ToolPreliminaryResultEvent, ToolStreamEvent, ToolWithExecute, ToolWithGenerator, TurnContext, TypedToolCall, TypedToolCallUnion, Warning, } from './lib/tool-types.js';
|
|
4
|
+
export type { BuildTurnContextOptions } from './lib/turn-context.js';
|
|
5
|
+
export type { ClaudeBase64ImageSource, ClaudeCacheControl, ClaudeCitationCharLocation, ClaudeCitationContentBlockLocation, ClaudeCitationPageLocation, ClaudeCitationSearchResultLocation, ClaudeCitationWebSearchResultLocation, ClaudeContentBlock, ClaudeContentBlockParam, ClaudeImageBlockParam, ClaudeMessage, ClaudeMessageParam, ClaudeRedactedThinkingBlock, ClaudeServerToolUseBlock, ClaudeStopReason, ClaudeTextBlock, ClaudeTextBlockParam, ClaudeTextCitation, ClaudeThinkingBlock, ClaudeToolResultBlockParam, ClaudeToolUseBlock, ClaudeToolUseBlockParam, ClaudeURLImageSource, ClaudeUsage, } from './models/claude-message.js';
|
|
6
|
+
export { fromClaudeMessages, toClaudeMessage } from './lib/anthropic-compat.js';
|
|
7
|
+
export { hasAsyncFunctions, resolveAsyncFunctions, } from './lib/async-params.js';
|
|
8
|
+
export { fromChatMessages, toChatMessage } from './lib/chat-compat.js';
|
|
9
|
+
export { ClaudeContentBlockType, NonClaudeMessageRole } from './lib/claude-constants.js';
|
|
10
|
+
export { isClaudeStyleMessages } from './lib/claude-type-guards.js';
|
|
11
|
+
export * from './lib/config.js';
|
|
12
|
+
export * as files from './lib/files.js';
|
|
13
|
+
export { HTTPClient } from './lib/http.js';
|
|
14
|
+
export { applyNextTurnParamsToRequest, buildNextTurnParamsContext, executeNextTurnParamsFunctions, } from './lib/next-turn-params.js';
|
|
15
|
+
export { finishReasonIs, hasToolCall, isStopConditionMet, maxCost, maxTokensUsed, stepCountIs, } from './lib/stop-conditions.js';
|
|
16
|
+
export { extractUnsupportedContent, getUnsupportedContentSummary, hasUnsupportedContent, } from './lib/stream-transformers.js';
|
|
17
|
+
export { tool } from './lib/tool.js';
|
|
18
|
+
export { hasExecuteFunction, isGeneratorTool, isRegularExecuteTool, isToolPreliminaryResultEvent, ToolType, } from './lib/tool-types.js';
|
|
19
|
+
export { buildTurnContext, normalizeInputToArray } from './lib/turn-context.js';
|
|
20
|
+
export * from './sdk/sdk.js';
|
|
6
21
|
//# sourceMappingURL=index.d.ts.map
|
package/esm/index.js
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export {
|
|
7
|
-
export
|
|
4
|
+
// Message format compatibility helpers
|
|
5
|
+
export { fromClaudeMessages, toClaudeMessage } from './lib/anthropic-compat.js';
|
|
6
|
+
export { hasAsyncFunctions, resolveAsyncFunctions, } from './lib/async-params.js';
|
|
7
|
+
export { fromChatMessages, toChatMessage } from './lib/chat-compat.js';
|
|
8
|
+
// Claude constants and type guards
|
|
9
|
+
export { ClaudeContentBlockType, NonClaudeMessageRole } from './lib/claude-constants.js';
|
|
10
|
+
export { isClaudeStyleMessages } from './lib/claude-type-guards.js';
|
|
11
|
+
export * from './lib/config.js';
|
|
12
|
+
export * as files from './lib/files.js';
|
|
13
|
+
export { HTTPClient } from './lib/http.js';
|
|
14
|
+
// Next turn params helpers
|
|
15
|
+
export { applyNextTurnParamsToRequest, buildNextTurnParamsContext, executeNextTurnParamsFunctions, } from './lib/next-turn-params.js';
|
|
16
|
+
// Stop condition helpers
|
|
17
|
+
export { finishReasonIs, hasToolCall, isStopConditionMet, maxCost, maxTokensUsed, stepCountIs, } from './lib/stop-conditions.js';
|
|
18
|
+
export { extractUnsupportedContent, getUnsupportedContentSummary, hasUnsupportedContent, } from './lib/stream-transformers.js';
|
|
19
|
+
// Tool creation helpers
|
|
20
|
+
export { tool } from './lib/tool.js';
|
|
21
|
+
export { hasExecuteFunction, isGeneratorTool, isRegularExecuteTool, isToolPreliminaryResultEvent, ToolType, } from './lib/tool-types.js';
|
|
22
|
+
// Turn context helpers
|
|
23
|
+
export { buildTurnContext, normalizeInputToArray } from './lib/turn-context.js';
|
|
24
|
+
export * from './sdk/sdk.js';
|
|
8
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type * as models from '../models/index.js';
|
|
2
|
+
import { convertToClaudeMessage } from './stream-transformers.js';
|
|
3
|
+
/**
|
|
4
|
+
* Convert Anthropic Claude-style messages to OpenResponses input format.
|
|
5
|
+
*
|
|
6
|
+
* This function transforms ClaudeMessageParam[] (Anthropic SDK format) to
|
|
7
|
+
* OpenResponsesInput format that can be passed directly to callModel().
|
|
8
|
+
*
|
|
9
|
+
* Note: Some Claude features are lost in conversion as OpenRouter doesn't support them:
|
|
10
|
+
* - cache_control on content blocks
|
|
11
|
+
* - is_error flag on tool_result blocks
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { fromClaudeMessages } from '@openrouter/sdk';
|
|
16
|
+
*
|
|
17
|
+
* const claudeMessages = [
|
|
18
|
+
* { role: "user", content: "Hello!" },
|
|
19
|
+
* { role: "assistant", content: "Hi there!" },
|
|
20
|
+
* ];
|
|
21
|
+
*
|
|
22
|
+
* const response = openrouter.callModel({
|
|
23
|
+
* model: "anthropic/claude-3-sonnet",
|
|
24
|
+
* input: fromClaudeMessages(claudeMessages),
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function fromClaudeMessages(messages: models.ClaudeMessageParam[]): models.OpenResponsesInput;
|
|
29
|
+
/**
|
|
30
|
+
* Convert an OpenResponses response to Anthropic Claude message format.
|
|
31
|
+
*
|
|
32
|
+
* This function transforms OpenResponsesNonStreamingResponse to ClaudeMessage
|
|
33
|
+
* (Anthropic SDK format) for compatibility with code expecting Claude responses.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import { toClaudeMessage } from '@openrouter/sdk';
|
|
38
|
+
*
|
|
39
|
+
* const response = await openrouter.callModel({
|
|
40
|
+
* model: "anthropic/claude-3-sonnet",
|
|
41
|
+
* input: "Hello!",
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* const openResponsesResult = await response.getResponse();
|
|
45
|
+
* const claudeMessage = toClaudeMessage(openResponsesResult);
|
|
46
|
+
* // claudeMessage is now compatible with Anthropic SDK types
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const toClaudeMessage: typeof convertToClaudeMessage;
|
|
50
|
+
//# sourceMappingURL=anthropic-compat.d.ts.map
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { OpenResponsesEasyInputMessageRoleAssistant, OpenResponsesEasyInputMessageRoleUser, } from '../models/openresponseseasyinputmessage.js';
|
|
2
|
+
import { OpenResponsesFunctionCallOutputType } from '../models/openresponsesfunctioncalloutput.js';
|
|
3
|
+
import { OpenResponsesInputMessageItemRoleUser, OpenResponsesInputMessageItemRoleDeveloper } from '../models/openresponsesinputmessageitem.js';
|
|
4
|
+
import { convertToClaudeMessage } from './stream-transformers.js';
|
|
5
|
+
/**
|
|
6
|
+
* Maps Claude role strings to OpenResponses role types
|
|
7
|
+
*/
|
|
8
|
+
function mapClaudeRole(role) {
|
|
9
|
+
if (role === 'user') {
|
|
10
|
+
return OpenResponsesEasyInputMessageRoleUser.User;
|
|
11
|
+
}
|
|
12
|
+
return OpenResponsesEasyInputMessageRoleAssistant.Assistant;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates a properly typed OpenResponsesEasyInputMessage
|
|
16
|
+
*/
|
|
17
|
+
function createEasyInputMessage(role, content) {
|
|
18
|
+
return {
|
|
19
|
+
role: mapClaudeRole(role),
|
|
20
|
+
content,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a properly typed OpenResponsesFunctionCallOutput
|
|
25
|
+
*/
|
|
26
|
+
function createFunctionCallOutput(callId, output) {
|
|
27
|
+
return {
|
|
28
|
+
type: OpenResponsesFunctionCallOutputType.FunctionCallOutput,
|
|
29
|
+
callId,
|
|
30
|
+
output,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Convert Anthropic Claude-style messages to OpenResponses input format.
|
|
35
|
+
*
|
|
36
|
+
* This function transforms ClaudeMessageParam[] (Anthropic SDK format) to
|
|
37
|
+
* OpenResponsesInput format that can be passed directly to callModel().
|
|
38
|
+
*
|
|
39
|
+
* Note: Some Claude features are lost in conversion as OpenRouter doesn't support them:
|
|
40
|
+
* - cache_control on content blocks
|
|
41
|
+
* - is_error flag on tool_result blocks
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { fromClaudeMessages } from '@openrouter/sdk';
|
|
46
|
+
*
|
|
47
|
+
* const claudeMessages = [
|
|
48
|
+
* { role: "user", content: "Hello!" },
|
|
49
|
+
* { role: "assistant", content: "Hi there!" },
|
|
50
|
+
* ];
|
|
51
|
+
*
|
|
52
|
+
* const response = openrouter.callModel({
|
|
53
|
+
* model: "anthropic/claude-3-sonnet",
|
|
54
|
+
* input: fromClaudeMessages(claudeMessages),
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function fromClaudeMessages(messages) {
|
|
59
|
+
const result = [];
|
|
60
|
+
for (const msg of messages) {
|
|
61
|
+
const { role, content } = msg;
|
|
62
|
+
if (typeof content === 'string') {
|
|
63
|
+
result.push(createEasyInputMessage(role, content));
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
// Separate content blocks into categories for clearer processing
|
|
67
|
+
const textBlocks = [];
|
|
68
|
+
const imageBlocks = [];
|
|
69
|
+
const toolUseBlocks = [];
|
|
70
|
+
const toolResultBlocks = [];
|
|
71
|
+
for (const block of content) {
|
|
72
|
+
switch (block.type) {
|
|
73
|
+
case 'text':
|
|
74
|
+
textBlocks.push(block);
|
|
75
|
+
break;
|
|
76
|
+
case 'image':
|
|
77
|
+
imageBlocks.push(block);
|
|
78
|
+
break;
|
|
79
|
+
case 'tool_use':
|
|
80
|
+
toolUseBlocks.push(block);
|
|
81
|
+
break;
|
|
82
|
+
case 'tool_result':
|
|
83
|
+
toolResultBlocks.push(block);
|
|
84
|
+
break;
|
|
85
|
+
default: {
|
|
86
|
+
// Exhaustiveness check - TypeScript will error if we don't handle all block types
|
|
87
|
+
const exhaustiveCheck = block;
|
|
88
|
+
throw new Error(`Unhandled content block type: ${JSON.stringify(exhaustiveCheck)}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Process tool use blocks first (they go directly to result)
|
|
93
|
+
for (const toolUseBlock of toolUseBlocks) {
|
|
94
|
+
result.push({
|
|
95
|
+
type: 'function_call',
|
|
96
|
+
callId: toolUseBlock.id,
|
|
97
|
+
name: toolUseBlock.name,
|
|
98
|
+
arguments: JSON.stringify(toolUseBlock.input),
|
|
99
|
+
id: toolUseBlock.id,
|
|
100
|
+
status: 'completed',
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// Process tool result blocks
|
|
104
|
+
for (const toolResultBlock of toolResultBlocks) {
|
|
105
|
+
let toolOutput = '';
|
|
106
|
+
if (typeof toolResultBlock.content === 'string') {
|
|
107
|
+
toolOutput = toolResultBlock.content;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
// Extract text and handle images separately
|
|
111
|
+
const textParts = [];
|
|
112
|
+
const imageParts = [];
|
|
113
|
+
for (const part of toolResultBlock.content) {
|
|
114
|
+
if (part.type === 'text') {
|
|
115
|
+
textParts.push(part.text);
|
|
116
|
+
}
|
|
117
|
+
else if (part.type === 'image') {
|
|
118
|
+
imageParts.push(part);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
toolOutput = textParts.join('');
|
|
122
|
+
// Map images to image_generation_call items
|
|
123
|
+
imageParts.forEach((imagePart, i) => {
|
|
124
|
+
let imageUrl;
|
|
125
|
+
if (imagePart.source.type === 'url') {
|
|
126
|
+
imageUrl = imagePart.source.url;
|
|
127
|
+
}
|
|
128
|
+
else if (imagePart.source.type === 'base64') {
|
|
129
|
+
imageUrl = `data:${imagePart.source.media_type};base64,${imagePart.source.data}`;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
const exhaustiveCheck = imagePart.source;
|
|
133
|
+
throw new Error(`Unhandled image source type: ${exhaustiveCheck}`);
|
|
134
|
+
}
|
|
135
|
+
result.push({
|
|
136
|
+
type: 'image_generation_call',
|
|
137
|
+
id: `${toolResultBlock.tool_use_id}-image-${i}`,
|
|
138
|
+
result: imageUrl,
|
|
139
|
+
status: 'completed',
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
// Add the function call output for the text portion (if any)
|
|
144
|
+
if (toolOutput.length > 0) {
|
|
145
|
+
result.push(createFunctionCallOutput(toolResultBlock.tool_use_id, toolOutput));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// Process text and image blocks (these become message content)
|
|
149
|
+
if (textBlocks.length > 0 || imageBlocks.length > 0) {
|
|
150
|
+
const contentItems = [];
|
|
151
|
+
// Add text blocks
|
|
152
|
+
for (const textBlock of textBlocks) {
|
|
153
|
+
contentItems.push({
|
|
154
|
+
type: 'input_text',
|
|
155
|
+
text: textBlock.text,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
// Add image blocks
|
|
159
|
+
for (const imageBlock of imageBlocks) {
|
|
160
|
+
let imageUrl;
|
|
161
|
+
if (imageBlock.source.type === 'url') {
|
|
162
|
+
imageUrl = imageBlock.source.url;
|
|
163
|
+
}
|
|
164
|
+
else if (imageBlock.source.type === 'base64') {
|
|
165
|
+
imageUrl = `data:${imageBlock.source.media_type};base64,${imageBlock.source.data}`;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
const exhaustiveCheck = imageBlock.source;
|
|
169
|
+
throw new Error(`Unhandled image source type: ${exhaustiveCheck}`);
|
|
170
|
+
}
|
|
171
|
+
contentItems.push({
|
|
172
|
+
type: 'input_image',
|
|
173
|
+
detail: 'auto',
|
|
174
|
+
imageUrl,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
// Determine output format based on content
|
|
178
|
+
if (imageBlocks.length > 0) {
|
|
179
|
+
// Use structured format for messages with images
|
|
180
|
+
result.push({
|
|
181
|
+
type: 'message',
|
|
182
|
+
role: role === 'user'
|
|
183
|
+
? OpenResponsesInputMessageItemRoleUser.User
|
|
184
|
+
: OpenResponsesInputMessageItemRoleDeveloper.Developer,
|
|
185
|
+
content: contentItems,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
// Use simple string format for text-only messages
|
|
190
|
+
const textContent = contentItems
|
|
191
|
+
.filter((item) => item.type === 'input_text')
|
|
192
|
+
.map((item) => item.text)
|
|
193
|
+
.join('');
|
|
194
|
+
if (textContent.length > 0) {
|
|
195
|
+
result.push(createEasyInputMessage(role, textContent));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Convert an OpenResponses response to Anthropic Claude message format.
|
|
204
|
+
*
|
|
205
|
+
* This function transforms OpenResponsesNonStreamingResponse to ClaudeMessage
|
|
206
|
+
* (Anthropic SDK format) for compatibility with code expecting Claude responses.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```typescript
|
|
210
|
+
* import { toClaudeMessage } from '@openrouter/sdk';
|
|
211
|
+
*
|
|
212
|
+
* const response = await openrouter.callModel({
|
|
213
|
+
* model: "anthropic/claude-3-sonnet",
|
|
214
|
+
* input: "Hello!",
|
|
215
|
+
* });
|
|
216
|
+
*
|
|
217
|
+
* const openResponsesResult = await response.getResponse();
|
|
218
|
+
* const claudeMessage = toClaudeMessage(openResponsesResult);
|
|
219
|
+
* // claudeMessage is now compatible with Anthropic SDK types
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
export const toClaudeMessage = convertToClaudeMessage;
|
|
223
|
+
//# sourceMappingURL=anthropic-compat.js.map
|