@love-moon/conductor-sdk 0.2.39 → 0.2.41
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 +12 -0
- package/dist/client.js +64 -1
- package/package.json +2 -2
package/dist/client.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export interface ConductorClientConnectOptions {
|
|
|
27
27
|
onPong?: (event: WebSocketPongEvent) => void;
|
|
28
28
|
onStopTask?: (event: StopTaskEvent) => Promise<void> | void;
|
|
29
29
|
onInterruptTurn?: (event: InterruptTurnEvent) => Promise<boolean | void> | boolean | void;
|
|
30
|
+
onRefreshSession?: (event: RefreshSessionEvent) => Promise<boolean | void> | boolean | void;
|
|
30
31
|
}
|
|
31
32
|
interface ConductorClientInit {
|
|
32
33
|
config: ConductorConfig;
|
|
@@ -43,6 +44,7 @@ interface ConductorClientInit {
|
|
|
43
44
|
agentHost: string;
|
|
44
45
|
onStopTask?: (event: StopTaskEvent) => Promise<void> | void;
|
|
45
46
|
onInterruptTurn?: (event: InterruptTurnEvent) => Promise<boolean | void> | boolean | void;
|
|
47
|
+
onRefreshSession?: (event: RefreshSessionEvent) => Promise<boolean | void> | boolean | void;
|
|
46
48
|
}
|
|
47
49
|
export interface StopTaskEvent {
|
|
48
50
|
taskId: string;
|
|
@@ -55,6 +57,13 @@ export interface InterruptTurnEvent {
|
|
|
55
57
|
reason?: string;
|
|
56
58
|
targetReplyTo: string;
|
|
57
59
|
}
|
|
60
|
+
export interface RefreshSessionEvent {
|
|
61
|
+
taskId: string;
|
|
62
|
+
requestId?: string;
|
|
63
|
+
reason?: string;
|
|
64
|
+
sessionId: string;
|
|
65
|
+
sessionFilePath?: string;
|
|
66
|
+
}
|
|
58
67
|
export interface FlushPendingUpstreamEventsOptions {
|
|
59
68
|
timeoutMs?: number;
|
|
60
69
|
retryIntervalMs?: number;
|
|
@@ -73,6 +82,7 @@ export declare class ConductorClient {
|
|
|
73
82
|
private readonly agentHost;
|
|
74
83
|
private readonly onStopTask?;
|
|
75
84
|
private readonly onInterruptTurn?;
|
|
85
|
+
private readonly onRefreshSession?;
|
|
76
86
|
private deliveryScopeId;
|
|
77
87
|
private closed;
|
|
78
88
|
private durableOutboxFlushPromise;
|
|
@@ -126,7 +136,9 @@ export declare class ConductorClient {
|
|
|
126
136
|
private handleStopTaskCommand;
|
|
127
137
|
private invokeStopTaskHandler;
|
|
128
138
|
private handleInterruptTurnCommand;
|
|
139
|
+
private handleRefreshSessionCommand;
|
|
129
140
|
private invokeInterruptTurnHandler;
|
|
141
|
+
private invokeRefreshSessionHandler;
|
|
130
142
|
private persistAndCommitUpstreamEvent;
|
|
131
143
|
private requestDurableOutboxFlush;
|
|
132
144
|
private hasEarlierPendingSdkMessage;
|
package/dist/client.js
CHANGED
|
@@ -24,6 +24,7 @@ export class ConductorClient {
|
|
|
24
24
|
agentHost;
|
|
25
25
|
onStopTask;
|
|
26
26
|
onInterruptTurn;
|
|
27
|
+
onRefreshSession;
|
|
27
28
|
deliveryScopeId;
|
|
28
29
|
closed = false;
|
|
29
30
|
durableOutboxFlushPromise = null;
|
|
@@ -43,6 +44,7 @@ export class ConductorClient {
|
|
|
43
44
|
this.agentHost = init.agentHost;
|
|
44
45
|
this.onStopTask = init.onStopTask;
|
|
45
46
|
this.onInterruptTurn = init.onInterruptTurn;
|
|
47
|
+
this.onRefreshSession = init.onRefreshSession;
|
|
46
48
|
this.deliveryScopeId = init.deliveryScopeId;
|
|
47
49
|
this.wsClient.registerHandler(this.handleBackendEvent);
|
|
48
50
|
}
|
|
@@ -86,6 +88,7 @@ export class ConductorClient {
|
|
|
86
88
|
agentHost,
|
|
87
89
|
onStopTask: options.onStopTask,
|
|
88
90
|
onInterruptTurn: options.onInterruptTurn,
|
|
91
|
+
onRefreshSession: options.onRefreshSession,
|
|
89
92
|
});
|
|
90
93
|
await client.wsClient.connect();
|
|
91
94
|
if (client.shouldAutoFlushDurableOutbox()) {
|
|
@@ -536,6 +539,17 @@ export class ConductorClient {
|
|
|
536
539
|
};
|
|
537
540
|
}
|
|
538
541
|
handleBackendEvent = async (payload) => {
|
|
542
|
+
if (typeof payload?.type === 'string' && payload.type === 'refresh_session') {
|
|
543
|
+
void this.handleRefreshSessionCommand(payload).catch((error) => {
|
|
544
|
+
const data = payload?.payload && typeof payload.payload === 'object'
|
|
545
|
+
? payload.payload
|
|
546
|
+
: null;
|
|
547
|
+
const taskId = typeof data?.task_id === 'string' ? data.task_id.trim() : '';
|
|
548
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
549
|
+
console.warn(`[sdk] refresh_session dispatch failed${taskId ? ` for task ${taskId}` : ''}: ${message}`);
|
|
550
|
+
});
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
539
553
|
if (typeof payload?.type === 'string' && payload.type === 'interrupt_turn') {
|
|
540
554
|
await this.handleInterruptTurnCommand(payload);
|
|
541
555
|
return;
|
|
@@ -641,6 +655,10 @@ export class ConductorClient {
|
|
|
641
655
|
const accepted = await this.invokeInterruptTurnHandler(payload);
|
|
642
656
|
await this.maybeAckInboundCommand(payload, { accepted });
|
|
643
657
|
}
|
|
658
|
+
async handleRefreshSessionCommand(payload) {
|
|
659
|
+
const accepted = await this.invokeRefreshSessionHandler(payload);
|
|
660
|
+
await this.maybeAckInboundCommand(payload, { accepted });
|
|
661
|
+
}
|
|
644
662
|
async invokeInterruptTurnHandler(payload) {
|
|
645
663
|
const data = payload?.payload && typeof payload.payload === 'object'
|
|
646
664
|
? payload.payload
|
|
@@ -677,6 +695,48 @@ export class ConductorClient {
|
|
|
677
695
|
return false;
|
|
678
696
|
}
|
|
679
697
|
}
|
|
698
|
+
async invokeRefreshSessionHandler(payload) {
|
|
699
|
+
const data = payload?.payload && typeof payload.payload === 'object'
|
|
700
|
+
? payload.payload
|
|
701
|
+
: null;
|
|
702
|
+
if (!data) {
|
|
703
|
+
return false;
|
|
704
|
+
}
|
|
705
|
+
const taskId = typeof data.task_id === 'string' ? data.task_id.trim() : '';
|
|
706
|
+
const requestId = typeof data.request_id === 'string' ? data.request_id.trim() : '';
|
|
707
|
+
const reason = typeof data.reason === 'string' ? data.reason.trim() : '';
|
|
708
|
+
const sessionId = typeof data.session_id === 'string'
|
|
709
|
+
? data.session_id.trim()
|
|
710
|
+
: typeof data.sessionId === 'string'
|
|
711
|
+
? data.sessionId.trim()
|
|
712
|
+
: '';
|
|
713
|
+
const sessionFilePath = typeof data.session_file_path === 'string'
|
|
714
|
+
? data.session_file_path.trim()
|
|
715
|
+
: typeof data.sessionFilePath === 'string'
|
|
716
|
+
? data.sessionFilePath.trim()
|
|
717
|
+
: '';
|
|
718
|
+
if (!taskId || !sessionId) {
|
|
719
|
+
return false;
|
|
720
|
+
}
|
|
721
|
+
if (!this.onRefreshSession) {
|
|
722
|
+
return false;
|
|
723
|
+
}
|
|
724
|
+
try {
|
|
725
|
+
const accepted = await this.onRefreshSession({
|
|
726
|
+
taskId,
|
|
727
|
+
requestId: requestId || undefined,
|
|
728
|
+
reason: reason || undefined,
|
|
729
|
+
sessionId,
|
|
730
|
+
sessionFilePath: sessionFilePath || undefined,
|
|
731
|
+
});
|
|
732
|
+
return accepted !== false;
|
|
733
|
+
}
|
|
734
|
+
catch (error) {
|
|
735
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
736
|
+
console.warn(`[sdk] refresh_session callback failed for task ${taskId}: ${message}`);
|
|
737
|
+
return false;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
680
740
|
async persistAndCommitUpstreamEvent(entry) {
|
|
681
741
|
const stored = this.upstreamOutbox.upsert(entry);
|
|
682
742
|
if (stored.eventType === 'sdk_message' && this.hasEarlierPendingSdkMessage(stored.stableId)) {
|
|
@@ -843,7 +903,10 @@ export class ConductorClient {
|
|
|
843
903
|
}
|
|
844
904
|
async maybeAckInboundCommand(payload, options = {}) {
|
|
845
905
|
const eventType = typeof payload?.type === 'string' ? payload.type : '';
|
|
846
|
-
if (eventType !== 'task_user_message' &&
|
|
906
|
+
if (eventType !== 'task_user_message' &&
|
|
907
|
+
eventType !== 'task_action' &&
|
|
908
|
+
eventType !== 'interrupt_turn' &&
|
|
909
|
+
eventType !== 'refresh_session') {
|
|
847
910
|
return;
|
|
848
911
|
}
|
|
849
912
|
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.41",
|
|
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": "89ac834"
|
|
31
31
|
}
|