@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.
Files changed (183) hide show
  1. package/dist/cjs/a2a/part_converter_utils.js +210 -0
  2. package/dist/cjs/agents/active_streaming_tool.js +1 -1
  3. package/dist/cjs/agents/base_agent.js +3 -3
  4. package/dist/cjs/agents/base_llm_processor.js +1 -1
  5. package/dist/cjs/agents/callback_context.js +1 -1
  6. package/dist/cjs/agents/content_processor_utils.js +1 -1
  7. package/dist/cjs/agents/functions.js +2 -1
  8. package/dist/cjs/agents/instructions.js +1 -1
  9. package/dist/cjs/agents/invocation_context.js +1 -1
  10. package/dist/cjs/agents/live_request_queue.js +1 -1
  11. package/dist/cjs/agents/llm_agent.js +58 -40
  12. package/dist/cjs/agents/loop_agent.js +1 -1
  13. package/dist/cjs/agents/parallel_agent.js +1 -1
  14. package/dist/cjs/agents/readonly_context.js +13 -1
  15. package/dist/cjs/agents/run_config.js +2 -1
  16. package/dist/cjs/agents/sequential_agent.js +1 -1
  17. package/dist/cjs/agents/transcription_entry.js +1 -1
  18. package/dist/cjs/artifacts/base_artifact_service.js +1 -1
  19. package/dist/cjs/artifacts/file_artifact_service.js +491 -0
  20. package/dist/cjs/artifacts/gcs_artifact_service.js +127 -48
  21. package/dist/cjs/artifacts/in_memory_artifact_service.js +54 -6
  22. package/dist/cjs/artifacts/registry.js +55 -0
  23. package/dist/cjs/auth/auth_credential.js +1 -1
  24. package/dist/cjs/auth/auth_handler.js +1 -1
  25. package/dist/cjs/auth/auth_schemes.js +1 -1
  26. package/dist/cjs/auth/auth_tool.js +1 -1
  27. package/dist/cjs/auth/credential_service/base_credential_service.js +1 -1
  28. package/dist/cjs/auth/credential_service/in_memory_credential_service.js +1 -1
  29. package/dist/cjs/auth/exchanger/base_credential_exchanger.js +1 -1
  30. package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +1 -1
  31. package/dist/cjs/code_executors/base_code_executor.js +1 -1
  32. package/dist/cjs/code_executors/built_in_code_executor.js +1 -1
  33. package/dist/cjs/code_executors/code_execution_utils.js +1 -1
  34. package/dist/cjs/code_executors/code_executor_context.js +1 -1
  35. package/dist/cjs/common.js +14 -1
  36. package/dist/cjs/events/event.js +33 -4
  37. package/dist/cjs/events/event_actions.js +2 -2
  38. package/dist/cjs/events/structured_events.js +105 -0
  39. package/dist/cjs/examples/base_example_provider.js +1 -1
  40. package/dist/cjs/examples/example.js +1 -1
  41. package/dist/cjs/examples/example_util.js +1 -1
  42. package/dist/cjs/index.js +54 -83
  43. package/dist/cjs/index_web.js +1 -1
  44. package/dist/cjs/memory/base_memory_service.js +1 -1
  45. package/dist/cjs/memory/in_memory_memory_service.js +1 -1
  46. package/dist/cjs/memory/memory_entry.js +1 -1
  47. package/dist/cjs/models/apigee_llm.js +182 -0
  48. package/dist/cjs/models/base_llm.js +1 -1
  49. package/dist/cjs/models/base_llm_connection.js +1 -1
  50. package/dist/cjs/models/gemini_llm_connection.js +1 -1
  51. package/dist/cjs/models/google_llm.js +70 -51
  52. package/dist/cjs/models/llm_request.js +1 -1
  53. package/dist/cjs/models/llm_response.js +1 -1
  54. package/dist/cjs/models/registry.js +3 -1
  55. package/dist/cjs/plugins/base_plugin.js +1 -1
  56. package/dist/cjs/plugins/logging_plugin.js +1 -1
  57. package/dist/cjs/plugins/plugin_manager.js +1 -1
  58. package/dist/cjs/plugins/security_plugin.js +1 -1
  59. package/dist/cjs/runner/in_memory_runner.js +1 -1
  60. package/dist/cjs/runner/runner.js +32 -1
  61. package/dist/cjs/sessions/base_session_service.js +53 -3
  62. package/dist/cjs/sessions/database_session_service.js +364 -0
  63. package/dist/cjs/sessions/db/operations.js +114 -0
  64. package/dist/cjs/sessions/db/schema.js +204 -0
  65. package/dist/cjs/sessions/in_memory_session_service.js +24 -22
  66. package/dist/cjs/sessions/registry.js +49 -0
  67. package/dist/cjs/sessions/session.js +1 -1
  68. package/dist/cjs/sessions/state.js +1 -1
  69. package/dist/cjs/telemetry/google_cloud.js +1 -1
  70. package/dist/cjs/telemetry/setup.js +1 -1
  71. package/dist/cjs/telemetry/tracing.js +1 -1
  72. package/dist/cjs/tools/agent_tool.js +1 -1
  73. package/dist/cjs/tools/base_tool.js +1 -1
  74. package/dist/cjs/tools/base_toolset.js +1 -1
  75. package/dist/cjs/tools/forwarding_artifact_service.js +17 -1
  76. package/dist/cjs/tools/function_tool.js +1 -1
  77. package/dist/cjs/tools/google_search_tool.js +1 -1
  78. package/dist/cjs/tools/long_running_tool.js +1 -1
  79. package/dist/cjs/tools/mcp/mcp_session_manager.js +1 -1
  80. package/dist/cjs/tools/mcp/mcp_tool.js +1 -1
  81. package/dist/cjs/tools/mcp/mcp_toolset.js +1 -1
  82. package/dist/cjs/tools/tool_confirmation.js +1 -1
  83. package/dist/cjs/tools/tool_context.js +1 -1
  84. package/dist/cjs/utils/client_labels.js +1 -1
  85. package/dist/cjs/utils/env_aware_utils.js +10 -1
  86. package/dist/cjs/utils/gemini_schema_util.js +1 -1
  87. package/dist/cjs/utils/logger.js +1 -1
  88. package/dist/cjs/utils/model_name.js +1 -1
  89. package/dist/cjs/utils/object_notation_utils.js +78 -0
  90. package/dist/cjs/utils/simple_zod_to_json.js +1 -1
  91. package/dist/cjs/utils/variant_utils.js +3 -9
  92. package/dist/cjs/version.js +2 -2
  93. package/dist/esm/a2a/part_converter_utils.js +171 -0
  94. package/dist/esm/agents/base_agent.js +2 -2
  95. package/dist/esm/agents/functions.js +1 -0
  96. package/dist/esm/agents/llm_agent.js +58 -40
  97. package/dist/esm/agents/readonly_context.js +12 -0
  98. package/dist/esm/agents/run_config.js +1 -0
  99. package/dist/esm/artifacts/file_artifact_service.js +451 -0
  100. package/dist/esm/artifacts/gcs_artifact_service.js +126 -47
  101. package/dist/esm/artifacts/in_memory_artifact_service.js +51 -4
  102. package/dist/esm/artifacts/registry.js +28 -0
  103. package/dist/esm/common.js +9 -1
  104. package/dist/esm/events/event.js +29 -2
  105. package/dist/esm/events/event_actions.js +1 -1
  106. package/dist/esm/events/structured_events.js +74 -0
  107. package/dist/esm/index.js +18 -88
  108. package/dist/esm/models/apigee_llm.js +152 -0
  109. package/dist/esm/models/google_llm.js +67 -49
  110. package/dist/esm/models/registry.js +2 -0
  111. package/dist/esm/runner/runner.js +31 -0
  112. package/dist/esm/sessions/base_session_service.js +49 -1
  113. package/dist/esm/sessions/database_session_service.js +350 -0
  114. package/dist/esm/sessions/db/operations.js +87 -0
  115. package/dist/esm/sessions/db/schema.js +172 -0
  116. package/dist/esm/sessions/in_memory_session_service.js +23 -21
  117. package/dist/esm/sessions/registry.js +25 -0
  118. package/dist/esm/tools/forwarding_artifact_service.js +16 -0
  119. package/dist/esm/utils/env_aware_utils.js +8 -0
  120. package/dist/esm/utils/object_notation_utils.js +47 -0
  121. package/dist/esm/utils/variant_utils.js +1 -7
  122. package/dist/esm/version.js +1 -1
  123. package/dist/types/a2a/part_converter_utils.d.ts +47 -0
  124. package/dist/types/agents/llm_agent.d.ts +11 -11
  125. package/dist/types/agents/readonly_context.d.ts +8 -0
  126. package/dist/types/agents/run_config.d.ts +6 -0
  127. package/dist/types/artifacts/base_artifact_service.d.ts +31 -0
  128. package/dist/types/artifacts/file_artifact_service.d.ts +43 -0
  129. package/dist/types/artifacts/gcs_artifact_service.d.ts +3 -1
  130. package/dist/types/artifacts/in_memory_artifact_service.d.ts +5 -2
  131. package/dist/types/artifacts/registry.d.ts +7 -0
  132. package/dist/types/common.d.ts +11 -2
  133. package/dist/types/events/event.d.ts +15 -1
  134. package/dist/types/events/event_actions.d.ts +1 -1
  135. package/dist/types/events/structured_events.d.ts +106 -0
  136. package/dist/types/index.d.ts +5 -1
  137. package/dist/types/models/apigee_llm.d.ts +59 -0
  138. package/dist/types/models/google_llm.d.ts +5 -2
  139. package/dist/types/runner/runner.d.ts +15 -0
  140. package/dist/types/sessions/base_session_service.d.ts +20 -0
  141. package/dist/types/sessions/database_session_service.d.ts +31 -0
  142. package/dist/types/sessions/db/operations.d.ts +29 -0
  143. package/dist/types/sessions/db/schema.d.ts +45 -0
  144. package/dist/types/sessions/in_memory_session_service.d.ts +4 -1
  145. package/dist/types/sessions/registry.d.ts +7 -0
  146. package/dist/types/tools/forwarding_artifact_service.d.ts +3 -1
  147. package/dist/types/utils/env_aware_utils.d.ts +7 -0
  148. package/dist/types/utils/object_notation_utils.d.ts +21 -0
  149. package/dist/types/version.d.ts +1 -1
  150. package/dist/web/a2a/part_converter_utils.js +171 -0
  151. package/dist/web/agents/base_agent.js +2 -2
  152. package/dist/web/agents/functions.js +1 -0
  153. package/dist/web/agents/llm_agent.js +79 -59
  154. package/dist/web/agents/readonly_context.js +12 -0
  155. package/dist/web/agents/run_config.js +2 -1
  156. package/dist/web/artifacts/file_artifact_service.js +506 -0
  157. package/dist/web/artifacts/gcs_artifact_service.js +123 -46
  158. package/dist/web/artifacts/in_memory_artifact_service.js +51 -4
  159. package/dist/web/artifacts/registry.js +28 -0
  160. package/dist/web/common.js +9 -1
  161. package/dist/web/events/event.js +29 -2
  162. package/dist/web/events/event_actions.js +1 -1
  163. package/dist/web/events/structured_events.js +74 -0
  164. package/dist/web/index.js +18 -8
  165. package/dist/web/models/apigee_llm.js +219 -0
  166. package/dist/web/models/google_llm.js +67 -46
  167. package/dist/web/models/registry.js +2 -0
  168. package/dist/web/runner/runner.js +33 -0
  169. package/dist/web/sessions/base_session_service.js +49 -1
  170. package/dist/web/sessions/database_session_service.js +368 -0
  171. package/dist/web/sessions/db/operations.js +87 -0
  172. package/dist/web/sessions/db/schema.js +172 -0
  173. package/dist/web/sessions/in_memory_session_service.js +23 -21
  174. package/dist/web/sessions/registry.js +25 -0
  175. package/dist/web/tools/forwarding_artifact_service.js +16 -0
  176. package/dist/web/utils/env_aware_utils.js +8 -0
  177. package/dist/web/utils/object_notation_utils.js +47 -0
  178. package/dist/web/utils/variant_utils.js +1 -7
  179. package/dist/web/version.js +1 -1
  180. package/package.json +13 -4
  181. package/dist/cjs/index.js.map +0 -7
  182. package/dist/esm/index.js.map +0 -7
  183. package/dist/web/index.js.map +0 -7
