@iqai/adk 0.3.0 → 0.3.2
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/CHANGELOG.md +34 -0
- package/README.md +3 -1
- package/dist/index.d.mts +3 -7
- package/dist/index.d.ts +3 -7
- package/dist/index.js +149 -158
- package/dist/index.mjs +32 -41
- package/package.json +34 -37
package/dist/index.js
CHANGED
|
@@ -1520,7 +1520,11 @@ var AiSdkLlm = (_class6 = class extends BaseLlm {
|
|
|
1520
1520
|
* @param model - Pre-configured LanguageModel from provider(modelName)
|
|
1521
1521
|
*/
|
|
1522
1522
|
constructor(modelInstance) {
|
|
1523
|
-
|
|
1523
|
+
let modelId = "ai-sdk-model";
|
|
1524
|
+
if (typeof modelInstance !== "string") {
|
|
1525
|
+
modelId = modelInstance.modelId;
|
|
1526
|
+
}
|
|
1527
|
+
super(modelId);_class6.prototype.__init12.call(this);;
|
|
1524
1528
|
this.modelInstance = modelInstance;
|
|
1525
1529
|
}
|
|
1526
1530
|
/**
|
|
@@ -1567,7 +1571,7 @@ var AiSdkLlm = (_class6 = class extends BaseLlm {
|
|
|
1567
1571
|
functionCall: {
|
|
1568
1572
|
id: toolCall.toolCallId,
|
|
1569
1573
|
name: toolCall.toolName,
|
|
1570
|
-
args: toolCall.
|
|
1574
|
+
args: toolCall.input
|
|
1571
1575
|
}
|
|
1572
1576
|
});
|
|
1573
1577
|
}
|
|
@@ -1580,8 +1584,8 @@ var AiSdkLlm = (_class6 = class extends BaseLlm {
|
|
|
1580
1584
|
parts: parts.length > 0 ? parts : [{ text: "" }]
|
|
1581
1585
|
},
|
|
1582
1586
|
usageMetadata: finalUsage ? {
|
|
1583
|
-
promptTokenCount: finalUsage.
|
|
1584
|
-
candidatesTokenCount: finalUsage.
|
|
1587
|
+
promptTokenCount: finalUsage.inputTokens,
|
|
1588
|
+
candidatesTokenCount: finalUsage.outputTokens,
|
|
1585
1589
|
totalTokenCount: finalUsage.totalTokens
|
|
1586
1590
|
} : void 0,
|
|
1587
1591
|
finishReason: this.mapFinishReason(finishReason),
|
|
@@ -1599,7 +1603,7 @@ var AiSdkLlm = (_class6 = class extends BaseLlm {
|
|
|
1599
1603
|
functionCall: {
|
|
1600
1604
|
id: toolCall.toolCallId,
|
|
1601
1605
|
name: toolCall.toolName,
|
|
1602
|
-
args: toolCall.
|
|
1606
|
+
args: toolCall.input
|
|
1603
1607
|
}
|
|
1604
1608
|
});
|
|
1605
1609
|
}
|
|
@@ -1610,8 +1614,8 @@ var AiSdkLlm = (_class6 = class extends BaseLlm {
|
|
|
1610
1614
|
parts: parts.length > 0 ? parts : [{ text: "" }]
|
|
1611
1615
|
},
|
|
1612
1616
|
usageMetadata: result.usage ? {
|
|
1613
|
-
promptTokenCount: result.usage.
|
|
1614
|
-
candidatesTokenCount: result.usage.
|
|
1617
|
+
promptTokenCount: result.usage.inputTokens,
|
|
1618
|
+
candidatesTokenCount: result.usage.outputTokens,
|
|
1615
1619
|
totalTokenCount: result.usage.totalTokens
|
|
1616
1620
|
} : void 0,
|
|
1617
1621
|
finishReason: this.mapFinishReason(result.finishReason),
|
|
@@ -1687,7 +1691,7 @@ var AiSdkLlm = (_class6 = class extends BaseLlm {
|
|
|
1687
1691
|
for (const funcDecl of toolConfig.functionDeclarations) {
|
|
1688
1692
|
tools[funcDecl.name] = {
|
|
1689
1693
|
description: funcDecl.description,
|
|
1690
|
-
|
|
1694
|
+
inputSchema: _ai.jsonSchema.call(void 0,
|
|
1691
1695
|
this.transformSchemaForAiSdk(funcDecl.parameters || {})
|
|
1692
1696
|
)
|
|
1693
1697
|
};
|
|
@@ -1733,7 +1737,7 @@ var AiSdkLlm = (_class6 = class extends BaseLlm {
|
|
|
1733
1737
|
type: "tool-call",
|
|
1734
1738
|
toolCallId: funcPart.functionCall.id,
|
|
1735
1739
|
toolName: funcPart.functionCall.name,
|
|
1736
|
-
|
|
1740
|
+
input: funcPart.functionCall.args
|
|
1737
1741
|
});
|
|
1738
1742
|
}
|
|
1739
1743
|
}
|
|
@@ -1746,12 +1750,14 @@ var AiSdkLlm = (_class6 = class extends BaseLlm {
|
|
|
1746
1750
|
const functionResponses = content.parts.filter(
|
|
1747
1751
|
(part) => part.functionResponse
|
|
1748
1752
|
);
|
|
1749
|
-
const contentParts2 = functionResponses.map((part) =>
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1753
|
+
const contentParts2 = functionResponses.map((part) => {
|
|
1754
|
+
return {
|
|
1755
|
+
type: "tool-result",
|
|
1756
|
+
toolCallId: part.functionResponse.id,
|
|
1757
|
+
toolName: part.functionResponse.name || "unknown",
|
|
1758
|
+
output: part.functionResponse.response
|
|
1759
|
+
};
|
|
1760
|
+
});
|
|
1755
1761
|
return {
|
|
1756
1762
|
role: "tool",
|
|
1757
1763
|
content: contentParts2
|
|
@@ -2201,16 +2207,6 @@ var GoogleLlm = class extends BaseLlm {
|
|
|
2201
2207
|
dataObj.displayName = null;
|
|
2202
2208
|
}
|
|
2203
2209
|
}
|
|
2204
|
-
/**
|
|
2205
|
-
* Builds function declaration log string.
|
|
2206
|
-
*/
|
|
2207
|
-
buildFunctionDeclarationLog(funcDecl) {
|
|
2208
|
-
let paramStr = "{}";
|
|
2209
|
-
if (_optionalChain([funcDecl, 'access', _92 => _92.parameters, 'optionalAccess', _93 => _93.properties])) {
|
|
2210
|
-
paramStr = JSON.stringify(funcDecl.parameters.properties);
|
|
2211
|
-
}
|
|
2212
|
-
return `${funcDecl.name}: ${paramStr}`;
|
|
2213
|
-
}
|
|
2214
2210
|
/**
|
|
2215
2211
|
* Provides the api client.
|
|
2216
2212
|
*/
|
|
@@ -2327,7 +2323,7 @@ var OpenAiLlm = class extends BaseLlm {
|
|
|
2327
2323
|
(content) => this.contentToOpenAiMessage(content)
|
|
2328
2324
|
);
|
|
2329
2325
|
let tools;
|
|
2330
|
-
if (_optionalChain([llmRequest, 'access',
|
|
2326
|
+
if (_optionalChain([llmRequest, 'access', _92 => _92.config, 'optionalAccess', _93 => _93.tools, 'optionalAccess', _94 => _94[0], 'optionalAccess', _95 => _95.functionDeclarations])) {
|
|
2331
2327
|
tools = llmRequest.config.tools[0].functionDeclarations.map(
|
|
2332
2328
|
(funcDecl) => this.functionDeclarationToOpenAiTool(funcDecl)
|
|
2333
2329
|
);
|
|
@@ -2345,9 +2341,9 @@ var OpenAiLlm = class extends BaseLlm {
|
|
|
2345
2341
|
messages: openAiMessages,
|
|
2346
2342
|
tools,
|
|
2347
2343
|
tool_choice: tools ? "auto" : void 0,
|
|
2348
|
-
max_tokens: _optionalChain([llmRequest, 'access',
|
|
2349
|
-
temperature: _optionalChain([llmRequest, 'access',
|
|
2350
|
-
top_p: _optionalChain([llmRequest, 'access',
|
|
2344
|
+
max_tokens: _optionalChain([llmRequest, 'access', _96 => _96.config, 'optionalAccess', _97 => _97.maxOutputTokens]),
|
|
2345
|
+
temperature: _optionalChain([llmRequest, 'access', _98 => _98.config, 'optionalAccess', _99 => _99.temperature]),
|
|
2346
|
+
top_p: _optionalChain([llmRequest, 'access', _100 => _100.config, 'optionalAccess', _101 => _101.topP]),
|
|
2351
2347
|
stream
|
|
2352
2348
|
};
|
|
2353
2349
|
if (stream) {
|
|
@@ -2367,7 +2363,7 @@ var OpenAiLlm = class extends BaseLlm {
|
|
|
2367
2363
|
if (chunk.usage) {
|
|
2368
2364
|
usageMetadata = chunk.usage;
|
|
2369
2365
|
}
|
|
2370
|
-
if (_optionalChain([llmResponse, 'access',
|
|
2366
|
+
if (_optionalChain([llmResponse, 'access', _102 => _102.content, 'optionalAccess', _103 => _103.parts, 'optionalAccess', _104 => _104[0], 'optionalAccess', _105 => _105.text])) {
|
|
2371
2367
|
const part0 = llmResponse.content.parts[0];
|
|
2372
2368
|
if (part0.thought) {
|
|
2373
2369
|
thoughtText += part0.text;
|
|
@@ -2408,10 +2404,10 @@ var OpenAiLlm = class extends BaseLlm {
|
|
|
2408
2404
|
function: { name: "", arguments: "" }
|
|
2409
2405
|
};
|
|
2410
2406
|
}
|
|
2411
|
-
if (_optionalChain([toolCall, 'access',
|
|
2407
|
+
if (_optionalChain([toolCall, 'access', _106 => _106.function, 'optionalAccess', _107 => _107.name])) {
|
|
2412
2408
|
accumulatedToolCalls[index].function.name += toolCall.function.name;
|
|
2413
2409
|
}
|
|
2414
|
-
if (_optionalChain([toolCall, 'access',
|
|
2410
|
+
if (_optionalChain([toolCall, 'access', _108 => _108.function, 'optionalAccess', _109 => _109.arguments])) {
|
|
2415
2411
|
accumulatedToolCalls[index].function.arguments += toolCall.function.arguments;
|
|
2416
2412
|
}
|
|
2417
2413
|
}
|
|
@@ -2426,7 +2422,7 @@ var OpenAiLlm = class extends BaseLlm {
|
|
|
2426
2422
|
}
|
|
2427
2423
|
if (accumulatedToolCalls.length > 0) {
|
|
2428
2424
|
for (const toolCall of accumulatedToolCalls) {
|
|
2429
|
-
if (_optionalChain([toolCall, 'access',
|
|
2425
|
+
if (_optionalChain([toolCall, 'access', _110 => _110.function, 'optionalAccess', _111 => _111.name])) {
|
|
2430
2426
|
parts.push({
|
|
2431
2427
|
functionCall: {
|
|
2432
2428
|
id: toolCall.id,
|
|
@@ -2486,7 +2482,7 @@ var OpenAiLlm = class extends BaseLlm {
|
|
|
2486
2482
|
response.usage
|
|
2487
2483
|
);
|
|
2488
2484
|
this.logger.debug(
|
|
2489
|
-
`OpenAI response: ${_optionalChain([response, 'access',
|
|
2485
|
+
`OpenAI response: ${_optionalChain([response, 'access', _112 => _112.usage, 'optionalAccess', _113 => _113.completion_tokens]) || 0} tokens`
|
|
2490
2486
|
);
|
|
2491
2487
|
yield llmResponse;
|
|
2492
2488
|
}
|
|
@@ -2513,7 +2509,7 @@ var OpenAiLlm = class extends BaseLlm {
|
|
|
2513
2509
|
}
|
|
2514
2510
|
if (delta.tool_calls) {
|
|
2515
2511
|
for (const toolCall of delta.tool_calls) {
|
|
2516
|
-
if (toolCall.type === "function" && _optionalChain([toolCall, 'access',
|
|
2512
|
+
if (toolCall.type === "function" && _optionalChain([toolCall, 'access', _114 => _114.function, 'optionalAccess', _115 => _115.name])) {
|
|
2517
2513
|
parts.push({
|
|
2518
2514
|
functionCall: {
|
|
2519
2515
|
id: toolCall.id || "",
|
|
@@ -2579,10 +2575,10 @@ var OpenAiLlm = class extends BaseLlm {
|
|
|
2579
2575
|
if (role === "system") {
|
|
2580
2576
|
return {
|
|
2581
2577
|
role: "system",
|
|
2582
|
-
content: _optionalChain([content, 'access',
|
|
2578
|
+
content: _optionalChain([content, 'access', _116 => _116.parts, 'optionalAccess', _117 => _117[0], 'optionalAccess', _118 => _118.text]) || ""
|
|
2583
2579
|
};
|
|
2584
2580
|
}
|
|
2585
|
-
if (_optionalChain([content, 'access',
|
|
2581
|
+
if (_optionalChain([content, 'access', _119 => _119.parts, 'optionalAccess', _120 => _120.some, 'call', _121 => _121((part) => part.functionCall)])) {
|
|
2586
2582
|
const functionCallPart = content.parts.find(
|
|
2587
2583
|
(part) => part.functionCall
|
|
2588
2584
|
);
|
|
@@ -2602,7 +2598,7 @@ var OpenAiLlm = class extends BaseLlm {
|
|
|
2602
2598
|
]
|
|
2603
2599
|
};
|
|
2604
2600
|
}
|
|
2605
|
-
if (_optionalChain([content, 'access',
|
|
2601
|
+
if (_optionalChain([content, 'access', _122 => _122.parts, 'optionalAccess', _123 => _123.some, 'call', _124 => _124((part) => part.functionResponse)])) {
|
|
2606
2602
|
const functionResponsePart = content.parts.find(
|
|
2607
2603
|
(part) => part.functionResponse
|
|
2608
2604
|
);
|
|
@@ -2614,7 +2610,7 @@ var OpenAiLlm = class extends BaseLlm {
|
|
|
2614
2610
|
)
|
|
2615
2611
|
};
|
|
2616
2612
|
}
|
|
2617
|
-
if (_optionalChain([content, 'access',
|
|
2613
|
+
if (_optionalChain([content, 'access', _125 => _125.parts, 'optionalAccess', _126 => _126.length]) === 1 && content.parts[0].text) {
|
|
2618
2614
|
return {
|
|
2619
2615
|
role,
|
|
2620
2616
|
content: content.parts[0].text
|
|
@@ -2637,7 +2633,7 @@ var OpenAiLlm = class extends BaseLlm {
|
|
|
2637
2633
|
text: part.text
|
|
2638
2634
|
};
|
|
2639
2635
|
}
|
|
2640
|
-
if (_optionalChain([part, 'access',
|
|
2636
|
+
if (_optionalChain([part, 'access', _127 => _127.inline_data, 'optionalAccess', _128 => _128.mime_type]) && _optionalChain([part, 'access', _129 => _129.inline_data, 'optionalAccess', _130 => _130.data])) {
|
|
2641
2637
|
return {
|
|
2642
2638
|
type: "image_url",
|
|
2643
2639
|
image_url: {
|
|
@@ -2765,8 +2761,8 @@ var OpenAiLlm = class extends BaseLlm {
|
|
|
2765
2761
|
* Check if response has inline data (similar to Google LLM)
|
|
2766
2762
|
*/
|
|
2767
2763
|
hasInlineData(response) {
|
|
2768
|
-
const parts = _optionalChain([response, 'access',
|
|
2769
|
-
return _optionalChain([parts, 'optionalAccess',
|
|
2764
|
+
const parts = _optionalChain([response, 'access', _131 => _131.content, 'optionalAccess', _132 => _132.parts]);
|
|
2765
|
+
return _optionalChain([parts, 'optionalAccess', _133 => _133.some, 'call', _134 => _134((part) => part.inlineData)]) || false;
|
|
2770
2766
|
}
|
|
2771
2767
|
/**
|
|
2772
2768
|
* Gets the OpenAI client
|
|
@@ -3074,7 +3070,7 @@ var OAuth2Credential = class extends AuthCredential {
|
|
|
3074
3070
|
"Cannot refresh token: no refresh token or refresh function"
|
|
3075
3071
|
);
|
|
3076
3072
|
}
|
|
3077
|
-
const result = await _optionalChain([this, 'access',
|
|
3073
|
+
const result = await _optionalChain([this, 'access', _135 => _135.refreshFunction, 'optionalCall', _136 => _136(this.refreshToken)]);
|
|
3078
3074
|
if (!result) {
|
|
3079
3075
|
throw new Error("Failed to refresh token");
|
|
3080
3076
|
}
|
|
@@ -3109,7 +3105,7 @@ var AuthHandler = class {
|
|
|
3109
3105
|
* Gets the authentication token
|
|
3110
3106
|
*/
|
|
3111
3107
|
getToken() {
|
|
3112
|
-
return _optionalChain([this, 'access',
|
|
3108
|
+
return _optionalChain([this, 'access', _137 => _137.credential, 'optionalAccess', _138 => _138.getToken, 'call', _139 => _139()]);
|
|
3113
3109
|
}
|
|
3114
3110
|
/**
|
|
3115
3111
|
* Gets headers for HTTP requests
|
|
@@ -3124,7 +3120,7 @@ var AuthHandler = class {
|
|
|
3124
3120
|
* Refreshes the token if necessary
|
|
3125
3121
|
*/
|
|
3126
3122
|
async refreshToken() {
|
|
3127
|
-
if (_optionalChain([this, 'access',
|
|
3123
|
+
if (_optionalChain([this, 'access', _140 => _140.credential, 'optionalAccess', _141 => _141.canRefresh, 'call', _142 => _142()])) {
|
|
3128
3124
|
await this.credential.refresh();
|
|
3129
3125
|
}
|
|
3130
3126
|
}
|
|
@@ -4085,7 +4081,6 @@ init_base_tool();
|
|
|
4085
4081
|
// src/tools/base/create-tool.ts
|
|
4086
4082
|
init_base_tool();
|
|
4087
4083
|
var _zod = require('zod'); var z = _interopRequireWildcard(_zod);
|
|
4088
|
-
var _zodtojsonschema = require('zod-to-json-schema');
|
|
4089
4084
|
var CreatedTool = class extends BaseTool {
|
|
4090
4085
|
|
|
4091
4086
|
|
|
@@ -4131,10 +4126,7 @@ var CreatedTool = class extends BaseTool {
|
|
|
4131
4126
|
* Builds the function declaration from the Zod schema
|
|
4132
4127
|
*/
|
|
4133
4128
|
buildDeclaration() {
|
|
4134
|
-
const rawParameters =
|
|
4135
|
-
target: "jsonSchema7",
|
|
4136
|
-
$refStrategy: "none"
|
|
4137
|
-
});
|
|
4129
|
+
const rawParameters = z.toJSONSchema(this.schema);
|
|
4138
4130
|
const { $schema, ...parameters } = rawParameters;
|
|
4139
4131
|
return {
|
|
4140
4132
|
name: this.name,
|
|
@@ -4411,7 +4403,7 @@ var AgentTool = (_class15 = class extends BaseTool {
|
|
|
4411
4403
|
} catch (e3) {
|
|
4412
4404
|
toolResult = mergedText;
|
|
4413
4405
|
}
|
|
4414
|
-
if (this.outputKey && _optionalChain([context4, 'optionalAccess',
|
|
4406
|
+
if (this.outputKey && _optionalChain([context4, 'optionalAccess', _143 => _143.state])) {
|
|
4415
4407
|
context4.state[this.outputKey] = toolResult;
|
|
4416
4408
|
}
|
|
4417
4409
|
return toolResult;
|
|
@@ -4678,7 +4670,7 @@ var FileOperationsTool = class extends BaseTool {
|
|
|
4678
4670
|
name: "file_operations",
|
|
4679
4671
|
description: "Perform file system operations like reading, writing, and managing files"
|
|
4680
4672
|
});
|
|
4681
|
-
this.basePath = _optionalChain([options, 'optionalAccess',
|
|
4673
|
+
this.basePath = _optionalChain([options, 'optionalAccess', _144 => _144.basePath]) || process.cwd();
|
|
4682
4674
|
}
|
|
4683
4675
|
/**
|
|
4684
4676
|
* Get the function declaration for the tool
|
|
@@ -5161,7 +5153,7 @@ var LoadMemoryTool = (_class20 = class extends BaseTool {
|
|
|
5161
5153
|
const searchResult = await context4.searchMemory(args.query);
|
|
5162
5154
|
return {
|
|
5163
5155
|
memories: searchResult.memories || [],
|
|
5164
|
-
count: _optionalChain([searchResult, 'access',
|
|
5156
|
+
count: _optionalChain([searchResult, 'access', _145 => _145.memories, 'optionalAccess', _146 => _146.length]) || 0
|
|
5165
5157
|
};
|
|
5166
5158
|
} catch (error) {
|
|
5167
5159
|
console.error("Error searching memory:", error);
|
|
@@ -5718,7 +5710,7 @@ var McpClientService = (_class22 = class {
|
|
|
5718
5710
|
},
|
|
5719
5711
|
this,
|
|
5720
5712
|
async (instance) => await instance.reinitialize(),
|
|
5721
|
-
_optionalChain([this, 'access',
|
|
5713
|
+
_optionalChain([this, 'access', _147 => _147.config, 'access', _148 => _148.retryOptions, 'optionalAccess', _149 => _149.maxRetries]) || 2
|
|
5722
5714
|
);
|
|
5723
5715
|
return await wrappedCall();
|
|
5724
5716
|
} catch (error) {
|
|
@@ -5802,7 +5794,7 @@ var McpClientService = (_class22 = class {
|
|
|
5802
5794
|
this.mcpSamplingHandler = null;
|
|
5803
5795
|
if (this.client) {
|
|
5804
5796
|
try {
|
|
5805
|
-
_optionalChain([this, 'access',
|
|
5797
|
+
_optionalChain([this, 'access', _150 => _150.client, 'access', _151 => _151.removeRequestHandler, 'optionalCall', _152 => _152("sampling/createMessage")]);
|
|
5806
5798
|
} catch (error) {
|
|
5807
5799
|
this.logger.error("Failed to remove sampling handler:", error);
|
|
5808
5800
|
}
|
|
@@ -6322,7 +6314,7 @@ var McpToolset = (_class24 = class {
|
|
|
6322
6314
|
"resource_closed_error" /* RESOURCE_CLOSED_ERROR */
|
|
6323
6315
|
);
|
|
6324
6316
|
}
|
|
6325
|
-
if (this.tools.length > 0 && !_optionalChain([this, 'access',
|
|
6317
|
+
if (this.tools.length > 0 && !_optionalChain([this, 'access', _153 => _153.config, 'access', _154 => _154.cacheConfig, 'optionalAccess', _155 => _155.enabled]) === false) {
|
|
6326
6318
|
return this.tools;
|
|
6327
6319
|
}
|
|
6328
6320
|
if (!this.clientService) {
|
|
@@ -6351,7 +6343,7 @@ var McpToolset = (_class24 = class {
|
|
|
6351
6343
|
}
|
|
6352
6344
|
}
|
|
6353
6345
|
}
|
|
6354
|
-
if (_optionalChain([this, 'access',
|
|
6346
|
+
if (_optionalChain([this, 'access', _156 => _156.config, 'access', _157 => _157.cacheConfig, 'optionalAccess', _158 => _158.enabled]) !== false) {
|
|
6355
6347
|
this.tools = tools;
|
|
6356
6348
|
}
|
|
6357
6349
|
return tools;
|
|
@@ -6440,12 +6432,12 @@ function populateClientFunctionCallId(modelResponseEvent) {
|
|
|
6440
6432
|
}
|
|
6441
6433
|
}
|
|
6442
6434
|
function removeClientFunctionCallId(content) {
|
|
6443
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
6435
|
+
if (_optionalChain([content, 'optionalAccess', _159 => _159.parts])) {
|
|
6444
6436
|
for (const part of content.parts) {
|
|
6445
|
-
if (_optionalChain([part, 'access',
|
|
6437
|
+
if (_optionalChain([part, 'access', _160 => _160.functionCall, 'optionalAccess', _161 => _161.id, 'optionalAccess', _162 => _162.startsWith, 'call', _163 => _163(AF_FUNCTION_CALL_ID_PREFIX)])) {
|
|
6446
6438
|
part.functionCall.id = void 0;
|
|
6447
6439
|
}
|
|
6448
|
-
if (_optionalChain([part, 'access',
|
|
6440
|
+
if (_optionalChain([part, 'access', _164 => _164.functionResponse, 'optionalAccess', _165 => _165.id, 'optionalAccess', _166 => _166.startsWith, 'call', _167 => _167(AF_FUNCTION_CALL_ID_PREFIX)])) {
|
|
6449
6441
|
part.functionResponse.id = void 0;
|
|
6450
6442
|
}
|
|
6451
6443
|
}
|
|
@@ -6607,7 +6599,7 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
|
|
|
6607
6599
|
}
|
|
6608
6600
|
const mergedParts = [];
|
|
6609
6601
|
for (const event of functionResponseEvents) {
|
|
6610
|
-
if (_optionalChain([event, 'access',
|
|
6602
|
+
if (_optionalChain([event, 'access', _168 => _168.content, 'optionalAccess', _169 => _169.parts])) {
|
|
6611
6603
|
for (const part of event.content.parts) {
|
|
6612
6604
|
mergedParts.push(part);
|
|
6613
6605
|
}
|
|
@@ -6732,7 +6724,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6732
6724
|
const seen = /* @__PURE__ */ new Set();
|
|
6733
6725
|
const filtered = [];
|
|
6734
6726
|
for (const t of tools) {
|
|
6735
|
-
const name = _optionalChain([t, 'optionalAccess',
|
|
6727
|
+
const name = _optionalChain([t, 'optionalAccess', _170 => _170.name]);
|
|
6736
6728
|
if (!name) continue;
|
|
6737
6729
|
if (seen.has(name)) {
|
|
6738
6730
|
continue;
|
|
@@ -6749,7 +6741,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6749
6741
|
if (tools.length > 0) {
|
|
6750
6742
|
const toolsData = tools.map((tool) => ({
|
|
6751
6743
|
Name: tool.name,
|
|
6752
|
-
Description: _optionalChain([tool, 'access',
|
|
6744
|
+
Description: _optionalChain([tool, 'access', _171 => _171.description, 'optionalAccess', _172 => _172.substring, 'call', _173 => _173(0, 50)]) + (_optionalChain([tool, 'access', _174 => _174.description, 'optionalAccess', _175 => _175.length]) > 50 ? "..." : ""),
|
|
6753
6745
|
"Long Running": tool.isLongRunning ? "Yes" : "No"
|
|
6754
6746
|
}));
|
|
6755
6747
|
this.logger.debugArray("\u{1F6E0}\uFE0F Available Tools", toolsData);
|
|
@@ -6812,14 +6804,14 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6812
6804
|
);
|
|
6813
6805
|
if (functionResponseEvent) {
|
|
6814
6806
|
yield functionResponseEvent;
|
|
6815
|
-
const transferToAgent = _optionalChain([functionResponseEvent, 'access',
|
|
6807
|
+
const transferToAgent = _optionalChain([functionResponseEvent, 'access', _176 => _176.actions, 'optionalAccess', _177 => _177.transferToAgent]);
|
|
6816
6808
|
if (transferToAgent) {
|
|
6817
6809
|
this.logger.debug(`\u{1F504} Live transfer to agent '${transferToAgent}'`);
|
|
6818
6810
|
const agentToRun = this._getAgentToRun(
|
|
6819
6811
|
invocationContext,
|
|
6820
6812
|
transferToAgent
|
|
6821
6813
|
);
|
|
6822
|
-
for await (const event of _optionalChain([agentToRun, 'access',
|
|
6814
|
+
for await (const event of _optionalChain([agentToRun, 'access', _178 => _178.runLive, 'optionalCall', _179 => _179(invocationContext)]) || agentToRun.runAsync(invocationContext)) {
|
|
6823
6815
|
yield event;
|
|
6824
6816
|
}
|
|
6825
6817
|
}
|
|
@@ -6851,7 +6843,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6851
6843
|
yield authEvent;
|
|
6852
6844
|
}
|
|
6853
6845
|
yield functionResponseEvent;
|
|
6854
|
-
const transferToAgent = _optionalChain([functionResponseEvent, 'access',
|
|
6846
|
+
const transferToAgent = _optionalChain([functionResponseEvent, 'access', _180 => _180.actions, 'optionalAccess', _181 => _181.transferToAgent]);
|
|
6855
6847
|
if (transferToAgent) {
|
|
6856
6848
|
this.logger.debug(`\u{1F504} Transferring to agent '${transferToAgent}'`);
|
|
6857
6849
|
const agentToRun = this._getAgentToRun(
|
|
@@ -6897,7 +6889,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6897
6889
|
}
|
|
6898
6890
|
invocationContext.incrementLlmCallCount();
|
|
6899
6891
|
const isStreaming = invocationContext.runConfig.streamingMode === "sse" /* SSE */;
|
|
6900
|
-
let tools = _optionalChain([llmRequest, 'access',
|
|
6892
|
+
let tools = _optionalChain([llmRequest, 'access', _182 => _182.config, 'optionalAccess', _183 => _183.tools]) || [];
|
|
6901
6893
|
if (tools.length) {
|
|
6902
6894
|
const deduped = [];
|
|
6903
6895
|
const seenFn = /* @__PURE__ */ new Set();
|
|
@@ -6906,7 +6898,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6906
6898
|
if (tool && Array.isArray(tool.functionDeclarations)) {
|
|
6907
6899
|
const newFds = tool.functionDeclarations.filter(
|
|
6908
6900
|
(fd) => {
|
|
6909
|
-
if (_optionalChain([fd, 'optionalAccess',
|
|
6901
|
+
if (_optionalChain([fd, 'optionalAccess', _184 => _184.name])) {
|
|
6910
6902
|
if (seenFn.has(fd.name)) {
|
|
6911
6903
|
return false;
|
|
6912
6904
|
}
|
|
@@ -6918,7 +6910,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6918
6910
|
if (newFds.length) {
|
|
6919
6911
|
deduped.push({ ...tool, functionDeclarations: newFds });
|
|
6920
6912
|
}
|
|
6921
|
-
} else if (_optionalChain([tool, 'optionalAccess',
|
|
6913
|
+
} else if (_optionalChain([tool, 'optionalAccess', _185 => _185.name])) {
|
|
6922
6914
|
if (seenFn.has(tool.name)) continue;
|
|
6923
6915
|
seenFn.add(tool.name);
|
|
6924
6916
|
deduped.push(tool);
|
|
@@ -6938,21 +6930,21 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6938
6930
|
return tool.functionDeclarations.map((fn) => fn.name).join(", ");
|
|
6939
6931
|
}
|
|
6940
6932
|
if (tool.name) return tool.name;
|
|
6941
|
-
if (_optionalChain([tool, 'access',
|
|
6942
|
-
if (_optionalChain([tool, 'access',
|
|
6933
|
+
if (_optionalChain([tool, 'access', _186 => _186.function, 'optionalAccess', _187 => _187.name])) return tool.function.name;
|
|
6934
|
+
if (_optionalChain([tool, 'access', _188 => _188.function, 'optionalAccess', _189 => _189.function, 'optionalAccess', _190 => _190.name])) return tool.function.function.name;
|
|
6943
6935
|
return "unknown";
|
|
6944
6936
|
}).join(", ");
|
|
6945
6937
|
const systemInstruction = llmRequest.getSystemInstructionText() || "";
|
|
6946
6938
|
const truncatedSystemInstruction = systemInstruction.length > 100 ? `${systemInstruction.substring(0, 100)}...` : systemInstruction;
|
|
6947
|
-
const contentPreview = _optionalChain([llmRequest, 'access',
|
|
6939
|
+
const contentPreview = _optionalChain([llmRequest, 'access', _191 => _191.contents, 'optionalAccess', _192 => _192.length]) > 0 ? LogFormatter.formatContentPreview(llmRequest.contents[0]) : "none";
|
|
6948
6940
|
this.logger.debugStructured("\u{1F4E4} LLM Request", {
|
|
6949
6941
|
Model: llm.model,
|
|
6950
6942
|
Agent: invocationContext.agent.name,
|
|
6951
|
-
"Content Items": _optionalChain([llmRequest, 'access',
|
|
6943
|
+
"Content Items": _optionalChain([llmRequest, 'access', _193 => _193.contents, 'optionalAccess', _194 => _194.length]) || 0,
|
|
6952
6944
|
"Content Preview": contentPreview,
|
|
6953
6945
|
"System Instruction": truncatedSystemInstruction || "none",
|
|
6954
6946
|
"Available Tools": toolNames || "none",
|
|
6955
|
-
"Tool Count": _optionalChain([llmRequest, 'access',
|
|
6947
|
+
"Tool Count": _optionalChain([llmRequest, 'access', _195 => _195.config, 'optionalAccess', _196 => _196.tools, 'optionalAccess', _197 => _197.length]) || 0,
|
|
6956
6948
|
Streaming: isStreaming ? "Yes" : "No"
|
|
6957
6949
|
});
|
|
6958
6950
|
let responseCount = 0;
|
|
@@ -6967,8 +6959,8 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6967
6959
|
llmRequest,
|
|
6968
6960
|
llmResponse
|
|
6969
6961
|
);
|
|
6970
|
-
const tokenCount = _optionalChain([llmResponse, 'access',
|
|
6971
|
-
const functionCalls = _optionalChain([llmResponse, 'access',
|
|
6962
|
+
const tokenCount = _optionalChain([llmResponse, 'access', _198 => _198.usageMetadata, 'optionalAccess', _199 => _199.totalTokenCount]) || "unknown";
|
|
6963
|
+
const functionCalls = _optionalChain([llmResponse, 'access', _200 => _200.content, 'optionalAccess', _201 => _201.parts, 'optionalAccess', _202 => _202.filter, 'call', _203 => _203((part) => part.functionCall)]) || [];
|
|
6972
6964
|
const functionCallsDisplay = LogFormatter.formatFunctionCalls(functionCalls);
|
|
6973
6965
|
const responsePreview = LogFormatter.formatResponsePreview(llmResponse);
|
|
6974
6966
|
this.logger.debugStructured("\u{1F4E5} LLM Response", {
|
|
@@ -7112,7 +7104,7 @@ var EnhancedAuthConfig = class {
|
|
|
7112
7104
|
*/
|
|
7113
7105
|
generateCredentialKey() {
|
|
7114
7106
|
const schemeKey = this.authScheme.type || "unknown";
|
|
7115
|
-
const credentialKey = _optionalChain([this, 'access',
|
|
7107
|
+
const credentialKey = _optionalChain([this, 'access', _204 => _204.rawAuthCredential, 'optionalAccess', _205 => _205.type]) || "none";
|
|
7116
7108
|
const timestamp = Date.now();
|
|
7117
7109
|
return `adk_${schemeKey}_${credentialKey}_${timestamp}`;
|
|
7118
7110
|
}
|
|
@@ -7269,7 +7261,7 @@ var AuthLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
7269
7261
|
*/
|
|
7270
7262
|
parseAndStoreAuthResponse(authHandler, invocationContext) {
|
|
7271
7263
|
try {
|
|
7272
|
-
const credentialKey = _optionalChain([authHandler, 'access',
|
|
7264
|
+
const credentialKey = _optionalChain([authHandler, 'access', _206 => _206.authConfig, 'access', _207 => _207.context, 'optionalAccess', _208 => _208.credentialKey]) || `temp:${Date.now()}`;
|
|
7273
7265
|
const fullCredentialKey = credentialKey.startsWith("temp:") ? credentialKey : `temp:${credentialKey}`;
|
|
7274
7266
|
invocationContext.session.state[fullCredentialKey] = authHandler.credential;
|
|
7275
7267
|
if (authHandler.authConfig.authScheme.type === "oauth2" || authHandler.authConfig.authScheme.type === "openIdConnect") {
|
|
@@ -7298,7 +7290,7 @@ var BasicLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
7298
7290
|
llmRequest.config = {};
|
|
7299
7291
|
}
|
|
7300
7292
|
if (agent.outputSchema) {
|
|
7301
|
-
const hasTools = await _asyncOptionalChain([(await _optionalChain([agent, 'access',
|
|
7293
|
+
const hasTools = await _asyncOptionalChain([(await _optionalChain([agent, 'access', _209 => _209.canonicalTools, 'optionalCall', _210 => _210(invocationContext)])), 'optionalAccess', async _211 => _211.length]) > 0;
|
|
7302
7294
|
const hasTransfers = !!("subAgents" in agent && agent.subAgents && agent.subAgents.length > 0 && !(agent.disallowTransferToParent && agent.disallowTransferToPeers));
|
|
7303
7295
|
if (!hasTools && !hasTransfers) {
|
|
7304
7296
|
llmRequest.setOutputSchema(agent.outputSchema);
|
|
@@ -7390,7 +7382,7 @@ var BuiltInCodeExecutor = class extends BaseCodeExecutor {
|
|
|
7390
7382
|
* Pre-process the LLM request for Gemini 2.0+ models to use the code execution tool
|
|
7391
7383
|
*/
|
|
7392
7384
|
processLlmRequest(llmRequest) {
|
|
7393
|
-
if (!_optionalChain([llmRequest, 'access',
|
|
7385
|
+
if (!_optionalChain([llmRequest, 'access', _212 => _212.model, 'optionalAccess', _213 => _213.startsWith, 'call', _214 => _214("gemini-2")])) {
|
|
7394
7386
|
throw new Error(
|
|
7395
7387
|
`Gemini code execution tool is not supported for model ${llmRequest.model}`
|
|
7396
7388
|
);
|
|
@@ -7435,7 +7427,7 @@ var CodeExecutionUtils = class _CodeExecutionUtils {
|
|
|
7435
7427
|
* Extracts the first code block from the content and truncates everything after it
|
|
7436
7428
|
*/
|
|
7437
7429
|
static extractCodeAndTruncateContent(content, codeBlockDelimiters) {
|
|
7438
|
-
if (!_optionalChain([content, 'optionalAccess',
|
|
7430
|
+
if (!_optionalChain([content, 'optionalAccess', _215 => _215.parts, 'optionalAccess', _216 => _216.length])) {
|
|
7439
7431
|
return null;
|
|
7440
7432
|
}
|
|
7441
7433
|
for (let idx = 0; idx < content.parts.length; idx++) {
|
|
@@ -7521,7 +7513,7 @@ ${fileNames}`);
|
|
|
7521
7513
|
* Converts the code execution parts to text parts in a Content
|
|
7522
7514
|
*/
|
|
7523
7515
|
static convertCodeExecutionParts(content, codeBlockDelimiter, executionResultDelimiters) {
|
|
7524
|
-
if (!_optionalChain([content, 'access',
|
|
7516
|
+
if (!_optionalChain([content, 'access', _217 => _217.parts, 'optionalAccess', _218 => _218.length])) {
|
|
7525
7517
|
return;
|
|
7526
7518
|
}
|
|
7527
7519
|
const lastPart = content.parts[content.parts.length - 1];
|
|
@@ -7914,7 +7906,7 @@ async function* runPostProcessor(invocationContext, llmResponse) {
|
|
|
7914
7906
|
function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
|
|
7915
7907
|
const allInputFiles = codeExecutorContext.getInputFiles();
|
|
7916
7908
|
const savedFileNames = new Set(allInputFiles.map((f) => f.name));
|
|
7917
|
-
for (let i = 0; i < (_optionalChain([llmRequest, 'access',
|
|
7909
|
+
for (let i = 0; i < (_optionalChain([llmRequest, 'access', _219 => _219.contents, 'optionalAccess', _220 => _220.length]) || 0); i++) {
|
|
7918
7910
|
const content = llmRequest.contents[i];
|
|
7919
7911
|
if (content.role !== "user" || !content.parts) {
|
|
7920
7912
|
continue;
|
|
@@ -7946,7 +7938,7 @@ Available file: \`${fileName}\`
|
|
|
7946
7938
|
}
|
|
7947
7939
|
function getOrSetExecutionId(invocationContext, codeExecutorContext) {
|
|
7948
7940
|
const agent = invocationContext.agent;
|
|
7949
|
-
if (!hasCodeExecutor(agent) || !_optionalChain([agent, 'access',
|
|
7941
|
+
if (!hasCodeExecutor(agent) || !_optionalChain([agent, 'access', _221 => _221.codeExecutor, 'optionalAccess', _222 => _222.stateful])) {
|
|
7950
7942
|
return void 0;
|
|
7951
7943
|
}
|
|
7952
7944
|
let executionId = codeExecutorContext.getExecutionId();
|
|
@@ -8177,7 +8169,7 @@ function rearrangeEventsForLatestFunctionResponse(events) {
|
|
|
8177
8169
|
continue;
|
|
8178
8170
|
}
|
|
8179
8171
|
const functionResponses2 = event.getFunctionResponses();
|
|
8180
|
-
if (_optionalChain([functionResponses2, 'optionalAccess',
|
|
8172
|
+
if (_optionalChain([functionResponses2, 'optionalAccess', _223 => _223.some, 'call', _224 => _224((fr) => fr.id && functionResponsesIds.has(fr.id))])) {
|
|
8181
8173
|
functionResponseEvents.push(event);
|
|
8182
8174
|
}
|
|
8183
8175
|
}
|
|
@@ -8276,7 +8268,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
|
|
|
8276
8268
|
const partIndicesInMergedEvent = {};
|
|
8277
8269
|
for (let idx = 0; idx < partsInMergedEvent.length; idx++) {
|
|
8278
8270
|
const part = partsInMergedEvent[idx];
|
|
8279
|
-
if (_optionalChain([part, 'access',
|
|
8271
|
+
if (_optionalChain([part, 'access', _225 => _225.functionResponse, 'optionalAccess', _226 => _226.id])) {
|
|
8280
8272
|
partIndicesInMergedEvent[part.functionResponse.id] = idx;
|
|
8281
8273
|
}
|
|
8282
8274
|
}
|
|
@@ -8285,7 +8277,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
|
|
|
8285
8277
|
throw new Error("There should be at least one function_response part.");
|
|
8286
8278
|
}
|
|
8287
8279
|
for (const part of event.content.parts) {
|
|
8288
|
-
if (_optionalChain([part, 'access',
|
|
8280
|
+
if (_optionalChain([part, 'access', _227 => _227.functionResponse, 'optionalAccess', _228 => _228.id])) {
|
|
8289
8281
|
const functionCallId = part.functionResponse.id;
|
|
8290
8282
|
if (functionCallId in partIndicesInMergedEvent) {
|
|
8291
8283
|
partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] = part;
|
|
@@ -8458,10 +8450,7 @@ var InstructionsLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
8458
8450
|
}
|
|
8459
8451
|
if (agent.outputSchema) {
|
|
8460
8452
|
try {
|
|
8461
|
-
const raw =
|
|
8462
|
-
target: "jsonSchema7",
|
|
8463
|
-
$refStrategy: "none"
|
|
8464
|
-
});
|
|
8453
|
+
const raw = z.default.toJSONSchema(agent.outputSchema);
|
|
8465
8454
|
const { $schema, ...json } = raw || {};
|
|
8466
8455
|
llmRequest.appendInstructions([
|
|
8467
8456
|
"You must respond with application/json that validates against this JSON Schema (do NOT wrap the output in markdown or code fences):",
|
|
@@ -8555,7 +8544,7 @@ var PlanReActPlanner = class extends BasePlanner {
|
|
|
8555
8544
|
let firstFcPartIndex = -1;
|
|
8556
8545
|
for (let i = 0; i < responseParts.length; i++) {
|
|
8557
8546
|
if (responseParts[i].functionCall) {
|
|
8558
|
-
if (!_optionalChain([responseParts, 'access',
|
|
8547
|
+
if (!_optionalChain([responseParts, 'access', _229 => _229[i], 'access', _230 => _230.functionCall, 'optionalAccess', _231 => _231.name])) {
|
|
8559
8548
|
continue;
|
|
8560
8549
|
}
|
|
8561
8550
|
preservedParts.push(responseParts[i]);
|
|
@@ -8594,7 +8583,7 @@ var PlanReActPlanner = class extends BasePlanner {
|
|
|
8594
8583
|
* Handles non-function-call parts of the response
|
|
8595
8584
|
*/
|
|
8596
8585
|
_handleNonFunctionCallParts(responsePart, preservedParts) {
|
|
8597
|
-
if (_optionalChain([responsePart, 'access',
|
|
8586
|
+
if (_optionalChain([responsePart, 'access', _232 => _232.text, 'optionalAccess', _233 => _233.includes, 'call', _234 => _234(FINAL_ANSWER_TAG)])) {
|
|
8598
8587
|
const [reasoningText, finalAnswerText] = this._splitByLastPattern(
|
|
8599
8588
|
responsePart.text,
|
|
8600
8589
|
FINAL_ANSWER_TAG
|
|
@@ -8840,7 +8829,7 @@ var OutputSchemaResponseProcessor = (_class26 = class extends BaseLlmResponsePro
|
|
|
8840
8829
|
stripCodeFences(raw) {
|
|
8841
8830
|
const fencePattern = /```(?:json)?\s*([\s\S]*?)```/i;
|
|
8842
8831
|
const fenceMatch = raw.match(fencePattern);
|
|
8843
|
-
if (_optionalChain([fenceMatch, 'optionalAccess',
|
|
8832
|
+
if (_optionalChain([fenceMatch, 'optionalAccess', _235 => _235[1]])) {
|
|
8844
8833
|
return fenceMatch[1].trim();
|
|
8845
8834
|
}
|
|
8846
8835
|
const lines = raw.split(/\r?\n/).map((l) => l.trim());
|
|
@@ -8877,7 +8866,7 @@ var SharedMemoryRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
8877
8866
|
const memoryService = invocationContext.memoryService;
|
|
8878
8867
|
if (!memoryService) return;
|
|
8879
8868
|
const lastUserEvent = invocationContext.session.events.findLast(
|
|
8880
|
-
(e) => e.author === "user" && _optionalChain([e, 'access',
|
|
8869
|
+
(e) => e.author === "user" && _optionalChain([e, 'access', _236 => _236.content, 'optionalAccess', _237 => _237.parts, 'optionalAccess', _238 => _238.length])
|
|
8881
8870
|
);
|
|
8882
8871
|
if (!lastUserEvent) return;
|
|
8883
8872
|
const query = (_nullishCoalesce(lastUserEvent.content.parts, () => ( []))).map((p) => p.text || "").join(" ");
|
|
@@ -8888,7 +8877,7 @@ var SharedMemoryRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
8888
8877
|
});
|
|
8889
8878
|
const sessionTexts = new Set(
|
|
8890
8879
|
(llmRequest.contents || []).flatMap(
|
|
8891
|
-
(c) => _optionalChain([c, 'access',
|
|
8880
|
+
(c) => _optionalChain([c, 'access', _239 => _239.parts, 'optionalAccess', _240 => _240.map, 'call', _241 => _241((p) => p.text)]) || []
|
|
8892
8881
|
)
|
|
8893
8882
|
);
|
|
8894
8883
|
for (const memory of results.memories) {
|
|
@@ -9309,7 +9298,7 @@ var LlmAgent = (_class27 = class _LlmAgent extends BaseAgent {
|
|
|
9309
9298
|
* This matches the Python implementation's _llm_flow property
|
|
9310
9299
|
*/
|
|
9311
9300
|
get llmFlow() {
|
|
9312
|
-
if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access',
|
|
9301
|
+
if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access', _242 => _242.subAgents, 'optionalAccess', _243 => _243.length])) {
|
|
9313
9302
|
return new SingleFlow();
|
|
9314
9303
|
}
|
|
9315
9304
|
return new AutoFlow();
|
|
@@ -9325,7 +9314,7 @@ var LlmAgent = (_class27 = class _LlmAgent extends BaseAgent {
|
|
|
9325
9314
|
);
|
|
9326
9315
|
return;
|
|
9327
9316
|
}
|
|
9328
|
-
if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access',
|
|
9317
|
+
if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access', _244 => _244.content, 'optionalAccess', _245 => _245.parts])) {
|
|
9329
9318
|
let result = event.content.parts.map((part) => part.text || "").join("");
|
|
9330
9319
|
if (this.outputSchema) {
|
|
9331
9320
|
if (!result.trim()) {
|
|
@@ -9545,7 +9534,7 @@ var LoopAgent = class extends BaseAgent {
|
|
|
9545
9534
|
for (const subAgent of this.subAgents) {
|
|
9546
9535
|
for await (const event of subAgent.runAsync(ctx)) {
|
|
9547
9536
|
yield event;
|
|
9548
|
-
if (_optionalChain([event, 'access',
|
|
9537
|
+
if (_optionalChain([event, 'access', _246 => _246.actions, 'optionalAccess', _247 => _247.escalate])) {
|
|
9549
9538
|
return;
|
|
9550
9539
|
}
|
|
9551
9540
|
}
|
|
@@ -9857,17 +9846,17 @@ var RunConfig = class {
|
|
|
9857
9846
|
*/
|
|
9858
9847
|
|
|
9859
9848
|
constructor(config) {
|
|
9860
|
-
this.speechConfig = _optionalChain([config, 'optionalAccess',
|
|
9861
|
-
this.responseModalities = _optionalChain([config, 'optionalAccess',
|
|
9862
|
-
this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess',
|
|
9863
|
-
this.supportCFC = _optionalChain([config, 'optionalAccess',
|
|
9864
|
-
this.streamingMode = _optionalChain([config, 'optionalAccess',
|
|
9865
|
-
this.outputAudioTranscription = _optionalChain([config, 'optionalAccess',
|
|
9866
|
-
this.inputAudioTranscription = _optionalChain([config, 'optionalAccess',
|
|
9867
|
-
this.realtimeInputConfig = _optionalChain([config, 'optionalAccess',
|
|
9868
|
-
this.enableAffectiveDialog = _optionalChain([config, 'optionalAccess',
|
|
9869
|
-
this.proactivity = _optionalChain([config, 'optionalAccess',
|
|
9870
|
-
this.maxLlmCalls = _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
9849
|
+
this.speechConfig = _optionalChain([config, 'optionalAccess', _248 => _248.speechConfig]);
|
|
9850
|
+
this.responseModalities = _optionalChain([config, 'optionalAccess', _249 => _249.responseModalities]);
|
|
9851
|
+
this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess', _250 => _250.saveInputBlobsAsArtifacts]) || false;
|
|
9852
|
+
this.supportCFC = _optionalChain([config, 'optionalAccess', _251 => _251.supportCFC]) || false;
|
|
9853
|
+
this.streamingMode = _optionalChain([config, 'optionalAccess', _252 => _252.streamingMode]) || "NONE" /* NONE */;
|
|
9854
|
+
this.outputAudioTranscription = _optionalChain([config, 'optionalAccess', _253 => _253.outputAudioTranscription]);
|
|
9855
|
+
this.inputAudioTranscription = _optionalChain([config, 'optionalAccess', _254 => _254.inputAudioTranscription]);
|
|
9856
|
+
this.realtimeInputConfig = _optionalChain([config, 'optionalAccess', _255 => _255.realtimeInputConfig]);
|
|
9857
|
+
this.enableAffectiveDialog = _optionalChain([config, 'optionalAccess', _256 => _256.enableAffectiveDialog]);
|
|
9858
|
+
this.proactivity = _optionalChain([config, 'optionalAccess', _257 => _257.proactivity]);
|
|
9859
|
+
this.maxLlmCalls = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _258 => _258.maxLlmCalls]), () => ( 500));
|
|
9871
9860
|
this.validateMaxLlmCalls();
|
|
9872
9861
|
}
|
|
9873
9862
|
/**
|
|
@@ -10011,7 +10000,7 @@ var InMemoryMemoryService = (_class30 = class {
|
|
|
10011
10000
|
}
|
|
10012
10001
|
const userSessions = this._sessionEvents.get(userKey);
|
|
10013
10002
|
const filteredEvents = session.events.filter(
|
|
10014
|
-
(event) => _optionalChain([event, 'access',
|
|
10003
|
+
(event) => _optionalChain([event, 'access', _259 => _259.content, 'optionalAccess', _260 => _260.parts])
|
|
10015
10004
|
);
|
|
10016
10005
|
userSessions.set(session.id, filteredEvents);
|
|
10017
10006
|
}
|
|
@@ -10150,7 +10139,7 @@ var InMemorySessionService = (_class31 = class extends BaseSessionService {const
|
|
|
10150
10139
|
return this.createSessionImpl(appName, userId, state, sessionId);
|
|
10151
10140
|
}
|
|
10152
10141
|
createSessionImpl(appName, userId, state, sessionId) {
|
|
10153
|
-
const finalSessionId = _optionalChain([sessionId, 'optionalAccess',
|
|
10142
|
+
const finalSessionId = _optionalChain([sessionId, 'optionalAccess', _261 => _261.trim, 'call', _262 => _262()]) || _crypto.randomUUID.call(void 0, );
|
|
10154
10143
|
const session = {
|
|
10155
10144
|
appName,
|
|
10156
10145
|
userId,
|
|
@@ -10307,7 +10296,7 @@ var InMemorySessionService = (_class31 = class extends BaseSessionService {const
|
|
|
10307
10296
|
warning(`sessionId ${sessionId} not in sessions[appName][userId]`);
|
|
10308
10297
|
return event;
|
|
10309
10298
|
}
|
|
10310
|
-
if (_optionalChain([event, 'access',
|
|
10299
|
+
if (_optionalChain([event, 'access', _263 => _263.actions, 'optionalAccess', _264 => _264.stateDelta])) {
|
|
10311
10300
|
for (const key in event.actions.stateDelta) {
|
|
10312
10301
|
const value = event.actions.stateDelta[key];
|
|
10313
10302
|
if (key.startsWith(State.APP_PREFIX)) {
|
|
@@ -10341,14 +10330,14 @@ function _findFunctionCallEventIfLastEventIsFunctionResponse(session) {
|
|
|
10341
10330
|
return null;
|
|
10342
10331
|
}
|
|
10343
10332
|
const lastEvent = events[events.length - 1];
|
|
10344
|
-
if (_optionalChain([lastEvent, 'access',
|
|
10345
|
-
const functionCallId = _optionalChain([lastEvent, 'access',
|
|
10333
|
+
if (_optionalChain([lastEvent, 'access', _265 => _265.content, 'optionalAccess', _266 => _266.parts, 'optionalAccess', _267 => _267.some, 'call', _268 => _268((part) => part.functionResponse)])) {
|
|
10334
|
+
const functionCallId = _optionalChain([lastEvent, 'access', _269 => _269.content, 'access', _270 => _270.parts, 'access', _271 => _271.find, 'call', _272 => _272(
|
|
10346
10335
|
(part) => part.functionResponse
|
|
10347
|
-
), 'optionalAccess',
|
|
10336
|
+
), 'optionalAccess', _273 => _273.functionResponse, 'optionalAccess', _274 => _274.id]);
|
|
10348
10337
|
if (!functionCallId) return null;
|
|
10349
10338
|
for (let i = events.length - 2; i >= 0; i--) {
|
|
10350
10339
|
const event = events[i];
|
|
10351
|
-
const functionCalls = _optionalChain([event, 'access',
|
|
10340
|
+
const functionCalls = _optionalChain([event, 'access', _275 => _275.getFunctionCalls, 'optionalCall', _276 => _276()]) || [];
|
|
10352
10341
|
for (const functionCall of functionCalls) {
|
|
10353
10342
|
if (functionCall.id === functionCallId) {
|
|
10354
10343
|
return event;
|
|
@@ -10551,15 +10540,15 @@ var Runner = (_class32 = class {
|
|
|
10551
10540
|
*/
|
|
10552
10541
|
_findAgentToRun(session, rootAgent) {
|
|
10553
10542
|
const event = _findFunctionCallEventIfLastEventIsFunctionResponse(session);
|
|
10554
|
-
if (_optionalChain([event, 'optionalAccess',
|
|
10543
|
+
if (_optionalChain([event, 'optionalAccess', _277 => _277.author])) {
|
|
10555
10544
|
return rootAgent.findAgent(event.author);
|
|
10556
10545
|
}
|
|
10557
|
-
const nonUserEvents = _optionalChain([session, 'access',
|
|
10546
|
+
const nonUserEvents = _optionalChain([session, 'access', _278 => _278.events, 'optionalAccess', _279 => _279.filter, 'call', _280 => _280((e) => e.author !== "user"), 'access', _281 => _281.reverse, 'call', _282 => _282()]) || [];
|
|
10558
10547
|
for (const event2 of nonUserEvents) {
|
|
10559
10548
|
if (event2.author === rootAgent.name) {
|
|
10560
10549
|
return rootAgent;
|
|
10561
10550
|
}
|
|
10562
|
-
const agent = _optionalChain([rootAgent, 'access',
|
|
10551
|
+
const agent = _optionalChain([rootAgent, 'access', _283 => _283.findSubAgent, 'optionalCall', _284 => _284(event2.author)]);
|
|
10563
10552
|
if (!agent) {
|
|
10564
10553
|
this.logger.debug(
|
|
10565
10554
|
`Event from an unknown agent: ${event2.author}, event id: ${event2.id}`
|
|
@@ -11165,7 +11154,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11165
11154
|
const outputSchema = this.config.outputSchema;
|
|
11166
11155
|
const agentType = this.agentType;
|
|
11167
11156
|
const isMulti = agentType === "parallel" || agentType === "sequential";
|
|
11168
|
-
const subAgentNames = _optionalChain([this, 'access',
|
|
11157
|
+
const subAgentNames = _optionalChain([this, 'access', _285 => _285.config, 'access', _286 => _286.subAgents, 'optionalAccess', _287 => _287.map, 'call', _288 => _288((a) => a.name)]) || [];
|
|
11169
11158
|
return {
|
|
11170
11159
|
__outputSchema: outputSchema,
|
|
11171
11160
|
async ask(message) {
|
|
@@ -11173,7 +11162,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11173
11162
|
let combinedResponse = "";
|
|
11174
11163
|
const perAgentBuffers = {};
|
|
11175
11164
|
const authors = /* @__PURE__ */ new Set();
|
|
11176
|
-
if (!_optionalChain([sessionOptions, 'optionalAccess',
|
|
11165
|
+
if (!_optionalChain([sessionOptions, 'optionalAccess', _289 => _289.userId])) {
|
|
11177
11166
|
throw new Error("Session configuration is required");
|
|
11178
11167
|
}
|
|
11179
11168
|
for await (const event of baseRunner.runAsync({
|
|
@@ -11181,7 +11170,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11181
11170
|
sessionId: session.id,
|
|
11182
11171
|
newMessage
|
|
11183
11172
|
})) {
|
|
11184
|
-
if (_optionalChain([event, 'access',
|
|
11173
|
+
if (_optionalChain([event, 'access', _290 => _290.content, 'optionalAccess', _291 => _291.parts]) && Array.isArray(event.content.parts)) {
|
|
11185
11174
|
const content = event.content.parts.map(
|
|
11186
11175
|
(part) => (part && typeof part === "object" && "text" in part ? part.text : "") || ""
|
|
11187
11176
|
).join("");
|
|
@@ -11209,12 +11198,14 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11209
11198
|
try {
|
|
11210
11199
|
return outputSchema.parse(combinedResponse);
|
|
11211
11200
|
} catch (validationError) {
|
|
11212
|
-
|
|
11213
|
-
|
|
11214
|
-
|
|
11215
|
-
|
|
11216
|
-
|
|
11217
|
-
|
|
11201
|
+
const message2 = `\u{1F6A8} Failed to parse and validate LLM output against the schema.
|
|
11202
|
+
|
|
11203
|
+
\u2139\uFE0F JSON parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}
|
|
11204
|
+
|
|
11205
|
+
\u{1F6A7} Zod validation error: ${validationError instanceof Error ? validationError.message : String(validationError)}
|
|
11206
|
+
|
|
11207
|
+
\u{1F4C4} Raw output: ${combinedResponse}`;
|
|
11208
|
+
throw new Error(message2);
|
|
11218
11209
|
}
|
|
11219
11210
|
}
|
|
11220
11211
|
}
|
|
@@ -11289,7 +11280,7 @@ var VertexAiSessionService = class extends BaseSessionService {
|
|
|
11289
11280
|
path: `operations/${operationId}`,
|
|
11290
11281
|
request_dict: {}
|
|
11291
11282
|
});
|
|
11292
|
-
if (_optionalChain([lroResponse, 'optionalAccess',
|
|
11283
|
+
if (_optionalChain([lroResponse, 'optionalAccess', _292 => _292.done])) {
|
|
11293
11284
|
break;
|
|
11294
11285
|
}
|
|
11295
11286
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
@@ -11660,12 +11651,12 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
11660
11651
|
}
|
|
11661
11652
|
async createSession(appName, userId, state, sessionId) {
|
|
11662
11653
|
await this.ensureInitialized();
|
|
11663
|
-
const id = _optionalChain([sessionId, 'optionalAccess',
|
|
11654
|
+
const id = _optionalChain([sessionId, 'optionalAccess', _293 => _293.trim, 'call', _294 => _294()]) || this.generateSessionId();
|
|
11664
11655
|
return await this.db.transaction().execute(async (trx) => {
|
|
11665
11656
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
|
|
11666
11657
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", appName).where("user_id", "=", userId).executeTakeFirst();
|
|
11667
|
-
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
11668
|
-
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
11658
|
+
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _295 => _295.state]), {});
|
|
11659
|
+
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _296 => _296.state]), {});
|
|
11669
11660
|
if (!appState) {
|
|
11670
11661
|
await trx.insertInto("app_states").values({
|
|
11671
11662
|
app_name: appName,
|
|
@@ -11724,21 +11715,21 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
11724
11715
|
return void 0;
|
|
11725
11716
|
}
|
|
11726
11717
|
let eventQuery = trx.selectFrom("events").selectAll().where("session_id", "=", sessionId).orderBy("timestamp", "desc");
|
|
11727
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
11718
|
+
if (_optionalChain([config, 'optionalAccess', _297 => _297.afterTimestamp])) {
|
|
11728
11719
|
eventQuery = eventQuery.where(
|
|
11729
11720
|
"timestamp",
|
|
11730
11721
|
">=",
|
|
11731
11722
|
new Date(config.afterTimestamp * 1e3)
|
|
11732
11723
|
);
|
|
11733
11724
|
}
|
|
11734
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
11725
|
+
if (_optionalChain([config, 'optionalAccess', _298 => _298.numRecentEvents])) {
|
|
11735
11726
|
eventQuery = eventQuery.limit(config.numRecentEvents);
|
|
11736
11727
|
}
|
|
11737
11728
|
const storageEvents = await eventQuery.execute();
|
|
11738
11729
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
|
|
11739
11730
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", appName).where("user_id", "=", userId).executeTakeFirst();
|
|
11740
|
-
const currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
11741
|
-
const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
11731
|
+
const currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _299 => _299.state]), {});
|
|
11732
|
+
const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _300 => _300.state]), {});
|
|
11742
11733
|
const sessionState = this.parseJsonSafely(storageSession.state, {});
|
|
11743
11734
|
const mergedState = this.mergeState(
|
|
11744
11735
|
currentAppState,
|
|
@@ -11796,13 +11787,13 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
11796
11787
|
}
|
|
11797
11788
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", session.appName).executeTakeFirst();
|
|
11798
11789
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", session.appName).where("user_id", "=", session.userId).executeTakeFirst();
|
|
11799
|
-
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
11800
|
-
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
11790
|
+
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _301 => _301.state]), {});
|
|
11791
|
+
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _302 => _302.state]), {});
|
|
11801
11792
|
let sessionState = this.parseJsonSafely(storageSession.state, {});
|
|
11802
11793
|
let appStateDelta = {};
|
|
11803
11794
|
let userStateDelta = {};
|
|
11804
11795
|
let sessionStateDelta = {};
|
|
11805
|
-
if (_optionalChain([event, 'access',
|
|
11796
|
+
if (_optionalChain([event, 'access', _303 => _303.actions, 'optionalAccess', _304 => _304.stateDelta])) {
|
|
11806
11797
|
const deltas = this.extractStateDelta(event.actions.stateDelta);
|
|
11807
11798
|
appStateDelta = deltas.appStateDelta;
|
|
11808
11799
|
userStateDelta = deltas.userStateDelta;
|
|
@@ -11948,7 +11939,7 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
11948
11939
|
* Overrides the base class method to work with plain object state.
|
|
11949
11940
|
*/
|
|
11950
11941
|
updateSessionState(session, event) {
|
|
11951
|
-
if (!_optionalChain([event, 'access',
|
|
11942
|
+
if (!_optionalChain([event, 'access', _305 => _305.actions, 'optionalAccess', _306 => _306.stateDelta])) {
|
|
11952
11943
|
return;
|
|
11953
11944
|
}
|
|
11954
11945
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
@@ -12118,7 +12109,7 @@ var GcsArtifactService = class {
|
|
|
12118
12109
|
};
|
|
12119
12110
|
return part;
|
|
12120
12111
|
} catch (error) {
|
|
12121
|
-
if (_optionalChain([error, 'optionalAccess',
|
|
12112
|
+
if (_optionalChain([error, 'optionalAccess', _307 => _307.code]) === 404) {
|
|
12122
12113
|
return null;
|
|
12123
12114
|
}
|
|
12124
12115
|
throw error;
|
|
@@ -12369,13 +12360,13 @@ var VertexAiEvalFacade = class _VertexAiEvalFacade {
|
|
|
12369
12360
|
};
|
|
12370
12361
|
}
|
|
12371
12362
|
_getText(content) {
|
|
12372
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
12363
|
+
if (_optionalChain([content, 'optionalAccess', _308 => _308.parts])) {
|
|
12373
12364
|
return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join("\n");
|
|
12374
12365
|
}
|
|
12375
12366
|
return "";
|
|
12376
12367
|
}
|
|
12377
12368
|
_getScore(evalResult) {
|
|
12378
|
-
if (_optionalChain([evalResult, 'optionalAccess',
|
|
12369
|
+
if (_optionalChain([evalResult, 'optionalAccess', _309 => _309.summaryMetrics, 'optionalAccess', _310 => _310[0], 'optionalAccess', _311 => _311.meanScore]) !== void 0 && typeof evalResult.summaryMetrics[0].meanScore === "number" && !Number.isNaN(evalResult.summaryMetrics[0].meanScore)) {
|
|
12379
12370
|
return evalResult.summaryMetrics[0].meanScore;
|
|
12380
12371
|
}
|
|
12381
12372
|
return void 0;
|
|
@@ -12525,7 +12516,7 @@ var ResponseEvaluator = class extends Evaluator {
|
|
|
12525
12516
|
return fmeasure;
|
|
12526
12517
|
}
|
|
12527
12518
|
extractText(content) {
|
|
12528
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
12519
|
+
if (_optionalChain([content, 'optionalAccess', _312 => _312.parts])) {
|
|
12529
12520
|
return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join(" ");
|
|
12530
12521
|
}
|
|
12531
12522
|
return "";
|
|
@@ -12558,7 +12549,7 @@ var TrajectoryEvaluator = class extends Evaluator {
|
|
|
12558
12549
|
for (let i = 0; i < actualInvocations.length; i++) {
|
|
12559
12550
|
const actual = actualInvocations[i];
|
|
12560
12551
|
const expected = expectedInvocations[i];
|
|
12561
|
-
if (!_optionalChain([actual, 'access',
|
|
12552
|
+
if (!_optionalChain([actual, 'access', _313 => _313.intermediateData, 'optionalAccess', _314 => _314.toolUses]) || !_optionalChain([expected, 'access', _315 => _315.intermediateData, 'optionalAccess', _316 => _316.toolUses])) {
|
|
12562
12553
|
perInvocationResults.push({
|
|
12563
12554
|
actualInvocation: actual,
|
|
12564
12555
|
expectedInvocation: expected,
|
|
@@ -12646,7 +12637,7 @@ var SafetyEvaluatorV1 = class extends Evaluator {
|
|
|
12646
12637
|
|
|
12647
12638
|
// src/evaluation/llm-as-judge-utils.ts
|
|
12648
12639
|
function getTextFromContent(content) {
|
|
12649
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
12640
|
+
if (_optionalChain([content, 'optionalAccess', _317 => _317.parts])) {
|
|
12650
12641
|
return content.parts.map((part) => part.text).filter(Boolean).join("\n");
|
|
12651
12642
|
}
|
|
12652
12643
|
return "";
|
|
@@ -12658,9 +12649,9 @@ function getEvalStatus(score, threshold) {
|
|
|
12658
12649
|
// src/evaluation/llm-as-judge.ts
|
|
12659
12650
|
var LlmAsJudge = class {
|
|
12660
12651
|
async sampleJudge(prompt, numSamples, critiqueParser, judgeModelOptions) {
|
|
12661
|
-
const modelName = _optionalChain([judgeModelOptions, 'optionalAccess',
|
|
12652
|
+
const modelName = _optionalChain([judgeModelOptions, 'optionalAccess', _318 => _318.judgeModel]) || "gemini-2.5-flash";
|
|
12662
12653
|
const model = LLMRegistry.getModelOrCreate(modelName);
|
|
12663
|
-
const config = _optionalChain([judgeModelOptions, 'optionalAccess',
|
|
12654
|
+
const config = _optionalChain([judgeModelOptions, 'optionalAccess', _319 => _319.judgeModelConfig]) || {};
|
|
12664
12655
|
const samples = [];
|
|
12665
12656
|
for (let i = 0; i < numSamples; i++) {
|
|
12666
12657
|
try {
|
|
@@ -12726,7 +12717,7 @@ function parseCritique(response) {
|
|
|
12726
12717
|
const labelMatchIsResponseValid = response.match(
|
|
12727
12718
|
/"is_the_agent_response_valid":\s*\[*[\n\s]*"*([^"^\]^\s]*)"*[\n\s]*\]*\s*[,\n\}]/
|
|
12728
12719
|
);
|
|
12729
|
-
if (_optionalChain([labelMatchIsResponseValid, 'optionalAccess',
|
|
12720
|
+
if (_optionalChain([labelMatchIsResponseValid, 'optionalAccess', _320 => _320[1]])) {
|
|
12730
12721
|
const label = labelMatchIsResponseValid[1].toLowerCase();
|
|
12731
12722
|
return label === "valid" ? "valid" /* VALID */ : "invalid" /* INVALID */;
|
|
12732
12723
|
}
|
|
@@ -12771,7 +12762,7 @@ var FinalResponseMatchV2Evaluator = class extends Evaluator {
|
|
|
12771
12762
|
"{prompt}",
|
|
12772
12763
|
prompt
|
|
12773
12764
|
).replace("{response}", response).replace("{golden_response}", goldenResponse);
|
|
12774
|
-
const numSamples = _nullishCoalesce(_optionalChain([this, 'access',
|
|
12765
|
+
const numSamples = _nullishCoalesce(_optionalChain([this, 'access', _321 => _321.metric, 'access', _322 => _322.judgeModelOptions, 'optionalAccess', _323 => _323.numSamples]), () => ( DEFAULT_NUM_SAMPLES));
|
|
12775
12766
|
const labels = await this.llmAsJudge.sampleJudge(
|
|
12776
12767
|
formattedPrompt,
|
|
12777
12768
|
numSamples,
|
|
@@ -12811,7 +12802,7 @@ var MetricEvaluatorRegistry = (_class35 = class {constructor() { _class35.protot
|
|
|
12811
12802
|
const metricName = metricInfo.metricName;
|
|
12812
12803
|
if (this.registry.has(metricName)) {
|
|
12813
12804
|
console.info(
|
|
12814
|
-
`Updating Evaluator class for ${metricName} from ${_optionalChain([this, 'access',
|
|
12805
|
+
`Updating Evaluator class for ${metricName} from ${_optionalChain([this, 'access', _324 => _324.registry, 'access', _325 => _325.get, 'call', _326 => _326(metricName), 'optionalAccess', _327 => _327.evaluator, 'access', _328 => _328.name])} to ${evaluator.name}`
|
|
12815
12806
|
);
|
|
12816
12807
|
}
|
|
12817
12808
|
this.registry.set(metricName, {
|
|
@@ -12925,10 +12916,10 @@ var LocalEvalService = class extends BaseEvalService {
|
|
|
12925
12916
|
for (const evalMetric of evaluateConfig.evalMetrics) {
|
|
12926
12917
|
const evaluator = DEFAULT_METRIC_EVALUATOR_REGISTRY.getEvaluator(evalMetric);
|
|
12927
12918
|
const actual = results.filter(
|
|
12928
|
-
(r) => !_optionalChain([r, 'access',
|
|
12919
|
+
(r) => !_optionalChain([r, 'access', _329 => _329.invocationId, 'optionalAccess', _330 => _330.includes, 'call', _331 => _331("expected")])
|
|
12929
12920
|
);
|
|
12930
12921
|
const expected = results.filter(
|
|
12931
|
-
(r) => _optionalChain([r, 'access',
|
|
12922
|
+
(r) => _optionalChain([r, 'access', _332 => _332.invocationId, 'optionalAccess', _333 => _333.includes, 'call', _334 => _334("expected")])
|
|
12932
12923
|
);
|
|
12933
12924
|
const result = await evaluator.evaluateInvocations(actual, expected);
|
|
12934
12925
|
evalResult.evalCaseResults.push({
|
|
@@ -13320,13 +13311,13 @@ ${failures.join(
|
|
|
13320
13311
|
console.log("\n\n");
|
|
13321
13312
|
}
|
|
13322
13313
|
static _convertContentToText(content) {
|
|
13323
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
13314
|
+
if (_optionalChain([content, 'optionalAccess', _335 => _335.parts])) {
|
|
13324
13315
|
return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join("\n");
|
|
13325
13316
|
}
|
|
13326
13317
|
return "";
|
|
13327
13318
|
}
|
|
13328
13319
|
static _convertToolCallsToText(intermediateData) {
|
|
13329
|
-
if (_optionalChain([intermediateData, 'optionalAccess',
|
|
13320
|
+
if (_optionalChain([intermediateData, 'optionalAccess', _336 => _336.toolUses])) {
|
|
13330
13321
|
return intermediateData.toolUses.map((t) => JSON.stringify(t)).join("\n");
|
|
13331
13322
|
}
|
|
13332
13323
|
return "";
|
|
@@ -13381,7 +13372,7 @@ ${failures.join(
|
|
|
13381
13372
|
for (const [metricName, evalMetricResultsWithInvocations] of Object.entries(
|
|
13382
13373
|
evalMetricResults
|
|
13383
13374
|
)) {
|
|
13384
|
-
const threshold = _optionalChain([evalMetricResultsWithInvocations, 'access',
|
|
13375
|
+
const threshold = _optionalChain([evalMetricResultsWithInvocations, 'access', _337 => _337[0], 'optionalAccess', _338 => _338.evalMetricResult, 'access', _339 => _339.threshold]) || 0;
|
|
13385
13376
|
const scores = evalMetricResultsWithInvocations.map((m) => m.evalMetricResult.score).filter((s) => s !== void 0);
|
|
13386
13377
|
let overallScore;
|
|
13387
13378
|
let overallEvalStatus;
|
|
@@ -13470,7 +13461,7 @@ var RougeEvaluator = class extends Evaluator {
|
|
|
13470
13461
|
}
|
|
13471
13462
|
};
|
|
13472
13463
|
function getTextFromContent2(content) {
|
|
13473
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
13464
|
+
if (_optionalChain([content, 'optionalAccess', _340 => _340.parts])) {
|
|
13474
13465
|
return content.parts.map((part) => part.text).filter(Boolean).join("\n");
|
|
13475
13466
|
}
|
|
13476
13467
|
return "";
|