@love-moon/conductor-sdk 0.2.37 → 0.2.39
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/client.d.ts +11 -0
- package/dist/client.js +48 -1
- package/package.json +2 -2
package/dist/client.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export interface ConductorClientConnectOptions {
|
|
|
26
26
|
onDisconnected?: (event: WebSocketDisconnectEvent) => void;
|
|
27
27
|
onPong?: (event: WebSocketPongEvent) => void;
|
|
28
28
|
onStopTask?: (event: StopTaskEvent) => Promise<void> | void;
|
|
29
|
+
onInterruptTurn?: (event: InterruptTurnEvent) => Promise<boolean | void> | boolean | void;
|
|
29
30
|
}
|
|
30
31
|
interface ConductorClientInit {
|
|
31
32
|
config: ConductorConfig;
|
|
@@ -41,12 +42,19 @@ interface ConductorClientInit {
|
|
|
41
42
|
downstreamCursorStore: DownstreamCursorStore;
|
|
42
43
|
agentHost: string;
|
|
43
44
|
onStopTask?: (event: StopTaskEvent) => Promise<void> | void;
|
|
45
|
+
onInterruptTurn?: (event: InterruptTurnEvent) => Promise<boolean | void> | boolean | void;
|
|
44
46
|
}
|
|
45
47
|
export interface StopTaskEvent {
|
|
46
48
|
taskId: string;
|
|
47
49
|
requestId?: string;
|
|
48
50
|
reason?: string;
|
|
49
51
|
}
|
|
52
|
+
export interface InterruptTurnEvent {
|
|
53
|
+
taskId: string;
|
|
54
|
+
requestId?: string;
|
|
55
|
+
reason?: string;
|
|
56
|
+
targetReplyTo: string;
|
|
57
|
+
}
|
|
50
58
|
export interface FlushPendingUpstreamEventsOptions {
|
|
51
59
|
timeoutMs?: number;
|
|
52
60
|
retryIntervalMs?: number;
|
|
@@ -64,6 +72,7 @@ export declare class ConductorClient {
|
|
|
64
72
|
private downstreamCursorStore;
|
|
65
73
|
private readonly agentHost;
|
|
66
74
|
private readonly onStopTask?;
|
|
75
|
+
private readonly onInterruptTurn?;
|
|
67
76
|
private deliveryScopeId;
|
|
68
77
|
private closed;
|
|
69
78
|
private durableOutboxFlushPromise;
|
|
@@ -116,6 +125,8 @@ export declare class ConductorClient {
|
|
|
116
125
|
private extractDownstreamCommandContext;
|
|
117
126
|
private handleStopTaskCommand;
|
|
118
127
|
private invokeStopTaskHandler;
|
|
128
|
+
private handleInterruptTurnCommand;
|
|
129
|
+
private invokeInterruptTurnHandler;
|
|
119
130
|
private persistAndCommitUpstreamEvent;
|
|
120
131
|
private requestDurableOutboxFlush;
|
|
121
132
|
private hasEarlierPendingSdkMessage;
|
package/dist/client.js
CHANGED
|
@@ -23,6 +23,7 @@ export class ConductorClient {
|
|
|
23
23
|
downstreamCursorStore;
|
|
24
24
|
agentHost;
|
|
25
25
|
onStopTask;
|
|
26
|
+
onInterruptTurn;
|
|
26
27
|
deliveryScopeId;
|
|
27
28
|
closed = false;
|
|
28
29
|
durableOutboxFlushPromise = null;
|
|
@@ -41,6 +42,7 @@ export class ConductorClient {
|
|
|
41
42
|
this.downstreamCursorStore = init.downstreamCursorStore;
|
|
42
43
|
this.agentHost = init.agentHost;
|
|
43
44
|
this.onStopTask = init.onStopTask;
|
|
45
|
+
this.onInterruptTurn = init.onInterruptTurn;
|
|
44
46
|
this.deliveryScopeId = init.deliveryScopeId;
|
|
45
47
|
this.wsClient.registerHandler(this.handleBackendEvent);
|
|
46
48
|
}
|
|
@@ -83,6 +85,7 @@ export class ConductorClient {
|
|
|
83
85
|
downstreamCursorStore,
|
|
84
86
|
agentHost,
|
|
85
87
|
onStopTask: options.onStopTask,
|
|
88
|
+
onInterruptTurn: options.onInterruptTurn,
|
|
86
89
|
});
|
|
87
90
|
await client.wsClient.connect();
|
|
88
91
|
if (client.shouldAutoFlushDurableOutbox()) {
|
|
@@ -533,6 +536,10 @@ export class ConductorClient {
|
|
|
533
536
|
};
|
|
534
537
|
}
|
|
535
538
|
handleBackendEvent = async (payload) => {
|
|
539
|
+
if (typeof payload?.type === 'string' && payload.type === 'interrupt_turn') {
|
|
540
|
+
await this.handleInterruptTurnCommand(payload);
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
536
543
|
const command = this.extractDownstreamCommandContext(payload);
|
|
537
544
|
if (command?.eventType === 'stop_task') {
|
|
538
545
|
await this.handleStopTaskCommand(payload, command);
|
|
@@ -630,6 +637,46 @@ export class ConductorClient {
|
|
|
630
637
|
return false;
|
|
631
638
|
}
|
|
632
639
|
}
|
|
640
|
+
async handleInterruptTurnCommand(payload) {
|
|
641
|
+
const accepted = await this.invokeInterruptTurnHandler(payload);
|
|
642
|
+
await this.maybeAckInboundCommand(payload, { accepted });
|
|
643
|
+
}
|
|
644
|
+
async invokeInterruptTurnHandler(payload) {
|
|
645
|
+
const data = payload?.payload && typeof payload.payload === 'object'
|
|
646
|
+
? payload.payload
|
|
647
|
+
: null;
|
|
648
|
+
if (!data) {
|
|
649
|
+
return false;
|
|
650
|
+
}
|
|
651
|
+
const taskId = typeof data.task_id === 'string' ? data.task_id.trim() : '';
|
|
652
|
+
const requestId = typeof data.request_id === 'string' ? data.request_id.trim() : '';
|
|
653
|
+
const reason = typeof data.reason === 'string' ? data.reason.trim() : '';
|
|
654
|
+
const targetReplyTo = typeof data.target_reply_to === 'string'
|
|
655
|
+
? data.target_reply_to.trim()
|
|
656
|
+
: typeof data.targetReplyTo === 'string'
|
|
657
|
+
? data.targetReplyTo.trim()
|
|
658
|
+
: '';
|
|
659
|
+
if (!taskId || !targetReplyTo) {
|
|
660
|
+
return false;
|
|
661
|
+
}
|
|
662
|
+
if (!this.onInterruptTurn) {
|
|
663
|
+
return false;
|
|
664
|
+
}
|
|
665
|
+
try {
|
|
666
|
+
const accepted = await this.onInterruptTurn({
|
|
667
|
+
taskId,
|
|
668
|
+
requestId: requestId || undefined,
|
|
669
|
+
reason: reason || undefined,
|
|
670
|
+
targetReplyTo,
|
|
671
|
+
});
|
|
672
|
+
return accepted !== false;
|
|
673
|
+
}
|
|
674
|
+
catch (error) {
|
|
675
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
676
|
+
console.warn(`[sdk] interrupt_turn callback failed for task ${taskId}: ${message}`);
|
|
677
|
+
return false;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
633
680
|
async persistAndCommitUpstreamEvent(entry) {
|
|
634
681
|
const stored = this.upstreamOutbox.upsert(entry);
|
|
635
682
|
if (stored.eventType === 'sdk_message' && this.hasEarlierPendingSdkMessage(stored.stableId)) {
|
|
@@ -796,7 +843,7 @@ export class ConductorClient {
|
|
|
796
843
|
}
|
|
797
844
|
async maybeAckInboundCommand(payload, options = {}) {
|
|
798
845
|
const eventType = typeof payload?.type === 'string' ? payload.type : '';
|
|
799
|
-
if (eventType !== 'task_user_message' && eventType !== 'task_action') {
|
|
846
|
+
if (eventType !== 'task_user_message' && eventType !== 'task_action' && eventType !== 'interrupt_turn') {
|
|
800
847
|
return;
|
|
801
848
|
}
|
|
802
849
|
const data = payload?.payload && typeof payload.payload === 'object'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@love-moon/conductor-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.39",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"typescript": "^5.6.3",
|
|
28
28
|
"vitest": "^2.1.4"
|
|
29
29
|
},
|
|
30
|
-
"gitCommitId": "
|
|
30
|
+
"gitCommitId": "30204c8"
|
|
31
31
|
}
|