@xiaoso/dsh-tool-plus 0.1.6 → 0.1.7-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.
- package/THIRD_PARTY_NOTICES.md +9 -3
- package/lib/{abort-Cwwm4Err.mjs → abort-Caqff3M6.mjs} +2 -2
- package/lib/alibaba-coding-plan-DTupMiAi.mjs +73 -0
- package/lib/alibaba-token-plan-CHGyWOfX.mjs +46 -0
- package/lib/alibaba-token-plan-Dj3OZhEE.mjs +82 -0
- package/lib/{amazon-bedrock-TVMpUTRG.mjs → amazon-bedrock-DbFSYXfJ.mjs} +117 -38
- package/lib/{anthropic-BL6LFDQS.mjs → anthropic-CTJ3IQVa.mjs} +675 -166
- package/lib/anthropic-CXfWlp-x.mjs +105 -0
- package/lib/{aws-credentials-B20dliS7.mjs → anthropic-wire-CKuhDwZ1.mjs} +74 -14
- package/lib/{api-key-login-CIDnXeYd.mjs → api-key-validation-CGCJFbFr.mjs} +27 -68
- package/lib/{azure-openai-responses-BkhsLmN3.mjs → azure-openai-responses-ChFbWaGj.mjs} +27 -16
- package/lib/{browser-render-CmgvSNte.mjs → browser-render-9o0Rknop.mjs} +4 -4
- package/lib/bun-shim.mjs +71 -2
- package/lib/{bundled-references-ChZSPDFw.mjs → bundled-references-DY3EJxZV.mjs} +6 -5
- package/lib/cline-pass-Bwg3esu9.mjs +44 -0
- package/lib/cloudflare-ai-gateway-BupNXyKK.mjs +35 -0
- package/lib/cloudflare-ai-gateway-EWo0VkP5.mjs +44 -0
- package/lib/collapse-DOR8sOGf.mjs +2304 -0
- package/lib/coreweave-C82HrLpb.mjs +31 -0
- package/lib/coreweave-Ct8cF-da.mjs +14 -0
- package/lib/{cursor-B6HcmplF.mjs → cursor-B95LzVWV.mjs} +11 -3
- package/lib/{cursor-CRpLpaZ3.mjs → cursor-DJV_dcgB.mjs} +887 -1784
- package/lib/{cursor-B8m6SqAH.mjs → cursor-LKGjucn2.mjs} +48 -38
- package/lib/cursor-proto-B8Wj8bv9.mjs +10513 -0
- package/lib/{deterministic-id-D-yIV_eI.mjs → deterministic-id-CUEIMSqR.mjs} +1 -1
- package/lib/devin-BMTdx_hx.mjs +316 -0
- package/lib/{devin-DUAfvBsW.mjs → devin-DSp0Rw_E.mjs} +172 -86
- package/lib/devin-ExGIghmx.mjs +69 -0
- package/lib/devin-proto-Br8fdyNl.mjs +2888 -0
- package/lib/{dom-CawWi8fa.mjs → dom-DG3sPESc.mjs} +8 -8
- package/lib/effort-BdtQMN-_.mjs +23 -0
- package/lib/{error-C-f_Wnw4.mjs → error-CORgGg5a.mjs} +275 -154
- package/lib/{event-stream-Dh2guZxS.mjs → event-stream-ulcDenZD.mjs} +20 -4
- package/lib/{gemini-headers-DKUShltF.mjs → gemini-headers-Co9cVvex.mjs} +2 -2
- package/lib/{github-copilot-suDymKrx.mjs → github-copilot-Dstq1D3s.mjs} +69 -29
- package/lib/github-copilot-headers-DOh1gt_w.mjs +312 -0
- package/lib/gitlab-duo-DSCMrU0m.mjs +11 -0
- package/lib/google-CtsKkOQK.mjs +38 -0
- package/lib/google-antigravity-z-5KsEci.mjs +252 -0
- package/lib/{google-auth-DYJLM792.mjs → google-auth-ieLBaneO.mjs} +4 -4
- package/lib/{google-gemini-cli-8BT513Ul.mjs → google-gemini-cli-C6NE5mWz.mjs} +28 -54
- package/lib/{google-gemini-cli-D6cSmfvB.mjs → google-gemini-cli-CAIPSl7e.mjs} +23 -29
- package/lib/google-oauth-shared-DhMllAkt.mjs +53 -0
- package/lib/{google-shared-CVbHK5vZ.mjs → google-shared-B0aNCYEH.mjs} +140 -44
- package/lib/{google-validation-Cgbn3tWJ.mjs → google-validation-BEkNs-Bx.mjs} +1 -1
- package/lib/{google-vertex-Bui-ypAe.mjs → google-vertex-Bbd1tYNc.mjs} +8 -8
- package/lib/hosts-00rjRzUD.mjs +203 -0
- package/lib/id-AL5obQzR.mjs +71 -0
- package/lib/{idle-iterator-CYAxUkSD.mjs → idle-iterator-DlUkEfzW.mjs} +3 -3
- package/lib/index.mjs +587 -5266
- package/lib/kilo-ChJL54wq.mjs +81 -0
- package/lib/kimi-C2c_Zq8A.mjs +67 -0
- package/lib/{launch-BmgEUycu.mjs → launch-DKDH71En.mjs} +1 -1
- package/lib/markit-CmRfm4E2.mjs +9885 -0
- package/lib/models-DnXMYGcJ.mjs +381604 -0
- package/lib/muse-code-Di1VZmB1.mjs +143 -0
- package/lib/{ollama-Df9ce-Cp.mjs → ollama-B8ic3sEp.mjs} +15 -30
- package/lib/{openai-codex-CAVI3Me-.mjs → openai-codex-DuJNC99x.mjs} +29 -99
- package/lib/{openai-codex-responses-BcnOotRB.mjs → openai-codex-responses-BL29nh9K.mjs} +204 -116
- package/lib/{openai-completions-Bq4WT47M.mjs → openai-completions-BK2f2dBv.mjs} +152 -82
- package/lib/openai-configuration-update-xMYUjaK_.mjs +150 -0
- package/lib/{openai-reasoning-fallback-DXsfiSXO.mjs → openai-reasoning-fallback-BdB3RCbj.mjs} +106 -12
- package/lib/{openai-responses-Mq_-PjvE.mjs → openai-responses-CGQPlIIy.mjs} +76 -82
- package/lib/{perplexity-XgLF73E7.mjs → perplexity-TBjz3VMB.mjs} +52 -9
- package/lib/{pkce-BlQikGPu.mjs → pkce-BYjmugmw.mjs} +1 -1
- package/lib/protobuf-aab1UGVn.mjs +717 -0
- package/lib/{provider-response-C6vcbQyO.mjs → provider-response-SqKSkkUc.mjs} +1 -1
- package/lib/{proxy-D9lm7ONA.mjs → proxy-5nWqRL1f.mjs} +45 -5
- package/lib/{readability-Cpm-ocau.mjs → readability-uGhqb4GC.mjs} +2 -2
- package/lib/reference-CtvM4zLU.mjs +114 -0
- package/lib/{request-debug-HJMoJncL.mjs → request-debug-NQN0BjHH.mjs} +1 -1
- package/lib/{sanitize-text-CfcXzw5X.mjs → sanitize-text-BCf5KmCf.mjs} +1 -1
- package/lib/{scrapers-Cg5w77td.mjs → scrapers-D8oWspgW.mjs} +12 -12
- package/lib/{src-BcD0_rQR.mjs → src-BwW51vA5.mjs} +979 -388
- package/lib/{sse-debug-CYdjOC96.mjs → sse-debug-B-tkLCPW.mjs} +1 -1
- package/lib/{stream-Bjq8wjfr.mjs → stream-B_7qN-bA.mjs} +3802 -2623
- package/lib/stream-markup-healing-DKT1lnkW.mjs +267 -0
- package/lib/{strict-tool-validation-imVLUcbI.mjs → strict-tool-validation-CBTz1dAA.mjs} +2 -2
- package/lib/taxonomy-DSIM99rS.mjs +15392 -0
- package/lib/{stream-markup-healing-DZ6bVDxH.mjs → thinking-CiLa2LFB.mjs} +31 -186
- package/lib/{turndown-DN7ByzEI.mjs → turndown-DrX1M4WG.mjs} +4 -4
- package/lib/{type-guards-B9VVjRDK.mjs → type-guards-CttAANEx.mjs} +1 -1
- package/lib/{types-DX_bvuus.mjs → types-PVueGi9S.mjs} +2 -2
- package/lib/{utils-C-dSORPa.mjs → utils-CCfhUQen.mjs} +2364 -2676
- package/lib/{utils-Cp2Mxf_U.mjs → utils-CUPhpw9A.mjs} +413 -134
- package/lib/{utils-CQHPEQ3W.mjs → utils-DeWqNWV8.mjs} +2 -2
- package/lib/{vision-guard-mBmtAHx0.mjs → vision-guard-_XwsL1DF.mjs} +14 -29
- package/lib/xai-oauth-CXhnz0gO.mjs +210 -0
- package/lib/{xiaomi-7mE345KX.mjs → xiaomi-psoUItal.mjs} +8 -37
- package/lib/{zai-CeNpMV3W.mjs → zai-ApJ8HBgT.mjs} +8 -71
- package/lib/{zip-BK7UHCwX.mjs → zip-Kd602XNe.mjs} +1 -1
- package/package.json +11 -11
- package/presets/package.json +1 -1
- package/presets/tool-plus-ptc/agent.cordis.yml +1 -1
- package/presets/tool-plus-standard/agent.cordis.yml +1 -1
- package/lib/agent_pb-Rizyt9Zg.mjs +0 -805
- package/lib/anthropic-CDmj476p.mjs +0 -262
- package/lib/api_server_pb-CDZgLMta.mjs +0 -252
- package/lib/callback-server-CFJK-jvK.mjs +0 -398
- package/lib/codex-P1dGpX7G.mjs +0 -54
- package/lib/device-code-CuXTWYwY.mjs +0 -51
- package/lib/devin-BcQwht1W.mjs +0 -114
- package/lib/devin-BvMfGevz.mjs +0 -95
- package/lib/github-copilot-B3kQl0g0.mjs +0 -104
- package/lib/gitlab-duo-BriUTP8k.mjs +0 -155
- package/lib/gitlab-duo-workflow-wK5Ljzmc.mjs +0 -91
- package/lib/google-CE5tFDod.mjs +0 -30
- package/lib/google-antigravity-C1jgNljz.mjs +0 -198
- package/lib/google-oauth-shared-BLVTvokk.mjs +0 -147
- package/lib/grammar-D-NqNUxQ.mjs +0 -49
- package/lib/identity-HNO1Oe9B.mjs +0 -219
- package/lib/kimi-DgcUpPtK.mjs +0 -236
- package/lib/markit-DtGoRE6M.mjs +0 -1417
- package/lib/minimax-code-Y3h5li9N.mjs +0 -53
- package/lib/models-DRA2c_8U.mjs +0 -104660
- package/lib/opencode-BsVw9rCD.mjs +0 -38
- package/lib/to-binary-B1BEBIPC.mjs +0 -6002
- package/lib/wafer-BlhWLweO.mjs +0 -17
- package/lib/xai-oauth-5pORHUrg.mjs +0 -446
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
+
__installBunShim();
|
|
3
|
+
import { r as __exportAll } from "./fs-promises-shim-Bx0fpxuk.mjs";
|
|
4
|
+
import { f as OAuthError, t as ConfigurationError } from "./error-CORgGg5a.mjs";
|
|
5
|
+
import { type } from "@oh-my-pi/omptype";
|
|
6
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@18.1.17/node_modules/@oh-my-pi/pi-ai/src/registry/oauth/muse-code.ts
|
|
7
|
+
var muse_code_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
attachMuseCodeApiKey: () => attachMuseCodeApiKey,
|
|
9
|
+
parseMuseCodeCredential: () => parseMuseCodeCredential,
|
|
10
|
+
requestMuseCodeKey: () => requestMuseCodeKey
|
|
11
|
+
});
|
|
12
|
+
const PROVIDER = "muse-code";
|
|
13
|
+
const MUSE_KEY_URL = "https://api.meta.ai/muse-code/key";
|
|
14
|
+
const API_VERSION = "1.0.0";
|
|
15
|
+
const REQUEST_TIMEOUT_MS = 2e4;
|
|
16
|
+
const subscriptionWindowSchema = type({
|
|
17
|
+
"used_percent?": "number",
|
|
18
|
+
"resets_at?": "string | number",
|
|
19
|
+
"window_duration_mins?": "number"
|
|
20
|
+
});
|
|
21
|
+
const subscriptionUsageSchema = type({
|
|
22
|
+
"window?": subscriptionWindowSchema.or("null"),
|
|
23
|
+
"weekly?": subscriptionWindowSchema.or("null")
|
|
24
|
+
});
|
|
25
|
+
const museCodeKeyResponseSchema = type({
|
|
26
|
+
"api_key?": "string",
|
|
27
|
+
"require_payment_action_url?": "string",
|
|
28
|
+
"require_payment?": "boolean",
|
|
29
|
+
"action_url?": "string | null",
|
|
30
|
+
"user_email?": "string",
|
|
31
|
+
"user_id?": "string",
|
|
32
|
+
"is_subs_active?": "boolean",
|
|
33
|
+
"subs_tier_id?": "string",
|
|
34
|
+
"subs_tier_name?": "string",
|
|
35
|
+
"subs_usage?": subscriptionUsageSchema.or("null")
|
|
36
|
+
});
|
|
37
|
+
const museCodeCredentialSchema = type({
|
|
38
|
+
oauthAccessToken: "string",
|
|
39
|
+
apiKey: "string"
|
|
40
|
+
});
|
|
41
|
+
function requestSignal(signal) {
|
|
42
|
+
const timeout = AbortSignal.timeout(REQUEST_TIMEOUT_MS);
|
|
43
|
+
return signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
44
|
+
}
|
|
45
|
+
function parseMuseCodeCredential(value) {
|
|
46
|
+
let payload;
|
|
47
|
+
try {
|
|
48
|
+
payload = JSON.parse(value);
|
|
49
|
+
} catch (cause) {
|
|
50
|
+
throw new ConfigurationError("Muse Code credential is invalid; sign in again", { cause });
|
|
51
|
+
}
|
|
52
|
+
const parsed = museCodeCredentialSchema(payload);
|
|
53
|
+
if (parsed instanceof type.errors || !parsed.oauthAccessToken.trim() || !parsed.apiKey.trim()) throw new ConfigurationError("Muse Code credential is invalid; sign in again");
|
|
54
|
+
return parsed;
|
|
55
|
+
}
|
|
56
|
+
function encodeMuseCodeCredential(oauthAccessToken, apiKey) {
|
|
57
|
+
return JSON.stringify({
|
|
58
|
+
oauthAccessToken,
|
|
59
|
+
apiKey
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async function requestMuseCodeKey(accessToken, options = {}) {
|
|
63
|
+
const response = await (options.fetch ?? fetch)(MUSE_KEY_URL, {
|
|
64
|
+
method: "POST",
|
|
65
|
+
headers: {
|
|
66
|
+
Accept: "application/json",
|
|
67
|
+
Authorization: `Bearer ${accessToken}`,
|
|
68
|
+
"Content-Type": "application/json",
|
|
69
|
+
"x-api-version": API_VERSION
|
|
70
|
+
},
|
|
71
|
+
body: JSON.stringify(options.onboard ? { onboard: true } : {}),
|
|
72
|
+
redirect: "error",
|
|
73
|
+
signal: requestSignal(options.signal)
|
|
74
|
+
});
|
|
75
|
+
const text = await response.text();
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
const excerpt = text.trim() ? ` ${text.slice(0, 500).trim()}` : "";
|
|
78
|
+
throw new OAuthError(`Muse Code key exchange failed: ${response.status}${excerpt}`, {
|
|
79
|
+
kind: "token-exchange",
|
|
80
|
+
provider: PROVIDER,
|
|
81
|
+
status: response.status
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
let payload;
|
|
85
|
+
try {
|
|
86
|
+
payload = JSON.parse(text);
|
|
87
|
+
} catch (cause) {
|
|
88
|
+
throw new OAuthError("Muse Code key exchange returned invalid JSON", {
|
|
89
|
+
kind: "validation",
|
|
90
|
+
provider: PROVIDER,
|
|
91
|
+
status: response.status,
|
|
92
|
+
cause
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
const parsed = museCodeKeyResponseSchema(payload);
|
|
96
|
+
if (parsed instanceof type.errors) throw new OAuthError(`Invalid Muse Code key response: ${parsed.summary}`, {
|
|
97
|
+
kind: "validation",
|
|
98
|
+
provider: PROVIDER
|
|
99
|
+
});
|
|
100
|
+
return parsed;
|
|
101
|
+
}
|
|
102
|
+
/** Exchange Meta account access for the Model API key authorized by a Muse subscription. */
|
|
103
|
+
const attachMuseCodeApiKey = async (credentials, context) => {
|
|
104
|
+
try {
|
|
105
|
+
if (parseMuseCodeCredential(credentials.access).apiKey.trim()) return credentials;
|
|
106
|
+
} catch {}
|
|
107
|
+
const payload = await requestMuseCodeKey(credentials.access, {
|
|
108
|
+
fetch: context.fetch,
|
|
109
|
+
signal: context.signal,
|
|
110
|
+
onboard: true
|
|
111
|
+
});
|
|
112
|
+
if (payload.is_subs_active === false) throw new OAuthError("invalid_grant: Muse Code subscription is inactive", {
|
|
113
|
+
kind: "token-exchange",
|
|
114
|
+
provider: PROVIDER,
|
|
115
|
+
status: 403
|
|
116
|
+
});
|
|
117
|
+
const apiKey = payload.api_key?.trim() || "";
|
|
118
|
+
if (!apiKey) {
|
|
119
|
+
const actionUrl = payload.action_url?.trim() || payload.require_payment_action_url?.trim();
|
|
120
|
+
if (payload.require_payment === true || actionUrl) throw new OAuthError(actionUrl ? `Muse Code subscription is required: ${actionUrl}` : "Muse Code subscription is required", {
|
|
121
|
+
kind: "entitlement",
|
|
122
|
+
provider: PROVIDER
|
|
123
|
+
});
|
|
124
|
+
throw new OAuthError("Muse Code key response is missing api_key", {
|
|
125
|
+
kind: "validation",
|
|
126
|
+
provider: PROVIDER
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
const email = payload.user_email?.trim().toLowerCase();
|
|
130
|
+
const accountId = payload.user_id?.trim() || email;
|
|
131
|
+
if (!accountId) throw new OAuthError("Muse Code key response is missing a stable account identity", {
|
|
132
|
+
kind: "validation",
|
|
133
|
+
provider: PROVIDER
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
...credentials,
|
|
137
|
+
access: encodeMuseCodeCredential(credentials.access, apiKey),
|
|
138
|
+
accountId,
|
|
139
|
+
email
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
//#endregion
|
|
143
|
+
export { parseMuseCodeCredential as n, requestMuseCodeKey as r, muse_code_exports as t };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
2
|
__installBunShim();
|
|
3
3
|
import { r as __exportAll } from "./fs-promises-shim-Bx0fpxuk.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import { G as fetchWithRetry,
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { i as partitionVisionContent, r as joinTextWithImagePlaceholder } from "./vision-guard-
|
|
9
|
-
import { t as AssistantMessageEventStream } from "./event-stream-
|
|
10
|
-
import { n as getOpenAIStreamFirstEventTimeoutMs, r as getOpenAIStreamIdleTimeoutMs, t as armPreResponseTimeout } from "./idle-iterator-
|
|
11
|
-
import { n as getStreamMarkupHealingPattern, t as StreamMarkupHealing } from "./stream-markup-healing-
|
|
12
|
-
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@
|
|
4
|
+
import { _ as parseStreamingJson, i as readJsonl } from "./src-BwW51vA5.mjs";
|
|
5
|
+
import { G as fetchWithRetry, c as finalize, h as MissingApiKeyError, y as LLAMA_CPP_TOOL_CALL_PARSE_PATTERN, z as OllamaApiError } from "./error-CORgGg5a.mjs";
|
|
6
|
+
import { A as toolWireSchema, R as sanitizeSchemaForOllama, g as clearStreamingPartialJson, h as transformMessages, o as normalizeSystemPrompts, w as kStreamingPartialJson } from "./utils-CUPhpw9A.mjs";
|
|
7
|
+
import { At as withReplaySafeStreamRetry, n as getEnvApiKey } from "./stream-B_7qN-bA.mjs";
|
|
8
|
+
import { i as partitionVisionContent, r as joinTextWithImagePlaceholder } from "./vision-guard-_XwsL1DF.mjs";
|
|
9
|
+
import { t as AssistantMessageEventStream } from "./event-stream-ulcDenZD.mjs";
|
|
10
|
+
import { n as getOpenAIStreamFirstEventTimeoutMs, r as getOpenAIStreamIdleTimeoutMs, t as armPreResponseTimeout } from "./idle-iterator-DlUkEfzW.mjs";
|
|
11
|
+
import { n as getStreamMarkupHealingPattern, t as StreamMarkupHealing } from "./stream-markup-healing-DKT1lnkW.mjs";
|
|
12
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@18.1.17/node_modules/@oh-my-pi/pi-ai/src/providers/ollama.ts
|
|
13
13
|
var ollama_exports = /* @__PURE__ */ __exportAll({ streamOllama: () => streamOllama });
|
|
14
14
|
function normalizeBaseUrl(baseUrl) {
|
|
15
15
|
const value = baseUrl?.trim();
|
|
@@ -139,22 +139,6 @@ function convertTools(tools) {
|
|
|
139
139
|
}
|
|
140
140
|
}));
|
|
141
141
|
}
|
|
142
|
-
/**
|
|
143
|
-
* Ollama Cloud rejects `num_predict` above this value with HTTP 400
|
|
144
|
-
* (`max_tokens (...) exceeds model's maximum output tokens (65536)`).
|
|
145
|
-
* The cap currently applies uniformly to cloud-served models; the cloud-side
|
|
146
|
-
* limit was confirmed empirically against `deepseek-v4-pro`/`-flash` and is
|
|
147
|
-
* the same cap surfaced for every other Ollama Cloud model we've probed.
|
|
148
|
-
*
|
|
149
|
-
* Acts as a wire-level safety net so stale `models.db` rows (or custom
|
|
150
|
-
* `modelOverrides` re-enabling `num_predict`) cannot 400 the request — even
|
|
151
|
-
* when `model.omitMaxOutputTokens` was never applied. See #3392.
|
|
152
|
-
*/
|
|
153
|
-
const OLLAMA_CLOUD_NUM_PREDICT_CAP = 65536;
|
|
154
|
-
function resolveNumPredict(model, requested) {
|
|
155
|
-
if (model.provider === "ollama-cloud") return Math.min(requested, OLLAMA_CLOUD_NUM_PREDICT_CAP);
|
|
156
|
-
return requested;
|
|
157
|
-
}
|
|
158
142
|
function createChatBody(model, context, options) {
|
|
159
143
|
const think = mapReasoning(model, options?.reasoning, options?.disableReasoning);
|
|
160
144
|
const toolChoice = mapToolChoice(options?.toolChoice);
|
|
@@ -162,7 +146,7 @@ function createChatBody(model, context, options) {
|
|
|
162
146
|
const runtimeOptions = {};
|
|
163
147
|
let hasRuntimeOptions = false;
|
|
164
148
|
if (options?.maxTokens !== void 0 && !model.omitMaxOutputTokens) {
|
|
165
|
-
runtimeOptions.num_predict =
|
|
149
|
+
runtimeOptions.num_predict = model.provider === "ollama-cloud" ? Math.min(options.maxTokens, 65536) : options.maxTokens;
|
|
166
150
|
hasRuntimeOptions = true;
|
|
167
151
|
}
|
|
168
152
|
if (options?.temperature !== void 0) {
|
|
@@ -292,7 +276,7 @@ const streamOllamaOnce = (model, context, options = {}) => {
|
|
|
292
276
|
let activeThinkingIndex;
|
|
293
277
|
let activeTextIndex;
|
|
294
278
|
const activeToolIndices = /* @__PURE__ */ new Set();
|
|
295
|
-
const streamMarkupHealingPattern = getStreamMarkupHealingPattern(model
|
|
279
|
+
const streamMarkupHealingPattern = getStreamMarkupHealingPattern(model);
|
|
296
280
|
const streamMarkupHealing = streamMarkupHealingPattern ? new StreamMarkupHealing({ pattern: streamMarkupHealingPattern }) : void 0;
|
|
297
281
|
let healedToolCallEmitted = false;
|
|
298
282
|
let suppressHealedThinking = false;
|
|
@@ -522,9 +506,10 @@ const streamOllamaOnce = (model, context, options = {}) => {
|
|
|
522
506
|
activeToolIndices.clear();
|
|
523
507
|
output.stopReason = mapDoneReason(chunk.done_reason, output);
|
|
524
508
|
if (healedToolCallEmitted && output.stopReason === "stop") output.stopReason = "toolUse";
|
|
525
|
-
output.usage.
|
|
509
|
+
output.usage.cacheRead = chunk.prompt_eval_cached_count ?? 0;
|
|
510
|
+
output.usage.input = (chunk.prompt_eval_count ?? 0) - output.usage.cacheRead;
|
|
526
511
|
output.usage.output = chunk.eval_count ?? 0;
|
|
527
|
-
output.usage.totalTokens = output.usage.input + output.usage.output;
|
|
512
|
+
output.usage.totalTokens = output.usage.input + output.usage.output + output.usage.cacheRead;
|
|
528
513
|
}
|
|
529
514
|
}
|
|
530
515
|
if (streamMarkupHealing) {
|
|
@@ -584,6 +569,6 @@ const streamOllamaOnce = (model, context, options = {}) => {
|
|
|
584
569
|
return stream;
|
|
585
570
|
};
|
|
586
571
|
/** Retry EOS-only Ollama completions before the agent loop sees an empty stop. */
|
|
587
|
-
const streamOllama = (model, context, options) =>
|
|
572
|
+
const streamOllama = (model, context, options) => withReplaySafeStreamRetry(model, context, options, streamOllamaOnce, { retryEmptyCompletion: true });
|
|
588
573
|
//#endregion
|
|
589
574
|
export { ollama_exports as t };
|
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
2
|
__installBunShim();
|
|
3
|
-
import {
|
|
4
|
-
import "./utils-
|
|
5
|
-
import { n as isRecord } from "./type-guards-
|
|
6
|
-
|
|
7
|
-
import { t as generatePKCE } from "./pkce-BlQikGPu.mjs";
|
|
8
|
-
import { i as OPENAI_HEADER_VALUES } from "./codex-P1dGpX7G.mjs";
|
|
9
|
-
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@17.3.5/node_modules/@oh-my-pi/pi-ai/src/registry/oauth/openai-codex.ts
|
|
10
|
-
/**
|
|
11
|
-
* OpenAI Codex (ChatGPT OAuth) flow — browser and device-code flows.
|
|
12
|
-
*/
|
|
3
|
+
import { f as OAuthError, m as LoginCancelledError } from "./error-CORgGg5a.mjs";
|
|
4
|
+
import "./utils-CUPhpw9A.mjs";
|
|
5
|
+
import { n as isRecord } from "./type-guards-CttAANEx.mjs";
|
|
6
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-ai@18.1.17/node_modules/@oh-my-pi/pi-ai/src/registry/oauth/openai-codex.ts
|
|
13
7
|
const CLIENT_ID = "app_EMoamEEZ73f0CkXaXp7hrann";
|
|
14
|
-
const AUTHORIZE_URL = "https://auth.openai.com/oauth/authorize";
|
|
15
8
|
const TOKEN_URL = "https://auth.openai.com/oauth/token";
|
|
16
|
-
const CALLBACK_PORT = 1455;
|
|
17
|
-
const CALLBACK_PATH = "/auth/callback";
|
|
18
|
-
const SCOPE = "openid profile email offline_access api.connectors.read api.connectors.invoke";
|
|
19
9
|
const JWT_CLAIM_PATH = "https://api.openai.com/auth";
|
|
20
10
|
const JWT_PROFILE_CLAIM = "https://api.openai.com/profile";
|
|
21
11
|
const TOKEN_REQUEST_TIMEOUT_MS = 15e3;
|
|
@@ -49,8 +39,8 @@ function getTokenProfile(accessToken, idToken) {
|
|
|
49
39
|
const idPayload = idToken ? decodeJwt(idToken) : null;
|
|
50
40
|
const auth = payload?.[JWT_CLAIM_PATH];
|
|
51
41
|
const idAuth = idPayload?.[JWT_CLAIM_PATH];
|
|
52
|
-
const accountId = auth?.chatgpt_account_id;
|
|
53
|
-
const email = payload?.[JWT_PROFILE_CLAIM]?.email?.trim().toLowerCase();
|
|
42
|
+
const accountId = auth?.chatgpt_account_id ?? idAuth?.chatgpt_account_id;
|
|
43
|
+
const email = (payload?.[JWT_PROFILE_CLAIM]?.email ?? idPayload?.[JWT_PROFILE_CLAIM]?.email)?.trim().toLowerCase();
|
|
54
44
|
const planType = (auth?.chatgpt_plan_type ?? idAuth?.chatgpt_plan_type)?.trim().toLowerCase();
|
|
55
45
|
return {
|
|
56
46
|
accountId: typeof accountId === "string" && accountId.length > 0 ? accountId : void 0,
|
|
@@ -70,7 +60,28 @@ function describeTokenEndpointValue(value) {
|
|
|
70
60
|
if (code && message && code !== message) return `${code}: ${message}`;
|
|
71
61
|
return code ?? message ?? JSON.stringify(value);
|
|
72
62
|
}
|
|
73
|
-
/**
|
|
63
|
+
/** Enriches declaratively exchanged Codex credentials from access/id-token JWT claims. */
|
|
64
|
+
const openAICodexProfileHook = async (credentials, context) => {
|
|
65
|
+
const idToken = isRecord(context.raw) && typeof context.raw.id_token === "string" ? context.raw.id_token : void 0;
|
|
66
|
+
const { accountId, email, planType } = getTokenProfile(credentials.access, idToken);
|
|
67
|
+
if (context.phase === "login" && !accountId) throw new OAuthError("Failed to extract accountId from token", {
|
|
68
|
+
kind: "validation",
|
|
69
|
+
provider: context.provider
|
|
70
|
+
});
|
|
71
|
+
const resolvedAccountId = accountId ?? context.stored?.accountId;
|
|
72
|
+
return {
|
|
73
|
+
...credentials,
|
|
74
|
+
...resolvedAccountId ? { accountId: resolvedAccountId } : {},
|
|
75
|
+
...email ? { email } : context.stored?.email ? { email: context.stored.email } : {},
|
|
76
|
+
...context.phase === "login" && resolvedAccountId ? { orgId: resolvedAccountId } : {},
|
|
77
|
+
...context.phase === "login" && planType ? { orgName: planType } : {},
|
|
78
|
+
...context.phase === "refresh" && context.stored?.orgId ? { orgId: context.stored.orgId } : {},
|
|
79
|
+
...context.phase === "refresh" && context.stored?.orgName ? { orgName: context.stored.orgName } : {}
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Formats OpenAI Codex OAuth token endpoint errors for login and refresh failures.
|
|
84
|
+
*/
|
|
74
85
|
function formatOpenAICodexTokenEndpointError(status, bodyText) {
|
|
75
86
|
const trimmed = bodyText.trim();
|
|
76
87
|
if (trimmed.length === 0) return `${status}`;
|
|
@@ -85,52 +96,6 @@ function formatOpenAICodexTokenEndpointError(status, bodyText) {
|
|
|
85
96
|
return `${status} ${trimmed}`;
|
|
86
97
|
}
|
|
87
98
|
}
|
|
88
|
-
/** Builds the Codex browser OAuth URL used by browser login; exported for auth regression tests. */
|
|
89
|
-
function createOpenAICodexAuthorizationUrl(args) {
|
|
90
|
-
const originator = args.originator?.trim() || OPENAI_HEADER_VALUES.ORIGINATOR_CODEX;
|
|
91
|
-
const searchParams = new URLSearchParams({
|
|
92
|
-
response_type: "code",
|
|
93
|
-
client_id: CLIENT_ID,
|
|
94
|
-
redirect_uri: args.redirectUri,
|
|
95
|
-
scope: SCOPE,
|
|
96
|
-
code_challenge: args.challenge,
|
|
97
|
-
code_challenge_method: "S256",
|
|
98
|
-
state: args.state,
|
|
99
|
-
id_token_add_organizations: "true",
|
|
100
|
-
codex_cli_simplified_flow: "true",
|
|
101
|
-
originator
|
|
102
|
-
});
|
|
103
|
-
return `${AUTHORIZE_URL}?${searchParams.toString()}`;
|
|
104
|
-
}
|
|
105
|
-
var OpenAICodexOAuthFlow = class extends OAuthCallbackFlow {
|
|
106
|
-
#pkce;
|
|
107
|
-
#originator;
|
|
108
|
-
#fetch;
|
|
109
|
-
constructor(ctrl, pkce, originator, fetchImpl) {
|
|
110
|
-
super(ctrl, {
|
|
111
|
-
preferredPort: CALLBACK_PORT,
|
|
112
|
-
callbackPath: CALLBACK_PATH,
|
|
113
|
-
redirectUri: `http://localhost:${CALLBACK_PORT}${CALLBACK_PATH}`
|
|
114
|
-
});
|
|
115
|
-
this.#pkce = pkce;
|
|
116
|
-
this.#originator = originator;
|
|
117
|
-
this.#fetch = fetchImpl;
|
|
118
|
-
}
|
|
119
|
-
async generateAuthUrl(state, redirectUri) {
|
|
120
|
-
return {
|
|
121
|
-
url: createOpenAICodexAuthorizationUrl({
|
|
122
|
-
state,
|
|
123
|
-
redirectUri,
|
|
124
|
-
challenge: this.#pkce.challenge,
|
|
125
|
-
originator: this.#originator
|
|
126
|
-
}),
|
|
127
|
-
instructions: "A browser window should open. Complete login to finish."
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
async exchangeToken(code, _state, redirectUri) {
|
|
131
|
-
return exchangeCodeForToken(code, this.#pkce.verifier, redirectUri, this.#fetch);
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
99
|
async function exchangeCodeForToken(code, verifier, redirectUri, fetchImpl = fetch) {
|
|
135
100
|
const tokenResponse = await fetchImpl(TOKEN_URL, {
|
|
136
101
|
method: "POST",
|
|
@@ -165,9 +130,6 @@ async function exchangeCodeForToken(code, verifier, redirectUri, fetchImpl = fet
|
|
|
165
130
|
orgName: planType
|
|
166
131
|
};
|
|
167
132
|
}
|
|
168
|
-
async function loginOpenAICodex(options) {
|
|
169
|
-
return new OpenAICodexOAuthFlow(options, await generatePKCE(), options.originator?.trim() || OPENAI_HEADER_VALUES.ORIGINATOR_CODEX, options.fetch ?? fetch).login();
|
|
170
|
-
}
|
|
171
133
|
/**
|
|
172
134
|
* Login with OpenAI Codex using the device-code (headless) flow.
|
|
173
135
|
*
|
|
@@ -219,37 +181,5 @@ async function loginOpenAICodexDevice(ctrl) {
|
|
|
219
181
|
}
|
|
220
182
|
throw new OAuthError("Device authorization timed out — user did not complete login in time", { kind: "timeout" });
|
|
221
183
|
}
|
|
222
|
-
/**
|
|
223
|
-
* Refresh OpenAI Codex OAuth token
|
|
224
|
-
*/
|
|
225
|
-
async function refreshOpenAICodexToken(refreshToken) {
|
|
226
|
-
const response = await fetch(TOKEN_URL, {
|
|
227
|
-
method: "POST",
|
|
228
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
229
|
-
body: new URLSearchParams({
|
|
230
|
-
grant_type: "refresh_token",
|
|
231
|
-
refresh_token: refreshToken,
|
|
232
|
-
client_id: CLIENT_ID
|
|
233
|
-
}),
|
|
234
|
-
signal: AbortSignal.timeout(TOKEN_REQUEST_TIMEOUT_MS)
|
|
235
|
-
});
|
|
236
|
-
if (!response.ok) {
|
|
237
|
-
const bodyText = await response.text();
|
|
238
|
-
throw new OAuthError(`OpenAI Codex token refresh failed: ${formatOpenAICodexTokenEndpointError(response.status, bodyText)}`, {
|
|
239
|
-
kind: "token-refresh",
|
|
240
|
-
status: response.status
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
const tokenData = await response.json();
|
|
244
|
-
if (!tokenData.access_token || !tokenData.refresh_token || typeof tokenData.expires_in !== "number") throw new OAuthError("Token response missing required fields", { kind: "validation" });
|
|
245
|
-
const { accountId, email } = getTokenProfile(tokenData.access_token);
|
|
246
|
-
return {
|
|
247
|
-
access: tokenData.access_token,
|
|
248
|
-
refresh: tokenData.refresh_token || refreshToken,
|
|
249
|
-
expires: Date.now() + tokenData.expires_in * 1e3,
|
|
250
|
-
accountId: accountId ?? void 0,
|
|
251
|
-
email
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
184
|
//#endregion
|
|
255
|
-
export {
|
|
185
|
+
export { loginOpenAICodexDevice, openAICodexProfileHook };
|