@iqai/adk 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +129 -4
- package/dist/index.d.ts +129 -4
- package/dist/index.js +413 -113
- package/dist/index.mjs +315 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3389,6 +3389,11 @@ 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
|
+
|
|
3392
3397
|
/**
|
|
3393
3398
|
* Constructor for EventActions
|
|
3394
3399
|
*/
|
|
@@ -3399,6 +3404,7 @@ var EventActions = (_class10 = class {
|
|
|
3399
3404
|
this.transferToAgent = options.transferToAgent;
|
|
3400
3405
|
this.escalate = options.escalate;
|
|
3401
3406
|
this.requestedAuthConfigs = options.requestedAuthConfigs;
|
|
3407
|
+
this.compaction = options.compaction;
|
|
3402
3408
|
}
|
|
3403
3409
|
}, _class10);
|
|
3404
3410
|
|
|
@@ -3941,9 +3947,196 @@ init_logger();
|
|
|
3941
3947
|
var events_exports = {};
|
|
3942
3948
|
__export(events_exports, {
|
|
3943
3949
|
Event: () => Event,
|
|
3944
|
-
EventActions: () => EventActions
|
|
3950
|
+
EventActions: () => EventActions,
|
|
3951
|
+
LlmEventSummarizer: () => LlmEventSummarizer,
|
|
3952
|
+
runCompactionForSlidingWindow: () => runCompactionForSlidingWindow
|
|
3945
3953
|
});
|
|
3946
3954
|
|
|
3955
|
+
// src/events/llm-event-summarizer.ts
|
|
3956
|
+
var DEFAULT_SUMMARIZATION_PROMPT = `You are a helpful assistant tasked with summarizing a conversation history.
|
|
3957
|
+
Please provide a concise summary of the following events, capturing the key information and context.
|
|
3958
|
+
Focus on the main topics discussed, important decisions made, and any action items or results.
|
|
3959
|
+
|
|
3960
|
+
Events to summarize:
|
|
3961
|
+
{events}
|
|
3962
|
+
|
|
3963
|
+
Provide your summary in a clear, concise format.`;
|
|
3964
|
+
var LlmEventSummarizer = class {
|
|
3965
|
+
|
|
3966
|
+
|
|
3967
|
+
/**
|
|
3968
|
+
* Creates a new LLM event summarizer.
|
|
3969
|
+
* @param model - The LLM model to use for summarization
|
|
3970
|
+
* @param prompt - Optional custom prompt template. Use {events} as placeholder for event content.
|
|
3971
|
+
*/
|
|
3972
|
+
constructor(model, prompt) {
|
|
3973
|
+
this.model = model;
|
|
3974
|
+
this.prompt = prompt || DEFAULT_SUMMARIZATION_PROMPT;
|
|
3975
|
+
}
|
|
3976
|
+
/**
|
|
3977
|
+
* Summarizes events using the configured LLM.
|
|
3978
|
+
*/
|
|
3979
|
+
async maybeSummarizeEvents(events) {
|
|
3980
|
+
if (!events || events.length === 0) {
|
|
3981
|
+
return void 0;
|
|
3982
|
+
}
|
|
3983
|
+
const eventsText = this.formatEventsForSummarization(events);
|
|
3984
|
+
const promptWithEvents = this.prompt.replace("{events}", eventsText);
|
|
3985
|
+
const llmRequest = new LlmRequest({
|
|
3986
|
+
contents: [
|
|
3987
|
+
{
|
|
3988
|
+
role: "user",
|
|
3989
|
+
parts: [{ text: promptWithEvents }]
|
|
3990
|
+
}
|
|
3991
|
+
]
|
|
3992
|
+
});
|
|
3993
|
+
let summaryText = "";
|
|
3994
|
+
for await (const response of this.model.generateContentAsync(llmRequest)) {
|
|
3995
|
+
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("")]);
|
|
3996
|
+
}
|
|
3997
|
+
summaryText = summaryText.trim();
|
|
3998
|
+
if (!summaryText) {
|
|
3999
|
+
return void 0;
|
|
4000
|
+
}
|
|
4001
|
+
const summaryContent = {
|
|
4002
|
+
role: "model",
|
|
4003
|
+
parts: [{ text: summaryText }]
|
|
4004
|
+
};
|
|
4005
|
+
const compactionEvent = new Event({
|
|
4006
|
+
invocationId: Event.newId(),
|
|
4007
|
+
author: "user",
|
|
4008
|
+
actions: new EventActions({
|
|
4009
|
+
compaction: {
|
|
4010
|
+
startTimestamp: events[0].timestamp,
|
|
4011
|
+
endTimestamp: events[events.length - 1].timestamp,
|
|
4012
|
+
compactedContent: summaryContent
|
|
4013
|
+
}
|
|
4014
|
+
})
|
|
4015
|
+
});
|
|
4016
|
+
return compactionEvent;
|
|
4017
|
+
}
|
|
4018
|
+
/**
|
|
4019
|
+
* Formats events into a readable text format for summarization.
|
|
4020
|
+
*/
|
|
4021
|
+
formatEventsForSummarization(events) {
|
|
4022
|
+
const lines = [];
|
|
4023
|
+
for (const event of events) {
|
|
4024
|
+
const timestamp = new Date(event.timestamp * 1e3).toISOString();
|
|
4025
|
+
const author = event.author;
|
|
4026
|
+
if (_optionalChain([event, 'access', _149 => _149.content, 'optionalAccess', _150 => _150.parts])) {
|
|
4027
|
+
for (const part of event.content.parts) {
|
|
4028
|
+
if (part.text) {
|
|
4029
|
+
lines.push(`[${timestamp}] ${author}: ${part.text}`);
|
|
4030
|
+
} else if (part.functionCall) {
|
|
4031
|
+
lines.push(
|
|
4032
|
+
`[${timestamp}] ${author}: Called tool '${part.functionCall.name}' with args ${JSON.stringify(part.functionCall.args)}`
|
|
4033
|
+
);
|
|
4034
|
+
} else if (part.functionResponse) {
|
|
4035
|
+
lines.push(
|
|
4036
|
+
`[${timestamp}] ${author}: Tool '${part.functionResponse.name}' returned: ${JSON.stringify(part.functionResponse.response)}`
|
|
4037
|
+
);
|
|
4038
|
+
}
|
|
4039
|
+
}
|
|
4040
|
+
}
|
|
4041
|
+
}
|
|
4042
|
+
return lines.join("\n");
|
|
4043
|
+
}
|
|
4044
|
+
};
|
|
4045
|
+
|
|
4046
|
+
// src/events/compaction.ts
|
|
4047
|
+
init_logger();
|
|
4048
|
+
var logger = new Logger({ name: "EventCompaction" });
|
|
4049
|
+
async function runCompactionForSlidingWindow(config, session, sessionService, summarizer) {
|
|
4050
|
+
if (!session.events || session.events.length === 0) {
|
|
4051
|
+
return;
|
|
4052
|
+
}
|
|
4053
|
+
const lastCompactedEndTimestamp = findLastCompactedEndTimestamp(
|
|
4054
|
+
session.events
|
|
4055
|
+
);
|
|
4056
|
+
const latestTimestampByInvocation = buildLatestTimestampByInvocation(
|
|
4057
|
+
session.events
|
|
4058
|
+
);
|
|
4059
|
+
const uniqueInvocationIds = Array.from(latestTimestampByInvocation.keys());
|
|
4060
|
+
const newInvocationIds = uniqueInvocationIds.filter(
|
|
4061
|
+
(invId) => (latestTimestampByInvocation.get(invId) || 0) > lastCompactedEndTimestamp
|
|
4062
|
+
);
|
|
4063
|
+
if (newInvocationIds.length < config.compactionInterval) {
|
|
4064
|
+
logger.debug(
|
|
4065
|
+
`Not enough new invocations for compaction. Need ${config.compactionInterval}, have ${newInvocationIds.length}`
|
|
4066
|
+
);
|
|
4067
|
+
return;
|
|
4068
|
+
}
|
|
4069
|
+
const endInvId = newInvocationIds[newInvocationIds.length - 1];
|
|
4070
|
+
const firstNewInvId = newInvocationIds[0];
|
|
4071
|
+
const firstNewInvIdx = uniqueInvocationIds.indexOf(firstNewInvId);
|
|
4072
|
+
const startIdx = Math.max(0, firstNewInvIdx - config.overlapSize);
|
|
4073
|
+
const startInvId = uniqueInvocationIds[startIdx];
|
|
4074
|
+
logger.debug(
|
|
4075
|
+
`Compacting invocations from ${startInvId} to ${endInvId} (${newInvocationIds.length} new invocations, overlap: ${config.overlapSize})`
|
|
4076
|
+
);
|
|
4077
|
+
const eventsToCompact = sliceEventsByInvocationRange(
|
|
4078
|
+
session.events,
|
|
4079
|
+
startInvId,
|
|
4080
|
+
endInvId
|
|
4081
|
+
);
|
|
4082
|
+
if (eventsToCompact.length === 0) {
|
|
4083
|
+
logger.debug("No events to compact after filtering");
|
|
4084
|
+
return;
|
|
4085
|
+
}
|
|
4086
|
+
logger.debug(`Summarizing ${eventsToCompact.length} events`);
|
|
4087
|
+
const compactionEvent = await summarizer.maybeSummarizeEvents(eventsToCompact);
|
|
4088
|
+
if (compactionEvent) {
|
|
4089
|
+
logger.debug(
|
|
4090
|
+
`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])}`
|
|
4091
|
+
);
|
|
4092
|
+
await sessionService.appendEvent(session, compactionEvent);
|
|
4093
|
+
}
|
|
4094
|
+
}
|
|
4095
|
+
function findLastCompactedEndTimestamp(events) {
|
|
4096
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
4097
|
+
const event = events[i];
|
|
4098
|
+
if (_optionalChain([event, 'access', _157 => _157.actions, 'optionalAccess', _158 => _158.compaction])) {
|
|
4099
|
+
return event.actions.compaction.endTimestamp;
|
|
4100
|
+
}
|
|
4101
|
+
}
|
|
4102
|
+
return 0;
|
|
4103
|
+
}
|
|
4104
|
+
function buildLatestTimestampByInvocation(events) {
|
|
4105
|
+
const latestByInvocation = /* @__PURE__ */ new Map();
|
|
4106
|
+
for (const event of events) {
|
|
4107
|
+
if (_optionalChain([event, 'access', _159 => _159.actions, 'optionalAccess', _160 => _160.compaction])) {
|
|
4108
|
+
continue;
|
|
4109
|
+
}
|
|
4110
|
+
const invId = event.invocationId;
|
|
4111
|
+
if (!invId) {
|
|
4112
|
+
continue;
|
|
4113
|
+
}
|
|
4114
|
+
const current = latestByInvocation.get(invId) || 0;
|
|
4115
|
+
if (event.timestamp > current) {
|
|
4116
|
+
latestByInvocation.set(invId, event.timestamp);
|
|
4117
|
+
}
|
|
4118
|
+
}
|
|
4119
|
+
return latestByInvocation;
|
|
4120
|
+
}
|
|
4121
|
+
function sliceEventsByInvocationRange(events, startInvId, endInvId) {
|
|
4122
|
+
let firstIndex = -1;
|
|
4123
|
+
let lastIndex = -1;
|
|
4124
|
+
for (let i = 0; i < events.length; i++) {
|
|
4125
|
+
const event = events[i];
|
|
4126
|
+
if (event.invocationId === startInvId && firstIndex === -1) {
|
|
4127
|
+
firstIndex = i;
|
|
4128
|
+
}
|
|
4129
|
+
if (event.invocationId === endInvId) {
|
|
4130
|
+
lastIndex = i;
|
|
4131
|
+
}
|
|
4132
|
+
}
|
|
4133
|
+
if (firstIndex === -1 || lastIndex === -1 || firstIndex > lastIndex) {
|
|
4134
|
+
return [];
|
|
4135
|
+
}
|
|
4136
|
+
const slicedEvents = events.slice(firstIndex, lastIndex + 1);
|
|
4137
|
+
return slicedEvents.filter((event) => !_optionalChain([event, 'access', _161 => _161.actions, 'optionalAccess', _162 => _162.compaction]));
|
|
4138
|
+
}
|
|
4139
|
+
|
|
3947
4140
|
// src/flows/llm-flows/base-llm-flow.ts
|
|
3948
4141
|
init_logger();
|
|
3949
4142
|
|
|
@@ -4454,7 +4647,7 @@ var AgentTool = (_class15 = class extends BaseTool {
|
|
|
4454
4647
|
} catch (e3) {
|
|
4455
4648
|
toolResult = mergedText;
|
|
4456
4649
|
}
|
|
4457
|
-
if (this.outputKey && _optionalChain([context4, 'optionalAccess',
|
|
4650
|
+
if (this.outputKey && _optionalChain([context4, 'optionalAccess', _163 => _163.state])) {
|
|
4458
4651
|
context4.state[this.outputKey] = toolResult;
|
|
4459
4652
|
}
|
|
4460
4653
|
return toolResult;
|
|
@@ -4721,7 +4914,7 @@ var FileOperationsTool = class extends BaseTool {
|
|
|
4721
4914
|
name: "file_operations",
|
|
4722
4915
|
description: "Perform file system operations like reading, writing, and managing files"
|
|
4723
4916
|
});
|
|
4724
|
-
this.basePath = _optionalChain([options, 'optionalAccess',
|
|
4917
|
+
this.basePath = _optionalChain([options, 'optionalAccess', _164 => _164.basePath]) || process.cwd();
|
|
4725
4918
|
}
|
|
4726
4919
|
/**
|
|
4727
4920
|
* Get the function declaration for the tool
|
|
@@ -5204,7 +5397,7 @@ var LoadMemoryTool = (_class20 = class extends BaseTool {
|
|
|
5204
5397
|
const searchResult = await context4.searchMemory(args.query);
|
|
5205
5398
|
return {
|
|
5206
5399
|
memories: searchResult.memories || [],
|
|
5207
|
-
count: _optionalChain([searchResult, 'access',
|
|
5400
|
+
count: _optionalChain([searchResult, 'access', _165 => _165.memories, 'optionalAccess', _166 => _166.length]) || 0
|
|
5208
5401
|
};
|
|
5209
5402
|
} catch (error) {
|
|
5210
5403
|
console.error("Error searching memory:", error);
|
|
@@ -5761,7 +5954,7 @@ var McpClientService = (_class22 = class {
|
|
|
5761
5954
|
},
|
|
5762
5955
|
this,
|
|
5763
5956
|
async (instance) => await instance.reinitialize(),
|
|
5764
|
-
_optionalChain([this, 'access',
|
|
5957
|
+
_optionalChain([this, 'access', _167 => _167.config, 'access', _168 => _168.retryOptions, 'optionalAccess', _169 => _169.maxRetries]) || 2
|
|
5765
5958
|
);
|
|
5766
5959
|
return await wrappedCall();
|
|
5767
5960
|
} catch (error) {
|
|
@@ -5845,7 +6038,7 @@ var McpClientService = (_class22 = class {
|
|
|
5845
6038
|
this.mcpSamplingHandler = null;
|
|
5846
6039
|
if (this.client) {
|
|
5847
6040
|
try {
|
|
5848
|
-
_optionalChain([this, 'access',
|
|
6041
|
+
_optionalChain([this, 'access', _170 => _170.client, 'access', _171 => _171.removeRequestHandler, 'optionalCall', _172 => _172("sampling/createMessage")]);
|
|
5849
6042
|
} catch (error) {
|
|
5850
6043
|
this.logger.error("Failed to remove sampling handler:", error);
|
|
5851
6044
|
}
|
|
@@ -6381,7 +6574,7 @@ var McpToolset = (_class24 = class {
|
|
|
6381
6574
|
"resource_closed_error" /* RESOURCE_CLOSED_ERROR */
|
|
6382
6575
|
);
|
|
6383
6576
|
}
|
|
6384
|
-
if (this.tools.length > 0 && !_optionalChain([this, 'access',
|
|
6577
|
+
if (this.tools.length > 0 && !_optionalChain([this, 'access', _173 => _173.config, 'access', _174 => _174.cacheConfig, 'optionalAccess', _175 => _175.enabled]) === false) {
|
|
6385
6578
|
return this.tools;
|
|
6386
6579
|
}
|
|
6387
6580
|
if (!this.clientService) {
|
|
@@ -6410,7 +6603,7 @@ var McpToolset = (_class24 = class {
|
|
|
6410
6603
|
}
|
|
6411
6604
|
}
|
|
6412
6605
|
}
|
|
6413
|
-
if (_optionalChain([this, 'access',
|
|
6606
|
+
if (_optionalChain([this, 'access', _176 => _176.config, 'access', _177 => _177.cacheConfig, 'optionalAccess', _178 => _178.enabled]) !== false) {
|
|
6414
6607
|
this.tools = tools;
|
|
6415
6608
|
}
|
|
6416
6609
|
return tools;
|
|
@@ -6499,12 +6692,12 @@ function populateClientFunctionCallId(modelResponseEvent) {
|
|
|
6499
6692
|
}
|
|
6500
6693
|
}
|
|
6501
6694
|
function removeClientFunctionCallId(content) {
|
|
6502
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
6695
|
+
if (_optionalChain([content, 'optionalAccess', _179 => _179.parts])) {
|
|
6503
6696
|
for (const part of content.parts) {
|
|
6504
|
-
if (_optionalChain([part, 'access',
|
|
6697
|
+
if (_optionalChain([part, 'access', _180 => _180.functionCall, 'optionalAccess', _181 => _181.id, 'optionalAccess', _182 => _182.startsWith, 'call', _183 => _183(AF_FUNCTION_CALL_ID_PREFIX)])) {
|
|
6505
6698
|
part.functionCall.id = void 0;
|
|
6506
6699
|
}
|
|
6507
|
-
if (_optionalChain([part, 'access',
|
|
6700
|
+
if (_optionalChain([part, 'access', _184 => _184.functionResponse, 'optionalAccess', _185 => _185.id, 'optionalAccess', _186 => _186.startsWith, 'call', _187 => _187(AF_FUNCTION_CALL_ID_PREFIX)])) {
|
|
6508
6701
|
part.functionResponse.id = void 0;
|
|
6509
6702
|
}
|
|
6510
6703
|
}
|
|
@@ -6699,7 +6892,7 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
|
|
|
6699
6892
|
}
|
|
6700
6893
|
const mergedParts = [];
|
|
6701
6894
|
for (const event of functionResponseEvents) {
|
|
6702
|
-
if (_optionalChain([event, 'access',
|
|
6895
|
+
if (_optionalChain([event, 'access', _188 => _188.content, 'optionalAccess', _189 => _189.parts])) {
|
|
6703
6896
|
for (const part of event.content.parts) {
|
|
6704
6897
|
mergedParts.push(part);
|
|
6705
6898
|
}
|
|
@@ -6820,7 +7013,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6820
7013
|
const seen = /* @__PURE__ */ new Set();
|
|
6821
7014
|
const filtered = [];
|
|
6822
7015
|
for (const t of tools) {
|
|
6823
|
-
const name = _optionalChain([t, 'optionalAccess',
|
|
7016
|
+
const name = _optionalChain([t, 'optionalAccess', _190 => _190.name]);
|
|
6824
7017
|
if (!name) continue;
|
|
6825
7018
|
if (seen.has(name)) {
|
|
6826
7019
|
continue;
|
|
@@ -6837,7 +7030,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6837
7030
|
if (tools.length > 0) {
|
|
6838
7031
|
const toolsData = tools.map((tool) => ({
|
|
6839
7032
|
Name: tool.name,
|
|
6840
|
-
Description: _optionalChain([tool, 'access',
|
|
7033
|
+
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
7034
|
"Long Running": tool.isLongRunning ? "Yes" : "No"
|
|
6842
7035
|
}));
|
|
6843
7036
|
this.logger.debugArray("\u{1F6E0}\uFE0F Available Tools", toolsData);
|
|
@@ -6900,14 +7093,14 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6900
7093
|
);
|
|
6901
7094
|
if (functionResponseEvent) {
|
|
6902
7095
|
yield functionResponseEvent;
|
|
6903
|
-
const transferToAgent = _optionalChain([functionResponseEvent, 'access',
|
|
7096
|
+
const transferToAgent = _optionalChain([functionResponseEvent, 'access', _196 => _196.actions, 'optionalAccess', _197 => _197.transferToAgent]);
|
|
6904
7097
|
if (transferToAgent) {
|
|
6905
7098
|
this.logger.debug(`\u{1F504} Live transfer to agent '${transferToAgent}'`);
|
|
6906
7099
|
const agentToRun = this._getAgentToRun(
|
|
6907
7100
|
invocationContext,
|
|
6908
7101
|
transferToAgent
|
|
6909
7102
|
);
|
|
6910
|
-
for await (const event of _optionalChain([agentToRun, 'access',
|
|
7103
|
+
for await (const event of _optionalChain([agentToRun, 'access', _198 => _198.runLive, 'optionalCall', _199 => _199(invocationContext)]) || agentToRun.runAsync(invocationContext)) {
|
|
6911
7104
|
yield event;
|
|
6912
7105
|
}
|
|
6913
7106
|
}
|
|
@@ -6939,7 +7132,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6939
7132
|
yield authEvent;
|
|
6940
7133
|
}
|
|
6941
7134
|
yield functionResponseEvent;
|
|
6942
|
-
const transferToAgent = _optionalChain([functionResponseEvent, 'access',
|
|
7135
|
+
const transferToAgent = _optionalChain([functionResponseEvent, 'access', _200 => _200.actions, 'optionalAccess', _201 => _201.transferToAgent]);
|
|
6943
7136
|
if (transferToAgent) {
|
|
6944
7137
|
this.logger.debug(`\u{1F504} Transferring to agent '${transferToAgent}'`);
|
|
6945
7138
|
const agentToRun = this._getAgentToRun(
|
|
@@ -6985,7 +7178,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6985
7178
|
}
|
|
6986
7179
|
invocationContext.incrementLlmCallCount();
|
|
6987
7180
|
const isStreaming = invocationContext.runConfig.streamingMode === "sse" /* SSE */;
|
|
6988
|
-
let tools = _optionalChain([llmRequest, 'access',
|
|
7181
|
+
let tools = _optionalChain([llmRequest, 'access', _202 => _202.config, 'optionalAccess', _203 => _203.tools]) || [];
|
|
6989
7182
|
if (tools.length) {
|
|
6990
7183
|
const deduped = [];
|
|
6991
7184
|
const seenFn = /* @__PURE__ */ new Set();
|
|
@@ -6994,7 +7187,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6994
7187
|
if (tool && Array.isArray(tool.functionDeclarations)) {
|
|
6995
7188
|
const newFds = tool.functionDeclarations.filter(
|
|
6996
7189
|
(fd) => {
|
|
6997
|
-
if (_optionalChain([fd, 'optionalAccess',
|
|
7190
|
+
if (_optionalChain([fd, 'optionalAccess', _204 => _204.name])) {
|
|
6998
7191
|
if (seenFn.has(fd.name)) {
|
|
6999
7192
|
return false;
|
|
7000
7193
|
}
|
|
@@ -7006,7 +7199,7 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
7006
7199
|
if (newFds.length) {
|
|
7007
7200
|
deduped.push({ ...tool, functionDeclarations: newFds });
|
|
7008
7201
|
}
|
|
7009
|
-
} else if (_optionalChain([tool, 'optionalAccess',
|
|
7202
|
+
} else if (_optionalChain([tool, 'optionalAccess', _205 => _205.name])) {
|
|
7010
7203
|
if (seenFn.has(tool.name)) continue;
|
|
7011
7204
|
seenFn.add(tool.name);
|
|
7012
7205
|
deduped.push(tool);
|
|
@@ -7026,21 +7219,21 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
7026
7219
|
return tool.functionDeclarations.map((fn) => fn.name).join(", ");
|
|
7027
7220
|
}
|
|
7028
7221
|
if (tool.name) return tool.name;
|
|
7029
|
-
if (_optionalChain([tool, 'access',
|
|
7030
|
-
if (_optionalChain([tool, 'access',
|
|
7222
|
+
if (_optionalChain([tool, 'access', _206 => _206.function, 'optionalAccess', _207 => _207.name])) return tool.function.name;
|
|
7223
|
+
if (_optionalChain([tool, 'access', _208 => _208.function, 'optionalAccess', _209 => _209.function, 'optionalAccess', _210 => _210.name])) return tool.function.function.name;
|
|
7031
7224
|
return "unknown";
|
|
7032
7225
|
}).join(", ");
|
|
7033
7226
|
const systemInstruction = llmRequest.getSystemInstructionText() || "";
|
|
7034
7227
|
const truncatedSystemInstruction = systemInstruction.length > 100 ? `${systemInstruction.substring(0, 100)}...` : systemInstruction;
|
|
7035
|
-
const contentPreview = _optionalChain([llmRequest, 'access',
|
|
7228
|
+
const contentPreview = _optionalChain([llmRequest, 'access', _211 => _211.contents, 'optionalAccess', _212 => _212.length]) > 0 ? LogFormatter.formatContentPreview(llmRequest.contents[0]) : "none";
|
|
7036
7229
|
this.logger.debugStructured("\u{1F4E4} LLM Request", {
|
|
7037
7230
|
Model: llm.model,
|
|
7038
7231
|
Agent: invocationContext.agent.name,
|
|
7039
|
-
"Content Items": _optionalChain([llmRequest, 'access',
|
|
7232
|
+
"Content Items": _optionalChain([llmRequest, 'access', _213 => _213.contents, 'optionalAccess', _214 => _214.length]) || 0,
|
|
7040
7233
|
"Content Preview": contentPreview,
|
|
7041
7234
|
"System Instruction": truncatedSystemInstruction || "none",
|
|
7042
7235
|
"Available Tools": toolNames || "none",
|
|
7043
|
-
"Tool Count": _optionalChain([llmRequest, 'access',
|
|
7236
|
+
"Tool Count": _optionalChain([llmRequest, 'access', _215 => _215.config, 'optionalAccess', _216 => _216.tools, 'optionalAccess', _217 => _217.length]) || 0,
|
|
7044
7237
|
Streaming: isStreaming ? "Yes" : "No"
|
|
7045
7238
|
});
|
|
7046
7239
|
let responseCount = 0;
|
|
@@ -7055,8 +7248,8 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
7055
7248
|
llmRequest,
|
|
7056
7249
|
llmResponse
|
|
7057
7250
|
);
|
|
7058
|
-
const tokenCount = _optionalChain([llmResponse, 'access',
|
|
7059
|
-
const functionCalls = _optionalChain([llmResponse, 'access',
|
|
7251
|
+
const tokenCount = _optionalChain([llmResponse, 'access', _218 => _218.usageMetadata, 'optionalAccess', _219 => _219.totalTokenCount]) || "unknown";
|
|
7252
|
+
const functionCalls = _optionalChain([llmResponse, 'access', _220 => _220.content, 'optionalAccess', _221 => _221.parts, 'optionalAccess', _222 => _222.filter, 'call', _223 => _223((part) => part.functionCall)]) || [];
|
|
7060
7253
|
const functionCallsDisplay = LogFormatter.formatFunctionCalls(functionCalls);
|
|
7061
7254
|
const responsePreview = LogFormatter.formatResponsePreview(llmResponse);
|
|
7062
7255
|
this.logger.debugStructured("\u{1F4E5} LLM Response", {
|
|
@@ -7200,7 +7393,7 @@ var EnhancedAuthConfig = class {
|
|
|
7200
7393
|
*/
|
|
7201
7394
|
generateCredentialKey() {
|
|
7202
7395
|
const schemeKey = this.authScheme.type || "unknown";
|
|
7203
|
-
const credentialKey = _optionalChain([this, 'access',
|
|
7396
|
+
const credentialKey = _optionalChain([this, 'access', _224 => _224.rawAuthCredential, 'optionalAccess', _225 => _225.type]) || "none";
|
|
7204
7397
|
const timestamp = Date.now();
|
|
7205
7398
|
return `adk_${schemeKey}_${credentialKey}_${timestamp}`;
|
|
7206
7399
|
}
|
|
@@ -7357,7 +7550,7 @@ var AuthLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
7357
7550
|
*/
|
|
7358
7551
|
parseAndStoreAuthResponse(authHandler, invocationContext) {
|
|
7359
7552
|
try {
|
|
7360
|
-
const credentialKey = _optionalChain([authHandler, 'access',
|
|
7553
|
+
const credentialKey = _optionalChain([authHandler, 'access', _226 => _226.authConfig, 'access', _227 => _227.context, 'optionalAccess', _228 => _228.credentialKey]) || `temp:${Date.now()}`;
|
|
7361
7554
|
const fullCredentialKey = credentialKey.startsWith("temp:") ? credentialKey : `temp:${credentialKey}`;
|
|
7362
7555
|
invocationContext.session.state[fullCredentialKey] = authHandler.credential;
|
|
7363
7556
|
if (authHandler.authConfig.authScheme.type === "oauth2" || authHandler.authConfig.authScheme.type === "openIdConnect") {
|
|
@@ -7386,15 +7579,15 @@ var BasicLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
7386
7579
|
llmRequest.config = {};
|
|
7387
7580
|
}
|
|
7388
7581
|
if (agent.outputSchema) {
|
|
7389
|
-
const hasTools = await _asyncOptionalChain([(await _optionalChain([agent, 'access',
|
|
7582
|
+
const hasTools = await _asyncOptionalChain([(await _optionalChain([agent, 'access', _229 => _229.canonicalTools, 'optionalCall', _230 => _230(invocationContext)])), 'optionalAccess', async _231 => _231.length]) > 0;
|
|
7390
7583
|
const hasTransfers = !!("subAgents" in agent && agent.subAgents && agent.subAgents.length > 0 && !(agent.disallowTransferToParent && agent.disallowTransferToPeers));
|
|
7391
7584
|
if (!hasTools && !hasTransfers) {
|
|
7392
7585
|
llmRequest.setOutputSchema(agent.outputSchema);
|
|
7393
7586
|
} else {
|
|
7394
7587
|
(() => {
|
|
7395
7588
|
try {
|
|
7396
|
-
const
|
|
7397
|
-
|
|
7589
|
+
const logger2 = new Logger({ name: "BasicLlmRequestProcessor" });
|
|
7590
|
+
logger2.debug(
|
|
7398
7591
|
`Skipping request-level output schema for agent ${agent.name} because tools/transfers are present. Schema will be validated during response processing.`
|
|
7399
7592
|
);
|
|
7400
7593
|
} catch (e) {
|
|
@@ -7478,7 +7671,7 @@ var BuiltInCodeExecutor = class extends BaseCodeExecutor {
|
|
|
7478
7671
|
* Pre-process the LLM request for Gemini 2.0+ models to use the code execution tool
|
|
7479
7672
|
*/
|
|
7480
7673
|
processLlmRequest(llmRequest) {
|
|
7481
|
-
if (!_optionalChain([llmRequest, 'access',
|
|
7674
|
+
if (!_optionalChain([llmRequest, 'access', _232 => _232.model, 'optionalAccess', _233 => _233.startsWith, 'call', _234 => _234("gemini-2")])) {
|
|
7482
7675
|
throw new Error(
|
|
7483
7676
|
`Gemini code execution tool is not supported for model ${llmRequest.model}`
|
|
7484
7677
|
);
|
|
@@ -7523,7 +7716,7 @@ var CodeExecutionUtils = class _CodeExecutionUtils {
|
|
|
7523
7716
|
* Extracts the first code block from the content and truncates everything after it
|
|
7524
7717
|
*/
|
|
7525
7718
|
static extractCodeAndTruncateContent(content, codeBlockDelimiters) {
|
|
7526
|
-
if (!_optionalChain([content, 'optionalAccess',
|
|
7719
|
+
if (!_optionalChain([content, 'optionalAccess', _235 => _235.parts, 'optionalAccess', _236 => _236.length])) {
|
|
7527
7720
|
return null;
|
|
7528
7721
|
}
|
|
7529
7722
|
for (let idx = 0; idx < content.parts.length; idx++) {
|
|
@@ -7609,7 +7802,7 @@ ${fileNames}`);
|
|
|
7609
7802
|
* Converts the code execution parts to text parts in a Content
|
|
7610
7803
|
*/
|
|
7611
7804
|
static convertCodeExecutionParts(content, codeBlockDelimiter, executionResultDelimiters) {
|
|
7612
|
-
if (!_optionalChain([content, 'access',
|
|
7805
|
+
if (!_optionalChain([content, 'access', _237 => _237.parts, 'optionalAccess', _238 => _238.length])) {
|
|
7613
7806
|
return;
|
|
7614
7807
|
}
|
|
7615
7808
|
const lastPart = content.parts[content.parts.length - 1];
|
|
@@ -8002,7 +8195,7 @@ async function* runPostProcessor(invocationContext, llmResponse) {
|
|
|
8002
8195
|
function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
|
|
8003
8196
|
const allInputFiles = codeExecutorContext.getInputFiles();
|
|
8004
8197
|
const savedFileNames = new Set(allInputFiles.map((f) => f.name));
|
|
8005
|
-
for (let i = 0; i < (_optionalChain([llmRequest, 'access',
|
|
8198
|
+
for (let i = 0; i < (_optionalChain([llmRequest, 'access', _239 => _239.contents, 'optionalAccess', _240 => _240.length]) || 0); i++) {
|
|
8006
8199
|
const content = llmRequest.contents[i];
|
|
8007
8200
|
if (content.role !== "user" || !content.parts) {
|
|
8008
8201
|
continue;
|
|
@@ -8034,7 +8227,7 @@ Available file: \`${fileName}\`
|
|
|
8034
8227
|
}
|
|
8035
8228
|
function getOrSetExecutionId(invocationContext, codeExecutorContext) {
|
|
8036
8229
|
const agent = invocationContext.agent;
|
|
8037
|
-
if (!hasCodeExecutor(agent) || !_optionalChain([agent, 'access',
|
|
8230
|
+
if (!hasCodeExecutor(agent) || !_optionalChain([agent, 'access', _241 => _241.codeExecutor, 'optionalAccess', _242 => _242.stateful])) {
|
|
8038
8231
|
return void 0;
|
|
8039
8232
|
}
|
|
8040
8233
|
let executionId = codeExecutorContext.getExecutionId();
|
|
@@ -8265,7 +8458,7 @@ function rearrangeEventsForLatestFunctionResponse(events) {
|
|
|
8265
8458
|
continue;
|
|
8266
8459
|
}
|
|
8267
8460
|
const functionResponses2 = event.getFunctionResponses();
|
|
8268
|
-
if (_optionalChain([functionResponses2, 'optionalAccess',
|
|
8461
|
+
if (_optionalChain([functionResponses2, 'optionalAccess', _243 => _243.some, 'call', _244 => _244((fr) => fr.id && functionResponsesIds.has(fr.id))])) {
|
|
8269
8462
|
functionResponseEvents.push(event);
|
|
8270
8463
|
}
|
|
8271
8464
|
}
|
|
@@ -8296,7 +8489,8 @@ function getContents(currentBranch, events, agentName = "") {
|
|
|
8296
8489
|
isOtherAgentReply(agentName, event) ? convertForeignEvent(event) : event
|
|
8297
8490
|
);
|
|
8298
8491
|
}
|
|
8299
|
-
|
|
8492
|
+
const processedEvents = processCompactionEvents(filteredEvents);
|
|
8493
|
+
let resultEvents = rearrangeEventsForLatestFunctionResponse(processedEvents);
|
|
8300
8494
|
resultEvents = rearrangeEventsForAsyncFunctionResponsesInHistory(resultEvents);
|
|
8301
8495
|
const contents = [];
|
|
8302
8496
|
for (const event of resultEvents) {
|
|
@@ -8364,7 +8558,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
|
|
|
8364
8558
|
const partIndicesInMergedEvent = {};
|
|
8365
8559
|
for (let idx = 0; idx < partsInMergedEvent.length; idx++) {
|
|
8366
8560
|
const part = partsInMergedEvent[idx];
|
|
8367
|
-
if (_optionalChain([part, 'access',
|
|
8561
|
+
if (_optionalChain([part, 'access', _245 => _245.functionResponse, 'optionalAccess', _246 => _246.id])) {
|
|
8368
8562
|
partIndicesInMergedEvent[part.functionResponse.id] = idx;
|
|
8369
8563
|
}
|
|
8370
8564
|
}
|
|
@@ -8373,7 +8567,7 @@ function mergeFunctionResponseEvents(functionResponseEvents) {
|
|
|
8373
8567
|
throw new Error("There should be at least one function_response part.");
|
|
8374
8568
|
}
|
|
8375
8569
|
for (const part of event.content.parts) {
|
|
8376
|
-
if (_optionalChain([part, 'access',
|
|
8570
|
+
if (_optionalChain([part, 'access', _247 => _247.functionResponse, 'optionalAccess', _248 => _248.id])) {
|
|
8377
8571
|
const functionCallId = part.functionResponse.id;
|
|
8378
8572
|
if (functionCallId in partIndicesInMergedEvent) {
|
|
8379
8573
|
partsInMergedEvent[partIndicesInMergedEvent[functionCallId]] = part;
|
|
@@ -8408,6 +8602,31 @@ function isAuthEvent(event) {
|
|
|
8408
8602
|
}
|
|
8409
8603
|
return false;
|
|
8410
8604
|
}
|
|
8605
|
+
function processCompactionEvents(events) {
|
|
8606
|
+
const result = [];
|
|
8607
|
+
let lastCompactionStartTime = Number.POSITIVE_INFINITY;
|
|
8608
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
8609
|
+
const event = events[i];
|
|
8610
|
+
if (_optionalChain([event, 'access', _249 => _249.actions, 'optionalAccess', _250 => _250.compaction])) {
|
|
8611
|
+
const compaction = event.actions.compaction;
|
|
8612
|
+
const synthesizedEvent = new Event({
|
|
8613
|
+
timestamp: compaction.endTimestamp,
|
|
8614
|
+
author: "model",
|
|
8615
|
+
content: compaction.compactedContent,
|
|
8616
|
+
branch: event.branch,
|
|
8617
|
+
invocationId: event.invocationId
|
|
8618
|
+
});
|
|
8619
|
+
result.unshift(synthesizedEvent);
|
|
8620
|
+
lastCompactionStartTime = Math.min(
|
|
8621
|
+
lastCompactionStartTime,
|
|
8622
|
+
compaction.startTimestamp
|
|
8623
|
+
);
|
|
8624
|
+
} else if (event.timestamp < lastCompactionStartTime) {
|
|
8625
|
+
result.unshift(event);
|
|
8626
|
+
}
|
|
8627
|
+
}
|
|
8628
|
+
return result;
|
|
8629
|
+
}
|
|
8411
8630
|
|
|
8412
8631
|
// src/flows/llm-flows/identity.ts
|
|
8413
8632
|
var IdentityLlmRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
@@ -8640,7 +8859,7 @@ var PlanReActPlanner = class extends BasePlanner {
|
|
|
8640
8859
|
let firstFcPartIndex = -1;
|
|
8641
8860
|
for (let i = 0; i < responseParts.length; i++) {
|
|
8642
8861
|
if (responseParts[i].functionCall) {
|
|
8643
|
-
if (!_optionalChain([responseParts, 'access',
|
|
8862
|
+
if (!_optionalChain([responseParts, 'access', _251 => _251[i], 'access', _252 => _252.functionCall, 'optionalAccess', _253 => _253.name])) {
|
|
8644
8863
|
continue;
|
|
8645
8864
|
}
|
|
8646
8865
|
preservedParts.push(responseParts[i]);
|
|
@@ -8679,7 +8898,7 @@ var PlanReActPlanner = class extends BasePlanner {
|
|
|
8679
8898
|
* Handles non-function-call parts of the response
|
|
8680
8899
|
*/
|
|
8681
8900
|
_handleNonFunctionCallParts(responsePart, preservedParts) {
|
|
8682
|
-
if (_optionalChain([responsePart, 'access',
|
|
8901
|
+
if (_optionalChain([responsePart, 'access', _254 => _254.text, 'optionalAccess', _255 => _255.includes, 'call', _256 => _256(FINAL_ANSWER_TAG)])) {
|
|
8683
8902
|
const [reasoningText, finalAnswerText] = this._splitByLastPattern(
|
|
8684
8903
|
responsePart.text,
|
|
8685
8904
|
FINAL_ANSWER_TAG
|
|
@@ -8777,14 +8996,7 @@ var NlPlanningRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
8777
8996
|
llmRequest
|
|
8778
8997
|
);
|
|
8779
8998
|
if (planningInstruction) {
|
|
8780
|
-
|
|
8781
|
-
llmRequest.appendInstructions([planningInstruction]);
|
|
8782
|
-
} else {
|
|
8783
|
-
const existingInstructions = llmRequest.instructions || "";
|
|
8784
|
-
llmRequest.instructions = `${existingInstructions}
|
|
8785
|
-
|
|
8786
|
-
${planningInstruction}`;
|
|
8787
|
-
}
|
|
8999
|
+
llmRequest.appendInstructions([planningInstruction]);
|
|
8788
9000
|
}
|
|
8789
9001
|
removeThoughtFromRequest(llmRequest);
|
|
8790
9002
|
for await (const _ of []) {
|
|
@@ -8925,7 +9137,7 @@ var OutputSchemaResponseProcessor = (_class26 = class extends BaseLlmResponsePro
|
|
|
8925
9137
|
stripCodeFences(raw) {
|
|
8926
9138
|
const fencePattern = /```(?:json)?\s*([\s\S]*?)```/i;
|
|
8927
9139
|
const fenceMatch = raw.match(fencePattern);
|
|
8928
|
-
if (_optionalChain([fenceMatch, 'optionalAccess',
|
|
9140
|
+
if (_optionalChain([fenceMatch, 'optionalAccess', _257 => _257[1]])) {
|
|
8929
9141
|
return fenceMatch[1].trim();
|
|
8930
9142
|
}
|
|
8931
9143
|
const lines = raw.split(/\r?\n/).map((l) => l.trim());
|
|
@@ -8962,7 +9174,7 @@ var SharedMemoryRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
8962
9174
|
const memoryService = invocationContext.memoryService;
|
|
8963
9175
|
if (!memoryService) return;
|
|
8964
9176
|
const lastUserEvent = invocationContext.session.events.findLast(
|
|
8965
|
-
(e) => e.author === "user" && _optionalChain([e, 'access',
|
|
9177
|
+
(e) => e.author === "user" && _optionalChain([e, 'access', _258 => _258.content, 'optionalAccess', _259 => _259.parts, 'optionalAccess', _260 => _260.length])
|
|
8966
9178
|
);
|
|
8967
9179
|
if (!lastUserEvent) return;
|
|
8968
9180
|
const query = (_nullishCoalesce(lastUserEvent.content.parts, () => ( []))).map((p) => p.text || "").join(" ");
|
|
@@ -8973,7 +9185,7 @@ var SharedMemoryRequestProcessor = class extends BaseLlmRequestProcessor {
|
|
|
8973
9185
|
});
|
|
8974
9186
|
const sessionTexts = new Set(
|
|
8975
9187
|
(llmRequest.contents || []).flatMap(
|
|
8976
|
-
(c) => _optionalChain([c, 'access',
|
|
9188
|
+
(c) => _optionalChain([c, 'access', _261 => _261.parts, 'optionalAccess', _262 => _262.map, 'call', _263 => _263((p) => p.text)]) || []
|
|
8977
9189
|
)
|
|
8978
9190
|
);
|
|
8979
9191
|
for (const memory of results.memories) {
|
|
@@ -9394,7 +9606,7 @@ var LlmAgent = (_class27 = class _LlmAgent extends BaseAgent {
|
|
|
9394
9606
|
* This matches the Python implementation's _llm_flow property
|
|
9395
9607
|
*/
|
|
9396
9608
|
get llmFlow() {
|
|
9397
|
-
if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access',
|
|
9609
|
+
if (this.disallowTransferToParent && this.disallowTransferToPeers && !_optionalChain([this, 'access', _264 => _264.subAgents, 'optionalAccess', _265 => _265.length])) {
|
|
9398
9610
|
return new SingleFlow();
|
|
9399
9611
|
}
|
|
9400
9612
|
return new AutoFlow();
|
|
@@ -9410,7 +9622,7 @@ var LlmAgent = (_class27 = class _LlmAgent extends BaseAgent {
|
|
|
9410
9622
|
);
|
|
9411
9623
|
return;
|
|
9412
9624
|
}
|
|
9413
|
-
if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access',
|
|
9625
|
+
if (this.outputKey && event.isFinalResponse() && _optionalChain([event, 'access', _266 => _266.content, 'optionalAccess', _267 => _267.parts])) {
|
|
9414
9626
|
let result = event.content.parts.map((part) => part.text || "").join("");
|
|
9415
9627
|
if (this.outputSchema) {
|
|
9416
9628
|
if (!result.trim()) {
|
|
@@ -9630,7 +9842,7 @@ var LoopAgent = class extends BaseAgent {
|
|
|
9630
9842
|
for (const subAgent of this.subAgents) {
|
|
9631
9843
|
for await (const event of subAgent.runAsync(ctx)) {
|
|
9632
9844
|
yield event;
|
|
9633
|
-
if (_optionalChain([event, 'access',
|
|
9845
|
+
if (_optionalChain([event, 'access', _268 => _268.actions, 'optionalAccess', _269 => _269.escalate])) {
|
|
9634
9846
|
return;
|
|
9635
9847
|
}
|
|
9636
9848
|
}
|
|
@@ -9942,17 +10154,17 @@ var RunConfig = class {
|
|
|
9942
10154
|
*/
|
|
9943
10155
|
|
|
9944
10156
|
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',
|
|
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));
|
|
9956
10168
|
this.validateMaxLlmCalls();
|
|
9957
10169
|
}
|
|
9958
10170
|
/**
|
|
@@ -10096,7 +10308,7 @@ var InMemoryMemoryService = (_class30 = class {
|
|
|
10096
10308
|
}
|
|
10097
10309
|
const userSessions = this._sessionEvents.get(userKey);
|
|
10098
10310
|
const filteredEvents = session.events.filter(
|
|
10099
|
-
(event) => _optionalChain([event, 'access',
|
|
10311
|
+
(event) => _optionalChain([event, 'access', _281 => _281.content, 'optionalAccess', _282 => _282.parts])
|
|
10100
10312
|
);
|
|
10101
10313
|
userSessions.set(session.id, filteredEvents);
|
|
10102
10314
|
}
|
|
@@ -10235,7 +10447,7 @@ var InMemorySessionService = (_class31 = class extends BaseSessionService {const
|
|
|
10235
10447
|
return this.createSessionImpl(appName, userId, state, sessionId);
|
|
10236
10448
|
}
|
|
10237
10449
|
createSessionImpl(appName, userId, state, sessionId) {
|
|
10238
|
-
const finalSessionId = _optionalChain([sessionId, 'optionalAccess',
|
|
10450
|
+
const finalSessionId = _optionalChain([sessionId, 'optionalAccess', _283 => _283.trim, 'call', _284 => _284()]) || _crypto.randomUUID.call(void 0, );
|
|
10239
10451
|
const session = {
|
|
10240
10452
|
appName,
|
|
10241
10453
|
userId,
|
|
@@ -10392,7 +10604,7 @@ var InMemorySessionService = (_class31 = class extends BaseSessionService {const
|
|
|
10392
10604
|
warning(`sessionId ${sessionId} not in sessions[appName][userId]`);
|
|
10393
10605
|
return event;
|
|
10394
10606
|
}
|
|
10395
|
-
if (_optionalChain([event, 'access',
|
|
10607
|
+
if (_optionalChain([event, 'access', _285 => _285.actions, 'optionalAccess', _286 => _286.stateDelta])) {
|
|
10396
10608
|
for (const key in event.actions.stateDelta) {
|
|
10397
10609
|
const value = event.actions.stateDelta[key];
|
|
10398
10610
|
if (key.startsWith(State.APP_PREFIX)) {
|
|
@@ -10426,14 +10638,14 @@ function _findFunctionCallEventIfLastEventIsFunctionResponse(session) {
|
|
|
10426
10638
|
return null;
|
|
10427
10639
|
}
|
|
10428
10640
|
const lastEvent = events[events.length - 1];
|
|
10429
|
-
if (_optionalChain([lastEvent, 'access',
|
|
10430
|
-
const functionCallId = _optionalChain([lastEvent, 'access',
|
|
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(
|
|
10431
10643
|
(part) => part.functionResponse
|
|
10432
|
-
), 'optionalAccess',
|
|
10644
|
+
), 'optionalAccess', _295 => _295.functionResponse, 'optionalAccess', _296 => _296.id]);
|
|
10433
10645
|
if (!functionCallId) return null;
|
|
10434
10646
|
for (let i = events.length - 2; i >= 0; i--) {
|
|
10435
10647
|
const event = events[i];
|
|
10436
|
-
const functionCalls = _optionalChain([event, 'access',
|
|
10648
|
+
const functionCalls = _optionalChain([event, 'access', _297 => _297.getFunctionCalls, 'optionalCall', _298 => _298()]) || [];
|
|
10437
10649
|
for (const functionCall of functionCalls) {
|
|
10438
10650
|
if (functionCall.id === functionCallId) {
|
|
10439
10651
|
return event;
|
|
@@ -10464,6 +10676,10 @@ var Runner = (_class32 = class {
|
|
|
10464
10676
|
* The memory service for the runner.
|
|
10465
10677
|
*/
|
|
10466
10678
|
|
|
10679
|
+
/**
|
|
10680
|
+
* Configuration for event compaction.
|
|
10681
|
+
*/
|
|
10682
|
+
|
|
10467
10683
|
__init55() {this.logger = new Logger({ name: "Runner" })}
|
|
10468
10684
|
/**
|
|
10469
10685
|
* Initializes the Runner.
|
|
@@ -10473,13 +10689,15 @@ var Runner = (_class32 = class {
|
|
|
10473
10689
|
agent,
|
|
10474
10690
|
artifactService,
|
|
10475
10691
|
sessionService,
|
|
10476
|
-
memoryService
|
|
10692
|
+
memoryService,
|
|
10693
|
+
eventsCompactionConfig
|
|
10477
10694
|
}) {;_class32.prototype.__init55.call(this);
|
|
10478
10695
|
this.appName = appName;
|
|
10479
10696
|
this.agent = agent;
|
|
10480
10697
|
this.artifactService = artifactService;
|
|
10481
10698
|
this.sessionService = sessionService;
|
|
10482
10699
|
this.memoryService = memoryService;
|
|
10700
|
+
this.eventsCompactionConfig = eventsCompactionConfig;
|
|
10483
10701
|
}
|
|
10484
10702
|
/**
|
|
10485
10703
|
* Runs the agent synchronously.
|
|
@@ -10581,6 +10799,10 @@ var Runner = (_class32 = class {
|
|
|
10581
10799
|
}
|
|
10582
10800
|
yield event;
|
|
10583
10801
|
}
|
|
10802
|
+
await _api.context.with(
|
|
10803
|
+
spanContext,
|
|
10804
|
+
() => this._runCompaction(session, invocationContext)
|
|
10805
|
+
);
|
|
10584
10806
|
} catch (error) {
|
|
10585
10807
|
this.logger.debug("Error running agent:", error);
|
|
10586
10808
|
span.recordException(error);
|
|
@@ -10636,15 +10858,15 @@ var Runner = (_class32 = class {
|
|
|
10636
10858
|
*/
|
|
10637
10859
|
_findAgentToRun(session, rootAgent) {
|
|
10638
10860
|
const event = _findFunctionCallEventIfLastEventIsFunctionResponse(session);
|
|
10639
|
-
if (_optionalChain([event, 'optionalAccess',
|
|
10861
|
+
if (_optionalChain([event, 'optionalAccess', _299 => _299.author])) {
|
|
10640
10862
|
return rootAgent.findAgent(event.author);
|
|
10641
10863
|
}
|
|
10642
|
-
const nonUserEvents = _optionalChain([session, 'access',
|
|
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()]) || [];
|
|
10643
10865
|
for (const event2 of nonUserEvents) {
|
|
10644
10866
|
if (event2.author === rootAgent.name) {
|
|
10645
10867
|
return rootAgent;
|
|
10646
10868
|
}
|
|
10647
|
-
const agent = _optionalChain([rootAgent, 'access',
|
|
10869
|
+
const agent = _optionalChain([rootAgent, 'access', _305 => _305.findSubAgent, 'optionalCall', _306 => _306(event2.author)]);
|
|
10648
10870
|
if (!agent) {
|
|
10649
10871
|
this.logger.debug(
|
|
10650
10872
|
`Event from an unknown agent: ${event2.author}, event id: ${event2.id}`
|
|
@@ -10693,6 +10915,52 @@ var Runner = (_class32 = class {
|
|
|
10693
10915
|
runConfig
|
|
10694
10916
|
});
|
|
10695
10917
|
}
|
|
10918
|
+
/**
|
|
10919
|
+
* Runs compaction if configured.
|
|
10920
|
+
*/
|
|
10921
|
+
async _runCompaction(session, _invocationContext) {
|
|
10922
|
+
if (!this.eventsCompactionConfig) {
|
|
10923
|
+
return;
|
|
10924
|
+
}
|
|
10925
|
+
const summarizer = this._getOrCreateSummarizer();
|
|
10926
|
+
if (!summarizer) {
|
|
10927
|
+
this.logger.warn(
|
|
10928
|
+
"Event compaction configured but no summarizer available"
|
|
10929
|
+
);
|
|
10930
|
+
return;
|
|
10931
|
+
}
|
|
10932
|
+
try {
|
|
10933
|
+
await runCompactionForSlidingWindow(
|
|
10934
|
+
this.eventsCompactionConfig,
|
|
10935
|
+
session,
|
|
10936
|
+
this.sessionService,
|
|
10937
|
+
summarizer
|
|
10938
|
+
);
|
|
10939
|
+
} catch (error) {
|
|
10940
|
+
this.logger.error("Error running compaction:", error);
|
|
10941
|
+
}
|
|
10942
|
+
}
|
|
10943
|
+
/**
|
|
10944
|
+
* Gets the configured summarizer or creates a default LLM-based one.
|
|
10945
|
+
*/
|
|
10946
|
+
_getOrCreateSummarizer() {
|
|
10947
|
+
if (_optionalChain([this, 'access', _307 => _307.eventsCompactionConfig, 'optionalAccess', _308 => _308.summarizer])) {
|
|
10948
|
+
return this.eventsCompactionConfig.summarizer;
|
|
10949
|
+
}
|
|
10950
|
+
if (this.agent instanceof LlmAgent) {
|
|
10951
|
+
try {
|
|
10952
|
+
const model = this.agent.canonicalModel;
|
|
10953
|
+
return new LlmEventSummarizer(model);
|
|
10954
|
+
} catch (error) {
|
|
10955
|
+
this.logger.warn(
|
|
10956
|
+
"Could not get canonical model for default summarizer:",
|
|
10957
|
+
error
|
|
10958
|
+
);
|
|
10959
|
+
return void 0;
|
|
10960
|
+
}
|
|
10961
|
+
}
|
|
10962
|
+
return void 0;
|
|
10963
|
+
}
|
|
10696
10964
|
}, _class32);
|
|
10697
10965
|
var InMemoryRunner = class extends Runner {
|
|
10698
10966
|
/**
|
|
@@ -10722,6 +10990,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
10722
10990
|
|
|
10723
10991
|
|
|
10724
10992
|
|
|
10993
|
+
|
|
10725
10994
|
__init56() {this.agentType = "llm"}
|
|
10726
10995
|
|
|
10727
10996
|
|
|
@@ -10935,6 +11204,14 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
10935
11204
|
this.config.afterToolCallback = callback;
|
|
10936
11205
|
return this;
|
|
10937
11206
|
}
|
|
11207
|
+
/**
|
|
11208
|
+
* Convenience method to start building with an existing agent
|
|
11209
|
+
* @param agent The agent instance to wrap
|
|
11210
|
+
* @returns New AgentBuilder instance with agent set
|
|
11211
|
+
*/
|
|
11212
|
+
static withAgent(agent) {
|
|
11213
|
+
return new _AgentBuilder(agent.name || "default_agent").withAgent(agent);
|
|
11214
|
+
}
|
|
10938
11215
|
/**
|
|
10939
11216
|
* Provide an already constructed agent instance. Further definition-mutating calls
|
|
10940
11217
|
* (model/tools/instruction/etc.) will be ignored with a dev warning.
|
|
@@ -11116,6 +11393,26 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11116
11393
|
this.runConfig = config instanceof RunConfig ? config : new RunConfig({ ...this.runConfig || {}, ...config });
|
|
11117
11394
|
return this;
|
|
11118
11395
|
}
|
|
11396
|
+
/**
|
|
11397
|
+
* Configure event compaction for automatic history management
|
|
11398
|
+
* @param config Event compaction configuration
|
|
11399
|
+
* @returns This builder instance for chaining
|
|
11400
|
+
* @example
|
|
11401
|
+
* ```typescript
|
|
11402
|
+
* const { runner } = await AgentBuilder
|
|
11403
|
+
* .create("assistant")
|
|
11404
|
+
* .withModel("gemini-2.5-flash")
|
|
11405
|
+
* .withEventsCompaction({
|
|
11406
|
+
* compactionInterval: 10, // Compact every 10 invocations
|
|
11407
|
+
* overlapSize: 2, // Include 2 prior invocations
|
|
11408
|
+
* })
|
|
11409
|
+
* .build();
|
|
11410
|
+
* ```
|
|
11411
|
+
*/
|
|
11412
|
+
withEventsCompaction(config) {
|
|
11413
|
+
this.eventsCompactionConfig = config;
|
|
11414
|
+
return this;
|
|
11415
|
+
}
|
|
11119
11416
|
/**
|
|
11120
11417
|
* Configure with an in-memory session with custom IDs
|
|
11121
11418
|
* Note: In-memory sessions are created automatically by default, use this only if you need custom appName/userId
|
|
@@ -11152,7 +11449,8 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11152
11449
|
agent,
|
|
11153
11450
|
sessionService: this.sessionService,
|
|
11154
11451
|
memoryService: this.memoryService,
|
|
11155
|
-
artifactService: this.artifactService
|
|
11452
|
+
artifactService: this.artifactService,
|
|
11453
|
+
eventsCompactionConfig: this.eventsCompactionConfig
|
|
11156
11454
|
};
|
|
11157
11455
|
const baseRunner = new Runner(runnerConfig);
|
|
11158
11456
|
runner = this.createEnhancedRunner(baseRunner, session);
|
|
@@ -11302,7 +11600,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11302
11600
|
const outputSchema = this.config.outputSchema;
|
|
11303
11601
|
const agentType = this.agentType;
|
|
11304
11602
|
const isMulti = agentType === "parallel" || agentType === "sequential";
|
|
11305
|
-
const subAgentNames = _optionalChain([this, 'access',
|
|
11603
|
+
const subAgentNames = _optionalChain([this, 'access', _309 => _309.config, 'access', _310 => _310.subAgents, 'optionalAccess', _311 => _311.map, 'call', _312 => _312((a) => a.name)]) || [];
|
|
11306
11604
|
const runConfig = this.runConfig;
|
|
11307
11605
|
return {
|
|
11308
11606
|
__outputSchema: outputSchema,
|
|
@@ -11311,7 +11609,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11311
11609
|
let combinedResponse = "";
|
|
11312
11610
|
const perAgentBuffers = {};
|
|
11313
11611
|
const authors = /* @__PURE__ */ new Set();
|
|
11314
|
-
if (!_optionalChain([sessionOptions, 'optionalAccess',
|
|
11612
|
+
if (!_optionalChain([sessionOptions, 'optionalAccess', _313 => _313.userId])) {
|
|
11315
11613
|
throw new Error("Session configuration is required");
|
|
11316
11614
|
}
|
|
11317
11615
|
for await (const event of baseRunner.runAsync({
|
|
@@ -11320,7 +11618,7 @@ var AgentBuilder = (_class33 = class _AgentBuilder {
|
|
|
11320
11618
|
newMessage,
|
|
11321
11619
|
runConfig
|
|
11322
11620
|
})) {
|
|
11323
|
-
if (_optionalChain([event, 'access',
|
|
11621
|
+
if (_optionalChain([event, 'access', _314 => _314.content, 'optionalAccess', _315 => _315.parts]) && Array.isArray(event.content.parts)) {
|
|
11324
11622
|
const content = event.content.parts.map(
|
|
11325
11623
|
(part) => (part && typeof part === "object" && "text" in part ? part.text : "") || ""
|
|
11326
11624
|
).join("");
|
|
@@ -11607,7 +11905,7 @@ var VertexAiSessionService = class extends BaseSessionService {
|
|
|
11607
11905
|
path: `operations/${operationId}`,
|
|
11608
11906
|
request_dict: {}
|
|
11609
11907
|
});
|
|
11610
|
-
if (_optionalChain([lroResponse, 'optionalAccess',
|
|
11908
|
+
if (_optionalChain([lroResponse, 'optionalAccess', _316 => _316.done])) {
|
|
11611
11909
|
break;
|
|
11612
11910
|
}
|
|
11613
11911
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
@@ -11978,12 +12276,12 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
11978
12276
|
}
|
|
11979
12277
|
async createSession(appName, userId, state, sessionId) {
|
|
11980
12278
|
await this.ensureInitialized();
|
|
11981
|
-
const id = _optionalChain([sessionId, 'optionalAccess',
|
|
12279
|
+
const id = _optionalChain([sessionId, 'optionalAccess', _317 => _317.trim, 'call', _318 => _318()]) || this.generateSessionId();
|
|
11982
12280
|
return await this.db.transaction().execute(async (trx) => {
|
|
11983
12281
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
|
|
11984
12282
|
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',
|
|
12283
|
+
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _319 => _319.state]), {});
|
|
12284
|
+
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _320 => _320.state]), {});
|
|
11987
12285
|
if (!appState) {
|
|
11988
12286
|
await trx.insertInto("app_states").values({
|
|
11989
12287
|
app_name: appName,
|
|
@@ -12042,21 +12340,21 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
12042
12340
|
return void 0;
|
|
12043
12341
|
}
|
|
12044
12342
|
let eventQuery = trx.selectFrom("events").selectAll().where("session_id", "=", sessionId).orderBy("timestamp", "desc");
|
|
12045
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
12343
|
+
if (_optionalChain([config, 'optionalAccess', _321 => _321.afterTimestamp])) {
|
|
12046
12344
|
eventQuery = eventQuery.where(
|
|
12047
12345
|
"timestamp",
|
|
12048
12346
|
">=",
|
|
12049
12347
|
new Date(config.afterTimestamp * 1e3)
|
|
12050
12348
|
);
|
|
12051
12349
|
}
|
|
12052
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
12350
|
+
if (_optionalChain([config, 'optionalAccess', _322 => _322.numRecentEvents])) {
|
|
12053
12351
|
eventQuery = eventQuery.limit(config.numRecentEvents);
|
|
12054
12352
|
}
|
|
12055
12353
|
const storageEvents = await eventQuery.execute();
|
|
12056
12354
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", appName).executeTakeFirst();
|
|
12057
12355
|
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',
|
|
12356
|
+
const currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _323 => _323.state]), {});
|
|
12357
|
+
const currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _324 => _324.state]), {});
|
|
12060
12358
|
const sessionState = this.parseJsonSafely(storageSession.state, {});
|
|
12061
12359
|
const mergedState = this.mergeState(
|
|
12062
12360
|
currentAppState,
|
|
@@ -12114,13 +12412,13 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
12114
12412
|
}
|
|
12115
12413
|
const appState = await trx.selectFrom("app_states").selectAll().where("app_name", "=", session.appName).executeTakeFirst();
|
|
12116
12414
|
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',
|
|
12415
|
+
let currentAppState = this.parseJsonSafely(_optionalChain([appState, 'optionalAccess', _325 => _325.state]), {});
|
|
12416
|
+
let currentUserState = this.parseJsonSafely(_optionalChain([userState, 'optionalAccess', _326 => _326.state]), {});
|
|
12119
12417
|
let sessionState = this.parseJsonSafely(storageSession.state, {});
|
|
12120
12418
|
let appStateDelta = {};
|
|
12121
12419
|
let userStateDelta = {};
|
|
12122
12420
|
let sessionStateDelta = {};
|
|
12123
|
-
if (_optionalChain([event, 'access',
|
|
12421
|
+
if (_optionalChain([event, 'access', _327 => _327.actions, 'optionalAccess', _328 => _328.stateDelta])) {
|
|
12124
12422
|
const deltas = this.extractStateDelta(event.actions.stateDelta);
|
|
12125
12423
|
appStateDelta = deltas.appStateDelta;
|
|
12126
12424
|
userStateDelta = deltas.userStateDelta;
|
|
@@ -12266,7 +12564,7 @@ var DatabaseSessionService = (_class34 = class extends BaseSessionService {
|
|
|
12266
12564
|
* Overrides the base class method to work with plain object state.
|
|
12267
12565
|
*/
|
|
12268
12566
|
updateSessionState(session, event) {
|
|
12269
|
-
if (!_optionalChain([event, 'access',
|
|
12567
|
+
if (!_optionalChain([event, 'access', _329 => _329.actions, 'optionalAccess', _330 => _330.stateDelta])) {
|
|
12270
12568
|
return;
|
|
12271
12569
|
}
|
|
12272
12570
|
for (const [key, value] of Object.entries(event.actions.stateDelta)) {
|
|
@@ -12436,7 +12734,7 @@ var GcsArtifactService = class {
|
|
|
12436
12734
|
};
|
|
12437
12735
|
return part;
|
|
12438
12736
|
} catch (error) {
|
|
12439
|
-
if (_optionalChain([error, 'optionalAccess',
|
|
12737
|
+
if (_optionalChain([error, 'optionalAccess', _331 => _331.code]) === 404) {
|
|
12440
12738
|
return null;
|
|
12441
12739
|
}
|
|
12442
12740
|
throw error;
|
|
@@ -12687,13 +12985,13 @@ var VertexAiEvalFacade = class _VertexAiEvalFacade {
|
|
|
12687
12985
|
};
|
|
12688
12986
|
}
|
|
12689
12987
|
_getText(content) {
|
|
12690
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
12988
|
+
if (_optionalChain([content, 'optionalAccess', _332 => _332.parts])) {
|
|
12691
12989
|
return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join("\n");
|
|
12692
12990
|
}
|
|
12693
12991
|
return "";
|
|
12694
12992
|
}
|
|
12695
12993
|
_getScore(evalResult) {
|
|
12696
|
-
if (_optionalChain([evalResult, 'optionalAccess',
|
|
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)) {
|
|
12697
12995
|
return evalResult.summaryMetrics[0].meanScore;
|
|
12698
12996
|
}
|
|
12699
12997
|
return void 0;
|
|
@@ -12843,7 +13141,7 @@ var ResponseEvaluator = class extends Evaluator {
|
|
|
12843
13141
|
return fmeasure;
|
|
12844
13142
|
}
|
|
12845
13143
|
extractText(content) {
|
|
12846
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
13144
|
+
if (_optionalChain([content, 'optionalAccess', _336 => _336.parts])) {
|
|
12847
13145
|
return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join(" ");
|
|
12848
13146
|
}
|
|
12849
13147
|
return "";
|
|
@@ -12876,7 +13174,7 @@ var TrajectoryEvaluator = class extends Evaluator {
|
|
|
12876
13174
|
for (let i = 0; i < actualInvocations.length; i++) {
|
|
12877
13175
|
const actual = actualInvocations[i];
|
|
12878
13176
|
const expected = expectedInvocations[i];
|
|
12879
|
-
if (!_optionalChain([actual, 'access',
|
|
13177
|
+
if (!_optionalChain([actual, 'access', _337 => _337.intermediateData, 'optionalAccess', _338 => _338.toolUses]) || !_optionalChain([expected, 'access', _339 => _339.intermediateData, 'optionalAccess', _340 => _340.toolUses])) {
|
|
12880
13178
|
perInvocationResults.push({
|
|
12881
13179
|
actualInvocation: actual,
|
|
12882
13180
|
expectedInvocation: expected,
|
|
@@ -12964,7 +13262,7 @@ var SafetyEvaluatorV1 = class extends Evaluator {
|
|
|
12964
13262
|
|
|
12965
13263
|
// src/evaluation/llm-as-judge-utils.ts
|
|
12966
13264
|
function getTextFromContent(content) {
|
|
12967
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
13265
|
+
if (_optionalChain([content, 'optionalAccess', _341 => _341.parts])) {
|
|
12968
13266
|
return content.parts.map((part) => part.text).filter(Boolean).join("\n");
|
|
12969
13267
|
}
|
|
12970
13268
|
return "";
|
|
@@ -12976,9 +13274,9 @@ function getEvalStatus(score, threshold) {
|
|
|
12976
13274
|
// src/evaluation/llm-as-judge.ts
|
|
12977
13275
|
var LlmAsJudge = class {
|
|
12978
13276
|
async sampleJudge(prompt, numSamples, critiqueParser, judgeModelOptions) {
|
|
12979
|
-
const modelName = _optionalChain([judgeModelOptions, 'optionalAccess',
|
|
13277
|
+
const modelName = _optionalChain([judgeModelOptions, 'optionalAccess', _342 => _342.judgeModel]) || "gemini-2.5-flash";
|
|
12980
13278
|
const model = LLMRegistry.getModelOrCreate(modelName);
|
|
12981
|
-
const config = _optionalChain([judgeModelOptions, 'optionalAccess',
|
|
13279
|
+
const config = _optionalChain([judgeModelOptions, 'optionalAccess', _343 => _343.judgeModelConfig]) || {};
|
|
12982
13280
|
const samples = [];
|
|
12983
13281
|
for (let i = 0; i < numSamples; i++) {
|
|
12984
13282
|
try {
|
|
@@ -13044,7 +13342,7 @@ function parseCritique(response) {
|
|
|
13044
13342
|
const labelMatchIsResponseValid = response.match(
|
|
13045
13343
|
/"is_the_agent_response_valid":\s*\[*[\n\s]*"*([^"^\]^\s]*)"*[\n\s]*\]*\s*[,\n\}]/
|
|
13046
13344
|
);
|
|
13047
|
-
if (_optionalChain([labelMatchIsResponseValid, 'optionalAccess',
|
|
13345
|
+
if (_optionalChain([labelMatchIsResponseValid, 'optionalAccess', _344 => _344[1]])) {
|
|
13048
13346
|
const label = labelMatchIsResponseValid[1].toLowerCase();
|
|
13049
13347
|
return label === "valid" ? "valid" /* VALID */ : "invalid" /* INVALID */;
|
|
13050
13348
|
}
|
|
@@ -13089,7 +13387,7 @@ var FinalResponseMatchV2Evaluator = class extends Evaluator {
|
|
|
13089
13387
|
"{prompt}",
|
|
13090
13388
|
prompt
|
|
13091
13389
|
).replace("{response}", response).replace("{golden_response}", goldenResponse);
|
|
13092
|
-
const numSamples = _nullishCoalesce(_optionalChain([this, 'access',
|
|
13390
|
+
const numSamples = _nullishCoalesce(_optionalChain([this, 'access', _345 => _345.metric, 'access', _346 => _346.judgeModelOptions, 'optionalAccess', _347 => _347.numSamples]), () => ( DEFAULT_NUM_SAMPLES));
|
|
13093
13391
|
const labels = await this.llmAsJudge.sampleJudge(
|
|
13094
13392
|
formattedPrompt,
|
|
13095
13393
|
numSamples,
|
|
@@ -13129,7 +13427,7 @@ var MetricEvaluatorRegistry = (_class35 = class {constructor() { _class35.protot
|
|
|
13129
13427
|
const metricName = metricInfo.metricName;
|
|
13130
13428
|
if (this.registry.has(metricName)) {
|
|
13131
13429
|
console.info(
|
|
13132
|
-
`Updating Evaluator class for ${metricName} from ${_optionalChain([this, 'access',
|
|
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}`
|
|
13133
13431
|
);
|
|
13134
13432
|
}
|
|
13135
13433
|
this.registry.set(metricName, {
|
|
@@ -13243,10 +13541,10 @@ var LocalEvalService = class extends BaseEvalService {
|
|
|
13243
13541
|
for (const evalMetric of evaluateConfig.evalMetrics) {
|
|
13244
13542
|
const evaluator = DEFAULT_METRIC_EVALUATOR_REGISTRY.getEvaluator(evalMetric);
|
|
13245
13543
|
const actual = results.filter(
|
|
13246
|
-
(r) => !_optionalChain([r, 'access',
|
|
13544
|
+
(r) => !_optionalChain([r, 'access', _353 => _353.invocationId, 'optionalAccess', _354 => _354.includes, 'call', _355 => _355("expected")])
|
|
13247
13545
|
);
|
|
13248
13546
|
const expected = results.filter(
|
|
13249
|
-
(r) => _optionalChain([r, 'access',
|
|
13547
|
+
(r) => _optionalChain([r, 'access', _356 => _356.invocationId, 'optionalAccess', _357 => _357.includes, 'call', _358 => _358("expected")])
|
|
13250
13548
|
);
|
|
13251
13549
|
const result = await evaluator.evaluateInvocations(actual, expected);
|
|
13252
13550
|
evalResult.evalCaseResults.push({
|
|
@@ -13638,13 +13936,13 @@ ${failures.join(
|
|
|
13638
13936
|
console.log("\n\n");
|
|
13639
13937
|
}
|
|
13640
13938
|
static _convertContentToText(content) {
|
|
13641
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
13939
|
+
if (_optionalChain([content, 'optionalAccess', _359 => _359.parts])) {
|
|
13642
13940
|
return content.parts.map((p) => p.text || "").filter((text) => text.length > 0).join("\n");
|
|
13643
13941
|
}
|
|
13644
13942
|
return "";
|
|
13645
13943
|
}
|
|
13646
13944
|
static _convertToolCallsToText(intermediateData) {
|
|
13647
|
-
if (_optionalChain([intermediateData, 'optionalAccess',
|
|
13945
|
+
if (_optionalChain([intermediateData, 'optionalAccess', _360 => _360.toolUses])) {
|
|
13648
13946
|
return intermediateData.toolUses.map((t) => JSON.stringify(t)).join("\n");
|
|
13649
13947
|
}
|
|
13650
13948
|
return "";
|
|
@@ -13699,7 +13997,7 @@ ${failures.join(
|
|
|
13699
13997
|
for (const [metricName, evalMetricResultsWithInvocations] of Object.entries(
|
|
13700
13998
|
evalMetricResults
|
|
13701
13999
|
)) {
|
|
13702
|
-
const threshold = _optionalChain([evalMetricResultsWithInvocations, 'access',
|
|
14000
|
+
const threshold = _optionalChain([evalMetricResultsWithInvocations, 'access', _361 => _361[0], 'optionalAccess', _362 => _362.evalMetricResult, 'access', _363 => _363.threshold]) || 0;
|
|
13703
14001
|
const scores = evalMetricResultsWithInvocations.map((m) => m.evalMetricResult.score).filter((s) => s !== void 0);
|
|
13704
14002
|
let overallScore;
|
|
13705
14003
|
let overallEvalStatus;
|
|
@@ -13788,7 +14086,7 @@ var RougeEvaluator = class extends Evaluator {
|
|
|
13788
14086
|
}
|
|
13789
14087
|
};
|
|
13790
14088
|
function getTextFromContent2(content) {
|
|
13791
|
-
if (_optionalChain([content, 'optionalAccess',
|
|
14089
|
+
if (_optionalChain([content, 'optionalAccess', _364 => _364.parts])) {
|
|
13792
14090
|
return content.parts.map((part) => part.text).filter(Boolean).join("\n");
|
|
13793
14091
|
}
|
|
13794
14092
|
return "";
|
|
@@ -13984,4 +14282,6 @@ var VERSION = "0.1.0";
|
|
|
13984
14282
|
|
|
13985
14283
|
|
|
13986
14284
|
|
|
13987
|
-
|
|
14285
|
+
|
|
14286
|
+
|
|
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;
|