@google/adk 0.3.0 → 0.5.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/dist/cjs/a2a/a2a_event.js +290 -0
- package/dist/cjs/a2a/event_converter_utils.js +201 -0
- package/dist/cjs/a2a/executor_context.js +53 -0
- package/dist/cjs/a2a/metadata_converter_utils.js +125 -0
- package/dist/cjs/a2a/part_converter_utils.js +212 -0
- package/dist/cjs/agents/active_streaming_tool.js +1 -1
- package/dist/cjs/agents/base_agent.js +6 -6
- package/dist/cjs/agents/content_processor_utils.js +1 -1
- package/dist/cjs/{tools/tool_context.js → agents/context.js} +71 -16
- package/dist/cjs/agents/functions.js +4 -3
- package/dist/cjs/agents/instructions.js +1 -1
- package/dist/cjs/agents/invocation_context.js +1 -1
- package/dist/cjs/agents/live_request_queue.js +1 -1
- package/dist/cjs/agents/llm_agent.js +76 -711
- package/dist/cjs/agents/loop_agent.js +1 -1
- package/dist/cjs/agents/parallel_agent.js +1 -1
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +132 -0
- package/dist/cjs/agents/{base_llm_processor.js → processors/base_llm_processor.js} +1 -1
- 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/processors/content_request_processor.js +66 -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/agents/readonly_context.js +13 -1
- package/dist/cjs/agents/run_config.js +2 -1
- package/dist/cjs/agents/sequential_agent.js +1 -1
- package/dist/cjs/agents/transcription_entry.js +1 -1
- package/dist/cjs/artifacts/base_artifact_service.js +1 -1
- package/dist/cjs/artifacts/file_artifact_service.js +491 -0
- package/dist/cjs/artifacts/gcs_artifact_service.js +127 -48
- package/dist/cjs/artifacts/in_memory_artifact_service.js +54 -6
- package/dist/cjs/artifacts/registry.js +55 -0
- package/dist/cjs/auth/auth_credential.js +1 -1
- package/dist/cjs/auth/auth_handler.js +1 -1
- package/dist/cjs/auth/auth_schemes.js +1 -1
- package/dist/cjs/auth/auth_tool.js +1 -1
- package/dist/cjs/auth/credential_service/base_credential_service.js +1 -1
- package/dist/cjs/auth/credential_service/in_memory_credential_service.js +1 -1
- package/dist/cjs/auth/exchanger/base_credential_exchanger.js +1 -1
- package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +1 -1
- package/dist/cjs/code_executors/base_code_executor.js +1 -1
- package/dist/cjs/code_executors/built_in_code_executor.js +1 -1
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/code_executors/code_executor_context.js +1 -1
- package/dist/cjs/common.js +25 -8
- package/dist/cjs/events/event.js +33 -4
- package/dist/cjs/events/event_actions.js +2 -2
- package/dist/cjs/events/structured_events.js +105 -0
- package/dist/cjs/examples/base_example_provider.js +1 -1
- package/dist/cjs/examples/example.js +1 -1
- package/dist/cjs/examples/example_util.js +1 -1
- package/dist/cjs/index.js +24 -17
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/index_web.js +1 -1
- package/dist/cjs/memory/base_memory_service.js +1 -1
- package/dist/cjs/memory/in_memory_memory_service.js +1 -1
- package/dist/cjs/memory/memory_entry.js +1 -1
- package/dist/cjs/models/apigee_llm.js +182 -0
- package/dist/cjs/models/base_llm.js +1 -1
- package/dist/cjs/models/base_llm_connection.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +1 -1
- package/dist/cjs/models/google_llm.js +70 -51
- package/dist/cjs/models/llm_request.js +1 -1
- package/dist/cjs/models/llm_response.js +3 -1
- package/dist/cjs/models/registry.js +3 -1
- package/dist/cjs/plugins/base_plugin.js +2 -2
- package/dist/cjs/plugins/logging_plugin.js +1 -1
- package/dist/cjs/plugins/plugin_manager.js +1 -1
- package/dist/cjs/plugins/security_plugin.js +1 -1
- package/dist/cjs/runner/in_memory_runner.js +1 -1
- package/dist/cjs/runner/runner.js +33 -2
- package/dist/cjs/sessions/base_session_service.js +53 -3
- package/dist/cjs/sessions/database_session_service.js +367 -0
- package/dist/cjs/sessions/db/operations.js +126 -0
- package/dist/cjs/sessions/db/schema.js +204 -0
- package/dist/cjs/sessions/in_memory_session_service.js +24 -22
- package/dist/cjs/sessions/registry.js +49 -0
- package/dist/cjs/sessions/session.js +1 -1
- package/dist/cjs/sessions/state.js +1 -1
- package/dist/cjs/telemetry/google_cloud.js +1 -1
- package/dist/cjs/telemetry/setup.js +1 -1
- package/dist/cjs/telemetry/tracing.js +1 -1
- package/dist/cjs/tools/agent_tool.js +1 -1
- package/dist/cjs/tools/base_tool.js +4 -1
- package/dist/cjs/tools/base_toolset.js +14 -4
- package/dist/cjs/tools/exit_loop_tool.js +63 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +17 -1
- package/dist/cjs/tools/function_tool.js +1 -1
- package/dist/cjs/tools/google_search_tool.js +1 -1
- package/dist/cjs/tools/long_running_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +1 -1
- package/dist/cjs/tools/mcp/mcp_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_toolset.js +10 -6
- package/dist/cjs/tools/tool_confirmation.js +1 -1
- package/dist/cjs/utils/client_labels.js +1 -1
- package/dist/cjs/utils/env_aware_utils.js +10 -1
- package/dist/cjs/utils/gemini_schema_util.js +1 -1
- package/dist/cjs/utils/logger.js +62 -55
- package/dist/cjs/utils/model_name.js +1 -1
- package/dist/cjs/utils/object_notation_utils.js +78 -0
- package/dist/cjs/utils/simple_zod_to_json.js +1 -1
- package/dist/cjs/utils/variant_utils.js +3 -9
- package/dist/cjs/version.js +2 -2
- package/dist/esm/a2a/a2a_event.js +243 -0
- package/dist/esm/a2a/event_converter_utils.js +187 -0
- package/dist/esm/a2a/executor_context.js +23 -0
- package/dist/esm/a2a/metadata_converter_utils.js +90 -0
- package/dist/esm/a2a/part_converter_utils.js +175 -0
- package/dist/esm/agents/base_agent.js +5 -5
- package/dist/esm/{tools/tool_context.js → agents/context.js} +66 -11
- package/dist/esm/agents/functions.js +3 -2
- package/dist/esm/agents/llm_agent.js +69 -720
- 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/processors/content_request_processor.js +38 -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/agents/readonly_context.js +12 -0
- package/dist/esm/agents/run_config.js +1 -0
- package/dist/esm/artifacts/file_artifact_service.js +451 -0
- package/dist/esm/artifacts/gcs_artifact_service.js +126 -47
- package/dist/esm/artifacts/in_memory_artifact_service.js +51 -4
- package/dist/esm/artifacts/registry.js +28 -0
- package/dist/esm/common.js +20 -10
- package/dist/esm/events/event.js +29 -2
- package/dist/esm/events/event_actions.js +1 -1
- package/dist/esm/events/structured_events.js +74 -0
- package/dist/esm/index.js +24 -17
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/models/apigee_llm.js +152 -0
- package/dist/esm/models/google_llm.js +67 -49
- package/dist/esm/models/llm_response.js +2 -0
- package/dist/esm/models/registry.js +2 -0
- package/dist/esm/plugins/base_plugin.js +1 -1
- package/dist/esm/runner/runner.js +32 -1
- package/dist/esm/sessions/base_session_service.js +49 -1
- package/dist/esm/sessions/database_session_service.js +353 -0
- package/dist/esm/sessions/db/operations.js +111 -0
- package/dist/esm/sessions/db/schema.js +172 -0
- package/dist/esm/sessions/in_memory_session_service.js +23 -21
- package/dist/esm/sessions/registry.js +25 -0
- 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/forwarding_artifact_service.js +16 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +9 -5
- package/dist/esm/utils/env_aware_utils.js +8 -0
- package/dist/esm/utils/logger.js +51 -54
- package/dist/esm/utils/object_notation_utils.js +47 -0
- package/dist/esm/utils/variant_utils.js +1 -7
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_event.d.ts +122 -0
- package/dist/types/a2a/event_converter_utils.d.ts +20 -0
- package/dist/types/a2a/executor_context.d.ts +33 -0
- package/dist/types/a2a/metadata_converter_utils.d.ts +62 -0
- package/dist/types/a2a/part_converter_utils.d.ts +48 -0
- 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 +19 -42
- 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/processors/content_request_processor.d.ts +13 -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/agents/readonly_context.d.ts +8 -0
- package/dist/types/agents/run_config.d.ts +6 -0
- package/dist/types/artifacts/base_artifact_service.d.ts +31 -0
- package/dist/types/artifacts/file_artifact_service.d.ts +43 -0
- package/dist/types/artifacts/gcs_artifact_service.d.ts +3 -1
- package/dist/types/artifacts/in_memory_artifact_service.d.ts +5 -2
- package/dist/types/artifacts/registry.d.ts +7 -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 +15 -6
- package/dist/types/events/event.d.ts +15 -1
- package/dist/types/events/event_actions.d.ts +1 -1
- package/dist/types/events/structured_events.d.ts +106 -0
- package/dist/types/index.d.ts +5 -1
- package/dist/types/models/apigee_llm.d.ts +59 -0
- package/dist/types/models/google_llm.d.ts +5 -2
- 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 +15 -0
- package/dist/types/sessions/base_session_service.d.ts +20 -0
- package/dist/types/sessions/database_session_service.d.ts +32 -0
- package/dist/types/sessions/db/operations.d.ts +29 -0
- package/dist/types/sessions/db/schema.d.ts +45 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +4 -1
- package/dist/types/sessions/registry.d.ts +7 -0
- 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 +5 -3
- package/dist/types/tools/function_tool.d.ts +2 -2
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -1
- package/dist/types/utils/env_aware_utils.d.ts +7 -0
- package/dist/types/utils/logger.d.ts +5 -9
- package/dist/types/utils/object_notation_utils.d.ts +21 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_event.js +243 -0
- package/dist/web/a2a/event_converter_utils.js +201 -0
- package/dist/web/a2a/executor_context.js +23 -0
- package/dist/web/a2a/metadata_converter_utils.js +107 -0
- package/dist/web/a2a/part_converter_utils.js +175 -0
- package/dist/web/agents/base_agent.js +5 -5
- package/dist/web/{tools/tool_context.js → agents/context.js} +66 -11
- package/dist/web/agents/functions.js +3 -2
- package/dist/web/agents/llm_agent.js +90 -717
- 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/processors/content_request_processor.js +56 -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/agents/readonly_context.js +12 -0
- package/dist/web/agents/run_config.js +2 -1
- package/dist/web/artifacts/file_artifact_service.js +506 -0
- package/dist/web/artifacts/gcs_artifact_service.js +123 -46
- package/dist/web/artifacts/in_memory_artifact_service.js +51 -4
- package/dist/web/artifacts/registry.js +28 -0
- package/dist/web/common.js +20 -10
- package/dist/web/events/event.js +29 -2
- package/dist/web/events/event_actions.js +1 -1
- package/dist/web/events/structured_events.js +74 -0
- package/dist/web/index.js +7 -2
- package/dist/web/index.js.map +4 -4
- package/dist/web/models/apigee_llm.js +219 -0
- package/dist/web/models/google_llm.js +67 -46
- package/dist/web/models/llm_response.js +2 -0
- package/dist/web/models/registry.js +2 -0
- package/dist/web/plugins/base_plugin.js +1 -1
- package/dist/web/runner/runner.js +34 -1
- package/dist/web/sessions/base_session_service.js +49 -1
- package/dist/web/sessions/database_session_service.js +371 -0
- package/dist/web/sessions/db/operations.js +111 -0
- package/dist/web/sessions/db/schema.js +172 -0
- package/dist/web/sessions/in_memory_session_service.js +23 -21
- package/dist/web/sessions/registry.js +25 -0
- 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/forwarding_artifact_service.js +16 -0
- package/dist/web/tools/mcp/mcp_toolset.js +27 -5
- package/dist/web/utils/env_aware_utils.js +8 -0
- package/dist/web/utils/logger.js +51 -54
- package/dist/web/utils/object_notation_utils.js +47 -0
- package/dist/web/utils/variant_utils.js +1 -7
- package/dist/web/version.js +1 -1
- package/package.json +13 -3
- 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/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,219 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
8
|
+
var __typeError = (msg) => {
|
|
9
|
+
throw TypeError(msg);
|
|
10
|
+
};
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __await = function(promise, isYieldStar) {
|
|
25
|
+
this[0] = promise;
|
|
26
|
+
this[1] = isYieldStar;
|
|
27
|
+
};
|
|
28
|
+
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
29
|
+
var resume = (k, v, yes, no) => {
|
|
30
|
+
try {
|
|
31
|
+
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
32
|
+
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));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
no(e);
|
|
35
|
+
}
|
|
36
|
+
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
37
|
+
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
38
|
+
};
|
|
39
|
+
var __yieldStar = (value) => {
|
|
40
|
+
var obj = value[__knownSymbol("asyncIterator")], isAwait = false, method, it = {};
|
|
41
|
+
if (obj == null) {
|
|
42
|
+
obj = value[__knownSymbol("iterator")]();
|
|
43
|
+
method = (k) => it[k] = (x) => obj[k](x);
|
|
44
|
+
} else {
|
|
45
|
+
obj = obj.call(value);
|
|
46
|
+
method = (k) => it[k] = (v) => {
|
|
47
|
+
if (isAwait) {
|
|
48
|
+
isAwait = false;
|
|
49
|
+
if (k === "throw") throw v;
|
|
50
|
+
return v;
|
|
51
|
+
}
|
|
52
|
+
isAwait = true;
|
|
53
|
+
return {
|
|
54
|
+
done: false,
|
|
55
|
+
value: new __await(new Promise((resolve) => {
|
|
56
|
+
var x = obj[k](v);
|
|
57
|
+
if (!(x instanceof Object)) __typeError("Object expected");
|
|
58
|
+
resolve(x);
|
|
59
|
+
}), 1)
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => {
|
|
64
|
+
throw x;
|
|
65
|
+
}, "return" in obj && method("return"), it;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* @license
|
|
69
|
+
* Copyright 2026 Google LLC
|
|
70
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
71
|
+
*/
|
|
72
|
+
import { isBrowser } from "../utils/env_aware_utils.js";
|
|
73
|
+
import { logger } from "../utils/logger.js";
|
|
74
|
+
import { Gemini, geminiInitParams } from "./google_llm.js";
|
|
75
|
+
const APIGEE_PROXY_URL_ENV_VARIABLE_NAME = "APIGEE_PROXY_URL";
|
|
76
|
+
class ApigeeLlm extends Gemini {
|
|
77
|
+
constructor({
|
|
78
|
+
model,
|
|
79
|
+
proxyUrl,
|
|
80
|
+
apiKey,
|
|
81
|
+
vertexai,
|
|
82
|
+
location,
|
|
83
|
+
project,
|
|
84
|
+
headers
|
|
85
|
+
}) {
|
|
86
|
+
var _a;
|
|
87
|
+
if (!validateModel(model)) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
"Model ".concat(model, " is not a valid Apigee model, expected apigee/[<provider>/][<version>/]<model_id>")
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
super(__spreadProps(__spreadValues({}, apigeeToGeminiInitParams({ model, vertexai, project, location, apiKey })), {
|
|
93
|
+
headers
|
|
94
|
+
}));
|
|
95
|
+
this.proxyUrl = proxyUrl != null ? proxyUrl : "";
|
|
96
|
+
if (!isBrowser() && !this.proxyUrl) {
|
|
97
|
+
this.proxyUrl = (_a = process.env[APIGEE_PROXY_URL_ENV_VARIABLE_NAME]) != null ? _a : "";
|
|
98
|
+
}
|
|
99
|
+
if (!this.proxyUrl) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
"Proxy URL must be provided via the constructor or ".concat(APIGEE_PROXY_URL_ENV_VARIABLE_NAME, " environment variable.")
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
getHttpOptions() {
|
|
106
|
+
const opts = super.getHttpOptions();
|
|
107
|
+
opts.baseUrl = this.proxyUrl;
|
|
108
|
+
return opts;
|
|
109
|
+
}
|
|
110
|
+
getLiveHttpOptions() {
|
|
111
|
+
const opts = super.getLiveHttpOptions();
|
|
112
|
+
opts.baseUrl = this.proxyUrl;
|
|
113
|
+
return opts;
|
|
114
|
+
}
|
|
115
|
+
identifyApiVersion() {
|
|
116
|
+
const modelTrimmed = this.model.startsWith("apigee/") ? this.model.substring("apigee/".length) : this.model;
|
|
117
|
+
const components = modelTrimmed.split("/");
|
|
118
|
+
if (components.length === 3) {
|
|
119
|
+
return components[1];
|
|
120
|
+
}
|
|
121
|
+
if (components.length === 2) {
|
|
122
|
+
if (components[0] != "vertex_ai" && components[0] != "gemini" && components[0].startsWith("v")) {
|
|
123
|
+
return components[0];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return this.vertexai ? "v1beta1" : "v1alpha";
|
|
127
|
+
}
|
|
128
|
+
get liveApiVersion() {
|
|
129
|
+
if (!this._apigeeLiveApiVersion) {
|
|
130
|
+
this._apigeeLiveApiVersion = this.identifyApiVersion();
|
|
131
|
+
}
|
|
132
|
+
return this._apigeeLiveApiVersion;
|
|
133
|
+
}
|
|
134
|
+
generateContentAsync(llmRequest, stream = false) {
|
|
135
|
+
return __asyncGenerator(this, null, function* () {
|
|
136
|
+
var _a;
|
|
137
|
+
const modelToUse = (_a = llmRequest.model) != null ? _a : this.model;
|
|
138
|
+
llmRequest.model = getModelId(modelToUse);
|
|
139
|
+
yield* __yieldStar(super.generateContentAsync(llmRequest, stream));
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
async connect(llmRequest) {
|
|
143
|
+
var _a;
|
|
144
|
+
const modelToUse = (_a = llmRequest.model) != null ? _a : this.model;
|
|
145
|
+
llmRequest.model = getModelId(modelToUse);
|
|
146
|
+
return super.connect(llmRequest);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* A list of model name patterns that are supported by this LLM.
|
|
151
|
+
*
|
|
152
|
+
* @returns A list of supported models.
|
|
153
|
+
*/
|
|
154
|
+
ApigeeLlm.supportedModels = [
|
|
155
|
+
/apigee\/.*/
|
|
156
|
+
];
|
|
157
|
+
function apigeeToGeminiInitParams({
|
|
158
|
+
model,
|
|
159
|
+
vertexai,
|
|
160
|
+
project,
|
|
161
|
+
location,
|
|
162
|
+
apiKey
|
|
163
|
+
}) {
|
|
164
|
+
var _a;
|
|
165
|
+
const params = geminiInitParams({ model, vertexai, project, location, apiKey });
|
|
166
|
+
params.vertexai = params.vertexai || ((_a = params.model) == null ? void 0 : _a.startsWith("apigee/vertex_ai/"));
|
|
167
|
+
if (params.vertexai) {
|
|
168
|
+
return params;
|
|
169
|
+
}
|
|
170
|
+
if (!params.apiKey) {
|
|
171
|
+
logger.warn(
|
|
172
|
+
'No API key provided when using a Gemini model, using a fake key "-".'
|
|
173
|
+
);
|
|
174
|
+
params.apiKey = "-";
|
|
175
|
+
}
|
|
176
|
+
return params;
|
|
177
|
+
}
|
|
178
|
+
function getModelId(model) {
|
|
179
|
+
if (!validateModel(model)) {
|
|
180
|
+
throw new Error(
|
|
181
|
+
"Model ".concat(model, " is not a valid Apigee model, expected apigee/[<provider>/][<version>/]<model_id>")
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
const components = model.split("/");
|
|
185
|
+
return components[components.length - 1];
|
|
186
|
+
}
|
|
187
|
+
function validateModel(model) {
|
|
188
|
+
const validProviders = ["vertex_ai", "gemini"];
|
|
189
|
+
if (!model.startsWith("apigee/")) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
const modelPart = model.substring("apigee/".length);
|
|
193
|
+
if (modelPart.length === 0) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
const components = modelPart.split("/", -1);
|
|
197
|
+
if (components[components.length - 1].length === 0) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
if (components.length == 1) {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
if (components.length == 2) {
|
|
204
|
+
if (validProviders.includes(components[0])) {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
return components[0].startsWith("v");
|
|
208
|
+
}
|
|
209
|
+
if (components.length == 3) {
|
|
210
|
+
if (!validProviders.includes(components[0])) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
return components[1].startsWith("v");
|
|
214
|
+
}
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
export {
|
|
218
|
+
ApigeeLlm
|
|
219
|
+
};
|
|
@@ -41,6 +41,7 @@ import {
|
|
|
41
41
|
FinishReason,
|
|
42
42
|
GoogleGenAI
|
|
43
43
|
} from "@google/genai";
|
|
44
|
+
import { getBooleanEnvVar, isBrowser } from "../utils/env_aware_utils.js";
|
|
44
45
|
import { logger } from "../utils/logger.js";
|
|
45
46
|
import { GoogleLLMVariant } from "../utils/variant_utils.js";
|
|
46
47
|
import { BaseLlm } from "./base_llm.js";
|
|
@@ -62,45 +63,23 @@ class Gemini extends BaseLlm {
|
|
|
62
63
|
model = "gemini-2.5-flash";
|
|
63
64
|
}
|
|
64
65
|
super({ model });
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
if (this.vertexai) {
|
|
78
|
-
if (canReadEnv && !this.project) {
|
|
79
|
-
this.project = process.env["GOOGLE_CLOUD_PROJECT"];
|
|
80
|
-
}
|
|
81
|
-
if (canReadEnv && !this.location) {
|
|
82
|
-
this.location = process.env["GOOGLE_CLOUD_LOCATION"];
|
|
83
|
-
}
|
|
84
|
-
if (!this.project) {
|
|
85
|
-
throw new Error(
|
|
86
|
-
"VertexAI project must be provided via constructor or GOOGLE_CLOUD_PROJECT environment variable."
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
if (!this.location) {
|
|
90
|
-
throw new Error(
|
|
91
|
-
"VertexAI location must be provided via constructor or GOOGLE_CLOUD_LOCATION environment variable."
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
if (!this.apiKey && canReadEnv) {
|
|
96
|
-
this.apiKey = process.env["GOOGLE_GENAI_API_KEY"] || process.env["GEMINI_API_KEY"];
|
|
97
|
-
}
|
|
98
|
-
if (!this.apiKey) {
|
|
99
|
-
throw new Error(
|
|
100
|
-
"API key must be provided via constructor or GOOGLE_GENAI_API_KEY or GEMINI_API_KEY environment variable."
|
|
101
|
-
);
|
|
102
|
-
}
|
|
66
|
+
const params = geminiInitParams({
|
|
67
|
+
model,
|
|
68
|
+
vertexai,
|
|
69
|
+
project,
|
|
70
|
+
location,
|
|
71
|
+
apiKey
|
|
72
|
+
});
|
|
73
|
+
if (!params.vertexai && !params.apiKey) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
"API key must be provided via constructor or GOOGLE_GENAI_API_KEY or GEMINI_API_KEY environment variable."
|
|
76
|
+
);
|
|
103
77
|
}
|
|
78
|
+
this.project = params.project;
|
|
79
|
+
this.location = params.location;
|
|
80
|
+
this.apiKey = params.apiKey;
|
|
81
|
+
this.headers = headers;
|
|
82
|
+
this.vertexai = !!params.vertexai;
|
|
104
83
|
}
|
|
105
84
|
/**
|
|
106
85
|
* Sends a request to the Gemini model.
|
|
@@ -200,22 +179,24 @@ class Gemini extends BaseLlm {
|
|
|
200
179
|
}
|
|
201
180
|
});
|
|
202
181
|
}
|
|
182
|
+
getHttpOptions() {
|
|
183
|
+
return { headers: __spreadValues(__spreadValues({}, this.trackingHeaders), this.headers) };
|
|
184
|
+
}
|
|
203
185
|
get apiClient() {
|
|
204
186
|
if (this._apiClient) {
|
|
205
187
|
return this._apiClient;
|
|
206
188
|
}
|
|
207
|
-
const combinedHeaders = __spreadValues(__spreadValues({}, this.trackingHeaders), this.headers);
|
|
208
189
|
if (this.vertexai) {
|
|
209
190
|
this._apiClient = new GoogleGenAI({
|
|
210
191
|
vertexai: this.vertexai,
|
|
211
192
|
project: this.project,
|
|
212
193
|
location: this.location,
|
|
213
|
-
httpOptions:
|
|
194
|
+
httpOptions: this.getHttpOptions()
|
|
214
195
|
});
|
|
215
196
|
} else {
|
|
216
197
|
this._apiClient = new GoogleGenAI({
|
|
217
198
|
apiKey: this.apiKey,
|
|
218
|
-
httpOptions:
|
|
199
|
+
httpOptions: this.getHttpOptions()
|
|
219
200
|
});
|
|
220
201
|
}
|
|
221
202
|
return this._apiClient;
|
|
@@ -232,14 +213,17 @@ class Gemini extends BaseLlm {
|
|
|
232
213
|
}
|
|
233
214
|
return this._liveApiVersion;
|
|
234
215
|
}
|
|
216
|
+
getLiveHttpOptions() {
|
|
217
|
+
return {
|
|
218
|
+
headers: this.trackingHeaders,
|
|
219
|
+
apiVersion: this.liveApiVersion
|
|
220
|
+
};
|
|
221
|
+
}
|
|
235
222
|
get liveApiClient() {
|
|
236
223
|
if (!this._liveApiClient) {
|
|
237
224
|
this._liveApiClient = new GoogleGenAI({
|
|
238
225
|
apiKey: this.apiKey,
|
|
239
|
-
httpOptions:
|
|
240
|
-
headers: this.trackingHeaders,
|
|
241
|
-
apiVersion: this.liveApiVersion
|
|
242
|
-
}
|
|
226
|
+
httpOptions: this.getLiveHttpOptions()
|
|
243
227
|
});
|
|
244
228
|
}
|
|
245
229
|
return this._liveApiClient;
|
|
@@ -317,6 +301,43 @@ function removeDisplayNameIfPresent(dataObj) {
|
|
|
317
301
|
dataObj.displayName = void 0;
|
|
318
302
|
}
|
|
319
303
|
}
|
|
304
|
+
function geminiInitParams({
|
|
305
|
+
model,
|
|
306
|
+
vertexai,
|
|
307
|
+
project,
|
|
308
|
+
location,
|
|
309
|
+
apiKey
|
|
310
|
+
}) {
|
|
311
|
+
const params = { model, vertexai, project, location, apiKey };
|
|
312
|
+
params.vertexai = !!vertexai;
|
|
313
|
+
if (!params.vertexai && !isBrowser()) {
|
|
314
|
+
params.vertexai = getBooleanEnvVar("GOOGLE_GENAI_USE_VERTEXAI");
|
|
315
|
+
}
|
|
316
|
+
if (params.vertexai) {
|
|
317
|
+
if (!isBrowser() && !params.project) {
|
|
318
|
+
params.project = process.env["GOOGLE_CLOUD_PROJECT"];
|
|
319
|
+
}
|
|
320
|
+
if (!isBrowser() && !params.location) {
|
|
321
|
+
params.location = process.env["GOOGLE_CLOUD_LOCATION"];
|
|
322
|
+
}
|
|
323
|
+
if (!params.project) {
|
|
324
|
+
throw new Error(
|
|
325
|
+
"VertexAI project must be provided via constructor or GOOGLE_CLOUD_PROJECT environment variable."
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
if (!params.location) {
|
|
329
|
+
throw new Error(
|
|
330
|
+
"VertexAI location must be provided via constructor or GOOGLE_CLOUD_LOCATION environment variable."
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
} else {
|
|
334
|
+
if (!params.apiKey && !isBrowser()) {
|
|
335
|
+
params.apiKey = process.env["GOOGLE_GENAI_API_KEY"] || process.env["GEMINI_API_KEY"];
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return params;
|
|
339
|
+
}
|
|
320
340
|
export {
|
|
321
|
-
Gemini
|
|
341
|
+
Gemini,
|
|
342
|
+
geminiInitParams
|
|
322
343
|
};
|
|
@@ -12,6 +12,7 @@ function createLlmResponse(response) {
|
|
|
12
12
|
return {
|
|
13
13
|
content: candidate.content,
|
|
14
14
|
groundingMetadata: candidate.groundingMetadata,
|
|
15
|
+
citationMetadata: candidate.citationMetadata,
|
|
15
16
|
usageMetadata,
|
|
16
17
|
finishReason: candidate.finishReason
|
|
17
18
|
};
|
|
@@ -20,6 +21,7 @@ function createLlmResponse(response) {
|
|
|
20
21
|
errorCode: candidate.finishReason,
|
|
21
22
|
errorMessage: candidate.finishMessage,
|
|
22
23
|
usageMetadata,
|
|
24
|
+
citationMetadata: candidate.citationMetadata,
|
|
23
25
|
finishReason: candidate.finishReason
|
|
24
26
|
};
|
|
25
27
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { logger } from "../utils/logger.js";
|
|
7
|
+
import { ApigeeLlm } from "./apigee_llm.js";
|
|
7
8
|
import { Gemini } from "./google_llm.js";
|
|
8
9
|
class LRUCache {
|
|
9
10
|
constructor(maxSize) {
|
|
@@ -86,6 +87,7 @@ _LLMRegistry.llmRegistryDict = /* @__PURE__ */ new Map();
|
|
|
86
87
|
_LLMRegistry.resolveCache = new LRUCache(32);
|
|
87
88
|
let LLMRegistry = _LLMRegistry;
|
|
88
89
|
LLMRegistry.register(Gemini);
|
|
90
|
+
LLMRegistry.register(ApigeeLlm);
|
|
89
91
|
export {
|
|
90
92
|
LLMRegistry
|
|
91
93
|
};
|
|
@@ -198,7 +198,7 @@ class BasePlugin {
|
|
|
198
198
|
* Callback executed when a tool call encounters an error.
|
|
199
199
|
tool: BaseTool;
|
|
200
200
|
toolArgs: Record<string, unknown>;
|
|
201
|
-
toolContext:
|
|
201
|
+
toolContext: Context;
|
|
202
202
|
result: Record<string, unknown>;
|
|
203
203
|
}): Promise<Record<string, unknown> | undefined> {
|
|
204
204
|
return;
|
|
@@ -83,6 +83,39 @@ class Runner {
|
|
|
83
83
|
this.memoryService = input.memoryService;
|
|
84
84
|
this.credentialService = input.credentialService;
|
|
85
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Runs the agent with a new, ephemeral session.
|
|
88
|
+
*
|
|
89
|
+
* @param params.userId The user ID of the session.
|
|
90
|
+
* @param params.newMessage A new message to append to the session.
|
|
91
|
+
* @param params.stateDelta An optional state delta to apply to the session.
|
|
92
|
+
* @param params.runConfig The run config for the agent.
|
|
93
|
+
* @yields The Events generated by the agent.
|
|
94
|
+
*/
|
|
95
|
+
runEphemeral(params) {
|
|
96
|
+
return __asyncGenerator(this, null, function* () {
|
|
97
|
+
const session = yield new __await(this.sessionService.createSession({
|
|
98
|
+
appName: this.appName,
|
|
99
|
+
userId: params.userId
|
|
100
|
+
}));
|
|
101
|
+
const sessionId = session.id;
|
|
102
|
+
try {
|
|
103
|
+
yield* __yieldStar(this.runAsync({
|
|
104
|
+
userId: params.userId,
|
|
105
|
+
sessionId,
|
|
106
|
+
newMessage: params.newMessage,
|
|
107
|
+
stateDelta: params.stateDelta,
|
|
108
|
+
runConfig: params.runConfig
|
|
109
|
+
}));
|
|
110
|
+
} finally {
|
|
111
|
+
yield new __await(this.sessionService.deleteSession({
|
|
112
|
+
appName: this.appName,
|
|
113
|
+
userId: params.userId,
|
|
114
|
+
sessionId
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
86
119
|
/**
|
|
87
120
|
* Runs the agent with the given message, and returns an async generator of
|
|
88
121
|
* events.
|
|
@@ -277,7 +310,7 @@ class Runner {
|
|
|
277
310
|
return rootAgent.findAgent(event.author) || rootAgent;
|
|
278
311
|
}
|
|
279
312
|
for (let i = session.events.length - 1; i >= 0; i--) {
|
|
280
|
-
logger.info("event:
|
|
313
|
+
logger.info("event:", JSON.stringify(session.events[i]));
|
|
281
314
|
const event2 = session.events[i];
|
|
282
315
|
if (event2.author === "user" || !event2.author) {
|
|
283
316
|
continue;
|
|
@@ -3,8 +3,29 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { cloneDeep } from "lodash-es";
|
|
6
7
|
import { State } from "./state.js";
|
|
7
8
|
class BaseSessionService {
|
|
9
|
+
/**
|
|
10
|
+
* Gets a session or creates one if it doesn't exist.
|
|
11
|
+
*
|
|
12
|
+
* @param request The request to get or create a session.
|
|
13
|
+
* @return A promise that resolves to the session instance.
|
|
14
|
+
*/
|
|
15
|
+
async getOrCreateSession(request) {
|
|
16
|
+
if (!request.sessionId) {
|
|
17
|
+
return this.createSession(request);
|
|
18
|
+
}
|
|
19
|
+
const session = await this.getSession({
|
|
20
|
+
appName: request.appName,
|
|
21
|
+
userId: request.userId,
|
|
22
|
+
sessionId: request.sessionId
|
|
23
|
+
});
|
|
24
|
+
if (session) {
|
|
25
|
+
return session;
|
|
26
|
+
}
|
|
27
|
+
return this.createSession(request);
|
|
28
|
+
}
|
|
8
29
|
/**
|
|
9
30
|
* Appends an event to a session.
|
|
10
31
|
*
|
|
@@ -15,6 +36,7 @@ class BaseSessionService {
|
|
|
15
36
|
if (event.partial) {
|
|
16
37
|
return event;
|
|
17
38
|
}
|
|
39
|
+
event = trimTempDeltaState(event);
|
|
18
40
|
this.updateSessionState({ session, event });
|
|
19
41
|
session.events.push(event);
|
|
20
42
|
return event;
|
|
@@ -36,6 +58,32 @@ class BaseSessionService {
|
|
|
36
58
|
}
|
|
37
59
|
}
|
|
38
60
|
}
|
|
61
|
+
function trimTempDeltaState(event) {
|
|
62
|
+
if (!event.actions || !event.actions.stateDelta) {
|
|
63
|
+
return event;
|
|
64
|
+
}
|
|
65
|
+
const stateDelta = event.actions.stateDelta;
|
|
66
|
+
const filteredStateDelta = {};
|
|
67
|
+
for (const [key, value] of Object.entries(stateDelta)) {
|
|
68
|
+
if (!key.startsWith(State.TEMP_PREFIX)) {
|
|
69
|
+
filteredStateDelta[key] = value;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
event.actions.stateDelta = filteredStateDelta;
|
|
73
|
+
return event;
|
|
74
|
+
}
|
|
75
|
+
function mergeStates(appState = {}, userState = {}, sessionState = {}) {
|
|
76
|
+
const merged = cloneDeep(sessionState);
|
|
77
|
+
for (const [k, v] of Object.entries(appState)) {
|
|
78
|
+
merged[State.APP_PREFIX + k] = v;
|
|
79
|
+
}
|
|
80
|
+
for (const [k, v] of Object.entries(userState)) {
|
|
81
|
+
merged[State.USER_PREFIX + k] = v;
|
|
82
|
+
}
|
|
83
|
+
return merged;
|
|
84
|
+
}
|
|
39
85
|
export {
|
|
40
|
-
BaseSessionService
|
|
86
|
+
BaseSessionService,
|
|
87
|
+
mergeStates,
|
|
88
|
+
trimTempDeltaState
|
|
41
89
|
};
|