@sortlist/cli 0.29.0 → 0.31.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.
@@ -18,71 +18,6 @@ export const Me = gql(`
18
18
  slug
19
19
  }
20
20
  }
21
- memberships {
22
- nodes {
23
- conversation {
24
- id
25
- }
26
- company {
27
- id
28
- }
29
- }
30
- }
31
- }
32
- }
33
- `);
34
-
35
- // ── Chat ──
36
-
37
- export const Conversation = gql(`
38
- query Conversation($id: ID!) {
39
- node(id: $id) {
40
- ... on Conversation {
41
- id
42
- title
43
- status
44
- modelId
45
- createdAt
46
- updatedAt
47
- messages(last: 50) {
48
- nodes {
49
- id
50
- role
51
- content
52
- modelId
53
- inputTokens
54
- outputTokens
55
- createdAt
56
- }
57
- }
58
- }
59
- }
60
- }
61
- `);
62
-
63
- export const SendMessage = gql(`
64
- mutation SendMessage($input: SendMessageInput!) {
65
- sendMessage(input: $input) {
66
- id
67
- role
68
- content
69
- createdAt
70
- }
71
- }
72
- `);
73
-
74
- export const RespondToToolCall = gql(`
75
- mutation RespondToToolCall($input: RespondToToolCallInput!) {
76
- respondToToolCall(input: $input) {
77
- ok
78
- }
79
- }
80
- `);
81
-
82
- export const CancelConversation = gql(`
83
- mutation CancelConversation($input: CancelConversationInput!) {
84
- cancelConversation(input: $input) {
85
- ok
86
21
  }
87
22
  }
88
23
  `);
@@ -96,20 +31,3 @@ export const CreateSalesOffer = gql(`
96
31
  }
97
32
  }
98
33
  `);
99
-
100
- export const ConversationEvent = gql(`
101
- subscription ConversationEvent($conversationId: ID!) {
102
- conversationEvent(conversationId: $conversationId) {
103
- __typename
104
- agentLoopId
105
- agentLoopSequence
106
- ... on MessageChunkEvent { content }
107
- ... on ToolCallEvent { toolName toolCallId arguments }
108
- ... on ToolResultEvent { toolCallId content }
109
- ... on AgentPickedEvent { agent reason turn }
110
- ... on SupervisorVerdictEvent { verdict reason turn }
111
- ... on AgentLoopCompletedEvent { messageId }
112
- ... on AgentLoopFailedEvent { message }
113
- }
114
- }
115
- `);
package/src/index.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import fs from 'node:fs';
2
2
  import { Command } from 'commander';
3
3
 
4
- // import { chatCommand } from './commands/chat/chat.ts';
5
4
  import { configCommand } from './commands/config.ts';
6
- import { buildServiceCommands } from './commands/dynamic.ts';
5
+ import { buildServiceCommands, formatTypeInspection } from './commands/dynamic.ts';
7
6
  import { loginCommand } from './commands/login.ts';
8
7
  import { logoutCommand } from './commands/logout.ts';
9
8
  import { offerCommand } from './commands/offer.ts';
@@ -120,6 +119,28 @@ schemaCommand
120
119
  }
121
120
  });
122
121
 
122
+ schemaCommand
123
+ .command('inspect <type>')
124
+ .description('Show the fields/values of a schema type (e.g. an input filter or enum)')
125
+ .action(async function (this: Command, typeName: string) {
126
+ const opts = this.optsWithGlobals();
127
+ try {
128
+ const { schema } = await getIntrospectedSchema(opts.endpoint);
129
+ const formatted = formatTypeInspection(schema, typeName);
130
+ if (!formatted) {
131
+ error(`No type named "${typeName}" in the schema.`);
132
+ hint('Type names are case-sensitive, e.g. `sl schema inspect OrganizationFilterInput`.');
133
+ hint('Find argument types in any command’s --help output.');
134
+ process.exit(1);
135
+ }
136
+ info(formatted);
137
+ } catch (err) {
138
+ error(`Could not read the schema: ${(err as Error).message}`);
139
+ hint('Check your network connection and endpoint: sl config show');
140
+ process.exit(1);
141
+ }
142
+ });
143
+
123
144
  program.addCommand(schemaCommand);
124
145
 
125
146
  // Parse --endpoint early so introspection uses the right URL
