@google/adk 0.2.0 → 0.2.2

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.
Files changed (75) hide show
  1. package/README.md +1 -7
  2. package/dist/cjs/agents/base_agent.js +14 -2
  3. package/dist/cjs/agents/content_processor_utils.js +2 -2
  4. package/dist/cjs/agents/functions.js +6 -3
  5. package/dist/cjs/agents/llm_agent.js +331 -4
  6. package/dist/cjs/auth/exchanger/base_credential_exchanger.js +40 -0
  7. package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +59 -0
  8. package/dist/cjs/code_executors/code_execution_utils.js +2 -2
  9. package/dist/cjs/code_executors/code_executor_context.js +2 -2
  10. package/dist/cjs/common.js +7 -0
  11. package/dist/cjs/index.js +63 -5
  12. package/dist/cjs/index.js.map +4 -4
  13. package/dist/cjs/models/base_llm.js +16 -4
  14. package/dist/cjs/runner/runner.js +10 -1
  15. package/dist/cjs/sessions/in_memory_session_service.js +3 -3
  16. package/dist/cjs/sessions/state.js +1 -1
  17. package/dist/cjs/tools/agent_tool.js +2 -2
  18. package/dist/cjs/tools/mcp/mcp_session_manager.js +7 -1
  19. package/dist/cjs/utils/gemini_schema_util.js +16 -0
  20. package/dist/cjs/version.js +2 -2
  21. package/dist/esm/agents/base_agent.js +12 -1
  22. package/dist/esm/agents/content_processor_utils.js +2 -2
  23. package/dist/esm/agents/functions.js +6 -3
  24. package/dist/esm/agents/llm_agent.js +330 -4
  25. package/dist/esm/auth/exchanger/base_credential_exchanger.js +10 -0
  26. package/dist/esm/auth/exchanger/credential_exchanger_registry.js +29 -0
  27. package/dist/esm/code_executors/code_execution_utils.js +2 -2
  28. package/dist/esm/code_executors/code_executor_context.js +2 -2
  29. package/dist/esm/common.js +6 -2
  30. package/dist/esm/index.js +63 -5
  31. package/dist/esm/index.js.map +4 -4
  32. package/dist/esm/models/base_llm.js +14 -3
  33. package/dist/esm/runner/runner.js +10 -1
  34. package/dist/esm/sessions/in_memory_session_service.js +3 -3
  35. package/dist/esm/sessions/state.js +1 -1
  36. package/dist/esm/tools/agent_tool.js +2 -2
  37. package/dist/esm/tools/function_tool.js +3 -1
  38. package/dist/esm/tools/mcp/mcp_session_manager.js +7 -1
  39. package/dist/esm/utils/gemini_schema_util.js +16 -0
  40. package/dist/esm/version.js +2 -2
  41. package/dist/types/agents/base_agent.d.ts +15 -0
  42. package/dist/types/agents/functions.d.ts +2 -0
  43. package/dist/types/agents/llm_agent.d.ts +23 -0
  44. package/dist/types/auth/exchanger/base_credential_exchanger.d.ts +32 -0
  45. package/dist/types/auth/exchanger/credential_exchanger_registry.d.ts +28 -0
  46. package/dist/types/code_executors/code_executor_context.d.ts +0 -5
  47. package/dist/types/common.d.ts +3 -2
  48. package/dist/types/models/base_llm.d.ts +16 -0
  49. package/dist/types/sessions/in_memory_session_service.d.ts +0 -5
  50. package/dist/types/sessions/state.d.ts +2 -2
  51. package/dist/types/tools/function_tool.d.ts +3 -3
  52. package/dist/types/tools/tool_confirmation.d.ts +1 -1
  53. package/dist/types/utils/gemini_schema_util.d.ts +2 -2
  54. package/dist/types/version.d.ts +2 -2
  55. package/dist/web/agents/base_agent.js +12 -1
  56. package/dist/web/agents/content_processor_utils.js +2 -2
  57. package/dist/web/agents/functions.js +6 -3
  58. package/dist/web/agents/llm_agent.js +315 -4
  59. package/dist/web/auth/exchanger/base_credential_exchanger.js +10 -0
  60. package/dist/web/auth/exchanger/credential_exchanger_registry.js +29 -0
  61. package/dist/web/code_executors/code_execution_utils.js +2 -2
  62. package/dist/web/code_executors/code_executor_context.js +2 -2
  63. package/dist/web/common.js +6 -2
  64. package/dist/web/index.js +6 -1
  65. package/dist/web/index.js.map +4 -4
  66. package/dist/web/models/base_llm.js +14 -3
  67. package/dist/web/runner/runner.js +10 -1
  68. package/dist/web/sessions/in_memory_session_service.js +3 -3
  69. package/dist/web/sessions/state.js +1 -1
  70. package/dist/web/tools/agent_tool.js +2 -2
  71. package/dist/web/tools/function_tool.js +3 -1
  72. package/dist/web/tools/mcp/mcp_session_manager.js +7 -1
  73. package/dist/web/utils/gemini_schema_util.js +16 -0
  74. package/dist/web/version.js +2 -2
  75. package/package.json +3 -1
@@ -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 _a;
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 (((_a = llmRequest.contents[llmRequest.contents.length - 1]) == null ? void 0 : _a.role) !== "user") {
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 new_message.");
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 { deepClone } from "../utils/deep_clone.js";
6
+ import { cloneDeep } from "lodash";
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, deepClone(session))
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 = deepClone(session);
54
+ const copiedSession = cloneDeep(session);
55
55
  if (config) {
56
56
  if (config.numRecentEvents) {
57
57
  copiedSession.events = copiedSession.events.slice(-config.numRecentEvents);
@@ -20,7 +20,7 @@ var __spreadValues = (a, b) => {
20
20
  * SPDX-License-Identifier: Apache-2.0
21
21
  */
22
22
  class State {
23
- constructor(value, delta) {
23
+ constructor(value = {}, delta = {}) {
24
24
  this.value = value;
25
25
  this.delta = delta;
26
26
  }
@@ -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 mergetText = lastEvent.content.parts.map((part) => part.text).filter((text) => text).join("\n");
113
- return hasOutputSchema ? JSON.parse(mergetText) : mergetText;
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 { ZodObject } from "zod";
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) {
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2025 Google LLC
3
+ * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- const version = "0.2.0";
6
+ const version = "0.2.3";
7
7
  export {
8
8
  version
9
9
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@google/adk",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
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": "^4.17.21",
45
46
  "zod": "3.25.76"
46
47
  },
47
48
  "devDependencies": {
49
+ "@types/lodash": "^4.17.21",
48
50
  "openapi-types": "^12.1.3"
49
51
  },
50
52
  "peerDependencies": {