dsh-codex-subscription 3.2.0 → 3.2.2
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 +17 -9
- package/README.md +16 -8
- package/compatibility.json +3 -2
- package/lib/client.js +368 -385
- package/lib/client.sketch.js +1 -0
- package/lib/index.js +268 -47
- package/package.json +36 -36
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
|
|
@@ -1399,6 +1431,27 @@ function createSubscriptionConnection({ resolveMode = () => "sse", resolveProxy
|
|
|
1399
1431
|
};
|
|
1400
1432
|
}
|
|
1401
1433
|
//#endregion
|
|
1434
|
+
//#region src/context-budget.js
|
|
1435
|
+
const effectiveContextPercent = (value) => Number.isInteger(value) && value > 0 && value <= 100 ? value : 95;
|
|
1436
|
+
function effectiveContextWindow(window, percent) {
|
|
1437
|
+
return Number.isSafeInteger(window) && window > 0 ? Math.floor(window * effectiveContextPercent(percent) / 100) : window;
|
|
1438
|
+
}
|
|
1439
|
+
/** Match DSH basic compaction's default pressure budget, using an already effective window.
|
|
1440
|
+
* maxTokens is the routed request's local output reservation, not the model's output ceiling.
|
|
1441
|
+
* Ratio and headroom are alternative pressure limits: do not subtract them successively.
|
|
1442
|
+
*/
|
|
1443
|
+
function compactionThreshold(window, maxTokens, configured) {
|
|
1444
|
+
if (configured !== void 0 && (!Number.isSafeInteger(configured) || configured < 1e3)) throw new Error("Invalid compaction threshold");
|
|
1445
|
+
const reserved = maxTokens ?? 0;
|
|
1446
|
+
if (!Number.isSafeInteger(reserved) || reserved < 0) throw new Error("Invalid compaction output reservation");
|
|
1447
|
+
if (window === void 0 || window === null) return configured ?? 1e5;
|
|
1448
|
+
if (!Number.isSafeInteger(window) || window <= 0) throw new Error("Invalid Codex context window");
|
|
1449
|
+
const pressure = window - reserved - 65536;
|
|
1450
|
+
const limit = Math.floor(Math.min(window * .8, pressure, configured ?? Infinity));
|
|
1451
|
+
if (limit < 1e3) throw new Error("Codex context budget is too small for the requested output reservation and compaction headroom");
|
|
1452
|
+
return limit;
|
|
1453
|
+
}
|
|
1454
|
+
//#endregion
|
|
1402
1455
|
//#region src/subscription-compaction.js
|
|
1403
1456
|
/** Experimental SSE bridge; callers must explicitly opt in. */
|
|
1404
1457
|
const clone$2 = (value) => JSON.parse(JSON.stringify(value));
|
|
@@ -1421,7 +1474,7 @@ function createCompactionBridge({ enabled = () => false, threshold, accountScope
|
|
|
1421
1474
|
checkpointsSaved: 0,
|
|
1422
1475
|
checkpointsReused: 0
|
|
1423
1476
|
};
|
|
1424
|
-
const wrapStream = (factory, options) => (async function* () {
|
|
1477
|
+
const wrapStream = (factory, options, modelInfo) => (async function* () {
|
|
1425
1478
|
if (!enabled() || options.provider !== "openai-codex") {
|
|
1426
1479
|
yield* factory(options);
|
|
1427
1480
|
return;
|
|
@@ -1433,7 +1486,8 @@ function createCompactionBridge({ enabled = () => false, threshold, accountScope
|
|
|
1433
1486
|
original: options.messages,
|
|
1434
1487
|
blocks: [],
|
|
1435
1488
|
suffix: void 0,
|
|
1436
|
-
completed: false
|
|
1489
|
+
completed: false,
|
|
1490
|
+
outputReserve: options.maxTokens ?? modelInfo?.defaultMaxTokens
|
|
1437
1491
|
};
|
|
1438
1492
|
let messages = options.messages;
|
|
1439
1493
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
@@ -1492,19 +1546,29 @@ function createCompactionBridge({ enabled = () => false, threshold, accountScope
|
|
|
1492
1546
|
snapshot: () => ({ ...stats }),
|
|
1493
1547
|
wrapAdapter(adapter) {
|
|
1494
1548
|
return new Proxy(adapter, { get(target, property) {
|
|
1495
|
-
if (property === "stream") return (options) =>
|
|
1549
|
+
if (property === "stream") return (options) => (async function* () {
|
|
1550
|
+
if (!enabled() || options.provider !== "openai-codex") {
|
|
1551
|
+
yield* target.stream(options);
|
|
1552
|
+
return;
|
|
1553
|
+
}
|
|
1554
|
+
const call = typeof target.prepareCall === "function" ? await target.prepareCall(options.provider, options.model, options.signal) : {
|
|
1555
|
+
model: await target.resolveModel?.(options.provider, options.model),
|
|
1556
|
+
stream: (o) => target.stream(o)
|
|
1557
|
+
};
|
|
1558
|
+
yield* wrapStream((o) => call.stream(o), options, call.model);
|
|
1559
|
+
})();
|
|
1496
1560
|
if (property === "prepareCall") return async (...args) => {
|
|
1497
1561
|
const call = await target.prepareCall(...args);
|
|
1498
1562
|
return {
|
|
1499
1563
|
...call,
|
|
1500
|
-
stream: (options) => wrapStream((o) => call.stream(o), options)
|
|
1564
|
+
stream: (options) => wrapStream((o) => call.stream(o), options, call.model)
|
|
1501
1565
|
};
|
|
1502
1566
|
};
|
|
1503
1567
|
const value = Reflect.get(target, property, target);
|
|
1504
1568
|
return typeof value === "function" ? value.bind(target) : value;
|
|
1505
1569
|
} });
|
|
1506
1570
|
},
|
|
1507
|
-
preparePayload(payload, contextWindow) {
|
|
1571
|
+
preparePayload(payload, contextWindow, maxTokens) {
|
|
1508
1572
|
const state = scope.getStore();
|
|
1509
1573
|
if (!state) return payload;
|
|
1510
1574
|
if (!state.counted) {
|
|
@@ -1512,12 +1576,7 @@ function createCompactionBridge({ enabled = () => false, threshold, accountScope
|
|
|
1512
1576
|
stats.requests = Math.min(Number.MAX_SAFE_INTEGER, stats.requests + 1);
|
|
1513
1577
|
if (state.suffix) stats.checkpointsReused = Math.min(Number.MAX_SAFE_INTEGER, stats.checkpointsReused + 1);
|
|
1514
1578
|
}
|
|
1515
|
-
const
|
|
1516
|
-
const configured = threshold?.();
|
|
1517
|
-
if (configured !== void 0 && (!Number.isSafeInteger(configured) || configured < 1e3)) throw new Error("Invalid compaction threshold");
|
|
1518
|
-
const byWindow = windowKnown ? Math.floor(Math.min(contextWindow * .8, contextWindow - Math.min(65536, contextWindow / 4))) : 1e5;
|
|
1519
|
-
const limit = configured === void 0 ? byWindow : windowKnown ? Math.min(configured, Math.floor(contextWindow / 2)) : configured;
|
|
1520
|
-
if (!Number.isSafeInteger(limit) || limit < 1e3) throw new Error("Invalid compaction threshold");
|
|
1579
|
+
const limit = compactionThreshold(contextWindow, maxTokens ?? state.outputReserve, threshold?.());
|
|
1521
1580
|
return {
|
|
1522
1581
|
...payload,
|
|
1523
1582
|
input: [...state.suffix ?? [], ...payload.input],
|
|
@@ -1786,6 +1845,7 @@ function normalizeTransportEvent(event, signal) {
|
|
|
1786
1845
|
}
|
|
1787
1846
|
//#endregion
|
|
1788
1847
|
//#region src/model-retry-hint.js
|
|
1848
|
+
const CODEX_OVERLOADED = /^\s*(?:Codex error:\s*)?Our servers are currently overloaded\. Please try again later\.\s*$/u;
|
|
1789
1849
|
/** Keep the provider's wait as a fact; only DSH decides whether and when to retry. */
|
|
1790
1850
|
function providerRetryAfterMs(headers, at = Date.now()) {
|
|
1791
1851
|
const read = (key) => typeof headers?.get === "function" ? headers.get(key) : headers?.[key];
|
|
@@ -1800,9 +1860,10 @@ function providerRetryAfterMs(headers, at = Date.now()) {
|
|
|
1800
1860
|
return Number.isFinite(value) && value > 0 ? Math.min(value, Number.MAX_SAFE_INTEGER) : void 0;
|
|
1801
1861
|
}
|
|
1802
1862
|
function createModelRetryHint({ now = Date.now, ErrorClass = dshLlm.LlmError } = {}) {
|
|
1803
|
-
let response, outputStarted = false;
|
|
1863
|
+
let response, responseStatus, outputStarted = false;
|
|
1804
1864
|
return {
|
|
1805
1865
|
onResponse(info) {
|
|
1866
|
+
responseStatus = info?.status;
|
|
1806
1867
|
response = [429, 503].includes(info?.status) ? {
|
|
1807
1868
|
status: info.status,
|
|
1808
1869
|
delay: providerRetryAfterMs(info.headers, now())
|
|
@@ -1816,23 +1877,29 @@ function createModelRetryHint({ now = Date.now, ErrorClass = dshLlm.LlmError } =
|
|
|
1816
1877
|
].includes(event.type)) outputStarted = true;
|
|
1817
1878
|
},
|
|
1818
1879
|
failure(original, signal) {
|
|
1819
|
-
if (signal?.aborted || outputStarted || !
|
|
1880
|
+
if (signal?.aborted || outputStarted || !original || typeof original.message !== "string" || [
|
|
1820
1881
|
"ABORTED",
|
|
1882
|
+
"AUTH",
|
|
1883
|
+
"INVALID_REQUEST",
|
|
1821
1884
|
"QUOTA",
|
|
1822
1885
|
"ACCOUNT_QUOTA",
|
|
1823
1886
|
"QUOTA_EXCEEDED"
|
|
1824
1887
|
].includes(original.code) || typeof dshLlm.isQuotaExceededError === "function" && dshLlm.isQuotaExceededError(original.message)) return original;
|
|
1825
|
-
|
|
1888
|
+
const status = responseStatus ?? original.status;
|
|
1889
|
+
const overloaded = original.code === "PI_AI_ERROR" && CODEX_OVERLOADED.test(original.message) && (status === void 0 || status >= 200 && status < 300);
|
|
1890
|
+
if (!response && !overloaded) return original;
|
|
1891
|
+
if (/You have hit your ChatGPT usage limit/iu.test(original.message) || response?.status === 429 && original.code !== "RATE_LIMIT") return original;
|
|
1892
|
+
const code = response?.status === 429 ? "RATE_LIMIT" : "SERVER";
|
|
1826
1893
|
let error;
|
|
1827
1894
|
try {
|
|
1828
|
-
error = new ErrorClass(original.message, response
|
|
1895
|
+
error = new ErrorClass(original.message, code, response ? {
|
|
1829
1896
|
status: response.status,
|
|
1830
1897
|
...response.delay === void 0 ? {} : { providerRetryAfterMs: response.delay }
|
|
1831
|
-
});
|
|
1898
|
+
} : {});
|
|
1832
1899
|
} catch {
|
|
1833
1900
|
return original;
|
|
1834
1901
|
}
|
|
1835
|
-
return error.failure?.status === response.status && (response.delay === void 0 || error.failure.providerRetryAfterMs === response.delay) ? {
|
|
1902
|
+
return error.failure?.code === code && (!response || error.failure.status === response.status && (response.delay === void 0 || error.failure.providerRetryAfterMs === response.delay)) ? {
|
|
1836
1903
|
...original,
|
|
1837
1904
|
...error.failure
|
|
1838
1905
|
} : original;
|
|
@@ -1882,6 +1949,134 @@ function createModelRetryBridge() {
|
|
|
1882
1949
|
};
|
|
1883
1950
|
}
|
|
1884
1951
|
//#endregion
|
|
1952
|
+
//#region src/model-stream-health.js
|
|
1953
|
+
const transportOf = (value) => value?.startsWith("websocket") ? "websocket" : value === "sse" ? "sse" : "unknown";
|
|
1954
|
+
const failureCode = (error) => {
|
|
1955
|
+
const text = String(error?.errorMessage ?? error?.message ?? "");
|
|
1956
|
+
return [
|
|
1957
|
+
"ECONNRESET",
|
|
1958
|
+
"ETIMEDOUT",
|
|
1959
|
+
"ECONNREFUSED",
|
|
1960
|
+
"ERR_STREAM_PREMATURE_CLOSE"
|
|
1961
|
+
].find((code) => error?.code === code || text.includes(code)) ?? (/timeout/i.test(text) ? "TIMEOUT" : /WebSocket closed/i.test(text) ? "WS_CLOSED" : "OTHER");
|
|
1962
|
+
};
|
|
1963
|
+
/** Bounded request-level facts; no prompts, response bodies, credentials or public session ids. */
|
|
1964
|
+
function createModelStreamHealth({ now = Date.now, log = () => {} } = {}) {
|
|
1965
|
+
const recent = [], streaks = /* @__PURE__ */ new Map();
|
|
1966
|
+
return {
|
|
1967
|
+
snapshot: () => recent.map((value) => ({ ...value })),
|
|
1968
|
+
begin({ sessionId, configured, selected }) {
|
|
1969
|
+
const start = now(), configuredTransport = transportOf(configured), selectedTransport = transportOf(selected);
|
|
1970
|
+
let done = false, providerEvents = false, lastEvent, firstEvent, count = 0, output = false, httpStatus;
|
|
1971
|
+
let effectiveTransport = "unknown";
|
|
1972
|
+
const event = () => {
|
|
1973
|
+
const at = now();
|
|
1974
|
+
firstEvent ??= at;
|
|
1975
|
+
lastEvent = at;
|
|
1976
|
+
count++;
|
|
1977
|
+
};
|
|
1978
|
+
return {
|
|
1979
|
+
response(info) {
|
|
1980
|
+
effectiveTransport = "sse";
|
|
1981
|
+
if (Number.isInteger(info?.status)) httpStatus = info.status;
|
|
1982
|
+
},
|
|
1983
|
+
providerEvent() {
|
|
1984
|
+
providerEvents = true;
|
|
1985
|
+
event();
|
|
1986
|
+
if (effectiveTransport === "unknown" && selectedTransport === "websocket") effectiveTransport = "websocket";
|
|
1987
|
+
},
|
|
1988
|
+
observe(value) {
|
|
1989
|
+
if (value?.type?.endsWith("_delta")) output = true;
|
|
1990
|
+
if (!providerEvents && ![
|
|
1991
|
+
"start",
|
|
1992
|
+
"error",
|
|
1993
|
+
"done"
|
|
1994
|
+
].includes(value?.type)) {
|
|
1995
|
+
event();
|
|
1996
|
+
if (effectiveTransport === "unknown" && selectedTransport === "websocket") effectiveTransport = "websocket";
|
|
1997
|
+
}
|
|
1998
|
+
},
|
|
1999
|
+
finish(status, error) {
|
|
2000
|
+
if (done) return;
|
|
2001
|
+
done = true;
|
|
2002
|
+
const end = now(), code = status === "failed" ? failureCode(error) : void 0;
|
|
2003
|
+
const previous = typeof sessionId === "string" ? streaks.get(sessionId) : void 0;
|
|
2004
|
+
const signature = `${effectiveTransport}:${code}`;
|
|
2005
|
+
const consecutiveFailures = status === "failed" && typeof sessionId === "string" ? previous?.signature === signature ? Math.min(previous.count + 1, 1e3) : 1 : 0;
|
|
2006
|
+
if (typeof sessionId === "string") {
|
|
2007
|
+
streaks.delete(sessionId);
|
|
2008
|
+
if (consecutiveFailures) streaks.set(sessionId, {
|
|
2009
|
+
signature,
|
|
2010
|
+
count: consecutiveFailures
|
|
2011
|
+
});
|
|
2012
|
+
if (streaks.size > 100) streaks.delete(streaks.keys().next().value);
|
|
2013
|
+
}
|
|
2014
|
+
const value = {
|
|
2015
|
+
status,
|
|
2016
|
+
configured: configuredTransport,
|
|
2017
|
+
selected: selectedTransport,
|
|
2018
|
+
effective: effectiveTransport,
|
|
2019
|
+
durationMs: Math.max(0, end - start),
|
|
2020
|
+
eventCount: count,
|
|
2021
|
+
eventSource: providerEvents ? "provider" : "adapter",
|
|
2022
|
+
outputStarted: output,
|
|
2023
|
+
...firstEvent === void 0 ? {} : {
|
|
2024
|
+
firstEventMs: Math.max(0, firstEvent - start),
|
|
2025
|
+
lastEventAgoMs: Math.max(0, end - lastEvent)
|
|
2026
|
+
},
|
|
2027
|
+
...httpStatus === void 0 ? {} : { httpStatus },
|
|
2028
|
+
...code === void 0 ? {} : {
|
|
2029
|
+
code,
|
|
2030
|
+
consecutiveFailures
|
|
2031
|
+
}
|
|
2032
|
+
};
|
|
2033
|
+
recent.push(value);
|
|
2034
|
+
if (recent.length > 20) recent.shift();
|
|
2035
|
+
if (status !== "cancelled") log(status === "failed" ? "warn" : "info", `stream ${status}: configured=${configuredTransport} selected=${selectedTransport} effective=${effectiveTransport} duration_ms=${value.durationMs} first_event_ms=${value.firstEventMs ?? "none"} last_event_ago_ms=${value.lastEventAgoMs ?? "none"} events=${count}${code ? ` failure=${code} consecutive=${consecutiveFailures}` : ""}`);
|
|
2036
|
+
}
|
|
2037
|
+
};
|
|
2038
|
+
}
|
|
2039
|
+
};
|
|
2040
|
+
}
|
|
2041
|
+
function safeStreamHealth(value) {
|
|
2042
|
+
if (!Array.isArray(value)) return [];
|
|
2043
|
+
return value.slice(-20).filter((item) => [
|
|
2044
|
+
"completed",
|
|
2045
|
+
"failed",
|
|
2046
|
+
"cancelled"
|
|
2047
|
+
].includes(item?.status)).map((item) => ({
|
|
2048
|
+
status: item.status,
|
|
2049
|
+
...Object.fromEntries([
|
|
2050
|
+
"configured",
|
|
2051
|
+
"selected",
|
|
2052
|
+
"effective"
|
|
2053
|
+
].filter((key) => [
|
|
2054
|
+
"sse",
|
|
2055
|
+
"websocket",
|
|
2056
|
+
"unknown"
|
|
2057
|
+
].includes(item[key])).map((key) => [key, item[key]])),
|
|
2058
|
+
...Object.fromEntries([
|
|
2059
|
+
"durationMs",
|
|
2060
|
+
"firstEventMs",
|
|
2061
|
+
"lastEventAgoMs",
|
|
2062
|
+
"eventCount",
|
|
2063
|
+
"consecutiveFailures",
|
|
2064
|
+
"httpStatus"
|
|
2065
|
+
].filter((key) => Number.isSafeInteger(item[key]) && item[key] >= 0).map((key) => [key, item[key]])),
|
|
2066
|
+
...["provider", "adapter"].includes(item.eventSource) ? { eventSource: item.eventSource } : {},
|
|
2067
|
+
...typeof item.outputStarted === "boolean" ? { outputStarted: item.outputStarted } : {},
|
|
2068
|
+
...[
|
|
2069
|
+
"ECONNRESET",
|
|
2070
|
+
"ETIMEDOUT",
|
|
2071
|
+
"ECONNREFUSED",
|
|
2072
|
+
"ERR_STREAM_PREMATURE_CLOSE",
|
|
2073
|
+
"TIMEOUT",
|
|
2074
|
+
"WS_CLOSED",
|
|
2075
|
+
"OTHER"
|
|
2076
|
+
].includes(item.code) ? { code: item.code } : {}
|
|
2077
|
+
}));
|
|
2078
|
+
}
|
|
2079
|
+
//#endregion
|
|
1885
2080
|
//#region src/pi-ai-runtime.js
|
|
1886
2081
|
const FAST_SERVICE_TIER = "priority";
|
|
1887
2082
|
const ULTRAFAST_SERVICE_TIER = "ultrafast";
|
|
@@ -1953,6 +2148,7 @@ function isDshAutoReview(context) {
|
|
|
1953
2148
|
*/
|
|
1954
2149
|
function openaiCodexSubscriptionProvider({ resolveSpeedMode = () => void 0, resolveOutputVerbosity = () => OUTPUT_VERBOSITY_DEFAULT, resolveInputImageDetail = () => void 0, resolveReasoningSummary = () => void 0, resolveContextMode = () => void 0, resolveCustomContextWindow = () => void 0, resolveReviewModel = () => REVIEW_MODEL_SESSION, catalog, connection, compaction, reasoning, ultra, runNetwork = (_area, operation) => operation() } = {}) {
|
|
1955
2150
|
const provider = createOpenAICodexProvider();
|
|
2151
|
+
const streamHealth = createModelStreamHealth({ log: (level, message) => diagnosticLog.log(level, "model-stream", message) });
|
|
1956
2152
|
const retryBridge = createModelRetryBridge();
|
|
1957
2153
|
const requestToken = Object.freeze({
|
|
1958
2154
|
name: "DSH-managed Codex OAuth request token",
|
|
@@ -1965,7 +2161,7 @@ function openaiCodexSubscriptionProvider({ resolveSpeedMode = () => void 0, reso
|
|
|
1965
2161
|
};
|
|
1966
2162
|
}
|
|
1967
2163
|
});
|
|
1968
|
-
const modelMetadata = (model) => catalog?.metadata(model?.id);
|
|
2164
|
+
const modelMetadata = (model) => catalog?.metadata?.(model?.id);
|
|
1969
2165
|
const supportsVerbosity = (model) => modelMetadata(model)?.supportVerbosity ?? model?.id !== "gpt-5.3-codex-spark";
|
|
1970
2166
|
const withPreferences = (model, options = {}) => {
|
|
1971
2167
|
const metadata = modelMetadata(model);
|
|
@@ -1990,7 +2186,7 @@ function openaiCodexSubscriptionProvider({ resolveSpeedMode = () => void 0, reso
|
|
|
1990
2186
|
} },
|
|
1991
2187
|
...serviceTier === void 0 ? {} : { service_tier: serviceTier }
|
|
1992
2188
|
};
|
|
1993
|
-
const managed = compaction?.preparePayload(preferred, model?.contextWindow) ?? preferred;
|
|
2189
|
+
const managed = compaction?.preparePayload(preferred, model?.contextWindow, options.maxTokens) ?? preferred;
|
|
1994
2190
|
const next = await onPayload?.(managed, requestModel);
|
|
1995
2191
|
const detailed = inputImageDetail === "auto" ? next ?? managed : withInputImageDetail(next ?? managed, inputImageDetail);
|
|
1996
2192
|
const { temperature: _dropped, ...accepted } = withReasoningSummary(detailed, reasoningSummary);
|
|
@@ -2010,18 +2206,14 @@ function openaiCodexSubscriptionProvider({ resolveSpeedMode = () => void 0, reso
|
|
|
2010
2206
|
const getModels = () => (catalog?.getModels() ?? provider.getModels()).map((model) => {
|
|
2011
2207
|
const maximum = modelContextMaximum(model);
|
|
2012
2208
|
const mode = resolveContextMode();
|
|
2013
|
-
|
|
2014
|
-
if (
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
...model,
|
|
2018
|
-
contextWindow
|
|
2019
|
-
};
|
|
2209
|
+
let window = model.contextWindow;
|
|
2210
|
+
if (model.id !== "gpt-5.3-codex-spark") {
|
|
2211
|
+
if (mode === "extended") window = maximum;
|
|
2212
|
+
else if (mode === "custom") window = clampModelContext(resolveCustomContextWindow(customContextModelKey(model.id)), maximum, window);
|
|
2020
2213
|
}
|
|
2021
|
-
|
|
2022
|
-
return {
|
|
2214
|
+
return window === void 0 ? model : {
|
|
2023
2215
|
...model,
|
|
2024
|
-
contextWindow:
|
|
2216
|
+
contextWindow: effectiveContextWindow(window, modelMetadata(model)?.effectiveContextWindowPercent)
|
|
2025
2217
|
};
|
|
2026
2218
|
});
|
|
2027
2219
|
const review = {
|
|
@@ -2117,6 +2309,7 @@ function openaiCodexSubscriptionProvider({ resolveSpeedMode = () => void 0, reso
|
|
|
2117
2309
|
};
|
|
2118
2310
|
const networkIterable = (factory, options, direct = false, source) => {
|
|
2119
2311
|
let iterator;
|
|
2312
|
+
let health;
|
|
2120
2313
|
let prepared;
|
|
2121
2314
|
let stage = "prepare";
|
|
2122
2315
|
const retryHint = direct ? void 0 : retryBridge.current();
|
|
@@ -2126,12 +2319,22 @@ function openaiCodexSubscriptionProvider({ resolveSpeedMode = () => void 0, reso
|
|
|
2126
2319
|
if (stage === "prepare") stage = "request";
|
|
2127
2320
|
const result = await runNetwork("model", () => {
|
|
2128
2321
|
const next = direct ? request.options : compaction?.requestOptions(request.options) ?? request.options;
|
|
2322
|
+
health ??= streamHealth.begin({
|
|
2323
|
+
sessionId: direct ? void 0 : options?.sessionId,
|
|
2324
|
+
configured: request.options?.transport,
|
|
2325
|
+
selected: next.transport
|
|
2326
|
+
});
|
|
2129
2327
|
iterator ??= factory({
|
|
2130
2328
|
...next,
|
|
2131
2329
|
async onResponse(info, requestModel) {
|
|
2330
|
+
health.response(info);
|
|
2132
2331
|
retryHint?.onResponse(info);
|
|
2133
2332
|
return next.onResponse?.(info, requestModel);
|
|
2134
2333
|
},
|
|
2334
|
+
onProviderStreamEvent(event) {
|
|
2335
|
+
health.providerEvent();
|
|
2336
|
+
return next.onProviderStreamEvent?.(event);
|
|
2337
|
+
},
|
|
2135
2338
|
async onPayload(payload, requestModel) {
|
|
2136
2339
|
stage = "payload";
|
|
2137
2340
|
return next.onPayload?.(payload, requestModel);
|
|
@@ -2143,15 +2346,21 @@ function openaiCodexSubscriptionProvider({ resolveSpeedMode = () => void 0, reso
|
|
|
2143
2346
|
}));
|
|
2144
2347
|
}, direct ? request.network : compaction?.networkOptions(request.network) ?? request.network);
|
|
2145
2348
|
if (!result.done) {
|
|
2349
|
+
health?.observe(result.value);
|
|
2350
|
+
if (result.value?.type === "error") health?.finish(request.options?.signal?.aborted ? "cancelled" : "failed", result.value.error);
|
|
2351
|
+
else if (result.value?.type === "done") health?.finish("completed");
|
|
2146
2352
|
retryHint?.observe(result.value, request.options?.signal);
|
|
2147
2353
|
if (result.value?.type === "error" && !request.options?.signal?.aborted) noteStreamFailure(stage, void 0, source);
|
|
2148
2354
|
else if (stage === "payload") stage = "stream";
|
|
2149
2355
|
}
|
|
2356
|
+
if (method === "return") health?.finish("cancelled");
|
|
2357
|
+
else if (result.done) health?.finish(request.options?.signal?.aborted ? "cancelled" : "completed");
|
|
2150
2358
|
return result.done ? result : {
|
|
2151
2359
|
...result,
|
|
2152
2360
|
value: normalizeTransportEvent(result.value, request.options?.signal)
|
|
2153
2361
|
};
|
|
2154
2362
|
} catch (error) {
|
|
2363
|
+
health?.finish(options?.signal?.aborted ? "cancelled" : "failed", error);
|
|
2155
2364
|
noteStreamFailure(stage, error, source);
|
|
2156
2365
|
throw error;
|
|
2157
2366
|
}
|
|
@@ -2191,6 +2400,7 @@ function openaiCodexSubscriptionProvider({ resolveSpeedMode = () => void 0, reso
|
|
|
2191
2400
|
streamSimple: (model, context, options) => routed("streamSimple", model, context, options),
|
|
2192
2401
|
reviewCounters: () => ({ ...review }),
|
|
2193
2402
|
streamFailure: () => ({ ...streamFailure }),
|
|
2403
|
+
streamHealth: streamHealth.snapshot,
|
|
2194
2404
|
noteAdapterFailure,
|
|
2195
2405
|
wrapRetryAdapter: (adapter) => retryBridge.wrapAdapter(adapter)
|
|
2196
2406
|
});
|
|
@@ -2617,6 +2827,7 @@ const RPC_ENDPOINTS = Object.freeze([
|
|
|
2617
2827
|
"preferences/update",
|
|
2618
2828
|
"default-model/status",
|
|
2619
2829
|
"default-model/select",
|
|
2830
|
+
"default-model/reset",
|
|
2620
2831
|
"predictions/generate",
|
|
2621
2832
|
"runtime/status",
|
|
2622
2833
|
"runtime/install",
|
|
@@ -2862,14 +3073,16 @@ const SUPPORTED_RUNTIME_VERSIONS = Object.freeze([
|
|
|
2862
3073
|
"0.2.1-rc.2",
|
|
2863
3074
|
"0.2.1-rc.3",
|
|
2864
3075
|
"0.2.1-rc.4",
|
|
3076
|
+
"0.2.1-rc.5",
|
|
2865
3077
|
"0.2.2-alpha.2"
|
|
2866
3078
|
]);
|
|
2867
3079
|
const require = createRequire(import.meta.url);
|
|
2868
3080
|
const execute = promisify(execFile);
|
|
2869
3081
|
/** The DSH release this plugin is loaded into, read from the host's own LLM package. */
|
|
2870
3082
|
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)] }));
|
|
3083
|
+
const attempts = [];
|
|
3084
|
+
if (typeof entry === "string" && entry) attempts.push(() => require.resolve("@deepseek-ai/dsh-llm/package.json", { paths: [dirname(realpathSync(entry))] }));
|
|
3085
|
+
attempts.push(() => resolve("@deepseek-ai/dsh-llm/package.json"));
|
|
2873
3086
|
for (const attempt of attempts) try {
|
|
2874
3087
|
const { version } = JSON.parse(readFileSync(attempt(), "utf8"));
|
|
2875
3088
|
if (typeof version === "string" && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u.test(version)) return version;
|
|
@@ -3682,7 +3895,7 @@ function inheritedOriginalImageRef(session, assetId) {
|
|
|
3682
3895
|
}
|
|
3683
3896
|
//#endregion
|
|
3684
3897
|
//#region src/version.js
|
|
3685
|
-
const PACKAGE_VERSION = "3.2.
|
|
3898
|
+
const PACKAGE_VERSION = "3.2.2";
|
|
3686
3899
|
const USER_AGENT = `dsh-codex-subscription/${PACKAGE_VERSION}`;
|
|
3687
3900
|
//#endregion
|
|
3688
3901
|
//#region src/codex-images.js
|
|
@@ -11200,6 +11413,7 @@ function visibleModel(value, displayNames, now) {
|
|
|
11200
11413
|
priority: Number.isFinite(value.priority) ? value.priority : 0,
|
|
11201
11414
|
input: input.length > 0 ? input : ["text"],
|
|
11202
11415
|
contextWindow: positiveInteger(value.context_window) ?? positiveInteger(value.max_context_window),
|
|
11416
|
+
effectiveContextWindowPercent: effectiveContextPercent(value.effective_context_window_percent),
|
|
11203
11417
|
...positiveInteger(value.max_context_window) === void 0 ? {} : { maxContextWindow: value.max_context_window },
|
|
11204
11418
|
reasoning: supported.length > 0,
|
|
11205
11419
|
supportsReasoningEffortUpdates: value.supports_reasoning_effort_updates === true,
|
|
@@ -12627,6 +12841,11 @@ async function createSubscriptionDiagnostics({ auth, preferences, login = { phas
|
|
|
12627
12841
|
};
|
|
12628
12842
|
}
|
|
12629
12843
|
],
|
|
12844
|
+
[
|
|
12845
|
+
"streamHealth",
|
|
12846
|
+
"transport",
|
|
12847
|
+
() => typeof review?.streamHealth === "function" ? safeStreamHealth(review.streamHealth()) : void 0
|
|
12848
|
+
],
|
|
12630
12849
|
[
|
|
12631
12850
|
"operations",
|
|
12632
12851
|
"transport",
|
|
@@ -12733,6 +12952,7 @@ async function createSubscriptionDiagnostics({ auth, preferences, login = { phas
|
|
|
12733
12952
|
...collected.compaction ? { compaction: collected.compaction } : {},
|
|
12734
12953
|
...collected.review ? { review: collected.review } : {},
|
|
12735
12954
|
...collected.streamFailure ? { streamFailure: collected.streamFailure } : {},
|
|
12955
|
+
...collected.streamHealth?.length ? { streamHealth: collected.streamHealth } : {},
|
|
12736
12956
|
...catalog && [
|
|
12737
12957
|
"unavailable",
|
|
12738
12958
|
"cached",
|
|
@@ -14677,12 +14897,12 @@ function createSubscriptionRpcHandler({ authHandler, usageReader, accountUsageRe
|
|
|
14677
14897
|
if (signal.aborted) throw error;
|
|
14678
14898
|
return publicError(error?.code === "voice-native-unavailable" ? "voice-native-unavailable" : "operation-error", "Could not use native voice");
|
|
14679
14899
|
}
|
|
14680
|
-
if (endpoint === "default-model/status" || endpoint === "default-model/select") try {
|
|
14900
|
+
if (endpoint === "default-model/status" || endpoint === "default-model/select" || endpoint === "default-model/reset") try {
|
|
14681
14901
|
signal.throwIfAborted();
|
|
14682
14902
|
if (!defaultModel) return publicError("unavailable", "The default model is unavailable");
|
|
14683
14903
|
return {
|
|
14684
14904
|
ok: true,
|
|
14685
|
-
value: endpoint === "default-model/status" ? defaultModel.status() : await defaultModel.select({ model: payload?.model })
|
|
14905
|
+
value: endpoint === "default-model/status" ? defaultModel.status() : endpoint === "default-model/reset" ? await defaultModel.reset() : await defaultModel.select({ model: payload?.model })
|
|
14686
14906
|
};
|
|
14687
14907
|
} catch (error) {
|
|
14688
14908
|
if (signal.aborted) throw error;
|
|
@@ -16221,6 +16441,7 @@ function apply(ctx, config = {}) {
|
|
|
16221
16441
|
const connection = createSubscriptionConnection({ resolveMode: () => settings.get().connectionMode });
|
|
16222
16442
|
const defaultModel = createDefaultModelController({
|
|
16223
16443
|
resolveService: () => ctx.get?.("agentDefaultModel"),
|
|
16444
|
+
resolveEditor: () => ctx.get?.("configEditor"),
|
|
16224
16445
|
listModels: () => modelCatalog.getModels().map((model) => model.id)
|
|
16225
16446
|
});
|
|
16226
16447
|
const accountScope = async () => {
|