@omnicross/core 0.1.1 → 0.1.2
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/dist/ApiConverter.cjs +3 -778
- package/dist/ApiConverter.js +12 -751
- package/dist/{CompletionService-DtOF_War.d.cts → CompletionService-D3a47vdU.d.cts} +2 -1
- package/dist/{CompletionService-7fCmKAP3.d.ts → CompletionService-DdWaAxq0.d.ts} +2 -1
- package/dist/auth/GeminiCodeAssistProjectResolver.cjs +27 -60
- package/dist/auth/GeminiCodeAssistProjectResolver.js +5 -9
- package/dist/builtin-web-fetch-77JZUZGM.cjs +100 -0
- package/dist/builtin-web-fetch-IGLBX2XY.js +100 -0
- package/dist/chunk-2DCNB7DF.cjs +514 -0
- package/dist/chunk-2FEVTJWG.js +4400 -0
- package/dist/chunk-3MEACFK3.js +193 -0
- package/dist/chunk-3OPYJG76.cjs +266 -0
- package/dist/chunk-46RLHI7D.js +0 -0
- package/dist/chunk-46ZIFWYG.cjs +277 -0
- package/dist/chunk-4NBS6KPV.cjs +43 -0
- package/dist/chunk-4VAVYUZS.cjs +991 -0
- package/dist/chunk-5ERIZW3D.js +44 -0
- package/dist/chunk-5HTVET6E.js +514 -0
- package/dist/chunk-5ZQBEOMD.js +764 -0
- package/dist/chunk-6VIXXLMX.cjs +14 -0
- package/dist/chunk-745DV5FL.js +147 -0
- package/dist/chunk-74TMJA7Z.js +53 -0
- package/dist/chunk-7VU7V2E4.js +0 -0
- package/dist/chunk-7YN22L2H.cjs +87 -0
- package/dist/chunk-A2YMUCBT.cjs +105 -0
- package/dist/chunk-AQ5TNQB7.js +13 -0
- package/dist/chunk-AVYJ4YBN.js +58 -0
- package/dist/chunk-C72S6TTV.cjs +49 -0
- package/dist/chunk-C7PSERMH.js +87 -0
- package/dist/chunk-CDHS2QDC.js +179 -0
- package/dist/chunk-DK4A7DLE.js +266 -0
- package/dist/chunk-DRWHTIIZ.js +13 -0
- package/dist/chunk-DWKQZ2SK.cjs +254 -0
- package/dist/chunk-E3WHL7CO.js +14 -0
- package/dist/chunk-EYZYXJTJ.cjs +1 -0
- package/dist/chunk-FMOBD2OQ.js +39 -0
- package/dist/chunk-FTQ7IQUC.js +991 -0
- package/dist/chunk-FZ46M34D.cjs +1 -0
- package/dist/chunk-G2FUJNA2.cjs +193 -0
- package/dist/chunk-G2UTNSGU.js +277 -0
- package/dist/chunk-GBHYAGX3.cjs +26 -0
- package/dist/chunk-GMMT7RVN.cjs +39 -0
- package/dist/chunk-H5JUT3KV.js +105 -0
- package/dist/chunk-HQP3K7PU.cjs +431 -0
- package/dist/chunk-JO5NLTLY.js +46 -0
- package/dist/chunk-JWC6APFQ.js +23 -0
- package/dist/chunk-KUU2RNG6.cjs +46 -0
- package/dist/chunk-LKZJEL6E.cjs +124 -0
- package/dist/chunk-MNYKI4CI.js +94 -0
- package/dist/chunk-MZNPGW5Q.js +26 -0
- package/dist/chunk-N3V2J5ZO.cjs +53 -0
- package/dist/chunk-NYUNU75A.cjs +44 -0
- package/dist/chunk-NZYN7C3P.cjs +179 -0
- package/dist/chunk-O466Y272.js +235 -0
- package/dist/chunk-PXUJF5HS.js +124 -0
- package/dist/chunk-QBZJ7P2T.cjs +13 -0
- package/dist/chunk-QOCNX236.js +46 -0
- package/dist/chunk-QXD4MV2X.cjs +23 -0
- package/dist/chunk-R3HK6R4B.cjs +13 -0
- package/dist/chunk-RSJ3TWJQ.cjs +186 -0
- package/dist/chunk-S4WBV25P.js +913 -0
- package/dist/chunk-SN3YWBX7.cjs +4400 -0
- package/dist/chunk-SPVWWUHX.cjs +46 -0
- package/dist/chunk-SUEGJ75D.cjs +764 -0
- package/dist/chunk-SVNDB62D.cjs +58 -0
- package/dist/chunk-UYPEN5XE.cjs +235 -0
- package/dist/chunk-V5KPWNYX.cjs +147 -0
- package/dist/chunk-VVEHS2LI.js +431 -0
- package/dist/chunk-XBSYYZIY.cjs +94 -0
- package/dist/chunk-YGXJGRFI.cjs +913 -0
- package/dist/chunk-YMFAJFQT.cjs +173 -0
- package/dist/chunk-Z7LUNECE.js +49 -0
- package/dist/chunk-Z7Y2NPHY.js +186 -0
- package/dist/chunk-ZJZAOKI7.js +254 -0
- package/dist/chunk-ZLX3KGXX.js +173 -0
- package/dist/chunk-ZSVQT3PW.js +43 -0
- package/dist/completion/ApiKeyPoolService.cjs +23 -48
- package/dist/completion/ApiKeyPoolService.d.cts +150 -2
- package/dist/completion/ApiKeyPoolService.d.ts +150 -2
- package/dist/completion/BuiltinToolExecutor.cjs +9 -324
- package/dist/completion/BuiltinToolExecutor.js +6 -290
- package/dist/completion/CompletionService.cjs +38 -3487
- package/dist/completion/CompletionService.d.cts +3 -2
- package/dist/completion/CompletionService.d.ts +3 -2
- package/dist/completion/CompletionService.js +34 -3457
- package/dist/completion/NativeSearchInjector.cjs +8 -192
- package/dist/completion/NativeSearchInjector.js +7 -162
- package/dist/completion/ProviderSearchInjector.cjs +12 -39
- package/dist/completion/native-search-types.cjs +13 -66
- package/dist/completion/native-search-types.js +7 -31
- package/dist/completion/openrouter-headers.cjs +15 -71
- package/dist/completion/openrouter-headers.js +8 -34
- package/dist/completion/openrouter-models.cjs +10 -67
- package/dist/completion/openrouter-models.js +4 -34
- package/dist/completion/types.cjs +1 -18
- package/dist/completion/url-builder.cjs +24 -138
- package/dist/completion/url-builder.js +12 -92
- package/dist/completion.cjs +55 -3989
- package/dist/completion.d.cts +3 -2
- package/dist/completion.d.ts +3 -2
- package/dist/completion.js +63 -3953
- package/dist/index.cjs +197 -10429
- package/dist/index.d.cts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +125 -10268
- package/dist/logger-4GvQNzhE.d.cts +22 -0
- package/dist/logger-4GvQNzhE.d.ts +22 -0
- package/dist/outbound-api/routeResolver.cjs +7 -217
- package/dist/outbound-api/routeResolver.d.cts +2 -1
- package/dist/outbound-api/routeResolver.d.ts +2 -1
- package/dist/outbound-api/routeResolver.js +6 -187
- package/dist/outbound-api/subscriptionRegistryPort.cjs +7 -37
- package/dist/outbound-api/subscriptionRegistryPort.d.cts +2 -1
- package/dist/outbound-api/subscriptionRegistryPort.d.ts +2 -1
- package/dist/outbound-api/subscriptionRegistryPort.js +4 -8
- package/dist/outbound-api/types.cjs +1 -18
- package/dist/outbound-api/types.d.cts +2 -1
- package/dist/outbound-api/types.d.ts +2 -1
- package/dist/outbound-api.cjs +35 -5221
- package/dist/outbound-api.d.cts +2 -1
- package/dist/outbound-api.d.ts +2 -1
- package/dist/outbound-api.js +54 -5194
- package/dist/pipeline/AuthSource.cjs +1 -18
- package/dist/pipeline/LlmConfigProviderAuth.cjs +5 -166
- package/dist/pipeline/LlmConfigProviderAuth.d.cts +2 -1
- package/dist/pipeline/LlmConfigProviderAuth.d.ts +2 -1
- package/dist/pipeline/LlmConfigProviderAuth.js +5 -139
- package/dist/pipeline/SubscriptionAuthSource.cjs +6 -128
- package/dist/pipeline/SubscriptionAuthSource.js +5 -99
- package/dist/pipeline/SubscriptionAuthStrategy.cjs +1 -18
- package/dist/pipeline/executeProviderCall.cjs +5 -69
- package/dist/pipeline/executeProviderCall.js +3 -42
- package/dist/pipeline/resolveProviderChain.cjs +5 -46
- package/dist/pipeline/resolveProviderChain.js +3 -19
- package/dist/pipeline/resolveSubscriptionChain.cjs +5 -67
- package/dist/pipeline/resolveSubscriptionChain.js +3 -40
- package/dist/ports/gemini-code-assist-resolver.cjs +7 -37
- package/dist/ports/gemini-code-assist-resolver.js +4 -8
- package/dist/ports/pricing-store.cjs +1 -0
- package/dist/ports/pricing-store.d.cts +50 -0
- package/dist/ports/pricing-store.d.ts +50 -0
- package/dist/ports/pricing-store.js +0 -0
- package/dist/ports/provider-config-source.cjs +1 -18
- package/dist/ports/usage-event-store.cjs +1 -0
- package/dist/ports/usage-event-store.d.cts +29 -0
- package/dist/ports/usage-event-store.d.ts +29 -0
- package/dist/ports/usage-event-store.js +0 -0
- package/dist/ports/web-search-backend.cjs +1 -18
- package/dist/ports.cjs +1 -18
- package/dist/ports.d.cts +6 -1
- package/dist/ports.d.ts +6 -1
- package/dist/provider-proxy/ProviderProxy.cjs +40 -4643
- package/dist/provider-proxy/ProviderProxy.d.cts +2 -1
- package/dist/provider-proxy/ProviderProxy.d.ts +2 -1
- package/dist/provider-proxy/ProviderProxy.js +35 -4613
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +35 -2941
- package/dist/provider-proxy/ingress/providerProxyShared.d.cts +2 -1
- package/dist/provider-proxy/ingress/providerProxyShared.d.ts +2 -1
- package/dist/provider-proxy/ingress/providerProxyShared.js +41 -2914
- package/dist/provider-proxy/matchText.cjs +11 -72
- package/dist/provider-proxy/matchText.js +6 -39
- package/dist/provider-proxy/types.cjs +1 -18
- package/dist/provider-proxy/types.d.cts +2 -1
- package/dist/provider-proxy/types.d.ts +2 -1
- package/dist/provider-proxy.cjs +35 -4655
- package/dist/provider-proxy.d.cts +2 -1
- package/dist/provider-proxy.d.ts +2 -1
- package/dist/provider-proxy.js +39 -4628
- package/dist/serializeError.cjs +5 -81
- package/dist/serializeError.js +3 -54
- package/dist/sse-parser.cjs +7 -455
- package/dist/sse-parser.js +4 -426
- package/dist/transformer/TransformerChainExecutor.cjs +4 -318
- package/dist/transformer/TransformerChainExecutor.js +4 -291
- package/dist/transformer/TransformerService.cjs +5 -289
- package/dist/transformer/TransformerService.js +3 -262
- package/dist/transformer/anthropicBetaInject.cjs +7 -50
- package/dist/transformer/anthropicBetaInject.js +4 -21
- package/dist/transformer/transformers/AnthropicTransformer.cjs +3 -1014
- package/dist/transformer/transformers/AnthropicTransformer.js +3 -987
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +4 -1106
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +7 -1079
- package/dist/transformer/transformers/GeminiTransformer.cjs +4 -1010
- package/dist/transformer/transformers/GeminiTransformer.js +4 -983
- package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +3 -535
- package/dist/transformer/transformers/OpenAIResponseTransformer.js +3 -510
- package/dist/transformer/transformers/OpenCodeGoTransformer.cjs +5 -72
- package/dist/transformer/transformers/OpenCodeGoTransformer.js +3 -45
- package/dist/transformer/transformers/ReasoningTransformer.cjs +3 -270
- package/dist/transformer/transformers/ReasoningTransformer.js +2 -249
- package/dist/transformer/transformers.cjs +10 -3177
- package/dist/transformer/transformers.js +23 -3158
- package/dist/transformer/types.cjs +1 -18
- package/dist/transformer.cjs +13 -3726
- package/dist/transformer.js +17 -3706
- package/dist/usage/pricing-engine.cjs +6 -0
- package/dist/usage/pricing-engine.d.cts +83 -0
- package/dist/usage/pricing-engine.d.ts +83 -0
- package/dist/usage/pricing-engine.js +6 -0
- package/dist/usage/usage-recorder.cjs +6 -0
- package/dist/usage/usage-recorder.d.cts +73 -0
- package/dist/usage/usage-recorder.d.ts +73 -0
- package/dist/usage/usage-recorder.js +6 -0
- package/dist/usage.cjs +11 -0
- package/dist/usage.d.cts +8 -0
- package/dist/usage.d.ts +8 -0
- package/dist/usage.js +11 -0
- package/package.json +1 -1
- package/dist/ApiKeyPoolService-BmMkau07.d.cts +0 -170
- package/dist/ApiKeyPoolService-BmMkau07.d.ts +0 -170
package/dist/ApiConverter.cjs
CHANGED
|
@@ -1,799 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
19
2
|
|
|
20
|
-
// src/ApiConverter.ts
|
|
21
|
-
var ApiConverter_exports = {};
|
|
22
|
-
__export(ApiConverter_exports, {
|
|
23
|
-
convertAnthropicRequestToOpenAI: () => convertAnthropicRequestToOpenAI,
|
|
24
|
-
convertAnthropicStreamToOpenAI: () => convertAnthropicStreamToOpenAI,
|
|
25
|
-
convertAnthropicToOpenAI: () => convertAnthropicToOpenAI,
|
|
26
|
-
convertAnthropicToOpenAIWithThinking: () => convertAnthropicToOpenAIWithThinking,
|
|
27
|
-
convertOpenAIResponseToAnthropic: () => convertOpenAIResponseToAnthropic,
|
|
28
|
-
convertOpenAIStreamToAnthropic: () => convertOpenAIStreamToAnthropic,
|
|
29
|
-
convertOpenAIToAnthropic: () => convertOpenAIToAnthropic,
|
|
30
|
-
convertOpenAIToAnthropicWithThinking: () => convertOpenAIToAnthropicWithThinking,
|
|
31
|
-
hasImageContent: () => hasImageContent,
|
|
32
|
-
hasThinkingEnabled: () => hasThinkingEnabled
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(ApiConverter_exports);
|
|
35
3
|
|
|
36
|
-
// src/api-converter/shared.ts
|
|
37
|
-
function convertOpenAITool(tool) {
|
|
38
|
-
return {
|
|
39
|
-
name: tool.function.name,
|
|
40
|
-
description: tool.function.description,
|
|
41
|
-
input_schema: tool.function.parameters
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
function mapAnthropicStopReason(stopReason) {
|
|
45
|
-
switch (stopReason) {
|
|
46
|
-
case "end_turn":
|
|
47
|
-
return "stop";
|
|
48
|
-
case "max_tokens":
|
|
49
|
-
return "length";
|
|
50
|
-
case "tool_use":
|
|
51
|
-
return "tool_calls";
|
|
52
|
-
case "stop_sequence":
|
|
53
|
-
return "stop";
|
|
54
|
-
default:
|
|
55
|
-
return "stop";
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function mapOpenAIFinishReason(finishReason) {
|
|
59
|
-
switch (finishReason) {
|
|
60
|
-
case "stop":
|
|
61
|
-
return "end_turn";
|
|
62
|
-
case "length":
|
|
63
|
-
return "max_tokens";
|
|
64
|
-
case "tool_calls":
|
|
65
|
-
return "tool_use";
|
|
66
|
-
case "content_filter":
|
|
67
|
-
return "end_turn";
|
|
68
|
-
default:
|
|
69
|
-
return "end_turn";
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function hasImageContent(request) {
|
|
73
|
-
const messages = request.messages;
|
|
74
|
-
for (const msg of messages) {
|
|
75
|
-
if (Array.isArray(msg.content)) {
|
|
76
|
-
for (const part of msg.content) {
|
|
77
|
-
if ("type" in part && part.type === "image_url") {
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
if ("type" in part && part.type === "image") {
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
function hasThinkingEnabled(request) {
|
|
89
|
-
if ("thinking" in request && request.thinking?.type === "enabled") {
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
if ("reasoning" in request) {
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
4
|
|
|
98
|
-
// src/api-converter/anthropic-to-openai.ts
|
|
99
|
-
function convertAnthropicToOpenAI(response) {
|
|
100
|
-
const content = [];
|
|
101
|
-
const toolCalls = [];
|
|
102
|
-
let reasoningContent = "";
|
|
103
|
-
for (const block of response.content) {
|
|
104
|
-
if (block.type === "text") {
|
|
105
|
-
content.push(block.text);
|
|
106
|
-
} else if (block.type === "tool_use") {
|
|
107
|
-
toolCalls.push({
|
|
108
|
-
id: block.id,
|
|
109
|
-
type: "function",
|
|
110
|
-
function: {
|
|
111
|
-
name: block.name,
|
|
112
|
-
arguments: JSON.stringify(block.input)
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
} else if (block.type === "thinking") {
|
|
116
|
-
reasoningContent += block.thinking;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
const finishReason = mapAnthropicStopReason(response.stop_reason);
|
|
120
|
-
const result = {
|
|
121
|
-
id: response.id,
|
|
122
|
-
object: "chat.completion",
|
|
123
|
-
created: Math.floor(Date.now() / 1e3),
|
|
124
|
-
model: response.model,
|
|
125
|
-
choices: [
|
|
126
|
-
{
|
|
127
|
-
index: 0,
|
|
128
|
-
message: {
|
|
129
|
-
role: "assistant",
|
|
130
|
-
content: content.join("\n") || null,
|
|
131
|
-
...toolCalls.length > 0 ? { tool_calls: toolCalls } : {}
|
|
132
|
-
},
|
|
133
|
-
finish_reason: finishReason
|
|
134
|
-
}
|
|
135
|
-
],
|
|
136
|
-
usage: {
|
|
137
|
-
prompt_tokens: response.usage.input_tokens,
|
|
138
|
-
completion_tokens: response.usage.output_tokens,
|
|
139
|
-
total_tokens: response.usage.input_tokens + response.usage.output_tokens
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
if (reasoningContent) {
|
|
143
|
-
result.reasoning_content = reasoningContent;
|
|
144
|
-
}
|
|
145
|
-
return result;
|
|
146
|
-
}
|
|
147
|
-
function convertAnthropicRequestToOpenAI(request) {
|
|
148
|
-
const messages = [];
|
|
149
|
-
if (request.system) {
|
|
150
|
-
if (typeof request.system === "string") {
|
|
151
|
-
messages.push({ role: "system", content: request.system });
|
|
152
|
-
} else if (Array.isArray(request.system)) {
|
|
153
|
-
const systemText = request.system.filter((s) => s.type === "text").map((s) => s.text).join("\n");
|
|
154
|
-
messages.push({ role: "system", content: systemText });
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
for (const msg of request.messages) {
|
|
158
|
-
if (typeof msg.content === "string") {
|
|
159
|
-
messages.push({
|
|
160
|
-
role: msg.role,
|
|
161
|
-
content: msg.content
|
|
162
|
-
});
|
|
163
|
-
} else if (Array.isArray(msg.content)) {
|
|
164
|
-
const openaiContent = [];
|
|
165
|
-
const toolCalls = [];
|
|
166
|
-
let toolResultId;
|
|
167
|
-
let toolResultContent;
|
|
168
|
-
for (const part of msg.content) {
|
|
169
|
-
if (part.type === "text") {
|
|
170
|
-
openaiContent.push({ type: "text", text: part.text });
|
|
171
|
-
} else if (part.type === "image") {
|
|
172
|
-
if (part.source.type === "base64") {
|
|
173
|
-
openaiContent.push({
|
|
174
|
-
type: "image_url",
|
|
175
|
-
image_url: {
|
|
176
|
-
url: `data:${part.source.media_type};base64,${part.source.data}`
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
} else if (part.source.url) {
|
|
180
|
-
openaiContent.push({
|
|
181
|
-
type: "image_url",
|
|
182
|
-
image_url: { url: part.source.url }
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
} else if (part.type === "tool_use") {
|
|
186
|
-
toolCalls.push({
|
|
187
|
-
id: part.id,
|
|
188
|
-
type: "function",
|
|
189
|
-
function: {
|
|
190
|
-
name: part.name,
|
|
191
|
-
arguments: JSON.stringify(part.input)
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
} else if (part.type === "tool_result") {
|
|
195
|
-
toolResultId = part.tool_use_id;
|
|
196
|
-
toolResultContent = typeof part.content === "string" ? part.content : JSON.stringify(part.content);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
if (toolResultId && toolResultContent !== void 0) {
|
|
200
|
-
messages.push({
|
|
201
|
-
role: "tool",
|
|
202
|
-
tool_call_id: toolResultId,
|
|
203
|
-
content: toolResultContent
|
|
204
|
-
});
|
|
205
|
-
} else if (toolCalls.length > 0) {
|
|
206
|
-
messages.push({
|
|
207
|
-
role: "assistant",
|
|
208
|
-
content: openaiContent.length > 0 ? openaiContent.map((c) => c.type === "text" ? c.text : "").join("\n") : null,
|
|
209
|
-
tool_calls: toolCalls
|
|
210
|
-
});
|
|
211
|
-
} else {
|
|
212
|
-
messages.push({
|
|
213
|
-
role: msg.role,
|
|
214
|
-
content: openaiContent.length > 0 ? openaiContent : null
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
const result = {
|
|
220
|
-
model: request.model,
|
|
221
|
-
messages,
|
|
222
|
-
max_tokens: request.max_tokens,
|
|
223
|
-
stream: request.stream
|
|
224
|
-
};
|
|
225
|
-
if (request.tools && request.tools.length > 0) {
|
|
226
|
-
result.tools = request.tools.map((tool) => ({
|
|
227
|
-
type: "function",
|
|
228
|
-
function: {
|
|
229
|
-
name: tool.name,
|
|
230
|
-
description: tool.description,
|
|
231
|
-
parameters: tool.input_schema
|
|
232
|
-
}
|
|
233
|
-
}));
|
|
234
|
-
if (request.tool_choice) {
|
|
235
|
-
if (request.tool_choice.type === "auto") {
|
|
236
|
-
result.tool_choice = "auto";
|
|
237
|
-
} else if (request.tool_choice.type === "any") {
|
|
238
|
-
result.tool_choice = "required";
|
|
239
|
-
} else if (request.tool_choice.type === "tool") {
|
|
240
|
-
result.tool_choice = {
|
|
241
|
-
type: "function",
|
|
242
|
-
function: { name: request.tool_choice.name }
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return result;
|
|
248
|
-
}
|
|
249
|
-
function convertAnthropicToOpenAIWithThinking(response) {
|
|
250
|
-
const baseResult = convertAnthropicToOpenAI(response);
|
|
251
|
-
const thinkingBlocks = response.content.filter(
|
|
252
|
-
(block) => block.type === "thinking"
|
|
253
|
-
);
|
|
254
|
-
if (thinkingBlocks.length > 0) {
|
|
255
|
-
baseResult.reasoning_content = thinkingBlocks.map((block) => "thinking" in block ? block.thinking : "").join("\n");
|
|
256
|
-
}
|
|
257
|
-
return baseResult;
|
|
258
|
-
}
|
|
259
|
-
async function* convertAnthropicStreamToOpenAI(anthropicStream) {
|
|
260
|
-
let messageId = "";
|
|
261
|
-
let model = "unknown";
|
|
262
|
-
const toolCalls = /* @__PURE__ */ new Map();
|
|
263
|
-
for await (const line of anthropicStream) {
|
|
264
|
-
if (!line.startsWith("data:")) continue;
|
|
265
|
-
const data = line.slice(5).trim();
|
|
266
|
-
try {
|
|
267
|
-
const event = JSON.parse(data);
|
|
268
|
-
switch (event.type) {
|
|
269
|
-
case "message_start":
|
|
270
|
-
messageId = event.message?.id || `chatcmpl-${Date.now()}`;
|
|
271
|
-
model = event.message?.model || model;
|
|
272
|
-
break;
|
|
273
|
-
case "content_block_delta":
|
|
274
|
-
if (event.delta?.type === "text_delta") {
|
|
275
|
-
yield `data: ${JSON.stringify({
|
|
276
|
-
id: messageId,
|
|
277
|
-
object: "chat.completion.chunk",
|
|
278
|
-
created: Math.floor(Date.now() / 1e3),
|
|
279
|
-
model,
|
|
280
|
-
choices: [{
|
|
281
|
-
index: 0,
|
|
282
|
-
delta: { content: event.delta.text },
|
|
283
|
-
finish_reason: null
|
|
284
|
-
}]
|
|
285
|
-
})}
|
|
286
5
|
|
|
287
|
-
`;
|
|
288
|
-
} else if (event.delta?.type === "thinking_delta") {
|
|
289
|
-
yield `data: ${JSON.stringify({
|
|
290
|
-
id: messageId,
|
|
291
|
-
object: "chat.completion.chunk",
|
|
292
|
-
created: Math.floor(Date.now() / 1e3),
|
|
293
|
-
model,
|
|
294
|
-
choices: [{
|
|
295
|
-
index: 0,
|
|
296
|
-
delta: { reasoning_content: event.delta.thinking },
|
|
297
|
-
finish_reason: null
|
|
298
|
-
}]
|
|
299
|
-
})}
|
|
300
6
|
|
|
301
|
-
`;
|
|
302
|
-
} else if (event.delta?.type === "input_json_delta") {
|
|
303
|
-
const toolIndex = event.index || 0;
|
|
304
|
-
const tc = toolCalls.get(toolIndex);
|
|
305
|
-
if (tc) {
|
|
306
|
-
yield `data: ${JSON.stringify({
|
|
307
|
-
id: messageId,
|
|
308
|
-
object: "chat.completion.chunk",
|
|
309
|
-
created: Math.floor(Date.now() / 1e3),
|
|
310
|
-
model,
|
|
311
|
-
choices: [{
|
|
312
|
-
index: 0,
|
|
313
|
-
delta: {
|
|
314
|
-
tool_calls: [{
|
|
315
|
-
index: toolIndex,
|
|
316
|
-
function: { arguments: event.delta.partial_json }
|
|
317
|
-
}]
|
|
318
|
-
},
|
|
319
|
-
finish_reason: null
|
|
320
|
-
}]
|
|
321
|
-
})}
|
|
322
7
|
|
|
323
|
-
`;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
break;
|
|
327
|
-
case "content_block_start":
|
|
328
|
-
if (event.content_block?.type === "tool_use") {
|
|
329
|
-
const toolIndex = event.index || 0;
|
|
330
|
-
toolCalls.set(toolIndex, {
|
|
331
|
-
id: event.content_block.id,
|
|
332
|
-
name: event.content_block.name,
|
|
333
|
-
arguments: ""
|
|
334
|
-
});
|
|
335
|
-
yield `data: ${JSON.stringify({
|
|
336
|
-
id: messageId,
|
|
337
|
-
object: "chat.completion.chunk",
|
|
338
|
-
created: Math.floor(Date.now() / 1e3),
|
|
339
|
-
model,
|
|
340
|
-
choices: [{
|
|
341
|
-
index: 0,
|
|
342
|
-
delta: {
|
|
343
|
-
tool_calls: [{
|
|
344
|
-
index: toolIndex,
|
|
345
|
-
id: event.content_block.id,
|
|
346
|
-
type: "function",
|
|
347
|
-
function: { name: event.content_block.name, arguments: "" }
|
|
348
|
-
}]
|
|
349
|
-
},
|
|
350
|
-
finish_reason: null
|
|
351
|
-
}]
|
|
352
|
-
})}
|
|
353
8
|
|
|
354
|
-
`;
|
|
355
|
-
}
|
|
356
|
-
break;
|
|
357
|
-
case "message_delta":
|
|
358
|
-
if (event.delta?.stop_reason) {
|
|
359
|
-
const finishReason = mapAnthropicStopReason(event.delta.stop_reason);
|
|
360
|
-
yield `data: ${JSON.stringify({
|
|
361
|
-
id: messageId,
|
|
362
|
-
object: "chat.completion.chunk",
|
|
363
|
-
created: Math.floor(Date.now() / 1e3),
|
|
364
|
-
model,
|
|
365
|
-
choices: [{
|
|
366
|
-
index: 0,
|
|
367
|
-
delta: {},
|
|
368
|
-
finish_reason: finishReason
|
|
369
|
-
}],
|
|
370
|
-
usage: event.usage ? {
|
|
371
|
-
prompt_tokens: event.usage.input_tokens || 0,
|
|
372
|
-
completion_tokens: event.usage.output_tokens || 0,
|
|
373
|
-
total_tokens: (event.usage.input_tokens || 0) + (event.usage.output_tokens || 0)
|
|
374
|
-
} : void 0
|
|
375
|
-
})}
|
|
376
9
|
|
|
377
|
-
`;
|
|
378
|
-
}
|
|
379
|
-
break;
|
|
380
|
-
case "message_stop":
|
|
381
|
-
yield "data: [DONE]\n\n";
|
|
382
|
-
break;
|
|
383
|
-
}
|
|
384
|
-
} catch {
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
10
|
|
|
389
|
-
// src/api-converter/openai-to-anthropic.ts
|
|
390
|
-
function convertOpenAIToAnthropic(request, config) {
|
|
391
|
-
const messages = [];
|
|
392
|
-
let system;
|
|
393
|
-
for (const msg of request.messages) {
|
|
394
|
-
if (msg.role === "system") {
|
|
395
|
-
if (typeof msg.content === "string") {
|
|
396
|
-
system = msg.content;
|
|
397
|
-
} else if (Array.isArray(msg.content)) {
|
|
398
|
-
system = msg.content.filter((p) => p.type === "text").map((p) => ({ type: "text", text: p.text || "" }));
|
|
399
|
-
}
|
|
400
|
-
continue;
|
|
401
|
-
}
|
|
402
|
-
if (msg.role === "tool" && msg.tool_call_id) {
|
|
403
|
-
const toolResult = {
|
|
404
|
-
type: "tool_result",
|
|
405
|
-
tool_use_id: msg.tool_call_id,
|
|
406
|
-
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
|
|
407
|
-
};
|
|
408
|
-
const lastMsg = messages[messages.length - 1];
|
|
409
|
-
if (lastMsg && lastMsg.role === "user" && Array.isArray(lastMsg.content)) {
|
|
410
|
-
lastMsg.content.push(toolResult);
|
|
411
|
-
} else {
|
|
412
|
-
messages.push({ role: "user", content: [toolResult] });
|
|
413
|
-
}
|
|
414
|
-
continue;
|
|
415
|
-
}
|
|
416
|
-
if (msg.role === "assistant" && msg.tool_calls && msg.tool_calls.length > 0) {
|
|
417
|
-
const content = [];
|
|
418
|
-
if (msg.content) {
|
|
419
|
-
if (typeof msg.content === "string") {
|
|
420
|
-
content.push({ type: "text", text: msg.content });
|
|
421
|
-
} else if (Array.isArray(msg.content)) {
|
|
422
|
-
for (const part of msg.content) {
|
|
423
|
-
if (part.type === "text" && part.text) {
|
|
424
|
-
content.push({ type: "text", text: part.text });
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
for (const tc of msg.tool_calls) {
|
|
430
|
-
content.push({
|
|
431
|
-
type: "tool_use",
|
|
432
|
-
id: tc.id,
|
|
433
|
-
name: tc.function.name,
|
|
434
|
-
input: JSON.parse(tc.function.arguments || "{}")
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
messages.push({ role: "assistant", content });
|
|
438
|
-
continue;
|
|
439
|
-
}
|
|
440
|
-
if (msg.role === "user" || msg.role === "assistant") {
|
|
441
|
-
const content = convertOpenAIMessageContent(msg);
|
|
442
|
-
messages.push({ role: msg.role, content });
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
let model = request.model;
|
|
446
|
-
if (config.modelMapping && config.modelMapping[model]) {
|
|
447
|
-
model = config.modelMapping[model];
|
|
448
|
-
} else if (!model.startsWith("claude")) {
|
|
449
|
-
model = config.defaultModel;
|
|
450
|
-
}
|
|
451
|
-
const result = {
|
|
452
|
-
model,
|
|
453
|
-
// Anthropic requires max_tokens; use high default (16384) if not explicitly set
|
|
454
|
-
// This prevents output truncation for long responses
|
|
455
|
-
max_tokens: request.max_tokens || 16384,
|
|
456
|
-
messages,
|
|
457
|
-
stream: request.stream
|
|
458
|
-
};
|
|
459
|
-
if (system) {
|
|
460
|
-
result.system = system;
|
|
461
|
-
}
|
|
462
|
-
if (request.tools && request.tools.length > 0) {
|
|
463
|
-
result.tools = request.tools.map(convertOpenAITool);
|
|
464
|
-
if (request.tool_choice) {
|
|
465
|
-
if (request.tool_choice === "auto") {
|
|
466
|
-
result.tool_choice = { type: "auto" };
|
|
467
|
-
} else if (request.tool_choice === "required") {
|
|
468
|
-
result.tool_choice = { type: "any" };
|
|
469
|
-
} else if (typeof request.tool_choice === "object") {
|
|
470
|
-
result.tool_choice = {
|
|
471
|
-
type: "tool",
|
|
472
|
-
name: request.tool_choice.function.name
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
return result;
|
|
478
|
-
}
|
|
479
|
-
function convertOpenAIMessageContent(msg) {
|
|
480
|
-
if (typeof msg.content === "string") {
|
|
481
|
-
return msg.content;
|
|
482
|
-
}
|
|
483
|
-
if (!msg.content || !Array.isArray(msg.content)) {
|
|
484
|
-
return "";
|
|
485
|
-
}
|
|
486
|
-
const parts = [];
|
|
487
|
-
for (const part of msg.content) {
|
|
488
|
-
if (part.type === "text" && part.text) {
|
|
489
|
-
parts.push({ type: "text", text: part.text });
|
|
490
|
-
} else if (part.type === "image_url" && part.image_url) {
|
|
491
|
-
const url = part.image_url.url;
|
|
492
|
-
if (url.startsWith("data:")) {
|
|
493
|
-
const match = url.match(/^data:([^;]+);base64,(.+)$/);
|
|
494
|
-
if (match) {
|
|
495
|
-
parts.push({
|
|
496
|
-
type: "image",
|
|
497
|
-
source: {
|
|
498
|
-
type: "base64",
|
|
499
|
-
media_type: match[1],
|
|
500
|
-
data: match[2]
|
|
501
|
-
}
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
} else {
|
|
505
|
-
parts.push({
|
|
506
|
-
type: "image",
|
|
507
|
-
source: { type: "url", url }
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
return parts.length > 0 ? parts : "";
|
|
513
|
-
}
|
|
514
|
-
function convertOpenAIResponseToAnthropic(response) {
|
|
515
|
-
const content = [];
|
|
516
|
-
const choice = response.choices[0];
|
|
517
|
-
if (choice.message.content) {
|
|
518
|
-
content.push({ type: "text", text: choice.message.content });
|
|
519
|
-
}
|
|
520
|
-
if (choice.message.tool_calls) {
|
|
521
|
-
for (const tc of choice.message.tool_calls) {
|
|
522
|
-
content.push({
|
|
523
|
-
type: "tool_use",
|
|
524
|
-
id: tc.id,
|
|
525
|
-
name: tc.function.name,
|
|
526
|
-
input: JSON.parse(tc.function.arguments || "{}")
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
if (response.reasoning_content) {
|
|
531
|
-
content.unshift({
|
|
532
|
-
type: "thinking",
|
|
533
|
-
thinking: response.reasoning_content
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
return {
|
|
537
|
-
id: response.id,
|
|
538
|
-
type: "message",
|
|
539
|
-
role: "assistant",
|
|
540
|
-
model: response.model,
|
|
541
|
-
content,
|
|
542
|
-
stop_reason: mapOpenAIFinishReason(choice.finish_reason),
|
|
543
|
-
usage: {
|
|
544
|
-
input_tokens: response.usage.prompt_tokens,
|
|
545
|
-
output_tokens: response.usage.completion_tokens
|
|
546
|
-
}
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
function convertOpenAIToAnthropicWithThinking(request, config) {
|
|
550
|
-
const baseResult = convertOpenAIToAnthropic(request, config);
|
|
551
|
-
if (config.enableThinking) {
|
|
552
|
-
baseResult.thinking = {
|
|
553
|
-
type: "enabled",
|
|
554
|
-
budget_tokens: config.thinkingBudget || 1e4
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
return baseResult;
|
|
558
|
-
}
|
|
559
|
-
async function* convertOpenAIStreamToAnthropic(openaiStream) {
|
|
560
|
-
const messageId = `msg_${Date.now()}`;
|
|
561
|
-
let hasStarted = false;
|
|
562
|
-
let hasTextContentStarted = false;
|
|
563
|
-
let hasThinkingContentStarted = false;
|
|
564
|
-
let contentIndex = 0;
|
|
565
|
-
let model = "unknown";
|
|
566
|
-
const toolCalls = /* @__PURE__ */ new Map();
|
|
567
|
-
for await (const line of openaiStream) {
|
|
568
|
-
if (!line.startsWith("data:")) continue;
|
|
569
|
-
const data = line.slice(5).trim();
|
|
570
|
-
if (data === "[DONE]") {
|
|
571
|
-
if (hasTextContentStarted) {
|
|
572
|
-
yield `event: content_block_stop
|
|
573
|
-
data: ${JSON.stringify({
|
|
574
|
-
type: "content_block_stop",
|
|
575
|
-
index: contentIndex
|
|
576
|
-
})}
|
|
577
11
|
|
|
578
|
-
|
|
579
|
-
contentIndex++;
|
|
580
|
-
hasTextContentStarted = false;
|
|
581
|
-
}
|
|
582
|
-
if (hasThinkingContentStarted) {
|
|
583
|
-
yield `event: content_block_stop
|
|
584
|
-
data: ${JSON.stringify({
|
|
585
|
-
type: "content_block_stop",
|
|
586
|
-
index: contentIndex
|
|
587
|
-
})}
|
|
12
|
+
var _chunkSUEGJ75Dcjs = require('./chunk-SUEGJ75D.cjs');
|
|
588
13
|
|
|
589
|
-
`;
|
|
590
|
-
contentIndex++;
|
|
591
|
-
hasThinkingContentStarted = false;
|
|
592
|
-
}
|
|
593
|
-
for (const [, tc] of toolCalls) {
|
|
594
|
-
yield `event: content_block_stop
|
|
595
|
-
data: ${JSON.stringify({
|
|
596
|
-
type: "content_block_stop",
|
|
597
|
-
index: tc.contentIndex
|
|
598
|
-
})}
|
|
599
14
|
|
|
600
|
-
`;
|
|
601
|
-
}
|
|
602
|
-
yield `event: message_delta
|
|
603
|
-
data: ${JSON.stringify({
|
|
604
|
-
type: "message_delta",
|
|
605
|
-
delta: { stop_reason: "end_turn", stop_sequence: null },
|
|
606
|
-
usage: { input_tokens: 0, output_tokens: 0 }
|
|
607
|
-
})}
|
|
608
15
|
|
|
609
|
-
`;
|
|
610
|
-
yield `event: message_stop
|
|
611
|
-
data: ${JSON.stringify({ type: "message_stop" })}
|
|
612
16
|
|
|
613
|
-
`;
|
|
614
|
-
break;
|
|
615
|
-
}
|
|
616
|
-
try {
|
|
617
|
-
const chunk = JSON.parse(data);
|
|
618
|
-
model = chunk.model || model;
|
|
619
|
-
if (!hasStarted) {
|
|
620
|
-
hasStarted = true;
|
|
621
|
-
yield `event: message_start
|
|
622
|
-
data: ${JSON.stringify({
|
|
623
|
-
type: "message_start",
|
|
624
|
-
message: {
|
|
625
|
-
id: messageId,
|
|
626
|
-
type: "message",
|
|
627
|
-
role: "assistant",
|
|
628
|
-
content: [],
|
|
629
|
-
model,
|
|
630
|
-
stop_reason: null,
|
|
631
|
-
stop_sequence: null,
|
|
632
|
-
usage: { input_tokens: 0, output_tokens: 0 }
|
|
633
|
-
}
|
|
634
|
-
})}
|
|
635
17
|
|
|
636
|
-
`;
|
|
637
|
-
}
|
|
638
|
-
const choice = chunk.choices?.[0];
|
|
639
|
-
if (!choice) continue;
|
|
640
|
-
if (choice.delta?.content) {
|
|
641
|
-
if (!hasTextContentStarted) {
|
|
642
|
-
hasTextContentStarted = true;
|
|
643
|
-
yield `event: content_block_start
|
|
644
|
-
data: ${JSON.stringify({
|
|
645
|
-
type: "content_block_start",
|
|
646
|
-
index: contentIndex,
|
|
647
|
-
content_block: { type: "text", text: "" }
|
|
648
|
-
})}
|
|
649
18
|
|
|
650
|
-
`;
|
|
651
|
-
}
|
|
652
|
-
yield `event: content_block_delta
|
|
653
|
-
data: ${JSON.stringify({
|
|
654
|
-
type: "content_block_delta",
|
|
655
|
-
index: contentIndex,
|
|
656
|
-
delta: { type: "text_delta", text: choice.delta.content }
|
|
657
|
-
})}
|
|
658
19
|
|
|
659
|
-
`;
|
|
660
|
-
}
|
|
661
|
-
if (choice.delta?.reasoning_content) {
|
|
662
|
-
if (hasTextContentStarted) {
|
|
663
|
-
yield `event: content_block_stop
|
|
664
|
-
data: ${JSON.stringify({
|
|
665
|
-
type: "content_block_stop",
|
|
666
|
-
index: contentIndex
|
|
667
|
-
})}
|
|
668
20
|
|
|
669
|
-
`;
|
|
670
|
-
contentIndex++;
|
|
671
|
-
hasTextContentStarted = false;
|
|
672
|
-
}
|
|
673
|
-
if (!hasThinkingContentStarted) {
|
|
674
|
-
hasThinkingContentStarted = true;
|
|
675
|
-
yield `event: content_block_start
|
|
676
|
-
data: ${JSON.stringify({
|
|
677
|
-
type: "content_block_start",
|
|
678
|
-
index: contentIndex,
|
|
679
|
-
content_block: { type: "thinking", thinking: "" }
|
|
680
|
-
})}
|
|
681
21
|
|
|
682
|
-
`;
|
|
683
|
-
}
|
|
684
|
-
yield `event: content_block_delta
|
|
685
|
-
data: ${JSON.stringify({
|
|
686
|
-
type: "content_block_delta",
|
|
687
|
-
index: contentIndex,
|
|
688
|
-
delta: { type: "thinking_delta", thinking: choice.delta.reasoning_content }
|
|
689
|
-
})}
|
|
690
22
|
|
|
691
|
-
`;
|
|
692
|
-
}
|
|
693
|
-
if (choice.delta?.tool_calls) {
|
|
694
|
-
if (hasTextContentStarted) {
|
|
695
|
-
yield `event: content_block_stop
|
|
696
|
-
data: ${JSON.stringify({
|
|
697
|
-
type: "content_block_stop",
|
|
698
|
-
index: contentIndex
|
|
699
|
-
})}
|
|
700
23
|
|
|
701
|
-
|
|
702
|
-
contentIndex++;
|
|
703
|
-
hasTextContentStarted = false;
|
|
704
|
-
}
|
|
705
|
-
for (const toolCall of choice.delta.tool_calls) {
|
|
706
|
-
const toolIndex = toolCall.index ?? 0;
|
|
707
|
-
if (!toolCalls.has(toolIndex)) {
|
|
708
|
-
const toolContentIndex = contentIndex++;
|
|
709
|
-
const toolId = toolCall.id || `call_${Date.now()}_${toolIndex}`;
|
|
710
|
-
const toolName = toolCall.function?.name || `tool_${toolIndex}`;
|
|
711
|
-
toolCalls.set(toolIndex, { id: toolId, name: toolName, contentIndex: toolContentIndex });
|
|
712
|
-
yield `event: content_block_start
|
|
713
|
-
data: ${JSON.stringify({
|
|
714
|
-
type: "content_block_start",
|
|
715
|
-
index: toolContentIndex,
|
|
716
|
-
content_block: { type: "tool_use", id: toolId, name: toolName, input: {} }
|
|
717
|
-
})}
|
|
718
|
-
|
|
719
|
-
`;
|
|
720
|
-
}
|
|
721
|
-
if (toolCall.function?.arguments) {
|
|
722
|
-
const tc = toolCalls.get(toolIndex);
|
|
723
|
-
yield `event: content_block_delta
|
|
724
|
-
data: ${JSON.stringify({
|
|
725
|
-
type: "content_block_delta",
|
|
726
|
-
index: tc.contentIndex,
|
|
727
|
-
delta: { type: "input_json_delta", partial_json: toolCall.function.arguments }
|
|
728
|
-
})}
|
|
729
|
-
|
|
730
|
-
`;
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
if (choice.finish_reason) {
|
|
735
|
-
if (hasTextContentStarted) {
|
|
736
|
-
yield `event: content_block_stop
|
|
737
|
-
data: ${JSON.stringify({
|
|
738
|
-
type: "content_block_stop",
|
|
739
|
-
index: contentIndex
|
|
740
|
-
})}
|
|
741
|
-
|
|
742
|
-
`;
|
|
743
|
-
contentIndex++;
|
|
744
|
-
hasTextContentStarted = false;
|
|
745
|
-
}
|
|
746
|
-
if (hasThinkingContentStarted) {
|
|
747
|
-
yield `event: content_block_stop
|
|
748
|
-
data: ${JSON.stringify({
|
|
749
|
-
type: "content_block_stop",
|
|
750
|
-
index: contentIndex
|
|
751
|
-
})}
|
|
752
|
-
|
|
753
|
-
`;
|
|
754
|
-
contentIndex++;
|
|
755
|
-
hasThinkingContentStarted = false;
|
|
756
|
-
}
|
|
757
|
-
for (const [, tc] of toolCalls) {
|
|
758
|
-
yield `event: content_block_stop
|
|
759
|
-
data: ${JSON.stringify({
|
|
760
|
-
type: "content_block_stop",
|
|
761
|
-
index: tc.contentIndex
|
|
762
|
-
})}
|
|
763
|
-
|
|
764
|
-
`;
|
|
765
|
-
}
|
|
766
|
-
const stopReason = mapOpenAIFinishReason(choice.finish_reason);
|
|
767
|
-
yield `event: message_delta
|
|
768
|
-
data: ${JSON.stringify({
|
|
769
|
-
type: "message_delta",
|
|
770
|
-
delta: { stop_reason: stopReason, stop_sequence: null },
|
|
771
|
-
usage: {
|
|
772
|
-
input_tokens: chunk.usage?.prompt_tokens || 0,
|
|
773
|
-
output_tokens: chunk.usage?.completion_tokens || 0
|
|
774
|
-
}
|
|
775
|
-
})}
|
|
776
|
-
|
|
777
|
-
`;
|
|
778
|
-
yield `event: message_stop
|
|
779
|
-
data: ${JSON.stringify({ type: "message_stop" })}
|
|
780
|
-
|
|
781
|
-
`;
|
|
782
|
-
}
|
|
783
|
-
} catch {
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
788
|
-
0 && (module.exports = {
|
|
789
|
-
convertAnthropicRequestToOpenAI,
|
|
790
|
-
convertAnthropicStreamToOpenAI,
|
|
791
|
-
convertAnthropicToOpenAI,
|
|
792
|
-
convertAnthropicToOpenAIWithThinking,
|
|
793
|
-
convertOpenAIResponseToAnthropic,
|
|
794
|
-
convertOpenAIStreamToAnthropic,
|
|
795
|
-
convertOpenAIToAnthropic,
|
|
796
|
-
convertOpenAIToAnthropicWithThinking,
|
|
797
|
-
hasImageContent,
|
|
798
|
-
hasThinkingEnabled
|
|
799
|
-
});
|
|
24
|
+
exports.convertAnthropicRequestToOpenAI = _chunkSUEGJ75Dcjs.convertAnthropicRequestToOpenAI; exports.convertAnthropicStreamToOpenAI = _chunkSUEGJ75Dcjs.convertAnthropicStreamToOpenAI; exports.convertAnthropicToOpenAI = _chunkSUEGJ75Dcjs.convertAnthropicToOpenAI; exports.convertAnthropicToOpenAIWithThinking = _chunkSUEGJ75Dcjs.convertAnthropicToOpenAIWithThinking; exports.convertOpenAIResponseToAnthropic = _chunkSUEGJ75Dcjs.convertOpenAIResponseToAnthropic; exports.convertOpenAIStreamToAnthropic = _chunkSUEGJ75Dcjs.convertOpenAIStreamToAnthropic; exports.convertOpenAIToAnthropic = _chunkSUEGJ75Dcjs.convertOpenAIToAnthropic; exports.convertOpenAIToAnthropicWithThinking = _chunkSUEGJ75Dcjs.convertOpenAIToAnthropicWithThinking; exports.hasImageContent = _chunkSUEGJ75Dcjs.hasImageContent; exports.hasThinkingEnabled = _chunkSUEGJ75Dcjs.hasThinkingEnabled;
|