@ngosangns/ns-bridge 0.1.29 → 0.1.31
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/cli.js +32 -1
- package/dist/cli.js.map +1 -1
- 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 +45 -6
- package/dist/hosts/omp/dist/index.js +382 -72
- package/dist/hosts/omp/package.json +1 -1
- package/dist/hosts/pi/dist/index.js +194 -72
- package/dist/hosts/pi/package.json +1 -1
- package/dist/plugin.d.ts +24 -0
- package/dist/plugin.js +183 -0
- package/dist/plugin.js.map +1 -0
- package/dist/refresh-entry.js +211 -16
- 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.31 — 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;
|
|
@@ -1042,6 +1042,21 @@ async function resolveKiroProfileArn(auth, providedArn) {
|
|
|
1042
1042
|
pendingProfileRequests.delete(key);
|
|
1043
1043
|
}
|
|
1044
1044
|
}
|
|
1045
|
+
function kiroProfileAuth(auth, profileArn) {
|
|
1046
|
+
const region = isApiKey(auth.accessToken) ? API_KEY_REGION2 : getKiroRegionFromProfileArn(profileArn) ?? profileRegionCache.get(profileCacheKey(auth)) ?? auth.region;
|
|
1047
|
+
return region === auth.region ? auth : { ...auth, region };
|
|
1048
|
+
}
|
|
1049
|
+
async function getUsageLimits(auth, request) {
|
|
1050
|
+
const operation = "GetUsageLimits";
|
|
1051
|
+
const url = new URL("Get-Usage-Limits", getKiroEndpoints(auth.region).management);
|
|
1052
|
+
let response;
|
|
1053
|
+
try {
|
|
1054
|
+
response = await kiroManagementFetch(url, auth, "GET", request);
|
|
1055
|
+
} catch (error2) {
|
|
1056
|
+
throw new Error(`Kiro management ${operation} request failed in ${auth.region}`, { cause: error2 });
|
|
1057
|
+
}
|
|
1058
|
+
return parseManagementResponse(response, operation, auth.region);
|
|
1059
|
+
}
|
|
1045
1060
|
var LIST_PROFILES_PATH, API_KEY_REGION2, profileArnCache, pendingProfileRequests, profileRegionCache, CANONICAL_MANAGEMENT_REGIONS, KiroManagementHttpError;
|
|
1046
1061
|
var init_management = __esm({
|
|
1047
1062
|
"../kiro-core/dist/management.js"() {
|
|
@@ -8290,6 +8305,109 @@ ${systemPrompt}` : ""}`;
|
|
|
8290
8305
|
// ../kiro-core/dist/usage.js
|
|
8291
8306
|
init_endpoints();
|
|
8292
8307
|
init_management();
|
|
8308
|
+
var MANAGE_USAGE_URL = "https://app.kiro.dev/account/usage";
|
|
8309
|
+
function toEpochMs(value) {
|
|
8310
|
+
if (value === void 0 || value === null)
|
|
8311
|
+
return void 0;
|
|
8312
|
+
const ms = typeof value === "number" ? value * 1e3 : Date.parse(value);
|
|
8313
|
+
return Number.isNaN(ms) ? void 0 : ms;
|
|
8314
|
+
}
|
|
8315
|
+
function toIsoDate(ms) {
|
|
8316
|
+
if (ms === void 0)
|
|
8317
|
+
return void 0;
|
|
8318
|
+
return new Date(ms).toISOString();
|
|
8319
|
+
}
|
|
8320
|
+
function toUsageUnit(unit, resourceType) {
|
|
8321
|
+
const named = unit?.toLowerCase();
|
|
8322
|
+
if (resourceType?.toLowerCase() === "credit" && (named === void 0 || named === "invocations"))
|
|
8323
|
+
return "credits";
|
|
8324
|
+
switch (named) {
|
|
8325
|
+
case "credit":
|
|
8326
|
+
case "credits":
|
|
8327
|
+
return "credits";
|
|
8328
|
+
case "request":
|
|
8329
|
+
case "requests":
|
|
8330
|
+
return "requests";
|
|
8331
|
+
case "token":
|
|
8332
|
+
case "tokens":
|
|
8333
|
+
return "tokens";
|
|
8334
|
+
case "usd":
|
|
8335
|
+
return "usd";
|
|
8336
|
+
default:
|
|
8337
|
+
return "unknown";
|
|
8338
|
+
}
|
|
8339
|
+
}
|
|
8340
|
+
function formatCount(value) {
|
|
8341
|
+
if (value === void 0 || Number.isNaN(value))
|
|
8342
|
+
return void 0;
|
|
8343
|
+
return Number.isInteger(value) ? String(value) : value.toFixed(2);
|
|
8344
|
+
}
|
|
8345
|
+
function formatMoney(amount, currency) {
|
|
8346
|
+
if (amount === void 0 || Number.isNaN(amount) || amount <= 0)
|
|
8347
|
+
return void 0;
|
|
8348
|
+
const code = currency || "USD";
|
|
8349
|
+
try {
|
|
8350
|
+
return new Intl.NumberFormat("en-US", { style: "currency", currency: code }).format(amount);
|
|
8351
|
+
} catch {
|
|
8352
|
+
return `${amount.toFixed(2)} ${code}`;
|
|
8353
|
+
}
|
|
8354
|
+
}
|
|
8355
|
+
function mapBucket(bucket, index) {
|
|
8356
|
+
const used = bucket.currentUsageWithPrecision ?? bucket.currentUsage;
|
|
8357
|
+
const limit = bucket.usageLimitWithPrecision ?? bucket.usageLimit;
|
|
8358
|
+
const overages = bucket.currentOveragesWithPrecision ?? bucket.currentOverages;
|
|
8359
|
+
const freeTrialUsed = bucket.freeTrialInfo?.currentUsageWithPrecision ?? bucket.freeTrialInfo?.currentUsage;
|
|
8360
|
+
const freeTrialLimit = bucket.freeTrialInfo?.usageLimitWithPrecision ?? bucket.freeTrialInfo?.usageLimit;
|
|
8361
|
+
const resetAtMs = toEpochMs(bucket.nextDateReset);
|
|
8362
|
+
return {
|
|
8363
|
+
id: bucket.resourceType || bucket.displayName || `usage-${index}`,
|
|
8364
|
+
label: bucket.displayName || bucket.displayNamePlural || bucket.resourceType || "Usage",
|
|
8365
|
+
resourceType: bucket.resourceType,
|
|
8366
|
+
used: used ?? 0,
|
|
8367
|
+
limit,
|
|
8368
|
+
overages: overages && overages > 0 ? overages : void 0,
|
|
8369
|
+
usedDisplay: formatCount(used) || "0",
|
|
8370
|
+
limitDisplay: formatCount(limit),
|
|
8371
|
+
unit: bucket.unit,
|
|
8372
|
+
unitKind: toUsageUnit(bucket.unit, bucket.resourceType),
|
|
8373
|
+
overagesDisplay: overages && overages > 0 ? formatCount(overages) : void 0,
|
|
8374
|
+
overageChargesDisplay: formatMoney(bucket.overageCharges, bucket.currency),
|
|
8375
|
+
resetAt: toIsoDate(resetAtMs),
|
|
8376
|
+
resetAtMs,
|
|
8377
|
+
bonus: freeTrialUsed !== void 0 || freeTrialLimit !== void 0 || bucket.freeTrialInfo?.freeTrialExpiry !== void 0 ? {
|
|
8378
|
+
label: "Bonus credits",
|
|
8379
|
+
usedDisplay: formatCount(freeTrialUsed),
|
|
8380
|
+
limitDisplay: formatCount(freeTrialLimit),
|
|
8381
|
+
expiresAt: toIsoDate(toEpochMs(bucket.freeTrialInfo?.freeTrialExpiry))
|
|
8382
|
+
} : void 0
|
|
8383
|
+
};
|
|
8384
|
+
}
|
|
8385
|
+
async function fetchRawUsage(auth, profileArn) {
|
|
8386
|
+
const resolvedProfileArn = await resolveKiroProfileArn(auth, profileArn);
|
|
8387
|
+
return getUsageLimits(kiroProfileAuth(auth, resolvedProfileArn), {
|
|
8388
|
+
profileArn: resolvedProfileArn,
|
|
8389
|
+
origin: "KIRO_CLI",
|
|
8390
|
+
resourceType: "CREDIT",
|
|
8391
|
+
isEmailRequired: false
|
|
8392
|
+
});
|
|
8393
|
+
}
|
|
8394
|
+
async function fetchKiroUsage(credentials) {
|
|
8395
|
+
const auth = { accessToken: credentials.access, region: resolveApiRegion(credentials.region) };
|
|
8396
|
+
const raw = await fetchRawUsage(auth, credentials.profileArn);
|
|
8397
|
+
const usageBuckets = raw.usageBreakdownList?.length ? raw.usageBreakdownList.map(mapBucket) : raw.usageBreakdown ? [mapBucket(raw.usageBreakdown, 0)] : [];
|
|
8398
|
+
const resetAtMs = toEpochMs(raw.nextDateReset);
|
|
8399
|
+
return {
|
|
8400
|
+
summary: raw.subscriptionInfo?.subscriptionTitle,
|
|
8401
|
+
subscriptionTitle: raw.subscriptionInfo?.subscriptionTitle,
|
|
8402
|
+
resetAt: toIsoDate(resetAtMs),
|
|
8403
|
+
resetAtMs,
|
|
8404
|
+
daysUntilReset: raw.daysUntilReset,
|
|
8405
|
+
overageStatus: raw.overageConfiguration?.overageStatus,
|
|
8406
|
+
manageUrl: MANAGE_USAGE_URL,
|
|
8407
|
+
usageBuckets,
|
|
8408
|
+
raw
|
|
8409
|
+
};
|
|
8410
|
+
}
|
|
8293
8411
|
|
|
8294
8412
|
// ../pi-provider/src/kiro/register.ts
|
|
8295
8413
|
var KIRO_PROVIDER_ID = "kiro";
|
|
@@ -8564,6 +8682,7 @@ function loadExports() {
|
|
|
8564
8682
|
"model_cache_decrypt",
|
|
8565
8683
|
"qodercontext_new",
|
|
8566
8684
|
"qodercontext_prepareInferRequest",
|
|
8685
|
+
"qodercontext_prepareRequest",
|
|
8567
8686
|
"requestresult_url",
|
|
8568
8687
|
"requestresult_body",
|
|
8569
8688
|
"requestresult_headers",
|
|
@@ -8713,6 +8832,41 @@ function signQoderInferRequest(endpoint, bodyJson, modelKey, modelSource, identi
|
|
|
8713
8832
|
exports.__wbg_qodercontext_free(ctx, 0);
|
|
8714
8833
|
}
|
|
8715
8834
|
}
|
|
8835
|
+
function callPrepareRequest(exports, ctx, endpoint, path, method, authType, body) {
|
|
8836
|
+
const retptr = exports.__wbindgen_add_to_stack_pointer(-16);
|
|
8837
|
+
try {
|
|
8838
|
+
const [endpointPtr, endpointLen] = passStringToWasm(exports, endpoint);
|
|
8839
|
+
const [pathPtr, pathLen] = passStringToWasm(exports, path);
|
|
8840
|
+
const [methodPtr, methodLen] = passStringToWasm(exports, method);
|
|
8841
|
+
const [authPtr, authLen] = passStringToWasm(exports, authType);
|
|
8842
|
+
const [bodyPtr, bodyLen] = body === void 0 ? [0, 0] : passStringToWasm(exports, body);
|
|
8843
|
+
exports.qodercontext_prepareRequest(retptr, ctx, endpointPtr, endpointLen, pathPtr, pathLen, methodPtr, methodLen, authPtr, authLen, bodyPtr, bodyLen, 0, 0);
|
|
8844
|
+
const view = new Int32Array(exports.memory.buffer, retptr, 4);
|
|
8845
|
+
if ((view[2] ?? 0) !== 0)
|
|
8846
|
+
throw takeObject(view[1] ?? 0);
|
|
8847
|
+
return (view[0] ?? 0) >>> 0;
|
|
8848
|
+
} finally {
|
|
8849
|
+
exports.__wbindgen_add_to_stack_pointer(16);
|
|
8850
|
+
}
|
|
8851
|
+
}
|
|
8852
|
+
function signQoderRequest(endpoint, path, method, authType, body, identity, cosyVersion) {
|
|
8853
|
+
const exports = loadExports();
|
|
8854
|
+
const ctx = callContextNew(exports, identity, cosyVersion);
|
|
8855
|
+
try {
|
|
8856
|
+
const result = callPrepareRequest(exports, ctx, endpoint, path, method, authType, body);
|
|
8857
|
+
try {
|
|
8858
|
+
const url = wasmResultString(exports, exports.requestresult_url, result);
|
|
8859
|
+
if (!url)
|
|
8860
|
+
throw new Error("qoder request signer returned an empty url");
|
|
8861
|
+
const signedBody = wasmResultString(exports, exports.requestresult_body, result);
|
|
8862
|
+
return { url, headers: signatureHeaders(exports, result), body: signedBody ?? "" };
|
|
8863
|
+
} finally {
|
|
8864
|
+
exports.__wbg_requestresult_free(result, 0);
|
|
8865
|
+
}
|
|
8866
|
+
} finally {
|
|
8867
|
+
exports.__wbg_qodercontext_free(ctx, 0);
|
|
8868
|
+
}
|
|
8869
|
+
}
|
|
8716
8870
|
function storedString(record, field) {
|
|
8717
8871
|
const value = record[field];
|
|
8718
8872
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
@@ -8945,71 +9099,9 @@ function qoderModelInfosFromVendorCatalog(raw, scene) {
|
|
|
8945
9099
|
// ../qoder-core/dist/models-api.js
|
|
8946
9100
|
import { readdirSync as readdirSync3, readFileSync as readFileSync7, statSync as statSync2 } from "node:fs";
|
|
8947
9101
|
import { join as join11 } from "node:path";
|
|
8948
|
-
|
|
8949
|
-
|
|
8950
|
-
|
|
8951
|
-
try {
|
|
8952
|
-
return [{ dir, mtime: statSync2(dir).mtimeMs }];
|
|
8953
|
-
} catch {
|
|
8954
|
-
return [];
|
|
8955
|
-
}
|
|
8956
|
-
});
|
|
8957
|
-
dirs.sort((a, b) => b.mtime - a.mtime);
|
|
8958
|
-
for (const { dir } of dirs) {
|
|
8959
|
-
const file = newestCatalog(dir);
|
|
8960
|
-
if (file)
|
|
8961
|
-
return { dir, file };
|
|
8962
|
-
}
|
|
8963
|
-
return void 0;
|
|
8964
|
-
} catch {
|
|
8965
|
-
return void 0;
|
|
8966
|
-
}
|
|
8967
|
-
}
|
|
8968
|
-
function newestCatalog(dir) {
|
|
8969
|
-
try {
|
|
8970
|
-
const files = readdirSync3(dir).flatMap((name) => {
|
|
8971
|
-
const match = /^catalog-v(\d+)$/.exec(name);
|
|
8972
|
-
return match ? [{ file: join11(dir, name), version: Number(match[1]) }] : [];
|
|
8973
|
-
}).sort((a, b) => b.version - a.version);
|
|
8974
|
-
return files[0]?.file;
|
|
8975
|
-
} catch {
|
|
8976
|
-
return void 0;
|
|
8977
|
-
}
|
|
8978
|
-
}
|
|
8979
|
-
function qoderVendorCatalogFile(configDir) {
|
|
8980
|
-
const root = join11(configDir, ".models");
|
|
8981
|
-
let uid;
|
|
8982
|
-
let scene;
|
|
8983
|
-
try {
|
|
8984
|
-
const pointer = JSON.parse(readFileSync7(join11(root, "default"), "utf8"));
|
|
8985
|
-
if (typeof pointer.uid === "string" && pointer.uid)
|
|
8986
|
-
uid = pointer.uid;
|
|
8987
|
-
if (typeof pointer.scene === "string" && pointer.scene)
|
|
8988
|
-
scene = pointer.scene;
|
|
8989
|
-
} catch {
|
|
8990
|
-
}
|
|
8991
|
-
let dir = uid ? join11(root, uid) : void 0;
|
|
8992
|
-
let file = dir ? newestCatalog(dir) : void 0;
|
|
8993
|
-
if (!file) {
|
|
8994
|
-
const found = newestCatalogDirectory(root);
|
|
8995
|
-
dir = found?.dir;
|
|
8996
|
-
file = found?.file;
|
|
8997
|
-
}
|
|
8998
|
-
if (!dir || !file)
|
|
8999
|
-
return void 0;
|
|
9000
|
-
return { file, uid: dir.slice(root.length + 1), ...scene ? { scene } : {} };
|
|
9001
|
-
}
|
|
9002
|
-
async function fetchQoderModels(_options = {}) {
|
|
9003
|
-
try {
|
|
9004
|
-
const target = qoderVendorCatalogFile(qoderConfigDir());
|
|
9005
|
-
if (!target)
|
|
9006
|
-
return qoderBootstrapModels();
|
|
9007
|
-
const plain = decryptQoderModelCache(readFileSync7(target.file, "utf8"), target.uid);
|
|
9008
|
-
return qoderModelsFromModelInfos(qoderModelInfosFromVendorCatalog(plain, target.scene));
|
|
9009
|
-
} catch {
|
|
9010
|
-
return qoderBootstrapModels();
|
|
9011
|
-
}
|
|
9012
|
-
}
|
|
9102
|
+
|
|
9103
|
+
// ../qoder-core/dist/stream.js
|
|
9104
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
9013
9105
|
|
|
9014
9106
|
// ../qoder-core/dist/prompt.js
|
|
9015
9107
|
function imageDataUrl(data, mimeType) {
|
|
@@ -9082,15 +9174,16 @@ function nonNegative2(value) {
|
|
|
9082
9174
|
return value;
|
|
9083
9175
|
}
|
|
9084
9176
|
function toQoderUsage(wire) {
|
|
9085
|
-
const
|
|
9177
|
+
const prompt = nonNegative2(wire.prompt_tokens);
|
|
9086
9178
|
const output = nonNegative2(wire.completion_tokens);
|
|
9087
9179
|
const hit = nonNegative2(wire.prompt_cache_hit_tokens);
|
|
9088
9180
|
const cached2 = nonNegative2(wire.prompt_tokens_details?.cached_tokens);
|
|
9089
|
-
const cacheRead = hit > 0 ? hit : cached2;
|
|
9181
|
+
const cacheRead = Math.min(hit > 0 ? hit : cached2, prompt);
|
|
9182
|
+
const input = prompt - cacheRead;
|
|
9090
9183
|
return {
|
|
9091
9184
|
input,
|
|
9092
9185
|
output,
|
|
9093
|
-
totalTokens: input + output,
|
|
9186
|
+
totalTokens: input + cacheRead + output,
|
|
9094
9187
|
...cacheRead > 0 ? { cacheRead } : {},
|
|
9095
9188
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
|
|
9096
9189
|
};
|
|
@@ -9292,7 +9385,6 @@ function qoderSessionId(raw) {
|
|
|
9292
9385
|
}
|
|
9293
9386
|
|
|
9294
9387
|
// ../qoder-core/dist/stream.js
|
|
9295
|
-
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
9296
9388
|
var QODER_WIRE_VERSION = "1.1.83";
|
|
9297
9389
|
var QODER_INFER_ORIGIN = "https://api2.qoder.sh";
|
|
9298
9390
|
var ANONYMOUS_SIGNING_IDENTITY = {
|
|
@@ -9334,6 +9426,40 @@ function machineOs() {
|
|
|
9334
9426
|
const arch = process.arch === "arm64" ? "aarch64" : process.arch;
|
|
9335
9427
|
return `${arch}_${process.platform}`;
|
|
9336
9428
|
}
|
|
9429
|
+
function estimateQoderBodyBytes(payload) {
|
|
9430
|
+
try {
|
|
9431
|
+
return Buffer.byteLength(JSON.stringify(payload));
|
|
9432
|
+
} catch {
|
|
9433
|
+
return Number.MAX_SAFE_INTEGER;
|
|
9434
|
+
}
|
|
9435
|
+
}
|
|
9436
|
+
function fitQoderBody(payload) {
|
|
9437
|
+
const messages = payload.messages;
|
|
9438
|
+
if (!Array.isArray(messages) || messages.length <= 1)
|
|
9439
|
+
return payload;
|
|
9440
|
+
if (estimateQoderBodyBytes(payload) <= QODER_WIRE_BODY_LIMIT_BYTES)
|
|
9441
|
+
return payload;
|
|
9442
|
+
const kept = messages.slice();
|
|
9443
|
+
while (kept.length > 1 && estimateQoderBodyBytes({ ...payload, messages: kept }) > QODER_WIRE_BODY_LIMIT_BYTES) {
|
|
9444
|
+
const dropped = kept[0];
|
|
9445
|
+
kept.shift();
|
|
9446
|
+
if (dropped?.role === "assistant" && Array.isArray(dropped.tool_calls) && dropped.tool_calls.length > 0) {
|
|
9447
|
+
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"));
|
|
9448
|
+
while (kept.length > 1) {
|
|
9449
|
+
const next = kept[0];
|
|
9450
|
+
if (next?.role === "tool" && typeof next.tool_call_id === "string" && toolCallIds.has(next.tool_call_id)) {
|
|
9451
|
+
kept.shift();
|
|
9452
|
+
toolCallIds.delete(next.tool_call_id);
|
|
9453
|
+
if (toolCallIds.size === 0)
|
|
9454
|
+
break;
|
|
9455
|
+
} else {
|
|
9456
|
+
break;
|
|
9457
|
+
}
|
|
9458
|
+
}
|
|
9459
|
+
}
|
|
9460
|
+
}
|
|
9461
|
+
return { ...payload, messages: kept };
|
|
9462
|
+
}
|
|
9337
9463
|
function toWireTool(tool) {
|
|
9338
9464
|
return {
|
|
9339
9465
|
type: "function",
|
|
@@ -9563,7 +9689,8 @@ async function* streamQoderResponse(options) {
|
|
|
9563
9689
|
if (payload.messages.length === 0)
|
|
9564
9690
|
throw new QoderApiError("Qoder prompt is empty");
|
|
9565
9691
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
9566
|
-
const
|
|
9692
|
+
const fittedPayload = fitQoderBody(payload);
|
|
9693
|
+
const body = JSON.stringify(fittedPayload);
|
|
9567
9694
|
const bodyBytes = Buffer.byteLength(body);
|
|
9568
9695
|
if (bodyBytes > QODER_WIRE_BODY_LIMIT_BYTES) {
|
|
9569
9696
|
throw new QoderApiError(`Qoder prompt is too long for this model's context window (${bodyBytes} bytes > ${QODER_WIRE_BODY_LIMIT_BYTES} bytes)`);
|
|
@@ -9620,6 +9747,110 @@ function streamQoder(options) {
|
|
|
9620
9747
|
});
|
|
9621
9748
|
}
|
|
9622
9749
|
|
|
9750
|
+
// ../qoder-core/dist/models-api.js
|
|
9751
|
+
var QODER_MODEL_LIST_PATH = "/algo/api/v2/model/list?Encode=1";
|
|
9752
|
+
function newestCatalogDirectory(root) {
|
|
9753
|
+
try {
|
|
9754
|
+
const dirs = readdirSync3(root, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => join11(root, entry.name)).flatMap((dir) => {
|
|
9755
|
+
try {
|
|
9756
|
+
return [{ dir, mtime: statSync2(dir).mtimeMs }];
|
|
9757
|
+
} catch {
|
|
9758
|
+
return [];
|
|
9759
|
+
}
|
|
9760
|
+
});
|
|
9761
|
+
dirs.sort((a, b) => b.mtime - a.mtime);
|
|
9762
|
+
for (const { dir } of dirs) {
|
|
9763
|
+
const file = newestCatalog(dir);
|
|
9764
|
+
if (file)
|
|
9765
|
+
return { dir, file };
|
|
9766
|
+
}
|
|
9767
|
+
return void 0;
|
|
9768
|
+
} catch {
|
|
9769
|
+
return void 0;
|
|
9770
|
+
}
|
|
9771
|
+
}
|
|
9772
|
+
function newestCatalog(dir) {
|
|
9773
|
+
try {
|
|
9774
|
+
const files = readdirSync3(dir).flatMap((name) => {
|
|
9775
|
+
const match = /^catalog-v(\d+)$/.exec(name);
|
|
9776
|
+
return match ? [{ file: join11(dir, name), version: Number(match[1]) }] : [];
|
|
9777
|
+
}).sort((a, b) => b.version - a.version);
|
|
9778
|
+
return files[0]?.file;
|
|
9779
|
+
} catch {
|
|
9780
|
+
return void 0;
|
|
9781
|
+
}
|
|
9782
|
+
}
|
|
9783
|
+
function qoderVendorCatalogFile(configDir) {
|
|
9784
|
+
const root = join11(configDir, ".models");
|
|
9785
|
+
let uid;
|
|
9786
|
+
let scene;
|
|
9787
|
+
try {
|
|
9788
|
+
const pointer = JSON.parse(readFileSync7(join11(root, "default"), "utf8"));
|
|
9789
|
+
if (typeof pointer.uid === "string" && pointer.uid)
|
|
9790
|
+
uid = pointer.uid;
|
|
9791
|
+
if (typeof pointer.scene === "string" && pointer.scene)
|
|
9792
|
+
scene = pointer.scene;
|
|
9793
|
+
} catch {
|
|
9794
|
+
}
|
|
9795
|
+
let dir = uid ? join11(root, uid) : void 0;
|
|
9796
|
+
let file = dir ? newestCatalog(dir) : void 0;
|
|
9797
|
+
if (!file) {
|
|
9798
|
+
const found = newestCatalogDirectory(root);
|
|
9799
|
+
dir = found?.dir;
|
|
9800
|
+
file = found?.file;
|
|
9801
|
+
}
|
|
9802
|
+
if (!dir || !file)
|
|
9803
|
+
return void 0;
|
|
9804
|
+
return { file, uid: dir.slice(root.length + 1), ...scene ? { scene } : {} };
|
|
9805
|
+
}
|
|
9806
|
+
var MODEL_LIST_TIMEOUT_MS = 1e4;
|
|
9807
|
+
async function fetchServerModels(signal) {
|
|
9808
|
+
const identity = readQoderSigningIdentity(qoderConfigDir());
|
|
9809
|
+
if (!identity)
|
|
9810
|
+
throw new QoderAuthError();
|
|
9811
|
+
const signed = signQoderRequest(qoderWireUrl(process.env.QODER_MODEL_SERVER_HOST), QODER_MODEL_LIST_PATH, "GET", "auth", void 0, identity, QODER_WIRE_VERSION);
|
|
9812
|
+
const timeout = AbortSignal.timeout(MODEL_LIST_TIMEOUT_MS);
|
|
9813
|
+
const response = await fetch(signed.url, {
|
|
9814
|
+
method: "GET",
|
|
9815
|
+
headers: signed.headers,
|
|
9816
|
+
signal: signal ? AbortSignal.any([signal, timeout]) : timeout
|
|
9817
|
+
});
|
|
9818
|
+
const text = await response.text();
|
|
9819
|
+
if (response.status === 401 || response.status === 403) {
|
|
9820
|
+
throw new QoderAuthError(`${QODER_LOGIN_MESSAGE} (HTTP ${response.status}: ${text.slice(0, 200)})`);
|
|
9821
|
+
}
|
|
9822
|
+
if (!response.ok)
|
|
9823
|
+
throw new QoderApiError(`models.list failed: HTTP ${response.status}: ${text.slice(0, 200)}`);
|
|
9824
|
+
const infos = qoderModelInfosFromVendorCatalog(text);
|
|
9825
|
+
if (infos.length === 0)
|
|
9826
|
+
throw new QoderApiError("models.list returned no models for the assistant scene");
|
|
9827
|
+
return qoderModelsFromModelInfos(infos);
|
|
9828
|
+
}
|
|
9829
|
+
function readLocalCatalog() {
|
|
9830
|
+
const target = qoderVendorCatalogFile(qoderConfigDir());
|
|
9831
|
+
if (!target)
|
|
9832
|
+
return void 0;
|
|
9833
|
+
const plain = decryptQoderModelCache(readFileSync7(target.file, "utf8"), target.uid);
|
|
9834
|
+
return qoderModelsFromModelInfos(qoderModelInfosFromVendorCatalog(plain, target.scene));
|
|
9835
|
+
}
|
|
9836
|
+
async function fetchQoderModels(options = {}) {
|
|
9837
|
+
let error2;
|
|
9838
|
+
try {
|
|
9839
|
+
return { models: await fetchServerModels(options.signal), source: "server" };
|
|
9840
|
+
} catch (err) {
|
|
9841
|
+
if (options.signal?.aborted)
|
|
9842
|
+
throw err;
|
|
9843
|
+
error2 = err instanceof Error ? err.message : String(err);
|
|
9844
|
+
}
|
|
9845
|
+
try {
|
|
9846
|
+
const models = readLocalCatalog();
|
|
9847
|
+
if (models)
|
|
9848
|
+
return { models, source: "catalog", error: error2 };
|
|
9849
|
+
} catch {
|
|
9850
|
+
}
|
|
9851
|
+
return { models: qoderBootstrapModels(), source: "bootstrap", error: error2 };
|
|
9852
|
+
}
|
|
9853
|
+
|
|
9623
9854
|
// ../pi-provider/src/qoder/api-mode.ts
|
|
9624
9855
|
function streamViaQoder(model, context, options) {
|
|
9625
9856
|
return streamToPi({
|
|
@@ -9737,7 +9968,16 @@ async function refreshQoderModels(options = {}) {
|
|
|
9737
9968
|
error: "no Qoder auth: run `qodercli login` or set QODER_PERSONAL_ACCESS_TOKEN"
|
|
9738
9969
|
};
|
|
9739
9970
|
}
|
|
9740
|
-
const
|
|
9971
|
+
const list = await fetchQoderModels();
|
|
9972
|
+
const catalog = specsToCatalog2(list.models);
|
|
9973
|
+
if (list.source !== "server") {
|
|
9974
|
+
return {
|
|
9975
|
+
models: catalogToProviderModels2(catalog),
|
|
9976
|
+
fromCache: false,
|
|
9977
|
+
source: "fallback",
|
|
9978
|
+
error: `model server unavailable (${list.error ?? "unknown error"}); showing ${list.source} list`
|
|
9979
|
+
};
|
|
9980
|
+
}
|
|
9741
9981
|
cache.store(QODER_PROVIDER_ID, catalog, { version: "qoder-cli-v1" });
|
|
9742
9982
|
return { models: catalogToProviderModels2(catalog), fromCache: false, source: "live" };
|
|
9743
9983
|
} catch (err) {
|
|
@@ -9796,6 +10036,73 @@ async function registerQoderProvider(pi) {
|
|
|
9796
10036
|
publish(models);
|
|
9797
10037
|
}
|
|
9798
10038
|
|
|
10039
|
+
// ../omp-provider/src/kiro-usage.ts
|
|
10040
|
+
function toUsageUnit2(bucket) {
|
|
10041
|
+
return bucket.unitKind ?? "unknown";
|
|
10042
|
+
}
|
|
10043
|
+
function toLimit(provider, bucket, usage) {
|
|
10044
|
+
const resetsAt = bucket.resetAtMs ?? usage.resetAtMs;
|
|
10045
|
+
const exhausted = bucket.limit !== void 0 && bucket.used >= bucket.limit;
|
|
10046
|
+
const notes = [];
|
|
10047
|
+
if (bucket.overagesDisplay) notes.push(`Overage: ${bucket.overagesDisplay}`);
|
|
10048
|
+
if (bucket.overageChargesDisplay) notes.push(`Overage charges: ${bucket.overageChargesDisplay}`);
|
|
10049
|
+
if (bucket.bonus?.limitDisplay) {
|
|
10050
|
+
notes.push(`${bucket.bonus.label}: ${bucket.bonus.usedDisplay ?? "0"} / ${bucket.bonus.limitDisplay}`);
|
|
10051
|
+
}
|
|
10052
|
+
return {
|
|
10053
|
+
id: bucket.id,
|
|
10054
|
+
label: bucket.label,
|
|
10055
|
+
scope: { provider, ...bucket.resourceType ? { tier: bucket.resourceType } : {} },
|
|
10056
|
+
...resetsAt !== void 0 ? { window: { id: "billing-period", label: "Billing period", resetsAt } } : {},
|
|
10057
|
+
amount: {
|
|
10058
|
+
used: bucket.used,
|
|
10059
|
+
...bucket.limit !== void 0 ? { limit: bucket.limit } : {},
|
|
10060
|
+
unit: toUsageUnit2(bucket)
|
|
10061
|
+
},
|
|
10062
|
+
// Kiro exposes no warning threshold of its own. Inventing one would put a
|
|
10063
|
+
// warning in front of the user that the service never raised.
|
|
10064
|
+
status: exhausted ? "exhausted" : "ok",
|
|
10065
|
+
...notes.length > 0 ? { notes } : {}
|
|
10066
|
+
};
|
|
10067
|
+
}
|
|
10068
|
+
function toUsageReport(provider, usage, fetchedAt = Date.now()) {
|
|
10069
|
+
return {
|
|
10070
|
+
provider,
|
|
10071
|
+
fetchedAt,
|
|
10072
|
+
limits: (usage.usageBuckets ?? []).map((bucket) => toLimit(provider, bucket, usage)),
|
|
10073
|
+
...usage.subscriptionTitle ? { notes: [usage.subscriptionTitle] } : {},
|
|
10074
|
+
metadata: {
|
|
10075
|
+
...usage.manageUrl ? { manageUrl: usage.manageUrl } : {},
|
|
10076
|
+
...usage.overageStatus ? { overageStatus: usage.overageStatus } : {},
|
|
10077
|
+
...usage.daysUntilReset !== void 0 ? { daysUntilReset: usage.daysUntilReset } : {}
|
|
10078
|
+
},
|
|
10079
|
+
raw: usage.raw
|
|
10080
|
+
};
|
|
10081
|
+
}
|
|
10082
|
+
function credentialsFor(params) {
|
|
10083
|
+
const token = params.credential.accessToken ?? params.credential.apiKey;
|
|
10084
|
+
if (!token) return void 0;
|
|
10085
|
+
return {
|
|
10086
|
+
access: token,
|
|
10087
|
+
refresh: "",
|
|
10088
|
+
expires: params.credential.expiresAt ?? 0,
|
|
10089
|
+
clientId: "",
|
|
10090
|
+
clientSecret: "",
|
|
10091
|
+
region: "us-east-1",
|
|
10092
|
+
authMethod: params.credential.type === "api_key" ? "apikey" : "idc"
|
|
10093
|
+
};
|
|
10094
|
+
}
|
|
10095
|
+
var kiroUsageProvider = {
|
|
10096
|
+
id: "kiro",
|
|
10097
|
+
async fetchUsage(params, _ctx) {
|
|
10098
|
+
const credentials = credentialsFor(params);
|
|
10099
|
+
if (!credentials) return null;
|
|
10100
|
+
const usage = await fetchKiroUsage(credentials);
|
|
10101
|
+
return toUsageReport(params.provider, usage);
|
|
10102
|
+
},
|
|
10103
|
+
validatesCredentials: true
|
|
10104
|
+
};
|
|
10105
|
+
|
|
9799
10106
|
// ../omp-provider/src/adapter.ts
|
|
9800
10107
|
var UNSUPPORTED_EVENTS = /* @__PURE__ */ new Set(["session_info_changed"]);
|
|
9801
10108
|
var SESSION_START_ALIASES = ["session_switch", "session_branch"];
|
|
@@ -9898,6 +10205,9 @@ function adaptProviderConfig(config, env = process.env, providerName) {
|
|
|
9898
10205
|
if (remapProvider && Array.isArray(next.models)) {
|
|
9899
10206
|
next.models = mapModelsForOmp(next.models, remapProvider);
|
|
9900
10207
|
}
|
|
10208
|
+
if (providerName === "kiro" && next.usage == null) {
|
|
10209
|
+
next.usage = kiroUsageProvider;
|
|
10210
|
+
}
|
|
9901
10211
|
return next;
|
|
9902
10212
|
}
|
|
9903
10213
|
function wrapExtensionApi(pi, options = {}) {
|