@yagr/agent 0.2.11 → 0.2.13

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 (212) hide show
  1. package/dist/agent.d.ts +16 -12
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +40 -33
  4. package/dist/agent.js.map +1 -1
  5. package/dist/cli.d.ts +1 -0
  6. package/dist/cli.d.ts.map +1 -1
  7. package/dist/cli.js +109 -17
  8. package/dist/cli.js.map +1 -1
  9. package/dist/config/n8n-config-service.d.ts +16 -0
  10. package/dist/config/n8n-config-service.d.ts.map +1 -1
  11. package/dist/config/n8n-config-service.js +32 -1
  12. package/dist/config/n8n-config-service.js.map +1 -1
  13. package/dist/config/yagr-config-service.d.ts +16 -0
  14. package/dist/config/yagr-config-service.d.ts.map +1 -1
  15. package/dist/config/yagr-config-service.js.map +1 -1
  16. package/dist/engine/engine.d.ts +15 -1
  17. package/dist/engine/engine.d.ts.map +1 -1
  18. package/dist/gateway/cli.d.ts +2 -2
  19. package/dist/gateway/cli.d.ts.map +1 -1
  20. package/dist/gateway/cli.js +6 -3
  21. package/dist/gateway/cli.js.map +1 -1
  22. package/dist/gateway/format-message.d.ts +8 -4
  23. package/dist/gateway/format-message.d.ts.map +1 -1
  24. package/dist/gateway/format-message.js +10 -5
  25. package/dist/gateway/format-message.js.map +1 -1
  26. package/dist/gateway/interactive-ui.d.ts +2 -2
  27. package/dist/gateway/interactive-ui.d.ts.map +1 -1
  28. package/dist/gateway/interactive-ui.js +87 -82
  29. package/dist/gateway/interactive-ui.js.map +1 -1
  30. package/dist/gateway/manager.d.ts +6 -6
  31. package/dist/gateway/manager.d.ts.map +1 -1
  32. package/dist/gateway/manager.js.map +1 -1
  33. package/dist/gateway/telegram.d.ts +5 -5
  34. package/dist/gateway/telegram.d.ts.map +1 -1
  35. package/dist/gateway/telegram.js +100 -101
  36. package/dist/gateway/telegram.js.map +1 -1
  37. package/dist/gateway/webui.d.ts +52 -5
  38. package/dist/gateway/webui.d.ts.map +1 -1
  39. package/dist/gateway/webui.js +109 -237
  40. package/dist/gateway/webui.js.map +1 -1
  41. package/dist/gateway/workflow-diagram.d.ts +19 -0
  42. package/dist/gateway/workflow-diagram.d.ts.map +1 -0
  43. package/dist/gateway/workflow-diagram.js +124 -0
  44. package/dist/gateway/workflow-diagram.js.map +1 -0
  45. package/dist/index.d.ts +9 -2
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +6 -1
  48. package/dist/index.js.map +1 -1
  49. package/dist/llm/anthropic-account.d.ts +2 -1
  50. package/dist/llm/anthropic-account.d.ts.map +1 -1
  51. package/dist/llm/anthropic-account.js +1 -1
  52. package/dist/llm/anthropic-account.js.map +1 -1
  53. package/dist/llm/capability-resolver.d.ts +10 -0
  54. package/dist/llm/capability-resolver.d.ts.map +1 -0
  55. package/dist/llm/capability-resolver.js +93 -0
  56. package/dist/llm/capability-resolver.js.map +1 -0
  57. package/dist/llm/copilot-account.d.ts +2 -1
  58. package/dist/llm/copilot-account.d.ts.map +1 -1
  59. package/dist/llm/copilot-account.js +323 -32
  60. package/dist/llm/copilot-account.js.map +1 -1
  61. package/dist/llm/create-language-model.d.ts.map +1 -1
  62. package/dist/llm/create-language-model.js +12 -171
  63. package/dist/llm/create-language-model.js.map +1 -1
  64. package/dist/llm/model-capabilities.d.ts +32 -0
  65. package/dist/llm/model-capabilities.d.ts.map +1 -0
  66. package/dist/llm/model-capabilities.js +144 -0
  67. package/dist/llm/model-capabilities.js.map +1 -0
  68. package/dist/llm/openai-account.d.ts +2 -1
  69. package/dist/llm/openai-account.d.ts.map +1 -1
  70. package/dist/llm/openai-account.js +29 -17
  71. package/dist/llm/openai-account.js.map +1 -1
  72. package/dist/llm/provider-discovery.d.ts +1 -1
  73. package/dist/llm/provider-discovery.d.ts.map +1 -1
  74. package/dist/llm/provider-discovery.js +3 -34
  75. package/dist/llm/provider-discovery.js.map +1 -1
  76. package/dist/llm/provider-metadata.d.ts +27 -0
  77. package/dist/llm/provider-metadata.d.ts.map +1 -0
  78. package/dist/llm/provider-metadata.js +327 -0
  79. package/dist/llm/provider-metadata.js.map +1 -0
  80. package/dist/llm/provider-plugin.d.ts +41 -0
  81. package/dist/llm/provider-plugin.d.ts.map +1 -0
  82. package/dist/llm/provider-plugin.js +429 -0
  83. package/dist/llm/provider-plugin.js.map +1 -0
  84. package/dist/llm/provider-registry.d.ts +5 -1
  85. package/dist/llm/provider-registry.d.ts.map +1 -1
  86. package/dist/llm/provider-registry.js +7 -24
  87. package/dist/llm/provider-registry.js.map +1 -1
  88. package/dist/llm/proxy-runtime.d.ts.map +1 -1
  89. package/dist/llm/proxy-runtime.js +16 -63
  90. package/dist/llm/proxy-runtime.js.map +1 -1
  91. package/dist/llm/test-model-policy.d.ts.map +1 -1
  92. package/dist/llm/test-model-policy.js +8 -10
  93. package/dist/llm/test-model-policy.js.map +1 -1
  94. package/dist/llm/tool-schema.d.ts +4 -0
  95. package/dist/llm/tool-schema.d.ts.map +1 -0
  96. package/dist/llm/tool-schema.js +80 -0
  97. package/dist/llm/tool-schema.js.map +1 -0
  98. package/dist/prompt/build-system-prompt.d.ts +3 -3
  99. package/dist/prompt/build-system-prompt.d.ts.map +1 -1
  100. package/dist/prompt/build-system-prompt.js +2 -0
  101. package/dist/prompt/build-system-prompt.js.map +1 -1
  102. package/dist/runtime/completion-gate.d.ts +4 -0
  103. package/dist/runtime/completion-gate.d.ts.map +1 -1
  104. package/dist/runtime/completion-gate.js +13 -2
  105. package/dist/runtime/completion-gate.js.map +1 -1
  106. package/dist/runtime/context-compaction.d.ts.map +1 -1
  107. package/dist/runtime/context-compaction.js +6 -5
  108. package/dist/runtime/context-compaction.js.map +1 -1
  109. package/dist/runtime/outcome.d.ts +3 -0
  110. package/dist/runtime/outcome.d.ts.map +1 -1
  111. package/dist/runtime/outcome.js +40 -3
  112. package/dist/runtime/outcome.js.map +1 -1
  113. package/dist/runtime/policy-hooks.d.ts +4 -0
  114. package/dist/runtime/policy-hooks.d.ts.map +1 -1
  115. package/dist/runtime/policy-hooks.js +137 -0
  116. package/dist/runtime/policy-hooks.js.map +1 -1
  117. package/dist/runtime/required-actions.d.ts +5 -0
  118. package/dist/runtime/required-actions.d.ts.map +1 -1
  119. package/dist/runtime/required-actions.js +22 -4
  120. package/dist/runtime/required-actions.js.map +1 -1
  121. package/dist/runtime/run-engine.d.ts +6 -3
  122. package/dist/runtime/run-engine.d.ts.map +1 -1
  123. package/dist/runtime/run-engine.js +699 -97
  124. package/dist/runtime/run-engine.js.map +1 -1
  125. package/dist/runtime/tool-runtime-strategy.d.ts +29 -0
  126. package/dist/runtime/tool-runtime-strategy.d.ts.map +1 -0
  127. package/dist/runtime/tool-runtime-strategy.js +102 -0
  128. package/dist/runtime/tool-runtime-strategy.js.map +1 -0
  129. package/dist/runtime/user-visible-updates.d.ts +12 -0
  130. package/dist/runtime/user-visible-updates.d.ts.map +1 -0
  131. package/dist/runtime/user-visible-updates.js +93 -0
  132. package/dist/runtime/user-visible-updates.js.map +1 -0
  133. package/dist/setup/application-services.d.ts +199 -0
  134. package/dist/setup/application-services.d.ts.map +1 -0
  135. package/dist/setup/application-services.js +468 -0
  136. package/dist/setup/application-services.js.map +1 -0
  137. package/dist/setup/setup-wizard.d.ts +1 -0
  138. package/dist/setup/setup-wizard.d.ts.map +1 -1
  139. package/dist/setup/setup-wizard.js +16 -18
  140. package/dist/setup/setup-wizard.js.map +1 -1
  141. package/dist/setup/status.d.ts +21 -0
  142. package/dist/setup/status.d.ts.map +1 -0
  143. package/dist/setup/status.js +47 -0
  144. package/dist/setup/status.js.map +1 -0
  145. package/dist/setup.d.ts +3 -14
  146. package/dist/setup.d.ts.map +1 -1
  147. package/dist/setup.js +30 -256
  148. package/dist/setup.js.map +1 -1
  149. package/dist/tools/build-tools.d.ts +160 -18
  150. package/dist/tools/build-tools.d.ts.map +1 -1
  151. package/dist/tools/build-tools.js +11 -1
  152. package/dist/tools/build-tools.js.map +1 -1
  153. package/dist/tools/deploy.d.ts +2 -2
  154. package/dist/tools/deploy.d.ts.map +1 -1
  155. package/dist/tools/deploy.js.map +1 -1
  156. package/dist/tools/generate-workflow.d.ts +9 -9
  157. package/dist/tools/generate-workflow.d.ts.map +1 -1
  158. package/dist/tools/generate-workflow.js.map +1 -1
  159. package/dist/tools/index.d.ts +1 -1
  160. package/dist/tools/index.d.ts.map +1 -1
  161. package/dist/tools/index.js.map +1 -1
  162. package/dist/tools/list-workflows.d.ts +2 -2
  163. package/dist/tools/list-workflows.d.ts.map +1 -1
  164. package/dist/tools/list-workflows.js.map +1 -1
  165. package/dist/tools/manage-workflow.d.ts +2 -2
  166. package/dist/tools/manage-workflow.d.ts.map +1 -1
  167. package/dist/tools/manage-workflow.js.map +1 -1
  168. package/dist/tools/n8nac.d.ts +121 -4
  169. package/dist/tools/n8nac.d.ts.map +1 -1
  170. package/dist/tools/n8nac.js +183 -38
  171. package/dist/tools/n8nac.js.map +1 -1
  172. package/dist/tools/node-info.d.ts +2 -2
  173. package/dist/tools/node-info.d.ts.map +1 -1
  174. package/dist/tools/node-info.js.map +1 -1
  175. package/dist/tools/observer.d.ts +6 -35
  176. package/dist/tools/observer.d.ts.map +1 -1
  177. package/dist/tools/observer.js +18 -0
  178. package/dist/tools/observer.js.map +1 -1
  179. package/dist/tools/present-workflow-result.d.ts +1 -0
  180. package/dist/tools/present-workflow-result.d.ts.map +1 -1
  181. package/dist/tools/present-workflow-result.js +24 -5
  182. package/dist/tools/present-workflow-result.js.map +1 -1
  183. package/dist/tools/request-required-action.d.ts +7 -3
  184. package/dist/tools/request-required-action.d.ts.map +1 -1
  185. package/dist/tools/request-required-action.js +5 -3
  186. package/dist/tools/request-required-action.js.map +1 -1
  187. package/dist/tools/search-nodes.d.ts +2 -2
  188. package/dist/tools/search-nodes.d.ts.map +1 -1
  189. package/dist/tools/search-nodes.js.map +1 -1
  190. package/dist/tools/search-templates.d.ts +2 -2
  191. package/dist/tools/search-templates.d.ts.map +1 -1
  192. package/dist/tools/search-templates.js.map +1 -1
  193. package/dist/tools/toolsets.d.ts +11 -0
  194. package/dist/tools/toolsets.d.ts.map +1 -0
  195. package/dist/tools/toolsets.js +49 -0
  196. package/dist/tools/toolsets.js.map +1 -0
  197. package/dist/tools/validate.d.ts +2 -2
  198. package/dist/tools/validate.d.ts.map +1 -1
  199. package/dist/tools/validate.js.map +1 -1
  200. package/dist/tools/write-workspace-file.d.ts +25 -9
  201. package/dist/tools/write-workspace-file.d.ts.map +1 -1
  202. package/dist/tools/write-workspace-file.js +27 -4
  203. package/dist/tools/write-workspace-file.js.map +1 -1
  204. package/dist/types.d.ts +1 -0
  205. package/dist/types.d.ts.map +1 -1
  206. package/dist/webui/app.js +97 -101
  207. package/dist/webui/app.js.map +4 -4
  208. package/package.json +6 -5
  209. package/dist/llm/google-account.d.ts +0 -31
  210. package/dist/llm/google-account.d.ts.map +0 -1
  211. package/dist/llm/google-account.js +0 -851
  212. package/dist/llm/google-account.js.map +0 -1
