bravecode-cli 0.1.0

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 (104) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +387 -0
  3. package/dist/autoModel.d.ts +39 -0
  4. package/dist/autoModel.d.ts.map +1 -0
  5. package/dist/autoModel.js +127 -0
  6. package/dist/autoModel.js.map +1 -0
  7. package/dist/cli.cjs +41727 -0
  8. package/dist/cli.cjs.map +7 -0
  9. package/dist/cli.d.ts +2 -0
  10. package/dist/cli.d.ts.map +1 -0
  11. package/dist/cli.js +459 -0
  12. package/dist/cli.js.map +1 -0
  13. package/dist/cli.mjs +41000 -0
  14. package/dist/cli.mjs.map +7 -0
  15. package/dist/core/agent/index.d.ts +31 -0
  16. package/dist/core/agent/index.d.ts.map +1 -0
  17. package/dist/core/agent/index.js +339 -0
  18. package/dist/core/agent/index.js.map +1 -0
  19. package/dist/core/config/index.d.ts +54 -0
  20. package/dist/core/config/index.d.ts.map +1 -0
  21. package/dist/core/config/index.js +138 -0
  22. package/dist/core/config/index.js.map +1 -0
  23. package/dist/core/context/index.d.ts +20 -0
  24. package/dist/core/context/index.d.ts.map +1 -0
  25. package/dist/core/context/index.js +70 -0
  26. package/dist/core/context/index.js.map +1 -0
  27. package/dist/core/mcp/index.d.ts +32 -0
  28. package/dist/core/mcp/index.d.ts.map +1 -0
  29. package/dist/core/mcp/index.js +160 -0
  30. package/dist/core/mcp/index.js.map +1 -0
  31. package/dist/core/permission/index.d.ts +24 -0
  32. package/dist/core/permission/index.d.ts.map +1 -0
  33. package/dist/core/permission/index.js +96 -0
  34. package/dist/core/permission/index.js.map +1 -0
  35. package/dist/core/plugin/index.d.ts +44 -0
  36. package/dist/core/plugin/index.d.ts.map +1 -0
  37. package/dist/core/plugin/index.js +139 -0
  38. package/dist/core/plugin/index.js.map +1 -0
  39. package/dist/core/session/index.d.ts +23 -0
  40. package/dist/core/session/index.d.ts.map +1 -0
  41. package/dist/core/session/index.js +51 -0
  42. package/dist/core/session/index.js.map +1 -0
  43. package/dist/core/share/index.d.ts +28 -0
  44. package/dist/core/share/index.d.ts.map +1 -0
  45. package/dist/core/share/index.js +100 -0
  46. package/dist/core/share/index.js.map +1 -0
  47. package/dist/core/snapshot/index.d.ts +30 -0
  48. package/dist/core/snapshot/index.d.ts.map +1 -0
  49. package/dist/core/snapshot/index.js +141 -0
  50. package/dist/core/snapshot/index.js.map +1 -0
  51. package/dist/core/tool/bash.d.ts +8 -0
  52. package/dist/core/tool/bash.d.ts.map +1 -0
  53. package/dist/core/tool/bash.js +29 -0
  54. package/dist/core/tool/bash.js.map +1 -0
  55. package/dist/core/tool/browser.d.ts +5 -0
  56. package/dist/core/tool/browser.d.ts.map +1 -0
  57. package/dist/core/tool/browser.js +119 -0
  58. package/dist/core/tool/browser.js.map +1 -0
  59. package/dist/core/tool/file.d.ts +5 -0
  60. package/dist/core/tool/file.d.ts.map +1 -0
  61. package/dist/core/tool/file.js +79 -0
  62. package/dist/core/tool/file.js.map +1 -0
  63. package/dist/core/tool/index.d.ts +21 -0
  64. package/dist/core/tool/index.d.ts.map +1 -0
  65. package/dist/core/tool/index.js +90 -0
  66. package/dist/core/tool/index.js.map +1 -0
  67. package/dist/core/tool/search.d.ts +4 -0
  68. package/dist/core/tool/search.d.ts.map +1 -0
  69. package/dist/core/tool/search.js +107 -0
  70. package/dist/core/tool/search.js.map +1 -0
  71. package/dist/core/tool/task.d.ts +9 -0
  72. package/dist/core/tool/task.d.ts.map +1 -0
  73. package/dist/core/tool/task.js +54 -0
  74. package/dist/core/tool/task.js.map +1 -0
  75. package/dist/core/tool/todowrite.d.ts +3 -0
  76. package/dist/core/tool/todowrite.d.ts.map +1 -0
  77. package/dist/core/tool/todowrite.js +75 -0
  78. package/dist/core/tool/todowrite.js.map +1 -0
  79. package/dist/core/tool/websearch.d.ts +3 -0
  80. package/dist/core/tool/websearch.d.ts.map +1 -0
  81. package/dist/core/tool/websearch.js +46 -0
  82. package/dist/core/tool/websearch.js.map +1 -0
  83. package/dist/core/tui/ChatTUI.d.ts +17 -0
  84. package/dist/core/tui/ChatTUI.d.ts.map +1 -0
  85. package/dist/core/tui/ChatTUI.js +64 -0
  86. package/dist/core/tui/ChatTUI.js.map +1 -0
  87. package/dist/core/tui/index.d.ts +15 -0
  88. package/dist/core/tui/index.d.ts.map +1 -0
  89. package/dist/core/tui/index.js +41 -0
  90. package/dist/core/tui/index.js.map +1 -0
  91. package/dist/core/update/index.d.ts +23 -0
  92. package/dist/core/update/index.d.ts.map +1 -0
  93. package/dist/core/update/index.js +115 -0
  94. package/dist/core/update/index.js.map +1 -0
  95. package/dist/index.d.ts +18 -0
  96. package/dist/index.d.ts.map +1 -0
  97. package/dist/index.js +11 -0
  98. package/dist/index.js.map +1 -0
  99. package/dist/models.json +545 -0
  100. package/dist/provider.d.ts +43 -0
  101. package/dist/provider.d.ts.map +1 -0
  102. package/dist/provider.js +294 -0
  103. package/dist/provider.js.map +1 -0
  104. package/package.json +88 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BraveCode Tech
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,387 @@
1
+ # BraveCode AI CLI
2
+
3
+ A free, open-source AI coding CLI with 6 specialized agents, 12+ developer tools, and free model access — all for $0/month with no API keys required.
4
+
5
+ ![BraveCode AI](https://raw.githubusercontent.com/brave-code-tech/brave-ai/main/public/icon.svg)
6
+
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+ [![npm version](https://img.shields.io/npm/v/@bravecode/cli.svg)](https://www.npmjs.com/package/@bravecode/cli)
9
+ [![Downloads](https://img.shields.io/npm/dm/@bravecode/cli.svg)](https://www.npmjs.com/package/@bravecode/cli)
10
+
11
+ ## Features
12
+
13
+ ### Free Models — No API Keys Required
14
+
15
+ | Model | Best For |
16
+ |-------|----------|
17
+ | Codestral | Code generation, completions |
18
+ | Mistral Large | General tasks |
19
+ | DeepSeek-R1 | Complex reasoning, debugging |
20
+ | DeepSeek-V3 | Balanced performance |
21
+ | Voxtral | Audio processing |
22
+ | Ministral | Fast responses |
23
+
24
+ ### 12 Built-in Tools
25
+
26
+ | Tool | Purpose |
27
+ |------|---------|
28
+ | `bash` | Execute shell commands |
29
+ | `read` | Read file contents |
30
+ | `write` | Create/overwrite files |
31
+ | `edit` | Modify existing files |
32
+ | `grep` | Search file contents |
33
+ | `glob` | Find files by pattern |
34
+ | `browser` | Automate web browsers |
35
+ | `webfetch` | Fetch URL content |
36
+ | `curl` | Make HTTP requests |
37
+ | `todowrite` | Manage task lists |
38
+ | `websearch` | Search the web |
39
+ | `task` | Delegate to subagents |
40
+
41
+ ### 6 Specialized Agents
42
+
43
+ | Agent | Purpose | Model |
44
+ |-------|---------|-------|
45
+ | Build | Full development access | Codestral |
46
+ | Plan | Read-only architecture review | Codestral |
47
+ | Debug | Bug investigation | DeepSeek-R1 |
48
+ | Testing | Test writing | Codestral |
49
+ | Security | Vulnerability audit | DeepSeek-R1 |
50
+ | API Security | API penetration testing | DeepSeek-R1 |
51
+
52
+ ### Safety-First Design
53
+
54
+ - **Permission System** — Allow/ask/deny for tool execution
55
+ - **Git Snapshots** — Automatic before every file edit
56
+ - **One-Command Undo** — Revert any change instantly
57
+ - **Context Compaction** — Stay within token limits
58
+
59
+ ## Installation
60
+
61
+ ```bash
62
+ npm install -g @bravecode/cli
63
+ ```
64
+
65
+ Or via npx (no install required):
66
+
67
+ ```bash
68
+ npx @bravecode/cli chat
69
+ ```
70
+
71
+ ## Quick Start
72
+
73
+ ```bash
74
+ # Start interactive chat
75
+ bravecode
76
+
77
+ # Run a single command
78
+ bravecode run "add error handling to the login function"
79
+
80
+ # Select a model
81
+ bravecode select
82
+
83
+ # View available models
84
+ bravecode models
85
+
86
+ # List all tools
87
+ bravecode tools
88
+
89
+ # List all agents
90
+ bravecode agents
91
+ ```
92
+
93
+ ## Commands
94
+
95
+ | Command | Description |
96
+ |---------|-------------|
97
+ | `bravecode` | Start interactive chat |
98
+ | `bravecode chat` | Start chat session |
99
+ | `bravecode run <prompt>` | Run a single prompt |
100
+ | `bravecode models` | List available models |
101
+ | `bravecode providers` | List providers |
102
+ | `bravecode select` | Interactive model selection |
103
+ | `bravecode tools` | List available tools |
104
+ | `bravecode agents` | List available agents |
105
+ | `bravecode open <file>` | Open file in editor |
106
+ | `bravecode fetch <url>` | Fetch URL content |
107
+ | `bravecode init` | Initialize AGENTS.md |
108
+ | `bravecode config` | View/edit configuration |
109
+ | `bravecode mcp` | Manage MCP servers |
110
+ | `bravecode plugins` | Manage plugins |
111
+ | `bravecode share` | Share conversation |
112
+ | `bravecode update` | Update CLI |
113
+
114
+ ## Configuration
115
+
116
+ BraveCode AI stores configuration in `~/.bravecode/config.json`.
117
+
118
+ ```bash
119
+ # View config
120
+ bravecode config
121
+
122
+ # Set a value
123
+ bravecode config set editor.theme dark
124
+
125
+ # Get a value
126
+ bravecode config get provider.default
127
+ ```
128
+
129
+ ### Providers
130
+
131
+ Configure additional providers in `~/.bravecode/config.json`:
132
+
133
+ ```json
134
+ {
135
+ "providers": {
136
+ "openrouter": {
137
+ "name": "OpenRouter",
138
+ "apiKey": "sk-or-...",
139
+ "baseUrl": "https://openrouter.ai/api/v1"
140
+ }
141
+ }
142
+ }
143
+ ```
144
+
145
+ ### Default Models
146
+
147
+ BraveCode AI uses free models by default:
148
+
149
+ - **Codestral** — Code generation and completions
150
+ - **Mistral Large** — General tasks
151
+ - **DeepSeek-R1** — Reasoning and debugging
152
+
153
+ No API keys required for default models.
154
+
155
+ ## Tools in Detail
156
+
157
+ ### File Operations
158
+
159
+ ```bash
160
+ # Read a file
161
+ bravecode run "read src/index.ts"
162
+
163
+ # Write a file
164
+ bravecode run "create a hello world Python script"
165
+
166
+ # Edit a file
167
+ bravecode run "add error handling to src/api.ts"
168
+ ```
169
+
170
+ ### Web Automation
171
+
172
+ ```bash
173
+ # Search the web
174
+ bravecode run "search for React 19 new features"
175
+
176
+ # Fetch a URL
177
+ bravecode run "fetch https://api.example.com/data"
178
+
179
+ # Open a browser
180
+ bravecode run "open https://github.com in a browser"
181
+ ```
182
+
183
+ ### Task Management
184
+
185
+ ```bash
186
+ # Create a todo list
187
+ bravecode run "create a todo list for building a REST API"
188
+
189
+ # Mark items complete
190
+ bravecode run "mark the first todo as complete"
191
+ ```
192
+
193
+ ## Multi-Agent Workflows
194
+
195
+ ```bash
196
+ # Start with build agent
197
+ bravecode agents build
198
+
199
+ # Switch to debug agent
200
+ bravecode agents debug
201
+
202
+ # Use plan agent for architecture
203
+ bravecode agents plan
204
+ ```
205
+
206
+ ### Subagent Delegation
207
+
208
+ Agents can delegate tasks to other agents:
209
+
210
+ ```
211
+ You: Refactor the authentication module and add tests
212
+
213
+ Build Agent:
214
+ 1. Delegates refactoring to Build agent
215
+ 2. Delegates test writing to Testing agent
216
+ 3. Delegates security review to Security agent
217
+ 4. Combines results
218
+ ```
219
+
220
+ ## Plugin System
221
+
222
+ Create custom tools and hooks:
223
+
224
+ ```bash
225
+ # Install a plugin
226
+ bravecode plugins install @bravecode/plugin-linter
227
+
228
+ # List installed plugins
229
+ bravecode plugins list
230
+ ```
231
+
232
+ ### Creating Plugins
233
+
234
+ ```typescript
235
+ // ~/.bravecode/plugins/my-plugin/index.ts
236
+ export const plugin = {
237
+ name: 'my-plugin',
238
+ tools: [
239
+ {
240
+ name: 'my-tool',
241
+ description: 'My custom tool',
242
+ execute: async (args) => {
243
+ return { result: 'Hello from my tool!' };
244
+ }
245
+ }
246
+ ],
247
+ hooks: {
248
+ beforeToolCall: async (tool, args) => {
249
+ console.log(`About to call ${tool.name}`);
250
+ }
251
+ }
252
+ };
253
+ ```
254
+
255
+ ## MCP Integration
256
+
257
+ Connect to external tool servers:
258
+
259
+ ```bash
260
+ # Add an MCP server
261
+ bravecode mcp add my-server npx @modelcontextprotocol/server-filesystem /path/to/dir
262
+
263
+ # List MCP servers
264
+ bravecode mcp list
265
+
266
+ # Remove an MCP server
267
+ bravecode mcp remove my-server
268
+ ```
269
+
270
+ ## Cross-Platform Support
271
+
272
+ - **Linux** — Full support
273
+ - **macOS** — Full support
274
+ - **Windows** — Full support (via Git Bash, WSL, or native)
275
+
276
+ ## Development
277
+
278
+ ### Prerequisites
279
+
280
+ - Node.js 18+
281
+ - npm or yarn
282
+
283
+ ### Setup
284
+
285
+ ```bash
286
+ # Clone the repository
287
+ git clone https://github.com/brave-code-tech/brave-ai.git
288
+ cd brave-ai
289
+
290
+ # Install dependencies
291
+ npm install
292
+
293
+ # Build the CLI
294
+ npm run build
295
+
296
+ # Run in development
297
+ npm run dev
298
+ ```
299
+
300
+ ### Project Structure
301
+
302
+ ```
303
+ brave-ai/
304
+ ├── src/
305
+ │ ├── cli.ts # CLI entry point
306
+ │ ├── index.ts # Public exports
307
+ │ ├── provider.ts # LLM provider manager
308
+ │ ├── autoModel.ts # Auto-model selection
309
+ │ ├── core/
310
+ │ │ ├── agent/ # Agent system
311
+ │ │ ├── tool/ # Tool implementations
312
+ │ │ ├── permission/ # Permission system
313
+ │ │ ├── snapshot/ # Git snapshots
314
+ │ │ ├── config/ # Configuration
315
+ │ │ ├── context/ # Context compaction
316
+ │ │ ├── mcp/ # MCP integration
317
+ │ │ ├── plugin/ # Plugin system
318
+ │ │ ├── share/ # Sharing
319
+ │ │ ├── update/ # Auto-update
320
+ │ │ └── tui/ # Terminal UI
321
+ │ └── ...
322
+ ├── scripts/
323
+ │ ├── build.js # Build script
324
+ │ └── postinstall.js # Post-install setup
325
+ ├── package.json
326
+ ├── tsconfig.json
327
+ └── BUILD-AGENTIC-AI-VIBE-CODING-CLI.md # Architecture
328
+ ```
329
+
330
+ ### Build
331
+
332
+ ```bash
333
+ # Build for production
334
+ npm run build
335
+
336
+ # Output: dist/cli.cjs
337
+ ```
338
+
339
+ ### Testing
340
+
341
+ ```bash
342
+ # Run tests
343
+ npm test
344
+
345
+ # Run specific test
346
+ npm test -- --grep "tool name"
347
+ ```
348
+
349
+ ## Architecture
350
+
351
+ See [BUILD-AGENTIC-AI-VIBE-CODING-CLI.md](BUILD-AGENTIC-AI-VIBE-CODING-CLI.md) for the complete architecture document.
352
+
353
+ ## Contributing
354
+
355
+ 1. Fork the repository
356
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
357
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
358
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
359
+ 5. Open a Pull Request
360
+
361
+ ### Development Guidelines
362
+
363
+ - Follow TypeScript best practices
364
+ - Add tests for new features
365
+ - Update documentation
366
+ - Follow existing code style
367
+
368
+ ## License
369
+
370
+ MIT License - see [LICENSE](LICENSE) for details.
371
+
372
+ ## Support
373
+
374
+ - **Issues:** [GitHub Issues](https://github.com/brave-code-tech/brave-ai/issues)
375
+ - **Discussions:** [GitHub Discussions](https://github.com/brave-code-tech/brave-ai/discussions)
376
+ - **Website:** [bravecode.dev](https://bravecode.dev)
377
+
378
+ ## Acknowledgments
379
+
380
+ - [Vercel AI SDK](https://sdk.vercel.ai) — AI SDK for model integration
381
+ - [Commander.js](https://github.com/tj/commander.js) — CLI framework
382
+ - [Ink](https://github.com/vadimdemedes/ink) — React for CLI
383
+ - [Codero](https://codero.sohailsyed.com) — Free model API
384
+
385
+ ---
386
+
387
+ Built with TypeScript, Node.js, and a passion for accessible AI coding tools.
@@ -0,0 +1,39 @@
1
+ export interface ModelConfig {
2
+ id: string;
3
+ name: string;
4
+ provider: string;
5
+ contextWindow: number;
6
+ maxOutputTokens: number;
7
+ capabilities: {
8
+ code: boolean;
9
+ reasoning: boolean;
10
+ vision: boolean;
11
+ audio: boolean;
12
+ functionCalling: boolean;
13
+ };
14
+ pricing: {
15
+ input: number;
16
+ output: number;
17
+ };
18
+ tags: string[];
19
+ }
20
+ export type TaskType = "code" | "reasoning" | "vision" | "audio" | "general";
21
+ export interface AutoModelConfig {
22
+ enabled: boolean;
23
+ preferredProvider?: string;
24
+ excludeModels?: string[];
25
+ taskOverrides?: Partial<Record<TaskType, string>>;
26
+ }
27
+ export declare class AutoModelSelector {
28
+ private config;
29
+ private models;
30
+ constructor(config?: Partial<AutoModelConfig>);
31
+ detectTaskType(prompt: string): TaskType;
32
+ selectModel(taskType: TaskType): ModelConfig;
33
+ getDefaultModel(): ModelConfig;
34
+ getModelById(id: string): ModelConfig | undefined;
35
+ getModelsByProvider(provider: string): ModelConfig[];
36
+ getModelsByCapability(capability: keyof ModelConfig["capabilities"]): ModelConfig[];
37
+ listModels(): ModelConfig[];
38
+ }
39
+ //# sourceMappingURL=autoModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autoModel.d.ts","sourceRoot":"","sources":["../src/autoModel.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAA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Config from "./models.json";
2
+ const defaultAutoModelConfig = {
3
+ enabled: true,
4
+ excludeModels: [],
5
+ };
6
+ export class AutoModelSelector {
7
+ config;
8
+ models;
9
+ constructor(config = {}) {
10
+ this.config = { ...defaultAutoModelConfig, ...config };
11
+ this.models = modelsConfig.models;
12
+ }
13
+ detectTaskType(prompt) {
14
+ const lowerPrompt = prompt.toLowerCase();
15
+ // Vision detection
16
+ if (lowerPrompt.includes("image") ||
17
+ lowerPrompt.includes("screenshot") ||
18
+ lowerPrompt.includes("picture") ||
19
+ lowerPrompt.includes("photo") ||
20
+ lowerPrompt.includes("visual")) {
21
+ return "vision";
22
+ }
23
+ // Audio detection
24
+ if (lowerPrompt.includes("audio") ||
25
+ lowerPrompt.includes("voice") ||
26
+ lowerPrompt.includes("speech") ||
27
+ lowerPrompt.includes("sound")) {
28
+ return "audio";
29
+ }
30
+ // Code detection
31
+ if (lowerPrompt.includes("code") ||
32
+ lowerPrompt.includes("function") ||
33
+ lowerPrompt.includes("class") ||
34
+ lowerPrompt.includes("implement") ||
35
+ lowerPrompt.includes("debug") ||
36
+ lowerPrompt.includes("refactor") ||
37
+ lowerPrompt.includes("program") ||
38
+ lowerPrompt.includes("script") ||
39
+ lowerPrompt.includes("typescript") ||
40
+ lowerPrompt.includes("javascript") ||
41
+ lowerPrompt.includes("python") ||
42
+ lowerPrompt.includes("rust") ||
43
+ lowerPrompt.includes("golang")) {
44
+ return "code";
45
+ }
46
+ // Reasoning detection
47
+ if (lowerPrompt.includes("explain") ||
48
+ lowerPrompt.includes("analyze") ||
49
+ lowerPrompt.includes("reason") ||
50
+ lowerPrompt.includes("think") ||
51
+ lowerPrompt.includes("plan") ||
52
+ lowerPrompt.includes("strategy") ||
53
+ lowerPrompt.includes("compare") ||
54
+ lowerPrompt.includes("evaluate")) {
55
+ return "reasoning";
56
+ }
57
+ return "general";
58
+ }
59
+ selectModel(taskType) {
60
+ if (!this.config.enabled) {
61
+ return this.getDefaultModel();
62
+ }
63
+ // Check for task overrides
64
+ if (this.config.taskOverrides?.[taskType]) {
65
+ const overrideId = this.config.taskOverrides[taskType];
66
+ const overrideModel = this.models.find((m) => m.id === overrideId);
67
+ if (overrideModel) {
68
+ return overrideModel;
69
+ }
70
+ }
71
+ // Filter available models
72
+ let availableModels = this.models.filter((m) => {
73
+ if (this.config.excludeModels?.includes(m.id)) {
74
+ return false;
75
+ }
76
+ if (this.config.preferredProvider && m.provider !== this.config.preferredProvider) {
77
+ return false;
78
+ }
79
+ return true;
80
+ });
81
+ // Filter by capability
82
+ let capabilityFiltered = availableModels.filter((m) => {
83
+ switch (taskType) {
84
+ case "code":
85
+ return m.capabilities.code;
86
+ case "reasoning":
87
+ return m.capabilities.reasoning;
88
+ case "vision":
89
+ return m.capabilities.vision;
90
+ case "audio":
91
+ return m.capabilities.audio;
92
+ default:
93
+ return true;
94
+ }
95
+ });
96
+ if (capabilityFiltered.length === 0) {
97
+ capabilityFiltered = availableModels;
98
+ }
99
+ // Sort by tags (recommended first) and then by context window
100
+ capabilityFiltered.sort((a, b) => {
101
+ const aRecommended = a.tags.includes("recommended") ? 1 : 0;
102
+ const bRecommended = b.tags.includes("recommended") ? 1 : 0;
103
+ if (aRecommended !== bRecommended) {
104
+ return bRecommended - aRecommended;
105
+ }
106
+ return b.contextWindow - a.contextWindow;
107
+ });
108
+ return capabilityFiltered[0] || this.getDefaultModel();
109
+ }
110
+ getDefaultModel() {
111
+ return (this.models.find((m) => m.tags.includes("recommended")) ||
112
+ this.models[0]);
113
+ }
114
+ getModelById(id) {
115
+ return this.models.find((m) => m.id === id);
116
+ }
117
+ getModelsByProvider(provider) {
118
+ return this.models.filter((m) => m.provider === provider);
119
+ }
120
+ getModelsByCapability(capability) {
121
+ return this.models.filter((m) => m.capabilities[capability]);
122
+ }
123
+ listModels() {
124
+ return this.models;
125
+ }
126
+ }
127
+ //# sourceMappingURL=autoModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autoModel.js","sourceRoot":"","sources":["../src/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