vibeman 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/index.js +5 -7
  2. package/dist/runtime/api/.tsbuildinfo +1 -1
  3. package/dist/runtime/api/agent/agent-service.d.ts +11 -13
  4. package/dist/runtime/api/agent/agent-service.js +25 -31
  5. package/dist/runtime/api/agent/ai-providers/claude-code-adapter.d.ts +2 -2
  6. package/dist/runtime/api/agent/ai-providers/claude-code-adapter.js +25 -36
  7. package/dist/runtime/api/agent/ai-providers/codex-cli-provider.js +48 -14
  8. package/dist/runtime/api/agent/ai-providers/types.d.ts +2 -0
  9. package/dist/runtime/api/agent/codex-cli-provider.test.js +37 -0
  10. package/dist/runtime/api/agent/parsers.d.ts +1 -0
  11. package/dist/runtime/api/agent/parsers.js +75 -8
  12. package/dist/runtime/api/agent/prompt-service.d.ts +14 -1
  13. package/dist/runtime/api/agent/prompt-service.js +123 -14
  14. package/dist/runtime/api/agent/prompt-service.test.d.ts +1 -0
  15. package/dist/runtime/api/agent/prompt-service.test.js +230 -0
  16. package/dist/runtime/api/agent/routing-policy.d.ts +14 -14
  17. package/dist/runtime/api/api/routers/ai.d.ts +6 -6
  18. package/dist/runtime/api/api/routers/ai.js +2 -17
  19. package/dist/runtime/api/api/routers/executions.d.ts +5 -5
  20. package/dist/runtime/api/api/routers/executions.js +12 -21
  21. package/dist/runtime/api/api/routers/provider-config.d.ts +165 -0
  22. package/dist/runtime/api/api/routers/provider-config.js +252 -0
  23. package/dist/runtime/api/api/routers/tasks.d.ts +10 -10
  24. package/dist/runtime/api/api/routers/workflows.d.ts +15 -16
  25. package/dist/runtime/api/api/routers/workflows.js +28 -26
  26. package/dist/runtime/api/api/routers/worktrees.d.ts +4 -5
  27. package/dist/runtime/api/api/routers/worktrees.js +11 -11
  28. package/dist/runtime/api/api/trpc.d.ts +18 -18
  29. package/dist/runtime/api/index.js +2 -10
  30. package/dist/runtime/api/lib/local-config.d.ts +245 -0
  31. package/dist/runtime/api/lib/local-config.js +288 -0
  32. package/dist/runtime/api/lib/provider-detection.d.ts +59 -0
  33. package/dist/runtime/api/lib/provider-detection.js +244 -0
  34. package/dist/runtime/api/lib/server/bootstrap.d.ts +38 -0
  35. package/dist/runtime/api/lib/server/bootstrap.js +197 -0
  36. package/dist/runtime/api/lib/server/project-root.js +24 -1
  37. package/dist/runtime/api/lib/trpc/server.d.ts +124 -31
  38. package/dist/runtime/api/lib/trpc/server.js +8 -8
  39. package/dist/runtime/api/lib/trpc/ws-server.js +2 -2
  40. package/dist/runtime/api/router.d.ts +125 -32
  41. package/dist/runtime/api/router.js +9 -31
  42. package/dist/runtime/api/settings-service.js +2 -0
  43. package/dist/runtime/api/workflows/vibing-orchestrator.d.ts +8 -3
  44. package/dist/runtime/api/workflows/vibing-orchestrator.js +182 -183
  45. package/dist/runtime/web/.next/BUILD_ID +1 -1
  46. package/dist/runtime/web/.next/app-build-manifest.json +2 -2
  47. package/dist/runtime/web/.next/build-manifest.json +2 -2
  48. package/dist/runtime/web/.next/prerender-manifest.json +3 -3
  49. package/dist/runtime/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  50. package/dist/runtime/web/.next/server/app/_not-found.html +2 -2
  51. package/dist/runtime/web/.next/server/app/_not-found.rsc +5 -5
  52. package/dist/runtime/web/.next/server/app/api/health/route.js +1 -1
  53. package/dist/runtime/web/.next/server/app/api/health/route_client-reference-manifest.js +1 -1
  54. package/dist/runtime/web/.next/server/app/api/images/[...path]/route_client-reference-manifest.js +1 -1
  55. package/dist/runtime/web/.next/server/app/api/upload/route_client-reference-manifest.js +1 -1
  56. package/dist/runtime/web/.next/server/app/index.html +2 -2
  57. package/dist/runtime/web/.next/server/app/index.rsc +6 -6
  58. package/dist/runtime/web/.next/server/app/page.js +3 -3
  59. package/dist/runtime/web/.next/server/app/page_client-reference-manifest.js +1 -1
  60. package/dist/runtime/web/.next/server/chunks/458.js +1 -1
  61. package/dist/runtime/web/.next/server/pages/404.html +2 -2
  62. package/dist/runtime/web/.next/server/pages/500.html +1 -1
  63. package/dist/runtime/web/.next/server/pages-manifest.json +1 -1
  64. package/dist/runtime/web/.next/server/server-reference-manifest.json +1 -1
  65. package/dist/runtime/web/.next/static/chunks/app/{layout-dc0cfd29075b2160.js → layout-8435322f09fd0975.js} +1 -1
  66. package/dist/runtime/web/.next/static/chunks/app/page-8c3ba579efc6f918.js +1 -0
  67. package/dist/tsconfig.tsbuildinfo +1 -1
  68. package/package.json +5 -1
  69. package/dist/runtime/web/.next/static/chunks/app/page-f34a8b196b18850b.js +0 -1
  70. /package/dist/runtime/web/.next/static/{1HR8N0rJkCvFRtbTPJMyH → mRpNgPfbYR_0wrODzlg_4}/_buildManifest.js +0 -0
  71. /package/dist/runtime/web/.next/static/{1HR8N0rJkCvFRtbTPJMyH → mRpNgPfbYR_0wrODzlg_4}/_ssgManifest.js +0 -0
