@evandu/super-pi 0.1.184 → 0.1.187
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 +41 -5
- 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 +3 -71
- package/dist/server/application/project-service.js +36 -195
- 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 +8 -3
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import type { Store } from "../store.js";
|
|
2
2
|
import { type AgentRuntime } from "../runtime.js";
|
|
3
3
|
import type { SubagentRunRecorder } from "../subagent-runs.js";
|
|
4
|
-
import type { Conversation, Message, MessageImage, PiQueueSnapshot, QuestionAnswer, Workspace } from "../types.js";
|
|
4
|
+
import type { Conversation, Message, MessageDeliveryMode, MessageImage, PiQueueSnapshot, QuestionAnswer, Workspace } from "../types.js";
|
|
5
5
|
import type { EventBroadcaster } from "../server-context.js";
|
|
6
6
|
import type { ExtensionUiService } from "./extension-ui-service.js";
|
|
7
7
|
import type { WorkflowEngine } from "../workflow-engine.js";
|
|
8
8
|
import { FileChangeTracker } from "../file-changes.js";
|
|
9
|
+
/**
|
|
10
|
+
* Validates a caller-supplied delivery mode without silently falling back on bogus values.
|
|
11
|
+
* Undefined defaults to `"queue"`; any other value is rejected explicitly.
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseMessageDeliveryMode(mode: unknown): MessageDeliveryMode;
|
|
9
14
|
export interface SubagentDispatchRequestBody {
|
|
10
15
|
conversationId?: string;
|
|
11
16
|
subagent_type?: string;
|
|
@@ -364,6 +369,14 @@ export declare class RunService {
|
|
|
364
369
|
* the user asked to be answered NOW - so the ones Pi had not delivered go back in, and clearing the
|
|
365
370
|
* queues for one message does not silently un-steer another.
|
|
366
371
|
*/
|
|
372
|
+
/**
|
|
373
|
+
* Empties Pi's steering and follow-up queues for a conversation, returning any steering message
|
|
374
|
+
* IDs that were intentionally withheld because they appear in `excludeMessageIds`.
|
|
375
|
+
*
|
|
376
|
+
* Remaining steering messages not in `excludeMessageIds` are put back into Pi's steering queue
|
|
377
|
+
* in FIFO order (matching at most once per message ID even when two messages share identical text).
|
|
378
|
+
* Remaining follow-up messages stay in Super Pi's waiting list and run after the active turn.
|
|
379
|
+
*/
|
|
367
380
|
private clearPiQueues;
|
|
368
381
|
/**
|
|
369
382
|
* Opens a turn on a message that is ALREADY IN THE TRANSCRIPT.
|
|
@@ -424,8 +437,11 @@ export declare class RunService {
|
|
|
424
437
|
* and the turn runs on them exactly as before. `composePrompt` is what tells the model who is
|
|
425
438
|
* speaking, so the model is addressed in the same words.
|
|
426
439
|
*/
|
|
427
|
-
enqueueAndRunAsAgent(conversationId: string, content: string
|
|
428
|
-
|
|
440
|
+
enqueueAndRunAsAgent(conversationId: string, content: string, options?: {
|
|
441
|
+
mode?: MessageDeliveryMode;
|
|
442
|
+
onAccepted?: (messageId: string) => void;
|
|
443
|
+
}): Promise<void>;
|
|
444
|
+
enqueueAndRun(conversationId: string, content: string, images?: MessageImage[], attachments?: import("../types.js").MessageAttachments, clientId?: string, mode?: MessageDeliveryMode): Promise<void>;
|
|
429
445
|
/**
|
|
430
446
|
* Steers a queued message into the in-flight turn.
|
|
431
447
|
*/
|
|
@@ -476,11 +492,31 @@ export declare class RunService {
|
|
|
476
492
|
*/
|
|
477
493
|
private processWaitingMessage;
|
|
478
494
|
private steerUnsafe;
|
|
495
|
+
/**
|
|
496
|
+
* Steers a newly queued message into the running turn at the next turn boundary.
|
|
497
|
+
* Mirrors `dispatchBackgroundResult`'s lock-free fallback if the active run ends before the
|
|
498
|
+
* conversation lane is entered.
|
|
499
|
+
*/
|
|
500
|
+
private steerWaitingMessageOnBusyRun;
|
|
479
501
|
/**
|
|
480
502
|
* Withdraws a waiting message.
|
|
481
503
|
*/
|
|
482
504
|
cancelQueued(conversationId: string, messageId: string): Promise<void>;
|
|
483
505
|
private cancelQueuedUnsafe;
|
|
506
|
+
/**
|
|
507
|
+
* Selectively withdraws a specific subset of queued/steered messages by id while preserving
|
|
508
|
+
* all remaining waiting and steered messages.
|
|
509
|
+
*/
|
|
510
|
+
cancelQueuedMany(conversationId: string, messageIds: string[], options?: {
|
|
511
|
+
actor?: "user" | "agent";
|
|
512
|
+
}): Promise<{
|
|
513
|
+
withdrawn: {
|
|
514
|
+
id: string;
|
|
515
|
+
content: string;
|
|
516
|
+
role: "user" | "tool";
|
|
517
|
+
}[];
|
|
518
|
+
missingIds: string[];
|
|
519
|
+
}>;
|
|
484
520
|
/**
|
|
485
521
|
* Rewrites a waiting message, in place, where the user can see it change.
|
|
486
522
|
*/
|
|
@@ -16,6 +16,17 @@ import { execFile } from "node:child_process";
|
|
|
16
16
|
import { promisify } from "node:util";
|
|
17
17
|
import { randomUUID } from "node:crypto";
|
|
18
18
|
const execFileAsync = promisify(execFile);
|
|
19
|
+
/**
|
|
20
|
+
* Validates a caller-supplied delivery mode without silently falling back on bogus values.
|
|
21
|
+
* Undefined defaults to `"queue"`; any other value is rejected explicitly.
|
|
22
|
+
*/
|
|
23
|
+
export function parseMessageDeliveryMode(mode) {
|
|
24
|
+
if (mode === undefined)
|
|
25
|
+
return "queue";
|
|
26
|
+
if (mode === "queue" || mode === "steer")
|
|
27
|
+
return mode;
|
|
28
|
+
throw new Error(`不支持的消息投递模式:${JSON.stringify(mode)}(仅支持 "queue" 或 "steer")`);
|
|
29
|
+
}
|
|
19
30
|
/** Expands composer references into explicit context for the model. */
|
|
20
31
|
async function expandAtReferences(store, workspace, content) {
|
|
21
32
|
const refs = [...content.matchAll(/@(worktree|session):([^\s]+)/gi)];
|
|
@@ -1004,26 +1015,42 @@ export class RunService {
|
|
|
1004
1015
|
* the user asked to be answered NOW - so the ones Pi had not delivered go back in, and clearing the
|
|
1005
1016
|
* queues for one message does not silently un-steer another.
|
|
1006
1017
|
*/
|
|
1007
|
-
|
|
1018
|
+
/**
|
|
1019
|
+
* Empties Pi's steering and follow-up queues for a conversation, returning any steering message
|
|
1020
|
+
* IDs that were intentionally withheld because they appear in `excludeMessageIds`.
|
|
1021
|
+
*
|
|
1022
|
+
* Remaining steering messages not in `excludeMessageIds` are put back into Pi's steering queue
|
|
1023
|
+
* in FIFO order (matching at most once per message ID even when two messages share identical text).
|
|
1024
|
+
* Remaining follow-up messages stay in Super Pi's waiting list and run after the active turn.
|
|
1025
|
+
*/
|
|
1026
|
+
async clearPiQueues(conversationId, options) {
|
|
1027
|
+
const evictedSteerIds = new Set();
|
|
1008
1028
|
if (!this.runtime.clearQueues)
|
|
1009
|
-
return;
|
|
1029
|
+
return evictedSteerIds;
|
|
1010
1030
|
let cleared;
|
|
1011
1031
|
try {
|
|
1012
1032
|
cleared = await this.runtime.clearQueues(conversationId);
|
|
1013
1033
|
}
|
|
1014
1034
|
catch (error) {
|
|
1015
1035
|
console.warn(`Super Pi: clearing Pi's queues for ${conversationId} failed: ${error instanceof Error ? error.message : "unknown error"}`);
|
|
1016
|
-
return;
|
|
1036
|
+
return evictedSteerIds;
|
|
1017
1037
|
}
|
|
1038
|
+
const matchedSteerIds = new Set();
|
|
1039
|
+
const excludeIds = options?.excludeMessageIds;
|
|
1018
1040
|
for (const text of cleared.steering ?? []) {
|
|
1041
|
+
const message = this.store.listWaitingMessages(conversationId)
|
|
1042
|
+
.find((item) => item.delivery === "sending" && composePrompt(item) === text && !matchedSteerIds.has(item.id));
|
|
1043
|
+
if (!message)
|
|
1044
|
+
continue;
|
|
1045
|
+
matchedSteerIds.add(message.id);
|
|
1046
|
+
if (excludeIds?.has(message.id)) {
|
|
1047
|
+
evictedSteerIds.add(message.id);
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1019
1050
|
// A STEER NEEDS A TURN TO GO INTO. With no turn running there is nothing to steer, and the message
|
|
1020
1051
|
// is released back to `waiting` when the run ends anyway - so it is answered as a turn of its own.
|
|
1021
1052
|
if (this.runtime.canSteer && !this.runtime.canSteer(conversationId))
|
|
1022
1053
|
continue;
|
|
1023
|
-
const message = this.store.listWaitingMessages(conversationId)
|
|
1024
|
-
.find((item) => item.delivery === "sending" && composePrompt(item) === text);
|
|
1025
|
-
if (!message)
|
|
1026
|
-
continue;
|
|
1027
1054
|
try {
|
|
1028
1055
|
await this.runtime.steer?.(conversationId, text, message.images);
|
|
1029
1056
|
}
|
|
@@ -1031,6 +1058,7 @@ export class RunService {
|
|
|
1031
1058
|
console.warn(`Super Pi: putting a steered message back failed: ${error instanceof Error ? error.message : "unknown error"}`);
|
|
1032
1059
|
}
|
|
1033
1060
|
}
|
|
1061
|
+
return evictedSteerIds;
|
|
1034
1062
|
}
|
|
1035
1063
|
/**
|
|
1036
1064
|
* Opens a turn on a message that is ALREADY IN THE TRANSCRIPT.
|
|
@@ -1220,7 +1248,7 @@ export class RunService {
|
|
|
1220
1248
|
let thinkingInterrupted = false;
|
|
1221
1249
|
let answerAfterThinking = false;
|
|
1222
1250
|
const currentThinkingBlock = () => {
|
|
1223
|
-
if (
|
|
1251
|
+
if (thinkingBlock >= 0 && !thinkingInterrupted && !answerAfterThinking)
|
|
1224
1252
|
return thinkingBlock;
|
|
1225
1253
|
// An outside call separates two thoughts even if no answer text was emitted.
|
|
1226
1254
|
if (thinkingBlock >= 0)
|
|
@@ -1306,8 +1334,9 @@ export class RunService {
|
|
|
1306
1334
|
// spends writing its replacement text - and by the time the file path was on screen, the block looked
|
|
1307
1335
|
// broken rather than early. The placeholder word is now only the FALLBACK for the first fragment, when
|
|
1308
1336
|
// Pi has not yet said what the call is or what it opens.
|
|
1309
|
-
//
|
|
1310
|
-
|
|
1337
|
+
// Ownership is fixed when the call is announced: once a thinking block is open on this message,
|
|
1338
|
+
// the thinking stage remains open across thinking_end until answer text appears.
|
|
1339
|
+
const callThinkingBlock = (thinkingBlock >= 0 && !thinkingInterrupted && !answerAfterThinking) ? thinkingBlock : null;
|
|
1311
1340
|
enqueueTools("a tool call being prepared", () => this.store.appendToolCall(conversation.id, assistant.id, {
|
|
1312
1341
|
label: call.name || "工具",
|
|
1313
1342
|
...(call.detail ? { detail: call.detail } : { detail: "正在生成参数…" }),
|
|
@@ -1459,9 +1488,8 @@ export class RunService {
|
|
|
1459
1488
|
//
|
|
1460
1489
|
// THIS IS THE PATH WITH NO PLACEHOLDER - Pi never announced a `toolcall_start` for this call,
|
|
1461
1490
|
// so there is no earlier moment to compare offsets against, and the reasoning offset is taken
|
|
1462
|
-
// here, at the announcement.
|
|
1463
|
-
//
|
|
1464
|
-
// `thinkingActive`, because a call with no placeholder carries no earlier offset to compare.
|
|
1491
|
+
// here, at the announcement. Ownership follows the same stage boundary as `onToolPreparing`:
|
|
1492
|
+
// once a thinking block is open on this message, the call belongs to it until answer text arrives.
|
|
1465
1493
|
const thinkingAt = thought;
|
|
1466
1494
|
// A CALL ANNOUNCED AFTER THE ANSWER BELONGS TO NO FOLD, even when the reasoning is still running.
|
|
1467
1495
|
// `currentThinkingBlock()` also marks the thinking as interrupted when it is not active, so it
|
|
@@ -1845,7 +1873,8 @@ export class RunService {
|
|
|
1845
1873
|
* and the turn runs on them exactly as before. `composePrompt` is what tells the model who is
|
|
1846
1874
|
* speaking, so the model is addressed in the same words.
|
|
1847
1875
|
*/
|
|
1848
|
-
async enqueueAndRunAsAgent(conversationId, content) {
|
|
1876
|
+
async enqueueAndRunAsAgent(conversationId, content, options) {
|
|
1877
|
+
const deliveryMode = parseMessageDeliveryMode(options?.mode);
|
|
1849
1878
|
this.assertHistoryAvailable(conversationId);
|
|
1850
1879
|
this.memory?.cancel(conversationId);
|
|
1851
1880
|
const trimmed = content.trim();
|
|
@@ -1875,14 +1904,20 @@ export class RunService {
|
|
|
1875
1904
|
this.broadcaster.broadcastState();
|
|
1876
1905
|
if (!reservedController) {
|
|
1877
1906
|
const waiting = this.store.listWaitingMessages(conversationId).find((item) => item.id === message.id && item.delivery === "waiting");
|
|
1878
|
-
if (!waiting)
|
|
1907
|
+
if (!waiting) {
|
|
1908
|
+
options?.onAccepted?.(message.id);
|
|
1879
1909
|
return;
|
|
1910
|
+
}
|
|
1880
1911
|
if (!this.activeRuns.has(conversationId) && !this.interruptTargets.has(conversationId))
|
|
1881
1912
|
await this.processWaitingMessage(conversationId, message.id);
|
|
1913
|
+
else if (deliveryMode === "steer")
|
|
1914
|
+
await this.steerWaitingMessageOnBusyRun(conversationId, message.id);
|
|
1882
1915
|
else
|
|
1883
1916
|
await this.submitToPiQueue(conversationId, message);
|
|
1917
|
+
options?.onAccepted?.(message.id);
|
|
1884
1918
|
return;
|
|
1885
1919
|
}
|
|
1920
|
+
options?.onAccepted?.(message.id);
|
|
1886
1921
|
const controller = reservedController;
|
|
1887
1922
|
try {
|
|
1888
1923
|
if (controller.signal.aborted) {
|
|
@@ -1918,7 +1953,8 @@ export class RunService {
|
|
|
1918
1953
|
this.broadcaster.broadcastState();
|
|
1919
1954
|
}
|
|
1920
1955
|
}
|
|
1921
|
-
async enqueueAndRun(conversationId, content, images, attachments, clientId) {
|
|
1956
|
+
async enqueueAndRun(conversationId, content, images, attachments, clientId, mode) {
|
|
1957
|
+
const deliveryMode = parseMessageDeliveryMode(mode);
|
|
1922
1958
|
this.assertHistoryAvailable(conversationId);
|
|
1923
1959
|
/**
|
|
1924
1960
|
* A CLIENT ID THIS CONVERSATION ALREADY HAS IS A RESEND, NOT A SECOND MESSAGE.
|
|
@@ -1999,6 +2035,9 @@ export class RunService {
|
|
|
1999
2035
|
if (!this.activeRuns.has(conversationId) && !this.interruptTargets.has(conversationId)) {
|
|
2000
2036
|
await this.processWaitingMessage(conversationId, message.id);
|
|
2001
2037
|
}
|
|
2038
|
+
else if (deliveryMode === "steer") {
|
|
2039
|
+
await this.steerWaitingMessageOnBusyRun(conversationId, message.id);
|
|
2040
|
+
}
|
|
2002
2041
|
else
|
|
2003
2042
|
await this.submitToPiQueue(conversationId, message);
|
|
2004
2043
|
return;
|
|
@@ -2311,6 +2350,49 @@ export class RunService {
|
|
|
2311
2350
|
throw error;
|
|
2312
2351
|
}
|
|
2313
2352
|
}
|
|
2353
|
+
/**
|
|
2354
|
+
* Steers a newly queued message into the running turn at the next turn boundary.
|
|
2355
|
+
* Mirrors `dispatchBackgroundResult`'s lock-free fallback if the active run ends before the
|
|
2356
|
+
* conversation lane is entered.
|
|
2357
|
+
*/
|
|
2358
|
+
async steerWaitingMessageOnBusyRun(conversationId, messageId) {
|
|
2359
|
+
const startWaiting = await this.serializeConversation(conversationId, async () => {
|
|
2360
|
+
if (this.shuttingDown || this.interruptTargets.has(conversationId)) {
|
|
2361
|
+
if (!this.shuttingDown) {
|
|
2362
|
+
await this.moveAheadOfUnclaimed(conversationId, messageId);
|
|
2363
|
+
this.broadcaster.broadcastState();
|
|
2364
|
+
}
|
|
2365
|
+
return false;
|
|
2366
|
+
}
|
|
2367
|
+
if (!this.activeRuns.has(conversationId))
|
|
2368
|
+
return true;
|
|
2369
|
+
const waiting = this.store.listWaitingMessages(conversationId);
|
|
2370
|
+
if (!waiting.some((item) => item.id === messageId && item.delivery === "waiting"))
|
|
2371
|
+
return false;
|
|
2372
|
+
await this.moveAheadOfUnclaimed(conversationId, messageId);
|
|
2373
|
+
this.broadcaster.broadcastState();
|
|
2374
|
+
if (!this.runtime.steer)
|
|
2375
|
+
return false;
|
|
2376
|
+
if (this.runtime.canSteer && !this.runtime.canSteer(conversationId))
|
|
2377
|
+
return false;
|
|
2378
|
+
const claimed = await this.store.claimWaitingMessage(conversationId, messageId);
|
|
2379
|
+
this.broadcaster.broadcastState();
|
|
2380
|
+
try {
|
|
2381
|
+
await this.runtime.steer(conversationId, composePrompt(claimed), claimed.images);
|
|
2382
|
+
return false;
|
|
2383
|
+
}
|
|
2384
|
+
catch (error) {
|
|
2385
|
+
await this.store.releaseWaitingMessage(conversationId, claimed.id);
|
|
2386
|
+
this.broadcaster.broadcastState();
|
|
2387
|
+
if (error instanceof SteerUnavailableError)
|
|
2388
|
+
return !this.activeRuns.has(conversationId);
|
|
2389
|
+
throw error;
|
|
2390
|
+
}
|
|
2391
|
+
});
|
|
2392
|
+
if (startWaiting) {
|
|
2393
|
+
await this.processWaitingMessage(conversationId, messageId);
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2314
2396
|
/**
|
|
2315
2397
|
* Withdraws a waiting message.
|
|
2316
2398
|
*/
|
|
@@ -2325,9 +2407,75 @@ export class RunService {
|
|
|
2325
2407
|
// ends - the model would answer words the user believes they withdrew. Pi cannot take back one
|
|
2326
2408
|
// message, so its queues are emptied; the other messages Pi was holding are still in Super Pi's
|
|
2327
2409
|
// waiting list and are answered as turns of their own.
|
|
2328
|
-
await this.clearPiQueues(conversationId);
|
|
2329
|
-
await this.store.cancelWaitingMessage(conversationId, messageId);
|
|
2410
|
+
await this.clearPiQueues(conversationId, { excludeMessageIds: new Set([messageId]) });
|
|
2411
|
+
const removed = await this.store.cancelWaitingMessage(conversationId, messageId);
|
|
2330
2412
|
this.broadcaster.broadcastState();
|
|
2413
|
+
if (removed) {
|
|
2414
|
+
this.broadcaster.broadcast({
|
|
2415
|
+
type: "queue.withdrawn",
|
|
2416
|
+
conversationId,
|
|
2417
|
+
withdrawn: [{ id: removed.id, content: removed.content, role: removed.role === "tool" ? "tool" : "user" }],
|
|
2418
|
+
actor: "user",
|
|
2419
|
+
});
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
/**
|
|
2423
|
+
* Selectively withdraws a specific subset of queued/steered messages by id while preserving
|
|
2424
|
+
* all remaining waiting and steered messages.
|
|
2425
|
+
*/
|
|
2426
|
+
async cancelQueuedMany(conversationId, messageIds, options) {
|
|
2427
|
+
const normalizedIds = [];
|
|
2428
|
+
const seen = new Set();
|
|
2429
|
+
for (const raw of messageIds) {
|
|
2430
|
+
const id = typeof raw === "string" ? raw.trim() : "";
|
|
2431
|
+
if (!id || seen.has(id))
|
|
2432
|
+
continue;
|
|
2433
|
+
seen.add(id);
|
|
2434
|
+
normalizedIds.push(id);
|
|
2435
|
+
}
|
|
2436
|
+
if (normalizedIds.length === 0) {
|
|
2437
|
+
throw new Error("请至少选择一条要撤回的排队消息");
|
|
2438
|
+
}
|
|
2439
|
+
return this.serializeConversation(conversationId, async () => {
|
|
2440
|
+
const interruptTarget = this.interruptTargets.get(conversationId);
|
|
2441
|
+
if (interruptTarget && seen.has(interruptTarget)) {
|
|
2442
|
+
throw new Error("所选消息中有一条正在打断并回答,无法撤回");
|
|
2443
|
+
}
|
|
2444
|
+
const waitingBefore = this.store.listWaitingMessages(conversationId);
|
|
2445
|
+
const evictedSteerIds = await this.clearPiQueues(conversationId, { excludeMessageIds: seen });
|
|
2446
|
+
const unwithdrawable = waitingBefore.find((item) => seen.has(item.id) && item.delivery === "sending" && !evictedSteerIds.has(item.id));
|
|
2447
|
+
if (unwithdrawable) {
|
|
2448
|
+
throw new Error("所选消息中有已经交给 Agent 的消息,取消不掉(Pi 没有撤回单条队列消息的能力)");
|
|
2449
|
+
}
|
|
2450
|
+
for (const id of evictedSteerIds) {
|
|
2451
|
+
await this.store.releaseWaitingMessage(conversationId, id);
|
|
2452
|
+
}
|
|
2453
|
+
const withdrawn = [];
|
|
2454
|
+
const missingIds = [];
|
|
2455
|
+
for (const id of normalizedIds) {
|
|
2456
|
+
const removed = await this.store.cancelWaitingMessage(conversationId, id);
|
|
2457
|
+
if (removed) {
|
|
2458
|
+
withdrawn.push({
|
|
2459
|
+
id: removed.id,
|
|
2460
|
+
content: removed.content,
|
|
2461
|
+
role: removed.role === "tool" ? "tool" : "user",
|
|
2462
|
+
});
|
|
2463
|
+
}
|
|
2464
|
+
else {
|
|
2465
|
+
missingIds.push(id);
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
this.broadcaster.broadcastState();
|
|
2469
|
+
if (withdrawn.length > 0) {
|
|
2470
|
+
this.broadcaster.broadcast({
|
|
2471
|
+
type: "queue.withdrawn",
|
|
2472
|
+
conversationId,
|
|
2473
|
+
withdrawn,
|
|
2474
|
+
actor: options?.actor ?? "user",
|
|
2475
|
+
});
|
|
2476
|
+
}
|
|
2477
|
+
return { withdrawn, missingIds };
|
|
2478
|
+
});
|
|
2331
2479
|
}
|
|
2332
2480
|
/**
|
|
2333
2481
|
* Rewrites a waiting message, in place, where the user can see it change.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Store } from "../store.js";
|
|
2
2
|
import type { ConversationService } from "./conversation-service.js";
|
|
3
|
-
import type
|
|
3
|
+
import { type RunService } from "./run-service.js";
|
|
4
4
|
import type { SessionLedger } from "../session-ledger.js";
|
|
5
5
|
import type { EventBroadcaster } from "../server-context.js";
|
|
6
|
-
import type { RunStatus } from "../types.js";
|
|
6
|
+
import type { MessageDeliveryMode, RunStatus } from "../types.js";
|
|
7
7
|
import { SessionWatchdog } from "./session-watchdog.js";
|
|
8
8
|
export declare const SESSION_OUTPUT_CHAR_LIMIT: number;
|
|
9
9
|
export declare const sessionResultRelativePath: (conversationId: string) => string;
|
|
@@ -66,10 +66,12 @@ export interface ReportSessionOptions {
|
|
|
66
66
|
status?: "in_progress" | "completed" | "failed";
|
|
67
67
|
}
|
|
68
68
|
export interface StopSessionOptions {
|
|
69
|
-
/**
|
|
69
|
+
/** Whether to stop only the running turn ('active'), only queued messages ('queued'), or both ('all', default). */
|
|
70
70
|
mode?: "active" | "queued" | "all";
|
|
71
|
-
/** Optional specific
|
|
71
|
+
/** Optional specific queued message ID to interrupt or cancel. */
|
|
72
72
|
messageId?: string;
|
|
73
|
+
/** Optional list of specific queued message IDs to selectively withdraw while keeping other queued/steered messages intact. */
|
|
74
|
+
messageIds?: string[];
|
|
73
75
|
}
|
|
74
76
|
export interface SessionSummary {
|
|
75
77
|
conversationId: string;
|
|
@@ -95,6 +97,12 @@ export interface SessionSummary {
|
|
|
95
97
|
output?: string;
|
|
96
98
|
outputPath?: string;
|
|
97
99
|
outputTruncated?: boolean;
|
|
100
|
+
queuedMessages?: {
|
|
101
|
+
id: string;
|
|
102
|
+
delivery: "waiting" | "sending";
|
|
103
|
+
role: "user" | "tool";
|
|
104
|
+
snippet: string;
|
|
105
|
+
}[];
|
|
98
106
|
}
|
|
99
107
|
/**
|
|
100
108
|
* Orchestrator service coordinating sibling and child conversations.
|
|
@@ -108,6 +116,7 @@ export declare class SessionOrchestratorService {
|
|
|
108
116
|
private readonly runService;
|
|
109
117
|
private readonly ledger;
|
|
110
118
|
private readonly broadcaster?;
|
|
119
|
+
private readonly uploadsDir?;
|
|
111
120
|
readonly watchdog: SessionWatchdog;
|
|
112
121
|
/**
|
|
113
122
|
* HOW MANY TIMES EACH CHILD HAS BEEN TOLD TO CONTINUE AFTER A TRUNCATION.
|
|
@@ -142,7 +151,7 @@ export declare class SessionOrchestratorService {
|
|
|
142
151
|
* result is still its own.
|
|
143
152
|
*/
|
|
144
153
|
private readonly reportedChildren;
|
|
145
|
-
constructor(store: Store, conversationService: ConversationService, runService: RunService, ledger: SessionLedger, broadcaster?: EventBroadcaster | undefined, watchdog?: SessionWatchdog);
|
|
154
|
+
constructor(store: Store, conversationService: ConversationService, runService: RunService, ledger: SessionLedger, broadcaster?: EventBroadcaster | undefined, watchdog?: SessionWatchdog, uploadsDir?: string | undefined);
|
|
146
155
|
/**
|
|
147
156
|
* The watchdog timer fired: the child has been silent for longer than the parent declared.
|
|
148
157
|
* Delivers a reminder message to the parent session. Does NOT interrupt or abort the child session.
|
|
@@ -160,8 +169,11 @@ export declare class SessionOrchestratorService {
|
|
|
160
169
|
*/
|
|
161
170
|
dispatch(conversationId: string, content: string, options?: {
|
|
162
171
|
wait?: boolean;
|
|
172
|
+
mode?: MessageDeliveryMode;
|
|
163
173
|
}): Promise<{
|
|
164
174
|
conversationId: string;
|
|
175
|
+
messageId?: string;
|
|
176
|
+
mode: MessageDeliveryMode;
|
|
165
177
|
}>;
|
|
166
178
|
/**
|
|
167
179
|
* THE CHILD'S OUTPUT WAS CUT OFF. TELL IT TO CARRY ON, AND LET IT.
|
|
@@ -238,6 +250,12 @@ export declare class SessionOrchestratorService {
|
|
|
238
250
|
stop(conversationId: string, options?: StopSessionOptions): Promise<{
|
|
239
251
|
stopped: boolean;
|
|
240
252
|
mode: string;
|
|
253
|
+
withdrawn?: {
|
|
254
|
+
id: string;
|
|
255
|
+
content: string;
|
|
256
|
+
role: "user" | "tool";
|
|
257
|
+
}[];
|
|
258
|
+
missingIds?: string[];
|
|
241
259
|
}>;
|
|
242
260
|
/**
|
|
243
261
|
* THE SESSIONS UNDER ONE SESSION, DEEPEST LAST.
|
|
@@ -275,6 +293,21 @@ export declare class SessionOrchestratorService {
|
|
|
275
293
|
stoppedIds: string[];
|
|
276
294
|
descendantCount: number;
|
|
277
295
|
}>;
|
|
296
|
+
/**
|
|
297
|
+
* Permanently destroys a direct child session and its entire descendant subtree (stopping any
|
|
298
|
+
* running/queued turns first) and removes all transcripts, outputs, runs, and auxiliary state.
|
|
299
|
+
*/
|
|
300
|
+
remove(conversationId: string, options?: {
|
|
301
|
+
reason?: string;
|
|
302
|
+
}): Promise<{
|
|
303
|
+
removed: boolean;
|
|
304
|
+
alreadyRemoved: boolean;
|
|
305
|
+
conversationId: string;
|
|
306
|
+
title?: string;
|
|
307
|
+
destroyedIds: string[];
|
|
308
|
+
stoppedFirst: boolean;
|
|
309
|
+
reason?: string;
|
|
310
|
+
}>;
|
|
278
311
|
/**
|
|
279
312
|
* Resumes execution in a conversation.
|
|
280
313
|
* If prompt is provided, sends it as a new turn.
|