@google/adk 2.2.0 → 2.2.1
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/event_converter_utils.js +5 -1
- package/dist/cjs/a2a/metadata_converter_utils.js +2 -1
- package/dist/cjs/common.js +18 -0
- package/dist/cjs/events/abort_events.js +135 -0
- package/dist/cjs/events/internal_metadata.js +131 -0
- package/dist/cjs/models/gemini_continuation.js +232 -0
- package/dist/cjs/plugins/debug_logging_plugin.js +653 -0
- package/dist/cjs/plugins/plugin_manager.js +1 -1
- package/dist/cjs/plugins/tool_call_integrity_plugin.js +364 -0
- package/dist/cjs/runner/runner.js +17 -3
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/event_converter_utils.js +5 -1
- package/dist/esm/a2a/metadata_converter_utils.js +2 -1
- package/dist/esm/common.js +20 -0
- package/dist/esm/events/abort_events.js +110 -0
- package/dist/esm/events/internal_metadata.js +97 -0
- package/dist/esm/models/gemini_continuation.js +205 -0
- package/dist/esm/plugins/debug_logging_plugin.js +615 -0
- package/dist/esm/plugins/plugin_manager.js +1 -1
- package/dist/esm/plugins/tool_call_integrity_plugin.js +339 -0
- package/dist/esm/runner/runner.js +20 -3
- package/dist/esm/version.js +1 -1
- package/dist/types/common.d.ts +3 -0
- package/dist/types/events/abort_events.d.ts +43 -0
- package/dist/types/events/internal_metadata.d.ts +78 -0
- package/dist/types/models/gemini_continuation.d.ts +59 -0
- package/dist/types/plugins/debug_logging_plugin.d.ts +157 -0
- package/dist/types/plugins/tool_call_integrity_plugin.d.ts +116 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index_web.js +59 -59
- package/dist/web/index_web.js.map +4 -4
- package/package.json +1 -1
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Content } from '@google/genai';
|
|
7
|
+
import { BaseAgent } from '../agents/base_agent.js';
|
|
8
|
+
import { Context } from '../agents/context.js';
|
|
9
|
+
import { InvocationContext } from '../agents/invocation_context.js';
|
|
10
|
+
import { Event } from '../events/event.js';
|
|
11
|
+
import { LlmRequest } from '../models/llm_request.js';
|
|
12
|
+
import { LlmResponse } from '../models/llm_response.js';
|
|
13
|
+
import { BaseTool } from '../tools/base_tool.js';
|
|
14
|
+
import { BasePlugin } from './base_plugin.js';
|
|
15
|
+
declare const DEBUG_LOGGING_PLUGIN_SYMBOL: unique symbol;
|
|
16
|
+
/**
|
|
17
|
+
* Options for configuring {@link DebugLoggingPlugin}.
|
|
18
|
+
*/
|
|
19
|
+
export interface DebugLoggingPluginOptions {
|
|
20
|
+
/**
|
|
21
|
+
* The name of the plugin instance.
|
|
22
|
+
* @defaultValue 'debug_logging_plugin'
|
|
23
|
+
*/
|
|
24
|
+
name?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Path to the output YAML debug file.
|
|
27
|
+
* @defaultValue 'adk_debug.yaml'
|
|
28
|
+
*/
|
|
29
|
+
outputPath?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Whether to include a session state snapshot at the end of each invocation.
|
|
32
|
+
* @defaultValue true
|
|
33
|
+
*/
|
|
34
|
+
includeSessionState?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Whether to include full system instructions in LLM request logs.
|
|
37
|
+
* @defaultValue true
|
|
38
|
+
*/
|
|
39
|
+
includeSystemInstruction?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A single debug log entry recorded during an invocation.
|
|
43
|
+
*/
|
|
44
|
+
export interface DebugEntry {
|
|
45
|
+
timestamp: string;
|
|
46
|
+
entry_type: string;
|
|
47
|
+
invocation_id?: string;
|
|
48
|
+
agent_name?: string;
|
|
49
|
+
data: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Per-invocation debug state written as a YAML document.
|
|
53
|
+
*/
|
|
54
|
+
export interface InvocationDebugState {
|
|
55
|
+
invocation_id: string;
|
|
56
|
+
session_id: string;
|
|
57
|
+
app_name: string;
|
|
58
|
+
user_id?: string;
|
|
59
|
+
start_time: string;
|
|
60
|
+
entries: DebugEntry[];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Type guard to check if an object is an instance of {@link DebugLoggingPlugin}.
|
|
64
|
+
*/
|
|
65
|
+
export declare function isDebugLoggingPlugin(obj: unknown): obj is DebugLoggingPlugin;
|
|
66
|
+
/**
|
|
67
|
+
* A plugin that captures complete debug information to a YAML file.
|
|
68
|
+
*
|
|
69
|
+
* This plugin records detailed interaction data including:
|
|
70
|
+
* - LLM requests (model, system instruction, contents, tools)
|
|
71
|
+
* - LLM responses (content, usage metadata, errors)
|
|
72
|
+
* - Function calls with arguments
|
|
73
|
+
* - Function responses with results
|
|
74
|
+
* - Events yielded from the runner
|
|
75
|
+
* - Session state at the end of each invocation
|
|
76
|
+
*
|
|
77
|
+
* Each invocation is appended to the output file as a separate YAML document
|
|
78
|
+
* (separated by `---`). Credentials, sensitive keys, `temp:`-scoped state keys,
|
|
79
|
+
* and armored private key blocks are automatically redacted to `[REDACTED]`.
|
|
80
|
+
*/
|
|
81
|
+
export declare class DebugLoggingPlugin extends BasePlugin {
|
|
82
|
+
readonly [DEBUG_LOGGING_PLUGIN_SYMBOL] = true;
|
|
83
|
+
readonly outputPath: string;
|
|
84
|
+
readonly includeSessionState: boolean;
|
|
85
|
+
readonly includeSystemInstruction: boolean;
|
|
86
|
+
private readonly invocationStates;
|
|
87
|
+
private warnedAboutOutputMode;
|
|
88
|
+
constructor(options?: DebugLoggingPluginOptions);
|
|
89
|
+
/**
|
|
90
|
+
* Exposes active invocation states for testing and inspection.
|
|
91
|
+
*/
|
|
92
|
+
getInvocationState(invocationId: string): InvocationDebugState | undefined;
|
|
93
|
+
private getTimestamp;
|
|
94
|
+
/**
|
|
95
|
+
* Serializes a Gemini `Content` object to a dictionary for YAML output.
|
|
96
|
+
*/
|
|
97
|
+
serializeContent(content: Content | null | undefined): Record<string, unknown> | null;
|
|
98
|
+
/**
|
|
99
|
+
* Safely serializes an arbitrary value to a YAML/JSON-compatible format with
|
|
100
|
+
* credential, sensitive key, and private key redaction.
|
|
101
|
+
*/
|
|
102
|
+
safeSerialize(obj: unknown, depth?: number): unknown;
|
|
103
|
+
private addEntry;
|
|
104
|
+
onUserMessageCallback({ invocationContext, userMessage, }: {
|
|
105
|
+
invocationContext: InvocationContext;
|
|
106
|
+
userMessage: Content;
|
|
107
|
+
}): Promise<Content | undefined>;
|
|
108
|
+
beforeRunCallback({ invocationContext, }: {
|
|
109
|
+
invocationContext: InvocationContext;
|
|
110
|
+
}): Promise<Content | undefined>;
|
|
111
|
+
onEventCallback({ invocationContext, event, }: {
|
|
112
|
+
invocationContext: InvocationContext;
|
|
113
|
+
event: Event;
|
|
114
|
+
}): Promise<Event | undefined>;
|
|
115
|
+
afterRunCallback({ invocationContext, }: {
|
|
116
|
+
invocationContext: InvocationContext;
|
|
117
|
+
}): Promise<void>;
|
|
118
|
+
beforeAgentCallback({ callbackContext, }: {
|
|
119
|
+
agent: BaseAgent;
|
|
120
|
+
callbackContext: Context;
|
|
121
|
+
}): Promise<Content | undefined>;
|
|
122
|
+
afterAgentCallback({ callbackContext, }: {
|
|
123
|
+
agent: BaseAgent;
|
|
124
|
+
callbackContext: Context;
|
|
125
|
+
}): Promise<Content | undefined>;
|
|
126
|
+
beforeModelCallback({ callbackContext, llmRequest, }: {
|
|
127
|
+
callbackContext: Context;
|
|
128
|
+
llmRequest: LlmRequest;
|
|
129
|
+
}): Promise<LlmResponse | undefined>;
|
|
130
|
+
afterModelCallback({ callbackContext, llmResponse, }: {
|
|
131
|
+
callbackContext: Context;
|
|
132
|
+
llmResponse: LlmResponse;
|
|
133
|
+
}): Promise<LlmResponse | undefined>;
|
|
134
|
+
onModelErrorCallback({ callbackContext, llmRequest, error, }: {
|
|
135
|
+
callbackContext: Context;
|
|
136
|
+
llmRequest: LlmRequest;
|
|
137
|
+
error: Error;
|
|
138
|
+
}): Promise<LlmResponse | undefined>;
|
|
139
|
+
beforeToolCallback({ tool, toolArgs, toolContext, }: {
|
|
140
|
+
tool: BaseTool;
|
|
141
|
+
toolArgs: Record<string, unknown>;
|
|
142
|
+
toolContext: Context;
|
|
143
|
+
}): Promise<Record<string, unknown> | undefined>;
|
|
144
|
+
afterToolCallback({ tool, toolContext, result, }: {
|
|
145
|
+
tool: BaseTool;
|
|
146
|
+
toolArgs: Record<string, unknown>;
|
|
147
|
+
toolContext: Context;
|
|
148
|
+
result: Record<string, unknown>;
|
|
149
|
+
}): Promise<Record<string, unknown> | undefined>;
|
|
150
|
+
onToolErrorCallback({ tool, toolArgs, toolContext, error, }: {
|
|
151
|
+
tool: BaseTool;
|
|
152
|
+
toolArgs: Record<string, unknown>;
|
|
153
|
+
toolContext: Context;
|
|
154
|
+
error: Error;
|
|
155
|
+
}): Promise<Record<string, unknown> | undefined>;
|
|
156
|
+
}
|
|
157
|
+
export {};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Optional HMAC integrity check for function calls stored in the session.
|
|
8
|
+
*
|
|
9
|
+
* Mirrors adk-python's `google.adk.plugins._tool_call_integrity_plugin`.
|
|
10
|
+
*/
|
|
11
|
+
import { Content } from '@google/genai';
|
|
12
|
+
import { Context } from '../agents/context.js';
|
|
13
|
+
import { InvocationContext } from '../agents/invocation_context.js';
|
|
14
|
+
import { Event } from '../events/event.js';
|
|
15
|
+
import { BaseTool } from '../tools/base_tool.js';
|
|
16
|
+
import { BasePlugin } from './base_plugin.js';
|
|
17
|
+
/** `customMetadata` key holding `{functionCallId: stamp}`. */
|
|
18
|
+
export declare const TOOL_CALL_HMAC_METADATA_KEY = "__adk_internal_fc_hmac";
|
|
19
|
+
/** A function call in the session failed its integrity check. */
|
|
20
|
+
export declare class ToolCallIntegrityError extends Error {
|
|
21
|
+
constructor(message: string);
|
|
22
|
+
}
|
|
23
|
+
/** Options for {@link ToolCallIntegrityPlugin}. */
|
|
24
|
+
export interface ToolCallIntegrityPluginOptions {
|
|
25
|
+
/**
|
|
26
|
+
* The HMAC key, or a list of keys during rotation. The first key stamps new
|
|
27
|
+
* calls; every key is accepted when verifying.
|
|
28
|
+
*/
|
|
29
|
+
secretKey: Uint8Array | readonly Uint8Array[];
|
|
30
|
+
/**
|
|
31
|
+
* Log a warning instead of throwing for function calls that have no stamp,
|
|
32
|
+
* such as calls stored before the plugin was installed. Such calls also run,
|
|
33
|
+
* so this reports tampering that removes a stamp but does not prevent it. A
|
|
34
|
+
* stamp that is present but wrong is always rejected. Defaults to `false`.
|
|
35
|
+
*/
|
|
36
|
+
allowUnstampedCalls?: boolean;
|
|
37
|
+
/** The plugin name. Defaults to `'tool_call_integrity'`. */
|
|
38
|
+
name?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Stamps function calls and verifies them before runs and tool calls.
|
|
42
|
+
*
|
|
43
|
+
* `onEventCallback` adds `"v1:" + HMAC-SHA256(key, payload)` for each function
|
|
44
|
+
* call to `event.customMetadata["__adk_internal_fc_hmac"]`, and throws
|
|
45
|
+
* {@link ToolCallIntegrityError} for a response that repeats a call ID before
|
|
46
|
+
* it is stored. `beforeRunCallback` recomputes the HMAC for every function call
|
|
47
|
+
* with an ID in the session history, answered or not, and throws when a stamp
|
|
48
|
+
* is wrong, malformed, repeated or left over from a call that no longer
|
|
49
|
+
* matches. `beforeToolCallback` lets a tool run only when every stored copy of
|
|
50
|
+
* its call verifies and the tool's name and arguments match one of them; it
|
|
51
|
+
* always refuses a call with no ID. Unstamped calls are rejected unless
|
|
52
|
+
* `allowUnstampedCalls` is set, in which case they are logged.
|
|
53
|
+
*
|
|
54
|
+
* Events without function calls are ignored. Events marked as restored are not
|
|
55
|
+
* verified, and their function calls are never executed. ADK marks events
|
|
56
|
+
* restored by `adk run --replay`, and {@link prepareRestoredEvent} marks events
|
|
57
|
+
* that your code copies. Anyone who can write to the session store can also
|
|
58
|
+
* set the marker, but `beforeToolCallback` still refuses those events' calls.
|
|
59
|
+
*
|
|
60
|
+
* `PluginManager` re-throws plugin errors as a generic `Error`; the
|
|
61
|
+
* {@link ToolCallIntegrityError} is its `cause`.
|
|
62
|
+
*
|
|
63
|
+
* Register this plugin before other plugins. `PluginManager` stops at the first
|
|
64
|
+
* `onEventCallback` that returns an event, and a later plugin must not change
|
|
65
|
+
* function calls or replace `customMetadata`.
|
|
66
|
+
*
|
|
67
|
+
* Requires the Web Crypto API (`globalThis.crypto.subtle`), available in
|
|
68
|
+
* browsers and in Node.js 19 and later.
|
|
69
|
+
*
|
|
70
|
+
* Example:
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const plugin = new ToolCallIntegrityPlugin({secretKey: keyBytes});
|
|
73
|
+
* const app = {name: 'my_app', rootAgent: agent, plugins: [plugin]};
|
|
74
|
+
*
|
|
75
|
+
* // Key rotation: stamp with the new key, accept both.
|
|
76
|
+
* new ToolCallIntegrityPlugin({secretKey: [newKeyBytes, oldKeyBytes]});
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare class ToolCallIntegrityPlugin extends BasePlugin {
|
|
80
|
+
private readonly keys;
|
|
81
|
+
private readonly allowUnstampedCalls;
|
|
82
|
+
private cryptoKeys?;
|
|
83
|
+
/**
|
|
84
|
+
* @throws {Error} If `secretKey` is empty or contains a key that is not
|
|
85
|
+
* non-empty bytes.
|
|
86
|
+
*/
|
|
87
|
+
constructor(options: ToolCallIntegrityPluginOptions);
|
|
88
|
+
/**
|
|
89
|
+
* Returns a copy with internal metadata removed and marked as restored.
|
|
90
|
+
*
|
|
91
|
+
* Use it on events that your code copies into another session, so that the
|
|
92
|
+
* history passes the integrity check. The copy only keeps the history: its
|
|
93
|
+
* function calls are never executed.
|
|
94
|
+
*
|
|
95
|
+
* @param event The event to copy. It is not modified.
|
|
96
|
+
* @returns The marked copy, ready to append to the new session.
|
|
97
|
+
*/
|
|
98
|
+
static prepareRestoredEvent(event: Event): Event;
|
|
99
|
+
private getCryptoKeys;
|
|
100
|
+
private sign;
|
|
101
|
+
/** `subtle.verify` compares in constant time. */
|
|
102
|
+
private verify;
|
|
103
|
+
private unstamped;
|
|
104
|
+
onEventCallback({ invocationContext, event, }: {
|
|
105
|
+
invocationContext: InvocationContext;
|
|
106
|
+
event: Event;
|
|
107
|
+
}): Promise<Event | undefined>;
|
|
108
|
+
beforeRunCallback({ invocationContext, }: {
|
|
109
|
+
invocationContext: InvocationContext;
|
|
110
|
+
}): Promise<Content | undefined>;
|
|
111
|
+
beforeToolCallback({ tool, toolArgs, toolContext, }: {
|
|
112
|
+
tool: BaseTool;
|
|
113
|
+
toolArgs: Record<string, unknown>;
|
|
114
|
+
toolContext: Context;
|
|
115
|
+
}): Promise<Record<string, unknown> | undefined>;
|
|
116
|
+
}
|
package/dist/types/version.d.ts
CHANGED