@robota-sdk/agent-transport-ws 3.0.0-beta.63 → 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.
- package/README.md +5 -88
- package/dist/node/index.cjs +1 -394
- package/dist/node/index.d.ts +138 -156
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +2 -365
- package/dist/node/index.js.map +1 -0
- package/package.json +21 -17
- package/src/__tests__/ws-handler.test.ts +409 -0
- package/src/__tests__/ws-transport.test.ts +53 -0
- package/src/index.ts +13 -0
- package/src/ws-background-messages.ts +170 -0
- package/src/ws-handler.ts +280 -0
- package/src/ws-protocol.ts +78 -0
- package/src/ws-transport-configurable.ts +128 -0
- package/src/ws-transport.ts +42 -0
- package/dist/node/index.d.cts +0 -231
package/dist/node/index.d.cts
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import { IToolState, IExecutionResult, ICommandResult, InteractiveSession, IExecutionWorkspaceSnapshot, TBackgroundTaskEvent, TBackgroundJobGroupEvent, IBackgroundTaskState, IBackgroundJobGroupState, IBackgroundTaskLogPage, IBackgroundTaskListFilter, IBackgroundTaskInput, IBackgroundTaskLogCursor } from '@robota-sdk/agent-sdk';
|
|
2
|
-
export { IExecutionWorkspaceEntry, IExecutionWorkspaceSnapshot, TExecutionAttention, TExecutionWorkspaceStatus } from '@robota-sdk/agent-sdk';
|
|
3
|
-
import { ITransportAdapter, IConfigurableTransport } from '@robota-sdk/agent-interface-transport';
|
|
4
|
-
import { ISession, TUniversalValue } from '@robota-sdk/agent-core';
|
|
5
|
-
|
|
6
|
-
type TBackgroundControlAction = 'cancel' | 'close' | 'send';
|
|
7
|
-
/** Inbound message from client to server. */
|
|
8
|
-
type TClientMessage = {
|
|
9
|
-
type: 'submit';
|
|
10
|
-
prompt: string;
|
|
11
|
-
} | {
|
|
12
|
-
type: 'command';
|
|
13
|
-
name: string;
|
|
14
|
-
args?: string;
|
|
15
|
-
} | {
|
|
16
|
-
type: 'abort';
|
|
17
|
-
} | {
|
|
18
|
-
type: 'cancel-queue';
|
|
19
|
-
} | {
|
|
20
|
-
type: 'get-messages';
|
|
21
|
-
} | {
|
|
22
|
-
type: 'get-context';
|
|
23
|
-
} | {
|
|
24
|
-
type: 'get-executing';
|
|
25
|
-
} | {
|
|
26
|
-
type: 'get-pending';
|
|
27
|
-
} | {
|
|
28
|
-
type: 'get-execution-workspace';
|
|
29
|
-
} | {
|
|
30
|
-
type: 'get-background-tasks';
|
|
31
|
-
filter?: IBackgroundTaskListFilter;
|
|
32
|
-
} | {
|
|
33
|
-
type: 'get-background-task';
|
|
34
|
-
taskId: string;
|
|
35
|
-
} | {
|
|
36
|
-
type: 'get-background-job-groups';
|
|
37
|
-
} | {
|
|
38
|
-
type: 'get-background-job-group';
|
|
39
|
-
groupId: string;
|
|
40
|
-
} | {
|
|
41
|
-
type: 'wait-background-job-group';
|
|
42
|
-
groupId: string;
|
|
43
|
-
} | {
|
|
44
|
-
type: 'cancel-background-task';
|
|
45
|
-
taskId: string;
|
|
46
|
-
reason?: string;
|
|
47
|
-
} | {
|
|
48
|
-
type: 'close-background-task';
|
|
49
|
-
taskId: string;
|
|
50
|
-
} | {
|
|
51
|
-
type: 'send-background-task';
|
|
52
|
-
taskId: string;
|
|
53
|
-
input: IBackgroundTaskInput;
|
|
54
|
-
} | {
|
|
55
|
-
type: 'read-background-task-log';
|
|
56
|
-
taskId: string;
|
|
57
|
-
cursor?: IBackgroundTaskLogCursor;
|
|
58
|
-
};
|
|
59
|
-
/** Outbound message from server to client. */
|
|
60
|
-
type TServerMessage = {
|
|
61
|
-
type: 'text_delta';
|
|
62
|
-
delta: string;
|
|
63
|
-
} | {
|
|
64
|
-
type: 'user_message';
|
|
65
|
-
content: string;
|
|
66
|
-
} | {
|
|
67
|
-
type: 'tool_start';
|
|
68
|
-
state: IToolState;
|
|
69
|
-
} | {
|
|
70
|
-
type: 'tool_end';
|
|
71
|
-
state: IToolState;
|
|
72
|
-
} | {
|
|
73
|
-
type: 'thinking';
|
|
74
|
-
isThinking: boolean;
|
|
75
|
-
} | {
|
|
76
|
-
type: 'complete';
|
|
77
|
-
result: IExecutionResult;
|
|
78
|
-
} | {
|
|
79
|
-
type: 'interrupted';
|
|
80
|
-
result: IExecutionResult;
|
|
81
|
-
} | {
|
|
82
|
-
type: 'error';
|
|
83
|
-
message: string;
|
|
84
|
-
} | {
|
|
85
|
-
type: 'command_result';
|
|
86
|
-
name: string;
|
|
87
|
-
message: string;
|
|
88
|
-
success: boolean;
|
|
89
|
-
data?: ICommandResult['data'];
|
|
90
|
-
} | {
|
|
91
|
-
type: 'messages';
|
|
92
|
-
messages: ReturnType<InteractiveSession['getMessages']>;
|
|
93
|
-
} | {
|
|
94
|
-
type: 'context';
|
|
95
|
-
state: ReturnType<InteractiveSession['getContextState']>;
|
|
96
|
-
} | {
|
|
97
|
-
type: 'executing';
|
|
98
|
-
executing: boolean;
|
|
99
|
-
} | {
|
|
100
|
-
type: 'pending';
|
|
101
|
-
pending: string | null;
|
|
102
|
-
} | {
|
|
103
|
-
type: 'execution_workspace_event';
|
|
104
|
-
snapshot: IExecutionWorkspaceSnapshot;
|
|
105
|
-
} | {
|
|
106
|
-
type: 'background_task_event';
|
|
107
|
-
event: TBackgroundTaskEvent;
|
|
108
|
-
} | {
|
|
109
|
-
type: 'background_job_group_event';
|
|
110
|
-
event: TBackgroundJobGroupEvent;
|
|
111
|
-
} | {
|
|
112
|
-
type: 'background_tasks';
|
|
113
|
-
tasks: IBackgroundTaskState[];
|
|
114
|
-
} | {
|
|
115
|
-
type: 'background_task';
|
|
116
|
-
taskId: string;
|
|
117
|
-
task: IBackgroundTaskState | null;
|
|
118
|
-
} | {
|
|
119
|
-
type: 'background_job_groups';
|
|
120
|
-
groups: IBackgroundJobGroupState[];
|
|
121
|
-
} | {
|
|
122
|
-
type: 'background_job_group';
|
|
123
|
-
groupId: string;
|
|
124
|
-
group: IBackgroundJobGroupState | null;
|
|
125
|
-
} | {
|
|
126
|
-
type: 'background_task_log';
|
|
127
|
-
taskId: string;
|
|
128
|
-
page: IBackgroundTaskLogPage;
|
|
129
|
-
} | {
|
|
130
|
-
type: 'background_task_control_result';
|
|
131
|
-
action: TBackgroundControlAction;
|
|
132
|
-
taskId: string;
|
|
133
|
-
success: boolean;
|
|
134
|
-
message?: string;
|
|
135
|
-
} | {
|
|
136
|
-
type: 'protocol_error';
|
|
137
|
-
message: string;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* WebSocket transport adapter — exposes InteractiveSession over WebSocket.
|
|
142
|
-
*
|
|
143
|
-
* Framework-agnostic: works with any WebSocket implementation via
|
|
144
|
-
* send/onMessage callbacks. No dependency on ws, uWebSockets, etc.
|
|
145
|
-
*
|
|
146
|
-
* Protocol: JSON messages with { type, ...payload } structure.
|
|
147
|
-
* Server pushes InteractiveSession events to client in real-time.
|
|
148
|
-
*/
|
|
149
|
-
|
|
150
|
-
interface IWsHandlerOptions {
|
|
151
|
-
/** InteractiveSession to expose. */
|
|
152
|
-
session: InteractiveSession;
|
|
153
|
-
/** Send a JSON message to the client. */
|
|
154
|
-
send: (message: TServerMessage) => void;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Create a WebSocket message handler for an InteractiveSession.
|
|
158
|
-
*
|
|
159
|
-
* Returns:
|
|
160
|
-
* - `onMessage(data)`: call this when the WebSocket receives a message
|
|
161
|
-
* - `cleanup()`: call this when the WebSocket disconnects
|
|
162
|
-
*
|
|
163
|
-
* Usage:
|
|
164
|
-
* ```typescript
|
|
165
|
-
* const { onMessage, cleanup } = createWsHandler({
|
|
166
|
-
* session: interactiveSession,
|
|
167
|
-
* send: (msg) => ws.send(JSON.stringify(msg)),
|
|
168
|
-
* });
|
|
169
|
-
*
|
|
170
|
-
* ws.on('message', (data) => onMessage(String(data)));
|
|
171
|
-
* ws.on('close', cleanup);
|
|
172
|
-
* ```
|
|
173
|
-
*/
|
|
174
|
-
declare function createWsHandler(options: IWsHandlerOptions): {
|
|
175
|
-
onMessage: (data: string) => void;
|
|
176
|
-
cleanup: () => void;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* ITransportAdapter implementation for WebSocket transport.
|
|
181
|
-
*
|
|
182
|
-
* Wraps createWsHandler into the unified ITransportAdapter interface.
|
|
183
|
-
* After start(), the consumer must wire onMessage to their WebSocket.
|
|
184
|
-
*/
|
|
185
|
-
|
|
186
|
-
interface IWsTransportOptions {
|
|
187
|
-
/** Send a JSON message to the connected WebSocket client. */
|
|
188
|
-
send: (message: TServerMessage) => void;
|
|
189
|
-
}
|
|
190
|
-
declare function createWsTransport(options: IWsTransportOptions): ITransportAdapter & {
|
|
191
|
-
onMessage: ((data: string) => void) | null;
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Self-contained WS transport implementing IConfigurableTransport.
|
|
196
|
-
* Owns the WebSocket server lifecycle (ws package), started/stopped via the transport registry.
|
|
197
|
-
*/
|
|
198
|
-
|
|
199
|
-
interface IWsTransportConfig {
|
|
200
|
-
port?: number;
|
|
201
|
-
maxRetries?: number;
|
|
202
|
-
}
|
|
203
|
-
declare class WsTransport implements IConfigurableTransport {
|
|
204
|
-
readonly name = "ws";
|
|
205
|
-
readonly defaultEnabled = true;
|
|
206
|
-
readonly optionsSchema: {
|
|
207
|
-
port: {
|
|
208
|
-
type: string;
|
|
209
|
-
description: string;
|
|
210
|
-
default: number;
|
|
211
|
-
};
|
|
212
|
-
maxRetries: {
|
|
213
|
-
type: string;
|
|
214
|
-
description: string;
|
|
215
|
-
default: number;
|
|
216
|
-
};
|
|
217
|
-
};
|
|
218
|
-
private session;
|
|
219
|
-
private stopFn;
|
|
220
|
-
private readonly port;
|
|
221
|
-
private readonly maxRetries;
|
|
222
|
-
constructor(config?: IWsTransportConfig);
|
|
223
|
-
attach(session: ISession): void;
|
|
224
|
-
start(): Promise<void>;
|
|
225
|
-
stop(): Promise<void>;
|
|
226
|
-
validateOptions(options: Record<string, TUniversalValue>): boolean;
|
|
227
|
-
private bindWithRetry;
|
|
228
|
-
private tryBind;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export { type IWsHandlerOptions, type IWsTransportConfig, type IWsTransportOptions, type TClientMessage, type TServerMessage, WsTransport, createWsHandler, createWsTransport };
|