@@ -1,13 +1,60 @@
1
- import { YagrConfigService } from '../config/yagr-config-service.js';
2
- import type { Engine } from '../engine/engine.js';
1
+ import { YagrConfigService, type YagrConfigStoreLike } from '../config/yagr-config-service.js';
2
+ import type { EngineRuntimePort } from '../engine/engine.js';
3
3
  import type { GatewayRuntimeHandle } from './types.js';
4
- import type { YagrRunOptions } from '../types.js';
4
+ import type { YagrPhaseEvent, YagrRunOptions, YagrStateEvent, YagrToolEvent } from '../types.js';
5
5
  export interface WebUiGatewayStatus {
6
6
  configured: boolean;
7
7
  host: string;
8
8
  port: number;
9
9
  url: string;
10
10
  }
11
- export declare function getWebUiGatewayStatus(configService?: YagrConfigService): WebUiGatewayStatus;
12
- export declare function createWebUiGatewayRuntime(engineResolver: () => Promise<Engine>, options?: YagrRunOptions, configService?: YagrConfigService): GatewayRuntimeHandle;
11
+ type WebUiChatStreamEvent = {
12
+ type: 'start';
13
+ sessionId: string;
14
+ message: string;
15
+ } | {
16
+ type: 'phase';
17
+ phase: string;
18
+ status: 'started' | 'completed';
19
+ message: string;
20
+ } | {
21
+ type: 'state';
22
+ state: string;
23
+ message: string;
24
+ } | {
25
+ type: 'progress';
26
+ tone: 'info' | 'success' | 'error';
27
+ title: string;
28
+ detail?: string;
29
+ phase?: string;
30
+ } | {
31
+ type: 'text-delta';
32
+ delta: string;
33
+ } | {
34
+ type: 'final';
35
+ sessionId: string;
36
+ response: string;
37
+ finalState: string;
38
+ requiredActions?: Array<{
39
+ title: string;
40
+ message: string;
41
+ }>;
42
+ } | {
43
+ type: 'error';
44
+ error: string;
45
+ } | {
46
+ type: 'embed';
47
+ kind: 'workflow';
48
+ workflowId: string;
49
+ url: string;
50
+ targetUrl?: string;
51
+ title?: string;
52
+ diagram?: string;
53
+ };
54
+ export declare function mapToolEventToWebUiStreamEvent(event: YagrToolEvent): WebUiChatStreamEvent | undefined;
55
+ export declare function mapPhaseEventToWebUiStreamEvent(event: YagrPhaseEvent): WebUiChatStreamEvent | undefined;
56
+ export declare function mapStateEventToWebUiStreamEvent(event: YagrStateEvent): WebUiChatStreamEvent | undefined;
57
+ export declare function getWebUiGatewayStatus(configService?: YagrConfigStoreLike): WebUiGatewayStatus;
58
+ export declare function createWebUiGatewayRuntime(engineResolver: () => Promise<EngineRuntimePort>, options?: YagrRunOptions, configService?: YagrConfigService): GatewayRuntimeHandle;
59
+ export {};
13
60
  //# sourceMappingURL=webui.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"webui.d.ts","sourceRoot":"","sources":["../../src/gateway/webui.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAErE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAOlD,OAAO,KAAK,EAAW,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,KAAK,EAIV,cAAc,EAGf,MAAM,aAAa,CAAC;AAgCrB,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,OAAO,CA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}
