pi-web-ui 0.113.1 → 0.114.1
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 +71 -1
- package/README.md +187 -316
- package/README.zh-CN.md +227 -299
- package/README.zh-TW.md +227 -299
- package/bin/device-hub-cli.mjs +577 -0
- package/bin/frp-manager.mjs +1573 -1573
- package/bin/pi-device-hub.mjs +9 -0
- package/bin/pi-web-ui.mjs +4081 -4041
- package/deploy/nginx-subpath.conf +100 -100
- package/deploy/pi-web-ui.service +36 -36
- package/dist/server/agent-service-daemon.js +102 -24
- package/dist/server/agent-service.js +2419 -1174
- package/dist/server/approval-rules.js +29 -3
- package/dist/server/ask-user-question-tool.js +8 -8
- package/dist/server/atomic-file.js +35 -14
- package/dist/server/attachment-store.js +71 -35
- package/dist/server/attachments.js +69 -13
- package/dist/server/canvas/canvas-agent-tool.js +68 -18
- package/dist/server/canvas/canvas-cards.js +1 -1
- package/dist/server/canvas/canvas-dispatch.js +61 -20
- package/dist/server/canvas/canvas-orchestrator.js +519 -202
- package/dist/server/canvas/canvas-scheduled-task.js +45 -0
- package/dist/server/canvas/canvas-scheduler.js +99 -0
- package/dist/server/canvas/canvas-store.js +107 -54
- package/dist/server/canvas/canvas-validation.js +131 -0
- package/dist/server/canvas/canvas-workspace.js +284 -0
- package/dist/server/client-id-utils.js +8 -0
- package/dist/server/client-state.js +110 -24
- package/dist/server/communicate-tool.js +76 -0
- package/dist/server/compact-context-tool.js +2 -3
- package/dist/server/compaction-instructions.js +75 -0
- package/dist/server/compaction-markers.js +7 -2
- package/dist/server/compaction-state.js +84 -0
- package/dist/server/composer-drafts.js +43 -40
- package/dist/server/context-evidence.js +346 -0
- package/dist/server/conversation-communication.js +368 -0
- package/dist/server/conversation-read-tool.js +3 -4
- package/dist/server/conversation-tool-names.js +14 -0
- package/dist/server/conversation-tool.js +57 -0
- package/dist/server/delegate-mode.js +17 -4
- package/dist/server/device-center/bot-catalog.js +88 -0
- package/dist/server/device-center/bot-execution.js +106 -0
- package/dist/server/device-center/bots.js +170 -0
- package/dist/server/device-center/collab-service.js +153 -0
- package/dist/server/device-center/collab-tool.js +184 -0
- package/dist/server/device-center/connector.js +351 -0
- package/dist/server/device-center/desktop-linux.js +372 -0
- package/dist/server/device-center/desktop-native.js +413 -0
- package/dist/server/device-center/desktop-page.js +232 -0
- package/dist/server/device-center/desktop-setup.js +30 -0
- package/dist/server/device-center/desktop.js +387 -0
- package/dist/server/device-center/device-portals.js +241 -0
- package/dist/server/device-center/execution-failure.js +70 -0
- package/dist/server/device-center/executor.js +371 -0
- package/dist/server/device-center/file-sync.js +493 -0
- package/dist/server/device-center/hub-auth.js +69 -0
- package/dist/server/device-center/hub-page.js +68 -0
- package/dist/server/device-center/hub-setup.js +214 -0
- package/dist/server/device-center/hub.js +830 -0
- package/dist/server/device-center/local-hub.js +92 -0
- package/dist/server/device-center/local.js +529 -0
- package/dist/server/device-center/main.js +118 -0
- package/dist/server/device-center/native-desktop/macos.js +192 -0
- package/dist/server/device-center/native-desktop/windows.js +118 -0
- package/dist/server/device-center/path-portal.js +120 -0
- package/dist/server/device-center/relay.js +996 -0
- package/dist/server/device-center/runtime.js +253 -0
- package/dist/server/device-center/store.js +122 -0
- package/dist/server/device-center/task-error.js +14 -0
- package/dist/server/device-center/transfers.js +293 -0
- package/dist/server/device-center/workspaces.js +45 -0
- package/dist/server/dispatch-domain-handlers.js +84 -27
- package/dist/server/dsh/dsh-agent-service.js +282 -159
- package/dist/server/dsh/dsh-client.js +12 -2
- package/dist/server/dsh/runtime/cordis.yml +1 -1
- package/dist/server/dsh/runtime/custom-prompt.mjs +33 -33
- package/dist/server/dsh/runtime/goal-rpc.mjs +1309 -1309
- package/dist/server/dsh/runtime/launcher.mjs +235 -235
- package/dist/server/dsh/runtime/override.patch.yml +89 -89
- package/dist/server/dsh/runtime/runtime-root.mjs +405 -405
- package/dist/server/durable/durable-agent-service.js +1 -1
- package/dist/server/engine-probe.js +36 -6
- package/dist/server/eval-tool.js +135 -135
- package/dist/server/evidence-tool-hooks.js +49 -0
- package/dist/server/file-save.js +95 -0
- package/dist/server/file-transfer-routes.js +97 -47
- package/dist/server/files-service.js +38 -26
- package/dist/server/global-loader.js +40 -2
- package/dist/server/goal-review-gate.js +16 -6
- package/dist/server/goal-service.js +54 -30
- package/dist/server/http-proxy.js +120 -0
- package/dist/server/index.js +285 -255
- package/dist/server/load-timing.js +31 -0
- package/dist/server/mcp-bridge.js +219 -94
- package/dist/server/mcp-hot-reload.js +31 -5
- package/dist/server/mcp-manager.js +192 -93
- package/dist/server/mcp-oauth-login.js +169 -0
- package/dist/server/mcp-oauth-ui.js +137 -0
- package/dist/server/mcp-oauth.js +395 -0
- package/dist/server/mcp-project-runtime.js +207 -0
- package/dist/server/message-window.js +74 -21
- package/dist/server/net-guard.js +122 -20
- package/dist/server/patch-bash-process.js +125 -0
- package/dist/server/patch-tool.js +9 -9
- package/dist/server/patch-turn-end-boundary.js +3 -3
- package/dist/server/payload-limits.js +17 -0
- package/dist/server/pending-question.js +82 -0
- package/dist/server/persona-chain.js +8 -8
- package/dist/server/plan-mode.js +338 -137
- package/dist/server/plugin-assets.js +8 -4
- package/dist/server/plugin-chat-attachments.js +48 -0
- package/dist/server/plugin-facilities.js +67 -220
- package/dist/server/plugin-installer.js +2 -1
- package/dist/server/plugin-removal.js +49 -0
- package/dist/server/plugin-secrets.js +179 -0
- package/dist/server/plugins.js +288 -94
- package/dist/server/preset-fields.js +56 -0
- package/dist/server/preset-plugin-dependencies.js +57 -0
- package/dist/server/preset-share.js +113 -72
- package/dist/server/prompt-templates.js +106 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/queue-modes.js +10 -0
- package/dist/server/remote-ssh-service.js +199 -106
- package/dist/server/request-context.js +164 -0
- package/dist/server/resolve-global-sdk.js +2 -0
- package/dist/server/sandbox-data.js +655 -0
- package/dist/server/sandbox-engines.js +7 -0
- package/dist/server/sandbox-runtime-gate.js +41 -0
- package/dist/server/sandbox-service.js +139 -698
- package/dist/server/sandbox-tool.js +21 -4
- package/dist/server/schedule-agent-tool.js +39 -21
- package/dist/server/scheduler-tasks.js +106 -55
- package/dist/server/scm-commitmsg.js +10 -10
- package/dist/server/serialize.js +48 -19
- package/dist/server/session-branch.js +25 -3
- package/dist/server/session-parser.js +28 -18
- package/dist/server/session-scan.js +130 -0
- package/dist/server/session-search.js +51 -37
- package/dist/server/settings-service.js +273 -111
- package/dist/server/setup-config.js +58 -0
- package/dist/server/setup-page.js +620 -620
- package/dist/server/skill-maintenance.js +112 -24
- package/dist/server/subagent-helpers.js +4 -1
- package/dist/server/subagent-notify.js +4 -1
- package/dist/server/subagent-security-gate.js +52 -11
- package/dist/server/subagent-task.js +27 -0
- package/dist/server/subagents.js +217 -46
- package/dist/server/tabs.js +9 -1
- package/dist/server/terminals.js +467 -363
- package/dist/server/text-quote.js +9 -0
- package/dist/server/tool-guards.js +42 -6
- package/dist/server/tool-manager.js +48 -20
- package/dist/server/tool-overrides.js +13 -11
- package/dist/server/tool-prompt-overrides.js +32 -2
- package/dist/server/tool-prompts.js +1 -1
- package/dist/server/turn-timing.js +11 -0
- package/dist/server/universal/drivers/claude-code.js +5 -0
- package/dist/server/universal/drivers/codex.js +336 -0
- package/dist/server/universal/index.js +1 -0
- package/dist/server/universal/session-store.js +48 -6
- package/dist/server/universal/universal-attachments.js +24 -1
- package/dist/server/universal/universal-service.js +1 -1
- package/dist/server/universal/universal-session.js +357 -231
- package/dist/server/uploads.js +64 -5
- package/dist/server/vision-bridge.js +18 -18
- package/dist/server/worktree-service.js +32 -24
- package/dist/server/ws-pending-queue.js +73 -27
- package/docs/device-center.md +148 -0
- package/docs/device-desktop.md +48 -0
- package/docs/dsh-engine.md +493 -493
- package/extensions/webui.ts +335 -335
- package/package.json +5 -2
- package/plugin-sdk/README.md +174 -174
- package/plugin-sdk/client-utils.mjs +279 -279
- package/plugin-sdk/import-check.mjs +210 -210
- package/plugin-sdk/index.d.ts +698 -676
- package/plugin-sdk/index.mjs +696 -696
- package/plugin-sdk/package.json +13 -13
- package/plugin-sdk/ssh-host-trust.mjs +225 -0
- package/plugins/catalog.json +11 -1
- package/themes/aetheris.css +501 -607
- package/themes/ayu-light.css +116 -140
- package/themes/bases/flow-base.css +1357 -1363
- package/themes/bases/obsidian-base.css +895 -895
- package/themes/bases/statusbar-flat-base.css +112 -0
- package/themes/bases/zhujian-base.css +688 -687
- package/themes/bases/zhupi-base.css +660 -659
- package/themes/catppuccin-latte.css +119 -142
- package/themes/catppuccin.css +116 -147
- package/themes/claude-code-dark.css +147 -146
- package/themes/codex.css +114 -138
- package/themes/cyberpunk.css +50 -108
- package/themes/dark-teal.css +264 -265
- package/themes/dazzle.css +38 -108
- package/themes/everforest-light.css +115 -138
- package/themes/flow-light.css +164 -164
- package/themes/flow.css +161 -161
- package/themes/geist.css +114 -138
- package/themes/gruvbox-light.css +115 -138
- package/themes/kanagawa-lotus.css +115 -138
- package/themes/md-preview.css +24 -234
- package/themes/mist.css +166 -186
- package/themes/nord.css +107 -138
- package/themes/one-dark.css +106 -139
- package/themes/paper.css +174 -186
- package/themes/rose-pine-dawn.css +114 -138
- package/themes/sakura.css +166 -186
- package/themes/solarized-light.css +114 -137
- package/themes/tokyo-night.css +115 -146
- package/themes/translucent.css +85 -85
- package/themes/transparent.css +116 -116
- package/themes/vs-code-dark.css +147 -147
- package/themes/wallpaper-flow.css +382 -382
- package/themes/wallpaper-obsidian.css +74 -74
- package/themes/white.css +164 -186
- package/themes/zhujian-dark.css +115 -114
- package/themes/zhujian.css +114 -114
- package/themes/zhupi-dark.css +115 -114
- package/themes/zhupi.css +114 -114
- package/web/dist/.build-assets.json +1 -0
- package/web/dist/assets/BgTasksModal-BcXJ20RO.js +1 -0
- package/web/dist/assets/BgTasksModal-DjQmiKnE.js +1 -0
- package/web/dist/assets/CanvasStudio-PI9pid0Y.js +1579 -0
- package/web/dist/assets/CanvasStudio-nf5-HxLM.js +1579 -0
- package/web/dist/assets/DeviceCenter-CYttJw2a.js +3 -0
- package/web/dist/assets/DeviceCenter-DPe4sz74.js +3 -0
- package/web/dist/assets/DeviceGroups-D2rogxEN.js +1 -0
- package/web/dist/assets/Dropdown-ZLS04O8p.js +1 -0
- package/web/dist/assets/FilePreview-C9Ut4Lq6.js +2 -0
- package/web/dist/assets/FilePreview-CvK3ZzX5.js +2 -0
- package/web/dist/assets/GlobalSearchModal-C5e-OCw2.js +1 -0
- package/web/dist/assets/GlobalSearchModal-H7pFK2UC.js +1 -0
- package/web/dist/assets/GroupConversation-C2wNM0dQ.js +1 -0
- package/web/dist/assets/GroupConversation-ChN3TWQK.js +1 -0
- package/web/dist/assets/ModelConfigModal-DDZccDYt.js +2 -0
- package/web/dist/assets/PiSetupModal-DHbqfx8T.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-C-MK36Dk.js +1 -0
- package/web/dist/assets/SCMPanel-buTGziDB.js +2 -0
- package/web/dist/assets/SCMPanel-kx-SCL2s.js +2 -0
- package/web/dist/assets/SettingsModal-BsUF8jqr.js +20 -0
- package/web/dist/assets/SettingsModal-D357Ky7P.js +20 -0
- package/web/dist/assets/TerminalPanel-BBuM_Sez.js +3 -0
- package/web/dist/assets/TerminalPanel-D6x6xz8Q.js +3 -0
- package/web/dist/assets/TuiOverlayModal-CdbGV3Za.js +1 -0
- package/web/dist/assets/TuiOverlayModal-d6x9u25n.js +1 -0
- package/web/dist/assets/app-globals-DcyO0UPi.js +1 -0
- package/web/dist/assets/desktop-YguLbrX1.js +1 -0
- package/web/dist/assets/es-DWMIuDU2.js +2 -0
- package/web/dist/assets/fi-DaSO0Q-m.js +325 -0
- package/web/dist/assets/index-BPvpea8t.js +85 -0
- package/web/dist/assets/index-D6u8xH0o.js +85 -0
- package/web/dist/assets/index-DDZMv6LO.css +1 -0
- package/web/dist/assets/markdown-BggnuQ4H.js +40 -0
- package/web/dist/assets/markdown-C8LL_u4z.css +1 -0
- package/web/dist/assets/math-1uRJCsA9.js +257 -0
- package/web/dist/assets/math-BorAY7qD.css +1 -0
- package/web/dist/assets/plugin-host-BRBg6zmQ.js +1 -0
- package/web/dist/assets/shortcut-stack-hhrDyRBn.js +1 -0
- package/web/dist/assets/theme-DDl-Oy1b.js +1 -0
- package/web/dist/assets/uuid-BzDIGCwP.js +1 -0
- package/web/dist/index.html +42 -35
- package/web/dist/sw.js +179 -179
- package/web/public/sw.js +179 -179
- package/dist/gh-comment-781.md +0 -5
- package/dist/server/durable/durable-capabilities.js +0 -11
- package/dist/server/markers/builtins/services.js +0 -123
- package/dist/server/markers/builtins/todo.js +0 -189
- package/dist/server/markers-list-tool.js +0 -34
- package/dist/server/orchestrator.js +0 -109
- package/dist/server/system-prompt-soul.js +0 -41
- package/dist/server/univer-service.js +0 -448
- package/dist/server/universal/drivers/dsh-driver.js +0 -379
- package/dist/test-artifact.md +0 -9
- package/dist/test-preview-modal.md +0 -11
- package/dist/test-report.html +0 -20
- package/web/dist/assets/TerminalPanel-Ci55JtJL.js +0 -3
- package/web/dist/assets/index-ByiO9f-N.js +0 -2008
- package/web/dist/assets/index-ycGLh4a4.css +0 -1
- package/web/dist/assets/markdown-BJZlfvdP.js +0 -296
- package/web/dist/assets/markdown-DSNUiDzp.css +0 -1
|
@@ -482,9 +482,13 @@ export class GoalService {
|
|
|
482
482
|
* and not be thrown away.
|
|
483
483
|
*/
|
|
484
484
|
async setGoal(goalText, opts) {
|
|
485
|
+
await this.commitGoal(goalText, opts);
|
|
486
|
+
}
|
|
487
|
+
/** Return the exact committed request so callers can guard follow-up work. */
|
|
488
|
+
async commitGoal(goalText, opts) {
|
|
485
489
|
const text = (goalText ?? "").trim();
|
|
486
490
|
if (!text) {
|
|
487
|
-
await this.clearGoal();
|
|
491
|
+
await this.clearGoal(opts?.targetConvId);
|
|
488
492
|
return;
|
|
489
493
|
}
|
|
490
494
|
if (!this.goalEnabled()) {
|
|
@@ -529,12 +533,14 @@ export class GoalService {
|
|
|
529
533
|
}
|
|
530
534
|
const conv = targetConv ?? this.host.activeConv();
|
|
531
535
|
const goalConversationId = conv.id;
|
|
532
|
-
conv.goalGeneration
|
|
536
|
+
const gen = ++conv.goalGeneration;
|
|
533
537
|
// 上一轮目标可能还留着常驻执行者子代理(委托执行):先停掉再开新的,
|
|
534
538
|
// 否则旧循环会在新目标上继续派活(代次已作废,但角色对话得收)。
|
|
535
539
|
// await 到 dismiss 完全落定:后面的 spawn 名额检查才不会数到还在收尾的
|
|
536
540
|
// 旧执行者而误报上限(issue #464;stopDelegated 自身已按会话串行化)。
|
|
537
541
|
await this.stopDelegated(conv);
|
|
542
|
+
if (!this.isCurrentGoalRequest(conv, gen))
|
|
543
|
+
return;
|
|
538
544
|
const goal = conv.goal;
|
|
539
545
|
goal.reviewing = false;
|
|
540
546
|
goal.conversationId = goalConversationId;
|
|
@@ -586,11 +592,8 @@ export class GoalService {
|
|
|
586
592
|
text: `🎯 已设目标:${text.slice(0, 80)}${text.length > 80 ? "…" : ""}`,
|
|
587
593
|
textEn: `🎯 Goal set: ${text.slice(0, 80)}${text.length > 80 ? "…" : ""}`,
|
|
588
594
|
});
|
|
589
|
-
//
|
|
590
|
-
// the wizard's internal one, which kicks off itself). This makes the direct
|
|
591
|
-
// goal-bar path behave like the AI-提炼 path: set a target → agent begins.
|
|
595
|
+
// Direct requests auto-start; the wizard commits its plan before starting.
|
|
592
596
|
if (opts?.autoStart !== false) {
|
|
593
|
-
const gen = conv.goalGeneration;
|
|
594
597
|
// #591:主对话若仍在跑设目标前的旧任务,首轮派发执行者前先中断让位,
|
|
595
598
|
// 避免主对话与目标执行者在同一工作区并行动工、污染采样 diff。
|
|
596
599
|
await this.preemptMainRunForGoal(conv, gen);
|
|
@@ -602,6 +605,7 @@ export class GoalService {
|
|
|
602
605
|
this.startDelegatedLoop(conv, gen, text);
|
|
603
606
|
this.host.flushSnapshot();
|
|
604
607
|
}
|
|
608
|
+
return { conv, generation: gen };
|
|
605
609
|
}
|
|
606
610
|
/**
|
|
607
611
|
* Collaborative target wizard. Turns a raw user requirement into a refined
|
|
@@ -631,6 +635,7 @@ export class GoalService {
|
|
|
631
635
|
// new active conversation while the wizard is still finishing.
|
|
632
636
|
const wizardConversationId = this.host.activeConvId();
|
|
633
637
|
const wizardConversation = this.host.activeConv();
|
|
638
|
+
const wizardGeneration = wizardConversation.goalGeneration;
|
|
634
639
|
// Human-readable name for notices that must say WHICH conversation the survey
|
|
635
640
|
// belongs to (issue #292: the user is expected to switch away mid-survey).
|
|
636
641
|
const wizardConversationTitle = wizardConversation.title;
|
|
@@ -1051,16 +1056,16 @@ export class GoalService {
|
|
|
1051
1056
|
});
|
|
1052
1057
|
return;
|
|
1053
1058
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
this.host.setPlan?.(wizardConversationId, parsedSteps);
|
|
1059
|
+
if (targetConv !== wizardConversation || !this.isCurrentGoalRequest(wizardConversation, wizardGeneration)) {
|
|
1060
|
+
return;
|
|
1057
1061
|
}
|
|
1062
|
+
const switchedAway = this.host.activeConvId() !== wizardConversationId;
|
|
1058
1063
|
// Auto-set the refined goal. The wizard workflow implies "set a goal and
|
|
1059
1064
|
// work until it passes", so default LOCKED=true unless the user explicitly
|
|
1060
1065
|
// turned the lock off (a lock lets the review loop keep revising to pass;
|
|
1061
1066
|
// without it the review is single-shot).
|
|
1062
1067
|
const wantLocked = opts?.locked === undefined ? true : opts.locked;
|
|
1063
|
-
await this.
|
|
1068
|
+
const committed = await this.commitGoal(refinedGoal, {
|
|
1064
1069
|
reviewModel: wgoal.reviewModel ?? undefined,
|
|
1065
1070
|
maxRounds: opts?.maxRounds,
|
|
1066
1071
|
locked: wantLocked,
|
|
@@ -1069,9 +1074,21 @@ export class GoalService {
|
|
|
1069
1074
|
// Land the goal on the conversation that launched the survey, even if the
|
|
1070
1075
|
// user is looking at another one right now (issue #292).
|
|
1071
1076
|
targetConvId: wizardConversationId,
|
|
1072
|
-
// The wizard kicks off generation itself below — avoid a double kick.
|
|
1073
1077
|
autoStart: false,
|
|
1074
1078
|
});
|
|
1079
|
+
if (!committed || !this.isCurrentDelegated(committed.conv, committed.generation))
|
|
1080
|
+
return;
|
|
1081
|
+
if (parsedSteps.length > 0) {
|
|
1082
|
+
this.host.setPlan?.(wizardConversationId, parsedSteps);
|
|
1083
|
+
}
|
|
1084
|
+
// Preserve plan-before-execution ordering, and retain the commit token across preemption.
|
|
1085
|
+
if (!this.isCurrentDelegated(committed.conv, committed.generation))
|
|
1086
|
+
return;
|
|
1087
|
+
await this.preemptMainRunForGoal(committed.conv, committed.generation);
|
|
1088
|
+
if (!this.isCurrentDelegated(committed.conv, committed.generation))
|
|
1089
|
+
return;
|
|
1090
|
+
this.startDelegatedLoop(committed.conv, committed.generation, refinedGoal);
|
|
1091
|
+
this.host.flushSnapshot();
|
|
1075
1092
|
this.wizardCancelled = false;
|
|
1076
1093
|
this.host.emit({
|
|
1077
1094
|
type: "notice",
|
|
@@ -1083,12 +1100,6 @@ export class GoalService {
|
|
|
1083
1100
|
? `🎯 Survey done in "${wizardConversationTitle}", goal set: ${refinedGoal.slice(0, 80)}${refinedGoal.length > 80 ? "…" : ""} (switch back to that conversation to watch it generate)`
|
|
1084
1101
|
: `🎯 Survey done, goal set: ${refinedGoal.slice(0, 80)}${refinedGoal.length > 80 ? "…" : ""}`,
|
|
1085
1102
|
});
|
|
1086
|
-
// 目标模式 2.0(唯一路径):不向主对话注入「开始实现」——它在目标模式下是审查者,
|
|
1087
|
-
// 干活的另有执行对话,改由服务端循环驱动(setGoal 已把 goal 落在发起会话上)。
|
|
1088
|
-
if (targetConv.goal.goal) {
|
|
1089
|
-
this.startDelegatedLoop(targetConv, targetConv.goalGeneration, targetConv.goal.goal);
|
|
1090
|
-
this.host.flushSnapshot();
|
|
1091
|
-
}
|
|
1092
1103
|
}
|
|
1093
1104
|
/** Persist goal/review preference defaults (model, rounds cap, locked) without
|
|
1094
1105
|
* touching the active goal — so changes in the goal bar are remembered across
|
|
@@ -1133,19 +1144,24 @@ export class GoalService {
|
|
|
1133
1144
|
});
|
|
1134
1145
|
this.emitGoalStatus();
|
|
1135
1146
|
}
|
|
1136
|
-
/** Clear the
|
|
1137
|
-
*
|
|
1138
|
-
async clearGoal() {
|
|
1139
|
-
const conv = this.host.activeConv();
|
|
1140
|
-
|
|
1147
|
+
/** Clear the specified conversation's goal, or the active one by default.
|
|
1148
|
+
* Cancels its review loop and any running goal wizard. */
|
|
1149
|
+
async clearGoal(target) {
|
|
1150
|
+
const conv = typeof target === "string" ? this.host.getConv(target) : (target ?? this.host.activeConv());
|
|
1151
|
+
// Missing/stale explicit targets must never fall back to the active conversation.
|
|
1152
|
+
if (!conv || this.host.isDisposed() || this.host.getConv(conv.id) !== conv)
|
|
1153
|
+
return;
|
|
1154
|
+
const gen = ++conv.goalGeneration;
|
|
1141
1155
|
// 委托执行:停掉在飞的执行者(循环靠代次作废 + 代次守卫退出)。
|
|
1142
1156
|
// await 落定,保证旧执行者已移出会话表,后续重设目标不再误报名额(issue #464)。
|
|
1143
1157
|
await this.stopDelegated(conv);
|
|
1158
|
+
if (!this.isCurrentGoalRequest(conv, gen))
|
|
1159
|
+
return;
|
|
1144
1160
|
this.resetLoopCounters(conv);
|
|
1145
1161
|
this.clearGoalFields(conv);
|
|
1146
1162
|
this.emitGoalStatus();
|
|
1147
1163
|
// Abort a running wizard for real (✗ in the goal bar while scoping).
|
|
1148
|
-
if (this.wizardOwnerId ===
|
|
1164
|
+
if (this.wizardOwnerId === conv.id) {
|
|
1149
1165
|
await this.abortWizard();
|
|
1150
1166
|
}
|
|
1151
1167
|
}
|
|
@@ -1179,10 +1195,12 @@ export class GoalService {
|
|
|
1179
1195
|
const conv = this.host.getConv(convId);
|
|
1180
1196
|
if (!conv)
|
|
1181
1197
|
continue;
|
|
1182
|
-
conv.goalGeneration
|
|
1198
|
+
const gen = ++conv.goalGeneration; // 作废在飞回调(循环靠代次守卫退出)
|
|
1183
1199
|
// 逐个 await 停/收落定(stopDelegated 已按会话串行化,issue #464):
|
|
1184
1200
|
// 停执行者 + 唤醒 verdict 等待者 + 清 roles/phase
|
|
1185
1201
|
await this.stopDelegated(conv);
|
|
1202
|
+
if (!this.isCurrentGoalRequest(conv, gen))
|
|
1203
|
+
continue;
|
|
1186
1204
|
this.resetLoopCounters(conv);
|
|
1187
1205
|
this.clearGoalFields(conv);
|
|
1188
1206
|
stopped++;
|
|
@@ -1298,13 +1316,13 @@ export class GoalService {
|
|
|
1298
1316
|
const v = this.host.roleDeadlineMs?.();
|
|
1299
1317
|
return typeof v === "number" && v > 0 ? v : 20 * 60_000;
|
|
1300
1318
|
}
|
|
1319
|
+
/** Mutation requests remain valid even before a goal exists. Never adopt a newer generation. */
|
|
1320
|
+
isCurrentGoalRequest(conv, goalGeneration) {
|
|
1321
|
+
return !this.host.isDisposed() && this.host.getConv(conv.id) === conv && conv.goalGeneration === goalGeneration;
|
|
1322
|
+
}
|
|
1301
1323
|
/** 代次守卫:目标没被改/清、会话还在才算本轮有效。 */
|
|
1302
1324
|
isCurrentDelegated(conv, goalGeneration) {
|
|
1303
|
-
return
|
|
1304
|
-
this.host.getConv(conv.id) === conv &&
|
|
1305
|
-
conv.goal.conversationId === conv.id &&
|
|
1306
|
-
conv.goalGeneration === goalGeneration &&
|
|
1307
|
-
!!conv.goal.goal);
|
|
1325
|
+
return this.isCurrentGoalRequest(conv, goalGeneration) && conv.goal.conversationId === conv.id && !!conv.goal.goal;
|
|
1308
1326
|
}
|
|
1309
1327
|
isConvStreaming(conv) {
|
|
1310
1328
|
try {
|
|
@@ -1326,6 +1344,8 @@ export class GoalService {
|
|
|
1326
1344
|
* 仅在首轮派发前生效(按 goalGeneration 去重),委托执行期间用户在主对话发起的新聊天不受影响。
|
|
1327
1345
|
*/
|
|
1328
1346
|
async preemptMainRunForGoal(conv, goalGeneration) {
|
|
1347
|
+
if (!this.isCurrentDelegated(conv, goalGeneration))
|
|
1348
|
+
return;
|
|
1329
1349
|
if (!this.isConvStreaming(conv))
|
|
1330
1350
|
return;
|
|
1331
1351
|
if (conv.preemptedGoalGen === goalGeneration)
|
|
@@ -1357,6 +1377,8 @@ export class GoalService {
|
|
|
1357
1377
|
}
|
|
1358
1378
|
/** 启动委托循环(同一对话同时只允许一个在飞;旧循环退场中到来的请求排队接力)。 */
|
|
1359
1379
|
startDelegatedLoop(conv, goalGeneration, goalText) {
|
|
1380
|
+
if (!this.isCurrentDelegated(conv, goalGeneration))
|
|
1381
|
+
return;
|
|
1360
1382
|
if (this.delegatedLoops.has(conv.id)) {
|
|
1361
1383
|
this.delegatedPending.set(conv.id, { goalGeneration, goalText });
|
|
1362
1384
|
return;
|
|
@@ -1486,6 +1508,7 @@ export class GoalService {
|
|
|
1486
1508
|
return run;
|
|
1487
1509
|
}
|
|
1488
1510
|
async stopDelegatedNow(conv) {
|
|
1511
|
+
const gen = conv.goalGeneration;
|
|
1489
1512
|
// 排队的启动请求一并作废:setGoal 会在后面按新代次重新排,clearGoal 则不需要。
|
|
1490
1513
|
this.delegatedPending.delete(conv.id);
|
|
1491
1514
|
conv.awaitingVerdict = undefined;
|
|
@@ -1509,7 +1532,8 @@ export class GoalService {
|
|
|
1509
1532
|
}
|
|
1510
1533
|
catch { }
|
|
1511
1534
|
}
|
|
1512
|
-
conv
|
|
1535
|
+
if (this.isCurrentGoalRequest(conv, gen))
|
|
1536
|
+
conv.goal.phase = "idle";
|
|
1513
1537
|
}
|
|
1514
1538
|
/** 会话过户时清理目标审查态并唤醒等待者(issue #457)。 */
|
|
1515
1539
|
notifyTakeover(conv) {
|
|
@@ -10,6 +10,126 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
10
10
|
import { join } from "node:path";
|
|
11
11
|
import { EventEmitter } from "node:events";
|
|
12
12
|
import { createRequire } from "node:module";
|
|
13
|
+
import { request as proxyRequest } from "node:http";
|
|
14
|
+
export function proxyForwardPath(hit, url) {
|
|
15
|
+
let fwd = String(url ?? "/").slice(hit.prefix.length);
|
|
16
|
+
if (!fwd.startsWith("/"))
|
|
17
|
+
fwd = `/${fwd}`;
|
|
18
|
+
return fwd || "/";
|
|
19
|
+
}
|
|
20
|
+
/** Forward plugin traffic and propagate cancellation without truncating successful responses. */
|
|
21
|
+
export function proxyHttp(hit, req, res) {
|
|
22
|
+
if (hit.pluginId === "live-preview" && req.path === hit.prefix) {
|
|
23
|
+
res.redirect(302, `${hit.prefix}/${req.url.slice(req.path.length)}`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const fwdPath = proxyForwardPath(hit, req.url ?? "/");
|
|
27
|
+
const headers = {};
|
|
28
|
+
for (const [k, v] of Object.entries(req.headers)) {
|
|
29
|
+
if (v === undefined)
|
|
30
|
+
continue;
|
|
31
|
+
if (k.toLowerCase() === "host")
|
|
32
|
+
continue;
|
|
33
|
+
if (hit.pluginId === "live-preview" && ["cookie", "authorization", "x-pi-token"].includes(k.toLowerCase()))
|
|
34
|
+
continue;
|
|
35
|
+
if (k.toLowerCase() === "content-length" && req.method !== "GET" && req.method !== "HEAD")
|
|
36
|
+
continue;
|
|
37
|
+
headers[k] = v;
|
|
38
|
+
}
|
|
39
|
+
headers["x-pi-proxy-prefix"] = hit.prefix;
|
|
40
|
+
let body;
|
|
41
|
+
if (req.method !== "GET" && req.method !== "HEAD" && req.body !== undefined) {
|
|
42
|
+
const b = req.body;
|
|
43
|
+
if (Buffer.isBuffer(b))
|
|
44
|
+
body = b;
|
|
45
|
+
else if (typeof b === "string")
|
|
46
|
+
body = Buffer.from(b);
|
|
47
|
+
else if (b !== undefined) {
|
|
48
|
+
body = Buffer.from(JSON.stringify(b));
|
|
49
|
+
if (!headers["content-type"])
|
|
50
|
+
headers["content-type"] = "application/json";
|
|
51
|
+
}
|
|
52
|
+
if (body)
|
|
53
|
+
headers["content-length"] = String(body.length);
|
|
54
|
+
}
|
|
55
|
+
let upstream;
|
|
56
|
+
let cancelled = false;
|
|
57
|
+
const cancel = () => {
|
|
58
|
+
if (cancelled)
|
|
59
|
+
return;
|
|
60
|
+
cancelled = true;
|
|
61
|
+
upstream?.destroy();
|
|
62
|
+
up.destroy();
|
|
63
|
+
};
|
|
64
|
+
const cleanup = () => {
|
|
65
|
+
req.off("aborted", onAborted);
|
|
66
|
+
req.off("error", onRequestError);
|
|
67
|
+
res.off("close", onClose);
|
|
68
|
+
res.off("error", onResponseError);
|
|
69
|
+
res.off("finish", cleanup);
|
|
70
|
+
};
|
|
71
|
+
const onAborted = () => {
|
|
72
|
+
cancel();
|
|
73
|
+
res.destroy();
|
|
74
|
+
cleanup();
|
|
75
|
+
};
|
|
76
|
+
const onRequestError = () => onAborted();
|
|
77
|
+
const onResponseError = () => {
|
|
78
|
+
cancel();
|
|
79
|
+
cleanup();
|
|
80
|
+
};
|
|
81
|
+
const onClose = () => {
|
|
82
|
+
if (!res.writableFinished)
|
|
83
|
+
cancel();
|
|
84
|
+
cleanup();
|
|
85
|
+
};
|
|
86
|
+
const fail = () => {
|
|
87
|
+
cancel();
|
|
88
|
+
if (res.destroyed || res.writableEnded)
|
|
89
|
+
return;
|
|
90
|
+
if (!res.headersSent)
|
|
91
|
+
res.status(502).end("proxy target unreachable");
|
|
92
|
+
else
|
|
93
|
+
res.destroy();
|
|
94
|
+
};
|
|
95
|
+
const up = proxyRequest({ host: hit.host, port: hit.port, method: req.method, path: fwdPath, headers, timeout: 30000 }, (upRes) => {
|
|
96
|
+
upstream = upRes;
|
|
97
|
+
upRes.on("aborted", fail);
|
|
98
|
+
upRes.on("error", fail);
|
|
99
|
+
upRes.on("close", () => {
|
|
100
|
+
if (!upRes.complete)
|
|
101
|
+
fail();
|
|
102
|
+
});
|
|
103
|
+
if (cancelled || res.destroyed) {
|
|
104
|
+
upRes.destroy();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const out = {};
|
|
108
|
+
for (const [k, v] of Object.entries(upRes.headers)) {
|
|
109
|
+
if (v === undefined)
|
|
110
|
+
continue;
|
|
111
|
+
const lk = k.toLowerCase();
|
|
112
|
+
if (lk === "connection" || lk === "keep-alive" || lk === "transfer-encoding" || lk === "upgrade")
|
|
113
|
+
continue;
|
|
114
|
+
out[k] = v;
|
|
115
|
+
}
|
|
116
|
+
res.writeHead(upRes.statusCode ?? 502, out);
|
|
117
|
+
upRes.pipe(res);
|
|
118
|
+
});
|
|
119
|
+
up.on("timeout", () => up.destroy(new Error("proxy timeout")));
|
|
120
|
+
up.on("error", fail);
|
|
121
|
+
req.on("aborted", onAborted);
|
|
122
|
+
req.on("error", onRequestError);
|
|
123
|
+
res.on("close", onClose);
|
|
124
|
+
res.on("error", onResponseError);
|
|
125
|
+
res.on("finish", cleanup);
|
|
126
|
+
if (req.aborted || res.destroyed)
|
|
127
|
+
onAborted();
|
|
128
|
+
else if (body)
|
|
129
|
+
up.end(body);
|
|
130
|
+
else
|
|
131
|
+
req.pipe(up);
|
|
132
|
+
}
|
|
13
133
|
/** Read proxy settings from settings.json and environment. */
|
|
14
134
|
export function resolveProxySettings(agentDir) {
|
|
15
135
|
let httpProxy;
|