@vibe-lark/larkpal 0.1.86 → 0.1.87
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/account-id-BM1T6029-BzQ_cMoi.mjs +1 -0
- package/dist/activation-context--5yu1dPF-XV0Y0pTy.mjs +1 -0
- package/dist/anthropic-CFZUCb1w.mjs +39 -0
- package/dist/assistant-visible-text-DuFWokAt-BOJV_zwc.mjs +9 -0
- package/dist/azure-openai-responses-BEuiMaF-.mjs +1 -0
- package/dist/boundary-file-read-BSd9MXPy-gnNVhPKT.mjs +1 -0
- package/dist/browser-lifecycle-cleanup-BdNsMhMD-BM97qA_M.mjs +1 -0
- package/dist/build-Bkj0hOS2.mjs +3 -0
- package/dist/bundled-compat-BpaDaAAu-DJtrIX6i.mjs +27 -0
- package/dist/bundled-dir-U738ay4K-BxbzrJOo.mjs +1 -0
- package/dist/call-DimWbpgJ-B4pv55RH.mjs +20 -0
- package/dist/channel-bootstrap.runtime-BVclcGv1-CEZ0-JP9.mjs +1 -0
- package/dist/channel-bootstrap.runtime-Cwcr38m2-Dt6QlQkX.mjs +1 -0
- package/dist/chunk-DHbaKqs-.mjs +1 -0
- package/dist/cli.mjs +7 -92
- package/dist/command-format-LSnUCVVF-Dn4h9IOh.mjs +16 -0
- package/dist/config-Bim2pi8a-03N-28sw.mjs +1 -0
- package/dist/delivery-context.shared-j5hC5qb1-BSLQG47q.mjs +1 -0
- package/dist/diagnostic-ClMwNnUA-BMKvPQJT.mjs +1 -0
- package/dist/dist-J5UB83Ws.mjs +601 -0
- package/dist/dist-coestTs9.mjs +5 -0
- package/dist/env-api-keys-Cuz5irWW.mjs +1 -0
- package/dist/event-stream-B7Ei41Bu.mjs +1 -0
- package/dist/facade-loader-DFzIYYt_-4bzFvy-b.mjs +1 -0
- package/dist/from-Ba69_5cR.mjs +14 -0
- package/dist/gateway-method-policy-C7rf0SeV-CTJcMQCE.mjs +1 -0
- package/dist/github-copilot-headers-BfhryVuU.mjs +1 -0
- package/dist/google-ABo-1guT.mjs +1 -0
- package/dist/google-gemini-cli-CGlN1zUA.mjs +2 -0
- package/dist/google-shared-C60sNhwd.mjs +301 -0
- package/dist/google-vertex-De0nAItu.mjs +1 -0
- package/dist/hash-Dw-N8Y9l.mjs +1 -0
- package/dist/headers-Bpsp70B9.mjs +1 -0
- package/dist/home-dir-C44RaPME-B5iLWwCq.mjs +1 -0
- package/dist/ids-BPsM98Uu-CJBJAeVC.mjs +1 -0
- package/dist/image-2w3cApg7-CrpUMCvm.mjs +3 -0
- package/dist/interactive-init-C5MFL5MW.mjs +8 -0
- package/dist/io-CH2g3vsv-JJtUIa_U.mjs +10 -0
- package/dist/jiti-loader-cache-Bat69wam-DNIteTtO.mjs +9 -0
- package/dist/json-file-BQRNuxmK-hRjIgOXI.mjs +1 -0
- package/dist/json-parse-BESd8UAM.mjs +3 -0
- package/dist/jws-YaZ38F_i.mjs +12 -0
- package/dist/lark-cli-provider-BLMxH6CN.mjs +4 -0
- package/dist/lark-logger-xpMKNNtY.mjs +1 -0
- package/dist/live-smoke-DpURW676.mjs +33 -0
- package/dist/load-context-mb7uvLSn-3xYwSnOZ.mjs +1 -0
- package/dist/loader-708jrx4Y-BbJRXNlQ.mjs +4 -0
- package/dist/main.mjs +153 -74571
- package/dist/manifest-registry-_hxKCS2K-OL8KK_o4.mjs +15 -0
- package/dist/mcp-server.mjs +4 -527
- package/dist/message-channel-Bk_YHfQg-n2Hw2Y0L.mjs +1 -0
- package/dist/message-channel-core-DTA--Gjh-CIh10vfo.mjs +1 -0
- package/dist/message.config.runtime-K-k4XOyq-F_h0Cgkl.mjs +1 -0
- package/dist/message.gateway.runtime-DqHOHRTQ-ge4c5p4s.mjs +1 -0
- package/dist/mistral-DyL3Zo1b.mjs +7 -0
- package/dist/model-auth-env-oyg2Hexc-DJbt9J3o.mjs +1 -0
- package/dist/models-config-BmpSQJQF-BL6S5qAo.mjs +1 -0
- package/dist/models-config.runtime-SOhLEw-f.mjs +1 -0
- package/dist/multipart-parser-B9dwXBqu.mjs +2 -0
- package/dist/oauth-25y2wc7K.mjs +75 -0
- package/dist/openai-C-rgGb7X.mjs +16 -0
- package/dist/openai-codex-responses-BbyAPsP1.mjs +7 -0
- package/dist/openai-completions-Bu5qvQzb.mjs +5 -0
- package/dist/openai-responses-pIdwQBc4.mjs +1 -0
- package/dist/openai-responses-shared-DqW1JSux.mjs +10 -0
- package/dist/paths-D6msg0S1-BO4XgM1u.mjs +1 -0
- package/dist/paths-D92DjaZ--DdtJ-zYp.mjs +1 -0
- package/dist/pi-model-discovery-Bd0TWzo8-DvSM0eWu.mjs +1 -0
- package/dist/pi-model-discovery-runtime-PrjWOmsV.mjs +1 -0
- package/dist/pi-tools.before-tool-call.runtime-Bn7uqKie-WPxU5oNX.mjs +2 -0
- package/dist/plugin-auto-enable-DdH3n9V8-Dr_bUXkG.mjs +1 -0
- package/dist/process-scoped-map-B2cWkYET-Co-i-MXA.mjs +1 -0
- package/dist/provider-discovery.runtime-DY0VWQ81.mjs +1 -0
- package/dist/provider-model-compat-CFqcq0it-BUwZENrz.mjs +1 -0
- package/dist/provider-runtime-C8rljsNs-BDvu6FW3.mjs +1 -0
- package/dist/provider-runtime-CT50mNIX-DImw7ZZu.mjs +79 -0
- package/dist/provider-stream-COLujAAo-Dpq1DSIk.mjs +248 -0
- package/dist/providers.runtime-Ba7tOlq7-B4t6ywCr.mjs +1 -0
- package/dist/public-surface-loader-BVl0NQAE-TfJ3izj1.mjs +1 -0
- package/dist/resolve-C33B7eeu-DZM_z6Wr.mjs +1 -0
- package/dist/runtime-Cym-fqI8-1GOIuRRQ.mjs +1 -0
- package/dist/runtime-channel-state-CohMybAh-BBzhl07Q.mjs +1 -0
- package/dist/runtime-snapshot-C54O1-gI-DxusscPf.mjs +1 -0
- package/dist/runtime-state-IBOIXKOx-Cw1GA1td.mjs +1 -0
- package/dist/runtime-web-tools-fallback.runtime-Ca-qn1mj-BsYE2gOd.mjs +1 -0
- package/dist/runtime-web-tools-manifest.runtime-BgxQTjmq-P6MKP9gQ.mjs +1 -0
- package/dist/runtime-web-tools-public-artifacts.runtime-D9qcoWIX-5VoyjouO.mjs +1 -0
- package/dist/session-archive.runtime-B52_5vs4-cU2tYbBz.mjs +1 -0
- package/dist/session-key-Cn2QoOyX-QZeYmbxd.mjs +1 -0
- package/dist/session-transcript-files.fs-DEeFXruQ-CXIAFSsr.mjs +1 -0
- package/dist/src-CCDx_C-U.mjs +3 -0
- package/dist/src-DACmA9V6.mjs +5 -0
- package/dist/subagent-announce-L5WsQatW--rMn240x.mjs +2 -0
- package/dist/subagent-announce.registry.runtime-DiqZyeTs-DNfNHsls.mjs +1 -0
- package/dist/subagent-registry-steer-runtime-DFgZFC0j-XYS1_qwl.mjs +1 -0
- package/dist/subagent-system-prompt-C1qnN--K-CsU4f97T.mjs +23 -0
- package/dist/target-parsing-loaded-DKkb6jJY-B830OA1a.mjs +12 -0
- package/dist/task-registry-delivery-runtime-Dd1CUkZF-B2Hj2k8C.mjs +16 -0
- package/dist/task-registry-delivery-runtime-ragbeVx5-Bdvo2Q5u.mjs +1 -0
- package/dist/thinking-Bh-7MqXz-uApNUe6g.mjs +1 -0
- package/dist/transcript-E_-ISOkD-VTwb782D.mjs +5 -0
- package/dist/transcript.runtime-BqhvZZdl-B4E0TiX5.mjs +1 -0
- package/dist/transform-messages-BTA3xbAI.mjs +1 -0
- package/dist/web-provider-public-artifacts-BlpRwIUS-DbVhDOrY.mjs +1 -0
- package/dist/web-search-providers.runtime--0aUtC3b-Bjh4Bmrz.mjs +1 -0
- package/package.json +2 -3
- package/dist/account-id-BM1T6029-DYjVxojW.mjs +0 -46
- package/dist/activation-context--5yu1dPF-Bwsn3moT.mjs +0 -172
- package/dist/anthropic-TH8ERTXK.mjs +0 -5962
- package/dist/assistant-visible-text-DuFWokAt-CsbII5KS.mjs +0 -596
- package/dist/azure-openai-responses-Bt_Ag9Er.mjs +0 -166
- package/dist/boundary-file-read-BSd9MXPy--KThL5e6.mjs +0 -594
- package/dist/browser-lifecycle-cleanup-BdNsMhMD-O3tnAM4i.mjs +0 -60
- package/dist/build-DgTrEpge.mjs +0 -3333
- package/dist/bundled-compat-BpaDaAAu-D7oazKjD.mjs +0 -5216
- package/dist/bundled-dir-U738ay4K-DXK0q_TV.mjs +0 -258
- package/dist/call-DimWbpgJ-ColD4W-y.mjs +0 -9993
- package/dist/channel-bootstrap.runtime-BVclcGv1-DJv_Z-Kr.mjs +0 -2
- package/dist/channel-bootstrap.runtime-Cwcr38m2-VRfVCR-i.mjs +0 -33
- package/dist/chunk-D6SyT4dJ.mjs +0 -36
- package/dist/command-format-LSnUCVVF-BQ2SMKka.mjs +0 -685
- package/dist/config-Bim2pi8a-BQUdfiEi.mjs +0 -9
- package/dist/delivery-context.shared-j5hC5qb1-CI83RXXZ.mjs +0 -72
- package/dist/diagnostic-ClMwNnUA-D6nUtLnb.mjs +0 -140
- package/dist/dist-CEGw8-2W.mjs +0 -429
- package/dist/dist-DD2aJ2UL.mjs +0 -125135
- package/dist/env-api-keys-BVvSg7T2.mjs +0 -68
- package/dist/event-stream-xaQWmyas.mjs +0 -15226
- package/dist/facade-loader-DFzIYYt_-CIr4HKtE.mjs +0 -194
- package/dist/from-DF7cl2wz.mjs +0 -3842
- package/dist/gateway-method-policy-C7rf0SeV-CJQMEYIE.mjs +0 -28
- package/dist/github-copilot-headers-DjqWtUoP.mjs +0 -22
- package/dist/google-C2pVrgBZ.mjs +0 -336
- package/dist/google-gemini-cli-BBxgS5Ho.mjs +0 -623
- package/dist/google-shared-BsWgwEk1.mjs +0 -22791
- package/dist/google-vertex-BsVLJrrC.mjs +0 -358
- package/dist/hash-DAFtW_W7.mjs +0 -16
- package/dist/headers-R3HdCbAE.mjs +0 -8
- package/dist/home-dir-C44RaPME-CBRS4HLP.mjs +0 -93
- package/dist/ids-BPsM98Uu-CwuxvUai.mjs +0 -77
- package/dist/image-2w3cApg7-CxpHvoB5.mjs +0 -207
- package/dist/interactive-init-BXQBalNr.mjs +0 -450
- package/dist/io-CH2g3vsv-BOGlLlB8.mjs +0 -26218
- package/dist/jiti-loader-cache-Bat69wam-D6hCxboy.mjs +0 -5049
- package/dist/json-file-BQRNuxmK-DhJM5NsG.mjs +0 -108
- package/dist/json-parse-v_HIJjjI.mjs +0 -381
- package/dist/jws-GFcTvvVT.mjs +0 -2291
- package/dist/lark-cli-provider-BARgbbmo.mjs +0 -554
- package/dist/lark-logger-D7_pEVQc.mjs +0 -143
- package/dist/live-smoke-BhkBOcH9.mjs +0 -7135
- package/dist/load-context-mb7uvLSn-B10MAi3I.mjs +0 -29
- package/dist/loader-708jrx4Y-BOswuvpe.mjs +0 -5053
- package/dist/manifest-registry-_hxKCS2K-CZdeyN0f.mjs +0 -3512
- package/dist/message-channel-Bk_YHfQg-AeNrPPpp.mjs +0 -50
- package/dist/message-channel-core-DTA--Gjh-CY4Tkb7N.mjs +0 -29
- package/dist/message.config.runtime-K-k4XOyq-DZTmXomP.mjs +0 -2
- package/dist/message.gateway.runtime-DqHOHRTQ-DH4ml0YF.mjs +0 -2
- package/dist/mistral-CaR4DiLu.mjs +0 -28657
- package/dist/model-auth-env-oyg2Hexc-DU_rOUU5.mjs +0 -1306
- package/dist/models-config-BmpSQJQF-Gfvh1n3A.mjs +0 -1282
- package/dist/models-config.runtime-BsU_22xk.mjs +0 -2
- package/dist/multipart-parser-DedmaB5g.mjs +0 -294
- package/dist/oauth-DOJeGfcE.mjs +0 -6392
- package/dist/openai-BDtIh3Ja.mjs +0 -6693
- package/dist/openai-codex-responses-C5EORu31.mjs +0 -664
- package/dist/openai-completions-CR_cS6gX.mjs +0 -669
- package/dist/openai-responses-oGxwZyuC.mjs +0 -184
- package/dist/openai-responses-shared-BixMSDZE.mjs +0 -398
- package/dist/paths-D6msg0S1-C2lYuisN.mjs +0 -189
- package/dist/paths-D92DjaZ--CTOESW2b.mjs +0 -192
- package/dist/pi-model-discovery-Bd0TWzo8-BFsJmeMb.mjs +0 -227
- package/dist/pi-model-discovery-runtime-CCCZxkd8.mjs +0 -2
- package/dist/pi-tools.before-tool-call.runtime-Bn7uqKie-C5ewk8kK.mjs +0 -399
- package/dist/plugin-auto-enable-DdH3n9V8-DsA1isaF.mjs +0 -1456
- package/dist/process-scoped-map-B2cWkYET-CXwUZ8CZ.mjs +0 -61
- package/dist/provider-discovery.runtime-BPzz1PFj.mjs +0 -58
- package/dist/provider-model-compat-CFqcq0it-BDDuBI3A.mjs +0 -118
- package/dist/provider-runtime-C8rljsNs-CIT93zoy.mjs +0 -2
- package/dist/provider-runtime-CT50mNIX-BwEV6GyO.mjs +0 -573
- package/dist/provider-stream-COLujAAo-CbJPDngm.mjs +0 -35449
- package/dist/providers.runtime-Ba7tOlq7-CXkhkzU9.mjs +0 -219
- package/dist/public-surface-loader-BVl0NQAE-C0piXtsT.mjs +0 -117
- package/dist/resolve-C33B7eeu-BNvYTl6k.mjs +0 -1041
- package/dist/runtime-Cym-fqI8-DaSDMH-a.mjs +0 -120
- package/dist/runtime-channel-state-CohMybAh-hXR6y5Gx.mjs +0 -19
- package/dist/runtime-snapshot-C54O1-gI-40cbyi7P.mjs +0 -677
- package/dist/runtime-state-IBOIXKOx-Bf9tcLvc.mjs +0 -10
- package/dist/runtime-web-tools-fallback.runtime-Ca-qn1mj-BCVImm7a.mjs +0 -39
- package/dist/runtime-web-tools-manifest.runtime-BgxQTjmq-Cb4nJkRT.mjs +0 -2
- package/dist/runtime-web-tools-public-artifacts.runtime-D9qcoWIX-BrQdXzOQ.mjs +0 -2
- package/dist/session-archive.runtime-B52_5vs4-BG-_IwNJ.mjs +0 -2
- package/dist/session-key-Cn2QoOyX-CuHbJMgR.mjs +0 -82
- package/dist/session-transcript-files.fs-DEeFXruQ-B1PF6nLy.mjs +0 -147
- package/dist/src-BgCX0MLG.mjs +0 -813
- package/dist/src-DYbqlAqf.mjs +0 -1177
- package/dist/subagent-announce-L5WsQatW-CQWI9GMd.mjs +0 -344
- package/dist/subagent-announce.registry.runtime-DiqZyeTs-BKuniyi3.mjs +0 -28
- package/dist/subagent-registry-steer-runtime-DFgZFC0j-BhBz0roy.mjs +0 -211
- package/dist/subagent-system-prompt-C1qnN--K-DpnTFP47.mjs +0 -3061
- package/dist/target-parsing-loaded-DKkb6jJY-BMD4CkpS.mjs +0 -1002
- package/dist/task-registry-delivery-runtime-Dd1CUkZF-C8U40a3O.mjs +0 -2950
- package/dist/task-registry-delivery-runtime-ragbeVx5-CNbFAkjD.mjs +0 -2
- package/dist/thinking-Bh-7MqXz-D3woGbO7.mjs +0 -2
- package/dist/transcript-E_-ISOkD-DWCfZP2p.mjs +0 -2019
- package/dist/transcript.runtime-BqhvZZdl-BPy42vBP.mjs +0 -2
- package/dist/transform-messages-DbhIzTxq.mjs +0 -207
- package/dist/web-provider-public-artifacts-BlpRwIUS-CGPSV4W2.mjs +0 -295
- package/dist/web-search-providers.runtime--0aUtC3b-DyuhC95V.mjs +0 -200
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { t as getEnvApiKey } from "./env-api-keys-BVvSg7T2.mjs";
|
|
2
|
-
import { o as supportsXhigh, t as AssistantMessageEventStream } from "./event-stream-xaQWmyas.mjs";
|
|
3
|
-
import { n as OpenAI } from "./openai-BDtIh3Ja.mjs";
|
|
4
|
-
import { t as headersToRecord } from "./headers-R3HdCbAE.mjs";
|
|
5
|
-
import { i as clampReasoning, r as buildBaseOptions } from "./transform-messages-DbhIzTxq.mjs";
|
|
6
|
-
import { n as hasCopilotVisionInput, t as buildCopilotDynamicHeaders } from "./github-copilot-headers-DjqWtUoP.mjs";
|
|
7
|
-
import { n as convertResponsesTools, r as processResponsesStream, t as convertResponsesMessages } from "./openai-responses-shared-BixMSDZE.mjs";
|
|
8
|
-
//#region node_modules/.pnpm/@mariozechner+pi-ai@0.69.0_@modelcontextprotocol+sdk@1.29.0_zod@4.3.6__ws@8.21.0_zod@4.3.6/node_modules/@mariozechner/pi-ai/dist/providers/openai-responses.js
|
|
9
|
-
const OPENAI_TOOL_CALL_PROVIDERS = new Set([
|
|
10
|
-
"openai",
|
|
11
|
-
"openai-codex",
|
|
12
|
-
"opencode"
|
|
13
|
-
]);
|
|
14
|
-
/**
|
|
15
|
-
* Resolve cache retention preference.
|
|
16
|
-
* Defaults to "short" and uses PI_CACHE_RETENTION for backward compatibility.
|
|
17
|
-
*/
|
|
18
|
-
function resolveCacheRetention(cacheRetention) {
|
|
19
|
-
if (cacheRetention) return cacheRetention;
|
|
20
|
-
if (typeof process !== "undefined" && process.env.PI_CACHE_RETENTION === "long") return "long";
|
|
21
|
-
return "short";
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Get prompt cache retention based on cacheRetention and base URL.
|
|
25
|
-
* Only applies to direct OpenAI API calls (api.openai.com).
|
|
26
|
-
*/
|
|
27
|
-
function getPromptCacheRetention(baseUrl, cacheRetention) {
|
|
28
|
-
if (cacheRetention !== "long") return;
|
|
29
|
-
if (baseUrl.includes("api.openai.com")) return "24h";
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Generate function for OpenAI Responses API
|
|
33
|
-
*/
|
|
34
|
-
const streamOpenAIResponses = (model, context, options) => {
|
|
35
|
-
const stream = new AssistantMessageEventStream();
|
|
36
|
-
(async () => {
|
|
37
|
-
const output = {
|
|
38
|
-
role: "assistant",
|
|
39
|
-
content: [],
|
|
40
|
-
api: model.api,
|
|
41
|
-
provider: model.provider,
|
|
42
|
-
model: model.id,
|
|
43
|
-
usage: {
|
|
44
|
-
input: 0,
|
|
45
|
-
output: 0,
|
|
46
|
-
cacheRead: 0,
|
|
47
|
-
cacheWrite: 0,
|
|
48
|
-
totalTokens: 0,
|
|
49
|
-
cost: {
|
|
50
|
-
input: 0,
|
|
51
|
-
output: 0,
|
|
52
|
-
cacheRead: 0,
|
|
53
|
-
cacheWrite: 0,
|
|
54
|
-
total: 0
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
stopReason: "stop",
|
|
58
|
-
timestamp: Date.now()
|
|
59
|
-
};
|
|
60
|
-
try {
|
|
61
|
-
const apiKey = options?.apiKey || getEnvApiKey(model.provider) || "";
|
|
62
|
-
const cacheSessionId = resolveCacheRetention(options?.cacheRetention) === "none" ? void 0 : options?.sessionId;
|
|
63
|
-
const client = createClient(model, context, apiKey, options?.headers, cacheSessionId);
|
|
64
|
-
let params = buildParams(model, context, options);
|
|
65
|
-
const nextParams = await options?.onPayload?.(params, model);
|
|
66
|
-
if (nextParams !== void 0) params = nextParams;
|
|
67
|
-
const { data: openaiStream, response } = await client.responses.create(params, options?.signal ? { signal: options.signal } : void 0).withResponse();
|
|
68
|
-
await options?.onResponse?.({
|
|
69
|
-
status: response.status,
|
|
70
|
-
headers: headersToRecord(response.headers)
|
|
71
|
-
}, model);
|
|
72
|
-
stream.push({
|
|
73
|
-
type: "start",
|
|
74
|
-
partial: output
|
|
75
|
-
});
|
|
76
|
-
await processResponsesStream(openaiStream, output, stream, model, {
|
|
77
|
-
serviceTier: options?.serviceTier,
|
|
78
|
-
applyServiceTierPricing
|
|
79
|
-
});
|
|
80
|
-
if (options?.signal?.aborted) throw new Error("Request was aborted");
|
|
81
|
-
if (output.stopReason === "aborted" || output.stopReason === "error") throw new Error("An unknown error occurred");
|
|
82
|
-
stream.push({
|
|
83
|
-
type: "done",
|
|
84
|
-
reason: output.stopReason,
|
|
85
|
-
message: output
|
|
86
|
-
});
|
|
87
|
-
stream.end();
|
|
88
|
-
} catch (error) {
|
|
89
|
-
for (const block of output.content) {
|
|
90
|
-
delete block.index;
|
|
91
|
-
delete block.partialJson;
|
|
92
|
-
}
|
|
93
|
-
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
94
|
-
output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
|
|
95
|
-
stream.push({
|
|
96
|
-
type: "error",
|
|
97
|
-
reason: output.stopReason,
|
|
98
|
-
error: output
|
|
99
|
-
});
|
|
100
|
-
stream.end();
|
|
101
|
-
}
|
|
102
|
-
})();
|
|
103
|
-
return stream;
|
|
104
|
-
};
|
|
105
|
-
const streamSimpleOpenAIResponses = (model, context, options) => {
|
|
106
|
-
const apiKey = options?.apiKey || getEnvApiKey(model.provider);
|
|
107
|
-
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
108
|
-
const base = buildBaseOptions(model, options, apiKey);
|
|
109
|
-
const reasoningEffort = supportsXhigh(model) ? options?.reasoning : clampReasoning(options?.reasoning);
|
|
110
|
-
return streamOpenAIResponses(model, context, {
|
|
111
|
-
...base,
|
|
112
|
-
reasoningEffort
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
function createClient(model, context, apiKey, optionsHeaders, sessionId) {
|
|
116
|
-
if (!apiKey) {
|
|
117
|
-
if (!process.env.OPENAI_API_KEY) throw new Error("OpenAI API key is required. Set OPENAI_API_KEY environment variable or pass it as an argument.");
|
|
118
|
-
apiKey = process.env.OPENAI_API_KEY;
|
|
119
|
-
}
|
|
120
|
-
const headers = { ...model.headers };
|
|
121
|
-
if (model.provider === "github-copilot") {
|
|
122
|
-
const hasImages = hasCopilotVisionInput(context.messages);
|
|
123
|
-
const copilotHeaders = buildCopilotDynamicHeaders({
|
|
124
|
-
messages: context.messages,
|
|
125
|
-
hasImages
|
|
126
|
-
});
|
|
127
|
-
Object.assign(headers, copilotHeaders);
|
|
128
|
-
}
|
|
129
|
-
if (sessionId) {
|
|
130
|
-
headers.session_id = sessionId;
|
|
131
|
-
headers["x-client-request-id"] = sessionId;
|
|
132
|
-
}
|
|
133
|
-
if (optionsHeaders) Object.assign(headers, optionsHeaders);
|
|
134
|
-
return new OpenAI({
|
|
135
|
-
apiKey,
|
|
136
|
-
baseURL: model.baseUrl,
|
|
137
|
-
dangerouslyAllowBrowser: true,
|
|
138
|
-
defaultHeaders: headers
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
function buildParams(model, context, options) {
|
|
142
|
-
const messages = convertResponsesMessages(model, context, OPENAI_TOOL_CALL_PROVIDERS);
|
|
143
|
-
const cacheRetention = resolveCacheRetention(options?.cacheRetention);
|
|
144
|
-
const params = {
|
|
145
|
-
model: model.id,
|
|
146
|
-
input: messages,
|
|
147
|
-
stream: true,
|
|
148
|
-
prompt_cache_key: cacheRetention === "none" ? void 0 : options?.sessionId,
|
|
149
|
-
prompt_cache_retention: getPromptCacheRetention(model.baseUrl, cacheRetention),
|
|
150
|
-
store: false
|
|
151
|
-
};
|
|
152
|
-
if (options?.maxTokens) params.max_output_tokens = options?.maxTokens;
|
|
153
|
-
if (options?.temperature !== void 0) params.temperature = options?.temperature;
|
|
154
|
-
if (options?.serviceTier !== void 0) params.service_tier = options.serviceTier;
|
|
155
|
-
if (context.tools) params.tools = convertResponsesTools(context.tools);
|
|
156
|
-
if (model.reasoning) {
|
|
157
|
-
if (options?.reasoningEffort || options?.reasoningSummary) {
|
|
158
|
-
params.reasoning = {
|
|
159
|
-
effort: options?.reasoningEffort || "medium",
|
|
160
|
-
summary: options?.reasoningSummary || "auto"
|
|
161
|
-
};
|
|
162
|
-
params.include = ["reasoning.encrypted_content"];
|
|
163
|
-
} else if (model.provider !== "github-copilot") params.reasoning = { effort: "none" };
|
|
164
|
-
}
|
|
165
|
-
return params;
|
|
166
|
-
}
|
|
167
|
-
function getServiceTierCostMultiplier(serviceTier) {
|
|
168
|
-
switch (serviceTier) {
|
|
169
|
-
case "flex": return .5;
|
|
170
|
-
case "priority": return 2;
|
|
171
|
-
default: return 1;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
function applyServiceTierPricing(usage, serviceTier) {
|
|
175
|
-
const multiplier = getServiceTierCostMultiplier(serviceTier);
|
|
176
|
-
if (multiplier === 1) return;
|
|
177
|
-
usage.cost.input *= multiplier;
|
|
178
|
-
usage.cost.output *= multiplier;
|
|
179
|
-
usage.cost.cacheRead *= multiplier;
|
|
180
|
-
usage.cost.cacheWrite *= multiplier;
|
|
181
|
-
usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
|
|
182
|
-
}
|
|
183
|
-
//#endregion
|
|
184
|
-
export { streamOpenAIResponses, streamSimpleOpenAIResponses };
|
|
@@ -1,398 +0,0 @@
|
|
|
1
|
-
import { r as calculateCost } from "./event-stream-xaQWmyas.mjs";
|
|
2
|
-
import { n as parseStreamingJson } from "./json-parse-v_HIJjjI.mjs";
|
|
3
|
-
import { a as sanitizeSurrogates, t as transformMessages } from "./transform-messages-DbhIzTxq.mjs";
|
|
4
|
-
import { t as shortHash } from "./hash-DAFtW_W7.mjs";
|
|
5
|
-
//#region node_modules/.pnpm/@mariozechner+pi-ai@0.69.0_@modelcontextprotocol+sdk@1.29.0_zod@4.3.6__ws@8.21.0_zod@4.3.6/node_modules/@mariozechner/pi-ai/dist/providers/openai-responses-shared.js
|
|
6
|
-
function encodeTextSignatureV1(id, phase) {
|
|
7
|
-
const payload = {
|
|
8
|
-
v: 1,
|
|
9
|
-
id
|
|
10
|
-
};
|
|
11
|
-
if (phase) payload.phase = phase;
|
|
12
|
-
return JSON.stringify(payload);
|
|
13
|
-
}
|
|
14
|
-
function parseTextSignature(signature) {
|
|
15
|
-
if (!signature) return void 0;
|
|
16
|
-
if (signature.startsWith("{")) try {
|
|
17
|
-
const parsed = JSON.parse(signature);
|
|
18
|
-
if (parsed.v === 1 && typeof parsed.id === "string") {
|
|
19
|
-
if (parsed.phase === "commentary" || parsed.phase === "final_answer") return {
|
|
20
|
-
id: parsed.id,
|
|
21
|
-
phase: parsed.phase
|
|
22
|
-
};
|
|
23
|
-
return { id: parsed.id };
|
|
24
|
-
}
|
|
25
|
-
} catch {}
|
|
26
|
-
return { id: signature };
|
|
27
|
-
}
|
|
28
|
-
function convertResponsesMessages(model, context, allowedToolCallProviders, options) {
|
|
29
|
-
const messages = [];
|
|
30
|
-
const normalizeIdPart = (part) => {
|
|
31
|
-
const sanitized = part.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
32
|
-
return (sanitized.length > 64 ? sanitized.slice(0, 64) : sanitized).replace(/_+$/, "");
|
|
33
|
-
};
|
|
34
|
-
const buildForeignResponsesItemId = (itemId) => {
|
|
35
|
-
const normalized = `fc_${shortHash(itemId)}`;
|
|
36
|
-
return normalized.length > 64 ? normalized.slice(0, 64) : normalized;
|
|
37
|
-
};
|
|
38
|
-
const normalizeToolCallId = (id, _targetModel, source) => {
|
|
39
|
-
if (!allowedToolCallProviders.has(model.provider)) return normalizeIdPart(id);
|
|
40
|
-
if (!id.includes("|")) return normalizeIdPart(id);
|
|
41
|
-
const [callId, itemId] = id.split("|");
|
|
42
|
-
const normalizedCallId = normalizeIdPart(callId);
|
|
43
|
-
let normalizedItemId = source.provider !== model.provider || source.api !== model.api ? buildForeignResponsesItemId(itemId) : normalizeIdPart(itemId);
|
|
44
|
-
if (!normalizedItemId.startsWith("fc_")) normalizedItemId = normalizeIdPart(`fc_${normalizedItemId}`);
|
|
45
|
-
return `${normalizedCallId}|${normalizedItemId}`;
|
|
46
|
-
};
|
|
47
|
-
const transformedMessages = transformMessages(context.messages, model, normalizeToolCallId);
|
|
48
|
-
if ((options?.includeSystemPrompt ?? true) && context.systemPrompt) {
|
|
49
|
-
const role = model.reasoning ? "developer" : "system";
|
|
50
|
-
messages.push({
|
|
51
|
-
role,
|
|
52
|
-
content: sanitizeSurrogates(context.systemPrompt)
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
let msgIndex = 0;
|
|
56
|
-
for (const msg of transformedMessages) {
|
|
57
|
-
if (msg.role === "user") if (typeof msg.content === "string") messages.push({
|
|
58
|
-
role: "user",
|
|
59
|
-
content: [{
|
|
60
|
-
type: "input_text",
|
|
61
|
-
text: sanitizeSurrogates(msg.content)
|
|
62
|
-
}]
|
|
63
|
-
});
|
|
64
|
-
else {
|
|
65
|
-
const content = msg.content.map((item) => {
|
|
66
|
-
if (item.type === "text") return {
|
|
67
|
-
type: "input_text",
|
|
68
|
-
text: sanitizeSurrogates(item.text)
|
|
69
|
-
};
|
|
70
|
-
return {
|
|
71
|
-
type: "input_image",
|
|
72
|
-
detail: "auto",
|
|
73
|
-
image_url: `data:${item.mimeType};base64,${item.data}`
|
|
74
|
-
};
|
|
75
|
-
});
|
|
76
|
-
if (content.length === 0) continue;
|
|
77
|
-
messages.push({
|
|
78
|
-
role: "user",
|
|
79
|
-
content
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
else if (msg.role === "assistant") {
|
|
83
|
-
const output = [];
|
|
84
|
-
const assistantMsg = msg;
|
|
85
|
-
const isDifferentModel = assistantMsg.model !== model.id && assistantMsg.provider === model.provider && assistantMsg.api === model.api;
|
|
86
|
-
for (const block of msg.content) if (block.type === "thinking") {
|
|
87
|
-
if (block.thinkingSignature) {
|
|
88
|
-
const reasoningItem = JSON.parse(block.thinkingSignature);
|
|
89
|
-
output.push(reasoningItem);
|
|
90
|
-
}
|
|
91
|
-
} else if (block.type === "text") {
|
|
92
|
-
const textBlock = block;
|
|
93
|
-
const parsedSignature = parseTextSignature(textBlock.textSignature);
|
|
94
|
-
let msgId = parsedSignature?.id;
|
|
95
|
-
if (!msgId) msgId = `msg_${msgIndex}`;
|
|
96
|
-
else if (msgId.length > 64) msgId = `msg_${shortHash(msgId)}`;
|
|
97
|
-
output.push({
|
|
98
|
-
type: "message",
|
|
99
|
-
role: "assistant",
|
|
100
|
-
content: [{
|
|
101
|
-
type: "output_text",
|
|
102
|
-
text: sanitizeSurrogates(textBlock.text),
|
|
103
|
-
annotations: []
|
|
104
|
-
}],
|
|
105
|
-
status: "completed",
|
|
106
|
-
id: msgId,
|
|
107
|
-
phase: parsedSignature?.phase
|
|
108
|
-
});
|
|
109
|
-
} else if (block.type === "toolCall") {
|
|
110
|
-
const toolCall = block;
|
|
111
|
-
const [callId, itemIdRaw] = toolCall.id.split("|");
|
|
112
|
-
let itemId = itemIdRaw;
|
|
113
|
-
if (isDifferentModel && itemId?.startsWith("fc_")) itemId = void 0;
|
|
114
|
-
output.push({
|
|
115
|
-
type: "function_call",
|
|
116
|
-
id: itemId,
|
|
117
|
-
call_id: callId,
|
|
118
|
-
name: toolCall.name,
|
|
119
|
-
arguments: JSON.stringify(toolCall.arguments)
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
if (output.length === 0) continue;
|
|
123
|
-
messages.push(...output);
|
|
124
|
-
} else if (msg.role === "toolResult") {
|
|
125
|
-
const textResult = msg.content.filter((c) => c.type === "text").map((c) => c.text).join("\n");
|
|
126
|
-
const hasImages = msg.content.some((c) => c.type === "image");
|
|
127
|
-
const hasText = textResult.length > 0;
|
|
128
|
-
const [callId] = msg.toolCallId.split("|");
|
|
129
|
-
let output;
|
|
130
|
-
if (hasImages && model.input.includes("image")) {
|
|
131
|
-
const contentParts = [];
|
|
132
|
-
if (hasText) contentParts.push({
|
|
133
|
-
type: "input_text",
|
|
134
|
-
text: sanitizeSurrogates(textResult)
|
|
135
|
-
});
|
|
136
|
-
for (const block of msg.content) if (block.type === "image") contentParts.push({
|
|
137
|
-
type: "input_image",
|
|
138
|
-
detail: "auto",
|
|
139
|
-
image_url: `data:${block.mimeType};base64,${block.data}`
|
|
140
|
-
});
|
|
141
|
-
output = contentParts;
|
|
142
|
-
} else output = sanitizeSurrogates(hasText ? textResult : "(see attached image)");
|
|
143
|
-
messages.push({
|
|
144
|
-
type: "function_call_output",
|
|
145
|
-
call_id: callId,
|
|
146
|
-
output
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
msgIndex++;
|
|
150
|
-
}
|
|
151
|
-
return messages;
|
|
152
|
-
}
|
|
153
|
-
function convertResponsesTools(tools, options) {
|
|
154
|
-
const strict = options?.strict === void 0 ? false : options.strict;
|
|
155
|
-
return tools.map((tool) => ({
|
|
156
|
-
type: "function",
|
|
157
|
-
name: tool.name,
|
|
158
|
-
description: tool.description,
|
|
159
|
-
parameters: tool.parameters,
|
|
160
|
-
strict
|
|
161
|
-
}));
|
|
162
|
-
}
|
|
163
|
-
async function processResponsesStream(openaiStream, output, stream, model, options) {
|
|
164
|
-
let currentItem = null;
|
|
165
|
-
let currentBlock = null;
|
|
166
|
-
const blocks = output.content;
|
|
167
|
-
const blockIndex = () => blocks.length - 1;
|
|
168
|
-
for await (const event of openaiStream) if (event.type === "response.created") output.responseId = event.response.id;
|
|
169
|
-
else if (event.type === "response.output_item.added") {
|
|
170
|
-
const item = event.item;
|
|
171
|
-
if (item.type === "reasoning") {
|
|
172
|
-
currentItem = item;
|
|
173
|
-
currentBlock = {
|
|
174
|
-
type: "thinking",
|
|
175
|
-
thinking: ""
|
|
176
|
-
};
|
|
177
|
-
output.content.push(currentBlock);
|
|
178
|
-
stream.push({
|
|
179
|
-
type: "thinking_start",
|
|
180
|
-
contentIndex: blockIndex(),
|
|
181
|
-
partial: output
|
|
182
|
-
});
|
|
183
|
-
} else if (item.type === "message") {
|
|
184
|
-
currentItem = item;
|
|
185
|
-
currentBlock = {
|
|
186
|
-
type: "text",
|
|
187
|
-
text: ""
|
|
188
|
-
};
|
|
189
|
-
output.content.push(currentBlock);
|
|
190
|
-
stream.push({
|
|
191
|
-
type: "text_start",
|
|
192
|
-
contentIndex: blockIndex(),
|
|
193
|
-
partial: output
|
|
194
|
-
});
|
|
195
|
-
} else if (item.type === "function_call") {
|
|
196
|
-
currentItem = item;
|
|
197
|
-
currentBlock = {
|
|
198
|
-
type: "toolCall",
|
|
199
|
-
id: `${item.call_id}|${item.id}`,
|
|
200
|
-
name: item.name,
|
|
201
|
-
arguments: {},
|
|
202
|
-
partialJson: item.arguments || ""
|
|
203
|
-
};
|
|
204
|
-
output.content.push(currentBlock);
|
|
205
|
-
stream.push({
|
|
206
|
-
type: "toolcall_start",
|
|
207
|
-
contentIndex: blockIndex(),
|
|
208
|
-
partial: output
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
} else if (event.type === "response.reasoning_summary_part.added") {
|
|
212
|
-
if (currentItem && currentItem.type === "reasoning") {
|
|
213
|
-
currentItem.summary = currentItem.summary || [];
|
|
214
|
-
currentItem.summary.push(event.part);
|
|
215
|
-
}
|
|
216
|
-
} else if (event.type === "response.reasoning_summary_text.delta") {
|
|
217
|
-
if (currentItem?.type === "reasoning" && currentBlock?.type === "thinking") {
|
|
218
|
-
currentItem.summary = currentItem.summary || [];
|
|
219
|
-
const lastPart = currentItem.summary[currentItem.summary.length - 1];
|
|
220
|
-
if (lastPart) {
|
|
221
|
-
currentBlock.thinking += event.delta;
|
|
222
|
-
lastPart.text += event.delta;
|
|
223
|
-
stream.push({
|
|
224
|
-
type: "thinking_delta",
|
|
225
|
-
contentIndex: blockIndex(),
|
|
226
|
-
delta: event.delta,
|
|
227
|
-
partial: output
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
} else if (event.type === "response.reasoning_summary_part.done") {
|
|
232
|
-
if (currentItem?.type === "reasoning" && currentBlock?.type === "thinking") {
|
|
233
|
-
currentItem.summary = currentItem.summary || [];
|
|
234
|
-
const lastPart = currentItem.summary[currentItem.summary.length - 1];
|
|
235
|
-
if (lastPart) {
|
|
236
|
-
currentBlock.thinking += "\n\n";
|
|
237
|
-
lastPart.text += "\n\n";
|
|
238
|
-
stream.push({
|
|
239
|
-
type: "thinking_delta",
|
|
240
|
-
contentIndex: blockIndex(),
|
|
241
|
-
delta: "\n\n",
|
|
242
|
-
partial: output
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
} else if (event.type === "response.content_part.added") {
|
|
247
|
-
if (currentItem?.type === "message") {
|
|
248
|
-
currentItem.content = currentItem.content || [];
|
|
249
|
-
if (event.part.type === "output_text" || event.part.type === "refusal") currentItem.content.push(event.part);
|
|
250
|
-
}
|
|
251
|
-
} else if (event.type === "response.output_text.delta") {
|
|
252
|
-
if (currentItem?.type === "message" && currentBlock?.type === "text") {
|
|
253
|
-
if (!currentItem.content || currentItem.content.length === 0) continue;
|
|
254
|
-
const lastPart = currentItem.content[currentItem.content.length - 1];
|
|
255
|
-
if (lastPart?.type === "output_text") {
|
|
256
|
-
currentBlock.text += event.delta;
|
|
257
|
-
lastPart.text += event.delta;
|
|
258
|
-
stream.push({
|
|
259
|
-
type: "text_delta",
|
|
260
|
-
contentIndex: blockIndex(),
|
|
261
|
-
delta: event.delta,
|
|
262
|
-
partial: output
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
} else if (event.type === "response.refusal.delta") {
|
|
267
|
-
if (currentItem?.type === "message" && currentBlock?.type === "text") {
|
|
268
|
-
if (!currentItem.content || currentItem.content.length === 0) continue;
|
|
269
|
-
const lastPart = currentItem.content[currentItem.content.length - 1];
|
|
270
|
-
if (lastPart?.type === "refusal") {
|
|
271
|
-
currentBlock.text += event.delta;
|
|
272
|
-
lastPart.refusal += event.delta;
|
|
273
|
-
stream.push({
|
|
274
|
-
type: "text_delta",
|
|
275
|
-
contentIndex: blockIndex(),
|
|
276
|
-
delta: event.delta,
|
|
277
|
-
partial: output
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
} else if (event.type === "response.function_call_arguments.delta") {
|
|
282
|
-
if (currentItem?.type === "function_call" && currentBlock?.type === "toolCall") {
|
|
283
|
-
currentBlock.partialJson += event.delta;
|
|
284
|
-
currentBlock.arguments = parseStreamingJson(currentBlock.partialJson);
|
|
285
|
-
stream.push({
|
|
286
|
-
type: "toolcall_delta",
|
|
287
|
-
contentIndex: blockIndex(),
|
|
288
|
-
delta: event.delta,
|
|
289
|
-
partial: output
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
} else if (event.type === "response.function_call_arguments.done") {
|
|
293
|
-
if (currentItem?.type === "function_call" && currentBlock?.type === "toolCall") {
|
|
294
|
-
const previousPartialJson = currentBlock.partialJson;
|
|
295
|
-
currentBlock.partialJson = event.arguments;
|
|
296
|
-
currentBlock.arguments = parseStreamingJson(currentBlock.partialJson);
|
|
297
|
-
if (event.arguments.startsWith(previousPartialJson)) {
|
|
298
|
-
const delta = event.arguments.slice(previousPartialJson.length);
|
|
299
|
-
if (delta.length > 0) stream.push({
|
|
300
|
-
type: "toolcall_delta",
|
|
301
|
-
contentIndex: blockIndex(),
|
|
302
|
-
delta,
|
|
303
|
-
partial: output
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
} else if (event.type === "response.output_item.done") {
|
|
308
|
-
const item = event.item;
|
|
309
|
-
if (item.type === "reasoning" && currentBlock?.type === "thinking") {
|
|
310
|
-
currentBlock.thinking = item.summary?.map((s) => s.text).join("\n\n") || "";
|
|
311
|
-
currentBlock.thinkingSignature = JSON.stringify(item);
|
|
312
|
-
stream.push({
|
|
313
|
-
type: "thinking_end",
|
|
314
|
-
contentIndex: blockIndex(),
|
|
315
|
-
content: currentBlock.thinking,
|
|
316
|
-
partial: output
|
|
317
|
-
});
|
|
318
|
-
currentBlock = null;
|
|
319
|
-
} else if (item.type === "message" && currentBlock?.type === "text") {
|
|
320
|
-
currentBlock.text = item.content.map((c) => c.type === "output_text" ? c.text : c.refusal).join("");
|
|
321
|
-
currentBlock.textSignature = encodeTextSignatureV1(item.id, item.phase ?? void 0);
|
|
322
|
-
stream.push({
|
|
323
|
-
type: "text_end",
|
|
324
|
-
contentIndex: blockIndex(),
|
|
325
|
-
content: currentBlock.text,
|
|
326
|
-
partial: output
|
|
327
|
-
});
|
|
328
|
-
currentBlock = null;
|
|
329
|
-
} else if (item.type === "function_call") {
|
|
330
|
-
const args = currentBlock?.type === "toolCall" && currentBlock.partialJson ? parseStreamingJson(currentBlock.partialJson) : parseStreamingJson(item.arguments || "{}");
|
|
331
|
-
let toolCall;
|
|
332
|
-
if (currentBlock?.type === "toolCall") {
|
|
333
|
-
currentBlock.arguments = args;
|
|
334
|
-
delete currentBlock.partialJson;
|
|
335
|
-
toolCall = currentBlock;
|
|
336
|
-
} else toolCall = {
|
|
337
|
-
type: "toolCall",
|
|
338
|
-
id: `${item.call_id}|${item.id}`,
|
|
339
|
-
name: item.name,
|
|
340
|
-
arguments: args
|
|
341
|
-
};
|
|
342
|
-
currentBlock = null;
|
|
343
|
-
stream.push({
|
|
344
|
-
type: "toolcall_end",
|
|
345
|
-
contentIndex: blockIndex(),
|
|
346
|
-
toolCall,
|
|
347
|
-
partial: output
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
} else if (event.type === "response.completed") {
|
|
351
|
-
const response = event.response;
|
|
352
|
-
if (response?.id) output.responseId = response.id;
|
|
353
|
-
if (response?.usage) {
|
|
354
|
-
const cachedTokens = response.usage.input_tokens_details?.cached_tokens || 0;
|
|
355
|
-
output.usage = {
|
|
356
|
-
input: (response.usage.input_tokens || 0) - cachedTokens,
|
|
357
|
-
output: response.usage.output_tokens || 0,
|
|
358
|
-
cacheRead: cachedTokens,
|
|
359
|
-
cacheWrite: 0,
|
|
360
|
-
totalTokens: response.usage.total_tokens || 0,
|
|
361
|
-
cost: {
|
|
362
|
-
input: 0,
|
|
363
|
-
output: 0,
|
|
364
|
-
cacheRead: 0,
|
|
365
|
-
cacheWrite: 0,
|
|
366
|
-
total: 0
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
calculateCost(model, output.usage);
|
|
371
|
-
if (options?.applyServiceTierPricing) {
|
|
372
|
-
const serviceTier = options.resolveServiceTier ? options.resolveServiceTier(response?.service_tier, options.serviceTier) : response?.service_tier ?? options.serviceTier;
|
|
373
|
-
options.applyServiceTierPricing(output.usage, serviceTier);
|
|
374
|
-
}
|
|
375
|
-
output.stopReason = mapStopReason(response?.status);
|
|
376
|
-
if (output.content.some((b) => b.type === "toolCall") && output.stopReason === "stop") output.stopReason = "toolUse";
|
|
377
|
-
} else if (event.type === "error") throw new Error(`Error Code ${event.code}: ${event.message}` || "Unknown error");
|
|
378
|
-
else if (event.type === "response.failed") {
|
|
379
|
-
const error = event.response?.error;
|
|
380
|
-
const details = event.response?.incomplete_details;
|
|
381
|
-
const msg = error ? `${error.code || "unknown"}: ${error.message || "no message"}` : details?.reason ? `incomplete: ${details.reason}` : "Unknown error (no error details in response)";
|
|
382
|
-
throw new Error(msg);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
function mapStopReason(status) {
|
|
386
|
-
if (!status) return "stop";
|
|
387
|
-
switch (status) {
|
|
388
|
-
case "completed": return "stop";
|
|
389
|
-
case "incomplete": return "length";
|
|
390
|
-
case "failed":
|
|
391
|
-
case "cancelled": return "error";
|
|
392
|
-
case "in_progress":
|
|
393
|
-
case "queued": return "stop";
|
|
394
|
-
default: throw new Error(`Unhandled stop reason: ${status}`);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
//#endregion
|
|
398
|
-
export { convertResponsesTools as n, processResponsesStream as r, convertResponsesMessages as t };
|