@@ -3,24 +3,21 @@ import { createServer } from 'node:http';
3
3
  import { readFile } from 'node:fs/promises';
4
4
  import path from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
- import { N8nApiClient, WorkspaceSetupService, getDisplayProjectName, } from 'n8nac';
7
- import { Command } from 'commander';
8
- import { UpdateAiCommand } from 'n8nac/dist/commands/init-ai.js';
9
- import { YagrAgent } from '../agent.js';
10
- import { resolveWorkflowDir, YagrN8nConfigService } from '../config/n8n-config-service.js';
6
+ import { getDisplayProjectName, } from 'n8nac';
7
+ import { YagrSessionAgent } from '../agent.js';
8
+ import { YagrN8nConfigService } from '../config/n8n-config-service.js';
11
9
  import { YagrConfigService } from '../config/yagr-config-service.js';
12
- import { getYagrN8nWorkspaceDir } from '../config/yagr-home.js';
13
- import { createOnboardingToken, getTelegramGatewayStatus, resetTelegramGateway, } from './telegram.js';
14
- import { getYagrSetupStatus } from '../setup.js';
10
+ import { resolveTelegramBotIdentity } from './telegram.js';
11
+ import { YagrSetupApplicationService } from '../setup/application-services.js';
15
12
  import { resolveLanguageModelConfig } from '../llm/create-language-model.js';