@@ -135,16 +156,6 @@ try {
135
156
 
136
157
  for (const [name, entry] of serviceCommands) {
137
158
  const cmd = entry.command;
138
- /**
139
- * Disabling the chat for now until we know what to do with this feature
140
- */
141
- // Chat: replace the generated basic `conversation` command with the interactive one
142
- // if (name === 'chat') {
143
- // const chatCmds = cmd.commands as unknown as Command[];
144
- // const convIdx = chatCmds.findIndex((c) => c.name() === 'conversation');
145
- // if (convIdx !== -1) chatCmds.splice(convIdx, 1);
146
- // cmd.addCommand(chatCommand);
147
- // }
148
159
  program.addCommand(cmd);
149
160
  servicesForHelp.set(name, {
150
161
  exampleQuery: entry.exampleQuery,
@@ -1,302 +0,0 @@
1
- import { createInterface } from 'node:readline';
2
- import { Command } from 'commander';
3
-
4
- import { graphql } from '../../graphql/client.ts';
5
- import { Conversation, Me, SendMessage } from '../../graphql/operations/common.ts';
6
- import { ensureAuthenticated, isExpired } from '../../lib/auth.ts';
7
- import { resolveCompanyId } from '../../lib/company.ts';
8
- import { getEndpoint, getUserContext } from '../../lib/config.ts';
9
- import { error, hint, info } from '../../lib/output.ts';
10
- import { captureException } from '../../lib/sentry.ts';
11
- import { SequenceBuffer } from '../../lib/sequence-buffer.ts';
12
- import { connectChatStream } from './interactive/connection.ts';
13
- import type { ChatConnection, ChatEvent } from './interactive/types.ts';
14
-
15
- // ── Colors (conditional on --no-color / NO_COLOR) ──
16
-
17
- function colors(enabled: boolean) {
18
- if (!enabled) return { reset: '', dim: '', cyan: '', green: '', yellow: '', red: '' };
19
- return {
20
- reset: '\x1b[0m',
21
- dim: '\x1b[2m',
22
- cyan: '\x1b[36m',
23
- green: '\x1b[32m',
24
- yellow: '\x1b[33m',
25
- red: '\x1b[31m',
26
- };
27
- }
28
-
29
- // ── Interactive chat command ──
30
-
31
- export const chatCommand = new Command('conversation')
32
- .summary('Start an interactive conversation with Sortlist AI')
33
- .description(
34
- 'Start an interactive conversation with Sortlist AI\n\n' +
35
- 'Opens a live chat session over GraphQL-SSE through the federation router.\n' +
36
- 'Type your messages and receive streaming responses. Use /quit or /exit to leave.\n\n' +
37
- 'Examples:\n' +
38
- ' sl chat conversation Start a new conversation (basic mode)\n' +
39
- ' sl chat conversation -i Start with rich markdown rendering\n' +
40
- ' sl chat conversation --conversation-id <id> Resume a previous conversation',
41
- )
42
- .option('--company-id <id>', 'Use a specific company by UUID (overrides your context)')
43
- .option('--company-slug <slug>', 'Use a specific company by slug (resolved server-side)')
44
- .option('--conversation-id <id>', 'Resume an existing conversation by its ID')
45
- .option('--title <title>', 'Set a title for the new conversation')
46
- .option('--debug', 'Log raw SSE frames to stderr')
47
- .option('-i, --interactive', 'Rich UI with markdown rendering (recommended)')
48
- .action(async function (this: Command) {
49
- const opts = this.optsWithGlobals();
50
- const ctx = getUserContext();
51
- const endpoint = getEndpoint(opts.endpoint);
52
- const debug = opts.debug === true;
53
-
54
- if (opts.companyId && opts.companySlug) {
55
- error('Pass either `--company-id` or `--company-slug`, not both.');
56
- process.exit(2);
57
- }
58
-
59
- const companyId = await resolveCompanyId({
60
- companyId: opts.companyId as string | undefined,
61
- companySlug: opts.companySlug as string | undefined,
62
- ctx,
63
- endpoint,
64
- });
65
- if (!companyId) {
66
- error('No company selected.');
67
- hint('Pick one with `sl switch`, or pass `--company-id <id>` / `--company-slug <slug>`.');
68
- process.exit(2);
69
- }
70
-
71
- // Launch interactive Ink UI if requested
72
- if (opts.interactive) {
73
- const { launchInteractive } = await import('./interactive/index.tsx');
74
- launchInteractive({
75
- companyId,
76
- conversationId: opts.conversationId,
77
- conversationTitle: opts.title,
78
- endpoint,
79
- });
80
- return;
81
- }
82
-
83
- const c = colors(opts.color !== false && !process.env.NO_COLOR);
84
-
85
- const creds = ensureAuthenticated();
86
- if (isExpired(creds)) {
87
- error('Your session has expired.');
88
- hint('Run `sl login` to re-authenticate.');
89
- process.exit(2);
90
- }
91
-
92
- let conversationId = opts.conversationId as string | undefined;
93
-
94
- // Create or resume conversation — resolve conversation id from the company's membership
95
- if (!conversationId) {
96
- const userData = await graphql(Me, undefined, { endpoint });
97
- const membership = (userData.me?.memberships?.nodes ?? []).find((m) => m?.company?.id === companyId);
98
- conversationId = membership?.conversation?.id ?? undefined;
99
- if (!conversationId) {
100
- error('Could not resolve a conversation for this company.');
101
- hint('Make sure you are a member of the selected company.');
102
- process.exit(1);
103
- }
104
- info(`${c.dim}Default conversation: ${conversationId}${c.reset}`);
105
- } else {
106
- const data = await graphql(Conversation, { id: conversationId }, { endpoint });
107
- const conversation = data.node?.__typename === 'Conversation' ? data.node : null;
108
-
109
- if (!conversation) {
110
- error(`Conversation not found: ${conversationId}`);
111
- hint('The conversation may have been deleted, or the ID is incorrect.');
112
- hint('Start a new conversation with: sl chat conversation');
113
- process.exit(1);
114
- }
115
-
116
- info(`${c.dim}Resuming: ${conversation.title ?? conversationId}${c.reset}\n`);
117
- for (const msg of (conversation.messages?.nodes ?? []).filter((m): m is NonNullable<typeof m> => m != null)) {
118
- if (msg.role === 'user' && msg.content) {
119
- info(`${c.green}You:${c.reset} ${msg.content}`);
120
- } else if (msg.role === 'assistant' && msg.content) {
121
- info(`${c.cyan}Chat:${c.reset} ${msg.content}`);
122
- }
123
- }
124
- info('');
125
- }
126
-
127
- // Subscribe to the conversation event stream via the federation router.
128
- // The router negotiates with the chat subgraph using the HTTP callback
129
- // protocol; this client only sees a plain GraphQL-SSE response.
130
- let connection: ChatConnection;
131
- try {
132
- connection = await connectChatStream(endpoint, creds.accessToken, conversationId!, (line) => {
133
- if (debug) process.stderr.write(`${c.dim}${line}${c.reset}\n`);
134
- });
135
- } catch (err) {
136
- captureException(err, { context: 'chat_stream_connect', conversationId });
137
- error(`Failed to connect to the chat stream.`);
138
- hint(`Reason: ${err instanceof Error ? err.message : err}`);
139
- hint('Check your network connection and try again.');
140
- hint('If the problem persists, verify your endpoint: sl config show');
141
- process.exit(3);
142
- }
143
-
144
- let streaming = false;
145
-
146
- const sequenceBuffer = new SequenceBuffer<ChatEvent>({
147
- onEvent: processEvent,
148
- onGap(from, to) {
149
- const count = to - from + 1;
150
- const range = to > from ? `→${to}` : '';
151
- process.stderr.write(`${c.yellow} ⚠ ${count} event(s) lost (#${from}${range})${c.reset}\n`);
152
- },
153
- });
154
-
155
- function processEvent(event: ChatEvent) {
156
- switch (event.__typename) {
157
- case 'AgentLoopStartedEvent':
158
- case 'MessageStartedEvent':
159
- case 'MessageEndedEvent':
160
- if (streaming) process.stdout.write('\n');
161
- streaming = false;
162
- break;
163
- case 'AgentPickedEvent': {
164
- if (streaming) process.stdout.write('\n');
165
- streaming = false;
166
- const label = `turn ${event.turn ?? '?'}: ${event.agent}`;
167
- const detail = event.reason ? ` — ${event.reason}` : '';
168
- info(`${c.yellow}▸ ${label}${c.reset}${c.dim}${detail}${c.reset}`);
169
- break;
170
- }
171
- case 'SupervisorVerdictEvent': {
172
- if (streaming) process.stdout.write('\n');
173
- streaming = false;
174
- const color = event.verdict === 'complete' ? c.green : c.yellow;
175
- const glyph = event.verdict === 'complete' ? '✓' : '↻';
176
- const label = `turn ${event.turn ?? '?'}: supervisor → ${event.verdict}`;
177
- const detail = event.reason ? ` — ${event.reason}` : '';
178
- info(`${color}${glyph} ${label}${c.reset}${c.dim}${detail}${c.reset}`);
179
- break;
180
- }
181
- case 'MessageChunkEvent':
182
- if (!streaming) {
183
- process.stdout.write(`${c.cyan}Chat:${c.reset} `);
184
- streaming = true;
185
- }
186
- process.stdout.write(event.content ?? '');
187
- break;
188
- case 'ToolCallEvent':
189
- if (streaming) process.stdout.write('\n');
190
- info(`${c.dim} ⚙ ${event.toolName}(${JSON.stringify(event.arguments)})${c.reset}`);
191
- streaming = false;
192
- break;
193
- case 'ToolResultEvent':
194
- info(`${c.dim} ← ${event.content}${c.reset}`);
195
- break;
196
- case 'AgentLoopCompletedEvent':
197
- if (streaming) {
198
- process.stdout.write('\n\n');
199
- streaming = false;
200
- }
201
- sequenceBuffer.reset();
202
- rl.prompt();
203
- break;
204
- case 'AgentLoopCancelledEvent':
205
- if (streaming) process.stdout.write('\n');
206
- info(`${c.yellow}✖ Cancelled.${c.reset}`);
207
- streaming = false;
208
- sequenceBuffer.reset();
209
- rl.prompt();
210
- break;
211
- case 'AgentLoopPausedEvent':
212
- if (streaming) process.stdout.write('\n');
213
- streaming = false;
214
- info(
215
- `${c.yellow}⏸ Waiting for input. Interactive prompts (${c.reset}${c.dim}--interactive${c.reset}${c.yellow}) are required to respond to tool calls.${c.reset}`,
216
- );
217
- sequenceBuffer.reset();
218
- rl.prompt();
219
- break;
220
- case 'AgentLoopResumedEvent':
221
- // No user-visible noise — the UI effect comes from the next message/tool events.
222
- break;
223
- case 'AgentLoopFailedEvent':
224
- captureException(new Error(`Chat stream error: ${event.message}`), {
225
- conversationId,
226
- event,
227
- });
228
- if (streaming) process.stdout.write('\n');
229
- process.stderr.write(`${c.red}Error: ${event.message}${c.reset}\n`);
230
- streaming = false;
231
- sequenceBuffer.reset();
232
- rl.prompt();
233
- break;
234
- default: {
235
- if (streaming) process.stdout.write('\n');
236
- streaming = false;
237
- const unknown = event as { __typename?: string };
238
- process.stderr.write(
239
- `${c.dim}? unknown event "${unknown.__typename}" — run \`sl update\` to pick up schema changes${c.reset}\n`,
240
- );
241
- }
242
- }
243
- }
244
-
245
- let lastAgentLoopId: string | null = null;
246
- connection.onMessage((event) => {
247
- if (event.agentLoopId && event.agentLoopId !== lastAgentLoopId) {
248
- sequenceBuffer.reset();
249
- lastAgentLoopId = event.agentLoopId;
250
- }
251
- sequenceBuffer.push(event);
252
- });
253
-
254
- connection.onClose(() => {
255
- if (streaming) process.stdout.write('\n');
256
- info(`${c.dim}Connection closed.${c.reset}`);
257
- process.exit(0);
258
- });
259
-
260
- const rl = createInterface({
261
- input: process.stdin,
262
- output: process.stdout,
263
- prompt: `${c.green}You: ${c.reset}`,
264
- });
265
-
266
- rl.prompt();
267
-
268
- rl.on('line', async (line) => {
269
- const content = line.trim();
270
- if (!content) {
271
- rl.prompt();
272
- return;
273
- }
274
-
275
- if (content === '/quit' || content === '/exit') {
276
- rl.close();
277
- return;
278
- }
279
-
280
- try {
281
- await graphql(
282
- SendMessage,
283
- {
284
- input: {
285
- conversationId: conversationId!,
286
- content,
287
- },
288
- },
289
- { endpoint },
290
- );
291
- } catch {
292
- process.stderr.write(`${c.red}Failed to send message.${c.reset}\n`);
293
- rl.prompt();
294
- }
295
- });
296
-
297
- rl.on('close', () => {
298
- connection.close();
299
- info(`${c.dim}Goodbye!${c.reset}`);
300
- process.exit(0);
301
- });
302
- });
@@ -1,119 +0,0 @@
1
- import { Spinner } from '@inkjs/ui';
2
- import { Box, Text, useApp, useInput } from 'ink';
3
- import React, { useCallback } from 'react';
4
-
5
- import { ChatInput } from './components/ChatInput.tsx';
6
- import { ChoicePrompt } from './components/ChoicePrompt.tsx';
7
- import { MessageView } from './components/MessageView.tsx';
8
- import { ThinkingBox } from './components/ThinkingBox.tsx';
9
- import { useChat } from './hooks/useChat.ts';
10
- import { useTerminalSize } from './hooks/useTerminalSize.ts';
11
-
12
- interface AppProps {
13
- companyId: string;
14
- conversationId?: string;
15
- conversationTitle?: string;
16
- endpoint: string;
17
- }
18
-
19
- export function App({ companyId, conversationId: initialConversationId, conversationTitle, endpoint }: AppProps) {
20
- const { exit } = useApp();
21
- const { rows: termHeight } = useTerminalSize();
22
-
23
- const chat = useChat({ companyId, conversationId: initialConversationId, conversationTitle, endpoint });
24
-
25
- const isBusy = chat.streamContent !== null || chat.thinkingLog.length > 0;
26
-
27
- useInput((_input, key) => {
28
- if (key.ctrl && _input === 'c') {
29
- chat.disconnect();
30
- exit();
31
- return;
32
- }
33
- // Esc (when no choice prompt is up) stops the chat mid-turn without quitting.
34
- if (key.escape && !chat.pendingChoice && isBusy) {
35
- chat.cancelStream();
36
- }
37
- });
38
-
39
- const handleSubmit = useCallback(
40
- (value: string) => {
41
- const content = value.trim();
42
- if (!content) return;
43
-
44
- if (content === '/quit' || content === '/exit') {
45
- chat.disconnect();
46
- exit();
47
- return;
48
- }
49
-
50
- chat.sendMessage(content);
51
- },
52
- [chat, exit],
53
- );
54
-
55
- // ── Early returns ──
56
-
57
- if (chat.status === 'error' && !chat.connection) {
58
- return (
59
- <Box flexDirection="column" padding={1} minHeight={termHeight}>
60
- <Text color="red">Error: {chat.errorMsg}</Text>
61
- </Box>
62
- );
63
- }
64
-
65
- if (chat.status === 'connecting') {
66
- return (
67
- <Box padding={1} minHeight={termHeight}>
68
- <Text color="cyan">Connecting...</Text>
69
- </Box>
70
- );
71
- }
72
-
73
- // ── Layout ──
74
-
75
- const streamingHeight = Math.max(6, Math.floor(termHeight / 4));
76
-
77
- return (
78
- <Box flexDirection="column" minHeight={termHeight}>
79
- {/* Header */}
80
- <Box marginBottom={1}>
81
- <Text dimColor>Sortlist Chat</Text>
82
- {chat.conversationId && <Text dimColor> · {chat.conversationId}</Text>}
83
- <Text dimColor> · /quit to exit{isBusy ? ' · esc to stop' : ''}</Text>
84
- </Box>
85
-
86
- {/* Greeting loader */}
87
- {chat.waitingForGreeting && chat.messages.length === 0 && chat.streamContent === null && (
88
- <Box marginBottom={1}>
89
- <Spinner label="Starting up..." />
90
- </Box>
91
- )}
92
-
93
- {/* Messages — all rendered, terminal scrollback handles overflow */}
94
- {chat.messages.map((msg, i) => (
95
- // eslint-disable-next-line react/no-array-index-key -- append-only list, no reorder
96
- <MessageView key={i} msg={msg} />
97
- ))}
98
-
99
- {/* Thinking/streaming box — hidden while the user is being prompted for a choice */}
100
- {!chat.pendingChoice && (chat.streamContent !== null || chat.thinkingLog.length > 0) && (
101
- <ThinkingBox thinkingLog={chat.thinkingLog} streamContent={chat.streamContent} height={streamingHeight} />
102
- )}
103
-
104
- {/* Error banner */}
105
- {chat.errorMsg && chat.status !== 'error' && (
106
- <Box>
107
- <Text color="red">{chat.errorMsg}</Text>
108
- </Box>
109
- )}
110
-
111
- {/* Input — choice prompt takes precedence when active */}
112
- {chat.pendingChoice ? (
113
- <ChoicePrompt choice={chat.pendingChoice} onSelect={chat.respondToChoice} onCancel={chat.cancelChoice} />
114
- ) : (
115
- <ChatInput inputKey={chat.inputKey} isDisabled={chat.inputDisabled} onSubmit={handleSubmit} />
116
- )}
117
- </Box>
118
- );
119
- }
@@ -1,115 +0,0 @@
1
- import chalk from 'chalk';
2
- import { Box, Text, useInput } from 'ink';
3
- import React, { useState } from 'react';
4
-
5
- interface ChatInputProps {
6
- inputKey: number;
7
- isDisabled: boolean;
8
- onSubmit: (value: string) => void;
9
- }
10
-
11
- const CURSOR = chalk.inverse(' ');
12
- const PLACEHOLDER = 'Type a message...';
13
-
14
- // Delete the word to the left of the cursor. Strips a run of whitespace, then a run of
15
- // non-whitespace — mirrors readline / most shells.
16
- function deleteWordLeft(value: string, cursor: number): { value: string; cursor: number } {
17
- if (cursor === 0) return { value, cursor };
18
- let index = cursor;
19
- while (index > 0 && /\s/.test(value[index - 1]!)) index--;
20
- while (index > 0 && !/\s/.test(value[index - 1]!)) index--;
21
- return { value: value.slice(0, index) + value.slice(cursor), cursor: index };
22
- }
23
-
24
- export function ChatInput({ inputKey, isDisabled, onSubmit }: ChatInputProps) {
25
- const [value, setValue] = useState('');
26
- const [cursor, setCursor] = useState(0);
27
-
28
- // Reset internal state when inputKey changes (parent signals "new turn").
29
- React.useEffect(() => {
30
- setValue('');
31
- setCursor(0);
32
- }, [inputKey]);
33
-
34
- useInput(
35
- (input, key) => {
36
- if (key.upArrow || key.downArrow || key.tab) return;
37
- if (key.ctrl && input === 'c') return;
38
-
39
- if (key.return) {
40
- onSubmit(value);
41
- return;
42
- }
43
-
44
- if (key.leftArrow) {
45
- setCursor((c) => Math.max(0, c - 1));
46
- return;
47
- }
48
- if (key.rightArrow) {
49
- setCursor((c) => Math.min(value.length, c + 1));
50
- return;
51
- }
52
-
53
- // Ctrl+W / Alt(Option)+Backspace / Ctrl+Backspace → delete word left
54
- const isWordDelete =
55
- (key.ctrl && input === 'w') ||
56
- (key.meta && (key.backspace || key.delete)) ||
57
- (key.ctrl && (key.backspace || key.delete));
58
- if (isWordDelete) {
59
- const next = deleteWordLeft(value, cursor);
60
- setValue(next.value);
61
- setCursor(next.cursor);
62
- return;
63
- }
64
-
65
- if (key.backspace || key.delete) {
66
- if (cursor === 0) return;
67
- setValue((v) => v.slice(0, cursor - 1) + v.slice(cursor));
68
- setCursor((c) => Math.max(0, c - 1));
69
- return;
70
- }
71
-
72
- // Ctrl+U → delete to line start
73
- if (key.ctrl && input === 'u') {
74
- setValue((v) => v.slice(cursor));
75
- setCursor(0);
76
- return;
77
- }
78
-
79
- // Swallow any other ctrl/meta combos we don't recognize instead of inserting
80
- // the raw letter (this was the source of the "ctrl+w inserted 'w'" bug).
81
- if (key.ctrl || key.meta) return;
82
-
83
- // Printable text: insert at cursor.
84
- if (input && input.length > 0) {
85
- setValue((v) => v.slice(0, cursor) + input + v.slice(cursor));
86
- setCursor((c) => c + input.length);
87
- }
88
- },
89
- { isActive: !isDisabled },
90
- );
91
-
92
- const rendered = React.useMemo(() => {
93
- if (isDisabled) {
94
- return value.length > 0 ? value : chalk.dim(PLACEHOLDER);
95
- }
96
- if (value.length === 0) {
97
- return chalk.inverse(PLACEHOLDER[0]!) + chalk.dim(PLACEHOLDER.slice(1));
98
- }
99
- let result = '';
100
- for (let index = 0; index < value.length; index++) {
101
- result += index === cursor ? chalk.inverse(value[index]!) : value[index]!;
102
- }
103
- if (cursor === value.length) result += CURSOR;
104
- return result;
105
- }, [value, cursor, isDisabled]);
106
-
107
- return (
108
- <Box borderStyle="round" borderColor="green" paddingX={1} flexShrink={0}>
109
- <Text color="green" bold>
110
- {'❯ '}
111
- </Text>
112
- <Text>{rendered}</Text>
113
- </Box>
114
- );
115
- }