@google/adk 0.2.1 → 0.2.3
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/agents/base_agent.js +14 -2
- package/dist/cjs/agents/content_processor_utils.js +12 -2
- package/dist/cjs/agents/functions.js +16 -3
- package/dist/cjs/agents/llm_agent.js +341 -4
- package/dist/cjs/{utils/deep_clone.js → auth/exchanger/base_credential_exchanger.js} +6 -10
- package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +59 -0
- package/dist/cjs/code_executors/built_in_code_executor.js +1 -1
- package/dist/cjs/code_executors/code_execution_utils.js +12 -2
- package/dist/cjs/code_executors/code_executor_context.js +12 -2
- package/dist/cjs/common.js +10 -0
- package/dist/cjs/index.js +58 -5
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/models/base_llm.js +16 -4
- package/dist/cjs/runner/runner.js +10 -1
- package/dist/cjs/sessions/in_memory_session_service.js +13 -3
- package/dist/cjs/sessions/state.js +1 -1
- package/dist/cjs/tools/agent_tool.js +2 -2
- package/dist/cjs/tools/mcp/mcp_session_manager.js +7 -1
- package/dist/cjs/utils/gemini_schema_util.js +16 -0
- package/dist/cjs/utils/model_name.js +24 -4
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/base_agent.js +12 -1
- package/dist/esm/agents/content_processor_utils.js +2 -2
- package/dist/esm/agents/functions.js +6 -3
- package/dist/esm/agents/llm_agent.js +330 -4
- package/dist/esm/auth/exchanger/base_credential_exchanger.js +10 -0
- package/dist/esm/auth/exchanger/credential_exchanger_registry.js +29 -0
- package/dist/esm/code_executors/built_in_code_executor.js +2 -2
- package/dist/esm/code_executors/code_execution_utils.js +2 -2
- package/dist/esm/code_executors/code_executor_context.js +2 -2
- package/dist/esm/common.js +8 -2
- package/dist/esm/index.js +58 -5
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/models/base_llm.js +14 -3
- package/dist/esm/runner/runner.js +10 -1
- package/dist/esm/sessions/in_memory_session_service.js +3 -3
- package/dist/esm/sessions/state.js +1 -1
- package/dist/esm/tools/agent_tool.js +2 -2
- package/dist/esm/tools/function_tool.js +3 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +7 -1
- package/dist/esm/utils/gemini_schema_util.js +16 -0
- package/dist/esm/utils/model_name.js +23 -3
- package/dist/esm/version.js +1 -1
- package/dist/types/agents/base_agent.d.ts +15 -0
- package/dist/types/agents/functions.d.ts +2 -0
- package/dist/types/agents/llm_agent.d.ts +23 -0
- package/dist/types/auth/exchanger/base_credential_exchanger.d.ts +32 -0
- package/dist/types/auth/exchanger/credential_exchanger_registry.d.ts +28 -0
- package/dist/types/code_executors/code_executor_context.d.ts +0 -5
- package/dist/types/common.d.ts +4 -2
- package/dist/types/models/base_llm.d.ts +16 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +0 -5
- package/dist/types/sessions/state.d.ts +2 -2
- package/dist/types/tools/function_tool.d.ts +3 -3
- package/dist/types/tools/tool_confirmation.d.ts +1 -1
- package/dist/types/utils/gemini_schema_util.d.ts +2 -2
- package/dist/types/utils/model_name.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/base_agent.js +12 -1
- package/dist/web/agents/content_processor_utils.js +2 -2
- package/dist/web/agents/functions.js +6 -3
- package/dist/web/agents/llm_agent.js +315 -4
- package/dist/web/auth/exchanger/base_credential_exchanger.js +10 -0
- package/dist/web/auth/exchanger/credential_exchanger_registry.js +29 -0
- package/dist/web/code_executors/built_in_code_executor.js +2 -2
- package/dist/web/code_executors/code_execution_utils.js +2 -2
- package/dist/web/code_executors/code_executor_context.js +2 -2
- package/dist/web/common.js +8 -2
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +4 -4
- package/dist/web/models/base_llm.js +14 -3
- package/dist/web/runner/runner.js +10 -1
- package/dist/web/sessions/in_memory_session_service.js +3 -3
- package/dist/web/sessions/state.js +1 -1
- package/dist/web/tools/agent_tool.js +2 -2
- package/dist/web/tools/function_tool.js +3 -1
- package/dist/web/tools/mcp/mcp_session_manager.js +7 -1
- package/dist/web/utils/gemini_schema_util.js +16 -0
- package/dist/web/utils/model_name.js +23 -3
- package/dist/web/version.js +1 -1
- package/package.json +3 -1
- package/dist/esm/utils/deep_clone.js +0 -14
- package/dist/types/utils/deep_clone.d.ts +0 -1
- package/dist/web/utils/deep_clone.js +0 -14
|
@@ -3,7 +3,13 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
var _a;
|
|
6
7
|
import { getClientLabels } from "../utils/client_labels.js";
|
|
8
|
+
const BASE_MODEL_SYMBOL = Symbol.for("google.adk.baseModel");
|
|
9
|
+
function isBaseLlm(obj) {
|
|
10
|
+
return typeof obj === "object" && obj !== null && BASE_MODEL_SYMBOL in obj && obj[BASE_MODEL_SYMBOL] === true;
|
|
11
|
+
}
|
|
12
|
+
_a = BASE_MODEL_SYMBOL;
|
|
7
13
|
class BaseLlm {
|
|
8
14
|
/**
|
|
9
15
|
* Creates an instance of BaseLLM.
|
|
@@ -12,6 +18,10 @@ class BaseLlm {
|
|
|
12
18
|
* gemini-1.5-flash-001.
|
|
13
19
|
*/
|
|
14
20
|
constructor({ model }) {
|
|
21
|
+
/**
|
|
22
|
+
* A unique symbol to identify BaseLlm classes.
|
|
23
|
+
*/
|
|
24
|
+
this[_a] = true;
|
|
15
25
|
this.model = model;
|
|
16
26
|
}
|
|
17
27
|
get trackingHeaders() {
|
|
@@ -28,7 +38,7 @@ class BaseLlm {
|
|
|
28
38
|
* @param llmRequest LlmRequest, the request to send to the LLM.
|
|
29
39
|
*/
|
|
30
40
|
maybeAppendUserContent(llmRequest) {
|
|
31
|
-
var
|
|
41
|
+
var _a2;
|
|
32
42
|
if (llmRequest.contents.length === 0) {
|
|
33
43
|
llmRequest.contents.push({
|
|
34
44
|
role: "user",
|
|
@@ -37,7 +47,7 @@ class BaseLlm {
|
|
|
37
47
|
]
|
|
38
48
|
});
|
|
39
49
|
}
|
|
40
|
-
if (((
|
|
50
|
+
if (((_a2 = llmRequest.contents[llmRequest.contents.length - 1]) == null ? void 0 : _a2.role) !== "user") {
|
|
41
51
|
llmRequest.contents.push({
|
|
42
52
|
role: "user",
|
|
43
53
|
parts: [{
|
|
@@ -52,5 +62,6 @@ class BaseLlm {
|
|
|
52
62
|
*/
|
|
53
63
|
BaseLlm.supportedModels = [];
|
|
54
64
|
export {
|
|
55
|
-
BaseLlm
|
|
65
|
+
BaseLlm,
|
|
66
|
+
isBaseLlm
|
|
56
67
|
};
|
|
@@ -25,6 +25,7 @@ import { trace } from "@opentelemetry/api";
|
|
|
25
25
|
import { InvocationContext, newInvocationContextId } from "../agents/invocation_context.js";
|
|
26
26
|
import { LlmAgent } from "../agents/llm_agent.js";
|
|
27
27
|
import { createRunConfig } from "../agents/run_config.js";
|
|
28
|
+
import { BuiltInCodeExecutor } from "../code_executors/built_in_code_executor.js";
|
|
28
29
|
import { createEvent, getFunctionCalls } from "../events/event.js";
|
|
29
30
|
import { createEventActions } from "../events/event_actions.js";
|
|
30
31
|
import { PluginManager } from "../plugins/plugin_manager.js";
|
|
@@ -66,6 +67,11 @@ class Runner {
|
|
|
66
67
|
try {
|
|
67
68
|
const session = yield new __await(this.sessionService.getSession({ appName: this.appName, userId, sessionId }));
|
|
68
69
|
if (!session) {
|
|
70
|
+
if (!this.appName) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
"Session lookup failed: appName must be provided in runner constructor"
|
|
73
|
+
);
|
|
74
|
+
}
|
|
69
75
|
throw new Error("Session not found: ".concat(sessionId));
|
|
70
76
|
}
|
|
71
77
|
if (runConfig.supportCfc && this.agent instanceof LlmAgent) {
|
|
@@ -74,6 +80,9 @@ class Runner {
|
|
|
74
80
|
throw new Error("CFC is not supported for model: ".concat(modelName, " in agent: ").concat(this.agent.name));
|
|
75
81
|
}
|
|
76
82
|
}
|
|
83
|
+
if (this.agent instanceof LlmAgent && !(this.agent.codeExecutor instanceof BuiltInCodeExecutor)) {
|
|
84
|
+
this.agent.codeExecutor = new BuiltInCodeExecutor();
|
|
85
|
+
}
|
|
77
86
|
const invocationContext = new InvocationContext({
|
|
78
87
|
artifactService: this.artifactService,
|
|
79
88
|
sessionService: this.sessionService,
|
|
@@ -95,7 +104,7 @@ class Runner {
|
|
|
95
104
|
}
|
|
96
105
|
if (newMessage) {
|
|
97
106
|
if (!((_a = newMessage.parts) == null ? void 0 : _a.length)) {
|
|
98
|
-
throw new Error("No parts in the
|
|
107
|
+
throw new Error("No parts in the newMessage.");
|
|
99
108
|
}
|
|
100
109
|
if (runConfig.saveInputBlobsAsArtifacts) {
|
|
101
110
|
yield new __await(this.saveArtifacts(
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import
|
|
6
|
+
import cloneDeep from "lodash-es/cloneDeep.js";
|
|
7
7
|
import { randomUUID } from "../utils/env_aware_utils.js";
|
|
8
8
|
import { logger } from "../utils/logger.js";
|
|
9
9
|
import { BaseSessionService } from "./base_session_service.js";
|
|
@@ -43,7 +43,7 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
43
43
|
}
|
|
44
44
|
this.sessions[appName][userId][session.id] = session;
|
|
45
45
|
return Promise.resolve(
|
|
46
|
-
this.mergeState(appName, userId,
|
|
46
|
+
this.mergeState(appName, userId, cloneDeep(session))
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
getSession({ appName, userId, sessionId, config }) {
|
|
@@ -51,7 +51,7 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
51
51
|
return Promise.resolve(void 0);
|
|
52
52
|
}
|
|
53
53
|
const session = this.sessions[appName][userId][sessionId];
|
|
54
|
-
const copiedSession =
|
|
54
|
+
const copiedSession = cloneDeep(session);
|
|
55
55
|
if (config) {
|
|
56
56
|
if (config.numRecentEvents) {
|
|
57
57
|
copiedSession.events = copiedSession.events.slice(-config.numRecentEvents);
|
|
@@ -109,8 +109,8 @@ class AgentTool extends BaseTool {
|
|
|
109
109
|
return "";
|
|
110
110
|
}
|
|
111
111
|
const hasOutputSchema = this.agent instanceof LlmAgent && this.agent.outputSchema;
|
|
112
|
-
const
|
|
113
|
-
return hasOutputSchema ? JSON.parse(
|
|
112
|
+
const mergedText = lastEvent.content.parts.map((part) => part.text).filter((text) => text).join("\n");
|
|
113
|
+
return hasOutputSchema ? JSON.parse(mergedText) : mergedText;
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
export {
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { Type } from "@google/genai";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
ZodObject
|
|
9
|
+
} from "zod";
|
|
8
10
|
import { isZodObject, zodObjectToSchema } from "../utils/simple_zod_to_json.js";
|
|
9
11
|
import { BaseTool } from "./base_tool.js";
|
|
10
12
|
function toSchema(parameters) {
|
|
@@ -19,8 +19,14 @@ class MCPSessionManager {
|
|
|
19
19
|
);
|
|
20
20
|
break;
|
|
21
21
|
case "StreamableHTTPConnectionParams":
|
|
22
|
+
const transportOptions = this.connectionParams.header ? {
|
|
23
|
+
requestInit: {
|
|
24
|
+
headers: this.connectionParams.header
|
|
25
|
+
}
|
|
26
|
+
} : void 0;
|
|
22
27
|
await client.connect(new StreamableHTTPClientTransport(
|
|
23
|
-
new URL(this.connectionParams.url)
|
|
28
|
+
new URL(this.connectionParams.url),
|
|
29
|
+
transportOptions
|
|
24
30
|
));
|
|
25
31
|
break;
|
|
26
32
|
default:
|
|
@@ -34,6 +34,22 @@ function toGeminiSchema(mcpSchema) {
|
|
|
34
34
|
return void 0;
|
|
35
35
|
}
|
|
36
36
|
function recursiveConvert(mcp) {
|
|
37
|
+
if (!mcp.type && mcp.anyOf && Array.isArray(mcp.anyOf)) {
|
|
38
|
+
const nonNullOption = mcp.anyOf.find((opt) => {
|
|
39
|
+
const t = opt.type;
|
|
40
|
+
return t !== "null" && t !== "NULL";
|
|
41
|
+
});
|
|
42
|
+
if (nonNullOption) {
|
|
43
|
+
mcp = nonNullOption;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!mcp.type) {
|
|
47
|
+
if (mcp.properties || mcp.$ref) {
|
|
48
|
+
mcp.type = "object";
|
|
49
|
+
} else if (mcp.items) {
|
|
50
|
+
mcp.type = "array";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
37
53
|
const geminiType = toGeminiType(mcp.type);
|
|
38
54
|
const geminiSchema = { type: geminiType, description: mcp.description };
|
|
39
55
|
if (geminiType === Type.OBJECT) {
|
|
@@ -15,17 +15,37 @@ function isGeminiModel(modelString) {
|
|
|
15
15
|
const modelName = extractModelName(modelString);
|
|
16
16
|
return modelName.startsWith("gemini-");
|
|
17
17
|
}
|
|
18
|
+
function parseVersion(versionString) {
|
|
19
|
+
if (!/^\d+(\.\d+)*$/.test(versionString)) {
|
|
20
|
+
return { valid: false, major: 0, minor: 0, patch: 0 };
|
|
21
|
+
}
|
|
22
|
+
const parts = versionString.split(".").map((part) => parseInt(part, 10));
|
|
23
|
+
return {
|
|
24
|
+
valid: true,
|
|
25
|
+
major: parts[0],
|
|
26
|
+
minor: parts.length > 1 ? parts[1] : 0,
|
|
27
|
+
patch: parts.length > 2 ? parts[2] : 0
|
|
28
|
+
};
|
|
29
|
+
}
|
|
18
30
|
function isGemini1Model(modelString) {
|
|
19
31
|
const modelName = extractModelName(modelString);
|
|
20
32
|
return modelName.startsWith("gemini-1");
|
|
21
33
|
}
|
|
22
|
-
function
|
|
34
|
+
function isGemini2OrAbove(modelString) {
|
|
35
|
+
if (!modelString) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
23
38
|
const modelName = extractModelName(modelString);
|
|
24
|
-
|
|
39
|
+
if (!modelName.startsWith("gemini-")) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const versionString = modelName.slice("gemini-".length).split("-", 1)[0];
|
|
43
|
+
const parsedVersion = parseVersion(versionString);
|
|
44
|
+
return parsedVersion.valid && parsedVersion.major >= 2;
|
|
25
45
|
}
|
|
26
46
|
export {
|
|
27
47
|
extractModelName,
|
|
28
48
|
isGemini1Model,
|
|
29
|
-
|
|
49
|
+
isGemini2OrAbove,
|
|
30
50
|
isGeminiModel
|
|
31
51
|
};
|
package/dist/web/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@google/adk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Google ADK JS",
|
|
5
5
|
"author": "Google",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -42,9 +42,11 @@
|
|
|
42
42
|
"@google/genai": "1.32.0",
|
|
43
43
|
"@modelcontextprotocol/sdk": "^1.24.0",
|
|
44
44
|
"google-auth-library": "^10.3.0",
|
|
45
|
+
"lodash-es": "^4.17.22",
|
|
45
46
|
"zod": "3.25.76"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
49
|
+
"@types/lodash-es": "^4.17.12",
|
|
48
50
|
"openapi-types": "^12.1.3"
|
|
49
51
|
},
|
|
50
52
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function deepClone<T>(obj: T): T;
|