@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,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { HttpOptions } from '@google/genai';
|
|
7
|
+
import { BaseLlmConnection } from './base_llm_connection.js';
|
|
8
|
+
import { Gemini, GeminiParams } from './google_llm.js';
|
|
9
|
+
import { LlmRequest } from './llm_request.js';
|
|
10
|
+
import { LlmResponse } from './llm_response.js';
|
|
11
|
+
export interface ApigeeLlmParams extends GeminiParams {
|
|
12
|
+
/**
|
|
13
|
+
* The name of the model to use. The model string specifies the LLM provider
|
|
14
|
+
* (e.g., Vertex AI, Gemini), API version, and the model ID. Supported format:
|
|
15
|
+
* `apigee/[<provider>/][<version>/]<model_id>`
|
|
16
|
+
* Components:
|
|
17
|
+
* `provider` (optional): `vertex_ai` or `gemini`.
|
|
18
|
+
* `version` (optional): The API version (e.g., `v1`, `v1beta`). If not
|
|
19
|
+
* provided, a default version will selected based on the provider.
|
|
20
|
+
* `model_id` (required): The model identifier (e.g.,
|
|
21
|
+
* `gemini-2.5-flash`).
|
|
22
|
+
* Examples:
|
|
23
|
+
* - `apigee/gemini-2.5-flash`
|
|
24
|
+
* - `apigee/v1/gemini-2.5-flash`
|
|
25
|
+
* - `apigee/vertex_ai/gemini-2.5-flash`
|
|
26
|
+
* - `apigee/gemini/v1/gemini-2.5-flash`
|
|
27
|
+
* - `apigee/vertex_ai/v1beta/gemini-2.5-flash`
|
|
28
|
+
*/
|
|
29
|
+
model: string;
|
|
30
|
+
/**
|
|
31
|
+
* The proxy URL for the provider API. If not provided, it will look for
|
|
32
|
+
* the APIGEE_PROXY_URL environment variable.
|
|
33
|
+
*/
|
|
34
|
+
proxyUrl?: string;
|
|
35
|
+
/**
|
|
36
|
+
* API key to use. If not provided, it will look for
|
|
37
|
+
* the GOOGLE_GENAI_API_KEY or GEMINI_API_KEY environment variable. If gemini
|
|
38
|
+
* provider is selected and no key is provided, the fake key "-" will be
|
|
39
|
+
* used for the "x-goog-api-key" header.
|
|
40
|
+
*/
|
|
41
|
+
apiKey?: string;
|
|
42
|
+
}
|
|
43
|
+
export declare class ApigeeLlm extends Gemini {
|
|
44
|
+
private readonly proxyUrl;
|
|
45
|
+
/**
|
|
46
|
+
* A list of model name patterns that are supported by this LLM.
|
|
47
|
+
*
|
|
48
|
+
* @returns A list of supported models.
|
|
49
|
+
*/
|
|
50
|
+
static readonly supportedModels: Array<string | RegExp>;
|
|
51
|
+
constructor({ model, proxyUrl, apiKey, vertexai, location, project, headers, }: ApigeeLlmParams);
|
|
52
|
+
protected getHttpOptions(): HttpOptions;
|
|
53
|
+
protected getLiveHttpOptions(): HttpOptions;
|
|
54
|
+
private identifyApiVersion;
|
|
55
|
+
private _apigeeLiveApiVersion?;
|
|
56
|
+
get liveApiVersion(): string;
|
|
57
|
+
generateContentAsync(llmRequest: LlmRequest, stream?: boolean): AsyncGenerator<LlmResponse, void>;
|
|
58
|
+
connect(llmRequest: LlmRequest): Promise<BaseLlmConnection>;
|
|
59
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { GoogleGenAI } from '@google/genai';
|
|
6
|
+
import { GoogleGenAI, HttpOptions } from '@google/genai';
|
|
7
7
|
import { GoogleLLMVariant } from '../utils/variant_utils.js';
|
|
8
8
|
import { BaseLlm } from './base_llm.js';
|
|
9
9
|
import { BaseLlmConnection } from './base_llm_connection.js';
|
|
@@ -45,7 +45,7 @@ export interface GeminiParams {
|
|
|
45
45
|
*/
|
|
46
46
|
export declare class Gemini extends BaseLlm {
|
|
47
47
|
private readonly apiKey?;
|
|
48
|
-
|
|
48
|
+
protected readonly vertexai: boolean;
|
|
49
49
|
private readonly project?;
|
|
50
50
|
private readonly location?;
|
|
51
51
|
private readonly headers?;
|
|
@@ -72,9 +72,11 @@ export declare class Gemini extends BaseLlm {
|
|
|
72
72
|
* @yields LlmResponse: The model response.
|
|
73
73
|
*/
|
|
74
74
|
generateContentAsync(llmRequest: LlmRequest, stream?: boolean): AsyncGenerator<LlmResponse, void>;
|
|
75
|
+
protected getHttpOptions(): HttpOptions;
|
|
75
76
|
get apiClient(): GoogleGenAI;
|
|
76
77
|
get apiBackend(): GoogleLLMVariant;
|
|
77
78
|
get liveApiVersion(): string;
|
|
79
|
+
protected getLiveHttpOptions(): HttpOptions;
|
|
78
80
|
get liveApiClient(): GoogleGenAI;
|
|
79
81
|
/**
|
|
80
82
|
* Connects to the Gemini model and returns an llm connection.
|
|
@@ -85,3 +87,4 @@ export declare class Gemini extends BaseLlm {
|
|
|
85
87
|
connect(llmRequest: LlmRequest): Promise<BaseLlmConnection>;
|
|
86
88
|
private preprocessRequest;
|
|
87
89
|
}
|
|
90
|
+
export declare function geminiInitParams({ model, vertexai, project, location, apiKey, }: GeminiParams): GeminiParams;
|
|
@@ -40,6 +40,21 @@ export declare class Runner {
|
|
|
40
40
|
readonly memoryService?: BaseMemoryService;
|
|
41
41
|
readonly credentialService?: BaseCredentialService;
|
|
42
42
|
constructor(input: RunnerConfig);
|
|
43
|
+
/**
|
|
44
|
+
* Runs the agent with a new, ephemeral session.
|
|
45
|
+
*
|
|
46
|
+
* @param params.userId The user ID of the session.
|
|
47
|
+
* @param params.newMessage A new message to append to the session.
|
|
48
|
+
* @param params.stateDelta An optional state delta to apply to the session.
|
|
49
|
+
* @param params.runConfig The run config for the agent.
|
|
50
|
+
* @yields The Events generated by the agent.
|
|
51
|
+
*/
|
|
52
|
+
runEphemeral(params: {
|
|
53
|
+
userId: string;
|
|
54
|
+
newMessage: Content;
|
|
55
|
+
stateDelta?: Record<string, unknown>;
|
|
56
|
+
runConfig?: RunConfig;
|
|
57
|
+
}): AsyncGenerator<Event, void, undefined>;
|
|
43
58
|
/**
|
|
44
59
|
* Runs the agent with the given message, and returns an async generator of
|
|
45
60
|
* events.
|
|
@@ -99,6 +99,13 @@ export declare abstract class BaseSessionService {
|
|
|
99
99
|
* found.
|
|
100
100
|
*/
|
|
101
101
|
abstract getSession(request: GetSessionRequest): Promise<Session | undefined>;
|
|
102
|
+
/**
|
|
103
|
+
* Gets a session or creates one if it doesn't exist.
|
|
104
|
+
*
|
|
105
|
+
* @param request The request to get or create a session.
|
|
106
|
+
* @return A promise that resolves to the session instance.
|
|
107
|
+
*/
|
|
108
|
+
getOrCreateSession(request: CreateSessionRequest): Promise<Session>;
|
|
102
109
|
/**
|
|
103
110
|
* Lists sessions for a user.
|
|
104
111
|
*
|
|
@@ -127,3 +134,16 @@ export declare abstract class BaseSessionService {
|
|
|
127
134
|
*/
|
|
128
135
|
private updateSessionState;
|
|
129
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Removes temporary state delta keys from the event.
|
|
139
|
+
*/
|
|
140
|
+
export declare function trimTempDeltaState(event: Event): Event;
|
|
141
|
+
/**
|
|
142
|
+
* Merges app state, user state, and session state.
|
|
143
|
+
*
|
|
144
|
+
* @param appState The application state.
|
|
145
|
+
* @param userState The user state.
|
|
146
|
+
* @param sessionState The session state.
|
|
147
|
+
* @return The merged state.
|
|
148
|
+
*/
|
|
149
|
+
export declare function mergeStates(appState?: Record<string, unknown>, userState?: Record<string, unknown>, sessionState?: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Options as MikroDBOptions } from '@mikro-orm/core';
|
|
7
|
+
import { Event } from '../events/event.js';
|
|
8
|
+
import { AppendEventRequest, BaseSessionService, CreateSessionRequest, DeleteSessionRequest, GetSessionRequest, ListSessionsRequest, ListSessionsResponse } from './base_session_service.js';
|
|
9
|
+
import { Session } from './session.js';
|
|
10
|
+
/**
|
|
11
|
+
* Checks if a URI is a database connection URI.
|
|
12
|
+
*
|
|
13
|
+
* @param uri The URI to check.
|
|
14
|
+
* @returns True if the URI is a database connection URI, false otherwise.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isDatabaseConnectionString(uri?: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* A session service that uses a SQL database for storage via MikroORM.
|
|
19
|
+
*/
|
|
20
|
+
export declare class DatabaseSessionService extends BaseSessionService {
|
|
21
|
+
private orm?;
|
|
22
|
+
private initialized;
|
|
23
|
+
private options;
|
|
24
|
+
constructor(connectionStringOrOptions: MikroDBOptions | string);
|
|
25
|
+
init(): Promise<void>;
|
|
26
|
+
createSession({ appName, userId, state, sessionId, }: CreateSessionRequest): Promise<Session>;
|
|
27
|
+
getSession({ appName, userId, sessionId, config, }: GetSessionRequest): Promise<Session | undefined>;
|
|
28
|
+
listSessions({ appName, userId, }: ListSessionsRequest): Promise<ListSessionsResponse>;
|
|
29
|
+
deleteSession({ appName, userId, sessionId, }: DeleteSessionRequest): Promise<void>;
|
|
30
|
+
appendEvent({ session, event, }: AppendEventRequest): Promise<Event>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { MikroORM, Options as MikroORMOptions } from '@mikro-orm/core';
|
|
7
|
+
/**
|
|
8
|
+
* Parses a database connection URI and returns MikroORM Options.
|
|
9
|
+
*
|
|
10
|
+
* @param uri The database connection URI (e.g., "postgres://user:password@host:port/database")
|
|
11
|
+
* @returns MikroORM Options configured for the database
|
|
12
|
+
* @throws Error if the URI is invalid or unsupported
|
|
13
|
+
*/
|
|
14
|
+
export declare function getConnectionOptionsFromUri(uri: string): MikroORMOptions;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a database and tables if they don't exist.
|
|
17
|
+
*
|
|
18
|
+
* @param url The database connection URI (e.g., "postgres://user:password@host:port/database")
|
|
19
|
+
* @returns Promise<void>
|
|
20
|
+
* @throws Error if the URI is invalid or unsupported
|
|
21
|
+
*/
|
|
22
|
+
export declare function ensureDatabaseCreated(ormOrUrlOrOptions: MikroORM | MikroORMOptions | string): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Validates the schema version.
|
|
25
|
+
*
|
|
26
|
+
* @param orm The MikroORM instance.
|
|
27
|
+
* @throws Error if the schema version is not compatible.
|
|
28
|
+
*/
|
|
29
|
+
export declare function validateDatabaseSchemaVersion(orm: MikroORM): Promise<void>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { PrimaryKey } from '@mikro-orm/core';
|
|
7
|
+
import { Event } from '../../events/event.js';
|
|
8
|
+
export declare const SCHEMA_VERSION_KEY = "schema_version";
|
|
9
|
+
export declare const SCHEMA_VERSION_1_JSON = "1";
|
|
10
|
+
export declare class StorageMetadata {
|
|
11
|
+
key: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}
|
|
14
|
+
export declare class StorageAppState {
|
|
15
|
+
appName: string;
|
|
16
|
+
state: Record<string, unknown>;
|
|
17
|
+
updateTime: Date;
|
|
18
|
+
}
|
|
19
|
+
export declare class StorageUserState {
|
|
20
|
+
[PrimaryKey.name]?: [string, string] | undefined;
|
|
21
|
+
appName: string;
|
|
22
|
+
userId: string;
|
|
23
|
+
state: Record<string, unknown>;
|
|
24
|
+
updateTime: Date;
|
|
25
|
+
}
|
|
26
|
+
export declare class StorageSession {
|
|
27
|
+
[PrimaryKey.name]?: [string, string, string] | undefined;
|
|
28
|
+
id: string;
|
|
29
|
+
appName: string;
|
|
30
|
+
userId: string;
|
|
31
|
+
state: Record<string, unknown>;
|
|
32
|
+
createTime: Date;
|
|
33
|
+
updateTime: Date;
|
|
34
|
+
}
|
|
35
|
+
export declare class StorageEvent {
|
|
36
|
+
[PrimaryKey.name]?: [string, string, string, string] | undefined;
|
|
37
|
+
id: string;
|
|
38
|
+
appName: string;
|
|
39
|
+
userId: string;
|
|
40
|
+
sessionId: string;
|
|
41
|
+
invocationId: string;
|
|
42
|
+
timestamp: Date;
|
|
43
|
+
eventData: Event;
|
|
44
|
+
}
|
|
45
|
+
export declare const ENTITIES: (typeof StorageMetadata | typeof StorageAppState | typeof StorageEvent)[];
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Event } from '../events/event.js';
|
|
2
2
|
import { AppendEventRequest, BaseSessionService, CreateSessionRequest, DeleteSessionRequest, GetSessionRequest, ListSessionsRequest, ListSessionsResponse } from './base_session_service.js';
|
|
3
3
|
import { Session } from './session.js';
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the given URI is an in-memory memory service URI.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isInMemoryConnectionString(uri?: string): boolean;
|
|
4
8
|
/**
|
|
5
9
|
* An in-memory implementation of the session service.
|
|
6
10
|
*/
|
|
@@ -23,5 +27,4 @@ export declare class InMemorySessionService extends BaseSessionService {
|
|
|
23
27
|
listSessions({ appName, userId, }: ListSessionsRequest): Promise<ListSessionsResponse>;
|
|
24
28
|
deleteSession({ appName, userId, sessionId, }: DeleteSessionRequest): Promise<void>;
|
|
25
29
|
appendEvent({ session, event, }: AppendEventRequest): Promise<Event>;
|
|
26
|
-
private mergeState;
|
|
27
30
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { Part } from '@google/genai';
|
|
7
|
-
import { BaseArtifactService, DeleteArtifactRequest, ListVersionsRequest, LoadArtifactRequest, SaveArtifactRequest } from '../artifacts/base_artifact_service.js';
|
|
7
|
+
import { ArtifactVersion, BaseArtifactService, DeleteArtifactRequest, ListVersionsRequest, LoadArtifactRequest, SaveArtifactRequest } from '../artifacts/base_artifact_service.js';
|
|
8
8
|
import { ToolContext } from './tool_context.js';
|
|
9
9
|
/**
|
|
10
10
|
* Artifact service that forwards to the parent tool context.
|
|
@@ -18,4 +18,6 @@ export declare class ForwardingArtifactService implements BaseArtifactService {
|
|
|
18
18
|
listArtifactKeys(): Promise<string[]>;
|
|
19
19
|
deleteArtifact(request: DeleteArtifactRequest): Promise<void>;
|
|
20
20
|
listVersions(request: ListVersionsRequest): Promise<number[]>;
|
|
21
|
+
listArtifactVersions(request: ListVersionsRequest): Promise<ArtifactVersion[]>;
|
|
22
|
+
getArtifactVersion(request: LoadArtifactRequest): Promise<ArtifactVersion | undefined>;
|
|
21
23
|
}
|
|
@@ -29,3 +29,10 @@ export declare function base64Decode(data: string): string;
|
|
|
29
29
|
* @return True if the string is base64-encoded, false otherwise.
|
|
30
30
|
*/
|
|
31
31
|
export declare function isBase64Encoded(data: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Gets the boolean value of the given environment variable.
|
|
34
|
+
*
|
|
35
|
+
* @param envVar The environment variable to get the value of.
|
|
36
|
+
* @return The boolean value of the environment variable.
|
|
37
|
+
*/
|
|
38
|
+
export declare function getBooleanEnvVar(envVar: string): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Converts an object with snake_case keys to camelCase keys.
|
|
8
|
+
*
|
|
9
|
+
* @param obj The object to convert.
|
|
10
|
+
* @param preserveKeys Keys to preserve in their original form.
|
|
11
|
+
* @returns The object with camelCase keys.
|
|
12
|
+
*/
|
|
13
|
+
export declare function toCamelCase(obj: unknown, preserveKeys?: string[]): unknown;
|
|
14
|
+
/**
|
|
15
|
+
* Converts an object with camelCase keys to snake_case keys.
|
|
16
|
+
*
|
|
17
|
+
* @param obj The object to convert.
|
|
18
|
+
* @param preserveKeys Keys to preserve in their original form.
|
|
19
|
+
* @returns The object with snake_case keys.
|
|
20
|
+
*/
|
|
21
|
+
export declare function toSnakeCase(obj: unknown, preserveKeys?: string[]): unknown;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
var MetadataKeys = /* @__PURE__ */ ((MetadataKeys2) => {
|
|
7
|
+
MetadataKeys2["TYPE"] = "adk_type";
|
|
8
|
+
MetadataKeys2["LONG_RUNNING"] = "adk_is_long_running";
|
|
9
|
+
MetadataKeys2["THOUGHT"] = "adk_thought";
|
|
10
|
+
return MetadataKeys2;
|
|
11
|
+
})(MetadataKeys || {});
|
|
12
|
+
var DataPartType = /* @__PURE__ */ ((DataPartType2) => {
|
|
13
|
+
DataPartType2["FUNCTION_CALL"] = "function_call";
|
|
14
|
+
DataPartType2["FUNCTION_RESPONSE"] = "function_response";
|
|
15
|
+
DataPartType2["CODE_EXEC_RESULT"] = "code_execution_result";
|
|
16
|
+
DataPartType2["CODE_EXECUTABLE_CODE"] = "executable_code";
|
|
17
|
+
return DataPartType2;
|
|
18
|
+
})(DataPartType || {});
|
|
19
|
+
function toA2AParts(parts, longRunningToolIDs = []) {
|
|
20
|
+
return parts.map((part) => toA2APart(part, longRunningToolIDs));
|
|
21
|
+
}
|
|
22
|
+
function toA2APart(part, longRunningToolIDs) {
|
|
23
|
+
if (part.text !== void 0 && part.text !== null) {
|
|
24
|
+
return toA2ATextPart(part);
|
|
25
|
+
}
|
|
26
|
+
if (part.inlineData || part.fileData) {
|
|
27
|
+
return toA2AFilePart(part);
|
|
28
|
+
}
|
|
29
|
+
return toA2ADataPart(part, longRunningToolIDs);
|
|
30
|
+
}
|
|
31
|
+
function toA2ATextPart(part) {
|
|
32
|
+
const a2aPart = { kind: "text", text: part.text || "" };
|
|
33
|
+
if ("thought" in part && part["thought"]) {
|
|
34
|
+
a2aPart.metadata = {
|
|
35
|
+
["adk_thought" /* THOUGHT */]: true
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return a2aPart;
|
|
39
|
+
}
|
|
40
|
+
function toA2AFilePart(part) {
|
|
41
|
+
if (part.fileData) {
|
|
42
|
+
return {
|
|
43
|
+
kind: "file",
|
|
44
|
+
file: {
|
|
45
|
+
uri: part.fileData.fileUri || "",
|
|
46
|
+
mimeType: part.fileData.mimeType
|
|
47
|
+
},
|
|
48
|
+
metadata: {}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (part.inlineData) {
|
|
52
|
+
return {
|
|
53
|
+
kind: "file",
|
|
54
|
+
file: {
|
|
55
|
+
bytes: part.inlineData.data || "",
|
|
56
|
+
mimeType: part.inlineData.mimeType
|
|
57
|
+
},
|
|
58
|
+
metadata: {}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
throw new Error("Not a file part: ".concat(JSON.stringify(part)));
|
|
62
|
+
}
|
|
63
|
+
function toA2ADataPart(part, longRunningToolIDs = []) {
|
|
64
|
+
let type;
|
|
65
|
+
let data;
|
|
66
|
+
if (part.functionCall) {
|
|
67
|
+
type = "function_call" /* FUNCTION_CALL */;
|
|
68
|
+
data = part.functionCall;
|
|
69
|
+
} else if (part.functionResponse) {
|
|
70
|
+
type = "function_response" /* FUNCTION_RESPONSE */;
|
|
71
|
+
data = part.functionResponse;
|
|
72
|
+
} else if (part.executableCode) {
|
|
73
|
+
type = "executable_code" /* CODE_EXECUTABLE_CODE */;
|
|
74
|
+
data = part.executableCode;
|
|
75
|
+
} else if (part.codeExecutionResult) {
|
|
76
|
+
type = "code_execution_result" /* CODE_EXEC_RESULT */;
|
|
77
|
+
data = part.codeExecutionResult;
|
|
78
|
+
} else {
|
|
79
|
+
throw new Error("Unknown part type: ".concat(JSON.stringify(part)));
|
|
80
|
+
}
|
|
81
|
+
const metadata = {
|
|
82
|
+
["adk_type" /* TYPE */]: type
|
|
83
|
+
};
|
|
84
|
+
if (part.functionCall && part.functionCall.name && longRunningToolIDs.includes(part.functionCall.name)) {
|
|
85
|
+
metadata["adk_is_long_running" /* LONG_RUNNING */] = true;
|
|
86
|
+
}
|
|
87
|
+
if (part.functionResponse && part.functionResponse.name && longRunningToolIDs.includes(part.functionResponse.name)) {
|
|
88
|
+
metadata["adk_is_long_running" /* LONG_RUNNING */] = true;
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
kind: "data",
|
|
92
|
+
data,
|
|
93
|
+
metadata
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function toGenAIParts(a2aParts) {
|
|
97
|
+
return a2aParts.map((a2aPart) => toGenAIPart(a2aPart));
|
|
98
|
+
}
|
|
99
|
+
function toGenAIPart(a2aPart) {
|
|
100
|
+
if (a2aPart.kind === "text") {
|
|
101
|
+
return toGenAIPartText(a2aPart);
|
|
102
|
+
}
|
|
103
|
+
if (a2aPart.kind === "file") {
|
|
104
|
+
return toGenAIPartFile(a2aPart);
|
|
105
|
+
}
|
|
106
|
+
if (a2aPart.kind === "data") {
|
|
107
|
+
return toGenAIPartData(a2aPart);
|
|
108
|
+
}
|
|
109
|
+
throw new Error("Unknown part kind: ".concat(JSON.stringify(a2aPart)));
|
|
110
|
+
}
|
|
111
|
+
function toGenAIPartText(a2aPart) {
|
|
112
|
+
var _a;
|
|
113
|
+
return {
|
|
114
|
+
text: a2aPart.text,
|
|
115
|
+
thought: !!((_a = a2aPart.metadata) == null ? void 0 : _a["adk_thought" /* THOUGHT */])
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function toGenAIPartFile(a2aPart) {
|
|
119
|
+
if ("bytes" in a2aPart.file) {
|
|
120
|
+
return {
|
|
121
|
+
inlineData: {
|
|
122
|
+
data: a2aPart.file.bytes,
|
|
123
|
+
mimeType: a2aPart.file.mimeType || ""
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if ("uri" in a2aPart.file) {
|
|
128
|
+
return {
|
|
129
|
+
fileData: {
|
|
130
|
+
fileUri: a2aPart.file.uri,
|
|
131
|
+
mimeType: a2aPart.file.mimeType || ""
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
throw new Error("Not a file part: ".concat(JSON.stringify(a2aPart)));
|
|
136
|
+
}
|
|
137
|
+
function toGenAIPartData(a2aPart) {
|
|
138
|
+
var _a;
|
|
139
|
+
if (!a2aPart.data) {
|
|
140
|
+
throw new Error("No data in part: ".concat(JSON.stringify(a2aPart)));
|
|
141
|
+
}
|
|
142
|
+
const data = a2aPart.data;
|
|
143
|
+
const type = (_a = a2aPart.metadata) == null ? void 0 : _a["adk_type" /* TYPE */];
|
|
144
|
+
if (type === "function_call" /* FUNCTION_CALL */) {
|
|
145
|
+
return { functionCall: data };
|
|
146
|
+
}
|
|
147
|
+
if (type === "function_response" /* FUNCTION_RESPONSE */) {
|
|
148
|
+
return { functionResponse: data };
|
|
149
|
+
}
|
|
150
|
+
if (type === "executable_code" /* CODE_EXECUTABLE_CODE */) {
|
|
151
|
+
return { executableCode: data };
|
|
152
|
+
}
|
|
153
|
+
if (type === "code_execution_result" /* CODE_EXEC_RESULT */) {
|
|
154
|
+
return { codeExecutionResult: data };
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
text: JSON.stringify(a2aPart.data)
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
export {
|
|
161
|
+
toA2ADataPart,
|
|
162
|
+
toA2AFilePart,
|
|
163
|
+
toA2APart,
|
|
164
|
+
toA2AParts,
|
|
165
|
+
toA2ATextPart,
|
|
166
|
+
toGenAIPart,
|
|
167
|
+
toGenAIPartData,
|
|
168
|
+
toGenAIPartFile,
|
|
169
|
+
toGenAIPartText,
|
|
170
|
+
toGenAIParts
|
|
171
|
+
};
|
|
@@ -311,7 +311,7 @@ class BaseAgent {
|
|
|
311
311
|
function validateAgentName(name) {
|
|
312
312
|
if (!isIdentifier(name)) {
|
|
313
313
|
throw new Error(
|
|
314
|
-
'Found invalid agent name: "'.concat(name, '". Agent name must be a valid identifier. It should start with a letter (a-z, A-Z) or an underscore (_), and can only contain letters, digits (0-9), and
|
|
314
|
+
'Found invalid agent name: "'.concat(name, '". Agent name must be a valid identifier. It should start with a letter (a-z, A-Z) or an underscore (_), and can only contain letters, digits (0-9), underscores, and hyphens.')
|
|
315
315
|
);
|
|
316
316
|
}
|
|
317
317
|
if (name === "user") {
|
|
@@ -322,7 +322,7 @@ function validateAgentName(name) {
|
|
|
322
322
|
return name;
|
|
323
323
|
}
|
|
324
324
|
function isIdentifier(str) {
|
|
325
|
-
return new RegExp("^[\\p{ID_Start}$_][\\p{ID_Continue}$_]*$", "u").test(str);
|
|
325
|
+
return new RegExp("^[\\p{ID_Start}$_][\\p{ID_Continue}$_-]*$", "u").test(str);
|
|
326
326
|
}
|
|
327
327
|
function getRootAgent(rootAgent) {
|
|
328
328
|
while (rootAgent.parentAgent) {
|