rocketride 1.0.0
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 +476 -0
- package/dist/cjs/client.js +1745 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/constants.js +48 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/core/DAPBase.js +328 -0
- package/dist/cjs/core/DAPBase.js.map +1 -0
- package/dist/cjs/core/DAPClient.js +226 -0
- package/dist/cjs/core/DAPClient.js.map +1 -0
- package/dist/cjs/core/TransportBase.js +152 -0
- package/dist/cjs/core/TransportBase.js.map +1 -0
- package/dist/cjs/core/TransportWebSocket.js +646 -0
- package/dist/cjs/core/TransportWebSocket.js.map +1 -0
- package/dist/cjs/exceptions/index.js +119 -0
- package/dist/cjs/exceptions/index.js.map +1 -0
- package/dist/cjs/index.js +56 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/schema/Doc.js +79 -0
- package/dist/cjs/schema/Doc.js.map +1 -0
- package/dist/cjs/schema/DocFilter.js +133 -0
- package/dist/cjs/schema/DocFilter.js.map +1 -0
- package/dist/cjs/schema/DocGroup.js +230 -0
- package/dist/cjs/schema/DocGroup.js.map +1 -0
- package/dist/cjs/schema/DocMetadata.js +58 -0
- package/dist/cjs/schema/DocMetadata.js.map +1 -0
- package/dist/cjs/schema/Question.js +414 -0
- package/dist/cjs/schema/Question.js.map +1 -0
- package/dist/cjs/schema/index.js +50 -0
- package/dist/cjs/schema/index.js.map +1 -0
- package/dist/cjs/types/client.js +26 -0
- package/dist/cjs/types/client.js.map +1 -0
- package/dist/cjs/types/data.js +26 -0
- package/dist/cjs/types/data.js.map +1 -0
- package/dist/cjs/types/events.js +119 -0
- package/dist/cjs/types/events.js.map +1 -0
- package/dist/cjs/types/index.js +50 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/types/pipeline.js +26 -0
- package/dist/cjs/types/pipeline.js.map +1 -0
- package/dist/cjs/types/task.js +115 -0
- package/dist/cjs/types/task.js.map +1 -0
- package/dist/cli/cli/rocketride.js +1399 -0
- package/dist/cli/cli/rocketride.js.map +1 -0
- package/dist/cli/client/client.js +1745 -0
- package/dist/cli/client/client.js.map +1 -0
- package/dist/cli/client/constants.js +48 -0
- package/dist/cli/client/constants.js.map +1 -0
- package/dist/cli/client/core/DAPBase.js +328 -0
- package/dist/cli/client/core/DAPBase.js.map +1 -0
- package/dist/cli/client/core/DAPClient.js +226 -0
- package/dist/cli/client/core/DAPClient.js.map +1 -0
- package/dist/cli/client/core/TransportBase.js +152 -0
- package/dist/cli/client/core/TransportBase.js.map +1 -0
- package/dist/cli/client/core/TransportWebSocket.js +646 -0
- package/dist/cli/client/core/TransportWebSocket.js.map +1 -0
- package/dist/cli/client/exceptions/index.js +119 -0
- package/dist/cli/client/exceptions/index.js.map +1 -0
- package/dist/cli/client/index.js +56 -0
- package/dist/cli/client/index.js.map +1 -0
- package/dist/cli/client/schema/Doc.js +79 -0
- package/dist/cli/client/schema/Doc.js.map +1 -0
- package/dist/cli/client/schema/DocFilter.js +133 -0
- package/dist/cli/client/schema/DocFilter.js.map +1 -0
- package/dist/cli/client/schema/DocGroup.js +230 -0
- package/dist/cli/client/schema/DocGroup.js.map +1 -0
- package/dist/cli/client/schema/DocMetadata.js +58 -0
- package/dist/cli/client/schema/DocMetadata.js.map +1 -0
- package/dist/cli/client/schema/Question.js +414 -0
- package/dist/cli/client/schema/Question.js.map +1 -0
- package/dist/cli/client/schema/index.js +50 -0
- package/dist/cli/client/schema/index.js.map +1 -0
- package/dist/cli/client/types/client.js +26 -0
- package/dist/cli/client/types/client.js.map +1 -0
- package/dist/cli/client/types/data.js +26 -0
- package/dist/cli/client/types/data.js.map +1 -0
- package/dist/cli/client/types/events.js +119 -0
- package/dist/cli/client/types/events.js.map +1 -0
- package/dist/cli/client/types/index.js +50 -0
- package/dist/cli/client/types/index.js.map +1 -0
- package/dist/cli/client/types/pipeline.js +26 -0
- package/dist/cli/client/types/pipeline.js.map +1 -0
- package/dist/cli/client/types/task.js +115 -0
- package/dist/cli/client/types/task.js.map +1 -0
- package/dist/esm/client.js +1740 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/constants.js +45 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/core/DAPBase.js +324 -0
- package/dist/esm/core/DAPBase.js.map +1 -0
- package/dist/esm/core/DAPClient.js +222 -0
- package/dist/esm/core/DAPClient.js.map +1 -0
- package/dist/esm/core/TransportBase.js +148 -0
- package/dist/esm/core/TransportBase.js.map +1 -0
- package/dist/esm/core/TransportWebSocket.js +609 -0
- package/dist/esm/core/TransportWebSocket.js.map +1 -0
- package/dist/esm/exceptions/index.js +109 -0
- package/dist/esm/exceptions/index.js.map +1 -0
- package/dist/esm/index.js +40 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/schema/Doc.js +75 -0
- package/dist/esm/schema/Doc.js.map +1 -0
- package/dist/esm/schema/DocFilter.js +129 -0
- package/dist/esm/schema/DocFilter.js.map +1 -0
- package/dist/esm/schema/DocGroup.js +226 -0
- package/dist/esm/schema/DocGroup.js.map +1 -0
- package/dist/esm/schema/DocMetadata.js +54 -0
- package/dist/esm/schema/DocMetadata.js.map +1 -0
- package/dist/esm/schema/Question.js +409 -0
- package/dist/esm/schema/Question.js.map +1 -0
- package/dist/esm/schema/index.js +34 -0
- package/dist/esm/schema/index.js.map +1 -0
- package/dist/esm/types/client.js +25 -0
- package/dist/esm/types/client.js.map +1 -0
- package/dist/esm/types/data.js +25 -0
- package/dist/esm/types/data.js.map +1 -0
- package/dist/esm/types/events.js +116 -0
- package/dist/esm/types/events.js.map +1 -0
- package/dist/esm/types/index.js +34 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/pipeline.js +25 -0
- package/dist/esm/types/pipeline.js.map +1 -0
- package/dist/esm/types/task.js +112 -0
- package/dist/esm/types/task.js.map +1 -0
- package/dist/types/client.d.ts +798 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/constants.d.ts +45 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/core/DAPBase.d.ts +152 -0
- package/dist/types/core/DAPBase.d.ts.map +1 -0
- package/dist/types/core/DAPClient.d.ts +93 -0
- package/dist/types/core/DAPClient.d.ts.map +1 -0
- package/dist/types/core/TransportBase.d.ts +113 -0
- package/dist/types/core/TransportBase.d.ts.map +1 -0
- package/dist/types/core/TransportWebSocket.d.ts +100 -0
- package/dist/types/core/TransportWebSocket.d.ts.map +1 -0
- package/dist/types/exceptions/index.d.ts +87 -0
- package/dist/types/exceptions/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +36 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/schema/Doc.d.ts +69 -0
- package/dist/types/schema/Doc.d.ts.map +1 -0
- package/dist/types/schema/DocFilter.d.ts +101 -0
- package/dist/types/schema/DocFilter.d.ts.map +1 -0
- package/dist/types/schema/DocGroup.d.ts +113 -0
- package/dist/types/schema/DocGroup.d.ts.map +1 -0
- package/dist/types/schema/DocMetadata.d.ts +77 -0
- package/dist/types/schema/DocMetadata.d.ts.map +1 -0
- package/dist/types/schema/Question.d.ts +163 -0
- package/dist/types/schema/Question.d.ts.map +1 -0
- package/dist/types/schema/index.d.ts +34 -0
- package/dist/types/schema/index.d.ts.map +1 -0
- package/dist/types/types/client.d.ts +149 -0
- package/dist/types/types/client.d.ts.map +1 -0
- package/dist/types/types/data.d.ts +95 -0
- package/dist/types/types/data.d.ts.map +1 -0
- package/dist/types/types/events.d.ts +246 -0
- package/dist/types/types/events.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +34 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/pipeline.d.ts +83 -0
- package/dist/types/types/pipeline.d.ts.map +1 -0
- package/dist/types/types/task.d.ts +314 -0
- package/dist/types/types/task.d.ts.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,1740 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2026 RocketRide, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
import { TransportWebSocket } from './core/TransportWebSocket';
|
|
25
|
+
import { DAPClient } from './core/DAPClient';
|
|
26
|
+
import { CONST_DEFAULT_SERVICE } from './constants';
|
|
27
|
+
import { AuthenticationException } from './exceptions';
|
|
28
|
+
// Global counter for generating unique client IDs
|
|
29
|
+
let clientId = 0;
|
|
30
|
+
/**
|
|
31
|
+
* Streaming data pipe for sending large datasets to RocketRide pipelines.
|
|
32
|
+
*
|
|
33
|
+
* DataPipe provides a stream-like interface for uploading data to an RocketRide
|
|
34
|
+
* pipeline. It handles the low-level protocol details of opening, writing to,
|
|
35
|
+
* and closing data pipes on the server.
|
|
36
|
+
*
|
|
37
|
+
* Usage pattern:
|
|
38
|
+
* 1. Create pipe using client.pipe()
|
|
39
|
+
* 2. Call open() to establish the pipe
|
|
40
|
+
* 3. Call write() multiple times with data chunks
|
|
41
|
+
* 4. Call close() to finalize and get results
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const pipe = await client.pipe(token, { filename: 'data.json' }, 'application/json');
|
|
46
|
+
* await pipe.open();
|
|
47
|
+
* await pipe.write(new TextEncoder().encode('{"data": "value"}'));
|
|
48
|
+
* const result = await pipe.close();
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export class DataPipe {
|
|
52
|
+
/**
|
|
53
|
+
* Creates a new DataPipe instance.
|
|
54
|
+
*
|
|
55
|
+
* @param client - The RocketRideClient instance managing this pipe
|
|
56
|
+
* @param token - Task token for the pipeline receiving the data
|
|
57
|
+
* @param objinfo - Metadata about the object being sent (e.g., filename, size)
|
|
58
|
+
* @param mimeType - MIME type of the data being sent (default: 'application/octet-stream')
|
|
59
|
+
* @param provider - Optional provider name for the data source
|
|
60
|
+
*/
|
|
61
|
+
constructor(client, token, objinfo = {}, mimeType = 'application/octet-stream', provider) {
|
|
62
|
+
this._opened = false;
|
|
63
|
+
this._closed = false;
|
|
64
|
+
this._client = client;
|
|
65
|
+
this._token = token;
|
|
66
|
+
this._objinfo = objinfo;
|
|
67
|
+
this._mimeType = mimeType;
|
|
68
|
+
this._provider = provider;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Check if the pipe is currently open for writing.
|
|
72
|
+
*
|
|
73
|
+
* @returns true if the pipe has been opened and not yet closed
|
|
74
|
+
*/
|
|
75
|
+
get isOpened() {
|
|
76
|
+
return this._opened;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get the unique ID assigned to this pipe by the server.
|
|
80
|
+
*
|
|
81
|
+
* This ID is assigned when the pipe is opened and is used for subsequent
|
|
82
|
+
* write operations. It remains undefined until open() is called successfully.
|
|
83
|
+
*
|
|
84
|
+
* @returns The server-assigned pipe ID, or undefined if not yet opened
|
|
85
|
+
*/
|
|
86
|
+
get pipeId() {
|
|
87
|
+
return this._pipeId;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Open the pipe for data transmission.
|
|
91
|
+
*
|
|
92
|
+
* Establishes a data pipe on the server for streaming data to the pipeline.
|
|
93
|
+
* Must be called before any write() operations. The server will assign a
|
|
94
|
+
* unique pipe ID that is used for subsequent operations.
|
|
95
|
+
*
|
|
96
|
+
* @returns This DataPipe instance (for method chaining)
|
|
97
|
+
* @throws Error if the pipe is already opened or if the pipeline is not running
|
|
98
|
+
*/
|
|
99
|
+
async open() {
|
|
100
|
+
if (this._opened) {
|
|
101
|
+
throw new Error('Pipe already opened');
|
|
102
|
+
}
|
|
103
|
+
const request = this._client.buildRequest('rrext_process', {
|
|
104
|
+
arguments: {
|
|
105
|
+
subcommand: 'open',
|
|
106
|
+
object: this._objinfo,
|
|
107
|
+
mimeType: this._mimeType,
|
|
108
|
+
provider: this._provider,
|
|
109
|
+
},
|
|
110
|
+
token: this._token,
|
|
111
|
+
});
|
|
112
|
+
const response = await this._client.request(request);
|
|
113
|
+
if (this._client.didFail(response)) {
|
|
114
|
+
throw new Error(response.message || 'Your pipeline is not currently running.');
|
|
115
|
+
}
|
|
116
|
+
this._pipeId = response.body?.pipe_id;
|
|
117
|
+
this._opened = true;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Write data to the pipe.
|
|
122
|
+
*
|
|
123
|
+
* Sends a chunk of data through the pipe to the server pipeline. Can be called
|
|
124
|
+
* multiple times to stream large datasets. The pipe must be opened first.
|
|
125
|
+
*
|
|
126
|
+
* @param buffer - Data to write, must be a Uint8Array
|
|
127
|
+
* @throws Error if the pipe is not opened, buffer is invalid, or write fails
|
|
128
|
+
*/
|
|
129
|
+
async write(buffer) {
|
|
130
|
+
if (!this._opened) {
|
|
131
|
+
throw new Error('Pipe not opened');
|
|
132
|
+
}
|
|
133
|
+
if (!(buffer instanceof Uint8Array)) {
|
|
134
|
+
throw new Error('Buffer must be Uint8Array');
|
|
135
|
+
}
|
|
136
|
+
const request = this._client.buildRequest('rrext_process', {
|
|
137
|
+
arguments: {
|
|
138
|
+
subcommand: 'write',
|
|
139
|
+
pipe_id: this._pipeId,
|
|
140
|
+
data: buffer,
|
|
141
|
+
},
|
|
142
|
+
token: this._token,
|
|
143
|
+
});
|
|
144
|
+
const response = await this._client.request(request);
|
|
145
|
+
if (this._client.didFail(response)) {
|
|
146
|
+
throw new Error(response.message || 'Failed to write to pipe');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Close the pipe and get the processing results.
|
|
151
|
+
*
|
|
152
|
+
* Finalizes the data stream and signals the server that no more data will be sent.
|
|
153
|
+
* The server processes any buffered data and returns the final result. After closing,
|
|
154
|
+
* the pipe cannot be reopened or written to again.
|
|
155
|
+
*
|
|
156
|
+
* @returns The processing result from the server, or undefined if already closed
|
|
157
|
+
* @throws Error if closing the pipe fails
|
|
158
|
+
*/
|
|
159
|
+
async close() {
|
|
160
|
+
if (!this._opened || this._closed) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
const request = this._client.buildRequest('rrext_process', {
|
|
165
|
+
arguments: {
|
|
166
|
+
subcommand: 'close',
|
|
167
|
+
pipe_id: this._pipeId,
|
|
168
|
+
},
|
|
169
|
+
token: this._token,
|
|
170
|
+
});
|
|
171
|
+
const response = await this._client.request(request);
|
|
172
|
+
if (this._client.didFail(response)) {
|
|
173
|
+
throw new Error(response.message || 'Failed to close pipe');
|
|
174
|
+
}
|
|
175
|
+
return response.body;
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
this._closed = true;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Main RocketRide client for connecting to RocketRide servers and services.
|
|
184
|
+
*
|
|
185
|
+
* This client provides a comprehensive API for interacting with RocketRide services,
|
|
186
|
+
* including connection management, pipeline execution, data operations, AI chat,
|
|
187
|
+
* event handling, and server connectivity testing.
|
|
188
|
+
*
|
|
189
|
+
* Key features:
|
|
190
|
+
* - Single shared WebSocket connection for all operations
|
|
191
|
+
* - Connection management (connect/disconnect) with optional persistence
|
|
192
|
+
* - Automatic reconnection when persist mode is enabled
|
|
193
|
+
* - Pipeline execution (use, terminate, getTaskStatus)
|
|
194
|
+
* - Data operations (send, sendFiles, pipe)
|
|
195
|
+
* - AI chat functionality (chat)
|
|
196
|
+
* - Event handling (setEvents, event callbacks)
|
|
197
|
+
* - Server connectivity testing (ping)
|
|
198
|
+
* - Full TypeScript type safety
|
|
199
|
+
*/
|
|
200
|
+
export class RocketRideClient extends DAPClient {
|
|
201
|
+
/**
|
|
202
|
+
* Creates a new RocketRideClient instance.
|
|
203
|
+
*
|
|
204
|
+
* Configuration priority (highest to lowest):
|
|
205
|
+
* 1. Values passed in config parameter (auth, uri)
|
|
206
|
+
* 2. Values from env parameter (if provided)
|
|
207
|
+
* 3. Values from .env file (Node.js only)
|
|
208
|
+
* 4. Default values
|
|
209
|
+
*
|
|
210
|
+
* @param config - Configuration options for the client
|
|
211
|
+
* @param config.auth - API key for authentication (required)
|
|
212
|
+
* @param config.uri - Server URI (default: CONST_DEFAULT_SERVICE)
|
|
213
|
+
* @param config.env - Environment variables dictionary for configuration and substitution
|
|
214
|
+
* @param config.onEvent - Callback for server events
|
|
215
|
+
* @param config.onConnected - Callback when connection is established
|
|
216
|
+
* @param config.onDisconnected - Callback when connection is lost
|
|
217
|
+
* @param config.persist - Enable automatic reconnection
|
|
218
|
+
* @param config.requestTimeout - Default timeout in ms for individual requests
|
|
219
|
+
* @param config.maxRetryTime - Max total time in ms to keep retrying connections
|
|
220
|
+
* @param config.module - Optional module name for client identification
|
|
221
|
+
*
|
|
222
|
+
* @throws Error if auth is not provided via config, env, or .env file
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* // Using explicit auth and URI
|
|
227
|
+
* const client = new RocketRideClient({
|
|
228
|
+
* auth: 'your-api-key',
|
|
229
|
+
* uri: 'wss://your-server.com',
|
|
230
|
+
* persist: true,
|
|
231
|
+
* onEvent: (event) => console.log('Event:', event)
|
|
232
|
+
* });
|
|
233
|
+
*
|
|
234
|
+
* // Using custom env dictionary
|
|
235
|
+
* const client = new RocketRideClient({
|
|
236
|
+
* env: {
|
|
237
|
+
* ROCKETRIDE_APIKEY: 'your-api-key',
|
|
238
|
+
* ROCKETRIDE_URI: 'wss://your-server.com',
|
|
239
|
+
* ROCKETRIDE_PROJECT_ID: 'my-project'
|
|
240
|
+
* }
|
|
241
|
+
* });
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
constructor(config = {}) {
|
|
245
|
+
// Check if we're in Node.js or browser environment
|
|
246
|
+
const isBrowser = typeof window !== 'undefined';
|
|
247
|
+
// Build environment variables dictionary
|
|
248
|
+
// Priority: provided env > .env file
|
|
249
|
+
let clientEnv = {};
|
|
250
|
+
if (config.env) {
|
|
251
|
+
// Use provided env dictionary
|
|
252
|
+
clientEnv = { ...config.env };
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
// Load from .env file only (Node.js only)
|
|
256
|
+
if (!isBrowser) {
|
|
257
|
+
try {
|
|
258
|
+
const fs = require('fs');
|
|
259
|
+
const path = require('path');
|
|
260
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
261
|
+
if (fs.existsSync(envPath)) {
|
|
262
|
+
const content = fs.readFileSync(envPath, 'utf-8');
|
|
263
|
+
// Parse each line
|
|
264
|
+
for (const line of content.split('\n')) {
|
|
265
|
+
const trimmed = line.trim();
|
|
266
|
+
// Skip comments and empty lines
|
|
267
|
+
if (!trimmed || trimmed.startsWith('#')) {
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
// Parse KEY=VALUE format
|
|
271
|
+
const match = trimmed.match(/^([^=]+)=(.*)$/);
|
|
272
|
+
if (match) {
|
|
273
|
+
const key = match[1].trim();
|
|
274
|
+
let value = match[2].trim();
|
|
275
|
+
// Remove quotes if present
|
|
276
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
277
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
278
|
+
value = value.slice(1, -1);
|
|
279
|
+
}
|
|
280
|
+
clientEnv[key] = value;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
// File doesn't exist or can't be read - that's okay
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const { auth = config.auth || clientEnv.ROCKETRIDE_APIKEY, uri = config.uri || clientEnv.ROCKETRIDE_URI || CONST_DEFAULT_SERVICE, onEvent, onConnected, onDisconnected, onConnectError, persist, maxRetryTime, module, } = config;
|
|
291
|
+
// Create unique client identifier
|
|
292
|
+
const clientName = module || `CLIENT-${clientId++}`;
|
|
293
|
+
// Initialize the DAPClient without a transport; transport is created in _internalConnect (CONNECTION_LOGIC.md §3)
|
|
294
|
+
super(clientName, undefined, config);
|
|
295
|
+
this._dapAttempted = false;
|
|
296
|
+
this._nextChatId = 1;
|
|
297
|
+
// Persistence properties for automatic reconnection
|
|
298
|
+
this._persist = false;
|
|
299
|
+
this._manualDisconnect = false;
|
|
300
|
+
this._currentReconnectDelay = 250;
|
|
301
|
+
/** True after onConnected has been invoked; used to only invoke onDisconnected when we had a connection. */
|
|
302
|
+
this._didNotifyConnected = false;
|
|
303
|
+
// Store connection details and environment
|
|
304
|
+
this._setUri(uri);
|
|
305
|
+
this._setAuth(auth);
|
|
306
|
+
this._env = clientEnv;
|
|
307
|
+
// Set up callbacks if provided
|
|
308
|
+
if (onEvent)
|
|
309
|
+
this._callerOnEvent = onEvent;
|
|
310
|
+
if (onConnected)
|
|
311
|
+
this._callerOnConnected = onConnected;
|
|
312
|
+
if (onDisconnected)
|
|
313
|
+
this._callerOnDisconnected = onDisconnected;
|
|
314
|
+
if (onConnectError)
|
|
315
|
+
this._callerOnConnectError = onConnectError;
|
|
316
|
+
// Set up persistence options
|
|
317
|
+
this._persist = persist ?? false;
|
|
318
|
+
this._maxRetryTime = maxRetryTime;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Update the server URI (internal). Accepts HTTP/HTTPS/WS/WSS; converts to WebSocket and appends /task/service.
|
|
322
|
+
*/
|
|
323
|
+
_setUri(uri) {
|
|
324
|
+
try {
|
|
325
|
+
const url = new URL(uri);
|
|
326
|
+
const wsScheme = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
327
|
+
this._uri = `${wsScheme}//${url.host}/task/service`;
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
this._uri = `${uri}/task/service`;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Update the authentication credential (internal).
|
|
335
|
+
*/
|
|
336
|
+
_setAuth(auth) {
|
|
337
|
+
this._apikey = auth;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Clear any pending reconnection timeout.
|
|
341
|
+
*/
|
|
342
|
+
_clearReconnectTimeout() {
|
|
343
|
+
if (this._reconnectTimeout) {
|
|
344
|
+
clearTimeout(this._reconnectTimeout);
|
|
345
|
+
this._reconnectTimeout = undefined;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
// ============================================================================
|
|
349
|
+
// CONNECTION METHODS
|
|
350
|
+
// ============================================================================
|
|
351
|
+
/**
|
|
352
|
+
* Single place for physical connection. Creates transport if needed, then
|
|
353
|
+
* calls DAPClient.connect (transport connect + auth handshake + onConnected).
|
|
354
|
+
*/
|
|
355
|
+
async _internalConnect(timeout) {
|
|
356
|
+
if (!this._transport) {
|
|
357
|
+
const transport = new TransportWebSocket(this._uri, this._apikey);
|
|
358
|
+
this._bindTransport(transport);
|
|
359
|
+
}
|
|
360
|
+
await super.connect(timeout);
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Single place for physical disconnect. Closes the transport directly,
|
|
364
|
+
* which triggers onDisconnected via the transport callback.
|
|
365
|
+
*/
|
|
366
|
+
async _internalDisconnect(reason, hasError) {
|
|
367
|
+
if (!this._transport)
|
|
368
|
+
return;
|
|
369
|
+
await this._transport.disconnect(reason, hasError);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Try to connect; on auth error notify and stop; on other error notify and
|
|
373
|
+
* reschedule with exponential backoff. Used by persist-mode connect() and
|
|
374
|
+
* by the reconnect timer.
|
|
375
|
+
*/
|
|
376
|
+
async _attemptConnection(timeout) {
|
|
377
|
+
try {
|
|
378
|
+
await this._internalConnect(timeout);
|
|
379
|
+
this._reconnectTimeout = undefined;
|
|
380
|
+
this.debugMessage('Connection successful');
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
384
|
+
this.debugMessage(`Connection failed: ${err}`);
|
|
385
|
+
await this.onConnectError(err);
|
|
386
|
+
if (error instanceof AuthenticationException) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
if (this._retryStartTime === undefined) {
|
|
390
|
+
this._retryStartTime = Date.now();
|
|
391
|
+
}
|
|
392
|
+
if (this._maxRetryTime !== undefined) {
|
|
393
|
+
if (Date.now() - this._retryStartTime >= this._maxRetryTime) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
this._currentReconnectDelay = Math.min(this._currentReconnectDelay * 2, 2500);
|
|
398
|
+
this._scheduleReconnect();
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Schedule a reconnection attempt with exponential backoff.
|
|
403
|
+
*/
|
|
404
|
+
_scheduleReconnect() {
|
|
405
|
+
this._clearReconnectTimeout();
|
|
406
|
+
if (this._maxRetryTime !== undefined && this._retryStartTime !== undefined) {
|
|
407
|
+
if (Date.now() - this._retryStartTime >= this._maxRetryTime) {
|
|
408
|
+
this.onConnectError(new Error('Max retry time exceeded'));
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
this.debugMessage(`Scheduling reconnection in ${this._currentReconnectDelay}ms`);
|
|
413
|
+
this._reconnectTimeout = setTimeout(async () => {
|
|
414
|
+
if (this._persist && !this._manualDisconnect) {
|
|
415
|
+
this.debugMessage('Attempting to reconnect...');
|
|
416
|
+
await this._attemptConnection();
|
|
417
|
+
}
|
|
418
|
+
}, this._currentReconnectDelay);
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Check if the client is currently connected to the RocketRide server.
|
|
422
|
+
*/
|
|
423
|
+
isConnected() {
|
|
424
|
+
return this._transport?.isConnected() || false;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Connect to the RocketRide server.
|
|
428
|
+
*
|
|
429
|
+
* Must be called before executing pipelines or other operations.
|
|
430
|
+
* In persist mode, enables automatic reconnection on disconnect and on initial failure
|
|
431
|
+
* (calls onConnectError on each failed attempt and keeps retrying).
|
|
432
|
+
* @param timeout - Optional overall timeout in ms for the connect + auth handshake.
|
|
433
|
+
*/
|
|
434
|
+
async connect(timeout) {
|
|
435
|
+
this._manualDisconnect = false;
|
|
436
|
+
this._currentReconnectDelay = 250;
|
|
437
|
+
this._retryStartTime = undefined;
|
|
438
|
+
// If already connected, disconnect first without setting _manualDisconnect
|
|
439
|
+
if (this.isConnected()) {
|
|
440
|
+
await this._internalDisconnect();
|
|
441
|
+
}
|
|
442
|
+
if (this._persist) {
|
|
443
|
+
this._clearReconnectTimeout();
|
|
444
|
+
await this._attemptConnection(timeout);
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
await this._internalConnect(timeout);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Disconnect from the RocketRide server and stop automatic reconnection.
|
|
452
|
+
*
|
|
453
|
+
* Should be called when finished with the client to clean up resources.
|
|
454
|
+
*/
|
|
455
|
+
async disconnect() {
|
|
456
|
+
this._manualDisconnect = true;
|
|
457
|
+
this._clearReconnectTimeout();
|
|
458
|
+
if (this._transport && this.isConnected()) {
|
|
459
|
+
await this._internalDisconnect();
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Update server URI and/or auth at runtime. If currently connected,
|
|
464
|
+
* disconnects and reconnects with the new params. In persist mode,
|
|
465
|
+
* reconnection is scheduled only if we were connected.
|
|
466
|
+
*/
|
|
467
|
+
async setConnectionParams(options) {
|
|
468
|
+
if (options.uri !== undefined) {
|
|
469
|
+
this._setUri(options.uri);
|
|
470
|
+
}
|
|
471
|
+
if (options.auth !== undefined) {
|
|
472
|
+
this._setAuth(options.auth);
|
|
473
|
+
}
|
|
474
|
+
const wasAlreadyConnected = this.isConnected();
|
|
475
|
+
this._manualDisconnect = true;
|
|
476
|
+
this._clearReconnectTimeout();
|
|
477
|
+
if (wasAlreadyConnected) {
|
|
478
|
+
await this._internalDisconnect();
|
|
479
|
+
}
|
|
480
|
+
// Destroy transport so next connect() creates a new one with updated uri/auth (CONNECTION_LOGIC.md §2c)
|
|
481
|
+
if (options.uri !== undefined || options.auth !== undefined) {
|
|
482
|
+
this._transport = undefined;
|
|
483
|
+
}
|
|
484
|
+
if (this._persist && wasAlreadyConnected) {
|
|
485
|
+
this._manualDisconnect = false;
|
|
486
|
+
this._scheduleReconnect();
|
|
487
|
+
}
|
|
488
|
+
else if (wasAlreadyConnected) {
|
|
489
|
+
this._manualDisconnect = false;
|
|
490
|
+
await this._internalConnect();
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
this._manualDisconnect = false;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
// ============================================================================
|
|
497
|
+
// PING METHODS
|
|
498
|
+
// ============================================================================
|
|
499
|
+
/**
|
|
500
|
+
* Test connectivity to the RocketRide server.
|
|
501
|
+
*
|
|
502
|
+
* Sends a lightweight ping request to the server to verify it's responding
|
|
503
|
+
* and reachable. This is useful for connectivity testing, health checks,
|
|
504
|
+
* and measuring response times.
|
|
505
|
+
*/
|
|
506
|
+
async ping(token) {
|
|
507
|
+
// Build ping request
|
|
508
|
+
const request = this.buildRequest('rrext_ping', { token });
|
|
509
|
+
// Send to server and wait for response
|
|
510
|
+
const response = await this.request(request);
|
|
511
|
+
// Check if ping failed
|
|
512
|
+
if (this.didFail(response)) {
|
|
513
|
+
const errorMsg = response.message || 'Ping failed';
|
|
514
|
+
throw new Error(`Ping failed: ${errorMsg}`);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
// ============================================================================
|
|
518
|
+
// EXECUTION METHODS
|
|
519
|
+
// ============================================================================
|
|
520
|
+
/**
|
|
521
|
+
* Substitute environment variables in a string.
|
|
522
|
+
* Replaces ${ROCKETRIDE_*} patterns with values from client's env dictionary.
|
|
523
|
+
* If variable is not found, leaves it unchanged.
|
|
524
|
+
*/
|
|
525
|
+
substituteEnvVars(value) {
|
|
526
|
+
// Match ${ROCKETRIDE_*} patterns
|
|
527
|
+
return value.replace(/\$\{(ROCKETRIDE_[^}]+)\}/g, (match, varName) => {
|
|
528
|
+
// Check if variable exists in client's env
|
|
529
|
+
if (varName in this._env) {
|
|
530
|
+
return String(this._env[varName]);
|
|
531
|
+
}
|
|
532
|
+
// If not found, leave as is
|
|
533
|
+
return match;
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Recursively process an object/array to substitute environment variables.
|
|
538
|
+
* Only processes string values, leaving other types unchanged.
|
|
539
|
+
*/
|
|
540
|
+
processEnvSubstitution(obj) {
|
|
541
|
+
if (typeof obj === 'string') {
|
|
542
|
+
// If it's a string, perform substitution
|
|
543
|
+
return this.substituteEnvVars(obj);
|
|
544
|
+
}
|
|
545
|
+
else if (Array.isArray(obj)) {
|
|
546
|
+
// If it's an array, process each element
|
|
547
|
+
return obj.map(item => this.processEnvSubstitution(item));
|
|
548
|
+
}
|
|
549
|
+
else if (obj !== null && typeof obj === 'object') {
|
|
550
|
+
// If it's an object, process each property
|
|
551
|
+
const result = {};
|
|
552
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
553
|
+
result[key] = this.processEnvSubstitution(value);
|
|
554
|
+
}
|
|
555
|
+
return result;
|
|
556
|
+
}
|
|
557
|
+
// For other types (number, boolean, null), return as is
|
|
558
|
+
return obj;
|
|
559
|
+
}
|
|
560
|
+
// ============================================================================
|
|
561
|
+
// VALIDATION METHODS
|
|
562
|
+
// ============================================================================
|
|
563
|
+
/**
|
|
564
|
+
* Validate a pipeline configuration.
|
|
565
|
+
*
|
|
566
|
+
* Sends the pipeline to the server for structural validation, checking
|
|
567
|
+
* component compatibility, connection integrity, and the resolved
|
|
568
|
+
* execution chain.
|
|
569
|
+
*
|
|
570
|
+
* Source resolution follows the same logic as {@link use}:
|
|
571
|
+
* 1. Explicit `source` option (if provided)
|
|
572
|
+
* 2. `source` field inside the pipeline config
|
|
573
|
+
* 3. Implied source: the single component whose config.mode is 'Source'
|
|
574
|
+
*
|
|
575
|
+
* @param options.pipeline - Pipeline configuration to validate
|
|
576
|
+
* @param options.source - Optional override for the source component ID
|
|
577
|
+
* @returns Promise resolving to validation result with errors, warnings,
|
|
578
|
+
* resolved component, and execution chain
|
|
579
|
+
* @throws Error if the server returns a validation error
|
|
580
|
+
*
|
|
581
|
+
* @example
|
|
582
|
+
* ```typescript
|
|
583
|
+
* const result = await client.validate({
|
|
584
|
+
* pipeline: { components: [...], project_id: '123' },
|
|
585
|
+
* source: 'webhook_1'
|
|
586
|
+
* });
|
|
587
|
+
* if (result.errors?.length) {
|
|
588
|
+
* console.log('Validation errors:', result.errors);
|
|
589
|
+
* }
|
|
590
|
+
* ```
|
|
591
|
+
*/
|
|
592
|
+
async validate(options) {
|
|
593
|
+
const { pipeline, source } = options;
|
|
594
|
+
const arguments_ = { pipeline };
|
|
595
|
+
if (source !== undefined) {
|
|
596
|
+
arguments_.source = source;
|
|
597
|
+
}
|
|
598
|
+
const request = this.buildRequest('rrext_validate', {
|
|
599
|
+
arguments: arguments_
|
|
600
|
+
});
|
|
601
|
+
const response = await this.request(request);
|
|
602
|
+
if (this.didFail(response)) {
|
|
603
|
+
const errorMsg = response.message || 'Validation failed';
|
|
604
|
+
throw new Error(`Pipeline validation failed: ${errorMsg}`);
|
|
605
|
+
}
|
|
606
|
+
return response.body || {};
|
|
607
|
+
}
|
|
608
|
+
// ============================================================================
|
|
609
|
+
// PIPELINE EXECUTION METHODS
|
|
610
|
+
// ============================================================================
|
|
611
|
+
/**
|
|
612
|
+
* Start an RocketRide pipeline for processing data.
|
|
613
|
+
*
|
|
614
|
+
* This method loads and executes a pipeline configuration. It automatically performs
|
|
615
|
+
* environment variable substitution on the pipeline config, replacing ${ROCKETRIDE_*}
|
|
616
|
+
* placeholders with values from the .env file.
|
|
617
|
+
*
|
|
618
|
+
* @param options - Pipeline execution options
|
|
619
|
+
* @param options.token - Custom token for the pipeline (auto-generated if not provided)
|
|
620
|
+
* @param options.filepath - Path to JSON file containing pipeline configuration
|
|
621
|
+
* @param options.pipeline - Pipeline configuration object (alternative to filepath)
|
|
622
|
+
* @param options.source - Override pipeline source
|
|
623
|
+
* @param options.threads - Number of threads for execution (default: 1)
|
|
624
|
+
* @param options.useExisting - Use existing pipeline instance
|
|
625
|
+
* @param options.args - Command line arguments to pass to pipeline
|
|
626
|
+
* @param options.ttl - Time-to-live in seconds for idle pipelines (optional, server default if not provided; use 0 for no timeout)
|
|
627
|
+
*
|
|
628
|
+
* @returns Promise resolving to an object containing the task token and other metadata
|
|
629
|
+
* @throws Error if neither pipeline nor filepath is provided
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* ```typescript
|
|
633
|
+
* // Using pipeline file
|
|
634
|
+
* const result = await client.use({ filepath: './pipeline.json' });
|
|
635
|
+
*
|
|
636
|
+
* // Using pipeline object
|
|
637
|
+
* const result = await client.use({
|
|
638
|
+
* pipeline: { name: 'My Pipeline', components: [...], source: 'local', project_id: '123' }
|
|
639
|
+
* });
|
|
640
|
+
*
|
|
641
|
+
* // With environment variable substitution
|
|
642
|
+
* // Pipeline config: { "endpoint": "${ROCKETRIDE_URI}/api" }
|
|
643
|
+
* // Will be replaced with actual ROCKETRIDE_URI value from .env
|
|
644
|
+
* ```
|
|
645
|
+
*/
|
|
646
|
+
async use(options = {}) {
|
|
647
|
+
const { token, filepath, pipeline, source, threads, useExisting, args, ttl } = options;
|
|
648
|
+
// Validate required parameters
|
|
649
|
+
if (!pipeline && !filepath) {
|
|
650
|
+
throw new Error('Pipeline configuration or file path is required and must be specified');
|
|
651
|
+
}
|
|
652
|
+
let pipelineConfig;
|
|
653
|
+
// Load pipeline configuration from file if needed
|
|
654
|
+
if (!pipeline && filepath) {
|
|
655
|
+
// Check if we're in Node.js environment
|
|
656
|
+
if (typeof window !== 'undefined') {
|
|
657
|
+
throw new Error('File loading not available in browser environment. Please provide pipeline object directly.');
|
|
658
|
+
}
|
|
659
|
+
// Load file in Node.js
|
|
660
|
+
const fs = require('fs');
|
|
661
|
+
const fileContent = fs.readFileSync(filepath, 'utf-8');
|
|
662
|
+
pipelineConfig = JSON.parse(fileContent);
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
pipelineConfig = pipeline;
|
|
666
|
+
}
|
|
667
|
+
// Create a deep copy of the pipeline config to avoid modifying the original
|
|
668
|
+
let processedConfig = JSON.parse(JSON.stringify(pipelineConfig));
|
|
669
|
+
// Perform environment variable substitution on the pipeline configuration
|
|
670
|
+
processedConfig = this.processEnvSubstitution(processedConfig);
|
|
671
|
+
// Override source if specified (after substitution)
|
|
672
|
+
if (source !== undefined) {
|
|
673
|
+
processedConfig.source = source;
|
|
674
|
+
}
|
|
675
|
+
// Build execution request with all parameters
|
|
676
|
+
const arguments_ = {
|
|
677
|
+
pipeline: processedConfig,
|
|
678
|
+
args: args || [],
|
|
679
|
+
};
|
|
680
|
+
// Add TTL if provided (server uses its default if not specified)
|
|
681
|
+
if (ttl !== undefined) {
|
|
682
|
+
arguments_.ttl = ttl;
|
|
683
|
+
}
|
|
684
|
+
// Add optional parameters if specified
|
|
685
|
+
if (token !== undefined) {
|
|
686
|
+
arguments_.token = token;
|
|
687
|
+
}
|
|
688
|
+
if (threads !== undefined) {
|
|
689
|
+
arguments_.threads = threads;
|
|
690
|
+
}
|
|
691
|
+
if (useExisting !== undefined) {
|
|
692
|
+
arguments_.useExisting = useExisting;
|
|
693
|
+
}
|
|
694
|
+
// Send execution request to server
|
|
695
|
+
const request = this.buildRequest('execute', { arguments: arguments_ });
|
|
696
|
+
const response = await this.request(request);
|
|
697
|
+
// Check for execution errors
|
|
698
|
+
if (this.didFail(response)) {
|
|
699
|
+
const errorMsg = response.message || 'Unknown execution error';
|
|
700
|
+
this.debugMessage(`Pipeline execution failed: ${errorMsg}`);
|
|
701
|
+
throw new Error(errorMsg);
|
|
702
|
+
}
|
|
703
|
+
// Extract and validate response
|
|
704
|
+
const responseBody = response.body || {};
|
|
705
|
+
const taskToken = responseBody.token;
|
|
706
|
+
if (!taskToken) {
|
|
707
|
+
throw new Error('Server did not return a task token in successful response');
|
|
708
|
+
}
|
|
709
|
+
this.debugMessage(`Pipeline execution started successfully, task token: ${taskToken}`);
|
|
710
|
+
// Type assertion to ensure token is present
|
|
711
|
+
return responseBody;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Terminate a running pipeline.
|
|
715
|
+
*/
|
|
716
|
+
async terminate(token) {
|
|
717
|
+
// Send termination request
|
|
718
|
+
const request = this.buildRequest('terminate', { token });
|
|
719
|
+
const response = await this.request(request);
|
|
720
|
+
// Check for termination errors
|
|
721
|
+
if (this.didFail(response)) {
|
|
722
|
+
const errorMsg = response.message || 'Unknown termination error';
|
|
723
|
+
this.debugMessage(`Pipeline termination failed: ${errorMsg}`);
|
|
724
|
+
throw new Error(errorMsg);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Get the current status of a running pipeline.
|
|
729
|
+
*/
|
|
730
|
+
async getTaskStatus(token) {
|
|
731
|
+
// Send status request
|
|
732
|
+
const request = this.buildRequest('rrext_get_task_status', { token });
|
|
733
|
+
const response = await this.request(request);
|
|
734
|
+
// Check for status retrieval errors
|
|
735
|
+
if (this.didFail(response)) {
|
|
736
|
+
const errorMsg = response.message || 'Unknown status retrieval error';
|
|
737
|
+
this.debugMessage(`Pipeline status retrieval failed: ${errorMsg}`);
|
|
738
|
+
throw new Error(errorMsg);
|
|
739
|
+
}
|
|
740
|
+
// Return status information
|
|
741
|
+
return response.body || {};
|
|
742
|
+
}
|
|
743
|
+
// ============================================================================
|
|
744
|
+
// DATA METHODS
|
|
745
|
+
// ============================================================================
|
|
746
|
+
/** Return objinfo with size set; never 0 (parse filter skips "empty"). */
|
|
747
|
+
_objinfoWithSize(objinfo, size) {
|
|
748
|
+
return { ...objinfo, size: size || 1 };
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Create a data pipe for streaming operations.
|
|
752
|
+
*/
|
|
753
|
+
async pipe(token, objinfo = {}, mimeType, provider) {
|
|
754
|
+
return new DataPipe(this, token, objinfo, mimeType, provider);
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Send data to a running pipeline.
|
|
758
|
+
*/
|
|
759
|
+
async send(token, data, objinfo = {}, mimetype) {
|
|
760
|
+
// Convert string to bytes if needed
|
|
761
|
+
let buffer;
|
|
762
|
+
if (typeof data === 'string') {
|
|
763
|
+
buffer = new TextEncoder().encode(data);
|
|
764
|
+
}
|
|
765
|
+
else if (data instanceof Uint8Array) {
|
|
766
|
+
buffer = data;
|
|
767
|
+
}
|
|
768
|
+
else {
|
|
769
|
+
throw new Error('data must be either a string or Uint8Array');
|
|
770
|
+
}
|
|
771
|
+
// Create and use a temporary pipe for the data
|
|
772
|
+
const pipe = await this.pipe(token, this._objinfoWithSize(objinfo, buffer.length), mimetype);
|
|
773
|
+
try {
|
|
774
|
+
await pipe.open();
|
|
775
|
+
await pipe.write(buffer);
|
|
776
|
+
return await pipe.close();
|
|
777
|
+
}
|
|
778
|
+
catch (error) {
|
|
779
|
+
// Clean up pipe on any error
|
|
780
|
+
if (pipe.isOpened) {
|
|
781
|
+
try {
|
|
782
|
+
await pipe.close();
|
|
783
|
+
}
|
|
784
|
+
catch {
|
|
785
|
+
// Ignore cleanup errors
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
throw error;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Upload multiple files to a pipeline with progress tracking and parallel execution.
|
|
793
|
+
*
|
|
794
|
+
* This method efficiently uploads files in parallel with configurable concurrency control.
|
|
795
|
+
* Each file is streamed through a data pipe, and progress events are emitted through the
|
|
796
|
+
* event system for all subscribers. The order of results matches the input file order.
|
|
797
|
+
*
|
|
798
|
+
* Progress events are sent through the event system as 'apaevt_status_upload' events
|
|
799
|
+
* (matching Python client behavior) rather than through a callback parameter.
|
|
800
|
+
*
|
|
801
|
+
* @param files - Array of file objects with optional metadata and MIME types
|
|
802
|
+
* @param token - Pipeline task token to receive the uploads
|
|
803
|
+
* @param maxConcurrent - Maximum number of concurrent uploads (default: 5)
|
|
804
|
+
*
|
|
805
|
+
* @returns Promise resolving to array of UPLOAD_RESULT objects in the same order as input
|
|
806
|
+
*
|
|
807
|
+
* @example
|
|
808
|
+
* ```typescript
|
|
809
|
+
* // Subscribe to upload events
|
|
810
|
+
* client.on('apaevt_status_upload', (event) => {
|
|
811
|
+
* console.log(`${event.body.filepath}: ${event.body.bytes_sent}/${event.body.file_size}`);
|
|
812
|
+
* });
|
|
813
|
+
*
|
|
814
|
+
* // Upload files
|
|
815
|
+
* const results = await client.sendFiles(
|
|
816
|
+
* [
|
|
817
|
+
* { file: fileObject1 },
|
|
818
|
+
* { file: fileObject2, mimetype: 'application/json' },
|
|
819
|
+
* { file: fileObject3, objinfo: { custom: 'metadata' } }
|
|
820
|
+
* ],
|
|
821
|
+
* 'task-token',
|
|
822
|
+
* 10 // Upload max 10 files concurrently
|
|
823
|
+
* );
|
|
824
|
+
* ```
|
|
825
|
+
*/
|
|
826
|
+
async sendFiles(files, token) {
|
|
827
|
+
const results = new Array(files.length);
|
|
828
|
+
/**
|
|
829
|
+
* Helper function to send upload events through the event system.
|
|
830
|
+
*/
|
|
831
|
+
const sendUploadEvent = (body) => {
|
|
832
|
+
const eventMessage = {
|
|
833
|
+
event: 'apaevt_status_upload',
|
|
834
|
+
body: body,
|
|
835
|
+
seq: 0,
|
|
836
|
+
type: 'event'
|
|
837
|
+
};
|
|
838
|
+
this.onEvent(eventMessage);
|
|
839
|
+
};
|
|
840
|
+
/**
|
|
841
|
+
* Upload a single file - straightforward linear process:
|
|
842
|
+
* 1. Wait for pipe to become available (server handles queuing)
|
|
843
|
+
* 2. Transfer data
|
|
844
|
+
* 3. Close pipe
|
|
845
|
+
* 4. Send status update
|
|
846
|
+
*/
|
|
847
|
+
const uploadFile = async (fileData, index) => {
|
|
848
|
+
const { file, objinfo = {}, mimetype } = fileData;
|
|
849
|
+
const startTime = Date.now();
|
|
850
|
+
let bytesUploaded = 0;
|
|
851
|
+
let pipe = null;
|
|
852
|
+
let error;
|
|
853
|
+
let result;
|
|
854
|
+
// Get file size: from filesystem when filepath in objinfo (Node.js), else file.size (same as Python os.path.getsize)
|
|
855
|
+
let fileSize = file.size;
|
|
856
|
+
if (typeof window === 'undefined' && objinfo?.filepath && typeof objinfo.filepath === 'string') {
|
|
857
|
+
try {
|
|
858
|
+
const fs = require('fs');
|
|
859
|
+
fileSize = fs.statSync(objinfo.filepath).size;
|
|
860
|
+
}
|
|
861
|
+
catch {
|
|
862
|
+
// fallback to file.size
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
const finalMimetype = mimetype || file.type || 'application/octet-stream';
|
|
866
|
+
try {
|
|
867
|
+
// Step 1: Create and open pipe (waits for server to allocate)
|
|
868
|
+
pipe = await this.pipe(token, this._objinfoWithSize({ name: file.name, ...objinfo }, fileSize), finalMimetype);
|
|
869
|
+
await pipe.open();
|
|
870
|
+
// Step 2: Send status update AFTER we have the pipe
|
|
871
|
+
sendUploadEvent({
|
|
872
|
+
action: 'open',
|
|
873
|
+
filepath: file.name,
|
|
874
|
+
bytes_sent: 0,
|
|
875
|
+
file_size: fileSize,
|
|
876
|
+
upload_time: 0,
|
|
877
|
+
});
|
|
878
|
+
// Step 3: Transfer data in chunks
|
|
879
|
+
const reader = file.stream().getReader();
|
|
880
|
+
try {
|
|
881
|
+
while (true) {
|
|
882
|
+
const { done, value } = await reader.read();
|
|
883
|
+
if (done)
|
|
884
|
+
break;
|
|
885
|
+
await pipe.write(value);
|
|
886
|
+
bytesUploaded += value.length;
|
|
887
|
+
// Send progress updates during transfer
|
|
888
|
+
sendUploadEvent({
|
|
889
|
+
action: 'write',
|
|
890
|
+
filepath: file.name,
|
|
891
|
+
bytes_sent: bytesUploaded,
|
|
892
|
+
file_size: fileSize,
|
|
893
|
+
upload_time: (Date.now() - startTime) / 1000,
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
finally {
|
|
898
|
+
reader.releaseLock();
|
|
899
|
+
}
|
|
900
|
+
// Step 4: Close pipe and get result
|
|
901
|
+
sendUploadEvent({
|
|
902
|
+
action: 'close',
|
|
903
|
+
filepath: file.name,
|
|
904
|
+
bytes_sent: bytesUploaded,
|
|
905
|
+
file_size: fileSize,
|
|
906
|
+
upload_time: (Date.now() - startTime) / 1000,
|
|
907
|
+
});
|
|
908
|
+
result = await pipe.close();
|
|
909
|
+
}
|
|
910
|
+
catch (err) {
|
|
911
|
+
error = err instanceof Error ? err.message : String(err);
|
|
912
|
+
}
|
|
913
|
+
// Send final status
|
|
914
|
+
const uploadTime = (Date.now() - startTime) / 1000;
|
|
915
|
+
const finalResult = {
|
|
916
|
+
action: error ? 'error' : 'complete',
|
|
917
|
+
filepath: file.name,
|
|
918
|
+
bytes_sent: bytesUploaded,
|
|
919
|
+
file_size: fileSize,
|
|
920
|
+
upload_time: uploadTime,
|
|
921
|
+
result,
|
|
922
|
+
error,
|
|
923
|
+
};
|
|
924
|
+
sendUploadEvent(finalResult);
|
|
925
|
+
results[index] = finalResult;
|
|
926
|
+
};
|
|
927
|
+
// Create a promise for every file - let server handle queuing
|
|
928
|
+
const uploadPromises = files.map((fileData, index) => uploadFile(fileData, index).catch(err => {
|
|
929
|
+
// Ensure errors don't kill the whole batch
|
|
930
|
+
console.error(`Upload failed for ${fileData.file.name}:`, err);
|
|
931
|
+
}));
|
|
932
|
+
// Wait for all uploads to complete
|
|
933
|
+
await Promise.all(uploadPromises);
|
|
934
|
+
return results;
|
|
935
|
+
}
|
|
936
|
+
// ============================================================================
|
|
937
|
+
// CHAT METHODS
|
|
938
|
+
// ============================================================================
|
|
939
|
+
/**
|
|
940
|
+
* Ask a question to RocketRide's AI and get an intelligent response.
|
|
941
|
+
*/
|
|
942
|
+
async chat(options) {
|
|
943
|
+
const { token, question } = options;
|
|
944
|
+
try {
|
|
945
|
+
// Validate that we have a question to ask
|
|
946
|
+
if (!question) {
|
|
947
|
+
throw new Error('Question cannot be empty');
|
|
948
|
+
}
|
|
949
|
+
// Create unique identifier for this chat operation
|
|
950
|
+
const objinfo = { name: `Question ${this._nextChatId}` };
|
|
951
|
+
this._nextChatId += 1;
|
|
952
|
+
// Create pipe instance
|
|
953
|
+
const pipe = new DataPipe(this, token, objinfo, 'application/rocketride-question', 'chat');
|
|
954
|
+
try {
|
|
955
|
+
// Open the communication channel to the AI
|
|
956
|
+
await pipe.open();
|
|
957
|
+
// Send the question as JSON data to the AI system
|
|
958
|
+
const questionJson = JSON.stringify(question.toDict());
|
|
959
|
+
const questionBytes = new TextEncoder().encode(questionJson);
|
|
960
|
+
await pipe.write(questionBytes);
|
|
961
|
+
// Close the pipe and get the AI's response
|
|
962
|
+
const result = await pipe.close();
|
|
963
|
+
// Check it
|
|
964
|
+
if (!result) {
|
|
965
|
+
throw new Error('No response received from AI');
|
|
966
|
+
}
|
|
967
|
+
// Return success response in standard format
|
|
968
|
+
return result;
|
|
969
|
+
}
|
|
970
|
+
finally {
|
|
971
|
+
// Ensure the pipe is properly closed even if errors occur
|
|
972
|
+
if (pipe.isOpened) {
|
|
973
|
+
try {
|
|
974
|
+
await pipe.close();
|
|
975
|
+
}
|
|
976
|
+
catch {
|
|
977
|
+
// Ignore errors during cleanup
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
catch (error) {
|
|
983
|
+
// Return error response in standard format
|
|
984
|
+
throw new Error(error instanceof Error ? error.message : String(error));
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
// ============================================================================
|
|
988
|
+
// EVENT METHODS
|
|
989
|
+
// ============================================================================
|
|
990
|
+
/**
|
|
991
|
+
* Send events to debugging interface if available (for development).
|
|
992
|
+
*/
|
|
993
|
+
_sendVSCodeEvent(eventType, body) {
|
|
994
|
+
// Set up debugging integration on first use
|
|
995
|
+
if (!this._dapAttempted) {
|
|
996
|
+
this._dapAttempted = true;
|
|
997
|
+
try {
|
|
998
|
+
// In browser environment, check for debugging tools
|
|
999
|
+
if (typeof window !== 'undefined') {
|
|
1000
|
+
const win = window;
|
|
1001
|
+
if (win.__ROCKETRIDE_DEBUG__) {
|
|
1002
|
+
this._dapSend = win.__ROCKETRIDE_DEBUG__.sendEvent;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
catch {
|
|
1007
|
+
// Not in debugging environment - no problem
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
// Send event to debugger if available
|
|
1011
|
+
if (this._dapSend) {
|
|
1012
|
+
const customEvent = {
|
|
1013
|
+
type: 'event',
|
|
1014
|
+
event: eventType,
|
|
1015
|
+
body: body,
|
|
1016
|
+
};
|
|
1017
|
+
this._dapSend(customEvent);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Handle incoming events from the RocketRide server.
|
|
1022
|
+
*/
|
|
1023
|
+
async onEvent(message) {
|
|
1024
|
+
// Extract event information
|
|
1025
|
+
const eventType = message.event || 'unknown';
|
|
1026
|
+
const eventBody = message.body || {};
|
|
1027
|
+
const seqNum = message.seq || 0;
|
|
1028
|
+
// Forward to debugging interface if available
|
|
1029
|
+
this._sendVSCodeEvent(eventType, eventBody);
|
|
1030
|
+
// Call user-provided event handler if available
|
|
1031
|
+
if (this._callerOnEvent) {
|
|
1032
|
+
try {
|
|
1033
|
+
await this._callerOnEvent(message);
|
|
1034
|
+
}
|
|
1035
|
+
catch (error) {
|
|
1036
|
+
// Log errors but don't let user code break the connection
|
|
1037
|
+
this.debugMessage(`Error in user onEvent handler for ${eventType} (seq ${seqNum}): ${error}`);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Handle connection attempt failure.
|
|
1043
|
+
* Calls the user callback and chains to parent.
|
|
1044
|
+
*/
|
|
1045
|
+
async onConnectError(error) {
|
|
1046
|
+
if (this._callerOnConnectError) {
|
|
1047
|
+
try {
|
|
1048
|
+
await this._callerOnConnectError(error instanceof Error ? error.message : String(error));
|
|
1049
|
+
}
|
|
1050
|
+
catch (e) {
|
|
1051
|
+
this.debugMessage(`Error in user onConnectError handler: ${e}`);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
await super.onConnectError(error);
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* Handle connected events from the RocketRide server.
|
|
1058
|
+
*/
|
|
1059
|
+
async onConnected(connectionInfo) {
|
|
1060
|
+
this._manualDisconnect = false;
|
|
1061
|
+
this._didNotifyConnected = true;
|
|
1062
|
+
this._clearReconnectTimeout();
|
|
1063
|
+
this._currentReconnectDelay = 250;
|
|
1064
|
+
this._retryStartTime = undefined;
|
|
1065
|
+
// Call user-provided event handler if available
|
|
1066
|
+
if (this._callerOnConnected) {
|
|
1067
|
+
try {
|
|
1068
|
+
await this._callerOnConnected(connectionInfo);
|
|
1069
|
+
}
|
|
1070
|
+
catch (error) {
|
|
1071
|
+
// Log errors but don't let user code break the connection
|
|
1072
|
+
this.debugMessage(`Error in user onConnected handler for ${connectionInfo}: ${error}`);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
await super.onConnected(connectionInfo);
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Handle disconnected events from the RocketRide server.
|
|
1079
|
+
* Only invokes the user's onDisconnected if onConnected had previously been called
|
|
1080
|
+
* (so "disconnect without ever connecting" does not fire the user callback).
|
|
1081
|
+
*/
|
|
1082
|
+
async onDisconnected(reason, hasError) {
|
|
1083
|
+
if (this._didNotifyConnected) {
|
|
1084
|
+
this._didNotifyConnected = false;
|
|
1085
|
+
if (this._callerOnDisconnected) {
|
|
1086
|
+
try {
|
|
1087
|
+
await this._callerOnDisconnected(reason, hasError);
|
|
1088
|
+
}
|
|
1089
|
+
catch (error) {
|
|
1090
|
+
// Log errors but don't let user code break the connection
|
|
1091
|
+
this.debugMessage(`Error in user onDisconnected handler for ${reason}: ${error}`);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
// Chain to parent to clear pending requests
|
|
1095
|
+
await super.onDisconnected(reason, hasError);
|
|
1096
|
+
}
|
|
1097
|
+
// Schedule reconnection if persist is enabled and not a manual disconnect
|
|
1098
|
+
if (this._persist && !this._manualDisconnect) {
|
|
1099
|
+
this._scheduleReconnect();
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
/**
|
|
1103
|
+
* Subscribe to specific types of events from the server.
|
|
1104
|
+
*/
|
|
1105
|
+
async setEvents(token, eventTypes) {
|
|
1106
|
+
// Build event subscription request
|
|
1107
|
+
const request = this.buildRequest('rrext_monitor', {
|
|
1108
|
+
arguments: { types: eventTypes },
|
|
1109
|
+
token,
|
|
1110
|
+
});
|
|
1111
|
+
// Send to server
|
|
1112
|
+
const response = await this.request(request);
|
|
1113
|
+
// Check for errors
|
|
1114
|
+
if (this.didFail(response)) {
|
|
1115
|
+
const errorMsg = response.message || 'Event subscription failed';
|
|
1116
|
+
throw new Error(errorMsg);
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
// ============================================================================
|
|
1120
|
+
// PROJECT STORAGE MANAGEMENT
|
|
1121
|
+
// ============================================================================
|
|
1122
|
+
/**
|
|
1123
|
+
* Save or update a project pipeline.
|
|
1124
|
+
*
|
|
1125
|
+
* Stores a project pipeline configuration on the server. If the project
|
|
1126
|
+
* already exists, it will be updated. Use expectedVersion to ensure
|
|
1127
|
+
* you're updating the version you expect (prevents conflicts).
|
|
1128
|
+
*
|
|
1129
|
+
* @param options - Save project options
|
|
1130
|
+
* @param options.projectId - Unique identifier for the project
|
|
1131
|
+
* @param options.pipeline - Pipeline configuration object
|
|
1132
|
+
* @param options.expectedVersion - Expected current version for atomic updates (optional)
|
|
1133
|
+
* @returns Promise resolving to save result with success status, projectId, and new version
|
|
1134
|
+
* @throws Error if save fails due to version mismatch, storage error, or invalid input
|
|
1135
|
+
*
|
|
1136
|
+
* @example
|
|
1137
|
+
* ```typescript
|
|
1138
|
+
* // Save a new project
|
|
1139
|
+
* const result = await client.saveProject({
|
|
1140
|
+
* projectId: 'proj-123',
|
|
1141
|
+
* pipeline: {
|
|
1142
|
+
* name: 'Data Processor',
|
|
1143
|
+
* source: 'source_1',
|
|
1144
|
+
* components: [...]
|
|
1145
|
+
* }
|
|
1146
|
+
* });
|
|
1147
|
+
* console.log(`Saved version: ${result.version}`);
|
|
1148
|
+
*
|
|
1149
|
+
* // Update existing project with version check
|
|
1150
|
+
* const existing = await client.getProject({ projectId: 'proj-123' });
|
|
1151
|
+
* existing.name = 'Updated Name';
|
|
1152
|
+
* const updated = await client.saveProject({
|
|
1153
|
+
* projectId: 'proj-123',
|
|
1154
|
+
* pipeline: existing,
|
|
1155
|
+
* expectedVersion: existing.version
|
|
1156
|
+
* });
|
|
1157
|
+
* ```
|
|
1158
|
+
*/
|
|
1159
|
+
async saveProject(options) {
|
|
1160
|
+
const { projectId, pipeline, expectedVersion } = options;
|
|
1161
|
+
// Validate inputs
|
|
1162
|
+
if (!projectId) {
|
|
1163
|
+
throw new Error('projectId is required');
|
|
1164
|
+
}
|
|
1165
|
+
if (!pipeline || typeof pipeline !== 'object') {
|
|
1166
|
+
throw new Error('pipeline must be a non-empty object');
|
|
1167
|
+
}
|
|
1168
|
+
// Build request arguments
|
|
1169
|
+
const args = {
|
|
1170
|
+
subcommand: 'save_project',
|
|
1171
|
+
projectId,
|
|
1172
|
+
pipeline,
|
|
1173
|
+
};
|
|
1174
|
+
// Add optional version for atomic updates
|
|
1175
|
+
if (expectedVersion !== undefined) {
|
|
1176
|
+
args.expectedVersion = expectedVersion;
|
|
1177
|
+
}
|
|
1178
|
+
// Send request to server
|
|
1179
|
+
const request = this.buildRequest('rrext_store', { arguments: args });
|
|
1180
|
+
const response = await this.request(request);
|
|
1181
|
+
// Check for errors
|
|
1182
|
+
if (this.didFail(response)) {
|
|
1183
|
+
const errorMsg = response.message || 'Unknown error saving project';
|
|
1184
|
+
this.debugMessage(`Project save failed: ${errorMsg}`);
|
|
1185
|
+
throw new Error(errorMsg);
|
|
1186
|
+
}
|
|
1187
|
+
// Extract and return response
|
|
1188
|
+
this.debugMessage(`Project saved successfully: ${projectId}, version: ${response.body?.version}`);
|
|
1189
|
+
return response.body;
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* Retrieve a project by its ID.
|
|
1193
|
+
*
|
|
1194
|
+
* Fetches the complete pipeline configuration and current version for
|
|
1195
|
+
* the specified project. Use this before updating to get the current
|
|
1196
|
+
* version for atomic updates.
|
|
1197
|
+
*
|
|
1198
|
+
* @param options - Get project options
|
|
1199
|
+
* @param options.projectId - Unique identifier of the project to retrieve
|
|
1200
|
+
* @returns Promise resolving to project data with success status, pipeline, and version
|
|
1201
|
+
* @throws Error if project doesn't exist or retrieval fails
|
|
1202
|
+
*
|
|
1203
|
+
* @example
|
|
1204
|
+
* ```typescript
|
|
1205
|
+
* // Get a project
|
|
1206
|
+
* try {
|
|
1207
|
+
* const project = await client.getProject({ projectId: 'proj-123' });
|
|
1208
|
+
* console.log(`Project: ${project.name}`);
|
|
1209
|
+
* console.log(`Version: ${project.version}`);
|
|
1210
|
+
* } catch (error) {
|
|
1211
|
+
* if (error.message.includes('NOT_FOUND')) {
|
|
1212
|
+
* console.log("Project doesn't exist");
|
|
1213
|
+
* }
|
|
1214
|
+
* }
|
|
1215
|
+
*
|
|
1216
|
+
* // Before updating - get current version
|
|
1217
|
+
* const project = await client.getProject({ projectId: 'proj-123' });
|
|
1218
|
+
* project.name = 'Updated';
|
|
1219
|
+
* await client.saveProject({
|
|
1220
|
+
* projectId: 'proj-123',
|
|
1221
|
+
* pipeline: project,
|
|
1222
|
+
* expectedVersion: project.version
|
|
1223
|
+
* });
|
|
1224
|
+
* ```
|
|
1225
|
+
*/
|
|
1226
|
+
async getProject(options) {
|
|
1227
|
+
const { projectId } = options;
|
|
1228
|
+
// Validate inputs
|
|
1229
|
+
if (!projectId) {
|
|
1230
|
+
throw new Error('projectId is required');
|
|
1231
|
+
}
|
|
1232
|
+
// Build request
|
|
1233
|
+
const args = {
|
|
1234
|
+
subcommand: 'get_project',
|
|
1235
|
+
projectId,
|
|
1236
|
+
};
|
|
1237
|
+
// Send request to server
|
|
1238
|
+
const request = this.buildRequest('rrext_store', { arguments: args });
|
|
1239
|
+
const response = await this.request(request);
|
|
1240
|
+
// Check for errors
|
|
1241
|
+
if (this.didFail(response)) {
|
|
1242
|
+
const errorMsg = response.message || 'Unknown error retrieving project';
|
|
1243
|
+
this.debugMessage(`Project retrieval failed: ${errorMsg}`);
|
|
1244
|
+
throw new Error(errorMsg);
|
|
1245
|
+
}
|
|
1246
|
+
// Extract and return response
|
|
1247
|
+
this.debugMessage(`Project retrieved successfully: ${projectId}`);
|
|
1248
|
+
return response.body;
|
|
1249
|
+
}
|
|
1250
|
+
/**
|
|
1251
|
+
* Delete a project by its ID.
|
|
1252
|
+
*
|
|
1253
|
+
* Permanently removes a project from storage. Optionally verify the
|
|
1254
|
+
* version before deletion to ensure you're deleting the version you
|
|
1255
|
+
* expect (prevents accidental deletion of modified projects).
|
|
1256
|
+
*
|
|
1257
|
+
* @param options - Delete project options
|
|
1258
|
+
* @param options.projectId - Unique identifier of the project to delete
|
|
1259
|
+
* @param options.expectedVersion - Expected current version for atomic deletion (required)
|
|
1260
|
+
* @returns Promise resolving to deletion result with success status and message
|
|
1261
|
+
* @throws Error if project doesn't exist, version mismatch, or deletion fails
|
|
1262
|
+
*
|
|
1263
|
+
* @example
|
|
1264
|
+
* ```typescript
|
|
1265
|
+
* // Safe deletion with version check
|
|
1266
|
+
* const project = await client.getProject({ projectId: 'proj-123' });
|
|
1267
|
+
* try {
|
|
1268
|
+
* const result = await client.deleteProject({
|
|
1269
|
+
* projectId: 'proj-123',
|
|
1270
|
+
* expectedVersion: project.version
|
|
1271
|
+
* });
|
|
1272
|
+
* console.log('Project deleted successfully');
|
|
1273
|
+
* } catch (error) {
|
|
1274
|
+
* if (error.message.includes('CONFLICT')) {
|
|
1275
|
+
* console.log('Project was modified, deletion cancelled');
|
|
1276
|
+
* }
|
|
1277
|
+
* }
|
|
1278
|
+
* ```
|
|
1279
|
+
*/
|
|
1280
|
+
async deleteProject(options) {
|
|
1281
|
+
const { projectId, expectedVersion } = options;
|
|
1282
|
+
// Validate inputs
|
|
1283
|
+
if (!projectId) {
|
|
1284
|
+
throw new Error('projectId is required');
|
|
1285
|
+
}
|
|
1286
|
+
// Build request
|
|
1287
|
+
const args = {
|
|
1288
|
+
subcommand: 'delete_project',
|
|
1289
|
+
projectId,
|
|
1290
|
+
};
|
|
1291
|
+
// Add optional version for atomic deletion
|
|
1292
|
+
if (expectedVersion !== undefined) {
|
|
1293
|
+
args.expectedVersion = expectedVersion;
|
|
1294
|
+
}
|
|
1295
|
+
// Send request to server
|
|
1296
|
+
const request = this.buildRequest('rrext_store', { arguments: args });
|
|
1297
|
+
const response = await this.request(request);
|
|
1298
|
+
// Check for errors
|
|
1299
|
+
if (this.didFail(response)) {
|
|
1300
|
+
const errorMsg = response.message || 'Unknown error deleting project';
|
|
1301
|
+
this.debugMessage(`Project deletion failed: ${errorMsg}`);
|
|
1302
|
+
throw new Error(errorMsg);
|
|
1303
|
+
}
|
|
1304
|
+
// Extract and return response
|
|
1305
|
+
this.debugMessage(`Project deleted successfully: ${projectId}`);
|
|
1306
|
+
return response.body;
|
|
1307
|
+
}
|
|
1308
|
+
/**
|
|
1309
|
+
* List all projects for the current user.
|
|
1310
|
+
*
|
|
1311
|
+
* Retrieves a summary of all projects stored for the authenticated user.
|
|
1312
|
+
* Each project summary includes the ID, name, list of data sources, and total component count.
|
|
1313
|
+
*
|
|
1314
|
+
* @returns Promise resolving to list result with success status, projects array, and count
|
|
1315
|
+
* @throws Error if retrieval fails
|
|
1316
|
+
*
|
|
1317
|
+
* @example
|
|
1318
|
+
* ```typescript
|
|
1319
|
+
* // List all projects
|
|
1320
|
+
* const result = await client.getAllProjects();
|
|
1321
|
+
* console.log(`Found ${result.count} projects:`);
|
|
1322
|
+
* for (const project of result.projects) {
|
|
1323
|
+
* console.log(`- ${project.id}: ${project.name} (${project.totalComponents} components)`);
|
|
1324
|
+
* for (const source of project.sources) {
|
|
1325
|
+
* console.log(` * ${source.name} (${source.provider})`);
|
|
1326
|
+
* }
|
|
1327
|
+
* }
|
|
1328
|
+
*
|
|
1329
|
+
* // Find specific project
|
|
1330
|
+
* const result = await client.getAllProjects();
|
|
1331
|
+
* const myProject = result.projects.find(p => p.id === 'proj-123');
|
|
1332
|
+
* ```
|
|
1333
|
+
*/
|
|
1334
|
+
async getAllProjects() {
|
|
1335
|
+
// Build request
|
|
1336
|
+
const args = {
|
|
1337
|
+
subcommand: 'get_all_projects',
|
|
1338
|
+
};
|
|
1339
|
+
// Send request to server
|
|
1340
|
+
const request = this.buildRequest('rrext_store', { arguments: args });
|
|
1341
|
+
const response = await this.request(request);
|
|
1342
|
+
// Check for errors
|
|
1343
|
+
if (this.didFail(response)) {
|
|
1344
|
+
const errorMsg = response.message || 'Unknown error listing projects';
|
|
1345
|
+
this.debugMessage(`Project list retrieval failed: ${errorMsg}`);
|
|
1346
|
+
throw new Error(errorMsg);
|
|
1347
|
+
}
|
|
1348
|
+
// Extract and return response
|
|
1349
|
+
const projectCount = response.body?.count || 0;
|
|
1350
|
+
this.debugMessage(`Projects retrieved successfully: ${projectCount} projects`);
|
|
1351
|
+
return response.body;
|
|
1352
|
+
}
|
|
1353
|
+
// ============================================================================
|
|
1354
|
+
// TEMPLATE STORAGE MANAGEMENT (System-wide templates)
|
|
1355
|
+
// ============================================================================
|
|
1356
|
+
/**
|
|
1357
|
+
* Save or update a template pipeline.
|
|
1358
|
+
*
|
|
1359
|
+
* Stores a template pipeline configuration on the server. Templates are system-wide
|
|
1360
|
+
* and accessible to all users. If the template already exists, it will be updated.
|
|
1361
|
+
* Use expectedVersion to ensure you're updating the version you expect.
|
|
1362
|
+
*
|
|
1363
|
+
* @param options - Save template options
|
|
1364
|
+
* @param options.templateId - Unique identifier for the template
|
|
1365
|
+
* @param options.pipeline - Pipeline configuration object
|
|
1366
|
+
* @param options.expectedVersion - Expected current version for atomic updates (optional)
|
|
1367
|
+
* @returns Promise resolving to save result with success status, templateId, and new version
|
|
1368
|
+
* @throws Error if save fails due to version mismatch, storage error, or invalid input
|
|
1369
|
+
*/
|
|
1370
|
+
async saveTemplate(options) {
|
|
1371
|
+
const { templateId, pipeline, expectedVersion } = options;
|
|
1372
|
+
// Validate inputs
|
|
1373
|
+
if (!templateId) {
|
|
1374
|
+
throw new Error('templateId is required');
|
|
1375
|
+
}
|
|
1376
|
+
if (!pipeline || typeof pipeline !== 'object') {
|
|
1377
|
+
throw new Error('pipeline must be a non-empty object');
|
|
1378
|
+
}
|
|
1379
|
+
// Build request arguments
|
|
1380
|
+
const args = {
|
|
1381
|
+
subcommand: 'save_template',
|
|
1382
|
+
templateId,
|
|
1383
|
+
pipeline,
|
|
1384
|
+
};
|
|
1385
|
+
// Add optional version for atomic updates
|
|
1386
|
+
if (expectedVersion !== undefined) {
|
|
1387
|
+
args.expectedVersion = expectedVersion;
|
|
1388
|
+
}
|
|
1389
|
+
// Send request to server
|
|
1390
|
+
const request = this.buildRequest('rrext_store', { arguments: args });
|
|
1391
|
+
const response = await this.request(request);
|
|
1392
|
+
// Check for errors
|
|
1393
|
+
if (this.didFail(response)) {
|
|
1394
|
+
const errorMsg = response.message || 'Unknown error saving template';
|
|
1395
|
+
this.debugMessage(`Template save failed: ${errorMsg}`);
|
|
1396
|
+
throw new Error(errorMsg);
|
|
1397
|
+
}
|
|
1398
|
+
// Extract and return response
|
|
1399
|
+
this.debugMessage(`Template saved successfully: ${templateId}, version: ${response.body?.version}`);
|
|
1400
|
+
return response.body;
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Retrieve a template by its ID.
|
|
1404
|
+
*/
|
|
1405
|
+
async getTemplate(options) {
|
|
1406
|
+
const { templateId } = options;
|
|
1407
|
+
// Validate inputs
|
|
1408
|
+
if (!templateId) {
|
|
1409
|
+
throw new Error('templateId is required');
|
|
1410
|
+
}
|
|
1411
|
+
// Build request
|
|
1412
|
+
const args = {
|
|
1413
|
+
subcommand: 'get_template',
|
|
1414
|
+
templateId,
|
|
1415
|
+
};
|
|
1416
|
+
// Send request to server
|
|
1417
|
+
const request = this.buildRequest('rrext_store', { arguments: args });
|
|
1418
|
+
const response = await this.request(request);
|
|
1419
|
+
// Check for errors
|
|
1420
|
+
if (this.didFail(response)) {
|
|
1421
|
+
const errorMsg = response.message || 'Unknown error retrieving template';
|
|
1422
|
+
this.debugMessage(`Template retrieval failed: ${errorMsg}`);
|
|
1423
|
+
throw new Error(errorMsg);
|
|
1424
|
+
}
|
|
1425
|
+
// Extract and return response
|
|
1426
|
+
this.debugMessage(`Template retrieved successfully: ${templateId}`);
|
|
1427
|
+
return response.body;
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Delete a template by its ID.
|
|
1431
|
+
*/
|
|
1432
|
+
async deleteTemplate(options) {
|
|
1433
|
+
const { templateId, expectedVersion } = options;
|
|
1434
|
+
// Validate inputs
|
|
1435
|
+
if (!templateId) {
|
|
1436
|
+
throw new Error('templateId is required');
|
|
1437
|
+
}
|
|
1438
|
+
// Build request
|
|
1439
|
+
const args = {
|
|
1440
|
+
subcommand: 'delete_template',
|
|
1441
|
+
templateId,
|
|
1442
|
+
};
|
|
1443
|
+
// Add optional version for atomic deletion
|
|
1444
|
+
if (expectedVersion !== undefined) {
|
|
1445
|
+
args.expectedVersion = expectedVersion;
|
|
1446
|
+
}
|
|
1447
|
+
// Send request to server
|
|
1448
|
+
const request = this.buildRequest('rrext_store', { arguments: args });
|
|
1449
|
+
const response = await this.request(request);
|
|
1450
|
+
// Check for errors
|
|
1451
|
+
if (this.didFail(response)) {
|
|
1452
|
+
const errorMsg = response.message || 'Unknown error deleting template';
|
|
1453
|
+
this.debugMessage(`Template deletion failed: ${errorMsg}`);
|
|
1454
|
+
throw new Error(errorMsg);
|
|
1455
|
+
}
|
|
1456
|
+
// Extract and return response
|
|
1457
|
+
this.debugMessage(`Template deleted successfully: ${templateId}`);
|
|
1458
|
+
return response.body;
|
|
1459
|
+
}
|
|
1460
|
+
/**
|
|
1461
|
+
* List all templates.
|
|
1462
|
+
*/
|
|
1463
|
+
async getAllTemplates() {
|
|
1464
|
+
// Build request
|
|
1465
|
+
const args = {
|
|
1466
|
+
subcommand: 'get_all_templates',
|
|
1467
|
+
};
|
|
1468
|
+
// Send request to server
|
|
1469
|
+
const request = this.buildRequest('rrext_store', { arguments: args });
|
|
1470
|
+
const response = await this.request(request);
|
|
1471
|
+
// Check for errors
|
|
1472
|
+
if (this.didFail(response)) {
|
|
1473
|
+
const errorMsg = response.message || 'Unknown error listing templates';
|
|
1474
|
+
this.debugMessage(`Template list retrieval failed: ${errorMsg}`);
|
|
1475
|
+
throw new Error(errorMsg);
|
|
1476
|
+
}
|
|
1477
|
+
// Extract and return response
|
|
1478
|
+
const templateCount = response.body?.count || 0;
|
|
1479
|
+
this.debugMessage(`Templates retrieved successfully: ${templateCount} templates`);
|
|
1480
|
+
return response.body;
|
|
1481
|
+
}
|
|
1482
|
+
// ============================================================================
|
|
1483
|
+
// LOG STORAGE MANAGEMENT (Per-project log files for historical tracking)
|
|
1484
|
+
// ============================================================================
|
|
1485
|
+
/**
|
|
1486
|
+
* Save a log file for a source run.
|
|
1487
|
+
*/
|
|
1488
|
+
async saveLog(options) {
|
|
1489
|
+
const { projectId, source, contents } = options;
|
|
1490
|
+
// Validate inputs
|
|
1491
|
+
if (!projectId) {
|
|
1492
|
+
throw new Error('projectId is required');
|
|
1493
|
+
}
|
|
1494
|
+
if (!source) {
|
|
1495
|
+
throw new Error('source is required');
|
|
1496
|
+
}
|
|
1497
|
+
if (!contents || typeof contents !== 'object') {
|
|
1498
|
+
throw new Error('contents must be a non-empty object');
|
|
1499
|
+
}
|
|
1500
|
+
// Build request arguments
|
|
1501
|
+
const args = {
|
|
1502
|
+
subcommand: 'save_log',
|
|
1503
|
+
projectId,
|
|
1504
|
+
source,
|
|
1505
|
+
contents,
|
|
1506
|
+
};
|
|
1507
|
+
// Send request to server
|
|
1508
|
+
const request = this.buildRequest('rrext_store', { arguments: args });
|
|
1509
|
+
const response = await this.request(request);
|
|
1510
|
+
// Check for errors
|
|
1511
|
+
if (this.didFail(response)) {
|
|
1512
|
+
const errorMsg = response.message || 'Unknown error saving log';
|
|
1513
|
+
this.debugMessage(`Log save failed: ${errorMsg}`);
|
|
1514
|
+
throw new Error(errorMsg);
|
|
1515
|
+
}
|
|
1516
|
+
// Extract and return response
|
|
1517
|
+
this.debugMessage(`Log saved successfully: ${response.body?.filename}`);
|
|
1518
|
+
return response.body;
|
|
1519
|
+
}
|
|
1520
|
+
/**
|
|
1521
|
+
* Get a log file by source name and start time.
|
|
1522
|
+
*/
|
|
1523
|
+
async getLog(options) {
|
|
1524
|
+
const { projectId, source, startTime } = options;
|
|
1525
|
+
// Validate inputs
|
|
1526
|
+
if (!projectId) {
|
|
1527
|
+
throw new Error('projectId is required');
|
|
1528
|
+
}
|
|
1529
|
+
if (!source) {
|
|
1530
|
+
throw new Error('source is required');
|
|
1531
|
+
}
|
|
1532
|
+
if (startTime === undefined || startTime === null) {
|
|
1533
|
+
throw new Error('startTime is required');
|
|
1534
|
+
}
|
|
1535
|
+
// Build request
|
|
1536
|
+
const args = {
|
|
1537
|
+
subcommand: 'get_log',
|
|
1538
|
+
projectId,
|
|
1539
|
+
source,
|
|
1540
|
+
startTime,
|
|
1541
|
+
};
|
|
1542
|
+
// Send request to server
|
|
1543
|
+
const request = this.buildRequest('rrext_store', { arguments: args });
|
|
1544
|
+
const response = await this.request(request);
|
|
1545
|
+
// Check for errors
|
|
1546
|
+
if (this.didFail(response)) {
|
|
1547
|
+
const errorMsg = response.message || 'Unknown error retrieving log';
|
|
1548
|
+
this.debugMessage(`Log retrieval failed: ${errorMsg}`);
|
|
1549
|
+
throw new Error(errorMsg);
|
|
1550
|
+
}
|
|
1551
|
+
// Extract and return response
|
|
1552
|
+
this.debugMessage(`Log retrieved successfully: ${projectId}/${source}`);
|
|
1553
|
+
return response.body;
|
|
1554
|
+
}
|
|
1555
|
+
/**
|
|
1556
|
+
* List log files for a project.
|
|
1557
|
+
*/
|
|
1558
|
+
async listLogs(options) {
|
|
1559
|
+
const { projectId, source, page } = options;
|
|
1560
|
+
// Validate inputs
|
|
1561
|
+
if (!projectId) {
|
|
1562
|
+
throw new Error('projectId is required');
|
|
1563
|
+
}
|
|
1564
|
+
// Build request
|
|
1565
|
+
const args = {
|
|
1566
|
+
subcommand: 'list_logs',
|
|
1567
|
+
projectId,
|
|
1568
|
+
};
|
|
1569
|
+
// Add optional parameters
|
|
1570
|
+
if (source !== undefined) {
|
|
1571
|
+
args.source = source;
|
|
1572
|
+
}
|
|
1573
|
+
if (page !== undefined) {
|
|
1574
|
+
args.page = page;
|
|
1575
|
+
}
|
|
1576
|
+
// Send request to server
|
|
1577
|
+
const request = this.buildRequest('rrext_store', { arguments: args });
|
|
1578
|
+
const response = await this.request(request);
|
|
1579
|
+
// Check for errors
|
|
1580
|
+
if (this.didFail(response)) {
|
|
1581
|
+
const errorMsg = response.message || 'Unknown error listing logs';
|
|
1582
|
+
this.debugMessage(`Log list retrieval failed: ${errorMsg}`);
|
|
1583
|
+
throw new Error(errorMsg);
|
|
1584
|
+
}
|
|
1585
|
+
// Extract and return response
|
|
1586
|
+
const logCount = response.body?.total_count || 0;
|
|
1587
|
+
this.debugMessage(`Logs retrieved successfully: ${logCount} logs`);
|
|
1588
|
+
return response.body;
|
|
1589
|
+
}
|
|
1590
|
+
// ============================================================================
|
|
1591
|
+
// RAW REQUEST METHOD
|
|
1592
|
+
// ============================================================================
|
|
1593
|
+
/**
|
|
1594
|
+
* Send an arbitrary DAP command with command name, arguments, and optional token.
|
|
1595
|
+
*
|
|
1596
|
+
* This is a convenience method for callers that don't want to construct
|
|
1597
|
+
* full DAPMessage objects. It builds the request internally and delegates
|
|
1598
|
+
* to the underlying request() method.
|
|
1599
|
+
*
|
|
1600
|
+
* @param command - The DAP command name (e.g., 'rrext_services', 'rrext_monitor')
|
|
1601
|
+
* @param args - Optional arguments for the command
|
|
1602
|
+
* @param token - Optional task/session token
|
|
1603
|
+
* @param timeout - Optional per-request timeout in ms
|
|
1604
|
+
* @returns The response DAPMessage from the server
|
|
1605
|
+
*/
|
|
1606
|
+
async dapRequest(command, args, token, timeout) {
|
|
1607
|
+
const message = this.buildRequest(command, {
|
|
1608
|
+
arguments: args,
|
|
1609
|
+
token,
|
|
1610
|
+
});
|
|
1611
|
+
return await this.request(message, timeout);
|
|
1612
|
+
}
|
|
1613
|
+
// ============================================================================
|
|
1614
|
+
// CONTEXT MANAGER SUPPORT - Python-style async context manager
|
|
1615
|
+
// ============================================================================
|
|
1616
|
+
/**
|
|
1617
|
+
* Async disposal support for 'await using' pattern.
|
|
1618
|
+
* Equivalent to Python's __aexit__
|
|
1619
|
+
*/
|
|
1620
|
+
async [Symbol.asyncDispose]() {
|
|
1621
|
+
await this.disconnect();
|
|
1622
|
+
}
|
|
1623
|
+
/**
|
|
1624
|
+
* Static factory method for automatic connection management.
|
|
1625
|
+
* Equivalent to Python's async with pattern
|
|
1626
|
+
*/
|
|
1627
|
+
static async withConnection(config, callback) {
|
|
1628
|
+
const client = new RocketRideClient(config);
|
|
1629
|
+
try {
|
|
1630
|
+
await client.connect();
|
|
1631
|
+
return await callback(client);
|
|
1632
|
+
}
|
|
1633
|
+
finally {
|
|
1634
|
+
await client.disconnect();
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
// ============================================================================
|
|
1638
|
+
// SERVICES METHODS
|
|
1639
|
+
// ============================================================================
|
|
1640
|
+
/**
|
|
1641
|
+
* Retrieve all available service definitions from the server.
|
|
1642
|
+
*
|
|
1643
|
+
* Returns a dictionary containing all service definitions available on
|
|
1644
|
+
* the connected RocketRide server. Each service definition includes schemas,
|
|
1645
|
+
* UI schemas, and configuration metadata.
|
|
1646
|
+
*
|
|
1647
|
+
* @returns Promise resolving to object mapping service names to their definitions
|
|
1648
|
+
* @throws Error if the request fails or server returns an error
|
|
1649
|
+
*
|
|
1650
|
+
* @example
|
|
1651
|
+
* ```typescript
|
|
1652
|
+
* // Get all available services
|
|
1653
|
+
* const services = await client.getServices();
|
|
1654
|
+
*
|
|
1655
|
+
* // List available service names
|
|
1656
|
+
* for (const name of Object.keys(services)) {
|
|
1657
|
+
* console.log(`Available service: ${name}`);
|
|
1658
|
+
* }
|
|
1659
|
+
*
|
|
1660
|
+
* // Access a specific service's schema
|
|
1661
|
+
* if (services['ocr']) {
|
|
1662
|
+
* console.log('OCR schema:', services['ocr'].schema);
|
|
1663
|
+
* }
|
|
1664
|
+
* ```
|
|
1665
|
+
*/
|
|
1666
|
+
async getServices() {
|
|
1667
|
+
// Build services request (no service argument = get all)
|
|
1668
|
+
const request = this.buildRequest('rrext_services', {});
|
|
1669
|
+
// Send to server and wait for response
|
|
1670
|
+
const response = await this.request(request);
|
|
1671
|
+
// Check if request failed
|
|
1672
|
+
if (this.didFail(response)) {
|
|
1673
|
+
const errorMsg = response.message || 'Failed to retrieve services';
|
|
1674
|
+
throw new Error(`Failed to retrieve services: ${errorMsg}`);
|
|
1675
|
+
}
|
|
1676
|
+
// Return the body containing all service definitions
|
|
1677
|
+
return response.body || {};
|
|
1678
|
+
}
|
|
1679
|
+
/**
|
|
1680
|
+
* Retrieve a specific service definition from the server.
|
|
1681
|
+
*
|
|
1682
|
+
* Returns the definition for a specific service (connector) by name.
|
|
1683
|
+
* The definition includes schemas, UI schemas, and configuration metadata.
|
|
1684
|
+
*
|
|
1685
|
+
* @param service - Name of the service to retrieve (e.g., 'ocr', 'embed', 'chat')
|
|
1686
|
+
* @returns Promise resolving to service definition or undefined if not found
|
|
1687
|
+
* @throws Error if the request fails or server returns an error
|
|
1688
|
+
*
|
|
1689
|
+
* @example
|
|
1690
|
+
* ```typescript
|
|
1691
|
+
* // Get OCR service definition
|
|
1692
|
+
* const ocr = await client.getService('ocr');
|
|
1693
|
+
* if (ocr) {
|
|
1694
|
+
* console.log('OCR schema:', ocr.schema);
|
|
1695
|
+
* console.log('OCR UI schema:', ocr.uiSchema);
|
|
1696
|
+
* } else {
|
|
1697
|
+
* console.log('OCR service not available');
|
|
1698
|
+
* }
|
|
1699
|
+
* ```
|
|
1700
|
+
*/
|
|
1701
|
+
async getService(service) {
|
|
1702
|
+
if (!service) {
|
|
1703
|
+
throw new Error('Service name is required');
|
|
1704
|
+
}
|
|
1705
|
+
// Build services request with specific service name
|
|
1706
|
+
const request = this.buildRequest('rrext_services', {
|
|
1707
|
+
arguments: { service }
|
|
1708
|
+
});
|
|
1709
|
+
// Send to server and wait for response
|
|
1710
|
+
const response = await this.request(request);
|
|
1711
|
+
// Check if request failed
|
|
1712
|
+
if (this.didFail(response)) {
|
|
1713
|
+
const errorMsg = response.message || `Service '${service}' not found`;
|
|
1714
|
+
throw new Error(`Failed to retrieve service '${service}': ${errorMsg}`);
|
|
1715
|
+
}
|
|
1716
|
+
// Return the body containing the service definition
|
|
1717
|
+
return response.body;
|
|
1718
|
+
}
|
|
1719
|
+
// ============================================================================
|
|
1720
|
+
// ADDITIONAL CONVENIENCE METHODS
|
|
1721
|
+
// ============================================================================
|
|
1722
|
+
/**
|
|
1723
|
+
* Get connection information (TypeScript-specific convenience)
|
|
1724
|
+
*/
|
|
1725
|
+
getConnectionInfo() {
|
|
1726
|
+
return {
|
|
1727
|
+
connected: this.isConnected(),
|
|
1728
|
+
transport: 'WebSocket',
|
|
1729
|
+
uri: this._uri,
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1732
|
+
/**
|
|
1733
|
+
* Get API key (for debugging/validation)
|
|
1734
|
+
*/
|
|
1735
|
+
getApiKey() {
|
|
1736
|
+
return this._apikey;
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
export { RocketRideClient as default };
|
|
1740
|
+
//# sourceMappingURL=client.js.map
|