@google/adk 0.2.5 → 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 +46 -24
- package/dist/cjs/agents/base_llm_processor.js +1 -1
- package/dist/cjs/agents/callback_context.js +5 -2
- package/dist/cjs/agents/content_processor_utils.js +16 -8
- package/dist/cjs/agents/functions.js +81 -30
- 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 +106 -62
- package/dist/cjs/agents/loop_agent.js +3 -2
- package/dist/cjs/agents/parallel_agent.js +4 -5
- 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 +145 -58
- package/dist/cjs/artifacts/in_memory_artifact_service.js +72 -10
- package/dist/cjs/artifacts/registry.js +55 -0
- package/dist/cjs/auth/auth_credential.js +1 -1
- package/dist/cjs/auth/auth_handler.js +4 -2
- 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 +4 -2
- package/dist/cjs/code_executors/built_in_code_executor.js +8 -4
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/code_executors/code_executor_context.js +6 -6
- package/dist/cjs/common.js +18 -1
- package/dist/cjs/events/event.js +34 -7
- 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 +4 -2
- 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 +9 -5
- package/dist/cjs/models/base_llm_connection.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +2 -1
- package/dist/cjs/models/google_llm.js +73 -54
- 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 +13 -1
- package/dist/cjs/plugins/logging_plugin.js +51 -14
- package/dist/cjs/plugins/plugin_manager.js +57 -25
- package/dist/cjs/plugins/security_plugin.js +2 -2
- package/dist/cjs/runner/in_memory_runner.js +1 -1
- package/dist/cjs/runner/runner.js +142 -96
- 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 +60 -34
- 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 +8 -10
- package/dist/cjs/telemetry/setup.js +16 -8
- package/dist/cjs/telemetry/tracing.js +38 -16
- package/dist/cjs/tools/agent_tool.js +9 -5
- package/dist/cjs/tools/base_tool.js +5 -3
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/forwarding_artifact_service.js +18 -2
- package/dist/cjs/tools/function_tool.js +2 -3
- package/dist/cjs/tools/google_search_tool.js +2 -3
- package/dist/cjs/tools/long_running_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +17 -11
- package/dist/cjs/tools/mcp/mcp_tool.js +2 -4
- package/dist/cjs/tools/mcp/mcp_toolset.js +2 -2
- 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 +11 -2
- package/dist/cjs/utils/gemini_schema_util.js +10 -5
- package/dist/cjs/utils/logger.js +48 -4
- 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 +101 -142
- 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 +50 -24
- package/dist/esm/agents/callback_context.js +4 -1
- package/dist/esm/agents/content_processor_utils.js +25 -9
- package/dist/esm/agents/functions.js +84 -29
- package/dist/esm/agents/llm_agent.js +110 -62
- package/dist/esm/agents/loop_agent.js +2 -1
- package/dist/esm/agents/parallel_agent.js +3 -4
- 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 +144 -57
- package/dist/esm/artifacts/in_memory_artifact_service.js +69 -8
- package/dist/esm/artifacts/registry.js +28 -0
- package/dist/esm/auth/auth_handler.js +3 -1
- package/dist/esm/code_executors/base_code_executor.js +3 -1
- package/dist/esm/code_executors/built_in_code_executor.js +7 -3
- package/dist/esm/code_executors/code_executor_context.js +5 -5
- package/dist/esm/common.js +12 -2
- package/dist/esm/events/event.js +30 -5
- 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/memory/in_memory_memory_service.js +3 -1
- package/dist/esm/models/apigee_llm.js +152 -0
- package/dist/esm/models/base_llm.js +8 -4
- package/dist/esm/models/gemini_llm_connection.js +1 -0
- package/dist/esm/models/google_llm.js +75 -53
- package/dist/esm/models/registry.js +2 -0
- package/dist/esm/plugins/base_plugin.js +12 -0
- package/dist/esm/plugins/logging_plugin.js +55 -14
- package/dist/esm/plugins/plugin_manager.js +56 -24
- package/dist/esm/plugins/security_plugin.js +1 -1
- package/dist/esm/runner/runner.js +145 -96
- 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 +61 -33
- package/dist/esm/sessions/registry.js +25 -0
- package/dist/esm/telemetry/google_cloud.js +7 -9
- package/dist/esm/telemetry/setup.js +23 -9
- package/dist/esm/telemetry/tracing.js +37 -15
- package/dist/esm/tools/agent_tool.js +8 -4
- package/dist/esm/tools/base_tool.js +4 -2
- package/dist/esm/tools/forwarding_artifact_service.js +17 -1
- package/dist/esm/tools/function_tool.js +1 -2
- package/dist/esm/tools/google_search_tool.js +2 -5
- package/dist/esm/tools/long_running_tool.js +3 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +22 -12
- package/dist/esm/tools/mcp/mcp_tool.js +1 -3
- package/dist/esm/tools/mcp/mcp_toolset.js +1 -1
- package/dist/esm/utils/env_aware_utils.js +9 -1
- package/dist/esm/utils/gemini_schema_util.js +9 -4
- package/dist/esm/utils/logger.js +43 -2
- package/dist/esm/utils/object_notation_utils.js +47 -0
- package/dist/esm/utils/simple_zod_to_json.js +102 -141
- 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/base_agent.d.ts +2 -1
- package/dist/types/agents/callback_context.d.ts +1 -1
- package/dist/types/agents/llm_agent.d.ts +12 -12
- package/dist/types/agents/loop_agent.d.ts +1 -1
- package/dist/types/agents/parallel_agent.d.ts +1 -1
- 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 +8 -5
- package/dist/types/artifacts/registry.d.ts +7 -0
- package/dist/types/code_executors/built_in_code_executor.d.ts +1 -1
- package/dist/types/code_executors/code_executor_context.d.ts +2 -4
- package/dist/types/common.d.ts +13 -3
- 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 +7 -3
- package/dist/types/models/apigee_llm.d.ts +59 -0
- package/dist/types/models/base_llm_connection.d.ts +1 -1
- package/dist/types/models/google_llm.d.ts +5 -2
- package/dist/types/models/llm_response.d.ts +1 -1
- package/dist/types/plugins/logging_plugin.d.ts +12 -12
- package/dist/types/plugins/plugin_manager.d.ts +12 -12
- package/dist/types/plugins/security_plugin.d.ts +1 -1
- package/dist/types/runner/runner.d.ts +16 -1
- 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 +9 -6
- package/dist/types/sessions/registry.d.ts +7 -0
- package/dist/types/telemetry/setup.d.ts +1 -1
- package/dist/types/telemetry/tracing.d.ts +7 -6
- package/dist/types/tools/agent_tool.d.ts +1 -1
- package/dist/types/tools/base_tool.d.ts +1 -1
- package/dist/types/tools/base_toolset.d.ts +2 -1
- package/dist/types/tools/forwarding_artifact_service.d.ts +4 -2
- package/dist/types/tools/function_tool.d.ts +4 -3
- package/dist/types/tools/google_search_tool.d.ts +3 -3
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +10 -3
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -2
- package/dist/types/utils/env_aware_utils.d.ts +7 -0
- package/dist/types/utils/gemini_schema_util.d.ts +4 -12
- package/dist/types/utils/logger.d.ts +11 -10
- package/dist/types/utils/object_notation_utils.d.ts +21 -0
- package/dist/types/utils/simple_zod_to_json.d.ts +5 -4
- 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 +96 -35
- package/dist/web/agents/callback_context.js +4 -1
- package/dist/web/agents/content_processor_utils.js +25 -9
- package/dist/web/agents/functions.js +84 -29
- package/dist/web/agents/llm_agent.js +166 -83
- package/dist/web/agents/loop_agent.js +2 -1
- package/dist/web/agents/parallel_agent.js +3 -4
- 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 +139 -54
- package/dist/web/artifacts/in_memory_artifact_service.js +69 -8
- package/dist/web/artifacts/registry.js +28 -0
- package/dist/web/auth/auth_handler.js +3 -1
- package/dist/web/code_executors/base_code_executor.js +3 -1
- package/dist/web/code_executors/built_in_code_executor.js +7 -3
- package/dist/web/code_executors/code_executor_context.js +5 -5
- package/dist/web/common.js +12 -2
- package/dist/web/events/event.js +30 -5
- 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/memory/in_memory_memory_service.js +3 -1
- package/dist/web/models/apigee_llm.js +219 -0
- package/dist/web/models/base_llm.js +8 -4
- package/dist/web/models/gemini_llm_connection.js +1 -0
- package/dist/web/models/google_llm.js +75 -50
- package/dist/web/models/registry.js +2 -0
- package/dist/web/plugins/base_plugin.js +12 -0
- package/dist/web/plugins/logging_plugin.js +55 -14
- package/dist/web/plugins/plugin_manager.js +56 -24
- package/dist/web/plugins/security_plugin.js +1 -1
- package/dist/web/runner/runner.js +192 -108
- 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 +61 -33
- package/dist/web/sessions/registry.js +25 -0
- package/dist/web/telemetry/google_cloud.js +7 -9
- package/dist/web/telemetry/setup.js +23 -9
- package/dist/web/telemetry/tracing.js +37 -15
- package/dist/web/tools/agent_tool.js +8 -4
- package/dist/web/tools/base_tool.js +4 -2
- package/dist/web/tools/forwarding_artifact_service.js +17 -1
- package/dist/web/tools/function_tool.js +1 -2
- package/dist/web/tools/google_search_tool.js +2 -5
- package/dist/web/tools/long_running_tool.js +3 -1
- package/dist/web/tools/mcp/mcp_session_manager.js +22 -12
- package/dist/web/tools/mcp/mcp_tool.js +1 -3
- package/dist/web/tools/mcp/mcp_toolset.js +1 -1
- package/dist/web/utils/env_aware_utils.js +9 -1
- package/dist/web/utils/gemini_schema_util.js +9 -4
- package/dist/web/utils/logger.js +43 -2
- package/dist/web/utils/object_notation_utils.js +47 -0
- package/dist/web/utils/simple_zod_to_json.js +102 -155
- package/dist/web/utils/variant_utils.js +1 -7
- package/dist/web/version.js +1 -1
- package/package.json +16 -5
- 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,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { MikroORM } from "@mikro-orm/core";
|
|
7
|
+
import { MariaDbDriver } from "@mikro-orm/mariadb";
|
|
8
|
+
import { MsSqlDriver } from "@mikro-orm/mssql";
|
|
9
|
+
import { MySqlDriver } from "@mikro-orm/mysql";
|
|
10
|
+
import { PostgreSqlDriver } from "@mikro-orm/postgresql";
|
|
11
|
+
import { SqliteDriver } from "@mikro-orm/sqlite";
|
|
12
|
+
import {
|
|
13
|
+
ENTITIES,
|
|
14
|
+
SCHEMA_VERSION_1_JSON,
|
|
15
|
+
SCHEMA_VERSION_KEY,
|
|
16
|
+
StorageMetadata
|
|
17
|
+
} from "./schema.js";
|
|
18
|
+
function getConnectionOptionsFromUri(uri) {
|
|
19
|
+
let driver;
|
|
20
|
+
if (uri.startsWith("postgres://") || uri.startsWith("postgresql://")) {
|
|
21
|
+
driver = PostgreSqlDriver;
|
|
22
|
+
} else if (uri.startsWith("mysql://")) {
|
|
23
|
+
driver = MySqlDriver;
|
|
24
|
+
} else if (uri.startsWith("mariadb://")) {
|
|
25
|
+
driver = MariaDbDriver;
|
|
26
|
+
} else if (uri.startsWith("sqlite://")) {
|
|
27
|
+
driver = SqliteDriver;
|
|
28
|
+
} else if (uri.startsWith("mssql://")) {
|
|
29
|
+
driver = MsSqlDriver;
|
|
30
|
+
} else {
|
|
31
|
+
throw new Error(`Unsupported database URI: ${uri}`);
|
|
32
|
+
}
|
|
33
|
+
if (uri === "sqlite://:memory:") {
|
|
34
|
+
return {
|
|
35
|
+
entities: ENTITIES,
|
|
36
|
+
dbName: ":memory:",
|
|
37
|
+
driver
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const { host, port, username, password, pathname } = new URL(uri);
|
|
41
|
+
const hostName = host.split(":")[0];
|
|
42
|
+
return {
|
|
43
|
+
entities: ENTITIES,
|
|
44
|
+
dbName: pathname.slice(1),
|
|
45
|
+
host: hostName,
|
|
46
|
+
port: port ? parseInt(port) : void 0,
|
|
47
|
+
user: username,
|
|
48
|
+
password,
|
|
49
|
+
driver
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
async function ensureDatabaseCreated(ormOrUrlOrOptions) {
|
|
53
|
+
let orm;
|
|
54
|
+
if (ormOrUrlOrOptions instanceof MikroORM) {
|
|
55
|
+
orm = ormOrUrlOrOptions;
|
|
56
|
+
} else if (typeof ormOrUrlOrOptions === "string") {
|
|
57
|
+
orm = await MikroORM.init(getConnectionOptionsFromUri(ormOrUrlOrOptions));
|
|
58
|
+
} else {
|
|
59
|
+
orm = await MikroORM.init(ormOrUrlOrOptions);
|
|
60
|
+
}
|
|
61
|
+
await orm.schema.ensureDatabase();
|
|
62
|
+
await orm.schema.updateSchema();
|
|
63
|
+
}
|
|
64
|
+
async function validateDatabaseSchemaVersion(orm) {
|
|
65
|
+
const em = orm.em.fork();
|
|
66
|
+
const existing = await em.findOne(StorageMetadata, {
|
|
67
|
+
key: SCHEMA_VERSION_KEY
|
|
68
|
+
});
|
|
69
|
+
if (existing) {
|
|
70
|
+
if (existing.value !== SCHEMA_VERSION_1_JSON) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`ADK Database schema version ${existing.value} is not compatible.`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const newVersion = em.create(StorageMetadata, {
|
|
78
|
+
key: SCHEMA_VERSION_KEY,
|
|
79
|
+
value: SCHEMA_VERSION_1_JSON
|
|
80
|
+
});
|
|
81
|
+
await em.persist(newVersion).flush();
|
|
82
|
+
}
|
|
83
|
+
export {
|
|
84
|
+
ensureDatabaseCreated,
|
|
85
|
+
getConnectionOptionsFromUri,
|
|
86
|
+
validateDatabaseSchemaVersion
|
|
87
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @license
|
|
13
|
+
* Copyright 2026 Google LLC
|
|
14
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
15
|
+
*/
|
|
16
|
+
import { Entity, JsonType, PrimaryKey, Property } from "@mikro-orm/core";
|
|
17
|
+
import {
|
|
18
|
+
transformToCamelCaseEvent,
|
|
19
|
+
transformToSnakeCaseEvent
|
|
20
|
+
} from "../../events/event.js";
|
|
21
|
+
const SCHEMA_VERSION_KEY = "schema_version";
|
|
22
|
+
const SCHEMA_VERSION_1_JSON = "1";
|
|
23
|
+
class CamelCaseToSnakeCaseJsonType extends JsonType {
|
|
24
|
+
convertToDatabaseValue(value) {
|
|
25
|
+
return JSON.stringify(transformToSnakeCaseEvent(value));
|
|
26
|
+
}
|
|
27
|
+
convertToJSValue(value) {
|
|
28
|
+
if (typeof value === "string") {
|
|
29
|
+
return transformToCamelCaseEvent(JSON.parse(value));
|
|
30
|
+
}
|
|
31
|
+
return transformToCamelCaseEvent(value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
let StorageMetadata = class {
|
|
35
|
+
};
|
|
36
|
+
__decorateClass([
|
|
37
|
+
PrimaryKey({ type: "string" })
|
|
38
|
+
], StorageMetadata.prototype, "key", 2);
|
|
39
|
+
__decorateClass([
|
|
40
|
+
Property({ type: "string" })
|
|
41
|
+
], StorageMetadata.prototype, "value", 2);
|
|
42
|
+
StorageMetadata = __decorateClass([
|
|
43
|
+
Entity({ tableName: "adk_internal_metadata" })
|
|
44
|
+
], StorageMetadata);
|
|
45
|
+
let StorageAppState = class {
|
|
46
|
+
constructor() {
|
|
47
|
+
this.updateTime = /* @__PURE__ */ new Date();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
__decorateClass([
|
|
51
|
+
PrimaryKey({ type: "string", fieldName: "app_name" })
|
|
52
|
+
], StorageAppState.prototype, "appName", 2);
|
|
53
|
+
__decorateClass([
|
|
54
|
+
Property({ type: "json" })
|
|
55
|
+
], StorageAppState.prototype, "state", 2);
|
|
56
|
+
__decorateClass([
|
|
57
|
+
Property({
|
|
58
|
+
type: "datetime",
|
|
59
|
+
fieldName: "update_time",
|
|
60
|
+
onCreate: () => /* @__PURE__ */ new Date(),
|
|
61
|
+
onUpdate: () => /* @__PURE__ */ new Date()
|
|
62
|
+
})
|
|
63
|
+
], StorageAppState.prototype, "updateTime", 2);
|
|
64
|
+
StorageAppState = __decorateClass([
|
|
65
|
+
Entity({ tableName: "app_states" })
|
|
66
|
+
], StorageAppState);
|
|
67
|
+
PrimaryKey.name;
|
|
68
|
+
let StorageUserState = class {
|
|
69
|
+
constructor() {
|
|
70
|
+
this.updateTime = /* @__PURE__ */ new Date();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
__decorateClass([
|
|
74
|
+
PrimaryKey({ type: "string", fieldName: "app_name" })
|
|
75
|
+
], StorageUserState.prototype, "appName", 2);
|
|
76
|
+
__decorateClass([
|
|
77
|
+
PrimaryKey({ type: "string", fieldName: "user_id" })
|
|
78
|
+
], StorageUserState.prototype, "userId", 2);
|
|
79
|
+
__decorateClass([
|
|
80
|
+
Property({ type: "json" })
|
|
81
|
+
], StorageUserState.prototype, "state", 2);
|
|
82
|
+
__decorateClass([
|
|
83
|
+
Property({
|
|
84
|
+
type: "datetime",
|
|
85
|
+
fieldName: "update_time",
|
|
86
|
+
onCreate: () => /* @__PURE__ */ new Date(),
|
|
87
|
+
onUpdate: () => /* @__PURE__ */ new Date()
|
|
88
|
+
})
|
|
89
|
+
], StorageUserState.prototype, "updateTime", 2);
|
|
90
|
+
StorageUserState = __decorateClass([
|
|
91
|
+
Entity({ tableName: "user_states" })
|
|
92
|
+
], StorageUserState);
|
|
93
|
+
PrimaryKey.name;
|
|
94
|
+
let StorageSession = class {
|
|
95
|
+
constructor() {
|
|
96
|
+
this.createTime = /* @__PURE__ */ new Date();
|
|
97
|
+
this.updateTime = /* @__PURE__ */ new Date();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
__decorateClass([
|
|
101
|
+
PrimaryKey({ type: "string" })
|
|
102
|
+
], StorageSession.prototype, "id", 2);
|
|
103
|
+
__decorateClass([
|
|
104
|
+
PrimaryKey({ type: "string", fieldName: "app_name" })
|
|
105
|
+
], StorageSession.prototype, "appName", 2);
|
|
106
|
+
__decorateClass([
|
|
107
|
+
PrimaryKey({ type: "string", fieldName: "user_id" })
|
|
108
|
+
], StorageSession.prototype, "userId", 2);
|
|
109
|
+
__decorateClass([
|
|
110
|
+
Property({ type: "json" })
|
|
111
|
+
], StorageSession.prototype, "state", 2);
|
|
112
|
+
__decorateClass([
|
|
113
|
+
Property({
|
|
114
|
+
type: "datetime",
|
|
115
|
+
fieldName: "create_time",
|
|
116
|
+
onCreate: () => /* @__PURE__ */ new Date()
|
|
117
|
+
})
|
|
118
|
+
], StorageSession.prototype, "createTime", 2);
|
|
119
|
+
__decorateClass([
|
|
120
|
+
Property({
|
|
121
|
+
type: "datetime",
|
|
122
|
+
fieldName: "update_time",
|
|
123
|
+
onCreate: () => /* @__PURE__ */ new Date()
|
|
124
|
+
})
|
|
125
|
+
], StorageSession.prototype, "updateTime", 2);
|
|
126
|
+
StorageSession = __decorateClass([
|
|
127
|
+
Entity({ tableName: "sessions" })
|
|
128
|
+
], StorageSession);
|
|
129
|
+
PrimaryKey.name;
|
|
130
|
+
let StorageEvent = class {
|
|
131
|
+
};
|
|
132
|
+
__decorateClass([
|
|
133
|
+
PrimaryKey({ type: "string" })
|
|
134
|
+
], StorageEvent.prototype, "id", 2);
|
|
135
|
+
__decorateClass([
|
|
136
|
+
PrimaryKey({ type: "string", fieldName: "app_name" })
|
|
137
|
+
], StorageEvent.prototype, "appName", 2);
|
|
138
|
+
__decorateClass([
|
|
139
|
+
PrimaryKey({ type: "string", fieldName: "user_id" })
|
|
140
|
+
], StorageEvent.prototype, "userId", 2);
|
|
141
|
+
__decorateClass([
|
|
142
|
+
PrimaryKey({ type: "string", fieldName: "session_id" })
|
|
143
|
+
], StorageEvent.prototype, "sessionId", 2);
|
|
144
|
+
__decorateClass([
|
|
145
|
+
Property({ type: "string", fieldName: "invocation_id" })
|
|
146
|
+
], StorageEvent.prototype, "invocationId", 2);
|
|
147
|
+
__decorateClass([
|
|
148
|
+
Property({ type: "datetime" })
|
|
149
|
+
], StorageEvent.prototype, "timestamp", 2);
|
|
150
|
+
__decorateClass([
|
|
151
|
+
Property({ type: CamelCaseToSnakeCaseJsonType, fieldName: "event_data" })
|
|
152
|
+
], StorageEvent.prototype, "eventData", 2);
|
|
153
|
+
StorageEvent = __decorateClass([
|
|
154
|
+
Entity({ tableName: "events" })
|
|
155
|
+
], StorageEvent);
|
|
156
|
+
const ENTITIES = [
|
|
157
|
+
StorageMetadata,
|
|
158
|
+
StorageAppState,
|
|
159
|
+
StorageUserState,
|
|
160
|
+
StorageSession,
|
|
161
|
+
StorageEvent
|
|
162
|
+
];
|
|
163
|
+
export {
|
|
164
|
+
ENTITIES,
|
|
165
|
+
SCHEMA_VERSION_1_JSON,
|
|
166
|
+
SCHEMA_VERSION_KEY,
|
|
167
|
+
StorageAppState,
|
|
168
|
+
StorageEvent,
|
|
169
|
+
StorageMetadata,
|
|
170
|
+
StorageSession,
|
|
171
|
+
StorageUserState
|
|
172
|
+
};
|
|
@@ -6,9 +6,15 @@
|
|
|
6
6
|
import { cloneDeep } from "lodash-es";
|
|
7
7
|
import { randomUUID } from "../utils/env_aware_utils.js";
|
|
8
8
|
import { logger } from "../utils/logger.js";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
BaseSessionService,
|
|
11
|
+
mergeStates
|
|
12
|
+
} from "./base_session_service.js";
|
|
10
13
|
import { createSession } from "./session.js";
|
|
11
14
|
import { State } from "./state.js";
|
|
15
|
+
function isInMemoryConnectionString(uri) {
|
|
16
|
+
return uri === "memory://";
|
|
17
|
+
}
|
|
12
18
|
class InMemorySessionService extends BaseSessionService {
|
|
13
19
|
constructor() {
|
|
14
20
|
super(...arguments);
|
|
@@ -26,7 +32,13 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
26
32
|
*/
|
|
27
33
|
this.appState = {};
|
|
28
34
|
}
|
|
29
|
-
createSession({
|
|
35
|
+
async createSession({
|
|
36
|
+
appName,
|
|
37
|
+
userId,
|
|
38
|
+
state,
|
|
39
|
+
sessionId
|
|
40
|
+
}) {
|
|
41
|
+
var _a;
|
|
30
42
|
const session = createSession({
|
|
31
43
|
id: sessionId || randomUUID(),
|
|
32
44
|
appName,
|
|
@@ -42,11 +54,21 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
42
54
|
this.sessions[appName][userId] = {};
|
|
43
55
|
}
|
|
44
56
|
this.sessions[appName][userId][session.id] = session;
|
|
45
|
-
|
|
46
|
-
|
|
57
|
+
const copiedSession = cloneDeep(session);
|
|
58
|
+
copiedSession.state = mergeStates(
|
|
59
|
+
this.appState[appName],
|
|
60
|
+
(_a = this.userState[appName]) == null ? void 0 : _a[userId],
|
|
61
|
+
copiedSession.state
|
|
47
62
|
);
|
|
63
|
+
return copiedSession;
|
|
48
64
|
}
|
|
49
|
-
getSession({
|
|
65
|
+
async getSession({
|
|
66
|
+
appName,
|
|
67
|
+
userId,
|
|
68
|
+
sessionId,
|
|
69
|
+
config
|
|
70
|
+
}) {
|
|
71
|
+
var _a;
|
|
50
72
|
if (!this.sessions[appName] || !this.sessions[appName][userId] || !this.sessions[appName][userId][sessionId]) {
|
|
51
73
|
return Promise.resolve(void 0);
|
|
52
74
|
}
|
|
@@ -54,7 +76,9 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
54
76
|
const copiedSession = cloneDeep(session);
|
|
55
77
|
if (config) {
|
|
56
78
|
if (config.numRecentEvents) {
|
|
57
|
-
copiedSession.events = copiedSession.events.slice(
|
|
79
|
+
copiedSession.events = copiedSession.events.slice(
|
|
80
|
+
-config.numRecentEvents
|
|
81
|
+
);
|
|
58
82
|
}
|
|
59
83
|
if (config.afterTimestamp) {
|
|
60
84
|
let i = copiedSession.events.length - 1;
|
|
@@ -69,33 +93,50 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
69
93
|
}
|
|
70
94
|
}
|
|
71
95
|
}
|
|
72
|
-
|
|
96
|
+
copiedSession.state = mergeStates(
|
|
97
|
+
this.appState[appName],
|
|
98
|
+
(_a = this.userState[appName]) == null ? void 0 : _a[userId],
|
|
99
|
+
copiedSession.state
|
|
100
|
+
);
|
|
101
|
+
return copiedSession;
|
|
73
102
|
}
|
|
74
|
-
listSessions({
|
|
103
|
+
listSessions({
|
|
104
|
+
appName,
|
|
105
|
+
userId
|
|
106
|
+
}) {
|
|
75
107
|
if (!this.sessions[appName] || !this.sessions[appName][userId]) {
|
|
76
108
|
return Promise.resolve({ sessions: [] });
|
|
77
109
|
}
|
|
78
110
|
const sessionsWithoutEvents = [];
|
|
79
111
|
for (const session of Object.values(this.sessions[appName][userId])) {
|
|
80
|
-
sessionsWithoutEvents.push(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
112
|
+
sessionsWithoutEvents.push(
|
|
113
|
+
createSession({
|
|
114
|
+
id: session.id,
|
|
115
|
+
appName: session.appName,
|
|
116
|
+
userId: session.userId,
|
|
117
|
+
state: {},
|
|
118
|
+
events: [],
|
|
119
|
+
lastUpdateTime: session.lastUpdateTime
|
|
120
|
+
})
|
|
121
|
+
);
|
|
88
122
|
}
|
|
89
123
|
return Promise.resolve({ sessions: sessionsWithoutEvents });
|
|
90
124
|
}
|
|
91
|
-
async deleteSession({
|
|
125
|
+
async deleteSession({
|
|
126
|
+
appName,
|
|
127
|
+
userId,
|
|
128
|
+
sessionId
|
|
129
|
+
}) {
|
|
92
130
|
const session = await this.getSession({ appName, userId, sessionId });
|
|
93
131
|
if (!session) {
|
|
94
132
|
return;
|
|
95
133
|
}
|
|
96
134
|
delete this.sessions[appName][userId][sessionId];
|
|
97
135
|
}
|
|
98
|
-
async appendEvent({
|
|
136
|
+
async appendEvent({
|
|
137
|
+
session,
|
|
138
|
+
event
|
|
139
|
+
}) {
|
|
99
140
|
await super.appendEvent({ session, event });
|
|
100
141
|
session.lastUpdateTime = event.timestamp;
|
|
101
142
|
const appName = session.appName;
|
|
@@ -134,21 +175,8 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
134
175
|
storageSession.lastUpdateTime = event.timestamp;
|
|
135
176
|
return event;
|
|
136
177
|
}
|
|
137
|
-
mergeState(appName, userId, copiedSession) {
|
|
138
|
-
if (this.appState[appName]) {
|
|
139
|
-
for (const key of Object.keys(this.appState[appName])) {
|
|
140
|
-
copiedSession.state[State.APP_PREFIX + key] = this.appState[appName][key];
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (!this.userState[appName] || !this.userState[appName][userId]) {
|
|
144
|
-
return copiedSession;
|
|
145
|
-
}
|
|
146
|
-
for (const key of Object.keys(this.userState[appName][userId])) {
|
|
147
|
-
copiedSession.state[State.USER_PREFIX + key] = this.userState[appName][userId][key];
|
|
148
|
-
}
|
|
149
|
-
return copiedSession;
|
|
150
|
-
}
|
|
151
178
|
}
|
|
152
179
|
export {
|
|
153
|
-
InMemorySessionService
|
|
180
|
+
InMemorySessionService,
|
|
181
|
+
isInMemoryConnectionString
|
|
154
182
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
DatabaseSessionService,
|
|
8
|
+
isDatabaseConnectionString
|
|
9
|
+
} from "./database_session_service.js";
|
|
10
|
+
import {
|
|
11
|
+
InMemorySessionService,
|
|
12
|
+
isInMemoryConnectionString
|
|
13
|
+
} from "./in_memory_session_service.js";
|
|
14
|
+
function getSessionServiceFromUri(uri) {
|
|
15
|
+
if (isInMemoryConnectionString(uri)) {
|
|
16
|
+
return new InMemorySessionService();
|
|
17
|
+
}
|
|
18
|
+
if (isDatabaseConnectionString(uri)) {
|
|
19
|
+
return new DatabaseSessionService(uri);
|
|
20
|
+
}
|
|
21
|
+
throw new Error(`Unsupported session service URI: ${uri}`);
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
getSessionServiceFromUri
|
|
25
|
+
};
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
|
|
8
|
-
import { detectResources } from "@opentelemetry/resources";
|
|
9
|
-
import { gcpDetector } from "@opentelemetry/resource-detector-gcp";
|
|
6
|
+
import { MetricExporter } from "@google-cloud/opentelemetry-cloud-monitoring-exporter";
|
|
10
7
|
import { TraceExporter } from "@google-cloud/opentelemetry-cloud-trace-exporter";
|
|
8
|
+
import { gcpDetector } from "@opentelemetry/resource-detector-gcp";
|
|
9
|
+
import { detectResources } from "@opentelemetry/resources";
|
|
10
|
+
import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
|
|
11
11
|
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
12
|
-
import {
|
|
12
|
+
import { GoogleAuth } from "google-auth-library";
|
|
13
13
|
import { logger } from "../utils/logger.js";
|
|
14
14
|
const GCP_PROJECT_ERROR_MESSAGE = "Cannot determine GCP Project. OTel GCP Exporters cannot be set up. Please make sure to log into correct GCP Project.";
|
|
15
15
|
async function getGcpProjectId() {
|
|
@@ -17,7 +17,7 @@ async function getGcpProjectId() {
|
|
|
17
17
|
const auth = new GoogleAuth();
|
|
18
18
|
const projectId = await auth.getProjectId();
|
|
19
19
|
return projectId || void 0;
|
|
20
|
-
} catch (
|
|
20
|
+
} catch (_e) {
|
|
21
21
|
return void 0;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -33,9 +33,7 @@ async function getGcpExporters(config = {}) {
|
|
|
33
33
|
return {};
|
|
34
34
|
}
|
|
35
35
|
return {
|
|
36
|
-
spanProcessors: enableTracing ? [
|
|
37
|
-
new BatchSpanProcessor(new TraceExporter({ projectId }))
|
|
38
|
-
] : [],
|
|
36
|
+
spanProcessors: enableTracing ? [new BatchSpanProcessor(new TraceExporter({ projectId }))] : [],
|
|
39
37
|
metricReaders: enableMetrics ? [
|
|
40
38
|
new PeriodicExportingMetricReader({
|
|
41
39
|
exporter: new MetricExporter({ projectId }),
|
|
@@ -3,22 +3,32 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { metrics, trace } from "@opentelemetry/api";
|
|
7
7
|
import { logs } from "@opentelemetry/api-logs";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
9
|
+
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
|
|
10
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
10
11
|
import { detectResources } from "@opentelemetry/resources";
|
|
12
|
+
import {
|
|
13
|
+
BatchLogRecordProcessor,
|
|
14
|
+
LoggerProvider
|
|
15
|
+
} from "@opentelemetry/sdk-logs";
|
|
16
|
+
import {
|
|
17
|
+
MeterProvider,
|
|
18
|
+
PeriodicExportingMetricReader
|
|
19
|
+
} from "@opentelemetry/sdk-metrics";
|
|
11
20
|
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
12
21
|
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
|
|
13
|
-
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
14
|
-
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
|
|
15
|
-
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
16
22
|
function maybeSetOtelProviders(otelHooksToSetup = [], otelResource) {
|
|
17
23
|
const resource = otelResource || getOtelResource();
|
|
18
24
|
const allHooks = [...otelHooksToSetup, getOtelExporters()];
|
|
19
|
-
const spanProcessors = allHooks.flatMap(
|
|
25
|
+
const spanProcessors = allHooks.flatMap(
|
|
26
|
+
(hooks) => hooks.spanProcessors || []
|
|
27
|
+
);
|
|
20
28
|
const metricReaders = allHooks.flatMap((hooks) => hooks.metricReaders || []);
|
|
21
|
-
const logRecordProcessors = allHooks.flatMap(
|
|
29
|
+
const logRecordProcessors = allHooks.flatMap(
|
|
30
|
+
(hooks) => hooks.logRecordProcessors || []
|
|
31
|
+
);
|
|
22
32
|
if (spanProcessors.length > 0) {
|
|
23
33
|
const tracerProvider = new NodeTracerProvider({
|
|
24
34
|
resource,
|
|
@@ -58,7 +68,11 @@ function getOtelExporters(config = getOtelExportersConfig()) {
|
|
|
58
68
|
const { enableTracing, enableMetrics, enableLogging } = config;
|
|
59
69
|
return {
|
|
60
70
|
spanProcessors: enableTracing ? [new BatchSpanProcessor(new OTLPTraceExporter())] : [],
|
|
61
|
-
metricReaders: enableMetrics ? [
|
|
71
|
+
metricReaders: enableMetrics ? [
|
|
72
|
+
new PeriodicExportingMetricReader({
|
|
73
|
+
exporter: new OTLPMetricExporter()
|
|
74
|
+
})
|
|
75
|
+
] : [],
|
|
62
76
|
logRecordProcessors: enableLogging ? [new BatchLogRecordProcessor(new OTLPLogExporter())] : []
|
|
63
77
|
};
|
|
64
78
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { context, trace } from "@opentelemetry/api";
|
|
7
7
|
import { version } from "../version.js";
|
|
8
8
|
const GEN_AI_AGENT_DESCRIPTION = "gen_ai.agent.description";
|
|
9
9
|
const GEN_AI_AGENT_NAME = "gen_ai.agent.name";
|
|
@@ -13,14 +13,11 @@ const GEN_AI_TOOL_CALL_ID = "gen_ai.tool.call.id";
|
|
|
13
13
|
const GEN_AI_TOOL_DESCRIPTION = "gen_ai.tool.description";
|
|
14
14
|
const GEN_AI_TOOL_NAME = "gen_ai.tool.name";
|
|
15
15
|
const GEN_AI_TOOL_TYPE = "gen_ai.tool.type";
|
|
16
|
-
const tracer = trace.getTracer(
|
|
17
|
-
"gcp.vertex.agent",
|
|
18
|
-
version
|
|
19
|
-
);
|
|
16
|
+
const tracer = trace.getTracer("gcp.vertex.agent", version);
|
|
20
17
|
function safeJsonSerialize(obj) {
|
|
21
18
|
try {
|
|
22
19
|
return JSON.stringify(obj);
|
|
23
|
-
} catch (
|
|
20
|
+
} catch (_e) {
|
|
24
21
|
return "<not serializable>";
|
|
25
22
|
}
|
|
26
23
|
}
|
|
@@ -97,7 +94,10 @@ function traceMergedToolCalls({
|
|
|
97
94
|
"gcp.vertex.agent.llm_request": "{}",
|
|
98
95
|
"gcp.vertex.agent.llm_response": "{}"
|
|
99
96
|
});
|
|
100
|
-
span.setAttribute(
|
|
97
|
+
span.setAttribute(
|
|
98
|
+
"gcp.vertex.agent.tool_response",
|
|
99
|
+
shouldAddRequestResponseToSpans() ? safeJsonSerialize(functionResponseEvent) : "{}"
|
|
100
|
+
);
|
|
101
101
|
}
|
|
102
102
|
function traceCallLlm({
|
|
103
103
|
invocationContext,
|
|
@@ -121,14 +121,26 @@ function traceCallLlm({
|
|
|
121
121
|
span.setAttribute("gen_ai.request.top_p", llmRequest.config.topP);
|
|
122
122
|
}
|
|
123
123
|
if (((_b = llmRequest.config) == null ? void 0 : _b.maxOutputTokens) !== void 0) {
|
|
124
|
-
span.setAttribute(
|
|
124
|
+
span.setAttribute(
|
|
125
|
+
"gen_ai.request.max_tokens",
|
|
126
|
+
llmRequest.config.maxOutputTokens
|
|
127
|
+
);
|
|
125
128
|
}
|
|
126
|
-
span.setAttribute(
|
|
129
|
+
span.setAttribute(
|
|
130
|
+
"gcp.vertex.agent.llm_response",
|
|
131
|
+
shouldAddRequestResponseToSpans() ? safeJsonSerialize(llmResponse) : "{}"
|
|
132
|
+
);
|
|
127
133
|
if (llmResponse.usageMetadata) {
|
|
128
|
-
span.setAttribute(
|
|
134
|
+
span.setAttribute(
|
|
135
|
+
"gen_ai.usage.input_tokens",
|
|
136
|
+
llmResponse.usageMetadata.promptTokenCount || 0
|
|
137
|
+
);
|
|
129
138
|
}
|
|
130
139
|
if ((_c = llmResponse.usageMetadata) == null ? void 0 : _c.candidatesTokenCount) {
|
|
131
|
-
span.setAttribute(
|
|
140
|
+
span.setAttribute(
|
|
141
|
+
"gen_ai.usage.output_tokens",
|
|
142
|
+
llmResponse.usageMetadata.candidatesTokenCount
|
|
143
|
+
);
|
|
132
144
|
}
|
|
133
145
|
if (llmResponse.finishReason) {
|
|
134
146
|
const finishReasonValue = typeof llmResponse.finishReason === "string" ? llmResponse.finishReason.toLowerCase() : String(llmResponse.finishReason).toLowerCase();
|
|
@@ -146,7 +158,10 @@ function traceSendData({
|
|
|
146
158
|
"gcp.vertex.agent.invocation_id": invocationContext.invocationId,
|
|
147
159
|
"gcp.vertex.agent.event_id": eventId
|
|
148
160
|
});
|
|
149
|
-
span.setAttribute(
|
|
161
|
+
span.setAttribute(
|
|
162
|
+
"gcp.vertex.agent.data",
|
|
163
|
+
shouldAddRequestResponseToSpans() ? safeJsonSerialize(data) : "{}"
|
|
164
|
+
);
|
|
150
165
|
}
|
|
151
166
|
function buildLlmRequestForTrace(llmRequest) {
|
|
152
167
|
const result = {
|
|
@@ -166,7 +181,7 @@ function buildLlmRequestForTrace(llmRequest) {
|
|
|
166
181
|
});
|
|
167
182
|
return result;
|
|
168
183
|
}
|
|
169
|
-
function
|
|
184
|
+
function bindOtelContextToAsyncGenerator(ctx, generator) {
|
|
170
185
|
return {
|
|
171
186
|
// Bind the next() method to execute within the provided context
|
|
172
187
|
next: context.bind(ctx, generator.next.bind(generator)),
|
|
@@ -176,16 +191,23 @@ function bindAsyncGenerator(ctx, generator) {
|
|
|
176
191
|
throw: context.bind(ctx, generator.throw.bind(generator)),
|
|
177
192
|
// Ensure the async iterator symbol also returns a context-bound generator
|
|
178
193
|
[Symbol.asyncIterator]() {
|
|
179
|
-
return
|
|
194
|
+
return bindOtelContextToAsyncGenerator(
|
|
195
|
+
ctx,
|
|
196
|
+
generator[Symbol.asyncIterator]()
|
|
197
|
+
);
|
|
180
198
|
}
|
|
181
199
|
};
|
|
182
200
|
}
|
|
201
|
+
function runAsyncGeneratorWithOtelContext(otelContext, generatorFnContext, generatorFn) {
|
|
202
|
+
const generator = generatorFn.call(generatorFnContext);
|
|
203
|
+
return bindOtelContextToAsyncGenerator(otelContext, generator);
|
|
204
|
+
}
|
|
183
205
|
function shouldAddRequestResponseToSpans() {
|
|
184
206
|
const envValue = process.env.ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS || "true";
|
|
185
207
|
return envValue === "true" || envValue === "1";
|
|
186
208
|
}
|
|
187
209
|
export {
|
|
188
|
-
|
|
210
|
+
runAsyncGeneratorWithOtelContext,
|
|
189
211
|
traceAgentInvocation,
|
|
190
212
|
traceCallLlm,
|
|
191
213
|
traceMergedToolCalls,
|
|
@@ -18,9 +18,10 @@ function isAgentTool(obj) {
|
|
|
18
18
|
}
|
|
19
19
|
class AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGNATURE_SYMBOL, _b) {
|
|
20
20
|
constructor(config) {
|
|
21
|
-
super(
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
super({
|
|
22
|
+
name: config.agent.name,
|
|
23
|
+
description: config.agent.description || ""
|
|
24
|
+
});
|
|
24
25
|
/** A unique symbol to identify ADK agent tool class. */
|
|
25
26
|
this[_a] = true;
|
|
26
27
|
this.agent = config.agent;
|
|
@@ -58,7 +59,10 @@ class AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGNATURE_SYMBOL, _b) {
|
|
|
58
59
|
}
|
|
59
60
|
return declaration;
|
|
60
61
|
}
|
|
61
|
-
async runAsync({
|
|
62
|
+
async runAsync({
|
|
63
|
+
args,
|
|
64
|
+
toolContext
|
|
65
|
+
}) {
|
|
62
66
|
var _a2, _b2;
|
|
63
67
|
if (this.skipSummarization) {
|
|
64
68
|
toolContext.actions.skipSummarization = true;
|