dsh-codex-subscription 3.2.3 → 3.2.5
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 +7 -5
- package/README.md +7 -5
- package/compatibility.json +5 -3
- package/docs/plugin/DETAIL.md +3 -0
- package/docs/plugin/DETAIL.zh.md +3 -0
- package/lib/client.js +515 -260
- package/lib/index.js +275 -57
- package/locale/en.json +2 -1
- package/locale/zh.json +2 -1
- package/package.json +39 -38
package/lib/index.js
CHANGED
|
@@ -34,7 +34,7 @@ function createSettingsAdapter(ctx, config) {
|
|
|
34
34
|
if (!id) throw new Error("DSH settings entry is unavailable");
|
|
35
35
|
const liveConfig = () => {
|
|
36
36
|
try {
|
|
37
|
-
const current = ctx.fiber?.config ?? ctx.config;
|
|
37
|
+
const current = ctx.fiber?.effectiveConfig ?? ctx.fiber?.config ?? ctx.config;
|
|
38
38
|
return current !== null && typeof current === "object" ? current : config;
|
|
39
39
|
} catch {
|
|
40
40
|
return config;
|
|
@@ -718,6 +718,67 @@ function withDefaultReasoningEffort(adapter, { provider = "openai-codex", prefer
|
|
|
718
718
|
} });
|
|
719
719
|
}
|
|
720
720
|
//#endregion
|
|
721
|
+
//#region src/subagent-defaults.js
|
|
722
|
+
const PROVIDER$3 = "openai-codex";
|
|
723
|
+
const SUBAGENT_EFFORTS = Object.freeze(DEFAULT_REASONING_EFFORTS.filter((value) => value !== "ultra"));
|
|
724
|
+
const normalizeSubagentModel = (value) => typeof value === "string" && /^[a-z][a-z0-9._-]{0,79}$/u.test(value) ? value : "";
|
|
725
|
+
const normalizeSubagentEffort = (value) => SUBAGENT_EFFORTS.includes(value) ? value : "auto";
|
|
726
|
+
const permits = (routes, id) => Array.isArray(routes) && routes.some((route) => route.provider === PROVIDER$3 && route.model === id);
|
|
727
|
+
function createSubagentDefaults({ readSettings, catalog, modelSelection, projections }) {
|
|
728
|
+
function models(settings, selection) {
|
|
729
|
+
if (!selection || typeof selection.enabled !== "boolean") return [];
|
|
730
|
+
const disabled = normalizeDisabledModels(settings.disabledModels);
|
|
731
|
+
return catalog.getModels().filter((model) => !disabled.includes(model.id) && (!selection.enabled || permits(selection.allowedModels, model.id))).map((model) => ({
|
|
732
|
+
id: model.id,
|
|
733
|
+
name: model.name,
|
|
734
|
+
efforts: SUBAGENT_EFFORTS.filter((effort) => catalog.metadata(model.id)?.thinkingLevelMap?.[effort] != null)
|
|
735
|
+
}));
|
|
736
|
+
}
|
|
737
|
+
return {
|
|
738
|
+
list() {
|
|
739
|
+
try {
|
|
740
|
+
return models(readSettings(), modelSelection());
|
|
741
|
+
} catch {
|
|
742
|
+
return [];
|
|
743
|
+
}
|
|
744
|
+
},
|
|
745
|
+
async ready(requested = {}, signal) {
|
|
746
|
+
if (Object.keys(requested).length > 0 || catalog.getModels().length > 0) return;
|
|
747
|
+
const settings = readSettings();
|
|
748
|
+
if (!normalizeSubagentModel(settings.subagentDefaultModel) && normalizeSubagentEffort(settings.subagentDefaultEffort) === "auto") return;
|
|
749
|
+
try {
|
|
750
|
+
await catalog.refresh({ signal });
|
|
751
|
+
} catch {
|
|
752
|
+
signal?.throwIfAborted();
|
|
753
|
+
}
|
|
754
|
+
},
|
|
755
|
+
resolve(parent, requested = {}) {
|
|
756
|
+
if (Object.keys(requested).length > 0) return requested;
|
|
757
|
+
const settings = readSettings();
|
|
758
|
+
const chosen = normalizeSubagentModel(settings.subagentDefaultModel);
|
|
759
|
+
const effort = normalizeSubagentEffort(settings.subagentDefaultEffort);
|
|
760
|
+
if (!chosen && effort === "auto") return requested;
|
|
761
|
+
const parentRoute = parent.session.requestHeader?.()?.config ?? parent.options ?? {};
|
|
762
|
+
const id = chosen || (parentRoute.provider === PROVIDER$3 ? parentRoute.model : void 0);
|
|
763
|
+
if (!id) return requested;
|
|
764
|
+
try {
|
|
765
|
+
const model = models(settings, modelSelection()).find((candidate) => candidate.id === id);
|
|
766
|
+
const registry = projections();
|
|
767
|
+
if (!model || typeof registry?.stateOf !== "function") return requested;
|
|
768
|
+
const allowed = registry.stateOf(parent.session, "subagentModelSelectionPolicy");
|
|
769
|
+
if (allowed != null && !permits(allowed, id)) return requested;
|
|
770
|
+
if (!chosen && !model.efforts.includes(effort)) return requested;
|
|
771
|
+
return {
|
|
772
|
+
...chosen ? { model: chosen } : {},
|
|
773
|
+
...model.efforts.includes(effort) ? { reasoningEffort: effort === "off" ? "none" : effort } : {}
|
|
774
|
+
};
|
|
775
|
+
} catch {
|
|
776
|
+
return requested;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
//#endregion
|
|
721
782
|
//#region src/preference-fields.js
|
|
722
783
|
const PREFERENCE_FIELDS = Object.freeze({
|
|
723
784
|
compactionMode: {
|
|
@@ -769,6 +830,11 @@ const PREFERENCE_FIELDS = Object.freeze({
|
|
|
769
830
|
default: "dsh",
|
|
770
831
|
error: "Invalid subagent backend"
|
|
771
832
|
},
|
|
833
|
+
subagentDefaultEffort: {
|
|
834
|
+
choices: SUBAGENT_EFFORTS,
|
|
835
|
+
default: "auto",
|
|
836
|
+
error: "Invalid subtask reasoning effort"
|
|
837
|
+
},
|
|
772
838
|
[QUICK_QUOTA_MODE_FIELD]: {
|
|
773
839
|
choices: [
|
|
774
840
|
"off",
|
|
@@ -869,6 +935,51 @@ const setAuthFailureLogger = (fn) => {
|
|
|
869
935
|
logAuthFailure = fn;
|
|
870
936
|
};
|
|
871
937
|
const SIGN_IN_RENEW = "ChatGPT sign-in needs to be renewed";
|
|
938
|
+
const ACCESS_DENIED = "ChatGPT denied this request (HTTP 403). Check account access or contact OpenAI Support; signing in again may not resolve it.";
|
|
939
|
+
const DEVICE_LIMIT = "ChatGPT does not allow this paid account on this device. Use another permitted account you own or contact OpenAI Support. Signing out or resetting usage does not clear this restriction.";
|
|
940
|
+
const PURCHASE_LIMIT = "ChatGPT blocked this purchase because too many subscriptions are associated with this card or device. Contact OpenAI Support if this is unexpected.";
|
|
941
|
+
const PUBLIC_ACCESS_MESSAGES = /* @__PURE__ */ new Set([
|
|
942
|
+
ACCESS_DENIED,
|
|
943
|
+
DEVICE_LIMIT,
|
|
944
|
+
PURCHASE_LIMIT
|
|
945
|
+
]);
|
|
946
|
+
const isAccessFailureMessage = (message) => PUBLIC_ACCESS_MESSAGES.has(message);
|
|
947
|
+
const isRestrictionFailureMessage = (message) => message === "ChatGPT does not allow this paid account on this device. Use another permitted account you own or contact OpenAI Support. Signing out or resetting usage does not clear this restriction." || message === "ChatGPT blocked this purchase because too many subscriptions are associated with this card or device. Contact OpenAI Support if this is unexpected.";
|
|
948
|
+
function restrictionMessage(value) {
|
|
949
|
+
if (typeof value !== "string" || value.length > 8192) return void 0;
|
|
950
|
+
let text = value.trim().replace(/^Codex error:\s*/u, "");
|
|
951
|
+
try {
|
|
952
|
+
const body = JSON.parse(text);
|
|
953
|
+
text = body?.error?.message ?? body?.detail?.message ?? body?.detail ?? body?.message;
|
|
954
|
+
} catch {}
|
|
955
|
+
if (typeof text !== "string") return void 0;
|
|
956
|
+
text = text.trim().replace(/\s+/gu, " ");
|
|
957
|
+
if (PUBLIC_ACCESS_MESSAGES.has(text)) return text;
|
|
958
|
+
if (/^Device limit reached[.!]?$/iu.test(text)) return DEVICE_LIMIT;
|
|
959
|
+
if (/^Too many subscriptions associated with this card or device\. We can[’']t complete this purchase\.$/u.test(text)) return PURCHASE_LIMIT;
|
|
960
|
+
}
|
|
961
|
+
async function responseRestrictionMessage(response) {
|
|
962
|
+
if (typeof response?.clone !== "function") return void 0;
|
|
963
|
+
if (!/json|text\/plain/iu.test(response.headers?.get?.("content-type") ?? "")) return void 0;
|
|
964
|
+
let reader;
|
|
965
|
+
try {
|
|
966
|
+
reader = response.clone().body?.getReader();
|
|
967
|
+
if (!reader) return void 0;
|
|
968
|
+
const decoder = new TextDecoder();
|
|
969
|
+
let text = "", size = 0;
|
|
970
|
+
while (true) {
|
|
971
|
+
const { done, value } = await reader.read();
|
|
972
|
+
if (done) return restrictionMessage(text + decoder.decode());
|
|
973
|
+
size += value.byteLength;
|
|
974
|
+
if (size > 8192) return void 0;
|
|
975
|
+
text += decoder.decode(value, { stream: true });
|
|
976
|
+
}
|
|
977
|
+
} catch {
|
|
978
|
+
return;
|
|
979
|
+
} finally {
|
|
980
|
+
reader?.cancel().catch(() => {});
|
|
981
|
+
}
|
|
982
|
+
}
|
|
872
983
|
const REQUEST_BLOCKED = "ChatGPT blocked this request before it reached your account (HTTP 403); your sign-in is fine, try again later or check your network, proxy or VPN";
|
|
873
984
|
const CHALLENGE_MARKERS = /just a moment|cf-chl|_cf_chl_opt|attention required|enable javascript and cookies|challenge-platform/iu;
|
|
874
985
|
/** Whether error text is a Cloudflare / network-protection page (pi-ai keeps only the body of a failed request, not its status). */
|
|
@@ -887,14 +998,18 @@ async function isBlockedByNetwork(response) {
|
|
|
887
998
|
return false;
|
|
888
999
|
}
|
|
889
1000
|
}
|
|
890
|
-
/**
|
|
1001
|
+
/** Known restrictions take precedence over status-based authentication advice. */
|
|
891
1002
|
async function authFailureMessage(response) {
|
|
892
|
-
if (response
|
|
1003
|
+
if (!response || response.ok || response.status < 400) return void 0;
|
|
1004
|
+
const restriction = await responseRestrictionMessage(response);
|
|
1005
|
+
if (restriction !== void 0) return restriction;
|
|
1006
|
+
if (response.status !== 401 && response.status !== 403) return void 0;
|
|
893
1007
|
const blocked = response.status === 403 && await isBlockedByNetwork(response);
|
|
894
1008
|
await noteAuthFailure(response, blocked);
|
|
895
|
-
return blocked ? REQUEST_BLOCKED : SIGN_IN_RENEW;
|
|
1009
|
+
return blocked ? REQUEST_BLOCKED : response.status === 401 ? SIGN_IN_RENEW : ACCESS_DENIED;
|
|
896
1010
|
}
|
|
897
1011
|
async function noteAuthFailure(response, blocked) {
|
|
1012
|
+
if (typeof logAuthFailure !== "function") return;
|
|
898
1013
|
try {
|
|
899
1014
|
const text = blocked || typeof response.clone !== "function" ? "" : (await response.clone().text()).slice(0, 400);
|
|
900
1015
|
logAuthFailure?.(blocked ? "HTTP 403 from the network layer in front of ChatGPT" : `ChatGPT answered HTTP ${response.status}`, text === "" ? void 0 : text);
|
|
@@ -2187,6 +2302,7 @@ function hoistLeadingSystem(context) {
|
|
|
2187
2302
|
//#endregion
|
|
2188
2303
|
//#region src/model-retry-hint.js
|
|
2189
2304
|
const CODEX_OVERLOADED = /^\s*(?:Codex error:\s*)?Our servers are currently overloaded\. Please try again later\.\s*$/u;
|
|
2305
|
+
const CODEX_REQUEST_FAILED = /^\s*(?:Codex error:\s*)?An error occurred while processing your request\. You can retry your request, or contact us through our help center at help\.openai\.com if the error persists\. Please include the request ID [\w-]+ in your message\.?\s*$/u;
|
|
2190
2306
|
/** Keep the provider's wait as a fact; only DSH decides whether and when to retry. */
|
|
2191
2307
|
function providerRetryAfterMs(headers, at = Date.now()) {
|
|
2192
2308
|
const read = (key) => typeof headers?.get === "function" ? headers.get(key) : headers?.[key];
|
|
@@ -2201,8 +2317,11 @@ function providerRetryAfterMs(headers, at = Date.now()) {
|
|
|
2201
2317
|
return Number.isFinite(value) && value > 0 ? Math.min(value, Number.MAX_SAFE_INTEGER) : void 0;
|
|
2202
2318
|
}
|
|
2203
2319
|
function createModelRetryHint({ now = Date.now, ErrorClass = dshLlm.LlmError } = {}) {
|
|
2204
|
-
let response, responseStatus, outputStarted = false;
|
|
2320
|
+
let response, responseStatus, accessFailure, outputStarted = false;
|
|
2205
2321
|
return {
|
|
2322
|
+
onAccessFailure(message) {
|
|
2323
|
+
accessFailure = message;
|
|
2324
|
+
},
|
|
2206
2325
|
onResponse(info) {
|
|
2207
2326
|
responseStatus = info?.status;
|
|
2208
2327
|
response = [429, 503].includes(info?.status) ? {
|
|
@@ -2218,7 +2337,18 @@ function createModelRetryHint({ now = Date.now, ErrorClass = dshLlm.LlmError } =
|
|
|
2218
2337
|
].includes(event.type)) outputStarted = true;
|
|
2219
2338
|
},
|
|
2220
2339
|
failure(original, signal) {
|
|
2221
|
-
if (signal?.aborted ||
|
|
2340
|
+
if (signal?.aborted || !original || original.code === "ABORTED" || typeof original.message !== "string") return original;
|
|
2341
|
+
const restriction = accessFailure ?? restrictionMessage(original.message) ?? (responseStatus === 403 ? "ChatGPT denied this request (HTTP 403). Check account access or contact OpenAI Support; signing in again may not resolve it." : responseStatus === 401 ? "ChatGPT sign-in needs to be renewed" : void 0);
|
|
2342
|
+
if (restriction !== void 0) {
|
|
2343
|
+
const { providerRetryAfterMs: _delay, ...failure } = original;
|
|
2344
|
+
return {
|
|
2345
|
+
...failure,
|
|
2346
|
+
message: restriction,
|
|
2347
|
+
code: "AUTH",
|
|
2348
|
+
...responseStatus === void 0 ? {} : { status: responseStatus }
|
|
2349
|
+
};
|
|
2350
|
+
}
|
|
2351
|
+
if (outputStarted || [
|
|
2222
2352
|
"ABORTED",
|
|
2223
2353
|
"AUTH",
|
|
2224
2354
|
"INVALID_REQUEST",
|
|
@@ -2227,8 +2357,8 @@ function createModelRetryHint({ now = Date.now, ErrorClass = dshLlm.LlmError } =
|
|
|
2227
2357
|
"QUOTA_EXCEEDED"
|
|
2228
2358
|
].includes(original.code) || typeof dshLlm.isQuotaExceededError === "function" && dshLlm.isQuotaExceededError(original.message)) return original;
|
|
2229
2359
|
const status = responseStatus ?? original.status;
|
|
2230
|
-
const
|
|
2231
|
-
if (!response && !
|
|
2360
|
+
const transientStreamFailure = original.code === "PI_AI_ERROR" && (CODEX_OVERLOADED.test(original.message) || CODEX_REQUEST_FAILED.test(original.message)) && (status === void 0 || status >= 200 && status < 300);
|
|
2361
|
+
if (!response && !transientStreamFailure) return original;
|
|
2232
2362
|
if (/You have hit your ChatGPT usage limit/iu.test(original.message) || response?.status === 429 && original.code !== "RATE_LIMIT") return original;
|
|
2233
2363
|
const code = response?.status === 429 ? "RATE_LIMIT" : "SERVER";
|
|
2234
2364
|
let error;
|
|
@@ -2718,6 +2848,11 @@ function openaiCodexSubscriptionProvider({ resolveSpeedMode = () => void 0, reso
|
|
|
2718
2848
|
networkFailure = safeFetchFailure(error);
|
|
2719
2849
|
attempt.fetchFailure(error);
|
|
2720
2850
|
scopedNetwork?.onFetchFailure?.(error);
|
|
2851
|
+
},
|
|
2852
|
+
async transformResponse(response, target) {
|
|
2853
|
+
const value = await (scopedNetwork?.transformResponse?.(response, target) ?? response);
|
|
2854
|
+
if (retryHint) retryHint.onAccessFailure(value.ok ? void 0 : await authFailureMessage(value));
|
|
2855
|
+
return value;
|
|
2721
2856
|
}
|
|
2722
2857
|
}
|
|
2723
2858
|
};
|
|
@@ -2840,7 +2975,8 @@ Object.freeze([
|
|
|
2840
2975
|
"1.1.0",
|
|
2841
2976
|
"1.2.0",
|
|
2842
2977
|
"1.3.0",
|
|
2843
|
-
"1.4.0"
|
|
2978
|
+
"1.4.0",
|
|
2979
|
+
"1.5.0"
|
|
2844
2980
|
]);
|
|
2845
2981
|
//#endregion
|
|
2846
2982
|
//#region src/reasoning-json.js
|
|
@@ -3489,6 +3625,8 @@ function authenticatedSubagentChild(child, { Transport, getTokens, thread, signa
|
|
|
3489
3625
|
//#endregion
|
|
3490
3626
|
//#region src/subagent-runtime.js
|
|
3491
3627
|
const SUBAGENT_RUNTIME_PACKAGE = "@deepseek-ai/dsh-subagent-codex";
|
|
3628
|
+
const SUBAGENT_RUNTIME_VERSION = "0.2.2-rc.1";
|
|
3629
|
+
const SUBAGENT_CODEX_VERSION = "0.153.4";
|
|
3492
3630
|
const SUPPORTED_RUNTIME_VERSIONS = Object.freeze([
|
|
3493
3631
|
"0.1.7-rc.2",
|
|
3494
3632
|
"0.2.0-rc.1",
|
|
@@ -3503,7 +3641,9 @@ const SUPPORTED_RUNTIME_VERSIONS = Object.freeze([
|
|
|
3503
3641
|
"0.2.1-rc.3",
|
|
3504
3642
|
"0.2.1-rc.4",
|
|
3505
3643
|
"0.2.1-rc.5",
|
|
3506
|
-
"0.2.2-alpha.2"
|
|
3644
|
+
"0.2.2-alpha.2",
|
|
3645
|
+
"0.2.2-alpha.3",
|
|
3646
|
+
SUBAGENT_RUNTIME_VERSION
|
|
3507
3647
|
]);
|
|
3508
3648
|
const require = createRequire(import.meta.url);
|
|
3509
3649
|
const execute = promisify(execFile);
|
|
@@ -3548,7 +3688,7 @@ async function loadSubagentRuntime({ resolve: resolve$1 = require.resolve, run =
|
|
|
3548
3688
|
maxBuffer: 4096,
|
|
3549
3689
|
windowsHide: true
|
|
3550
3690
|
});
|
|
3551
|
-
if (stdout.trim() !==
|
|
3691
|
+
if (stdout.trim() !== `codex-cli 0.153.4`) throw new Error("Unexpected CLI version");
|
|
3552
3692
|
} catch {
|
|
3553
3693
|
throw new Error("Codex subtask runtime is incomplete; prepare it for this platform");
|
|
3554
3694
|
}
|
|
@@ -3617,7 +3757,7 @@ const CHILD_FEATURES_OFF = Object.freeze({ features: Object.freeze(Object.fromEn
|
|
|
3617
3757
|
"in_app_browser"
|
|
3618
3758
|
].map((name) => [name, false]))) });
|
|
3619
3759
|
/** Reuse the official DSH process/turn provider; keep only subscription auth here. */
|
|
3620
|
-
function createSubscriptionSubagent({ ctx, nativeHome, resolveAuth, store, refresh, loadRuntime, maintenance = () => false }) {
|
|
3760
|
+
function createSubscriptionSubagent({ ctx, nativeHome, resolveAuth, store, refresh, loadRuntime, maintenance = () => false, defaults }) {
|
|
3621
3761
|
let runtime;
|
|
3622
3762
|
const load = () => runtime ??= loadRuntime().catch((error) => {
|
|
3623
3763
|
runtime = void 0;
|
|
@@ -3644,7 +3784,10 @@ function createSubscriptionSubagent({ ctx, nativeHome, resolveAuth, store, refre
|
|
|
3644
3784
|
const signal = AbortSignal.any([request.signal, controller.signal]);
|
|
3645
3785
|
let run;
|
|
3646
3786
|
try {
|
|
3647
|
-
|
|
3787
|
+
await defaults?.ready(request.agentOptions, signal);
|
|
3788
|
+
signal.throwIfAborted();
|
|
3789
|
+
const options = defaults?.resolve(request.parent, request.agentOptions) ?? request.agentOptions;
|
|
3790
|
+
const thread = subagentThreadPolicy(request.parent, ctx.sandboxPolicy.resolve({ session: request.parent.session }), options);
|
|
3648
3791
|
const getTokens = await createSubagentTokens({
|
|
3649
3792
|
resolveAuth,
|
|
3650
3793
|
store,
|
|
@@ -4329,7 +4472,7 @@ function inheritedOriginalImageRef(session, assetId) {
|
|
|
4329
4472
|
}
|
|
4330
4473
|
//#endregion
|
|
4331
4474
|
//#region src/version.js
|
|
4332
|
-
const PACKAGE_VERSION = "3.2.
|
|
4475
|
+
const PACKAGE_VERSION = "3.2.5";
|
|
4333
4476
|
const USER_AGENT = `dsh-codex-subscription/${PACKAGE_VERSION}`;
|
|
4334
4477
|
//#endregion
|
|
4335
4478
|
//#region src/codex-images.js
|
|
@@ -4852,7 +4995,7 @@ function createCodexImageTool(options) {
|
|
|
4852
4995
|
if (!response.ok) {
|
|
4853
4996
|
const authFailure = await authFailureMessage(response);
|
|
4854
4997
|
const requestId = supportId(response);
|
|
4855
|
-
if (response.status === 403 && authFailure === "ChatGPT
|
|
4998
|
+
if (response.status === 403 && authFailure === "ChatGPT denied this request (HTTP 403). Check account access or contact OpenAI Support; signing in again may not resolve it.") throw new Error(`${await refusalMessage(response, editing)}${requestId}`);
|
|
4856
4999
|
if (authFailure !== void 0) throw new Error(authFailure);
|
|
4857
5000
|
if (response.status === 429) throw new Error(`${await limitMessage(response)}${requestId}`);
|
|
4858
5001
|
throw new Error(`Codex image ${editing ? "edit" : "generation"} failed (HTTP ${response.status})${requestId}`);
|
|
@@ -10188,7 +10331,7 @@ function nativeDelegations(ctx, agent) {
|
|
|
10188
10331
|
const tools = scopedTools(agent) ?? ctx.get?.("tools");
|
|
10189
10332
|
const subagents = ctx.get?.("subagents");
|
|
10190
10333
|
return presetEntries(ctx).flatMap((entry) => {
|
|
10191
|
-
const config = entry.fiber?.config ?? entry.options?.config;
|
|
10334
|
+
const config = entry.fiber?.effectiveConfig ?? entry.fiber?.config ?? entry.options?.config;
|
|
10192
10335
|
if (entry.options?.name !== "@deepseek-ai/dsh-tool-subagent" || !["spawn", "codex-subscription-subagent"].includes(config?.provider) || !subagents?.getProvider?.(config.provider)) return [];
|
|
10193
10336
|
const name = config.toolName ?? "subagent";
|
|
10194
10337
|
const definition = tools?.get?.(name, agent);
|
|
@@ -10232,7 +10375,7 @@ function createUltraExecutionPreset({ catalog, resolveAgent = () => void 0, defa
|
|
|
10232
10375
|
if (!state || !state.tools.some((tool) => tool.name === exec.name)) return;
|
|
10233
10376
|
if (!state.active || state.signal.aborted || exec.agent !== agent) return "Ultra delegation belongs to an inactive or cancelled request";
|
|
10234
10377
|
const tool = state.tools.find((tool) => tool.name === exec.name);
|
|
10235
|
-
if (tools.get(exec.name, agent) !== tool.definition) return "Ultra delegation tool changed after request preparation; retry the request";
|
|
10378
|
+
if (tools.get(exec.name, agent, exec.toolSet) !== tool.definition) return "Ultra delegation tool changed after request preparation; retry the request";
|
|
10236
10379
|
});
|
|
10237
10380
|
bindings.set(agent, binding);
|
|
10238
10381
|
return binding;
|
|
@@ -10708,6 +10851,15 @@ function emailFromAccessToken(access) {
|
|
|
10708
10851
|
const payload = decodeJwtPayload(access);
|
|
10709
10852
|
return normalizeAccountEmail(payload?.["https://api.openai.com/profile"]?.email ?? payload?.email);
|
|
10710
10853
|
}
|
|
10854
|
+
function sameOAuthAccount(previous, next) {
|
|
10855
|
+
if (typeof previous.accountId !== "string" || previous.accountId.length === 0 || previous.accountId !== next.accountId) return false;
|
|
10856
|
+
const old = decodeJwtPayload(previous.access);
|
|
10857
|
+
const fresh = decodeJwtPayload(next.access);
|
|
10858
|
+
const oldUser = old?.["https://api.openai.com/auth"]?.chatgpt_user_id;
|
|
10859
|
+
const freshUser = fresh?.["https://api.openai.com/auth"]?.chatgpt_user_id;
|
|
10860
|
+
if (typeof oldUser === "string" && oldUser && typeof freshUser === "string" && freshUser) return oldUser === freshUser;
|
|
10861
|
+
return typeof old?.sub === "string" && old.sub.length > 0 && old.sub === fresh?.sub;
|
|
10862
|
+
}
|
|
10711
10863
|
/** Normalize the one non-secret account attribute that may cross the UI boundary. */
|
|
10712
10864
|
function sanitizeOAuthCredential(value) {
|
|
10713
10865
|
const credential = assertOAuthCredential$1(value);
|
|
@@ -10920,6 +11072,18 @@ var DshOAuthAccountVault = class {
|
|
|
10920
11072
|
activeId() {
|
|
10921
11073
|
return this.#enqueue(async () => (await this.#ensurePayload())?.activeId);
|
|
10922
11074
|
}
|
|
11075
|
+
renew(id, credential, signal) {
|
|
11076
|
+
const next = sanitizeOAuthCredential(credential);
|
|
11077
|
+
return this.modifyAccount(id, (current) => {
|
|
11078
|
+
signal?.throwIfAborted();
|
|
11079
|
+
if (!sameOAuthAccount(current, next)) {
|
|
11080
|
+
const error = /* @__PURE__ */ new Error("Codex login did not match the saved account");
|
|
11081
|
+
error.code = "account-mismatch";
|
|
11082
|
+
throw error;
|
|
11083
|
+
}
|
|
11084
|
+
return next;
|
|
11085
|
+
});
|
|
11086
|
+
}
|
|
10923
11087
|
add(label, credential) {
|
|
10924
11088
|
return this.#enqueue(async () => {
|
|
10925
11089
|
const normalizedLabel = normalizeLabel(label);
|
|
@@ -11166,14 +11330,16 @@ function createCodexAuthService(models, store, options = {}) {
|
|
|
11166
11330
|
};
|
|
11167
11331
|
},
|
|
11168
11332
|
login(interaction, input = {}) {
|
|
11169
|
-
if (input.label !== void 0) {
|
|
11333
|
+
if (input.label !== void 0 || input.renewId !== void 0) {
|
|
11170
11334
|
if (accountVault === void 0 || createLoginModels === void 0) throw new Error("Codex multi-account is unavailable");
|
|
11171
11335
|
return runLogin(async () => {
|
|
11172
11336
|
const pending = createPendingStore();
|
|
11173
11337
|
await createLoginModels(pending).login(PROVIDER$2, "oauth", interaction);
|
|
11174
11338
|
const credential = pending.credential();
|
|
11175
11339
|
if (credential === void 0) throw new Error("Codex login did not return credentials");
|
|
11176
|
-
|
|
11340
|
+
interaction.signal?.throwIfAborted();
|
|
11341
|
+
if (input.renewId !== void 0) await accountVault.renew(input.renewId, credential, interaction.signal);
|
|
11342
|
+
else await accountVault.add(input.label, credential);
|
|
11177
11343
|
});
|
|
11178
11344
|
}
|
|
11179
11345
|
return runLogin(() => models.login(PROVIDER$2, "oauth", interaction));
|
|
@@ -11317,10 +11483,12 @@ const PUBLIC_FAILURES = /* @__PURE__ */ new Set([
|
|
|
11317
11483
|
"account-claim",
|
|
11318
11484
|
"network",
|
|
11319
11485
|
"token-exchange",
|
|
11320
|
-
"callback"
|
|
11486
|
+
"callback",
|
|
11487
|
+
"account-mismatch"
|
|
11321
11488
|
]);
|
|
11322
11489
|
const publicFailure = (kind) => PUBLIC_FAILURES.has(kind) ? kind : void 0;
|
|
11323
11490
|
function classifyLoginFailure(error) {
|
|
11491
|
+
if (error?.code === "account-mismatch") return "account-mismatch";
|
|
11324
11492
|
const message = error instanceof Error ? error.message : "";
|
|
11325
11493
|
if (/token exchange failed/iu.test(message)) return "token-exchange";
|
|
11326
11494
|
if (/fetch failed|\b(?:ECONN|ENOTFOUND|ETIMEDOUT|CERT_|socket|network)\b/iu.test(message)) return "network";
|
|
@@ -11349,9 +11517,10 @@ var CodexLoginCoordinator = class {
|
|
|
11349
11517
|
...active.view.phase === "failed" ? { failure: classifyLoginFailure(active.hostError) } : {}
|
|
11350
11518
|
};
|
|
11351
11519
|
}
|
|
11352
|
-
async start({ method, label }) {
|
|
11520
|
+
async start({ method, label, renewId }) {
|
|
11353
11521
|
if (!LOGIN_METHODS.has(method)) throw new Error(`unsupported Codex login method: ${String(method)}`);
|
|
11354
11522
|
if (label !== void 0 && (typeof label !== "string" || label.trim().length === 0 || label.trim().length > 48)) throw new Error("unsupported Codex account label");
|
|
11523
|
+
if (renewId !== void 0 && (label !== void 0 || typeof renewId !== "string" || !/^[\w-]{1,128}$/u.test(renewId))) throw new Error("unsupported Codex renewal target");
|
|
11355
11524
|
const active = this.#activeId === void 0 ? void 0 : this.#sessions.get(this.#activeId);
|
|
11356
11525
|
if (active !== void 0 && !TERMINAL_PHASES.has(active.view.phase)) {
|
|
11357
11526
|
active.view = {
|
|
@@ -11436,7 +11605,7 @@ var CodexLoginCoordinator = class {
|
|
|
11436
11605
|
publishReady();
|
|
11437
11606
|
}
|
|
11438
11607
|
};
|
|
11439
|
-
session.run = Promise.resolve().then(() => this.auth.login(interaction, label === void 0 ? {} : { label: label.trim() })).then(async () => {
|
|
11608
|
+
session.run = Promise.resolve().then(() => this.auth.login(interaction, renewId !== void 0 ? { renewId } : label === void 0 ? {} : { label: label.trim() })).then(async () => {
|
|
11440
11609
|
if (controller.signal.aborted) return;
|
|
11441
11610
|
const status = await this.auth.status();
|
|
11442
11611
|
session.view = {
|
|
@@ -11459,7 +11628,8 @@ var CodexLoginCoordinator = class {
|
|
|
11459
11628
|
return;
|
|
11460
11629
|
}
|
|
11461
11630
|
try {
|
|
11462
|
-
if (
|
|
11631
|
+
if (restrictionMessage(error?.message) !== void 0) throw error;
|
|
11632
|
+
if (label !== void 0 || renewId !== void 0) throw error;
|
|
11463
11633
|
const status = await this.auth.status();
|
|
11464
11634
|
if (status.authenticated === true) {
|
|
11465
11635
|
session.view = {
|
|
@@ -11480,7 +11650,7 @@ var CodexLoginCoordinator = class {
|
|
|
11480
11650
|
method,
|
|
11481
11651
|
phase: "failed",
|
|
11482
11652
|
authenticated: false,
|
|
11483
|
-
error: "Codex login failed",
|
|
11653
|
+
error: restrictionMessage(error?.message) ?? "Codex login failed",
|
|
11484
11654
|
failure: publicFailure(classifyLoginFailure(error))
|
|
11485
11655
|
};
|
|
11486
11656
|
session.hostError = error;
|
|
@@ -11554,7 +11724,8 @@ function createCodexRpcHandler(coordinator, options = {}) {
|
|
|
11554
11724
|
if (endpoint === "login/start") {
|
|
11555
11725
|
const started = await coordinator.start({
|
|
11556
11726
|
method: input.method,
|
|
11557
|
-
label: input.label
|
|
11727
|
+
label: input.label,
|
|
11728
|
+
renewId: input.renewId
|
|
11558
11729
|
});
|
|
11559
11730
|
if (input.openExternal !== true) return ok(started);
|
|
11560
11731
|
const url = started.authUrl ?? started.deviceCode?.verificationUri;
|
|
@@ -11923,6 +12094,8 @@ function mergeModel(baseModels, remote) {
|
|
|
11923
12094
|
* @returns {object} 可初始化、刷新、查询和清除的模型目录
|
|
11924
12095
|
*/
|
|
11925
12096
|
function createOfficialModelCatalog(options = {}) {
|
|
12097
|
+
const nativeVersion = options.nativeVersion;
|
|
12098
|
+
const endpoint = nativeVersion === void 0 ? CODEX_MODELS_URL : `https://chatgpt.com/backend-api/codex/models?client_version=${encodeURIComponent(nativeVersion)}`;
|
|
11926
12099
|
const fetchCatalog = options.fetch ?? fetch;
|
|
11927
12100
|
const getNow = options.now ?? Date.now;
|
|
11928
12101
|
const schedule = options.setTimeout ?? setTimeout;
|
|
@@ -12090,7 +12263,7 @@ function createOfficialModelCatalog(options = {}) {
|
|
|
12090
12263
|
initialized = true;
|
|
12091
12264
|
}
|
|
12092
12265
|
const id = credentials.accountId;
|
|
12093
|
-
const response = await fetchCatalog(
|
|
12266
|
+
const response = await fetchCatalog(endpoint, {
|
|
12094
12267
|
method: "GET",
|
|
12095
12268
|
redirect: "error",
|
|
12096
12269
|
signal: requestSignal,
|
|
@@ -12098,17 +12271,20 @@ function createOfficialModelCatalog(options = {}) {
|
|
|
12098
12271
|
authorization: `Bearer ${credentials.access}`,
|
|
12099
12272
|
"chatgpt-account-id": id,
|
|
12100
12273
|
accept: "application/json",
|
|
12101
|
-
originator: "pi",
|
|
12274
|
+
originator: nativeVersion === void 0 ? "pi" : "codex_cli_rs",
|
|
12102
12275
|
"user-agent": USER_AGENT,
|
|
12103
12276
|
...etag === void 0 ? {} : { "if-none-match": etag }
|
|
12104
12277
|
}
|
|
12105
12278
|
});
|
|
12106
12279
|
if (!current(flight) || accountId !== id) return false;
|
|
12107
|
-
if (response.status !== 304 && !response.ok) throw new Error(`Codex model catalog failed (HTTP ${response.status})`);
|
|
12280
|
+
if (response.status !== 304 && !response.ok) throw new Error(await authFailureMessage(response) ?? `Codex model catalog failed (HTTP ${response.status})`);
|
|
12108
12281
|
const raw = response.status === 304 ? rawCatalog : await response.json();
|
|
12109
12282
|
if (!current(flight) || accountId !== id) return false;
|
|
12110
12283
|
if (raw === void 0) throw new Error("Codex returned HTTP 304 without a cached model catalog");
|
|
12111
|
-
const remote = parseOfficialModelCatalog(
|
|
12284
|
+
const remote = parseOfficialModelCatalog(nativeVersion !== void 0 && Array.isArray(raw?.models) ? {
|
|
12285
|
+
...raw,
|
|
12286
|
+
models: raw.models.filter((model) => model?.visibility === "list" && model.supported_in_api !== false)
|
|
12287
|
+
} : raw, getNow());
|
|
12112
12288
|
const next = remote.map((model) => mergeModel(options.baseModels(), model)).filter(Boolean);
|
|
12113
12289
|
if (!next.length) throw new Error("Codex returned an empty or incompatible model catalog");
|
|
12114
12290
|
const changed = response.status !== 304 || JSON.stringify(next) !== JSON.stringify(models);
|
|
@@ -12134,7 +12310,7 @@ function createOfficialModelCatalog(options = {}) {
|
|
|
12134
12310
|
}, (error) => {
|
|
12135
12311
|
if (flight.generation === generation) {
|
|
12136
12312
|
refreshStatus = signal?.aborted ? "idle" : "failed";
|
|
12137
|
-
if (!signal?.aborted) scheduleRetry(flight.generation);
|
|
12313
|
+
if (!signal?.aborted && !isRestrictionFailureMessage(error?.message)) scheduleRetry(flight.generation);
|
|
12138
12314
|
}
|
|
12139
12315
|
throw error;
|
|
12140
12316
|
}).finally(() => {
|
|
@@ -12301,7 +12477,7 @@ function createCodexSearchProvider(options) {
|
|
|
12301
12477
|
if (typeof access !== "string" || access.length === 0 || typeof accountId !== "string" || accountId.length === 0) throw new WebError("ChatGPT subscription is not signed in", "WEB_PROVIDER_CREDENTIAL_MISSING");
|
|
12302
12478
|
const model = nonEmpty(options.resolveModel?.()) ?? DEFAULT_MODEL;
|
|
12303
12479
|
const id = nonEmpty(options.resolveSessionId?.()) ?? randomUUID();
|
|
12304
|
-
let response;
|
|
12480
|
+
let response, authFailure;
|
|
12305
12481
|
try {
|
|
12306
12482
|
const init = {
|
|
12307
12483
|
method: "POST",
|
|
@@ -12333,9 +12509,10 @@ function createCodexSearchProvider(options) {
|
|
|
12333
12509
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
12334
12510
|
response = await fetchSearch(CODEX_SEARCH_URL, init);
|
|
12335
12511
|
signal?.throwIfAborted();
|
|
12512
|
+
authFailure = response.ok ? void 0 : await authFailureMessage(response);
|
|
12336
12513
|
const requestId = response.headers?.get?.("x-request-id") ?? response.headers?.get?.("cf-ray");
|
|
12337
12514
|
const detail = `model=${model}, mode=${preferences.searchMode}, attempt=${attempt + 1}${typeof requestId === "string" && /^[a-zA-Z0-9._:-]{1,128}$/u.test(requestId) ? `, requestId=${requestId}` : ""}`;
|
|
12338
|
-
const retry = attempt === 0 && RETRYABLE_STATUSES.has(response.status);
|
|
12515
|
+
const retry = authFailure === void 0 && attempt === 0 && RETRYABLE_STATUSES.has(response.status);
|
|
12339
12516
|
diagnosticLog.log(response.ok ? "info" : "warn", "search", `Codex search HTTP ${response.status}${retry ? "; retrying once on the same source" : ""}`, detail);
|
|
12340
12517
|
if (!retry) break;
|
|
12341
12518
|
try {
|
|
@@ -12348,7 +12525,6 @@ function createCodexSearchProvider(options) {
|
|
|
12348
12525
|
throw new WebError("Codex search request failed", "WEB_PROVIDER_ERROR", { cause: error });
|
|
12349
12526
|
}
|
|
12350
12527
|
if (!response.ok) {
|
|
12351
|
-
const authFailure = await authFailureMessage(response);
|
|
12352
12528
|
if (signal?.aborted) throw new WebError("Codex search aborted", "WEB_ABORTED", { cause: signal.reason });
|
|
12353
12529
|
throw authFailure === "ChatGPT sign-in needs to be renewed" ? new WebError(authFailure, "WEB_PROVIDER_CREDENTIAL_MISSING") : authFailure !== void 0 ? new WebError(authFailure, "WEB_PROVIDER_ERROR") : new WebError(`Codex search request failed (HTTP ${response.status})`, "WEB_PROVIDER_ERROR");
|
|
12354
12530
|
}
|
|
@@ -12571,12 +12747,12 @@ function createCodexFetchProvider(options) {
|
|
|
12571
12747
|
activeSignal.throwIfAborted();
|
|
12572
12748
|
diagnosticLog.info("fetch", `Codex webpage HTTP ${response.status}`, `attempt=${attempt}`);
|
|
12573
12749
|
if (!response.ok) {
|
|
12574
|
-
|
|
12750
|
+
const authFailure = await authFailureMessage(response);
|
|
12751
|
+
if (authFailure === void 0 && RETRYABLE.has(response.status) && attempt === 1) {
|
|
12575
12752
|
await response.body?.cancel();
|
|
12576
12753
|
await setTimeout$1(options.retryDelayMs ?? 250, void 0, { signal: activeSignal });
|
|
12577
12754
|
continue;
|
|
12578
12755
|
}
|
|
12579
|
-
const authFailure = await authFailureMessage(response);
|
|
12580
12756
|
throw new WebError(authFailure ?? `Codex webpage request failed (HTTP ${response.status})`, authFailure === "ChatGPT sign-in needs to be renewed" ? "WEB_PROVIDER_CREDENTIAL_MISSING" : "WEB_PROVIDER_ERROR");
|
|
12581
12757
|
}
|
|
12582
12758
|
const value = await response.json();
|
|
@@ -12650,7 +12826,8 @@ function configuredFetchProviderId(web, entries = [], ambient = process.env.DSH_
|
|
|
12650
12826
|
const environment = "fetchProviderEnv" in web ? web.fetchProviderEnv : ambient;
|
|
12651
12827
|
if (typeof web.config?.fetchProvider?.get === "function") return web.config.fetchProvider.get() ?? environment;
|
|
12652
12828
|
const entry = [...entries].find((item) => item.options?.id === "web");
|
|
12653
|
-
const
|
|
12829
|
+
const fiber = entry?.fiber;
|
|
12830
|
+
const value = (fiber?.effectiveConfig ?? fiber?.config)?.fetchProvider;
|
|
12654
12831
|
if (typeof value?.get === "function") return value.get() ?? environment;
|
|
12655
12832
|
return value ?? entry?.options?.config?.fetchProvider ?? environment;
|
|
12656
12833
|
}
|
|
@@ -13805,7 +13982,7 @@ function createCodexUsageReader(options) {
|
|
|
13805
13982
|
read({ force = false, signal } = {}) {
|
|
13806
13983
|
if (signal?.aborted) return Promise.reject(signal.reason);
|
|
13807
13984
|
if (failed !== void 0 && now() < failed.retryAt) return Promise.reject(new Error(failed.message));
|
|
13808
|
-
if (!force && cached !== void 0 && now() - cached.fetchedAt < ttlFor(cached)) return Promise.resolve(structuredClone(cached));
|
|
13985
|
+
if (!force && failed === void 0 && cached !== void 0 && now() - cached.fetchedAt < ttlFor(cached)) return Promise.resolve(structuredClone(cached));
|
|
13809
13986
|
return requests.run("read", async (sharedSignal) => {
|
|
13810
13987
|
const currentGeneration = generation;
|
|
13811
13988
|
try {
|
|
@@ -13895,7 +14072,7 @@ function createAccountUsageReader({ vault, createModels, fetch, expirySkewMs = 0
|
|
|
13895
14072
|
const summarize = (error, signal) => {
|
|
13896
14073
|
if (signal?.aborted) throw error;
|
|
13897
14074
|
const message = error instanceof Error ? error.message : "";
|
|
13898
|
-
return ["ChatGPT subscription is not signed in", "ChatGPT sign-in needs to be renewed"].includes(message) || message.includes("blocked this request") ? message : "Could not read ChatGPT usage";
|
|
14075
|
+
return isAccessFailureMessage(message) || ["ChatGPT subscription is not signed in", "ChatGPT sign-in needs to be renewed"].includes(message) || message.includes("blocked this request") ? message : "Could not read ChatGPT usage";
|
|
13899
14076
|
};
|
|
13900
14077
|
return Object.freeze({
|
|
13901
14078
|
/** One entry per account: its usage reading, or the reason it could not be read. */
|
|
@@ -14014,7 +14191,10 @@ function createReportReader({ url, parse, label, getAuth, readCredential, fetch:
|
|
|
14014
14191
|
available: false,
|
|
14015
14192
|
fetchedAt: now()
|
|
14016
14193
|
};
|
|
14017
|
-
if (!response.ok)
|
|
14194
|
+
if (!response.ok) {
|
|
14195
|
+
const failure = await authFailureMessage(response);
|
|
14196
|
+
throw new Error(failure === "ChatGPT denied this request (HTTP 403). Check account access or contact OpenAI Support; signing in again may not resolve it." ? `ChatGPT does not offer the ${label} to this account` : failure ?? `ChatGPT ${label} request failed (HTTP ${response.status})`);
|
|
14197
|
+
}
|
|
14018
14198
|
let body;
|
|
14019
14199
|
try {
|
|
14020
14200
|
body = await response.json();
|
|
@@ -14196,9 +14376,10 @@ function createConnectorsClient({ getAuth, readCredential, fetch: fetchRpc = fet
|
|
|
14196
14376
|
}),
|
|
14197
14377
|
signal: signal === void 0 ? timeout : AbortSignal.any([signal, timeout])
|
|
14198
14378
|
});
|
|
14199
|
-
if (response.
|
|
14200
|
-
|
|
14201
|
-
|
|
14379
|
+
if (!response.ok) {
|
|
14380
|
+
const failure = await authFailureMessage(response);
|
|
14381
|
+
throw new Error(failure === "ChatGPT denied this request (HTTP 403). Check account access or contact OpenAI Support; signing in again may not resolve it." ? "ChatGPT does not offer connectors to this account" : failure ?? `ChatGPT connectors request failed (HTTP ${response.status})`);
|
|
14382
|
+
}
|
|
14202
14383
|
const message = await readRpc(response);
|
|
14203
14384
|
if (record$1(message.error)) throw new Error(`Connector error: ${clip(oneLine(String(message.error.message ?? message.error.code ?? "failed")), 200)}`);
|
|
14204
14385
|
return {
|
|
@@ -14573,6 +14754,7 @@ function createCodexQuotaRetryHandler({ usageReader, provider = "openai-codex",
|
|
|
14573
14754
|
} catch {}
|
|
14574
14755
|
};
|
|
14575
14756
|
const handler = async ({ agent, turn, step, provider: requestProvider, failure, signal }, next) => {
|
|
14757
|
+
if (requestProvider === provider && isRestrictionFailureMessage(failure?.message)) return void 0;
|
|
14576
14758
|
if (requestProvider !== provider || !isCodexRateLimit(failure) || !enabled()) return next();
|
|
14577
14759
|
if (signal?.aborted) return void 0;
|
|
14578
14760
|
let wakeRevision = wakeSignal.revision();
|
|
@@ -15074,12 +15256,11 @@ function parseDetails(value, now) {
|
|
|
15074
15256
|
if (available.length === 0) throw new Error("No usable quota reset is available");
|
|
15075
15257
|
return {
|
|
15076
15258
|
availableCount: value.available_count,
|
|
15077
|
-
credits: available.map(({ credit, expiresAt }
|
|
15259
|
+
credits: available.map(({ credit, expiresAt }) => ({
|
|
15078
15260
|
creditId: credit.id,
|
|
15079
15261
|
title: safeCopy(credit.title),
|
|
15080
15262
|
description: safeCopy(credit.description),
|
|
15081
|
-
creditExpiresAt: expiresAt
|
|
15082
|
-
index
|
|
15263
|
+
creditExpiresAt: expiresAt
|
|
15083
15264
|
}))
|
|
15084
15265
|
};
|
|
15085
15266
|
}
|
|
@@ -15117,11 +15298,16 @@ function createCodexResetCreditService(options) {
|
|
|
15117
15298
|
const creditRefs = /* @__PURE__ */ new Map();
|
|
15118
15299
|
let creditRefSequence = 0;
|
|
15119
15300
|
const rememberCreditRef = (accountId, credit) => {
|
|
15301
|
+
for (const [ref, stored] of creditRefs) {
|
|
15302
|
+
if (stored.accountId !== accountId || stored.creditId !== credit.creditId) continue;
|
|
15303
|
+
creditRefs.delete(ref);
|
|
15304
|
+
creditRefs.set(ref, stored);
|
|
15305
|
+
return ref;
|
|
15306
|
+
}
|
|
15120
15307
|
const ref = `${randomUUID$1()}-${++creditRefSequence}`;
|
|
15121
15308
|
creditRefs.set(ref, {
|
|
15122
15309
|
accountId,
|
|
15123
|
-
creditId: credit.creditId
|
|
15124
|
-
index: credit.index
|
|
15310
|
+
creditId: credit.creditId
|
|
15125
15311
|
});
|
|
15126
15312
|
while (creditRefs.size > 64) creditRefs.delete(creditRefs.keys().next().value);
|
|
15127
15313
|
return ref;
|
|
@@ -15200,7 +15386,7 @@ function createCodexResetCreditService(options) {
|
|
|
15200
15386
|
if (creditRef !== void 0) {
|
|
15201
15387
|
const reference = typeof creditRef === "string" ? creditRefs.get(creditRef) : void 0;
|
|
15202
15388
|
if (reference === void 0 || reference.accountId !== accountId) throw new Error("This quota reset confirmation is no longer valid");
|
|
15203
|
-
selected = details.credits.find((credit) => credit.creditId === reference.creditId
|
|
15389
|
+
selected = details.credits.find((credit) => credit.creditId === reference.creditId);
|
|
15204
15390
|
if (selected === void 0) throw new Error("This quota reset confirmation is no longer valid");
|
|
15205
15391
|
}
|
|
15206
15392
|
if (selected === void 0) throw new Error("No usable quota reset is available");
|
|
@@ -15336,7 +15522,7 @@ async function settlesLive(preferences, patch, signal, { attempts = 8, delayMs =
|
|
|
15336
15522
|
}
|
|
15337
15523
|
return live();
|
|
15338
15524
|
}
|
|
15339
|
-
function createSubscriptionRpcHandler({ authHandler, usageReader, accountUsageReader, planHistoryReader, usageProfileReader, resetCreditService, preferences, defaultModel, runtimeManagement, remoteControl, desktopVoice, nativeVoice, voicePreview, composerPredictions, diagnosticsReader, modelCatalog, originalImages, resolveInheritedOriginal, closeConnections, onAccountChanged, onCleanupFailure }) {
|
|
15525
|
+
function createSubscriptionRpcHandler({ authHandler, usageReader, accountUsageReader, planHistoryReader, usageProfileReader, resetCreditService, preferences, defaultModel, runtimeManagement, remoteControl, desktopVoice, nativeVoice, voicePreview, composerPredictions, diagnosticsReader, modelCatalog, subagentCatalog, originalImages, resolveInheritedOriginal, closeConnections, onAccountChanged, onCleanupFailure }) {
|
|
15340
15526
|
return async (endpoint, payload, signal) => {
|
|
15341
15527
|
if (endpoint === "predictions/generate") try {
|
|
15342
15528
|
signal?.throwIfAborted();
|
|
@@ -15562,12 +15748,15 @@ function createSubscriptionRpcHandler({ authHandler, usageReader, accountUsageRe
|
|
|
15562
15748
|
if (endpoint === "preferences/models") try {
|
|
15563
15749
|
signal.throwIfAborted();
|
|
15564
15750
|
if (typeof modelCatalog?.refresh !== "function" || typeof preferences?.status !== "function") return publicError("internal", "Could not refresh Codex model catalog");
|
|
15565
|
-
|
|
15751
|
+
const native = subagentCatalog && preferences.status()?.subagentBackend === "codex" ? subagentCatalog.refresh({ signal }).catch(() => {}) : void 0;
|
|
15752
|
+
await Promise.all([modelCatalog.refresh({ signal }), native]);
|
|
15753
|
+
signal.throwIfAborted();
|
|
15566
15754
|
const value = preferences.status();
|
|
15567
15755
|
return {
|
|
15568
15756
|
ok: true,
|
|
15569
15757
|
value: {
|
|
15570
15758
|
availableModels: Array.isArray(value?.availableModels) ? value.availableModels : [],
|
|
15759
|
+
subagentModels: Array.isArray(value?.subagentModels) ? value.subagentModels : [],
|
|
15571
15760
|
contextModels: Array.isArray(value?.contextModels) ? value.contextModels : [],
|
|
15572
15761
|
verbosityModels: Array.isArray(value?.verbosityModels) ? value.verbosityModels : [],
|
|
15573
15762
|
fastModels: Array.isArray(value?.fastModels) ? value.fastModels : [],
|
|
@@ -15600,6 +15789,10 @@ function createSubscriptionRpcHandler({ authHandler, usageReader, accountUsageRe
|
|
|
15600
15789
|
if (!rule.choices.includes(payload[field])) return publicError("internal", rule.error);
|
|
15601
15790
|
patch[field] = payload[field];
|
|
15602
15791
|
}
|
|
15792
|
+
if (Object.hasOwn(payload ?? {}, "subagentDefaultModel")) {
|
|
15793
|
+
if (normalizeSubagentModel(payload.subagentDefaultModel) !== payload.subagentDefaultModel) return publicError("internal", "Invalid subtask model");
|
|
15794
|
+
patch.subagentDefaultModel = payload.subagentDefaultModel;
|
|
15795
|
+
}
|
|
15603
15796
|
if (Object.hasOwn(payload ?? {}, "customContextWindow")) {
|
|
15604
15797
|
if (normalizeCustomContextWindow(payload["customContextWindow"]) !== payload["customContextWindow"]) return publicError("internal", "Invalid custom context window");
|
|
15605
15798
|
patch[CUSTOM_CONTEXT_WINDOW_FIELD] = payload[CUSTOM_CONTEXT_WINDOW_FIELD];
|
|
@@ -15642,7 +15835,7 @@ function createSubscriptionRpcHandler({ authHandler, usageReader, accountUsageRe
|
|
|
15642
15835
|
"ChatGPT sign-in needs to be renewed",
|
|
15643
15836
|
REQUEST_BLOCKED
|
|
15644
15837
|
]);
|
|
15645
|
-
const message = error instanceof Error && known.has(error.message) ? error.message : "Could not read ChatGPT usage";
|
|
15838
|
+
const message = error instanceof Error && (known.has(error.message) || isAccessFailureMessage(error.message)) ? error.message : "Could not read ChatGPT usage";
|
|
15646
15839
|
return publicError("internal", message);
|
|
15647
15840
|
}
|
|
15648
15841
|
if (endpoint === "usage/profile") try {
|
|
@@ -15661,7 +15854,7 @@ function createSubscriptionRpcHandler({ authHandler, usageReader, accountUsageRe
|
|
|
15661
15854
|
"ChatGPT sign-in needs to be renewed",
|
|
15662
15855
|
REQUEST_BLOCKED
|
|
15663
15856
|
]);
|
|
15664
|
-
return publicError("internal", error instanceof Error && known.has(error.message) ? error.message : "Could not read ChatGPT usage profile");
|
|
15857
|
+
return publicError("internal", error instanceof Error && (known.has(error.message) || isAccessFailureMessage(error.message)) ? error.message : "Could not read ChatGPT usage profile");
|
|
15665
15858
|
}
|
|
15666
15859
|
if (endpoint === "usage/accounts") try {
|
|
15667
15860
|
signal.throwIfAborted();
|
|
@@ -15692,7 +15885,7 @@ function createSubscriptionRpcHandler({ authHandler, usageReader, accountUsageRe
|
|
|
15692
15885
|
"ChatGPT sign-in needs to be renewed",
|
|
15693
15886
|
REQUEST_BLOCKED
|
|
15694
15887
|
]);
|
|
15695
|
-
return publicError("internal", error instanceof Error && known.has(error.message) ? error.message : "Could not read ChatGPT usage history");
|
|
15888
|
+
return publicError("internal", error instanceof Error && (known.has(error.message) || isAccessFailureMessage(error.message)) ? error.message : "Could not read ChatGPT usage history");
|
|
15696
15889
|
}
|
|
15697
15890
|
if (endpoint === "reset-credit/inspect" || endpoint === "reset-credit/prepare" || endpoint === "reset-credit/consume") try {
|
|
15698
15891
|
signal.throwIfAborted();
|
|
@@ -15723,7 +15916,7 @@ function createSubscriptionRpcHandler({ authHandler, usageReader, accountUsageRe
|
|
|
15723
15916
|
"The signed-in ChatGPT account changed"
|
|
15724
15917
|
]);
|
|
15725
15918
|
const fallback = endpoint === "reset-credit/inspect" ? "Could not read quota reset details" : endpoint === "reset-credit/prepare" ? "Could not prepare a quota reset" : "Could not use the quota reset";
|
|
15726
|
-
const message = error instanceof Error && known.has(error.message) ? error.message : fallback;
|
|
15919
|
+
const message = error instanceof Error && (known.has(error.message) || isAccessFailureMessage(error.message)) ? error.message : fallback;
|
|
15727
15920
|
return publicError("internal", message);
|
|
15728
15921
|
}
|
|
15729
15922
|
const result = await authHandler(endpoint, payload, signal);
|
|
@@ -15738,6 +15931,7 @@ function createSubscriptionRpcHandler({ authHandler, usageReader, accountUsageRe
|
|
|
15738
15931
|
() => onAccountChanged?.()
|
|
15739
15932
|
];
|
|
15740
15933
|
if (endpoint === "logout") tasks.push(() => usageReader.clear(), () => accountUsageReader?.clear());
|
|
15934
|
+
if (endpoint === "login/status") tasks.push(() => accountUsageReader?.clear());
|
|
15741
15935
|
if (endpoint === "account/remove" && typeof payload?.id === "string") tasks.push(() => usageReader.clearScope(payload.id));
|
|
15742
15936
|
const outcomes = await Promise.allSettled(tasks.map((task) => Promise.resolve().then(task)));
|
|
15743
15937
|
const catalogOutcomes = endpoint === "logout" ? [] : await Promise.allSettled([Promise.resolve().then(() => modelCatalog?.initialize())]);
|
|
@@ -16838,7 +17032,8 @@ function createSearchProviderSwitcher(loader) {
|
|
|
16838
17032
|
return typeof configured === "string" && configured.length > 0 && !SUBSCRIPTION_SEARCH_PROVIDER_IDS.has(configured) ? configured : DSH_SEARCH_PROVIDER_FALLBACK;
|
|
16839
17033
|
};
|
|
16840
17034
|
const current = () => {
|
|
16841
|
-
const
|
|
17035
|
+
const fiber = webEntry()?.fiber;
|
|
17036
|
+
const value = (fiber?.effectiveConfig ?? fiber?.config)?.searchProvider;
|
|
16842
17037
|
return typeof value === "string" ? value : value?.get?.();
|
|
16843
17038
|
};
|
|
16844
17039
|
const writeProvider = async (provider) => {
|
|
@@ -16861,6 +17056,7 @@ function createSearchProviderSwitcher(loader) {
|
|
|
16861
17056
|
const settingsFields = {
|
|
16862
17057
|
[DISABLED_MODELS_FIELD]: z.transform(z.array(z.string()).max(100), normalizeDisabledModels).default([]),
|
|
16863
17058
|
[AUTO_QUOTA_RETRY_FIELD]: z.boolean().default(false),
|
|
17059
|
+
subagentDefaultModel: z.transform(z.string().max(80), normalizeSubagentModel).default(""),
|
|
16864
17060
|
...Object.fromEntries(Object.entries(PREFERENCE_FIELDS).map(([field, rule]) => [field, rule.default === void 0 ? z.union(rule.choices) : z.union(rule.choices).default(rule.default)])),
|
|
16865
17061
|
imageModel: z.union(Object.keys(IMAGE_MODELS)).default(DEFAULT_IMAGE_MODEL),
|
|
16866
17062
|
imageQuality: z.union([
|
|
@@ -16932,6 +17128,20 @@ function apply(ctx, config = {}) {
|
|
|
16932
17128
|
]
|
|
16933
17129
|
});
|
|
16934
17130
|
const appendUltraPolicy = loadHostSessionSdk()?.appendPluginRecord;
|
|
17131
|
+
const subagentCatalog = createOfficialModelCatalog({
|
|
17132
|
+
nativeVersion: SUBAGENT_CODEX_VERSION,
|
|
17133
|
+
getAuth: (options) => resolveAuth(options),
|
|
17134
|
+
readCredential: (options) => store.read(PROVIDER, options),
|
|
17135
|
+
baseModels: () => baseProvider.getModels(),
|
|
17136
|
+
fetch: (input, init) => network.fetch("catalog", input, init)
|
|
17137
|
+
});
|
|
17138
|
+
ctx.effect(() => () => subagentCatalog.clear());
|
|
17139
|
+
const subagentDefaults = createSubagentDefaults({
|
|
17140
|
+
readSettings: settings.get,
|
|
17141
|
+
catalog: subagentCatalog,
|
|
17142
|
+
modelSelection: () => ctx.get?.("subagentModelSelection")?.current(),
|
|
17143
|
+
projections: () => ctx.get?.("sessionProjections")
|
|
17144
|
+
});
|
|
16935
17145
|
const ultra = createUltraExecutionPreset({
|
|
16936
17146
|
catalog: modelCatalog,
|
|
16937
17147
|
resolveAgent: () => ctx.get?.("agents")?.currentInitiator?.(),
|
|
@@ -17005,6 +17215,9 @@ function apply(ctx, config = {}) {
|
|
|
17005
17215
|
composerPredictions: settings.get().composerPredictions === "on" ? "on" : "off",
|
|
17006
17216
|
otherModels: settings.get().otherModels === "off" ? "off" : "on",
|
|
17007
17217
|
subagentBackend: settings.get().subagentBackend ?? "dsh",
|
|
17218
|
+
subagentDefaultModel: normalizeSubagentModel(settings.get().subagentDefaultModel),
|
|
17219
|
+
subagentDefaultEffort: normalizeSubagentEffort(settings.get().subagentDefaultEffort),
|
|
17220
|
+
subagentModels: subagentDefaults.list(),
|
|
17008
17221
|
subagentBackendAvailable: subagentBackend !== void 0,
|
|
17009
17222
|
subagentRuntimeInstalled: inspectSubagentRuntime().installed,
|
|
17010
17223
|
...readCapabilitySettings(settings.get()),
|
|
@@ -17039,10 +17252,12 @@ function apply(ctx, config = {}) {
|
|
|
17039
17252
|
};
|
|
17040
17253
|
},
|
|
17041
17254
|
update: async (patch) => {
|
|
17255
|
+
if (patch.subagentDefaultModel && !subagentDefaults.list().some((model) => model.id === patch.subagentDefaultModel)) throw new Error("Codex subtask model is unavailable or disallowed");
|
|
17042
17256
|
if (patch["fetchProvider"] === "codex" && !fetchRouted) throw new Error("This DSH version does not support Codex webpage reading");
|
|
17043
17257
|
if (Object.hasOwn(patch, "subagentBackend")) {
|
|
17044
17258
|
if (!subagentBackend) throw new Error("DSH subagent services are unavailable");
|
|
17045
17259
|
await subagentBackend.select(patch.subagentBackend);
|
|
17260
|
+
if (patch.subagentBackend === "codex") await subagentCatalog.refresh().catch(() => {});
|
|
17046
17261
|
}
|
|
17047
17262
|
const rest = { ...patch };
|
|
17048
17263
|
delete rest.subagentBackend;
|
|
@@ -17104,7 +17319,8 @@ function apply(ctx, config = {}) {
|
|
|
17104
17319
|
store,
|
|
17105
17320
|
refresh: (credential) => network.run("oauth", () => baseProvider.auth.oauth.refresh(credential)),
|
|
17106
17321
|
loadRuntime: loadSubagentRuntime,
|
|
17107
|
-
maintenance: runtimeManagement.blocked
|
|
17322
|
+
maintenance: runtimeManagement.blocked,
|
|
17323
|
+
defaults: subagentDefaults
|
|
17108
17324
|
});
|
|
17109
17325
|
scoped.subagents.registerProvider(instance.provider);
|
|
17110
17326
|
const switcher = createSubagentBackendSwitcher({
|
|
@@ -17547,7 +17763,7 @@ function apply(ctx, config = {}) {
|
|
|
17547
17763
|
}, next).finally(() => activeQuotaRetries.delete(tracked));
|
|
17548
17764
|
activeQuotaRetries.add(tracked);
|
|
17549
17765
|
return tracked;
|
|
17550
|
-
});
|
|
17766
|
+
}, true);
|
|
17551
17767
|
ctx.effect(() => async () => {
|
|
17552
17768
|
disposeQuotaRetry();
|
|
17553
17769
|
quotaRetryLifetime.abort(/* @__PURE__ */ new Error("codex-subscription quota retry disposed"));
|
|
@@ -17649,6 +17865,7 @@ function apply(ctx, config = {}) {
|
|
|
17649
17865
|
voicePreview,
|
|
17650
17866
|
composerPredictions,
|
|
17651
17867
|
onAccountChanged: () => {
|
|
17868
|
+
subagentCatalog.clear();
|
|
17652
17869
|
connectorsClient.clear();
|
|
17653
17870
|
usageProfileReader.clear();
|
|
17654
17871
|
voicePreview.clear();
|
|
@@ -17671,6 +17888,7 @@ function apply(ctx, config = {}) {
|
|
|
17671
17888
|
}),
|
|
17672
17889
|
onCleanupFailure: () => diagnosticOperations.record("account/cleanup", "failed"),
|
|
17673
17890
|
modelCatalog,
|
|
17891
|
+
subagentCatalog,
|
|
17674
17892
|
closeConnections: () => connection.dispose(),
|
|
17675
17893
|
originalImages,
|
|
17676
17894
|
resolveInheritedOriginal: (sessionId, assetId) => inheritedOriginalImageRef(ctx.get?.("sessions")?.get?.(sessionId), assetId)
|