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.cjs
CHANGED
|
@@ -148,6 +148,7 @@ var OrchestratorAsync = class {
|
|
|
148
148
|
this._getToken = opts.getToken;
|
|
149
149
|
this._timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
150
150
|
this._maxRetries = opts.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
151
|
+
this._locale = opts.locale;
|
|
151
152
|
this._fetch = opts.fetch ?? globalThis.fetch;
|
|
152
153
|
if (opts.insecure && !opts.fetch && typeof process !== "undefined" && process.versions?.node) {
|
|
153
154
|
this._insecure = true;
|
|
@@ -172,6 +173,9 @@ var OrchestratorAsync = class {
|
|
|
172
173
|
headers.Authorization = `Bearer ${token}`;
|
|
173
174
|
}
|
|
174
175
|
}
|
|
176
|
+
if (this._locale) {
|
|
177
|
+
headers["X-Locale"] = this._locale;
|
|
178
|
+
}
|
|
175
179
|
return headers;
|
|
176
180
|
}
|
|
177
181
|
async _request(method, path, opts) {
|
|
@@ -317,13 +321,17 @@ var OrchestratorAsync = class {
|
|
|
317
321
|
// Tasks
|
|
318
322
|
// ------------------------------------------------------------------
|
|
319
323
|
async listTasks(params) {
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
324
|
+
const headers = {};
|
|
325
|
+
if (params?.locale) headers["X-Locale"] = params.locale;
|
|
326
|
+
const data = await this._request("GET", "/tasks", {
|
|
327
|
+
params: {
|
|
328
|
+
page: params?.page,
|
|
329
|
+
limit: params?.limit,
|
|
330
|
+
order_by: params?.orderBy,
|
|
331
|
+
order_direction: params?.orderDirection,
|
|
332
|
+
workflow_id: params?.workflowId
|
|
333
|
+
},
|
|
334
|
+
headers
|
|
327
335
|
});
|
|
328
336
|
const tasks = (data.tasks ?? []).map(
|
|
329
337
|
buildTaskSummary
|
|
@@ -331,22 +339,36 @@ var OrchestratorAsync = class {
|
|
|
331
339
|
return { tasks, pagination: buildPagination(data) };
|
|
332
340
|
}
|
|
333
341
|
async createTask(params) {
|
|
334
|
-
const data = await this._post("/
|
|
342
|
+
const data = await this._post("/task/create", {
|
|
335
343
|
workflow_id: params.workflowId,
|
|
336
344
|
goal_prompt: params.goalPrompt,
|
|
337
345
|
max_iterations: params.maxIterations,
|
|
338
|
-
|
|
346
|
+
reasoning_effort: params.reasoningEffort,
|
|
347
|
+
system_prompt: params.systemPrompt,
|
|
348
|
+
developer_prompt: params.developerPrompt,
|
|
339
349
|
ticket_id: params.ticketId,
|
|
340
|
-
|
|
341
|
-
|
|
350
|
+
ticket_text: params.ticketText,
|
|
351
|
+
summary: params.summary,
|
|
352
|
+
problem_summary: params.problemSummary,
|
|
353
|
+
solution_strategy: params.solutionStrategy,
|
|
354
|
+
agent_model_id: params.agentModelId,
|
|
355
|
+
orchestrator_model_id: params.orchestratorModelId,
|
|
356
|
+
available_tools: params.availableTools,
|
|
357
|
+
attachment_ids: params.attachmentIds,
|
|
358
|
+
options: params.options
|
|
342
359
|
});
|
|
343
360
|
return {
|
|
344
361
|
taskId: data.taskId ?? data.task_id ?? "",
|
|
345
362
|
status: data.status ?? ""
|
|
346
363
|
};
|
|
347
364
|
}
|
|
348
|
-
async getTaskStatus(taskId) {
|
|
349
|
-
const
|
|
365
|
+
async getTaskStatus(taskId, locale) {
|
|
366
|
+
const headers = {};
|
|
367
|
+
if (locale) headers["X-Locale"] = locale;
|
|
368
|
+
const data = await this._request("GET", "/task/status", {
|
|
369
|
+
params: { task_id: taskId },
|
|
370
|
+
headers
|
|
371
|
+
});
|
|
350
372
|
return {
|
|
351
373
|
...buildTaskSummary(data),
|
|
352
374
|
subtaskIds: data.subtaskIds ?? data.subtask_ids ?? [],
|
|
@@ -354,10 +376,24 @@ var OrchestratorAsync = class {
|
|
|
354
376
|
options: data.options ?? null
|
|
355
377
|
};
|
|
356
378
|
}
|
|
357
|
-
async
|
|
358
|
-
const data = await this.
|
|
359
|
-
|
|
360
|
-
|
|
379
|
+
async setTaskStatus(taskId, status) {
|
|
380
|
+
const data = await this._post("/task/set_status", {
|
|
381
|
+
task_id: taskId,
|
|
382
|
+
status
|
|
383
|
+
});
|
|
384
|
+
return { message: data.message ?? "" };
|
|
385
|
+
}
|
|
386
|
+
async getTaskConversation(taskId, params) {
|
|
387
|
+
const headers = {};
|
|
388
|
+
if (params?.locale) headers["X-Locale"] = params.locale;
|
|
389
|
+
const data = await this._request("GET", "/task/conversation", {
|
|
390
|
+
params: {
|
|
391
|
+
task_id: taskId,
|
|
392
|
+
include_summaries: params?.includeSummaries,
|
|
393
|
+
exclude_archived: params?.excludeArchived
|
|
394
|
+
},
|
|
395
|
+
headers
|
|
396
|
+
});
|
|
361
397
|
return {
|
|
362
398
|
taskId: data.taskId ?? data.task_id ?? taskId,
|
|
363
399
|
conversation: (data.conversation ?? []).map((m) => m)
|
|
@@ -365,19 +401,19 @@ var OrchestratorAsync = class {
|
|
|
365
401
|
}
|
|
366
402
|
async getArchivedMessageContent(taskId, messageId) {
|
|
367
403
|
return this._get(
|
|
368
|
-
|
|
404
|
+
"/task/message/archived-content",
|
|
405
|
+
{ task_id: taskId, message_id: messageId }
|
|
369
406
|
);
|
|
370
407
|
}
|
|
371
408
|
async getTaskCompactions(taskId) {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
);
|
|
375
|
-
return data.compactions ?? [];
|
|
409
|
+
return this._get("/task/compactions", {
|
|
410
|
+
task_id: taskId
|
|
411
|
+
});
|
|
376
412
|
}
|
|
377
413
|
async getTaskJournal(taskId) {
|
|
378
|
-
const data = await this._get(
|
|
379
|
-
|
|
380
|
-
);
|
|
414
|
+
const data = await this._get("/task/journal", {
|
|
415
|
+
task_id: taskId
|
|
416
|
+
});
|
|
381
417
|
return {
|
|
382
418
|
taskId: data.taskId ?? data.task_id ?? taskId,
|
|
383
419
|
exists: data.exists ?? false,
|
|
@@ -388,15 +424,22 @@ var OrchestratorAsync = class {
|
|
|
388
424
|
};
|
|
389
425
|
}
|
|
390
426
|
async cancelTask(taskId) {
|
|
391
|
-
const data = await this._post(
|
|
392
|
-
|
|
393
|
-
);
|
|
394
|
-
return {
|
|
427
|
+
const data = await this._post("/task/cancel", {
|
|
428
|
+
task_id: taskId
|
|
429
|
+
});
|
|
430
|
+
return {
|
|
431
|
+
taskId: data.taskId ?? data.task_id ?? taskId,
|
|
432
|
+
killed: data.killed ?? false,
|
|
433
|
+
via: data.via ?? "none",
|
|
434
|
+
holderId: data.holderId ?? data.holder_id ?? void 0,
|
|
435
|
+
reason: data.reason ?? void 0,
|
|
436
|
+
message: data.message ?? ""
|
|
437
|
+
};
|
|
395
438
|
}
|
|
396
439
|
async deleteTask(taskId) {
|
|
397
|
-
const data = await this.
|
|
398
|
-
|
|
399
|
-
);
|
|
440
|
+
const data = await this._post("/task/delete", {
|
|
441
|
+
task_id: taskId
|
|
442
|
+
});
|
|
400
443
|
return {
|
|
401
444
|
deletedTasks: data.deletedTasks ?? data.deleted_tasks ?? [],
|
|
402
445
|
failedTasks: data.failedTasks ?? data.failed_tasks ?? [],
|
|
@@ -405,9 +448,10 @@ var OrchestratorAsync = class {
|
|
|
405
448
|
};
|
|
406
449
|
}
|
|
407
450
|
async deleteTasks(taskIds) {
|
|
408
|
-
const data = await this._post(
|
|
409
|
-
|
|
410
|
-
|
|
451
|
+
const data = await this._post(
|
|
452
|
+
"/task/delete/multiple",
|
|
453
|
+
{ task_ids: taskIds }
|
|
454
|
+
);
|
|
411
455
|
return {
|
|
412
456
|
deletedTasks: data.deletedTasks ?? data.deleted_tasks ?? [],
|
|
413
457
|
failedTasks: data.failedTasks ?? data.failed_tasks ?? [],
|
|
@@ -418,18 +462,15 @@ var OrchestratorAsync = class {
|
|
|
418
462
|
// ------------------------------------------------------------------
|
|
419
463
|
// Attachments
|
|
420
464
|
// ------------------------------------------------------------------
|
|
421
|
-
async uploadAttachment(
|
|
465
|
+
async uploadAttachment(file, filename) {
|
|
422
466
|
const formData = new FormData();
|
|
423
467
|
formData.append("file", file, filename);
|
|
424
468
|
const headers = await this._resolveHeaders();
|
|
425
|
-
const response = await this._fetch(
|
|
426
|
-
|
|
427
|
-
{
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
body: formData
|
|
431
|
-
}
|
|
432
|
-
);
|
|
469
|
+
const response = await this._fetch(this._makeUrl("/attachment"), {
|
|
470
|
+
method: "POST",
|
|
471
|
+
headers: { ...headers },
|
|
472
|
+
body: formData
|
|
473
|
+
});
|
|
433
474
|
if (!response.ok) {
|
|
434
475
|
throw new OrchestratorAPIError(
|
|
435
476
|
`Attachment upload failed: ${response.statusText}`,
|
|
@@ -447,13 +488,11 @@ var OrchestratorAsync = class {
|
|
|
447
488
|
tokenCount: data.tokenCount ?? data.token_count ?? null
|
|
448
489
|
};
|
|
449
490
|
}
|
|
450
|
-
async downloadAttachment(
|
|
491
|
+
async downloadAttachment(attachmentId) {
|
|
451
492
|
const headers = await this._resolveHeaders();
|
|
452
493
|
const response = await this._fetch(
|
|
453
|
-
this._makeUrl(`/
|
|
454
|
-
{
|
|
455
|
-
headers
|
|
456
|
-
}
|
|
494
|
+
this._makeUrl(`/attachment/${attachmentId}`),
|
|
495
|
+
{ headers }
|
|
457
496
|
);
|
|
458
497
|
if (!response.ok) {
|
|
459
498
|
throw new OrchestratorAPIError(
|
|
@@ -466,126 +505,135 @@ var OrchestratorAsync = class {
|
|
|
466
505
|
// ------------------------------------------------------------------
|
|
467
506
|
// Interactive workflow
|
|
468
507
|
// ------------------------------------------------------------------
|
|
469
|
-
async sendInteractiveMessage(taskId,
|
|
508
|
+
async sendInteractiveMessage(taskId, message, attachmentIds) {
|
|
470
509
|
const data = await this._post(
|
|
471
|
-
|
|
472
|
-
{
|
|
473
|
-
content
|
|
474
|
-
}
|
|
510
|
+
"/task/interactive/message",
|
|
511
|
+
{ task_id: taskId, message, attachment_ids: attachmentIds }
|
|
475
512
|
);
|
|
476
513
|
return { message: data.message ?? "" };
|
|
477
514
|
}
|
|
478
515
|
async markInteractiveComplete(taskId) {
|
|
479
516
|
const data = await this._post(
|
|
480
|
-
|
|
517
|
+
"/task/interactive/mark_complete",
|
|
518
|
+
{ task_id: taskId }
|
|
481
519
|
);
|
|
482
520
|
return { message: data.message ?? "" };
|
|
483
521
|
}
|
|
484
522
|
async markInteractiveFailed(taskId) {
|
|
485
523
|
const data = await this._post(
|
|
486
|
-
|
|
524
|
+
"/task/interactive/mark_failed",
|
|
525
|
+
{ task_id: taskId }
|
|
487
526
|
);
|
|
488
527
|
return { message: data.message ?? "" };
|
|
489
528
|
}
|
|
490
|
-
async approveInteractiveAction(taskId) {
|
|
529
|
+
async approveInteractiveAction(taskId, approved = true) {
|
|
491
530
|
const data = await this._post(
|
|
492
|
-
|
|
531
|
+
"/task/interactive/action",
|
|
532
|
+
{ task_id: taskId, approved }
|
|
533
|
+
);
|
|
534
|
+
return { message: data.message ?? "" };
|
|
535
|
+
}
|
|
536
|
+
async stopInteractive(taskId) {
|
|
537
|
+
const data = await this._post(
|
|
538
|
+
"/task/interactive/stop",
|
|
539
|
+
{ task_id: taskId }
|
|
493
540
|
);
|
|
494
541
|
return { message: data.message ?? "" };
|
|
495
542
|
}
|
|
496
543
|
// ------------------------------------------------------------------
|
|
497
544
|
// Proactive workflow
|
|
498
545
|
// ------------------------------------------------------------------
|
|
499
|
-
async sendProactiveGuide(taskId,
|
|
546
|
+
async sendProactiveGuide(taskId, message, attachmentIds) {
|
|
500
547
|
const data = await this._post(
|
|
501
|
-
|
|
502
|
-
{
|
|
503
|
-
guide
|
|
504
|
-
}
|
|
548
|
+
"/task/proactive/guide",
|
|
549
|
+
{ task_id: taskId, message, attachment_ids: attachmentIds }
|
|
505
550
|
);
|
|
506
551
|
return { message: data.message ?? "" };
|
|
507
552
|
}
|
|
508
553
|
async respondProactiveHelp(taskId, response) {
|
|
509
554
|
const data = await this._post(
|
|
510
|
-
|
|
511
|
-
{
|
|
512
|
-
response
|
|
513
|
-
}
|
|
555
|
+
"/task/proactive/help",
|
|
556
|
+
{ task_id: taskId, response }
|
|
514
557
|
);
|
|
515
558
|
return { message: data.message ?? "" };
|
|
516
559
|
}
|
|
517
|
-
async approveProactiveAction(taskId) {
|
|
560
|
+
async approveProactiveAction(taskId, approved = true) {
|
|
518
561
|
const data = await this._post(
|
|
519
|
-
|
|
562
|
+
"/task/proactive/action",
|
|
563
|
+
{ task_id: taskId, approved }
|
|
520
564
|
);
|
|
521
565
|
return { message: data.message ?? "" };
|
|
522
566
|
}
|
|
523
567
|
// ------------------------------------------------------------------
|
|
524
568
|
// Ticket workflow
|
|
525
569
|
// ------------------------------------------------------------------
|
|
526
|
-
async sendTicketGuide(taskId,
|
|
570
|
+
async sendTicketGuide(taskId, message, attachmentIds) {
|
|
527
571
|
const data = await this._post(
|
|
528
|
-
|
|
529
|
-
{
|
|
530
|
-
guide
|
|
531
|
-
}
|
|
572
|
+
"/task/ticket/guide",
|
|
573
|
+
{ task_id: taskId, message, attachment_ids: attachmentIds }
|
|
532
574
|
);
|
|
533
575
|
return { message: data.message ?? "" };
|
|
534
576
|
}
|
|
535
577
|
async respondTicketHelp(taskId, response) {
|
|
536
578
|
const data = await this._post(
|
|
537
|
-
|
|
538
|
-
{
|
|
539
|
-
response
|
|
540
|
-
}
|
|
579
|
+
"/task/ticket/help",
|
|
580
|
+
{ task_id: taskId, response }
|
|
541
581
|
);
|
|
542
582
|
return { message: data.message ?? "" };
|
|
543
583
|
}
|
|
544
|
-
async approveTicketAction(taskId) {
|
|
584
|
+
async approveTicketAction(taskId, approved = true) {
|
|
545
585
|
const data = await this._post(
|
|
546
|
-
|
|
586
|
+
"/task/ticket/action",
|
|
587
|
+
{ task_id: taskId, approved }
|
|
547
588
|
);
|
|
548
589
|
return { message: data.message ?? "" };
|
|
549
590
|
}
|
|
550
591
|
async wakeTicket(taskId) {
|
|
551
592
|
const data = await this._post(
|
|
552
|
-
|
|
593
|
+
"/task/ticket/wake",
|
|
594
|
+
{ task_id: taskId }
|
|
553
595
|
);
|
|
554
596
|
return { message: data.message ?? "" };
|
|
555
597
|
}
|
|
556
598
|
// ------------------------------------------------------------------
|
|
557
599
|
// Matrix workflow
|
|
558
600
|
// ------------------------------------------------------------------
|
|
559
|
-
async sendMatrixMessage(taskId,
|
|
601
|
+
async sendMatrixMessage(taskId, message, attachmentIds) {
|
|
560
602
|
const data = await this._post(
|
|
561
|
-
|
|
562
|
-
{
|
|
563
|
-
content
|
|
564
|
-
}
|
|
603
|
+
"/task/matrix/message",
|
|
604
|
+
{ task_id: taskId, message, attachment_ids: attachmentIds }
|
|
565
605
|
);
|
|
566
606
|
return { message: data.message ?? "" };
|
|
567
607
|
}
|
|
568
608
|
async markMatrixComplete(taskId) {
|
|
569
609
|
const data = await this._post(
|
|
570
|
-
|
|
610
|
+
"/task/matrix/mark_complete",
|
|
611
|
+
{ task_id: taskId }
|
|
571
612
|
);
|
|
572
613
|
return { message: data.message ?? "" };
|
|
573
614
|
}
|
|
574
615
|
async markMatrixFailed(taskId) {
|
|
575
616
|
const data = await this._post(
|
|
576
|
-
|
|
617
|
+
"/task/matrix/mark_failed",
|
|
618
|
+
{ task_id: taskId }
|
|
577
619
|
);
|
|
578
620
|
return { message: data.message ?? "" };
|
|
579
621
|
}
|
|
580
|
-
async approveMatrixAction(taskId) {
|
|
622
|
+
async approveMatrixAction(taskId, approved = true) {
|
|
581
623
|
const data = await this._post(
|
|
582
|
-
|
|
624
|
+
"/task/matrix/action",
|
|
625
|
+
{ task_id: taskId, approved }
|
|
583
626
|
);
|
|
584
627
|
return { message: data.message ?? "" };
|
|
585
628
|
}
|
|
586
|
-
async getMatrixConversation(taskId) {
|
|
629
|
+
async getMatrixConversation(taskId, phase, includeSummaries) {
|
|
587
630
|
const data = await this._get(
|
|
588
|
-
|
|
631
|
+
"/task/matrix/conversation",
|
|
632
|
+
{
|
|
633
|
+
task_id: taskId,
|
|
634
|
+
phase,
|
|
635
|
+
include_summaries: includeSummaries
|
|
636
|
+
}
|
|
589
637
|
);
|
|
590
638
|
return {
|
|
591
639
|
taskId: data.taskId ?? data.task_id ?? taskId,
|
|
@@ -597,72 +645,84 @@ var OrchestratorAsync = class {
|
|
|
597
645
|
// ------------------------------------------------------------------
|
|
598
646
|
async createVSATask(params) {
|
|
599
647
|
const body = {
|
|
648
|
+
user_id: params.userId,
|
|
600
649
|
goal_prompt: params.goalPrompt,
|
|
601
650
|
title: params.title,
|
|
602
|
-
|
|
651
|
+
agent_model_id: params.agentModelId,
|
|
652
|
+
orchestrator_model_id: params.orchestratorModelId,
|
|
653
|
+
attachment_ids: params.attachmentIds,
|
|
654
|
+
options: params.options
|
|
603
655
|
};
|
|
604
656
|
if (params.delegatedToken !== void 0) {
|
|
605
657
|
body.delegated_token = params.delegatedToken;
|
|
606
658
|
}
|
|
607
|
-
const data = await this._post(
|
|
659
|
+
const data = await this._post(
|
|
660
|
+
"/task/vsa/create",
|
|
661
|
+
body
|
|
662
|
+
);
|
|
608
663
|
return {
|
|
609
664
|
taskId: data.taskId ?? data.task_id ?? "",
|
|
610
665
|
status: data.status ?? ""
|
|
611
666
|
};
|
|
612
667
|
}
|
|
613
|
-
async sendVSAMessage(taskId,
|
|
614
|
-
const body = {
|
|
668
|
+
async sendVSAMessage(taskId, message, options) {
|
|
669
|
+
const body = {
|
|
670
|
+
task_id: taskId,
|
|
671
|
+
message,
|
|
672
|
+
attachment_ids: options?.attachmentIds
|
|
673
|
+
};
|
|
615
674
|
if (options?.delegatedToken !== void 0) {
|
|
616
675
|
body.delegated_token = options.delegatedToken;
|
|
617
676
|
}
|
|
618
677
|
const data = await this._post(
|
|
619
|
-
|
|
678
|
+
"/task/vsa/message",
|
|
620
679
|
body
|
|
621
680
|
);
|
|
622
681
|
return { message: data.message ?? "" };
|
|
623
682
|
}
|
|
624
683
|
async renameVSATask(taskId, title) {
|
|
625
|
-
const data = await this._post(
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
}
|
|
630
|
-
);
|
|
684
|
+
const data = await this._post("/task/vsa/rename", {
|
|
685
|
+
task_id: taskId,
|
|
686
|
+
title
|
|
687
|
+
});
|
|
631
688
|
return { message: data.message ?? "" };
|
|
632
689
|
}
|
|
633
690
|
async regenerateVSATitle(taskId) {
|
|
634
691
|
const data = await this._post(
|
|
635
|
-
|
|
692
|
+
"/task/vsa/regenerate_title",
|
|
693
|
+
{ task_id: taskId }
|
|
636
694
|
);
|
|
637
695
|
return { message: data.message ?? "" };
|
|
638
696
|
}
|
|
639
697
|
async markVSAComplete(taskId) {
|
|
640
698
|
const data = await this._post(
|
|
641
|
-
|
|
699
|
+
"/task/vsa/mark_complete",
|
|
700
|
+
{ task_id: taskId }
|
|
642
701
|
);
|
|
643
702
|
return { message: data.message ?? "" };
|
|
644
703
|
}
|
|
645
704
|
async markVSAFailed(taskId) {
|
|
646
705
|
const data = await this._post(
|
|
647
|
-
|
|
706
|
+
"/task/vsa/mark_failed",
|
|
707
|
+
{ task_id: taskId }
|
|
648
708
|
);
|
|
649
709
|
return { message: data.message ?? "" };
|
|
650
710
|
}
|
|
651
711
|
async stopVSA(taskId) {
|
|
652
|
-
const data = await this._post(
|
|
653
|
-
|
|
654
|
-
);
|
|
712
|
+
const data = await this._post("/task/vsa/stop", {
|
|
713
|
+
task_id: taskId
|
|
714
|
+
});
|
|
655
715
|
return { message: data.message ?? "" };
|
|
656
716
|
}
|
|
657
717
|
async deleteVSA(taskId) {
|
|
658
|
-
const data = await this.
|
|
659
|
-
|
|
660
|
-
);
|
|
718
|
+
const data = await this._post("/task/vsa/delete", {
|
|
719
|
+
task_id: taskId
|
|
720
|
+
});
|
|
661
721
|
return { message: data.message ?? "" };
|
|
662
722
|
}
|
|
663
|
-
async listVSATasks(params) {
|
|
664
|
-
const data = await this._get("/
|
|
665
|
-
|
|
723
|
+
async listVSATasks(userId, params) {
|
|
724
|
+
const data = await this._get("/task/vsa/list", {
|
|
725
|
+
user_id: userId,
|
|
666
726
|
limit: params?.limit,
|
|
667
727
|
offset: params?.offset
|
|
668
728
|
});
|
|
@@ -671,9 +731,11 @@ var OrchestratorAsync = class {
|
|
|
671
731
|
);
|
|
672
732
|
return { tasks, pagination: buildPagination(data) };
|
|
673
733
|
}
|
|
674
|
-
async searchVSATasks(query) {
|
|
675
|
-
const data = await this._get("/
|
|
676
|
-
|
|
734
|
+
async searchVSATasks(userId, query, limit) {
|
|
735
|
+
const data = await this._get("/task/vsa/search", {
|
|
736
|
+
user_id: userId,
|
|
737
|
+
query,
|
|
738
|
+
limit
|
|
677
739
|
});
|
|
678
740
|
const tasks = (data.tasks ?? []).map(
|
|
679
741
|
buildTaskSummary
|
|
@@ -682,91 +744,123 @@ var OrchestratorAsync = class {
|
|
|
682
744
|
}
|
|
683
745
|
async deleteVSATasksBulk(taskIds) {
|
|
684
746
|
const data = await this._post(
|
|
685
|
-
"/
|
|
686
|
-
{
|
|
687
|
-
task_ids: taskIds
|
|
688
|
-
}
|
|
747
|
+
"/task/vsa/delete_bulk",
|
|
748
|
+
{ task_ids: taskIds }
|
|
689
749
|
);
|
|
690
|
-
return {
|
|
750
|
+
return {
|
|
751
|
+
deletedTasks: data.deletedTasks ?? data.deleted_tasks ?? [],
|
|
752
|
+
failedTasks: data.failedTasks ?? data.failed_tasks ?? [],
|
|
753
|
+
totalDeleted: data.totalDeleted ?? data.total_deleted ?? 0,
|
|
754
|
+
totalFailed: data.totalFailed ?? data.total_failed ?? 0
|
|
755
|
+
};
|
|
691
756
|
}
|
|
692
757
|
// ------------------------------------------------------------------
|
|
693
|
-
// MIO workflow
|
|
758
|
+
// MIO (self_managed) workflow
|
|
694
759
|
// ------------------------------------------------------------------
|
|
695
|
-
async sendMioMessage(taskId,
|
|
760
|
+
async sendMioMessage(taskId, message, attachmentIds) {
|
|
696
761
|
const data = await this._post(
|
|
697
|
-
|
|
698
|
-
{
|
|
699
|
-
content
|
|
700
|
-
}
|
|
762
|
+
"/task/self_managed/message",
|
|
763
|
+
{ task_id: taskId, message, attachment_ids: attachmentIds }
|
|
701
764
|
);
|
|
702
765
|
return { message: data.message ?? "" };
|
|
703
766
|
}
|
|
704
|
-
async approveMioAction(taskId) {
|
|
767
|
+
async approveMioAction(taskId, approved = true, feedback) {
|
|
705
768
|
const data = await this._post(
|
|
706
|
-
|
|
769
|
+
"/task/self_managed/action",
|
|
770
|
+
{ task_id: taskId, approved, feedback }
|
|
707
771
|
);
|
|
708
772
|
return { message: data.message ?? "" };
|
|
709
773
|
}
|
|
710
774
|
async wakeMio(taskId) {
|
|
711
775
|
const data = await this._post(
|
|
712
|
-
|
|
776
|
+
"/task/self_managed/wake",
|
|
777
|
+
{ task_id: taskId }
|
|
713
778
|
);
|
|
714
779
|
return { message: data.message ?? "" };
|
|
715
780
|
}
|
|
716
781
|
async sendMioUserAway(taskId) {
|
|
717
782
|
const data = await this._post(
|
|
718
|
-
|
|
783
|
+
"/task/self_managed/user_away",
|
|
784
|
+
{ task_id: taskId }
|
|
719
785
|
);
|
|
720
786
|
return { message: data.message ?? "" };
|
|
721
787
|
}
|
|
722
788
|
async markMioComplete(taskId) {
|
|
723
789
|
const data = await this._post(
|
|
724
|
-
|
|
790
|
+
"/task/self_managed/mark_complete",
|
|
791
|
+
{ task_id: taskId }
|
|
725
792
|
);
|
|
726
793
|
return { message: data.message ?? "" };
|
|
727
794
|
}
|
|
728
795
|
async markMioFailed(taskId) {
|
|
729
796
|
const data = await this._post(
|
|
730
|
-
|
|
797
|
+
"/task/self_managed/mark_failed",
|
|
798
|
+
{ task_id: taskId }
|
|
731
799
|
);
|
|
732
800
|
return { message: data.message ?? "" };
|
|
733
801
|
}
|
|
734
802
|
async archiveMio(taskId) {
|
|
735
803
|
const data = await this._post(
|
|
736
|
-
|
|
804
|
+
"/task/self_managed/archive",
|
|
805
|
+
{ task_id: taskId }
|
|
737
806
|
);
|
|
738
807
|
return { message: data.message ?? "" };
|
|
739
808
|
}
|
|
740
809
|
async getMioContext(taskId) {
|
|
741
810
|
const data = await this._get(
|
|
742
|
-
|
|
811
|
+
"/task/self_managed/context",
|
|
812
|
+
{ task_id: taskId }
|
|
743
813
|
);
|
|
744
814
|
return {
|
|
745
815
|
taskId: data.taskId ?? data.task_id ?? taskId,
|
|
816
|
+
modelId: data.modelId ?? data.model_id ?? "",
|
|
746
817
|
currentTokens: data.currentTokens ?? data.current_tokens ?? 0,
|
|
747
818
|
contextLimit: data.contextLimit ?? data.context_limit ?? 0,
|
|
748
819
|
usagePercentage: data.usagePercentage ?? data.usage_percentage ?? 0,
|
|
749
|
-
|
|
750
|
-
|
|
820
|
+
totalMessages: data.totalMessages ?? data.total_messages ?? 0,
|
|
821
|
+
activeMessages: data.activeMessages ?? data.active_messages ?? 0,
|
|
822
|
+
archivedMessages: data.archivedMessages ?? data.archived_messages ?? 0,
|
|
823
|
+
messagesWithoutTokenCount: data.messagesWithoutTokenCount ?? data.messages_without_token_count ?? 0
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
async getMioMemories(taskId, includeCommon) {
|
|
827
|
+
const data = await this._get(
|
|
828
|
+
"/task/self_managed/memories",
|
|
829
|
+
{ task_id: taskId, include_common: includeCommon }
|
|
830
|
+
);
|
|
831
|
+
return {
|
|
832
|
+
memories: data.memories ?? [],
|
|
833
|
+
total: data.total ?? 0
|
|
751
834
|
};
|
|
752
835
|
}
|
|
753
836
|
// ------------------------------------------------------------------
|
|
754
837
|
// Tools
|
|
755
838
|
// ------------------------------------------------------------------
|
|
756
839
|
async listTools() {
|
|
757
|
-
const data = await this._get("/tools");
|
|
840
|
+
const data = await this._get("/tools/all");
|
|
758
841
|
return {
|
|
759
|
-
tools: (data.tools ??
|
|
842
|
+
tools: (data.tools ?? []).map(
|
|
843
|
+
(t) => t
|
|
844
|
+
),
|
|
760
845
|
totalTools: data.totalTools ?? data.total_tools ?? 0,
|
|
761
846
|
servers: data.servers ?? []
|
|
762
847
|
};
|
|
763
848
|
}
|
|
849
|
+
async getToolCatalog() {
|
|
850
|
+
return this._get("/tools/catalog");
|
|
851
|
+
}
|
|
852
|
+
async refreshMCPTools() {
|
|
853
|
+
return this._post("/tools/mcp/refresh");
|
|
854
|
+
}
|
|
855
|
+
async validateToolCatalog() {
|
|
856
|
+
return this._get("/tools/validate");
|
|
857
|
+
}
|
|
764
858
|
// ------------------------------------------------------------------
|
|
765
859
|
// Debug / Admin
|
|
766
860
|
// ------------------------------------------------------------------
|
|
767
861
|
async getWorkflowStates() {
|
|
768
862
|
const data = await this._get(
|
|
769
|
-
"/debug/
|
|
863
|
+
"/debug/workflow_states"
|
|
770
864
|
);
|
|
771
865
|
return {
|
|
772
866
|
validStates: data.validStates ?? data.valid_states ?? {},
|
|
@@ -778,65 +872,65 @@ var OrchestratorAsync = class {
|
|
|
778
872
|
}
|
|
779
873
|
async updateTaskModels(taskId, models) {
|
|
780
874
|
const data = await this._post(
|
|
781
|
-
|
|
875
|
+
"/debug/task/models",
|
|
782
876
|
{
|
|
783
|
-
|
|
784
|
-
|
|
877
|
+
task_id: taskId,
|
|
878
|
+
agent_model_id: models.agentModelId,
|
|
879
|
+
orchestrator_model_id: models.orchestratorModelId
|
|
785
880
|
}
|
|
786
881
|
);
|
|
787
882
|
return { message: data.message ?? "" };
|
|
788
883
|
}
|
|
789
|
-
async updateTaskIteration(taskId, iteration) {
|
|
884
|
+
async updateTaskIteration(taskId, iteration, maxIterations) {
|
|
790
885
|
const data = await this._post(
|
|
791
|
-
|
|
792
|
-
{
|
|
793
|
-
iteration
|
|
794
|
-
}
|
|
886
|
+
"/debug/task/iteration",
|
|
887
|
+
{ task_id: taskId, iteration, max_iterations: maxIterations }
|
|
795
888
|
);
|
|
796
889
|
return { message: data.message ?? "" };
|
|
797
890
|
}
|
|
798
891
|
async updateTaskWorkflowData(taskId, workflowData) {
|
|
799
892
|
const data = await this._post(
|
|
800
|
-
|
|
801
|
-
{
|
|
802
|
-
workflow_data: workflowData
|
|
803
|
-
}
|
|
893
|
+
"/debug/task/workflow_data",
|
|
894
|
+
{ task_id: taskId, workflow_data: workflowData }
|
|
804
895
|
);
|
|
805
896
|
return { message: data.message ?? "" };
|
|
806
897
|
}
|
|
807
898
|
async deleteMessage(taskId, messageId) {
|
|
808
|
-
const data = await this.
|
|
809
|
-
|
|
899
|
+
const data = await this._post(
|
|
900
|
+
"/debug/task/message/delete",
|
|
901
|
+
{ task_id: taskId, message_id: messageId }
|
|
810
902
|
);
|
|
811
903
|
return { message: data.message ?? "" };
|
|
812
904
|
}
|
|
813
905
|
async deleteMessages(taskId, messageIds) {
|
|
814
906
|
const data = await this._post(
|
|
815
|
-
|
|
816
|
-
{ message_ids: messageIds }
|
|
907
|
+
"/debug/task/message/delete/multiple",
|
|
908
|
+
{ task_id: taskId, message_ids: messageIds }
|
|
817
909
|
);
|
|
818
|
-
return {
|
|
910
|
+
return {
|
|
911
|
+
deletedIds: data.deletedIds ?? data.deleted_ids ?? [],
|
|
912
|
+
failedIds: data.failedIds ?? data.failed_ids ?? [],
|
|
913
|
+
totalDeleted: data.totalDeleted ?? data.total_deleted ?? 0,
|
|
914
|
+
totalFailed: data.totalFailed ?? data.total_failed ?? 0
|
|
915
|
+
};
|
|
819
916
|
}
|
|
820
917
|
async updateMessage(taskId, messageId, update) {
|
|
821
|
-
const data = await this.
|
|
822
|
-
|
|
823
|
-
update
|
|
918
|
+
const data = await this._post(
|
|
919
|
+
"/debug/task/message/update",
|
|
920
|
+
{ task_id: taskId, message_id: messageId, ...update }
|
|
824
921
|
);
|
|
825
922
|
return { message: data.message ?? "" };
|
|
826
923
|
}
|
|
827
924
|
async resetMatrixToPhase(taskId, phase) {
|
|
828
925
|
const data = await this._post(
|
|
829
|
-
|
|
830
|
-
{ phase }
|
|
926
|
+
"/debug/task/matrix/reset_to_phase",
|
|
927
|
+
{ task_id: taskId, phase }
|
|
831
928
|
);
|
|
832
929
|
return { message: data.message ?? "" };
|
|
833
930
|
}
|
|
834
|
-
async getMessageTranslations(taskId, messageId
|
|
835
|
-
const params = {};
|
|
836
|
-
if (locale) params.locale = locale;
|
|
931
|
+
async getMessageTranslations(taskId, messageId) {
|
|
837
932
|
const data = await this._get(
|
|
838
|
-
`/
|
|
839
|
-
params
|
|
933
|
+
`/debug/task/${taskId}/message/${messageId}/translations`
|
|
840
934
|
);
|
|
841
935
|
return {
|
|
842
936
|
messageId: data.messageId ?? data.message_id ?? messageId,
|
|
@@ -847,25 +941,54 @@ var OrchestratorAsync = class {
|
|
|
847
941
|
// Error events
|
|
848
942
|
// ------------------------------------------------------------------
|
|
849
943
|
async listErrors(params) {
|
|
850
|
-
const
|
|
851
|
-
|
|
852
|
-
if (params?.
|
|
853
|
-
|
|
854
|
-
if (params?.limit
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
);
|
|
860
|
-
|
|
861
|
-
(
|
|
862
|
-
);
|
|
944
|
+
const authHeaders = await this._resolveHeaders();
|
|
945
|
+
const url = new URL(this._makeUrl("/errors"));
|
|
946
|
+
if (params?.page !== void 0)
|
|
947
|
+
url.searchParams.set("page", String(params.page));
|
|
948
|
+
if (params?.limit !== void 0)
|
|
949
|
+
url.searchParams.set("limit", String(params.limit));
|
|
950
|
+
if (params?.taskId) url.searchParams.set("task_id", params.taskId);
|
|
951
|
+
if (params?.workflowId)
|
|
952
|
+
url.searchParams.set("workflow_id", params.workflowId);
|
|
953
|
+
if (params?.errorCode) url.searchParams.set("error_code", params.errorCode);
|
|
954
|
+
if (params?.exceptionType)
|
|
955
|
+
url.searchParams.set("exception_type", params.exceptionType);
|
|
956
|
+
if (params?.holderId) url.searchParams.set("holder_id", params.holderId);
|
|
957
|
+
if (params?.requestId) url.searchParams.set("request_id", params.requestId);
|
|
958
|
+
if (params?.search) url.searchParams.set("search", params.search);
|
|
959
|
+
if (params?.since) url.searchParams.set("since", params.since);
|
|
960
|
+
if (params?.until) url.searchParams.set("until", params.until);
|
|
961
|
+
if (params?.orderDirection)
|
|
962
|
+
url.searchParams.set("order_direction", params.orderDirection);
|
|
963
|
+
for (const s of params?.severity ?? []) {
|
|
964
|
+
url.searchParams.append("severity", s);
|
|
965
|
+
}
|
|
966
|
+
for (const s of params?.source ?? []) {
|
|
967
|
+
url.searchParams.append("source", s);
|
|
968
|
+
}
|
|
969
|
+
const response = await this._fetch(url.toString(), {
|
|
970
|
+
method: "GET",
|
|
971
|
+
headers: { ...authHeaders }
|
|
972
|
+
});
|
|
973
|
+
if (!response.ok) {
|
|
974
|
+
throw new OrchestratorAPIError(
|
|
975
|
+
`listErrors failed: ${response.statusText}`,
|
|
976
|
+
response.status
|
|
977
|
+
);
|
|
978
|
+
}
|
|
979
|
+
const data = await response.json();
|
|
980
|
+
return {
|
|
981
|
+
items: (data.items ?? data.errors ?? []).map((e) => e),
|
|
982
|
+
pagination: buildPagination(data)
|
|
983
|
+
};
|
|
863
984
|
}
|
|
864
985
|
async getErrorDetail(errorId) {
|
|
865
986
|
return this._get(`/errors/${errorId}`);
|
|
866
987
|
}
|
|
867
|
-
async getErrorStats(since) {
|
|
868
|
-
const params = {
|
|
988
|
+
async getErrorStats(since, topN = 10) {
|
|
989
|
+
const params = {
|
|
990
|
+
top_n: topN
|
|
991
|
+
};
|
|
869
992
|
if (since) params.since = since;
|
|
870
993
|
return this._get("/errors/stats", params);
|
|
871
994
|
}
|
|
@@ -884,13 +1007,13 @@ var OrchestratorAsync = class {
|
|
|
884
1007
|
return this._get("/health");
|
|
885
1008
|
}
|
|
886
1009
|
async healthDetailed() {
|
|
887
|
-
return this._get("/health/
|
|
1010
|
+
return this._get("/health/detailed");
|
|
888
1011
|
}
|
|
889
1012
|
async ready() {
|
|
890
1013
|
return this._get("/ready");
|
|
891
1014
|
}
|
|
892
1015
|
async healthLeader() {
|
|
893
|
-
return this._get("/leader");
|
|
1016
|
+
return this._get("/health/leader");
|
|
894
1017
|
}
|
|
895
1018
|
async getMetrics(types) {
|
|
896
1019
|
const params = {};
|
|
@@ -901,107 +1024,122 @@ var OrchestratorAsync = class {
|
|
|
901
1024
|
// Configuration
|
|
902
1025
|
// ------------------------------------------------------------------
|
|
903
1026
|
async getSystemStatus() {
|
|
904
|
-
return this._get("/
|
|
1027
|
+
return this._get("/configuration/system/status");
|
|
905
1028
|
}
|
|
906
1029
|
async updateSettings(settings) {
|
|
907
|
-
return this._post("/
|
|
1030
|
+
return this._post("/configuration/system/settings", settings);
|
|
908
1031
|
}
|
|
909
1032
|
async getConfigurationStatus() {
|
|
910
|
-
return this._get("/
|
|
1033
|
+
return this._get("/configuration/status");
|
|
911
1034
|
}
|
|
912
1035
|
async setAgentModel(model) {
|
|
913
1036
|
const data = await this._post(
|
|
914
|
-
"/
|
|
915
|
-
{ model }
|
|
1037
|
+
"/configuration/agent",
|
|
1038
|
+
{ model_name: model }
|
|
916
1039
|
);
|
|
917
1040
|
return { message: data.message ?? "" };
|
|
918
1041
|
}
|
|
919
1042
|
async setOrchestratorModel(model) {
|
|
920
1043
|
const data = await this._post(
|
|
921
|
-
"/
|
|
922
|
-
{ model }
|
|
1044
|
+
"/configuration/orchestrator",
|
|
1045
|
+
{ model_name: model }
|
|
923
1046
|
);
|
|
924
1047
|
return { message: data.message ?? "" };
|
|
925
1048
|
}
|
|
926
1049
|
async getLLMBackendStatus() {
|
|
927
|
-
return this._get(
|
|
1050
|
+
return this._get(
|
|
1051
|
+
"/configuration/llmbackend/status"
|
|
1052
|
+
);
|
|
928
1053
|
}
|
|
929
1054
|
async addLLMBackend(host, apiKey) {
|
|
930
1055
|
const data = await this._post(
|
|
931
|
-
"/
|
|
932
|
-
{
|
|
933
|
-
host,
|
|
934
|
-
api_key: apiKey
|
|
935
|
-
}
|
|
1056
|
+
"/configuration/llmbackend/add",
|
|
1057
|
+
{ backends: [{ url: host, api_key: apiKey }] }
|
|
936
1058
|
);
|
|
937
1059
|
return { message: data.message ?? "" };
|
|
938
1060
|
}
|
|
939
1061
|
async removeLLMBackend(host) {
|
|
940
|
-
const data = await this.
|
|
941
|
-
|
|
1062
|
+
const data = await this._post(
|
|
1063
|
+
"/configuration/llmbackend/remove",
|
|
1064
|
+
{ host }
|
|
942
1065
|
);
|
|
943
1066
|
return { message: data.message ?? "" };
|
|
944
1067
|
}
|
|
945
1068
|
async getMCPServerStatus() {
|
|
946
|
-
return this._get(
|
|
1069
|
+
return this._get(
|
|
1070
|
+
"/configuration/mcpserver/status"
|
|
1071
|
+
);
|
|
947
1072
|
}
|
|
948
1073
|
async addMCPServer(host, apiKey) {
|
|
949
1074
|
const data = await this._post(
|
|
950
|
-
"/
|
|
951
|
-
{
|
|
952
|
-
host,
|
|
953
|
-
api_key: apiKey
|
|
954
|
-
}
|
|
1075
|
+
"/configuration/mcpserver/add",
|
|
1076
|
+
{ servers: [{ url: host, api_key: apiKey }] }
|
|
955
1077
|
);
|
|
956
1078
|
return { message: data.message ?? "" };
|
|
957
1079
|
}
|
|
958
1080
|
async removeMCPServer(host) {
|
|
959
|
-
const data = await this.
|
|
960
|
-
|
|
1081
|
+
const data = await this._post(
|
|
1082
|
+
"/configuration/mcpserver/remove",
|
|
1083
|
+
{ host }
|
|
961
1084
|
);
|
|
962
1085
|
return { message: data.message ?? "" };
|
|
963
1086
|
}
|
|
964
1087
|
async getTaskHandlerStatus() {
|
|
965
|
-
return this._get("/
|
|
1088
|
+
return this._get("/configuration/taskhandler/status");
|
|
966
1089
|
}
|
|
967
1090
|
async getTaskHandlerStatusLocal() {
|
|
968
|
-
return this._get(
|
|
1091
|
+
return this._get(
|
|
1092
|
+
"/configuration/taskhandler/status/local"
|
|
1093
|
+
);
|
|
969
1094
|
}
|
|
970
1095
|
async setConcurrentTasksPerReplica(maxTasks) {
|
|
971
|
-
const data = await this.
|
|
972
|
-
"
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
}
|
|
1096
|
+
const data = await this._request(
|
|
1097
|
+
"POST",
|
|
1098
|
+
"/configuration/taskhandler/concurrent-per-replica",
|
|
1099
|
+
{ params: { max_tasks: maxTasks } }
|
|
976
1100
|
);
|
|
977
1101
|
return { message: data.message ?? "" };
|
|
978
1102
|
}
|
|
979
1103
|
async getSummaryWorkerStatus() {
|
|
980
|
-
return this._get(
|
|
1104
|
+
return this._get(
|
|
1105
|
+
"/configuration/summary-worker/status"
|
|
1106
|
+
);
|
|
981
1107
|
}
|
|
982
1108
|
async setCompactorModel(modelName) {
|
|
983
1109
|
const data = await this._post(
|
|
984
|
-
"/
|
|
985
|
-
{
|
|
986
|
-
model_name: modelName
|
|
987
|
-
}
|
|
1110
|
+
"/configuration/summary-worker/model",
|
|
1111
|
+
{ model_name: modelName }
|
|
988
1112
|
);
|
|
989
1113
|
return { message: data.message ?? "" };
|
|
990
1114
|
}
|
|
991
1115
|
async setTranslateModel(modelName) {
|
|
992
1116
|
const data = await this._post(
|
|
993
|
-
"/
|
|
994
|
-
{
|
|
995
|
-
model_name: modelName
|
|
996
|
-
}
|
|
1117
|
+
"/configuration/summary-worker/translate-model",
|
|
1118
|
+
{ model_name: modelName }
|
|
997
1119
|
);
|
|
998
1120
|
return { message: data.message ?? "" };
|
|
999
1121
|
}
|
|
1000
1122
|
async getTokenWorkerStatus() {
|
|
1001
|
-
return this._get("/
|
|
1123
|
+
return this._get("/configuration/token-worker/status");
|
|
1002
1124
|
}
|
|
1003
1125
|
async getSlotsStatus() {
|
|
1004
|
-
return this._get("/
|
|
1126
|
+
return this._get("/configuration/slots/status");
|
|
1127
|
+
}
|
|
1128
|
+
async getSubagentsStatus() {
|
|
1129
|
+
return this._get("/configuration/subagents/status");
|
|
1130
|
+
}
|
|
1131
|
+
async setSubagentsEnabled(enabled) {
|
|
1132
|
+
const data = await this._post(
|
|
1133
|
+
"/configuration/subagents",
|
|
1134
|
+
{ enabled }
|
|
1135
|
+
);
|
|
1136
|
+
return { message: data.message ?? "" };
|
|
1137
|
+
}
|
|
1138
|
+
async reloadServices() {
|
|
1139
|
+
return this._post("/configuration/reload");
|
|
1140
|
+
}
|
|
1141
|
+
async getReloadStatus() {
|
|
1142
|
+
return this._get("/configuration/reload/status");
|
|
1005
1143
|
}
|
|
1006
1144
|
// ------------------------------------------------------------------
|
|
1007
1145
|
// Auth / WebSocket status
|
|
@@ -1019,10 +1157,10 @@ var OrchestratorAsync = class {
|
|
|
1019
1157
|
const headers = await this._resolveHeaders();
|
|
1020
1158
|
headers.Accept = "text/event-stream";
|
|
1021
1159
|
const response = await this._fetch(
|
|
1022
|
-
this._makeUrl(
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
}
|
|
1160
|
+
this._makeUrl(
|
|
1161
|
+
`/task/stream_status?task_id=${encodeURIComponent(taskId)}`
|
|
1162
|
+
),
|
|
1163
|
+
{ headers }
|
|
1026
1164
|
);
|
|
1027
1165
|
if (!response.ok) {
|
|
1028
1166
|
throw new OrchestratorAPIError(
|
|
@@ -1089,11 +1227,14 @@ var Orchestrator = class {
|
|
|
1089
1227
|
createTask(params) {
|
|
1090
1228
|
return runSync(this._async.createTask(params));
|
|
1091
1229
|
}
|
|
1092
|
-
getTaskStatus(taskId) {
|
|
1093
|
-
return runSync(this._async.getTaskStatus(taskId));
|
|
1230
|
+
getTaskStatus(taskId, locale) {
|
|
1231
|
+
return runSync(this._async.getTaskStatus(taskId, locale));
|
|
1094
1232
|
}
|
|
1095
|
-
|
|
1096
|
-
return runSync(this._async.
|
|
1233
|
+
setTaskStatus(taskId, status) {
|
|
1234
|
+
return runSync(this._async.setTaskStatus(taskId, status));
|
|
1235
|
+
}
|
|
1236
|
+
getTaskConversation(taskId, params) {
|
|
1237
|
+
return runSync(this._async.getTaskConversation(taskId, params));
|
|
1097
1238
|
}
|
|
1098
1239
|
getArchivedMessageContent(taskId, messageId) {
|
|
1099
1240
|
return runSync(this._async.getArchivedMessageContent(taskId, messageId));
|
|
@@ -1116,17 +1257,19 @@ var Orchestrator = class {
|
|
|
1116
1257
|
// ------------------------------------------------------------------
|
|
1117
1258
|
// Attachments
|
|
1118
1259
|
// ------------------------------------------------------------------
|
|
1119
|
-
uploadAttachment(
|
|
1120
|
-
return runSync(this._async.uploadAttachment(
|
|
1260
|
+
uploadAttachment(file, filename) {
|
|
1261
|
+
return runSync(this._async.uploadAttachment(file, filename));
|
|
1121
1262
|
}
|
|
1122
|
-
downloadAttachment(
|
|
1123
|
-
return runSync(this._async.downloadAttachment(
|
|
1263
|
+
downloadAttachment(attachmentId) {
|
|
1264
|
+
return runSync(this._async.downloadAttachment(attachmentId));
|
|
1124
1265
|
}
|
|
1125
1266
|
// ------------------------------------------------------------------
|
|
1126
1267
|
// Interactive workflow
|
|
1127
1268
|
// ------------------------------------------------------------------
|
|
1128
|
-
sendInteractiveMessage(taskId,
|
|
1129
|
-
return runSync(
|
|
1269
|
+
sendInteractiveMessage(taskId, message, attachmentIds) {
|
|
1270
|
+
return runSync(
|
|
1271
|
+
this._async.sendInteractiveMessage(taskId, message, attachmentIds)
|
|
1272
|
+
);
|
|
1130
1273
|
}
|
|
1131
1274
|
markInteractiveComplete(taskId) {
|
|
1132
1275
|
return runSync(this._async.markInteractiveComplete(taskId));
|
|
@@ -1134,32 +1277,37 @@ var Orchestrator = class {
|
|
|
1134
1277
|
markInteractiveFailed(taskId) {
|
|
1135
1278
|
return runSync(this._async.markInteractiveFailed(taskId));
|
|
1136
1279
|
}
|
|
1137
|
-
approveInteractiveAction(taskId) {
|
|
1138
|
-
return runSync(this._async.approveInteractiveAction(taskId));
|
|
1280
|
+
approveInteractiveAction(taskId, approved = true) {
|
|
1281
|
+
return runSync(this._async.approveInteractiveAction(taskId, approved));
|
|
1282
|
+
}
|
|
1283
|
+
stopInteractive(taskId) {
|
|
1284
|
+
return runSync(this._async.stopInteractive(taskId));
|
|
1139
1285
|
}
|
|
1140
1286
|
// ------------------------------------------------------------------
|
|
1141
1287
|
// Proactive workflow
|
|
1142
1288
|
// ------------------------------------------------------------------
|
|
1143
|
-
sendProactiveGuide(taskId,
|
|
1144
|
-
return runSync(
|
|
1289
|
+
sendProactiveGuide(taskId, message, attachmentIds) {
|
|
1290
|
+
return runSync(
|
|
1291
|
+
this._async.sendProactiveGuide(taskId, message, attachmentIds)
|
|
1292
|
+
);
|
|
1145
1293
|
}
|
|
1146
1294
|
respondProactiveHelp(taskId, response) {
|
|
1147
1295
|
return runSync(this._async.respondProactiveHelp(taskId, response));
|
|
1148
1296
|
}
|
|
1149
|
-
approveProactiveAction(taskId) {
|
|
1150
|
-
return runSync(this._async.approveProactiveAction(taskId));
|
|
1297
|
+
approveProactiveAction(taskId, approved = true) {
|
|
1298
|
+
return runSync(this._async.approveProactiveAction(taskId, approved));
|
|
1151
1299
|
}
|
|
1152
1300
|
// ------------------------------------------------------------------
|
|
1153
1301
|
// Ticket workflow
|
|
1154
1302
|
// ------------------------------------------------------------------
|
|
1155
|
-
sendTicketGuide(taskId,
|
|
1156
|
-
return runSync(this._async.sendTicketGuide(taskId,
|
|
1303
|
+
sendTicketGuide(taskId, message, attachmentIds) {
|
|
1304
|
+
return runSync(this._async.sendTicketGuide(taskId, message, attachmentIds));
|
|
1157
1305
|
}
|
|
1158
1306
|
respondTicketHelp(taskId, response) {
|
|
1159
1307
|
return runSync(this._async.respondTicketHelp(taskId, response));
|
|
1160
1308
|
}
|
|
1161
|
-
approveTicketAction(taskId) {
|
|
1162
|
-
return runSync(this._async.approveTicketAction(taskId));
|
|
1309
|
+
approveTicketAction(taskId, approved = true) {
|
|
1310
|
+
return runSync(this._async.approveTicketAction(taskId, approved));
|
|
1163
1311
|
}
|
|
1164
1312
|
wakeTicket(taskId) {
|
|
1165
1313
|
return runSync(this._async.wakeTicket(taskId));
|
|
@@ -1167,8 +1315,10 @@ var Orchestrator = class {
|
|
|
1167
1315
|
// ------------------------------------------------------------------
|
|
1168
1316
|
// Matrix workflow
|
|
1169
1317
|
// ------------------------------------------------------------------
|
|
1170
|
-
sendMatrixMessage(taskId,
|
|
1171
|
-
return runSync(
|
|
1318
|
+
sendMatrixMessage(taskId, message, attachmentIds) {
|
|
1319
|
+
return runSync(
|
|
1320
|
+
this._async.sendMatrixMessage(taskId, message, attachmentIds)
|
|
1321
|
+
);
|
|
1172
1322
|
}
|
|
1173
1323
|
markMatrixComplete(taskId) {
|
|
1174
1324
|
return runSync(this._async.markMatrixComplete(taskId));
|
|
@@ -1176,11 +1326,13 @@ var Orchestrator = class {
|
|
|
1176
1326
|
markMatrixFailed(taskId) {
|
|
1177
1327
|
return runSync(this._async.markMatrixFailed(taskId));
|
|
1178
1328
|
}
|
|
1179
|
-
approveMatrixAction(taskId) {
|
|
1180
|
-
return runSync(this._async.approveMatrixAction(taskId));
|
|
1329
|
+
approveMatrixAction(taskId, approved = true) {
|
|
1330
|
+
return runSync(this._async.approveMatrixAction(taskId, approved));
|
|
1181
1331
|
}
|
|
1182
|
-
getMatrixConversation(taskId) {
|
|
1183
|
-
return runSync(
|
|
1332
|
+
getMatrixConversation(taskId, phase, includeSummaries) {
|
|
1333
|
+
return runSync(
|
|
1334
|
+
this._async.getMatrixConversation(taskId, phase, includeSummaries)
|
|
1335
|
+
);
|
|
1184
1336
|
}
|
|
1185
1337
|
// ------------------------------------------------------------------
|
|
1186
1338
|
// VSA workflow
|
|
@@ -1188,8 +1340,8 @@ var Orchestrator = class {
|
|
|
1188
1340
|
createVSATask(params) {
|
|
1189
1341
|
return runSync(this._async.createVSATask(params));
|
|
1190
1342
|
}
|
|
1191
|
-
sendVSAMessage(taskId,
|
|
1192
|
-
return runSync(this._async.sendVSAMessage(taskId,
|
|
1343
|
+
sendVSAMessage(taskId, message, options) {
|
|
1344
|
+
return runSync(this._async.sendVSAMessage(taskId, message, options));
|
|
1193
1345
|
}
|
|
1194
1346
|
renameVSATask(taskId, title) {
|
|
1195
1347
|
return runSync(this._async.renameVSATask(taskId, title));
|
|
@@ -1209,23 +1361,23 @@ var Orchestrator = class {
|
|
|
1209
1361
|
deleteVSA(taskId) {
|
|
1210
1362
|
return runSync(this._async.deleteVSA(taskId));
|
|
1211
1363
|
}
|
|
1212
|
-
listVSATasks(params) {
|
|
1213
|
-
return runSync(this._async.listVSATasks(params));
|
|
1364
|
+
listVSATasks(userId, params) {
|
|
1365
|
+
return runSync(this._async.listVSATasks(userId, params));
|
|
1214
1366
|
}
|
|
1215
|
-
searchVSATasks(query) {
|
|
1216
|
-
return runSync(this._async.searchVSATasks(query));
|
|
1367
|
+
searchVSATasks(userId, query, limit) {
|
|
1368
|
+
return runSync(this._async.searchVSATasks(userId, query, limit));
|
|
1217
1369
|
}
|
|
1218
1370
|
deleteVSATasksBulk(taskIds) {
|
|
1219
1371
|
return runSync(this._async.deleteVSATasksBulk(taskIds));
|
|
1220
1372
|
}
|
|
1221
1373
|
// ------------------------------------------------------------------
|
|
1222
|
-
// MIO workflow
|
|
1374
|
+
// MIO (self_managed) workflow
|
|
1223
1375
|
// ------------------------------------------------------------------
|
|
1224
|
-
sendMioMessage(taskId,
|
|
1225
|
-
return runSync(this._async.sendMioMessage(taskId,
|
|
1376
|
+
sendMioMessage(taskId, message, attachmentIds) {
|
|
1377
|
+
return runSync(this._async.sendMioMessage(taskId, message, attachmentIds));
|
|
1226
1378
|
}
|
|
1227
|
-
approveMioAction(taskId) {
|
|
1228
|
-
return runSync(this._async.approveMioAction(taskId));
|
|
1379
|
+
approveMioAction(taskId, approved = true, feedback) {
|
|
1380
|
+
return runSync(this._async.approveMioAction(taskId, approved, feedback));
|
|
1229
1381
|
}
|
|
1230
1382
|
wakeMio(taskId) {
|
|
1231
1383
|
return runSync(this._async.wakeMio(taskId));
|
|
@@ -1245,12 +1397,24 @@ var Orchestrator = class {
|
|
|
1245
1397
|
getMioContext(taskId) {
|
|
1246
1398
|
return runSync(this._async.getMioContext(taskId));
|
|
1247
1399
|
}
|
|
1400
|
+
getMioMemories(taskId, includeCommon) {
|
|
1401
|
+
return runSync(this._async.getMioMemories(taskId, includeCommon));
|
|
1402
|
+
}
|
|
1248
1403
|
// ------------------------------------------------------------------
|
|
1249
1404
|
// Tools
|
|
1250
1405
|
// ------------------------------------------------------------------
|
|
1251
1406
|
listTools() {
|
|
1252
1407
|
return runSync(this._async.listTools());
|
|
1253
1408
|
}
|
|
1409
|
+
getToolCatalog() {
|
|
1410
|
+
return runSync(this._async.getToolCatalog());
|
|
1411
|
+
}
|
|
1412
|
+
refreshMCPTools() {
|
|
1413
|
+
return runSync(this._async.refreshMCPTools());
|
|
1414
|
+
}
|
|
1415
|
+
validateToolCatalog() {
|
|
1416
|
+
return runSync(this._async.validateToolCatalog());
|
|
1417
|
+
}
|
|
1254
1418
|
// ------------------------------------------------------------------
|
|
1255
1419
|
// Debug / Admin
|
|
1256
1420
|
// ------------------------------------------------------------------
|
|
@@ -1260,8 +1424,10 @@ var Orchestrator = class {
|
|
|
1260
1424
|
updateTaskModels(taskId, models) {
|
|
1261
1425
|
return runSync(this._async.updateTaskModels(taskId, models));
|
|
1262
1426
|
}
|
|
1263
|
-
updateTaskIteration(taskId, iteration) {
|
|
1264
|
-
return runSync(
|
|
1427
|
+
updateTaskIteration(taskId, iteration, maxIterations) {
|
|
1428
|
+
return runSync(
|
|
1429
|
+
this._async.updateTaskIteration(taskId, iteration, maxIterations)
|
|
1430
|
+
);
|
|
1265
1431
|
}
|
|
1266
1432
|
updateTaskWorkflowData(taskId, workflowData) {
|
|
1267
1433
|
return runSync(this._async.updateTaskWorkflowData(taskId, workflowData));
|
|
@@ -1278,10 +1444,8 @@ var Orchestrator = class {
|
|
|
1278
1444
|
resetMatrixToPhase(taskId, phase) {
|
|
1279
1445
|
return runSync(this._async.resetMatrixToPhase(taskId, phase));
|
|
1280
1446
|
}
|
|
1281
|
-
getMessageTranslations(taskId, messageId
|
|
1282
|
-
return runSync(
|
|
1283
|
-
this._async.getMessageTranslations(taskId, messageId, locale)
|
|
1284
|
-
);
|
|
1447
|
+
getMessageTranslations(taskId, messageId) {
|
|
1448
|
+
return runSync(this._async.getMessageTranslations(taskId, messageId));
|
|
1285
1449
|
}
|
|
1286
1450
|
// ------------------------------------------------------------------
|
|
1287
1451
|
// Error events
|
|
@@ -1379,6 +1543,18 @@ var Orchestrator = class {
|
|
|
1379
1543
|
getSlotsStatus() {
|
|
1380
1544
|
return runSync(this._async.getSlotsStatus());
|
|
1381
1545
|
}
|
|
1546
|
+
getSubagentsStatus() {
|
|
1547
|
+
return runSync(this._async.getSubagentsStatus());
|
|
1548
|
+
}
|
|
1549
|
+
setSubagentsEnabled(enabled) {
|
|
1550
|
+
return runSync(this._async.setSubagentsEnabled(enabled));
|
|
1551
|
+
}
|
|
1552
|
+
reloadServices() {
|
|
1553
|
+
return runSync(this._async.reloadServices());
|
|
1554
|
+
}
|
|
1555
|
+
getReloadStatus() {
|
|
1556
|
+
return runSync(this._async.getReloadStatus());
|
|
1557
|
+
}
|
|
1382
1558
|
// ------------------------------------------------------------------
|
|
1383
1559
|
// Auth / WebSocket status
|
|
1384
1560
|
// ------------------------------------------------------------------
|
|
@@ -1522,9 +1698,15 @@ var RealtimeClient = class {
|
|
|
1522
1698
|
this._socket = null;
|
|
1523
1699
|
this._handlers = /* @__PURE__ */ new Map();
|
|
1524
1700
|
this._connected = false;
|
|
1701
|
+
// Multi-subscriber room-diffing state (mirrors WebSocketProvider)
|
|
1702
|
+
this._subscriptions = /* @__PURE__ */ new Map();
|
|
1703
|
+
this._currentRooms = /* @__PURE__ */ new Set();
|
|
1704
|
+
this._subIdCounter = 0;
|
|
1525
1705
|
this._baseUrl = baseUrl.replace(/\/+$/, "");
|
|
1526
1706
|
this._socketOptions = opts.socketOptions ?? {};
|
|
1527
1707
|
this._getToken = opts.getToken;
|
|
1708
|
+
this._clientId = opts.clientId ?? "orchestrator-client";
|
|
1709
|
+
this._locale = opts.locale;
|
|
1528
1710
|
if (opts.autoConnect) {
|
|
1529
1711
|
this.connect();
|
|
1530
1712
|
}
|
|
@@ -1537,19 +1719,28 @@ var RealtimeClient = class {
|
|
|
1537
1719
|
if (this._getToken) {
|
|
1538
1720
|
auth.token = typeof this._getToken === "function" ? await this._getToken() : this._getToken;
|
|
1539
1721
|
}
|
|
1722
|
+
const query = { client_id: this._clientId };
|
|
1723
|
+
if (this._locale) {
|
|
1724
|
+
query.locale = this._locale;
|
|
1725
|
+
}
|
|
1540
1726
|
const { io } = await import("socket.io-client");
|
|
1541
1727
|
this._socket = io(this._baseUrl, {
|
|
1542
1728
|
path: "/socket.io",
|
|
1543
1729
|
auth,
|
|
1730
|
+
query,
|
|
1544
1731
|
transports: ["websocket", "polling"],
|
|
1545
1732
|
...this._socketOptions
|
|
1546
1733
|
});
|
|
1547
1734
|
this._socket.on("connect", () => {
|
|
1548
1735
|
this._connected = true;
|
|
1736
|
+
this._currentRooms = /* @__PURE__ */ new Set();
|
|
1737
|
+
this._syncRooms();
|
|
1549
1738
|
});
|
|
1550
1739
|
this._socket.on("disconnect", () => {
|
|
1551
1740
|
this._connected = false;
|
|
1741
|
+
this._currentRooms = /* @__PURE__ */ new Set();
|
|
1552
1742
|
});
|
|
1743
|
+
this._socket.on("message", (payload) => this._dispatch(payload));
|
|
1553
1744
|
return new Promise((resolve, reject) => {
|
|
1554
1745
|
if (!this._socket) {
|
|
1555
1746
|
reject(new Error("RealtimeClient not connected"));
|
|
@@ -1569,53 +1760,187 @@ var RealtimeClient = class {
|
|
|
1569
1760
|
}
|
|
1570
1761
|
this._connected = false;
|
|
1571
1762
|
}
|
|
1763
|
+
/**
|
|
1764
|
+
* Dispatch a message envelope to registered handlers and subscribers.
|
|
1765
|
+
* The server sends: socket.emit("message", {type: "message", event: {..., event_type: "...", ...}})
|
|
1766
|
+
*/
|
|
1767
|
+
_dispatch(payload) {
|
|
1768
|
+
const envelope = payload;
|
|
1769
|
+
const event = envelope.event ?? envelope;
|
|
1770
|
+
const eventType = event.event_type;
|
|
1771
|
+
if (!eventType) return;
|
|
1772
|
+
const handlers = this._handlers.get(eventType);
|
|
1773
|
+
if (handlers) {
|
|
1774
|
+
for (const h of handlers) {
|
|
1775
|
+
h(event);
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
for (const sub of this._subscriptions.values()) {
|
|
1779
|
+
sub.handler(event);
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1572
1782
|
/**
|
|
1573
1783
|
* Subscribe to realtime events for a specific task.
|
|
1784
|
+
* Emits a `join` event with `{rooms: ["task:{taskId}"]}`.
|
|
1574
1785
|
*/
|
|
1575
|
-
|
|
1786
|
+
subscribeTask(taskId) {
|
|
1576
1787
|
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1577
|
-
|
|
1578
|
-
this._socket?.emit(
|
|
1579
|
-
"subscribe",
|
|
1580
|
-
{ task_id: taskId },
|
|
1581
|
-
(response) => {
|
|
1582
|
-
if (response.ok) resolve();
|
|
1583
|
-
else reject(new Error(response.error ?? "Subscription failed"));
|
|
1584
|
-
}
|
|
1585
|
-
);
|
|
1586
|
-
});
|
|
1788
|
+
this._socket.emit("join", { rooms: [`task:${taskId}`] });
|
|
1587
1789
|
}
|
|
1588
1790
|
/**
|
|
1589
1791
|
* Unsubscribe from realtime events for a specific task.
|
|
1792
|
+
* Emits a `leave` event with `{rooms: ["task:{taskId}"]}`.
|
|
1590
1793
|
*/
|
|
1591
|
-
|
|
1794
|
+
unsubscribeTask(taskId) {
|
|
1592
1795
|
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
});
|
|
1796
|
+
this._socket.emit("leave", { rooms: [`task:${taskId}`] });
|
|
1797
|
+
}
|
|
1798
|
+
/**
|
|
1799
|
+
* Subscribe to event-type-scoped rooms.
|
|
1800
|
+
* e.g. subscribeEvents("task_created", "task_deleted")
|
|
1801
|
+
*/
|
|
1802
|
+
subscribeEvents(...eventTypes) {
|
|
1803
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1804
|
+
const rooms = eventTypes.map((t) => `event:${t}`);
|
|
1805
|
+
this._socket.emit("join", { rooms });
|
|
1806
|
+
}
|
|
1807
|
+
/**
|
|
1808
|
+
* Unsubscribe from event-type-scoped rooms.
|
|
1809
|
+
*/
|
|
1810
|
+
unsubscribeEvents(...eventTypes) {
|
|
1811
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1812
|
+
const rooms = eventTypes.map((t) => `event:${t}`);
|
|
1813
|
+
this._socket.emit("leave", { rooms });
|
|
1814
|
+
}
|
|
1815
|
+
/**
|
|
1816
|
+
* Subscribe to the `all` broadcast room (receives all events).
|
|
1817
|
+
*/
|
|
1818
|
+
subscribeAll() {
|
|
1819
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1820
|
+
this._socket.emit("join", { rooms: ["all"] });
|
|
1821
|
+
}
|
|
1822
|
+
/**
|
|
1823
|
+
* Subscribe to a locale-specific room.
|
|
1824
|
+
*/
|
|
1825
|
+
subscribeLocale(locale) {
|
|
1826
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1827
|
+
this._socket.emit("join", { rooms: [`locale:${locale}`] });
|
|
1828
|
+
}
|
|
1829
|
+
/**
|
|
1830
|
+
* Unsubscribe from a locale-specific room.
|
|
1831
|
+
*/
|
|
1832
|
+
unsubscribeLocale(locale) {
|
|
1833
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1834
|
+
this._socket.emit("leave", { rooms: [`locale:${locale}`] });
|
|
1835
|
+
}
|
|
1836
|
+
/**
|
|
1837
|
+
* Join arbitrary rooms by name.
|
|
1838
|
+
*/
|
|
1839
|
+
joinRooms(rooms) {
|
|
1840
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1841
|
+
this._socket.emit("join", { rooms });
|
|
1842
|
+
}
|
|
1843
|
+
/**
|
|
1844
|
+
* Leave arbitrary rooms by name.
|
|
1845
|
+
*/
|
|
1846
|
+
leaveRooms(rooms) {
|
|
1847
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1848
|
+
this._socket.emit("leave", { rooms });
|
|
1849
|
+
}
|
|
1850
|
+
// ------------------------------------------------------------------
|
|
1851
|
+
// Multi-subscriber API (mirrors WebSocketProvider room-diffing)
|
|
1852
|
+
// ------------------------------------------------------------------
|
|
1853
|
+
/**
|
|
1854
|
+
* Register a subscriber that receives all events from the given rooms.
|
|
1855
|
+
*
|
|
1856
|
+
* Room membership is managed automatically: the client joins the union
|
|
1857
|
+
* of all active subscribers' rooms and leaves rooms that are no longer
|
|
1858
|
+
* needed when the last subscriber referencing them is removed.
|
|
1859
|
+
*
|
|
1860
|
+
* The `handler` receives the unwrapped event dict (same object that
|
|
1861
|
+
* `on()` handlers receive).
|
|
1862
|
+
*
|
|
1863
|
+
* Returns an opaque subscription id that must be passed to
|
|
1864
|
+
* `unsubscribe()` to remove the subscription.
|
|
1865
|
+
*
|
|
1866
|
+
* Example — mirror the webui's per-component subscription pattern:
|
|
1867
|
+
*
|
|
1868
|
+
* const id = rt.subscribe((event) => {
|
|
1869
|
+
* if (event.event_type === "task_status_changed") { ... }
|
|
1870
|
+
* }, [`task:${taskId}`]);
|
|
1871
|
+
*
|
|
1872
|
+
* // later, on cleanup:
|
|
1873
|
+
* rt.unsubscribe(id);
|
|
1874
|
+
*/
|
|
1875
|
+
subscribe(handler, rooms) {
|
|
1876
|
+
const id = `sub_${++this._subIdCounter}`;
|
|
1877
|
+
this._subscriptions.set(id, { handler, rooms });
|
|
1878
|
+
this._syncRooms();
|
|
1879
|
+
return id;
|
|
1880
|
+
}
|
|
1881
|
+
/**
|
|
1882
|
+
* Remove a subscription registered via `subscribe()`.
|
|
1883
|
+
*
|
|
1884
|
+
* Rooms that are no longer referenced by any remaining subscriber are
|
|
1885
|
+
* left automatically.
|
|
1886
|
+
*/
|
|
1887
|
+
unsubscribe(id) {
|
|
1888
|
+
this._subscriptions.delete(id);
|
|
1889
|
+
this._syncRooms();
|
|
1890
|
+
}
|
|
1891
|
+
/**
|
|
1892
|
+
* Diff the union of all subscribers' rooms against the currently joined
|
|
1893
|
+
* rooms and emit `join`/`leave` for the delta. No-ops when not connected.
|
|
1894
|
+
*/
|
|
1895
|
+
_syncRooms() {
|
|
1896
|
+
const socket = this._socket;
|
|
1897
|
+
if (!socket?.connected) return;
|
|
1898
|
+
const needed = /* @__PURE__ */ new Set();
|
|
1899
|
+
for (const sub of this._subscriptions.values()) {
|
|
1900
|
+
for (const r of sub.rooms) needed.add(r);
|
|
1901
|
+
}
|
|
1902
|
+
const toJoin = [...needed].filter((r) => !this._currentRooms.has(r));
|
|
1903
|
+
const toLeave = [...this._currentRooms].filter((r) => !needed.has(r));
|
|
1904
|
+
if (toJoin.length) socket.emit("join", { rooms: toJoin });
|
|
1905
|
+
if (toLeave.length) socket.emit("leave", { rooms: toLeave });
|
|
1906
|
+
this._currentRooms = needed;
|
|
1907
|
+
}
|
|
1908
|
+
/**
|
|
1909
|
+
* Send a ping to the server.
|
|
1910
|
+
*/
|
|
1911
|
+
ping() {
|
|
1912
|
+
if (!this._socket) throw new Error("RealtimeClient not connected");
|
|
1913
|
+
this._socket.emit("ping");
|
|
1603
1914
|
}
|
|
1604
1915
|
/**
|
|
1605
1916
|
* Register a handler for a specific event type.
|
|
1917
|
+
*
|
|
1918
|
+
* Domain events (task_created, task_status_changed, etc.) are dispatched
|
|
1919
|
+
* via the message envelope. Raw socket events (connect, disconnect,
|
|
1920
|
+
* connection_established, rooms_updated, pong) are wired directly.
|
|
1606
1921
|
*/
|
|
1607
1922
|
on(event, handler) {
|
|
1608
1923
|
if (!this._handlers.has(event)) {
|
|
1609
1924
|
this._handlers.set(event, /* @__PURE__ */ new Set());
|
|
1610
1925
|
if (this._socket) {
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1926
|
+
const rawSocketEvents = /* @__PURE__ */ new Set([
|
|
1927
|
+
"connect",
|
|
1928
|
+
"disconnect",
|
|
1929
|
+
"connect_error",
|
|
1930
|
+
"connection_established",
|
|
1931
|
+
"rooms_updated",
|
|
1932
|
+
"pong"
|
|
1933
|
+
]);
|
|
1934
|
+
if (rawSocketEvents.has(event)) {
|
|
1935
|
+
this._socket.on(event, (...args) => {
|
|
1936
|
+
const handlers2 = this._handlers.get(event);
|
|
1937
|
+
if (handlers2) {
|
|
1938
|
+
for (const h of handlers2) {
|
|
1939
|
+
h(...args);
|
|
1940
|
+
}
|
|
1616
1941
|
}
|
|
1617
|
-
}
|
|
1618
|
-
}
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1619
1944
|
}
|
|
1620
1945
|
}
|
|
1621
1946
|
const handlers = this._handlers.get(event);
|