pi-web-ui 0.114.2 → 0.115.0
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/CHANGELOG.md +55 -1
- package/bin/pi-web-ui.mjs +69 -7
- package/dist/server/agent-service-daemon.js +440 -32
- package/dist/server/agent-service.js +878 -383
- package/dist/server/canvas/canvas-dispatch.js +13 -1
- package/dist/server/client-state.js +25 -0
- package/dist/server/communicate-tool.js +2 -0
- package/dist/server/context-usage.js +105 -0
- package/dist/server/conversation-communication.js +14 -0
- package/dist/server/conversation-identity.js +27 -0
- package/dist/server/device-center/approval-summary.js +31 -0
- package/dist/server/device-center/bot-catalog.js +21 -7
- package/dist/server/device-center/bot-execution.js +72 -9
- package/dist/server/device-center/bot-presets.js +46 -0
- package/dist/server/device-center/collab-service.js +328 -10
- package/dist/server/device-center/collab-tool.js +738 -12
- package/dist/server/device-center/connector.js +359 -23
- package/dist/server/device-center/desktop-page.js +22 -16
- package/dist/server/device-center/device-integration.js +595 -0
- package/dist/server/device-center/execution-guides.js +32 -0
- package/dist/server/device-center/execution-instructions.js +19 -0
- package/dist/server/device-center/execution-settings.js +100 -0
- package/dist/server/device-center/execution-system-prompt.js +38 -0
- package/dist/server/device-center/execution-workspace.js +20 -0
- package/dist/server/device-center/executor.js +389 -40
- package/dist/server/device-center/file-sync-paths.js +171 -0
- package/dist/server/device-center/file-sync.js +180 -91
- package/dist/server/device-center/group-context-delta.js +37 -0
- package/dist/server/device-center/group-context-message.js +208 -0
- package/dist/server/device-center/group-context.js +109 -0
- package/dist/server/device-center/group-events.js +136 -0
- package/dist/server/device-center/group-plan-guard.js +138 -0
- package/dist/server/device-center/hub-conversations.js +178 -0
- package/dist/server/device-center/hub-deliveries.js +277 -0
- package/dist/server/device-center/hub-integration.js +451 -0
- package/dist/server/device-center/hub.js +1544 -80
- package/dist/server/device-center/human-interaction.js +232 -0
- package/dist/server/device-center/integration-errors.js +25 -0
- package/dist/server/device-center/local-hub.js +18 -0
- package/dist/server/device-center/local.js +356 -40
- package/dist/server/device-center/main.js +11 -1
- package/dist/server/device-center/path-portal.js +11 -3
- package/dist/server/device-center/relay.js +364 -35
- package/dist/server/device-center/report-metadata.js +66 -0
- package/dist/server/device-center/report-upload.js +63 -0
- package/dist/server/device-center/runtime.js +549 -41
- package/dist/server/device-center/store.js +66 -3
- package/dist/server/device-center/task-context-budget.js +161 -0
- package/dist/server/device-center/task-journal.js +385 -0
- package/dist/server/device-center/task-plan.js +33 -0
- package/dist/server/device-center/task-progress.js +141 -0
- package/dist/server/device-center/task-recovery.js +452 -0
- package/dist/server/device-center/task-report-outbox.js +216 -0
- package/dist/server/device-center/task-report.js +384 -0
- package/dist/server/device-center/task-scheduler.js +400 -0
- package/dist/server/device-center/task-state.js +333 -0
- package/dist/server/device-center/transfer-stream.js +1006 -0
- package/dist/server/device-center/transfers.js +815 -8
- package/dist/server/dispatch-domain-handlers.js +21 -3
- package/dist/server/dsh/dsh-agent-service.js +6 -0
- package/dist/server/goal-service.js +10 -5
- package/dist/server/index.js +89 -13
- package/dist/server/message-deletion.js +40 -0
- package/dist/server/message-window.js +9 -0
- package/dist/server/patch-executable-lookup.js +396 -0
- package/dist/server/payload-limits.js +2 -0
- package/dist/server/plugin-llm.js +100 -9
- package/dist/server/plugins.js +1 -0
- package/dist/server/preset-fields.js +24 -0
- package/dist/server/preset-share.js +2 -0
- package/dist/server/prompt-base-store.js +85 -0
- package/dist/server/prompt-composer.js +5 -2
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/protocol.js +2 -2
- package/dist/server/remote-ssh-service.js +22 -9
- package/dist/server/resolve-global-sdk.js +2 -0
- package/dist/server/session-search.js +1 -1
- package/dist/server/settings-service.js +90 -39
- package/dist/server/skill-content-filler.js +29 -8
- package/dist/server/skill-tool.js +12 -3
- package/dist/server/subagent-helpers.js +4 -1
- package/dist/server/subagents.js +50 -36
- package/dist/server/tool-host-factories.js +1 -0
- package/dist/server/universal/universal-session.js +5 -0
- package/dist/server/webui-context.js +25 -5
- package/docs/README.md +94 -0
- package/docs/device-center.md +100 -12
- package/docs/dsh-engine.md +10 -10
- package/extensions/webui.ts +43 -1
- package/package.json +1 -1
- package/themes/aetheris.css +5 -0
- package/themes/ayu-light.css +6 -0
- package/themes/bases/flow-base.css +68 -68
- package/themes/catppuccin-latte.css +6 -0
- package/themes/catppuccin.css +6 -0
- package/themes/claude-code-dark.css +5 -0
- package/themes/codex.css +6 -0
- package/themes/cyberpunk.css +6 -0
- package/themes/dark-teal.css +6 -1
- package/themes/dazzle.css +6 -0
- package/themes/everforest-light.css +6 -0
- package/themes/flow-light.css +8 -1
- package/themes/flow.css +6 -1
- package/themes/geist.css +6 -0
- package/themes/gruvbox-light.css +6 -0
- package/themes/kanagawa-lotus.css +6 -0
- package/themes/md-preview.css +6 -0
- package/themes/mist.css +6 -0
- package/themes/nord.css +6 -0
- package/themes/one-dark.css +6 -0
- package/themes/paper.css +6 -0
- package/themes/rose-pine-dawn.css +6 -0
- package/themes/sakura.css +6 -0
- package/themes/solarized-light.css +6 -0
- package/themes/tokyo-night.css +6 -0
- package/themes/translucent.css +6 -0
- package/themes/transparent.css +6 -0
- package/themes/vs-code-dark.css +5 -0
- package/themes/wallpaper-flow.css +5 -1
- package/themes/wallpaper-obsidian.css +6 -0
- package/themes/white.css +6 -0
- package/themes/zhujian-dark.css +6 -1
- package/themes/zhujian.css +6 -1
- package/themes/zhupi-dark.css +6 -1
- package/themes/zhupi.css +6 -1
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/BgTasksModal-BYzPgmoq.js +1 -0
- package/web/dist/assets/BgTasksModal-ni0VTmAQ.js +1 -0
- package/web/dist/assets/{CanvasStudio-B3W6b_rA.js → CanvasStudio-BCUeEf25.js} +3 -3
- package/web/dist/assets/{CanvasStudio-Csv1Sj1-.js → CanvasStudio-DNmDNBod.js} +3 -3
- package/web/dist/assets/DeviceCenter-BcBhRgL6.js +3 -0
- package/web/dist/assets/DeviceCenter-CmL5FZmt.js +3 -0
- package/web/dist/assets/DeviceGroups-CLdpdnI7.js +1 -0
- package/web/dist/assets/DeviceGroups-CgBaDPrD.js +1 -0
- package/web/dist/assets/Dropdown-CGXD0DfT.js +1 -0
- package/web/dist/assets/FilePreview-B8iqnBjy.js +2 -0
- package/web/dist/assets/FilePreview-BqviZKCN.js +2 -0
- package/web/dist/assets/GlobalSearchModal-mevF-ySi.js +1 -0
- package/web/dist/assets/GlobalSearchModal-qL99FN_F.js +1 -0
- package/web/dist/assets/GroupConversation-B88Yy-lt.js +3 -0
- package/web/dist/assets/GroupConversation-BwP5NVOE.js +3 -0
- package/web/dist/assets/HintTip-LHwkS2jV.js +1 -0
- package/web/dist/assets/ModelConfigModal-Do3Fe3jH.js +2 -0
- package/web/dist/assets/PiSetupModal-DE5-gEtI.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-6UMARucA.js +1 -0
- package/web/dist/assets/SCMPanel-Hi6QqC1Q.js +2 -0
- package/web/dist/assets/SCMPanel-ezY_ZtCu.js +2 -0
- package/web/dist/assets/SettingsModal-6HgeEsJ8.js +20 -0
- package/web/dist/assets/SettingsModal-CF-7MwqS.js +20 -0
- package/web/dist/assets/TerminalPanel-CTp_BZ4S.js +3 -0
- package/web/dist/assets/TerminalPanel-CkYxC-Gh.js +3 -0
- package/web/dist/assets/TuiOverlayModal-1cRLP8IF.js +1 -0
- package/web/dist/assets/TuiOverlayModal-2xlptqWX.js +1 -0
- package/web/dist/assets/app-globals-DZNa9v8u.js +325 -0
- package/web/dist/assets/canvas-client-Bye9nSFO.js +1 -0
- package/web/dist/assets/{desktop-YguLbrX1.js → desktop-kjBoE3Nu.js} +1 -1
- package/web/dist/assets/group-view-state-CGCzYF8k.js +1 -0
- package/web/dist/assets/index-CsFs_HMb.css +1 -0
- package/web/dist/assets/index-DHeeHS_l.js +85 -0
- package/web/dist/assets/index-DTZch8uz.js +85 -0
- package/web/dist/assets/plugin-host-C8mNgghx.js +1 -0
- package/web/dist/assets/remote-ssh-client-CeP3CLUW.js +1 -0
- package/web/dist/assets/theme-BXGpyTMh.js +1 -0
- package/web/dist/index.html +10 -9
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/BgTasksModal-BIlQ89vr.js +0 -1
- package/web/dist/assets/BgTasksModal-Ck2sjlPM.js +0 -1
- package/web/dist/assets/DeviceCenter-BQdDcO8A.js +0 -3
- package/web/dist/assets/DeviceCenter-CHRKL0Vy.js +0 -3
- package/web/dist/assets/DeviceGroups-D2rogxEN.js +0 -1
- package/web/dist/assets/Dropdown-ZLS04O8p.js +0 -1
- package/web/dist/assets/FilePreview-B9xoU6ON.js +0 -2
- package/web/dist/assets/FilePreview-DUQpVZkH.js +0 -2
- package/web/dist/assets/GlobalSearchModal-BXEGvUZq.js +0 -1
- package/web/dist/assets/GlobalSearchModal-CnVPmfOI.js +0 -1
- package/web/dist/assets/GroupConversation-CyIpQzDd.js +0 -1
- package/web/dist/assets/GroupConversation-DgYV3uYS.js +0 -1
- package/web/dist/assets/ModelConfigModal-DDZccDYt.js +0 -2
- package/web/dist/assets/PiSetupModal-DHbqfx8T.js +0 -1
- package/web/dist/assets/ProviderOAuthControls-C-MK36Dk.js +0 -1
- package/web/dist/assets/SCMPanel-imYI2Ecw.js +0 -2
- package/web/dist/assets/SCMPanel-sVZcV7dR.js +0 -2
- package/web/dist/assets/SettingsModal-Xw1Yoi3_.js +0 -20
- package/web/dist/assets/SettingsModal-mb4e34-0.js +0 -20
- package/web/dist/assets/TerminalPanel-CLkJJvxg.js +0 -3
- package/web/dist/assets/TerminalPanel-DpcIellm.js +0 -3
- package/web/dist/assets/TuiOverlayModal-4-fFAZe7.js +0 -1
- package/web/dist/assets/TuiOverlayModal-DCu01lks.js +0 -1
- package/web/dist/assets/app-globals-DcyO0UPi.js +0 -1
- package/web/dist/assets/fi-DaSO0Q-m.js +0 -325
- package/web/dist/assets/index-Cdh3sibd.js +0 -85
- package/web/dist/assets/index-DDZMv6LO.css +0 -1
- package/web/dist/assets/index-DWw_SxRq.js +0 -85
- package/web/dist/assets/plugin-host-BRBg6zmQ.js +0 -1
- package/web/dist/assets/theme-DDl-Oy1b.js +0 -1
|
@@ -423,11 +423,22 @@ export function handleSessionLifecycleMessage(msg, cs, send) {
|
|
|
423
423
|
});
|
|
424
424
|
};
|
|
425
425
|
void cs
|
|
426
|
-
.newChat(msg.preset, msg.ephemeral, acknowledge)
|
|
426
|
+
.newChat(msg.preset, msg.ephemeral, acknowledge, msg.independent)
|
|
427
427
|
.then(() => acknowledge())
|
|
428
428
|
.catch(() => acknowledge());
|
|
429
429
|
return true;
|
|
430
430
|
}
|
|
431
|
+
case "delete_message":
|
|
432
|
+
if (cs.deleteMessage)
|
|
433
|
+
void cs.deleteMessage(msg.messageId, msg.conversationId);
|
|
434
|
+
else
|
|
435
|
+
send?.({
|
|
436
|
+
type: "notice",
|
|
437
|
+
level: "error",
|
|
438
|
+
text: "当前引擎不支持删除消息",
|
|
439
|
+
textEn: "This engine does not support message deletion",
|
|
440
|
+
});
|
|
441
|
+
return true;
|
|
431
442
|
case "edit_message":
|
|
432
443
|
void cs.editMessage(msg.messageId, msg.text, msg.attachments);
|
|
433
444
|
return true;
|
|
@@ -471,7 +482,7 @@ export function handleSessionLifecycleMessage(msg, cs, send) {
|
|
|
471
482
|
void cs.dismissFinishedSubagents(msg.parentId);
|
|
472
483
|
return true;
|
|
473
484
|
case "switch_session":
|
|
474
|
-
void cs.switchSession(msg.path, msg.sessionId);
|
|
485
|
+
void cs.switchSession(msg.path, msg.sessionId, msg.independent);
|
|
475
486
|
return true;
|
|
476
487
|
case "switch_conversation":
|
|
477
488
|
void cs.switchConversation(msg.id);
|
|
@@ -622,7 +633,7 @@ export function handleSettingsMessage(msg, cs, send) {
|
|
|
622
633
|
void cs.saveCommands(msg.commands);
|
|
623
634
|
return true;
|
|
624
635
|
case "get_settings":
|
|
625
|
-
cs.
|
|
636
|
+
cs.refreshSettings();
|
|
626
637
|
return true;
|
|
627
638
|
case "set_settings":
|
|
628
639
|
// SAFETY: Both dispatch engines validate the explicitly enumerated settings fields below.
|
|
@@ -669,6 +680,8 @@ export function handleSettingsMessage(msg, cs, send) {
|
|
|
669
680
|
skillsCatalogMaxDesc: msg.skillsCatalogMaxDesc,
|
|
670
681
|
skillsCatalogShowLocation: msg.skillsCatalogShowLocation,
|
|
671
682
|
skillsCatalogBudget: msg.skillsCatalogBudget,
|
|
683
|
+
skillsMaxFileBytes: msg.skillsMaxFileBytes,
|
|
684
|
+
skillsFullTextMaxBytes: msg.skillsFullTextMaxBytes,
|
|
672
685
|
codemodeMode: msg.codemodeMode,
|
|
673
686
|
codemodeInlineBudget: msg.codemodeInlineBudget,
|
|
674
687
|
visionBridgeEnabled: msg.visionBridgeEnabled,
|
|
@@ -758,6 +771,8 @@ export function handleInteractiveResponseMessage(msg, cs, service, clientId, sen
|
|
|
758
771
|
cs.handleTuiOverlayCancel?.(msg.id);
|
|
759
772
|
return true;
|
|
760
773
|
case "question_answer":
|
|
774
|
+
if (clientId && service.resolveSharedQuestion?.(clientId, msg.id, msg.answers, msg.cancelled, msg.cancelReason))
|
|
775
|
+
return true;
|
|
761
776
|
if (msg.owner) {
|
|
762
777
|
// 跨页作答:答案转交持有方会话(本页不持有该问卷)。
|
|
763
778
|
if (typeof service.answerElsewhereQuestion === "function" && clientId) {
|
|
@@ -777,6 +792,9 @@ export function handleInteractiveResponseMessage(msg, cs, service, clientId, sen
|
|
|
777
792
|
}
|
|
778
793
|
return true;
|
|
779
794
|
case "tool_approval_response":
|
|
795
|
+
if (clientId &&
|
|
796
|
+
service.resolveSharedToolApproval?.(clientId, msg.id, msg.decision, msg.editedParams, msg.reason, msg.scope))
|
|
797
|
+
return true;
|
|
780
798
|
cs.resolveToolApproval?.(msg.id, msg.decision, msg.editedParams, msg.reason, msg.scope);
|
|
781
799
|
return true;
|
|
782
800
|
case "set_approval_policy":
|
|
@@ -3742,6 +3742,9 @@ export class DshClientSession {
|
|
|
3742
3742
|
}
|
|
3743
3743
|
return defs;
|
|
3744
3744
|
}
|
|
3745
|
+
refreshSettings() {
|
|
3746
|
+
this.pushSettings();
|
|
3747
|
+
}
|
|
3745
3748
|
pushSettings() {
|
|
3746
3749
|
if (this.runtime?.alive && !this.cachedEffectiveSystemPrompt) {
|
|
3747
3750
|
void this.refreshPromptInfo().catch(() => { });
|
|
@@ -3799,6 +3802,9 @@ export class DshClientSession {
|
|
|
3799
3802
|
skillsCatalogMaxDesc: 250,
|
|
3800
3803
|
skillsCatalogShowLocation: false,
|
|
3801
3804
|
skillsCatalogBudget: 20000,
|
|
3805
|
+
// DSH 不注入技能正文,但协议字段要齐全(设置页读快照)。
|
|
3806
|
+
skillsMaxFileBytes: 8192,
|
|
3807
|
+
skillsFullTextMaxBytes: 32768,
|
|
3802
3808
|
chatUploadMaxMb: this.stateStore.getSettingsSnapshot(this.clientId).chatUploadMaxMb ?? 20,
|
|
3803
3809
|
workspaceUploadMaxMb: this.stateStore.getSettingsSnapshot(this.clientId).workspaceUploadMaxMb ?? 100,
|
|
3804
3810
|
folderUploadMaxMb: this.stateStore.getSettingsSnapshot(this.clientId).folderUploadMaxMb ?? 32,
|
|
@@ -615,7 +615,7 @@ export class GoalService {
|
|
|
615
615
|
* the existing select/input dialog), converging on a goal, then auto-sets it.
|
|
616
616
|
* Mutually exclusive with the review loop of the same conversation.
|
|
617
617
|
*/
|
|
618
|
-
async startGoalWizard(text, opts) {
|
|
618
|
+
async startGoalWizard(text, opts, target) {
|
|
619
619
|
if (this.host.quiesceBlocked())
|
|
620
620
|
return;
|
|
621
621
|
if (!this.goalEnabled()) {
|
|
@@ -633,8 +633,10 @@ export class GoalService {
|
|
|
633
633
|
// The wizard and its progress cards belong to the conversation that
|
|
634
634
|
// launched it. If the user switches away, do not later set a goal on the
|
|
635
635
|
// new active conversation while the wizard is still finishing.
|
|
636
|
-
const
|
|
637
|
-
|
|
636
|
+
const wizardConversation = target ?? this.host.activeConv();
|
|
637
|
+
if (this.host.getConv(wizardConversation.id) !== wizardConversation)
|
|
638
|
+
return;
|
|
639
|
+
const wizardConversationId = wizardConversation.id;
|
|
638
640
|
const wizardGeneration = wizardConversation.goalGeneration;
|
|
639
641
|
// Human-readable name for notices that must say WHICH conversation the survey
|
|
640
642
|
// belongs to (issue #292: the user is expected to switch away mid-survey).
|
|
@@ -1104,10 +1106,13 @@ export class GoalService {
|
|
|
1104
1106
|
/** Persist goal/review preference defaults (model, rounds cap, locked) without
|
|
1105
1107
|
* touching the active goal — so changes in the goal bar are remembered across
|
|
1106
1108
|
* reloads. maxRounds 0 = unlimited. Emits goal_status so the UI stays synced. */
|
|
1107
|
-
async setGoalPrefs(opts) {
|
|
1109
|
+
async setGoalPrefs(opts, target) {
|
|
1108
1110
|
if (!this.goalEnabled())
|
|
1109
1111
|
return;
|
|
1110
|
-
const
|
|
1112
|
+
const conv = target ?? this.host.activeConv();
|
|
1113
|
+
if (this.host.getConv(conv.id) !== conv)
|
|
1114
|
+
return;
|
|
1115
|
+
const goal = conv.goal;
|
|
1111
1116
|
if (opts?.reviewModel !== undefined)
|
|
1112
1117
|
goal.reviewModel = opts?.reviewModel || null;
|
|
1113
1118
|
if (typeof opts?.maxRounds === "number") {
|
package/dist/server/index.js
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* PI_CODING_AGENT_DIR pi config dir (auth/models/skills) — passed to the SDK
|
|
18
18
|
*/
|
|
19
19
|
import { botExecutionMessageAllowed } from "./device-center/bot-execution.js";
|
|
20
|
+
import { ALL_AGENT_TOOL_ENTRIES, effectiveDisabledAgentTools, isToolSupportedOnPlatform } from "./tool-manager.js";
|
|
20
21
|
// MUST be imported before the SDK is loaded so on-disk patches apply cleanly.
|
|
21
22
|
import "./patch-remote-catalog.js";
|
|
22
23
|
import "./patch-turn-end-boundary.js";
|
|
@@ -1022,6 +1023,10 @@ const deviceCenter = await installLocalDeviceCenter({
|
|
|
1022
1023
|
app,
|
|
1023
1024
|
dataDir: DATA_DIR,
|
|
1024
1025
|
bots: deviceBots,
|
|
1026
|
+
// Reverse-proxied deployments reach the device center (groups) through a real
|
|
1027
|
+
// domain: accept the operator-declared hostnames there too, otherwise every
|
|
1028
|
+
// /api/device-center call is 403 LOCAL_ONLY behind nginx/Caddy.
|
|
1029
|
+
allowHosts: ALLOW_HOSTS,
|
|
1025
1030
|
botCatalog: {
|
|
1026
1031
|
defaultCwd: CWD,
|
|
1027
1032
|
dataDir: DATA_DIR,
|
|
@@ -1033,6 +1038,10 @@ const deviceCenter = await installLocalDeviceCenter({
|
|
|
1033
1038
|
},
|
|
1034
1039
|
projects: () => sharedStateStore.getRecentProjects(""),
|
|
1035
1040
|
defaultModel: () => sharedStateStore.getDefaultModel("pi"),
|
|
1041
|
+
defaultTools: () => {
|
|
1042
|
+
const disabled = new Set(effectiveDisabledAgentTools(sharedStateStore.getSettingsSnapshot("")));
|
|
1043
|
+
return ALL_AGENT_TOOL_ENTRIES.filter((tool) => !disabled.has(tool.name) && isToolSupportedOnPlatform(tool.name)).map((tool) => tool.name);
|
|
1044
|
+
},
|
|
1036
1045
|
peekMcpBridge: (cwd) => mcpProjects.peekBridge(cwd),
|
|
1037
1046
|
},
|
|
1038
1047
|
async connect(config, syncBots) {
|
|
@@ -1051,7 +1060,10 @@ const deviceCenter = await installLocalDeviceCenter({
|
|
|
1051
1060
|
credential: config.credential,
|
|
1052
1061
|
localOrigin,
|
|
1053
1062
|
localAuthToken: AUTH_TOKEN,
|
|
1063
|
+
recovery: runtime.recovery,
|
|
1064
|
+
reportOutbox: runtime.reportOutbox,
|
|
1054
1065
|
onTask: runtime.onTask,
|
|
1066
|
+
onInteractionAnswer: (answer) => runtime.answerTaskInteraction(answer.taskId, answer.attemptId, answer),
|
|
1055
1067
|
onConnect: syncBots,
|
|
1056
1068
|
onCommand: runtime.onCommand,
|
|
1057
1069
|
onDisconnect: () => {
|
|
@@ -1062,6 +1074,7 @@ const deviceCenter = await installLocalDeviceCenter({
|
|
|
1062
1074
|
});
|
|
1063
1075
|
return {
|
|
1064
1076
|
isConnected: connector.isOnline,
|
|
1077
|
+
runtime,
|
|
1065
1078
|
async close() {
|
|
1066
1079
|
setDeviceCollabService(undefined);
|
|
1067
1080
|
connector.close();
|
|
@@ -1459,8 +1472,8 @@ function ensureEngine(engine) {
|
|
|
1459
1472
|
// 启动时预热默认引擎实例
|
|
1460
1473
|
ensureEngine(currentDefaultEngine);
|
|
1461
1474
|
const service = {
|
|
1462
|
-
attach(clientId, send) {
|
|
1463
|
-
return ensureEngine(resolveClientEngine(clientId)).attach(clientId, send);
|
|
1475
|
+
attach(clientId, send, sendShared) {
|
|
1476
|
+
return ensureEngine(resolveClientEngine(clientId)).attach(clientId, send, sendShared);
|
|
1464
1477
|
},
|
|
1465
1478
|
detach(clientId, send) {
|
|
1466
1479
|
const eng = clientEngines.get(clientId);
|
|
@@ -1569,6 +1582,24 @@ const service = {
|
|
|
1569
1582
|
setLocale(clientId, locale) {
|
|
1570
1583
|
return ensureEngine(resolveClientEngine(clientId)).setLocale(clientId, locale);
|
|
1571
1584
|
},
|
|
1585
|
+
openSharedConversation(viewerId, ownerId, convId, send) {
|
|
1586
|
+
return (ensureEngine(resolveClientEngine(viewerId)).openSharedConversation?.(viewerId, ownerId, convId, send) ?? false);
|
|
1587
|
+
},
|
|
1588
|
+
closeSharedConversation(viewerId) {
|
|
1589
|
+
ensureEngine(resolveClientEngine(viewerId)).closeSharedConversation?.(viewerId);
|
|
1590
|
+
},
|
|
1591
|
+
sharedConversationTarget(viewerId) {
|
|
1592
|
+
return ensureEngine(resolveClientEngine(viewerId)).sharedConversationTarget?.(viewerId);
|
|
1593
|
+
},
|
|
1594
|
+
dispatchSharedConversationMessage(viewerId, msg) {
|
|
1595
|
+
return ensureEngine(resolveClientEngine(viewerId)).dispatchSharedConversationMessage?.(viewerId, msg) ?? false;
|
|
1596
|
+
},
|
|
1597
|
+
resolveSharedQuestion(viewerId, id, answers, cancelled, cancelReason) {
|
|
1598
|
+
return (ensureEngine(resolveClientEngine(viewerId)).resolveSharedQuestion?.(viewerId, id, answers, cancelled, cancelReason) ?? false);
|
|
1599
|
+
},
|
|
1600
|
+
resolveSharedToolApproval(viewerId, ...args) {
|
|
1601
|
+
return ensureEngine(resolveClientEngine(viewerId)).resolveSharedToolApproval?.(viewerId, ...args) ?? false;
|
|
1602
|
+
},
|
|
1572
1603
|
takeOverConversation(targetId, ownerId, convId) {
|
|
1573
1604
|
const targetSvc = ensureEngine(resolveClientEngine(targetId));
|
|
1574
1605
|
if (typeof targetSvc.takeOverConversation === "function") {
|
|
@@ -2261,7 +2292,9 @@ wss.on("connection", (ws) => {
|
|
|
2261
2292
|
if (!snapshotRetryTimer) {
|
|
2262
2293
|
snapshotRetryTimer = setTimeout(() => {
|
|
2263
2294
|
snapshotRetryTimer = null;
|
|
2264
|
-
service.
|
|
2295
|
+
if (!service.dispatchSharedConversationMessage?.(clientId ?? "", { type: "get_state" })) {
|
|
2296
|
+
service.get(clientId ?? "")?.flushSnapshot(wasFull);
|
|
2297
|
+
}
|
|
2265
2298
|
}, SNAPSHOT_RETRY_MS);
|
|
2266
2299
|
}
|
|
2267
2300
|
return;
|
|
@@ -2275,7 +2308,26 @@ wss.on("connection", (ws) => {
|
|
|
2275
2308
|
* `send` 必须包在 `sendRaw` **外面**:窗口先裁消息,再算背压字节数——否则
|
|
2276
2309
|
* 背压阈值还在按未裁剪的 10MB 量级估。 */
|
|
2277
2310
|
const windowTap = new MessageWindowTap(sendRaw, readMessageWindowConfig(process.env));
|
|
2278
|
-
const
|
|
2311
|
+
const sendShared = (msg) => {
|
|
2312
|
+
const shared = clientId ? service.sharedConversationTarget?.(clientId) : undefined;
|
|
2313
|
+
windowTap.setScope(shared ? `shared:${JSON.stringify([shared.ownerClientId, shared.conversationId])}` : `local:${clientId}`);
|
|
2314
|
+
windowTap.accept(msg);
|
|
2315
|
+
};
|
|
2316
|
+
const send = (msg) => {
|
|
2317
|
+
if (clientId &&
|
|
2318
|
+
service.sharedConversationTarget?.(clientId) &&
|
|
2319
|
+
(msg.type === "snapshot" ||
|
|
2320
|
+
msg.type === "snapshot_delta" ||
|
|
2321
|
+
msg.type === "tool_delta" ||
|
|
2322
|
+
msg.type === "message_delta" ||
|
|
2323
|
+
msg.type === "terminal_output" ||
|
|
2324
|
+
msg.type === "terminal_list" ||
|
|
2325
|
+
msg.type === "terminal_exit"))
|
|
2326
|
+
return;
|
|
2327
|
+
if (msg.type === "snapshot" || msg.type === "snapshot_delta")
|
|
2328
|
+
windowTap.setScope(`local:${clientId}`);
|
|
2329
|
+
windowTap.accept(msg);
|
|
2330
|
+
};
|
|
2279
2331
|
// Plugins broadcast to every open socket; unregister on close below.
|
|
2280
2332
|
// Plugins broadcast to every open socket; unregister on close below. The
|
|
2281
2333
|
// cid getter lets plugins target THIS socket via host.sendTo(clientId).
|
|
@@ -2359,7 +2411,7 @@ wss.on("connection", (ws) => {
|
|
|
2359
2411
|
const nextSvc = ensureEngine(targetEngine);
|
|
2360
2412
|
const switchGen = ++attachGen;
|
|
2361
2413
|
nextSvc
|
|
2362
|
-
.attach(cid, send)
|
|
2414
|
+
.attach(cid, send, sendShared)
|
|
2363
2415
|
.then((newCs) => {
|
|
2364
2416
|
if (closed) {
|
|
2365
2417
|
nextSvc.detach(cid, send);
|
|
@@ -2411,7 +2463,7 @@ wss.on("connection", (ws) => {
|
|
|
2411
2463
|
setClientEngine(cid, prevEngine);
|
|
2412
2464
|
const rollbackGen = ++attachGen;
|
|
2413
2465
|
ensureEngine(prevEngine)
|
|
2414
|
-
.attach(cid, send)
|
|
2466
|
+
.attach(cid, send, sendShared)
|
|
2415
2467
|
.then((rollbackCs) => {
|
|
2416
2468
|
if (closed || rollbackGen !== attachGen) {
|
|
2417
2469
|
ensureEngine(prevEngine).detach(cid, send);
|
|
@@ -2544,6 +2596,12 @@ wss.on("connection", (ws) => {
|
|
|
2544
2596
|
// 历史窗口按需加载:连接级窗口化直接服务(四个引擎通吃,不依赖引擎实现)。
|
|
2545
2597
|
// 放在引擎分发之前:它不是引擎能力,窗口化关闭时静默无回执(前端保持现状)。
|
|
2546
2598
|
if (msg.type === "load_earlier_messages") {
|
|
2599
|
+
const sharedTarget = service.sharedConversationTarget?.(clientId);
|
|
2600
|
+
if (sharedTarget && msg.conversationId && msg.conversationId !== sharedTarget.conversationId)
|
|
2601
|
+
return;
|
|
2602
|
+
windowTap.setScope(sharedTarget
|
|
2603
|
+
? `shared:${JSON.stringify([sharedTarget.ownerClientId, sharedTarget.conversationId])}`
|
|
2604
|
+
: `local:${clientId}`);
|
|
2547
2605
|
let handled = windowTap.loadEarlier({
|
|
2548
2606
|
count: msg.count,
|
|
2549
2607
|
all: msg.all,
|
|
@@ -2553,9 +2611,14 @@ wss.on("connection", (ws) => {
|
|
|
2553
2611
|
historyGeneration: msg.historyGeneration,
|
|
2554
2612
|
});
|
|
2555
2613
|
if (!handled && cs) {
|
|
2556
|
-
const
|
|
2614
|
+
const shared = service.sharedConversationTarget?.(clientId);
|
|
2615
|
+
const historyOwner = shared?.owner ?? cs;
|
|
2616
|
+
const activeId = shared?.conversationId ??
|
|
2617
|
+
(typeof cs.activeConversationId === "function" ? cs.activeConversationId() : undefined);
|
|
2557
2618
|
const convId = msg.conversationId || activeId;
|
|
2558
|
-
|
|
2619
|
+
if (shared && convId !== shared.conversationId)
|
|
2620
|
+
return;
|
|
2621
|
+
const full = convId ? historyOwner.getMessagesOfConversation?.(convId) : undefined;
|
|
2559
2622
|
if (convId && full && full.length > 0) {
|
|
2560
2623
|
windowTap.rehydrate(convId, full, msg.before);
|
|
2561
2624
|
handled = windowTap.loadEarlier({
|
|
@@ -2568,7 +2631,8 @@ wss.on("connection", (ws) => {
|
|
|
2568
2631
|
});
|
|
2569
2632
|
}
|
|
2570
2633
|
if (!handled && (!msg.conversationId || msg.conversationId === activeId)) {
|
|
2571
|
-
|
|
2634
|
+
if (!service.dispatchSharedConversationMessage?.(clientId, { type: "get_state" }))
|
|
2635
|
+
cs.flushSnapshot(true);
|
|
2572
2636
|
}
|
|
2573
2637
|
}
|
|
2574
2638
|
return;
|
|
@@ -2583,6 +2647,10 @@ wss.on("connection", (ws) => {
|
|
|
2583
2647
|
return;
|
|
2584
2648
|
}
|
|
2585
2649
|
try {
|
|
2650
|
+
if (service.dispatchSharedConversationMessage?.(clientId, msg))
|
|
2651
|
+
return;
|
|
2652
|
+
if (handleInteractiveResponseMessage(msg, cs, service, clientId, send))
|
|
2653
|
+
return;
|
|
2586
2654
|
if (handleFileMessage(msg, cs))
|
|
2587
2655
|
return;
|
|
2588
2656
|
if (handleScmMessage(msg, cs, send))
|
|
@@ -2607,8 +2675,6 @@ wss.on("connection", (ws) => {
|
|
|
2607
2675
|
return;
|
|
2608
2676
|
if (handleCanvasMessage(msg, DATA_DIR, canvasOrchestrator, send, { runBase: cs.cwd }))
|
|
2609
2677
|
return;
|
|
2610
|
-
if (handleInteractiveResponseMessage(msg, cs, service, clientId, send))
|
|
2611
|
-
return;
|
|
2612
2678
|
if (handlePluginMessage(msg, {
|
|
2613
2679
|
pluginMgr,
|
|
2614
2680
|
pluginInstaller,
|
|
@@ -2703,6 +2769,16 @@ wss.on("connection", (ws) => {
|
|
|
2703
2769
|
send({ type: "tool_prompt", name: msg.name, found: false, unsupported: true });
|
|
2704
2770
|
}
|
|
2705
2771
|
break;
|
|
2772
|
+
case "open_shared_conversation":
|
|
2773
|
+
if (!service.openSharedConversation?.(clientId, msg.owner, msg.id, sendShared)) {
|
|
2774
|
+
send({
|
|
2775
|
+
type: "notice",
|
|
2776
|
+
level: "error",
|
|
2777
|
+
text: "共享对话不可用",
|
|
2778
|
+
textEn: "Shared conversation is unavailable.",
|
|
2779
|
+
});
|
|
2780
|
+
}
|
|
2781
|
+
return;
|
|
2706
2782
|
case "take_over_conversation":
|
|
2707
2783
|
if (typeof service.takeOverConversation === "function") {
|
|
2708
2784
|
void service.takeOverConversation(clientId, msg.owner, msg.id);
|
|
@@ -2852,7 +2928,7 @@ wss.on("connection", (ws) => {
|
|
|
2852
2928
|
const msg = parsed;
|
|
2853
2929
|
try {
|
|
2854
2930
|
const botClientId = clientId ?? (msg.type === "hello" ? msg.clientId : undefined);
|
|
2855
|
-
if (botClientId && !botExecutionMessageAllowed(botClientId, msg.type)) {
|
|
2931
|
+
if (botClientId && !botExecutionMessageAllowed(botClientId, msg.type, msg)) {
|
|
2856
2932
|
ws.close(1008, "Bot control command denied");
|
|
2857
2933
|
return;
|
|
2858
2934
|
}
|
|
@@ -2922,7 +2998,7 @@ wss.on("connection", (ws) => {
|
|
|
2922
2998
|
const helloSvc = ensureEngine(resolveClientEngine(cid));
|
|
2923
2999
|
const helloGen = ++attachGen;
|
|
2924
3000
|
helloSvc
|
|
2925
|
-
.attach(cid, send)
|
|
3001
|
+
.attach(cid, send, sendShared)
|
|
2926
3002
|
.then((cs) => {
|
|
2927
3003
|
clearTimeout(slowTimer);
|
|
2928
3004
|
if (closed) {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isPromptAsideEntry } from "./attachments.js";
|
|
2
|
+
/** Context entries retain tombstones; omit deleted messages before resolving UI IDs. */
|
|
3
|
+
export function undeletedContextEntries(entries) {
|
|
4
|
+
const edits = new Map();
|
|
5
|
+
for (const entry of entries) {
|
|
6
|
+
if (entry.type === "context_edit")
|
|
7
|
+
edits.set(entry.targetId, entry.replacement);
|
|
8
|
+
}
|
|
9
|
+
return entries.filter((entry) => edits.get(entry.id) !== null);
|
|
10
|
+
}
|
|
11
|
+
/** Keep deletion local to the selected message, including its attachment/tool records. */
|
|
12
|
+
export function messageDeletionTargets(entries, targetId) {
|
|
13
|
+
const visible = undeletedContextEntries(entries);
|
|
14
|
+
const index = visible.findIndex((entry) => entry.id === targetId);
|
|
15
|
+
const target = visible[index];
|
|
16
|
+
if (!target || target.type !== "message" || !["user", "assistant"].includes(target.message.role)) {
|
|
17
|
+
throw new Error("Message is no longer available for deletion");
|
|
18
|
+
}
|
|
19
|
+
const ids = new Set([target.id]);
|
|
20
|
+
if (target.message.role === "user") {
|
|
21
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
22
|
+
const entry = visible[i];
|
|
23
|
+
if (entry.type === "message" && entry.message.role !== "system" && !isPromptAsideEntry(entry))
|
|
24
|
+
break;
|
|
25
|
+
if (entry.type === "compaction" || entry.type === "branch_summary")
|
|
26
|
+
break;
|
|
27
|
+
if (isPromptAsideEntry(entry))
|
|
28
|
+
ids.add(entry.id);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if (target.message.role === "assistant") {
|
|
32
|
+
const calls = new Set(target.message.content.filter((block) => block.type === "toolCall").map((block) => block.id));
|
|
33
|
+
for (const entry of visible.slice(index + 1)) {
|
|
34
|
+
if (entry.type === "message" && entry.message.role === "toolResult" && calls.has(entry.message.toolCallId)) {
|
|
35
|
+
ids.add(entry.id);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return [...ids];
|
|
40
|
+
}
|
|
@@ -117,6 +117,15 @@ export class MessageWindowTap {
|
|
|
117
117
|
convs = new Map();
|
|
118
118
|
/** 最近一次快照所属的对话 —— `load_earlier_messages` 不带 id,按「当前对话」服务。 */
|
|
119
119
|
lastConversationId = "";
|
|
120
|
+
scope = "";
|
|
121
|
+
/** Local conversation IDs are unique only within an execution owner. */
|
|
122
|
+
setScope(scope) {
|
|
123
|
+
if (this.scope === scope)
|
|
124
|
+
return;
|
|
125
|
+
this.scope = scope;
|
|
126
|
+
this.convs.clear();
|
|
127
|
+
this.lastConversationId = "";
|
|
128
|
+
}
|
|
120
129
|
constructor(send, cfg) {
|
|
121
130
|
this.send = send;
|
|
122
131
|
this.cfg = cfg;
|