@ngosangns/ns-bridge 0.1.5 → 0.1.7

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.
Files changed (2) hide show
  1. package/dist/refresh-entry.js +533 -519
  2. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- // @ngosangns/ns-bridge 0.1.5 — catalog refresh bundle.
1
+ // @ngosangns/ns-bridge 0.1.7 — 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;
@@ -815,14 +815,14 @@ function createProvider(input) {
815
815
  return merged;
816
816
  };
817
817
  const apiFor = (model) => single ?? byApi?.[model.api];
818
- const dispatch = (model, run) => {
818
+ const dispatch = (model, run2) => {
819
819
  const streams2 = apiFor(model);
820
820
  if (!streams2) {
821
821
  return lazyStream(model, async () => {
822
822
  throw new ModelsError("stream", `Provider ${input.id} has no API implementation for "${model.api}"`);
823
823
  });
824
824
  }
825
- return run(streams2);
825
+ return run2(streams2);
826
826
  };
827
827
  const provider = {
828
828
  id: input.id,
@@ -1820,21 +1820,21 @@ var init_uuid = __esm({
1820
1820
  });
1821
1821
 
1822
1822
  // ../../node_modules/.pnpm/@anthropic-ai+sdk@0.129.0_zod@4.5.4/node_modules/@anthropic-ai/sdk/internal/tslib.mjs
1823
- function __classPrivateFieldSet(receiver, state3, value, kind, f3) {
1823
+ function __classPrivateFieldSet(receiver, state2, value, kind, f3) {
1824
1824
  if (kind === "m")
1825
1825
  throw new TypeError("Private method is not writable");
1826
1826
  if (kind === "a" && !f3)
1827
1827
  throw new TypeError("Private accessor was defined without a setter");
1828
- if (typeof state3 === "function" ? receiver !== state3 || !f3 : !state3.has(receiver))
1828
+ if (typeof state2 === "function" ? receiver !== state2 || !f3 : !state2.has(receiver))
1829
1829
  throw new TypeError("Cannot write private member to an object whose class did not declare it");
1830
- return kind === "a" ? f3.call(receiver, value) : f3 ? f3.value = value : state3.set(receiver, value), value;
1830
+ return kind === "a" ? f3.call(receiver, value) : f3 ? f3.value = value : state2.set(receiver, value), value;
1831
1831
  }
1832
- function __classPrivateFieldGet(receiver, state3, kind, f3) {
1832
+ function __classPrivateFieldGet(receiver, state2, kind, f3) {
1833
1833
  if (kind === "a" && !f3)
1834
1834
  throw new TypeError("Private accessor was defined without a getter");
1835
- if (typeof state3 === "function" ? receiver !== state3 || !f3 : !state3.has(receiver))
1835
+ if (typeof state2 === "function" ? receiver !== state2 || !f3 : !state2.has(receiver))
1836
1836
  throw new TypeError("Cannot read private member from an object whose class did not declare it");
1837
- return kind === "m" ? f3 : kind === "a" ? f3.call(receiver) : f3 ? f3.value : state3.get(receiver);
1837
+ return kind === "m" ? f3 : kind === "a" ? f3.call(receiver) : f3 ? f3.value : state2.get(receiver);
1838
1838
  }
1839
1839
  var init_tslib = __esm({
1840
1840
  "../../node_modules/.pnpm/@anthropic-ai+sdk@0.129.0_zod@4.5.4/node_modules/@anthropic-ai/sdk/internal/tslib.mjs"() {
@@ -13110,7 +13110,7 @@ var init_BetaToolRunner = __esm({
13110
13110
  }
13111
13111
  let definition = change.tool;
13112
13112
  if ("run" in change.tool) {
13113
- const { run, parse, close, ...rest } = change.tool;
13113
+ const { run: run2, parse, close, ...rest } = change.tool;
13114
13114
  definition = rest;
13115
13115
  }
13116
13116
  content.push({ type: "tool_addition", tool: { type: "tool_definition", definition } });
@@ -19850,25 +19850,25 @@ function getAnthropicFederation(model, apiKey, headers, env3) {
19850
19850
  }
19851
19851
  };
19852
19852
  }
19853
- function flushSseEvent(state3) {
19854
- if (!state3.event && state3.data.length === 0) {
19853
+ function flushSseEvent(state2) {
19854
+ if (!state2.event && state2.data.length === 0) {
19855
19855
  return null;
19856
19856
  }
19857
19857
  const event = {
19858
- event: state3.event,
19859
- data: state3.data.join("\n"),
19860
- raw: [...state3.raw]
19858
+ event: state2.event,
19859
+ data: state2.data.join("\n"),
19860
+ raw: [...state2.raw]
19861
19861
  };
19862
- state3.event = null;
19863
- state3.data = [];
19864
- state3.raw = [];
19862
+ state2.event = null;
19863
+ state2.data = [];
19864
+ state2.raw = [];
19865
19865
  return event;
19866
19866
  }
19867
- function decodeSseLine(line, state3) {
19867
+ function decodeSseLine(line, state2) {
19868
19868
  if (line === "") {
19869
- return flushSseEvent(state3);
19869
+ return flushSseEvent(state2);
19870
19870
  }
19871
- state3.raw.push(line);
19871
+ state2.raw.push(line);
19872
19872
  if (line.startsWith(":")) {
19873
19873
  return null;
19874
19874
  }
@@ -19879,9 +19879,9 @@ function decodeSseLine(line, state3) {
19879
19879
  value = value.slice(1);
19880
19880
  }
19881
19881
  if (fieldName === "event") {
19882
- state3.event = value;
19882
+ state2.event = value;
19883
19883
  } else if (fieldName === "data") {
19884
- state3.data.push(value);
19884
+ state2.data.push(value);
19885
19885
  }
19886
19886
  return null;
19887
19887
  }
@@ -19913,7 +19913,7 @@ function consumeLine(text) {
19913
19913
  async function* iterateSseMessages(body, signal) {
19914
19914
  const reader = body.getReader();
19915
19915
  const decoder = new TextDecoder();
19916
- const state3 = { event: null, data: [], raw: [] };
19916
+ const state2 = { event: null, data: [], raw: [] };
19917
19917
  let buffer = "";
19918
19918
  try {
19919
19919
  while (true) {
@@ -19928,7 +19928,7 @@ async function* iterateSseMessages(body, signal) {
19928
19928
  let consumed2 = consumeLine(buffer);
19929
19929
  while (consumed2) {
19930
19930
  buffer = consumed2.rest;
19931
- const event = decodeSseLine(consumed2.line, state3);
19931
+ const event = decodeSseLine(consumed2.line, state2);
19932
19932
  if (event) {
19933
19933
  yield event;
19934
19934
  }
@@ -19939,19 +19939,19 @@ async function* iterateSseMessages(body, signal) {
19939
19939
  let consumed = consumeLine(buffer);
19940
19940
  while (consumed) {
19941
19941
  buffer = consumed.rest;
19942
- const event = decodeSseLine(consumed.line, state3);
19942
+ const event = decodeSseLine(consumed.line, state2);
19943
19943
  if (event) {
19944
19944
  yield event;
19945
19945
  }
19946
19946
  consumed = consumeLine(buffer);
19947
19947
  }
19948
19948
  if (buffer.length > 0) {
19949
- const event = decodeSseLine(buffer, state3);
19949
+ const event = decodeSseLine(buffer, state2);
19950
19950
  if (event) {
19951
19951
  yield event;
19952
19952
  }
19953
19953
  }
19954
- const trailingEvent = flushSseEvent(state3);
19954
+ const trailingEvent = flushSseEvent(state2);
19955
19955
  if (trailingEvent) {
19956
19956
  yield trailingEvent;
19957
19957
  }
@@ -20883,21 +20883,21 @@ var init_anthropic_messages = __esm({
20883
20883
  });
20884
20884
 
20885
20885
  // ../../node_modules/.pnpm/openai@7.19.0_@aws-sdk+credential-provider-node@3.972.84_@smithy+signature-v4@5.7.4_undici@8.10.2_ws@8.21.3_zod@4.5.4/node_modules/openai/internal/tslib.mjs
20886
- function __classPrivateFieldSet2(receiver, state3, value, kind, f3) {
20886
+ function __classPrivateFieldSet2(receiver, state2, value, kind, f3) {
20887
20887
  if (kind === "m")
20888
20888
  throw new TypeError("Private method is not writable");
20889
20889
  if (kind === "a" && !f3)
20890
20890
  throw new TypeError("Private accessor was defined without a setter");
20891
- if (typeof state3 === "function" ? receiver !== state3 || !f3 : !state3.has(receiver))
20891
+ if (typeof state2 === "function" ? receiver !== state2 || !f3 : !state2.has(receiver))
20892
20892
  throw new TypeError("Cannot write private member to an object whose class did not declare it");
20893
- return kind === "a" ? f3.call(receiver, value) : f3 ? f3.value = value : state3.set(receiver, value), value;
20893
+ return kind === "a" ? f3.call(receiver, value) : f3 ? f3.value = value : state2.set(receiver, value), value;
20894
20894
  }
20895
- function __classPrivateFieldGet2(receiver, state3, kind, f3) {
20895
+ function __classPrivateFieldGet2(receiver, state2, kind, f3) {
20896
20896
  if (kind === "a" && !f3)
20897
20897
  throw new TypeError("Private accessor was defined without a getter");
20898
- if (typeof state3 === "function" ? receiver !== state3 || !f3 : !state3.has(receiver))
20898
+ if (typeof state2 === "function" ? receiver !== state2 || !f3 : !state2.has(receiver))
20899
20899
  throw new TypeError("Cannot read private member from an object whose class did not declare it");
20900
- return kind === "m" ? f3 : kind === "a" ? f3.call(receiver) : f3 ? f3.value : state3.get(receiver);
20900
+ return kind === "m" ? f3 : kind === "a" ? f3.call(receiver) : f3 ? f3.value : state2.get(receiver);
20901
20901
  }
20902
20902
  var init_tslib2 = __esm({
20903
20903
  "../../node_modules/.pnpm/openai@7.19.0_@aws-sdk+credential-provider-node@3.972.84_@smithy+signature-v4@5.7.4_undici@8.10.2_ws@8.21.3_zod@4.5.4/node_modules/openai/internal/tslib.mjs"() {
@@ -27398,18 +27398,18 @@ function createPartialJSONParseState() {
27398
27398
  pending_high_surrogate: false
27399
27399
  };
27400
27400
  }
27401
- function recordPartialJSONFragment(state3, budget, fragment, validationWorkBudget) {
27401
+ function recordPartialJSONFragment(state2, budget, fragment, validationWorkBudget) {
27402
27402
  if (budget.fragments >= MAX_PARTIAL_JSON_FRAGMENTS) {
27403
27403
  throw new OpenAIError("Chat completion stream exceeded its structured JSON fragment limit");
27404
27404
  }
27405
27405
  let bytes = 0;
27406
- let { depth, escaped, has_non_whitespace: hasNonWhitespace, in_string: inString } = state3;
27406
+ let { depth, escaped, has_non_whitespace: hasNonWhitespace, in_string: inString } = state2;
27407
27407
  let completed = false;
27408
27408
  let firstCharacter = true;
27409
27409
  for (const character of fragment) {
27410
27410
  const previousBytes = bytes;
27411
27411
  const codePoint = character.codePointAt(0);
27412
- if (firstCharacter && state3.pending_high_surrogate && codePoint >= 56320 && codePoint <= 57343) {
27412
+ if (firstCharacter && state2.pending_high_surrogate && codePoint >= 56320 && codePoint <= 57343) {
27413
27413
  bytes += 1;
27414
27414
  } else if (codePoint <= 127) {
27415
27415
  bytes += 1;
@@ -27454,15 +27454,15 @@ function recordPartialJSONFragment(state3, budget, fragment, validationWorkBudge
27454
27454
  completed || (completed = depth === 0);
27455
27455
  }
27456
27456
  }
27457
- state3.bytes += bytes;
27458
- state3.fragments += 1;
27459
- state3.depth = depth;
27460
- state3.escaped = escaped;
27461
- state3.has_non_whitespace = hasNonWhitespace;
27462
- state3.in_string = inString;
27457
+ state2.bytes += bytes;
27458
+ state2.fragments += 1;
27459
+ state2.depth = depth;
27460
+ state2.escaped = escaped;
27461
+ state2.has_non_whitespace = hasNonWhitespace;
27462
+ state2.in_string = inString;
27463
27463
  if (fragment.length > 0) {
27464
27464
  const finalCodeUnit = fragment.codePointAt(fragment.length - 1) ?? 0;
27465
- state3.pending_high_surrogate = finalCodeUnit >= 55296 && finalCodeUnit <= 56319;
27465
+ state2.pending_high_surrogate = finalCodeUnit >= 55296 && finalCodeUnit <= 56319;
27466
27466
  }
27467
27467
  budget.bytes += bytes;
27468
27468
  budget.fragments += 1;
@@ -27472,19 +27472,19 @@ function recordPartialJSONFragment(state3, budget, fragment, validationWorkBudge
27472
27472
  if (!hasNonWhitespace || bytes === 0) {
27473
27473
  return false;
27474
27474
  }
27475
- const minimumGrowth = Math.max(EAGER_PARTIAL_JSON_BYTES, Math.floor(state3.last_parsed_bytes / 2));
27476
- if (state3.bytes > EAGER_PARTIAL_JSON_BYTES && !completed && state3.bytes - state3.last_parsed_bytes < minimumGrowth) {
27475
+ const minimumGrowth = Math.max(EAGER_PARTIAL_JSON_BYTES, Math.floor(state2.last_parsed_bytes / 2));
27476
+ if (state2.bytes > EAGER_PARTIAL_JSON_BYTES && !completed && state2.bytes - state2.last_parsed_bytes < minimumGrowth) {
27477
27477
  return false;
27478
27478
  }
27479
27479
  return true;
27480
27480
  }
27481
- function reservePartialJSONParse(state3, budget) {
27482
- if (budget.work + state3.bytes > MAX_PARTIAL_JSON_PARSE_WORK) {
27481
+ function reservePartialJSONParse(state2, budget) {
27482
+ if (budget.work + state2.bytes > MAX_PARTIAL_JSON_PARSE_WORK) {
27483
27483
  return false;
27484
27484
  }
27485
- budget.work += state3.bytes;
27486
- state3.work += state3.bytes;
27487
- state3.last_parsed_bytes = state3.bytes;
27485
+ budget.work += state2.bytes;
27486
+ state2.work += state2.bytes;
27487
+ state2.last_parsed_bytes = state2.bytes;
27488
27488
  return true;
27489
27489
  }
27490
27490
  function captureStructuredJSONSnapshot(snapshot, property) {
@@ -27563,10 +27563,10 @@ function mapCapturedSnapshotArray(array, maximum, kind, map) {
27563
27563
  return mapped;
27564
27564
  }
27565
27565
  function validateStructuredJSONSnapshot(value, budget, validationWorkBudget) {
27566
- const state3 = createPartialJSONParseState();
27566
+ const state2 = createPartialJSONParseState();
27567
27567
  const parseBudget = budget ?? { bytes: 0, fragments: 0, work: 0 };
27568
- recordPartialJSONFragment(state3, parseBudget, value, validationWorkBudget);
27569
- if (!reservePartialJSONParse(state3, parseBudget)) {
27568
+ recordPartialJSONFragment(state2, parseBudget, value, validationWorkBudget);
27569
+ if (!reservePartialJSONParse(state2, parseBudget)) {
27570
27570
  throw new OpenAIError("Chat completion stream exceeded its structured JSON parse-work limit");
27571
27571
  }
27572
27572
  return value;
@@ -28358,11 +28358,11 @@ var init_ChatCompletionStream = __esm({
28358
28358
  __classPrivateFieldSet2(this, _ChatCompletionStream_currentChatCompletionSnapshot, void 0, "f");
28359
28359
  __classPrivateFieldSet2(this, _ChatCompletionStream_partialJSONParseBudget, { bytes: 0, fragments: 0, work: 0 }, "f");
28360
28360
  }, _ChatCompletionStream_getChoiceEventState = function _ChatCompletionStream_getChoiceEventState2(choice) {
28361
- let state3 = __classPrivateFieldGet2(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index];
28362
- if (state3) {
28363
- return state3;
28361
+ let state2 = __classPrivateFieldGet2(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index];
28362
+ if (state2) {
28363
+ return state2;
28364
28364
  }
28365
- state3 = {
28365
+ state2 = {
28366
28366
  content_done: false,
28367
28367
  content_parse_state: void 0,
28368
28368
  refusal_done: false,
@@ -28373,8 +28373,8 @@ var init_ChatCompletionStream = __esm({
28373
28373
  tool_call_parse_states: /* @__PURE__ */ new Map(),
28374
28374
  tool_call_identities: /* @__PURE__ */ new Map()
28375
28375
  };
28376
- __classPrivateFieldGet2(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index] = state3;
28377
- return state3;
28376
+ __classPrivateFieldGet2(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index] = state2;
28377
+ return state2;
28378
28378
  }, _ChatCompletionStream_addChunk = function _ChatCompletionStream_addChunk2(chunk) {
28379
28379
  if (this.ended) {
28380
28380
  return;
@@ -28419,21 +28419,21 @@ var init_ChatCompletionStream = __esm({
28419
28419
  snapshot: choiceSnapshot.logprobs?.refusal ?? []
28420
28420
  });
28421
28421
  }
28422
- const state3 = __classPrivateFieldGet2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
28422
+ const state2 = __classPrivateFieldGet2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
28423
28423
  if (choiceSnapshot.finish_reason) {
28424
28424
  __classPrivateFieldGet2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitContentDoneEvents).call(this, choiceSnapshot);
28425
- if (state3.current_tool_call_index != null) {
28426
- __classPrivateFieldGet2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitToolCallDoneEvent).call(this, choiceSnapshot, state3.current_tool_call_index);
28425
+ if (state2.current_tool_call_index != null) {
28426
+ __classPrivateFieldGet2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitToolCallDoneEvent).call(this, choiceSnapshot, state2.current_tool_call_index);
28427
28427
  }
28428
28428
  }
28429
28429
  for (const toolCall of capturedToolCalls) {
28430
- if (state3.current_tool_call_index !== toolCall.index) {
28430
+ if (state2.current_tool_call_index !== toolCall.index) {
28431
28431
  __classPrivateFieldGet2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitContentDoneEvents).call(this, choiceSnapshot);
28432
- if (state3.current_tool_call_index != null) {
28433
- __classPrivateFieldGet2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitToolCallDoneEvent).call(this, choiceSnapshot, state3.current_tool_call_index);
28432
+ if (state2.current_tool_call_index != null) {
28433
+ __classPrivateFieldGet2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_emitToolCallDoneEvent).call(this, choiceSnapshot, state2.current_tool_call_index);
28434
28434
  }
28435
28435
  }
28436
- state3.current_tool_call_index = toolCall.index;
28436
+ state2.current_tool_call_index = toolCall.index;
28437
28437
  }
28438
28438
  for (const toolCallDelta of capturedToolCalls) {
28439
28439
  const toolCallSnapshot = messageSnapshot.tool_calls?.[toolCallDelta.index];
@@ -28441,7 +28441,7 @@ var init_ChatCompletionStream = __esm({
28441
28441
  continue;
28442
28442
  }
28443
28443
  if (toolCallSnapshot.type === "function") {
28444
- const boundIdentity = state3.tool_call_identities.get(toolCallDelta.index);
28444
+ const boundIdentity = state2.tool_call_identities.get(toolCallDelta.index);
28445
28445
  let argumentsSnapshot;
28446
28446
  if (boundIdentity?.parseable) {
28447
28447
  const capturedArguments = captureStructuredJSONSnapshot(toolCallSnapshot.function, "arguments");
@@ -28465,8 +28465,8 @@ var init_ChatCompletionStream = __esm({
28465
28465
  }
28466
28466
  }
28467
28467
  }, _ChatCompletionStream_emitToolCallDoneEvent = function _ChatCompletionStream_emitToolCallDoneEvent2(choiceSnapshot, toolCallIndex) {
28468
- const state3 = __classPrivateFieldGet2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
28469
- if (state3.done_tool_calls.has(toolCallIndex)) {
28468
+ const state2 = __classPrivateFieldGet2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
28469
+ if (state2.done_tool_calls.has(toolCallIndex)) {
28470
28470
  return;
28471
28471
  }
28472
28472
  const messageSnapshot = __classPrivateFieldGet2(this, _ChatCompletionStream_hasAutoParseableTool, "f") ? captureStructuredMessageSnapshot(choiceSnapshot) : choiceSnapshot.message;
@@ -28474,7 +28474,7 @@ var init_ChatCompletionStream = __esm({
28474
28474
  if (!toolCallSnapshot) {
28475
28475
  throw new Error("no tool call snapshot");
28476
28476
  }
28477
- const boundIdentity = state3.tool_call_identities.get(toolCallIndex);
28477
+ const boundIdentity = state2.tool_call_identities.get(toolCallIndex);
28478
28478
  if (boundIdentity) {
28479
28479
  assertBoundToolCallIdentity(toolCallSnapshot, boundIdentity);
28480
28480
  }
@@ -28504,7 +28504,7 @@ var init_ChatCompletionStream = __esm({
28504
28504
  parsedArguments = parseResponseFormatContent({ type: "json_schema", $parseRaw: void 0 }, validateStructuredJSONSnapshot(argumentsSnapshot));
28505
28505
  }
28506
28506
  if (choiceSnapshot.finish_reason) {
28507
- state3.done_tool_calls.add(toolCallIndex);
28507
+ state2.done_tool_calls.add(toolCallIndex);
28508
28508
  }
28509
28509
  this._emit("tool_calls.function.arguments.done", {
28510
28510
  name: toolCallSnapshot.function.name,
@@ -28516,33 +28516,33 @@ var init_ChatCompletionStream = __esm({
28516
28516
  assertNever(toolCallSnapshot);
28517
28517
  }
28518
28518
  }, _ChatCompletionStream_emitContentDoneEvents = function _ChatCompletionStream_emitContentDoneEvents2(choiceSnapshot) {
28519
- const state3 = __classPrivateFieldGet2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
28519
+ const state2 = __classPrivateFieldGet2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_getChoiceEventState).call(this, choiceSnapshot);
28520
28520
  const structuredResponse = isParseableResponseFormat(__classPrivateFieldGet2(this, _ChatCompletionStream_params, "f")?.response_format);
28521
28521
  const boundedSnapshot = structuredResponse || __classPrivateFieldGet2(this, _ChatCompletionStream_hasAutoParseableTool, "f");
28522
28522
  const messageSnapshot = boundedSnapshot ? captureStructuredMessageSnapshot(choiceSnapshot) : choiceSnapshot.message;
28523
28523
  const refusal = boundedSnapshot ? captureStructuredJSONSnapshot(messageSnapshot, "refusal") : messageSnapshot.refusal;
28524
28524
  const parseableContent = !refusal && structuredResponse;
28525
28525
  const content = parseableContent ? captureStructuredJSONSnapshot(messageSnapshot, "content") : messageSnapshot.content;
28526
- if (content != null && (content !== "" || !refusal && !messageSnapshot.tool_calls?.length && !messageSnapshot.function_call) && !state3.content_done) {
28526
+ if (content != null && (content !== "" || !refusal && !messageSnapshot.tool_calls?.length && !messageSnapshot.function_call) && !state2.content_done) {
28527
28527
  if (parseableContent && __classPrivateFieldGet2(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f")) {
28528
28528
  __classPrivateFieldGet2(this, _ChatCompletionStream_instances, "m", _ChatCompletionStream_validateStructuredSnapshots).call(this, __classPrivateFieldGet2(this, _ChatCompletionStream_currentChatCompletionSnapshot, "f"));
28529
28529
  }
28530
- state3.content_done = true;
28530
+ state2.content_done = true;
28531
28531
  this._emit("content.done", {
28532
28532
  content,
28533
28533
  parsed: refusal ? null : parseResponseFormatContent(__classPrivateFieldGet2(this, _ChatCompletionStream_params, "f")?.response_format, parseableContent ? validateStructuredJSONSnapshot(content) : content)
28534
28534
  });
28535
28535
  }
28536
- if (refusal && !state3.refusal_done) {
28537
- state3.refusal_done = true;
28536
+ if (refusal && !state2.refusal_done) {
28537
+ state2.refusal_done = true;
28538
28538
  this._emit("refusal.done", { refusal });
28539
28539
  }
28540
- if (choiceSnapshot.logprobs?.content && !state3.logprobs_content_done) {
28541
- state3.logprobs_content_done = true;
28540
+ if (choiceSnapshot.logprobs?.content && !state2.logprobs_content_done) {
28541
+ state2.logprobs_content_done = true;
28542
28542
  this._emit("logprobs.content.done", { content: choiceSnapshot.logprobs.content });
28543
28543
  }
28544
- if (choiceSnapshot.logprobs?.refusal && !state3.logprobs_refusal_done) {
28545
- state3.logprobs_refusal_done = true;
28544
+ if (choiceSnapshot.logprobs?.refusal && !state2.logprobs_refusal_done) {
28545
+ state2.logprobs_refusal_done = true;
28546
28546
  this._emit("logprobs.refusal.done", { refusal: choiceSnapshot.logprobs.refusal });
28547
28547
  }
28548
28548
  }, _ChatCompletionStream_validateStructuredSnapshots = function _ChatCompletionStream_validateStructuredSnapshots2(snapshot) {
@@ -28570,11 +28570,11 @@ var init_ChatCompletionStream = __esm({
28570
28570
  toolCallCollection: toolCalls,
28571
28571
  toolCalls: validatedTools
28572
28572
  }));
28573
- const state3 = __classPrivateFieldGet2(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index];
28573
+ const state2 = __classPrivateFieldGet2(this, _ChatCompletionStream_choiceEventStates, "f")[choice.index];
28574
28574
  if (parseableContent && !refusal && typeof content === "string") {
28575
28575
  validateStructuredJSONSnapshot(content, finalJSONBudget, __classPrivateFieldGet2(this, _ChatCompletionStream_partialJSONParseBudget, "f"));
28576
28576
  }
28577
- for (const [index, identity] of state3?.tool_call_identities ?? []) {
28577
+ for (const [index, identity] of state2?.tool_call_identities ?? []) {
28578
28578
  const toolCall = toolCalls && captureSnapshotArrayItem(toolCalls, index);
28579
28579
  if (!toolCall) {
28580
28580
  throw new OpenAIError("Chat completion stream contains a changed tool call identity");
@@ -32503,7 +32503,7 @@ var init_agent_session_stream = __esm({
32503
32503
  externalSignal?.addEventListener("abort", abort, { once: true });
32504
32504
  this.controller.signal.addEventListener("abort", abort, { once: true });
32505
32505
  const options = { ...__classPrivateFieldGet2(this, _AgentSessionStream_options, "f"), signal: this.controller.signal };
32506
- const state3 = new TurnState();
32506
+ const state2 = new TurnState();
32507
32507
  try {
32508
32508
  if (externalSignal?.aborted) {
32509
32509
  this.abort(externalSignal.reason);
@@ -32529,11 +32529,11 @@ var init_agent_session_stream = __esm({
32529
32529
  __classPrivateFieldSet2(this, _AgentSessionStream_reading, true, "f");
32530
32530
  for await (const event of __classPrivateFieldGet2(this, _AgentSessionStream_stream, "f")) {
32531
32531
  __classPrivateFieldGet2(this, _AgentSessionStream_instances, "m", _AgentSessionStream_checkAbort).call(this);
32532
- if (!state3.accept(event)) {
32532
+ if (!state2.accept(event)) {
32533
32533
  continue;
32534
32534
  }
32535
- const terminal = state3.terminal(event);
32536
- const pendingCall = state3.call(event);
32535
+ const terminal = state2.terminal(event);
32536
+ const pendingCall = state2.call(event);
32537
32537
  const handler = pendingCall && __classPrivateFieldGet2(this, _AgentSessionStream_handlers, "f").get(pendingCall.name);
32538
32538
  const call = pendingCall && handler ? structuredClone(pendingCall) : void 0;
32539
32539
  if (terminal) {
@@ -34520,10 +34520,10 @@ var init_AssistantStream = __esm({
34520
34520
  }));
34521
34521
  return runner;
34522
34522
  }
34523
- async _createToolAssistantStream(run, runId, params, options) {
34523
+ async _createToolAssistantStream(run2, runId, params, options) {
34524
34524
  this._listenForAbort(options?.signal);
34525
34525
  const body = { ...params, stream: true };
34526
- const stream11 = await run.submitToolOutputs(runId, body, {
34526
+ const stream11 = await run2.submitToolOutputs(runId, body, {
34527
34527
  ...options,
34528
34528
  signal: this.controller.signal
34529
34529
  });
@@ -34608,10 +34608,10 @@ var init_AssistantStream = __esm({
34608
34608
  }
34609
34609
  return this._addRun(__classPrivateFieldGet2(this, _AssistantStream_instances, "m", _AssistantStream_endRequest).call(this));
34610
34610
  }
34611
- async _createAssistantStream(run, threadId, params, options) {
34611
+ async _createAssistantStream(run2, threadId, params, options) {
34612
34612
  this._listenForAbort(options?.signal);
34613
34613
  const body = { ...params, stream: true };
34614
- const stream11 = await run.create(threadId, body, { ...options, signal: this.controller.signal });
34614
+ const stream11 = await run2.create(threadId, body, { ...options, signal: this.controller.signal });
34615
34615
  this._connected();
34616
34616
  for await (const event of stream11) {
34617
34617
  __classPrivateFieldGet2(this, _AssistantStream_instances, "m", _AssistantStream_addEvent).call(this, event);
@@ -34628,9 +34628,9 @@ var init_AssistantStream = __esm({
34628
34628
  static accumulateDelta(acc, delta) {
34629
34629
  return accumulateAssistantStreamDelta(acc, delta);
34630
34630
  }
34631
- _addRun(run) {
34632
- __classPrivateFieldGet2(this, _AssistantStream_instances, "m", _AssistantStream_emitExposed).call(this, "run", run);
34633
- return run;
34631
+ _addRun(run2) {
34632
+ __classPrivateFieldGet2(this, _AssistantStream_instances, "m", _AssistantStream_emitExposed).call(this, "run", run2);
34633
+ return run2;
34634
34634
  }
34635
34635
  async _threadAssistantStream(params, thread, options) {
34636
34636
  return await this._createThreadAssistantStream(thread, params, options);
@@ -35310,8 +35310,8 @@ var init_runs = __esm({
35310
35310
  * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps
35311
35311
  */
35312
35312
  async createAndPoll(threadId, body, options) {
35313
- const run = await this.create(threadId, body, options);
35314
- return await this.poll(run.id, { thread_id: threadId }, options);
35313
+ const run2 = await this.create(threadId, body, options);
35314
+ return await this.poll(run2.id, { thread_id: threadId }, options);
35315
35315
  }
35316
35316
  /**
35317
35317
  * Create a Run stream
@@ -35352,8 +35352,8 @@ var init_runs = __esm({
35352
35352
  * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps
35353
35353
  */
35354
35354
  async submitToolOutputsAndPoll(runId, params, options) {
35355
- const run = await this.submitToolOutputs(runId, params, options);
35356
- return await this.poll(run.id, params, options);
35355
+ const run2 = await this.submitToolOutputs(runId, params, options);
35356
+ return await this.poll(run2.id, params, options);
35357
35357
  }
35358
35358
  /**
35359
35359
  * Submit the tool outputs from a previous run and stream the run to a terminal
@@ -35452,8 +35452,8 @@ var init_threads3 = __esm({
35452
35452
  * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps
35453
35453
  */
35454
35454
  async createAndRunPoll(body, options) {
35455
- const run = await this.createAndRun(body, options);
35456
- return await this.runs.poll(run.id, { thread_id: run.thread_id }, options);
35455
+ const run2 = await this.createAndRun(body, options);
35456
+ return await this.runs.poll(run2.id, { thread_id: run2.thread_id }, options);
35457
35457
  }
35458
35458
  /**
35459
35459
  * Create a thread and stream the run back
@@ -45117,9 +45117,9 @@ var require_ponyfill_es2018 = __commonJS({
45117
45117
  if (this._closeRequested) {
45118
45118
  throw new TypeError("The stream has already been closed; do not close it again!");
45119
45119
  }
45120
- const state3 = this._controlledReadableByteStream._state;
45121
- if (state3 !== "readable") {
45122
- throw new TypeError(`The stream (in ${state3} state) is not in the readable state and cannot be closed`);
45120
+ const state2 = this._controlledReadableByteStream._state;
45121
+ if (state2 !== "readable") {
45122
+ throw new TypeError(`The stream (in ${state2} state) is not in the readable state and cannot be closed`);
45123
45123
  }
45124
45124
  ReadableByteStreamControllerClose(this);
45125
45125
  }
@@ -45140,9 +45140,9 @@ var require_ponyfill_es2018 = __commonJS({
45140
45140
  if (this._closeRequested) {
45141
45141
  throw new TypeError("stream is closed or draining");
45142
45142
  }
45143
- const state3 = this._controlledReadableByteStream._state;
45144
- if (state3 !== "readable") {
45145
- throw new TypeError(`The stream (in ${state3} state) is not in the readable state and cannot be enqueued to`);
45143
+ const state2 = this._controlledReadableByteStream._state;
45144
+ if (state2 !== "readable") {
45145
+ throw new TypeError(`The stream (in ${state2} state) is not in the readable state and cannot be enqueued to`);
45146
45146
  }
45147
45147
  ReadableByteStreamControllerEnqueue(this, chunk);
45148
45148
  }
@@ -45460,8 +45460,8 @@ var require_ponyfill_es2018 = __commonJS({
45460
45460
  function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) {
45461
45461
  const firstDescriptor = controller._pendingPullIntos.peek();
45462
45462
  ReadableByteStreamControllerInvalidateBYOBRequest(controller);
45463
- const state3 = controller._controlledReadableByteStream._state;
45464
- if (state3 === "closed") {
45463
+ const state2 = controller._controlledReadableByteStream._state;
45464
+ if (state2 === "closed") {
45465
45465
  ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor);
45466
45466
  } else {
45467
45467
  ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor);
@@ -45587,19 +45587,19 @@ var require_ponyfill_es2018 = __commonJS({
45587
45587
  return controller._byobRequest;
45588
45588
  }
45589
45589
  function ReadableByteStreamControllerGetDesiredSize(controller) {
45590
- const state3 = controller._controlledReadableByteStream._state;
45591
- if (state3 === "errored") {
45590
+ const state2 = controller._controlledReadableByteStream._state;
45591
+ if (state2 === "errored") {
45592
45592
  return null;
45593
45593
  }
45594
- if (state3 === "closed") {
45594
+ if (state2 === "closed") {
45595
45595
  return 0;
45596
45596
  }
45597
45597
  return controller._strategyHWM - controller._queueTotalSize;
45598
45598
  }
45599
45599
  function ReadableByteStreamControllerRespond(controller, bytesWritten) {
45600
45600
  const firstDescriptor = controller._pendingPullIntos.peek();
45601
- const state3 = controller._controlledReadableByteStream._state;
45602
- if (state3 === "closed") {
45601
+ const state2 = controller._controlledReadableByteStream._state;
45602
+ if (state2 === "closed") {
45603
45603
  if (bytesWritten !== 0) {
45604
45604
  throw new TypeError("bytesWritten must be 0 when calling respond() on a closed stream");
45605
45605
  }
@@ -45616,8 +45616,8 @@ var require_ponyfill_es2018 = __commonJS({
45616
45616
  }
45617
45617
  function ReadableByteStreamControllerRespondWithNewView(controller, view) {
45618
45618
  const firstDescriptor = controller._pendingPullIntos.peek();
45619
- const state3 = controller._controlledReadableByteStream._state;
45620
- if (state3 === "closed") {
45619
+ const state2 = controller._controlledReadableByteStream._state;
45620
+ if (state2 === "closed") {
45621
45621
  if (view.byteLength !== 0) {
45622
45622
  throw new TypeError("The view's length must be 0 when calling respondWithNewView() on a closed stream");
45623
45623
  }
@@ -46124,15 +46124,15 @@ var require_ponyfill_es2018 = __commonJS({
46124
46124
  }
46125
46125
  stream11._writableStreamController._abortReason = reason;
46126
46126
  (_a8 = stream11._writableStreamController._abortController) === null || _a8 === void 0 ? void 0 : _a8.abort(reason);
46127
- const state3 = stream11._state;
46128
- if (state3 === "closed" || state3 === "errored") {
46127
+ const state2 = stream11._state;
46128
+ if (state2 === "closed" || state2 === "errored") {
46129
46129
  return promiseResolvedWith(void 0);
46130
46130
  }
46131
46131
  if (stream11._pendingAbortRequest !== void 0) {
46132
46132
  return stream11._pendingAbortRequest._promise;
46133
46133
  }
46134
46134
  let wasAlreadyErroring = false;
46135
- if (state3 === "erroring") {
46135
+ if (state2 === "erroring") {
46136
46136
  wasAlreadyErroring = true;
46137
46137
  reason = void 0;
46138
46138
  }
@@ -46152,9 +46152,9 @@ var require_ponyfill_es2018 = __commonJS({
46152
46152
  return promise;
46153
46153
  }
46154
46154
  function WritableStreamClose(stream11) {
46155
- const state3 = stream11._state;
46156
- if (state3 === "closed" || state3 === "errored") {
46157
- return promiseRejectedWith(new TypeError(`The stream (in ${state3} state) is not in the writable state and cannot be closed`));
46155
+ const state2 = stream11._state;
46156
+ if (state2 === "closed" || state2 === "errored") {
46157
+ return promiseRejectedWith(new TypeError(`The stream (in ${state2} state) is not in the writable state and cannot be closed`));
46158
46158
  }
46159
46159
  const promise = newPromise((resolve2, reject) => {
46160
46160
  const closeRequest = {
@@ -46164,7 +46164,7 @@ var require_ponyfill_es2018 = __commonJS({
46164
46164
  stream11._closeRequest = closeRequest;
46165
46165
  });
46166
46166
  const writer = stream11._writer;
46167
- if (writer !== void 0 && stream11._backpressure && state3 === "writable") {
46167
+ if (writer !== void 0 && stream11._backpressure && state2 === "writable") {
46168
46168
  defaultWriterReadyPromiseResolve(writer);
46169
46169
  }
46170
46170
  WritableStreamDefaultControllerClose(stream11._writableStreamController);
@@ -46181,8 +46181,8 @@ var require_ponyfill_es2018 = __commonJS({
46181
46181
  return promise;
46182
46182
  }
46183
46183
  function WritableStreamDealWithRejection(stream11, error) {
46184
- const state3 = stream11._state;
46185
- if (state3 === "writable") {
46184
+ const state2 = stream11._state;
46185
+ if (state2 === "writable") {
46186
46186
  WritableStreamStartErroring(stream11, error);
46187
46187
  return;
46188
46188
  }
@@ -46242,8 +46242,8 @@ var require_ponyfill_es2018 = __commonJS({
46242
46242
  function WritableStreamFinishInFlightClose(stream11) {
46243
46243
  stream11._inFlightCloseRequest._resolve(void 0);
46244
46244
  stream11._inFlightCloseRequest = void 0;
46245
- const state3 = stream11._state;
46246
- if (state3 === "erroring") {
46245
+ const state2 = stream11._state;
46246
+ if (state2 === "erroring") {
46247
46247
  stream11._storedError = void 0;
46248
46248
  if (stream11._pendingAbortRequest !== void 0) {
46249
46249
  stream11._pendingAbortRequest._resolve();
@@ -46314,18 +46314,18 @@ var require_ponyfill_es2018 = __commonJS({
46314
46314
  }
46315
46315
  this._ownerWritableStream = stream11;
46316
46316
  stream11._writer = this;
46317
- const state3 = stream11._state;
46318
- if (state3 === "writable") {
46317
+ const state2 = stream11._state;
46318
+ if (state2 === "writable") {
46319
46319
  if (!WritableStreamCloseQueuedOrInFlight(stream11) && stream11._backpressure) {
46320
46320
  defaultWriterReadyPromiseInitialize(this);
46321
46321
  } else {
46322
46322
  defaultWriterReadyPromiseInitializeAsResolved(this);
46323
46323
  }
46324
46324
  defaultWriterClosedPromiseInitialize(this);
46325
- } else if (state3 === "erroring") {
46325
+ } else if (state2 === "erroring") {
46326
46326
  defaultWriterReadyPromiseInitializeAsRejected(this, stream11._storedError);
46327
46327
  defaultWriterClosedPromiseInitialize(this);
46328
- } else if (state3 === "closed") {
46328
+ } else if (state2 === "closed") {
46329
46329
  defaultWriterReadyPromiseInitializeAsResolved(this);
46330
46330
  defaultWriterClosedPromiseInitializeAsResolved(this);
46331
46331
  } else {
@@ -46471,11 +46471,11 @@ var require_ponyfill_es2018 = __commonJS({
46471
46471
  }
46472
46472
  function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) {
46473
46473
  const stream11 = writer._ownerWritableStream;
46474
- const state3 = stream11._state;
46475
- if (WritableStreamCloseQueuedOrInFlight(stream11) || state3 === "closed") {
46474
+ const state2 = stream11._state;
46475
+ if (WritableStreamCloseQueuedOrInFlight(stream11) || state2 === "closed") {
46476
46476
  return promiseResolvedWith(void 0);
46477
46477
  }
46478
- if (state3 === "errored") {
46478
+ if (state2 === "errored") {
46479
46479
  return promiseRejectedWith(stream11._storedError);
46480
46480
  }
46481
46481
  return WritableStreamDefaultWriterClose(writer);
@@ -46496,11 +46496,11 @@ var require_ponyfill_es2018 = __commonJS({
46496
46496
  }
46497
46497
  function WritableStreamDefaultWriterGetDesiredSize(writer) {
46498
46498
  const stream11 = writer._ownerWritableStream;
46499
- const state3 = stream11._state;
46500
- if (state3 === "errored" || state3 === "erroring") {
46499
+ const state2 = stream11._state;
46500
+ if (state2 === "errored" || state2 === "erroring") {
46501
46501
  return null;
46502
46502
  }
46503
- if (state3 === "closed") {
46503
+ if (state2 === "closed") {
46504
46504
  return 0;
46505
46505
  }
46506
46506
  return WritableStreamDefaultControllerGetDesiredSize(stream11._writableStreamController);
@@ -46520,14 +46520,14 @@ var require_ponyfill_es2018 = __commonJS({
46520
46520
  if (stream11 !== writer._ownerWritableStream) {
46521
46521
  return promiseRejectedWith(defaultWriterLockException("write to"));
46522
46522
  }
46523
- const state3 = stream11._state;
46524
- if (state3 === "errored") {
46523
+ const state2 = stream11._state;
46524
+ if (state2 === "errored") {
46525
46525
  return promiseRejectedWith(stream11._storedError);
46526
46526
  }
46527
- if (WritableStreamCloseQueuedOrInFlight(stream11) || state3 === "closed") {
46527
+ if (WritableStreamCloseQueuedOrInFlight(stream11) || state2 === "closed") {
46528
46528
  return promiseRejectedWith(new TypeError("The stream is closing or closed and cannot be written to"));
46529
46529
  }
46530
- if (state3 === "erroring") {
46530
+ if (state2 === "erroring") {
46531
46531
  return promiseRejectedWith(stream11._storedError);
46532
46532
  }
46533
46533
  const promise = WritableStreamAddWriteRequest(stream11);
@@ -46575,8 +46575,8 @@ var require_ponyfill_es2018 = __commonJS({
46575
46575
  if (!IsWritableStreamDefaultController(this)) {
46576
46576
  throw defaultControllerBrandCheckException$2("error");
46577
46577
  }
46578
- const state3 = this._controlledWritableStream._state;
46579
- if (state3 !== "writable") {
46578
+ const state2 = this._controlledWritableStream._state;
46579
+ if (state2 !== "writable") {
46580
46580
  return;
46581
46581
  }
46582
46582
  WritableStreamDefaultControllerError(this, e2);
@@ -46711,8 +46711,8 @@ var require_ponyfill_es2018 = __commonJS({
46711
46711
  if (stream11._inFlightWriteRequest !== void 0) {
46712
46712
  return;
46713
46713
  }
46714
- const state3 = stream11._state;
46715
- if (state3 === "erroring") {
46714
+ const state2 = stream11._state;
46715
+ if (state2 === "erroring") {
46716
46716
  WritableStreamFinishErroring(stream11);
46717
46717
  return;
46718
46718
  }
@@ -46751,9 +46751,9 @@ var require_ponyfill_es2018 = __commonJS({
46751
46751
  const sinkWritePromise = controller._writeAlgorithm(chunk);
46752
46752
  uponPromise(sinkWritePromise, () => {
46753
46753
  WritableStreamFinishInFlightWrite(stream11);
46754
- const state3 = stream11._state;
46754
+ const state2 = stream11._state;
46755
46755
  DequeueValue(controller);
46756
- if (!WritableStreamCloseQueuedOrInFlight(stream11) && state3 === "writable") {
46756
+ if (!WritableStreamCloseQueuedOrInFlight(stream11) && state2 === "writable") {
46757
46757
  const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);
46758
46758
  WritableStreamUpdateBackpressure(stream11, backpressure);
46759
46759
  }
@@ -47252,11 +47252,11 @@ var require_ponyfill_es2018 = __commonJS({
47252
47252
  ReadableStreamError(stream11, e2);
47253
47253
  }
47254
47254
  function ReadableStreamDefaultControllerGetDesiredSize(controller) {
47255
- const state3 = controller._controlledReadableStream._state;
47256
- if (state3 === "errored") {
47255
+ const state2 = controller._controlledReadableStream._state;
47256
+ if (state2 === "errored") {
47257
47257
  return null;
47258
47258
  }
47259
- if (state3 === "closed") {
47259
+ if (state2 === "closed") {
47260
47260
  return 0;
47261
47261
  }
47262
47262
  return controller._strategyHWM - controller._queueTotalSize;
@@ -47268,8 +47268,8 @@ var require_ponyfill_es2018 = __commonJS({
47268
47268
  return true;
47269
47269
  }
47270
47270
  function ReadableStreamDefaultControllerCanCloseOrEnqueue(controller) {
47271
- const state3 = controller._controlledReadableStream._state;
47272
- if (!controller._closeRequested && state3 === "readable") {
47271
+ const state2 = controller._controlledReadableStream._state;
47272
+ if (!controller._closeRequested && state2 === "readable") {
47273
47273
  return true;
47274
47274
  }
47275
47275
  return false;
@@ -48461,8 +48461,8 @@ var require_ponyfill_es2018 = __commonJS({
48461
48461
  const backpressureChangePromise = stream11._backpressureChangePromise;
48462
48462
  return transformPromiseWith(backpressureChangePromise, () => {
48463
48463
  const writable = stream11._writable;
48464
- const state3 = writable._state;
48465
- if (state3 === "erroring") {
48464
+ const state2 = writable._state;
48465
+ if (state2 === "erroring") {
48466
48466
  throw writable._storedError;
48467
48467
  }
48468
48468
  return TransformStreamDefaultControllerPerformTransform(controller, chunk);
@@ -49293,7 +49293,7 @@ var init_multipart_parser = __esm({
49293
49293
  let i2 = 0;
49294
49294
  const length_ = data.length;
49295
49295
  let previousIndex = this.index;
49296
- let { lookbehind, boundary, boundaryChars, index, state: state3, flags } = this;
49296
+ let { lookbehind, boundary, boundaryChars, index, state: state2, flags } = this;
49297
49297
  const boundaryLength = this.boundary.length;
49298
49298
  const boundaryEnd = boundaryLength - 1;
49299
49299
  const bufferLength = data.length;
@@ -49325,7 +49325,7 @@ var init_multipart_parser = __esm({
49325
49325
  };
49326
49326
  for (i2 = 0; i2 < length_; i2++) {
49327
49327
  c = data[i2];
49328
- switch (state3) {
49328
+ switch (state2) {
49329
49329
  case S.START_BOUNDARY:
49330
49330
  if (index === boundary.length - 2) {
49331
49331
  if (c === HYPHEN) {
@@ -49337,12 +49337,12 @@ var init_multipart_parser = __esm({
49337
49337
  break;
49338
49338
  } else if (index - 1 === boundary.length - 2) {
49339
49339
  if (flags & F.LAST_BOUNDARY && c === HYPHEN) {
49340
- state3 = S.END;
49340
+ state2 = S.END;
49341
49341
  flags = 0;
49342
49342
  } else if (!(flags & F.LAST_BOUNDARY) && c === LF) {
49343
49343
  index = 0;
49344
49344
  callback("onPartBegin");
49345
- state3 = S.HEADER_FIELD_START;
49345
+ state2 = S.HEADER_FIELD_START;
49346
49346
  } else {
49347
49347
  return;
49348
49348
  }
@@ -49356,14 +49356,14 @@ var init_multipart_parser = __esm({
49356
49356
  }
49357
49357
  break;
49358
49358
  case S.HEADER_FIELD_START:
49359
- state3 = S.HEADER_FIELD;
49359
+ state2 = S.HEADER_FIELD;
49360
49360
  mark("onHeaderField");
49361
49361
  index = 0;
49362
49362
  // falls through
49363
49363
  case S.HEADER_FIELD:
49364
49364
  if (c === CR) {
49365
49365
  clear("onHeaderField");
49366
- state3 = S.HEADERS_ALMOST_DONE;
49366
+ state2 = S.HEADERS_ALMOST_DONE;
49367
49367
  break;
49368
49368
  }
49369
49369
  index++;
@@ -49375,7 +49375,7 @@ var init_multipart_parser = __esm({
49375
49375
  return;
49376
49376
  }
49377
49377
  dataCallback("onHeaderField", true);
49378
- state3 = S.HEADER_VALUE_START;
49378
+ state2 = S.HEADER_VALUE_START;
49379
49379
  break;
49380
49380
  }
49381
49381
  cl = lower(c);
@@ -49388,30 +49388,30 @@ var init_multipart_parser = __esm({
49388
49388
  break;
49389
49389
  }
49390
49390
  mark("onHeaderValue");
49391
- state3 = S.HEADER_VALUE;
49391
+ state2 = S.HEADER_VALUE;
49392
49392
  // falls through
49393
49393
  case S.HEADER_VALUE:
49394
49394
  if (c === CR) {
49395
49395
  dataCallback("onHeaderValue", true);
49396
49396
  callback("onHeaderEnd");
49397
- state3 = S.HEADER_VALUE_ALMOST_DONE;
49397
+ state2 = S.HEADER_VALUE_ALMOST_DONE;
49398
49398
  }
49399
49399
  break;
49400
49400
  case S.HEADER_VALUE_ALMOST_DONE:
49401
49401
  if (c !== LF) {
49402
49402
  return;
49403
49403
  }
49404
- state3 = S.HEADER_FIELD_START;
49404
+ state2 = S.HEADER_FIELD_START;
49405
49405
  break;
49406
49406
  case S.HEADERS_ALMOST_DONE:
49407
49407
  if (c !== LF) {
49408
49408
  return;
49409
49409
  }
49410
49410
  callback("onHeadersEnd");
49411
- state3 = S.PART_DATA_START;
49411
+ state2 = S.PART_DATA_START;
49412
49412
  break;
49413
49413
  case S.PART_DATA_START:
49414
- state3 = S.PART_DATA;
49414
+ state2 = S.PART_DATA;
49415
49415
  mark("onPartData");
49416
49416
  // falls through
49417
49417
  case S.PART_DATA:
@@ -49449,13 +49449,13 @@ var init_multipart_parser = __esm({
49449
49449
  flags &= ~F.PART_BOUNDARY;
49450
49450
  callback("onPartEnd");
49451
49451
  callback("onPartBegin");
49452
- state3 = S.HEADER_FIELD_START;
49452
+ state2 = S.HEADER_FIELD_START;
49453
49453
  break;
49454
49454
  }
49455
49455
  } else if (flags & F.LAST_BOUNDARY) {
49456
49456
  if (c === HYPHEN) {
49457
49457
  callback("onPartEnd");
49458
- state3 = S.END;
49458
+ state2 = S.END;
49459
49459
  flags = 0;
49460
49460
  } else {
49461
49461
  index = 0;
@@ -49477,14 +49477,14 @@ var init_multipart_parser = __esm({
49477
49477
  case S.END:
49478
49478
  break;
49479
49479
  default:
49480
- throw new Error(`Unexpected state entered: ${state3}`);
49480
+ throw new Error(`Unexpected state entered: ${state2}`);
49481
49481
  }
49482
49482
  }
49483
49483
  dataCallback("onHeaderField");
49484
49484
  dataCallback("onHeaderValue");
49485
49485
  dataCallback("onPartData");
49486
49486
  this.index = index;
49487
- this.state = state3;
49487
+ this.state = state2;
49488
49488
  this.flags = flags;
49489
49489
  }
49490
49490
  end() {
@@ -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 randomUUID3 = async () => globalThis.crypto?.randomUUID() || (await import("crypto")).randomUUID();
50784
+ var randomUUID4 = 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 randomUUID3();
51057
+ const boundary = await randomUUID4();
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) {
@@ -65693,8 +65693,8 @@ function tBatchJobName(apiClient, name) {
65693
65693
  throw new Error(`Invalid batch job name: ${nameString}.`);
65694
65694
  }
65695
65695
  }
65696
- function tJobState(state3) {
65697
- const stateString = state3;
65696
+ function tJobState(state2) {
65697
+ const stateString = state2;
65698
65698
  if (stateString === "BATCH_STATE_UNSPECIFIED") {
65699
65699
  return "JOB_STATE_UNSPECIFIED";
65700
65700
  } else if (stateString === "BATCH_STATE_PENDING") {
@@ -75063,7 +75063,7 @@ function findBoundary(buf, len, from) {
75063
75063
  }
75064
75064
  return null;
75065
75065
  }
75066
- function parseMessage2(chunk, parse, state3, dataRequired) {
75066
+ function parseMessage2(chunk, parse, state2, dataRequired) {
75067
75067
  const text = new TextDecoder().decode(chunk);
75068
75068
  const lines = text.split(/\r\n|\r|\n/);
75069
75069
  const dataLines = [];
@@ -75085,14 +75085,14 @@ function parseMessage2(chunk, parse, state3, dataRequired) {
75085
75085
  else if (field === "event")
75086
75086
  ret.event = value;
75087
75087
  else if (field === "id" && !value.includes("\0"))
75088
- state3.eventId = value;
75088
+ state2.eventId = value;
75089
75089
  else if (field === "retry" && /^\d+$/.test(value)) {
75090
75090
  ret.retry = Number(value);
75091
75091
  }
75092
75092
  }
75093
75093
  if (ignore)
75094
75094
  return;
75095
- ret.id = state3.eventId;
75095
+ ret.id = state2.eventId;
75096
75096
  if (dataLines.length)
75097
75097
  ret.data = dataLines.join("\n");
75098
75098
  else if (dataRequired)
@@ -75222,7 +75222,7 @@ function unpackHeaders(headers) {
75222
75222
  return out;
75223
75223
  }
75224
75224
  function resolveSecurity(...options) {
75225
- const state3 = {
75225
+ const state2 = {
75226
75226
  basic: {},
75227
75227
  headers: {},
75228
75228
  queryParams: {},
@@ -75261,46 +75261,46 @@ function resolveSecurity(...options) {
75261
75261
  const { type } = spec;
75262
75262
  switch (type) {
75263
75263
  case "apiKey:header":
75264
- state3.headers[spec.fieldName] = spec.value;
75264
+ state2.headers[spec.fieldName] = spec.value;
75265
75265
  break;
75266
75266
  case "apiKey:query":
75267
- state3.queryParams[spec.fieldName] = spec.value;
75267
+ state2.queryParams[spec.fieldName] = spec.value;
75268
75268
  break;
75269
75269
  case "apiKey:cookie":
75270
- state3.cookies[spec.fieldName] = spec.value;
75270
+ state2.cookies[spec.fieldName] = spec.value;
75271
75271
  break;
75272
75272
  case "http:basic":
75273
- applyBasic(state3, spec);
75273
+ applyBasic(state2, spec);
75274
75274
  break;
75275
75275
  case "http:custom":
75276
75276
  break;
75277
75277
  case "http:bearer":
75278
- applyBearer(state3, spec);
75278
+ applyBearer(state2, spec);
75279
75279
  break;
75280
75280
  case "oauth2":
75281
- applyBearer(state3, spec);
75281
+ applyBearer(state2, spec);
75282
75282
  break;
75283
75283
  case "oauth2:password":
75284
- applyBearer(state3, spec);
75284
+ applyBearer(state2, spec);
75285
75285
  break;
75286
75286
  case "oauth2:client_credentials":
75287
75287
  break;
75288
75288
  case "openIdConnect":
75289
- applyBearer(state3, spec);
75289
+ applyBearer(state2, spec);
75290
75290
  break;
75291
75291
  default:
75292
75292
  throw SecurityError.unrecognizedType(type);
75293
75293
  }
75294
75294
  });
75295
- return state3;
75295
+ return state2;
75296
75296
  }
75297
- function applyBasic(state3, spec) {
75297
+ function applyBasic(state2, spec) {
75298
75298
  if (spec.value == null) {
75299
75299
  return;
75300
75300
  }
75301
- state3.basic = spec.value;
75301
+ state2.basic = spec.value;
75302
75302
  }
75303
- function applyBearer(state3, spec) {
75303
+ function applyBearer(state2, spec) {
75304
75304
  if (typeof spec.value !== "string" || !spec.value) {
75305
75305
  return;
75306
75306
  }
@@ -75309,7 +75309,7 @@ function applyBearer(state3, spec) {
75309
75309
  value = `Bearer ${value}`;
75310
75310
  }
75311
75311
  if (spec.fieldName !== void 0) {
75312
- state3.headers[spec.fieldName] = value;
75312
+ state2.headers[spec.fieldName] = value;
75313
75313
  }
75314
75314
  }
75315
75315
  function resolveGlobalSecurity(security, allowedFields) {
@@ -85318,7 +85318,7 @@ var init_node3 = __esm({
85318
85318
  let buffer = new Uint8Array(4096);
85319
85319
  let bufferLen = 0;
85320
85320
  let searchStart = 0;
85321
- const state3 = { eventId: void 0 };
85321
+ const state2 = { eventId: void 0 };
85322
85322
  const dataRequired = (_a7 = opts === null || opts === void 0 ? void 0 : opts.dataRequired) !== null && _a7 !== void 0 ? _a7 : true;
85323
85323
  super({
85324
85324
  async pull(downstream) {
@@ -85348,7 +85348,7 @@ var init_node3 = __esm({
85348
85348
  buffer = shrunk;
85349
85349
  }
85350
85350
  searchStart = 0;
85351
- const item = parseMessage2(message, parse, state3, dataRequired);
85351
+ const item = parseMessage2(message, parse, state2, dataRequired);
85352
85352
  if (item && !item.done)
85353
85353
  return downstream.enqueue(item.value);
85354
85354
  if (item === null || item === void 0 ? void 0 : item.done) {
@@ -92177,10 +92177,10 @@ function wireQuestion(name, question) {
92177
92177
  return { type: "predicate", name, instructions: predicateInstructions(question) };
92178
92178
  }
92179
92179
  function wireInput(context) {
92180
- const state3 = JSON.stringify(context.state);
92180
+ const state2 = JSON.stringify(context.state);
92181
92181
  const images = context.images ?? [];
92182
92182
  if (images.length === 0)
92183
- return state3;
92183
+ return state2;
92184
92184
  if (images.length > MAX_IMAGES) {
92185
92185
  throw new Error(`${LABEL2} accepts at most ${MAX_IMAGES} images, got ${images.length}`);
92186
92186
  }
@@ -92188,7 +92188,7 @@ function wireInput(context) {
92188
92188
  {
92189
92189
  role: "user",
92190
92190
  content: [
92191
- { type: "input_text", text: state3 },
92191
+ { type: "input_text", text: state2 },
92192
92192
  ...images.map((image) => ({
92193
92193
  type: "input_image",
92194
92194
  image_url: `data:${image.mimeType};base64,${image.data}`
@@ -92431,7 +92431,7 @@ __export(kiro_cli_exports, {
92431
92431
  saveKiroCliCredentials: () => saveKiroCliCredentials,
92432
92432
  tryKiroCliToken: () => tryKiroCliToken
92433
92433
  });
92434
- import { execFileSync as execFileSync3, execSync } from "node:child_process";
92434
+ import { execFileSync, execSync } from "node:child_process";
92435
92435
  import { existsSync as existsSync3 } from "node:fs";
92436
92436
  import { createRequire } from "node:module";
92437
92437
  import { homedir as homedir6, platform } from "node:os";
@@ -92672,7 +92672,7 @@ function saveKiroCliCredentials(creds) {
92672
92672
  function getKiroCliModelRates() {
92673
92673
  let raw;
92674
92674
  try {
92675
- raw = execFileSync3("kiro-cli", ["chat", "--list-models", "--format", "json"], {
92675
+ raw = execFileSync("kiro-cli", ["chat", "--list-models", "--format", "json"], {
92676
92676
  encoding: "utf-8",
92677
92677
  timeout: 1e4,
92678
92678
  stdio: ["pipe", "pipe", "pipe"]
@@ -92706,7 +92706,7 @@ function getKiroCliModelRates() {
92706
92706
  }
92707
92707
  function refreshViaKiroCli() {
92708
92708
  try {
92709
- execFileSync3("kiro-cli", ["debug", "refresh-auth-token"], {
92709
+ execFileSync("kiro-cli", ["debug", "refresh-auth-token"], {
92710
92710
  timeout: 15e3,
92711
92711
  stdio: ["pipe", "pipe", "pipe"]
92712
92712
  });
@@ -92732,6 +92732,94 @@ var init_kiro_cli = __esm({
92732
92732
  }
92733
92733
  });
92734
92734
 
92735
+ // ../kiro-core/dist/token-type.js
92736
+ function isExternalIdpAccessToken(accessToken) {
92737
+ if (typeof accessToken !== "string" || !accessToken)
92738
+ return false;
92739
+ const segments = accessToken.split(".");
92740
+ const payloadSegment = segments[1];
92741
+ if (segments.length === 3 && payloadSegment) {
92742
+ try {
92743
+ const payload = JSON.parse(Buffer.from(payloadSegment.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf-8"));
92744
+ if (payload.aud === EXTERNAL_IDP_AUDIENCE || Array.isArray(payload.aud) && payload.aud.includes(EXTERNAL_IDP_AUDIENCE)) {
92745
+ return true;
92746
+ }
92747
+ } catch {
92748
+ }
92749
+ }
92750
+ try {
92751
+ return getKiroCliExternalIdpCredentials()?.access === accessToken;
92752
+ } catch {
92753
+ return false;
92754
+ }
92755
+ }
92756
+ function kiroTokenTypeHeaders(accessToken) {
92757
+ return isExternalIdpAccessToken(accessToken) ? { tokentype: "EXTERNAL_IDP" } : {};
92758
+ }
92759
+ function isApiKey(token) {
92760
+ return token.startsWith("ksk_");
92761
+ }
92762
+ function kiroAuthHeaders(token) {
92763
+ const headers = { Authorization: `Bearer ${token}` };
92764
+ if (isApiKey(token))
92765
+ headers.tokentype = "API_KEY";
92766
+ return headers;
92767
+ }
92768
+ var EXTERNAL_IDP_AUDIENCE;
92769
+ var init_token_type = __esm({
92770
+ "../kiro-core/dist/token-type.js"() {
92771
+ "use strict";
92772
+ init_kiro_cli();
92773
+ EXTERNAL_IDP_AUDIENCE = "api://kiro";
92774
+ }
92775
+ });
92776
+
92777
+ // ../kiro-core/dist/http.js
92778
+ function kiroSdkUserAgent(service, sdkVersion) {
92779
+ return {
92780
+ "User-Agent": `aws-sdk-js/3.714.0 os/macos/24.3.0 lang/js md/nodejs/22.14.0 api/${service}/3.714.0 exec-env/kiro-cli/2.7.0 m/E`,
92781
+ "amz-sdk-invocation-id": "00000000-0000-0000-0000-000000000000",
92782
+ "amz-sdk-request": `attempt=1; max=${sdkVersion}`
92783
+ };
92784
+ }
92785
+ function kiroFetch(url, init) {
92786
+ return fetch(url, init);
92787
+ }
92788
+ async function kiroManagementFetch(url, auth, method, body) {
92789
+ const headers = {
92790
+ Accept: "application/json",
92791
+ ...kiroAuthHeaders(auth.accessToken),
92792
+ ...kiroTokenTypeHeaders(auth.accessToken),
92793
+ "User-Agent": KIRO_USER_AGENTS.management
92794
+ };
92795
+ const init = { method, headers };
92796
+ if (method === "GET") {
92797
+ for (const [name, value] of Object.entries(body)) {
92798
+ if (value !== void 0)
92799
+ url.searchParams.set(name, String(value));
92800
+ }
92801
+ } else {
92802
+ headers["Content-Type"] = "application/json";
92803
+ init.body = JSON.stringify(body);
92804
+ }
92805
+ return kiroFetch(url.toString(), init);
92806
+ }
92807
+ var KIRO_USER_AGENTS;
92808
+ var init_http = __esm({
92809
+ "../kiro-core/dist/http.js"() {
92810
+ "use strict";
92811
+ init_token_type();
92812
+ KIRO_USER_AGENTS = {
92813
+ /** REST-style management calls (ListAvailableProfiles, ListAvailableModels, GetUsageLimits). */
92814
+ management: "ns-kiro-provider",
92815
+ /** `prod.{region}.auth.desktop.kiro.dev/refreshToken` — the desktop app's own refresh. */
92816
+ desktop: "Kiro-Desktop/0.2.13 (darwin; arm64)",
92817
+ /** A customer's own OIDC token endpoint. No vendor to impersonate, so this names the package. */
92818
+ externalIdp: "kiro-core"
92819
+ };
92820
+ }
92821
+ });
92822
+
92735
92823
  // ../kiro-core/dist/kiro-ide.js
92736
92824
  import { existsSync as existsSync4, readFileSync as readFileSync5 } from "node:fs";
92737
92825
  import { homedir as homedir7 } from "node:os";
@@ -92800,31 +92888,15 @@ function resolveKiroAuthSource() {
92800
92888
  console.warn(`[kiro-core] Ignoring ${AUTH_SOURCE_ENV}=${configured}: expected "cli" or "ide".`);
92801
92889
  return "cli";
92802
92890
  }
92803
- function kiroUserAgent(service, sdkVersion) {
92804
- return {
92805
- "User-Agent": `aws-sdk-js/3.714.0 os/macos/24.3.0 lang/js md/nodejs/22.14.0 api/${service}/3.714.0 exec-env/kiro-cli/2.7.0 m/E`,
92806
- "amz-sdk-invocation-id": "00000000-0000-0000-0000-000000000000",
92807
- "amz-sdk-request": `attempt=1; max=${sdkVersion}`
92808
- };
92809
- }
92810
- function kiroAuthHeaders(token) {
92811
- const headers = { Authorization: `Bearer ${token}` };
92812
- if (isApiKey(token))
92813
- headers.tokentype = "API_KEY";
92814
- return headers;
92815
- }
92816
- function isApiKey(token) {
92817
- return token.startsWith("ksk_");
92818
- }
92819
92891
  async function fetchApiKeyGetProfile(accessToken) {
92820
92892
  try {
92821
- return await fetch(getKiroEndpoints(API_KEY_REGION).management, {
92893
+ return await kiroFetch(getKiroEndpoints(API_KEY_REGION).management, {
92822
92894
  method: "POST",
92823
92895
  headers: {
92824
92896
  "Content-Type": "application/x-amz-json-1.0",
92825
92897
  "X-Amz-Target": "AmazonCodeWhispererService.GetProfile",
92826
92898
  ...kiroAuthHeaders(accessToken),
92827
- ...kiroUserAgent("codewhispererruntime", "F,C")
92899
+ ...kiroSdkUserAgent("codewhispererruntime", "F,C")
92828
92900
  },
92829
92901
  body: "{}"
92830
92902
  });
@@ -92900,9 +92972,9 @@ async function refreshKiroTokenDirectInProcess(credentials) {
92900
92972
  return credentials;
92901
92973
  if (authMethod === "desktop") {
92902
92974
  const url = endpointFromEnv(KIRO_DESKTOP_REFRESH_ENDPOINT_ENV, KIRO_DESKTOP_REFRESH_URL, region);
92903
- const response2 = await fetch(url, {
92975
+ const response2 = await kiroFetch(url, {
92904
92976
  method: "POST",
92905
- headers: { "Content-Type": "application/json", "User-Agent": KIRO_DESKTOP_USER_AGENT },
92977
+ headers: { "Content-Type": "application/json", "User-Agent": KIRO_USER_AGENTS.desktop },
92906
92978
  body: JSON.stringify({ refreshToken })
92907
92979
  });
92908
92980
  if (!response2.ok)
@@ -92927,12 +92999,12 @@ async function refreshKiroTokenDirectInProcess(credentials) {
92927
92999
  const tokenEndpoint = parts[2] ?? "";
92928
93000
  if (!tokenEndpoint)
92929
93001
  throw new Error("External IdP token refresh: missing token endpoint");
92930
- const response2 = await fetch(tokenEndpoint, {
93002
+ const response2 = await kiroFetch(tokenEndpoint, {
92931
93003
  method: "POST",
92932
93004
  headers: {
92933
93005
  "Content-Type": "application/x-www-form-urlencoded",
92934
93006
  Accept: "application/json",
92935
- "User-Agent": "kiro-core"
93007
+ "User-Agent": KIRO_USER_AGENTS.externalIdp
92936
93008
  },
92937
93009
  body: new URLSearchParams({
92938
93010
  grant_type: "refresh_token",
@@ -92960,9 +93032,9 @@ async function refreshKiroTokenDirectInProcess(credentials) {
92960
93032
  const clientId = parts[1] ?? "";
92961
93033
  const clientSecret = parts[2] ?? "";
92962
93034
  const ssoEndpoint = endpointFromEnv(KIRO_OIDC_ENDPOINT_ENV, "https://oidc.{region}.amazonaws.com", region);
92963
- const response = await fetch(`${ssoEndpoint}/token`, {
93035
+ const response = await kiroFetch(`${ssoEndpoint}/token`, {
92964
93036
  method: "POST",
92965
- headers: { "Content-Type": "application/json", ...kiroUserAgent("ssooidc", "E") },
93037
+ headers: { "Content-Type": "application/json", ...kiroSdkUserAgent("ssooidc", "E") },
92966
93038
  body: JSON.stringify({ clientId, clientSecret, refreshToken, grantType: "refresh_token" })
92967
93039
  });
92968
93040
  if (!response.ok)
@@ -93013,11 +93085,13 @@ var init_oauth = __esm({
93013
93085
  "use strict";
93014
93086
  init_debug();
93015
93087
  init_endpoints();
93088
+ init_http();
93016
93089
  init_kiro_cli();
93017
93090
  init_kiro_ide();
93091
+ init_token_type();
93018
93092
  KIRO_DESKTOP_REFRESH_URL = "https://prod.{region}.auth.desktop.kiro.dev/refreshToken";
93019
93093
  EXPIRES_BUFFER_MS = 5 * 60 * 1e3;
93020
- KIRO_DESKTOP_USER_AGENT = "Kiro-Desktop/0.2.13 (darwin; arm64)";
93094
+ KIRO_DESKTOP_USER_AGENT = KIRO_USER_AGENTS.desktop;
93021
93095
  AUTH_SOURCE_ENV = "KIRO_AUTH_SOURCE";
93022
93096
  API_KEY_REGION = "us-east-1";
93023
93097
  KIRO_DESKTOP_REFRESH_ENDPOINT_ENV = "KIRO_DESKTOP_REFRESH_ENDPOINT";
@@ -93025,39 +93099,6 @@ var init_oauth = __esm({
93025
93099
  }
93026
93100
  });
93027
93101
 
93028
- // ../kiro-core/dist/token-type.js
93029
- function isExternalIdpAccessToken(accessToken) {
93030
- if (typeof accessToken !== "string" || !accessToken)
93031
- return false;
93032
- const segments = accessToken.split(".");
93033
- const payloadSegment = segments[1];
93034
- if (segments.length === 3 && payloadSegment) {
93035
- try {
93036
- const payload = JSON.parse(Buffer.from(payloadSegment.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf-8"));
93037
- if (payload.aud === EXTERNAL_IDP_AUDIENCE || Array.isArray(payload.aud) && payload.aud.includes(EXTERNAL_IDP_AUDIENCE)) {
93038
- return true;
93039
- }
93040
- } catch {
93041
- }
93042
- }
93043
- try {
93044
- return getKiroCliExternalIdpCredentials()?.access === accessToken;
93045
- } catch {
93046
- return false;
93047
- }
93048
- }
93049
- function kiroTokenTypeHeaders(accessToken) {
93050
- return isExternalIdpAccessToken(accessToken) ? { tokentype: "EXTERNAL_IDP" } : {};
93051
- }
93052
- var EXTERNAL_IDP_AUDIENCE;
93053
- var init_token_type = __esm({
93054
- "../kiro-core/dist/token-type.js"() {
93055
- "use strict";
93056
- init_kiro_cli();
93057
- EXTERNAL_IDP_AUDIENCE = "api://kiro";
93058
- }
93059
- });
93060
-
93061
93102
  // ../kiro-core/dist/management.js
93062
93103
  var management_exports = {};
93063
93104
  __export(management_exports, {
@@ -93087,26 +93128,9 @@ function candidateManagementRegions(primary) {
93087
93128
  }
93088
93129
  async function requestManagement(auth, operation, path6, method, body) {
93089
93130
  const url = new URL(path6, getKiroEndpoints(auth.region).management);
93090
- const request = {
93091
- method,
93092
- headers: {
93093
- Accept: "application/json",
93094
- ...kiroAuthHeaders(auth.accessToken),
93095
- ...kiroTokenTypeHeaders(auth.accessToken)
93096
- }
93097
- };
93098
- if (method === "GET") {
93099
- for (const [name, value] of Object.entries(body)) {
93100
- if (value !== void 0)
93101
- url.searchParams.set(name, String(value));
93102
- }
93103
- } else {
93104
- request.headers = { ...request.headers, "Content-Type": "application/json" };
93105
- request.body = JSON.stringify(body);
93106
- }
93107
93131
  let response;
93108
93132
  try {
93109
- response = await fetch(url.toString(), request);
93133
+ response = await kiroManagementFetch(url, auth, method, body);
93110
93134
  } catch (error) {
93111
93135
  throw new Error(`Kiro management ${operation} request failed in ${auth.region}`, { cause: error });
93112
93136
  }
@@ -93258,21 +93282,9 @@ async function fetchKiroModelCatalog(auth, providedProfileArn) {
93258
93282
  async function getUsageLimits(auth, request) {
93259
93283
  const operation = "GetUsageLimits";
93260
93284
  const url = new URL("Get-Usage-Limits", getKiroEndpoints(auth.region).management);
93261
- for (const [name, value] of Object.entries(request)) {
93262
- if (value !== void 0)
93263
- url.searchParams.set(name, String(value));
93264
- }
93265
93285
  let response;
93266
93286
  try {
93267
- response = await fetch(url.toString(), {
93268
- method: "GET",
93269
- headers: {
93270
- Accept: "application/json",
93271
- ...kiroAuthHeaders(auth.accessToken),
93272
- ...kiroTokenTypeHeaders(auth.accessToken),
93273
- "User-Agent": "ns-kiro-provider"
93274
- }
93275
- });
93287
+ response = await kiroManagementFetch(url, auth, "GET", request);
93276
93288
  } catch (error) {
93277
93289
  throw new Error(`Kiro management ${operation} request failed in ${auth.region}`, { cause: error });
93278
93290
  }
@@ -93284,8 +93296,8 @@ var init_management = __esm({
93284
93296
  "use strict";
93285
93297
  init_debug();
93286
93298
  init_endpoints();
93299
+ init_http();
93287
93300
  init_oauth();
93288
- init_token_type();
93289
93301
  LIST_PROFILES_PATH = "List-Available-Profiles";
93290
93302
  LIST_MODELS_PATH = "List-Available-Models";
93291
93303
  API_KEY_REGION2 = "us-east-1";
@@ -93368,6 +93380,28 @@ function toPiThinkingLevelMap(efforts) {
93368
93380
  return map;
93369
93381
  }
93370
93382
 
93383
+ // ../core-utils/dist/cache.js
93384
+ import { randomUUID } from "node:crypto";
93385
+ import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
93386
+ import { dirname } from "node:path";
93387
+ function readJsonFile(path6) {
93388
+ try {
93389
+ return JSON.parse(readFileSync(path6, "utf8"));
93390
+ } catch {
93391
+ return void 0;
93392
+ }
93393
+ }
93394
+ function writeJsonFileAtomic(path6, value, options = {}) {
93395
+ const temporaryPath = `${path6}.${process.pid}.${randomUUID()}.tmp`;
93396
+ try {
93397
+ mkdirSync(dirname(path6), { recursive: true });
93398
+ writeFileSync(temporaryPath, JSON.stringify(value, null, options.pretty ? 2 : void 0), "utf8");
93399
+ renameSync(temporaryPath, path6);
93400
+ } finally {
93401
+ rmSync(temporaryPath, { force: true });
93402
+ }
93403
+ }
93404
+
93371
93405
  // ../devin-core/dist/util.js
93372
93406
  function isRecord(value) {
93373
93407
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -95852,9 +95886,9 @@ var MAX_CONNECT_FRAME_PAYLOAD = 16 * 1024 * 1024;
95852
95886
  var LARGE_HISTORY_RECOVERY_BYTES = 512 * 1024;
95853
95887
 
95854
95888
  // ../devin-core/dist/credentials.js
95855
- import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
95889
+ import { mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
95856
95890
  import { homedir } from "node:os";
95857
- import { dirname, join } from "node:path";
95891
+ import { dirname as dirname2, join } from "node:path";
95858
95892
 
95859
95893
  // ../devin-core/dist/oauth.js
95860
95894
  var FALLBACK_EXPIRES_MS = 365 * 24 * 60 * 60 * 1e3;
@@ -95895,7 +95929,7 @@ function devinTokenFromToml(text) {
95895
95929
  function resolveDevinCredentials() {
95896
95930
  let text;
95897
95931
  try {
95898
- text = readFileSync(devinCredentialsPath(), "utf8");
95932
+ text = readFileSync2(devinCredentialsPath(), "utf8");
95899
95933
  } catch {
95900
95934
  return void 0;
95901
95935
  }
@@ -96257,9 +96291,9 @@ function normalizeDevinModels(configs, baseUrlOverride) {
96257
96291
  }
96258
96292
 
96259
96293
  // ../devin-core/dist/models.js
96260
- import { mkdirSync as mkdirSync2, readFileSync as readFileSync2, statSync, writeFileSync as writeFileSync2 } from "node:fs";
96294
+ import { statSync } from "node:fs";
96261
96295
  import { homedir as homedir2 } from "node:os";
96262
- import { dirname as dirname2, join as join2 } from "node:path";
96296
+ import { join as join2 } from "node:path";
96263
96297
  var devinModels = [
96264
96298
  {
96265
96299
  id: "swe-1-6",
@@ -96302,7 +96336,7 @@ function loadCacheFile() {
96302
96336
  const mtimeMs = statSync(devinModelCachePath()).mtimeMs;
96303
96337
  if (mtimeMs !== cacheMtimeMs) {
96304
96338
  cacheMtimeMs = mtimeMs;
96305
- const parsed = JSON.parse(readFileSync2(devinModelCachePath(), "utf8"));
96339
+ const parsed = readJsonFile(devinModelCachePath());
96306
96340
  cacheFile = typeof parsed === "object" && parsed !== null && Array.isArray(parsed.models) && typeof parsed.fetchedAt === "number" ? parsed : void 0;
96307
96341
  }
96308
96342
  } catch {
@@ -96321,8 +96355,7 @@ function isCacheStale(now = Date.now()) {
96321
96355
  function updateDevinModelsCache(models, now = Date.now()) {
96322
96356
  cacheFile = { fetchedAt: now, models };
96323
96357
  try {
96324
- mkdirSync2(dirname2(devinModelCachePath()), { recursive: true });
96325
- writeFileSync2(devinModelCachePath(), JSON.stringify(cacheFile), "utf8");
96358
+ writeJsonFileAtomic(devinModelCachePath(), cacheFile);
96326
96359
  cacheMtimeMs = statSync(devinModelCachePath()).mtimeMs;
96327
96360
  } catch {
96328
96361
  }
@@ -96383,6 +96416,24 @@ async function refreshDevinModels(options = {}) {
96383
96416
  return { models: getCachedModels().map(toPiDevinModel), fromCache };
96384
96417
  }
96385
96418
 
96419
+ // ../grok-core/dist/catalog.js
96420
+ var GROK_BOOTSTRAP_MODEL_IDS = ["grok-4.7", "grok-4.7-build-fast", "grok-4.6", "grok-4.5"];
96421
+ var GROK_DEFAULT_CONTEXT_WINDOW = 5e5;
96422
+ var GROK_DEFAULT_MAX_TOKENS = 128e3;
96423
+ var GROK_CATALOG_PROVIDER_ID = "grok";
96424
+ var GROK_DEFAULT_MODEL_ID = "grok-4.5";
96425
+ var GROK_CATALOG_FILE = `${GROK_CATALOG_PROVIDER_ID}.models.json`;
96426
+ function grokBootstrapModels() {
96427
+ return GROK_BOOTSTRAP_MODEL_IDS.map((id) => ({
96428
+ id,
96429
+ name: id,
96430
+ contextWindow: GROK_DEFAULT_CONTEXT_WINDOW,
96431
+ maxTokens: GROK_DEFAULT_MAX_TOKENS,
96432
+ reasoning: true,
96433
+ input: ["text"]
96434
+ }));
96435
+ }
96436
+
96386
96437
  // ../pi-provider/src/shared/types.ts
96387
96438
  function ensureCacheCost(cost) {
96388
96439
  return {
@@ -96394,7 +96445,7 @@ function ensureCacheCost(cost) {
96394
96445
  }
96395
96446
 
96396
96447
  // ../pi-provider/src/shared/catalog-cache.ts
96397
- import { mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync, writeFileSync as writeFileSync3, existsSync as existsSync2 } from "node:fs";
96448
+ import { mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync3, existsSync as existsSync2 } from "node:fs";
96398
96449
  import { join as join3 } from "node:path";
96399
96450
  import { homedir as homedir3 } from "node:os";
96400
96451
  var DEFAULT_TTL_MS = 15 * 60 * 1e3;
@@ -96418,7 +96469,7 @@ var CatalogCache = class {
96418
96469
  mkdirSync: options.fs?.mkdirSync ?? ((path6, opts) => {
96419
96470
  mkdirSync3(path6, opts);
96420
96471
  }),
96421
- renameSync: options.fs?.renameSync ?? renameSync,
96472
+ renameSync: options.fs?.renameSync ?? renameSync2,
96422
96473
  existsSync: options.fs?.existsSync ?? existsSync2
96423
96474
  };
96424
96475
  }
@@ -96534,12 +96585,13 @@ function getDefaultCatalogCache(options) {
96534
96585
  return defaultCache;
96535
96586
  }
96536
96587
 
96537
- // ../pi-provider/src/grok/binary.ts
96588
+ // ../grok-core/dist/agent/binary.js
96589
+ import { execFile } from "node:child_process";
96538
96590
  import { accessSync, constants } from "node:fs";
96539
- import { execFileSync } from "node:child_process";
96540
96591
  import { homedir as homedir4 } from "node:os";
96541
96592
  import { join as join4 } from "node:path";
96542
96593
  var CANDIDATE_NAMES = ["agent", "grok"];
96594
+ var BINARY_ENV_NAMES = ["GROK_AGENT_BIN", "GROK_BIN", "PI_GROK_SDK_BIN", "PI_GROK_AGENT_BIN"];
96543
96595
  function isExecutable(path6) {
96544
96596
  try {
96545
96597
  accessSync(path6, constants.X_OK);
@@ -96548,59 +96600,44 @@ function isExecutable(path6) {
96548
96600
  return false;
96549
96601
  }
96550
96602
  }
96551
- function which(name) {
96552
- try {
96553
- const out = execFileSync(process.platform === "win32" ? "where" : "which", [name], {
96554
- encoding: "utf8",
96555
- stdio: ["ignore", "pipe", "pipe"],
96556
- timeout: 5e3
96557
- }).trim();
96558
- const first = out.split(/\r?\n/).map((l) => l.trim()).find(Boolean);
96559
- return first && isExecutable(first) ? first : void 0;
96560
- } catch {
96603
+ function run(command, args, timeout) {
96604
+ return new Promise((resolve2) => {
96605
+ execFile(command, args, { encoding: "utf8", timeout }, (error, stdout) => {
96606
+ resolve2(error ? void 0 : stdout);
96607
+ });
96608
+ });
96609
+ }
96610
+ async function which(name) {
96611
+ const out = await run(process.platform === "win32" ? "where" : "which", [name], 5e3);
96612
+ if (out === void 0)
96561
96613
  return void 0;
96562
- }
96614
+ const first = out.trim().split(/\r?\n/).map((line) => line.trim()).find(Boolean);
96615
+ return first && isExecutable(first) ? first : void 0;
96563
96616
  }
96564
- function resolveGrokBinary(env3 = process.env) {
96565
- const explicit = env3.PI_GROK_SDK_BIN?.trim() || env3.PI_GROK_AGENT_BIN?.trim() || env3.GROK_AGENT_BIN?.trim() || env3.GROK_BIN?.trim();
96617
+ async function resolveGrokBinary(env3 = process.env) {
96618
+ const explicit = BINARY_ENV_NAMES.map((name) => env3[name]?.trim()).find(Boolean);
96566
96619
  if (explicit) {
96567
96620
  if (!isExecutable(explicit)) {
96568
- throw new Error(
96569
- `Configured Grok agent binary is not executable: ${explicit}. Check PI_GROK_SDK_BIN / PI_GROK_AGENT_BIN / GROK_AGENT_BIN.`
96570
- );
96621
+ throw new Error(`Configured Grok agent binary is not executable: ${explicit}. Check ${BINARY_ENV_NAMES.join(" / ")}.`);
96571
96622
  }
96572
96623
  return explicit;
96573
96624
  }
96574
96625
  for (const name of CANDIDATE_NAMES) {
96575
- const found = which(name);
96576
- if (found) return found;
96626
+ const found = await which(name);
96627
+ if (found)
96628
+ return found;
96577
96629
  }
96578
96630
  const homeBin = join4(homedir4(), ".grok", "bin");
96579
96631
  for (const name of CANDIDATE_NAMES) {
96580
96632
  const candidate = join4(homeBin, name);
96581
- if (isExecutable(candidate)) return candidate;
96633
+ if (isExecutable(candidate))
96634
+ return candidate;
96582
96635
  }
96583
- throw new Error(
96584
- "Grok agent CLI not found. Install/authenticate the xAI Grok agent (`agent` or `grok` on PATH, or ~/.grok/bin). Then run: agent --version"
96585
- );
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");
96586
96637
  }
96587
96638
 
96588
- // ../pi-provider/src/grok/config.ts
96589
- var DEFAULT_MODEL_ID = "grok-4.5";
96590
- var THINKING_LEVEL_MAP = {
96591
- off: "none",
96592
- minimal: "minimal",
96593
- low: "low",
96594
- medium: "medium",
96595
- high: "high",
96596
- xhigh: "xhigh",
96597
- max: "max"
96598
- };
96599
- var DEFAULT_CONTEXT_WINDOW2 = 5e5;
96600
- var DEFAULT_MAX_TOKENS2 = 128e3;
96601
-
96602
- // ../pi-provider/src/grok/models.ts
96603
- import { execFileSync as execFileSync2 } from "node:child_process";
96639
+ // ../grok-core/dist/agent/models.js
96640
+ import { execFile as execFile2 } from "node:child_process";
96604
96641
  function parseGrokModelsOutput(stdout) {
96605
96642
  const models = [];
96606
96643
  const seen = /* @__PURE__ */ new Set();
@@ -96615,8 +96652,8 @@ function parseGrokModelsOutput(stdout) {
96615
96652
  models.push({
96616
96653
  id,
96617
96654
  name: id,
96618
- contextWindow: DEFAULT_CONTEXT_WINDOW2,
96619
- maxTokens: DEFAULT_MAX_TOKENS2,
96655
+ contextWindow: GROK_DEFAULT_CONTEXT_WINDOW,
96656
+ maxTokens: GROK_DEFAULT_MAX_TOKENS,
96620
96657
  supportsReasoningEffort: true
96621
96658
  });
96622
96659
  }
@@ -96628,45 +96665,68 @@ function parseGrokModelsOutput(stdout) {
96628
96665
  models.unshift({
96629
96666
  id: d[1],
96630
96667
  name: d[1],
96631
- contextWindow: DEFAULT_CONTEXT_WINDOW2,
96632
- maxTokens: DEFAULT_MAX_TOKENS2,
96668
+ contextWindow: GROK_DEFAULT_CONTEXT_WINDOW,
96669
+ maxTokens: GROK_DEFAULT_MAX_TOKENS,
96633
96670
  supportsReasoningEffort: true
96634
96671
  });
96635
96672
  }
96636
96673
  }
96637
96674
  return models;
96638
96675
  }
96639
- var BOOTSTRAP_MODEL_IDS = ["grok-4.7", "grok-4.7-build-fast", "grok-4.6", "grok-4.5"];
96640
- function fallbackModels() {
96641
- return BOOTSTRAP_MODEL_IDS.map((id) => ({
96642
- id,
96643
- name: id,
96644
- contextWindow: DEFAULT_CONTEXT_WINDOW2,
96645
- maxTokens: DEFAULT_MAX_TOKENS2,
96646
- supportsReasoningEffort: true
96647
- }));
96648
- }
96649
- function discoverModels(binary) {
96676
+ async function discoverGrokModels(binary) {
96650
96677
  try {
96651
- const bin = binary ?? resolveGrokBinary();
96652
- const stdout = execFileSync2(bin, ["models"], {
96653
- encoding: "utf8",
96654
- stdio: ["ignore", "pipe", "pipe"],
96655
- timeout: 2e4
96678
+ const bin = binary ?? await resolveGrokBinary();
96679
+ const stdout = await new Promise((resolve2, reject) => {
96680
+ execFile2(bin, ["models"], { encoding: "utf8", timeout: 2e4 }, (error, out) => {
96681
+ if (error)
96682
+ reject(error);
96683
+ else
96684
+ resolve2(out);
96685
+ });
96656
96686
  });
96657
96687
  const parsed = parseGrokModelsOutput(stdout);
96658
96688
  if (parsed.length === 0) {
96659
- return { models: fallbackModels(), source: "fallback", error: "empty model list from CLI" };
96689
+ return { models: [], source: "fallback", error: "empty model list from CLI" };
96660
96690
  }
96661
96691
  return { models: parsed, source: "live" };
96662
96692
  } catch (err) {
96663
96693
  return {
96664
- models: fallbackModels(),
96694
+ models: [],
96665
96695
  source: "fallback",
96666
96696
  error: err instanceof Error ? err.message : String(err)
96667
96697
  };
96668
96698
  }
96669
96699
  }
96700
+
96701
+ // ../pi-provider/src/grok/config.ts
96702
+ var DEFAULT_MODEL_ID = GROK_DEFAULT_MODEL_ID;
96703
+ var THINKING_LEVEL_MAP = {
96704
+ off: "none",
96705
+ minimal: "minimal",
96706
+ low: "low",
96707
+ medium: "medium",
96708
+ high: "high",
96709
+ xhigh: "xhigh",
96710
+ max: "max"
96711
+ };
96712
+ var DEFAULT_CONTEXT_WINDOW2 = GROK_DEFAULT_CONTEXT_WINDOW;
96713
+ var DEFAULT_MAX_TOKENS2 = GROK_DEFAULT_MAX_TOKENS;
96714
+
96715
+ // ../pi-provider/src/grok/models.ts
96716
+ function fallbackModels() {
96717
+ return grokBootstrapModels().map((model) => ({
96718
+ id: model.id,
96719
+ name: model.name,
96720
+ contextWindow: model.contextWindow,
96721
+ maxTokens: model.maxTokens,
96722
+ supportsReasoningEffort: model.reasoning
96723
+ }));
96724
+ }
96725
+ async function discoverModels(binary) {
96726
+ const discovered = await discoverGrokModels(binary);
96727
+ if (discovered.source === "live") return discovered;
96728
+ return { ...discovered, models: fallbackModels() };
96729
+ }
96670
96730
  function toProviderModel(d) {
96671
96731
  return {
96672
96732
  id: d.id,
@@ -98455,50 +98515,6 @@ function registerBuiltInApiProviders() {
98455
98515
  registerBuiltInApiProviders();
98456
98516
  var compatModels = builtinModels();
98457
98517
 
98458
- // ../pi-provider/src/grok/prompt.ts
98459
- var GROK_BRIDGE_NOTE = [
98460
- "[grok bridge] You are the Grok coding agent, running behind an external coding harness that only relays your messages.",
98461
- "Tools named in the harness instructions below (read, bash, edit, write, \u2026) are not callable from here.",
98462
- "Use your own built-in tools (read_file, grep, search_replace, write, run_terminal_command, \u2026) directly in the working directory.",
98463
- "When the task needs file changes or commands, perform them with those tools instead of describing them or writing tool calls as text."
98464
- ].join("\n");
98465
-
98466
- // ../pi-provider/src/grok/session-scope.ts
98467
- var state2 = {
98468
- cwd: process.cwd(),
98469
- sessionFile: void 0,
98470
- sessionId: void 0,
98471
- generation: 0
98472
- };
98473
-
98474
- // ../pi-provider/src/grok/tool-activity.ts
98475
- var MAX_OUTPUT = 64 * 1024;
98476
-
98477
- // ../pi-provider/src/grok/host-tools.ts
98478
- var REPLACE_SCRIPT = [
98479
- "import json,sys,base64,pathlib",
98480
- "p=json.loads(base64.b64decode(sys.argv[2]))",
98481
- "path=p['path']",
98482
- "old=p['old']",
98483
- "new=p['new']",
98484
- "replace_all=bool(p.get('all'))",
98485
- "file=pathlib.Path(path)",
98486
- "text=file.read_text()",
98487
- "if old=='':",
98488
- " sys.stderr.write('old text is empty\\n')",
98489
- " sys.exit(1)",
98490
- "count=text.count(old)",
98491
- "if count==0:",
98492
- " sys.stderr.write('old text not found\\n')",
98493
- " sys.exit(1)",
98494
- "if not replace_all and count!=1:",
98495
- " sys.stderr.write('old text appears %d times\\n' % count)",
98496
- " sys.exit(1)",
98497
- "updated=text.replace(old, new) if replace_all else text.replace(old, new, 1)",
98498
- "file.write_text(updated)",
98499
- "print('Updated '+path)"
98500
- ].join("\n");
98501
-
98502
98518
  // ../pi-provider/src/grok/register.ts
98503
98519
  var GROK_PROVIDER_ID = "grok";
98504
98520
  var GROK_API = "grok-cli";
@@ -98531,7 +98547,7 @@ function catalogToProviderModels(models) {
98531
98547
  cost: ensureCacheCost(models[i2]?.cost ?? m2.cost)
98532
98548
  }));
98533
98549
  }
98534
- function refreshGrokModels(options = {}) {
98550
+ async function refreshGrokModels(options = {}) {
98535
98551
  const cache = options.cache ?? getDefaultCatalogCache();
98536
98552
  if (!options.force) {
98537
98553
  const lookup = cache.lookup(GROK_PROVIDER_ID);
@@ -98566,11 +98582,11 @@ function refreshGrokModels(options = {}) {
98566
98582
  }
98567
98583
  let binary = options.binary;
98568
98584
  try {
98569
- binary ??= resolveGrokBinary();
98585
+ binary ??= await resolveGrokBinary();
98570
98586
  } catch {
98571
98587
  binary = void 0;
98572
98588
  }
98573
- const discovered = discoverModels(binary);
98589
+ const discovered = await discoverModels(binary);
98574
98590
  const catalog = descriptorsToCatalog(discovered.models);
98575
98591
  cache.store(GROK_PROVIDER_ID, catalog, { version: "grok-cli-v1" });
98576
98592
  return {
@@ -98582,6 +98598,100 @@ function refreshGrokModels(options = {}) {
98582
98598
 
98583
98599
  // ../kiro-core/dist/index.js
98584
98600
  init_debug();
98601
+ init_endpoints();
98602
+
98603
+ // ../kiro-core/dist/retry.js
98604
+ var KIRO_REASON_CODES = Object.freeze({
98605
+ /** Request body exceeded the service's size threshold. */
98606
+ CONTENT_LENGTH_EXCEEDS_THRESHOLD: "CONTENT_LENGTH_EXCEEDS_THRESHOLD",
98607
+ /** Prose-only size rejection; the service sends no reason code for this one. */
98608
+ INPUT_TOO_LONG: "Input is too long",
98609
+ /** Monthly request quota exhausted — hard limit, not transient. */
98610
+ MONTHLY_REQUEST_COUNT: "MONTHLY_REQUEST_COUNT",
98611
+ /** Model capacity temporarily unavailable — transient, worth retrying. */
98612
+ INSUFFICIENT_MODEL_CAPACITY: "INSUFFICIENT_MODEL_CAPACITY",
98613
+ /** Short-window request throttle — retry only within the provider budget. */
98614
+ USER_REQUEST_RATE_EXCEEDED: "USER_REQUEST_RATE_EXCEEDED",
98615
+ /**
98616
+ * Generic request-validation rejection, returned for a malformed body of any
98617
+ * size (empty `content`, history referencing tools absent from the catalog).
98618
+ * Not a size signal: classifying it as "too big" makes the caller compact a
98619
+ * history that was never the problem, a loop it can never satisfy.
98620
+ */
98621
+ REQUEST_BODY_INVALID: "REQUEST_BODY_INVALID"
98622
+ });
98623
+ var TOO_BIG_PATTERNS = Object.freeze([
98624
+ KIRO_REASON_CODES.CONTENT_LENGTH_EXCEEDS_THRESHOLD,
98625
+ KIRO_REASON_CODES.INPUT_TOO_LONG
98626
+ ]);
98627
+ var NON_RETRYABLE_BODY_PATTERNS = Object.freeze([KIRO_REASON_CODES.MONTHLY_REQUEST_COUNT]);
98628
+ var CAPACITY_PATTERN = KIRO_REASON_CODES.INSUFFICIENT_MODEL_CAPACITY;
98629
+
98630
+ // ../kiro-core/dist/errors.js
98631
+ var REASON_CODE_MARKERS = [
98632
+ KIRO_REASON_CODES.CONTENT_LENGTH_EXCEEDS_THRESHOLD,
98633
+ KIRO_REASON_CODES.MONTHLY_REQUEST_COUNT,
98634
+ KIRO_REASON_CODES.INSUFFICIENT_MODEL_CAPACITY,
98635
+ KIRO_REASON_CODES.REQUEST_BODY_INVALID
98636
+ ];
98637
+
98638
+ // ../kiro-core/dist/event-parser.js
98639
+ var KIRO_EVENT_KEYS = [
98640
+ "assistantResponseEvent",
98641
+ "codeReferenceEvent",
98642
+ "contextUsageEvent",
98643
+ "documentCitationEvent",
98644
+ "error",
98645
+ "metadataEvent",
98646
+ "meteringEvent",
98647
+ "reasoningContentEvent",
98648
+ "serviceUnavailableError",
98649
+ "throttlingError",
98650
+ "toolResultEvent",
98651
+ "toolUseEvent",
98652
+ "validationError"
98653
+ ];
98654
+ var KIRO_EVENT_KEY_SET = new Set(KIRO_EVENT_KEYS);
98655
+ var KIRO_ERROR_MEMBERS = {
98656
+ error: { kind: "internalServer", exception: "InternalServerException" },
98657
+ throttlingError: { kind: "throttling", exception: "ThrottlingException" },
98658
+ validationError: { kind: "validation", exception: "ValidationException" },
98659
+ serviceUnavailableError: { kind: "serviceUnavailable", exception: "ServiceUnavailableException" }
98660
+ };
98661
+ var KIRO_ERROR_TOKENS = {
98662
+ ...KIRO_ERROR_MEMBERS,
98663
+ InternalServerException: KIRO_ERROR_MEMBERS.error,
98664
+ ThrottlingException: KIRO_ERROR_MEMBERS.throttlingError,
98665
+ ValidationException: KIRO_ERROR_MEMBERS.validationError,
98666
+ ServiceUnavailableException: KIRO_ERROR_MEMBERS.serviceUnavailableError
98667
+ };
98668
+
98669
+ // ../kiro-core/dist/host-auth.js
98670
+ init_endpoints();
98671
+ init_oauth();
98672
+ async function resolveKiroRequestCredentials(hostKey) {
98673
+ const stored = await resolveKiroCredentials();
98674
+ const region = resolveApiRegion(stored?.region);
98675
+ if (hostKey && (isApiKey(hostKey) || hostKey === stored?.access)) {
98676
+ return { accessToken: hostKey, region, ...stored?.profileArn ? { profileArn: stored.profileArn } : {} };
98677
+ }
98678
+ if (stored) {
98679
+ return {
98680
+ accessToken: stored.access,
98681
+ region,
98682
+ ...stored.profileArn ? { profileArn: stored.profileArn } : {}
98683
+ };
98684
+ }
98685
+ if (hostKey)
98686
+ return { accessToken: hostKey, region };
98687
+ throw new Error("Kiro credentials not set. Run `kiro-cli login`, or set KIRO_API_KEY to a `ksk_` API key.");
98688
+ }
98689
+
98690
+ // ../kiro-core/dist/models.js
98691
+ 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";
98585
98695
 
98586
98696
  // ../kiro-core/dist/types.js
98587
98697
  var KIRO_EFFORT_ORDER = ["minimal", "low", "medium", "high", "xhigh", "max"];
@@ -98645,14 +98755,7 @@ function getKiroEffortConfig(schema, kiroModelId) {
98645
98755
  return fallbackKiroEffort(kiroModelId);
98646
98756
  }
98647
98757
 
98648
- // ../kiro-core/dist/index.js
98649
- init_endpoints();
98650
-
98651
98758
  // ../kiro-core/dist/models.js
98652
- import { randomUUID as randomUUID2 } from "node:crypto";
98653
- import { existsSync as existsSync5, readFileSync as readFileSync6, renameSync as renameSync2, rmSync, writeFileSync as writeFileSync4 } from "node:fs";
98654
- import { homedir as homedir8 } from "node:os";
98655
- import { join as join9 } from "node:path";
98656
98759
  init_endpoints();
98657
98760
  var KIRO_MANAGEMENT_CACHE_VERSION = 1;
98658
98761
  var KIRO_MANAGEMENT_CACHE_SOURCE = "ns-kiro-provider-management";
@@ -98935,12 +99038,12 @@ function readManagementCache() {
98935
99038
  }
98936
99039
  }
98937
99040
  function writeManagementCache(cache) {
98938
- const temporaryPath = `${KIRO_MANAGEMENT_CACHE_PATH}.${process.pid}.${randomUUID2()}.tmp`;
99041
+ const temporaryPath = `${KIRO_MANAGEMENT_CACHE_PATH}.${process.pid}.${randomUUID3()}.tmp`;
98939
99042
  try {
98940
99043
  writeFileSync4(temporaryPath, JSON.stringify(cache, null, 2), "utf-8");
98941
- renameSync2(temporaryPath, KIRO_MANAGEMENT_CACHE_PATH);
99044
+ renameSync3(temporaryPath, KIRO_MANAGEMENT_CACHE_PATH);
98942
99045
  } finally {
98943
- rmSync(temporaryPath, { force: true });
99046
+ rmSync2(temporaryPath, { force: true });
98944
99047
  }
98945
99048
  }
98946
99049
  function toLocalModelId(kiroModelId) {
@@ -99058,10 +99161,6 @@ function isCacheStale2(region) {
99058
99161
  return !entry || Date.now() - entry.fetchedAt > CACHE_MAX_AGE_MS;
99059
99162
  }
99060
99163
  async function updateKiroModelsCache(accessToken, region, profileArn) {
99061
- await updateKiroModelsCacheInProcess(accessToken, region, profileArn);
99062
- refreshKnownModelIds(readManagementCache());
99063
- }
99064
- async function updateKiroModelsCacheInProcess(accessToken, region, profileArn) {
99065
99164
  const { fetchKiroModelCatalog: fetchKiroModelCatalog2 } = await Promise.resolve().then(() => (init_management(), management_exports));
99066
99165
  const { getKiroCliModelRates: getKiroCliModelRates2 } = await Promise.resolve().then(() => (init_kiro_cli(), kiro_cli_exports));
99067
99166
  const response = await fetchKiroModelCatalog2({ accessToken, region }, profileArn);
@@ -99076,71 +99175,15 @@ async function updateKiroModelsCacheInProcess(accessToken, region, profileArn) {
99076
99175
  refreshKnownModelIds(cache);
99077
99176
  }
99078
99177
 
99079
- // ../kiro-core/dist/retry.js
99080
- var KIRO_REASON_CODES = Object.freeze({
99081
- /** Request body exceeded the service's size threshold. */
99082
- CONTENT_LENGTH_EXCEEDS_THRESHOLD: "CONTENT_LENGTH_EXCEEDS_THRESHOLD",
99083
- /** Prose-only size rejection; the service sends no reason code for this one. */
99084
- INPUT_TOO_LONG: "Input is too long",
99085
- /** Monthly request quota exhausted — hard limit, not transient. */
99086
- MONTHLY_REQUEST_COUNT: "MONTHLY_REQUEST_COUNT",
99087
- /** Model capacity temporarily unavailable — transient, worth retrying. */
99088
- INSUFFICIENT_MODEL_CAPACITY: "INSUFFICIENT_MODEL_CAPACITY",
99089
- /** Short-window request throttle — retry only within the provider budget. */
99090
- USER_REQUEST_RATE_EXCEEDED: "USER_REQUEST_RATE_EXCEEDED",
99091
- /**
99092
- * Generic request-validation rejection, returned for a malformed body of any
99093
- * size (empty `content`, history referencing tools absent from the catalog).
99094
- * Not a size signal: classifying it as "too big" makes the caller compact a
99095
- * history that was never the problem, a loop it can never satisfy.
99096
- */
99097
- REQUEST_BODY_INVALID: "REQUEST_BODY_INVALID"
99098
- });
99099
- var TOO_BIG_PATTERNS = Object.freeze([
99100
- KIRO_REASON_CODES.CONTENT_LENGTH_EXCEEDS_THRESHOLD,
99101
- KIRO_REASON_CODES.INPUT_TOO_LONG
99102
- ]);
99103
- var NON_RETRYABLE_BODY_PATTERNS = Object.freeze([KIRO_REASON_CODES.MONTHLY_REQUEST_COUNT]);
99104
- var CAPACITY_PATTERN = KIRO_REASON_CODES.INSUFFICIENT_MODEL_CAPACITY;
99178
+ // ../kiro-core/dist/index.js
99179
+ init_kiro_cli();
99180
+ init_oauth();
99105
99181
 
99106
- // ../kiro-core/dist/errors.js
99107
- var REASON_CODE_MARKERS = [
99108
- KIRO_REASON_CODES.CONTENT_LENGTH_EXCEEDS_THRESHOLD,
99109
- KIRO_REASON_CODES.MONTHLY_REQUEST_COUNT,
99110
- KIRO_REASON_CODES.INSUFFICIENT_MODEL_CAPACITY,
99111
- KIRO_REASON_CODES.REQUEST_BODY_INVALID
99112
- ];
99182
+ // ../kiro-core/dist/request-builder.js
99183
+ init_debug();
99113
99184
 
99114
- // ../kiro-core/dist/event-parser.js
99115
- var KIRO_EVENT_KEYS = [
99116
- "assistantResponseEvent",
99117
- "codeReferenceEvent",
99118
- "contextUsageEvent",
99119
- "documentCitationEvent",
99120
- "error",
99121
- "metadataEvent",
99122
- "meteringEvent",
99123
- "reasoningContentEvent",
99124
- "serviceUnavailableError",
99125
- "throttlingError",
99126
- "toolResultEvent",
99127
- "toolUseEvent",
99128
- "validationError"
99129
- ];
99130
- var KIRO_EVENT_KEY_SET = new Set(KIRO_EVENT_KEYS);
99131
- var KIRO_ERROR_MEMBERS = {
99132
- error: { kind: "internalServer", exception: "InternalServerException" },
99133
- throttlingError: { kind: "throttling", exception: "ThrottlingException" },
99134
- validationError: { kind: "validation", exception: "ValidationException" },
99135
- serviceUnavailableError: { kind: "serviceUnavailable", exception: "ServiceUnavailableException" }
99136
- };
99137
- var KIRO_ERROR_TOKENS = {
99138
- ...KIRO_ERROR_MEMBERS,
99139
- InternalServerException: KIRO_ERROR_MEMBERS.error,
99140
- ThrottlingException: KIRO_ERROR_MEMBERS.throttlingError,
99141
- ValidationException: KIRO_ERROR_MEMBERS.validationError,
99142
- ServiceUnavailableException: KIRO_ERROR_MEMBERS.serviceUnavailableError
99143
- };
99185
+ // ../kiro-core/dist/history.js
99186
+ var HISTORY_IMAGE_BASE64_LIMIT = 512 * 1024;
99144
99187
 
99145
99188
  // ../kiro-core/dist/history-validator.js
99146
99189
  var KiroValidationRule;
@@ -99168,39 +99211,6 @@ var KIRO_TOOL_STRUCTURE_RULES = [
99168
99211
  KiroValidationRule.TOOL_RESULTS_ORPHAN_IDS
99169
99212
  ];
99170
99213
 
99171
- // ../kiro-core/dist/host-auth.js
99172
- init_endpoints();
99173
- init_oauth();
99174
- async function resolveKiroRequestCredentials(hostKey) {
99175
- const stored = await resolveKiroCredentials();
99176
- const region = resolveApiRegion(stored?.region);
99177
- if (hostKey && (isApiKey(hostKey) || hostKey === stored?.access)) {
99178
- return { accessToken: hostKey, region, ...stored?.profileArn ? { profileArn: stored.profileArn } : {} };
99179
- }
99180
- if (stored) {
99181
- return {
99182
- accessToken: stored.access,
99183
- region,
99184
- ...stored.profileArn ? { profileArn: stored.profileArn } : {}
99185
- };
99186
- }
99187
- if (hostKey)
99188
- return { accessToken: hostKey, region };
99189
- throw new Error("Kiro credentials not set. Run `kiro-cli login`, or set KIRO_API_KEY to a `ksk_` API key.");
99190
- }
99191
-
99192
- // ../kiro-core/dist/index.js
99193
- init_kiro_cli();
99194
- init_kiro_ide();
99195
- init_management();
99196
- init_oauth();
99197
-
99198
- // ../kiro-core/dist/request-builder.js
99199
- init_debug();
99200
-
99201
- // ../kiro-core/dist/history.js
99202
- var HISTORY_IMAGE_BASE64_LIMIT = 512 * 1024;
99203
-
99204
99214
  // ../kiro-core/dist/response-assembler.js
99205
99215
  init_debug();
99206
99216
 
@@ -99213,10 +99223,14 @@ init_debug();
99213
99223
  import { createRequire as createRequire3 } from "node:module";
99214
99224
  var require4 = createRequire3(import.meta.url);
99215
99225
 
99226
+ // ../kiro-core/dist/credential-rotation.js
99227
+ init_kiro_cli();
99228
+ init_management();
99229
+
99216
99230
  // ../kiro-core/dist/stream.js
99217
99231
  init_debug();
99218
99232
  init_endpoints();
99219
- init_kiro_cli();
99233
+ init_http();
99220
99234
  init_management();
99221
99235
  init_oauth();
99222
99236
  init_token_type();
@@ -99302,7 +99316,7 @@ function createBundledRefresh() {
99302
99316
  return { count: refreshed.models.length };
99303
99317
  },
99304
99318
  grok: async () => {
99305
- const refreshed = refreshGrokModels({ force: true });
99319
+ const refreshed = await refreshGrokModels({ force: true });
99306
99320
  return { count: refreshed.models.length, detail: `source=${refreshed.source}` };
99307
99321
  }
99308
99322
  };