@xiaoso/dsh-tool-plus 0.1.16-beta.0 → 0.1.17-beta.0

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.
Files changed (109) hide show
  1. package/lib/{abort-DZ54CaKU.mjs → abort-BTblp0Rt.mjs} +2 -2
  2. package/lib/{alibaba-coding-plan-DODpkcqi.mjs → alibaba-coding-plan-t3R4YKCB.mjs} +3 -3
  3. package/lib/{alibaba-token-plan-C6lpKCda.mjs → alibaba-token-plan-CO4djG1y.mjs} +4 -4
  4. package/lib/{alibaba-token-plan-CHGyWOfX.mjs → alibaba-token-plan-CUjYJX0-.mjs} +1 -1
  5. package/lib/{anthropic-Dv_GGX6g.mjs → anthropic-nf7w6so1.mjs} +48 -21
  6. package/lib/{api-key-validation-MnMf_ihX.mjs → api-key-validation-C_tZ7Y9a.mjs} +2 -2
  7. package/lib/behavior-BwvTUtag.mjs +111 -0
  8. package/lib/{browser-render-BZXt548F.mjs → browser-render-BQaEVK_n.mjs} +4 -4
  9. package/lib/{reference-CtvM4zLU.mjs → bundled-references-CrQ4dQcT.mjs} +57 -4
  10. package/lib/cascade-BWjRTD1q.mjs +30265 -0
  11. package/lib/{cline-pass-BT9CBEOj.mjs → cline-pass-Bjm-O8GG.mjs} +2 -2
  12. package/lib/cloudflare-CKXRJ0l9.mjs +37 -0
  13. package/lib/{cloudflare-ai-gateway-DReN6ohJ.mjs → cloudflare-ai-gateway-BpnBSjwV.mjs} +8 -4
  14. package/lib/cloudflare-workers-ai-odj9XswL.mjs +32 -0
  15. package/lib/collapse-_nkb2dn7.mjs +1945 -0
  16. package/lib/{coreweave-C82HrLpb.mjs → coreweave-CGDZOD8-.mjs} +1 -1
  17. package/lib/{coreweave-C68UgRQO.mjs → coreweave-DwffcgW5.mjs} +4 -4
  18. package/lib/cursor-BgOuV7Qf.mjs +794 -0
  19. package/lib/{cursor-_gHHq-Dq.mjs → cursor-CF1iHHbv.mjs} +68 -19
  20. package/lib/{cursor-proto-Cr_WEMuv.mjs → cursor-proto-BuNTjX3L.mjs} +823 -23
  21. package/lib/{devin-QpfTSl9H.mjs → devin-7OEeEb80.mjs} +112 -31
  22. package/lib/{devin-proto-DYhp4Ty6.mjs → devin-proto-C-QreeAv.mjs} +71 -5
  23. package/lib/{dom-DG3sPESc.mjs → dom-BmbZv4v9.mjs} +598 -182
  24. package/lib/{error-O63pC8zg.mjs → error-8LVo7tug.mjs} +725 -104
  25. package/lib/factory-droid-ChhmsGWb.mjs +71 -0
  26. package/lib/{fs-promises-shim-B2YFWkcd.mjs → fs-promises-shim-CANAxFWh.mjs} +10 -1
  27. package/lib/{github-copilot-BMEcw8N1.mjs → github-copilot-QwevdT30.mjs} +4 -4
  28. package/lib/{github-copilot-headers-DnjGEbko.mjs → github-copilot-headers-CAUZ0rUD.mjs} +138 -26
  29. package/lib/{gitlab-duo-DnHqJjFY.mjs → gitlab-duo-DigV7k_o.mjs} +2 -2
  30. package/lib/{google-antigravity-B1mSckrK.mjs → google-antigravity-D-oe0r8A.mjs} +6 -7
  31. package/lib/{google-gemini-cli-DJwThCCn.mjs → google-gemini-cli-CQBHgGJT.mjs} +5 -6
  32. package/lib/{google-oauth-shared-BctLpVUN.mjs → google-oauth-shared-CvgVIUwJ.mjs} +2 -2
  33. package/lib/google-validation-CdvRj4ec.mjs +126 -0
  34. package/lib/id-EJwVLDHE.mjs +2548 -0
  35. package/lib/index.mjs +248 -258
  36. package/lib/{kilo-BEgEwMJQ.mjs → kilo-5r6OffCa.mjs} +2 -2
  37. package/lib/{kimi-T9NldEIJ.mjs → kimi-DOOtbXmm.mjs} +9 -10
  38. package/lib/{launch-BIWNyrBB.mjs → launch-DkAjib7h.mjs} +1 -1
  39. package/lib/{markit-Dvp2JPdT.mjs → markit-CCcyeAds.mjs} +359 -140
  40. package/lib/{models-DnXMYGcJ.mjs → models-DCpDT_im.mjs} +199203 -112275
  41. package/lib/{muse-code-CNvqqAp6.mjs → muse-code-CYf8zj_B.mjs} +5 -5
  42. package/lib/{openai-codex-D5-CyTxa.mjs → openai-codex-Cj-TvSFh.mjs} +13 -10
  43. package/lib/{perplexity-A2PEoGaC.mjs → perplexity-Dh_Qgsmx.mjs} +68 -25
  44. package/lib/{pkce-BYjmugmw.mjs → pkce-DO-jBJLV.mjs} +1 -1
  45. package/lib/pricing-DusBEhwm.mjs +593 -0
  46. package/lib/{readability-uGhqb4GC.mjs → readability-XHK0o3bv.mjs} +287 -27
  47. package/lib/{scrapers-C6oBIusN.mjs → scrapers-B6PADOVm.mjs} +13 -13
  48. package/lib/slugify-ynYWBIA5.mjs +11 -0
  49. package/lib/snowflake-B_jap6lz.mjs +666 -0
  50. package/lib/snowflake-Cu1ZyOp6.mjs +151 -0
  51. package/lib/{src-AELUUb5U.mjs → src-BhinCSpi.mjs} +1172 -458
  52. package/lib/{stream-AVOoe5Hj.mjs → stream-D2ivg3GH.mjs} +3740 -5311
  53. package/lib/{turndown-D6fof1OX.mjs → turndown-Vya8SavL.mjs} +82 -30
  54. package/lib/types/tools/hashline/native/index.d.ts +2 -2
  55. package/lib/types/tools/hashline/native/policy.d.ts +19 -21
  56. package/lib/types/tools/omp/session/agent-storage.d.ts +3 -3
  57. package/lib/types/tools/shared/bun-named-shim.d.ts +5 -0
  58. package/lib/{types-BLrLohwK.mjs → types-tH1v9uRm.mjs} +2 -2
  59. package/lib/{utils-cZX3f_Ls.mjs → utils-C_Ncya1r.mjs} +1737 -509
  60. package/lib/utils-D2tK38xq.mjs +34006 -0
  61. package/lib/{utils-I4I8azHN.mjs → utils-DrDwmNtu.mjs} +8 -3
  62. package/lib/{xai-oauth-CbeldUSV.mjs → xai-oauth-DLLzX6my.mjs} +4 -4
  63. package/lib/{xiaomi-Dl3VSs04.mjs → xiaomi-CqK-KivK.mjs} +2 -2
  64. package/lib/{zai-FyjGSypr.mjs → zai-DoJ2xPIH.mjs} +2 -2
  65. package/lib/{zip-DRrycScC.mjs → zip-DG1mUV6X.mjs} +1 -1
  66. package/package.json +8 -8
  67. package/lib/amazon-bedrock-Dx0rr9dY.mjs +0 -996
  68. package/lib/anthropic-ClCw0PV_.mjs +0 -3624
  69. package/lib/anthropic-wire-lbGAFzYb.mjs +0 -927
  70. package/lib/azure-openai-responses-WE_bgFWp.mjs +0 -285
  71. package/lib/bundled-references-DY3EJxZV.mjs +0 -56
  72. package/lib/cloudflare-ai-gateway-CrMa97Ap.mjs +0 -44
  73. package/lib/collapse-CkMNRNr7.mjs +0 -2304
  74. package/lib/cursor-C6jaIJDg.mjs +0 -283
  75. package/lib/cursor-D-XZYDf_.mjs +0 -4544
  76. package/lib/deterministic-id-CUEIMSqR.mjs +0 -17
  77. package/lib/devin-ExGIghmx.mjs +0 -69
  78. package/lib/devin-u0ljw5P6.mjs +0 -628
  79. package/lib/effort-BdtQMN-_.mjs +0 -23
  80. package/lib/event-stream-BKEtb45Y.mjs +0 -167
  81. package/lib/gemini-headers-Co9cVvex.mjs +0 -54
  82. package/lib/google-auth-qAN-6DMW.mjs +0 -232
  83. package/lib/google-gemini-cli-B2Aw1S5w.mjs +0 -844
  84. package/lib/google-lTxuq28n.mjs +0 -38
  85. package/lib/google-shared-Y01j9xOr.mjs +0 -856
  86. package/lib/google-validation-BEkNs-Bx.mjs +0 -18
  87. package/lib/google-vertex-DcM-FRC5.mjs +0 -99
  88. package/lib/hosts-00rjRzUD.mjs +0 -203
  89. package/lib/id-AL5obQzR.mjs +0 -71
  90. package/lib/idle-iterator-D0ZXEcUq.mjs +0 -366
  91. package/lib/ollama-6R0oXZks.mjs +0 -574
  92. package/lib/openai-codex-responses-C8bnBWOe.mjs +0 -3232
  93. package/lib/openai-completions-DNr3mUsn.mjs +0 -1430
  94. package/lib/openai-configuration-update-xMYUjaK_.mjs +0 -150
  95. package/lib/openai-reasoning-fallback-Ju-5pSR8.mjs +0 -380
  96. package/lib/openai-responses-CjpafAEr.mjs +0 -861
  97. package/lib/protobuf-BMgDYu_U.mjs +0 -717
  98. package/lib/provider-response-SqKSkkUc.mjs +0 -22
  99. package/lib/proxy-DxvCQOCA.mjs +0 -230
  100. package/lib/request-debug-BwPOqN_j.mjs +0 -183
  101. package/lib/sanitize-text-BCf5KmCf.mjs +0 -33
  102. package/lib/sse-debug-B-tkLCPW.mjs +0 -11
  103. package/lib/stream-markup-healing-CN3RsqG9.mjs +0 -267
  104. package/lib/strict-tool-validation-CBTz1dAA.mjs +0 -105
  105. package/lib/taxonomy-DSIM99rS.mjs +0 -15392
  106. package/lib/thinking-ngMwf_1Y.mjs +0 -336
  107. package/lib/type-guards-CttAANEx.mjs +0 -11
  108. package/lib/utils-eJcxzVy7.mjs +0 -11763
  109. package/lib/vision-guard-BCpXWUj3.mjs +0 -77
