@evandu/super-pi 0.1.184 → 0.1.186
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/coder.md +1 -1
- package/agents/planner.md +1 -1
- package/agents/project-leader.md +2 -2
- package/agents/reviewer.md +1 -1
- package/agents/super-pi-task/core.ts +164 -7
- package/agents/super-pi-task/index.ts +33 -1
- package/dist/client/.super-pi-client-sources.json +7 -7
- package/dist/client/assets/{CodeMirrorEditor-v8j7qM-5.js → CodeMirrorEditor-Cmx7-z0f.js} +2 -2
- package/dist/client/assets/{dist-DFpSLAtp.js → dist-B8CAEuXW.js} +1 -1
- package/dist/client/assets/{dist-1PSYOzSn.js → dist-BKx3CpQJ.js} +1 -1
- package/dist/client/assets/{dist-XrYkL2Xu.js → dist-BMSVWA_A.js} +1 -1
- package/dist/client/assets/{dist-BtRpNdOI.js → dist-BdiInYmk.js} +1 -1
- package/dist/client/assets/{dist-Bvl-DsMt.js → dist-Bq7p17eF.js} +1 -1
- package/dist/client/assets/{dist-CJ4rSQ4N.js → dist-BzqUlzAf.js} +1 -1
- package/dist/client/assets/{dist-DF3hHXYK.js → dist-C0PMHwdm.js} +1 -1
- package/dist/client/assets/{dist-Bc6s4uHe.js → dist-C2ltv_8u.js} +1 -1
- package/dist/client/assets/{dist-BoSFlin7.js → dist-CDSDxXju.js} +1 -1
- package/dist/client/assets/{dist-BUHFKfEO.js → dist-CKZOnuRU.js} +1 -1
- package/dist/client/assets/{dist-BS72C5ep.js → dist-CWlI6qO0.js} +1 -1
- package/dist/client/assets/{dist-cgEoGcO1.js → dist-CXDhHY7N.js} +1 -1
- package/dist/client/assets/{dist-BKj3_VBI.js → dist-Cblc22Ag.js} +1 -1
- package/dist/client/assets/{dist-DsUX6SY5.js → dist-CcuBp_Kn.js} +1 -1
- package/dist/client/assets/{dist-D-MqsRQM.js → dist-DHFt0Hvo.js} +1 -1
- package/dist/client/assets/{dist-Bcw21qWX.js → dist-D_7x3oZt.js} +1 -1
- package/dist/client/assets/{dist-CIxW4sg_.js → dist-RHYiODih.js} +1 -1
- package/dist/client/assets/{dist-Bta_JEiJ.js → dist-V27Fcf8p.js} +1 -1
- package/dist/client/assets/{dist-CvM_6f5G.js → dist-WfagMkC4.js} +1 -1
- package/dist/client/assets/{dist-CPEKtCMg.js → dist-akJoBtjs.js} +1 -1
- package/dist/client/assets/{dist-Bpfwpwk8.js → dist-frBiV55p.js} +1 -1
- package/dist/client/assets/{dist-D4SHQTo9.js → dist-ibsGPa_S.js} +1 -1
- package/dist/client/assets/{index-DeTEc54b.css → index-BXQjUHV_.css} +1 -1
- package/dist/client/assets/{index-D_XU8eXm.js → index-Dx7HAZ5j.js} +14 -13
- package/dist/client/index.html +2 -2
- package/dist/server/agents.d.ts +1 -1
- package/dist/server/agents.js +1 -1
- package/dist/server/application/conversation-service.d.ts +13 -0
- package/dist/server/application/conversation-service.js +21 -0
- package/dist/server/application/project-service.d.ts +2 -70
- package/dist/server/application/project-service.js +33 -192
- package/dist/server/application/run-service.d.ts +39 -3
- package/dist/server/application/run-service.js +166 -18
- package/dist/server/application/session-orchestrator-service.d.ts +38 -5
- package/dist/server/application/session-orchestrator-service.js +167 -5
- package/dist/server/command-handler.js +5 -1
- package/dist/server/http-server.js +45 -18
- package/dist/server/index.js +1 -1
- package/dist/server/pi-session.d.ts +3 -2
- package/dist/server/runtime.js +9 -6
- package/dist/server/session-tree-scope.d.ts +1 -1
- package/dist/server/store.d.ts +24 -0
- package/dist/server/store.js +229 -4
- package/dist/server/task-tool.d.ts +5 -2
- package/dist/server/task-tool.js +25 -2
- package/dist/server/types.d.ts +36 -13
- package/dist/server/upload.d.ts +2 -6
- package/dist/server/upload.js +7 -5
- package/dist/shared/session-reporting.d.ts +2 -0
- package/dist/shared/session-reporting.js +9 -9
- package/package.json +7 -3
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
1
|
+
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
+
import { parseMessageDeliveryMode } from "./run-service.js";
|
|
4
|
+
import { deleteConversationUploads } from "../upload.js";
|
|
3
5
|
import { capText } from "../workflow.js";
|
|
4
6
|
import { assertSessionCwdInsideWorkspace } from "../session-cwd.js";
|
|
5
7
|
import { SessionWatchdog } from "./session-watchdog.js";
|
|
@@ -28,6 +30,7 @@ export class SessionOrchestratorService {
|
|
|
28
30
|
runService;
|
|
29
31
|
ledger;
|
|
30
32
|
broadcaster;
|
|
33
|
+
uploadsDir;
|
|
31
34
|
watchdog;
|
|
32
35
|
/**
|
|
33
36
|
* HOW MANY TIMES EACH CHILD HAS BEEN TOLD TO CONTINUE AFTER A TRUNCATION.
|
|
@@ -62,12 +65,13 @@ export class SessionOrchestratorService {
|
|
|
62
65
|
* result is still its own.
|
|
63
66
|
*/
|
|
64
67
|
reportedChildren = new Map();
|
|
65
|
-
constructor(store, conversationService, runService, ledger, broadcaster, watchdog) {
|
|
68
|
+
constructor(store, conversationService, runService, ledger, broadcaster, watchdog, uploadsDir) {
|
|
66
69
|
this.store = store;
|
|
67
70
|
this.conversationService = conversationService;
|
|
68
71
|
this.runService = runService;
|
|
69
72
|
this.ledger = ledger;
|
|
70
73
|
this.broadcaster = broadcaster;
|
|
74
|
+
this.uploadsDir = uploadsDir;
|
|
71
75
|
this.watchdog = watchdog ?? new SessionWatchdog({
|
|
72
76
|
onTimeout: async (event) => {
|
|
73
77
|
await this.handleWatchdogTimeout(event);
|
|
@@ -181,6 +185,10 @@ export class SessionOrchestratorService {
|
|
|
181
185
|
* By default dispatches asynchronously so the orchestrator caller is not blocked.
|
|
182
186
|
*/
|
|
183
187
|
async dispatch(conversationId, content, options) {
|
|
188
|
+
const mode = parseMessageDeliveryMode(options?.mode);
|
|
189
|
+
if (!content.trim()) {
|
|
190
|
+
throw new Error("dispatch requires non-empty content");
|
|
191
|
+
}
|
|
184
192
|
const conversation = this.store.conversation(conversationId);
|
|
185
193
|
if (!conversation) {
|
|
186
194
|
throw new Error(`找不到会话:${conversationId}`);
|
|
@@ -197,7 +205,19 @@ export class SessionOrchestratorService {
|
|
|
197
205
|
// turn?" is answered by comparing the report's time against it. A report made inside the turn
|
|
198
206
|
// speaks for the turn; a report made before it speaks for an earlier one.
|
|
199
207
|
const turnStartedAt = Date.now();
|
|
200
|
-
|
|
208
|
+
let acceptedMessageId;
|
|
209
|
+
let resolveAccepted;
|
|
210
|
+
const acceptedPromise = new Promise((resolve) => {
|
|
211
|
+
resolveAccepted = resolve;
|
|
212
|
+
});
|
|
213
|
+
const runPromise = this.runService.enqueueAndRunAsAgent(conversationId, content, {
|
|
214
|
+
mode,
|
|
215
|
+
onAccepted: (messageId) => {
|
|
216
|
+
acceptedMessageId = messageId;
|
|
217
|
+
resolveAccepted?.(messageId);
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
void runPromise.then(() => { resolveAccepted?.(acceptedMessageId ?? ""); }, () => { resolveAccepted?.(acceptedMessageId ?? ""); });
|
|
201
221
|
const completion = (async () => {
|
|
202
222
|
let failure;
|
|
203
223
|
try {
|
|
@@ -299,9 +319,11 @@ export class SessionOrchestratorService {
|
|
|
299
319
|
})();
|
|
300
320
|
if (options?.wait)
|
|
301
321
|
await completion;
|
|
302
|
-
else
|
|
322
|
+
else {
|
|
303
323
|
void completion.catch(() => undefined);
|
|
304
|
-
|
|
324
|
+
await acceptedPromise;
|
|
325
|
+
}
|
|
326
|
+
return { conversationId, ...(acceptedMessageId ? { messageId: acceptedMessageId } : {}), mode };
|
|
305
327
|
}
|
|
306
328
|
/**
|
|
307
329
|
* THE CHILD'S OUTPUT WAS CUT OFF. TELL IT TO CARRY ON, AND LET IT.
|
|
@@ -565,6 +587,15 @@ export class SessionOrchestratorService {
|
|
|
565
587
|
...(conversation.error ? { error: conversation.error } : {}),
|
|
566
588
|
});
|
|
567
589
|
}
|
|
590
|
+
const waiting = this.store.listWaitingMessages(conversationId);
|
|
591
|
+
const queuedMessages = waiting.length > 0
|
|
592
|
+
? waiting.map((item) => ({
|
|
593
|
+
id: item.id,
|
|
594
|
+
delivery: item.delivery === "sending" ? "sending" : "waiting",
|
|
595
|
+
role: item.role === "tool" ? "tool" : "user",
|
|
596
|
+
snippet: item.content.replace(/\s+/g, " ").trim().slice(0, 120),
|
|
597
|
+
}))
|
|
598
|
+
: undefined;
|
|
568
599
|
return {
|
|
569
600
|
conversationId: conversation.id,
|
|
570
601
|
workspaceId: conversation.workspaceId,
|
|
@@ -583,6 +614,7 @@ export class SessionOrchestratorService {
|
|
|
583
614
|
updatedAt: conversation.updatedAt,
|
|
584
615
|
createdAt: ledgerEntry?.createdAt ?? (conversation.messages?.[0]?.createdAt ? new Date(conversation.messages[0].createdAt).getTime() : (conversation.updatedAt ? new Date(conversation.updatedAt).getTime() : Date.now())),
|
|
585
616
|
lastProgress: finalProgress,
|
|
617
|
+
...(queuedMessages ? { queuedMessages } : {}),
|
|
586
618
|
...(options?.includeOutput ? { outputPath: resultPath } : {}),
|
|
587
619
|
...(output !== undefined ? { output, outputTruncated } : {}),
|
|
588
620
|
};
|
|
@@ -637,6 +669,15 @@ export class SessionOrchestratorService {
|
|
|
637
669
|
const parentConv = targetParentId ? this.store.conversation(targetParentId) : undefined;
|
|
638
670
|
const summaries = [];
|
|
639
671
|
for (const conversationId of candidateIds) {
|
|
672
|
+
const conv = this.store.conversation(conversationId);
|
|
673
|
+
if (!conv) {
|
|
674
|
+
// Conversation was removed from store; prune ledger
|
|
675
|
+
this.ledger.delete(conversationId);
|
|
676
|
+
continue;
|
|
677
|
+
}
|
|
678
|
+
if (conv.archivedAt) {
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
640
681
|
try {
|
|
641
682
|
const summary = await this.status(conversationId);
|
|
642
683
|
// Workspace boundary enforcement: do not leak sessions across different workspaces
|
|
@@ -669,6 +710,29 @@ export class SessionOrchestratorService {
|
|
|
669
710
|
if (!conversation) {
|
|
670
711
|
throw new Error(`找不到会话:${conversationId}`);
|
|
671
712
|
}
|
|
713
|
+
if (options?.messageIds !== undefined) {
|
|
714
|
+
if (options.messageId) {
|
|
715
|
+
throw new Error("不能同时传入 messageId 和 messageIds。");
|
|
716
|
+
}
|
|
717
|
+
if (!Array.isArray(options.messageIds) || options.messageIds.length === 0) {
|
|
718
|
+
throw new Error("messageIds 必须是非空字符串数组。");
|
|
719
|
+
}
|
|
720
|
+
for (const rawId of options.messageIds) {
|
|
721
|
+
if (typeof rawId !== "string" || !rawId.trim()) {
|
|
722
|
+
throw new Error("messageIds 中的每一项都必须是非空消息 ID。");
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
const { withdrawn, missingIds } = await this.runService.cancelQueuedMany(conversationId, options.messageIds, { actor: "agent" });
|
|
726
|
+
if (withdrawn.length === 0) {
|
|
727
|
+
throw new Error("指定的排队消息不存在、已发送或已被撤回。");
|
|
728
|
+
}
|
|
729
|
+
return {
|
|
730
|
+
stopped: false,
|
|
731
|
+
mode: "queued-withdraw",
|
|
732
|
+
withdrawn,
|
|
733
|
+
...(missingIds.length > 0 ? { missingIds } : {}),
|
|
734
|
+
};
|
|
735
|
+
}
|
|
672
736
|
let mode = options?.mode ?? "all";
|
|
673
737
|
if (options?.messageId) {
|
|
674
738
|
await this.runService.interruptQueued(conversationId, options.messageId);
|
|
@@ -787,6 +851,104 @@ export class SessionOrchestratorService {
|
|
|
787
851
|
descendantCount: descendants.length,
|
|
788
852
|
};
|
|
789
853
|
}
|
|
854
|
+
/**
|
|
855
|
+
* Permanently destroys a direct child session and its entire descendant subtree (stopping any
|
|
856
|
+
* running/queued turns first) and removes all transcripts, outputs, runs, and auxiliary state.
|
|
857
|
+
*/
|
|
858
|
+
async remove(conversationId, options) {
|
|
859
|
+
const reason = options?.reason?.trim() || undefined;
|
|
860
|
+
const conversation = this.store.conversation(conversationId);
|
|
861
|
+
if (!conversation) {
|
|
862
|
+
this.ledger.delete(conversationId);
|
|
863
|
+
this.reportedChildren.delete(conversationId);
|
|
864
|
+
await this.watchdog.cancel(conversationId);
|
|
865
|
+
return {
|
|
866
|
+
removed: false,
|
|
867
|
+
alreadyRemoved: true,
|
|
868
|
+
conversationId,
|
|
869
|
+
destroyedIds: [],
|
|
870
|
+
stoppedFirst: false,
|
|
871
|
+
...(reason ? { reason } : {}),
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
if (!conversation.parentConversationId) {
|
|
875
|
+
throw new Error("顶层会话不能销毁,只能由用户归档。");
|
|
876
|
+
}
|
|
877
|
+
const descendants = this.descendantsOf(conversationId);
|
|
878
|
+
const subtreeIdsDeepestFirst = [...descendants.reverse(), conversationId];
|
|
879
|
+
let stoppedFirst = false;
|
|
880
|
+
for (const id of subtreeIdsDeepestFirst) {
|
|
881
|
+
const target = this.store.conversation(id);
|
|
882
|
+
if (!target)
|
|
883
|
+
continue;
|
|
884
|
+
const waiting = this.store.listWaitingMessages(id);
|
|
885
|
+
const isActive = target.status === "running" ||
|
|
886
|
+
target.status === "waiting" ||
|
|
887
|
+
target.status === "awaiting_background" ||
|
|
888
|
+
Boolean(this.runService.isRunning?.(id)) ||
|
|
889
|
+
waiting.length > 0;
|
|
890
|
+
if (isActive) {
|
|
891
|
+
await this.stop(id, { mode: "all" });
|
|
892
|
+
stoppedFirst = true;
|
|
893
|
+
}
|
|
894
|
+
else {
|
|
895
|
+
await this.watchdog.cancel(id);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
for (const id of subtreeIdsDeepestFirst) {
|
|
899
|
+
const afterStop = this.store.conversation(id);
|
|
900
|
+
if (!afterStop)
|
|
901
|
+
continue;
|
|
902
|
+
if (afterStop.status === "running" ||
|
|
903
|
+
afterStop.status === "awaiting_background" ||
|
|
904
|
+
Boolean(this.runService.isRunning?.(id))) {
|
|
905
|
+
throw new Error("目标会话或其下属会话仍在运行且未能停止,无法销毁。");
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
for (const id of subtreeIdsDeepestFirst) {
|
|
909
|
+
this.runService.reviewMemoryBoundary?.(id);
|
|
910
|
+
await this.conversationService.prepareDestroyConversation?.(id);
|
|
911
|
+
}
|
|
912
|
+
const { destroyed } = await this.store.deleteConversationSubtree(conversationId);
|
|
913
|
+
if (destroyed.length === 0) {
|
|
914
|
+
return {
|
|
915
|
+
removed: false,
|
|
916
|
+
alreadyRemoved: true,
|
|
917
|
+
conversationId,
|
|
918
|
+
title: conversation.title,
|
|
919
|
+
destroyedIds: [],
|
|
920
|
+
stoppedFirst,
|
|
921
|
+
...(reason ? { reason } : {}),
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
const remainingSessionFiles = new Set(this.store.snapshot().conversations.map((item) => item.piSessionFile).filter((file) => Boolean(file)));
|
|
925
|
+
for (const item of destroyed) {
|
|
926
|
+
this.ledger.delete(item.id);
|
|
927
|
+
this.reportedChildren.delete(item.id);
|
|
928
|
+
await this.watchdog.cancel(item.id);
|
|
929
|
+
const workspace = this.store.workspace(item.workspaceId);
|
|
930
|
+
if (workspace) {
|
|
931
|
+
await rm(join(workspace.path, ".super-pi", "session-results", `${item.id}.md`), { force: true }).catch(() => { });
|
|
932
|
+
}
|
|
933
|
+
if (item.piSessionFile && !remainingSessionFiles.has(item.piSessionFile)) {
|
|
934
|
+
await rm(item.piSessionFile, { force: true }).catch(() => { });
|
|
935
|
+
}
|
|
936
|
+
if (this.uploadsDir) {
|
|
937
|
+
await deleteConversationUploads(this.uploadsDir, item.id).catch(() => { });
|
|
938
|
+
}
|
|
939
|
+
await this.conversationService.cleanupDestroyedConversation?.(item);
|
|
940
|
+
}
|
|
941
|
+
this.broadcaster?.broadcastState();
|
|
942
|
+
return {
|
|
943
|
+
removed: true,
|
|
944
|
+
alreadyRemoved: false,
|
|
945
|
+
conversationId,
|
|
946
|
+
title: conversation.title,
|
|
947
|
+
destroyedIds: destroyed.map((item) => item.id),
|
|
948
|
+
stoppedFirst,
|
|
949
|
+
...(reason ? { reason } : {}),
|
|
950
|
+
};
|
|
951
|
+
}
|
|
790
952
|
/**
|
|
791
953
|
* Resumes execution in a conversation.
|
|
792
954
|
* If prompt is provided, sends it as a new turn.
|
|
@@ -273,7 +273,7 @@ export class CommandHandler {
|
|
|
273
273
|
// attachment lost it on arrival - the browser drew the attachment, the transcript never had it, and
|
|
274
274
|
// the model was handed the bare prompt. Forwarded now because this is the one line that carries
|
|
275
275
|
// every field of the send.
|
|
276
|
-
await this.runService.enqueueAndRun(command.conversationId, command.content, command.images, command.attachments, command.clientId);
|
|
276
|
+
await this.runService.enqueueAndRun(command.conversationId, command.content, command.images, command.attachments, command.clientId, command.mode);
|
|
277
277
|
return;
|
|
278
278
|
}
|
|
279
279
|
if (command.type === "message.steer") {
|
|
@@ -292,6 +292,10 @@ export class CommandHandler {
|
|
|
292
292
|
await this.runService.cancelQueued(command.conversationId, command.messageId);
|
|
293
293
|
return;
|
|
294
294
|
}
|
|
295
|
+
if (command.type === "message.cancelMany") {
|
|
296
|
+
await this.runService.cancelQueuedMany(command.conversationId, command.messageIds, { actor: "user" });
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
295
299
|
if (command.type === "message.edit") {
|
|
296
300
|
await this.runService.editQueued(command.conversationId, command.messageId, command.content);
|
|
297
301
|
return;
|
|
@@ -18,6 +18,7 @@ import { conversationWorkspace } from "./model-filter.js";
|
|
|
18
18
|
import { describeSchedule } from "./scheduled-tasks.js";
|
|
19
19
|
import { MAX_KNOWLEDGE_REQUEST_BYTES } from "./knowledge.js";
|
|
20
20
|
import { MAX_DOCUMENT_REQUEST_BYTES } from "./application/document-service.js";
|
|
21
|
+
import { parseMessageDeliveryMode } from "./application/run-service.js";
|
|
21
22
|
import { MAX_FEISHU_REQUEST_BYTES } from "./application/feishu-service.js";
|
|
22
23
|
import { MAX_WEB_REQUEST_BYTES } from "./web.js";
|
|
23
24
|
import { MAX_TOOL_BODY_BYTES } from "./tool-registry.js";
|
|
@@ -315,7 +316,7 @@ export function createHttpServer(options) {
|
|
|
315
316
|
// the endpoint that can spend it is exactly the one an agent's own turn can reach, and the
|
|
316
317
|
// management half (`/api/feishu/config`) stays behind the ordinary token AND the local-address
|
|
317
318
|
// predicate.
|
|
318
|
-
if (requestPath !== "/api/conversation/usage" && requestPath !== "/api/memory/tool" && requestPath !== "/api/knowledge/tool" && requestPath !== "/api/documents/tool" && requestPath !== "/api/web/tool" && requestPath !== "/api/feishu/tool" && requestPath !== "/api/todos" && requestPath !== "/api/scheduled-tasks" && requestPath !== "/api/projects/tool" && requestPath !== "/api/question" && (requestPath !== "/api/tools" || request.method !== "POST") && !requestPath.startsWith("/tools/") && !isAuthorized(request, accessToken)) {
|
|
319
|
+
if (requestPath !== "/api/conversations" && requestPath !== "/api/conversation/usage" && requestPath !== "/api/memory/tool" && requestPath !== "/api/knowledge/tool" && requestPath !== "/api/documents/tool" && requestPath !== "/api/web/tool" && requestPath !== "/api/feishu/tool" && requestPath !== "/api/todos" && requestPath !== "/api/scheduled-tasks" && requestPath !== "/api/projects/tool" && requestPath !== "/api/question" && (requestPath !== "/api/tools" || request.method !== "POST") && !requestPath.startsWith("/tools/") && !isAuthorized(request, accessToken)) {
|
|
319
320
|
response.writeHead(401, { "www-authenticate": "Bearer" }).end("Authentication required");
|
|
320
321
|
return;
|
|
321
322
|
}
|
|
@@ -1668,20 +1669,6 @@ export function createHttpServer(options) {
|
|
|
1668
1669
|
json(200, { project });
|
|
1669
1670
|
return;
|
|
1670
1671
|
}
|
|
1671
|
-
if (request.method === "PATCH" && subresource === "budget") {
|
|
1672
|
-
const project = await service.updateBudget(projectId, body, workspaceId);
|
|
1673
|
-
broadcaster.broadcastState();
|
|
1674
|
-
json(200, { project });
|
|
1675
|
-
return;
|
|
1676
|
-
}
|
|
1677
|
-
// ONE CLICK: RAISE THE BUDGET AND CONTINUE. The server computes the new cap, closes the
|
|
1678
|
-
// budget exception and wakes the leader - the client sends no number of its own.
|
|
1679
|
-
if (request.method === "POST" && subresource === "budget" && parts[2] === "continue") {
|
|
1680
|
-
const result = await service.raiseBudgetAndContinue(projectId, workspaceId, callerConversationId);
|
|
1681
|
-
broadcaster.broadcastState();
|
|
1682
|
-
json(200, result);
|
|
1683
|
-
return;
|
|
1684
|
-
}
|
|
1685
1672
|
if (request.method === "POST" && subresource === "tasks" && parts[2] && parts[3] === "dispatch") {
|
|
1686
1673
|
const task = await service.dispatchTask(projectId, parts[2], workspaceId);
|
|
1687
1674
|
broadcaster.broadcastState();
|
|
@@ -1856,12 +1843,13 @@ export function createHttpServer(options) {
|
|
|
1856
1843
|
throw new Error("dispatch requires conversationId");
|
|
1857
1844
|
if (!body.content)
|
|
1858
1845
|
throw new Error("dispatch requires content");
|
|
1846
|
+
const deliveryMode = parseMessageDeliveryMode(body.mode);
|
|
1859
1847
|
const scope = verifyTargetScope(body.conversationId, "调度");
|
|
1860
1848
|
if (!scope.ok) {
|
|
1861
1849
|
json(scope.status, { error: scope.error });
|
|
1862
1850
|
return;
|
|
1863
1851
|
}
|
|
1864
|
-
const result = await service.dispatch(body.conversationId, body.content, { wait: body.wait });
|
|
1852
|
+
const result = await service.dispatch(body.conversationId, body.content, { wait: body.wait, mode: deliveryMode });
|
|
1865
1853
|
json(200, { ok: true, ...result });
|
|
1866
1854
|
return;
|
|
1867
1855
|
}
|
|
@@ -1906,7 +1894,11 @@ export function createHttpServer(options) {
|
|
|
1906
1894
|
json(scope.status, { error: scope.error });
|
|
1907
1895
|
return;
|
|
1908
1896
|
}
|
|
1909
|
-
const result = await service.stop(body.conversationId, {
|
|
1897
|
+
const result = await service.stop(body.conversationId, {
|
|
1898
|
+
mode: body.mode,
|
|
1899
|
+
messageId: body.messageId,
|
|
1900
|
+
messageIds: body.messageIds,
|
|
1901
|
+
});
|
|
1910
1902
|
json(200, { ok: true, ...result });
|
|
1911
1903
|
return;
|
|
1912
1904
|
}
|
|
@@ -1925,6 +1917,24 @@ export function createHttpServer(options) {
|
|
|
1925
1917
|
json(200, { ok: true, ...result });
|
|
1926
1918
|
return;
|
|
1927
1919
|
}
|
|
1920
|
+
if (action === "remove") {
|
|
1921
|
+
if (!body.conversationId)
|
|
1922
|
+
throw new Error("remove requires conversationId");
|
|
1923
|
+
// Already-absent targets resolve idempotently via service.remove; existing targets must
|
|
1924
|
+
// still pass the direct-child scope check so top-level, self, or unrelated sessions fail.
|
|
1925
|
+
if (context.store.conversation(body.conversationId)) {
|
|
1926
|
+
const scope = verifyTargetScope(body.conversationId, "移出");
|
|
1927
|
+
if (!scope.ok) {
|
|
1928
|
+
json(scope.status, { error: scope.error });
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
const result = await service.remove(body.conversationId, {
|
|
1933
|
+
reason: typeof body.reason === "string" ? body.reason : undefined,
|
|
1934
|
+
});
|
|
1935
|
+
json(200, { ok: true, ...result });
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1928
1938
|
if (action === "resume") {
|
|
1929
1939
|
if (!body.conversationId)
|
|
1930
1940
|
throw new Error("resume requires conversationId");
|
|
@@ -2040,11 +2050,15 @@ export function createHttpServer(options) {
|
|
|
2040
2050
|
json(400, { error: "缺少 conversationId" });
|
|
2041
2051
|
return;
|
|
2042
2052
|
}
|
|
2053
|
+
if (body.subtree && body.messageIds !== undefined) {
|
|
2054
|
+
json(400, { error: "stopSubtree 不支持按 messageIds 撤回单会话队列消息" });
|
|
2055
|
+
return;
|
|
2056
|
+
}
|
|
2043
2057
|
// THE TREE GOES WITH THE ROOT WHEN THE PERSON ASKS FOR THE TREE. Stopping one session and
|
|
2044
2058
|
// stopping its whole branch are two different intentions, and the person says which.
|
|
2045
2059
|
const result = body.subtree
|
|
2046
2060
|
? await service.stopSubtree(conversationId, { mode: body.mode, messageId: body.messageId })
|
|
2047
|
-
: await service.stop(conversationId, { mode: body.mode, messageId: body.messageId });
|
|
2061
|
+
: await service.stop(conversationId, { mode: body.mode, messageId: body.messageId, messageIds: body.messageIds });
|
|
2048
2062
|
json(200, { ok: true, ...result });
|
|
2049
2063
|
}
|
|
2050
2064
|
catch (error) {
|
|
@@ -2052,6 +2066,19 @@ export function createHttpServer(options) {
|
|
|
2052
2066
|
}
|
|
2053
2067
|
return;
|
|
2054
2068
|
}
|
|
2069
|
+
if (url.pathname === "/api/conversations") {
|
|
2070
|
+
const json = (status, payload) => {
|
|
2071
|
+
response.writeHead(status, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" }).end(JSON.stringify(payload));
|
|
2072
|
+
};
|
|
2073
|
+
if (request.method !== "GET") {
|
|
2074
|
+
json(405, { error: "仅支持 GET 请求。" });
|
|
2075
|
+
return;
|
|
2076
|
+
}
|
|
2077
|
+
const workspaceId = url.searchParams.get("workspaceId");
|
|
2078
|
+
const conversations = workspaceId ? store.conversationsForWorkspace(workspaceId) : store.clientState().conversations;
|
|
2079
|
+
json(200, { conversations });
|
|
2080
|
+
return;
|
|
2081
|
+
}
|
|
2055
2082
|
if (url.pathname === "/api/conversation/usage") {
|
|
2056
2083
|
const json = (status, payload) => {
|
|
2057
2084
|
response.writeHead(status, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" }).end(JSON.stringify(payload));
|
package/dist/server/index.js
CHANGED
|
@@ -309,7 +309,7 @@ runService.setExecService(execService);
|
|
|
309
309
|
*/
|
|
310
310
|
const scheduledTaskService = new ScheduledTaskService(store, runService, conversationService, broadcaster);
|
|
311
311
|
const sessionLedger = new SessionLedger();
|
|
312
|
-
const sessionOrchestratorService = new SessionOrchestratorService(store, conversationService, runService, sessionLedger, broadcaster);
|
|
312
|
+
const sessionOrchestratorService = new SessionOrchestratorService(store, conversationService, runService, sessionLedger, broadcaster, undefined, uploadsDir);
|
|
313
313
|
/**
|
|
314
314
|
* THE PROJECT SERVICE IS TOLD HOW TO ASK WHAT AN AGENT IS.
|
|
315
315
|
*
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* the transcript on disk while the live session still holds the old context in memory, and nothing in Pi
|
|
24
24
|
* would notice the difference.
|
|
25
25
|
*/
|
|
26
|
+
import type { PiImageContent } from "./types.js";
|
|
26
27
|
/**
|
|
27
28
|
* The Pi SDK, imported lazily.
|
|
28
29
|
*
|
|
@@ -280,7 +281,7 @@ export declare function withIsolatedSessionEnv<T>(values: Record<string, string>
|
|
|
280
281
|
export interface PiSessionLike {
|
|
281
282
|
/** Runs one turn. Resolves when the agent settles. */
|
|
282
283
|
prompt(message: string, options?: {
|
|
283
|
-
images?:
|
|
284
|
+
images?: PiImageContent[];
|
|
284
285
|
streamingBehavior?: "steer" | "followUp";
|
|
285
286
|
preflightResult?: (success: boolean) => void;
|
|
286
287
|
}): Promise<void>;
|
|
@@ -298,7 +299,7 @@ export interface PiSessionLike {
|
|
|
298
299
|
* Optional because a test double has no queues; its absence means "this session cannot hold a
|
|
299
300
|
* message for later", and the caller falls back to answering it as a turn of its own.
|
|
300
301
|
*/
|
|
301
|
-
followUp?(message: string, images?:
|
|
302
|
+
followUp?(message: string, images?: PiImageContent[]): Promise<"queued" | "handled">;
|
|
302
303
|
sendCustomMessage?(message: {
|
|
303
304
|
customType: string;
|
|
304
305
|
content: unknown;
|
package/dist/server/runtime.js
CHANGED
|
@@ -24,7 +24,7 @@ import { LengthExceededError } from "./turn-failure.js";
|
|
|
24
24
|
// paths recognise a delivery identically. Re-exported because they were part of this module's surface.
|
|
25
25
|
export { describeDeliveredUserMessage, describePiQueue } from "./pi-session-events.js";
|
|
26
26
|
import { createPiSession, createSdkCatalog, piSdkAvailable, resolveTranscriptFile, superPiExtensionPaths } from "./pi-session.js";
|
|
27
|
-
import { TASK_CONVERSATION_ENV, PARENT_CONVERSATION_ENV, TASK_DEPTH_ENV, TASK_ENDPOINT_ENV, TASK_EXEC_ENDPOINT_ENV, TASK_ROSTER_ENV, TASK_TOOL_NAME, TODO_ENDPOINT_ENV, TODO_TOOL_NAME, PROJECT_TOOL_NAME, PROJECT_ENDPOINT_ENV, SCHEDULED_TASK_ENDPOINT_ENV, SCHEDULED_TASK_TOOL_NAME, WORKFLOW_ENDPOINT_ENV, WORKFLOW_TOOL_NAME, RUN_ASYNC_TOOL_NAME, ORCHESTRATOR_ENDPOINT_ENV, ORCHESTRATOR_WORKSPACE_ENV, SESSION_SPAWN_TOOL_NAME, SESSION_STATUS_TOOL_NAME, SESSION_DISPATCH_TOOL_NAME, SESSION_STOP_TOOL_NAME, SESSION_REPORT_TOOL_NAME, SESSION_STOP_SUBTREE_TOOL_NAME, rosterPayload, } from "./task-tool.js";
|
|
27
|
+
import { TASK_CONVERSATION_ENV, PARENT_CONVERSATION_ENV, TASK_DEPTH_ENV, TASK_ENDPOINT_ENV, TASK_EXEC_ENDPOINT_ENV, TASK_ROSTER_ENV, TASK_TOOL_NAME, TODO_ENDPOINT_ENV, TODO_TOOL_NAME, PROJECT_TOOL_NAME, PROJECT_ENDPOINT_ENV, SCHEDULED_TASK_ENDPOINT_ENV, SCHEDULED_TASK_TOOL_NAME, WORKFLOW_ENDPOINT_ENV, WORKFLOW_TOOL_NAME, RUN_ASYNC_TOOL_NAME, ORCHESTRATOR_ENDPOINT_ENV, ORCHESTRATOR_WORKSPACE_ENV, SESSION_SPAWN_TOOL_NAME, SESSION_STATUS_TOOL_NAME, SESSION_DISPATCH_TOOL_NAME, SESSION_STOP_TOOL_NAME, SESSION_REPORT_TOOL_NAME, SESSION_STOP_SUBTREE_TOOL_NAME, SESSION_REMOVE_TOOL_NAME, rosterPayload, } from "./task-tool.js";
|
|
28
28
|
import { BLOCKING_UI_METHODS, EXTENSION_UI_METHODS, } from "./types.js";
|
|
29
29
|
import { loadConversationImages } from "./upload.js";
|
|
30
30
|
import { describeToolCall, describeToolCallArgs, describeToolCallInProgress, extractPartialResultText, extractToolResultText, readQuestionCall } from "./tool-calls.js";
|
|
@@ -966,8 +966,11 @@ export class PiRpcRuntime {
|
|
|
966
966
|
const finished = (async () => {
|
|
967
967
|
try {
|
|
968
968
|
let promptAccepted = false;
|
|
969
|
+
const imagePayloads = this.options.uploadsDir && images?.length
|
|
970
|
+
? await loadConversationImages(this.options.uploadsDir, conversation.id, images)
|
|
971
|
+
: undefined;
|
|
969
972
|
const promptOptions = {
|
|
970
|
-
...(
|
|
973
|
+
...(imagePayloads?.length ? { images: imagePayloads } : {}),
|
|
971
974
|
preflightResult: (success) => {
|
|
972
975
|
if (!success)
|
|
973
976
|
return;
|
|
@@ -1263,7 +1266,7 @@ export class PiRpcRuntime {
|
|
|
1263
1266
|
if (this.options.orchestratorEndpoint)
|
|
1264
1267
|
names.push(PROJECT_TOOL_NAME);
|
|
1265
1268
|
if (this.options.orchestratorEndpoint)
|
|
1266
|
-
names.push(SESSION_SPAWN_TOOL_NAME, SESSION_STATUS_TOOL_NAME, SESSION_DISPATCH_TOOL_NAME, SESSION_STOP_TOOL_NAME, SESSION_REPORT_TOOL_NAME, SESSION_STOP_SUBTREE_TOOL_NAME);
|
|
1269
|
+
names.push(SESSION_SPAWN_TOOL_NAME, SESSION_STATUS_TOOL_NAME, SESSION_DISPATCH_TOOL_NAME, SESSION_STOP_TOOL_NAME, SESSION_REPORT_TOOL_NAME, SESSION_STOP_SUBTREE_TOOL_NAME, SESSION_REMOVE_TOOL_NAME);
|
|
1267
1270
|
return names;
|
|
1268
1271
|
}
|
|
1269
1272
|
/**
|
|
@@ -1482,7 +1485,7 @@ export class PiRpcRuntime {
|
|
|
1482
1485
|
// allowlist and naming a tool Pi has not registered would change the spawn line for every other
|
|
1483
1486
|
// mode. The prompt asks for a bare JSON array and nothing else; if the model spends a turn on a
|
|
1484
1487
|
// tool call anyway the reranker times out and falls back to the lexical order.
|
|
1485
|
-
const agentArgs = memoryReview ? ["--no-extensions", "--no-skills", "--no-mcp", "--no-context-files", "--no-prompt-templates", "--tools", "memory,skill_manage,session_search"] : knowledgeRerank ? ["--no-extensions", "--no-skills", "--no-mcp", "--no-context-files", "--no-prompt-templates"] : await agentSpawnArgs(this.agents.promptDir, agent, { extraAllowedTools: [...(extensionArgs.length ? [TASK_TOOL_NAME, TODO_TOOL_NAME, PROJECT_TOOL_NAME, WORKFLOW_TOOL_NAME, RUN_ASYNC_TOOL_NAME, SCHEDULED_TASK_TOOL_NAME, "question", "tool_register", ...(this.options.orchestratorEndpoint ? [SESSION_SPAWN_TOOL_NAME, SESSION_STATUS_TOOL_NAME, SESSION_DISPATCH_TOOL_NAME, SESSION_STOP_TOOL_NAME, SESSION_REPORT_TOOL_NAME, SESSION_STOP_SUBTREE_TOOL_NAME] : [])] : []), ...(memoryEnabled ? ["memory", "skill_manage", "session_search"] : []), ...(knowledgeEnabled ? [KNOWLEDGE_TOOL_NAME, KNOWLEDGE_IMPORT_TOOL_NAME] : []), ...(documentsEnabled ? [DOCUMENT_READ_TOOL_NAME, DOCUMENT_WRITE_TOOL_NAME] : []), ...(webEnabled ? [WEB_SEARCH_TOOL_NAME, WEB_FETCH_TOOL_NAME] : []), ...(feishuEnabled ? [FEISHU_READ_TOOL_NAME, FEISHU_WRITE_TOOL_NAME] : [])] });
|
|
1488
|
+
const agentArgs = memoryReview ? ["--no-extensions", "--no-skills", "--no-mcp", "--no-context-files", "--no-prompt-templates", "--tools", "memory,skill_manage,session_search"] : knowledgeRerank ? ["--no-extensions", "--no-skills", "--no-mcp", "--no-context-files", "--no-prompt-templates"] : await agentSpawnArgs(this.agents.promptDir, agent, { extraAllowedTools: [...(extensionArgs.length ? [TASK_TOOL_NAME, TODO_TOOL_NAME, PROJECT_TOOL_NAME, WORKFLOW_TOOL_NAME, RUN_ASYNC_TOOL_NAME, SCHEDULED_TASK_TOOL_NAME, "question", "tool_register", ...(this.options.orchestratorEndpoint ? [SESSION_SPAWN_TOOL_NAME, SESSION_STATUS_TOOL_NAME, SESSION_DISPATCH_TOOL_NAME, SESSION_STOP_TOOL_NAME, SESSION_REPORT_TOOL_NAME, SESSION_STOP_SUBTREE_TOOL_NAME, SESSION_REMOVE_TOOL_NAME] : [])] : []), ...(memoryEnabled ? ["memory", "skill_manage", "session_search"] : []), ...(knowledgeEnabled ? [KNOWLEDGE_TOOL_NAME, KNOWLEDGE_IMPORT_TOOL_NAME] : []), ...(documentsEnabled ? [DOCUMENT_READ_TOOL_NAME, DOCUMENT_WRITE_TOOL_NAME] : []), ...(webEnabled ? [WEB_SEARCH_TOOL_NAME, WEB_FETCH_TOOL_NAME] : []), ...(feishuEnabled ? [FEISHU_READ_TOOL_NAME, FEISHU_WRITE_TOOL_NAME] : [])] });
|
|
1486
1489
|
// Refused here, with the reason, rather than handed to the spawn: an ENOENT from `spawn` reads as
|
|
1487
1490
|
// "the app is broken" and hides the one fact that matters, which is where it looked for Pi.
|
|
1488
1491
|
if (!this.pi.found)
|
|
@@ -2569,7 +2572,7 @@ export class PiRpcRuntime {
|
|
|
2569
2572
|
: undefined;
|
|
2570
2573
|
if (!session.followUp)
|
|
2571
2574
|
throw new SteerUnavailableError(`会话 ${conversationId} 的 Pi 不支持排队消息`);
|
|
2572
|
-
const disposition = await session.followUp(message, imagePayloads);
|
|
2575
|
+
const disposition = await session.followUp(message, imagePayloads?.length ? imagePayloads : undefined);
|
|
2573
2576
|
return disposition === "handled" ? "handled" : "queued";
|
|
2574
2577
|
}
|
|
2575
2578
|
// NO TURN TO FOLLOW. A follow-up is only meaningful while something is running - with nothing
|
|
@@ -2639,7 +2642,7 @@ export class PiRpcRuntime {
|
|
|
2639
2642
|
? await loadConversationImages(this.options.uploadsDir, conversationId, images)
|
|
2640
2643
|
: undefined;
|
|
2641
2644
|
try {
|
|
2642
|
-
await session.prompt(message, { ...(imagePayloads ? { images: imagePayloads } : {}), streamingBehavior: "steer" });
|
|
2645
|
+
await session.prompt(message, { ...(imagePayloads?.length ? { images: imagePayloads } : {}), streamingBehavior: "steer" });
|
|
2643
2646
|
}
|
|
2644
2647
|
catch (error) {
|
|
2645
2648
|
throw error instanceof Error ? error : new Error(String(error));
|
|
@@ -33,7 +33,7 @@ export type ScopeVerdict = {
|
|
|
33
33
|
error: string;
|
|
34
34
|
};
|
|
35
35
|
/** The verb a refusal is about, so the message reads like the action that was refused. */
|
|
36
|
-
export type ScopeVerb = "调度" | "读取" | "停止" | "恢复" | "列出" | "看护";
|
|
36
|
+
export type ScopeVerb = "调度" | "读取" | "停止" | "恢复" | "列出" | "看护" | "移出";
|
|
37
37
|
/** What the caller was trying to reach: a session to manage, a session's children, or a parent to claim. */
|
|
38
38
|
export type ScopeSubject = "manage" | "list-children" | "declare-parent";
|
|
39
39
|
/** The narrow slice of the store this file needs. */
|
package/dist/server/store.d.ts
CHANGED
|
@@ -147,6 +147,10 @@ export declare class Store {
|
|
|
147
147
|
scheduledTasks(): ScheduledTask[];
|
|
148
148
|
projects(): Project[];
|
|
149
149
|
project(projectId: string): Project | undefined;
|
|
150
|
+
/** Conversation IDs that currently have an unresolved escalation requested. */
|
|
151
|
+
openEscalationConversationIds(): Set<string>;
|
|
152
|
+
/** Child conversation IDs whose enqueued session result is still waiting or sending on a non-archived parent. */
|
|
153
|
+
pendingResultConversationIds(): Set<string>;
|
|
150
154
|
setProject(project: Project): Promise<Project>;
|
|
151
155
|
removeProject(projectId: string): Promise<void>;
|
|
152
156
|
/** Small detached rows used when refreshing each conversation's scoped model catalog. */
|
|
@@ -390,6 +394,26 @@ export declare class Store {
|
|
|
390
394
|
archiveConversationTree(conversationId: string): Promise<void>;
|
|
391
395
|
/** Restores one archived tree in one write; active descendants are already restored by definition. */
|
|
392
396
|
unarchiveConversationTree(conversationId: string): Promise<void>;
|
|
397
|
+
/**
|
|
398
|
+
* Lists the conversation IDs in a session's subtree (root first, pre-order).
|
|
399
|
+
* Returns `[]` when the conversation does not exist.
|
|
400
|
+
*/
|
|
401
|
+
conversationSubtreeIds(conversationId: string): string[];
|
|
402
|
+
/**
|
|
403
|
+
* Permanently destroys a child conversation and its entire descendant subtree along with all
|
|
404
|
+
* conversation-scoped store records (messages, tool calls, sub-agent runs, background tasks,
|
|
405
|
+
* workflows, todos, UI locks/collapse markers, and open escalations raised by the destroyed
|
|
406
|
+
* sessions). Refuses top-level sessions and refuses if any session in the subtree is running.
|
|
407
|
+
*/
|
|
408
|
+
deleteConversationSubtree(conversationId: string): Promise<{
|
|
409
|
+
destroyed: Array<{
|
|
410
|
+
id: string;
|
|
411
|
+
title: string;
|
|
412
|
+
workspaceId: string;
|
|
413
|
+
piSessionFile?: string;
|
|
414
|
+
messageIds: string[];
|
|
415
|
+
}>;
|
|
416
|
+
}>;
|
|
393
417
|
/** Pre-order traversal with cycle protection; archived nodes are traversed, not treated as leaves. */
|
|
394
418
|
private conversationSubtree;
|
|
395
419
|
/**
|