@love-moon/conductor-sdk 0.2.7 → 0.2.9
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 +16 -0
- package/dist/client.js +60 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -17,6 +17,10 @@ export interface ConductorClientConnectOptions {
|
|
|
17
17
|
sessionStore?: SessionDiskStore;
|
|
18
18
|
messageRouter?: MessageRouter;
|
|
19
19
|
agentHost?: string;
|
|
20
|
+
onConnected?: (event: {
|
|
21
|
+
isReconnect: boolean;
|
|
22
|
+
}) => void;
|
|
23
|
+
onDisconnected?: () => void;
|
|
20
24
|
}
|
|
21
25
|
interface ConductorClientInit {
|
|
22
26
|
config: ConductorConfig;
|
|
@@ -47,6 +51,17 @@ export declare class ConductorClient {
|
|
|
47
51
|
sendMessage(taskId: string, content: string, metadata?: Record<string, any>): Promise<Record<string, any>>;
|
|
48
52
|
sendTaskStatus(taskId: string, payload: Record<string, any>): Promise<Record<string, any>>;
|
|
49
53
|
sendRuntimeStatus(taskId: string, payload: Record<string, any>): Promise<Record<string, any>>;
|
|
54
|
+
sendAgentResume(payload?: {
|
|
55
|
+
active_tasks?: string[];
|
|
56
|
+
source?: string;
|
|
57
|
+
metadata?: Record<string, any>;
|
|
58
|
+
}): Promise<Record<string, any>>;
|
|
59
|
+
sendAgentCommandAck(payload: {
|
|
60
|
+
request_id: string;
|
|
61
|
+
task_id?: string;
|
|
62
|
+
event_type?: string;
|
|
63
|
+
accepted?: boolean;
|
|
64
|
+
}): Promise<Record<string, any>>;
|
|
50
65
|
receiveMessages(taskId: string, limit?: number): Promise<Record<string, any>>;
|
|
51
66
|
ackMessages(taskId: string, ackToken?: string | null): Promise<Record<string, any> | undefined>;
|
|
52
67
|
listProjects(): Promise<Record<string, any>>;
|
|
@@ -57,6 +72,7 @@ export declare class ConductorClient {
|
|
|
57
72
|
bindProjectPath(projectId: string, payload?: Record<string, any>): Promise<Record<string, any>>;
|
|
58
73
|
private readonly handleBackendEvent;
|
|
59
74
|
private sendEnvelope;
|
|
75
|
+
private maybeAckInboundCommand;
|
|
60
76
|
private resolveHostname;
|
|
61
77
|
private waitForTaskCreation;
|
|
62
78
|
private readIntEnv;
|
package/dist/client.js
CHANGED
|
@@ -40,6 +40,8 @@ export class ConductorClient {
|
|
|
40
40
|
const wsClient = options.wsClient ??
|
|
41
41
|
new ConductorWebSocketClient(config, {
|
|
42
42
|
hostName: agentHost,
|
|
43
|
+
onConnected: options.onConnected,
|
|
44
|
+
onDisconnected: options.onDisconnected,
|
|
43
45
|
});
|
|
44
46
|
const client = new ConductorClient({
|
|
45
47
|
config,
|
|
@@ -146,6 +148,35 @@ export class ConductorClient {
|
|
|
146
148
|
});
|
|
147
149
|
return { delivered: true };
|
|
148
150
|
}
|
|
151
|
+
async sendAgentResume(payload = {}) {
|
|
152
|
+
await this.sendEnvelope({
|
|
153
|
+
type: 'agent_resume',
|
|
154
|
+
payload: {
|
|
155
|
+
active_tasks: Array.isArray(payload.active_tasks)
|
|
156
|
+
? payload.active_tasks.map((taskId) => String(taskId)).filter(Boolean)
|
|
157
|
+
: [],
|
|
158
|
+
source: payload.source,
|
|
159
|
+
metadata: payload.metadata,
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
return { delivered: true };
|
|
163
|
+
}
|
|
164
|
+
async sendAgentCommandAck(payload) {
|
|
165
|
+
const requestId = String(payload.request_id || '').trim();
|
|
166
|
+
if (!requestId) {
|
|
167
|
+
throw new Error('request_id is required');
|
|
168
|
+
}
|
|
169
|
+
await this.sendEnvelope({
|
|
170
|
+
type: 'agent_command_ack',
|
|
171
|
+
payload: {
|
|
172
|
+
request_id: requestId,
|
|
173
|
+
task_id: payload.task_id,
|
|
174
|
+
event_type: payload.event_type,
|
|
175
|
+
accepted: payload.accepted !== false,
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
return { delivered: true };
|
|
179
|
+
}
|
|
149
180
|
async receiveMessages(taskId, limit = 20) {
|
|
150
181
|
const messages = await this.sessions.popMessages(taskId, limit);
|
|
151
182
|
return formatMessagesResponse(messages);
|
|
@@ -248,10 +279,39 @@ export class ConductorClient {
|
|
|
248
279
|
}
|
|
249
280
|
handleBackendEvent = async (payload) => {
|
|
250
281
|
await this.messageRouter.handleBackendEvent(payload);
|
|
282
|
+
await this.maybeAckInboundCommand(payload);
|
|
251
283
|
};
|
|
252
284
|
async sendEnvelope(envelope) {
|
|
253
285
|
await this.wsClient.sendJson(envelope);
|
|
254
286
|
}
|
|
287
|
+
async maybeAckInboundCommand(payload) {
|
|
288
|
+
const eventType = typeof payload?.type === 'string' ? payload.type : '';
|
|
289
|
+
if (eventType !== 'task_user_message' && eventType !== 'task_action') {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
const data = payload?.payload && typeof payload.payload === 'object'
|
|
293
|
+
? payload.payload
|
|
294
|
+
: null;
|
|
295
|
+
if (!data) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const requestId = typeof data.request_id === 'string' ? data.request_id.trim() : '';
|
|
299
|
+
if (!requestId) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
await this.sendAgentCommandAck({
|
|
304
|
+
request_id: requestId,
|
|
305
|
+
task_id: typeof data.task_id === 'string' ? data.task_id : undefined,
|
|
306
|
+
event_type: eventType,
|
|
307
|
+
accepted: true,
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
catch (error) {
|
|
311
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
312
|
+
console.warn(`[sdk] failed to ack inbound command ${requestId}: ${message}`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
255
315
|
resolveHostname() {
|
|
256
316
|
const records = this.sessionStore.load();
|
|
257
317
|
for (const record of records) {
|