@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,122 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { writeFileSync } from 'node:fs';
|
|
3
|
+
import { render, useApp } from 'ink';
|
|
4
|
+
import InteractivePrompt from '../../InteractivePrompt.js';
|
|
5
|
+
import type { TCommandInteractionPrompt as TInteractivePrompt } from '@robota-sdk/agent-framework';
|
|
6
|
+
import {
|
|
7
|
+
createProviderSetupFlow,
|
|
8
|
+
formatProviderSetupHelpLinks,
|
|
9
|
+
getProviderSetupStep,
|
|
10
|
+
submitProviderSetupValue,
|
|
11
|
+
validateProviderSetupValue,
|
|
12
|
+
type IProviderSetupFlowState,
|
|
13
|
+
type TProviderSetupType,
|
|
14
|
+
} from '@robota-sdk/agent-command';
|
|
15
|
+
import type { IAIProvider, IProviderDefinition } from '@robota-sdk/agent-core';
|
|
16
|
+
|
|
17
|
+
const openaiDefaults = {
|
|
18
|
+
apiKey: '$ENV:OPENAI_API_KEY',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const providerDefinitions: readonly IProviderDefinition[] = [
|
|
22
|
+
{
|
|
23
|
+
type: 'openai',
|
|
24
|
+
defaults: openaiDefaults,
|
|
25
|
+
setupHelpLinks: [
|
|
26
|
+
{
|
|
27
|
+
kind: 'api-key',
|
|
28
|
+
label: 'OpenAI API keys',
|
|
29
|
+
url: 'https://platform.openai.com/api-keys',
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
setupSteps: [
|
|
33
|
+
{
|
|
34
|
+
key: 'model',
|
|
35
|
+
title: 'OpenAI model',
|
|
36
|
+
required: true,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
key: 'apiKey',
|
|
40
|
+
title: 'OpenAI API key',
|
|
41
|
+
defaultValue: openaiDefaults.apiKey,
|
|
42
|
+
masked: true,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
requiresApiKey: true,
|
|
46
|
+
createProvider: () => {
|
|
47
|
+
throw new Error('not used');
|
|
48
|
+
},
|
|
49
|
+
} as IProviderDefinition & { createProvider: () => IAIProvider },
|
|
50
|
+
{
|
|
51
|
+
type: 'anthropic',
|
|
52
|
+
defaults: { model: 'claude-sonnet-4-6' },
|
|
53
|
+
setupSteps: [
|
|
54
|
+
{ key: 'apiKey', title: 'Anthropic API key', required: true, masked: true },
|
|
55
|
+
{ key: 'model', title: 'Anthropic model', defaultValue: 'claude-sonnet-4-6' },
|
|
56
|
+
],
|
|
57
|
+
requiresApiKey: true,
|
|
58
|
+
createProvider: () => {
|
|
59
|
+
throw new Error('not used');
|
|
60
|
+
},
|
|
61
|
+
} as IProviderDefinition & { createProvider: () => IAIProvider },
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
const [, , outputPath, rawType] = process.argv;
|
|
65
|
+
|
|
66
|
+
if (!outputPath || (rawType !== 'openai' && rawType !== 'anthropic')) {
|
|
67
|
+
process.stderr.write('Usage: provider-setup-prompt-driver <output-path> <openai|anthropic>\n');
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function Driver({ type }: { type: TProviderSetupType }): React.ReactElement {
|
|
72
|
+
const { exit } = useApp();
|
|
73
|
+
const initial = createProviderSetupFlow(type, providerDefinitions);
|
|
74
|
+
const [state, setState] = React.useState<IProviderSetupFlowState>(initial);
|
|
75
|
+
const [prompt, setPrompt] = React.useState<TInteractivePrompt>(() => toPrompt(initial));
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<InteractivePrompt
|
|
79
|
+
prompt={prompt}
|
|
80
|
+
onSubmit={(value) => {
|
|
81
|
+
const result = submitProviderSetupValue(state, value);
|
|
82
|
+
if (result.status === 'complete') {
|
|
83
|
+
writeFileSync(outputPath, JSON.stringify(result.input), 'utf8');
|
|
84
|
+
exit();
|
|
85
|
+
setTimeout(() => process.exit(0), 0);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (result.status === 'error') {
|
|
89
|
+
throw new Error(result.message);
|
|
90
|
+
}
|
|
91
|
+
setState(result.state);
|
|
92
|
+
setPrompt(toPrompt(result.state));
|
|
93
|
+
}}
|
|
94
|
+
onCancel={() => {
|
|
95
|
+
exit();
|
|
96
|
+
setTimeout(() => process.exit(2), 0);
|
|
97
|
+
}}
|
|
98
|
+
/>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function toPrompt(flow: IProviderSetupFlowState): TInteractivePrompt {
|
|
103
|
+
const step = getProviderSetupStep(flow);
|
|
104
|
+
return {
|
|
105
|
+
kind: 'text',
|
|
106
|
+
title: step.title,
|
|
107
|
+
...toPromptDescription(flow),
|
|
108
|
+
...(step.defaultValue !== undefined ? { placeholder: step.defaultValue } : {}),
|
|
109
|
+
...(step.defaultValue !== undefined ? { allowEmpty: true } : {}),
|
|
110
|
+
...(step.masked !== undefined ? { masked: step.masked } : {}),
|
|
111
|
+
validate: (value) => validateProviderSetupValue(step, value),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function toPromptDescription(
|
|
116
|
+
flow: IProviderSetupFlowState,
|
|
117
|
+
): { description: string } | Record<string, never> {
|
|
118
|
+
const description = formatProviderSetupHelpLinks(flow.setupHelpLinks);
|
|
119
|
+
return description.length > 0 ? { description } : {};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
render(<Driver type={rawType} />);
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
appendPromptHistory,
|
|
4
|
+
createPasteLabelChange,
|
|
5
|
+
createPromptHistoryNavigationState,
|
|
6
|
+
extractPromptHistory,
|
|
7
|
+
getAutocompletePopupAction,
|
|
8
|
+
getPromptHistoryInputAction,
|
|
9
|
+
getPendingPromptInputAction,
|
|
10
|
+
moveAutocompleteSelection,
|
|
11
|
+
navigatePromptHistory,
|
|
12
|
+
resolveEnterCommandSelection,
|
|
13
|
+
resolveTabCompletion,
|
|
14
|
+
shouldSubmitInput,
|
|
15
|
+
} from '../flows/input-area-flow.js';
|
|
16
|
+
import type { ICommand } from '@robota-sdk/agent-framework';
|
|
17
|
+
import {
|
|
18
|
+
createAssistantMessage,
|
|
19
|
+
createSystemMessage,
|
|
20
|
+
createUserMessage,
|
|
21
|
+
messageToHistoryEntry,
|
|
22
|
+
} from '@robota-sdk/agent-core';
|
|
23
|
+
|
|
24
|
+
const command = (name: string, subcommands?: ICommand[]): ICommand => ({
|
|
25
|
+
name,
|
|
26
|
+
description: `${name} command`,
|
|
27
|
+
source: 'test',
|
|
28
|
+
subcommands,
|
|
29
|
+
execute: async () => {},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('input area flow', () => {
|
|
33
|
+
it('Given autocomplete key info When mapped Then popup actions are produced', () => {
|
|
34
|
+
expect(getAutocompletePopupAction({ upArrow: true })).toBe('previous');
|
|
35
|
+
expect(getAutocompletePopupAction({ downArrow: true })).toBe('next');
|
|
36
|
+
expect(getAutocompletePopupAction({ escape: true })).toBe('close');
|
|
37
|
+
expect(getAutocompletePopupAction({ tab: true })).toBe('complete');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('Given pending prompt key info When mapped Then cancel queue action is produced', () => {
|
|
41
|
+
expect(getPendingPromptInputAction({ backspace: true })).toBe('cancelQueue');
|
|
42
|
+
expect(getPendingPromptInputAction({ delete: true })).toBe('cancelQueue');
|
|
43
|
+
expect(getPendingPromptInputAction({ downArrow: true })).toBeUndefined();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('Given wrapping autocomplete When moving beyond bounds Then index wraps', () => {
|
|
47
|
+
expect(moveAutocompleteSelection(0, 3, 'previous')).toBe(2);
|
|
48
|
+
expect(moveAutocompleteSelection(2, 3, 'next')).toBe(0);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('Given parent command input When tab completes subcommand Then child name is inserted', () => {
|
|
52
|
+
const result = resolveTabCompletion('/plugin i', command('install'));
|
|
53
|
+
|
|
54
|
+
expect(result).toEqual({ type: 'insert', value: '/plugin install ' });
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('Given command with subcommands When enter selects it Then command name is inserted', () => {
|
|
58
|
+
const result = resolveEnterCommandSelection('/pl', command('plugin', [command('list')]));
|
|
59
|
+
|
|
60
|
+
expect(result).toEqual({ type: 'insert', value: '/plugin ', selectedIndex: 0 });
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('Given leaf command When enter selects it Then submit value is emitted', () => {
|
|
64
|
+
const result = resolveEnterCommandSelection('/he', command('help'));
|
|
65
|
+
|
|
66
|
+
expect(result).toEqual({ type: 'submit', value: '/help' });
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('Given multiline paste When label change is created Then label is inserted at cursor', () => {
|
|
70
|
+
const result = createPasteLabelChange('abef', 2, 7, 'c\nd\ne');
|
|
71
|
+
|
|
72
|
+
expect(result).toEqual({
|
|
73
|
+
value: 'ab[Pasted text #7 +3 lines]ef',
|
|
74
|
+
cursorHint: 27,
|
|
75
|
+
label: '[Pasted text #7 +3 lines]',
|
|
76
|
+
lineCount: 3,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('Given blank prompt When checked Then submit is rejected', () => {
|
|
81
|
+
expect(shouldSubmitInput(' ')).toBe(false);
|
|
82
|
+
expect(shouldSubmitInput(' hello ')).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('Given prompt history key info When mapped Then history actions are produced', () => {
|
|
86
|
+
expect(getPromptHistoryInputAction({ upArrow: true })).toBe('previous');
|
|
87
|
+
expect(getPromptHistoryInputAction({ downArrow: true })).toBe('next');
|
|
88
|
+
expect(getPromptHistoryInputAction({ escape: true })).toBeUndefined();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('Given empty prompt history When navigating Then input is unchanged', () => {
|
|
92
|
+
const result = navigatePromptHistory(
|
|
93
|
+
'draft',
|
|
94
|
+
[],
|
|
95
|
+
createPromptHistoryNavigationState(),
|
|
96
|
+
'previous',
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
expect(result).toEqual({
|
|
100
|
+
value: 'draft',
|
|
101
|
+
cursorHint: 5,
|
|
102
|
+
state: createPromptHistoryNavigationState(),
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('Given draft and history When pressing up Then latest prompt is recalled and draft is saved', () => {
|
|
107
|
+
const result = navigatePromptHistory(
|
|
108
|
+
'draft text',
|
|
109
|
+
['first', 'second'],
|
|
110
|
+
createPromptHistoryNavigationState(),
|
|
111
|
+
'previous',
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
expect(result).toEqual({
|
|
115
|
+
value: 'second',
|
|
116
|
+
cursorHint: 6,
|
|
117
|
+
state: { selectedIndex: 1, draft: 'draft text' },
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('Given history navigation When pressing down past latest Then draft is restored', () => {
|
|
122
|
+
const result = navigatePromptHistory(
|
|
123
|
+
'second',
|
|
124
|
+
['first', 'second'],
|
|
125
|
+
{ selectedIndex: 1, draft: 'draft text' },
|
|
126
|
+
'next',
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
expect(result).toEqual({
|
|
130
|
+
value: 'draft text',
|
|
131
|
+
cursorHint: 10,
|
|
132
|
+
state: createPromptHistoryNavigationState(),
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('Given prompt submit When appended Then blank and consecutive duplicates are ignored', () => {
|
|
137
|
+
expect(appendPromptHistory(['first'], 'second')).toEqual(['first', 'second']);
|
|
138
|
+
expect(appendPromptHistory(['first'], 'first')).toEqual(['first']);
|
|
139
|
+
expect(appendPromptHistory(['first'], ' ')).toEqual(['first']);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('Given history entries When extracted Then only user chat content is included', () => {
|
|
143
|
+
const entries = [
|
|
144
|
+
messageToHistoryEntry(createUserMessage('first')),
|
|
145
|
+
messageToHistoryEntry(createAssistantMessage('answer')),
|
|
146
|
+
messageToHistoryEntry(createSystemMessage('system')),
|
|
147
|
+
messageToHistoryEntry(createUserMessage('second')),
|
|
148
|
+
];
|
|
149
|
+
|
|
150
|
+
expect(extractPromptHistory(entries)).toEqual(['first', 'second']);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rendering tests for MessageList — verifies that IHistoryEntry[]
|
|
3
|
+
* entries render with correct labels and content.
|
|
4
|
+
*
|
|
5
|
+
* These tests catch rendering bugs that data-flow tests miss:
|
|
6
|
+
* - tool execution list must show "Tool:" label with tool names
|
|
7
|
+
* - chat messages must show correct role labels
|
|
8
|
+
* - event entries must show formatted content
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import { render } from 'ink-testing-library';
|
|
13
|
+
import { describe, it, expect } from 'vitest';
|
|
14
|
+
import MessageList from '../MessageList.js';
|
|
15
|
+
import type { IHistoryEntry } from '@robota-sdk/agent-core';
|
|
16
|
+
import {
|
|
17
|
+
createUserMessage,
|
|
18
|
+
createAssistantMessage,
|
|
19
|
+
createSystemMessage,
|
|
20
|
+
createToolMessage,
|
|
21
|
+
messageToHistoryEntry,
|
|
22
|
+
} from '@robota-sdk/agent-core';
|
|
23
|
+
|
|
24
|
+
function makeToolSummaryEntry(): IHistoryEntry {
|
|
25
|
+
return {
|
|
26
|
+
id: 'tool-1',
|
|
27
|
+
timestamp: new Date(),
|
|
28
|
+
category: 'event',
|
|
29
|
+
type: 'tool-summary',
|
|
30
|
+
data: {
|
|
31
|
+
tools: [
|
|
32
|
+
{ toolName: 'Read', firstArg: 'file.ts', isRunning: false, result: 'success' },
|
|
33
|
+
{ toolName: 'Edit', firstArg: 'file.ts', isRunning: false, result: 'success' },
|
|
34
|
+
],
|
|
35
|
+
summary: '✓ Read(file.ts)\n✓ Edit(file.ts)',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function makeSkillInvocationEntry(): IHistoryEntry {
|
|
41
|
+
return {
|
|
42
|
+
id: 'evt-1',
|
|
43
|
+
timestamp: new Date(),
|
|
44
|
+
category: 'event',
|
|
45
|
+
type: 'skill-activation',
|
|
46
|
+
data: {
|
|
47
|
+
type: 'skill-activation',
|
|
48
|
+
skillName: 'audit',
|
|
49
|
+
source: 'plugin',
|
|
50
|
+
invocation: 'user-slash',
|
|
51
|
+
mode: 'inject',
|
|
52
|
+
status: 'started',
|
|
53
|
+
timestamp: '2026-05-06T00:00:00.000Z',
|
|
54
|
+
message: 'Invoking plugin skill: audit',
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
describe('MessageList rendering', () => {
|
|
60
|
+
// ── Tool summary rendering ────────────────────────────────────
|
|
61
|
+
|
|
62
|
+
it('tool execution list renders with "Tool:" label and tool names', () => {
|
|
63
|
+
const history: IHistoryEntry[] = [makeToolSummaryEntry()];
|
|
64
|
+
const { lastFrame } = render(<MessageList history={history} />);
|
|
65
|
+
const output = lastFrame() ?? '';
|
|
66
|
+
|
|
67
|
+
expect(output).toContain('Tool:');
|
|
68
|
+
expect(output).toContain('Read(file.ts)');
|
|
69
|
+
expect(output).toContain('Edit(file.ts)');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// ── Skill invocation rendering ────────────────────────────────
|
|
73
|
+
|
|
74
|
+
it('skill-activation event renders with "System:" label and message', () => {
|
|
75
|
+
const history: IHistoryEntry[] = [makeSkillInvocationEntry()];
|
|
76
|
+
const { lastFrame } = render(<MessageList history={history} />);
|
|
77
|
+
const output = lastFrame() ?? '';
|
|
78
|
+
|
|
79
|
+
expect(output).toContain('System:');
|
|
80
|
+
expect(output).toContain('Invoking plugin skill: audit');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// ── Chat message rendering ────────────────────────────────────
|
|
84
|
+
|
|
85
|
+
it('user message renders with "You:" label', () => {
|
|
86
|
+
const history: IHistoryEntry[] = [messageToHistoryEntry(createUserMessage('hello'))];
|
|
87
|
+
const { lastFrame } = render(<MessageList history={history} />);
|
|
88
|
+
const output = lastFrame() ?? '';
|
|
89
|
+
|
|
90
|
+
expect(output).toContain('You:');
|
|
91
|
+
expect(output).toContain('hello');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('assistant message renders with "Robota:" label', () => {
|
|
95
|
+
const history: IHistoryEntry[] = [
|
|
96
|
+
messageToHistoryEntry(createAssistantMessage('response text')),
|
|
97
|
+
];
|
|
98
|
+
const { lastFrame } = render(<MessageList history={history} />);
|
|
99
|
+
const output = lastFrame() ?? '';
|
|
100
|
+
|
|
101
|
+
expect(output).toContain('Robota:');
|
|
102
|
+
expect(output).toContain('response text');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('assistant message preserves CJK and emoji content', () => {
|
|
106
|
+
const content = '긴 한국어 응답과 emoji 🎉 를 표시합니다';
|
|
107
|
+
const history: IHistoryEntry[] = [messageToHistoryEntry(createAssistantMessage(content))];
|
|
108
|
+
const { lastFrame } = render(<MessageList history={history} />);
|
|
109
|
+
|
|
110
|
+
expect(lastFrame()).toContain(content);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('assistant message renders markdown diff fenced code block content', () => {
|
|
114
|
+
const response = [
|
|
115
|
+
'Patch preview:',
|
|
116
|
+
'',
|
|
117
|
+
'```diff',
|
|
118
|
+
'- const oldValue = true;',
|
|
119
|
+
'+ const newValue = true;',
|
|
120
|
+
'```',
|
|
121
|
+
].join('\n');
|
|
122
|
+
const history: IHistoryEntry[] = [messageToHistoryEntry(createAssistantMessage(response))];
|
|
123
|
+
const { lastFrame } = render(<MessageList history={history} />);
|
|
124
|
+
const output = lastFrame() ?? '';
|
|
125
|
+
|
|
126
|
+
expect(output).toContain('Robota:');
|
|
127
|
+
expect(output).toContain('Patch preview:');
|
|
128
|
+
expect(output).toContain('- const oldValue = true;');
|
|
129
|
+
expect(output).toContain('+ const newValue = true;');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('tool message diff summary renders through markdown diff body format', () => {
|
|
133
|
+
const toolSummary = [
|
|
134
|
+
{
|
|
135
|
+
line: 'Edit(/src/index.ts)',
|
|
136
|
+
diffFile: '/src/index.ts',
|
|
137
|
+
diffLines: [
|
|
138
|
+
{ type: 'remove', lineNumber: 1, text: 'const oldValue = true;' },
|
|
139
|
+
{ type: 'add', lineNumber: 1, text: 'const newValue = true;' },
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
];
|
|
143
|
+
const history: IHistoryEntry[] = [
|
|
144
|
+
messageToHistoryEntry(
|
|
145
|
+
createToolMessage(JSON.stringify(toolSummary), {
|
|
146
|
+
toolCallId: 'call_1',
|
|
147
|
+
name: 'tools',
|
|
148
|
+
}),
|
|
149
|
+
),
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
const { lastFrame } = render(<MessageList history={history} />);
|
|
153
|
+
const output = lastFrame() ?? '';
|
|
154
|
+
|
|
155
|
+
expect(output).toContain('/src/index.ts');
|
|
156
|
+
expect(output).toContain('- 1 | const oldValue = true;');
|
|
157
|
+
expect(output).toContain('+ 1 | const newValue = true;');
|
|
158
|
+
expect(output).not.toContain('│ 1 - const oldValue = true;');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('tool-summary event renders persisted edit diff metadata', () => {
|
|
162
|
+
const history: IHistoryEntry[] = [
|
|
163
|
+
{
|
|
164
|
+
id: 'summary_1',
|
|
165
|
+
timestamp: new Date(),
|
|
166
|
+
category: 'event',
|
|
167
|
+
type: 'tool-summary',
|
|
168
|
+
data: {
|
|
169
|
+
tools: [
|
|
170
|
+
{
|
|
171
|
+
toolName: 'Edit',
|
|
172
|
+
firstArg: '/src/index.ts',
|
|
173
|
+
isRunning: false,
|
|
174
|
+
result: 'success',
|
|
175
|
+
diffFile: '/src/index.ts',
|
|
176
|
+
diffLines: [
|
|
177
|
+
{ type: 'remove', lineNumber: 1, text: 'const temporary = true;' },
|
|
178
|
+
{ type: 'add', lineNumber: 1, text: 'const original = true;' },
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
summary: '✓ Edit(/src/index.ts)',
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
];
|
|
186
|
+
|
|
187
|
+
const { lastFrame } = render(<MessageList history={history} />);
|
|
188
|
+
const output = lastFrame() ?? '';
|
|
189
|
+
|
|
190
|
+
expect(output).toContain('/src/index.ts');
|
|
191
|
+
expect(output).toContain('- 1 | const temporary = true;');
|
|
192
|
+
expect(output).toContain('+ 1 | const original = true;');
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('tool-summary event collapses long command output with transcript hint', () => {
|
|
196
|
+
const commandOutput = Array.from({ length: 7 }, (_, index) => `line-${index + 1}`).join('\n');
|
|
197
|
+
const history: IHistoryEntry[] = [
|
|
198
|
+
{
|
|
199
|
+
id: 'summary_command_long',
|
|
200
|
+
timestamp: new Date(),
|
|
201
|
+
category: 'event',
|
|
202
|
+
type: 'tool-summary',
|
|
203
|
+
data: {
|
|
204
|
+
tools: [
|
|
205
|
+
{
|
|
206
|
+
toolName: 'Bash',
|
|
207
|
+
firstArg: 'pnpm test',
|
|
208
|
+
isRunning: false,
|
|
209
|
+
result: 'success',
|
|
210
|
+
toolResultData: JSON.stringify({
|
|
211
|
+
success: true,
|
|
212
|
+
output: commandOutput,
|
|
213
|
+
exitCode: 0,
|
|
214
|
+
}),
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
summary: '✓ Bash(pnpm test)',
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
];
|
|
221
|
+
|
|
222
|
+
const { lastFrame } = render(<MessageList history={history} />);
|
|
223
|
+
const output = lastFrame() ?? '';
|
|
224
|
+
|
|
225
|
+
expect(output).toContain('✓ Bash(pnpm test)');
|
|
226
|
+
expect(output).toContain('line-1');
|
|
227
|
+
expect(output).toContain('line-4');
|
|
228
|
+
expect(output).not.toContain('line-5');
|
|
229
|
+
expect(output).toContain('... +3 lines (full output in session transcript)');
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('tool-summary event marks non-zero command exits as failed', () => {
|
|
233
|
+
const history: IHistoryEntry[] = [
|
|
234
|
+
{
|
|
235
|
+
id: 'summary_command_failed',
|
|
236
|
+
timestamp: new Date(),
|
|
237
|
+
category: 'event',
|
|
238
|
+
type: 'tool-summary',
|
|
239
|
+
data: {
|
|
240
|
+
tools: [
|
|
241
|
+
{
|
|
242
|
+
toolName: 'Bash',
|
|
243
|
+
firstArg: 'exit 42',
|
|
244
|
+
isRunning: false,
|
|
245
|
+
result: 'success',
|
|
246
|
+
toolResultData: JSON.stringify({ success: true, output: '', exitCode: 42 }),
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
summary: '✓ Bash(exit 42)',
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
];
|
|
253
|
+
|
|
254
|
+
const { lastFrame } = render(<MessageList history={history} />);
|
|
255
|
+
const output = lastFrame() ?? '';
|
|
256
|
+
|
|
257
|
+
expect(output).toContain('✗ Bash(exit 42)');
|
|
258
|
+
expect(output).toContain('exit 42');
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('usage-summary event renders compact token and cost visibility', () => {
|
|
262
|
+
const history: IHistoryEntry[] = [
|
|
263
|
+
{
|
|
264
|
+
id: 'usage_1',
|
|
265
|
+
timestamp: new Date(),
|
|
266
|
+
category: 'event',
|
|
267
|
+
type: 'usage-summary',
|
|
268
|
+
data: {
|
|
269
|
+
kind: 'exact',
|
|
270
|
+
scope: 'turn',
|
|
271
|
+
promptTokens: 100,
|
|
272
|
+
completionTokens: 50,
|
|
273
|
+
totalTokens: 150,
|
|
274
|
+
contextUsedTokens: 150,
|
|
275
|
+
contextMaxTokens: 1000,
|
|
276
|
+
contextUsedPercentage: 15,
|
|
277
|
+
costStatus: 'unknown',
|
|
278
|
+
},
|
|
279
|
+
},
|
|
280
|
+
];
|
|
281
|
+
|
|
282
|
+
const { lastFrame } = render(<MessageList history={history} />);
|
|
283
|
+
const output = lastFrame() ?? '';
|
|
284
|
+
|
|
285
|
+
expect(output).toContain('Usage:');
|
|
286
|
+
expect(output).toContain('exact');
|
|
287
|
+
expect(output).toContain('150 tokens');
|
|
288
|
+
expect(output).toContain('in 100');
|
|
289
|
+
expect(output).toContain('out 50');
|
|
290
|
+
expect(output).toContain('cost unknown');
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it('system message renders with "System:" label', () => {
|
|
294
|
+
const history: IHistoryEntry[] = [
|
|
295
|
+
messageToHistoryEntry(createSystemMessage('Interrupted by user.')),
|
|
296
|
+
];
|
|
297
|
+
const { lastFrame } = render(<MessageList history={history} />);
|
|
298
|
+
const output = lastFrame() ?? '';
|
|
299
|
+
|
|
300
|
+
expect(output).toContain('System:');
|
|
301
|
+
expect(output).toContain('Interrupted by user.');
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
// ── Display order after abort ─────────────────────────────────
|
|
305
|
+
|
|
306
|
+
it('abort display order: You → Tool → Robota → System', () => {
|
|
307
|
+
const history: IHistoryEntry[] = [
|
|
308
|
+
messageToHistoryEntry(createUserMessage('/audit')),
|
|
309
|
+
makeToolSummaryEntry(),
|
|
310
|
+
messageToHistoryEntry(createAssistantMessage('partial response')),
|
|
311
|
+
messageToHistoryEntry(createSystemMessage('Interrupted by user.')),
|
|
312
|
+
];
|
|
313
|
+
|
|
314
|
+
const { lastFrame } = render(<MessageList history={history} />);
|
|
315
|
+
const output = lastFrame() ?? '';
|
|
316
|
+
|
|
317
|
+
const youIdx = output.indexOf('You:');
|
|
318
|
+
const toolIdx = output.indexOf('Tool:');
|
|
319
|
+
const robotaIdx = output.indexOf('Robota:');
|
|
320
|
+
const systemIdx = output.indexOf('Interrupted by user.');
|
|
321
|
+
|
|
322
|
+
// All must be present
|
|
323
|
+
expect(youIdx).toBeGreaterThanOrEqual(0);
|
|
324
|
+
expect(toolIdx).toBeGreaterThanOrEqual(0);
|
|
325
|
+
expect(robotaIdx).toBeGreaterThanOrEqual(0);
|
|
326
|
+
expect(systemIdx).toBeGreaterThanOrEqual(0);
|
|
327
|
+
|
|
328
|
+
// Order: You → Tool → Robota → System
|
|
329
|
+
expect(youIdx).toBeLessThan(toolIdx);
|
|
330
|
+
expect(toolIdx).toBeLessThan(robotaIdx);
|
|
331
|
+
expect(robotaIdx).toBeLessThan(systemIdx);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
// ── Mixed history ─────────────────────────────────────────────
|
|
335
|
+
|
|
336
|
+
it('renders mixed chat and event entries in order', () => {
|
|
337
|
+
const history: IHistoryEntry[] = [
|
|
338
|
+
messageToHistoryEntry(createUserMessage('hello')),
|
|
339
|
+
makeSkillInvocationEntry(),
|
|
340
|
+
makeToolSummaryEntry(),
|
|
341
|
+
messageToHistoryEntry(createAssistantMessage('done')),
|
|
342
|
+
];
|
|
343
|
+
|
|
344
|
+
const { lastFrame } = render(<MessageList history={history} />);
|
|
345
|
+
const output = lastFrame() ?? '';
|
|
346
|
+
|
|
347
|
+
// All four entries rendered
|
|
348
|
+
expect(output).toContain('You:');
|
|
349
|
+
expect(output).toContain('Invoking plugin skill: audit');
|
|
350
|
+
expect(output).toContain('Tool:');
|
|
351
|
+
expect(output).toContain('Robota:');
|
|
352
|
+
});
|
|
353
|
+
});
|