@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.cjs +58 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +58 -6
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -85,6 +85,31 @@ function normalizeGroundingCitations(groundingMetadata) {
|
|
|
85
85
|
return citations;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
// src/tool-call-id.ts
|
|
89
|
+
function reserveProviderToolCallIds(ids) {
|
|
90
|
+
const reserved = /* @__PURE__ */ new Set();
|
|
91
|
+
for (const id of ids) {
|
|
92
|
+
if (typeof id === "string" && id.length > 0) reserved.add(id);
|
|
93
|
+
}
|
|
94
|
+
return reserved;
|
|
95
|
+
}
|
|
96
|
+
function nextFallbackToolCallId(toolName, counters, reserved, counterKey = toolName) {
|
|
97
|
+
let n = counters.get(counterKey) ?? 0;
|
|
98
|
+
let id;
|
|
99
|
+
do {
|
|
100
|
+
n += 1;
|
|
101
|
+
id = `call_${toolName}_${n}`;
|
|
102
|
+
} while (reserved.has(id));
|
|
103
|
+
counters.set(counterKey, n);
|
|
104
|
+
return id;
|
|
105
|
+
}
|
|
106
|
+
function resolveToolCallId(providerId, toolName, counters, reserved, counterKey) {
|
|
107
|
+
if (typeof providerId === "string" && providerId.length > 0) {
|
|
108
|
+
return providerId;
|
|
109
|
+
}
|
|
110
|
+
return nextFallbackToolCallId(toolName, counters, reserved, counterKey ?? toolName);
|
|
111
|
+
}
|
|
112
|
+
|
|
88
113
|
// src/flex-fallback.ts
|
|
89
114
|
var CAPACITY_PATTERNS = [
|
|
90
115
|
/capacity/i,
|
|
@@ -468,6 +493,7 @@ function mapPart(p) {
|
|
|
468
493
|
case "tool-call":
|
|
469
494
|
return {
|
|
470
495
|
functionCall: {
|
|
496
|
+
id: p.toolCallId,
|
|
471
497
|
name: p.toolName,
|
|
472
498
|
args: p.args
|
|
473
499
|
}
|
|
@@ -475,6 +501,7 @@ function mapPart(p) {
|
|
|
475
501
|
case "tool-result":
|
|
476
502
|
return {
|
|
477
503
|
functionResponse: {
|
|
504
|
+
id: p.toolCallId,
|
|
478
505
|
name: p.toolName,
|
|
479
506
|
response: p.isError === true ? { error: p.result } : p.result
|
|
480
507
|
}
|
|
@@ -768,11 +795,21 @@ function geminiAdapter(opts) {
|
|
|
768
795
|
const textParts = [];
|
|
769
796
|
const thoughtParts = [];
|
|
770
797
|
const toolCalls = [];
|
|
798
|
+
const nameCounts = /* @__PURE__ */ new Map();
|
|
799
|
+
const reservedIds = reserveProviderToolCallIds(
|
|
800
|
+
parts.map((part) => part.functionCall?.id)
|
|
801
|
+
);
|
|
771
802
|
for (const part of parts) {
|
|
772
803
|
if (part.functionCall !== void 0 && typeof part.functionCall.name === "string") {
|
|
804
|
+
const toolName = part.functionCall.name;
|
|
773
805
|
toolCalls.push({
|
|
774
|
-
toolCallId:
|
|
775
|
-
|
|
806
|
+
toolCallId: resolveToolCallId(
|
|
807
|
+
part.functionCall.id,
|
|
808
|
+
toolName,
|
|
809
|
+
nameCounts,
|
|
810
|
+
reservedIds
|
|
811
|
+
),
|
|
812
|
+
toolName,
|
|
776
813
|
args: part.functionCall.args ?? {}
|
|
777
814
|
});
|
|
778
815
|
}
|
|
@@ -3352,7 +3389,7 @@ function convertMediaResolution(mediaResolution, location) {
|
|
|
3352
3389
|
}
|
|
3353
3390
|
return mapMediaResolutionLevel(mediaResolution.level, location);
|
|
3354
3391
|
}
|
|
3355
|
-
function convertPart(part, location) {
|
|
3392
|
+
function convertPart(part, location, nameCounts, reservedIds) {
|
|
3356
3393
|
const keys = definedKeys(part);
|
|
3357
3394
|
const baseKeys = keys.filter(
|
|
3358
3395
|
(key) => key === "text" || key === "inlineData" || key === "fileData"
|
|
@@ -3365,7 +3402,7 @@ function convertPart(part, location) {
|
|
|
3365
3402
|
}
|
|
3366
3403
|
return {
|
|
3367
3404
|
kind: "tool-call",
|
|
3368
|
-
toolCallId: fc.name,
|
|
3405
|
+
toolCallId: resolveToolCallId(fc.id, fc.name, nameCounts, reservedIds),
|
|
3369
3406
|
toolName: fc.name,
|
|
3370
3407
|
args: fc.args ?? {}
|
|
3371
3408
|
};
|
|
@@ -3377,7 +3414,13 @@ function convertPart(part, location) {
|
|
|
3377
3414
|
}
|
|
3378
3415
|
return {
|
|
3379
3416
|
kind: "tool-result",
|
|
3380
|
-
toolCallId:
|
|
3417
|
+
toolCallId: resolveToolCallId(
|
|
3418
|
+
fr.id,
|
|
3419
|
+
fr.name,
|
|
3420
|
+
nameCounts,
|
|
3421
|
+
reservedIds,
|
|
3422
|
+
`result:${fr.name}`
|
|
3423
|
+
),
|
|
3381
3424
|
toolName: fr.name,
|
|
3382
3425
|
result: fr.response ?? null
|
|
3383
3426
|
};
|
|
@@ -3492,6 +3535,15 @@ function convertSystemInstruction(systemInstruction) {
|
|
|
3492
3535
|
}
|
|
3493
3536
|
function geminiContentToMessages(input) {
|
|
3494
3537
|
const system = input.systemInstruction !== void 0 ? convertSystemInstruction(input.systemInstruction) : void 0;
|
|
3538
|
+
const nameCounts = /* @__PURE__ */ new Map();
|
|
3539
|
+
const reservedIds = reserveProviderToolCallIds(
|
|
3540
|
+
input.contents.flatMap(
|
|
3541
|
+
(content) => (content.parts ?? []).flatMap((part) => {
|
|
3542
|
+
const p = part;
|
|
3543
|
+
return [p.functionCall?.id, p.functionResponse?.id];
|
|
3544
|
+
})
|
|
3545
|
+
)
|
|
3546
|
+
);
|
|
3495
3547
|
const messages = input.contents.map((content, contentIndex) => {
|
|
3496
3548
|
const location = `contents[${contentIndex}]`;
|
|
3497
3549
|
const envelopeExtraKeys = definedKeys(content).filter(
|
|
@@ -3504,7 +3556,7 @@ function geminiContentToMessages(input) {
|
|
|
3504
3556
|
}
|
|
3505
3557
|
const role = convertRole(content.role, location);
|
|
3506
3558
|
const parts = (content.parts ?? []).map(
|
|
3507
|
-
(part, partIndex) => convertPart(part, `${location}.parts[${partIndex}]
|
|
3559
|
+
(part, partIndex) => convertPart(part, `${location}.parts[${partIndex}]`, nameCounts, reservedIds)
|
|
3508
3560
|
);
|
|
3509
3561
|
return { role, parts };
|
|
3510
3562
|
});
|