@robota-sdk/agent-transport-ws 3.0.0-beta.62 → 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.
@@ -1,186 +0,0 @@
1
- import { IToolState, IExecutionResult, ICommandResult, InteractiveSession, TBackgroundTaskEvent, TBackgroundJobGroupEvent, IBackgroundTaskState, IBackgroundJobGroupState, IBackgroundTaskLogPage, IBackgroundTaskListFilter, IBackgroundTaskInput, IBackgroundTaskLogCursor, ITransportAdapter } from '@robota-sdk/agent-sdk';
2
-
3
- type TBackgroundControlAction = 'cancel' | 'close' | 'send';
4
- /** Inbound message from client to server. */
5
- type TClientMessage = {
6
- type: 'submit';
7
- prompt: string;
8
- } | {
9
- type: 'command';
10
- name: string;
11
- args?: string;
12
- } | {
13
- type: 'abort';
14
- } | {
15
- type: 'cancel-queue';
16
- } | {
17
- type: 'get-messages';
18
- } | {
19
- type: 'get-context';
20
- } | {
21
- type: 'get-executing';
22
- } | {
23
- type: 'get-pending';
24
- } | {
25
- type: 'get-background-tasks';
26
- filter?: IBackgroundTaskListFilter;
27
- } | {
28
- type: 'get-background-task';
29
- taskId: string;
30
- } | {
31
- type: 'get-background-job-groups';
32
- } | {
33
- type: 'get-background-job-group';
34
- groupId: string;
35
- } | {
36
- type: 'wait-background-job-group';
37
- groupId: string;
38
- } | {
39
- type: 'cancel-background-task';
40
- taskId: string;
41
- reason?: string;
42
- } | {
43
- type: 'close-background-task';
44
- taskId: string;
45
- } | {
46
- type: 'send-background-task';
47
- taskId: string;
48
- input: IBackgroundTaskInput;
49
- } | {
50
- type: 'read-background-task-log';
51
- taskId: string;
52
- cursor?: IBackgroundTaskLogCursor;
53
- };
54
- /** Outbound message from server to client. */
55
- type TServerMessage = {
56
- type: 'text_delta';
57
- delta: string;
58
- } | {
59
- type: 'user_message';
60
- content: string;
61
- } | {
62
- type: 'tool_start';
63
- state: IToolState;
64
- } | {
65
- type: 'tool_end';
66
- state: IToolState;
67
- } | {
68
- type: 'thinking';
69
- isThinking: boolean;
70
- } | {
71
- type: 'complete';
72
- result: IExecutionResult;
73
- } | {
74
- type: 'interrupted';
75
- result: IExecutionResult;
76
- } | {
77
- type: 'error';
78
- message: string;
79
- } | {
80
- type: 'command_result';
81
- name: string;
82
- message: string;
83
- success: boolean;
84
- data?: ICommandResult['data'];
85
- } | {
86
- type: 'messages';
87
- messages: ReturnType<InteractiveSession['getMessages']>;
88
- } | {
89
- type: 'context';
90
- state: ReturnType<InteractiveSession['getContextState']>;
91
- } | {
92
- type: 'executing';
93
- executing: boolean;
94
- } | {
95
- type: 'pending';
96
- pending: string | null;
97
- } | {
98
- type: 'background_task_event';
99
- event: TBackgroundTaskEvent;
100
- } | {
101
- type: 'background_job_group_event';
102
- event: TBackgroundJobGroupEvent;
103
- } | {
104
- type: 'background_tasks';
105
- tasks: IBackgroundTaskState[];
106
- } | {
107
- type: 'background_task';
108
- taskId: string;
109
- task: IBackgroundTaskState | null;
110
- } | {
111
- type: 'background_job_groups';
112
- groups: IBackgroundJobGroupState[];
113
- } | {
114
- type: 'background_job_group';
115
- groupId: string;
116
- group: IBackgroundJobGroupState | null;
117
- } | {
118
- type: 'background_task_log';
119
- taskId: string;
120
- page: IBackgroundTaskLogPage;
121
- } | {
122
- type: 'background_task_control_result';
123
- action: TBackgroundControlAction;
124
- taskId: string;
125
- success: boolean;
126
- message?: string;
127
- } | {
128
- type: 'protocol_error';
129
- message: string;
130
- };
131
-
132
- /**
133
- * WebSocket transport adapter — exposes InteractiveSession over WebSocket.
134
- *
135
- * Framework-agnostic: works with any WebSocket implementation via
136
- * send/onMessage callbacks. No dependency on ws, uWebSockets, etc.
137
- *
138
- * Protocol: JSON messages with { type, ...payload } structure.
139
- * Server pushes InteractiveSession events to client in real-time.
140
- */
141
-
142
- interface IWsHandlerOptions {
143
- /** InteractiveSession to expose. */
144
- session: InteractiveSession;
145
- /** Send a JSON message to the client. */
146
- send: (message: TServerMessage) => void;
147
- }
148
- /**
149
- * Create a WebSocket message handler for an InteractiveSession.
150
- *
151
- * Returns:
152
- * - `onMessage(data)`: call this when the WebSocket receives a message
153
- * - `cleanup()`: call this when the WebSocket disconnects
154
- *
155
- * Usage:
156
- * ```typescript
157
- * const { onMessage, cleanup } = createWsHandler({
158
- * session: interactiveSession,
159
- * send: (msg) => ws.send(JSON.stringify(msg)),
160
- * });
161
- *
162
- * ws.on('message', (data) => onMessage(String(data)));
163
- * ws.on('close', cleanup);
164
- * ```
165
- */
166
- declare function createWsHandler(options: IWsHandlerOptions): {
167
- onMessage: (data: string) => void;
168
- cleanup: () => void;
169
- };
170
-
171
- /**
172
- * ITransportAdapter implementation for WebSocket transport.
173
- *
174
- * Wraps createWsHandler into the unified ITransportAdapter interface.
175
- * After start(), the consumer must wire onMessage to their WebSocket.
176
- */
177
-
178
- interface IWsTransportOptions {
179
- /** Send a JSON message to the connected WebSocket client. */
180
- send: (message: TServerMessage) => void;
181
- }
182
- declare function createWsTransport(options: IWsTransportOptions): ITransportAdapter & {
183
- onMessage: ((data: string) => void) | null;
184
- };
185
-
186
- export { type IWsHandlerOptions, type IWsTransportOptions, type TClientMessage, type TServerMessage, createWsHandler, createWsTransport };