@ngosangns/ns-bridge 0.1.7 → 0.1.9

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.
@@ -1,4 +1,4 @@
1
- // @ngosangns/ns-bridge 0.1.7 — catalog refresh bundle.
1
+ // @ngosangns/ns-bridge 0.1.9 — 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;
@@ -18933,8 +18933,8 @@ function getBunSandboxEnvValue(name) {
18933
18933
  if (procEnvCache === null) {
18934
18934
  procEnvCache = /* @__PURE__ */ new Map();
18935
18935
  try {
18936
- const { readFileSync: readFileSync7 } = __require("node:fs");
18937
- const data = readFileSync7("/proc/self/environ", "utf-8");
18936
+ const { readFileSync: readFileSync8 } = __require("node:fs");
18937
+ const data = readFileSync8("/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) {
@@ -92324,8 +92324,8 @@ var init_typesafe_system_one = __esm({
92324
92324
 
92325
92325
  // ../kiro-core/dist/debug.js
92326
92326
  import { appendFileSync, mkdirSync as mkdirSync4 } from "node:fs";
92327
- import { homedir as homedir5 } from "node:os";
92328
- import { dirname as dirname5, join as join6 } from "node:path";
92327
+ import { homedir as homedir6 } from "node:os";
92328
+ import { dirname as dirname5, join as join7 } from "node:path";
92329
92329
  function debugLog(section, data) {
92330
92330
  if (!ENABLED)
92331
92331
  return;
@@ -92361,7 +92361,7 @@ var init_debug = __esm({
92361
92361
  "../kiro-core/dist/debug.js"() {
92362
92362
  "use strict";
92363
92363
  ENABLED = !!process.env.KIRO_DEBUG && process.env.KIRO_DEBUG !== "0";
92364
- LOG_FILE = process.env.KIRO_DEBUG_LOG || join6(homedir5(), ".ns-kiro-provider", "logs", "kiro-debug.log");
92364
+ LOG_FILE = process.env.KIRO_DEBUG_LOG || join7(homedir6(), ".ns-kiro-provider", "logs", "kiro-debug.log");
92365
92365
  dirReady = false;
92366
92366
  PROFILE_ARN_PATTERN = /arn:[a-z0-9-]+:codewhisperer:[^:\s"']*:[^:\s"']*:profile\/[^\s"',}\]]+/gi;
92367
92367
  BEARER_TOKEN_PATTERN = /(\bBearer\s+)[^\s"',}\]]+/gi;
@@ -92431,16 +92431,16 @@ __export(kiro_cli_exports, {
92431
92431
  saveKiroCliCredentials: () => saveKiroCliCredentials,
92432
92432
  tryKiroCliToken: () => tryKiroCliToken
92433
92433
  });
92434
- import { execFileSync, execSync } from "node:child_process";
92434
+ import { execFile as execFile3, execSync } from "node:child_process";
92435
92435
  import { existsSync as existsSync3 } from "node:fs";
92436
92436
  import { createRequire } from "node:module";
92437
- import { homedir as homedir6, platform } from "node:os";
92438
- import { join as join7 } from "node:path";
92437
+ import { homedir as homedir7, platform } from "node:os";
92438
+ import { join as join8 } from "node:path";
92439
92439
  function getKiroCliDbPath() {
92440
92440
  const p = platform();
92441
- const localAppData = process.env.LOCALAPPDATA || join7(homedir6(), "AppData", "Local");
92442
- const roamingAppData = process.env.APPDATA || join7(homedir6(), "AppData", "Roaming");
92443
- const candidates = p === "win32" ? [join7(localAppData, "Kiro-Cli", "data.sqlite3"), join7(roamingAppData, "kiro-cli", "data.sqlite3")] : p === "darwin" ? [join7(homedir6(), "Library", "Application Support", "kiro-cli", "data.sqlite3")] : [join7(homedir6(), ".local", "share", "kiro-cli", "data.sqlite3")];
92441
+ const localAppData = process.env.LOCALAPPDATA || join8(homedir7(), "AppData", "Local");
92442
+ const roamingAppData = process.env.APPDATA || join8(homedir7(), "AppData", "Roaming");
92443
+ const candidates = p === "win32" ? [join8(localAppData, "Kiro-Cli", "data.sqlite3"), join8(roamingAppData, "kiro-cli", "data.sqlite3")] : p === "darwin" ? [join8(homedir7(), "Library", "Application Support", "kiro-cli", "data.sqlite3")] : [join8(homedir7(), ".local", "share", "kiro-cli", "data.sqlite3")];
92444
92444
  return candidates.find((candidate) => existsSync3(candidate));
92445
92445
  }
92446
92446
  function getKiroCliExternalIdpCredentials() {
@@ -92669,14 +92669,20 @@ function saveKiroCliCredentials(creds) {
92669
92669
  }
92670
92670
  }
92671
92671
  }
92672
- function getKiroCliModelRates() {
92672
+ function runKiroCli(args, timeout) {
92673
+ return new Promise((resolve2, reject) => {
92674
+ execFile3("kiro-cli", args, { encoding: "utf-8", timeout }, (error, stdout) => {
92675
+ if (error)
92676
+ reject(error);
92677
+ else
92678
+ resolve2(stdout);
92679
+ });
92680
+ });
92681
+ }
92682
+ async function getKiroCliModelRates() {
92673
92683
  let raw;
92674
92684
  try {
92675
- raw = execFileSync("kiro-cli", ["chat", "--list-models", "--format", "json"], {
92676
- encoding: "utf-8",
92677
- timeout: 1e4,
92678
- stdio: ["pipe", "pipe", "pipe"]
92679
- });
92685
+ raw = await runKiroCli(["chat", "--list-models", "--format", "json"], 1e4);
92680
92686
  } catch (error) {
92681
92687
  debugLog("models.rates", { source: "kiro-cli", error: formatSafeError(error) });
92682
92688
  return void 0;
@@ -92704,12 +92710,9 @@ function getKiroCliModelRates() {
92704
92710
  return void 0;
92705
92711
  }
92706
92712
  }
92707
- function refreshViaKiroCli() {
92713
+ async function refreshViaKiroCli() {
92708
92714
  try {
92709
- execFileSync("kiro-cli", ["debug", "refresh-auth-token"], {
92710
- timeout: 15e3,
92711
- stdio: ["pipe", "pipe", "pipe"]
92712
- });
92715
+ await runKiroCli(["debug", "refresh-auth-token"], 15e3);
92713
92716
  return getKiroCliCredentials();
92714
92717
  } catch (error) {
92715
92718
  console.warn(`[kiro-core] kiro-cli refresh failed: ${formatSafeError(error)}`);
@@ -92821,14 +92824,14 @@ var init_http = __esm({
92821
92824
  });
92822
92825
 
92823
92826
  // ../kiro-core/dist/kiro-ide.js
92824
- import { existsSync as existsSync4, readFileSync as readFileSync5 } from "node:fs";
92825
- import { homedir as homedir7 } from "node:os";
92826
- import { join as join8 } from "node:path";
92827
+ import { existsSync as existsSync4, readFileSync as readFileSync6 } from "node:fs";
92828
+ import { homedir as homedir8 } from "node:os";
92829
+ import { join as join9 } from "node:path";
92827
92830
  function readKiroIdeToken(allowExpired) {
92828
92831
  try {
92829
92832
  if (!existsSync4(KIRO_IDE_TOKEN_PATH))
92830
92833
  return void 0;
92831
- const tokenData = JSON.parse(readFileSync5(KIRO_IDE_TOKEN_PATH, "utf-8"));
92834
+ const tokenData = JSON.parse(readFileSync6(KIRO_IDE_TOKEN_PATH, "utf-8"));
92832
92835
  if (!tokenData.accessToken || !tokenData.refreshToken)
92833
92836
  return void 0;
92834
92837
  const expiresAt = new Date(tokenData.expiresAt).getTime();
@@ -92838,10 +92841,10 @@ function readKiroIdeToken(allowExpired) {
92838
92841
  let clientId = "";
92839
92842
  let clientSecret = "";
92840
92843
  if (tokenData.clientIdHash) {
92841
- const regPath = join8(SSO_CACHE_DIR, `${tokenData.clientIdHash}.json`);
92844
+ const regPath = join9(SSO_CACHE_DIR, `${tokenData.clientIdHash}.json`);
92842
92845
  if (existsSync4(regPath)) {
92843
92846
  try {
92844
- const reg = JSON.parse(readFileSync5(regPath, "utf-8"));
92847
+ const reg = JSON.parse(readFileSync6(regPath, "utf-8"));
92845
92848
  clientId = reg.clientId ?? "";
92846
92849
  clientSecret = reg.clientSecret ?? "";
92847
92850
  } catch {
@@ -92873,8 +92876,8 @@ var SSO_CACHE_DIR, KIRO_IDE_TOKEN_PATH;
92873
92876
  var init_kiro_ide = __esm({
92874
92877
  "../kiro-core/dist/kiro-ide.js"() {
92875
92878
  "use strict";
92876
- SSO_CACHE_DIR = join8(homedir7(), ".aws", "sso", "cache");
92877
- KIRO_IDE_TOKEN_PATH = join8(SSO_CACHE_DIR, "kiro-auth-token.json");
92879
+ SSO_CACHE_DIR = join9(homedir8(), ".aws", "sso", "cache");
92880
+ KIRO_IDE_TOKEN_PATH = join9(SSO_CACHE_DIR, "kiro-auth-token.json");
92878
92881
  }
92879
92882
  });
92880
92883
 
@@ -96416,12 +96419,16 @@ async function refreshDevinModels(options = {}) {
96416
96419
  return { models: getCachedModels().map(toPiDevinModel), fromCache };
96417
96420
  }
96418
96421
 
96422
+ // ../pi-provider/src/grok/register.ts
96423
+ import { readFileSync as readFileSync5 } from "node:fs";
96424
+ import { homedir as homedir5 } from "node:os";
96425
+ import { join as join6 } from "node:path";
96426
+
96419
96427
  // ../grok-core/dist/catalog.js
96420
96428
  var GROK_BOOTSTRAP_MODEL_IDS = ["grok-4.7", "grok-4.7-build-fast", "grok-4.6", "grok-4.5"];
96421
96429
  var GROK_DEFAULT_CONTEXT_WINDOW = 5e5;
96422
96430
  var GROK_DEFAULT_MAX_TOKENS = 128e3;
96423
96431
  var GROK_CATALOG_PROVIDER_ID = "grok";
96424
- var GROK_DEFAULT_MODEL_ID = "grok-4.5";
96425
96432
  var GROK_CATALOG_FILE = `${GROK_CATALOG_PROVIDER_ID}.models.json`;
96426
96433
  function grokBootstrapModels() {
96427
96434
  return GROK_BOOTSTRAP_MODEL_IDS.map((id) => ({
@@ -96585,13 +96592,13 @@ function getDefaultCatalogCache(options) {
96585
96592
  return defaultCache;
96586
96593
  }
96587
96594
 
96588
- // ../grok-core/dist/agent/binary.js
96595
+ // ../grok-core/dist/cli/binary.js
96589
96596
  import { execFile } from "node:child_process";
96590
96597
  import { accessSync, constants } from "node:fs";
96591
96598
  import { homedir as homedir4 } from "node:os";
96592
96599
  import { join as join4 } from "node:path";
96593
96600
  var CANDIDATE_NAMES = ["agent", "grok"];
96594
- var BINARY_ENV_NAMES = ["GROK_AGENT_BIN", "GROK_BIN", "PI_GROK_SDK_BIN", "PI_GROK_AGENT_BIN"];
96601
+ var BINARY_ENV_NAMES = ["GROK_AGENT_BIN", "GROK_BIN"];
96595
96602
  function isExecutable(path6) {
96596
96603
  try {
96597
96604
  accessSync(path6, constants.X_OK);
@@ -96618,7 +96625,7 @@ async function resolveGrokBinary(env3 = process.env) {
96618
96625
  const explicit = BINARY_ENV_NAMES.map((name) => env3[name]?.trim()).find(Boolean);
96619
96626
  if (explicit) {
96620
96627
  if (!isExecutable(explicit)) {
96621
- throw new Error(`Configured Grok agent binary is not executable: ${explicit}. Check ${BINARY_ENV_NAMES.join(" / ")}.`);
96628
+ throw new Error(`Configured Grok binary is not executable: ${explicit}. Check ${BINARY_ENV_NAMES.join(" / ")}.`);
96622
96629
  }
96623
96630
  return explicit;
96624
96631
  }
@@ -96633,12 +96640,31 @@ async function resolveGrokBinary(env3 = process.env) {
96633
96640
  if (isExecutable(candidate))
96634
96641
  return candidate;
96635
96642
  }
96636
- throw new Error("Grok agent CLI not found. Install/authenticate the xAI Grok agent (`agent` or `grok` on PATH, or ~/.grok/bin). Then run: agent --version");
96643
+ throw new Error("Grok CLI not found. Install/authenticate the xAI Grok CLI (`agent` or `grok` on PATH, or ~/.grok/bin). Then run: agent --version");
96637
96644
  }
96638
96645
 
96639
- // ../grok-core/dist/agent/models.js
96646
+ // ../grok-core/dist/cli/models.js
96640
96647
  import { execFile as execFile2 } from "node:child_process";
96641
- function parseGrokModelsOutput(stdout) {
96648
+ function grokContextWindowsFromCache(raw) {
96649
+ const windows = /* @__PURE__ */ new Map();
96650
+ if (!raw?.trim())
96651
+ return windows;
96652
+ try {
96653
+ const parsed = JSON.parse(raw);
96654
+ const models = parsed?.models;
96655
+ if (!models || typeof models !== "object")
96656
+ return windows;
96657
+ for (const [id, entry] of Object.entries(models)) {
96658
+ const info = entry?.info;
96659
+ const window2 = info?.context_window;
96660
+ if (typeof window2 === "number" && Number.isInteger(window2) && window2 > 0)
96661
+ windows.set(id, window2);
96662
+ }
96663
+ } catch {
96664
+ }
96665
+ return windows;
96666
+ }
96667
+ function parseGrokModelsOutput(stdout, contextWindows) {
96642
96668
  const models = [];
96643
96669
  const seen = /* @__PURE__ */ new Set();
96644
96670
  const bullet = /^\s*[*•-]\s+(\S+)/;
@@ -96649,31 +96675,28 @@ function parseGrokModelsOutput(stdout) {
96649
96675
  const id = m2[1].replace(/[(),]+$/g, "");
96650
96676
  if (!seen.has(id)) {
96651
96677
  seen.add(id);
96652
- models.push({
96653
- id,
96654
- name: id,
96655
- contextWindow: GROK_DEFAULT_CONTEXT_WINDOW,
96656
- maxTokens: GROK_DEFAULT_MAX_TOKENS,
96657
- supportsReasoningEffort: true
96658
- });
96678
+ models.push(describe(id, contextWindows));
96659
96679
  }
96660
96680
  continue;
96661
96681
  }
96662
96682
  const d = line.match(defaultLine);
96663
96683
  if (d && !seen.has(d[1])) {
96664
96684
  seen.add(d[1]);
96665
- models.unshift({
96666
- id: d[1],
96667
- name: d[1],
96668
- contextWindow: GROK_DEFAULT_CONTEXT_WINDOW,
96669
- maxTokens: GROK_DEFAULT_MAX_TOKENS,
96670
- supportsReasoningEffort: true
96671
- });
96685
+ models.unshift(describe(d[1], contextWindows));
96672
96686
  }
96673
96687
  }
96674
96688
  return models;
96675
96689
  }
96676
- async function discoverGrokModels(binary) {
96690
+ function describe(id, contextWindows) {
96691
+ return {
96692
+ id,
96693
+ name: id,
96694
+ contextWindow: contextWindows?.get(id) ?? GROK_DEFAULT_CONTEXT_WINDOW,
96695
+ maxTokens: GROK_DEFAULT_MAX_TOKENS,
96696
+ supportsReasoningEffort: true
96697
+ };
96698
+ }
96699
+ async function discoverGrokModels(binary, contextWindows) {
96677
96700
  try {
96678
96701
  const bin = binary ?? await resolveGrokBinary();
96679
96702
  const stdout = await new Promise((resolve2, reject) => {
@@ -96684,7 +96707,7 @@ async function discoverGrokModels(binary) {
96684
96707
  resolve2(out);
96685
96708
  });
96686
96709
  });
96687
- const parsed = parseGrokModelsOutput(stdout);
96710
+ const parsed = parseGrokModelsOutput(stdout, contextWindows);
96688
96711
  if (parsed.length === 0) {
96689
96712
  return { models: [], source: "fallback", error: "empty model list from CLI" };
96690
96713
  }
@@ -96699,7 +96722,6 @@ async function discoverGrokModels(binary) {
96699
96722
  }
96700
96723
 
96701
96724
  // ../pi-provider/src/grok/config.ts
96702
- var DEFAULT_MODEL_ID = GROK_DEFAULT_MODEL_ID;
96703
96725
  var THINKING_LEVEL_MAP = {
96704
96726
  off: "none",
96705
96727
  minimal: "minimal",
@@ -96722,8 +96744,8 @@ function fallbackModels() {
96722
96744
  supportsReasoningEffort: model.reasoning
96723
96745
  }));
96724
96746
  }
96725
- async function discoverModels(binary) {
96726
- const discovered = await discoverGrokModels(binary);
96747
+ async function discoverModels(binary, contextCache) {
96748
+ const discovered = await discoverGrokModels(binary, grokContextWindowsFromCache(contextCache));
96727
96749
  if (discovered.source === "live") return discovered;
96728
96750
  return { ...discovered, models: fallbackModels() };
96729
96751
  }
@@ -96740,18 +96762,7 @@ function toProviderModel(d) {
96740
96762
  };
96741
96763
  }
96742
96764
  function toProviderModels(descriptors) {
96743
- const models = descriptors.map(toProviderModel);
96744
- const hasDefault = models.some((m2) => m2.id === DEFAULT_MODEL_ID);
96745
- const hasLegacyAlias = models.some((m2) => m2.id === "grok-4.5-agent");
96746
- if (hasDefault && !hasLegacyAlias) {
96747
- const base = models.find((m2) => m2.id === DEFAULT_MODEL_ID);
96748
- models.push({
96749
- ...base,
96750
- id: "grok-4.5-agent",
96751
- name: `${base.name} (legacy alias)`
96752
- });
96753
- }
96754
- return models;
96765
+ return descriptors.map(toProviderModel);
96755
96766
  }
96756
96767
 
96757
96768
  // ../../node_modules/.pnpm/@earendil-works+pi-ai@1.1.0_@aws-sdk+credential-provider-node@3.972.84_@smithy+signatur_b86043277c99936d7a9ffd4d41485846/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.lazy.js
@@ -98586,7 +98597,13 @@ async function refreshGrokModels(options = {}) {
98586
98597
  } catch {
98587
98598
  binary = void 0;
98588
98599
  }
98589
- const discovered = await discoverModels(binary);
98600
+ let contextCache;
98601
+ try {
98602
+ contextCache = readFileSync5(join6(homedir5(), ".grok", "models_cache.json"), "utf8");
98603
+ } catch {
98604
+ contextCache = void 0;
98605
+ }
98606
+ const discovered = await discoverModels(binary, contextCache);
98590
98607
  const catalog = descriptorsToCatalog(discovered.models);
98591
98608
  cache.store(GROK_PROVIDER_ID, catalog, { version: "grok-cli-v1" });
98592
98609
  return {
@@ -98689,9 +98706,9 @@ async function resolveKiroRequestCredentials(hostKey) {
98689
98706
 
98690
98707
  // ../kiro-core/dist/models.js
98691
98708
  import { randomUUID as randomUUID3 } from "node:crypto";
98692
- import { existsSync as existsSync5, readFileSync as readFileSync6, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "node:fs";
98693
- import { homedir as homedir8 } from "node:os";
98694
- import { join as join9 } from "node:path";
98709
+ import { existsSync as existsSync5, readFileSync as readFileSync7, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "node:fs";
98710
+ import { homedir as homedir9 } from "node:os";
98711
+ import { join as join10 } from "node:path";
98695
98712
 
98696
98713
  // ../kiro-core/dist/types.js
98697
98714
  var KIRO_EFFORT_ORDER = ["minimal", "low", "medium", "high", "xhigh", "max"];
@@ -98759,7 +98776,7 @@ function getKiroEffortConfig(schema, kiroModelId) {
98759
98776
  init_endpoints();
98760
98777
  var KIRO_MANAGEMENT_CACHE_VERSION = 1;
98761
98778
  var KIRO_MANAGEMENT_CACHE_SOURCE = "ns-kiro-provider-management";
98762
- var KIRO_MANAGEMENT_CACHE_PATH = join9(homedir8(), ".ns-kiro-provider-models-cache.json");
98779
+ var KIRO_MANAGEMENT_CACHE_PATH = join10(homedir9(), ".ns-kiro-provider-models-cache.json");
98763
98780
  var CACHE_MAX_AGE_MS = 36e5;
98764
98781
  var DEFAULT_CONTEXT_WINDOW3 = 2e5;
98765
98782
  var DEFAULT_MAX_TOKENS3 = 8192;
@@ -99032,7 +99049,7 @@ function readManagementCache() {
99032
99049
  if (!existsSync5(KIRO_MANAGEMENT_CACHE_PATH))
99033
99050
  return void 0;
99034
99051
  try {
99035
- return parseManagementCache(readFileSync6(KIRO_MANAGEMENT_CACHE_PATH, "utf-8"));
99052
+ return parseManagementCache(readFileSync7(KIRO_MANAGEMENT_CACHE_PATH, "utf-8"));
99036
99053
  } catch {
99037
99054
  return void 0;
99038
99055
  }
@@ -99164,7 +99181,7 @@ async function updateKiroModelsCache(accessToken, region, profileArn) {
99164
99181
  const { fetchKiroModelCatalog: fetchKiroModelCatalog2 } = await Promise.resolve().then(() => (init_management(), management_exports));
99165
99182
  const { getKiroCliModelRates: getKiroCliModelRates2 } = await Promise.resolve().then(() => (init_kiro_cli(), kiro_cli_exports));
99166
99183
  const response = await fetchKiroModelCatalog2({ accessToken, region }, profileArn);
99167
- const models = mapKiroCatalogModels(response.models, region, getKiroCliModelRates2());
99184
+ const models = mapKiroCatalogModels(response.models, region, await getKiroCliModelRates2());
99168
99185
  const cache = readManagementCache() ?? {
99169
99186
  version: KIRO_MANAGEMENT_CACHE_VERSION,
99170
99187
  source: KIRO_MANAGEMENT_CACHE_SOURCE,
@@ -99236,10 +99253,10 @@ init_oauth();
99236
99253
  init_token_type();
99237
99254
 
99238
99255
  // ../kiro-core/dist/transport.js
99239
- import { homedir as homedir9 } from "node:os";
99240
- import { join as join10 } from "node:path";
99241
- var CAPACITY_LOG_DIR = join10(homedir9(), ".ns-kiro-provider", "logs");
99242
- var CAPACITY_LOG_FILE = join10(CAPACITY_LOG_DIR, "capacity-retries.log");
99256
+ import { homedir as homedir10 } from "node:os";
99257
+ import { join as join11 } from "node:path";
99258
+ var CAPACITY_LOG_DIR = join11(homedir10(), ".ns-kiro-provider", "logs");
99259
+ var CAPACITY_LOG_FILE = join11(CAPACITY_LOG_DIR, "capacity-retries.log");
99243
99260
 
99244
99261
  // ../kiro-core/dist/usage-tracking.js
99245
99262
  var DEFAULT_USD_PER_CREDIT = 0.04;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngosangns/ns-bridge",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Install, update, and refresh ns-bridge providers outside Pi, OMP, and DSH.",
5
5
  "type": "module",
6
6
  "license": "MIT",