@@ -30,14 +30,13 @@ const ValidateProvidersInputSchema = z.object({
30
30
  * Build AI router with required dependencies
31
31
  */
32
32
  export function buildAIRoutes(options) {
33
- const { requireAgentService } = options;
33
+ const { agentService } = options;
34
34
  return {
35
35
  /**
36
36
  * List all registered AI providers with health status
37
37
  */
38
38
  listProviders: publicProcedure.query(async () => {
39
39
  try {
40
- const agentService = requireAgentService();
41
40
  const providers = agentService.getAvailableProviders();
42
41
  const providerStatuses = await agentService.validateProviders();
43
42
  const result = Array.from(providers.entries()).map(([name, provider]) => {
@@ -65,7 +64,6 @@ export function buildAIRoutes(options) {
65
64
  */
66
65
  listModels: publicProcedure.input(ListModelsInputSchema.optional()).query(async ({ input }) => {
67
66
  try {
68
- const agentService = requireAgentService();
69
67
  if (input?.provider) {
70
68
  // Get models from specific provider
71
69
  const provider = agentService.getAvailableProviders().get(input.provider);
@@ -94,7 +92,6 @@ export function buildAIRoutes(options) {
94
92
  */
95
93
  getRoutingPolicy: publicProcedure.query(async () => {
96
94
  try {
97
- const agentService = requireAgentService();
98
95
  const policy = await agentService.getRoutingPolicyManager()?.getPolicy();
99
96
  if (!policy) {
100
97
  // Return default policy if none exists
@@ -121,7 +118,6 @@ export function buildAIRoutes(options) {
121
118
  .input(UpdateRoutingPolicyInputSchema)
122
119
  .mutation(async ({ input }) => {
123
120
  try {
124
- const agentService = requireAgentService();
125
121
  const routingManager = agentService.getRoutingPolicyManager();
126
122
  if (!routingManager) {
127
123
  throw new Error('Routing policy manager not available');
@@ -144,7 +140,6 @@ export function buildAIRoutes(options) {
144
140
  .input(SetDefaultProviderInputSchema)
145
141
  .mutation(async ({ input }) => {
146
142
  try {
147
- const agentService = requireAgentService();
148
143
  const routingManager = agentService.getRoutingPolicyManager();
149
144
  if (!routingManager) {
150
145
  throw new Error('Routing policy manager not available');
@@ -171,7 +166,6 @@ export function buildAIRoutes(options) {
171
166
  .input(SetOperationConfigInputSchema)
172
167
  .mutation(async ({ input }) => {
173
168
  try {
174
- const agentService = requireAgentService();
175
169
  const routingManager = agentService.getRoutingPolicyManager();
176
170
  if (!routingManager) {
177
171
  throw new Error('Routing policy manager not available');
@@ -206,7 +200,6 @@ export function buildAIRoutes(options) {
206
200
  .input(ValidateProvidersInputSchema.optional())
207
201
  .mutation(async ({ input }) => {
208
202
  try {
209
- const agentService = requireAgentService();
210
203
  const results = await agentService.validateProviders();
211
204
  const validation = Array.from(results.entries()).map(([name, status]) => ({
212
205
  provider: name,
@@ -239,11 +232,10 @@ export function buildAIRoutes(options) {
239
232
  * Useful for unit tests that call functions directly.
240
233
  */
241
234
  export function buildAIRouteHandlers(options) {
242
- const { requireAgentService } = options;
235
+ const { agentService } = options;
243
236
  return {
244
237
  async listProviders() {
245
238
  try {
246
- const agentService = requireAgentService();
247
239
  const providers = agentService.getAvailableProviders();
248
240
  const providerStatuses = await agentService.validateProviders();
249
241
  return Array.from(providers.entries()).map(([name, provider]) => {
@@ -264,7 +256,6 @@ export function buildAIRouteHandlers(options) {
264
256
  },
265
257
  async listModels(input) {
266
258
  try {
267
- const agentService = requireAgentService();
268
259
  if (input?.provider) {
269
260
  const provider = agentService.getAvailableProviders().get(input.provider);
270
261
  if (!provider)
@@ -279,7 +270,6 @@ export function buildAIRouteHandlers(options) {
279
270
  },
280
271
  async getRoutingPolicy() {
281
272
  try {
282
- const agentService = requireAgentService();
283
273
  const rpm = agentService.getRoutingPolicyManager?.() ||
284
274
  agentService.routingPolicyManager;
285
275
  const policy = await rpm?.getPolicy();
@@ -298,7 +288,6 @@ export function buildAIRouteHandlers(options) {
298
288
  },
299
289
  async updateRoutingPolicy(input) {
300
290
  try {
301
- const agentService = requireAgentService();
302
291
  const routingManager = agentService.getRoutingPolicyManager?.() ||
303
292
  agentService.routingPolicyManager;
304
293
  if (!routingManager)
@@ -313,7 +302,6 @@ export function buildAIRouteHandlers(options) {
313
302
  },
314
303
  async setDefaultProvider(input) {
315
304
  try {
316
- const agentService = requireAgentService();
317
305
  const routingManager = agentService.getRoutingPolicyManager?.() ||
318
306
  agentService.routingPolicyManager;
319
307
  if (!routingManager)
@@ -330,7 +318,6 @@ export function buildAIRouteHandlers(options) {
330
318
  },
331
319
  async setOperationConfig(input) {
332
320
  try {
333
- const agentService = requireAgentService();
334
321
  const routingManager = agentService.getRoutingPolicyManager?.() ||
335
322
  agentService.routingPolicyManager;
336
323
  if (!routingManager)
@@ -355,7 +342,6 @@ export function buildAIRouteHandlers(options) {
355
342
  },
356
343
  async validateProviders() {
357
344
  try {
358
- const agentService = requireAgentService();
359
345
  const results = await agentService.validateProviders();
360
346
  const validation = Array.from(results.entries()).map(([name, status]) => ({
361
347
  provider: name,
@@ -377,7 +363,6 @@ export function buildAIRouteHandlers(options) {
377
363
  },
378
364
  async getProviderHealth() {
379
365
  try {
380
- const agentService = requireAgentService();
381
366
  const providers = agentService.getAvailableProviders();
382
367
  const statuses = await agentService.validateProviders();
383
368
  const health = {
@@ -2,10 +2,9 @@ import type { TaskService } from '../../tasks/task-service.js';
2
2
  import type { VibingOrchestrator } from '../../workflows/vibing-orchestrator.js';
3
3
  type Deps = {
4
4
  taskService: TaskService;
5
- requireOrchestrator: () => Promise<VibingOrchestrator>;
6
- requireOrchestratorSync: () => VibingOrchestrator;
5
+ vibingOrchestrator: VibingOrchestrator;
7
6
  };
8
- export declare function buildExecutionRoutes({ taskService, requireOrchestrator, requireOrchestratorSync, }: Deps): {
7
+ export declare function buildExecutionRoutes({ taskService, vibingOrchestrator }: Deps): {
9
8
  readonly executeTask: import("@trpc/server").TRPCMutationProcedure<{
10
9
  input: {
11
10
  taskId: string;
@@ -66,9 +65,9 @@ export declare function buildExecutionRoutes({ taskService, requireOrchestrator,
66
65
  }>;
67
66
  readonly improveTask: import("@trpc/server").TRPCMutationProcedure<{
68
67
  input: {
69
- type: "feature" | "bug" | "chore" | "refactor" | "test" | "doc";
70
- priority: "low" | "medium" | "high";
71
68
  title: string;
69
+ type: "feature" | "bug" | "chore" | "refactor" | "test" | "doc";
70
+ priority: "high" | "medium" | "low";
72
71
  content: string;
73
72
  taskId: string;
74
73
  executionId?: string | undefined;
@@ -77,6 +76,7 @@ export declare function buildExecutionRoutes({ taskService, requireOrchestrator,
77
76
  type: string;
78
77
  priority: string;
79
78
  content: string;
79
+ title?: string;
80
80
  executionId: string;
81
81
  selectedModel?: string;
82
82
  };
@@ -4,34 +4,29 @@ import { publicProcedure } from '../trpc.js';
4
4
  import { ExecutionIdSchema, TaskIdSchema } from '../router-helpers.js';
5
5
  import { makeAssertTaskActive } from '../router-helpers.js';
6
6
  import { log } from '../../lib/logger.js';
7
- export function buildExecutionRoutes({ taskService, requireOrchestrator, requireOrchestratorSync, }) {
7
+ export function buildExecutionRoutes({ taskService, vibingOrchestrator }) {
8
8
  const assertTaskActive = makeAssertTaskActive(taskService);
9
9
  return {
10
10
  executeTask: publicProcedure.input(TaskIdSchema).mutation(async ({ input }) => {
11
- const orchestrator = await requireOrchestrator();
12
11
  assertTaskActive(input.taskId);
13
- const { executionId } = await orchestrator.executeTask(input.taskId);
12
+ const { executionId } = await vibingOrchestrator.executeTask(input.taskId);
14
13
  return { executionId };
15
14
  }),
16
15
  stopTaskExecution: publicProcedure.input(ExecutionIdSchema).mutation(async ({ input }) => {
17
- const orchestrator = await requireOrchestrator();
18
- await orchestrator.stopExecution(input.executionId);
16
+ await vibingOrchestrator.stopExecution(input.executionId);
19
17
  return { success: true };
20
18
  }),
21
19
  getTaskExecutionStatus: publicProcedure.input(ExecutionIdSchema).query(async ({ input }) => {
22
- const orchestrator = await requireOrchestrator();
23
- return orchestrator.getExecutionStatus(input.executionId);
20
+ return vibingOrchestrator.getExecutionStatus(input.executionId);
24
21
  }),
25
22
  getTaskExecutionLogs: publicProcedure.input(ExecutionIdSchema).query(async ({ input }) => {
26
23
  try {
27
- const orchestrator = await requireOrchestrator();
28
- const persistedLogs = await orchestrator.getPersistedExecutionLogs(input.executionId);
24
+ const persistedLogs = await vibingOrchestrator.getPersistedExecutionLogs(input.executionId);
29
25
  return { logs: persistedLogs.logs };
30
26
  }
31
27
  catch (error) {
32
28
  log.error('Failed to get task execution logs', error);
33
- const orchestrator = await requireOrchestrator();
34
- const logs = orchestrator.getExecutionLogs(input.executionId);
29
+ const logs = vibingOrchestrator.getExecutionLogs(input.executionId);
35
30
  const logEntries = logs.map((message, index) => ({
36
31
  timestamp: new Date().toISOString(),
37
32
  level: 'info',
@@ -42,12 +37,10 @@ export function buildExecutionRoutes({ taskService, requireOrchestrator, require
42
37
  }
43
38
  }),
44
39
  getTaskExecutions: publicProcedure.input(TaskIdSchema).query(async ({ input }) => {
45
- const orchestrator = await requireOrchestrator();
46
- return orchestrator.getTaskExecutions(input.taskId);
40
+ return vibingOrchestrator.getTaskExecutions(input.taskId);
47
41
  }),
48
42
  getTaskExecutionStats: publicProcedure.query(async () => {
49
- const orchestrator = await requireOrchestrator();
50
- return orchestrator.getExecutionStats();
43
+ return vibingOrchestrator.getExecutionStats();
51
44
  }),
52
45
  improveTask: publicProcedure
53
46
  .input(z.object({
@@ -60,8 +53,7 @@ export function buildExecutionRoutes({ taskService, requireOrchestrator, require
60
53
  }))
61
54
  .mutation(async ({ input }) => {
62
55
  assertTaskActive(input.taskId);
63
- const orchestrator = await requireOrchestrator();
64
- const improvement = await orchestrator.improveTaskContent(input.taskId, {
56
+ const improvement = await vibingOrchestrator.improveTaskContent(input.taskId, {
65
57
  title: input.title,
66
58
  type: input.type,
67
59
  priority: input.priority,
@@ -73,9 +65,8 @@ export function buildExecutionRoutes({ taskService, requireOrchestrator, require
73
65
  .input(z.object({ executionId: z.string() }))
74
66
  .subscription(async function* (opts) {
75
67
  const input = opts.input;
76
- const orchestrator = requireOrchestratorSync();
77
68
  // Emit initial status if exists
78
- const initial = orchestrator.getExecutionStatus(input.executionId);
69
+ const initial = vibingOrchestrator.getExecutionStatus(input.executionId);
79
70
  if (initial) {
80
71
  yield {
81
72
  executionId: initial.id,
@@ -89,14 +80,14 @@ export function buildExecutionRoutes({ taskService, requireOrchestrator, require
89
80
  if (update.executionId === input.executionId)
90
81
  proxy.emit('data', update);
91
82
  };
92
- orchestrator.on('executionUpdated', handleUpdate);
83
+ vibingOrchestrator.on('executionUpdated', handleUpdate);
93
84
  try {
94
85
  for await (const [payload] of on(proxy, 'data', { signal: opts.signal })) {
95
86
  yield payload;
96
87
  }
97
88
  }
98
89
  finally {
99
- orchestrator.off('executionUpdated', handleUpdate);
90
+ vibingOrchestrator.off('executionUpdated', handleUpdate);
100
91
  }
101
92
  }),
102
93
  };
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Provider Configuration Router
3
+ * Handles provider detection and local configuration management
4
+ */
5
+ /**
6
+ * Provider Configuration Router
7
+ */
8
+ export declare function buildProviderConfigRoutes(): {
9
+ /**
10
+ * Detect all providers with current status
11
+ */
12
+ detectAllProviders: import("@trpc/server").TRPCQueryProcedure<{
13
+ input: void;
14
+ output: Record<string, import("../../lib/provider-detection.js").DetectionResult>;
15
+ meta: object;
16
+ }>;
17
+ /**
18
+ * Detect specific provider
19
+ */
20
+ detectProvider: import("@trpc/server").TRPCQueryProcedure<{
21
+ input: {
22
+ provider: string;
23
+ };
24
+ output: import("../../lib/provider-detection.js").DetectionResult;
25
+ meta: object;
26
+ }>;
27
+ /**
28
+ * Set explicit provider path
29
+ */
30
+ setProviderPath: import("@trpc/server").TRPCMutationProcedure<{
31
+ input: {
32
+ path: string;
33
+ provider: string;
34
+ };
35
+ output: {
36
+ success: boolean;
37
+ result: import("../../lib/provider-detection.js").DetectionResult;
38
+ };
39
+ meta: object;
40
+ }>;
41
+ /**
42
+ * Clear provider path (reset to auto-detection)
43
+ */
44
+ clearProviderPath: import("@trpc/server").TRPCMutationProcedure<{
45
+ input: {
46
+ provider: string;
47
+ };
48
+ output: {
49
+ success: boolean;
50
+ };
51
+ meta: object;
52
+ }>;
53
+ /**
54
+ * Get local configuration info
55
+ */
56
+ getLocalConfigInfo: import("@trpc/server").TRPCQueryProcedure<{
57
+ input: void;
58
+ output: {
59
+ providers: {
60
+ 'claude-code'?: {
61
+ binPath?: string | undefined;
62
+ detectedPath?: string | undefined;
63
+ lastDetected?: string | undefined;
64
+ detectionMethod?: "explicit" | "PATH" | "common-location" | undefined;
65
+ } | undefined;
66
+ codex?: {
67
+ binPath?: string | undefined;
68
+ detectedPath?: string | undefined;
69
+ lastDetected?: string | undefined;
70
+ detectionMethod?: "explicit" | "PATH" | "common-location" | undefined;
71
+ } | undefined;
72
+ };
73
+ path: string;
74
+ exists: boolean;
75
+ size?: number;
76
+ };
77
+ meta: object;
78
+ }>;
79
+ /**
80
+ * Clear validation cache (force re-detection)
81
+ */
82
+ clearValidationCache: import("@trpc/server").TRPCMutationProcedure<{
83
+ input: void;
84
+ output: {
85
+ success: boolean;
86
+ };
87
+ meta: object;
88
+ }>;
89
+ /**
90
+ * Get provider detection diagnostics
91
+ */
92
+ getProviderDiagnostics: import("@trpc/server").TRPCQueryProcedure<{
93
+ input: void;
94
+ output: {
95
+ localConfigPath: string;
96
+ localConfigExists: boolean;
97
+ providers: {
98
+ provider: string;
99
+ detection: import("../../lib/provider-detection.js").DetectionResult;
100
+ localConfig: {
101
+ binPath?: string | undefined;
102
+ detectedPath?: string | undefined;
103
+ lastDetected?: string | undefined;
104
+ detectionMethod?: "explicit" | "PATH" | "common-location" | undefined;
105
+ } | {
106
+ binPath?: string | undefined;
107
+ detectedPath?: string | undefined;
108
+ lastDetected?: string | undefined;
109
+ detectionMethod?: "explicit" | "PATH" | "common-location" | undefined;
110
+ } | undefined;
111
+ cached: {
112
+ available: boolean;
113
+ error: string | undefined;
114
+ version: string | undefined;
115
+ checkedAt: string;
116
+ isFresh: boolean;
117
+ } | null;
118
+ }[];
119
+ };
120
+ meta: object;
121
+ }>;
122
+ };
123
+ /**
124
+ * Test-friendly plain handlers
125
+ */
126
+ export declare function buildProviderConfigRouteHandlers(): {
127
+ readonly detectAllProviders: () => Promise<Record<string, import("../../lib/provider-detection.js").DetectionResult>>;
128
+ readonly detectProvider: (input: {
129
+ provider: string;
130
+ }) => Promise<import("../../lib/provider-detection.js").DetectionResult>;
131
+ readonly setProviderPath: (input: {
132
+ provider: string;
133
+ path: string;
134
+ }) => Promise<{
135
+ success: true;
136
+ result: import("../../lib/provider-detection.js").DetectionResult;
137
+ }>;
138
+ readonly clearProviderPath: (input: {
139
+ provider: string;
140
+ }) => Promise<{
141
+ success: true;
142
+ }>;
143
+ readonly getLocalConfigInfo: () => Promise<{
144
+ providers: {
145
+ 'claude-code'?: {
146
+ binPath?: string | undefined;
147
+ detectedPath?: string | undefined;
148
+ lastDetected?: string | undefined;
149
+ detectionMethod?: "explicit" | "PATH" | "common-location" | undefined;
150
+ } | undefined;
151
+ codex?: {
152
+ binPath?: string | undefined;
153
+ detectedPath?: string | undefined;
154
+ lastDetected?: string | undefined;
155
+ detectionMethod?: "explicit" | "PATH" | "common-location" | undefined;
156
+ } | undefined;
157
+ };
158
+ path: string;
159
+ exists: boolean;
160
+ size?: number;
161
+ }>;
162
+ readonly clearValidationCache: () => Promise<{
163
+ success: true;
164
+ }>;
165
+ };
@@ -0,0 +1,252 @@
1
+ /**
2
+ * Provider Configuration Router
3
+ * Handles provider detection and local configuration management
4
+ */
5
+ import { z } from 'zod';
6
+ import { publicProcedure } from '../trpc.js';
7
+ import { getProviderDetectionService } from '../../lib/provider-detection.js';
8
+ import { getLocalConfigService } from '../../lib/local-config.js';
9
+ import { log } from '../../lib/logger.js';
10
+ /**
11
+ * Input schemas for API endpoints
12
+ */
13
+ const DetectProviderInputSchema = z.object({
14
+ provider: z.string(),
15
+ });
16
+ const SetProviderPathInputSchema = z.object({
17
+ provider: z.string(),
18
+ path: z.string().trim().min(1, 'Path is required'),
19
+ });
20
+ const ClearProviderPathInputSchema = z.object({
21
+ provider: z.string(),
22
+ });
23
+ /**
24
+ * Provider Configuration Router
25
+ */
26
+ export function buildProviderConfigRoutes() {
27
+ return {
28
+ /**
29
+ * Detect all providers with current status
30
+ */
31
+ detectAllProviders: publicProcedure.query(async () => {
32
+ try {
33
+ const detectionService = getProviderDetectionService();
34
+ const results = await detectionService.detectAllProviders();
35
+ log.debug('Detected all providers', { results }, 'provider-config');
36
+ return results;
37
+ }
38
+ catch (error) {
39
+ const msg = `Failed to detect providers: ${error instanceof Error ? error.message : String(error)}`;
40
+ log.error(msg, error, 'provider-config');
41
+ throw new Error(msg);
42
+ }
43
+ }),
44
+ /**
45
+ * Detect specific provider
46
+ */
47
+ detectProvider: publicProcedure.input(DetectProviderInputSchema).query(async ({ input }) => {
48
+ try {
49
+ const detectionService = getProviderDetectionService();
50
+ const result = await detectionService.detectProvider(input.provider);
51
+ log.debug('Detected provider', { provider: input.provider, result }, 'provider-config');
52
+ return result;
53
+ }
54
+ catch (error) {
55
+ const msg = `Failed to detect provider ${input.provider}: ${error instanceof Error ? error.message : String(error)}`;
56
+ log.error(msg, error, 'provider-config');
57
+ throw new Error(msg);
58
+ }
59
+ }),
60
+ /**
61
+ * Set explicit provider path
62
+ */
63
+ setProviderPath: publicProcedure
64
+ .input(SetProviderPathInputSchema)
65
+ .mutation(async ({ input }) => {
66
+ try {
67
+ const detectionService = getProviderDetectionService();
68
+ const result = await detectionService.setProviderPath(input.provider, input.path);
69
+ if (!result.found) {
70
+ throw new Error(result.error || 'Invalid provider path');
71
+ }
72
+ log.info('Set provider path', { provider: input.provider, path: input.path }, 'provider-config');
73
+ return { success: true, result };
74
+ }
75
+ catch (error) {
76
+ const msg = `Failed to set provider path: ${error instanceof Error ? error.message : String(error)}`;
77
+ log.error(msg, error, 'provider-config');
78
+ throw new Error(msg);
79
+ }
80
+ }),
81
+ /**
82
+ * Clear provider path (reset to auto-detection)
83
+ */
84
+ clearProviderPath: publicProcedure
85
+ .input(ClearProviderPathInputSchema)
86
+ .mutation(async ({ input }) => {
87
+ try {
88
+ const detectionService = getProviderDetectionService();
89
+ await detectionService.clearProviderPath(input.provider);
90
+ log.info('Cleared provider path', { provider: input.provider }, 'provider-config');
91
+ return { success: true };
92
+ }
93
+ catch (error) {
94
+ const msg = `Failed to clear provider path: ${error instanceof Error ? error.message : String(error)}`;
95
+ log.error(msg, error, 'provider-config');
96
+ throw new Error(msg);
97
+ }
98
+ }),
99
+ /**
100
+ * Get local configuration info
101
+ */
102
+ getLocalConfigInfo: publicProcedure.query(async () => {
103
+ try {
104
+ const localConfig = getLocalConfigService();
105
+ await localConfig.initialize();
106
+ const info = await localConfig.getConfigInfo();
107
+ const config = localConfig.getConfig();
108
+ return {
109
+ ...info,
110
+ providers: config.providers || {},
111
+ };
112
+ }
113
+ catch (error) {
114
+ const msg = `Failed to get local config info: ${error instanceof Error ? error.message : String(error)}`;
115
+ log.error(msg, error, 'provider-config');
116
+ throw new Error(msg);
117
+ }
118
+ }),
119
+ /**
120
+ * Clear validation cache (force re-detection)
121
+ */
122
+ clearValidationCache: publicProcedure.mutation(async () => {
123
+ try {
124
+ const localConfig = getLocalConfigService();
125
+ await localConfig.initialize();
126
+ await localConfig.clearValidationCache();
127
+ log.info('Cleared validation cache', undefined, 'provider-config');
128
+ return { success: true };
129
+ }
130
+ catch (error) {
131
+ const msg = `Failed to clear validation cache: ${error instanceof Error ? error.message : String(error)}`;
132
+ log.error(msg, error, 'provider-config');
133
+ throw new Error(msg);
134
+ }
135
+ }),
136
+ /**
137
+ * Get provider detection diagnostics
138
+ */
139
+ getProviderDiagnostics: publicProcedure.query(async () => {
140
+ try {
141
+ const detectionService = getProviderDetectionService();
142
+ const localConfig = getLocalConfigService();
143
+ await localConfig.initialize();
144
+ const detectionResults = await detectionService.detectAllProviders();
145
+ const localConfigInfo = await localConfig.getConfigInfo();
146
+ const providerConfigs = localConfig.getConfig().providers || {};
147
+ const diagnostics = Object.entries(detectionResults).map(([provider, result]) => {
148
+ const config = providerConfigs[provider];
149
+ const cached = localConfig.getCachedValidationResult(provider);
150
+ return {
151
+ provider,
152
+ detection: result,
153
+ localConfig: config,
154
+ cached: cached
155
+ ? {
156
+ available: cached.available,
157
+ error: cached.error,
158
+ version: cached.version,
159
+ checkedAt: cached.checkedAt,
160
+ isFresh: localConfig.isCachedValidationFresh(provider),
161
+ }
162
+ : null,
163
+ };
164
+ });
165
+ return {
166
+ localConfigPath: localConfigInfo.path,
167
+ localConfigExists: localConfigInfo.exists,
168
+ providers: diagnostics,
169
+ };
170
+ }
171
+ catch (error) {
172
+ const msg = `Failed to get provider diagnostics: ${error instanceof Error ? error.message : String(error)}`;
173
+ log.error(msg, error, 'provider-config');
174
+ throw new Error(msg);
175
+ }
176
+ }),
177
+ };
178
+ }
179
+ /**
180
+ * Test-friendly plain handlers
181
+ */
182
+ export function buildProviderConfigRouteHandlers() {
183
+ return {
184
+ async detectAllProviders() {
185
+ try {
186
+ const detectionService = getProviderDetectionService();
187
+ return await detectionService.detectAllProviders();
188
+ }
189
+ catch (error) {
190
+ throw new Error(`Failed to detect providers: ${error instanceof Error ? error.message : String(error)}`);
191
+ }
192
+ },
193
+ async detectProvider(input) {
194
+ try {
195
+ const detectionService = getProviderDetectionService();
196
+ return await detectionService.detectProvider(input.provider);
197
+ }
198
+ catch (error) {
199
+ throw new Error(`Failed to detect provider ${input.provider}: ${error instanceof Error ? error.message : String(error)}`);
200
+ }
201
+ },
202
+ async setProviderPath(input) {
203
+ try {
204
+ const detectionService = getProviderDetectionService();
205
+ const result = await detectionService.setProviderPath(input.provider, input.path);
206
+ if (!result.found) {
207
+ throw new Error(result.error || 'Invalid provider path');
208
+ }
209
+ return { success: true, result };
210
+ }
211
+ catch (error) {
212
+ throw new Error(`Failed to set provider path: ${error instanceof Error ? error.message : String(error)}`);
213
+ }
214
+ },
215
+ async clearProviderPath(input) {
216
+ try {
217
+ const detectionService = getProviderDetectionService();
218
+ await detectionService.clearProviderPath(input.provider);
219
+ return { success: true };
220
+ }
221
+ catch (error) {
222
+ throw new Error(`Failed to clear provider path: ${error instanceof Error ? error.message : String(error)}`);
223
+ }
224
+ },
225
+ async getLocalConfigInfo() {
226
+ try {
227
+ const localConfig = getLocalConfigService();
228
+ await localConfig.initialize();
229
+ const info = await localConfig.getConfigInfo();
230
+ const config = localConfig.getConfig();
231
+ return {
232
+ ...info,
233
+ providers: config.providers || {},
234
+ };
235
+ }
236
+ catch (error) {
237
+ throw new Error(`Failed to get local config info: ${error instanceof Error ? error.message : String(error)}`);
238
+ }
239
+ },
240
+ async clearValidationCache() {
241
+ try {
242
+ const localConfig = getLocalConfigService();
243
+ await localConfig.initialize();
244
+ await localConfig.clearValidationCache();
245
+ return { success: true };
246
+ }
247
+ catch (error) {
248
+ throw new Error(`Failed to clear validation cache: ${error instanceof Error ? error.message : String(error)}`);
249
+ }
250
+ },
251
+ };
252
+ }