dsh-coding-subscription-oauth 0.7.1 → 0.8.0
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/CHANGELOG.md +312 -302
- package/CONTRIBUTING.md +138 -138
- package/INSTALL.md +267 -262
- package/LICENSE +19 -19
- package/NOTICE +11 -11
- package/README.de.md +309 -303
- package/README.es.md +310 -304
- package/README.fr.md +310 -304
- package/README.ja.md +310 -304
- package/README.ko.md +310 -304
- package/README.md +327 -321
- package/README.pt-BR.md +310 -304
- package/README.ru.md +310 -304
- package/README.zh-CN.md +325 -319
- package/compatibility/dsh-bom.json +36 -36
- package/cordis.patch.yml +13 -13
- package/docs/00-project-rules.md +213 -213
- package/docs/02-architecture.md +143 -142
- package/docs/02-architecture.zh-CN.md +143 -142
- package/lib/bin.js +13 -6
- package/lib/bin.js.map +3 -3
- package/lib/client.js +3 -3
- package/lib/client.js.map +4 -4
- package/lib/gateway-auth.d.ts +1 -0
- package/lib/gateway-auth.d.ts.map +1 -1
- package/lib/gateway-config.d.ts +4 -0
- package/lib/gateway-config.d.ts.map +1 -1
- package/lib/gateway-http.d.ts +5 -0
- package/lib/gateway-http.d.ts.map +1 -1
- package/lib/gateway-opencode-go.d.ts +22 -0
- package/lib/gateway-opencode-go.d.ts.map +1 -0
- package/lib/gateway.d.ts +2 -0
- package/lib/gateway.d.ts.map +1 -1
- package/lib/index.js +276 -63
- package/lib/index.js.map +4 -4
- package/lib/invariant.js.map +1 -1
- package/package.json +229 -229
- package/patches/dsh-agy@0.1.2.patch +25 -25
- package/scripts/release.mjs +187 -187
- package/scripts/smoke-deployed-routes.mjs +146 -146
- package/scripts/verify-adapter-host.mjs +70 -70
- package/scripts/verify-deployed-catalog.mjs +87 -87
package/lib/index.js
CHANGED
|
@@ -6072,20 +6072,20 @@ var require_formdata_parser = __commonJS({
|
|
|
6072
6072
|
);
|
|
6073
6073
|
let value;
|
|
6074
6074
|
if (isExtended) {
|
|
6075
|
-
const
|
|
6075
|
+
const headerValue2 = collectASequenceOfBytes(
|
|
6076
6076
|
(char) => char !== 32 && char !== 13 && char !== 10 && char !== 59,
|
|
6077
6077
|
// not space, CRLF, or ;
|
|
6078
6078
|
input,
|
|
6079
6079
|
position
|
|
6080
6080
|
);
|
|
6081
|
-
if (
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6081
|
+
if (headerValue2[0] !== 117 && headerValue2[0] !== 85 || // u or U
|
|
6082
|
+
headerValue2[1] !== 116 && headerValue2[1] !== 84 || // t or T
|
|
6083
|
+
headerValue2[2] !== 102 && headerValue2[2] !== 70 || // f or F
|
|
6084
|
+
headerValue2[3] !== 45 || // -
|
|
6085
|
+
headerValue2[4] !== 56) {
|
|
6086
6086
|
throw parsingError("unknown encoding, expected utf-8''");
|
|
6087
6087
|
}
|
|
6088
|
-
value = decodeURIComponent(decoder.decode(
|
|
6088
|
+
value = decodeURIComponent(decoder.decode(headerValue2.subarray(7)));
|
|
6089
6089
|
} else if (input[position.position] === 34) {
|
|
6090
6090
|
position.position++;
|
|
6091
6091
|
const quotedValue = collectASequenceOfBytes(
|
|
@@ -6174,23 +6174,23 @@ var require_formdata_parser = __commonJS({
|
|
|
6174
6174
|
break;
|
|
6175
6175
|
}
|
|
6176
6176
|
case "content-type": {
|
|
6177
|
-
let
|
|
6177
|
+
let headerValue2 = collectASequenceOfBytes(
|
|
6178
6178
|
(char) => char !== 10 && char !== 13,
|
|
6179
6179
|
input,
|
|
6180
6180
|
position
|
|
6181
6181
|
);
|
|
6182
|
-
|
|
6183
|
-
contentType = isomorphicDecode(
|
|
6182
|
+
headerValue2 = removeChars(headerValue2, false, true, (char) => char === 9 || char === 32);
|
|
6183
|
+
contentType = isomorphicDecode(headerValue2);
|
|
6184
6184
|
break;
|
|
6185
6185
|
}
|
|
6186
6186
|
case "content-transfer-encoding": {
|
|
6187
|
-
let
|
|
6187
|
+
let headerValue2 = collectASequenceOfBytes(
|
|
6188
6188
|
(char) => char !== 10 && char !== 13,
|
|
6189
6189
|
input,
|
|
6190
6190
|
position
|
|
6191
6191
|
);
|
|
6192
|
-
|
|
6193
|
-
encoding = isomorphicDecode(
|
|
6192
|
+
headerValue2 = removeChars(headerValue2, false, true, (char) => char === 9 || char === 32);
|
|
6193
|
+
encoding = isomorphicDecode(headerValue2);
|
|
6194
6194
|
break;
|
|
6195
6195
|
}
|
|
6196
6196
|
default: {
|
|
@@ -7848,7 +7848,7 @@ var require_client_h2 = __commonJS({
|
|
|
7848
7848
|
"node_modules/.pnpm/undici@7.29.0/node_modules/undici/lib/dispatcher/client-h2.js"(exports, module) {
|
|
7849
7849
|
"use strict";
|
|
7850
7850
|
var assert = __require("node:assert");
|
|
7851
|
-
var { pipeline } = __require("node:stream");
|
|
7851
|
+
var { pipeline: pipeline2 } = __require("node:stream");
|
|
7852
7852
|
var util = require_util();
|
|
7853
7853
|
var {
|
|
7854
7854
|
RequestContentLengthMismatchError,
|
|
@@ -8481,7 +8481,7 @@ var require_client_h2 = __commonJS({
|
|
|
8481
8481
|
}
|
|
8482
8482
|
function writeStream(abort, socket, expectsPayload, h2stream, body, client, request, contentLength) {
|
|
8483
8483
|
assert(contentLength !== 0 || client[kRunning] === 0, "stream body cannot be pipelined");
|
|
8484
|
-
const pipe =
|
|
8484
|
+
const pipe = pipeline2(
|
|
8485
8485
|
body,
|
|
8486
8486
|
h2stream,
|
|
8487
8487
|
(err) => {
|
|
@@ -11332,7 +11332,7 @@ var require_readable = __commonJS({
|
|
|
11332
11332
|
"node_modules/.pnpm/undici@7.29.0/node_modules/undici/lib/api/readable.js"(exports, module) {
|
|
11333
11333
|
"use strict";
|
|
11334
11334
|
var assert = __require("node:assert");
|
|
11335
|
-
var { Readable } = __require("node:stream");
|
|
11335
|
+
var { Readable: Readable2 } = __require("node:stream");
|
|
11336
11336
|
var { RequestAbortedError, NotSupportedError, InvalidArgumentError, AbortError } = require_errors();
|
|
11337
11337
|
var util = require_util();
|
|
11338
11338
|
var { ReadableStreamFrom } = require_util();
|
|
@@ -11346,7 +11346,7 @@ var require_readable = __commonJS({
|
|
|
11346
11346
|
var kBytesRead = /* @__PURE__ */ Symbol("kBytesRead");
|
|
11347
11347
|
var noop = () => {
|
|
11348
11348
|
};
|
|
11349
|
-
var BodyReadable = class extends
|
|
11349
|
+
var BodyReadable = class extends Readable2 {
|
|
11350
11350
|
/**
|
|
11351
11351
|
* @param {object} opts
|
|
11352
11352
|
* @param {(this: Readable, size: number) => void} opts.resume
|
|
@@ -11735,7 +11735,7 @@ var require_api_request = __commonJS({
|
|
|
11735
11735
|
"use strict";
|
|
11736
11736
|
var assert = __require("node:assert");
|
|
11737
11737
|
var { AsyncResource } = __require("node:async_hooks");
|
|
11738
|
-
var { Readable } = require_readable();
|
|
11738
|
+
var { Readable: Readable2 } = require_readable();
|
|
11739
11739
|
var { InvalidArgumentError, RequestAbortedError } = require_errors();
|
|
11740
11740
|
var util = require_util();
|
|
11741
11741
|
function noop() {
|
|
@@ -11816,7 +11816,7 @@ var require_api_request = __commonJS({
|
|
|
11816
11816
|
const parsedHeaders = responseHeaders === "raw" ? util.parseHeaders(rawHeaders) : headers;
|
|
11817
11817
|
const contentType = parsedHeaders["content-type"];
|
|
11818
11818
|
const contentLength = parsedHeaders["content-length"];
|
|
11819
|
-
const res = new
|
|
11819
|
+
const res = new Readable2({
|
|
11820
11820
|
resume,
|
|
11821
11821
|
abort,
|
|
11822
11822
|
contentType,
|
|
@@ -12125,7 +12125,7 @@ var require_api_pipeline = __commonJS({
|
|
|
12125
12125
|
"node_modules/.pnpm/undici@7.29.0/node_modules/undici/lib/api/api-pipeline.js"(exports, module) {
|
|
12126
12126
|
"use strict";
|
|
12127
12127
|
var {
|
|
12128
|
-
Readable,
|
|
12128
|
+
Readable: Readable2,
|
|
12129
12129
|
Duplex,
|
|
12130
12130
|
PassThrough
|
|
12131
12131
|
} = __require("node:stream");
|
|
@@ -12141,7 +12141,7 @@ var require_api_pipeline = __commonJS({
|
|
|
12141
12141
|
function noop() {
|
|
12142
12142
|
}
|
|
12143
12143
|
var kResume = /* @__PURE__ */ Symbol("resume");
|
|
12144
|
-
var PipelineRequest = class extends
|
|
12144
|
+
var PipelineRequest = class extends Readable2 {
|
|
12145
12145
|
constructor() {
|
|
12146
12146
|
super({ autoDestroy: true });
|
|
12147
12147
|
this[kResume] = null;
|
|
@@ -12158,7 +12158,7 @@ var require_api_pipeline = __commonJS({
|
|
|
12158
12158
|
callback(err);
|
|
12159
12159
|
}
|
|
12160
12160
|
};
|
|
12161
|
-
var PipelineResponse = class extends
|
|
12161
|
+
var PipelineResponse = class extends Readable2 {
|
|
12162
12162
|
constructor(resume) {
|
|
12163
12163
|
super({ autoDestroy: true });
|
|
12164
12164
|
this[kResume] = resume;
|
|
@@ -12308,7 +12308,7 @@ var require_api_pipeline = __commonJS({
|
|
|
12308
12308
|
util.destroy(ret, err);
|
|
12309
12309
|
}
|
|
12310
12310
|
};
|
|
12311
|
-
function
|
|
12311
|
+
function pipeline2(opts, handler) {
|
|
12312
12312
|
try {
|
|
12313
12313
|
const pipelineHandler = new PipelineHandler(opts, handler);
|
|
12314
12314
|
this.dispatch({ ...opts, body: pipelineHandler.req }, pipelineHandler);
|
|
@@ -12317,7 +12317,7 @@ var require_api_pipeline = __commonJS({
|
|
|
12317
12317
|
return new PassThrough().destroy(err);
|
|
12318
12318
|
}
|
|
12319
12319
|
}
|
|
12320
|
-
module.exports =
|
|
12320
|
+
module.exports = pipeline2;
|
|
12321
12321
|
}
|
|
12322
12322
|
});
|
|
12323
12323
|
|
|
@@ -12616,8 +12616,8 @@ var require_mock_utils = __commonJS({
|
|
|
12616
12616
|
}
|
|
12617
12617
|
function lowerCaseEntries(headers) {
|
|
12618
12618
|
return Object.fromEntries(
|
|
12619
|
-
Object.entries(headers).map(([headerName,
|
|
12620
|
-
return [headerName.toLocaleLowerCase(),
|
|
12619
|
+
Object.entries(headers).map(([headerName, headerValue2]) => {
|
|
12620
|
+
return [headerName.toLocaleLowerCase(), headerValue2];
|
|
12621
12621
|
})
|
|
12622
12622
|
);
|
|
12623
12623
|
}
|
|
@@ -12657,8 +12657,8 @@ var require_mock_utils = __commonJS({
|
|
|
12657
12657
|
return false;
|
|
12658
12658
|
}
|
|
12659
12659
|
for (const [matchHeaderName, matchHeaderValue] of Object.entries(mockDispatch2.headers)) {
|
|
12660
|
-
const
|
|
12661
|
-
if (!matchValue(matchHeaderValue,
|
|
12660
|
+
const headerValue2 = getHeaderByName(headers, matchHeaderName);
|
|
12661
|
+
if (!matchValue(matchHeaderValue, headerValue2)) {
|
|
12662
12662
|
return false;
|
|
12663
12663
|
}
|
|
12664
12664
|
}
|
|
@@ -15752,8 +15752,8 @@ var require_cache = __commonJS({
|
|
|
15752
15752
|
if (!isValidHTTPToken(trimmedHeader)) {
|
|
15753
15753
|
return void 0;
|
|
15754
15754
|
}
|
|
15755
|
-
const
|
|
15756
|
-
output[trimmedHeader] = Array.isArray(
|
|
15755
|
+
const headerValue2 = headers[trimmedHeader];
|
|
15756
|
+
output[trimmedHeader] = Array.isArray(headerValue2) ? headerValue2.slice() : headerValue2 ?? null;
|
|
15757
15757
|
}
|
|
15758
15758
|
return output;
|
|
15759
15759
|
}
|
|
@@ -16415,11 +16415,11 @@ var require_cache_handler = __commonJS({
|
|
|
16415
16415
|
}
|
|
16416
16416
|
}
|
|
16417
16417
|
}
|
|
16418
|
-
function deleteLocationTargets(store, cacheKey,
|
|
16419
|
-
if (
|
|
16418
|
+
function deleteLocationTargets(store, cacheKey, headerValue2) {
|
|
16419
|
+
if (headerValue2 === void 0) {
|
|
16420
16420
|
return;
|
|
16421
16421
|
}
|
|
16422
|
-
const values = Array.isArray(
|
|
16422
|
+
const values = Array.isArray(headerValue2) ? headerValue2 : [headerValue2];
|
|
16423
16423
|
for (let i = 0; i < values.length; i++) {
|
|
16424
16424
|
const path = getSameOriginPath(cacheKey, values[i]);
|
|
16425
16425
|
if (path !== void 0) {
|
|
@@ -17142,7 +17142,7 @@ var require_cache2 = __commonJS({
|
|
|
17142
17142
|
"node_modules/.pnpm/undici@7.29.0/node_modules/undici/lib/interceptor/cache.js"(exports, module) {
|
|
17143
17143
|
"use strict";
|
|
17144
17144
|
var assert = __require("node:assert");
|
|
17145
|
-
var { Readable } = __require("node:stream");
|
|
17145
|
+
var { Readable: Readable2 } = __require("node:stream");
|
|
17146
17146
|
var util = require_util();
|
|
17147
17147
|
var CacheHandler = require_cache_handler();
|
|
17148
17148
|
var MemoryCacheStore = require_memory_cache_store();
|
|
@@ -17311,7 +17311,7 @@ var require_cache2 = __commonJS({
|
|
|
17311
17311
|
return dispatch(opts, new CacheHandler(globalOpts, cacheKey, handler));
|
|
17312
17312
|
}
|
|
17313
17313
|
function sendCachedValue(handler, opts, result, age, context, isStale2) {
|
|
17314
|
-
const stream = util.isStream(result.body) ? result.body :
|
|
17314
|
+
const stream = util.isStream(result.body) ? result.body : Readable2.from(result.body ?? []);
|
|
17315
17315
|
assert(!stream.destroyed, "stream should not be destroyed");
|
|
17316
17316
|
assert(!stream.readableDidRead, "stream should not be readableDidRead");
|
|
17317
17317
|
const controller = {
|
|
@@ -17550,7 +17550,7 @@ var require_decompress = __commonJS({
|
|
|
17550
17550
|
"node_modules/.pnpm/undici@7.29.0/node_modules/undici/lib/interceptor/decompress.js"(exports, module) {
|
|
17551
17551
|
"use strict";
|
|
17552
17552
|
var { createInflate, createGunzip, createBrotliDecompress, createZstdDecompress } = __require("node:zlib");
|
|
17553
|
-
var { pipeline } = __require("node:stream");
|
|
17553
|
+
var { pipeline: pipeline2 } = __require("node:stream");
|
|
17554
17554
|
var DecoratorHandler = require_decorator_handler();
|
|
17555
17555
|
var { runtimeFeatures } = require_runtime_features();
|
|
17556
17556
|
var supportedEncodings = {
|
|
@@ -17659,7 +17659,7 @@ var require_decompress = __commonJS({
|
|
|
17659
17659
|
#setupMultipleDecompressors(controller) {
|
|
17660
17660
|
const lastDecompressor = this.#decompressors[this.#decompressors.length - 1];
|
|
17661
17661
|
this.#setupDecompressorEvents(lastDecompressor, controller);
|
|
17662
|
-
|
|
17662
|
+
pipeline2(this.#decompressors, (err) => {
|
|
17663
17663
|
if (err) {
|
|
17664
17664
|
super.onResponseError(controller, err);
|
|
17665
17665
|
return;
|
|
@@ -20404,7 +20404,7 @@ var require_fetch = __commonJS({
|
|
|
20404
20404
|
subresourceSet
|
|
20405
20405
|
} = require_constants3();
|
|
20406
20406
|
var EE = __require("node:events");
|
|
20407
|
-
var { Readable, pipeline, finished, isErrored, isReadable } = __require("node:stream");
|
|
20407
|
+
var { Readable: Readable2, pipeline: pipeline2, finished, isErrored, isReadable } = __require("node:stream");
|
|
20408
20408
|
var { addAbortListener, bufferToLowerCasedHeaderName } = require_util();
|
|
20409
20409
|
var { dataURLProcessor, serializeAMimeType, minimizeSupportedMimeType } = require_data_url();
|
|
20410
20410
|
var { getGlobalDispatcher: getGlobalDispatcher2 } = require_global2();
|
|
@@ -21347,7 +21347,7 @@ var require_fetch = __commonJS({
|
|
|
21347
21347
|
}
|
|
21348
21348
|
}
|
|
21349
21349
|
const location = headersList.get("location", true);
|
|
21350
|
-
this.body = new
|
|
21350
|
+
this.body = new Readable2({ read: resume });
|
|
21351
21351
|
const willFollow = location && request.redirect === "follow" && redirectStatusSet.has(status);
|
|
21352
21352
|
const decoders = [];
|
|
21353
21353
|
if (request.method !== "HEAD" && request.method !== "CONNECT" && !nullBodyStatus.includes(status) && !willFollow) {
|
|
@@ -21395,7 +21395,7 @@ var require_fetch = __commonJS({
|
|
|
21395
21395
|
status,
|
|
21396
21396
|
statusText,
|
|
21397
21397
|
headersList,
|
|
21398
|
-
body: decoders.length ?
|
|
21398
|
+
body: decoders.length ? pipeline2(this.body, ...decoders, (err) => {
|
|
21399
21399
|
if (err) {
|
|
21400
21400
|
this.onError(err);
|
|
21401
21401
|
}
|
|
@@ -25096,7 +25096,7 @@ ${value}`;
|
|
|
25096
25096
|
var require_eventsource = __commonJS({
|
|
25097
25097
|
"node_modules/.pnpm/undici@7.29.0/node_modules/undici/lib/web/eventsource/eventsource.js"(exports, module) {
|
|
25098
25098
|
"use strict";
|
|
25099
|
-
var { pipeline } = __require("node:stream");
|
|
25099
|
+
var { pipeline: pipeline2 } = __require("node:stream");
|
|
25100
25100
|
var { fetching } = require_fetch();
|
|
25101
25101
|
var { makeRequest } = require_request2();
|
|
25102
25102
|
var { webidl } = require_webidl();
|
|
@@ -25254,7 +25254,7 @@ var require_eventsource = __commonJS({
|
|
|
25254
25254
|
));
|
|
25255
25255
|
}
|
|
25256
25256
|
});
|
|
25257
|
-
|
|
25257
|
+
pipeline2(
|
|
25258
25258
|
response.body.stream,
|
|
25259
25259
|
eventSourceStream,
|
|
25260
25260
|
(error) => {
|
|
@@ -25609,7 +25609,7 @@ import { dirname as dirname6, join as join8 } from "node:path";
|
|
|
25609
25609
|
import { assertUsableApiKey, RetryPolicySchema } from "@deepseek-ai/dsh-llm";
|
|
25610
25610
|
import z2 from "@deepseek-ai/schemastery";
|
|
25611
25611
|
|
|
25612
|
-
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.
|
|
25612
|
+
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.2_82bbdc1424db474a5d3f648945c0fadb/node_modules/dsh-coding-oauth-core/lib/proxy.js
|
|
25613
25613
|
var import_undici = __toESM(require_undici(), 1);
|
|
25614
25614
|
var DEFAULT_PROXIED_HOSTS = [
|
|
25615
25615
|
"auth.x.ai",
|
|
@@ -25744,7 +25744,7 @@ function grokBuildProxyInEffect() {
|
|
|
25744
25744
|
return codingOAuthProxyInEffect();
|
|
25745
25745
|
}
|
|
25746
25746
|
|
|
25747
|
-
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.
|
|
25747
|
+
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.2_82bbdc1424db474a5d3f648945c0fadb/node_modules/dsh-coding-oauth-core/lib/route-registration.js
|
|
25748
25748
|
function releaseRegistrationsSynchronously(disposers) {
|
|
25749
25749
|
for (const dispose of [...disposers].reverse()) {
|
|
25750
25750
|
try {
|
|
@@ -25780,7 +25780,7 @@ function setupAtomicallySynchronously(registry, setup) {
|
|
|
25780
25780
|
return onceSynchronously(disposers);
|
|
25781
25781
|
}
|
|
25782
25782
|
|
|
25783
|
-
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.
|
|
25783
|
+
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.2_82bbdc1424db474a5d3f648945c0fadb/node_modules/dsh-coding-oauth-core/lib/ids.js
|
|
25784
25784
|
var XAI_PI_PROVIDER = "xai";
|
|
25785
25785
|
var CODEX_PI_PROVIDER = "openai-codex";
|
|
25786
25786
|
var KIMI_PI_PROVIDER = "kimi-coding";
|
|
@@ -25808,7 +25808,7 @@ var CLAUDE_CODE_OAUTH_MODELS_CACHE_FILENAME = ".claude-code-oauth-models.json";
|
|
|
25808
25808
|
var DEFAULT_GROK_BUILD_MODEL = "grok-4.6";
|
|
25809
25809
|
var GROK_BUILD_STREAM_IDLE_TIMEOUT_MS = 3e5;
|
|
25810
25810
|
|
|
25811
|
-
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.
|
|
25811
|
+
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.2_82bbdc1424db474a5d3f648945c0fadb/node_modules/dsh-coding-oauth-core/lib/state-contract.js
|
|
25812
25812
|
var CAPABILITY_SETTINGS_NAMESPACE = "coding-subscription-oauth";
|
|
25813
25813
|
var GATEWAY_KEY_FILENAME = ".coding-oauth-gateway.json";
|
|
25814
25814
|
var IMAGINE_MEDIA_STORE_DIRNAME = ".dsh-coding-subscription-oauth-media";
|
|
@@ -25861,7 +25861,7 @@ var CODING_OAUTH_MANAGEMENT_PATHS = Object.freeze([
|
|
|
25861
25861
|
GATEWAY_ROTATE_PATH
|
|
25862
25862
|
]);
|
|
25863
25863
|
|
|
25864
|
-
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.
|
|
25864
|
+
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.2_82bbdc1424db474a5d3f648945c0fadb/node_modules/dsh-coding-oauth-core/lib/http-json.js
|
|
25865
25865
|
var JSON_BODY_LIMIT_BYTES = 64 * 1024;
|
|
25866
25866
|
var JsonRequestError = class extends Error {
|
|
25867
25867
|
statusCode;
|
|
@@ -25941,7 +25941,7 @@ function requestErrorStatus(error, fallback) {
|
|
|
25941
25941
|
return error instanceof JsonRequestError ? error.statusCode : fallback;
|
|
25942
25942
|
}
|
|
25943
25943
|
|
|
25944
|
-
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.
|
|
25944
|
+
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.2_82bbdc1424db474a5d3f648945c0fadb/node_modules/dsh-coding-oauth-core/lib/grok-errors.js
|
|
25945
25945
|
var XAI_CAPACITY = /\b(?:at\s+capacity|high\s+demand|priority\s+processing|overloaded)\b/i;
|
|
25946
25946
|
function isXaiCapacityError(detail) {
|
|
25947
25947
|
return XAI_CAPACITY.test(detail);
|
|
@@ -25952,7 +25952,7 @@ function remapXaiCapacityFailure(failure) {
|
|
|
25952
25952
|
return { ...failure, code: "RATE_LIMIT" };
|
|
25953
25953
|
}
|
|
25954
25954
|
|
|
25955
|
-
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.
|
|
25955
|
+
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.2_82bbdc1424db474a5d3f648945c0fadb/node_modules/dsh-coding-oauth-core/lib/kimi-errors.js
|
|
25956
25956
|
import { CONTEXT_WINDOW_EXCEEDED_CODE, isContextWindowExceededError } from "@deepseek-ai/dsh-llm";
|
|
25957
25957
|
var KIMI_CONTEXT_CAPACITY = /\bsupports only\s+\d+\s*k\s+context\b/i;
|
|
25958
25958
|
function isMisclassifiedContextWindowError(detail) {
|
|
@@ -25964,12 +25964,12 @@ function remapAuthFailureIfContextOverflow(failure) {
|
|
|
25964
25964
|
return { ...failure, code: CONTEXT_WINDOW_EXCEEDED_CODE };
|
|
25965
25965
|
}
|
|
25966
25966
|
|
|
25967
|
-
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.
|
|
25967
|
+
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.2_82bbdc1424db474a5d3f648945c0fadb/node_modules/dsh-coding-oauth-core/lib/gateway-protocol.js
|
|
25968
25968
|
function isThinkingLevel(value) {
|
|
25969
25969
|
return value === "off" || value === "minimal" || value === "low" || value === "medium" || value === "high" || value === "xhigh" || value === "max";
|
|
25970
25970
|
}
|
|
25971
25971
|
|
|
25972
|
-
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.
|
|
25972
|
+
// node_modules/.pnpm/dsh-coding-oauth-core@0.1.2_82bbdc1424db474a5d3f648945c0fadb/node_modules/dsh-coding-oauth-core/lib/index.js
|
|
25973
25973
|
var CODING_OAUTH_CORE_ABI = "dsh-coding-oauth-core/v1";
|
|
25974
25974
|
var STORE_SYMBOL = /* @__PURE__ */ Symbol.for("dsh.coding-oauth-core.runtime-store");
|
|
25975
25975
|
function resolveCodingOAuthScope(context) {
|
|
@@ -34102,6 +34102,13 @@ function maskGatewayApiKey(apiKey) {
|
|
|
34102
34102
|
if (apiKey.length <= 4) return "****";
|
|
34103
34103
|
return `****${apiKey.slice(-4)}`;
|
|
34104
34104
|
}
|
|
34105
|
+
function documentExtras(existing) {
|
|
34106
|
+
return {
|
|
34107
|
+
...existing?.enabled === void 0 ? {} : { enabled: existing.enabled },
|
|
34108
|
+
...existing?.port === void 0 ? {} : { port: existing.port },
|
|
34109
|
+
...existing?.opencodeGoEnabled === void 0 ? {} : { opencodeGoEnabled: existing.opencodeGoEnabled }
|
|
34110
|
+
};
|
|
34111
|
+
}
|
|
34105
34112
|
async function loadGatewayKeyDocument(path) {
|
|
34106
34113
|
try {
|
|
34107
34114
|
const text = (await readHardenedOAuthSourceFile(path)).text;
|
|
@@ -34118,7 +34125,8 @@ async function loadGatewayKeyDocument(path) {
|
|
|
34118
34125
|
version: KEY_FORMAT_VERSION,
|
|
34119
34126
|
apiKey: document["apiKey"],
|
|
34120
34127
|
...typeof document["enabled"] === "boolean" ? { enabled: document["enabled"] } : {},
|
|
34121
|
-
...typeof port === "number" && Number.isSafeInteger(port) && port >= 1024 && port <= 65535 ? { port } : {}
|
|
34128
|
+
...typeof port === "number" && Number.isSafeInteger(port) && port >= 1024 && port <= 65535 ? { port } : {},
|
|
34129
|
+
...typeof document["opencodeGoEnabled"] === "boolean" ? { opencodeGoEnabled: document["opencodeGoEnabled"] } : {}
|
|
34122
34130
|
};
|
|
34123
34131
|
} catch (error) {
|
|
34124
34132
|
if (error instanceof OAuthSourceError && error.code === "not_found") return void 0;
|
|
@@ -34131,8 +34139,7 @@ async function loadOrCreateGatewayApiKey(path, configured) {
|
|
|
34131
34139
|
await persistGatewayKeyDocument(path, {
|
|
34132
34140
|
version: KEY_FORMAT_VERSION,
|
|
34133
34141
|
apiKey: configured,
|
|
34134
|
-
...existing
|
|
34135
|
-
...existing?.port === void 0 ? {} : { port: existing.port }
|
|
34142
|
+
...documentExtras(existing)
|
|
34136
34143
|
});
|
|
34137
34144
|
return configured;
|
|
34138
34145
|
}
|
|
@@ -34363,7 +34370,10 @@ var GatewayConfigSchema = z.object({
|
|
|
34363
34370
|
bind: z.string().default(GATEWAY_DEFAULT_BIND),
|
|
34364
34371
|
port: z.number().default(GATEWAY_DEFAULT_PORT),
|
|
34365
34372
|
apiKey: z.string(),
|
|
34366
|
-
rateLimit: z.number().default(0)
|
|
34373
|
+
rateLimit: z.number().default(0),
|
|
34374
|
+
opencodeGo: z.object({
|
|
34375
|
+
enabled: z.boolean().default(false)
|
|
34376
|
+
}).default({ enabled: false })
|
|
34367
34377
|
});
|
|
34368
34378
|
function resolveGatewayConfig(raw) {
|
|
34369
34379
|
const bind = raw?.bind ?? GATEWAY_DEFAULT_BIND;
|
|
@@ -34377,12 +34387,16 @@ function resolveGatewayConfig(raw) {
|
|
|
34377
34387
|
if (apiKey !== void 0 && (typeof apiKey !== "string" || apiKey.length === 0)) {
|
|
34378
34388
|
throw new Error("gateway.apiKey must be a non-empty string when set");
|
|
34379
34389
|
}
|
|
34390
|
+
const opencodeGoRaw = raw?.opencodeGo;
|
|
34380
34391
|
return {
|
|
34381
34392
|
enabled: raw?.enabled === true,
|
|
34382
34393
|
bind: bind.trim(),
|
|
34383
34394
|
port,
|
|
34384
34395
|
...apiKey === void 0 ? {} : { apiKey },
|
|
34385
|
-
rateLimit
|
|
34396
|
+
rateLimit,
|
|
34397
|
+
opencodeGo: {
|
|
34398
|
+
enabled: opencodeGoRaw?.enabled === true
|
|
34399
|
+
}
|
|
34386
34400
|
};
|
|
34387
34401
|
}
|
|
34388
34402
|
function isLoopbackBind(bind) {
|
|
@@ -34893,13 +34907,162 @@ data: ${JSON.stringify(gatewayErrorEnvelope(error).body)}
|
|
|
34893
34907
|
}
|
|
34894
34908
|
}
|
|
34895
34909
|
|
|
34910
|
+
// src/gateway-opencode-go.ts
|
|
34911
|
+
import { randomUUID } from "node:crypto";
|
|
34912
|
+
import { Readable } from "node:stream";
|
|
34913
|
+
import { pipeline } from "node:stream/promises";
|
|
34914
|
+
var OPENCODE_GO_ORIGIN = "https://opencode.ai";
|
|
34915
|
+
var OPENCODE_GO_CHAT_COMPLETIONS_URL = `${OPENCODE_GO_ORIGIN}/zen/go/v1/chat/completions`;
|
|
34916
|
+
var SESSION_MAP_MAX = 1024;
|
|
34917
|
+
var HOP_BY_HOP = /* @__PURE__ */ new Set([
|
|
34918
|
+
"connection",
|
|
34919
|
+
"keep-alive",
|
|
34920
|
+
"proxy-authenticate",
|
|
34921
|
+
"proxy-authorization",
|
|
34922
|
+
"te",
|
|
34923
|
+
"trailers",
|
|
34924
|
+
"transfer-encoding",
|
|
34925
|
+
"upgrade",
|
|
34926
|
+
"host",
|
|
34927
|
+
"content-length"
|
|
34928
|
+
]);
|
|
34929
|
+
function createOpencodeGoSessionMap(maxEntries = SESSION_MAP_MAX) {
|
|
34930
|
+
const map = /* @__PURE__ */ new Map();
|
|
34931
|
+
const limit = Number.isSafeInteger(maxEntries) && maxEntries > 0 ? maxEntries : SESSION_MAP_MAX;
|
|
34932
|
+
return {
|
|
34933
|
+
get(key) {
|
|
34934
|
+
const value = map.get(key);
|
|
34935
|
+
if (value === void 0) return void 0;
|
|
34936
|
+
map.delete(key);
|
|
34937
|
+
map.set(key, value);
|
|
34938
|
+
return value;
|
|
34939
|
+
},
|
|
34940
|
+
set(key, value) {
|
|
34941
|
+
if (map.has(key)) map.delete(key);
|
|
34942
|
+
map.set(key, value);
|
|
34943
|
+
while (map.size > limit) {
|
|
34944
|
+
const oldest = map.keys().next().value;
|
|
34945
|
+
if (oldest === void 0) break;
|
|
34946
|
+
map.delete(oldest);
|
|
34947
|
+
}
|
|
34948
|
+
},
|
|
34949
|
+
get size() {
|
|
34950
|
+
return map.size;
|
|
34951
|
+
}
|
|
34952
|
+
};
|
|
34953
|
+
}
|
|
34954
|
+
function resolveSessionId(req, bodyRecord, sessionMap) {
|
|
34955
|
+
const inbound = headerValue(req, "x-deepseek-harness-session-id") ?? headerValue(req, "x-opencode-session") ?? headerValue(req, "x-session-id") ?? (typeof bodyRecord["session_id"] === "string" && bodyRecord["session_id"].trim().length > 0 ? bodyRecord["session_id"].trim() : void 0);
|
|
34956
|
+
if (inbound === void 0) return randomUUID();
|
|
34957
|
+
const sticky = sessionMap.get(inbound);
|
|
34958
|
+
if (sticky !== void 0) return sticky;
|
|
34959
|
+
sessionMap.set(inbound, inbound);
|
|
34960
|
+
return inbound;
|
|
34961
|
+
}
|
|
34962
|
+
async function handleOpencodeGoChatCompletions(req, res, deps) {
|
|
34963
|
+
if (deps.isEnabled() !== true) {
|
|
34964
|
+
writeGatewayJson(res, 503, {
|
|
34965
|
+
error: {
|
|
34966
|
+
message: "OpenCode Go proxy is disabled",
|
|
34967
|
+
type: "api_error",
|
|
34968
|
+
code: "opencode_go_disabled"
|
|
34969
|
+
}
|
|
34970
|
+
});
|
|
34971
|
+
return;
|
|
34972
|
+
}
|
|
34973
|
+
if (OPENCODE_GO_CHAT_COMPLETIONS_URL !== `${OPENCODE_GO_ORIGIN}/zen/go/v1/chat/completions`) {
|
|
34974
|
+
writeGatewayJson(res, 503, {
|
|
34975
|
+
error: {
|
|
34976
|
+
message: "OpenCode Go upstream is misconfigured",
|
|
34977
|
+
type: "api_error",
|
|
34978
|
+
code: "opencode_go_misconfigured"
|
|
34979
|
+
}
|
|
34980
|
+
});
|
|
34981
|
+
return;
|
|
34982
|
+
}
|
|
34983
|
+
const upstreamKey = deps.getUpstreamApiKey().trim();
|
|
34984
|
+
if (upstreamKey.length === 0) {
|
|
34985
|
+
writeGatewayJson(res, 503, {
|
|
34986
|
+
error: {
|
|
34987
|
+
message: "OpenCode Go upstream API key is not configured",
|
|
34988
|
+
type: "api_error",
|
|
34989
|
+
code: "opencode_go_key_missing"
|
|
34990
|
+
}
|
|
34991
|
+
});
|
|
34992
|
+
return;
|
|
34993
|
+
}
|
|
34994
|
+
const bodyRecord = await readGatewayJsonBody(req);
|
|
34995
|
+
const sessionId = resolveSessionId(req, bodyRecord, deps.sessionMap);
|
|
34996
|
+
const wantStream = bodyRecord["stream"] === true;
|
|
34997
|
+
const body = `${JSON.stringify(bodyRecord)}
|
|
34998
|
+
`;
|
|
34999
|
+
let upstream;
|
|
35000
|
+
try {
|
|
35001
|
+
upstream = await deps.fetchImpl(OPENCODE_GO_CHAT_COMPLETIONS_URL, {
|
|
35002
|
+
method: "POST",
|
|
35003
|
+
headers: {
|
|
35004
|
+
authorization: `Bearer ${upstreamKey}`,
|
|
35005
|
+
"content-type": "application/json",
|
|
35006
|
+
accept: wantStream ? "text/event-stream" : "application/json",
|
|
35007
|
+
"x-opencode-session": sessionId
|
|
35008
|
+
},
|
|
35009
|
+
body
|
|
35010
|
+
});
|
|
35011
|
+
} catch {
|
|
35012
|
+
writeGatewayJson(res, 503, {
|
|
35013
|
+
error: {
|
|
35014
|
+
message: "OpenCode Go upstream request failed",
|
|
35015
|
+
type: "api_error",
|
|
35016
|
+
code: "opencode_go_upstream_error"
|
|
35017
|
+
}
|
|
35018
|
+
});
|
|
35019
|
+
return;
|
|
35020
|
+
}
|
|
35021
|
+
const contentType = upstream.headers.get("content-type") ?? "";
|
|
35022
|
+
const isEventStream = contentType.toLowerCase().includes("text/event-stream");
|
|
35023
|
+
const shouldStream = isEventStream || wantStream;
|
|
35024
|
+
const headers = {
|
|
35025
|
+
"cache-control": "no-store"
|
|
35026
|
+
};
|
|
35027
|
+
upstream.headers.forEach((value, name2) => {
|
|
35028
|
+
const lower = name2.toLowerCase();
|
|
35029
|
+
if (HOP_BY_HOP.has(lower)) return;
|
|
35030
|
+
headers[lower] = value;
|
|
35031
|
+
});
|
|
35032
|
+
if (!headers["content-type"] && isEventStream) {
|
|
35033
|
+
headers["content-type"] = "text/event-stream; charset=utf-8";
|
|
35034
|
+
}
|
|
35035
|
+
if (!shouldStream || upstream.body === null) {
|
|
35036
|
+
const buffer = Buffer.from(await upstream.arrayBuffer());
|
|
35037
|
+
if (!headers["content-type"]) headers["content-type"] = "application/json; charset=utf-8";
|
|
35038
|
+
headers["content-length"] = String(buffer.byteLength);
|
|
35039
|
+
res.writeHead(upstream.status, headers);
|
|
35040
|
+
res.end(buffer);
|
|
35041
|
+
return;
|
|
35042
|
+
}
|
|
35043
|
+
res.writeHead(upstream.status, headers);
|
|
35044
|
+
const nodeStream = Readable.fromWeb(upstream.body);
|
|
35045
|
+
await pipeline(nodeStream, res);
|
|
35046
|
+
}
|
|
35047
|
+
function headerValue(req, name2) {
|
|
35048
|
+
const raw = req.headers[name2];
|
|
35049
|
+
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
35050
|
+
if (typeof value !== "string") return void 0;
|
|
35051
|
+
const trimmed = value.trim();
|
|
35052
|
+
return trimmed.length === 0 ? void 0 : trimmed;
|
|
35053
|
+
}
|
|
35054
|
+
|
|
34896
35055
|
// src/gateway-http.ts
|
|
34897
35056
|
function createGatewayHttpServer(options) {
|
|
34898
35057
|
if (!isLoopbackBind(options.config.bind) && options.apiKey.length === 0) {
|
|
34899
35058
|
throw new Error("gateway bind outside loopback requires a Bearer API key");
|
|
34900
35059
|
}
|
|
35060
|
+
const resolved = {
|
|
35061
|
+
...options,
|
|
35062
|
+
sessionMap: options.sessionMap ?? createOpencodeGoSessionMap()
|
|
35063
|
+
};
|
|
34901
35064
|
return createServer2((req, res) => {
|
|
34902
|
-
void route(req, res,
|
|
35065
|
+
void route(req, res, resolved).catch((error) => {
|
|
34903
35066
|
if (res.headersSent) {
|
|
34904
35067
|
res.end();
|
|
34905
35068
|
return;
|
|
@@ -34947,6 +35110,15 @@ async function route(req, res, options) {
|
|
|
34947
35110
|
return;
|
|
34948
35111
|
}
|
|
34949
35112
|
if (req.method === "POST" && url.pathname === "/v1/chat/completions") {
|
|
35113
|
+
if (options.isOpencodeGoEnabled?.() === true) {
|
|
35114
|
+
await handleOpencodeGoChatCompletions(req, res, {
|
|
35115
|
+
fetchImpl: options.fetchImpl ?? fetch,
|
|
35116
|
+
sessionMap: options.sessionMap ?? createOpencodeGoSessionMap(),
|
|
35117
|
+
getUpstreamApiKey: options.getUpstreamApiKey ?? (() => options.apiKey),
|
|
35118
|
+
isEnabled: options.isOpencodeGoEnabled
|
|
35119
|
+
});
|
|
35120
|
+
return;
|
|
35121
|
+
}
|
|
34950
35122
|
await handleOpenAiChatCompletions(req, res, options.backend);
|
|
34951
35123
|
return;
|
|
34952
35124
|
}
|
|
@@ -34986,9 +35158,11 @@ function createCodingOAuthGatewayController(options) {
|
|
|
34986
35158
|
if (options.grok === void 0) throw new Error("gateway requires a backend or Grok session");
|
|
34987
35159
|
return createSessionGatewayBackend(options.grok, options.subscriptions ?? []);
|
|
34988
35160
|
};
|
|
35161
|
+
const sessionMap = createOpencodeGoSessionMap();
|
|
34989
35162
|
let server;
|
|
34990
35163
|
let apiKey = yaml.apiKey ?? "";
|
|
34991
35164
|
let port = yaml.port;
|
|
35165
|
+
let opencodeGoEnabled = yaml.opencodeGo.enabled;
|
|
34992
35166
|
let lock = Promise.resolve();
|
|
34993
35167
|
const withLock = async (work) => {
|
|
34994
35168
|
const previous = lock;
|
|
@@ -35009,7 +35183,7 @@ function createCodingOAuthGatewayController(options) {
|
|
|
35009
35183
|
server = void 0;
|
|
35010
35184
|
await closeGateway(current).catch(() => void 0);
|
|
35011
35185
|
};
|
|
35012
|
-
const activeConfig = () => ({ ...yaml, port });
|
|
35186
|
+
const activeConfig = () => ({ ...yaml, port, opencodeGo: { enabled: opencodeGoEnabled } });
|
|
35013
35187
|
const snapshot = async (enabled) => {
|
|
35014
35188
|
let models = [];
|
|
35015
35189
|
try {
|
|
@@ -35026,7 +35200,8 @@ function createCodingOAuthGatewayController(options) {
|
|
|
35026
35200
|
keyAvailable: apiKey.length > 0,
|
|
35027
35201
|
keyHint: apiKey.length === 0 ? "" : maskGatewayApiKey(apiKey),
|
|
35028
35202
|
models,
|
|
35029
|
-
warning: GATEWAY_TOS_WARNING
|
|
35203
|
+
warning: GATEWAY_TOS_WARNING,
|
|
35204
|
+
opencodeGoEnabled
|
|
35030
35205
|
};
|
|
35031
35206
|
};
|
|
35032
35207
|
const persistState = async (next) => {
|
|
@@ -35037,17 +35212,27 @@ function createCodingOAuthGatewayController(options) {
|
|
|
35037
35212
|
const nextEnabled = next.enabled ?? document?.enabled;
|
|
35038
35213
|
const nextPort = next.port ?? document?.port ?? port;
|
|
35039
35214
|
port = nextPort;
|
|
35215
|
+
if (next.opencodeGoEnabled !== void 0) opencodeGoEnabled = next.opencodeGoEnabled;
|
|
35216
|
+
const nextOpencodeGo = next.opencodeGoEnabled ?? document?.opencodeGoEnabled;
|
|
35040
35217
|
await persistGatewayKeyDocument(path, {
|
|
35041
35218
|
version: 1,
|
|
35042
35219
|
apiKey: nextKey,
|
|
35043
35220
|
...nextEnabled === void 0 ? {} : { enabled: nextEnabled },
|
|
35044
|
-
port: nextPort
|
|
35221
|
+
port: nextPort,
|
|
35222
|
+
...nextOpencodeGo === void 0 ? {} : { opencodeGoEnabled: nextOpencodeGo }
|
|
35045
35223
|
});
|
|
35046
35224
|
};
|
|
35047
35225
|
const listen = async () => {
|
|
35048
35226
|
if (apiKey.length === 0) apiKey = await loadOrCreateGatewayApiKey(path, yaml.apiKey);
|
|
35049
35227
|
const config = activeConfig();
|
|
35050
|
-
const http = createGatewayHttpServer({
|
|
35228
|
+
const http = createGatewayHttpServer({
|
|
35229
|
+
config,
|
|
35230
|
+
apiKey,
|
|
35231
|
+
backend: backend(),
|
|
35232
|
+
sessionMap,
|
|
35233
|
+
isOpencodeGoEnabled: () => opencodeGoEnabled,
|
|
35234
|
+
getUpstreamApiKey: () => apiKey
|
|
35235
|
+
});
|
|
35051
35236
|
try {
|
|
35052
35237
|
await listenGateway(http, config);
|
|
35053
35238
|
} catch (error) {
|
|
@@ -35062,13 +35247,21 @@ function createCodingOAuthGatewayController(options) {
|
|
|
35062
35247
|
const document = await loadGatewayKeyDocument(path);
|
|
35063
35248
|
return document?.enabled ?? yaml.enabled;
|
|
35064
35249
|
};
|
|
35250
|
+
const desiredOpencodeGoEnabled = async () => {
|
|
35251
|
+
const document = await loadGatewayKeyDocument(path);
|
|
35252
|
+
return document?.opencodeGoEnabled ?? yaml.opencodeGo.enabled;
|
|
35253
|
+
};
|
|
35065
35254
|
const hydratePort = async () => {
|
|
35066
35255
|
const document = await loadGatewayKeyDocument(path);
|
|
35067
35256
|
if (document?.port !== void 0) port = document.port;
|
|
35068
35257
|
};
|
|
35258
|
+
const hydrateOpencodeGo = async () => {
|
|
35259
|
+
opencodeGoEnabled = await desiredOpencodeGoEnabled();
|
|
35260
|
+
};
|
|
35069
35261
|
return {
|
|
35070
35262
|
async status() {
|
|
35071
35263
|
await hydratePort();
|
|
35264
|
+
await hydrateOpencodeGo();
|
|
35072
35265
|
if (apiKey.length === 0) {
|
|
35073
35266
|
const document = await loadGatewayKeyDocument(path);
|
|
35074
35267
|
apiKey = document?.apiKey ?? "";
|
|
@@ -35078,6 +35271,7 @@ function createCodingOAuthGatewayController(options) {
|
|
|
35078
35271
|
startIfEnabled() {
|
|
35079
35272
|
return withLock(async () => {
|
|
35080
35273
|
await hydratePort();
|
|
35274
|
+
await hydrateOpencodeGo();
|
|
35081
35275
|
if (!await desiredEnabled()) return void 0;
|
|
35082
35276
|
if (server !== void 0) return { bind: yaml.bind, port, close: () => closeServer() };
|
|
35083
35277
|
try {
|
|
@@ -35090,6 +35284,7 @@ function createCodingOAuthGatewayController(options) {
|
|
|
35090
35284
|
setEnabled(enabled) {
|
|
35091
35285
|
return withLock(async () => {
|
|
35092
35286
|
await hydratePort();
|
|
35287
|
+
await hydrateOpencodeGo();
|
|
35093
35288
|
if (apiKey.length === 0) apiKey = await loadOrCreateGatewayApiKey(path, yaml.apiKey);
|
|
35094
35289
|
await persistState({ enabled });
|
|
35095
35290
|
if (enabled && server === void 0) {
|
|
@@ -35105,6 +35300,7 @@ function createCodingOAuthGatewayController(options) {
|
|
|
35105
35300
|
setPort(nextPort) {
|
|
35106
35301
|
return withLock(async () => {
|
|
35107
35302
|
await hydratePort();
|
|
35303
|
+
await hydrateOpencodeGo();
|
|
35108
35304
|
const wanted = assertGatewayPort(nextPort);
|
|
35109
35305
|
if (apiKey.length === 0) apiKey = await loadOrCreateGatewayApiKey(path, yaml.apiKey);
|
|
35110
35306
|
const previous = port;
|
|
@@ -35126,6 +35322,14 @@ function createCodingOAuthGatewayController(options) {
|
|
|
35126
35322
|
}
|
|
35127
35323
|
});
|
|
35128
35324
|
},
|
|
35325
|
+
setOpencodeGoEnabled(enabled) {
|
|
35326
|
+
return withLock(async () => {
|
|
35327
|
+
await hydratePort();
|
|
35328
|
+
if (apiKey.length === 0) apiKey = await loadOrCreateGatewayApiKey(path, yaml.apiKey);
|
|
35329
|
+
await persistState({ opencodeGoEnabled: enabled });
|
|
35330
|
+
return snapshot();
|
|
35331
|
+
});
|
|
35332
|
+
},
|
|
35129
35333
|
revealKey() {
|
|
35130
35334
|
return withLock(async () => {
|
|
35131
35335
|
if (apiKey.length === 0) apiKey = await loadOrCreateGatewayApiKey(path, yaml.apiKey);
|
|
@@ -35135,6 +35339,7 @@ function createCodingOAuthGatewayController(options) {
|
|
|
35135
35339
|
rotateKey() {
|
|
35136
35340
|
return withLock(async () => {
|
|
35137
35341
|
await hydratePort();
|
|
35342
|
+
await hydrateOpencodeGo();
|
|
35138
35343
|
const next = generateGatewayApiKey();
|
|
35139
35344
|
const document = await loadGatewayKeyDocument(path);
|
|
35140
35345
|
await persistState({
|
|
@@ -35209,14 +35414,19 @@ async function handleGatewaySettings(req, res, controller, ownerRequestPolicy) {
|
|
|
35209
35414
|
const payload = typeof raw === "object" && raw !== null ? raw : {};
|
|
35210
35415
|
const enabled = payload.enabled;
|
|
35211
35416
|
const port = payload.port;
|
|
35212
|
-
|
|
35213
|
-
|
|
35417
|
+
const opencodeGoEnabled = payload.opencodeGoEnabled;
|
|
35418
|
+
if (enabled === void 0 && port === void 0 && opencodeGoEnabled === void 0) {
|
|
35419
|
+
json3(res, 400, { error: "enabled, port, or opencodeGoEnabled is required" });
|
|
35214
35420
|
return;
|
|
35215
35421
|
}
|
|
35216
35422
|
if (enabled !== void 0 && typeof enabled !== "boolean") {
|
|
35217
35423
|
json3(res, 400, { error: "enabled must be a boolean" });
|
|
35218
35424
|
return;
|
|
35219
35425
|
}
|
|
35426
|
+
if (opencodeGoEnabled !== void 0 && typeof opencodeGoEnabled !== "boolean") {
|
|
35427
|
+
json3(res, 400, { error: "opencodeGoEnabled must be a boolean" });
|
|
35428
|
+
return;
|
|
35429
|
+
}
|
|
35220
35430
|
if (port !== void 0) {
|
|
35221
35431
|
if (typeof port !== "number" || !Number.isSafeInteger(port)) {
|
|
35222
35432
|
json3(res, 400, { error: "port must be an integer" });
|
|
@@ -35230,6 +35440,9 @@ async function handleGatewaySettings(req, res, controller, ownerRequestPolicy) {
|
|
|
35230
35440
|
}
|
|
35231
35441
|
await controller.setPort(port);
|
|
35232
35442
|
}
|
|
35443
|
+
if (typeof opencodeGoEnabled === "boolean") {
|
|
35444
|
+
await controller.setOpencodeGoEnabled(opencodeGoEnabled);
|
|
35445
|
+
}
|
|
35233
35446
|
const status = typeof enabled === "boolean" ? await controller.setEnabled(enabled) : await controller.status();
|
|
35234
35447
|
json3(res, 200, status);
|
|
35235
35448
|
return;
|