16
- import { fetchAvailableModels } from '../llm/provider-discovery.js';
17
- import { providerRequiresApiKey, YAGR_MODEL_PROVIDERS, } from '../llm/provider-registry.js';
13
+ import { providerRequiresApiKey, YAGR_SELECTABLE_MODEL_PROVIDERS, } from '../llm/provider-registry.js';
18
14
  import { resolveManagedN8nWorkflowOpen } from '../n8n-local/workflow-open.js';
15
+ import { mapPhaseEventToUserVisibleUpdate, mapStateEventToUserVisibleUpdate, mapToolEventToUserVisibleUpdate, } from '../runtime/user-visible-updates.js';
19
16
  const __filename = fileURLToPath(import.meta.url);
20
17
  const __dirname = path.dirname(__filename);
21
18
  const DEFAULT_HOST = '127.0.0.1';
22
19
  const DEFAULT_PORT = 3789;
23
- const VALID_PROVIDERS = [...YAGR_MODEL_PROVIDERS];
20
+ const VALID_PROVIDERS = [...YAGR_SELECTABLE_MODEL_PROVIDERS];
24
21
  const ACTIVE_WEBUI_SURFACES = ['webui'];
25
22
  const WEB_UI_HTML = `<!doctype html>
26
23
  <html lang="en">
@@ -35,6 +32,56 @@ const WEB_UI_HTML = `<!doctype html>
35
32
  <div id="root"></div>
