@evandu/super-pi 0.1.219 → 0.1.221
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 +3 -2
- package/agents/super-pi-task/core.ts +1 -1
- package/dist/client/.super-pi-client-sources.json +6 -6
- package/dist/client/assets/{CodeMirrorEditor-BoRBaVec.js → CodeMirrorEditor-Cv1X2hmd.js} +2 -2
- package/dist/client/assets/{dist-CYpk6fXT.js → dist-B3GZVLeH.js} +1 -1
- package/dist/client/assets/{dist-DQ_C0DEU.js → dist-BA1wBjGJ.js} +1 -1
- package/dist/client/assets/{dist-CPjKkcyd.js → dist-BT_Z_-2X.js} +1 -1
- package/dist/client/assets/{dist-Digy2Mj0.js → dist-BqNxkXgs.js} +1 -1
- package/dist/client/assets/{dist-CiRgPe6t.js → dist-Bxyffyjn.js} +1 -1
- package/dist/client/assets/{dist-D1hdxSH6.js → dist-C-Kbr0WK.js} +1 -1
- package/dist/client/assets/{dist-CIv6vCdn.js → dist-C071I6sD.js} +1 -1
- package/dist/client/assets/{dist-CMdO3YzL.js → dist-C729XRkf.js} +1 -1
- package/dist/client/assets/{dist-BOF4T7jI.js → dist-CRfLPcZ8.js} +1 -1
- package/dist/client/assets/{dist-Dwsqs8C-.js → dist-CT23BwQB.js} +1 -1
- package/dist/client/assets/{dist-mAA5Fw0-.js → dist-CVErcv3I.js} +1 -1
- package/dist/client/assets/{dist-Cp3XgqJR.js → dist-CeHhOkTz.js} +1 -1
- package/dist/client/assets/{dist-CjhpwEGf.js → dist-ClwDCrdU.js} +1 -1
- package/dist/client/assets/{dist-xb23AFcT.js → dist-CsqiBKUZ.js} +1 -1
- package/dist/client/assets/{dist-DvWgfLRt.js → dist-DPYofnO9.js} +1 -1
- package/dist/client/assets/{dist-DUbHNa35.js → dist-DlBSkHdo.js} +1 -1
- package/dist/client/assets/{dist-DLYLxwOe.js → dist-DrNjVA0k.js} +1 -1
- package/dist/client/assets/{dist-BVVJTFYw.js → dist-Gvvox7eW.js} +1 -1
- package/dist/client/assets/{dist-BXOV_xtI.js → dist-IohJ9Qkl.js} +1 -1
- package/dist/client/assets/{dist-BOC9yjsN.js → dist-J-F3f1eU.js} +1 -1
- package/dist/client/assets/{dist-Bh20DSAa.js → dist-w6rH3SJG.js} +1 -1
- package/dist/client/assets/{dist-gRtmlyhZ.js → dist-xdw6XDXx.js} +1 -1
- package/dist/client/assets/index-B-h_KnC5.css +1 -0
- package/dist/client/assets/{index-DmxXnVfN.js → index-CCF1Ymba.js} +11 -11
- package/dist/client/index.html +2 -2
- package/dist/server/application/extension-ui-service.d.ts +2 -1
- package/dist/server/application/extension-ui-service.js +25 -17
- package/dist/server/application/project-service.d.ts +48 -3
- package/dist/server/application/project-service.js +123 -38
- package/dist/server/application/run-service.d.ts +3 -1
- package/dist/server/application/run-service.js +20 -5
- package/dist/server/application/session-orchestrator-service.d.ts +62 -0
- package/dist/server/application/session-orchestrator-service.js +122 -1
- package/dist/server/application/session-reminder-service.js +1 -2
- package/dist/server/index.js +5 -1
- package/dist/server/runtime.js +2 -2
- package/dist/server/store.d.ts +10 -3
- package/dist/server/store.js +87 -20
- package/dist/server/types.d.ts +7 -0
- package/dist/shared/project-overview.d.ts +12 -0
- package/dist/shared/project-overview.js +15 -0
- package/dist/shared/session-reporting.d.ts +14 -0
- package/dist/shared/session-reporting.js +11 -0
- package/package.json +5 -1
- package/dist/client/assets/index-Nu--gcBs.css +0 -1
|
@@ -155,6 +155,19 @@ export declare class SessionOrchestratorService {
|
|
|
155
155
|
* result is still its own.
|
|
156
156
|
*/
|
|
157
157
|
private readonly reportedChildren;
|
|
158
|
+
/**
|
|
159
|
+
* THE COMPLETION NOTICES THAT HAVE ALREADY KNOCKED ON A PARENT'S DOOR.
|
|
160
|
+
*
|
|
161
|
+
* One entry per finished child per completion, and the completion is identified by the child's
|
|
162
|
+
* last answer - so a RETRY of the same finished turn knocks once, while the next turn the child
|
|
163
|
+
* runs is a different completion and knocks again.
|
|
164
|
+
*
|
|
165
|
+
* WHY THIS IS A SET AND NOT A FLAG. A flag would say "this child has been announced", and that
|
|
166
|
+
* is a different question from "THIS completion has been announced". A flag silences every
|
|
167
|
+
* later completion of the same child, and a child that works for three turns would be announced
|
|
168
|
+
* once - the parent would sit through two of the child's finishes without being told.
|
|
169
|
+
*/
|
|
170
|
+
private readonly completionNotices;
|
|
158
171
|
constructor(store: Store, conversationService: ConversationService, runService: RunService, ledger: SessionLedger, broadcaster?: EventBroadcaster | undefined, watchdog?: SessionWatchdog, uploadsDir?: string | undefined);
|
|
159
172
|
/**
|
|
160
173
|
* The watchdog timer fired: the child has been silent for longer than the parent declared.
|
|
@@ -170,15 +183,64 @@ export declare class SessionOrchestratorService {
|
|
|
170
183
|
/**
|
|
171
184
|
* Dispatches a message to an arbitrary session (server-to-server).
|
|
172
185
|
* By default dispatches asynchronously so the orchestrator caller is not blocked.
|
|
186
|
+
*
|
|
187
|
+
* `silent` is for the platform's own housekeeping - the completion knock. A knock wakes a
|
|
188
|
+
* session and carries no result, so the turn it starts must not produce a result report of its
|
|
189
|
+
* own: a knock that made the woken session report up would turn one child's finish into a
|
|
190
|
+
* chain of knocks all the way to the top.
|
|
173
191
|
*/
|
|
174
192
|
dispatch(conversationId: string, content: string, options?: {
|
|
175
193
|
wait?: boolean;
|
|
176
194
|
mode?: MessageDeliveryMode;
|
|
195
|
+
silent?: boolean;
|
|
177
196
|
}): Promise<{
|
|
178
197
|
conversationId: string;
|
|
179
198
|
messageId?: string;
|
|
180
199
|
mode: MessageDeliveryMode;
|
|
181
200
|
}>;
|
|
201
|
+
/**
|
|
202
|
+
* THE PLATFORM KNOCKS ON THE PARENT'S DOOR WHEN A CHILD SESSION ENDS.
|
|
203
|
+
*
|
|
204
|
+
* A child that finished its work is a child the parent has to hear about, and the PLATFORM is the
|
|
205
|
+
* one that knows the turn ended: the child may forget to say so, and a parent that was not
|
|
206
|
+
* present for the turn cannot see that it happened. This is the platform's own housekeeping -
|
|
207
|
+
* it is not something the child is asked to do and not something the model has to remember.
|
|
208
|
+
*
|
|
209
|
+
* THE KNOCK CARRIES NO WORK. It says WHICH child session finished and nothing else: no output,
|
|
210
|
+
* no summary, no last message, no result, no task result. The parent reads the child's session
|
|
211
|
+
* itself, so a platform that summarized here would be writing the report the parent is supposed
|
|
212
|
+
* to write - and a summary written by the platform is a summary nobody verified.
|
|
213
|
+
*
|
|
214
|
+
* ONLY THE DIRECT PARENT IS TOLD. The parent wakes up and looks at its own child; the
|
|
215
|
+
* grandparent is not told about a grandchild's finish, because the parent is the one who has to
|
|
216
|
+
* decide what that means.
|
|
217
|
+
*
|
|
218
|
+
* A TOP-LEVEL SESSION HAS NOBODY TO TELL, so a session without a parent produces nothing - and
|
|
219
|
+
* the user's own session is one of those.
|
|
220
|
+
*/
|
|
221
|
+
notifyChildCompleted(childConversationId: string, options?: {
|
|
222
|
+
unit?: string;
|
|
223
|
+
}): Promise<{
|
|
224
|
+
delivered: boolean;
|
|
225
|
+
parentConversationId?: string;
|
|
226
|
+
}>;
|
|
227
|
+
/**
|
|
228
|
+
* WHAT MAKES TWO COMPLETION REPORTS THE SAME COMPLETION.
|
|
229
|
+
*
|
|
230
|
+
* The child's last answer is the thing the completion is about, so two reports that arrive after
|
|
231
|
+
* the same answer are the same completion - a retry, a repeated settle, a second report about a
|
|
232
|
+
* turn that already ended. The next turn produces the next answer, and that is a new completion
|
|
233
|
+
* the parent has not been told about yet.
|
|
234
|
+
*/
|
|
235
|
+
private completionUnit;
|
|
236
|
+
/**
|
|
237
|
+
* IS THIS SESSION ONE OF A PROJECT'S EMPLOYEES?
|
|
238
|
+
*
|
|
239
|
+
* A project member's turn ending is NOT its work being done: the delivery still has to be
|
|
240
|
+
* reviewed. The moment that counts is the task being completed, and the project announces that
|
|
241
|
+
* one - announcing both would wake the Leader twice for one piece of work.
|
|
242
|
+
*/
|
|
243
|
+
private projectParticipant;
|
|
182
244
|
/**
|
|
183
245
|
* THE CHILD'S OUTPUT WAS CUT OFF. TELL IT TO CARRY ON, AND LET IT.
|
|
184
246
|
*
|
|
@@ -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;
|
|
@@ -217,9 +230,15 @@ export class SessionOrchestratorService {
|
|
|
217
230
|
/**
|
|
218
231
|
* Dispatches a message to an arbitrary session (server-to-server).
|
|
219
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.
|
|
220
238
|
*/
|
|
221
239
|
async dispatch(conversationId, content, options) {
|
|
222
240
|
const mode = parseMessageDeliveryMode(options?.mode);
|
|
241
|
+
const silent = options?.silent === true;
|
|
223
242
|
if (!content.trim()) {
|
|
224
243
|
throw new Error("dispatch requires non-empty content");
|
|
225
244
|
}
|
|
@@ -306,9 +325,14 @@ export class SessionOrchestratorService {
|
|
|
306
325
|
// the failures was a real defect - it left a parent that had successfully delegated a task
|
|
307
326
|
// staring at an empty transcript, and the child looking finished to everyone except the one
|
|
308
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;
|
|
309
333
|
try {
|
|
310
334
|
const result = await this.persistSessionResult(conversationId, failure);
|
|
311
|
-
if (result) {
|
|
335
|
+
if (result && !silent) {
|
|
312
336
|
const current = this.store.conversation(conversationId);
|
|
313
337
|
// THE REPORT GOES OUT ONLY WHEN THE CHILD'S TURN ENDED. The statuses that mean "the turn is
|
|
314
338
|
// over" are `completed` and `failed`; `running` and `awaiting_background` mean work is still
|
|
@@ -326,6 +350,7 @@ export class SessionOrchestratorService {
|
|
|
326
350
|
// one because of that would swallow a result the parent is still waiting for.
|
|
327
351
|
const reportedAt = this.reportedChildren.get(conversationId);
|
|
328
352
|
const alreadyReported = reportedAt !== undefined && reportedAt >= turnStartedAt;
|
|
353
|
+
reportedItself = alreadyReported;
|
|
329
354
|
if (turnEnded && !alreadyReported) {
|
|
330
355
|
await this.runService.enqueueSessionResult({
|
|
331
356
|
conversationId,
|
|
@@ -355,6 +380,33 @@ export class SessionOrchestratorService {
|
|
|
355
380
|
// turn that was running when it was made.
|
|
356
381
|
this.reportedChildren.delete(conversationId);
|
|
357
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
|
+
}
|
|
358
410
|
if (failure !== undefined) {
|
|
359
411
|
console.warn(`Super Pi: dispatch failed for conversation ${conversationId}:`, failure instanceof Error ? failure.message : String(failure));
|
|
360
412
|
this.ledger.update(conversationId, { status: "failed" });
|
|
@@ -369,6 +421,75 @@ export class SessionOrchestratorService {
|
|
|
369
421
|
}
|
|
370
422
|
return { conversationId, ...(acceptedMessageId ? { messageId: acceptedMessageId } : {}), mode };
|
|
371
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
|
+
}
|
|
372
493
|
/**
|
|
373
494
|
* THE CHILD'S OUTPUT WAS CUT OFF. TELL IT TO CARRY ON, AND LET IT.
|
|
374
495
|
*
|
|
@@ -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));
|
package/dist/server/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import { mkdir } from "node:fs/promises";
|
|
|
7
7
|
import { homedir } from "node:os";
|
|
8
8
|
import { join, resolve } from "node:path";
|
|
9
9
|
import { pathToFileURL } from "node:url";
|
|
10
|
+
import { isChildSession } from "../shared/child-session-lock.js";
|
|
10
11
|
import { openStateStore } from "./persistence/open-state-store.js";
|
|
11
12
|
import { PiRpcRuntime, WelcomeRuntime } from "./runtime.js";
|
|
12
13
|
import { agentModeOf, resolveAgentDirectories } from "./agents.js";
|
|
@@ -187,7 +188,10 @@ const feishu = new FeishuService();
|
|
|
187
188
|
process.env.SUPER_PI_FEISHU_ENDPOINT = `http://${internalHost}:${port}/api/feishu/tool`;
|
|
188
189
|
const web = new WebService();
|
|
189
190
|
process.env.SUPER_PI_WEB_ENDPOINT = `http://${internalHost}:${port}/api/web/tool`;
|
|
190
|
-
const extensionUiService = new ExtensionUiService(broadcaster
|
|
191
|
+
const extensionUiService = new ExtensionUiService(broadcaster, id => {
|
|
192
|
+
const { parentConversationId, parent } = store.childSessionFacts(id);
|
|
193
|
+
return !isChildSession(parentConversationId, parent);
|
|
194
|
+
});
|
|
191
195
|
const supervisor = new SubagentSupervisor(join(dataDir, "pi-sessions"), undefined, {
|
|
192
196
|
dir: initialAgentDirs,
|
|
193
197
|
promptDir: agentPromptDir,
|
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
|
+
* 旧的子会话记录在加载时归回父会话,此处仅聚合规范化后的受众。
|
|
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>;
|
|
@@ -473,13 +481,12 @@ export declare class Store {
|
|
|
473
481
|
* `composePrompt` in the run service). So the instruction reaches the model the same way, and the
|
|
474
482
|
* reader sees who spoke.
|
|
475
483
|
*/
|
|
476
|
-
addAgentMessage(conversationId: string, content: string, options?:
|
|
477
|
-
delivery?: Message["delivery"];
|
|
478
|
-
}): Promise<Message>;
|
|
484
|
+
addAgentMessage(conversationId: string, content: string, options?: Pick<Message, "delivery" | "source">): Promise<Message>;
|
|
479
485
|
addUserMessage(conversationId: string, content: string, images?: MessageImage[], attachments?: import("./types.js").MessageAttachments, options?: {
|
|
480
486
|
clientId?: string;
|
|
481
487
|
delivery?: Message["delivery"];
|
|
482
488
|
}): Promise<Message>;
|
|
489
|
+
private persistIncomingTurn;
|
|
483
490
|
/**
|
|
484
491
|
* Takes the browser's id for its own optimistic message, when it is safe to.
|
|
485
492
|
*
|
package/dist/server/store.js
CHANGED
|
@@ -652,6 +652,43 @@ function reconcileBackgroundTasks(state) {
|
|
|
652
652
|
}
|
|
653
653
|
return { orphaned, changed: orphaned.length > 0, unlinked };
|
|
654
654
|
}
|
|
655
|
+
function normalizeProjectEscalations(project, conversation) {
|
|
656
|
+
let changed = false;
|
|
657
|
+
for (const item of project.escalations ?? []) {
|
|
658
|
+
if (String(item.status) === "pending") {
|
|
659
|
+
item.status = "open";
|
|
660
|
+
changed = true;
|
|
661
|
+
}
|
|
662
|
+
if (item.status !== "open" || item.audience === "supervisor" || !item.requestedByConversationId)
|
|
663
|
+
continue;
|
|
664
|
+
const requester = conversation(item.requestedByConversationId);
|
|
665
|
+
const assigned = item.requestedByConversationId !== project.ownerConversationId
|
|
666
|
+
&& item.requestedByConversationId !== project.initiatorConversationId
|
|
667
|
+
? project.tasks?.find(task => task.ownerConversationId === item.requestedByConversationId
|
|
668
|
+
|| task.reviewerConversationId === item.requestedByConversationId) : undefined;
|
|
669
|
+
const taskManager = assigned?.parentTaskId
|
|
670
|
+
? project.tasks.find(task => task.id === assigned.parentTaskId)?.ownerConversationId : project.ownerConversationId;
|
|
671
|
+
const fallback = !requester && item.requestedByConversationId === project.ownerConversationId ? project.initiatorConversationId : undefined;
|
|
672
|
+
if (!requester?.parentConversationId && !assigned && !fallback)
|
|
673
|
+
continue;
|
|
674
|
+
// Old versions let project leaders address the user while they still had a parent.
|
|
675
|
+
const parent = [requester?.parentConversationId, assigned ? taskManager : undefined, fallback]
|
|
676
|
+
.filter((id) => Boolean(id && id !== item.requestedByConversationId))
|
|
677
|
+
.map(conversation)
|
|
678
|
+
.find(candidate => candidate?.workspaceId === project.workspaceId && !candidate.archivedAt
|
|
679
|
+
&& (candidate.id === project.ownerConversationId || candidate.id === project.initiatorConversationId
|
|
680
|
+
|| project.tasks?.some(task => task.ownerConversationId === candidate.id || task.reviewerConversationId === candidate.id)));
|
|
681
|
+
item.audience = "supervisor";
|
|
682
|
+
item.targetConversationId = parent?.id;
|
|
683
|
+
if (!parent) {
|
|
684
|
+
item.status = "dismissed";
|
|
685
|
+
item.decision = "旧例外找不到可处理的直属上级,原始记录已保留。";
|
|
686
|
+
item.resolvedAt = now();
|
|
687
|
+
}
|
|
688
|
+
changed = true;
|
|
689
|
+
}
|
|
690
|
+
return changed;
|
|
691
|
+
}
|
|
655
692
|
export class Store {
|
|
656
693
|
repository;
|
|
657
694
|
state;
|
|
@@ -691,7 +728,10 @@ export class Store {
|
|
|
691
728
|
if (state.projects !== undefined && !Array.isArray(state.projects))
|
|
692
729
|
delete state.projects;
|
|
693
730
|
let migratedProjects = false;
|
|
731
|
+
const conversationsById = new Map((state.conversations ?? []).filter(Boolean).map(item => [item.id, item]));
|
|
694
732
|
for (const project of state.projects ?? []) {
|
|
733
|
+
if (normalizeProjectEscalations(project, id => conversationsById.get(id)))
|
|
734
|
+
migratedProjects = true;
|
|
695
735
|
if (String(project.status) !== "completed")
|
|
696
736
|
continue;
|
|
697
737
|
project.status = project.ownerConversationId ? "active" : "awaiting_start";
|
|
@@ -826,8 +866,10 @@ export class Store {
|
|
|
826
866
|
if (!conversation)
|
|
827
867
|
return undefined;
|
|
828
868
|
const clone = structuredClone(conversation);
|
|
829
|
-
|
|
869
|
+
const escalationAudience = this.openEscalationAudiences().get(conversation.id);
|
|
870
|
+
if (escalationAudience) {
|
|
830
871
|
clone.hasOpenEscalation = true;
|
|
872
|
+
clone.escalationAudience = escalationAudience;
|
|
831
873
|
}
|
|
832
874
|
if (this.pendingResultConversationIds().has(conversation.id)) {
|
|
833
875
|
clone.hasPendingResult = true;
|
|
@@ -869,15 +911,28 @@ export class Store {
|
|
|
869
911
|
project(projectId) { const project = this.state.projects?.find((item) => item.id === projectId); return project ? structuredClone(project) : undefined; }
|
|
870
912
|
/** Conversation IDs that currently have an unresolved escalation requested. */
|
|
871
913
|
openEscalationConversationIds() {
|
|
872
|
-
|
|
914
|
+
return new Set(this.openEscalationAudiences().keys());
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* 每条未决例外该谁拍板,按发起会话归拢。
|
|
918
|
+
*
|
|
919
|
+
* `supervisor` = 团队内部的事(会话在等自己的直属上级),`boss` = 到了顶层。
|
|
920
|
+
* 一个会话同时开着内部和顶层两条时,顶层那条赢:那是唯一需要用户听见的一条。
|
|
921
|
+
* 旧的子会话记录在加载时归回父会话,此处仅聚合规范化后的受众。
|
|
922
|
+
*/
|
|
923
|
+
openEscalationAudiences() {
|
|
924
|
+
const audiences = new Map();
|
|
873
925
|
for (const project of this.state.projects ?? []) {
|
|
874
926
|
for (const e of project.escalations ?? []) {
|
|
875
927
|
if ((e.status === "open" || e.status === "pending") && e.requestedByConversationId) {
|
|
876
|
-
|
|
928
|
+
const audience = e.audience ?? "boss";
|
|
929
|
+
if (audiences.get(e.requestedByConversationId) !== "boss") {
|
|
930
|
+
audiences.set(e.requestedByConversationId, audience);
|
|
931
|
+
}
|
|
877
932
|
}
|
|
878
933
|
}
|
|
879
934
|
}
|
|
880
|
-
return
|
|
935
|
+
return audiences;
|
|
881
936
|
}
|
|
882
937
|
/** Child conversation IDs whose enqueued session result is still waiting or sending on a non-archived parent. */
|
|
883
938
|
pendingResultConversationIds() {
|
|
@@ -886,7 +941,7 @@ export class Store {
|
|
|
886
941
|
if (parent.archivedAt)
|
|
887
942
|
continue;
|
|
888
943
|
for (const message of parent.messages) {
|
|
889
|
-
if (message.role !== "tool" || !message.delivery)
|
|
944
|
+
if (message.role !== "tool" || !message.delivery || message.source === "session-reminder")
|
|
890
945
|
continue;
|
|
891
946
|
const tagMatch = /^<task\b([^>]*)>/.exec(message.content);
|
|
892
947
|
if (!tagMatch)
|
|
@@ -906,6 +961,7 @@ export class Store {
|
|
|
906
961
|
if (!this.state.projects)
|
|
907
962
|
this.state.projects = [];
|
|
908
963
|
const stored = structuredClone(project);
|
|
964
|
+
normalizeProjectEscalations(stored, id => this.state.conversations.find(item => item.id === id));
|
|
909
965
|
const index = this.state.projects.findIndex((item) => item.id === stored.id);
|
|
910
966
|
if (index < 0)
|
|
911
967
|
this.state.projects.unshift(stored);
|
|
@@ -932,16 +988,16 @@ export class Store {
|
|
|
932
988
|
}
|
|
933
989
|
/** Clone only one workspace's transcripts, never unrelated workspaces or app state. */
|
|
934
990
|
conversationsForWorkspace(workspaceId) {
|
|
935
|
-
const openEscalations = this.
|
|
991
|
+
const openEscalations = this.openEscalationAudiences();
|
|
936
992
|
const pendingResults = this.pendingResultConversationIds();
|
|
937
993
|
return structuredClone(this.state.conversations.filter((item) => item.workspaceId === workspaceId && !item.warmSession)).map((c) => {
|
|
938
|
-
const
|
|
994
|
+
const escalationAudience = openEscalations.get(c.id);
|
|
939
995
|
const hasPendingResult = pendingResults.has(c.id);
|
|
940
|
-
if (!
|
|
996
|
+
if (!escalationAudience && !hasPendingResult)
|
|
941
997
|
return c;
|
|
942
998
|
return {
|
|
943
999
|
...c,
|
|
944
|
-
...(
|
|
1000
|
+
...(escalationAudience ? { hasOpenEscalation: true, escalationAudience } : {}),
|
|
945
1001
|
...(hasPendingResult ? { hasPendingResult: true } : {}),
|
|
946
1002
|
};
|
|
947
1003
|
});
|
|
@@ -1213,7 +1269,7 @@ export class Store {
|
|
|
1213
1269
|
const visible = this.state.conversations.filter((item) => !closed.has(item.workspaceId) && !item.warmSession);
|
|
1214
1270
|
const warmSessions = workspaces.flatMap((workspace) => this.listWarmSessions(workspace.id));
|
|
1215
1271
|
const presets = warmSessions.length ? { warmSessions } : {};
|
|
1216
|
-
const openEscalations = this.
|
|
1272
|
+
const openEscalations = this.openEscalationAudiences();
|
|
1217
1273
|
const pendingResults = this.pendingResultConversationIds();
|
|
1218
1274
|
// Legacy sockets still receive complete visible transcripts. Project before cloning so a closed
|
|
1219
1275
|
// workspace's retained history is never copied just to discard it afterwards.
|
|
@@ -1223,13 +1279,13 @@ export class Store {
|
|
|
1223
1279
|
...presets,
|
|
1224
1280
|
workspaces,
|
|
1225
1281
|
conversations: visible.map((c) => {
|
|
1226
|
-
const
|
|
1282
|
+
const escalationAudience = openEscalations.get(c.id);
|
|
1227
1283
|
const hasPendingResult = pendingResults.has(c.id);
|
|
1228
|
-
if (!
|
|
1284
|
+
if (!escalationAudience && !hasPendingResult)
|
|
1229
1285
|
return c;
|
|
1230
1286
|
return {
|
|
1231
1287
|
...c,
|
|
1232
|
-
...(
|
|
1288
|
+
...(escalationAudience ? { hasOpenEscalation: true, escalationAudience } : {}),
|
|
1233
1289
|
...(hasPendingResult ? { hasPendingResult: true } : {}),
|
|
1234
1290
|
};
|
|
1235
1291
|
}),
|
|
@@ -1241,7 +1297,9 @@ export class Store {
|
|
|
1241
1297
|
const selectedId = visible.find((item) => item.id === scope.conversationId)?.id;
|
|
1242
1298
|
const conversations = visible.map(({ messages, ...metadata }) => ({
|
|
1243
1299
|
...metadata,
|
|
1244
|
-
...(openEscalations.has(metadata.id)
|
|
1300
|
+
...(openEscalations.has(metadata.id)
|
|
1301
|
+
? { hasOpenEscalation: true, escalationAudience: openEscalations.get(metadata.id) }
|
|
1302
|
+
: {}),
|
|
1245
1303
|
...(pendingResults.has(metadata.id) ? { hasPendingResult: true } : {}),
|
|
1246
1304
|
messages: metadata.id === selectedId ? messages : [],
|
|
1247
1305
|
messagesLoaded: metadata.id === selectedId,
|
|
@@ -1810,10 +1868,15 @@ export class Store {
|
|
|
1810
1868
|
if (conversation.archivedAt)
|
|
1811
1869
|
throw new Error("无法向已归档的会话下发指令,请先恢复该会话");
|
|
1812
1870
|
const message = { id: id("message"), role: "tool", content, createdAt: now() };
|
|
1871
|
+
if (options?.source)
|
|
1872
|
+
message.source = options.source;
|
|
1813
1873
|
if (options?.delivery)
|
|
1814
1874
|
message.delivery = options.delivery;
|
|
1815
1875
|
conversation.messages.push(message);
|
|
1816
|
-
|
|
1876
|
+
if (message.source === "session-reminder" && !message.delivery)
|
|
1877
|
+
await this.persistIncomingTurn(conversation, message);
|
|
1878
|
+
else
|
|
1879
|
+
await this.persistMessages(conversation);
|
|
1817
1880
|
return structuredClone(message);
|
|
1818
1881
|
}
|
|
1819
1882
|
async addUserMessage(conversationId, content, images, attachments, options) {
|
|
@@ -1833,10 +1896,13 @@ export class Store {
|
|
|
1833
1896
|
conversation.messages.push(message);
|
|
1834
1897
|
// Persisted as a transcript change and nothing more: this is the honest record of "the user said this
|
|
1835
1898
|
// and nothing has picked it up yet", and a refresh has to show it in the same place it was sent from.
|
|
1836
|
-
if (message.delivery)
|
|
1899
|
+
if (message.delivery)
|
|
1837
1900
|
await this.persistMessages(conversation);
|
|
1838
|
-
|
|
1839
|
-
|
|
1901
|
+
else
|
|
1902
|
+
await this.persistIncomingTurn(conversation, message);
|
|
1903
|
+
return structuredClone(message);
|
|
1904
|
+
}
|
|
1905
|
+
async persistIncomingTurn(conversation, message) {
|
|
1840
1906
|
const firstUser = conversation.messages.find((item) => item.role === "user");
|
|
1841
1907
|
const autoTitle = firstUser?.content.trim()
|
|
1842
1908
|
? firstUser.content.slice(0, 42)
|
|
@@ -1871,8 +1937,7 @@ export class Store {
|
|
|
1871
1937
|
// changed, and the repository has an incremental path for each. The base snapshot every other
|
|
1872
1938
|
// conversation lives in is untouched by this call, so rewriting it buys nothing.
|
|
1873
1939
|
await this.persistMessages(conversation);
|
|
1874
|
-
await this.persistMetadata(
|
|
1875
|
-
return structuredClone(message);
|
|
1940
|
+
await this.persistMetadata(conversation.id);
|
|
1876
1941
|
}
|
|
1877
1942
|
/**
|
|
1878
1943
|
* Takes the browser's id for its own optimistic message, when it is safe to.
|
|
@@ -2617,6 +2682,8 @@ export class Store {
|
|
|
2617
2682
|
if (!trimmed)
|
|
2618
2683
|
throw new Error("消息不能为空");
|
|
2619
2684
|
const { conversation, message } = this.requireWaitingMessage(conversationId, messageId);
|
|
2685
|
+
if (message.source === "session-reminder")
|
|
2686
|
+
throw new Error("Agent 的定时提醒不能改字");
|
|
2620
2687
|
if (message.role === "tool")
|
|
2621
2688
|
throw new Error("后台任务结果不能改字");
|
|
2622
2689
|
if (message.delivery !== "waiting")
|
package/dist/server/types.d.ts
CHANGED
|
@@ -112,6 +112,7 @@ export type ToolCallQuestion = {
|
|
|
112
112
|
export type Message = {
|
|
113
113
|
id: string;
|
|
114
114
|
role: MessageRole;
|
|
115
|
+
source?: "session-reminder";
|
|
115
116
|
content: string;
|
|
116
117
|
createdAt: string;
|
|
117
118
|
piEntryId?: string;
|
|
@@ -595,6 +596,12 @@ export type Conversation = {
|
|
|
595
596
|
reportedToParentAt?: string;
|
|
596
597
|
/** 该会话是否存在未决的例外升级(等待上级处理)。 */
|
|
597
598
|
hasOpenEscalation?: boolean;
|
|
599
|
+
/**
|
|
600
|
+
* 这条未决例外该谁拍板:`supervisor` = 团队内部(直属上级),`boss` = 到了顶层。
|
|
601
|
+
* 与 `hasOpenEscalation` 一样是只读投影,不落盘;客户端靠它区分「内部升级」和
|
|
602
|
+
* 「真的需要用户决定的事」——只有后者才配出现在用户面前。
|
|
603
|
+
*/
|
|
604
|
+
escalationAudience?: "supervisor" | "boss";
|
|
598
605
|
/** Read-only projection: whether this child session still has an undelivered result in its parent's waiting queue. */
|
|
599
606
|
hasPendingResult?: boolean;
|
|
600
607
|
/**
|
|
@@ -39,6 +39,18 @@ export type OverviewProject = {
|
|
|
39
39
|
};
|
|
40
40
|
/** Internal coordination is not a request for the user's attention. */
|
|
41
41
|
export declare function userProjectDecisions(project: OverviewProject): OverviewDecision[];
|
|
42
|
+
/**
|
|
43
|
+
* HOW MANY PROJECTS NEED THE USER - counted by project, not by case.
|
|
44
|
+
*
|
|
45
|
+
* The notice above the project tab says "N projects need you to decide". One project with two
|
|
46
|
+
* open boss-level cases is still ONE project to decide about, and a notice that says "2 projects"
|
|
47
|
+
* above a list that shows one is simply wrong. The count therefore goes over the PROJECTS that
|
|
48
|
+
* have at least one such case, and the cases themselves are counted separately.
|
|
49
|
+
*/
|
|
50
|
+
export declare function projectsNeedingUserDecision(projects: OverviewProject[]): {
|
|
51
|
+
projects: number;
|
|
52
|
+
cases: number;
|
|
53
|
+
};
|
|
42
54
|
export declare function ownerProjectReports(project: OverviewProject): OverviewReport[];
|
|
43
55
|
export declare function latestProjectDelivery<T extends OverviewReport>(project: {
|
|
44
56
|
ownerConversationId?: string;
|
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
export function userProjectDecisions(project) {
|
|
3
3
|
return (project.escalations ?? []).filter(item => item.status === "open" && (item.audience === "boss" || item.audience === undefined));
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* HOW MANY PROJECTS NEED THE USER - counted by project, not by case.
|
|
7
|
+
*
|
|
8
|
+
* The notice above the project tab says "N projects need you to decide". One project with two
|
|
9
|
+
* open boss-level cases is still ONE project to decide about, and a notice that says "2 projects"
|
|
10
|
+
* above a list that shows one is simply wrong. The count therefore goes over the PROJECTS that
|
|
11
|
+
* have at least one such case, and the cases themselves are counted separately.
|
|
12
|
+
*/
|
|
13
|
+
export function projectsNeedingUserDecision(projects) {
|
|
14
|
+
const withCases = projects.filter(project => userProjectDecisions(project).length > 0);
|
|
15
|
+
return {
|
|
16
|
+
projects: withCases.length,
|
|
17
|
+
cases: withCases.reduce((sum, project) => sum + userProjectDecisions(project).length, 0),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
5
20
|
export function ownerProjectReports(project) {
|
|
6
21
|
return (project.reports ?? []).filter(report => !report.taskId && ["progress", "delivery"].includes(report.kind ?? "")
|
|
7
22
|
&& (report.authorConversationId === project.ownerConversationId && Boolean(project.ownerConversationId)
|
|
@@ -7,7 +7,14 @@ export type SessionReportingSnapshot = {
|
|
|
7
7
|
archivedAt?: string;
|
|
8
8
|
hasOpenEscalation?: boolean;
|
|
9
9
|
hasPendingResult?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* 谁来拍板这条未决例外:`supervisor` = 团队内部(直属上级),`boss` = 到了顶层。
|
|
12
|
+
* User-facing decisions require an explicit Boss audience on a top-level session.
|
|
13
|
+
*/
|
|
14
|
+
escalationAudience?: EscalationAudience;
|
|
10
15
|
};
|
|
16
|
+
/** 这条未决例外该谁拍板。 */
|
|
17
|
+
export type EscalationAudience = "supervisor" | "boss";
|
|
11
18
|
export type ReportingAxisState = "pending_report" | "awaiting_subordinates" | "awaiting_decision" | "unread";
|
|
12
19
|
export declare function deriveReportingState(params: {
|
|
13
20
|
conversation: SessionReportingSnapshot;
|
|
@@ -15,6 +22,13 @@ export declare function deriveReportingState(params: {
|
|
|
15
22
|
directChildren: SessionReportingSnapshot[];
|
|
16
23
|
isTopLevelUnread?: boolean;
|
|
17
24
|
}): ReportingAxisState | null;
|
|
25
|
+
/** Internal issues do not create user-visible decision or activity badges. */
|
|
26
|
+
export declare function deriveUserReportingState(params: {
|
|
27
|
+
conversation: SessionReportingSnapshot;
|
|
28
|
+
parent?: ChildSessionRow;
|
|
29
|
+
directChildren: SessionReportingSnapshot[];
|
|
30
|
+
isTopLevelUnread?: boolean;
|
|
31
|
+
}): ReportingAxisState | null;
|
|
18
32
|
export type SessionDisplayState = "waiting" | "running" | "failed" | "question" | "completed" | "unread" | "idle" | "awaiting_background" | "pending_report" | "awaiting_subordinates" | "awaiting_decision";
|
|
19
33
|
export declare const SESSION_STATE_WORD: Record<string, string>;
|
|
20
34
|
export declare function sessionStateWord(state: string | undefined): string;
|