friday-code 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yashwanth Reddy
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,154 @@
1
+ # Friday Code
2
+
3
+ **Open-source terminal AI coding agent.**
4
+
5
+ Friday Code is a terminal-native AI assistant that reads, writes, and edits code using tool-calling agent loops. Built with React (Ink), Vercel AI SDK, and SQLite.
6
+
7
+ ```
8
+ ◈ friday code
9
+ model → ollama/qwen3:Thinking
10
+ scope → ~/projects/my-app
11
+
12
+ · explain this project
13
+ · find and fix bugs in @file
14
+ · refactor this module for clarity
15
+ ```
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ npm install -g friday-code
21
+ ```
22
+
23
+ Or run from source:
24
+
25
+ ```bash
26
+ git clone https://github.com/yashwanthreddy/friday-code.git
27
+ cd friday-code
28
+ npm install
29
+ npm run build
30
+ npm start
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ```bash
36
+ friday # Start in current directory
37
+ friday --dir ~/projects # Start with a specific scope
38
+ ```
39
+
40
+ ### Commands
41
+
42
+ | Command | Description |
43
+ |---------|-------------|
44
+ | `/help` | Show all commands and shortcuts |
45
+ | `/model` | Select AI model and provider |
46
+ | `/provider` | Manage providers and API keys |
47
+ | `/scope <path>` | Change working directory |
48
+ | `/config` | View or set configuration |
49
+ | `/clear` | Clear conversation history |
50
+ | `/new` | Start a new conversation |
51
+ | `/history` | Show message count |
52
+ | `/exit` | Quit Friday Code |
53
+
54
+ ### Keyboard Shortcuts
55
+
56
+ | Key | Action |
57
+ |-----|--------|
58
+ | `Enter` | Send message |
59
+ | `Tab` | Autocomplete command or file |
60
+ | `↑` / `↓` | Navigate input history |
61
+ | `Ctrl+C` | Cancel generation |
62
+ | `Ctrl+D` | Exit |
63
+ | `Ctrl+U` | Clear input line |
64
+
65
+ ### File Mentions
66
+
67
+ Reference files inline with `@filename`:
68
+
69
+ ```
70
+ explain what @src/index.ts does and suggest improvements
71
+ ```
72
+
73
+ The file contents are automatically included as context.
74
+
75
+ ## Providers
76
+
77
+ Friday Code supports three AI providers out of the box:
78
+
79
+ | Provider | Setup | Notes |
80
+ |----------|-------|-------|
81
+ | **OpenAI** | Set `OPENAI_API_KEY` env var or use `/provider` | GPT-4o, o1, o3, o4 |
82
+ | **Anthropic** | Set `ANTHROPIC_API_KEY` env var or use `/provider` | Claude Sonnet 4, 3.5 Sonnet |
83
+ | **Ollama** | Install [Ollama](https://ollama.com) locally | Any local model — no API key needed |
84
+
85
+ Models are fetched live from each provider. Use `/model` to browse and select.
86
+
87
+ ## Tools
88
+
89
+ The agent has access to these tools during conversations:
90
+
91
+ | Tool | Description | Approval |
92
+ |------|-------------|----------|
93
+ | `readFile` | Read file contents | Auto |
94
+ | `writeFile` | Create or overwrite a file | Required |
95
+ | `editFile` | Find-and-replace edit | Required |
96
+ | `listDirectory` | List files in a directory | Auto |
97
+ | `searchFiles` | Glob-pattern file search | Auto |
98
+ | `searchContent` | Grep-based content search | Auto |
99
+ | `executeCommand` | Run a shell command | Required |
100
+ | `gitStatus` | Show git status | Auto |
101
+ | `gitDiff` | Show git diff | Auto |
102
+ | `gitLog` | Show commit history | Auto |
103
+ | `gitCommit` | Stage and commit | Required |
104
+ | `webFetch` | Fetch a URL | Auto |
105
+ | `runTests` | Run the test suite | Required |
106
+
107
+ Destructive tools require approval by default. Press `Enter` to approve or `Esc` to deny. Disable with `/config approval off`.
108
+
109
+ ## Configuration
110
+
111
+ Friday Code stores its database at `~/.friday-code/friday.db`.
112
+
113
+ API keys can be set via:
114
+ - Environment variables (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`)
115
+ - The `/provider` command inside the TUI
116
+ - A `.env` file in the working directory
117
+
118
+ Runtime settings via `/config`:
119
+
120
+ | Setting | Values | Default |
121
+ |---------|--------|---------|
122
+ | `maxSteps` | `1`–`100` | `25` |
123
+ | `approval` | `on` / `off` | `on` |
124
+
125
+ ## Architecture
126
+
127
+ ```
128
+ src/
129
+ ├── index.tsx # CLI entry point
130
+ ├── core/
131
+ │ ├── engine/agent.ts # Agent loop (streamText, tool calling)
132
+ │ ├── providers/registry.ts # Provider and model management
133
+ │ └── tools/tools.ts # Tool definitions
134
+ ├── db/
135
+ │ ├── index.ts # Database initialization
136
+ │ └── schema.ts # Drizzle ORM schema
137
+ └── ui/
138
+ ├── theme/theme.ts # Color palette and icons
139
+ ├── components/components.tsx # All UI components
140
+ └── views/
141
+ ├── App.tsx # Main application orchestrator
142
+ ├── InputBox.tsx # Input with autocomplete
143
+ └── ModelSelector.tsx # Model/provider picker
144
+ ```
145
+
146
+ **Stack:** TypeScript · React + Ink · Vercel AI SDK · SQLite + Drizzle ORM · Node.js 18+
147
+
148
+ ## Contributing
149
+
150
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
151
+
152
+ ## License
153
+
154
+ [MIT](LICENSE)
package/bin/friday.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import '../dist/index.js';
@@ -0,0 +1,99 @@
1
+ export type StreamEvent = {
2
+ type: 'step-start';
3
+ stepNumber: number;
4
+ messageId: string;
5
+ } | {
6
+ type: 'step-finish';
7
+ stepNumber: number;
8
+ finishReason: string;
9
+ usage?: {
10
+ promptTokens: number;
11
+ completionTokens: number;
12
+ };
13
+ isContinued: boolean;
14
+ } | {
15
+ type: 'text-delta';
16
+ text: string;
17
+ stepNumber: number;
18
+ } | {
19
+ type: 'reasoning';
20
+ text: string;
21
+ stepNumber: number;
22
+ } | {
23
+ type: 'tool-call-streaming-start';
24
+ stepNumber: number;
25
+ toolCallId: string;
26
+ toolName: string;
27
+ } | {
28
+ type: 'tool-call-delta';
29
+ stepNumber: number;
30
+ toolCallId: string;
31
+ toolName: string;
32
+ argsText: string;
33
+ } | {
34
+ type: 'tool-call';
35
+ stepNumber: number;
36
+ toolCallId: string;
37
+ toolName: string;
38
+ args: unknown;
39
+ } | {
40
+ type: 'tool-result';
41
+ stepNumber: number;
42
+ toolCallId: string;
43
+ toolName: string;
44
+ result: unknown;
45
+ } | {
46
+ type: 'finish';
47
+ text: string;
48
+ reasoning?: string;
49
+ usage?: {
50
+ promptTokens: number;
51
+ completionTokens: number;
52
+ };
53
+ finishReason: string;
54
+ totalSteps: number;
55
+ } | {
56
+ type: 'error';
57
+ error: string;
58
+ } | {
59
+ type: 'status';
60
+ message: string;
61
+ } | {
62
+ type: 'tool-approval-request';
63
+ stepNumber: number;
64
+ toolCallId: string;
65
+ toolName: string;
66
+ args: unknown;
67
+ } | {
68
+ type: 'tool-approval-response';
69
+ toolCallId: string;
70
+ approved: boolean;
71
+ };
72
+ export interface EngineConfig {
73
+ workingDirectory: string;
74
+ conversationId?: string;
75
+ systemPrompt?: string;
76
+ maxSteps?: number;
77
+ }
78
+ export declare class AgentEngine {
79
+ private config;
80
+ private conversationId;
81
+ private messageHistory;
82
+ private abortController;
83
+ private pendingApproval;
84
+ private approvalMode;
85
+ constructor(config: EngineConfig);
86
+ getConversationId(): string;
87
+ loadHistory(): void;
88
+ ensureConversation(): void;
89
+ private saveMessage;
90
+ abort(): void;
91
+ respondToApproval(approved: boolean): void;
92
+ setApprovalMode(enabled: boolean): void;
93
+ getApprovalMode(): boolean;
94
+ run(userMessage: string): AsyncGenerator<StreamEvent>;
95
+ clearHistory(): void;
96
+ setWorkingDirectory(directory: string): void;
97
+ getWorkingDirectory(): string;
98
+ getMessageCount(): number;
99
+ }
@@ -0,0 +1,317 @@
1
+ import { streamText } from 'ai';
2
+ import { createModel, getActiveModelConfig } from '../providers/registry.js';
3
+ import { createTools, TOOL_SAFETY } from '../tools/tools.js';
4
+ import { db } from '../../db/index.js';
5
+ import { conversations, messages as messagesTable } from '../../db/schema.js';
6
+ import { nanoid } from 'nanoid';
7
+ import { eq } from 'drizzle-orm';
8
+ const DEFAULT_SYSTEM_PROMPT = `You are Friday Code, a proactive terminal coding agent.
9
+
10
+ Execution protocol:
11
+ - Keep a short internal plan and update it as the task evolves.
12
+ - Work in visible loops: inspect, act, verify, then continue until the task is actually done.
13
+ - Use tools when evidence is needed. Prefer reading before editing and verifying after changes.
14
+ - When a step is complete, move to the next best action instead of stopping early.
15
+ - Finish only after the work is complete or you genuinely need the user.
16
+
17
+ Working directory: {cwd}`;
18
+ export class AgentEngine {
19
+ config;
20
+ conversationId;
21
+ messageHistory = [];
22
+ abortController = null;
23
+ pendingApproval = null;
24
+ approvalMode = true;
25
+ constructor(config) {
26
+ this.config = config;
27
+ this.conversationId = config.conversationId || nanoid();
28
+ }
29
+ getConversationId() {
30
+ return this.conversationId;
31
+ }
32
+ loadHistory() {
33
+ const rows = db
34
+ .select()
35
+ .from(messagesTable)
36
+ .where(eq(messagesTable.conversationId, this.conversationId))
37
+ .all();
38
+ this.messageHistory = rows.map(row => {
39
+ if (row.role === 'user') {
40
+ return { role: 'user', content: row.content };
41
+ }
42
+ if (row.role === 'assistant') {
43
+ return { role: 'assistant', content: row.content };
44
+ }
45
+ return { role: row.role, content: row.content };
46
+ });
47
+ }
48
+ ensureConversation() {
49
+ const existing = db
50
+ .select()
51
+ .from(conversations)
52
+ .where(eq(conversations.id, this.conversationId))
53
+ .get();
54
+ if (!existing) {
55
+ db.insert(conversations)
56
+ .values({
57
+ id: this.conversationId,
58
+ workingDirectory: this.config.workingDirectory,
59
+ title: 'New Chat',
60
+ })
61
+ .run();
62
+ }
63
+ }
64
+ saveMessage(role, content, extra) {
65
+ db.insert(messagesTable)
66
+ .values({
67
+ id: nanoid(),
68
+ conversationId: this.conversationId,
69
+ role,
70
+ content,
71
+ ...extra,
72
+ })
73
+ .run();
74
+ }
75
+ abort() {
76
+ this.abortController?.abort();
77
+ this.abortController = null;
78
+ }
79
+ respondToApproval(approved) {
80
+ if (this.pendingApproval) {
81
+ this.pendingApproval.resolve(approved);
82
+ this.pendingApproval = null;
83
+ }
84
+ }
85
+ setApprovalMode(enabled) {
86
+ this.approvalMode = enabled;
87
+ }
88
+ getApprovalMode() {
89
+ return this.approvalMode;
90
+ }
91
+ async *run(userMessage) {
92
+ const modelConfig = getActiveModelConfig();
93
+ if (!modelConfig) {
94
+ yield { type: 'error', error: 'No model configured. Use /model to select one.' };
95
+ return;
96
+ }
97
+ this.ensureConversation();
98
+ this.messageHistory.push({ role: 'user', content: userMessage });
99
+ this.saveMessage('user', userMessage);
100
+ const systemPrompt = (this.config.systemPrompt || DEFAULT_SYSTEM_PROMPT)
101
+ .replace('{cwd}', this.config.workingDirectory);
102
+ const rawTools = createTools(this.config.workingDirectory);
103
+ const engine = this;
104
+ const tools = {};
105
+ for (const [name, rawTool] of Object.entries(rawTools)) {
106
+ if (engine.approvalMode && TOOL_SAFETY[name] === 'destructive') {
107
+ tools[name] = {
108
+ ...rawTool,
109
+ execute: async (args) => {
110
+ const approved = await new Promise((resolve) => {
111
+ engine.pendingApproval = { resolve };
112
+ });
113
+ if (!approved) {
114
+ return { error: 'Tool execution denied by user.' };
115
+ }
116
+ return rawTool.execute(args);
117
+ },
118
+ };
119
+ }
120
+ else {
121
+ tools[name] = rawTool;
122
+ }
123
+ }
124
+ this.abortController = new AbortController();
125
+ const model = createModel(modelConfig.provider, modelConfig.modelId);
126
+ let fullText = '';
127
+ let fullReasoning = '';
128
+ let currentStep = 0;
129
+ let openStep = 0;
130
+ const toolCallsLog = [];
131
+ const toolResultsLog = [];
132
+ try {
133
+ yield { type: 'status', message: `Using ${modelConfig.provider.name} / ${modelConfig.modelId}` };
134
+ const providerOptions = {};
135
+ if (modelConfig.provider.type === 'anthropic') {
136
+ providerOptions.anthropic = {
137
+ thinking: { type: 'enabled', budgetTokens: 8000 },
138
+ };
139
+ }
140
+ const result = streamText({
141
+ model,
142
+ system: systemPrompt,
143
+ messages: this.messageHistory,
144
+ tools,
145
+ maxSteps: this.config.maxSteps || 25,
146
+ abortSignal: this.abortController.signal,
147
+ maxRetries: 2,
148
+ providerOptions,
149
+ toolCallStreaming: true,
150
+ });
151
+ for await (const chunk of result.fullStream) {
152
+ const stepNumber = openStep || currentStep || 1;
153
+ switch (chunk.type) {
154
+ case 'step-start': {
155
+ currentStep += 1;
156
+ openStep = currentStep;
157
+ yield { type: 'step-start', stepNumber: currentStep, messageId: chunk.messageId };
158
+ break;
159
+ }
160
+ case 'reasoning': {
161
+ fullReasoning += chunk.textDelta;
162
+ yield { type: 'reasoning', text: chunk.textDelta, stepNumber };
163
+ break;
164
+ }
165
+ case 'tool-call-streaming-start': {
166
+ yield {
167
+ type: 'tool-call-streaming-start',
168
+ stepNumber,
169
+ toolCallId: chunk.toolCallId,
170
+ toolName: chunk.toolName,
171
+ };
172
+ break;
173
+ }
174
+ case 'tool-call-delta': {
175
+ yield {
176
+ type: 'tool-call-delta',
177
+ stepNumber,
178
+ toolCallId: chunk.toolCallId,
179
+ toolName: chunk.toolName,
180
+ argsText: chunk.argsTextDelta,
181
+ };
182
+ break;
183
+ }
184
+ case 'tool-call': {
185
+ toolCallsLog.push({
186
+ stepNumber,
187
+ toolCallId: chunk.toolCallId,
188
+ toolName: chunk.toolName,
189
+ args: chunk.args,
190
+ });
191
+ yield {
192
+ type: 'tool-call',
193
+ stepNumber,
194
+ toolCallId: chunk.toolCallId,
195
+ toolName: chunk.toolName,
196
+ args: chunk.args,
197
+ };
198
+ if (engine.approvalMode && TOOL_SAFETY[chunk.toolName] === 'destructive') {
199
+ yield {
200
+ type: 'tool-approval-request',
201
+ stepNumber,
202
+ toolCallId: chunk.toolCallId,
203
+ toolName: chunk.toolName,
204
+ args: chunk.args,
205
+ };
206
+ }
207
+ break;
208
+ }
209
+ case 'tool-result': {
210
+ toolResultsLog.push({
211
+ stepNumber,
212
+ toolCallId: chunk.toolCallId,
213
+ toolName: chunk.toolName,
214
+ result: chunk.result,
215
+ });
216
+ yield {
217
+ type: 'tool-result',
218
+ stepNumber,
219
+ toolCallId: chunk.toolCallId,
220
+ toolName: chunk.toolName,
221
+ result: chunk.result,
222
+ };
223
+ break;
224
+ }
225
+ case 'text-delta': {
226
+ fullText += chunk.textDelta;
227
+ yield { type: 'text-delta', text: chunk.textDelta, stepNumber };
228
+ break;
229
+ }
230
+ case 'step-finish': {
231
+ yield {
232
+ type: 'step-finish',
233
+ stepNumber,
234
+ finishReason: chunk.finishReason,
235
+ usage: normalizeUsage(chunk.usage),
236
+ isContinued: chunk.isContinued,
237
+ };
238
+ openStep = 0;
239
+ break;
240
+ }
241
+ case 'error':
242
+ yield { type: 'error', error: String(chunk.error) };
243
+ break;
244
+ case 'finish':
245
+ break;
246
+ }
247
+ }
248
+ let usage;
249
+ try {
250
+ usage = await result.usage;
251
+ }
252
+ catch {
253
+ usage = null;
254
+ }
255
+ const finishReason = await result.finishReason;
256
+ this.messageHistory.push({ role: 'assistant', content: fullText });
257
+ this.saveMessage('assistant', fullText, {
258
+ reasoning: fullReasoning || undefined,
259
+ toolCalls: toolCallsLog.length > 0 ? JSON.stringify(toolCallsLog) : undefined,
260
+ toolResults: toolResultsLog.length > 0 ? JSON.stringify(toolResultsLog) : undefined,
261
+ tokenUsage: usage ? JSON.stringify(usage) : undefined,
262
+ finishReason,
263
+ modelId: modelConfig.modelId,
264
+ });
265
+ if (this.messageHistory.length <= 2) {
266
+ const title = userMessage.slice(0, 80) + (userMessage.length > 80 ? '...' : '');
267
+ db.update(conversations)
268
+ .set({ title })
269
+ .where(eq(conversations.id, this.conversationId))
270
+ .run();
271
+ }
272
+ yield {
273
+ type: 'finish',
274
+ text: fullText,
275
+ reasoning: fullReasoning || undefined,
276
+ usage: normalizeUsage(usage),
277
+ finishReason: finishReason || 'stop',
278
+ totalSteps: currentStep,
279
+ };
280
+ }
281
+ catch (error) {
282
+ if (error.name === 'AbortError') {
283
+ yield { type: 'status', message: 'Generation cancelled.' };
284
+ }
285
+ else {
286
+ yield { type: 'error', error: error.message || String(error) };
287
+ }
288
+ }
289
+ finally {
290
+ this.abortController = null;
291
+ }
292
+ }
293
+ clearHistory() {
294
+ this.messageHistory = [];
295
+ this.conversationId = nanoid();
296
+ }
297
+ setWorkingDirectory(directory) {
298
+ this.config.workingDirectory = directory;
299
+ }
300
+ getWorkingDirectory() {
301
+ return this.config.workingDirectory;
302
+ }
303
+ getMessageCount() {
304
+ return this.messageHistory.length;
305
+ }
306
+ }
307
+ function normalizeUsage(usage) {
308
+ if (!usage)
309
+ return undefined;
310
+ const promptTokens = Number(usage?.promptTokens ?? usage?.prompt_tokens ?? 0) || 0;
311
+ const completionTokens = Number(usage?.completionTokens ?? usage?.completion_tokens ?? 0) || 0;
312
+ if (promptTokens === 0 && completionTokens === 0) {
313
+ return undefined;
314
+ }
315
+ return { promptTokens, completionTokens };
316
+ }
317
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../../src/core/engine/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,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N,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACjE,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,YAAY;QACV,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,cAAc,GAAG,MAAM,EAAE,CAAC;IACjC,CAAC;IAED,mBAAmB,CAAC,SAAiB;QACnC,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAC3C,CAAC;IAED,mBAAmB;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC;IACtC,CAAC;IAED,eAAe;QACb,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC;IACpC,CAAC;CACF;AAED,SAAS,cAAc,CAAC,KAAU;IAChC,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,EAAE,YAAY,IAAI,KAAK,EAAE,aAAa,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;IACnF,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,EAAE,gBAAgB,IAAI,KAAK,EAAE,iBAAiB,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;IAE/F,IAAI,YAAY,KAAK,CAAC,IAAI,gBAAgB,KAAK,CAAC,EAAE,CAAC;QACjD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { LanguageModelV1 } from 'ai';
2
+ export interface ProviderConfig {
3
+ id: string;
4
+ name: string;
5
+ type: 'openai' | 'anthropic' | 'ollama';
6
+ apiKey?: string | null;
7
+ baseUrl?: string | null;
8
+ isEnabled: boolean;
9
+ }
10
+ export interface ModelInfo {
11
+ id: string;
12
+ providerId: string;
13
+ modelId: string;
14
+ name: string;
15
+ supportsStreaming: boolean;
16
+ supportsTools: boolean;
17
+ supportsReasoning: boolean;
18
+ contextWindow?: number;
19
+ }
20
+ export declare function createModel(provider: ProviderConfig, modelId: string): LanguageModelV1;
21
+ export declare function fetchModelsFromProvider(provider: ProviderConfig): Promise<ModelInfo[]>;
22
+ export declare function getProviders(): ProviderConfig[];
23
+ export declare function updateProviderKey(providerId: string, apiKey: string): void;
24
+ export declare function getSetting(key: string): string | undefined;
25
+ export declare function setSetting(key: string, value: string): void;
26
+ export declare function cacheModels(modelList: ModelInfo[]): void;
27
+ export declare function getCachedModels(providerId?: string): ModelInfo[];
28
+ export declare function getActiveModelConfig(): {
29
+ provider: ProviderConfig;
30
+ modelId: string;
31
+ } | null;