@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,280 +0,0 @@
1
- /**
2
- * WebSocket transport adapter — exposes IInteractiveSession over WebSocket.
3
- *
4
- * Framework-agnostic: works with any WebSocket implementation via
5
- * send/onMessage callbacks. No dependency on ws, uWebSockets, etc.
6
- *
7
- * Protocol: JSON messages with { type, ...payload } structure.
8
- * Server pushes IInteractiveSession events to client in real-time.
9
- */
10
-
11
- import {
12
- handleBackgroundControlMessage,
13
- handleBackgroundQueryMessage,
14
- } from './ws-background-messages.js';
15
-
16
- import type { TClientMessage, TServerMessage } from './ws-protocol.js';
17
- import type { TBackgroundTaskEvent } from '@robota-sdk/agent-framework';
18
- import type {
19
- IExecutionResult,
20
- IExecutionWorkspaceEvent,
21
- IInteractiveSession,
22
- IToolState,
23
- TBackgroundJobGroupEvent,
24
- } from '@robota-sdk/agent-interface-transport';
25
-
26
- export interface IWsHandlerOptions {
27
- /** IInteractiveSession to expose. */
28
- session: IInteractiveSession;
29
- /** Send a JSON message to the client. */
30
- send: (message: TServerMessage) => void;
31
- }
32
-
33
- /**
34
- * Create a WebSocket message handler for an IInteractiveSession.
35
- *
36
- * Returns:
37
- * - `onMessage(data)`: call this when the WebSocket receives a message
38
- * - `cleanup()`: call this when the WebSocket disconnects
39
- *
40
- * Usage:
41
- * ```typescript
42
- * const { onMessage, cleanup } = createWsHandler({
43
- * session: interactiveSession,
44
- * send: (msg) => ws.send(JSON.stringify(msg)),
45
- * });
46
- *
47
- * ws.on('message', (data) => onMessage(String(data)));
48
- * ws.on('close', cleanup);
49
- * ```
50
- */
51
- export function createWsHandler(options: IWsHandlerOptions): {
52
- onMessage: (data: string) => void;
53
- cleanup: () => void;
54
- } {
55
- const cleanup = subscribeSessionEvents(options.session, options.send);
56
- const onMessage = createWsMessageHandler(options.session, options.send);
57
-
58
- return { onMessage, cleanup };
59
- }
60
-
61
- function subscribeSessionEvents(
62
- session: IInteractiveSession,
63
- send: (message: TServerMessage) => void,
64
- ): () => void {
65
- const onUserMessage = (content: string): void => send({ type: 'user_message', content });
66
- const onTextDelta = (delta: string): void => send({ type: 'text_delta', delta });
67
- const onToolStart = (state: IToolState): void => send({ type: 'tool_start', state });
68
- const onToolEnd = (state: IToolState): void => send({ type: 'tool_end', state });
69
- const onThinking = (isThinking: boolean): void => send({ type: 'thinking', isThinking });
70
- const onComplete = (result: IExecutionResult): void => send({ type: 'complete', result });
71
- const onInterrupted = (result: IExecutionResult): void => send({ type: 'interrupted', result });
72
- const onError = (error: Error): void => send({ type: 'error', message: error.message });
73
- const onBackgroundTaskEvent = (event: TBackgroundTaskEvent): void =>
74
- send({ type: 'background_task_event', event });
75
- const onBackgroundJobGroupEvent = (event: TBackgroundJobGroupEvent): void =>
76
- send({ type: 'background_job_group_event', event });
77
- const onExecutionWorkspace = (event: IExecutionWorkspaceEvent): void =>
78
- send({ type: 'execution_workspace_event', snapshot: event.snapshot });
79
-
80
- session.on('user_message', onUserMessage);
81
- session.on('text_delta', onTextDelta);
82
- session.on('tool_start', onToolStart);
83
- session.on('tool_end', onToolEnd);
84
- session.on('thinking', onThinking);
85
- session.on('complete', onComplete);
86
- session.on('interrupted', onInterrupted);
87
- session.on('error', onError);
88
- session.on('background_task_event', onBackgroundTaskEvent);
89
- session.on('background_job_group_event', onBackgroundJobGroupEvent);
90
- session.on('execution_workspace_event', onExecutionWorkspace);
91
-
92
- return (): void => {
93
- session.off('user_message', onUserMessage);
94
- session.off('text_delta', onTextDelta);
95
- session.off('tool_start', onToolStart);
96
- session.off('tool_end', onToolEnd);
97
- session.off('thinking', onThinking);
98
- session.off('complete', onComplete);
99
- session.off('interrupted', onInterrupted);
100
- session.off('error', onError);
101
- session.off('background_task_event', onBackgroundTaskEvent);
102
- session.off('background_job_group_event', onBackgroundJobGroupEvent);
103
- session.off('execution_workspace_event', onExecutionWorkspace);
104
- };
105
- }
106
-
107
- function createWsMessageHandler(
108
- session: IInteractiveSession,
109
- send: (message: TServerMessage) => void,
110
- ): (data: string) => void {
111
- return (data: string): void => {
112
- const msg = parseClientMessage(data, send);
113
- if (!msg) return;
114
- handleClientMessage(session, send, msg);
115
- };
116
- }
117
-
118
- function parseClientMessage(
119
- data: string,
120
- send: (message: TServerMessage) => void,
121
- ): TClientMessage | null {
122
- try {
123
- return JSON.parse(data) as TClientMessage;
124
- } catch {
125
- send({ type: 'protocol_error', message: 'Invalid JSON' });
126
- return null;
127
- }
128
- }
129
-
130
- function handleClientMessage(
131
- session: IInteractiveSession,
132
- send: (message: TServerMessage) => void,
133
- msg: TClientMessage,
134
- ): void {
135
- if (isSessionControlMessage(msg)) {
136
- handleSessionControlMessage(session, send, msg);
137
- return;
138
- }
139
- if (isSessionQueryMessage(msg)) {
140
- handleSessionQueryMessage(session, send, msg);
141
- return;
142
- }
143
- if (isBackgroundQueryMessage(msg)) {
144
- handleBackgroundQueryMessage(session, send, msg);
145
- return;
146
- }
147
- if (isBackgroundControlMessage(msg)) {
148
- handleBackgroundControlMessage(session, send, msg);
149
- return;
150
- }
151
- send({ type: 'protocol_error', message: `Unknown message type: ${getMessageType(msg)}` });
152
- }
153
-
154
- function getMessageType(msg: TClientMessage): string {
155
- return (msg as { type: string }).type;
156
- }
157
-
158
- function isSessionControlMessage(
159
- msg: TClientMessage,
160
- ): msg is Extract<TClientMessage, { type: 'submit' | 'command' | 'abort' | 'cancel-queue' }> {
161
- return (
162
- msg.type === 'submit' ||
163
- msg.type === 'command' ||
164
- msg.type === 'abort' ||
165
- msg.type === 'cancel-queue'
166
- );
167
- }
168
-
169
- function isSessionQueryMessage(msg: TClientMessage): msg is Extract<
170
- TClientMessage,
171
- {
172
- type:
173
- | 'get-messages'
174
- | 'get-context'
175
- | 'get-executing'
176
- | 'get-pending'
177
- | 'get-execution-workspace';
178
- }
179
- > {
180
- return (
181
- msg.type === 'get-messages' ||
182
- msg.type === 'get-context' ||
183
- msg.type === 'get-executing' ||
184
- msg.type === 'get-pending' ||
185
- msg.type === 'get-execution-workspace'
186
- );
187
- }
188
-
189
- function isBackgroundQueryMessage(
190
- msg: TClientMessage,
191
- ): msg is Extract<
192
- TClientMessage,
193
- | { type: 'get-background-tasks' | 'get-background-task' | 'read-background-task-log' }
194
- | { type: 'get-background-job-groups' | 'get-background-job-group' | 'wait-background-job-group' }
195
- > {
196
- return (
197
- msg.type === 'get-background-tasks' ||
198
- msg.type === 'get-background-task' ||
199
- msg.type === 'read-background-task-log' ||
200
- msg.type === 'get-background-job-groups' ||
201
- msg.type === 'get-background-job-group' ||
202
- msg.type === 'wait-background-job-group'
203
- );
204
- }
205
-
206
- function isBackgroundControlMessage(
207
- msg: TClientMessage,
208
- ): msg is Extract<
209
- TClientMessage,
210
- { type: 'cancel-background-task' | 'close-background-task' | 'send-background-task' }
211
- > {
212
- return (
213
- msg.type === 'cancel-background-task' ||
214
- msg.type === 'close-background-task' ||
215
- msg.type === 'send-background-task'
216
- );
217
- }
218
-
219
- function handleSessionControlMessage(
220
- session: IInteractiveSession,
221
- send: (message: TServerMessage) => void,
222
- msg: Extract<TClientMessage, { type: 'submit' | 'command' | 'abort' | 'cancel-queue' }>,
223
- ): void {
224
- if (msg.type === 'submit') {
225
- if (!msg.prompt) {
226
- send({ type: 'protocol_error', message: 'prompt is required' });
227
- return;
228
- }
229
- session.submit(msg.prompt);
230
- } else if (msg.type === 'command') {
231
- if (!msg.name) {
232
- send({ type: 'protocol_error', message: 'name is required' });
233
- return;
234
- }
235
- session.executeCommand(msg.name, msg.args ?? '').then((result) => {
236
- send({
237
- type: 'command_result',
238
- name: msg.name,
239
- message: result?.message ?? `Unknown command: ${msg.name}`,
240
- success: result?.success ?? false,
241
- data: result?.data,
242
- });
243
- });
244
- } else if (msg.type === 'abort') {
245
- session.abort();
246
- } else {
247
- session.cancelQueue();
248
- }
249
- }
250
-
251
- function handleSessionQueryMessage(
252
- session: IInteractiveSession,
253
- send: (message: TServerMessage) => void,
254
- msg: Extract<
255
- TClientMessage,
256
- {
257
- type:
258
- | 'get-messages'
259
- | 'get-context'
260
- | 'get-executing'
261
- | 'get-pending'
262
- | 'get-execution-workspace';
263
- }
264
- >,
265
- ): void {
266
- if (msg.type === 'get-messages') {
267
- send({ type: 'messages', messages: session.getMessages() });
268
- } else if (msg.type === 'get-context') {
269
- send({ type: 'context', state: session.getContextState() });
270
- } else if (msg.type === 'get-executing') {
271
- send({ type: 'executing', executing: session.isExecuting() });
272
- } else if (msg.type === 'get-execution-workspace') {
273
- send({
274
- type: 'execution_workspace_event',
275
- snapshot: session.getExecutionWorkspaceSnapshot(),
276
- });
277
- } else {
278
- send({ type: 'pending', pending: session.getPendingPrompt() });
279
- }
280
- }
@@ -1,78 +0,0 @@
1
- import type {
2
- InteractiveSession,
3
- IBackgroundTaskInput,
4
- IBackgroundTaskListFilter,
5
- IBackgroundTaskLogCursor,
6
- IBackgroundTaskLogPage,
7
- IBackgroundTaskState,
8
- TBackgroundTaskEvent,
9
- } from '@robota-sdk/agent-framework';
10
- import type {
11
- IBackgroundJobGroupState,
12
- ICommandResult,
13
- IExecutionResult,
14
- IExecutionWorkspaceSnapshot,
15
- IToolState,
16
- TBackgroundJobGroupEvent,
17
- } from '@robota-sdk/agent-interface-transport';
18
-
19
- export type TBackgroundControlAction = 'cancel' | 'close' | 'send';
20
-
21
- /** Inbound message from client to server. */
22
- export type TClientMessage =
23
- | { type: 'submit'; prompt: string }
24
- | { type: 'command'; name: string; args?: string }
25
- | { type: 'abort' }
26
- | { type: 'cancel-queue' }
27
- | { type: 'get-messages' }
28
- | { type: 'get-context' }
29
- | { type: 'get-executing' }
30
- | { type: 'get-pending' }
31
- | { type: 'get-execution-workspace' }
32
- | { type: 'get-background-tasks'; filter?: IBackgroundTaskListFilter }
33
- | { type: 'get-background-task'; taskId: string }
34
- | { type: 'get-background-job-groups' }
35
- | { type: 'get-background-job-group'; groupId: string }
36
- | { type: 'wait-background-job-group'; groupId: string }
37
- | { type: 'cancel-background-task'; taskId: string; reason?: string }
38
- | { type: 'close-background-task'; taskId: string }
39
- | { type: 'send-background-task'; taskId: string; input: IBackgroundTaskInput }
40
- | { type: 'read-background-task-log'; taskId: string; cursor?: IBackgroundTaskLogCursor };
41
-
42
- /** Outbound message from server to client. */
43
- export type TServerMessage =
44
- | { type: 'text_delta'; delta: string }
45
- | { type: 'user_message'; content: string }
46
- | { type: 'tool_start'; state: IToolState }
47
- | { type: 'tool_end'; state: IToolState }
48
- | { type: 'thinking'; isThinking: boolean }
49
- | { type: 'complete'; result: IExecutionResult }
50
- | { type: 'interrupted'; result: IExecutionResult }
51
- | { type: 'error'; message: string }
52
- | {
53
- type: 'command_result';
54
- name: string;
55
- message: string;
56
- success: boolean;
57
- data?: ICommandResult['data'];
58
- }
59
- | { type: 'messages'; messages: ReturnType<InteractiveSession['getMessages']> }
60
- | { type: 'context'; state: ReturnType<InteractiveSession['getContextState']> }
61
- | { type: 'executing'; executing: boolean }
62
- | { type: 'pending'; pending: string | null }
63
- | { type: 'execution_workspace_event'; snapshot: IExecutionWorkspaceSnapshot }
64
- | { type: 'background_task_event'; event: TBackgroundTaskEvent }
65
- | { type: 'background_job_group_event'; event: TBackgroundJobGroupEvent }
66
- | { type: 'background_tasks'; tasks: IBackgroundTaskState[] }
67
- | { type: 'background_task'; taskId: string; task: IBackgroundTaskState | null }
68
- | { type: 'background_job_groups'; groups: IBackgroundJobGroupState[] }
69
- | { type: 'background_job_group'; groupId: string; group: IBackgroundJobGroupState | null }
70
- | { type: 'background_task_log'; taskId: string; page: IBackgroundTaskLogPage }
71
- | {
72
- type: 'background_task_control_result';
73
- action: TBackgroundControlAction;
74
- taskId: string;
75
- success: boolean;
76
- message?: string;
77
- }
78
- | { type: 'protocol_error'; message: string };
@@ -1,128 +0,0 @@
1
- /**
2
- * Self-contained WS transport implementing IConfigurableTransport.
3
- * Owns the WebSocket server lifecycle (ws package), started/stopped via the transport registry.
4
- */
5
-
6
- import { createServer, type Server } from 'node:http';
7
-
8
- import { WebSocketServer, WebSocket } from 'ws';
9
-
10
- import { createWsHandler } from './ws-handler.js';
11
-
12
- import type { TServerMessage } from './ws-protocol.js';
13
- import type { TUniversalValue } from '@robota-sdk/agent-core';
14
- import type {
15
- IConfigurableTransport,
16
- IInteractiveSession,
17
- } from '@robota-sdk/agent-interface-transport';
18
-
19
- const DEFAULT_PORT = 7070;
20
- const DEFAULT_MAX_RETRIES = 20;
21
-
22
- export interface IWsTransportConfig {
23
- port?: number;
24
- maxRetries?: number;
25
- }
26
-
27
- export class WsTransport implements IConfigurableTransport<IInteractiveSession> {
28
- readonly name = 'ws';
29
- readonly defaultEnabled = true;
30
- readonly optionsSchema = {
31
- port: { type: 'number', description: 'WebSocket server port', default: DEFAULT_PORT },
32
- maxRetries: {
33
- type: 'number',
34
- description: 'Port retry attempts when port is occupied',
35
- default: DEFAULT_MAX_RETRIES,
36
- },
37
- };
38
-
39
- private session: IInteractiveSession | null = null;
40
- private stopFn: (() => Promise<void>) | null = null;
41
- private readonly port: number;
42
- private readonly maxRetries: number;
43
-
44
- constructor(config: IWsTransportConfig = {}) {
45
- this.port = config.port ?? DEFAULT_PORT;
46
- this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
47
- }
48
-
49
- attach(session: IInteractiveSession): void {
50
- this.session = session;
51
- }
52
-
53
- async start(): Promise<void> {
54
- if (!this.session) throw new Error('WsTransport: attach() must be called before start()');
55
- const handle = await this.bindWithRetry(this.session, this.port, this.maxRetries);
56
- this.stopFn = handle.stop;
57
- }
58
-
59
- async stop(): Promise<void> {
60
- await this.stopFn?.();
61
- this.stopFn = null;
62
- }
63
-
64
- validateOptions(options: Record<string, TUniversalValue>): boolean {
65
- const { port, maxRetries } = options;
66
- if (port !== undefined && (typeof port !== 'number' || port < 1 || port > 65535)) return false;
67
- if (maxRetries !== undefined && (typeof maxRetries !== 'number' || maxRetries < 0))
68
- return false;
69
- return true;
70
- }
71
-
72
- private bindWithRetry(
73
- session: IInteractiveSession,
74
- port: number,
75
- retriesLeft: number,
76
- ): Promise<{ stop: () => Promise<void> }> {
77
- return this.tryBind(session, port).catch((err: NodeJS.ErrnoException) => {
78
- if (err.code === 'EADDRINUSE' && retriesLeft > 0)
79
- return this.bindWithRetry(session, port + 1, retriesLeft - 1);
80
- throw err;
81
- });
82
- }
83
-
84
- private tryBind(
85
- session: IInteractiveSession,
86
- port: number,
87
- ): Promise<{ stop: () => Promise<void> }> {
88
- return new Promise((resolve, reject) => {
89
- const httpServer: Server = createServer((_, res) => {
90
- res.writeHead(400).end('WebSocket endpoint');
91
- });
92
-
93
- httpServer.on('error', (err: NodeJS.ErrnoException) => {
94
- httpServer.close();
95
- reject(err);
96
- });
97
-
98
- httpServer.listen(port, '127.0.0.1', () => {
99
- const wss = new WebSocketServer({ server: httpServer });
100
-
101
- wss.on('connection', (ws: WebSocket) => {
102
- const send = (message: TServerMessage): void => {
103
- if (ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify(message));
104
- };
105
-
106
- const { onMessage, cleanup } = createWsHandler({ session, send });
107
-
108
- ws.on('message', (data) => onMessage(String(data)));
109
- ws.on('close', cleanup);
110
- ws.on('error', cleanup);
111
-
112
- send({ type: 'messages', messages: session.getMessages() });
113
- send({
114
- type: 'execution_workspace_event',
115
- snapshot: session.getExecutionWorkspaceSnapshot(),
116
- });
117
- });
118
-
119
- resolve({
120
- stop: () =>
121
- new Promise<void>((res) => {
122
- wss.close(() => httpServer.close(() => res()));
123
- }),
124
- });
125
- });
126
- });
127
- }
128
- }
@@ -1,42 +0,0 @@
1
- /**
2
- * ITransportAdapter implementation for WebSocket transport.
3
- *
4
- * Wraps createWsHandler into the unified ITransportAdapter interface.
5
- * After start(), the consumer must wire onMessage to their WebSocket.
6
- */
7
-
8
- import { createWsHandler } from './ws-handler.js';
9
-
10
- import type { TServerMessage } from './ws-protocol.js';
11
- import type { IInteractiveSession, ITransportAdapter } from '@robota-sdk/agent-interface-transport';
12
-
13
- export interface IWsTransportOptions {
14
- /** Send a JSON message to the connected WebSocket client. */
15
- send: (message: TServerMessage) => void;
16
- }
17
-
18
- export function createWsTransport(
19
- options: IWsTransportOptions,
20
- ): ITransportAdapter<IInteractiveSession> & { onMessage: ((data: string) => void) | null } {
21
- let session: IInteractiveSession | null = null;
22
- let cleanup: (() => void) | null = null;
23
-
24
- return {
25
- name: 'ws',
26
- onMessage: null,
27
- attach(s: IInteractiveSession) {
28
- session = s;
29
- },
30
- async start() {
31
- if (!session) throw new Error('No session attached. Call attach() first.');
32
- const handler = createWsHandler({ session, send: options.send });
33
- cleanup = handler.cleanup;
34
- this.onMessage = handler.onMessage;
35
- },
36
- async stop() {
37
- cleanup?.();
38
- cleanup = null;
39
- this.onMessage = null;
40
- },
41
- };
42
- }