@iqai/adk 0.5.2 → 0.5.4

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
@@ -3394,6 +3394,10 @@ var EventActions = (_class10 = class {
3394
3394
  * a compaction of events within the specified timestamp range.
3395
3395
  */
3396
3396
 
3397
+ /**
3398
+ * The invocation id to rewind to. This is only set for rewind event.
3399
+ */
3400
+
3397
3401
  /**
3398
3402
  * Constructor for EventActions
3399
3403
  */
@@ -3405,6 +3409,7 @@ var EventActions = (_class10 = class {
3405
3409
  this.escalate = options.escalate;
3406
3410
  this.requestedAuthConfigs = options.requestedAuthConfigs;
3407
3411
  this.compaction = options.compaction;
3412
+ this.rewindBeforeInvocationId = options.rewindBeforeInvocationId;
3408
3413
  }
3409
3414
  }, _class10);
3410
3415
 
@@ -4302,6 +4307,7 @@ __export(tools_exports, {
4302
4307
  McpNearAgent: () => McpNearAgent,
4303
4308
  McpNearIntents: () => McpNearIntents,
4304
4309
  McpOdos: () => McpOdos,
4310
+ McpPolymarket: () => McpPolymarket,
4305
4311
  McpSamplingHandler: () => McpSamplingHandler,
4306
4312
  McpTelegram: () => McpTelegram,
4307
4313
  McpToolset: () => McpToolset,
@@ -6470,6 +6476,14 @@ function McpUpbit(config = {}) {
6470
6476
  );
6471
6477
  return new McpToolset(mcpConfig);
6472
6478
  }
6479
+ function McpPolymarket(config = {}) {
6480
+ const mcpConfig = createMcpConfig(
6481
+ "Polymarket MCP Client",
6482
+ "@iqai/mcp-polymarket",
6483
+ config
6484
+ );
6485
+ return new McpToolset(mcpConfig);
6486
+ }
6473
6487
  function McpFilesystem(config = {}) {
6474
6488
  const mcpConfig = createMcpConfig(
6475
6489
  "Filesystem MCP Client",
@@ -8468,8 +8482,30 @@ function rearrangeEventsForLatestFunctionResponse(events) {
8468
8482
  return resultEvents;
8469
8483
  }
8470
8484
  function getContents(currentBranch, events, agentName = "") {
8485
+ const invocationIdToIndex = /* @__PURE__ */ new Map();
8486
+ for (let idx = 0; idx < events.length; idx++) {
8487
+ if (events[idx].invocationId) {
8488
+ invocationIdToIndex.set(events[idx].invocationId, idx);
8489
+ }
8490
+ }
8491
+ const rewindFilteredEvents = [];
8492
+ let i = events.length - 1;
8493
+ while (i >= 0) {
8494
+ const event = events[i];
8495
+ if (_optionalChain([event, 'access', _245 => _245.actions, 'optionalAccess', _246 => _246.rewindBeforeInvocationId])) {
8496
+ const rewindInvocationId = event.actions.rewindBeforeInvocationId;
8497
+ const rewindIndex = invocationIdToIndex.get(rewindInvocationId);
8498
+ if (rewindIndex !== void 0 && rewindIndex < i) {
8499
+ i = rewindIndex;
8500
+ }
8501
+ } else {
8502
+ rewindFilteredEvents.push(event);
8503
+ }
8504
+ i--;
8505
+ }
8506
+ rewindFilteredEvents.reverse();
8471
8507
  const filteredEvents = [];
8472
- for (const event of events) {
8508
+ for (const event of rewindFilteredEvents) {
8473
8509
  if (!event.content || !event.content.role || !event.content.parts || event.content.parts.length === 0) {
8474
8510
  continue;
8475
8511
  }
@@ -8558,7 +8594,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
8558
8594
  const partIndicesInMergedEvent = {};
8559
8595
  for (let idx = 0; idx < partsInMergedEvent.length; idx++) {
8560
8596
  const part = partsInMergedEvent[idx];
8561
- if (_optionalChain([part, 'access', _245 => _245.functionResponse, 'optionalAccess', _246 => _246.id])) {
8597
+ if (_optionalChain([part, 'access', _247 => _247.functionResponse, 'optionalAccess', _248 => _248.id])) {
8562
8598
  partIndicesInMergedEvent[part.functionResponse.id] = idx;
8563
8599
  }
8564
8600
  }
@@ -8567,7 +8603,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
8567
8603
  throw new Error("There should be at least one function_response part.");
8568
8604
  }
8569
8605
  for (const part of event.content.parts) {
8570
- if (_optionalChain([part, 'access', _247 => _247.functionResponse, 'optionalAccess', _248 => _248.id])) {
8606
+ if (_optionalChain([part, 'access', _249 => _249.functionResponse, 'optionalAccess', _250 => _250.id])) {
8571
8607
  const functionCallId = part.functionResponse.id;
8572
8608
  if (functionCallId in partIndicesInMergedEvent) {
8573
8609
  partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] = part;
@@ -8607,7 +8643,7 @@ function processCompactionEvents(events) {
8607
8643
  let lastCompactionStartTime = Number.POSITIVE_INFINITY;
8608
8644
  for (let i = events.length - 1; i >= 0; i--) {
8609
8645
  const event = events[i];
8610
- if (_optionalChain([event, 'access', _249 => _249.actions, 'optionalAccess', _250 => _250.compaction])) {
8646
+ if (_optionalChain([event, 'access', _251 => _251.actions, 'optionalAccess', _252 => _252.compaction])) {
8611
8647
  const compaction = event.actions.compaction;
8612
8648
  const synthesizedEvent = new Event({
8613
8649
  timestamp: compaction.endTimestamp,
@@ -8859,7 +8895,7 @@ var PlanReActPlanner = class extends BasePlanner {
8859
8895
  let firstFcPartIndex = -1;
8860
8896
  for (let i = 0; i < responseParts.length; i++) {
8861
8897
  if (responseParts[i].functionCall) {
8862
- if (!_optionalChain([responseParts, 'access', _251 => _251[i], 'access', _252 => _252.functionCall, 'optionalAccess', _253 => _253.name])) {
8898
+ if (!_optionalChain([responseParts, 'access', _253 => _253[i], 'access', _254 => _254.functionCall, 'optionalAccess', _255 => _255.name])) {
8863
8899
  continue;
8864
8900
  }
8865
8901
  preservedParts.push(responseParts[i]);
@@ -8898,7 +8934,7 @@ var PlanReActPlanner = class extends BasePlanner {
8898
8934
  * Handles non-function-call parts of the response
8899
8935
  */
8900
8936
  _handleNonFunctionCallParts(responsePart, preservedParts) {
8901
- if (_optionalChain([responsePart, 'access', _254 => _254.text, 'optionalAccess', _255 => _255.includes, 'call', _256 => _256(FINAL_ANSWER_TAG)])) {
8937
+ if (_optionalChain([responsePart, 'access', _256 => _256.text, 'optionalAccess', _257 => _257.includes, 'call', _258 => _258(FINAL_ANSWER_TAG)])) {
8902
8938
  const [reasoningText, finalAnswerText] = this._splitByLastPattern(
8903
8939
  responsePart.text,
8904
8940
  FINAL_ANSWER_TAG
@@ -9137,7 +9173,7 @@ var OutputSchemaResponseProcessor = (_class26 = class extends BaseLlmResponsePro
9137
9173
  stripCodeFences(raw) {
9138
9174
  const fencePattern = /```(?:json)?\s*([\s\S]*?)```/i;
9139
9175
  const fenceMatch = raw.match(fencePattern);
9140
- if (_optionalChain([fenceMatch, 'optionalAccess', _257 => _257[1]])) {
9176
+ if (_optionalChain([fenceMatch, 'optionalAccess', _259 => _259[1]])) {
9141
9177
  return fenceMatch[1].trim();
9142
9178
  }
9143
9179
  const lines = raw.split(/\r?\n/).map((l) => l.trim());
@@ -9174,7 +9210,7 @@ var SharedMemoryRequestProcessor = class extends BaseLlmRequestProcessor {
9174
9210
  const memoryService = invocationContext.memoryService;
9175
9211
  if (!memoryService) return;
9176
9212
  const lastUserEvent = invocationContext.session.events.findLast(
9177
- (e) => e.author === "user" && _optionalChain([e, 'access', _258 => _258.content, 'optionalAccess', _259 => _259.parts, 'optionalAccess', _260 => _260.length])
9213
+ (e) => e.author === "user" && _optionalChain([e, 'access', _260 => _260.content, 'optionalAccess', _261 => _261.parts, 'optionalAccess', _262 => _262.length])
9178
9214
  );
9179
9215
  if (!lastUserEvent) return;
9180
9216
  const query = (_nullishCoalesce(lastUserEvent.content.parts, () => ( []))).map((p) => p.text || "").join(" ");
@@ -9185,7 +9221,7 @@ var SharedMemoryRequestProcessor = class extends BaseLlmRequestProcessor {
9185
9221
  });
9186
9222
  const sessionTexts = new Set(
9187
9223
  (llmRequest.contents || []).flatMap(
9188
- (c) => _optionalChain([c, 'access', _261 => _261.parts, 'optionalAccess', _262 => _262.map, 'call', _263 => _263((p) => p.text)]) || []
9224
+ (c) => _optionalChain([c, 'access', _263 => _263.parts, 'optionalAccess', _264 => _264.map, 'call', _265 => _265((p) => p.text)]) || []
9189
9225
  )
9190
9226
  );
9191
9227
  for (const memory of results.memories) {
@@ -9606,7 +9642,7 @@ var LlmAgent = (_class27 = class _LlmAgent extends BaseAgent {
9606
9642
  * This matches the Python implementation's _llm_flow property
9607
9643
  */
9608
9644
  get llmFlow() {
9609
- if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access', _264 => _264.subAgents, 'optionalAccess', _265 => _265.length])) {
9645
+ if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access', _266 => _266.subAgents, 'optionalAccess', _267 => _267.length])) {
9610
9646
  return new SingleFlow();
9611
9647
  }
9612
9648
  return new AutoFlow();
@@ -9622,7 +9658,7 @@ var LlmAgent = (_class27 = class _LlmAgent extends BaseAgent {
9622
9658
  );
9623
9659
  return;
9624
9660
  }
9625
- if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access', _266 => _266.content, 'optionalAccess', _267 => _267.parts])) {
9661
+ if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access', _268 => _268.content, 'optionalAccess', _269 => _269.parts])) {
9626
9662
  let result = event.content.parts.map((part) => part.text || "").join("");
9627
9663
  if (this.outputSchema) {
9628
9664
  if (!result.trim()) {
@@ -9842,7 +9878,7 @@ var LoopAgent = class extends BaseAgent {
9842
9878
  for (const subAgent of this.subAgents) {
9843
9879
  for await (const event of subAgent.runAsync(ctx)) {
9844
9880
  yield event;
9845
- if (_optionalChain([event, 'access', _268 => _268.actions, 'optionalAccess', _269 => _269.escalate])) {
9881
+ if (_optionalChain([event, 'access', _270 => _270.actions, 'optionalAccess', _271 => _271.escalate])) {
9846
9882
  return;
9847
9883
  }
9848
9884
  }
@@ -10154,17 +10190,17 @@ var RunConfig = class {
10154
10190
  */
10155
10191
 
10156
10192
  constructor(config) {
10157
- this.speechConfig = _optionalChain([config, 'optionalAccess', _270 => _270.speechConfig]);
10158
- this.responseModalities = _optionalChain([config, 'optionalAccess', _271 => _271.responseModalities]);
10159
- this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess', _272 => _272.saveInputBlobsAsArtifacts]) || false;
10160
- this.supportCFC = _optionalChain([config, 'optionalAccess', _273 => _273.supportCFC]) || false;
10161
- this.streamingMode = _optionalChain([config, 'optionalAccess', _274 => _274.streamingMode]) || "NONE" /* NONE */;
10162
- this.outputAudioTranscription = _optionalChain([config, 'optionalAccess', _275 => _275.outputAudioTranscription]);
10163
- this.inputAudioTranscription = _optionalChain([config, 'optionalAccess', _276 => _276.inputAudioTranscription]);
10164
- this.realtimeInputConfig = _optionalChain([config, 'optionalAccess', _277 => _277.realtimeInputConfig]);
10165
- this.enableAffectiveDialog = _optionalChain([config, 'optionalAccess', _278 => _278.enableAffectiveDialog]);
10166
- this.proactivity = _optionalChain([config, 'optionalAccess', _279 => _279.proactivity]);
10167
- this.maxLlmCalls = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _280 => _280.maxLlmCalls]), () => ( 500));
10193
+ this.speechConfig = _optionalChain([config, 'optionalAccess', _272 => _272.speechConfig]);
10194
+ this.responseModalities = _optionalChain([config, 'optionalAccess', _273 => _273.responseModalities]);
10195
+ this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess', _274 => _274.saveInputBlobsAsArtifacts]) || false;
10196
+ this.supportCFC = _optionalChain([config, 'optionalAccess', _275 => _275.supportCFC]) || false;
10197
+ this.streamingMode = _optionalChain([config, 'optionalAccess', _276 => _276.streamingMode]) || "NONE" /* NONE */;
10198
+ this.outputAudioTranscription = _optionalChain([config, 'optionalAccess', _277 => _277.outputAudioTranscription]);
10199
+ this.inputAudioTranscription = _optionalChain([config, 'optionalAccess', _278 => _278.inputAudioTranscription]);
10200
+ this.realtimeInputConfig = _optionalChain([config, 'optionalAccess', _279 => _279.realtimeInputConfig]);
10201
+ this.enableAffectiveDialog = _optionalChain([config, 'optionalAccess', _280 => _280.enableAffectiveDialog]);
10202
+ this.proactivity = _optionalChain([config, 'optionalAccess', _281 => _281.proactivity]);
10203
+ this.maxLlmCalls = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _282 => _282.maxLlmCalls]), () => ( 500));
10168
10204
  this.validateMaxLlmCalls();
10169
10205
  }
10170
10206
  /**
@@ -10184,6 +10220,48 @@ var RunConfig = class {
10184
10220
  }
10185
10221
  };
10186
10222
 
10223
+ // src/artifacts/artifact-util.ts
10224
+ var SESSION_SCOPED_ARTIFACT_URI_RE = /^artifact:\/\/apps\/([^/]+)\/users\/([^/]+)\/sessions\/([^/]+)\/artifacts\/([^/]+)\/versions\/(\d+)$/;
10225
+ var USER_SCOPED_ARTIFACT_URI_RE = /^artifact:\/\/apps\/([^/]+)\/users\/([^/]+)\/artifacts\/([^/]+)\/versions\/(\d+)$/;
10226
+ function parseArtifactUri(uri) {
10227
+ if (!uri || !uri.startsWith("artifact://")) {
10228
+ return null;
10229
+ }
10230
+ let match = SESSION_SCOPED_ARTIFACT_URI_RE.exec(uri);
10231
+ if (match) {
10232
+ return {
10233
+ appName: match[1],
10234
+ userId: match[2],
10235
+ sessionId: match[3],
10236
+ filename: match[4],
10237
+ version: Number.parseInt(match[5], 10)
10238
+ };
10239
+ }
10240
+ match = USER_SCOPED_ARTIFACT_URI_RE.exec(uri);
10241
+ if (match) {
10242
+ return {
10243
+ appName: match[1],
10244
+ userId: match[2],
10245
+ sessionId: void 0,
10246
+ filename: match[3],
10247
+ version: Number.parseInt(match[4], 10)
10248
+ };
10249
+ }
10250
+ return null;
10251
+ }
10252
+ function getArtifactUri(args) {
10253
+ const { appName, userId, filename, version, sessionId } = args;
10254
+ if (sessionId) {
10255
+ return `artifact://apps/${appName}/users/${userId}/sessions/${sessionId}/artifacts/${filename}/versions/${version}`;
10256
+ }
10257
+ return `artifact://apps/${appName}/users/${userId}/artifacts/${filename}/versions/${version}`;
10258
+ }
10259
+ function isArtifactRef(artifact) {
10260
+ return Boolean(
10261
+ _optionalChain([artifact, 'access', _283 => _283.fileData, 'optionalAccess', _284 => _284.fileUri]) && artifact.fileData.fileUri.startsWith("artifact://")
10262
+ );
10263
+ }
10264
+
10187
10265
  // src/artifacts/in-memory-artifact-service.ts
10188
10266
  var InMemoryArtifactService = (_class29 = class {constructor() { _class29.prototype.__init50.call(this); }
10189
10267
  __init50() {this.artifacts = /* @__PURE__ */ new Map()}
@@ -10224,7 +10302,29 @@ var InMemoryArtifactService = (_class29 = class {constructor() { _class29.protot
10224
10302
  if (targetVersion < 0 || targetVersion >= versions.length) {
10225
10303
  return null;
10226
10304
  }
10227
- return versions[targetVersion];
10305
+ const artifactEntry = versions[targetVersion];
10306
+ if (!artifactEntry) {
10307
+ return null;
10308
+ }
10309
+ if (isArtifactRef(artifactEntry)) {
10310
+ const parsedUri = parseArtifactUri(_optionalChain([artifactEntry, 'access', _285 => _285.fileData, 'optionalAccess', _286 => _286.fileUri]) || "");
10311
+ if (!parsedUri) {
10312
+ throw new Error(
10313
+ `Invalid artifact reference URI: ${_optionalChain([artifactEntry, 'access', _287 => _287.fileData, 'optionalAccess', _288 => _288.fileUri])}`
10314
+ );
10315
+ }
10316
+ return await this.loadArtifact({
10317
+ appName: parsedUri.appName,
10318
+ userId: parsedUri.userId,
10319
+ sessionId: parsedUri.sessionId || sessionId,
10320
+ filename: parsedUri.filename,
10321
+ version: parsedUri.version
10322
+ });
10323
+ }
10324
+ if (!artifactEntry.text && (!_optionalChain([artifactEntry, 'access', _289 => _289.inlineData, 'optionalAccess', _290 => _290.data]) || artifactEntry.inlineData.data.length === 0) && !artifactEntry.fileData) {
10325
+ return null;
10326
+ }
10327
+ return artifactEntry;
10228
10328
  }
10229
10329
  async listArtifactKeys(args) {
10230
10330
  const { appName, userId, sessionId } = args;
@@ -10308,7 +10408,7 @@ var InMemoryMemoryService = (_class30 = class {
10308
10408
  }
10309
10409
  const userSessions = this._sessionEvents.get(userKey);
10310
10410
  const filteredEvents = session.events.filter(
10311
- (event) => _optionalChain([event, 'access', _281 => _281.content, 'optionalAccess', _282 => _282.parts])
10411
+ (event) => _optionalChain([event, 'access', _291 => _291.content, 'optionalAccess', _292 => _292.parts])
10312
10412
  );
10313
10413
  userSessions.set(session.id, filteredEvents);
10314
10414
  }
@@ -10409,11 +10509,16 @@ var BaseSessionService = class {
10409
10509
  return;
10410
10510
  }
10411
10511
  for (const key in event.actions.stateDelta) {
10412
- if (Object.prototype.hasOwnProperty.call(event.actions.stateDelta, key)) {
10512
+ if (Object.hasOwn(event.actions.stateDelta, key)) {
10413
10513
  if (key.startsWith("temp_")) {
10414
10514
  continue;
10415
10515
  }
10416
- session.state[key] = event.actions.stateDelta[key];
10516
+ const value = event.actions.stateDelta[key];
10517
+ if (value === null || value === void 0) {
10518
+ delete session.state[key];
10519
+ } else {
10520
+ session.state[key] = value;
10521
+ }
10417
10522
  }
10418
10523
  }
10419
10524
  }
@@ -10447,7 +10552,7 @@ var InMemorySessionService = (_class31 = class extends BaseSessionService {const
10447
10552
  return this.createSessionImpl(appName, userId, state, sessionId);
10448
10553
  }
10449
10554
  createSessionImpl(appName, userId, state, sessionId) {
10450
- const finalSessionId = _optionalChain([sessionId, 'optionalAccess', _283 => _283.trim, 'call', _284 => _284()]) || _crypto.randomUUID.call(void 0, );
10555
+ const finalSessionId = _optionalChain([sessionId, 'optionalAccess', _293 => _293.trim, 'call', _294 => _294()]) || _crypto.randomUUID.call(void 0, );
10451
10556
  const session = {
10452
10557
  appName,
10453
10558
  userId,
@@ -10604,7 +10709,7 @@ var InMemorySessionService = (_class31 = class extends BaseSessionService {const
10604
10709
  warning(`sessionId ${sessionId} not in sessions[appName][userId]`);
10605
10710
  return event;
10606
10711
  }
10607
- if (_optionalChain([event, 'access', _285 => _285.actions, 'optionalAccess', _286 => _286.stateDelta])) {
10712
+ if (_optionalChain([event, 'access', _295 => _295.actions, 'optionalAccess', _296 => _296.stateDelta])) {
10608
10713
  for (const key in event.actions.stateDelta) {
10609
10714
  const value = event.actions.stateDelta[key];
10610
10715
  if (key.startsWith(State.APP_PREFIX)) {
@@ -10638,14 +10743,14 @@ function _findFunctionCallEventIfLastEventIsFunctionResponse(session) {
10638
10743
  return null;
10639
10744
  }
10640
10745
  const lastEvent = events[events.length - 1];
10641
- if (_optionalChain([lastEvent, 'access', _287 => _287.content, 'optionalAccess', _288 => _288.parts, 'optionalAccess', _289 => _289.some, 'call', _290 => _290((part) => part.functionResponse)])) {
10642
- const functionCallId = _optionalChain([lastEvent, 'access', _291 => _291.content, 'access', _292 => _292.parts, 'access', _293 => _293.find, 'call', _294 => _294(
10746
+ if (_optionalChain([lastEvent, 'access', _297 => _297.content, 'optionalAccess', _298 => _298.parts, 'optionalAccess', _299 => _299.some, 'call', _300 => _300((part) => part.functionResponse)])) {
10747
+ const functionCallId = _optionalChain([lastEvent, 'access', _301 => _301.content, 'access', _302 => _302.parts, 'access', _303 => _303.find, 'call', _304 => _304(
10643
10748
  (part) => part.functionResponse
10644
- ), 'optionalAccess', _295 => _295.functionResponse, 'optionalAccess', _296 => _296.id]);
10749
+ ), 'optionalAccess', _305 => _305.functionResponse, 'optionalAccess', _306 => _306.id]);
10645
10750
  if (!functionCallId) return null;
10646
10751
  for (let i = events.length - 2; i >= 0; i--) {
10647
10752
  const event = events[i];
10648
- const functionCalls = _optionalChain([event, 'access', _297 => _297.getFunctionCalls, 'optionalCall', _298 => _298()]) || [];
10753
+ const functionCalls = _optionalChain([event, 'access', _307 => _307.getFunctionCalls, 'optionalCall', _308 => _308()]) || [];
10649
10754
  for (const functionCall of functionCalls) {
10650
10755
  if (functionCall.id === functionCallId) {
10651
10756
  return event;
@@ -10858,15 +10963,15 @@ var Runner = (_class32 = class {
10858
10963
  */
10859
10964
  _findAgentToRun(session, rootAgent) {
10860
10965
  const event = _findFunctionCallEventIfLastEventIsFunctionResponse(session);
10861
- if (_optionalChain([event, 'optionalAccess', _299 => _299.author])) {
10966
+ if (_optionalChain([event, 'optionalAccess', _309 => _309.author])) {
10862
10967
  return rootAgent.findAgent(event.author);
10863
10968
  }
10864
- const nonUserEvents = _optionalChain([session, 'access', _300 => _300.events, 'optionalAccess', _301 => _301.filter, 'call', _302 => _302((e) => e.author !== "user"), 'access', _303 => _303.reverse, 'call', _304 => _304()]) || [];
10969
+ const nonUserEvents = _optionalChain([session, 'access', _310 => _310.events, 'optionalAccess', _311 => _311.filter, 'call', _312 => _312((e) => e.author !== "user"), 'access', _313 => _313.reverse, 'call', _314 => _314()]) || [];
10865
10970
  for (const event2 of nonUserEvents) {
10866
10971
  if (event2.author === rootAgent.name) {
10867
10972
  return rootAgent;
10868
10973
  }
10869
- const agent = _optionalChain([rootAgent, 'access', _305 => _305.findSubAgent, 'optionalCall', _306 => _306(event2.author)]);
10974
+ const agent = _optionalChain([rootAgent, 'access', _315 => _315.findSubAgent, 'optionalCall', _316 => _316(event2.author)]);
10870
10975
  if (!agent) {
10871
10976
  this.logger.debug(
10872
10977
  `Event from an unknown agent: ${event2.author}, event id: ${event2.id}`
@@ -10944,7 +11049,7 @@ var Runner = (_class32 = class {
10944
11049
  * Gets the configured summarizer or creates a default LLM-based one.
10945
11050
  */
10946
11051
  _getOrCreateSummarizer() {
10947
- if (_optionalChain([this, 'access', _307 => _307.eventsCompactionConfig, 'optionalAccess', _308 => _308.summarizer])) {
11052
+ if (_optionalChain([this, 'access', _317 => _317.eventsCompactionConfig, 'optionalAccess', _318 => _318.summarizer])) {
10948
11053
  return this.eventsCompactionConfig.summarizer;
10949
11054
  }
10950
11055
  if (this.agent instanceof LlmAgent) {
@@ -10961,6 +11066,142 @@ var Runner = (_class32 = class {
10961
11066
  }
10962
11067
  return void 0;
10963
11068
  }
11069
+ async rewind(args) {
11070
+ const { userId, sessionId, rewindBeforeInvocationId } = args;
11071
+ const session = await this.sessionService.getSession(
11072
+ this.appName,
11073
+ userId,
11074
+ sessionId
11075
+ );
11076
+ if (!session) {
11077
+ throw new Error(`Session not found: ${sessionId}`);
11078
+ }
11079
+ let rewindEventIndex = -1;
11080
+ for (let i = 0; i < session.events.length; i++) {
11081
+ if (session.events[i].invocationId === rewindBeforeInvocationId) {
11082
+ rewindEventIndex = i;
11083
+ break;
11084
+ }
11085
+ }
11086
+ if (rewindEventIndex === -1) {
11087
+ throw new Error(`Invocation ID not found: ${rewindBeforeInvocationId}`);
11088
+ }
11089
+ const stateDelta = await this._computeStateDeltaForRewind(
11090
+ session,
11091
+ rewindEventIndex
11092
+ );
11093
+ const artifactDelta = await this._computeArtifactDeltaForRewind(
11094
+ session,
11095
+ rewindEventIndex
11096
+ );
11097
+ const rewindEvent = new Event({
11098
+ invocationId: newInvocationContextId(),
11099
+ author: "user",
11100
+ actions: new EventActions({
11101
+ rewindBeforeInvocationId,
11102
+ stateDelta,
11103
+ artifactDelta
11104
+ })
11105
+ });
11106
+ this.logger.info(
11107
+ "Rewinding session to invocation:",
11108
+ rewindBeforeInvocationId
11109
+ );
11110
+ await this.sessionService.appendEvent(session, rewindEvent);
11111
+ }
11112
+ async _computeStateDeltaForRewind(session, rewindEventIndex) {
11113
+ const stateAtRewindPoint = {};
11114
+ for (let i = 0; i < rewindEventIndex; i++) {
11115
+ const event = session.events[i];
11116
+ if (_optionalChain([event, 'access', _319 => _319.actions, 'optionalAccess', _320 => _320.stateDelta])) {
11117
+ for (const [k, v] of Object.entries(event.actions.stateDelta)) {
11118
+ if (k.startsWith("app:") || k.startsWith("user:")) {
11119
+ continue;
11120
+ }
11121
+ if (v === null || v === void 0) {
11122
+ delete stateAtRewindPoint[k];
11123
+ } else {
11124
+ stateAtRewindPoint[k] = v;
11125
+ }
11126
+ }
11127
+ }
11128
+ }
11129
+ const currentState = session.state;
11130
+ const rewindStateDelta = {};
11131
+ for (const [key, valueAtRewind] of Object.entries(stateAtRewindPoint)) {
11132
+ if (!(key in currentState) || currentState[key] !== valueAtRewind) {
11133
+ rewindStateDelta[key] = valueAtRewind;
11134
+ }
11135
+ }
11136
+ for (const key of Object.keys(currentState)) {
11137
+ if (key.startsWith("app:") || key.startsWith("user:")) {
11138
+ continue;
11139
+ }
11140
+ if (!(key in stateAtRewindPoint)) {
11141
+ rewindStateDelta[key] = null;
11142
+ }
11143
+ }
11144
+ return rewindStateDelta;
11145
+ }
11146
+ async _computeArtifactDeltaForRewind(session, rewindEventIndex) {
11147
+ if (!this.artifactService) {
11148
+ return {};
11149
+ }
11150
+ const versionsAtRewindPoint = {};
11151
+ for (let i = 0; i < rewindEventIndex; i++) {
11152
+ const event = session.events[i];
11153
+ if (_optionalChain([event, 'access', _321 => _321.actions, 'optionalAccess', _322 => _322.artifactDelta])) {
11154
+ Object.assign(versionsAtRewindPoint, event.actions.artifactDelta);
11155
+ }
11156
+ }
11157
+ const currentVersions = {};
11158
+ for (const event of session.events) {
11159
+ if (_optionalChain([event, 'access', _323 => _323.actions, 'optionalAccess', _324 => _324.artifactDelta])) {
11160
+ Object.assign(currentVersions, event.actions.artifactDelta);
11161
+ }
11162
+ }
11163
+ const rewindArtifactDelta = {};
11164
+ for (const [filename, vn] of Object.entries(currentVersions)) {
11165
+ if (filename.startsWith("user:")) {
11166
+ continue;
11167
+ }
11168
+ const vt = versionsAtRewindPoint[filename];
11169
+ if (vt === vn) {
11170
+ continue;
11171
+ }
11172
+ let artifact;
11173
+ if (vt === void 0 || vt === null) {
11174
+ artifact = {
11175
+ inlineData: {
11176
+ mimeType: "application/octet-stream",
11177
+ data: ""
11178
+ }
11179
+ };
11180
+ } else {
11181
+ const artifactUri = getArtifactUri({
11182
+ appName: this.appName,
11183
+ userId: session.userId,
11184
+ sessionId: session.id,
11185
+ filename,
11186
+ version: vt
11187
+ });
11188
+ artifact = {
11189
+ fileData: {
11190
+ fileUri: artifactUri
11191
+ }
11192
+ };
11193
+ }
11194
+ const newVersion = await this.artifactService.saveArtifact({
11195
+ appName: this.appName,
11196
+ userId: session.userId,
11197
+ sessionId: session.id,
11198
+ filename,
11199
+ artifact
11200
+ });
11201
+ rewindArtifactDelta[filename] = newVersion;
11202
+ }
11203
+ return rewindArtifactDelta;
11204
+ }
10964
11205
  }, _class32);
10965
11206
  var InMemoryRunner = class extends Runner {
10966
11207
  /**
@@ -11600,7 +11841,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
11600
11841
  const outputSchema = this.config.outputSchema;
11601
11842
  const agentType = this.agentType;
11602
11843
  const isMulti = agentType === "parallel" || agentType === "sequential";
11603
- const subAgentNames = _optionalChain([this, 'access', _309 => _309.config, 'access', _310 => _310.subAgents, 'optionalAccess', _311 => _311.map, 'call', _312 => _312((a) => a.name)]) || [];
11844
+ const subAgentNames = _optionalChain([this, 'access', _325 => _325.config, 'access', _326 => _326.subAgents, 'optionalAccess', _327 => _327.map, 'call', _328 => _328((a) => a.name)]) || [];
11604
11845
  const runConfig = this.runConfig;
11605
11846
  return {
11606
11847
  __outputSchema: outputSchema,
@@ -11609,7 +11850,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
11609
11850
  let combinedResponse = "";
11610
11851
  const perAgentBuffers = {};
11611
11852
  const authors = /* @__PURE__ */ new Set();
11612
- if (!_optionalChain([sessionOptions, 'optionalAccess', _313 => _313.userId])) {
11853
+ if (!_optionalChain([sessionOptions, 'optionalAccess', _329 => _329.userId])) {
11613
11854
  throw new Error("Session configuration is required");
11614
11855
  }
11615
11856
  for await (const event of baseRunner.runAsync({
@@ -11618,7 +11859,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
11618
11859
  newMessage,
11619
11860
  runConfig
11620
11861
  })) {
11621
- if (_optionalChain([event, 'access', _314 => _314.content, 'optionalAccess', _315 => _315.parts]) && Array.isArray(event.content.parts)) {
11862
+ if (_optionalChain([event, 'access', _330 => _330.content, 'optionalAccess', _331 => _331.parts]) && Array.isArray(event.content.parts)) {
11622
11863
  const content = event.content.parts.map(
11623
11864
  (part) => (part && typeof part === "object" && "text" in part ? part.text : "") || ""
11624
11865
  ).join("");
@@ -11664,6 +11905,9 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
11664
11905
  ...params,
11665
11906
  runConfig: _nullishCoalesce(params.runConfig, () => ( runConfig))
11666
11907
  });
11908
+ },
11909
+ rewind(params) {
11910
+ return baseRunner.rewind(params);
11667
11911
  }
11668
11912
  };
11669
11913
  }
@@ -11905,7 +12149,7 @@ var VertexAiSessionService = class extends BaseSessionService {
11905
12149
  path: `operations/${operationId}`,
11906
12150
  request_dict: {}
11907
12151
  });
11908
- if (_optionalChain([lroResponse, 'optionalAccess', _316 => _316.done])) {
12152
+ if (_optionalChain([lroResponse, 'optionalAccess', _332 => _332.done])) {
11909
12153
  break;
11910
12154
  }
11911
12155
  await new Promise((resolve) => setTimeout(resolve, 1e3));
@@ -12276,12 +12520,12 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
12276
12520
  }
12277
12521
  async createSession(appName, userId, state, sessionId) {
12278
12522
  await this.ensureInitialized();
12279
- const id = _optionalChain([sessionId, 'optionalAccess', _317 => _317.trim, 'call', _318 => _318()]) || this.generateSessionId();
12523
+ const id = _optionalChain([sessionId, 'optionalAccess', _333 => _333.trim, 'call', _334 => _334()]) || this.generateSessionId();
12280
12524
  return await this.db.transaction().execute(async (trx) => {
12281
12525
  const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
12282
12526
  const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", appName).where("user_id", "=", userId).executeTakeFirst();
12283
- let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _319 => _319.state]), {});
12284
- let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _320 => _320.state]), {});
12527
+ let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _335 => _335.state]), {});
12528
+ let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _336 => _336.state]), {});
12285
12529
  if (!appState) {
12286
12530
  await trx.insertInto("app_states").values({
12287
12531
  app_name: appName,
@@ -12340,21 +12584,21 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
12340
12584
  return void 0;
12341
12585
  }
12342
12586
  let eventQuery = trx.selectFrom("events").selectAll().where("session_id", "=", sessionId).orderBy("timestamp", "desc");
12343
- if (_optionalChain([config, 'optionalAccess', _321 => _321.afterTimestamp])) {
12587
+ if (_optionalChain([config, 'optionalAccess', _337 => _337.afterTimestamp])) {
12344
12588
  eventQuery = eventQuery.where(
12345
12589
  "timestamp",
12346
12590
  ">=",
12347
12591
  new Date(config.afterTimestamp * 1e3)
12348
12592
  );
12349
12593
  }
12350
- if (_optionalChain([config, 'optionalAccess', _322 => _322.numRecentEvents])) {
12594
+ if (_optionalChain([config, 'optionalAccess', _338 => _338.numRecentEvents])) {
12351
12595
  eventQuery = eventQuery.limit(config.numRecentEvents);
12352
12596
  }
12353
12597
  const storageEvents = await eventQuery.execute();
12354
12598
  const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
12355
12599
  const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", appName).where("user_id", "=", userId).executeTakeFirst();
12356
- const currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _323 => _323.state]), {});
12357
- const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _324 => _324.state]), {});
12600
+ const currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _339 => _339.state]), {});
12601
+ const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _340 => _340.state]), {});
12358
12602
  const sessionState = this.parseJsonSafely(storageSession.state, {});
12359
12603
  const mergedState = this.mergeState(
12360
12604
  currentAppState,
@@ -12412,13 +12656,13 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
12412
12656
  }
12413
12657
  const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", session.appName).executeTakeFirst();
12414
12658
  const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", session.appName).where("user_id", "=", session.userId).executeTakeFirst();
12415
- let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _325 => _325.state]), {});
12416
- let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _326 => _326.state]), {});
12659
+ let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _341 => _341.state]), {});
12660
+ let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _342 => _342.state]), {});
12417
12661
  let sessionState = this.parseJsonSafely(storageSession.state, {});
12418
12662
  let appStateDelta = {};
12419
12663
  let userStateDelta = {};
12420
12664
  let sessionStateDelta = {};
12421
- if (_optionalChain([event, 'access', _327 => _327.actions, 'optionalAccess', _328 => _328.stateDelta])) {
12665
+ if (_optionalChain([event, 'access', _343 => _343.actions, 'optionalAccess', _344 => _344.stateDelta])) {
12422
12666
  const deltas = this.extractStateDelta(event.actions.stateDelta);
12423
12667
  appStateDelta = deltas.appStateDelta;
12424
12668
  userStateDelta = deltas.userStateDelta;
@@ -12564,7 +12808,7 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
12564
12808
  * Overrides the base class method to work with plain object state.
12565
12809
  */
12566
12810
  updateSessionState(session, event) {
12567
- if (!_optionalChain([event, 'access', _329 => _329.actions, 'optionalAccess', _330 => _330.stateDelta])) {
12811
+ if (!_optionalChain([event, 'access', _345 => _345.actions, 'optionalAccess', _346 => _346.stateDelta])) {
12568
12812
  return;
12569
12813
  }
12570
12814
  for (const [key, value] of Object.entries(event.actions.stateDelta)) {
@@ -12734,7 +12978,7 @@ var GcsArtifactService = class {
12734
12978
  };
12735
12979
  return part;
12736
12980
  } catch (error) {
12737
- if (_optionalChain([error, 'optionalAccess', _331 => _331.code]) === 404) {
12981
+ if (_optionalChain([error, 'optionalAccess', _347 => _347.code]) === 404) {
12738
12982
  return null;
12739
12983
  }
12740
12984
  throw error;
@@ -12985,13 +13229,13 @@ var VertexAiEvalFacade = class _VertexAiEvalFacade {
12985
13229
  };
12986
13230
  }
12987
13231
  _getText(content) {
12988
- if (_optionalChain([content, 'optionalAccess', _332 => _332.parts])) {
13232
+ if (_optionalChain([content, 'optionalAccess', _348 => _348.parts])) {
12989
13233
  return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join("\n");
12990
13234
  }
12991
13235
  return "";
12992
13236
  }
12993
13237
  _getScore(evalResult) {
12994
- if (_optionalChain([evalResult, 'optionalAccess', _333 => _333.summaryMetrics, 'optionalAccess', _334 => _334[0], 'optionalAccess', _335 => _335.meanScore]) !== void 0 && typeof evalResult.summaryMetrics[0].meanScore === "number" && !Number.isNaN(evalResult.summaryMetrics[0].meanScore)) {
13238
+ if (_optionalChain([evalResult, 'optionalAccess', _349 => _349.summaryMetrics, 'optionalAccess', _350 => _350[0], 'optionalAccess', _351 => _351.meanScore]) !== void 0 && typeof evalResult.summaryMetrics[0].meanScore === "number" && !Number.isNaN(evalResult.summaryMetrics[0].meanScore)) {
12995
13239
  return evalResult.summaryMetrics[0].meanScore;
12996
13240
  }
12997
13241
  return void 0;
@@ -13141,7 +13385,7 @@ var ResponseEvaluator = class extends Evaluator {
13141
13385
  return fmeasure;
13142
13386
  }
13143
13387
  extractText(content) {
13144
- if (_optionalChain([content, 'optionalAccess', _336 => _336.parts])) {
13388
+ if (_optionalChain([content, 'optionalAccess', _352 => _352.parts])) {
13145
13389
  return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join(" ");
13146
13390
  }
13147
13391
  return "";
@@ -13174,7 +13418,7 @@ var TrajectoryEvaluator = class extends Evaluator {
13174
13418
  for (let i = 0; i < actualInvocations.length; i++) {
13175
13419
  const actual = actualInvocations[i];
13176
13420
  const expected = expectedInvocations[i];
13177
- if (!_optionalChain([actual, 'access', _337 => _337.intermediateData, 'optionalAccess', _338 => _338.toolUses]) || !_optionalChain([expected, 'access', _339 => _339.intermediateData, 'optionalAccess', _340 => _340.toolUses])) {
13421
+ if (!_optionalChain([actual, 'access', _353 => _353.intermediateData, 'optionalAccess', _354 => _354.toolUses]) || !_optionalChain([expected, 'access', _355 => _355.intermediateData, 'optionalAccess', _356 => _356.toolUses])) {
13178
13422
  perInvocationResults.push({
13179
13423
  actualInvocation: actual,
13180
13424
  expectedInvocation: expected,
@@ -13262,7 +13506,7 @@ var SafetyEvaluatorV1 = class extends Evaluator {
13262
13506
 
13263
13507
  // src/evaluation/llm-as-judge-utils.ts
13264
13508
  function getTextFromContent(content) {
13265
- if (_optionalChain([content, 'optionalAccess', _341 => _341.parts])) {
13509
+ if (_optionalChain([content, 'optionalAccess', _357 => _357.parts])) {
13266
13510
  return content.parts.map((part) => part.text).filter(Boolean).join("\n");
13267
13511
  }
13268
13512
  return "";
@@ -13274,9 +13518,9 @@ function getEvalStatus(score, threshold) {
13274
13518
  // src/evaluation/llm-as-judge.ts
13275
13519
  var LlmAsJudge = class {
13276
13520
  async sampleJudge(prompt, numSamples, critiqueParser, judgeModelOptions) {
13277
- const modelName = _optionalChain([judgeModelOptions, 'optionalAccess', _342 => _342.judgeModel]) || "gemini-2.5-flash";
13521
+ const modelName = _optionalChain([judgeModelOptions, 'optionalAccess', _358 => _358.judgeModel]) || "gemini-2.5-flash";
13278
13522
  const model = LLMRegistry.getModelOrCreate(modelName);
13279
- const config = _optionalChain([judgeModelOptions, 'optionalAccess', _343 => _343.judgeModelConfig]) || {};
13523
+ const config = _optionalChain([judgeModelOptions, 'optionalAccess', _359 => _359.judgeModelConfig]) || {};
13280
13524
  const samples = [];
13281
13525
  for (let i = 0; i < numSamples; i++) {
13282
13526
  try {
@@ -13342,7 +13586,7 @@ function parseCritique(response) {
13342
13586
  const labelMatchIsResponseValid = response.match(
13343
13587
  /"is_the_agent_response_valid":\s*\[*[\n\s]*"*([^"^\]^\s]*)"*[\n\s]*\]*\s*[,\n\}]/
13344
13588
  );
13345
- if (_optionalChain([labelMatchIsResponseValid, 'optionalAccess', _344 => _344[1]])) {
13589
+ if (_optionalChain([labelMatchIsResponseValid, 'optionalAccess', _360 => _360[1]])) {
13346
13590
  const label = labelMatchIsResponseValid[1].toLowerCase();
13347
13591
  return label === "valid" ? "valid" /* VALID */ : "invalid" /* INVALID */;
13348
13592
  }
@@ -13387,7 +13631,7 @@ var FinalResponseMatchV2Evaluator = class extends Evaluator {
13387
13631
  "{prompt}",
13388
13632
  prompt
13389
13633
  ).replace("{response}", response).replace("{golden_response}", goldenResponse);
13390
- const numSamples = _nullishCoalesce(_optionalChain([this, 'access', _345 => _345.metric, 'access', _346 => _346.judgeModelOptions, 'optionalAccess', _347 => _347.numSamples]), () => ( DEFAULT_NUM_SAMPLES));
13634
+ const numSamples = _nullishCoalesce(_optionalChain([this, 'access', _361 => _361.metric, 'access', _362 => _362.judgeModelOptions, 'optionalAccess', _363 => _363.numSamples]), () => ( DEFAULT_NUM_SAMPLES));
13391
13635
  const labels = await this.llmAsJudge.sampleJudge(
13392
13636
  formattedPrompt,
13393
13637
  numSamples,
@@ -13427,7 +13671,7 @@ var MetricEvaluatorRegistry = (_class35 = class {constructor() { _class35.protot
13427
13671
  const metricName = metricInfo.metricName;
13428
13672
  if (this.registry.has(metricName)) {
13429
13673
  console.info(
13430
- `Updating Evaluator class for ${metricName} from ${_optionalChain([this, 'access', _348 => _348.registry, 'access', _349 => _349.get, 'call', _350 => _350(metricName), 'optionalAccess', _351 => _351.evaluator, 'access', _352 => _352.name])} to ${evaluator.name}`
13674
+ `Updating Evaluator class for ${metricName} from ${_optionalChain([this, 'access', _364 => _364.registry, 'access', _365 => _365.get, 'call', _366 => _366(metricName), 'optionalAccess', _367 => _367.evaluator, 'access', _368 => _368.name])} to ${evaluator.name}`
13431
13675
  );
13432
13676
  }
13433
13677
  this.registry.set(metricName, {
@@ -13541,10 +13785,10 @@ var LocalEvalService = class extends BaseEvalService {
13541
13785
  for (const evalMetric of evaluateConfig.evalMetrics) {
13542
13786
  const evaluator = DEFAULT_METRIC_EVALUATOR_REGISTRY.getEvaluator(evalMetric);
13543
13787
  const actual = results.filter(
13544
- (r) => !_optionalChain([r, 'access', _353 => _353.invocationId, 'optionalAccess', _354 => _354.includes, 'call', _355 => _355("expected")])
13788
+ (r) => !_optionalChain([r, 'access', _369 => _369.invocationId, 'optionalAccess', _370 => _370.includes, 'call', _371 => _371("expected")])
13545
13789
  );
13546
13790
  const expected = results.filter(
13547
- (r) => _optionalChain([r, 'access', _356 => _356.invocationId, 'optionalAccess', _357 => _357.includes, 'call', _358 => _358("expected")])
13791
+ (r) => _optionalChain([r, 'access', _372 => _372.invocationId, 'optionalAccess', _373 => _373.includes, 'call', _374 => _374("expected")])
13548
13792
  );
13549
13793
  const result = await evaluator.evaluateInvocations(actual, expected);
13550
13794
  evalResult.evalCaseResults.push({
@@ -13936,13 +14180,13 @@ ${failures.join(
13936
14180
  console.log("\n\n");
13937
14181
  }
13938
14182
  static _convertContentToText(content) {
13939
- if (_optionalChain([content, 'optionalAccess', _359 => _359.parts])) {
14183
+ if (_optionalChain([content, 'optionalAccess', _375 => _375.parts])) {
13940
14184
  return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join("\n");
13941
14185
  }
13942
14186
  return "";
13943
14187
  }
13944
14188
  static _convertToolCallsToText(intermediateData) {
13945
- if (_optionalChain([intermediateData, 'optionalAccess', _360 => _360.toolUses])) {
14189
+ if (_optionalChain([intermediateData, 'optionalAccess', _376 => _376.toolUses])) {
13946
14190
  return intermediateData.toolUses.map((t) => JSON.stringify(t)).join("\n");
13947
14191
  }
13948
14192
  return "";
@@ -13997,7 +14241,7 @@ ${failures.join(
13997
14241
  for (const [metricName, evalMetricResultsWithInvocations] of Object.entries(
13998
14242
  evalMetricResults
13999
14243
  )) {
14000
- const threshold = _optionalChain([evalMetricResultsWithInvocations, 'access', _361 => _361[0], 'optionalAccess', _362 => _362.evalMetricResult, 'access', _363 => _363.threshold]) || 0;
14244
+ const threshold = _optionalChain([evalMetricResultsWithInvocations, 'access', _377 => _377[0], 'optionalAccess', _378 => _378.evalMetricResult, 'access', _379 => _379.threshold]) || 0;
14001
14245
  const scores = evalMetricResultsWithInvocations.map((m) => m.evalMetricResult.score).filter((s) => s !== void 0);
14002
14246
  let overallScore;
14003
14247
  let overallEvalStatus;
@@ -14086,7 +14330,7 @@ var RougeEvaluator = class extends Evaluator {
14086
14330
  }
14087
14331
  };
14088
14332
  function getTextFromContent2(content) {
14089
- if (_optionalChain([content, 'optionalAccess', _364 => _364.parts])) {
14333
+ if (_optionalChain([content, 'optionalAccess', _380 => _380.parts])) {
14090
14334
  return content.parts.map((part) => part.text).filter(Boolean).join("\n");
14091
14335
  }
14092
14336
  return "";
@@ -14284,4 +14528,8 @@ var VERSION = "0.1.0";
14284
14528
 
14285
14529
 
14286
14530
 
14287
- exports.AF_FUNCTION_CALL_ID_PREFIX = AF_FUNCTION_CALL_ID_PREFIX; exports.Agent = LlmAgent; exports.AgentBuilder = AgentBuilder; exports.AgentEvaluator = AgentEvaluator; exports.AgentTool = AgentTool; exports.Agents = agents_exports; exports.AiSdkLlm = AiSdkLlm; exports.AnthropicLlm = AnthropicLlm; exports.ApiKeyCredential = ApiKeyCredential; exports.ApiKeyScheme = ApiKeyScheme; exports.AuthConfig = AuthConfig; exports.AuthCredential = AuthCredential; exports.AuthCredentialType = AuthCredentialType; exports.AuthHandler = AuthHandler; exports.AuthScheme = AuthScheme; exports.AuthSchemeType = AuthSchemeType; exports.AuthTool = AuthTool; exports.AutoFlow = AutoFlow; exports.BaseAgent = BaseAgent; exports.BaseCodeExecutor = BaseCodeExecutor; exports.BaseLLMConnection = BaseLLMConnection; exports.BaseLlm = BaseLlm; exports.BaseLlmFlow = BaseLlmFlow; exports.BaseLlmRequestProcessor = BaseLlmRequestProcessor; exports.BaseLlmResponseProcessor = BaseLlmResponseProcessor; exports.BasePlanner = BasePlanner; exports.BaseSessionService = BaseSessionService; exports.BaseTool = BaseTool; exports.BasicAuthCredential = BasicAuthCredential; exports.BearerTokenCredential = BearerTokenCredential; exports.BuiltInCodeExecutor = BuiltInCodeExecutor; exports.BuiltInPlanner = BuiltInPlanner; exports.CallbackContext = CallbackContext; exports.CodeExecutionUtils = CodeExecutionUtils; exports.CodeExecutorContext = CodeExecutorContext; exports.DatabaseSessionService = DatabaseSessionService; exports.EnhancedAuthConfig = EnhancedAuthConfig; exports.EvalResult = EvalResult; exports.EvalStatus = EvalStatus; exports.Evaluation = evaluation_exports; exports.Evaluator = Evaluator; exports.Event = Event; exports.EventActions = EventActions; exports.Events = events_exports; exports.ExitLoopTool = ExitLoopTool; exports.FileOperationsTool = FileOperationsTool; exports.FinalResponseMatchV2Evaluator = FinalResponseMatchV2Evaluator; exports.Flows = flows_exports; exports.FunctionTool = FunctionTool; exports.GcsArtifactService = GcsArtifactService; exports.GetUserChoiceTool = GetUserChoiceTool; exports.GoogleLlm = GoogleLlm; exports.GoogleSearch = GoogleSearch; exports.HttpRequestTool = HttpRequestTool; exports.HttpScheme = HttpScheme; exports.InMemoryArtifactService = InMemoryArtifactService; exports.InMemoryMemoryService = InMemoryMemoryService; exports.InMemoryRunner = InMemoryRunner; exports.InMemorySessionService = InMemorySessionService; exports.InvocationContext = InvocationContext; exports.LLMRegistry = LLMRegistry; exports.LangGraphAgent = LangGraphAgent; exports.LlmAgent = LlmAgent; exports.LlmCallsLimitExceededError = LlmCallsLimitExceededError; exports.LlmEventSummarizer = LlmEventSummarizer; exports.LlmRequest = LlmRequest; exports.LlmResponse = LlmResponse; exports.LoadArtifactsTool = LoadArtifactsTool; exports.LoadMemoryTool = LoadMemoryTool; exports.LocalEvalService = LocalEvalService; exports.LoopAgent = LoopAgent; exports.McpAbi = McpAbi; exports.McpAtp = McpAtp; exports.McpBamm = McpBamm; exports.McpCoinGecko = McpCoinGecko; exports.McpCoinGeckoPro = McpCoinGeckoPro; exports.McpDiscord = McpDiscord; exports.McpError = McpError; exports.McpErrorType = McpErrorType; exports.McpFilesystem = McpFilesystem; exports.McpFraxlend = McpFraxlend; exports.McpGeneric = McpGeneric; exports.McpIqWiki = McpIqWiki; exports.McpMemory = McpMemory; exports.McpNearAgent = McpNearAgent; exports.McpNearIntents = McpNearIntents; exports.McpOdos = McpOdos; exports.McpSamplingHandler = McpSamplingHandler; exports.McpTelegram = McpTelegram; exports.McpToolset = McpToolset; exports.McpUpbit = McpUpbit; exports.Memory = memory_exports; exports.Models = models_exports; exports.OAuth2Credential = OAuth2Credential; exports.OAuth2Scheme = OAuth2Scheme; exports.OpenAiLlm = OpenAiLlm; exports.OpenIdConnectScheme = OpenIdConnectScheme; exports.ParallelAgent = ParallelAgent; exports.PlanReActPlanner = PlanReActPlanner; exports.PrebuiltMetrics = PrebuiltMetrics; exports.REQUEST_EUC_FUNCTION_CALL_NAME = REQUEST_EUC_FUNCTION_CALL_NAME; exports.ReadonlyContext = ReadonlyContext; exports.RougeEvaluator = RougeEvaluator; exports.RunConfig = RunConfig; exports.Runner = Runner; exports.SafetyEvaluatorV1 = SafetyEvaluatorV1; exports.SequentialAgent = SequentialAgent; exports.Sessions = sessions_exports; exports.SingleFlow = SingleFlow; exports.State = State; exports.StreamingMode = StreamingMode; exports.TelemetryService = TelemetryService; exports.ToolContext = ToolContext; exports.Tools = tools_exports; exports.TrajectoryEvaluator = TrajectoryEvaluator; exports.TransferToAgentTool = TransferToAgentTool; exports.UserInteractionTool = UserInteractionTool; exports.VERSION = VERSION; exports.VertexAiRagMemoryService = VertexAiRagMemoryService; exports.VertexAiSessionService = VertexAiSessionService; exports._findFunctionCallEventIfLastEventIsFunctionResponse = _findFunctionCallEventIfLastEventIsFunctionResponse; exports.adkToMcpToolType = adkToMcpToolType; exports.agentTransferRequestProcessor = requestProcessor8; exports.basicRequestProcessor = requestProcessor2; exports.buildFunctionDeclaration = buildFunctionDeclaration; exports.codeExecutionRequestProcessor = requestProcessor3; exports.codeExecutionResponseProcessor = responseProcessor; exports.contentRequestProcessor = requestProcessor4; exports.convertMcpToolToBaseTool = convertMcpToolToBaseTool; exports.createAuthToolArguments = createAuthToolArguments; exports.createBranchContextForSubAgent = createBranchContextForSubAgent; exports.createDatabaseSessionService = createDatabaseSessionService; exports.createFunctionTool = createFunctionTool; exports.createMysqlSessionService = createMysqlSessionService; exports.createPostgresSessionService = createPostgresSessionService; exports.createSamplingHandler = createSamplingHandler; exports.createSqliteSessionService = createSqliteSessionService; exports.createTool = createTool; exports.generateAuthEvent = generateAuthEvent; exports.generateClientFunctionCallId = generateClientFunctionCallId; exports.getLongRunningFunctionCalls = getLongRunningFunctionCalls; exports.getMcpTools = getMcpTools; exports.handleFunctionCallsAsync = handleFunctionCallsAsync; exports.handleFunctionCallsLive = handleFunctionCallsLive; exports.identityRequestProcessor = requestProcessor5; exports.initializeTelemetry = initializeTelemetry; exports.injectSessionState = injectSessionState; exports.instructionsRequestProcessor = requestProcessor6; exports.isEnhancedAuthConfig = isEnhancedAuthConfig; exports.jsonSchemaToDeclaration = jsonSchemaToDeclaration; exports.mcpSchemaToParameters = mcpSchemaToParameters; exports.mergeAgentRun = mergeAgentRun; exports.mergeParallelFunctionResponseEvents = mergeParallelFunctionResponseEvents; exports.newInvocationContextId = newInvocationContextId; exports.nlPlanningRequestProcessor = requestProcessor7; exports.nlPlanningResponseProcessor = responseProcessor2; exports.normalizeJsonSchema = normalizeJsonSchema; exports.populateClientFunctionCallId = populateClientFunctionCallId; exports.registerProviders = registerProviders; exports.removeClientFunctionCallId = removeClientFunctionCallId; exports.requestProcessor = requestProcessor; exports.runCompactionForSlidingWindow = runCompactionForSlidingWindow; exports.shutdownTelemetry = shutdownTelemetry; exports.telemetryService = telemetryService; exports.traceLlmCall = traceLlmCall; exports.traceToolCall = traceToolCall; exports.tracer = tracer;
14531
+
14532
+
14533
+
14534
+
14535
+ exports.AF_FUNCTION_CALL_ID_PREFIX = AF_FUNCTION_CALL_ID_PREFIX; exports.Agent = LlmAgent; exports.AgentBuilder = AgentBuilder; exports.AgentEvaluator = AgentEvaluator; exports.AgentTool = AgentTool; exports.Agents = agents_exports; exports.AiSdkLlm = AiSdkLlm; exports.AnthropicLlm = AnthropicLlm; exports.ApiKeyCredential = ApiKeyCredential; exports.ApiKeyScheme = ApiKeyScheme; exports.AuthConfig = AuthConfig; exports.AuthCredential = AuthCredential; exports.AuthCredentialType = AuthCredentialType; exports.AuthHandler = AuthHandler; exports.AuthScheme = AuthScheme; exports.AuthSchemeType = AuthSchemeType; exports.AuthTool = AuthTool; exports.AutoFlow = AutoFlow; exports.BaseAgent = BaseAgent; exports.BaseCodeExecutor = BaseCodeExecutor; exports.BaseLLMConnection = BaseLLMConnection; exports.BaseLlm = BaseLlm; exports.BaseLlmFlow = BaseLlmFlow; exports.BaseLlmRequestProcessor = BaseLlmRequestProcessor; exports.BaseLlmResponseProcessor = BaseLlmResponseProcessor; exports.BasePlanner = BasePlanner; exports.BaseSessionService = BaseSessionService; exports.BaseTool = BaseTool; exports.BasicAuthCredential = BasicAuthCredential; exports.BearerTokenCredential = BearerTokenCredential; exports.BuiltInCodeExecutor = BuiltInCodeExecutor; exports.BuiltInPlanner = BuiltInPlanner; exports.CallbackContext = CallbackContext; exports.CodeExecutionUtils = CodeExecutionUtils; exports.CodeExecutorContext = CodeExecutorContext; exports.DatabaseSessionService = DatabaseSessionService; exports.EnhancedAuthConfig = EnhancedAuthConfig; exports.EvalResult = EvalResult; exports.EvalStatus = EvalStatus; exports.Evaluation = evaluation_exports; exports.Evaluator = Evaluator; exports.Event = Event; exports.EventActions = EventActions; exports.Events = events_exports; exports.ExitLoopTool = ExitLoopTool; exports.FileOperationsTool = FileOperationsTool; exports.FinalResponseMatchV2Evaluator = FinalResponseMatchV2Evaluator; exports.Flows = flows_exports; exports.FunctionTool = FunctionTool; exports.GcsArtifactService = GcsArtifactService; exports.GetUserChoiceTool = GetUserChoiceTool; exports.GoogleLlm = GoogleLlm; exports.GoogleSearch = GoogleSearch; exports.HttpRequestTool = HttpRequestTool; exports.HttpScheme = HttpScheme; exports.InMemoryArtifactService = InMemoryArtifactService; exports.InMemoryMemoryService = InMemoryMemoryService; exports.InMemoryRunner = InMemoryRunner; exports.InMemorySessionService = InMemorySessionService; exports.InvocationContext = InvocationContext; exports.LLMRegistry = LLMRegistry; exports.LangGraphAgent = LangGraphAgent; exports.LlmAgent = LlmAgent; exports.LlmCallsLimitExceededError = LlmCallsLimitExceededError; exports.LlmEventSummarizer = LlmEventSummarizer; exports.LlmRequest = LlmRequest; exports.LlmResponse = LlmResponse; exports.LoadArtifactsTool = LoadArtifactsTool; exports.LoadMemoryTool = LoadMemoryTool; exports.LocalEvalService = LocalEvalService; exports.LoopAgent = LoopAgent; exports.McpAbi = McpAbi; exports.McpAtp = McpAtp; exports.McpBamm = McpBamm; exports.McpCoinGecko = McpCoinGecko; exports.McpCoinGeckoPro = McpCoinGeckoPro; exports.McpDiscord = McpDiscord; exports.McpError = McpError; exports.McpErrorType = McpErrorType; exports.McpFilesystem = McpFilesystem; exports.McpFraxlend = McpFraxlend; exports.McpGeneric = McpGeneric; exports.McpIqWiki = McpIqWiki; exports.McpMemory = McpMemory; exports.McpNearAgent = McpNearAgent; exports.McpNearIntents = McpNearIntents; exports.McpOdos = McpOdos; exports.McpPolymarket = McpPolymarket; exports.McpSamplingHandler = McpSamplingHandler; exports.McpTelegram = McpTelegram; exports.McpToolset = McpToolset; exports.McpUpbit = McpUpbit; exports.Memory = memory_exports; exports.Models = models_exports; exports.OAuth2Credential = OAuth2Credential; exports.OAuth2Scheme = OAuth2Scheme; exports.OpenAiLlm = OpenAiLlm; exports.OpenIdConnectScheme = OpenIdConnectScheme; exports.ParallelAgent = ParallelAgent; exports.PlanReActPlanner = PlanReActPlanner; exports.PrebuiltMetrics = PrebuiltMetrics; exports.REQUEST_EUC_FUNCTION_CALL_NAME = REQUEST_EUC_FUNCTION_CALL_NAME; exports.ReadonlyContext = ReadonlyContext; exports.RougeEvaluator = RougeEvaluator; exports.RunConfig = RunConfig; exports.Runner = Runner; exports.SafetyEvaluatorV1 = SafetyEvaluatorV1; exports.SequentialAgent = SequentialAgent; exports.Sessions = sessions_exports; exports.SingleFlow = SingleFlow; exports.State = State; exports.StreamingMode = StreamingMode; exports.TelemetryService = TelemetryService; exports.ToolContext = ToolContext; exports.Tools = tools_exports; exports.TrajectoryEvaluator = TrajectoryEvaluator; exports.TransferToAgentTool = TransferToAgentTool; exports.UserInteractionTool = UserInteractionTool; exports.VERSION = VERSION; exports.VertexAiRagMemoryService = VertexAiRagMemoryService; exports.VertexAiSessionService = VertexAiSessionService; exports._findFunctionCallEventIfLastEventIsFunctionResponse = _findFunctionCallEventIfLastEventIsFunctionResponse; exports.adkToMcpToolType = adkToMcpToolType; exports.agentTransferRequestProcessor = requestProcessor8; exports.basicRequestProcessor = requestProcessor2; exports.buildFunctionDeclaration = buildFunctionDeclaration; exports.codeExecutionRequestProcessor = requestProcessor3; exports.codeExecutionResponseProcessor = responseProcessor; exports.contentRequestProcessor = requestProcessor4; exports.convertMcpToolToBaseTool = convertMcpToolToBaseTool; exports.createAuthToolArguments = createAuthToolArguments; exports.createBranchContextForSubAgent = createBranchContextForSubAgent; exports.createDatabaseSessionService = createDatabaseSessionService; exports.createFunctionTool = createFunctionTool; exports.createMysqlSessionService = createMysqlSessionService; exports.createPostgresSessionService = createPostgresSessionService; exports.createSamplingHandler = createSamplingHandler; exports.createSqliteSessionService = createSqliteSessionService; exports.createTool = createTool; exports.generateAuthEvent = generateAuthEvent; exports.generateClientFunctionCallId = generateClientFunctionCallId; exports.getArtifactUri = getArtifactUri; exports.getLongRunningFunctionCalls = getLongRunningFunctionCalls; exports.getMcpTools = getMcpTools; exports.handleFunctionCallsAsync = handleFunctionCallsAsync; exports.handleFunctionCallsLive = handleFunctionCallsLive; exports.identityRequestProcessor = requestProcessor5; exports.initializeTelemetry = initializeTelemetry; exports.injectSessionState = injectSessionState; exports.instructionsRequestProcessor = requestProcessor6; exports.isArtifactRef = isArtifactRef; exports.isEnhancedAuthConfig = isEnhancedAuthConfig; exports.jsonSchemaToDeclaration = jsonSchemaToDeclaration; exports.mcpSchemaToParameters = mcpSchemaToParameters; exports.mergeAgentRun = mergeAgentRun; exports.mergeParallelFunctionResponseEvents = mergeParallelFunctionResponseEvents; exports.newInvocationContextId = newInvocationContextId; exports.nlPlanningRequestProcessor = requestProcessor7; exports.nlPlanningResponseProcessor = responseProcessor2; exports.normalizeJsonSchema = normalizeJsonSchema; exports.parseArtifactUri = parseArtifactUri; exports.populateClientFunctionCallId = populateClientFunctionCallId; exports.registerProviders = registerProviders; exports.removeClientFunctionCallId = removeClientFunctionCallId; exports.requestProcessor = requestProcessor; exports.runCompactionForSlidingWindow = runCompactionForSlidingWindow; exports.shutdownTelemetry = shutdownTelemetry; exports.telemetryService = telemetryService; exports.traceLlmCall = traceLlmCall; exports.traceToolCall = traceToolCall; exports.tracer = tracer;