@paean-ai/adk 0.2.17 → 0.2.19

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 (253) hide show
  1. package/dist/cjs/index.js +3 -3
  2. package/dist/cjs/index.js.map +3 -3
  3. package/dist/esm/index.js +3 -3
  4. package/dist/esm/index.js.map +3 -3
  5. package/dist/web/index.js +1 -1
  6. package/dist/web/index.js.map +3 -3
  7. package/package.json +2 -2
  8. package/dist/cjs/agents/active_streaming_tool.js +0 -44
  9. package/dist/cjs/agents/base_agent.js +0 -245
  10. package/dist/cjs/agents/base_llm_processor.js +0 -44
  11. package/dist/cjs/agents/callback_context.js +0 -98
  12. package/dist/cjs/agents/content_processor_utils.js +0 -346
  13. package/dist/cjs/agents/functions.js +0 -424
  14. package/dist/cjs/agents/instructions.js +0 -110
  15. package/dist/cjs/agents/invocation_context.js +0 -107
  16. package/dist/cjs/agents/live_request_queue.js +0 -136
  17. package/dist/cjs/agents/llm_agent.js +0 -1247
  18. package/dist/cjs/agents/loop_agent.js +0 -68
  19. package/dist/cjs/agents/parallel_agent.js +0 -78
  20. package/dist/cjs/agents/readonly_context.js +0 -68
  21. package/dist/cjs/agents/run_config.js +0 -70
  22. package/dist/cjs/agents/sequential_agent.js +0 -84
  23. package/dist/cjs/agents/transcription_entry.js +0 -27
  24. package/dist/cjs/artifacts/base_artifact_service.js +0 -27
  25. package/dist/cjs/artifacts/gcs_artifact_service.js +0 -140
  26. package/dist/cjs/artifacts/in_memory_artifact_service.js +0 -119
  27. package/dist/cjs/auth/auth_credential.js +0 -46
  28. package/dist/cjs/auth/auth_handler.js +0 -92
  29. package/dist/cjs/auth/auth_schemes.js +0 -62
  30. package/dist/cjs/auth/auth_tool.js +0 -27
  31. package/dist/cjs/auth/credential_service/base_credential_service.js +0 -27
  32. package/dist/cjs/auth/credential_service/in_memory_credential_service.js +0 -63
  33. package/dist/cjs/auth/exchanger/base_credential_exchanger.js +0 -40
  34. package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +0 -59
  35. package/dist/cjs/code_executors/base_code_executor.js +0 -76
  36. package/dist/cjs/code_executors/built_in_code_executor.js +0 -58
  37. package/dist/cjs/code_executors/code_execution_utils.js +0 -142
  38. package/dist/cjs/code_executors/code_executor_context.js +0 -198
  39. package/dist/cjs/common.js +0 -181
  40. package/dist/cjs/events/event.js +0 -119
  41. package/dist/cjs/events/event_actions.js +0 -83
  42. package/dist/cjs/examples/base_example_provider.js +0 -40
  43. package/dist/cjs/examples/example.js +0 -27
  44. package/dist/cjs/examples/example_util.js +0 -107
  45. package/dist/cjs/index_web.js +0 -33
  46. package/dist/cjs/memory/base_memory_service.js +0 -27
  47. package/dist/cjs/memory/in_memory_memory_service.js +0 -97
  48. package/dist/cjs/memory/memory_entry.js +0 -27
  49. package/dist/cjs/models/base_llm.js +0 -95
  50. package/dist/cjs/models/base_llm_connection.js +0 -27
  51. package/dist/cjs/models/gemini_llm_connection.js +0 -132
  52. package/dist/cjs/models/google_llm.js +0 -559
  53. package/dist/cjs/models/llm_request.js +0 -82
  54. package/dist/cjs/models/llm_response.js +0 -71
  55. package/dist/cjs/models/registry.js +0 -121
  56. package/dist/cjs/plugins/base_plugin.js +0 -236
  57. package/dist/cjs/plugins/logging_plugin.js +0 -222
  58. package/dist/cjs/plugins/plugin_manager.js +0 -239
  59. package/dist/cjs/plugins/security_plugin.js +0 -153
  60. package/dist/cjs/runner/in_memory_runner.js +0 -58
  61. package/dist/cjs/runner/runner.js +0 -277
  62. package/dist/cjs/sessions/base_session_service.js +0 -71
  63. package/dist/cjs/sessions/in_memory_session_service.js +0 -184
  64. package/dist/cjs/sessions/session.js +0 -48
  65. package/dist/cjs/sessions/state.js +0 -101
  66. package/dist/cjs/telemetry/google_cloud.js +0 -85
  67. package/dist/cjs/telemetry/setup.js +0 -97
  68. package/dist/cjs/telemetry/tracing.js +0 -231
  69. package/dist/cjs/tools/agent_tool.js +0 -134
  70. package/dist/cjs/tools/base_tool.js +0 -107
  71. package/dist/cjs/tools/base_toolset.js +0 -76
  72. package/dist/cjs/tools/forwarding_artifact_service.js +0 -71
  73. package/dist/cjs/tools/function_tool.js +0 -101
  74. package/dist/cjs/tools/google_search_tool.js +0 -77
  75. package/dist/cjs/tools/long_running_tool.js +0 -63
  76. package/dist/cjs/tools/mcp/mcp_session_manager.js +0 -65
  77. package/dist/cjs/tools/mcp/mcp_tool.js +0 -65
  78. package/dist/cjs/tools/mcp/mcp_toolset.js +0 -61
  79. package/dist/cjs/tools/tool_confirmation.js +0 -49
  80. package/dist/cjs/tools/tool_context.js +0 -129
  81. package/dist/cjs/utils/client_labels.js +0 -56
  82. package/dist/cjs/utils/deep_clone.js +0 -44
  83. package/dist/cjs/utils/env_aware_utils.js +0 -83
  84. package/dist/cjs/utils/gemini_schema_util.js +0 -88
  85. package/dist/cjs/utils/logger.js +0 -121
  86. package/dist/cjs/utils/model_name.js +0 -76
  87. package/dist/cjs/utils/simple_zod_to_json.js +0 -191
  88. package/dist/cjs/utils/variant_utils.js +0 -55
  89. package/dist/cjs/version.js +0 -39
  90. package/dist/esm/agents/active_streaming_tool.js +0 -14
  91. package/dist/esm/agents/base_agent.js +0 -214
  92. package/dist/esm/agents/base_llm_processor.js +0 -13
  93. package/dist/esm/agents/callback_context.js +0 -68
  94. package/dist/esm/agents/content_processor_utils.js +0 -315
  95. package/dist/esm/agents/functions.js +0 -383
  96. package/dist/esm/agents/instructions.js +0 -80
  97. package/dist/esm/agents/invocation_context.js +0 -76
  98. package/dist/esm/agents/live_request_queue.js +0 -106
  99. package/dist/esm/agents/llm_agent.js +0 -1215
  100. package/dist/esm/agents/loop_agent.js +0 -38
  101. package/dist/esm/agents/parallel_agent.js +0 -48
  102. package/dist/esm/agents/readonly_context.js +0 -38
  103. package/dist/esm/agents/run_config.js +0 -39
  104. package/dist/esm/agents/sequential_agent.js +0 -54
  105. package/dist/esm/agents/transcription_entry.js +0 -5
  106. package/dist/esm/artifacts/base_artifact_service.js +0 -5
  107. package/dist/esm/artifacts/gcs_artifact_service.js +0 -110
  108. package/dist/esm/artifacts/in_memory_artifact_service.js +0 -89
  109. package/dist/esm/auth/auth_credential.js +0 -16
  110. package/dist/esm/auth/auth_handler.js +0 -62
  111. package/dist/esm/auth/auth_schemes.js +0 -31
  112. package/dist/esm/auth/auth_tool.js +0 -5
  113. package/dist/esm/auth/credential_service/base_credential_service.js +0 -5
  114. package/dist/esm/auth/credential_service/in_memory_credential_service.js +0 -33
  115. package/dist/esm/auth/exchanger/base_credential_exchanger.js +0 -10
  116. package/dist/esm/auth/exchanger/credential_exchanger_registry.js +0 -29
  117. package/dist/esm/code_executors/base_code_executor.js +0 -46
  118. package/dist/esm/code_executors/built_in_code_executor.js +0 -28
  119. package/dist/esm/code_executors/code_execution_utils.js +0 -108
  120. package/dist/esm/code_executors/code_executor_context.js +0 -168
  121. package/dist/esm/common.js +0 -98
  122. package/dist/esm/events/event.js +0 -83
  123. package/dist/esm/events/event_actions.js +0 -52
  124. package/dist/esm/examples/base_example_provider.js +0 -10
  125. package/dist/esm/examples/example.js +0 -5
  126. package/dist/esm/examples/example_util.js +0 -76
  127. package/dist/esm/index_web.js +0 -6
  128. package/dist/esm/memory/base_memory_service.js +0 -5
  129. package/dist/esm/memory/in_memory_memory_service.js +0 -67
  130. package/dist/esm/memory/memory_entry.js +0 -5
  131. package/dist/esm/models/base_llm.js +0 -64
  132. package/dist/esm/models/base_llm_connection.js +0 -5
  133. package/dist/esm/models/gemini_llm_connection.js +0 -102
  134. package/dist/esm/models/google_llm.js +0 -533
  135. package/dist/esm/models/llm_request.js +0 -50
  136. package/dist/esm/models/llm_response.js +0 -41
  137. package/dist/esm/models/registry.js +0 -91
  138. package/dist/esm/plugins/base_plugin.js +0 -206
  139. package/dist/esm/plugins/logging_plugin.js +0 -192
  140. package/dist/esm/plugins/plugin_manager.js +0 -209
  141. package/dist/esm/plugins/security_plugin.js +0 -119
  142. package/dist/esm/runner/in_memory_runner.js +0 -28
  143. package/dist/esm/runner/runner.js +0 -247
  144. package/dist/esm/sessions/base_session_service.js +0 -41
  145. package/dist/esm/sessions/in_memory_session_service.js +0 -154
  146. package/dist/esm/sessions/session.js +0 -18
  147. package/dist/esm/sessions/state.js +0 -71
  148. package/dist/esm/telemetry/google_cloud.js +0 -54
  149. package/dist/esm/telemetry/setup.js +0 -67
  150. package/dist/esm/telemetry/tracing.js +0 -195
  151. package/dist/esm/tools/agent_tool.js +0 -104
  152. package/dist/esm/tools/base_tool.js +0 -77
  153. package/dist/esm/tools/base_toolset.js +0 -46
  154. package/dist/esm/tools/forwarding_artifact_service.js +0 -41
  155. package/dist/esm/tools/function_tool.js +0 -71
  156. package/dist/esm/tools/google_search_tool.js +0 -47
  157. package/dist/esm/tools/long_running_tool.js +0 -33
  158. package/dist/esm/tools/mcp/mcp_session_manager.js +0 -35
  159. package/dist/esm/tools/mcp/mcp_tool.js +0 -35
  160. package/dist/esm/tools/mcp/mcp_toolset.js +0 -31
  161. package/dist/esm/tools/tool_confirmation.js +0 -19
  162. package/dist/esm/tools/tool_context.js +0 -99
  163. package/dist/esm/utils/client_labels.js +0 -26
  164. package/dist/esm/utils/deep_clone.js +0 -14
  165. package/dist/esm/utils/env_aware_utils.js +0 -49
  166. package/dist/esm/utils/gemini_schema_util.js +0 -58
  167. package/dist/esm/utils/logger.js +0 -89
  168. package/dist/esm/utils/model_name.js +0 -41
  169. package/dist/esm/utils/simple_zod_to_json.js +0 -160
  170. package/dist/esm/utils/variant_utils.js +0 -24
  171. package/dist/esm/version.js +0 -9
  172. package/dist/web/agents/active_streaming_tool.js +0 -14
  173. package/dist/web/agents/base_agent.js +0 -265
  174. package/dist/web/agents/base_llm_processor.js +0 -13
  175. package/dist/web/agents/callback_context.js +0 -68
  176. package/dist/web/agents/content_processor_utils.js +0 -315
  177. package/dist/web/agents/functions.js +0 -383
  178. package/dist/web/agents/instructions.js +0 -80
  179. package/dist/web/agents/invocation_context.js +0 -76
  180. package/dist/web/agents/live_request_queue.js +0 -124
  181. package/dist/web/agents/llm_agent.js +0 -1345
  182. package/dist/web/agents/loop_agent.js +0 -71
  183. package/dist/web/agents/parallel_agent.js +0 -83
  184. package/dist/web/agents/readonly_context.js +0 -38
  185. package/dist/web/agents/run_config.js +0 -54
  186. package/dist/web/agents/sequential_agent.js +0 -99
  187. package/dist/web/agents/transcription_entry.js +0 -5
  188. package/dist/web/artifacts/base_artifact_service.js +0 -5
  189. package/dist/web/artifacts/gcs_artifact_service.js +0 -126
  190. package/dist/web/artifacts/in_memory_artifact_service.js +0 -89
  191. package/dist/web/auth/auth_credential.js +0 -16
  192. package/dist/web/auth/auth_handler.js +0 -62
  193. package/dist/web/auth/auth_schemes.js +0 -31
  194. package/dist/web/auth/auth_tool.js +0 -5
  195. package/dist/web/auth/credential_service/base_credential_service.js +0 -5
  196. package/dist/web/auth/credential_service/in_memory_credential_service.js +0 -33
  197. package/dist/web/auth/exchanger/base_credential_exchanger.js +0 -10
  198. package/dist/web/auth/exchanger/credential_exchanger_registry.js +0 -29
  199. package/dist/web/code_executors/base_code_executor.js +0 -46
  200. package/dist/web/code_executors/built_in_code_executor.js +0 -28
  201. package/dist/web/code_executors/code_execution_utils.js +0 -105
  202. package/dist/web/code_executors/code_executor_context.js +0 -168
  203. package/dist/web/common.js +0 -98
  204. package/dist/web/events/event.js +0 -101
  205. package/dist/web/events/event_actions.js +0 -67
  206. package/dist/web/examples/base_example_provider.js +0 -10
  207. package/dist/web/examples/example.js +0 -5
  208. package/dist/web/examples/example_util.js +0 -75
  209. package/dist/web/index_web.js +0 -6
  210. package/dist/web/memory/base_memory_service.js +0 -5
  211. package/dist/web/memory/in_memory_memory_service.js +0 -67
  212. package/dist/web/memory/memory_entry.js +0 -5
  213. package/dist/web/models/base_llm.js +0 -64
  214. package/dist/web/models/base_llm_connection.js +0 -5
  215. package/dist/web/models/gemini_llm_connection.js +0 -120
  216. package/dist/web/models/google_llm.js +0 -574
  217. package/dist/web/models/llm_request.js +0 -50
  218. package/dist/web/models/llm_response.js +0 -41
  219. package/dist/web/models/registry.js +0 -91
  220. package/dist/web/plugins/base_plugin.js +0 -206
  221. package/dist/web/plugins/logging_plugin.js +0 -192
  222. package/dist/web/plugins/plugin_manager.js +0 -209
  223. package/dist/web/plugins/security_plugin.js +0 -119
  224. package/dist/web/runner/in_memory_runner.js +0 -28
  225. package/dist/web/runner/runner.js +0 -278
  226. package/dist/web/sessions/base_session_service.js +0 -41
  227. package/dist/web/sessions/in_memory_session_service.js +0 -154
  228. package/dist/web/sessions/session.js +0 -18
  229. package/dist/web/sessions/state.js +0 -87
  230. package/dist/web/telemetry/google_cloud.js +0 -54
  231. package/dist/web/telemetry/setup.js +0 -67
  232. package/dist/web/telemetry/tracing.js +0 -210
  233. package/dist/web/tools/agent_tool.js +0 -118
  234. package/dist/web/tools/base_tool.js +0 -77
  235. package/dist/web/tools/base_toolset.js +0 -46
  236. package/dist/web/tools/forwarding_artifact_service.js +0 -41
  237. package/dist/web/tools/function_tool.js +0 -71
  238. package/dist/web/tools/google_search_tool.js +0 -47
  239. package/dist/web/tools/long_running_tool.js +0 -50
  240. package/dist/web/tools/mcp/mcp_session_manager.js +0 -35
  241. package/dist/web/tools/mcp/mcp_tool.js +0 -35
  242. package/dist/web/tools/mcp/mcp_toolset.js +0 -31
  243. package/dist/web/tools/tool_confirmation.js +0 -19
  244. package/dist/web/tools/tool_context.js +0 -99
  245. package/dist/web/utils/client_labels.js +0 -26
  246. package/dist/web/utils/deep_clone.js +0 -14
  247. package/dist/web/utils/env_aware_utils.js +0 -49
  248. package/dist/web/utils/gemini_schema_util.js +0 -58
  249. package/dist/web/utils/logger.js +0 -89
  250. package/dist/web/utils/model_name.js +0 -41
  251. package/dist/web/utils/simple_zod_to_json.js +0 -174
  252. package/dist/web/utils/variant_utils.js +0 -24
  253. package/dist/web/version.js +0 -9
