@xiaoso/dsh-tool-plus 0.1.0-beta.2 → 0.1.0-beta.3
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/amazon-bedrock-D-shAr1X.mjs +917 -0
- package/lib/anthropic-BWsZFzU8.mjs +262 -0
- package/lib/anthropic-CMT1Qj1t.mjs +3115 -0
- package/lib/api-key-login-CpzSezsi.mjs +157 -0
- package/lib/aws-credentials-8Mgn5MAy.mjs +867 -0
- package/lib/azure-openai-responses-CNkHiLUh.mjs +274 -0
- package/lib/bun-shim.mjs +172 -7
- package/lib/bundled-references-CSuBco5p.mjs +55 -0
- package/lib/callback-server-BEFNf-jf.mjs +398 -0
- package/lib/client.js +110 -40
- package/lib/cursor-BIQfBC6V.mjs +135 -0
- package/lib/cursor-DNk6eXDd.mjs +5470 -0
- package/lib/cursor-MjSm74IJ.mjs +273 -0
- package/lib/device-code-OI_tQcmc.mjs +51 -0
- package/lib/devin-CldyPD8K.mjs +95 -0
- package/lib/devin-CzRpTUOA.mjs +114 -0
- package/lib/devin-DXOeNyU7.mjs +542 -0
- package/lib/error-B3bevhrs.mjs +1449 -0
- package/lib/event-stream-BDPi64mK.mjs +151 -0
- package/lib/github-copilot-4GaMtQmg.mjs +208 -0
- package/lib/github-copilot-B2HGSIJK.mjs +104 -0
- package/lib/gitlab-duo-akICyfeD.mjs +155 -0
- package/lib/gitlab-duo-workflow-CSEgYk3N.mjs +91 -0
- package/lib/google-antigravity-Dlkdhahq.mjs +198 -0
- package/lib/google-auth-DhqpOYrX.mjs +232 -0
- package/lib/google-gemini-cli-BG_LRdIV.mjs +850 -0
- package/lib/google-gemini-cli-zJhiOcND.mjs +211 -0
- package/lib/google-oauth-shared-CwNWYdmR.mjs +147 -0
- package/lib/google-shared-DzhCb9b0.mjs +760 -0
- package/lib/google-vertex-kscbkyRb.mjs +99 -0
- package/lib/google-zyDOG9x7.mjs +30 -0
- package/lib/identity-DnB63pS7.mjs +219 -0
- package/lib/idle-iterator-C6XbWcuB.mjs +366 -0
- package/lib/index.mjs +2865 -2745
- package/lib/kimi-DMVI-zrZ.mjs +236 -0
- package/lib/markit-M0jhziqU.mjs +1417 -0
- package/lib/minimax-code-BK-3eBbz.mjs +53 -0
- package/lib/models-CfT4coYT.mjs +104660 -0
- package/lib/ollama-BQMGPxtV.mjs +589 -0
- package/lib/openai-codex-CQL_kvYL.mjs +255 -0
- package/lib/openai-codex-responses-Cz-2qpC7.mjs +3144 -0
- package/lib/openai-completions-i8doczAk.mjs +1360 -0
- package/lib/openai-reasoning-fallback-DGVVLgd1.mjs +286 -0
- package/lib/openai-responses-DTkBiiy-.mjs +867 -0
- package/lib/opencode-DaJjcUbf.mjs +38 -0
- package/lib/perplexity-9b-RQ0mV.mjs +194 -0
- package/lib/proxy-ZtUcl6r5.mjs +190 -0
- package/lib/scrapers-CL-WgdU1.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/src-DTid0g4K.mjs +5001 -0
- package/lib/stream-C_RAoxJC.mjs +10236 -0
- package/lib/stream-markup-healing-2toHXWXM.mjs +491 -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 +16 -2
- package/lib/types/tools/omp/sdk.d.ts +6 -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/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/bun-shim.d.ts +35 -3
- package/lib/types/tools/shared/image-bridge.d.ts +98 -0
- package/lib/types/tools/shared/omp-prompt.d.ts +4 -2
- package/lib/utils-2Wq2eATG.mjs +8119 -0
- package/lib/utils-BnX8O3vi.mjs +12303 -0
- package/lib/utils-CE8N8P4Q.mjs +12315 -0
- package/lib/utils-C_MrQ_0z.mjs +12301 -0
- package/lib/utils-D0Z1fyoO.mjs +12299 -0
- package/lib/utils-DppGHXQB.mjs +51 -0
- package/lib/utils-W8WdSBpX.mjs +12315 -0
- package/lib/vision-guard-BDD4OrKo.mjs +92 -0
- package/lib/wafer-DRU0EjZX.mjs +17 -0
- package/lib/xai-oauth-DPHDXKD7.mjs +446 -0
- package/lib/xiaomi-Dd87KSg5.mjs +157 -0
- package/lib/zai-CFeOt-53.mjs +203 -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-B-9cMxz5.mjs";
|
|
4
|
+
import { P as $env } from "./src-DTid0g4K.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-B3bevhrs.mjs";
|
|
6
|
+
import { L as sanitizeSchemaForOpenAIResponses, k as toolWireSchema, s as resolveCacheRetention } from "./utils-2Wq2eATG.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-C_RAoxJC.mjs";
|
|
8
|
+
import { t as createAbortSourceTracker } from "./abort-B7izMMna.mjs";
|
|
9
|
+
import { t as AssistantMessageEventStream } from "./event-stream-BDPi64mK.mjs";
|
|
10
|
+
import { n as getOpenAIStreamFirstEventTimeoutMs, o as iterateWithIdleTimeout, r as getOpenAIStreamIdleTimeoutMs } from "./idle-iterator-C6XbWcuB.mjs";
|
|
11
|
+
import { c as postOpenAIStream, r as createOpenAIReasoningEffortFallbackKey, s as resolveOpenAIReasoningEffortFallback, t as applyOpenAIReasoningEffortFallback } from "./openai-reasoning-fallback-DGVVLgd1.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;
|
|
@@ -333,9 +336,171 @@ function bunColor(color, format) {
|
|
|
333
336
|
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
337
|
return `\x1b[38;2;${r};${g};${b}m`;
|
|
335
338
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
+
let sharpLoaderPromise;
|
|
340
|
+
async function loadSharp() {
|
|
341
|
+
if (!sharpLoaderPromise) sharpLoaderPromise = resolveSharp();
|
|
342
|
+
try {
|
|
343
|
+
return await sharpLoaderPromise;
|
|
344
|
+
} catch (error) {
|
|
345
|
+
sharpLoaderPromise = void 0;
|
|
346
|
+
throw error;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
function normalizeSharp(mod) {
|
|
350
|
+
const candidate = mod?.default ?? mod;
|
|
351
|
+
const fn = candidate?.sharp ?? candidate;
|
|
352
|
+
return typeof fn === "function" ? fn : void 0;
|
|
353
|
+
}
|
|
354
|
+
async function resolveSharp() {
|
|
355
|
+
const errors = [];
|
|
356
|
+
try {
|
|
357
|
+
const sharp = normalizeSharp(await import("sharp"));
|
|
358
|
+
if (sharp) return sharp;
|
|
359
|
+
errors.push("import(\"sharp\"): no callable export");
|
|
360
|
+
} catch (error) {
|
|
361
|
+
errors.push(`import("sharp"): ${error.message.split("\n")[0]}`);
|
|
362
|
+
}
|
|
363
|
+
try {
|
|
364
|
+
const { createRequire } = await import("node:module");
|
|
365
|
+
const required = normalizeSharp(createRequire(import.meta.url)("sharp"));
|
|
366
|
+
if (required) return required;
|
|
367
|
+
errors.push("createRequire(\"sharp\"): no callable export");
|
|
368
|
+
} catch (error) {
|
|
369
|
+
errors.push(`createRequire("sharp"): ${error.message.split("\n")[0]}`);
|
|
370
|
+
}
|
|
371
|
+
try {
|
|
372
|
+
const { createRequire } = await import("node:module");
|
|
373
|
+
const { fileURLToPath } = await import("node:url");
|
|
374
|
+
const { existsSync } = await import("node:fs");
|
|
375
|
+
let dir = path.dirname(fileURLToPath(import.meta.url));
|
|
376
|
+
for (let depth = 0; depth < 10; depth++) {
|
|
377
|
+
const parent = path.dirname(dir);
|
|
378
|
+
if (parent === dir) break;
|
|
379
|
+
if (existsSync(path.join(parent, "node_modules", "@deepseek-ai", "dsh", "node_modules", "sharp", "package.json"))) {
|
|
380
|
+
const sharp = normalizeSharp(createRequire(path.join(parent, "noop.js"))("sharp"));
|
|
381
|
+
if (sharp) return sharp;
|
|
382
|
+
}
|
|
383
|
+
dir = parent;
|
|
384
|
+
}
|
|
385
|
+
} catch {}
|
|
386
|
+
throw new Error(`DSH: Bun.Image 需要 sharp,但运行时解析失败(${errors.join(";")})。sharp 应随宿主 @deepseek-ai/dsh(dsh-attachment-local)安装;图片缩放将按调用方的降级路径处理。`);
|
|
387
|
+
}
|
|
388
|
+
/** Map sharp's format vocabulary onto Bun.Image's (width/height/format[/hasAlpha]). */
|
|
389
|
+
function mapImageMetadata(meta) {
|
|
390
|
+
const format = typeof meta.format === "string" ? meta.format : void 0;
|
|
391
|
+
return {
|
|
392
|
+
width: typeof meta.width === "number" ? meta.width : 0,
|
|
393
|
+
height: typeof meta.height === "number" ? meta.height : 0,
|
|
394
|
+
...format !== void 0 ? { format } : {},
|
|
395
|
+
...typeof meta.channels === "number" ? { hasAlpha: meta.channels === 2 || meta.channels === 4 } : {}
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
var BunImageShim = class BunImageShim {
|
|
399
|
+
#source;
|
|
400
|
+
#steps;
|
|
401
|
+
constructor(bytes, steps) {
|
|
402
|
+
this.#source = bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : bytes;
|
|
403
|
+
this.#steps = steps ?? [];
|
|
404
|
+
}
|
|
405
|
+
#extend(step) {
|
|
406
|
+
return new BunImageShim(this.#source, [...this.#steps, step]);
|
|
407
|
+
}
|
|
408
|
+
async metadata() {
|
|
409
|
+
return mapImageMetadata(await (await loadSharp())(this.#source, { failOn: "error" }).metadata());
|
|
410
|
+
}
|
|
411
|
+
resize(widthOrOpts, height) {
|
|
412
|
+
if (typeof widthOrOpts === "object" && widthOrOpts !== null) return this.#extend({
|
|
413
|
+
op: "resize",
|
|
414
|
+
args: [widthOrOpts.width, widthOrOpts.height]
|
|
415
|
+
});
|
|
416
|
+
return this.#extend({
|
|
417
|
+
op: "resize",
|
|
418
|
+
args: [widthOrOpts, height]
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
/** Bun's resize() accepts { width, height, fit } — expose fit through to sharp. */
|
|
422
|
+
resizeWithFit(width, height, fit) {
|
|
423
|
+
return this.#extend({
|
|
424
|
+
op: "resize",
|
|
425
|
+
args: [
|
|
426
|
+
width,
|
|
427
|
+
height,
|
|
428
|
+
{ fit }
|
|
429
|
+
]
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
png() {
|
|
433
|
+
return this.#extend({
|
|
434
|
+
op: "png",
|
|
435
|
+
args: []
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
jpeg(opts) {
|
|
439
|
+
return this.#extend({
|
|
440
|
+
op: "jpeg",
|
|
441
|
+
args: [opts]
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
webp(opts) {
|
|
445
|
+
return this.#extend({
|
|
446
|
+
op: "webp",
|
|
447
|
+
args: [opts]
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
rotate() {
|
|
451
|
+
return this.#extend({
|
|
452
|
+
op: "rotate",
|
|
453
|
+
args: []
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
flip(flip) {
|
|
457
|
+
return this.#extend({
|
|
458
|
+
op: "flip",
|
|
459
|
+
args: [flip]
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
blur(radius) {
|
|
463
|
+
return this.#extend({
|
|
464
|
+
op: "blur",
|
|
465
|
+
args: [radius]
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
sharpen(radius) {
|
|
469
|
+
return this.#extend({
|
|
470
|
+
op: "sharpen",
|
|
471
|
+
args: [radius]
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
#build() {
|
|
475
|
+
return loadSharp().then((sharp) => {
|
|
476
|
+
let pipe = sharp(this.#source, { failOn: "error" });
|
|
477
|
+
for (const step of this.#steps) switch (step.op) {
|
|
478
|
+
case "resize": {
|
|
479
|
+
const [w, h, extra] = step.args;
|
|
480
|
+
pipe = pipe.resize(w ?? 0, h ?? 0, { fit: extra?.fit ?? "cover" });
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
483
|
+
case "png":
|
|
484
|
+
pipe = pipe.png();
|
|
485
|
+
break;
|
|
486
|
+
case "jpeg":
|
|
487
|
+
pipe = pipe.jpeg(step.args[0] ?? void 0);
|
|
488
|
+
break;
|
|
489
|
+
case "webp": pipe = pipe.webp(step.args[0] ?? void 0);
|
|
490
|
+
}
|
|
491
|
+
return pipe.toBuffer();
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
async bytes() {
|
|
495
|
+
return this.#build();
|
|
496
|
+
}
|
|
497
|
+
async toBase64() {
|
|
498
|
+
return Buffer.from(await this.#build()).toString("base64");
|
|
499
|
+
}
|
|
500
|
+
async write(destPath) {
|
|
501
|
+
const data = await this.#build();
|
|
502
|
+
await fsp.writeFile(destPath, data);
|
|
503
|
+
return data.byteLength;
|
|
339
504
|
}
|
|
340
505
|
};
|
|
341
506
|
async function memberToBytes(content) {
|
|
@@ -394,7 +559,7 @@ function installBunShim() {
|
|
|
394
559
|
Glob: GlobShim,
|
|
395
560
|
Archive: { write: archiveWrite },
|
|
396
561
|
FileSink: FileSinkShim,
|
|
397
|
-
Image:
|
|
562
|
+
Image: BunImageShim,
|
|
398
563
|
CryptoHasher: CryptoHasherShim,
|
|
399
564
|
color: bunColor,
|
|
400
565
|
JSON,
|
|
@@ -408,4 +573,4 @@ function installBunShim() {
|
|
|
408
573
|
bun.hash.xxHash64 = bunHashXxHash64;
|
|
409
574
|
}
|
|
410
575
|
//#endregion
|
|
411
|
-
export { BunFileShim, BunFileSliceShim, FileSinkShim, GlobShim, installBunShim };
|
|
576
|
+
export { BunFileShim, BunFileSliceShim, BunImageShim, FileSinkShim, GlobShim, 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 };
|