dsh-codex-subscription 2.5.5 → 2.5.7
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 -6
- package/README.md +7 -6
- package/lib/client.js +109 -194
- package/lib/index.js +126 -40
- package/package.json +1 -2
- package/lib/sketch-psd-worker.js +0 -11
package/lib/index.js
CHANGED
|
@@ -424,6 +424,11 @@ const PREFERENCE_FIELDS = Object.freeze({
|
|
|
424
424
|
default: "sse",
|
|
425
425
|
error: "Invalid connection mode"
|
|
426
426
|
},
|
|
427
|
+
reviewModel: {
|
|
428
|
+
choices: ["session", "official"],
|
|
429
|
+
default: "session",
|
|
430
|
+
error: "Invalid review model"
|
|
431
|
+
},
|
|
427
432
|
subagentBackend: {
|
|
428
433
|
choices: ["dsh", "codex"],
|
|
429
434
|
default: "dsh",
|
|
@@ -2044,7 +2049,7 @@ function inheritedOriginalImageRef(session, assetId) {
|
|
|
2044
2049
|
}
|
|
2045
2050
|
//#endregion
|
|
2046
2051
|
//#region src/version.js
|
|
2047
|
-
const PACKAGE_VERSION = "2.5.
|
|
2052
|
+
const PACKAGE_VERSION = "2.5.7";
|
|
2048
2053
|
const USER_AGENT = `dsh-codex-subscription/${PACKAGE_VERSION}`;
|
|
2049
2054
|
//#endregion
|
|
2050
2055
|
//#region src/codex-images.js
|
|
@@ -2672,23 +2677,6 @@ function createSketchAgentTool(bridge, attachments, getSessionMessages = () => [
|
|
|
2672
2677
|
});
|
|
2673
2678
|
}
|
|
2674
2679
|
//#endregion
|
|
2675
|
-
//#region src/sketch-codec-route.js
|
|
2676
|
-
function registerSketchCodec(connection) {
|
|
2677
|
-
let source;
|
|
2678
|
-
return connection.fetch.register({
|
|
2679
|
-
path: "/api/codex-subscription/sketch-psd-worker",
|
|
2680
|
-
methods: ["GET"],
|
|
2681
|
-
requestBody: "buffered",
|
|
2682
|
-
async fetch() {
|
|
2683
|
-
source ??= await readFile(new URL("./sketch-psd-worker.js", import.meta.url));
|
|
2684
|
-
return new Response(source, { headers: {
|
|
2685
|
-
"content-type": "text/javascript; charset=utf-8",
|
|
2686
|
-
"cache-control": "no-store"
|
|
2687
|
-
} });
|
|
2688
|
-
}
|
|
2689
|
-
});
|
|
2690
|
-
}
|
|
2691
|
-
//#endregion
|
|
2692
2680
|
//#region src/account-vault.js
|
|
2693
2681
|
const VERSION = 1;
|
|
2694
2682
|
const DEFAULT_LABEL = "Account 1";
|
|
@@ -3600,6 +3588,20 @@ function withInputImageDetail(payload, detail) {
|
|
|
3600
3588
|
input
|
|
3601
3589
|
} : payload;
|
|
3602
3590
|
}
|
|
3591
|
+
const DSH_REVIEW_POLICY_PREFIX = "REVIEW_POLICY\nYou are the final authorization reviewer";
|
|
3592
|
+
const REVIEW_MODEL_SESSION = "session";
|
|
3593
|
+
const REVIEW_RETRIES = 2;
|
|
3594
|
+
const TRANSIENT_REVIEW_FAILURE = /stream ended (?:before|without)|\b(?:network|connection|socket)\b|\bECONN[A-Z]+\b|other side closed|premature close|\bterminated\b|WebSocket closed (?:1006|1011|1012|1013)/iu;
|
|
3595
|
+
function systemText(context) {
|
|
3596
|
+
if (typeof context?.systemPrompt === "string") return context.systemPrompt;
|
|
3597
|
+
const first = Array.isArray(context?.messages) ? context.messages[0] : void 0;
|
|
3598
|
+
if (first?.role !== "system") return "";
|
|
3599
|
+
return typeof first.content === "string" ? first.content : Array.isArray(first.content) ? first.content.map((part) => part?.text ?? "").join("") : "";
|
|
3600
|
+
}
|
|
3601
|
+
/** Whether this request is DSH Auto review judging one pending tool call. */
|
|
3602
|
+
function isDshAutoReview(context) {
|
|
3603
|
+
return systemText(context).startsWith(DSH_REVIEW_POLICY_PREFIX);
|
|
3604
|
+
}
|
|
3603
3605
|
/**
|
|
3604
3606
|
* Preserve pi-ai's native Codex OAuth provider while allowing DSH's generic
|
|
3605
3607
|
* PiAiAdapter to pass the access token resolved by the host credential store.
|
|
@@ -3612,7 +3614,7 @@ function withInputImageDetail(payload, detail) {
|
|
|
3612
3614
|
* persistence, headers, transport, and model behavior remain owned by the
|
|
3613
3615
|
* original provider.
|
|
3614
3616
|
*/
|
|
3615
|
-
function openaiCodexSubscriptionProvider({ resolveSpeedMode = () => void 0, resolveOutputVerbosity = () => OUTPUT_VERBOSITY_DEFAULT, resolveInputImageDetail = () => void 0, resolveContextMode = () => void 0, resolveCustomContextWindow = () => void 0, catalog, connection, compaction, runNetwork = (_area, operation) => operation() } = {}) {
|
|
3617
|
+
function openaiCodexSubscriptionProvider({ resolveSpeedMode = () => void 0, resolveOutputVerbosity = () => OUTPUT_VERBOSITY_DEFAULT, resolveInputImageDetail = () => void 0, resolveContextMode = () => void 0, resolveCustomContextWindow = () => void 0, resolveReviewModel = () => REVIEW_MODEL_SESSION, catalog, connection, compaction, runNetwork = (_area, operation) => operation() } = {}) {
|
|
3616
3618
|
const provider = createOpenAICodexProvider();
|
|
3617
3619
|
const requestToken = Object.freeze({
|
|
3618
3620
|
name: "DSH-managed Codex OAuth request token",
|
|
@@ -3680,18 +3682,77 @@ function openaiCodexSubscriptionProvider({ resolveSpeedMode = () => void 0, reso
|
|
|
3680
3682
|
contextWindow: requested
|
|
3681
3683
|
};
|
|
3682
3684
|
});
|
|
3683
|
-
const
|
|
3685
|
+
const review = {
|
|
3686
|
+
requests: 0,
|
|
3687
|
+
routed: 0,
|
|
3688
|
+
sessionModel: 0,
|
|
3689
|
+
retries: 0
|
|
3690
|
+
};
|
|
3691
|
+
const reviewRoute = (model, context) => {
|
|
3692
|
+
if (resolveReviewModel() !== "official" || !isDshAutoReview(context)) return void 0;
|
|
3693
|
+
review.requests += 1;
|
|
3694
|
+
const route = catalog?.reviewModel?.(model?.id);
|
|
3695
|
+
if (route === void 0) review.sessionModel += 1;
|
|
3696
|
+
else review.routed += 1;
|
|
3697
|
+
return route;
|
|
3698
|
+
};
|
|
3699
|
+
const withReview = (route, options = {}) => {
|
|
3700
|
+
const { temperature: _temperature, onPayload, ...rest } = options;
|
|
3701
|
+
return {
|
|
3702
|
+
...rest,
|
|
3703
|
+
async onPayload(payload, requestModel) {
|
|
3704
|
+
const { temperature: _dropped, service_tier: _tier, text: _text, ...accepted } = await onPayload?.(payload, requestModel) ?? payload;
|
|
3705
|
+
return {
|
|
3706
|
+
...accepted,
|
|
3707
|
+
model: route.id,
|
|
3708
|
+
...route.effort === void 0 ? {} : { reasoning: {
|
|
3709
|
+
...accepted.reasoning ?? {},
|
|
3710
|
+
effort: route.effort
|
|
3711
|
+
} }
|
|
3712
|
+
};
|
|
3713
|
+
}
|
|
3714
|
+
};
|
|
3715
|
+
};
|
|
3716
|
+
const reviewIterable = (create) => {
|
|
3717
|
+
let replay;
|
|
3718
|
+
const run = async function* () {
|
|
3719
|
+
for (let attempt = 0;; attempt += 1) {
|
|
3720
|
+
const events = [];
|
|
3721
|
+
let failure;
|
|
3722
|
+
let thrown;
|
|
3723
|
+
try {
|
|
3724
|
+
for await (const event of create()) {
|
|
3725
|
+
events.push(event);
|
|
3726
|
+
if (event?.type === "error") failure = event.error?.errorMessage;
|
|
3727
|
+
}
|
|
3728
|
+
} catch (error) {
|
|
3729
|
+
thrown = error;
|
|
3730
|
+
failure = error?.message;
|
|
3731
|
+
}
|
|
3732
|
+
if (failure !== void 0 && attempt < REVIEW_RETRIES && TRANSIENT_REVIEW_FAILURE.test(failure)) {
|
|
3733
|
+
review.retries += 1;
|
|
3734
|
+
continue;
|
|
3735
|
+
}
|
|
3736
|
+
if (thrown !== void 0 && events.length === 0) throw thrown;
|
|
3737
|
+
yield* events;
|
|
3738
|
+
if (thrown !== void 0) throw thrown;
|
|
3739
|
+
return;
|
|
3740
|
+
}
|
|
3741
|
+
};
|
|
3742
|
+
return { [Symbol.asyncIterator]: () => replay ??= run() };
|
|
3743
|
+
};
|
|
3744
|
+
const networkIterable = (factory, options, direct = false) => {
|
|
3684
3745
|
let iterator;
|
|
3685
3746
|
let prepared;
|
|
3686
3747
|
const step = async (method, value) => {
|
|
3687
|
-
const request = await (prepared ??= connection?.prepare(options) ?? Promise.resolve({ options }));
|
|
3748
|
+
const request = await (prepared ??= (direct ? void 0 : connection?.prepare(options)) ?? Promise.resolve({ options }));
|
|
3688
3749
|
const result = await runNetwork("model", () => {
|
|
3689
|
-
iterator ??= factory(compaction?.requestOptions(request.options) ?? request.options)[Symbol.asyncIterator]();
|
|
3750
|
+
iterator ??= factory(direct ? request.options : compaction?.requestOptions(request.options) ?? request.options)[Symbol.asyncIterator]();
|
|
3690
3751
|
return iterator[method]?.(value) ?? (method === "throw" ? Promise.reject(value) : Promise.resolve({
|
|
3691
3752
|
done: true,
|
|
3692
3753
|
value
|
|
3693
3754
|
}));
|
|
3694
|
-
}, compaction?.networkOptions(request.network) ?? request.network);
|
|
3755
|
+
}, direct ? request.network : compaction?.networkOptions(request.network) ?? request.network);
|
|
3695
3756
|
return result.done ? result : {
|
|
3696
3757
|
...result,
|
|
3697
3758
|
value: normalizeTransportEvent(result.value, request.options?.signal)
|
|
@@ -3709,6 +3770,11 @@ function openaiCodexSubscriptionProvider({ resolveSpeedMode = () => void 0, reso
|
|
|
3709
3770
|
throw: (error) => iterator ? step("throw", error) : Promise.reject(error)
|
|
3710
3771
|
};
|
|
3711
3772
|
};
|
|
3773
|
+
const routed = (method, model, context, options) => {
|
|
3774
|
+
const route = reviewRoute(model, context);
|
|
3775
|
+
const create = () => route === void 0 ? networkIterable((prepared) => provider[method](model, context, prepared), withPreferences(model, options)) : networkIterable((prepared) => provider[method](model, context, prepared), withReview(route, options), true);
|
|
3776
|
+
return isDshAutoReview(context) ? reviewIterable(create) : create();
|
|
3777
|
+
};
|
|
3712
3778
|
return Object.freeze({
|
|
3713
3779
|
...provider,
|
|
3714
3780
|
auth: Object.freeze({
|
|
@@ -3716,8 +3782,9 @@ function openaiCodexSubscriptionProvider({ resolveSpeedMode = () => void 0, reso
|
|
|
3716
3782
|
apiKey: requestToken
|
|
3717
3783
|
}),
|
|
3718
3784
|
getModels,
|
|
3719
|
-
stream: (model, context, options) =>
|
|
3720
|
-
streamSimple: (model, context, options) =>
|
|
3785
|
+
stream: (model, context, options) => routed("stream", model, context, options),
|
|
3786
|
+
streamSimple: (model, context, options) => routed("streamSimple", model, context, options),
|
|
3787
|
+
reviewCounters: () => ({ ...review })
|
|
3721
3788
|
});
|
|
3722
3789
|
}
|
|
3723
3790
|
Object.freeze([
|
|
@@ -3844,6 +3911,23 @@ function visibleModel(value, displayNames, now) {
|
|
|
3844
3911
|
supportsUltrafast: speedTierIds(value).includes("ultrafast")
|
|
3845
3912
|
};
|
|
3846
3913
|
}
|
|
3914
|
+
/**
|
|
3915
|
+
* Mirror Codex's reviewer selection: a parent model's override, else the
|
|
3916
|
+
* default reviewer, used only when the account catalog lists that slug (any
|
|
3917
|
+
* visibility), with low reasoning when the reviewer supports it.
|
|
3918
|
+
*/
|
|
3919
|
+
function officialReviewModel(value, parentId) {
|
|
3920
|
+
if (!record$3(value) || !Array.isArray(value.models)) return void 0;
|
|
3921
|
+
const parent = value.models.find((model) => record$3(model) && model.slug === parentId);
|
|
3922
|
+
const id = nonEmpty$1(parent?.auto_review_model_override) ?? "codex-auto-review";
|
|
3923
|
+
const preset = value.models.find((model) => record$3(model) && model.slug === id);
|
|
3924
|
+
if (preset === void 0) return void 0;
|
|
3925
|
+
const effort = (Array.isArray(preset.supported_reasoning_levels) ? preset.supported_reasoning_levels : []).some((level) => (record$3(level) ? level.effort : level) === "low") ? "low" : nonEmpty$1(preset.default_reasoning_level);
|
|
3926
|
+
return {
|
|
3927
|
+
id,
|
|
3928
|
+
...effort === void 0 ? {} : { effort }
|
|
3929
|
+
};
|
|
3930
|
+
}
|
|
3847
3931
|
function parseOfficialModelCatalog(value, now = Date.now()) {
|
|
3848
3932
|
if (!record$3(value) || !Array.isArray(value.models)) throw new Error("Codex returned a malformed model catalog");
|
|
3849
3933
|
const displayNames = /* @__PURE__ */ new Map();
|
|
@@ -3985,6 +4069,7 @@ function createOfficialModelCatalog(options = {}) {
|
|
|
3985
4069
|
refresh,
|
|
3986
4070
|
getModels: () => models ?? [],
|
|
3987
4071
|
metadata: (modelId) => metadata.get(modelId),
|
|
4072
|
+
reviewModel: (parentId) => officialReviewModel(rawCatalog, parentId),
|
|
3988
4073
|
revision: () => revision,
|
|
3989
4074
|
capabilityGaps: () => [...metadata.values()].filter((model) => model.unsupported && /^[a-z][a-z0-9._-]{0,79}$/u.test(model.id)).slice(0, 20).map((model) => ({
|
|
3990
4075
|
model: model.id,
|
|
@@ -4644,7 +4729,7 @@ function safeRequests(network) {
|
|
|
4644
4729
|
return result;
|
|
4645
4730
|
}
|
|
4646
4731
|
/** Build a support report that deliberately excludes OAuth and account metadata. */
|
|
4647
|
-
async function createSubscriptionDiagnostics({ auth, preferences, login = { phase: "idle" }, network, modelCatalog, connection, compaction, inspectionOptions, operations, runtimeManagement, storage, tools }) {
|
|
4732
|
+
async function createSubscriptionDiagnostics({ auth, preferences, login = { phase: "idle" }, network, modelCatalog, connection, compaction, review, inspectionOptions, operations, runtimeManagement, storage, tools }) {
|
|
4648
4733
|
const collected = {};
|
|
4649
4734
|
const checks = await collectChecks([
|
|
4650
4735
|
[
|
|
@@ -4698,6 +4783,16 @@ async function createSubscriptionDiagnostics({ auth, preferences, login = { phas
|
|
|
4698
4783
|
"checkpointsReused"
|
|
4699
4784
|
]) : void 0
|
|
4700
4785
|
],
|
|
4786
|
+
[
|
|
4787
|
+
"review",
|
|
4788
|
+
"transport",
|
|
4789
|
+
() => typeof review?.reviewCounters === "function" ? safeCounters({ snapshot: () => review.reviewCounters() }, [
|
|
4790
|
+
"requests",
|
|
4791
|
+
"routed",
|
|
4792
|
+
"sessionModel",
|
|
4793
|
+
"retries"
|
|
4794
|
+
]) : void 0
|
|
4795
|
+
],
|
|
4701
4796
|
[
|
|
4702
4797
|
"operations",
|
|
4703
4798
|
"transport",
|
|
@@ -4800,6 +4895,7 @@ async function createSubscriptionDiagnostics({ auth, preferences, login = { phas
|
|
|
4800
4895
|
...collected.operations ? { operations: collected.operations } : {},
|
|
4801
4896
|
...collected.websocket ? { websocket: collected.websocket } : {},
|
|
4802
4897
|
...collected.compaction ? { compaction: collected.compaction } : {},
|
|
4898
|
+
...collected.review ? { review: collected.review } : {},
|
|
4803
4899
|
...catalog && ["unavailable", "online"].includes(catalog.source) && [
|
|
4804
4900
|
"idle",
|
|
4805
4901
|
"refreshing",
|
|
@@ -6295,6 +6391,7 @@ function apply(ctx, config = {}) {
|
|
|
6295
6391
|
if (field === void 0) return void 0;
|
|
6296
6392
|
return normalizeCustomContextWindow(settings.get()[field] ?? CUSTOM_CONTEXT_MODEL_DEFAULTS[modelKey], CUSTOM_CONTEXT_MODEL_CAPS[modelKey]);
|
|
6297
6393
|
},
|
|
6394
|
+
resolveReviewModel: () => settings.get().reviewModel,
|
|
6298
6395
|
catalog: modelCatalog,
|
|
6299
6396
|
runNetwork: network.run
|
|
6300
6397
|
});
|
|
@@ -6306,6 +6403,7 @@ function apply(ctx, config = {}) {
|
|
|
6306
6403
|
[AUTO_QUOTA_RETRY_FIELD]: normalizeAutoQuotaRetry(settings.get()[AUTO_QUOTA_RETRY_FIELD]),
|
|
6307
6404
|
compactionMode: settings.get().compactionMode ?? "dsh",
|
|
6308
6405
|
connectionMode: settings.get().connectionMode ?? "sse",
|
|
6406
|
+
reviewModel: settings.get().reviewModel ?? "session",
|
|
6309
6407
|
subagentBackend: settings.get().subagentBackend ?? "dsh",
|
|
6310
6408
|
subagentBackendAvailable: subagentBackend !== void 0,
|
|
6311
6409
|
subagentRuntimeInstalled: inspectSubagentRuntime().installed,
|
|
@@ -6593,6 +6691,7 @@ function apply(ctx, config = {}) {
|
|
|
6593
6691
|
modelCatalog,
|
|
6594
6692
|
connection,
|
|
6595
6693
|
compaction,
|
|
6694
|
+
review: provider,
|
|
6596
6695
|
operations: diagnosticOperations,
|
|
6597
6696
|
runtimeManagement,
|
|
6598
6697
|
storage: () => usageReader.storage(),
|
|
@@ -6608,20 +6707,7 @@ function apply(ctx, config = {}) {
|
|
|
6608
6707
|
ctx.effect(() => {
|
|
6609
6708
|
modelCatalog.refresh().catch((error) => ctx.logger?.debug?.("could not refresh Codex model catalog: %s", error.message));
|
|
6610
6709
|
}, "codex-subscription: official model catalog");
|
|
6611
|
-
ctx.inject(["connection"], (connectionContext) => connectionContext.effect(() =>
|
|
6612
|
-
const transport = registerSubscriptionTransport(connectionContext.connection, handler);
|
|
6613
|
-
let codec;
|
|
6614
|
-
try {
|
|
6615
|
-
codec = registerSketchCodec(connectionContext.connection);
|
|
6616
|
-
} catch (error) {
|
|
6617
|
-
transport();
|
|
6618
|
-
throw error;
|
|
6619
|
-
}
|
|
6620
|
-
return () => {
|
|
6621
|
-
codec();
|
|
6622
|
-
transport();
|
|
6623
|
-
};
|
|
6624
|
-
}, "codex-subscription: DSH-trusted account RPC"));
|
|
6710
|
+
ctx.inject(["connection"], (connectionContext) => connectionContext.effect(() => registerSubscriptionTransport(connectionContext.connection, handler), "codex-subscription: DSH-trusted account RPC"));
|
|
6625
6711
|
}
|
|
6626
6712
|
//#endregion
|
|
6627
6713
|
export { CODEX_IMAGE_GENERATION_URL, CODEX_IMAGE_TOOL_NAME, CODEX_RESET_CONSUME_URL, CODEX_RESET_CREDITS_URL, CODEX_USAGE_URL, CodexLoginCoordinator, Config, DEFAULT_MODEL_PROVIDER, DshOAuthCredentialStore, apply, assertCodexAuthUrl, commandForCodexAuthUrl, createCodexAuthService, createCodexImageTool, createCodexResetCreditService, createCodexRpcHandler, createCodexUsageReader, createDefaultModelController, createSearchProviderSwitcher, createSubscriptionDiagnostics, createSubscriptionRpcHandler, decodeCodexPng, inject, name, normalizeContextMode, normalizeCustomContextWindow, openCodexAuthUrl, parseCodexUsage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-codex-subscription",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.7",
|
|
4
4
|
"description": "Use ChatGPT and Codex subscriptions in DeepSeek Harness with OAuth, quota, safe resets, web search, images, and Fast mode",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -121,7 +121,6 @@
|
|
|
121
121
|
"@deepseek-ai/schemastery": "3.18.4",
|
|
122
122
|
"@earendil-works/pi-ai": "0.85.1",
|
|
123
123
|
"@heroicons/react": "2.2.0",
|
|
124
|
-
"ag-psd": "31.0.2",
|
|
125
124
|
"fake-indexeddb": "6.2.5",
|
|
126
125
|
"react": "18.3.1",
|
|
127
126
|
"react-dom": "18.3.1",
|