orchestrator-client 5.7.0 → 5.7.2
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/dist/index.cjs +628 -303
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +330 -78
- package/dist/index.d.ts +330 -78
- package/dist/index.js +628 -303
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -90,6 +90,7 @@ var OrchestratorAsync = class {
|
|
|
90
90
|
this._getToken = opts.getToken;
|
|
91
91
|
this._timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
92
92
|
this._maxRetries = opts.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
93
|
+
this._locale = opts.locale;
|
|
93
94
|
this._fetch = opts.fetch ?? globalThis.fetch;
|
|
94
95
|
if (opts.insecure && !opts.fetch && typeof process !== "undefined" && process.versions?.node) {
|
|
95
96
|
this._insecure = true;
|
|
@@ -114,6 +115,9 @@ var OrchestratorAsync = class {
|
|
|
114
115
|
headers.Authorization = `Bearer ${token}`;
|
|
115
116
|
}
|
|
116
117
|
}
|
|
118
|
+
if (this._locale) {
|
|
119
|
+
headers["X-Locale"] = this._locale;
|
|
120
|
+
}
|
|
117
121
|
return headers;
|
|
118
122
|
}
|
|
119
123
|
async _request(method, path, opts) {
|
|
@@ -259,13 +263,17 @@ var OrchestratorAsync = class {
|
|
|
259
263
|
// Tasks
|
|
260
264
|
// ------------------------------------------------------------------
|
|
261
265
|
async listTasks(params) {
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
266
|
+
const headers = {};
|
|
267
|
+
if (params?.locale) headers["X-Locale"] = params.locale;
|
|
268
|
+
const data = await this._request("GET", "/tasks", {
|
|
269
|
+
params: {
|
|
270
|
+
page: params?.page,
|
|
271
|
+
limit: params?.limit,
|
|
272
|
+
order_by: params?.orderBy,
|
|
273
|
+
order_direction: params?.orderDirection,
|
|
274
|
+
workflow_id: params?.workflowId
|
|
275
|
+
},
|
|
276
|
+
headers
|
|
269
277
|
});
|
|
270
278
|
const tasks = (data.tasks ?? []).map(
|
|
271
279
|
buildTaskSummary
|
|
@@ -273,22 +281,36 @@ var OrchestratorAsync = class {
|
|
|
273
281
|
return { tasks, pagination: buildPagination(data) };
|
|
274
282
|
}
|
|
275
283
|
async createTask(params) {
|
|
276
|
-
const data = await this._post("/
|
|
284
|
+
const data = await this._post("/task/create", {
|
|
277
285
|
workflow_id: params.workflowId,
|
|
278
286
|
goal_prompt: params.goalPrompt,
|
|
279
287
|
max_iterations: params.maxIterations,
|
|
280
|
-
|
|
288
|
+
reasoning_effort: params.reasoningEffort,
|
|
289
|
+
system_prompt: params.systemPrompt,
|
|
290
|
+
developer_prompt: params.developerPrompt,
|
|
281
291
|
ticket_id: params.ticketId,
|
|
282
|
-
|
|
283
|
-
|
|
292
|
+
ticket_text: params.ticketText,
|
|
293
|
+
summary: params.summary,
|
|
294
|
+
problem_summary: params.problemSummary,
|
|
295
|
+
solution_strategy: params.solutionStrategy,
|
|
296
|
+
agent_model_id: params.agentModelId,
|
|
297
|
+
orchestrator_model_id: params.orchestratorModelId,
|
|
298
|
+
available_tools: params.availableTools,
|
|
299
|
+
attachment_ids: params.attachmentIds,
|
|
300
|
+
options: params.options
|
|
284
301
|
});
|
|
285
302
|
return {
|
|
286
303
|
taskId: data.taskId ?? data.task_id ?? "",
|
|
287
304
|
status: data.status ?? ""
|
|
288
305
|
};
|
|
289
306
|
}
|
|
290
|
-
async getTaskStatus(taskId) {
|
|
291
|
-
const
|
|
307
|
+
async getTaskStatus(taskId, locale) {
|
|
308
|
+
const headers = {};
|
|
309
|
+
if (locale) headers["X-Locale"] = locale;
|
|
310
|
+
const data = await this._request("GET", "/task/status", {
|
|
311
|
+
params: { task_id: taskId },
|
|
312
|
+
headers
|
|
313
|
+
});
|
|
292
314
|
return {
|
|
293
315
|
...buildTaskSummary(data),
|
|
294
316
|
subtaskIds: data.subtaskIds ?? data.subtask_ids ?? [],
|
|
@@ -296,10 +318,24 @@ var OrchestratorAsync = class {
|
|
|
296
318
|
options: data.options ?? null
|
|
297
319
|
};
|
|
298
320
|
}
|
|
299
|
-
async
|
|
300
|
-
const data = await this.
|
|
301
|
-
|
|
302
|
-
|
|
321
|
+
async setTaskStatus(taskId, status) {
|
|
322
|
+
const data = await this._post("/task/set_status", {
|
|
323
|
+
task_id: taskId,
|
|
324
|
+
status
|
|
325
|
+
});
|
|
326
|
+
return { message: data.message ?? "" };
|
|
327
|
+
}
|
|
328
|
+
async getTaskConversation(taskId, params) {
|
|
329
|
+
const headers = {};
|
|
330
|
+
if (params?.locale) headers["X-Locale"] = params.locale;
|
|
331
|
+
const data = await this._request("GET", "/task/conversation", {
|
|
332
|
+
params: {
|
|
333
|
+
task_id: taskId,
|
|
334
|
+
include_summaries: params?.includeSummaries,
|
|
335
|
+
exclude_archived: params?.excludeArchived
|
|
336
|
+
},
|
|
337
|
+
headers
|
|
338
|
+
});
|
|
303
339
|
return {
|
|
304
340
|
taskId: data.taskId ?? data.task_id ?? taskId,
|
|
305
341
|
conversation: (data.conversation ?? []).map((m) => m)
|
|
@@ -307,19 +343,19 @@ var OrchestratorAsync = class {
|
|
|
307
343
|
}
|
|
308
344
|
async getArchivedMessageContent(taskId, messageId) {
|
|
309
345
|
return this._get(
|
|
310
|
-
|
|
346
|
+
"/task/message/archived-content",
|
|
347
|
+
{ task_id: taskId, message_id: messageId }
|
|
311
348
|
);
|
|
312
349
|
}
|
|
313
350
|
async getTaskCompactions(taskId) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
);
|
|
317
|
-
return data.compactions ?? [];
|
|
351
|
+
return this._get("/task/compactions", {
|
|
352
|
+
task_id: taskId
|
|
353
|
+
});
|
|
318
354
|
}
|
|
319
355
|
async getTaskJournal(taskId) {
|
|
320
|
-
const data = await this._get(
|
|
321
|
-
|
|
322
|
-
);
|
|
356
|
+
const data = await this._get("/task/journal", {
|
|
357
|
+
task_id: taskId
|
|
358
|
+
});
|
|
323
359
|
return {
|
|
324
360
|
taskId: data.taskId ?? data.task_id ?? taskId,
|
|
325
361
|
exists: data.exists ?? false,
|
|
@@ -330,15 +366,22 @@ var OrchestratorAsync = class {
|
|
|
330
366
|
};
|
|
331
367
|
}
|
|
332
368
|
async cancelTask(taskId) {
|
|
333
|
-
const data = await this._post(
|
|
334
|
-
|
|
335
|
-
);
|
|
336
|
-
return {
|
|
369
|
+
const data = await this._post("/task/cancel", {
|
|
370
|
+
task_id: taskId
|
|
371
|
+
});
|
|
372
|
+
return {
|
|
373
|
+
taskId: data.taskId ?? data.task_id ?? taskId,
|
|
374
|
+
killed: data.killed ?? false,
|
|
375
|
+
via: data.via ?? "none",
|
|
376
|
+
holderId: data.holderId ?? data.holder_id ?? void 0,
|
|
377
|
+
reason: data.reason ?? void 0,
|
|
378
|
+
message: data.message ?? ""
|
|
379
|
+
};
|
|
337
380
|
}
|
|
338
381
|
async deleteTask(taskId) {
|
|
339
|
-
const data = await this.
|
|
340
|
-
|
|
341
|
-
);
|
|
382
|
+
const data = await this._post("/task/delete", {
|
|
383
|
+
task_id: taskId
|
|
384
|
+
});
|
|
342
385
|
return {
|
|
343
386
|
deletedTasks: data.deletedTasks ?? data.deleted_tasks ?? [],
|
|
344
387
|
failedTasks: data.failedTasks ?? data.failed_tasks ?? [],
|
|
@@ -347,9 +390,10 @@ var OrchestratorAsync = class {
|
|
|
347
390
|
};
|
|
348
391
|
}
|
|
349
392
|
async deleteTasks(taskIds) {
|
|
350
|
-
const data = await this._post(
|
|
351
|
-
|
|
352
|
-
|
|
393
|
+
const data = await this._post(
|
|
394
|
+
"/task/delete/multiple",
|
|
395
|
+
{ task_ids: taskIds }
|
|
396
|
+
);
|
|
353
397
|
return {
|
|
354
398
|
deletedTasks: data.deletedTasks ?? data.deleted_tasks ?? [],
|
|
355
399
|
failedTasks: data.failedTasks ?? data.failed_tasks ?? [],
|
|
@@ -360,18 +404,15 @@ var OrchestratorAsync = class {
|
|
|
360
404
|
// ------------------------------------------------------------------
|
|
361
405
|
// Attachments
|
|
362
406
|
// ------------------------------------------------------------------
|
|
363
|
-
async uploadAttachment(
|
|
407
|
+
async uploadAttachment(file, filename) {
|
|
364
408
|
const formData = new FormData();
|
|
365
409
|
formData.append("file", file, filename);
|
|
366
410
|
const headers = await this._resolveHeaders();
|
|
367
|
-
const response = await this._fetch(
|
|
368
|
-
|
|
369
|
-
{
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
body: formData
|
|
373
|
-
}
|
|
374
|
-
);
|
|
411
|
+
const response = await this._fetch(this._makeUrl("/attachment"), {
|
|
412
|
+
method: "POST",
|
|
413
|
+
headers: { ...headers },
|
|
414
|
+
body: formData
|
|
415
|
+
});
|
|
375
416
|
if (!response.ok) {
|
|
376
417
|
throw new OrchestratorAPIError(
|
|
377
418
|
`Attachment upload failed: ${response.statusText}`,
|
|
@@ -389,13 +430,11 @@ var OrchestratorAsync = class {
|
|
|
389
430
|
tokenCount: data.tokenCount ?? data.token_count ?? null
|
|
390
431
|
};
|
|
391
432
|
}
|
|
392
|
-
async downloadAttachment(
|
|
433
|
+
async downloadAttachment(attachmentId) {
|
|
393
434
|
const headers = await this._resolveHeaders();
|
|
394
435
|
const response = await this._fetch(
|
|
395
|
-
this._makeUrl(`/
|
|
396
|
-
{
|
|
397
|
-
headers
|
|
398
|
-
}
|
|
436
|
+
this._makeUrl(`/attachment/${attachmentId}`),
|
|
437
|
+
{ headers }
|
|
399
438
|
);
|
|
400
439
|
if (!response.ok) {
|
|
401
440
|
throw new OrchestratorAPIError(
|
|
@@ -408,126 +447,135 @@ var OrchestratorAsync = class {
|
|
|
408
447
|
// ------------------------------------------------------------------
|
|
409
448
|
// Interactive workflow
|
|
410
449
|
// ------------------------------------------------------------------
|
|
411
|
-
async sendInteractiveMessage(taskId,
|
|
450
|
+
async sendInteractiveMessage(taskId, message, attachmentIds) {
|
|
412
451
|
const data = await this._post(
|
|
413
|
-
|
|
414
|
-
{
|
|
415
|
-
content
|
|
416
|
-
}
|
|
452
|
+
"/task/interactive/message",
|
|
453
|
+
{ task_id: taskId, message, attachment_ids: attachmentIds }
|
|
417
454
|
);
|
|
418
455
|
return { message: data.message ?? "" };
|
|
419
456
|
}
|
|
420
457
|
async markInteractiveComplete(taskId) {
|
|
421
458
|
const data = await this._post(
|
|
422
|
-
|
|
459
|
+
"/task/interactive/mark_complete",
|
|
460
|
+
{ task_id: taskId }
|
|
423
461
|
);
|
|
424
462
|
return { message: data.message ?? "" };
|
|
425
463
|
}
|
|
426
464
|
async markInteractiveFailed(taskId) {
|
|
427
465
|
const data = await this._post(
|
|
428
|
-
|
|
466
|
+
"/task/interactive/mark_failed",
|
|
467
|
+
{ task_id: taskId }
|
|
429
468
|
);
|
|
430
469
|
return { message: data.message ?? "" };
|
|
431
470
|
}
|
|
432
|
-
async approveInteractiveAction(taskId) {
|
|
471
|
+
async approveInteractiveAction(taskId, approved = true) {
|
|
433
472
|
const data = await this._post(
|
|
434
|
-
|
|
473
|
+
"/task/interactive/action",
|
|
474
|
+
{ task_id: taskId, approved }
|
|
475
|
+
);
|
|
476
|
+
return { message: data.message ?? "" };
|
|
477
|
+
}
|
|
478
|
+
async stopInteractive(taskId) {
|
|
479
|
+
const data = await this._post(
|
|
480
|
+
"/task/interactive/stop",
|
|
481
|
+
{ task_id: taskId }
|
|
435
482
|
);
|
|
436
483
|
return { message: data.message ?? "" };
|
|
437
484
|
}
|
|
438
485
|
// ------------------------------------------------------------------
|
|
439
486
|
// Proactive workflow
|
|
440
487
|
// ------------------------------------------------------------------
|
|
441
|
-
async sendProactiveGuide(taskId,
|
|
488
|
+
async sendProactiveGuide(taskId, message, attachmentIds) {
|
|
442
489
|
const data = await this._post(
|
|
443
|
-
|
|
444
|
-
{
|
|
445
|
-
guide
|
|
446
|
-
}
|
|
490
|
+
"/task/proactive/guide",
|
|
491
|
+
{ task_id: taskId, message, attachment_ids: attachmentIds }
|
|
447
492
|
);
|
|
448
493
|
return { message: data.message ?? "" };
|
|
449
494
|
}
|
|
450
495
|
async respondProactiveHelp(taskId, response) {
|
|
451
496
|
const data = await this._post(
|
|
452
|
-
|
|
453
|
-
{
|
|
454
|
-
response
|
|
455
|
-
}
|
|
497
|
+
"/task/proactive/help",
|
|
498
|
+
{ task_id: taskId, response }
|
|
456
499
|
);
|
|
457
500
|
return { message: data.message ?? "" };
|
|
458
501
|
}
|
|
459
|
-
async approveProactiveAction(taskId) {
|
|
502
|
+
async approveProactiveAction(taskId, approved = true) {
|
|
460
503
|
const data = await this._post(
|
|
461
|
-
|
|
504
|
+
"/task/proactive/action",
|
|
505
|
+
{ task_id: taskId, approved }
|
|
462
506
|
);
|
|
463
507
|
return { message: data.message ?? "" };
|
|
464
508
|
}
|
|
465
509
|
// ------------------------------------------------------------------
|
|
466
510
|
// Ticket workflow
|
|
467
511
|
// ------------------------------------------------------------------
|
|
468
|
-
async sendTicketGuide(taskId,
|
|
512
|
+
async sendTicketGuide(taskId, message, attachmentIds) {
|
|
469
513
|
const data = await this._post(
|
|
470
|
-
|
|
471
|
-
{
|
|
472
|
-
guide
|
|
473
|
-
}
|
|
514
|
+
"/task/ticket/guide",
|
|
515
|
+
{ task_id: taskId, message, attachment_ids: attachmentIds }
|
|
474
516
|
);
|
|
475
517
|
return { message: data.message ?? "" };
|
|
476
518
|
}
|
|
477
519
|
async respondTicketHelp(taskId, response) {
|
|
478
520
|
const data = await this._post(
|
|
479
|
-
|
|
480
|
-
{
|
|
481
|
-
response
|
|
482
|
-
}
|
|
521
|
+
"/task/ticket/help",
|
|
522
|
+
{ task_id: taskId, response }
|
|
483
523
|
);
|
|
484
524
|
return { message: data.message ?? "" };
|
|
485
525
|
}
|
|
486
|
-
async approveTicketAction(taskId) {
|
|
526
|
+
async approveTicketAction(taskId, approved = true) {
|
|
487
527
|
const data = await this._post(
|
|
488
|
-
|
|
528
|
+
"/task/ticket/action",
|
|
529
|
+
{ task_id: taskId, approved }
|
|
489
530
|
);
|
|
490
531
|
return { message: data.message ?? "" };
|
|
491
532
|
}
|
|
492
533
|
async wakeTicket(taskId) {
|
|
493
534
|
const data = await this._post(
|
|
494
|
-
|
|
535
|
+
"/task/ticket/wake",
|
|
536
|
+
{ task_id: taskId }
|
|
495
537
|
);
|
|
496
538
|
return { message: data.message ?? "" };
|
|
497
539
|
}
|
|
498
540
|
// ------------------------------------------------------------------
|
|
499
541
|
// Matrix workflow
|
|
500
542
|
// ------------------------------------------------------------------
|
|
501
|
-
async sendMatrixMessage(taskId,
|
|
543
|
+
async sendMatrixMessage(taskId, message, attachmentIds) {
|
|
502
544
|
const data = await this._post(
|
|
503
|
-
|
|
504
|
-
{
|
|
505
|
-
content
|
|
506
|
-
}
|
|
545
|
+
"/task/matrix/message",
|
|
546
|
+
{ task_id: taskId, message, attachment_ids: attachmentIds }
|
|
507
547
|
);
|
|
508
548
|
return { message: data.message ?? "" };
|
|
509
549
|
}
|
|
510
550
|
async markMatrixComplete(taskId) {
|
|
511
551
|
const data = await this._post(
|
|
512
|
-
|
|
552
|
+
"/task/matrix/mark_complete",
|
|
553
|
+
{ task_id: taskId }
|
|
513
554
|
);
|
|
514
555
|
return { message: data.message ?? "" };
|
|
515
556
|
}
|
|
516
557
|
async markMatrixFailed(taskId) {
|
|
517
558
|
const data = await this._post(
|
|
518
|
-
|
|
559
|
+
"/task/matrix/mark_failed",
|
|
560
|
+
{ task_id: taskId }
|
|
519
561
|
);
|
|
520
562
|
return { message: data.message ?? "" };
|
|
521
563
|
}
|
|
522
|
-
async approveMatrixAction(taskId) {
|
|
564
|
+
async approveMatrixAction(taskId, approved = true) {
|
|
523
565
|
const data = await this._post(
|
|
524
|
-
|
|
566
|
+
"/task/matrix/action",
|
|
567
|
+
{ task_id: taskId, approved }
|
|
525
568
|
);
|
|
526
569
|
return { message: data.message ?? "" };
|
|
527
570
|
}
|
|
528
|
-
async getMatrixConversation(taskId) {
|
|
571
|
+
async getMatrixConversation(taskId, phase, includeSummaries) {
|
|
529
572
|
const data = await this._get(
|
|
530
|
-
|
|
573
|
+
"/task/matrix/conversation",
|
|
574
|
+
{
|
|
575
|
+
task_id: taskId,
|
|
576
|
+
phase,
|
|
577
|
+
include_summaries: includeSummaries
|
|
578
|
+
}
|
|
531
579
|
);
|
|
532
580
|
return {
|
|
533
581
|
taskId: data.taskId ?? data.task_id ?? taskId,
|
|
@@ -539,72 +587,84 @@ var OrchestratorAsync = class {
|
|
|
539
587
|
// ------------------------------------------------------------------
|
|
540
588
|
async createVSATask(params) {
|
|
541
589
|
const body = {
|
|
590
|
+
user_id: params.userId,
|
|
542
591
|
goal_prompt: params.goalPrompt,
|
|
543
592
|
title: params.title,
|
|
544
|
-
|
|
593
|
+
agent_model_id: params.agentModelId,
|
|
594
|
+
orchestrator_model_id: params.orchestratorModelId,
|
|
595
|
+
attachment_ids: params.attachmentIds,
|
|
596
|
+
options: params.options
|
|
545
597
|
};
|
|
546
598
|
if (params.delegatedToken !== void 0) {
|
|
547
599
|
body.delegated_token = params.delegatedToken;
|
|
548
600
|
}
|
|
549
|
-
const data = await this._post(
|
|
601
|
+
const data = await this._post(
|
|
602
|
+
"/task/vsa/create",
|
|
603
|
+
body
|
|
604
|
+
);
|
|
550
605
|
return {
|
|
551
606
|
taskId: data.taskId ?? data.task_id ?? "",
|
|
552
607
|
status: data.status ?? ""
|
|
553
608
|
};
|
|
554
609
|
}
|
|
555
|
-
async sendVSAMessage(taskId,
|
|
556
|
-
const body = {
|
|
610
|
+
async sendVSAMessage(taskId, message, options) {
|
|
611
|
+
const body = {
|
|
612
|
+
task_id: taskId,
|
|
613
|
+
message,
|
|
614
|
+
attachment_ids: options?.attachmentIds
|
|
615
|
+
};
|
|
557
616
|
if (options?.delegatedToken !== void 0) {
|
|
558
617
|
body.delegated_token = options.delegatedToken;
|
|
559
618
|
}
|
|
560
619
|
const data = await this._post(
|
|
561
|
-
|
|
620
|
+
"/task/vsa/message",
|
|
562
621
|
body
|
|
563
622
|
);
|
|
564
623
|
return { message: data.message ?? "" };
|
|
565
624
|
}
|
|
566
625
|
async renameVSATask(taskId, title) {
|
|
567
|
-
const data = await this._post(
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
}
|
|
572
|
-
);
|
|
626
|
+
const data = await this._post("/task/vsa/rename", {
|
|
627
|
+
task_id: taskId,
|
|
628
|
+
title
|
|
629
|
+
});
|
|
573
630
|
return { message: data.message ?? "" };
|
|
574
631
|
}
|
|
575
632
|
async regenerateVSATitle(taskId) {
|
|
576
633
|
const data = await this._post(
|
|
577
|
-
|
|
634
|
+
"/task/vsa/regenerate_title",
|
|
635
|
+
{ task_id: taskId }
|
|
578
636
|
);
|
|
579
637
|
return { message: data.message ?? "" };
|
|
580
638
|
}
|
|
581
639
|
async markVSAComplete(taskId) {
|
|
582
640
|
const data = await this._post(
|
|
583
|
-
|
|
641
|
+
"/task/vsa/mark_complete",
|
|
642
|
+
{ task_id: taskId }
|
|
584
643
|
);
|
|
585
644
|
return { message: data.message ?? "" };
|
|
586
645
|
}
|
|
587
646
|
async markVSAFailed(taskId) {
|
|
588
647
|
const data = await this._post(
|
|
589
|
-
|
|
648
|
+
"/task/vsa/mark_failed",
|
|
649
|
+
{ task_id: taskId }
|
|
590
650
|
);
|
|
591
651
|
return { message: data.message ?? "" };
|
|
592
652
|
}
|
|
593
653
|
async stopVSA(taskId) {
|
|
594
|
-
const data = await this._post(
|
|
595
|
-
|
|
596
|
-
);
|
|
654
|
+
const data = await this._post("/task/vsa/stop", {
|
|
655
|
+
task_id: taskId
|
|
656
|
+
});
|
|
597
657
|
return { message: data.message ?? "" };
|
|
598
658
|
}
|
|
599
659
|
async deleteVSA(taskId) {
|
|
600
|
-
const data = await this.
|
|
601
|
-
|
|
602
|
-
);
|
|
660
|
+
const data = await this._post("/task/vsa/delete", {
|
|
661
|
+
task_id: taskId
|
|
662
|
+
});
|
|
603
663
|
return { message: data.message ?? "" };
|
|
604
664
|
}
|
|
605
|
-
async listVSATasks(params) {
|
|
606
|
-
const data = await this._get("/
|
|
607
|
-
|
|
665
|
+
async listVSATasks(userId, params) {
|
|
666
|
+
const data = await this._get("/task/vsa/list", {
|
|
667
|
+
user_id: userId,
|
|
608
668
|
limit: params?.limit,
|
|
609
669
|
offset: params?.offset
|
|
610
670
|
});
|
|
@@ -613,9 +673,11 @@ var OrchestratorAsync = class {
|
|
|
613
673
|
);
|
|
614
674
|
return { tasks, pagination: buildPagination(data) };
|
|
615
675
|
}
|
|
616
|
-
async searchVSATasks(query) {
|
|
617
|
-
const data = await this._get("/
|
|
618
|
-
|
|
676
|
+
async searchVSATasks(userId, query, limit) {
|
|
677
|
+
const data = await this._get("/task/vsa/search", {
|
|
678
|
+
user_id: userId,
|
|
679
|
+
query,
|
|
680
|
+
limit
|
|
619
681
|
});
|
|
620
682
|
const tasks = (data.tasks ?? []).map(
|
|
621
683
|
buildTaskSummary
|
|
@@ -624,91 +686,123 @@ var OrchestratorAsync = class {
|
|
|
624
686
|
}
|
|
625
687
|
async deleteVSATasksBulk(taskIds) {
|
|
626
688
|
const data = await this._post(
|
|
627
|
-
"/
|
|
628
|
-
{
|
|
629
|
-
task_ids: taskIds
|
|
630
|
-
}
|
|
689
|
+
"/task/vsa/delete_bulk",
|
|
690
|
+
{ task_ids: taskIds }
|
|
631
691
|
);
|
|
632
|
-
return {
|
|
692
|
+
return {
|
|
693
|
+
deletedTasks: data.deletedTasks ?? data.deleted_tasks ?? [],
|
|
694
|
+
failedTasks: data.failedTasks ?? data.failed_tasks ?? [],
|
|
695
|
+
totalDeleted: data.totalDeleted ?? data.total_deleted ?? 0,
|
|
696
|
+
totalFailed: data.totalFailed ?? data.total_failed ?? 0
|
|
697
|
+
};
|
|
633
698
|
}
|
|
634
699
|
// ------------------------------------------------------------------
|
|
635
|
-
// MIO workflow
|
|
700
|
+
// MIO (self_managed) workflow
|
|
636
701
|
// ------------------------------------------------------------------
|
|
637
|
-
async sendMioMessage(taskId,
|
|
702
|
+
async sendMioMessage(taskId, message, attachmentIds) {
|
|
638
703
|
const data = await this._post(
|
|
639
|
-
|
|
640
|
-
{
|
|
641
|
-
content
|
|
642
|
-
}
|
|
704
|
+
"/task/self_managed/message",
|
|
705
|
+
{ task_id: taskId, message, attachment_ids: attachmentIds }
|
|
643
706
|
);
|
|
644
707
|
return { message: data.message ?? "" };
|
|
645
708
|
}
|
|
646
|
-
async approveMioAction(taskId) {
|
|
709
|
+
async approveMioAction(taskId, approved = true, feedback) {
|
|
647
710
|
const data = await this._post(
|
|
648
|
-
|
|
711
|
+
"/task/self_managed/action",
|
|
712
|
+
{ task_id: taskId, approved, feedback }
|
|
649
713
|
);
|
|
650
714
|
return { message: data.message ?? "" };
|
|
651
715
|
}
|
|
652
716
|
async wakeMio(taskId) {
|
|
653
717
|
const data = await this._post(
|
|
654
|
-
|
|
718
|
+
"/task/self_managed/wake",
|
|
719
|
+
{ task_id: taskId }
|
|
655
720
|
);
|
|
656
721
|
return { message: data.message ?? "" };
|
|
657
722
|
}
|
|
658
723
|
async sendMioUserAway(taskId) {
|
|
659
724
|
const data = await this._post(
|
|
660
|
-
|
|
725
|
+
"/task/self_managed/user_away",
|
|
726
|
+
{ task_id: taskId }
|
|
661
727
|
);
|
|
662
728
|
return { message: data.message ?? "" };
|
|
663
729
|
}
|
|
664
730
|
async markMioComplete(taskId) {
|
|
665
731
|
const data = await this._post(
|
|
666
|
-
|
|
732
|
+
"/task/self_managed/mark_complete",
|
|
733
|
+
{ task_id: taskId }
|
|
667
734
|
);
|
|
668
735
|
return { message: data.message ?? "" };
|
|
669
736
|
}
|
|
670
737
|
async markMioFailed(taskId) {
|
|
671
738
|
const data = await this._post(
|
|
672
|
-
|
|
739
|
+
"/task/self_managed/mark_failed",
|
|
740
|
+
{ task_id: taskId }
|
|
673
741
|
);
|
|
674
742
|
return { message: data.message ?? "" };
|
|
675
743
|
}
|
|
676
744
|
async archiveMio(taskId) {
|
|
677
745
|
const data = await this._post(
|
|
678
|
-
|
|
746
|
+
"/task/self_managed/archive",
|
|
747
|
+
{ task_id: taskId }
|
|
679
748
|
);
|
|
680
749
|
return { message: data.message ?? "" };
|
|
681
750
|
}
|
|
682
751
|
async getMioContext(taskId) {
|
|
683
752
|
const data = await this._get(
|
|
684
|
-
|
|
753
|
+
"/task/self_managed/context",
|
|
754
|
+
{ task_id: taskId }
|
|
685
755
|
);
|
|
686
756
|
return {
|
|
687
757
|
taskId: data.taskId ?? data.task_id ?? taskId,
|
|
758
|
+
modelId: data.modelId ?? data.model_id ?? "",
|
|
688
759
|
currentTokens: data.currentTokens ?? data.current_tokens ?? 0,
|
|
689
760
|
contextLimit: data.contextLimit ?? data.context_limit ?? 0,
|
|
690
761
|
usagePercentage: data.usagePercentage ?? data.usage_percentage ?? 0,
|
|
691
|
-
|
|
692
|
-
|
|
762
|
+
totalMessages: data.totalMessages ?? data.total_messages ?? 0,
|
|
763
|
+
activeMessages: data.activeMessages ?? data.active_messages ?? 0,
|
|
764
|
+
archivedMessages: data.archivedMessages ?? data.archived_messages ?? 0,
|
|
765
|
+
messagesWithoutTokenCount: data.messagesWithoutTokenCount ?? data.messages_without_token_count ?? 0
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
async getMioMemories(taskId, includeCommon) {
|
|
769
|
+
const data = await this._get(
|
|
770
|
+
"/task/self_managed/memories",
|
|
771
|
+
{ task_id: taskId, include_common: includeCommon }
|
|
772
|
+
);
|
|
773
|
+
return {
|
|
774
|
+
memories: data.memories ?? [],
|
|
775
|
+
total: data.total ?? 0
|
|
693
776
|
};
|
|
694
777
|
}
|
|
695
778
|
// ------------------------------------------------------------------
|
|
696
779
|
// Tools
|
|
697
780
|
// ------------------------------------------------------------------
|
|
698
781
|
async listTools() {
|
|
699
|
-
const data = await this._get("/tools");
|
|
782
|
+
const data = await this._get("/tools/all");
|
|
700
783
|
return {
|
|
701
|
-
tools: (data.tools ??
|
|
784
|
+
tools: (data.tools ?? []).map(
|
|
785
|
+
(t) => t
|
|
786
|
+
),
|
|
702
787
|
totalTools: data.totalTools ?? data.total_tools ?? 0,
|
|
703
788
|
servers: data.servers ?? []
|
|
704
789
|
};
|
|
705
790
|
}
|
|
791
|
+
async getToolCatalog() {
|
|
792
|
+
return this._get("/tools/catalog");
|
|
793
|
+
}
|
|
794
|
+
async refreshMCPTools() {
|
|
795
|
+
return this._post("/tools/mcp/refresh");
|
|
796
|
+
}
|
|
797
|
+
async validateToolCatalog() {
|
|
798
|
+
return this._get("/tools/validate");
|
|
799
|
+
}
|
|
706
800
|
// ------------------------------------------------------------------
|
|
707
801
|
// Debug / Admin
|
|
708
802
|
// ------------------------------------------------------------------
|
|
709
803
|
async getWorkflowStates() {
|
|
710
804
|
const data = await this._get(
|
|
711
|
-
"/debug/
|
|
805
|
+
"/debug/workflow_states"
|
|
712
806
|
);
|
|
713
807
|
return {
|
|
714
808
|
validStates: data.validStates ?? data.valid_states ?? {},
|
|
@@ -720,65 +814,65 @@ var OrchestratorAsync = class {
|
|
|
720
814
|
}
|
|
721
815
|
async updateTaskModels(taskId, models) {
|
|
722
816
|
const data = await this._post(
|
|
723
|
-
|
|
817
|
+
"/debug/task/models",
|
|
724
818
|
{
|
|
725
|
-
|
|
726
|
-
|
|
819
|
+
task_id: taskId,
|
|
820
|
+
agent_model_id: models.agentModelId,
|
|
821
|
+
orchestrator_model_id: models.orchestratorModelId
|
|
727
822
|
}
|
|
728
823
|
);
|
|
729
824
|
return { message: data.message ?? "" };
|
|
730
825
|
}
|
|
731
|
-
async updateTaskIteration(taskId, iteration) {
|
|
826
|
+
async updateTaskIteration(taskId, iteration, maxIterations) {
|
|
732
827
|
const data = await this._post(
|
|
733
|
-
|
|
734
|
-
{
|
|
735
|
-
iteration
|
|
736
|
-
}
|
|
828
|
+
"/debug/task/iteration",
|
|
829
|
+
{ task_id: taskId, iteration, max_iterations: maxIterations }
|
|
737
830
|
);
|
|
738
831
|
return { message: data.message ?? "" };
|
|
739
832
|
}
|
|
740
833
|
async updateTaskWorkflowData(taskId, workflowData) {
|
|
741
834
|
const data = await this._post(
|
|
742
|
-
|
|
743
|
-
{
|
|
744
|
-
workflow_data: workflowData
|
|
745
|
-
}
|
|
835
|
+
"/debug/task/workflow_data",
|
|
836
|
+
{ task_id: taskId, workflow_data: workflowData }
|
|
746
837
|
);
|
|
747
838
|
return { message: data.message ?? "" };
|
|
748
839
|
}
|
|
749
840
|
async deleteMessage(taskId, messageId) {
|
|
750
|
-
const data = await this.
|
|
751
|
-
|
|
841
|
+
const data = await this._post(
|
|
842
|
+
"/debug/task/message/delete",
|
|
843
|
+
{ task_id: taskId, message_id: messageId }
|
|
752
844
|
);
|
|
753
845
|
return { message: data.message ?? "" };
|
|
754
846
|
}
|
|
755
847
|
async deleteMessages(taskId, messageIds) {
|
|
756
848
|
const data = await this._post(
|
|
757
|
-
|
|
758
|
-
{ message_ids: messageIds }
|
|
849
|
+
"/debug/task/message/delete/multiple",
|
|
850
|
+
{ task_id: taskId, message_ids: messageIds }
|
|
759
851
|
);
|
|
760
|
-
return {
|
|
852
|
+
return {
|
|
853
|
+
deletedIds: data.deletedIds ?? data.deleted_ids ?? [],
|
|
854
|
+
failedIds: data.failedIds ?? data.failed_ids ?? [],
|
|
855
|
+
totalDeleted: data.totalDeleted ?? data.total_deleted ?? 0,
|
|
856
|
+
totalFailed: data.totalFailed ?? data.total_failed ?? 0
|
|
857
|
+
};
|
|
761
858
|
}
|
|
762
859
|
async updateMessage(taskId, messageId, update) {
|
|
763
|
-
const data = await this.
|
|
764
|
-
|
|
765
|
-
update
|
|
860
|
+
const data = await this._post(
|
|
861
|
+
"/debug/task/message/update",
|
|
862
|
+
{ task_id: taskId, message_id: messageId, ...update }
|
|
766
863
|
);
|
|
767
864
|
return { message: data.message ?? "" };
|
|
768
865
|
}
|
|
769
866
|
async resetMatrixToPhase(taskId, phase) {
|
|
770
867
|
const data = await this._post(
|
|
771
|
-
|
|
772
|
-
{ phase }
|
|
868
|
+
"/debug/task/matrix/reset_to_phase",
|
|
869
|
+
{ task_id: taskId, phase }
|
|
773
870
|
);
|
|
774
871
|
return { message: data.message ?? "" };
|
|
775
872
|
}
|
|
776
|
-
async getMessageTranslations(taskId, messageId
|
|
777
|
-
const params = {};
|
|
778
|
-
if (locale) params.locale = locale;
|
|
873
|
+
async getMessageTranslations(taskId, messageId) {
|
|
779
874
|
const data = await this._get(
|
|
780
|
-
`/
|
|
781
|
-
params
|
|
875
|
+
`/debug/task/${taskId}/message/${messageId}/translations`
|
|
782
876
|
);
|
|
783
877
|
return {
|
|
784
878
|
messageId: data.messageId ?? data.message_id ?? messageId,
|
|
@@ -789,25 +883,54 @@ var OrchestratorAsync = class {
|
|
|
789
883
|
// Error events
|
|
790
884
|
// ------------------------------------------------------------------
|
|
791
885
|
async listErrors(params) {
|
|
792
|
-
const
|
|
793
|
-
|
|
794
|
-
if (params?.
|
|
795
|
-
|
|
796
|
-
if (params?.limit
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
);
|
|
802
|
-
|
|
803
|
-
(
|
|
804
|
-
);
|
|
886
|
+
const authHeaders = await this._resolveHeaders();
|
|
887
|
+
const url = new URL(this._makeUrl("/errors"));
|
|
888
|
+
if (params?.page !== void 0)
|
|
889
|
+
url.searchParams.set("page", String(params.page));
|
|
890
|
+
if (params?.limit !== void 0)
|
|
891
|
+
url.searchParams.set("limit", String(params.limit));
|
|
892
|
+
if (params?.taskId) url.searchParams.set("task_id", params.taskId);
|
|
893
|
+
if (params?.workflowId)
|
|
894
|
+
url.searchParams.set("workflow_id", params.workflowId);
|
|
895
|
+
if (params?.errorCode) url.searchParams.set("error_code", params.errorCode);
|
|
896
|
+
if (params?.exceptionType)
|
|
897
|
+
url.searchParams.set("exception_type", params.exceptionType);
|
|
898
|
+
if (params?.holderId) url.searchParams.set("holder_id", params.holderId);
|
|
899
|
+
if (params?.requestId) url.searchParams.set("request_id", params.requestId);
|
|
900
|
+
if (params?.search) url.searchParams.set("search", params.search);
|
|
901
|
+
if (params?.since) url.searchParams.set("since", params.since);
|
|
902
|
+
if (params?.until) url.searchParams.set("until", params.until);
|
|
903
|
+
if (params?.orderDirection)
|
|
904
|
+
url.searchParams.set("order_direction", params.orderDirection);
|
|
905
|
+
for (const s of params?.severity ?? []) {
|
|
906
|
+
url.searchParams.append("severity", s);
|
|
907
|
+
}
|
|
908
|
+
for (const s of params?.source ?? []) {
|
|
909
|
+
url.searchParams.append("source", s);
|
|
910
|
+
}
|
|
911
|
+
const response = await this._fetch(url.toString(), {
|
|
912
|
+
method: "GET",
|
|
913
|
+
headers: { ...authHeaders }
|
|
914
|
+
});
|
|
915
|
+
if (!response.ok) {
|
|
916
|
+
throw new OrchestratorAPIError(
|
|
917
|
+
`listErrors failed: ${response.statusText}`,
|
|
918
|
+
response.status
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
const data = await response.json();
|
|
922
|
+
return {
|
|
923
|
+
items: (data.items ?? data.errors ?? []).map((e) => e),
|
|
924
|
+
pagination: buildPagination(data)
|
|
925
|
+
};
|
|
805
926
|
}
|
|
806
927
|
async getErrorDetail(errorId) {
|
|
807
928
|
return this._get(`/errors/${errorId}`);
|
|
808
929
|
}
|
|
809
|
-
async getErrorStats(since) {
|
|
810
|
-
const params = {
|
|
930
|
+
async getErrorStats(since, topN = 10) {
|
|
931
|
+
const params = {
|
|
932
|
+
top_n: topN
|
|
933
|
+
};
|
|
811
934
|
if (since) params.since = since;
|
|
812
935
|
return this._get("/errors/stats", params);
|
|
813
936
|
}
|
|
@@ -826,13 +949,13 @@ var OrchestratorAsync = class {
|
|
|
826
949
|
return this._get("/health");
|
|
827
950
|
}
|
|
828
951
|
async healthDetailed() {
|
|
829
|
-
return this._get("/health/
|
|
952
|
+
return this._get("/health/detailed");
|
|
830
953
|
}
|
|
831
954
|
async ready() {
|
|
832
955
|
return this._get("/ready");
|
|
833
956
|
}
|
|
834
957
|
async healthLeader() {
|
|
835
|
-
return this._get("/leader");
|
|
958
|
+
return this._get("/health/leader");
|
|
836
959
|
}
|
|
837
960
|
async getMetrics(types) {
|
|
838
961
|
const params = {};
|
|
@@ -843,107 +966,122 @@ var OrchestratorAsync = class {
|
|
|
843
966
|
// Configuration
|
|
844
967
|
// ------------------------------------------------------------------
|
|
845
968
|
async getSystemStatus() {
|
|
846
|
-
return this._get("/
|
|
969
|
+
return this._get("/configuration/system/status");
|
|
847
970
|
}
|
|
848
971
|
async updateSettings(settings) {
|
|
849
|
-
return this._post("/
|
|
972
|
+
return this._post("/configuration/system/settings", settings);
|
|
850
973
|
}
|
|
851
974
|
async getConfigurationStatus() {
|
|
852
|
-
return this._get("/
|
|
975
|
+
return this._get("/configuration/status");
|
|
853
976
|
}
|
|
854
977
|
async setAgentModel(model) {
|
|
855
978
|
const data = await this._post(
|
|
856
|
-
"/
|
|
857
|
-
{ model }
|
|
979
|
+
"/configuration/agent",
|
|
980
|
+
{ model_name: model }
|
|
858
981
|
);
|
|
859
982
|
return { message: data.message ?? "" };
|
|
860
983
|
}
|
|
861
984
|
async setOrchestratorModel(model) {
|
|
862
985
|
const data = await this._post(
|
|
863
|
-
"/
|
|
864
|
-
{ model }
|
|
986
|
+
"/configuration/orchestrator",
|
|
987
|
+
{ model_name: model }
|
|
865
988
|
);
|
|
866
989
|
return { message: data.message ?? "" };
|
|
867
990
|
}
|
|
868
991
|
async getLLMBackendStatus() {
|
|
869
|
-
return this._get(
|
|
992
|
+
return this._get(
|
|
993
|
+
"/configuration/llmbackend/status"
|
|
994
|
+
);
|
|
870
995
|
}
|
|
871
996
|
async addLLMBackend(host, apiKey) {
|
|
872
997
|
const data = await this._post(
|
|
873
|
-
"/
|
|
874
|
-
{
|
|
875
|
-
host,
|
|
876
|
-
api_key: apiKey
|
|
877
|
-
}
|
|
998
|
+
"/configuration/llmbackend/add",
|
|
999
|
+
{ backends: [{ url: host, api_key: apiKey }] }
|
|
878
1000
|
);
|
|
879
1001
|
return { message: data.message ?? "" };
|
|
880
1002
|
}
|
|
881
1003
|
async removeLLMBackend(host) {
|
|
882
|
-
const data = await this.
|
|
883
|
-
|
|
1004
|
+
const data = await this._post(
|
|
1005
|
+
"/configuration/llmbackend/remove",
|
|
1006
|
+
{ host }
|
|
884
1007
|
);
|
|
885
1008
|
return { message: data.message ?? "" };
|
|
886
1009
|
}
|
|
887
1010
|
async getMCPServerStatus() {
|
|
888
|
-
return this._get(
|
|
1011
|
+
return this._get(
|
|
1012
|
+
"/configuration/mcpserver/status"
|
|
1013
|
+
);
|
|
889
1014
|
}
|
|
890
1015
|
async addMCPServer(host, apiKey) {
|
|
891
1016
|
const data = await this._post(
|
|
892
|
-
"/
|
|
893
|
-
{
|
|
894
|
-
host,
|
|
895
|
-
api_key: apiKey
|
|
896
|
-
}
|
|
1017
|
+
"/configuration/mcpserver/add",
|
|
1018
|
+
{ servers: [{ url: host, api_key: apiKey }] }
|
|
897
1019
|
);
|
|
898
1020
|
return { message: data.message ?? "" };
|
|
899
1021
|
}
|
|
900
1022
|
async removeMCPServer(host) {
|
|
901
|
-
const data = await this.
|
|
902
|
-
|
|
1023
|
+
const data = await this._post(
|
|
1024
|
+
"/configuration/mcpserver/remove",
|
|
1025
|
+
{ host }
|
|
903
1026
|
);
|
|
904
1027
|
return { message: data.message ?? "" };
|
|
905
1028
|
}
|
|
906
1029
|
async getTaskHandlerStatus() {
|
|
907
|
-
return this._get("/
|
|
1030
|
+
return this._get("/configuration/taskhandler/status");
|
|
908
1031
|
}
|
|
909
1032
|
async getTaskHandlerStatusLocal() {
|
|
910
|
-
return this._get(
|
|
1033
|
+
return this._get(
|
|
1034
|
+
"/configuration/taskhandler/status/local"
|
|
1035
|
+
);
|
|
911
1036
|
}
|
|
912
1037
|
async setConcurrentTasksPerReplica(maxTasks) {
|
|
913
|
-
const data = await this.
|
|
914
|
-
"
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
}
|
|
1038
|
+
const data = await this._request(
|
|
1039
|
+
"POST",
|
|
1040
|
+
"/configuration/taskhandler/concurrent-per-replica",
|
|
1041
|
+
{ params: { max_tasks: maxTasks } }
|
|
918
1042
|
);
|
|
919
1043
|
return { message: data.message ?? "" };
|
|
920
1044
|
}
|
|
921
1045
|
async getSummaryWorkerStatus() {
|
|
922
|
-
return this._get(
|
|
1046
|
+
return this._get(
|
|
1047
|
+
"/configuration/summary-worker/status"
|
|
1048
|
+
);
|
|
923
1049
|
}
|
|
924
1050
|
async setCompactorModel(modelName) {
|
|
925
1051
|
const data = await this._post(
|
|
926
|
-
"/
|
|
927
|
-
{
|
|
928
|
-
model_name: modelName
|
|
929
|
-
}
|
|
1052
|
+
"/configuration/summary-worker/model",
|
|
1053
|
+
{ model_name: modelName }
|
|
930
1054
|
);
|
|
931
1055
|
return { message: data.message ?? "" };
|
|
932
1056
|
}
|
|
933
1057
|
async setTranslateModel(modelName) {
|
|
934
1058
|
const data = await this._post(
|
|
935
|
-
"/
|
|
936
|
-
{
|
|
937
|
-
model_name: modelName
|
|
938
|
-
}
|
|
1059
|
+
"/configuration/summary-worker/translate-model",
|
|
1060
|
+
{ model_name: modelName }
|
|
939
1061
|
);
|
|
940
1062
|
return { message: data.message ?? "" };
|
|
941
1063
|
}
|
|
942
1064
|
async getTokenWorkerStatus() {
|
|
943
|
-
return this._get("/
|
|
1065
|
+
return this._get("/configuration/token-worker/status");
|
|
944
1066
|
}
|
|
945
1067
|
async getSlotsStatus() {
|
|
946
|
-
return this._get("/
|
|
1068
|
+
return this._get("/configuration/slots/status");
|
|
1069
|
+
}
|
|
1070
|
+
async getSubagentsStatus() {
|
|
1071
|
+
return this._get("/configuration/subagents/status");
|
|
1072
|
+
}
|
|
1073
|
+
async setSubagentsEnabled(enabled) {
|
|
1074
|
+
const data = await this._post(
|
|
1075
|
+
"/configuration/subagents",
|
|
1076
|
+
{ enabled }
|
|
1077
|
+
);
|
|
1078
|
+
return { message: data.message ?? "" };
|
|
1079
|
+
}
|
|
1080
|
+
async reloadServices() {
|
|
1081
|
+
return this._post("/configuration/reload");
|
|
1082
|
+
}
|
|
1083
|
+
async getReloadStatus() {
|
|
1084
|
+
return this._get("/configuration/reload/status");
|
|
947
1085
|
}
|
|
948
1086
|
// ------------------------------------------------------------------
|
|
949
1087
|
// Auth / WebSocket status
|
|
@@ -961,10 +1099,10 @@ var OrchestratorAsync = class {
|
|
|
961
1099
|
const headers = await this._resolveHeaders();
|
|
962
1100
|
headers.Accept = "text/event-stream";
|
|
963
1101
|
const response = await this._fetch(
|
|
964
|
-
this._makeUrl(
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
}
|
|
1102
|
+
this._makeUrl(
|
|
1103
|
+
`/task/stream_status?task_id=${encodeURIComponent(taskId)}`
|
|
1104
|
+
),
|
|
1105
|
+
{ headers }
|
|
968
1106
|
);
|
|
969
1107
|
if (!response.ok) {
|
|
970
1108
|
throw new OrchestratorAPIError(
|
|
@@ -1031,11 +1169,14 @@ var Orchestrator = class {
|
|
|
1031
1169
|
createTask(params) {
|
|
1032
1170
|
return runSync(this._async.createTask(params));
|
|
1033
1171
|
}
|
|
1034
|
-
getTaskStatus(taskId) {
|
|
1035
|
-
return runSync(this._async.getTaskStatus(taskId));
|
|
1172
|
+
getTaskStatus(taskId, locale) {
|
|
1173
|
+
return runSync(this._async.getTaskStatus(taskId, locale));
|
|
1036
1174
|
}
|
|
1037
|
-
|
|
1038
|
-
return runSync(this._async.
|
|
1175
|
+
setTaskStatus(taskId, status) {
|
|
1176
|
+
return runSync(this._async.setTaskStatus(taskId, status));
|
|
1177
|
+
}
|
|
1178
|
+
getTaskConversation(taskId, params) {
|
|
1179
|
+
return runSync(this._async.getTaskConversation(taskId, params));
|
|
1039
1180
|
}
|
|
1040
1181
|
getArchivedMessageContent(taskId, messageId) {
|
|
1041
1182
|
return runSync(this._async.getArchivedMessageContent(taskId, messageId));
|
|
@@ -1058,17 +1199,19 @@ var Orchestrator = class {
|
|
|
1058
1199
|
// ------------------------------------------------------------------
|
|
1059
1200
|
// Attachments
|
|
1060
1201
|
// ------------------------------------------------------------------
|
|
1061
|
-
uploadAttachment(
|
|
1062
|
-
return runSync(this._async.uploadAttachment(
|
|
1202
|
+
uploadAttachment(file, filename) {
|
|
1203
|
+
return runSync(this._async.uploadAttachment(file, filename));
|
|
1063
1204
|
}
|
|
1064
|
-
downloadAttachment(
|
|
1065
|
-
return runSync(this._async.downloadAttachment(
|
|
1205
|
+
downloadAttachment(attachmentId) {
|
|
1206
|
+
return runSync(this._async.downloadAttachment(attachmentId));
|
|
1066
1207
|
}
|
|
1067
1208
|
// ------------------------------------------------------------------
|
|
1068
1209
|
// Interactive workflow
|
|
1069
1210
|
// ------------------------------------------------------------------
|
|
1070
|
-
sendInteractiveMessage(taskId,
|
|
1071
|
-
return runSync(
|
|
1211
|
+
sendInteractiveMessage(taskId, message, attachmentIds) {
|
|
1212
|
+
return runSync(
|
|
1213
|
+
this._async.sendInteractiveMessage(taskId, message, attachmentIds)
|
|
1214
|
+
);
|
|
1072
1215
|
}
|
|
1073
1216
|
markInteractiveComplete(taskId) {
|
|
1074
1217
|
return runSync(this._async.markInteractiveComplete(taskId));
|
|
@@ -1076,32 +1219,37 @@ var Orchestrator = class {
|
|
|
1076
1219
|
markInteractiveFailed(taskId) {
|
|
1077
1220
|
return runSync(this._async.markInteractiveFailed(taskId));
|
|
1078
1221
|
}
|
|
1079
|
-
approveInteractiveAction(taskId) {
|
|
1080
|
-
return runSync(this._async.approveInteractiveAction(taskId));
|
|
1222
|
+
approveInteractiveAction(taskId, approved = true) {
|
|
1223
|
+
return runSync(this._async.approveInteractiveAction(taskId, approved));
|
|
1224
|
+
}
|
|
1225
|
+
stopInteractive(taskId) {
|
|
1226
|
+
return runSync(this._async.stopInteractive(taskId));
|
|
1081
1227
|
}
|
|
1082
1228
|
// ------------------------------------------------------------------
|
|
1083
1229
|
// Proactive workflow
|
|
1084
1230
|
// ------------------------------------------------------------------
|
|
1085
|
-
sendProactiveGuide(taskId,
|
|
1086
|
-
return runSync(
|
|
1231
|
+
sendProactiveGuide(taskId, message, attachmentIds) {
|
|
1232
|
+
return runSync(
|
|
1233
|
+
this._async.sendProactiveGuide(taskId, message, attachmentIds)
|
|
1234
|
+
);
|
|
1087
1235
|
}
|
|
1088
1236
|
respondProactiveHelp(taskId, response) {
|
|
1089
1237
|
return runSync(this._async.respondProactiveHelp(taskId, response));
|
|
1090
1238
|
}
|
|
1091
|
-
approveProactiveAction(taskId) {
|
|
1092
|
-
return runSync(this._async.approveProactiveAction(taskId));
|
|
1239
|
+
approveProactiveAction(taskId, approved = true) {
|
|
1240
|
+
return runSync(this._async.approveProactiveAction(taskId, approved));
|
|
1093
1241
|
}
|
|
1094
1242
|
// ------------------------------------------------------------------
|
|
1095
1243
|
// Ticket workflow
|
|
1096
1244
|
// ------------------------------------------------------------------
|
|
1097
|
-
sendTicketGuide(taskId,
|
|
1098
|
-
return runSync(this._async.sendTicketGuide(taskId,
|
|
1245
|
+
sendTicketGuide(taskId, message, attachmentIds) {
|
|
1246
|
+
return runSync(this._async.sendTicketGuide(taskId, message, attachmentIds));
|
|
1099
1247
|
}
|
|
1100
1248
|
respondTicketHelp(taskId, response) {
|
|
1101
1249
|
return runSync(this._async.respondTicketHelp(taskId, response));
|
|
1102
1250
|
}
|
|
1103
|
-
approveTicketAction(taskId) {
|
|
1104
|
-
return runSync(this._async.approveTicketAction(taskId));
|
|
1251
|
+
approveTicketAction(taskId, approved = true) {
|
|
1252
|
+
return runSync(this._async.approveTicketAction(taskId, approved));
|
|
1105
1253
|
}
|
|
1106
1254
|
wakeTicket(taskId) {
|
|
1107
1255
|
return runSync(this._async.wakeTicket(taskId));
|
|
@@ -1109,8 +1257,10 @@ var Orchestrator = class {
|
|
|
1109
1257
|
// ------------------------------------------------------------------
|
|
1110
1258
|
// Matrix workflow
|
|
1111
1259
|
// ------------------------------------------------------------------
|
|
1112
|
-
sendMatrixMessage(taskId,
|
|
1113
|
-
return runSync(
|
|
1260
|
+
sendMatrixMessage(taskId, message, attachmentIds) {
|
|
1261
|
+
return runSync(
|
|
1262
|
+
this._async.sendMatrixMessage(taskId, message, attachmentIds)
|
|
1263
|
+
);
|
|
1114
1264
|
}
|
|
1115
1265
|
markMatrixComplete(taskId) {
|
|
1116
1266
|
return runSync(this._async.markMatrixComplete(taskId));
|
|
@@ -1118,11 +1268,13 @@ var Orchestrator = class {
|
|
|
1118
1268
|
markMatrixFailed(taskId) {
|
|
1119
1269
|
return runSync(this._async.markMatrixFailed(taskId));
|
|
1120
1270
|
}
|
|
1121
|
-
approveMatrixAction(taskId) {
|
|
1122
|
-
return runSync(this._async.approveMatrixAction(taskId));
|
|
1271
|
+
approveMatrixAction(taskId, approved = true) {
|
|
1272
|
+
return runSync(this._async.approveMatrixAction(taskId, approved));
|
|
1123
1273
|
}
|
|
1124
|
-
getMatrixConversation(taskId) {
|
|
1125
|
-
return runSync(
|
|
1274
|
+
getMatrixConversation(taskId, phase, includeSummaries) {
|
|
1275
|
+
return runSync(
|
|
1276
|
+
this._async.getMatrixConversation(taskId, phase, includeSummaries)
|
|
1277
|
+
);
|
|
1126
1278
|
}
|
|
1127
1279
|
// ------------------------------------------------------------------
|
|
1128
1280
|
// VSA workflow
|
|
@@ -1130,8 +1282,8 @@ var Orchestrator = class {
|
|
|
1130
1282
|
createVSATask(params) {
|
|
1131
1283
|
return runSync(this._async.createVSATask(params));
|
|
1132
1284
|
}
|
|
1133
|
-
sendVSAMessage(taskId,
|
|
1134
|
-
return runSync(this._async.sendVSAMessage(taskId,
|
|
1285
|
+
sendVSAMessage(taskId, message, options) {
|
|
1286
|
+
return runSync(this._async.sendVSAMessage(taskId, message, options));
|
|
1135
1287
|
}
|
|
1136
1288
|
renameVSATask(taskId, title) {
|
|
1137
1289
|
return runSync(this._async.renameVSATask(taskId, title));
|
|
@@ -1151,23 +1303,23 @@ var Orchestrator = class {
|
|
|
1151
1303
|
deleteVSA(taskId) {
|
|
1152
1304
|
return runSync(this._async.deleteVSA(taskId));
|
|
1153
1305
|
}
|
|
1154
|
-
listVSATasks(params) {
|
|
1155
|
-
return runSync(this._async.listVSATasks(params));
|
|
1306
|
+
listVSATasks(userId, params) {
|
|
1307
|
+
return runSync(this._async.listVSATasks(userId, params));
|
|
1156
1308
|
}
|
|
1157
|
-
searchVSATasks(query) {
|
|
1158
|
-
return runSync(this._async.searchVSATasks(query));
|
|
1309
|
+
searchVSATasks(userId, query, limit) {
|
|
1310
|
+
return runSync(this._async.searchVSATasks(userId, query, limit));
|
|
1159
1311
|
}
|
|
1160
1312
|
deleteVSATasksBulk(taskIds) {
|
|
1161
1313
|
return runSync(this._async.deleteVSATasksBulk(taskIds));
|
|
1162
1314
|
}
|
|
1163
1315
|
// ------------------------------------------------------------------
|
|
1164
|
-
// MIO workflow
|
|
1316
|
+
// MIO (self_managed) workflow
|
|
1165
1317
|
// ------------------------------------------------------------------
|
|
1166
|
-
sendMioMessage(taskId,
|
|
1167
|
-
return runSync(this._async.sendMioMessage(taskId,
|
|
1318
|
+
sendMioMessage(taskId, message, attachmentIds) {
|
|
1319
|
+
return runSync(this._async.sendMioMessage(taskId, message, attachmentIds));
|
|
1168
1320
|
}
|
|
1169
|
-
approveMioAction(taskId) {
|
|
1170
|
-
return runSync(this._async.approveMioAction(taskId));
|
|
1321
|
+
approveMioAction(taskId, approved = true, feedback) {
|
|
1322
|
+
return runSync(this._async.approveMioAction(taskId, approved, feedback));
|
|
1171
1323
|
}
|
|
1172
1324
|
wakeMio(taskId) {
|
|
1173
1325
|
return runSync(this._async.wakeMio(taskId));
|
|
@@ -1187,12 +1339,24 @@ var Orchestrator = class {
|
|
|
1187
1339
|
getMioContext(taskId) {
|
|
1188
1340
|
return runSync(this._async.getMioContext(taskId));
|
|
1189
1341
|
}
|
|
1342
|
+
getMioMemories(taskId, includeCommon) {
|
|
1343
|
+
return runSync(this._async.getMioMemories(taskId, includeCommon));
|
|
1344
|
+
}
|
|
1190
1345
|
// ------------------------------------------------------------------
|
|
1191
1346
|
// Tools
|
|
1192
1347
|
// ------------------------------------------------------------------
|
|
1193
1348
|
listTools() {
|
|
1194
1349
|
return runSync(this._async.listTools());
|
|
1195
1350
|
}
|
|
1351
|
+
getToolCatalog() {
|
|
1352
|
+
return runSync(this._async.getToolCatalog());
|
|
1353
|
+
}
|
|
1354
|
+
refreshMCPTools() {
|
|
1355
|
+
return runSync(this._async.refreshMCPTools());
|
|
1356
|
+
}
|
|
1357
|
+
validateToolCatalog() {
|
|
1358
|
+
return runSync(this._async.validateToolCatalog());
|
|
1359
|
+
}
|
|
1196
1360
|
// ------------------------------------------------------------------
|
|
1197
1361
|
// Debug / Admin
|
|
1198
1362
|
// ------------------------------------------------------------------
|
|
@@ -1202,8 +1366,10 @@ var Orchestrator = class {
|
|
|
1202
1366
|
updateTaskModels(taskId, models) {
|
|
1203
1367
|
return runSync(this._async.updateTaskModels(taskId, models));
|
|
1204
1368
|
}
|
|
1205
|
-
updateTaskIteration(taskId, iteration) {
|
|
1206
|
-
return runSync(
|
|
1369
|
+
updateTaskIteration(taskId, iteration, maxIterations) {
|
|
1370
|
+
return runSync(
|
|
1371
|
+
this._async.updateTaskIteration(taskId, iteration, maxIterations)
|
|
1372
|
+
);
|
|
1207
1373
|
}
|
|
1208
1374
|
updateTaskWorkflowData(taskId, workflowData) {
|
|
1209
1375
|
return runSync(this._async.updateTaskWorkflowData(taskId, workflowData));
|
|
@@ -1220,10 +1386,8 @@ var Orchestrator = class {
|
|
|
1220
1386
|
resetMatrixToPhase(taskId, phase) {
|
|
1221
1387
|
return runSync(this._async.resetMatrixToPhase(taskId, phase));
|
|
1222
1388
|
}
|
|
1223
|
-
getMessageTranslations(taskId, messageId
|
|
1224
|
-
return runSync(
|
|
1225
|
-
this._async.getMessageTranslations(taskId, messageId, locale)
|
|
1226
|
-
);
|
|
1389
|
+
getMessageTranslations(taskId, messageId) {
|
|
1390
|
+
return runSync(this._async.getMessageTranslations(taskId, messageId));
|
|
1227
1391
|
}
|
|
1228
1392
|
// ------------------------------------------------------------------
|
|
1229
1393
|
// Error events
|
|
@@ -1321,6 +1485,18 @@ var Orchestrator = class {
|
|
|
1321
1485
|
getSlotsStatus() {
|
|
1322
1486
|
return runSync(this._async.getSlotsStatus());
|
|
1323
1487
|
}
|
|
1488
|
+
getSubagentsStatus() {
|
|
1489
|
+
return runSync(this._async.getSubagentsStatus());
|
|
1490
|
+
}
|
|
1491
|
+
setSubagentsEnabled(enabled) {
|
|
1492
|
+
return runSync(this._async.setSubagentsEnabled(enabled));
|
|
1493
|
+
}
|
|
1494
|
+
reloadServices() {
|
|
1495
|
+
return runSync(this._async.reloadServices());
|
|
1496
|
+
}
|
|
1497
|
+
getReloadStatus() {
|
|
1498
|
+
return runSync(this._async.getReloadStatus());
|
|
1499
|
+
}
|
|
1324
1500
|
// ------------------------------------------------------------------
|
|
1325
1501
|
// Auth / WebSocket status
|
|
1326
1502
|
// ------------------------------------------------------------------
|
|
@@ -1464,9 +1640,15 @@ var RealtimeClient = class {
|
|
|
1464
1640
|
this._socket = null;
|
|
1465
1641
|
this._handlers = /* @__PURE__ */ new Map();
|
|
1466
1642
|
this._connected = false;
|
|
1643
|
+
// Multi-subscriber room-diffing state (mirrors WebSocketProvider)
|
|
1644
|
+
this._subscriptions = /* @__PURE__ */ new Map();
|
|
1645
|
+
this._currentRooms = /* @__PURE__ */ new Set();
|
|
1646
|
+
this._subIdCounter = 0;
|
|
1467
1647
|
this._baseUrl = baseUrl.replace(/\/+$/, "");
|
|
1468
1648
|
this._socketOptions = opts.socketOptions ?? {};
|
|
1469
1649
|
this._getToken = opts.getToken;
|
|
1650
|
+
this._clientId = opts.clientId ?? "orchestrator-client";
|
|
1651
|
+
this._locale = opts.locale;
|
|
1470
1652
|
if (opts.autoConnect) {
|
|
1471
1653
|
this.connect();
|
|
1472
1654
|
}
|
|
@@ -1479,19 +1661,28 @@ var RealtimeClient = class {
|
|
|
1479
1661
|
if (this._getToken) {
|
|
1480
1662
|
auth.token = typeof this._getToken === "function" ? await this._getToken() : this._getToken;
|
|
1481
1663
|
}
|
|
1664
|
+
const query = { client_id: this._clientId };
|
|
1665
|
+
if (this._locale) {
|
|
1666
|
+
query.locale = this._locale;
|
|
1667
|
+
}
|
|
1482
1668
|
const { io } = await import("socket.io-client");
|
|
1483
1669
|
this._socket = io(this._baseUrl, {
|
|
1484
1670
|
path: "/socket.io",
|
|
1485
1671
|
auth,
|
|
1672
|
+
query,
|
|
1486
1673
|
transports: ["websocket", "polling"],
|
|
1487
1674
|
...this._socketOptions
|
|
1488
1675
|
});
|
|
1489
1676
|
this._socket.on("connect", () => {
|
|
1490
1677
|
this._connected = true;
|
|
1678
|
+
this._currentRooms = /* @__PURE__ */ new Set();
|
|
1679
|
+
this._syncRooms();
|
|
1491
1680
|
});
|
|
1492
1681
|
this._socket.on("disconnect", () => {
|
|
1493
1682
|
this._connected = false;
|
|
1683
|
+
this._currentRooms = /* @__PURE__ */ new Set();
|
|
1494
1684
|
});
|
|
1685
|
+
this._socket.on("message", (payload) => this._dispatch(payload));
|
|
1495
1686
|
return new Promise((resolve, reject) => {
|
|
1496
1687
|
if (!this._socket) {
|
|
1497
1688
|
reject(new Error("RealtimeClient not connected"));
|
|
@@ -1511,53 +1702,187 @@ var RealtimeClient = class {
|
|
|
1511
1702
|
}
|
|
1512
1703
|
this._connected = false;
|
|
1513
1704
|
}
|
|
1705
|
+
/**
|
|
1706
|
+
* Dispatch a message envelope to registered handlers and subscribers.
|
|
1707
|
+
* The server sends: socket.emit("message", {type: "message", event: {..., event_type: "...", ...}})
|
|
1708
|
+
*/
|
|
1709
|
+
_dispatch(payload) {
|
|
1710
|
+
const envelope = payload;
|
|
1711
|
+
const event = envelope.event ?? envelope;
|
|
1712
|
+
const eventType = event.event_type;
|
|
1713
|
+
if (!eventType) return;
|
|
1714
|
+
const handlers = this._handlers.get(eventType);
|
|
1715
|
+
if (handlers) {
|
|
1716
|
+
for (const h of handlers) {
|
|
1717
|
+
h(event);
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
for (const sub of this._subscriptions.values()) {
|
|
1721
|
+
sub.handler(event);
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1514
1724
|
/**
|
|
1515
1725
|
* Subscribe to realtime events for a specific task.
|
|
1726
|
+
* Emits a `join` event with `{rooms: ["task:{taskId}"]}`.
|
|
1516
1727
|
*/
|
|
1517
|
-
|
|
1728
|
+
subscribeTask(taskId) {
|
|
1518
1729
|
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1519
|
-
|
|
1520
|
-
this._socket?.emit(
|
|
1521
|
-
"subscribe",
|
|
1522
|
-
{ task_id: taskId },
|
|
1523
|
-
(response) => {
|
|
1524
|
-
if (response.ok) resolve();
|
|
1525
|
-
else reject(new Error(response.error ?? "Subscription failed"));
|
|
1526
|
-
}
|
|
1527
|
-
);
|
|
1528
|
-
});
|
|
1730
|
+
this._socket.emit("join", { rooms: [`task:${taskId}`] });
|
|
1529
1731
|
}
|
|
1530
1732
|
/**
|
|
1531
1733
|
* Unsubscribe from realtime events for a specific task.
|
|
1734
|
+
* Emits a `leave` event with `{rooms: ["task:{taskId}"]}`.
|
|
1532
1735
|
*/
|
|
1533
|
-
|
|
1736
|
+
unsubscribeTask(taskId) {
|
|
1534
1737
|
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
});
|
|
1738
|
+
this._socket.emit("leave", { rooms: [`task:${taskId}`] });
|
|
1739
|
+
}
|
|
1740
|
+
/**
|
|
1741
|
+
* Subscribe to event-type-scoped rooms.
|
|
1742
|
+
* e.g. subscribeEvents("task_created", "task_deleted")
|
|
1743
|
+
*/
|
|
1744
|
+
subscribeEvents(...eventTypes) {
|
|
1745
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1746
|
+
const rooms = eventTypes.map((t) => `event:${t}`);
|
|
1747
|
+
this._socket.emit("join", { rooms });
|
|
1748
|
+
}
|
|
1749
|
+
/**
|
|
1750
|
+
* Unsubscribe from event-type-scoped rooms.
|
|
1751
|
+
*/
|
|
1752
|
+
unsubscribeEvents(...eventTypes) {
|
|
1753
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1754
|
+
const rooms = eventTypes.map((t) => `event:${t}`);
|
|
1755
|
+
this._socket.emit("leave", { rooms });
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* Subscribe to the `all` broadcast room (receives all events).
|
|
1759
|
+
*/
|
|
1760
|
+
subscribeAll() {
|
|
1761
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1762
|
+
this._socket.emit("join", { rooms: ["all"] });
|
|
1763
|
+
}
|
|
1764
|
+
/**
|
|
1765
|
+
* Subscribe to a locale-specific room.
|
|
1766
|
+
*/
|
|
1767
|
+
subscribeLocale(locale) {
|
|
1768
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1769
|
+
this._socket.emit("join", { rooms: [`locale:${locale}`] });
|
|
1770
|
+
}
|
|
1771
|
+
/**
|
|
1772
|
+
* Unsubscribe from a locale-specific room.
|
|
1773
|
+
*/
|
|
1774
|
+
unsubscribeLocale(locale) {
|
|
1775
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1776
|
+
this._socket.emit("leave", { rooms: [`locale:${locale}`] });
|
|
1777
|
+
}
|
|
1778
|
+
/**
|
|
1779
|
+
* Join arbitrary rooms by name.
|
|
1780
|
+
*/
|
|
1781
|
+
joinRooms(rooms) {
|
|
1782
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1783
|
+
this._socket.emit("join", { rooms });
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Leave arbitrary rooms by name.
|
|
1787
|
+
*/
|
|
1788
|
+
leaveRooms(rooms) {
|
|
1789
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1790
|
+
this._socket.emit("leave", { rooms });
|
|
1791
|
+
}
|
|
1792
|
+
// ------------------------------------------------------------------
|
|
1793
|
+
// Multi-subscriber API (mirrors WebSocketProvider room-diffing)
|
|
1794
|
+
// ------------------------------------------------------------------
|
|
1795
|
+
/**
|
|
1796
|
+
* Register a subscriber that receives all events from the given rooms.
|
|
1797
|
+
*
|
|
1798
|
+
* Room membership is managed automatically: the client joins the union
|
|
1799
|
+
* of all active subscribers' rooms and leaves rooms that are no longer
|
|
1800
|
+
* needed when the last subscriber referencing them is removed.
|
|
1801
|
+
*
|
|
1802
|
+
* The `handler` receives the unwrapped event dict (same object that
|
|
1803
|
+
* `on()` handlers receive).
|
|
1804
|
+
*
|
|
1805
|
+
* Returns an opaque subscription id that must be passed to
|
|
1806
|
+
* `unsubscribe()` to remove the subscription.
|
|
1807
|
+
*
|
|
1808
|
+
* Example — mirror the webui's per-component subscription pattern:
|
|
1809
|
+
*
|
|
1810
|
+
* const id = rt.subscribe((event) => {
|
|
1811
|
+
* if (event.event_type === "task_status_changed") { ... }
|
|
1812
|
+
* }, [`task:${taskId}`]);
|
|
1813
|
+
*
|
|
1814
|
+
* // later, on cleanup:
|
|
1815
|
+
* rt.unsubscribe(id);
|
|
1816
|
+
*/
|
|
1817
|
+
subscribe(handler, rooms) {
|
|
1818
|
+
const id = `sub_${++this._subIdCounter}`;
|
|
1819
|
+
this._subscriptions.set(id, { handler, rooms });
|
|
1820
|
+
this._syncRooms();
|
|
1821
|
+
return id;
|
|
1822
|
+
}
|
|
1823
|
+
/**
|
|
1824
|
+
* Remove a subscription registered via `subscribe()`.
|
|
1825
|
+
*
|
|
1826
|
+
* Rooms that are no longer referenced by any remaining subscriber are
|
|
1827
|
+
* left automatically.
|
|
1828
|
+
*/
|
|
1829
|
+
unsubscribe(id) {
|
|
1830
|
+
this._subscriptions.delete(id);
|
|
1831
|
+
this._syncRooms();
|
|
1832
|
+
}
|
|
1833
|
+
/**
|
|
1834
|
+
* Diff the union of all subscribers' rooms against the currently joined
|
|
1835
|
+
* rooms and emit `join`/`leave` for the delta. No-ops when not connected.
|
|
1836
|
+
*/
|
|
1837
|
+
_syncRooms() {
|
|
1838
|
+
const socket = this._socket;
|
|
1839
|
+
if (!socket?.connected) return;
|
|
1840
|
+
const needed = /* @__PURE__ */ new Set();
|
|
1841
|
+
for (const sub of this._subscriptions.values()) {
|
|
1842
|
+
for (const r of sub.rooms) needed.add(r);
|
|
1843
|
+
}
|
|
1844
|
+
const toJoin = [...needed].filter((r) => !this._currentRooms.has(r));
|
|
1845
|
+
const toLeave = [...this._currentRooms].filter((r) => !needed.has(r));
|
|
1846
|
+
if (toJoin.length) socket.emit("join", { rooms: toJoin });
|
|
1847
|
+
if (toLeave.length) socket.emit("leave", { rooms: toLeave });
|
|
1848
|
+
this._currentRooms = needed;
|
|
1849
|
+
}
|
|
1850
|
+
/**
|
|
1851
|
+
* Send a ping to the server.
|
|
1852
|
+
*/
|
|
1853
|
+
ping() {
|
|
1854
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1855
|
+
this._socket.emit("ping");
|
|
1545
1856
|
}
|
|
1546
1857
|
/**
|
|
1547
1858
|
* Register a handler for a specific event type.
|
|
1859
|
+
*
|
|
1860
|
+
* Domain events (task_created, task_status_changed, etc.) are dispatched
|
|
1861
|
+
* via the message envelope. Raw socket events (connect, disconnect,
|
|
1862
|
+
* connection_established, rooms_updated, pong) are wired directly.
|
|
1548
1863
|
*/
|
|
1549
1864
|
on(event, handler) {
|
|
1550
1865
|
if (!this._handlers.has(event)) {
|
|
1551
1866
|
this._handlers.set(event, /* @__PURE__ */ new Set());
|
|
1552
1867
|
if (this._socket) {
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1868
|
+
const rawSocketEvents = /* @__PURE__ */ new Set([
|
|
1869
|
+
"connect",
|
|
1870
|
+
"disconnect",
|
|
1871
|
+
"connect_error",
|
|
1872
|
+
"connection_established",
|
|
1873
|
+
"rooms_updated",
|
|
1874
|
+
"pong"
|
|
1875
|
+
]);
|
|
1876
|
+
if (rawSocketEvents.has(event)) {
|
|
1877
|
+
this._socket.on(event, (...args) => {
|
|
1878
|
+
const handlers2 = this._handlers.get(event);
|
|
1879
|
+
if (handlers2) {
|
|
1880
|
+
for (const h of handlers2) {
|
|
1881
|
+
h(...args);
|
|
1882
|
+
}
|
|
1558
1883
|
}
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1884
|
+
});
|
|
1885
|
+
}
|
|
1561
1886
|
}
|
|
1562
1887
|
}
|
|
1563
1888
|
const handlers = this._handlers.get(event);
|