@ngosangns/ns-bridge 0.1.30 → 0.1.32
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/dist/hosts/dsh/arnict/dist/index.js +1 -1
- package/dist/hosts/dsh/devin/dist/index.js +1 -1
- package/dist/hosts/dsh/grok/dist/index.js +1 -1
- package/dist/hosts/dsh/kiro/dist/index.js +1 -1
- package/dist/hosts/dsh/qoder/dist/index.js +28 -52
- package/dist/hosts/omp/dist/index.js +394 -171
- package/dist/hosts/omp/package.json +1 -1
- package/dist/hosts/pi/dist/index.js +233 -147
- package/dist/hosts/pi/package.json +1 -1
- package/dist/refresh-entry.js +213 -20
- package/dist/serve-entry.js +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @ngosangns/ns-bridge 0.1.
|
|
1
|
+
// @ngosangns/ns-bridge 0.1.32 — prebuilt host bundle.
|
|
2
2
|
import { createRequire as __nsBridgeCreateRequire } from 'node:module';
|
|
3
3
|
const require = __nsBridgeCreateRequire(import.meta.url);
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -4773,13 +4773,12 @@ function createProviderConfig(models) {
|
|
|
4773
4773
|
api: ARNICT_API,
|
|
4774
4774
|
models,
|
|
4775
4775
|
streamSimple: streamArnictForPi,
|
|
4776
|
-
// OMP
|
|
4777
|
-
//
|
|
4778
|
-
//
|
|
4779
|
-
// null here and do not become that authoritative list.
|
|
4776
|
+
// OMP 19.1.1 reads `.length` on this return, so null throws during discovery.
|
|
4777
|
+
// A disk snapshot, fresh or past the 15-minute TTL, is a real catalog. The
|
|
4778
|
+
// bootstrap list stays null so it is not pinned as authoritative for 24h.
|
|
4780
4779
|
fetchDynamicModels: async () => {
|
|
4781
4780
|
const latest = await refreshArnictModels({ allowNetwork: false });
|
|
4782
|
-
if (
|
|
4781
|
+
if (latest.source !== "cache" || latest.models.length === 0) return null;
|
|
4783
4782
|
return latest.models;
|
|
4784
4783
|
},
|
|
4785
4784
|
async refreshModels() {
|
|
@@ -8460,6 +8459,12 @@ function loadCacheFile() {
|
|
|
8460
8459
|
function getCachedModels() {
|
|
8461
8460
|
return withCompaction(loadCacheFile()?.models ?? devinModels);
|
|
8462
8461
|
}
|
|
8462
|
+
function readDevinDiskModels() {
|
|
8463
|
+
const models = loadCacheFile()?.models;
|
|
8464
|
+
if (!models)
|
|
8465
|
+
return void 0;
|
|
8466
|
+
return withCompaction(models);
|
|
8467
|
+
}
|
|
8463
8468
|
function isCacheStale(now = Date.now()) {
|
|
8464
8469
|
const cache = loadCacheFile();
|
|
8465
8470
|
return cache === void 0 || now - cache.fetchedAt > CACHE_TTL_MS;
|
|
@@ -8733,14 +8738,13 @@ function providerConfig(models, apiKey) {
|
|
|
8733
8738
|
// When CLI credentials.toml (or env) already has a token, set apiKey so Pi
|
|
8734
8739
|
// marks the provider configured for --list-models without /login.
|
|
8735
8740
|
...apiKey ? { apiKey } : {},
|
|
8736
|
-
// OMP
|
|
8737
|
-
//
|
|
8738
|
-
//
|
|
8739
|
-
// landed is what gets stored. `models` above is what the host shows until then.
|
|
8741
|
+
// OMP 19.1.1 reads `.length` on this return, so null throws during discovery.
|
|
8742
|
+
// A catalog file on disk is returned even past the 24h TTL. A missing or
|
|
8743
|
+
// empty file stays null so the bootstrap seed is not pinned for a day.
|
|
8740
8744
|
fetchDynamicModels: async () => {
|
|
8741
|
-
|
|
8742
|
-
|
|
8743
|
-
return latest.
|
|
8745
|
+
const latest = readDevinDiskModels();
|
|
8746
|
+
if (!latest || latest.length === 0) return null;
|
|
8747
|
+
return latest.map(toPiDevinModel);
|
|
8744
8748
|
},
|
|
8745
8749
|
async refreshModels() {
|
|
8746
8750
|
return models;
|
|
@@ -10124,13 +10128,12 @@ function createProviderConfig2(models) {
|
|
|
10124
10128
|
api: GROK_API,
|
|
10125
10129
|
models,
|
|
10126
10130
|
streamSimple: streamGrokForPi,
|
|
10127
|
-
// OMP
|
|
10128
|
-
//
|
|
10129
|
-
//
|
|
10130
|
-
// null here and do not become that authoritative list.
|
|
10131
|
+
// OMP 19.1.1 reads `.length` on this return, so null throws during discovery.
|
|
10132
|
+
// A disk snapshot, fresh or past the 15-minute TTL, is a real catalog. The
|
|
10133
|
+
// bootstrap list stays null so it is not pinned as authoritative for 24h.
|
|
10131
10134
|
fetchDynamicModels: async () => {
|
|
10132
10135
|
const latest = await refreshGrokModels({ allowCli: false });
|
|
10133
|
-
if (
|
|
10136
|
+
if (latest.source !== "cache" || latest.models.length === 0) return null;
|
|
10134
10137
|
return latest.models;
|
|
10135
10138
|
},
|
|
10136
10139
|
async refreshModels() {
|
|
@@ -11104,6 +11107,11 @@ function allCacheEntries(cache) {
|
|
|
11104
11107
|
function kiroProfileCacheKey(profileArn) {
|
|
11105
11108
|
return createHash4("sha256").update(profileArn).digest("base64url").slice(0, 16);
|
|
11106
11109
|
}
|
|
11110
|
+
function hasCachedKiroCatalog(region) {
|
|
11111
|
+
const cache = readManagementCache();
|
|
11112
|
+
const models = activeCacheEntry(cache, region)?.models ?? cache?.regions[region]?.models;
|
|
11113
|
+
return Array.isArray(models) && models.length > 0;
|
|
11114
|
+
}
|
|
11107
11115
|
function activeCacheEntry(cache, region) {
|
|
11108
11116
|
const override = getKiroProfileOverride();
|
|
11109
11117
|
return override ? cache?.profiles?.[kiroProfileCacheKey(override.arn)] : cache?.regions[region];
|
|
@@ -13741,13 +13749,12 @@ ${current.models.map((model) => model.id).join("\n")}`;
|
|
|
13741
13749
|
authHeader: false,
|
|
13742
13750
|
streamSimple: streamKiroForPi,
|
|
13743
13751
|
models: current.models,
|
|
13744
|
-
// OMP
|
|
13745
|
-
//
|
|
13746
|
-
//
|
|
13747
|
-
// in place and does not lock a stale catalog.
|
|
13752
|
+
// OMP 19.1.1 reads `.length` on this return, so null throws during discovery.
|
|
13753
|
+
// A disk catalog is returned even past the 1h TTL. No disk entry stays null
|
|
13754
|
+
// so the bootstrap list is not pinned as authoritative for 24h.
|
|
13748
13755
|
fetchDynamicModels: async () => {
|
|
13749
13756
|
const latest = localKiroCatalog();
|
|
13750
|
-
if (latest.models.length === 0 ||
|
|
13757
|
+
if (latest.models.length === 0 || !hasCachedKiroCatalog(latest.region)) return null;
|
|
13751
13758
|
return latest.models;
|
|
13752
13759
|
},
|
|
13753
13760
|
async refreshModels() {
|
|
@@ -13945,6 +13952,7 @@ function loadExports() {
|
|
|
13945
13952
|
"model_cache_decrypt",
|
|
13946
13953
|
"qodercontext_new",
|
|
13947
13954
|
"qodercontext_prepareInferRequest",
|
|
13955
|
+
"qodercontext_prepareRequest",
|
|
13948
13956
|
"requestresult_url",
|
|
13949
13957
|
"requestresult_body",
|
|
13950
13958
|
"requestresult_headers",
|
|
@@ -14094,6 +14102,41 @@ function signQoderInferRequest(endpoint, bodyJson, modelKey, modelSource, identi
|
|
|
14094
14102
|
exports.__wbg_qodercontext_free(ctx, 0);
|
|
14095
14103
|
}
|
|
14096
14104
|
}
|
|
14105
|
+
function callPrepareRequest(exports, ctx, endpoint, path, method, authType, body) {
|
|
14106
|
+
const retptr = exports.__wbindgen_add_to_stack_pointer(-16);
|
|
14107
|
+
try {
|
|
14108
|
+
const [endpointPtr, endpointLen] = passStringToWasm(exports, endpoint);
|
|
14109
|
+
const [pathPtr, pathLen] = passStringToWasm(exports, path);
|
|
14110
|
+
const [methodPtr, methodLen] = passStringToWasm(exports, method);
|
|
14111
|
+
const [authPtr, authLen] = passStringToWasm(exports, authType);
|
|
14112
|
+
const [bodyPtr, bodyLen] = body === void 0 ? [0, 0] : passStringToWasm(exports, body);
|
|
14113
|
+
exports.qodercontext_prepareRequest(retptr, ctx, endpointPtr, endpointLen, pathPtr, pathLen, methodPtr, methodLen, authPtr, authLen, bodyPtr, bodyLen, 0, 0);
|
|
14114
|
+
const view = new Int32Array(exports.memory.buffer, retptr, 4);
|
|
14115
|
+
if ((view[2] ?? 0) !== 0)
|
|
14116
|
+
throw takeObject(view[1] ?? 0);
|
|
14117
|
+
return (view[0] ?? 0) >>> 0;
|
|
14118
|
+
} finally {
|
|
14119
|
+
exports.__wbindgen_add_to_stack_pointer(16);
|
|
14120
|
+
}
|
|
14121
|
+
}
|
|
14122
|
+
function signQoderRequest(endpoint, path, method, authType, body, identity, cosyVersion) {
|
|
14123
|
+
const exports = loadExports();
|
|
14124
|
+
const ctx = callContextNew(exports, identity, cosyVersion);
|
|
14125
|
+
try {
|
|
14126
|
+
const result = callPrepareRequest(exports, ctx, endpoint, path, method, authType, body);
|
|
14127
|
+
try {
|
|
14128
|
+
const url = wasmResultString(exports, exports.requestresult_url, result);
|
|
14129
|
+
if (!url)
|
|
14130
|
+
throw new Error("qoder request signer returned an empty url");
|
|
14131
|
+
const signedBody = wasmResultString(exports, exports.requestresult_body, result);
|
|
14132
|
+
return { url, headers: signatureHeaders(exports, result), body: signedBody ?? "" };
|
|
14133
|
+
} finally {
|
|
14134
|
+
exports.__wbg_requestresult_free(result, 0);
|
|
14135
|
+
}
|
|
14136
|
+
} finally {
|
|
14137
|
+
exports.__wbg_qodercontext_free(ctx, 0);
|
|
14138
|
+
}
|
|
14139
|
+
}
|
|
14097
14140
|
function storedString(record, field) {
|
|
14098
14141
|
const value = record[field];
|
|
14099
14142
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
@@ -14189,12 +14232,14 @@ function requireQoderAuth(env = process.env, home = homedir16()) {
|
|
|
14189
14232
|
}
|
|
14190
14233
|
|
|
14191
14234
|
// ../qoder-core/dist/catalog.js
|
|
14235
|
+
import { readFileSync as readFileSync11 } from "node:fs";
|
|
14236
|
+
import { homedir as homedir17 } from "node:os";
|
|
14237
|
+
import { join as join17 } from "node:path";
|
|
14192
14238
|
var QODER_CATALOG_PROVIDER_ID = "qoder";
|
|
14193
14239
|
var QODER_CATALOG_FILE = `${QODER_CATALOG_PROVIDER_ID}.models.json`;
|
|
14240
|
+
var QODER_CATALOG_CACHE_DIR_ENV = "NS_QODER_CATALOG_CACHE_DIR";
|
|
14194
14241
|
var QODER_DEFAULT_MAX_TOKENS = 16384;
|
|
14195
|
-
var
|
|
14196
|
-
var QODER_WIRE_CONTEXT_WINDOW = QODER_WIRE_BODY_LIMIT_BYTES / 4;
|
|
14197
|
-
var QODER_DEFAULT_CONTEXT_WINDOW = QODER_WIRE_CONTEXT_WINDOW;
|
|
14242
|
+
var QODER_DEFAULT_CONTEXT_WINDOW = 2e5;
|
|
14198
14243
|
var BOOTSTRAP_IDS = [
|
|
14199
14244
|
"auto",
|
|
14200
14245
|
"ultimate",
|
|
@@ -14238,6 +14283,28 @@ var QODER_MODEL_DISPLAY_NAMES = {
|
|
|
14238
14283
|
function qoderBootstrapModels() {
|
|
14239
14284
|
return BOOTSTRAP_IDS.map((value) => qoderModelFromInfo({ value, isEnabled: true }));
|
|
14240
14285
|
}
|
|
14286
|
+
function qoderCatalogPath(cacheDir) {
|
|
14287
|
+
return join17(cacheDir, QODER_CATALOG_FILE);
|
|
14288
|
+
}
|
|
14289
|
+
function qoderCatalogCacheDir(env = process.env, home = homedir17()) {
|
|
14290
|
+
const override = env[QODER_CATALOG_CACHE_DIR_ENV]?.trim();
|
|
14291
|
+
return override || join17(home, ".pi", "agent", "cache", "ns-pi-provider");
|
|
14292
|
+
}
|
|
14293
|
+
function resolveQoderModelSpec(modelId, cacheDir = qoderCatalogCacheDir()) {
|
|
14294
|
+
const listed2 = readQoderCatalog({ cacheDir });
|
|
14295
|
+
return listed2.find((model) => model.id === modelId) ?? qoderBootstrapModels().find((model) => model.id === modelId);
|
|
14296
|
+
}
|
|
14297
|
+
function readQoderCatalog(options) {
|
|
14298
|
+
try {
|
|
14299
|
+
const raw = readFileSync11(qoderCatalogPath(options.cacheDir), "utf8");
|
|
14300
|
+
const parsed = JSON.parse(raw);
|
|
14301
|
+
if (!parsed?.models?.length)
|
|
14302
|
+
return qoderBootstrapModels();
|
|
14303
|
+
return parsed.models;
|
|
14304
|
+
} catch {
|
|
14305
|
+
return qoderBootstrapModels();
|
|
14306
|
+
}
|
|
14307
|
+
}
|
|
14241
14308
|
var EFFORT_ORDER = ["minimal", "low", "medium", "high", "xhigh", "max"];
|
|
14242
14309
|
function positive(value) {
|
|
14243
14310
|
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
@@ -14258,7 +14325,7 @@ function qoderModelFromInfo(info) {
|
|
|
14258
14325
|
name: info.displayName ?? QODER_MODEL_DISPLAY_NAMES[info.value] ?? info.value,
|
|
14259
14326
|
reasoning: info.isReasoning === true || efforts.length > 0,
|
|
14260
14327
|
input: info.isVl === true ? ["text", "image"] : ["text"],
|
|
14261
|
-
contextWindow:
|
|
14328
|
+
contextWindow: declared,
|
|
14262
14329
|
maxTokens: positive(info.maxOutputTokens) ? info.maxOutputTokens : QODER_DEFAULT_MAX_TOKENS,
|
|
14263
14330
|
...efforts.length > 0 ? { efforts } : {}
|
|
14264
14331
|
};
|
|
@@ -14324,73 +14391,11 @@ function qoderModelInfosFromVendorCatalog(raw, scene) {
|
|
|
14324
14391
|
}
|
|
14325
14392
|
|
|
14326
14393
|
// ../qoder-core/dist/models-api.js
|
|
14327
|
-
import { readdirSync as readdirSync3, readFileSync as
|
|
14328
|
-
import { join as
|
|
14329
|
-
|
|
14330
|
-
|
|
14331
|
-
|
|
14332
|
-
try {
|
|
14333
|
-
return [{ dir, mtime: statSync3(dir).mtimeMs }];
|
|
14334
|
-
} catch {
|
|
14335
|
-
return [];
|
|
14336
|
-
}
|
|
14337
|
-
});
|
|
14338
|
-
dirs.sort((a, b) => b.mtime - a.mtime);
|
|
14339
|
-
for (const { dir } of dirs) {
|
|
14340
|
-
const file = newestCatalog(dir);
|
|
14341
|
-
if (file)
|
|
14342
|
-
return { dir, file };
|
|
14343
|
-
}
|
|
14344
|
-
return void 0;
|
|
14345
|
-
} catch {
|
|
14346
|
-
return void 0;
|
|
14347
|
-
}
|
|
14348
|
-
}
|
|
14349
|
-
function newestCatalog(dir) {
|
|
14350
|
-
try {
|
|
14351
|
-
const files = readdirSync3(dir).flatMap((name) => {
|
|
14352
|
-
const match = /^catalog-v(\d+)$/.exec(name);
|
|
14353
|
-
return match ? [{ file: join17(dir, name), version: Number(match[1]) }] : [];
|
|
14354
|
-
}).sort((a, b) => b.version - a.version);
|
|
14355
|
-
return files[0]?.file;
|
|
14356
|
-
} catch {
|
|
14357
|
-
return void 0;
|
|
14358
|
-
}
|
|
14359
|
-
}
|
|
14360
|
-
function qoderVendorCatalogFile(configDir) {
|
|
14361
|
-
const root = join17(configDir, ".models");
|
|
14362
|
-
let uid;
|
|
14363
|
-
let scene;
|
|
14364
|
-
try {
|
|
14365
|
-
const pointer = JSON.parse(readFileSync11(join17(root, "default"), "utf8"));
|
|
14366
|
-
if (typeof pointer.uid === "string" && pointer.uid)
|
|
14367
|
-
uid = pointer.uid;
|
|
14368
|
-
if (typeof pointer.scene === "string" && pointer.scene)
|
|
14369
|
-
scene = pointer.scene;
|
|
14370
|
-
} catch {
|
|
14371
|
-
}
|
|
14372
|
-
let dir = uid ? join17(root, uid) : void 0;
|
|
14373
|
-
let file = dir ? newestCatalog(dir) : void 0;
|
|
14374
|
-
if (!file) {
|
|
14375
|
-
const found = newestCatalogDirectory(root);
|
|
14376
|
-
dir = found?.dir;
|
|
14377
|
-
file = found?.file;
|
|
14378
|
-
}
|
|
14379
|
-
if (!dir || !file)
|
|
14380
|
-
return void 0;
|
|
14381
|
-
return { file, uid: dir.slice(root.length + 1), ...scene ? { scene } : {} };
|
|
14382
|
-
}
|
|
14383
|
-
async function fetchQoderModels(_options = {}) {
|
|
14384
|
-
try {
|
|
14385
|
-
const target = qoderVendorCatalogFile(qoderConfigDir());
|
|
14386
|
-
if (!target)
|
|
14387
|
-
return qoderBootstrapModels();
|
|
14388
|
-
const plain = decryptQoderModelCache(readFileSync11(target.file, "utf8"), target.uid);
|
|
14389
|
-
return qoderModelsFromModelInfos(qoderModelInfosFromVendorCatalog(plain, target.scene));
|
|
14390
|
-
} catch {
|
|
14391
|
-
return qoderBootstrapModels();
|
|
14392
|
-
}
|
|
14393
|
-
}
|
|
14394
|
+
import { readdirSync as readdirSync3, readFileSync as readFileSync12, statSync as statSync3 } from "node:fs";
|
|
14395
|
+
import { join as join18 } from "node:path";
|
|
14396
|
+
|
|
14397
|
+
// ../qoder-core/dist/stream.js
|
|
14398
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
14394
14399
|
|
|
14395
14400
|
// ../qoder-core/dist/prompt.js
|
|
14396
14401
|
function imageDataUrl(data, mimeType) {
|
|
@@ -14439,7 +14444,9 @@ function toWireMessage(message) {
|
|
|
14439
14444
|
return void 0;
|
|
14440
14445
|
return {
|
|
14441
14446
|
role: "assistant",
|
|
14442
|
-
|
|
14447
|
+
// Kimi, DeepSeek-Flash and MiniMax reject a tool-only turn whose content is
|
|
14448
|
+
// null. An empty string is the same "no text" and those models accept it.
|
|
14449
|
+
content: text || "",
|
|
14443
14450
|
...toolCalls.length > 0 ? { tool_calls: toolCalls } : {}
|
|
14444
14451
|
};
|
|
14445
14452
|
}
|
|
@@ -14574,7 +14581,7 @@ function reduceWireChunk(state, chunk) {
|
|
|
14574
14581
|
ensureStart3(state, events);
|
|
14575
14582
|
if (typeof record.id === "string" && record.id)
|
|
14576
14583
|
state.responseId = record.id;
|
|
14577
|
-
if (typeof record.model === "string" && record.model)
|
|
14584
|
+
if (typeof record.model === "string" && record.model && record.model !== "auto")
|
|
14578
14585
|
state.upstreamModel = record.model;
|
|
14579
14586
|
if (record.raw_usage !== void 0 || record.usage !== void 0) {
|
|
14580
14587
|
const raw = record.raw_usage ?? record.usage;
|
|
@@ -14674,7 +14681,6 @@ function qoderSessionId(raw) {
|
|
|
14674
14681
|
}
|
|
14675
14682
|
|
|
14676
14683
|
// ../qoder-core/dist/stream.js
|
|
14677
|
-
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
14678
14684
|
var QODER_WIRE_VERSION = "1.1.83";
|
|
14679
14685
|
var QODER_INFER_ORIGIN = "https://api2.qoder.sh";
|
|
14680
14686
|
var ANONYMOUS_SIGNING_IDENTITY = {
|
|
@@ -14716,40 +14722,6 @@ function machineOs() {
|
|
|
14716
14722
|
const arch = process.arch === "arm64" ? "aarch64" : process.arch;
|
|
14717
14723
|
return `${arch}_${process.platform}`;
|
|
14718
14724
|
}
|
|
14719
|
-
function estimateQoderBodyBytes(payload) {
|
|
14720
|
-
try {
|
|
14721
|
-
return Buffer.byteLength(JSON.stringify(payload));
|
|
14722
|
-
} catch {
|
|
14723
|
-
return Number.MAX_SAFE_INTEGER;
|
|
14724
|
-
}
|
|
14725
|
-
}
|
|
14726
|
-
function fitQoderBody(payload) {
|
|
14727
|
-
const messages = payload.messages;
|
|
14728
|
-
if (!Array.isArray(messages) || messages.length <= 1)
|
|
14729
|
-
return payload;
|
|
14730
|
-
if (estimateQoderBodyBytes(payload) <= QODER_WIRE_BODY_LIMIT_BYTES)
|
|
14731
|
-
return payload;
|
|
14732
|
-
const kept = messages.slice();
|
|
14733
|
-
while (kept.length > 1 && estimateQoderBodyBytes({ ...payload, messages: kept }) > QODER_WIRE_BODY_LIMIT_BYTES) {
|
|
14734
|
-
const dropped = kept[0];
|
|
14735
|
-
kept.shift();
|
|
14736
|
-
if (dropped?.role === "assistant" && Array.isArray(dropped.tool_calls) && dropped.tool_calls.length > 0) {
|
|
14737
|
-
const toolCallIds = new Set(dropped.tool_calls.map((tc) => tc && typeof tc === "object" && "id" in tc ? tc.id : void 0).filter((id) => typeof id === "string"));
|
|
14738
|
-
while (kept.length > 1) {
|
|
14739
|
-
const next = kept[0];
|
|
14740
|
-
if (next?.role === "tool" && typeof next.tool_call_id === "string" && toolCallIds.has(next.tool_call_id)) {
|
|
14741
|
-
kept.shift();
|
|
14742
|
-
toolCallIds.delete(next.tool_call_id);
|
|
14743
|
-
if (toolCallIds.size === 0)
|
|
14744
|
-
break;
|
|
14745
|
-
} else {
|
|
14746
|
-
break;
|
|
14747
|
-
}
|
|
14748
|
-
}
|
|
14749
|
-
}
|
|
14750
|
-
}
|
|
14751
|
-
return { ...payload, messages: kept };
|
|
14752
|
-
}
|
|
14753
14725
|
function toWireTool(tool) {
|
|
14754
14726
|
return {
|
|
14755
14727
|
type: "function",
|
|
@@ -14778,7 +14750,7 @@ function lastUserText(messages) {
|
|
|
14778
14750
|
}
|
|
14779
14751
|
function buildRequestBody(options, sessionId) {
|
|
14780
14752
|
const requestId = randomUUID2();
|
|
14781
|
-
const spec =
|
|
14753
|
+
const spec = resolveQoderModelSpec(options.model);
|
|
14782
14754
|
const text = lastUserText(options.messages);
|
|
14783
14755
|
const maxTokens = spec?.maxTokens ?? QODER_DEFAULT_MAX_TOKENS;
|
|
14784
14756
|
const payload = {
|
|
@@ -14893,6 +14865,9 @@ function unwrapWireChunk(chunk) {
|
|
|
14893
14865
|
} catch {
|
|
14894
14866
|
}
|
|
14895
14867
|
const status = typeof record.statusCode === "string" ? record.statusCode : String(record.statusCodeValue);
|
|
14868
|
+
if (status === "PAYLOAD_TOO_LARGE") {
|
|
14869
|
+
throw new QoderApiError(`Qoder prompt is too long for this model's context window (${status}${detail ? `: ${detail}` : ""})`);
|
|
14870
|
+
}
|
|
14896
14871
|
throw new QoderApiError(`Qoder model server rejected the request (${status}${detail ? `: ${detail}` : ""})`);
|
|
14897
14872
|
}
|
|
14898
14873
|
try {
|
|
@@ -14979,12 +14954,7 @@ async function* streamQoderResponse(options) {
|
|
|
14979
14954
|
if (payload.messages.length === 0)
|
|
14980
14955
|
throw new QoderApiError("Qoder prompt is empty");
|
|
14981
14956
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
14982
|
-
const
|
|
14983
|
-
const body = JSON.stringify(fittedPayload);
|
|
14984
|
-
const bodyBytes = Buffer.byteLength(body);
|
|
14985
|
-
if (bodyBytes > QODER_WIRE_BODY_LIMIT_BYTES) {
|
|
14986
|
-
throw new QoderApiError(`Qoder prompt is too long for this model's context window (${bodyBytes} bytes > ${QODER_WIRE_BODY_LIMIT_BYTES} bytes)`);
|
|
14987
|
-
}
|
|
14957
|
+
const body = JSON.stringify(payload);
|
|
14988
14958
|
const origin = qoderWireUrl(process.env.QODER_MODEL_SERVER_HOST, options.endpoint);
|
|
14989
14959
|
const identity = readQoderSigningIdentity(qoderConfigDir()) ?? ANONYMOUS_SIGNING_IDENTITY;
|
|
14990
14960
|
const signed = signQoderInferRequest(origin, body, options.model, "system", identity, QODER_WIRE_VERSION);
|
|
@@ -15027,7 +14997,7 @@ async function* streamQoderResponse(options) {
|
|
|
15027
14997
|
}
|
|
15028
14998
|
}
|
|
15029
14999
|
function streamQoder(options) {
|
|
15030
|
-
const contextWindow =
|
|
15000
|
+
const contextWindow = resolveQoderModelSpec(options.model)?.contextWindow ?? QODER_DEFAULT_CONTEXT_WINDOW;
|
|
15031
15001
|
return recordUsage(streamQoderResponse(options), {
|
|
15032
15002
|
vendor: "qoder",
|
|
15033
15003
|
model: options.model,
|
|
@@ -15037,6 +15007,110 @@ function streamQoder(options) {
|
|
|
15037
15007
|
});
|
|
15038
15008
|
}
|
|
15039
15009
|
|
|
15010
|
+
// ../qoder-core/dist/models-api.js
|
|
15011
|
+
var QODER_MODEL_LIST_PATH = "/algo/api/v2/model/list?Encode=1";
|
|
15012
|
+
function newestCatalogDirectory(root) {
|
|
15013
|
+
try {
|
|
15014
|
+
const dirs = readdirSync3(root, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => join18(root, entry.name)).flatMap((dir) => {
|
|
15015
|
+
try {
|
|
15016
|
+
return [{ dir, mtime: statSync3(dir).mtimeMs }];
|
|
15017
|
+
} catch {
|
|
15018
|
+
return [];
|
|
15019
|
+
}
|
|
15020
|
+
});
|
|
15021
|
+
dirs.sort((a, b) => b.mtime - a.mtime);
|
|
15022
|
+
for (const { dir } of dirs) {
|
|
15023
|
+
const file = newestCatalog(dir);
|
|
15024
|
+
if (file)
|
|
15025
|
+
return { dir, file };
|
|
15026
|
+
}
|
|
15027
|
+
return void 0;
|
|
15028
|
+
} catch {
|
|
15029
|
+
return void 0;
|
|
15030
|
+
}
|
|
15031
|
+
}
|
|
15032
|
+
function newestCatalog(dir) {
|
|
15033
|
+
try {
|
|
15034
|
+
const files = readdirSync3(dir).flatMap((name) => {
|
|
15035
|
+
const match = /^catalog-v(\d+)$/.exec(name);
|
|
15036
|
+
return match ? [{ file: join18(dir, name), version: Number(match[1]) }] : [];
|
|
15037
|
+
}).sort((a, b) => b.version - a.version);
|
|
15038
|
+
return files[0]?.file;
|
|
15039
|
+
} catch {
|
|
15040
|
+
return void 0;
|
|
15041
|
+
}
|
|
15042
|
+
}
|
|
15043
|
+
function qoderVendorCatalogFile(configDir) {
|
|
15044
|
+
const root = join18(configDir, ".models");
|
|
15045
|
+
let uid;
|
|
15046
|
+
let scene;
|
|
15047
|
+
try {
|
|
15048
|
+
const pointer = JSON.parse(readFileSync12(join18(root, "default"), "utf8"));
|
|
15049
|
+
if (typeof pointer.uid === "string" && pointer.uid)
|
|
15050
|
+
uid = pointer.uid;
|
|
15051
|
+
if (typeof pointer.scene === "string" && pointer.scene)
|
|
15052
|
+
scene = pointer.scene;
|
|
15053
|
+
} catch {
|
|
15054
|
+
}
|
|
15055
|
+
let dir = uid ? join18(root, uid) : void 0;
|
|
15056
|
+
let file = dir ? newestCatalog(dir) : void 0;
|
|
15057
|
+
if (!file) {
|
|
15058
|
+
const found = newestCatalogDirectory(root);
|
|
15059
|
+
dir = found?.dir;
|
|
15060
|
+
file = found?.file;
|
|
15061
|
+
}
|
|
15062
|
+
if (!dir || !file)
|
|
15063
|
+
return void 0;
|
|
15064
|
+
return { file, uid: dir.slice(root.length + 1), ...scene ? { scene } : {} };
|
|
15065
|
+
}
|
|
15066
|
+
var MODEL_LIST_TIMEOUT_MS = 1e4;
|
|
15067
|
+
async function fetchServerModels(signal) {
|
|
15068
|
+
const identity = readQoderSigningIdentity(qoderConfigDir());
|
|
15069
|
+
if (!identity)
|
|
15070
|
+
throw new QoderAuthError();
|
|
15071
|
+
const signed = signQoderRequest(qoderWireUrl(process.env.QODER_MODEL_SERVER_HOST), QODER_MODEL_LIST_PATH, "GET", "auth", void 0, identity, QODER_WIRE_VERSION);
|
|
15072
|
+
const timeout = AbortSignal.timeout(MODEL_LIST_TIMEOUT_MS);
|
|
15073
|
+
const response = await fetch(signed.url, {
|
|
15074
|
+
method: "GET",
|
|
15075
|
+
headers: signed.headers,
|
|
15076
|
+
signal: signal ? AbortSignal.any([signal, timeout]) : timeout
|
|
15077
|
+
});
|
|
15078
|
+
const text = await response.text();
|
|
15079
|
+
if (response.status === 401 || response.status === 403) {
|
|
15080
|
+
throw new QoderAuthError(`${QODER_LOGIN_MESSAGE} (HTTP ${response.status}: ${text.slice(0, 200)})`);
|
|
15081
|
+
}
|
|
15082
|
+
if (!response.ok)
|
|
15083
|
+
throw new QoderApiError(`models.list failed: HTTP ${response.status}: ${text.slice(0, 200)}`);
|
|
15084
|
+
const infos = qoderModelInfosFromVendorCatalog(text);
|
|
15085
|
+
if (infos.length === 0)
|
|
15086
|
+
throw new QoderApiError("models.list returned no models for the assistant scene");
|
|
15087
|
+
return qoderModelsFromModelInfos(infos);
|
|
15088
|
+
}
|
|
15089
|
+
function readLocalCatalog() {
|
|
15090
|
+
const target = qoderVendorCatalogFile(qoderConfigDir());
|
|
15091
|
+
if (!target)
|
|
15092
|
+
return void 0;
|
|
15093
|
+
const plain = decryptQoderModelCache(readFileSync12(target.file, "utf8"), target.uid);
|
|
15094
|
+
return qoderModelsFromModelInfos(qoderModelInfosFromVendorCatalog(plain, target.scene));
|
|
15095
|
+
}
|
|
15096
|
+
async function fetchQoderModels(options = {}) {
|
|
15097
|
+
let error2;
|
|
15098
|
+
try {
|
|
15099
|
+
return { models: await fetchServerModels(options.signal), source: "server" };
|
|
15100
|
+
} catch (err) {
|
|
15101
|
+
if (options.signal?.aborted)
|
|
15102
|
+
throw err;
|
|
15103
|
+
error2 = err instanceof Error ? err.message : String(err);
|
|
15104
|
+
}
|
|
15105
|
+
try {
|
|
15106
|
+
const models = readLocalCatalog();
|
|
15107
|
+
if (models)
|
|
15108
|
+
return { models, source: "catalog", error: error2 };
|
|
15109
|
+
} catch {
|
|
15110
|
+
}
|
|
15111
|
+
return { models: qoderBootstrapModels(), source: "bootstrap", error: error2 };
|
|
15112
|
+
}
|
|
15113
|
+
|
|
15040
15114
|
// ../pi-provider/src/qoder/provider.ts
|
|
15041
15115
|
import {
|
|
15042
15116
|
createAssistantMessageEventStream as createAssistantMessageEventStream8
|
|
@@ -15162,7 +15236,16 @@ async function refreshQoderModels(options = {}) {
|
|
|
15162
15236
|
error: "no Qoder auth: run `qodercli login` or set QODER_PERSONAL_ACCESS_TOKEN"
|
|
15163
15237
|
};
|
|
15164
15238
|
}
|
|
15165
|
-
const
|
|
15239
|
+
const list = await fetchQoderModels();
|
|
15240
|
+
const catalog = specsToCatalog2(list.models);
|
|
15241
|
+
if (list.source !== "server") {
|
|
15242
|
+
return {
|
|
15243
|
+
models: catalogToProviderModels3(catalog),
|
|
15244
|
+
fromCache: false,
|
|
15245
|
+
source: "fallback",
|
|
15246
|
+
error: `model server unavailable (${list.error ?? "unknown error"}); showing ${list.source} list`
|
|
15247
|
+
};
|
|
15248
|
+
}
|
|
15166
15249
|
cache.store(QODER_PROVIDER_ID, catalog, { version: "qoder-cli-v1" });
|
|
15167
15250
|
return { models: catalogToProviderModels3(catalog), fromCache: false, source: "live" };
|
|
15168
15251
|
} catch (err) {
|
|
@@ -15177,9 +15260,12 @@ function createProviderConfig3(models) {
|
|
|
15177
15260
|
api: QODER_API,
|
|
15178
15261
|
models,
|
|
15179
15262
|
streamSimple: streamQoderForPi,
|
|
15263
|
+
// OMP 19.1.1 reads `.length` on this return, so null throws during discovery.
|
|
15264
|
+
// A disk snapshot, fresh or past the 15-minute TTL, is a real catalog. The
|
|
15265
|
+
// bootstrap list stays null so it is not pinned as authoritative for 24h.
|
|
15180
15266
|
fetchDynamicModels: async () => {
|
|
15181
15267
|
const latest = await refreshQoderModels({ allowNetwork: false });
|
|
15182
|
-
if (
|
|
15268
|
+
if (latest.source !== "cache" || latest.models.length === 0) return null;
|
|
15183
15269
|
return latest.models;
|
|
15184
15270
|
},
|
|
15185
15271
|
async refreshModels() {
|
|
@@ -15222,9 +15308,9 @@ async function registerQoderProvider(pi) {
|
|
|
15222
15308
|
}
|
|
15223
15309
|
|
|
15224
15310
|
// ../pi-provider/src/selection.ts
|
|
15225
|
-
import { readFileSync as
|
|
15226
|
-
import { homedir as
|
|
15227
|
-
import { join as
|
|
15311
|
+
import { readFileSync as readFileSync13 } from "node:fs";
|
|
15312
|
+
import { homedir as homedir18 } from "node:os";
|
|
15313
|
+
import { join as join19 } from "node:path";
|
|
15228
15314
|
var PROVIDER_KEYS = ["kiro", "devin", "grok", "arnict", "qoder"];
|
|
15229
15315
|
var DEFAULT_SELECTION = {
|
|
15230
15316
|
kiro: true,
|
|
@@ -15233,8 +15319,8 @@ var DEFAULT_SELECTION = {
|
|
|
15233
15319
|
arnict: true,
|
|
15234
15320
|
qoder: true
|
|
15235
15321
|
};
|
|
15236
|
-
function selectionFilePath(env = process.env, home =
|
|
15237
|
-
return env.NS_BRIDGE_PROVIDERS ??
|
|
15322
|
+
function selectionFilePath(env = process.env, home = homedir18()) {
|
|
15323
|
+
return env.NS_BRIDGE_PROVIDERS ?? join19(home, ".ns-bridge", "providers.json");
|
|
15238
15324
|
}
|
|
15239
15325
|
function resolveProviderSelection(env = process.env, file = readProviderFile(selectionFilePath(env))) {
|
|
15240
15326
|
const allow = listed(env.NS_OMP_PROVIDERS);
|
|
@@ -15250,7 +15336,7 @@ function resolveProviderSelection(env = process.env, file = readProviderFile(sel
|
|
|
15250
15336
|
function readProviderFile(path) {
|
|
15251
15337
|
let raw;
|
|
15252
15338
|
try {
|
|
15253
|
-
raw =
|
|
15339
|
+
raw = readFileSync13(path, "utf8");
|
|
15254
15340
|
} catch {
|
|
15255
15341
|
return {};
|
|
15256
15342
|
}
|