@ljoukov/llm 4.0.11 → 4.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -7327,8 +7327,6 @@ async function runToolLoop(request) {
7327
7327
  let thoughtsText2 = "";
7328
7328
  const modelParts = [];
7329
7329
  const functionCalls = [];
7330
- const seenFunctionCallIds = /* @__PURE__ */ new Set();
7331
- const seenFunctionCallKeys = /* @__PURE__ */ new Set();
7332
7330
  let latestUsageMetadata;
7333
7331
  let resolvedModelVersion;
7334
7332
  for await (const chunk of stream) {
@@ -7345,34 +7343,13 @@ async function runToolLoop(request) {
7345
7343
  continue;
7346
7344
  }
7347
7345
  const primary = candidates[0];
7348
- const parts = primary?.content?.parts;
7349
- if (!parts || parts.length === 0) {
7346
+ const parts = primary?.content?.parts ?? [];
7347
+ const chunkFunctionCalls = chunk.functionCalls ?? [];
7348
+ if (parts.length === 0 && chunkFunctionCalls.length === 0) {
7350
7349
  continue;
7351
7350
  }
7352
7351
  for (const part of parts) {
7353
7352
  modelParts.push(part);
7354
- const call = part.functionCall;
7355
- if (call) {
7356
- const id = typeof call.id === "string" ? call.id : "";
7357
- const shouldAdd = (() => {
7358
- if (id.length > 0) {
7359
- if (seenFunctionCallIds.has(id)) {
7360
- return false;
7361
- }
7362
- seenFunctionCallIds.add(id);
7363
- return true;
7364
- }
7365
- const key = JSON.stringify({ name: call.name ?? "", args: call.args ?? null });
7366
- if (seenFunctionCallKeys.has(key)) {
7367
- return false;
7368
- }
7369
- seenFunctionCallKeys.add(key);
7370
- return true;
7371
- })();
7372
- if (shouldAdd) {
7373
- functionCalls.push(call);
7374
- }
7375
- }
7376
7353
  if (typeof part.text === "string" && part.text.length > 0) {
7377
7354
  if (part.thought) {
7378
7355
  thoughtsText2 += part.text;
@@ -7385,6 +7362,15 @@ async function runToolLoop(request) {
7385
7362
  }
7386
7363
  }
7387
7364
  }
7365
+ if (chunkFunctionCalls.length > 0) {
7366
+ functionCalls.push(...chunkFunctionCalls);
7367
+ continue;
7368
+ }
7369
+ for (const part of parts) {
7370
+ if (part.functionCall) {
7371
+ functionCalls.push(part.functionCall);
7372
+ }
7373
+ }
7388
7374
  }
7389
7375
  return {
7390
7376
  responseText: responseText2,