@dan-ai-studio/dshopencodego 0.1.91 → 0.1.93
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 +4 -2
- package/README.md +4 -2
- package/lib/client.js +180 -4
- package/lib/index.js +738 -224
- package/lib/types/catalog/go-doc.d.ts +6 -5
- package/lib/types/desktop/contract.d.ts +25 -0
- package/lib/types/desktop/feed.d.ts +96 -0
- package/lib/types/desktop/index.d.ts +10 -0
- package/lib/types/desktop/service.d.ts +30 -0
- package/lib/types/llm-error.d.ts +27 -0
- package/package.json +25 -25
package/lib/index.js
CHANGED
|
@@ -50835,7 +50835,7 @@ var require_parser_h1 = __commonJS({
|
|
|
50835
50835
|
var EVENT_RANGE_SIZE = 9;
|
|
50836
50836
|
var EVENT_HEADERS_SIZE = 19;
|
|
50837
50837
|
var miloPackage;
|
|
50838
|
-
var useWasmSIMD = process.arch !== "ppc64";
|
|
50838
|
+
var useWasmSIMD = process.arch !== "riscv64" && process.arch !== "ppc64";
|
|
50839
50839
|
if (process.env.UNDICI_NO_WASM_SIMD === "1") {
|
|
50840
50840
|
useWasmSIMD = false;
|
|
50841
50841
|
} else if (process.env.UNDICI_NO_WASM_SIMD === "0") {
|
|
@@ -52113,14 +52113,35 @@ Content-Type: ${value.type || "application/octet-stream"}\r
|
|
|
52113
52113
|
"Response body object should not be disturbed or locked"
|
|
52114
52114
|
);
|
|
52115
52115
|
}
|
|
52116
|
-
|
|
52117
|
-
|
|
52118
|
-
|
|
52119
|
-
|
|
52120
|
-
|
|
52116
|
+
if (webidl.is.ReadableStream(object)) {
|
|
52117
|
+
stream5 = object;
|
|
52118
|
+
} else {
|
|
52119
|
+
const reader = ReadableStream.from(object).getReader();
|
|
52120
|
+
let cancelled = false;
|
|
52121
|
+
stream5 = new ReadableStream({
|
|
52122
|
+
async pull(controller) {
|
|
52123
|
+
while (true) {
|
|
52124
|
+
const { done, value } = await reader.read();
|
|
52125
|
+
if (cancelled) {
|
|
52126
|
+
return;
|
|
52127
|
+
}
|
|
52128
|
+
if (done) {
|
|
52129
|
+
controller.close();
|
|
52130
|
+
return;
|
|
52131
|
+
}
|
|
52132
|
+
const bytes = isUint8Array(value) ? value : Buffer.from(value);
|
|
52133
|
+
if (bytes.byteLength) {
|
|
52134
|
+
controller.enqueue(bytes);
|
|
52135
|
+
return;
|
|
52136
|
+
}
|
|
52137
|
+
}
|
|
52138
|
+
},
|
|
52139
|
+
cancel(reason) {
|
|
52140
|
+
cancelled = true;
|
|
52141
|
+
return reader.cancel(reason);
|
|
52121
52142
|
}
|
|
52122
|
-
}
|
|
52123
|
-
}
|
|
52143
|
+
}, { highWaterMark: 0 });
|
|
52144
|
+
}
|
|
52124
52145
|
}
|
|
52125
52146
|
if (typeof source === "string" || isUint8Array(source)) {
|
|
52126
52147
|
action = () => source;
|
|
@@ -52352,7 +52373,9 @@ var require_client_h1 = __commonJS({
|
|
|
52352
52373
|
const llhttpWasmData = process.env.JEST_WORKER_ID ? require_llhttp_wasm() : void 0;
|
|
52353
52374
|
let mod;
|
|
52354
52375
|
let useWasmSIMD = true;
|
|
52355
|
-
if (process.arch === "
|
|
52376
|
+
if (process.arch === "riscv64") {
|
|
52377
|
+
useWasmSIMD = false;
|
|
52378
|
+
} else if (process.arch === "ppc64") {
|
|
52356
52379
|
const [major, minor] = process.versions.node.split(".").map((n) => parseInt(n, 10));
|
|
52357
52380
|
if (major < 24 || major === 24 && minor < 12) {
|
|
52358
52381
|
useWasmSIMD = false;
|
|
@@ -53673,7 +53696,6 @@ var require_client_h2 = __commonJS({
|
|
|
53673
53696
|
} = require_symbols();
|
|
53674
53697
|
var { channels } = require_diagnostics();
|
|
53675
53698
|
var kOpenStreams = /* @__PURE__ */ Symbol("open streams");
|
|
53676
|
-
var kRequestStreamId = /* @__PURE__ */ Symbol("request stream id");
|
|
53677
53699
|
var kRequestStream = /* @__PURE__ */ Symbol("request stream");
|
|
53678
53700
|
var kRequestStreamCleanup = /* @__PURE__ */ Symbol("request stream cleanup");
|
|
53679
53701
|
var kRequestStreamState = /* @__PURE__ */ Symbol("request stream state");
|
|
@@ -53681,6 +53703,7 @@ var require_client_h2 = __commonJS({
|
|
|
53681
53703
|
var kGoAwayReplayAttempts = /* @__PURE__ */ Symbol("goaway replay attempts");
|
|
53682
53704
|
var kRefusedStreamRetry = /* @__PURE__ */ Symbol("refused stream retry");
|
|
53683
53705
|
var MAX_GOAWAY_REPLAY_ATTEMPTS = 1;
|
|
53706
|
+
var HTTP2_FRAME_TYPE_HEADERS = 1;
|
|
53684
53707
|
var MIN_PROBE_TIMEOUT = 1e3;
|
|
53685
53708
|
var extractBody2;
|
|
53686
53709
|
var http2;
|
|
@@ -53732,14 +53755,14 @@ var require_client_h2 = __commonJS({
|
|
|
53732
53755
|
if (request == null) {
|
|
53733
53756
|
continue;
|
|
53734
53757
|
}
|
|
53735
|
-
|
|
53758
|
+
const streamId = request[kRequestStream]?.id;
|
|
53759
|
+
if (typeof streamId !== "number" || streamId > maxAcceptedStreamID) {
|
|
53736
53760
|
return i;
|
|
53737
53761
|
}
|
|
53738
53762
|
}
|
|
53739
53763
|
return client[kPendingIdx];
|
|
53740
53764
|
}
|
|
53741
53765
|
function detachRequestFromStream(request) {
|
|
53742
|
-
request[kRequestStreamId] = null;
|
|
53743
53766
|
request[kRequestStream] = null;
|
|
53744
53767
|
request[kRequestStreamCleanup] = null;
|
|
53745
53768
|
}
|
|
@@ -53748,7 +53771,6 @@ var require_client_h2 = __commonJS({
|
|
|
53748
53771
|
const previousStream = request[kRequestStream];
|
|
53749
53772
|
detachRequestFromStream(request);
|
|
53750
53773
|
previousCleanup?.(previousStream);
|
|
53751
|
-
request[kRequestStreamId] = stream5.id;
|
|
53752
53774
|
request[kRequestStream] = stream5;
|
|
53753
53775
|
request[kRequestStreamCleanup] = cleanup;
|
|
53754
53776
|
}
|
|
@@ -53817,7 +53839,8 @@ var require_client_h2 = __commonJS({
|
|
|
53817
53839
|
closeStreamSession(stream5);
|
|
53818
53840
|
}
|
|
53819
53841
|
if (!stream5.destroyed && !stream5.closed) {
|
|
53820
|
-
stream5.
|
|
53842
|
+
stream5.off("error", noop3);
|
|
53843
|
+
stream5.on("error", noop3);
|
|
53821
53844
|
}
|
|
53822
53845
|
}
|
|
53823
53846
|
function connectH2(client, socket) {
|
|
@@ -54152,14 +54175,12 @@ var require_client_h2 = __commonJS({
|
|
|
54152
54175
|
}
|
|
54153
54176
|
}
|
|
54154
54177
|
}
|
|
54155
|
-
for (let i = 0; i < streamsToClose.length; i++) {
|
|
54156
|
-
closeStream(streamsToClose[i]);
|
|
54157
|
-
}
|
|
54158
54178
|
if (pendingIdx !== previousPendingIdx) {
|
|
54159
54179
|
const remainingPendingRequests = client[kQueue].slice(previousPendingIdx);
|
|
54160
54180
|
client[kQueue].length = pendingIdx;
|
|
54161
54181
|
client[kQueue].push(...retriableRequests, ...remainingPendingRequests);
|
|
54162
54182
|
}
|
|
54183
|
+
client[kPendingIdx] = pendingIdx;
|
|
54163
54184
|
if (client[kHTTP2Session] === this) {
|
|
54164
54185
|
client[kSocket] = null;
|
|
54165
54186
|
client[kHTTPContext] = null;
|
|
@@ -54171,10 +54192,12 @@ var require_client_h2 = __commonJS({
|
|
|
54171
54192
|
clearHttp2IdleTimeout(this);
|
|
54172
54193
|
clearNoStreamsTimeout(this);
|
|
54173
54194
|
clearHttp2ProbeTimeout(this);
|
|
54195
|
+
for (let i = 0; i < streamsToClose.length; i++) {
|
|
54196
|
+
closeStream(streamsToClose[i]);
|
|
54197
|
+
}
|
|
54174
54198
|
if (!this.closed && !this.destroyed) {
|
|
54175
54199
|
this.close();
|
|
54176
54200
|
}
|
|
54177
|
-
client[kPendingIdx] = pendingIdx;
|
|
54178
54201
|
client.emit("disconnect", client[kUrl], [client], err);
|
|
54179
54202
|
client[kResume]();
|
|
54180
54203
|
}
|
|
@@ -54250,7 +54273,6 @@ var require_client_h2 = __commonJS({
|
|
|
54250
54273
|
}
|
|
54251
54274
|
}
|
|
54252
54275
|
function onUpgradeStreamClose() {
|
|
54253
|
-
this.off("error", noop3);
|
|
54254
54276
|
const state2 = this[kRequestStreamState];
|
|
54255
54277
|
this[kRequestStreamState] = null;
|
|
54256
54278
|
failUpgradeStream(state2, new InformationalError("HTTP/2: stream closed before response headers"));
|
|
@@ -54323,7 +54345,7 @@ var require_client_h2 = __commonJS({
|
|
|
54323
54345
|
}
|
|
54324
54346
|
removeUpgradeStreamListeners(stream5);
|
|
54325
54347
|
if (!stream5.destroyed && !stream5.closed) {
|
|
54326
|
-
stream5.
|
|
54348
|
+
stream5.on("error", noop3);
|
|
54327
54349
|
}
|
|
54328
54350
|
}
|
|
54329
54351
|
function failUpgradeStream(state2, err) {
|
|
@@ -54617,7 +54639,7 @@ var require_client_h2 = __commonJS({
|
|
|
54617
54639
|
}
|
|
54618
54640
|
if (!stream5.destroyed && !stream5.closed) {
|
|
54619
54641
|
removeRequestStreamListeners(stream5);
|
|
54620
|
-
stream5.
|
|
54642
|
+
stream5.on("error", noop3);
|
|
54621
54643
|
}
|
|
54622
54644
|
}
|
|
54623
54645
|
function onData(chunk) {
|
|
@@ -54730,13 +54752,25 @@ var require_client_h2 = __commonJS({
|
|
|
54730
54752
|
return false;
|
|
54731
54753
|
}
|
|
54732
54754
|
request[kRefusedStreamRetry] = true;
|
|
54755
|
+
requeueStreamRequest(client, state2);
|
|
54756
|
+
return true;
|
|
54757
|
+
}
|
|
54758
|
+
function retryUnsentStream(state2) {
|
|
54759
|
+
const { client, request, session } = state2;
|
|
54760
|
+
if (!session[kReceivedGoAway] || state2.responseReceived || request.aborted || request.completed || !canReplayRequest(request) || !registerGoAwayRefusal(request)) {
|
|
54761
|
+
return false;
|
|
54762
|
+
}
|
|
54763
|
+
requeueStreamRequest(client, state2);
|
|
54764
|
+
return true;
|
|
54765
|
+
}
|
|
54766
|
+
function requeueStreamRequest(client, state2) {
|
|
54767
|
+
const { request } = state2;
|
|
54733
54768
|
detachRequestStreamForClose(request);
|
|
54734
54769
|
state2.stream = null;
|
|
54735
54770
|
state2.requestFinalized = true;
|
|
54736
54771
|
completeRequest(client, request);
|
|
54737
54772
|
client[kQueue].splice(client[kPendingIdx], 0, request);
|
|
54738
54773
|
client[kResume]();
|
|
54739
|
-
return true;
|
|
54740
54774
|
}
|
|
54741
54775
|
function onError(err) {
|
|
54742
54776
|
const stream5 = this;
|
|
@@ -54745,6 +54779,7 @@ var require_client_h2 = __commonJS({
|
|
|
54745
54779
|
return;
|
|
54746
54780
|
}
|
|
54747
54781
|
stream5.off("error", onError);
|
|
54782
|
+
stream5.on("error", noop3);
|
|
54748
54783
|
if (state2.responseContentLength != null && state2.bytesRead !== state2.responseContentLength) {
|
|
54749
54784
|
err = new ResponseContentLengthMismatchError();
|
|
54750
54785
|
}
|
|
@@ -54763,6 +54798,9 @@ var require_client_h2 = __commonJS({
|
|
|
54763
54798
|
return;
|
|
54764
54799
|
}
|
|
54765
54800
|
stream5.off("frameError", onFrameError);
|
|
54801
|
+
if (type === HTTP2_FRAME_TYPE_HEADERS && retryUnsentStream(state2)) {
|
|
54802
|
+
return;
|
|
54803
|
+
}
|
|
54766
54804
|
state2.abort(new InformationalError(`HTTP/2: "frameError" received - type ${type}, code ${code}`));
|
|
54767
54805
|
}
|
|
54768
54806
|
function onAborted() {
|
|
@@ -60015,13 +60053,18 @@ var require_mock_utils = __commonJS({
|
|
|
60015
60053
|
if (typeof path5 !== "string") {
|
|
60016
60054
|
return path5;
|
|
60017
60055
|
}
|
|
60056
|
+
const queryIndex = path5.indexOf("?");
|
|
60057
|
+
const search = queryIndex === -1 ? "" : path5.slice(queryIndex);
|
|
60058
|
+
if (queryIndex !== -1) {
|
|
60059
|
+
path5 = path5.slice(0, queryIndex);
|
|
60060
|
+
}
|
|
60018
60061
|
while (path5.endsWith("/")) {
|
|
60019
60062
|
path5 = path5.slice(0, -1);
|
|
60020
60063
|
}
|
|
60021
60064
|
if (path5.length === 0) {
|
|
60022
60065
|
path5 = "/";
|
|
60023
60066
|
}
|
|
60024
|
-
return path5;
|
|
60067
|
+
return path5 + search;
|
|
60025
60068
|
}
|
|
60026
60069
|
function buildKey(opts) {
|
|
60027
60070
|
const { path: path5, method, body, headers, query } = opts;
|
|
@@ -60108,6 +60151,9 @@ var require_mock_utils = __commonJS({
|
|
|
60108
60151
|
paused: false,
|
|
60109
60152
|
rawHeaders: null,
|
|
60110
60153
|
rawTrailers: null,
|
|
60154
|
+
get aborted() {
|
|
60155
|
+
return aborted;
|
|
60156
|
+
},
|
|
60111
60157
|
pause() {
|
|
60112
60158
|
this.paused = true;
|
|
60113
60159
|
},
|
|
@@ -61989,8 +62035,11 @@ var require_decorator_handler = __commonJS({
|
|
|
61989
62035
|
onResponseStart(...args) {
|
|
61990
62036
|
assert(!this.#onCompleteCalled);
|
|
61991
62037
|
assert(!this.#onErrorCalled);
|
|
61992
|
-
|
|
61993
|
-
|
|
62038
|
+
const statusCode = args[1];
|
|
62039
|
+
if (statusCode >= 200) {
|
|
62040
|
+
assert(!this.#onResponseStartCalled);
|
|
62041
|
+
this.#onResponseStartCalled = true;
|
|
62042
|
+
}
|
|
61994
62043
|
return this.#handler.onResponseStart?.(...args);
|
|
61995
62044
|
}
|
|
61996
62045
|
onResponseData(...args) {
|
|
@@ -62110,7 +62159,11 @@ var require_redirect_handler = __commonJS({
|
|
|
62110
62159
|
this.handler.onResponseStart?.(controller, statusCode, headers, statusMessage);
|
|
62111
62160
|
return;
|
|
62112
62161
|
}
|
|
62113
|
-
this.history[kRedirectCacheControl].push(
|
|
62162
|
+
this.history[kRedirectCacheControl].push({
|
|
62163
|
+
statusCode,
|
|
62164
|
+
headers: { ...headers },
|
|
62165
|
+
receivedAt: Date.now()
|
|
62166
|
+
});
|
|
62114
62167
|
const baseUrl = requestOrigin ? new URL(this.opts.path, requestOrigin) : void 0;
|
|
62115
62168
|
const { origin, pathname, search } = util2.parseURL(new URL(this.location, baseUrl));
|
|
62116
62169
|
const path5 = search ? `${pathname}${search}` : pathname;
|
|
@@ -62178,9 +62231,17 @@ var require_redirect_handler = __commonJS({
|
|
|
62178
62231
|
function cleanRequestHeaders(headers, removeContent, unknownOrigin, stripHeaders, stripHeadersOnCrossOrigin) {
|
|
62179
62232
|
const ret = [];
|
|
62180
62233
|
if (Array.isArray(headers)) {
|
|
62181
|
-
|
|
62182
|
-
|
|
62183
|
-
|
|
62234
|
+
if (headers.length > 0 && Array.isArray(headers[0])) {
|
|
62235
|
+
for (const [key, value] of headers) {
|
|
62236
|
+
if (!shouldRemoveHeader(key, removeContent, unknownOrigin, stripHeaders, stripHeadersOnCrossOrigin)) {
|
|
62237
|
+
ret.push(key, value);
|
|
62238
|
+
}
|
|
62239
|
+
}
|
|
62240
|
+
} else {
|
|
62241
|
+
for (let i = 0; i < headers.length; i += 2) {
|
|
62242
|
+
if (!shouldRemoveHeader(headers[i], removeContent, unknownOrigin, stripHeaders, stripHeadersOnCrossOrigin)) {
|
|
62243
|
+
ret.push(headers[i], headers[i + 1]);
|
|
62244
|
+
}
|
|
62184
62245
|
}
|
|
62185
62246
|
}
|
|
62186
62247
|
} else if (headers && typeof headers === "object") {
|
|
@@ -64044,6 +64105,15 @@ var require_cache_handler = __commonJS({
|
|
|
64044
64105
|
}
|
|
64045
64106
|
return false;
|
|
64046
64107
|
}
|
|
64108
|
+
function appendVaryValues(target, varyValue) {
|
|
64109
|
+
if (Array.isArray(varyValue)) {
|
|
64110
|
+
for (let i = 0; i < varyValue.length; i++) {
|
|
64111
|
+
target.push(varyValue[i]);
|
|
64112
|
+
}
|
|
64113
|
+
} else if (varyValue != null) {
|
|
64114
|
+
target.push(varyValue);
|
|
64115
|
+
}
|
|
64116
|
+
}
|
|
64047
64117
|
function appendConnectionHeaderTokens(headersToRemove, connectionHeader) {
|
|
64048
64118
|
const values = Array.isArray(connectionHeader) ? connectionHeader : [connectionHeader];
|
|
64049
64119
|
for (let i = 0; i < values.length; i++) {
|
|
@@ -64105,6 +64175,9 @@ var require_cache_handler = __commonJS({
|
|
|
64105
64175
|
deleteLocationTargets(store, cacheKey, resHeaders.location);
|
|
64106
64176
|
deleteLocationTargets(store, cacheKey, resHeaders["content-location"]);
|
|
64107
64177
|
}
|
|
64178
|
+
function requestCarriesCredentials(headers) {
|
|
64179
|
+
return headers != null && (Object.hasOwn(headers, "authorization") || Object.hasOwn(headers, "cookie") || Object.hasOwn(headers, "proxy-authorization"));
|
|
64180
|
+
}
|
|
64108
64181
|
var CacheHandler = class {
|
|
64109
64182
|
/**
|
|
64110
64183
|
* @type {import('../../types/cache-interceptor.d.ts').default.CacheKey}
|
|
@@ -64137,7 +64210,7 @@ var require_cache_handler = __commonJS({
|
|
|
64137
64210
|
/**
|
|
64138
64211
|
* The URLs visited while following redirects, shared by reference from the
|
|
64139
64212
|
* redirect handler through the request context. Carries the suppressed hops'
|
|
64140
|
-
*
|
|
64213
|
+
* status/headers under {@link kRedirectCacheControl}.
|
|
64141
64214
|
* @type {URL[] | undefined}
|
|
64142
64215
|
*/
|
|
64143
64216
|
#history;
|
|
@@ -64187,21 +64260,29 @@ var require_cache_handler = __commonJS({
|
|
|
64187
64260
|
invalidateUnsafeRequest(this.#store, this.#cacheKey, resHeaders);
|
|
64188
64261
|
return downstreamOnHeaders();
|
|
64189
64262
|
}
|
|
64190
|
-
if (this.#history && this.#history.length >
|
|
64191
|
-
|
|
64192
|
-
if (!sameOrigin(finalUrl.origin, this.#cacheKey.origin)) {
|
|
64193
|
-
return downstreamOnHeaders();
|
|
64194
|
-
}
|
|
64263
|
+
if (this.#history && this.#history.length > 1 && requestCarriesCredentials(this.#cacheKey.headers)) {
|
|
64264
|
+
return downstreamOnHeaders();
|
|
64195
64265
|
}
|
|
64196
|
-
|
|
64197
|
-
|
|
64198
|
-
|
|
64199
|
-
const hopDirectives = hopCacheControl ? parseCacheControlHeader(hopCacheControl) : {};
|
|
64200
|
-
if (hopDirectives["no-store"] === true || this.#cacheType === "shared" && hopDirectives.private === true) {
|
|
64266
|
+
if (this.#history && this.#history.length > 0) {
|
|
64267
|
+
for (const hopUrl of this.#history) {
|
|
64268
|
+
if (!sameOrigin(hopUrl.origin, this.#cacheKey.origin)) {
|
|
64201
64269
|
return downstreamOnHeaders();
|
|
64202
64270
|
}
|
|
64203
64271
|
}
|
|
64204
64272
|
}
|
|
64273
|
+
const now = Date.now();
|
|
64274
|
+
const redirectHopInfo = this.#history?.[kRedirectCacheControl];
|
|
64275
|
+
const redirectPolicy = redirectHopInfo?.length > 0 ? getRedirectPolicy(
|
|
64276
|
+
this.#cacheType,
|
|
64277
|
+
this.#cacheKey.method,
|
|
64278
|
+
redirectHopInfo,
|
|
64279
|
+
this.#cacheKey.headers,
|
|
64280
|
+
this.#cacheByDefault,
|
|
64281
|
+
now
|
|
64282
|
+
) : void 0;
|
|
64283
|
+
if (redirectHopInfo?.length > 0 && redirectPolicy === void 0) {
|
|
64284
|
+
return downstreamOnHeaders();
|
|
64285
|
+
}
|
|
64205
64286
|
const cacheControlHeader = resHeaders["cache-control"];
|
|
64206
64287
|
const cacheControlDirectives = cacheControlHeader ? parseCacheControlHeader(cacheControlHeader) : {};
|
|
64207
64288
|
if (revalidationResponseDisallowsCachedReuse(this.#cacheType, resHeaders, cacheControlDirectives)) {
|
|
@@ -64221,7 +64302,6 @@ var require_cache_handler = __commonJS({
|
|
|
64221
64302
|
}
|
|
64222
64303
|
return downstreamOnHeaders();
|
|
64223
64304
|
}
|
|
64224
|
-
const now = Date.now();
|
|
64225
64305
|
const resAge = Object.hasOwn(resHeaders, "age") ? getAge(resHeaders.age) : void 0;
|
|
64226
64306
|
if (resAge !== void 0 && resAge >= MAX_RESPONSE_AGE) {
|
|
64227
64307
|
deleteCachedValueIfNotModified(statusCode, this.#store, this.#cacheKey);
|
|
@@ -64244,27 +64324,53 @@ var require_cache_handler = __commonJS({
|
|
|
64244
64324
|
return downstreamOnHeaders();
|
|
64245
64325
|
}
|
|
64246
64326
|
const baseTime = now - currentAge;
|
|
64247
|
-
|
|
64327
|
+
let absoluteStaleAt = staleAt + baseTime;
|
|
64328
|
+
if (redirectPolicy !== void 0) {
|
|
64329
|
+
absoluteStaleAt = Math.min(absoluteStaleAt, redirectPolicy.staleAt);
|
|
64330
|
+
}
|
|
64248
64331
|
if (now >= absoluteStaleAt && !revalidationOnly) {
|
|
64249
64332
|
deleteCachedValueIfNotModified(statusCode, this.#store, this.#cacheKey);
|
|
64250
64333
|
return downstreamOnHeaders();
|
|
64251
64334
|
}
|
|
64252
64335
|
let varyDirectives;
|
|
64253
|
-
|
|
64254
|
-
|
|
64255
|
-
|
|
64256
|
-
|
|
64336
|
+
const combinedVary = [];
|
|
64337
|
+
if (redirectHopInfo) {
|
|
64338
|
+
for (const hop of redirectHopInfo) {
|
|
64339
|
+
appendVaryValues(combinedVary, hop?.headers?.vary);
|
|
64340
|
+
}
|
|
64341
|
+
}
|
|
64342
|
+
appendVaryValues(combinedVary, resHeaders.vary);
|
|
64343
|
+
if (combinedVary.length > 0) {
|
|
64344
|
+
for (const varyHeader of combinedVary) {
|
|
64345
|
+
if (hasVaryStar(varyHeader)) {
|
|
64346
|
+
return downstreamOnHeaders();
|
|
64347
|
+
}
|
|
64348
|
+
}
|
|
64349
|
+
if (this.#cacheKey.headers) {
|
|
64350
|
+
varyDirectives = parseVaryHeader(combinedVary, this.#cacheKey.headers);
|
|
64351
|
+
if (!varyDirectives) {
|
|
64352
|
+
return downstreamOnHeaders();
|
|
64353
|
+
}
|
|
64354
|
+
}
|
|
64355
|
+
}
|
|
64356
|
+
let effectiveCacheControlDirectives = cacheControlDirectives;
|
|
64357
|
+
if (redirectPolicy !== void 0) {
|
|
64358
|
+
effectiveCacheControlDirectives = { ...cacheControlDirectives };
|
|
64359
|
+
delete effectiveCacheControlDirectives["stale-while-revalidate"];
|
|
64360
|
+
delete effectiveCacheControlDirectives["stale-if-error"];
|
|
64361
|
+
if (redirectPolicy.requiresRevalidation === true) {
|
|
64362
|
+
effectiveCacheControlDirectives["proxy-revalidate"] = true;
|
|
64257
64363
|
}
|
|
64258
64364
|
}
|
|
64259
64365
|
const cachedAt = baseTime;
|
|
64260
|
-
const deleteAt = determineDeleteAt(baseTime, now,
|
|
64366
|
+
const deleteAt = determineDeleteAt(baseTime, now, effectiveCacheControlDirectives, absoluteStaleAt);
|
|
64261
64367
|
const strippedHeaders = stripNecessaryHeaders(resHeaders, cacheControlDirectives);
|
|
64262
64368
|
const value = {
|
|
64263
64369
|
statusCode,
|
|
64264
64370
|
statusMessage,
|
|
64265
64371
|
headers: strippedHeaders,
|
|
64266
64372
|
vary: varyDirectives,
|
|
64267
|
-
cacheControlDirectives,
|
|
64373
|
+
cacheControlDirectives: effectiveCacheControlDirectives,
|
|
64268
64374
|
cachedAt,
|
|
64269
64375
|
staleAt: absoluteStaleAt,
|
|
64270
64376
|
deleteAt
|
|
@@ -64278,6 +64384,13 @@ var require_cache_handler = __commonJS({
|
|
|
64278
64384
|
done = true;
|
|
64279
64385
|
this.#downstreamController.release();
|
|
64280
64386
|
};
|
|
64387
|
+
const failReplay = (err) => {
|
|
64388
|
+
if (done) {
|
|
64389
|
+
return;
|
|
64390
|
+
}
|
|
64391
|
+
done = true;
|
|
64392
|
+
controller.abort(err);
|
|
64393
|
+
};
|
|
64281
64394
|
const handle304 = (cachedValue) => {
|
|
64282
64395
|
if (!cachedValue) {
|
|
64283
64396
|
downstreamOnHeaders();
|
|
@@ -64301,14 +64414,18 @@ var require_cache_handler = __commonJS({
|
|
|
64301
64414
|
if (done) {
|
|
64302
64415
|
return;
|
|
64303
64416
|
}
|
|
64304
|
-
|
|
64305
|
-
const
|
|
64306
|
-
|
|
64307
|
-
|
|
64308
|
-
|
|
64417
|
+
try {
|
|
64418
|
+
for (const chunk of bodyIterator) {
|
|
64419
|
+
const full = this.#writeStream?.write(chunk) === false;
|
|
64420
|
+
this.#handler.onResponseData?.(this.#downstreamController, chunk);
|
|
64421
|
+
if (full) {
|
|
64422
|
+
return;
|
|
64423
|
+
}
|
|
64309
64424
|
}
|
|
64425
|
+
finish304();
|
|
64426
|
+
} catch (err) {
|
|
64427
|
+
failReplay(err);
|
|
64310
64428
|
}
|
|
64311
|
-
finish304();
|
|
64312
64429
|
};
|
|
64313
64430
|
this.#writeStream.on("error", function() {
|
|
64314
64431
|
handler.#writeStream = void 0;
|
|
@@ -64325,8 +64442,13 @@ var require_cache_handler = __commonJS({
|
|
|
64325
64442
|
streamCachedBody();
|
|
64326
64443
|
} else if (typeof cachedValue.body.on === "function") {
|
|
64327
64444
|
cachedValue.body.on("data", (chunk) => {
|
|
64328
|
-
|
|
64329
|
-
|
|
64445
|
+
try {
|
|
64446
|
+
this.#writeStream?.write(chunk);
|
|
64447
|
+
this.#handler.onResponseData?.(this.#downstreamController, chunk);
|
|
64448
|
+
} catch (err) {
|
|
64449
|
+
cachedValue.body.destroy();
|
|
64450
|
+
failReplay(err);
|
|
64451
|
+
}
|
|
64330
64452
|
}).on("end", () => {
|
|
64331
64453
|
this.#writeStream?.end();
|
|
64332
64454
|
finish304();
|
|
@@ -64443,6 +64565,74 @@ var require_cache_handler = __commonJS({
|
|
|
64443
64565
|
}
|
|
64444
64566
|
return true;
|
|
64445
64567
|
}
|
|
64568
|
+
function getRedirectPolicy(cacheType, method, redirectHops, reqHeaders, cacheByDefault, now) {
|
|
64569
|
+
let staleAt = Infinity;
|
|
64570
|
+
let requiresRevalidation = false;
|
|
64571
|
+
for (const hop of redirectHops) {
|
|
64572
|
+
const hopPolicy = getRedirectHopPolicy(cacheType, method, hop, reqHeaders, cacheByDefault);
|
|
64573
|
+
if (hopPolicy === void 0 || hopPolicy.staleAt <= now) {
|
|
64574
|
+
return void 0;
|
|
64575
|
+
}
|
|
64576
|
+
staleAt = Math.min(staleAt, hopPolicy.staleAt);
|
|
64577
|
+
requiresRevalidation ||= hopPolicy.requiresRevalidation;
|
|
64578
|
+
}
|
|
64579
|
+
return { staleAt, requiresRevalidation };
|
|
64580
|
+
}
|
|
64581
|
+
function getRedirectHopPolicy(cacheType, method, hop, reqHeaders, cacheByDefault) {
|
|
64582
|
+
if (!Number.isInteger(hop?.statusCode) || !Number.isFinite(hop?.receivedAt)) {
|
|
64583
|
+
return void 0;
|
|
64584
|
+
}
|
|
64585
|
+
const hopHeaders = hop.headers ?? {};
|
|
64586
|
+
const cacheControlHeader = hopHeaders["cache-control"];
|
|
64587
|
+
const hopCacheControl = cacheControlHeader ? parseCacheControlHeader(cacheControlHeader) : {};
|
|
64588
|
+
if (hopHeaders.vary && hasVaryStar(hopHeaders.vary)) {
|
|
64589
|
+
return void 0;
|
|
64590
|
+
}
|
|
64591
|
+
if (hopCacheControl["no-store"] === true) {
|
|
64592
|
+
return void 0;
|
|
64593
|
+
}
|
|
64594
|
+
if (cacheType === "shared" && Object.hasOwn(hopCacheControl, "private")) {
|
|
64595
|
+
return void 0;
|
|
64596
|
+
}
|
|
64597
|
+
if (Object.hasOwn(hopCacheControl, "no-cache") || hopCacheControl["must-revalidate"] === true || cacheType === "shared" && hopCacheControl["proxy-revalidate"] === true) {
|
|
64598
|
+
return void 0;
|
|
64599
|
+
}
|
|
64600
|
+
const heuristicallyCacheable = hopHeaders["last-modified"] && arrayIncludes(HEURISTICALLY_CACHEABLE_STATUS_CODES, hop.statusCode);
|
|
64601
|
+
if (!cacheControlHeader && !hopHeaders.expires && !heuristicallyCacheable && !cacheByDefault) {
|
|
64602
|
+
return void 0;
|
|
64603
|
+
}
|
|
64604
|
+
if (!canCacheResponse(cacheType, method, hop.statusCode, hopHeaders, hopCacheControl, reqHeaders)) {
|
|
64605
|
+
return void 0;
|
|
64606
|
+
}
|
|
64607
|
+
const age = Object.hasOwn(hopHeaders, "age") ? getAge(hopHeaders.age) : void 0;
|
|
64608
|
+
if (age !== void 0 && age >= MAX_RESPONSE_AGE) {
|
|
64609
|
+
return void 0;
|
|
64610
|
+
}
|
|
64611
|
+
const responseDate = Object.hasOwn(hopHeaders, "date") ? getDate(hopHeaders.date) : void 0;
|
|
64612
|
+
if (responseDate === null) {
|
|
64613
|
+
return void 0;
|
|
64614
|
+
}
|
|
64615
|
+
const apparentAge = responseDate ? Math.max(0, hop.receivedAt - responseDate.getTime()) : 0;
|
|
64616
|
+
const currentAge = Math.max(apparentAge, age ?? 0);
|
|
64617
|
+
const hasValidator = typeof hopHeaders.etag === "string" && isEtagUsable(hopHeaders.etag) || typeof hopHeaders["last-modified"] === "string";
|
|
64618
|
+
const freshnessLifetime = determineStaleAt(
|
|
64619
|
+
cacheType,
|
|
64620
|
+
hop.receivedAt,
|
|
64621
|
+
age,
|
|
64622
|
+
hopHeaders,
|
|
64623
|
+
responseDate,
|
|
64624
|
+
hopCacheControl,
|
|
64625
|
+
hasValidator
|
|
64626
|
+
) ?? cacheByDefault;
|
|
64627
|
+
if (freshnessLifetime === void 0) {
|
|
64628
|
+
return void 0;
|
|
64629
|
+
}
|
|
64630
|
+
return {
|
|
64631
|
+
staleAt: hop.receivedAt - currentAge + freshnessLifetime,
|
|
64632
|
+
// RFC 9111 §5.2.2.10: s-maxage implies proxy-revalidate for shared caches.
|
|
64633
|
+
requiresRevalidation: cacheType === "shared" && Object.hasOwn(hopCacheControl, "s-maxage")
|
|
64634
|
+
};
|
|
64635
|
+
}
|
|
64446
64636
|
function getDate(dateHeader) {
|
|
64447
64637
|
let dateValue = dateHeader;
|
|
64448
64638
|
if (Array.isArray(dateValue)) {
|
|
@@ -64944,7 +65134,8 @@ var require_cache2 = __commonJS({
|
|
|
64944
65134
|
normalizeHeaders,
|
|
64945
65135
|
parseCacheControlHeader,
|
|
64946
65136
|
isInvalidOrWildcardVaryHeader,
|
|
64947
|
-
parseVaryHeader
|
|
65137
|
+
parseVaryHeader,
|
|
65138
|
+
isEtagUsable
|
|
64948
65139
|
} = require_cache();
|
|
64949
65140
|
var { AbortError } = require_errors();
|
|
64950
65141
|
var { parseHttpDate } = require_date();
|
|
@@ -65064,6 +65255,34 @@ var require_cache2 = __commonJS({
|
|
|
65064
65255
|
}
|
|
65065
65256
|
return headers;
|
|
65066
65257
|
}
|
|
65258
|
+
function revalidationTargetMatchesCacheKey(cacheKey, context) {
|
|
65259
|
+
const history = context?.history;
|
|
65260
|
+
if (!Array.isArray(history) || history.length === 0) {
|
|
65261
|
+
return true;
|
|
65262
|
+
}
|
|
65263
|
+
try {
|
|
65264
|
+
const cachedUrl = new URL(cacheKey.path, cacheKey.origin);
|
|
65265
|
+
const responseUrl = history[history.length - 1];
|
|
65266
|
+
return responseUrl.origin === cachedUrl.origin && responseUrl.pathname === cachedUrl.pathname && responseUrl.search === cachedUrl.search;
|
|
65267
|
+
} catch {
|
|
65268
|
+
return false;
|
|
65269
|
+
}
|
|
65270
|
+
}
|
|
65271
|
+
function revalidationEtagMatchesCachedValue(result, headers) {
|
|
65272
|
+
if (!Object.hasOwn(headers, "etag")) {
|
|
65273
|
+
return true;
|
|
65274
|
+
}
|
|
65275
|
+
const responseEtag = headers.etag;
|
|
65276
|
+
const cachedEtag = result.etag;
|
|
65277
|
+
if (typeof responseEtag !== "string" || typeof cachedEtag !== "string" || !isEtagUsable(responseEtag) || !isEtagUsable(cachedEtag)) {
|
|
65278
|
+
return false;
|
|
65279
|
+
}
|
|
65280
|
+
if (!responseEtag.startsWith("W/")) {
|
|
65281
|
+
return responseEtag === cachedEtag;
|
|
65282
|
+
}
|
|
65283
|
+
const cachedOpaqueTag = cachedEtag.startsWith("W/") ? cachedEtag.slice(2) : cachedEtag;
|
|
65284
|
+
return responseEtag.slice(2) === cachedOpaqueTag;
|
|
65285
|
+
}
|
|
65067
65286
|
function isStale(result, cacheControlDirectives, cacheType) {
|
|
65068
65287
|
const now = Date.now();
|
|
65069
65288
|
if (now > result.staleAt || result.staleAt <= result.cachedAt) {
|
|
@@ -65161,18 +65380,23 @@ var require_cache2 = __commonJS({
|
|
|
65161
65380
|
};
|
|
65162
65381
|
stream5.on("error", function(err) {
|
|
65163
65382
|
if (!this.readableEnded) {
|
|
65164
|
-
|
|
65165
|
-
handler.onResponseError(controller, err);
|
|
65166
|
-
} else {
|
|
65167
|
-
throw err;
|
|
65168
|
-
}
|
|
65383
|
+
handler.onResponseError?.(controller, err);
|
|
65169
65384
|
}
|
|
65170
65385
|
}).on("close", function() {
|
|
65171
65386
|
if (!this.errored) {
|
|
65172
|
-
|
|
65387
|
+
try {
|
|
65388
|
+
handler.onResponseEnd?.(controller, {});
|
|
65389
|
+
} catch (err) {
|
|
65390
|
+
handler.onResponseError?.(controller, err);
|
|
65391
|
+
}
|
|
65173
65392
|
}
|
|
65174
65393
|
});
|
|
65175
|
-
|
|
65394
|
+
try {
|
|
65395
|
+
handler.onRequestStart?.(controller, context);
|
|
65396
|
+
} catch (err) {
|
|
65397
|
+
stream5.destroy(err);
|
|
65398
|
+
return;
|
|
65399
|
+
}
|
|
65176
65400
|
if (stream5.destroyed) {
|
|
65177
65401
|
return;
|
|
65178
65402
|
}
|
|
@@ -65181,12 +65405,21 @@ var require_cache2 = __commonJS({
|
|
|
65181
65405
|
headers.warning = '110 - "response is stale"';
|
|
65182
65406
|
}
|
|
65183
65407
|
controller.rawHeaders = util2.toRawHeaders(headers);
|
|
65184
|
-
|
|
65408
|
+
try {
|
|
65409
|
+
handler.onResponseStart?.(controller, result.statusCode, headers, result.statusMessage);
|
|
65410
|
+
} catch (err) {
|
|
65411
|
+
stream5.destroy(err);
|
|
65412
|
+
return;
|
|
65413
|
+
}
|
|
65185
65414
|
if (opts.method === "HEAD") {
|
|
65186
65415
|
stream5.destroy();
|
|
65187
65416
|
} else {
|
|
65188
65417
|
stream5.on("data", function(chunk) {
|
|
65189
|
-
|
|
65418
|
+
try {
|
|
65419
|
+
handler.onResponseData?.(controller, chunk);
|
|
65420
|
+
} catch (err) {
|
|
65421
|
+
stream5.destroy(err);
|
|
65422
|
+
}
|
|
65190
65423
|
});
|
|
65191
65424
|
}
|
|
65192
65425
|
}
|
|
@@ -65249,6 +65482,13 @@ var require_cache2 = __commonJS({
|
|
|
65249
65482
|
}
|
|
65250
65483
|
}
|
|
65251
65484
|
const headers = makeRevalidationHeaders(opts, result);
|
|
65485
|
+
const refetch = () => {
|
|
65486
|
+
if (util2.isStream(result.body)) {
|
|
65487
|
+
result.body.on("error", nop).destroy();
|
|
65488
|
+
}
|
|
65489
|
+
deleteCachedValue(globalOpts.store, cacheKey);
|
|
65490
|
+
return dispatch(opts, new CacheHandler(globalOpts, cacheKey, handler));
|
|
65491
|
+
};
|
|
65252
65492
|
return dispatch(
|
|
65253
65493
|
{
|
|
65254
65494
|
...opts,
|
|
@@ -65258,21 +65498,13 @@ var require_cache2 = __commonJS({
|
|
|
65258
65498
|
(success, context, statusCode, headers2) => {
|
|
65259
65499
|
if (success) {
|
|
65260
65500
|
if (statusCode === 304) {
|
|
65261
|
-
if (revalidationResponseDisallowsCachedReuse(globalOpts.type, headers2)) {
|
|
65262
|
-
|
|
65263
|
-
result.body.on("error", nop).destroy();
|
|
65264
|
-
}
|
|
65265
|
-
deleteCachedValue(globalOpts.store, cacheKey);
|
|
65266
|
-
return dispatch(opts, new CacheHandler(globalOpts, cacheKey, handler));
|
|
65501
|
+
if (!revalidationTargetMatchesCacheKey(cacheKey, context) || !revalidationEtagMatchesCachedValue(result, headers2) || revalidationResponseDisallowsCachedReuse(globalOpts.type, headers2)) {
|
|
65502
|
+
return refetch();
|
|
65267
65503
|
}
|
|
65268
65504
|
if (revalidationResponseUpdatesCacheControl(headers2)) {
|
|
65269
65505
|
deleteCachedValue(globalOpts.store, cacheKey);
|
|
65270
65506
|
} else if (revalidationResponseAddsVary(result, headers2.vary ? parseVaryHeader(headers2.vary, opts.headers) : void 0)) {
|
|
65271
|
-
|
|
65272
|
-
result.body.on("error", nop).destroy();
|
|
65273
|
-
}
|
|
65274
|
-
deleteCachedValue(globalOpts.store, cacheKey);
|
|
65275
|
-
return dispatch(opts, new CacheHandler(globalOpts, cacheKey, handler));
|
|
65507
|
+
return refetch();
|
|
65276
65508
|
}
|
|
65277
65509
|
}
|
|
65278
65510
|
sendCachedValue(handler, opts, result, age, context, stale);
|
|
@@ -65370,7 +65602,31 @@ var require_cache2 = __commonJS({
|
|
|
65370
65602
|
opts2,
|
|
65371
65603
|
reqCacheControl,
|
|
65372
65604
|
result2
|
|
65373
|
-
))
|
|
65605
|
+
)).catch((err) => {
|
|
65606
|
+
if (typeof handler.onResponseError === "function") {
|
|
65607
|
+
handler.onResponseError({
|
|
65608
|
+
rawHeaders: [],
|
|
65609
|
+
rawTrailers: [],
|
|
65610
|
+
pause() {
|
|
65611
|
+
},
|
|
65612
|
+
resume() {
|
|
65613
|
+
},
|
|
65614
|
+
get paused() {
|
|
65615
|
+
return false;
|
|
65616
|
+
},
|
|
65617
|
+
get aborted() {
|
|
65618
|
+
return false;
|
|
65619
|
+
},
|
|
65620
|
+
get reason() {
|
|
65621
|
+
return null;
|
|
65622
|
+
},
|
|
65623
|
+
abort() {
|
|
65624
|
+
}
|
|
65625
|
+
}, err);
|
|
65626
|
+
} else {
|
|
65627
|
+
throw err;
|
|
65628
|
+
}
|
|
65629
|
+
});
|
|
65374
65630
|
} else {
|
|
65375
65631
|
return handleResult(
|
|
65376
65632
|
dispatch,
|
|
@@ -66378,10 +66634,15 @@ var require_sqlite_cache_store = __commonJS({
|
|
|
66378
66634
|
var { assertCacheKey, assertCacheValue } = require_cache();
|
|
66379
66635
|
var { zstdCompressSync, zstdDecompressSync } = __require("node:zlib");
|
|
66380
66636
|
var DatabaseSync;
|
|
66381
|
-
var VERSION3 =
|
|
66637
|
+
var VERSION3 = 5;
|
|
66382
66638
|
var MAX_ENTRY_SIZE = 2 * 1e3 * 1e3 * 1e3;
|
|
66383
66639
|
var COMPRESS_THRESHOLD = 1024 * 1024;
|
|
66384
66640
|
var hasZstd = typeof zstdCompressSync === "function" && typeof zstdDecompressSync === "function";
|
|
66641
|
+
var SQLITE_BUSY = 5;
|
|
66642
|
+
var SQLITE_LOCKED = 6;
|
|
66643
|
+
function isLockedError(err) {
|
|
66644
|
+
return err?.errcode === SQLITE_BUSY || err?.errcode === SQLITE_LOCKED;
|
|
66645
|
+
}
|
|
66385
66646
|
module.exports = class SqliteCacheStore {
|
|
66386
66647
|
#maxEntrySize = MAX_ENTRY_SIZE;
|
|
66387
66648
|
#maxCount = Infinity;
|
|
@@ -66564,7 +66825,7 @@ var require_sqlite_cache_store = __commonJS({
|
|
|
66564
66825
|
*/
|
|
66565
66826
|
get(key) {
|
|
66566
66827
|
assertCacheKey(key);
|
|
66567
|
-
const value = this.#findValue(key);
|
|
66828
|
+
const value = this.#lockSafe(() => this.#findValue(key));
|
|
66568
66829
|
return value ? {
|
|
66569
66830
|
body: value.body ? value.compressed === "zstd" ? zstdDecompressSync(Buffer.from(value.body.buffer, value.body.byteOffset, value.body.byteLength)) : Buffer.from(value.body.buffer, value.body.byteOffset, value.body.byteLength) : void 0,
|
|
66570
66831
|
statusCode: value.statusCode,
|
|
@@ -66599,9 +66860,9 @@ var require_sqlite_cache_store = __commonJS({
|
|
|
66599
66860
|
compressed = "zstd";
|
|
66600
66861
|
}
|
|
66601
66862
|
}
|
|
66602
|
-
const existingValue = this.#findValue(key, true);
|
|
66863
|
+
const existingValue = this.#lockSafe(() => this.#findValue(key, true));
|
|
66603
66864
|
if (existingValue) {
|
|
66604
|
-
this.#updateValueQuery.run(
|
|
66865
|
+
this.#lockSafe(() => this.#updateValueQuery.run(
|
|
66605
66866
|
storedBody,
|
|
66606
66867
|
compressed,
|
|
66607
66868
|
value.deleteAt,
|
|
@@ -66614,9 +66875,9 @@ var require_sqlite_cache_store = __commonJS({
|
|
|
66614
66875
|
value.cachedAt,
|
|
66615
66876
|
value.staleAt,
|
|
66616
66877
|
existingValue.id
|
|
66617
|
-
);
|
|
66878
|
+
));
|
|
66618
66879
|
} else {
|
|
66619
|
-
this.#insertValueQuery.run(
|
|
66880
|
+
this.#lockSafe(() => this.#insertValueQuery.run(
|
|
66620
66881
|
url,
|
|
66621
66882
|
key.method,
|
|
66622
66883
|
storedBody,
|
|
@@ -66630,7 +66891,7 @@ var require_sqlite_cache_store = __commonJS({
|
|
|
66630
66891
|
value.vary ? JSON.stringify(value.vary) : null,
|
|
66631
66892
|
value.cachedAt,
|
|
66632
66893
|
value.staleAt
|
|
66633
|
-
);
|
|
66894
|
+
));
|
|
66634
66895
|
this.#prune();
|
|
66635
66896
|
}
|
|
66636
66897
|
}
|
|
@@ -66669,20 +66930,46 @@ var require_sqlite_cache_store = __commonJS({
|
|
|
66669
66930
|
if (typeof key !== "object") {
|
|
66670
66931
|
throw new TypeError(`expected key to be object, got ${typeof key}`);
|
|
66671
66932
|
}
|
|
66672
|
-
this.#deleteByUrlQuery.run(this.#makeValueUrl(key));
|
|
66933
|
+
this.#lockSafe(() => this.#deleteByUrlQuery.run(this.#makeValueUrl(key)));
|
|
66934
|
+
}
|
|
66935
|
+
/**
|
|
66936
|
+
* Runs a database operation, skipping it when another connection holds the
|
|
66937
|
+
* database lock.
|
|
66938
|
+
*
|
|
66939
|
+
* The cache store is meant to be shared between processes, and SQLite reports
|
|
66940
|
+
* a concurrent writer as SQLITE_BUSY/SQLITE_LOCKED. Those errors are
|
|
66941
|
+
* transient, and caching is best effort: the entry is skipped and the next
|
|
66942
|
+
* request retries, rather than failing the request that triggered the write.
|
|
66943
|
+
*
|
|
66944
|
+
* @template T
|
|
66945
|
+
* @param {() => T} fn
|
|
66946
|
+
* @returns {T | undefined}
|
|
66947
|
+
*/
|
|
66948
|
+
#lockSafe(fn) {
|
|
66949
|
+
try {
|
|
66950
|
+
return fn();
|
|
66951
|
+
} catch (err) {
|
|
66952
|
+
if (!isLockedError(err)) {
|
|
66953
|
+
throw err;
|
|
66954
|
+
}
|
|
66955
|
+
return void 0;
|
|
66956
|
+
}
|
|
66673
66957
|
}
|
|
66674
66958
|
#prune() {
|
|
66675
|
-
if (Number.isFinite(this.#maxCount)
|
|
66676
|
-
|
|
66959
|
+
if (Number.isFinite(this.#maxCount)) {
|
|
66960
|
+
const size = this.#lockSafe(() => this.size);
|
|
66961
|
+
if (size === void 0 || size <= this.#maxCount) {
|
|
66962
|
+
return 0;
|
|
66963
|
+
}
|
|
66677
66964
|
}
|
|
66678
66965
|
{
|
|
66679
|
-
const removed = this.#deleteExpiredValuesQuery.run(Date.now()).changes;
|
|
66966
|
+
const removed = this.#lockSafe(() => this.#deleteExpiredValuesQuery.run(Date.now()).changes);
|
|
66680
66967
|
if (removed) {
|
|
66681
66968
|
return removed;
|
|
66682
66969
|
}
|
|
66683
66970
|
}
|
|
66684
66971
|
{
|
|
66685
|
-
const removed = this.#deleteOldValuesQuery?.run(Math.max(Math.floor(this.#maxCount * 0.1), 1)).changes;
|
|
66972
|
+
const removed = this.#lockSafe(() => this.#deleteOldValuesQuery?.run(Math.max(Math.floor(this.#maxCount * 0.1), 1)).changes);
|
|
66686
66973
|
if (removed) {
|
|
66687
66974
|
return removed;
|
|
66688
66975
|
}
|
|
@@ -67671,41 +67958,64 @@ var require_request2 = __commonJS({
|
|
|
67671
67958
|
var { URLSerializer } = require_data_url();
|
|
67672
67959
|
var { kConstruct } = require_symbols();
|
|
67673
67960
|
var assert = __require("node:assert");
|
|
67674
|
-
var {
|
|
67675
|
-
|
|
67676
|
-
var requestFinalizer = new FinalizationRegistry(({ signal, abort }) => {
|
|
67677
|
-
signal.removeEventListener("abort", abort);
|
|
67961
|
+
var requestFinalizer = new FinalizationRegistry(({ signal, reference }) => {
|
|
67962
|
+
removeSignalFollower(signal, reference);
|
|
67678
67963
|
});
|
|
67679
|
-
var
|
|
67680
|
-
var
|
|
67681
|
-
|
|
67682
|
-
|
|
67683
|
-
|
|
67684
|
-
|
|
67685
|
-
|
|
67686
|
-
|
|
67687
|
-
|
|
67688
|
-
|
|
67689
|
-
|
|
67690
|
-
|
|
67691
|
-
|
|
67692
|
-
|
|
67693
|
-
|
|
67694
|
-
|
|
67695
|
-
|
|
67696
|
-
|
|
67697
|
-
|
|
67698
|
-
|
|
67699
|
-
|
|
67700
|
-
|
|
67701
|
-
|
|
67702
|
-
|
|
67703
|
-
|
|
67704
|
-
|
|
67705
|
-
|
|
67706
|
-
|
|
67707
|
-
|
|
67964
|
+
var requestSignals = /* @__PURE__ */ new WeakMap();
|
|
67965
|
+
var signalFollowers = /* @__PURE__ */ new WeakMap();
|
|
67966
|
+
function removeSignalFollower(signal, reference) {
|
|
67967
|
+
const followers = signalFollowers.get(signal);
|
|
67968
|
+
if (followers instanceof Set) {
|
|
67969
|
+
followers.delete(reference);
|
|
67970
|
+
if (followers.size !== 0) return;
|
|
67971
|
+
}
|
|
67972
|
+
signal.removeEventListener("abort", abortSignalFollowers);
|
|
67973
|
+
signalFollowers.delete(signal);
|
|
67974
|
+
}
|
|
67975
|
+
function abortSignalFollower(reference, reason) {
|
|
67976
|
+
requestFinalizer.unregister(reference);
|
|
67977
|
+
const ac = reference.deref();
|
|
67978
|
+
if (ac !== void 0) {
|
|
67979
|
+
requestSignals.delete(ac.signal);
|
|
67980
|
+
ac.abort(reason);
|
|
67981
|
+
}
|
|
67982
|
+
}
|
|
67983
|
+
function abortSignalFollowers() {
|
|
67984
|
+
this.removeEventListener("abort", abortSignalFollowers);
|
|
67985
|
+
const followers = signalFollowers.get(this);
|
|
67986
|
+
if (followers instanceof Set) {
|
|
67987
|
+
for (const reference of followers) {
|
|
67988
|
+
abortSignalFollower(reference, this.reason);
|
|
67989
|
+
}
|
|
67990
|
+
followers.clear();
|
|
67991
|
+
} else {
|
|
67992
|
+
abortSignalFollower(followers, this.reason);
|
|
67993
|
+
}
|
|
67994
|
+
signalFollowers.delete(this);
|
|
67995
|
+
}
|
|
67996
|
+
function createDependentSignal(signal) {
|
|
67997
|
+
const ac = new AbortController();
|
|
67998
|
+
if (signal == null) return ac.signal;
|
|
67999
|
+
if (signal.aborted) {
|
|
68000
|
+
ac.abort(signal.reason);
|
|
68001
|
+
return ac.signal;
|
|
68002
|
+
}
|
|
68003
|
+
const reference = new WeakRef(ac);
|
|
68004
|
+
const followers = signalFollowers.get(signal);
|
|
68005
|
+
if (followers === void 0) {
|
|
68006
|
+
util2.addAbortListener(signal, abortSignalFollowers);
|
|
68007
|
+
signalFollowers.set(signal, reference);
|
|
68008
|
+
} else if (followers instanceof WeakRef) {
|
|
68009
|
+
const controllers = /* @__PURE__ */ new Set();
|
|
68010
|
+
controllers.add(followers);
|
|
68011
|
+
controllers.add(reference);
|
|
68012
|
+
signalFollowers.set(signal, controllers);
|
|
68013
|
+
} else {
|
|
68014
|
+
followers.add(reference);
|
|
67708
68015
|
}
|
|
68016
|
+
requestFinalizer.register(ac, { signal, reference }, reference);
|
|
68017
|
+
requestSignals.set(ac.signal, { controller: ac, source: signal, reference });
|
|
68018
|
+
return ac.signal;
|
|
67709
68019
|
}
|
|
67710
68020
|
var patchMethodWarning = false;
|
|
67711
68021
|
var setRequestSignal;
|
|
@@ -67723,12 +68033,6 @@ var require_request2 = __commonJS({
|
|
|
67723
68033
|
/** @type {Headers} */
|
|
67724
68034
|
#headers;
|
|
67725
68035
|
#state;
|
|
67726
|
-
/**
|
|
67727
|
-
* Removes the `abort` listener that makes this request's signal follow the
|
|
67728
|
-
* passed signal. `null` when no such listener was registered.
|
|
67729
|
-
* @type {(() => void) | null}
|
|
67730
|
-
*/
|
|
67731
|
-
#abortCleanup = null;
|
|
67732
68036
|
// https://fetch.spec.whatwg.org/#dom-request
|
|
67733
68037
|
constructor(input, init = void 0) {
|
|
67734
68038
|
webidl.util.markAsUncloneable(this);
|
|
@@ -67914,27 +68218,7 @@ var require_request2 = __commonJS({
|
|
|
67914
68218
|
signal = init.signal;
|
|
67915
68219
|
}
|
|
67916
68220
|
this.#state = request;
|
|
67917
|
-
|
|
67918
|
-
this.#signal = ac.signal;
|
|
67919
|
-
if (signal != null) {
|
|
67920
|
-
if (signal.aborted) {
|
|
67921
|
-
ac.abort(signal.reason);
|
|
67922
|
-
} else {
|
|
67923
|
-
this[kAbortController] = ac;
|
|
67924
|
-
const acRef = new WeakRef(ac);
|
|
67925
|
-
const abort = buildAbort(acRef);
|
|
67926
|
-
if (abortSignalHasEventHandlerLeakWarning && getMaxListeners(signal) === defaultMaxListeners) {
|
|
67927
|
-
setMaxListeners(1500, signal);
|
|
67928
|
-
}
|
|
67929
|
-
const removeAbortListener = util2.addAbortListener(signal, abort);
|
|
67930
|
-
requestFinalizer.register(ac, { signal, abort }, abort);
|
|
67931
|
-
this.#abortCleanup = () => {
|
|
67932
|
-
requestFinalizer.unregister(abort);
|
|
67933
|
-
removeAbortListener();
|
|
67934
|
-
this.#abortCleanup = null;
|
|
67935
|
-
};
|
|
67936
|
-
}
|
|
67937
|
-
}
|
|
68221
|
+
this.#signal = createDependentSignal(signal);
|
|
67938
68222
|
this.#headers = new Headers2(kConstruct);
|
|
67939
68223
|
setHeadersList(this.#headers, request.headersList);
|
|
67940
68224
|
setHeadersGuard(this.#headers, "request");
|
|
@@ -68128,23 +68412,8 @@ var require_request2 = __commonJS({
|
|
|
68128
68412
|
throw new TypeError("unusable");
|
|
68129
68413
|
}
|
|
68130
68414
|
const clonedRequest = cloneRequest(this.#state);
|
|
68131
|
-
const
|
|
68132
|
-
|
|
68133
|
-
ac.abort(this.signal.reason);
|
|
68134
|
-
} else {
|
|
68135
|
-
let list = dependentControllerMap.get(this.signal);
|
|
68136
|
-
if (list === void 0) {
|
|
68137
|
-
list = /* @__PURE__ */ new Set();
|
|
68138
|
-
dependentControllerMap.set(this.signal, list);
|
|
68139
|
-
}
|
|
68140
|
-
const acRef = new WeakRef(ac);
|
|
68141
|
-
list.add(acRef);
|
|
68142
|
-
util2.addAbortListener(
|
|
68143
|
-
ac.signal,
|
|
68144
|
-
buildAbort(acRef)
|
|
68145
|
-
);
|
|
68146
|
-
}
|
|
68147
|
-
return fromInnerRequest(clonedRequest, this.#dispatcher, ac.signal, getHeadersGuard(this.#headers));
|
|
68415
|
+
const signal = createDependentSignal(this.#signal);
|
|
68416
|
+
return fromInnerRequest(clonedRequest, this.#dispatcher, signal, getHeadersGuard(this.#headers));
|
|
68148
68417
|
}
|
|
68149
68418
|
[nodeUtil.inspect.custom](depth, options) {
|
|
68150
68419
|
if (options.depth === null) {
|
|
@@ -68190,7 +68459,12 @@ var require_request2 = __commonJS({
|
|
|
68190
68459
|
request.#state = newState;
|
|
68191
68460
|
};
|
|
68192
68461
|
removeRequestAbortListener = (request) => {
|
|
68193
|
-
request.#
|
|
68462
|
+
const state2 = requestSignals.get(request.#signal);
|
|
68463
|
+
if (state2 !== void 0) {
|
|
68464
|
+
requestSignals.delete(request.#signal);
|
|
68465
|
+
requestFinalizer.unregister(state2.reference);
|
|
68466
|
+
removeSignalFollower(state2.source, state2.reference);
|
|
68467
|
+
}
|
|
68194
68468
|
};
|
|
68195
68469
|
webidl.is.Request = (arg) => {
|
|
68196
68470
|
return arg != null && typeof arg === "object" && #state in arg;
|
|
@@ -68472,7 +68746,7 @@ var require_subresource_integrity = __commonJS({
|
|
|
68472
68746
|
}
|
|
68473
68747
|
function parseMetadata(metadata) {
|
|
68474
68748
|
const result = [];
|
|
68475
|
-
for (const item of metadata.split(
|
|
68749
|
+
for (const item of metadata.split(/[\t\n\f\r ]+/)) {
|
|
68476
68750
|
const expressionAndOptions = item.split("?", 1);
|
|
68477
68751
|
const algorithmExpression = expressionAndOptions[0];
|
|
68478
68752
|
let base64Value = "";
|
|
@@ -68723,11 +68997,8 @@ var require_fetch = __commonJS({
|
|
|
68723
68997
|
cleanupAbortListeners();
|
|
68724
68998
|
},
|
|
68725
68999
|
processResponse,
|
|
68726
|
-
dispatcher: getRequestDispatcher(requestObject)
|
|
69000
|
+
dispatcher: getRequestDispatcher(requestObject)
|
|
68727
69001
|
// undici
|
|
68728
|
-
// Keep requestObject alive to prevent its AbortController from being GC'd
|
|
68729
|
-
// See https://github.com/nodejs/undici/issues/4627
|
|
68730
|
-
requestObject
|
|
68731
69002
|
});
|
|
68732
69003
|
return p.promise;
|
|
68733
69004
|
}
|
|
@@ -68795,10 +69066,8 @@ var require_fetch = __commonJS({
|
|
|
68795
69066
|
processResponseEndOfBody,
|
|
68796
69067
|
processResponseConsumeBody,
|
|
68797
69068
|
useParallelQueue = false,
|
|
68798
|
-
dispatcher = getGlobalDispatcher()
|
|
69069
|
+
dispatcher = getGlobalDispatcher()
|
|
68799
69070
|
// undici
|
|
68800
|
-
requestObject = null
|
|
68801
|
-
// Keep alive to prevent AbortController GC, see #4627
|
|
68802
69071
|
}) {
|
|
68803
69072
|
assert(dispatcher);
|
|
68804
69073
|
let taskDestination = null;
|
|
@@ -68821,9 +69090,7 @@ var require_fetch = __commonJS({
|
|
|
68821
69090
|
processResponseConsumeBody,
|
|
68822
69091
|
processResponseEndOfBody,
|
|
68823
69092
|
taskDestination,
|
|
68824
|
-
crossOriginIsolatedCapability
|
|
68825
|
-
// Keep requestObject alive to prevent its AbortController from being GC'd
|
|
68826
|
-
requestObject
|
|
69093
|
+
crossOriginIsolatedCapability
|
|
68827
69094
|
};
|
|
68828
69095
|
assert(!request.body || request.body.stream);
|
|
68829
69096
|
if (request.window === "client") {
|
|
@@ -74122,7 +74389,7 @@ import dc from "node:diagnostics_channel";
|
|
|
74122
74389
|
import { credentialRef } from "@deepseek-ai/dsh-credentials";
|
|
74123
74390
|
import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
|
|
74124
74391
|
import * as llm2 from "@deepseek-ai/dsh-llm";
|
|
74125
|
-
import { LlmError as
|
|
74392
|
+
import { LlmError as LlmError13 } from "@deepseek-ai/dsh-llm";
|
|
74126
74393
|
|
|
74127
74394
|
// src/adapter.ts
|
|
74128
74395
|
init_models();
|
|
@@ -74178,6 +74445,14 @@ var openAIResponsesApi = () => lazyApi(() => Promise.resolve().then(() => (init_
|
|
|
74178
74445
|
// src/catalog/index.ts
|
|
74179
74446
|
import { attributionHeaders as attributionHeaders3, LlmError as LlmError4 } from "@deepseek-ai/dsh-llm";
|
|
74180
74447
|
|
|
74448
|
+
// src/llm-error.ts
|
|
74449
|
+
import { LlmError } from "@deepseek-ai/dsh-llm";
|
|
74450
|
+
function llmFailure(message, code, options) {
|
|
74451
|
+
const raise = LlmError.fromFailure;
|
|
74452
|
+
if (typeof raise === "function") return raise.call(LlmError, { message, code }, options);
|
|
74453
|
+
return new LlmError(message, code, options);
|
|
74454
|
+
}
|
|
74455
|
+
|
|
74181
74456
|
// src/catalog/constants.ts
|
|
74182
74457
|
var PROVIDER_ID = "opencode-go";
|
|
74183
74458
|
var DISPLAY_NAME = "OpenCode Go";
|
|
@@ -74195,29 +74470,29 @@ var UNKNOWN_MODEL_PROBE_COOLDOWN_MS = 5 * 6e4;
|
|
|
74195
74470
|
var MAX_CATALOG_STALENESS_MS = 24 * 60 * 6e4;
|
|
74196
74471
|
|
|
74197
74472
|
// src/catalog/gateway.ts
|
|
74198
|
-
import { attributionHeaders, LlmError as
|
|
74473
|
+
import { attributionHeaders, LlmError as LlmError3 } from "@deepseek-ai/dsh-llm";
|
|
74199
74474
|
|
|
74200
74475
|
// src/catalog/json-response.ts
|
|
74201
|
-
import { LlmError } from "@deepseek-ai/dsh-llm";
|
|
74476
|
+
import { LlmError as LlmError2 } from "@deepseek-ai/dsh-llm";
|
|
74202
74477
|
async function readBoundedJson(response, url, maxBytes) {
|
|
74203
74478
|
const declared = Number(response.headers.get("content-length") ?? Number.NaN);
|
|
74204
74479
|
if (Number.isFinite(declared) && declared > maxBytes) {
|
|
74205
74480
|
await response.body?.cancel().catch(() => {
|
|
74206
74481
|
});
|
|
74207
|
-
throw new
|
|
74482
|
+
throw new LlmError2(`${url} declares ${declared} bytes, over the ${maxBytes}-byte cap`, "DISCOVERY_FAILED");
|
|
74208
74483
|
}
|
|
74209
74484
|
let text2;
|
|
74210
74485
|
try {
|
|
74211
74486
|
text2 = await readBoundedText(response, maxBytes);
|
|
74212
74487
|
} catch (error) {
|
|
74213
|
-
if (error instanceof
|
|
74488
|
+
if (error instanceof LlmError2) throw error;
|
|
74214
74489
|
const detail = error instanceof Error ? error.message : String(error);
|
|
74215
|
-
throw new
|
|
74490
|
+
throw new LlmError2(`could not read ${url}: ${detail}`, "DISCOVERY_FAILED", { cause: error });
|
|
74216
74491
|
}
|
|
74217
74492
|
try {
|
|
74218
74493
|
return JSON.parse(text2);
|
|
74219
74494
|
} catch (error) {
|
|
74220
|
-
throw new
|
|
74495
|
+
throw new LlmError2(`${url} did not answer with JSON`, "DISCOVERY_FAILED", { cause: error });
|
|
74221
74496
|
}
|
|
74222
74497
|
}
|
|
74223
74498
|
async function readBoundedText(response, maxBytes) {
|
|
@@ -74233,7 +74508,7 @@ async function readBoundedText(response, maxBytes) {
|
|
|
74233
74508
|
if (total > maxBytes) {
|
|
74234
74509
|
await reader.cancel().catch(() => {
|
|
74235
74510
|
});
|
|
74236
|
-
throw new
|
|
74511
|
+
throw new LlmError2(`response exceeds the ${maxBytes}-byte cap`, "DISCOVERY_FAILED");
|
|
74237
74512
|
}
|
|
74238
74513
|
chunks.push(value);
|
|
74239
74514
|
}
|
|
@@ -74272,23 +74547,23 @@ async function fetchModelIds(baseURL, signal, request = globalThis.fetch) {
|
|
|
74272
74547
|
headers: { ...attributionHeaders(), accept: "application/json", "cache-control": "no-cache" },
|
|
74273
74548
|
signal: signal === void 0 ? timeout : AbortSignal.any([signal, timeout])
|
|
74274
74549
|
}).catch((error) => {
|
|
74275
|
-
throw new
|
|
74550
|
+
throw new LlmError3(`could not reach ${url}`, "DISCOVERY_FAILED", { cause: error });
|
|
74276
74551
|
});
|
|
74277
74552
|
if (!response.ok) {
|
|
74278
74553
|
await response.body?.cancel().catch(() => {
|
|
74279
74554
|
});
|
|
74280
|
-
throw new
|
|
74555
|
+
throw new LlmError3(`${url} answered HTTP ${response.status}`, "DISCOVERY_FAILED");
|
|
74281
74556
|
}
|
|
74282
74557
|
const body = await readBoundedJson(response, url, MODEL_LISTING_MAX_BYTES);
|
|
74283
74558
|
try {
|
|
74284
74559
|
return readModelIds(body);
|
|
74285
74560
|
} catch (error) {
|
|
74286
|
-
throw new
|
|
74561
|
+
throw new LlmError3(`${url} returned an invalid model listing`, "DISCOVERY_FAILED", { cause: error });
|
|
74287
74562
|
}
|
|
74288
74563
|
}
|
|
74289
74564
|
|
|
74290
74565
|
// src/catalog/go-doc.ts
|
|
74291
|
-
import { attributionHeaders as attributionHeaders2
|
|
74566
|
+
import { attributionHeaders as attributionHeaders2 } from "@deepseek-ai/dsh-llm";
|
|
74292
74567
|
|
|
74293
74568
|
// src/catalog/go-doc-discovery.ts
|
|
74294
74569
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
@@ -74427,8 +74702,8 @@ function writeDocCache(cacheDir, entry) {
|
|
|
74427
74702
|
|
|
74428
74703
|
// src/catalog/go-doc.ts
|
|
74429
74704
|
var GO_DOC_URLS = [
|
|
74430
|
-
"https://raw.githubusercontent.com/anomalyco/opencode/dev/services/
|
|
74431
|
-
"https://cdn.jsdelivr.net/gh/anomalyco/opencode@dev/services/
|
|
74705
|
+
"https://raw.githubusercontent.com/anomalyco/opencode/dev/services/site/src/docs/content/console/go.mdx",
|
|
74706
|
+
"https://cdn.jsdelivr.net/gh/anomalyco/opencode@dev/services/site/src/docs/content/console/go.mdx"
|
|
74432
74707
|
];
|
|
74433
74708
|
var GO_DOC_MAX_BYTES = 1024 * 1024;
|
|
74434
74709
|
var ENDPOINT_PROTOCOLS = {
|
|
@@ -74568,7 +74843,7 @@ async function fetchGoDocument(signal, options = {}) {
|
|
|
74568
74843
|
}
|
|
74569
74844
|
}
|
|
74570
74845
|
}
|
|
74571
|
-
throw
|
|
74846
|
+
throw llmFailure(
|
|
74572
74847
|
`could not read the Go documentation (${failures.join("; ")})`,
|
|
74573
74848
|
"DOCUMENT_UNAVAILABLE"
|
|
74574
74849
|
);
|
|
@@ -75137,7 +75412,7 @@ var OpencodeGoCatalog = class {
|
|
|
75137
75412
|
}
|
|
75138
75413
|
const reason = snapshot2.unavailable.get(id);
|
|
75139
75414
|
if (reason !== void 0) {
|
|
75140
|
-
throw
|
|
75415
|
+
throw llmFailure(
|
|
75141
75416
|
`opencode-go model "${id}" is advertised but cannot be configured: ${reason}; refresh the model list to retry`,
|
|
75142
75417
|
"MODEL_METADATA_UNAVAILABLE"
|
|
75143
75418
|
);
|
|
@@ -79124,6 +79399,75 @@ var catalogRemote = {
|
|
|
79124
79399
|
]
|
|
79125
79400
|
};
|
|
79126
79401
|
|
|
79402
|
+
// src/desktop/contract.ts
|
|
79403
|
+
function parseRelease(value) {
|
|
79404
|
+
if (value === null || typeof value !== "object") throw new Error("invalid desktop release");
|
|
79405
|
+
const row = value;
|
|
79406
|
+
const version = row["version"];
|
|
79407
|
+
const url = row["url"];
|
|
79408
|
+
if (typeof version !== "string" || version.length === 0) throw new Error("invalid desktop release");
|
|
79409
|
+
if (typeof url !== "string" || url.length === 0) throw new Error("invalid desktop release");
|
|
79410
|
+
const size = row["size"];
|
|
79411
|
+
const sha512 = row["sha512"];
|
|
79412
|
+
const stagingPercentage = row["stagingPercentage"];
|
|
79413
|
+
const releaseDate = row["releaseDate"];
|
|
79414
|
+
return {
|
|
79415
|
+
version,
|
|
79416
|
+
url,
|
|
79417
|
+
...typeof size === "number" && Number.isFinite(size) && size >= 0 ? { size } : {},
|
|
79418
|
+
...typeof sha512 === "string" && sha512.length > 0 ? { sha512 } : {},
|
|
79419
|
+
...typeof stagingPercentage === "number" && Number.isFinite(stagingPercentage) ? { stagingPercentage } : {},
|
|
79420
|
+
...typeof releaseDate === "string" && releaseDate.length > 0 ? { releaseDate } : {}
|
|
79421
|
+
};
|
|
79422
|
+
}
|
|
79423
|
+
function parseDesktopReading(value) {
|
|
79424
|
+
if (value === null || typeof value !== "object") throw new Error("invalid desktop reading");
|
|
79425
|
+
const row = value;
|
|
79426
|
+
if (typeof row["checked"] !== "boolean") throw new Error("invalid desktop reading");
|
|
79427
|
+
if (typeof row["checkedAt"] !== "number" || !Number.isFinite(row["checkedAt"])) {
|
|
79428
|
+
throw new Error("invalid desktop reading");
|
|
79429
|
+
}
|
|
79430
|
+
if (typeof row["platform"] !== "string") throw new Error("invalid desktop reading");
|
|
79431
|
+
if (typeof row["channel"] !== "string") throw new Error("invalid desktop reading");
|
|
79432
|
+
const release = row["release"];
|
|
79433
|
+
return {
|
|
79434
|
+
checked: row["checked"],
|
|
79435
|
+
checkedAt: row["checkedAt"],
|
|
79436
|
+
platform: row["platform"],
|
|
79437
|
+
channel: row["channel"],
|
|
79438
|
+
...release === void 0 ? {} : { release: parseRelease(release) }
|
|
79439
|
+
};
|
|
79440
|
+
}
|
|
79441
|
+
var codec2 = {
|
|
79442
|
+
mode: "strict",
|
|
79443
|
+
typeSymbol: "@dan-ai-studio/dshopencodego#DesktopReading",
|
|
79444
|
+
schema: { parse: parseDesktopReading },
|
|
79445
|
+
create: () => ({ parse: parseDesktopReading })
|
|
79446
|
+
};
|
|
79447
|
+
var desktopRemote = {
|
|
79448
|
+
package: "@dan-ai-studio/dshopencodego",
|
|
79449
|
+
descriptors: [
|
|
79450
|
+
{
|
|
79451
|
+
id: "@dan-ai-studio/dshopencodego#opencodeGoDesktop/readDesktop",
|
|
79452
|
+
service: "opencodeGoDesktop",
|
|
79453
|
+
namespace: "opencodeGoDesktop",
|
|
79454
|
+
method: "readDesktop",
|
|
79455
|
+
invocation: { kind: "direct" },
|
|
79456
|
+
parameters: [],
|
|
79457
|
+
result: codec2
|
|
79458
|
+
},
|
|
79459
|
+
{
|
|
79460
|
+
id: "@dan-ai-studio/dshopencodego#opencodeGoDesktop/refreshDesktop",
|
|
79461
|
+
service: "opencodeGoDesktop",
|
|
79462
|
+
namespace: "opencodeGoDesktop",
|
|
79463
|
+
method: "refreshDesktop",
|
|
79464
|
+
invocation: { kind: "direct" },
|
|
79465
|
+
parameters: [],
|
|
79466
|
+
result: codec2
|
|
79467
|
+
}
|
|
79468
|
+
]
|
|
79469
|
+
};
|
|
79470
|
+
|
|
79127
79471
|
// src/network/contract.ts
|
|
79128
79472
|
function parseNetworkReading(value) {
|
|
79129
79473
|
if (value === null || typeof value !== "object") throw new Error("invalid network reading");
|
|
@@ -79138,7 +79482,7 @@ function parseNetworkReading(value) {
|
|
|
79138
79482
|
...typeof failed === "boolean" ? { failed } : {}
|
|
79139
79483
|
};
|
|
79140
79484
|
}
|
|
79141
|
-
var
|
|
79485
|
+
var codec3 = {
|
|
79142
79486
|
mode: "strict",
|
|
79143
79487
|
typeSymbol: "@dan-ai-studio/dshopencodego#NetworkReading",
|
|
79144
79488
|
schema: { parse: parseNetworkReading },
|
|
@@ -79154,7 +79498,7 @@ var networkRemote = {
|
|
|
79154
79498
|
method: "readNetwork",
|
|
79155
79499
|
invocation: { kind: "direct" },
|
|
79156
79500
|
parameters: [],
|
|
79157
|
-
result:
|
|
79501
|
+
result: codec3
|
|
79158
79502
|
}
|
|
79159
79503
|
]
|
|
79160
79504
|
};
|
|
@@ -79512,7 +79856,7 @@ function parseRequestLogSnapshot(value) {
|
|
|
79512
79856
|
...typeof row["poolKey"] === "string" ? { poolKey: row["poolKey"] } : {}
|
|
79513
79857
|
};
|
|
79514
79858
|
}
|
|
79515
|
-
var
|
|
79859
|
+
var codec4 = {
|
|
79516
79860
|
mode: "strict",
|
|
79517
79861
|
typeSymbol: "@dan-ai-studio/dshopencodego#RequestLogSnapshot",
|
|
79518
79862
|
schema: { parse: parseRequestLogSnapshot },
|
|
@@ -79528,7 +79872,7 @@ var requestLogRemote = {
|
|
|
79528
79872
|
method: "readLog",
|
|
79529
79873
|
invocation: { kind: "direct" },
|
|
79530
79874
|
parameters: [],
|
|
79531
|
-
result:
|
|
79875
|
+
result: codec4
|
|
79532
79876
|
}
|
|
79533
79877
|
]
|
|
79534
79878
|
};
|
|
@@ -79552,7 +79896,7 @@ function parseUpdateStatus(value) {
|
|
|
79552
79896
|
checked: row["checked"]
|
|
79553
79897
|
};
|
|
79554
79898
|
}
|
|
79555
|
-
var
|
|
79899
|
+
var codec5 = (typeSymbol, parse) => ({
|
|
79556
79900
|
mode: "strict",
|
|
79557
79901
|
typeSymbol,
|
|
79558
79902
|
schema: { parse },
|
|
@@ -79568,7 +79912,7 @@ var updateRemote = {
|
|
|
79568
79912
|
method: "readUpdate",
|
|
79569
79913
|
invocation: { kind: "direct" },
|
|
79570
79914
|
parameters: [],
|
|
79571
|
-
result:
|
|
79915
|
+
result: codec5("@dan-ai-studio/dshopencodego#UpdateStatus", parseUpdateStatus)
|
|
79572
79916
|
},
|
|
79573
79917
|
{
|
|
79574
79918
|
id: "@dan-ai-studio/dshopencodego#opencodeGoUpdate/refreshUpdate",
|
|
@@ -79577,7 +79921,7 @@ var updateRemote = {
|
|
|
79577
79921
|
method: "refreshUpdate",
|
|
79578
79922
|
invocation: { kind: "direct" },
|
|
79579
79923
|
parameters: [],
|
|
79580
|
-
result:
|
|
79924
|
+
result: codec5("@dan-ai-studio/dshopencodego#UpdateStatus", parseUpdateStatus)
|
|
79581
79925
|
}
|
|
79582
79926
|
]
|
|
79583
79927
|
};
|
|
@@ -79643,7 +79987,7 @@ function parseGoMeter(value) {
|
|
|
79643
79987
|
})
|
|
79644
79988
|
};
|
|
79645
79989
|
}
|
|
79646
|
-
var
|
|
79990
|
+
var codec6 = (typeSymbol, parse) => ({
|
|
79647
79991
|
mode: "strict",
|
|
79648
79992
|
typeSymbol,
|
|
79649
79993
|
schema: { parse },
|
|
@@ -79659,7 +80003,7 @@ var usageRemote = {
|
|
|
79659
80003
|
method: "readWindows",
|
|
79660
80004
|
invocation: { kind: "direct" },
|
|
79661
80005
|
parameters: [],
|
|
79662
|
-
result:
|
|
80006
|
+
result: codec6("@dan-ai-studio/dshopencodego#GoUsageWindows", parseUsageWindows)
|
|
79663
80007
|
},
|
|
79664
80008
|
{
|
|
79665
80009
|
id: "@dan-ai-studio/dshopencodego#opencodeGoUsage/readMeter",
|
|
@@ -79668,7 +80012,7 @@ var usageRemote = {
|
|
|
79668
80012
|
method: "readMeter",
|
|
79669
80013
|
invocation: { kind: "direct" },
|
|
79670
80014
|
parameters: [],
|
|
79671
|
-
result:
|
|
80015
|
+
result: codec6("@dan-ai-studio/dshopencodego#GoMeter", parseGoMeter)
|
|
79672
80016
|
}
|
|
79673
80017
|
]
|
|
79674
80018
|
};
|
|
@@ -79681,6 +80025,7 @@ var contribution = {
|
|
|
79681
80025
|
...catalogRemote.descriptors,
|
|
79682
80026
|
...updateRemote.descriptors,
|
|
79683
80027
|
...networkRemote.descriptors,
|
|
80028
|
+
...desktopRemote.descriptors,
|
|
79684
80029
|
...requestLogRemote.descriptors
|
|
79685
80030
|
]
|
|
79686
80031
|
};
|
|
@@ -79816,6 +80161,174 @@ function catalogFailure(error) {
|
|
|
79816
80161
|
}, { cause: error });
|
|
79817
80162
|
}
|
|
79818
80163
|
|
|
80164
|
+
// src/desktop/feed.ts
|
|
80165
|
+
var DESKTOP_FEED_PLATFORM = "win-x64";
|
|
80166
|
+
var DESKTOP_FEED_CHANNEL = "nightly";
|
|
80167
|
+
var DESKTOP_FEED_URL = `https://download.deepseek.com/dsh-desk/feeds/${DESKTOP_FEED_PLATFORM}/${DESKTOP_FEED_CHANNEL}.yml`;
|
|
80168
|
+
var DESKTOP_CACHE_MS = 6 * 60 * 60 * 1e3;
|
|
80169
|
+
var DESKTOP_TIMEOUT_MS = 1e4;
|
|
80170
|
+
function indentOf(line) {
|
|
80171
|
+
return line.length - line.trimStart().length;
|
|
80172
|
+
}
|
|
80173
|
+
function unquote(raw) {
|
|
80174
|
+
const value = raw.trim();
|
|
80175
|
+
const quoted = value.length >= 2 && (value.startsWith("'") && value.endsWith("'") || value.startsWith('"') && value.endsWith('"'));
|
|
80176
|
+
return quoted ? value.slice(1, -1) : value;
|
|
80177
|
+
}
|
|
80178
|
+
function toNumber(value) {
|
|
80179
|
+
if (!/^\d+$/.test(value)) return void 0;
|
|
80180
|
+
const parsed = Number(value);
|
|
80181
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
80182
|
+
}
|
|
80183
|
+
function foldBlocks(source) {
|
|
80184
|
+
const lines = source.split(/\r?\n/);
|
|
80185
|
+
const out = [];
|
|
80186
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
80187
|
+
const line = lines[index] ?? "";
|
|
80188
|
+
const open = /^([ \t]*)([A-Za-z][\w-]*):[ \t]*(>-?|>|\|-?|\|)[ \t]*$/.exec(line);
|
|
80189
|
+
if (open === null) {
|
|
80190
|
+
out.push({ indent: indentOf(line), text: line.trim() });
|
|
80191
|
+
continue;
|
|
80192
|
+
}
|
|
80193
|
+
const [, leading = "", key = "", marker = ""] = open;
|
|
80194
|
+
const indent = leading.length;
|
|
80195
|
+
const parts = [];
|
|
80196
|
+
let cursor = index + 1;
|
|
80197
|
+
for (; cursor < lines.length; cursor += 1) {
|
|
80198
|
+
const next = lines[cursor] ?? "";
|
|
80199
|
+
if (next.trim().length === 0) continue;
|
|
80200
|
+
if (indentOf(next) <= indent) break;
|
|
80201
|
+
parts.push(next.trim());
|
|
80202
|
+
}
|
|
80203
|
+
out.push({ indent, text: `${key}: ${parts.join(marker.startsWith("|") ? "\n" : " ")}` });
|
|
80204
|
+
index = cursor - 1;
|
|
80205
|
+
}
|
|
80206
|
+
return out;
|
|
80207
|
+
}
|
|
80208
|
+
function assignFile(target, text2) {
|
|
80209
|
+
const match = /^([A-Za-z][\w-]*):[ \t]*(.*)$/.exec(text2);
|
|
80210
|
+
if (match === null) return;
|
|
80211
|
+
const [, key = "", raw = ""] = match;
|
|
80212
|
+
const value = unquote(raw);
|
|
80213
|
+
if (key === "url") target.url = value;
|
|
80214
|
+
else if (key === "sha512") target.sha512 = value;
|
|
80215
|
+
else if (key === "size") {
|
|
80216
|
+
const size = toNumber(value);
|
|
80217
|
+
if (size !== void 0) target.size = size;
|
|
80218
|
+
}
|
|
80219
|
+
}
|
|
80220
|
+
function parseDesktopFeed(source) {
|
|
80221
|
+
let version;
|
|
80222
|
+
let path5;
|
|
80223
|
+
let digest;
|
|
80224
|
+
let stagingPercentage;
|
|
80225
|
+
let releaseDate;
|
|
80226
|
+
const files = [];
|
|
80227
|
+
let section = "top";
|
|
80228
|
+
for (const line of foldBlocks(source)) {
|
|
80229
|
+
const text2 = line.text;
|
|
80230
|
+
if (text2.length === 0 || text2.startsWith("#")) continue;
|
|
80231
|
+
if (line.indent === 0) {
|
|
80232
|
+
const match = /^([A-Za-z][\w-]*):[ \t]*(.*)$/.exec(text2);
|
|
80233
|
+
if (match === null) continue;
|
|
80234
|
+
const [, key = "", raw = ""] = match;
|
|
80235
|
+
section = key === "files" ? "files" : "top";
|
|
80236
|
+
if (section === "files") continue;
|
|
80237
|
+
const value = unquote(raw);
|
|
80238
|
+
if (key === "version") version = value;
|
|
80239
|
+
else if (key === "path") path5 = value;
|
|
80240
|
+
else if (key === "sha512") digest = value;
|
|
80241
|
+
else if (key === "releaseDate") releaseDate = value;
|
|
80242
|
+
else if (key === "stagingPercentage") stagingPercentage = toNumber(value);
|
|
80243
|
+
continue;
|
|
80244
|
+
}
|
|
80245
|
+
if (section !== "files") continue;
|
|
80246
|
+
if (text2.startsWith("-")) {
|
|
80247
|
+
files.push({});
|
|
80248
|
+
const rest = text2.slice(1).trim();
|
|
80249
|
+
const target2 = files[files.length - 1];
|
|
80250
|
+
if (target2 !== void 0 && rest.length > 0) assignFile(target2, rest);
|
|
80251
|
+
continue;
|
|
80252
|
+
}
|
|
80253
|
+
const target = files[files.length - 1];
|
|
80254
|
+
if (target !== void 0) assignFile(target, text2);
|
|
80255
|
+
}
|
|
80256
|
+
const first = files[0];
|
|
80257
|
+
const url = path5 ?? first?.url;
|
|
80258
|
+
if (version === void 0 || version.length === 0) return void 0;
|
|
80259
|
+
if (url === void 0 || url.length === 0) return void 0;
|
|
80260
|
+
const sha512 = digest ?? first?.sha512;
|
|
80261
|
+
return {
|
|
80262
|
+
version,
|
|
80263
|
+
url,
|
|
80264
|
+
...first?.size === void 0 ? {} : { size: first.size },
|
|
80265
|
+
...sha512 === void 0 ? {} : { sha512 },
|
|
80266
|
+
...stagingPercentage === void 0 ? {} : { stagingPercentage },
|
|
80267
|
+
...releaseDate === void 0 ? {} : { releaseDate }
|
|
80268
|
+
};
|
|
80269
|
+
}
|
|
80270
|
+
function createDesktopFeedReader(deps = {}) {
|
|
80271
|
+
const now = deps.now ?? Date.now;
|
|
80272
|
+
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
80273
|
+
let cached;
|
|
80274
|
+
let inflight;
|
|
80275
|
+
async function lookup() {
|
|
80276
|
+
const checkedAt = now();
|
|
80277
|
+
const identity = { checkedAt, platform: DESKTOP_FEED_PLATFORM, channel: DESKTOP_FEED_CHANNEL };
|
|
80278
|
+
try {
|
|
80279
|
+
const response = await fetchImpl(DESKTOP_FEED_URL, {
|
|
80280
|
+
signal: AbortSignal.timeout(DESKTOP_TIMEOUT_MS),
|
|
80281
|
+
headers: { accept: "text/yaml, text/plain, */*" }
|
|
80282
|
+
});
|
|
80283
|
+
if (!response.ok) throw new Error(`feed answered ${response.status}`);
|
|
80284
|
+
const release = parseDesktopFeed(await response.text());
|
|
80285
|
+
if (release === void 0) throw new Error("feed carried no release");
|
|
80286
|
+
return { ...identity, checked: true, release };
|
|
80287
|
+
} catch {
|
|
80288
|
+
return { ...identity, checked: false };
|
|
80289
|
+
}
|
|
80290
|
+
}
|
|
80291
|
+
return {
|
|
80292
|
+
read(force = false) {
|
|
80293
|
+
if (!force && cached !== void 0 && now() - cached.checkedAt < DESKTOP_CACHE_MS) {
|
|
80294
|
+
return Promise.resolve(cached);
|
|
80295
|
+
}
|
|
80296
|
+
inflight ??= lookup().then((reading) => {
|
|
80297
|
+
cached = reading;
|
|
80298
|
+
inflight = void 0;
|
|
80299
|
+
return reading;
|
|
80300
|
+
});
|
|
80301
|
+
return inflight;
|
|
80302
|
+
}
|
|
80303
|
+
};
|
|
80304
|
+
}
|
|
80305
|
+
|
|
80306
|
+
// src/desktop/service.ts
|
|
80307
|
+
import { TypertRemoteService as TypertRemoteService2 } from "@deepseek-ai/dsh-typert-protocol";
|
|
80308
|
+
var OpencodeGoDesktopService = class extends TypertRemoteService2 {
|
|
80309
|
+
read;
|
|
80310
|
+
constructor(ctx) {
|
|
80311
|
+
super(ctx, "opencodeGoDesktop");
|
|
80312
|
+
const reader = createDesktopFeedReader();
|
|
80313
|
+
this.read = (force) => reader.read(force);
|
|
80314
|
+
}
|
|
80315
|
+
/**
|
|
80316
|
+
* The newest published installer (cached reading).
|
|
80317
|
+
*
|
|
80318
|
+
* The wire method takes no arguments — the gateway client rejects any call
|
|
80319
|
+
* whose positional arity differs from the descriptor's `parameters`, so a
|
|
80320
|
+
* `force` flag cannot ride this call. Forced revalidation is the separate
|
|
80321
|
+
* `refreshDesktop` method below, mirroring the update Remote's pair.
|
|
80322
|
+
*/
|
|
80323
|
+
readDesktop() {
|
|
80324
|
+
return this.read(false);
|
|
80325
|
+
}
|
|
80326
|
+
/** Revalidate against the feed, bypassing the cache. */
|
|
80327
|
+
refreshDesktop() {
|
|
80328
|
+
return this.read(true);
|
|
80329
|
+
}
|
|
80330
|
+
};
|
|
80331
|
+
|
|
79819
80332
|
// src/network/pinning.ts
|
|
79820
80333
|
var import_undici = __toESM(require_undici(), 1);
|
|
79821
80334
|
import { isIP } from "node:net";
|
|
@@ -79972,8 +80485,8 @@ function gatewayFetch(pin, keepAliveTimeoutMs) {
|
|
|
79972
80485
|
}
|
|
79973
80486
|
|
|
79974
80487
|
// src/network/service.ts
|
|
79975
|
-
import { TypertRemoteService as
|
|
79976
|
-
var OpencodeGoNetworkService = class extends
|
|
80488
|
+
import { TypertRemoteService as TypertRemoteService3 } from "@deepseek-ai/dsh-typert-protocol";
|
|
80489
|
+
var OpencodeGoNetworkService = class extends TypertRemoteService3 {
|
|
79977
80490
|
options;
|
|
79978
80491
|
constructor(ctx, options) {
|
|
79979
80492
|
super(ctx, "opencodeGoNetwork");
|
|
@@ -79991,8 +80504,8 @@ var OpencodeGoNetworkService = class extends TypertRemoteService2 {
|
|
|
79991
80504
|
};
|
|
79992
80505
|
|
|
79993
80506
|
// src/request-log/service.ts
|
|
79994
|
-
import { TypertRemoteService as
|
|
79995
|
-
var OpencodeGoRequestLogService = class extends
|
|
80507
|
+
import { TypertRemoteService as TypertRemoteService4 } from "@deepseek-ai/dsh-typert-protocol";
|
|
80508
|
+
var OpencodeGoRequestLogService = class extends TypertRemoteService4 {
|
|
79996
80509
|
options;
|
|
79997
80510
|
constructor(ctx, options) {
|
|
79998
80511
|
super(ctx, "opencodeGoRequestLog");
|
|
@@ -80098,11 +80611,11 @@ function createUpdateChecker(deps) {
|
|
|
80098
80611
|
}
|
|
80099
80612
|
|
|
80100
80613
|
// src/update/version.ts
|
|
80101
|
-
var PLUGIN_VERSION = true ? "0.1.
|
|
80614
|
+
var PLUGIN_VERSION = true ? "0.1.93" : "0.0.0-dev";
|
|
80102
80615
|
|
|
80103
80616
|
// src/update/service.ts
|
|
80104
|
-
import { TypertRemoteService as
|
|
80105
|
-
var OpencodeGoUpdateService = class extends
|
|
80617
|
+
import { TypertRemoteService as TypertRemoteService5 } from "@deepseek-ai/dsh-typert-protocol";
|
|
80618
|
+
var OpencodeGoUpdateService = class extends TypertRemoteService5 {
|
|
80106
80619
|
check;
|
|
80107
80620
|
constructor(ctx, options) {
|
|
80108
80621
|
super(ctx, "opencodeGoUpdate");
|
|
@@ -80127,7 +80640,7 @@ var OpencodeGoUpdateService = class extends TypertRemoteService4 {
|
|
|
80127
80640
|
};
|
|
80128
80641
|
|
|
80129
80642
|
// src/usage/windows.ts
|
|
80130
|
-
import { attributionHeaders as attributionHeaders6
|
|
80643
|
+
import { attributionHeaders as attributionHeaders6 } from "@deepseek-ai/dsh-llm";
|
|
80131
80644
|
var USAGE_MAX_BYTES = 1024 * 1024;
|
|
80132
80645
|
var USAGE_TIMEOUT_MS = 1e4;
|
|
80133
80646
|
function parseGoUsage(value) {
|
|
@@ -80145,7 +80658,7 @@ function parseGoUsage(value) {
|
|
|
80145
80658
|
}
|
|
80146
80659
|
async function readUsageWindows(options) {
|
|
80147
80660
|
if (options.apiKey === void 0 || options.apiKey.length === 0) {
|
|
80148
|
-
throw
|
|
80661
|
+
throw llmFailure("dshopencodego: no credential is configured for the opencode-go route", "USAGE_UNAVAILABLE");
|
|
80149
80662
|
}
|
|
80150
80663
|
const url = `${options.baseURL.replace(/\/+$/, "")}/usage`;
|
|
80151
80664
|
const timeout = AbortSignal.timeout(USAGE_TIMEOUT_MS);
|
|
@@ -80162,12 +80675,12 @@ async function readUsageWindows(options) {
|
|
|
80162
80675
|
signal: options.signal === void 0 ? timeout : AbortSignal.any([options.signal, timeout])
|
|
80163
80676
|
});
|
|
80164
80677
|
} catch (error) {
|
|
80165
|
-
throw
|
|
80678
|
+
throw llmFailure(`could not reach ${url}`, "USAGE_UNAVAILABLE", { cause: error });
|
|
80166
80679
|
}
|
|
80167
80680
|
if (!response.ok) {
|
|
80168
80681
|
await response.body?.cancel().catch(() => {
|
|
80169
80682
|
});
|
|
80170
|
-
throw
|
|
80683
|
+
throw llmFailure(`${url} answered HTTP ${response.status}`, "USAGE_UNAVAILABLE");
|
|
80171
80684
|
}
|
|
80172
80685
|
const body = await readBoundedJson(response, url, USAGE_MAX_BYTES);
|
|
80173
80686
|
try {
|
|
@@ -80176,16 +80689,16 @@ async function readUsageWindows(options) {
|
|
|
80176
80689
|
...options.source === void 0 ? {} : { source: options.source }
|
|
80177
80690
|
};
|
|
80178
80691
|
} catch (error) {
|
|
80179
|
-
throw
|
|
80692
|
+
throw llmFailure(`${url} returned an invalid usage document`, "USAGE_UNAVAILABLE", { cause: error });
|
|
80180
80693
|
}
|
|
80181
80694
|
}
|
|
80182
80695
|
|
|
80183
80696
|
// src/usage/service.ts
|
|
80184
80697
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
80185
|
-
import { RemoteError as RemoteError2, TypertRemoteService as
|
|
80186
|
-
import { LlmError as
|
|
80698
|
+
import { RemoteError as RemoteError2, TypertRemoteService as TypertRemoteService6 } from "@deepseek-ai/dsh-typert-protocol";
|
|
80699
|
+
import { LlmError as LlmError12 } from "@deepseek-ai/dsh-llm";
|
|
80187
80700
|
function usageFailure(error, source) {
|
|
80188
|
-
const missing = error instanceof
|
|
80701
|
+
const missing = error instanceof LlmError12 && error.code === "MISSING_CREDENTIAL";
|
|
80189
80702
|
return new RemoteError2(
|
|
80190
80703
|
"dshopencodego/usage-unavailable",
|
|
80191
80704
|
error instanceof Error ? error.message : "OpenCode Go usage is unavailable",
|
|
@@ -80193,7 +80706,7 @@ function usageFailure(error, source) {
|
|
|
80193
80706
|
{ cause: error }
|
|
80194
80707
|
);
|
|
80195
80708
|
}
|
|
80196
|
-
var OpencodeGoUsageService = class extends
|
|
80709
|
+
var OpencodeGoUsageService = class extends TypertRemoteService6 {
|
|
80197
80710
|
identity;
|
|
80198
80711
|
options;
|
|
80199
80712
|
constructor(ctx, options) {
|
|
@@ -80212,7 +80725,7 @@ var OpencodeGoUsageService = class extends TypertRemoteService5 {
|
|
|
80212
80725
|
}
|
|
80213
80726
|
if (key === void 0 || key.length === 0) {
|
|
80214
80727
|
this.identity = void 0;
|
|
80215
|
-
throw usageFailure(new
|
|
80728
|
+
throw usageFailure(new LlmError12("No OpenCode Go API key is configured", "MISSING_CREDENTIAL"), void 0);
|
|
80216
80729
|
}
|
|
80217
80730
|
if (this.identity?.baseURL !== baseURL || this.identity.key !== key) {
|
|
80218
80731
|
this.identity = { baseURL, key, source: randomUUID3() };
|
|
@@ -80261,7 +80774,7 @@ function apply(ctx, raw) {
|
|
|
80261
80774
|
const credentials = ctx.get("credentials");
|
|
80262
80775
|
const hit = credentials !== void 0 ? (await credentials.resolve(credentialRef(ref)))?.value : launchEnvironmentOf(ctx).get(ref)?.value;
|
|
80263
80776
|
if (hit !== void 0 && hit.length > 0) return llm2.assertUsableApiKey(hit, name, ref);
|
|
80264
|
-
throw new
|
|
80777
|
+
throw new LlmError13(
|
|
80265
80778
|
`dshopencodego: no credential; the profile resolves ${ref}, which is not set \u2014 store ${ref} through the credentials service (the Web Models page writes it) or export it`,
|
|
80266
80779
|
"MISSING_CREDENTIAL"
|
|
80267
80780
|
);
|
|
@@ -80345,6 +80858,7 @@ function apply(ctx, raw) {
|
|
|
80345
80858
|
}
|
|
80346
80859
|
});
|
|
80347
80860
|
ctx.plugin(OpencodeGoUpdateService, { currentVersion: PLUGIN_VERSION });
|
|
80861
|
+
ctx.plugin(OpencodeGoDesktopService);
|
|
80348
80862
|
ctx.effect(() => {
|
|
80349
80863
|
const refresh = () => {
|
|
80350
80864
|
void adapter.catalogOf(current2()).snapshot().catch(() => void 0);
|
|
@@ -80407,7 +80921,7 @@ function apply(ctx, raw) {
|
|
|
80407
80921
|
settingsNs,
|
|
80408
80922
|
async (request, signal) => {
|
|
80409
80923
|
if (request.provider !== PROVIDER_ID && !(request.baseURL ?? "").includes("opencode.ai")) {
|
|
80410
|
-
throw new
|
|
80924
|
+
throw new LlmError13(
|
|
80411
80925
|
"dshopencodego discovers only OpenCode Go/Console endpoints; enter this provider's models by hand",
|
|
80412
80926
|
"DISCOVERY_UNSUPPORTED"
|
|
80413
80927
|
);
|