@robota-sdk/agent-transport 3.0.0-beta.74 → 3.0.0-beta.76

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.
Files changed (197) hide show
  1. package/README.md +10 -10
  2. package/dist/node/headless/index.cjs +1 -1
  3. package/dist/node/headless/index.d.ts +1 -1
  4. package/dist/node/headless/index.js +1 -1
  5. package/dist/node/headless-OnpVk4-k.cjs +15 -0
  6. package/dist/node/{headless-D02zUEGh.js → headless-mRYilLfC.js} +2 -2
  7. package/dist/node/{headless-D02zUEGh.js.map → headless-mRYilLfC.js.map} +1 -1
  8. package/dist/node/{index-DE3-dHqw.d.ts → index-CYl7ksS6.d.ts} +12 -2
  9. package/dist/node/{index-DE3-dHqw.d.ts.map → index-CYl7ksS6.d.ts.map} +1 -1
  10. package/dist/node/{index-WKTgvhlg.d.ts → index-E8Gx4-lc.d.ts} +12 -2
  11. package/dist/node/{index-WKTgvhlg.d.ts.map → index-E8Gx4-lc.d.ts.map} +1 -1
  12. package/dist/node/index.cjs +1 -1
  13. package/dist/node/index.d.ts +2 -7
  14. package/dist/node/index.d.ts.map +1 -1
  15. package/dist/node/index.js +1 -1
  16. package/dist/node/index.js.map +1 -1
  17. package/package.json +7 -75
  18. package/src/headless/HeadlessInteractionChannel.ts +21 -1
  19. package/src/index.ts +1 -5
  20. package/src/transport-registry.ts +0 -9
  21. package/dist/node/headless-BeHAOlIM.cjs +0 -15
  22. package/dist/node/http/index.cjs +0 -1
  23. package/dist/node/http/index.d.ts +0 -2
  24. package/dist/node/http/index.js +0 -1
  25. package/dist/node/http-2Jiuflc1.js +0 -2
  26. package/dist/node/http-2Jiuflc1.js.map +0 -1
  27. package/dist/node/http-CBAvefLw.cjs +0 -1
  28. package/dist/node/index-BQLN_Lc9.d.ts +0 -78
  29. package/dist/node/index-BQLN_Lc9.d.ts.map +0 -1
  30. package/dist/node/index-BnAGE-u9.d.ts +0 -33
  31. package/dist/node/index-BnAGE-u9.d.ts.map +0 -1
  32. package/dist/node/index-BrQ4gGw0.d.ts +0 -213
  33. package/dist/node/index-BrQ4gGw0.d.ts.map +0 -1
  34. package/dist/node/index-CoeBF21y.d.ts +0 -213
  35. package/dist/node/index-CoeBF21y.d.ts.map +0 -1
  36. package/dist/node/index-DHt-2VQ-.d.ts +0 -46
  37. package/dist/node/index-DHt-2VQ-.d.ts.map +0 -1
  38. package/dist/node/index-DMwKN5Le.d.ts +0 -33
  39. package/dist/node/index-DMwKN5Le.d.ts.map +0 -1
  40. package/dist/node/index-IvYaYY6v.d.ts +0 -78
  41. package/dist/node/index-IvYaYY6v.d.ts.map +0 -1
  42. package/dist/node/index-c0M42fsA.d.ts +0 -46
  43. package/dist/node/index-c0M42fsA.d.ts.map +0 -1
  44. package/dist/node/mcp/index.cjs +0 -1
  45. package/dist/node/mcp/index.d.ts +0 -2
  46. package/dist/node/mcp/index.js +0 -1
  47. package/dist/node/mcp-BOglBJNy.cjs +0 -1
  48. package/dist/node/mcp-D3BBVK7C.js +0 -2
  49. package/dist/node/mcp-D3BBVK7C.js.map +0 -1
  50. package/dist/node/rolldown-runtime-CMqjfN_6.cjs +0 -1
  51. package/dist/node/tui/index.cjs +0 -1
  52. package/dist/node/tui/index.d.ts +0 -2
  53. package/dist/node/tui/index.js +0 -1
  54. package/dist/node/tui-Btb1q88j.js +0 -25
  55. package/dist/node/tui-Btb1q88j.js.map +0 -1
  56. package/dist/node/tui-SbUT7Zlt.cjs +0 -24
  57. package/dist/node/ws/index.cjs +0 -1
  58. package/dist/node/ws/index.d.ts +0 -2
  59. package/dist/node/ws/index.js +0 -1
  60. package/dist/node/ws-Dc2RUwVs.js +0 -2
  61. package/dist/node/ws-Dc2RUwVs.js.map +0 -1
  62. package/dist/node/ws-QNMQn5kg.cjs +0 -1
  63. package/src/http/__tests__/http-transport.test.ts +0 -55
  64. package/src/http/__tests__/routes.test.ts +0 -168
  65. package/src/http/http-transport.ts +0 -41
  66. package/src/http/index.ts +0 -4
  67. package/src/http/routes.ts +0 -152
  68. package/src/mcp/__tests__/mcp-server.test.ts +0 -66
  69. package/src/mcp/__tests__/mcp-transport.test.ts +0 -46
  70. package/src/mcp/index.ts +0 -4
  71. package/src/mcp/mcp-server.ts +0 -163
  72. package/src/mcp/mcp-transport.ts +0 -48
  73. package/src/tui/App.tsx +0 -488
  74. package/src/tui/BackgroundTaskPanel.tsx +0 -36
  75. package/src/tui/CjkTextInput.tsx +0 -199
  76. package/src/tui/ConfirmPrompt.tsx +0 -70
  77. package/src/tui/ContextWarningBanner.tsx +0 -34
  78. package/src/tui/ExecutionWorkspaceDetailPane.tsx +0 -64
  79. package/src/tui/ExecutionWorkspaceSwitcher.tsx +0 -187
  80. package/src/tui/InputArea.tsx +0 -310
  81. package/src/tui/InteractivePrompt.tsx +0 -59
  82. package/src/tui/ListPicker.tsx +0 -95
  83. package/src/tui/MenuSelect.tsx +0 -104
  84. package/src/tui/MessageList.tsx +0 -284
  85. package/src/tui/PermissionPrompt.tsx +0 -86
  86. package/src/tui/PluginTUI.tsx +0 -258
  87. package/src/tui/SessionPicker.tsx +0 -68
  88. package/src/tui/SessionStatusBar.tsx +0 -70
  89. package/src/tui/SlashAutocomplete.tsx +0 -110
  90. package/src/tui/StatusBar.tsx +0 -209
  91. package/src/tui/StreamingIndicator.tsx +0 -93
  92. package/src/tui/TextPrompt.tsx +0 -81
  93. package/src/tui/ToolCommandOutput.tsx +0 -39
  94. package/src/tui/ToolDiffBlock.tsx +0 -32
  95. package/src/tui/TransportTUI.tsx +0 -117
  96. package/src/tui/TuiInteractionChannel.ts +0 -483
  97. package/src/tui/UpdateNotice.tsx +0 -14
  98. package/src/tui/UsageSummaryEntry.tsx +0 -39
  99. package/src/tui/WaveText.tsx +0 -44
  100. package/src/tui/__tests__/InteractivePrompt.test.tsx +0 -82
  101. package/src/tui/__tests__/ListPicker.test.tsx +0 -159
  102. package/src/tui/__tests__/MenuSelect.test.tsx +0 -103
  103. package/src/tui/__tests__/PluginTUI.test.tsx +0 -167
  104. package/src/tui/__tests__/SlashAutocomplete.test.tsx +0 -140
  105. package/src/tui/__tests__/TextPrompt.test.tsx +0 -98
  106. package/src/tui/__tests__/TuiInteractionChannel.display-contract.test.ts +0 -239
  107. package/src/tui/__tests__/TuiInteractionChannel.lifecycle.test.ts +0 -297
  108. package/src/tui/__tests__/TuiInteractionChannel.requestAction.test.ts +0 -124
  109. package/src/tui/__tests__/UpdateNotice.test.tsx +0 -15
  110. package/src/tui/__tests__/abort-after-permission.test.tsx +0 -169
  111. package/src/tui/__tests__/abort-streaming-e2e.test.tsx +0 -183
  112. package/src/tui/__tests__/background-task-panel.test.tsx +0 -53
  113. package/src/tui/__tests__/background-task-row-format.test.ts +0 -59
  114. package/src/tui/__tests__/channel-factory-integration.test.ts +0 -138
  115. package/src/tui/__tests__/cjk-text-input-flow.test.ts +0 -109
  116. package/src/tui/__tests__/cjk-text-input.test.ts +0 -191
  117. package/src/tui/__tests__/command-effect-handler.test.ts +0 -127
  118. package/src/tui/__tests__/command-output-summary.test.ts +0 -95
  119. package/src/tui/__tests__/compact-event-bridge.test.ts +0 -20
  120. package/src/tui/__tests__/confirm-permission-flow.test.ts +0 -130
  121. package/src/tui/__tests__/confirm-prompt.test.tsx +0 -87
  122. package/src/tui/__tests__/execution-workspace-switcher.test.tsx +0 -110
  123. package/src/tui/__tests__/execution-workspace-view-model.test.ts +0 -93
  124. package/src/tui/__tests__/fixtures/provider-setup-prompt-driver.tsx +0 -125
  125. package/src/tui/__tests__/input-area-flow.test.ts +0 -164
  126. package/src/tui/__tests__/message-list-rendering.test.tsx +0 -353
  127. package/src/tui/__tests__/prompt-queue.test.tsx +0 -255
  128. package/src/tui/__tests__/provider-setup-pty-e2e.test.ts +0 -233
  129. package/src/tui/__tests__/pty/pty-driver.ts +0 -135
  130. package/src/tui/__tests__/pty/tui-pty.ptytest.ts +0 -61
  131. package/src/tui/__tests__/render-channel-options.test.ts +0 -32
  132. package/src/tui/__tests__/render-markdown.test.ts +0 -72
  133. package/src/tui/__tests__/selection-flow.test.ts +0 -61
  134. package/src/tui/__tests__/session-init-poller.test.ts +0 -102
  135. package/src/tui/__tests__/session-naming.test.ts +0 -64
  136. package/src/tui/__tests__/session-switch-channel.test.tsx +0 -307
  137. package/src/tui/__tests__/slash-routing-effects.test.ts +0 -228
  138. package/src/tui/__tests__/status-activity.test.ts +0 -71
  139. package/src/tui/__tests__/status-bar.test.tsx +0 -158
  140. package/src/tui/__tests__/streaming-indicator.test.tsx +0 -137
  141. package/src/tui/__tests__/text-prompt-flow.test.ts +0 -77
  142. package/src/tui/__tests__/tui-channel-init-failure.test.ts +0 -57
  143. package/src/tui/__tests__/tui-state-manager.test.ts +0 -401
  144. package/src/tui/background-task-row-format.ts +0 -53
  145. package/src/tui/command-interaction.ts +0 -9
  146. package/src/tui/command-output-summary.ts +0 -122
  147. package/src/tui/create-default-tui-cli-adapter.ts +0 -41
  148. package/src/tui/execution-workspace-view-model.ts +0 -123
  149. package/src/tui/flows/cjk-text-input-flow.ts +0 -285
  150. package/src/tui/flows/confirm-prompt-flow.ts +0 -45
  151. package/src/tui/flows/input-area-flow.ts +0 -189
  152. package/src/tui/flows/permission-prompt-flow.ts +0 -85
  153. package/src/tui/flows/selection-flow.ts +0 -126
  154. package/src/tui/flows/session-init-poller.ts +0 -77
  155. package/src/tui/flows/text-prompt-flow.ts +0 -98
  156. package/src/tui/hooks/command-effect-handler.ts +0 -97
  157. package/src/tui/hooks/command-effect-queue.ts +0 -39
  158. package/src/tui/hooks/side-effects-types.ts +0 -35
  159. package/src/tui/hooks/useAutocomplete.ts +0 -87
  160. package/src/tui/hooks/usePluginCallbacks.ts +0 -31
  161. package/src/tui/hooks/usePluginScreenData.ts +0 -85
  162. package/src/tui/hooks/useSideEffects.ts +0 -175
  163. package/src/tui/hooks/useSlashRouting.ts +0 -118
  164. package/src/tui/hooks/useStatusLineSettings.ts +0 -37
  165. package/src/tui/hooks/useTuiChannel.ts +0 -95
  166. package/src/tui/index.ts +0 -14
  167. package/src/tui/interactions/CommandConfirm.tsx +0 -36
  168. package/src/tui/interactions/CommandPicker.tsx +0 -77
  169. package/src/tui/interactions/__tests__/CommandConfirm.test.tsx +0 -124
  170. package/src/tui/interactions/__tests__/CommandPicker.test.tsx +0 -138
  171. package/src/tui/plugin-tui-handlers.ts +0 -163
  172. package/src/tui/render-markdown.ts +0 -130
  173. package/src/tui/render.tsx +0 -117
  174. package/src/tui/session-naming.ts +0 -33
  175. package/src/tui/status-activity.ts +0 -63
  176. package/src/tui/tui-cli-adapter-context.tsx +0 -13
  177. package/src/tui/tui-cli-adapter.ts +0 -25
  178. package/src/tui/tui-state-manager.ts +0 -226
  179. package/src/tui/tui-transport.ts +0 -35
  180. package/src/tui/types.ts +0 -15
  181. package/src/tui/utils/__tests__/edit-diff.test.ts +0 -426
  182. package/src/tui/utils/__tests__/paste-detection.test.ts +0 -116
  183. package/src/tui/utils/__tests__/paste-labels.test.ts +0 -46
  184. package/src/tui/utils/__tests__/tool-call-extractor.test.ts +0 -227
  185. package/src/tui/utils/__tests__/tool-diff-summary.test.ts +0 -104
  186. package/src/tui/utils/edit-diff.ts +0 -153
  187. package/src/tui/utils/paste-labels.ts +0 -9
  188. package/src/tui/utils/tool-call-extractor.ts +0 -92
  189. package/src/tui/utils/tool-diff-summary.ts +0 -75
  190. package/src/ws/__tests__/ws-handler.test.ts +0 -409
  191. package/src/ws/__tests__/ws-transport.test.ts +0 -53
  192. package/src/ws/index.ts +0 -13
  193. package/src/ws/ws-background-messages.ts +0 -170
  194. package/src/ws/ws-handler.ts +0 -280
  195. package/src/ws/ws-protocol.ts +0 -78
  196. package/src/ws/ws-transport-configurable.ts +0 -128
  197. package/src/ws/ws-transport.ts +0 -42