36
33
  </body>
37
34
  </html>`;
35
+ export function mapToolEventToWebUiStreamEvent(event) {
36
+ const userFacingStatus = mapToolEventToUserVisibleUpdate(event);
37
+ if (userFacingStatus) {
38
+ return {
39
+ type: 'progress',
40
+ tone: userFacingStatus.tone,
41
+ title: userFacingStatus.title,
42
+ detail: userFacingStatus.detail,
43
+ ...(userFacingStatus.phase ? { phase: userFacingStatus.phase } : {}),
44
+ };
45
+ }
46
+ if (event.type === 'embed') {
47
+ return {
48
+ type: 'embed',
49
+ kind: event.kind,
50
+ workflowId: event.workflowId,
51
+ url: event.url,
52
+ targetUrl: event.targetUrl,
53
+ title: event.title,
54
+ diagram: event.diagram,
55
+ };
56
+ }
57
+ return undefined;
58
+ }
59
+ export function mapPhaseEventToWebUiStreamEvent(event) {
60
+ const update = mapPhaseEventToUserVisibleUpdate(event);
61
+ if (!update) {
62
+ return undefined;
63
+ }
64
+ return {
65
+ type: 'progress',
66
+ tone: update.tone,
67
+ title: update.title,
68
+ detail: update.detail,
69
+ ...(update.phase ? { phase: update.phase } : {}),
70
+ };
71
+ }
72
+ export function mapStateEventToWebUiStreamEvent(event) {
73
+ const update = mapStateEventToUserVisibleUpdate(event);
74
+ if (!update) {
75
+ return undefined;
76
+ }
77
+ return {
78
+ type: 'progress',
79
+ tone: update.tone,
80
+ title: update.title,
81
+ detail: update.detail,
82
+ ...(update.phase ? { phase: update.phase } : {}),
83
+ };
84
+ }
38
85
  function isAbortError(error) {
39
86
  return error instanceof Error && error.name === 'AbortError';
40
87
  }
@@ -55,22 +102,8 @@ function getWebUiConfig(configService = new YagrConfigService()) {
55
102
  port: sanitizePort(config.gateway?.webui?.port),
56
103
  };
57
104
  }
58
- function persistWebUiConfig(configService = new YagrConfigService(), nextConfig) {
59
- const normalized = {
60
- host: sanitizeHost(nextConfig.host),
61
- port: sanitizePort(nextConfig.port),
62
- };
63
- configService.updateLocalConfig((localConfig) => ({
64
- ...localConfig,
65
- gateway: {
66
- ...localConfig.gateway,
67
- webui: normalized,
68
- },
69
- }));
70
- return normalized;
71
- }
72
105
  export function getWebUiGatewayStatus(configService = new YagrConfigService()) {
73
- const config = persistWebUiConfig(configService, getWebUiConfig(configService));
106
+ const config = getWebUiConfig(configService);
74
107
  return {
75
108
  configured: true,
76
109
  host: config.host,
@@ -97,11 +130,15 @@ class WebUiGateway {
97
130
  server;
98
131
  enginePromise;
99
132
  agents = new Map();
133
+ setupService;
100
134
  constructor(engineResolver, options, configService, status) {
101
135
  this.engineResolver = engineResolver;
102
136
  this.options = options;
103
137
  this.configService = configService;
104
138
  this.status = status;
139
+ this.setupService = new YagrSetupApplicationService(this.configService, new YagrN8nConfigService(), {
140
+ resolveTelegramIdentity: resolveTelegramBotIdentity,
141
+ });
105
142
  }
106
143
  async start() {
107
144
  if (this.server) {
@@ -160,11 +197,10 @@ class WebUiGateway {
160
197
  }
161
198
  if (method === 'POST' && url.pathname === '/api/n8n/projects') {
162
199
  const body = await this.readJson(request);
163
- const projects = await this.fetchN8nProjects(String(body.host ?? ''), body.apiKey ? String(body.apiKey) : undefined);
164
- const current = new YagrN8nConfigService().getLocalConfig();
200
+ const projects = await this.setupService.fetchN8nProjects(String(body.host ?? ''), body.apiKey ? String(body.apiKey) : undefined);
165
201
  this.sendJson(response, 200, {
166
202
  projects: projects.map((project) => ({ id: project.id, name: getDisplayProjectName(project) })),
167
- selectedProjectId: current.projectId,
203
+ selectedProjectId: this.setupService.getSelectedN8nProjectId(),
168
204
  });
169
205
  return;
170
206
  }
@@ -185,18 +221,13 @@ class WebUiGateway {
185
221
  if (method === 'POST' && url.pathname === '/api/llm/models') {
186
222
  const body = await this.readJson(request);
187
223
  const provider = this.assertProvider(String(body.provider ?? ''));
188
- const apiKey = body.apiKey !== undefined ? String(body.apiKey) : this.configService.getApiKey(provider);
189
- if (providerRequiresApiKey(provider) && !apiKey) {
190
- throw new Error(`No API key available for ${provider}. Save one first.`);
191
- }
192
- const configuredLlm = this.configService.getLocalConfig();
193
- const baseUrl = body.baseUrl
194
- ? String(body.baseUrl)
195
- : configuredLlm.provider === provider
196
- ? configuredLlm.baseUrl
197
- : undefined;
198
224
  this.sendJson(response, 200, {
199
- models: await fetchAvailableModels(provider, apiKey, baseUrl),
225
+ models: await this.setupService.fetchModelsForSelection({
226
+ provider,
227
+ apiKey: body.apiKey !== undefined ? String(body.apiKey) : undefined,
228
+ baseUrl: body.baseUrl ? String(body.baseUrl) : undefined,
229
+ requiresApiKey: providerRequiresApiKey,
230
+ }),
200
231
  });
201
232
  return;
202
233
  }
@@ -208,15 +239,12 @@ class WebUiGateway {
208
239
  if (!model) {
209
240
  throw new Error('Model is required.');
210
241
  }
211
- if (apiKey) {
212
- this.configService.saveApiKey(provider, apiKey);
213
- }
214
- this.configService.updateLocalConfig((localConfig) => ({
215
- ...localConfig,
242
+ this.setupService.saveLlmConfig({
216
243
  provider,
244
+ apiKey,
217
245
  model,
218
246
  baseUrl: body.baseUrl ? String(body.baseUrl) : undefined,
219
- }));
247
+ });
220
248
  this.sendJson(response, 200, { snapshot: await this.buildSnapshot() });
221
249
  return;
222
250
  }
@@ -225,33 +253,18 @@ class WebUiGateway {
225
253
  const enabledSurfaces = Array.isArray(body.enabledSurfaces)
226
254
  ? body.enabledSurfaces.filter((surface) => surface === 'telegram' || surface === 'whatsapp')
227
255
  : [];
228
- this.configService.setEnabledGatewaySurfaces(enabledSurfaces);
256
+ this.setupService.saveSurfaces({ surfaces: enabledSurfaces });
229
257
  this.sendJson(response, 200, { snapshot: await this.buildSnapshot() });
230
258
  return;
231
259
  }
232
260
  if (method === 'POST' && url.pathname === '/api/telegram/configure') {
233
261
  const body = await this.readJson(request);
234
- const botToken = String(body.botToken ?? '').trim();
235
- if (!botToken || !botToken.includes(':')) {
236
- throw new Error('Enter a valid Telegram BotFather token.');
237
- }
238
- const identity = await resolveTelegramBotIdentity(botToken);
239
- this.configService.saveTelegramBotToken(botToken);
240
- this.configService.enableGatewaySurface('telegram');
241
- this.configService.updateLocalConfig((localConfig) => ({
242
- ...localConfig,
243
- telegram: {
244
- ...localConfig.telegram,
245
- botUsername: identity.username,
246
- onboardingToken: localConfig.telegram?.onboardingToken ?? createOnboardingToken(),
247
- linkedChats: localConfig.telegram?.linkedChats ?? [],
248
- },
249
- }));
262
+ await this.setupService.configureTelegram(String(body.botToken ?? ''));
250
263
  this.sendJson(response, 200, { snapshot: await this.buildSnapshot() });
251
264
  return;
252
265
  }
253
266
  if (method === 'POST' && url.pathname === '/api/telegram/reset') {
254
- resetTelegramGateway(this.configService);
267
+ this.setupService.resetTelegram();
255
268
  this.sendJson(response, 200, { snapshot: await this.buildSnapshot() });
256
269
  return;
257
270
  }
@@ -262,7 +275,7 @@ class WebUiGateway {
262
275
  if (!message) {
263
276
  throw new Error('Message is required.');
264
277
  }
265
- const setupStatus = getYagrSetupStatus(this.configService, new YagrN8nConfigService(), {
278
+ const setupStatus = this.setupService.getSetupStatus({
266
279
  activeSurfaces: [...ACTIVE_WEBUI_SURFACES],
267
280
  });
268
281
  if (!setupStatus.ready) {
@@ -317,70 +330,12 @@ class WebUiGateway {
317
330
  this.sendJson(response, 404, { error: 'Not found' });
318
331
  }
319
332
  async buildSnapshot() {
320
- const n8nService = new YagrN8nConfigService();
321
- const n8nConfig = n8nService.getLocalConfig();
322
- const setupStatus = getYagrSetupStatus(this.configService, n8nService, {
333
+ const webUiStatus = getWebUiGatewayStatus(this.configService);
334
+ return this.setupService.buildWebUiSnapshot({
323
335
  activeSurfaces: [...ACTIVE_WEBUI_SURFACES],
336
+ webUiStatus,
337
+ selectableProviders: VALID_PROVIDERS,
324
338
  });
325
- const telegramStatus = getTelegramGatewayStatus(this.configService);
326
- const webUiStatus = getWebUiGatewayStatus(this.configService);
327
- const yagrConfig = this.configService.getLocalConfig();
328
- const enabledSurfaces = Array.from(new Set([...this.configService.getEnabledGatewaySurfaces(), ...ACTIVE_WEBUI_SURFACES]));
329
- const startableSurfaces = enabledSurfaces.filter((surface) => surface === 'webui' || (surface === 'telegram' && telegramStatus.configured));
330
- let availableModels = [];
331
- if (yagrConfig.provider) {
332
- const apiKey = this.configService.getApiKey(yagrConfig.provider);
333
- try {
334
- availableModels = await fetchAvailableModels(yagrConfig.provider, apiKey, yagrConfig.baseUrl);
335
- }
336
- catch {
337
- availableModels = [];
338
- }
339
- }
340
- return {
341
- setupStatus,
342
- gatewayStatus: {
343
- enabledSurfaces,
344
- startableSurfaces,
345
- },
346
- telegram: telegramStatus,
347
- webui: webUiStatus,
348
- yagr: {
349
- provider: yagrConfig.provider,
350
- model: yagrConfig.model,
351
- baseUrl: yagrConfig.baseUrl,
352
- providers: VALID_PROVIDERS.map((provider) => ({
353
- provider,
354
- apiKeyStored: this.configService.hasApiKey(provider),
355
- })),
356
- },
357
- n8n: {
358
- host: n8nConfig.host,
359
- syncFolder: n8nConfig.syncFolder,
360
- projectId: n8nConfig.projectId,
361
- projectName: n8nConfig.projectName,
362
- apiKeyStored: Boolean(n8nConfig.host && n8nService.getApiKey(n8nConfig.host)),
363
- projects: n8nConfig.projectId && n8nConfig.projectName ? [{ id: n8nConfig.projectId, name: n8nConfig.projectName }] : [],
364
- },
365
- availableModels,
366
- };
367
- }
368
- async fetchN8nProjects(host, apiKeyOverride) {
369
- const normalizedHost = host.trim();
370
- if (!normalizedHost) {
371
- throw new Error('n8n host is required.');
372
- }
373
- const configService = new YagrN8nConfigService();
374
- const apiKey = apiKeyOverride ?? configService.getApiKey(normalizedHost);
375
- if (!apiKey) {
376
- throw new Error('No n8n API key available for that host.');
377
- }
378
- const client = new N8nApiClient({ host: normalizedHost, apiKey });
379
- const connected = await client.testConnection();
380
- if (!connected) {
381
- throw new Error('Unable to connect to n8n with the provided URL and API key.');
382
- }
383
- return client.getProjects();
384
339
  }
385
340
  async sendManagedN8nWorkflowSession(response, target) {
386
341
  const session = resolveManagedN8nWorkflowOpen(target);
@@ -404,51 +359,12 @@ class WebUiGateway {
404
359
  this.sendText(response, 200, session.payload.fallbackPage, 'text/html; charset=utf-8');
405
360
  }
406
361
  async saveN8nConfig(input) {
407
- const host = input.host.trim();
408
- const projectId = input.projectId.trim();
409
- const syncFolder = input.syncFolder.trim() || 'workflows';
410
- if (!host) {
411
- throw new Error('n8n host is required.');
412
- }
413
- if (!projectId) {
414
- throw new Error('Select an n8n project first.');
415
- }
416
- const configService = new YagrN8nConfigService();
417
- const apiKey = input.apiKey?.trim() || configService.getApiKey(host);
418
- if (!apiKey) {
419
- throw new Error('An n8n API key is required.');
420
- }
421
- const projects = await this.fetchN8nProjects(host, apiKey);
422
- const selectedProject = projects.find((project) => project.id === projectId);
423
- if (!selectedProject) {
424
- throw new Error('The selected n8n project could not be found. Reload projects and try again.');
425
- }
426
- configService.saveApiKey(host, apiKey);
427
- configService.saveBootstrapState(host, syncFolder);
428
- const instanceIdentifier = await configService.getOrCreateInstanceIdentifier(host);
429
- const projectName = getDisplayProjectName(selectedProject);
430
- configService.saveLocalConfig({
431
- host,
432
- syncFolder,
433
- projectId: selectedProject.id,
434
- projectName,
435
- instanceIdentifier,
436
- });
437
- const workflowDir = resolveWorkflowDir({ syncFolder, instanceIdentifier, projectName });
438
- if (workflowDir) {
439
- WorkspaceSetupService.ensureWorkspaceFiles(workflowDir);
440
- }
362
+ const warning = await this.setupService.saveN8nConfig(input);
441
363
  // Invalidate the cached engine and all agent sessions so the next request
442
364
  // picks up a fresh engine built from the new config (new host, new API key).
443
365
  this.enginePromise = undefined;
444
366
  this.agents.clear();
445
- try {
446
- await refreshAiContext({ host, apiKey });
447
- return undefined;
448
- }
449
- catch (error) {
450
- return `Workspace saved, but the n8n workspace instructions refresh failed: ${error instanceof Error ? error.message : String(error)}`;
451
- }
367
+ return warning;
452
368
  }
453
369
  assertProvider(value) {
454
370
  if (!VALID_PROVIDERS.includes(value)) {
@@ -465,7 +381,7 @@ class WebUiGateway {
465
381
  this.enginePromise = this.engineResolver();
466
382
  }
467
383
  const engine = await this.enginePromise;
468
- const agent = new YagrAgent(engine);
384
+ const agent = new YagrSessionAgent(engine);
469
385
  this.agents.set(sessionId, agent);
470
386
  return agent;
471
387
  }
@@ -499,7 +415,7 @@ class WebUiGateway {
499
415
  this.sendText(response, 200, content, contentType);
500
416
  }
501
417
  async handleStreamingChat(response, sessionId, message) {
502
- const setupStatus = getYagrSetupStatus(this.configService, new YagrN8nConfigService(), {
418
+ const setupStatus = this.setupService.getSetupStatus({
503
419
  activeSurfaces: [...ACTIVE_WEBUI_SURFACES],
504
420
  });
505
421
  if (!setupStatus.ready) {
@@ -528,59 +444,38 @@ class WebUiGateway {
528
444
  response.write(`${JSON.stringify(event)}\n`);
529
445
  };
530
446
  const pushPhaseEvent = (event) => {
531
- if (event.status !== 'started') {
447
+ const mappedEvent = mapPhaseEventToWebUiStreamEvent(event);
448
+ if (mappedEvent) {
449
+ writeEvent(mappedEvent);
532
450
  return;
533
451
  }
534
- writeEvent({
535
- type: 'phase',
536
- phase: event.phase,
537
- status: event.status,
538
- message: event.message,
539
- });
540
- };
541
- const pushStateEvent = (event) => {
542
- if (event.state === 'running' || event.state === 'streaming' || event.state === 'completed') {
543
- return;
544
- }
545
- writeEvent({
546
- type: 'state',
547
- state: event.state,
548
- message: event.message,
549
- });
550
- };
551
- const pushToolEvent = (event) => {
552
- if (event.type === 'status') {
452
+ if (event.status === 'started') {
553
453
  writeEvent({
554
- type: 'progress',
555
- tone: 'info',
556
- title: event.toolName === 'reportProgress' ? 'Progress' : `Tool ${event.toolName}`,
557
- detail: event.message,
454
+ type: 'phase',
455
+ phase: event.phase,
456
+ status: event.status,
457
+ message: event.message,
558
458
  });
559
- return;
560
459
  }
561
- if (event.type === 'command-end') {
562
- if (event.exitCode === 0) {
563
- return;
564
- }
565
- writeEvent({
566
- type: 'progress',
567
- tone: 'info',
568
- title: 'Correcting commands',
569
- detail: event.message,
570
- });
460
+ };
461
+ const pushStateEvent = (event) => {
462
+ const mappedEvent = mapStateEventToWebUiStreamEvent(event);
463
+ if (mappedEvent) {
464
+ writeEvent(mappedEvent);
571
465
  return;
572
466
  }
573
- if (event.type === 'embed') {
467
+ if (event.state !== 'running' && event.state !== 'streaming' && event.state !== 'completed') {
574
468
  writeEvent({
575
- type: 'embed',
576
- kind: event.kind,
577
- workflowId: event.workflowId,
578
- url: event.url,
579
- targetUrl: event.targetUrl,
580
- title: event.title,
581
- diagram: event.diagram,
469
+ type: 'state',
470
+ state: event.state,
471
+ message: event.message,
582
472
  });
583
- return;
473
+ }
474
+ };
475
+ const pushToolEvent = (event) => {
476
+ const mappedEvent = mapToolEventToWebUiStreamEvent(event);
477
+ if (mappedEvent) {
478
+ writeEvent(mappedEvent);
584
479
  }
585
480
  };
586
481
  const pushCompactionEvent = (event) => {
@@ -664,27 +559,4 @@ class WebUiGateway {
664
559
  }
665
560
  }
666
561
  }
667
- async function resolveTelegramBotIdentity(botToken) {
668
- const { Telegraf } = await import('telegraf');
669
- const bot = new Telegraf(botToken);
670
- const me = await bot.telegram.getMe();
671
- if (!me.username) {
672
- throw new Error('Telegram bot username is missing. Configure the bot with BotFather first.');
673
- }
674
- return {
675
- username: me.username,
676
- firstName: me.first_name,
677
- };
678
- }
679
- async function refreshAiContext(credentials) {
680
- const updateAi = new UpdateAiCommand(new Command());
681
- const previousCwd = process.cwd();
682
- try {
683
- process.chdir(getYagrN8nWorkspaceDir());
684
- await updateAi.run({}, credentials);
685
- }
686
- finally {
687
- process.chdir(previousCwd);
688
- }
689
- }
690
562
  //# sourceMappingURL=webui.js.map