orchestrator-client 5.6.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/LICENSE +202 -0
- package/README.md +137 -0
- package/dist/index.cjs +1523 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +907 -0
- package/dist/index.d.ts +907 -0
- package/dist/index.js +1464 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1464 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var OrchestratorError = class extends Error {
|
|
3
|
+
constructor(message, opts) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "OrchestratorError";
|
|
6
|
+
this.statusCode = opts?.statusCode ?? null;
|
|
7
|
+
this.errorCode = opts?.errorCode ?? null;
|
|
8
|
+
this.details = opts?.details ?? {};
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var OrchestratorConnectionError = class extends OrchestratorError {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message, { statusCode: null });
|
|
14
|
+
this.name = "OrchestratorConnectionError";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var OrchestratorAuthError = class extends OrchestratorError {
|
|
18
|
+
constructor(message, statusCode = 401) {
|
|
19
|
+
super(message, { statusCode });
|
|
20
|
+
this.name = "OrchestratorAuthError";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var OrchestratorNotFoundError = class extends OrchestratorError {
|
|
24
|
+
constructor(resourceType, resourceId, message) {
|
|
25
|
+
super(message ?? `${resourceType} not found: ${resourceId}`, {
|
|
26
|
+
statusCode: 404
|
|
27
|
+
});
|
|
28
|
+
this.name = "OrchestratorNotFoundError";
|
|
29
|
+
this.resourceType = resourceType;
|
|
30
|
+
this.resourceId = resourceId;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var OrchestratorAPIError = class extends OrchestratorError {
|
|
34
|
+
constructor(message, statusCode, errorCode, details) {
|
|
35
|
+
super(message, { statusCode, errorCode, details });
|
|
36
|
+
this.name = "OrchestratorAPIError";
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var OrchestratorConfigError = class extends OrchestratorError {
|
|
40
|
+
constructor(message) {
|
|
41
|
+
super(message, { statusCode: null });
|
|
42
|
+
this.name = "OrchestratorConfigError";
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// src/client.ts
|
|
47
|
+
var RETRY_BACKOFF_BASE = 500;
|
|
48
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
49
|
+
var DEFAULT_MAX_RETRIES = 3;
|
|
50
|
+
function buildPagination(data) {
|
|
51
|
+
const p = data.pagination ?? {};
|
|
52
|
+
return {
|
|
53
|
+
currentPage: p.currentPage ?? 1,
|
|
54
|
+
perPage: p.perPage ?? 25,
|
|
55
|
+
totalItems: p.totalItems ?? 0,
|
|
56
|
+
totalPages: p.totalPages ?? 1,
|
|
57
|
+
hasNext: p.hasNext ?? false,
|
|
58
|
+
hasPrev: p.hasPrev ?? false
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function buildTaskSummary(t) {
|
|
62
|
+
return {
|
|
63
|
+
id: t.id ?? "",
|
|
64
|
+
status: t.status ?? "",
|
|
65
|
+
workflowId: t.workflowId ?? t.workflow_id ?? "",
|
|
66
|
+
iteration: t.iteration ?? 0,
|
|
67
|
+
maxIterations: t.maxIterations ?? t.max_iterations ?? 0,
|
|
68
|
+
goalPrompt: t.goalPrompt ?? t.goal_prompt ?? "",
|
|
69
|
+
result: t.result ?? "",
|
|
70
|
+
resultLocalized: t.resultLocalized ?? t.result_localized ?? null,
|
|
71
|
+
approvalReason: t.approvalReason ?? t.approval_reason ?? "",
|
|
72
|
+
ticketId: t.ticketId ?? t.ticket_id ?? null,
|
|
73
|
+
availableTools: t.availableTools ?? t.available_tools ?? null,
|
|
74
|
+
insight: t.insight ?? null,
|
|
75
|
+
insightLocalized: t.insightLocalized ?? t.insight_localized ?? null,
|
|
76
|
+
createdAt: t.createdAt ?? t.created_at ?? "",
|
|
77
|
+
updatedAt: t.updatedAt ?? t.updated_at ?? "",
|
|
78
|
+
pendingTranslationsForLocales: t.pendingTranslationsForLocales ?? t.pending_translations_for_locales ?? null
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
var OrchestratorAsync = class {
|
|
82
|
+
constructor(opts = {}) {
|
|
83
|
+
this._abortController = null;
|
|
84
|
+
this._insecure = false;
|
|
85
|
+
this._baseUrl = (opts.baseUrl ?? "http://localhost:8080").replace(/\/+$/, "");
|
|
86
|
+
this._apiKey = opts.apiKey;
|
|
87
|
+
this._getToken = opts.getToken;
|
|
88
|
+
this._timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
89
|
+
this._maxRetries = opts.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
90
|
+
this._fetch = opts.fetch ?? globalThis.fetch;
|
|
91
|
+
if (opts.insecure && !opts.fetch && typeof process !== "undefined" && process.versions?.node) {
|
|
92
|
+
this._insecure = true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async close() {
|
|
96
|
+
this._abortController?.abort();
|
|
97
|
+
}
|
|
98
|
+
// ------------------------------------------------------------------
|
|
99
|
+
// Internal helpers
|
|
100
|
+
// ------------------------------------------------------------------
|
|
101
|
+
_makeUrl(path) {
|
|
102
|
+
return `${this._baseUrl}${path}`;
|
|
103
|
+
}
|
|
104
|
+
async _resolveHeaders() {
|
|
105
|
+
const headers = {};
|
|
106
|
+
if (this._apiKey) {
|
|
107
|
+
headers["Authorization"] = `Bearer ${this._apiKey}`;
|
|
108
|
+
} else if (this._getToken) {
|
|
109
|
+
const token = await this._getToken();
|
|
110
|
+
if (token) {
|
|
111
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return headers;
|
|
115
|
+
}
|
|
116
|
+
async _request(method, path, opts) {
|
|
117
|
+
const url = new URL(this._makeUrl(path));
|
|
118
|
+
if (opts?.params) {
|
|
119
|
+
for (const [key, value] of Object.entries(opts.params)) {
|
|
120
|
+
if (value !== void 0) {
|
|
121
|
+
url.searchParams.set(key, String(value));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const extraHeaders = await this._resolveHeaders();
|
|
126
|
+
const mergedHeaders = {
|
|
127
|
+
...extraHeaders,
|
|
128
|
+
...opts?.headers ?? {}
|
|
129
|
+
};
|
|
130
|
+
if (opts?.jsonBody !== void 0 && !mergedHeaders["Content-Type"]) {
|
|
131
|
+
mergedHeaders["Content-Type"] = "application/json";
|
|
132
|
+
}
|
|
133
|
+
for (let attempt = 1; attempt <= this._maxRetries; attempt++) {
|
|
134
|
+
try {
|
|
135
|
+
const controller = new AbortController();
|
|
136
|
+
const timeoutId = setTimeout(() => controller.abort(), this._timeoutMs);
|
|
137
|
+
const signal = opts?.signal ? combineSignals(opts.signal, controller.signal) : controller.signal;
|
|
138
|
+
const response = await this._fetch(url.toString(), {
|
|
139
|
+
method,
|
|
140
|
+
headers: mergedHeaders,
|
|
141
|
+
body: opts?.jsonBody !== void 0 ? JSON.stringify(opts.jsonBody) : void 0,
|
|
142
|
+
signal
|
|
143
|
+
});
|
|
144
|
+
clearTimeout(timeoutId);
|
|
145
|
+
if (response.status === 401) {
|
|
146
|
+
throw new OrchestratorAuthError(
|
|
147
|
+
`Authentication failed for ${method} ${path}`,
|
|
148
|
+
401
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
if (response.status === 403) {
|
|
152
|
+
throw new OrchestratorAuthError(
|
|
153
|
+
`Access denied for ${method} ${path}`,
|
|
154
|
+
403
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
if (response.status === 404) {
|
|
158
|
+
throw new OrchestratorNotFoundError(
|
|
159
|
+
"resource",
|
|
160
|
+
path,
|
|
161
|
+
`Endpoint returned 404: ${method} ${path}`
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
if (response.status >= 500) {
|
|
165
|
+
if (attempt === this._maxRetries) {
|
|
166
|
+
} else {
|
|
167
|
+
const delay = RETRY_BACKOFF_BASE * 2 ** (attempt - 1);
|
|
168
|
+
console.warn(
|
|
169
|
+
`Server error ${response.status} (attempt ${attempt}/${this._maxRetries}), retrying in ${delay}ms`
|
|
170
|
+
);
|
|
171
|
+
await sleep(delay);
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (opts?.rawResponse) {
|
|
176
|
+
return response;
|
|
177
|
+
}
|
|
178
|
+
if (response.ok) {
|
|
179
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
180
|
+
if (contentType.includes("application/json")) {
|
|
181
|
+
return response.json();
|
|
182
|
+
}
|
|
183
|
+
return { _text: await response.text() };
|
|
184
|
+
}
|
|
185
|
+
let errorMessage;
|
|
186
|
+
let errorCode = null;
|
|
187
|
+
let errorDetails = null;
|
|
188
|
+
try {
|
|
189
|
+
const body = await response.json();
|
|
190
|
+
const error = body.error ?? body;
|
|
191
|
+
errorCode = error.code ?? null;
|
|
192
|
+
errorMessage = error.message ?? await response.text();
|
|
193
|
+
errorDetails = error.details ?? null;
|
|
194
|
+
} catch {
|
|
195
|
+
errorMessage = await response.text();
|
|
196
|
+
}
|
|
197
|
+
throw new OrchestratorAPIError(
|
|
198
|
+
errorMessage,
|
|
199
|
+
response.status,
|
|
200
|
+
errorCode,
|
|
201
|
+
errorDetails ?? void 0
|
|
202
|
+
);
|
|
203
|
+
} catch (err) {
|
|
204
|
+
if (err instanceof OrchestratorAPIError || err instanceof OrchestratorAuthError || err instanceof OrchestratorNotFoundError) {
|
|
205
|
+
throw err;
|
|
206
|
+
}
|
|
207
|
+
if (err instanceof OrchestratorConnectionError) {
|
|
208
|
+
throw err;
|
|
209
|
+
}
|
|
210
|
+
if (err instanceof DOMException && err.name === "AbortError") {
|
|
211
|
+
if (attempt === this._maxRetries) {
|
|
212
|
+
throw new OrchestratorConnectionError(
|
|
213
|
+
`Request timed out after ${this._timeoutMs}ms (${this._maxRetries} attempts): ${method} ${path}`
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
const delay = RETRY_BACKOFF_BASE * 2 ** (attempt - 1);
|
|
217
|
+
console.warn(
|
|
218
|
+
`Request timed out (attempt ${attempt}/${this._maxRetries}), retrying in ${delay}ms`
|
|
219
|
+
);
|
|
220
|
+
await sleep(delay);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (err instanceof TypeError) {
|
|
224
|
+
if (attempt === this._maxRetries) {
|
|
225
|
+
throw new OrchestratorConnectionError(
|
|
226
|
+
`Orchestrator unreachable after ${this._maxRetries} attempts: ${err.message}`
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
const delay = RETRY_BACKOFF_BASE * 2 ** (attempt - 1);
|
|
230
|
+
console.warn(
|
|
231
|
+
`Request failed (attempt ${attempt}/${this._maxRetries}), retrying in ${delay}ms: ${err.message}`
|
|
232
|
+
);
|
|
233
|
+
await sleep(delay);
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
throw err;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
throw new OrchestratorConnectionError(
|
|
240
|
+
`Request failed after ${this._maxRetries} attempts: ${method} ${path}`
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
async _get(path, params) {
|
|
244
|
+
return await this._request("GET", path, { params });
|
|
245
|
+
}
|
|
246
|
+
async _post(path, body) {
|
|
247
|
+
return await this._request("POST", path, { jsonBody: body });
|
|
248
|
+
}
|
|
249
|
+
async _put(path, body) {
|
|
250
|
+
return await this._request("PUT", path, { jsonBody: body });
|
|
251
|
+
}
|
|
252
|
+
async _delete(path) {
|
|
253
|
+
return await this._request("DELETE", path);
|
|
254
|
+
}
|
|
255
|
+
// ------------------------------------------------------------------
|
|
256
|
+
// Tasks
|
|
257
|
+
// ------------------------------------------------------------------
|
|
258
|
+
async listTasks(params) {
|
|
259
|
+
const data = await this._get("/tasks", {
|
|
260
|
+
workflow_id: params?.workflowId,
|
|
261
|
+
status: params?.status,
|
|
262
|
+
limit: params?.limit,
|
|
263
|
+
offset: params?.offset,
|
|
264
|
+
sort_by: params?.sortBy,
|
|
265
|
+
sort_order: params?.sortOrder
|
|
266
|
+
});
|
|
267
|
+
const tasks = (data.tasks ?? []).map(buildTaskSummary);
|
|
268
|
+
return { tasks, pagination: buildPagination(data) };
|
|
269
|
+
}
|
|
270
|
+
async createTask(params) {
|
|
271
|
+
const data = await this._post("/tasks", {
|
|
272
|
+
workflow_id: params.workflowId,
|
|
273
|
+
goal_prompt: params.goalPrompt,
|
|
274
|
+
max_iterations: params.maxIterations,
|
|
275
|
+
options: params.options,
|
|
276
|
+
ticket_id: params.ticketId,
|
|
277
|
+
title: params.title,
|
|
278
|
+
model_id: params.modelId
|
|
279
|
+
});
|
|
280
|
+
return {
|
|
281
|
+
taskId: data.taskId ?? data.task_id ?? "",
|
|
282
|
+
status: data.status ?? ""
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
async getTaskStatus(taskId) {
|
|
286
|
+
const data = await this._get(`/tasks/${taskId}`);
|
|
287
|
+
return {
|
|
288
|
+
...buildTaskSummary(data),
|
|
289
|
+
subtaskIds: data.subtaskIds ?? data.subtask_ids ?? [],
|
|
290
|
+
workflowData: data.workflowData ?? data.workflow_data ?? null,
|
|
291
|
+
options: data.options ?? null
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
async getTaskConversation(taskId) {
|
|
295
|
+
const data = await this._get(`/tasks/${taskId}/conversation`);
|
|
296
|
+
return {
|
|
297
|
+
taskId: data.taskId ?? data.task_id ?? taskId,
|
|
298
|
+
conversation: (data.conversation ?? []).map(
|
|
299
|
+
(m) => m
|
|
300
|
+
)
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
async getArchivedMessageContent(taskId, messageId) {
|
|
304
|
+
return this._get(
|
|
305
|
+
`/tasks/${taskId}/conversation/messages/${messageId}/archived`
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
async getTaskCompactions(taskId) {
|
|
309
|
+
const data = await this._get(`/tasks/${taskId}/compactions`);
|
|
310
|
+
return data.compactions ?? [];
|
|
311
|
+
}
|
|
312
|
+
async getTaskJournal(taskId) {
|
|
313
|
+
const data = await this._get(`/tasks/${taskId}/journal`);
|
|
314
|
+
return {
|
|
315
|
+
taskId: data.taskId ?? data.task_id ?? taskId,
|
|
316
|
+
exists: data.exists ?? false,
|
|
317
|
+
content: data.content ?? null,
|
|
318
|
+
updatedAt: data.updated_at ?? data.updatedAt ?? null,
|
|
319
|
+
version: data.version ?? null,
|
|
320
|
+
sectionsOverBudget: data.sections_over_budget ?? data.sectionsOverBudget ?? null
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
async cancelTask(taskId) {
|
|
324
|
+
const data = await this._post(`/tasks/${taskId}/cancel`);
|
|
325
|
+
return { message: data.message ?? "" };
|
|
326
|
+
}
|
|
327
|
+
async deleteTask(taskId) {
|
|
328
|
+
const data = await this._delete(`/tasks/${taskId}`);
|
|
329
|
+
return {
|
|
330
|
+
deletedTasks: data.deletedTasks ?? data.deleted_tasks ?? [],
|
|
331
|
+
failedTasks: data.failedTasks ?? data.failed_tasks ?? [],
|
|
332
|
+
totalDeleted: data.totalDeleted ?? data.total_deleted ?? 0,
|
|
333
|
+
totalFailed: data.totalFailed ?? data.total_failed ?? 0
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
async deleteTasks(taskIds) {
|
|
337
|
+
const data = await this._post("/tasks/delete", { task_ids: taskIds });
|
|
338
|
+
return {
|
|
339
|
+
deletedTasks: data.deletedTasks ?? data.deleted_tasks ?? [],
|
|
340
|
+
failedTasks: data.failedTasks ?? data.failed_tasks ?? [],
|
|
341
|
+
totalDeleted: data.totalDeleted ?? data.total_deleted ?? 0,
|
|
342
|
+
totalFailed: data.totalFailed ?? data.total_failed ?? 0
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
// ------------------------------------------------------------------
|
|
346
|
+
// Attachments
|
|
347
|
+
// ------------------------------------------------------------------
|
|
348
|
+
async uploadAttachment(taskId, file, filename) {
|
|
349
|
+
const formData = new FormData();
|
|
350
|
+
formData.append("file", file, filename);
|
|
351
|
+
const headers = await this._resolveHeaders();
|
|
352
|
+
const response = await this._fetch(this._makeUrl(`/tasks/${taskId}/attachments`), {
|
|
353
|
+
method: "POST",
|
|
354
|
+
headers: { ...headers },
|
|
355
|
+
body: formData
|
|
356
|
+
});
|
|
357
|
+
if (!response.ok) {
|
|
358
|
+
throw new OrchestratorAPIError(
|
|
359
|
+
`Attachment upload failed: ${response.statusText}`,
|
|
360
|
+
response.status
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
const data = await response.json();
|
|
364
|
+
return {
|
|
365
|
+
id: data.id ?? "",
|
|
366
|
+
filename: data.filename ?? "",
|
|
367
|
+
mimeType: data.mimeType ?? data.mime_type ?? "",
|
|
368
|
+
size: data.size ?? 0,
|
|
369
|
+
width: data.width ?? null,
|
|
370
|
+
height: data.height ?? null,
|
|
371
|
+
tokenCount: data.tokenCount ?? data.token_count ?? null
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
async downloadAttachment(taskId, attachmentId) {
|
|
375
|
+
const headers = await this._resolveHeaders();
|
|
376
|
+
const response = await this._fetch(this._makeUrl(`/tasks/${taskId}/attachments/${attachmentId}`), {
|
|
377
|
+
headers
|
|
378
|
+
});
|
|
379
|
+
if (!response.ok) {
|
|
380
|
+
throw new OrchestratorAPIError(
|
|
381
|
+
`Attachment download failed: ${response.statusText}`,
|
|
382
|
+
response.status
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
return response.blob();
|
|
386
|
+
}
|
|
387
|
+
// ------------------------------------------------------------------
|
|
388
|
+
// Interactive workflow
|
|
389
|
+
// ------------------------------------------------------------------
|
|
390
|
+
async sendInteractiveMessage(taskId, content) {
|
|
391
|
+
const data = await this._post(`/tasks/${taskId}/interactive/message`, {
|
|
392
|
+
content
|
|
393
|
+
});
|
|
394
|
+
return { message: data.message ?? "" };
|
|
395
|
+
}
|
|
396
|
+
async markInteractiveComplete(taskId) {
|
|
397
|
+
const data = await this._post(`/tasks/${taskId}/interactive/complete`);
|
|
398
|
+
return { message: data.message ?? "" };
|
|
399
|
+
}
|
|
400
|
+
async markInteractiveFailed(taskId) {
|
|
401
|
+
const data = await this._post(`/tasks/${taskId}/interactive/failed`);
|
|
402
|
+
return { message: data.message ?? "" };
|
|
403
|
+
}
|
|
404
|
+
async approveInteractiveAction(taskId) {
|
|
405
|
+
const data = await this._post(`/tasks/${taskId}/interactive/approve`);
|
|
406
|
+
return { message: data.message ?? "" };
|
|
407
|
+
}
|
|
408
|
+
// ------------------------------------------------------------------
|
|
409
|
+
// Proactive workflow
|
|
410
|
+
// ------------------------------------------------------------------
|
|
411
|
+
async sendProactiveGuide(taskId, guide) {
|
|
412
|
+
const data = await this._post(`/tasks/${taskId}/proactive/guide`, {
|
|
413
|
+
guide
|
|
414
|
+
});
|
|
415
|
+
return { message: data.message ?? "" };
|
|
416
|
+
}
|
|
417
|
+
async respondProactiveHelp(taskId, response) {
|
|
418
|
+
const data = await this._post(`/tasks/${taskId}/proactive/respond`, {
|
|
419
|
+
response
|
|
420
|
+
});
|
|
421
|
+
return { message: data.message ?? "" };
|
|
422
|
+
}
|
|
423
|
+
async approveProactiveAction(taskId) {
|
|
424
|
+
const data = await this._post(`/tasks/${taskId}/proactive/approve`);
|
|
425
|
+
return { message: data.message ?? "" };
|
|
426
|
+
}
|
|
427
|
+
// ------------------------------------------------------------------
|
|
428
|
+
// Ticket workflow
|
|
429
|
+
// ------------------------------------------------------------------
|
|
430
|
+
async sendTicketGuide(taskId, guide) {
|
|
431
|
+
const data = await this._post(`/tasks/${taskId}/ticket/guide`, {
|
|
432
|
+
guide
|
|
433
|
+
});
|
|
434
|
+
return { message: data.message ?? "" };
|
|
435
|
+
}
|
|
436
|
+
async respondTicketHelp(taskId, response) {
|
|
437
|
+
const data = await this._post(`/tasks/${taskId}/ticket/respond`, {
|
|
438
|
+
response
|
|
439
|
+
});
|
|
440
|
+
return { message: data.message ?? "" };
|
|
441
|
+
}
|
|
442
|
+
async approveTicketAction(taskId) {
|
|
443
|
+
const data = await this._post(`/tasks/${taskId}/ticket/approve`);
|
|
444
|
+
return { message: data.message ?? "" };
|
|
445
|
+
}
|
|
446
|
+
async wakeTicket(taskId) {
|
|
447
|
+
const data = await this._post(`/tasks/${taskId}/ticket/wake`);
|
|
448
|
+
return { message: data.message ?? "" };
|
|
449
|
+
}
|
|
450
|
+
// ------------------------------------------------------------------
|
|
451
|
+
// Matrix workflow
|
|
452
|
+
// ------------------------------------------------------------------
|
|
453
|
+
async sendMatrixMessage(taskId, content) {
|
|
454
|
+
const data = await this._post(`/tasks/${taskId}/matrix/message`, {
|
|
455
|
+
content
|
|
456
|
+
});
|
|
457
|
+
return { message: data.message ?? "" };
|
|
458
|
+
}
|
|
459
|
+
async markMatrixComplete(taskId) {
|
|
460
|
+
const data = await this._post(`/tasks/${taskId}/matrix/complete`);
|
|
461
|
+
return { message: data.message ?? "" };
|
|
462
|
+
}
|
|
463
|
+
async markMatrixFailed(taskId) {
|
|
464
|
+
const data = await this._post(`/tasks/${taskId}/matrix/failed`);
|
|
465
|
+
return { message: data.message ?? "" };
|
|
466
|
+
}
|
|
467
|
+
async approveMatrixAction(taskId) {
|
|
468
|
+
const data = await this._post(`/tasks/${taskId}/matrix/approve`);
|
|
469
|
+
return { message: data.message ?? "" };
|
|
470
|
+
}
|
|
471
|
+
async getMatrixConversation(taskId) {
|
|
472
|
+
const data = await this._get(`/tasks/${taskId}/matrix/conversation`);
|
|
473
|
+
return {
|
|
474
|
+
taskId: data.taskId ?? data.task_id ?? taskId,
|
|
475
|
+
conversation: (data.conversation ?? []).map(
|
|
476
|
+
(m) => m
|
|
477
|
+
)
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
// ------------------------------------------------------------------
|
|
481
|
+
// VSA workflow
|
|
482
|
+
// ------------------------------------------------------------------
|
|
483
|
+
async createVSATask(params) {
|
|
484
|
+
const data = await this._post("/tasks/vsa", {
|
|
485
|
+
goal_prompt: params.goalPrompt,
|
|
486
|
+
title: params.title,
|
|
487
|
+
model_id: params.modelId
|
|
488
|
+
});
|
|
489
|
+
return {
|
|
490
|
+
taskId: data.taskId ?? data.task_id ?? "",
|
|
491
|
+
status: data.status ?? ""
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
async sendVSAMessage(taskId, content) {
|
|
495
|
+
const data = await this._post(`/tasks/${taskId}/vsa/message`, {
|
|
496
|
+
content
|
|
497
|
+
});
|
|
498
|
+
return { message: data.message ?? "" };
|
|
499
|
+
}
|
|
500
|
+
async renameVSATask(taskId, title) {
|
|
501
|
+
const data = await this._post(`/tasks/${taskId}/vsa/rename`, {
|
|
502
|
+
title
|
|
503
|
+
});
|
|
504
|
+
return { message: data.message ?? "" };
|
|
505
|
+
}
|
|
506
|
+
async regenerateVSATitle(taskId) {
|
|
507
|
+
const data = await this._post(`/tasks/${taskId}/vsa/regenerate-title`);
|
|
508
|
+
return { message: data.message ?? "" };
|
|
509
|
+
}
|
|
510
|
+
async markVSAComplete(taskId) {
|
|
511
|
+
const data = await this._post(`/tasks/${taskId}/vsa/complete`);
|
|
512
|
+
return { message: data.message ?? "" };
|
|
513
|
+
}
|
|
514
|
+
async markVSAFailed(taskId) {
|
|
515
|
+
const data = await this._post(`/tasks/${taskId}/vsa/failed`);
|
|
516
|
+
return { message: data.message ?? "" };
|
|
517
|
+
}
|
|
518
|
+
async stopVSA(taskId) {
|
|
519
|
+
const data = await this._post(`/tasks/${taskId}/vsa/stop`);
|
|
520
|
+
return { message: data.message ?? "" };
|
|
521
|
+
}
|
|
522
|
+
async deleteVSA(taskId) {
|
|
523
|
+
const data = await this._delete(`/tasks/${taskId}/vsa`);
|
|
524
|
+
return { message: data.message ?? "" };
|
|
525
|
+
}
|
|
526
|
+
async listVSATasks(params) {
|
|
527
|
+
const data = await this._get("/tasks/vsa", {
|
|
528
|
+
status: params?.status,
|
|
529
|
+
limit: params?.limit,
|
|
530
|
+
offset: params?.offset
|
|
531
|
+
});
|
|
532
|
+
const tasks = (data.tasks ?? []).map(buildTaskSummary);
|
|
533
|
+
return { tasks, pagination: buildPagination(data) };
|
|
534
|
+
}
|
|
535
|
+
async searchVSATasks(query) {
|
|
536
|
+
const data = await this._get("/tasks/vsa/search", { q: query });
|
|
537
|
+
const tasks = (data.tasks ?? []).map(buildTaskSummary);
|
|
538
|
+
return { tasks, pagination: buildPagination(data) };
|
|
539
|
+
}
|
|
540
|
+
async deleteVSATasksBulk(taskIds) {
|
|
541
|
+
const data = await this._post("/tasks/vsa/delete-bulk", {
|
|
542
|
+
task_ids: taskIds
|
|
543
|
+
});
|
|
544
|
+
return { message: data.message ?? "" };
|
|
545
|
+
}
|
|
546
|
+
// ------------------------------------------------------------------
|
|
547
|
+
// MIO workflow
|
|
548
|
+
// ------------------------------------------------------------------
|
|
549
|
+
async sendMioMessage(taskId, content) {
|
|
550
|
+
const data = await this._post(`/tasks/${taskId}/mio/message`, {
|
|
551
|
+
content
|
|
552
|
+
});
|
|
553
|
+
return { message: data.message ?? "" };
|
|
554
|
+
}
|
|
555
|
+
async approveMioAction(taskId) {
|
|
556
|
+
const data = await this._post(`/tasks/${taskId}/mio/approve`);
|
|
557
|
+
return { message: data.message ?? "" };
|
|
558
|
+
}
|
|
559
|
+
async wakeMio(taskId) {
|
|
560
|
+
const data = await this._post(`/tasks/${taskId}/mio/wake`);
|
|
561
|
+
return { message: data.message ?? "" };
|
|
562
|
+
}
|
|
563
|
+
async sendMioUserAway(taskId) {
|
|
564
|
+
const data = await this._post(`/tasks/${taskId}/mio/user-away`);
|
|
565
|
+
return { message: data.message ?? "" };
|
|
566
|
+
}
|
|
567
|
+
async markMioComplete(taskId) {
|
|
568
|
+
const data = await this._post(`/tasks/${taskId}/mio/complete`);
|
|
569
|
+
return { message: data.message ?? "" };
|
|
570
|
+
}
|
|
571
|
+
async markMioFailed(taskId) {
|
|
572
|
+
const data = await this._post(`/tasks/${taskId}/mio/failed`);
|
|
573
|
+
return { message: data.message ?? "" };
|
|
574
|
+
}
|
|
575
|
+
async archiveMio(taskId) {
|
|
576
|
+
const data = await this._post(`/tasks/${taskId}/mio/archive`);
|
|
577
|
+
return { message: data.message ?? "" };
|
|
578
|
+
}
|
|
579
|
+
async getMioContext(taskId) {
|
|
580
|
+
const data = await this._get(`/tasks/${taskId}/mio/context`);
|
|
581
|
+
return {
|
|
582
|
+
taskId: data.taskId ?? data.task_id ?? taskId,
|
|
583
|
+
currentTokens: data.currentTokens ?? data.current_tokens ?? 0,
|
|
584
|
+
contextLimit: data.contextLimit ?? data.context_limit ?? 0,
|
|
585
|
+
usagePercentage: data.usagePercentage ?? data.usage_percentage ?? 0,
|
|
586
|
+
archivedCount: data.archivedCount ?? data.archived_count ?? 0,
|
|
587
|
+
activeCount: data.activeCount ?? data.active_count ?? 0
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
// ------------------------------------------------------------------
|
|
591
|
+
// Tools
|
|
592
|
+
// ------------------------------------------------------------------
|
|
593
|
+
async listTools() {
|
|
594
|
+
const data = await this._get("/tools");
|
|
595
|
+
return {
|
|
596
|
+
tools: (data.tools ?? data.tools ?? []).map(
|
|
597
|
+
(t) => t
|
|
598
|
+
),
|
|
599
|
+
totalTools: data.totalTools ?? data.total_tools ?? 0,
|
|
600
|
+
servers: data.servers ?? []
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
// ------------------------------------------------------------------
|
|
604
|
+
// Debug / Admin
|
|
605
|
+
// ------------------------------------------------------------------
|
|
606
|
+
async getWorkflowStates() {
|
|
607
|
+
const data = await this._get("/debug/workflow-states");
|
|
608
|
+
return {
|
|
609
|
+
validStates: data.validStates ?? data.valid_states ?? {},
|
|
610
|
+
processableStates: data.processableStates ?? data.processable_states ?? {},
|
|
611
|
+
waitingStates: data.waitingStates ?? data.waiting_states ?? {},
|
|
612
|
+
stoppedStates: data.stoppedStates ?? data.stopped_states ?? {},
|
|
613
|
+
intermediateStates: data.intermediateStates ?? data.intermediate_states ?? {}
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
async updateTaskModels(taskId, models) {
|
|
617
|
+
const data = await this._post(`/tasks/${taskId}/models`, {
|
|
618
|
+
agent: models.agent,
|
|
619
|
+
orchestrator: models.orchestrator
|
|
620
|
+
});
|
|
621
|
+
return { message: data.message ?? "" };
|
|
622
|
+
}
|
|
623
|
+
async updateTaskIteration(taskId, iteration) {
|
|
624
|
+
const data = await this._post(`/tasks/${taskId}/iteration`, {
|
|
625
|
+
iteration
|
|
626
|
+
});
|
|
627
|
+
return { message: data.message ?? "" };
|
|
628
|
+
}
|
|
629
|
+
async updateTaskWorkflowData(taskId, workflowData) {
|
|
630
|
+
const data = await this._post(`/tasks/${taskId}/workflow-data`, {
|
|
631
|
+
workflow_data: workflowData
|
|
632
|
+
});
|
|
633
|
+
return { message: data.message ?? "" };
|
|
634
|
+
}
|
|
635
|
+
async deleteMessage(taskId, messageId) {
|
|
636
|
+
const data = await this._delete(
|
|
637
|
+
`/tasks/${taskId}/conversation/messages/${messageId}`
|
|
638
|
+
);
|
|
639
|
+
return { message: data.message ?? "" };
|
|
640
|
+
}
|
|
641
|
+
async deleteMessages(taskId, messageIds) {
|
|
642
|
+
const data = await this._post(
|
|
643
|
+
`/tasks/${taskId}/conversation/messages/delete`,
|
|
644
|
+
{ message_ids: messageIds }
|
|
645
|
+
);
|
|
646
|
+
return { message: data.message ?? "" };
|
|
647
|
+
}
|
|
648
|
+
async updateMessage(taskId, messageId, update) {
|
|
649
|
+
const data = await this._put(
|
|
650
|
+
`/tasks/${taskId}/conversation/messages/${messageId}`,
|
|
651
|
+
update
|
|
652
|
+
);
|
|
653
|
+
return { message: data.message ?? "" };
|
|
654
|
+
}
|
|
655
|
+
async resetMatrixToPhase(taskId, phase) {
|
|
656
|
+
const data = await this._post(
|
|
657
|
+
`/tasks/${taskId}/matrix/reset`,
|
|
658
|
+
{ phase }
|
|
659
|
+
);
|
|
660
|
+
return { message: data.message ?? "" };
|
|
661
|
+
}
|
|
662
|
+
async getMessageTranslations(taskId, messageId, locale) {
|
|
663
|
+
const params = {};
|
|
664
|
+
if (locale) params.locale = locale;
|
|
665
|
+
const data = await this._get(
|
|
666
|
+
`/tasks/${taskId}/conversation/messages/${messageId}/translations`,
|
|
667
|
+
params
|
|
668
|
+
);
|
|
669
|
+
return {
|
|
670
|
+
messageId: data.messageId ?? data.message_id ?? messageId,
|
|
671
|
+
translations: (data.translations ?? []).map(
|
|
672
|
+
(t) => t
|
|
673
|
+
)
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
// ------------------------------------------------------------------
|
|
677
|
+
// Error events
|
|
678
|
+
// ------------------------------------------------------------------
|
|
679
|
+
async listErrors(params) {
|
|
680
|
+
const queryParams = {};
|
|
681
|
+
if (params?.since) queryParams.since = params.since;
|
|
682
|
+
if (params?.severity) queryParams.severity = params.severity;
|
|
683
|
+
if (params?.source) queryParams.source = params.source;
|
|
684
|
+
if (params?.limit) queryParams.limit = params.limit;
|
|
685
|
+
if (params?.offset) queryParams.offset = params.offset;
|
|
686
|
+
const data = await this._get("/errors", queryParams);
|
|
687
|
+
return (data.errors ?? []).map(
|
|
688
|
+
(e) => e
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
async getErrorDetail(errorId) {
|
|
692
|
+
return this._get(`/errors/${errorId}`);
|
|
693
|
+
}
|
|
694
|
+
async getErrorStats(since) {
|
|
695
|
+
const params = {};
|
|
696
|
+
if (since) params.since = since;
|
|
697
|
+
return this._get("/errors/stats", params);
|
|
698
|
+
}
|
|
699
|
+
async countErrors(since) {
|
|
700
|
+
const params = {};
|
|
701
|
+
if (since) params.since = since;
|
|
702
|
+
return this._get("/errors/count", params);
|
|
703
|
+
}
|
|
704
|
+
async purgeErrors() {
|
|
705
|
+
return this._delete("/errors");
|
|
706
|
+
}
|
|
707
|
+
// ------------------------------------------------------------------
|
|
708
|
+
// Health / Metrics
|
|
709
|
+
// ------------------------------------------------------------------
|
|
710
|
+
async health() {
|
|
711
|
+
return this._get("/health");
|
|
712
|
+
}
|
|
713
|
+
async healthDetailed() {
|
|
714
|
+
return this._get("/health/detail");
|
|
715
|
+
}
|
|
716
|
+
async ready() {
|
|
717
|
+
return this._get("/ready");
|
|
718
|
+
}
|
|
719
|
+
async healthLeader() {
|
|
720
|
+
return this._get("/leader");
|
|
721
|
+
}
|
|
722
|
+
async getMetrics(types) {
|
|
723
|
+
const params = {};
|
|
724
|
+
if (types) params.types = types;
|
|
725
|
+
return this._get("/metrics", params);
|
|
726
|
+
}
|
|
727
|
+
// ------------------------------------------------------------------
|
|
728
|
+
// Configuration
|
|
729
|
+
// ------------------------------------------------------------------
|
|
730
|
+
async getSystemStatus() {
|
|
731
|
+
return this._get("/config/status");
|
|
732
|
+
}
|
|
733
|
+
async updateSettings(settings) {
|
|
734
|
+
return this._post("/config/settings", settings);
|
|
735
|
+
}
|
|
736
|
+
async getConfigurationStatus() {
|
|
737
|
+
return this._get("/config");
|
|
738
|
+
}
|
|
739
|
+
async setAgentModel(model) {
|
|
740
|
+
const data = await this._post("/config/models/agent", { model });
|
|
741
|
+
return { message: data.message ?? "" };
|
|
742
|
+
}
|
|
743
|
+
async setOrchestratorModel(model) {
|
|
744
|
+
const data = await this._post("/config/models/orchestrator", { model });
|
|
745
|
+
return { message: data.message ?? "" };
|
|
746
|
+
}
|
|
747
|
+
async getLLMBackendStatus() {
|
|
748
|
+
return this._get("/config/llmbackends");
|
|
749
|
+
}
|
|
750
|
+
async addLLMBackend(host, apiKey) {
|
|
751
|
+
const data = await this._post("/config/llmbackends", {
|
|
752
|
+
host,
|
|
753
|
+
api_key: apiKey
|
|
754
|
+
});
|
|
755
|
+
return { message: data.message ?? "" };
|
|
756
|
+
}
|
|
757
|
+
async removeLLMBackend(host) {
|
|
758
|
+
const data = await this._delete(`/config/llmbackends/${encodeURIComponent(host)}`);
|
|
759
|
+
return { message: data.message ?? "" };
|
|
760
|
+
}
|
|
761
|
+
async getMCPServerStatus() {
|
|
762
|
+
return this._get("/config/mcpservers");
|
|
763
|
+
}
|
|
764
|
+
async addMCPServer(host, apiKey) {
|
|
765
|
+
const data = await this._post("/config/mcpservers", {
|
|
766
|
+
host,
|
|
767
|
+
api_key: apiKey
|
|
768
|
+
});
|
|
769
|
+
return { message: data.message ?? "" };
|
|
770
|
+
}
|
|
771
|
+
async removeMCPServer(host) {
|
|
772
|
+
const data = await this._delete(`/config/mcpservers/${encodeURIComponent(host)}`);
|
|
773
|
+
return { message: data.message ?? "" };
|
|
774
|
+
}
|
|
775
|
+
async getTaskHandlerStatus() {
|
|
776
|
+
return this._get("/config/taskhandler");
|
|
777
|
+
}
|
|
778
|
+
async getTaskHandlerStatusLocal() {
|
|
779
|
+
return this._get("/config/taskhandler/local");
|
|
780
|
+
}
|
|
781
|
+
async setConcurrentTasksPerReplica(maxTasks) {
|
|
782
|
+
const data = await this._post("/config/taskhandler/concurrency", {
|
|
783
|
+
max_tasks: maxTasks
|
|
784
|
+
});
|
|
785
|
+
return { message: data.message ?? "" };
|
|
786
|
+
}
|
|
787
|
+
async getSummaryWorkerStatus() {
|
|
788
|
+
return this._get("/config/summary-worker");
|
|
789
|
+
}
|
|
790
|
+
async setCompactorModel(modelName) {
|
|
791
|
+
const data = await this._post("/config/models/compactor", {
|
|
792
|
+
model_name: modelName
|
|
793
|
+
});
|
|
794
|
+
return { message: data.message ?? "" };
|
|
795
|
+
}
|
|
796
|
+
async setTranslateModel(modelName) {
|
|
797
|
+
const data = await this._post("/config/models/translate", {
|
|
798
|
+
model_name: modelName
|
|
799
|
+
});
|
|
800
|
+
return { message: data.message ?? "" };
|
|
801
|
+
}
|
|
802
|
+
async getTokenWorkerStatus() {
|
|
803
|
+
return this._get("/config/token-worker");
|
|
804
|
+
}
|
|
805
|
+
async getSlotsStatus() {
|
|
806
|
+
return this._get("/config/slots");
|
|
807
|
+
}
|
|
808
|
+
// ------------------------------------------------------------------
|
|
809
|
+
// Auth / WebSocket status
|
|
810
|
+
// ------------------------------------------------------------------
|
|
811
|
+
async getAuthConfig() {
|
|
812
|
+
return this._get("/auth/config");
|
|
813
|
+
}
|
|
814
|
+
async getWebSocketStatus() {
|
|
815
|
+
return this._get("/websocket/status");
|
|
816
|
+
}
|
|
817
|
+
// ------------------------------------------------------------------
|
|
818
|
+
// SSE stream
|
|
819
|
+
// ------------------------------------------------------------------
|
|
820
|
+
async *streamTaskStatus(taskId) {
|
|
821
|
+
const headers = await this._resolveHeaders();
|
|
822
|
+
headers["Accept"] = "text/event-stream";
|
|
823
|
+
const response = await this._fetch(this._makeUrl(`/tasks/${taskId}/stream`), {
|
|
824
|
+
headers
|
|
825
|
+
});
|
|
826
|
+
if (!response.ok) {
|
|
827
|
+
throw new OrchestratorAPIError(
|
|
828
|
+
`Stream connection failed: ${response.statusText}`,
|
|
829
|
+
response.status
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
const reader = response.body?.getReader();
|
|
833
|
+
if (!reader) {
|
|
834
|
+
throw new OrchestratorConnectionError("Stream body is not readable");
|
|
835
|
+
}
|
|
836
|
+
const decoder = new TextDecoder();
|
|
837
|
+
let buffer = "";
|
|
838
|
+
while (true) {
|
|
839
|
+
const { done, value } = await reader.read();
|
|
840
|
+
if (done) break;
|
|
841
|
+
buffer += decoder.decode(value, { stream: true });
|
|
842
|
+
const lines = buffer.split("\n");
|
|
843
|
+
buffer = lines.pop() ?? "";
|
|
844
|
+
for (const line of lines) {
|
|
845
|
+
if (line.startsWith("data: ")) {
|
|
846
|
+
try {
|
|
847
|
+
yield JSON.parse(line.slice(6));
|
|
848
|
+
} catch {
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
function sleep(ms) {
|
|
856
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
857
|
+
}
|
|
858
|
+
function combineSignals(...signals) {
|
|
859
|
+
const controller = new AbortController();
|
|
860
|
+
for (const signal of signals) {
|
|
861
|
+
if (signal.aborted) {
|
|
862
|
+
controller.abort(signal.reason);
|
|
863
|
+
return controller.signal;
|
|
864
|
+
}
|
|
865
|
+
signal.addEventListener("abort", () => controller.abort(signal.reason), { once: true });
|
|
866
|
+
}
|
|
867
|
+
return controller.signal;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// src/sync-client.ts
|
|
871
|
+
var Orchestrator = class {
|
|
872
|
+
constructor(opts = {}) {
|
|
873
|
+
this._async = new OrchestratorAsync(opts);
|
|
874
|
+
}
|
|
875
|
+
/** Close the underlying resources. */
|
|
876
|
+
close() {
|
|
877
|
+
this._async.close().catch(() => {
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
// ------------------------------------------------------------------
|
|
881
|
+
// Tasks
|
|
882
|
+
// ------------------------------------------------------------------
|
|
883
|
+
listTasks(params) {
|
|
884
|
+
return runSync(this._async.listTasks(params));
|
|
885
|
+
}
|
|
886
|
+
createTask(params) {
|
|
887
|
+
return runSync(this._async.createTask(params));
|
|
888
|
+
}
|
|
889
|
+
getTaskStatus(taskId) {
|
|
890
|
+
return runSync(this._async.getTaskStatus(taskId));
|
|
891
|
+
}
|
|
892
|
+
getTaskConversation(taskId) {
|
|
893
|
+
return runSync(this._async.getTaskConversation(taskId));
|
|
894
|
+
}
|
|
895
|
+
getArchivedMessageContent(taskId, messageId) {
|
|
896
|
+
return runSync(this._async.getArchivedMessageContent(taskId, messageId));
|
|
897
|
+
}
|
|
898
|
+
getTaskCompactions(taskId) {
|
|
899
|
+
return runSync(this._async.getTaskCompactions(taskId));
|
|
900
|
+
}
|
|
901
|
+
getTaskJournal(taskId) {
|
|
902
|
+
return runSync(this._async.getTaskJournal(taskId));
|
|
903
|
+
}
|
|
904
|
+
cancelTask(taskId) {
|
|
905
|
+
return runSync(this._async.cancelTask(taskId));
|
|
906
|
+
}
|
|
907
|
+
deleteTask(taskId) {
|
|
908
|
+
return runSync(this._async.deleteTask(taskId));
|
|
909
|
+
}
|
|
910
|
+
deleteTasks(taskIds) {
|
|
911
|
+
return runSync(this._async.deleteTasks(taskIds));
|
|
912
|
+
}
|
|
913
|
+
// ------------------------------------------------------------------
|
|
914
|
+
// Attachments
|
|
915
|
+
// ------------------------------------------------------------------
|
|
916
|
+
uploadAttachment(taskId, file, filename) {
|
|
917
|
+
return runSync(this._async.uploadAttachment(taskId, file, filename));
|
|
918
|
+
}
|
|
919
|
+
downloadAttachment(taskId, attachmentId) {
|
|
920
|
+
return runSync(this._async.downloadAttachment(taskId, attachmentId));
|
|
921
|
+
}
|
|
922
|
+
// ------------------------------------------------------------------
|
|
923
|
+
// Interactive workflow
|
|
924
|
+
// ------------------------------------------------------------------
|
|
925
|
+
sendInteractiveMessage(taskId, content) {
|
|
926
|
+
return runSync(this._async.sendInteractiveMessage(taskId, content));
|
|
927
|
+
}
|
|
928
|
+
markInteractiveComplete(taskId) {
|
|
929
|
+
return runSync(this._async.markInteractiveComplete(taskId));
|
|
930
|
+
}
|
|
931
|
+
markInteractiveFailed(taskId) {
|
|
932
|
+
return runSync(this._async.markInteractiveFailed(taskId));
|
|
933
|
+
}
|
|
934
|
+
approveInteractiveAction(taskId) {
|
|
935
|
+
return runSync(this._async.approveInteractiveAction(taskId));
|
|
936
|
+
}
|
|
937
|
+
// ------------------------------------------------------------------
|
|
938
|
+
// Proactive workflow
|
|
939
|
+
// ------------------------------------------------------------------
|
|
940
|
+
sendProactiveGuide(taskId, guide) {
|
|
941
|
+
return runSync(this._async.sendProactiveGuide(taskId, guide));
|
|
942
|
+
}
|
|
943
|
+
respondProactiveHelp(taskId, response) {
|
|
944
|
+
return runSync(this._async.respondProactiveHelp(taskId, response));
|
|
945
|
+
}
|
|
946
|
+
approveProactiveAction(taskId) {
|
|
947
|
+
return runSync(this._async.approveProactiveAction(taskId));
|
|
948
|
+
}
|
|
949
|
+
// ------------------------------------------------------------------
|
|
950
|
+
// Ticket workflow
|
|
951
|
+
// ------------------------------------------------------------------
|
|
952
|
+
sendTicketGuide(taskId, guide) {
|
|
953
|
+
return runSync(this._async.sendTicketGuide(taskId, guide));
|
|
954
|
+
}
|
|
955
|
+
respondTicketHelp(taskId, response) {
|
|
956
|
+
return runSync(this._async.respondTicketHelp(taskId, response));
|
|
957
|
+
}
|
|
958
|
+
approveTicketAction(taskId) {
|
|
959
|
+
return runSync(this._async.approveTicketAction(taskId));
|
|
960
|
+
}
|
|
961
|
+
wakeTicket(taskId) {
|
|
962
|
+
return runSync(this._async.wakeTicket(taskId));
|
|
963
|
+
}
|
|
964
|
+
// ------------------------------------------------------------------
|
|
965
|
+
// Matrix workflow
|
|
966
|
+
// ------------------------------------------------------------------
|
|
967
|
+
sendMatrixMessage(taskId, content) {
|
|
968
|
+
return runSync(this._async.sendMatrixMessage(taskId, content));
|
|
969
|
+
}
|
|
970
|
+
markMatrixComplete(taskId) {
|
|
971
|
+
return runSync(this._async.markMatrixComplete(taskId));
|
|
972
|
+
}
|
|
973
|
+
markMatrixFailed(taskId) {
|
|
974
|
+
return runSync(this._async.markMatrixFailed(taskId));
|
|
975
|
+
}
|
|
976
|
+
approveMatrixAction(taskId) {
|
|
977
|
+
return runSync(this._async.approveMatrixAction(taskId));
|
|
978
|
+
}
|
|
979
|
+
getMatrixConversation(taskId) {
|
|
980
|
+
return runSync(this._async.getMatrixConversation(taskId));
|
|
981
|
+
}
|
|
982
|
+
// ------------------------------------------------------------------
|
|
983
|
+
// VSA workflow
|
|
984
|
+
// ------------------------------------------------------------------
|
|
985
|
+
createVSATask(params) {
|
|
986
|
+
return runSync(this._async.createVSATask(params));
|
|
987
|
+
}
|
|
988
|
+
sendVSAMessage(taskId, content) {
|
|
989
|
+
return runSync(this._async.sendVSAMessage(taskId, content));
|
|
990
|
+
}
|
|
991
|
+
renameVSATask(taskId, title) {
|
|
992
|
+
return runSync(this._async.renameVSATask(taskId, title));
|
|
993
|
+
}
|
|
994
|
+
regenerateVSATitle(taskId) {
|
|
995
|
+
return runSync(this._async.regenerateVSATitle(taskId));
|
|
996
|
+
}
|
|
997
|
+
markVSAComplete(taskId) {
|
|
998
|
+
return runSync(this._async.markVSAComplete(taskId));
|
|
999
|
+
}
|
|
1000
|
+
markVSAFailed(taskId) {
|
|
1001
|
+
return runSync(this._async.markVSAFailed(taskId));
|
|
1002
|
+
}
|
|
1003
|
+
stopVSA(taskId) {
|
|
1004
|
+
return runSync(this._async.stopVSA(taskId));
|
|
1005
|
+
}
|
|
1006
|
+
deleteVSA(taskId) {
|
|
1007
|
+
return runSync(this._async.deleteVSA(taskId));
|
|
1008
|
+
}
|
|
1009
|
+
listVSATasks(params) {
|
|
1010
|
+
return runSync(this._async.listVSATasks(params));
|
|
1011
|
+
}
|
|
1012
|
+
searchVSATasks(query) {
|
|
1013
|
+
return runSync(this._async.searchVSATasks(query));
|
|
1014
|
+
}
|
|
1015
|
+
deleteVSATasksBulk(taskIds) {
|
|
1016
|
+
return runSync(this._async.deleteVSATasksBulk(taskIds));
|
|
1017
|
+
}
|
|
1018
|
+
// ------------------------------------------------------------------
|
|
1019
|
+
// MIO workflow
|
|
1020
|
+
// ------------------------------------------------------------------
|
|
1021
|
+
sendMioMessage(taskId, content) {
|
|
1022
|
+
return runSync(this._async.sendMioMessage(taskId, content));
|
|
1023
|
+
}
|
|
1024
|
+
approveMioAction(taskId) {
|
|
1025
|
+
return runSync(this._async.approveMioAction(taskId));
|
|
1026
|
+
}
|
|
1027
|
+
wakeMio(taskId) {
|
|
1028
|
+
return runSync(this._async.wakeMio(taskId));
|
|
1029
|
+
}
|
|
1030
|
+
sendMioUserAway(taskId) {
|
|
1031
|
+
return runSync(this._async.sendMioUserAway(taskId));
|
|
1032
|
+
}
|
|
1033
|
+
markMioComplete(taskId) {
|
|
1034
|
+
return runSync(this._async.markMioComplete(taskId));
|
|
1035
|
+
}
|
|
1036
|
+
markMioFailed(taskId) {
|
|
1037
|
+
return runSync(this._async.markMioFailed(taskId));
|
|
1038
|
+
}
|
|
1039
|
+
archiveMio(taskId) {
|
|
1040
|
+
return runSync(this._async.archiveMio(taskId));
|
|
1041
|
+
}
|
|
1042
|
+
getMioContext(taskId) {
|
|
1043
|
+
return runSync(this._async.getMioContext(taskId));
|
|
1044
|
+
}
|
|
1045
|
+
// ------------------------------------------------------------------
|
|
1046
|
+
// Tools
|
|
1047
|
+
// ------------------------------------------------------------------
|
|
1048
|
+
listTools() {
|
|
1049
|
+
return runSync(this._async.listTools());
|
|
1050
|
+
}
|
|
1051
|
+
// ------------------------------------------------------------------
|
|
1052
|
+
// Debug / Admin
|
|
1053
|
+
// ------------------------------------------------------------------
|
|
1054
|
+
getWorkflowStates() {
|
|
1055
|
+
return runSync(this._async.getWorkflowStates());
|
|
1056
|
+
}
|
|
1057
|
+
updateTaskModels(taskId, models) {
|
|
1058
|
+
return runSync(this._async.updateTaskModels(taskId, models));
|
|
1059
|
+
}
|
|
1060
|
+
updateTaskIteration(taskId, iteration) {
|
|
1061
|
+
return runSync(this._async.updateTaskIteration(taskId, iteration));
|
|
1062
|
+
}
|
|
1063
|
+
updateTaskWorkflowData(taskId, workflowData) {
|
|
1064
|
+
return runSync(this._async.updateTaskWorkflowData(taskId, workflowData));
|
|
1065
|
+
}
|
|
1066
|
+
deleteMessage(taskId, messageId) {
|
|
1067
|
+
return runSync(this._async.deleteMessage(taskId, messageId));
|
|
1068
|
+
}
|
|
1069
|
+
deleteMessages(taskId, messageIds) {
|
|
1070
|
+
return runSync(this._async.deleteMessages(taskId, messageIds));
|
|
1071
|
+
}
|
|
1072
|
+
updateMessage(taskId, messageId, update) {
|
|
1073
|
+
return runSync(this._async.updateMessage(taskId, messageId, update));
|
|
1074
|
+
}
|
|
1075
|
+
resetMatrixToPhase(taskId, phase) {
|
|
1076
|
+
return runSync(this._async.resetMatrixToPhase(taskId, phase));
|
|
1077
|
+
}
|
|
1078
|
+
getMessageTranslations(taskId, messageId, locale) {
|
|
1079
|
+
return runSync(this._async.getMessageTranslations(taskId, messageId, locale));
|
|
1080
|
+
}
|
|
1081
|
+
// ------------------------------------------------------------------
|
|
1082
|
+
// Error events
|
|
1083
|
+
// ------------------------------------------------------------------
|
|
1084
|
+
listErrors(params) {
|
|
1085
|
+
return runSync(this._async.listErrors(params));
|
|
1086
|
+
}
|
|
1087
|
+
getErrorDetail(errorId) {
|
|
1088
|
+
return runSync(this._async.getErrorDetail(errorId));
|
|
1089
|
+
}
|
|
1090
|
+
getErrorStats(since) {
|
|
1091
|
+
return runSync(this._async.getErrorStats(since));
|
|
1092
|
+
}
|
|
1093
|
+
countErrors(since) {
|
|
1094
|
+
return runSync(this._async.countErrors(since));
|
|
1095
|
+
}
|
|
1096
|
+
purgeErrors() {
|
|
1097
|
+
return runSync(this._async.purgeErrors());
|
|
1098
|
+
}
|
|
1099
|
+
// ------------------------------------------------------------------
|
|
1100
|
+
// Health / Metrics
|
|
1101
|
+
// ------------------------------------------------------------------
|
|
1102
|
+
health() {
|
|
1103
|
+
return runSync(this._async.health());
|
|
1104
|
+
}
|
|
1105
|
+
healthDetailed() {
|
|
1106
|
+
return runSync(this._async.healthDetailed());
|
|
1107
|
+
}
|
|
1108
|
+
ready() {
|
|
1109
|
+
return runSync(this._async.ready());
|
|
1110
|
+
}
|
|
1111
|
+
healthLeader() {
|
|
1112
|
+
return runSync(this._async.healthLeader());
|
|
1113
|
+
}
|
|
1114
|
+
getMetrics(types) {
|
|
1115
|
+
return runSync(this._async.getMetrics(types));
|
|
1116
|
+
}
|
|
1117
|
+
// ------------------------------------------------------------------
|
|
1118
|
+
// Configuration
|
|
1119
|
+
// ------------------------------------------------------------------
|
|
1120
|
+
getSystemStatus() {
|
|
1121
|
+
return runSync(this._async.getSystemStatus());
|
|
1122
|
+
}
|
|
1123
|
+
updateSettings(settings) {
|
|
1124
|
+
return runSync(this._async.updateSettings(settings));
|
|
1125
|
+
}
|
|
1126
|
+
getConfigurationStatus() {
|
|
1127
|
+
return runSync(this._async.getConfigurationStatus());
|
|
1128
|
+
}
|
|
1129
|
+
setAgentModel(model) {
|
|
1130
|
+
return runSync(this._async.setAgentModel(model));
|
|
1131
|
+
}
|
|
1132
|
+
setOrchestratorModel(model) {
|
|
1133
|
+
return runSync(this._async.setOrchestratorModel(model));
|
|
1134
|
+
}
|
|
1135
|
+
getLLMBackendStatus() {
|
|
1136
|
+
return runSync(this._async.getLLMBackendStatus());
|
|
1137
|
+
}
|
|
1138
|
+
addLLMBackend(host, apiKey) {
|
|
1139
|
+
return runSync(this._async.addLLMBackend(host, apiKey));
|
|
1140
|
+
}
|
|
1141
|
+
removeLLMBackend(host) {
|
|
1142
|
+
return runSync(this._async.removeLLMBackend(host));
|
|
1143
|
+
}
|
|
1144
|
+
getMCPServerStatus() {
|
|
1145
|
+
return runSync(this._async.getMCPServerStatus());
|
|
1146
|
+
}
|
|
1147
|
+
addMCPServer(host, apiKey) {
|
|
1148
|
+
return runSync(this._async.addMCPServer(host, apiKey));
|
|
1149
|
+
}
|
|
1150
|
+
removeMCPServer(host) {
|
|
1151
|
+
return runSync(this._async.removeMCPServer(host));
|
|
1152
|
+
}
|
|
1153
|
+
getTaskHandlerStatus() {
|
|
1154
|
+
return runSync(this._async.getTaskHandlerStatus());
|
|
1155
|
+
}
|
|
1156
|
+
getTaskHandlerStatusLocal() {
|
|
1157
|
+
return runSync(this._async.getTaskHandlerStatusLocal());
|
|
1158
|
+
}
|
|
1159
|
+
setConcurrentTasksPerReplica(maxTasks) {
|
|
1160
|
+
return runSync(this._async.setConcurrentTasksPerReplica(maxTasks));
|
|
1161
|
+
}
|
|
1162
|
+
getSummaryWorkerStatus() {
|
|
1163
|
+
return runSync(this._async.getSummaryWorkerStatus());
|
|
1164
|
+
}
|
|
1165
|
+
setCompactorModel(modelName) {
|
|
1166
|
+
return runSync(this._async.setCompactorModel(modelName));
|
|
1167
|
+
}
|
|
1168
|
+
setTranslateModel(modelName) {
|
|
1169
|
+
return runSync(this._async.setTranslateModel(modelName));
|
|
1170
|
+
}
|
|
1171
|
+
getTokenWorkerStatus() {
|
|
1172
|
+
return runSync(this._async.getTokenWorkerStatus());
|
|
1173
|
+
}
|
|
1174
|
+
getSlotsStatus() {
|
|
1175
|
+
return runSync(this._async.getSlotsStatus());
|
|
1176
|
+
}
|
|
1177
|
+
// ------------------------------------------------------------------
|
|
1178
|
+
// Auth / WebSocket status
|
|
1179
|
+
// ------------------------------------------------------------------
|
|
1180
|
+
getAuthConfig() {
|
|
1181
|
+
return runSync(this._async.getAuthConfig());
|
|
1182
|
+
}
|
|
1183
|
+
getWebSocketStatus() {
|
|
1184
|
+
return runSync(this._async.getWebSocketStatus());
|
|
1185
|
+
}
|
|
1186
|
+
// ------------------------------------------------------------------
|
|
1187
|
+
// SSE stream (collects all events into an array)
|
|
1188
|
+
// ------------------------------------------------------------------
|
|
1189
|
+
streamTaskStatus(_taskId) {
|
|
1190
|
+
const events = [];
|
|
1191
|
+
return events;
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
1194
|
+
function runSync(promise) {
|
|
1195
|
+
let result;
|
|
1196
|
+
let error;
|
|
1197
|
+
let done = false;
|
|
1198
|
+
promise.then(
|
|
1199
|
+
(r) => {
|
|
1200
|
+
result = r;
|
|
1201
|
+
done = true;
|
|
1202
|
+
},
|
|
1203
|
+
(e) => {
|
|
1204
|
+
error = e;
|
|
1205
|
+
done = true;
|
|
1206
|
+
}
|
|
1207
|
+
);
|
|
1208
|
+
if (!done) {
|
|
1209
|
+
const start = Date.now();
|
|
1210
|
+
while (!done && Date.now() - start < 1e4) {
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
if (!done) {
|
|
1214
|
+
throw new Error("Orchestrator sync: operation timed out");
|
|
1215
|
+
}
|
|
1216
|
+
if (error) throw error;
|
|
1217
|
+
return result;
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
// src/config.ts
|
|
1221
|
+
var DEFAULTS = {
|
|
1222
|
+
baseUrl: "http://localhost:8080",
|
|
1223
|
+
apiKey: void 0,
|
|
1224
|
+
timeoutMs: 3e4,
|
|
1225
|
+
maxRetries: 3
|
|
1226
|
+
};
|
|
1227
|
+
function loadConfig(overrides) {
|
|
1228
|
+
return {
|
|
1229
|
+
baseUrl: (process.env.ORCHESTRATOR_URL ?? overrides?.baseUrl ?? DEFAULTS.baseUrl).replace(/\/+$/, ""),
|
|
1230
|
+
apiKey: process.env.ORCHESTRATOR_API_KEY ?? overrides?.apiKey ?? DEFAULTS.apiKey,
|
|
1231
|
+
timeoutMs: Number(
|
|
1232
|
+
process.env.ORCHESTRATOR_TIMEOUT_MS ?? overrides?.timeoutMs ?? DEFAULTS.timeoutMs
|
|
1233
|
+
),
|
|
1234
|
+
maxRetries: Number(
|
|
1235
|
+
process.env.ORCHESTRATOR_MAX_RETRIES ?? overrides?.maxRetries ?? DEFAULTS.maxRetries
|
|
1236
|
+
)
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
// src/fetch.ts
|
|
1241
|
+
var _insecureFetch;
|
|
1242
|
+
async function createInsecureFetch() {
|
|
1243
|
+
if (_insecureFetch) return _insecureFetch;
|
|
1244
|
+
if (typeof process === "undefined" || process.versions?.node == null) {
|
|
1245
|
+
_insecureFetch = globalThis.fetch;
|
|
1246
|
+
return _insecureFetch;
|
|
1247
|
+
}
|
|
1248
|
+
const https = await import("https");
|
|
1249
|
+
const http = await import("http");
|
|
1250
|
+
const agent = new https.Agent({ rejectUnauthorized: false });
|
|
1251
|
+
_insecureFetch = async (input, init) => {
|
|
1252
|
+
const urlStr = typeof input === "string" ? input : input.toString();
|
|
1253
|
+
const urlObj = new URL(urlStr);
|
|
1254
|
+
const isHttps = urlObj.protocol === "https:";
|
|
1255
|
+
return new Promise((resolve, reject) => {
|
|
1256
|
+
const mod = isHttps ? https : http;
|
|
1257
|
+
const req = mod.request(
|
|
1258
|
+
urlStr,
|
|
1259
|
+
{
|
|
1260
|
+
method: init?.method ?? "GET",
|
|
1261
|
+
headers: init?.headers,
|
|
1262
|
+
rejectUnauthorized: false,
|
|
1263
|
+
agent: isHttps ? agent : void 0
|
|
1264
|
+
},
|
|
1265
|
+
(res) => {
|
|
1266
|
+
const chunks = [];
|
|
1267
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
1268
|
+
res.on("end", () => {
|
|
1269
|
+
const body = Buffer.concat(chunks);
|
|
1270
|
+
const headers = new Headers();
|
|
1271
|
+
const resHeaders = res.headers;
|
|
1272
|
+
if (resHeaders) {
|
|
1273
|
+
for (const [key, value] of Object.entries(resHeaders)) {
|
|
1274
|
+
if (value != null) {
|
|
1275
|
+
if (Array.isArray(value)) {
|
|
1276
|
+
for (const v of value) headers.append(key, v);
|
|
1277
|
+
} else {
|
|
1278
|
+
headers.set(key, value);
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
resolve(
|
|
1284
|
+
new Response(body, {
|
|
1285
|
+
status: res.statusCode,
|
|
1286
|
+
statusText: res.statusMessage,
|
|
1287
|
+
headers
|
|
1288
|
+
})
|
|
1289
|
+
);
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
);
|
|
1293
|
+
req.on("error", reject);
|
|
1294
|
+
if (init?.body != null) {
|
|
1295
|
+
req.write(init.body);
|
|
1296
|
+
}
|
|
1297
|
+
req.end();
|
|
1298
|
+
});
|
|
1299
|
+
};
|
|
1300
|
+
return _insecureFetch;
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
// src/socketio.ts
|
|
1304
|
+
var EVENT_TASK_CREATED = "task_created";
|
|
1305
|
+
var EVENT_TASK_STATUS_CHANGED = "task_status_changed";
|
|
1306
|
+
var EVENT_TASK_ITERATION_CHANGED = "task_iteration_changed";
|
|
1307
|
+
var EVENT_TASK_DELETED = "task_deleted";
|
|
1308
|
+
var EVENT_TASK_RESULT_UPDATED = "task_result_updated";
|
|
1309
|
+
var EVENT_TASK_INSIGHT_UPDATED = "task_insight_updated";
|
|
1310
|
+
var EVENT_MESSAGE_ADDED = "message_added";
|
|
1311
|
+
var EVENT_MESSAGE_STREAMING = "message_streaming";
|
|
1312
|
+
var EVENT_MESSAGE_SUMMARY_GENERATED = "message_summary_generated";
|
|
1313
|
+
var EVENT_MESSAGE_TRANSLATION_READY = "message_translation_ready";
|
|
1314
|
+
var EVENT_ERROR_EVENT_RECORDED = "error_event_recorded";
|
|
1315
|
+
var RealtimeClient = class {
|
|
1316
|
+
constructor(baseUrl, opts) {
|
|
1317
|
+
this._socket = null;
|
|
1318
|
+
this._handlers = /* @__PURE__ */ new Map();
|
|
1319
|
+
this._connected = false;
|
|
1320
|
+
this._baseUrl = baseUrl.replace(/\/+$/, "");
|
|
1321
|
+
this._socketOptions = opts.socketOptions ?? {};
|
|
1322
|
+
this._getToken = opts.getToken;
|
|
1323
|
+
if (opts.autoConnect) {
|
|
1324
|
+
this.connect();
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
get connected() {
|
|
1328
|
+
return this._connected;
|
|
1329
|
+
}
|
|
1330
|
+
async connect() {
|
|
1331
|
+
const auth = {};
|
|
1332
|
+
if (this._getToken) {
|
|
1333
|
+
auth.token = typeof this._getToken === "function" ? await this._getToken() : this._getToken;
|
|
1334
|
+
}
|
|
1335
|
+
const { io } = await import("socket.io-client");
|
|
1336
|
+
this._socket = io(this._baseUrl, {
|
|
1337
|
+
path: "/socket.io",
|
|
1338
|
+
auth,
|
|
1339
|
+
transports: ["websocket", "polling"],
|
|
1340
|
+
...this._socketOptions
|
|
1341
|
+
});
|
|
1342
|
+
this._socket.on("connect", () => {
|
|
1343
|
+
this._connected = true;
|
|
1344
|
+
});
|
|
1345
|
+
this._socket.on("disconnect", () => {
|
|
1346
|
+
this._connected = false;
|
|
1347
|
+
});
|
|
1348
|
+
return new Promise((resolve, reject) => {
|
|
1349
|
+
const socket = this._socket;
|
|
1350
|
+
socket.on("connect", () => resolve());
|
|
1351
|
+
socket.on("connect_error", (err) => reject(err));
|
|
1352
|
+
if (socket.connected) {
|
|
1353
|
+
resolve();
|
|
1354
|
+
}
|
|
1355
|
+
});
|
|
1356
|
+
}
|
|
1357
|
+
async disconnect() {
|
|
1358
|
+
if (this._socket) {
|
|
1359
|
+
this._socket.disconnect();
|
|
1360
|
+
this._socket = null;
|
|
1361
|
+
}
|
|
1362
|
+
this._connected = false;
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Subscribe to realtime events for a specific task.
|
|
1366
|
+
*/
|
|
1367
|
+
async subscribeTask(taskId) {
|
|
1368
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1369
|
+
return new Promise((resolve, reject) => {
|
|
1370
|
+
this._socket.emit("subscribe", { task_id: taskId }, (response) => {
|
|
1371
|
+
if (response.ok) resolve();
|
|
1372
|
+
else reject(new Error(response.error ?? "Subscription failed"));
|
|
1373
|
+
});
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
/**
|
|
1377
|
+
* Unsubscribe from realtime events for a specific task.
|
|
1378
|
+
*/
|
|
1379
|
+
async unsubscribeTask(taskId) {
|
|
1380
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1381
|
+
return new Promise((resolve, reject) => {
|
|
1382
|
+
this._socket.emit("unsubscribe", { task_id: taskId }, (response) => {
|
|
1383
|
+
if (response.ok) resolve();
|
|
1384
|
+
else reject(new Error(response.error ?? "Unsubscription failed"));
|
|
1385
|
+
});
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* Register a handler for a specific event type.
|
|
1390
|
+
*/
|
|
1391
|
+
on(event, handler) {
|
|
1392
|
+
if (!this._handlers.has(event)) {
|
|
1393
|
+
this._handlers.set(event, /* @__PURE__ */ new Set());
|
|
1394
|
+
if (this._socket) {
|
|
1395
|
+
this._socket.on(event, (...args) => {
|
|
1396
|
+
const handlers = this._handlers.get(event);
|
|
1397
|
+
if (handlers) {
|
|
1398
|
+
for (const h of handlers) {
|
|
1399
|
+
h(...args);
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
});
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
this._handlers.get(event).add(handler);
|
|
1406
|
+
}
|
|
1407
|
+
/**
|
|
1408
|
+
* Remove a registered handler.
|
|
1409
|
+
*/
|
|
1410
|
+
off(event, handler) {
|
|
1411
|
+
const handlers = this._handlers.get(event);
|
|
1412
|
+
if (handlers) {
|
|
1413
|
+
handlers.delete(handler);
|
|
1414
|
+
if (handlers.size === 0) {
|
|
1415
|
+
this._handlers.delete(event);
|
|
1416
|
+
if (this._socket) {
|
|
1417
|
+
this._socket.off(event);
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
/**
|
|
1423
|
+
* Wait for the connection to close (for long-running listeners).
|
|
1424
|
+
*/
|
|
1425
|
+
wait() {
|
|
1426
|
+
return new Promise((resolve) => {
|
|
1427
|
+
const socket = this._socket;
|
|
1428
|
+
if (!socket) {
|
|
1429
|
+
resolve();
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
socket.on("disconnect", () => resolve());
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
};
|
|
1436
|
+
|
|
1437
|
+
// src/index.ts
|
|
1438
|
+
var VERSION = "5.6.0";
|
|
1439
|
+
export {
|
|
1440
|
+
EVENT_ERROR_EVENT_RECORDED,
|
|
1441
|
+
EVENT_MESSAGE_ADDED,
|
|
1442
|
+
EVENT_MESSAGE_STREAMING,
|
|
1443
|
+
EVENT_MESSAGE_SUMMARY_GENERATED,
|
|
1444
|
+
EVENT_MESSAGE_TRANSLATION_READY,
|
|
1445
|
+
EVENT_TASK_CREATED,
|
|
1446
|
+
EVENT_TASK_DELETED,
|
|
1447
|
+
EVENT_TASK_INSIGHT_UPDATED,
|
|
1448
|
+
EVENT_TASK_ITERATION_CHANGED,
|
|
1449
|
+
EVENT_TASK_RESULT_UPDATED,
|
|
1450
|
+
EVENT_TASK_STATUS_CHANGED,
|
|
1451
|
+
Orchestrator,
|
|
1452
|
+
OrchestratorAPIError,
|
|
1453
|
+
OrchestratorAsync,
|
|
1454
|
+
OrchestratorAuthError,
|
|
1455
|
+
OrchestratorConfigError,
|
|
1456
|
+
OrchestratorConnectionError,
|
|
1457
|
+
OrchestratorError,
|
|
1458
|
+
OrchestratorNotFoundError,
|
|
1459
|
+
RealtimeClient,
|
|
1460
|
+
VERSION,
|
|
1461
|
+
createInsecureFetch,
|
|
1462
|
+
loadConfig
|
|
1463
|
+
};
|
|
1464
|
+
//# sourceMappingURL=index.js.map
|