@evandu/super-pi 0.1.218 → 0.1.220
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/agents/project-leader.md +1 -1
- package/agents/super-pi-task/core.ts +1 -1
- package/agents/super-pi-task/index.ts +4 -2
- package/dist/client/.super-pi-client-sources.json +6 -6
- package/dist/client/assets/{CodeMirrorEditor-CyESWKhO.js → CodeMirrorEditor-DLESYIdU.js} +2 -2
- package/dist/client/assets/{dist-xAE0Sxu_.js → dist-2Gv721yB.js} +1 -1
- package/dist/client/assets/{dist-CWLwzCNI.js → dist-B-63MNT9.js} +1 -1
- package/dist/client/assets/{dist-BQ5yUYGI.js → dist-B-ydE4PJ.js} +1 -1
- package/dist/client/assets/{dist-BfAB10-T.js → dist-B6UYFWUo.js} +1 -1
- package/dist/client/assets/{dist-GMozZ-IZ.js → dist-BG1xVEUu.js} +1 -1
- package/dist/client/assets/{dist-C6tiomV0.js → dist-BTUuXAFG.js} +1 -1
- package/dist/client/assets/{dist-Zl8KoipB.js → dist-Bz37bm03.js} +1 -1
- package/dist/client/assets/{dist-BwQiVXeZ.js → dist-CQAWuaHA.js} +1 -1
- package/dist/client/assets/{dist-XNj0UVAT.js → dist-CYEoLBJJ.js} +1 -1
- package/dist/client/assets/{dist-CkjmcyTq.js → dist-CbixgvA8.js} +1 -1
- package/dist/client/assets/{dist-DHh4-Br1.js → dist-CoC8iHD1.js} +1 -1
- package/dist/client/assets/{dist-DtyV497P.js → dist-CrtcsyOg.js} +1 -1
- package/dist/client/assets/{dist-BlALlifb.js → dist-D0Mff5_O.js} +1 -1
- package/dist/client/assets/{dist-BXMYNRiG.js → dist-DKRxalqK.js} +1 -1
- package/dist/client/assets/{dist-Cgclz1Km.js → dist-DPvgTEV_.js} +1 -1
- package/dist/client/assets/{dist-C9qNY2Kp.js → dist-DhCNXN4F.js} +1 -1
- package/dist/client/assets/{dist-BXq9HMCd.js → dist-DmraLEb2.js} +1 -1
- package/dist/client/assets/{dist-B33BwR-8.js → dist-DvJTvgiN.js} +1 -1
- package/dist/client/assets/{dist-C7y8W3IU.js → dist-YSB8UKj7.js} +1 -1
- package/dist/client/assets/{dist-1djw1Aua.js → dist-aDKso4tk.js} +1 -1
- package/dist/client/assets/{dist-DH6F4kKv.js → dist-h8QFV1py.js} +1 -1
- package/dist/client/assets/{dist-DZGY_CNU.js → dist-hyn4QSU9.js} +1 -1
- package/dist/client/assets/index-B-h_KnC5.css +1 -0
- package/dist/client/assets/{index-2k9h0zMt.js → index-BMuvJCSx.js} +11 -11
- package/dist/client/index.html +2 -2
- package/dist/server/application/conversation-service.d.ts +7 -2
- package/dist/server/application/conversation-service.js +45 -5
- package/dist/server/application/project-service.d.ts +53 -5
- package/dist/server/application/project-service.js +167 -36
- package/dist/server/application/run-service.d.ts +3 -1
- package/dist/server/application/run-service.js +22 -5
- package/dist/server/application/session-orchestrator-service.d.ts +65 -0
- package/dist/server/application/session-orchestrator-service.js +175 -22
- package/dist/server/application/session-reminder-service.js +1 -2
- package/dist/server/command-handler.d.ts +3 -1
- package/dist/server/command-handler.js +21 -1
- package/dist/server/index.js +2 -2
- package/dist/server/runtime.js +2 -2
- package/dist/server/store.d.ts +17 -4
- package/dist/server/store.js +93 -28
- package/dist/server/types.d.ts +24 -1
- package/dist/server/upload.d.ts +2 -0
- package/dist/server/upload.js +19 -2
- package/dist/shared/project-overview.d.ts +21 -0
- package/dist/shared/project-overview.js +36 -7
- package/dist/shared/project-presentation.d.ts +3 -0
- package/dist/shared/project-presentation.js +13 -5
- package/dist/shared/session-reporting.d.ts +32 -0
- package/dist/shared/session-reporting.js +29 -0
- package/dist/shared/team-context.d.ts +1 -1
- package/package.json +5 -1
- package/dist/client/assets/index-CwfAN5Vw.css +0 -1
|
@@ -66,6 +66,19 @@ export class SessionOrchestratorService {
|
|
|
66
66
|
* result is still its own.
|
|
67
67
|
*/
|
|
68
68
|
reportedChildren = new Map();
|
|
69
|
+
/**
|
|
70
|
+
* THE COMPLETION NOTICES THAT HAVE ALREADY KNOCKED ON A PARENT'S DOOR.
|
|
71
|
+
*
|
|
72
|
+
* One entry per finished child per completion, and the completion is identified by the child's
|
|
73
|
+
* last answer - so a RETRY of the same finished turn knocks once, while the next turn the child
|
|
74
|
+
* runs is a different completion and knocks again.
|
|
75
|
+
*
|
|
76
|
+
* WHY THIS IS A SET AND NOT A FLAG. A flag would say "this child has been announced", and that
|
|
77
|
+
* is a different question from "THIS completion has been announced". A flag silences every
|
|
78
|
+
* later completion of the same child, and a child that works for three turns would be announced
|
|
79
|
+
* once - the parent would sit through two of the child's finishes without being told.
|
|
80
|
+
*/
|
|
81
|
+
completionNotices = new Set();
|
|
69
82
|
constructor(store, conversationService, runService, ledger, broadcaster, watchdog, uploadsDir) {
|
|
70
83
|
this.store = store;
|
|
71
84
|
this.conversationService = conversationService;
|
|
@@ -127,7 +140,15 @@ export class SessionOrchestratorService {
|
|
|
127
140
|
if (!workspace)
|
|
128
141
|
throw new Error("找不到这个工作区。");
|
|
129
142
|
const parent = options.parentConversationId ? this.store.conversation(options.parentConversationId) : undefined;
|
|
130
|
-
const
|
|
143
|
+
const source = options.forkFromConversationId ? this.store.conversation(options.forkFromConversationId) : undefined;
|
|
144
|
+
if (options.forkFromConversationId && (!source || !parent || source.workspaceId !== workspaceId
|
|
145
|
+
|| parent.workspaceId !== workspaceId || (!source.warmSession && source.parentConversationId !== parent.id) || parent.archivedAt)) {
|
|
146
|
+
throw new Error("只能分叉同工作区及同一直属上级的会话");
|
|
147
|
+
}
|
|
148
|
+
if (source && options.cwd !== undefined && options.cwd !== (source.cwd ?? ".")) {
|
|
149
|
+
throw new Error("分叉任务须使用来源会话的工作目录");
|
|
150
|
+
}
|
|
151
|
+
const cwd = source ? source.cwd : options.cwd !== undefined ? options.cwd : parent?.workspaceId === workspaceId ? parent.cwd : undefined;
|
|
131
152
|
await assertSessionCwdInsideWorkspace(workspace.path, cwd);
|
|
132
153
|
if (options.handoffNote !== undefined && (typeof options.handoffNote !== "string" || options.handoffNote.length > 8000))
|
|
133
154
|
throw new Error("handoffNote 须为最多 8000 字符的交接说明");
|
|
@@ -135,28 +156,42 @@ export class SessionOrchestratorService {
|
|
|
135
156
|
// in-memory ledger below. The ledger is task/status/progress metadata and dies with the process;
|
|
136
157
|
// the conversation's parentConversationId/origin is what the sidebar's session tree redraws
|
|
137
158
|
// from after a restart, so it has to be the persistent record.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (options.title) {
|
|
145
|
-
await this.conversationService.renameConversation(conversationId, options.title);
|
|
146
|
-
}
|
|
147
|
-
else if (options.task) {
|
|
148
|
-
const titleSnippet = options.task.trim().replace(/\s+/g, " ").slice(0, 30);
|
|
149
|
-
await this.conversationService.renameConversation(conversationId, `任务:${titleSnippet}`);
|
|
159
|
+
let conversationId;
|
|
160
|
+
if (source) {
|
|
161
|
+
const result = await this.conversationService.forkConversation(source.id, { parentConversationId: parent?.id });
|
|
162
|
+
if (!result.ok)
|
|
163
|
+
throw new Error(result.message);
|
|
164
|
+
conversationId = result.forkedId;
|
|
150
165
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
166
|
+
else {
|
|
167
|
+
conversationId = await this.conversationService.createConversation(workspaceId, {
|
|
168
|
+
parentConversationId: options.parentConversationId,
|
|
169
|
+
origin: options.parentConversationId ? "orchestrator" : "user",
|
|
170
|
+
...(options.separateMemoryTree ? { separateMemoryTree: true } : {}),
|
|
171
|
+
}, cwd);
|
|
154
172
|
}
|
|
155
|
-
|
|
156
|
-
|
|
173
|
+
try {
|
|
174
|
+
if (options.title) {
|
|
175
|
+
await this.conversationService.renameConversation(conversationId, options.title);
|
|
176
|
+
}
|
|
177
|
+
else if (options.task) {
|
|
178
|
+
const titleSnippet = options.task.trim().replace(/\s+/g, " ").slice(0, 30);
|
|
179
|
+
await this.conversationService.renameConversation(conversationId, `任务:${titleSnippet}`);
|
|
180
|
+
}
|
|
181
|
+
if (options.agentId) {
|
|
182
|
+
await this.conversationService.setAgent(conversationId, options.agentId);
|
|
183
|
+
}
|
|
184
|
+
if (options.model) {
|
|
185
|
+
await this.conversationService.setModel(conversationId, options.model.provider, options.model.modelId);
|
|
186
|
+
}
|
|
187
|
+
if (options.thinkingLevel) {
|
|
188
|
+
await this.conversationService.setThinking(conversationId, options.thinkingLevel);
|
|
189
|
+
}
|
|
157
190
|
}
|
|
158
|
-
|
|
159
|
-
|
|
191
|
+
catch (error) {
|
|
192
|
+
if (source)
|
|
193
|
+
await this.remove(conversationId);
|
|
194
|
+
throw error;
|
|
160
195
|
}
|
|
161
196
|
// Register in relationship ledger
|
|
162
197
|
this.ledger.register({
|
|
@@ -195,9 +230,15 @@ export class SessionOrchestratorService {
|
|
|
195
230
|
/**
|
|
196
231
|
* Dispatches a message to an arbitrary session (server-to-server).
|
|
197
232
|
* By default dispatches asynchronously so the orchestrator caller is not blocked.
|
|
233
|
+
*
|
|
234
|
+
* `silent` is for the platform's own housekeeping - the completion knock. A knock wakes a
|
|
235
|
+
* session and carries no result, so the turn it starts must not produce a result report of its
|
|
236
|
+
* own: a knock that made the woken session report up would turn one child's finish into a
|
|
237
|
+
* chain of knocks all the way to the top.
|
|
198
238
|
*/
|
|
199
239
|
async dispatch(conversationId, content, options) {
|
|
200
240
|
const mode = parseMessageDeliveryMode(options?.mode);
|
|
241
|
+
const silent = options?.silent === true;
|
|
201
242
|
if (!content.trim()) {
|
|
202
243
|
throw new Error("dispatch requires non-empty content");
|
|
203
244
|
}
|
|
@@ -205,6 +246,8 @@ export class SessionOrchestratorService {
|
|
|
205
246
|
if (!conversation) {
|
|
206
247
|
throw new Error(`找不到会话:${conversationId}`);
|
|
207
248
|
}
|
|
249
|
+
if (conversation.warmSession)
|
|
250
|
+
throw new Error("预热快照只能通过项目派发使用");
|
|
208
251
|
this.ledger.update(conversationId, {
|
|
209
252
|
status: "running",
|
|
210
253
|
});
|
|
@@ -282,9 +325,14 @@ export class SessionOrchestratorService {
|
|
|
282
325
|
// the failures was a real defect - it left a parent that had successfully delegated a task
|
|
283
326
|
// staring at an empty transcript, and the child looking finished to everyone except the one
|
|
284
327
|
// person waiting for it.
|
|
328
|
+
// DID THIS TURN REPORT ITSELF? A child that reported from inside its turn has already told
|
|
329
|
+
// the parent everything the knock would have said - and a knock on top of that report would
|
|
330
|
+
// make the parent hear about one finished turn twice. The knock exists for the child that
|
|
331
|
+
// FORGOT to report, so a child that did report is not knocked.
|
|
332
|
+
let reportedItself = false;
|
|
285
333
|
try {
|
|
286
334
|
const result = await this.persistSessionResult(conversationId, failure);
|
|
287
|
-
if (result) {
|
|
335
|
+
if (result && !silent) {
|
|
288
336
|
const current = this.store.conversation(conversationId);
|
|
289
337
|
// THE REPORT GOES OUT ONLY WHEN THE CHILD'S TURN ENDED. The statuses that mean "the turn is
|
|
290
338
|
// over" are `completed` and `failed`; `running` and `awaiting_background` mean work is still
|
|
@@ -302,6 +350,7 @@ export class SessionOrchestratorService {
|
|
|
302
350
|
// one because of that would swallow a result the parent is still waiting for.
|
|
303
351
|
const reportedAt = this.reportedChildren.get(conversationId);
|
|
304
352
|
const alreadyReported = reportedAt !== undefined && reportedAt >= turnStartedAt;
|
|
353
|
+
reportedItself = alreadyReported;
|
|
305
354
|
if (turnEnded && !alreadyReported) {
|
|
306
355
|
await this.runService.enqueueSessionResult({
|
|
307
356
|
conversationId,
|
|
@@ -331,6 +380,33 @@ export class SessionOrchestratorService {
|
|
|
331
380
|
// turn that was running when it was made.
|
|
332
381
|
this.reportedChildren.delete(conversationId);
|
|
333
382
|
}
|
|
383
|
+
// THE PLATFORM KNOCKS ON THE PARENT'S DOOR. The turn is over, so the parent has to hear
|
|
384
|
+
// about it - whether the child remembered to say so or not. What the knock carries is the
|
|
385
|
+
// child's identity and nothing else: the parent reads the child's session itself.
|
|
386
|
+
//
|
|
387
|
+
// ONLY A FINISHED TURN KNOCKS. A turn that failed or was stopped did not finish its work,
|
|
388
|
+
// and the knock says 「完成」 - a broken turn is reported through the failure report, which
|
|
389
|
+
// carries the diagnosis.
|
|
390
|
+
//
|
|
391
|
+
// A PROJECT EMPLOYEE IS NOT ANNOUNCED HERE. Its turn ending is not its task being done, and
|
|
392
|
+
// the project announces the task's completion instead - one knock per piece of work.
|
|
393
|
+
//
|
|
394
|
+
// AND A CHILD THAT REPORTED ITSELF IS NOT KNOCKED. The knock exists for the child that
|
|
395
|
+
// FORGOT to report up; a child that did report has already said everything the knock would
|
|
396
|
+
// have said, and knocking as well would make the parent hear about one finished turn twice.
|
|
397
|
+
const finished = this.store.conversation(conversationId);
|
|
398
|
+
if (!silent
|
|
399
|
+
&& !reportedItself
|
|
400
|
+
&& finished?.status === "completed"
|
|
401
|
+
&& finished.parentConversationId
|
|
402
|
+
&& !this.projectParticipant(conversationId)) {
|
|
403
|
+
try {
|
|
404
|
+
await this.notifyChildCompleted(conversationId);
|
|
405
|
+
}
|
|
406
|
+
catch (error) {
|
|
407
|
+
console.warn(`Super Pi: 子会话 ${conversationId} 的完成通知失败:${error instanceof Error ? error.message : String(error)}`);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
334
410
|
if (failure !== undefined) {
|
|
335
411
|
console.warn(`Super Pi: dispatch failed for conversation ${conversationId}:`, failure instanceof Error ? failure.message : String(failure));
|
|
336
412
|
this.ledger.update(conversationId, { status: "failed" });
|
|
@@ -345,6 +421,75 @@ export class SessionOrchestratorService {
|
|
|
345
421
|
}
|
|
346
422
|
return { conversationId, ...(acceptedMessageId ? { messageId: acceptedMessageId } : {}), mode };
|
|
347
423
|
}
|
|
424
|
+
/**
|
|
425
|
+
* THE PLATFORM KNOCKS ON THE PARENT'S DOOR WHEN A CHILD SESSION ENDS.
|
|
426
|
+
*
|
|
427
|
+
* A child that finished its work is a child the parent has to hear about, and the PLATFORM is the
|
|
428
|
+
* one that knows the turn ended: the child may forget to say so, and a parent that was not
|
|
429
|
+
* present for the turn cannot see that it happened. This is the platform's own housekeeping -
|
|
430
|
+
* it is not something the child is asked to do and not something the model has to remember.
|
|
431
|
+
*
|
|
432
|
+
* THE KNOCK CARRIES NO WORK. It says WHICH child session finished and nothing else: no output,
|
|
433
|
+
* no summary, no last message, no result, no task result. The parent reads the child's session
|
|
434
|
+
* itself, so a platform that summarized here would be writing the report the parent is supposed
|
|
435
|
+
* to write - and a summary written by the platform is a summary nobody verified.
|
|
436
|
+
*
|
|
437
|
+
* ONLY THE DIRECT PARENT IS TOLD. The parent wakes up and looks at its own child; the
|
|
438
|
+
* grandparent is not told about a grandchild's finish, because the parent is the one who has to
|
|
439
|
+
* decide what that means.
|
|
440
|
+
*
|
|
441
|
+
* A TOP-LEVEL SESSION HAS NOBODY TO TELL, so a session without a parent produces nothing - and
|
|
442
|
+
* the user's own session is one of those.
|
|
443
|
+
*/
|
|
444
|
+
async notifyChildCompleted(childConversationId, options = {}) {
|
|
445
|
+
const child = this.store.conversation(childConversationId);
|
|
446
|
+
if (!child)
|
|
447
|
+
return { delivered: false };
|
|
448
|
+
const parentConversationId = child.parentConversationId;
|
|
449
|
+
if (!parentConversationId)
|
|
450
|
+
return { delivered: false };
|
|
451
|
+
const parent = this.store.conversation(parentConversationId);
|
|
452
|
+
if (!parent || parent.archivedAt)
|
|
453
|
+
return { delivered: false };
|
|
454
|
+
const unit = options.unit ?? this.completionUnit(child);
|
|
455
|
+
const key = `${childConversationId}:${unit}`;
|
|
456
|
+
// ONE COMPLETION, ONE KNOCK. A retry, or a second report about the same finished turn, must
|
|
457
|
+
// not knock twice - and the knock is remembered even if the delivery fails, so a parent that
|
|
458
|
+
// cannot be reached does not turn into a storm of retries.
|
|
459
|
+
if (this.completionNotices.has(key))
|
|
460
|
+
return { delivered: false, parentConversationId };
|
|
461
|
+
this.completionNotices.add(key);
|
|
462
|
+
const notice = `子会话已完成:${child.title || child.id}(${child.id})。`;
|
|
463
|
+
try {
|
|
464
|
+
await this.dispatch(parentConversationId, notice, { wait: false, silent: true });
|
|
465
|
+
}
|
|
466
|
+
catch (error) {
|
|
467
|
+
console.warn(`Super Pi: 子会话 ${childConversationId} 已完成,但叫不醒父会话 ${parentConversationId}:${error instanceof Error ? error.message : String(error)}`);
|
|
468
|
+
}
|
|
469
|
+
return { delivered: true, parentConversationId };
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* WHAT MAKES TWO COMPLETION REPORTS THE SAME COMPLETION.
|
|
473
|
+
*
|
|
474
|
+
* The child's last answer is the thing the completion is about, so two reports that arrive after
|
|
475
|
+
* the same answer are the same completion - a retry, a repeated settle, a second report about a
|
|
476
|
+
* turn that already ended. The next turn produces the next answer, and that is a new completion
|
|
477
|
+
* the parent has not been told about yet.
|
|
478
|
+
*/
|
|
479
|
+
completionUnit(conversation) {
|
|
480
|
+
const lastAnswer = [...conversation.messages].reverse().find((message) => message.role === "assistant");
|
|
481
|
+
return lastAnswer?.id ?? conversation.messages.at(-1)?.id ?? "end";
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* IS THIS SESSION ONE OF A PROJECT'S EMPLOYEES?
|
|
485
|
+
*
|
|
486
|
+
* A project member's turn ending is NOT its work being done: the delivery still has to be
|
|
487
|
+
* reviewed. The moment that counts is the task being completed, and the project announces that
|
|
488
|
+
* one - announcing both would wake the Leader twice for one piece of work.
|
|
489
|
+
*/
|
|
490
|
+
projectParticipant(conversationId) {
|
|
491
|
+
return this.store.projects().some(project => project.tasks.some(task => task.ownerConversationId === conversationId || task.reviewerConversationId === conversationId));
|
|
492
|
+
}
|
|
348
493
|
/**
|
|
349
494
|
* THE CHILD'S OUTPUT WAS CUT OFF. TELL IT TO CARRY ON, AND LET IT.
|
|
350
495
|
*
|
|
@@ -871,6 +1016,14 @@ export class SessionOrchestratorService {
|
|
|
871
1016
|
descendantCount: descendants.length,
|
|
872
1017
|
};
|
|
873
1018
|
}
|
|
1019
|
+
async removeWarmSession(conversationId) {
|
|
1020
|
+
const conversation = this.store.conversation(conversationId);
|
|
1021
|
+
if (!conversation)
|
|
1022
|
+
return;
|
|
1023
|
+
if (!conversation.warmSession)
|
|
1024
|
+
throw new Error("只能通过此操作移除预热快照");
|
|
1025
|
+
await this.remove(conversationId);
|
|
1026
|
+
}
|
|
874
1027
|
/**
|
|
875
1028
|
* Permanently destroys a direct child session and its entire descendant subtree (stopping any
|
|
876
1029
|
* running/queued turns first) and removes all transcripts, outputs, runs, and auxiliary state.
|
|
@@ -891,7 +1044,7 @@ export class SessionOrchestratorService {
|
|
|
891
1044
|
...(reason ? { reason } : {}),
|
|
892
1045
|
};
|
|
893
1046
|
}
|
|
894
|
-
if (!conversation.parentConversationId) {
|
|
1047
|
+
if (!conversation.parentConversationId && !conversation.warmSession) {
|
|
895
1048
|
throw new Error("顶层会话不能销毁,只能由用户归档。");
|
|
896
1049
|
}
|
|
897
1050
|
const descendants = this.descendantsOf(conversationId);
|
|
@@ -110,9 +110,8 @@ export class SessionReminderService {
|
|
|
110
110
|
if (!conversation || conversation.archivedAt) {
|
|
111
111
|
return;
|
|
112
112
|
}
|
|
113
|
-
const message = `[定时提醒] ${note}`;
|
|
114
113
|
try {
|
|
115
|
-
await this.runService.
|
|
114
|
+
await this.runService.enqueueReminder(conversationId, note);
|
|
116
115
|
}
|
|
117
116
|
catch (error) {
|
|
118
117
|
console.warn(`Super Pi: delivering session reminder to ${conversationId} failed:`, error instanceof Error ? error.message : String(error));
|
|
@@ -6,6 +6,7 @@ import type { ExtensionUiService } from "./application/extension-ui-service.js";
|
|
|
6
6
|
import type { CatalogService } from "./application/catalog-service.js";
|
|
7
7
|
import type { ProviderService } from "./application/provider-service.js";
|
|
8
8
|
import type { ScheduledTaskService } from "./application/scheduled-task-service.js";
|
|
9
|
+
import type { SessionOrchestratorService } from "./application/session-orchestrator-service.js";
|
|
9
10
|
import type { TerminalService } from "./terminal.js";
|
|
10
11
|
export type SocketSender = (event: ServerEvent) => void;
|
|
11
12
|
/**
|
|
@@ -34,6 +35,7 @@ export declare class CommandHandler {
|
|
|
34
35
|
* follows.
|
|
35
36
|
*/
|
|
36
37
|
private readonly scheduledTaskService?;
|
|
38
|
+
private readonly sessionOrchestratorService?;
|
|
37
39
|
/**
|
|
38
40
|
* The built-in terminal service.
|
|
39
41
|
*
|
|
@@ -57,7 +59,7 @@ export declare class CommandHandler {
|
|
|
57
59
|
* service has to say so rather than take the whole handler down - the same rule `providerService`
|
|
58
60
|
* follows.
|
|
59
61
|
*/
|
|
60
|
-
scheduledTaskService?: ScheduledTaskService | undefined);
|
|
62
|
+
scheduledTaskService?: ScheduledTaskService | undefined, sessionOrchestratorService?: SessionOrchestratorService | undefined);
|
|
61
63
|
/**
|
|
62
64
|
* Processes a client command.
|
|
63
65
|
*
|
|
@@ -15,6 +15,7 @@ export class CommandHandler {
|
|
|
15
15
|
rootDir;
|
|
16
16
|
providerService;
|
|
17
17
|
scheduledTaskService;
|
|
18
|
+
sessionOrchestratorService;
|
|
18
19
|
/**
|
|
19
20
|
* The built-in terminal service.
|
|
20
21
|
*
|
|
@@ -38,7 +39,7 @@ export class CommandHandler {
|
|
|
38
39
|
* service has to say so rather than take the whole handler down - the same rule `providerService`
|
|
39
40
|
* follows.
|
|
40
41
|
*/
|
|
41
|
-
scheduledTaskService) {
|
|
42
|
+
scheduledTaskService, sessionOrchestratorService) {
|
|
42
43
|
this.workspaceService = workspaceService;
|
|
43
44
|
this.conversationService = conversationService;
|
|
44
45
|
this.runService = runService;
|
|
@@ -47,6 +48,7 @@ export class CommandHandler {
|
|
|
47
48
|
this.rootDir = rootDir;
|
|
48
49
|
this.providerService = providerService;
|
|
49
50
|
this.scheduledTaskService = scheduledTaskService;
|
|
51
|
+
this.sessionOrchestratorService = sessionOrchestratorService;
|
|
50
52
|
this.terminalService = terminalService;
|
|
51
53
|
}
|
|
52
54
|
/**
|
|
@@ -76,6 +78,10 @@ export class CommandHandler {
|
|
|
76
78
|
this.conversationService.releaseRevert(conversationId);
|
|
77
79
|
}
|
|
78
80
|
async handleCommand(command, sendToSocket, remoteAddress) {
|
|
81
|
+
if ("conversationId" in command && typeof command.conversationId === "string"
|
|
82
|
+
&& command.type !== "conversation.warm.delete" && this.conversationService.isWarmSession?.(command.conversationId)) {
|
|
83
|
+
throw new Error("预热快照只能通过项目派发使用");
|
|
84
|
+
}
|
|
79
85
|
if (command.type === "terminal.shell.set") {
|
|
80
86
|
if (!this.terminalService || !(await this.terminalService.setShell(command.command, remoteAddress)))
|
|
81
87
|
return;
|
|
@@ -235,6 +241,20 @@ export class CommandHandler {
|
|
|
235
241
|
}
|
|
236
242
|
return;
|
|
237
243
|
}
|
|
244
|
+
if (command.type === "conversation.warm.save") {
|
|
245
|
+
if (typeof command.title !== "string")
|
|
246
|
+
throw new Error("请输入预热会话名称");
|
|
247
|
+
const result = await this.conversationService.forkConversation(command.conversationId, { warmTitle: command.title });
|
|
248
|
+
if (!result.ok)
|
|
249
|
+
throw new Error(result.message);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (command.type === "conversation.warm.delete") {
|
|
253
|
+
if (!this.sessionOrchestratorService)
|
|
254
|
+
throw new Error("会话编排服务未就绪");
|
|
255
|
+
await this.sessionOrchestratorService.removeWarmSession(command.conversationId);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
238
258
|
if (command.type === "conversation.model") {
|
|
239
259
|
await this.conversationService.setModel(command.conversationId, command.provider, command.modelId);
|
|
240
260
|
return;
|
package/dist/server/index.js
CHANGED
|
@@ -277,7 +277,7 @@ runService.setFileIndexes(fileIndexes);
|
|
|
277
277
|
*/
|
|
278
278
|
const nameIndexes = new Map();
|
|
279
279
|
runService.setNameIndexes(nameIndexes);
|
|
280
|
-
const conversationService = new ConversationService(store, runtime, subagents, broadcaster, catalogService, runService, extensionUiService, initialAgentDirs);
|
|
280
|
+
const conversationService = new ConversationService(store, runtime, subagents, broadcaster, catalogService, runService, extensionUiService, initialAgentDirs, uploadsDir);
|
|
281
281
|
conversationService.setMemory(memory);
|
|
282
282
|
const workspaceService = new WorkspaceService(store, runtime, broadcaster, catalogService, runService, extensionUiService, initialAgentDirs);
|
|
283
283
|
/**
|
|
@@ -360,7 +360,7 @@ const serverContext = {
|
|
|
360
360
|
terminalEnabled: () => terminalService.enabled,
|
|
361
361
|
terminalDisabledReason: () => terminalDisabledReason(),
|
|
362
362
|
};
|
|
363
|
-
const commandHandler = new CommandHandler(workspaceService, conversationService, runService, extensionUiService, catalogService, terminalService, rootDir, providerService, scheduledTaskService);
|
|
363
|
+
const commandHandler = new CommandHandler(workspaceService, conversationService, runService, extensionUiService, catalogService, terminalService, rootDir, providerService, scheduledTaskService, sessionOrchestratorService);
|
|
364
364
|
// ------------------------------------------------------------- Lifecycle & shutdown
|
|
365
365
|
let shutdownPromise;
|
|
366
366
|
async function closeHttpServer() {
|
package/dist/server/runtime.js
CHANGED
|
@@ -2434,8 +2434,8 @@ export class PiRpcRuntime {
|
|
|
2434
2434
|
const deadline = Date.now() + TIMEOUT_MS;
|
|
2435
2435
|
try {
|
|
2436
2436
|
const transcript = conversation.messages
|
|
2437
|
-
.filter(
|
|
2438
|
-
.map(
|
|
2437
|
+
.filter(message => (message.role === "user" || message.role === "assistant" || message.source === "session-reminder") && message.content.trim())
|
|
2438
|
+
.map(message => `${message.source === "session-reminder" ? "定时提醒" : message.role === "user" ? "User" : "Assistant"}: ${message.content.trim()}`)
|
|
2439
2439
|
.join("\n");
|
|
2440
2440
|
if (!transcript)
|
|
2441
2441
|
throw new Error("这个会话还没有内容,无法据此生成标题");
|
package/dist/server/store.d.ts
CHANGED
|
@@ -149,6 +149,14 @@ export declare class Store {
|
|
|
149
149
|
project(projectId: string): Project | undefined;
|
|
150
150
|
/** Conversation IDs that currently have an unresolved escalation requested. */
|
|
151
151
|
openEscalationConversationIds(): Set<string>;
|
|
152
|
+
/**
|
|
153
|
+
* 每条未决例外该谁拍板,按发起会话归拢。
|
|
154
|
+
*
|
|
155
|
+
* `supervisor` = 团队内部的事(会话在等自己的直属上级),`boss` = 到了顶层。
|
|
156
|
+
* 一个会话同时开着内部和顶层两条时,顶层那条赢:那是唯一需要用户听见的一条。
|
|
157
|
+
* 老记录没有 `audience`,按 `boss` 读 —— 宁可多让用户看见一次,也不要把该用户决定的事藏起来。
|
|
158
|
+
*/
|
|
159
|
+
openEscalationAudiences(): Map<string, "supervisor" | "boss">;
|
|
152
160
|
/** Child conversation IDs whose enqueued session result is still waiting or sending on a non-archived parent. */
|
|
153
161
|
pendingResultConversationIds(): Set<string>;
|
|
154
162
|
setProject(project: Project): Promise<Project>;
|
|
@@ -304,6 +312,8 @@ export declare class Store {
|
|
|
304
312
|
* for a message that was never allowed to be sent.
|
|
305
313
|
*/
|
|
306
314
|
childLockUnlocked(conversationId: string): boolean;
|
|
315
|
+
listWarmSessions(workspaceId: string): NonNullable<AppState["warmSessions"]>;
|
|
316
|
+
isWarmSession(conversationId: string): boolean;
|
|
307
317
|
/**
|
|
308
318
|
* Opens (or re-closes) one child session's composer, and persists it.
|
|
309
319
|
*
|
|
@@ -371,7 +381,11 @@ export declare class Store {
|
|
|
371
381
|
* (`byRecency`) puts a fork at the TOP of its workspace group, because `updatedAt` is now - which is the
|
|
372
382
|
* same position a newly created conversation takes, and the same reason.
|
|
373
383
|
*/
|
|
374
|
-
forkConversation(sourceConversationId: string, forkedConversationId: string
|
|
384
|
+
forkConversation(sourceConversationId: string, forkedConversationId: string, options?: {
|
|
385
|
+
parentConversationId?: string;
|
|
386
|
+
warmTitle?: string;
|
|
387
|
+
piSessionFile?: string;
|
|
388
|
+
}): Promise<Conversation>;
|
|
375
389
|
/**
|
|
376
390
|
* Archive is a marker, not a move: the conversation keeps its id, workspace, messages and position.
|
|
377
391
|
* `updatedAt` is deliberately NOT touched, because it drives the sidebar's live timestamp and recency -
|
|
@@ -467,13 +481,12 @@ export declare class Store {
|
|
|
467
481
|
* `composePrompt` in the run service). So the instruction reaches the model the same way, and the
|
|
468
482
|
* reader sees who spoke.
|
|
469
483
|
*/
|
|
470
|
-
addAgentMessage(conversationId: string, content: string, options?:
|
|
471
|
-
delivery?: Message["delivery"];
|
|
472
|
-
}): Promise<Message>;
|
|
484
|
+
addAgentMessage(conversationId: string, content: string, options?: Pick<Message, "delivery" | "source">): Promise<Message>;
|
|
473
485
|
addUserMessage(conversationId: string, content: string, images?: MessageImage[], attachments?: import("./types.js").MessageAttachments, options?: {
|
|
474
486
|
clientId?: string;
|
|
475
487
|
delivery?: Message["delivery"];
|
|
476
488
|
}): Promise<Message>;
|
|
489
|
+
private persistIncomingTurn;
|
|
477
490
|
/**
|
|
478
491
|
* Takes the browser's id for its own optimistic message, when it is safe to.
|
|
479
492
|
*
|