ns-omp-provider 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0
4
+
5
+ Bundles `@ngosangns/ns-pi-provider@0.4.0`.
6
+
7
+ - Kiro and Devin calls run in the Go `ns-bridge` sidecar when a binary is installed, and
8
+ in-process otherwise (see the Pi adapter's changelog); `NS_BRIDGE_ENGINE=ts` opts out.
9
+
3
10
  ## 0.4.0
4
11
 
5
12
  Bundles `@ngosangns/ns-pi-provider@0.3.0`.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // ns-omp-provider 0.4.0 — bundles @ngosangns/ns-pi-provider@0.3.0 (MIT). See NOTICE.
1
+ // ns-omp-provider 0.6.0 — bundles @ngosangns/ns-pi-provider@0.5.0 (MIT). See NOTICE.
2
2
  import { createRequire as __nsOmpCreateRequire } from 'node:module';
3
3
  const require = __nsOmpCreateRequire(import.meta.url);
4
4
  var __create = Object.create;
@@ -240,11 +240,18 @@ function resolveApiRegion(ssoRegion) {
240
240
  return "us-east-1";
241
241
  return API_REGION_MAP[ssoRegion] ?? ssoRegion;
242
242
  }
243
+ function endpointOverride(name, region) {
244
+ const value = process.env[name]?.trim();
245
+ if (!value)
246
+ return void 0;
247
+ const url = value.replaceAll("{region}", region);
248
+ return url.endsWith("/") ? url : `${url}/`;
249
+ }
243
250
  function getKiroEndpoints(region) {
244
251
  return {
245
252
  region,
246
- management: `https://management.${region}.kiro.dev/`,
247
- runtime: `https://runtime.${region}.kiro.dev/`
253
+ management: endpointOverride(KIRO_MANAGEMENT_ENDPOINT_ENV, region) ?? `https://management.${region}.kiro.dev/`,
254
+ runtime: endpointOverride(KIRO_RUNTIME_ENDPOINT_ENV, region) ?? `https://runtime.${region}.kiro.dev/`
248
255
  };
249
256
  }
250
257
  function getKiroRegionFromProfileArn(profileArn) {
@@ -264,7 +271,7 @@ function getKiroRegionFromEndpoint(endpoint) {
264
271
  return void 0;
265
272
  }
266
273
  }
267
- var API_REGION_MAP;
274
+ var API_REGION_MAP, KIRO_RUNTIME_ENDPOINT_ENV, KIRO_MANAGEMENT_ENDPOINT_ENV;
268
275
  var init_endpoints = __esm({
269
276
  "../kiro-core/dist/endpoints.js"() {
270
277
  "use strict";
@@ -286,6 +293,8 @@ var init_endpoints = __esm({
286
293
  "eu-south-2": "eu-central-1",
287
294
  "eu-central-2": "eu-central-1"
288
295
  };
296
+ KIRO_RUNTIME_ENDPOINT_ENV = "KIRO_RUNTIME_ENDPOINT";
297
+ KIRO_MANAGEMENT_ENDPOINT_ENV = "KIRO_MANAGEMENT_ENDPOINT";
289
298
  }
290
299
  });
291
300
 
@@ -688,23 +697,28 @@ function kiroAuthHeaders(token) {
688
697
  function isApiKey(token) {
689
698
  return token.startsWith("ksk_");
690
699
  }
700
+ async function fetchApiKeyGetProfile(accessToken) {
701
+ try {
702
+ return await fetch(getKiroEndpoints(API_KEY_REGION).management, {
703
+ method: "POST",
704
+ headers: {
705
+ "Content-Type": "application/x-amz-json-1.0",
706
+ "X-Amz-Target": "AmazonCodeWhispererService.GetProfile",
707
+ ...kiroAuthHeaders(accessToken),
708
+ ...kiroUserAgent("codewhispererruntime", "F,C")
709
+ },
710
+ body: "{}"
711
+ });
712
+ } catch (error2) {
713
+ throw new Error(`Kiro management GetProfile request failed in ${API_KEY_REGION}`, { cause: error2 });
714
+ }
715
+ }
691
716
  async function loginKiroWithApiKey(apiKey, onProgress) {
692
717
  if (!apiKey.startsWith("ksk_")) {
693
718
  throw new Error("Invalid API key format. Kiro API keys start with 'ksk_'.");
694
719
  }
695
720
  onProgress?.("Validating API key...");
696
- const region = "us-east-1";
697
- const managementUrl = `https://management.${resolveApiRegion(region)}.kiro.dev/`;
698
- const response = await fetch(managementUrl, {
699
- method: "POST",
700
- headers: {
701
- "Content-Type": "application/x-amz-json-1.0",
702
- "X-Amz-Target": "AmazonCodeWhispererService.GetProfile",
703
- ...kiroAuthHeaders(apiKey),
704
- ...kiroUserAgent("codewhispererruntime", "F,C")
705
- },
706
- body: "{}"
707
- });
721
+ const response = await fetchApiKeyGetProfile(apiKey);
708
722
  if (!response.ok) {
709
723
  let detail = "";
710
724
  try {
@@ -725,7 +739,7 @@ async function loginKiroWithApiKey(apiKey, onProgress) {
725
739
  expires: Date.now() + 365 * 24 * 60 * 60 * 1e3,
726
740
  clientId: "",
727
741
  clientSecret: "",
728
- region,
742
+ region: API_KEY_REGION,
729
743
  authMethod: "apikey",
730
744
  ...profileArn ? { profileArn } : {}
731
745
  };
@@ -796,6 +810,12 @@ async function refreshKiroTokenInternal(credentials) {
796
810
  }
797
811
  }
798
812
  async function refreshKiroTokenDirect(credentials) {
813
+ return refreshKiroTokenDirectInProcess(credentials);
814
+ }
815
+ function endpointFromEnv(name, fallback, region) {
816
+ return (process.env[name]?.trim() || fallback).replaceAll("{region}", region);
817
+ }
818
+ async function refreshKiroTokenDirectInProcess(credentials) {
799
819
  const parts = credentials.refresh.split("|");
800
820
  const refreshToken = parts[0] ?? "";
801
821
  const authMethod = parts[parts.length - 1] ?? "idc";
@@ -803,7 +823,7 @@ async function refreshKiroTokenDirect(credentials) {
803
823
  if (authMethod === "apikey")
804
824
  return credentials;
805
825
  if (authMethod === "desktop") {
806
- const url = KIRO_DESKTOP_REFRESH_URL.replace("{region}", region);
826
+ const url = endpointFromEnv(KIRO_DESKTOP_REFRESH_ENDPOINT_ENV, KIRO_DESKTOP_REFRESH_URL, region);
807
827
  const response2 = await fetch(url, {
808
828
  method: "POST",
809
829
  headers: { "Content-Type": "application/json", "User-Agent": KIRO_DESKTOP_USER_AGENT },
@@ -863,7 +883,7 @@ async function refreshKiroTokenDirect(credentials) {
863
883
  }
864
884
  const clientId = parts[1] ?? "";
865
885
  const clientSecret = parts[2] ?? "";
866
- const ssoEndpoint = `https://oidc.${region}.amazonaws.com`;
886
+ const ssoEndpoint = endpointFromEnv(KIRO_OIDC_ENDPOINT_ENV, "https://oidc.{region}.amazonaws.com", region);
867
887
  const response = await fetch(`${ssoEndpoint}/token`, {
868
888
  method: "POST",
869
889
  headers: { "Content-Type": "application/json", ...kiroUserAgent("ssooidc", "E") },
@@ -911,7 +931,7 @@ async function resolveKiroCredentials() {
911
931
  throw lastFailure;
912
932
  return void 0;
913
933
  }
914
- var KIRO_DESKTOP_REFRESH_URL, EXPIRES_BUFFER_MS, KIRO_DESKTOP_USER_AGENT, AUTH_SOURCE_ENV;
934
+ var KIRO_DESKTOP_REFRESH_URL, EXPIRES_BUFFER_MS, KIRO_DESKTOP_USER_AGENT, AUTH_SOURCE_ENV, API_KEY_REGION, KIRO_DESKTOP_REFRESH_ENDPOINT_ENV, KIRO_OIDC_ENDPOINT_ENV;
915
935
  var init_oauth = __esm({
916
936
  "../kiro-core/dist/oauth.js"() {
917
937
  "use strict";
@@ -922,6 +942,9 @@ var init_oauth = __esm({
922
942
  EXPIRES_BUFFER_MS = 5 * 60 * 1e3;
923
943
  KIRO_DESKTOP_USER_AGENT = "Kiro-Desktop/0.2.13 (darwin; arm64)";
924
944
  AUTH_SOURCE_ENV = "KIRO_AUTH_SOURCE";
945
+ API_KEY_REGION = "us-east-1";
946
+ KIRO_DESKTOP_REFRESH_ENDPOINT_ENV = "KIRO_DESKTOP_REFRESH_ENDPOINT";
947
+ KIRO_OIDC_ENDPOINT_ENV = "KIRO_OIDC_ENDPOINT";
925
948
  }
926
949
  });
927
950
 
@@ -1004,25 +1027,11 @@ function profileCacheKey(auth) {
1004
1027
  }
1005
1028
  async function getApiKeyProfileArn(accessToken) {
1006
1029
  const operation = "GetProfile";
1007
- let response;
1008
- try {
1009
- response = await fetch(getKiroEndpoints(API_KEY_REGION).management, {
1010
- method: "POST",
1011
- headers: {
1012
- "Content-Type": "application/x-amz-json-1.0",
1013
- "X-Amz-Target": GET_PROFILE_TARGET,
1014
- ...kiroAuthHeaders(accessToken),
1015
- ...kiroUserAgent("codewhispererruntime", "F,C")
1016
- },
1017
- body: "{}"
1018
- });
1019
- } catch (error2) {
1020
- throw new Error(`Kiro management ${operation} request failed in ${API_KEY_REGION}`, { cause: error2 });
1021
- }
1022
- const parsed = await parseManagementResponse(response, operation, API_KEY_REGION);
1030
+ const response = await fetchApiKeyGetProfile(accessToken);
1031
+ const parsed = await parseManagementResponse(response, operation, API_KEY_REGION2);
1023
1032
  const arn = parsed.profile?.arn;
1024
1033
  if (!arn) {
1025
- throw new Error(`Kiro management ${operation} returned no profile in ${API_KEY_REGION}`);
1034
+ throw new Error(`Kiro management ${operation} returned no profile in ${API_KEY_REGION2}`);
1026
1035
  }
1027
1036
  return arn;
1028
1037
  }
@@ -1064,8 +1073,8 @@ async function resolveKiroProfileArn(auth, providedArn) {
1064
1073
  if (isApiKey(auth.accessToken)) {
1065
1074
  const arn = await getApiKeyProfileArn(auth.accessToken);
1066
1075
  profileArnCache.set(key, arn);
1067
- profileRegionCache.set(key, API_KEY_REGION);
1068
- debugLog("profile.resolve", { source: "api-key", region: API_KEY_REGION, arn });
1076
+ profileRegionCache.set(key, API_KEY_REGION2);
1077
+ debugLog("profile.resolve", { source: "api-key", region: API_KEY_REGION2, arn });
1069
1078
  return arn;
1070
1079
  }
1071
1080
  let lastResponse;
@@ -1118,13 +1127,13 @@ async function listAvailableModels(auth, profileArn) {
1118
1127
  }
1119
1128
  async function fetchKiroModelCatalog(auth, providedProfileArn) {
1120
1129
  const profileArn = await resolveKiroProfileArn(auth, providedProfileArn);
1121
- const region = isApiKey(auth.accessToken) ? API_KEY_REGION : profileRegionCache.get(profileCacheKey(auth)) ?? auth.region;
1130
+ const region = isApiKey(auth.accessToken) ? API_KEY_REGION2 : profileRegionCache.get(profileCacheKey(auth)) ?? auth.region;
1122
1131
  if (region !== auth.region) {
1123
1132
  return listAvailableModels({ ...auth, region }, profileArn);
1124
1133
  }
1125
1134
  return listAvailableModels(auth, profileArn);
1126
1135
  }
1127
- var LIST_PROFILES_PATH, LIST_MODELS_PATH, GET_PROFILE_TARGET, API_KEY_REGION, profileArnCache, pendingProfileRequests, profileRegionCache, CANONICAL_MANAGEMENT_REGIONS, ENV_PROFILE_ARN, KiroManagementHttpError;
1136
+ var LIST_PROFILES_PATH, LIST_MODELS_PATH, API_KEY_REGION2, profileArnCache, pendingProfileRequests, profileRegionCache, CANONICAL_MANAGEMENT_REGIONS, ENV_PROFILE_ARN, KiroManagementHttpError;
1128
1137
  var init_management = __esm({
1129
1138
  "../kiro-core/dist/management.js"() {
1130
1139
  "use strict";
@@ -1134,8 +1143,7 @@ var init_management = __esm({
1134
1143
  init_token_type();
1135
1144
  LIST_PROFILES_PATH = "List-Available-Profiles";
1136
1145
  LIST_MODELS_PATH = "List-Available-Models";
1137
- GET_PROFILE_TARGET = "AmazonCodeWhispererService.GetProfile";
1138
- API_KEY_REGION = "us-east-1";
1146
+ API_KEY_REGION2 = "us-east-1";
1139
1147
  profileArnCache = /* @__PURE__ */ new Map();
1140
1148
  pendingProfileRequests = /* @__PURE__ */ new Map();
1141
1149
  profileRegionCache = /* @__PURE__ */ new Map();
@@ -1167,7 +1175,8 @@ __export(models_exports, {
1167
1175
  mapKiroCatalogModels: () => mapKiroCatalogModels,
1168
1176
  resolveApiRegion: () => resolveApiRegion,
1169
1177
  resolveKiroModel: () => resolveKiroModel,
1170
- updateKiroModelsCache: () => updateKiroModelsCache
1178
+ updateKiroModelsCache: () => updateKiroModelsCache,
1179
+ updateKiroModelsCacheInProcess: () => updateKiroModelsCacheInProcess
1171
1180
  });
1172
1181
  import { randomUUID } from "node:crypto";
1173
1182
  import { existsSync as existsSync3, readFileSync as readFileSync2, renameSync, rmSync, writeFileSync } from "node:fs";
@@ -1359,6 +1368,10 @@ function isCacheStale(region) {
1359
1368
  return !entry || Date.now() - entry.fetchedAt > CACHE_MAX_AGE_MS;
1360
1369
  }
1361
1370
  async function updateKiroModelsCache(accessToken, region, profileArn) {
1371
+ await updateKiroModelsCacheInProcess(accessToken, region, profileArn);
1372
+ refreshKnownModelIds(readManagementCache());
1373
+ }
1374
+ async function updateKiroModelsCacheInProcess(accessToken, region, profileArn) {
1362
1375
  const response = await fetchKiroModelCatalog({ accessToken, region }, profileArn);
1363
1376
  const models = mapKiroCatalogModels(response.models, region, getKiroCliModelRates());
1364
1377
  const cache = readManagementCache() ?? {
@@ -5522,6 +5535,9 @@ function throwOnTerminalWireStop(wireStopReason, stopDetails) {
5522
5535
  }
5523
5536
  }
5524
5537
  async function* streamKiro(request) {
5538
+ yield* streamKiroInProcess(request);
5539
+ }
5540
+ async function* streamKiroInProcess(request) {
5525
5541
  const { model, signal } = request;
5526
5542
  const initialAccessToken = request.accessToken;
5527
5543
  if (!initialAccessToken) {
@@ -9086,7 +9102,10 @@ function calculateDevinCost(cost, usage) {
9086
9102
  const cacheWrite = per(usage.cacheWrite, cost.cacheWrite);
9087
9103
  return { input, output, cacheRead, cacheWrite, total: input + output + cacheRead + cacheWrite };
9088
9104
  }
9089
- async function* streamDevin(request) {
9105
+ function streamDevin(request) {
9106
+ return streamDevinInProcess(request);
9107
+ }
9108
+ async function* streamDevinInProcess(request) {
9090
9109
  const model = request.model;
9091
9110
  const fetchImpl = request.fetch ?? fetch;
9092
9111
  const baseUrl = (model.baseUrl || DEVIN_DEFAULT_BASE_URL).replace(/\/+$/, "");
@@ -9288,7 +9307,7 @@ async function* streamDevin(request) {
9288
9307
  };
9289
9308
  const totalTokens = usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
9290
9309
  const credits = msg.creditCost || msg.committedCreditCost || msg.committedAcuCost;
9291
- const moved = responseUsage === void 0 ? totalTokens > 0 || credits !== 0 : totalTokens !== responseUsage.totalTokens || credits !== responseUsage.credits;
9310
+ const moved = responseUsage === void 0 ? totalTokens > 0 || credits !== 0 : totalTokens !== responseUsage.totalTokens || credits !== (responseUsage.credits ?? 0);
9292
9311
  if (!moved)
9293
9312
  continue;
9294
9313
  responseUsage = {
@@ -9693,6 +9712,9 @@ function collectDevinFamilyLane(lanes, config, uid) {
9693
9712
  }
9694
9713
  }
9695
9714
  async function fetchDevinModels(options) {
9715
+ return fetchDevinModelsInProcess(options);
9716
+ }
9717
+ async function fetchDevinModelsInProcess(options) {
9696
9718
  const timeoutMs = options.timeoutMs ?? 5e3;
9697
9719
  const resolvedBaseUrl = (options.baseUrl ?? DEVIN_DEFAULT_BASE_URL).replace(/\/+$/, "");
9698
9720
  const fetchImpl = options.fetch ?? fetch;
@@ -10085,6 +10107,9 @@ function buildDevinUsageReport(response) {
10085
10107
  };
10086
10108
  }
10087
10109
  async function fetchDevinUsage(options) {
10110
+ return fetchDevinUsageInProcess(options);
10111
+ }
10112
+ async function fetchDevinUsageInProcess(options) {
10088
10113
  const token = options.apiKey?.trim();
10089
10114
  if (!token)
10090
10115
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ns-omp-provider",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "OMP (oh-my-pi) plugin: Kiro, Devin, and Grok providers from @ngosangns/ns-pi-provider, wrapped for OMP's provider/extension API.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -63,12 +63,12 @@
63
63
  }
64
64
  },
65
65
  "devDependencies": {
66
- "@ngosangns/ns-pi-provider": "0.3.0",
66
+ "@ngosangns/ns-pi-provider": "0.5.0",
67
67
  "@types/node": "^22.18.6",
68
68
  "esbuild": "^0.28.2",
69
69
  "typescript": "^5.9.2",
70
70
  "vitest": "^3.2.4",
71
- "ns-bridge-core": "0.1.0"
71
+ "ns-bridge-core": "0.3.0"
72
72
  },
73
73
  "publishConfig": {
74
74
  "access": "public",