@gullabs/google 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -98,6 +98,7 @@ interface GeminiPartShape {
98
98
  */
99
99
  thought?: boolean;
100
100
  functionCall?: {
101
+ id?: string;
101
102
  name?: string;
102
103
  args?: unknown;
103
104
  };
@@ -205,12 +206,14 @@ interface GeminiFileDataContentPart {
205
206
  */
206
207
  interface GeminiFunctionCallPart {
207
208
  functionCall: {
209
+ id?: string;
208
210
  name: string;
209
211
  args?: unknown;
210
212
  };
211
213
  }
212
214
  interface GeminiFunctionResponsePart {
213
215
  functionResponse: {
216
+ id?: string;
214
217
  name: string;
215
218
  response: unknown;
216
219
  };
package/dist/index.d.ts CHANGED
@@ -98,6 +98,7 @@ interface GeminiPartShape {
98
98
  */
99
99
  thought?: boolean;
100
100
  functionCall?: {
101
+ id?: string;
101
102
  name?: string;
102
103
  args?: unknown;
103
104
  };
@@ -205,12 +206,14 @@ interface GeminiFileDataContentPart {
205
206
  */
206
207
  interface GeminiFunctionCallPart {
207
208
  functionCall: {
209
+ id?: string;
208
210
  name: string;
209
211
  args?: unknown;
210
212
  };
211
213
  }
212
214
  interface GeminiFunctionResponsePart {
213
215
  functionResponse: {
216
+ id?: string;
214
217
  name: string;
215
218
  response: unknown;
216
219
  };
package/dist/index.js CHANGED
@@ -83,6 +83,31 @@ function normalizeGroundingCitations(groundingMetadata) {
83
83
  return citations;
84
84
  }
85
85
 
86
+ // src/tool-call-id.ts
87
+ function reserveProviderToolCallIds(ids) {
88
+ const reserved = /* @__PURE__ */ new Set();
89
+ for (const id of ids) {
90
+ if (typeof id === "string" && id.length > 0) reserved.add(id);
91
+ }
92
+ return reserved;
93
+ }
94
+ function nextFallbackToolCallId(toolName, counters, reserved, counterKey = toolName) {
95
+ let n = counters.get(counterKey) ?? 0;
96
+ let id;
97
+ do {
98
+ n += 1;
99
+ id = `call_${toolName}_${n}`;
100
+ } while (reserved.has(id));
101
+ counters.set(counterKey, n);
102
+ return id;
103
+ }
104
+ function resolveToolCallId(providerId, toolName, counters, reserved, counterKey) {
105
+ if (typeof providerId === "string" && providerId.length > 0) {
106
+ return providerId;
107
+ }
108
+ return nextFallbackToolCallId(toolName, counters, reserved, counterKey ?? toolName);
109
+ }
110
+
86
111
  // src/flex-fallback.ts
87
112
  var CAPACITY_PATTERNS = [
88
113
  /capacity/i,
@@ -466,6 +491,7 @@ function mapPart(p) {
466
491
  case "tool-call":
467
492
  return {
468
493
  functionCall: {
494
+ id: p.toolCallId,
469
495
  name: p.toolName,
470
496
  args: p.args
471
497
  }
@@ -473,6 +499,7 @@ function mapPart(p) {
473
499
  case "tool-result":
474
500
  return {
475
501
  functionResponse: {
502
+ id: p.toolCallId,
476
503
  name: p.toolName,
477
504
  response: p.isError === true ? { error: p.result } : p.result
478
505
  }
@@ -766,11 +793,21 @@ function geminiAdapter(opts) {
766
793
  const textParts = [];
767
794
  const thoughtParts = [];
768
795
  const toolCalls = [];
796
+ const nameCounts = /* @__PURE__ */ new Map();
797
+ const reservedIds = reserveProviderToolCallIds(
798
+ parts.map((part) => part.functionCall?.id)
799
+ );
769
800
  for (const part of parts) {
770
801
  if (part.functionCall !== void 0 && typeof part.functionCall.name === "string") {
802
+ const toolName = part.functionCall.name;
771
803
  toolCalls.push({
772
- toolCallId: part.functionCall.name,
773
- toolName: part.functionCall.name,
804
+ toolCallId: resolveToolCallId(
805
+ part.functionCall.id,
806
+ toolName,
807
+ nameCounts,
808
+ reservedIds
809
+ ),
810
+ toolName,
774
811
  args: part.functionCall.args ?? {}
775
812
  });
776
813
  }
@@ -3350,7 +3387,7 @@ function convertMediaResolution(mediaResolution, location) {
3350
3387
  }
3351
3388
  return mapMediaResolutionLevel(mediaResolution.level, location);
3352
3389
  }
3353
- function convertPart(part, location) {
3390
+ function convertPart(part, location, nameCounts, reservedIds) {
3354
3391
  const keys = definedKeys(part);
3355
3392
  const baseKeys = keys.filter(
3356
3393
  (key) => key === "text" || key === "inlineData" || key === "fileData"
@@ -3363,7 +3400,7 @@ function convertPart(part, location) {
3363
3400
  }
3364
3401
  return {
3365
3402
  kind: "tool-call",
3366
- toolCallId: fc.name,
3403
+ toolCallId: resolveToolCallId(fc.id, fc.name, nameCounts, reservedIds),
3367
3404
  toolName: fc.name,
3368
3405
  args: fc.args ?? {}
3369
3406
  };
@@ -3375,7 +3412,13 @@ function convertPart(part, location) {
3375
3412
  }
3376
3413
  return {
3377
3414
  kind: "tool-result",
3378
- toolCallId: fr.name,
3415
+ toolCallId: resolveToolCallId(
3416
+ fr.id,
3417
+ fr.name,
3418
+ nameCounts,
3419
+ reservedIds,
3420
+ `result:${fr.name}`
3421
+ ),
3379
3422
  toolName: fr.name,
3380
3423
  result: fr.response ?? null
3381
3424
  };
@@ -3490,6 +3533,15 @@ function convertSystemInstruction(systemInstruction) {
3490
3533
  }
3491
3534
  function geminiContentToMessages(input) {
3492
3535
  const system = input.systemInstruction !== void 0 ? convertSystemInstruction(input.systemInstruction) : void 0;
3536
+ const nameCounts = /* @__PURE__ */ new Map();
3537
+ const reservedIds = reserveProviderToolCallIds(
3538
+ input.contents.flatMap(
3539
+ (content) => (content.parts ?? []).flatMap((part) => {
3540
+ const p = part;
3541
+ return [p.functionCall?.id, p.functionResponse?.id];
3542
+ })
3543
+ )
3544
+ );
3493
3545
  const messages = input.contents.map((content, contentIndex) => {
3494
3546
  const location = `contents[${contentIndex}]`;
3495
3547
  const envelopeExtraKeys = definedKeys(content).filter(
@@ -3502,7 +3554,7 @@ function geminiContentToMessages(input) {
3502
3554
  }
3503
3555
  const role = convertRole(content.role, location);
3504
3556
  const parts = (content.parts ?? []).map(
3505
- (part, partIndex) => convertPart(part, `${location}.parts[${partIndex}]`)
3557
+ (part, partIndex) => convertPart(part, `${location}.parts[${partIndex}]`, nameCounts, reservedIds)
3506
3558
  );
3507
3559
  return { role, parts };
3508
3560
  });