thatgfsj-code 0.4.0 ā 0.4.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/dist/cmd/index.js +56 -8
- package/dist/cmd/index.js.map +1 -1
- package/dist/llm/anthropic.d.ts +4 -17
- package/dist/llm/anthropic.d.ts.map +1 -1
- package/dist/llm/anthropic.js +54 -12
- package/dist/llm/anthropic.js.map +1 -1
- package/dist/llm/gemini.d.ts +3 -16
- package/dist/llm/gemini.d.ts.map +1 -1
- package/dist/llm/gemini.js +26 -22
- package/dist/llm/gemini.js.map +1 -1
- package/dist/llm/index.d.ts +5 -19
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +87 -87
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/openai.d.ts +9 -23
- package/dist/llm/openai.d.ts.map +1 -1
- package/dist/llm/openai.js +48 -14
- package/dist/llm/openai.js.map +1 -1
- package/dist/llm/provider.d.ts +11 -16
- package/dist/llm/provider.d.ts.map +1 -1
- package/dist/tui/input.d.ts +0 -1
- package/dist/tui/input.d.ts.map +1 -1
- package/dist/tui/input.js +2 -5
- package/dist/tui/input.js.map +1 -1
- package/dist/tui/output.d.ts +27 -12
- package/dist/tui/output.d.ts.map +1 -1
- package/dist/tui/output.js +176 -40
- package/dist/tui/output.js.map +1 -1
- package/dist/tui/repl.d.ts +0 -10
- package/dist/tui/repl.d.ts.map +1 -1
- package/dist/tui/repl.js +76 -42
- package/dist/tui/repl.js.map +1 -1
- package/dist/tui/welcome.d.ts +1 -11
- package/dist/tui/welcome.d.ts.map +1 -1
- package/dist/tui/welcome.js +60 -56
- package/dist/tui/welcome.js.map +1 -1
- package/package.json +1 -1
- package/src/cmd/index.ts +49 -8
- package/src/llm/anthropic.ts +60 -14
- package/src/llm/gemini.ts +31 -24
- package/src/llm/index.ts +94 -92
- package/src/llm/openai.ts +58 -15
- package/src/llm/provider.ts +12 -16
- package/src/tui/input.ts +2 -5
- package/src/tui/output.ts +193 -40
- package/src/tui/repl.ts +82 -43
- package/src/tui/welcome.ts +62 -59
package/src/llm/index.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import chalk from 'chalk';
|
|
7
7
|
import type { ChatMessage, ChatResponse, ChatOptions, ToolCall } from '../types.js';
|
|
8
8
|
import type { Tool } from '../tools/types.js';
|
|
9
|
-
import type { LLMProvider } from './provider.js';
|
|
9
|
+
import type { LLMProvider, StreamChunk } from './provider.js';
|
|
10
10
|
import type { AIConfig, ProviderName } from '../config/types.js';
|
|
11
11
|
import { PROVIDERS } from '../config/providers.js';
|
|
12
12
|
import { OpenAIProvider } from './openai.js';
|
|
@@ -23,9 +23,6 @@ export class LLMService {
|
|
|
23
23
|
this.apiKey = apiKey;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
/**
|
|
27
|
-
* Create LLMService from AIConfig
|
|
28
|
-
*/
|
|
29
26
|
static fromConfig(config: AIConfig): LLMService {
|
|
30
27
|
const providerName = config.provider || 'siliconflow';
|
|
31
28
|
const providerConfig = PROVIDERS[providerName];
|
|
@@ -55,49 +52,32 @@ export class LLMService {
|
|
|
55
52
|
return new LLMService(provider, providerCfg.apiKey);
|
|
56
53
|
}
|
|
57
54
|
|
|
58
|
-
/**
|
|
59
|
-
* Register tools for function calling
|
|
60
|
-
*/
|
|
61
55
|
registerTools(tools: Tool[]): void {
|
|
62
56
|
for (const tool of tools) {
|
|
63
57
|
this.tools.set(tool.name, tool);
|
|
64
58
|
}
|
|
65
59
|
}
|
|
66
60
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
*/
|
|
70
|
-
getProviderName(): string {
|
|
71
|
-
return this.provider.name;
|
|
72
|
-
}
|
|
61
|
+
getProviderName(): string { return this.provider.name; }
|
|
62
|
+
hasApiKey(): boolean { return !!this.apiKey; }
|
|
73
63
|
|
|
74
|
-
/**
|
|
75
|
-
* Check if API key is available
|
|
76
|
-
*/
|
|
77
|
-
hasApiKey(): boolean {
|
|
78
|
-
return !!this.apiKey;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Non-streaming chat
|
|
83
|
-
*/
|
|
84
64
|
async chat(messages: ChatMessage[], options?: ChatOptions): Promise<ChatResponse> {
|
|
85
|
-
if (!this.hasApiKey())
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return this.provider.chat(messages, options);
|
|
65
|
+
if (!this.hasApiKey()) throw new Error(this.getNoKeyMessage());
|
|
66
|
+
const toolsArray = [...this.tools.values()];
|
|
67
|
+
return this.provider.chat(messages, options, toolsArray.length > 0 ? toolsArray : undefined);
|
|
89
68
|
}
|
|
90
69
|
|
|
91
70
|
/**
|
|
92
71
|
* Streaming chat with agent loop (tool call support)
|
|
72
|
+
* - Streams text to the user
|
|
73
|
+
* - Detects structured tool calls from the API
|
|
74
|
+
* - Executes tools and loops back for more
|
|
93
75
|
*/
|
|
94
76
|
async *chatStream(
|
|
95
77
|
messages: ChatMessage[],
|
|
96
78
|
options?: ChatOptions & { maxIterations?: number }
|
|
97
79
|
): AsyncGenerator<string, ChatResponse> {
|
|
98
|
-
if (!this.hasApiKey())
|
|
99
|
-
throw new Error(this.getNoKeyMessage());
|
|
100
|
-
}
|
|
80
|
+
if (!this.hasApiKey()) throw new Error(this.getNoKeyMessage());
|
|
101
81
|
|
|
102
82
|
const maxIterations = options?.maxIterations ?? 10;
|
|
103
83
|
let currentMessages = [...messages];
|
|
@@ -105,95 +85,117 @@ export class LLMService {
|
|
|
105
85
|
|
|
106
86
|
while (iterations < maxIterations) {
|
|
107
87
|
iterations++;
|
|
88
|
+
const toolsArray = [...this.tools.values()];
|
|
89
|
+
const hasTools = toolsArray.length > 0;
|
|
108
90
|
|
|
109
|
-
// Stream the response
|
|
110
91
|
let fullContent = '';
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
92
|
+
let detectedToolCalls: ToolCall[] | undefined;
|
|
93
|
+
|
|
94
|
+
// Stream the response, passing tools so the API knows about them
|
|
95
|
+
const stream = this.provider.chatStream(currentMessages, options, hasTools ? toolsArray : undefined);
|
|
96
|
+
|
|
97
|
+
for await (const chunk of stream) {
|
|
98
|
+
if (chunk.type === 'text' && chunk.content) {
|
|
99
|
+
fullContent += chunk.content;
|
|
100
|
+
yield chunk.content;
|
|
101
|
+
} else if (chunk.type === 'tool_calls' && chunk.toolCalls) {
|
|
102
|
+
detectedToolCalls = chunk.toolCalls;
|
|
103
|
+
}
|
|
114
104
|
}
|
|
115
105
|
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
106
|
+
// If we got tool calls, execute them and loop
|
|
107
|
+
if (detectedToolCalls && detectedToolCalls.length > 0) {
|
|
108
|
+
// Add assistant message with tool calls
|
|
109
|
+
currentMessages.push({
|
|
110
|
+
role: 'assistant',
|
|
111
|
+
content: fullContent || '',
|
|
112
|
+
tool_calls: detectedToolCalls,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Execute each tool
|
|
116
|
+
for (const toolCall of detectedToolCalls) {
|
|
117
|
+
const tool = this.tools.get(toolCall.function.name);
|
|
118
|
+
|
|
119
|
+
// Yield structured tool call as JSON line
|
|
120
|
+
yield `\n@@TOOL@@${JSON.stringify({ action: 'call', name: toolCall.function.name, args: toolCall.function.arguments })}\n`;
|
|
123
121
|
|
|
124
|
-
if (
|
|
122
|
+
if (!tool) {
|
|
123
|
+
const errMsg = `Tool "${toolCall.function.name}" not found`;
|
|
125
124
|
currentMessages.push({
|
|
126
|
-
role: '
|
|
127
|
-
content:
|
|
128
|
-
|
|
125
|
+
role: 'tool',
|
|
126
|
+
content: errMsg,
|
|
127
|
+
tool_call_id: toolCall.id,
|
|
128
|
+
name: toolCall.function.name,
|
|
129
129
|
});
|
|
130
|
-
|
|
131
|
-
for (const toolCall of toolCalls) {
|
|
132
|
-
const tool = this.tools.get(toolCall.function.name);
|
|
133
|
-
if (!tool) {
|
|
134
|
-
currentMessages.push({
|
|
135
|
-
role: 'tool',
|
|
136
|
-
content: `Tool "${toolCall.function.name}" not found`,
|
|
137
|
-
tool_call_id: toolCall.id,
|
|
138
|
-
name: toolCall.function.name,
|
|
139
|
-
});
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
try {
|
|
144
|
-
const params = JSON.parse(toolCall.function.arguments || '{}');
|
|
145
|
-
const result = await tool.execute(params);
|
|
146
|
-
currentMessages.push({
|
|
147
|
-
role: 'tool',
|
|
148
|
-
content: result.success ? (result.output || JSON.stringify(result.data)) : (result.error || 'Tool failed'),
|
|
149
|
-
tool_call_id: toolCall.id,
|
|
150
|
-
name: toolCall.function.name,
|
|
151
|
-
});
|
|
152
|
-
yield `\n${chalk.gray(`[tool: ${toolCall.function.name}]`)}`;
|
|
153
|
-
} catch (error: any) {
|
|
154
|
-
currentMessages.push({
|
|
155
|
-
role: 'tool',
|
|
156
|
-
content: `Tool execution error: ${error.message}`,
|
|
157
|
-
tool_call_id: toolCall.id,
|
|
158
|
-
name: toolCall.function.name,
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
130
|
+
yield `@@TOOL@@${JSON.stringify({ action: 'result', error: errMsg })}\n`;
|
|
162
131
|
continue;
|
|
163
132
|
}
|
|
164
|
-
|
|
165
|
-
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
const params = JSON.parse(toolCall.function.arguments || '{}');
|
|
136
|
+
const result = await tool.execute(params);
|
|
137
|
+
const output = result.success ? (result.output || JSON.stringify(result.data)) : (result.error || 'Tool failed');
|
|
138
|
+
|
|
139
|
+
currentMessages.push({
|
|
140
|
+
role: 'tool',
|
|
141
|
+
content: output,
|
|
142
|
+
tool_call_id: toolCall.id,
|
|
143
|
+
name: toolCall.function.name,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
yield `@@TOOL@@${JSON.stringify({ action: 'result', output })}\n`;
|
|
147
|
+
} catch (error: any) {
|
|
148
|
+
const errMsg = `Error: ${error.message}`;
|
|
149
|
+
currentMessages.push({
|
|
150
|
+
role: 'tool',
|
|
151
|
+
content: errMsg,
|
|
152
|
+
tool_call_id: toolCall.id,
|
|
153
|
+
name: toolCall.function.name,
|
|
154
|
+
});
|
|
155
|
+
yield `@@TOOL@@${JSON.stringify({ action: 'result', error: errMsg })}\n`;
|
|
156
|
+
}
|
|
166
157
|
}
|
|
158
|
+
|
|
159
|
+
yield '\n';
|
|
160
|
+
continue;
|
|
167
161
|
}
|
|
168
162
|
|
|
163
|
+
// No tool calls - done
|
|
169
164
|
return { content: fullContent, role: 'assistant' };
|
|
170
165
|
}
|
|
171
166
|
|
|
172
167
|
return { content: '[Agent loop exceeded maximum iterations]', role: 'assistant' };
|
|
173
168
|
}
|
|
174
169
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
170
|
+
private truncateArgs(args: string): string {
|
|
171
|
+
try {
|
|
172
|
+
const obj = JSON.parse(args || '{}');
|
|
173
|
+
const entries = Object.entries(obj);
|
|
174
|
+
if (entries.length === 0) return '';
|
|
175
|
+
return entries.map(([k, v]) => {
|
|
176
|
+
const val = typeof v === 'string' && v.length > 50 ? v.slice(0, 50) + '...' : v;
|
|
177
|
+
return `${k}: ${JSON.stringify(val)}`;
|
|
178
|
+
}).join(', ');
|
|
179
|
+
} catch {
|
|
180
|
+
return args.length > 80 ? args.slice(0, 80) + '...' : args;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
178
184
|
private getNoKeyMessage(): string {
|
|
179
185
|
return [
|
|
180
186
|
'ā ęŖé
ē½® API Keyļ¼ę ę³č°ēØ AIć',
|
|
181
187
|
'',
|
|
182
|
-
'
|
|
183
|
-
' gfcode init',
|
|
188
|
+
'请å
čæč”: gfcode init',
|
|
184
189
|
'',
|
|
185
|
-
'
|
|
186
|
-
' export SILICONFLOW_API_KEY="sk-..."
|
|
187
|
-
' export OPENAI_API_KEY="sk-..."
|
|
188
|
-
' export DEEPSEEK_API_KEY="sk-..."
|
|
189
|
-
' export KIMI_API_KEY="sk-..." # Kimi',
|
|
190
|
-
' export ANTHROPIC_API_KEY="sk-ant-..." # Claude',
|
|
190
|
+
'ę设置ēÆå¢åé:',
|
|
191
|
+
' export SILICONFLOW_API_KEY="sk-..."',
|
|
192
|
+
' export OPENAI_API_KEY="sk-..."',
|
|
193
|
+
' export DEEPSEEK_API_KEY="sk-..."',
|
|
191
194
|
].join('\n');
|
|
192
195
|
}
|
|
193
196
|
}
|
|
194
197
|
|
|
195
|
-
|
|
196
|
-
export type { LLMProvider, ProviderConfig } from './provider.js';
|
|
198
|
+
export type { LLMProvider, ProviderConfig, StreamChunk } from './provider.js';
|
|
197
199
|
export { OpenAIProvider } from './openai.js';
|
|
198
200
|
export { AnthropicProvider } from './anthropic.js';
|
|
199
201
|
export { GeminiProvider } from './gemini.js';
|
package/src/llm/openai.ts
CHANGED
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
* OpenAI-compatible Provider
|
|
3
3
|
* Works with: OpenAI, SiliconFlow, DeepSeek, Kimi, Zhipu, MiniMax, Baichuan, Stepfun, Doubao, Ollama, ERNIE
|
|
4
4
|
* Also works with any OpenAI-compatible relay station (äøč½¬ē«)
|
|
5
|
-
*
|
|
6
|
-
* API: POST {baseUrl}/chat/completions
|
|
7
|
-
* Auth: Authorization: Bearer {apiKey}
|
|
8
|
-
* Streaming: SSE with "data: {...}" lines, ends with "data: [DONE]"
|
|
9
5
|
*/
|
|
10
6
|
|
|
11
|
-
import type { ChatMessage, ChatResponse, ChatOptions } from '../types.js';
|
|
7
|
+
import type { ChatMessage, ChatResponse, ChatOptions, ToolCall } from '../types.js';
|
|
12
8
|
import type { Tool } from '../tools/types.js';
|
|
13
9
|
import type { LLMProvider, ProviderConfig } from './provider.js';
|
|
14
10
|
|
|
11
|
+
export interface StreamChunk {
|
|
12
|
+
type: 'text' | 'tool_calls';
|
|
13
|
+
content?: string;
|
|
14
|
+
toolCalls?: ToolCall[];
|
|
15
|
+
}
|
|
16
|
+
|
|
15
17
|
export class OpenAIProvider implements LLMProvider {
|
|
16
18
|
readonly name = 'openai';
|
|
17
19
|
protected config: ProviderConfig;
|
|
@@ -37,8 +39,8 @@ export class OpenAIProvider implements LLMProvider {
|
|
|
37
39
|
}));
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
async chat(messages: ChatMessage[], options?: ChatOptions): Promise<ChatResponse> {
|
|
41
|
-
const body = this.buildRequest(messages, false, options);
|
|
42
|
+
async chat(messages: ChatMessage[], options?: ChatOptions, tools?: Tool[]): Promise<ChatResponse> {
|
|
43
|
+
const body = this.buildRequest(messages, false, options, tools);
|
|
42
44
|
const response = await this.doRequest(body);
|
|
43
45
|
const data = await response.json();
|
|
44
46
|
const choice = data.choices?.[0];
|
|
@@ -55,8 +57,8 @@ export class OpenAIProvider implements LLMProvider {
|
|
|
55
57
|
};
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
async *chatStream(messages: ChatMessage[], options?: ChatOptions): AsyncGenerator<
|
|
59
|
-
const body = this.buildRequest(messages, true, options);
|
|
60
|
+
async *chatStream(messages: ChatMessage[], options?: ChatOptions, tools?: Tool[]): AsyncGenerator<StreamChunk, ChatResponse> {
|
|
61
|
+
const body = this.buildRequest(messages, true, options, tools);
|
|
60
62
|
const response = await this.doRequest(body);
|
|
61
63
|
|
|
62
64
|
if (!response.ok || !response.body) {
|
|
@@ -68,6 +70,8 @@ export class OpenAIProvider implements LLMProvider {
|
|
|
68
70
|
const decoder = new TextDecoder();
|
|
69
71
|
let fullContent = '';
|
|
70
72
|
let buffer = '';
|
|
73
|
+
// Accumulate streaming tool call chunks
|
|
74
|
+
const toolCallBuffers: Map<number, { id: string; name: string; arguments: string }> = new Map();
|
|
71
75
|
|
|
72
76
|
try {
|
|
73
77
|
while (true) {
|
|
@@ -87,13 +91,25 @@ export class OpenAIProvider implements LLMProvider {
|
|
|
87
91
|
try {
|
|
88
92
|
const data = JSON.parse(trimmed.slice(6));
|
|
89
93
|
const delta = data.choices?.[0]?.delta;
|
|
94
|
+
|
|
95
|
+
// Text content
|
|
90
96
|
if (delta?.content) {
|
|
91
97
|
fullContent += delta.content;
|
|
92
|
-
yield delta.content;
|
|
98
|
+
yield { type: 'text', content: delta.content };
|
|
93
99
|
}
|
|
94
|
-
|
|
100
|
+
|
|
101
|
+
// Streaming tool calls - accumulate chunks
|
|
95
102
|
if (delta?.tool_calls) {
|
|
96
|
-
|
|
103
|
+
for (const tc of delta.tool_calls) {
|
|
104
|
+
const idx = tc.index ?? 0;
|
|
105
|
+
if (!toolCallBuffers.has(idx)) {
|
|
106
|
+
toolCallBuffers.set(idx, { id: '', name: '', arguments: '' });
|
|
107
|
+
}
|
|
108
|
+
const buf = toolCallBuffers.get(idx)!;
|
|
109
|
+
if (tc.id) buf.id = tc.id;
|
|
110
|
+
if (tc.function?.name) buf.name += tc.function.name;
|
|
111
|
+
if (tc.function?.arguments) buf.arguments += tc.function.arguments;
|
|
112
|
+
}
|
|
97
113
|
}
|
|
98
114
|
} catch {
|
|
99
115
|
// Skip invalid JSON lines
|
|
@@ -104,14 +120,34 @@ export class OpenAIProvider implements LLMProvider {
|
|
|
104
120
|
reader.releaseLock();
|
|
105
121
|
}
|
|
106
122
|
|
|
107
|
-
|
|
123
|
+
// Convert accumulated tool call buffers to ToolCall[]
|
|
124
|
+
const toolCalls: ToolCall[] = [];
|
|
125
|
+
for (const [, buf] of toolCallBuffers) {
|
|
126
|
+
if (buf.id && buf.name) {
|
|
127
|
+
toolCalls.push({
|
|
128
|
+
id: buf.id,
|
|
129
|
+
type: 'function',
|
|
130
|
+
function: { name: buf.name, arguments: buf.arguments },
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (toolCalls.length > 0) {
|
|
136
|
+
yield { type: 'tool_calls', toolCalls };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
content: fullContent,
|
|
141
|
+
role: 'assistant',
|
|
142
|
+
tool_calls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
143
|
+
};
|
|
108
144
|
}
|
|
109
145
|
|
|
110
146
|
/**
|
|
111
147
|
* Build the request body for OpenAI-compatible API
|
|
112
148
|
*/
|
|
113
|
-
protected buildRequest(messages: ChatMessage[], stream: boolean, options?: ChatOptions) {
|
|
114
|
-
|
|
149
|
+
protected buildRequest(messages: ChatMessage[], stream: boolean, options?: ChatOptions, tools?: Tool[]) {
|
|
150
|
+
const body: any = {
|
|
115
151
|
model: this.config.model,
|
|
116
152
|
messages: messages.map(m => ({
|
|
117
153
|
role: m.role,
|
|
@@ -125,6 +161,13 @@ export class OpenAIProvider implements LLMProvider {
|
|
|
125
161
|
stream,
|
|
126
162
|
...(stream && { stream_options: { include_usage: true } }),
|
|
127
163
|
};
|
|
164
|
+
|
|
165
|
+
// Add tools if provided - this is critical for structured tool calling
|
|
166
|
+
if (tools && tools.length > 0) {
|
|
167
|
+
body.tools = this.buildTools(tools);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return body;
|
|
128
171
|
}
|
|
129
172
|
|
|
130
173
|
/**
|
package/src/llm/provider.ts
CHANGED
|
@@ -3,32 +3,28 @@
|
|
|
3
3
|
* All providers implement this interface
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { ChatMessage, ChatResponse, ChatOptions } from '../types.js';
|
|
6
|
+
import type { ChatMessage, ChatResponse, ChatOptions, ToolCall } from '../types.js';
|
|
7
7
|
import type { Tool } from '../tools/types.js';
|
|
8
8
|
|
|
9
|
+
export interface StreamChunk {
|
|
10
|
+
type: 'text' | 'tool_calls';
|
|
11
|
+
content?: string;
|
|
12
|
+
toolCalls?: ToolCall[];
|
|
13
|
+
}
|
|
14
|
+
|
|
9
15
|
export interface LLMProvider {
|
|
10
|
-
/** Provider name for logging */
|
|
11
16
|
readonly name: string;
|
|
12
17
|
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
*/
|
|
16
|
-
chat(messages: ChatMessage[], options?: ChatOptions): Promise<ChatResponse>;
|
|
18
|
+
/** Non-streaming chat with optional tools */
|
|
19
|
+
chat(messages: ChatMessage[], options?: ChatOptions, tools?: Tool[]): Promise<ChatResponse>;
|
|
17
20
|
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
*/
|
|
21
|
-
chatStream(messages: ChatMessage[], options?: ChatOptions): AsyncGenerator<string, ChatResponse>;
|
|
21
|
+
/** Streaming chat with optional tools - yields StreamChunks */
|
|
22
|
+
chatStream(messages: ChatMessage[], options?: ChatOptions, tools?: Tool[]): AsyncGenerator<StreamChunk, ChatResponse>;
|
|
22
23
|
|
|
23
|
-
/**
|
|
24
|
-
* Convert Tool[] to provider-specific format
|
|
25
|
-
*/
|
|
24
|
+
/** Convert Tool[] to provider-specific format */
|
|
26
25
|
buildTools(tools: Tool[]): any[];
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
/**
|
|
30
|
-
* Provider configuration passed to each provider
|
|
31
|
-
*/
|
|
32
28
|
export interface ProviderConfig {
|
|
33
29
|
apiKey: string;
|
|
34
30
|
model: string;
|
package/src/tui/input.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* REPL Input Handler
|
|
3
|
-
* Migrated from old src/repl/input.ts
|
|
4
3
|
*/
|
|
5
4
|
|
|
6
5
|
import readline from 'readline';
|
|
@@ -20,13 +19,11 @@ export class REPLInput {
|
|
|
20
19
|
tabSize: 4,
|
|
21
20
|
});
|
|
22
21
|
|
|
23
|
-
// Handle Ctrl+C
|
|
24
22
|
this.rl.on('SIGINT', () => {
|
|
25
|
-
process.stdout.write(chalk.gray('\n
|
|
23
|
+
process.stdout.write(chalk.gray('\n Goodbye! š\n'));
|
|
26
24
|
process.exit(0);
|
|
27
25
|
});
|
|
28
26
|
|
|
29
|
-
// Track history
|
|
30
27
|
this.rl.on('line', (line) => {
|
|
31
28
|
if (line.trim()) {
|
|
32
29
|
this.history.push(line);
|
|
@@ -36,7 +33,7 @@ export class REPLInput {
|
|
|
36
33
|
});
|
|
37
34
|
}
|
|
38
35
|
|
|
39
|
-
async prompt(prefix: string = chalk.
|
|
36
|
+
async prompt(prefix: string = chalk.cyan('⯠')): Promise<string> {
|
|
40
37
|
return new Promise((resolve) => {
|
|
41
38
|
this.rl.question(prefix, (answer) => {
|
|
42
39
|
resolve(answer);
|