@iqai/adk 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -82,7 +82,8 @@ var init_logger = __esm({
82
82
  title: `${icon} ${this.capitalize(level)} @ ${time} (${this.name})`,
83
83
  description: message,
84
84
  lines,
85
- color
85
+ color,
86
+ wrap: true
86
87
  });
87
88
  method(box);
88
89
  } else {
@@ -109,7 +110,7 @@ var init_logger = __esm({
109
110
  }
110
111
  formatArgs(args, includeStack = false) {
111
112
  const lines = [];
112
- const maxFrames = Number(process.env.ADK_ERROR_STACK_FRAMES || 8);
113
+ const maxFrames = process.env.ADK_ERROR_STACK_FRAMES !== void 0 ? Number(process.env.ADK_ERROR_STACK_FRAMES) : Number.POSITIVE_INFINITY;
113
114
  for (const arg of args) {
114
115
  if (!arg) continue;
115
116
  if (arg instanceof Error) {
@@ -161,7 +162,8 @@ var init_logger = __esm({
161
162
  maxWidthPct = 0.9,
162
163
  color = _chalk2.default.yellow,
163
164
  pad = 1,
164
- borderChar = "\u2500"
165
+ borderChar = "\u2500",
166
+ wrap = false
165
167
  } = params;
166
168
  const isProd = process.env.NODE_ENV === "production";
167
169
  const forceBoxes = process.env.ADK_FORCE_BOXES === "true";
@@ -181,20 +183,41 @@ var init_logger = __esm({
181
183
  const top = `\u250C${horizontal}\u2510`;
182
184
  const separator = `\u251C${horizontal}\u2524`;
183
185
  const bottom = `\u2514${horizontal}\u2518`;
184
- const padLine = (text) => {
185
- const maxContent = innerWidth - pad * 2;
186
- const truncated = text.length > maxContent ? `${text.slice(0, maxContent - 1)}\u2026` : text;
187
- const padded = " ".repeat(pad) + truncated;
188
- return padded + " ".repeat(innerWidth - padded.length);
186
+ const maxContent = innerWidth - pad * 2;
187
+ const wrapText = (text) => {
188
+ if (!wrap) {
189
+ const truncated = text.length > maxContent ? `${text.slice(0, maxContent - 1)}\u2026` : text;
190
+ const padded = " ".repeat(pad) + truncated;
191
+ return [padded + " ".repeat(innerWidth - padded.length)];
192
+ }
193
+ const out = [];
194
+ let remaining = text;
195
+ while (remaining.length > 0) {
196
+ if (remaining.length <= maxContent) {
197
+ const padded2 = " ".repeat(pad) + remaining;
198
+ out.push(padded2 + " ".repeat(innerWidth - padded2.length));
199
+ break;
200
+ }
201
+ let sliceEnd = maxContent;
202
+ const slice = remaining.slice(0, maxContent + 1);
203
+ const lastSpace = slice.lastIndexOf(" ");
204
+ if (lastSpace > -1 && lastSpace >= Math.floor(maxContent * 0.6)) {
205
+ sliceEnd = lastSpace;
206
+ }
207
+ const chunk = remaining.slice(0, sliceEnd).trimEnd();
208
+ const padded = " ".repeat(pad) + chunk;
209
+ out.push(padded + " ".repeat(innerWidth - padded.length));
210
+ remaining = remaining.slice(sliceEnd).trimStart();
211
+ }
212
+ return out;
189
213
  };
190
- const content = [
191
- top,
192
- `\u2502 ${padLine(title)} \u2502`,
193
- separator,
194
- `\u2502 ${padLine(description)} \u2502`,
195
- ...lines.map((line) => `\u2502 ${padLine(line)} \u2502`),
196
- bottom
197
- ];
214
+ const content = [top];
215
+ for (const l of wrapText(title)) content.push(`\u2502 ${l} \u2502`);
216
+ content.push(separator);
217
+ for (const l of wrapText(description)) content.push(`\u2502 ${l} \u2502`);
218
+ for (const line of lines)
219
+ for (const l of wrapText(line)) content.push(`\u2502 ${l} \u2502`);
220
+ content.push(bottom);
198
221
  return `
199
222
  ${content.map((line) => color(line)).join("\n")}`;
200
223
  }
@@ -1520,7 +1543,11 @@ var AiSdkLlm = (_class6 = class extends BaseLlm {
1520
1543
  * @param model - Pre-configured LanguageModel from provider(modelName)
1521
1544
  */
1522
1545
  constructor(modelInstance) {
1523
- super(modelInstance.modelId || "ai-sdk-model");_class6.prototype.__init12.call(this);;
1546
+ let modelId = "ai-sdk-model";
1547
+ if (typeof modelInstance !== "string") {
1548
+ modelId = modelInstance.modelId;
1549
+ }
1550
+ super(modelId);_class6.prototype.__init12.call(this);;
1524
1551
  this.modelInstance = modelInstance;
1525
1552
  }
1526
1553
  /**
@@ -1567,7 +1594,7 @@ var AiSdkLlm = (_class6 = class extends BaseLlm {
1567
1594
  functionCall: {
1568
1595
  id: toolCall.toolCallId,
1569
1596
  name: toolCall.toolName,
1570
- args: toolCall.args
1597
+ args: toolCall.input
1571
1598
  }
1572
1599
  });
1573
1600
  }
@@ -1580,8 +1607,8 @@ var AiSdkLlm = (_class6 = class extends BaseLlm {
1580
1607
  parts: parts.length > 0 ? parts : [{ text: "" }]
1581
1608
  },
1582
1609
  usageMetadata: finalUsage ? {
1583
- promptTokenCount: finalUsage.promptTokens,
1584
- candidatesTokenCount: finalUsage.completionTokens,
1610
+ promptTokenCount: finalUsage.inputTokens,
1611
+ candidatesTokenCount: finalUsage.outputTokens,
1585
1612
  totalTokenCount: finalUsage.totalTokens
1586
1613
  } : void 0,
1587
1614
  finishReason: this.mapFinishReason(finishReason),
@@ -1599,7 +1626,7 @@ var AiSdkLlm = (_class6 = class extends BaseLlm {
1599
1626
  functionCall: {
1600
1627
  id: toolCall.toolCallId,
1601
1628
  name: toolCall.toolName,
1602
- args: toolCall.args
1629
+ args: toolCall.input
1603
1630
  }
1604
1631
  });
1605
1632
  }
@@ -1610,8 +1637,8 @@ var AiSdkLlm = (_class6 = class extends BaseLlm {
1610
1637
  parts: parts.length > 0 ? parts : [{ text: "" }]
1611
1638
  },
1612
1639
  usageMetadata: result.usage ? {
1613
- promptTokenCount: result.usage.promptTokens,
1614
- candidatesTokenCount: result.usage.completionTokens,
1640
+ promptTokenCount: result.usage.inputTokens,
1641
+ candidatesTokenCount: result.usage.outputTokens,
1615
1642
  totalTokenCount: result.usage.totalTokens
1616
1643
  } : void 0,
1617
1644
  finishReason: this.mapFinishReason(result.finishReason),
@@ -1687,7 +1714,7 @@ var AiSdkLlm = (_class6 = class extends BaseLlm {
1687
1714
  for (const funcDecl of toolConfig.functionDeclarations) {
1688
1715
  tools[funcDecl.name] = {
1689
1716
  description: funcDecl.description,
1690
- parameters: _ai.jsonSchema.call(void 0,
1717
+ inputSchema: _ai.jsonSchema.call(void 0,
1691
1718
  this.transformSchemaForAiSdk(funcDecl.parameters || {})
1692
1719
  )
1693
1720
  };
@@ -1733,7 +1760,7 @@ var AiSdkLlm = (_class6 = class extends BaseLlm {
1733
1760
  type: "tool-call",
1734
1761
  toolCallId: funcPart.functionCall.id,
1735
1762
  toolName: funcPart.functionCall.name,
1736
- args: funcPart.functionCall.args
1763
+ input: funcPart.functionCall.args
1737
1764
  });
1738
1765
  }
1739
1766
  }
@@ -1746,12 +1773,14 @@ var AiSdkLlm = (_class6 = class extends BaseLlm {
1746
1773
  const functionResponses = content.parts.filter(
1747
1774
  (part) => part.functionResponse
1748
1775
  );
1749
- const contentParts2 = functionResponses.map((part) => ({
1750
- type: "tool-result",
1751
- toolCallId: part.functionResponse.id,
1752
- toolName: part.functionResponse.name || "unknown",
1753
- result: part.functionResponse.response
1754
- }));
1776
+ const contentParts2 = functionResponses.map((part) => {
1777
+ return {
1778
+ type: "tool-result",
1779
+ toolCallId: part.functionResponse.id,
1780
+ toolName: part.functionResponse.name || "unknown",
1781
+ output: part.functionResponse.response
1782
+ };
1783
+ });
1755
1784
  return {
1756
1785
  role: "tool",
1757
1786
  content: contentParts2
@@ -2201,16 +2230,6 @@ var GoogleLlm = class extends BaseLlm {
2201
2230
  dataObj.displayName = null;
2202
2231
  }
2203
2232
  }
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
2233
  /**
2215
2234
  * Provides the api client.
2216
2235
  */
@@ -2327,7 +2346,7 @@ var OpenAiLlm = class extends BaseLlm {
2327
2346
  (content) => this.contentToOpenAiMessage(content)
2328
2347
  );
2329
2348
  let tools;
2330
- if (_optionalChain([llmRequest, 'access', _94 => _94.config, 'optionalAccess', _95 => _95.tools, 'optionalAccess', _96 => _96[0], 'optionalAccess', _97 => _97.functionDeclarations])) {
2349
+ if (_optionalChain([llmRequest, 'access', _92 => _92.config, 'optionalAccess', _93 => _93.tools, 'optionalAccess', _94 => _94[0], 'optionalAccess', _95 => _95.functionDeclarations])) {
2331
2350
  tools = llmRequest.config.tools[0].functionDeclarations.map(
2332
2351
  (funcDecl) => this.functionDeclarationToOpenAiTool(funcDecl)
2333
2352
  );
@@ -2345,9 +2364,9 @@ var OpenAiLlm = class extends BaseLlm {
2345
2364
  messages: openAiMessages,
2346
2365
  tools,
2347
2366
  tool_choice: tools ? "auto" : void 0,
2348
- max_tokens: _optionalChain([llmRequest, 'access', _98 => _98.config, 'optionalAccess', _99 => _99.maxOutputTokens]),
2349
- temperature: _optionalChain([llmRequest, 'access', _100 => _100.config, 'optionalAccess', _101 => _101.temperature]),
2350
- top_p: _optionalChain([llmRequest, 'access', _102 => _102.config, 'optionalAccess', _103 => _103.topP]),
2367
+ max_tokens: _optionalChain([llmRequest, 'access', _96 => _96.config, 'optionalAccess', _97 => _97.maxOutputTokens]),
2368
+ temperature: _optionalChain([llmRequest, 'access', _98 => _98.config, 'optionalAccess', _99 => _99.temperature]),
2369
+ top_p: _optionalChain([llmRequest, 'access', _100 => _100.config, 'optionalAccess', _101 => _101.topP]),
2351
2370
  stream
2352
2371
  };
2353
2372
  if (stream) {
@@ -2367,7 +2386,7 @@ var OpenAiLlm = class extends BaseLlm {
2367
2386
  if (chunk.usage) {
2368
2387
  usageMetadata = chunk.usage;
2369
2388
  }
2370
- if (_optionalChain([llmResponse, 'access', _104 => _104.content, 'optionalAccess', _105 => _105.parts, 'optionalAccess', _106 => _106[0], 'optionalAccess', _107 => _107.text])) {
2389
+ if (_optionalChain([llmResponse, 'access', _102 => _102.content, 'optionalAccess', _103 => _103.parts, 'optionalAccess', _104 => _104[0], 'optionalAccess', _105 => _105.text])) {
2371
2390
  const part0 = llmResponse.content.parts[0];
2372
2391
  if (part0.thought) {
2373
2392
  thoughtText += part0.text;
@@ -2408,10 +2427,10 @@ var OpenAiLlm = class extends BaseLlm {
2408
2427
  function: { name: "", arguments: "" }
2409
2428
  };
2410
2429
  }
2411
- if (_optionalChain([toolCall, 'access', _108 => _108.function, 'optionalAccess', _109 => _109.name])) {
2430
+ if (_optionalChain([toolCall, 'access', _106 => _106.function, 'optionalAccess', _107 => _107.name])) {
2412
2431
  accumulatedToolCalls[index].function.name += toolCall.function.name;
2413
2432
  }
2414
- if (_optionalChain([toolCall, 'access', _110 => _110.function, 'optionalAccess', _111 => _111.arguments])) {
2433
+ if (_optionalChain([toolCall, 'access', _108 => _108.function, 'optionalAccess', _109 => _109.arguments])) {
2415
2434
  accumulatedToolCalls[index].function.arguments += toolCall.function.arguments;
2416
2435
  }
2417
2436
  }
@@ -2426,7 +2445,7 @@ var OpenAiLlm = class extends BaseLlm {
2426
2445
  }
2427
2446
  if (accumulatedToolCalls.length > 0) {
2428
2447
  for (const toolCall of accumulatedToolCalls) {
2429
- if (_optionalChain([toolCall, 'access', _112 => _112.function, 'optionalAccess', _113 => _113.name])) {
2448
+ if (_optionalChain([toolCall, 'access', _110 => _110.function, 'optionalAccess', _111 => _111.name])) {
2430
2449
  parts.push({
2431
2450
  functionCall: {
2432
2451
  id: toolCall.id,
@@ -2486,7 +2505,7 @@ var OpenAiLlm = class extends BaseLlm {
2486
2505
  response.usage
2487
2506
  );
2488
2507
  this.logger.debug(
2489
- `OpenAI response: ${_optionalChain([response, 'access', _114 => _114.usage, 'optionalAccess', _115 => _115.completion_tokens]) || 0} tokens`
2508
+ `OpenAI response: ${_optionalChain([response, 'access', _112 => _112.usage, 'optionalAccess', _113 => _113.completion_tokens]) || 0} tokens`
2490
2509
  );
2491
2510
  yield llmResponse;
2492
2511
  }
@@ -2513,7 +2532,7 @@ var OpenAiLlm = class extends BaseLlm {
2513
2532
  }
2514
2533
  if (delta.tool_calls) {
2515
2534
  for (const toolCall of delta.tool_calls) {
2516
- if (toolCall.type === "function" && _optionalChain([toolCall, 'access', _116 => _116.function, 'optionalAccess', _117 => _117.name])) {
2535
+ if (toolCall.type === "function" && _optionalChain([toolCall, 'access', _114 => _114.function, 'optionalAccess', _115 => _115.name])) {
2517
2536
  parts.push({
2518
2537
  functionCall: {
2519
2538
  id: toolCall.id || "",
@@ -2579,10 +2598,10 @@ var OpenAiLlm = class extends BaseLlm {
2579
2598
  if (role === "system") {
2580
2599
  return {
2581
2600
  role: "system",
2582
- content: _optionalChain([content, 'access', _118 => _118.parts, 'optionalAccess', _119 => _119[0], 'optionalAccess', _120 => _120.text]) || ""
2601
+ content: _optionalChain([content, 'access', _116 => _116.parts, 'optionalAccess', _117 => _117[0], 'optionalAccess', _118 => _118.text]) || ""
2583
2602
  };
2584
2603
  }
2585
- if (_optionalChain([content, 'access', _121 => _121.parts, 'optionalAccess', _122 => _122.some, 'call', _123 => _123((part) => part.functionCall)])) {
2604
+ if (_optionalChain([content, 'access', _119 => _119.parts, 'optionalAccess', _120 => _120.some, 'call', _121 => _121((part) => part.functionCall)])) {
2586
2605
  const functionCallPart = content.parts.find(
2587
2606
  (part) => part.functionCall
2588
2607
  );
@@ -2602,7 +2621,7 @@ var OpenAiLlm = class extends BaseLlm {
2602
2621
  ]
2603
2622
  };
2604
2623
  }
2605
- if (_optionalChain([content, 'access', _124 => _124.parts, 'optionalAccess', _125 => _125.some, 'call', _126 => _126((part) => part.functionResponse)])) {
2624
+ if (_optionalChain([content, 'access', _122 => _122.parts, 'optionalAccess', _123 => _123.some, 'call', _124 => _124((part) => part.functionResponse)])) {
2606
2625
  const functionResponsePart = content.parts.find(
2607
2626
  (part) => part.functionResponse
2608
2627
  );
@@ -2614,7 +2633,7 @@ var OpenAiLlm = class extends BaseLlm {
2614
2633
  )
2615
2634
  };
2616
2635
  }
2617
- if (_optionalChain([content, 'access', _127 => _127.parts, 'optionalAccess', _128 => _128.length]) === 1 && content.parts[0].text) {
2636
+ if (_optionalChain([content, 'access', _125 => _125.parts, 'optionalAccess', _126 => _126.length]) === 1 && content.parts[0].text) {
2618
2637
  return {
2619
2638
  role,
2620
2639
  content: content.parts[0].text
@@ -2637,7 +2656,7 @@ var OpenAiLlm = class extends BaseLlm {
2637
2656
  text: part.text
2638
2657
  };
2639
2658
  }
2640
- if (_optionalChain([part, 'access', _129 => _129.inline_data, 'optionalAccess', _130 => _130.mime_type]) && _optionalChain([part, 'access', _131 => _131.inline_data, 'optionalAccess', _132 => _132.data])) {
2659
+ 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
2660
  return {
2642
2661
  type: "image_url",
2643
2662
  image_url: {
@@ -2765,8 +2784,8 @@ var OpenAiLlm = class extends BaseLlm {
2765
2784
  * Check if response has inline data (similar to Google LLM)
2766
2785
  */
2767
2786
  hasInlineData(response) {
2768
- const parts = _optionalChain([response, 'access', _133 => _133.content, 'optionalAccess', _134 => _134.parts]);
2769
- return _optionalChain([parts, 'optionalAccess', _135 => _135.some, 'call', _136 => _136((part) => part.inlineData)]) || false;
2787
+ const parts = _optionalChain([response, 'access', _131 => _131.content, 'optionalAccess', _132 => _132.parts]);
2788
+ return _optionalChain([parts, 'optionalAccess', _133 => _133.some, 'call', _134 => _134((part) => part.inlineData)]) || false;
2770
2789
  }
2771
2790
  /**
2772
2791
  * Gets the OpenAI client
@@ -3074,7 +3093,7 @@ var OAuth2Credential = class extends AuthCredential {
3074
3093
  "Cannot refresh token: no refresh token or refresh function"
3075
3094
  );
3076
3095
  }
3077
- const result = await _optionalChain([this, 'access', _137 => _137.refreshFunction, 'optionalCall', _138 => _138(this.refreshToken)]);
3096
+ const result = await _optionalChain([this, 'access', _135 => _135.refreshFunction, 'optionalCall', _136 => _136(this.refreshToken)]);
3078
3097
  if (!result) {
3079
3098
  throw new Error("Failed to refresh token");
3080
3099
  }
@@ -3109,7 +3128,7 @@ var AuthHandler = class {
3109
3128
  * Gets the authentication token
3110
3129
  */
3111
3130
  getToken() {
3112
- return _optionalChain([this, 'access', _139 => _139.credential, 'optionalAccess', _140 => _140.getToken, 'call', _141 => _141()]);
3131
+ return _optionalChain([this, 'access', _137 => _137.credential, 'optionalAccess', _138 => _138.getToken, 'call', _139 => _139()]);
3113
3132
  }
3114
3133
  /**
3115
3134
  * Gets headers for HTTP requests
@@ -3124,7 +3143,7 @@ var AuthHandler = class {
3124
3143
  * Refreshes the token if necessary
3125
3144
  */
3126
3145
  async refreshToken() {
3127
- if (_optionalChain([this, 'access', _142 => _142.credential, 'optionalAccess', _143 => _143.canRefresh, 'call', _144 => _144()])) {
3146
+ if (_optionalChain([this, 'access', _140 => _140.credential, 'optionalAccess', _141 => _141.canRefresh, 'call', _142 => _142()])) {
3128
3147
  await this.credential.refresh();
3129
3148
  }
3130
3149
  }
@@ -4085,7 +4104,6 @@ init_base_tool();
4085
4104
  // src/tools/base/create-tool.ts
4086
4105
  init_base_tool();
4087
4106
  var _zod = require('zod'); var z = _interopRequireWildcard(_zod);
4088
- var _zodtojsonschema = require('zod-to-json-schema');
4089
4107
  var CreatedTool = class extends BaseTool {
4090
4108
 
4091
4109
 
@@ -4131,10 +4149,7 @@ var CreatedTool = class extends BaseTool {
4131
4149
  * Builds the function declaration from the Zod schema
4132
4150
  */
4133
4151
  buildDeclaration() {
4134
- const rawParameters = _zodtojsonschema.zodToJsonSchema.call(void 0, this.schema, {
4135
- target: "jsonSchema7",
4136
- $refStrategy: "none"
4137
- });
4152
+ const rawParameters = z.toJSONSchema(this.schema);
4138
4153
  const { $schema, ...parameters } = rawParameters;
4139
4154
  return {
4140
4155
  name: this.name,
@@ -4411,7 +4426,7 @@ var AgentTool = (_class15 = class extends BaseTool {
4411
4426
  } catch (e3) {
4412
4427
  toolResult = mergedText;
4413
4428
  }
4414
- if (this.outputKey && _optionalChain([context4, 'optionalAccess', _145 => _145.state])) {
4429
+ if (this.outputKey && _optionalChain([context4, 'optionalAccess', _143 => _143.state])) {
4415
4430
  context4.state[this.outputKey] = toolResult;
4416
4431
  }
4417
4432
  return toolResult;
@@ -4678,7 +4693,7 @@ var FileOperationsTool = class extends BaseTool {
4678
4693
  name: "file_operations",
4679
4694
  description: "Perform file system operations like reading, writing, and managing files"
4680
4695
  });
4681
- this.basePath = _optionalChain([options, 'optionalAccess', _146 => _146.basePath]) || process.cwd();
4696
+ this.basePath = _optionalChain([options, 'optionalAccess', _144 => _144.basePath]) || process.cwd();
4682
4697
  }
4683
4698
  /**
4684
4699
  * Get the function declaration for the tool
@@ -5161,7 +5176,7 @@ var LoadMemoryTool = (_class20 = class extends BaseTool {
5161
5176
  const searchResult = await context4.searchMemory(args.query);
5162
5177
  return {
5163
5178
  memories: searchResult.memories || [],
5164
- count: _optionalChain([searchResult, 'access', _147 => _147.memories, 'optionalAccess', _148 => _148.length]) || 0
5179
+ count: _optionalChain([searchResult, 'access', _145 => _145.memories, 'optionalAccess', _146 => _146.length]) || 0
5165
5180
  };
5166
5181
  } catch (error) {
5167
5182
  console.error("Error searching memory:", error);
@@ -5718,7 +5733,7 @@ var McpClientService = (_class22 = class {
5718
5733
  },
5719
5734
  this,
5720
5735
  async (instance) => await instance.reinitialize(),
5721
- _optionalChain([this, 'access', _149 => _149.config, 'access', _150 => _150.retryOptions, 'optionalAccess', _151 => _151.maxRetries]) || 2
5736
+ _optionalChain([this, 'access', _147 => _147.config, 'access', _148 => _148.retryOptions, 'optionalAccess', _149 => _149.maxRetries]) || 2
5722
5737
  );
5723
5738
  return await wrappedCall();
5724
5739
  } catch (error) {
@@ -5802,7 +5817,7 @@ var McpClientService = (_class22 = class {
5802
5817
  this.mcpSamplingHandler = null;
5803
5818
  if (this.client) {
5804
5819
  try {
5805
- _optionalChain([this, 'access', _152 => _152.client, 'access', _153 => _153.removeRequestHandler, 'optionalCall', _154 => _154("sampling/createMessage")]);
5820
+ _optionalChain([this, 'access', _150 => _150.client, 'access', _151 => _151.removeRequestHandler, 'optionalCall', _152 => _152("sampling/createMessage")]);
5806
5821
  } catch (error) {
5807
5822
  this.logger.error("Failed to remove sampling handler:", error);
5808
5823
  }
@@ -6322,7 +6337,7 @@ var McpToolset = (_class24 = class {
6322
6337
  "resource_closed_error" /* RESOURCE_CLOSED_ERROR */
6323
6338
  );
6324
6339
  }
6325
- if (this.tools.length > 0 && !_optionalChain([this, 'access', _155 => _155.config, 'access', _156 => _156.cacheConfig, 'optionalAccess', _157 => _157.enabled]) === false) {
6340
+ if (this.tools.length > 0 && !_optionalChain([this, 'access', _153 => _153.config, 'access', _154 => _154.cacheConfig, 'optionalAccess', _155 => _155.enabled]) === false) {
6326
6341
  return this.tools;
6327
6342
  }
6328
6343
  if (!this.clientService) {
@@ -6351,7 +6366,7 @@ var McpToolset = (_class24 = class {
6351
6366
  }
6352
6367
  }
6353
6368
  }
6354
- if (_optionalChain([this, 'access', _158 => _158.config, 'access', _159 => _159.cacheConfig, 'optionalAccess', _160 => _160.enabled]) !== false) {
6369
+ if (_optionalChain([this, 'access', _156 => _156.config, 'access', _157 => _157.cacheConfig, 'optionalAccess', _158 => _158.enabled]) !== false) {
6355
6370
  this.tools = tools;
6356
6371
  }
6357
6372
  return tools;
@@ -6440,12 +6455,12 @@ function populateClientFunctionCallId(modelResponseEvent) {
6440
6455
  }
6441
6456
  }
6442
6457
  function removeClientFunctionCallId(content) {
6443
- if (_optionalChain([content, 'optionalAccess', _161 => _161.parts])) {
6458
+ if (_optionalChain([content, 'optionalAccess', _159 => _159.parts])) {
6444
6459
  for (const part of content.parts) {
6445
- if (_optionalChain([part, 'access', _162 => _162.functionCall, 'optionalAccess', _163 => _163.id, 'optionalAccess', _164 => _164.startsWith, 'call', _165 => _165(AF_FUNCTION_CALL_ID_PREFIX)])) {
6460
+ if (_optionalChain([part, 'access', _160 => _160.functionCall, 'optionalAccess', _161 => _161.id, 'optionalAccess', _162 => _162.startsWith, 'call', _163 => _163(AF_FUNCTION_CALL_ID_PREFIX)])) {
6446
6461
  part.functionCall.id = void 0;
6447
6462
  }
6448
- if (_optionalChain([part, 'access', _166 => _166.functionResponse, 'optionalAccess', _167 => _167.id, 'optionalAccess', _168 => _168.startsWith, 'call', _169 => _169(AF_FUNCTION_CALL_ID_PREFIX)])) {
6463
+ if (_optionalChain([part, 'access', _164 => _164.functionResponse, 'optionalAccess', _165 => _165.id, 'optionalAccess', _166 => _166.startsWith, 'call', _167 => _167(AF_FUNCTION_CALL_ID_PREFIX)])) {
6449
6464
  part.functionResponse.id = void 0;
6450
6465
  }
6451
6466
  }
@@ -6607,7 +6622,7 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
6607
6622
  }
6608
6623
  const mergedParts = [];
6609
6624
  for (const event of functionResponseEvents) {
6610
- if (_optionalChain([event, 'access', _170 => _170.content, 'optionalAccess', _171 => _171.parts])) {
6625
+ if (_optionalChain([event, 'access', _168 => _168.content, 'optionalAccess', _169 => _169.parts])) {
6611
6626
  for (const part of event.content.parts) {
6612
6627
  mergedParts.push(part);
6613
6628
  }
@@ -6732,7 +6747,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
6732
6747
  const seen = /* @__PURE__ */ new Set();
6733
6748
  const filtered = [];
6734
6749
  for (const t of tools) {
6735
- const name = _optionalChain([t, 'optionalAccess', _172 => _172.name]);
6750
+ const name = _optionalChain([t, 'optionalAccess', _170 => _170.name]);
6736
6751
  if (!name) continue;
6737
6752
  if (seen.has(name)) {
6738
6753
  continue;
@@ -6749,7 +6764,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
6749
6764
  if (tools.length > 0) {
6750
6765
  const toolsData = tools.map((tool) => ({
6751
6766
  Name: tool.name,
6752
- Description: _optionalChain([tool, 'access', _173 => _173.description, 'optionalAccess', _174 => _174.substring, 'call', _175 => _175(0, 50)]) + (_optionalChain([tool, 'access', _176 => _176.description, 'optionalAccess', _177 => _177.length]) > 50 ? "..." : ""),
6767
+ 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
6768
  "Long Running": tool.isLongRunning ? "Yes" : "No"
6754
6769
  }));
6755
6770
  this.logger.debugArray("\u{1F6E0}\uFE0F Available Tools", toolsData);
@@ -6812,14 +6827,14 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
6812
6827
  );
6813
6828
  if (functionResponseEvent) {
6814
6829
  yield functionResponseEvent;
6815
- const transferToAgent = _optionalChain([functionResponseEvent, 'access', _178 => _178.actions, 'optionalAccess', _179 => _179.transferToAgent]);
6830
+ const transferToAgent = _optionalChain([functionResponseEvent, 'access', _176 => _176.actions, 'optionalAccess', _177 => _177.transferToAgent]);
6816
6831
  if (transferToAgent) {
6817
6832
  this.logger.debug(`\u{1F504} Live transfer to agent '${transferToAgent}'`);
6818
6833
  const agentToRun = this._getAgentToRun(
6819
6834
  invocationContext,
6820
6835
  transferToAgent
6821
6836
  );
6822
- for await (const event of _optionalChain([agentToRun, 'access', _180 => _180.runLive, 'optionalCall', _181 => _181(invocationContext)]) || agentToRun.runAsync(invocationContext)) {
6837
+ for await (const event of _optionalChain([agentToRun, 'access', _178 => _178.runLive, 'optionalCall', _179 => _179(invocationContext)]) || agentToRun.runAsync(invocationContext)) {
6823
6838
  yield event;
6824
6839
  }
6825
6840
  }
@@ -6851,7 +6866,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
6851
6866
  yield authEvent;
6852
6867
  }
6853
6868
  yield functionResponseEvent;
6854
- const transferToAgent = _optionalChain([functionResponseEvent, 'access', _182 => _182.actions, 'optionalAccess', _183 => _183.transferToAgent]);
6869
+ const transferToAgent = _optionalChain([functionResponseEvent, 'access', _180 => _180.actions, 'optionalAccess', _181 => _181.transferToAgent]);
6855
6870
  if (transferToAgent) {
6856
6871
  this.logger.debug(`\u{1F504} Transferring to agent '${transferToAgent}'`);
6857
6872
  const agentToRun = this._getAgentToRun(
@@ -6897,7 +6912,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
6897
6912
  }
6898
6913
  invocationContext.incrementLlmCallCount();
6899
6914
  const isStreaming = invocationContext.runConfig.streamingMode === "sse" /* SSE */;
6900
- let tools = _optionalChain([llmRequest, 'access', _184 => _184.config, 'optionalAccess', _185 => _185.tools]) || [];
6915
+ let tools = _optionalChain([llmRequest, 'access', _182 => _182.config, 'optionalAccess', _183 => _183.tools]) || [];
6901
6916
  if (tools.length) {
6902
6917
  const deduped = [];
6903
6918
  const seenFn = /* @__PURE__ */ new Set();
@@ -6906,7 +6921,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
6906
6921
  if (tool && Array.isArray(tool.functionDeclarations)) {
6907
6922
  const newFds = tool.functionDeclarations.filter(
6908
6923
  (fd) => {
6909
- if (_optionalChain([fd, 'optionalAccess', _186 => _186.name])) {
6924
+ if (_optionalChain([fd, 'optionalAccess', _184 => _184.name])) {
6910
6925
  if (seenFn.has(fd.name)) {
6911
6926
  return false;
6912
6927
  }
@@ -6918,7 +6933,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
6918
6933
  if (newFds.length) {
6919
6934
  deduped.push({ ...tool, functionDeclarations: newFds });
6920
6935
  }
6921
- } else if (_optionalChain([tool, 'optionalAccess', _187 => _187.name])) {
6936
+ } else if (_optionalChain([tool, 'optionalAccess', _185 => _185.name])) {
6922
6937
  if (seenFn.has(tool.name)) continue;
6923
6938
  seenFn.add(tool.name);
6924
6939
  deduped.push(tool);
@@ -6938,21 +6953,21 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
6938
6953
  return tool.functionDeclarations.map((fn) => fn.name).join(", ");
6939
6954
  }
6940
6955
  if (tool.name) return tool.name;
6941
- if (_optionalChain([tool, 'access', _188 => _188.function, 'optionalAccess', _189 => _189.name])) return tool.function.name;
6942
- if (_optionalChain([tool, 'access', _190 => _190.function, 'optionalAccess', _191 => _191.function, 'optionalAccess', _192 => _192.name])) return tool.function.function.name;
6956
+ if (_optionalChain([tool, 'access', _186 => _186.function, 'optionalAccess', _187 => _187.name])) return tool.function.name;
6957
+ if (_optionalChain([tool, 'access', _188 => _188.function, 'optionalAccess', _189 => _189.function, 'optionalAccess', _190 => _190.name])) return tool.function.function.name;
6943
6958
  return "unknown";
6944
6959
  }).join(", ");
6945
6960
  const systemInstruction = llmRequest.getSystemInstructionText() || "";
6946
6961
  const truncatedSystemInstruction = systemInstruction.length > 100 ? `${systemInstruction.substring(0, 100)}...` : systemInstruction;
6947
- const contentPreview = _optionalChain([llmRequest, 'access', _193 => _193.contents, 'optionalAccess', _194 => _194.length]) > 0 ? LogFormatter.formatContentPreview(llmRequest.contents[0]) : "none";
6962
+ const contentPreview = _optionalChain([llmRequest, 'access', _191 => _191.contents, 'optionalAccess', _192 => _192.length]) > 0 ? LogFormatter.formatContentPreview(llmRequest.contents[0]) : "none";
6948
6963
  this.logger.debugStructured("\u{1F4E4} LLM Request", {
6949
6964
  Model: llm.model,
6950
6965
  Agent: invocationContext.agent.name,
6951
- "Content Items": _optionalChain([llmRequest, 'access', _195 => _195.contents, 'optionalAccess', _196 => _196.length]) || 0,
6966
+ "Content Items": _optionalChain([llmRequest, 'access', _193 => _193.contents, 'optionalAccess', _194 => _194.length]) || 0,
6952
6967
  "Content Preview": contentPreview,
6953
6968
  "System Instruction": truncatedSystemInstruction || "none",
6954
6969
  "Available Tools": toolNames || "none",
6955
- "Tool Count": _optionalChain([llmRequest, 'access', _197 => _197.config, 'optionalAccess', _198 => _198.tools, 'optionalAccess', _199 => _199.length]) || 0,
6970
+ "Tool Count": _optionalChain([llmRequest, 'access', _195 => _195.config, 'optionalAccess', _196 => _196.tools, 'optionalAccess', _197 => _197.length]) || 0,
6956
6971
  Streaming: isStreaming ? "Yes" : "No"
6957
6972
  });
6958
6973
  let responseCount = 0;
@@ -6967,8 +6982,8 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
6967
6982
  llmRequest,
6968
6983
  llmResponse
6969
6984
  );
6970
- const tokenCount = _optionalChain([llmResponse, 'access', _200 => _200.usageMetadata, 'optionalAccess', _201 => _201.totalTokenCount]) || "unknown";
6971
- const functionCalls = _optionalChain([llmResponse, 'access', _202 => _202.content, 'optionalAccess', _203 => _203.parts, 'optionalAccess', _204 => _204.filter, 'call', _205 => _205((part) => part.functionCall)]) || [];
6985
+ const tokenCount = _optionalChain([llmResponse, 'access', _198 => _198.usageMetadata, 'optionalAccess', _199 => _199.totalTokenCount]) || "unknown";
6986
+ const functionCalls = _optionalChain([llmResponse, 'access', _200 => _200.content, 'optionalAccess', _201 => _201.parts, 'optionalAccess', _202 => _202.filter, 'call', _203 => _203((part) => part.functionCall)]) || [];
6972
6987
  const functionCallsDisplay = LogFormatter.formatFunctionCalls(functionCalls);
6973
6988
  const responsePreview = LogFormatter.formatResponsePreview(llmResponse);
6974
6989
  this.logger.debugStructured("\u{1F4E5} LLM Response", {
@@ -7112,7 +7127,7 @@ var EnhancedAuthConfig = class {
7112
7127
  */
7113
7128
  generateCredentialKey() {
7114
7129
  const schemeKey = this.authScheme.type || "unknown";
7115
- const credentialKey = _optionalChain([this, 'access', _206 => _206.rawAuthCredential, 'optionalAccess', _207 => _207.type]) || "none";
7130
+ const credentialKey = _optionalChain([this, 'access', _204 => _204.rawAuthCredential, 'optionalAccess', _205 => _205.type]) || "none";
7116
7131
  const timestamp = Date.now();
7117
7132
  return `adk_${schemeKey}_${credentialKey}_${timestamp}`;
7118
7133
  }
@@ -7269,7 +7284,7 @@ var AuthLlmRequestProcessor = class extends BaseLlmRequestProcessor {
7269
7284
  */
7270
7285
  parseAndStoreAuthResponse(authHandler, invocationContext) {
7271
7286
  try {
7272
- const credentialKey = _optionalChain([authHandler, 'access', _208 => _208.authConfig, 'access', _209 => _209.context, 'optionalAccess', _210 => _210.credentialKey]) || `temp:${Date.now()}`;
7287
+ const credentialKey = _optionalChain([authHandler, 'access', _206 => _206.authConfig, 'access', _207 => _207.context, 'optionalAccess', _208 => _208.credentialKey]) || `temp:${Date.now()}`;
7273
7288
  const fullCredentialKey = credentialKey.startsWith("temp:") ? credentialKey : `temp:${credentialKey}`;
7274
7289
  invocationContext.session.state[fullCredentialKey] = authHandler.credential;
7275
7290
  if (authHandler.authConfig.authScheme.type === "oauth2" || authHandler.authConfig.authScheme.type === "openIdConnect") {
@@ -7298,7 +7313,7 @@ var BasicLlmRequestProcessor = class extends BaseLlmRequestProcessor {
7298
7313
  llmRequest.config = {};
7299
7314
  }
7300
7315
  if (agent.outputSchema) {
7301
- const hasTools = await _asyncOptionalChain([(await _optionalChain([agent, 'access', _211 => _211.canonicalTools, 'optionalCall', _212 => _212(invocationContext)])), 'optionalAccess', async _213 => _213.length]) > 0;
7316
+ const hasTools = await _asyncOptionalChain([(await _optionalChain([agent, 'access', _209 => _209.canonicalTools, 'optionalCall', _210 => _210(invocationContext)])), 'optionalAccess', async _211 => _211.length]) > 0;
7302
7317
  const hasTransfers = !!("subAgents" in agent && agent.subAgents && agent.subAgents.length > 0 && !(agent.disallowTransferToParent && agent.disallowTransferToPeers));
7303
7318
  if (!hasTools && !hasTransfers) {
7304
7319
  llmRequest.setOutputSchema(agent.outputSchema);
@@ -7390,7 +7405,7 @@ var BuiltInCodeExecutor = class extends BaseCodeExecutor {
7390
7405
  * Pre-process the LLM request for Gemini 2.0+ models to use the code execution tool
7391
7406
  */
7392
7407
  processLlmRequest(llmRequest) {
7393
- if (!_optionalChain([llmRequest, 'access', _214 => _214.model, 'optionalAccess', _215 => _215.startsWith, 'call', _216 => _216("gemini-2")])) {
7408
+ if (!_optionalChain([llmRequest, 'access', _212 => _212.model, 'optionalAccess', _213 => _213.startsWith, 'call', _214 => _214("gemini-2")])) {
7394
7409
  throw new Error(
7395
7410
  `Gemini code execution tool is not supported for model ${llmRequest.model}`
7396
7411
  );
@@ -7435,7 +7450,7 @@ var CodeExecutionUtils = class _CodeExecutionUtils {
7435
7450
  * Extracts the first code block from the content and truncates everything after it
7436
7451
  */
7437
7452
  static extractCodeAndTruncateContent(content, codeBlockDelimiters) {
7438
- if (!_optionalChain([content, 'optionalAccess', _217 => _217.parts, 'optionalAccess', _218 => _218.length])) {
7453
+ if (!_optionalChain([content, 'optionalAccess', _215 => _215.parts, 'optionalAccess', _216 => _216.length])) {
7439
7454
  return null;
7440
7455
  }
7441
7456
  for (let idx = 0; idx < content.parts.length; idx++) {
@@ -7521,7 +7536,7 @@ ${fileNames}`);
7521
7536
  * Converts the code execution parts to text parts in a Content
7522
7537
  */
7523
7538
  static convertCodeExecutionParts(content, codeBlockDelimiter, executionResultDelimiters) {
7524
- if (!_optionalChain([content, 'access', _219 => _219.parts, 'optionalAccess', _220 => _220.length])) {
7539
+ if (!_optionalChain([content, 'access', _217 => _217.parts, 'optionalAccess', _218 => _218.length])) {
7525
7540
  return;
7526
7541
  }
7527
7542
  const lastPart = content.parts[content.parts.length - 1];
@@ -7914,7 +7929,7 @@ async function* runPostProcessor(invocationContext, llmResponse) {
7914
7929
  function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
7915
7930
  const allInputFiles = codeExecutorContext.getInputFiles();
7916
7931
  const savedFileNames = new Set(allInputFiles.map((f) => f.name));
7917
- for (let i = 0; i < (_optionalChain([llmRequest, 'access', _221 => _221.contents, 'optionalAccess', _222 => _222.length]) || 0); i++) {
7932
+ for (let i = 0; i < (_optionalChain([llmRequest, 'access', _219 => _219.contents, 'optionalAccess', _220 => _220.length]) || 0); i++) {
7918
7933
  const content = llmRequest.contents[i];
7919
7934
  if (content.role !== "user" || !content.parts) {
7920
7935
  continue;
@@ -7946,7 +7961,7 @@ Available file: \`${fileName}\`
7946
7961
  }
7947
7962
  function getOrSetExecutionId(invocationContext, codeExecutorContext) {
7948
7963
  const agent = invocationContext.agent;
7949
- if (!hasCodeExecutor(agent) || !_optionalChain([agent, 'access', _223 => _223.codeExecutor, 'optionalAccess', _224 => _224.stateful])) {
7964
+ if (!hasCodeExecutor(agent) || !_optionalChain([agent, 'access', _221 => _221.codeExecutor, 'optionalAccess', _222 => _222.stateful])) {
7950
7965
  return void 0;
7951
7966
  }
7952
7967
  let executionId = codeExecutorContext.getExecutionId();
@@ -8177,7 +8192,7 @@ function rearrangeEventsForLatestFunctionResponse(events) {
8177
8192
  continue;
8178
8193
  }
8179
8194
  const functionResponses2 = event.getFunctionResponses();
8180
- if (_optionalChain([functionResponses2, 'optionalAccess', _225 => _225.some, 'call', _226 => _226((fr) => fr.id && functionResponsesIds.has(fr.id))])) {
8195
+ if (_optionalChain([functionResponses2, 'optionalAccess', _223 => _223.some, 'call', _224 => _224((fr) => fr.id && functionResponsesIds.has(fr.id))])) {
8181
8196
  functionResponseEvents.push(event);
8182
8197
  }
8183
8198
  }
@@ -8276,7 +8291,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
8276
8291
  const partIndicesInMergedEvent = {};
8277
8292
  for (let idx = 0; idx < partsInMergedEvent.length; idx++) {
8278
8293
  const part = partsInMergedEvent[idx];
8279
- if (_optionalChain([part, 'access', _227 => _227.functionResponse, 'optionalAccess', _228 => _228.id])) {
8294
+ if (_optionalChain([part, 'access', _225 => _225.functionResponse, 'optionalAccess', _226 => _226.id])) {
8280
8295
  partIndicesInMergedEvent[part.functionResponse.id] = idx;
8281
8296
  }
8282
8297
  }
@@ -8285,7 +8300,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
8285
8300
  throw new Error("There should be at least one function_response part.");
8286
8301
  }
8287
8302
  for (const part of event.content.parts) {
8288
- if (_optionalChain([part, 'access', _229 => _229.functionResponse, 'optionalAccess', _230 => _230.id])) {
8303
+ if (_optionalChain([part, 'access', _227 => _227.functionResponse, 'optionalAccess', _228 => _228.id])) {
8289
8304
  const functionCallId = part.functionResponse.id;
8290
8305
  if (functionCallId in partIndicesInMergedEvent) {
8291
8306
  partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] = part;
@@ -8458,10 +8473,7 @@ var InstructionsLlmRequestProcessor = class extends BaseLlmRequestProcessor {
8458
8473
  }
8459
8474
  if (agent.outputSchema) {
8460
8475
  try {
8461
- const raw = _zodtojsonschema.zodToJsonSchema.call(void 0, agent.outputSchema, {
8462
- target: "jsonSchema7",
8463
- $refStrategy: "none"
8464
- });
8476
+ const raw = z.default.toJSONSchema(agent.outputSchema);
8465
8477
  const { $schema, ...json } = raw || {};
8466
8478
  llmRequest.appendInstructions([
8467
8479
  "You must respond with application/json that validates against this JSON Schema (do NOT wrap the output in markdown or code fences):",
@@ -8555,7 +8567,7 @@ var PlanReActPlanner = class extends BasePlanner {
8555
8567
  let firstFcPartIndex = -1;
8556
8568
  for (let i = 0; i < responseParts.length; i++) {
8557
8569
  if (responseParts[i].functionCall) {
8558
- if (!_optionalChain([responseParts, 'access', _231 => _231[i], 'access', _232 => _232.functionCall, 'optionalAccess', _233 => _233.name])) {
8570
+ if (!_optionalChain([responseParts, 'access', _229 => _229[i], 'access', _230 => _230.functionCall, 'optionalAccess', _231 => _231.name])) {
8559
8571
  continue;
8560
8572
  }
8561
8573
  preservedParts.push(responseParts[i]);
@@ -8594,7 +8606,7 @@ var PlanReActPlanner = class extends BasePlanner {
8594
8606
  * Handles non-function-call parts of the response
8595
8607
  */
8596
8608
  _handleNonFunctionCallParts(responsePart, preservedParts) {
8597
- if (_optionalChain([responsePart, 'access', _234 => _234.text, 'optionalAccess', _235 => _235.includes, 'call', _236 => _236(FINAL_ANSWER_TAG)])) {
8609
+ if (_optionalChain([responsePart, 'access', _232 => _232.text, 'optionalAccess', _233 => _233.includes, 'call', _234 => _234(FINAL_ANSWER_TAG)])) {
8598
8610
  const [reasoningText, finalAnswerText] = this._splitByLastPattern(
8599
8611
  responsePart.text,
8600
8612
  FINAL_ANSWER_TAG
@@ -8840,7 +8852,7 @@ var OutputSchemaResponseProcessor = (_class26 = class extends BaseLlmResponsePro
8840
8852
  stripCodeFences(raw) {
8841
8853
  const fencePattern = /```(?:json)?\s*([\s\S]*?)```/i;
8842
8854
  const fenceMatch = raw.match(fencePattern);
8843
- if (_optionalChain([fenceMatch, 'optionalAccess', _237 => _237[1]])) {
8855
+ if (_optionalChain([fenceMatch, 'optionalAccess', _235 => _235[1]])) {
8844
8856
  return fenceMatch[1].trim();
8845
8857
  }
8846
8858
  const lines = raw.split(/\r?\n/).map((l) => l.trim());
@@ -8877,7 +8889,7 @@ var SharedMemoryRequestProcessor = class extends BaseLlmRequestProcessor {
8877
8889
  const memoryService = invocationContext.memoryService;
8878
8890
  if (!memoryService) return;
8879
8891
  const lastUserEvent = invocationContext.session.events.findLast(
8880
- (e) => e.author === "user" && _optionalChain([e, 'access', _238 => _238.content, 'optionalAccess', _239 => _239.parts, 'optionalAccess', _240 => _240.length])
8892
+ (e) => e.author === "user" && _optionalChain([e, 'access', _236 => _236.content, 'optionalAccess', _237 => _237.parts, 'optionalAccess', _238 => _238.length])
8881
8893
  );
8882
8894
  if (!lastUserEvent) return;
8883
8895
  const query = (_nullishCoalesce(lastUserEvent.content.parts, () => ( []))).map((p) => p.text || "").join(" ");
@@ -8888,7 +8900,7 @@ var SharedMemoryRequestProcessor = class extends BaseLlmRequestProcessor {
8888
8900
  });
8889
8901
  const sessionTexts = new Set(
8890
8902
  (llmRequest.contents || []).flatMap(
8891
- (c) => _optionalChain([c, 'access', _241 => _241.parts, 'optionalAccess', _242 => _242.map, 'call', _243 => _243((p) => p.text)]) || []
8903
+ (c) => _optionalChain([c, 'access', _239 => _239.parts, 'optionalAccess', _240 => _240.map, 'call', _241 => _241((p) => p.text)]) || []
8892
8904
  )
8893
8905
  );
8894
8906
  for (const memory of results.memories) {
@@ -9309,7 +9321,7 @@ var LlmAgent = (_class27 = class _LlmAgent extends BaseAgent {
9309
9321
  * This matches the Python implementation's _llm_flow property
9310
9322
  */
9311
9323
  get llmFlow() {
9312
- if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access', _244 => _244.subAgents, 'optionalAccess', _245 => _245.length])) {
9324
+ if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access', _242 => _242.subAgents, 'optionalAccess', _243 => _243.length])) {
9313
9325
  return new SingleFlow();
9314
9326
  }
9315
9327
  return new AutoFlow();
@@ -9325,7 +9337,7 @@ var LlmAgent = (_class27 = class _LlmAgent extends BaseAgent {
9325
9337
  );
9326
9338
  return;
9327
9339
  }
9328
- if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access', _246 => _246.content, 'optionalAccess', _247 => _247.parts])) {
9340
+ if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access', _244 => _244.content, 'optionalAccess', _245 => _245.parts])) {
9329
9341
  let result = event.content.parts.map((part) => part.text || "").join("");
9330
9342
  if (this.outputSchema) {
9331
9343
  if (!result.trim()) {
@@ -9545,7 +9557,7 @@ var LoopAgent = class extends BaseAgent {
9545
9557
  for (const subAgent of this.subAgents) {
9546
9558
  for await (const event of subAgent.runAsync(ctx)) {
9547
9559
  yield event;
9548
- if (_optionalChain([event, 'access', _248 => _248.actions, 'optionalAccess', _249 => _249.escalate])) {
9560
+ if (_optionalChain([event, 'access', _246 => _246.actions, 'optionalAccess', _247 => _247.escalate])) {
9549
9561
  return;
9550
9562
  }
9551
9563
  }
@@ -9857,17 +9869,17 @@ var RunConfig = class {
9857
9869
  */
9858
9870
 
9859
9871
  constructor(config) {
9860
- this.speechConfig = _optionalChain([config, 'optionalAccess', _250 => _250.speechConfig]);
9861
- this.responseModalities = _optionalChain([config, 'optionalAccess', _251 => _251.responseModalities]);
9862
- this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess', _252 => _252.saveInputBlobsAsArtifacts]) || false;
9863
- this.supportCFC = _optionalChain([config, 'optionalAccess', _253 => _253.supportCFC]) || false;
9864
- this.streamingMode = _optionalChain([config, 'optionalAccess', _254 => _254.streamingMode]) || "NONE" /* NONE */;
9865
- this.outputAudioTranscription = _optionalChain([config, 'optionalAccess', _255 => _255.outputAudioTranscription]);
9866
- this.inputAudioTranscription = _optionalChain([config, 'optionalAccess', _256 => _256.inputAudioTranscription]);
9867
- this.realtimeInputConfig = _optionalChain([config, 'optionalAccess', _257 => _257.realtimeInputConfig]);
9868
- this.enableAffectiveDialog = _optionalChain([config, 'optionalAccess', _258 => _258.enableAffectiveDialog]);
9869
- this.proactivity = _optionalChain([config, 'optionalAccess', _259 => _259.proactivity]);
9870
- this.maxLlmCalls = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _260 => _260.maxLlmCalls]), () => ( 500));
9872
+ this.speechConfig = _optionalChain([config, 'optionalAccess', _248 => _248.speechConfig]);
9873
+ this.responseModalities = _optionalChain([config, 'optionalAccess', _249 => _249.responseModalities]);
9874
+ this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess', _250 => _250.saveInputBlobsAsArtifacts]) || false;
9875
+ this.supportCFC = _optionalChain([config, 'optionalAccess', _251 => _251.supportCFC]) || false;
9876
+ this.streamingMode = _optionalChain([config, 'optionalAccess', _252 => _252.streamingMode]) || "NONE" /* NONE */;
9877
+ this.outputAudioTranscription = _optionalChain([config, 'optionalAccess', _253 => _253.outputAudioTranscription]);
9878
+ this.inputAudioTranscription = _optionalChain([config, 'optionalAccess', _254 => _254.inputAudioTranscription]);
9879
+ this.realtimeInputConfig = _optionalChain([config, 'optionalAccess', _255 => _255.realtimeInputConfig]);
9880
+ this.enableAffectiveDialog = _optionalChain([config, 'optionalAccess', _256 => _256.enableAffectiveDialog]);
9881
+ this.proactivity = _optionalChain([config, 'optionalAccess', _257 => _257.proactivity]);
9882
+ this.maxLlmCalls = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _258 => _258.maxLlmCalls]), () => ( 500));
9871
9883
  this.validateMaxLlmCalls();
9872
9884
  }
9873
9885
  /**
@@ -10011,7 +10023,7 @@ var InMemoryMemoryService = (_class30 = class {
10011
10023
  }
10012
10024
  const userSessions = this._sessionEvents.get(userKey);
10013
10025
  const filteredEvents = session.events.filter(
10014
- (event) => _optionalChain([event, 'access', _261 => _261.content, 'optionalAccess', _262 => _262.parts])
10026
+ (event) => _optionalChain([event, 'access', _259 => _259.content, 'optionalAccess', _260 => _260.parts])
10015
10027
  );
10016
10028
  userSessions.set(session.id, filteredEvents);
10017
10029
  }
@@ -10150,7 +10162,7 @@ var InMemorySessionService = (_class31 = class extends BaseSessionService {const
10150
10162
  return this.createSessionImpl(appName, userId, state, sessionId);
10151
10163
  }
10152
10164
  createSessionImpl(appName, userId, state, sessionId) {
10153
- const finalSessionId = _optionalChain([sessionId, 'optionalAccess', _263 => _263.trim, 'call', _264 => _264()]) || _crypto.randomUUID.call(void 0, );
10165
+ const finalSessionId = _optionalChain([sessionId, 'optionalAccess', _261 => _261.trim, 'call', _262 => _262()]) || _crypto.randomUUID.call(void 0, );
10154
10166
  const session = {
10155
10167
  appName,
10156
10168
  userId,
@@ -10307,7 +10319,7 @@ var InMemorySessionService = (_class31 = class extends BaseSessionService {const
10307
10319
  warning(`sessionId ${sessionId} not in sessions[appName][userId]`);
10308
10320
  return event;
10309
10321
  }
10310
- if (_optionalChain([event, 'access', _265 => _265.actions, 'optionalAccess', _266 => _266.stateDelta])) {
10322
+ if (_optionalChain([event, 'access', _263 => _263.actions, 'optionalAccess', _264 => _264.stateDelta])) {
10311
10323
  for (const key in event.actions.stateDelta) {
10312
10324
  const value = event.actions.stateDelta[key];
10313
10325
  if (key.startsWith(State.APP_PREFIX)) {
@@ -10341,14 +10353,14 @@ function _findFunctionCallEventIfLastEventIsFunctionResponse(session) {
10341
10353
  return null;
10342
10354
  }
10343
10355
  const lastEvent = events[events.length - 1];
10344
- if (_optionalChain([lastEvent, 'access', _267 => _267.content, 'optionalAccess', _268 => _268.parts, 'optionalAccess', _269 => _269.some, 'call', _270 => _270((part) => part.functionResponse)])) {
10345
- const functionCallId = _optionalChain([lastEvent, 'access', _271 => _271.content, 'access', _272 => _272.parts, 'access', _273 => _273.find, 'call', _274 => _274(
10356
+ if (_optionalChain([lastEvent, 'access', _265 => _265.content, 'optionalAccess', _266 => _266.parts, 'optionalAccess', _267 => _267.some, 'call', _268 => _268((part) => part.functionResponse)])) {
10357
+ const functionCallId = _optionalChain([lastEvent, 'access', _269 => _269.content, 'access', _270 => _270.parts, 'access', _271 => _271.find, 'call', _272 => _272(
10346
10358
  (part) => part.functionResponse
10347
- ), 'optionalAccess', _275 => _275.functionResponse, 'optionalAccess', _276 => _276.id]);
10359
+ ), 'optionalAccess', _273 => _273.functionResponse, 'optionalAccess', _274 => _274.id]);
10348
10360
  if (!functionCallId) return null;
10349
10361
  for (let i = events.length - 2; i >= 0; i--) {
10350
10362
  const event = events[i];
10351
- const functionCalls = _optionalChain([event, 'access', _277 => _277.getFunctionCalls, 'optionalCall', _278 => _278()]) || [];
10363
+ const functionCalls = _optionalChain([event, 'access', _275 => _275.getFunctionCalls, 'optionalCall', _276 => _276()]) || [];
10352
10364
  for (const functionCall of functionCalls) {
10353
10365
  if (functionCall.id === functionCallId) {
10354
10366
  return event;
@@ -10551,15 +10563,15 @@ var Runner = (_class32 = class {
10551
10563
  */
10552
10564
  _findAgentToRun(session, rootAgent) {
10553
10565
  const event = _findFunctionCallEventIfLastEventIsFunctionResponse(session);
10554
- if (_optionalChain([event, 'optionalAccess', _279 => _279.author])) {
10566
+ if (_optionalChain([event, 'optionalAccess', _277 => _277.author])) {
10555
10567
  return rootAgent.findAgent(event.author);
10556
10568
  }
10557
- const nonUserEvents = _optionalChain([session, 'access', _280 => _280.events, 'optionalAccess', _281 => _281.filter, 'call', _282 => _282((e) => e.author !== "user"), 'access', _283 => _283.reverse, 'call', _284 => _284()]) || [];
10569
+ 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
10570
  for (const event2 of nonUserEvents) {
10559
10571
  if (event2.author === rootAgent.name) {
10560
10572
  return rootAgent;
10561
10573
  }
10562
- const agent = _optionalChain([rootAgent, 'access', _285 => _285.findSubAgent, 'optionalCall', _286 => _286(event2.author)]);
10574
+ const agent = _optionalChain([rootAgent, 'access', _283 => _283.findSubAgent, 'optionalCall', _284 => _284(event2.author)]);
10563
10575
  if (!agent) {
10564
10576
  this.logger.debug(
10565
10577
  `Event from an unknown agent: ${event2.author}, event id: ${event2.id}`
@@ -11165,7 +11177,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
11165
11177
  const outputSchema = this.config.outputSchema;
11166
11178
  const agentType = this.agentType;
11167
11179
  const isMulti = agentType === "parallel" || agentType === "sequential";
11168
- const subAgentNames = _optionalChain([this, 'access', _287 => _287.config, 'access', _288 => _288.subAgents, 'optionalAccess', _289 => _289.map, 'call', _290 => _290((a) => a.name)]) || [];
11180
+ const subAgentNames = _optionalChain([this, 'access', _285 => _285.config, 'access', _286 => _286.subAgents, 'optionalAccess', _287 => _287.map, 'call', _288 => _288((a) => a.name)]) || [];
11169
11181
  return {
11170
11182
  __outputSchema: outputSchema,
11171
11183
  async ask(message) {
@@ -11173,7 +11185,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
11173
11185
  let combinedResponse = "";
11174
11186
  const perAgentBuffers = {};
11175
11187
  const authors = /* @__PURE__ */ new Set();
11176
- if (!_optionalChain([sessionOptions, 'optionalAccess', _291 => _291.userId])) {
11188
+ if (!_optionalChain([sessionOptions, 'optionalAccess', _289 => _289.userId])) {
11177
11189
  throw new Error("Session configuration is required");
11178
11190
  }
11179
11191
  for await (const event of baseRunner.runAsync({
@@ -11181,7 +11193,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
11181
11193
  sessionId: session.id,
11182
11194
  newMessage
11183
11195
  })) {
11184
- if (_optionalChain([event, 'access', _292 => _292.content, 'optionalAccess', _293 => _293.parts]) && Array.isArray(event.content.parts)) {
11196
+ if (_optionalChain([event, 'access', _290 => _290.content, 'optionalAccess', _291 => _291.parts]) && Array.isArray(event.content.parts)) {
11185
11197
  const content = event.content.parts.map(
11186
11198
  (part) => (part && typeof part === "object" && "text" in part ? part.text : "") || ""
11187
11199
  ).join("");
@@ -11209,12 +11221,14 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
11209
11221
  try {
11210
11222
  return outputSchema.parse(combinedResponse);
11211
11223
  } catch (validationError) {
11212
- throw new Error(
11213
- `Failed to parse and validate LLM output against the schema.
11214
- JSON parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}
11215
- Zod validation error: ${validationError instanceof Error ? validationError.message : String(validationError)}
11216
- Raw output: "${combinedResponse}"`
11217
- );
11224
+ const message2 = `\u{1F6A8} Failed to parse and validate LLM output against the schema.
11225
+
11226
+ \u2139\uFE0F JSON parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}
11227
+
11228
+ \u{1F6A7} Zod validation error: ${validationError instanceof Error ? validationError.message : String(validationError)}
11229
+
11230
+ \u{1F4C4} Raw output: ${combinedResponse}`;
11231
+ throw new Error(message2);
11218
11232
  }
11219
11233
  }
11220
11234
  }
@@ -11289,7 +11303,7 @@ var VertexAiSessionService = class extends BaseSessionService {
11289
11303
  path: `operations/${operationId}`,
11290
11304
  request_dict: {}
11291
11305
  });
11292
- if (_optionalChain([lroResponse, 'optionalAccess', _294 => _294.done])) {
11306
+ if (_optionalChain([lroResponse, 'optionalAccess', _292 => _292.done])) {
11293
11307
  break;
11294
11308
  }
11295
11309
  await new Promise((resolve) => setTimeout(resolve, 1e3));
@@ -11660,12 +11674,12 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
11660
11674
  }
11661
11675
  async createSession(appName, userId, state, sessionId) {
11662
11676
  await this.ensureInitialized();
11663
- const id = _optionalChain([sessionId, 'optionalAccess', _295 => _295.trim, 'call', _296 => _296()]) || this.generateSessionId();
11677
+ const id = _optionalChain([sessionId, 'optionalAccess', _293 => _293.trim, 'call', _294 => _294()]) || this.generateSessionId();
11664
11678
  return await this.db.transaction().execute(async (trx) => {
11665
11679
  const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
11666
11680
  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', _297 => _297.state]), {});
11668
- let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _298 => _298.state]), {});
11681
+ let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _295 => _295.state]), {});
11682
+ let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _296 => _296.state]), {});
11669
11683
  if (!appState) {
11670
11684
  await trx.insertInto("app_states").values({
11671
11685
  app_name: appName,
@@ -11724,21 +11738,21 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
11724
11738
  return void 0;
11725
11739
  }
11726
11740
  let eventQuery = trx.selectFrom("events").selectAll().where("session_id", "=", sessionId).orderBy("timestamp", "desc");
11727
- if (_optionalChain([config, 'optionalAccess', _299 => _299.afterTimestamp])) {
11741
+ if (_optionalChain([config, 'optionalAccess', _297 => _297.afterTimestamp])) {
11728
11742
  eventQuery = eventQuery.where(
11729
11743
  "timestamp",
11730
11744
  ">=",
11731
11745
  new Date(config.afterTimestamp * 1e3)
11732
11746
  );
11733
11747
  }
11734
- if (_optionalChain([config, 'optionalAccess', _300 => _300.numRecentEvents])) {
11748
+ if (_optionalChain([config, 'optionalAccess', _298 => _298.numRecentEvents])) {
11735
11749
  eventQuery = eventQuery.limit(config.numRecentEvents);
11736
11750
  }
11737
11751
  const storageEvents = await eventQuery.execute();
11738
11752
  const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
11739
11753
  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', _301 => _301.state]), {});
11741
- const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _302 => _302.state]), {});
11754
+ const currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _299 => _299.state]), {});
11755
+ const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _300 => _300.state]), {});
11742
11756
  const sessionState = this.parseJsonSafely(storageSession.state, {});
11743
11757
  const mergedState = this.mergeState(
11744
11758
  currentAppState,
@@ -11796,13 +11810,13 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
11796
11810
  }
11797
11811
  const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", session.appName).executeTakeFirst();
11798
11812
  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', _303 => _303.state]), {});
11800
- let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _304 => _304.state]), {});
11813
+ let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _301 => _301.state]), {});
11814
+ let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _302 => _302.state]), {});
11801
11815
  let sessionState = this.parseJsonSafely(storageSession.state, {});
11802
11816
  let appStateDelta = {};
11803
11817
  let userStateDelta = {};
11804
11818
  let sessionStateDelta = {};
11805
- if (_optionalChain([event, 'access', _305 => _305.actions, 'optionalAccess', _306 => _306.stateDelta])) {
11819
+ if (_optionalChain([event, 'access', _303 => _303.actions, 'optionalAccess', _304 => _304.stateDelta])) {
11806
11820
  const deltas = this.extractStateDelta(event.actions.stateDelta);
11807
11821
  appStateDelta = deltas.appStateDelta;
11808
11822
  userStateDelta = deltas.userStateDelta;
@@ -11948,7 +11962,7 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
11948
11962
  * Overrides the base class method to work with plain object state.
11949
11963
  */
11950
11964
  updateSessionState(session, event) {
11951
- if (!_optionalChain([event, 'access', _307 => _307.actions, 'optionalAccess', _308 => _308.stateDelta])) {
11965
+ if (!_optionalChain([event, 'access', _305 => _305.actions, 'optionalAccess', _306 => _306.stateDelta])) {
11952
11966
  return;
11953
11967
  }
11954
11968
  for (const [key, value] of Object.entries(event.actions.stateDelta)) {
@@ -12118,7 +12132,7 @@ var GcsArtifactService = class {
12118
12132
  };
12119
12133
  return part;
12120
12134
  } catch (error) {
12121
- if (_optionalChain([error, 'optionalAccess', _309 => _309.code]) === 404) {
12135
+ if (_optionalChain([error, 'optionalAccess', _307 => _307.code]) === 404) {
12122
12136
  return null;
12123
12137
  }
12124
12138
  throw error;
@@ -12369,13 +12383,13 @@ var VertexAiEvalFacade = class _VertexAiEvalFacade {
12369
12383
  };
12370
12384
  }
12371
12385
  _getText(content) {
12372
- if (_optionalChain([content, 'optionalAccess', _310 => _310.parts])) {
12386
+ if (_optionalChain([content, 'optionalAccess', _308 => _308.parts])) {
12373
12387
  return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join("\n");
12374
12388
  }
12375
12389
  return "";
12376
12390
  }
12377
12391
  _getScore(evalResult) {
12378
- if (_optionalChain([evalResult, 'optionalAccess', _311 => _311.summaryMetrics, 'optionalAccess', _312 => _312[0], 'optionalAccess', _313 => _313.meanScore]) !== void 0 && typeof evalResult.summaryMetrics[0].meanScore === "number" && !Number.isNaN(evalResult.summaryMetrics[0].meanScore)) {
12392
+ 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
12393
  return evalResult.summaryMetrics[0].meanScore;
12380
12394
  }
12381
12395
  return void 0;
@@ -12525,7 +12539,7 @@ var ResponseEvaluator = class extends Evaluator {
12525
12539
  return fmeasure;
12526
12540
  }
12527
12541
  extractText(content) {
12528
- if (_optionalChain([content, 'optionalAccess', _314 => _314.parts])) {
12542
+ if (_optionalChain([content, 'optionalAccess', _312 => _312.parts])) {
12529
12543
  return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join(" ");
12530
12544
  }
12531
12545
  return "";
@@ -12558,7 +12572,7 @@ var TrajectoryEvaluator = class extends Evaluator {
12558
12572
  for (let i = 0; i < actualInvocations.length; i++) {
12559
12573
  const actual = actualInvocations[i];
12560
12574
  const expected = expectedInvocations[i];
12561
- if (!_optionalChain([actual, 'access', _315 => _315.intermediateData, 'optionalAccess', _316 => _316.toolUses]) || !_optionalChain([expected, 'access', _317 => _317.intermediateData, 'optionalAccess', _318 => _318.toolUses])) {
12575
+ if (!_optionalChain([actual, 'access', _313 => _313.intermediateData, 'optionalAccess', _314 => _314.toolUses]) || !_optionalChain([expected, 'access', _315 => _315.intermediateData, 'optionalAccess', _316 => _316.toolUses])) {
12562
12576
  perInvocationResults.push({
12563
12577
  actualInvocation: actual,
12564
12578
  expectedInvocation: expected,
@@ -12646,7 +12660,7 @@ var SafetyEvaluatorV1 = class extends Evaluator {
12646
12660
 
12647
12661
  // src/evaluation/llm-as-judge-utils.ts
12648
12662
  function getTextFromContent(content) {
12649
- if (_optionalChain([content, 'optionalAccess', _319 => _319.parts])) {
12663
+ if (_optionalChain([content, 'optionalAccess', _317 => _317.parts])) {
12650
12664
  return content.parts.map((part) => part.text).filter(Boolean).join("\n");
12651
12665
  }
12652
12666
  return "";
@@ -12658,9 +12672,9 @@ function getEvalStatus(score, threshold) {
12658
12672
  // src/evaluation/llm-as-judge.ts
12659
12673
  var LlmAsJudge = class {
12660
12674
  async sampleJudge(prompt, numSamples, critiqueParser, judgeModelOptions) {
12661
- const modelName = _optionalChain([judgeModelOptions, 'optionalAccess', _320 => _320.judgeModel]) || "gemini-2.5-flash";
12675
+ const modelName = _optionalChain([judgeModelOptions, 'optionalAccess', _318 => _318.judgeModel]) || "gemini-2.5-flash";
12662
12676
  const model = LLMRegistry.getModelOrCreate(modelName);
12663
- const config = _optionalChain([judgeModelOptions, 'optionalAccess', _321 => _321.judgeModelConfig]) || {};
12677
+ const config = _optionalChain([judgeModelOptions, 'optionalAccess', _319 => _319.judgeModelConfig]) || {};
12664
12678
  const samples = [];
12665
12679
  for (let i = 0; i < numSamples; i++) {
12666
12680
  try {
@@ -12726,7 +12740,7 @@ function parseCritique(response) {
12726
12740
  const labelMatchIsResponseValid = response.match(
12727
12741
  /"is_the_agent_response_valid":\s*\[*[\n\s]*"*([^"^\]^\s]*)"*[\n\s]*\]*\s*[,\n\}]/
12728
12742
  );
12729
- if (_optionalChain([labelMatchIsResponseValid, 'optionalAccess', _322 => _322[1]])) {
12743
+ if (_optionalChain([labelMatchIsResponseValid, 'optionalAccess', _320 => _320[1]])) {
12730
12744
  const label = labelMatchIsResponseValid[1].toLowerCase();
12731
12745
  return label === "valid" ? "valid" /* VALID */ : "invalid" /* INVALID */;
12732
12746
  }
@@ -12771,7 +12785,7 @@ var FinalResponseMatchV2Evaluator = class extends Evaluator {
12771
12785
  "{prompt}",
12772
12786
  prompt
12773
12787
  ).replace("{response}", response).replace("{golden_response}", goldenResponse);
12774
- const numSamples = _nullishCoalesce(_optionalChain([this, 'access', _323 => _323.metric, 'access', _324 => _324.judgeModelOptions, 'optionalAccess', _325 => _325.numSamples]), () => ( DEFAULT_NUM_SAMPLES));
12788
+ const numSamples = _nullishCoalesce(_optionalChain([this, 'access', _321 => _321.metric, 'access', _322 => _322.judgeModelOptions, 'optionalAccess', _323 => _323.numSamples]), () => ( DEFAULT_NUM_SAMPLES));
12775
12789
  const labels = await this.llmAsJudge.sampleJudge(
12776
12790
  formattedPrompt,
12777
12791
  numSamples,
@@ -12811,7 +12825,7 @@ var MetricEvaluatorRegistry = (_class35 = class {constructor() { _class35.protot
12811
12825
  const metricName = metricInfo.metricName;
12812
12826
  if (this.registry.has(metricName)) {
12813
12827
  console.info(
12814
- `Updating Evaluator class for ${metricName} from ${_optionalChain([this, 'access', _326 => _326.registry, 'access', _327 => _327.get, 'call', _328 => _328(metricName), 'optionalAccess', _329 => _329.evaluator, 'access', _330 => _330.name])} to ${evaluator.name}`
12828
+ `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
12829
  );
12816
12830
  }
12817
12831
  this.registry.set(metricName, {
@@ -12925,10 +12939,10 @@ var LocalEvalService = class extends BaseEvalService {
12925
12939
  for (const evalMetric of evaluateConfig.evalMetrics) {
12926
12940
  const evaluator = DEFAULT_METRIC_EVALUATOR_REGISTRY.getEvaluator(evalMetric);
12927
12941
  const actual = results.filter(
12928
- (r) => !_optionalChain([r, 'access', _331 => _331.invocationId, 'optionalAccess', _332 => _332.includes, 'call', _333 => _333("expected")])
12942
+ (r) => !_optionalChain([r, 'access', _329 => _329.invocationId, 'optionalAccess', _330 => _330.includes, 'call', _331 => _331("expected")])
12929
12943
  );
12930
12944
  const expected = results.filter(
12931
- (r) => _optionalChain([r, 'access', _334 => _334.invocationId, 'optionalAccess', _335 => _335.includes, 'call', _336 => _336("expected")])
12945
+ (r) => _optionalChain([r, 'access', _332 => _332.invocationId, 'optionalAccess', _333 => _333.includes, 'call', _334 => _334("expected")])
12932
12946
  );
12933
12947
  const result = await evaluator.evaluateInvocations(actual, expected);
12934
12948
  evalResult.evalCaseResults.push({
@@ -13320,13 +13334,13 @@ ${failures.join(
13320
13334
  console.log("\n\n");
13321
13335
  }
13322
13336
  static _convertContentToText(content) {
13323
- if (_optionalChain([content, 'optionalAccess', _337 => _337.parts])) {
13337
+ if (_optionalChain([content, 'optionalAccess', _335 => _335.parts])) {
13324
13338
  return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join("\n");
13325
13339
  }
13326
13340
  return "";
13327
13341
  }
13328
13342
  static _convertToolCallsToText(intermediateData) {
13329
- if (_optionalChain([intermediateData, 'optionalAccess', _338 => _338.toolUses])) {
13343
+ if (_optionalChain([intermediateData, 'optionalAccess', _336 => _336.toolUses])) {
13330
13344
  return intermediateData.toolUses.map((t) => JSON.stringify(t)).join("\n");
13331
13345
  }
13332
13346
  return "";
@@ -13381,7 +13395,7 @@ ${failures.join(
13381
13395
  for (const [metricName, evalMetricResultsWithInvocations] of Object.entries(
13382
13396
  evalMetricResults
13383
13397
  )) {
13384
- const threshold = _optionalChain([evalMetricResultsWithInvocations, 'access', _339 => _339[0], 'optionalAccess', _340 => _340.evalMetricResult, 'access', _341 => _341.threshold]) || 0;
13398
+ const threshold = _optionalChain([evalMetricResultsWithInvocations, 'access', _337 => _337[0], 'optionalAccess', _338 => _338.evalMetricResult, 'access', _339 => _339.threshold]) || 0;
13385
13399
  const scores = evalMetricResultsWithInvocations.map((m) => m.evalMetricResult.score).filter((s) => s !== void 0);
13386
13400
  let overallScore;
13387
13401
  let overallEvalStatus;
@@ -13470,7 +13484,7 @@ var RougeEvaluator = class extends Evaluator {
13470
13484
  }
13471
13485
  };
13472
13486
  function getTextFromContent2(content) {
13473
- if (_optionalChain([content, 'optionalAccess', _342 => _342.parts])) {
13487
+ if (_optionalChain([content, 'optionalAccess', _340 => _340.parts])) {
13474
13488
  return content.parts.map((part) => part.text).filter(Boolean).join("\n");
13475
13489
  }
13476
13490
  return "";