@google/adk 0.3.0 → 0.4.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/part_converter_utils.js +210 -0
- package/dist/cjs/agents/active_streaming_tool.js +1 -1
- package/dist/cjs/agents/base_agent.js +3 -3
- package/dist/cjs/agents/base_llm_processor.js +1 -1
- package/dist/cjs/agents/callback_context.js +1 -1
- package/dist/cjs/agents/content_processor_utils.js +1 -1
- package/dist/cjs/agents/functions.js +2 -1
- 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 +58 -40
- package/dist/cjs/agents/loop_agent.js +1 -1
- package/dist/cjs/agents/parallel_agent.js +1 -1
- 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 +14 -1
- 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 +54 -83
- 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 +1 -1
- package/dist/cjs/models/registry.js +3 -1
- package/dist/cjs/plugins/base_plugin.js +1 -1
- 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 +32 -1
- package/dist/cjs/sessions/base_session_service.js +53 -3
- package/dist/cjs/sessions/database_session_service.js +364 -0
- package/dist/cjs/sessions/db/operations.js +114 -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 +1 -1
- package/dist/cjs/tools/base_toolset.js +1 -1
- 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 +1 -1
- package/dist/cjs/tools/tool_confirmation.js +1 -1
- package/dist/cjs/tools/tool_context.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 +1 -1
- 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/part_converter_utils.js +171 -0
- package/dist/esm/agents/base_agent.js +2 -2
- package/dist/esm/agents/functions.js +1 -0
- package/dist/esm/agents/llm_agent.js +58 -40
- 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 +9 -1
- 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 +18 -88
- package/dist/esm/models/apigee_llm.js +152 -0
- package/dist/esm/models/google_llm.js +67 -49
- package/dist/esm/models/registry.js +2 -0
- package/dist/esm/runner/runner.js +31 -0
- package/dist/esm/sessions/base_session_service.js +49 -1
- package/dist/esm/sessions/database_session_service.js +350 -0
- package/dist/esm/sessions/db/operations.js +87 -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/forwarding_artifact_service.js +16 -0
- package/dist/esm/utils/env_aware_utils.js +8 -0
- 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/part_converter_utils.d.ts +47 -0
- package/dist/types/agents/llm_agent.d.ts +11 -11
- 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/common.d.ts +11 -2
- 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/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 +31 -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/forwarding_artifact_service.d.ts +3 -1
- package/dist/types/utils/env_aware_utils.d.ts +7 -0
- package/dist/types/utils/object_notation_utils.d.ts +21 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/part_converter_utils.js +171 -0
- package/dist/web/agents/base_agent.js +2 -2
- package/dist/web/agents/functions.js +1 -0
- package/dist/web/agents/llm_agent.js +79 -59
- 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 +9 -1
- 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 +18 -8
- package/dist/web/models/apigee_llm.js +219 -0
- package/dist/web/models/google_llm.js +67 -46
- package/dist/web/models/registry.js +2 -0
- package/dist/web/runner/runner.js +33 -0
- package/dist/web/sessions/base_session_service.js +49 -1
- package/dist/web/sessions/database_session_service.js +368 -0
- package/dist/web/sessions/db/operations.js +87 -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/forwarding_artifact_service.js +16 -0
- package/dist/web/utils/env_aware_utils.js +8 -0
- 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 -4
- package/dist/cjs/index.js.map +0 -7
- package/dist/esm/index.js.map +0 -7
- package/dist/web/index.js.map +0 -7
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var apigee_llm_exports = {};
|
|
26
|
+
__export(apigee_llm_exports, {
|
|
27
|
+
ApigeeLlm: () => ApigeeLlm
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(apigee_llm_exports);
|
|
30
|
+
var import_env_aware_utils = require("../utils/env_aware_utils.js");
|
|
31
|
+
var import_logger = require("../utils/logger.js");
|
|
32
|
+
var import_google_llm = require("./google_llm.js");
|
|
33
|
+
/**
|
|
34
|
+
* @license
|
|
35
|
+
* Copyright 2026 Google LLC
|
|
36
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
37
|
+
*/
|
|
38
|
+
const APIGEE_PROXY_URL_ENV_VARIABLE_NAME = "APIGEE_PROXY_URL";
|
|
39
|
+
class ApigeeLlm extends import_google_llm.Gemini {
|
|
40
|
+
constructor({
|
|
41
|
+
model,
|
|
42
|
+
proxyUrl,
|
|
43
|
+
apiKey,
|
|
44
|
+
vertexai,
|
|
45
|
+
location,
|
|
46
|
+
project,
|
|
47
|
+
headers
|
|
48
|
+
}) {
|
|
49
|
+
var _a;
|
|
50
|
+
if (!validateModel(model)) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Model ${model} is not a valid Apigee model, expected apigee/[<provider>/][<version>/]<model_id>`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
super({
|
|
56
|
+
...apigeeToGeminiInitParams({ model, vertexai, project, location, apiKey }),
|
|
57
|
+
headers
|
|
58
|
+
});
|
|
59
|
+
this.proxyUrl = proxyUrl != null ? proxyUrl : "";
|
|
60
|
+
if (!(0, import_env_aware_utils.isBrowser)() && !this.proxyUrl) {
|
|
61
|
+
this.proxyUrl = (_a = process.env[APIGEE_PROXY_URL_ENV_VARIABLE_NAME]) != null ? _a : "";
|
|
62
|
+
}
|
|
63
|
+
if (!this.proxyUrl) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
`Proxy URL must be provided via the constructor or ${APIGEE_PROXY_URL_ENV_VARIABLE_NAME} environment variable.`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
getHttpOptions() {
|
|
70
|
+
const opts = super.getHttpOptions();
|
|
71
|
+
opts.baseUrl = this.proxyUrl;
|
|
72
|
+
return opts;
|
|
73
|
+
}
|
|
74
|
+
getLiveHttpOptions() {
|
|
75
|
+
const opts = super.getLiveHttpOptions();
|
|
76
|
+
opts.baseUrl = this.proxyUrl;
|
|
77
|
+
return opts;
|
|
78
|
+
}
|
|
79
|
+
identifyApiVersion() {
|
|
80
|
+
const modelTrimmed = this.model.startsWith("apigee/") ? this.model.substring("apigee/".length) : this.model;
|
|
81
|
+
const components = modelTrimmed.split("/");
|
|
82
|
+
if (components.length === 3) {
|
|
83
|
+
return components[1];
|
|
84
|
+
}
|
|
85
|
+
if (components.length === 2) {
|
|
86
|
+
if (components[0] != "vertex_ai" && components[0] != "gemini" && components[0].startsWith("v")) {
|
|
87
|
+
return components[0];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return this.vertexai ? "v1beta1" : "v1alpha";
|
|
91
|
+
}
|
|
92
|
+
get liveApiVersion() {
|
|
93
|
+
if (!this._apigeeLiveApiVersion) {
|
|
94
|
+
this._apigeeLiveApiVersion = this.identifyApiVersion();
|
|
95
|
+
}
|
|
96
|
+
return this._apigeeLiveApiVersion;
|
|
97
|
+
}
|
|
98
|
+
async *generateContentAsync(llmRequest, stream = false) {
|
|
99
|
+
var _a;
|
|
100
|
+
const modelToUse = (_a = llmRequest.model) != null ? _a : this.model;
|
|
101
|
+
llmRequest.model = getModelId(modelToUse);
|
|
102
|
+
yield* super.generateContentAsync(llmRequest, stream);
|
|
103
|
+
}
|
|
104
|
+
async connect(llmRequest) {
|
|
105
|
+
var _a;
|
|
106
|
+
const modelToUse = (_a = llmRequest.model) != null ? _a : this.model;
|
|
107
|
+
llmRequest.model = getModelId(modelToUse);
|
|
108
|
+
return super.connect(llmRequest);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* A list of model name patterns that are supported by this LLM.
|
|
113
|
+
*
|
|
114
|
+
* @returns A list of supported models.
|
|
115
|
+
*/
|
|
116
|
+
ApigeeLlm.supportedModels = [
|
|
117
|
+
/apigee\/.*/
|
|
118
|
+
];
|
|
119
|
+
function apigeeToGeminiInitParams({
|
|
120
|
+
model,
|
|
121
|
+
vertexai,
|
|
122
|
+
project,
|
|
123
|
+
location,
|
|
124
|
+
apiKey
|
|
125
|
+
}) {
|
|
126
|
+
var _a;
|
|
127
|
+
const params = (0, import_google_llm.geminiInitParams)({ model, vertexai, project, location, apiKey });
|
|
128
|
+
params.vertexai = params.vertexai || ((_a = params.model) == null ? void 0 : _a.startsWith("apigee/vertex_ai/"));
|
|
129
|
+
if (params.vertexai) {
|
|
130
|
+
return params;
|
|
131
|
+
}
|
|
132
|
+
if (!params.apiKey) {
|
|
133
|
+
import_logger.logger.warn(
|
|
134
|
+
`No API key provided when using a Gemini model, using a fake key "-".`
|
|
135
|
+
);
|
|
136
|
+
params.apiKey = "-";
|
|
137
|
+
}
|
|
138
|
+
return params;
|
|
139
|
+
}
|
|
140
|
+
function getModelId(model) {
|
|
141
|
+
if (!validateModel(model)) {
|
|
142
|
+
throw new Error(
|
|
143
|
+
`Model ${model} is not a valid Apigee model, expected apigee/[<provider>/][<version>/]<model_id>`
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
const components = model.split("/");
|
|
147
|
+
return components[components.length - 1];
|
|
148
|
+
}
|
|
149
|
+
function validateModel(model) {
|
|
150
|
+
const validProviders = ["vertex_ai", "gemini"];
|
|
151
|
+
if (!model.startsWith("apigee/")) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
const modelPart = model.substring("apigee/".length);
|
|
155
|
+
if (modelPart.length === 0) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
const components = modelPart.split("/", -1);
|
|
159
|
+
if (components[components.length - 1].length === 0) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
if (components.length == 1) {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
if (components.length == 2) {
|
|
166
|
+
if (validProviders.includes(components[0])) {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
return components[0].startsWith("v");
|
|
170
|
+
}
|
|
171
|
+
if (components.length == 3) {
|
|
172
|
+
if (!validProviders.includes(components[0])) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return components[1].startsWith("v");
|
|
176
|
+
}
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
180
|
+
0 && (module.exports = {
|
|
181
|
+
ApigeeLlm
|
|
182
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -24,10 +24,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var google_llm_exports = {};
|
|
26
26
|
__export(google_llm_exports, {
|
|
27
|
-
Gemini: () => Gemini
|
|
27
|
+
Gemini: () => Gemini,
|
|
28
|
+
geminiInitParams: () => geminiInitParams
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(google_llm_exports);
|
|
30
31
|
var import_genai = require("@google/genai");
|
|
32
|
+
var import_env_aware_utils = require("../utils/env_aware_utils.js");
|
|
31
33
|
var import_logger = require("../utils/logger.js");
|
|
32
34
|
var import_variant_utils = require("../utils/variant_utils.js");
|
|
33
35
|
var import_base_llm = require("./base_llm.js");
|
|
@@ -54,45 +56,23 @@ class Gemini extends import_base_llm.BaseLlm {
|
|
|
54
56
|
model = "gemini-2.5-flash";
|
|
55
57
|
}
|
|
56
58
|
super({ model });
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
if (this.vertexai) {
|
|
70
|
-
if (canReadEnv && !this.project) {
|
|
71
|
-
this.project = process.env["GOOGLE_CLOUD_PROJECT"];
|
|
72
|
-
}
|
|
73
|
-
if (canReadEnv && !this.location) {
|
|
74
|
-
this.location = process.env["GOOGLE_CLOUD_LOCATION"];
|
|
75
|
-
}
|
|
76
|
-
if (!this.project) {
|
|
77
|
-
throw new Error(
|
|
78
|
-
"VertexAI project must be provided via constructor or GOOGLE_CLOUD_PROJECT environment variable."
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
if (!this.location) {
|
|
82
|
-
throw new Error(
|
|
83
|
-
"VertexAI location must be provided via constructor or GOOGLE_CLOUD_LOCATION environment variable."
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
if (!this.apiKey && canReadEnv) {
|
|
88
|
-
this.apiKey = process.env["GOOGLE_GENAI_API_KEY"] || process.env["GEMINI_API_KEY"];
|
|
89
|
-
}
|
|
90
|
-
if (!this.apiKey) {
|
|
91
|
-
throw new Error(
|
|
92
|
-
"API key must be provided via constructor or GOOGLE_GENAI_API_KEY or GEMINI_API_KEY environment variable."
|
|
93
|
-
);
|
|
94
|
-
}
|
|
59
|
+
const params = geminiInitParams({
|
|
60
|
+
model,
|
|
61
|
+
vertexai,
|
|
62
|
+
project,
|
|
63
|
+
location,
|
|
64
|
+
apiKey
|
|
65
|
+
});
|
|
66
|
+
if (!params.vertexai && !params.apiKey) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
"API key must be provided via constructor or GOOGLE_GENAI_API_KEY or GEMINI_API_KEY environment variable."
|
|
69
|
+
);
|
|
95
70
|
}
|
|
71
|
+
this.project = params.project;
|
|
72
|
+
this.location = params.location;
|
|
73
|
+
this.apiKey = params.apiKey;
|
|
74
|
+
this.headers = headers;
|
|
75
|
+
this.vertexai = !!params.vertexai;
|
|
96
76
|
}
|
|
97
77
|
/**
|
|
98
78
|
* Sends a request to the Gemini model.
|
|
@@ -181,25 +161,24 @@ class Gemini extends import_base_llm.BaseLlm {
|
|
|
181
161
|
yield (0, import_llm_response.createLlmResponse)(response);
|
|
182
162
|
}
|
|
183
163
|
}
|
|
164
|
+
getHttpOptions() {
|
|
165
|
+
return { headers: { ...this.trackingHeaders, ...this.headers } };
|
|
166
|
+
}
|
|
184
167
|
get apiClient() {
|
|
185
168
|
if (this._apiClient) {
|
|
186
169
|
return this._apiClient;
|
|
187
170
|
}
|
|
188
|
-
const combinedHeaders = {
|
|
189
|
-
...this.trackingHeaders,
|
|
190
|
-
...this.headers
|
|
191
|
-
};
|
|
192
171
|
if (this.vertexai) {
|
|
193
172
|
this._apiClient = new import_genai.GoogleGenAI({
|
|
194
173
|
vertexai: this.vertexai,
|
|
195
174
|
project: this.project,
|
|
196
175
|
location: this.location,
|
|
197
|
-
httpOptions:
|
|
176
|
+
httpOptions: this.getHttpOptions()
|
|
198
177
|
});
|
|
199
178
|
} else {
|
|
200
179
|
this._apiClient = new import_genai.GoogleGenAI({
|
|
201
180
|
apiKey: this.apiKey,
|
|
202
|
-
httpOptions:
|
|
181
|
+
httpOptions: this.getHttpOptions()
|
|
203
182
|
});
|
|
204
183
|
}
|
|
205
184
|
return this._apiClient;
|
|
@@ -216,14 +195,17 @@ class Gemini extends import_base_llm.BaseLlm {
|
|
|
216
195
|
}
|
|
217
196
|
return this._liveApiVersion;
|
|
218
197
|
}
|
|
198
|
+
getLiveHttpOptions() {
|
|
199
|
+
return {
|
|
200
|
+
headers: this.trackingHeaders,
|
|
201
|
+
apiVersion: this.liveApiVersion
|
|
202
|
+
};
|
|
203
|
+
}
|
|
219
204
|
get liveApiClient() {
|
|
220
205
|
if (!this._liveApiClient) {
|
|
221
206
|
this._liveApiClient = new import_genai.GoogleGenAI({
|
|
222
207
|
apiKey: this.apiKey,
|
|
223
|
-
httpOptions:
|
|
224
|
-
headers: this.trackingHeaders,
|
|
225
|
-
apiVersion: this.liveApiVersion
|
|
226
|
-
}
|
|
208
|
+
httpOptions: this.getLiveHttpOptions()
|
|
227
209
|
});
|
|
228
210
|
}
|
|
229
211
|
return this._liveApiClient;
|
|
@@ -301,7 +283,44 @@ function removeDisplayNameIfPresent(dataObj) {
|
|
|
301
283
|
dataObj.displayName = void 0;
|
|
302
284
|
}
|
|
303
285
|
}
|
|
286
|
+
function geminiInitParams({
|
|
287
|
+
model,
|
|
288
|
+
vertexai,
|
|
289
|
+
project,
|
|
290
|
+
location,
|
|
291
|
+
apiKey
|
|
292
|
+
}) {
|
|
293
|
+
const params = { model, vertexai, project, location, apiKey };
|
|
294
|
+
params.vertexai = !!vertexai;
|
|
295
|
+
if (!params.vertexai && !(0, import_env_aware_utils.isBrowser)()) {
|
|
296
|
+
params.vertexai = (0, import_env_aware_utils.getBooleanEnvVar)("GOOGLE_GENAI_USE_VERTEXAI");
|
|
297
|
+
}
|
|
298
|
+
if (params.vertexai) {
|
|
299
|
+
if (!(0, import_env_aware_utils.isBrowser)() && !params.project) {
|
|
300
|
+
params.project = process.env["GOOGLE_CLOUD_PROJECT"];
|
|
301
|
+
}
|
|
302
|
+
if (!(0, import_env_aware_utils.isBrowser)() && !params.location) {
|
|
303
|
+
params.location = process.env["GOOGLE_CLOUD_LOCATION"];
|
|
304
|
+
}
|
|
305
|
+
if (!params.project) {
|
|
306
|
+
throw new Error(
|
|
307
|
+
"VertexAI project must be provided via constructor or GOOGLE_CLOUD_PROJECT environment variable."
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
if (!params.location) {
|
|
311
|
+
throw new Error(
|
|
312
|
+
"VertexAI location must be provided via constructor or GOOGLE_CLOUD_LOCATION environment variable."
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
} else {
|
|
316
|
+
if (!params.apiKey && !(0, import_env_aware_utils.isBrowser)()) {
|
|
317
|
+
params.apiKey = process.env["GOOGLE_GENAI_API_KEY"] || process.env["GEMINI_API_KEY"];
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return params;
|
|
321
|
+
}
|
|
304
322
|
// Annotate the CommonJS export names for ESM import in node:
|
|
305
323
|
0 && (module.exports = {
|
|
306
|
-
Gemini
|
|
324
|
+
Gemini,
|
|
325
|
+
geminiInitParams
|
|
307
326
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -28,6 +28,7 @@ __export(registry_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(registry_exports);
|
|
30
30
|
var import_logger = require("../utils/logger.js");
|
|
31
|
+
var import_apigee_llm = require("./apigee_llm.js");
|
|
31
32
|
var import_google_llm = require("./google_llm.js");
|
|
32
33
|
/**
|
|
33
34
|
* @license
|
|
@@ -115,6 +116,7 @@ _LLMRegistry.llmRegistryDict = /* @__PURE__ */ new Map();
|
|
|
115
116
|
_LLMRegistry.resolveCache = new LRUCache(32);
|
|
116
117
|
let LLMRegistry = _LLMRegistry;
|
|
117
118
|
LLMRegistry.register(import_google_llm.Gemini);
|
|
119
|
+
LLMRegistry.register(import_apigee_llm.ApigeeLlm);
|
|
118
120
|
// Annotate the CommonJS export names for ESM import in node:
|
|
119
121
|
0 && (module.exports = {
|
|
120
122
|
LLMRegistry
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -55,6 +55,37 @@ class Runner {
|
|
|
55
55
|
this.memoryService = input.memoryService;
|
|
56
56
|
this.credentialService = input.credentialService;
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Runs the agent with a new, ephemeral session.
|
|
60
|
+
*
|
|
61
|
+
* @param params.userId The user ID of the session.
|
|
62
|
+
* @param params.newMessage A new message to append to the session.
|
|
63
|
+
* @param params.stateDelta An optional state delta to apply to the session.
|
|
64
|
+
* @param params.runConfig The run config for the agent.
|
|
65
|
+
* @yields The Events generated by the agent.
|
|
66
|
+
*/
|
|
67
|
+
async *runEphemeral(params) {
|
|
68
|
+
const session = await this.sessionService.createSession({
|
|
69
|
+
appName: this.appName,
|
|
70
|
+
userId: params.userId
|
|
71
|
+
});
|
|
72
|
+
const sessionId = session.id;
|
|
73
|
+
try {
|
|
74
|
+
yield* this.runAsync({
|
|
75
|
+
userId: params.userId,
|
|
76
|
+
sessionId,
|
|
77
|
+
newMessage: params.newMessage,
|
|
78
|
+
stateDelta: params.stateDelta,
|
|
79
|
+
runConfig: params.runConfig
|
|
80
|
+
});
|
|
81
|
+
} finally {
|
|
82
|
+
await this.sessionService.deleteSession({
|
|
83
|
+
appName: this.appName,
|
|
84
|
+
userId: params.userId,
|
|
85
|
+
sessionId
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
58
89
|
/**
|
|
59
90
|
* Runs the agent with the given message, and returns an async generator of
|
|
60
91
|
* events.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -24,9 +24,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var base_session_service_exports = {};
|
|
26
26
|
__export(base_session_service_exports, {
|
|
27
|
-
BaseSessionService: () => BaseSessionService
|
|
27
|
+
BaseSessionService: () => BaseSessionService,
|
|
28
|
+
mergeStates: () => mergeStates,
|
|
29
|
+
trimTempDeltaState: () => trimTempDeltaState
|
|
28
30
|
});
|
|
29
31
|
module.exports = __toCommonJS(base_session_service_exports);
|
|
32
|
+
var import_lodash_es = require("lodash-es");
|
|
30
33
|
var import_state = require("./state.js");
|
|
31
34
|
/**
|
|
32
35
|
* @license
|
|
@@ -34,6 +37,26 @@ var import_state = require("./state.js");
|
|
|
34
37
|
* SPDX-License-Identifier: Apache-2.0
|
|
35
38
|
*/
|
|
36
39
|
class BaseSessionService {
|
|
40
|
+
/**
|
|
41
|
+
* Gets a session or creates one if it doesn't exist.
|
|
42
|
+
*
|
|
43
|
+
* @param request The request to get or create a session.
|
|
44
|
+
* @return A promise that resolves to the session instance.
|
|
45
|
+
*/
|
|
46
|
+
async getOrCreateSession(request) {
|
|
47
|
+
if (!request.sessionId) {
|
|
48
|
+
return this.createSession(request);
|
|
49
|
+
}
|
|
50
|
+
const session = await this.getSession({
|
|
51
|
+
appName: request.appName,
|
|
52
|
+
userId: request.userId,
|
|
53
|
+
sessionId: request.sessionId
|
|
54
|
+
});
|
|
55
|
+
if (session) {
|
|
56
|
+
return session;
|
|
57
|
+
}
|
|
58
|
+
return this.createSession(request);
|
|
59
|
+
}
|
|
37
60
|
/**
|
|
38
61
|
* Appends an event to a session.
|
|
39
62
|
*
|
|
@@ -44,6 +67,7 @@ class BaseSessionService {
|
|
|
44
67
|
if (event.partial) {
|
|
45
68
|
return event;
|
|
46
69
|
}
|
|
70
|
+
event = trimTempDeltaState(event);
|
|
47
71
|
this.updateSessionState({ session, event });
|
|
48
72
|
session.events.push(event);
|
|
49
73
|
return event;
|
|
@@ -65,7 +89,33 @@ class BaseSessionService {
|
|
|
65
89
|
}
|
|
66
90
|
}
|
|
67
91
|
}
|
|
92
|
+
function trimTempDeltaState(event) {
|
|
93
|
+
if (!event.actions || !event.actions.stateDelta) {
|
|
94
|
+
return event;
|
|
95
|
+
}
|
|
96
|
+
const stateDelta = event.actions.stateDelta;
|
|
97
|
+
const filteredStateDelta = {};
|
|
98
|
+
for (const [key, value] of Object.entries(stateDelta)) {
|
|
99
|
+
if (!key.startsWith(import_state.State.TEMP_PREFIX)) {
|
|
100
|
+
filteredStateDelta[key] = value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
event.actions.stateDelta = filteredStateDelta;
|
|
104
|
+
return event;
|
|
105
|
+
}
|
|
106
|
+
function mergeStates(appState = {}, userState = {}, sessionState = {}) {
|
|
107
|
+
const merged = (0, import_lodash_es.cloneDeep)(sessionState);
|
|
108
|
+
for (const [k, v] of Object.entries(appState)) {
|
|
109
|
+
merged[import_state.State.APP_PREFIX + k] = v;
|
|
110
|
+
}
|
|
111
|
+
for (const [k, v] of Object.entries(userState)) {
|
|
112
|
+
merged[import_state.State.USER_PREFIX + k] = v;
|
|
113
|
+
}
|
|
114
|
+
return merged;
|
|
115
|
+
}
|
|
68
116
|
// Annotate the CommonJS export names for ESM import in node:
|
|
69
117
|
0 && (module.exports = {
|
|
70
|
-
BaseSessionService
|
|
118
|
+
BaseSessionService,
|
|
119
|
+
mergeStates,
|
|
120
|
+
trimTempDeltaState
|
|
71
121
|
});
|