@paean-ai/adk 0.2.13 → 0.2.15
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/index.js +11 -11
- package/dist/cjs/index.js.map +3 -3
- package/dist/esm/index.js +11 -11
- package/dist/esm/index.js.map +3 -3
- package/dist/types/agents/llm_agent.d.ts +4 -0
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +3 -3
- package/package.json +3 -3
- package/dist/cjs/agents/active_streaming_tool.js +0 -44
- package/dist/cjs/agents/base_agent.js +0 -245
- package/dist/cjs/agents/base_llm_processor.js +0 -44
- package/dist/cjs/agents/callback_context.js +0 -98
- package/dist/cjs/agents/content_processor_utils.js +0 -346
- package/dist/cjs/agents/functions.js +0 -385
- package/dist/cjs/agents/instructions.js +0 -110
- package/dist/cjs/agents/invocation_context.js +0 -107
- package/dist/cjs/agents/live_request_queue.js +0 -136
- package/dist/cjs/agents/llm_agent.js +0 -1212
- package/dist/cjs/agents/loop_agent.js +0 -68
- package/dist/cjs/agents/parallel_agent.js +0 -78
- package/dist/cjs/agents/readonly_context.js +0 -68
- package/dist/cjs/agents/run_config.js +0 -70
- package/dist/cjs/agents/sequential_agent.js +0 -84
- package/dist/cjs/agents/transcription_entry.js +0 -27
- package/dist/cjs/artifacts/base_artifact_service.js +0 -27
- package/dist/cjs/artifacts/gcs_artifact_service.js +0 -140
- package/dist/cjs/artifacts/in_memory_artifact_service.js +0 -119
- package/dist/cjs/auth/auth_credential.js +0 -46
- package/dist/cjs/auth/auth_handler.js +0 -92
- package/dist/cjs/auth/auth_schemes.js +0 -62
- package/dist/cjs/auth/auth_tool.js +0 -27
- package/dist/cjs/auth/credential_service/base_credential_service.js +0 -27
- package/dist/cjs/auth/credential_service/in_memory_credential_service.js +0 -63
- package/dist/cjs/auth/exchanger/base_credential_exchanger.js +0 -40
- package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +0 -59
- package/dist/cjs/code_executors/base_code_executor.js +0 -76
- package/dist/cjs/code_executors/built_in_code_executor.js +0 -58
- package/dist/cjs/code_executors/code_execution_utils.js +0 -142
- package/dist/cjs/code_executors/code_executor_context.js +0 -198
- package/dist/cjs/common.js +0 -181
- package/dist/cjs/events/event.js +0 -119
- package/dist/cjs/events/event_actions.js +0 -83
- package/dist/cjs/examples/base_example_provider.js +0 -40
- package/dist/cjs/examples/example.js +0 -27
- package/dist/cjs/examples/example_util.js +0 -107
- package/dist/cjs/index_web.js +0 -33
- package/dist/cjs/memory/base_memory_service.js +0 -27
- package/dist/cjs/memory/in_memory_memory_service.js +0 -97
- package/dist/cjs/memory/memory_entry.js +0 -27
- package/dist/cjs/models/base_llm.js +0 -95
- package/dist/cjs/models/base_llm_connection.js +0 -27
- package/dist/cjs/models/gemini_llm_connection.js +0 -132
- package/dist/cjs/models/google_llm.js +0 -559
- package/dist/cjs/models/llm_request.js +0 -82
- package/dist/cjs/models/llm_response.js +0 -71
- package/dist/cjs/models/registry.js +0 -121
- package/dist/cjs/plugins/base_plugin.js +0 -236
- package/dist/cjs/plugins/logging_plugin.js +0 -222
- package/dist/cjs/plugins/plugin_manager.js +0 -239
- package/dist/cjs/plugins/security_plugin.js +0 -153
- package/dist/cjs/runner/in_memory_runner.js +0 -58
- package/dist/cjs/runner/runner.js +0 -277
- package/dist/cjs/sessions/base_session_service.js +0 -71
- package/dist/cjs/sessions/in_memory_session_service.js +0 -184
- package/dist/cjs/sessions/session.js +0 -48
- package/dist/cjs/sessions/state.js +0 -101
- package/dist/cjs/telemetry/google_cloud.js +0 -85
- package/dist/cjs/telemetry/setup.js +0 -97
- package/dist/cjs/telemetry/tracing.js +0 -231
- package/dist/cjs/tools/agent_tool.js +0 -134
- package/dist/cjs/tools/base_tool.js +0 -107
- package/dist/cjs/tools/base_toolset.js +0 -76
- package/dist/cjs/tools/forwarding_artifact_service.js +0 -71
- package/dist/cjs/tools/function_tool.js +0 -101
- package/dist/cjs/tools/google_search_tool.js +0 -76
- package/dist/cjs/tools/long_running_tool.js +0 -63
- package/dist/cjs/tools/mcp/mcp_session_manager.js +0 -65
- package/dist/cjs/tools/mcp/mcp_tool.js +0 -65
- package/dist/cjs/tools/mcp/mcp_toolset.js +0 -61
- package/dist/cjs/tools/tool_confirmation.js +0 -49
- package/dist/cjs/tools/tool_context.js +0 -129
- package/dist/cjs/utils/client_labels.js +0 -56
- package/dist/cjs/utils/deep_clone.js +0 -44
- package/dist/cjs/utils/env_aware_utils.js +0 -83
- package/dist/cjs/utils/gemini_schema_util.js +0 -88
- package/dist/cjs/utils/logger.js +0 -121
- package/dist/cjs/utils/model_name.js +0 -76
- package/dist/cjs/utils/simple_zod_to_json.js +0 -191
- package/dist/cjs/utils/variant_utils.js +0 -55
- package/dist/cjs/version.js +0 -39
- package/dist/esm/agents/active_streaming_tool.js +0 -14
- package/dist/esm/agents/base_agent.js +0 -214
- package/dist/esm/agents/base_llm_processor.js +0 -13
- package/dist/esm/agents/callback_context.js +0 -68
- package/dist/esm/agents/content_processor_utils.js +0 -315
- package/dist/esm/agents/functions.js +0 -344
- package/dist/esm/agents/instructions.js +0 -80
- package/dist/esm/agents/invocation_context.js +0 -76
- package/dist/esm/agents/live_request_queue.js +0 -106
- package/dist/esm/agents/llm_agent.js +0 -1180
- package/dist/esm/agents/loop_agent.js +0 -38
- package/dist/esm/agents/parallel_agent.js +0 -48
- package/dist/esm/agents/readonly_context.js +0 -38
- package/dist/esm/agents/run_config.js +0 -39
- package/dist/esm/agents/sequential_agent.js +0 -54
- package/dist/esm/agents/transcription_entry.js +0 -5
- package/dist/esm/artifacts/base_artifact_service.js +0 -5
- package/dist/esm/artifacts/gcs_artifact_service.js +0 -110
- package/dist/esm/artifacts/in_memory_artifact_service.js +0 -89
- package/dist/esm/auth/auth_credential.js +0 -16
- package/dist/esm/auth/auth_handler.js +0 -62
- package/dist/esm/auth/auth_schemes.js +0 -31
- package/dist/esm/auth/auth_tool.js +0 -5
- package/dist/esm/auth/credential_service/base_credential_service.js +0 -5
- package/dist/esm/auth/credential_service/in_memory_credential_service.js +0 -33
- package/dist/esm/auth/exchanger/base_credential_exchanger.js +0 -10
- package/dist/esm/auth/exchanger/credential_exchanger_registry.js +0 -29
- package/dist/esm/code_executors/base_code_executor.js +0 -46
- package/dist/esm/code_executors/built_in_code_executor.js +0 -28
- package/dist/esm/code_executors/code_execution_utils.js +0 -108
- package/dist/esm/code_executors/code_executor_context.js +0 -168
- package/dist/esm/common.js +0 -98
- package/dist/esm/events/event.js +0 -83
- package/dist/esm/events/event_actions.js +0 -52
- package/dist/esm/examples/base_example_provider.js +0 -10
- package/dist/esm/examples/example.js +0 -5
- package/dist/esm/examples/example_util.js +0 -76
- package/dist/esm/index_web.js +0 -6
- package/dist/esm/memory/base_memory_service.js +0 -5
- package/dist/esm/memory/in_memory_memory_service.js +0 -67
- package/dist/esm/memory/memory_entry.js +0 -5
- package/dist/esm/models/base_llm.js +0 -64
- package/dist/esm/models/base_llm_connection.js +0 -5
- package/dist/esm/models/gemini_llm_connection.js +0 -102
- package/dist/esm/models/google_llm.js +0 -533
- package/dist/esm/models/llm_request.js +0 -50
- package/dist/esm/models/llm_response.js +0 -41
- package/dist/esm/models/registry.js +0 -91
- package/dist/esm/plugins/base_plugin.js +0 -206
- package/dist/esm/plugins/logging_plugin.js +0 -192
- package/dist/esm/plugins/plugin_manager.js +0 -209
- package/dist/esm/plugins/security_plugin.js +0 -119
- package/dist/esm/runner/in_memory_runner.js +0 -28
- package/dist/esm/runner/runner.js +0 -247
- package/dist/esm/sessions/base_session_service.js +0 -41
- package/dist/esm/sessions/in_memory_session_service.js +0 -154
- package/dist/esm/sessions/session.js +0 -18
- package/dist/esm/sessions/state.js +0 -71
- package/dist/esm/telemetry/google_cloud.js +0 -54
- package/dist/esm/telemetry/setup.js +0 -67
- package/dist/esm/telemetry/tracing.js +0 -195
- package/dist/esm/tools/agent_tool.js +0 -104
- package/dist/esm/tools/base_tool.js +0 -77
- package/dist/esm/tools/base_toolset.js +0 -46
- package/dist/esm/tools/forwarding_artifact_service.js +0 -41
- package/dist/esm/tools/function_tool.js +0 -71
- package/dist/esm/tools/google_search_tool.js +0 -46
- package/dist/esm/tools/long_running_tool.js +0 -33
- package/dist/esm/tools/mcp/mcp_session_manager.js +0 -35
- package/dist/esm/tools/mcp/mcp_tool.js +0 -35
- package/dist/esm/tools/mcp/mcp_toolset.js +0 -31
- package/dist/esm/tools/tool_confirmation.js +0 -19
- package/dist/esm/tools/tool_context.js +0 -99
- package/dist/esm/utils/client_labels.js +0 -26
- package/dist/esm/utils/deep_clone.js +0 -14
- package/dist/esm/utils/env_aware_utils.js +0 -49
- package/dist/esm/utils/gemini_schema_util.js +0 -58
- package/dist/esm/utils/logger.js +0 -89
- package/dist/esm/utils/model_name.js +0 -41
- package/dist/esm/utils/simple_zod_to_json.js +0 -160
- package/dist/esm/utils/variant_utils.js +0 -24
- package/dist/esm/version.js +0 -9
- package/dist/web/agents/active_streaming_tool.js +0 -14
- package/dist/web/agents/base_agent.js +0 -265
- package/dist/web/agents/base_llm_processor.js +0 -13
- package/dist/web/agents/callback_context.js +0 -68
- package/dist/web/agents/content_processor_utils.js +0 -315
- package/dist/web/agents/functions.js +0 -344
- package/dist/web/agents/instructions.js +0 -80
- package/dist/web/agents/invocation_context.js +0 -76
- package/dist/web/agents/live_request_queue.js +0 -124
- package/dist/web/agents/llm_agent.js +0 -1310
- package/dist/web/agents/loop_agent.js +0 -71
- package/dist/web/agents/parallel_agent.js +0 -83
- package/dist/web/agents/readonly_context.js +0 -38
- package/dist/web/agents/run_config.js +0 -54
- package/dist/web/agents/sequential_agent.js +0 -99
- package/dist/web/agents/transcription_entry.js +0 -5
- package/dist/web/artifacts/base_artifact_service.js +0 -5
- package/dist/web/artifacts/gcs_artifact_service.js +0 -126
- package/dist/web/artifacts/in_memory_artifact_service.js +0 -89
- package/dist/web/auth/auth_credential.js +0 -16
- package/dist/web/auth/auth_handler.js +0 -62
- package/dist/web/auth/auth_schemes.js +0 -31
- package/dist/web/auth/auth_tool.js +0 -5
- package/dist/web/auth/credential_service/base_credential_service.js +0 -5
- package/dist/web/auth/credential_service/in_memory_credential_service.js +0 -33
- package/dist/web/auth/exchanger/base_credential_exchanger.js +0 -10
- package/dist/web/auth/exchanger/credential_exchanger_registry.js +0 -29
- package/dist/web/code_executors/base_code_executor.js +0 -46
- package/dist/web/code_executors/built_in_code_executor.js +0 -28
- package/dist/web/code_executors/code_execution_utils.js +0 -105
- package/dist/web/code_executors/code_executor_context.js +0 -168
- package/dist/web/common.js +0 -98
- package/dist/web/events/event.js +0 -101
- package/dist/web/events/event_actions.js +0 -67
- package/dist/web/examples/base_example_provider.js +0 -10
- package/dist/web/examples/example.js +0 -5
- package/dist/web/examples/example_util.js +0 -75
- package/dist/web/index_web.js +0 -6
- package/dist/web/memory/base_memory_service.js +0 -5
- package/dist/web/memory/in_memory_memory_service.js +0 -67
- package/dist/web/memory/memory_entry.js +0 -5
- package/dist/web/models/base_llm.js +0 -64
- package/dist/web/models/base_llm_connection.js +0 -5
- package/dist/web/models/gemini_llm_connection.js +0 -120
- package/dist/web/models/google_llm.js +0 -574
- package/dist/web/models/llm_request.js +0 -50
- package/dist/web/models/llm_response.js +0 -41
- package/dist/web/models/registry.js +0 -91
- package/dist/web/plugins/base_plugin.js +0 -206
- package/dist/web/plugins/logging_plugin.js +0 -192
- package/dist/web/plugins/plugin_manager.js +0 -209
- package/dist/web/plugins/security_plugin.js +0 -119
- package/dist/web/runner/in_memory_runner.js +0 -28
- package/dist/web/runner/runner.js +0 -278
- package/dist/web/sessions/base_session_service.js +0 -41
- package/dist/web/sessions/in_memory_session_service.js +0 -154
- package/dist/web/sessions/session.js +0 -18
- package/dist/web/sessions/state.js +0 -87
- package/dist/web/telemetry/google_cloud.js +0 -54
- package/dist/web/telemetry/setup.js +0 -67
- package/dist/web/telemetry/tracing.js +0 -210
- package/dist/web/tools/agent_tool.js +0 -118
- package/dist/web/tools/base_tool.js +0 -77
- package/dist/web/tools/base_toolset.js +0 -46
- package/dist/web/tools/forwarding_artifact_service.js +0 -41
- package/dist/web/tools/function_tool.js +0 -71
- package/dist/web/tools/google_search_tool.js +0 -46
- package/dist/web/tools/long_running_tool.js +0 -50
- package/dist/web/tools/mcp/mcp_session_manager.js +0 -35
- package/dist/web/tools/mcp/mcp_tool.js +0 -35
- package/dist/web/tools/mcp/mcp_toolset.js +0 -31
- package/dist/web/tools/tool_confirmation.js +0 -19
- package/dist/web/tools/tool_context.js +0 -99
- package/dist/web/utils/client_labels.js +0 -26
- package/dist/web/utils/deep_clone.js +0 -14
- package/dist/web/utils/env_aware_utils.js +0 -49
- package/dist/web/utils/gemini_schema_util.js +0 -58
- package/dist/web/utils/logger.js +0 -89
- package/dist/web/utils/model_name.js +0 -41
- package/dist/web/utils/simple_zod_to_json.js +0 -174
- package/dist/web/utils/variant_utils.js +0 -24
- package/dist/web/version.js +0 -9
|
@@ -1,574 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __spreadValues = (a, b) => {
|
|
8
|
-
for (var prop in b || (b = {}))
|
|
9
|
-
if (__hasOwnProp.call(b, prop))
|
|
10
|
-
__defNormalProp(a, prop, b[prop]);
|
|
11
|
-
if (__getOwnPropSymbols)
|
|
12
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
13
|
-
if (__propIsEnum.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
}
|
|
16
|
-
return a;
|
|
17
|
-
};
|
|
18
|
-
var __await = function(promise, isYieldStar) {
|
|
19
|
-
this[0] = promise;
|
|
20
|
-
this[1] = isYieldStar;
|
|
21
|
-
};
|
|
22
|
-
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
23
|
-
var resume = (k, v, yes, no) => {
|
|
24
|
-
try {
|
|
25
|
-
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
26
|
-
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));
|
|
27
|
-
} catch (e) {
|
|
28
|
-
no(e);
|
|
29
|
-
}
|
|
30
|
-
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
31
|
-
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
32
|
-
};
|
|
33
|
-
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);
|
|
34
|
-
/**
|
|
35
|
-
* @license
|
|
36
|
-
* Copyright 2025 Google LLC
|
|
37
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
38
|
-
*/
|
|
39
|
-
import {
|
|
40
|
-
createPartFromText,
|
|
41
|
-
FinishReason,
|
|
42
|
-
GoogleGenAI
|
|
43
|
-
} from "@google/genai";
|
|
44
|
-
import { logger } from "../utils/logger.js";
|
|
45
|
-
import { isGemini3PreviewModel } from "../utils/model_name.js";
|
|
46
|
-
import { GoogleLLMVariant } from "../utils/variant_utils.js";
|
|
47
|
-
import { BaseLlm } from "./base_llm.js";
|
|
48
|
-
import { GeminiLlmConnection } from "./gemini_llm_connection.js";
|
|
49
|
-
import { createLlmResponse } from "./llm_response.js";
|
|
50
|
-
const AGENT_ENGINE_TELEMETRY_TAG = "remote_reasoning_engine";
|
|
51
|
-
const AGENT_ENGINE_TELEMETRY_ENV_VARIABLE_NAME = "GOOGLE_CLOUD_AGENT_ENGINE_ID";
|
|
52
|
-
const GEMINI3_PREVIEW_API_ENDPOINT = "https://aiplatform.googleapis.com/v1/publishers/google";
|
|
53
|
-
class Gemini extends BaseLlm {
|
|
54
|
-
/**
|
|
55
|
-
* @param params The parameters for creating a Gemini instance.
|
|
56
|
-
*/
|
|
57
|
-
constructor({
|
|
58
|
-
model,
|
|
59
|
-
apiKey,
|
|
60
|
-
vertexai,
|
|
61
|
-
project,
|
|
62
|
-
location,
|
|
63
|
-
headers,
|
|
64
|
-
apiEndpoint
|
|
65
|
-
}) {
|
|
66
|
-
if (!model) {
|
|
67
|
-
model = "gemini-2.5-flash";
|
|
68
|
-
}
|
|
69
|
-
super({ model });
|
|
70
|
-
this.project = project;
|
|
71
|
-
this.location = location;
|
|
72
|
-
this.apiKey = apiKey;
|
|
73
|
-
this.headers = headers;
|
|
74
|
-
this.isGemini3Preview = isGemini3PreviewModel(model);
|
|
75
|
-
const canReadEnv = typeof process === "object";
|
|
76
|
-
this.apiEndpoint = apiEndpoint;
|
|
77
|
-
if (!this.apiEndpoint && canReadEnv) {
|
|
78
|
-
this.apiEndpoint = process.env["GEMINI_API_ENDPOINT"];
|
|
79
|
-
}
|
|
80
|
-
if (!this.apiEndpoint && this.isGemini3Preview) {
|
|
81
|
-
this.apiEndpoint = GEMINI3_PREVIEW_API_ENDPOINT;
|
|
82
|
-
logger.info("Using Gemini 3 preview endpoint: ".concat(this.apiEndpoint));
|
|
83
|
-
}
|
|
84
|
-
let useVertexAI = !!vertexai;
|
|
85
|
-
if (!useVertexAI && canReadEnv) {
|
|
86
|
-
const vertexAIfromEnv = process.env["GOOGLE_GENAI_USE_VERTEXAI"];
|
|
87
|
-
if (vertexAIfromEnv) {
|
|
88
|
-
useVertexAI = vertexAIfromEnv.toLowerCase() === "true" || vertexAIfromEnv === "1";
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (this.isGemini3Preview && useVertexAI) {
|
|
92
|
-
const availableApiKey = apiKey || (canReadEnv ? process.env["GOOGLE_GENAI_API_KEY"] || process.env["GEMINI_API_KEY"] : void 0);
|
|
93
|
-
if (availableApiKey) {
|
|
94
|
-
logger.info(
|
|
95
|
-
"Gemini 3 preview detected with Vertex AI mode. Switching to API key mode for correct endpoint handling."
|
|
96
|
-
);
|
|
97
|
-
useVertexAI = false;
|
|
98
|
-
this.apiKey = availableApiKey;
|
|
99
|
-
} else {
|
|
100
|
-
logger.warn(
|
|
101
|
-
"Gemini 3 preview requires API key authentication for correct endpoint handling. Set GEMINI_API_KEY or GOOGLE_GENAI_API_KEY environment variable for best compatibility."
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
this.vertexai = useVertexAI;
|
|
106
|
-
if (this.vertexai) {
|
|
107
|
-
if (canReadEnv && !this.project) {
|
|
108
|
-
this.project = process.env["GOOGLE_CLOUD_PROJECT"];
|
|
109
|
-
}
|
|
110
|
-
if (canReadEnv && !this.location) {
|
|
111
|
-
this.location = process.env["GOOGLE_CLOUD_LOCATION"];
|
|
112
|
-
}
|
|
113
|
-
if (!this.project) {
|
|
114
|
-
throw new Error(
|
|
115
|
-
"VertexAI project must be provided via constructor or GOOGLE_CLOUD_PROJECT environment variable."
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
if (!this.location) {
|
|
119
|
-
throw new Error(
|
|
120
|
-
"VertexAI location must be provided via constructor or GOOGLE_CLOUD_LOCATION environment variable."
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
} else {
|
|
124
|
-
if (!this.apiKey && canReadEnv) {
|
|
125
|
-
this.apiKey = process.env["GOOGLE_GENAI_API_KEY"] || process.env["GEMINI_API_KEY"];
|
|
126
|
-
}
|
|
127
|
-
if (!this.apiKey) {
|
|
128
|
-
throw new Error(
|
|
129
|
-
"API key must be provided via constructor or GOOGLE_GENAI_API_KEY or GEMINI_API_KEY environment variable."
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Sends a request to the Gemini model.
|
|
136
|
-
*
|
|
137
|
-
* @param llmRequest LlmRequest, the request to send to the Gemini model.
|
|
138
|
-
* @param stream bool = false, whether to do streaming call.
|
|
139
|
-
* @yields LlmResponse: The model response.
|
|
140
|
-
*/
|
|
141
|
-
generateContentAsync(llmRequest, stream = false) {
|
|
142
|
-
return __asyncGenerator(this, null, function* () {
|
|
143
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
144
|
-
this.preprocessRequest(llmRequest);
|
|
145
|
-
this.maybeAppendUserContent(llmRequest);
|
|
146
|
-
logger.info(
|
|
147
|
-
"Sending out request, model: ".concat(llmRequest.model, ", backend: ").concat(this.apiBackend, ", stream: ").concat(stream)
|
|
148
|
-
);
|
|
149
|
-
if ((_a = llmRequest.config) == null ? void 0 : _a.httpOptions) {
|
|
150
|
-
llmRequest.config.httpOptions.headers = __spreadValues(__spreadValues({}, llmRequest.config.httpOptions.headers), this.trackingHeaders);
|
|
151
|
-
}
|
|
152
|
-
if (stream) {
|
|
153
|
-
const streamResult = yield new __await(this.apiClient.models.generateContentStream({
|
|
154
|
-
model: (_b = llmRequest.model) != null ? _b : this.model,
|
|
155
|
-
contents: llmRequest.contents,
|
|
156
|
-
config: llmRequest.config
|
|
157
|
-
}));
|
|
158
|
-
let thoughtText = "";
|
|
159
|
-
let thoughtSignature;
|
|
160
|
-
let text = "";
|
|
161
|
-
let usageMetadata;
|
|
162
|
-
let lastResponse;
|
|
163
|
-
if (this.isGemini3Preview && this.cachedThoughtSignature) {
|
|
164
|
-
logger.info(
|
|
165
|
-
"[Gemini3] Starting new request with CACHED thoughtSignature (length: ".concat(this.cachedThoughtSignature.length, ")")
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
try {
|
|
169
|
-
for (var iter = __forAwait(streamResult), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
170
|
-
const response = temp.value;
|
|
171
|
-
lastResponse = response;
|
|
172
|
-
const llmResponse = createLlmResponse(response);
|
|
173
|
-
usageMetadata = llmResponse.usageMetadata;
|
|
174
|
-
const firstPart = (_d = (_c = llmResponse.content) == null ? void 0 : _c.parts) == null ? void 0 : _d[0];
|
|
175
|
-
const hasFunctionCalls = (_f = (_e = llmResponse.content) == null ? void 0 : _e.parts) == null ? void 0 : _f.some(
|
|
176
|
-
(part) => part.functionCall
|
|
177
|
-
);
|
|
178
|
-
if (this.isGemini3Preview && ((_g = llmResponse.content) == null ? void 0 : _g.parts)) {
|
|
179
|
-
for (const part of llmResponse.content.parts) {
|
|
180
|
-
if (part.thoughtSignature && !thoughtSignature) {
|
|
181
|
-
thoughtSignature = part.thoughtSignature;
|
|
182
|
-
this.cachedThoughtSignature = thoughtSignature;
|
|
183
|
-
logger.info(
|
|
184
|
-
"[Gemini3] Captured and CACHED thoughtSignature from response part (length: ".concat(thoughtSignature.length, ")")
|
|
185
|
-
);
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (firstPart == null ? void 0 : firstPart.text) {
|
|
191
|
-
if ("thought" in firstPart && firstPart.thought) {
|
|
192
|
-
thoughtText += firstPart.text;
|
|
193
|
-
if ("thoughtSignature" in firstPart && firstPart.thoughtSignature) {
|
|
194
|
-
thoughtSignature = firstPart.thoughtSignature;
|
|
195
|
-
this.cachedThoughtSignature = thoughtSignature;
|
|
196
|
-
logger.info(
|
|
197
|
-
"[Gemini3] Captured and CACHED thoughtSignature from thought part (length: ".concat(thoughtSignature.length, ")")
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
} else {
|
|
201
|
-
text += firstPart.text;
|
|
202
|
-
}
|
|
203
|
-
llmResponse.partial = true;
|
|
204
|
-
if (this.isGemini3Preview && hasFunctionCalls) {
|
|
205
|
-
const responseHasSignature = (_i = (_h = llmResponse.content) == null ? void 0 : _h.parts) == null ? void 0 : _i.some(
|
|
206
|
-
(p) => p.thoughtSignature
|
|
207
|
-
);
|
|
208
|
-
logger.info(
|
|
209
|
-
"[Gemini3] Chunk has thought AND function calls. Response has signature: ".concat(responseHasSignature)
|
|
210
|
-
);
|
|
211
|
-
thoughtText = "";
|
|
212
|
-
thoughtSignature = void 0;
|
|
213
|
-
text = "";
|
|
214
|
-
}
|
|
215
|
-
} else if ((thoughtText || text) && (!firstPart || !firstPart.inlineData)) {
|
|
216
|
-
if (this.isGemini3Preview && hasFunctionCalls && llmResponse.content) {
|
|
217
|
-
logger.info(
|
|
218
|
-
"[Gemini3] Merging thought with function calls. Has accumulated signature: ".concat(!!thoughtSignature)
|
|
219
|
-
);
|
|
220
|
-
const prependParts = [];
|
|
221
|
-
if (thoughtText) {
|
|
222
|
-
const thoughtPart = { text: thoughtText, thought: true };
|
|
223
|
-
if (thoughtSignature) {
|
|
224
|
-
thoughtPart.thoughtSignature = thoughtSignature;
|
|
225
|
-
}
|
|
226
|
-
prependParts.push(thoughtPart);
|
|
227
|
-
logger.info(
|
|
228
|
-
"[Gemini3] Created thought part with signature: ".concat(!!thoughtSignature)
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
if (text) {
|
|
232
|
-
prependParts.push(createPartFromText(text));
|
|
233
|
-
}
|
|
234
|
-
if (!thoughtText && thoughtSignature) {
|
|
235
|
-
let signatureApplied = false;
|
|
236
|
-
for (const part of llmResponse.content.parts || []) {
|
|
237
|
-
if (part.functionCall && !signatureApplied) {
|
|
238
|
-
if (!part.thoughtSignature) {
|
|
239
|
-
part.thoughtSignature = thoughtSignature;
|
|
240
|
-
logger.info(
|
|
241
|
-
"[Gemini3] Applied accumulated signature to first function call: ".concat(part.functionCall.name)
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
signatureApplied = true;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
llmResponse.content.parts = [
|
|
249
|
-
...prependParts,
|
|
250
|
-
...llmResponse.content.parts || []
|
|
251
|
-
];
|
|
252
|
-
logger.info(
|
|
253
|
-
"[Gemini3] Final merged content has ".concat(llmResponse.content.parts.length, " parts")
|
|
254
|
-
);
|
|
255
|
-
for (let i = 0; i < llmResponse.content.parts.length; i++) {
|
|
256
|
-
const p = llmResponse.content.parts[i];
|
|
257
|
-
logger.info(
|
|
258
|
-
"[Gemini3] Part ".concat(i, ": thought=").concat(!!p.thought, ", functionCall=").concat(((_j = p.functionCall) == null ? void 0 : _j.name) || "none", ", hasSignature=").concat(!!p.thoughtSignature)
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
thoughtText = "";
|
|
262
|
-
thoughtSignature = void 0;
|
|
263
|
-
text = "";
|
|
264
|
-
} else {
|
|
265
|
-
const parts = [];
|
|
266
|
-
if (thoughtText) {
|
|
267
|
-
const thoughtPart = { text: thoughtText, thought: true };
|
|
268
|
-
if (thoughtSignature) {
|
|
269
|
-
thoughtPart.thoughtSignature = thoughtSignature;
|
|
270
|
-
}
|
|
271
|
-
parts.push(thoughtPart);
|
|
272
|
-
}
|
|
273
|
-
if (text) {
|
|
274
|
-
parts.push(createPartFromText(text));
|
|
275
|
-
}
|
|
276
|
-
yield {
|
|
277
|
-
content: {
|
|
278
|
-
role: "model",
|
|
279
|
-
parts
|
|
280
|
-
},
|
|
281
|
-
usageMetadata: llmResponse.usageMetadata
|
|
282
|
-
};
|
|
283
|
-
thoughtText = "";
|
|
284
|
-
thoughtSignature = void 0;
|
|
285
|
-
text = "";
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
if (this.isGemini3Preview && hasFunctionCalls && ((_k = llmResponse.content) == null ? void 0 : _k.parts)) {
|
|
289
|
-
const hasExistingSignature = llmResponse.content.parts.some(
|
|
290
|
-
(p) => p.thoughtSignature
|
|
291
|
-
);
|
|
292
|
-
if (!hasExistingSignature && thoughtSignature) {
|
|
293
|
-
for (const part of llmResponse.content.parts) {
|
|
294
|
-
if (part.functionCall) {
|
|
295
|
-
part.thoughtSignature = thoughtSignature;
|
|
296
|
-
logger.info(
|
|
297
|
-
"[Gemini3] Applied cached signature to first function call: ".concat(part.functionCall.name)
|
|
298
|
-
);
|
|
299
|
-
break;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
const functionCallNames = llmResponse.content.parts.filter((p) => p.functionCall).map((p) => p.functionCall.name);
|
|
304
|
-
let partsWithSig = llmResponse.content.parts.filter(
|
|
305
|
-
(p) => p.thoughtSignature
|
|
306
|
-
).length;
|
|
307
|
-
if (partsWithSig === 0) {
|
|
308
|
-
const signatureToUse = thoughtSignature || this.cachedThoughtSignature;
|
|
309
|
-
if (signatureToUse) {
|
|
310
|
-
for (const part of llmResponse.content.parts) {
|
|
311
|
-
if (part.functionCall && !part.thoughtSignature) {
|
|
312
|
-
part.thoughtSignature = signatureToUse;
|
|
313
|
-
logger.info(
|
|
314
|
-
"[Gemini3] Applied CACHED signature to function call: ".concat(part.functionCall.name, " (API didn't return new signature, using ").concat(thoughtSignature ? "local" : "class-level", " cache)")
|
|
315
|
-
);
|
|
316
|
-
partsWithSig = 1;
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
logger.info(
|
|
323
|
-
"[Gemini3] Yielding function call response: calls=[".concat(functionCallNames.join(", "), "], partsWithSignature=").concat(partsWithSig)
|
|
324
|
-
);
|
|
325
|
-
if (partsWithSig === 0) {
|
|
326
|
-
logger.warn(
|
|
327
|
-
"[Gemini3] WARNING: No thoughtSignature found and no cached signature available! This may cause 400 errors on next request."
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
yield llmResponse;
|
|
332
|
-
}
|
|
333
|
-
} catch (temp) {
|
|
334
|
-
error = [temp];
|
|
335
|
-
} finally {
|
|
336
|
-
try {
|
|
337
|
-
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
338
|
-
} finally {
|
|
339
|
-
if (error)
|
|
340
|
-
throw error[0];
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
if ((text || thoughtText) && ((_m = (_l = lastResponse == null ? void 0 : lastResponse.candidates) == null ? void 0 : _l[0]) == null ? void 0 : _m.finishReason) === FinishReason.STOP) {
|
|
344
|
-
const parts = [];
|
|
345
|
-
if (thoughtText) {
|
|
346
|
-
const thoughtPart = { text: thoughtText, thought: true };
|
|
347
|
-
if (thoughtSignature) {
|
|
348
|
-
thoughtPart.thoughtSignature = thoughtSignature;
|
|
349
|
-
}
|
|
350
|
-
parts.push(thoughtPart);
|
|
351
|
-
}
|
|
352
|
-
if (text) {
|
|
353
|
-
parts.push({ text });
|
|
354
|
-
}
|
|
355
|
-
yield {
|
|
356
|
-
content: {
|
|
357
|
-
role: "model",
|
|
358
|
-
parts
|
|
359
|
-
},
|
|
360
|
-
usageMetadata
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
} else {
|
|
364
|
-
const response = yield new __await(this.apiClient.models.generateContent({
|
|
365
|
-
model: (_n = llmRequest.model) != null ? _n : this.model,
|
|
366
|
-
contents: llmRequest.contents,
|
|
367
|
-
config: llmRequest.config
|
|
368
|
-
}));
|
|
369
|
-
const llmResponse = createLlmResponse(response);
|
|
370
|
-
if (this.isGemini3Preview && ((_o = llmResponse.content) == null ? void 0 : _o.parts)) {
|
|
371
|
-
let thoughtSig;
|
|
372
|
-
let hasThoughtPartWithSignature = false;
|
|
373
|
-
for (const part of llmResponse.content.parts) {
|
|
374
|
-
if (part.thoughtSignature) {
|
|
375
|
-
thoughtSig = part.thoughtSignature;
|
|
376
|
-
this.cachedThoughtSignature = thoughtSig;
|
|
377
|
-
if (part.thought) {
|
|
378
|
-
hasThoughtPartWithSignature = true;
|
|
379
|
-
}
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
logger.info(
|
|
384
|
-
"[Gemini3] Non-streaming response: hasSignature=".concat(!!thoughtSig, ", hasThoughtPart=").concat(hasThoughtPartWithSignature, ", hasCachedSig=").concat(!!this.cachedThoughtSignature)
|
|
385
|
-
);
|
|
386
|
-
if (thoughtSig && !hasThoughtPartWithSignature) {
|
|
387
|
-
let signatureApplied = false;
|
|
388
|
-
for (const part of llmResponse.content.parts) {
|
|
389
|
-
if (part.functionCall) {
|
|
390
|
-
if (!signatureApplied && !part.thoughtSignature) {
|
|
391
|
-
part.thoughtSignature = thoughtSig;
|
|
392
|
-
logger.info(
|
|
393
|
-
"[Gemini3] Applied signature to first function call: ".concat(part.functionCall.name)
|
|
394
|
-
);
|
|
395
|
-
}
|
|
396
|
-
signatureApplied = true;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
const hasFunctionCalls = llmResponse.content.parts.some(
|
|
401
|
-
(p) => p.functionCall
|
|
402
|
-
);
|
|
403
|
-
if (hasFunctionCalls) {
|
|
404
|
-
let partsWithSig = llmResponse.content.parts.filter(
|
|
405
|
-
(p) => p.thoughtSignature
|
|
406
|
-
).length;
|
|
407
|
-
if (partsWithSig === 0 && this.cachedThoughtSignature) {
|
|
408
|
-
for (const part of llmResponse.content.parts) {
|
|
409
|
-
if (part.functionCall && !part.thoughtSignature) {
|
|
410
|
-
part.thoughtSignature = this.cachedThoughtSignature;
|
|
411
|
-
logger.info(
|
|
412
|
-
"[Gemini3] Applied CACHED signature to function call: ".concat(part.functionCall.name, " (API didn't return new signature)")
|
|
413
|
-
);
|
|
414
|
-
partsWithSig = 1;
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
for (let i = 0; i < llmResponse.content.parts.length; i++) {
|
|
420
|
-
const p = llmResponse.content.parts[i];
|
|
421
|
-
logger.info(
|
|
422
|
-
"[Gemini3] Response Part ".concat(i, ": thought=").concat(!!p.thought, ", functionCall=").concat(((_p = p.functionCall) == null ? void 0 : _p.name) || "none", ", hasSignature=").concat(!!p.thoughtSignature)
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
if (partsWithSig === 0) {
|
|
426
|
-
logger.warn(
|
|
427
|
-
"[Gemini3] WARNING: No thoughtSignature found and no cached signature available! This may cause 400 errors on next request."
|
|
428
|
-
);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
yield llmResponse;
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
get apiClient() {
|
|
437
|
-
if (this._apiClient) {
|
|
438
|
-
return this._apiClient;
|
|
439
|
-
}
|
|
440
|
-
const combinedHeaders = __spreadValues(__spreadValues({}, this.trackingHeaders), this.headers);
|
|
441
|
-
if (this.vertexai) {
|
|
442
|
-
this._apiClient = new GoogleGenAI({
|
|
443
|
-
vertexai: this.vertexai,
|
|
444
|
-
project: this.project,
|
|
445
|
-
location: this.location,
|
|
446
|
-
httpOptions: { headers: combinedHeaders }
|
|
447
|
-
});
|
|
448
|
-
} else {
|
|
449
|
-
const httpOptions = { headers: combinedHeaders };
|
|
450
|
-
if (this.apiEndpoint) {
|
|
451
|
-
httpOptions.baseUrl = this.apiEndpoint;
|
|
452
|
-
logger.debug("Using custom API endpoint: ".concat(this.apiEndpoint));
|
|
453
|
-
if (this.isGemini3Preview) {
|
|
454
|
-
httpOptions.apiVersion = "";
|
|
455
|
-
logger.info(
|
|
456
|
-
"Gemini 3 preview mode: using direct API path without version prefix"
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
this._apiClient = new GoogleGenAI({
|
|
461
|
-
apiKey: this.apiKey,
|
|
462
|
-
vertexai: false,
|
|
463
|
-
httpOptions
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
return this._apiClient;
|
|
467
|
-
}
|
|
468
|
-
get apiBackend() {
|
|
469
|
-
if (!this._apiBackend) {
|
|
470
|
-
this._apiBackend = this.apiClient.vertexai ? GoogleLLMVariant.VERTEX_AI : GoogleLLMVariant.GEMINI_API;
|
|
471
|
-
}
|
|
472
|
-
return this._apiBackend;
|
|
473
|
-
}
|
|
474
|
-
get liveApiVersion() {
|
|
475
|
-
if (!this._liveApiVersion) {
|
|
476
|
-
this._liveApiVersion = this.apiBackend === GoogleLLMVariant.VERTEX_AI ? "v1beta1" : "v1alpha";
|
|
477
|
-
}
|
|
478
|
-
return this._liveApiVersion;
|
|
479
|
-
}
|
|
480
|
-
get liveApiClient() {
|
|
481
|
-
if (!this._liveApiClient) {
|
|
482
|
-
const httpOptions = {
|
|
483
|
-
headers: this.trackingHeaders,
|
|
484
|
-
apiVersion: this.liveApiVersion
|
|
485
|
-
};
|
|
486
|
-
if (this.apiEndpoint) {
|
|
487
|
-
httpOptions.baseUrl = this.apiEndpoint;
|
|
488
|
-
if (this.isGemini3Preview) {
|
|
489
|
-
httpOptions.apiVersion = "";
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
this._liveApiClient = new GoogleGenAI({
|
|
493
|
-
apiKey: this.apiKey,
|
|
494
|
-
httpOptions
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
return this._liveApiClient;
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
|
-
* Connects to the Gemini model and returns an llm connection.
|
|
501
|
-
*
|
|
502
|
-
* @param llmRequest LlmRequest, the request to send to the Gemini model.
|
|
503
|
-
* @returns BaseLlmConnection, the connection to the Gemini model.
|
|
504
|
-
*/
|
|
505
|
-
async connect(llmRequest) {
|
|
506
|
-
var _a, _b, _c, _d;
|
|
507
|
-
if ((_a = llmRequest.liveConnectConfig) == null ? void 0 : _a.httpOptions) {
|
|
508
|
-
if (!llmRequest.liveConnectConfig.httpOptions.headers) {
|
|
509
|
-
llmRequest.liveConnectConfig.httpOptions.headers = {};
|
|
510
|
-
}
|
|
511
|
-
Object.assign(
|
|
512
|
-
llmRequest.liveConnectConfig.httpOptions.headers,
|
|
513
|
-
this.trackingHeaders
|
|
514
|
-
);
|
|
515
|
-
llmRequest.liveConnectConfig.httpOptions.apiVersion = this.isGemini3Preview ? "" : this.liveApiVersion;
|
|
516
|
-
}
|
|
517
|
-
if ((_b = llmRequest.config) == null ? void 0 : _b.systemInstruction) {
|
|
518
|
-
llmRequest.liveConnectConfig.systemInstruction = {
|
|
519
|
-
role: "system",
|
|
520
|
-
// TODO - b/425992518: validate type casting works well.
|
|
521
|
-
parts: [
|
|
522
|
-
createPartFromText(llmRequest.config.systemInstruction)
|
|
523
|
-
]
|
|
524
|
-
};
|
|
525
|
-
}
|
|
526
|
-
llmRequest.liveConnectConfig.tools = (_c = llmRequest.config) == null ? void 0 : _c.tools;
|
|
527
|
-
const liveSession = await this.liveApiClient.live.connect({
|
|
528
|
-
model: (_d = llmRequest.model) != null ? _d : this.model,
|
|
529
|
-
config: llmRequest.liveConnectConfig,
|
|
530
|
-
callbacks: {
|
|
531
|
-
// TODO - b/425992518: GenAI SDK inconsistent API, missing methods.
|
|
532
|
-
onmessage: () => {
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
});
|
|
536
|
-
return new GeminiLlmConnection(liveSession);
|
|
537
|
-
}
|
|
538
|
-
preprocessRequest(llmRequest) {
|
|
539
|
-
if (this.apiBackend === GoogleLLMVariant.GEMINI_API) {
|
|
540
|
-
if (llmRequest.config) {
|
|
541
|
-
llmRequest.config.labels = void 0;
|
|
542
|
-
}
|
|
543
|
-
if (llmRequest.contents) {
|
|
544
|
-
for (const content of llmRequest.contents) {
|
|
545
|
-
if (!content.parts) continue;
|
|
546
|
-
for (const part of content.parts) {
|
|
547
|
-
removeDisplayNameIfPresent(part.inlineData);
|
|
548
|
-
removeDisplayNameIfPresent(part.fileData);
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* A list of model name patterns that are supported by this LLM.
|
|
557
|
-
*
|
|
558
|
-
* @returns A list of supported models.
|
|
559
|
-
*/
|
|
560
|
-
Gemini.supportedModels = [
|
|
561
|
-
/gemini-.*/,
|
|
562
|
-
// fine-tuned vertex endpoint pattern
|
|
563
|
-
/projects\/.+\/locations\/.+\/endpoints\/.+/,
|
|
564
|
-
// vertex gemini long name
|
|
565
|
-
/projects\/.+\/locations\/.+\/publishers\/google\/models\/gemini.+/
|
|
566
|
-
];
|
|
567
|
-
function removeDisplayNameIfPresent(dataObj) {
|
|
568
|
-
if (dataObj && dataObj.displayName) {
|
|
569
|
-
dataObj.displayName = void 0;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
export {
|
|
573
|
-
Gemini
|
|
574
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2025 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
function appendInstructions(llmRequest, instructions) {
|
|
7
|
-
if (!llmRequest.config) {
|
|
8
|
-
llmRequest.config = {};
|
|
9
|
-
}
|
|
10
|
-
const newInstructions = instructions.join("\n\n");
|
|
11
|
-
if (llmRequest.config.systemInstruction) {
|
|
12
|
-
llmRequest.config.systemInstruction += "\n\n" + newInstructions;
|
|
13
|
-
} else {
|
|
14
|
-
llmRequest.config.systemInstruction = newInstructions;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function appendTools(llmRequest, tools) {
|
|
18
|
-
if (!(tools == null ? void 0 : tools.length)) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const functionDeclarations = [];
|
|
22
|
-
for (const tool of tools) {
|
|
23
|
-
const declaration = tool._getDeclaration();
|
|
24
|
-
if (declaration) {
|
|
25
|
-
functionDeclarations.push(declaration);
|
|
26
|
-
llmRequest.toolsDict[tool.name] = tool;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (functionDeclarations.length) {
|
|
30
|
-
if (!llmRequest.config) {
|
|
31
|
-
llmRequest.config = {};
|
|
32
|
-
}
|
|
33
|
-
if (!llmRequest.config.tools) {
|
|
34
|
-
llmRequest.config.tools = [];
|
|
35
|
-
}
|
|
36
|
-
llmRequest.config.tools.push({ functionDeclarations });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function setOutputSchema(llmRequest, schema) {
|
|
40
|
-
if (!llmRequest.config) {
|
|
41
|
-
llmRequest.config = {};
|
|
42
|
-
}
|
|
43
|
-
llmRequest.config.responseSchema = schema;
|
|
44
|
-
llmRequest.config.responseMimeType = "application/json";
|
|
45
|
-
}
|
|
46
|
-
export {
|
|
47
|
-
appendInstructions,
|
|
48
|
-
appendTools,
|
|
49
|
-
setOutputSchema
|
|
50
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2025 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
function createLlmResponse(response) {
|
|
7
|
-
var _a;
|
|
8
|
-
const usageMetadata = response.usageMetadata;
|
|
9
|
-
if (response.candidates && response.candidates.length > 0) {
|
|
10
|
-
const candidate = response.candidates[0];
|
|
11
|
-
if (((_a = candidate.content) == null ? void 0 : _a.parts) && candidate.content.parts.length > 0) {
|
|
12
|
-
return {
|
|
13
|
-
content: candidate.content,
|
|
14
|
-
groundingMetadata: candidate.groundingMetadata,
|
|
15
|
-
usageMetadata,
|
|
16
|
-
finishReason: candidate.finishReason
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
errorCode: candidate.finishReason,
|
|
21
|
-
errorMessage: candidate.finishMessage,
|
|
22
|
-
usageMetadata,
|
|
23
|
-
finishReason: candidate.finishReason
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
if (response.promptFeedback) {
|
|
27
|
-
return {
|
|
28
|
-
errorCode: response.promptFeedback.blockReason,
|
|
29
|
-
errorMessage: response.promptFeedback.blockReasonMessage,
|
|
30
|
-
usageMetadata
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
errorCode: "UNKNOWN_ERROR",
|
|
35
|
-
errorMessage: "Unknown error.",
|
|
36
|
-
usageMetadata
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
export {
|
|
40
|
-
createLlmResponse
|
|
41
|
-
};
|