@@ -24,11 +24,15 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
24
  */
25
25
  import { Storage } from "@google-cloud/storage";
26
26
  import { createPartFromBase64, createPartFromText } from "@google/genai";
27
+ import { logger } from "../utils/logger.js";
27
28
  class GcsArtifactService {
28
29
  constructor(bucket) {
29
30
  this.bucket = new Storage().bucket(bucket);
30
31
  }
31
32
  async saveArtifact(request) {
33
+ if (!request.artifact.inlineData && !request.artifact.text) {
34
+ throw new Error("Artifact must have either inlineData or text content.");
35
+ }
32
36
  const versions = await this.listVersions(request);
33
37
  const version = versions.length > 0 ? Math.max(...versions) + 1 : 0;
34
38
  const file = this.bucket.file(
@@ -36,61 +40,68 @@ class GcsArtifactService {
36
40
  version
37
41
  }))
38
42
  );
43
+ const metadata = request.customMetadata || {};
39
44
  if (request.artifact.inlineData) {
40
- await file.save(JSON.stringify(request.artifact.inlineData.data), {
41
- contentType: request.artifact.inlineData.mimeType
42
- });
43
- return version;
44
- }
45
- if (request.artifact.text) {
46
- await file.save(request.artifact.text, {
47
- contentType: "text/plain"
48
- });
45
+ await file.save(
46
+ Buffer.from(request.artifact.inlineData.data || "", "base64"),
47
+ {
48
+ contentType: request.artifact.inlineData.mimeType,
49
+ metadata
50
+ }
51
+ );
49
52
  return version;
50
53
  }
