@ridit/lens 0.3.7 → 0.3.9
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/index.mjs +105368 -274002
- package/package.json +13 -19
- package/src/colors.ts +15 -15
- package/src/commands/chat.tsx +32 -23
- package/src/commands/provider.tsx +11 -238
- package/src/commands/repo.tsx +66 -120
- package/src/commands/timeline.tsx +11 -22
- package/src/components/ChatView.tsx +238 -0
- package/src/components/Message.tsx +46 -0
- package/src/components/ToolCall.tsx +67 -0
- package/src/components/chat/ChatView.tsx +550 -0
- package/src/components/chat/Message.tsx +152 -0
- package/src/components/chat/StatusBar.tsx +214 -0
- package/src/components/chat/TextArea.tsx +173 -176
- package/src/components/provider/ApiKeyStep.tsx +207 -199
- package/src/components/provider/ModelStep.tsx +90 -88
- package/src/components/provider/ProviderSetup.tsx +331 -0
- package/src/components/provider/ProviderTypeStep.tsx +53 -61
- package/src/components/repo/StepRow.tsx +68 -69
- package/src/components/timeline/TimelineView.tsx +840 -0
- package/src/components/toolcall-utils.ts +103 -0
- package/src/components/watch/RunView.tsx +497 -0
- package/src/hooks/useChatInput.ts +49 -0
- package/src/hooks/useCommandHandler.ts +117 -0
- package/src/index.tsx +386 -139
- package/src/utils/git.ts +149 -155
- package/src/utils/repo.ts +62 -69
- package/src/utils/thinking.tsx +64 -0
- package/src/utils/watch.ts +165 -307
- package/tests/message.test.ts +38 -0
- package/tests/toolcall-utils.test.ts +111 -0
- package/tsconfig.json +8 -24
- package/CLAUDE.md +0 -50
- package/LENS.md +0 -48
- package/LICENSE +0 -21
- package/README.md +0 -93
- package/addons/README.md +0 -55
- package/addons/clean-cache.js +0 -48
- package/addons/generate-readme.js +0 -67
- package/addons/git-stats.js +0 -29
- package/addons/run-tests.js +0 -127
- package/src/commands/commit.tsx +0 -668
- package/src/commands/review.tsx +0 -294
- package/src/commands/run.tsx +0 -56
- package/src/commands/task.tsx +0 -36
- package/src/components/chat/ChatMessage.tsx +0 -195
- package/src/components/chat/ChatOverlays.tsx +0 -399
- package/src/components/chat/ChatRunner.tsx +0 -517
- package/src/components/chat/hooks/useChat.ts +0 -631
- package/src/components/chat/hooks/useChatInput.ts +0 -79
- package/src/components/chat/hooks/useCommandHandlers.ts +0 -327
- package/src/components/provider/ProviderPicker.tsx +0 -76
- package/src/components/provider/RemoveProviderStep.tsx +0 -82
- package/src/components/repo/DiffViewer.tsx +0 -175
- package/src/components/repo/FileReviewer.tsx +0 -70
- package/src/components/repo/FileViewer.tsx +0 -60
- package/src/components/repo/IssueFixer.tsx +0 -666
- package/src/components/repo/LensFileMenu.tsx +0 -115
- package/src/components/repo/NoProviderPrompt.tsx +0 -28
- package/src/components/repo/PreviewRunner.tsx +0 -217
- package/src/components/repo/RepoAnalysis.tsx +0 -534
- package/src/components/task/TaskRunner.tsx +0 -396
- package/src/components/timeline/CommitDetail.tsx +0 -272
- package/src/components/timeline/CommitList.tsx +0 -162
- package/src/components/timeline/TimelineChat.tsx +0 -166
- package/src/components/timeline/TimelineRunner.tsx +0 -1285
- package/src/components/watch/RunRunner.tsx +0 -929
- package/src/prompts/fewshot.ts +0 -252
- package/src/prompts/index.ts +0 -2
- package/src/prompts/system.ts +0 -285
- package/src/tools/chart.ts +0 -202
- package/src/tools/convert-image.ts +0 -312
- package/src/tools/files.ts +0 -253
- package/src/tools/git.ts +0 -603
- package/src/tools/index.ts +0 -17
- package/src/tools/pdf.ts +0 -164
- package/src/tools/shell.ts +0 -96
- package/src/tools/view-image.ts +0 -335
- package/src/tools/web.ts +0 -212
- package/src/types/chat.ts +0 -86
- package/src/types/config.ts +0 -20
- package/src/types/repo.ts +0 -54
- package/src/utils/addons/loadAddons.ts +0 -34
- package/src/utils/ai.ts +0 -321
- package/src/utils/chat.ts +0 -326
- package/src/utils/chatHistory.ts +0 -121
- package/src/utils/config.ts +0 -61
- package/src/utils/files.ts +0 -105
- package/src/utils/intentClassifier.ts +0 -58
- package/src/utils/lensfile.ts +0 -142
- package/src/utils/llm.ts +0 -81
- package/src/utils/memory.ts +0 -209
- package/src/utils/preview.ts +0 -119
- package/src/utils/stats.ts +0 -174
- package/src/utils/tools/builtins.ts +0 -377
- package/src/utils/tools/registry.ts +0 -105
|
@@ -1,199 +1,207 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
</Box>
|
|
169
|
-
</Box>
|
|
170
|
-
);
|
|
171
|
-
})}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Box, Text, useInput, type Key } from "ink";
|
|
3
|
+
import { execSync } from "child_process";
|
|
4
|
+
import type { Provider } from "@ridit/lens-core";
|
|
5
|
+
import { ACCENT } from "../../colors";
|
|
6
|
+
|
|
7
|
+
function readClipboard(): string | null {
|
|
8
|
+
try {
|
|
9
|
+
if (process.platform === "win32") {
|
|
10
|
+
return execSync("powershell -command Get-Clipboard", { encoding: "utf-8" }).trim();
|
|
11
|
+
} else if (process.platform === "darwin") {
|
|
12
|
+
return execSync("pbpaste", { encoding: "utf-8" }).trim();
|
|
13
|
+
} else {
|
|
14
|
+
try {
|
|
15
|
+
return execSync("xclip -selection clipboard -o", { encoding: "utf-8" }).trim();
|
|
16
|
+
} catch {
|
|
17
|
+
return execSync("xsel --clipboard --output", { encoding: "utf-8" }).trim();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const LABELS: Partial<Record<Provider, string>> = {
|
|
26
|
+
anthropic: "Anthropic API key",
|
|
27
|
+
openai: "OpenAI API key",
|
|
28
|
+
google: "Google API key",
|
|
29
|
+
groq: "Groq API key",
|
|
30
|
+
openrouter: "OpenRouter API key",
|
|
31
|
+
ollama: "Ollama base URL (leave blank for http://localhost:11434)",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function useFieldInput(initial: string, onPasteError: (v: boolean) => void) {
|
|
35
|
+
const [value, setValue] = useState(initial);
|
|
36
|
+
|
|
37
|
+
const handle = (input: string, key: Key) => {
|
|
38
|
+
if (key.backspace || key.delete) {
|
|
39
|
+
setValue((v) => v.slice(0, -1));
|
|
40
|
+
onPasteError(false);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (key.ctrl && input === "v") {
|
|
44
|
+
const clip = readClipboard();
|
|
45
|
+
if (clip) {
|
|
46
|
+
setValue((v) => v + clip);
|
|
47
|
+
onPasteError(false);
|
|
48
|
+
} else {
|
|
49
|
+
onPasteError(true);
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (key.ctrl && input === "a") {
|
|
54
|
+
setValue("");
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (!key.ctrl && !key.meta && input) {
|
|
58
|
+
setValue((v) => v + input);
|
|
59
|
+
onPasteError(false);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return { value, setValue, handle };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Single-field input (API key or base URL)
|
|
67
|
+
function SimpleInput({
|
|
68
|
+
providerType,
|
|
69
|
+
onSubmit,
|
|
70
|
+
}: {
|
|
71
|
+
providerType: Exclude<Provider, "custom">;
|
|
72
|
+
onSubmit: (value: string) => void;
|
|
73
|
+
}) {
|
|
74
|
+
const [pasteError, setPasteError] = useState(false);
|
|
75
|
+
const isOllama = providerType === "ollama";
|
|
76
|
+
const { value, handle } = useFieldInput(
|
|
77
|
+
isOllama ? "http://localhost:11434" : "",
|
|
78
|
+
setPasteError,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
useInput((input, key) => {
|
|
82
|
+
if (key.return) {
|
|
83
|
+
onSubmit(value.trim());
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
handle(input, key);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const display = isOllama ? value : "•".repeat(value.length);
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<Box flexDirection="column" gap={1}>
|
|
93
|
+
<Text bold color={ACCENT}>
|
|
94
|
+
{LABELS[providerType] ?? "API key"}
|
|
95
|
+
</Text>
|
|
96
|
+
<Box borderStyle="round" borderColor="gray" paddingX={1}>
|
|
97
|
+
<Text>{display || " "}</Text>
|
|
98
|
+
</Box>
|
|
99
|
+
{pasteError ? (
|
|
100
|
+
<Text color="red">⚠ Could not read clipboard</Text>
|
|
101
|
+
) : (
|
|
102
|
+
<Text color="gray" dimColor>
|
|
103
|
+
enter to confirm · ctrl+v to paste · ctrl+a to clear
|
|
104
|
+
</Text>
|
|
105
|
+
)}
|
|
106
|
+
</Box>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Two-field input for custom provider (API key + base URL)
|
|
111
|
+
function CustomInput({
|
|
112
|
+
onSubmit,
|
|
113
|
+
}: {
|
|
114
|
+
onSubmit: (apiKey: string, baseURL?: string) => void;
|
|
115
|
+
}) {
|
|
116
|
+
type Field = "apiKey" | "baseUrl";
|
|
117
|
+
const [activeField, setActiveField] = useState<Field>("apiKey");
|
|
118
|
+
const [pasteError, setPasteError] = useState(false);
|
|
119
|
+
|
|
120
|
+
const apiKeyField = useFieldInput("", setPasteError);
|
|
121
|
+
const baseUrlField = useFieldInput("", setPasteError);
|
|
122
|
+
const active = activeField === "apiKey" ? apiKeyField : baseUrlField;
|
|
123
|
+
|
|
124
|
+
useInput((input, key) => {
|
|
125
|
+
if (key.tab) {
|
|
126
|
+
setActiveField((f) => (f === "apiKey" ? "baseUrl" : "apiKey"));
|
|
127
|
+
setPasteError(false);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (key.return) {
|
|
131
|
+
if (activeField === "apiKey" && apiKeyField.value.trim()) {
|
|
132
|
+
setActiveField("baseUrl");
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (activeField === "baseUrl") {
|
|
136
|
+
onSubmit(
|
|
137
|
+
apiKeyField.value.trim(),
|
|
138
|
+
baseUrlField.value.trim() || undefined,
|
|
139
|
+
);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
active.handle(input, key);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const fields: { id: Field; label: string; password: boolean; placeholder: string }[] = [
|
|
147
|
+
{ id: "apiKey", label: "API key", password: true, placeholder: "sk-..." },
|
|
148
|
+
{ id: "baseUrl", label: "Base URL", password: false, placeholder: "https://api.example.com/v1" },
|
|
149
|
+
];
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<Box flexDirection="column" gap={1}>
|
|
153
|
+
<Text bold color={ACCENT}>
|
|
154
|
+
Custom provider
|
|
155
|
+
</Text>
|
|
156
|
+
{fields.map(({ id, label, password, placeholder }) => {
|
|
157
|
+
const isActive = activeField === id;
|
|
158
|
+
const val = id === "apiKey" ? apiKeyField.value : baseUrlField.value;
|
|
159
|
+
const display = password ? "•".repeat(val.length) : val;
|
|
160
|
+
return (
|
|
161
|
+
<Box key={id} flexDirection="column">
|
|
162
|
+
<Text color={isActive ? ACCENT : "gray"}>
|
|
163
|
+
{isActive ? "›" : " "} {label}
|
|
164
|
+
{id === "baseUrl" ? " (optional)" : ""}
|
|
165
|
+
</Text>
|
|
166
|
+
<Box borderStyle="round" borderColor={isActive ? ACCENT : "gray"} paddingX={1}>
|
|
167
|
+
<Text color={val ? "white" : "gray"}>{display || placeholder}</Text>
|
|
168
|
+
</Box>
|
|
169
|
+
</Box>
|
|
170
|
+
);
|
|
171
|
+
})}
|
|
172
|
+
{pasteError ? (
|
|
173
|
+
<Text color="red">⚠ Could not read clipboard</Text>
|
|
174
|
+
) : (
|
|
175
|
+
<Text color="gray" dimColor>
|
|
176
|
+
enter to next · tab to switch · ctrl+v to paste · ctrl+a to clear
|
|
177
|
+
</Text>
|
|
178
|
+
)}
|
|
179
|
+
</Box>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function ApiKeyStep({
|
|
184
|
+
providerType,
|
|
185
|
+
onSubmit,
|
|
186
|
+
}: {
|
|
187
|
+
providerType: Provider;
|
|
188
|
+
onSubmit: (apiKey: string, baseURL?: string) => void;
|
|
189
|
+
}) {
|
|
190
|
+
if (providerType === "custom") {
|
|
191
|
+
return <CustomInput onSubmit={onSubmit} />;
|
|
192
|
+
}
|
|
193
|
+
if (providerType === "ollama") {
|
|
194
|
+
return (
|
|
195
|
+
<SimpleInput
|
|
196
|
+
providerType="ollama"
|
|
197
|
+
onSubmit={(baseUrl) => onSubmit("ollama", baseUrl || "http://localhost:11434")}
|
|
198
|
+
/>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
return (
|
|
202
|
+
<SimpleInput
|
|
203
|
+
providerType={providerType}
|
|
204
|
+
onSubmit={(apiKey) => onSubmit(apiKey)}
|
|
205
|
+
/>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
@@ -1,88 +1,90 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import figures from "figures";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Box, Text, useInput } from "ink";
|
|
3
|
+
import figures from "figures";
|
|
4
|
+
import type { Provider } from "@ridit/lens-core";
|
|
5
|
+
import { ACCENT } from "../../colors";
|
|
6
|
+
|
|
7
|
+
const DEFAULT_MODELS: Partial<Record<Provider, string[]>> = {
|
|
8
|
+
anthropic: [
|
|
9
|
+
"claude-sonnet-4-5-20250514",
|
|
10
|
+
"claude-opus-4-5-20250514",
|
|
11
|
+
"claude-haiku-4-5-20251001",
|
|
12
|
+
],
|
|
13
|
+
openai: ["gpt-4o", "gpt-4o-mini", "gpt-4-turbo"],
|
|
14
|
+
google: ["gemini-2.0-flash", "gemini-1.5-pro", "gemini-1.5-flash"],
|
|
15
|
+
groq: ["llama-3.3-70b-versatile", "llama-3.1-8b-instant", "mixtral-8x7b-32768"],
|
|
16
|
+
openrouter: ["openai/gpt-4o", "openai/gpt-4o-mini", "anthropic/claude-3.5-sonnet"],
|
|
17
|
+
ollama: ["llama3.2", "llama3.1", "mistral", "codellama", "phi3"],
|
|
18
|
+
custom: [],
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function ModelStep({
|
|
22
|
+
providerType,
|
|
23
|
+
onSelect,
|
|
24
|
+
}: {
|
|
25
|
+
providerType: Provider;
|
|
26
|
+
onSelect: (model: string) => void;
|
|
27
|
+
}) {
|
|
28
|
+
const models = DEFAULT_MODELS[providerType] ?? [];
|
|
29
|
+
const [index, setIndex] = useState(0);
|
|
30
|
+
const [custom, setCustom] = useState("");
|
|
31
|
+
const [typing, setTyping] = useState(models.length === 0);
|
|
32
|
+
|
|
33
|
+
useInput((input, key) => {
|
|
34
|
+
if (typing) {
|
|
35
|
+
if (key.return && custom.trim()) {
|
|
36
|
+
onSelect(custom.trim());
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (key.backspace || key.delete) {
|
|
40
|
+
setCustom((v) => v.slice(0, -1));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!key.ctrl && !key.meta && input) setCustom((v) => v + input);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (key.upArrow) setIndex((i) => Math.max(0, i - 1));
|
|
47
|
+
if (key.downArrow) setIndex((i) => Math.min(models.length, i + 1));
|
|
48
|
+
if (key.return) {
|
|
49
|
+
if (index === models.length) setTyping(true);
|
|
50
|
+
else onSelect(models[index]!);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<Box flexDirection="column" gap={1}>
|
|
56
|
+
<Text bold color={ACCENT}>
|
|
57
|
+
Select a model
|
|
58
|
+
</Text>
|
|
59
|
+
{models.map((m, i) => {
|
|
60
|
+
const selected = !typing && i === index;
|
|
61
|
+
return (
|
|
62
|
+
<Box key={m} marginLeft={1}>
|
|
63
|
+
<Text color={selected ? ACCENT : "white"}>
|
|
64
|
+
{selected ? figures.arrowRight : " "}
|
|
65
|
+
{" "}
|
|
66
|
+
{m}
|
|
67
|
+
</Text>
|
|
68
|
+
</Box>
|
|
69
|
+
);
|
|
70
|
+
})}
|
|
71
|
+
<Box marginLeft={1}>
|
|
72
|
+
<Text color={index === models.length && !typing ? ACCENT : "gray"}>
|
|
73
|
+
{index === models.length && !typing ? figures.arrowRight : " "}
|
|
74
|
+
{" "}
|
|
75
|
+
{typing ? (
|
|
76
|
+
<Text>
|
|
77
|
+
Model name:{" "}
|
|
78
|
+
<Text color="white">{custom || " "}</Text>
|
|
79
|
+
</Text>
|
|
80
|
+
) : (
|
|
81
|
+
"Enter custom model name"
|
|
82
|
+
)}
|
|
83
|
+
</Text>
|
|
84
|
+
</Box>
|
|
85
|
+
<Text color="gray" dimColor>
|
|
86
|
+
↑↓ navigate · enter to select
|
|
87
|
+
</Text>
|
|
88
|
+
</Box>
|
|
89
|
+
);
|
|
90
|
+
}
|