@robota-sdk/agent-transport 3.0.0-beta.64
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 +21 -0
- package/dist/node/headless/index.cjs +1 -0
- package/dist/node/headless/index.d.ts +2 -0
- package/dist/node/headless/index.js +1 -0
- package/dist/node/headless-CWEpJXFK.js +7 -0
- package/dist/node/headless-CWEpJXFK.js.map +1 -0
- package/dist/node/headless-CsZFelG9.cjs +6 -0
- package/dist/node/http/index.cjs +1 -0
- package/dist/node/http/index.d.ts +2 -0
- package/dist/node/http/index.js +1 -0
- package/dist/node/http-CM3TJhrF.cjs +1 -0
- package/dist/node/http-DwO1AHG-.js +2 -0
- package/dist/node/http-DwO1AHG-.js.map +1 -0
- package/dist/node/index--Ti9NzQX.d.ts +64 -0
- package/dist/node/index--Ti9NzQX.d.ts.map +1 -0
- package/dist/node/index-B_rcr14p.d.ts +47 -0
- package/dist/node/index-B_rcr14p.d.ts.map +1 -0
- package/dist/node/index-C9LWCL4l.d.ts +34 -0
- package/dist/node/index-C9LWCL4l.d.ts.map +1 -0
- package/dist/node/index-CAr3ioVh.d.ts +64 -0
- package/dist/node/index-CAr3ioVh.d.ts.map +1 -0
- package/dist/node/index-CEs25wVk.d.ts +213 -0
- package/dist/node/index-CEs25wVk.d.ts.map +1 -0
- package/dist/node/index-CvXLpjJO.d.ts +213 -0
- package/dist/node/index-CvXLpjJO.d.ts.map +1 -0
- package/dist/node/index-D34WUfFH.d.ts +26 -0
- package/dist/node/index-D34WUfFH.d.ts.map +1 -0
- package/dist/node/index-Y0zHb1Bz.d.ts +47 -0
- package/dist/node/index-Y0zHb1Bz.d.ts.map +1 -0
- package/dist/node/index-k3TUjA-T.d.ts +26 -0
- package/dist/node/index-k3TUjA-T.d.ts.map +1 -0
- package/dist/node/index-nBlMTFkZ.d.ts +34 -0
- package/dist/node/index-nBlMTFkZ.d.ts.map +1 -0
- package/dist/node/index.cjs +1 -0
- package/dist/node/index.d.ts +6 -0
- package/dist/node/index.js +1 -0
- package/dist/node/mcp/index.cjs +1 -0
- package/dist/node/mcp/index.d.ts +2 -0
- package/dist/node/mcp/index.js +1 -0
- package/dist/node/mcp-BXBwF6Wu.js +2 -0
- package/dist/node/mcp-BXBwF6Wu.js.map +1 -0
- package/dist/node/mcp-DcHuGokt.cjs +1 -0
- package/dist/node/tui/index.cjs +1 -0
- package/dist/node/tui/index.d.ts +2 -0
- package/dist/node/tui/index.js +1 -0
- package/dist/node/tui-CeD_6rSo.cjs +24 -0
- package/dist/node/tui-zmDTPk4b.js +25 -0
- package/dist/node/tui-zmDTPk4b.js.map +1 -0
- package/dist/node/ws/index.cjs +1 -0
- package/dist/node/ws/index.d.ts +2 -0
- package/dist/node/ws/index.js +1 -0
- package/dist/node/ws-B-oRccFl.js +2 -0
- package/dist/node/ws-B-oRccFl.js.map +1 -0
- package/dist/node/ws-COnIgnmn.cjs +1 -0
- package/package.json +141 -0
- package/src/headless/__tests__/headless-runner-initialization.test.ts +45 -0
- package/src/headless/__tests__/headless-runner.test.ts +484 -0
- package/src/headless/__tests__/headless-skill-activation.integration.test.ts +430 -0
- package/src/headless/__tests__/headless-transport.test.ts +268 -0
- package/src/headless/headless-runner.ts +141 -0
- package/src/headless/headless-stream-json.ts +142 -0
- package/src/headless/headless-transport.ts +43 -0
- package/src/headless/index.ts +4 -0
- package/src/http/__tests__/http-transport.test.ts +55 -0
- package/src/http/__tests__/routes.test.ts +168 -0
- package/src/http/http-transport.ts +42 -0
- package/src/http/index.ts +4 -0
- package/src/http/routes.ts +151 -0
- package/src/index.ts +5 -0
- package/src/mcp/__tests__/mcp-server.test.ts +66 -0
- package/src/mcp/__tests__/mcp-transport.test.ts +46 -0
- package/src/mcp/index.ts +4 -0
- package/src/mcp/mcp-server.ts +162 -0
- package/src/mcp/mcp-transport.ts +48 -0
- package/src/tui/App.tsx +478 -0
- package/src/tui/BackgroundTaskPanel.tsx +34 -0
- package/src/tui/CjkTextInput.tsx +204 -0
- package/src/tui/ConfirmPrompt.tsx +69 -0
- package/src/tui/ExecutionWorkspaceDetailPane.tsx +62 -0
- package/src/tui/ExecutionWorkspaceSwitcher.tsx +185 -0
- package/src/tui/InkTerminal.ts +42 -0
- package/src/tui/InputArea.tsx +298 -0
- package/src/tui/InteractivePrompt.tsx +57 -0
- package/src/tui/ListPicker.tsx +94 -0
- package/src/tui/MenuSelect.tsx +103 -0
- package/src/tui/MessageList.tsx +282 -0
- package/src/tui/PermissionPrompt.tsx +84 -0
- package/src/tui/PluginTUI.tsx +256 -0
- package/src/tui/SessionPicker.tsx +66 -0
- package/src/tui/SessionStatusBar.tsx +66 -0
- package/src/tui/SlashAutocomplete.tsx +110 -0
- package/src/tui/StatusBar.tsx +213 -0
- package/src/tui/StreamingIndicator.tsx +91 -0
- package/src/tui/TextPrompt.tsx +80 -0
- package/src/tui/ToolCommandOutput.tsx +37 -0
- package/src/tui/ToolDiffBlock.tsx +30 -0
- package/src/tui/TransportTUI.tsx +116 -0
- package/src/tui/UpdateNotice.tsx +14 -0
- package/src/tui/UsageSummaryEntry.tsx +38 -0
- package/src/tui/WaveText.tsx +44 -0
- package/src/tui/__tests__/InteractivePrompt.test.tsx +82 -0
- package/src/tui/__tests__/ListPicker.test.tsx +159 -0
- package/src/tui/__tests__/MenuSelect.test.tsx +103 -0
- package/src/tui/__tests__/PluginTUI.test.tsx +167 -0
- package/src/tui/__tests__/SlashAutocomplete.test.tsx +140 -0
- package/src/tui/__tests__/TextPrompt.test.tsx +98 -0
- package/src/tui/__tests__/UpdateNotice.test.tsx +15 -0
- package/src/tui/__tests__/abort-after-permission.test.tsx +169 -0
- package/src/tui/__tests__/abort-streaming-e2e.test.tsx +183 -0
- package/src/tui/__tests__/background-task-panel.test.tsx +53 -0
- package/src/tui/__tests__/background-task-row-format.test.ts +59 -0
- package/src/tui/__tests__/cjk-text-input-flow.test.ts +109 -0
- package/src/tui/__tests__/cjk-text-input.test.ts +191 -0
- package/src/tui/__tests__/command-effect-handler.test.ts +128 -0
- package/src/tui/__tests__/command-output-summary.test.ts +95 -0
- package/src/tui/__tests__/compact-event-bridge.test.ts +20 -0
- package/src/tui/__tests__/confirm-permission-flow.test.ts +91 -0
- package/src/tui/__tests__/confirm-prompt.test.tsx +87 -0
- package/src/tui/__tests__/execution-workspace-switcher.test.tsx +110 -0
- package/src/tui/__tests__/execution-workspace-view-model.test.ts +93 -0
- package/src/tui/__tests__/fixtures/provider-setup-prompt-driver.tsx +122 -0
- package/src/tui/__tests__/input-area-flow.test.ts +152 -0
- package/src/tui/__tests__/message-list-rendering.test.tsx +353 -0
- package/src/tui/__tests__/model-change-side-effect.test.ts +91 -0
- package/src/tui/__tests__/prompt-queue.test.tsx +255 -0
- package/src/tui/__tests__/provider-setup-pty-e2e.test.ts +233 -0
- package/src/tui/__tests__/render-markdown.test.ts +72 -0
- package/src/tui/__tests__/selection-flow.test.ts +61 -0
- package/src/tui/__tests__/slash-routing-effects.test.ts +225 -0
- package/src/tui/__tests__/status-activity.test.ts +71 -0
- package/src/tui/__tests__/status-bar.test.tsx +157 -0
- package/src/tui/__tests__/streaming-indicator.test.tsx +137 -0
- package/src/tui/__tests__/text-prompt-flow.test.ts +77 -0
- package/src/tui/__tests__/tui-state-manager.test.ts +401 -0
- package/src/tui/background-task-row-format.ts +52 -0
- package/src/tui/command-output-summary.ts +122 -0
- package/src/tui/execution-workspace-view-model.ts +123 -0
- package/src/tui/flows/cjk-text-input-flow.ts +285 -0
- package/src/tui/flows/confirm-prompt-flow.ts +45 -0
- package/src/tui/flows/input-area-flow.ts +186 -0
- package/src/tui/flows/permission-prompt-flow.ts +76 -0
- package/src/tui/flows/selection-flow.ts +126 -0
- package/src/tui/flows/text-prompt-flow.ts +98 -0
- package/src/tui/hooks/command-effect-handler.ts +98 -0
- package/src/tui/hooks/command-effect-queue.ts +39 -0
- package/src/tui/hooks/model-change-side-effect.ts +63 -0
- package/src/tui/hooks/side-effects-types.ts +38 -0
- package/src/tui/hooks/use-interactive-session-init.ts +50 -0
- package/src/tui/hooks/useAutocomplete.ts +85 -0
- package/src/tui/hooks/useInteractiveSession.ts +273 -0
- package/src/tui/hooks/usePermissionQueue.ts +51 -0
- package/src/tui/hooks/usePluginCallbacks.ts +30 -0
- package/src/tui/hooks/usePluginScreenData.ts +84 -0
- package/src/tui/hooks/useSideEffects.ts +210 -0
- package/src/tui/hooks/useSlashRouting.ts +117 -0
- package/src/tui/hooks/useStatusLineSettings.ts +35 -0
- package/src/tui/index.ts +3 -0
- package/src/tui/plugin-tui-handlers.ts +163 -0
- package/src/tui/render-markdown.ts +129 -0
- package/src/tui/render.tsx +60 -0
- package/src/tui/status-activity.ts +63 -0
- package/src/tui/tui-cli-adapter-context.tsx +12 -0
- package/src/tui/tui-cli-adapter.ts +25 -0
- package/src/tui/tui-state-manager.ts +225 -0
- package/src/tui/tui-transport.ts +32 -0
- package/src/tui/types.ts +14 -0
- package/src/tui/utils/__tests__/edit-diff.test.ts +426 -0
- package/src/tui/utils/__tests__/paste-detection.test.ts +116 -0
- package/src/tui/utils/__tests__/paste-labels.test.ts +46 -0
- package/src/tui/utils/__tests__/tool-call-extractor.test.ts +227 -0
- package/src/tui/utils/__tests__/tool-diff-summary.test.ts +104 -0
- package/src/tui/utils/edit-diff.ts +152 -0
- package/src/tui/utils/paste-labels.ts +9 -0
- package/src/tui/utils/tool-call-extractor.ts +91 -0
- package/src/tui/utils/tool-diff-summary.ts +75 -0
- package/src/ws/__tests__/ws-handler.test.ts +407 -0
- package/src/ws/__tests__/ws-transport.test.ts +53 -0
- package/src/ws/index.ts +13 -0
- package/src/ws/ws-background-messages.ts +170 -0
- package/src/ws/ws-handler.ts +279 -0
- package/src/ws/ws-protocol.ts +76 -0
- package/src/ws/ws-transport-configurable.ts +123 -0
- package/src/ws/ws-transport.ts +42 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, Text } from 'ink';
|
|
3
|
+
import type { IHistoryEntry, TUniversalMessage, TUniversalValue } from '@robota-sdk/agent-core';
|
|
4
|
+
import { isToolMessage, isAssistantMessage } from '@robota-sdk/agent-core';
|
|
5
|
+
import { renderMarkdown } from './render-markdown.js';
|
|
6
|
+
import type { IToolCallSummary } from './utils/tool-call-extractor.js';
|
|
7
|
+
import ToolDiffBlock from './ToolDiffBlock.js';
|
|
8
|
+
import UsageSummaryEntry from './UsageSummaryEntry.js';
|
|
9
|
+
import { formatCommandOutputSummary } from './command-output-summary.js';
|
|
10
|
+
import ToolCommandOutput from './ToolCommandOutput.js';
|
|
11
|
+
|
|
12
|
+
interface IProps {
|
|
13
|
+
history: IHistoryEntry[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type TToolSummaryItem = {
|
|
17
|
+
toolName: string;
|
|
18
|
+
firstArg?: string;
|
|
19
|
+
isRunning?: boolean;
|
|
20
|
+
result?: string;
|
|
21
|
+
diffLines?: IToolCallSummary['diffLines'];
|
|
22
|
+
diffFile?: string;
|
|
23
|
+
toolResultData?: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function getToolSummaryStatus(tool: TToolSummaryItem): string {
|
|
27
|
+
if (formatCommandOutputSummary(tool)?.status === 'error') return '✗';
|
|
28
|
+
if (tool.isRunning) return '⟳';
|
|
29
|
+
if (tool.result === 'error') return '✗';
|
|
30
|
+
if (tool.result === 'denied') return '⊘';
|
|
31
|
+
return '✓';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function getToolSummaryColor(tool: TToolSummaryItem): string {
|
|
35
|
+
if (formatCommandOutputSummary(tool)?.status === 'error' || tool.result === 'error') return 'red';
|
|
36
|
+
if (tool.isRunning || tool.result === 'denied') return 'yellow';
|
|
37
|
+
return 'green';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getToolSummaryLabel(tool: TToolSummaryItem): string {
|
|
41
|
+
return `${getToolSummaryStatus(tool)} ${tool.toolName}${tool.firstArg ? `(${tool.firstArg})` : ''}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function RoleLabel({ role }: { role: TUniversalMessage['role'] }): React.ReactElement {
|
|
45
|
+
switch (role) {
|
|
46
|
+
case 'user':
|
|
47
|
+
return (
|
|
48
|
+
<Text color="green" bold>
|
|
49
|
+
You:{' '}
|
|
50
|
+
</Text>
|
|
51
|
+
);
|
|
52
|
+
case 'assistant':
|
|
53
|
+
return (
|
|
54
|
+
<Text color="cyan" bold>
|
|
55
|
+
Robota:{' '}
|
|
56
|
+
</Text>
|
|
57
|
+
);
|
|
58
|
+
case 'system':
|
|
59
|
+
return (
|
|
60
|
+
<Text color="yellow" bold>
|
|
61
|
+
System:{' '}
|
|
62
|
+
</Text>
|
|
63
|
+
);
|
|
64
|
+
case 'tool':
|
|
65
|
+
return (
|
|
66
|
+
<Text color="white" bold>
|
|
67
|
+
Tool:{' '}
|
|
68
|
+
</Text>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function ToolMessage({ message }: { message: TUniversalMessage }): React.ReactElement {
|
|
74
|
+
if (!isToolMessage(message)) {
|
|
75
|
+
return <></>;
|
|
76
|
+
}
|
|
77
|
+
const toolName = message.name;
|
|
78
|
+
const content = message.content;
|
|
79
|
+
|
|
80
|
+
// Try to parse structured tool summaries (with diff info)
|
|
81
|
+
let summaries: IToolCallSummary[] | null = null;
|
|
82
|
+
try {
|
|
83
|
+
const parsed = JSON.parse(content) as IToolCallSummary[];
|
|
84
|
+
if (Array.isArray(parsed) && parsed.length > 0 && typeof parsed[0].line === 'string') {
|
|
85
|
+
summaries = parsed as IToolCallSummary[];
|
|
86
|
+
}
|
|
87
|
+
} catch {
|
|
88
|
+
// Not JSON — fall back to plain text lines
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (summaries) {
|
|
92
|
+
return (
|
|
93
|
+
<Box flexDirection="column" marginBottom={1}>
|
|
94
|
+
<Box>
|
|
95
|
+
<Text color="white" bold>
|
|
96
|
+
Tool:{' '}
|
|
97
|
+
</Text>
|
|
98
|
+
{toolName && (
|
|
99
|
+
<Text color="white" dimColor>
|
|
100
|
+
[{toolName}]
|
|
101
|
+
</Text>
|
|
102
|
+
)}
|
|
103
|
+
</Box>
|
|
104
|
+
<Text> </Text>
|
|
105
|
+
{summaries.map((s, i) => (
|
|
106
|
+
<Box key={i} flexDirection="column">
|
|
107
|
+
<Text color="green">
|
|
108
|
+
{' '}
|
|
109
|
+
{'✓'} {s.line}
|
|
110
|
+
</Text>
|
|
111
|
+
{s.diffLines && s.diffLines.length > 0 && (
|
|
112
|
+
<ToolDiffBlock file={s.diffFile} lines={s.diffLines} />
|
|
113
|
+
)}
|
|
114
|
+
</Box>
|
|
115
|
+
))}
|
|
116
|
+
</Box>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Fallback: plain text lines
|
|
121
|
+
const lines = content.split('\n').filter((l) => l.trim());
|
|
122
|
+
return (
|
|
123
|
+
<Box flexDirection="column" marginBottom={1}>
|
|
124
|
+
<Box>
|
|
125
|
+
<Text color="white" bold>
|
|
126
|
+
Tool:{' '}
|
|
127
|
+
</Text>
|
|
128
|
+
{toolName && (
|
|
129
|
+
<Text color="white" dimColor>
|
|
130
|
+
[{toolName}]
|
|
131
|
+
</Text>
|
|
132
|
+
)}
|
|
133
|
+
</Box>
|
|
134
|
+
<Text> </Text>
|
|
135
|
+
{lines.map((line, i) => (
|
|
136
|
+
<Text key={i} color="green">
|
|
137
|
+
{' '}
|
|
138
|
+
{'✓'} {line}
|
|
139
|
+
</Text>
|
|
140
|
+
))}
|
|
141
|
+
</Box>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const MessageItem = React.memo(function MessageItem({
|
|
146
|
+
message,
|
|
147
|
+
}: {
|
|
148
|
+
message: TUniversalMessage;
|
|
149
|
+
}): React.ReactElement {
|
|
150
|
+
if (isToolMessage(message)) {
|
|
151
|
+
return <ToolMessage message={message} />;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const content = message.content ?? '';
|
|
155
|
+
const isInterrupted = message.state === 'interrupted';
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<Box flexDirection="column" marginBottom={1}>
|
|
159
|
+
<Box>
|
|
160
|
+
<RoleLabel role={message.role} />
|
|
161
|
+
</Box>
|
|
162
|
+
<Text> </Text>
|
|
163
|
+
<Box marginLeft={2}>
|
|
164
|
+
<Text wrap="wrap">
|
|
165
|
+
{isAssistantMessage(message)
|
|
166
|
+
? renderMarkdown(content + (isInterrupted ? '\n\n_(interrupted)_' : ''))
|
|
167
|
+
: content}
|
|
168
|
+
</Text>
|
|
169
|
+
</Box>
|
|
170
|
+
</Box>
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
function ToolSummaryEntry({ entry }: { entry: IHistoryEntry }): React.ReactElement {
|
|
175
|
+
const data = entry.data as
|
|
176
|
+
| {
|
|
177
|
+
summary?: string;
|
|
178
|
+
tools?: TToolSummaryItem[];
|
|
179
|
+
}
|
|
180
|
+
| undefined;
|
|
181
|
+
const tools = data?.tools;
|
|
182
|
+
const lines = data?.summary?.split('\n') ?? [];
|
|
183
|
+
|
|
184
|
+
if (tools && tools.length > 0) {
|
|
185
|
+
return (
|
|
186
|
+
<Box flexDirection="column" marginBottom={1}>
|
|
187
|
+
<Box>
|
|
188
|
+
<Text color="white" bold>
|
|
189
|
+
Tool:{' '}
|
|
190
|
+
</Text>
|
|
191
|
+
</Box>
|
|
192
|
+
<Text> </Text>
|
|
193
|
+
{tools.map((tool, i) => (
|
|
194
|
+
<Box key={i} flexDirection="column">
|
|
195
|
+
<Text color={getToolSummaryColor(tool)}>
|
|
196
|
+
{' '}
|
|
197
|
+
{getToolSummaryLabel(tool)}
|
|
198
|
+
</Text>
|
|
199
|
+
<ToolCommandOutput tool={tool} />
|
|
200
|
+
{tool.diffLines && tool.diffLines.length > 0 && (
|
|
201
|
+
<ToolDiffBlock file={tool.diffFile} lines={tool.diffLines} />
|
|
202
|
+
)}
|
|
203
|
+
</Box>
|
|
204
|
+
))}
|
|
205
|
+
</Box>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<Box flexDirection="column" marginBottom={1}>
|
|
211
|
+
<Box>
|
|
212
|
+
<Text color="white" bold>
|
|
213
|
+
Tool:{' '}
|
|
214
|
+
</Text>
|
|
215
|
+
</Box>
|
|
216
|
+
<Text> </Text>
|
|
217
|
+
{lines.map((line, i) => (
|
|
218
|
+
<Text key={i} color="green">
|
|
219
|
+
{' '}
|
|
220
|
+
{line}
|
|
221
|
+
</Text>
|
|
222
|
+
))}
|
|
223
|
+
</Box>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function EventEntry({ entry }: { entry: IHistoryEntry }): React.ReactElement {
|
|
228
|
+
const eventData = entry.data as Record<string, TUniversalValue> | undefined;
|
|
229
|
+
const eventMessage =
|
|
230
|
+
typeof eventData?.message === 'string'
|
|
231
|
+
? eventData.message
|
|
232
|
+
: typeof eventData?.content === 'string'
|
|
233
|
+
? eventData.content
|
|
234
|
+
: entry.type;
|
|
235
|
+
|
|
236
|
+
return (
|
|
237
|
+
<Box flexDirection="column" marginBottom={1}>
|
|
238
|
+
<Box>
|
|
239
|
+
<Text color="yellow" bold>
|
|
240
|
+
System:{' '}
|
|
241
|
+
</Text>
|
|
242
|
+
</Box>
|
|
243
|
+
<Text> </Text>
|
|
244
|
+
<Box marginLeft={2}>
|
|
245
|
+
<Text wrap="wrap">{eventMessage}</Text>
|
|
246
|
+
</Box>
|
|
247
|
+
</Box>
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function EntryItem({ entry }: { entry: IHistoryEntry }): React.ReactElement {
|
|
252
|
+
if (entry.category === 'chat') {
|
|
253
|
+
const message = entry.data as TUniversalMessage;
|
|
254
|
+
return <MessageItem message={message} />;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (entry.type === 'tool-summary') {
|
|
258
|
+
return <ToolSummaryEntry entry={entry} />;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (entry.type === 'usage-summary') {
|
|
262
|
+
return <UsageSummaryEntry entry={entry} />;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// tool-start/tool-end are recorded in history for persistence but not rendered
|
|
266
|
+
// (StreamingIndicator shows them during streaming, tool-summary shows them after)
|
|
267
|
+
if (entry.type === 'tool-start' || entry.type === 'tool-end') {
|
|
268
|
+
return <></>;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return <EventEntry entry={entry} />;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export default function MessageList({ history }: IProps): React.ReactElement {
|
|
275
|
+
return (
|
|
276
|
+
<Box flexDirection="column">
|
|
277
|
+
{history.map((entry) => (
|
|
278
|
+
<EntryItem key={entry.id} entry={entry} />
|
|
279
|
+
))}
|
|
280
|
+
</Box>
|
|
281
|
+
);
|
|
282
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, Text, useInput } from 'ink';
|
|
3
|
+
import type { IPermissionRequest } from './types.js';
|
|
4
|
+
import type { TToolArgs } from '@robota-sdk/agent-core';
|
|
5
|
+
import {
|
|
6
|
+
applyPermissionPromptInput,
|
|
7
|
+
getPermissionPromptInputAction,
|
|
8
|
+
PERMISSION_PROMPT_OPTIONS,
|
|
9
|
+
type TPermissionPromptInputAction,
|
|
10
|
+
} from './flows/permission-prompt-flow.js';
|
|
11
|
+
import { createSelectionFlowState, type ISelectionFlowState } from './flows/selection-flow.js';
|
|
12
|
+
|
|
13
|
+
interface IProps {
|
|
14
|
+
request: IPermissionRequest;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function formatArgs(args: TToolArgs): string {
|
|
18
|
+
const entries = Object.entries(args);
|
|
19
|
+
if (entries.length === 0) return '(no arguments)';
|
|
20
|
+
return entries
|
|
21
|
+
.map(([k, v]) => `${k}: ${typeof v === 'string' ? v : JSON.stringify(v)}`)
|
|
22
|
+
.join(', ');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default function PermissionPrompt({ request }: IProps): React.ReactElement {
|
|
26
|
+
const [state, setState] = React.useState<ISelectionFlowState>(() => createSelectionFlowState());
|
|
27
|
+
const stateRef = React.useRef(state);
|
|
28
|
+
const prevRequestRef = React.useRef(request);
|
|
29
|
+
|
|
30
|
+
if (prevRequestRef.current !== request) {
|
|
31
|
+
prevRequestRef.current = request;
|
|
32
|
+
const nextState = createSelectionFlowState();
|
|
33
|
+
stateRef.current = nextState;
|
|
34
|
+
setState(nextState);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const applyAction = React.useCallback(
|
|
38
|
+
(action: TPermissionPromptInputAction): void => {
|
|
39
|
+
const result = applyPermissionPromptInput(stateRef.current, action);
|
|
40
|
+
stateRef.current = result.state;
|
|
41
|
+
setState(result.state);
|
|
42
|
+
if (result.effect.type === 'resolve') {
|
|
43
|
+
request.resolve(result.effect.decision);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
[request],
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
useInput((input, key) => {
|
|
50
|
+
const action = getPermissionPromptInputAction(input, key);
|
|
51
|
+
if (action !== undefined) {
|
|
52
|
+
applyAction(action);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Box flexDirection="column" borderStyle="round" borderColor="yellow" paddingX={1}>
|
|
58
|
+
<Text color="yellow" bold>
|
|
59
|
+
[Permission Required]
|
|
60
|
+
</Text>
|
|
61
|
+
<Text>
|
|
62
|
+
Tool:{' '}
|
|
63
|
+
<Text color="cyan" bold>
|
|
64
|
+
{request.toolName}
|
|
65
|
+
</Text>
|
|
66
|
+
</Text>
|
|
67
|
+
<Text dimColor> {formatArgs(request.toolArgs)}</Text>
|
|
68
|
+
<Box marginTop={1}>
|
|
69
|
+
{PERMISSION_PROMPT_OPTIONS.map((opt, i) => (
|
|
70
|
+
<Box key={opt} marginRight={2}>
|
|
71
|
+
<Text
|
|
72
|
+
color={i === state.selectedIndex ? 'cyan' : undefined}
|
|
73
|
+
bold={i === state.selectedIndex}
|
|
74
|
+
>
|
|
75
|
+
{i === state.selectedIndex ? '> ' : ' '}
|
|
76
|
+
{opt}
|
|
77
|
+
</Text>
|
|
78
|
+
</Box>
|
|
79
|
+
))}
|
|
80
|
+
</Box>
|
|
81
|
+
<Text dimColor> left/right to select, Enter to confirm</Text>
|
|
82
|
+
</Box>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PluginTUI — Main orchestrator component for plugin management.
|
|
3
|
+
* Manages a stack of screens: main, marketplace, installed plugins, etc.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { useState, useCallback } from 'react';
|
|
7
|
+
import MenuSelect from './MenuSelect.js';
|
|
8
|
+
import TextPrompt from './TextPrompt.js';
|
|
9
|
+
import ConfirmPrompt from './ConfirmPrompt.js';
|
|
10
|
+
import {
|
|
11
|
+
handleMainSelect,
|
|
12
|
+
handleMarketplaceListSelect,
|
|
13
|
+
handleMarketplaceActionSelect,
|
|
14
|
+
handleMarketplaceBrowseSelect,
|
|
15
|
+
handleInstallScopeSelect,
|
|
16
|
+
handleInstalledListSelect,
|
|
17
|
+
handleInstalledActionSelect,
|
|
18
|
+
} from './plugin-tui-handlers.js';
|
|
19
|
+
import type { IMenuSelectItem } from './MenuSelect.js';
|
|
20
|
+
import type { ICommandPluginAdapter } from '@robota-sdk/agent-framework';
|
|
21
|
+
import { usePluginScreenData } from './hooks/usePluginScreenData.js';
|
|
22
|
+
|
|
23
|
+
type TScreenId =
|
|
24
|
+
| 'main'
|
|
25
|
+
| 'marketplace-list'
|
|
26
|
+
| 'marketplace-action'
|
|
27
|
+
| 'marketplace-browse'
|
|
28
|
+
| 'marketplace-install-scope'
|
|
29
|
+
| 'marketplace-add'
|
|
30
|
+
| 'installed-list'
|
|
31
|
+
| 'installed-action';
|
|
32
|
+
|
|
33
|
+
interface IMenuContext {
|
|
34
|
+
marketplace?: string;
|
|
35
|
+
pluginId?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface IMenuState {
|
|
39
|
+
screen: TScreenId;
|
|
40
|
+
context?: IMenuContext;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface IConfirmState {
|
|
44
|
+
message: string;
|
|
45
|
+
onConfirm: () => void;
|
|
46
|
+
onCancel: () => void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface IProps {
|
|
50
|
+
callbacks: ICommandPluginAdapter;
|
|
51
|
+
onClose: () => void;
|
|
52
|
+
addMessage?: (msg: { role: string; content: string }) => void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default function PluginTUI({ callbacks, onClose, addMessage }: IProps): React.ReactElement {
|
|
56
|
+
const [stack, setStack] = useState<IMenuState[]>([{ screen: 'main' }]);
|
|
57
|
+
const [confirm, setConfirm] = useState<IConfirmState | undefined>();
|
|
58
|
+
const [refreshCounter, setRefreshCounter] = useState(0);
|
|
59
|
+
|
|
60
|
+
const current = stack[stack.length - 1] ?? { screen: 'main' };
|
|
61
|
+
|
|
62
|
+
const push = useCallback((state: IMenuState) => {
|
|
63
|
+
setStack((prev) => [...prev, state]);
|
|
64
|
+
}, []);
|
|
65
|
+
|
|
66
|
+
const pop = useCallback(() => {
|
|
67
|
+
setStack((prev) => {
|
|
68
|
+
if (prev.length <= 1) {
|
|
69
|
+
onClose();
|
|
70
|
+
return prev;
|
|
71
|
+
}
|
|
72
|
+
return prev.slice(0, -1);
|
|
73
|
+
});
|
|
74
|
+
}, [onClose]);
|
|
75
|
+
|
|
76
|
+
const popN = useCallback(
|
|
77
|
+
(n: number) => {
|
|
78
|
+
setStack((prev) => {
|
|
79
|
+
const next = prev.slice(0, Math.max(1, prev.length - n));
|
|
80
|
+
if (next.length === 0) {
|
|
81
|
+
onClose();
|
|
82
|
+
return prev;
|
|
83
|
+
}
|
|
84
|
+
return next;
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
[onClose],
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const notify = useCallback(
|
|
91
|
+
(content: string) => {
|
|
92
|
+
addMessage?.({ role: 'system', content });
|
|
93
|
+
},
|
|
94
|
+
[addMessage],
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const refresh = useCallback(() => {
|
|
98
|
+
setRefreshCounter((c) => c + 1);
|
|
99
|
+
}, []);
|
|
100
|
+
|
|
101
|
+
const setConfirmNav = useCallback(
|
|
102
|
+
(state: IConfirmState | undefined) => setConfirm(state),
|
|
103
|
+
[setConfirm],
|
|
104
|
+
);
|
|
105
|
+
// nav.push accepts a loose { screen: string } shape to satisfy plugin-tui-handlers types;
|
|
106
|
+
// we cast screen to TScreenId which is safe because handlers only push valid screen names.
|
|
107
|
+
const pushNav = useCallback(
|
|
108
|
+
(state: { screen: string; context?: IMenuContext }) =>
|
|
109
|
+
push({ screen: state.screen as TScreenId, context: state.context }),
|
|
110
|
+
[push],
|
|
111
|
+
);
|
|
112
|
+
const nav = { push: pushNav, pop, popN, notify, setConfirm: setConfirmNav, refresh };
|
|
113
|
+
|
|
114
|
+
const { items, loading, error } = usePluginScreenData(
|
|
115
|
+
current.screen,
|
|
116
|
+
current.context?.marketplace,
|
|
117
|
+
callbacks,
|
|
118
|
+
refreshCounter,
|
|
119
|
+
stack.length,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const handleSelect = useCallback(
|
|
123
|
+
(value: string) => {
|
|
124
|
+
const screen = current.screen;
|
|
125
|
+
const ctx = current.context;
|
|
126
|
+
|
|
127
|
+
if (screen === 'main') handleMainSelect(value, nav);
|
|
128
|
+
else if (screen === 'marketplace-list') handleMarketplaceListSelect(value, nav);
|
|
129
|
+
else if (screen === 'marketplace-action')
|
|
130
|
+
handleMarketplaceActionSelect(value, ctx?.marketplace ?? '', callbacks, nav);
|
|
131
|
+
else if (screen === 'marketplace-browse')
|
|
132
|
+
handleMarketplaceBrowseSelect(value, ctx?.marketplace ?? '', items, nav);
|
|
133
|
+
else if (screen === 'marketplace-install-scope')
|
|
134
|
+
handleInstallScopeSelect(value, ctx?.pluginId ?? '', callbacks, nav);
|
|
135
|
+
else if (screen === 'installed-list') handleInstalledListSelect(value, callbacks, nav);
|
|
136
|
+
else if (screen === 'installed-action')
|
|
137
|
+
handleInstalledActionSelect(value, ctx?.pluginId ?? '', callbacks, nav);
|
|
138
|
+
},
|
|
139
|
+
[current, items, callbacks, push, pop, popN, notify, setConfirm, refresh],
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const handleTextSubmit = useCallback(
|
|
143
|
+
(value: string) => {
|
|
144
|
+
if (current.screen === 'marketplace-add') {
|
|
145
|
+
callbacks
|
|
146
|
+
.marketplaceAdd(value)
|
|
147
|
+
.then((name) => {
|
|
148
|
+
notify(`Added marketplace "${name}" from ${value}.`);
|
|
149
|
+
pop();
|
|
150
|
+
})
|
|
151
|
+
.catch((err) => {
|
|
152
|
+
notify(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
153
|
+
pop();
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
[current.screen, callbacks, notify, pop],
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
// Confirm overlay intercepts everything
|
|
161
|
+
if (confirm) {
|
|
162
|
+
return (
|
|
163
|
+
<ConfirmPrompt
|
|
164
|
+
message={confirm.message}
|
|
165
|
+
onSelect={(index) => {
|
|
166
|
+
if (index === 0) confirm.onConfirm();
|
|
167
|
+
else confirm.onCancel();
|
|
168
|
+
}}
|
|
169
|
+
/>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const screen = current.screen;
|
|
174
|
+
|
|
175
|
+
if (screen === 'marketplace-add') {
|
|
176
|
+
return (
|
|
177
|
+
<TextPrompt
|
|
178
|
+
title="Add Marketplace Source"
|
|
179
|
+
placeholder="owner/repo or git URL"
|
|
180
|
+
onSubmit={handleTextSubmit}
|
|
181
|
+
onCancel={pop}
|
|
182
|
+
validate={(v) => (!v.includes('/') ? 'Must be owner/repo or a git URL' : undefined)}
|
|
183
|
+
/>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (screen === 'marketplace-action') {
|
|
188
|
+
return (
|
|
189
|
+
<MenuSelect
|
|
190
|
+
key={stack.length}
|
|
191
|
+
title={`Marketplace: ${current.context?.marketplace ?? ''}`}
|
|
192
|
+
items={[
|
|
193
|
+
{ label: 'Browse plugins', value: 'browse' },
|
|
194
|
+
{ label: 'Update', value: 'update' },
|
|
195
|
+
{ label: 'Remove', value: 'remove' },
|
|
196
|
+
]}
|
|
197
|
+
onSelect={handleSelect}
|
|
198
|
+
onBack={pop}
|
|
199
|
+
/>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (screen === 'marketplace-install-scope') {
|
|
204
|
+
return (
|
|
205
|
+
<MenuSelect
|
|
206
|
+
key={stack.length}
|
|
207
|
+
title={`Install scope for "${current.context?.pluginId ?? ''}"`}
|
|
208
|
+
items={[
|
|
209
|
+
{ label: 'User scope', value: 'user' },
|
|
210
|
+
{ label: 'Project scope', value: 'project' },
|
|
211
|
+
]}
|
|
212
|
+
onSelect={handleSelect}
|
|
213
|
+
onBack={pop}
|
|
214
|
+
/>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (screen === 'installed-action') {
|
|
219
|
+
return (
|
|
220
|
+
<MenuSelect
|
|
221
|
+
key={stack.length}
|
|
222
|
+
title={`Plugin: ${current.context?.pluginId ?? ''}`}
|
|
223
|
+
items={[{ label: 'Uninstall', value: 'uninstall' }]}
|
|
224
|
+
onSelect={handleSelect}
|
|
225
|
+
onBack={pop}
|
|
226
|
+
/>
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Screens with async items: main, marketplace-list, marketplace-browse, installed-list
|
|
231
|
+
const titleMap: Record<string, string> = {
|
|
232
|
+
main: 'Plugin Management',
|
|
233
|
+
'marketplace-list': 'Marketplace',
|
|
234
|
+
'marketplace-browse': `Browse: ${current.context?.marketplace ?? ''}`,
|
|
235
|
+
'installed-list': 'Installed Plugins',
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const staticItemsMap: Record<string, IMenuSelectItem[]> = {
|
|
239
|
+
main: [
|
|
240
|
+
{ label: 'Marketplace', value: 'marketplace' },
|
|
241
|
+
{ label: 'Installed Plugins', value: 'installed' },
|
|
242
|
+
],
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
return (
|
|
246
|
+
<MenuSelect
|
|
247
|
+
key={`${screen}-${stack.length}-${refreshCounter}`}
|
|
248
|
+
title={titleMap[screen] ?? 'Plugin Management'}
|
|
249
|
+
items={staticItemsMap[screen] ?? items}
|
|
250
|
+
onSelect={handleSelect}
|
|
251
|
+
onBack={pop}
|
|
252
|
+
loading={loading}
|
|
253
|
+
error={error}
|
|
254
|
+
/>
|
|
255
|
+
);
|
|
256
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session picker component for /resume command.
|
|
3
|
+
* Shows a list of sessions for the current cwd.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { Box, Text } from 'ink';
|
|
8
|
+
import type { IResumableSessionSummary } from '@robota-sdk/agent-framework';
|
|
9
|
+
import ListPicker from './ListPicker.js';
|
|
10
|
+
|
|
11
|
+
const SESSION_ID_DISPLAY_LENGTH = 8;
|
|
12
|
+
const SESSION_PREVIEW_DISPLAY_LENGTH = 60;
|
|
13
|
+
|
|
14
|
+
interface IProps {
|
|
15
|
+
sessions: readonly IResumableSessionSummary[];
|
|
16
|
+
onSelect: (sessionId: string) => void;
|
|
17
|
+
onCancel: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default function SessionPicker({
|
|
21
|
+
sessions,
|
|
22
|
+
onSelect,
|
|
23
|
+
onCancel,
|
|
24
|
+
}: IProps): React.ReactElement {
|
|
25
|
+
return (
|
|
26
|
+
<Box flexDirection="column" paddingX={1} marginBottom={1}>
|
|
27
|
+
<Text bold color="cyan">
|
|
28
|
+
Select a session to resume (ESC to cancel):
|
|
29
|
+
</Text>
|
|
30
|
+
<ListPicker<IResumableSessionSummary>
|
|
31
|
+
items={[...sessions]}
|
|
32
|
+
renderItem={(session: IResumableSessionSummary, isSelected: boolean) => {
|
|
33
|
+
const preview = session.preview
|
|
34
|
+
? session.preview.slice(0, SESSION_PREVIEW_DISPLAY_LENGTH) +
|
|
35
|
+
(session.preview.length > SESSION_PREVIEW_DISPLAY_LENGTH ? '...' : '')
|
|
36
|
+
: '';
|
|
37
|
+
return (
|
|
38
|
+
<Text>
|
|
39
|
+
{isSelected ? '> ' : ' '}
|
|
40
|
+
<Text bold>{session.name ?? session.id.slice(0, SESSION_ID_DISPLAY_LENGTH)}</Text>
|
|
41
|
+
{' '}
|
|
42
|
+
<Text dimColor>
|
|
43
|
+
{new Date(session.updatedAt).toLocaleString(undefined, {
|
|
44
|
+
month: 'short',
|
|
45
|
+
day: 'numeric',
|
|
46
|
+
hour: '2-digit',
|
|
47
|
+
minute: '2-digit',
|
|
48
|
+
})}
|
|
49
|
+
</Text>
|
|
50
|
+
{' '}
|
|
51
|
+
<Text dimColor>msgs: {session.messageCount}</Text>
|
|
52
|
+
{preview ? (
|
|
53
|
+
<>
|
|
54
|
+
{'\n '}
|
|
55
|
+
<Text color="gray">{preview}</Text>
|
|
56
|
+
</>
|
|
57
|
+
) : null}
|
|
58
|
+
</Text>
|
|
59
|
+
);
|
|
60
|
+
}}
|
|
61
|
+
onSelect={(session: IResumableSessionSummary) => onSelect(session.id)}
|
|
62
|
+
onCancel={onCancel}
|
|
63
|
+
/>
|
|
64
|
+
</Box>
|
|
65
|
+
);
|
|
66
|
+
}
|