@@ -1,150 +0,0 @@
1
- import { installBunShim as __installBunShim } from "./bun-shim.mjs";
2
- __installBunShim();
3
- //#region node_modules/.pnpm/@oh-my-pi+pi-ai@18.1.17/node_modules/@oh-my-pi/pi-ai/src/providers/grammar.ts
4
- function compactGrammarDefinition(syntax, definition) {
5
- if (syntax !== "lark") return definition;
6
- return compactLarkGrammarDefinition(definition);
7
- }
8
- function compactLarkGrammarDefinition(definition) {
9
- const lines = [];
10
- for (const line of definition.split(/\r?\n/)) {
11
- const uncommented = stripLarkLineComment(line).trimEnd();
12
- if (uncommented.trim()) lines.push(uncommented);
13
- }
14
- return lines.join("\n");
15
- }
16
- function stripLarkLineComment(line) {
17
- let inString;
18
- let inRegex = false;
19
- let escaped = false;
20
- for (let i = 0; i < line.length; i++) {
21
- const char = line[i];
22
- const next = line[i + 1];
23
- if (escaped) {
24
- escaped = false;
25
- continue;
26
- }
27
- if (char === "\\") {
28
- escaped = true;
29
- continue;
30
- }
31
- if (inString) {
32
- if (char === inString) inString = void 0;
33
- continue;
34
- }
35
- if (inRegex) {
36
- if (char === "/") inRegex = false;
37
- continue;
38
- }
39
- if (char === "/" && next === "/") return line.slice(0, i);
40
- if (char === "\"" || char === "'") {
41
- inString = char;
42
- continue;
43
- }
44
- if (char === "/") inRegex = true;
45
- }
46
- return line;
47
- }
48
- //#endregion
49
- //#region node_modules/.pnpm/@oh-my-pi+pi-ai@18.1.17/node_modules/@oh-my-pi/pi-ai/src/providers/openai-configuration-update.ts
50
- function createOpenAIEffortControlState() {
51
- return { transitions: [] };
52
- }
53
- const MAX_EFFORT_CONTROL_STATES = 16;
54
- /**
55
- * Fetch (or create) the control state for one conversation from a provider's
56
- * bounded per-session map, refreshing its LRU slot.
57
- */
58
- function getOpenAIEffortControlState(states, key) {
59
- const existing = states.get(key);
60
- if (existing) {
61
- states.delete(key);
62
- states.set(key, existing);
63
- return existing;
64
- }
65
- const created = createOpenAIEffortControlState();
66
- states.set(key, created);
67
- if (states.size > MAX_EFFORT_CONTROL_STATES) {
68
- const oldest = states.keys().next().value;
69
- if (oldest !== void 0) states.delete(oldest);
70
- }
71
- return created;
72
- }
73
- /**
74
- * Fingerprint of the item a transition sits after. Output-only lifecycle
75
- * fields are excluded: a live response item carries `id`/`status` that the
76
- * sanitized replay of the same item drops.
77
- */
78
- function effortControlAnchor(input, index) {
79
- if (index === 0) return "";
80
- const item = input[index - 1];
81
- if (!item) return "";
82
- const { id: _id, status: _status, ...stable } = item;
83
- return String(Bun.hash(JSON.stringify(stable)));
84
- }
85
- function resetOpenAIEffortControlState(state) {
86
- state.baseEffort = void 0;
87
- state.currentEffort = void 0;
88
- state.transitions = [];
89
- }
90
- /**
91
- * Discard the baseline when the request no longer continues the conversation
92
- * it was captured for: a wire history that shrank or was rewritten under a
93
- * recorded transition (compaction, branch switch, `/clear`). The next request
94
- * re-baselines from its own effort, which is what the API asks for after
95
- * compaction anyway.
96
- */
97
- function syncOpenAIEffortControlState(state, input) {
98
- for (const transition of state.transitions) if (transition.index > input.length || transition.anchor !== effortControlAnchor(input, transition.index)) {
99
- resetOpenAIEffortControlState(state);
100
- return;
101
- }
102
- }
103
- /**
104
- * Pin the request-level effort to the session baseline and splice pending
105
- * `configuration_update` items into `input` (mutated in place).
106
- *
107
- * `input` is the freshly built transcript for this request, without any
108
- * `configuration_update` items. `requested` is the wire effort the caller
109
- * would otherwise send at the request level. Returns the effort to send at the
110
- * request level (`requested` on the first request, the baseline afterwards).
111
- */
112
- function planStableOpenAIEffort(state, input, requested) {
113
- syncOpenAIEffortControlState(state, input);
114
- if (state.baseEffort === void 0) {
115
- state.baseEffort = requested;
116
- state.currentEffort = requested;
117
- return requested;
118
- }
119
- if (state.currentEffort !== requested) {
120
- const last = input[input.length - 1];
121
- const index = last && "role" in last && last.role === "user" ? input.length - 1 : input.length;
122
- const existing = state.transitions.find((transition) => transition.index === index);
123
- if (existing) existing.effort = requested;
124
- else state.transitions.push({
125
- index,
126
- anchor: effortControlAnchor(input, index),
127
- effort: requested
128
- });
129
- let preceding = state.baseEffort;
130
- let precedingIndex = -1;
131
- for (const transition of state.transitions) if (transition.index < index && transition.index > precedingIndex) {
132
- preceding = transition.effort;
133
- precedingIndex = transition.index;
134
- }
135
- if (requested === preceding) state.transitions = state.transitions.filter((transition) => transition.index !== index);
136
- state.currentEffort = requested;
137
- }
138
- state.transitions.sort((a, b) => a.index - b.index);
139
- let offset = 0;
140
- for (const transition of state.transitions) {
141
- input.splice(transition.index + offset, 0, {
142
- type: "configuration_update",
143
- reasoning: { effort: transition.effort }
144
- });
145
- offset++;
146
- }
147
- return state.baseEffort;
148
- }
149
- //#endregion
150
- export { planStableOpenAIEffort as n, compactGrammarDefinition as r, getOpenAIEffortControlState as t };
@@ -1,380 +0,0 @@
1
- import { installBunShim as __installBunShim } from "./bun-shim.mjs";
2
- __installBunShim();
3
- import { o as readSseJson } from "./src-AELUUb5U.mjs";
4
- import { B as OpenAIHttpError, G as fetchWithRetry, W as extractHttpStatusFromError, s as ProviderResponseError } from "./error-O63pC8zg.mjs";
5
- //#region node_modules/.pnpm/@oh-my-pi+pi-ai@18.1.17/node_modules/@oh-my-pi/pi-ai/src/utils/openai-http.ts
6
- /**
7
- * JSON-POST → SSE transport for OpenAI-wire streaming endpoints (chat
8
- * completions, responses, azure responses). Replaces the `openai` SDK client:
9
- *
10
- * - Retries: `fetchWithRetry` (Retry-After/quota-hint aware; 5xx/408/429 and
11
- * transient network errors). Default 6 total attempts — parity with the
12
- * SDK's former `maxRetries: 5`.
13
- * - SSE decode: `readSseJson` (spec-compliant framing, `[DONE]`-aware).
14
- * `onSseEvent` observers now receive real wire frames instead of events
15
- * re-synthesized from decoded SDK objects.
16
- * - Errors: {@link OpenAIHttpError} exposes `status`/`headers`/`code`
17
- * structurally (ProviderHttpError contract — `extractHttpStatusFromError`,
18
- * retry-after extraction, copilot transient classification) and carries the
19
- * captured response body for the strict-tools fallback and the responses
20
- * chain-state detectors, which regex over `error.message`.
21
- */
22
- /**
23
- * Total attempts (initial + retries). Parity with the removed SDK clients'
24
- * `maxRetries: 5`, i.e. 6 requests. Callers arming a first-event watchdog
25
- * stay bounded: the watchdog aborts the request `signal`, which
26
- * `fetchWithRetry` races on every attempt and every backoff sleep, so
27
- * transient 408/429/5xx retries can never extend the caller's deadline.
28
- */
29
- const DEFAULT_MAX_ATTEMPTS = 6;
30
- /** Bound the `Error.message` allocation for proxy HTML error pages and the like. */
31
- const MAX_DETAIL_CHARS = 4096;
32
- /**
33
- * LiteLLM (and compatible proxies) shed over-concurrency requests *before* the
34
- * upstream call with an immediate HTTP 429 marked `rate_limit_type:
35
- * max_parallel_requests` — as a response header and/or a structured body field.
36
- * This is an admission failure, not an upstream rate/quota limit: the request
37
- * never reached a model. Retrying it inside the transport (honoring the proxy's
38
- * `Retry-After`, up to {@link DEFAULT_MAX_ATTEMPTS} times) duplicates — worse,
39
- * at 60s per sleep instead of 5s — the concurrency backoff and model fallback
40
- * that `TurnRecovery` already owns, stalling one turn for up to ~300s
41
- * (issue #8854). {@link isConcurrencyAdmissionRejection} lets the transport
42
- * surface it on the first attempt so session recovery runs promptly. Genuine
43
- * RPM/quota 429s carry no such marker and keep honoring `Retry-After`.
44
- */
45
- const CONCURRENCY_ADMISSION_LIMITER = "max_parallel_requests";
46
- /** Body form of the marker: `"rate_limit_type": "max_parallel_requests"` (top level or under `error`). */
47
- const CONCURRENCY_ADMISSION_BODY_PATTERN = /"rate_limit_type"\s*:\s*"max_parallel_requests"/;
48
- /** `true` for a proxy concurrency-admission 429 that must bypass transport-level retry. */
49
- function isConcurrencyAdmissionRejection(response, bodyText) {
50
- return response.headers.get("rate_limit_type")?.trim() === CONCURRENCY_ADMISSION_LIMITER || CONCURRENCY_ADMISSION_BODY_PATTERN.test(bodyText);
51
- }
52
- /**
53
- * POST a JSON body and stream back decoded SSE events.
54
- *
55
- * Throws {@link OpenAIHttpError} on a non-2xx terminal response. Aborts on
56
- * `signal` propagate from `fetchWithRetry`/`readSseJson`; callers own the
57
- * watchdog timers and abort-reason bookkeeping.
58
- */
59
- async function postOpenAIStream(init) {
60
- const response = await fetchWithRetry(init.url, {
61
- method: "POST",
62
- headers: {
63
- "Content-Type": "application/json",
64
- Accept: "text/event-stream",
65
- ...init.headers
66
- },
67
- body: JSON.stringify(init.body),
68
- signal: init.signal,
69
- fetch: init.fetch,
70
- maxAttempts: DEFAULT_MAX_ATTEMPTS,
71
- shouldRetryResponse: (response, bodyText) => !isConcurrencyAdmissionRejection(response, bodyText),
72
- timeout: false
73
- });
74
- if (!response.ok) throw await captureOpenAIHttpError(response);
75
- if (!response.body) throw new ProviderResponseError(`OpenAI stream response has no body (status ${response.status})`, { kind: "envelope" });
76
- return {
77
- events: readSseJson(response.body, init.signal, init.onSseEvent),
78
- response,
79
- requestId: response.headers.get("x-request-id")
80
- };
81
- }
82
- /** Decode a non-2xx response into an {@link OpenAIHttpError} without consuming it twice. */
83
- async function captureOpenAIHttpError(response) {
84
- let bodyText;
85
- let bodyJson;
86
- try {
87
- bodyText = await response.text();
88
- if (bodyText.trim().length > 0) try {
89
- bodyJson = JSON.parse(bodyText);
90
- } catch {}
91
- else bodyText = void 0;
92
- } catch {}
93
- const captured = {
94
- status: response.status,
95
- headers: response.headers,
96
- bodyText,
97
- bodyJson
98
- };
99
- const { detail, code } = OpenAIHttpError.parseEnvelope(bodyJson, bodyText);
100
- const message = detail ? `${response.status} ${detail.length > MAX_DETAIL_CHARS ? detail.slice(0, MAX_DETAIL_CHARS) : detail}` : `${response.status} status code (no body)`;
101
- return new OpenAIHttpError(message, captured, code);
102
- }
103
- //#endregion
104
- //#region node_modules/.pnpm/@oh-my-pi+pi-ai@18.1.17/node_modules/@oh-my-pi/pi-ai/src/providers/openai-reasoning-fallback.ts
105
- /**
106
- * Fallback marker: the server rejected the `chat_template_kwargs.reasoning_effort`
107
- * spelling itself (strict kwargs whitelists — Ninfer-style servers), not the
108
- * effort value. Apply strips the kwarg and hoists the value onto the top-level
109
- * `reasoning_effort` field when that spelling is absent.
110
- * @internal
111
- */
112
- const STRIP_TEMPLATE_KWARG_REASONING_EFFORT = Symbol("strip-template-kwarg-reasoning-effort");
113
- const ENABLED_REASONING_VALUES = [
114
- "minimal",
115
- "low",
116
- "medium",
117
- "high",
118
- "xhigh",
119
- "max"
120
- ];
121
- const KNOWN_REASONING_VALUE = {
122
- none: true,
123
- minimal: true,
124
- low: true,
125
- medium: true,
126
- high: true,
127
- xhigh: true,
128
- max: true
129
- };
130
- const REASONING_VALUE_RANK = {
131
- minimal: 0,
132
- low: 1,
133
- medium: 2,
134
- high: 3,
135
- xhigh: 4,
136
- max: 5
137
- };
138
- /** @internal */
139
- function createOpenAIReasoningEffortFallbackState() {
140
- return { reasoningEffortFallbacks: /* @__PURE__ */ new Map() };
141
- }
142
- /** @internal */
143
- function clearOpenAIReasoningEffortFallbackState(state) {
144
- state.reasoningEffortFallbacks.clear();
145
- }
146
- /** @internal */
147
- function getOpenAIReasoningEffortFallback(state, key) {
148
- return state?.reasoningEffortFallbacks.get(key);
149
- }
150
- /** @internal */
151
- function rememberOpenAIReasoningEffortFallback(state, key, fallback) {
152
- state?.reasoningEffortFallbacks.set(key, fallback);
153
- }
154
- /** @internal */
155
- function createOpenAIReasoningEffortFallbackKey(endpoint, baseUrl, wireModelId) {
156
- return `${endpoint}:${baseUrl ?? ""}:${wireModelId ?? ""}`;
157
- }
158
- function isRecord(value) {
159
- return typeof value === "object" && value !== null && !Array.isArray(value);
160
- }
161
- /** @internal */
162
- function readOpenAIReasoningEffort(params) {
163
- if (!isRecord(params)) return void 0;
164
- if (typeof params.reasoning_effort === "string") return params.reasoning_effort;
165
- const reasoning = params.reasoning;
166
- if (isRecord(reasoning) && typeof reasoning.effort === "string") return reasoning.effort;
167
- return readTemplateKwargReasoningEffort(params);
168
- }
169
- function readTemplateKwargReasoningEffort(params) {
170
- const kwargs = params.chat_template_kwargs;
171
- return isRecord(kwargs) && typeof kwargs.reasoning_effort === "string" ? kwargs.reasoning_effort : void 0;
172
- }
173
- /** Remove `chat_template_kwargs.reasoning_effort`, dropping the kwargs object when it becomes empty. */
174
- function deleteTemplateKwargReasoningEffort(kwargs, parent) {
175
- delete kwargs.reasoning_effort;
176
- for (const key in kwargs) return;
177
- delete parent.chat_template_kwargs;
178
- }
179
- function deleteReasoningEffort(reasoning, parent) {
180
- if (typeof reasoning.effort !== "string") return false;
181
- delete reasoning.effort;
182
- for (const key in reasoning) if (key !== "effort") return true;
183
- delete parent.reasoning;
184
- return true;
185
- }
186
- /** @internal */
187
- function applyOpenAIReasoningEffortFallback(params, fallback) {
188
- if (!isRecord(params)) return false;
189
- if (fallback === STRIP_TEMPLATE_KWARG_REASONING_EFFORT) {
190
- const kwargs = params.chat_template_kwargs;
191
- if (!isRecord(kwargs) || typeof kwargs.reasoning_effort !== "string") return false;
192
- const effort = kwargs.reasoning_effort;
193
- deleteTemplateKwargReasoningEffort(kwargs, params);
194
- if (typeof params.reasoning_effort !== "string") params.reasoning_effort = effort;
195
- return true;
196
- }
197
- let changed = false;
198
- if (typeof params.reasoning_effort === "string") {
199
- if (fallback === null) delete params.reasoning_effort;
200
- else params.reasoning_effort = fallback;
201
- changed = true;
202
- }
203
- const reasoning = params.reasoning;
204
- if (isRecord(reasoning) && typeof reasoning.effort === "string") {
205
- if (fallback === null) changed = deleteReasoningEffort(reasoning, params) || changed;
206
- else {
207
- reasoning.effort = fallback;
208
- changed = true;
209
- }
210
- }
211
- const kwargs = params.chat_template_kwargs;
212
- if (isRecord(kwargs) && typeof kwargs.reasoning_effort === "string") {
213
- if (fallback === null) deleteTemplateKwargReasoningEffort(kwargs, params);
214
- else kwargs.reasoning_effort = fallback;
215
- changed = true;
216
- }
217
- return changed;
218
- }
219
- function capturedStringField(captured, field) {
220
- const body = isRecord(captured?.bodyJson) ? captured.bodyJson : void 0;
221
- const error = isRecord(body?.error) ? body.error : void 0;
222
- if (typeof error?.[field] === "string") return error[field];
223
- return typeof body?.[field] === "string" ? body[field] : void 0;
224
- }
225
- function collectMessageParts(error, captured) {
226
- return [
227
- error instanceof Error ? error.message : void 0,
228
- capturedStringField(captured, "message"),
229
- capturedStringField(captured, "param"),
230
- capturedStringField(captured, "code"),
231
- capturedStringField(captured, "type"),
232
- captured?.bodyText
233
- ].filter((value) => typeof value === "string" && value.trim().length > 0).join("\n");
234
- }
235
- /**
236
- * Text that identifies a 400 as being about the reasoning-effort field.
237
- * OpenAI-compatible gateways (cliproxy, …) never name the field — they reject
238
- * the value alone with `level "none" not supported, valid levels: low, …` — so
239
- * the allowed-level phrasing counts as a mention too. GitHub Copilot phrases
240
- * the same rejection with `Supported values are: …`, so value lists count too.
241
- */
242
- const REASONING_EFFORT_FIELD_PATTERN = /reasoning[_. ]effort|reasoning value|(?:valid|supported|allowed) (?:levels?|values?)/i;
243
- function mentionsReasoningEffort(error, captured) {
244
- const param = capturedStringField(captured, "param");
245
- const code = capturedStringField(captured, "code");
246
- const type = capturedStringField(captured, "type");
247
- const message = collectMessageParts(error, captured);
248
- return REASONING_EFFORT_FIELD_PATTERN.test(param ?? "") || REASONING_EFFORT_FIELD_PATTERN.test(code ?? "") || REASONING_EFFORT_FIELD_PATTERN.test(type ?? "") || REASONING_EFFORT_FIELD_PATTERN.test(message);
249
- }
250
- const EFFORT_FIELD_PATTERN = /reasoning[_. ]effort|reasoning value/i;
251
- const ALLOWED_LEVELS_PATTERN = /(?:valid|supported|allowed) levels?/i;
252
- /** Fielded rejection verdicts in any word order: verdict-first, field-first, or bare mention plus verdict. */
253
- function messageCarriesEffortVerdict(message) {
254
- return /invalid[^\n]*(?:reasoning[_. ]effort|reasoning value)/i.test(message) || /(?:reasoning[_. ]effort|reasoning value)[^\n]*(?:invalid|unsupported|not supported|not permitted|must be|expected|unknown|unexpected|unrecognized)/i.test(message) || /(?:unsupported|not supported|not permitted|unknown|unexpected|unrecognized|extra)[^\n]*(?:reasoning[_. ]effort|reasoning value)/i.test(message);
255
- }
256
- function parseEffortRejectionSignal(message, captured, currentEffort) {
257
- const namesFieldInMessage = EFFORT_FIELD_PATTERN.test(message);
258
- const param = capturedStringField(captured, "param") ?? "";
259
- const quoted = `["'\`]${escapeRegExp(currentEffort)}["'\`]`;
260
- return {
261
- field: namesFieldInMessage || EFFORT_FIELD_PATTERN.test(param) ? "reasoning-effort" : param.trim() !== "" ? "other" : "unknown",
262
- namesFieldInMessage,
263
- messageVerdict: messageCarriesEffortVerdict(message),
264
- listsLevels: ALLOWED_LEVELS_PATTERN.test(message),
265
- rejectedMatches: new RegExp(`(?:invalid|unsupported|not supported)[^\\n]*${quoted}`, "i").test(message) || new RegExp(`${quoted}[^\\n]*(?:invalid|unsupported|not supported)`, "i").test(message)
266
- };
267
- }
268
- function isInvalidReasoningEffortError(error, captured, currentEffort) {
269
- const status = extractHttpStatusFromError(error) ?? captured?.status;
270
- if (status !== 400 && status !== 422) return false;
271
- if (!mentionsReasoningEffort(error, captured)) return false;
272
- const message = collectMessageParts(error, captured);
273
- if (/reasoning[_ ]content/i.test(message) && !REASONING_EFFORT_FIELD_PATTERN.test(message)) return false;
274
- const signal = parseEffortRejectionSignal(message, captured, currentEffort);
275
- if (signal.field === "other" && !signal.namesFieldInMessage) return false;
276
- if (signal.messageVerdict) return true;
277
- if (currentEffort.toLowerCase() !== "none" && !signal.namesFieldInMessage && !signal.listsLevels) return false;
278
- return signal.rejectedMatches;
279
- }
280
- function escapeRegExp(value) {
281
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
282
- }
283
- function parseKnownReasoningValues(text) {
284
- const values = /* @__PURE__ */ new Set();
285
- const quotedPattern = /["'`](none|minimal|low|medium|high|xhigh|max)["'`]/gi;
286
- let quotedMatch = quotedPattern.exec(text);
287
- while (quotedMatch !== null) {
288
- values.add(quotedMatch[1].toLowerCase());
289
- quotedMatch = quotedPattern.exec(text);
290
- }
291
- const allowedMatch = /(?:must be|one of|allowed values?|supported values?(?: are)?|expected|(?:valid|supported|allowed) levels?(?: are)?)[^.\n]+/i.exec(text);
292
- if (allowedMatch) {
293
- const allowedText = allowedMatch[0];
294
- const barePattern = /\b(none|minimal|low|medium|high|xhigh|max)\b/gi;
295
- let bareMatch = barePattern.exec(allowedText);
296
- while (bareMatch !== null) {
297
- values.add(bareMatch[1].toLowerCase());
298
- bareMatch = barePattern.exec(allowedText);
299
- }
300
- }
301
- return values;
302
- }
303
- function parseAllowedReasoningValues(message, currentEffort) {
304
- const values = parseKnownReasoningValues(message);
305
- const hasAllowedCue = /must be|one of|allowed values?|supported values?|expected|(?:valid|supported|allowed) levels?/i.test(message);
306
- values.delete(currentEffort.toLowerCase());
307
- if (!hasAllowedCue && values.size === 0) return void 0;
308
- return values;
309
- }
310
- function orderedEnabledAllowedValues(allowed) {
311
- return ENABLED_REASONING_VALUES.filter((value) => allowed.has(value));
312
- }
313
- function lowestEnabledAllowedValue(allowed) {
314
- for (const value of ENABLED_REASONING_VALUES) if (allowed.has(value)) return value;
315
- }
316
- function nearestEnabledReasoningFallback(currentEffort, allowed) {
317
- const current = currentEffort.toLowerCase();
318
- const allowedEnabled = orderedEnabledAllowedValues(allowed);
319
- if (allowedEnabled.length === 0) return void 0;
320
- if (current === "minimal" && allowedEnabled.includes("low")) return "low";
321
- if (current === "xhigh" && allowedEnabled.includes("max")) return "max";
322
- if (current === "xhigh" && allowedEnabled.includes("high")) return "high";
323
- if (current === "max" && allowedEnabled.includes("xhigh")) return "xhigh";
324
- const currentRank = REASONING_VALUE_RANK[current];
325
- if (currentRank === void 0) return void 0;
326
- let best;
327
- let bestDistance = Number.POSITIVE_INFINITY;
328
- let bestRank = Number.NEGATIVE_INFINITY;
329
- for (const candidate of allowedEnabled) {
330
- if (candidate === current) continue;
331
- const candidateRank = REASONING_VALUE_RANK[candidate];
332
- if (candidateRank === void 0) continue;
333
- const distance = Math.abs(candidateRank - currentRank);
334
- if (distance < bestDistance || distance === bestDistance && candidateRank > bestRank) {
335
- best = candidate;
336
- bestDistance = distance;
337
- bestRank = candidateRank;
338
- }
339
- }
340
- return best;
341
- }
342
- /**
343
- * Text that identifies a rejection of the kwargs spelling itself: the server
344
- * names `chat_template_kwargs` together with `reasoning_effort` (Ninfer-style
345
- * strict kwargs whitelists: `chat_template_kwargs.reasoning_effort is not
346
- * supported`).
347
- */
348
- const TEMPLATE_KWARG_EFFORT_PATTERN = /chat_template_kwargs[^\n]{0,120}reasoning[_. ]effort|reasoning[_. ]effort[^\n]{0,120}chat_template_kwargs/i;
349
- const FIELD_REJECTION_PATTERN = /invalid|unsupported|not supported|not permitted|unknown|unexpected|unrecognized|rejected|extra input/i;
350
- function resolveStripTemplateKwargFallback(error, captured, params) {
351
- if (!isRecord(params)) return void 0;
352
- const effort = readTemplateKwargReasoningEffort(params);
353
- if (effort === void 0) return void 0;
354
- const status = extractHttpStatusFromError(error) ?? captured?.status;
355
- if (status !== 400 && status !== 422) return void 0;
356
- const message = collectMessageParts(error, captured);
357
- if (!TEMPLATE_KWARG_EFFORT_PATTERN.test(message) || !FIELD_REJECTION_PATTERN.test(message)) return void 0;
358
- if (parseAllowedReasoningValues(message, effort) !== void 0) return void 0;
359
- return STRIP_TEMPLATE_KWARG_REASONING_EFFORT;
360
- }
361
- /** @internal */
362
- function resolveOpenAIReasoningEffortFallback(error, captured, params, options) {
363
- const strip = resolveStripTemplateKwargFallback(error, captured, params);
364
- if (strip !== void 0) return strip;
365
- const currentEffort = readOpenAIReasoningEffort(params);
366
- if (!currentEffort || !KNOWN_REASONING_VALUE[currentEffort.toLowerCase()]) return void 0;
367
- if (!isInvalidReasoningEffortError(error, captured, currentEffort)) return void 0;
368
- const allowed = parseAllowedReasoningValues(collectMessageParts(error, captured), currentEffort);
369
- const normalizedCurrent = currentEffort.toLowerCase();
370
- if (allowed === void 0) return null;
371
- if (options?.explicitDisable) {
372
- if (normalizedCurrent !== "none" && allowed.has("none")) return "none";
373
- const fallback = lowestEnabledAllowedValue(allowed);
374
- return fallback && fallback !== normalizedCurrent ? fallback : null;
375
- }
376
- if (normalizedCurrent === "none") return null;
377
- return nearestEnabledReasoningFallback(normalizedCurrent, allowed) ?? null;
378
- }
379
- //#endregion
380
- export { getOpenAIReasoningEffortFallback as a, postOpenAIStream as c, createOpenAIReasoningEffortFallbackState as i, clearOpenAIReasoningEffortFallbackState as n, rememberOpenAIReasoningEffortFallback as o, createOpenAIReasoningEffortFallbackKey as r, resolveOpenAIReasoningEffortFallback as s, applyOpenAIReasoningEffortFallback as t };