@yeaft/webchat-agent 0.1.1067 → 0.1.1069
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/package.json +1 -1
- package/yeaft/session.js +1 -1
- package/yeaft/tasks/manager.js +1 -51
package/package.json
CHANGED
package/yeaft/session.js
CHANGED
|
@@ -400,7 +400,7 @@ export async function loadSession(options = {}) {
|
|
|
400
400
|
}
|
|
401
401
|
|
|
402
402
|
// ─── 8. Build tool registry ────────────────────────────
|
|
403
|
-
const taskManager = new TaskManager({ yeaftDir
|
|
403
|
+
const taskManager = new TaskManager({ yeaftDir });
|
|
404
404
|
const toolRegistry = createFullRegistry();
|
|
405
405
|
|
|
406
406
|
// Register any extra tools from caller
|
package/yeaft/tasks/manager.js
CHANGED
|
@@ -40,33 +40,10 @@ function publicSnapshot(task) {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
function formatTaskMessage(kind, task, extra = {}) {
|
|
44
|
-
const lines = [];
|
|
45
|
-
const label = kind === 'started' ? 'Task started' : 'Task finished';
|
|
46
|
-
lines.push(`[${label}]`);
|
|
47
|
-
lines.push(`taskId: ${task.id}`);
|
|
48
|
-
lines.push(`kind: ${task.kind}`);
|
|
49
|
-
lines.push(`status: ${task.status}`);
|
|
50
|
-
lines.push(`ownerVpId: ${task.ownerVpId || 'unknown'}`);
|
|
51
|
-
lines.push(`title: ${task.title}`);
|
|
52
|
-
if (task.runtime?.command) lines.push(`command: ${task.runtime.command}`);
|
|
53
|
-
if (task.runtime?.cwd) lines.push(`cwd: ${task.runtime.cwd}`);
|
|
54
|
-
if (task.log?.path) lines.push(`log: ${task.log.path}`);
|
|
55
|
-
if (extra.exitCode != null) lines.push(`exitCode: ${extra.exitCode}`);
|
|
56
|
-
if (extra.signal) lines.push(`signal: ${extra.signal}`);
|
|
57
|
-
if (extra.summary) lines.push(`summary: ${extra.summary}`);
|
|
58
|
-
if (extra.logTail) {
|
|
59
|
-
lines.push('logTail:');
|
|
60
|
-
lines.push(extra.logTail.trimEnd());
|
|
61
|
-
}
|
|
62
|
-
return lines.join('\n');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
43
|
export class TaskManager {
|
|
66
|
-
constructor({ yeaftDir,
|
|
44
|
+
constructor({ yeaftDir, onEvent = null, runtimePlatform = null } = {}) {
|
|
67
45
|
if (!yeaftDir) throw new Error('TaskManager requires yeaftDir');
|
|
68
46
|
this.store = new TaskStore({ yeaftDir });
|
|
69
|
-
this.conversationStore = conversationStore;
|
|
70
47
|
this.onEvent = typeof onEvent === 'function' ? onEvent : null;
|
|
71
48
|
this.runtimePlatform = runtimePlatform || getRuntimePlatformInfo();
|
|
72
49
|
this.active = new Map();
|
|
@@ -87,24 +64,6 @@ export class TaskManager {
|
|
|
87
64
|
try { this.onEvent?.(payload); } catch { /* event sinks must not break tasks */ }
|
|
88
65
|
}
|
|
89
66
|
|
|
90
|
-
#persistLifecycleMessage(task, kind, extra = {}) {
|
|
91
|
-
if (!this.conversationStore || !task?.sessionId) return;
|
|
92
|
-
try {
|
|
93
|
-
this.conversationStore.append({
|
|
94
|
-
role: 'assistant',
|
|
95
|
-
content: formatTaskMessage(kind, task, extra),
|
|
96
|
-
sessionId: task.sessionId,
|
|
97
|
-
threadId: task.source?.threadId || 'main',
|
|
98
|
-
...(task.ownerVpId ? { speakerVpId: task.ownerVpId } : {}),
|
|
99
|
-
eventType: 'task_lifecycle',
|
|
100
|
-
taskId: task.id,
|
|
101
|
-
taskStatus: task.status,
|
|
102
|
-
});
|
|
103
|
-
} catch {
|
|
104
|
-
// Conversation persistence must not kill the background process.
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
67
|
#loadPersistedRunningTasks() {
|
|
109
68
|
for (const task of this.store.loadActiveTasks()) {
|
|
110
69
|
const orphaned = {
|
|
@@ -119,7 +78,6 @@ export class TaskManager {
|
|
|
119
78
|
};
|
|
120
79
|
this.store.writeTask(orphaned);
|
|
121
80
|
this.store.appendEvent(orphaned.sessionId, { event: 'orphaned', taskId: orphaned.id });
|
|
122
|
-
this.#persistLifecycleMessage(orphaned, 'finished', { summary: orphaned.result.error });
|
|
123
81
|
this.#emit('completed', orphaned);
|
|
124
82
|
}
|
|
125
83
|
}
|
|
@@ -150,7 +108,6 @@ export class TaskManager {
|
|
|
150
108
|
this.store.writeTask(task);
|
|
151
109
|
this.store.appendEvent(task.sessionId, { event: 'started', taskId: task.id, kind: task.kind });
|
|
152
110
|
this.active.set(this.#key(task.sessionId, task.id), task);
|
|
153
|
-
this.#persistLifecycleMessage(task, 'started');
|
|
154
111
|
this.#emit('started', task);
|
|
155
112
|
return publicSnapshot(task);
|
|
156
113
|
}
|
|
@@ -191,7 +148,6 @@ export class TaskManager {
|
|
|
191
148
|
this.store.writeTask(task);
|
|
192
149
|
this.store.appendEvent(task.sessionId, { event: 'started', taskId: task.id, kind: task.kind });
|
|
193
150
|
this.active.set(this.#key(task.sessionId, task.id), task);
|
|
194
|
-
this.#persistLifecycleMessage(task, 'started');
|
|
195
151
|
this.#emit('started', task);
|
|
196
152
|
|
|
197
153
|
const runtime = runtimePlatform || this.runtimePlatform;
|
|
@@ -241,12 +197,6 @@ export class TaskManager {
|
|
|
241
197
|
this.store.appendEvent(sessionId, { event: 'completed', taskId, status: task.status, exitCode, signal, error });
|
|
242
198
|
this.active.delete(key);
|
|
243
199
|
this.processes.delete(key);
|
|
244
|
-
this.#persistLifecycleMessage(task, 'finished', {
|
|
245
|
-
exitCode,
|
|
246
|
-
signal,
|
|
247
|
-
summary: error || `Task ${task.status}`,
|
|
248
|
-
logTail: tail.text,
|
|
249
|
-
});
|
|
250
200
|
this.#emit('completed', task);
|
|
251
201
|
return publicSnapshot(task);
|
|
252
202
|
}
|