@@ -1,85 +0,0 @@
1
- /**
2
- * Hook: fetch data for PluginTUI screens.
3
- * Extracted from PluginTUI.tsx for single-responsibility.
4
- */
5
-
6
- import { useState, useEffect } from 'react';
7
-
8
- import type { IMenuSelectItem } from '../MenuSelect.js';
9
- import type { ICommandPluginAdapter } from '@robota-sdk/agent-interface-transport';
10
-
11
- export function usePluginScreenData(
12
- screen: string,
13
- marketplace: string | undefined,
14
- callbacks: ICommandPluginAdapter,
15
- refreshCounter: number,
16
- stackLength: number,
17
- ): { items: IMenuSelectItem[]; loading: boolean; error: string | undefined } {
18
- const [items, setItems] = useState<IMenuSelectItem[]>([]);
19
- const [loading, setLoading] = useState(false);
20
- const [error, setError] = useState<string | undefined>();
21
-
22
- useEffect(() => {
23
- setItems([]);
24
- setError(undefined);
25
-
26
- if (screen === 'marketplace-list') {
27
- setLoading(true);
28
- callbacks
29
- .marketplaceList()
30
- .then((sources) => {
31
- const baseItems: IMenuSelectItem[] = [{ label: 'Add Marketplace', value: '__add__' }];
32
- const sourceItems: IMenuSelectItem[] = sources.map((s) => ({
33
- label: s.name,
34
- value: s.name,
35
- hint: s.type,
36
- }));
37
- setItems([...baseItems, ...sourceItems]);
38
- setLoading(false);
39
- })
40
- .catch((err) => {
41
- setError(err instanceof Error ? err.message : String(err));
42
- setLoading(false);
43
- });
44
- } else if (screen === 'marketplace-browse') {
45
- const mp = marketplace ?? '';
46
- setLoading(true);
47
- callbacks
48
- .listAvailablePlugins(mp)
49
- .then((plugins) => {
50
- setItems(
51
- plugins.map((p) => ({
52
- label: p.name,
53
- value: p.name,
54
- hint: p.installed ? 'installed' : p.description,
55
- })),
56
- );
57
- setLoading(false);
58
- })
59
- .catch((err) => {
60
- setError(err instanceof Error ? err.message : String(err));
61
- setLoading(false);
62
- });
63
- } else if (screen === 'installed-list') {
64
- setLoading(true);
65
- callbacks
66
- .listInstalled()
67
- .then((plugins) => {
68
- setItems(
69
- plugins.map((p) => ({
70
- label: p.name,
71
- value: p.name,
72
- hint: p.description,
73
- })),
74
- );
75
- setLoading(false);
76
- })
77
- .catch((err) => {
78
- setError(err instanceof Error ? err.message : String(err));
79
- setLoading(false);
80
- });
81
- }
82
- }, [stackLength, screen, marketplace, callbacks, refreshCounter]);
83
-
84
- return { items, loading, error };
85
- }
@@ -1,175 +0,0 @@
1
- import { createSystemMessage, messageToHistoryEntry } from '@robota-sdk/agent-core';
2
- import { useApp } from 'ink';
3
- import { useState, useRef, useCallback } from 'react';
4
-
5
- import { applyCommandEffects } from './command-effect-handler.js';
6
- import { useTuiCliAdapter } from '../tui-cli-adapter-context.js';
7
-
8
- import type { IUseSideEffectsOptions, IUseSideEffectsResult } from './side-effects-types.js';
9
- import type { TInteractivePrompt } from './side-effects-types.js';
10
- import type { TSessionEndReason } from '@robota-sdk/agent-core';
11
- import type { ICommandInteraction, ICommandResult } from '@robota-sdk/agent-interface-transport';
12
-
13
- const EXIT_DELAY_MS = 500;
14
-
15
- export function useSideEffects({
16
- cwd,
17
- providerOverride,
18
- interactiveSession,
19
- commandEffectQueue,
20
- addEntry,
21
- baseHandleSubmit,
22
- setSessionName,
23
- setStatusLineSettings,
24
- showSessionPickerOnStart,
25
- openAgentSwitcher,
26
- }: IUseSideEffectsOptions): IUseSideEffectsResult {
27
- const { exit } = useApp();
28
- const cliAdapter = useTuiCliAdapter();
29
- const [pendingInteractionPrompt, setPendingInteractionPrompt] =
30
- useState<TInteractivePrompt | null>(null);
31
- const commandInteractionRef = useRef<ICommandInteraction | null>(null);
32
- const [showPluginTUI, setShowPluginTUI] = useState(false);
33
- const [showSessionPicker, setShowSessionPicker] = useState(showSessionPickerOnStart ?? false);
34
- const [showTransportTUI, setShowTransportTUI] = useState(false);
35
-
36
- const requestShutdown = useCallback(
37
- (reason: TSessionEndReason, message: string): void => {
38
- addEntry(messageToHistoryEntry(createSystemMessage('Shutting down...')));
39
- setTimeout(() => {
40
- void interactiveSession.shutdown({ reason, message }).finally(() => exit());
41
- }, EXIT_DELAY_MS);
42
- },
43
- [interactiveSession, addEntry, exit],
44
- );
45
-
46
- const applyEffects = useCallback(
47
- (effects: Parameters<typeof applyCommandEffects>[0]): boolean =>
48
- applyCommandEffects(effects, {
49
- addEntry,
50
- requestShutdown,
51
- openPluginTUI: () => setShowPluginTUI(true),
52
- openSessionPicker: () => setShowSessionPicker(true),
53
- openTransportTUI: () => setShowTransportTUI(true),
54
- openAgentSwitcher: () => openAgentSwitcher?.(),
55
- renameSession: (name) => {
56
- interactiveSession.setName(name);
57
- setSessionName(name);
58
- },
59
- applyStatusLinePatch: (patch) => {
60
- setStatusLineSettings(
61
- cliAdapter.applyStatusLineSettings(cliAdapter.getUserSettingsPath(), patch),
62
- );
63
- return true;
64
- },
65
- cliAdapter,
66
- }),
67
- [
68
- addEntry,
69
- cliAdapter,
70
- interactiveSession,
71
- requestShutdown,
72
- setSessionName,
73
- setStatusLineSettings,
74
- ],
75
- );
76
-
77
- const applyCommandResult = useCallback(
78
- (result: ICommandResult): void => {
79
- if (result.message.length > 0) {
80
- addEntry(messageToHistoryEntry(createSystemMessage(result.message)));
81
- }
82
- if (result.interaction !== undefined) {
83
- commandInteractionRef.current = result.interaction;
84
- setPendingInteractionPrompt(result.interaction.prompt);
85
- return;
86
- }
87
- commandInteractionRef.current = null;
88
- setPendingInteractionPrompt(null);
89
- if (result.effects !== undefined && result.effects.length > 0) {
90
- applyEffects(result.effects);
91
- }
92
- },
93
- [addEntry, applyEffects],
94
- );
95
-
96
- const applyQueuedCommandState = useCallback((): boolean => {
97
- const queued = commandEffectQueue.drain();
98
- if (queued === undefined) {
99
- return false;
100
- }
101
- if (queued.type === 'interaction') {
102
- const { interaction } = queued;
103
- commandInteractionRef.current = interaction;
104
- setPendingInteractionPrompt(interaction.prompt);
105
- return true;
106
- }
107
- return applyEffects(queued.effects);
108
- }, [applyEffects, commandEffectQueue]);
109
-
110
- const handleSubmit = useCallback(
111
- async (input: string): Promise<void> => {
112
- await baseHandleSubmit(input);
113
- applyQueuedCommandState();
114
- },
115
- [baseHandleSubmit, applyQueuedCommandState],
116
- );
117
-
118
- const handleInteractionSubmit = useCallback(
119
- async (value: string): Promise<void> => {
120
- const interaction = commandInteractionRef.current;
121
- if (interaction === null) {
122
- setPendingInteractionPrompt(null);
123
- return;
124
- }
125
- try {
126
- // allow-fallback: user-facing error display for plugin interaction submit
127
- const result = await interaction.submit(value);
128
- applyCommandResult(result);
129
- } catch (err) {
130
- // allow-fallback: user-facing error display for plugin interaction submit
131
- commandInteractionRef.current = null;
132
- setPendingInteractionPrompt(null);
133
- addEntry(
134
- messageToHistoryEntry(
135
- createSystemMessage(`Failed: ${err instanceof Error ? err.message : String(err)}`),
136
- ),
137
- );
138
- }
139
- },
140
- [addEntry, applyCommandResult],
141
- );
142
-
143
- const handleInteractionCancel = useCallback(() => {
144
- const interaction = commandInteractionRef.current;
145
- commandInteractionRef.current = null;
146
- setPendingInteractionPrompt(null);
147
- if (interaction?.cancel === undefined) {
148
- addEntry(messageToHistoryEntry(createSystemMessage('Command interaction cancelled.')));
149
- return;
150
- }
151
- Promise.resolve(interaction.cancel())
152
- .then((result) => applyCommandResult(result))
153
- .catch((err) => {
154
- // allow-fallback: user-facing error display for interaction cancel
155
- addEntry(
156
- messageToHistoryEntry(
157
- createSystemMessage(`Failed: ${err instanceof Error ? err.message : String(err)}`),
158
- ),
159
- );
160
- });
161
- }, [addEntry, applyCommandResult]);
162
-
163
- return {
164
- handleSubmit,
165
- pendingInteractionPrompt,
166
- showPluginTUI,
167
- showSessionPicker,
168
- showTransportTUI,
169
- setShowPluginTUI,
170
- setShowSessionPicker,
171
- setShowTransportTUI,
172
- handleInteractionSubmit,
173
- handleInteractionCancel,
174
- };
175
- }
@@ -1,118 +0,0 @@
1
- /**
2
- * Slash command routing logic for the TUI.
3
- * Extracted for single-responsibility.
4
- */
5
-
6
- import { createSystemMessage, messageToHistoryEntry } from '@robota-sdk/agent-core';
7
- import { useCallback } from 'react';
8
-
9
- import type { TuiStateManager } from '../tui-state-manager.js';
10
- import type { ICommandEffectQueue } from './command-effect-queue.js';
11
- import type { CommandRegistry } from '@robota-sdk/agent-framework';
12
- import type {
13
- ICommandResult,
14
- IInteractiveSession,
15
- TCommandEffect,
16
- } from '@robota-sdk/agent-interface-transport';
17
-
18
- export function useSlashRouting(
19
- interactiveSession: IInteractiveSession,
20
- registry: CommandRegistry,
21
- manager: TuiStateManager,
22
- commandEffectQueue: ICommandEffectQueue,
23
- reloadPluginCommandSource?: (registry: CommandRegistry) => void,
24
- ): (input: string) => Promise<void> {
25
- return useCallback(
26
- async (input: string) => {
27
- if (!input.startsWith('/')) {
28
- await interactiveSession.submit(input);
29
- manager.setPendingPrompt(interactiveSession.getPendingPrompt());
30
- return;
31
- }
32
-
33
- const parts = input.slice(1).split(/\s+/);
34
- const cmd = parts[0]?.toLowerCase() ?? '';
35
- const args = parts.slice(1).join(' ');
36
-
37
- // Try system command first
38
- const result = await interactiveSession.executeCommand(cmd, args);
39
- if (result) {
40
- if (result.effects?.some((effect) => effect.type === 'session-execution-started')) {
41
- manager.setPendingPrompt(interactiveSession.getPendingPrompt());
42
- return;
43
- }
44
- applySystemCommandResult(
45
- result,
46
- interactiveSession,
47
- registry,
48
- manager,
49
- commandEffectQueue,
50
- reloadPluginCommandSource,
51
- );
52
- return;
53
- }
54
-
55
- manager.addEntry(
56
- messageToHistoryEntry(
57
- createSystemMessage(`Unknown command "/${cmd}". Type /help for help.`),
58
- ),
59
- );
60
- },
61
- [interactiveSession, registry, manager, commandEffectQueue, reloadPluginCommandSource],
62
- );
63
- }
64
-
65
- export function applySystemCommandResult(
66
- result: ICommandResult,
67
- interactiveSession: IInteractiveSession,
68
- registry: CommandRegistry,
69
- manager: TuiStateManager,
70
- commandEffectQueue: ICommandEffectQueue,
71
- reloadPluginCommandSource?: (registry: CommandRegistry) => void,
72
- ): void {
73
- const pendingEffects = applyImmediateCommandEffects(
74
- result.effects,
75
- registry,
76
- manager,
77
- reloadPluginCommandSource,
78
- );
79
- manager.addEntry(messageToHistoryEntry(createSystemMessage(result.message)));
80
-
81
- if (result.interaction !== undefined) {
82
- commandEffectQueue.enqueueInteraction(result.interaction);
83
- }
84
- if (pendingEffects.length > 0) {
85
- commandEffectQueue.enqueueEffects(pendingEffects);
86
- }
87
-
88
- if (interactiveSession.isInitialized) {
89
- const ctx = interactiveSession.getContextState();
90
- manager.setContextState({
91
- percentage: ctx.usedPercentage,
92
- usedTokens: ctx.usedTokens,
93
- maxTokens: ctx.maxTokens,
94
- });
95
- }
96
- }
97
-
98
- function applyImmediateCommandEffects(
99
- effects: readonly TCommandEffect[] | undefined,
100
- registry: CommandRegistry,
101
- manager: TuiStateManager,
102
- reloadPluginCommandSource?: (registry: CommandRegistry) => void,
103
- ): TCommandEffect[] {
104
- if (effects === undefined || effects.length === 0) return [];
105
- const pendingEffects: TCommandEffect[] = [];
106
- for (const effect of effects) {
107
- if (effect.type === 'conversation-history-cleared') {
108
- manager.clearHistory();
109
- continue;
110
- }
111
- if (effect.type === 'plugin-registry-reload-requested') {
112
- reloadPluginCommandSource?.(registry);
113
- continue;
114
- }
115
- pendingEffects.push(effect);
116
- }
117
- return pendingEffects;
118
- }
@@ -1,37 +0,0 @@
1
- import { DEFAULT_STATUS_LINE_COMMAND_SETTINGS } from '@robota-sdk/agent-framework';
2
- import { useState } from 'react';
3
-
4
- import { useTuiCliAdapter } from '../tui-cli-adapter-context.js';
5
-
6
- import type { TUniversalValue } from '@robota-sdk/agent-core';
7
- import type { IStatusLineCommandSettings } from '@robota-sdk/agent-interface-transport';
8
-
9
- function readStatusLineSettings(
10
- settings: Record<string, TUniversalValue>,
11
- ): IStatusLineCommandSettings {
12
- const defaults = { ...DEFAULT_STATUS_LINE_COMMAND_SETTINGS };
13
- const raw = settings.statusline;
14
- if (!isRecord(raw)) {
15
- return defaults;
16
- }
17
- return {
18
- enabled: typeof raw.enabled === 'boolean' ? raw.enabled : defaults.enabled,
19
- gitBranch: typeof raw.gitBranch === 'boolean' ? raw.gitBranch : defaults.gitBranch,
20
- };
21
- }
22
-
23
- function isRecord(value: TUniversalValue): value is Record<string, TUniversalValue> {
24
- return (
25
- value !== null && typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date)
26
- );
27
- }
28
-
29
- export function useStatusLineSettings(): [
30
- IStatusLineCommandSettings,
31
- (settings: IStatusLineCommandSettings) => void,
32
- ] {
33
- const cliAdapter = useTuiCliAdapter();
34
- return useState<IStatusLineCommandSettings>(() =>
35
- readStatusLineSettings(cliAdapter.readSettings(cliAdapter.getUserSettingsPath())),
36
- );
37
- }
@@ -1,95 +0,0 @@
1
- /**
2
- * useTuiChannel — React hook that subscribes to TuiInteractionChannel state changes.
3
- *
4
- * Returns the same shape as the former IInteractiveSessionState so that App.tsx
5
- * changes are minimal.
6
- */
7
-
8
- import { useState, useEffect } from 'react';
9
-
10
- import type { TuiInteractionChannel } from '../TuiInteractionChannel.js';
11
- import type { ICommandEffectQueue } from './command-effect-queue.js';
12
- import type { IPermissionRequest } from '../types.js';
13
- import type { IHistoryEntry, TSessionEndReason } from '@robota-sdk/agent-core';
14
- import type { InteractiveSession, CommandRegistry } from '@robota-sdk/agent-framework';
15
- import type {
16
- IExecutionDetailPage,
17
- IExecutionWorkspaceSnapshot,
18
- IToolState,
19
- } from '@robota-sdk/agent-interface-transport';
20
-
21
- export interface IInteractiveSessionState {
22
- interactiveSession: InteractiveSession;
23
- registry: CommandRegistry;
24
- commandEffectQueue: ICommandEffectQueue;
25
- history: IHistoryEntry[];
26
- addEntry: (entry: IHistoryEntry) => void;
27
- streamingText: string;
28
- activeTools: IToolState[];
29
- isThinking: boolean;
30
- isAborting: boolean;
31
- isShuttingDown: boolean;
32
- pendingPrompt: string | null;
33
- executionWorkspaceSnapshot: IExecutionWorkspaceSnapshot | null;
34
- selectedExecutionEntryId?: string;
35
- permissionRequest: IPermissionRequest | null;
36
- contextState: { percentage: number; usedTokens: number; maxTokens: number };
37
- handleSubmit: (input: string) => Promise<void>;
38
- handleAbort: () => void;
39
- handleCancelQueue: () => void;
40
- handleShutdown: (reason?: TSessionEndReason) => Promise<void>;
41
- selectExecutionWorkspaceEntry: (entryId: string) => void;
42
- readExecutionWorkspaceDetail: (entryId: string) => Promise<IExecutionDetailPage>;
43
- }
44
-
45
- interface IHistoryReadableSession {
46
- getFullHistory(): IHistoryEntry[];
47
- }
48
-
49
- interface IHistorySyncManager {
50
- syncHistory(entries: IHistoryEntry[]): void;
51
- }
52
-
53
- export function applyCompactEventToManager(
54
- interactiveSession: IHistoryReadableSession,
55
- manager: IHistorySyncManager,
56
- ): void {
57
- manager.syncHistory(interactiveSession.getFullHistory());
58
- }
59
-
60
- export function useTuiChannel(channel: TuiInteractionChannel): IInteractiveSessionState {
61
- const [, forceRender] = useState(0);
62
-
63
- useEffect(() => {
64
- channel.onChange = () => forceRender((n) => n + 1);
65
- return () => {
66
- channel.onChange = null;
67
- };
68
- }, [channel]);
69
-
70
- const manager = channel.stateManager;
71
-
72
- return {
73
- interactiveSession: channel.getSession(),
74
- registry: channel.getRegistry(),
75
- commandEffectQueue: channel.getCommandEffectQueue(),
76
- history: manager.history,
77
- addEntry: (e) => manager.addEntry(e),
78
- streamingText: manager.streamingText,
79
- activeTools: manager.activeTools,
80
- isThinking: manager.isThinking,
81
- isAborting: manager.isAborting,
82
- isShuttingDown: channel.isShuttingDown,
83
- pendingPrompt: manager.pendingPrompt,
84
- executionWorkspaceSnapshot: manager.executionWorkspaceSnapshot,
85
- selectedExecutionEntryId: manager.selectedExecutionEntryId,
86
- permissionRequest: channel.permissionRequest,
87
- contextState: manager.contextState,
88
- handleSubmit: (input) => channel.handleInput(input),
89
- handleAbort: () => channel.abort(),
90
- handleCancelQueue: () => channel.cancelQueue(),
91
- handleShutdown: (reason) => channel.shutdown({ reason }),
92
- selectExecutionWorkspaceEntry: (id) => channel.selectExecutionWorkspaceEntry(id),
93
- readExecutionWorkspaceDetail: (id) => channel.readExecutionWorkspaceDetail(id),
94
- };
95
- }
package/src/tui/index.ts DELETED
@@ -1,14 +0,0 @@
1
- export { TuiTransport } from './tui-transport.js';
2
- export { renderApp } from './render.js';
3
- export type { IRenderOptions } from './render.js';
4
- export type { ITuiCliAdapter } from './tui-cli-adapter.js';
5
- export type { IDefaultTuiCliAdapterOptions } from './create-default-tui-cli-adapter.js';
6
- export { createDefaultTuiCliAdapter } from './create-default-tui-cli-adapter.js';
7
- export type {
8
- TOnMissingArgsAction,
9
- ITuiPickerItem,
10
- ITuiCommandInteraction,
11
- ITuiPickerInteraction,
12
- ITuiConfirmInteraction,
13
- TAnyTuiCommandInteraction,
14
- } from './command-interaction.js';
@@ -1,36 +0,0 @@
1
- import { Box, Text, useInput } from 'ink';
2
- import React from 'react';
3
-
4
- import type { ITuiConfirmInteraction } from '../command-interaction.js';
5
-
6
- interface IProps {
7
- commandName: string;
8
- interaction: ITuiConfirmInteraction;
9
- onConfirm: () => void;
10
- onCancel: () => void;
11
- }
12
-
13
- export default function CommandConfirm({
14
- commandName,
15
- interaction,
16
- onConfirm,
17
- onCancel,
18
- }: IProps): React.ReactElement {
19
- useInput((input, key) => {
20
- if (key.return || input === 'y' || input === 'Y') {
21
- onConfirm();
22
- } else if (key.escape || input === 'n' || input === 'N') {
23
- onCancel();
24
- }
25
- });
26
-
27
- return (
28
- <Box paddingX={1}>
29
- <Text bold color="yellow">
30
- /{commandName}:{' '}
31
- </Text>
32
- <Text>{interaction.message} </Text>
33
- <Text dimColor>[y/n]</Text>
34
- </Box>
35
- );
36
- }
@@ -1,77 +0,0 @@
1
- import { Box, Text, useInput, useStdout } from 'ink';
2
- import React, { useState } from 'react';
3
-
4
- import type { ITuiPickerInteraction, ITuiPickerItem } from '../command-interaction.js';
5
-
6
- interface IProps {
7
- commandName: string;
8
- interaction: ITuiPickerInteraction;
9
- onSelect: (item: ITuiPickerItem) => void;
10
- onCancel: () => void;
11
- }
12
-
13
- const MAX_VISIBLE = 8;
14
- const OUTER_CHROME = 4;
15
- const MIN_ROW_WIDTH = 40;
16
-
17
- function useRowWidth(): number {
18
- const { stdout } = useStdout();
19
- return Math.max(MIN_ROW_WIDTH, (stdout.columns ?? 80) - OUTER_CHROME);
20
- }
21
-
22
- export default function CommandPicker({
23
- commandName,
24
- interaction,
25
- onSelect,
26
- onCancel,
27
- }: IProps): React.ReactElement {
28
- const items = interaction.getItems();
29
- const [selectedIndex, setSelectedIndex] = useState(0);
30
- const rowWidth = useRowWidth();
31
-
32
- useInput((input, key) => {
33
- if (key.upArrow) {
34
- setSelectedIndex((i) => (i > 0 ? i - 1 : items.length - 1));
35
- } else if (key.downArrow) {
36
- setSelectedIndex((i) => (i < items.length - 1 ? i + 1 : 0));
37
- } else if (key.return) {
38
- const item = items[selectedIndex];
39
- if (item) onSelect(item);
40
- } else if (key.escape || input === 'q') {
41
- onCancel();
42
- }
43
- });
44
-
45
- const scrollOffset = (() => {
46
- if (items.length <= MAX_VISIBLE) return 0;
47
- if (selectedIndex < MAX_VISIBLE) return 0;
48
- return Math.min(selectedIndex - MAX_VISIBLE + 1, items.length - MAX_VISIBLE);
49
- })();
50
- const visibleItems = items.slice(scrollOffset, scrollOffset + MAX_VISIBLE);
51
-
52
- return (
53
- <Box flexDirection="column" borderStyle="round" borderColor="cyan" paddingX={1}>
54
- <Text bold color="cyan">
55
- /{commandName}
56
- </Text>
57
- {visibleItems.map((item, i) => {
58
- const isSelected = scrollOffset + i === selectedIndex;
59
- const indicator = isSelected ? '▸ ' : ' ';
60
- return (
61
- <Box key={item.value} width={rowWidth}>
62
- <Text
63
- color={isSelected ? 'cyan' : undefined}
64
- dimColor={!isSelected}
65
- wrap="truncate-end"
66
- >
67
- {indicator}
68
- {item.label}
69
- {item.description != null ? ` ${item.description}` : ''}
70
- </Text>
71
- </Box>
72
- );
73
- })}
74
- <Text dimColor>↑↓ navigate · Enter select · Esc cancel</Text>
75
- </Box>
76
- );
77
- }