@iqai/adk 0.5.0 → 0.5.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/CHANGELOG.md +21 -0
- package/dist/index.d.mts +163 -4
- package/dist/index.d.ts +163 -4
- package/dist/index.js +655 -117
- package/dist/index.mjs +557 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3389,6 +3389,15 @@ var EventActions = (_class10 = class {
|
|
|
3389
3389
|
* Requested authentication configurations.
|
|
3390
3390
|
*/
|
|
3391
3391
|
|
|
3392
|
+
/**
|
|
3393
|
+
* Event compaction information. When set, this event represents
|
|
3394
|
+
* a compaction of events within the specified timestamp range.
|
|
3395
|
+
*/
|
|
3396
|
+
|
|
3397
|
+
/**
|
|
3398
|
+
* The invocation id to rewind to. This is only set for rewind event.
|
|
3399
|
+
*/
|
|
3400
|
+
|
|
3392
3401
|
/**
|
|
3393
3402
|
* Constructor for EventActions
|
|
3394
3403
|
*/
|
|
@@ -3399,6 +3408,8 @@ var EventActions = (_class10 = class {
|
|
|
3399
3408
|
this.transferToAgent = options.transferToAgent;
|
|
3400
3409
|
this.escalate = options.escalate;
|
|
3401
3410
|
this.requestedAuthConfigs = options.requestedAuthConfigs;
|
|
3411
|
+
this.compaction = options.compaction;
|
|
3412
|
+
this.rewindBeforeInvocationId = options.rewindBeforeInvocationId;
|
|
3402
3413
|
}
|
|
3403
3414
|
}, _class10);
|
|
3404
3415
|
|
|
@@ -3941,9 +3952,196 @@ init_logger();
|
|
|
3941
3952
|
var events_exports = {};
|
|
3942
3953
|
__export(events_exports, {
|
|
3943
3954
|
Event: () => Event,
|
|
3944
|
-
EventActions: () => EventActions
|
|
3955
|
+
EventActions: () => EventActions,
|
|
3956
|
+
LlmEventSummarizer: () => LlmEventSummarizer,
|
|
3957
|
+
runCompactionForSlidingWindow: () => runCompactionForSlidingWindow
|
|
3945
3958
|
});
|
|
3946
3959
|
|
|
3960
|
+
// src/events/llm-event-summarizer.ts
|
|
3961
|
+
var DEFAULT_SUMMARIZATION_PROMPT = `You are a helpful assistant tasked with summarizing a conversation history.
|
|
3962
|
+
Please provide a concise summary of the following events, capturing the key information and context.
|
|
3963
|
+
Focus on the main topics discussed, important decisions made, and any action items or results.
|
|
3964
|
+
|
|
3965
|
+
Events to summarize:
|
|
3966
|
+
{events}
|
|
3967
|
+
|
|
3968
|
+
Provide your summary in a clear, concise format.`;
|
|
3969
|
+
var LlmEventSummarizer = class {
|
|
3970
|
+
|
|
3971
|
+
|
|
3972
|
+
/**
|
|
3973
|
+
* Creates a new LLM event summarizer.
|
|
3974
|
+
* @param model - The LLM model to use for summarization
|
|
3975
|
+
* @param prompt - Optional custom prompt template. Use {events} as placeholder for event content.
|
|
3976
|
+
*/
|
|
3977
|
+
constructor(model, prompt) {
|
|
3978
|
+
this.model = model;
|
|
3979
|
+
this.prompt = prompt || DEFAULT_SUMMARIZATION_PROMPT;
|
|
3980
|
+
}
|
|
3981
|
+
/**
|
|
3982
|
+
* Summarizes events using the configured LLM.
|
|
3983
|
+
*/
|
|
3984
|
+
async maybeSummarizeEvents(events) {
|
|
3985
|
+
if (!events || events.length === 0) {
|
|
3986
|
+
return void 0;
|
|
3987
|
+
}
|
|
3988
|
+
const eventsText = this.formatEventsForSummarization(events);
|
|
3989
|
+
const promptWithEvents = this.prompt.replace("{events}", eventsText);
|
|
3990
|
+
const llmRequest = new LlmRequest({
|
|
3991
|
+
contents: [
|
|
3992
|
+
{
|
|
3993
|
+
role: "user",
|
|
3994
|
+
parts: [{ text: promptWithEvents }]
|
|
3995
|
+
}
|
|
3996
|
+
]
|
|
3997
|
+
});
|
|
3998
|
+
let summaryText = "";
|
|
3999
|
+
for await (const response of this.model.generateContentAsync(llmRequest)) {
|
|
4000
|
+
summaryText += _optionalChain([response, 'access', _143 => _143.content, 'optionalAccess', _144 => _144.parts, 'optionalAccess', _145 => _145.map, 'call', _146 => _146((part) => part.text || ""), 'access', _147 => _147.join, 'call', _148 => _148("")]);
|
|
4001
|
+
}
|
|
4002
|
+
summaryText = summaryText.trim();
|
|
4003
|
+
if (!summaryText) {
|
|
4004
|
+
return void 0;
|
|
4005
|
+
}
|
|
4006
|
+
const summaryContent = {
|
|
4007
|
+
role: "model",
|
|
4008
|
+
parts: [{ text: summaryText }]
|
|
4009
|
+
};
|
|
4010
|
+
const compactionEvent = new Event({
|
|
4011
|
+
invocationId: Event.newId(),
|
|
4012
|
+
author: "user",
|
|
4013
|
+
actions: new EventActions({
|
|
4014
|
+
compaction: {
|
|
4015
|
+
startTimestamp: events[0].timestamp,
|
|
4016
|
+
endTimestamp: events[events.length - 1].timestamp,
|
|
4017
|
+
compactedContent: summaryContent
|
|
4018
|
+
}
|
|
4019
|
+
})
|
|
4020
|
+
});
|
|
4021
|
+
return compactionEvent;
|
|
4022
|
+
}
|
|
4023
|
+
/**
|
|
4024
|
+
* Formats events into a readable text format for summarization.
|
|
4025
|
+
*/
|
|
4026
|
+
formatEventsForSummarization(events) {
|
|
4027
|
+
const lines = [];
|
|
4028
|
+
for (const event of events) {
|
|
4029
|
+
const timestamp = new Date(event.timestamp * 1e3).toISOString();
|
|
4030
|
+
const author = event.author;
|
|
4031
|
+
if (_optionalChain([event, 'access', _149 => _149.content, 'optionalAccess', _150 => _150.parts])) {
|
|
4032
|
+
for (const part of event.content.parts) {
|
|
4033
|
+
if (part.text) {
|
|
4034
|
+
lines.push(`[${timestamp}] ${author}: ${part.text}`);
|
|
4035
|
+
} else if (part.functionCall) {
|
|
4036
|
+
lines.push(
|
|
4037
|
+
`[${timestamp}] ${author}: Called tool '${part.functionCall.name}' with args ${JSON.stringify(part.functionCall.args)}`
|
|
4038
|
+
);
|
|
4039
|
+
} else if (part.functionResponse) {
|
|
4040
|
+
lines.push(
|
|
4041
|
+
`[${timestamp}] ${author}: Tool '${part.functionResponse.name}' returned: ${JSON.stringify(part.functionResponse.response)}`
|
|
4042
|
+
);
|
|
4043
|
+
}
|
|
4044
|
+
}
|
|
4045
|
+
}
|
|
4046
|
+
}
|
|
4047
|
+
return lines.join("\n");
|
|
4048
|
+
}
|
|
4049
|
+
};
|
|
4050
|
+
|
|
4051
|
+
// src/events/compaction.ts
|
|
4052
|
+
init_logger();
|
|
4053
|
+
var logger = new Logger({ name: "EventCompaction" });
|
|
4054
|
+
async function runCompactionForSlidingWindow(config, session, sessionService, summarizer) {
|
|
4055
|
+
if (!session.events || session.events.length === 0) {
|
|
4056
|
+
return;
|
|
4057
|
+
}
|
|
4058
|
+
const lastCompactedEndTimestamp = findLastCompactedEndTimestamp(
|
|
4059
|
+
session.events
|
|
4060
|
+
);
|
|
4061
|
+
const latestTimestampByInvocation = buildLatestTimestampByInvocation(
|
|
4062
|
+
session.events
|
|
4063
|
+
);
|
|
4064
|
+
const uniqueInvocationIds = Array.from(latestTimestampByInvocation.keys());
|
|
4065
|
+
const newInvocationIds = uniqueInvocationIds.filter(
|
|
4066
|
+
(invId) => (latestTimestampByInvocation.get(invId) || 0) > lastCompactedEndTimestamp
|
|
4067
|
+
);
|
|
4068
|
+
if (newInvocationIds.length < config.compactionInterval) {
|
|
4069
|
+
logger.debug(
|
|
4070
|
+
`Not enough new invocations for compaction. Need ${config.compactionInterval}, have ${newInvocationIds.length}`
|
|
4071
|
+
);
|
|
4072
|
+
return;
|
|
4073
|
+
}
|
|
4074
|
+
const endInvId = newInvocationIds[newInvocationIds.length - 1];
|
|
4075
|
+
const firstNewInvId = newInvocationIds[0];
|
|
4076
|
+
const firstNewInvIdx = uniqueInvocationIds.indexOf(firstNewInvId);
|
|
4077
|
+
const startIdx = Math.max(0, firstNewInvIdx - config.overlapSize);
|
|
4078
|
+
const startInvId = uniqueInvocationIds[startIdx];
|
|
4079
|
+
logger.debug(
|
|
4080
|
+
`Compacting invocations from ${startInvId} to ${endInvId} (${newInvocationIds.length} new invocations, overlap: ${config.overlapSize})`
|
|
4081
|
+
);
|
|
4082
|
+
const eventsToCompact = sliceEventsByInvocationRange(
|
|
4083
|
+
session.events,
|
|
4084
|
+
startInvId,
|
|
4085
|
+
endInvId
|
|
4086
|
+
);
|
|
4087
|
+
if (eventsToCompact.length === 0) {
|
|
4088
|
+
logger.debug("No events to compact after filtering");
|
|
4089
|
+
return;
|
|
4090
|
+
}
|
|
4091
|
+
logger.debug(`Summarizing ${eventsToCompact.length} events`);
|
|
4092
|
+
const compactionEvent = await summarizer.maybeSummarizeEvents(eventsToCompact);
|
|
4093
|
+
if (compactionEvent) {
|
|
4094
|
+
logger.debug(
|
|
4095
|
+
`Compaction created covering timestamps ${_optionalChain([compactionEvent, 'access', _151 => _151.actions, 'access', _152 => _152.compaction, 'optionalAccess', _153 => _153.startTimestamp])} to ${_optionalChain([compactionEvent, 'access', _154 => _154.actions, 'access', _155 => _155.compaction, 'optionalAccess', _156 => _156.endTimestamp])}`
|
|
4096
|
+
);
|
|
4097
|
+
await sessionService.appendEvent(session, compactionEvent);
|
|
4098
|
+
}
|
|
4099
|
+
}
|
|
4100
|
+
function findLastCompactedEndTimestamp(events) {
|
|
4101
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
4102
|
+
const event = events[i];
|
|
4103
|
+
if (_optionalChain([event, 'access', _157 => _157.actions, 'optionalAccess', _158 => _158.compaction])) {
|
|
4104
|
+
return event.actions.compaction.endTimestamp;
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
4107
|
+
return 0;
|
|
4108
|
+
}
|
|
4109
|
+
function buildLatestTimestampByInvocation(events) {
|
|
4110
|
+
const latestByInvocation = /* @__PURE__ */ new Map();
|
|
4111
|
+
for (const event of events) {
|
|
4112
|
+
if (_optionalChain([event, 'access', _159 => _159.actions, 'optionalAccess', _160 => _160.compaction])) {
|
|
4113
|
+
continue;
|
|
4114
|
+
}
|
|
4115
|
+
const invId = event.invocationId;
|
|
4116
|
+
if (!invId) {
|
|
4117
|
+
continue;
|
|
4118
|
+
}
|
|
4119
|
+
const current = latestByInvocation.get(invId) || 0;
|
|
4120
|
+
if (event.timestamp > current) {
|
|
4121
|
+
latestByInvocation.set(invId, event.timestamp);
|
|
4122
|
+
}
|
|
4123
|
+
}
|
|
4124
|
+
return latestByInvocation;
|
|
4125
|
+
}
|
|
4126
|
+
function sliceEventsByInvocationRange(events, startInvId, endInvId) {
|
|
4127
|
+
let firstIndex = -1;
|
|
4128
|
+
let lastIndex = -1;
|
|
4129
|
+
for (let i = 0; i < events.length; i++) {
|
|
4130
|
+
const event = events[i];
|
|
4131
|
+
if (event.invocationId === startInvId && firstIndex === -1) {
|
|
4132
|
+
firstIndex = i;
|
|
4133
|
+
}
|
|
4134
|
+
if (event.invocationId === endInvId) {
|
|
4135
|
+
lastIndex = i;
|
|
4136
|
+
}
|
|
4137
|
+
}
|
|
4138
|
+
if (firstIndex === -1 || lastIndex === -1 || firstIndex > lastIndex) {
|
|
4139
|
+
return [];
|
|
4140
|
+
}
|
|
4141
|
+
const slicedEvents = events.slice(firstIndex, lastIndex + 1);
|
|
4142
|
+
return slicedEvents.filter((event) => !_optionalChain([event, 'access', _161 => _161.actions, 'optionalAccess', _162 => _162.compaction]));
|
|
4143
|
+
}
|
|
4144
|
+
|
|
3947
4145
|
// src/flows/llm-flows/base-llm-flow.ts
|
|
3948
4146
|
init_logger();
|
|
3949
4147
|
|
|
@@ -4454,7 +4652,7 @@ var AgentTool = (_class15 = class extends BaseTool {
|
|
|
4454
4652
|
} catch (e3) {
|
|
4455
4653
|
toolResult = mergedText;
|
|
4456
4654
|
}
|
|
4457
|
-
if (this.outputKey && _optionalChain([context4, 'optionalAccess',
|
|
4655
|
+
if (this.outputKey && _optionalChain([context4, 'optionalAccess', _163 => _163.state])) {
|
|
4458
4656
|
context4.state[this.outputKey] = toolResult;
|
|
4459
4657
|
}
|
|
4460
4658
|
return toolResult;
|
|
@@ -4721,7 +4919,7 @@ var FileOperationsTool = class extends BaseTool {
|
|
|
4721
4919
|
name: "file_operations",
|
|
4722
4920
|
description: "Perform file system operations like reading, writing, and managing files"
|
|
4723
4921
|
});
|
|
4724
|
-
this.basePath = _optionalChain([options, 'optionalAccess',
|
|
4922
|
+
this.basePath = _optionalChain([options, 'optionalAccess', _164 => _164.basePath]) || process.cwd();
|
|
4725
4923
|
}
|
|
4726
4924
|
/**
|
|
4727
4925
|
* Get the function declaration for the tool
|
|
@@ -5204,7 +5402,7 @@ var LoadMemoryTool = (_class20 = class extends BaseTool {
|
|
|
5204
5402
|
const searchResult = await context4.searchMemory(args.query);
|
|
5205
5403
|
return {
|
|
5206
5404
|
memories: searchResult.memories || [],
|
|
5207
|
-
count: _optionalChain([searchResult, 'access',
|
|
5405
|
+
count: _optionalChain([searchResult, 'access', _165 => _165.memories, 'optionalAccess', _166 => _166.length]) || 0
|
|
5208
5406
|
};
|
|
5209
5407
|
} catch (error) {
|
|
5210
5408
|
console.error("Error searching memory:", error);
|
|
@@ -5761,7 +5959,7 @@ var McpClientService = (_class22 = class {
|
|
|
5761
5959
|
},
|
|
5762
5960
|
this,
|
|
5763
5961
|
async (instance) => await instance.reinitialize(),
|
|
5764
|
-
_optionalChain([this, 'access',
|
|
5962
|
+
_optionalChain([this, 'access', _167 => _167.config, 'access', _168 => _168.retryOptions, 'optionalAccess', _169 => _169.maxRetries]) || 2
|
|
5765
5963
|
);
|
|
5766
5964
|
return await wrappedCall();
|
|
5767
5965
|
} catch (error) {
|
|
@@ -5845,7 +6043,7 @@ var McpClientService = (_class22 = class {
|
|
|
5845
6043
|
this.mcpSamplingHandler = null;
|
|
5846
6044
|
if (this.client) {
|
|
5847
6045
|
try {
|
|
5848
|
-
_optionalChain([this, 'access',
|
|
6046
|
+
_optionalChain([this, 'access', _170 => _170.client, 'access', _171 => _171.removeRequestHandler, 'optionalCall', _172 => _172("sampling/createMessage")]);
|
|
5849
6047
|
} catch (error) {
|
|
5850
6048
|
this.logger.error("Failed to remove sampling handler:", error);
|
|
5851
6049
|
}
|
|
@@ -6381,7 +6579,7 @@ var McpToolset = (_class24 = class {
|
|
|
6381
6579
|
"resource_closed_error" /* RESOURCE_CLOSED_ERROR */
|
|
6382
6580
|
);
|
|
6383
6581
|
}
|
|
6384
|
-
if (this.tools.length > 0 && !_optionalChain([this, 'access',
|
|
6582
|
+
if (this.tools.length > 0 && !_optionalChain([this, 'access', _173 => _173.config, 'access', _174 => _174.cacheConfig, 'optionalAccess', _175 => _175.enabled]) === false) {
|
|
6385
6583
|
return this.tools;
|
|
6386
6584
|
}
|
|
6387
6585
|
if (!this.clientService) {
|
|
@@ -6410,7 +6608,7 @@ var McpToolset = (_class24 = class {
|
|
|
6410
6608
|
}
|
|
6411
6609
|
}
|
|
6412
6610
|
}
|
|
6413
|
-
if (_optionalChain([this, 'access',
|
|
6611
|
+
if (_optionalChain([this, 'access', _176 => _176.config, 'access', _177 => _177.cacheConfig, 'optionalAccess', _178 => _178.enabled]) !== false) {
|
|
6414
6612
|
this.tools = tools;
|
|
6415
6613
|
}
|
|
6416
6614
|
return tools;
|
|
@@ -6499,12 +6697,12 @@ function populateClientFunctionCallId(modelResponseEvent) {
|
|
|
6499
6697
|
}
|
|
6500
6698
|
}
|
|
6501
6699
|
function removeClientFunctionCallId(content) {
|
|
6502
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
6700
|
+
if (_optionalChain([content, 'optionalAccess', _179 => _179.parts])) {
|
|
6503
6701
|
for (const part of content.parts) {
|
|
6504
|
-
if (_optionalChain([part, 'access',
|
|
6702
|
+
if (_optionalChain([part, 'access', _180 => _180.functionCall, 'optionalAccess', _181 => _181.id, 'optionalAccess', _182 => _182.startsWith, 'call', _183 => _183(AF_FUNCTION_CALL_ID_PREFIX)])) {
|
|
6505
6703
|
part.functionCall.id = void 0;
|
|
6506
6704
|
}
|
|
6507
|
-
if (_optionalChain([part, 'access',
|
|
6705
|
+
if (_optionalChain([part, 'access', _184 => _184.functionResponse, 'optionalAccess', _185 => _185.id, 'optionalAccess', _186 => _186.startsWith, 'call', _187 => _187(AF_FUNCTION_CALL_ID_PREFIX)])) {
|
|
6508
6706
|
part.functionResponse.id = void 0;
|
|
6509
6707
|
}
|
|
6510
6708
|
}
|
|
@@ -6699,7 +6897,7 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
|
|
|
6699
6897
|
}
|
|
6700
6898
|
const mergedParts = [];
|
|
6701
6899
|
for (const event of functionResponseEvents) {
|
|
6702
|
-
if (_optionalChain([event, 'access',
|
|
6900
|
+
if (_optionalChain([event, 'access', _188 => _188.content, 'optionalAccess', _189 => _189.parts])) {
|
|
6703
6901
|
for (const part of event.content.parts) {
|
|
6704
6902
|
mergedParts.push(part);
|
|
6705
6903
|
}
|
|
@@ -6820,7 +7018,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6820
7018
|
const seen = /* @__PURE__ */ new Set();
|
|
6821
7019
|
const filtered = [];
|
|
6822
7020
|
for (const t of tools) {
|
|
6823
|
-
const name = _optionalChain([t, 'optionalAccess',
|
|
7021
|
+
const name = _optionalChain([t, 'optionalAccess', _190 => _190.name]);
|
|
6824
7022
|
if (!name) continue;
|
|
6825
7023
|
if (seen.has(name)) {
|
|
6826
7024
|
continue;
|
|
@@ -6837,7 +7035,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6837
7035
|
if (tools.length > 0) {
|
|
6838
7036
|
const toolsData = tools.map((tool) => ({
|
|
6839
7037
|
Name: tool.name,
|
|
6840
|
-
Description: _optionalChain([tool, 'access',
|
|
7038
|
+
Description: _optionalChain([tool, 'access', _191 => _191.description, 'optionalAccess', _192 => _192.substring, 'call', _193 => _193(0, 50)]) + (_optionalChain([tool, 'access', _194 => _194.description, 'optionalAccess', _195 => _195.length]) > 50 ? "..." : ""),
|
|
6841
7039
|
"Long Running": tool.isLongRunning ? "Yes" : "No"
|
|
6842
7040
|
}));
|
|
6843
7041
|
this.logger.debugArray("\u{1F6E0}\uFE0F Available Tools", toolsData);
|
|
@@ -6900,14 +7098,14 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6900
7098
|
);
|
|
6901
7099
|
if (functionResponseEvent) {
|
|
6902
7100
|
yield functionResponseEvent;
|
|
6903
|
-
const transferToAgent = _optionalChain([functionResponseEvent, 'access',
|
|
7101
|
+
const transferToAgent = _optionalChain([functionResponseEvent, 'access', _196 => _196.actions, 'optionalAccess', _197 => _197.transferToAgent]);
|
|
6904
7102
|
if (transferToAgent) {
|
|
6905
7103
|
this.logger.debug(`\u{1F504} Live transfer to agent '${transferToAgent}'`);
|
|
6906
7104
|
const agentToRun = this._getAgentToRun(
|
|
6907
7105
|
invocationContext,
|
|
6908
7106
|
transferToAgent
|
|
6909
7107
|
);
|
|
6910
|
-
for await (const event of _optionalChain([agentToRun, 'access',
|
|
7108
|
+
for await (const event of _optionalChain([agentToRun, 'access', _198 => _198.runLive, 'optionalCall', _199 => _199(invocationContext)]) || agentToRun.runAsync(invocationContext)) {
|
|
6911
7109
|
yield event;
|
|
6912
7110
|
}
|
|
6913
7111
|
}
|
|
@@ -6939,7 +7137,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6939
7137
|
yield authEvent;
|
|
6940
7138
|
}
|
|
6941
7139
|
yield functionResponseEvent;
|
|
6942
|
-
const transferToAgent = _optionalChain([functionResponseEvent, 'access',
|
|
7140
|
+
const transferToAgent = _optionalChain([functionResponseEvent, 'access', _200 => _200.actions, 'optionalAccess', _201 => _201.transferToAgent]);
|
|
6943
7141
|
if (transferToAgent) {
|
|
6944
7142
|
this.logger.debug(`\u{1F504} Transferring to agent '${transferToAgent}'`);
|
|
6945
7143
|
const agentToRun = this._getAgentToRun(
|
|
@@ -6985,7 +7183,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6985
7183
|
}
|
|
6986
7184
|
invocationContext.incrementLlmCallCount();
|
|
6987
7185
|
const isStreaming = invocationContext.runConfig.streamingMode === "sse" /* SSE */;
|
|
6988
|
-
let tools = _optionalChain([llmRequest, 'access',
|
|
7186
|
+
let tools = _optionalChain([llmRequest, 'access', _202 => _202.config, 'optionalAccess', _203 => _203.tools]) || [];
|
|
6989
7187
|
if (tools.length) {
|
|
6990
7188
|
const deduped = [];
|
|
6991
7189
|
const seenFn = /* @__PURE__ */ new Set();
|
|
@@ -6994,7 +7192,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6994
7192
|
if (tool && Array.isArray(tool.functionDeclarations)) {
|
|
6995
7193
|
const newFds = tool.functionDeclarations.filter(
|
|
6996
7194
|
(fd) => {
|
|
6997
|
-
if (_optionalChain([fd, 'optionalAccess',
|
|
7195
|
+
if (_optionalChain([fd, 'optionalAccess', _204 => _204.name])) {
|
|
6998
7196
|
if (seenFn.has(fd.name)) {
|
|
6999
7197
|
return false;
|
|
7000
7198
|
}
|
|
@@ -7006,7 +7204,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
7006
7204
|
if (newFds.length) {
|
|
7007
7205
|
deduped.push({ ...tool, functionDeclarations: newFds });
|
|
7008
7206
|
}
|
|
7009
|
-
} else if (_optionalChain([tool, 'optionalAccess',
|
|
7207
|
+
} else if (_optionalChain([tool, 'optionalAccess', _205 => _205.name])) {
|
|
7010
7208
|
if (seenFn.has(tool.name)) continue;
|
|
7011
7209
|
seenFn.add(tool.name);
|
|
7012
7210
|
deduped.push(tool);
|
|
@@ -7026,21 +7224,21 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
7026
7224
|
return tool.functionDeclarations.map((fn) => fn.name).join(", ");
|
|
7027
7225
|
}
|
|
7028
7226
|
if (tool.name) return tool.name;
|
|
7029
|
-
if (_optionalChain([tool, 'access',
|
|
7030
|
-
if (_optionalChain([tool, 'access',
|
|
7227
|
+
if (_optionalChain([tool, 'access', _206 => _206.function, 'optionalAccess', _207 => _207.name])) return tool.function.name;
|
|
7228
|
+
if (_optionalChain([tool, 'access', _208 => _208.function, 'optionalAccess', _209 => _209.function, 'optionalAccess', _210 => _210.name])) return tool.function.function.name;
|
|
7031
7229
|
return "unknown";
|
|
7032
7230
|
}).join(", ");
|
|
7033
7231
|
const systemInstruction = llmRequest.getSystemInstructionText() || "";
|
|
7034
7232
|
const truncatedSystemInstruction = systemInstruction.length > 100 ? `${systemInstruction.substring(0, 100)}...` : systemInstruction;
|
|
7035
|
-
const contentPreview = _optionalChain([llmRequest, 'access',
|
|
7233
|
+
const contentPreview = _optionalChain([llmRequest, 'access', _211 => _211.contents, 'optionalAccess', _212 => _212.length]) > 0 ? LogFormatter.formatContentPreview(llmRequest.contents[0]) : "none";
|
|
7036
7234
|
this.logger.debugStructured("\u{1F4E4} LLM Request", {
|
|
7037
7235
|
Model: llm.model,
|
|
7038
7236
|
Agent: invocationContext.agent.name,
|
|
7039
|
-
"Content Items": _optionalChain([llmRequest, 'access',
|
|
7237
|
+
"Content Items": _optionalChain([llmRequest, 'access', _213 => _213.contents, 'optionalAccess', _214 => _214.length]) || 0,
|
|
7040
7238
|
"Content Preview": contentPreview,
|
|
7041
7239
|
"System Instruction": truncatedSystemInstruction || "none",
|
|
7042
7240
|
"Available Tools": toolNames || "none",
|
|
7043
|
-
"Tool Count": _optionalChain([llmRequest, 'access',
|
|
7241
|
+
"Tool Count": _optionalChain([llmRequest, 'access', _215 => _215.config, 'optionalAccess', _216 => _216.tools, 'optionalAccess', _217 => _217.length]) || 0,
|
|
7044
7242
|
Streaming: isStreaming ? "Yes" : "No"
|
|
7045
7243
|
});
|
|
7046
7244
|
let responseCount = 0;
|
|
@@ -7055,8 +7253,8 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
7055
7253
|
llmRequest,
|
|
7056
7254
|
llmResponse
|
|
7057
7255
|
);
|
|
7058
|
-
const tokenCount = _optionalChain([llmResponse, 'access',
|
|
7059
|
-
const functionCalls = _optionalChain([llmResponse, 'access',
|
|
7256
|
+
const tokenCount = _optionalChain([llmResponse, 'access', _218 => _218.usageMetadata, 'optionalAccess', _219 => _219.totalTokenCount]) || "unknown";
|
|
7257
|
+
const functionCalls = _optionalChain([llmResponse, 'access', _220 => _220.content, 'optionalAccess', _221 => _221.parts, 'optionalAccess', _222 => _222.filter, 'call', _223 => _223((part) => part.functionCall)]) || [];
|
|
7060
7258
|
const functionCallsDisplay = LogFormatter.formatFunctionCalls(functionCalls);
|
|
7061
7259
|
const responsePreview = LogFormatter.formatResponsePreview(llmResponse);
|
|
7062
7260
|
this.logger.debugStructured("\u{1F4E5} LLM Response", {
|
|
@@ -7200,7 +7398,7 @@ var EnhancedAuthConfig = class {
|
|
|
7200
7398
|
*/
|
|
7201
7399
|
generateCredentialKey() {
|
|
7202
7400
|
const schemeKey = this.authScheme.type || "unknown";
|
|
7203
|
-
const credentialKey = _optionalChain([this, 'access',
|
|
7401
|
+
const credentialKey = _optionalChain([this, 'access', _224 => _224.rawAuthCredential, 'optionalAccess', _225 => _225.type]) || "none";
|
|
7204
7402
|
const timestamp = Date.now();
|
|
7205
7403
|
return `adk_${schemeKey}_${credentialKey}_${timestamp}`;
|
|
7206
7404
|
}
|
|
@@ -7357,7 +7555,7 @@ var AuthLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
7357
7555
|
*/
|
|
7358
7556
|
parseAndStoreAuthResponse(authHandler, invocationContext) {
|
|
7359
7557
|
try {
|
|
7360
|
-
const credentialKey = _optionalChain([authHandler, 'access',
|
|
7558
|
+
const credentialKey = _optionalChain([authHandler, 'access', _226 => _226.authConfig, 'access', _227 => _227.context, 'optionalAccess', _228 => _228.credentialKey]) || `temp:${Date.now()}`;
|
|
7361
7559
|
const fullCredentialKey = credentialKey.startsWith("temp:") ? credentialKey : `temp:${credentialKey}`;
|
|
7362
7560
|
invocationContext.session.state[fullCredentialKey] = authHandler.credential;
|
|
7363
7561
|
if (authHandler.authConfig.authScheme.type === "oauth2" || authHandler.authConfig.authScheme.type === "openIdConnect") {
|
|
@@ -7386,15 +7584,15 @@ var BasicLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
7386
7584
|
llmRequest.config = {};
|
|
7387
7585
|
}
|
|
7388
7586
|
if (agent.outputSchema) {
|
|
7389
|
-
const hasTools = await _asyncOptionalChain([(await _optionalChain([agent, 'access',
|
|
7587
|
+
const hasTools = await _asyncOptionalChain([(await _optionalChain([agent, 'access', _229 => _229.canonicalTools, 'optionalCall', _230 => _230(invocationContext)])), 'optionalAccess', async _231 => _231.length]) > 0;
|
|
7390
7588
|
const hasTransfers = !!("subAgents" in agent && agent.subAgents && agent.subAgents.length > 0 && !(agent.disallowTransferToParent && agent.disallowTransferToPeers));
|
|
7391
7589
|
if (!hasTools && !hasTransfers) {
|
|
7392
7590
|
llmRequest.setOutputSchema(agent.outputSchema);
|
|
7393
7591
|
} else {
|
|
7394
7592
|
(() => {
|
|
7395
7593
|
try {
|
|
7396
|
-
const
|
|
7397
|
-
|
|
7594
|
+
const logger2 = new Logger({ name: "BasicLlmRequestProcessor" });
|
|
7595
|
+
logger2.debug(
|
|
7398
7596
|
`Skipping request-level output schema for agent ${agent.name} because tools/transfers are present. Schema will be validated during response processing.`
|
|
7399
7597
|
);
|
|
7400
7598
|
} catch (e) {
|
|
@@ -7478,7 +7676,7 @@ var BuiltInCodeExecutor = class extends BaseCodeExecutor {
|
|
|
7478
7676
|
* Pre-process the LLM request for Gemini 2.0+ models to use the code execution tool
|
|
7479
7677
|
*/
|
|
7480
7678
|
processLlmRequest(llmRequest) {
|
|
7481
|
-
if (!_optionalChain([llmRequest, 'access',
|
|
7679
|
+
if (!_optionalChain([llmRequest, 'access', _232 => _232.model, 'optionalAccess', _233 => _233.startsWith, 'call', _234 => _234("gemini-2")])) {
|
|
7482
7680
|
throw new Error(
|
|
7483
7681
|
`Gemini code execution tool is not supported for model ${llmRequest.model}`
|
|
7484
7682
|
);
|
|
@@ -7523,7 +7721,7 @@ var CodeExecutionUtils = class _CodeExecutionUtils {
|
|
|
7523
7721
|
* Extracts the first code block from the content and truncates everything after it
|
|
7524
7722
|
*/
|
|
7525
7723
|
static extractCodeAndTruncateContent(content, codeBlockDelimiters) {
|
|
7526
|
-
if (!_optionalChain([content, 'optionalAccess',
|
|
7724
|
+
if (!_optionalChain([content, 'optionalAccess', _235 => _235.parts, 'optionalAccess', _236 => _236.length])) {
|
|
7527
7725
|
return null;
|
|
7528
7726
|
}
|
|
7529
7727
|
for (let idx = 0; idx < content.parts.length; idx++) {
|
|
@@ -7609,7 +7807,7 @@ ${fileNames}`);
|
|
|
7609
7807
|
* Converts the code execution parts to text parts in a Content
|
|
7610
7808
|
*/
|
|
7611
7809
|
static convertCodeExecutionParts(content, codeBlockDelimiter, executionResultDelimiters) {
|
|
7612
|
-
if (!_optionalChain([content, 'access',
|
|
7810
|
+
if (!_optionalChain([content, 'access', _237 => _237.parts, 'optionalAccess', _238 => _238.length])) {
|
|
7613
7811
|
return;
|
|
7614
7812
|
}
|
|
7615
7813
|
const lastPart = content.parts[content.parts.length - 1];
|
|
@@ -8002,7 +8200,7 @@ async function* runPostProcessor(invocationContext, llmResponse) {
|
|
|
8002
8200
|
function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
|
|
8003
8201
|
const allInputFiles = codeExecutorContext.getInputFiles();
|
|
8004
8202
|
const savedFileNames = new Set(allInputFiles.map((f) => f.name));
|
|
8005
|
-
for (let i = 0; i < (_optionalChain([llmRequest, 'access',
|
|
8203
|
+
for (let i = 0; i < (_optionalChain([llmRequest, 'access', _239 => _239.contents, 'optionalAccess', _240 => _240.length]) || 0); i++) {
|
|
8006
8204
|
const content = llmRequest.contents[i];
|
|
8007
8205
|
if (content.role !== "user" || !content.parts) {
|
|
8008
8206
|
continue;
|
|
@@ -8034,7 +8232,7 @@ Available file: \`${fileName}\`
|
|
|
8034
8232
|
}
|
|
8035
8233
|
function getOrSetExecutionId(invocationContext, codeExecutorContext) {
|
|
8036
8234
|
const agent = invocationContext.agent;
|
|
8037
|
-
if (!hasCodeExecutor(agent) || !_optionalChain([agent, 'access',
|
|
8235
|
+
if (!hasCodeExecutor(agent) || !_optionalChain([agent, 'access', _241 => _241.codeExecutor, 'optionalAccess', _242 => _242.stateful])) {
|
|
8038
8236
|
return void 0;
|
|
8039
8237
|
}
|
|
8040
8238
|
let executionId = codeExecutorContext.getExecutionId();
|
|
@@ -8265,7 +8463,7 @@ function rearrangeEventsForLatestFunctionResponse(events) {
|
|
|
8265
8463
|
continue;
|
|
8266
8464
|
}
|
|
8267
8465
|
const functionResponses2 = event.getFunctionResponses();
|
|
8268
|
-
if (_optionalChain([functionResponses2, 'optionalAccess',
|
|
8466
|
+
if (_optionalChain([functionResponses2, 'optionalAccess', _243 => _243.some, 'call', _244 => _244((fr) => fr.id && functionResponsesIds.has(fr.id))])) {
|
|
8269
8467
|
functionResponseEvents.push(event);
|
|
8270
8468
|
}
|
|
8271
8469
|
}
|
|
@@ -8275,8 +8473,30 @@ function rearrangeEventsForLatestFunctionResponse(events) {
|
|
|
8275
8473
|
return resultEvents;
|
|
8276
8474
|
}
|
|
8277
8475
|
function getContents(currentBranch, events, agentName = "") {
|
|
8476
|
+
const invocationIdToIndex = /* @__PURE__ */ new Map();
|
|
8477
|
+
for (let idx = 0; idx < events.length; idx++) {
|
|
8478
|
+
if (events[idx].invocationId) {
|
|
8479
|
+
invocationIdToIndex.set(events[idx].invocationId, idx);
|
|
8480
|
+
}
|
|
8481
|
+
}
|
|
8482
|
+
const rewindFilteredEvents = [];
|
|
8483
|
+
let i = events.length - 1;
|
|
8484
|
+
while (i >= 0) {
|
|
8485
|
+
const event = events[i];
|
|
8486
|
+
if (_optionalChain([event, 'access', _245 => _245.actions, 'optionalAccess', _246 => _246.rewindBeforeInvocationId])) {
|
|
8487
|
+
const rewindInvocationId = event.actions.rewindBeforeInvocationId;
|
|
8488
|
+
const rewindIndex = invocationIdToIndex.get(rewindInvocationId);
|
|
8489
|
+
if (rewindIndex !== void 0 && rewindIndex < i) {
|
|
8490
|
+
i = rewindIndex;
|
|
8491
|
+
}
|
|
8492
|
+
} else {
|
|
8493
|
+
rewindFilteredEvents.push(event);
|
|
8494
|
+
}
|
|
8495
|
+
i--;
|
|
8496
|
+
}
|
|
8497
|
+
rewindFilteredEvents.reverse();
|
|
8278
8498
|
const filteredEvents = [];
|
|
8279
|
-
for (const event of
|
|
8499
|
+
for (const event of rewindFilteredEvents) {
|
|
8280
8500
|
if (!event.content || !event.content.role || !event.content.parts || event.content.parts.length === 0) {
|
|
8281
8501
|
continue;
|
|
8282
8502
|
}
|
|
@@ -8296,7 +8516,8 @@ function getContents(currentBranch, events, agentName = "") {
|
|
|
8296
8516
|
isOtherAgentReply(agentName, event) ? convertForeignEvent(event) : event
|
|
8297
8517
|
);
|
|
8298
8518
|
}
|
|
8299
|
-
|
|
8519
|
+
const processedEvents = processCompactionEvents(filteredEvents);
|
|
8520
|
+
let resultEvents = rearrangeEventsForLatestFunctionResponse(processedEvents);
|
|
8300
8521
|
resultEvents = rearrangeEventsForAsyncFunctionResponsesInHistory(resultEvents);
|
|
8301
8522
|
const contents = [];
|
|
8302
8523
|
for (const event of resultEvents) {
|
|
@@ -8364,7 +8585,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
|
|
|
8364
8585
|
const partIndicesInMergedEvent = {};
|
|
8365
8586
|
for (let idx = 0; idx < partsInMergedEvent.length; idx++) {
|
|
8366
8587
|
const part = partsInMergedEvent[idx];
|
|
8367
|
-
if (_optionalChain([part, 'access',
|
|
8588
|
+
if (_optionalChain([part, 'access', _247 => _247.functionResponse, 'optionalAccess', _248 => _248.id])) {
|
|
8368
8589
|
partIndicesInMergedEvent[part.functionResponse.id] = idx;
|
|
8369
8590
|
}
|
|
8370
8591
|
}
|
|
@@ -8373,7 +8594,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
|
|
|
8373
8594
|
throw new Error("There should be at least one function_response part.");
|
|
8374
8595
|
}
|
|
8375
8596
|
for (const part of event.content.parts) {
|
|
8376
|
-
if (_optionalChain([part, 'access',
|
|
8597
|
+
if (_optionalChain([part, 'access', _249 => _249.functionResponse, 'optionalAccess', _250 => _250.id])) {
|
|
8377
8598
|
const functionCallId = part.functionResponse.id;
|
|
8378
8599
|
if (functionCallId in partIndicesInMergedEvent) {
|
|
8379
8600
|
partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] = part;
|
|
@@ -8408,6 +8629,31 @@ function isAuthEvent(event) {
|
|
|
8408
8629
|
}
|
|
8409
8630
|
return false;
|
|
8410
8631
|
}
|
|
8632
|
+
function processCompactionEvents(events) {
|
|
8633
|
+
const result = [];
|
|
8634
|
+
let lastCompactionStartTime = Number.POSITIVE_INFINITY;
|
|
8635
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
8636
|
+
const event = events[i];
|
|
8637
|
+
if (_optionalChain([event, 'access', _251 => _251.actions, 'optionalAccess', _252 => _252.compaction])) {
|
|
8638
|
+
const compaction = event.actions.compaction;
|
|
8639
|
+
const synthesizedEvent = new Event({
|
|
8640
|
+
timestamp: compaction.endTimestamp,
|
|
8641
|
+
author: "model",
|
|
8642
|
+
content: compaction.compactedContent,
|
|
8643
|
+
branch: event.branch,
|
|
8644
|
+
invocationId: event.invocationId
|
|
8645
|
+
});
|
|
8646
|
+
result.unshift(synthesizedEvent);
|
|
8647
|
+
lastCompactionStartTime = Math.min(
|
|
8648
|
+
lastCompactionStartTime,
|
|
8649
|
+
compaction.startTimestamp
|
|
8650
|
+
);
|
|
8651
|
+
} else if (event.timestamp < lastCompactionStartTime) {
|
|
8652
|
+
result.unshift(event);
|
|
8653
|
+
}
|
|
8654
|
+
}
|
|
8655
|
+
return result;
|
|
8656
|
+
}
|
|
8411
8657
|
|
|
8412
8658
|
// src/flows/llm-flows/identity.ts
|
|
8413
8659
|
var IdentityLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
@@ -8640,7 +8886,7 @@ var PlanReActPlanner = class extends BasePlanner {
|
|
|
8640
8886
|
let firstFcPartIndex = -1;
|
|
8641
8887
|
for (let i = 0; i < responseParts.length; i++) {
|
|
8642
8888
|
if (responseParts[i].functionCall) {
|
|
8643
|
-
if (!_optionalChain([responseParts, 'access',
|
|
8889
|
+
if (!_optionalChain([responseParts, 'access', _253 => _253[i], 'access', _254 => _254.functionCall, 'optionalAccess', _255 => _255.name])) {
|
|
8644
8890
|
continue;
|
|
8645
8891
|
}
|
|
8646
8892
|
preservedParts.push(responseParts[i]);
|
|
@@ -8679,7 +8925,7 @@ var PlanReActPlanner = class extends BasePlanner {
|
|
|
8679
8925
|
* Handles non-function-call parts of the response
|
|
8680
8926
|
*/
|
|
8681
8927
|
_handleNonFunctionCallParts(responsePart, preservedParts) {
|
|
8682
|
-
if (_optionalChain([responsePart, 'access',
|
|
8928
|
+
if (_optionalChain([responsePart, 'access', _256 => _256.text, 'optionalAccess', _257 => _257.includes, 'call', _258 => _258(FINAL_ANSWER_TAG)])) {
|
|
8683
8929
|
const [reasoningText, finalAnswerText] = this._splitByLastPattern(
|
|
8684
8930
|
responsePart.text,
|
|
8685
8931
|
FINAL_ANSWER_TAG
|
|
@@ -8777,14 +9023,7 @@ var NlPlanningRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
8777
9023
|
llmRequest
|
|
8778
9024
|
);
|
|
8779
9025
|
if (planningInstruction) {
|
|
8780
|
-
|
|
8781
|
-
llmRequest.appendInstructions([planningInstruction]);
|
|
8782
|
-
} else {
|
|
8783
|
-
const existingInstructions = llmRequest.instructions || "";
|
|
8784
|
-
llmRequest.instructions = `${existingInstructions}
|
|
8785
|
-
|
|
8786
|
-
${planningInstruction}`;
|
|
8787
|
-
}
|
|
9026
|
+
llmRequest.appendInstructions([planningInstruction]);
|
|
8788
9027
|
}
|
|
8789
9028
|
removeThoughtFromRequest(llmRequest);
|
|
8790
9029
|
for await (const _ of []) {
|
|
@@ -8925,7 +9164,7 @@ var OutputSchemaResponseProcessor = (_class26 = class extends BaseLlmResponsePro
|
|
|
8925
9164
|
stripCodeFences(raw) {
|
|
8926
9165
|
const fencePattern = /```(?:json)?\s*([\s\S]*?)```/i;
|
|
8927
9166
|
const fenceMatch = raw.match(fencePattern);
|
|
8928
|
-
if (_optionalChain([fenceMatch, 'optionalAccess',
|
|
9167
|
+
if (_optionalChain([fenceMatch, 'optionalAccess', _259 => _259[1]])) {
|
|
8929
9168
|
return fenceMatch[1].trim();
|
|
8930
9169
|
}
|
|
8931
9170
|
const lines = raw.split(/\r?\n/).map((l) => l.trim());
|
|
@@ -8962,7 +9201,7 @@ var SharedMemoryRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
8962
9201
|
const memoryService = invocationContext.memoryService;
|
|
8963
9202
|
if (!memoryService) return;
|
|
8964
9203
|
const lastUserEvent = invocationContext.session.events.findLast(
|
|
8965
|
-
(e) => e.author === "user" && _optionalChain([e, 'access',
|
|
9204
|
+
(e) => e.author === "user" && _optionalChain([e, 'access', _260 => _260.content, 'optionalAccess', _261 => _261.parts, 'optionalAccess', _262 => _262.length])
|
|
8966
9205
|
);
|
|
8967
9206
|
if (!lastUserEvent) return;
|
|
8968
9207
|
const query = (_nullishCoalesce(lastUserEvent.content.parts, () => ( []))).map((p) => p.text || "").join(" ");
|
|
@@ -8973,7 +9212,7 @@ var SharedMemoryRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
8973
9212
|
});
|
|
8974
9213
|
const sessionTexts = new Set(
|
|
8975
9214
|
(llmRequest.contents || []).flatMap(
|
|
8976
|
-
(c) => _optionalChain([c, 'access',
|
|
9215
|
+
(c) => _optionalChain([c, 'access', _263 => _263.parts, 'optionalAccess', _264 => _264.map, 'call', _265 => _265((p) => p.text)]) || []
|
|
8977
9216
|
)
|
|
8978
9217
|
);
|
|
8979
9218
|
for (const memory of results.memories) {
|
|
@@ -9394,7 +9633,7 @@ var LlmAgent = (_class27 = class _LlmAgent extends BaseAgent {
|
|
|
9394
9633
|
* This matches the Python implementation's _llm_flow property
|
|
9395
9634
|
*/
|
|
9396
9635
|
get llmFlow() {
|
|
9397
|
-
if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access',
|
|
9636
|
+
if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access', _266 => _266.subAgents, 'optionalAccess', _267 => _267.length])) {
|
|
9398
9637
|
return new SingleFlow();
|
|
9399
9638
|
}
|
|
9400
9639
|
return new AutoFlow();
|
|
@@ -9410,7 +9649,7 @@ var LlmAgent = (_class27 = class _LlmAgent extends BaseAgent {
|
|
|
9410
9649
|
);
|
|
9411
9650
|
return;
|
|
9412
9651
|
}
|
|
9413
|
-
if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access',
|
|
9652
|
+
if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access', _268 => _268.content, 'optionalAccess', _269 => _269.parts])) {
|
|
9414
9653
|
let result = event.content.parts.map((part) => part.text || "").join("");
|
|
9415
9654
|
if (this.outputSchema) {
|
|
9416
9655
|
if (!result.trim()) {
|
|
@@ -9630,7 +9869,7 @@ var LoopAgent = class extends BaseAgent {
|
|
|
9630
9869
|
for (const subAgent of this.subAgents) {
|
|
9631
9870
|
for await (const event of subAgent.runAsync(ctx)) {
|
|
9632
9871
|
yield event;
|
|
9633
|
-
if (_optionalChain([event, 'access',
|
|
9872
|
+
if (_optionalChain([event, 'access', _270 => _270.actions, 'optionalAccess', _271 => _271.escalate])) {
|
|
9634
9873
|
return;
|
|
9635
9874
|
}
|
|
9636
9875
|
}
|
|
@@ -9942,17 +10181,17 @@ var RunConfig = class {
|
|
|
9942
10181
|
*/
|
|
9943
10182
|
|
|
9944
10183
|
constructor(config) {
|
|
9945
|
-
this.speechConfig = _optionalChain([config, 'optionalAccess',
|
|
9946
|
-
this.responseModalities = _optionalChain([config, 'optionalAccess',
|
|
9947
|
-
this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess',
|
|
9948
|
-
this.supportCFC = _optionalChain([config, 'optionalAccess',
|
|
9949
|
-
this.streamingMode = _optionalChain([config, 'optionalAccess',
|
|
9950
|
-
this.outputAudioTranscription = _optionalChain([config, 'optionalAccess',
|
|
9951
|
-
this.inputAudioTranscription = _optionalChain([config, 'optionalAccess',
|
|
9952
|
-
this.realtimeInputConfig = _optionalChain([config, 'optionalAccess',
|
|
9953
|
-
this.enableAffectiveDialog = _optionalChain([config, 'optionalAccess',
|
|
9954
|
-
this.proactivity = _optionalChain([config, 'optionalAccess',
|
|
9955
|
-
this.maxLlmCalls = _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
10184
|
+
this.speechConfig = _optionalChain([config, 'optionalAccess', _272 => _272.speechConfig]);
|
|
10185
|
+
this.responseModalities = _optionalChain([config, 'optionalAccess', _273 => _273.responseModalities]);
|
|
10186
|
+
this.saveInputBlobsAsArtifacts = _optionalChain([config, 'optionalAccess', _274 => _274.saveInputBlobsAsArtifacts]) || false;
|
|
10187
|
+
this.supportCFC = _optionalChain([config, 'optionalAccess', _275 => _275.supportCFC]) || false;
|
|
10188
|
+
this.streamingMode = _optionalChain([config, 'optionalAccess', _276 => _276.streamingMode]) || "NONE" /* NONE */;
|
|
10189
|
+
this.outputAudioTranscription = _optionalChain([config, 'optionalAccess', _277 => _277.outputAudioTranscription]);
|
|
10190
|
+
this.inputAudioTranscription = _optionalChain([config, 'optionalAccess', _278 => _278.inputAudioTranscription]);
|
|
10191
|
+
this.realtimeInputConfig = _optionalChain([config, 'optionalAccess', _279 => _279.realtimeInputConfig]);
|
|
10192
|
+
this.enableAffectiveDialog = _optionalChain([config, 'optionalAccess', _280 => _280.enableAffectiveDialog]);
|
|
10193
|
+
this.proactivity = _optionalChain([config, 'optionalAccess', _281 => _281.proactivity]);
|
|
10194
|
+
this.maxLlmCalls = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _282 => _282.maxLlmCalls]), () => ( 500));
|
|
9956
10195
|
this.validateMaxLlmCalls();
|
|
9957
10196
|
}
|
|
9958
10197
|
/**
|
|
@@ -9972,6 +10211,48 @@ var RunConfig = class {
|
|
|
9972
10211
|
}
|
|
9973
10212
|
};
|
|
9974
10213
|
|
|
10214
|
+
// src/artifacts/artifact-util.ts
|
|
10215
|
+
var SESSION_SCOPED_ARTIFACT_URI_RE = /^artifact:\/\/apps\/([^/]+)\/users\/([^/]+)\/sessions\/([^/]+)\/artifacts\/([^/]+)\/versions\/(\d+)$/;
|
|
10216
|
+
var USER_SCOPED_ARTIFACT_URI_RE = /^artifact:\/\/apps\/([^/]+)\/users\/([^/]+)\/artifacts\/([^/]+)\/versions\/(\d+)$/;
|
|
10217
|
+
function parseArtifactUri(uri) {
|
|
10218
|
+
if (!uri || !uri.startsWith("artifact://")) {
|
|
10219
|
+
return null;
|
|
10220
|
+
}
|
|
10221
|
+
let match = SESSION_SCOPED_ARTIFACT_URI_RE.exec(uri);
|
|
10222
|
+
if (match) {
|
|
10223
|
+
return {
|
|
10224
|
+
appName: match[1],
|
|
10225
|
+
userId: match[2],
|
|
10226
|
+
sessionId: match[3],
|
|
10227
|
+
filename: match[4],
|
|
10228
|
+
version: Number.parseInt(match[5], 10)
|
|
10229
|
+
};
|
|
10230
|
+
}
|
|
10231
|
+
match = USER_SCOPED_ARTIFACT_URI_RE.exec(uri);
|
|
10232
|
+
if (match) {
|
|
10233
|
+
return {
|
|
10234
|
+
appName: match[1],
|
|
10235
|
+
userId: match[2],
|
|
10236
|
+
sessionId: void 0,
|
|
10237
|
+
filename: match[3],
|
|
10238
|
+
version: Number.parseInt(match[4], 10)
|
|
10239
|
+
};
|
|
10240
|
+
}
|
|
10241
|
+
return null;
|
|
10242
|
+
}
|
|
10243
|
+
function getArtifactUri(args) {
|
|
10244
|
+
const { appName, userId, filename, version, sessionId } = args;
|
|
10245
|
+
if (sessionId) {
|
|
10246
|
+
return `artifact://apps/${appName}/users/${userId}/sessions/${sessionId}/artifacts/${filename}/versions/${version}`;
|
|
10247
|
+
}
|
|
10248
|
+
return `artifact://apps/${appName}/users/${userId}/artifacts/${filename}/versions/${version}`;
|
|
10249
|
+
}
|
|
10250
|
+
function isArtifactRef(artifact) {
|
|
10251
|
+
return Boolean(
|
|
10252
|
+
_optionalChain([artifact, 'access', _283 => _283.fileData, 'optionalAccess', _284 => _284.fileUri]) && artifact.fileData.fileUri.startsWith("artifact://")
|
|
10253
|
+
);
|
|
10254
|
+
}
|
|
10255
|
+
|
|
9975
10256
|
// src/artifacts/in-memory-artifact-service.ts
|
|
9976
10257
|
var InMemoryArtifactService = (_class29 = class {constructor() { _class29.prototype.__init50.call(this); }
|
|
9977
10258
|
__init50() {this.artifacts = /* @__PURE__ */ new Map()}
|
|
@@ -10012,7 +10293,29 @@ var InMemoryArtifactService = (_class29 = class {constructor() { _class29.protot
|
|
|
10012
10293
|
if (targetVersion < 0 || targetVersion >= versions.length) {
|
|
10013
10294
|
return null;
|
|
10014
10295
|
}
|
|
10015
|
-
|
|
10296
|
+
const artifactEntry = versions[targetVersion];
|
|
10297
|
+
if (!artifactEntry) {
|
|
10298
|
+
return null;
|
|
10299
|
+
}
|
|
10300
|
+
if (isArtifactRef(artifactEntry)) {
|
|
10301
|
+
const parsedUri = parseArtifactUri(_optionalChain([artifactEntry, 'access', _285 => _285.fileData, 'optionalAccess', _286 => _286.fileUri]) || "");
|
|
10302
|
+
if (!parsedUri) {
|
|
10303
|
+
throw new Error(
|
|
10304
|
+
`Invalid artifact reference URI: ${_optionalChain([artifactEntry, 'access', _287 => _287.fileData, 'optionalAccess', _288 => _288.fileUri])}`
|
|
10305
|
+
);
|
|
10306
|
+
}
|
|
10307
|
+
return await this.loadArtifact({
|
|
10308
|
+
appName: parsedUri.appName,
|
|
10309
|
+
userId: parsedUri.userId,
|
|
10310
|
+
sessionId: parsedUri.sessionId || sessionId,
|
|
10311
|
+
filename: parsedUri.filename,
|
|
10312
|
+
version: parsedUri.version
|
|
10313
|
+
});
|
|
10314
|
+
}
|
|
10315
|
+
if (!artifactEntry.text && (!_optionalChain([artifactEntry, 'access', _289 => _289.inlineData, 'optionalAccess', _290 => _290.data]) || artifactEntry.inlineData.data.length === 0) && !artifactEntry.fileData) {
|
|
10316
|
+
return null;
|
|
10317
|
+
}
|
|
10318
|
+
return artifactEntry;
|
|
10016
10319
|
}
|
|
10017
10320
|
async listArtifactKeys(args) {
|
|
10018
10321
|
const { appName, userId, sessionId } = args;
|
|
@@ -10096,7 +10399,7 @@ var InMemoryMemoryService = (_class30 = class {
|
|
|
10096
10399
|
}
|
|
10097
10400
|
const userSessions = this._sessionEvents.get(userKey);
|
|
10098
10401
|
const filteredEvents = session.events.filter(
|
|
10099
|
-
(event) => _optionalChain([event, 'access',
|
|
10402
|
+
(event) => _optionalChain([event, 'access', _291 => _291.content, 'optionalAccess', _292 => _292.parts])
|
|
10100
10403
|
);
|
|
10101
10404
|
userSessions.set(session.id, filteredEvents);
|
|
10102
10405
|
}
|
|
@@ -10197,11 +10500,16 @@ var BaseSessionService = class {
|
|
|
10197
10500
|
return;
|
|
10198
10501
|
}
|
|
10199
10502
|
for (const key in event.actions.stateDelta) {
|
|
10200
|
-
if (Object.
|
|
10503
|
+
if (Object.hasOwn(event.actions.stateDelta, key)) {
|
|
10201
10504
|
if (key.startsWith("temp_")) {
|
|
10202
10505
|
continue;
|
|
10203
10506
|
}
|
|
10204
|
-
|
|
10507
|
+
const value = event.actions.stateDelta[key];
|
|
10508
|
+
if (value === null || value === void 0) {
|
|
10509
|
+
delete session.state[key];
|
|
10510
|
+
} else {
|
|
10511
|
+
session.state[key] = value;
|
|
10512
|
+
}
|
|
10205
10513
|
}
|
|
10206
10514
|
}
|
|
10207
10515
|
}
|
|
@@ -10235,7 +10543,7 @@ var InMemorySessionService = (_class31 = class extends BaseSessionService {const
|
|
|
10235
10543
|
return this.createSessionImpl(appName, userId, state, sessionId);
|
|
10236
10544
|
}
|
|
10237
10545
|
createSessionImpl(appName, userId, state, sessionId) {
|
|
10238
|
-
const finalSessionId = _optionalChain([sessionId, 'optionalAccess',
|
|
10546
|
+
const finalSessionId = _optionalChain([sessionId, 'optionalAccess', _293 => _293.trim, 'call', _294 => _294()]) || _crypto.randomUUID.call(void 0, );
|
|
10239
10547
|
const session = {
|
|
10240
10548
|
appName,
|
|
10241
10549
|
userId,
|
|
@@ -10392,7 +10700,7 @@ var InMemorySessionService = (_class31 = class extends BaseSessionService {const
|
|
|
10392
10700
|
warning(`sessionId ${sessionId} not in sessions[appName][userId]`);
|
|
10393
10701
|
return event;
|
|
10394
10702
|
}
|
|
10395
|
-
if (_optionalChain([event, 'access',
|
|
10703
|
+
if (_optionalChain([event, 'access', _295 => _295.actions, 'optionalAccess', _296 => _296.stateDelta])) {
|
|
10396
10704
|
for (const key in event.actions.stateDelta) {
|
|
10397
10705
|
const value = event.actions.stateDelta[key];
|
|
10398
10706
|
if (key.startsWith(State.APP_PREFIX)) {
|
|
@@ -10426,14 +10734,14 @@ function _findFunctionCallEventIfLastEventIsFunctionResponse(session) {
|
|
|
10426
10734
|
return null;
|
|
10427
10735
|
}
|
|
10428
10736
|
const lastEvent = events[events.length - 1];
|
|
10429
|
-
if (_optionalChain([lastEvent, 'access',
|
|
10430
|
-
const functionCallId = _optionalChain([lastEvent, 'access',
|
|
10737
|
+
if (_optionalChain([lastEvent, 'access', _297 => _297.content, 'optionalAccess', _298 => _298.parts, 'optionalAccess', _299 => _299.some, 'call', _300 => _300((part) => part.functionResponse)])) {
|
|
10738
|
+
const functionCallId = _optionalChain([lastEvent, 'access', _301 => _301.content, 'access', _302 => _302.parts, 'access', _303 => _303.find, 'call', _304 => _304(
|
|
10431
10739
|
(part) => part.functionResponse
|
|
10432
|
-
), 'optionalAccess',
|
|
10740
|
+
), 'optionalAccess', _305 => _305.functionResponse, 'optionalAccess', _306 => _306.id]);
|
|
10433
10741
|
if (!functionCallId) return null;
|
|
10434
10742
|
for (let i = events.length - 2; i >= 0; i--) {
|
|
10435
10743
|
const event = events[i];
|
|
10436
|
-
const functionCalls = _optionalChain([event, 'access',
|
|
10744
|
+
const functionCalls = _optionalChain([event, 'access', _307 => _307.getFunctionCalls, 'optionalCall', _308 => _308()]) || [];
|
|
10437
10745
|
for (const functionCall of functionCalls) {
|
|
10438
10746
|
if (functionCall.id === functionCallId) {
|
|
10439
10747
|
return event;
|
|
@@ -10464,6 +10772,10 @@ var Runner = (_class32 = class {
|
|
|
10464
10772
|
* The memory service for the runner.
|
|
10465
10773
|
*/
|
|
10466
10774
|
|
|
10775
|
+
/**
|
|
10776
|
+
* Configuration for event compaction.
|
|
10777
|
+
*/
|
|
10778
|
+
|
|
10467
10779
|
__init55() {this.logger = new Logger({ name: "Runner" })}
|
|
10468
10780
|
/**
|
|
10469
10781
|
* Initializes the Runner.
|
|
@@ -10473,13 +10785,15 @@ var Runner = (_class32 = class {
|
|
|
10473
10785
|
agent,
|
|
10474
10786
|
artifactService,
|
|
10475
10787
|
sessionService,
|
|
10476
|
-
memoryService
|
|
10788
|
+
memoryService,
|
|
10789
|
+
eventsCompactionConfig
|
|
10477
10790
|
}) {;_class32.prototype.__init55.call(this);
|
|
10478
10791
|
this.appName = appName;
|
|
10479
10792
|
this.agent = agent;
|
|
10480
10793
|
this.artifactService = artifactService;
|
|
10481
10794
|
this.sessionService = sessionService;
|
|
10482
10795
|
this.memoryService = memoryService;
|
|
10796
|
+
this.eventsCompactionConfig = eventsCompactionConfig;
|
|
10483
10797
|
}
|
|
10484
10798
|
/**
|
|
10485
10799
|
* Runs the agent synchronously.
|
|
@@ -10581,6 +10895,10 @@ var Runner = (_class32 = class {
|
|
|
10581
10895
|
}
|
|
10582
10896
|
yield event;
|
|
10583
10897
|
}
|
|
10898
|
+
await _api.context.with(
|
|
10899
|
+
spanContext,
|
|
10900
|
+
() => this._runCompaction(session, invocationContext)
|
|
10901
|
+
);
|
|
10584
10902
|
} catch (error) {
|
|
10585
10903
|
this.logger.debug("Error running agent:", error);
|
|
10586
10904
|
span.recordException(error);
|
|
@@ -10636,15 +10954,15 @@ var Runner = (_class32 = class {
|
|
|
10636
10954
|
*/
|
|
10637
10955
|
_findAgentToRun(session, rootAgent) {
|
|
10638
10956
|
const event = _findFunctionCallEventIfLastEventIsFunctionResponse(session);
|
|
10639
|
-
if (_optionalChain([event, 'optionalAccess',
|
|
10957
|
+
if (_optionalChain([event, 'optionalAccess', _309 => _309.author])) {
|
|
10640
10958
|
return rootAgent.findAgent(event.author);
|
|
10641
10959
|
}
|
|
10642
|
-
const nonUserEvents = _optionalChain([session, 'access',
|
|
10960
|
+
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()]) || [];
|
|
10643
10961
|
for (const event2 of nonUserEvents) {
|
|
10644
10962
|
if (event2.author === rootAgent.name) {
|
|
10645
10963
|
return rootAgent;
|
|
10646
10964
|
}
|
|
10647
|
-
const agent = _optionalChain([rootAgent, 'access',
|
|
10965
|
+
const agent = _optionalChain([rootAgent, 'access', _315 => _315.findSubAgent, 'optionalCall', _316 => _316(event2.author)]);
|
|
10648
10966
|
if (!agent) {
|
|
10649
10967
|
this.logger.debug(
|
|
10650
10968
|
`Event from an unknown agent: ${event2.author}, event id: ${event2.id}`
|
|
@@ -10693,6 +11011,188 @@ var Runner = (_class32 = class {
|
|
|
10693
11011
|
runConfig
|
|
10694
11012
|
});
|
|
10695
11013
|
}
|
|
11014
|
+
/**
|
|
11015
|
+
* Runs compaction if configured.
|
|
11016
|
+
*/
|
|
11017
|
+
async _runCompaction(session, _invocationContext) {
|
|
11018
|
+
if (!this.eventsCompactionConfig) {
|
|
11019
|
+
return;
|
|
11020
|
+
}
|
|
11021
|
+
const summarizer = this._getOrCreateSummarizer();
|
|
11022
|
+
if (!summarizer) {
|
|
11023
|
+
this.logger.warn(
|
|
11024
|
+
"Event compaction configured but no summarizer available"
|
|
11025
|
+
);
|
|
11026
|
+
return;
|
|
11027
|
+
}
|
|
11028
|
+
try {
|
|
11029
|
+
await runCompactionForSlidingWindow(
|
|
11030
|
+
this.eventsCompactionConfig,
|
|
11031
|
+
session,
|
|
11032
|
+
this.sessionService,
|
|
11033
|
+
summarizer
|
|
11034
|
+
);
|
|
11035
|
+
} catch (error) {
|
|
11036
|
+
this.logger.error("Error running compaction:", error);
|
|
11037
|
+
}
|
|
11038
|
+
}
|
|
11039
|
+
/**
|
|
11040
|
+
* Gets the configured summarizer or creates a default LLM-based one.
|
|
11041
|
+
*/
|
|
11042
|
+
_getOrCreateSummarizer() {
|
|
11043
|
+
if (_optionalChain([this, 'access', _317 => _317.eventsCompactionConfig, 'optionalAccess', _318 => _318.summarizer])) {
|
|
11044
|
+
return this.eventsCompactionConfig.summarizer;
|
|
11045
|
+
}
|
|
11046
|
+
if (this.agent instanceof LlmAgent) {
|
|
11047
|
+
try {
|
|
11048
|
+
const model = this.agent.canonicalModel;
|
|
11049
|
+
return new LlmEventSummarizer(model);
|
|
11050
|
+
} catch (error) {
|
|
11051
|
+
this.logger.warn(
|
|
11052
|
+
"Could not get canonical model for default summarizer:",
|
|
11053
|
+
error
|
|
11054
|
+
);
|
|
11055
|
+
return void 0;
|
|
11056
|
+
}
|
|
11057
|
+
}
|
|
11058
|
+
return void 0;
|
|
11059
|
+
}
|
|
11060
|
+
async rewind(args) {
|
|
11061
|
+
const { userId, sessionId, rewindBeforeInvocationId } = args;
|
|
11062
|
+
const session = await this.sessionService.getSession(
|
|
11063
|
+
this.appName,
|
|
11064
|
+
userId,
|
|
11065
|
+
sessionId
|
|
11066
|
+
);
|
|
11067
|
+
if (!session) {
|
|
11068
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
11069
|
+
}
|
|
11070
|
+
let rewindEventIndex = -1;
|
|
11071
|
+
for (let i = 0; i < session.events.length; i++) {
|
|
11072
|
+
if (session.events[i].invocationId === rewindBeforeInvocationId) {
|
|
11073
|
+
rewindEventIndex = i;
|
|
11074
|
+
break;
|
|
11075
|
+
}
|
|
11076
|
+
}
|
|
11077
|
+
if (rewindEventIndex === -1) {
|
|
11078
|
+
throw new Error(`Invocation ID not found: ${rewindBeforeInvocationId}`);
|
|
11079
|
+
}
|
|
11080
|
+
const stateDelta = await this._computeStateDeltaForRewind(
|
|
11081
|
+
session,
|
|
11082
|
+
rewindEventIndex
|
|
11083
|
+
);
|
|
11084
|
+
const artifactDelta = await this._computeArtifactDeltaForRewind(
|
|
11085
|
+
session,
|
|
11086
|
+
rewindEventIndex
|
|
11087
|
+
);
|
|
11088
|
+
const rewindEvent = new Event({
|
|
11089
|
+
invocationId: newInvocationContextId(),
|
|
11090
|
+
author: "user",
|
|
11091
|
+
actions: new EventActions({
|
|
11092
|
+
rewindBeforeInvocationId,
|
|
11093
|
+
stateDelta,
|
|
11094
|
+
artifactDelta
|
|
11095
|
+
})
|
|
11096
|
+
});
|
|
11097
|
+
this.logger.info(
|
|
11098
|
+
"Rewinding session to invocation:",
|
|
11099
|
+
rewindBeforeInvocationId
|
|
11100
|
+
);
|
|
11101
|
+
await this.sessionService.appendEvent(session, rewindEvent);
|
|
11102
|
+
}
|
|
11103
|
+
async _computeStateDeltaForRewind(session, rewindEventIndex) {
|
|
11104
|
+
const stateAtRewindPoint = {};
|
|
11105
|
+
for (let i = 0; i < rewindEventIndex; i++) {
|
|
11106
|
+
const event = session.events[i];
|
|
11107
|
+
if (_optionalChain([event, 'access', _319 => _319.actions, 'optionalAccess', _320 => _320.stateDelta])) {
|
|
11108
|
+
for (const [k, v] of Object.entries(event.actions.stateDelta)) {
|
|
11109
|
+
if (k.startsWith("app:") || k.startsWith("user:")) {
|
|
11110
|
+
continue;
|
|
11111
|
+
}
|
|
11112
|
+
if (v === null || v === void 0) {
|
|
11113
|
+
delete stateAtRewindPoint[k];
|
|
11114
|
+
} else {
|
|
11115
|
+
stateAtRewindPoint[k] = v;
|
|
11116
|
+
}
|
|
11117
|
+
}
|
|
11118
|
+
}
|
|
11119
|
+
}
|
|
11120
|
+
const currentState = session.state;
|
|
11121
|
+
const rewindStateDelta = {};
|
|
11122
|
+
for (const [key, valueAtRewind] of Object.entries(stateAtRewindPoint)) {
|
|
11123
|
+
if (!(key in currentState) || currentState[key] !== valueAtRewind) {
|
|
11124
|
+
rewindStateDelta[key] = valueAtRewind;
|
|
11125
|
+
}
|
|
11126
|
+
}
|
|
11127
|
+
for (const key of Object.keys(currentState)) {
|
|
11128
|
+
if (key.startsWith("app:") || key.startsWith("user:")) {
|
|
11129
|
+
continue;
|
|
11130
|
+
}
|
|
11131
|
+
if (!(key in stateAtRewindPoint)) {
|
|
11132
|
+
rewindStateDelta[key] = null;
|
|
11133
|
+
}
|
|
11134
|
+
}
|
|
11135
|
+
return rewindStateDelta;
|
|
11136
|
+
}
|
|
11137
|
+
async _computeArtifactDeltaForRewind(session, rewindEventIndex) {
|
|
11138
|
+
if (!this.artifactService) {
|
|
11139
|
+
return {};
|
|
11140
|
+
}
|
|
11141
|
+
const versionsAtRewindPoint = {};
|
|
11142
|
+
for (let i = 0; i < rewindEventIndex; i++) {
|
|
11143
|
+
const event = session.events[i];
|
|
11144
|
+
if (_optionalChain([event, 'access', _321 => _321.actions, 'optionalAccess', _322 => _322.artifactDelta])) {
|
|
11145
|
+
Object.assign(versionsAtRewindPoint, event.actions.artifactDelta);
|
|
11146
|
+
}
|
|
11147
|
+
}
|
|
11148
|
+
const currentVersions = {};
|
|
11149
|
+
for (const event of session.events) {
|
|
11150
|
+
if (_optionalChain([event, 'access', _323 => _323.actions, 'optionalAccess', _324 => _324.artifactDelta])) {
|
|
11151
|
+
Object.assign(currentVersions, event.actions.artifactDelta);
|
|
11152
|
+
}
|
|
11153
|
+
}
|
|
11154
|
+
const rewindArtifactDelta = {};
|
|
11155
|
+
for (const [filename, vn] of Object.entries(currentVersions)) {
|
|
11156
|
+
if (filename.startsWith("user:")) {
|
|
11157
|
+
continue;
|
|
11158
|
+
}
|
|
11159
|
+
const vt = versionsAtRewindPoint[filename];
|
|
11160
|
+
if (vt === vn) {
|
|
11161
|
+
continue;
|
|
11162
|
+
}
|
|
11163
|
+
let artifact;
|
|
11164
|
+
if (vt === void 0 || vt === null) {
|
|
11165
|
+
artifact = {
|
|
11166
|
+
inlineData: {
|
|
11167
|
+
mimeType: "application/octet-stream",
|
|
11168
|
+
data: ""
|
|
11169
|
+
}
|
|
11170
|
+
};
|
|
11171
|
+
} else {
|
|
11172
|
+
const artifactUri = getArtifactUri({
|
|
11173
|
+
appName: this.appName,
|
|
11174
|
+
userId: session.userId,
|
|
11175
|
+
sessionId: session.id,
|
|
11176
|
+
filename,
|
|
11177
|
+
version: vt
|
|
11178
|
+
});
|
|
11179
|
+
artifact = {
|
|
11180
|
+
fileData: {
|
|
11181
|
+
fileUri: artifactUri
|
|
11182
|
+
}
|
|
11183
|
+
};
|
|
11184
|
+
}
|
|
11185
|
+
const newVersion = await this.artifactService.saveArtifact({
|
|
11186
|
+
appName: this.appName,
|
|
11187
|
+
userId: session.userId,
|
|
11188
|
+
sessionId: session.id,
|
|
11189
|
+
filename,
|
|
11190
|
+
artifact
|
|
11191
|
+
});
|
|
11192
|
+
rewindArtifactDelta[filename] = newVersion;
|
|
11193
|
+
}
|
|
11194
|
+
return rewindArtifactDelta;
|
|
11195
|
+
}
|
|
10696
11196
|
}, _class32);
|
|
10697
11197
|
var InMemoryRunner = class extends Runner {
|
|
10698
11198
|
/**
|
|
@@ -10722,6 +11222,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
10722
11222
|
|
|
10723
11223
|
|
|
10724
11224
|
|
|
11225
|
+
|
|
10725
11226
|
__init56() {this.agentType = "llm"}
|
|
10726
11227
|
|
|
10727
11228
|
|
|
@@ -10935,6 +11436,14 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
10935
11436
|
this.config.afterToolCallback = callback;
|
|
10936
11437
|
return this;
|
|
10937
11438
|
}
|
|
11439
|
+
/**
|
|
11440
|
+
* Convenience method to start building with an existing agent
|
|
11441
|
+
* @param agent The agent instance to wrap
|
|
11442
|
+
* @returns New AgentBuilder instance with agent set
|
|
11443
|
+
*/
|
|
11444
|
+
static withAgent(agent) {
|
|
11445
|
+
return new _AgentBuilder(agent.name || "default_agent").withAgent(agent);
|
|
11446
|
+
}
|
|
10938
11447
|
/**
|
|
10939
11448
|
* Provide an already constructed agent instance. Further definition-mutating calls
|
|
10940
11449
|
* (model/tools/instruction/etc.) will be ignored with a dev warning.
|
|
@@ -11116,6 +11625,26 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11116
11625
|
this.runConfig = config instanceof RunConfig ? config : new RunConfig({ ...this.runConfig || {}, ...config });
|
|
11117
11626
|
return this;
|
|
11118
11627
|
}
|
|
11628
|
+
/**
|
|
11629
|
+
* Configure event compaction for automatic history management
|
|
11630
|
+
* @param config Event compaction configuration
|
|
11631
|
+
* @returns This builder instance for chaining
|
|
11632
|
+
* @example
|
|
11633
|
+
* ```typescript
|
|
11634
|
+
* const { runner } = await AgentBuilder
|
|
11635
|
+
* .create("assistant")
|
|
11636
|
+
* .withModel("gemini-2.5-flash")
|
|
11637
|
+
* .withEventsCompaction({
|
|
11638
|
+
* compactionInterval: 10, // Compact every 10 invocations
|
|
11639
|
+
* overlapSize: 2, // Include 2 prior invocations
|
|
11640
|
+
* })
|
|
11641
|
+
* .build();
|
|
11642
|
+
* ```
|
|
11643
|
+
*/
|
|
11644
|
+
withEventsCompaction(config) {
|
|
11645
|
+
this.eventsCompactionConfig = config;
|
|
11646
|
+
return this;
|
|
11647
|
+
}
|
|
11119
11648
|
/**
|
|
11120
11649
|
* Configure with an in-memory session with custom IDs
|
|
11121
11650
|
* Note: In-memory sessions are created automatically by default, use this only if you need custom appName/userId
|
|
@@ -11152,7 +11681,8 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11152
11681
|
agent,
|
|
11153
11682
|
sessionService: this.sessionService,
|
|
11154
11683
|
memoryService: this.memoryService,
|
|
11155
|
-
artifactService: this.artifactService
|
|
11684
|
+
artifactService: this.artifactService,
|
|
11685
|
+
eventsCompactionConfig: this.eventsCompactionConfig
|
|
11156
11686
|
};
|
|
11157
11687
|
const baseRunner = new Runner(runnerConfig);
|
|
11158
11688
|
runner = this.createEnhancedRunner(baseRunner, session);
|
|
@@ -11302,7 +11832,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11302
11832
|
const outputSchema = this.config.outputSchema;
|
|
11303
11833
|
const agentType = this.agentType;
|
|
11304
11834
|
const isMulti = agentType === "parallel" || agentType === "sequential";
|
|
11305
|
-
const subAgentNames = _optionalChain([this, 'access',
|
|
11835
|
+
const subAgentNames = _optionalChain([this, 'access', _325 => _325.config, 'access', _326 => _326.subAgents, 'optionalAccess', _327 => _327.map, 'call', _328 => _328((a) => a.name)]) || [];
|
|
11306
11836
|
const runConfig = this.runConfig;
|
|
11307
11837
|
return {
|
|
11308
11838
|
__outputSchema: outputSchema,
|
|
@@ -11311,7 +11841,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11311
11841
|
let combinedResponse = "";
|
|
11312
11842
|
const perAgentBuffers = {};
|
|
11313
11843
|
const authors = /* @__PURE__ */ new Set();
|
|
11314
|
-
if (!_optionalChain([sessionOptions, 'optionalAccess',
|
|
11844
|
+
if (!_optionalChain([sessionOptions, 'optionalAccess', _329 => _329.userId])) {
|
|
11315
11845
|
throw new Error("Session configuration is required");
|
|
11316
11846
|
}
|
|
11317
11847
|
for await (const event of baseRunner.runAsync({
|
|
@@ -11320,7 +11850,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11320
11850
|
newMessage,
|
|
11321
11851
|
runConfig
|
|
11322
11852
|
})) {
|
|
11323
|
-
if (_optionalChain([event, 'access',
|
|
11853
|
+
if (_optionalChain([event, 'access', _330 => _330.content, 'optionalAccess', _331 => _331.parts]) && Array.isArray(event.content.parts)) {
|
|
11324
11854
|
const content = event.content.parts.map(
|
|
11325
11855
|
(part) => (part && typeof part === "object" && "text" in part ? part.text : "") || ""
|
|
11326
11856
|
).join("");
|
|
@@ -11366,6 +11896,9 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11366
11896
|
...params,
|
|
11367
11897
|
runConfig: _nullishCoalesce(params.runConfig, () => ( runConfig))
|
|
11368
11898
|
});
|
|
11899
|
+
},
|
|
11900
|
+
rewind(params) {
|
|
11901
|
+
return baseRunner.rewind(params);
|
|
11369
11902
|
}
|
|
11370
11903
|
};
|
|
11371
11904
|
}
|
|
@@ -11607,7 +12140,7 @@ var VertexAiSessionService = class extends BaseSessionService {
|
|
|
11607
12140
|
path: `operations/${operationId}`,
|
|
11608
12141
|
request_dict: {}
|
|
11609
12142
|
});
|
|
11610
|
-
if (_optionalChain([lroResponse, 'optionalAccess',
|
|
12143
|
+
if (_optionalChain([lroResponse, 'optionalAccess', _332 => _332.done])) {
|
|
11611
12144
|
break;
|
|
11612
12145
|
}
|
|
11613
12146
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
@@ -11978,12 +12511,12 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
11978
12511
|
}
|
|
11979
12512
|
async createSession(appName, userId, state, sessionId) {
|
|
11980
12513
|
await this.ensureInitialized();
|
|
11981
|
-
const id = _optionalChain([sessionId, 'optionalAccess',
|
|
12514
|
+
const id = _optionalChain([sessionId, 'optionalAccess', _333 => _333.trim, 'call', _334 => _334()]) || this.generateSessionId();
|
|
11982
12515
|
return await this.db.transaction().execute(async (trx) => {
|
|
11983
12516
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
|
|
11984
12517
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", appName).where("user_id", "=", userId).executeTakeFirst();
|
|
11985
|
-
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
11986
|
-
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
12518
|
+
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _335 => _335.state]), {});
|
|
12519
|
+
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _336 => _336.state]), {});
|
|
11987
12520
|
if (!appState) {
|
|
11988
12521
|
await trx.insertInto("app_states").values({
|
|
11989
12522
|
app_name: appName,
|
|
@@ -12042,21 +12575,21 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
12042
12575
|
return void 0;
|
|
12043
12576
|
}
|
|
12044
12577
|
let eventQuery = trx.selectFrom("events").selectAll().where("session_id", "=", sessionId).orderBy("timestamp", "desc");
|
|
12045
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
12578
|
+
if (_optionalChain([config, 'optionalAccess', _337 => _337.afterTimestamp])) {
|
|
12046
12579
|
eventQuery = eventQuery.where(
|
|
12047
12580
|
"timestamp",
|
|
12048
12581
|
">=",
|
|
12049
12582
|
new Date(config.afterTimestamp * 1e3)
|
|
12050
12583
|
);
|
|
12051
12584
|
}
|
|
12052
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
12585
|
+
if (_optionalChain([config, 'optionalAccess', _338 => _338.numRecentEvents])) {
|
|
12053
12586
|
eventQuery = eventQuery.limit(config.numRecentEvents);
|
|
12054
12587
|
}
|
|
12055
12588
|
const storageEvents = await eventQuery.execute();
|
|
12056
12589
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
|
|
12057
12590
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", appName).where("user_id", "=", userId).executeTakeFirst();
|
|
12058
|
-
const currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
12059
|
-
const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
12591
|
+
const currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _339 => _339.state]), {});
|
|
12592
|
+
const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _340 => _340.state]), {});
|
|
12060
12593
|
const sessionState = this.parseJsonSafely(storageSession.state, {});
|
|
12061
12594
|
const mergedState = this.mergeState(
|
|
12062
12595
|
currentAppState,
|
|
@@ -12114,13 +12647,13 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
12114
12647
|
}
|
|
12115
12648
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", session.appName).executeTakeFirst();
|
|
12116
12649
|
const userState = await trx.selectFrom("user_states").selectAll().where("app_name", "=", session.appName).where("user_id", "=", session.userId).executeTakeFirst();
|
|
12117
|
-
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess',
|
|
12118
|
-
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess',
|
|
12650
|
+
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _341 => _341.state]), {});
|
|
12651
|
+
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _342 => _342.state]), {});
|
|
12119
12652
|
let sessionState = this.parseJsonSafely(storageSession.state, {});
|
|
12120
12653
|
let appStateDelta = {};
|
|
12121
12654
|
let userStateDelta = {};
|
|
12122
12655
|
let sessionStateDelta = {};
|
|
12123
|
-
if (_optionalChain([event, 'access',
|
|
12656
|
+
if (_optionalChain([event, 'access', _343 => _343.actions, 'optionalAccess', _344 => _344.stateDelta])) {
|
|
12124
12657
|
const deltas = this.extractStateDelta(event.actions.stateDelta);
|
|
12125
12658
|
appStateDelta = deltas.appStateDelta;
|
|
12126
12659
|
userStateDelta = deltas.userStateDelta;
|
|
@@ -12266,7 +12799,7 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
12266
12799
|
* Overrides the base class method to work with plain object state.
|
|
12267
12800
|
*/
|
|
12268
12801
|
updateSessionState(session, event) {
|
|
12269
|
-
if (!_optionalChain([event, 'access',
|
|
12802
|
+
if (!_optionalChain([event, 'access', _345 => _345.actions, 'optionalAccess', _346 => _346.stateDelta])) {
|
|
12270
12803
|
return;
|
|
12271
12804
|
}
|
|
12272
12805
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
@@ -12436,7 +12969,7 @@ var GcsArtifactService = class {
|
|
|
12436
12969
|
};
|
|
12437
12970
|
return part;
|
|
12438
12971
|
} catch (error) {
|
|
12439
|
-
if (_optionalChain([error, 'optionalAccess',
|
|
12972
|
+
if (_optionalChain([error, 'optionalAccess', _347 => _347.code]) === 404) {
|
|
12440
12973
|
return null;
|
|
12441
12974
|
}
|
|
12442
12975
|
throw error;
|
|
@@ -12687,13 +13220,13 @@ var VertexAiEvalFacade = class _VertexAiEvalFacade {
|
|
|
12687
13220
|
};
|
|
12688
13221
|
}
|
|
12689
13222
|
_getText(content) {
|
|
12690
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
13223
|
+
if (_optionalChain([content, 'optionalAccess', _348 => _348.parts])) {
|
|
12691
13224
|
return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join("\n");
|
|
12692
13225
|
}
|
|
12693
13226
|
return "";
|
|
12694
13227
|
}
|
|
12695
13228
|
_getScore(evalResult) {
|
|
12696
|
-
if (_optionalChain([evalResult, 'optionalAccess',
|
|
13229
|
+
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)) {
|
|
12697
13230
|
return evalResult.summaryMetrics[0].meanScore;
|
|
12698
13231
|
}
|
|
12699
13232
|
return void 0;
|
|
@@ -12843,7 +13376,7 @@ var ResponseEvaluator = class extends Evaluator {
|
|
|
12843
13376
|
return fmeasure;
|
|
12844
13377
|
}
|
|
12845
13378
|
extractText(content) {
|
|
12846
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
13379
|
+
if (_optionalChain([content, 'optionalAccess', _352 => _352.parts])) {
|
|
12847
13380
|
return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join(" ");
|
|
12848
13381
|
}
|
|
12849
13382
|
return "";
|
|
@@ -12876,7 +13409,7 @@ var TrajectoryEvaluator = class extends Evaluator {
|
|
|
12876
13409
|
for (let i = 0; i < actualInvocations.length; i++) {
|
|
12877
13410
|
const actual = actualInvocations[i];
|
|
12878
13411
|
const expected = expectedInvocations[i];
|
|
12879
|
-
if (!_optionalChain([actual, 'access',
|
|
13412
|
+
if (!_optionalChain([actual, 'access', _353 => _353.intermediateData, 'optionalAccess', _354 => _354.toolUses]) || !_optionalChain([expected, 'access', _355 => _355.intermediateData, 'optionalAccess', _356 => _356.toolUses])) {
|
|
12880
13413
|
perInvocationResults.push({
|
|
12881
13414
|
actualInvocation: actual,
|
|
12882
13415
|
expectedInvocation: expected,
|
|
@@ -12964,7 +13497,7 @@ var SafetyEvaluatorV1 = class extends Evaluator {
|
|
|
12964
13497
|
|
|
12965
13498
|
// src/evaluation/llm-as-judge-utils.ts
|
|
12966
13499
|
function getTextFromContent(content) {
|
|
12967
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
13500
|
+
if (_optionalChain([content, 'optionalAccess', _357 => _357.parts])) {
|
|
12968
13501
|
return content.parts.map((part) => part.text).filter(Boolean).join("\n");
|
|
12969
13502
|
}
|
|
12970
13503
|
return "";
|
|
@@ -12976,9 +13509,9 @@ function getEvalStatus(score, threshold) {
|
|
|
12976
13509
|
// src/evaluation/llm-as-judge.ts
|
|
12977
13510
|
var LlmAsJudge = class {
|
|
12978
13511
|
async sampleJudge(prompt, numSamples, critiqueParser, judgeModelOptions) {
|
|
12979
|
-
const modelName = _optionalChain([judgeModelOptions, 'optionalAccess',
|
|
13512
|
+
const modelName = _optionalChain([judgeModelOptions, 'optionalAccess', _358 => _358.judgeModel]) || "gemini-2.5-flash";
|
|
12980
13513
|
const model = LLMRegistry.getModelOrCreate(modelName);
|
|
12981
|
-
const config = _optionalChain([judgeModelOptions, 'optionalAccess',
|
|
13514
|
+
const config = _optionalChain([judgeModelOptions, 'optionalAccess', _359 => _359.judgeModelConfig]) || {};
|
|
12982
13515
|
const samples = [];
|
|
12983
13516
|
for (let i = 0; i < numSamples; i++) {
|
|
12984
13517
|
try {
|
|
@@ -13044,7 +13577,7 @@ function parseCritique(response) {
|
|
|
13044
13577
|
const labelMatchIsResponseValid = response.match(
|
|
13045
13578
|
/"is_the_agent_response_valid":\s*\[*[\n\s]*"*([^"^\]^\s]*)"*[\n\s]*\]*\s*[,\n\}]/
|
|
13046
13579
|
);
|
|
13047
|
-
if (_optionalChain([labelMatchIsResponseValid, 'optionalAccess',
|
|
13580
|
+
if (_optionalChain([labelMatchIsResponseValid, 'optionalAccess', _360 => _360[1]])) {
|
|
13048
13581
|
const label = labelMatchIsResponseValid[1].toLowerCase();
|
|
13049
13582
|
return label === "valid" ? "valid" /* VALID */ : "invalid" /* INVALID */;
|
|
13050
13583
|
}
|
|
@@ -13089,7 +13622,7 @@ var FinalResponseMatchV2Evaluator = class extends Evaluator {
|
|
|
13089
13622
|
"{prompt}",
|
|
13090
13623
|
prompt
|
|
13091
13624
|
).replace("{response}", response).replace("{golden_response}", goldenResponse);
|
|
13092
|
-
const numSamples = _nullishCoalesce(_optionalChain([this, 'access',
|
|
13625
|
+
const numSamples = _nullishCoalesce(_optionalChain([this, 'access', _361 => _361.metric, 'access', _362 => _362.judgeModelOptions, 'optionalAccess', _363 => _363.numSamples]), () => ( DEFAULT_NUM_SAMPLES));
|
|
13093
13626
|
const labels = await this.llmAsJudge.sampleJudge(
|
|
13094
13627
|
formattedPrompt,
|
|
13095
13628
|
numSamples,
|
|
@@ -13129,7 +13662,7 @@ var MetricEvaluatorRegistry = (_class35 = class {constructor() { _class35.protot
|
|
|
13129
13662
|
const metricName = metricInfo.metricName;
|
|
13130
13663
|
if (this.registry.has(metricName)) {
|
|
13131
13664
|
console.info(
|
|
13132
|
-
`Updating Evaluator class for ${metricName} from ${_optionalChain([this, 'access',
|
|
13665
|
+
`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}`
|
|
13133
13666
|
);
|
|
13134
13667
|
}
|
|
13135
13668
|
this.registry.set(metricName, {
|
|
@@ -13243,10 +13776,10 @@ var LocalEvalService = class extends BaseEvalService {
|
|
|
13243
13776
|
for (const evalMetric of evaluateConfig.evalMetrics) {
|
|
13244
13777
|
const evaluator = DEFAULT_METRIC_EVALUATOR_REGISTRY.getEvaluator(evalMetric);
|
|
13245
13778
|
const actual = results.filter(
|
|
13246
|
-
(r) => !_optionalChain([r, 'access',
|
|
13779
|
+
(r) => !_optionalChain([r, 'access', _369 => _369.invocationId, 'optionalAccess', _370 => _370.includes, 'call', _371 => _371("expected")])
|
|
13247
13780
|
);
|
|
13248
13781
|
const expected = results.filter(
|
|
13249
|
-
(r) => _optionalChain([r, 'access',
|
|
13782
|
+
(r) => _optionalChain([r, 'access', _372 => _372.invocationId, 'optionalAccess', _373 => _373.includes, 'call', _374 => _374("expected")])
|
|
13250
13783
|
);
|
|
13251
13784
|
const result = await evaluator.evaluateInvocations(actual, expected);
|
|
13252
13785
|
evalResult.evalCaseResults.push({
|
|
@@ -13638,13 +14171,13 @@ ${failures.join(
|
|
|
13638
14171
|
console.log("\n\n");
|
|
13639
14172
|
}
|
|
13640
14173
|
static _convertContentToText(content) {
|
|
13641
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
14174
|
+
if (_optionalChain([content, 'optionalAccess', _375 => _375.parts])) {
|
|
13642
14175
|
return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join("\n");
|
|
13643
14176
|
}
|
|
13644
14177
|
return "";
|
|
13645
14178
|
}
|
|
13646
14179
|
static _convertToolCallsToText(intermediateData) {
|
|
13647
|
-
if (_optionalChain([intermediateData, 'optionalAccess',
|
|
14180
|
+
if (_optionalChain([intermediateData, 'optionalAccess', _376 => _376.toolUses])) {
|
|
13648
14181
|
return intermediateData.toolUses.map((t) => JSON.stringify(t)).join("\n");
|
|
13649
14182
|
}
|
|
13650
14183
|
return "";
|
|
@@ -13699,7 +14232,7 @@ ${failures.join(
|
|
|
13699
14232
|
for (const [metricName, evalMetricResultsWithInvocations] of Object.entries(
|
|
13700
14233
|
evalMetricResults
|
|
13701
14234
|
)) {
|
|
13702
|
-
const threshold = _optionalChain([evalMetricResultsWithInvocations, 'access',
|
|
14235
|
+
const threshold = _optionalChain([evalMetricResultsWithInvocations, 'access', _377 => _377[0], 'optionalAccess', _378 => _378.evalMetricResult, 'access', _379 => _379.threshold]) || 0;
|
|
13703
14236
|
const scores = evalMetricResultsWithInvocations.map((m) => m.evalMetricResult.score).filter((s) => s !== void 0);
|
|
13704
14237
|
let overallScore;
|
|
13705
14238
|
let overallEvalStatus;
|
|
@@ -13788,7 +14321,7 @@ var RougeEvaluator = class extends Evaluator {
|
|
|
13788
14321
|
}
|
|
13789
14322
|
};
|
|
13790
14323
|
function getTextFromContent2(content) {
|
|
13791
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
14324
|
+
if (_optionalChain([content, 'optionalAccess', _380 => _380.parts])) {
|
|
13792
14325
|
return content.parts.map((part) => part.text).filter(Boolean).join("\n");
|
|
13793
14326
|
}
|
|
13794
14327
|
return "";
|
|
@@ -13984,4 +14517,9 @@ var VERSION = "0.1.0";
|
|
|
13984
14517
|
|
|
13985
14518
|
|
|
13986
14519
|
|
|
13987
|
-
|
|
14520
|
+
|
|
14521
|
+
|
|
14522
|
+
|
|
14523
|
+
|
|
14524
|
+
|
|
14525
|
+
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.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;
|