@vybestack/llxprt-code-core 0.5.0 → 0.6.0-nightly.251128.1049d5f2b

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 (261) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/src/agents/codebase-investigator.d.ts +46 -0
  5. package/dist/src/agents/codebase-investigator.js +136 -0
  6. package/dist/src/agents/codebase-investigator.js.map +1 -0
  7. package/dist/src/agents/executor.d.ts +92 -0
  8. package/dist/src/agents/executor.js +624 -0
  9. package/dist/src/agents/executor.js.map +1 -0
  10. package/dist/src/agents/invocation.d.ts +45 -0
  11. package/dist/src/agents/invocation.js +114 -0
  12. package/dist/src/agents/invocation.js.map +1 -0
  13. package/dist/src/agents/registry.d.ts +38 -0
  14. package/dist/src/agents/registry.js +64 -0
  15. package/dist/src/agents/registry.js.map +1 -0
  16. package/dist/src/agents/types.d.ts +145 -0
  17. package/dist/src/agents/types.js +17 -0
  18. package/dist/src/agents/types.js.map +1 -0
  19. package/dist/src/agents/utils.d.ts +15 -0
  20. package/dist/src/agents/utils.js +27 -0
  21. package/dist/src/agents/utils.js.map +1 -0
  22. package/dist/src/auth/types.d.ts +4 -4
  23. package/dist/src/code_assist/oauth-credential-storage.d.ts +27 -0
  24. package/dist/src/code_assist/oauth-credential-storage.js +115 -0
  25. package/dist/src/code_assist/oauth-credential-storage.js.map +1 -0
  26. package/dist/src/code_assist/oauth2.js +36 -9
  27. package/dist/src/code_assist/oauth2.js.map +1 -1
  28. package/dist/src/config/config.d.ts +72 -8
  29. package/dist/src/config/config.js +130 -23
  30. package/dist/src/config/config.js.map +1 -1
  31. package/dist/src/config/constants.d.ts +11 -0
  32. package/dist/src/config/constants.js +16 -0
  33. package/dist/src/config/constants.js.map +1 -0
  34. package/dist/src/config/storage.d.ts +1 -0
  35. package/dist/src/config/storage.js +2 -1
  36. package/dist/src/config/storage.js.map +1 -1
  37. package/dist/src/confirmation-bus/index.d.ts +2 -0
  38. package/dist/src/confirmation-bus/index.js +3 -0
  39. package/dist/src/confirmation-bus/index.js.map +1 -0
  40. package/dist/src/confirmation-bus/message-bus.d.ts +60 -0
  41. package/dist/src/confirmation-bus/message-bus.js +141 -0
  42. package/dist/src/confirmation-bus/message-bus.js.map +1 -0
  43. package/dist/src/confirmation-bus/types.d.ts +59 -0
  44. package/dist/src/confirmation-bus/types.js +10 -0
  45. package/dist/src/confirmation-bus/types.js.map +1 -0
  46. package/dist/src/core/baseLlmClient.d.ts +77 -0
  47. package/dist/src/core/baseLlmClient.js +175 -0
  48. package/dist/src/core/baseLlmClient.js.map +1 -0
  49. package/dist/src/core/client.d.ts +13 -1
  50. package/dist/src/core/client.js +98 -119
  51. package/dist/src/core/client.js.map +1 -1
  52. package/dist/src/core/coreToolScheduler.d.ts +20 -1
  53. package/dist/src/core/coreToolScheduler.js +160 -16
  54. package/dist/src/core/coreToolScheduler.js.map +1 -1
  55. package/dist/src/core/geminiChat.d.ts +8 -1
  56. package/dist/src/core/geminiChat.js +30 -21
  57. package/dist/src/core/geminiChat.js.map +1 -1
  58. package/dist/src/core/subagent.d.ts +16 -1
  59. package/dist/src/core/subagent.js +59 -3
  60. package/dist/src/core/subagent.js.map +1 -1
  61. package/dist/src/core/subagentOrchestrator.d.ts +2 -1
  62. package/dist/src/core/subagentOrchestrator.js +36 -6
  63. package/dist/src/core/subagentOrchestrator.js.map +1 -1
  64. package/dist/src/core/turn.d.ts +1 -4
  65. package/dist/src/core/turn.js +2 -12
  66. package/dist/src/core/turn.js.map +1 -1
  67. package/dist/src/ide/detect-ide.d.ts +44 -14
  68. package/dist/src/ide/detect-ide.js +35 -75
  69. package/dist/src/ide/detect-ide.js.map +1 -1
  70. package/dist/src/ide/ide-client.d.ts +5 -4
  71. package/dist/src/ide/ide-client.js +34 -25
  72. package/dist/src/ide/ide-client.js.map +1 -1
  73. package/dist/src/ide/ide-installer.d.ts +2 -2
  74. package/dist/src/ide/ide-installer.js +7 -9
  75. package/dist/src/ide/ide-installer.js.map +1 -1
  76. package/dist/src/index.d.ts +10 -2
  77. package/dist/src/index.js +12 -3
  78. package/dist/src/index.js.map +1 -1
  79. package/dist/src/mcp/oauth-provider.d.ts +5 -1
  80. package/dist/src/mcp/oauth-provider.js +56 -44
  81. package/dist/src/mcp/oauth-provider.js.map +1 -1
  82. package/dist/src/mcp/oauth-token-storage.d.ts +43 -40
  83. package/dist/src/mcp/oauth-token-storage.js +114 -44
  84. package/dist/src/mcp/oauth-token-storage.js.map +1 -1
  85. package/dist/src/mcp/oauth-utils.js +1 -0
  86. package/dist/src/mcp/oauth-utils.js.map +1 -1
  87. package/dist/src/mcp/sa-impersonation-provider.d.ts +33 -0
  88. package/dist/src/mcp/sa-impersonation-provider.js +130 -0
  89. package/dist/src/mcp/sa-impersonation-provider.js.map +1 -0
  90. package/dist/src/mcp/token-storage/hybrid-token-storage.js +1 -1
  91. package/dist/src/policy/config.d.ts +51 -0
  92. package/dist/src/policy/config.js +102 -0
  93. package/dist/src/policy/config.js.map +1 -0
  94. package/dist/src/policy/index.d.ts +5 -0
  95. package/dist/src/policy/index.js +6 -0
  96. package/dist/src/policy/index.js.map +1 -0
  97. package/dist/src/policy/policies/discovered.toml +9 -0
  98. package/dist/src/policy/policies/read-only.toml +68 -0
  99. package/dist/src/policy/policies/write.toml +69 -0
  100. package/dist/src/policy/policies/yolo.toml +8 -0
  101. package/dist/src/policy/policy-engine.d.ts +55 -0
  102. package/dist/src/policy/policy-engine.js +126 -0
  103. package/dist/src/policy/policy-engine.js.map +1 -0
  104. package/dist/src/policy/stable-stringify.d.ts +29 -0
  105. package/dist/src/policy/stable-stringify.js +111 -0
  106. package/dist/src/policy/stable-stringify.js.map +1 -0
  107. package/dist/src/policy/toml-loader.d.ts +37 -0
  108. package/dist/src/policy/toml-loader.js +183 -0
  109. package/dist/src/policy/toml-loader.js.map +1 -0
  110. package/dist/src/policy/types.d.ts +16 -0
  111. package/dist/src/policy/types.js +7 -0
  112. package/dist/src/policy/types.js.map +1 -0
  113. package/dist/src/providers/LoggingProviderWrapper.d.ts +2 -0
  114. package/dist/src/providers/LoggingProviderWrapper.js +27 -6
  115. package/dist/src/providers/LoggingProviderWrapper.js.map +1 -1
  116. package/dist/src/providers/ProviderManager.d.ts +18 -0
  117. package/dist/src/providers/ProviderManager.js +54 -3
  118. package/dist/src/providers/ProviderManager.js.map +1 -1
  119. package/dist/src/providers/anthropic/AnthropicProvider.d.ts +49 -0
  120. package/dist/src/providers/anthropic/AnthropicProvider.js +468 -30
  121. package/dist/src/providers/anthropic/AnthropicProvider.js.map +1 -1
  122. package/dist/src/providers/openai/OpenAIProvider.d.ts +3 -0
  123. package/dist/src/providers/openai/OpenAIProvider.js +12 -6
  124. package/dist/src/providers/openai/OpenAIProvider.js.map +1 -1
  125. package/dist/src/providers/utils/localEndpoint.d.ts +39 -0
  126. package/dist/src/providers/utils/localEndpoint.js +117 -0
  127. package/dist/src/providers/utils/localEndpoint.js.map +1 -0
  128. package/dist/src/runtime/AgentRuntimeLoader.d.ts +1 -0
  129. package/dist/src/runtime/AgentRuntimeLoader.js +6 -1
  130. package/dist/src/runtime/AgentRuntimeLoader.js.map +1 -1
  131. package/dist/src/runtime/createAgentRuntimeContext.js +8 -7
  132. package/dist/src/runtime/createAgentRuntimeContext.js.map +1 -1
  133. package/dist/src/services/fileSystemService.d.ts +9 -0
  134. package/dist/src/services/fileSystemService.js +12 -1
  135. package/dist/src/services/fileSystemService.js.map +1 -1
  136. package/dist/src/services/history/HistoryService.d.ts +4 -0
  137. package/dist/src/services/history/HistoryService.js +18 -0
  138. package/dist/src/services/history/HistoryService.js.map +1 -1
  139. package/dist/src/services/history/IContent.d.ts +6 -0
  140. package/dist/src/services/history/IContent.js.map +1 -1
  141. package/dist/src/services/shellExecutionService.js +0 -6
  142. package/dist/src/services/shellExecutionService.js.map +1 -1
  143. package/dist/src/settings/types.d.ts +7 -0
  144. package/dist/src/storage/sessionTypes.d.ts +27 -0
  145. package/dist/src/storage/sessionTypes.js +10 -0
  146. package/dist/src/storage/sessionTypes.js.map +1 -0
  147. package/dist/src/telemetry/constants.d.ts +8 -0
  148. package/dist/src/telemetry/constants.js +8 -0
  149. package/dist/src/telemetry/constants.js.map +1 -1
  150. package/dist/src/telemetry/loggers.d.ts +9 -1
  151. package/dist/src/telemetry/loggers.js +154 -2
  152. package/dist/src/telemetry/loggers.js.map +1 -1
  153. package/dist/src/telemetry/metrics.d.ts +5 -0
  154. package/dist/src/telemetry/metrics.js +4 -0
  155. package/dist/src/telemetry/metrics.js.map +1 -1
  156. package/dist/src/telemetry/types.d.ts +62 -1
  157. package/dist/src/telemetry/types.js +92 -0
  158. package/dist/src/telemetry/types.js.map +1 -1
  159. package/dist/src/telemetry/uiTelemetry.d.ts +1 -1
  160. package/dist/src/telemetry/uiTelemetry.js +2 -3
  161. package/dist/src/telemetry/uiTelemetry.js.map +1 -1
  162. package/dist/src/test-utils/config.js +14 -0
  163. package/dist/src/test-utils/config.js.map +1 -1
  164. package/dist/src/test-utils/mock-tool.d.ts +8 -4
  165. package/dist/src/test-utils/mock-tool.js +35 -18
  166. package/dist/src/test-utils/mock-tool.js.map +1 -1
  167. package/dist/src/test-utils/tools.d.ts +1 -1
  168. package/dist/src/test-utils/tools.js +4 -4
  169. package/dist/src/test-utils/tools.js.map +1 -1
  170. package/dist/src/tools/edit.d.ts +3 -2
  171. package/dist/src/tools/edit.js +29 -10
  172. package/dist/src/tools/edit.js.map +1 -1
  173. package/dist/src/tools/glob.d.ts +6 -4
  174. package/dist/src/tools/glob.js +3 -3
  175. package/dist/src/tools/glob.js.map +1 -1
  176. package/dist/src/tools/grep.d.ts +3 -2
  177. package/dist/src/tools/grep.js +2 -2
  178. package/dist/src/tools/grep.js.map +1 -1
  179. package/dist/src/tools/ls.d.ts +4 -3
  180. package/dist/src/tools/ls.js +3 -3
  181. package/dist/src/tools/ls.js.map +1 -1
  182. package/dist/src/tools/mcp-client.d.ts +9 -18
  183. package/dist/src/tools/mcp-client.js +60 -102
  184. package/dist/src/tools/mcp-client.js.map +1 -1
  185. package/dist/src/tools/mcp-tool.js +7 -1
  186. package/dist/src/tools/mcp-tool.js.map +1 -1
  187. package/dist/src/tools/memoryTool.d.ts +6 -2
  188. package/dist/src/tools/memoryTool.js +14 -4
  189. package/dist/src/tools/memoryTool.js.map +1 -1
  190. package/dist/src/tools/modifiable-tool.d.ts +1 -1
  191. package/dist/src/tools/modifiable-tool.js +9 -1
  192. package/dist/src/tools/modifiable-tool.js.map +1 -1
  193. package/dist/src/tools/read-file.d.ts +3 -2
  194. package/dist/src/tools/read-file.js +2 -2
  195. package/dist/src/tools/read-file.js.map +1 -1
  196. package/dist/src/tools/read-many-files.d.ts +3 -2
  197. package/dist/src/tools/read-many-files.js +2 -2
  198. package/dist/src/tools/read-many-files.js.map +1 -1
  199. package/dist/src/tools/ripGrep.d.ts +3 -2
  200. package/dist/src/tools/ripGrep.js +2 -2
  201. package/dist/src/tools/ripGrep.js.map +1 -1
  202. package/dist/src/tools/shell.d.ts +3 -2
  203. package/dist/src/tools/shell.js +69 -9
  204. package/dist/src/tools/shell.js.map +1 -1
  205. package/dist/src/tools/smart-edit.d.ts +22 -2
  206. package/dist/src/tools/smart-edit.js +124 -12
  207. package/dist/src/tools/smart-edit.js.map +1 -1
  208. package/dist/src/tools/task.d.ts +1 -0
  209. package/dist/src/tools/task.js +33 -16
  210. package/dist/src/tools/task.js.map +1 -1
  211. package/dist/src/tools/tool-confirmation-types.d.ts +20 -0
  212. package/dist/src/tools/tool-confirmation-types.js +15 -0
  213. package/dist/src/tools/tool-confirmation-types.js.map +1 -0
  214. package/dist/src/tools/tool-error.d.ts +2 -0
  215. package/dist/src/tools/tool-error.js +2 -0
  216. package/dist/src/tools/tool-error.js.map +1 -1
  217. package/dist/src/tools/tool-registry.d.ts +8 -1
  218. package/dist/src/tools/tool-registry.js +18 -4
  219. package/dist/src/tools/tool-registry.js.map +1 -1
  220. package/dist/src/tools/tools.d.ts +52 -14
  221. package/dist/src/tools/tools.js +71 -15
  222. package/dist/src/tools/tools.js.map +1 -1
  223. package/dist/src/tools/web-fetch.d.ts +3 -2
  224. package/dist/src/tools/web-fetch.js +11 -6
  225. package/dist/src/tools/web-fetch.js.map +1 -1
  226. package/dist/src/tools/web-search-invocation.d.ts +3 -1
  227. package/dist/src/tools/web-search-invocation.js +5 -2
  228. package/dist/src/tools/web-search-invocation.js.map +1 -1
  229. package/dist/src/tools/web-search.d.ts +3 -2
  230. package/dist/src/tools/web-search.js +6 -4
  231. package/dist/src/tools/web-search.js.map +1 -1
  232. package/dist/src/tools/write-file.d.ts +3 -2
  233. package/dist/src/tools/write-file.js +11 -6
  234. package/dist/src/tools/write-file.js.map +1 -1
  235. package/dist/src/utils/bfsFileSearch.d.ts +2 -2
  236. package/dist/src/utils/editor.js +5 -3
  237. package/dist/src/utils/editor.js.map +1 -1
  238. package/dist/src/utils/getFolderStructure.d.ts +2 -2
  239. package/dist/src/utils/getFolderStructure.js +1 -1
  240. package/dist/src/utils/getFolderStructure.js.map +1 -1
  241. package/dist/src/utils/llm-edit-fixer.js +10 -1
  242. package/dist/src/utils/llm-edit-fixer.js.map +1 -1
  243. package/dist/src/utils/memoryDiscovery.d.ts +2 -1
  244. package/dist/src/utils/memoryDiscovery.js +3 -2
  245. package/dist/src/utils/memoryDiscovery.js.map +1 -1
  246. package/dist/src/utils/memoryImportProcessor.js +13 -20
  247. package/dist/src/utils/memoryImportProcessor.js.map +1 -1
  248. package/dist/src/utils/retry.d.ts +5 -1
  249. package/dist/src/utils/retry.js +31 -16
  250. package/dist/src/utils/retry.js.map +1 -1
  251. package/dist/src/utils/schemaValidator.js +11 -1
  252. package/dist/src/utils/schemaValidator.js.map +1 -1
  253. package/dist/src/utils/shell-utils.d.ts +1 -0
  254. package/dist/src/utils/shell-utils.js +6 -2
  255. package/dist/src/utils/shell-utils.js.map +1 -1
  256. package/dist/src/utils/thoughtUtils.d.ts +21 -0
  257. package/dist/src/utils/thoughtUtils.js +39 -0
  258. package/dist/src/utils/thoughtUtils.js.map +1 -0
  259. package/dist/src/utils/tool-utils.js +2 -2
  260. package/dist/src/utils/tool-utils.js.map +1 -1
  261. package/package.json +6 -4
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { Config } from '../config/config.js';
7
+ import { BaseToolInvocation, type ToolResult } from '../tools/tools.js';
8
+ import type { AgentDefinition, AgentInputs } from './types.js';
9
+ import type { MessageBus } from '../confirmation-bus/message-bus.js';
10
+ import { type z } from 'zod';
11
+ /**
12
+ * Represents a validated, executable instance of a subagent tool.
13
+ *
14
+ * This class orchestrates the execution of a defined agent by:
15
+ * 1. Initializing the {@link AgentExecutor}.
16
+ * 2. Running the agent's execution loop.
17
+ * 3. Bridging the agent's streaming activity (e.g., thoughts) to the tool's
18
+ * live output stream.
19
+ * 4. Formatting the final result into a {@link ToolResult}.
20
+ */
21
+ export declare class SubagentInvocation<TOutput extends z.ZodTypeAny> extends BaseToolInvocation<AgentInputs, ToolResult> {
22
+ private readonly definition;
23
+ private readonly config;
24
+ /**
25
+ * @param params The validated input parameters for the agent.
26
+ * @param definition The definition object that configures the agent.
27
+ * @param config The global runtime configuration.
28
+ * @param messageBus Optional message bus for policy enforcement.
29
+ */
30
+ constructor(params: AgentInputs, definition: AgentDefinition<TOutput>, config: Config, messageBus?: MessageBus);
31
+ /**
32
+ * Returns a concise, human-readable description of the invocation.
33
+ * Used for logging and display purposes.
34
+ */
35
+ getDescription(): string;
36
+ /**
37
+ * Executes the subagent.
38
+ *
39
+ * @param signal An `AbortSignal` to cancel the agent's execution.
40
+ * @param updateOutput A callback to stream intermediate output, such as the
41
+ * agent's thoughts, to the user interface.
42
+ * @returns A `Promise` that resolves with the final `ToolResult`.
43
+ */
44
+ execute(signal: AbortSignal, updateOutput?: (output: string) => void): Promise<ToolResult>;
45
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { AgentExecutor } from './executor.js';
7
+ import { BaseToolInvocation } from '../tools/tools.js';
8
+ import { ToolErrorType } from '../tools/tool-error.js';
9
+ const INPUT_PREVIEW_MAX_LENGTH = 50;
10
+ const DESCRIPTION_MAX_LENGTH = 200;
11
+ /**
12
+ * Represents a validated, executable instance of a subagent tool.
13
+ *
14
+ * This class orchestrates the execution of a defined agent by:
15
+ * 1. Initializing the {@link AgentExecutor}.
16
+ * 2. Running the agent's execution loop.
17
+ * 3. Bridging the agent's streaming activity (e.g., thoughts) to the tool's
18
+ * live output stream.
19
+ * 4. Formatting the final result into a {@link ToolResult}.
20
+ */
21
+ export class SubagentInvocation extends BaseToolInvocation {
22
+ definition;
23
+ config;
24
+ /**
25
+ * @param params The validated input parameters for the agent.
26
+ * @param definition The definition object that configures the agent.
27
+ * @param config The global runtime configuration.
28
+ * @param messageBus Optional message bus for policy enforcement.
29
+ */
30
+ constructor(params, definition, config, messageBus) {
31
+ super(params, messageBus);
32
+ this.definition = definition;
33
+ this.config = config;
34
+ }
35
+ /**
36
+ * Returns a concise, human-readable description of the invocation.
37
+ * Used for logging and display purposes.
38
+ */
39
+ getDescription() {
40
+ const inputSummary = Object.entries(this.params)
41
+ .map(([key, value]) => {
42
+ let stringValue;
43
+ try {
44
+ stringValue =
45
+ typeof value === 'object' && value !== null
46
+ ? JSON.stringify(value)
47
+ : String(value);
48
+ }
49
+ catch {
50
+ // Handle circular references/unsupported values gracefully
51
+ stringValue = Object.prototype.toString.call(value);
52
+ }
53
+ return `${key}: ${stringValue.slice(0, INPUT_PREVIEW_MAX_LENGTH)}`;
54
+ })
55
+ .join(', ');
56
+ const description = `Running subagent '${this.definition.name}' with inputs: { ${inputSummary} }`;
57
+ return description.slice(0, DESCRIPTION_MAX_LENGTH);
58
+ }
59
+ /**
60
+ * Executes the subagent.
61
+ *
62
+ * @param signal An `AbortSignal` to cancel the agent's execution.
63
+ * @param updateOutput A callback to stream intermediate output, such as the
64
+ * agent's thoughts, to the user interface.
65
+ * @returns A `Promise` that resolves with the final `ToolResult`.
66
+ */
67
+ async execute(signal, updateOutput) {
68
+ try {
69
+ if (updateOutput) {
70
+ updateOutput('Subagent starting...\n');
71
+ }
72
+ // Create an activity callback to bridge the executor's events to the
73
+ // tool's streaming output.
74
+ const onActivity = (activity) => {
75
+ if (!updateOutput)
76
+ return;
77
+ if (activity.type === 'THOUGHT_CHUNK' &&
78
+ typeof activity.data['text'] === 'string') {
79
+ updateOutput(`🤖💭 ${activity.data['text']}`);
80
+ }
81
+ };
82
+ const executor = await AgentExecutor.create(this.definition, this.config, onActivity);
83
+ const output = await executor.run(this.params, signal);
84
+ const resultContent = `Subagent '${this.definition.name}' finished.
85
+ Termination Reason: ${output.terminate_reason}
86
+ Result:
87
+ ${output.result}`;
88
+ const displayContent = `
89
+ Subagent ${this.definition.name} Finished
90
+
91
+ Termination Reason:\n ${output.terminate_reason}
92
+
93
+ Result:
94
+ ${output.result}
95
+ `;
96
+ return {
97
+ llmContent: [{ text: resultContent }],
98
+ returnDisplay: displayContent,
99
+ };
100
+ }
101
+ catch (error) {
102
+ const errorMessage = error instanceof Error ? error.message : String(error);
103
+ return {
104
+ llmContent: `Subagent '${this.definition.name}' failed. Error: ${errorMessage}`,
105
+ returnDisplay: `Subagent Failed: ${this.definition.name}\nError: ${errorMessage}`,
106
+ error: {
107
+ message: errorMessage,
108
+ type: ToolErrorType.EXECUTION_FAILED,
109
+ },
110
+ };
111
+ }
112
+ }
113
+ }
114
+ //# sourceMappingURL=invocation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invocation.js","sourceRoot":"","sources":["../../../src/agents/invocation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAm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AAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAEzD,OAAO;gBACL,UAAU,EAAE,aAAa,IAAI,CAAC,UAAU,CAAC,IAAI,oBAAoB,YAAY,EAAE;gBAC/E,aAAa,EAAE,oBAAoB,IAAI,CAAC,UAAU,CAAC,IAAI,YAAY,YAAY,EAAE;gBACjF,KAAK,EAAE;oBACL,OAAO,EAAE,YAAY;oBACrB,IAAI,EAAE,aAAa,CAAC,gBAAgB;iBACrC;aACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { Config } from '../config/config.js';
7
+ import type { AgentDefinition } from './types.js';
8
+ import type { z } from 'zod';
9
+ /**
10
+ * Manages the discovery, loading, validation, and registration of
11
+ * AgentDefinitions.
12
+ */
13
+ export declare class AgentRegistry {
14
+ private readonly config;
15
+ private readonly agents;
16
+ private readonly logger;
17
+ constructor(config: Config);
18
+ /**
19
+ * Discovers and loads agents.
20
+ */
21
+ initialize(): Promise<void>;
22
+ private loadBuiltInAgents;
23
+ /**
24
+ * Registers an agent definition. If an agent with the same name exists,
25
+ * it will be overwritten, respecting the precedence established by the
26
+ * initialization order.
27
+ */
28
+ protected registerAgent<TOutput extends z.ZodTypeAny>(definition: AgentDefinition<TOutput>): void;
29
+ /**
30
+ * Retrieves an agent definition by name.
31
+ * Callers should cast to their expected AgentDefinition<TOutput> shape before invoking typed callbacks.
32
+ */
33
+ getDefinition(name: string): AgentDefinition | undefined;
34
+ /**
35
+ * Returns all active agent definitions.
36
+ */
37
+ getAllDefinitions(): AgentDefinition[];
38
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { DebugLogger } from '../debug/DebugLogger.js';
7
+ /**
8
+ * Manages the discovery, loading, validation, and registration of
9
+ * AgentDefinitions.
10
+ */
11
+ export class AgentRegistry {
12
+ config;
13
+ // Using unknown output type for the internal map to handle generic variance correctly
14
+ // Callers will cast to specific types as needed
15
+ agents = new Map();
16
+ logger = new DebugLogger('llxprt:agents:registry');
17
+ constructor(config) {
18
+ this.config = config;
19
+ // Access config to satisfy lint and allow future conditional logging
20
+ void this.config;
21
+ }
22
+ /**
23
+ * Discovers and loads agents.
24
+ */
25
+ async initialize() {
26
+ this.loadBuiltInAgents();
27
+ this.logger.debug(() => `[AgentRegistry] Initialized with ${this.agents.size} agents.`);
28
+ }
29
+ loadBuiltInAgents() {
30
+ // No built-in agents registered - CodebaseInvestigatorAgent was removed
31
+ // because it hardcodes DEFAULT_GEMINI_MODEL, violating multi-provider support
32
+ }
33
+ /**
34
+ * Registers an agent definition. If an agent with the same name exists,
35
+ * it will be overwritten, respecting the precedence established by the
36
+ * initialization order.
37
+ */
38
+ registerAgent(definition) {
39
+ // Basic validation
40
+ if (!definition.name || !definition.description) {
41
+ this.logger.warn(`[AgentRegistry] Skipping invalid agent definition. Missing name or description.`);
42
+ return;
43
+ }
44
+ if (this.agents.has(definition.name)) {
45
+ this.logger.debug(`[AgentRegistry] Overriding agent '${definition.name}'`);
46
+ }
47
+ // Cast to default AgentDefinition type for storage - callers will cast back as needed
48
+ this.agents.set(definition.name, definition);
49
+ }
50
+ /**
51
+ * Retrieves an agent definition by name.
52
+ * Callers should cast to their expected AgentDefinition<TOutput> shape before invoking typed callbacks.
53
+ */
54
+ getDefinition(name) {
55
+ return this.agents.get(name);
56
+ }
57
+ /**
58
+ * Returns all active agent definitions.
59
+ */
60
+ getAllDefinitions() {
61
+ return Array.from(this.agents.values());
62
+ }
63
+ }
64
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/agents/registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,EAAE,WAAW,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,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1C,CAAC;CACF"}
@@ -0,0 +1,145 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * @fileoverview Defines the core configuration interfaces and types for the agent architecture.
8
+ */
9
+ import type { Content, FunctionDeclaration } from '@google/genai';
10
+ import type { AnyDeclarativeTool } from '../tools/tools.js';
11
+ import { type z } from 'zod';
12
+ /**
13
+ * Describes the possible termination modes for an agent.
14
+ */
15
+ export declare enum AgentTerminateMode {
16
+ ERROR = "ERROR",
17
+ TIMEOUT = "TIMEOUT",
18
+ GOAL = "GOAL",
19
+ MAX_TURNS = "MAX_TURNS",
20
+ ABORTED = "ABORTED"
21
+ }
22
+ /**
23
+ * Represents the output structure of an agent's execution.
24
+ */
25
+ export interface OutputObject {
26
+ result: string;
27
+ terminate_reason: AgentTerminateMode;
28
+ }
29
+ /**
30
+ * Represents the validated input parameters passed to an agent upon invocation.
31
+ * Used primarily for templating the system prompt. (Replaces ContextState)
32
+ */
33
+ export type AgentInputs = Record<string, unknown>;
34
+ /**
35
+ * Structured events emitted during subagent execution for user observability.
36
+ */
37
+ export interface SubagentActivityEvent {
38
+ isSubagentActivityEvent: true;
39
+ agentName: string;
40
+ type: 'TOOL_CALL_START' | 'TOOL_CALL_END' | 'THOUGHT_CHUNK' | 'ERROR';
41
+ data: Record<string, unknown>;
42
+ }
43
+ /**
44
+ * The definition for an agent.
45
+ * @template TOutput The specific Zod schema for the agent's final output object.
46
+ */
47
+ export interface AgentDefinition<TOutput extends z.ZodTypeAny = z.ZodUnknown> {
48
+ /** Unique identifier for the agent. */
49
+ name: string;
50
+ displayName?: string;
51
+ description: string;
52
+ promptConfig: PromptConfig;
53
+ modelConfig: ModelConfig;
54
+ runConfig: RunConfig;
55
+ toolConfig?: ToolConfig;
56
+ outputConfig?: OutputConfig<TOutput>;
57
+ inputConfig: InputConfig;
58
+ /**
59
+ * An optional function to process the raw output from the agent's final tool
60
+ * call into a string format.
61
+ *
62
+ * @param output The raw output value from the `complete_task` tool, now strongly typed with TOutput.
63
+ * @returns A string representation of the final output.
64
+ */
65
+ processOutput?: (output: z.infer<TOutput>) => string;
66
+ }
67
+ /**
68
+ * Configures the initial prompt for the agent.
69
+ */
70
+ export interface PromptConfig {
71
+ /**
72
+ * A single system prompt string. Supports templating using `${input_name}` syntax.
73
+ */
74
+ systemPrompt?: string;
75
+ /**
76
+ * An array of user/model content pairs for few-shot prompting.
77
+ */
78
+ initialMessages?: Content[];
79
+ /**
80
+ * The specific task or question to trigger the agent's execution loop.
81
+ * This is sent as the first user message, distinct from the systemPrompt (identity/rules)
82
+ * and initialMessages (history/few-shots). Supports templating.
83
+ * If not provided, a generic "Get Started!" message is used.
84
+ */
85
+ query?: string;
86
+ }
87
+ /**
88
+ * Configures the tools available to the agent during its execution.
89
+ */
90
+ export interface ToolConfig {
91
+ tools: Array<string | FunctionDeclaration | AnyDeclarativeTool>;
92
+ }
93
+ /**
94
+ * Configures the expected inputs (parameters) for the agent.
95
+ */
96
+ export interface InputConfig {
97
+ /**
98
+ * Defines the parameters the agent accepts.
99
+ * This is vital for generating the tool wrapper schema.
100
+ */
101
+ inputs: Record<string, {
102
+ description: string;
103
+ type: 'string' | 'number' | 'boolean' | 'integer' | 'string[]' | 'number[]';
104
+ required: boolean;
105
+ }>;
106
+ }
107
+ /**
108
+ * Configures the expected outputs for the agent.
109
+ */
110
+ export interface OutputConfig<T extends z.ZodTypeAny> {
111
+ /**
112
+ * The name of the final result parameter. This will be the name of the
113
+ * argument in the `submit_final_output` tool (e.g., "report", "answer").
114
+ */
115
+ outputName: string;
116
+ /**
117
+ * A description of the expected output. This will be used as the description
118
+ * for the tool argument.
119
+ */
120
+ description: string;
121
+ /**
122
+ * Optional JSON schema for the output. If provided, it will be used as the
123
+ * schema for the tool's argument, allowing for structured output enforcement.
124
+ * Defaults to { type: 'string' }.
125
+ */
126
+ schema: T;
127
+ }
128
+ /**
129
+ * Configures the generative model parameters for the agent.
130
+ */
131
+ export interface ModelConfig {
132
+ model: string;
133
+ temp: number;
134
+ top_p: number;
135
+ thinkingBudget?: number;
136
+ }
137
+ /**
138
+ * Configures the execution environment and constraints for the agent.
139
+ */
140
+ export interface RunConfig {
141
+ /** The maximum execution time for the agent in minutes. */
142
+ max_time_minutes: number;
143
+ /** The maximum number of conversational turns. */
144
+ max_turns?: number;
145
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Describes the possible termination modes for an agent.
8
+ */
9
+ export var AgentTerminateMode;
10
+ (function (AgentTerminateMode) {
11
+ AgentTerminateMode["ERROR"] = "ERROR";
12
+ AgentTerminateMode["TIMEOUT"] = "TIMEOUT";
13
+ AgentTerminateMode["GOAL"] = "GOAL";
14
+ AgentTerminateMode["MAX_TURNS"] = "MAX_TURNS";
15
+ AgentTerminateMode["ABORTED"] = "ABORTED";
16
+ })(AgentTerminateMode || (AgentTerminateMode = {}));
17
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/agents/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH;;GAEG;AACH,MAAM,CAAN,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,qCAAe,CAAA;IACf,yCAAmB,CAAA;IACnB,mCAAa,CAAA;IACb,6CAAuB,CAAA;IACvB,yCAAmB,CAAA;AACrB,CAAC,EANW,kBAAkB,KAAlB,kBAAkB,QAM7B"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { AgentInputs } from './types.js';
7
+ /**
8
+ * Simple template string replacement for agent prompts.
9
+ * Replaces ${key} placeholders with values from the inputs object.
10
+ *
11
+ * @param template The template string with ${key} placeholders
12
+ * @param inputs The input values to substitute
13
+ * @returns The template with placeholders replaced
14
+ */
15
+ export declare function templateString(template: string, inputs: AgentInputs): string;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Simple template string replacement for agent prompts.
8
+ * Replaces ${key} placeholders with values from the inputs object.
9
+ *
10
+ * @param template The template string with ${key} placeholders
11
+ * @param inputs The input values to substitute
12
+ * @returns The template with placeholders replaced
13
+ */
14
+ export function templateString(template, inputs) {
15
+ const placeholderRegex = /\$\{(\w+)\}/g;
16
+ // First, find all unique keys required by the template.
17
+ const requiredKeys = new Set(Array.from(template.matchAll(placeholderRegex), (match) => match[1]));
18
+ // Check if all required keys exist in the inputs.
19
+ const inputKeys = new Set(Object.keys(inputs));
20
+ const missingKeys = Array.from(requiredKeys).filter((key) => !inputKeys.has(key));
21
+ if (missingKeys.length > 0) {
22
+ throw new Error(`Missing input values for the following keys: ${missingKeys.join(', ')}`);
23
+ }
24
+ // Perform the replacement using a replacer function.
25
+ return template.replace(placeholderRegex, (_match, key) => String(inputs[key]));
26
+ }
27
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/agents/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB,EAAE,MAAmB;IAClE,MAAM,gBAAgB,GAAG,cAAc,CAAC;IAExC,wDAAwD;IACxD,MAAM,YAAY,GAAG,IAAI,GAAG,CAC1B,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CACrE,CAAC;IAEF,kDAAkD;IAClD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/C,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,CACjD,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAC7B,CAAC;IAEF,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,gDAAgD,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACzE,CAAC;IACJ,CAAC;IAED,qDAAqD;IACrD,OAAO,QAAQ,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CACxD,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CACpB,CAAC;AACJ,CAAC"}
@@ -40,13 +40,13 @@ export declare const ProviderOAuthConfigSchema: z.ZodObject<{
40
40
  scopes: z.ZodArray<z.ZodString, "many">;
41
41
  }, "strip", z.ZodTypeAny, {
42
42
  clientId: string;
43
- provider: "qwen" | "gemini";
43
+ provider: "gemini" | "qwen";
44
44
  scopes: string[];
45
45
  authorizationEndpoint: string;
46
46
  tokenEndpoint: string;
47
47
  }, {
48
48
  clientId: string;
49
- provider: "qwen" | "gemini";
49
+ provider: "gemini" | "qwen";
50
50
  scopes: string[];
51
51
  authorizationEndpoint: string;
52
52
  tokenEndpoint: string;
@@ -111,14 +111,14 @@ export declare const AuthStatusSchema: z.ZodObject<{
111
111
  expiresIn: z.ZodOptional<z.ZodNumber>;
112
112
  oauthEnabled: z.ZodOptional<z.ZodBoolean>;
113
113
  }, "strip", z.ZodTypeAny, {
114
- provider: string;
115
114
  authType: "none" | "api-key" | "oauth";
115
+ provider: string;
116
116
  authenticated: boolean;
117
117
  expiresIn?: number | undefined;
118
118
  oauthEnabled?: boolean | undefined;
119
119
  }, {
120
- provider: string;
121
120
  authType: "none" | "api-key" | "oauth";
121
+ provider: string;
122
122
  authenticated: boolean;
123
123
  expiresIn?: number | undefined;
124
124
  oauthEnabled?: boolean | undefined;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { type Credentials } from 'google-auth-library';
7
+ import { HybridTokenStorage } from '../mcp/token-storage/hybrid-token-storage.js';
8
+ export declare class OAuthCredentialStorage {
9
+ private readonly storage;
10
+ constructor(storage?: HybridTokenStorage);
11
+ /**
12
+ * Load cached OAuth credentials
13
+ */
14
+ loadCredentials(): Promise<Credentials | null>;
15
+ /**
16
+ * Save OAuth credentials
17
+ */
18
+ saveCredentials(credentials: Credentials): Promise<void>;
19
+ /**
20
+ * Clear cached OAuth credentials
21
+ */
22
+ clearCredentials(): Promise<void>;
23
+ /**
24
+ * Migrate credentials from old file-based storage to keychain
25
+ */
26
+ private migrateFromFileStorage;
27
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { HybridTokenStorage } from '../mcp/token-storage/hybrid-token-storage.js';
7
+ import { OAUTH_FILE, Storage } from '../config/storage.js';
8
+ import * as path from 'node:path';
9
+ import * as os from 'node:os';
10
+ import { promises as fs } from 'node:fs';
11
+ const KEYCHAIN_SERVICE_NAME = 'llxprt-code-oauth';
12
+ const MAIN_ACCOUNT_KEY = 'main-account';
13
+ function getLegacyCredentialPaths() {
14
+ const legacyPaths = [Storage.getOAuthCredsPath()];
15
+ const homeDir = os.homedir();
16
+ if (homeDir) {
17
+ legacyPaths.push(path.join(homeDir, '.gemini', OAUTH_FILE));
18
+ }
19
+ return Array.from(new Set(legacyPaths));
20
+ }
21
+ export class OAuthCredentialStorage {
22
+ storage;
23
+ constructor(storage = new HybridTokenStorage(KEYCHAIN_SERVICE_NAME)) {
24
+ this.storage = storage;
25
+ }
26
+ /**
27
+ * Load cached OAuth credentials
28
+ */
29
+ async loadCredentials() {
30
+ try {
31
+ const credentials = await this.storage.getCredentials(MAIN_ACCOUNT_KEY);
32
+ if (credentials?.token) {
33
+ const { accessToken, refreshToken, expiresAt, tokenType, scope } = credentials.token;
34
+ // Convert from OAuthCredentials format to Google Credentials format
35
+ const googleCreds = {
36
+ access_token: accessToken,
37
+ refresh_token: refreshToken || undefined,
38
+ token_type: tokenType || undefined,
39
+ scope: scope || undefined,
40
+ };
41
+ if (expiresAt) {
42
+ googleCreds.expiry_date = expiresAt;
43
+ }
44
+ return googleCreds;
45
+ }
46
+ // Fallback: Try to migrate from old file-based storage
47
+ return await this.migrateFromFileStorage();
48
+ }
49
+ catch (error) {
50
+ console.error(error);
51
+ throw new Error('Failed to load OAuth credentials');
52
+ }
53
+ }
54
+ /**
55
+ * Save OAuth credentials
56
+ */
57
+ async saveCredentials(credentials) {
58
+ if (!credentials.access_token) {
59
+ throw new Error('Attempted to save credentials without an access token.');
60
+ }
61
+ // Convert Google Credentials to OAuthCredentials format
62
+ const mcpCredentials = {
63
+ serverName: MAIN_ACCOUNT_KEY,
64
+ token: {
65
+ accessToken: credentials.access_token,
66
+ refreshToken: credentials.refresh_token || undefined,
67
+ tokenType: credentials.token_type || 'Bearer',
68
+ scope: credentials.scope || undefined,
69
+ expiresAt: credentials.expiry_date || undefined,
70
+ },
71
+ updatedAt: Date.now(),
72
+ };
73
+ await this.storage.setCredentials(mcpCredentials);
74
+ }
75
+ /**
76
+ * Clear cached OAuth credentials
77
+ */
78
+ async clearCredentials() {
79
+ try {
80
+ await this.storage.deleteCredentials(MAIN_ACCOUNT_KEY);
81
+ // Also try to remove the old file if it exists
82
+ await Promise.all(getLegacyCredentialPaths().map((legacyPath) => fs.rm(legacyPath, { force: true }).catch(() => { })));
83
+ }
84
+ catch (error) {
85
+ console.error(error);
86
+ throw new Error('Failed to clear OAuth credentials');
87
+ }
88
+ }
89
+ /**
90
+ * Migrate credentials from old file-based storage to keychain
91
+ */
92
+ async migrateFromFileStorage() {
93
+ for (const legacyPath of getLegacyCredentialPaths()) {
94
+ let credsJson;
95
+ try {
96
+ credsJson = await fs.readFile(legacyPath, 'utf-8');
97
+ }
98
+ catch (error) {
99
+ if (typeof error === 'object' &&
100
+ error !== null &&
101
+ 'code' in error &&
102
+ error.code === 'ENOENT') {
103
+ continue;
104
+ }
105
+ throw error;
106
+ }
107
+ const credentials = JSON.parse(credsJson);
108
+ await this.saveCredentials(credentials);
109
+ await fs.rm(legacyPath, { force: true }).catch(() => { });
110
+ return credentials;
111
+ }
112
+ return null;
113
+ }
114
+ }
115
+ //# sourceMappingURL=oauth-credential-storage.js.map