@xiaoso/dsh-tool-plus 0.1.0-beta.2 → 0.1.0-beta.4
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/README.en.md +122 -0
- package/README.md +3 -2
- package/THIRD_PARTY_NOTICES.md +4 -35
- package/lib/abort-B7izMMna.mjs +51 -0
- package/lib/abort-D1_Z5Ut5.mjs +51 -0
- package/lib/abort-dIkZBV7Q.mjs +51 -0
- package/lib/amazon-bedrock-B0nxT06F.mjs +917 -0
- package/lib/amazon-bedrock-D-shAr1X.mjs +917 -0
- package/lib/amazon-bedrock-WQhvjHYu.mjs +917 -0
- package/lib/anthropic-BWsZFzU8.mjs +262 -0
- package/lib/anthropic-CJCauvYz.mjs +3115 -0
- package/lib/anthropic-CMT1Qj1t.mjs +3115 -0
- package/lib/anthropic-CZghe_9U.mjs +3115 -0
- package/lib/anthropic-sCMH7JID.mjs +262 -0
- package/lib/anthropic-tTntD8BD.mjs +262 -0
- package/lib/api-key-login-BzqNdM2y.mjs +157 -0
- package/lib/api-key-login-CWVwvHT1.mjs +157 -0
- package/lib/api-key-login-CpzSezsi.mjs +157 -0
- package/lib/aws-credentials-8Mgn5MAy.mjs +867 -0
- package/lib/aws-credentials-CXryMobh.mjs +867 -0
- package/lib/aws-credentials-ChG79ey-.mjs +867 -0
- package/lib/azure-openai-responses-CNkHiLUh.mjs +274 -0
- package/lib/azure-openai-responses-Cgmc-rbL.mjs +274 -0
- package/lib/azure-openai-responses-DuukbD0F.mjs +274 -0
- package/lib/bun-shim.mjs +252 -12
- package/lib/bundled-references-CSuBco5p.mjs +55 -0
- package/lib/bundled-references-Cavaffah.mjs +55 -0
- package/lib/bundled-references-sLN0YdXU.mjs +55 -0
- package/lib/callback-server-BEFNf-jf.mjs +398 -0
- package/lib/callback-server-CQ5Jo8F-.mjs +398 -0
- package/lib/callback-server-DDSrZ6l_.mjs +398 -0
- package/lib/client.js +111 -41
- package/lib/cursor-B3zg7EHj.mjs +273 -0
- package/lib/cursor-B6TUEmgP.mjs +135 -0
- package/lib/cursor-BIQfBC6V.mjs +135 -0
- package/lib/cursor-D8gvtTL3.mjs +135 -0
- package/lib/cursor-DNk6eXDd.mjs +5470 -0
- package/lib/cursor-DkSX2h3H.mjs +5441 -0
- package/lib/cursor-MjSm74IJ.mjs +273 -0
- package/lib/cursor-aJrXeYCb.mjs +273 -0
- package/lib/cursor-mJQwUKXK.mjs +5441 -0
- package/lib/device-code-DBo3B5nh.mjs +51 -0
- package/lib/device-code-DIb0FU-H.mjs +51 -0
- package/lib/device-code-OI_tQcmc.mjs +51 -0
- package/lib/devin-BHZZyMhO.mjs +95 -0
- package/lib/devin-BK7DHeca.mjs +114 -0
- package/lib/devin-CfMp3cXS.mjs +95 -0
- package/lib/devin-CldyPD8K.mjs +95 -0
- package/lib/devin-CzRpTUOA.mjs +114 -0
- package/lib/devin-D9zR5B_R.mjs +542 -0
- package/lib/devin-DXOeNyU7.mjs +542 -0
- package/lib/devin-Q1yem3lp.mjs +114 -0
- package/lib/devin-vNZTNUON.mjs +542 -0
- package/lib/error-B3bevhrs.mjs +1449 -0
- package/lib/error-Dd8DIqs-.mjs +1449 -0
- package/lib/error-yCSG0mGC.mjs +1449 -0
- package/lib/event-stream-BDPi64mK.mjs +151 -0
- package/lib/event-stream-BbFZJy-z.mjs +151 -0
- package/lib/event-stream-loUa0s1T.mjs +151 -0
- package/lib/fs-promises-shim-Bx0fpxuk.mjs +57 -0
- package/lib/github-copilot-4GaMtQmg.mjs +208 -0
- package/lib/github-copilot-B1yiyVRh.mjs +104 -0
- package/lib/github-copilot-B2HGSIJK.mjs +104 -0
- package/lib/github-copilot-BWT3eAOF.mjs +208 -0
- package/lib/github-copilot-CYkjeTi3.mjs +208 -0
- package/lib/github-copilot-jscUZ8Hf.mjs +104 -0
- package/lib/gitlab-duo-CM7Ref1H.mjs +155 -0
- package/lib/gitlab-duo-akICyfeD.mjs +155 -0
- package/lib/gitlab-duo-gubO4FNw.mjs +155 -0
- package/lib/gitlab-duo-workflow-BGAF6JDw.mjs +91 -0
- package/lib/gitlab-duo-workflow-CSEgYk3N.mjs +91 -0
- package/lib/gitlab-duo-workflow-D78tdn8E.mjs +91 -0
- package/lib/google-BS4T25Pn.mjs +30 -0
- package/lib/google-TFe-7-of.mjs +30 -0
- package/lib/google-antigravity-DGmwC2KV.mjs +198 -0
- package/lib/google-antigravity-DNYhgTpA.mjs +198 -0
- package/lib/google-antigravity-Dlkdhahq.mjs +198 -0
- package/lib/google-auth-B6gjsZvg.mjs +232 -0
- package/lib/google-auth-De7_s3eo.mjs +232 -0
- package/lib/google-auth-DhqpOYrX.mjs +232 -0
- package/lib/google-gemini-cli-BG_LRdIV.mjs +850 -0
- package/lib/google-gemini-cli-CWu8HvXW.mjs +211 -0
- package/lib/google-gemini-cli-Cb97bzQc.mjs +850 -0
- package/lib/google-gemini-cli-Cqds_Q5T.mjs +850 -0
- package/lib/google-gemini-cli-Dsztq0N5.mjs +211 -0
- package/lib/google-gemini-cli-zJhiOcND.mjs +211 -0
- package/lib/google-oauth-shared-CuEHaDDj.mjs +147 -0
- package/lib/google-oauth-shared-CwNWYdmR.mjs +147 -0
- package/lib/google-oauth-shared-yqlyqPPC.mjs +147 -0
- package/lib/google-shared-CgKmmdO3.mjs +760 -0
- package/lib/google-shared-Dr-VG-ap.mjs +760 -0
- package/lib/google-shared-DzhCb9b0.mjs +760 -0
- package/lib/google-vertex-BDN2tLaD.mjs +99 -0
- package/lib/google-vertex-DopVOQOG.mjs +99 -0
- package/lib/google-vertex-kscbkyRb.mjs +99 -0
- package/lib/google-zyDOG9x7.mjs +30 -0
- package/lib/identity-Da1GPU9a.mjs +219 -0
- package/lib/identity-DnB63pS7.mjs +219 -0
- package/lib/identity-xRP7_eSR.mjs +219 -0
- package/lib/idle-iterator-Baoyn3Hp.mjs +366 -0
- package/lib/idle-iterator-C6XbWcuB.mjs +366 -0
- package/lib/idle-iterator-DUjKQEGT.mjs +366 -0
- package/lib/index.mjs +4608 -3935
- package/lib/kimi--wUOWER5.mjs +236 -0
- package/lib/kimi-DMVI-zrZ.mjs +236 -0
- package/lib/kimi-Dh0pv3WZ.mjs +236 -0
- package/lib/markit-BL3cH47U.mjs +1417 -0
- package/lib/markit-BNiNY6SE.mjs +1417 -0
- package/lib/markit-M0jhziqU.mjs +1417 -0
- package/lib/minimax-code-BK-3eBbz.mjs +53 -0
- package/lib/minimax-code-DCbuA6Yk.mjs +53 -0
- package/lib/minimax-code-Uq8Qu9LW.mjs +53 -0
- package/lib/models-CfT4coYT.mjs +104660 -0
- package/lib/models-D_XnT6ay.mjs +104660 -0
- package/lib/models-SGASygJ3.mjs +104660 -0
- package/lib/ollama-BQMGPxtV.mjs +589 -0
- package/lib/ollama-DPzBmq89.mjs +589 -0
- package/lib/ollama-DoBz5SFm.mjs +589 -0
- package/lib/openai-codex-Bi-4S4PX.mjs +255 -0
- package/lib/openai-codex-CQL_kvYL.mjs +255 -0
- package/lib/openai-codex-Ch8CkT3p.mjs +255 -0
- package/lib/openai-codex-responses-CvxL_FMF.mjs +3144 -0
- package/lib/openai-codex-responses-Cz-2qpC7.mjs +3144 -0
- package/lib/openai-codex-responses-pejZgdZo.mjs +3144 -0
- package/lib/openai-completions-CF8IyNtP.mjs +1360 -0
- package/lib/openai-completions-DIf361kF.mjs +1360 -0
- package/lib/openai-completions-i8doczAk.mjs +1360 -0
- package/lib/openai-reasoning-fallback-DGVVLgd1.mjs +286 -0
- package/lib/openai-reasoning-fallback-Nj6yB2rY.mjs +286 -0
- package/lib/openai-reasoning-fallback-OdJREP1o.mjs +286 -0
- package/lib/openai-responses-BqXJInHX.mjs +867 -0
- package/lib/openai-responses-DTkBiiy-.mjs +867 -0
- package/lib/openai-responses-Db_a-U4-.mjs +867 -0
- package/lib/opencode-DaJjcUbf.mjs +38 -0
- package/lib/opencode-DhMolSoB.mjs +38 -0
- package/lib/opencode-Rq_Q2vAO.mjs +38 -0
- package/lib/perplexity-9b-RQ0mV.mjs +194 -0
- package/lib/perplexity-C4iLVMUj.mjs +194 -0
- package/lib/perplexity-Uu7Jzg5b.mjs +194 -0
- package/lib/proxy-DDqrmjjC.mjs +190 -0
- package/lib/proxy-ZtUcl6r5.mjs +190 -0
- package/lib/proxy-pM_NIv-H.mjs +190 -0
- package/lib/request-debug-HJMoJncL.mjs +183 -0
- package/lib/sanitize-text-CfcXzw5X.mjs +33 -0
- package/lib/scrapers-BkFfcPHj.mjs +9198 -0
- package/lib/scrapers-CL-WgdU1.mjs +9198 -0
- package/lib/scrapers-CVptboMs.mjs +9198 -0
- package/lib/scrapers-CipyKyCH.mjs +9198 -0
- package/lib/scrapers-DGfrYhtw.mjs +9198 -0
- package/lib/scrapers-DSUPYoUF.mjs +9198 -0
- package/lib/scrapers-DZ2GXmp7.mjs +9198 -0
- package/lib/scrapers-nhQAvc8d.mjs +9198 -0
- package/lib/shell-snapshot-fn-env.sh +67 -43
- package/lib/src-BgpusnsB.mjs +5076 -0
- package/lib/src-DTid0g4K.mjs +5001 -0
- package/lib/src-lDmkSRbm.mjs +5006 -0
- package/lib/stream-BlldLkVq.mjs +10236 -0
- package/lib/stream-CRtexYLe.mjs +10236 -0
- package/lib/stream-C_RAoxJC.mjs +10236 -0
- package/lib/stream-markup-healing-2toHXWXM.mjs +491 -0
- package/lib/stream-markup-healing-DMsxBx1L.mjs +491 -0
- package/lib/stream-markup-healing-KMkiAA00.mjs +491 -0
- package/lib/turndown-DN7ByzEI.mjs +667 -0
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/config/fields.d.ts +1 -1
- package/lib/types/config/settings.d.ts +25 -3
- package/lib/types/config/truncate.d.ts +9 -5
- package/lib/types/tools/bash/background.d.ts +1 -1
- package/lib/types/tools/bash/bash-executor.d.ts +4 -0
- package/lib/types/tools/bash/bash-interceptor.d.ts +10 -8
- package/lib/types/tools/bash/cd-workdir.d.ts +35 -0
- package/lib/types/tools/bash/non-interactive-env.d.ts +2 -0
- package/lib/types/tools/bash/render.d.ts +4 -3
- package/lib/types/tools/bash/sanitize-text.d.ts +5 -0
- package/lib/types/tools/bash/shell-snapshot.d.ts +4 -1
- package/lib/types/tools/bash/shell-tokenize.d.ts +60 -0
- package/lib/types/tools/bash/streaming-output.d.ts +12 -212
- package/lib/types/tools/bash/which.d.ts +20 -0
- package/lib/types/tools/bash/windows-shell.d.ts +31 -0
- package/lib/types/tools/edit/adapter/index.d.ts +25 -3
- package/lib/types/tools/edit/adapter/tools/auto-generated-guard.d.ts +7 -17
- package/lib/types/tools/glob/adapter/index.d.ts +27 -1
- package/lib/types/tools/grep/adapter/index.d.ts +29 -1
- package/lib/types/tools/omp/edit/dispatch.d.ts +43 -0
- package/lib/types/tools/omp/edit/hashline/noop-loop-guard.d.ts +3 -1
- package/lib/types/tools/omp/sdk.d.ts +6 -0
- package/lib/types/tools/omp/tools/auto-generated-guard.d.ts +20 -0
- package/lib/types/tools/omp/tools/fetch.d.ts +2 -0
- package/lib/types/tools/omp/tools/read.d.ts +2 -8
- package/lib/types/tools/omp/tools/write.d.ts +4 -4
- package/lib/types/tools/omp/utils/image-loading.d.ts +10 -36
- package/lib/types/tools/read/adapter/index.d.ts +4 -1
- package/lib/types/tools/read-image/index.d.ts +4 -0
- package/lib/types/tools/shared/auto-generated-guard.dsh.d.ts +16 -4
- package/lib/types/tools/shared/bun-shim.d.ts +39 -3
- package/lib/types/tools/shared/fs-promises-shim.d.ts +3 -1
- package/lib/types/tools/shared/image-bridge.d.ts +98 -0
- package/lib/types/tools/shared/omp-prompt.d.ts +17 -9
- package/lib/types/tools/shared/session-state.d.ts +9 -3
- package/lib/utils-2Wq2eATG.mjs +8119 -0
- package/lib/utils-BnX8O3vi.mjs +12303 -0
- package/lib/utils-Bw139LTz.mjs +8119 -0
- package/lib/utils-CE8N8P4Q.mjs +12315 -0
- package/lib/utils-CZw4tVZQ.mjs +12315 -0
- package/lib/utils-C_MrQ_0z.mjs +12301 -0
- package/lib/utils-CiGN7OHR.mjs +12315 -0
- package/lib/utils-Cp76gCyk.mjs +8119 -0
- package/lib/utils-D0GRDgAr.mjs +12315 -0
- package/lib/utils-D0Z1fyoO.mjs +12299 -0
- package/lib/utils-D2YknRk4.mjs +51 -0
- package/lib/utils-DppGHXQB.mjs +51 -0
- package/lib/utils-DzXZDfYc.mjs +51 -0
- package/lib/utils-W8WdSBpX.mjs +12315 -0
- package/lib/vision-guard-01qSwFpf.mjs +92 -0
- package/lib/vision-guard-BDD4OrKo.mjs +92 -0
- package/lib/vision-guard-DzZGaOga.mjs +92 -0
- package/lib/wafer-CgtPHerf.mjs +17 -0
- package/lib/wafer-DRU0EjZX.mjs +17 -0
- package/lib/wafer-cBtrn6q9.mjs +17 -0
- package/lib/xai-oauth-Buk8XVvM.mjs +446 -0
- package/lib/xai-oauth-CMal8l1O.mjs +446 -0
- package/lib/xai-oauth-DPHDXKD7.mjs +446 -0
- package/lib/xiaomi-CZgwvX2G.mjs +157 -0
- package/lib/xiaomi-D2qT5cAC.mjs +157 -0
- package/lib/xiaomi-Dd87KSg5.mjs +157 -0
- package/lib/zai-7DWMkEqM.mjs +203 -0
- package/lib/zai-C59YnomG.mjs +203 -0
- package/lib/zai-CFeOt-53.mjs +203 -0
- package/lib/zip-Cg9ANN_U.mjs +1316 -0
- package/lib/zip-D36ZKsP8.mjs +1316 -0
- package/lib/zip-D6QXpvaJ.mjs +1316 -0
- package/package.json +14 -10
- package/presets/package.json +1 -1
- package/presets/tool-plus-ptc/preset.yml +1 -1
- package/presets/tool-plus-standard/preset.yml +1 -1
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
+
__installBunShim();
|
|
3
|
+
import { r as __exportAll } from "./fs-promises-shim-Bx0fpxuk.mjs";
|
|
4
|
+
import { P as $env } from "./src-BgpusnsB.mjs";
|
|
5
|
+
import { B as OpenAIHttpError, g as MissingApiKeyError, l as finalize, n as StreamTimeoutError, s as ProviderResponseError, t as ConfigurationError, v as AbortError } from "./error-Dd8DIqs-.mjs";
|
|
6
|
+
import { L as sanitizeSchemaForOpenAIResponses, k as toolWireSchema, s as resolveCacheRetention } from "./utils-Cp76gCyk.mjs";
|
|
7
|
+
import { C as applyResponsesReasoningParams, D as buildResponsesInput, K as getOpenAIPromptCacheKey, N as createInitialResponsesAssistantMessage, Q as isOpenAIResponsesProgressEvent, g as applyCommonResponsesSamplingParams, it as parseAzureDeploymentNameMap, n as getEnvApiKey, ot as processResponsesStream, yt as mapToOpenAIResponsesToolChoice } from "./stream-CRtexYLe.mjs";
|
|
8
|
+
import { t as createAbortSourceTracker } from "./abort-dIkZBV7Q.mjs";
|
|
9
|
+
import { t as AssistantMessageEventStream } from "./event-stream-BbFZJy-z.mjs";
|
|
10
|
+
import { n as getOpenAIStreamFirstEventTimeoutMs, o as iterateWithIdleTimeout, r as getOpenAIStreamIdleTimeoutMs } from "./idle-iterator-DUjKQEGT.mjs";
|
|
11
|
+
import { c as postOpenAIStream, r as createOpenAIReasoningEffortFallbackKey, s as resolveOpenAIReasoningEffortFallback, t as applyOpenAIReasoningEffortFallback } from "./openai-reasoning-fallback-Nj6yB2rY.mjs";
|
|
12
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@17.3.5/node_modules/@oh-my-pi/pi-ai/src/providers/azure-openai-responses.ts
|
|
13
|
+
var azure_openai_responses_exports = /* @__PURE__ */ __exportAll({ streamAzureOpenAIResponses: () => streamAzureOpenAIResponses });
|
|
14
|
+
const DEFAULT_AZURE_API_VERSION = "v1";
|
|
15
|
+
const AZURE_OPENAI_RESPONSES_FIRST_EVENT_TIMEOUT_MESSAGE = "Azure OpenAI responses stream timed out while waiting for the first event";
|
|
16
|
+
function resolveDeploymentName(model, options) {
|
|
17
|
+
if (options?.azureDeploymentName) return options.azureDeploymentName;
|
|
18
|
+
return parseAzureDeploymentNameMap($env.AZURE_OPENAI_DEPLOYMENT_NAME_MAP).get(model.id) ?? model.id;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Generate function for Azure OpenAI Responses API
|
|
22
|
+
*/
|
|
23
|
+
const streamAzureOpenAIResponses = (model, context, options) => {
|
|
24
|
+
if (options?.promptCache?.mode === "explicit" && resolveCacheRetention(options.cacheRetention) !== "none") throw new ConfigurationError(`OpenAI explicit prompt caching is unsupported for ${model.provider}/${model.id}; Azure Responses does not emit explicit cache controls.`);
|
|
25
|
+
const stream = new AssistantMessageEventStream();
|
|
26
|
+
(async () => {
|
|
27
|
+
const startTime = performance.now();
|
|
28
|
+
let firstTokenTime;
|
|
29
|
+
const deploymentName = resolveDeploymentName(model, options);
|
|
30
|
+
const output = createInitialResponsesAssistantMessage("azure-openai-responses", model.provider, model.id);
|
|
31
|
+
let rawRequestDump;
|
|
32
|
+
const abortTracker = createAbortSourceTracker(options?.signal);
|
|
33
|
+
const firstEventTimeoutAbortError = new StreamTimeoutError(AZURE_OPENAI_RESPONSES_FIRST_EVENT_TIMEOUT_MESSAGE);
|
|
34
|
+
const { requestAbortController, requestSignal } = abortTracker;
|
|
35
|
+
const onSseEvent = options?.onSseEvent;
|
|
36
|
+
const rawSseObserver = onSseEvent ? (event) => {
|
|
37
|
+
if (!event.event && event.data && event.data !== "[DONE]") try {
|
|
38
|
+
const parsed = JSON.parse(event.data);
|
|
39
|
+
const resolvedEvent = typeof parsed.type === "string" ? parsed.type : typeof parsed.object === "string" ? parsed.object : null;
|
|
40
|
+
if (resolvedEvent) {
|
|
41
|
+
event.event = resolvedEvent;
|
|
42
|
+
event.raw = [`event: ${resolvedEvent}`, ...event.raw];
|
|
43
|
+
}
|
|
44
|
+
} catch {}
|
|
45
|
+
onSseEvent(event, model);
|
|
46
|
+
} : void 0;
|
|
47
|
+
try {
|
|
48
|
+
const { url, headers, baseUrl } = buildAzureResponsesRequest(model, options?.apiKey || getEnvApiKey(model.provider) || "", options);
|
|
49
|
+
const requestModel = modelForAzureEndpoint(model, baseUrl);
|
|
50
|
+
let params = buildParams(requestModel, context, options, deploymentName);
|
|
51
|
+
const replacementPayload = await options?.onPayload?.(params, requestModel);
|
|
52
|
+
if (replacementPayload !== void 0) params = replacementPayload;
|
|
53
|
+
const idleTimeoutMs = options?.streamIdleTimeoutMs ?? getOpenAIStreamIdleTimeoutMs();
|
|
54
|
+
const firstEventTimeoutMs = options?.streamFirstEventTimeoutMs ?? getOpenAIStreamFirstEventTimeoutMs(idleTimeoutMs);
|
|
55
|
+
const requestTimeoutMs = firstEventTimeoutMs !== void 0 && firstEventTimeoutMs > 0 ? firstEventTimeoutMs : void 0;
|
|
56
|
+
rawRequestDump = {
|
|
57
|
+
provider: model.provider,
|
|
58
|
+
api: output.api,
|
|
59
|
+
model: model.id,
|
|
60
|
+
method: "POST",
|
|
61
|
+
url,
|
|
62
|
+
body: params
|
|
63
|
+
};
|
|
64
|
+
const reasoningEffortFallbackKey = createOpenAIReasoningEffortFallbackKey("azure-responses", url, typeof params.model === "string" ? params.model : model.id);
|
|
65
|
+
const attemptedReasoningEffortFallbacks = /* @__PURE__ */ new Set();
|
|
66
|
+
let openaiStream;
|
|
67
|
+
while (true) {
|
|
68
|
+
let requestTimeout;
|
|
69
|
+
if (requestTimeoutMs !== void 0) requestTimeout = setTimeout(() => abortTracker.abortLocally(firstEventTimeoutAbortError), requestTimeoutMs);
|
|
70
|
+
try {
|
|
71
|
+
const headersWithTimeout = { ...headers };
|
|
72
|
+
if (requestTimeoutMs !== void 0) headersWithTimeout["X-Stainless-Timeout"] = Math.floor(requestTimeoutMs / 1e3).toString();
|
|
73
|
+
openaiStream = (await postOpenAIStream({
|
|
74
|
+
url,
|
|
75
|
+
headers: headersWithTimeout,
|
|
76
|
+
body: params,
|
|
77
|
+
signal: requestSignal,
|
|
78
|
+
fetch: options?.fetch,
|
|
79
|
+
onSseEvent: rawSseObserver
|
|
80
|
+
})).events;
|
|
81
|
+
break;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
const capturedErrorResponse = error instanceof OpenAIHttpError ? error.captured : void 0;
|
|
84
|
+
const reasoningEffortFallback = !requestSignal.aborted ? resolveOpenAIReasoningEffortFallback(error, capturedErrorResponse, params) : void 0;
|
|
85
|
+
if (reasoningEffortFallback === void 0) throw error;
|
|
86
|
+
const retryMarker = `${reasoningEffortFallbackKey}:${String(reasoningEffortFallback)}`;
|
|
87
|
+
if (attemptedReasoningEffortFallbacks.has(retryMarker)) throw error;
|
|
88
|
+
attemptedReasoningEffortFallbacks.add(retryMarker);
|
|
89
|
+
applyOpenAIReasoningEffortFallback(params, reasoningEffortFallback);
|
|
90
|
+
rawRequestDump.body = params;
|
|
91
|
+
} finally {
|
|
92
|
+
if (requestTimeout !== void 0) clearTimeout(requestTimeout);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
stream.push({
|
|
96
|
+
type: "start",
|
|
97
|
+
partial: output
|
|
98
|
+
});
|
|
99
|
+
const timedOpenaiStream = iterateWithIdleTimeout(openaiStream, {
|
|
100
|
+
idleTimeoutMs,
|
|
101
|
+
firstItemTimeoutMs: firstEventTimeoutMs,
|
|
102
|
+
firstItemErrorMessage: AZURE_OPENAI_RESPONSES_FIRST_EVENT_TIMEOUT_MESSAGE,
|
|
103
|
+
errorMessage: "Azure OpenAI responses stream stalled while waiting for the next event",
|
|
104
|
+
onIdle: () => requestAbortController.abort(),
|
|
105
|
+
onFirstItemTimeout: () => abortTracker.abortLocally(firstEventTimeoutAbortError),
|
|
106
|
+
abortSignal: options?.signal,
|
|
107
|
+
isProgressItem: isOpenAIResponsesProgressEvent
|
|
108
|
+
});
|
|
109
|
+
let sawTerminalResponseEvent = false;
|
|
110
|
+
await processResponsesStream(timedOpenaiStream, output, stream, model, {
|
|
111
|
+
onFirstToken: () => {
|
|
112
|
+
if (!firstTokenTime) firstTokenTime = performance.now();
|
|
113
|
+
},
|
|
114
|
+
onCompleted: () => {
|
|
115
|
+
sawTerminalResponseEvent = true;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
const firstEventTimeoutError = abortTracker.getLocalAbortReason();
|
|
119
|
+
if (firstEventTimeoutError) throw firstEventTimeoutError;
|
|
120
|
+
if (abortTracker.wasCallerAbort()) throw new AbortError();
|
|
121
|
+
if (!sawTerminalResponseEvent) throw new ProviderResponseError("Azure OpenAI responses stream closed before a terminal response event was received", {
|
|
122
|
+
provider: model.provider,
|
|
123
|
+
kind: "incomplete-stream"
|
|
124
|
+
});
|
|
125
|
+
if (output.stopReason === "aborted" || output.stopReason === "error") throw new ProviderResponseError(output.errorMessage ?? "An unknown error occurred", {
|
|
126
|
+
provider: model.provider,
|
|
127
|
+
kind: "output"
|
|
128
|
+
});
|
|
129
|
+
output.duration = performance.now() - startTime;
|
|
130
|
+
if (firstTokenTime) output.ttft = firstTokenTime - startTime;
|
|
131
|
+
stream.push({
|
|
132
|
+
type: "done",
|
|
133
|
+
reason: output.stopReason,
|
|
134
|
+
message: output
|
|
135
|
+
});
|
|
136
|
+
stream.end();
|
|
137
|
+
} catch (error) {
|
|
138
|
+
const result = await finalize(error, {
|
|
139
|
+
api: model.api,
|
|
140
|
+
abortTracker,
|
|
141
|
+
rawRequestDump
|
|
142
|
+
});
|
|
143
|
+
output.stopReason = result.stopReason;
|
|
144
|
+
output.errorStatus = result.status;
|
|
145
|
+
output.errorId = result.id;
|
|
146
|
+
output.errorMessage = result.message;
|
|
147
|
+
output.duration = performance.now() - startTime;
|
|
148
|
+
if (firstTokenTime) output.ttft = firstTokenTime - startTime;
|
|
149
|
+
stream.push({
|
|
150
|
+
type: "error",
|
|
151
|
+
reason: output.stopReason,
|
|
152
|
+
error: output
|
|
153
|
+
});
|
|
154
|
+
stream.end();
|
|
155
|
+
}
|
|
156
|
+
})();
|
|
157
|
+
return stream;
|
|
158
|
+
};
|
|
159
|
+
function resolveAzureConfig(model, options) {
|
|
160
|
+
const apiVersion = options?.azureApiVersion || $env.AZURE_OPENAI_API_VERSION || DEFAULT_AZURE_API_VERSION;
|
|
161
|
+
const baseUrl = options?.azureBaseUrl?.trim() || $env.AZURE_OPENAI_BASE_URL?.trim() || void 0;
|
|
162
|
+
const resourceName = options?.azureResourceName || $env.AZURE_OPENAI_RESOURCE_NAME;
|
|
163
|
+
let resolvedBaseUrl = baseUrl;
|
|
164
|
+
if (!resolvedBaseUrl && resourceName) resolvedBaseUrl = `https://${resourceName}.openai.azure.com/openai/v1`;
|
|
165
|
+
if (!resolvedBaseUrl && model.baseUrl) resolvedBaseUrl = model.baseUrl;
|
|
166
|
+
if (!resolvedBaseUrl) throw new ConfigurationError("Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME, or pass azureBaseUrl, azureResourceName, or model.baseUrl.");
|
|
167
|
+
return {
|
|
168
|
+
baseUrl: resolvedBaseUrl.replace(/\/+$/, ""),
|
|
169
|
+
apiVersion
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function modelForAzureEndpoint(model, baseUrl) {
|
|
173
|
+
if (model.supportsComputerUseConfig !== void 0 || model.supportsComputerUse !== true) return model;
|
|
174
|
+
try {
|
|
175
|
+
const url = new URL(baseUrl);
|
|
176
|
+
if (url.protocol === "https:" && (url.hostname.endsWith(".openai.azure.com") || url.hostname === "models.inference.ai.azure.com")) return model;
|
|
177
|
+
} catch {}
|
|
178
|
+
return {
|
|
179
|
+
...model,
|
|
180
|
+
supportsComputerUse: false
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Replicates the `AzureOpenAI` SDK client's request shape for `/responses`:
|
|
185
|
+
* a string api key becomes a single `api-key` header (azure.mjs `authHeaders`;
|
|
186
|
+
* never `Authorization: Bearer`), `api-version` rides as a query parameter
|
|
187
|
+
* (azure.mjs constructor `defaultQuery`), and `/responses` is not a
|
|
188
|
+
* deployment-scoped path, so no `/deployments/{model}` URL rewriting applies.
|
|
189
|
+
* Custom model/options headers may override the auth header, matching the SDK's
|
|
190
|
+
* `buildHeaders` precedence.
|
|
191
|
+
*/
|
|
192
|
+
function buildAzureResponsesRequest(model, apiKey, options) {
|
|
193
|
+
if (!apiKey) {
|
|
194
|
+
const envKey = $env.AZURE_OPENAI_API_KEY;
|
|
195
|
+
if (!envKey) throw new MissingApiKeyError(void 0, "Azure OpenAI API key is required. Set AZURE_OPENAI_API_KEY environment variable or pass it as an argument.");
|
|
196
|
+
apiKey = envKey;
|
|
197
|
+
}
|
|
198
|
+
const headers = {
|
|
199
|
+
"api-key": apiKey,
|
|
200
|
+
...model.headers ?? {}
|
|
201
|
+
};
|
|
202
|
+
if (options?.headers) Object.assign(headers, options.headers);
|
|
203
|
+
const { baseUrl, apiVersion } = resolveAzureConfig(model, options);
|
|
204
|
+
return {
|
|
205
|
+
url: `${baseUrl}/responses?api-version=${encodeURIComponent(apiVersion)}`,
|
|
206
|
+
headers,
|
|
207
|
+
baseUrl
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function buildParams(model, context, options, deploymentName) {
|
|
211
|
+
const systemRole = model.reasoning && model.compat.supportsDeveloperRole ? "developer" : "system";
|
|
212
|
+
const params = {
|
|
213
|
+
model: deploymentName,
|
|
214
|
+
input: buildResponsesInput({
|
|
215
|
+
model,
|
|
216
|
+
context,
|
|
217
|
+
strictResponsesPairing: true,
|
|
218
|
+
supportsImageDetailOriginal: model.compat.supportsImageDetailOriginal,
|
|
219
|
+
systemRole,
|
|
220
|
+
nativeHistory: {
|
|
221
|
+
replay: true,
|
|
222
|
+
filterReasoning: false
|
|
223
|
+
},
|
|
224
|
+
includeThinkingSignatures: true,
|
|
225
|
+
developerStringContent: true,
|
|
226
|
+
preserveAssistantMessageIds: true
|
|
227
|
+
}),
|
|
228
|
+
stream: true,
|
|
229
|
+
prompt_cache_key: getOpenAIPromptCacheKey(options),
|
|
230
|
+
store: false
|
|
231
|
+
};
|
|
232
|
+
applyCommonResponsesSamplingParams(params, options, model);
|
|
233
|
+
if (options?.include?.length) params.include = Array.from(new Set(options.include));
|
|
234
|
+
if (context.tools) {
|
|
235
|
+
const serializedTools = [];
|
|
236
|
+
for (const tool of context.tools) {
|
|
237
|
+
if (tool.native?.type === "computer") {
|
|
238
|
+
if (model.supportsComputerUse === true) {
|
|
239
|
+
serializedTools.push({ type: "computer" });
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
} else if (tool.native !== void 0) continue;
|
|
243
|
+
serializedTools.push({
|
|
244
|
+
type: "function",
|
|
245
|
+
name: tool.name,
|
|
246
|
+
description: tool.description || "",
|
|
247
|
+
parameters: sanitizeSchemaForOpenAIResponses(toolWireSchema(tool)),
|
|
248
|
+
strict: false
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
if (serializedTools.length > 0) {
|
|
252
|
+
params.tools = serializedTools;
|
|
253
|
+
if (options?.toolChoice) {
|
|
254
|
+
let toolChoice = mapToOpenAIResponsesToolChoice(options.toolChoice);
|
|
255
|
+
const hasComputerTool = serializedTools.some((tool) => tool.type === "computer");
|
|
256
|
+
if (toolChoice && typeof toolChoice !== "string" && toolChoice.type === "computer" && !hasComputerTool) {
|
|
257
|
+
const computer = context.tools.find((tool) => tool.native?.type === "computer");
|
|
258
|
+
if (computer && serializedTools.some((tool) => tool.type === "function" && tool.name === computer.name)) toolChoice = {
|
|
259
|
+
type: "function",
|
|
260
|
+
name: computer.name
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
if (toolChoice && typeof toolChoice !== "string" && toolChoice.type === "function" && hasComputerTool) {
|
|
264
|
+
if (context.tools.find((tool) => tool.native?.type === "computer")?.name === toolChoice.name) toolChoice = { type: "computer" };
|
|
265
|
+
}
|
|
266
|
+
if (toolChoice && (typeof toolChoice === "string" || toolChoice.type === "computer" && hasComputerTool || toolChoice.type === "function" && serializedTools.some((tool) => tool.type === "function" && tool.name === toolChoice.name))) params.tool_choice = toolChoice;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
applyResponsesReasoningParams(params, model, options);
|
|
271
|
+
return params;
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
274
|
+
export { azure_openai_responses_exports as t };
|
package/lib/bun-shim.mjs
CHANGED
|
@@ -15,8 +15,11 @@ import JSON5 from "json5";
|
|
|
15
15
|
* `fromBase64` extensions Bun adds. Every change here is recorded in step.md
|
|
16
16
|
* ("Bun 兼容" section).
|
|
17
17
|
*
|
|
18
|
-
* `Bun.Image`
|
|
19
|
-
*
|
|
18
|
+
* `Bun.Image` is backed by `sharp` resolved at runtime (拍板#22, 2026-08-28:
|
|
19
|
+
* 图像链路重建——sharp 兼容层取代构造即抛错的桩,fetch/read 的 resizeImage
|
|
20
|
+
* 后端由此复活)。sharp 是宿主 DSH 的传递依赖(dsh-attachment-local 直接依
|
|
21
|
+
* 赖),本包不打包、不安装,运行时经 createRequire/import 级联解析;解析不到
|
|
22
|
+
* 时抛带指引的错误,`resizeImage` 的 try/catch 降级语义保持不变。
|
|
20
23
|
*/
|
|
21
24
|
function patchBase64() {
|
|
22
25
|
const bufProto = Buffer.prototype;
|
|
@@ -110,12 +113,35 @@ var BunFileSliceShim = class extends BunFileShim {
|
|
|
110
113
|
this.#start = start;
|
|
111
114
|
this.#end = end;
|
|
112
115
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
116
|
+
/** Resolve the slice window against `total` with Bun's Blob semantics:
|
|
117
|
+
* negative endpoints count from the end (slice(-8) is a window of length 8,
|
|
118
|
+
* so the sliced object's size is 8), NaN → 0, out-of-range clamps. */
|
|
119
|
+
#window(total) {
|
|
120
|
+
const from = Number.isNaN(this.#start) ? 0 : this.#start;
|
|
121
|
+
const to = this.#end === void 0 ? total : Number.isNaN(this.#end) ? 0 : this.#end;
|
|
122
|
+
const start = from < 0 ? Math.max(0, total + from) : Math.min(from, total);
|
|
123
|
+
const end = to < 0 ? Math.max(0, total + to) : Math.min(to, total);
|
|
124
|
+
return [start, Math.max(start, end)];
|
|
125
|
+
}
|
|
126
|
+
/** S-15a: positional read — open the file and read only the window instead
|
|
127
|
+
* of reading the whole file and subarray-ing (30MB file + slice(1000,2000)
|
|
128
|
+
* spiked 29.7MB under the old whole-read). */
|
|
117
129
|
async #sliced() {
|
|
118
|
-
|
|
130
|
+
const fh = await fsp.open(this.path, "r");
|
|
131
|
+
try {
|
|
132
|
+
const [start, end] = this.#window((await fh.stat()).size);
|
|
133
|
+
const length = end - start;
|
|
134
|
+
if (length <= 0) return /* @__PURE__ */ new Uint8Array(0);
|
|
135
|
+
const buf = new Uint8Array(length);
|
|
136
|
+
const { bytesRead } = await fh.read(buf, 0, length, start);
|
|
137
|
+
return bytesRead < length ? buf.subarray(0, bytesRead) : buf;
|
|
138
|
+
} finally {
|
|
139
|
+
await fh.close();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
get size() {
|
|
143
|
+
const [start, end] = this.#window(super.size);
|
|
144
|
+
return end - start;
|
|
119
145
|
}
|
|
120
146
|
async text() {
|
|
121
147
|
return new TextDecoder("utf-8", { fatal: false }).decode(await this.#sliced());
|
|
@@ -127,6 +153,13 @@ var BunFileSliceShim = class extends BunFileShim {
|
|
|
127
153
|
const b = await this.#sliced();
|
|
128
154
|
return b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength);
|
|
129
155
|
}
|
|
156
|
+
/** Blob semantics: stream yields only the slice window. */
|
|
157
|
+
stream() {
|
|
158
|
+
return new ReadableStream({ start: async (controller) => {
|
|
159
|
+
controller.enqueue(await this.#sliced());
|
|
160
|
+
controller.close();
|
|
161
|
+
} });
|
|
162
|
+
}
|
|
130
163
|
};
|
|
131
164
|
var FileSinkShim = class {
|
|
132
165
|
#fd = null;
|
|
@@ -333,9 +366,171 @@ function bunColor(color, format) {
|
|
|
333
366
|
if (format === "ansi256") return `\x1b[38;5;${16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5)}m`;
|
|
334
367
|
return `\x1b[38;2;${r};${g};${b}m`;
|
|
335
368
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
369
|
+
let sharpLoaderPromise;
|
|
370
|
+
async function loadSharp() {
|
|
371
|
+
if (!sharpLoaderPromise) sharpLoaderPromise = resolveSharp();
|
|
372
|
+
try {
|
|
373
|
+
return await sharpLoaderPromise;
|
|
374
|
+
} catch (error) {
|
|
375
|
+
sharpLoaderPromise = void 0;
|
|
376
|
+
throw error;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function normalizeSharp(mod) {
|
|
380
|
+
const candidate = mod?.default ?? mod;
|
|
381
|
+
const fn = candidate?.sharp ?? candidate;
|
|
382
|
+
return typeof fn === "function" ? fn : void 0;
|
|
383
|
+
}
|
|
384
|
+
async function resolveSharp() {
|
|
385
|
+
const errors = [];
|
|
386
|
+
try {
|
|
387
|
+
const sharp = normalizeSharp(await import("sharp"));
|
|
388
|
+
if (sharp) return sharp;
|
|
389
|
+
errors.push("import(\"sharp\"): no callable export");
|
|
390
|
+
} catch (error) {
|
|
391
|
+
errors.push(`import("sharp"): ${error.message.split("\n")[0]}`);
|
|
392
|
+
}
|
|
393
|
+
try {
|
|
394
|
+
const { createRequire } = await import("node:module");
|
|
395
|
+
const required = normalizeSharp(createRequire(import.meta.url)("sharp"));
|
|
396
|
+
if (required) return required;
|
|
397
|
+
errors.push("createRequire(\"sharp\"): no callable export");
|
|
398
|
+
} catch (error) {
|
|
399
|
+
errors.push(`createRequire("sharp"): ${error.message.split("\n")[0]}`);
|
|
400
|
+
}
|
|
401
|
+
try {
|
|
402
|
+
const { createRequire } = await import("node:module");
|
|
403
|
+
const { fileURLToPath } = await import("node:url");
|
|
404
|
+
const { existsSync } = await import("node:fs");
|
|
405
|
+
let dir = path.dirname(fileURLToPath(import.meta.url));
|
|
406
|
+
for (let depth = 0; depth < 10; depth++) {
|
|
407
|
+
const parent = path.dirname(dir);
|
|
408
|
+
if (parent === dir) break;
|
|
409
|
+
if (existsSync(path.join(parent, "node_modules", "@deepseek-ai", "dsh", "node_modules", "sharp", "package.json"))) {
|
|
410
|
+
const sharp = normalizeSharp(createRequire(path.join(parent, "noop.js"))("sharp"));
|
|
411
|
+
if (sharp) return sharp;
|
|
412
|
+
}
|
|
413
|
+
dir = parent;
|
|
414
|
+
}
|
|
415
|
+
} catch {}
|
|
416
|
+
throw new Error(`DSH: Bun.Image 需要 sharp,但运行时解析失败(${errors.join(";")})。sharp 应随宿主 @deepseek-ai/dsh(dsh-attachment-local)安装;图片缩放将按调用方的降级路径处理。`);
|
|
417
|
+
}
|
|
418
|
+
/** Map sharp's format vocabulary onto Bun.Image's (width/height/format[/hasAlpha]). */
|
|
419
|
+
function mapImageMetadata(meta) {
|
|
420
|
+
const format = typeof meta.format === "string" ? meta.format : void 0;
|
|
421
|
+
return {
|
|
422
|
+
width: typeof meta.width === "number" ? meta.width : 0,
|
|
423
|
+
height: typeof meta.height === "number" ? meta.height : 0,
|
|
424
|
+
...format !== void 0 ? { format } : {},
|
|
425
|
+
...typeof meta.channels === "number" ? { hasAlpha: meta.channels === 2 || meta.channels === 4 } : {}
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
var BunImageShim = class BunImageShim {
|
|
429
|
+
#source;
|
|
430
|
+
#steps;
|
|
431
|
+
constructor(bytes, steps) {
|
|
432
|
+
this.#source = bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : bytes;
|
|
433
|
+
this.#steps = steps ?? [];
|
|
434
|
+
}
|
|
435
|
+
#extend(step) {
|
|
436
|
+
return new BunImageShim(this.#source, [...this.#steps, step]);
|
|
437
|
+
}
|
|
438
|
+
async metadata() {
|
|
439
|
+
return mapImageMetadata(await (await loadSharp())(this.#source, { failOn: "error" }).metadata());
|
|
440
|
+
}
|
|
441
|
+
resize(widthOrOpts, height) {
|
|
442
|
+
if (typeof widthOrOpts === "object" && widthOrOpts !== null) return this.#extend({
|
|
443
|
+
op: "resize",
|
|
444
|
+
args: [widthOrOpts.width, widthOrOpts.height]
|
|
445
|
+
});
|
|
446
|
+
return this.#extend({
|
|
447
|
+
op: "resize",
|
|
448
|
+
args: [widthOrOpts, height]
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
/** Bun's resize() accepts { width, height, fit } — expose fit through to sharp. */
|
|
452
|
+
resizeWithFit(width, height, fit) {
|
|
453
|
+
return this.#extend({
|
|
454
|
+
op: "resize",
|
|
455
|
+
args: [
|
|
456
|
+
width,
|
|
457
|
+
height,
|
|
458
|
+
{ fit }
|
|
459
|
+
]
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
png() {
|
|
463
|
+
return this.#extend({
|
|
464
|
+
op: "png",
|
|
465
|
+
args: []
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
jpeg(opts) {
|
|
469
|
+
return this.#extend({
|
|
470
|
+
op: "jpeg",
|
|
471
|
+
args: [opts]
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
webp(opts) {
|
|
475
|
+
return this.#extend({
|
|
476
|
+
op: "webp",
|
|
477
|
+
args: [opts]
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
rotate() {
|
|
481
|
+
return this.#extend({
|
|
482
|
+
op: "rotate",
|
|
483
|
+
args: []
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
flip(flip) {
|
|
487
|
+
return this.#extend({
|
|
488
|
+
op: "flip",
|
|
489
|
+
args: [flip]
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
blur(radius) {
|
|
493
|
+
return this.#extend({
|
|
494
|
+
op: "blur",
|
|
495
|
+
args: [radius]
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
sharpen(radius) {
|
|
499
|
+
return this.#extend({
|
|
500
|
+
op: "sharpen",
|
|
501
|
+
args: [radius]
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
#build() {
|
|
505
|
+
return loadSharp().then((sharp) => {
|
|
506
|
+
let pipe = sharp(this.#source, { failOn: "error" });
|
|
507
|
+
for (const step of this.#steps) switch (step.op) {
|
|
508
|
+
case "resize": {
|
|
509
|
+
const [w, h, extra] = step.args;
|
|
510
|
+
pipe = pipe.resize(w ?? 0, h ?? 0, { fit: extra?.fit ?? "cover" });
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
513
|
+
case "png":
|
|
514
|
+
pipe = pipe.png();
|
|
515
|
+
break;
|
|
516
|
+
case "jpeg":
|
|
517
|
+
pipe = pipe.jpeg(step.args[0] ?? void 0);
|
|
518
|
+
break;
|
|
519
|
+
case "webp": pipe = pipe.webp(step.args[0] ?? void 0);
|
|
520
|
+
}
|
|
521
|
+
return pipe.toBuffer();
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
async bytes() {
|
|
525
|
+
return this.#build();
|
|
526
|
+
}
|
|
527
|
+
async toBase64() {
|
|
528
|
+
return Buffer.from(await this.#build()).toString("base64");
|
|
529
|
+
}
|
|
530
|
+
async write(destPath) {
|
|
531
|
+
const data = await this.#build();
|
|
532
|
+
await fsp.writeFile(destPath, data);
|
|
533
|
+
return data.byteLength;
|
|
339
534
|
}
|
|
340
535
|
};
|
|
341
536
|
async function memberToBytes(content) {
|
|
@@ -379,6 +574,50 @@ async function archiveWrite(destPath, record, opts) {
|
|
|
379
574
|
await fsp.mkdir(path.dirname(destPath), { recursive: true });
|
|
380
575
|
await fsp.writeFile(destPath, buf);
|
|
381
576
|
}
|
|
577
|
+
/** Consume one escape sequence starting at `esc` (text[esc] === ESC); returns
|
|
578
|
+
* the index of the first char after it. Malformed / unterminated sequences
|
|
579
|
+
* swallow through their last consumed byte (Bun parity on the S-8 corpus). */
|
|
580
|
+
function scanAnsiEscape(text, esc) {
|
|
581
|
+
const n = text.length;
|
|
582
|
+
const next = esc + 1 < n ? text.charCodeAt(esc + 1) : -1;
|
|
583
|
+
if (next === -1) return n;
|
|
584
|
+
if (next === 27) return esc + 1;
|
|
585
|
+
if (next === 91) {
|
|
586
|
+
let i = esc + 2;
|
|
587
|
+
if (i < n && text.charCodeAt(i) >= 60 && text.charCodeAt(i) <= 63) i++;
|
|
588
|
+
while (i < n && text.charCodeAt(i) >= 48 && text.charCodeAt(i) <= 63) i++;
|
|
589
|
+
while (i < n && text.charCodeAt(i) >= 32 && text.charCodeAt(i) <= 47) i++;
|
|
590
|
+
return i < n && text.charCodeAt(i) >= 64 && text.charCodeAt(i) <= 126 ? i + 1 : i;
|
|
591
|
+
}
|
|
592
|
+
if (next === 93 || next === 80 || next === 88 || next === 94 || next === 95) {
|
|
593
|
+
let i = esc + 2;
|
|
594
|
+
while (i < n) {
|
|
595
|
+
const c = text.charCodeAt(i);
|
|
596
|
+
if (c === 7) return i + 1;
|
|
597
|
+
if (c === 27 && i + 1 < n && text.charCodeAt(i + 1) === 92) return i + 2;
|
|
598
|
+
i++;
|
|
599
|
+
}
|
|
600
|
+
return n;
|
|
601
|
+
}
|
|
602
|
+
let i = esc + 1;
|
|
603
|
+
while (i < n && text.charCodeAt(i) >= 32 && text.charCodeAt(i) <= 47) i++;
|
|
604
|
+
return i < n && text.charCodeAt(i) >= 48 && text.charCodeAt(i) <= 126 ? i + 1 : i;
|
|
605
|
+
}
|
|
606
|
+
function bunStripANSI(text) {
|
|
607
|
+
if (text.indexOf("\x1B") === -1) return text;
|
|
608
|
+
let out = "";
|
|
609
|
+
let i = 0;
|
|
610
|
+
const n = text.length;
|
|
611
|
+
while (i < n) {
|
|
612
|
+
if (text.charCodeAt(i) !== 27) {
|
|
613
|
+
out += text[i];
|
|
614
|
+
i++;
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
i = scanAnsiEscape(text, i);
|
|
618
|
+
}
|
|
619
|
+
return out;
|
|
620
|
+
}
|
|
382
621
|
function installBunShim() {
|
|
383
622
|
patchBase64();
|
|
384
623
|
const g = globalThis;
|
|
@@ -394,9 +633,10 @@ function installBunShim() {
|
|
|
394
633
|
Glob: GlobShim,
|
|
395
634
|
Archive: { write: archiveWrite },
|
|
396
635
|
FileSink: FileSinkShim,
|
|
397
|
-
Image:
|
|
636
|
+
Image: BunImageShim,
|
|
398
637
|
CryptoHasher: CryptoHasherShim,
|
|
399
638
|
color: bunColor,
|
|
639
|
+
stripANSI: bunStripANSI,
|
|
400
640
|
JSON,
|
|
401
641
|
JSON5,
|
|
402
642
|
Encoding: {},
|
|
@@ -408,4 +648,4 @@ function installBunShim() {
|
|
|
408
648
|
bun.hash.xxHash64 = bunHashXxHash64;
|
|
409
649
|
}
|
|
410
650
|
//#endregion
|
|
411
|
-
export { BunFileShim, BunFileSliceShim, FileSinkShim, GlobShim, installBunShim };
|
|
651
|
+
export { BunFileShim, BunFileSliceShim, BunImageShim, FileSinkShim, GlobShim, bunStripANSI, installBunShim };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
+
__installBunShim();
|
|
3
|
+
import { i as getBundledProviders, r as getBundledModels } from "./models-CfT4coYT.mjs";
|
|
4
|
+
import { r as isZeroCostXaiOAuthReference } from "./identity-DnB63pS7.mjs";
|
|
5
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-catalog@17.3.5/node_modules/@oh-my-pi/pi-catalog/src/provider-models/bundled-references.ts
|
|
6
|
+
/**
|
|
7
|
+
* Project a built `Model` back to spec stage: `compat` becomes the verbatim
|
|
8
|
+
* sparse override record (`compatConfig`), never the resolved view. Discovery
|
|
9
|
+
* mappers spread these references into the specs they hand to the model
|
|
10
|
+
* manager, which rebuilds via `buildModel`.
|
|
11
|
+
*/
|
|
12
|
+
function toModelSpec(model) {
|
|
13
|
+
const { compat: _compat, compatConfig, ...rest } = model;
|
|
14
|
+
return {
|
|
15
|
+
...rest,
|
|
16
|
+
compat: compatConfig
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function createBundledReferenceMap(provider) {
|
|
20
|
+
const references = /* @__PURE__ */ new Map();
|
|
21
|
+
for (const model of getBundledModels(provider)) references.set(model.id, toModelSpec(model));
|
|
22
|
+
return references;
|
|
23
|
+
}
|
|
24
|
+
let globalReferences;
|
|
25
|
+
function getGlobalReferences() {
|
|
26
|
+
if (globalReferences) return globalReferences;
|
|
27
|
+
const references = /* @__PURE__ */ new Map();
|
|
28
|
+
for (const provider of getBundledProviders()) for (const model of getBundledModels(provider)) {
|
|
29
|
+
const candidate = model;
|
|
30
|
+
if (isZeroCostXaiOAuthReference(candidate)) continue;
|
|
31
|
+
const existing = references.get(candidate.id);
|
|
32
|
+
if (!existing) references.set(candidate.id, candidate);
|
|
33
|
+
else if (candidate.contextWindow !== existing.contextWindow) {
|
|
34
|
+
if ((candidate.contextWindow ?? 0) > (existing.contextWindow ?? 0)) references.set(candidate.id, candidate);
|
|
35
|
+
} else if (candidate.maxTokens !== existing.maxTokens) {
|
|
36
|
+
if ((candidate.maxTokens ?? 0) > (existing.maxTokens ?? 0)) references.set(candidate.id, candidate);
|
|
37
|
+
} else if (existing.provider !== "openai" && candidate.provider === "openai") references.set(candidate.id, candidate);
|
|
38
|
+
}
|
|
39
|
+
globalReferences = references;
|
|
40
|
+
return references;
|
|
41
|
+
}
|
|
42
|
+
function createReferenceResolver(providerReferenceSource) {
|
|
43
|
+
let lazyProviderReferences;
|
|
44
|
+
const getProviderReferences = typeof providerReferenceSource === "function" ? () => lazyProviderReferences ??= providerReferenceSource() : () => providerReferenceSource;
|
|
45
|
+
return (modelId) => {
|
|
46
|
+
const providerRefs = getProviderReferences();
|
|
47
|
+
const globalRefs = getGlobalReferences();
|
|
48
|
+
const providerRef = providerRefs.get(modelId);
|
|
49
|
+
if (providerRef) return providerRef;
|
|
50
|
+
const globalRef = globalRefs.get(modelId);
|
|
51
|
+
return globalRef ? toModelSpec(globalRef) : void 0;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { createReferenceResolver as n, toModelSpec as r, createBundledReferenceMap as t };
|