@@ -1,91 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import { logger } from "../utils/logger.js";
7
- import { Gemini } from "./google_llm.js";
8
- class LRUCache {
9
- constructor(maxSize) {
10
- this.maxSize = maxSize;
11
- this.cache = /* @__PURE__ */ new Map();
12
- }
13
- get(key) {
14
- const item = this.cache.get(key);
15
- if (item) {
16
- this.cache.delete(key);
17
- this.cache.set(key, item);
18
- }
19
- return item;
20
- }
21
- set(key, value) {
22
- if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
23
- const lruKey = this.cache.keys().next().value;
24
- if (lruKey !== void 0) {
25
- this.cache.delete(lruKey);
26
- }
27
- }
28
- this.cache.set(key, value);
29
- }
30
- }
31
- const _LLMRegistry = class _LLMRegistry {
32
- /**
33
- * Creates a new LLM instance.
34
- * @param model The model name.
35
- * @returns The LLM instance.
36
- */
37
- static newLlm(model) {
38
- return new (_LLMRegistry.resolve(model))({ model });
39
- }
40
- static _register(modelNameRegex, llmCls) {
41
- if (_LLMRegistry.llmRegistryDict.has(modelNameRegex)) {
42
- logger.info(
43
- `Updating LLM class for ${modelNameRegex} from ${_LLMRegistry.llmRegistryDict.get(modelNameRegex)} to ${llmCls}`
44
- );
45
- }
46
- _LLMRegistry.llmRegistryDict.set(modelNameRegex, llmCls);
47
- }
48
- /**
49
- * Registers a new LLM class.
50
- * @param llmCls The class that implements the model.
51
- */
52
- static register(llmCls) {
53
- for (const regex of llmCls.supportedModels) {
54
- _LLMRegistry._register(regex, llmCls);
55
- }
56
- }
57
- /**
58
- * Resolves the model to a BaseLlm subclass.
59
- * @param model The model name.
60
- * @returns The BaseLlm subclass.
61
- * @throws If the model is not found.
62
- */
63
- static resolve(model) {
64
- const cachedLlm = _LLMRegistry.resolveCache.get(model);
65
- if (cachedLlm) {
66
- return cachedLlm;
67
- }
68
- for (const [regex, llmClass] of _LLMRegistry.llmRegistryDict.entries()) {
69
- const pattern = new RegExp(
70
- `^${regex instanceof RegExp ? regex.source : regex}$`,
71
- regex instanceof RegExp ? regex.flags : void 0
72
- );
73
- if (pattern.test(model)) {
74
- _LLMRegistry.resolveCache.set(model, llmClass);
75
- return llmClass;
76
- }
77
- }
78
- throw new Error(`Model ${model} not found.`);
79
- }
80
- };
81
- /**
82
- * Key is the regex that matches the model name.
83
- * Value is the class that implements the model.
84
- */
85
- _LLMRegistry.llmRegistryDict = /* @__PURE__ */ new Map();
86
- _LLMRegistry.resolveCache = new LRUCache(32);
87
- let LLMRegistry = _LLMRegistry;
88
- LLMRegistry.register(Gemini);
89
- export {
90
- LLMRegistry
91
- };
@@ -1,206 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- class BasePlugin {
7
- /**
8
- * Initializes the plugin.
9
- *
10
- * @param name A unique identifier for this plugin instance.
11
- */
12
- constructor(name) {
13
- this.name = name;
14
- }
15
- /**
16
- * Callback executed when a user message is received before an invocation
17
- * starts.
18
- *
19
- * This callback helps logging and modifying the user message before the
20
- * runner starts the invocation.
21
- *
22
- * @param invocationContext The context for the entire invocation.
23
- * @param userMessage The message content input by user.
24
- * @returns An optional `Content` to be returned to the ADK. Returning a
25
- * value to replace the user message. Returning `undefined` to proceed
26
- * normally.
27
- */
28
- async onUserMessageCallback({ invocationContext, userMessage }) {
29
- return;
30
- }
31
- /**
32
- * Callback executed before the ADK runner runs.
33
- *
34
- * This is the first callback to be called in the lifecycle, ideal for global
35
- * setup or initialization tasks.
36
- *
37
- * @param invocationContext The context for the entire invocation, containing
38
- * session information, the root agent, etc.
39
- * @returns An optional `Event` to be returned to the ADK. Returning a value
40
- * to halt execution of the runner and ends the runner with that event.
41
- * Return `undefined` to proceed normally.
42
- */
43
- async beforeRunCallback({ invocationContext }) {
44
- return;
45
- }
46
- /**
47
- * Callback executed after an event is yielded from runner.
48
- *
49
- * This is the ideal place to make modification to the event before the event
50
- * is handled by the underlying agent app.
51
- *
52
- * @param invocationContext The context for the entire invocation.
53
- * @param event The event raised by the runner.
54
- * @returns An optional value. A non-`undefined` return may be used by the
55
- * framework to modify or replace the response. Returning `undefined`
56
- * allows the original response to be used.
57
- */
58
- async onEventCallback({ invocationContext, event }) {
59
- return;
60
- }
61
- /**
62
- * Callback executed after an ADK runner run has completed.
63
- *
64
- * This is the final callback in the ADK lifecycle, suitable for cleanup,
65
- * final logging, or reporting tasks.
66
- *
67
- * @param invocationContext The context for the entire invocation.
68
- * @returns undefined
69
- */
70
- async afterRunCallback({ invocationContext }) {
71
- return;
72
- }
73
- /**
74
- * Callback executed before an agent's primary logic is invoked.
75
- *
76
- * This callback can be used for logging, setup, or to short-circuit the
77
- * agent's execution by returning a value.
78
- *
79
- * @param agent The agent that is about to run.
80
- * @param callbackContext The context for the agent invocation.
81
- * @returns An optional `Content` object. If a value is returned, it will
82
- * bypass the agent's callbacks and its execution, and return this value
83
- * directly. Returning `undefined` allows the agent to proceed normally.
84
- */
85
- async beforeAgentCallback({ agent, callbackContext }) {
86
- return;
87
- }
88
- /**
89
- * Callback executed after an agent's primary logic has completed.
90
- *
91
- * This callback can be used to inspect, log, or modify the agent's final
92
- * result before it is returned.
93
- *
94
- * @param agent The agent that has just run.
95
- * @param callbackContext The context for the agent invocation.
96
- * @returns An optional `Content` object. If a value is returned, it will
97
- * replace the agent's original result. Returning `undefined` uses the
98
- * original, unmodified result.
99
- */
100
- async afterAgentCallback({ agent, callbackContext }) {
101
- return;
102
- }
103
- /**
104
- * Callback executed before a request is sent to the model.
105
- *
106
- * This provides an opportunity to inspect, log, or modify the `LlmRequest`
107
- * object. It can also be used to implement caching by returning a cached
108
- * `LlmResponse`, which would skip the actual model call.
109
- *
110
- * @param callbackContext The context for the current agent call.
111
- * @param llmRequest The prepared request object to be sent to the model.
112
- * @returns An optional value. The interpretation of a non-`undefined`
113
- * trigger an early exit and returns the response immediately. Returning
114
- * `undefined` allows the LLM request to proceed normally.
115
- */
116
- async beforeModelCallback({ callbackContext, llmRequest }) {
117
- return;
118
- }
119
- /**
120
- * Callback executed after a response is received from the model.
121
- *
122
- * This is the ideal place to log model responses, collect metrics on token
123
- * usage, or perform post-processing on the raw `LlmResponse`.
124
- *
125
- * @param callbackContext The context for the current agent call.
126
- * @param llmResponse The response object received from the model.
127
- * @returns An optional value. A non-`undefined` return may be used by the
128
- * framework to modify or replace the response. Returning `undefined`
129
- * allows the original response to be used.
130
- */
131
- async afterModelCallback({ callbackContext, llmResponse }) {
132
- return;
133
- }
134
- /**
135
- * Callback executed when a model call encounters an error.
136
- *
137
- * This callback provides an opportunity to handle model errors gracefully,
138
- * potentially providing alternative responses or recovery mechanisms.
139
- *
140
- * @param callbackContext The context for the current agent call.
141
- * @param llmRequest The request that was sent to the model when the error
142
- * occurred.
143
- * @param error The exception that was raised during model execution.
144
- * @returns An optional LlmResponse. If an LlmResponse is returned, it will be
145
- * used instead of propagating the error. Returning `undefined` allows
146
- * the original error to be raised.
147
- */
148
- async onModelErrorCallback({ callbackContext, llmRequest, error }) {
149
- return;
150
- }
151
- /**
152
- * Callback executed before a tool is called.
153
- *
154
- * This callback is useful for logging tool usage, input validation, or
155
- * modifying the arguments before they are passed to the tool.
156
- *
157
- * @param tool The tool instance that is about to be executed.
158
- * @param toolArgs The dictionary of arguments to be used for invoking the
159
- * tool.
160
- * @param toolContext The context specific to the tool execution.
161
- * @returns An optional dictionary. If a dictionary is returned, it will stop
162
- * the tool execution and return this response immediately. Returning
163
- * `undefined` uses the original, unmodified arguments.
164
- */
165
- async beforeToolCallback({ tool, toolArgs, toolContext }) {
166
- return;
167
- }
168
- /**
169
- * Callback executed after a tool has been called.
170
- *
171
- * This callback allows for inspecting, logging, or modifying the result
172
- * returned by a tool.
173
- *
174
- * @param tool The tool instance that has just been executed.
175
- * @param toolArgs The original arguments that were passed to the tool.
176
- * @param toolContext The context specific to the tool execution.
177
- * @param result The dictionary returned by the tool invocation.
178
- * @returns An optional dictionary. If a dictionary is returned, it will
179
- * **replace** the original result from the tool. This allows for
180
- * post-processing or altering tool outputs. Returning `undefined` uses
181
- * the original, unmodified result.
182
- */
183
- async afterToolCallback({ tool, toolArgs, toolContext, result }) {
184
- return;
185
- }
186
- /**
187
- * Callback executed when a tool call encounters an error.
188
- *
189
- * This callback provides an opportunity to handle tool errors gracefully,
190
- * potentially providing alternative responses or recovery mechanisms.
191
- *
192
- * @param tool The tool instance that encountered an error.
193
- * @param toolArgs The arguments that were passed to the tool.
194
- * @param toolContext The context specific to the tool execution.
195
- * @param error The exception that was raised during tool execution.
196
- * @returns An optional dictionary. If a dictionary is returned, it will be
197
- * used as the tool response instead of propagating the error. Returning
198
- * `undefined` allows the original error to be raised.
199
- */
200
- async onToolErrorCallback({ tool, toolArgs, toolContext, error }) {
201
- return;
202
- }
203
- }
204
- export {
205
- BasePlugin
206
- };
@@ -1,192 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import { getFunctionCalls, getFunctionResponses, isFinalResponse } from "../events/event.js";
7
- import { logger } from "../utils/logger.js";
8
- import { BasePlugin } from "./base_plugin.js";
9
- class LoggingPlugin extends BasePlugin {
10
- /**
11
- * Initialize the logging plugin.
12
- *
13
- * @param name The name of the plugin instance.
14
- */
15
- constructor(name = "logging_plugin") {
16
- super(name);
17
- }
18
- async onUserMessageCallback({ invocationContext, userMessage }) {
19
- var _a;
20
- this.log("\u{1F680} USER MESSAGE RECEIVED");
21
- this.log(` Invocation ID: ${invocationContext.invocationId}`);
22
- this.log(` Session ID: ${invocationContext.session.id}`);
23
- this.log(` User ID: ${invocationContext.userId}`);
24
- this.log(` App Name: ${invocationContext.appName}`);
25
- this.log(` Root Agent: ${(_a = invocationContext.agent.name) != null ? _a : "Unknown"}`);
26
- this.log(` User Content: ${this.formatContent(userMessage)}`);
27
- if (invocationContext.branch) {
28
- this.log(` Branch: ${invocationContext.branch}`);
29
- }
30
- return void 0;
31
- }
32
- async beforeRunCallback({ invocationContext }) {
33
- var _a;
34
- this.log("\u{1F3C3} INVOCATION STARTING");
35
- this.log(` Invocation ID: ${invocationContext.invocationId}`);
36
- this.log(` Starting Agent: ${(_a = invocationContext.agent.name) != null ? _a : "Unknown"}`);
37
- return void 0;
38
- }
39
- async onEventCallback({ invocationContext, event }) {
40
- this.log("\u{1F4E2} EVENT YIELDED");
41
- this.log(` Event ID: ${event.id}`);
42
- this.log(` Author: ${event.author}`);
43
- this.log(` Content: ${this.formatContent(event.content)}`);
44
- this.log(` Final Response: ${isFinalResponse(event)}`);
45
- const functionCalls = getFunctionCalls(event);
46
- if (functionCalls.length > 0) {
47
- const funcCalls = functionCalls.map((fc) => fc.name);
48
- this.log(` Function Calls: ${funcCalls}`);
49
- }
50
- const functionResponses = getFunctionResponses(event);
51
- if (functionResponses.length > 0) {
52
- const funcResponses = functionResponses.map((fr) => fr.name);
53
- this.log(` Function Responses: ${funcResponses}`);
54
- }
55
- if (event.longRunningToolIds && event.longRunningToolIds.length > 0) {
56
- this.log(` Long Running Tools: ${[...event.longRunningToolIds]}`);
57
- }
58
- return void 0;
59
- }
60
- async afterRunCallback({ invocationContext }) {
61
- var _a;
62
- this.log("\u2705 INVOCATION COMPLETED");
63
- this.log(` Invocation ID: ${invocationContext.invocationId}`);
64
- this.log(` Final Agent: ${(_a = invocationContext.agent.name) != null ? _a : "Unknown"}`);
65
- return void 0;
66
- }
67
- async beforeAgentCallback({ agent, callbackContext }) {
68
- this.log("\u{1F916} AGENT STARTING");
69
- this.log(` Agent Name: ${callbackContext.agentName}`);
70
- this.log(` Invocation ID: ${callbackContext.invocationId}`);
71
- if (callbackContext.invocationContext.branch) {
72
- this.log(` Branch: ${callbackContext.invocationContext.branch}`);
73
- }
74
- return void 0;
75
- }
76
- async afterAgentCallback({ agent, callbackContext }) {
77
- this.log("\u{1F916} AGENT COMPLETED");
78
- this.log(` Agent Name: ${callbackContext.agentName}`);
79
- this.log(` Invocation ID: ${callbackContext.invocationId}`);
80
- return void 0;
81
- }
82
- async beforeModelCallback({ callbackContext, llmRequest }) {
83
- var _a;
84
- this.log("\u{1F9E0} LLM REQUEST");
85
- this.log(` Model: ${(_a = llmRequest.model) != null ? _a : "default"}`);
86
- this.log(` Agent: ${callbackContext.agentName}`);
87
- if (llmRequest.config && llmRequest.config.systemInstruction) {
88
- let sysInstruction = llmRequest.config.systemInstruction;
89
- if (sysInstruction.length > 200) {
90
- sysInstruction = sysInstruction.substring(0, 200) + "...";
91
- }
92
- this.log(` System Instruction: '${sysInstruction}'`);
93
- }
94
- if (llmRequest.toolsDict) {
95
- const toolNames = Object.keys(llmRequest.toolsDict);
96
- this.log(` Available Tools: ${toolNames}`);
97
- }
98
- return void 0;
99
- }
100
- async afterModelCallback({ callbackContext, llmResponse }) {
101
- this.log("\u{1F9E0} LLM RESPONSE");
102
- this.log(` Agent: ${callbackContext.agentName}`);
103
- if (llmResponse.errorCode) {
104
- this.log(` \u274C ERROR - Code: ${llmResponse.errorCode}`);
105
- this.log(` Error Message: ${llmResponse.errorMessage}`);
106
- } else {
107
- this.log(` Content: ${this.formatContent(llmResponse.content)}`);
108
- if (llmResponse.partial) {
109
- this.log(` Partial: ${llmResponse.partial}`);
110
- }
111
- if (llmResponse.turnComplete !== void 0) {
112
- this.log(` Turn Complete: ${llmResponse.turnComplete}`);
113
- }
114
- }
115
- if (llmResponse.usageMetadata) {
116
- this.log(` Token Usage - Input: ${llmResponse.usageMetadata.promptTokenCount}, Output: ${llmResponse.usageMetadata.candidatesTokenCount}`);
117
- }
118
- return void 0;
119
- }
120
- async beforeToolCallback({ tool, toolArgs, toolContext }) {
121
- this.log("\u{1F527} TOOL STARTING");
122
- this.log(` Tool Name: ${tool.name}`);
123
- this.log(` Agent: ${toolContext.agentName}`);
124
- this.log(` Function Call ID: ${toolContext.functionCallId}`);
125
- this.log(` Arguments: ${this.formatArgs(toolArgs)}`);
126
- return void 0;
127
- }
128
- async afterToolCallback({ tool, toolArgs, toolContext, result }) {
129
- this.log("\u{1F527} TOOL COMPLETED");
130
- this.log(` Tool Name: ${tool.name}`);
131
- this.log(` Agent: ${toolContext.agentName}`);
132
- this.log(` Function Call ID: ${toolContext.functionCallId}`);
133
- this.log(` Result: ${this.formatArgs(result)}`);
134
- return void 0;
135
- }
136
- async onModelErrorCallback({ callbackContext, llmRequest, error }) {
137
- this.log("\u{1F9E0} LLM ERROR");
138
- this.log(` Agent: ${callbackContext.agentName}`);
139
- this.log(` Error: ${error}`);
140
- return void 0;
141
- }
142
- async onToolErrorCallback({ tool, toolArgs, toolContext, error }) {
143
- this.log("\u{1F527} TOOL ERROR");
144
- this.log(` Tool Name: ${tool.name}`);
145
- this.log(` Agent: ${toolContext.agentName}`);
146
- this.log(` Function Call ID: ${toolContext.functionCallId}`);
147
- this.log(` Arguments: ${this.formatArgs(toolArgs)}`);
148
- this.log(` Error: ${error}`);
149
- return void 0;
150
- }
151
- log(message) {
152
- const formattedMessage = `\x1B[90m[${this.name}] ${message}\x1B[0m`;
153
- logger.info(formattedMessage);
154
- }
155
- formatContent(content, maxLength = 200) {
156
- if (!content || !content.parts) {
157
- return "None";
158
- }
159
- const parts = [];
160
- for (const part of content.parts) {
161
- if (part.text) {
162
- let text = part.text.trim();
163
- if (text.length > maxLength) {
164
- text = text.substring(0, maxLength) + "...";
165
- }
166
- parts.push(`text: '${text}'`);
167
- } else if (part.functionCall) {
168
- parts.push(`function_call: ${part.functionCall.name}`);
169
- } else if (part.functionResponse) {
170
- parts.push(`function_response: ${part.functionResponse.name}`);
171
- } else if (part.codeExecutionResult) {
172
- parts.push("code_execution_result");
173
- } else {
174
- parts.push("other_part");
175
- }
176
- }
177
- return parts.join(" | ");
178
- }
179
- formatArgs(args, maxLength = 300) {
180
- if (!args) {
181
- return "{}";
182
- }
183
- let formatted = JSON.stringify(args);
184
- if (formatted.length > maxLength) {
185
- formatted = formatted.substring(0, maxLength) + "...}";
186
- }
187
- return formatted;
188
- }
189
- }
190
- export {
191
- LoggingPlugin
192
- };
@@ -1,209 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import { logger } from "../utils/logger.js";
7
- class PluginManager {
8
- /**
9
- * Initializes the plugin service.
10
- *
11
- * @param plugins An optional list of plugins to register upon
12
- * initialization.
13
- */
14
- constructor(plugins) {
15
- this.plugins = /* @__PURE__ */ new Set();
16
- if (plugins) {
17
- for (const plugin of plugins) {
18
- this.registerPlugin(plugin);
19
- }
20
- }
21
- }
22
- /**
23
- * Registers a new plugin.
24
- *
25
- * @param plugin The plugin instance to register.
26
- * @throws If the same exact plugin or a plugin with the same name is already
27
- * registered.
28
- */
29
- registerPlugin(plugin) {
30
- if (this.plugins.has(plugin)) {
31
- throw new Error(`Plugin '${plugin.name}' already registered.`);
32
- }
33
- if (Array.from(this.plugins).some((p) => p.name === plugin.name)) {
34
- throw new Error(`Plugin with name '${plugin.name}' already registered.`);
35
- }
36
- this.plugins.add(plugin);
37
- logger.info(`Plugin '${plugin.name}' registered.`);
38
- }
39
- /**
40
- * Retrieves a registered plugin by its name.
41
- *
42
- * @param pluginName The name of the plugin to retrieve.
43
- * @returns The plugin instance if found, otherwise `undefined`.
44
- */
45
- getPlugin(pluginName) {
46
- return Array.from(this.plugins).find((p) => p.name === pluginName);
47
- }
48
- /**
49
- * Runs the same callback for all plugins. This is a utility method to reduce
50
- * duplication below.
51
- *
52
- * @param plugins The set of plugins to run
53
- * @param callback A closure containing the callback method to run on each
54
- * plugin
55
- * @param callbackName The name of the function being called in the closure
56
- * above. Used for logging purposes.
57
- * @returns A promise containing the plugin method result. Must be casted to
58
- * the proper type for the plugin method.
59
- */
60
- async runCallbacks(plugins, callback, callbackName) {
61
- for (const plugin of plugins) {
62
- try {
63
- const result = await callback(plugin);
64
- if (result !== void 0) {
65
- logger.debug(
66
- `Plugin '${plugin.name}' returned a value for callback '${callbackName}', exiting early.`
67
- );
68
- return result;
69
- }
70
- } catch (e) {
71
- const errorMessage = `Error in plugin '${plugin.name}' during '${callbackName}' callback: ${e}`;
72
- logger.error(errorMessage);
73
- throw new Error(errorMessage);
74
- }
75
- }
76
- return void 0;
77
- }
78
- /**
79
- * Runs the `onUserMessageCallback` for all plugins.
80
- */
81
- async runOnUserMessageCallback({ userMessage, invocationContext }) {
82
- return await this.runCallbacks(
83
- this.plugins,
84
- (plugin) => plugin.onUserMessageCallback(
85
- { userMessage, invocationContext }
86
- ),
87
- "onUserMessageCallback"
88
- );
89
- }
90
- /**
91
- * Runs the `beforeRunCallback` for all plugins.
92
- */
93
- async runBeforeRunCallback({ invocationContext }) {
94
- return await this.runCallbacks(
95
- this.plugins,
96
- (plugin) => plugin.beforeRunCallback({ invocationContext }),
97
- "beforeRunCallback"
98
- );
99
- }
100
- /**
101
- * Runs the `afterRunCallback` for all plugins.
102
- */
103
- async runAfterRunCallback({ invocationContext }) {
104
- await this.runCallbacks(
105
- this.plugins,
106
- (plugin) => plugin.afterRunCallback({ invocationContext }),
107
- "afterRunCallback"
108
- );
109
- }
110
- /**
111
- * Runs the `onEventCallback` for all plugins.
112
- */
113
- async runOnEventCallback({ invocationContext, event }) {
114
- return await this.runCallbacks(
115
- this.plugins,
116
- (plugin) => plugin.onEventCallback({ invocationContext, event }),
117
- "onEventCallback"
118
- );
119
- }
120
- /**
121
- * Runs the `beforeAgentCallback` for all plugins.
122
- */
123
- async runBeforeAgentCallback({ agent, callbackContext }) {
124
- return await this.runCallbacks(
125
- this.plugins,
126
- (plugin) => plugin.beforeAgentCallback({ agent, callbackContext }),
127
- "beforeAgentCallback"
128
- );
129
- }
130
- /**
131
- * Runs the `afterAgentCallback` for all plugins.
132
- */
133
- async runAfterAgentCallback({ agent, callbackContext }) {
134
- return await this.runCallbacks(
135
- this.plugins,
136
- (plugin) => plugin.afterAgentCallback({ agent, callbackContext }),
137
- "afterAgentCallback"
138
- );
139
- }
140
- /**
141
- * Runs the `beforeToolCallback` for all plugins.
142
- */
143
- async runBeforeToolCallback({ tool, toolArgs, toolContext }) {
144
- return await this.runCallbacks(
145
- this.plugins,
146
- (plugin) => plugin.beforeToolCallback({ tool, toolArgs, toolContext }),
147
- "beforeToolCallback"
148
- );
149
- }
150
- /**
151
- * Runs the `afterToolCallback` for all plugins.
152
- */
153
- async runAfterToolCallback({ tool, toolArgs, toolContext, result }) {
154
- return await this.runCallbacks(
155
- this.plugins,
156
- (plugin) => plugin.afterToolCallback(
157
- { tool, toolArgs, toolContext, result }
158
- ),
159
- "afterToolCallback"
160
- );
161
- }
162
- /**
163
- * Runs the `onModelErrorCallback` for all plugins.
164
- */
165
- async runOnModelErrorCallback({ callbackContext, llmRequest, error }) {
166
- return await this.runCallbacks(
167
- this.plugins,
168
- (plugin) => plugin.onModelErrorCallback(
169
- { callbackContext, llmRequest, error }
170
- ),
171
- "onModelErrorCallback"
172
- );
173
- }
174
- /**
175
- * Runs the `beforeModelCallback` for all plugins.
176
- */
177
- async runBeforeModelCallback({ callbackContext, llmRequest }) {
178
- return await this.runCallbacks(
179
- this.plugins,
180
- (plugin) => plugin.beforeModelCallback({ callbackContext, llmRequest }),
181
- "beforeModelCallback"
182
- );
183
- }
184
- /**
185
- * Runs the `afterModelCallback` for all plugins.
186
- */
187
- async runAfterModelCallback({ callbackContext, llmResponse }) {
188
- return await this.runCallbacks(
189
- this.plugins,
190
- (plugin) => plugin.afterModelCallback({ callbackContext, llmResponse }),
191
- "afterModelCallback"
192
- );
193
- }
194
- /**
195
- * Runs the `onToolErrorCallback` for all plugins.
196
- */
197
- async runOnToolErrorCallback({ tool, toolArgs, toolContext, error }) {
198
- return await this.runCallbacks(
199
- this.plugins,
200
- (plugin) => plugin.onToolErrorCallback(
201
- { tool, toolArgs, toolContext, error }
202
- ),
203
- "onToolErrorCallback"
204
- );
205
- }
206
- }
207
- export {
208
- PluginManager
209
- };