@waq666/pneuma 0.7.1 → 0.8.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/README.md +242 -206
- package/bin/dsc.js +9 -3
- package/bin/headless.cjs +1 -1
- package/lib/adapter/transcript.d.ts +19 -2
- package/lib/adapter/transcript.js +71 -14
- package/lib/app/AgentsOverlay.js +7 -6
- package/lib/app/App.js +1 -1
- package/lib/app/ApprovalCard.js +15 -9
- package/lib/app/ChatView.d.ts +3 -1
- package/lib/app/ChatView.js +21 -17
- package/lib/app/Composer.js +22 -4
- package/lib/app/MarkdownView.js +2 -1
- package/lib/app/ModelPicker.js +7 -6
- package/lib/app/PickerFrame.d.ts +4 -0
- package/lib/app/PickerFrame.js +18 -0
- package/lib/app/PlanReviewCard.js +2 -1
- package/lib/app/PresetPicker.js +8 -7
- package/lib/app/SessionPicker.js +21 -20
- package/lib/app/SettingsOverlay.js +1 -1
- package/lib/app/SkillsPicker.js +7 -6
- package/lib/app/StatusBar.js +3 -15
- package/lib/app/TaskStrips.js +1 -4
- package/lib/app/TimelineRail.js +2 -1
- package/lib/app/ToolCard.js +2 -6
- package/lib/app/Welcome.d.ts +1 -0
- package/lib/app/Welcome.js +1 -4
- package/lib/app/click.d.ts +0 -2
- package/lib/app/click.js +2 -21
- package/lib/app/display-width.d.ts +16 -0
- package/lib/app/display-width.js +33 -0
- package/lib/app/markdown.d.ts +1 -3
- package/lib/app/markdown.js +2 -19
- package/lib/app/scroll-model.js +1 -1
- package/lib/contract/approval.d.ts +91 -0
- package/lib/contract/approval.js +1 -0
- package/lib/contract/mode.d.ts +69 -0
- package/lib/contract/mode.js +1 -0
- package/lib/contract/plugin.d.ts +240 -0
- package/lib/contract/plugin.js +1 -0
- package/lib/contract/runtime.d.ts +282 -0
- package/lib/contract/runtime.js +1 -0
- package/lib/contract/session.d.ts +208 -0
- package/lib/contract/session.js +36 -0
- package/lib/contract/settings.d.ts +242 -0
- package/lib/contract/settings.js +1 -0
- package/lib/contract/snapshot.d.ts +453 -0
- package/lib/contract/snapshot.js +1 -0
- package/lib/contract/task.d.ts +189 -0
- package/lib/contract/task.js +10 -0
- package/lib/contract/transcript.d.ts +358 -0
- package/lib/contract/transcript.js +1 -0
- package/lib/contract/usage.d.ts +132 -0
- package/lib/contract/usage.js +10 -0
- package/lib/contract.d.ts +20 -1968
- package/lib/contract.js +19 -30
- package/lib/core/agent-roles.d.ts +1 -1
- package/lib/core/agent-roles.js +6 -5
- package/lib/core/approval-floor.d.ts +9 -0
- package/lib/core/approval-floor.js +152 -25
- package/lib/core/attachments.d.ts +185 -0
- package/lib/core/attachments.js +425 -0
- package/lib/core/bytes.d.ts +14 -0
- package/lib/core/bytes.js +28 -0
- package/lib/core/call-meaning.d.ts +20 -0
- package/lib/core/call-meaning.js +347 -0
- package/lib/core/cdp/actions.js +6 -0
- package/lib/core/cdp/launch.js +2 -2
- package/lib/core/cdp/report.d.ts +27 -0
- package/lib/core/cdp/report.js +50 -0
- package/lib/core/cdp/ring-buffer.d.ts +25 -0
- package/lib/core/cdp/ring-buffer.js +44 -0
- package/lib/core/cdp/snapshot.js +5 -9
- package/lib/core/cdp/transport.js +1 -1
- package/lib/core/clamp.d.ts +20 -0
- package/lib/core/clamp.js +24 -0
- package/lib/core/clock.d.ts +16 -0
- package/lib/core/clock.js +20 -0
- package/lib/core/command-policy.js +33 -1
- package/lib/core/commands-completion.d.ts +28 -0
- package/lib/core/commands-completion.js +108 -30
- package/lib/core/compact.d.ts +36 -6
- package/lib/core/compact.js +89 -17
- package/lib/core/desktop-control.js +1 -3
- package/lib/core/dsh-compat/llm-usage-event.d.ts +78 -0
- package/lib/core/dsh-compat/llm-usage-event.js +91 -0
- package/lib/core/dsh-compat/presentation.d.ts +84 -0
- package/lib/core/dsh-compat/presentation.js +105 -0
- package/lib/core/dsh-compat/resolve-hook.d.ts +3 -3
- package/lib/core/dsh-compat/resolve-hook.js +41 -13
- package/lib/core/dsh-compat/service-map.d.ts +52 -0
- package/lib/core/dsh-compat/service-map.js +87 -0
- package/lib/core/dsh-compat/session-bridge.d.ts +107 -0
- package/lib/core/dsh-compat/session-bridge.js +376 -0
- package/lib/core/dsh-compat/session-events.d.ts +54 -0
- package/lib/core/dsh-compat/session-events.js +297 -0
- package/lib/core/dsh-compat/shims/credentials.d.ts +62 -0
- package/lib/core/dsh-compat/shims/credentials.js +86 -0
- package/lib/core/dsh-compat/shims/home-paths.d.ts +77 -0
- package/lib/core/dsh-compat/shims/home-paths.js +143 -0
- package/lib/core/dsh-compat/tools-facade.d.ts +31 -1
- package/lib/core/dsh-compat/tools-facade.js +207 -3
- package/lib/core/err-text.d.ts +5 -0
- package/lib/core/err-text.js +5 -0
- package/lib/core/events.d.ts +31 -2
- package/lib/core/git-info.d.ts +127 -15
- package/lib/core/git-info.js +315 -34
- package/lib/core/git-surface.d.ts +17 -0
- package/lib/core/git-surface.js +7 -0
- package/lib/core/hooks.d.ts +19 -2
- package/lib/core/hooks.js +57 -13
- package/lib/core/host-methods.d.ts +1 -1
- package/lib/core/host-methods.js +4 -0
- package/lib/core/image-diet.js +1 -4
- package/lib/core/json-text.d.ts +11 -0
- package/lib/core/json-text.js +18 -0
- package/lib/core/learnings/skill-write.d.ts +1 -7
- package/lib/core/learnings/skill-write.js +3 -37
- package/lib/core/lifecycle-hooks.d.ts +11 -3
- package/lib/core/lifecycle-hooks.js +33 -42
- package/lib/core/llm.d.ts +42 -0
- package/lib/core/llm.js +40 -25
- package/lib/core/loop.d.ts +11 -1
- package/lib/core/loop.js +95 -28
- package/lib/core/lsp/client.js +30 -17
- package/lib/core/lsp/normalize.d.ts +0 -2
- package/lib/core/lsp/normalize.js +1 -6
- package/lib/core/lsp/servers.js +1 -4
- package/lib/core/mcp.d.ts +18 -0
- package/lib/core/mcp.js +60 -16
- package/lib/core/microcompact.d.ts +45 -0
- package/lib/core/microcompact.js +128 -0
- package/lib/core/native-bridge.js +2 -10
- package/lib/core/path-policy.d.ts +13 -1
- package/lib/core/path-policy.js +87 -18
- package/lib/core/permission-presets.d.ts +9 -5
- package/lib/core/permission-presets.js +14 -7
- package/lib/core/permission-scope.d.ts +65 -0
- package/lib/core/permission-scope.js +109 -0
- package/lib/core/plugin-bundle.d.ts +95 -0
- package/lib/core/plugin-bundle.js +137 -0
- package/lib/core/plugin-loader.d.ts +36 -1
- package/lib/core/plugin-loader.js +336 -12
- package/lib/core/plugin-patch.d.ts +64 -0
- package/lib/core/plugin-patch.js +146 -0
- package/lib/core/plugin-registry.d.ts +14 -0
- package/lib/core/plugin-registry.js +2 -0
- package/lib/core/prefs.js +40 -2
- package/lib/core/presets.d.ts +11 -0
- package/lib/core/presets.js +61 -22
- package/lib/core/profile-dir.d.ts +5 -0
- package/lib/core/profile-dir.js +40 -0
- package/lib/core/prompt.js +55 -19
- package/lib/core/ptc.d.ts +8 -2
- package/lib/core/ptc.js +18 -4
- package/lib/core/records.d.ts +16 -0
- package/lib/core/records.js +22 -0
- package/lib/core/remote/notify.js +1 -3
- package/lib/core/remote/push.js +2 -6
- package/lib/core/sandbox/execpolicy.js +27 -3
- package/lib/core/sandbox/net-proxy.js +2 -2
- package/lib/core/sandbox/policy.d.ts +1 -1
- package/lib/core/sandbox/policy.js +21 -15
- package/lib/core/sandbox/win/account.js +1 -4
- package/lib/core/sandbox/win/acl.js +1 -6
- package/lib/core/sandbox/win/backend.d.ts +24 -3
- package/lib/core/sandbox/win/backend.js +73 -23
- package/lib/core/sandbox/win/doctor.js +1 -4
- package/lib/core/sandbox/win/runner-entry.js +1 -6
- package/lib/core/sandbox/win/setup.js +1 -4
- package/lib/core/sandbox/win/utf16.d.ts +11 -0
- package/lib/core/sandbox/win/utf16.js +15 -0
- package/lib/core/sandbox/win/wfp.js +1 -4
- package/lib/core/schedule/rule.d.ts +0 -17
- package/lib/core/schedule/rule.js +1 -3
- package/lib/core/schedule/runner.d.ts +5 -2
- package/lib/core/schedule/runner.js +32 -9
- package/lib/core/schedule/store.d.ts +0 -2
- package/lib/core/schedule/store.js +2 -9
- package/lib/core/session-index.d.ts +50 -0
- package/lib/core/session-index.js +169 -3
- package/lib/core/session.d.ts +89 -13
- package/lib/core/session.js +385 -32
- package/lib/core/shell-quote.d.ts +21 -0
- package/lib/core/shell-quote.js +24 -0
- package/lib/core/side-ask.d.ts +52 -0
- package/lib/core/side-ask.js +89 -0
- package/lib/core/skills.d.ts +16 -0
- package/lib/core/skills.js +45 -8
- package/lib/core/snapshot-throttle.d.ts +8 -0
- package/lib/core/snapshot-throttle.js +24 -0
- package/lib/core/spill.d.ts +11 -5
- package/lib/core/spill.js +35 -36
- package/lib/core/strings.d.ts +21 -0
- package/lib/core/strings.js +33 -0
- package/lib/core/terminal-env.d.ts +61 -0
- package/lib/core/terminal-env.js +327 -0
- package/lib/core/text-format.d.ts +17 -0
- package/lib/core/text-format.js +26 -0
- package/lib/core/todo-reminder.d.ts +19 -14
- package/lib/core/todo-reminder.js +14 -23
- package/lib/core/token-estimate.d.ts +18 -2
- package/lib/core/token-estimate.js +10 -2
- package/lib/core/tool-result-prune.d.ts +42 -0
- package/lib/core/tool-result-prune.js +47 -0
- package/lib/core/tool-search.d.ts +3 -2
- package/lib/core/tool-search.js +3 -2
- package/lib/core/tools/bash.d.ts +35 -3
- package/lib/core/tools/bash.js +168 -41
- package/lib/core/tools/fs-tools.js +18 -17
- package/lib/core/tools/image-tool.d.ts +2 -0
- package/lib/core/tools/image-tool.js +59 -0
- package/lib/core/tools/path-args.d.ts +4 -0
- package/lib/core/tools/path-args.js +22 -0
- package/lib/core/tools/search-tools.d.ts +30 -0
- package/lib/core/tools/search-tools.js +321 -34
- package/lib/core/tools.d.ts +82 -0
- package/lib/core/tools.js +21 -0
- package/lib/core/transcript-text.d.ts +19 -0
- package/lib/core/transcript-text.js +44 -0
- package/lib/core/ui-boot-source.d.ts +5 -0
- package/lib/core/ui-boot-source.js +10 -3
- package/lib/core/ui-bundles.d.ts +80 -6
- package/lib/core/ui-bundles.js +700 -76
- package/lib/core/ui-events.d.ts +10 -0
- package/lib/core/ui-events.js +25 -0
- package/lib/core/ui-methods.d.ts +1 -1
- package/lib/core/ui-methods.js +42 -13
- package/lib/core/ui-route.js +11 -7
- package/lib/core/ui-server.d.ts +6 -0
- package/lib/core/ui-server.js +106 -1
- package/lib/core/unified-diff.d.ts +35 -0
- package/lib/core/unified-diff.js +86 -0
- package/lib/core/usage-log.js +39 -0
- package/lib/core/web-http.d.ts +1 -1
- package/lib/core/web-http.js +1 -3
- package/lib/host/kernel.js +57 -41
- package/lib/plugins/agent.js +101 -20
- package/lib/plugins/approval-floor.js +12 -8
- package/lib/plugins/approval.js +252 -80
- package/lib/plugins/ask.js +60 -8
- package/lib/plugins/browser.js +32 -84
- package/lib/plugins/commands.js +167 -57
- package/lib/plugins/compact.d.ts +2 -2
- package/lib/plugins/compact.js +200 -30
- package/lib/plugins/computer-use.js +34 -18
- package/lib/plugins/dock-browser.js +24 -65
- package/lib/plugins/dsh-compat.js +7 -0
- package/lib/plugins/file-review.js +59 -15
- package/lib/plugins/git.js +16 -8
- package/lib/plugins/goal.js +9 -8
- package/lib/plugins/hooks.js +4 -2
- package/lib/plugins/host-stdio.js +14 -16
- package/lib/plugins/lifecycle-hooks.d.ts +5 -4
- package/lib/plugins/lifecycle-hooks.js +12 -10
- package/lib/plugins/llm.js +74 -33
- package/lib/plugins/lsp.js +22 -27
- package/lib/plugins/mcp.js +16 -17
- package/lib/plugins/memory.js +3 -24
- package/lib/plugins/microcompact.d.ts +4 -1
- package/lib/plugins/microcompact.js +117 -19
- package/lib/plugins/mode.js +30 -11
- package/lib/plugins/permission-presets.d.ts +2 -1
- package/lib/plugins/permission-presets.js +55 -35
- package/lib/plugins/plugin-manager.js +4 -6
- package/lib/plugins/presets.js +56 -27
- package/lib/plugins/prompt.js +54 -11
- package/lib/plugins/ptc.d.ts +13 -0
- package/lib/plugins/ptc.js +121 -24
- package/lib/plugins/remote/types.d.ts +1 -1
- package/lib/plugins/remote/types.js +11 -0
- package/lib/plugins/remote.js +14 -15
- package/lib/plugins/runtime.js +91 -14
- package/lib/plugins/sandbox.js +181 -60
- package/lib/plugins/schedule.js +12 -11
- package/lib/plugins/self-improve.js +28 -18
- package/lib/plugins/session-search.js +18 -13
- package/lib/plugins/session-title.js +1 -1
- package/lib/plugins/session.js +103 -25
- package/lib/plugins/settings.js +16 -40
- package/lib/plugins/skills.js +18 -1
- package/lib/plugins/spill.js +18 -11
- package/lib/plugins/subagent.js +208 -42
- package/lib/plugins/team.js +11 -5
- package/lib/plugins/todo.d.ts +1 -1
- package/lib/plugins/todo.js +25 -19
- package/lib/plugins/tool-search.js +47 -28
- package/lib/plugins/tools-default.js +89 -5
- package/lib/plugins/tools.js +3 -3
- package/lib/plugins/transcript.js +116 -9
- package/lib/plugins/web-search.d.ts +1 -1
- package/lib/plugins/web-search.js +25 -16
- package/lib/plugins/webserver.js +40 -7
- package/lib/remote/assets/app-B3Id1EBq.js +14 -0
- package/lib/remote/assets/index.html +2 -2
- package/lib/remote/assets/{style-DIB6729x.css → style-NtlpbKOI.css} +1 -1
- package/lib/services/types.d.ts +247 -29
- package/lib/tools/plugin-cli.d.ts +1 -0
- package/lib/tools/plugin-cli.js +209 -0
- package/lib/ui/assets/app-B-Jx5dnh.js +90 -0
- package/lib/ui/assets/{chunk-BajyYBss.js → chunk-Bfdlo8Me.js} +1 -1
- package/lib/ui/assets/chunk-DGX-i4eb.js +12 -0
- package/lib/ui/assets/index.html +62 -14
- package/lib/ui/assets/style-WzxwEPaE.css +1 -0
- package/lib/ui/frames.js +1 -3
- package/lib/ui/index.d.ts +30 -1
- package/lib/ui/index.js +29 -0
- package/lib/ui/manifest.d.ts +24 -6
- package/lib/ui/manifest.js +3 -2
- package/lib/ui/plugins/actions/bundle.json +8 -0
- package/lib/ui/plugins/actions/client.js +43 -0
- package/lib/ui/plugins/ask/bundle.json +8 -0
- package/lib/ui/plugins/ask/client.js +415 -0
- package/lib/ui/plugins/browser/bundle.json +8 -0
- package/lib/ui/plugins/composer/bundle.json +9 -0
- package/lib/ui/plugins/composer/client.js +1806 -1087
- package/lib/ui/plugins/files/bundle.json +8 -0
- package/lib/ui/plugins/files/client.js +13 -98
- package/lib/ui/plugins/manifest.json +1 -104
- package/lib/ui/plugins/palette/bundle.json +8 -0
- package/lib/ui/plugins/palette/client.js +360 -0
- package/lib/ui/plugins/plugins/bundle.json +8 -0
- package/lib/ui/plugins/plugins/client.js +116 -38
- package/lib/ui/plugins/preview/bundle.json +8 -0
- package/lib/ui/plugins/preview/client.js +6 -16
- package/lib/ui/plugins/prompt/bundle.json +8 -0
- package/lib/ui/plugins/prompt/client.js +81 -47
- package/lib/ui/plugins/sessions/bundle.json +8 -0
- package/lib/ui/plugins/sessions/client.js +157 -111
- package/lib/ui/plugins/settings/bundle.json +8 -0
- package/lib/ui/plugins/settings/client.js +184 -170
- package/lib/ui/plugins/skills/bundle.json +8 -0
- package/lib/ui/plugins/skills/client.js +161 -79
- package/lib/ui/plugins/status/bundle.json +8 -0
- package/lib/ui/plugins/status/client.js +165 -26
- package/lib/ui/plugins/statusbar/bundle.json +9 -0
- package/lib/ui/plugins/statusbar/client.js +100 -144
- package/lib/ui/plugins/tasks/bundle.json +8 -0
- package/lib/ui/plugins/team/bundle.json +8 -0
- package/lib/ui/plugins/team/client.js +60 -58
- package/lib/ui/plugins/terminal/bundle.json +8 -0
- package/lib/ui/plugins/terminal/client.js +1 -7
- package/lib/ui/plugins/trace/bundle.json +11 -0
- package/lib/ui/plugins/trace/client.js +86 -179
- package/lib/ui/plugins/transcript/bundle.json +8 -0
- package/lib/ui/plugins/transcript/client.js +1608 -1243
- package/lib/ui/sdk/@dsc/ui/index.d.ts +54 -16
- package/lib/ui/sdk/@dsc/ui/package.json +1 -1
- package/lib/ui/sdk/@dsc/ui-core/contract.d.ts +20 -1968
- package/lib/ui/sdk/@dsc/ui-core/core/attachments.d.ts +185 -0
- package/lib/ui/sdk/@dsc/ui-core/core/bytes.d.ts +14 -0
- package/lib/ui/sdk/@dsc/ui-core/core/err-text.d.ts +18 -0
- package/lib/ui/sdk/@dsc/ui-core/core/git-surface.d.ts +17 -0
- package/lib/ui/sdk/@dsc/ui-core/core/json-text.d.ts +11 -0
- package/lib/ui/sdk/@dsc/ui-core/core/path-policy.d.ts +44 -0
- package/lib/ui/sdk/@dsc/ui-core/core/records.d.ts +16 -0
- package/lib/ui/sdk/@dsc/ui-core/core/throughput.d.ts +46 -0
- package/lib/ui/sdk/@dsc/ui-core/core/token-estimate.d.ts +18 -2
- package/lib/ui/sdk/@dsc/ui-core/core/unified-diff.d.ts +35 -0
- package/lib/ui/sdk/@dsc/ui-core/package.json +1 -1
- package/lib/ui/sdk/@dsc/ui-core/ui/index.d.ts +30 -1
- package/lib/ui/sdk/@dsc/ui-core/ui/manifest.d.ts +24 -6
- package/lib/ui/sdk/@dsc/ui-core/ui/services.d.ts +19 -8
- package/lib/ui/sdk/@dsc/ui-core/ui/signal.d.ts +49 -0
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-model.d.ts +17 -3
- package/lib/ui/sdk/@dsc/ui-dockkit/dock-state.d.ts +1 -1
- package/lib/ui/sdk/@dsc/ui-dockkit/package.json +1 -1
- package/lib/ui/sdk/@dsc/ui-layout/app.d.ts +4 -0
- package/lib/ui/sdk/@dsc/ui-layout/appearance.d.ts +6 -1
- package/lib/ui/sdk/@dsc/ui-layout/host-channel.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-layout/index.d.ts +1 -0
- package/lib/ui/sdk/@dsc/ui-layout/package.json +1 -1
- package/lib/ui/sdk/@dsc/ui-layout/page-state.d.ts +1 -1
- package/lib/ui/sdk/@dsc/ui-layout/runtime-context.d.ts +10 -1
- package/lib/ui/sdk/@dsc/ui-layout/thread-view.d.ts +1 -1
- package/lib/ui/sdk/@dsc/ui-layout/usage-today.d.ts +11 -0
- package/lib/ui/sdk/@dsc/ui-primitives/dialog-focus.d.ts +30 -0
- package/lib/ui/sdk/@dsc/ui-primitives/error-text.d.ts +12 -0
- package/lib/ui/sdk/@dsc/ui-primitives/git-surface.d.ts +9 -0
- package/lib/ui/sdk/@dsc/ui-primitives/highlight.d.ts +23 -0
- package/lib/ui/sdk/@dsc/ui-primitives/humanize-error.d.ts +35 -0
- package/lib/ui/sdk/@dsc/ui-primitives/icons-workspace.d.ts +33 -0
- package/lib/ui/sdk/@dsc/ui-primitives/icons.d.ts +21 -3
- package/lib/ui/sdk/@dsc/ui-primitives/image-lightbox.d.ts +21 -0
- package/lib/ui/sdk/@dsc/ui-primitives/index.d.ts +16 -0
- package/lib/ui/sdk/@dsc/ui-primitives/markdown.d.ts +10 -14
- package/lib/ui/sdk/@dsc/ui-primitives/package.json +1 -1
- package/lib/ui/sdk/@dsc/ui-primitives/panels.d.ts +31 -8
- package/lib/ui/sdk/@dsc/ui-primitives/paths.d.ts +2 -0
- package/lib/ui/sdk/@dsc/ui-primitives/review-findings-card.d.ts +25 -0
- package/lib/ui/sdk/@dsc/ui-primitives/review-findings.d.ts +64 -0
- package/lib/ui/sdk/@dsc/ui-primitives/review-notice-card.d.ts +27 -0
- package/lib/ui/sdk/@dsc/ui-primitives/review-notice.d.ts +80 -0
- package/lib/ui/sdk/@dsc/ui-primitives/signal.d.ts +9 -0
- package/lib/ui/sdk/@dsc/ui-primitives/sizes.d.ts +15 -0
- package/lib/ui/sdk/@dsc/ui-primitives/skeleton.d.ts +39 -0
- package/lib/ui/sdk/@dsc/ui-primitives/snapshot.d.ts +46 -0
- package/lib/ui/sdk/@dsc/ui-primitives/thread-resizer.d.ts +3 -3
- package/lib/ui/sdk/@dsc/ui-primitives/throughput.d.ts +13 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tokens.d.ts +9 -0
- package/lib/ui/sdk/@dsc/ui-primitives/tool-args.d.ts +1 -1
- package/lib/ui/sdk/@dsc/ui-primitives/tool-summary.d.ts +30 -6
- package/lib/ui/sdk/@dsc/ui-primitives/unified-diff.d.ts +10 -0
- package/lib/ui/sdk/@dsc/ui-renderer/boot.d.ts +10 -1
- package/lib/ui/sdk/@dsc/ui-renderer/cordis-host.d.ts +113 -0
- package/lib/ui/sdk/@dsc/ui-renderer/package.json +1 -1
- package/lib/ui/sdk/@dsc/ui-slots/package.json +1 -1
- package/lib/ui/services.d.ts +19 -8
- package/lib/ui/services.js +20 -12
- package/lib/ui/signal.d.ts +49 -0
- package/lib/ui/signal.js +57 -0
- package/lib/ui/tui-plugins.js +36 -16
- package/package.json +71 -58
- package/lib/remote/assets/app-DAcUCOEn.js +0 -14
- package/lib/ui/assets/app-B70nVIKd.js +0 -69
- package/lib/ui/assets/chunk-BGcgwlCI.js +0 -12
- package/lib/ui/assets/style-Bq01xH_b.css +0 -1
|
@@ -4,6 +4,7 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
|
|
|
4
4
|
const jsxRuntime = require("react/jsx-runtime");
|
|
5
5
|
const react = require("react");
|
|
6
6
|
const ui$1 = require("@dsc/ui");
|
|
7
|
+
const uiPrimitives = require("@dsc/ui-primitives");
|
|
7
8
|
const MAX_FILES = 500;
|
|
8
9
|
const MAX_DEPTH = 4;
|
|
9
10
|
const CACHE_MS = 6e4;
|
|
@@ -156,6 +157,21 @@ function insertCommand(command) {
|
|
|
156
157
|
function blockedNow(command, working) {
|
|
157
158
|
return working && command.duringTask === "deny";
|
|
158
159
|
}
|
|
160
|
+
function claimInput(commands, value) {
|
|
161
|
+
const trimmed = value.trimEnd();
|
|
162
|
+
if (!trimmed.startsWith("/")) return null;
|
|
163
|
+
const body = trimmed.slice(1);
|
|
164
|
+
const match = /^(\S+)(?:\s+([\s\S]*))?$/.exec(body);
|
|
165
|
+
if (match === null) return null;
|
|
166
|
+
const word = match[1] ?? "";
|
|
167
|
+
if ((match[2] ?? "").trim() !== "") return null;
|
|
168
|
+
const lower = word.toLowerCase();
|
|
169
|
+
const exact = commands.find((command) => command.name === word);
|
|
170
|
+
const prefix = commands.filter((command) => command.name.toLowerCase().startsWith(lower));
|
|
171
|
+
const spec = exact ?? (prefix.length === 1 ? prefix[0] : void 0) ?? (prefix.filter((command) => command.input !== void 0).length === 1 ? prefix.find((command) => command.input !== void 0) : void 0);
|
|
172
|
+
if (spec === void 0 || spec.input === void 0) return null;
|
|
173
|
+
return { insert: `/${spec.name} `, hint: spec.input.hint };
|
|
174
|
+
}
|
|
159
175
|
let cache = null;
|
|
160
176
|
let unavailable = false;
|
|
161
177
|
function useCommandMenu(options) {
|
|
@@ -215,22 +231,46 @@ function useCommandMenu(options) {
|
|
|
215
231
|
latest.current = null;
|
|
216
232
|
setOpen(false);
|
|
217
233
|
};
|
|
234
|
+
const hide = () => {
|
|
235
|
+
latest.current = null;
|
|
236
|
+
dismissed.current = null;
|
|
237
|
+
setOpen(false);
|
|
238
|
+
};
|
|
218
239
|
const pick = () => {
|
|
219
240
|
const inserted = insertText();
|
|
220
241
|
if (inserted === null) return;
|
|
242
|
+
adopt(inserted);
|
|
243
|
+
};
|
|
244
|
+
const adopt = (text) => {
|
|
221
245
|
latest.current = null;
|
|
222
246
|
dismissed.current = null;
|
|
223
247
|
setOpen(false);
|
|
224
|
-
apply(
|
|
248
|
+
apply(text, text.length);
|
|
249
|
+
};
|
|
250
|
+
const claim = (value) => {
|
|
251
|
+
if (cache === null) return null;
|
|
252
|
+
return claimInput(cache, value);
|
|
225
253
|
};
|
|
226
254
|
const insertText = () => {
|
|
227
255
|
if (latest.current === null) return null;
|
|
228
256
|
const command = current.current[at];
|
|
229
257
|
return command === void 0 ? null : insertCommand(command);
|
|
230
258
|
};
|
|
231
|
-
return { open, rows, loading, at, track, move, pick, close, insertText };
|
|
259
|
+
return { open, rows, loading, at, track, move, pick, close, hide, insertText, claim, adopt };
|
|
260
|
+
}
|
|
261
|
+
const GLYPHS = {
|
|
262
|
+
new: ui$1.IconNewChat,
|
|
263
|
+
compact: ui$1.IconLayers,
|
|
264
|
+
status: ui$1.IconActivity,
|
|
265
|
+
usage: ui$1.IconChart,
|
|
266
|
+
diff: ui$1.IconDiff,
|
|
267
|
+
review: ui$1.IconCode,
|
|
268
|
+
help: ui$1.IconInfo
|
|
269
|
+
};
|
|
270
|
+
function commandGlyph(name) {
|
|
271
|
+
return GLYPHS[name] ?? null;
|
|
232
272
|
}
|
|
233
|
-
const EMPTY_DRAFT = { value: "", history: [] };
|
|
273
|
+
const EMPTY_DRAFT = { value: "", history: [], attachments: [] };
|
|
234
274
|
function draftScopeOf(input) {
|
|
235
275
|
if (input.unsaved && input.cwd !== "") {
|
|
236
276
|
return { key: `new:${input.cwd}`, sessionId: input.sessionId, unsaved: true };
|
|
@@ -244,55 +284,466 @@ function carryDraft(store, previous, next, current) {
|
|
|
244
284
|
else store.set(previous.key, current);
|
|
245
285
|
return store.get(next.key) ?? EMPTY_DRAFT;
|
|
246
286
|
}
|
|
247
|
-
const
|
|
248
|
-
const
|
|
249
|
-
const
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
287
|
+
const MAX_IMAGES = 20;
|
|
288
|
+
const MAX_IMAGE_BYTES = 20 * 1024 * 1024;
|
|
289
|
+
const TARGET_IMAGE_BYTES = 4 * 1024 * 1024;
|
|
290
|
+
const MAX_IMAGE_EDGE = 2048;
|
|
291
|
+
const MAX_FRAME_EDGE = 1280;
|
|
292
|
+
const SEEK_TIMEOUT_MS = 5e3;
|
|
293
|
+
const FRAME_TOTAL_TIMEOUT_MS = 45e3;
|
|
294
|
+
const IMAGE_MIME = /* @__PURE__ */ new Set(["image/png", "image/jpeg", "image/jpg", "image/webp", "image/gif"]);
|
|
295
|
+
const IMAGE_EXT = /\.(png|jpe?g|webp|gif)$/i;
|
|
296
|
+
const IMAGE_FORMAT_ERROR = "仅支持 PNG、JPG、WebP、GIF 格式的图片";
|
|
297
|
+
const IMAGE_TOO_LARGE_ERROR = "单张图片超过 20 MB,先缩小一点";
|
|
298
|
+
let nextId = 0;
|
|
299
|
+
function newAttachmentId() {
|
|
300
|
+
nextId += 1;
|
|
301
|
+
return `attach-${String(Date.now())}-${String(nextId)}`;
|
|
254
302
|
}
|
|
255
|
-
function
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
303
|
+
function displayNameOf(file, kind) {
|
|
304
|
+
if (file.name !== "") return file.name;
|
|
305
|
+
if (kind === "image") return "粘贴的图片.png";
|
|
306
|
+
if (kind === "video") return "粘贴的视频.mp4";
|
|
307
|
+
return "附件";
|
|
259
308
|
}
|
|
260
|
-
function
|
|
261
|
-
if (
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
309
|
+
function kindOf(file) {
|
|
310
|
+
if (file.type.startsWith("image/")) return "image";
|
|
311
|
+
if (file.type.startsWith("video/")) return "video";
|
|
312
|
+
return "file";
|
|
313
|
+
}
|
|
314
|
+
function uploadFile(file, name, onProgress) {
|
|
315
|
+
return new Promise((resolve, reject) => {
|
|
316
|
+
const xhr = new XMLHttpRequest();
|
|
317
|
+
xhr.open("POST", `/api/attachments?name=${encodeURIComponent(name)}`);
|
|
318
|
+
xhr.responseType = "text";
|
|
319
|
+
xhr.upload.onprogress = (event) => {
|
|
320
|
+
if (!event.lengthComputable || event.total <= 0) return;
|
|
321
|
+
onProgress?.(Math.min(1, event.loaded / event.total));
|
|
270
322
|
};
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const body = open === -1 ? text : close === -1 ? text.slice(open + 1) : text.slice(open + 1, close);
|
|
279
|
-
return {
|
|
280
|
-
label: `${who}${state === "" ? "" : ` ${state}`},交回了 findings,本步结束会交给模型`,
|
|
281
|
-
detail: flatten(body)
|
|
323
|
+
xhr.onload = () => {
|
|
324
|
+
const parsed = parseAttachmentResponse(xhr.responseText);
|
|
325
|
+
if (xhr.status >= 200 && xhr.status < 300 && parsed.ok && parsed.meta !== null) {
|
|
326
|
+
resolve(parsed.meta);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
reject(new Error(parsed.error !== "" ? parsed.error : `上传失败(HTTP ${String(xhr.status)})`));
|
|
282
330
|
};
|
|
331
|
+
xhr.onerror = () => {
|
|
332
|
+
reject(new Error("上传失败:网络连接中断"));
|
|
333
|
+
};
|
|
334
|
+
xhr.ontimeout = () => {
|
|
335
|
+
reject(new Error("上传失败:等宿主响应超时"));
|
|
336
|
+
};
|
|
337
|
+
xhr.onabort = () => {
|
|
338
|
+
reject(new Error("上传已取消"));
|
|
339
|
+
};
|
|
340
|
+
xhr.send(file);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
function parseAttachmentResponse(text) {
|
|
344
|
+
let body = null;
|
|
345
|
+
try {
|
|
346
|
+
body = JSON.parse(text);
|
|
347
|
+
} catch {
|
|
348
|
+
return { ok: false, meta: null, error: "" };
|
|
283
349
|
}
|
|
284
|
-
if (
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
350
|
+
if (typeof body !== "object" || body === null) return { ok: false, meta: null, error: "" };
|
|
351
|
+
const record = body;
|
|
352
|
+
const error = typeof record["error"] === "string" ? record["error"] : "";
|
|
353
|
+
if (record["ok"] !== true) return { ok: false, meta: null, error };
|
|
354
|
+
const meta = record["attachment"];
|
|
355
|
+
if (typeof meta !== "object" || meta === null) return { ok: false, meta: null, error };
|
|
356
|
+
const item = meta;
|
|
357
|
+
const kind = item["kind"];
|
|
358
|
+
if (kind !== "image" && kind !== "video" && kind !== "file") return { ok: false, meta: null, error };
|
|
359
|
+
if (typeof item["sha"] !== "string" || typeof item["name"] !== "string" || typeof item["mime"] !== "string" || typeof item["bytes"] !== "number" || typeof item["url"] !== "string" || typeof item["path"] !== "string") {
|
|
360
|
+
return { ok: false, meta: null, error };
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
ok: true,
|
|
364
|
+
meta: {
|
|
365
|
+
sha: item["sha"],
|
|
366
|
+
kind,
|
|
367
|
+
name: item["name"],
|
|
368
|
+
mime: item["mime"],
|
|
369
|
+
bytes: item["bytes"],
|
|
370
|
+
url: item["url"],
|
|
371
|
+
path: item["path"]
|
|
372
|
+
},
|
|
373
|
+
error
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
async function normalizeImage(file) {
|
|
377
|
+
if (file.size > MAX_IMAGE_BYTES) throw new Error(IMAGE_TOO_LARGE_ERROR);
|
|
378
|
+
const mime = file.type.toLowerCase();
|
|
379
|
+
if (!IMAGE_MIME.has(mime) && !IMAGE_EXT.test(file.name)) throw new Error(IMAGE_FORMAT_ERROR);
|
|
380
|
+
const gif = mime === "image/gif" || /\.gif$/i.test(file.name);
|
|
381
|
+
const direct = !gif && (mime === "image/png" || mime === "image/jpeg" || mime === "image/jpg" || mime === "image/webp") && file.size <= TARGET_IMAGE_BYTES;
|
|
382
|
+
const bitmap = await createImageBitmap(file, { imageOrientation: "from-image" });
|
|
383
|
+
try {
|
|
384
|
+
const edge = Math.max(bitmap.width, bitmap.height);
|
|
385
|
+
const scale = edge > MAX_IMAGE_EDGE ? MAX_IMAGE_EDGE / edge : 1;
|
|
386
|
+
const width = Math.max(1, Math.round(bitmap.width * scale));
|
|
387
|
+
const height = Math.max(1, Math.round(bitmap.height * scale));
|
|
388
|
+
const resized = width !== bitmap.width || height !== bitmap.height;
|
|
389
|
+
if (direct && !resized) return file;
|
|
390
|
+
const canvas = document.createElement("canvas");
|
|
391
|
+
canvas.width = width;
|
|
392
|
+
canvas.height = height;
|
|
393
|
+
const context = canvas.getContext("2d");
|
|
394
|
+
if (context === null) throw new Error("图片处理失败:浏览器画布不可用");
|
|
395
|
+
context.drawImage(bitmap, 0, 0, width, height);
|
|
396
|
+
const hasAlpha = mayHaveAlpha(mime, file.name) && canvasHasTransparency(context, width, height);
|
|
397
|
+
if (hasAlpha) {
|
|
398
|
+
const webp = await canvasToBlob(canvas, "image/webp", 0.85);
|
|
399
|
+
if (webp === null) throw new Error("图片处理失败:无法编码 WebP");
|
|
400
|
+
if (webp.size > TARGET_IMAGE_BYTES) throw new Error("图片压缩后仍超过 4 MB,先换一张小一点的");
|
|
401
|
+
return webp;
|
|
402
|
+
}
|
|
403
|
+
for (const quality of [0.85, 0.75, 0.6]) {
|
|
404
|
+
const jpeg = await canvasToBlob(canvas, "image/jpeg", quality);
|
|
405
|
+
if (jpeg === null) throw new Error("图片处理失败:无法编码 JPEG");
|
|
406
|
+
if (jpeg.size <= TARGET_IMAGE_BYTES) return jpeg;
|
|
407
|
+
}
|
|
408
|
+
throw new Error("图片压缩后仍超过 4 MB,先换一张小一点的");
|
|
409
|
+
} finally {
|
|
410
|
+
bitmap.close();
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function mayHaveAlpha(mime, name) {
|
|
414
|
+
if (mime === "image/jpeg" || mime === "image/jpg") return false;
|
|
415
|
+
if (/\.jpe?g$/i.test(name)) return false;
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
418
|
+
function canvasHasTransparency(context, width, height) {
|
|
419
|
+
const data = context.getImageData(0, 0, width, height).data;
|
|
420
|
+
for (let index = 3; index < data.length; index += 4) {
|
|
421
|
+
if (data[index] < 255) return true;
|
|
422
|
+
}
|
|
423
|
+
return false;
|
|
424
|
+
}
|
|
425
|
+
function canvasToBlob(canvas, type, quality) {
|
|
426
|
+
return new Promise((resolve) => {
|
|
427
|
+
canvas.toBlob((blob) => {
|
|
428
|
+
resolve(blob);
|
|
429
|
+
}, type, quality);
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
async function extractVideoFrames(url, count = 6) {
|
|
433
|
+
const frames = [];
|
|
434
|
+
if (typeof document === "undefined" || count <= 0) return frames;
|
|
435
|
+
const video = document.createElement("video");
|
|
436
|
+
video.muted = true;
|
|
437
|
+
video.playsInline = true;
|
|
438
|
+
video.preload = "metadata";
|
|
439
|
+
video.crossOrigin = "anonymous";
|
|
440
|
+
video.setAttribute("aria-hidden", "true");
|
|
441
|
+
video.style.cssText = "position:fixed;left:-9999px;top:0;width:1px;height:1px;opacity:0;pointer-events:none";
|
|
442
|
+
document.body.appendChild(video);
|
|
443
|
+
return new Promise((resolve) => {
|
|
444
|
+
let finished = false;
|
|
445
|
+
let totalTimer = 0;
|
|
446
|
+
const finish = () => {
|
|
447
|
+
if (finished) return;
|
|
448
|
+
finished = true;
|
|
449
|
+
window.clearTimeout(totalTimer);
|
|
450
|
+
video.pause();
|
|
451
|
+
video.removeAttribute("src");
|
|
452
|
+
video.load();
|
|
453
|
+
video.remove();
|
|
454
|
+
resolve(frames);
|
|
293
455
|
};
|
|
456
|
+
totalTimer = window.setTimeout(finish, FRAME_TOTAL_TIMEOUT_MS);
|
|
457
|
+
video.onerror = () => {
|
|
458
|
+
finish();
|
|
459
|
+
};
|
|
460
|
+
video.onloadedmetadata = () => {
|
|
461
|
+
void (async () => {
|
|
462
|
+
const duration = video.duration;
|
|
463
|
+
if (!Number.isFinite(duration) || duration <= 0) {
|
|
464
|
+
finish();
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
for (let index = 0; index < count; index += 1) {
|
|
468
|
+
if (finished) return;
|
|
469
|
+
const time = duration * (index + 0.5) / count;
|
|
470
|
+
const sought = await seekTo(video, time);
|
|
471
|
+
if (!sought || finished) break;
|
|
472
|
+
const frame = await grabFrame(video);
|
|
473
|
+
if (frame !== null) frames.push(frame);
|
|
474
|
+
}
|
|
475
|
+
finish();
|
|
476
|
+
})();
|
|
477
|
+
};
|
|
478
|
+
video.src = url;
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
function seekTo(video, time) {
|
|
482
|
+
if (Math.abs(video.currentTime - time) < 1e-3) return Promise.resolve(true);
|
|
483
|
+
return new Promise((resolve) => {
|
|
484
|
+
let settled = false;
|
|
485
|
+
const timer = window.setTimeout(() => {
|
|
486
|
+
if (settled) return;
|
|
487
|
+
settled = true;
|
|
488
|
+
video.removeEventListener("seeked", onSeeked);
|
|
489
|
+
resolve(false);
|
|
490
|
+
}, SEEK_TIMEOUT_MS);
|
|
491
|
+
function onSeeked() {
|
|
492
|
+
if (settled) return;
|
|
493
|
+
settled = true;
|
|
494
|
+
window.clearTimeout(timer);
|
|
495
|
+
video.removeEventListener("seeked", onSeeked);
|
|
496
|
+
resolve(true);
|
|
497
|
+
}
|
|
498
|
+
video.addEventListener("seeked", onSeeked);
|
|
499
|
+
try {
|
|
500
|
+
video.currentTime = time;
|
|
501
|
+
} catch {
|
|
502
|
+
if (!settled) {
|
|
503
|
+
settled = true;
|
|
504
|
+
window.clearTimeout(timer);
|
|
505
|
+
video.removeEventListener("seeked", onSeeked);
|
|
506
|
+
resolve(false);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
async function grabFrame(video) {
|
|
512
|
+
const sourceWidth = video.videoWidth;
|
|
513
|
+
const sourceHeight = video.videoHeight;
|
|
514
|
+
if (sourceWidth <= 0 || sourceHeight <= 0) return null;
|
|
515
|
+
const scale = Math.min(1, MAX_FRAME_EDGE / Math.max(sourceWidth, sourceHeight));
|
|
516
|
+
const width = Math.max(1, Math.round(sourceWidth * scale));
|
|
517
|
+
const height = Math.max(1, Math.round(sourceHeight * scale));
|
|
518
|
+
const canvas = document.createElement("canvas");
|
|
519
|
+
canvas.width = width;
|
|
520
|
+
canvas.height = height;
|
|
521
|
+
const context = canvas.getContext("2d");
|
|
522
|
+
if (context === null) return null;
|
|
523
|
+
context.drawImage(video, 0, 0, width, height);
|
|
524
|
+
return canvasToBlob(canvas, "image/jpeg", 0.82);
|
|
525
|
+
}
|
|
526
|
+
function composeSubmit(list) {
|
|
527
|
+
const images = [];
|
|
528
|
+
const files = [];
|
|
529
|
+
for (const item of list) {
|
|
530
|
+
if (item.meta === null) continue;
|
|
531
|
+
if (item.kind === "image") {
|
|
532
|
+
images.push(item.meta.url);
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
files.push({
|
|
536
|
+
sha: item.meta.sha,
|
|
537
|
+
kind: item.kind,
|
|
538
|
+
name: item.meta.name,
|
|
539
|
+
mime: item.meta.mime,
|
|
540
|
+
bytes: item.meta.bytes,
|
|
541
|
+
path: item.meta.path,
|
|
542
|
+
...item.kind === "video" && item.frames.length > 0 ? { frames: [...item.frames] } : {}
|
|
543
|
+
});
|
|
294
544
|
}
|
|
295
|
-
|
|
545
|
+
const frameCount = files.reduce((sum, file) => sum + (file.frames?.length ?? 0), 0);
|
|
546
|
+
const dropped = Math.max(0, images.length + frameCount - MAX_IMAGES);
|
|
547
|
+
let budget = Math.max(0, MAX_IMAGES - images.length);
|
|
548
|
+
for (const file of files) {
|
|
549
|
+
if (file.frames === void 0) continue;
|
|
550
|
+
const keep = Math.min(file.frames.length, budget);
|
|
551
|
+
budget -= keep;
|
|
552
|
+
if (keep === 0) delete file.frames;
|
|
553
|
+
else if (keep < file.frames.length) file.frames = file.frames.slice(0, keep);
|
|
554
|
+
}
|
|
555
|
+
return { images: images.slice(0, MAX_IMAGES), files, dropped };
|
|
556
|
+
}
|
|
557
|
+
function filteredBranches(rows, query) {
|
|
558
|
+
const needle = query.trim().toLowerCase();
|
|
559
|
+
if (needle === "") return rows;
|
|
560
|
+
return rows.filter((row) => row.name.toLowerCase().includes(needle));
|
|
561
|
+
}
|
|
562
|
+
function wouldOverwrite(text) {
|
|
563
|
+
return /would be overwritten|Please commit your changes or stash/i.test(text);
|
|
564
|
+
}
|
|
565
|
+
function BranchMenu({ open, onOpenChange, git, channel, onFault }) {
|
|
566
|
+
const [branchList, setBranchList] = react.useState(null);
|
|
567
|
+
const [branchQuery, setBranchQuery] = react.useState("");
|
|
568
|
+
const [branchBusy, setBranchBusy] = react.useState(false);
|
|
569
|
+
const [branchCreateOpen, setBranchCreateOpen] = react.useState(false);
|
|
570
|
+
const [newBranchName, setNewBranchName] = react.useState("");
|
|
571
|
+
const branchRows = react.useRef(null);
|
|
572
|
+
react.useEffect(() => {
|
|
573
|
+
if (!open) return void 0;
|
|
574
|
+
let alive = true;
|
|
575
|
+
setBranchQuery("");
|
|
576
|
+
setBranchCreateOpen(false);
|
|
577
|
+
setNewBranchName("");
|
|
578
|
+
void channel.invoke("dock", ["git-branches", {}]).then((list) => {
|
|
579
|
+
if (alive) setBranchList(list);
|
|
580
|
+
}).catch((reason) => {
|
|
581
|
+
if (!alive) return;
|
|
582
|
+
setBranchList(null);
|
|
583
|
+
onFault(`读分支清单失败:${reason instanceof Error ? reason.message : String(reason)}`);
|
|
584
|
+
});
|
|
585
|
+
return () => {
|
|
586
|
+
alive = false;
|
|
587
|
+
};
|
|
588
|
+
}, [open, channel, git.branch]);
|
|
589
|
+
react.useEffect(() => {
|
|
590
|
+
if (!open || branchList === null) return;
|
|
591
|
+
const node = branchRows.current?.querySelector('[data-branch-current="true"]');
|
|
592
|
+
node?.scrollIntoView({ block: "nearest" });
|
|
593
|
+
}, [open, branchList]);
|
|
594
|
+
const switchBranch = (name) => {
|
|
595
|
+
setBranchBusy(true);
|
|
596
|
+
onFault(null);
|
|
597
|
+
onOpenChange(false);
|
|
598
|
+
void channel.invoke("dock", ["git-checkout", { branch: name }], { timeoutMs: ui$1.HUMAN_WAIT_TIMEOUT_MS }).then(() => {
|
|
599
|
+
ui$1.toastOk(`已切到分支「${name}」`);
|
|
600
|
+
}).catch((reason) => {
|
|
601
|
+
const text = reason instanceof Error ? reason.message : String(reason);
|
|
602
|
+
onFault(wouldOverwrite(text) ? `${text}(先提交或暂存这些改动再切:右侧边栏「变更」页签可以提交)` : text);
|
|
603
|
+
}).finally(() => {
|
|
604
|
+
setBranchBusy(false);
|
|
605
|
+
});
|
|
606
|
+
};
|
|
607
|
+
const createBranch = () => {
|
|
608
|
+
const name = newBranchName.trim();
|
|
609
|
+
if (name === "") return;
|
|
610
|
+
setBranchBusy(true);
|
|
611
|
+
onFault(null);
|
|
612
|
+
onOpenChange(false);
|
|
613
|
+
void channel.invoke("dock", ["git-branch-create", { branch: name }], { timeoutMs: ui$1.HUMAN_WAIT_TIMEOUT_MS }).then(() => {
|
|
614
|
+
setBranchCreateOpen(false);
|
|
615
|
+
setNewBranchName("");
|
|
616
|
+
ui$1.toastOk(`已新建并切到分支「${name}」`);
|
|
617
|
+
}).catch((reason) => {
|
|
618
|
+
onFault(reason instanceof Error ? reason.message : String(reason));
|
|
619
|
+
}).finally(() => {
|
|
620
|
+
setBranchBusy(false);
|
|
621
|
+
});
|
|
622
|
+
};
|
|
623
|
+
return git.repo ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "composer-git", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "model-anchor", children: [
|
|
624
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
625
|
+
"button",
|
|
626
|
+
{
|
|
627
|
+
type: "button",
|
|
628
|
+
className: `model-btn git-btn${open ? " open" : ""}`,
|
|
629
|
+
"data-tip": git.detached ? "HEAD 已分离(不在任何分支上);点开可以切回一个分支" : `当前分支:${git.branch}`,
|
|
630
|
+
"aria-haspopup": "menu",
|
|
631
|
+
"aria-expanded": open,
|
|
632
|
+
onClick: () => {
|
|
633
|
+
onOpenChange(!open);
|
|
634
|
+
},
|
|
635
|
+
children: [
|
|
636
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconBranch, { size: 13 }),
|
|
637
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "git-branch-name", children: git.branch }),
|
|
638
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronDown, { size: 12 })
|
|
639
|
+
]
|
|
640
|
+
}
|
|
641
|
+
),
|
|
642
|
+
open ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
643
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
644
|
+
"div",
|
|
645
|
+
{
|
|
646
|
+
className: "pop-mask",
|
|
647
|
+
onClick: () => {
|
|
648
|
+
onOpenChange(false);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
),
|
|
652
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "model-pop git-pop", role: "menu", "aria-label": "切换分支", children: [
|
|
653
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pop-label", children: [
|
|
654
|
+
"切换分支",
|
|
655
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "pop-note", children: [
|
|
656
|
+
branchList?.detached === true ? "HEAD 已分离" : `当前 ${branchList?.current ?? git.branch}`,
|
|
657
|
+
git.dirtyFileCount > 0 ? ` · ${String(git.dirtyFileCount)} 个文件已更改` : ""
|
|
658
|
+
] })
|
|
659
|
+
] }),
|
|
660
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "git-search", children: [
|
|
661
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconSearch, { size: 13 }),
|
|
662
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
663
|
+
"input",
|
|
664
|
+
{
|
|
665
|
+
type: "text",
|
|
666
|
+
value: branchQuery,
|
|
667
|
+
placeholder: "搜索分支…",
|
|
668
|
+
"aria-label": "搜索分支",
|
|
669
|
+
autoFocus: true,
|
|
670
|
+
onChange: (event) => {
|
|
671
|
+
setBranchQuery(event.target.value);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
)
|
|
675
|
+
] }),
|
|
676
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "model-list git-branch-list", ref: branchRows, children: branchList === null ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pop-item", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: "正在读取分支…" }) }) : filteredBranches(branchList.branches, branchQuery).length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pop-item", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: branchQuery.trim() === "" ? "这个仓库还没有分支" : "没有匹配的分支" }) }) : filteredBranches(branchList.branches, branchQuery).map((row) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
677
|
+
"button",
|
|
678
|
+
{
|
|
679
|
+
type: "button",
|
|
680
|
+
role: "menuitemradio",
|
|
681
|
+
"aria-checked": row.current,
|
|
682
|
+
className: `pop-item${row.current ? " on" : ""}`,
|
|
683
|
+
title: row.current ? `${row.name}(当前分支)` : `切到 ${row.name}`,
|
|
684
|
+
disabled: row.current || branchBusy,
|
|
685
|
+
...row.current ? { "data-branch-current": "true" } : {},
|
|
686
|
+
onClick: () => {
|
|
687
|
+
switchBranch(row.name);
|
|
688
|
+
},
|
|
689
|
+
children: [
|
|
690
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconBranch, { size: 13, className: "git-item-icon" }),
|
|
691
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: row.name }),
|
|
692
|
+
row.current ? /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconCheck, { size: 14, className: "check" }) : null
|
|
693
|
+
]
|
|
694
|
+
},
|
|
695
|
+
row.name
|
|
696
|
+
)) }),
|
|
697
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "git-foot", children: branchCreateOpen ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
698
|
+
"form",
|
|
699
|
+
{
|
|
700
|
+
className: "git-create",
|
|
701
|
+
onSubmit: (event) => {
|
|
702
|
+
event.preventDefault();
|
|
703
|
+
createBranch();
|
|
704
|
+
},
|
|
705
|
+
children: [
|
|
706
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
707
|
+
"input",
|
|
708
|
+
{
|
|
709
|
+
type: "text",
|
|
710
|
+
value: newBranchName,
|
|
711
|
+
placeholder: "新分支名,如 feat/xxx",
|
|
712
|
+
"aria-label": "新分支名",
|
|
713
|
+
autoFocus: true,
|
|
714
|
+
disabled: branchBusy,
|
|
715
|
+
onChange: (event) => {
|
|
716
|
+
setNewBranchName(event.target.value);
|
|
717
|
+
},
|
|
718
|
+
onKeyDown: (event) => {
|
|
719
|
+
if (event.key === "Escape") {
|
|
720
|
+
event.preventDefault();
|
|
721
|
+
setBranchCreateOpen(false);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
),
|
|
726
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", disabled: branchBusy || newBranchName.trim() === "", children: "创建并切换" })
|
|
727
|
+
]
|
|
728
|
+
}
|
|
729
|
+
) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
730
|
+
"button",
|
|
731
|
+
{
|
|
732
|
+
type: "button",
|
|
733
|
+
className: "git-foot-btn",
|
|
734
|
+
disabled: branchBusy,
|
|
735
|
+
onClick: () => {
|
|
736
|
+
setBranchCreateOpen(true);
|
|
737
|
+
},
|
|
738
|
+
children: [
|
|
739
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconPlus, { size: 13 }),
|
|
740
|
+
"新建分支…"
|
|
741
|
+
]
|
|
742
|
+
}
|
|
743
|
+
) })
|
|
744
|
+
] })
|
|
745
|
+
] }) : null
|
|
746
|
+
] }) }) : null;
|
|
296
747
|
}
|
|
297
748
|
const EFFORT_LABELS = {
|
|
298
749
|
default: "默认",
|
|
@@ -356,9 +807,6 @@ function effortChoices(entry) {
|
|
|
356
807
|
}
|
|
357
808
|
return ["default", ...rest];
|
|
358
809
|
}
|
|
359
|
-
function effortSwitchable(options) {
|
|
360
|
-
return options.length > 1;
|
|
361
|
-
}
|
|
362
810
|
function effortLabel(effort) {
|
|
363
811
|
return EFFORT_LABELS[effort] ?? effort;
|
|
364
812
|
}
|
|
@@ -403,60 +851,297 @@ function placeFlyout(rowTop, rowBottom, panelHeight, cardHeight, pad = 12) {
|
|
|
403
851
|
const top = Math.max(pad, Math.min(wanted, panelHeight - pad - height));
|
|
404
852
|
return { top, maxHeight: height };
|
|
405
853
|
}
|
|
406
|
-
function
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
return rows.filter((row) => row.name.toLowerCase().includes(needle));
|
|
854
|
+
function percentOf(index, count) {
|
|
855
|
+
if (count <= 1) return 100;
|
|
856
|
+
return Math.max(0, Math.min(index, count - 1)) / (count - 1) * 100;
|
|
410
857
|
}
|
|
411
|
-
function
|
|
412
|
-
|
|
858
|
+
function EffortSlider({
|
|
859
|
+
levels,
|
|
860
|
+
value,
|
|
861
|
+
note,
|
|
862
|
+
onCommit
|
|
863
|
+
}) {
|
|
864
|
+
const railRef = react.useRef(null);
|
|
865
|
+
const dragRef = react.useRef(null);
|
|
866
|
+
const [drag, setDrag] = react.useState(null);
|
|
867
|
+
const selected = levels.indexOf(value);
|
|
868
|
+
const index = drag ?? selected;
|
|
869
|
+
const unset = index < 0;
|
|
870
|
+
const activeLevel = unset ? "unset" : levels[Math.min(index, levels.length - 1)];
|
|
871
|
+
const indexAt = (clientX) => {
|
|
872
|
+
const rail = railRef.current;
|
|
873
|
+
if (rail === null) return 0;
|
|
874
|
+
const box = rail.getBoundingClientRect();
|
|
875
|
+
if (box.width === 0 || levels.length <= 1) return 0;
|
|
876
|
+
const ratio = Math.max(0, Math.min(1, (clientX - box.left) / box.width));
|
|
877
|
+
return Math.round(ratio * (levels.length - 1));
|
|
878
|
+
};
|
|
879
|
+
const onPointerDown = (event) => {
|
|
880
|
+
if (event.button !== 0) return;
|
|
881
|
+
event.preventDefault();
|
|
882
|
+
try {
|
|
883
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
884
|
+
} catch {
|
|
885
|
+
}
|
|
886
|
+
const next = indexAt(event.clientX);
|
|
887
|
+
dragRef.current = next;
|
|
888
|
+
setDrag(next);
|
|
889
|
+
};
|
|
890
|
+
const onPointerMove = (event) => {
|
|
891
|
+
if (dragRef.current === null) return;
|
|
892
|
+
const next = indexAt(event.clientX);
|
|
893
|
+
if (next === dragRef.current) return;
|
|
894
|
+
dragRef.current = next;
|
|
895
|
+
setDrag(next);
|
|
896
|
+
};
|
|
897
|
+
const finish = (event) => {
|
|
898
|
+
const at = dragRef.current;
|
|
899
|
+
if (at === null) return;
|
|
900
|
+
dragRef.current = null;
|
|
901
|
+
setDrag(null);
|
|
902
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
903
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
904
|
+
}
|
|
905
|
+
const level = levels[at];
|
|
906
|
+
if (level !== void 0 && level !== value) onCommit(level);
|
|
907
|
+
};
|
|
908
|
+
const onKeyDown = (event) => {
|
|
909
|
+
const from = unset ? 0 : selected;
|
|
910
|
+
let next = null;
|
|
911
|
+
if (event.key === "ArrowLeft" || event.key === "ArrowDown") next = Math.max(0, from - 1);
|
|
912
|
+
else if (event.key === "ArrowRight" || event.key === "ArrowUp") next = Math.min(levels.length - 1, from + 1);
|
|
913
|
+
else if (event.key === "Home") next = 0;
|
|
914
|
+
else if (event.key === "End") next = levels.length - 1;
|
|
915
|
+
if (next === null) return;
|
|
916
|
+
event.preventDefault();
|
|
917
|
+
const level = levels[next];
|
|
918
|
+
if (level !== void 0 && level !== value) onCommit(level);
|
|
919
|
+
};
|
|
920
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "effort-slider", "data-effort-slider": "", children: [
|
|
921
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "effort-slider-head", children: [
|
|
922
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "effort-slider-title", children: "思考强度" }),
|
|
923
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "effort-now" + (unset ? " unset" : ""), "data-effort-now": unset ? "unset" : value, children: unset ? "未设置" : effortLabel(value) })
|
|
924
|
+
] }),
|
|
925
|
+
note === null ? null : /* @__PURE__ */ jsxRuntime.jsx("p", { className: "effort-note", children: note }),
|
|
926
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
927
|
+
"div",
|
|
928
|
+
{
|
|
929
|
+
className: "effort-track",
|
|
930
|
+
"data-level": activeLevel,
|
|
931
|
+
"data-unset": unset ? "1" : void 0,
|
|
932
|
+
"data-dragging": drag === null ? void 0 : "1",
|
|
933
|
+
"data-effort-track": "",
|
|
934
|
+
role: "slider",
|
|
935
|
+
tabIndex: 0,
|
|
936
|
+
"aria-label": "思考强度",
|
|
937
|
+
"aria-valuemin": 0,
|
|
938
|
+
"aria-valuemax": Math.max(0, levels.length - 1),
|
|
939
|
+
"aria-valuenow": unset ? 0 : index,
|
|
940
|
+
"aria-valuetext": unset ? "未设置" : effortLabel(value),
|
|
941
|
+
onPointerDown,
|
|
942
|
+
onPointerMove,
|
|
943
|
+
onPointerUp: finish,
|
|
944
|
+
onPointerCancel: finish,
|
|
945
|
+
onKeyDown,
|
|
946
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "effort-rail", ref: railRef, children: [
|
|
947
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
948
|
+
"span",
|
|
949
|
+
{
|
|
950
|
+
className: "effort-rail-fill",
|
|
951
|
+
"data-effort-fill": "",
|
|
952
|
+
style: { "--effort-fill": (unset ? 0 : percentOf(index, levels.length)) + "%" }
|
|
953
|
+
}
|
|
954
|
+
),
|
|
955
|
+
levels.map((level, at) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
956
|
+
"span",
|
|
957
|
+
{
|
|
958
|
+
className: "effort-dot",
|
|
959
|
+
"data-effort-dot": level,
|
|
960
|
+
"data-lit": !unset && at <= index ? "1" : void 0,
|
|
961
|
+
style: { left: percentOf(at, levels.length) + "%" }
|
|
962
|
+
},
|
|
963
|
+
level
|
|
964
|
+
)),
|
|
965
|
+
unset ? null : /* @__PURE__ */ jsxRuntime.jsx(
|
|
966
|
+
"span",
|
|
967
|
+
{
|
|
968
|
+
className: "effort-knob",
|
|
969
|
+
"data-effort-knob": "",
|
|
970
|
+
style: { left: percentOf(index, levels.length) + "%" }
|
|
971
|
+
}
|
|
972
|
+
)
|
|
973
|
+
] })
|
|
974
|
+
}
|
|
975
|
+
)
|
|
976
|
+
] });
|
|
413
977
|
}
|
|
414
|
-
const MAX_INPUT_HEIGHT = 200;
|
|
415
|
-
const PREVIEW_CHARS = 200;
|
|
416
|
-
const HISTORY_LIMIT = 50;
|
|
417
978
|
const EMPTY_PERMISSION_PRESETS = { current: "", defaultName: "", options: [] };
|
|
418
979
|
const EMPTY_PRESET = { current: "", defaultName: "", options: [], droppable: [] };
|
|
419
980
|
const EMPTY_GIT = { repo: false, branch: "", detached: false, dirtyFileCount: 0 };
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
const
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
const
|
|
449
|
-
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
|
|
981
|
+
function sameQueued(left, right) {
|
|
982
|
+
if (left === right) return true;
|
|
983
|
+
if (left.length !== right.length) return false;
|
|
984
|
+
return left.every((item, index) => {
|
|
985
|
+
const other = right[index];
|
|
986
|
+
if (other === void 0) return false;
|
|
987
|
+
return item.index === other.index && item.text === other.text && (item.images?.join("|") ?? "") === (other.images?.join("|") ?? "");
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
function readModel(snapshot) {
|
|
991
|
+
const status = snapshot?.["status"];
|
|
992
|
+
if (typeof status !== "object" || status === null) return "";
|
|
993
|
+
const value = status["model"];
|
|
994
|
+
return typeof value === "string" ? value : "";
|
|
995
|
+
}
|
|
996
|
+
function readProvider(snapshot) {
|
|
997
|
+
const status = snapshot?.["status"];
|
|
998
|
+
if (typeof status !== "object" || status === null) return "";
|
|
999
|
+
const value = status["provider"];
|
|
1000
|
+
return typeof value === "string" ? value : "";
|
|
1001
|
+
}
|
|
1002
|
+
function readEffort(snapshot) {
|
|
1003
|
+
const status = snapshot?.["status"];
|
|
1004
|
+
if (typeof status !== "object" || status === null) return "default";
|
|
1005
|
+
const value = status["effort"];
|
|
1006
|
+
return typeof value === "string" ? value : "default";
|
|
1007
|
+
}
|
|
1008
|
+
function readHasApproval(snapshot) {
|
|
1009
|
+
const surfaces = snapshot?.["surfaces"];
|
|
1010
|
+
if (typeof surfaces !== "object" || surfaces === null) return false;
|
|
1011
|
+
const pending = surfaces["pendingApproval"];
|
|
1012
|
+
return pending !== null && pending !== void 0;
|
|
1013
|
+
}
|
|
1014
|
+
function readSessionPath(snapshot) {
|
|
1015
|
+
const status = snapshot?.["status"];
|
|
1016
|
+
if (typeof status !== "object" || status === null) return "";
|
|
1017
|
+
const path = status["sessionPath"];
|
|
1018
|
+
return typeof path === "string" ? path : "";
|
|
1019
|
+
}
|
|
1020
|
+
function readSessionId(snapshot) {
|
|
1021
|
+
const status = snapshot?.["status"];
|
|
1022
|
+
if (typeof status !== "object" || status === null) return "";
|
|
1023
|
+
const value = status["sessionId"];
|
|
1024
|
+
return typeof value === "string" ? value : "";
|
|
1025
|
+
}
|
|
1026
|
+
function readDraftCwd(snapshot) {
|
|
1027
|
+
const status = snapshot?.["status"];
|
|
1028
|
+
if (typeof status !== "object" || status === null) return "";
|
|
1029
|
+
const value = status["cwd"];
|
|
1030
|
+
return typeof value === "string" ? value : "";
|
|
1031
|
+
}
|
|
1032
|
+
function readSessionUnsaved(snapshot) {
|
|
1033
|
+
const status = snapshot?.["status"];
|
|
1034
|
+
if (typeof status !== "object" || status === null) return false;
|
|
1035
|
+
return status["sessionUnsaved"] === true;
|
|
1036
|
+
}
|
|
1037
|
+
function readPermissionPresets(snapshot) {
|
|
1038
|
+
const surfaces = snapshot?.["surfaces"];
|
|
1039
|
+
if (typeof surfaces !== "object" || surfaces === null) return EMPTY_PERMISSION_PRESETS;
|
|
1040
|
+
const presets = surfaces["permissionPresets"];
|
|
1041
|
+
if (typeof presets !== "object" || presets === null) return EMPTY_PERMISSION_PRESETS;
|
|
1042
|
+
const record = presets;
|
|
1043
|
+
const current = record["current"];
|
|
1044
|
+
const options = record["options"];
|
|
1045
|
+
if (typeof current !== "string" || !Array.isArray(options)) return EMPTY_PERMISSION_PRESETS;
|
|
1046
|
+
return {
|
|
1047
|
+
current,
|
|
1048
|
+
defaultName: typeof record["defaultName"] === "string" ? record["defaultName"] : "",
|
|
1049
|
+
options
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
function samePermissionPresets(left, right) {
|
|
1053
|
+
if (left === right) return true;
|
|
1054
|
+
if (left.current !== right.current || left.defaultName !== right.defaultName) return false;
|
|
1055
|
+
if (left.options.length !== right.options.length) return false;
|
|
1056
|
+
return left.options.every((item, index) => {
|
|
1057
|
+
const other = right.options[index];
|
|
1058
|
+
return other !== void 0 && item.name === other.name && item.label === other.label && item.description === other.description && item.builtin === other.builtin;
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
function readPresetSurface(snapshot) {
|
|
1062
|
+
const surfaces = snapshot?.["surfaces"];
|
|
1063
|
+
if (typeof surfaces !== "object" || surfaces === null) return EMPTY_PRESET;
|
|
1064
|
+
const preset = surfaces["preset"];
|
|
1065
|
+
if (typeof preset !== "object" || preset === null) return EMPTY_PRESET;
|
|
1066
|
+
const record = preset;
|
|
1067
|
+
const current = record["current"];
|
|
1068
|
+
const options = record["options"];
|
|
1069
|
+
if (typeof current !== "string" || !Array.isArray(options)) return EMPTY_PRESET;
|
|
1070
|
+
return {
|
|
1071
|
+
current,
|
|
1072
|
+
defaultName: typeof record["defaultName"] === "string" ? record["defaultName"] : "",
|
|
1073
|
+
options,
|
|
1074
|
+
droppable: Array.isArray(record["droppable"]) ? record["droppable"] : []
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
function samePresetSurface(left, right) {
|
|
1078
|
+
if (left === right) return true;
|
|
1079
|
+
if (left.current !== right.current || left.defaultName !== right.defaultName) return false;
|
|
1080
|
+
if (left.options.length !== right.options.length) return false;
|
|
1081
|
+
return left.options.every((item, index) => {
|
|
1082
|
+
const other = right.options[index];
|
|
1083
|
+
return other !== void 0 && item.name === other.name && item.label === other.label && item.description === other.description && item.problem === other.problem;
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
function readInboxCount(snapshot) {
|
|
1087
|
+
const queued = snapshot?.["queued"];
|
|
1088
|
+
const notices = snapshot?.["notices"];
|
|
1089
|
+
return (Array.isArray(queued) ? queued.length : 0) + (Array.isArray(notices) ? notices.length : 0);
|
|
1090
|
+
}
|
|
1091
|
+
function readQueued(snapshot) {
|
|
1092
|
+
const value = snapshot?.["queued"];
|
|
1093
|
+
return Array.isArray(value) ? value : EMPTY_QUEUE;
|
|
1094
|
+
}
|
|
1095
|
+
const EMPTY_QUEUE = Object.freeze([]);
|
|
1096
|
+
function sameNotices(left, right) {
|
|
1097
|
+
if (left === right) return true;
|
|
1098
|
+
if (left.length !== right.length) return false;
|
|
1099
|
+
return left.every((item, index) => {
|
|
1100
|
+
const other = right[index];
|
|
1101
|
+
return other !== void 0 && item.index === other.index && item.text === other.text;
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
function readNotices(snapshot) {
|
|
1105
|
+
const value = snapshot?.["notices"];
|
|
1106
|
+
return Array.isArray(value) ? value : EMPTY_NOTICES;
|
|
1107
|
+
}
|
|
1108
|
+
const EMPTY_NOTICES = Object.freeze([]);
|
|
1109
|
+
function readGit(snapshot) {
|
|
1110
|
+
const surfaces = snapshot?.["surfaces"];
|
|
1111
|
+
if (typeof surfaces !== "object" || surfaces === null) return EMPTY_GIT;
|
|
1112
|
+
const raw = surfaces["git"];
|
|
1113
|
+
if (typeof raw !== "object" || raw === null) return EMPTY_GIT;
|
|
1114
|
+
const record = raw;
|
|
1115
|
+
return {
|
|
1116
|
+
repo: record["repo"] === true,
|
|
1117
|
+
branch: typeof record["branch"] === "string" ? record["branch"] : "",
|
|
1118
|
+
detached: record["detached"] === true,
|
|
1119
|
+
dirtyFileCount: typeof record["dirtyFileCount"] === "number" ? record["dirtyFileCount"] : 0
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
1122
|
+
function useModelControls({ channel, onFault, onTakeOver }) {
|
|
1123
|
+
const model = ui$1.useHostSelector(readModel);
|
|
1124
|
+
const effort = ui$1.useHostSelector(readEffort);
|
|
1125
|
+
const [pendingEffort, setPendingEffort] = react.useState(null);
|
|
1126
|
+
react.useEffect(() => {
|
|
1127
|
+
if (pendingEffort !== null && effort === pendingEffort) setPendingEffort(null);
|
|
1128
|
+
}, [effort, pendingEffort]);
|
|
1129
|
+
react.useEffect(() => {
|
|
1130
|
+
if (pendingEffort === null) return void 0;
|
|
1131
|
+
const timer = setTimeout(() => setPendingEffort(null), 1500);
|
|
1132
|
+
return () => clearTimeout(timer);
|
|
1133
|
+
}, [pendingEffort]);
|
|
1134
|
+
const [models, setModels] = react.useState([]);
|
|
1135
|
+
const [modelOpen, setModelOpen] = react.useState(false);
|
|
1136
|
+
const [effortOpen, setEffortOpen] = react.useState(false);
|
|
1137
|
+
const [hoverProvider, setHoverProvider] = react.useState(null);
|
|
1138
|
+
const [flyout, setFlyout] = react.useState(null);
|
|
1139
|
+
const [flyoutSide, setFlyoutSide] = react.useState("right");
|
|
1140
|
+
const [dropPrefix, setDropPrefix] = react.useState(false);
|
|
1141
|
+
const [panelShift, setPanelShift] = react.useState(0);
|
|
1142
|
+
const [measureTick, setMeasureTick] = react.useState(0);
|
|
459
1143
|
const modelPanelRef = react.useRef(null);
|
|
1144
|
+
const shiftRef = react.useRef(0);
|
|
460
1145
|
const modelRows = react.useRef(null);
|
|
461
1146
|
const flyoutCardRef = react.useRef(null);
|
|
462
1147
|
const barRef = react.useRef(null);
|
|
@@ -485,60 +1170,6 @@ function ComposerBox() {
|
|
|
485
1170
|
window.addEventListener("keydown", onKey);
|
|
486
1171
|
return () => window.removeEventListener("keydown", onKey);
|
|
487
1172
|
}, [modelOpen, effortOpen]);
|
|
488
|
-
react.useEffect(() => {
|
|
489
|
-
if (!branchOpen) return void 0;
|
|
490
|
-
let alive = true;
|
|
491
|
-
setBranchQuery("");
|
|
492
|
-
setBranchCreateOpen(false);
|
|
493
|
-
setNewBranchName("");
|
|
494
|
-
void channel.invoke("dock", ["git-branches", {}]).then((list) => {
|
|
495
|
-
if (alive) setBranchList(list);
|
|
496
|
-
}).catch((reason) => {
|
|
497
|
-
if (!alive) return;
|
|
498
|
-
setBranchList(null);
|
|
499
|
-
setFault(`读分支清单失败:${reason instanceof Error ? reason.message : String(reason)}`);
|
|
500
|
-
});
|
|
501
|
-
return () => {
|
|
502
|
-
alive = false;
|
|
503
|
-
};
|
|
504
|
-
}, [branchOpen, channel, git.branch]);
|
|
505
|
-
react.useEffect(() => {
|
|
506
|
-
if (!branchOpen || branchList === null) return;
|
|
507
|
-
const node = branchRows.current?.querySelector('[data-branch-current="true"]');
|
|
508
|
-
node?.scrollIntoView({ block: "nearest" });
|
|
509
|
-
}, [branchOpen, branchList]);
|
|
510
|
-
const area = react.useRef(null);
|
|
511
|
-
const history = react.useRef([]);
|
|
512
|
-
const [historyAt, setHistoryAt] = react.useState(null);
|
|
513
|
-
const drafts = react.useRef(/* @__PURE__ */ new Map());
|
|
514
|
-
const draftSessionId = ui$1.useHostSelector(readSessionId);
|
|
515
|
-
const draftCwd = ui$1.useHostSelector(readDraftCwd);
|
|
516
|
-
const draftUnsaved = ui$1.useHostSelector(readSessionUnsaved);
|
|
517
|
-
const draftScope = draftScopeOf({
|
|
518
|
-
sessionPath: draftKey,
|
|
519
|
-
sessionId: draftSessionId,
|
|
520
|
-
cwd: draftCwd,
|
|
521
|
-
unsaved: draftUnsaved
|
|
522
|
-
});
|
|
523
|
-
const draftScopeRef = react.useRef(draftScope);
|
|
524
|
-
const working = turnState !== "idle";
|
|
525
|
-
react.useEffect(() => {
|
|
526
|
-
if (draftScopeRef.current.key === draftScope.key) return;
|
|
527
|
-
const next = carryDraft(drafts.current, draftScopeRef.current, draftScope, {
|
|
528
|
-
value: text,
|
|
529
|
-
history: history.current
|
|
530
|
-
});
|
|
531
|
-
draftScopeRef.current = draftScope;
|
|
532
|
-
setText(next.value);
|
|
533
|
-
history.current = [...next.history];
|
|
534
|
-
setHistoryAt(null);
|
|
535
|
-
}, [draftScope.key, draftScope.sessionId, draftScope.unsaved, text]);
|
|
536
|
-
react.useEffect(() => {
|
|
537
|
-
const node = area.current;
|
|
538
|
-
if (node === null) return;
|
|
539
|
-
node.style.height = "auto";
|
|
540
|
-
node.style.height = `${String(Math.min(node.scrollHeight, MAX_INPUT_HEIGHT))}px`;
|
|
541
|
-
}, [text]);
|
|
542
1173
|
react.useEffect(() => {
|
|
543
1174
|
let alive = true;
|
|
544
1175
|
void channel.invoke("listModels").then((list) => {
|
|
@@ -549,217 +1180,34 @@ function ComposerBox() {
|
|
|
549
1180
|
alive = false;
|
|
550
1181
|
};
|
|
551
1182
|
}, [channel, modelOpen]);
|
|
552
|
-
const
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
setSending(true);
|
|
574
|
-
setFault(null);
|
|
575
|
-
void (async () => {
|
|
576
|
-
try {
|
|
577
|
-
await channel.invoke("submit", [value]);
|
|
578
|
-
history.current = [...history.current.filter((item) => item !== value), value].slice(-HISTORY_LIMIT);
|
|
579
|
-
setHistoryAt(null);
|
|
580
|
-
void channel.invoke("refreshSessions").catch(() => void 0);
|
|
581
|
-
if (steerIndex !== null) {
|
|
582
|
-
const done = await channel.invoke("steerQueued", [steerIndex]);
|
|
583
|
-
if (done !== true) setFault("插话没赶上:这一轮刚结束,这条消息会自己发出去");
|
|
584
|
-
}
|
|
585
|
-
setText("");
|
|
586
|
-
} catch (reason) {
|
|
587
|
-
setFault(reason instanceof Error ? reason.message : String(reason));
|
|
588
|
-
} finally {
|
|
589
|
-
setSending(false);
|
|
590
|
-
}
|
|
591
|
-
})();
|
|
1183
|
+
const groups = groupModels(models);
|
|
1184
|
+
const provider = ui$1.useHostSelector(readProvider);
|
|
1185
|
+
const current = findCurrent(groups, provider, model);
|
|
1186
|
+
const imageInputAllowed = current.entry === void 0 || current.entry.modalities.includes("image");
|
|
1187
|
+
const chip = modelChipText(groups, provider, model);
|
|
1188
|
+
const twoLevel = shouldShowProviderLevel(groups);
|
|
1189
|
+
const hoveredGroup = groups.find((item) => item.provider === hoverProvider);
|
|
1190
|
+
const visibleModels = twoLevel ? hoveredGroup?.models ?? [] : groups[0]?.models ?? [];
|
|
1191
|
+
const flyoutShown = twoLevel && flyout !== null && hoveredGroup !== void 0;
|
|
1192
|
+
const levelOptions = effortChoices(current.entry);
|
|
1193
|
+
const sliderLevels = levelOptions.filter((level) => level !== "default");
|
|
1194
|
+
const switchEffort = sliderLevels.length > 0;
|
|
1195
|
+
const shownEffort = pendingEffort ?? effort;
|
|
1196
|
+
const effortText = effortLabel(shownEffort);
|
|
1197
|
+
const commitEffort = (level) => {
|
|
1198
|
+
setPendingEffort(level);
|
|
1199
|
+
onFault(null);
|
|
1200
|
+
void channel.invoke("setEffort", [level, true]).catch((reason) => {
|
|
1201
|
+
setPendingEffort(null);
|
|
1202
|
+
onFault(reason instanceof Error ? reason.message : String(reason));
|
|
1203
|
+
});
|
|
592
1204
|
};
|
|
593
|
-
const interrupt = () => {
|
|
594
|
-
setFault(null);
|
|
595
|
-
void channel.invoke("interrupt").catch((reason) => {
|
|
596
|
-
setFault(reason instanceof Error ? reason.message : String(reason));
|
|
597
|
-
});
|
|
598
|
-
};
|
|
599
|
-
const choosePermissionPreset = (name, label) => {
|
|
600
|
-
setPermOpen(false);
|
|
601
|
-
setFault(null);
|
|
602
|
-
const native = ui$1.getHostNative();
|
|
603
|
-
if (!native.available) {
|
|
604
|
-
setFault("切权限预设这条口子只在桌面窗口里开(浏览器页签与远程页面够不着),请用桌面端或终端改");
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
607
|
-
void native.invoke("usePermissionPreset", [name]).then(() => {
|
|
608
|
-
ui$1.toastOk(`权限预设已切到「${label}」`);
|
|
609
|
-
}).catch((reason) => {
|
|
610
|
-
setFault(`切权限预设失败:${reason instanceof Error ? reason.message : String(reason)}`);
|
|
611
|
-
});
|
|
612
|
-
};
|
|
613
|
-
const choosePreset = (name, label) => {
|
|
614
|
-
setPresetOpen(false);
|
|
615
|
-
setFault(null);
|
|
616
|
-
void channel.invoke("usePreset", [name]).then(() => {
|
|
617
|
-
ui$1.toastOk(`已切到「${label}」模式`);
|
|
618
|
-
}).catch((reason) => {
|
|
619
|
-
ui$1.toastErr(`切换失败:${reason instanceof Error ? reason.message : String(reason)}`);
|
|
620
|
-
});
|
|
621
|
-
};
|
|
622
|
-
const switchBranch = (name) => {
|
|
623
|
-
setBranchBusy(true);
|
|
624
|
-
setFault(null);
|
|
625
|
-
setBranchOpen(false);
|
|
626
|
-
void channel.invoke("dock", ["git-checkout", { branch: name }], { timeoutMs: ui$1.HUMAN_WAIT_TIMEOUT_MS }).then(() => {
|
|
627
|
-
ui$1.toastOk(`已切到分支「${name}」`);
|
|
628
|
-
}).catch((reason) => {
|
|
629
|
-
const text2 = reason instanceof Error ? reason.message : String(reason);
|
|
630
|
-
setFault(wouldOverwrite(text2) ? `${text2}(先提交或暂存这些改动再切:右侧边栏「变更」页签可以提交)` : text2);
|
|
631
|
-
}).finally(() => {
|
|
632
|
-
setBranchBusy(false);
|
|
633
|
-
});
|
|
634
|
-
};
|
|
635
|
-
const createBranch = () => {
|
|
636
|
-
const name = newBranchName.trim();
|
|
637
|
-
if (name === "") return;
|
|
638
|
-
setBranchBusy(true);
|
|
639
|
-
setFault(null);
|
|
640
|
-
setBranchOpen(false);
|
|
641
|
-
void channel.invoke("dock", ["git-branch-create", { branch: name }], { timeoutMs: ui$1.HUMAN_WAIT_TIMEOUT_MS }).then(() => {
|
|
642
|
-
setBranchCreateOpen(false);
|
|
643
|
-
setNewBranchName("");
|
|
644
|
-
ui$1.toastOk(`已新建并切到分支「${name}」`);
|
|
645
|
-
}).catch((reason) => {
|
|
646
|
-
setFault(reason instanceof Error ? reason.message : String(reason));
|
|
647
|
-
}).finally(() => {
|
|
648
|
-
setBranchBusy(false);
|
|
649
|
-
});
|
|
650
|
-
};
|
|
651
|
-
const mention = useMention({
|
|
652
|
-
channel,
|
|
653
|
-
area,
|
|
654
|
-
apply: (next, caret) => {
|
|
655
|
-
setText(next);
|
|
656
|
-
window.requestAnimationFrame(() => {
|
|
657
|
-
area.current?.setSelectionRange(caret, caret);
|
|
658
|
-
});
|
|
659
|
-
}
|
|
660
|
-
});
|
|
661
|
-
const command = useCommandMenu({
|
|
662
|
-
channel,
|
|
663
|
-
apply: (next, caret) => {
|
|
664
|
-
setText(next);
|
|
665
|
-
window.requestAnimationFrame(() => {
|
|
666
|
-
area.current?.setSelectionRange(caret, caret);
|
|
667
|
-
});
|
|
668
|
-
},
|
|
669
|
-
onUnavailable: () => {
|
|
670
|
-
setFault("当前宿主没接“/”命令通道:菜单不可用,请用桌面端或终端执行(升级宿主后自动可用)");
|
|
671
|
-
}
|
|
672
|
-
});
|
|
673
|
-
const onKeyDown = (event) => {
|
|
674
|
-
if (command.open) {
|
|
675
|
-
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
676
|
-
event.preventDefault();
|
|
677
|
-
command.move(event.key === "ArrowDown" ? 1 : -1);
|
|
678
|
-
return;
|
|
679
|
-
}
|
|
680
|
-
if (event.key === "Tab") {
|
|
681
|
-
event.preventDefault();
|
|
682
|
-
event.stopPropagation();
|
|
683
|
-
command.pick();
|
|
684
|
-
return;
|
|
685
|
-
}
|
|
686
|
-
if (event.key === "Escape") {
|
|
687
|
-
event.preventDefault();
|
|
688
|
-
command.close();
|
|
689
|
-
return;
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
if (mention.open) {
|
|
693
|
-
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
694
|
-
event.preventDefault();
|
|
695
|
-
mention.move(event.key === "ArrowDown" ? 1 : -1);
|
|
696
|
-
return;
|
|
697
|
-
}
|
|
698
|
-
if (event.key === "Tab" || event.key === "Enter") {
|
|
699
|
-
event.preventDefault();
|
|
700
|
-
event.stopPropagation();
|
|
701
|
-
mention.pick();
|
|
702
|
-
return;
|
|
703
|
-
}
|
|
704
|
-
if (event.key === "Escape") {
|
|
705
|
-
event.preventDefault();
|
|
706
|
-
mention.close();
|
|
707
|
-
return;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
if (event.key === "Enter") {
|
|
711
|
-
if (event.shiftKey || event.nativeEvent.isComposing) return;
|
|
712
|
-
event.preventDefault();
|
|
713
|
-
send(event.ctrlKey || event.metaKey);
|
|
714
|
-
return;
|
|
715
|
-
}
|
|
716
|
-
if (event.key === "ArrowUp" && (text === "" || historyAt !== null) && history.current.length > 0) {
|
|
717
|
-
event.preventDefault();
|
|
718
|
-
const next = historyAt === null ? history.current.length - 1 : Math.max(0, historyAt - 1);
|
|
719
|
-
setHistoryAt(next);
|
|
720
|
-
setText(history.current[next] ?? "");
|
|
721
|
-
return;
|
|
722
|
-
}
|
|
723
|
-
if (event.key === "ArrowDown" && historyAt !== null) {
|
|
724
|
-
event.preventDefault();
|
|
725
|
-
const next = historyAt + 1;
|
|
726
|
-
if (next >= history.current.length) {
|
|
727
|
-
setHistoryAt(null);
|
|
728
|
-
setText("");
|
|
729
|
-
} else {
|
|
730
|
-
setHistoryAt(next);
|
|
731
|
-
setText(history.current[next] ?? "");
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
};
|
|
735
|
-
const onTextChange = (value, caret) => {
|
|
736
|
-
setText(value);
|
|
737
|
-
setHistoryAt(null);
|
|
738
|
-
command.track(value, caret);
|
|
739
|
-
if (commandQuery(value, caret) === null) mention.track(value, caret);
|
|
740
|
-
else mention.close();
|
|
741
|
-
};
|
|
742
|
-
const sendable = text.trim() !== "";
|
|
743
|
-
const queueing = working && sendable;
|
|
744
|
-
const permOption = permissionPresets.options.find((item) => item.name === permissionPresets.current);
|
|
745
|
-
const presetOption = preset.options.find((item) => item.name === preset.current);
|
|
746
|
-
const groups = groupModels(models);
|
|
747
|
-
const provider = ui$1.useHostSelector(readProvider);
|
|
748
|
-
const current = findCurrent(groups, provider, model);
|
|
749
|
-
const chip = modelChipText(groups, provider, model);
|
|
750
|
-
const twoLevel = shouldShowProviderLevel(groups);
|
|
751
|
-
const hoveredGroup = groups.find((item) => item.provider === hoverProvider);
|
|
752
|
-
const visibleModels = twoLevel ? hoveredGroup?.models ?? [] : groups[0]?.models ?? [];
|
|
753
|
-
const flyoutShown = twoLevel && flyout !== null && hoveredGroup !== void 0;
|
|
754
|
-
const levelOptions = effortChoices(current.entry);
|
|
755
|
-
const switchEffort = effortSwitchable(levelOptions);
|
|
756
|
-
const effortText = effortLabel(effort);
|
|
757
1205
|
const clipBoxOf = (el) => {
|
|
758
1206
|
let node = el.parentElement;
|
|
759
1207
|
while (node !== null) {
|
|
760
1208
|
if (getComputedStyle(node).overflowX !== "visible") {
|
|
761
1209
|
const box = node.getBoundingClientRect();
|
|
762
|
-
return { left: box.left, right: box.right };
|
|
1210
|
+
return { left: Math.max(0, box.left), right: Math.min(window.innerWidth, box.right) };
|
|
763
1211
|
}
|
|
764
1212
|
node = node.parentElement;
|
|
765
1213
|
}
|
|
@@ -805,15 +1253,32 @@ function ComposerBox() {
|
|
|
805
1253
|
setFlyout(
|
|
806
1254
|
(prev) => prev !== null && prev.top === next.top && prev.maxHeight === next.maxHeight ? prev : next
|
|
807
1255
|
);
|
|
808
|
-
}, [hoverProvider, models.length, flyoutSide]);
|
|
1256
|
+
}, [hoverProvider, models.length, flyoutSide, measureTick]);
|
|
1257
|
+
react.useLayoutEffect(() => {
|
|
1258
|
+
if (!modelOpen) return void 0;
|
|
1259
|
+
const panel = modelPanelRef.current;
|
|
1260
|
+
if (panel === null) return void 0;
|
|
1261
|
+
const bump = () => {
|
|
1262
|
+
setMeasureTick((tick) => tick + 1);
|
|
1263
|
+
};
|
|
1264
|
+
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(bump);
|
|
1265
|
+
observer?.observe(panel);
|
|
1266
|
+
window.addEventListener("resize", bump);
|
|
1267
|
+
return () => {
|
|
1268
|
+
observer?.disconnect();
|
|
1269
|
+
window.removeEventListener("resize", bump);
|
|
1270
|
+
};
|
|
1271
|
+
}, [modelOpen]);
|
|
809
1272
|
react.useLayoutEffect(() => {
|
|
810
1273
|
if (!modelOpen) return;
|
|
811
1274
|
const panel = modelPanelRef.current;
|
|
812
1275
|
if (panel === null) return;
|
|
813
1276
|
const box = panel.getBoundingClientRect();
|
|
814
|
-
const
|
|
1277
|
+
const raw = { left: box.left - shiftRef.current, right: box.right - shiftRef.current };
|
|
1278
|
+
const shift = clampShift(raw, clipBoxOf(panel));
|
|
1279
|
+
shiftRef.current = shift;
|
|
815
1280
|
setPanelShift((prev) => prev === shift ? prev : shift);
|
|
816
|
-
}, [modelOpen, models.length, twoLevel]);
|
|
1281
|
+
}, [modelOpen, models.length, twoLevel, measureTick]);
|
|
817
1282
|
react.useEffect(() => {
|
|
818
1283
|
if (!modelOpen) return;
|
|
819
1284
|
if (hoverProvider === null) return;
|
|
@@ -836,9 +1301,9 @@ function ComposerBox() {
|
|
|
836
1301
|
"data-model-current": on ? "true" : void 0,
|
|
837
1302
|
onClick: () => {
|
|
838
1303
|
setModelOpen(false);
|
|
839
|
-
|
|
1304
|
+
onFault(null);
|
|
840
1305
|
void channel.invoke("setModel", [choice.value]).catch((reason) => {
|
|
841
|
-
|
|
1306
|
+
onFault(reason instanceof Error ? reason.message : String(reason));
|
|
842
1307
|
});
|
|
843
1308
|
},
|
|
844
1309
|
children: [
|
|
@@ -871,144 +1336,877 @@ function ComposerBox() {
|
|
|
871
1336
|
const openModelsSettings = () => {
|
|
872
1337
|
window.dispatchEvent(new CustomEvent("shell.settings.open", { detail: { section: "models" } }));
|
|
873
1338
|
};
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
// 为什么不让分支行长在 `.composer` 里(原来就是):`.composer` 是带描边和圆角的
|
|
878
|
-
// 输入框本体,住在里面的东西会被同一个外框一起圈住,分支钮看着就成了输入框的一部分
|
|
879
|
-
// (用户报「git 管理按钮,需要与输入框作出区分」)。参考实现里这一行也在输入框上方的
|
|
880
|
-
// 框外。`.composer-zone` 的「与正文列同宽」打在插件根节点上,所以这一层要接住它。
|
|
881
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "composer-stack", style: { marginTop: 10 }, children: [
|
|
882
|
-
git.repo ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "composer-git", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "model-anchor", children: [
|
|
1339
|
+
return {
|
|
1340
|
+
node: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1341
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "model-anchor", children: [
|
|
883
1342
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
884
1343
|
"button",
|
|
885
1344
|
{
|
|
886
1345
|
type: "button",
|
|
887
|
-
|
|
888
|
-
|
|
1346
|
+
ref: modelChipRef,
|
|
1347
|
+
className: `model-btn composer-model-chip${modelOpen ? " open" : ""}`,
|
|
1348
|
+
title: `模型:${chip.full}(点开换)`,
|
|
889
1349
|
"aria-haspopup": "menu",
|
|
890
|
-
"aria-expanded":
|
|
1350
|
+
"aria-expanded": modelOpen,
|
|
1351
|
+
"aria-label": `当前模型 ${chip.full}`,
|
|
1352
|
+
"data-composer-model": current.entry?.value ?? chip.full,
|
|
891
1353
|
onClick: () => {
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
1354
|
+
setModelOpen((open) => !open);
|
|
1355
|
+
setHoverProvider(null);
|
|
1356
|
+
setFlyout(null);
|
|
1357
|
+
shiftRef.current = 0;
|
|
1358
|
+
setPanelShift(0);
|
|
896
1359
|
setEffortOpen(false);
|
|
1360
|
+
onTakeOver();
|
|
897
1361
|
},
|
|
898
1362
|
children: [
|
|
899
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui$1.
|
|
900
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "
|
|
1363
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconPackage, { size: 13 }),
|
|
1364
|
+
chip.prefix === "" || dropPrefix ? null : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "composer-model-provider", children: chip.prefix }),
|
|
1365
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "model-name", children: chip.name }),
|
|
901
1366
|
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronDown, { size: 12 })
|
|
902
1367
|
]
|
|
903
1368
|
}
|
|
904
1369
|
),
|
|
905
|
-
|
|
1370
|
+
modelOpen ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
906
1371
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
907
1372
|
"div",
|
|
908
1373
|
{
|
|
909
1374
|
className: "pop-mask",
|
|
910
1375
|
onClick: () => {
|
|
911
|
-
|
|
1376
|
+
setModelOpen(false);
|
|
912
1377
|
}
|
|
913
1378
|
}
|
|
914
1379
|
),
|
|
915
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
{
|
|
928
|
-
type: "text",
|
|
929
|
-
value: branchQuery,
|
|
930
|
-
placeholder: "搜索分支…",
|
|
931
|
-
"aria-label": "搜索分支",
|
|
932
|
-
autoFocus: true,
|
|
933
|
-
onChange: (event) => {
|
|
934
|
-
setBranchQuery(event.target.value);
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
)
|
|
938
|
-
] }),
|
|
939
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "model-list git-branch-list", ref: branchRows, children: branchList === null ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pop-item", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: "正在读取分支…" }) }) : filteredBranches(branchList.branches, branchQuery).length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pop-item", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: branchQuery.trim() === "" ? "这个仓库还没有分支" : "没有匹配的分支" }) }) : filteredBranches(branchList.branches, branchQuery).map((row) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
940
|
-
"button",
|
|
941
|
-
{
|
|
942
|
-
type: "button",
|
|
943
|
-
role: "menuitemradio",
|
|
944
|
-
"aria-checked": row.current,
|
|
945
|
-
className: `pop-item${row.current ? " on" : ""}`,
|
|
946
|
-
title: row.current ? `${row.name}(当前分支)` : `切到 ${row.name}`,
|
|
947
|
-
disabled: row.current || branchBusy,
|
|
948
|
-
...row.current ? { "data-branch-current": "true" } : {},
|
|
949
|
-
onClick: () => {
|
|
950
|
-
switchBranch(row.name);
|
|
951
|
-
},
|
|
952
|
-
children: [
|
|
953
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconBranch, { size: 13, className: "git-item-icon" }),
|
|
954
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: row.name }),
|
|
955
|
-
row.current ? /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconCheck, { size: 14, className: "check" }) : null
|
|
956
|
-
]
|
|
1380
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1381
|
+
"div",
|
|
1382
|
+
{
|
|
1383
|
+
className: `model-pop model-picker${twoLevel ? "" : " flat"}`,
|
|
1384
|
+
role: "menu",
|
|
1385
|
+
"aria-label": "选择模型",
|
|
1386
|
+
ref: modelPanelRef,
|
|
1387
|
+
"data-flyout-side": flyoutShown ? flyoutSide : void 0,
|
|
1388
|
+
style: panelShift === 0 ? void 0 : { transform: `translateX(${String(panelShift)}px)` },
|
|
1389
|
+
onMouseLeave: () => {
|
|
1390
|
+
setHoverProvider(null);
|
|
1391
|
+
setFlyout(null);
|
|
957
1392
|
},
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
1393
|
+
children: [
|
|
1394
|
+
current.entry === void 0 && model !== "" ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pop-item model-unknown", "data-model-unknown": "true", children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "name", children: [
|
|
1395
|
+
"当前:",
|
|
1396
|
+
model,
|
|
1397
|
+
" —— 清单里没有这个模型"
|
|
1398
|
+
] }) }) : null,
|
|
1399
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "model-picker-body", children: twoLevel ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1400
|
+
"div",
|
|
1401
|
+
{
|
|
1402
|
+
className: "model-providers",
|
|
1403
|
+
"data-model-providers": "",
|
|
1404
|
+
onScroll: () => {
|
|
1405
|
+
if (hoverProvider === null) return;
|
|
1406
|
+
const row = modelPanelRef.current?.querySelector(
|
|
1407
|
+
`[data-model-provider="${CSS.escape(hoverProvider)}"]`
|
|
1408
|
+
) ?? null;
|
|
1409
|
+
openFlyout(hoverProvider, row);
|
|
1410
|
+
},
|
|
1411
|
+
children: groups.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pop-item", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: "清单没取到" }) }) : groups.map((group) => {
|
|
1412
|
+
const owns = current.group?.provider === group.provider;
|
|
1413
|
+
const hint = providerHint(group, current);
|
|
1414
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1415
|
+
"button",
|
|
1416
|
+
{
|
|
1417
|
+
type: "button",
|
|
1418
|
+
role: "menuitem",
|
|
1419
|
+
"aria-current": owns,
|
|
1420
|
+
className: `pop-item provider-row${group.provider === hoverProvider ? " on" : ""}`,
|
|
1421
|
+
"data-model-provider": group.provider,
|
|
1422
|
+
"data-provider-current": owns ? "true" : void 0,
|
|
1423
|
+
title: hint === "" ? `${group.displayName} · ${String(group.models.length)} 个模型` : `${group.displayName} · 当前 ${hint}`,
|
|
1424
|
+
onMouseEnter: (event) => {
|
|
1425
|
+
openFlyout(group.provider, event.currentTarget);
|
|
1426
|
+
},
|
|
1427
|
+
onFocus: (event) => {
|
|
1428
|
+
openFlyout(group.provider, event.currentTarget);
|
|
1429
|
+
},
|
|
1430
|
+
onClick: (event) => {
|
|
1431
|
+
openFlyout(group.provider, event.currentTarget);
|
|
1432
|
+
},
|
|
1433
|
+
children: [
|
|
1434
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: group.displayName }),
|
|
1435
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "model-picker-check", children: owns ? /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconCheck, { size: 13, className: "check" }) : null }),
|
|
1436
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronRight, { size: 12, className: "provider-arrow" })
|
|
1437
|
+
]
|
|
1438
|
+
},
|
|
1439
|
+
group.provider
|
|
1440
|
+
);
|
|
1441
|
+
})
|
|
1442
|
+
}
|
|
1443
|
+
) : modelRowList(visibleModels) }),
|
|
1444
|
+
flyoutShown ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1445
|
+
"div",
|
|
1446
|
+
{
|
|
1447
|
+
className: `model-flyout${flyoutSide === "overlay" ? " model-flyout-inline" : ""}`,
|
|
1448
|
+
"data-model-flyout": "",
|
|
1449
|
+
"data-side": flyoutSide,
|
|
1450
|
+
style: flyoutSide === "overlay" ? void 0 : {
|
|
1451
|
+
"--flyout-top": `${String(flyout.top)}px`,
|
|
1452
|
+
"--flyout-max": `${String(flyout.maxHeight)}px`,
|
|
1453
|
+
"--flyout-w": `${String(FLYOUT_WIDTH)}px`
|
|
1454
|
+
},
|
|
1455
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1456
|
+
"div",
|
|
1457
|
+
{
|
|
1458
|
+
className: "model-flyout-card",
|
|
1459
|
+
role: "menu",
|
|
1460
|
+
"aria-label": `${hoveredGroup.displayName} 的模型`,
|
|
1461
|
+
ref: flyoutCardRef,
|
|
1462
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "model-picker-rows", "data-model-rows": "", ref: modelRows, children: modelRowList(visibleModels) })
|
|
986
1463
|
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1464
|
+
)
|
|
1465
|
+
}
|
|
1466
|
+
) : null,
|
|
1467
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1468
|
+
"button",
|
|
1469
|
+
{
|
|
1470
|
+
type: "button",
|
|
1471
|
+
className: "pop-item model-manage",
|
|
1472
|
+
"data-model-manage": "",
|
|
1473
|
+
onClick: () => {
|
|
1474
|
+
setModelOpen(false);
|
|
1475
|
+
openModelsSettings();
|
|
1476
|
+
},
|
|
1477
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: "管理模型" })
|
|
1478
|
+
}
|
|
1479
|
+
)
|
|
1480
|
+
]
|
|
1481
|
+
}
|
|
1482
|
+
)
|
|
1483
|
+
] }) : null
|
|
1484
|
+
] }),
|
|
1485
|
+
switchEffort ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "model-anchor model-anchor-sheet", children: [
|
|
1486
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1487
|
+
"button",
|
|
1488
|
+
{
|
|
1489
|
+
type: "button",
|
|
1490
|
+
className: `model-btn composer-effort-chip${effortOpen ? " open" : ""}`,
|
|
1491
|
+
title: `思考强度:${effortText}(点开换档)`,
|
|
1492
|
+
"aria-haspopup": "menu",
|
|
1493
|
+
"aria-expanded": effortOpen,
|
|
1494
|
+
"aria-label": `当前思考强度 ${effortText}`,
|
|
1495
|
+
"data-composer-effort": shownEffort,
|
|
1496
|
+
onClick: () => {
|
|
1497
|
+
setEffortOpen((open) => !open);
|
|
1498
|
+
setModelOpen(false);
|
|
1499
|
+
onTakeOver();
|
|
1500
|
+
},
|
|
1501
|
+
children: [
|
|
1502
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconBrain, { size: 13 }),
|
|
1503
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "model-name", children: effortText }),
|
|
1504
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronDown, { size: 12 })
|
|
1505
|
+
]
|
|
1506
|
+
}
|
|
1507
|
+
),
|
|
1508
|
+
effortOpen ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1509
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1510
|
+
"div",
|
|
1511
|
+
{
|
|
1512
|
+
className: "pop-mask",
|
|
1513
|
+
onClick: () => {
|
|
1514
|
+
setEffortOpen(false);
|
|
1005
1515
|
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1516
|
+
}
|
|
1517
|
+
),
|
|
1518
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "model-pop effort-pop", role: "group", "aria-label": "思考强度", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1519
|
+
EffortSlider,
|
|
1520
|
+
{
|
|
1521
|
+
levels: sliderLevels,
|
|
1522
|
+
value: shownEffort,
|
|
1523
|
+
note: current.entry === void 0 && model !== "" ? "模型不在清单里,列的是它声明的全部档位" : null,
|
|
1524
|
+
onCommit: commitEffort
|
|
1525
|
+
}
|
|
1526
|
+
) })
|
|
1008
1527
|
] }) : null
|
|
1009
|
-
] })
|
|
1010
|
-
|
|
1011
|
-
|
|
1528
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1529
|
+
"span",
|
|
1530
|
+
{
|
|
1531
|
+
className: "model-btn composer-effort-chip fixed",
|
|
1532
|
+
title: `思考强度:${effortText}(这个模型没有可切换的档位)`,
|
|
1533
|
+
"data-composer-effort": effort,
|
|
1534
|
+
children: [
|
|
1535
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconBrain, { size: 13 }),
|
|
1536
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "model-name", children: effortText })
|
|
1537
|
+
]
|
|
1538
|
+
}
|
|
1539
|
+
)
|
|
1540
|
+
] }),
|
|
1541
|
+
allowImage: imageInputAllowed,
|
|
1542
|
+
close: () => {
|
|
1543
|
+
setModelOpen(false);
|
|
1544
|
+
setEffortOpen(false);
|
|
1545
|
+
},
|
|
1546
|
+
barRef
|
|
1547
|
+
};
|
|
1548
|
+
}
|
|
1549
|
+
const TEAMMATE_REPORT_OPEN = "<teammate-report ";
|
|
1550
|
+
const REVIEW_FINDINGS_OPEN = "<review-findings ";
|
|
1551
|
+
const MESSAGE_OPEN = "<message ";
|
|
1552
|
+
const DETAIL_CHARS = 120;
|
|
1553
|
+
function attrOf(text, key) {
|
|
1554
|
+
const match = new RegExp(`${key}="([^"]*)"`).exec(text);
|
|
1555
|
+
return match?.[1] ?? "";
|
|
1556
|
+
}
|
|
1557
|
+
function flatten(text) {
|
|
1558
|
+
const flat = text.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
|
|
1559
|
+
const chars = Array.from(flat);
|
|
1560
|
+
return chars.length > DETAIL_CHARS ? `${chars.slice(0, DETAIL_CHARS).join("")}…` : flat;
|
|
1561
|
+
}
|
|
1562
|
+
function summarizeNotice(text) {
|
|
1563
|
+
if (text.startsWith(TEAMMATE_REPORT_OPEN)) {
|
|
1564
|
+
const name = attrOf(text, "from");
|
|
1565
|
+
const state = attrOf(text, "state");
|
|
1566
|
+
const who = name === "" ? "一个队友" : `队友 ${name}`;
|
|
1567
|
+
const reportAt = text.indexOf("它的汇报:");
|
|
1568
|
+
const body = reportAt === -1 ? text : text.slice(reportAt + "它的汇报:".length);
|
|
1569
|
+
return {
|
|
1570
|
+
label: `${who}${state === "" ? "" : ` ${state}`},汇报了,本步结束会交给模型`,
|
|
1571
|
+
detail: flatten(body)
|
|
1572
|
+
};
|
|
1573
|
+
}
|
|
1574
|
+
if (text.startsWith(REVIEW_FINDINGS_OPEN)) {
|
|
1575
|
+
const name = attrOf(text, "teammate");
|
|
1576
|
+
const state = attrOf(text, "state");
|
|
1577
|
+
const who = name === "" ? "审查队友" : `审查队友 ${name}`;
|
|
1578
|
+
const open = text.indexOf(">");
|
|
1579
|
+
const close = text.lastIndexOf("</review-findings>");
|
|
1580
|
+
const body = open === -1 ? text : close === -1 ? text.slice(open + 1) : text.slice(open + 1, close);
|
|
1581
|
+
return {
|
|
1582
|
+
label: `${who}${state === "" ? "" : ` ${state}`},交回了 findings,本步结束会交给模型`,
|
|
1583
|
+
detail: flatten(body)
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
if (text.startsWith(MESSAGE_OPEN)) {
|
|
1587
|
+
const from = attrOf(text, "from");
|
|
1588
|
+
const who = from === "" || from === "user" ? "队友" : `队友 ${from}`;
|
|
1589
|
+
const open = text.indexOf(">");
|
|
1590
|
+
const close = text.lastIndexOf("</message>");
|
|
1591
|
+
const body = open === -1 ? text : close === -1 ? text.slice(open + 1) : text.slice(open + 1, close);
|
|
1592
|
+
return {
|
|
1593
|
+
label: `${who} 传来一条消息,本步结束会交给模型`,
|
|
1594
|
+
detail: flatten(body)
|
|
1595
|
+
};
|
|
1596
|
+
}
|
|
1597
|
+
return { label: "有一条待投递通知,本步结束会交给模型", detail: flatten(text) };
|
|
1598
|
+
}
|
|
1599
|
+
function NoticeStrip() {
|
|
1600
|
+
const notices = ui$1.useHostSelector(readNotices, sameNotices);
|
|
1601
|
+
if (notices.length === 0) return null;
|
|
1602
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "notice-strip", "data-notice-strip": "", children: notices.map((item) => {
|
|
1603
|
+
const summary = summarizeNotice(item.text);
|
|
1604
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "notice-row", children: [
|
|
1605
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "notice-lead", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconSpark, { size: 13 }) }),
|
|
1606
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "notice-label", "data-tip": summary.detail === "" ? summary.label : summary.detail, children: summary.label }),
|
|
1607
|
+
summary.detail === "" ? null : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "notice-detail", children: summary.detail })
|
|
1608
|
+
] }, item.index);
|
|
1609
|
+
}) });
|
|
1610
|
+
}
|
|
1611
|
+
const PREVIEW_CHARS = 200;
|
|
1612
|
+
function previewOf(text) {
|
|
1613
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
1614
|
+
const chars = Array.from(flat);
|
|
1615
|
+
return chars.length > PREVIEW_CHARS ? `${chars.slice(0, PREVIEW_CHARS).join("")}…` : flat;
|
|
1616
|
+
}
|
|
1617
|
+
function QueueDock() {
|
|
1618
|
+
const channel = ui$1.useHostChannel();
|
|
1619
|
+
const items = ui$1.useHostSelector(readQueued, sameQueued);
|
|
1620
|
+
const turnState = ui$1.useHostSelector(uiPrimitives.readTurnState);
|
|
1621
|
+
const [collapsed, setCollapsed] = react.useState(true);
|
|
1622
|
+
const [editing, setEditing] = react.useState(null);
|
|
1623
|
+
const [busy, setBusy] = react.useState(false);
|
|
1624
|
+
const [fault, setFault] = react.useState(null);
|
|
1625
|
+
const count = items.length;
|
|
1626
|
+
react.useEffect(() => {
|
|
1627
|
+
if (count === 0 && !collapsed) setCollapsed(true);
|
|
1628
|
+
if (editing !== null && !items.some((item) => item.index === editing.index)) setEditing(null);
|
|
1629
|
+
}, [collapsed, editing, items, count]);
|
|
1630
|
+
if (count === 0) return null;
|
|
1631
|
+
const expanded = count === 1 || !collapsed || editing !== null;
|
|
1632
|
+
const running = turnState !== "idle";
|
|
1633
|
+
const act = async (work, failure) => {
|
|
1634
|
+
setBusy(true);
|
|
1635
|
+
setFault(null);
|
|
1636
|
+
try {
|
|
1637
|
+
return await work() ? "ok" : "rejected";
|
|
1638
|
+
} catch (error) {
|
|
1639
|
+
setFault(`${failure}:${error instanceof Error ? error.message : String(error)}`);
|
|
1640
|
+
return "failed";
|
|
1641
|
+
} finally {
|
|
1642
|
+
setBusy(false);
|
|
1643
|
+
}
|
|
1644
|
+
};
|
|
1645
|
+
const save = async (index) => {
|
|
1646
|
+
const value = editing?.text.trim() ?? "";
|
|
1647
|
+
if (value === "") return;
|
|
1648
|
+
const outcome = await act(() => channel.invoke("editQueued", [index, value]), "编辑失败");
|
|
1649
|
+
if (outcome === "ok") {
|
|
1650
|
+
setEditing(null);
|
|
1651
|
+
return;
|
|
1652
|
+
}
|
|
1653
|
+
if (outcome === "rejected") setFault("编辑失败:这条已经开始发送了");
|
|
1654
|
+
};
|
|
1655
|
+
const remove = async (index) => {
|
|
1656
|
+
const outcome = await act(() => channel.invoke("removeQueued", [index]), "撤掉失败");
|
|
1657
|
+
if (outcome === "rejected") setFault("撤掉失败:这条已经开始发送了");
|
|
1658
|
+
};
|
|
1659
|
+
const steer = async (index) => {
|
|
1660
|
+
const ahead = index;
|
|
1661
|
+
const detail = ahead > 0 ? `会打断模型当前的输出,让这条以及排在它前面的 ${String(ahead)} 条立刻作为新一轮发出去(模型已经说出的半截会保留)。` : "会打断模型当前的输出,让这条立刻作为新一轮发出去(模型已经说出的半截会保留)。";
|
|
1662
|
+
if (!window.confirm(`打断并插话?
|
|
1663
|
+
|
|
1664
|
+
${detail}`)) return;
|
|
1665
|
+
const outcome = await act(() => channel.invoke("steerQueued", [index]), "插话失败");
|
|
1666
|
+
if (outcome === "rejected") setFault("插话没赶上:这一轮刚结束,排队消息会自己发出去");
|
|
1667
|
+
};
|
|
1668
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "queue-dock", "data-queue-dock": "", children: [
|
|
1669
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "queue-panel", children: [
|
|
1670
|
+
count > 1 ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1671
|
+
"button",
|
|
1672
|
+
{
|
|
1673
|
+
type: "button",
|
|
1674
|
+
className: "queue-head",
|
|
1675
|
+
"aria-expanded": expanded,
|
|
1676
|
+
disabled: busy || editing !== null,
|
|
1677
|
+
"data-tip": expanded ? "收起排队消息" : "展开排队消息",
|
|
1678
|
+
onClick: () => {
|
|
1679
|
+
setCollapsed((current) => !current);
|
|
1680
|
+
},
|
|
1681
|
+
children: [
|
|
1682
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "queue-lead", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconQueue, { size: 13 }) }),
|
|
1683
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "queue-count", children: [
|
|
1684
|
+
count,
|
|
1685
|
+
" 条排队消息"
|
|
1686
|
+
] }),
|
|
1687
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "queue-note", children: "这一轮跑完自动发出" }),
|
|
1688
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "queue-caret", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronDown, { size: 13 }) })
|
|
1689
|
+
]
|
|
1690
|
+
}
|
|
1691
|
+
) : null,
|
|
1692
|
+
expanded ? /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "queue-list", children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx("li", { className: "queue-row", children: editing?.index === item.index ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1693
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1694
|
+
"textarea",
|
|
1695
|
+
{
|
|
1696
|
+
className: "queue-edit-box",
|
|
1697
|
+
value: editing.text,
|
|
1698
|
+
autoFocus: true,
|
|
1699
|
+
rows: Math.min(8, Math.max(1, editing.text.split("\n").length)),
|
|
1700
|
+
"aria-label": "编辑排队消息",
|
|
1701
|
+
onChange: (event) => {
|
|
1702
|
+
setEditing({ index: item.index, text: event.target.value });
|
|
1703
|
+
},
|
|
1704
|
+
onKeyDown: (event) => {
|
|
1705
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
1706
|
+
event.preventDefault();
|
|
1707
|
+
void save(item.index);
|
|
1708
|
+
return;
|
|
1709
|
+
}
|
|
1710
|
+
if (event.key === "Escape") {
|
|
1711
|
+
event.preventDefault();
|
|
1712
|
+
setEditing(null);
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
),
|
|
1717
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1718
|
+
"button",
|
|
1719
|
+
{
|
|
1720
|
+
type: "button",
|
|
1721
|
+
className: "queue-act",
|
|
1722
|
+
"aria-label": "保存排队消息",
|
|
1723
|
+
"data-tip": "保存(回车)",
|
|
1724
|
+
disabled: busy || editing.text.trim() === "",
|
|
1725
|
+
onClick: () => void save(item.index),
|
|
1726
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconCheck, { size: 13 })
|
|
1727
|
+
}
|
|
1728
|
+
),
|
|
1729
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1730
|
+
"button",
|
|
1731
|
+
{
|
|
1732
|
+
type: "button",
|
|
1733
|
+
className: "queue-act",
|
|
1734
|
+
"aria-label": "取消编辑",
|
|
1735
|
+
"data-tip": "取消(Esc)",
|
|
1736
|
+
disabled: busy,
|
|
1737
|
+
onClick: () => {
|
|
1738
|
+
setEditing(null);
|
|
1739
|
+
},
|
|
1740
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconClose, { size: 13 })
|
|
1741
|
+
}
|
|
1742
|
+
)
|
|
1743
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1744
|
+
count === 1 ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "queue-lead", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconQueue, { size: 13 }) }) : null,
|
|
1745
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "queue-text", "data-tip": item.text, children: previewOf(item.text) }),
|
|
1746
|
+
item.images === void 0 || item.images.length === 0 ? null : /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "queue-badge", "data-tip": `随这条一起排队的 ${String(item.images.length)} 张图`, children: [
|
|
1747
|
+
"+",
|
|
1748
|
+
item.images.length,
|
|
1749
|
+
" 图"
|
|
1750
|
+
] }),
|
|
1751
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "queue-acts", children: [
|
|
1752
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1753
|
+
"button",
|
|
1754
|
+
{
|
|
1755
|
+
type: "button",
|
|
1756
|
+
className: "queue-act",
|
|
1757
|
+
"aria-label": "编辑排队消息",
|
|
1758
|
+
"data-tip": "改这条排队消息",
|
|
1759
|
+
disabled: busy,
|
|
1760
|
+
onClick: () => {
|
|
1761
|
+
setEditing({ index: item.index, text: item.text });
|
|
1762
|
+
},
|
|
1763
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconEdit, { size: 13 })
|
|
1764
|
+
}
|
|
1765
|
+
),
|
|
1766
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1767
|
+
"button",
|
|
1768
|
+
{
|
|
1769
|
+
type: "button",
|
|
1770
|
+
className: "queue-act",
|
|
1771
|
+
"aria-label": "撤回排队消息",
|
|
1772
|
+
"data-tip": "撤掉这条(还没发出去)",
|
|
1773
|
+
disabled: busy,
|
|
1774
|
+
onClick: () => void remove(item.index),
|
|
1775
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconTrash, { size: 13 })
|
|
1776
|
+
}
|
|
1777
|
+
),
|
|
1778
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1779
|
+
"button",
|
|
1780
|
+
{
|
|
1781
|
+
type: "button",
|
|
1782
|
+
className: "queue-act",
|
|
1783
|
+
"aria-label": "插话发送",
|
|
1784
|
+
"data-tip": running ? "打断当前输出,让这条立刻发出去(模型已说出的半截保留)" : "这一轮已经跑完,排队消息会自己发出去",
|
|
1785
|
+
disabled: busy || !running,
|
|
1786
|
+
onClick: () => void steer(item.index),
|
|
1787
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconArrowUp, { size: 13 })
|
|
1788
|
+
}
|
|
1789
|
+
)
|
|
1790
|
+
] })
|
|
1791
|
+
] }) }, item.index)) }) : null
|
|
1792
|
+
] }),
|
|
1793
|
+
fault === null ? null : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shell-composer-fault", children: fault })
|
|
1794
|
+
] });
|
|
1795
|
+
}
|
|
1796
|
+
const MAX_INPUT_HEIGHT = 200;
|
|
1797
|
+
const HISTORY_LIMIT = 50;
|
|
1798
|
+
let insertDraft = null;
|
|
1799
|
+
const DRAFT_STORE = /* @__PURE__ */ new Map();
|
|
1800
|
+
const ui = ui$1.defineUiPlugin({
|
|
1801
|
+
name: "输入区",
|
|
1802
|
+
apply(ui2) {
|
|
1803
|
+
ui2.provide("composerDraft", {
|
|
1804
|
+
insert: (text) => {
|
|
1805
|
+
insertDraft?.(text);
|
|
1806
|
+
}
|
|
1807
|
+
});
|
|
1808
|
+
ui2.slots.register("shell.composer", { id: "composer.notices", order: 40 }, NoticeStrip);
|
|
1809
|
+
ui2.slots.register("shell.composer", { id: "composer.box", order: 50 }, ComposerBox);
|
|
1810
|
+
ui2.slots.register("shell.composer", { id: "composer.queue", order: 60 }, QueueDock);
|
|
1811
|
+
}
|
|
1812
|
+
});
|
|
1813
|
+
function ComposerBox() {
|
|
1814
|
+
const channel = ui$1.useHostChannel();
|
|
1815
|
+
const turnState = ui$1.useHostSelector(uiPrimitives.readTurnState);
|
|
1816
|
+
const blocked = ui$1.useHostSelector(readHasApproval);
|
|
1817
|
+
const queuedCount = ui$1.useHostSelector(readInboxCount);
|
|
1818
|
+
const permissionPresets = ui$1.useHostSelector(readPermissionPresets, samePermissionPresets);
|
|
1819
|
+
const preset = ui$1.useHostSelector(readPresetSurface, samePresetSurface);
|
|
1820
|
+
const git = ui$1.useHostSelector(readGit, uiPrimitives.sameGitSurface);
|
|
1821
|
+
const draftKey = ui$1.useHostSelector(readSessionPath);
|
|
1822
|
+
const [text, setText] = react.useState("");
|
|
1823
|
+
const [fault, setFault] = react.useState(null);
|
|
1824
|
+
const [sending, setSending] = react.useState(false);
|
|
1825
|
+
const [attachments, setAttachments] = react.useState([]);
|
|
1826
|
+
const [dragOver, setDragOver] = react.useState(false);
|
|
1827
|
+
const [zoom, setZoom] = react.useState(null);
|
|
1828
|
+
const [permOpen, setPermOpen] = react.useState(false);
|
|
1829
|
+
const [presetOpen, setPresetOpen] = react.useState(false);
|
|
1830
|
+
const [branchOpen, setBranchOpen] = react.useState(false);
|
|
1831
|
+
const controls = useModelControls({
|
|
1832
|
+
channel,
|
|
1833
|
+
onFault: setFault,
|
|
1834
|
+
onTakeOver: () => {
|
|
1835
|
+
setPermOpen(false);
|
|
1836
|
+
setPresetOpen(false);
|
|
1837
|
+
setBranchOpen(false);
|
|
1838
|
+
}
|
|
1839
|
+
});
|
|
1840
|
+
const area = react.useRef(null);
|
|
1841
|
+
react.useEffect(() => {
|
|
1842
|
+
insertDraft = (value) => {
|
|
1843
|
+
setText(value);
|
|
1844
|
+
const node = area.current;
|
|
1845
|
+
if (node === null) return;
|
|
1846
|
+
node.focus();
|
|
1847
|
+
node.setSelectionRange(value.length, value.length);
|
|
1848
|
+
};
|
|
1849
|
+
return () => {
|
|
1850
|
+
insertDraft = null;
|
|
1851
|
+
};
|
|
1852
|
+
}, []);
|
|
1853
|
+
const history = react.useRef([]);
|
|
1854
|
+
const [historyAt, setHistoryAt] = react.useState(null);
|
|
1855
|
+
const drafts = react.useRef(DRAFT_STORE);
|
|
1856
|
+
const draftSessionId = ui$1.useHostSelector(readSessionId);
|
|
1857
|
+
const draftCwd = ui$1.useHostSelector(readDraftCwd);
|
|
1858
|
+
const draftUnsaved = ui$1.useHostSelector(readSessionUnsaved);
|
|
1859
|
+
const draftScope = draftScopeOf({
|
|
1860
|
+
sessionPath: draftKey,
|
|
1861
|
+
sessionId: draftSessionId,
|
|
1862
|
+
cwd: draftCwd,
|
|
1863
|
+
unsaved: draftUnsaved
|
|
1864
|
+
});
|
|
1865
|
+
const draftScopeRef = react.useRef(draftScope);
|
|
1866
|
+
const patchDraftsAttachment = (id, patch) => {
|
|
1867
|
+
for (const [key, draft] of drafts.current) {
|
|
1868
|
+
const list = draft.attachments;
|
|
1869
|
+
if (list === void 0 || !list.some((item) => item.id === id)) continue;
|
|
1870
|
+
const next = patch === null ? list.filter((item) => item.id !== id) : list.map((item) => item.id === id ? { ...item, ...patch } : item);
|
|
1871
|
+
drafts.current.set(key, { ...draft, attachments: next });
|
|
1872
|
+
}
|
|
1873
|
+
};
|
|
1874
|
+
const updateAttachment = (id, patch) => {
|
|
1875
|
+
setAttachments((list) => list.map((item) => item.id === id ? { ...item, ...patch } : item));
|
|
1876
|
+
patchDraftsAttachment(id, patch);
|
|
1877
|
+
};
|
|
1878
|
+
const removeAttachment = (id) => {
|
|
1879
|
+
const target = attachments.find((item) => item.id === id);
|
|
1880
|
+
if (target?.localUrl !== void 0) URL.revokeObjectURL(target.localUrl);
|
|
1881
|
+
setAttachments((list) => list.filter((item) => item.id !== id));
|
|
1882
|
+
patchDraftsAttachment(id, null);
|
|
1883
|
+
};
|
|
1884
|
+
const clearDraftAttachments = () => {
|
|
1885
|
+
for (const item of attachments) {
|
|
1886
|
+
if (item.localUrl !== void 0) URL.revokeObjectURL(item.localUrl);
|
|
1887
|
+
}
|
|
1888
|
+
setAttachments([]);
|
|
1889
|
+
const key = draftScopeRef.current.key;
|
|
1890
|
+
const saved = drafts.current.get(key);
|
|
1891
|
+
if (saved !== void 0) drafts.current.set(key, { ...saved, attachments: [] });
|
|
1892
|
+
};
|
|
1893
|
+
const working = turnState !== "idle";
|
|
1894
|
+
const restored = react.useRef(false);
|
|
1895
|
+
react.useEffect(() => {
|
|
1896
|
+
if (restored.current) return;
|
|
1897
|
+
restored.current = true;
|
|
1898
|
+
const key = draftScopeRef.current.key;
|
|
1899
|
+
if (key === "") return;
|
|
1900
|
+
const saved = DRAFT_STORE.get(key);
|
|
1901
|
+
if (saved === void 0) return;
|
|
1902
|
+
setText(saved.value);
|
|
1903
|
+
history.current = [...saved.history];
|
|
1904
|
+
setAttachments([...saved.attachments ?? []]);
|
|
1905
|
+
}, []);
|
|
1906
|
+
react.useEffect(() => {
|
|
1907
|
+
const key = draftScopeRef.current.key;
|
|
1908
|
+
if (key === "") return;
|
|
1909
|
+
DRAFT_STORE.set(key, { value: text, history: history.current, attachments });
|
|
1910
|
+
}, [text, attachments]);
|
|
1911
|
+
react.useEffect(() => {
|
|
1912
|
+
if (draftScopeRef.current.key === draftScope.key) return;
|
|
1913
|
+
const next = carryDraft(drafts.current, draftScopeRef.current, draftScope, {
|
|
1914
|
+
value: text,
|
|
1915
|
+
history: history.current,
|
|
1916
|
+
attachments
|
|
1917
|
+
});
|
|
1918
|
+
draftScopeRef.current = draftScope;
|
|
1919
|
+
setText(next.value);
|
|
1920
|
+
history.current = [...next.history];
|
|
1921
|
+
setAttachments([...next.attachments ?? []]);
|
|
1922
|
+
setHistoryAt(null);
|
|
1923
|
+
}, [draftScope.key, draftScope.sessionId, draftScope.unsaved, text, attachments]);
|
|
1924
|
+
react.useEffect(() => {
|
|
1925
|
+
const node = area.current;
|
|
1926
|
+
if (node === null) return;
|
|
1927
|
+
node.style.height = "auto";
|
|
1928
|
+
node.style.height = `${String(Math.min(node.scrollHeight, MAX_INPUT_HEIGHT))}px`;
|
|
1929
|
+
}, [text]);
|
|
1930
|
+
const send = (steer) => {
|
|
1931
|
+
const typed = text.trim();
|
|
1932
|
+
const picked = command.open && typed !== "/" ? command.insertText()?.trim() ?? null : null;
|
|
1933
|
+
const value = picked ?? typed;
|
|
1934
|
+
if (value === "" && attachments.length === 0 || blocked || sending) return;
|
|
1935
|
+
const claim = attachments.length === 0 ? command.claim(value) : null;
|
|
1936
|
+
if (claim !== null) {
|
|
1937
|
+
setFault(null);
|
|
1938
|
+
command.adopt(claim.insert);
|
|
1939
|
+
return;
|
|
1940
|
+
}
|
|
1941
|
+
if (value.startsWith("/") && attachments.length === 0) {
|
|
1942
|
+
command.hide();
|
|
1943
|
+
const target = value;
|
|
1944
|
+
setFault(null);
|
|
1945
|
+
void channel.invoke("runUiCommand", [target]).then(() => {
|
|
1946
|
+
history.current = [...history.current.filter((item) => item !== target), target].slice(-HISTORY_LIMIT);
|
|
1947
|
+
setHistoryAt(null);
|
|
1948
|
+
setText("");
|
|
1949
|
+
}).catch((reason) => {
|
|
1950
|
+
const message = reason instanceof Error ? reason.message : String(reason);
|
|
1951
|
+
setFault(
|
|
1952
|
+
message.includes("协议不允许调用的方法") ? "“/” 命令要宿主支持:当前宿主没把这条路接到界面通道,请在桌面端或终端里执行" : message
|
|
1953
|
+
);
|
|
1954
|
+
});
|
|
1955
|
+
return;
|
|
1956
|
+
}
|
|
1957
|
+
if (attachments.some((item) => item.uploading !== null)) {
|
|
1958
|
+
setFault("附件还在上传,请等上传完成后再发送");
|
|
1959
|
+
return;
|
|
1960
|
+
}
|
|
1961
|
+
const payload = composeSubmit(attachments);
|
|
1962
|
+
const steerIndex = steer && working ? queuedCount : null;
|
|
1963
|
+
setSending(true);
|
|
1964
|
+
setFault(null);
|
|
1965
|
+
void (async () => {
|
|
1966
|
+
try {
|
|
1967
|
+
if (payload.files.length > 0) {
|
|
1968
|
+
await channel.invoke("submit", [value, payload.images, payload.files]);
|
|
1969
|
+
} else if (payload.images.length > 0) {
|
|
1970
|
+
await channel.invoke("submit", [value, payload.images]);
|
|
1971
|
+
} else {
|
|
1972
|
+
await channel.invoke("submit", [value]);
|
|
1973
|
+
}
|
|
1974
|
+
if (value !== "") {
|
|
1975
|
+
history.current = [...history.current.filter((item) => item !== value), value].slice(-HISTORY_LIMIT);
|
|
1976
|
+
}
|
|
1977
|
+
setHistoryAt(null);
|
|
1978
|
+
void channel.invoke("refreshSessions").catch(() => void 0);
|
|
1979
|
+
if (steerIndex !== null) {
|
|
1980
|
+
const done = await channel.invoke("steerQueued", [steerIndex]);
|
|
1981
|
+
if (done !== true) setFault("插话没赶上:这一轮刚结束,这条消息会自己发出去");
|
|
1982
|
+
}
|
|
1983
|
+
setText("");
|
|
1984
|
+
clearDraftAttachments();
|
|
1985
|
+
if (payload.dropped > 0) {
|
|
1986
|
+
setFault(`图片最多 ${String(MAX_IMAGES)} 张,已发送前 ${String(MAX_IMAGES)} 张(${String(payload.dropped)} 张未发送)`);
|
|
1987
|
+
}
|
|
1988
|
+
} catch (reason) {
|
|
1989
|
+
setFault(reason instanceof Error ? reason.message : String(reason));
|
|
1990
|
+
} finally {
|
|
1991
|
+
setSending(false);
|
|
1992
|
+
}
|
|
1993
|
+
})();
|
|
1994
|
+
};
|
|
1995
|
+
const interrupt = () => {
|
|
1996
|
+
setFault(null);
|
|
1997
|
+
void channel.invoke("interrupt").catch((reason) => {
|
|
1998
|
+
setFault(reason instanceof Error ? reason.message : String(reason));
|
|
1999
|
+
});
|
|
2000
|
+
};
|
|
2001
|
+
const choosePermissionPreset = (name, label) => {
|
|
2002
|
+
setPermOpen(false);
|
|
2003
|
+
setFault(null);
|
|
2004
|
+
const native = ui$1.getHostNative();
|
|
2005
|
+
if (!native.available) {
|
|
2006
|
+
setFault("切权限预设这条口子只在桌面窗口里开(浏览器页签与远程页面够不着),请用桌面端或终端改");
|
|
2007
|
+
return;
|
|
2008
|
+
}
|
|
2009
|
+
void native.invoke("usePermissionPreset", [name]).then(() => {
|
|
2010
|
+
ui$1.toastOk(`权限预设已切到「${label}」`);
|
|
2011
|
+
}).catch((reason) => {
|
|
2012
|
+
setFault(`切权限预设失败:${reason instanceof Error ? reason.message : String(reason)}`);
|
|
2013
|
+
});
|
|
2014
|
+
};
|
|
2015
|
+
const choosePreset = (name, label) => {
|
|
2016
|
+
setPresetOpen(false);
|
|
2017
|
+
setFault(null);
|
|
2018
|
+
void channel.invoke("usePreset", [name]).then(() => {
|
|
2019
|
+
ui$1.toastOk(`已切到「${label}」模式`);
|
|
2020
|
+
}).catch((reason) => {
|
|
2021
|
+
ui$1.toastErr(`切换失败:${reason instanceof Error ? reason.message : String(reason)}`);
|
|
2022
|
+
});
|
|
2023
|
+
};
|
|
2024
|
+
const mention = useMention({
|
|
2025
|
+
channel,
|
|
2026
|
+
area,
|
|
2027
|
+
apply: (next, caret) => {
|
|
2028
|
+
setText(next);
|
|
2029
|
+
window.requestAnimationFrame(() => {
|
|
2030
|
+
area.current?.setSelectionRange(caret, caret);
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
});
|
|
2034
|
+
const command = useCommandMenu({
|
|
2035
|
+
channel,
|
|
2036
|
+
apply: (next, caret) => {
|
|
2037
|
+
setText(next);
|
|
2038
|
+
window.requestAnimationFrame(() => {
|
|
2039
|
+
area.current?.setSelectionRange(caret, caret);
|
|
2040
|
+
});
|
|
2041
|
+
},
|
|
2042
|
+
onUnavailable: () => {
|
|
2043
|
+
setFault("当前宿主没接“/”命令通道:菜单不可用,请用桌面端或终端执行(升级宿主后自动可用)");
|
|
2044
|
+
}
|
|
2045
|
+
});
|
|
2046
|
+
const onKeyDown = (event) => {
|
|
2047
|
+
if (command.open) {
|
|
2048
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
2049
|
+
event.preventDefault();
|
|
2050
|
+
command.move(event.key === "ArrowDown" ? 1 : -1);
|
|
2051
|
+
return;
|
|
2052
|
+
}
|
|
2053
|
+
if (event.key === "Tab") {
|
|
2054
|
+
event.preventDefault();
|
|
2055
|
+
event.stopPropagation();
|
|
2056
|
+
command.pick();
|
|
2057
|
+
return;
|
|
2058
|
+
}
|
|
2059
|
+
if (event.key === "Escape") {
|
|
2060
|
+
event.preventDefault();
|
|
2061
|
+
command.close();
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
if (mention.open) {
|
|
2066
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
2067
|
+
event.preventDefault();
|
|
2068
|
+
mention.move(event.key === "ArrowDown" ? 1 : -1);
|
|
2069
|
+
return;
|
|
2070
|
+
}
|
|
2071
|
+
if (event.key === "Tab" || event.key === "Enter") {
|
|
2072
|
+
event.preventDefault();
|
|
2073
|
+
event.stopPropagation();
|
|
2074
|
+
mention.pick();
|
|
2075
|
+
return;
|
|
2076
|
+
}
|
|
2077
|
+
if (event.key === "Escape") {
|
|
2078
|
+
event.preventDefault();
|
|
2079
|
+
mention.close();
|
|
2080
|
+
return;
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
if (event.key === "Backspace" && text === "" && attachments.length > 0) {
|
|
2084
|
+
event.preventDefault();
|
|
2085
|
+
const last = attachments[attachments.length - 1];
|
|
2086
|
+
if (last !== void 0) removeAttachment(last.id);
|
|
2087
|
+
return;
|
|
2088
|
+
}
|
|
2089
|
+
if (event.key === "Enter") {
|
|
2090
|
+
if (event.shiftKey || event.nativeEvent.isComposing) return;
|
|
2091
|
+
event.preventDefault();
|
|
2092
|
+
send(event.ctrlKey || event.metaKey);
|
|
2093
|
+
return;
|
|
2094
|
+
}
|
|
2095
|
+
if (event.key === "ArrowUp" && (text === "" || historyAt !== null) && history.current.length > 0) {
|
|
2096
|
+
event.preventDefault();
|
|
2097
|
+
const next = historyAt === null ? history.current.length - 1 : Math.max(0, historyAt - 1);
|
|
2098
|
+
setHistoryAt(next);
|
|
2099
|
+
setText(history.current[next] ?? "");
|
|
2100
|
+
return;
|
|
2101
|
+
}
|
|
2102
|
+
if (event.key === "ArrowDown" && historyAt !== null) {
|
|
2103
|
+
event.preventDefault();
|
|
2104
|
+
const next = historyAt + 1;
|
|
2105
|
+
if (next >= history.current.length) {
|
|
2106
|
+
setHistoryAt(null);
|
|
2107
|
+
setText("");
|
|
2108
|
+
} else {
|
|
2109
|
+
setHistoryAt(next);
|
|
2110
|
+
setText(history.current[next] ?? "");
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
};
|
|
2114
|
+
const onTextChange = (value, caret) => {
|
|
2115
|
+
setText(value);
|
|
2116
|
+
setHistoryAt(null);
|
|
2117
|
+
command.track(value, caret);
|
|
2118
|
+
if (commandQuery(value, caret) === null) mention.track(value, caret);
|
|
2119
|
+
else mention.close();
|
|
2120
|
+
};
|
|
2121
|
+
const sendable = text.trim() !== "" || attachments.length > 0;
|
|
2122
|
+
const inputHint = command.claim(text)?.hint ?? null;
|
|
2123
|
+
const queueing = working && sendable;
|
|
2124
|
+
const permOption = permissionPresets.options.find((item) => item.name === permissionPresets.current);
|
|
2125
|
+
const presetOption = preset.options.find((item) => item.name === preset.current);
|
|
2126
|
+
const addOneFile = async (file, kind) => {
|
|
2127
|
+
const id = newAttachmentId();
|
|
2128
|
+
const name = displayNameOf(file, kind);
|
|
2129
|
+
const localUrl = URL.createObjectURL(file);
|
|
2130
|
+
const placeholder2 = {
|
|
2131
|
+
id,
|
|
2132
|
+
kind,
|
|
2133
|
+
name,
|
|
2134
|
+
mime: file.type,
|
|
2135
|
+
bytes: file.size,
|
|
2136
|
+
meta: null,
|
|
2137
|
+
previewUrl: localUrl,
|
|
2138
|
+
localUrl,
|
|
2139
|
+
frames: [],
|
|
2140
|
+
uploading: 0,
|
|
2141
|
+
error: null
|
|
2142
|
+
};
|
|
2143
|
+
setAttachments((list) => [...list, placeholder2]);
|
|
2144
|
+
try {
|
|
2145
|
+
const payload = kind === "image" ? await normalizeImage(file) : file;
|
|
2146
|
+
const meta = await uploadFile(payload, name, (ratio) => {
|
|
2147
|
+
updateAttachment(id, { uploading: ratio });
|
|
2148
|
+
});
|
|
2149
|
+
updateAttachment(id, { meta, previewUrl: meta.url, uploading: null, localUrl: void 0 });
|
|
2150
|
+
URL.revokeObjectURL(localUrl);
|
|
2151
|
+
if (kind !== "video") return;
|
|
2152
|
+
const frames = await extractVideoFrames(meta.url, 6);
|
|
2153
|
+
const base = name.replace(/\.[^.]+$/, "");
|
|
2154
|
+
const urls = [];
|
|
2155
|
+
for (const [index, frame] of frames.entries()) {
|
|
2156
|
+
try {
|
|
2157
|
+
const frameMeta = await uploadFile(frame, `${base}-帧${String(index + 1)}.jpg`);
|
|
2158
|
+
urls.push(frameMeta.url);
|
|
2159
|
+
updateAttachment(id, { frames: [...urls] });
|
|
2160
|
+
} catch {
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
} catch (reason) {
|
|
2164
|
+
URL.revokeObjectURL(localUrl);
|
|
2165
|
+
setAttachments((list) => list.filter((item) => item.id !== id));
|
|
2166
|
+
patchDraftsAttachment(id, null);
|
|
2167
|
+
setFault(`上传失败:${reason instanceof Error ? reason.message : String(reason)}`);
|
|
2168
|
+
}
|
|
2169
|
+
};
|
|
2170
|
+
const addFiles = (files) => {
|
|
2171
|
+
if (files.length === 0) return;
|
|
2172
|
+
setFault(null);
|
|
2173
|
+
let rejected = false;
|
|
2174
|
+
for (const file of files) {
|
|
2175
|
+
const kind = kindOf(file);
|
|
2176
|
+
if (kind !== "file" && !controls.allowImage) {
|
|
2177
|
+
rejected = true;
|
|
2178
|
+
continue;
|
|
2179
|
+
}
|
|
2180
|
+
void addOneFile(file, kind);
|
|
2181
|
+
}
|
|
2182
|
+
if (rejected) setFault("当前模型不支持图片,请切换支持图片的模型");
|
|
2183
|
+
};
|
|
2184
|
+
const placeholder = blocked ? "等待审批…" : working ? "回合进行中:回车把消息排进队里,Ctrl+Enter 插话(打断当前输出)" : "发消息,@ 引用文件,可贴图 / 拖图片、视频或文件进来,回车发送,Ctrl+Enter 插话";
|
|
2185
|
+
return (
|
|
2186
|
+
// 这一层是「输入框外面那一列」:分支行在上、输入框在下,各占一行、各带自己的边。
|
|
2187
|
+
// 为什么不让分支行长在 `.composer` 里(原来就是):`.composer` 是带描边和圆角的
|
|
2188
|
+
// 输入框本体,住在里面的东西会被同一个外框一起圈住,分支钮看着就成了输入框的一部分
|
|
2189
|
+
// (用户报「git 管理按钮,需要与输入框作出区分」)。参考实现里这一行也在输入框上方的
|
|
2190
|
+
// 框外。`.composer-zone` 的「与正文列同宽」打在插件根节点上,所以这一层要接住它。
|
|
2191
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "composer-stack", style: { marginTop: 10 }, children: [
|
|
2192
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2193
|
+
BranchMenu,
|
|
2194
|
+
{
|
|
2195
|
+
open: branchOpen,
|
|
2196
|
+
onOpenChange: (open) => {
|
|
2197
|
+
setBranchOpen(open);
|
|
2198
|
+
if (!open) return;
|
|
2199
|
+
setPermOpen(false);
|
|
2200
|
+
setPresetOpen(false);
|
|
2201
|
+
controls.close();
|
|
2202
|
+
},
|
|
2203
|
+
git,
|
|
2204
|
+
channel,
|
|
2205
|
+
onFault: setFault
|
|
2206
|
+
}
|
|
2207
|
+
),
|
|
2208
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2209
|
+
"div",
|
|
1012
2210
|
{
|
|
1013
2211
|
className: "composer",
|
|
1014
2212
|
onClick: (event) => {
|
|
@@ -1017,18 +2215,94 @@ function ComposerBox() {
|
|
|
1017
2215
|
area.current?.focus();
|
|
1018
2216
|
},
|
|
1019
2217
|
onPaste: (event) => {
|
|
1020
|
-
|
|
1021
|
-
|
|
2218
|
+
const files = Array.from(event.clipboardData.files);
|
|
2219
|
+
if (files.length === 0) return;
|
|
2220
|
+
event.preventDefault();
|
|
2221
|
+
addFiles(files);
|
|
1022
2222
|
},
|
|
1023
2223
|
onDrop: (event) => {
|
|
1024
|
-
|
|
2224
|
+
const files = Array.from(event.dataTransfer.files);
|
|
2225
|
+
setDragOver(false);
|
|
2226
|
+
if (files.length === 0) return;
|
|
2227
|
+
event.preventDefault();
|
|
2228
|
+
addFiles(files);
|
|
2229
|
+
},
|
|
2230
|
+
onDragEnter: (event) => {
|
|
2231
|
+
if (!event.dataTransfer.types.includes("Files")) return;
|
|
1025
2232
|
event.preventDefault();
|
|
1026
|
-
|
|
2233
|
+
setDragOver(true);
|
|
1027
2234
|
},
|
|
1028
2235
|
onDragOver: (event) => {
|
|
1029
|
-
if (event.dataTransfer.types.includes("Files"))
|
|
2236
|
+
if (!event.dataTransfer.types.includes("Files")) return;
|
|
2237
|
+
event.preventDefault();
|
|
2238
|
+
setDragOver(true);
|
|
2239
|
+
},
|
|
2240
|
+
onDragLeave: (event) => {
|
|
2241
|
+
const next = event.relatedTarget;
|
|
2242
|
+
if (next instanceof Node && event.currentTarget.contains(next)) return;
|
|
2243
|
+
setDragOver(false);
|
|
1030
2244
|
},
|
|
2245
|
+
"data-drag": dragOver ? "1" : void 0,
|
|
1031
2246
|
children: [
|
|
2247
|
+
attachments.length === 0 ? null : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "composer-attachments", "aria-label": "待发送的附件", children: attachments.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2248
|
+
"div",
|
|
2249
|
+
{
|
|
2250
|
+
className: "attach-item",
|
|
2251
|
+
"data-kind": item.kind,
|
|
2252
|
+
"data-uploading": item.uploading !== null ? "1" : void 0,
|
|
2253
|
+
children: [
|
|
2254
|
+
item.kind === "file" ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "attach-file", children: [
|
|
2255
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconPackage, { size: 14 }),
|
|
2256
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "attach-name", title: item.name, children: item.name }),
|
|
2257
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "attach-bytes", children: uiPrimitives.formatBytes(item.bytes) })
|
|
2258
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2259
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "attach-thumb", children: item.kind === "image" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2260
|
+
"button",
|
|
2261
|
+
{
|
|
2262
|
+
type: "button",
|
|
2263
|
+
className: "attach-zoom",
|
|
2264
|
+
"data-tip": "点开看大图",
|
|
2265
|
+
"aria-label": `预览 ${item.name}`,
|
|
2266
|
+
onClick: () => {
|
|
2267
|
+
setZoom({ src: item.previewUrl, alt: item.name });
|
|
2268
|
+
},
|
|
2269
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: item.previewUrl, alt: item.name })
|
|
2270
|
+
}
|
|
2271
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
2272
|
+
"video",
|
|
2273
|
+
{
|
|
2274
|
+
muted: true,
|
|
2275
|
+
playsInline: true,
|
|
2276
|
+
preload: "metadata",
|
|
2277
|
+
src: item.previewUrl,
|
|
2278
|
+
"aria-label": item.name
|
|
2279
|
+
}
|
|
2280
|
+
) }),
|
|
2281
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "attach-name", title: item.name, children: item.name }),
|
|
2282
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "attach-bytes", children: uiPrimitives.formatBytes(item.bytes) }),
|
|
2283
|
+
item.frames.length === 0 ? null : /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "attach-hint", children: [
|
|
2284
|
+
item.frames.length,
|
|
2285
|
+
" 帧"
|
|
2286
|
+
] })
|
|
2287
|
+
] }),
|
|
2288
|
+
item.uploading === null ? null : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "attach-progress", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("span", { style: { width: `${String(Math.round(item.uploading * 100))}%` } }) }),
|
|
2289
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2290
|
+
"button",
|
|
2291
|
+
{
|
|
2292
|
+
type: "button",
|
|
2293
|
+
className: "attach-remove",
|
|
2294
|
+
"aria-label": `移除 ${item.name}`,
|
|
2295
|
+
title: `移除 ${item.name}`,
|
|
2296
|
+
onClick: () => {
|
|
2297
|
+
removeAttachment(item.id);
|
|
2298
|
+
},
|
|
2299
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconClose, { size: 12 })
|
|
2300
|
+
}
|
|
2301
|
+
)
|
|
2302
|
+
]
|
|
2303
|
+
},
|
|
2304
|
+
item.id
|
|
2305
|
+
)) }),
|
|
1032
2306
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1033
2307
|
"textarea",
|
|
1034
2308
|
{
|
|
@@ -1045,33 +2319,35 @@ function ComposerBox() {
|
|
|
1045
2319
|
}
|
|
1046
2320
|
),
|
|
1047
2321
|
command.open ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "slash-pop", role: "listbox", "aria-label": "命令候选", children: [
|
|
1048
|
-
command.loading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "slash-item", "data-loading": "1", children: "正在读取命令清单…" }) : command.rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "slash-item", "data-empty": "1", children: "没有匹配的命令" }) :
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
2322
|
+
command.loading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "slash-item", "data-loading": "1", children: "正在读取命令清单…" }) : command.rows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "slash-item", "data-empty": "1", children: "没有匹配的命令" }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2323
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "slash-section", role: "presentation", children: "指令" }),
|
|
2324
|
+
command.rows.map((row, index) => {
|
|
2325
|
+
const off = blockedNow(row, working);
|
|
2326
|
+
const Glyph = commandGlyph(row.name);
|
|
2327
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2328
|
+
"button",
|
|
2329
|
+
{
|
|
2330
|
+
type: "button",
|
|
2331
|
+
role: "option",
|
|
2332
|
+
"aria-selected": index === command.at,
|
|
2333
|
+
className: `slash-item${index === command.at ? " on" : ""}${off ? " off" : ""}`,
|
|
2334
|
+
title: row.description,
|
|
2335
|
+
onMouseDown: (event) => {
|
|
2336
|
+
event.preventDefault();
|
|
2337
|
+
command.pick();
|
|
2338
|
+
},
|
|
2339
|
+
children: [
|
|
2340
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "slash-icon", "aria-hidden": "true", children: Glyph === null ? null : /* @__PURE__ */ jsxRuntime.jsx(Glyph, { size: 14 }) }),
|
|
2341
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "slash-label", children: row.label ?? `/${row.name}` }),
|
|
2342
|
+
row.label === void 0 ? null : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "slash-name", children: row.name }),
|
|
2343
|
+
off ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "slash-flag", children: "回合中不可用" }) : null,
|
|
2344
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "slash-desc", children: row.description })
|
|
2345
|
+
]
|
|
1061
2346
|
},
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
] }),
|
|
1067
|
-
row.args === "" ? null : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "slash-args", children: row.args }),
|
|
1068
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "slash-desc", children: row.description }),
|
|
1069
|
-
off ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "slash-flag", children: "回合中不可用" }) : null
|
|
1070
|
-
]
|
|
1071
|
-
},
|
|
1072
|
-
row.name
|
|
1073
|
-
);
|
|
1074
|
-
}),
|
|
2347
|
+
row.name
|
|
2348
|
+
);
|
|
2349
|
+
})
|
|
2350
|
+
] }),
|
|
1075
2351
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "slash-hint", children: "↑↓ 选 · Tab 补全 · Enter 执行 · Esc 关闭" })
|
|
1076
2352
|
] }) : null,
|
|
1077
2353
|
mention.open ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mention-pop", role: "listbox", "aria-label": "文件提及候选", children: [
|
|
@@ -1093,7 +2369,7 @@ function ComposerBox() {
|
|
|
1093
2369
|
)),
|
|
1094
2370
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mention-hint", children: "↑↓ 选 · Tab/Enter 补全 · Esc 关闭" })
|
|
1095
2371
|
] }) : null,
|
|
1096
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "composer-bar", ref: barRef, children: [
|
|
2372
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "composer-bar", ref: controls.barRef, children: [
|
|
1097
2373
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bar-left", children: [
|
|
1098
2374
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1099
2375
|
"button",
|
|
@@ -1122,16 +2398,16 @@ function ComposerBox() {
|
|
|
1122
2398
|
"data-tip": permOption?.description ?? "当前三项旋钮的组合不匹配任何预设;在设置里逐格改出来的状态",
|
|
1123
2399
|
"aria-haspopup": "menu",
|
|
1124
2400
|
"aria-expanded": permOpen,
|
|
2401
|
+
"aria-label": `权限预设:${permOption?.label ?? "自定义"}`,
|
|
1125
2402
|
onClick: () => {
|
|
1126
2403
|
setPermOpen((open) => !open);
|
|
1127
2404
|
setPresetOpen(false);
|
|
1128
|
-
|
|
1129
|
-
setEffortOpen(false);
|
|
2405
|
+
controls.close();
|
|
1130
2406
|
setBranchOpen(false);
|
|
1131
2407
|
},
|
|
1132
2408
|
children: [
|
|
1133
2409
|
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconShield, { size: 13 }),
|
|
1134
|
-
permOption?.label ?? "自定义",
|
|
2410
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "chip-label", children: permOption?.label ?? "自定义" }),
|
|
1135
2411
|
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronDown, { size: 12 })
|
|
1136
2412
|
]
|
|
1137
2413
|
}
|
|
@@ -1182,16 +2458,16 @@ function ComposerBox() {
|
|
|
1182
2458
|
"data-tip": presetOption?.problem ?? presetOption?.description ?? "模式:模型是谁、手上有什么、被叮嘱了什么",
|
|
1183
2459
|
"aria-haspopup": "menu",
|
|
1184
2460
|
"aria-expanded": presetOpen,
|
|
2461
|
+
"aria-label": `模式:${presetOption?.label ?? preset.current}`,
|
|
1185
2462
|
onClick: () => {
|
|
1186
2463
|
setPresetOpen((open) => !open);
|
|
1187
2464
|
setPermOpen(false);
|
|
1188
|
-
|
|
1189
|
-
setEffortOpen(false);
|
|
2465
|
+
controls.close();
|
|
1190
2466
|
setBranchOpen(false);
|
|
1191
2467
|
},
|
|
1192
2468
|
children: [
|
|
1193
2469
|
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconLayers, { size: 13 }),
|
|
1194
|
-
presetOption?.label ?? preset.current,
|
|
2470
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "chip-label", children: presetOption?.label ?? preset.current }),
|
|
1195
2471
|
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronDown, { size: 12 })
|
|
1196
2472
|
]
|
|
1197
2473
|
}
|
|
@@ -1207,10 +2483,7 @@ function ComposerBox() {
|
|
|
1207
2483
|
}
|
|
1208
2484
|
),
|
|
1209
2485
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "model-pop preset-pop", role: "menu", "aria-label": "模式", children: [
|
|
1210
|
-
/* @__PURE__ */ jsxRuntime.
|
|
1211
|
-
"模式",
|
|
1212
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "pop-note", children: "新建/编辑:设置 → 模式" })
|
|
1213
|
-
] }),
|
|
2486
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "pop-label", children: "模式" }),
|
|
1214
2487
|
preset.options.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pop-item", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: "清单没取到" }) }) : preset.options.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1215
2488
|
"button",
|
|
1216
2489
|
{
|
|
@@ -1239,226 +2512,7 @@ function ComposerBox() {
|
|
|
1239
2512
|
] })
|
|
1240
2513
|
] }),
|
|
1241
2514
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bar-right", children: [
|
|
1242
|
-
|
|
1243
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1244
|
-
"button",
|
|
1245
|
-
{
|
|
1246
|
-
type: "button",
|
|
1247
|
-
ref: modelChipRef,
|
|
1248
|
-
className: `model-btn composer-model-chip${modelOpen ? " open" : ""}`,
|
|
1249
|
-
title: `模型:${chip.full}(点开换)`,
|
|
1250
|
-
"aria-haspopup": "menu",
|
|
1251
|
-
"aria-expanded": modelOpen,
|
|
1252
|
-
"aria-label": `当前模型 ${chip.full}`,
|
|
1253
|
-
"data-composer-model": current.entry?.value ?? chip.full,
|
|
1254
|
-
onClick: () => {
|
|
1255
|
-
setModelOpen((open) => !open);
|
|
1256
|
-
setHoverProvider(null);
|
|
1257
|
-
setFlyout(null);
|
|
1258
|
-
setEffortOpen(false);
|
|
1259
|
-
setPermOpen(false);
|
|
1260
|
-
setPresetOpen(false);
|
|
1261
|
-
setBranchOpen(false);
|
|
1262
|
-
},
|
|
1263
|
-
children: [
|
|
1264
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconPackage, { size: 13 }),
|
|
1265
|
-
chip.prefix === "" || dropPrefix ? null : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "composer-model-provider", children: chip.prefix }),
|
|
1266
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "model-name", children: chip.name }),
|
|
1267
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronDown, { size: 12 })
|
|
1268
|
-
]
|
|
1269
|
-
}
|
|
1270
|
-
),
|
|
1271
|
-
modelOpen ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1272
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1273
|
-
"div",
|
|
1274
|
-
{
|
|
1275
|
-
className: "pop-mask",
|
|
1276
|
-
onClick: () => {
|
|
1277
|
-
setModelOpen(false);
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
),
|
|
1281
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1282
|
-
"div",
|
|
1283
|
-
{
|
|
1284
|
-
className: `model-pop model-picker${twoLevel ? "" : " flat"}`,
|
|
1285
|
-
role: "menu",
|
|
1286
|
-
"aria-label": "选择模型",
|
|
1287
|
-
ref: modelPanelRef,
|
|
1288
|
-
"data-flyout-side": flyoutShown ? flyoutSide : void 0,
|
|
1289
|
-
style: panelShift === 0 ? void 0 : { transform: `translateX(${String(panelShift)}px)` },
|
|
1290
|
-
onMouseLeave: () => {
|
|
1291
|
-
setHoverProvider(null);
|
|
1292
|
-
setFlyout(null);
|
|
1293
|
-
},
|
|
1294
|
-
children: [
|
|
1295
|
-
current.entry === void 0 && model !== "" ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pop-item model-unknown", "data-model-unknown": "true", children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "name", children: [
|
|
1296
|
-
"当前:",
|
|
1297
|
-
model,
|
|
1298
|
-
" —— 清单里没有这个模型"
|
|
1299
|
-
] }) }) : null,
|
|
1300
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "model-picker-body", children: twoLevel ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1301
|
-
"div",
|
|
1302
|
-
{
|
|
1303
|
-
className: "model-providers",
|
|
1304
|
-
"data-model-providers": "",
|
|
1305
|
-
onScroll: () => {
|
|
1306
|
-
if (hoverProvider === null) return;
|
|
1307
|
-
const row = modelPanelRef.current?.querySelector(
|
|
1308
|
-
`[data-model-provider="${CSS.escape(hoverProvider)}"]`
|
|
1309
|
-
) ?? null;
|
|
1310
|
-
openFlyout(hoverProvider, row);
|
|
1311
|
-
},
|
|
1312
|
-
children: groups.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pop-item", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: "清单没取到" }) }) : groups.map((group) => {
|
|
1313
|
-
const owns = current.group?.provider === group.provider;
|
|
1314
|
-
const hint = providerHint(group, current);
|
|
1315
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1316
|
-
"button",
|
|
1317
|
-
{
|
|
1318
|
-
type: "button",
|
|
1319
|
-
role: "menuitem",
|
|
1320
|
-
"aria-current": owns,
|
|
1321
|
-
className: `pop-item provider-row${group.provider === hoverProvider ? " on" : ""}`,
|
|
1322
|
-
"data-model-provider": group.provider,
|
|
1323
|
-
"data-provider-current": owns ? "true" : void 0,
|
|
1324
|
-
title: hint === "" ? `${group.displayName} · ${String(group.models.length)} 个模型` : `${group.displayName} · 当前 ${hint}`,
|
|
1325
|
-
onMouseEnter: (event) => {
|
|
1326
|
-
openFlyout(group.provider, event.currentTarget);
|
|
1327
|
-
},
|
|
1328
|
-
onFocus: (event) => {
|
|
1329
|
-
openFlyout(group.provider, event.currentTarget);
|
|
1330
|
-
},
|
|
1331
|
-
onClick: (event) => {
|
|
1332
|
-
openFlyout(group.provider, event.currentTarget);
|
|
1333
|
-
},
|
|
1334
|
-
children: [
|
|
1335
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: group.displayName }),
|
|
1336
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "model-picker-check", children: owns ? /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconCheck, { size: 13, className: "check" }) : null }),
|
|
1337
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronRight, { size: 12, className: "provider-arrow" })
|
|
1338
|
-
]
|
|
1339
|
-
},
|
|
1340
|
-
group.provider
|
|
1341
|
-
);
|
|
1342
|
-
})
|
|
1343
|
-
}
|
|
1344
|
-
) : modelRowList(visibleModels) }),
|
|
1345
|
-
flyoutShown ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1346
|
-
"div",
|
|
1347
|
-
{
|
|
1348
|
-
className: `model-flyout${flyoutSide === "overlay" ? " model-flyout-inline" : ""}`,
|
|
1349
|
-
"data-model-flyout": "",
|
|
1350
|
-
"data-side": flyoutSide,
|
|
1351
|
-
style: flyoutSide === "overlay" ? void 0 : {
|
|
1352
|
-
"--flyout-top": `${String(flyout.top)}px`,
|
|
1353
|
-
"--flyout-max": `${String(flyout.maxHeight)}px`,
|
|
1354
|
-
"--flyout-w": `${String(FLYOUT_WIDTH)}px`
|
|
1355
|
-
},
|
|
1356
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1357
|
-
"div",
|
|
1358
|
-
{
|
|
1359
|
-
className: "model-flyout-card",
|
|
1360
|
-
role: "menu",
|
|
1361
|
-
"aria-label": `${hoveredGroup.displayName} 的模型`,
|
|
1362
|
-
ref: flyoutCardRef,
|
|
1363
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "model-picker-rows", "data-model-rows": "", ref: modelRows, children: modelRowList(visibleModels) })
|
|
1364
|
-
}
|
|
1365
|
-
)
|
|
1366
|
-
}
|
|
1367
|
-
) : null,
|
|
1368
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1369
|
-
"button",
|
|
1370
|
-
{
|
|
1371
|
-
type: "button",
|
|
1372
|
-
className: "pop-item model-manage",
|
|
1373
|
-
"data-model-manage": "",
|
|
1374
|
-
onClick: () => {
|
|
1375
|
-
setModelOpen(false);
|
|
1376
|
-
openModelsSettings();
|
|
1377
|
-
},
|
|
1378
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: "管理模型" })
|
|
1379
|
-
}
|
|
1380
|
-
)
|
|
1381
|
-
]
|
|
1382
|
-
}
|
|
1383
|
-
)
|
|
1384
|
-
] }) : null
|
|
1385
|
-
] }),
|
|
1386
|
-
switchEffort ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "model-anchor model-anchor-sheet", children: [
|
|
1387
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1388
|
-
"button",
|
|
1389
|
-
{
|
|
1390
|
-
type: "button",
|
|
1391
|
-
className: `model-btn composer-effort-chip${effortOpen ? " open" : ""}`,
|
|
1392
|
-
title: `思考强度:${effortText}(点开换档)`,
|
|
1393
|
-
"aria-haspopup": "menu",
|
|
1394
|
-
"aria-expanded": effortOpen,
|
|
1395
|
-
"aria-label": `当前思考强度 ${effortText}`,
|
|
1396
|
-
"data-composer-effort": effort,
|
|
1397
|
-
onClick: () => {
|
|
1398
|
-
setEffortOpen((open) => !open);
|
|
1399
|
-
setModelOpen(false);
|
|
1400
|
-
setPermOpen(false);
|
|
1401
|
-
setPresetOpen(false);
|
|
1402
|
-
setBranchOpen(false);
|
|
1403
|
-
},
|
|
1404
|
-
children: [
|
|
1405
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconBrain, { size: 13 }),
|
|
1406
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "model-name", children: effortText }),
|
|
1407
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronDown, { size: 12 })
|
|
1408
|
-
]
|
|
1409
|
-
}
|
|
1410
|
-
),
|
|
1411
|
-
effortOpen ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1412
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1413
|
-
"div",
|
|
1414
|
-
{
|
|
1415
|
-
className: "pop-mask",
|
|
1416
|
-
onClick: () => {
|
|
1417
|
-
setEffortOpen(false);
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
),
|
|
1421
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "model-pop effort-pop", role: "menu", "aria-label": "思考强度", children: [
|
|
1422
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pop-label", children: [
|
|
1423
|
-
"思考强度",
|
|
1424
|
-
current.entry === void 0 && model !== "" ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "pop-note", children: "模型不在清单里,列的是全部档位" }) : null
|
|
1425
|
-
] }),
|
|
1426
|
-
levelOptions.map((level) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1427
|
-
"button",
|
|
1428
|
-
{
|
|
1429
|
-
type: "button",
|
|
1430
|
-
role: "menuitemradio",
|
|
1431
|
-
"aria-checked": level === effort,
|
|
1432
|
-
className: `pop-item${level === effort ? " on" : ""}`,
|
|
1433
|
-
"data-effort-option": level,
|
|
1434
|
-
onClick: () => {
|
|
1435
|
-
setEffortOpen(false);
|
|
1436
|
-
setFault(null);
|
|
1437
|
-
void channel.invoke("setEffort", [level]).catch((reason) => {
|
|
1438
|
-
setFault(reason instanceof Error ? reason.message : String(reason));
|
|
1439
|
-
});
|
|
1440
|
-
},
|
|
1441
|
-
children: [
|
|
1442
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: effortLabel(level) }),
|
|
1443
|
-
level === effort ? /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconCheck, { size: 14, className: "check" }) : null
|
|
1444
|
-
]
|
|
1445
|
-
},
|
|
1446
|
-
level
|
|
1447
|
-
))
|
|
1448
|
-
] })
|
|
1449
|
-
] }) : null
|
|
1450
|
-
] }) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1451
|
-
"span",
|
|
1452
|
-
{
|
|
1453
|
-
className: "model-btn composer-effort-chip fixed",
|
|
1454
|
-
title: `思考强度:${effortText}(这个模型没有可切换的档位)`,
|
|
1455
|
-
"data-composer-effort": effort,
|
|
1456
|
-
children: [
|
|
1457
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui$1.IconBrain, { size: 13 }),
|
|
1458
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "model-name", children: effortText })
|
|
1459
|
-
]
|
|
1460
|
-
}
|
|
1461
|
-
),
|
|
2515
|
+
controls.node,
|
|
1462
2516
|
working ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1463
2517
|
"button",
|
|
1464
2518
|
{
|
|
@@ -1483,361 +2537,26 @@ function ComposerBox() {
|
|
|
1483
2537
|
},
|
|
1484
2538
|
children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconArrowUp, { size: 16 })
|
|
1485
2539
|
}
|
|
1486
|
-
) : null
|
|
1487
|
-
] })
|
|
1488
|
-
] })
|
|
1489
|
-
]
|
|
1490
|
-
}
|
|
1491
|
-
),
|
|
1492
|
-
fault === null ? null : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shell-composer-fault", children: fault })
|
|
1493
|
-
] })
|
|
1494
|
-
);
|
|
1495
|
-
}
|
|
1496
|
-
function previewOf(text) {
|
|
1497
|
-
const flat = text.replace(/\s+/g, " ").trim();
|
|
1498
|
-
const chars = Array.from(flat);
|
|
1499
|
-
return chars.length > PREVIEW_CHARS ? `${chars.slice(0, PREVIEW_CHARS).join("")}…` : flat;
|
|
1500
|
-
}
|
|
1501
|
-
function NoticeStrip() {
|
|
1502
|
-
const notices = ui$1.useHostSelector(readNotices, sameNotices);
|
|
1503
|
-
if (notices.length === 0) return null;
|
|
1504
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "notice-strip", "data-notice-strip": "", children: notices.map((item) => {
|
|
1505
|
-
const summary = summarizeNotice(item.text);
|
|
1506
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "notice-row", children: [
|
|
1507
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "notice-lead", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconSpark, { size: 13 }) }),
|
|
1508
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "notice-label", "data-tip": summary.detail === "" ? summary.label : summary.detail, children: summary.label }),
|
|
1509
|
-
summary.detail === "" ? null : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "notice-detail", children: summary.detail })
|
|
1510
|
-
] }, item.index);
|
|
1511
|
-
}) });
|
|
1512
|
-
}
|
|
1513
|
-
function QueueDock() {
|
|
1514
|
-
const channel = ui$1.useHostChannel();
|
|
1515
|
-
const items = ui$1.useHostSelector(readQueued, sameQueued);
|
|
1516
|
-
const turnState = ui$1.useHostSelector(readTurnState);
|
|
1517
|
-
const [collapsed, setCollapsed] = react.useState(true);
|
|
1518
|
-
const [editing, setEditing] = react.useState(null);
|
|
1519
|
-
const [busy, setBusy] = react.useState(false);
|
|
1520
|
-
const [fault, setFault] = react.useState(null);
|
|
1521
|
-
const count = items.length;
|
|
1522
|
-
react.useEffect(() => {
|
|
1523
|
-
if (count === 0 && !collapsed) setCollapsed(true);
|
|
1524
|
-
if (editing !== null && !items.some((item) => item.index === editing.index)) setEditing(null);
|
|
1525
|
-
}, [collapsed, editing, items, count]);
|
|
1526
|
-
if (count === 0) return null;
|
|
1527
|
-
const expanded = count === 1 || !collapsed || editing !== null;
|
|
1528
|
-
const running = turnState !== "idle";
|
|
1529
|
-
const act = async (work, failure) => {
|
|
1530
|
-
setBusy(true);
|
|
1531
|
-
setFault(null);
|
|
1532
|
-
try {
|
|
1533
|
-
return await work() ? "ok" : "rejected";
|
|
1534
|
-
} catch (error) {
|
|
1535
|
-
setFault(`${failure}:${error instanceof Error ? error.message : String(error)}`);
|
|
1536
|
-
return "failed";
|
|
1537
|
-
} finally {
|
|
1538
|
-
setBusy(false);
|
|
1539
|
-
}
|
|
1540
|
-
};
|
|
1541
|
-
const save = async (index) => {
|
|
1542
|
-
const value = editing?.text.trim() ?? "";
|
|
1543
|
-
if (value === "") return;
|
|
1544
|
-
const outcome = await act(() => channel.invoke("editQueued", [index, value]), "编辑失败");
|
|
1545
|
-
if (outcome === "ok") {
|
|
1546
|
-
setEditing(null);
|
|
1547
|
-
return;
|
|
1548
|
-
}
|
|
1549
|
-
if (outcome === "rejected") setFault("编辑失败:这条已经开始发送了");
|
|
1550
|
-
};
|
|
1551
|
-
const remove = async (index) => {
|
|
1552
|
-
const outcome = await act(() => channel.invoke("removeQueued", [index]), "撤掉失败");
|
|
1553
|
-
if (outcome === "rejected") setFault("撤掉失败:这条已经开始发送了");
|
|
1554
|
-
};
|
|
1555
|
-
const steer = async (index) => {
|
|
1556
|
-
const ahead = index;
|
|
1557
|
-
const detail = ahead > 0 ? `会打断模型当前的输出,让这条以及排在它前面的 ${String(ahead)} 条立刻作为新一轮发出去(模型已经说出的半截会保留)。` : "会打断模型当前的输出,让这条立刻作为新一轮发出去(模型已经说出的半截会保留)。";
|
|
1558
|
-
if (!window.confirm(`打断并插话?
|
|
1559
|
-
|
|
1560
|
-
${detail}`)) return;
|
|
1561
|
-
const outcome = await act(() => channel.invoke("steerQueued", [index]), "插话失败");
|
|
1562
|
-
if (outcome === "rejected") setFault("插话没赶上:这一轮刚结束,排队消息会自己发出去");
|
|
1563
|
-
};
|
|
1564
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "queue-dock", "data-queue-dock": "", children: [
|
|
1565
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "queue-panel", children: [
|
|
1566
|
-
count > 1 ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1567
|
-
"button",
|
|
1568
|
-
{
|
|
1569
|
-
type: "button",
|
|
1570
|
-
className: "queue-head",
|
|
1571
|
-
"aria-expanded": expanded,
|
|
1572
|
-
disabled: busy || editing !== null,
|
|
1573
|
-
"data-tip": expanded ? "收起排队消息" : "展开排队消息",
|
|
1574
|
-
onClick: () => {
|
|
1575
|
-
setCollapsed((current) => !current);
|
|
1576
|
-
},
|
|
1577
|
-
children: [
|
|
1578
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "queue-lead", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconQueue, { size: 13 }) }),
|
|
1579
|
-
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "queue-count", children: [
|
|
1580
|
-
count,
|
|
1581
|
-
" 条排队消息"
|
|
1582
|
-
] }),
|
|
1583
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "queue-note", children: "这一轮跑完自动发出" }),
|
|
1584
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "queue-caret", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronDown, { size: 13 }) })
|
|
2540
|
+
) : null
|
|
2541
|
+
] })
|
|
2542
|
+
] })
|
|
1585
2543
|
]
|
|
1586
2544
|
}
|
|
1587
|
-
)
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
onChange: (event) => {
|
|
1598
|
-
setEditing({ index: item.index, text: event.target.value });
|
|
1599
|
-
},
|
|
1600
|
-
onKeyDown: (event) => {
|
|
1601
|
-
if (event.key === "Enter" && !event.shiftKey) {
|
|
1602
|
-
event.preventDefault();
|
|
1603
|
-
void save(item.index);
|
|
1604
|
-
return;
|
|
1605
|
-
}
|
|
1606
|
-
if (event.key === "Escape") {
|
|
1607
|
-
event.preventDefault();
|
|
1608
|
-
setEditing(null);
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
),
|
|
1613
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1614
|
-
"button",
|
|
1615
|
-
{
|
|
1616
|
-
type: "button",
|
|
1617
|
-
className: "queue-act",
|
|
1618
|
-
"aria-label": "保存排队消息",
|
|
1619
|
-
"data-tip": "保存(回车)",
|
|
1620
|
-
disabled: busy || editing.text.trim() === "",
|
|
1621
|
-
onClick: () => void save(item.index),
|
|
1622
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconCheck, { size: 13 })
|
|
1623
|
-
}
|
|
1624
|
-
),
|
|
1625
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1626
|
-
"button",
|
|
1627
|
-
{
|
|
1628
|
-
type: "button",
|
|
1629
|
-
className: "queue-act",
|
|
1630
|
-
"aria-label": "取消编辑",
|
|
1631
|
-
"data-tip": "取消(Esc)",
|
|
1632
|
-
disabled: busy,
|
|
1633
|
-
onClick: () => {
|
|
1634
|
-
setEditing(null);
|
|
1635
|
-
},
|
|
1636
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconClose, { size: 13 })
|
|
2545
|
+
),
|
|
2546
|
+
inputHint === null ? null : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shell-composer-hint", children: inputHint }),
|
|
2547
|
+
fault === null ? null : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shell-composer-fault", children: fault }),
|
|
2548
|
+
zoom === null ? null : /* @__PURE__ */ jsxRuntime.jsx(
|
|
2549
|
+
uiPrimitives.ImageLightbox,
|
|
2550
|
+
{
|
|
2551
|
+
src: zoom.src,
|
|
2552
|
+
alt: zoom.alt,
|
|
2553
|
+
onClose: () => {
|
|
2554
|
+
setZoom(null);
|
|
1637
2555
|
}
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
item.images === void 0 || item.images.length === 0 ? null : /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "queue-badge", "data-tip": `随这条一起排队的 ${String(item.images.length)} 张图`, children: [
|
|
1643
|
-
"+",
|
|
1644
|
-
item.images.length,
|
|
1645
|
-
" 图"
|
|
1646
|
-
] }),
|
|
1647
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "queue-acts", children: [
|
|
1648
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1649
|
-
"button",
|
|
1650
|
-
{
|
|
1651
|
-
type: "button",
|
|
1652
|
-
className: "queue-act",
|
|
1653
|
-
"aria-label": "编辑排队消息",
|
|
1654
|
-
"data-tip": "改这条排队消息",
|
|
1655
|
-
disabled: busy,
|
|
1656
|
-
onClick: () => {
|
|
1657
|
-
setEditing({ index: item.index, text: item.text });
|
|
1658
|
-
},
|
|
1659
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconEdit, { size: 13 })
|
|
1660
|
-
}
|
|
1661
|
-
),
|
|
1662
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1663
|
-
"button",
|
|
1664
|
-
{
|
|
1665
|
-
type: "button",
|
|
1666
|
-
className: "queue-act",
|
|
1667
|
-
"aria-label": "撤回排队消息",
|
|
1668
|
-
"data-tip": "撤掉这条(还没发出去)",
|
|
1669
|
-
disabled: busy,
|
|
1670
|
-
onClick: () => void remove(item.index),
|
|
1671
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconTrash, { size: 13 })
|
|
1672
|
-
}
|
|
1673
|
-
),
|
|
1674
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1675
|
-
"button",
|
|
1676
|
-
{
|
|
1677
|
-
type: "button",
|
|
1678
|
-
className: "queue-act",
|
|
1679
|
-
"aria-label": "插话发送",
|
|
1680
|
-
"data-tip": running ? "打断当前输出,让这条立刻发出去(模型已说出的半截保留)" : "这一轮已经跑完,排队消息会自己发出去",
|
|
1681
|
-
disabled: busy || !running,
|
|
1682
|
-
onClick: () => void steer(item.index),
|
|
1683
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconArrowUp, { size: 13 })
|
|
1684
|
-
}
|
|
1685
|
-
)
|
|
1686
|
-
] })
|
|
1687
|
-
] }) }, item.index)) }) : null
|
|
1688
|
-
] }),
|
|
1689
|
-
fault === null ? null : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shell-composer-fault", children: fault })
|
|
1690
|
-
] });
|
|
1691
|
-
}
|
|
1692
|
-
function sameQueued(left, right) {
|
|
1693
|
-
if (left === right) return true;
|
|
1694
|
-
if (left.length !== right.length) return false;
|
|
1695
|
-
return left.every((item, index) => {
|
|
1696
|
-
const other = right[index];
|
|
1697
|
-
if (other === void 0) return false;
|
|
1698
|
-
return item.index === other.index && item.text === other.text && (item.images?.join("|") ?? "") === (other.images?.join("|") ?? "");
|
|
1699
|
-
});
|
|
1700
|
-
}
|
|
1701
|
-
function readTurnState(snapshot) {
|
|
1702
|
-
const status = snapshot?.["status"];
|
|
1703
|
-
if (typeof status !== "object" || status === null) return "idle";
|
|
1704
|
-
const value = status["turnState"];
|
|
1705
|
-
return typeof value === "string" ? value : "idle";
|
|
1706
|
-
}
|
|
1707
|
-
function readModel(snapshot) {
|
|
1708
|
-
const status = snapshot?.["status"];
|
|
1709
|
-
if (typeof status !== "object" || status === null) return "";
|
|
1710
|
-
const value = status["model"];
|
|
1711
|
-
return typeof value === "string" ? value : "";
|
|
1712
|
-
}
|
|
1713
|
-
function readProvider(snapshot) {
|
|
1714
|
-
const status = snapshot?.["status"];
|
|
1715
|
-
if (typeof status !== "object" || status === null) return "";
|
|
1716
|
-
const value = status["provider"];
|
|
1717
|
-
return typeof value === "string" ? value : "";
|
|
1718
|
-
}
|
|
1719
|
-
function readEffort(snapshot) {
|
|
1720
|
-
const status = snapshot?.["status"];
|
|
1721
|
-
if (typeof status !== "object" || status === null) return "default";
|
|
1722
|
-
const value = status["effort"];
|
|
1723
|
-
return typeof value === "string" ? value : "default";
|
|
1724
|
-
}
|
|
1725
|
-
function readHasApproval(snapshot) {
|
|
1726
|
-
const surfaces = snapshot?.["surfaces"];
|
|
1727
|
-
if (typeof surfaces !== "object" || surfaces === null) return false;
|
|
1728
|
-
const pending = surfaces["pendingApproval"];
|
|
1729
|
-
return pending !== null && pending !== void 0;
|
|
1730
|
-
}
|
|
1731
|
-
function readSessionPath(snapshot) {
|
|
1732
|
-
const status = snapshot?.["status"];
|
|
1733
|
-
if (typeof status !== "object" || status === null) return "";
|
|
1734
|
-
const path = status["sessionPath"];
|
|
1735
|
-
return typeof path === "string" ? path : "";
|
|
1736
|
-
}
|
|
1737
|
-
function readSessionId(snapshot) {
|
|
1738
|
-
const status = snapshot?.["status"];
|
|
1739
|
-
if (typeof status !== "object" || status === null) return "";
|
|
1740
|
-
const value = status["sessionId"];
|
|
1741
|
-
return typeof value === "string" ? value : "";
|
|
1742
|
-
}
|
|
1743
|
-
function readDraftCwd(snapshot) {
|
|
1744
|
-
const status = snapshot?.["status"];
|
|
1745
|
-
if (typeof status !== "object" || status === null) return "";
|
|
1746
|
-
const value = status["cwd"];
|
|
1747
|
-
return typeof value === "string" ? value : "";
|
|
1748
|
-
}
|
|
1749
|
-
function readSessionUnsaved(snapshot) {
|
|
1750
|
-
const status = snapshot?.["status"];
|
|
1751
|
-
if (typeof status !== "object" || status === null) return false;
|
|
1752
|
-
return status["sessionUnsaved"] === true;
|
|
1753
|
-
}
|
|
1754
|
-
function readPermissionPresets(snapshot) {
|
|
1755
|
-
const surfaces = snapshot?.["surfaces"];
|
|
1756
|
-
if (typeof surfaces !== "object" || surfaces === null) return EMPTY_PERMISSION_PRESETS;
|
|
1757
|
-
const presets = surfaces["permissionPresets"];
|
|
1758
|
-
if (typeof presets !== "object" || presets === null) return EMPTY_PERMISSION_PRESETS;
|
|
1759
|
-
const record = presets;
|
|
1760
|
-
const current = record["current"];
|
|
1761
|
-
const options = record["options"];
|
|
1762
|
-
if (typeof current !== "string" || !Array.isArray(options)) return EMPTY_PERMISSION_PRESETS;
|
|
1763
|
-
return {
|
|
1764
|
-
current,
|
|
1765
|
-
defaultName: typeof record["defaultName"] === "string" ? record["defaultName"] : "",
|
|
1766
|
-
options
|
|
1767
|
-
};
|
|
1768
|
-
}
|
|
1769
|
-
function samePermissionPresets(left, right) {
|
|
1770
|
-
if (left === right) return true;
|
|
1771
|
-
if (left.current !== right.current || left.defaultName !== right.defaultName) return false;
|
|
1772
|
-
if (left.options.length !== right.options.length) return false;
|
|
1773
|
-
return left.options.every((item, index) => {
|
|
1774
|
-
const other = right.options[index];
|
|
1775
|
-
return other !== void 0 && item.name === other.name && item.label === other.label && item.description === other.description && item.builtin === other.builtin;
|
|
1776
|
-
});
|
|
1777
|
-
}
|
|
1778
|
-
function readPresetSurface(snapshot) {
|
|
1779
|
-
const surfaces = snapshot?.["surfaces"];
|
|
1780
|
-
if (typeof surfaces !== "object" || surfaces === null) return EMPTY_PRESET;
|
|
1781
|
-
const preset = surfaces["preset"];
|
|
1782
|
-
if (typeof preset !== "object" || preset === null) return EMPTY_PRESET;
|
|
1783
|
-
const record = preset;
|
|
1784
|
-
const current = record["current"];
|
|
1785
|
-
const options = record["options"];
|
|
1786
|
-
if (typeof current !== "string" || !Array.isArray(options)) return EMPTY_PRESET;
|
|
1787
|
-
return {
|
|
1788
|
-
current,
|
|
1789
|
-
defaultName: typeof record["defaultName"] === "string" ? record["defaultName"] : "",
|
|
1790
|
-
options,
|
|
1791
|
-
droppable: Array.isArray(record["droppable"]) ? record["droppable"] : []
|
|
1792
|
-
};
|
|
1793
|
-
}
|
|
1794
|
-
function samePresetSurface(left, right) {
|
|
1795
|
-
if (left === right) return true;
|
|
1796
|
-
if (left.current !== right.current || left.defaultName !== right.defaultName) return false;
|
|
1797
|
-
if (left.options.length !== right.options.length) return false;
|
|
1798
|
-
return left.options.every((item, index) => {
|
|
1799
|
-
const other = right.options[index];
|
|
1800
|
-
return other !== void 0 && item.name === other.name && item.label === other.label && item.description === other.description && item.problem === other.problem;
|
|
1801
|
-
});
|
|
1802
|
-
}
|
|
1803
|
-
function readInboxCount(snapshot) {
|
|
1804
|
-
const queued = snapshot?.["queued"];
|
|
1805
|
-
const notices = snapshot?.["notices"];
|
|
1806
|
-
return (Array.isArray(queued) ? queued.length : 0) + (Array.isArray(notices) ? notices.length : 0);
|
|
1807
|
-
}
|
|
1808
|
-
function readQueued(snapshot) {
|
|
1809
|
-
const value = snapshot?.["queued"];
|
|
1810
|
-
return Array.isArray(value) ? value : EMPTY_QUEUE;
|
|
1811
|
-
}
|
|
1812
|
-
const EMPTY_QUEUE = Object.freeze([]);
|
|
1813
|
-
function sameNotices(left, right) {
|
|
1814
|
-
if (left === right) return true;
|
|
1815
|
-
if (left.length !== right.length) return false;
|
|
1816
|
-
return left.every((item, index) => {
|
|
1817
|
-
const other = right[index];
|
|
1818
|
-
return other !== void 0 && item.index === other.index && item.text === other.text;
|
|
1819
|
-
});
|
|
1820
|
-
}
|
|
1821
|
-
function readNotices(snapshot) {
|
|
1822
|
-
const value = snapshot?.["notices"];
|
|
1823
|
-
return Array.isArray(value) ? value : EMPTY_NOTICES;
|
|
1824
|
-
}
|
|
1825
|
-
const EMPTY_NOTICES = Object.freeze([]);
|
|
1826
|
-
function readGit(snapshot) {
|
|
1827
|
-
const surfaces = snapshot?.["surfaces"];
|
|
1828
|
-
if (typeof surfaces !== "object" || surfaces === null) return EMPTY_GIT;
|
|
1829
|
-
const raw = surfaces["git"];
|
|
1830
|
-
if (typeof raw !== "object" || raw === null) return EMPTY_GIT;
|
|
1831
|
-
const record = raw;
|
|
1832
|
-
return {
|
|
1833
|
-
repo: record["repo"] === true,
|
|
1834
|
-
branch: typeof record["branch"] === "string" ? record["branch"] : "",
|
|
1835
|
-
detached: record["detached"] === true,
|
|
1836
|
-
dirtyFileCount: typeof record["dirtyFileCount"] === "number" ? record["dirtyFileCount"] : 0
|
|
1837
|
-
};
|
|
1838
|
-
}
|
|
1839
|
-
function sameGit(left, right) {
|
|
1840
|
-
return left.repo === right.repo && left.branch === right.branch && left.detached === right.detached && left.dirtyFileCount === right.dirtyFileCount;
|
|
2556
|
+
}
|
|
2557
|
+
)
|
|
2558
|
+
] })
|
|
2559
|
+
);
|
|
1841
2560
|
}
|
|
1842
2561
|
exports.default = ui;
|
|
1843
2562
|
};
|