@ngosangns/ns-bridge 0.1.14 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/catalog.js +22 -8
- package/dist/catalog.js.map +1 -1
- package/dist/cli.d.ts +5 -0
- package/dist/cli.js +181 -1
- package/dist/cli.js.map +1 -1
- package/dist/kiro-profile.d.ts +44 -0
- package/dist/kiro-profile.js +54 -0
- package/dist/kiro-profile.js.map +1 -0
- package/dist/refresh-entry.js +221 -58
- package/dist/usage.d.ts +62 -0
- package/dist/usage.js +210 -0
- package/dist/usage.js.map +1 -0
- package/package.json +2 -1
package/dist/refresh-entry.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @ngosangns/ns-bridge 0.1.
|
|
1
|
+
// @ngosangns/ns-bridge 0.1.16 — catalog refresh bundle.
|
|
2
2
|
import { createRequire as __nsBridgeCreateRequire } from 'node:module';
|
|
3
3
|
const require = __nsBridgeCreateRequire(import.meta.url);
|
|
4
4
|
var __create = Object.create;
|
|
@@ -7736,10 +7736,10 @@ async function setupSkills(ctx) {
|
|
|
7736
7736
|
for (const skill of session.agent.skills) {
|
|
7737
7737
|
try {
|
|
7738
7738
|
const version = await client.beta.skills.versions.retrieve(skill.version, { skill_id: skill.skill_id });
|
|
7739
|
-
let
|
|
7740
|
-
if (
|
|
7741
|
-
|
|
7742
|
-
const dest = path.resolve(skillsRoot,
|
|
7739
|
+
let dirname7 = path.basename(version.name.trim());
|
|
7740
|
+
if (dirname7 === "" || dirname7 === "." || dirname7 === "..")
|
|
7741
|
+
dirname7 = skill.skill_id;
|
|
7742
|
+
const dest = path.resolve(skillsRoot, dirname7);
|
|
7743
7743
|
if (dest !== skillsRoot && !dest.startsWith(skillsRoot + path.sep)) {
|
|
7744
7744
|
log.warn("skill name escapes the skills dir; skipping", {
|
|
7745
7745
|
component: "agent-tool-context",
|
|
@@ -18933,8 +18933,8 @@ function getBunSandboxEnvValue(name) {
|
|
|
18933
18933
|
if (procEnvCache === null) {
|
|
18934
18934
|
procEnvCache = /* @__PURE__ */ new Map();
|
|
18935
18935
|
try {
|
|
18936
|
-
const { readFileSync:
|
|
18937
|
-
const data =
|
|
18936
|
+
const { readFileSync: readFileSync9 } = __require("node:fs");
|
|
18937
|
+
const data = readFileSync9("/proc/self/environ", "utf-8");
|
|
18938
18938
|
for (const entry of data.split("\0")) {
|
|
18939
18939
|
const idx = entry.indexOf("=");
|
|
18940
18940
|
if (idx > 0) {
|
|
@@ -50781,7 +50781,7 @@ var require_gaxios = __commonJS({
|
|
|
50781
50781
|
var retry_js_1 = require_retry3();
|
|
50782
50782
|
var stream_1 = __require("stream");
|
|
50783
50783
|
var interceptor_js_1 = require_interceptor();
|
|
50784
|
-
var
|
|
50784
|
+
var randomUUID5 = async () => globalThis.crypto?.randomUUID() || (await import("crypto")).randomUUID();
|
|
50785
50785
|
var HTTP_STATUS_NO_CONTENT = 204;
|
|
50786
50786
|
var Gaxios = class {
|
|
50787
50787
|
agentCache = /* @__PURE__ */ new Map();
|
|
@@ -51054,7 +51054,7 @@ var require_gaxios = __commonJS({
|
|
|
51054
51054
|
*/
|
|
51055
51055
|
["Blob", "File", "FormData"].includes(opts.data?.constructor?.name || "");
|
|
51056
51056
|
if (opts.multipart?.length) {
|
|
51057
|
-
const boundary = await
|
|
51057
|
+
const boundary = await randomUUID5();
|
|
51058
51058
|
preparedHeaders.set("content-type", `multipart/related; boundary=${boundary}`);
|
|
51059
51059
|
opts.body = stream_1.Readable.from(this.getMultipartRequest(opts.multipart, boundary));
|
|
51060
51060
|
} else if (shouldDirectlyPassData) {
|
|
@@ -63197,7 +63197,7 @@ var require_websocket = __commonJS({
|
|
|
63197
63197
|
var http3 = __require("http");
|
|
63198
63198
|
var net = __require("net");
|
|
63199
63199
|
var tls = __require("tls");
|
|
63200
|
-
var { randomBytes, createHash:
|
|
63200
|
+
var { randomBytes, createHash: createHash3 } = __require("crypto");
|
|
63201
63201
|
var { Duplex, Readable: Readable2 } = __require("stream");
|
|
63202
63202
|
var { URL: URL2 } = __require("url");
|
|
63203
63203
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -63865,7 +63865,7 @@ var require_websocket = __commonJS({
|
|
|
63865
63865
|
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
63866
63866
|
return;
|
|
63867
63867
|
}
|
|
63868
|
-
const digest =
|
|
63868
|
+
const digest = createHash3("sha1").update(key + GUID).digest("base64");
|
|
63869
63869
|
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
63870
63870
|
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
63871
63871
|
return;
|
|
@@ -64234,7 +64234,7 @@ var require_websocket_server = __commonJS({
|
|
|
64234
64234
|
var EventEmitter = __require("events");
|
|
64235
64235
|
var http3 = __require("http");
|
|
64236
64236
|
var { Duplex } = __require("stream");
|
|
64237
|
-
var { createHash:
|
|
64237
|
+
var { createHash: createHash3 } = __require("crypto");
|
|
64238
64238
|
var extension2 = require_extension();
|
|
64239
64239
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
64240
64240
|
var subprotocol2 = require_subprotocol();
|
|
@@ -64541,7 +64541,7 @@ var require_websocket_server = __commonJS({
|
|
|
64541
64541
|
);
|
|
64542
64542
|
}
|
|
64543
64543
|
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
64544
|
-
const digest =
|
|
64544
|
+
const digest = createHash3("sha1").update(key + GUID).digest("base64");
|
|
64545
64545
|
const headers = [
|
|
64546
64546
|
"HTTP/1.1 101 Switching Protocols",
|
|
64547
64547
|
"Upgrade: websocket",
|
|
@@ -92390,6 +92390,12 @@ function getKiroEndpoints(region) {
|
|
|
92390
92390
|
runtime: endpointOverride(KIRO_RUNTIME_ENDPOINT_ENV, region) ?? `https://runtime.${region}.kiro.dev/`
|
|
92391
92391
|
};
|
|
92392
92392
|
}
|
|
92393
|
+
function getKiroRegionFromProfileArn(profileArn) {
|
|
92394
|
+
if (!profileArn)
|
|
92395
|
+
return void 0;
|
|
92396
|
+
const region = profileArn.split(":")[3];
|
|
92397
|
+
return region && /^[a-z]{2}(?:-[a-z]+)+-\d$/.test(region) ? region : void 0;
|
|
92398
|
+
}
|
|
92393
92399
|
var API_REGION_MAP, KIRO_RUNTIME_ENDPOINT_ENV, KIRO_MANAGEMENT_ENDPOINT_ENV;
|
|
92394
92400
|
var init_endpoints = __esm({
|
|
92395
92401
|
"../kiro-core/dist/endpoints.js"() {
|
|
@@ -92550,6 +92556,18 @@ function getKiroCliCredentialsAllowExpired() {
|
|
|
92550
92556
|
return void 0;
|
|
92551
92557
|
}
|
|
92552
92558
|
}
|
|
92559
|
+
function getKiroCliSelectedProfileArn(dbPath) {
|
|
92560
|
+
const result = queryKiroCliDb(dbPath, "SELECT value FROM state WHERE key = 'api.codewhisperer.profile'");
|
|
92561
|
+
if (!result)
|
|
92562
|
+
return void 0;
|
|
92563
|
+
try {
|
|
92564
|
+
const rows = JSON.parse(result);
|
|
92565
|
+
const profile = JSON.parse(rows[0]?.value ?? "");
|
|
92566
|
+
return typeof profile.arn === "string" && profile.arn ? profile.arn : void 0;
|
|
92567
|
+
} catch {
|
|
92568
|
+
return void 0;
|
|
92569
|
+
}
|
|
92570
|
+
}
|
|
92553
92571
|
function tryKiroCliToken(dbPath, tokenKey, authMethod, allowExpired = false) {
|
|
92554
92572
|
const tokenResult = queryKiroCliDb(dbPath, `SELECT value FROM auth_kv WHERE key = '${tokenKey}'`);
|
|
92555
92573
|
if (!tokenResult)
|
|
@@ -92566,6 +92584,8 @@ function tryKiroCliToken(dbPath, tokenKey, authMethod, allowExpired = false) {
|
|
|
92566
92584
|
if (!allowExpired && Date.now() >= expiresAt - 2 * 60 * 1e3)
|
|
92567
92585
|
return void 0;
|
|
92568
92586
|
const region = tokenData.region || "us-east-1";
|
|
92587
|
+
const tokenProfileArn = tokenData.profile_arn || tokenData.profileArn;
|
|
92588
|
+
const profileArn = authMethod === "desktop" ? tokenProfileArn ?? getKiroCliSelectedProfileArn(dbPath) : getKiroCliSelectedProfileArn(dbPath) ?? tokenProfileArn;
|
|
92569
92589
|
if (authMethod === "desktop") {
|
|
92570
92590
|
return {
|
|
92571
92591
|
refresh: `${tokenData.refresh_token}|desktop`,
|
|
@@ -92575,7 +92595,7 @@ function tryKiroCliToken(dbPath, tokenKey, authMethod, allowExpired = false) {
|
|
|
92575
92595
|
clientSecret: "",
|
|
92576
92596
|
region,
|
|
92577
92597
|
authMethod: "desktop",
|
|
92578
|
-
profileArn
|
|
92598
|
+
profileArn
|
|
92579
92599
|
};
|
|
92580
92600
|
}
|
|
92581
92601
|
if (authMethod === "external-idp") {
|
|
@@ -92590,7 +92610,7 @@ function tryKiroCliToken(dbPath, tokenKey, authMethod, allowExpired = false) {
|
|
|
92590
92610
|
clientSecret: "",
|
|
92591
92611
|
region,
|
|
92592
92612
|
authMethod: "external-idp",
|
|
92593
|
-
profileArn
|
|
92613
|
+
profileArn
|
|
92594
92614
|
};
|
|
92595
92615
|
}
|
|
92596
92616
|
let clientId = "";
|
|
@@ -92613,7 +92633,7 @@ function tryKiroCliToken(dbPath, tokenKey, authMethod, allowExpired = false) {
|
|
|
92613
92633
|
clientSecret,
|
|
92614
92634
|
region,
|
|
92615
92635
|
authMethod: "idc",
|
|
92616
|
-
profileArn
|
|
92636
|
+
profileArn
|
|
92617
92637
|
};
|
|
92618
92638
|
}
|
|
92619
92639
|
function getKiroCliSocialToken() {
|
|
@@ -93102,6 +93122,56 @@ var init_oauth = __esm({
|
|
|
93102
93122
|
}
|
|
93103
93123
|
});
|
|
93104
93124
|
|
|
93125
|
+
// ../kiro-core/dist/profile.js
|
|
93126
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
93127
|
+
import { mkdirSync as mkdirSync5, readFileSync as readFileSync7, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "node:fs";
|
|
93128
|
+
import { homedir as homedir9 } from "node:os";
|
|
93129
|
+
import { dirname as dirname6, join as join10 } from "node:path";
|
|
93130
|
+
function readKiroProfileSelection() {
|
|
93131
|
+
let value;
|
|
93132
|
+
try {
|
|
93133
|
+
value = JSON.parse(readFileSync7(KIRO_PROFILE_SELECTION_PATH, "utf-8"));
|
|
93134
|
+
} catch {
|
|
93135
|
+
return void 0;
|
|
93136
|
+
}
|
|
93137
|
+
if (typeof value !== "object" || value === null)
|
|
93138
|
+
return void 0;
|
|
93139
|
+
const { arn, name } = value;
|
|
93140
|
+
if (typeof arn !== "string" || !arn)
|
|
93141
|
+
return void 0;
|
|
93142
|
+
return { arn, ...typeof name === "string" && name ? { name } : {} };
|
|
93143
|
+
}
|
|
93144
|
+
function writeKiroProfileSelection(selection) {
|
|
93145
|
+
if (!selection) {
|
|
93146
|
+
rmSync2(KIRO_PROFILE_SELECTION_PATH, { force: true });
|
|
93147
|
+
return;
|
|
93148
|
+
}
|
|
93149
|
+
mkdirSync5(dirname6(KIRO_PROFILE_SELECTION_PATH), { recursive: true });
|
|
93150
|
+
const temporaryPath = `${KIRO_PROFILE_SELECTION_PATH}.${process.pid}.${randomUUID3()}.tmp`;
|
|
93151
|
+
try {
|
|
93152
|
+
writeFileSync4(temporaryPath, `${JSON.stringify(selection, null, 2)}
|
|
93153
|
+
`, "utf-8");
|
|
93154
|
+
renameSync3(temporaryPath, KIRO_PROFILE_SELECTION_PATH);
|
|
93155
|
+
} finally {
|
|
93156
|
+
rmSync2(temporaryPath, { force: true });
|
|
93157
|
+
}
|
|
93158
|
+
}
|
|
93159
|
+
function getKiroProfileOverride() {
|
|
93160
|
+
const envArn = process.env[KIRO_PROFILE_ARN_ENV]?.trim();
|
|
93161
|
+
if (envArn)
|
|
93162
|
+
return { arn: envArn, source: "env" };
|
|
93163
|
+
const selection = readKiroProfileSelection();
|
|
93164
|
+
return selection ? { arn: selection.arn, source: "ns-bridge" } : void 0;
|
|
93165
|
+
}
|
|
93166
|
+
var KIRO_PROFILE_SELECTION_PATH, KIRO_PROFILE_ARN_ENV;
|
|
93167
|
+
var init_profile = __esm({
|
|
93168
|
+
"../kiro-core/dist/profile.js"() {
|
|
93169
|
+
"use strict";
|
|
93170
|
+
KIRO_PROFILE_SELECTION_PATH = join10(homedir9(), ".ns-bridge", "kiro-profile.json");
|
|
93171
|
+
KIRO_PROFILE_ARN_ENV = "KIRO_PROFILE_ARN";
|
|
93172
|
+
}
|
|
93173
|
+
});
|
|
93174
|
+
|
|
93105
93175
|
// ../kiro-core/dist/management.js
|
|
93106
93176
|
var management_exports = {};
|
|
93107
93177
|
__export(management_exports, {
|
|
@@ -93111,7 +93181,9 @@ __export(management_exports, {
|
|
|
93111
93181
|
fetchKiroModelCatalog: () => fetchKiroModelCatalog,
|
|
93112
93182
|
getUsageLimits: () => getUsageLimits,
|
|
93113
93183
|
invalidateKiroProfileArn: () => invalidateKiroProfileArn,
|
|
93184
|
+
kiroProfileAuth: () => kiroProfileAuth,
|
|
93114
93185
|
listAvailableModels: () => listAvailableModels,
|
|
93186
|
+
listKiroProfiles: () => listKiroProfiles,
|
|
93115
93187
|
resetKiroProfileArnCache: () => resetKiroProfileArnCache,
|
|
93116
93188
|
resolveKiroProfileArn: () => resolveKiroProfileArn,
|
|
93117
93189
|
snapshotKiroProfileArnCache: () => snapshotKiroProfileArnCache,
|
|
@@ -93202,10 +93274,10 @@ function invalidateKiroProfileArn(auth) {
|
|
|
93202
93274
|
pendingProfileRequests.delete(key);
|
|
93203
93275
|
}
|
|
93204
93276
|
async function resolveKiroProfileArn(auth, providedArn) {
|
|
93205
|
-
const
|
|
93206
|
-
if (
|
|
93207
|
-
debugLog("profile.resolve", { source:
|
|
93208
|
-
return
|
|
93277
|
+
const override = getKiroProfileOverride();
|
|
93278
|
+
if (override) {
|
|
93279
|
+
debugLog("profile.resolve", { source: override.source, arn: override.arn });
|
|
93280
|
+
return override.arn;
|
|
93209
93281
|
}
|
|
93210
93282
|
if (providedArn) {
|
|
93211
93283
|
debugLog("profile.resolve", { source: "provided", arn: providedArn });
|
|
@@ -93261,6 +93333,37 @@ async function resolveKiroProfileArn(auth, providedArn) {
|
|
|
93261
93333
|
pendingProfileRequests.delete(key);
|
|
93262
93334
|
}
|
|
93263
93335
|
}
|
|
93336
|
+
async function listKiroProfiles(auth) {
|
|
93337
|
+
if (isApiKey(auth.accessToken)) {
|
|
93338
|
+
return [{ arn: await getApiKeyProfileArn(auth.accessToken), region: API_KEY_REGION2 }];
|
|
93339
|
+
}
|
|
93340
|
+
const profiles = /* @__PURE__ */ new Map();
|
|
93341
|
+
let lastHttpError;
|
|
93342
|
+
for (const region of candidateManagementRegions(auth.region)) {
|
|
93343
|
+
let response;
|
|
93344
|
+
try {
|
|
93345
|
+
response = await requestManagement({ ...auth, region }, "ListAvailableProfiles", LIST_PROFILES_PATH, "POST", {});
|
|
93346
|
+
} catch (error) {
|
|
93347
|
+
if (error instanceof KiroManagementHttpError && error.status === 403) {
|
|
93348
|
+
lastHttpError = error;
|
|
93349
|
+
continue;
|
|
93350
|
+
}
|
|
93351
|
+
throw error;
|
|
93352
|
+
}
|
|
93353
|
+
for (const profile of response.profiles ?? []) {
|
|
93354
|
+
if (!profile.arn || profiles.has(profile.arn))
|
|
93355
|
+
continue;
|
|
93356
|
+
profiles.set(profile.arn, {
|
|
93357
|
+
arn: profile.arn,
|
|
93358
|
+
...typeof profile.profileName === "string" && profile.profileName ? { name: profile.profileName } : {},
|
|
93359
|
+
region: getKiroRegionFromProfileArn(profile.arn) ?? region
|
|
93360
|
+
});
|
|
93361
|
+
}
|
|
93362
|
+
}
|
|
93363
|
+
if (profiles.size === 0 && lastHttpError)
|
|
93364
|
+
throw lastHttpError;
|
|
93365
|
+
return [...profiles.values()];
|
|
93366
|
+
}
|
|
93264
93367
|
async function listAvailableModels(auth, profileArn) {
|
|
93265
93368
|
const response = await requestManagement(auth, "ListAvailableModels", LIST_MODELS_PATH, "GET", {
|
|
93266
93369
|
origin: "KIRO_CLI",
|
|
@@ -93276,11 +93379,11 @@ async function listAvailableModels(auth, profileArn) {
|
|
|
93276
93379
|
}
|
|
93277
93380
|
async function fetchKiroModelCatalog(auth, providedProfileArn) {
|
|
93278
93381
|
const profileArn = await resolveKiroProfileArn(auth, providedProfileArn);
|
|
93279
|
-
|
|
93280
|
-
|
|
93281
|
-
|
|
93282
|
-
|
|
93283
|
-
return
|
|
93382
|
+
return listAvailableModels(kiroProfileAuth(auth, profileArn), profileArn);
|
|
93383
|
+
}
|
|
93384
|
+
function kiroProfileAuth(auth, profileArn) {
|
|
93385
|
+
const region = isApiKey(auth.accessToken) ? API_KEY_REGION2 : getKiroRegionFromProfileArn(profileArn) ?? profileRegionCache.get(profileCacheKey(auth)) ?? auth.region;
|
|
93386
|
+
return region === auth.region ? auth : { ...auth, region };
|
|
93284
93387
|
}
|
|
93285
93388
|
async function getUsageLimits(auth, request) {
|
|
93286
93389
|
const operation = "GetUsageLimits";
|
|
@@ -93293,7 +93396,7 @@ async function getUsageLimits(auth, request) {
|
|
|
93293
93396
|
}
|
|
93294
93397
|
return parseManagementResponse(response, operation, auth.region);
|
|
93295
93398
|
}
|
|
93296
|
-
var LIST_PROFILES_PATH, LIST_MODELS_PATH, API_KEY_REGION2, profileArnCache, pendingProfileRequests, profileRegionCache, CANONICAL_MANAGEMENT_REGIONS,
|
|
93399
|
+
var LIST_PROFILES_PATH, LIST_MODELS_PATH, API_KEY_REGION2, profileArnCache, pendingProfileRequests, profileRegionCache, CANONICAL_MANAGEMENT_REGIONS, KiroManagementHttpError;
|
|
93297
93400
|
var init_management = __esm({
|
|
93298
93401
|
"../kiro-core/dist/management.js"() {
|
|
93299
93402
|
"use strict";
|
|
@@ -93301,6 +93404,7 @@ var init_management = __esm({
|
|
|
93301
93404
|
init_endpoints();
|
|
93302
93405
|
init_http();
|
|
93303
93406
|
init_oauth();
|
|
93407
|
+
init_profile();
|
|
93304
93408
|
LIST_PROFILES_PATH = "List-Available-Profiles";
|
|
93305
93409
|
LIST_MODELS_PATH = "List-Available-Models";
|
|
93306
93410
|
API_KEY_REGION2 = "us-east-1";
|
|
@@ -93308,7 +93412,6 @@ var init_management = __esm({
|
|
|
93308
93412
|
pendingProfileRequests = /* @__PURE__ */ new Map();
|
|
93309
93413
|
profileRegionCache = /* @__PURE__ */ new Map();
|
|
93310
93414
|
CANONICAL_MANAGEMENT_REGIONS = ["us-east-1", "eu-central-1"];
|
|
93311
|
-
ENV_PROFILE_ARN = "KIRO_PROFILE_ARN";
|
|
93312
93415
|
KiroManagementHttpError = class extends Error {
|
|
93313
93416
|
status;
|
|
93314
93417
|
constructor(message, status) {
|
|
@@ -93418,6 +93521,9 @@ function compactionBudget(model) {
|
|
|
93418
93521
|
return { reserveTokens, thresholdTokens: contextWindow - reserveTokens };
|
|
93419
93522
|
}
|
|
93420
93523
|
|
|
93524
|
+
// ../core-utils/dist/usage-ledger.js
|
|
93525
|
+
var USAGE_MAX_BYTES = 50 * 1024 * 1024;
|
|
93526
|
+
|
|
93421
93527
|
// ../devin-core/dist/util.js
|
|
93422
93528
|
function isRecord(value) {
|
|
93423
93529
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -98745,10 +98851,10 @@ async function resolveKiroRequestCredentials(hostKey) {
|
|
|
98745
98851
|
}
|
|
98746
98852
|
|
|
98747
98853
|
// ../kiro-core/dist/models.js
|
|
98748
|
-
import { randomUUID as
|
|
98749
|
-
import { existsSync as existsSync5, readFileSync as
|
|
98750
|
-
import { homedir as
|
|
98751
|
-
import { join as
|
|
98854
|
+
import { createHash as createHash2, randomUUID as randomUUID4 } from "node:crypto";
|
|
98855
|
+
import { existsSync as existsSync5, readFileSync as readFileSync8, renameSync as renameSync4, rmSync as rmSync3, writeFileSync as writeFileSync5 } from "node:fs";
|
|
98856
|
+
import { homedir as homedir10 } from "node:os";
|
|
98857
|
+
import { join as join11 } from "node:path";
|
|
98752
98858
|
|
|
98753
98859
|
// ../kiro-core/dist/types.js
|
|
98754
98860
|
var KIRO_EFFORT_ORDER = ["minimal", "low", "medium", "high", "xhigh", "max"];
|
|
@@ -98814,9 +98920,11 @@ function getKiroEffortConfig(schema, kiroModelId) {
|
|
|
98814
98920
|
|
|
98815
98921
|
// ../kiro-core/dist/models.js
|
|
98816
98922
|
init_endpoints();
|
|
98923
|
+
init_profile();
|
|
98924
|
+
init_endpoints();
|
|
98817
98925
|
var KIRO_MANAGEMENT_CACHE_VERSION = 1;
|
|
98818
98926
|
var KIRO_MANAGEMENT_CACHE_SOURCE = "ns-kiro-provider-management";
|
|
98819
|
-
var KIRO_MANAGEMENT_CACHE_PATH =
|
|
98927
|
+
var KIRO_MANAGEMENT_CACHE_PATH = join11(homedir10(), ".ns-kiro-provider-models-cache.json");
|
|
98820
98928
|
var CACHE_MAX_AGE_MS = 36e5;
|
|
98821
98929
|
var DEFAULT_CONTEXT_WINDOW3 = 2e5;
|
|
98822
98930
|
var DEFAULT_MAX_TOKENS3 = 8192;
|
|
@@ -99074,39 +99182,65 @@ function parseManagementCache(raw) {
|
|
|
99074
99182
|
}
|
|
99075
99183
|
const regions = {};
|
|
99076
99184
|
for (const [region, rawEntry] of Object.entries(value.regions)) {
|
|
99077
|
-
if (!
|
|
99185
|
+
if (!isCacheEntry(rawEntry) || rawEntry.region !== region)
|
|
99078
99186
|
return void 0;
|
|
99079
|
-
}
|
|
99080
|
-
const modelIds = /* @__PURE__ */ new Set();
|
|
99081
|
-
for (const model of rawEntry.models) {
|
|
99082
|
-
if (modelIds.has(model.id))
|
|
99083
|
-
return void 0;
|
|
99084
|
-
modelIds.add(model.id);
|
|
99085
|
-
}
|
|
99086
99187
|
regions[region] = rawEntry;
|
|
99087
99188
|
}
|
|
99189
|
+
const profiles = {};
|
|
99190
|
+
for (const [key, rawEntry] of Object.entries(isRecord4(value.profiles) ? value.profiles : {})) {
|
|
99191
|
+
if (isCacheEntry(rawEntry))
|
|
99192
|
+
profiles[key] = rawEntry;
|
|
99193
|
+
}
|
|
99088
99194
|
return {
|
|
99089
99195
|
version: KIRO_MANAGEMENT_CACHE_VERSION,
|
|
99090
99196
|
source: KIRO_MANAGEMENT_CACHE_SOURCE,
|
|
99091
|
-
regions
|
|
99197
|
+
regions,
|
|
99198
|
+
...Object.keys(profiles).length > 0 ? { profiles } : {}
|
|
99092
99199
|
};
|
|
99093
99200
|
}
|
|
99201
|
+
function isCacheEntry(value) {
|
|
99202
|
+
if (!isRecord4(value) || typeof value.region !== "string" || !isPositiveNumber(value.fetchedAt) || !Array.isArray(value.models) || value.models.length === 0 || !value.models.every(isCachedKiroModel)) {
|
|
99203
|
+
return false;
|
|
99204
|
+
}
|
|
99205
|
+
const modelIds = /* @__PURE__ */ new Set();
|
|
99206
|
+
for (const model of value.models) {
|
|
99207
|
+
if (modelIds.has(model.id))
|
|
99208
|
+
return false;
|
|
99209
|
+
modelIds.add(model.id);
|
|
99210
|
+
}
|
|
99211
|
+
return true;
|
|
99212
|
+
}
|
|
99213
|
+
function allCacheEntries(cache) {
|
|
99214
|
+
if (!cache)
|
|
99215
|
+
return [];
|
|
99216
|
+
return [...Object.values(cache.regions), ...Object.values(cache.profiles ?? {})];
|
|
99217
|
+
}
|
|
99218
|
+
function kiroProfileCacheKey(profileArn) {
|
|
99219
|
+
return createHash2("sha256").update(profileArn).digest("base64url").slice(0, 16);
|
|
99220
|
+
}
|
|
99221
|
+
function hasCachedKiroProfileCatalog(profileArn) {
|
|
99222
|
+
return readManagementCache()?.profiles?.[kiroProfileCacheKey(profileArn)] !== void 0;
|
|
99223
|
+
}
|
|
99224
|
+
function activeCacheEntry(cache, region) {
|
|
99225
|
+
const override = getKiroProfileOverride();
|
|
99226
|
+
return override ? cache?.profiles?.[kiroProfileCacheKey(override.arn)] : cache?.regions[region];
|
|
99227
|
+
}
|
|
99094
99228
|
function readManagementCache() {
|
|
99095
99229
|
if (!existsSync5(KIRO_MANAGEMENT_CACHE_PATH))
|
|
99096
99230
|
return void 0;
|
|
99097
99231
|
try {
|
|
99098
|
-
return parseManagementCache(
|
|
99232
|
+
return parseManagementCache(readFileSync8(KIRO_MANAGEMENT_CACHE_PATH, "utf-8"));
|
|
99099
99233
|
} catch {
|
|
99100
99234
|
return void 0;
|
|
99101
99235
|
}
|
|
99102
99236
|
}
|
|
99103
99237
|
function writeManagementCache(cache) {
|
|
99104
|
-
const temporaryPath = `${KIRO_MANAGEMENT_CACHE_PATH}.${process.pid}.${
|
|
99238
|
+
const temporaryPath = `${KIRO_MANAGEMENT_CACHE_PATH}.${process.pid}.${randomUUID4()}.tmp`;
|
|
99105
99239
|
try {
|
|
99106
|
-
|
|
99107
|
-
|
|
99240
|
+
writeFileSync5(temporaryPath, JSON.stringify(cache, null, 2), "utf-8");
|
|
99241
|
+
renameSync4(temporaryPath, KIRO_MANAGEMENT_CACHE_PATH);
|
|
99108
99242
|
} finally {
|
|
99109
|
-
|
|
99243
|
+
rmSync3(temporaryPath, { force: true });
|
|
99110
99244
|
}
|
|
99111
99245
|
}
|
|
99112
99246
|
function toLocalModelId(kiroModelId) {
|
|
@@ -99210,9 +99344,7 @@ function refreshKnownModelIds(cache) {
|
|
|
99210
99344
|
KIRO_MODEL_IDS.clear();
|
|
99211
99345
|
for (const modelId of BOOTSTRAP_KIRO_MODEL_IDS)
|
|
99212
99346
|
KIRO_MODEL_IDS.add(modelId);
|
|
99213
|
-
|
|
99214
|
-
return;
|
|
99215
|
-
for (const entry of Object.values(cache.regions)) {
|
|
99347
|
+
for (const entry of allCacheEntries(cache)) {
|
|
99216
99348
|
for (const model of entry.models)
|
|
99217
99349
|
KIRO_MODEL_IDS.add(model.kiroModelId);
|
|
99218
99350
|
}
|
|
@@ -99220,7 +99352,7 @@ function refreshKnownModelIds(cache) {
|
|
|
99220
99352
|
function getCachedModels2(region) {
|
|
99221
99353
|
const cache = readManagementCache();
|
|
99222
99354
|
refreshKnownModelIds(cache);
|
|
99223
|
-
const models = cache?.regions[region]?.models ?? kiroModels;
|
|
99355
|
+
const models = activeCacheEntry(cache, region)?.models ?? cache?.regions[region]?.models ?? kiroModels;
|
|
99224
99356
|
let changed = false;
|
|
99225
99357
|
const corrected = models.map((model) => {
|
|
99226
99358
|
const result = applyVerifiedCapabilities(model);
|
|
@@ -99231,27 +99363,38 @@ function getCachedModels2(region) {
|
|
|
99231
99363
|
return changed ? corrected : models;
|
|
99232
99364
|
}
|
|
99233
99365
|
function isCacheStale2(region) {
|
|
99234
|
-
const entry = readManagementCache()
|
|
99366
|
+
const entry = activeCacheEntry(readManagementCache(), region);
|
|
99235
99367
|
return !entry || Date.now() - entry.fetchedAt > CACHE_MAX_AGE_MS;
|
|
99236
99368
|
}
|
|
99237
99369
|
async function updateKiroModelsCache(accessToken, region, profileArn) {
|
|
99238
|
-
const { fetchKiroModelCatalog: fetchKiroModelCatalog2 } = await Promise.resolve().then(() => (init_management(), management_exports));
|
|
99370
|
+
const { fetchKiroModelCatalog: fetchKiroModelCatalog2, resolveKiroProfileArn: resolveKiroProfileArn2 } = await Promise.resolve().then(() => (init_management(), management_exports));
|
|
99239
99371
|
const { getKiroCliModelRates: getKiroCliModelRates2 } = await Promise.resolve().then(() => (init_kiro_cli(), kiro_cli_exports));
|
|
99240
|
-
const
|
|
99372
|
+
const auth = { accessToken, region };
|
|
99373
|
+
const resolvedProfileArn = await resolveKiroProfileArn2(auth, profileArn);
|
|
99374
|
+
const response = await fetchKiroModelCatalog2(auth, resolvedProfileArn);
|
|
99241
99375
|
const models = mapKiroCatalogModels(response.models, region, await getKiroCliModelRates2());
|
|
99242
99376
|
const cache = readManagementCache() ?? {
|
|
99243
99377
|
version: KIRO_MANAGEMENT_CACHE_VERSION,
|
|
99244
99378
|
source: KIRO_MANAGEMENT_CACHE_SOURCE,
|
|
99245
99379
|
regions: {}
|
|
99246
99380
|
};
|
|
99247
|
-
|
|
99381
|
+
const entry = { region, fetchedAt: Date.now(), models };
|
|
99382
|
+
const profileRegion = getKiroRegionFromProfileArn(resolvedProfileArn);
|
|
99383
|
+
cache.profiles = {
|
|
99384
|
+
...cache.profiles,
|
|
99385
|
+
[kiroProfileCacheKey(resolvedProfileArn)]: { ...entry, ...profileRegion ? { profileRegion } : {} }
|
|
99386
|
+
};
|
|
99387
|
+
if (!getKiroProfileOverride())
|
|
99388
|
+
cache.regions[region] = entry;
|
|
99248
99389
|
writeManagementCache(cache);
|
|
99249
99390
|
refreshKnownModelIds(cache);
|
|
99250
99391
|
}
|
|
99251
99392
|
|
|
99252
99393
|
// ../kiro-core/dist/index.js
|
|
99253
99394
|
init_kiro_cli();
|
|
99395
|
+
init_management();
|
|
99254
99396
|
init_oauth();
|
|
99397
|
+
init_profile();
|
|
99255
99398
|
|
|
99256
99399
|
// ../kiro-core/dist/request-builder.js
|
|
99257
99400
|
init_debug();
|
|
@@ -99310,10 +99453,10 @@ init_oauth();
|
|
|
99310
99453
|
init_token_type();
|
|
99311
99454
|
|
|
99312
99455
|
// ../kiro-core/dist/transport.js
|
|
99313
|
-
import { homedir as
|
|
99314
|
-
import { join as
|
|
99315
|
-
var CAPACITY_LOG_DIR =
|
|
99316
|
-
var CAPACITY_LOG_FILE =
|
|
99456
|
+
import { homedir as homedir11 } from "node:os";
|
|
99457
|
+
import { join as join12 } from "node:path";
|
|
99458
|
+
var CAPACITY_LOG_DIR = join12(homedir11(), ".ns-kiro-provider", "logs");
|
|
99459
|
+
var CAPACITY_LOG_FILE = join12(CAPACITY_LOG_DIR, "capacity-retries.log");
|
|
99317
99460
|
|
|
99318
99461
|
// ../kiro-core/dist/usage-tracking.js
|
|
99319
99462
|
var DEFAULT_USD_PER_CREDIT = 0.04;
|
|
@@ -99395,7 +99538,27 @@ function createBundledRefresh() {
|
|
|
99395
99538
|
}
|
|
99396
99539
|
};
|
|
99397
99540
|
}
|
|
99541
|
+
function createBundledKiroProfiles() {
|
|
99542
|
+
return {
|
|
99543
|
+
list: async () => {
|
|
99544
|
+
const credentials = await resolveKiroRequestCredentials(process.env.KIRO_API_KEY?.trim() || void 0);
|
|
99545
|
+
const auth = { accessToken: credentials.accessToken, region: credentials.region };
|
|
99546
|
+
const profiles = await listKiroProfiles(auth);
|
|
99547
|
+
const override = getKiroProfileOverride();
|
|
99548
|
+
const arn = await resolveKiroProfileArn(auth, credentials.profileArn);
|
|
99549
|
+
return {
|
|
99550
|
+
profiles,
|
|
99551
|
+
active: { arn, source: override?.source ?? "login" },
|
|
99552
|
+
...credentials.profileArn ? { loginArn: credentials.profileArn } : {}
|
|
99553
|
+
};
|
|
99554
|
+
},
|
|
99555
|
+
select: writeKiroProfileSelection,
|
|
99556
|
+
hasCatalog: hasCachedKiroProfileCatalog,
|
|
99557
|
+
selectionPath: KIRO_PROFILE_SELECTION_PATH
|
|
99558
|
+
};
|
|
99559
|
+
}
|
|
99398
99560
|
export {
|
|
99561
|
+
createBundledKiroProfiles,
|
|
99399
99562
|
createBundledRefresh
|
|
99400
99563
|
};
|
|
99401
99564
|
/*! Bundled license information:
|
package/dist/usage.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ns-bridge usage`: read the usage ledger the provider cores write.
|
|
3
|
+
*
|
|
4
|
+
* Layout: <root>/<day>/<vendor>/<session>.jsonl, one JSON line per response.
|
|
5
|
+
* This module only reads. It shares no code with the writer, so the published
|
|
6
|
+
* CLI keeps no runtime dependency on the provider packages; the record shape
|
|
7
|
+
* below is the contract between them.
|
|
8
|
+
*/
|
|
9
|
+
export interface UsageLine {
|
|
10
|
+
ts: string;
|
|
11
|
+
vendor: string;
|
|
12
|
+
host: string;
|
|
13
|
+
model: string;
|
|
14
|
+
session: string | null;
|
|
15
|
+
step: number | null;
|
|
16
|
+
gapMs: number | null;
|
|
17
|
+
input: number;
|
|
18
|
+
output: number;
|
|
19
|
+
promptTokens: number;
|
|
20
|
+
cacheRead?: number;
|
|
21
|
+
cacheWrite?: number;
|
|
22
|
+
cacheHitRatio: number | null;
|
|
23
|
+
cacheWriteRatio: number | null;
|
|
24
|
+
cacheSource: "wire" | "credits" | "credits-capped" | "none";
|
|
25
|
+
cacheHitMax?: number;
|
|
26
|
+
contextFill?: number;
|
|
27
|
+
effort?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface UsageQuery {
|
|
30
|
+
/** Newest N day folders. Ignored when `day` is set, or when `session` is set without `days`. */
|
|
31
|
+
days?: number;
|
|
32
|
+
day?: string;
|
|
33
|
+
vendor?: string;
|
|
34
|
+
session?: string;
|
|
35
|
+
}
|
|
36
|
+
export declare const DEFAULT_USAGE_DAYS = 10;
|
|
37
|
+
export declare function usageRoot(env?: NodeJS.ProcessEnv): string;
|
|
38
|
+
/** Records for the query, oldest first. `skipped` counts lines that did not parse. */
|
|
39
|
+
export declare function readUsage(root: string, query?: UsageQuery): {
|
|
40
|
+
records: UsageLine[];
|
|
41
|
+
skipped: number;
|
|
42
|
+
days: string[];
|
|
43
|
+
};
|
|
44
|
+
export interface UsageRow {
|
|
45
|
+
day: string;
|
|
46
|
+
vendor: string;
|
|
47
|
+
steps: number;
|
|
48
|
+
promptTokens: number;
|
|
49
|
+
/** cacheRead over prompt tokens, summed. Steps with no cache counters are left out of both sides. */
|
|
50
|
+
hit: number | null;
|
|
51
|
+
write: number | null;
|
|
52
|
+
wire: number;
|
|
53
|
+
credits: number;
|
|
54
|
+
capped: number;
|
|
55
|
+
none: number;
|
|
56
|
+
}
|
|
57
|
+
/** Group by local day (the folder the writer used is not on the record, so derive it the same way) and vendor. */
|
|
58
|
+
export declare function summarize(records: readonly UsageLine[], dayOf: (ts: string) => string): UsageRow[];
|
|
59
|
+
export declare function localDay(ts: string): string;
|
|
60
|
+
export declare function formatSummary(rows: readonly UsageRow[]): string[];
|
|
61
|
+
export declare function formatSession(records: readonly UsageLine[]): string[];
|
|
62
|
+
export declare function usageRootExists(root: string): boolean;
|