@vedmalex/ai-connect 0.2.0 → 0.2.1

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.
@@ -2163,6 +2163,7 @@ function normalizeResult(route, output, attempts) {
2163
2163
  attempts,
2164
2164
  ...output.toolCalls ? { toolCalls: output.toolCalls } : {},
2165
2165
  ...output.text !== void 0 ? { text: output.text } : {},
2166
+ ...output.reasoning !== void 0 ? { reasoning: output.reasoning } : {},
2166
2167
  ...output.data !== void 0 ? { data: output.data } : {},
2167
2168
  ...output.usage !== void 0 ? { usage: output.usage } : {}
2168
2169
  };
@@ -5521,6 +5522,9 @@ function extractText(value) {
5521
5522
  return [part];
5522
5523
  }
5523
5524
  if (part && typeof part === "object") {
5525
+ if (part.thought === true) {
5526
+ return [];
5527
+ }
5524
5528
  const candidate = part.text;
5525
5529
  if (typeof candidate === "string") {
5526
5530
  return [candidate];
@@ -5531,6 +5535,22 @@ function extractText(value) {
5531
5535
  }
5532
5536
  return "";
5533
5537
  }
5538
+ function extractThoughts(value) {
5539
+ if (!Array.isArray(value)) {
5540
+ return void 0;
5541
+ }
5542
+ const thoughts = value.flatMap((part) => {
5543
+ if (part && typeof part === "object" && part.thought === true) {
5544
+ const candidate = part.text;
5545
+ if (typeof candidate === "string") {
5546
+ return [candidate];
5547
+ }
5548
+ }
5549
+ return [];
5550
+ });
5551
+ const joined = thoughts.join("\n").trim();
5552
+ return joined.length > 0 ? joined : void 0;
5553
+ }
5534
5554
  function imageAttachmentsFromPayload(payload, ...sources) {
5535
5555
  return extractImagePayloads(payload, ...sources).map(
5536
5556
  (item) => preparePortableFile(item)
@@ -6073,8 +6093,11 @@ async function runGemini(fetchImpl, context) {
6073
6093
  throw classifyApiError(provider, response, payload);
6074
6094
  }
6075
6095
  const data = payload;
6096
+ const geminiThoughts = extractThoughts(data.candidates?.[0]?.content?.parts);
6076
6097
  return {
6077
6098
  text: extractText(data.candidates?.[0]?.content?.parts),
6099
+ // The model's `{ thought: true }` parts, separated from the answer (consumers route this to a thinking UI).
6100
+ ...geminiThoughts ? { reasoning: geminiThoughts } : {},
6078
6101
  data,
6079
6102
  ...geminiToolCallsFromPayload(data).length > 0 ? { toolCalls: geminiToolCallsFromPayload(data) } : {},
6080
6103
  ...(() => {