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