@google/adk 0.4.0 → 0.6.0
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/README.md +1 -1
- package/dist/cjs/a2a/a2a_event.js +317 -0
- package/dist/cjs/a2a/a2a_remote_agent.js +174 -0
- package/dist/cjs/a2a/a2a_remote_agent_run_processor.js +198 -0
- package/dist/cjs/a2a/a2a_remote_agent_utils.js +165 -0
- package/dist/cjs/a2a/agent_card.js +380 -0
- package/dist/cjs/a2a/agent_executor.js +221 -0
- package/dist/cjs/a2a/agent_to_a2a.js +115 -0
- package/dist/cjs/a2a/event_converter_utils.js +201 -0
- package/dist/cjs/a2a/event_processor_utils.js +180 -0
- package/dist/cjs/a2a/executor_context.js +53 -0
- package/dist/cjs/a2a/metadata_converter_utils.js +126 -0
- package/dist/cjs/a2a/part_converter_utils.js +47 -34
- package/dist/cjs/agents/base_agent.js +3 -3
- package/dist/cjs/{tools/tool_context.js → agents/context.js} +70 -15
- package/dist/cjs/agents/functions.js +2 -2
- package/dist/cjs/agents/llm_agent.js +38 -674
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +132 -0
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +68 -0
- package/dist/cjs/agents/processors/code_execution_request_processor.js +389 -0
- package/dist/cjs/agents/{content_processor_utils.js → processors/content_processor_utils.js} +21 -2
- package/dist/cjs/agents/processors/content_request_processor.js +87 -0
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +61 -0
- package/dist/cjs/agents/processors/identity_llm_request_processor.js +54 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +85 -0
- package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +165 -0
- package/dist/cjs/artifacts/file_artifact_service.js +35 -4
- package/dist/cjs/common.js +48 -7
- package/dist/cjs/context/base_context_compactor.js +27 -0
- package/dist/cjs/context/summarizers/base_summarizer.js +27 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +93 -0
- package/dist/cjs/context/token_based_context_compactor.js +135 -0
- package/dist/cjs/context/truncating_context_compactor.js +58 -0
- package/dist/cjs/events/compacted_event.js +53 -0
- package/dist/cjs/index.js +113 -53
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/memory/in_memory_memory_service.js +1 -1
- package/dist/cjs/models/llm_response.js +2 -0
- package/dist/cjs/plugins/base_plugin.js +1 -1
- package/dist/cjs/runner/runner.js +20 -11
- package/dist/cjs/sessions/database_session_service.js +4 -1
- package/dist/cjs/sessions/db/operations.js +25 -23
- package/dist/cjs/sessions/state.js +2 -2
- package/dist/cjs/tools/agent_tool.js +6 -5
- package/dist/cjs/tools/base_tool.js +3 -0
- package/dist/cjs/tools/base_toolset.js +13 -3
- package/dist/cjs/tools/exit_loop_tool.js +63 -0
- package/dist/cjs/tools/load_artifacts_tool.js +188 -0
- package/dist/cjs/tools/load_memory_tool.js +107 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +9 -5
- package/dist/cjs/tools/preload_memory_tool.js +109 -0
- package/dist/cjs/utils/logger.js +62 -54
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_event.js +269 -0
- package/dist/esm/a2a/a2a_remote_agent.js +148 -0
- package/dist/esm/a2a/a2a_remote_agent_run_processor.js +175 -0
- package/dist/esm/a2a/a2a_remote_agent_utils.js +131 -0
- package/dist/esm/a2a/agent_card.js +340 -0
- package/dist/esm/a2a/agent_executor.js +202 -0
- package/dist/esm/a2a/agent_to_a2a.js +80 -0
- package/dist/esm/a2a/event_converter_utils.js +187 -0
- package/dist/esm/a2a/event_processor_utils.js +159 -0
- package/dist/esm/a2a/executor_context.js +23 -0
- package/dist/esm/a2a/metadata_converter_utils.js +91 -0
- package/dist/esm/a2a/part_converter_utils.js +49 -34
- package/dist/esm/agents/base_agent.js +3 -3
- package/dist/{web/tools/tool_context.js → esm/agents/context.js} +66 -11
- package/dist/esm/agents/functions.js +2 -2
- package/dist/esm/agents/llm_agent.js +31 -683
- package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +101 -0
- package/dist/esm/agents/processors/basic_llm_request_processor.js +37 -0
- package/dist/esm/agents/processors/code_execution_request_processor.js +363 -0
- package/dist/esm/agents/{content_processor_utils.js → processors/content_processor_utils.js} +23 -2
- package/dist/esm/agents/processors/content_request_processor.js +59 -0
- package/dist/esm/agents/processors/context_compactor_request_processor.js +31 -0
- package/dist/esm/agents/processors/identity_llm_request_processor.js +23 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +54 -0
- package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +140 -0
- package/dist/esm/artifacts/file_artifact_service.js +30 -3
- package/dist/esm/common.js +44 -10
- package/dist/esm/context/base_context_compactor.js +5 -0
- package/dist/esm/context/summarizers/base_summarizer.js +5 -0
- package/dist/esm/context/summarizers/llm_summarizer.js +65 -0
- package/dist/esm/context/token_based_context_compactor.js +105 -0
- package/dist/esm/context/truncating_context_compactor.js +28 -0
- package/dist/esm/events/compacted_event.js +22 -0
- package/dist/esm/index.js +119 -18
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/memory/in_memory_memory_service.js +1 -1
- package/dist/esm/models/llm_response.js +2 -0
- package/dist/esm/plugins/base_plugin.js +1 -1
- package/dist/esm/runner/runner.js +18 -10
- package/dist/esm/sessions/database_session_service.js +4 -1
- package/dist/esm/sessions/db/operations.js +32 -18
- package/dist/esm/sessions/state.js +2 -2
- package/dist/esm/tools/agent_tool.js +6 -5
- package/dist/esm/tools/base_tool.js +3 -0
- package/dist/esm/tools/base_toolset.js +11 -2
- package/dist/esm/tools/exit_loop_tool.js +32 -0
- package/dist/esm/tools/load_artifacts_tool.js +159 -0
- package/dist/esm/tools/load_memory_tool.js +78 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +9 -5
- package/dist/esm/tools/preload_memory_tool.js +80 -0
- package/dist/esm/utils/logger.js +52 -54
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_event.d.ts +139 -0
- package/dist/types/a2a/a2a_remote_agent.d.ts +63 -0
- package/dist/types/a2a/a2a_remote_agent_run_processor.d.ts +31 -0
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +38 -0
- package/dist/types/a2a/agent_card.d.ts +23 -0
- package/dist/types/a2a/agent_executor.d.ts +52 -0
- package/dist/types/a2a/agent_to_a2a.d.ts +45 -0
- package/dist/types/a2a/event_converter_utils.d.ts +20 -0
- package/dist/types/a2a/event_processor_utils.d.ts +24 -0
- package/dist/types/a2a/executor_context.d.ts +33 -0
- package/dist/types/a2a/metadata_converter_utils.d.ts +63 -0
- package/dist/types/a2a/part_converter_utils.d.ts +4 -3
- package/dist/types/agents/base_agent.d.ts +2 -2
- package/dist/types/{tools/tool_context.d.ts → agents/context.d.ts} +43 -8
- package/dist/types/agents/llm_agent.d.ts +14 -31
- package/dist/types/agents/loop_agent.d.ts +1 -1
- package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +18 -0
- package/dist/types/agents/{base_llm_processor.d.ts → processors/base_llm_processor.d.ts} +4 -4
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/code_execution_request_processor.d.ts +34 -0
- package/dist/types/agents/{content_processor_utils.d.ts → processors/content_processor_utils.d.ts} +1 -1
- package/dist/types/agents/processors/content_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/context_compactor_request_processor.d.ts +22 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/instructions_llm_request_processor.d.ts +16 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +13 -0
- package/dist/types/artifacts/file_artifact_service.d.ts +4 -0
- package/dist/types/auth/credential_service/base_credential_service.d.ts +3 -3
- package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +3 -3
- package/dist/types/common.d.ts +20 -5
- package/dist/types/context/base_context_compactor.d.ts +24 -0
- package/dist/types/context/summarizers/base_summarizer.d.ts +19 -0
- package/dist/types/context/summarizers/llm_summarizer.d.ts +23 -0
- package/dist/types/context/token_based_context_compactor.d.ts +33 -0
- package/dist/types/context/truncating_context_compactor.d.ts +24 -0
- package/dist/types/events/compacted_event.d.ts +33 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/models/llm_response.d.ts +5 -1
- package/dist/types/plugins/base_plugin.d.ts +12 -13
- package/dist/types/plugins/logging_plugin.d.ts +9 -10
- package/dist/types/plugins/plugin_manager.d.ts +9 -10
- package/dist/types/plugins/security_plugin.d.ts +2 -2
- package/dist/types/runner/runner.d.ts +13 -0
- package/dist/types/sessions/database_session_service.d.ts +2 -1
- package/dist/types/sessions/db/operations.d.ts +3 -4
- package/dist/types/tools/base_tool.d.ts +3 -3
- package/dist/types/tools/base_toolset.d.ts +12 -3
- package/dist/types/tools/exit_loop_tool.d.ts +24 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +2 -2
- package/dist/types/tools/function_tool.d.ts +2 -2
- package/dist/types/tools/load_artifacts_tool.d.ts +21 -0
- package/dist/types/tools/load_memory_tool.d.ts +22 -0
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -1
- package/dist/types/tools/preload_memory_tool.d.ts +23 -0
- package/dist/types/utils/logger.d.ts +5 -9
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_event.js +269 -0
- package/dist/web/a2a/a2a_remote_agent.js +193 -0
- package/dist/web/a2a/a2a_remote_agent_run_processor.js +175 -0
- package/dist/web/a2a/a2a_remote_agent_utils.js +131 -0
- package/dist/web/a2a/agent_card.js +340 -0
- package/dist/web/a2a/agent_executor.js +216 -0
- package/dist/web/a2a/agent_to_a2a.js +80 -0
- package/dist/web/a2a/event_converter_utils.js +201 -0
- package/dist/web/a2a/event_processor_utils.js +168 -0
- package/dist/web/a2a/executor_context.js +23 -0
- package/dist/web/a2a/metadata_converter_utils.js +108 -0
- package/dist/web/a2a/part_converter_utils.js +49 -34
- package/dist/web/agents/base_agent.js +3 -3
- package/dist/{esm/tools/tool_context.js → web/agents/context.js} +66 -11
- package/dist/web/agents/functions.js +2 -2
- package/dist/web/agents/llm_agent.js +31 -661
- package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +100 -0
- package/dist/web/agents/processors/basic_llm_request_processor.js +71 -0
- package/dist/web/agents/processors/code_execution_request_processor.js +365 -0
- package/dist/web/agents/{content_processor_utils.js → processors/content_processor_utils.js} +22 -2
- package/dist/web/agents/processors/content_request_processor.js +77 -0
- package/dist/web/agents/processors/context_compactor_request_processor.js +49 -0
- package/dist/web/agents/processors/identity_llm_request_processor.js +41 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +72 -0
- package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +158 -0
- package/dist/web/artifacts/file_artifact_service.js +30 -3
- package/dist/web/common.js +44 -10
- package/dist/web/context/base_context_compactor.js +5 -0
- package/dist/web/context/summarizers/base_summarizer.js +5 -0
- package/dist/web/context/summarizers/llm_summarizer.js +74 -0
- package/dist/web/context/token_based_context_compactor.js +105 -0
- package/dist/web/context/truncating_context_compactor.js +28 -0
- package/dist/web/events/compacted_event.js +40 -0
- package/dist/web/index.js +13 -18
- package/dist/web/index.js.map +7 -0
- package/dist/web/memory/in_memory_memory_service.js +1 -1
- package/dist/web/models/llm_response.js +2 -0
- package/dist/web/plugins/base_plugin.js +1 -1
- package/dist/web/runner/runner.js +18 -10
- package/dist/web/sessions/database_session_service.js +4 -1
- package/dist/web/sessions/db/operations.js +32 -18
- package/dist/web/sessions/state.js +2 -2
- package/dist/web/tools/agent_tool.js +6 -5
- package/dist/web/tools/base_tool.js +3 -0
- package/dist/web/tools/base_toolset.js +11 -2
- package/dist/web/tools/exit_loop_tool.js +32 -0
- package/dist/web/tools/load_artifacts_tool.js +150 -0
- package/dist/web/tools/load_memory_tool.js +77 -0
- package/dist/web/tools/mcp/mcp_toolset.js +27 -5
- package/dist/web/tools/preload_memory_tool.js +75 -0
- package/dist/web/utils/logger.js +52 -54
- package/dist/web/version.js +1 -1
- package/package.json +7 -4
- package/dist/cjs/agents/callback_context.js +0 -101
- package/dist/esm/agents/callback_context.js +0 -71
- package/dist/types/agents/callback_context.d.ts +0 -42
- package/dist/web/agents/callback_context.js +0 -71
- /package/dist/cjs/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
- /package/dist/esm/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
- /package/dist/web/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
2
|
+
var __await = function(promise, isYieldStar) {
|
|
3
|
+
this[0] = promise;
|
|
4
|
+
this[1] = isYieldStar;
|
|
5
|
+
};
|
|
6
|
+
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
7
|
+
var resume = (k, v, yes, no) => {
|
|
8
|
+
try {
|
|
9
|
+
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
10
|
+
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
no(e);
|
|
13
|
+
}
|
|
14
|
+
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
15
|
+
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @license
|
|
19
|
+
* Copyright 2026 Google LLC
|
|
20
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
21
|
+
*/
|
|
22
|
+
class ContextCompactorRequestProcessor {
|
|
23
|
+
constructor(compactors) {
|
|
24
|
+
this.compactors = compactors;
|
|
25
|
+
}
|
|
26
|
+
runAsync(invocationContext, _llmRequest) {
|
|
27
|
+
return __asyncGenerator(this, null, function* () {
|
|
28
|
+
for (const compactor of this.compactors) {
|
|
29
|
+
const shouldCompact = yield new __await(Promise.resolve(
|
|
30
|
+
compactor.shouldCompact(invocationContext)
|
|
31
|
+
));
|
|
32
|
+
if (shouldCompact) {
|
|
33
|
+
const oldEvents = new Set(invocationContext.session.events);
|
|
34
|
+
yield new __await(Promise.resolve(compactor.compact(invocationContext)));
|
|
35
|
+
const newEvents = invocationContext.session.events.filter(
|
|
36
|
+
(e) => !oldEvents.has(e)
|
|
37
|
+
);
|
|
38
|
+
for (const e of newEvents) {
|
|
39
|
+
yield e;
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
ContextCompactorRequestProcessor
|
|
49
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
2
|
+
var __await = function(promise, isYieldStar) {
|
|
3
|
+
this[0] = promise;
|
|
4
|
+
this[1] = isYieldStar;
|
|
5
|
+
};
|
|
6
|
+
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
7
|
+
var resume = (k, v, yes, no) => {
|
|
8
|
+
try {
|
|
9
|
+
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
10
|
+
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
no(e);
|
|
13
|
+
}
|
|
14
|
+
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
15
|
+
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @license
|
|
19
|
+
* Copyright 2025 Google LLC
|
|
20
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
21
|
+
*/
|
|
22
|
+
import { appendInstructions } from "../../models/llm_request.js";
|
|
23
|
+
import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
|
|
24
|
+
class IdentityLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
25
|
+
// eslint-disable-next-line require-yield
|
|
26
|
+
runAsync(invocationContext, llmRequest) {
|
|
27
|
+
return __asyncGenerator(this, null, function* () {
|
|
28
|
+
const agent = invocationContext.agent;
|
|
29
|
+
const si = ['You are an agent. Your internal name is "'.concat(agent.name, '".')];
|
|
30
|
+
if (agent.description) {
|
|
31
|
+
si.push('The description about you is "'.concat(agent.description, '"'));
|
|
32
|
+
}
|
|
33
|
+
appendInstructions(llmRequest, si);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const IDENTITY_LLM_REQUEST_PROCESSOR = new IdentityLlmRequestProcessor();
|
|
38
|
+
export {
|
|
39
|
+
IDENTITY_LLM_REQUEST_PROCESSOR,
|
|
40
|
+
IdentityLlmRequestProcessor
|
|
41
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
2
|
+
var __await = function(promise, isYieldStar) {
|
|
3
|
+
this[0] = promise;
|
|
4
|
+
this[1] = isYieldStar;
|
|
5
|
+
};
|
|
6
|
+
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
7
|
+
var resume = (k, v, yes, no) => {
|
|
8
|
+
try {
|
|
9
|
+
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
10
|
+
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
no(e);
|
|
13
|
+
}
|
|
14
|
+
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
15
|
+
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @license
|
|
19
|
+
* Copyright 2025 Google LLC
|
|
20
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
21
|
+
*/
|
|
22
|
+
import { appendInstructions } from "../../models/llm_request.js";
|
|
23
|
+
import { injectSessionState } from "../instructions.js";
|
|
24
|
+
import { isLlmAgent } from "../llm_agent.js";
|
|
25
|
+
import { ReadonlyContext } from "../readonly_context.js";
|
|
26
|
+
import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
|
|
27
|
+
class InstructionsLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
28
|
+
/**
|
|
29
|
+
* Handles instructions and global instructions for LLM flow.
|
|
30
|
+
*/
|
|
31
|
+
// eslint-disable-next-line require-yield
|
|
32
|
+
runAsync(invocationContext, llmRequest) {
|
|
33
|
+
return __asyncGenerator(this, null, function* () {
|
|
34
|
+
const agent = invocationContext.agent;
|
|
35
|
+
if (!isLlmAgent(agent)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const rootAgent = agent.rootAgent;
|
|
39
|
+
if (isLlmAgent(rootAgent) && rootAgent.globalInstruction) {
|
|
40
|
+
const { instruction, requireStateInjection } = yield new __await(rootAgent.canonicalGlobalInstruction(
|
|
41
|
+
new ReadonlyContext(invocationContext)
|
|
42
|
+
));
|
|
43
|
+
let instructionWithState = instruction;
|
|
44
|
+
if (requireStateInjection) {
|
|
45
|
+
instructionWithState = yield new __await(injectSessionState(
|
|
46
|
+
instruction,
|
|
47
|
+
new ReadonlyContext(invocationContext)
|
|
48
|
+
));
|
|
49
|
+
}
|
|
50
|
+
appendInstructions(llmRequest, [instructionWithState]);
|
|
51
|
+
}
|
|
52
|
+
if (agent.instruction) {
|
|
53
|
+
const { instruction, requireStateInjection } = yield new __await(agent.canonicalInstruction(
|
|
54
|
+
new ReadonlyContext(invocationContext)
|
|
55
|
+
));
|
|
56
|
+
let instructionWithState = instruction;
|
|
57
|
+
if (requireStateInjection) {
|
|
58
|
+
instructionWithState = yield new __await(injectSessionState(
|
|
59
|
+
instruction,
|
|
60
|
+
new ReadonlyContext(invocationContext)
|
|
61
|
+
));
|
|
62
|
+
}
|
|
63
|
+
appendInstructions(llmRequest, [instructionWithState]);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const INSTRUCTIONS_LLM_REQUEST_PROCESSOR = new InstructionsLlmRequestProcessor();
|
|
69
|
+
export {
|
|
70
|
+
INSTRUCTIONS_LLM_REQUEST_PROCESSOR,
|
|
71
|
+
InstructionsLlmRequestProcessor
|
|
72
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
2
|
+
var __await = function(promise, isYieldStar) {
|
|
3
|
+
this[0] = promise;
|
|
4
|
+
this[1] = isYieldStar;
|
|
5
|
+
};
|
|
6
|
+
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
7
|
+
var resume = (k, v, yes, no) => {
|
|
8
|
+
try {
|
|
9
|
+
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
10
|
+
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
no(e);
|
|
13
|
+
}
|
|
14
|
+
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
15
|
+
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @license
|
|
19
|
+
* Copyright 2025 Google LLC
|
|
20
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
21
|
+
*/
|
|
22
|
+
import {
|
|
23
|
+
getFunctionCalls,
|
|
24
|
+
getFunctionResponses
|
|
25
|
+
} from "../../events/event.js";
|
|
26
|
+
import { ToolConfirmation } from "../../tools/tool_confirmation.js";
|
|
27
|
+
import {
|
|
28
|
+
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
|
|
29
|
+
handleFunctionCallList
|
|
30
|
+
} from "../functions.js";
|
|
31
|
+
import { isLlmAgent } from "../llm_agent.js";
|
|
32
|
+
import { ReadonlyContext } from "../readonly_context.js";
|
|
33
|
+
import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
|
|
34
|
+
class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
35
|
+
/** Handles tool confirmation information to build the LLM request. */
|
|
36
|
+
runAsync(invocationContext) {
|
|
37
|
+
return __asyncGenerator(this, null, function* () {
|
|
38
|
+
const agent = invocationContext.agent;
|
|
39
|
+
if (!isLlmAgent(agent)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const events = invocationContext.session.events;
|
|
43
|
+
if (!events || events.length === 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const requestConfirmationFunctionResponses = {};
|
|
47
|
+
let confirmationEventIndex = -1;
|
|
48
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
49
|
+
const event = events[i];
|
|
50
|
+
if (event.author !== "user") {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const responses = getFunctionResponses(event);
|
|
54
|
+
if (!responses) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
let foundConfirmation = false;
|
|
58
|
+
for (const functionResponse of responses) {
|
|
59
|
+
if (functionResponse.name !== REQUEST_CONFIRMATION_FUNCTION_CALL_NAME) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
foundConfirmation = true;
|
|
63
|
+
let toolConfirmation = null;
|
|
64
|
+
if (functionResponse.response && Object.keys(functionResponse.response).length === 1 && "response" in functionResponse.response) {
|
|
65
|
+
toolConfirmation = JSON.parse(
|
|
66
|
+
functionResponse.response["response"]
|
|
67
|
+
);
|
|
68
|
+
} else if (functionResponse.response) {
|
|
69
|
+
toolConfirmation = new ToolConfirmation({
|
|
70
|
+
hint: functionResponse.response["hint"],
|
|
71
|
+
payload: functionResponse.response["payload"],
|
|
72
|
+
confirmed: functionResponse.response["confirmed"]
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (functionResponse.id && toolConfirmation) {
|
|
76
|
+
requestConfirmationFunctionResponses[functionResponse.id] = toolConfirmation;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (foundConfirmation) {
|
|
80
|
+
confirmationEventIndex = i;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (Object.keys(requestConfirmationFunctionResponses).length === 0) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
for (let i = confirmationEventIndex - 1; i >= 0; i--) {
|
|
88
|
+
const event = events[i];
|
|
89
|
+
const functionCalls = getFunctionCalls(event);
|
|
90
|
+
if (!functionCalls) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const toolsToResumeWithConfirmation = {};
|
|
94
|
+
const toolsToResumeWithArgs = {};
|
|
95
|
+
for (const functionCall of functionCalls) {
|
|
96
|
+
if (!functionCall.id || !(functionCall.id in requestConfirmationFunctionResponses)) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const args = functionCall.args;
|
|
100
|
+
if (!args || !("originalFunctionCall" in args)) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const originalFunctionCall = args["originalFunctionCall"];
|
|
104
|
+
if (originalFunctionCall.id) {
|
|
105
|
+
toolsToResumeWithConfirmation[originalFunctionCall.id] = requestConfirmationFunctionResponses[functionCall.id];
|
|
106
|
+
toolsToResumeWithArgs[originalFunctionCall.id] = originalFunctionCall;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (Object.keys(toolsToResumeWithConfirmation).length === 0) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
for (let j = events.length - 1; j > confirmationEventIndex; j--) {
|
|
113
|
+
const eventToCheck = events[j];
|
|
114
|
+
const functionResponses = getFunctionResponses(eventToCheck);
|
|
115
|
+
if (!functionResponses) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
for (const fr of functionResponses) {
|
|
119
|
+
if (fr.id && fr.id in toolsToResumeWithConfirmation) {
|
|
120
|
+
delete toolsToResumeWithConfirmation[fr.id];
|
|
121
|
+
delete toolsToResumeWithArgs[fr.id];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (Object.keys(toolsToResumeWithConfirmation).length === 0) {
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (Object.keys(toolsToResumeWithConfirmation).length === 0) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const toolsList = yield new __await(agent.canonicalTools(
|
|
132
|
+
new ReadonlyContext(invocationContext)
|
|
133
|
+
));
|
|
134
|
+
const toolsDict = Object.fromEntries(
|
|
135
|
+
toolsList.map((tool) => [tool.name, tool])
|
|
136
|
+
);
|
|
137
|
+
const functionResponseEvent = yield new __await(handleFunctionCallList({
|
|
138
|
+
invocationContext,
|
|
139
|
+
functionCalls: Object.values(toolsToResumeWithArgs),
|
|
140
|
+
toolsDict,
|
|
141
|
+
beforeToolCallbacks: agent.canonicalBeforeToolCallbacks,
|
|
142
|
+
afterToolCallbacks: agent.canonicalAfterToolCallbacks,
|
|
143
|
+
filters: new Set(Object.keys(toolsToResumeWithConfirmation)),
|
|
144
|
+
toolConfirmationDict: toolsToResumeWithConfirmation
|
|
145
|
+
}));
|
|
146
|
+
if (functionResponseEvent) {
|
|
147
|
+
yield functionResponseEvent;
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR = new RequestConfirmationLlmRequestProcessor();
|
|
155
|
+
export {
|
|
156
|
+
REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
|
|
157
|
+
RequestConfirmationLlmRequestProcessor
|
|
158
|
+
};
|
|
@@ -348,8 +348,28 @@ class FileArtifactService {
|
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
|
+
const SAFE_SEGMENT_RE = /^[a-zA-Z0-9_@-][a-zA-Z0-9_.@-]{0,255}$/;
|
|
352
|
+
function assertSafeSegment(value, label) {
|
|
353
|
+
if (!value || !SAFE_SEGMENT_RE.test(value)) {
|
|
354
|
+
throw new Error(
|
|
355
|
+
"[FileArtifactService] Invalid ".concat(label, ": value contains disallowed characters.")
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
function assertInsideRoot(resolvedPath, rootDir, label) {
|
|
360
|
+
const root = path.resolve(rootDir);
|
|
361
|
+
const resolved = path.resolve(resolvedPath);
|
|
362
|
+
if (!resolved.startsWith(root + path.sep) && resolved !== root) {
|
|
363
|
+
throw new Error(
|
|
364
|
+
"[FileArtifactService] ".concat(label, " escapes storage root. Resolved: ").concat(resolved, ", Root: ").concat(root)
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
351
368
|
function getUserRoot(rootDir, userId) {
|
|
352
|
-
|
|
369
|
+
assertSafeSegment(userId, "userId");
|
|
370
|
+
const result = path.join(rootDir, "users", userId);
|
|
371
|
+
assertInsideRoot(result, rootDir, "userRoot");
|
|
372
|
+
return result;
|
|
353
373
|
}
|
|
354
374
|
function isUserScoped(sessionId, filename) {
|
|
355
375
|
return !sessionId || filename.startsWith(USER_NAMESPACE_PREFIX);
|
|
@@ -358,7 +378,10 @@ function getUserArtifactsDir(userRoot) {
|
|
|
358
378
|
return path.join(userRoot, "artifacts");
|
|
359
379
|
}
|
|
360
380
|
function getSessionArtifactsDir(baseRoot, sessionId) {
|
|
361
|
-
|
|
381
|
+
assertSafeSegment(sessionId, "sessionId");
|
|
382
|
+
const result = path.join(baseRoot, "sessions", sessionId, "artifacts");
|
|
383
|
+
assertInsideRoot(result, baseRoot, "sessionArtifactsDir");
|
|
384
|
+
return result;
|
|
362
385
|
}
|
|
363
386
|
function getVersionsDir(artifactDir) {
|
|
364
387
|
return path.join(artifactDir, "versions");
|
|
@@ -502,5 +525,9 @@ function asPosixPath(p) {
|
|
|
502
525
|
return p.split(path.sep).join("/");
|
|
503
526
|
}
|
|
504
527
|
export {
|
|
505
|
-
FileArtifactService
|
|
528
|
+
FileArtifactService,
|
|
529
|
+
assertInsideRoot,
|
|
530
|
+
assertSafeSegment,
|
|
531
|
+
getSessionArtifactsDir,
|
|
532
|
+
getUserRoot
|
|
506
533
|
};
|
package/dist/web/common.js
CHANGED
|
@@ -5,17 +5,22 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { ActiveStreamingTool } from "./agents/active_streaming_tool.js";
|
|
7
7
|
import { BaseAgent, isBaseAgent } from "./agents/base_agent.js";
|
|
8
|
-
import {
|
|
9
|
-
BaseLlmRequestProcessor,
|
|
10
|
-
BaseLlmResponseProcessor
|
|
11
|
-
} from "./agents/base_llm_processor.js";
|
|
12
|
-
import { CallbackContext } from "./agents/callback_context.js";
|
|
8
|
+
import { Context } from "./agents/context.js";
|
|
13
9
|
import { functionsExportedForTestingOnly } from "./agents/functions.js";
|
|
14
10
|
import { InvocationContext } from "./agents/invocation_context.js";
|
|
15
11
|
import { LiveRequestQueue } from "./agents/live_request_queue.js";
|
|
16
12
|
import { LlmAgent, isLlmAgent } from "./agents/llm_agent.js";
|
|
17
13
|
import { LoopAgent, isLoopAgent } from "./agents/loop_agent.js";
|
|
18
14
|
import { ParallelAgent, isParallelAgent } from "./agents/parallel_agent.js";
|
|
15
|
+
import {
|
|
16
|
+
BaseLlmRequestProcessor,
|
|
17
|
+
BaseLlmResponseProcessor
|
|
18
|
+
} from "./agents/processors/base_llm_processor.js";
|
|
19
|
+
import {
|
|
20
|
+
CONTENT_REQUEST_PROCESSOR,
|
|
21
|
+
ContentRequestProcessor
|
|
22
|
+
} from "./agents/processors/content_request_processor.js";
|
|
23
|
+
import { ContextCompactorRequestProcessor } from "./agents/processors/context_compactor_request_processor.js";
|
|
19
24
|
import { ReadonlyContext } from "./agents/readonly_context.js";
|
|
20
25
|
import { StreamingMode } from "./agents/run_config.js";
|
|
21
26
|
import { SequentialAgent, isSequentialAgent } from "./agents/sequential_agent.js";
|
|
@@ -23,6 +28,10 @@ import { InMemoryArtifactService } from "./artifacts/in_memory_artifact_service.
|
|
|
23
28
|
import { AuthCredentialTypes } from "./auth/auth_credential.js";
|
|
24
29
|
import { BaseCodeExecutor } from "./code_executors/base_code_executor.js";
|
|
25
30
|
import { BuiltInCodeExecutor } from "./code_executors/built_in_code_executor.js";
|
|
31
|
+
import { LlmSummarizer } from "./context/summarizers/llm_summarizer.js";
|
|
32
|
+
import { TokenBasedContextCompactor } from "./context/token_based_context_compactor.js";
|
|
33
|
+
import { TruncatingContextCompactor } from "./context/truncating_context_compactor.js";
|
|
34
|
+
import { isCompactedEvent } from "./events/compacted_event.js";
|
|
26
35
|
import {
|
|
27
36
|
createEvent,
|
|
28
37
|
getFunctionCalls,
|
|
@@ -53,19 +62,28 @@ import {
|
|
|
53
62
|
getAskUserConfirmationFunctionCalls
|
|
54
63
|
} from "./plugins/security_plugin.js";
|
|
55
64
|
import { InMemoryRunner } from "./runner/in_memory_runner.js";
|
|
56
|
-
import { Runner } from "./runner/runner.js";
|
|
65
|
+
import { Runner, isRunner } from "./runner/runner.js";
|
|
57
66
|
import { BaseSessionService } from "./sessions/base_session_service.js";
|
|
58
67
|
import { InMemorySessionService } from "./sessions/in_memory_session_service.js";
|
|
59
68
|
import { createSession } from "./sessions/session.js";
|
|
60
69
|
import { State } from "./sessions/state.js";
|
|
61
70
|
import { AgentTool, isAgentTool } from "./tools/agent_tool.js";
|
|
62
71
|
import { BaseTool, isBaseTool } from "./tools/base_tool.js";
|
|
63
|
-
import { BaseToolset } from "./tools/base_toolset.js";
|
|
72
|
+
import { BaseToolset, isBaseToolset } from "./tools/base_toolset.js";
|
|
73
|
+
import { EXIT_LOOP, ExitLoopTool } from "./tools/exit_loop_tool.js";
|
|
64
74
|
import { FunctionTool, isFunctionTool } from "./tools/function_tool.js";
|
|
65
75
|
import { GOOGLE_SEARCH, GoogleSearchTool } from "./tools/google_search_tool.js";
|
|
76
|
+
import {
|
|
77
|
+
LOAD_ARTIFACTS,
|
|
78
|
+
LoadArtifactsTool
|
|
79
|
+
} from "./tools/load_artifacts_tool.js";
|
|
80
|
+
import { LOAD_MEMORY, LoadMemoryTool } from "./tools/load_memory_tool.js";
|
|
66
81
|
import { LongRunningFunctionTool } from "./tools/long_running_tool.js";
|
|
82
|
+
import {
|
|
83
|
+
PRELOAD_MEMORY,
|
|
84
|
+
PreloadMemoryTool
|
|
85
|
+
} from "./tools/preload_memory_tool.js";
|
|
67
86
|
import { ToolConfirmation } from "./tools/tool_confirmation.js";
|
|
68
|
-
import { ToolContext } from "./tools/tool_context.js";
|
|
69
87
|
import { LogLevel, getLogger, setLogLevel, setLogger } from "./utils/logger.js";
|
|
70
88
|
import { isGemini2OrAbove } from "./utils/model_name.js";
|
|
71
89
|
import { zodObjectToSchema } from "./utils/simple_zod_to_json.js";
|
|
@@ -91,8 +109,13 @@ export {
|
|
|
91
109
|
BaseTool,
|
|
92
110
|
BaseToolset,
|
|
93
111
|
BuiltInCodeExecutor,
|
|
94
|
-
|
|
112
|
+
CONTENT_REQUEST_PROCESSOR,
|
|
113
|
+
ContentRequestProcessor,
|
|
114
|
+
Context,
|
|
115
|
+
ContextCompactorRequestProcessor,
|
|
116
|
+
EXIT_LOOP,
|
|
95
117
|
EventType,
|
|
118
|
+
ExitLoopTool,
|
|
96
119
|
FunctionTool,
|
|
97
120
|
GOOGLE_SEARCH,
|
|
98
121
|
Gemini,
|
|
@@ -105,15 +128,22 @@ export {
|
|
|
105
128
|
InMemorySessionService,
|
|
106
129
|
InvocationContext,
|
|
107
130
|
LLMRegistry,
|
|
131
|
+
LOAD_ARTIFACTS,
|
|
132
|
+
LOAD_MEMORY,
|
|
108
133
|
LiveRequestQueue,
|
|
109
134
|
LlmAgent,
|
|
135
|
+
LlmSummarizer,
|
|
136
|
+
LoadArtifactsTool,
|
|
137
|
+
LoadMemoryTool,
|
|
110
138
|
LogLevel,
|
|
111
139
|
LoggingPlugin,
|
|
112
140
|
LongRunningFunctionTool,
|
|
113
141
|
LoopAgent,
|
|
142
|
+
PRELOAD_MEMORY,
|
|
114
143
|
ParallelAgent,
|
|
115
144
|
PluginManager,
|
|
116
145
|
PolicyOutcome,
|
|
146
|
+
PreloadMemoryTool,
|
|
117
147
|
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
|
|
118
148
|
ReadonlyContext,
|
|
119
149
|
Runner,
|
|
@@ -121,8 +151,9 @@ export {
|
|
|
121
151
|
SequentialAgent,
|
|
122
152
|
State,
|
|
123
153
|
StreamingMode,
|
|
154
|
+
TokenBasedContextCompactor,
|
|
124
155
|
ToolConfirmation,
|
|
125
|
-
|
|
156
|
+
TruncatingContextCompactor,
|
|
126
157
|
createEvent,
|
|
127
158
|
createEventActions,
|
|
128
159
|
createSession,
|
|
@@ -138,12 +169,15 @@ export {
|
|
|
138
169
|
isBaseExampleProvider,
|
|
139
170
|
isBaseLlm,
|
|
140
171
|
isBaseTool,
|
|
172
|
+
isBaseToolset,
|
|
173
|
+
isCompactedEvent,
|
|
141
174
|
isFinalResponse,
|
|
142
175
|
isFunctionTool,
|
|
143
176
|
isGemini2OrAbove,
|
|
144
177
|
isLlmAgent,
|
|
145
178
|
isLoopAgent,
|
|
146
179
|
isParallelAgent,
|
|
180
|
+
isRunner,
|
|
147
181
|
isSequentialAgent,
|
|
148
182
|
setLogLevel,
|
|
149
183
|
setLogger,
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
2
|
+
var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
import {
|
|
9
|
+
createCompactedEvent
|
|
10
|
+
} from "../../events/compacted_event.js";
|
|
11
|
+
import { stringifyContent } from "../../events/event.js";
|
|
12
|
+
const DEFAULT_PROMPT = "The following is a conversation history between a user and an AI agent. Please summarize the conversation, focusing on key information and decisions made, as well as any unresolved questions or tasks. The summary should be concise and capture the essence of the interaction.";
|
|
13
|
+
class LlmSummarizer {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.llm = options.llm;
|
|
16
|
+
this.prompt = options.prompt || DEFAULT_PROMPT;
|
|
17
|
+
}
|
|
18
|
+
async summarize(events) {
|
|
19
|
+
var _a, _b, _c, _d, _e, _f;
|
|
20
|
+
if (events.length === 0) {
|
|
21
|
+
throw new Error("Cannot summarize an empty list of events.");
|
|
22
|
+
}
|
|
23
|
+
const startTime = events[0].timestamp;
|
|
24
|
+
const endTime = events[events.length - 1].timestamp;
|
|
25
|
+
let formattedEvents = "";
|
|
26
|
+
for (let i = 0; i < events.length; i++) {
|
|
27
|
+
formattedEvents += "[Event ".concat(i + 1, " - Author: ").concat(events[i].author, "]\n");
|
|
28
|
+
formattedEvents += "".concat(stringifyContent(events[i]), "\n\n");
|
|
29
|
+
}
|
|
30
|
+
const fullPrompt = "".concat(this.prompt, "\n\n").concat(formattedEvents);
|
|
31
|
+
const request = {
|
|
32
|
+
contents: [{ role: "user", parts: [{ text: fullPrompt }] }],
|
|
33
|
+
toolsDict: {},
|
|
34
|
+
liveConnectConfig: {}
|
|
35
|
+
};
|
|
36
|
+
const responseGen = this.llm.generateContentAsync(request, false);
|
|
37
|
+
let compactedContent = "";
|
|
38
|
+
const firstResponse = await responseGen.next();
|
|
39
|
+
if (firstResponse.done || !((_c = (_b = (_a = firstResponse.value.content) == null ? void 0 : _a.parts) == null ? void 0 : _b[0]) == null ? void 0 : _c.text)) {
|
|
40
|
+
throw new Error("LLM failed to return a valid summary.");
|
|
41
|
+
}
|
|
42
|
+
compactedContent += firstResponse.value.content.parts[0].text;
|
|
43
|
+
try {
|
|
44
|
+
for (var iter = __forAwait(responseGen), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
|
|
45
|
+
const chunk = temp.value;
|
|
46
|
+
if ((_f = (_e = (_d = chunk.content) == null ? void 0 : _d.parts) == null ? void 0 : _e[0]) == null ? void 0 : _f.text) {
|
|
47
|
+
compactedContent += chunk.content.parts[0].text;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
} catch (temp) {
|
|
51
|
+
error = [temp];
|
|
52
|
+
} finally {
|
|
53
|
+
try {
|
|
54
|
+
more && (temp = iter.return) && await temp.call(iter);
|
|
55
|
+
} finally {
|
|
56
|
+
if (error)
|
|
57
|
+
throw error[0];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return createCompactedEvent({
|
|
61
|
+
author: "system",
|
|
62
|
+
content: {
|
|
63
|
+
role: "model",
|
|
64
|
+
parts: [{ text: compactedContent }]
|
|
65
|
+
},
|
|
66
|
+
startTime,
|
|
67
|
+
endTime,
|
|
68
|
+
compactedContent
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
LlmSummarizer
|
|
74
|
+
};
|