dsh-codex-subscription 3.2.0 → 3.2.1
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 +14 -7
- package/README.md +13 -6
- package/lib/client.js +315 -378
- package/lib/client.sketch.js +1 -0
- package/lib/index.js +67 -24
- package/package.json +1 -1
package/lib/client.sketch.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -194,7 +194,13 @@ function normalizeDefaultSelection(value) {
|
|
|
194
194
|
* @param resolveService - reads the optional DSH `agentDefaultModel` service.
|
|
195
195
|
* @param listModels - optional account catalog used to reject unknown models.
|
|
196
196
|
*/
|
|
197
|
-
function createDefaultModelController({ resolveService, listModels } = {}) {
|
|
197
|
+
function createDefaultModelController({ resolveService, resolveEditor, listModels } = {}) {
|
|
198
|
+
let writes = Promise.resolve();
|
|
199
|
+
const enqueue = (operation) => {
|
|
200
|
+
const result = writes.then(operation);
|
|
201
|
+
writes = result.catch(() => {});
|
|
202
|
+
return result;
|
|
203
|
+
};
|
|
198
204
|
const service = () => {
|
|
199
205
|
try {
|
|
200
206
|
return resolveService?.();
|
|
@@ -211,11 +217,25 @@ function createDefaultModelController({ resolveService, listModels } = {}) {
|
|
|
211
217
|
return;
|
|
212
218
|
}
|
|
213
219
|
};
|
|
220
|
+
const resetTarget = () => {
|
|
221
|
+
try {
|
|
222
|
+
const editor = resolveEditor?.();
|
|
223
|
+
if (typeof editor?.entries !== "function" || typeof editor.edit !== "function" || typeof editor.configuration !== "function") return void 0;
|
|
224
|
+
const entries = editor.entries().filter((entry) => entry.options?.name === "@deepseek-ai/dsh-agent-default-model");
|
|
225
|
+
return entries.length === 1 ? {
|
|
226
|
+
editor,
|
|
227
|
+
entry: entries[0]
|
|
228
|
+
} : void 0;
|
|
229
|
+
} catch {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
214
233
|
const status = () => {
|
|
215
234
|
const selection = read();
|
|
216
235
|
return {
|
|
217
236
|
available: selection !== void 0,
|
|
218
237
|
managed: selection?.provider === "openai-codex" && selection.model !== void 0,
|
|
238
|
+
...selection !== void 0 && resetTarget() ? { resetAvailable: true } : {},
|
|
219
239
|
...selection
|
|
220
240
|
};
|
|
221
241
|
};
|
|
@@ -224,22 +244,34 @@ function createDefaultModelController({ resolveService, listModels } = {}) {
|
|
|
224
244
|
if (!validDefaultModelId(model)) throw new DefaultModelError("invalid-model", "Invalid default model");
|
|
225
245
|
const catalog = typeof listModels === "function" ? listModels() : void 0;
|
|
226
246
|
if (Array.isArray(catalog) && catalog.length > 0 && !catalog.includes(model)) throw new DefaultModelError("invalid-model", "Invalid default model");
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
247
|
+
return enqueue(async () => {
|
|
248
|
+
const current = service();
|
|
249
|
+
if (current === void 0 || typeof current.saveSelection !== "function") throw new DefaultModelError("unavailable", "This DSH deployment cannot save a default model");
|
|
250
|
+
const previous = read();
|
|
251
|
+
const reasoningEffort = previous?.provider === "openai-codex" && previous.model === model ? previous.reasoningEffort : void 0;
|
|
252
|
+
await current.saveSelection({
|
|
253
|
+
provider: DEFAULT_MODEL_PROVIDER,
|
|
254
|
+
model,
|
|
255
|
+
...reasoningEffort === void 0 ? {} : { reasoningEffort }
|
|
256
|
+
});
|
|
257
|
+
const applied = read();
|
|
258
|
+
if (applied?.provider !== "openai-codex" || applied.model !== model) throw new DefaultModelError("unavailable", "The default model could not be saved");
|
|
259
|
+
return status();
|
|
235
260
|
});
|
|
236
|
-
const applied = read();
|
|
237
|
-
if (applied?.provider !== "openai-codex" || applied.model !== model) throw new DefaultModelError("unavailable", "The default model could not be saved");
|
|
238
|
-
return status();
|
|
239
261
|
};
|
|
262
|
+
const reset = () => enqueue(async () => {
|
|
263
|
+
const target = resetTarget();
|
|
264
|
+
if (!target || read() === void 0) throw new DefaultModelError("unavailable", "This DSH deployment cannot restore its default model");
|
|
265
|
+
await target.editor.edit(target.entry, (_current, inherited) => inherited);
|
|
266
|
+
const active = resetTarget();
|
|
267
|
+
const row = active?.editor.configuration().find((item) => item.entry === active.entry);
|
|
268
|
+
if (!row || Object.keys(row.override).length !== 0 || read() === void 0) throw new DefaultModelError("unavailable", "The DSH default model could not be restored");
|
|
269
|
+
return status();
|
|
270
|
+
});
|
|
240
271
|
return Object.freeze({
|
|
241
272
|
status,
|
|
242
|
-
select
|
|
273
|
+
select,
|
|
274
|
+
reset
|
|
243
275
|
});
|
|
244
276
|
}
|
|
245
277
|
//#endregion
|
|
@@ -1786,6 +1818,7 @@ function normalizeTransportEvent(event, signal) {
|
|
|
1786
1818
|
}
|
|
1787
1819
|
//#endregion
|
|
1788
1820
|
//#region src/model-retry-hint.js
|
|
1821
|
+
const CODEX_OVERLOADED = /^\s*(?:Codex error:\s*)?Our servers are currently overloaded\. Please try again later\.\s*$/u;
|
|
1789
1822
|
/** Keep the provider's wait as a fact; only DSH decides whether and when to retry. */
|
|
1790
1823
|
function providerRetryAfterMs(headers, at = Date.now()) {
|
|
1791
1824
|
const read = (key) => typeof headers?.get === "function" ? headers.get(key) : headers?.[key];
|
|
@@ -1800,9 +1833,10 @@ function providerRetryAfterMs(headers, at = Date.now()) {
|
|
|
1800
1833
|
return Number.isFinite(value) && value > 0 ? Math.min(value, Number.MAX_SAFE_INTEGER) : void 0;
|
|
1801
1834
|
}
|
|
1802
1835
|
function createModelRetryHint({ now = Date.now, ErrorClass = dshLlm.LlmError } = {}) {
|
|
1803
|
-
let response, outputStarted = false;
|
|
1836
|
+
let response, responseStatus, outputStarted = false;
|
|
1804
1837
|
return {
|
|
1805
1838
|
onResponse(info) {
|
|
1839
|
+
responseStatus = info?.status;
|
|
1806
1840
|
response = [429, 503].includes(info?.status) ? {
|
|
1807
1841
|
status: info.status,
|
|
1808
1842
|
delay: providerRetryAfterMs(info.headers, now())
|
|
@@ -1816,23 +1850,29 @@ function createModelRetryHint({ now = Date.now, ErrorClass = dshLlm.LlmError } =
|
|
|
1816
1850
|
].includes(event.type)) outputStarted = true;
|
|
1817
1851
|
},
|
|
1818
1852
|
failure(original, signal) {
|
|
1819
|
-
if (signal?.aborted || outputStarted || !
|
|
1853
|
+
if (signal?.aborted || outputStarted || !original || typeof original.message !== "string" || [
|
|
1820
1854
|
"ABORTED",
|
|
1855
|
+
"AUTH",
|
|
1856
|
+
"INVALID_REQUEST",
|
|
1821
1857
|
"QUOTA",
|
|
1822
1858
|
"ACCOUNT_QUOTA",
|
|
1823
1859
|
"QUOTA_EXCEEDED"
|
|
1824
1860
|
].includes(original.code) || typeof dshLlm.isQuotaExceededError === "function" && dshLlm.isQuotaExceededError(original.message)) return original;
|
|
1825
|
-
|
|
1861
|
+
const status = responseStatus ?? original.status;
|
|
1862
|
+
const overloaded = original.code === "PI_AI_ERROR" && CODEX_OVERLOADED.test(original.message) && (status === void 0 || status >= 200 && status < 300);
|
|
1863
|
+
if (!response && !overloaded) return original;
|
|
1864
|
+
if (/You have hit your ChatGPT usage limit/iu.test(original.message) || response?.status === 429 && original.code !== "RATE_LIMIT") return original;
|
|
1865
|
+
const code = response?.status === 429 ? "RATE_LIMIT" : "SERVER";
|
|
1826
1866
|
let error;
|
|
1827
1867
|
try {
|
|
1828
|
-
error = new ErrorClass(original.message, response
|
|
1868
|
+
error = new ErrorClass(original.message, code, response ? {
|
|
1829
1869
|
status: response.status,
|
|
1830
1870
|
...response.delay === void 0 ? {} : { providerRetryAfterMs: response.delay }
|
|
1831
|
-
});
|
|
1871
|
+
} : {});
|
|
1832
1872
|
} catch {
|
|
1833
1873
|
return original;
|
|
1834
1874
|
}
|
|
1835
|
-
return error.failure?.status === response.status && (response.delay === void 0 || error.failure.providerRetryAfterMs === response.delay) ? {
|
|
1875
|
+
return error.failure?.code === code && (!response || error.failure.status === response.status && (response.delay === void 0 || error.failure.providerRetryAfterMs === response.delay)) ? {
|
|
1836
1876
|
...original,
|
|
1837
1877
|
...error.failure
|
|
1838
1878
|
} : original;
|
|
@@ -2617,6 +2657,7 @@ const RPC_ENDPOINTS = Object.freeze([
|
|
|
2617
2657
|
"preferences/update",
|
|
2618
2658
|
"default-model/status",
|
|
2619
2659
|
"default-model/select",
|
|
2660
|
+
"default-model/reset",
|
|
2620
2661
|
"predictions/generate",
|
|
2621
2662
|
"runtime/status",
|
|
2622
2663
|
"runtime/install",
|
|
@@ -2868,8 +2909,9 @@ const require = createRequire(import.meta.url);
|
|
|
2868
2909
|
const execute = promisify(execFile);
|
|
2869
2910
|
/** The DSH release this plugin is loaded into, read from the host's own LLM package. */
|
|
2870
2911
|
function hostDshVersion(resolve = require.resolve, entry = process.argv[1]) {
|
|
2871
|
-
const attempts = [
|
|
2872
|
-
if (typeof entry === "string" && entry) attempts.push(() => require.resolve("@deepseek-ai/dsh-llm/package.json", { paths: [dirname(entry)] }));
|
|
2912
|
+
const attempts = [];
|
|
2913
|
+
if (typeof entry === "string" && entry) attempts.push(() => require.resolve("@deepseek-ai/dsh-llm/package.json", { paths: [dirname(realpathSync(entry))] }));
|
|
2914
|
+
attempts.push(() => resolve("@deepseek-ai/dsh-llm/package.json"));
|
|
2873
2915
|
for (const attempt of attempts) try {
|
|
2874
2916
|
const { version } = JSON.parse(readFileSync(attempt(), "utf8"));
|
|
2875
2917
|
if (typeof version === "string" && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u.test(version)) return version;
|
|
@@ -3682,7 +3724,7 @@ function inheritedOriginalImageRef(session, assetId) {
|
|
|
3682
3724
|
}
|
|
3683
3725
|
//#endregion
|
|
3684
3726
|
//#region src/version.js
|
|
3685
|
-
const PACKAGE_VERSION = "3.2.
|
|
3727
|
+
const PACKAGE_VERSION = "3.2.1";
|
|
3686
3728
|
const USER_AGENT = `dsh-codex-subscription/${PACKAGE_VERSION}`;
|
|
3687
3729
|
//#endregion
|
|
3688
3730
|
//#region src/codex-images.js
|
|
@@ -14677,12 +14719,12 @@ function createSubscriptionRpcHandler({ authHandler, usageReader, accountUsageRe
|
|
|
14677
14719
|
if (signal.aborted) throw error;
|
|
14678
14720
|
return publicError(error?.code === "voice-native-unavailable" ? "voice-native-unavailable" : "operation-error", "Could not use native voice");
|
|
14679
14721
|
}
|
|
14680
|
-
if (endpoint === "default-model/status" || endpoint === "default-model/select") try {
|
|
14722
|
+
if (endpoint === "default-model/status" || endpoint === "default-model/select" || endpoint === "default-model/reset") try {
|
|
14681
14723
|
signal.throwIfAborted();
|
|
14682
14724
|
if (!defaultModel) return publicError("unavailable", "The default model is unavailable");
|
|
14683
14725
|
return {
|
|
14684
14726
|
ok: true,
|
|
14685
|
-
value: endpoint === "default-model/status" ? defaultModel.status() : await defaultModel.select({ model: payload?.model })
|
|
14727
|
+
value: endpoint === "default-model/status" ? defaultModel.status() : endpoint === "default-model/reset" ? await defaultModel.reset() : await defaultModel.select({ model: payload?.model })
|
|
14686
14728
|
};
|
|
14687
14729
|
} catch (error) {
|
|
14688
14730
|
if (signal.aborted) throw error;
|
|
@@ -16221,6 +16263,7 @@ function apply(ctx, config = {}) {
|
|
|
16221
16263
|
const connection = createSubscriptionConnection({ resolveMode: () => settings.get().connectionMode });
|
|
16222
16264
|
const defaultModel = createDefaultModelController({
|
|
16223
16265
|
resolveService: () => ctx.get?.("agentDefaultModel"),
|
|
16266
|
+
resolveEditor: () => ctx.get?.("configEditor"),
|
|
16224
16267
|
listModels: () => modelCatalog.getModels().map((model) => model.id)
|
|
16225
16268
|
});
|
|
16226
16269
|
const accountScope = async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-codex-subscription",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "Use ChatGPT and Codex subscriptions in DeepSeek Harness with OAuth, quota, safe resets, web search, images and Fast mode, and control DSH from the ChatGPT mobile app (Beta)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|