snow-ai 0.3.11 → 0.3.13
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/agents/compactAgent.js +6 -5
- package/dist/agents/reviewAgent.js +1 -0
- package/dist/agents/summaryAgent.js +1 -0
- package/dist/api/anthropic.d.ts +7 -1
- package/dist/api/anthropic.js +74 -7
- package/dist/api/chat.js +1 -1
- package/dist/api/responses.js +2 -2
- package/dist/api/systemPrompt.js +4 -5
- package/dist/api/types.d.ts +5 -0
- package/dist/hooks/useConversation.js +13 -3
- package/dist/hooks/useFilePicker.d.ts +4 -4
- package/dist/hooks/useFilePicker.js +88 -40
- package/dist/hooks/useHistoryNavigation.d.ts +5 -0
- package/dist/hooks/useHistoryNavigation.js +78 -1
- package/dist/hooks/useInputBuffer.js +1 -1
- package/dist/hooks/useKeyboardInput.d.ts +5 -0
- package/dist/hooks/useKeyboardInput.js +51 -9
- package/dist/hooks/useStreamingState.js +1 -1
- package/dist/mcp/aceCodeSearch.d.ts +4 -0
- package/dist/mcp/aceCodeSearch.js +17 -1
- package/dist/mcp/filesystem.js +2 -2
- package/dist/mcp/utils/filesystem/match-finder.utils.js +1 -1
- package/dist/ui/components/ChatInput.js +11 -4
- package/dist/ui/pages/ChatScreen.js +6 -2
- package/dist/ui/pages/ConfigScreen.js +245 -110
- package/dist/ui/pages/HeadlessModeScreen.js +3 -1
- package/dist/utils/apiConfig.d.ts +5 -0
- package/dist/utils/apiConfig.js +9 -3
- package/dist/utils/contextCompressor.js +7 -2
- package/dist/utils/historyManager.d.ts +45 -0
- package/dist/utils/historyManager.js +159 -0
- package/dist/utils/subAgentExecutor.js +2 -1
- package/dist/utils/textBuffer.js +24 -5
- package/package.json +1 -1
|
@@ -102,6 +102,7 @@ export class CompactAgent {
|
|
|
102
102
|
messages,
|
|
103
103
|
max_tokens: 4096,
|
|
104
104
|
includeBuiltinSystemPrompt: false, // 不需要内置系统提示词
|
|
105
|
+
disableThinking: true, // Agents 不使用 Extended Thinking
|
|
105
106
|
}, abortSignal);
|
|
106
107
|
break;
|
|
107
108
|
case 'gemini':
|
|
@@ -192,14 +193,14 @@ export class CompactAgent {
|
|
|
192
193
|
stack: streamError.stack,
|
|
193
194
|
name: streamError.name,
|
|
194
195
|
chunkCount,
|
|
195
|
-
contentLength: completeContent.length
|
|
196
|
+
contentLength: completeContent.length,
|
|
196
197
|
});
|
|
197
198
|
}
|
|
198
199
|
else {
|
|
199
200
|
logger.error('Compact agent: Unknown streaming error:', {
|
|
200
201
|
error: streamError,
|
|
201
202
|
chunkCount,
|
|
202
|
-
contentLength: completeContent.length
|
|
203
|
+
contentLength: completeContent.length,
|
|
203
204
|
});
|
|
204
205
|
}
|
|
205
206
|
throw streamError;
|
|
@@ -220,14 +221,14 @@ export class CompactAgent {
|
|
|
220
221
|
stack: error.stack,
|
|
221
222
|
name: error.name,
|
|
222
223
|
requestMethod: this.requestMethod,
|
|
223
|
-
modelName: this.modelName
|
|
224
|
+
modelName: this.modelName,
|
|
224
225
|
});
|
|
225
226
|
}
|
|
226
227
|
else {
|
|
227
228
|
logger.error('Compact agent: Unknown API error:', {
|
|
228
229
|
error,
|
|
229
230
|
requestMethod: this.requestMethod,
|
|
230
|
-
modelName: this.modelName
|
|
231
|
+
modelName: this.modelName,
|
|
231
232
|
});
|
|
232
233
|
}
|
|
233
234
|
throw error;
|
|
@@ -291,7 +292,7 @@ Provide the extracted content below:`;
|
|
|
291
292
|
logger.warn('Compact agent extraction failed, using original content:', {
|
|
292
293
|
error: error.message,
|
|
293
294
|
stack: error.stack,
|
|
294
|
-
name: error.name
|
|
295
|
+
name: error.name,
|
|
295
296
|
});
|
|
296
297
|
}
|
|
297
298
|
else {
|
package/dist/api/anthropic.d.ts
CHANGED
|
@@ -7,9 +7,10 @@ export interface AnthropicOptions {
|
|
|
7
7
|
tools?: ChatCompletionTool[];
|
|
8
8
|
sessionId?: string;
|
|
9
9
|
includeBuiltinSystemPrompt?: boolean;
|
|
10
|
+
disableThinking?: boolean;
|
|
10
11
|
}
|
|
11
12
|
export interface AnthropicStreamChunk {
|
|
12
|
-
type: 'content' | 'tool_calls' | 'tool_call_delta' | 'done' | 'usage';
|
|
13
|
+
type: 'content' | 'tool_calls' | 'tool_call_delta' | 'done' | 'usage' | 'reasoning_started' | 'reasoning_delta';
|
|
13
14
|
content?: string;
|
|
14
15
|
tool_calls?: Array<{
|
|
15
16
|
id: string;
|
|
@@ -21,6 +22,11 @@ export interface AnthropicStreamChunk {
|
|
|
21
22
|
}>;
|
|
22
23
|
delta?: string;
|
|
23
24
|
usage?: UsageInfo;
|
|
25
|
+
thinking?: {
|
|
26
|
+
type: 'thinking';
|
|
27
|
+
thinking: string;
|
|
28
|
+
signature?: string;
|
|
29
|
+
};
|
|
24
30
|
}
|
|
25
31
|
export interface AnthropicTool {
|
|
26
32
|
name: string;
|
package/dist/api/anthropic.js
CHANGED
|
@@ -20,6 +20,7 @@ function getAnthropicConfig() {
|
|
|
20
20
|
: 'https://api.anthropic.com/v1',
|
|
21
21
|
customHeaders,
|
|
22
22
|
anthropicBeta: config.anthropicBeta,
|
|
23
|
+
thinking: config.thinking,
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
26
|
return anthropicConfig;
|
|
@@ -124,6 +125,11 @@ function convertToAnthropicMessages(messages, includeBuiltinSystemPrompt = true)
|
|
|
124
125
|
msg.tool_calls &&
|
|
125
126
|
msg.tool_calls.length > 0) {
|
|
126
127
|
const content = [];
|
|
128
|
+
// When thinking is enabled, thinking block must come first
|
|
129
|
+
if (msg.thinking) {
|
|
130
|
+
// Use the complete thinking block object (includes signature)
|
|
131
|
+
content.push(msg.thinking);
|
|
132
|
+
}
|
|
127
133
|
if (msg.content) {
|
|
128
134
|
content.push({
|
|
129
135
|
type: 'text',
|
|
@@ -145,10 +151,29 @@ function convertToAnthropicMessages(messages, includeBuiltinSystemPrompt = true)
|
|
|
145
151
|
continue;
|
|
146
152
|
}
|
|
147
153
|
if (msg.role === 'user' || msg.role === 'assistant') {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
content
|
|
151
|
-
|
|
154
|
+
// For assistant messages with thinking, convert to structured format
|
|
155
|
+
if (msg.role === 'assistant' && msg.thinking) {
|
|
156
|
+
const content = [];
|
|
157
|
+
// Thinking block must come first - use complete block object (includes signature)
|
|
158
|
+
content.push(msg.thinking);
|
|
159
|
+
// Then text content
|
|
160
|
+
if (msg.content) {
|
|
161
|
+
content.push({
|
|
162
|
+
type: 'text',
|
|
163
|
+
text: msg.content,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
anthropicMessages.push({
|
|
167
|
+
role: 'assistant',
|
|
168
|
+
content,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
anthropicMessages.push({
|
|
173
|
+
role: msg.role,
|
|
174
|
+
content: msg.content,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
152
177
|
}
|
|
153
178
|
}
|
|
154
179
|
// 如果配置了自定义系统提示词(最高优先级,始终添加)
|
|
@@ -266,7 +291,6 @@ export async function* createStreamingAnthropicCompletion(options, abortSignal,
|
|
|
266
291
|
const requestBody = {
|
|
267
292
|
model: options.model,
|
|
268
293
|
max_tokens: options.max_tokens || 4096,
|
|
269
|
-
temperature: options.temperature ?? 0.7,
|
|
270
294
|
system,
|
|
271
295
|
messages,
|
|
272
296
|
tools: convertToolsToAnthropic(options.tools),
|
|
@@ -275,11 +299,18 @@ export async function* createStreamingAnthropicCompletion(options, abortSignal,
|
|
|
275
299
|
},
|
|
276
300
|
stream: true,
|
|
277
301
|
};
|
|
302
|
+
// Add thinking configuration if enabled and not explicitly disabled
|
|
303
|
+
// When thinking is enabled, temperature must be 1
|
|
304
|
+
// Note: agents and other internal tools should set disableThinking=true
|
|
305
|
+
if (config.thinking && !options.disableThinking) {
|
|
306
|
+
requestBody.thinking = config.thinking;
|
|
307
|
+
requestBody.temperature = 1;
|
|
308
|
+
}
|
|
278
309
|
// Prepare headers
|
|
279
310
|
const headers = {
|
|
280
311
|
'Content-Type': 'application/json',
|
|
281
312
|
'x-api-key': config.apiKey,
|
|
282
|
-
|
|
313
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
283
314
|
'anthropic-version': '2023-06-01',
|
|
284
315
|
...config.customHeaders,
|
|
285
316
|
};
|
|
@@ -305,10 +336,13 @@ export async function* createStreamingAnthropicCompletion(options, abortSignal,
|
|
|
305
336
|
throw new Error('No response body from Anthropic API');
|
|
306
337
|
}
|
|
307
338
|
let contentBuffer = '';
|
|
339
|
+
let thinkingTextBuffer = ''; // Accumulate thinking text content
|
|
340
|
+
let thinkingSignature = ''; // Accumulate thinking signature
|
|
308
341
|
let toolCallsBuffer = new Map();
|
|
309
342
|
let hasToolCalls = false;
|
|
310
343
|
let usageData;
|
|
311
344
|
let blockIndexToId = new Map();
|
|
345
|
+
let blockIndexToType = new Map(); // Track block types (text, thinking, tool_use)
|
|
312
346
|
let completedToolBlocks = new Set(); // Track which tool blocks have finished streaming
|
|
313
347
|
for await (const event of parseSSEStream(response.body.getReader())) {
|
|
314
348
|
if (abortSignal?.aborted) {
|
|
@@ -316,9 +350,11 @@ export async function* createStreamingAnthropicCompletion(options, abortSignal,
|
|
|
316
350
|
}
|
|
317
351
|
if (event.type === 'content_block_start') {
|
|
318
352
|
const block = event.content_block;
|
|
353
|
+
const blockIndex = event.index;
|
|
354
|
+
// Track block type for later reference
|
|
355
|
+
blockIndexToType.set(blockIndex, block.type);
|
|
319
356
|
if (block.type === 'tool_use') {
|
|
320
357
|
hasToolCalls = true;
|
|
321
|
-
const blockIndex = event.index;
|
|
322
358
|
blockIndexToId.set(blockIndex, block.id);
|
|
323
359
|
toolCallsBuffer.set(block.id, {
|
|
324
360
|
id: block.id,
|
|
@@ -333,6 +369,13 @@ export async function* createStreamingAnthropicCompletion(options, abortSignal,
|
|
|
333
369
|
delta: block.name,
|
|
334
370
|
};
|
|
335
371
|
}
|
|
372
|
+
// Handle thinking block start (Extended Thinking feature)
|
|
373
|
+
else if (block.type === 'thinking') {
|
|
374
|
+
// Thinking block started - emit reasoning_started event
|
|
375
|
+
yield {
|
|
376
|
+
type: 'reasoning_started',
|
|
377
|
+
};
|
|
378
|
+
}
|
|
336
379
|
}
|
|
337
380
|
else if (event.type === 'content_block_delta') {
|
|
338
381
|
const delta = event.delta;
|
|
@@ -344,6 +387,21 @@ export async function* createStreamingAnthropicCompletion(options, abortSignal,
|
|
|
344
387
|
content: text,
|
|
345
388
|
};
|
|
346
389
|
}
|
|
390
|
+
// Handle thinking_delta (Extended Thinking feature)
|
|
391
|
+
// Emit reasoning_delta event for thinking content
|
|
392
|
+
if (delta.type === 'thinking_delta') {
|
|
393
|
+
const thinkingText = delta.thinking;
|
|
394
|
+
thinkingTextBuffer += thinkingText; // Accumulate thinking text
|
|
395
|
+
yield {
|
|
396
|
+
type: 'reasoning_delta',
|
|
397
|
+
delta: thinkingText,
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
// Handle signature_delta (Extended Thinking feature)
|
|
401
|
+
// Signature is required for thinking blocks
|
|
402
|
+
if (delta.type === 'signature_delta') {
|
|
403
|
+
thinkingSignature += delta.signature; // Accumulate signature
|
|
404
|
+
}
|
|
347
405
|
if (delta.type === 'input_json_delta') {
|
|
348
406
|
const jsonDelta = delta.partial_json;
|
|
349
407
|
const blockIndex = event.index;
|
|
@@ -457,8 +515,17 @@ export async function* createStreamingAnthropicCompletion(options, abortSignal,
|
|
|
457
515
|
usage: usageData,
|
|
458
516
|
};
|
|
459
517
|
}
|
|
518
|
+
// Return complete thinking block with signature if thinking content exists
|
|
519
|
+
const thinkingBlock = thinkingTextBuffer
|
|
520
|
+
? {
|
|
521
|
+
type: 'thinking',
|
|
522
|
+
thinking: thinkingTextBuffer,
|
|
523
|
+
signature: thinkingSignature || undefined,
|
|
524
|
+
}
|
|
525
|
+
: undefined;
|
|
460
526
|
yield {
|
|
461
527
|
type: 'done',
|
|
528
|
+
thinking: thinkingBlock,
|
|
462
529
|
};
|
|
463
530
|
}, {
|
|
464
531
|
abortSignal,
|
package/dist/api/chat.js
CHANGED
|
@@ -185,7 +185,7 @@ export async function* createStreamingChatCompletion(options, abortSignal, onRet
|
|
|
185
185
|
method: 'POST',
|
|
186
186
|
headers: {
|
|
187
187
|
'Content-Type': 'application/json',
|
|
188
|
-
|
|
188
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
189
189
|
...config.customHeaders,
|
|
190
190
|
},
|
|
191
191
|
body: JSON.stringify(requestBody),
|
package/dist/api/responses.js
CHANGED
|
@@ -256,7 +256,7 @@ export async function* createStreamingResponse(options, abortSignal, onRetry) {
|
|
|
256
256
|
method: 'POST',
|
|
257
257
|
headers: {
|
|
258
258
|
'Content-Type': 'application/json',
|
|
259
|
-
|
|
259
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
260
260
|
...config.customHeaders,
|
|
261
261
|
},
|
|
262
262
|
body: JSON.stringify(requestPayload),
|
|
@@ -442,7 +442,7 @@ export async function* createStreamingResponse(options, abortSignal, onRetry) {
|
|
|
442
442
|
usage: usageData,
|
|
443
443
|
};
|
|
444
444
|
}
|
|
445
|
-
// 发送完成信号
|
|
445
|
+
// 发送完成信号 - For Responses API, thinking content is in reasoning object, not separate thinking field
|
|
446
446
|
yield {
|
|
447
447
|
type: 'done',
|
|
448
448
|
};
|
package/dist/api/systemPrompt.js
CHANGED
|
@@ -33,7 +33,7 @@ const SYSTEM_PROMPT_TEMPLATE = `You are Snow AI CLI, an intelligent command-line
|
|
|
33
33
|
1. **Language Adaptation**: ALWAYS respond in the SAME language as the user's query
|
|
34
34
|
2. **ACTION FIRST**: Write code immediately when task is clear - stop overthinking
|
|
35
35
|
3. **Smart Context**: Read what's needed for correctness, skip excessive exploration
|
|
36
|
-
4. **Quality Verification**:
|
|
36
|
+
4. **Quality Verification**: run build/test after changes
|
|
37
37
|
|
|
38
38
|
## 🚀 Execution Strategy - BALANCE ACTION & ANALYSIS
|
|
39
39
|
|
|
@@ -124,10 +124,9 @@ system administration and data processing challenges.
|
|
|
124
124
|
## 🔍 Quality Assurance
|
|
125
125
|
|
|
126
126
|
Guidance and recommendations:
|
|
127
|
-
1.
|
|
128
|
-
2.
|
|
129
|
-
3.
|
|
130
|
-
4. Never leave broken code
|
|
127
|
+
1. Run build: \`npm run build\` or \`tsc\`
|
|
128
|
+
2. Fix any errors immediately
|
|
129
|
+
3. Never leave broken code
|
|
131
130
|
|
|
132
131
|
## 📚 Project Context (SNOW.md)
|
|
133
132
|
|
package/dist/api/types.d.ts
CHANGED
|
@@ -114,6 +114,7 @@ export async function handleConversationWithTools(options) {
|
|
|
114
114
|
let streamedContent = '';
|
|
115
115
|
let receivedToolCalls;
|
|
116
116
|
let receivedReasoning;
|
|
117
|
+
let receivedThinking; // Accumulate thinking content from all platforms
|
|
117
118
|
// Stream AI response - choose API based on config
|
|
118
119
|
let toolCallAccumulator = ''; // Accumulate tool call deltas for token counting
|
|
119
120
|
let reasoningAccumulator = ''; // Accumulate reasoning summary deltas for token counting (Responses API only)
|
|
@@ -194,6 +195,8 @@ export async function handleConversationWithTools(options) {
|
|
|
194
195
|
}
|
|
195
196
|
else if (chunk.type === 'tool_call_delta' && chunk.delta) {
|
|
196
197
|
// Accumulate tool call deltas and update token count in real-time
|
|
198
|
+
// When tool calls start, reasoning is done (OpenAI generally doesn't output text content during tool calls)
|
|
199
|
+
setIsReasoning?.(false);
|
|
197
200
|
toolCallAccumulator += chunk.delta;
|
|
198
201
|
try {
|
|
199
202
|
const tokens = encoder.encode(streamedContent + toolCallAccumulator + reasoningAccumulator);
|
|
@@ -222,6 +225,10 @@ export async function handleConversationWithTools(options) {
|
|
|
222
225
|
// Capture reasoning data from Responses API
|
|
223
226
|
receivedReasoning = chunk.reasoning;
|
|
224
227
|
}
|
|
228
|
+
else if (chunk.type === 'done' && chunk.thinking) {
|
|
229
|
+
// Capture thinking content from Anthropic only (includes signature)
|
|
230
|
+
receivedThinking = chunk.thinking;
|
|
231
|
+
}
|
|
225
232
|
else if (chunk.type === 'usage' && chunk.usage) {
|
|
226
233
|
// Capture usage information both in state and locally
|
|
227
234
|
setContextUsage(chunk.usage);
|
|
@@ -256,7 +263,8 @@ export async function handleConversationWithTools(options) {
|
|
|
256
263
|
}
|
|
257
264
|
if (chunk.usage.cached_tokens !== undefined) {
|
|
258
265
|
accumulatedUsage.cached_tokens =
|
|
259
|
-
(accumulatedUsage.cached_tokens || 0) +
|
|
266
|
+
(accumulatedUsage.cached_tokens || 0) +
|
|
267
|
+
chunk.usage.cached_tokens;
|
|
260
268
|
}
|
|
261
269
|
}
|
|
262
270
|
}
|
|
@@ -283,7 +291,8 @@ export async function handleConversationWithTools(options) {
|
|
|
283
291
|
arguments: tc.function.arguments,
|
|
284
292
|
},
|
|
285
293
|
})),
|
|
286
|
-
reasoning: receivedReasoning, // Include reasoning data for caching
|
|
294
|
+
reasoning: receivedReasoning, // Include reasoning data for caching (Responses API)
|
|
295
|
+
thinking: receivedThinking, // Include thinking content (Anthropic/OpenAI)
|
|
287
296
|
};
|
|
288
297
|
conversationMessages.push(assistantMessage);
|
|
289
298
|
// Save assistant message with tool calls
|
|
@@ -819,7 +828,8 @@ export async function handleConversationWithTools(options) {
|
|
|
819
828
|
const assistantMessage = {
|
|
820
829
|
role: 'assistant',
|
|
821
830
|
content: streamedContent.trim(),
|
|
822
|
-
reasoning: receivedReasoning, // Include reasoning data for caching
|
|
831
|
+
reasoning: receivedReasoning, // Include reasoning data for caching (Responses API)
|
|
832
|
+
thinking: receivedThinking, // Include thinking content (Anthropic/OpenAI)
|
|
823
833
|
};
|
|
824
834
|
conversationMessages.push(assistantMessage);
|
|
825
835
|
saveMessage(assistantMessage).catch(error => {
|
|
@@ -2,13 +2,13 @@ import { TextBuffer } from '../utils/textBuffer.js';
|
|
|
2
2
|
import { FileListRef } from '../ui/components/FileList.js';
|
|
3
3
|
export declare function useFilePicker(buffer: TextBuffer, triggerUpdate: () => void): {
|
|
4
4
|
showFilePicker: boolean;
|
|
5
|
-
setShowFilePicker:
|
|
5
|
+
setShowFilePicker: (show: boolean) => void;
|
|
6
6
|
fileSelectedIndex: number;
|
|
7
|
-
setFileSelectedIndex:
|
|
7
|
+
setFileSelectedIndex: (index: number | ((prev: number) => number)) => void;
|
|
8
8
|
fileQuery: string;
|
|
9
|
-
setFileQuery:
|
|
9
|
+
setFileQuery: (_query: string) => void;
|
|
10
10
|
atSymbolPosition: number;
|
|
11
|
-
setAtSymbolPosition:
|
|
11
|
+
setAtSymbolPosition: (_pos: number) => void;
|
|
12
12
|
filteredFileCount: number;
|
|
13
13
|
updateFilePickerState: (text: string, cursorPos: number) => void;
|
|
14
14
|
handleFileSelect: (filePath: string) => Promise<void>;
|
|
@@ -1,19 +1,58 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useReducer, useCallback, useRef } from 'react';
|
|
2
|
+
function filePickerReducer(state, action) {
|
|
3
|
+
switch (action.type) {
|
|
4
|
+
case 'SHOW':
|
|
5
|
+
return {
|
|
6
|
+
...state,
|
|
7
|
+
showFilePicker: true,
|
|
8
|
+
fileSelectedIndex: 0,
|
|
9
|
+
fileQuery: action.query,
|
|
10
|
+
atSymbolPosition: action.position,
|
|
11
|
+
};
|
|
12
|
+
case 'HIDE':
|
|
13
|
+
return {
|
|
14
|
+
...state,
|
|
15
|
+
showFilePicker: false,
|
|
16
|
+
fileSelectedIndex: 0,
|
|
17
|
+
fileQuery: '',
|
|
18
|
+
atSymbolPosition: -1,
|
|
19
|
+
};
|
|
20
|
+
case 'SELECT_FILE':
|
|
21
|
+
return {
|
|
22
|
+
...state,
|
|
23
|
+
showFilePicker: false,
|
|
24
|
+
fileSelectedIndex: 0,
|
|
25
|
+
fileQuery: '',
|
|
26
|
+
atSymbolPosition: -1,
|
|
27
|
+
};
|
|
28
|
+
case 'SET_SELECTED_INDEX':
|
|
29
|
+
return {
|
|
30
|
+
...state,
|
|
31
|
+
fileSelectedIndex: action.index,
|
|
32
|
+
};
|
|
33
|
+
case 'SET_FILTERED_COUNT':
|
|
34
|
+
return {
|
|
35
|
+
...state,
|
|
36
|
+
filteredFileCount: action.count,
|
|
37
|
+
};
|
|
38
|
+
default:
|
|
39
|
+
return state;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
2
42
|
export function useFilePicker(buffer, triggerUpdate) {
|
|
3
|
-
const [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
43
|
+
const [state, dispatch] = useReducer(filePickerReducer, {
|
|
44
|
+
showFilePicker: false,
|
|
45
|
+
fileSelectedIndex: 0,
|
|
46
|
+
fileQuery: '',
|
|
47
|
+
atSymbolPosition: -1,
|
|
48
|
+
filteredFileCount: 0,
|
|
49
|
+
});
|
|
8
50
|
const fileListRef = useRef(null);
|
|
9
51
|
// Update file picker state
|
|
10
52
|
const updateFilePickerState = useCallback((text, cursorPos) => {
|
|
11
53
|
if (!text.includes('@')) {
|
|
12
|
-
if (showFilePicker) {
|
|
13
|
-
|
|
14
|
-
setFileSelectedIndex(0);
|
|
15
|
-
setFileQuery('');
|
|
16
|
-
setAtSymbolPosition(-1);
|
|
54
|
+
if (state.showFilePicker) {
|
|
55
|
+
dispatch({ type: 'HIDE' });
|
|
17
56
|
}
|
|
18
57
|
return;
|
|
19
58
|
}
|
|
@@ -24,65 +63,74 @@ export function useFilePicker(buffer, triggerUpdate) {
|
|
|
24
63
|
// Check if there's no space between '@' and cursor
|
|
25
64
|
const afterAt = beforeCursor.slice(lastAtIndex + 1);
|
|
26
65
|
if (!afterAt.includes(' ') && !afterAt.includes('\n')) {
|
|
27
|
-
if (!showFilePicker ||
|
|
28
|
-
fileQuery !== afterAt ||
|
|
29
|
-
atSymbolPosition !== lastAtIndex) {
|
|
30
|
-
|
|
31
|
-
setFileSelectedIndex(0);
|
|
32
|
-
setFileQuery(afterAt);
|
|
33
|
-
setAtSymbolPosition(lastAtIndex);
|
|
66
|
+
if (!state.showFilePicker ||
|
|
67
|
+
state.fileQuery !== afterAt ||
|
|
68
|
+
state.atSymbolPosition !== lastAtIndex) {
|
|
69
|
+
dispatch({ type: 'SHOW', query: afterAt, position: lastAtIndex });
|
|
34
70
|
}
|
|
35
71
|
return;
|
|
36
72
|
}
|
|
37
73
|
}
|
|
38
74
|
// Hide file picker if no valid @ context found
|
|
39
|
-
if (showFilePicker) {
|
|
40
|
-
|
|
41
|
-
setFileSelectedIndex(0);
|
|
42
|
-
setFileQuery('');
|
|
43
|
-
setAtSymbolPosition(-1);
|
|
75
|
+
if (state.showFilePicker) {
|
|
76
|
+
dispatch({ type: 'HIDE' });
|
|
44
77
|
}
|
|
45
|
-
}, [showFilePicker, fileQuery, atSymbolPosition]);
|
|
78
|
+
}, [state.showFilePicker, state.fileQuery, state.atSymbolPosition]);
|
|
46
79
|
// Handle file selection
|
|
47
80
|
const handleFileSelect = useCallback(async (filePath) => {
|
|
48
|
-
if (atSymbolPosition !== -1) {
|
|
81
|
+
if (state.atSymbolPosition !== -1) {
|
|
49
82
|
const text = buffer.getFullText();
|
|
50
83
|
const cursorPos = buffer.getCursorPosition();
|
|
51
84
|
// Replace @query with @filePath + space
|
|
52
|
-
const beforeAt = text.slice(0, atSymbolPosition);
|
|
85
|
+
const beforeAt = text.slice(0, state.atSymbolPosition);
|
|
53
86
|
const afterCursor = text.slice(cursorPos);
|
|
54
87
|
const newText = beforeAt + '@' + filePath + ' ' + afterCursor;
|
|
55
88
|
// Set the new text and position cursor after the inserted file path + space
|
|
56
89
|
buffer.setText(newText);
|
|
57
90
|
// Calculate cursor position after the inserted file path + space
|
|
58
91
|
// Reset cursor to beginning, then move to correct position
|
|
59
|
-
for (let i = 0; i < atSymbolPosition + filePath.length + 2; i++) {
|
|
92
|
+
for (let i = 0; i < state.atSymbolPosition + filePath.length + 2; i++) {
|
|
60
93
|
// +2 for @ and space
|
|
61
94
|
if (i < buffer.getFullText().length) {
|
|
62
95
|
buffer.moveRight();
|
|
63
96
|
}
|
|
64
97
|
}
|
|
65
|
-
|
|
66
|
-
setFileSelectedIndex(0);
|
|
67
|
-
setFileQuery('');
|
|
68
|
-
setAtSymbolPosition(-1);
|
|
98
|
+
dispatch({ type: 'SELECT_FILE' });
|
|
69
99
|
triggerUpdate();
|
|
70
100
|
}
|
|
71
|
-
}, [atSymbolPosition, buffer
|
|
101
|
+
}, [state.atSymbolPosition, buffer]);
|
|
72
102
|
// Handle filtered file count change
|
|
73
103
|
const handleFilteredCountChange = useCallback((count) => {
|
|
74
|
-
|
|
104
|
+
dispatch({ type: 'SET_FILTERED_COUNT', count });
|
|
105
|
+
}, []);
|
|
106
|
+
// Wrapper setters for backwards compatibility
|
|
107
|
+
const setShowFilePicker = useCallback((show) => {
|
|
108
|
+
dispatch({ type: show ? 'SHOW' : 'HIDE', query: '', position: -1 });
|
|
75
109
|
}, []);
|
|
110
|
+
const setFileSelectedIndex = useCallback((index) => {
|
|
111
|
+
if (typeof index === 'function') {
|
|
112
|
+
// For functional updates, we need to get current state first
|
|
113
|
+
// This is a simplified version - in production you might want to use a ref
|
|
114
|
+
dispatch({ type: 'SET_SELECTED_INDEX', index: index(state.fileSelectedIndex) });
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
dispatch({ type: 'SET_SELECTED_INDEX', index });
|
|
118
|
+
}
|
|
119
|
+
}, [state.fileSelectedIndex]);
|
|
76
120
|
return {
|
|
77
|
-
showFilePicker,
|
|
121
|
+
showFilePicker: state.showFilePicker,
|
|
78
122
|
setShowFilePicker,
|
|
79
|
-
fileSelectedIndex,
|
|
123
|
+
fileSelectedIndex: state.fileSelectedIndex,
|
|
80
124
|
setFileSelectedIndex,
|
|
81
|
-
fileQuery,
|
|
82
|
-
setFileQuery
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
125
|
+
fileQuery: state.fileQuery,
|
|
126
|
+
setFileQuery: (_query) => {
|
|
127
|
+
// Not used, but kept for compatibility
|
|
128
|
+
},
|
|
129
|
+
atSymbolPosition: state.atSymbolPosition,
|
|
130
|
+
setAtSymbolPosition: (_pos) => {
|
|
131
|
+
// Not used, but kept for compatibility
|
|
132
|
+
},
|
|
133
|
+
filteredFileCount: state.filteredFileCount,
|
|
86
134
|
updateFilePickerState,
|
|
87
135
|
handleFileSelect,
|
|
88
136
|
handleFilteredCountChange,
|
|
@@ -17,5 +17,10 @@ export declare function useHistoryNavigation(buffer: TextBuffer, triggerUpdate:
|
|
|
17
17
|
infoText: string;
|
|
18
18
|
}[];
|
|
19
19
|
handleHistorySelect: (value: string) => void;
|
|
20
|
+
currentHistoryIndex: number;
|
|
21
|
+
navigateHistoryUp: () => boolean;
|
|
22
|
+
navigateHistoryDown: () => boolean;
|
|
23
|
+
resetHistoryNavigation: () => void;
|
|
24
|
+
saveToHistory: (content: string) => Promise<void>;
|
|
20
25
|
};
|
|
21
26
|
export {};
|