@specforge/mcp 2.6.0 → 3.0.1
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.
- package/README.md +73 -0
- package/bin/{specforge-mcp → specforge} +0 -5
- package/dist/ai-provider/circuit-breaker.d.ts +63 -0
- package/dist/ai-provider/circuit-breaker.d.ts.map +1 -0
- package/dist/ai-provider/circuit-breaker.js +160 -0
- package/dist/ai-provider/circuit-breaker.js.map +1 -0
- package/dist/ai-provider/cli-version.d.ts +50 -0
- package/dist/ai-provider/cli-version.d.ts.map +1 -0
- package/dist/ai-provider/cli-version.js +141 -0
- package/dist/ai-provider/cli-version.js.map +1 -0
- package/dist/ai-provider/config-loader.d.ts +45 -0
- package/dist/ai-provider/config-loader.d.ts.map +1 -0
- package/dist/ai-provider/config-loader.js +106 -0
- package/dist/ai-provider/config-loader.js.map +1 -0
- package/dist/ai-provider/errors.d.ts +48 -0
- package/dist/ai-provider/errors.d.ts.map +1 -0
- package/dist/ai-provider/errors.js +102 -0
- package/dist/ai-provider/errors.js.map +1 -0
- package/dist/ai-provider/events.d.ts +73 -0
- package/dist/ai-provider/events.d.ts.map +1 -0
- package/dist/ai-provider/events.js +75 -0
- package/dist/ai-provider/events.js.map +1 -0
- package/dist/ai-provider/factory.d.ts +31 -0
- package/dist/ai-provider/factory.d.ts.map +1 -0
- package/dist/ai-provider/factory.js +100 -0
- package/dist/ai-provider/factory.js.map +1 -0
- package/dist/ai-provider/index.d.ts +24 -0
- package/dist/ai-provider/index.d.ts.map +1 -0
- package/dist/ai-provider/index.js +46 -0
- package/dist/ai-provider/index.js.map +1 -0
- package/dist/ai-provider/instance-coordinator.d.ts +54 -0
- package/dist/ai-provider/instance-coordinator.d.ts.map +1 -0
- package/dist/ai-provider/instance-coordinator.js +199 -0
- package/dist/ai-provider/instance-coordinator.js.map +1 -0
- package/dist/ai-provider/jsonl-parser.d.ts +43 -0
- package/dist/ai-provider/jsonl-parser.d.ts.map +1 -0
- package/dist/ai-provider/jsonl-parser.js +107 -0
- package/dist/ai-provider/jsonl-parser.js.map +1 -0
- package/dist/ai-provider/lifecycle.d.ts +50 -0
- package/dist/ai-provider/lifecycle.d.ts.map +1 -0
- package/dist/ai-provider/lifecycle.js +145 -0
- package/dist/ai-provider/lifecycle.js.map +1 -0
- package/dist/ai-provider/logger.d.ts +69 -0
- package/dist/ai-provider/logger.d.ts.map +1 -0
- package/dist/ai-provider/logger.js +161 -0
- package/dist/ai-provider/logger.js.map +1 -0
- package/dist/ai-provider/metrics.d.ts +91 -0
- package/dist/ai-provider/metrics.d.ts.map +1 -0
- package/dist/ai-provider/metrics.js +187 -0
- package/dist/ai-provider/metrics.js.map +1 -0
- package/dist/ai-provider/process-manager.d.ts +97 -0
- package/dist/ai-provider/process-manager.d.ts.map +1 -0
- package/dist/ai-provider/process-manager.js +477 -0
- package/dist/ai-provider/process-manager.js.map +1 -0
- package/dist/ai-provider/providers/claude-code.d.ts +64 -0
- package/dist/ai-provider/providers/claude-code.d.ts.map +1 -0
- package/dist/ai-provider/providers/claude-code.js +205 -0
- package/dist/ai-provider/providers/claude-code.js.map +1 -0
- package/dist/ai-provider/retry-executor.d.ts +52 -0
- package/dist/ai-provider/retry-executor.d.ts.map +1 -0
- package/dist/ai-provider/retry-executor.js +138 -0
- package/dist/ai-provider/retry-executor.js.map +1 -0
- package/dist/ai-provider/safe-args.d.ts +58 -0
- package/dist/ai-provider/safe-args.d.ts.map +1 -0
- package/dist/ai-provider/safe-args.js +176 -0
- package/dist/ai-provider/safe-args.js.map +1 -0
- package/dist/ai-provider/semaphore.d.ts +50 -0
- package/dist/ai-provider/semaphore.d.ts.map +1 -0
- package/dist/ai-provider/semaphore.js +97 -0
- package/dist/ai-provider/semaphore.js.map +1 -0
- package/dist/ai-provider/tracer.d.ts +67 -0
- package/dist/ai-provider/tracer.d.ts.map +1 -0
- package/dist/ai-provider/tracer.js +209 -0
- package/dist/ai-provider/tracer.js.map +1 -0
- package/dist/ai-provider/types.d.ts +181 -0
- package/dist/ai-provider/types.d.ts.map +1 -0
- package/dist/ai-provider/types.js +8 -0
- package/dist/ai-provider/types.js.map +1 -0
- package/dist/autopilot/agents/agent-runner.d.ts +109 -0
- package/dist/autopilot/agents/agent-runner.d.ts.map +1 -0
- package/dist/autopilot/agents/agent-runner.js +731 -0
- package/dist/autopilot/agents/agent-runner.js.map +1 -0
- package/dist/autopilot/agents/agent-selector.d.ts +59 -0
- package/dist/autopilot/agents/agent-selector.d.ts.map +1 -0
- package/dist/autopilot/agents/agent-selector.js +234 -0
- package/dist/autopilot/agents/agent-selector.js.map +1 -0
- package/dist/autopilot/agents/model-selector.d.ts +49 -0
- package/dist/autopilot/agents/model-selector.d.ts.map +1 -0
- package/dist/autopilot/agents/model-selector.js +62 -0
- package/dist/autopilot/agents/model-selector.js.map +1 -0
- package/dist/autopilot/agents/profiles/builtin.d.ts +55 -0
- package/dist/autopilot/agents/profiles/builtin.d.ts.map +1 -0
- package/dist/autopilot/agents/profiles/builtin.js +323 -0
- package/dist/autopilot/agents/profiles/builtin.js.map +1 -0
- package/dist/autopilot/agents/profiles/types.d.ts +98 -0
- package/dist/autopilot/agents/profiles/types.d.ts.map +1 -0
- package/dist/autopilot/agents/profiles/types.js +17 -0
- package/dist/autopilot/agents/profiles/types.js.map +1 -0
- package/dist/autopilot/api/autopilot-api-client.d.ts +217 -0
- package/dist/autopilot/api/autopilot-api-client.d.ts.map +1 -0
- package/dist/autopilot/api/autopilot-api-client.js +402 -0
- package/dist/autopilot/api/autopilot-api-client.js.map +1 -0
- package/dist/autopilot/cli/abort.d.ts +20 -0
- package/dist/autopilot/cli/abort.d.ts.map +1 -0
- package/dist/autopilot/cli/abort.js +201 -0
- package/dist/autopilot/cli/abort.js.map +1 -0
- package/dist/autopilot/cli/display.d.ts +63 -0
- package/dist/autopilot/cli/display.d.ts.map +1 -0
- package/dist/autopilot/cli/display.js +260 -0
- package/dist/autopilot/cli/display.js.map +1 -0
- package/dist/autopilot/cli/index.d.ts +24 -0
- package/dist/autopilot/cli/index.d.ts.map +1 -0
- package/dist/autopilot/cli/index.js +79 -0
- package/dist/autopilot/cli/index.js.map +1 -0
- package/dist/autopilot/cli/pause.d.ts +18 -0
- package/dist/autopilot/cli/pause.d.ts.map +1 -0
- package/dist/autopilot/cli/pause.js +110 -0
- package/dist/autopilot/cli/pause.js.map +1 -0
- package/dist/autopilot/cli/resume.d.ts +22 -0
- package/dist/autopilot/cli/resume.d.ts.map +1 -0
- package/dist/autopilot/cli/resume.js +172 -0
- package/dist/autopilot/cli/resume.js.map +1 -0
- package/dist/autopilot/cli/run.d.ts +25 -0
- package/dist/autopilot/cli/run.d.ts.map +1 -0
- package/dist/autopilot/cli/run.js +220 -0
- package/dist/autopilot/cli/run.js.map +1 -0
- package/dist/autopilot/cli/status.d.ts +20 -0
- package/dist/autopilot/cli/status.d.ts.map +1 -0
- package/dist/autopilot/cli/status.js +217 -0
- package/dist/autopilot/cli/status.js.map +1 -0
- package/dist/autopilot/config.d.ts +45 -0
- package/dist/autopilot/config.d.ts.map +1 -0
- package/dist/autopilot/config.js +269 -0
- package/dist/autopilot/config.js.map +1 -0
- package/dist/autopilot/core/dependency-resolver.d.ts +108 -0
- package/dist/autopilot/core/dependency-resolver.d.ts.map +1 -0
- package/dist/autopilot/core/dependency-resolver.js +394 -0
- package/dist/autopilot/core/dependency-resolver.js.map +1 -0
- package/dist/autopilot/core/dispatcher.d.ts +215 -0
- package/dist/autopilot/core/dispatcher.d.ts.map +1 -0
- package/dist/autopilot/core/dispatcher.js +594 -0
- package/dist/autopilot/core/dispatcher.js.map +1 -0
- package/dist/autopilot/core/failure-handler.d.ts +145 -0
- package/dist/autopilot/core/failure-handler.d.ts.map +1 -0
- package/dist/autopilot/core/failure-handler.js +308 -0
- package/dist/autopilot/core/failure-handler.js.map +1 -0
- package/dist/autopilot/core/rate-limit-handler.d.ts +108 -0
- package/dist/autopilot/core/rate-limit-handler.d.ts.map +1 -0
- package/dist/autopilot/core/rate-limit-handler.js +195 -0
- package/dist/autopilot/core/rate-limit-handler.js.map +1 -0
- package/dist/autopilot/core/state-manager.d.ts +160 -0
- package/dist/autopilot/core/state-manager.d.ts.map +1 -0
- package/dist/autopilot/core/state-manager.js +393 -0
- package/dist/autopilot/core/state-manager.js.map +1 -0
- package/dist/autopilot/core/timeout-manager.d.ts +95 -0
- package/dist/autopilot/core/timeout-manager.d.ts.map +1 -0
- package/dist/autopilot/core/timeout-manager.js +188 -0
- package/dist/autopilot/core/timeout-manager.js.map +1 -0
- package/dist/autopilot/git/branch-manager.d.ts +117 -0
- package/dist/autopilot/git/branch-manager.d.ts.map +1 -0
- package/dist/autopilot/git/branch-manager.js +238 -0
- package/dist/autopilot/git/branch-manager.js.map +1 -0
- package/dist/autopilot/git/index.d.ts +9 -0
- package/dist/autopilot/git/index.d.ts.map +1 -0
- package/dist/autopilot/git/index.js +9 -0
- package/dist/autopilot/git/index.js.map +1 -0
- package/dist/autopilot/git/merge-manager.d.ts +118 -0
- package/dist/autopilot/git/merge-manager.d.ts.map +1 -0
- package/dist/autopilot/git/merge-manager.js +304 -0
- package/dist/autopilot/git/merge-manager.js.map +1 -0
- package/dist/autopilot/git/worktree-manager.d.ts +128 -0
- package/dist/autopilot/git/worktree-manager.d.ts.map +1 -0
- package/dist/autopilot/git/worktree-manager.js +298 -0
- package/dist/autopilot/git/worktree-manager.js.map +1 -0
- package/dist/autopilot/index.d.ts +30 -0
- package/dist/autopilot/index.d.ts.map +1 -0
- package/dist/autopilot/index.js +55 -0
- package/dist/autopilot/index.js.map +1 -0
- package/dist/autopilot/sync/index.d.ts +7 -0
- package/dist/autopilot/sync/index.d.ts.map +1 -0
- package/dist/autopilot/sync/index.js +7 -0
- package/dist/autopilot/sync/index.js.map +1 -0
- package/dist/autopilot/sync/sync-manager.d.ts +168 -0
- package/dist/autopilot/sync/sync-manager.d.ts.map +1 -0
- package/dist/autopilot/sync/sync-manager.js +303 -0
- package/dist/autopilot/sync/sync-manager.js.map +1 -0
- package/dist/autopilot/types.d.ts +454 -0
- package/dist/autopilot/types.d.ts.map +1 -0
- package/dist/autopilot/types.js +26 -0
- package/dist/autopilot/types.js.map +1 -0
- package/dist/autopilot/utils/audit-logger.d.ts +176 -0
- package/dist/autopilot/utils/audit-logger.d.ts.map +1 -0
- package/dist/autopilot/utils/audit-logger.js +308 -0
- package/dist/autopilot/utils/audit-logger.js.map +1 -0
- package/dist/autopilot/utils/cost-tracker.d.ts +162 -0
- package/dist/autopilot/utils/cost-tracker.d.ts.map +1 -0
- package/dist/autopilot/utils/cost-tracker.js +269 -0
- package/dist/autopilot/utils/cost-tracker.js.map +1 -0
- package/dist/autopilot/utils/index.d.ts +9 -0
- package/dist/autopilot/utils/index.d.ts.map +1 -0
- package/dist/autopilot/utils/index.js +9 -0
- package/dist/autopilot/utils/index.js.map +1 -0
- package/dist/autopilot/utils/progress-reporter.d.ts +132 -0
- package/dist/autopilot/utils/progress-reporter.d.ts.map +1 -0
- package/dist/autopilot/utils/progress-reporter.js +290 -0
- package/dist/autopilot/utils/progress-reporter.js.map +1 -0
- package/dist/autopilot/worker/worker-pool.d.ts +179 -0
- package/dist/autopilot/worker/worker-pool.d.ts.map +1 -0
- package/dist/autopilot/worker/worker-pool.js +331 -0
- package/dist/autopilot/worker/worker-pool.js.map +1 -0
- package/dist/autopilot/worker/worker-session.d.ts +171 -0
- package/dist/autopilot/worker/worker-session.d.ts.map +1 -0
- package/dist/autopilot/worker/worker-session.js +295 -0
- package/dist/autopilot/worker/worker-session.js.map +1 -0
- package/dist/cli/commands/debug/call.d.ts.map +1 -1
- package/dist/cli/commands/debug/call.js +5 -1
- package/dist/cli/commands/debug/call.js.map +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +4 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/tools/core/epic.js +1 -1
- package/dist/tools/core/epic.js.map +1 -1
- package/dist/tools/core/lookup.d.ts.map +1 -1
- package/dist/tools/core/lookup.js +3 -2
- package/dist/tools/core/lookup.js.map +1 -1
- package/dist/tools/core/specification.js +1 -1
- package/dist/tools/core/specification.js.map +1 -1
- package/dist/tools/core/ticket.d.ts.map +1 -1
- package/dist/tools/core/ticket.js +4 -6
- package/dist/tools/core/ticket.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +60 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/validation/index.d.ts.map +1 -1
- package/dist/validation/index.js +4 -1
- package/dist/validation/index.js.map +1 -1
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -251,6 +251,22 @@ The SpecForge MCP server provides the following tool categories:
|
|
|
251
251
|
- `get_ticket_commits` - Get commits for a ticket
|
|
252
252
|
- `get_ticket_prs` - Get PRs for a ticket
|
|
253
253
|
|
|
254
|
+
### Blueprint Management
|
|
255
|
+
- `blueprint` - Manage specification blueprints (diagrams, mockups, ADRs)
|
|
256
|
+
- Operations: `create`, `get`, `update`, `list`, `delete`, `link`, `unlink`, `get_for_ticket`
|
|
257
|
+
- Categories: flowchart, architecture, state, sequence, erd, mockup, adr, component, deployment, api
|
|
258
|
+
- See [Blueprint Documentation](/docs/mcp/tools/blueprint.md)
|
|
259
|
+
|
|
260
|
+
### Project Sharing
|
|
261
|
+
- `list_project_members` - List all members of a project
|
|
262
|
+
- `invite_to_project` - Invite a user by email
|
|
263
|
+
- `remove_project_member` - Remove a member from project
|
|
264
|
+
- `update_member_role` - Change a member's role (owner, editor, viewer)
|
|
265
|
+
- `list_invitations` - List pending invitations
|
|
266
|
+
- `accept_project_invitation` - Accept an invitation
|
|
267
|
+
- `decline_project_invitation` - Decline an invitation
|
|
268
|
+
- See [Project Sharing Documentation](/docs/mcp/collaboration/)
|
|
269
|
+
|
|
254
270
|
## CLI Commands
|
|
255
271
|
|
|
256
272
|
The SpecForge MCP package includes a CLI for project configuration and management.
|
|
@@ -278,6 +294,11 @@ The SpecForge MCP package includes a CLI for project configuration and managemen
|
|
|
278
294
|
| `tools` | List available MCP tools |
|
|
279
295
|
| `test` | Test API connection |
|
|
280
296
|
| `whoami` | Show current user/config |
|
|
297
|
+
| `autopilot run` | Start autonomous implementation |
|
|
298
|
+
| `autopilot status` | Show autopilot session status |
|
|
299
|
+
| `autopilot pause` | Pause active session |
|
|
300
|
+
| `autopilot resume` | Resume paused session |
|
|
301
|
+
| `autopilot abort` | Stop and cleanup session |
|
|
281
302
|
|
|
282
303
|
### Setup Commands
|
|
283
304
|
|
|
@@ -506,6 +527,58 @@ specforge whoami [--json]
|
|
|
506
527
|
|
|
507
528
|
Show current user information and configuration settings.
|
|
508
529
|
|
|
530
|
+
### Autopilot Commands
|
|
531
|
+
|
|
532
|
+
Autopilot enables autonomous ticket implementation using Claude Code. See [full documentation](/docs/mcp/autopilot/).
|
|
533
|
+
|
|
534
|
+
#### autopilot run
|
|
535
|
+
|
|
536
|
+
```bash
|
|
537
|
+
specforge autopilot run [options]
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
Start autonomous ticket implementation.
|
|
541
|
+
|
|
542
|
+
| Option | Description |
|
|
543
|
+
|--------|-------------|
|
|
544
|
+
| `-s, --spec <id>` | Specification ID |
|
|
545
|
+
| `-e, --epic <id>` | Only implement tickets from this epic |
|
|
546
|
+
| `-p, --parallel <n>` | Number of parallel workers (1-10) |
|
|
547
|
+
| `-c, --max-cost <usd>` | Maximum cost in USD |
|
|
548
|
+
| `-n, --dry-run` | Show plan without executing |
|
|
549
|
+
| `-w, --watch` | Watch mode with live dashboard |
|
|
550
|
+
| `-r, --resume <id>` | Resume a previous run |
|
|
551
|
+
|
|
552
|
+
Examples:
|
|
553
|
+
```bash
|
|
554
|
+
specforge autopilot run --dry-run # Preview
|
|
555
|
+
specforge autopilot run --parallel 2 # Run with 2 workers
|
|
556
|
+
specforge autopilot run --max-cost 10 # Limit to $10
|
|
557
|
+
specforge autopilot run --watch # Live dashboard
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
#### autopilot status
|
|
561
|
+
|
|
562
|
+
```bash
|
|
563
|
+
specforge autopilot status [options]
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
Show current autopilot session status.
|
|
567
|
+
|
|
568
|
+
| Option | Description |
|
|
569
|
+
|--------|-------------|
|
|
570
|
+
| `-w, --watch` | Live updates (2s refresh) |
|
|
571
|
+
| `-v, --verbose` | Show detailed dashboard |
|
|
572
|
+
| `--json` | Output as JSON |
|
|
573
|
+
|
|
574
|
+
#### autopilot pause / resume / abort
|
|
575
|
+
|
|
576
|
+
```bash
|
|
577
|
+
specforge autopilot pause # Pause gracefully
|
|
578
|
+
specforge autopilot resume # Resume latest session
|
|
579
|
+
specforge autopilot abort --force # Stop and cleanup
|
|
580
|
+
```
|
|
581
|
+
|
|
509
582
|
### Configuration Files
|
|
510
583
|
|
|
511
584
|
| File | Location | Purpose |
|
|
@@ -10,11 +10,6 @@
|
|
|
10
10
|
* When called with subcommands/flags: runs CLI
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
// Show deprecation warning when invoked as specforge-mcp
|
|
14
|
-
if (process.argv[1]?.includes('specforge-mcp')) {
|
|
15
|
-
console.warn('\x1b[33m⚠ Warning: "specforge-mcp" is deprecated. Use "specforge" instead.\x1b[0m\n');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
13
|
import('../dist/cli/index.js')
|
|
19
14
|
.then(({ runCLI }) => runCLI())
|
|
20
15
|
.catch((error) => {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Circuit Breaker Pattern
|
|
3
|
+
*
|
|
4
|
+
* Prevents cascading failures by opening the circuit after too many failures.
|
|
5
|
+
* States: closed (normal) -> open (failing) -> half-open (testing) -> closed
|
|
6
|
+
*/
|
|
7
|
+
import type { CircuitState, CircuitBreakerConfig } from './types.js';
|
|
8
|
+
export declare class CircuitBreaker {
|
|
9
|
+
private config;
|
|
10
|
+
private state;
|
|
11
|
+
private failures;
|
|
12
|
+
private successes;
|
|
13
|
+
private lastFailureTime;
|
|
14
|
+
private halfOpenAttempts;
|
|
15
|
+
constructor(config: CircuitBreakerConfig);
|
|
16
|
+
/**
|
|
17
|
+
* Check if a request can proceed.
|
|
18
|
+
*/
|
|
19
|
+
canRequest(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Record a successful request.
|
|
22
|
+
*/
|
|
23
|
+
recordSuccess(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Record a failed request.
|
|
26
|
+
*/
|
|
27
|
+
recordFailure(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Get current circuit state.
|
|
30
|
+
*/
|
|
31
|
+
getState(): CircuitState;
|
|
32
|
+
/**
|
|
33
|
+
* Get circuit breaker statistics.
|
|
34
|
+
*/
|
|
35
|
+
getStats(): {
|
|
36
|
+
state: CircuitState;
|
|
37
|
+
failures: number;
|
|
38
|
+
successes: number;
|
|
39
|
+
lastFailureTime: number | null;
|
|
40
|
+
halfOpenAttempts: number;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Force reset the circuit breaker to closed state.
|
|
44
|
+
*/
|
|
45
|
+
forceReset(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Update state based on recovery time.
|
|
48
|
+
*/
|
|
49
|
+
private updateState;
|
|
50
|
+
/**
|
|
51
|
+
* Transition to a new state with event emission.
|
|
52
|
+
*/
|
|
53
|
+
private transitionTo;
|
|
54
|
+
/**
|
|
55
|
+
* Reset internal counters.
|
|
56
|
+
*/
|
|
57
|
+
private reset;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Create a circuit breaker with default configuration.
|
|
61
|
+
*/
|
|
62
|
+
export declare function createCircuitBreaker(config?: Partial<CircuitBreakerConfig>): CircuitBreaker;
|
|
63
|
+
//# sourceMappingURL=circuit-breaker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuit-breaker.d.ts","sourceRoot":"","sources":["../../src/ai-provider/circuit-breaker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAMrE,qBAAa,cAAc;IAOb,OAAO,CAAC,MAAM;IAN1B,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,eAAe,CAAa;IACpC,OAAO,CAAC,gBAAgB,CAAa;gBAEjB,MAAM,EAAE,oBAAoB;IAEhD;;OAEG;IACH,UAAU,IAAI,OAAO;IAarB;;OAEG;IACH,aAAa,IAAI,IAAI;IAkBrB;;OAEG;IACH,aAAa,IAAI,IAAI;IAsBrB;;OAEG;IACH,QAAQ,IAAI,YAAY;IAKxB;;OAEG;IACH,QAAQ,IAAI;QACV,KAAK,EAAE,YAAY,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;QAC/B,gBAAgB,EAAE,MAAM,CAAC;KAC1B;IAUD;;OAEG;IACH,UAAU,IAAI,IAAI;IAMlB;;OAEG;IACH,OAAO,CAAC,WAAW;IAUnB;;OAEG;IACH,OAAO,CAAC,YAAY;IA4BpB;;OAEG;IACH,OAAO,CAAC,KAAK;CAId;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,GACrC,cAAc,CAMhB"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Circuit Breaker Pattern
|
|
3
|
+
*
|
|
4
|
+
* Prevents cascading failures by opening the circuit after too many failures.
|
|
5
|
+
* States: closed (normal) -> open (failing) -> half-open (testing) -> closed
|
|
6
|
+
*/
|
|
7
|
+
import { aiProviderEvents } from './events.js';
|
|
8
|
+
import { createLogger } from './logger.js';
|
|
9
|
+
const logger = createLogger('CircuitBreaker');
|
|
10
|
+
export class CircuitBreaker {
|
|
11
|
+
config;
|
|
12
|
+
state = 'closed';
|
|
13
|
+
failures = 0;
|
|
14
|
+
successes = 0;
|
|
15
|
+
lastFailureTime = 0;
|
|
16
|
+
halfOpenAttempts = 0;
|
|
17
|
+
constructor(config) {
|
|
18
|
+
this.config = config;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Check if a request can proceed.
|
|
22
|
+
*/
|
|
23
|
+
canRequest() {
|
|
24
|
+
this.updateState();
|
|
25
|
+
switch (this.state) {
|
|
26
|
+
case 'closed':
|
|
27
|
+
return true;
|
|
28
|
+
case 'open':
|
|
29
|
+
return false;
|
|
30
|
+
case 'half-open':
|
|
31
|
+
return this.halfOpenAttempts < this.config.halfOpenRequests;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Record a successful request.
|
|
36
|
+
*/
|
|
37
|
+
recordSuccess() {
|
|
38
|
+
// Update state first (open -> half-open if recovery time elapsed)
|
|
39
|
+
this.updateState();
|
|
40
|
+
this.successes++;
|
|
41
|
+
if (this.state === 'half-open') {
|
|
42
|
+
this.halfOpenAttempts++;
|
|
43
|
+
if (this.halfOpenAttempts >= this.config.halfOpenRequests) {
|
|
44
|
+
// Recovery successful - close the circuit
|
|
45
|
+
this.transitionTo('closed');
|
|
46
|
+
this.reset();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if (this.state === 'closed') {
|
|
50
|
+
// Reset failure count on success in closed state
|
|
51
|
+
this.failures = 0;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Record a failed request.
|
|
56
|
+
*/
|
|
57
|
+
recordFailure() {
|
|
58
|
+
// Update state first (open -> half-open if recovery time elapsed)
|
|
59
|
+
this.updateState();
|
|
60
|
+
this.failures++;
|
|
61
|
+
this.lastFailureTime = Date.now();
|
|
62
|
+
if (this.state === 'half-open') {
|
|
63
|
+
// Failed during recovery - reopen the circuit
|
|
64
|
+
this.transitionTo('open');
|
|
65
|
+
this.halfOpenAttempts = 0;
|
|
66
|
+
}
|
|
67
|
+
else if (this.failures >= this.config.failureThreshold) {
|
|
68
|
+
// Too many failures - open the circuit
|
|
69
|
+
this.transitionTo('open');
|
|
70
|
+
}
|
|
71
|
+
logger.warn('Failure recorded', {
|
|
72
|
+
failures: this.failures,
|
|
73
|
+
threshold: this.config.failureThreshold,
|
|
74
|
+
state: this.state,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get current circuit state.
|
|
79
|
+
*/
|
|
80
|
+
getState() {
|
|
81
|
+
this.updateState();
|
|
82
|
+
return this.state;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get circuit breaker statistics.
|
|
86
|
+
*/
|
|
87
|
+
getStats() {
|
|
88
|
+
return {
|
|
89
|
+
state: this.getState(),
|
|
90
|
+
failures: this.failures,
|
|
91
|
+
successes: this.successes,
|
|
92
|
+
lastFailureTime: this.lastFailureTime || null,
|
|
93
|
+
halfOpenAttempts: this.halfOpenAttempts,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Force reset the circuit breaker to closed state.
|
|
98
|
+
*/
|
|
99
|
+
forceReset() {
|
|
100
|
+
this.reset();
|
|
101
|
+
this.transitionTo('closed');
|
|
102
|
+
logger.info('Circuit breaker force reset');
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Update state based on recovery time.
|
|
106
|
+
*/
|
|
107
|
+
updateState() {
|
|
108
|
+
if (this.state === 'open') {
|
|
109
|
+
const elapsed = Date.now() - this.lastFailureTime;
|
|
110
|
+
if (elapsed >= this.config.recoveryTimeMs) {
|
|
111
|
+
this.transitionTo('half-open');
|
|
112
|
+
this.halfOpenAttempts = 0;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Transition to a new state with event emission.
|
|
118
|
+
*/
|
|
119
|
+
transitionTo(newState) {
|
|
120
|
+
const previousState = this.state;
|
|
121
|
+
if (previousState === newState) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
this.state = newState;
|
|
125
|
+
logger.info('Circuit breaker state change', {
|
|
126
|
+
previousState,
|
|
127
|
+
newState,
|
|
128
|
+
});
|
|
129
|
+
const payload = { previousState, newState };
|
|
130
|
+
switch (newState) {
|
|
131
|
+
case 'open':
|
|
132
|
+
aiProviderEvents.emit('circuit_breaker:opened', payload);
|
|
133
|
+
break;
|
|
134
|
+
case 'half-open':
|
|
135
|
+
aiProviderEvents.emit('circuit_breaker:half_open', payload);
|
|
136
|
+
break;
|
|
137
|
+
case 'closed':
|
|
138
|
+
aiProviderEvents.emit('circuit_breaker:closed', payload);
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Reset internal counters.
|
|
144
|
+
*/
|
|
145
|
+
reset() {
|
|
146
|
+
this.failures = 0;
|
|
147
|
+
this.halfOpenAttempts = 0;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Create a circuit breaker with default configuration.
|
|
152
|
+
*/
|
|
153
|
+
export function createCircuitBreaker(config) {
|
|
154
|
+
return new CircuitBreaker({
|
|
155
|
+
failureThreshold: config?.failureThreshold ?? 5,
|
|
156
|
+
recoveryTimeMs: config?.recoveryTimeMs ?? 30000,
|
|
157
|
+
halfOpenRequests: config?.halfOpenRequests ?? 2,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=circuit-breaker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuit-breaker.js","sourceRoot":"","sources":["../../src/ai-provider/circuit-breaker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;A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O,IAAI,cAAc,CAAC;QACxB,gBAAgB,EAAE,MAAM,EAAE,gBAAgB,IAAI,CAAC;QAC/C,cAAc,EAAE,MAAM,EAAE,cAAc,IAAI,KAAK;QAC/C,gBAAgB,EAAE,MAAM,EAAE,gBAAgB,IAAI,CAAC;KAChD,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Version Detection
|
|
3
|
+
*
|
|
4
|
+
* Detects Claude CLI version and feature support.
|
|
5
|
+
*/
|
|
6
|
+
import type { CLIVersionInfo } from './types.js';
|
|
7
|
+
export declare class CLIVersionDetector {
|
|
8
|
+
private cachedVersion?;
|
|
9
|
+
/**
|
|
10
|
+
* Detect CLI version and capabilities.
|
|
11
|
+
*/
|
|
12
|
+
detect(): Promise<CLIVersionInfo>;
|
|
13
|
+
/**
|
|
14
|
+
* Check if CLI is installed.
|
|
15
|
+
*/
|
|
16
|
+
isInstalled(): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Get cached version info (throws if not detected yet).
|
|
19
|
+
*/
|
|
20
|
+
getCachedVersion(): CLIVersionInfo | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Clear cached version.
|
|
23
|
+
*/
|
|
24
|
+
clearCache(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Build appropriate arguments based on version capabilities.
|
|
27
|
+
*/
|
|
28
|
+
buildArgs(options: {
|
|
29
|
+
prompt: string;
|
|
30
|
+
outputFormat?: string;
|
|
31
|
+
}): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Compare two semver versions.
|
|
34
|
+
* Returns: -1 if a < b, 0 if a == b, 1 if a > b
|
|
35
|
+
*/
|
|
36
|
+
private compareVersions;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get or create the CLI version detector.
|
|
40
|
+
*/
|
|
41
|
+
export declare function getCLIVersionDetector(): CLIVersionDetector;
|
|
42
|
+
/**
|
|
43
|
+
* Detect CLI version (convenience function).
|
|
44
|
+
*/
|
|
45
|
+
export declare function detectCLIVersion(): Promise<CLIVersionInfo>;
|
|
46
|
+
/**
|
|
47
|
+
* Check if CLI is installed (convenience function).
|
|
48
|
+
*/
|
|
49
|
+
export declare function isCLIInstalled(): Promise<boolean>;
|
|
50
|
+
//# sourceMappingURL=cli-version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-version.d.ts","sourceRoot":"","sources":["../../src/ai-provider/cli-version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAiBjD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,aAAa,CAAC,CAAiB;IAEvC;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,cAAc,CAAC;IAqCvC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IASrC;;OAEG;IACH,gBAAgB,IAAI,cAAc,GAAG,SAAS;IAI9C;;OAEG;IACH,UAAU,IAAI,IAAI;IAIlB;;OAEG;IACH,SAAS,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,EAAE;IAoBvE;;;OAGG;IACH,OAAO,CAAC,eAAe;CAcxB;AAOD;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,kBAAkB,CAK1D;AAED;;GAEG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,cAAc,CAAC,CAEhE;AAED;;GAEG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC,CAEvD"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Version Detection
|
|
3
|
+
*
|
|
4
|
+
* Detects Claude CLI version and feature support.
|
|
5
|
+
*/
|
|
6
|
+
import { execSync } from 'child_process';
|
|
7
|
+
import { CLINotFoundError } from './errors.js';
|
|
8
|
+
import { createLogger } from './logger.js';
|
|
9
|
+
const logger = createLogger('CLIVersionDetector');
|
|
10
|
+
/**
|
|
11
|
+
* Minimum required version for various features.
|
|
12
|
+
*/
|
|
13
|
+
const FEATURE_REQUIREMENTS = {
|
|
14
|
+
outputFormat: '1.0.0',
|
|
15
|
+
printMode: '1.0.0',
|
|
16
|
+
workingDirectory: '1.0.0',
|
|
17
|
+
streamJson: '1.0.0',
|
|
18
|
+
modelSelection: '1.0.0',
|
|
19
|
+
};
|
|
20
|
+
export class CLIVersionDetector {
|
|
21
|
+
cachedVersion;
|
|
22
|
+
/**
|
|
23
|
+
* Detect CLI version and capabilities.
|
|
24
|
+
*/
|
|
25
|
+
async detect() {
|
|
26
|
+
if (this.cachedVersion) {
|
|
27
|
+
return this.cachedVersion;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
const output = execSync('claude --version', {
|
|
31
|
+
encoding: 'utf-8',
|
|
32
|
+
timeout: 10000,
|
|
33
|
+
});
|
|
34
|
+
const match = output.match(/v?(\d+\.\d+\.\d+)/);
|
|
35
|
+
if (!match) {
|
|
36
|
+
logger.warn('Could not parse version from output', { output });
|
|
37
|
+
throw new Error('Could not parse version');
|
|
38
|
+
}
|
|
39
|
+
const version = match[1];
|
|
40
|
+
this.cachedVersion = {
|
|
41
|
+
version,
|
|
42
|
+
supportsOutputFormat: this.compareVersions(version, FEATURE_REQUIREMENTS.outputFormat) >= 0,
|
|
43
|
+
supportsPrintMode: this.compareVersions(version, FEATURE_REQUIREMENTS.printMode) >= 0,
|
|
44
|
+
supportsWorkingDirectory: this.compareVersions(version, FEATURE_REQUIREMENTS.workingDirectory) >= 0,
|
|
45
|
+
};
|
|
46
|
+
logger.info('CLI version detected', { ...this.cachedVersion });
|
|
47
|
+
return this.cachedVersion;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (error.code === 'ENOENT') {
|
|
51
|
+
throw new CLINotFoundError();
|
|
52
|
+
}
|
|
53
|
+
throw new CLINotFoundError();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Check if CLI is installed.
|
|
58
|
+
*/
|
|
59
|
+
async isInstalled() {
|
|
60
|
+
try {
|
|
61
|
+
await this.detect();
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get cached version info (throws if not detected yet).
|
|
70
|
+
*/
|
|
71
|
+
getCachedVersion() {
|
|
72
|
+
return this.cachedVersion;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Clear cached version.
|
|
76
|
+
*/
|
|
77
|
+
clearCache() {
|
|
78
|
+
this.cachedVersion = undefined;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Build appropriate arguments based on version capabilities.
|
|
82
|
+
*/
|
|
83
|
+
buildArgs(options) {
|
|
84
|
+
const version = this.cachedVersion;
|
|
85
|
+
const args = [];
|
|
86
|
+
// Print mode for non-interactive execution
|
|
87
|
+
if (version?.supportsPrintMode) {
|
|
88
|
+
args.push('--print');
|
|
89
|
+
}
|
|
90
|
+
// Output format
|
|
91
|
+
if (version?.supportsOutputFormat && options.outputFormat) {
|
|
92
|
+
args.push('--output-format', options.outputFormat);
|
|
93
|
+
}
|
|
94
|
+
// The prompt (positional argument, not --prompt flag)
|
|
95
|
+
args.push(options.prompt);
|
|
96
|
+
return args;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Compare two semver versions.
|
|
100
|
+
* Returns: -1 if a < b, 0 if a == b, 1 if a > b
|
|
101
|
+
*/
|
|
102
|
+
compareVersions(a, b) {
|
|
103
|
+
const partsA = a.split('.').map(Number);
|
|
104
|
+
const partsB = b.split('.').map(Number);
|
|
105
|
+
for (let i = 0; i < 3; i++) {
|
|
106
|
+
const numA = partsA[i] || 0;
|
|
107
|
+
const numB = partsB[i] || 0;
|
|
108
|
+
if (numA < numB)
|
|
109
|
+
return -1;
|
|
110
|
+
if (numA > numB)
|
|
111
|
+
return 1;
|
|
112
|
+
}
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Singleton instance for convenience.
|
|
118
|
+
*/
|
|
119
|
+
let detector = null;
|
|
120
|
+
/**
|
|
121
|
+
* Get or create the CLI version detector.
|
|
122
|
+
*/
|
|
123
|
+
export function getCLIVersionDetector() {
|
|
124
|
+
if (!detector) {
|
|
125
|
+
detector = new CLIVersionDetector();
|
|
126
|
+
}
|
|
127
|
+
return detector;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Detect CLI version (convenience function).
|
|
131
|
+
*/
|
|
132
|
+
export async function detectCLIVersion() {
|
|
133
|
+
return getCLIVersionDetector().detect();
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Check if CLI is installed (convenience function).
|
|
137
|
+
*/
|
|
138
|
+
export async function isCLIInstalled() {
|
|
139
|
+
return getCLIVersionDetector().isInstalled();
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=cli-version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-version.js","sourceRoot":"","sources":["../../src/ai-provider/cli-version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,MAAM,GAAG,YAAY,CAAC,oBAAoB,CAAC,CAAC;AAElD;;GAEG;AACH,MAAM,oBAAoB,GAAG;IAC3B,YAAY,EAAE,OAAO;IACrB,SAAS,EAAE,OAAO;IAClB,gBAAgB,EAAE,OAAO;IACzB,UAAU,EAAE,OAAO;IACnB,cAAc,EAAE,OAAO;CACxB,CAAC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C,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3B,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAE5B,IAAI,IAAI,GAAG,IAAI;gBAAE,OAAO,CAAC,CAAC,CAAC;YAC3B,IAAI,IAAI,GAAG,IAAI;gBAAE,OAAO,CAAC,CAAC;QAC5B,CAAC;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AAED;;GAEG;AACH,IAAI,QAAQ,GAA8B,IAAI,CAAC;AAE/C;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACnC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,IAAI,kBAAkB,EAAE,CAAC;IACtC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,OAAO,qBAAqB,EAAE,CAAC,MAAM,EAAE,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc;IAClC,OAAO,qBAAqB,EAAE,CAAC,WAAW,EAAE,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Provider Configuration Loader
|
|
3
|
+
*
|
|
4
|
+
* Loads configuration from local sources with caching.
|
|
5
|
+
*/
|
|
6
|
+
import type { AIProviderConfig } from './types.js';
|
|
7
|
+
export declare class ConfigLoader {
|
|
8
|
+
private cache;
|
|
9
|
+
private cacheTimestamp;
|
|
10
|
+
private userId;
|
|
11
|
+
constructor(userId: string);
|
|
12
|
+
/**
|
|
13
|
+
* Get configuration with caching.
|
|
14
|
+
*/
|
|
15
|
+
getConfig(): Promise<AIProviderConfig>;
|
|
16
|
+
/**
|
|
17
|
+
* Update configuration.
|
|
18
|
+
*/
|
|
19
|
+
updateConfig(updates: Partial<AIProviderConfig>): Promise<AIProviderConfig>;
|
|
20
|
+
/**
|
|
21
|
+
* Get default configuration.
|
|
22
|
+
*/
|
|
23
|
+
getDefaults(): AIProviderConfig;
|
|
24
|
+
/**
|
|
25
|
+
* Invalidate cache.
|
|
26
|
+
*/
|
|
27
|
+
invalidateCache(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Set cache directly (useful for testing or initialization).
|
|
30
|
+
*/
|
|
31
|
+
setCache(config: AIProviderConfig): void;
|
|
32
|
+
/**
|
|
33
|
+
* Get user ID.
|
|
34
|
+
*/
|
|
35
|
+
getUserId(): string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get or create a config loader for a user.
|
|
39
|
+
*/
|
|
40
|
+
export declare function getConfigLoader(userId: string): ConfigLoader;
|
|
41
|
+
/**
|
|
42
|
+
* Create a new config loader.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createConfigLoader(userId: string): ConfigLoader;
|
|
45
|
+
//# sourceMappingURL=config-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../../src/ai-provider/config-loader.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAoBnD,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAiC;IAC9C,OAAO,CAAC,cAAc,CAAa;IACnC,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,MAAM;IAI1B;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAe5C;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAcjF;;OAEG;IACH,WAAW,IAAI,gBAAgB;IAI/B;;OAEG;IACH,eAAe,IAAI,IAAI;IAMvB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI;IAKxC;;OAEG;IACH,SAAS,IAAI,MAAM;CAGpB;AAOD;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAO5D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAE/D"}
|