51
- throw new Error("Artifact must have either inlineData or text.");
54
+ await file.save(request.artifact.text, {
55
+ contentType: "text/plain",
56
+ metadata
57
+ });
58
+ return version;
52
59
  }
53
60
  async loadArtifact(request) {
54
- let version = request.version;
55
- if (version === void 0) {
56
- const versions = await this.listVersions(request);
57
- if (versions.length === 0) {
58
- return void 0;
61
+ try {
62
+ let version = request.version;
63
+ if (version === void 0) {
64
+ const versions = await this.listVersions(request);
65
+ if (versions.length === 0) {
66
+ return void 0;
67
+ }
68
+ version = Math.max(...versions);
59
69
  }
60
- version = Math.max(...versions);
61
- }
62
- const file = this.bucket.file(
63
- getFileName(__spreadProps(__spreadValues({}, request), {
64
- version
65
- }))
66
- );
67
- const [[metadata], [rawDataBuffer]] = await Promise.all([
68
- file.getMetadata(),
69
- file.download()
70
- ]);
71
- if (metadata.contentType === "text/plain") {
72
- return createPartFromText(rawDataBuffer.toString("utf-8"));
70
+ const file = this.bucket.file(
71
+ getFileName(__spreadProps(__spreadValues({}, request), {
72
+ version
73
+ }))
74
+ );
75
+ const [[metadata], [rawDataBuffer]] = await Promise.all([
76
+ file.getMetadata(),
77
+ file.download()
78
+ ]);
79
+ if (metadata.contentType === "text/plain") {
80
+ return createPartFromText(rawDataBuffer.toString("utf-8"));
81
+ }
82
+ return createPartFromBase64(
83
+ rawDataBuffer.toString("base64"),
84
+ metadata.contentType
85
+ );
86
+ } catch (e) {
87
+ logger.warn(
88
+ "[GcsArtifactService] loadArtifact: Failed to load artifact ".concat(request.filename),
89
+ e
90
+ );
91
+ return void 0;
73
92
  }
74
- return createPartFromBase64(
75
- rawDataBuffer.toString("base64"),
76
- metadata.contentType
77
- );
78
93
  }
79
94
  async listArtifactKeys(request) {
80
- const fileNames = [];
81
95
  const sessionPrefix = "".concat(request.appName, "/").concat(request.userId, "/").concat(request.sessionId, "/");
82
96
  const usernamePrefix = "".concat(request.appName, "/").concat(request.userId, "/user/");
83
97
  const [[sessionFiles], [userSessionFiles]] = await Promise.all([
84
98
  this.bucket.getFiles({ prefix: sessionPrefix }),
85
99
  this.bucket.getFiles({ prefix: usernamePrefix })
86
100
  ]);
87
- for (const file of sessionFiles) {
88
- fileNames.push(file.name.split("/").pop());
89
- }
90
- for (const file of userSessionFiles) {
91
- fileNames.push(file.name.split("/").pop());
92
- }
93
- return fileNames.sort((a, b) => a.localeCompare(b));
101
+ return [
102
+ ...extractArtifactKeys(sessionFiles, sessionPrefix),
103
+ ...extractArtifactKeys(userSessionFiles, usernamePrefix, "user:")
104
+ ].sort((a, b) => a.localeCompare(b));
94
105
  }
95
106
  async deleteArtifact(request) {
96
107
  const versions = await this.listVersions(request);
@@ -108,13 +119,60 @@ class GcsArtifactService {
108
119
  }
109
120
  async listVersions(request) {
110
121
  const prefix = getFileName(request);
111
- const [files] = await this.bucket.getFiles({ prefix });
122
+ const searchPrefix = prefix + "/";
123
+ const [files] = await this.bucket.getFiles({ prefix: searchPrefix });
112
124
  const versions = [];
113
125
  for (const file of files) {
114
126
  const version = file.name.split("/").pop();
115
- versions.push(parseInt(version, 10));
127
+ const v = parseInt(version, 10);
128
+ if (!isNaN(v)) {
129
+ versions.push(v);
130
+ }
131
+ }
132
+ return versions.sort((a, b) => a - b);
133
+ }
134
+ async listArtifactVersions(request) {
135
+ const versions = await this.listVersions(request);
136
+ const artifactVersions = [];
137
+ for (const version of versions) {
138
+ const artifactVersion = await this.getArtifactVersion(__spreadProps(__spreadValues({}, request), {
139
+ version
140
+ }));
141
+ if (artifactVersion) {
142
+ artifactVersions.push(artifactVersion);
143
+ }
144
+ }
145
+ return artifactVersions;
146
+ }
147
+ async getArtifactVersion(request) {
148
+ try {
149
+ let version = request.version;
150
+ if (version === void 0) {
151
+ const versions = await this.listVersions(request);
152
+ if (versions.length === 0) {
153
+ return void 0;
154
+ }
155
+ version = Math.max(...versions);
156
+ }
157
+ const file = this.bucket.file(
158
+ getFileName(__spreadProps(__spreadValues({}, request), {
159
+ version
160
+ }))
161
+ );
162
+ const [metadata] = await file.getMetadata();
163
+ return {
164
+ version,
165
+ mimeType: metadata.contentType,
166
+ customMetadata: metadata.metadata,
167
+ canonicalUri: file.publicUrl()
168
+ };
169
+ } catch (e) {
170
+ logger.warn(
171
+ "[GcsArtifactService] getArtifactVersion: Failed to get artifact version for userId: ".concat(request.userId, " sessionId: ").concat(request.sessionId, " filename: ").concat(request.filename, " version: ").concat(request.version),
172
+ e
173
+ );
174
+ return void 0;
116
175
  }
117
- return versions;
118
176
  }
119
177
  }
120
178
  function getFileName({
@@ -124,10 +182,29 @@ function getFileName({
124
182
  filename,
125
183
  version
126
184
  }) {
127
- if (filename.startsWith("user:")) {
128
- return "".concat(appName, "/").concat(userId, "/user/").concat(filename, "/").concat(version);
185
+ const isUser = filename.startsWith("user:");
186
+ const cleanFilename = isUser ? filename.substring(5) : filename;
187
+ const prefix = isUser ? "".concat(appName, "/").concat(userId, "/user/").concat(cleanFilename) : "".concat(appName, "/").concat(userId, "/").concat(sessionId, "/").concat(cleanFilename);
188
+ return version !== void 0 ? "".concat(prefix, "/").concat(version) : prefix;
189
+ }
190
+ function extractArtifactKeys(files, fileNamePrefix, keyPrefix = "") {
191
+ const keys = /* @__PURE__ */ new Set();
192
+ for (const file of files) {
193
+ if (!file.name.startsWith(fileNamePrefix)) {
194
+ continue;
195
+ }
196
+ const relative = file.name.substring(fileNamePrefix.length);
197
+ const name = getFileNameFromPath(relative);
198
+ keys.add("".concat(keyPrefix).concat(name));
199
+ }
200
+ return [...keys];
201
+ }
202
+ function getFileNameFromPath(filePath) {
203
+ const parts = filePath.split("/");
204
+ if (parts.length < 2) {
205
+ return filePath;
129
206
  }
130
- return "".concat(appName, "/").concat(userId, "/").concat(sessionId, "/").concat(filename, "/").concat(version);
207
+ return parts.slice(0, -1).join("/");
131
208
  }
132
209
  export {
133
210
  GcsArtifactService
@@ -3,6 +3,9 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ function isInMemoryConnectionString(uri) {
7
+ return uri === "memory://";
8
+ }
6
9
  class InMemoryArtifactService {
7
10
  constructor() {
8
11
  this.artifacts = {};
@@ -12,14 +15,24 @@ class InMemoryArtifactService {
12
15
  userId,
13
16
  sessionId,
14
17
  filename,
15
- artifact
18
+ artifact,
19
+ customMetadata
16
20
  }) {
21
+ if (!artifact.inlineData && !artifact.text) {
22
+ return Promise.reject(
23
+ new Error("Artifact must have either inlineData or text content.")
24
+ );
25
+ }
17
26
  const path = artifactPath(appName, userId, sessionId, filename);
18
27
  if (!this.artifacts[path]) {
19
28
  this.artifacts[path] = [];
20
29
  }
21
30
  const version = this.artifacts[path].length;
22
- this.artifacts[path].push(artifact);
31
+ const metadata = {
32
+ version,
33
+ customMetadata
34
+ };
35
+ this.artifacts[path].push({ part: artifact, metadata });
23
36
  return Promise.resolve(version);
24
37
  }
25
38
  loadArtifact({
@@ -37,7 +50,7 @@ class InMemoryArtifactService {
37
50
  if (version === void 0) {
38
51
  version = versions.length - 1;
39
52
  }
40
- return Promise.resolve(versions[version]);
53
+ return Promise.resolve(versions[version].part);
41
54
  }
42
55
  listArtifactKeys({
43
56
  appName,
@@ -88,6 +101,39 @@ class InMemoryArtifactService {
88
101
  }
89
102
  return Promise.resolve(versions);
90
103
  }
104
+ listArtifactVersions({
105
+ appName,
106
+ userId,
107
+ sessionId,
108
+ filename
109
+ }) {
110
+ const path = artifactPath(appName, userId, sessionId, filename);
111
+ const artifacts = this.artifacts[path];
112
+ if (!artifacts) {
113
+ return Promise.resolve([]);
114
+ }
115
+ return Promise.resolve(artifacts.map((a) => a.metadata));
116
+ }
117
+ getArtifactVersion({
118
+ appName,
119
+ userId,
120
+ sessionId,
121
+ filename,
122
+ version
123
+ }) {
124
+ const path = artifactPath(appName, userId, sessionId, filename);
125
+ const versions = this.artifacts[path];
126
+ if (!versions) {
127
+ return Promise.resolve(void 0);
128
+ }
129
+ if (version === void 0) {
130
+ version = versions.length - 1;
131
+ }
132
+ if (versions[version]) {
133
+ return Promise.resolve(versions[version].metadata);
134
+ }
135
+ return Promise.resolve(void 0);
136
+ }
91
137
  }
92
138
  function artifactPath(appName, userId, sessionId, filename) {
93
139
  if (fileHasUserNamespace(filename)) {
@@ -99,5 +145,6 @@ function fileHasUserNamespace(filename) {
99
145
  return filename.startsWith("user:");
100
146
  }
101
147
  export {
102
- InMemoryArtifactService
148
+ InMemoryArtifactService,
149
+ isInMemoryConnectionString
103
150
  };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { FileArtifactService } from "./file_artifact_service.js";
7
+ import { GcsArtifactService } from "./gcs_artifact_service.js";
8
+ import {
9
+ InMemoryArtifactService,
10
+ isInMemoryConnectionString
11
+ } from "./in_memory_artifact_service.js";
12
+ function getArtifactServiceFromUri(uri) {
13
+ if (isInMemoryConnectionString(uri)) {
14
+ return new InMemoryArtifactService();
15
+ }
16
+ if (uri.startsWith("gs://")) {
17
+ const bucket = uri.split("://")[1];
18
+ return new GcsArtifactService(bucket);
19
+ }
20
+ if (uri.startsWith("file://")) {
21
+ const rootDir = uri.split("://")[1];
22
+ return new FileArtifactService(rootDir);
23
+ }
24
+ throw new Error("Unsupported artifact service URI: ".concat(uri));
25
+ }
26
+ export {
27
+ getArtifactServiceFromUri
28
+ };
@@ -32,13 +32,15 @@ import {
32
32
  stringifyContent
33
33
  } from "./events/event.js";
34
34
  import { createEventActions } from "./events/event_actions.js";
35
+ import { EventType, toStructuredEvents } from "./events/structured_events.js";
35
36
  import {
36
37
  BaseExampleProvider,
37
38
  isBaseExampleProvider
38
39
  } from "./examples/base_example_provider.js";
39
40
  import { InMemoryMemoryService } from "./memory/in_memory_memory_service.js";
41
+ import { ApigeeLlm } from "./models/apigee_llm.js";
40
42
  import { BaseLlm, isBaseLlm } from "./models/base_llm.js";
41
- import { Gemini } from "./models/google_llm.js";
43
+ import { Gemini, geminiInitParams } from "./models/google_llm.js";
42
44
  import { LLMRegistry } from "./models/registry.js";
43
45
  import { BasePlugin } from "./plugins/base_plugin.js";
44
46
  import { LoggingPlugin } from "./plugins/logging_plugin.js";
@@ -52,6 +54,7 @@ import {
52
54
  } from "./plugins/security_plugin.js";
53
55
  import { InMemoryRunner } from "./runner/in_memory_runner.js";
54
56
  import { Runner } from "./runner/runner.js";
57
+ import { BaseSessionService } from "./sessions/base_session_service.js";
55
58
  import { InMemorySessionService } from "./sessions/in_memory_session_service.js";
56
59
  import { createSession } from "./sessions/session.js";
57
60
  import { State } from "./sessions/state.js";
@@ -75,6 +78,7 @@ export * from "./tools/base_tool.js";
75
78
  export {
76
79
  ActiveStreamingTool,
77
80
  AgentTool,
81
+ ApigeeLlm,
78
82
  AuthCredentialTypes,
79
83
  BaseAgent,
80
84
  BaseCodeExecutor,
@@ -83,10 +87,12 @@ export {
83
87
  BaseLlmRequestProcessor,
84
88
  BaseLlmResponseProcessor,
85
89
  BasePlugin,
90
+ BaseSessionService,
86
91
  BaseTool,
87
92
  BaseToolset,
88
93
  BuiltInCodeExecutor,
89
94
  CallbackContext,
95
+ EventType,
90
96
  FunctionTool,
91
97
  GOOGLE_SEARCH,
92
98
  Gemini,
@@ -121,6 +127,7 @@ export {
121
127
  createEventActions,
122
128
  createSession,
123
129
  functionsExportedForTestingOnly,
130
+ geminiInitParams,
124
131
  getAskUserConfirmationFunctionCalls,
125
132
  getFunctionCalls,
126
133
  getFunctionResponses,
@@ -141,6 +148,7 @@ export {
141
148
  setLogLevel,
142
149
  setLogger,
143
150
  stringifyContent,
151
+ toStructuredEvents,
144
152
  version,
145
153
  zodObjectToSchema
146
154
  };
@@ -19,9 +19,10 @@ var __spreadValues = (a, b) => {
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  /**
21
21
  * @license
22
- * Copyright 2025 Google LLC
22
+ * Copyright 2026 Google LLC
23
23
  * SPDX-License-Identifier: Apache-2.0
24
24
  */
25
+ import { toCamelCase, toSnakeCase } from "../utils/object_notation_utils.js";
25
26
  import { createEventActions } from "./event_actions.js";
26
27
  function createEvent(params = {}) {
27
28
  return __spreadProps(__spreadValues({}, params), {
@@ -88,6 +89,30 @@ function createNewEventId() {
88
89
  }
89
90
  return id;
90
91
  }
92
+ const PRESERVE_KEYS_CAMEL_CASE = [
93
+ "actions.stateDelta",
94
+ "actions.artifactDelta",
95
+ "actions.requestedAuthConfigs",
96
+ "actions.requestedToolConfirmations",
97
+ "actions.customMetadata",
98
+ "content.parts.functionCall.args",
99
+ "content.parts.functionResponse.response"
100
+ ];
101
+ const PRESERVE_KEYS_SNAKE_CASE = [
102
+ "actions.state_delta",
103
+ "actions.artifact_delta",
104
+ "actions.requested_auth_configs",
105
+ "actions.requested_tool_confirmations",
106
+ "actions.custom_metadata",
107
+ "content.parts.function_call.args",
108
+ "content.parts.function_response.response"
109
+ ];
110
+ function transformToCamelCaseEvent(event) {
111
+ return toCamelCase(event, PRESERVE_KEYS_SNAKE_CASE);
112
+ }
113
+ function transformToSnakeCaseEvent(event) {
114
+ return toSnakeCase(event, PRESERVE_KEYS_CAMEL_CASE);
115
+ }
91
116
  export {
92
117
  createEvent,
93
118
  createNewEventId,
@@ -95,5 +120,7 @@ export {
95
120
  getFunctionResponses,
96
121
  hasTrailingCodeExecutionResult,
97
122
  isFinalResponse,
98
- stringifyContent
123
+ stringifyContent,
124
+ transformToCamelCaseEvent,
125
+ transformToSnakeCaseEvent
99
126
  };
@@ -16,7 +16,7 @@ var __spreadValues = (a, b) => {
16
16
  };
17
17
  /**
18
18
  * @license
19
- * Copyright 2025 Google LLC
19
+ * Copyright 2026 Google LLC
20
20
  * SPDX-License-Identifier: Apache-2.0
21
21
  */
22
22
  function createEventActions(state = {}) {
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { isEmpty } from "lodash-es";
7
+ import { isFinalResponse } from "./event.js";
8
+ var EventType = /* @__PURE__ */ ((EventType2) => {
9
+ EventType2["THOUGHT"] = "thought";
10
+ EventType2["CONTENT"] = "content";
11
+ EventType2["TOOL_CALL"] = "tool_call";
12
+ EventType2["TOOL_RESULT"] = "tool_result";
13
+ EventType2["CALL_CODE"] = "call_code";
14
+ EventType2["CODE_RESULT"] = "code_result";
15
+ EventType2["ERROR"] = "error";
16
+ EventType2["ACTIVITY"] = "activity";
17
+ EventType2["TOOL_CONFIRMATION"] = "tool_confirmation";
18
+ EventType2["FINISHED"] = "finished";
19
+ return EventType2;
20
+ })(EventType || {});
21
+ function toStructuredEvents(event) {
22
+ var _a, _b;
23
+ const structuredEvents = [];
24
+ if (event.errorCode) {
25
+ structuredEvents.push({
26
+ type: "error" /* ERROR */,
27
+ error: new Error(event.errorMessage || event.errorCode)
28
+ });
29
+ return structuredEvents;
30
+ }
31
+ for (const part of (_b = (_a = event.content) == null ? void 0 : _a.parts) != null ? _b : []) {
32
+ if (part.functionCall && !isEmpty(part.functionCall)) {
33
+ structuredEvents.push({
34
+ type: "tool_call" /* TOOL_CALL */,
35
+ call: part.functionCall
36
+ });
37
+ } else if (part.functionResponse && !isEmpty(part.functionResponse)) {
38
+ structuredEvents.push({
39
+ type: "tool_result" /* TOOL_RESULT */,
40
+ result: part.functionResponse
41
+ });
42
+ } else if (part.executableCode && !isEmpty(part.executableCode)) {
43
+ structuredEvents.push({
44
+ type: "call_code" /* CALL_CODE */,
45
+ code: part.executableCode
46
+ });
47
+ } else if (part.codeExecutionResult && !isEmpty(part.codeExecutionResult)) {
48
+ structuredEvents.push({
49
+ type: "code_result" /* CODE_RESULT */,
50
+ result: part.codeExecutionResult
51
+ });
52
+ } else if (part.text) {
53
+ if (part.thought) {
54
+ structuredEvents.push({ type: "thought" /* THOUGHT */, content: part.text });
55
+ } else {
56
+ structuredEvents.push({ type: "content" /* CONTENT */, content: part.text });
57
+ }
58
+ }
59
+ }
60
+ if (event.actions.requestedToolConfirmations && !isEmpty(event.actions.requestedToolConfirmations)) {
61
+ structuredEvents.push({
62
+ type: "tool_confirmation" /* TOOL_CONFIRMATION */,
63
+ confirmations: event.actions.requestedToolConfirmations
64
+ });
65
+ }
66
+ if (isFinalResponse(event)) {
67
+ structuredEvents.push({ type: "finished" /* FINISHED */, output: void 0 });
68
+ }
69
+ return structuredEvents;
70
+ }
71
+ export {
72
+ EventType,
73
+ toStructuredEvents
74
+ };