@crewai-ts/core 0.1.3 → 0.1.6
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/agent.d.ts +1 -0
- package/dist/index.cjs +95 -36
- package/dist/index.js +94 -36
- package/dist/provider-completions.d.ts +1 -1
- package/package.json +1 -1
package/dist/agent.d.ts
CHANGED
|
@@ -427,6 +427,7 @@ export declare class Agent {
|
|
|
427
427
|
private callAndTrackLLM;
|
|
428
428
|
private messagesWithInputFilesForClient;
|
|
429
429
|
private clientSupportsMultimodal;
|
|
430
|
+
private clientSupportsFunctionCalling;
|
|
430
431
|
private modelNameForClient;
|
|
431
432
|
private applyGuardrail;
|
|
432
433
|
private emitStep;
|
package/dist/index.cjs
CHANGED
|
@@ -44139,8 +44139,13 @@ Result: ${output4}`, {
|
|
|
44139
44139
|
const beforeUsage = getLLMUsageMetrics(llmClient);
|
|
44140
44140
|
const model = this.modelNameForClient(llmClient);
|
|
44141
44141
|
const responseModel = responseModelFromOptions(options);
|
|
44142
|
+
const nativeToolOptions = tools.length > 0 && this.clientSupportsFunctionCalling(llmClient) ? (() => {
|
|
44143
|
+
const [, availableFunctions] = setupNativeTools(tools);
|
|
44144
|
+
return { availableFunctions, available_functions: availableFunctions };
|
|
44145
|
+
})() : {};
|
|
44142
44146
|
const result = await callLLM(llmClient, messagesForCall, {
|
|
44143
44147
|
tools,
|
|
44148
|
+
...nativeToolOptions,
|
|
44144
44149
|
...responseModel === void 0 ? {} : { responseModel },
|
|
44145
44150
|
metadata: {
|
|
44146
44151
|
agent: this,
|
|
@@ -44173,6 +44178,13 @@ Result: ${output4}`, {
|
|
|
44173
44178
|
}
|
|
44174
44179
|
return typeof candidate.supports_multimodal === "function" && candidate.supports_multimodal();
|
|
44175
44180
|
}
|
|
44181
|
+
clientSupportsFunctionCalling(llmClient) {
|
|
44182
|
+
const candidate = llmClient;
|
|
44183
|
+
if (typeof candidate.supportsFunctionCalling === "function" && candidate.supportsFunctionCalling()) {
|
|
44184
|
+
return true;
|
|
44185
|
+
}
|
|
44186
|
+
return typeof candidate.supports_function_calling === "function" && candidate.supports_function_calling();
|
|
44187
|
+
}
|
|
44176
44188
|
modelNameForClient(llmClient) {
|
|
44177
44189
|
if (llmClient === this.llmClient && typeof this.llm === "string") {
|
|
44178
44190
|
return this.llm;
|
|
@@ -46193,6 +46205,7 @@ function readStringNumberBooleanRecord(value) {
|
|
|
46193
46205
|
|
|
46194
46206
|
// src/provider-completions.ts
|
|
46195
46207
|
init_cjs_shims();
|
|
46208
|
+
init_string_utils();
|
|
46196
46209
|
var TOOL_SEARCH_TOOL_TYPES = Object.freeze([
|
|
46197
46210
|
"tool_search_tool_regex_20251119",
|
|
46198
46211
|
"tool_search_tool_bm25_20251119"
|
|
@@ -47347,33 +47360,37 @@ var GeminiCompletion = class _GeminiCompletion extends ConfiguredLLM {
|
|
|
47347
47360
|
delete generationConfigBody.safety_settings;
|
|
47348
47361
|
const model = this.model.replace(/^(?:gemini|google)\//, "");
|
|
47349
47362
|
const baseUrl = this.baseUrl ?? "https://generativelanguage.googleapis.com/v1beta";
|
|
47350
|
-
const
|
|
47363
|
+
const buildRequestInit = (currentContents) => ({
|
|
47351
47364
|
method: "POST",
|
|
47352
47365
|
headers: { "Content-Type": "application/json" },
|
|
47353
47366
|
body: JSON.stringify({
|
|
47354
|
-
contents,
|
|
47367
|
+
contents: currentContents,
|
|
47355
47368
|
...Object.keys(generationConfigBody).length > 0 ? { generationConfig: generationConfigBody } : {},
|
|
47356
47369
|
..."system_instruction" in requestBody ? { system_instruction: requestBody.system_instruction } : {},
|
|
47357
47370
|
..."tools" in requestBody ? { tools: requestBody.tools } : {},
|
|
47358
47371
|
..."safety_settings" in requestBody ? { safety_settings: requestBody.safety_settings } : {}
|
|
47359
|
-
})
|
|
47360
|
-
|
|
47361
|
-
|
|
47362
|
-
|
|
47363
|
-
|
|
47364
|
-
|
|
47365
|
-
|
|
47366
|
-
|
|
47367
|
-
).then(async (response) => {
|
|
47372
|
+
}),
|
|
47373
|
+
...options?.signal ? { signal: options.signal } : {}
|
|
47374
|
+
});
|
|
47375
|
+
const generateContent = async (currentContents) => {
|
|
47376
|
+
const response = await fetch(
|
|
47377
|
+
`${baseUrl.replace(/\/$/, "")}/models/${encodeURIComponent(model)}:generateContent?key=${encodeURIComponent(apiKey)}`,
|
|
47378
|
+
buildRequestInit(currentContents)
|
|
47379
|
+
);
|
|
47368
47380
|
const body = await response.json();
|
|
47369
47381
|
if (!response.ok) {
|
|
47370
47382
|
const error = readObject2(readObject2(body).error);
|
|
47371
47383
|
throw new Error(scalarToString(error.message) ?? `Gemini request failed with HTTP ${response.status.toString()}.`);
|
|
47372
47384
|
}
|
|
47385
|
+
return body;
|
|
47386
|
+
};
|
|
47387
|
+
return generateContent(contents).then(async (body) => {
|
|
47373
47388
|
return await this.processResponseWithTools(
|
|
47374
47389
|
body,
|
|
47375
47390
|
contents,
|
|
47376
|
-
options?.availableFunctions ?? options?.available_functions ?? null
|
|
47391
|
+
options?.availableFunctions ?? options?.available_functions ?? null,
|
|
47392
|
+
generateContent,
|
|
47393
|
+
geminiMaxToolRounds(options)
|
|
47377
47394
|
);
|
|
47378
47395
|
});
|
|
47379
47396
|
}
|
|
@@ -47673,42 +47690,69 @@ ${textContent}` : textContent;
|
|
|
47673
47690
|
static extract_structured_output_from_response(response) {
|
|
47674
47691
|
return _GeminiCompletion.extractStructuredOutputFromResponse(response);
|
|
47675
47692
|
}
|
|
47676
|
-
async processResponseWithTools(response, contents = [], availableFunctions = null) {
|
|
47677
|
-
|
|
47678
|
-
|
|
47679
|
-
|
|
47680
|
-
|
|
47681
|
-
|
|
47682
|
-
|
|
47683
|
-
|
|
47684
|
-
|
|
47685
|
-
|
|
47686
|
-
const
|
|
47687
|
-
const
|
|
47688
|
-
|
|
47689
|
-
|
|
47690
|
-
|
|
47691
|
-
|
|
47692
|
-
|
|
47693
|
-
|
|
47693
|
+
async processResponseWithTools(response, contents = [], availableFunctions = null, generateContent = null, maxToolRounds = DEFAULT_GEMINI_MAX_TOOL_ROUNDS) {
|
|
47694
|
+
let currentResponse = response;
|
|
47695
|
+
let currentContents = [...contents];
|
|
47696
|
+
for (let round = 0; round <= maxToolRounds; round += 1) {
|
|
47697
|
+
const candidates = readObject2(currentResponse).candidates;
|
|
47698
|
+
if (!Array.isArray(candidates)) {
|
|
47699
|
+
return _GeminiCompletion.extractTextFromResponse(currentResponse);
|
|
47700
|
+
}
|
|
47701
|
+
const first = readObject2(candidates[0]);
|
|
47702
|
+
const rawParts = Array.isArray(readObject2(first.content).parts) ? readObject2(first.content).parts : [];
|
|
47703
|
+
const functionCallParts = rawParts.filter((part) => Object.keys(readObject2(readObject2(part).functionCall ?? readObject2(part).function_call)).length > 0);
|
|
47704
|
+
const structuredOutput = _GeminiCompletion.extractStructuredOutputFromResponse(currentResponse);
|
|
47705
|
+
const nonStructuredParts = functionCallParts.filter((part) => {
|
|
47706
|
+
const partRecord = readObject2(part);
|
|
47707
|
+
const functionCall = readObject2(partRecord.functionCall ?? partRecord.function_call);
|
|
47708
|
+
return (scalarToString(functionCall.name) ?? "") !== STRUCTURED_OUTPUT_TOOL_NAME;
|
|
47709
|
+
});
|
|
47710
|
+
if (nonStructuredParts.length === 0) {
|
|
47711
|
+
return structuredOutput ?? _GeminiCompletion.extractTextFromResponse(currentResponse);
|
|
47712
|
+
}
|
|
47713
|
+
if (!availableFunctions) {
|
|
47714
|
+
return nonStructuredParts;
|
|
47715
|
+
}
|
|
47716
|
+
if (round >= maxToolRounds) {
|
|
47717
|
+
throw new Error(`Gemini tool loop exceeded max tool rounds (${String(maxToolRounds)}).`);
|
|
47718
|
+
}
|
|
47719
|
+
const functionResponseParts = [];
|
|
47720
|
+
let firstToolResult = null;
|
|
47694
47721
|
for (const part of nonStructuredParts) {
|
|
47695
47722
|
const partRecord = readObject2(part);
|
|
47696
47723
|
const functionCall = readObject2(partRecord.functionCall ?? partRecord.function_call);
|
|
47697
|
-
const
|
|
47724
|
+
const rawFunctionName = scalarToString(functionCall.name) ?? "";
|
|
47725
|
+
const functionName = resolveGeminiFunctionName(rawFunctionName, availableFunctions);
|
|
47698
47726
|
if (!functionName) {
|
|
47699
|
-
|
|
47727
|
+
throw new Error(`Gemini requested unknown function '${rawFunctionName}'.`);
|
|
47700
47728
|
}
|
|
47701
47729
|
const result = await this.handleToolExecution({
|
|
47702
47730
|
functionName,
|
|
47703
47731
|
functionArgs: readObject2(functionCall.args),
|
|
47704
47732
|
availableFunctions
|
|
47705
47733
|
});
|
|
47706
|
-
if (result
|
|
47707
|
-
|
|
47734
|
+
if (result === null) {
|
|
47735
|
+
throw new Error(`Gemini failed to execute function '${rawFunctionName}'.`);
|
|
47708
47736
|
}
|
|
47737
|
+
firstToolResult ??= result;
|
|
47738
|
+
functionResponseParts.push({
|
|
47739
|
+
functionResponse: {
|
|
47740
|
+
name: rawFunctionName,
|
|
47741
|
+
response: { result }
|
|
47742
|
+
}
|
|
47743
|
+
});
|
|
47709
47744
|
}
|
|
47745
|
+
if (!generateContent) {
|
|
47746
|
+
return firstToolResult;
|
|
47747
|
+
}
|
|
47748
|
+
currentContents = [
|
|
47749
|
+
...currentContents,
|
|
47750
|
+
{ role: "model", parts: rawParts },
|
|
47751
|
+
{ role: "user", parts: functionResponseParts }
|
|
47752
|
+
];
|
|
47753
|
+
currentResponse = await generateContent(currentContents);
|
|
47710
47754
|
}
|
|
47711
|
-
|
|
47755
|
+
throw new Error(`Gemini tool loop exceeded max tool rounds (${String(maxToolRounds)}).`);
|
|
47712
47756
|
}
|
|
47713
47757
|
async _process_response_with_tools(response, contents = [], availableFunctions = null) {
|
|
47714
47758
|
return await this.processResponseWithTools(response, contents, availableFunctions);
|
|
@@ -48797,6 +48841,19 @@ function geminiVersion(model) {
|
|
|
48797
48841
|
const match = /gemini-(\d+(?:\.\d+)?)/iu.exec(model.toLowerCase());
|
|
48798
48842
|
return match ? Number.parseFloat(match[1] ?? "0") : 0;
|
|
48799
48843
|
}
|
|
48844
|
+
var DEFAULT_GEMINI_MAX_TOOL_ROUNDS = 8;
|
|
48845
|
+
function geminiMaxToolRounds(options) {
|
|
48846
|
+
const record = readObject2(options);
|
|
48847
|
+
const configured = record.maxToolRounds ?? record.max_tool_rounds;
|
|
48848
|
+
return typeof configured === "number" && Number.isInteger(configured) && configured > 0 ? configured : DEFAULT_GEMINI_MAX_TOOL_ROUNDS;
|
|
48849
|
+
}
|
|
48850
|
+
function resolveGeminiFunctionName(functionName, availableFunctions) {
|
|
48851
|
+
if (functionName in availableFunctions) {
|
|
48852
|
+
return functionName;
|
|
48853
|
+
}
|
|
48854
|
+
const sanitizedName = sanitizeToolName(functionName);
|
|
48855
|
+
return sanitizedName in availableFunctions ? sanitizedName : null;
|
|
48856
|
+
}
|
|
48800
48857
|
function geminiTextParts(content) {
|
|
48801
48858
|
if (Array.isArray(content)) {
|
|
48802
48859
|
return content.map((item) => {
|
|
@@ -52088,9 +52145,11 @@ ${todo.description}`);
|
|
|
52088
52145
|
if (this.tools.length === 0) {
|
|
52089
52146
|
return Object.keys(options).length > 0 ? options : void 0;
|
|
52090
52147
|
}
|
|
52091
|
-
const [tools] = setupNativeTools(this.tools);
|
|
52148
|
+
const [tools, availableFunctions] = setupNativeTools(this.tools);
|
|
52092
52149
|
if (tools.length > 0) {
|
|
52093
52150
|
options.tools = tools;
|
|
52151
|
+
options.availableFunctions = availableFunctions;
|
|
52152
|
+
options.available_functions = availableFunctions;
|
|
52094
52153
|
}
|
|
52095
52154
|
return Object.keys(options).length > 0 ? options : void 0;
|
|
52096
52155
|
}
|
package/dist/index.js
CHANGED
|
@@ -27809,8 +27809,13 @@ Result: ${output4}`, {
|
|
|
27809
27809
|
const beforeUsage = getLLMUsageMetrics(llmClient);
|
|
27810
27810
|
const model = this.modelNameForClient(llmClient);
|
|
27811
27811
|
const responseModel = responseModelFromOptions(options);
|
|
27812
|
+
const nativeToolOptions = tools.length > 0 && this.clientSupportsFunctionCalling(llmClient) ? (() => {
|
|
27813
|
+
const [, availableFunctions] = setupNativeTools(tools);
|
|
27814
|
+
return { availableFunctions, available_functions: availableFunctions };
|
|
27815
|
+
})() : {};
|
|
27812
27816
|
const result = await callLLM(llmClient, messagesForCall, {
|
|
27813
27817
|
tools,
|
|
27818
|
+
...nativeToolOptions,
|
|
27814
27819
|
...responseModel === void 0 ? {} : { responseModel },
|
|
27815
27820
|
metadata: {
|
|
27816
27821
|
agent: this,
|
|
@@ -27843,6 +27848,13 @@ Result: ${output4}`, {
|
|
|
27843
27848
|
}
|
|
27844
27849
|
return typeof candidate.supports_multimodal === "function" && candidate.supports_multimodal();
|
|
27845
27850
|
}
|
|
27851
|
+
clientSupportsFunctionCalling(llmClient) {
|
|
27852
|
+
const candidate = llmClient;
|
|
27853
|
+
if (typeof candidate.supportsFunctionCalling === "function" && candidate.supportsFunctionCalling()) {
|
|
27854
|
+
return true;
|
|
27855
|
+
}
|
|
27856
|
+
return typeof candidate.supports_function_calling === "function" && candidate.supports_function_calling();
|
|
27857
|
+
}
|
|
27846
27858
|
modelNameForClient(llmClient) {
|
|
27847
27859
|
if (llmClient === this.llmClient && typeof this.llm === "string") {
|
|
27848
27860
|
return this.llm;
|
|
@@ -31009,33 +31021,37 @@ var GeminiCompletion = class _GeminiCompletion extends ConfiguredLLM {
|
|
|
31009
31021
|
delete generationConfigBody.safety_settings;
|
|
31010
31022
|
const model = this.model.replace(/^(?:gemini|google)\//, "");
|
|
31011
31023
|
const baseUrl = this.baseUrl ?? "https://generativelanguage.googleapis.com/v1beta";
|
|
31012
|
-
const
|
|
31024
|
+
const buildRequestInit = (currentContents) => ({
|
|
31013
31025
|
method: "POST",
|
|
31014
31026
|
headers: { "Content-Type": "application/json" },
|
|
31015
31027
|
body: JSON.stringify({
|
|
31016
|
-
contents,
|
|
31028
|
+
contents: currentContents,
|
|
31017
31029
|
...Object.keys(generationConfigBody).length > 0 ? { generationConfig: generationConfigBody } : {},
|
|
31018
31030
|
..."system_instruction" in requestBody ? { system_instruction: requestBody.system_instruction } : {},
|
|
31019
31031
|
..."tools" in requestBody ? { tools: requestBody.tools } : {},
|
|
31020
31032
|
..."safety_settings" in requestBody ? { safety_settings: requestBody.safety_settings } : {}
|
|
31021
|
-
})
|
|
31022
|
-
|
|
31023
|
-
|
|
31024
|
-
|
|
31025
|
-
|
|
31026
|
-
|
|
31027
|
-
|
|
31028
|
-
|
|
31029
|
-
).then(async (response) => {
|
|
31033
|
+
}),
|
|
31034
|
+
...options?.signal ? { signal: options.signal } : {}
|
|
31035
|
+
});
|
|
31036
|
+
const generateContent = async (currentContents) => {
|
|
31037
|
+
const response = await fetch(
|
|
31038
|
+
`${baseUrl.replace(/\/$/, "")}/models/${encodeURIComponent(model)}:generateContent?key=${encodeURIComponent(apiKey)}`,
|
|
31039
|
+
buildRequestInit(currentContents)
|
|
31040
|
+
);
|
|
31030
31041
|
const body = await response.json();
|
|
31031
31042
|
if (!response.ok) {
|
|
31032
31043
|
const error = readObject2(readObject2(body).error);
|
|
31033
31044
|
throw new Error(scalarToString(error.message) ?? `Gemini request failed with HTTP ${response.status.toString()}.`);
|
|
31034
31045
|
}
|
|
31046
|
+
return body;
|
|
31047
|
+
};
|
|
31048
|
+
return generateContent(contents).then(async (body) => {
|
|
31035
31049
|
return await this.processResponseWithTools(
|
|
31036
31050
|
body,
|
|
31037
31051
|
contents,
|
|
31038
|
-
options?.availableFunctions ?? options?.available_functions ?? null
|
|
31052
|
+
options?.availableFunctions ?? options?.available_functions ?? null,
|
|
31053
|
+
generateContent,
|
|
31054
|
+
geminiMaxToolRounds(options)
|
|
31039
31055
|
);
|
|
31040
31056
|
});
|
|
31041
31057
|
}
|
|
@@ -31335,42 +31351,69 @@ ${textContent}` : textContent;
|
|
|
31335
31351
|
static extract_structured_output_from_response(response) {
|
|
31336
31352
|
return _GeminiCompletion.extractStructuredOutputFromResponse(response);
|
|
31337
31353
|
}
|
|
31338
|
-
async processResponseWithTools(response, contents = [], availableFunctions = null) {
|
|
31339
|
-
|
|
31340
|
-
|
|
31341
|
-
|
|
31342
|
-
|
|
31343
|
-
|
|
31344
|
-
|
|
31345
|
-
|
|
31346
|
-
|
|
31347
|
-
|
|
31348
|
-
const
|
|
31349
|
-
const
|
|
31350
|
-
|
|
31351
|
-
|
|
31352
|
-
|
|
31353
|
-
|
|
31354
|
-
|
|
31355
|
-
|
|
31354
|
+
async processResponseWithTools(response, contents = [], availableFunctions = null, generateContent = null, maxToolRounds = DEFAULT_GEMINI_MAX_TOOL_ROUNDS) {
|
|
31355
|
+
let currentResponse = response;
|
|
31356
|
+
let currentContents = [...contents];
|
|
31357
|
+
for (let round = 0; round <= maxToolRounds; round += 1) {
|
|
31358
|
+
const candidates = readObject2(currentResponse).candidates;
|
|
31359
|
+
if (!Array.isArray(candidates)) {
|
|
31360
|
+
return _GeminiCompletion.extractTextFromResponse(currentResponse);
|
|
31361
|
+
}
|
|
31362
|
+
const first = readObject2(candidates[0]);
|
|
31363
|
+
const rawParts = Array.isArray(readObject2(first.content).parts) ? readObject2(first.content).parts : [];
|
|
31364
|
+
const functionCallParts = rawParts.filter((part) => Object.keys(readObject2(readObject2(part).functionCall ?? readObject2(part).function_call)).length > 0);
|
|
31365
|
+
const structuredOutput = _GeminiCompletion.extractStructuredOutputFromResponse(currentResponse);
|
|
31366
|
+
const nonStructuredParts = functionCallParts.filter((part) => {
|
|
31367
|
+
const partRecord = readObject2(part);
|
|
31368
|
+
const functionCall = readObject2(partRecord.functionCall ?? partRecord.function_call);
|
|
31369
|
+
return (scalarToString(functionCall.name) ?? "") !== STRUCTURED_OUTPUT_TOOL_NAME;
|
|
31370
|
+
});
|
|
31371
|
+
if (nonStructuredParts.length === 0) {
|
|
31372
|
+
return structuredOutput ?? _GeminiCompletion.extractTextFromResponse(currentResponse);
|
|
31373
|
+
}
|
|
31374
|
+
if (!availableFunctions) {
|
|
31375
|
+
return nonStructuredParts;
|
|
31376
|
+
}
|
|
31377
|
+
if (round >= maxToolRounds) {
|
|
31378
|
+
throw new Error(`Gemini tool loop exceeded max tool rounds (${String(maxToolRounds)}).`);
|
|
31379
|
+
}
|
|
31380
|
+
const functionResponseParts = [];
|
|
31381
|
+
let firstToolResult = null;
|
|
31356
31382
|
for (const part of nonStructuredParts) {
|
|
31357
31383
|
const partRecord = readObject2(part);
|
|
31358
31384
|
const functionCall = readObject2(partRecord.functionCall ?? partRecord.function_call);
|
|
31359
|
-
const
|
|
31385
|
+
const rawFunctionName = scalarToString(functionCall.name) ?? "";
|
|
31386
|
+
const functionName = resolveGeminiFunctionName(rawFunctionName, availableFunctions);
|
|
31360
31387
|
if (!functionName) {
|
|
31361
|
-
|
|
31388
|
+
throw new Error(`Gemini requested unknown function '${rawFunctionName}'.`);
|
|
31362
31389
|
}
|
|
31363
31390
|
const result = await this.handleToolExecution({
|
|
31364
31391
|
functionName,
|
|
31365
31392
|
functionArgs: readObject2(functionCall.args),
|
|
31366
31393
|
availableFunctions
|
|
31367
31394
|
});
|
|
31368
|
-
if (result
|
|
31369
|
-
|
|
31395
|
+
if (result === null) {
|
|
31396
|
+
throw new Error(`Gemini failed to execute function '${rawFunctionName}'.`);
|
|
31370
31397
|
}
|
|
31398
|
+
firstToolResult ??= result;
|
|
31399
|
+
functionResponseParts.push({
|
|
31400
|
+
functionResponse: {
|
|
31401
|
+
name: rawFunctionName,
|
|
31402
|
+
response: { result }
|
|
31403
|
+
}
|
|
31404
|
+
});
|
|
31371
31405
|
}
|
|
31406
|
+
if (!generateContent) {
|
|
31407
|
+
return firstToolResult;
|
|
31408
|
+
}
|
|
31409
|
+
currentContents = [
|
|
31410
|
+
...currentContents,
|
|
31411
|
+
{ role: "model", parts: rawParts },
|
|
31412
|
+
{ role: "user", parts: functionResponseParts }
|
|
31413
|
+
];
|
|
31414
|
+
currentResponse = await generateContent(currentContents);
|
|
31372
31415
|
}
|
|
31373
|
-
|
|
31416
|
+
throw new Error(`Gemini tool loop exceeded max tool rounds (${String(maxToolRounds)}).`);
|
|
31374
31417
|
}
|
|
31375
31418
|
async _process_response_with_tools(response, contents = [], availableFunctions = null) {
|
|
31376
31419
|
return await this.processResponseWithTools(response, contents, availableFunctions);
|
|
@@ -32459,6 +32502,19 @@ function geminiVersion(model) {
|
|
|
32459
32502
|
const match = /gemini-(\d+(?:\.\d+)?)/iu.exec(model.toLowerCase());
|
|
32460
32503
|
return match ? Number.parseFloat(match[1] ?? "0") : 0;
|
|
32461
32504
|
}
|
|
32505
|
+
var DEFAULT_GEMINI_MAX_TOOL_ROUNDS = 8;
|
|
32506
|
+
function geminiMaxToolRounds(options) {
|
|
32507
|
+
const record = readObject2(options);
|
|
32508
|
+
const configured = record.maxToolRounds ?? record.max_tool_rounds;
|
|
32509
|
+
return typeof configured === "number" && Number.isInteger(configured) && configured > 0 ? configured : DEFAULT_GEMINI_MAX_TOOL_ROUNDS;
|
|
32510
|
+
}
|
|
32511
|
+
function resolveGeminiFunctionName(functionName, availableFunctions) {
|
|
32512
|
+
if (functionName in availableFunctions) {
|
|
32513
|
+
return functionName;
|
|
32514
|
+
}
|
|
32515
|
+
const sanitizedName = sanitizeToolName(functionName);
|
|
32516
|
+
return sanitizedName in availableFunctions ? sanitizedName : null;
|
|
32517
|
+
}
|
|
32462
32518
|
function geminiTextParts(content) {
|
|
32463
32519
|
if (Array.isArray(content)) {
|
|
32464
32520
|
return content.map((item) => {
|
|
@@ -35736,9 +35792,11 @@ ${todo.description}`);
|
|
|
35736
35792
|
if (this.tools.length === 0) {
|
|
35737
35793
|
return Object.keys(options).length > 0 ? options : void 0;
|
|
35738
35794
|
}
|
|
35739
|
-
const [tools] = setupNativeTools(this.tools);
|
|
35795
|
+
const [tools, availableFunctions] = setupNativeTools(this.tools);
|
|
35740
35796
|
if (tools.length > 0) {
|
|
35741
35797
|
options.tools = tools;
|
|
35798
|
+
options.availableFunctions = availableFunctions;
|
|
35799
|
+
options.available_functions = availableFunctions;
|
|
35742
35800
|
}
|
|
35743
35801
|
return Object.keys(options).length > 0 ? options : void 0;
|
|
35744
35802
|
}
|
|
@@ -358,7 +358,7 @@ export declare class GeminiCompletion extends ConfiguredLLM {
|
|
|
358
358
|
static extract_function_calls_from_response(response: unknown): Record<string, unknown>[];
|
|
359
359
|
static extractStructuredOutputFromResponse(response: unknown): Record<string, unknown> | null;
|
|
360
360
|
static extract_structured_output_from_response(response: unknown): Record<string, unknown> | null;
|
|
361
|
-
processResponseWithTools(response: unknown, contents?: readonly unknown[], availableFunctions?: Record<string, LLMAvailableFunction> | null): Promise<unknown>;
|
|
361
|
+
processResponseWithTools(response: unknown, contents?: readonly unknown[], availableFunctions?: Record<string, LLMAvailableFunction> | null, generateContent?: ((contents: readonly unknown[]) => Promise<unknown>) | null, maxToolRounds?: number): Promise<unknown>;
|
|
362
362
|
_process_response_with_tools(response: unknown, contents?: readonly unknown[], availableFunctions?: Record<string, LLMAvailableFunction> | null): Promise<unknown>;
|
|
363
363
|
static addPropertyOrdering<T extends Record<string, unknown>>(schema: T): T;
|
|
364
364
|
static add_property_ordering<T extends Record<string, unknown>>(schema: T): T;
|