@alumbwe/anvil 1.0.20 → 1.0.22
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/package.json +74 -70
- package/src/agents/bundled-agents.generated.ts +4 -4
- package/src/chat.tsx +1703 -1698
- package/src/cli-args.ts +134 -134
- package/src/components/status-bar.tsx +331 -313
- package/src/hooks/helpers/send-message.ts +663 -654
- package/src/hooks/use-send-message.ts +806 -773
- package/src/index.tsx +473 -473
- package/src/state/chat-store.ts +553 -544
- package/src/utils/create-run-config.ts +121 -121
- package/src/utils/format-compact-number.ts +37 -0
- package/vendor/@anvil/common/package.json +27 -0
- package/vendor/@anvil/common/src/__tests__/agent-validation.test.ts +846 -0
- package/vendor/@anvil/common/src/__tests__/anvil-model-availability.test.ts +101 -0
- package/vendor/@anvil/common/src/__tests__/anvil-models.test.ts +1408 -0
- package/vendor/@anvil/common/src/__tests__/anvil-public-data-use-copy.test.ts +258 -0
- package/vendor/@anvil/common/src/__tests__/anvil-referral-tiers.test.ts +48 -0
- package/vendor/@anvil/common/src/__tests__/anvil-spend-ceilings.test.ts +282 -0
- package/vendor/@anvil/common/src/__tests__/anvil-trust.test.ts +526 -0
- package/vendor/@anvil/common/src/__tests__/deepseek-direct.test.ts +68 -0
- package/vendor/@anvil/common/src/__tests__/disposable-email.test.ts +132 -0
- package/vendor/@anvil/common/src/__tests__/dynamic-agent-template-schema.test.ts +422 -0
- package/vendor/@anvil/common/src/__tests__/env-ci.test.ts +167 -0
- package/vendor/@anvil/common/src/__tests__/env-process.test.ts +145 -0
- package/vendor/@anvil/common/src/__tests__/foreign-client-shipped-agents.test.ts +234 -0
- package/vendor/@anvil/common/src/__tests__/foreign-client-signals.test.ts +379 -0
- package/vendor/@anvil/common/src/__tests__/free-agents.test.ts +807 -0
- package/vendor/@anvil/common/src/__tests__/gravity-capi.test.ts +154 -0
- package/vendor/@anvil/common/src/__tests__/handlesteps-parsing.test.ts +246 -0
- package/vendor/@anvil/common/src/__tests__/kimi-k3-god-only.test.ts +77 -0
- package/vendor/@anvil/common/src/__tests__/model-config.test.ts +89 -0
- package/vendor/@anvil/common/src/__tests__/project-file-tree.test.ts +298 -0
- package/vendor/@anvil/common/src/__tests__/provisioned-model-tiers.test.ts +116 -0
- package/vendor/@anvil/common/src/__tests__/reasoning-effort.test.ts +167 -0
- package/vendor/@anvil/common/src/__tests__/reddit-capi.test.ts +132 -0
- package/vendor/@anvil/common/src/__tests__/response-ad-positions.test.ts +72 -0
- package/vendor/@anvil/common/src/__tests__/user-state.test.ts +30 -0
- package/vendor/@anvil/common/src/actions.ts +215 -0
- package/vendor/@anvil/common/src/analytics-core.ts +69 -0
- package/vendor/@anvil/common/src/analytics.ts +93 -0
- package/vendor/@anvil/common/src/api-keys/constants.ts +26 -0
- package/vendor/@anvil/common/src/browser-actions.ts +413 -0
- package/vendor/@anvil/common/src/constants/__tests__/anvil-onboarding-gate.test.ts +63 -0
- package/vendor/@anvil/common/src/constants/__tests__/anvil-onboarding.test.ts +246 -0
- package/vendor/@anvil/common/src/constants/__tests__/cf-worker-signals.test.ts +106 -0
- package/vendor/@anvil/common/src/constants/agents.ts +99 -0
- package/vendor/@anvil/common/src/constants/analytics-events.ts +435 -0
- package/vendor/@anvil/common/src/constants/anthropic.ts +73 -0
- package/vendor/@anvil/common/src/constants/anvil-data-use.ts +81 -0
- package/vendor/@anvil/common/src/constants/anvil-errors.ts +7 -0
- package/vendor/@anvil/common/src/constants/anvil-gemini-thinker.ts +21 -0
- package/vendor/@anvil/common/src/constants/anvil-model-ids.ts +11 -0
- package/vendor/@anvil/common/src/constants/anvil-models.ts +2130 -0
- package/vendor/@anvil/common/src/constants/anvil-onboarding-gate.ts +55 -0
- package/vendor/@anvil/common/src/constants/anvil-onboarding.ts +307 -0
- package/vendor/@anvil/common/src/constants/anvil-referral-tiers.ts +87 -0
- package/vendor/@anvil/common/src/constants/anvil-signup-block.ts +68 -0
- package/vendor/@anvil/common/src/constants/anvil-spend-ceilings.ts +450 -0
- package/vendor/@anvil/common/src/constants/anvil-trust.ts +976 -0
- package/vendor/@anvil/common/src/constants/auth.ts +18 -0
- package/vendor/@anvil/common/src/constants/byok.ts +2 -0
- package/vendor/@anvil/common/src/constants/cf-worker-signals.ts +132 -0
- package/vendor/@anvil/common/src/constants/composio.ts +34 -0
- package/vendor/@anvil/common/src/constants/deepseek-direct.ts +55 -0
- package/vendor/@anvil/common/src/constants/feedback.ts +13 -0
- package/vendor/@anvil/common/src/constants/foreign-client-signals.ts +272 -0
- package/vendor/@anvil/common/src/constants/free-agents.ts +777 -0
- package/vendor/@anvil/common/src/constants/gemini.ts +15 -0
- package/vendor/@anvil/common/src/constants/grant-priorities.ts +13 -0
- package/vendor/@anvil/common/src/constants/hosts.ts +6 -0
- package/vendor/@anvil/common/src/constants/images.ts +51 -0
- package/vendor/@anvil/common/src/constants/index.ts +7 -0
- package/vendor/@anvil/common/src/constants/knowledge.ts +35 -0
- package/vendor/@anvil/common/src/constants/limits.ts +23 -0
- package/vendor/@anvil/common/src/constants/model-config.ts +277 -0
- package/vendor/@anvil/common/src/constants/openrouter-attribution.ts +8 -0
- package/vendor/@anvil/common/src/constants/paths.ts +69 -0
- package/vendor/@anvil/common/src/constants/provider-routes.ts +317 -0
- package/vendor/@anvil/common/src/constants/reasoning-effort.ts +79 -0
- package/vendor/@anvil/common/src/constants/skills.ts +60 -0
- package/vendor/@anvil/common/src/constants/subscription-plans.ts +49 -0
- package/vendor/@anvil/common/src/constants/ui.ts +25 -0
- package/vendor/@anvil/common/src/env-ci.ts +36 -0
- package/vendor/@anvil/common/src/env-process.ts +95 -0
- package/vendor/@anvil/common/src/env-schema.ts +95 -0
- package/vendor/@anvil/common/src/env.ts +24 -0
- package/vendor/@anvil/common/src/gravity-capi.ts +207 -0
- package/vendor/@anvil/common/src/mcp/client.ts +233 -0
- package/vendor/@anvil/common/src/old-constants.ts +10 -0
- package/vendor/@anvil/common/src/project-file-tree.ts +355 -0
- package/vendor/@anvil/common/src/reddit-capi.ts +254 -0
- package/vendor/@anvil/common/src/schemas/feedback.ts +52 -0
- package/vendor/@anvil/common/src/schemas/logs.ts +66 -0
- package/vendor/@anvil/common/src/templates/agent-validation.ts +392 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/LICENSE +202 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/README.md +294 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/examples/01-basic-diff-reviewer.ts +17 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/examples/02-intermediate-git-committer.ts +78 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/examples/03-advanced-file-explorer.ts +73 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/my-custom-agent.ts +40 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/package.json +6 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/skills/README.md +65 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/skills/example-skill/SKILL.md +29 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/types/agent-definition.ts +497 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/types/tools.ts +444 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/types/util-types.ts +178 -0
- package/vendor/@anvil/common/src/testing/TESTING_PATTERNS.md +351 -0
- package/vendor/@anvil/common/src/testing/anvil-offer-invariants.ts +169 -0
- package/vendor/@anvil/common/src/testing/errors.ts +33 -0
- package/vendor/@anvil/common/src/testing/fixtures/agent-runtime.ts +334 -0
- package/vendor/@anvil/common/src/testing/impl/agent-runtime.ts +6 -0
- package/vendor/@anvil/common/src/testing/index.ts +84 -0
- package/vendor/@anvil/common/src/testing/mock-modules.ts +53 -0
- package/vendor/@anvil/common/src/testing/mock-types.ts +123 -0
- package/vendor/@anvil/common/src/testing/mocks/analytics.ts +261 -0
- package/vendor/@anvil/common/src/testing/mocks/child-process.ts +93 -0
- package/vendor/@anvil/common/src/testing/mocks/crypto.ts +218 -0
- package/vendor/@anvil/common/src/testing/mocks/database.ts +337 -0
- package/vendor/@anvil/common/src/testing/mocks/fetch.ts +219 -0
- package/vendor/@anvil/common/src/testing/mocks/filesystem.ts +166 -0
- package/vendor/@anvil/common/src/testing/mocks/index.ts +101 -0
- package/vendor/@anvil/common/src/testing/mocks/logger.ts +135 -0
- package/vendor/@anvil/common/src/testing/mocks/stream.ts +313 -0
- package/vendor/@anvil/common/src/testing/mocks/timers.ts +132 -0
- package/vendor/@anvil/common/src/testing/mocks/tree-sitter.ts +127 -0
- package/vendor/@anvil/common/src/testing/setup.ts +282 -0
- package/vendor/@anvil/common/src/testing-env-ci.ts +15 -0
- package/vendor/@anvil/common/src/testing-env-process.ts +78 -0
- package/vendor/@anvil/common/src/tools/__tests__/compile-tool-definitions.test.ts +34 -0
- package/vendor/@anvil/common/src/tools/compile-tool-definitions.ts +157 -0
- package/vendor/@anvil/common/src/tools/constants.ts +117 -0
- package/vendor/@anvil/common/src/tools/list.ts +190 -0
- package/vendor/@anvil/common/src/tools/params/__tests__/coerce-to-array.test.ts +213 -0
- package/vendor/@anvil/common/src/tools/params/__tests__/read-docs.test.ts +47 -0
- package/vendor/@anvil/common/src/tools/params/__tests__/render-ui.test.ts +65 -0
- package/vendor/@anvil/common/src/tools/params/tool/__tests__/run-terminal-command-timeout.test.ts +49 -0
- package/vendor/@anvil/common/src/tools/params/tool/add-message.ts +39 -0
- package/vendor/@anvil/common/src/tools/params/tool/add-subgoal.ts +57 -0
- package/vendor/@anvil/common/src/tools/params/tool/apply-patch.ts +110 -0
- package/vendor/@anvil/common/src/tools/params/tool/ask-user.ts +181 -0
- package/vendor/@anvil/common/src/tools/params/tool/browser-logs.ts +85 -0
- package/vendor/@anvil/common/src/tools/params/tool/cloud-plan-ready.ts +94 -0
- package/vendor/@anvil/common/src/tools/params/tool/code-search.ts +159 -0
- package/vendor/@anvil/common/src/tools/params/tool/composio.ts +131 -0
- package/vendor/@anvil/common/src/tools/params/tool/create-plan.ts +80 -0
- package/vendor/@anvil/common/src/tools/params/tool/end-turn.ts +57 -0
- package/vendor/@anvil/common/src/tools/params/tool/find-files.ts +60 -0
- package/vendor/@anvil/common/src/tools/params/tool/glob.ts +80 -0
- package/vendor/@anvil/common/src/tools/params/tool/gravity-index.ts +93 -0
- package/vendor/@anvil/common/src/tools/params/tool/list-directory.ts +58 -0
- package/vendor/@anvil/common/src/tools/params/tool/lookup-agent-info.ts +37 -0
- package/vendor/@anvil/common/src/tools/params/tool/propose-str-replace.ts +103 -0
- package/vendor/@anvil/common/src/tools/params/tool/propose-write-file.ts +71 -0
- package/vendor/@anvil/common/src/tools/params/tool/read-docs.ts +90 -0
- package/vendor/@anvil/common/src/tools/params/tool/read-files.ts +109 -0
- package/vendor/@anvil/common/src/tools/params/tool/read-subtree.ts +79 -0
- package/vendor/@anvil/common/src/tools/params/tool/read-url.ts +81 -0
- package/vendor/@anvil/common/src/tools/params/tool/render-ui.ts +168 -0
- package/vendor/@anvil/common/src/tools/params/tool/run-file-change-hooks.ts +57 -0
- package/vendor/@anvil/common/src/tools/params/tool/run-terminal-command.ts +211 -0
- package/vendor/@anvil/common/src/tools/params/tool/screenshot.ts +97 -0
- package/vendor/@anvil/common/src/tools/params/tool/set-messages.ts +44 -0
- package/vendor/@anvil/common/src/tools/params/tool/set-output.ts +61 -0
- package/vendor/@anvil/common/src/tools/params/tool/skill.ts +59 -0
- package/vendor/@anvil/common/src/tools/params/tool/spawn-agent-inline.ts +56 -0
- package/vendor/@anvil/common/src/tools/params/tool/spawn-agents.ts +154 -0
- package/vendor/@anvil/common/src/tools/params/tool/str-replace.ts +107 -0
- package/vendor/@anvil/common/src/tools/params/tool/suggest-followups.ts +97 -0
- package/vendor/@anvil/common/src/tools/params/tool/task-completed.ts +61 -0
- package/vendor/@anvil/common/src/tools/params/tool/think-deeply.ts +56 -0
- package/vendor/@anvil/common/src/tools/params/tool/update-subgoal.ts +89 -0
- package/vendor/@anvil/common/src/tools/params/tool/vision-analyze.ts +82 -0
- package/vendor/@anvil/common/src/tools/params/tool/web-search.ts +73 -0
- package/vendor/@anvil/common/src/tools/params/tool/write-file.ts +71 -0
- package/vendor/@anvil/common/src/tools/params/tool/write-todos.ts +67 -0
- package/vendor/@anvil/common/src/tools/params/utils.ts +150 -0
- package/vendor/@anvil/common/src/tools/utils.ts +24 -0
- package/vendor/@anvil/common/src/types/__tests__/dynamic-agent-template.test.ts +20 -0
- package/vendor/@anvil/common/src/types/agent-template.ts +215 -0
- package/vendor/@anvil/common/src/types/anvil-session.ts +535 -0
- package/vendor/@anvil/common/src/types/anvil-streak.ts +6 -0
- package/vendor/@anvil/common/src/types/anvil-usage.ts +64 -0
- package/vendor/@anvil/common/src/types/api/agents/publish.ts +61 -0
- package/vendor/@anvil/common/src/types/bun-test.d.ts +5 -0
- package/vendor/@anvil/common/src/types/contracts/agent-runtime.ts +75 -0
- package/vendor/@anvil/common/src/types/contracts/analytics.ts +9 -0
- package/vendor/@anvil/common/src/types/contracts/bigquery.ts +55 -0
- package/vendor/@anvil/common/src/types/contracts/billing.ts +46 -0
- package/vendor/@anvil/common/src/types/contracts/client.ts +53 -0
- package/vendor/@anvil/common/src/types/contracts/database.ts +112 -0
- package/vendor/@anvil/common/src/types/contracts/env.ts +203 -0
- package/vendor/@anvil/common/src/types/contracts/llm.ts +191 -0
- package/vendor/@anvil/common/src/types/contracts/logger.ts +14 -0
- package/vendor/@anvil/common/src/types/contracts/logs.ts +34 -0
- package/vendor/@anvil/common/src/types/contracts/trace.ts +21 -0
- package/vendor/@anvil/common/src/types/dynamic-agent-template.ts +328 -0
- package/vendor/@anvil/common/src/types/filesystem.ts +10 -0
- package/vendor/@anvil/common/src/types/function-params.ts +33 -0
- package/vendor/@anvil/common/src/types/grant.ts +20 -0
- package/vendor/@anvil/common/src/types/gravity-index.ts +170 -0
- package/vendor/@anvil/common/src/types/json.ts +29 -0
- package/vendor/@anvil/common/src/types/mcp.ts +24 -0
- package/vendor/@anvil/common/src/types/messages/anvil-message.ts +58 -0
- package/vendor/@anvil/common/src/types/messages/content-part.ts +59 -0
- package/vendor/@anvil/common/src/types/messages/data-content.ts +14 -0
- package/vendor/@anvil/common/src/types/messages/provider-metadata.ts +13 -0
- package/vendor/@anvil/common/src/types/organization.ts +118 -0
- package/vendor/@anvil/common/src/types/print-mode.ts +121 -0
- package/vendor/@anvil/common/src/types/publisher.ts +67 -0
- package/vendor/@anvil/common/src/types/session-state.ts +149 -0
- package/vendor/@anvil/common/src/types/skill.ts +86 -0
- package/vendor/@anvil/common/src/types/source.ts +11 -0
- package/vendor/@anvil/common/src/types/spawn.ts +13 -0
- package/vendor/@anvil/common/src/types/subscription.ts +67 -0
- package/vendor/@anvil/common/src/types/usage.ts +16 -0
- package/vendor/@anvil/common/src/types/util.ts +3 -0
- package/vendor/@anvil/common/src/util/__tests__/ad-user-agent.test.ts +26 -0
- package/vendor/@anvil/common/src/util/__tests__/analytics-dispatcher.test.ts +122 -0
- package/vendor/@anvil/common/src/util/__tests__/analytics-log.test.ts +102 -0
- package/vendor/@anvil/common/src/util/__tests__/analytics-sampling.test.ts +143 -0
- package/vendor/@anvil/common/src/util/__tests__/anvil-streak.test.ts +202 -0
- package/vendor/@anvil/common/src/util/__tests__/anvil-usage-summary.test.ts +193 -0
- package/vendor/@anvil/common/src/util/__tests__/axiom-only-log.test.ts +140 -0
- package/vendor/@anvil/common/src/util/__tests__/client-user-agent.test.ts +148 -0
- package/vendor/@anvil/common/src/util/__tests__/engagement-tracker.test.ts +115 -0
- package/vendor/@anvil/common/src/util/__tests__/env-file-path.test.ts +57 -0
- package/vendor/@anvil/common/src/util/__tests__/error-abort.test.ts +774 -0
- package/vendor/@anvil/common/src/util/__tests__/error-api-details.test.ts +206 -0
- package/vendor/@anvil/common/src/util/__tests__/file-read-limits.test.ts +173 -0
- package/vendor/@anvil/common/src/util/__tests__/format-code-search.test.ts +60 -0
- package/vendor/@anvil/common/src/util/__tests__/log-mirror.test.ts +31 -0
- package/vendor/@anvil/common/src/util/__tests__/messages.test.ts +1252 -0
- package/vendor/@anvil/common/src/util/__tests__/partial-json-delta.test.ts +505 -0
- package/vendor/@anvil/common/src/util/__tests__/path.test.ts +22 -0
- package/vendor/@anvil/common/src/util/__tests__/project-ignore.test.ts +90 -0
- package/vendor/@anvil/common/src/util/__tests__/promise.test.ts +325 -0
- package/vendor/@anvil/common/src/util/__tests__/rate-limit.test.ts +28 -0
- package/vendor/@anvil/common/src/util/__tests__/reddit-anvil-retention.test.ts +130 -0
- package/vendor/@anvil/common/src/util/__tests__/saxy.test.ts +1008 -0
- package/vendor/@anvil/common/src/util/__tests__/split-data.test.ts +289 -0
- package/vendor/@anvil/common/src/util/__tests__/string.test.ts +239 -0
- package/vendor/@anvil/common/src/util/__tests__/thread-title.test.ts +70 -0
- package/vendor/@anvil/common/src/util/__tests__/tool-result-media-order.test.ts +108 -0
- package/vendor/@anvil/common/src/util/__tests__/ttft-histogram.test.ts +180 -0
- package/vendor/@anvil/common/src/util/__tests__/with-timeout.test.ts +24 -0
- package/vendor/@anvil/common/src/util/__tests__/zoned-time.test.ts +88 -0
- package/vendor/@anvil/common/src/util/ad-user-agent.ts +25 -0
- package/vendor/@anvil/common/src/util/agent-file-utils.ts +110 -0
- package/vendor/@anvil/common/src/util/agent-id-parsing.ts +136 -0
- package/vendor/@anvil/common/src/util/agent-name-normalization.ts +38 -0
- package/vendor/@anvil/common/src/util/agent-name-resolver.ts +86 -0
- package/vendor/@anvil/common/src/util/analytics-dispatcher.ts +82 -0
- package/vendor/@anvil/common/src/util/analytics-log.ts +78 -0
- package/vendor/@anvil/common/src/util/analytics-sampling.ts +255 -0
- package/vendor/@anvil/common/src/util/anvil-model-availability.ts +102 -0
- package/vendor/@anvil/common/src/util/anvil-privacy.ts +82 -0
- package/vendor/@anvil/common/src/util/anvil-streak-line.ts +103 -0
- package/vendor/@anvil/common/src/util/anvil-streak.ts +156 -0
- package/vendor/@anvil/common/src/util/anvil-usage-summary.ts +125 -0
- package/vendor/@anvil/common/src/util/array.ts +31 -0
- package/vendor/@anvil/common/src/util/axiom-only-log.ts +124 -0
- package/vendor/@anvil/common/src/util/cache-debug.ts +171 -0
- package/vendor/@anvil/common/src/util/client-user-agent.ts +114 -0
- package/vendor/@anvil/common/src/util/credentials.ts +26 -0
- package/vendor/@anvil/common/src/util/currency.ts +25 -0
- package/vendor/@anvil/common/src/util/dates.ts +81 -0
- package/vendor/@anvil/common/src/util/disposable-email.ts +277 -0
- package/vendor/@anvil/common/src/util/engagement-tracker.ts +129 -0
- package/vendor/@anvil/common/src/util/env-file-path.ts +40 -0
- package/vendor/@anvil/common/src/util/error.ts +562 -0
- package/vendor/@anvil/common/src/util/file-read-limits.ts +236 -0
- package/vendor/@anvil/common/src/util/file.ts +339 -0
- package/vendor/@anvil/common/src/util/format-code-search.ts +115 -0
- package/vendor/@anvil/common/src/util/lazy-response-ads.ts +92 -0
- package/vendor/@anvil/common/src/util/log-data.ts +57 -0
- package/vendor/@anvil/common/src/util/log-ingest.ts +58 -0
- package/vendor/@anvil/common/src/util/log-mirror.ts +34 -0
- package/vendor/@anvil/common/src/util/lru-cache.ts +67 -0
- package/vendor/@anvil/common/src/util/messages.ts +685 -0
- package/vendor/@anvil/common/src/util/min-heap.ts +87 -0
- package/vendor/@anvil/common/src/util/model-utils.ts +4 -0
- package/vendor/@anvil/common/src/util/object.ts +128 -0
- package/vendor/@anvil/common/src/util/partial-json-delta.ts +89 -0
- package/vendor/@anvil/common/src/util/path.ts +15 -0
- package/vendor/@anvil/common/src/util/project-ignore.ts +119 -0
- package/vendor/@anvil/common/src/util/promise.ts +73 -0
- package/vendor/@anvil/common/src/util/random.ts +15 -0
- package/vendor/@anvil/common/src/util/rate-limit.ts +56 -0
- package/vendor/@anvil/common/src/util/reddit-anvil-retention.ts +60 -0
- package/vendor/@anvil/common/src/util/reddit-capi-events.ts +36 -0
- package/vendor/@anvil/common/src/util/response-ad-positions.ts +54 -0
- package/vendor/@anvil/common/src/util/saxy.ts +741 -0
- package/vendor/@anvil/common/src/util/skills.test.ts +44 -0
- package/vendor/@anvil/common/src/util/skills.ts +36 -0
- package/vendor/@anvil/common/src/util/split-data.ts +259 -0
- package/vendor/@anvil/common/src/util/stop-sequence.ts +61 -0
- package/vendor/@anvil/common/src/util/string.ts +426 -0
- package/vendor/@anvil/common/src/util/system-info.ts +53 -0
- package/vendor/@anvil/common/src/util/thread-title.ts +46 -0
- package/vendor/@anvil/common/src/util/ttft-histogram.ts +73 -0
- package/vendor/@anvil/common/src/util/xml-parser.ts +27 -0
- package/vendor/@anvil/common/src/util/xml.ts +17 -0
- package/vendor/@anvil/common/src/util/zod-schema.ts +25 -0
- package/vendor/@anvil/common/src/util/zoned-time.ts +136 -0
- package/vendor/@anvil/common/src/utils/ask-user-bridge.ts +44 -0
- package/vendor/@anvil/sdk/dist/index.cjs +52297 -0
- package/vendor/@anvil/sdk/dist/index.cjs.map +440 -0
- package/vendor/@anvil/sdk/dist/index.d.ts +4277 -0
- package/vendor/@anvil/sdk/dist/index.mjs +52290 -0
- package/vendor/@anvil/sdk/dist/index.mjs.map +440 -0
- package/vendor/@anvil/sdk/dist/vendor/ai.cjs +30886 -0
- package/vendor/@anvil/sdk/dist/vendor/ripgrep/arm64-darwin/rg +0 -0
- package/vendor/@anvil/sdk/dist/vendor/ripgrep/arm64-linux/rg +0 -0
- package/vendor/@anvil/sdk/dist/vendor/ripgrep/x64-darwin/rg +0 -0
- package/vendor/@anvil/sdk/dist/vendor/ripgrep/x64-linux/rg +0 -0
- package/vendor/@anvil/sdk/dist/vendor/ripgrep/x64-win32/rg.exe +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-c-sharp.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-cpp.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-go.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-java.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-javascript.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-python.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-ruby.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-rust.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-tsx.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-typescript.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter.wasm +0 -0
- package/vendor/@anvil/sdk/package.json +21 -0
package/src/chat.tsx
CHANGED
|
@@ -1,1698 +1,1703 @@
|
|
|
1
|
-
import { AnalyticsEvent } from '@anvil/common/constants/analytics-events'
|
|
2
|
-
import type { FeedbackCategory } from '@anvil/common/constants/feedback'
|
|
3
|
-
import { isDirectDeepSeekMode } from '@anvil/common/constants/deepseek-direct'
|
|
4
|
-
import { setFreeModeCapacityDeferralListener } from '@anvil/sdk'
|
|
5
|
-
import { safeOpen } from './utils/open-url'
|
|
6
|
-
import {
|
|
7
|
-
useCallback,
|
|
8
|
-
useEffect,
|
|
9
|
-
useLayoutEffect,
|
|
10
|
-
useMemo,
|
|
11
|
-
useRef,
|
|
12
|
-
useState,
|
|
13
|
-
} from 'react'
|
|
14
|
-
import { useShallow } from 'zustand/react/shallow'
|
|
15
|
-
|
|
16
|
-
import { getAdsEnabled } from './commands/ads'
|
|
17
|
-
import { routeUserPrompt, addBashMessageToHistory } from './commands/router'
|
|
18
|
-
import { SingleAdBanner } from './components/ad-banner'
|
|
19
|
-
import { ChatInputBar } from './components/chat-input-bar'
|
|
20
|
-
import { ChatHeader } from './components/chat-header'
|
|
21
|
-
import { AnvilActiveSessionSummary } from './components/anvil-active-session-summary'
|
|
22
|
-
import { LoadPreviousButton } from './components/load-previous-button'
|
|
23
|
-
import { QueuePanel } from './components/queue-panel'
|
|
24
|
-
import { ReviewScreen } from './components/review-screen'
|
|
25
|
-
import { MessageWithAgents } from './components/message-with-agents'
|
|
26
|
-
import { areCreditsRestored } from './components/out-of-credits-banner'
|
|
27
|
-
import { PendingBashMessage } from './components/pending-bash-message'
|
|
28
|
-
import { SessionEndedBanner } from './components/session-ended-banner'
|
|
29
|
-
import { StatusBar } from './components/status-bar'
|
|
30
|
-
import {
|
|
31
|
-
SuggestedPrompts,
|
|
32
|
-
DEFAULT_SUGGESTED_PROMPTS,
|
|
33
|
-
type SuggestedPromptSelection,
|
|
34
|
-
} from './components/suggested-prompts'
|
|
35
|
-
import { TopBanner } from './components/top-banner'
|
|
36
|
-
import { useChatRuntime } from './contexts/chat-runtime-context'
|
|
37
|
-
import { getSlashCommandsWithSkills } from './data/slash-commands'
|
|
38
|
-
import { useAskUserBridge } from './hooks/use-ask-user-bridge'
|
|
39
|
-
import { useChatInput } from './hooks/use-chat-input'
|
|
40
|
-
import {
|
|
41
|
-
useChatKeyboard,
|
|
42
|
-
type ChatKeyboardHandlers,
|
|
43
|
-
} from './hooks/use-chat-keyboard'
|
|
44
|
-
import { useChatMessages } from './hooks/use-chat-messages'
|
|
45
|
-
import { useChatState } from './hooks/use-chat-state'
|
|
46
|
-
import { useChatStreaming } from './hooks/use-chat-streaming'
|
|
47
|
-
import { useChatUI } from './hooks/use-chat-ui'
|
|
48
|
-
import { useClipboard } from './hooks/use-clipboard'
|
|
49
|
-
import { useEvent } from './hooks/use-event'
|
|
50
|
-
import { useGravityAd } from './hooks/use-gravity-ad'
|
|
51
|
-
import { useInputHistory } from './hooks/use-input-history'
|
|
52
|
-
import { usePublishMutation } from './hooks/use-publish-mutation'
|
|
53
|
-
import { useSuggestionEngine } from './hooks/use-suggestion-engine'
|
|
54
|
-
import { useUsageMonitor } from './hooks/use-usage-monitor'
|
|
55
|
-
import { WEBSITE_URL } from './login/constants'
|
|
56
|
-
import { getProjectRoot } from './project-files'
|
|
57
|
-
import { useChatHistoryStore } from './state/chat-history-store'
|
|
58
|
-
import { useChatStore } from './state/chat-store'
|
|
59
|
-
import { useQueuePanelStore } from './state/queue-panel-store'
|
|
60
|
-
import { useReviewStore } from './state/review-store'
|
|
61
|
-
import { useFeedbackStore } from './state/feedback-store'
|
|
62
|
-
import { useMessageBlockStore } from './state/message-block-store'
|
|
63
|
-
import { usePublishStore } from './state/publish-store'
|
|
64
|
-
import { reportActivity } from './utils/activity-tracker'
|
|
65
|
-
import { stopActiveRun } from './utils/active-run'
|
|
66
|
-
import { trackEvent } from './utils/analytics'
|
|
67
|
-
import { showClipboardMessage } from './utils/clipboard'
|
|
68
|
-
import { readClipboardImage } from './utils/clipboard-image'
|
|
69
|
-
import { returnToAnvilLanding } from './hooks/use-anvil-session'
|
|
70
|
-
import { END_SESSION_MESSAGE, IS_ANVIL } from './utils/constants'
|
|
71
|
-
import { getSystemMessage } from './utils/message-history'
|
|
72
|
-
import { getInputModeConfig } from './utils/input-modes'
|
|
73
|
-
import {
|
|
74
|
-
hasSubmittedFirstPrompt,
|
|
75
|
-
markFirstPromptSubmitted,
|
|
76
|
-
} from './utils/settings'
|
|
77
|
-
|
|
78
|
-
import {
|
|
79
|
-
type ChatKeyboardState,
|
|
80
|
-
createDefaultChatKeyboardState,
|
|
81
|
-
} from './utils/keyboard-actions'
|
|
82
|
-
import { loadLocalAgents } from './utils/local-agent-registry'
|
|
83
|
-
import { logger } from './utils/logger'
|
|
84
|
-
import {
|
|
85
|
-
addClipboardPlaceholder,
|
|
86
|
-
addPendingFileFromPath,
|
|
87
|
-
addPendingImageFromFile,
|
|
88
|
-
validateAndAddImage,
|
|
89
|
-
} from './utils/pending-attachments'
|
|
90
|
-
import { getLoadedSkills } from './utils/skill-registry'
|
|
91
|
-
import {
|
|
92
|
-
getStatusIndicatorState,
|
|
93
|
-
type AuthStatus,
|
|
94
|
-
} from './utils/status-indicator-state'
|
|
95
|
-
import { createPasteHandler } from './utils/strings'
|
|
96
|
-
import { setTerminalTitle } from './utils/terminal-title'
|
|
97
|
-
import { computeInputLayoutMetrics } from './utils/text-layout'
|
|
98
|
-
|
|
99
|
-
import type { CommandResult } from './commands/command-registry'
|
|
100
|
-
import type { MultilineInputHandle } from './components/multiline-input'
|
|
101
|
-
import type { MatchedSlashCommand } from './hooks/use-suggestion-engine'
|
|
102
|
-
import type { AnvilSessionResponse } from './types/anvil-session'
|
|
103
|
-
import type { User } from './utils/auth'
|
|
104
|
-
import type { AgentMode } from './utils/constants'
|
|
105
|
-
import type { FileTreeNode } from '@anvil/common/util/file'
|
|
106
|
-
import type { BoxRenderable, ScrollBoxRenderable } from '@opentui/core'
|
|
107
|
-
import type { UseMutationResult } from '@tanstack/react-query'
|
|
108
|
-
import type { Dispatch, SetStateAction } from 'react'
|
|
109
|
-
|
|
110
|
-
export const Chat = ({
|
|
111
|
-
consumeInitialPrompt,
|
|
112
|
-
fileTree,
|
|
113
|
-
inputRef,
|
|
114
|
-
setIsAuthenticated,
|
|
115
|
-
setUser,
|
|
116
|
-
logoutMutation,
|
|
117
|
-
authStatus,
|
|
118
|
-
initialMode,
|
|
119
|
-
gitRoot,
|
|
120
|
-
onSwitchToGitRoot,
|
|
121
|
-
anvilSession,
|
|
122
|
-
}: {
|
|
123
|
-
consumeInitialPrompt: () => string | null
|
|
124
|
-
fileTree: FileTreeNode[]
|
|
125
|
-
inputRef: React.MutableRefObject<MultilineInputHandle | null>
|
|
126
|
-
setIsAuthenticated: Dispatch<SetStateAction<boolean | null>>
|
|
127
|
-
setUser: Dispatch<SetStateAction<User | null>>
|
|
128
|
-
logoutMutation: UseMutationResult<boolean, Error, void, unknown>
|
|
129
|
-
authStatus: AuthStatus
|
|
130
|
-
initialMode?: AgentMode
|
|
131
|
-
gitRoot?: string | null
|
|
132
|
-
onSwitchToGitRoot?: () => void
|
|
133
|
-
anvilSession: AnvilSessionResponse | null
|
|
134
|
-
}) => {
|
|
135
|
-
const [forceFileOnlyMentions, setForceFileOnlyMentions] = useState(false)
|
|
136
|
-
const headerRef = useRef<BoxRenderable | null>(null)
|
|
137
|
-
|
|
138
|
-
// First-time onboarding: show clickable starter prompts until the user
|
|
139
|
-
// submits their first prompt ever (persisted in settings). Anvil only.
|
|
140
|
-
const [showSuggestedPrompts, setShowSuggestedPrompts] = useState(
|
|
141
|
-
() => IS_ANVIL && !hasSubmittedFirstPrompt(),
|
|
142
|
-
)
|
|
143
|
-
|
|
144
|
-
// Subscribe to ask_user bridge to trigger form display
|
|
145
|
-
useAskUserBridge()
|
|
146
|
-
|
|
147
|
-
// Monitor usage data and auto-show banner when thresholds are crossed
|
|
148
|
-
useUsageMonitor()
|
|
149
|
-
|
|
150
|
-
// Get chat state from extracted hook
|
|
151
|
-
const {
|
|
152
|
-
inputValue,
|
|
153
|
-
cursorPosition,
|
|
154
|
-
lastEditDueToNav,
|
|
155
|
-
setInputValue,
|
|
156
|
-
inputFocused,
|
|
157
|
-
setInputFocused,
|
|
158
|
-
slashSelectedIndex,
|
|
159
|
-
setSlashSelectedIndex,
|
|
160
|
-
agentSelectedIndex,
|
|
161
|
-
setAgentSelectedIndex,
|
|
162
|
-
focusedAgentId,
|
|
163
|
-
setFocusedAgentId,
|
|
164
|
-
messages,
|
|
165
|
-
setMessages,
|
|
166
|
-
agentMode,
|
|
167
|
-
setAgentMode,
|
|
168
|
-
toggleAgentMode,
|
|
169
|
-
isRetrying,
|
|
170
|
-
isCapacityWait,
|
|
171
|
-
pendingBashMessages,
|
|
172
|
-
} = useChatState()
|
|
173
|
-
|
|
174
|
-
const { statusMessage } = useClipboard()
|
|
175
|
-
const {
|
|
176
|
-
isChainInProgressRef,
|
|
177
|
-
sendMessage,
|
|
178
|
-
clearMessages,
|
|
179
|
-
subscriptionData,
|
|
180
|
-
registerScrollToLatest,
|
|
181
|
-
queuedMessages,
|
|
182
|
-
editQueuedMessage,
|
|
183
|
-
removeQueuedMessage,
|
|
184
|
-
moveQueuedMessage,
|
|
185
|
-
} = useChatRuntime()
|
|
186
|
-
const hasSubscription = subscriptionData?.hasSubscription ?? false
|
|
187
|
-
|
|
188
|
-
const {
|
|
189
|
-
ads,
|
|
190
|
-
responseAds,
|
|
191
|
-
requestResponseAds,
|
|
192
|
-
recordClick,
|
|
193
|
-
recordImpression,
|
|
194
|
-
} = useGravityAd({
|
|
195
|
-
enabled: IS_ANVIL || !hasSubscription,
|
|
196
|
-
provider: 'gravity',
|
|
197
|
-
inline: true,
|
|
198
|
-
surface: 'cli_chat',
|
|
199
|
-
// Lazily fill a four-ad pool, then repeat it for later transcript slots.
|
|
200
|
-
inlinePlacementId: 'CLI-Chat-Inline',
|
|
201
|
-
// Keep the rotating above-input slot separate for reporting continuity.
|
|
202
|
-
slotPlacementId: 'Single-Ad-Unit-1',
|
|
203
|
-
})
|
|
204
|
-
const showInlineAds = IS_ANVIL || getAdsEnabled()
|
|
205
|
-
|
|
206
|
-
// Stable identities so the message-block callbacks (set once) always call
|
|
207
|
-
// the latest recorder from the hook.
|
|
208
|
-
const handleAdClick = useEvent(recordClick)
|
|
209
|
-
const handleAdImpression = useEvent(recordImpression)
|
|
210
|
-
const handleResponseAdsNeeded = useEvent(requestResponseAds)
|
|
211
|
-
|
|
212
|
-
// Set initial mode from CLI flag on mount
|
|
213
|
-
useEffect(() => {
|
|
214
|
-
if (initialMode) {
|
|
215
|
-
setAgentMode(initialMode)
|
|
216
|
-
}
|
|
217
|
-
}, [initialMode, setAgentMode])
|
|
218
|
-
|
|
219
|
-
// Use extracted chat messages hook for message tree and pagination
|
|
220
|
-
const {
|
|
221
|
-
messageTree,
|
|
222
|
-
visibleTopLevelMessages,
|
|
223
|
-
hiddenMessageCount,
|
|
224
|
-
handleCollapseToggle,
|
|
225
|
-
isUserCollapsing,
|
|
226
|
-
handleLoadPreviousMessages,
|
|
227
|
-
handleToggleAll,
|
|
228
|
-
} = useChatMessages({ messages, setMessages })
|
|
229
|
-
|
|
230
|
-
// Use extracted UI hook for scroll, terminal dimensions, and theme
|
|
231
|
-
const {
|
|
232
|
-
scrollRef,
|
|
233
|
-
scrollToLatest,
|
|
234
|
-
scrollUp,
|
|
235
|
-
scrollDown,
|
|
236
|
-
appliedScrollboxProps,
|
|
237
|
-
isAtBottom,
|
|
238
|
-
hasOverflow,
|
|
239
|
-
terminalWidth,
|
|
240
|
-
terminalHeight,
|
|
241
|
-
separatorWidth,
|
|
242
|
-
messageAvailableWidth,
|
|
243
|
-
isCompactHeight,
|
|
244
|
-
isNarrowWidth,
|
|
245
|
-
theme,
|
|
246
|
-
markdownPalette,
|
|
247
|
-
} = useChatUI({ messages, isUserCollapsing })
|
|
248
|
-
|
|
249
|
-
useEffect(
|
|
250
|
-
() => registerScrollToLatest(scrollToLatest),
|
|
251
|
-
[registerScrollToLatest, scrollToLatest],
|
|
252
|
-
)
|
|
253
|
-
|
|
254
|
-
// Surface server capacity deferrals (free-mode tier shedding under peak
|
|
255
|
-
// demand): the SDK's retry loop absorbs the 429s silently, so without this
|
|
256
|
-
// the user just sees a longer unexplained "thinking". The stream-chunk
|
|
257
|
-
// handlers clear the flag (via setIsRetrying(false)) as soon as real
|
|
258
|
-
// output resumes.
|
|
259
|
-
useEffect(() => {
|
|
260
|
-
setFreeModeCapacityDeferralListener(() => {
|
|
261
|
-
useChatStore.getState().noteCapacityDeferral()
|
|
262
|
-
})
|
|
263
|
-
return () => setFreeModeCapacityDeferralListener(null)
|
|
264
|
-
}, [])
|
|
265
|
-
|
|
266
|
-
const localAgents = useMemo(() => loadLocalAgents(agentMode), [agentMode])
|
|
267
|
-
const inputMode = useChatStore((state) => state.inputMode)
|
|
268
|
-
const setInputMode = useChatStore((state) => state.setInputMode)
|
|
269
|
-
const askUserState = useChatStore((state) => state.askUserState)
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
//
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
slashContext.active
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
const
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
!
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
)
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
useChatStore.
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
//
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
//
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
const
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
if (result
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
preSelectAgents
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
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
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
(
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
//
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
useLayoutEffect
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
!
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
!
|
|
1385
|
-
!
|
|
1386
|
-
!
|
|
1387
|
-
!
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
const
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
const
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
const
|
|
1465
|
-
IS_ANVIL && anvilSession?.status === '
|
|
1466
|
-
const
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
flexDirection: 'column',
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
<
|
|
1542
|
-
|
|
1543
|
-
{
|
|
1544
|
-
<
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
))
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
)
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1
|
+
import { AnalyticsEvent } from '@anvil/common/constants/analytics-events'
|
|
2
|
+
import type { FeedbackCategory } from '@anvil/common/constants/feedback'
|
|
3
|
+
import { isDirectDeepSeekMode } from '@anvil/common/constants/deepseek-direct'
|
|
4
|
+
import { setFreeModeCapacityDeferralListener } from '@anvil/sdk'
|
|
5
|
+
import { safeOpen } from './utils/open-url'
|
|
6
|
+
import {
|
|
7
|
+
useCallback,
|
|
8
|
+
useEffect,
|
|
9
|
+
useLayoutEffect,
|
|
10
|
+
useMemo,
|
|
11
|
+
useRef,
|
|
12
|
+
useState,
|
|
13
|
+
} from 'react'
|
|
14
|
+
import { useShallow } from 'zustand/react/shallow'
|
|
15
|
+
|
|
16
|
+
import { getAdsEnabled } from './commands/ads'
|
|
17
|
+
import { routeUserPrompt, addBashMessageToHistory } from './commands/router'
|
|
18
|
+
import { SingleAdBanner } from './components/ad-banner'
|
|
19
|
+
import { ChatInputBar } from './components/chat-input-bar'
|
|
20
|
+
import { ChatHeader } from './components/chat-header'
|
|
21
|
+
import { AnvilActiveSessionSummary } from './components/anvil-active-session-summary'
|
|
22
|
+
import { LoadPreviousButton } from './components/load-previous-button'
|
|
23
|
+
import { QueuePanel } from './components/queue-panel'
|
|
24
|
+
import { ReviewScreen } from './components/review-screen'
|
|
25
|
+
import { MessageWithAgents } from './components/message-with-agents'
|
|
26
|
+
import { areCreditsRestored } from './components/out-of-credits-banner'
|
|
27
|
+
import { PendingBashMessage } from './components/pending-bash-message'
|
|
28
|
+
import { SessionEndedBanner } from './components/session-ended-banner'
|
|
29
|
+
import { StatusBar } from './components/status-bar'
|
|
30
|
+
import {
|
|
31
|
+
SuggestedPrompts,
|
|
32
|
+
DEFAULT_SUGGESTED_PROMPTS,
|
|
33
|
+
type SuggestedPromptSelection,
|
|
34
|
+
} from './components/suggested-prompts'
|
|
35
|
+
import { TopBanner } from './components/top-banner'
|
|
36
|
+
import { useChatRuntime } from './contexts/chat-runtime-context'
|
|
37
|
+
import { getSlashCommandsWithSkills } from './data/slash-commands'
|
|
38
|
+
import { useAskUserBridge } from './hooks/use-ask-user-bridge'
|
|
39
|
+
import { useChatInput } from './hooks/use-chat-input'
|
|
40
|
+
import {
|
|
41
|
+
useChatKeyboard,
|
|
42
|
+
type ChatKeyboardHandlers,
|
|
43
|
+
} from './hooks/use-chat-keyboard'
|
|
44
|
+
import { useChatMessages } from './hooks/use-chat-messages'
|
|
45
|
+
import { useChatState } from './hooks/use-chat-state'
|
|
46
|
+
import { useChatStreaming } from './hooks/use-chat-streaming'
|
|
47
|
+
import { useChatUI } from './hooks/use-chat-ui'
|
|
48
|
+
import { useClipboard } from './hooks/use-clipboard'
|
|
49
|
+
import { useEvent } from './hooks/use-event'
|
|
50
|
+
import { useGravityAd } from './hooks/use-gravity-ad'
|
|
51
|
+
import { useInputHistory } from './hooks/use-input-history'
|
|
52
|
+
import { usePublishMutation } from './hooks/use-publish-mutation'
|
|
53
|
+
import { useSuggestionEngine } from './hooks/use-suggestion-engine'
|
|
54
|
+
import { useUsageMonitor } from './hooks/use-usage-monitor'
|
|
55
|
+
import { WEBSITE_URL } from './login/constants'
|
|
56
|
+
import { getProjectRoot } from './project-files'
|
|
57
|
+
import { useChatHistoryStore } from './state/chat-history-store'
|
|
58
|
+
import { useChatStore } from './state/chat-store'
|
|
59
|
+
import { useQueuePanelStore } from './state/queue-panel-store'
|
|
60
|
+
import { useReviewStore } from './state/review-store'
|
|
61
|
+
import { useFeedbackStore } from './state/feedback-store'
|
|
62
|
+
import { useMessageBlockStore } from './state/message-block-store'
|
|
63
|
+
import { usePublishStore } from './state/publish-store'
|
|
64
|
+
import { reportActivity } from './utils/activity-tracker'
|
|
65
|
+
import { stopActiveRun } from './utils/active-run'
|
|
66
|
+
import { trackEvent } from './utils/analytics'
|
|
67
|
+
import { showClipboardMessage } from './utils/clipboard'
|
|
68
|
+
import { readClipboardImage } from './utils/clipboard-image'
|
|
69
|
+
import { returnToAnvilLanding } from './hooks/use-anvil-session'
|
|
70
|
+
import { END_SESSION_MESSAGE, IS_ANVIL } from './utils/constants'
|
|
71
|
+
import { getSystemMessage } from './utils/message-history'
|
|
72
|
+
import { getInputModeConfig } from './utils/input-modes'
|
|
73
|
+
import {
|
|
74
|
+
hasSubmittedFirstPrompt,
|
|
75
|
+
markFirstPromptSubmitted,
|
|
76
|
+
} from './utils/settings'
|
|
77
|
+
|
|
78
|
+
import {
|
|
79
|
+
type ChatKeyboardState,
|
|
80
|
+
createDefaultChatKeyboardState,
|
|
81
|
+
} from './utils/keyboard-actions'
|
|
82
|
+
import { loadLocalAgents } from './utils/local-agent-registry'
|
|
83
|
+
import { logger } from './utils/logger'
|
|
84
|
+
import {
|
|
85
|
+
addClipboardPlaceholder,
|
|
86
|
+
addPendingFileFromPath,
|
|
87
|
+
addPendingImageFromFile,
|
|
88
|
+
validateAndAddImage,
|
|
89
|
+
} from './utils/pending-attachments'
|
|
90
|
+
import { getLoadedSkills } from './utils/skill-registry'
|
|
91
|
+
import {
|
|
92
|
+
getStatusIndicatorState,
|
|
93
|
+
type AuthStatus,
|
|
94
|
+
} from './utils/status-indicator-state'
|
|
95
|
+
import { createPasteHandler } from './utils/strings'
|
|
96
|
+
import { setTerminalTitle } from './utils/terminal-title'
|
|
97
|
+
import { computeInputLayoutMetrics } from './utils/text-layout'
|
|
98
|
+
|
|
99
|
+
import type { CommandResult } from './commands/command-registry'
|
|
100
|
+
import type { MultilineInputHandle } from './components/multiline-input'
|
|
101
|
+
import type { MatchedSlashCommand } from './hooks/use-suggestion-engine'
|
|
102
|
+
import type { AnvilSessionResponse } from './types/anvil-session'
|
|
103
|
+
import type { User } from './utils/auth'
|
|
104
|
+
import type { AgentMode } from './utils/constants'
|
|
105
|
+
import type { FileTreeNode } from '@anvil/common/util/file'
|
|
106
|
+
import type { BoxRenderable, ScrollBoxRenderable } from '@opentui/core'
|
|
107
|
+
import type { UseMutationResult } from '@tanstack/react-query'
|
|
108
|
+
import type { Dispatch, SetStateAction } from 'react'
|
|
109
|
+
|
|
110
|
+
export const Chat = ({
|
|
111
|
+
consumeInitialPrompt,
|
|
112
|
+
fileTree,
|
|
113
|
+
inputRef,
|
|
114
|
+
setIsAuthenticated,
|
|
115
|
+
setUser,
|
|
116
|
+
logoutMutation,
|
|
117
|
+
authStatus,
|
|
118
|
+
initialMode,
|
|
119
|
+
gitRoot,
|
|
120
|
+
onSwitchToGitRoot,
|
|
121
|
+
anvilSession,
|
|
122
|
+
}: {
|
|
123
|
+
consumeInitialPrompt: () => string | null
|
|
124
|
+
fileTree: FileTreeNode[]
|
|
125
|
+
inputRef: React.MutableRefObject<MultilineInputHandle | null>
|
|
126
|
+
setIsAuthenticated: Dispatch<SetStateAction<boolean | null>>
|
|
127
|
+
setUser: Dispatch<SetStateAction<User | null>>
|
|
128
|
+
logoutMutation: UseMutationResult<boolean, Error, void, unknown>
|
|
129
|
+
authStatus: AuthStatus
|
|
130
|
+
initialMode?: AgentMode
|
|
131
|
+
gitRoot?: string | null
|
|
132
|
+
onSwitchToGitRoot?: () => void
|
|
133
|
+
anvilSession: AnvilSessionResponse | null
|
|
134
|
+
}) => {
|
|
135
|
+
const [forceFileOnlyMentions, setForceFileOnlyMentions] = useState(false)
|
|
136
|
+
const headerRef = useRef<BoxRenderable | null>(null)
|
|
137
|
+
|
|
138
|
+
// First-time onboarding: show clickable starter prompts until the user
|
|
139
|
+
// submits their first prompt ever (persisted in settings). Anvil only.
|
|
140
|
+
const [showSuggestedPrompts, setShowSuggestedPrompts] = useState(
|
|
141
|
+
() => IS_ANVIL && !hasSubmittedFirstPrompt(),
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
// Subscribe to ask_user bridge to trigger form display
|
|
145
|
+
useAskUserBridge()
|
|
146
|
+
|
|
147
|
+
// Monitor usage data and auto-show banner when thresholds are crossed
|
|
148
|
+
useUsageMonitor()
|
|
149
|
+
|
|
150
|
+
// Get chat state from extracted hook
|
|
151
|
+
const {
|
|
152
|
+
inputValue,
|
|
153
|
+
cursorPosition,
|
|
154
|
+
lastEditDueToNav,
|
|
155
|
+
setInputValue,
|
|
156
|
+
inputFocused,
|
|
157
|
+
setInputFocused,
|
|
158
|
+
slashSelectedIndex,
|
|
159
|
+
setSlashSelectedIndex,
|
|
160
|
+
agentSelectedIndex,
|
|
161
|
+
setAgentSelectedIndex,
|
|
162
|
+
focusedAgentId,
|
|
163
|
+
setFocusedAgentId,
|
|
164
|
+
messages,
|
|
165
|
+
setMessages,
|
|
166
|
+
agentMode,
|
|
167
|
+
setAgentMode,
|
|
168
|
+
toggleAgentMode,
|
|
169
|
+
isRetrying,
|
|
170
|
+
isCapacityWait,
|
|
171
|
+
pendingBashMessages,
|
|
172
|
+
} = useChatState()
|
|
173
|
+
|
|
174
|
+
const { statusMessage } = useClipboard()
|
|
175
|
+
const {
|
|
176
|
+
isChainInProgressRef,
|
|
177
|
+
sendMessage,
|
|
178
|
+
clearMessages,
|
|
179
|
+
subscriptionData,
|
|
180
|
+
registerScrollToLatest,
|
|
181
|
+
queuedMessages,
|
|
182
|
+
editQueuedMessage,
|
|
183
|
+
removeQueuedMessage,
|
|
184
|
+
moveQueuedMessage,
|
|
185
|
+
} = useChatRuntime()
|
|
186
|
+
const hasSubscription = subscriptionData?.hasSubscription ?? false
|
|
187
|
+
|
|
188
|
+
const {
|
|
189
|
+
ads,
|
|
190
|
+
responseAds,
|
|
191
|
+
requestResponseAds,
|
|
192
|
+
recordClick,
|
|
193
|
+
recordImpression,
|
|
194
|
+
} = useGravityAd({
|
|
195
|
+
enabled: IS_ANVIL || !hasSubscription,
|
|
196
|
+
provider: 'gravity',
|
|
197
|
+
inline: true,
|
|
198
|
+
surface: 'cli_chat',
|
|
199
|
+
// Lazily fill a four-ad pool, then repeat it for later transcript slots.
|
|
200
|
+
inlinePlacementId: 'CLI-Chat-Inline',
|
|
201
|
+
// Keep the rotating above-input slot separate for reporting continuity.
|
|
202
|
+
slotPlacementId: 'Single-Ad-Unit-1',
|
|
203
|
+
})
|
|
204
|
+
const showInlineAds = IS_ANVIL || getAdsEnabled()
|
|
205
|
+
|
|
206
|
+
// Stable identities so the message-block callbacks (set once) always call
|
|
207
|
+
// the latest recorder from the hook.
|
|
208
|
+
const handleAdClick = useEvent(recordClick)
|
|
209
|
+
const handleAdImpression = useEvent(recordImpression)
|
|
210
|
+
const handleResponseAdsNeeded = useEvent(requestResponseAds)
|
|
211
|
+
|
|
212
|
+
// Set initial mode from CLI flag on mount
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
if (initialMode) {
|
|
215
|
+
setAgentMode(initialMode)
|
|
216
|
+
}
|
|
217
|
+
}, [initialMode, setAgentMode])
|
|
218
|
+
|
|
219
|
+
// Use extracted chat messages hook for message tree and pagination
|
|
220
|
+
const {
|
|
221
|
+
messageTree,
|
|
222
|
+
visibleTopLevelMessages,
|
|
223
|
+
hiddenMessageCount,
|
|
224
|
+
handleCollapseToggle,
|
|
225
|
+
isUserCollapsing,
|
|
226
|
+
handleLoadPreviousMessages,
|
|
227
|
+
handleToggleAll,
|
|
228
|
+
} = useChatMessages({ messages, setMessages })
|
|
229
|
+
|
|
230
|
+
// Use extracted UI hook for scroll, terminal dimensions, and theme
|
|
231
|
+
const {
|
|
232
|
+
scrollRef,
|
|
233
|
+
scrollToLatest,
|
|
234
|
+
scrollUp,
|
|
235
|
+
scrollDown,
|
|
236
|
+
appliedScrollboxProps,
|
|
237
|
+
isAtBottom,
|
|
238
|
+
hasOverflow,
|
|
239
|
+
terminalWidth,
|
|
240
|
+
terminalHeight,
|
|
241
|
+
separatorWidth,
|
|
242
|
+
messageAvailableWidth,
|
|
243
|
+
isCompactHeight,
|
|
244
|
+
isNarrowWidth,
|
|
245
|
+
theme,
|
|
246
|
+
markdownPalette,
|
|
247
|
+
} = useChatUI({ messages, isUserCollapsing })
|
|
248
|
+
|
|
249
|
+
useEffect(
|
|
250
|
+
() => registerScrollToLatest(scrollToLatest),
|
|
251
|
+
[registerScrollToLatest, scrollToLatest],
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
// Surface server capacity deferrals (free-mode tier shedding under peak
|
|
255
|
+
// demand): the SDK's retry loop absorbs the 429s silently, so without this
|
|
256
|
+
// the user just sees a longer unexplained "thinking". The stream-chunk
|
|
257
|
+
// handlers clear the flag (via setIsRetrying(false)) as soon as real
|
|
258
|
+
// output resumes.
|
|
259
|
+
useEffect(() => {
|
|
260
|
+
setFreeModeCapacityDeferralListener(() => {
|
|
261
|
+
useChatStore.getState().noteCapacityDeferral()
|
|
262
|
+
})
|
|
263
|
+
return () => setFreeModeCapacityDeferralListener(null)
|
|
264
|
+
}, [])
|
|
265
|
+
|
|
266
|
+
const localAgents = useMemo(() => loadLocalAgents(agentMode), [agentMode])
|
|
267
|
+
const inputMode = useChatStore((state) => state.inputMode)
|
|
268
|
+
const setInputMode = useChatStore((state) => state.setInputMode)
|
|
269
|
+
const askUserState = useChatStore((state) => state.askUserState)
|
|
270
|
+
const sessionCreditsUsed = useChatStore((state) => state.sessionCreditsUsed)
|
|
271
|
+
const contextTokensUsed = useChatStore((state) => state.contextTokensUsed)
|
|
272
|
+
|
|
273
|
+
// Get loaded skills for slash commands
|
|
274
|
+
const loadedSkills = useMemo(() => getLoadedSkills(), [])
|
|
275
|
+
|
|
276
|
+
// Filter slash commands based on current ads state - only show the option that changes state
|
|
277
|
+
// Hide both ads commands entirely for subscribers
|
|
278
|
+
// Also merge in skill commands
|
|
279
|
+
const filteredSlashCommands = useMemo(() => {
|
|
280
|
+
const adsEnabled = getAdsEnabled()
|
|
281
|
+
const allCommands = getSlashCommandsWithSkills(loadedSkills)
|
|
282
|
+
return allCommands.filter((cmd) => {
|
|
283
|
+
if (cmd.id === 'ads:enable') return !hasSubscription && !adsEnabled
|
|
284
|
+
if (cmd.id === 'ads:disable') return !hasSubscription && adsEnabled
|
|
285
|
+
return true
|
|
286
|
+
})
|
|
287
|
+
}, [inputValue, loadedSkills, hasSubscription]) // Re-evaluate when input changes (user may have just toggled)
|
|
288
|
+
|
|
289
|
+
const {
|
|
290
|
+
slashContext,
|
|
291
|
+
mentionContext,
|
|
292
|
+
slashMatches,
|
|
293
|
+
agentMatches,
|
|
294
|
+
fileMatches,
|
|
295
|
+
slashSuggestionItems,
|
|
296
|
+
agentSuggestionItems,
|
|
297
|
+
fileSuggestionItems,
|
|
298
|
+
} = useSuggestionEngine({
|
|
299
|
+
disableAgentSuggestions: forceFileOnlyMentions || inputMode !== 'default',
|
|
300
|
+
inputValue: inputMode === 'bash' ? '' : inputValue,
|
|
301
|
+
cursorPosition,
|
|
302
|
+
slashCommands: filteredSlashCommands,
|
|
303
|
+
localAgents,
|
|
304
|
+
fileTree,
|
|
305
|
+
currentAgentMode: agentMode,
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
useEffect(() => {
|
|
309
|
+
if (!mentionContext.active) {
|
|
310
|
+
setForceFileOnlyMentions(false)
|
|
311
|
+
}
|
|
312
|
+
}, [mentionContext.active])
|
|
313
|
+
|
|
314
|
+
// Track when slash menu is activated
|
|
315
|
+
const prevSlashActiveRef = useRef(false)
|
|
316
|
+
useEffect(() => {
|
|
317
|
+
if (slashContext.active && !prevSlashActiveRef.current) {
|
|
318
|
+
trackEvent(AnalyticsEvent.SLASH_MENU_ACTIVATED, {
|
|
319
|
+
queryLength: slashContext.query.length,
|
|
320
|
+
matchCount: slashMatches.length,
|
|
321
|
+
inputLength: inputValue.length,
|
|
322
|
+
})
|
|
323
|
+
}
|
|
324
|
+
prevSlashActiveRef.current = slashContext.active
|
|
325
|
+
}, [
|
|
326
|
+
slashContext.active,
|
|
327
|
+
slashContext.query,
|
|
328
|
+
slashMatches.length,
|
|
329
|
+
inputValue.length,
|
|
330
|
+
])
|
|
331
|
+
|
|
332
|
+
// Reset suggestion menu indexes when context changes
|
|
333
|
+
useEffect(() => {
|
|
334
|
+
if (!slashContext.active) {
|
|
335
|
+
setSlashSelectedIndex(0)
|
|
336
|
+
return
|
|
337
|
+
}
|
|
338
|
+
setSlashSelectedIndex(0)
|
|
339
|
+
}, [slashContext.active, slashContext.query, setSlashSelectedIndex])
|
|
340
|
+
|
|
341
|
+
useEffect(() => {
|
|
342
|
+
if (slashMatches.length > 0 && slashSelectedIndex >= slashMatches.length) {
|
|
343
|
+
setSlashSelectedIndex(slashMatches.length - 1)
|
|
344
|
+
}
|
|
345
|
+
if (slashMatches.length === 0 && slashSelectedIndex !== 0) {
|
|
346
|
+
setSlashSelectedIndex(0)
|
|
347
|
+
}
|
|
348
|
+
}, [slashMatches.length, slashSelectedIndex, setSlashSelectedIndex])
|
|
349
|
+
|
|
350
|
+
useEffect(() => {
|
|
351
|
+
if (!mentionContext.active) {
|
|
352
|
+
setAgentSelectedIndex(0)
|
|
353
|
+
return
|
|
354
|
+
}
|
|
355
|
+
setAgentSelectedIndex(0)
|
|
356
|
+
}, [mentionContext.active, mentionContext.query, setAgentSelectedIndex])
|
|
357
|
+
|
|
358
|
+
useEffect(() => {
|
|
359
|
+
const totalMatches = agentMatches.length + fileMatches.length
|
|
360
|
+
if (totalMatches > 0 && agentSelectedIndex >= totalMatches) {
|
|
361
|
+
setAgentSelectedIndex(totalMatches - 1)
|
|
362
|
+
}
|
|
363
|
+
if (totalMatches === 0 && agentSelectedIndex !== 0) {
|
|
364
|
+
setAgentSelectedIndex(0)
|
|
365
|
+
}
|
|
366
|
+
}, [
|
|
367
|
+
agentMatches.length,
|
|
368
|
+
fileMatches.length,
|
|
369
|
+
agentSelectedIndex,
|
|
370
|
+
setAgentSelectedIndex,
|
|
371
|
+
])
|
|
372
|
+
|
|
373
|
+
const openFileMenuWithTab = useCallback(() => {
|
|
374
|
+
const safeCursor = Math.max(0, Math.min(cursorPosition, inputValue.length))
|
|
375
|
+
|
|
376
|
+
let wordStart = safeCursor
|
|
377
|
+
while (wordStart > 0 && !/\s/.test(inputValue[wordStart - 1])) {
|
|
378
|
+
wordStart--
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const before = inputValue.slice(0, wordStart)
|
|
382
|
+
const wordAtCursor = inputValue.slice(wordStart, safeCursor)
|
|
383
|
+
const after = inputValue.slice(safeCursor)
|
|
384
|
+
const mentionWord = wordAtCursor.startsWith('@')
|
|
385
|
+
? wordAtCursor
|
|
386
|
+
: `@${wordAtCursor}`
|
|
387
|
+
|
|
388
|
+
const text = `${before}${mentionWord}${after}`
|
|
389
|
+
const nextCursor = before.length + mentionWord.length
|
|
390
|
+
|
|
391
|
+
setInputValue({
|
|
392
|
+
text,
|
|
393
|
+
cursorPosition: nextCursor,
|
|
394
|
+
lastEditDueToNav: false,
|
|
395
|
+
})
|
|
396
|
+
setForceFileOnlyMentions(true)
|
|
397
|
+
}, [cursorPosition, inputValue, setInputValue])
|
|
398
|
+
|
|
399
|
+
const { saveToHistory, navigateUp, navigateDown, resetHistoryNavigation } =
|
|
400
|
+
useInputHistory(inputValue, setInputValue, { inputMode, setInputMode })
|
|
401
|
+
|
|
402
|
+
// Use extracted streaming hook for connection, timer, queue, and exit handling
|
|
403
|
+
const {
|
|
404
|
+
isConnected,
|
|
405
|
+
showReconnectionMessage,
|
|
406
|
+
timerStartTime,
|
|
407
|
+
streamStatus,
|
|
408
|
+
isWaitingForResponse,
|
|
409
|
+
isStreaming,
|
|
410
|
+
queuePaused,
|
|
411
|
+
streamMessageIdRef,
|
|
412
|
+
addToQueue,
|
|
413
|
+
setCanProcessQueue,
|
|
414
|
+
clearQueue,
|
|
415
|
+
queuedCount,
|
|
416
|
+
shouldShowQueuePreview,
|
|
417
|
+
inputBoxTitle,
|
|
418
|
+
inputPlaceholder,
|
|
419
|
+
handleCtrlC,
|
|
420
|
+
ensureQueueActiveBeforeSubmit,
|
|
421
|
+
nextCtrlCWillExit,
|
|
422
|
+
} = useChatStreaming({
|
|
423
|
+
inputValue,
|
|
424
|
+
setInputValue,
|
|
425
|
+
terminalWidth,
|
|
426
|
+
separatorWidth,
|
|
427
|
+
})
|
|
428
|
+
|
|
429
|
+
// When streaming completes, flush any pending bash commands into history (ghost mode only)
|
|
430
|
+
// Non-ghost mode commands are already in history and will be cleared when user sends next message
|
|
431
|
+
useEffect(() => {
|
|
432
|
+
if (
|
|
433
|
+
!isStreaming &&
|
|
434
|
+
!streamMessageIdRef.current &&
|
|
435
|
+
!isChainInProgressRef.current &&
|
|
436
|
+
pendingBashMessages.length > 0
|
|
437
|
+
) {
|
|
438
|
+
// Only flush ghost mode commands (those not already added to history) to UI
|
|
439
|
+
const ghostModeMessages = pendingBashMessages.filter(
|
|
440
|
+
(msg) => !msg.isRunning && !msg.addedToHistory,
|
|
441
|
+
)
|
|
442
|
+
|
|
443
|
+
// Add ghost mode messages to UI history
|
|
444
|
+
for (const msg of ghostModeMessages) {
|
|
445
|
+
addBashMessageToHistory({
|
|
446
|
+
command: msg.command,
|
|
447
|
+
stdout: msg.stdout,
|
|
448
|
+
stderr: msg.stderr ?? null,
|
|
449
|
+
exitCode: msg.exitCode,
|
|
450
|
+
cwd: msg.cwd || process.cwd(),
|
|
451
|
+
setMessages,
|
|
452
|
+
})
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// Mark ghost mode messages as added to history (so they don't show as ghost UI)
|
|
456
|
+
// but keep them in pendingBashMessages so they get sent to LLM with next user message
|
|
457
|
+
if (ghostModeMessages.length > 0) {
|
|
458
|
+
const ghostIds = new Set(ghostModeMessages.map((m) => m.id))
|
|
459
|
+
useChatStore.setState((state) => ({
|
|
460
|
+
pendingBashMessages: state.pendingBashMessages.map((m) =>
|
|
461
|
+
ghostIds.has(m.id) ? { ...m, addedToHistory: true } : m,
|
|
462
|
+
),
|
|
463
|
+
}))
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}, [isStreaming, pendingBashMessages, setMessages])
|
|
467
|
+
|
|
468
|
+
const onSubmitPrompt = useEvent(
|
|
469
|
+
async (
|
|
470
|
+
content: string,
|
|
471
|
+
mode: AgentMode,
|
|
472
|
+
options?: { preserveInputValue?: boolean },
|
|
473
|
+
) => {
|
|
474
|
+
ensureQueueActiveBeforeSubmit()
|
|
475
|
+
|
|
476
|
+
const preserveInput = options?.preserveInputValue === true
|
|
477
|
+
const previousInputValue = preserveInput
|
|
478
|
+
? (() => {
|
|
479
|
+
const {
|
|
480
|
+
inputValue: text,
|
|
481
|
+
cursorPosition,
|
|
482
|
+
lastEditDueToNav,
|
|
483
|
+
} = useChatStore.getState()
|
|
484
|
+
return { text, cursorPosition, lastEditDueToNav }
|
|
485
|
+
})()
|
|
486
|
+
: null
|
|
487
|
+
|
|
488
|
+
// Preserve attachments if needed (inline logic to avoid abstraction overhead)
|
|
489
|
+
const preservedAttachments = preserveInput
|
|
490
|
+
? (() => {
|
|
491
|
+
const items = useChatStore.getState().pendingAttachments
|
|
492
|
+
if (items.length > 0) {
|
|
493
|
+
useChatStore.getState().clearPendingAttachments()
|
|
494
|
+
return [...items]
|
|
495
|
+
}
|
|
496
|
+
return null
|
|
497
|
+
})()
|
|
498
|
+
: null
|
|
499
|
+
|
|
500
|
+
try {
|
|
501
|
+
const result = await routeUserPrompt({
|
|
502
|
+
agentMode: mode,
|
|
503
|
+
inputRef,
|
|
504
|
+
inputValue: content,
|
|
505
|
+
isChainInProgressRef,
|
|
506
|
+
isStreaming,
|
|
507
|
+
logoutMutation,
|
|
508
|
+
streamMessageIdRef,
|
|
509
|
+
addToQueue,
|
|
510
|
+
clearMessages,
|
|
511
|
+
saveToHistory,
|
|
512
|
+
scrollToLatest,
|
|
513
|
+
sendMessage,
|
|
514
|
+
setCanProcessQueue,
|
|
515
|
+
setInputFocused,
|
|
516
|
+
setInputValue,
|
|
517
|
+
setIsAuthenticated,
|
|
518
|
+
setMessages,
|
|
519
|
+
setUser,
|
|
520
|
+
})
|
|
521
|
+
|
|
522
|
+
return result
|
|
523
|
+
} finally {
|
|
524
|
+
if (previousInputValue) {
|
|
525
|
+
setInputValue({
|
|
526
|
+
text: previousInputValue.text,
|
|
527
|
+
cursorPosition: previousInputValue.cursorPosition,
|
|
528
|
+
lastEditDueToNav: previousInputValue.lastEditDueToNav,
|
|
529
|
+
})
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
// Restore attachments if they were preserved and none have been added since
|
|
533
|
+
if (
|
|
534
|
+
preservedAttachments &&
|
|
535
|
+
useChatStore.getState().pendingAttachments.length === 0
|
|
536
|
+
) {
|
|
537
|
+
useChatStore.setState((state) => {
|
|
538
|
+
state.pendingAttachments = preservedAttachments
|
|
539
|
+
})
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
},
|
|
543
|
+
)
|
|
544
|
+
|
|
545
|
+
// Retire onboarding suggested prompts once the user submits anything
|
|
546
|
+
// (typed or clicked), persisting so they don't return on future launches.
|
|
547
|
+
useEffect(() => {
|
|
548
|
+
if (showSuggestedPrompts && messages.length > 0) {
|
|
549
|
+
markFirstPromptSubmitted()
|
|
550
|
+
setShowSuggestedPrompts(false)
|
|
551
|
+
}
|
|
552
|
+
}, [showSuggestedPrompts, messages.length])
|
|
553
|
+
|
|
554
|
+
// Submit a suggested onboarding prompt as if the user had typed and sent it
|
|
555
|
+
const handleSelectSuggestedPrompt = useEvent(
|
|
556
|
+
(prompt: string, selection: SuggestedPromptSelection) => {
|
|
557
|
+
trackEvent(AnalyticsEvent.SUGGESTED_PROMPT_CLICKED, {
|
|
558
|
+
label: selection.label,
|
|
559
|
+
index: selection.index,
|
|
560
|
+
promptLength: prompt.length,
|
|
561
|
+
agentMode,
|
|
562
|
+
})
|
|
563
|
+
onSubmitPrompt(prompt, agentMode).catch((error) => {
|
|
564
|
+
logger.error({ error }, '[suggested-prompt] Failed to submit prompt')
|
|
565
|
+
showClipboardMessage('Failed to send prompt', { durationMs: 3000 })
|
|
566
|
+
})
|
|
567
|
+
},
|
|
568
|
+
)
|
|
569
|
+
|
|
570
|
+
// Handle followup suggestion clicks
|
|
571
|
+
useEffect(() => {
|
|
572
|
+
const handleFollowupClick = (event: Event) => {
|
|
573
|
+
const customEvent = event as CustomEvent<{
|
|
574
|
+
prompt: string
|
|
575
|
+
index: number
|
|
576
|
+
toolCallId: string
|
|
577
|
+
}>
|
|
578
|
+
const { prompt, index, toolCallId } = customEvent.detail
|
|
579
|
+
|
|
580
|
+
logger.info(
|
|
581
|
+
{ promptLength: prompt.length, index, toolCallId, agentMode },
|
|
582
|
+
'[followup-click] Followup clicked',
|
|
583
|
+
)
|
|
584
|
+
|
|
585
|
+
// Track analytics event
|
|
586
|
+
trackEvent(AnalyticsEvent.FOLLOWUP_CLICKED, {
|
|
587
|
+
promptLength: prompt.length,
|
|
588
|
+
index,
|
|
589
|
+
agentMode,
|
|
590
|
+
})
|
|
591
|
+
|
|
592
|
+
// Mark this followup as clicked (persisted per toolCallId)
|
|
593
|
+
useChatStore.getState().markFollowupClicked(toolCallId, index)
|
|
594
|
+
|
|
595
|
+
// Send the followup prompt directly, preserving the user's current input
|
|
596
|
+
onSubmitPrompt(prompt, agentMode, {
|
|
597
|
+
preserveInputValue: true,
|
|
598
|
+
})
|
|
599
|
+
.then((result) => {
|
|
600
|
+
logger.info(
|
|
601
|
+
{ hasResult: !!result },
|
|
602
|
+
'[followup-click] onSubmitPrompt completed',
|
|
603
|
+
)
|
|
604
|
+
})
|
|
605
|
+
.catch((error) => {
|
|
606
|
+
logger.error(
|
|
607
|
+
{ error },
|
|
608
|
+
'[followup-click] onSubmitPrompt failed with error',
|
|
609
|
+
)
|
|
610
|
+
showClipboardMessage('Failed to send followup', { durationMs: 3000 })
|
|
611
|
+
})
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
globalThis.addEventListener('anvil:send-followup', handleFollowupClick)
|
|
615
|
+
return () => {
|
|
616
|
+
globalThis.removeEventListener(
|
|
617
|
+
'anvil:send-followup',
|
|
618
|
+
handleFollowupClick,
|
|
619
|
+
)
|
|
620
|
+
}
|
|
621
|
+
}, [onSubmitPrompt, agentMode])
|
|
622
|
+
|
|
623
|
+
// handleSlashItemClick is defined later after feedback/publish stores are available
|
|
624
|
+
|
|
625
|
+
const handleMentionItemClick = useCallback(
|
|
626
|
+
(index: number) => {
|
|
627
|
+
if (mentionContext.startIndex < 0) return
|
|
628
|
+
|
|
629
|
+
let replacement: string
|
|
630
|
+
if (index < agentMatches.length) {
|
|
631
|
+
const selected = agentMatches[index]
|
|
632
|
+
if (!selected) return
|
|
633
|
+
replacement = `@${selected.id} `
|
|
634
|
+
} else {
|
|
635
|
+
const fileIndex = index - agentMatches.length
|
|
636
|
+
const selectedFile = fileMatches[fileIndex]
|
|
637
|
+
if (!selectedFile) return
|
|
638
|
+
replacement = `@${selectedFile.filePath} `
|
|
639
|
+
}
|
|
640
|
+
const before = inputValue.slice(0, mentionContext.startIndex)
|
|
641
|
+
const after = inputValue.slice(
|
|
642
|
+
mentionContext.startIndex + 1 + mentionContext.query.length,
|
|
643
|
+
)
|
|
644
|
+
setInputValue({
|
|
645
|
+
text: before + replacement + after,
|
|
646
|
+
cursorPosition: before.length + replacement.length,
|
|
647
|
+
lastEditDueToNav: false,
|
|
648
|
+
})
|
|
649
|
+
setAgentSelectedIndex(0)
|
|
650
|
+
},
|
|
651
|
+
[
|
|
652
|
+
mentionContext,
|
|
653
|
+
agentMatches,
|
|
654
|
+
fileMatches,
|
|
655
|
+
inputValue,
|
|
656
|
+
setInputValue,
|
|
657
|
+
setAgentSelectedIndex,
|
|
658
|
+
],
|
|
659
|
+
)
|
|
660
|
+
|
|
661
|
+
const { inputWidth, handleBuildFast, handleBuildMax, handleBuildLite } =
|
|
662
|
+
useChatInput({
|
|
663
|
+
setInputValue,
|
|
664
|
+
agentMode,
|
|
665
|
+
setAgentMode,
|
|
666
|
+
separatorWidth,
|
|
667
|
+
consumeInitialPrompt,
|
|
668
|
+
onSubmitPrompt,
|
|
669
|
+
isCompactHeight,
|
|
670
|
+
isNarrowWidth,
|
|
671
|
+
})
|
|
672
|
+
|
|
673
|
+
const {
|
|
674
|
+
feedbackMode,
|
|
675
|
+
feedbackText,
|
|
676
|
+
openFeedbackForMessage,
|
|
677
|
+
closeFeedback,
|
|
678
|
+
saveCurrentInput,
|
|
679
|
+
restoreSavedInput,
|
|
680
|
+
setFeedbackText,
|
|
681
|
+
} = useFeedbackStore(
|
|
682
|
+
useShallow((state) => ({
|
|
683
|
+
feedbackMode: state.feedbackMode,
|
|
684
|
+
feedbackText: state.feedbackText,
|
|
685
|
+
openFeedbackForMessage: state.openFeedbackForMessage,
|
|
686
|
+
closeFeedback: state.closeFeedback,
|
|
687
|
+
saveCurrentInput: state.saveCurrentInput,
|
|
688
|
+
restoreSavedInput: state.restoreSavedInput,
|
|
689
|
+
setFeedbackText: state.setFeedbackText,
|
|
690
|
+
})),
|
|
691
|
+
)
|
|
692
|
+
|
|
693
|
+
const { publishMode, openPublishMode, closePublish, preSelectAgents } =
|
|
694
|
+
usePublishStore(
|
|
695
|
+
useShallow((state) => ({
|
|
696
|
+
publishMode: state.publishMode,
|
|
697
|
+
openPublishMode: state.openPublishMode,
|
|
698
|
+
closePublish: state.closePublish,
|
|
699
|
+
preSelectAgents: state.preSelectAgents,
|
|
700
|
+
})),
|
|
701
|
+
)
|
|
702
|
+
|
|
703
|
+
const { reviewMode, closeReviewScreen } = useReviewStore(
|
|
704
|
+
useShallow((state) => ({
|
|
705
|
+
reviewMode: state.reviewMode,
|
|
706
|
+
closeReviewScreen: state.closeReviewScreen,
|
|
707
|
+
})),
|
|
708
|
+
)
|
|
709
|
+
|
|
710
|
+
const { queuePanelOpen, openQueuePanel, closeQueuePanel } =
|
|
711
|
+
useQueuePanelStore(
|
|
712
|
+
useShallow((state) => ({
|
|
713
|
+
queuePanelOpen: state.queuePanelOpen,
|
|
714
|
+
openQueuePanel: state.openQueuePanel,
|
|
715
|
+
closeQueuePanel: state.closeQueuePanel,
|
|
716
|
+
})),
|
|
717
|
+
)
|
|
718
|
+
|
|
719
|
+
// Review and ask_user take the composer's place too. Leaving the panel
|
|
720
|
+
// flagged open behind them would keep chat's keyboard disabled with nothing
|
|
721
|
+
// rendered to handle keys, so hand the surface back for real.
|
|
722
|
+
useEffect(() => {
|
|
723
|
+
if (queuePanelOpen && (reviewMode || askUserState !== null)) {
|
|
724
|
+
closeQueuePanel()
|
|
725
|
+
}
|
|
726
|
+
}, [queuePanelOpen, reviewMode, askUserState, closeQueuePanel])
|
|
727
|
+
|
|
728
|
+
// The panel store outlives this component and a Anvil session can end on
|
|
729
|
+
// its own, unmounting chat mid-edit. Without this, the next session would
|
|
730
|
+
// open onto a panel for a queue that no longer exists.
|
|
731
|
+
useEffect(() => () => useQueuePanelStore.getState().closeQueuePanel(), [])
|
|
732
|
+
|
|
733
|
+
const publishMutation = usePublishMutation()
|
|
734
|
+
|
|
735
|
+
const handleCommandResult = useCallback(
|
|
736
|
+
(result?: CommandResult) => {
|
|
737
|
+
if (!result) return
|
|
738
|
+
|
|
739
|
+
if (result.openFeedbackMode) {
|
|
740
|
+
// Save the feedback text that was set by the command handler before opening feedback mode
|
|
741
|
+
const { feedbackText, feedbackCursor } = useFeedbackStore.getState()
|
|
742
|
+
saveCurrentInput('', 0)
|
|
743
|
+
openFeedbackForMessage(null)
|
|
744
|
+
// Restore the prefilled text after openFeedbackForMessage resets it
|
|
745
|
+
if (feedbackText) {
|
|
746
|
+
useFeedbackStore.getState().setFeedbackText(feedbackText)
|
|
747
|
+
useFeedbackStore.getState().setFeedbackCursor(feedbackCursor)
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
if (result.openPublishMode) {
|
|
752
|
+
if (result.preSelectAgents && result.preSelectAgents.length > 0) {
|
|
753
|
+
// preSelectAgents already sets publishMode: true, so don't call openPublishMode
|
|
754
|
+
// which would reset the selectedAgentIds
|
|
755
|
+
preSelectAgents(result.preSelectAgents)
|
|
756
|
+
} else {
|
|
757
|
+
openPublishMode()
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
if (result.openChatHistory) {
|
|
762
|
+
useChatHistoryStore.getState().openChatHistory()
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
if (result.openReviewScreen) {
|
|
766
|
+
useReviewStore.getState().openReviewScreen()
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
if (result.openQueuePanel) {
|
|
770
|
+
// The panel closes itself once the queue drains, so opening an empty
|
|
771
|
+
// one would just flash. Say so instead.
|
|
772
|
+
if (queuedCount > 0) useQueuePanelStore.getState().openQueuePanel()
|
|
773
|
+
else setMessages((prev) => [...prev, getSystemMessage('Nothing queued.')])
|
|
774
|
+
}
|
|
775
|
+
},
|
|
776
|
+
[
|
|
777
|
+
saveCurrentInput,
|
|
778
|
+
openFeedbackForMessage,
|
|
779
|
+
openPublishMode,
|
|
780
|
+
preSelectAgents,
|
|
781
|
+
queuedCount,
|
|
782
|
+
setMessages,
|
|
783
|
+
],
|
|
784
|
+
)
|
|
785
|
+
|
|
786
|
+
// Helper to apply insertText for slash commands - returns true if handled
|
|
787
|
+
const applySlashInsertText = useCallback(
|
|
788
|
+
(selected: MatchedSlashCommand): boolean => {
|
|
789
|
+
if (selected.insertText != null && slashContext.startIndex >= 0) {
|
|
790
|
+
const before = inputValue.slice(0, slashContext.startIndex)
|
|
791
|
+
const after = inputValue.slice(
|
|
792
|
+
slashContext.startIndex + 1 + slashContext.query.length,
|
|
793
|
+
)
|
|
794
|
+
setInputValue({
|
|
795
|
+
text: before + selected.insertText + after,
|
|
796
|
+
cursorPosition: before.length + selected.insertText.length,
|
|
797
|
+
lastEditDueToNav: false,
|
|
798
|
+
})
|
|
799
|
+
setSlashSelectedIndex(0)
|
|
800
|
+
return true
|
|
801
|
+
}
|
|
802
|
+
return false
|
|
803
|
+
},
|
|
804
|
+
[slashContext, inputValue, setInputValue, setSlashSelectedIndex],
|
|
805
|
+
)
|
|
806
|
+
|
|
807
|
+
// Click handler for slash menu items - executes command or inserts text
|
|
808
|
+
const handleSlashItemClick = useCallback(
|
|
809
|
+
async (index: number) => {
|
|
810
|
+
const selected = slashMatches[index]
|
|
811
|
+
if (!selected) return
|
|
812
|
+
|
|
813
|
+
// If the command has insertText, insert it instead of executing
|
|
814
|
+
if (applySlashInsertText(selected)) return
|
|
815
|
+
|
|
816
|
+
// Execute the selected slash command immediately
|
|
817
|
+
const commandString = `/${selected.id}`
|
|
818
|
+
setSlashSelectedIndex(0)
|
|
819
|
+
|
|
820
|
+
const result = await onSubmitPrompt(commandString, agentMode)
|
|
821
|
+
handleCommandResult(result)
|
|
822
|
+
},
|
|
823
|
+
[
|
|
824
|
+
slashMatches,
|
|
825
|
+
applySlashInsertText,
|
|
826
|
+
setSlashSelectedIndex,
|
|
827
|
+
onSubmitPrompt,
|
|
828
|
+
agentMode,
|
|
829
|
+
handleCommandResult,
|
|
830
|
+
],
|
|
831
|
+
)
|
|
832
|
+
|
|
833
|
+
const inputValueRef = useRef(inputValue)
|
|
834
|
+
const cursorPositionRef = useRef(cursorPosition)
|
|
835
|
+
useEffect(() => {
|
|
836
|
+
inputValueRef.current = inputValue
|
|
837
|
+
}, [inputValue])
|
|
838
|
+
|
|
839
|
+
// Report activity on input changes for ad rotation (debounced via separate effect)
|
|
840
|
+
const lastReportedActivityRef = useRef<number>(0)
|
|
841
|
+
useEffect(() => {
|
|
842
|
+
const now = Date.now()
|
|
843
|
+
// Throttle to max once per second to avoid excessive calls
|
|
844
|
+
if (now - lastReportedActivityRef.current > 1000) {
|
|
845
|
+
lastReportedActivityRef.current = now
|
|
846
|
+
reportActivity()
|
|
847
|
+
}
|
|
848
|
+
}, [inputValue])
|
|
849
|
+
useEffect(() => {
|
|
850
|
+
cursorPositionRef.current = cursorPosition
|
|
851
|
+
}, [cursorPosition])
|
|
852
|
+
|
|
853
|
+
const handleOpenFeedbackForMessage = useCallback(
|
|
854
|
+
(
|
|
855
|
+
id: string | null,
|
|
856
|
+
options?: {
|
|
857
|
+
category?: FeedbackCategory
|
|
858
|
+
footerMessage?: string
|
|
859
|
+
errors?: Array<{ id: string; message: string }>
|
|
860
|
+
},
|
|
861
|
+
) => {
|
|
862
|
+
saveCurrentInput(inputValueRef.current, cursorPositionRef.current)
|
|
863
|
+
openFeedbackForMessage(id, options)
|
|
864
|
+
},
|
|
865
|
+
[saveCurrentInput, openFeedbackForMessage],
|
|
866
|
+
)
|
|
867
|
+
|
|
868
|
+
const handleMessageFeedback = useCallback(
|
|
869
|
+
(
|
|
870
|
+
id: string,
|
|
871
|
+
options?: {
|
|
872
|
+
category?: FeedbackCategory
|
|
873
|
+
footerMessage?: string
|
|
874
|
+
errors?: Array<{ id: string; message: string }>
|
|
875
|
+
},
|
|
876
|
+
) => {
|
|
877
|
+
handleOpenFeedbackForMessage(id, options)
|
|
878
|
+
},
|
|
879
|
+
[handleOpenFeedbackForMessage],
|
|
880
|
+
)
|
|
881
|
+
|
|
882
|
+
const handleExitFeedback = useCallback(() => {
|
|
883
|
+
const { value, cursor } = restoreSavedInput()
|
|
884
|
+
setInputValue({
|
|
885
|
+
text: value,
|
|
886
|
+
cursorPosition: cursor,
|
|
887
|
+
lastEditDueToNav: false,
|
|
888
|
+
})
|
|
889
|
+
setInputFocused(true)
|
|
890
|
+
resetHistoryNavigation()
|
|
891
|
+
}, [
|
|
892
|
+
restoreSavedInput,
|
|
893
|
+
setInputValue,
|
|
894
|
+
setInputFocused,
|
|
895
|
+
resetHistoryNavigation,
|
|
896
|
+
])
|
|
897
|
+
|
|
898
|
+
const handleCloseFeedback = useCallback(() => {
|
|
899
|
+
closeFeedback()
|
|
900
|
+
handleExitFeedback()
|
|
901
|
+
}, [closeFeedback, handleExitFeedback])
|
|
902
|
+
|
|
903
|
+
const handleExitPublish = useCallback(() => {
|
|
904
|
+
closePublish()
|
|
905
|
+
setInputFocused(true)
|
|
906
|
+
}, [closePublish, setInputFocused])
|
|
907
|
+
|
|
908
|
+
const handleReviewOptionSelect = useCallback(
|
|
909
|
+
(reviewText: string) => {
|
|
910
|
+
closeReviewScreen()
|
|
911
|
+
setInputFocused(true)
|
|
912
|
+
// Submit the review request
|
|
913
|
+
onSubmitPrompt(reviewText, agentMode)
|
|
914
|
+
.then((result) => handleCommandResult(result))
|
|
915
|
+
.catch((error) => {
|
|
916
|
+
logger.error({ error }, '[review] Failed to submit review prompt')
|
|
917
|
+
showClipboardMessage('Failed to send review request', {
|
|
918
|
+
durationMs: 3000,
|
|
919
|
+
})
|
|
920
|
+
})
|
|
921
|
+
},
|
|
922
|
+
[
|
|
923
|
+
closeReviewScreen,
|
|
924
|
+
setInputFocused,
|
|
925
|
+
onSubmitPrompt,
|
|
926
|
+
agentMode,
|
|
927
|
+
handleCommandResult,
|
|
928
|
+
],
|
|
929
|
+
)
|
|
930
|
+
|
|
931
|
+
const handleCloseReviewScreen = useCallback(() => {
|
|
932
|
+
closeReviewScreen()
|
|
933
|
+
setInputFocused(true)
|
|
934
|
+
}, [closeReviewScreen, setInputFocused])
|
|
935
|
+
|
|
936
|
+
// The panel took the composer's place, so give the keyboard back to it the
|
|
937
|
+
// same way the review screen does.
|
|
938
|
+
const handleCloseQueuePanel = useCallback(() => {
|
|
939
|
+
closeQueuePanel()
|
|
940
|
+
setInputFocused(true)
|
|
941
|
+
inputRef.current?.focus()
|
|
942
|
+
}, [closeQueuePanel, setInputFocused, inputRef])
|
|
943
|
+
|
|
944
|
+
const handleReviewCustom = useCallback(() => {
|
|
945
|
+
closeReviewScreen()
|
|
946
|
+
setInputMode('review')
|
|
947
|
+
setInputFocused(true)
|
|
948
|
+
}, [closeReviewScreen, setInputMode, setInputFocused])
|
|
949
|
+
|
|
950
|
+
const handlePublish = useCallback(
|
|
951
|
+
async (agentIds: string[]) => {
|
|
952
|
+
await publishMutation.mutateAsync(agentIds)
|
|
953
|
+
},
|
|
954
|
+
[publishMutation],
|
|
955
|
+
)
|
|
956
|
+
|
|
957
|
+
// Ensure bracketed paste events target the active chat input
|
|
958
|
+
useEffect(() => {
|
|
959
|
+
if (feedbackMode) {
|
|
960
|
+
inputRef.current?.focus()
|
|
961
|
+
return
|
|
962
|
+
}
|
|
963
|
+
if (!askUserState) {
|
|
964
|
+
inputRef.current?.focus()
|
|
965
|
+
}
|
|
966
|
+
}, [feedbackMode, askUserState, inputRef])
|
|
967
|
+
|
|
968
|
+
const handleSubmit = useCallback(async () => {
|
|
969
|
+
// Report activity for ad rotation
|
|
970
|
+
reportActivity()
|
|
971
|
+
// Update terminal title with truncated user input
|
|
972
|
+
if (inputValue.trim()) {
|
|
973
|
+
setTerminalTitle(inputValue)
|
|
974
|
+
}
|
|
975
|
+
const result = await onSubmitPrompt(inputValue, agentMode)
|
|
976
|
+
handleCommandResult(result)
|
|
977
|
+
}, [onSubmitPrompt, inputValue, agentMode, handleCommandResult])
|
|
978
|
+
|
|
979
|
+
const totalMentionMatches = agentMatches.length + fileMatches.length
|
|
980
|
+
const historyNavUpEnabled =
|
|
981
|
+
lastEditDueToNav ||
|
|
982
|
+
(cursorPosition === 0 &&
|
|
983
|
+
((slashContext.active && slashSelectedIndex === 0) ||
|
|
984
|
+
(mentionContext.active && agentSelectedIndex === 0) ||
|
|
985
|
+
(!slashContext.active && !mentionContext.active)))
|
|
986
|
+
const historyNavDownEnabled =
|
|
987
|
+
lastEditDueToNav ||
|
|
988
|
+
(cursorPosition === inputValue.length &&
|
|
989
|
+
((slashContext.active &&
|
|
990
|
+
slashSelectedIndex === slashMatches.length - 1) ||
|
|
991
|
+
(mentionContext.active &&
|
|
992
|
+
agentSelectedIndex === totalMentionMatches - 1) ||
|
|
993
|
+
(!slashContext.active && !mentionContext.active)))
|
|
994
|
+
|
|
995
|
+
// Build keyboard state from store values
|
|
996
|
+
const chatKeyboardState: ChatKeyboardState = useMemo(
|
|
997
|
+
() => ({
|
|
998
|
+
...createDefaultChatKeyboardState(),
|
|
999
|
+
inputMode,
|
|
1000
|
+
inputValue: feedbackMode ? feedbackText : inputValue,
|
|
1001
|
+
cursorPosition,
|
|
1002
|
+
isStreaming,
|
|
1003
|
+
isWaitingForResponse,
|
|
1004
|
+
feedbackMode,
|
|
1005
|
+
focusedAgentId,
|
|
1006
|
+
slashMenuActive: slashContext.active,
|
|
1007
|
+
mentionMenuActive: mentionContext.active,
|
|
1008
|
+
slashSelectedIndex,
|
|
1009
|
+
agentSelectedIndex,
|
|
1010
|
+
slashMatchesLength: slashMatches.length,
|
|
1011
|
+
totalMentionMatches: agentMatches.length + fileMatches.length,
|
|
1012
|
+
disableSlashSuggestions:
|
|
1013
|
+
getInputModeConfig(inputMode).disableSlashSuggestions,
|
|
1014
|
+
historyNavUpEnabled,
|
|
1015
|
+
historyNavDownEnabled,
|
|
1016
|
+
nextCtrlCWillExit,
|
|
1017
|
+
queuePaused,
|
|
1018
|
+
queuedCount,
|
|
1019
|
+
}),
|
|
1020
|
+
[
|
|
1021
|
+
inputMode,
|
|
1022
|
+
inputValue,
|
|
1023
|
+
feedbackText,
|
|
1024
|
+
cursorPosition,
|
|
1025
|
+
isStreaming,
|
|
1026
|
+
isWaitingForResponse,
|
|
1027
|
+
feedbackMode,
|
|
1028
|
+
focusedAgentId,
|
|
1029
|
+
slashContext.active,
|
|
1030
|
+
mentionContext.active,
|
|
1031
|
+
slashSelectedIndex,
|
|
1032
|
+
agentSelectedIndex,
|
|
1033
|
+
slashMatches.length,
|
|
1034
|
+
agentMatches.length,
|
|
1035
|
+
fileMatches.length,
|
|
1036
|
+
historyNavUpEnabled,
|
|
1037
|
+
historyNavDownEnabled,
|
|
1038
|
+
nextCtrlCWillExit,
|
|
1039
|
+
queuePaused,
|
|
1040
|
+
queuedCount,
|
|
1041
|
+
],
|
|
1042
|
+
)
|
|
1043
|
+
|
|
1044
|
+
// Keyboard handlers
|
|
1045
|
+
const chatKeyboardHandlers: ChatKeyboardHandlers = useMemo(
|
|
1046
|
+
() => ({
|
|
1047
|
+
onExitInputMode: () => setInputMode('default'),
|
|
1048
|
+
onExitFeedbackMode: handleCloseFeedback,
|
|
1049
|
+
onClearFeedbackInput: () => {
|
|
1050
|
+
setFeedbackText('')
|
|
1051
|
+
useFeedbackStore.getState().setFeedbackCursor(0)
|
|
1052
|
+
},
|
|
1053
|
+
onClearInput: () =>
|
|
1054
|
+
setInputValue({ text: '', cursorPosition: 0, lastEditDueToNav: false }),
|
|
1055
|
+
onBackspaceExitMode: () => setInputMode('default'),
|
|
1056
|
+
onInterruptStream: () => {
|
|
1057
|
+
stopActiveRun('user-interrupt')
|
|
1058
|
+
},
|
|
1059
|
+
onSlashMenuDown: () => setSlashSelectedIndex((prev) => prev + 1),
|
|
1060
|
+
onSlashMenuUp: () => setSlashSelectedIndex((prev) => prev - 1),
|
|
1061
|
+
onSlashMenuSelect: async () => {
|
|
1062
|
+
const selected = slashMatches[slashSelectedIndex] || slashMatches[0]
|
|
1063
|
+
if (!selected) return
|
|
1064
|
+
|
|
1065
|
+
// If the command has insertText, insert it instead of executing
|
|
1066
|
+
if (applySlashInsertText(selected)) return
|
|
1067
|
+
|
|
1068
|
+
// Execute the selected slash command immediately
|
|
1069
|
+
const commandString = `/${selected.id}`
|
|
1070
|
+
setSlashSelectedIndex(0)
|
|
1071
|
+
|
|
1072
|
+
const result = await onSubmitPrompt(commandString, agentMode)
|
|
1073
|
+
|
|
1074
|
+
handleCommandResult(result)
|
|
1075
|
+
},
|
|
1076
|
+
onSlashMenuComplete: () => {
|
|
1077
|
+
// Complete the word without executing - same as clicking on the item
|
|
1078
|
+
const selected = slashMatches[slashSelectedIndex] || slashMatches[0]
|
|
1079
|
+
if (!selected || slashContext.startIndex < 0) return
|
|
1080
|
+
|
|
1081
|
+
// If the command has insertText, insert it instead of the command
|
|
1082
|
+
if (applySlashInsertText(selected)) return
|
|
1083
|
+
|
|
1084
|
+
const before = inputValue.slice(0, slashContext.startIndex)
|
|
1085
|
+
const after = inputValue.slice(
|
|
1086
|
+
slashContext.startIndex + 1 + slashContext.query.length,
|
|
1087
|
+
)
|
|
1088
|
+
const replacement = `/${selected.id} `
|
|
1089
|
+
setInputValue({
|
|
1090
|
+
text: before + replacement + after,
|
|
1091
|
+
cursorPosition: before.length + replacement.length,
|
|
1092
|
+
lastEditDueToNav: false,
|
|
1093
|
+
})
|
|
1094
|
+
setSlashSelectedIndex(0)
|
|
1095
|
+
},
|
|
1096
|
+
onMentionMenuDown: () => setAgentSelectedIndex((prev) => prev + 1),
|
|
1097
|
+
onMentionMenuUp: () => setAgentSelectedIndex((prev) => prev - 1),
|
|
1098
|
+
onMentionMenuTab: () => {
|
|
1099
|
+
const totalMatches = agentMatches.length + fileMatches.length
|
|
1100
|
+
setAgentSelectedIndex((prev) => (prev + 1) % totalMatches)
|
|
1101
|
+
},
|
|
1102
|
+
onMentionMenuShiftTab: () => {
|
|
1103
|
+
const totalMatches = agentMatches.length + fileMatches.length
|
|
1104
|
+
setAgentSelectedIndex(
|
|
1105
|
+
(prev) => (totalMatches + prev - 1) % totalMatches,
|
|
1106
|
+
)
|
|
1107
|
+
},
|
|
1108
|
+
onMentionMenuSelect: () => {
|
|
1109
|
+
if (mentionContext.startIndex < 0) return
|
|
1110
|
+
|
|
1111
|
+
const trySelectAtIndex = (index: number): boolean => {
|
|
1112
|
+
let replacement: string
|
|
1113
|
+
if (index < agentMatches.length) {
|
|
1114
|
+
const selected = agentMatches[index]
|
|
1115
|
+
if (!selected) return false
|
|
1116
|
+
replacement = `@${selected.id} `
|
|
1117
|
+
} else {
|
|
1118
|
+
const fileIndex = index - agentMatches.length
|
|
1119
|
+
const selectedFile = fileMatches[fileIndex]
|
|
1120
|
+
if (!selectedFile) return false
|
|
1121
|
+
replacement = `@${selectedFile.filePath} `
|
|
1122
|
+
}
|
|
1123
|
+
const before = inputValue.slice(0, mentionContext.startIndex)
|
|
1124
|
+
const after = inputValue.slice(
|
|
1125
|
+
mentionContext.startIndex + 1 + mentionContext.query.length,
|
|
1126
|
+
)
|
|
1127
|
+
setInputValue({
|
|
1128
|
+
text: before + replacement + after,
|
|
1129
|
+
cursorPosition: before.length + replacement.length,
|
|
1130
|
+
lastEditDueToNav: false,
|
|
1131
|
+
})
|
|
1132
|
+
setAgentSelectedIndex(0)
|
|
1133
|
+
return true
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
// Try current selection, fall back to first item
|
|
1137
|
+
trySelectAtIndex(agentSelectedIndex) || trySelectAtIndex(0)
|
|
1138
|
+
},
|
|
1139
|
+
onMentionMenuComplete: () => {
|
|
1140
|
+
// Complete the word without executing - same as select for mentions
|
|
1141
|
+
if (mentionContext.startIndex < 0) return
|
|
1142
|
+
|
|
1143
|
+
let replacement: string
|
|
1144
|
+
const index = agentSelectedIndex
|
|
1145
|
+
if (index < agentMatches.length) {
|
|
1146
|
+
const selected =
|
|
1147
|
+
agentMatches.length > 0
|
|
1148
|
+
? agentMatches[index] || agentMatches[0]
|
|
1149
|
+
: undefined
|
|
1150
|
+
if (!selected) return
|
|
1151
|
+
replacement = `@${selected.id} `
|
|
1152
|
+
} else {
|
|
1153
|
+
const fileIndex = index - agentMatches.length
|
|
1154
|
+
const selectedFile =
|
|
1155
|
+
fileMatches.length > 0
|
|
1156
|
+
? fileMatches[fileIndex] || fileMatches[0]
|
|
1157
|
+
: undefined
|
|
1158
|
+
if (!selectedFile) return
|
|
1159
|
+
replacement = `@${selectedFile.filePath} `
|
|
1160
|
+
}
|
|
1161
|
+
const before = inputValue.slice(0, mentionContext.startIndex)
|
|
1162
|
+
const after = inputValue.slice(
|
|
1163
|
+
mentionContext.startIndex + 1 + mentionContext.query.length,
|
|
1164
|
+
)
|
|
1165
|
+
setInputValue({
|
|
1166
|
+
text: before + replacement + after,
|
|
1167
|
+
cursorPosition: before.length + replacement.length,
|
|
1168
|
+
lastEditDueToNav: false,
|
|
1169
|
+
})
|
|
1170
|
+
setAgentSelectedIndex(0)
|
|
1171
|
+
},
|
|
1172
|
+
onOpenFileMenuWithTab: () => {
|
|
1173
|
+
const safeCursor = Math.max(
|
|
1174
|
+
0,
|
|
1175
|
+
Math.min(cursorPosition, inputValue.length),
|
|
1176
|
+
)
|
|
1177
|
+
let wordStart = safeCursor
|
|
1178
|
+
while (wordStart > 0 && !/\s/.test(inputValue[wordStart - 1]!)) {
|
|
1179
|
+
wordStart--
|
|
1180
|
+
}
|
|
1181
|
+
if (wordStart < safeCursor) {
|
|
1182
|
+
openFileMenuWithTab()
|
|
1183
|
+
return true
|
|
1184
|
+
}
|
|
1185
|
+
return false
|
|
1186
|
+
},
|
|
1187
|
+
onHistoryUp: navigateUp,
|
|
1188
|
+
onHistoryDown: navigateDown,
|
|
1189
|
+
onToggleAgentMode: toggleAgentMode,
|
|
1190
|
+
onUnfocusAgent: () => {
|
|
1191
|
+
setFocusedAgentId(null)
|
|
1192
|
+
setInputFocused(true)
|
|
1193
|
+
inputRef.current?.focus()
|
|
1194
|
+
},
|
|
1195
|
+
onClearQueue: clearQueue,
|
|
1196
|
+
onOpenQueuePanel: openQueuePanel,
|
|
1197
|
+
onExitAppWarning: () => handleCtrlC(),
|
|
1198
|
+
onExitApp: () => handleCtrlC(),
|
|
1199
|
+
onBashHistoryUp: navigateUp,
|
|
1200
|
+
onBashHistoryDown: navigateDown,
|
|
1201
|
+
onPasteImage: () => {
|
|
1202
|
+
const placeholderPath = addClipboardPlaceholder()
|
|
1203
|
+
|
|
1204
|
+
// Process the image in the background
|
|
1205
|
+
setTimeout(() => {
|
|
1206
|
+
const result = readClipboardImage()
|
|
1207
|
+
if (!result.success || !result.imagePath) {
|
|
1208
|
+
useChatStore.getState().removePendingImage(placeholderPath)
|
|
1209
|
+
showClipboardMessage(result.error || 'Failed to paste image', {
|
|
1210
|
+
durationMs: 3000,
|
|
1211
|
+
})
|
|
1212
|
+
return
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
const cwd = getProjectRoot() ?? process.cwd()
|
|
1216
|
+
addPendingImageFromFile(result.imagePath, cwd, placeholderPath).catch(
|
|
1217
|
+
(error) => {
|
|
1218
|
+
logger.error({ error }, 'Failed to add pending image from file')
|
|
1219
|
+
showClipboardMessage('Failed to add image', { durationMs: 3000 })
|
|
1220
|
+
},
|
|
1221
|
+
)
|
|
1222
|
+
}, 0)
|
|
1223
|
+
},
|
|
1224
|
+
onPasteImagePath: (imagePath: string) => {
|
|
1225
|
+
const cwd = getProjectRoot() ?? process.cwd()
|
|
1226
|
+
validateAndAddImage(imagePath, cwd).catch((error) => {
|
|
1227
|
+
logger.error({ error, imagePath }, 'Failed to validate and add image')
|
|
1228
|
+
showClipboardMessage('Failed to add image', { durationMs: 3000 })
|
|
1229
|
+
})
|
|
1230
|
+
},
|
|
1231
|
+
onPasteFilePath: (filePath: string, isDirectory: boolean) => {
|
|
1232
|
+
addPendingFileFromPath(filePath, isDirectory)
|
|
1233
|
+
},
|
|
1234
|
+
onPasteText: (text: string) => {
|
|
1235
|
+
setInputValue((prev) => {
|
|
1236
|
+
const before = prev.text.slice(0, prev.cursorPosition)
|
|
1237
|
+
const after = prev.text.slice(prev.cursorPosition)
|
|
1238
|
+
return {
|
|
1239
|
+
text: before + text + after,
|
|
1240
|
+
cursorPosition: before.length + text.length,
|
|
1241
|
+
lastEditDueToNav: false,
|
|
1242
|
+
}
|
|
1243
|
+
})
|
|
1244
|
+
},
|
|
1245
|
+
onScrollUp: scrollUp,
|
|
1246
|
+
onScrollDown: scrollDown,
|
|
1247
|
+
onToggleAll: handleToggleAll,
|
|
1248
|
+
onOpenBuyCredits: () => {
|
|
1249
|
+
// If credits have been restored, just return to default mode
|
|
1250
|
+
if (areCreditsRestored()) {
|
|
1251
|
+
setInputMode('default')
|
|
1252
|
+
return
|
|
1253
|
+
}
|
|
1254
|
+
// Direct-to-DeepSeek mode has no Anvil credits to buy; the provider's
|
|
1255
|
+
// own balance page is the correct destination, so fall through to the
|
|
1256
|
+
// default input rather than opening the Anvil billing page.
|
|
1257
|
+
if (isDirectDeepSeekMode()) {
|
|
1258
|
+
setInputMode('default')
|
|
1259
|
+
return
|
|
1260
|
+
}
|
|
1261
|
+
// Otherwise open the buy credits page
|
|
1262
|
+
safeOpen(WEBSITE_URL + '/usage')
|
|
1263
|
+
},
|
|
1264
|
+
}),
|
|
1265
|
+
[
|
|
1266
|
+
setInputMode,
|
|
1267
|
+
handleCloseFeedback,
|
|
1268
|
+
setFeedbackText,
|
|
1269
|
+
setInputValue,
|
|
1270
|
+
setSlashSelectedIndex,
|
|
1271
|
+
slashMatches,
|
|
1272
|
+
slashSelectedIndex,
|
|
1273
|
+
slashContext,
|
|
1274
|
+
inputValue,
|
|
1275
|
+
applySlashInsertText,
|
|
1276
|
+
onSubmitPrompt,
|
|
1277
|
+
agentMode,
|
|
1278
|
+
handleCommandResult,
|
|
1279
|
+
setAgentSelectedIndex,
|
|
1280
|
+
agentMatches,
|
|
1281
|
+
fileMatches,
|
|
1282
|
+
agentSelectedIndex,
|
|
1283
|
+
mentionContext,
|
|
1284
|
+
cursorPosition,
|
|
1285
|
+
openFileMenuWithTab,
|
|
1286
|
+
navigateUp,
|
|
1287
|
+
navigateDown,
|
|
1288
|
+
toggleAgentMode,
|
|
1289
|
+
setFocusedAgentId,
|
|
1290
|
+
setInputFocused,
|
|
1291
|
+
inputRef,
|
|
1292
|
+
handleCtrlC,
|
|
1293
|
+
clearQueue,
|
|
1294
|
+
openQueuePanel,
|
|
1295
|
+
scrollUp,
|
|
1296
|
+
scrollDown,
|
|
1297
|
+
handleToggleAll,
|
|
1298
|
+
],
|
|
1299
|
+
)
|
|
1300
|
+
|
|
1301
|
+
// Use the chat keyboard hook
|
|
1302
|
+
useChatKeyboard({
|
|
1303
|
+
state: chatKeyboardState,
|
|
1304
|
+
handlers: chatKeyboardHandlers,
|
|
1305
|
+
disabled: askUserState !== null || reviewMode || queuePanelOpen,
|
|
1306
|
+
})
|
|
1307
|
+
|
|
1308
|
+
// Sync message block context to zustand store for child components
|
|
1309
|
+
const setMessageBlockContext = useMessageBlockStore(
|
|
1310
|
+
(state) => state.setContext,
|
|
1311
|
+
)
|
|
1312
|
+
const setMessageBlockCallbacks = useMessageBlockStore(
|
|
1313
|
+
(state) => state.setCallbacks,
|
|
1314
|
+
)
|
|
1315
|
+
|
|
1316
|
+
// Update context when values change - useLayoutEffect ensures synchronous updates
|
|
1317
|
+
// to prevent message loss during rapid streaming (race condition fix)
|
|
1318
|
+
useLayoutEffect(() => {
|
|
1319
|
+
setMessageBlockContext({
|
|
1320
|
+
theme,
|
|
1321
|
+
markdownPalette,
|
|
1322
|
+
messageTree,
|
|
1323
|
+
isWaitingForResponse,
|
|
1324
|
+
timerStartTime,
|
|
1325
|
+
availableWidth: messageAvailableWidth,
|
|
1326
|
+
responseAds: showInlineAds ? responseAds : {},
|
|
1327
|
+
})
|
|
1328
|
+
}, [
|
|
1329
|
+
theme,
|
|
1330
|
+
markdownPalette,
|
|
1331
|
+
messageTree,
|
|
1332
|
+
isWaitingForResponse,
|
|
1333
|
+
timerStartTime,
|
|
1334
|
+
messageAvailableWidth,
|
|
1335
|
+
responseAds,
|
|
1336
|
+
showInlineAds,
|
|
1337
|
+
setMessageBlockContext,
|
|
1338
|
+
])
|
|
1339
|
+
|
|
1340
|
+
// Update callbacks once (they're stable)
|
|
1341
|
+
useEffect(() => {
|
|
1342
|
+
setMessageBlockCallbacks({
|
|
1343
|
+
onToggleCollapsed: handleCollapseToggle,
|
|
1344
|
+
onBuildFast: handleBuildFast,
|
|
1345
|
+
onBuildMax: handleBuildMax,
|
|
1346
|
+
onBuildLite: handleBuildLite,
|
|
1347
|
+
onFeedback: handleMessageFeedback,
|
|
1348
|
+
onCloseFeedback: handleCloseFeedback,
|
|
1349
|
+
onAdClick: handleAdClick,
|
|
1350
|
+
onAdImpression: handleAdImpression,
|
|
1351
|
+
onResponseAdsNeeded: handleResponseAdsNeeded,
|
|
1352
|
+
})
|
|
1353
|
+
}, [
|
|
1354
|
+
handleCollapseToggle,
|
|
1355
|
+
handleBuildFast,
|
|
1356
|
+
handleBuildMax,
|
|
1357
|
+
handleBuildLite,
|
|
1358
|
+
handleMessageFeedback,
|
|
1359
|
+
handleCloseFeedback,
|
|
1360
|
+
handleAdClick,
|
|
1361
|
+
handleAdImpression,
|
|
1362
|
+
handleResponseAdsNeeded,
|
|
1363
|
+
setMessageBlockCallbacks,
|
|
1364
|
+
])
|
|
1365
|
+
|
|
1366
|
+
const modeConfig = getInputModeConfig(inputMode)
|
|
1367
|
+
const hasSlashSuggestions =
|
|
1368
|
+
slashContext.active &&
|
|
1369
|
+
slashSuggestionItems.length > 0 &&
|
|
1370
|
+
!modeConfig.disableSlashSuggestions
|
|
1371
|
+
const hasMentionSuggestions =
|
|
1372
|
+
!slashContext.active &&
|
|
1373
|
+
mentionContext.active &&
|
|
1374
|
+
(agentSuggestionItems.length > 0 || fileSuggestionItems.length > 0)
|
|
1375
|
+
const hasSuggestionMenu = hasSlashSuggestions || hasMentionSuggestions
|
|
1376
|
+
|
|
1377
|
+
// Show first-time onboarding starter prompts only on a pristine, idle,
|
|
1378
|
+
// empty-input default-mode chat — and never while a menu/overlay is up.
|
|
1379
|
+
const showOnboardingPrompts =
|
|
1380
|
+
showSuggestedPrompts &&
|
|
1381
|
+
messages.length === 0 &&
|
|
1382
|
+
inputValue.length === 0 &&
|
|
1383
|
+
inputMode === 'default' &&
|
|
1384
|
+
!hasSuggestionMenu &&
|
|
1385
|
+
!isStreaming &&
|
|
1386
|
+
!isWaitingForResponse &&
|
|
1387
|
+
!feedbackMode &&
|
|
1388
|
+
!publishMode &&
|
|
1389
|
+
!reviewMode &&
|
|
1390
|
+
askUserState === null
|
|
1391
|
+
|
|
1392
|
+
// Fire a one-time impression so we can measure onboarding-prompt usage
|
|
1393
|
+
// (click-through = SUGGESTED_PROMPT_CLICKED / SUGGESTED_PROMPT_SHOWN).
|
|
1394
|
+
const suggestedPromptsShownRef = useRef(false)
|
|
1395
|
+
useEffect(() => {
|
|
1396
|
+
if (showOnboardingPrompts && !suggestedPromptsShownRef.current) {
|
|
1397
|
+
suggestedPromptsShownRef.current = true
|
|
1398
|
+
trackEvent(AnalyticsEvent.SUGGESTED_PROMPT_SHOWN, {
|
|
1399
|
+
count: isCompactHeight
|
|
1400
|
+
? Math.min(2, DEFAULT_SUGGESTED_PROMPTS.length)
|
|
1401
|
+
: DEFAULT_SUGGESTED_PROMPTS.length,
|
|
1402
|
+
isCompactHeight,
|
|
1403
|
+
})
|
|
1404
|
+
}
|
|
1405
|
+
}, [showOnboardingPrompts, isCompactHeight])
|
|
1406
|
+
|
|
1407
|
+
const inputLayoutMetrics = useMemo(() => {
|
|
1408
|
+
// In bash mode, layout is based on the actual input (no ! prefix needed)
|
|
1409
|
+
const text = inputValue ?? ''
|
|
1410
|
+
const layoutContent = text.length > 0 ? text : ' '
|
|
1411
|
+
const safeCursor = Math.max(
|
|
1412
|
+
0,
|
|
1413
|
+
Math.min(cursorPosition, layoutContent.length),
|
|
1414
|
+
)
|
|
1415
|
+
const cursorProbe =
|
|
1416
|
+
safeCursor >= layoutContent.length
|
|
1417
|
+
? layoutContent
|
|
1418
|
+
: layoutContent.slice(0, safeCursor)
|
|
1419
|
+
const cols = Math.max(1, inputWidth)
|
|
1420
|
+
return computeInputLayoutMetrics({
|
|
1421
|
+
layoutContent,
|
|
1422
|
+
cursorProbe,
|
|
1423
|
+
cols,
|
|
1424
|
+
maxHeight: Math.floor(terminalHeight / 2),
|
|
1425
|
+
})
|
|
1426
|
+
}, [inputValue, cursorPosition, inputWidth, terminalHeight])
|
|
1427
|
+
const isMultilineInput = inputLayoutMetrics.heightLines > 1
|
|
1428
|
+
const shouldCenterInputVertically = !hasSuggestionMenu && !isMultilineInput
|
|
1429
|
+
const statusIndicatorState = getStatusIndicatorState({
|
|
1430
|
+
statusMessage,
|
|
1431
|
+
streamStatus,
|
|
1432
|
+
nextCtrlCWillExit,
|
|
1433
|
+
isConnected,
|
|
1434
|
+
authStatus,
|
|
1435
|
+
showReconnectionMessage,
|
|
1436
|
+
isRetrying,
|
|
1437
|
+
isCapacityWait,
|
|
1438
|
+
isAskUserActive: askUserState !== null,
|
|
1439
|
+
})
|
|
1440
|
+
const hasStatusIndicatorContent = statusIndicatorState.kind !== 'idle'
|
|
1441
|
+
|
|
1442
|
+
// Auto-show subscription limit banner when rate limit becomes active
|
|
1443
|
+
const subscriptionLimitShownRef = useRef(false)
|
|
1444
|
+
const subscriptionRateLimit = subscriptionData?.hasSubscription
|
|
1445
|
+
? subscriptionData.rateLimit
|
|
1446
|
+
: undefined
|
|
1447
|
+
const fallbackToALaCarte = subscriptionData?.fallbackToALaCarte ?? false
|
|
1448
|
+
useEffect(() => {
|
|
1449
|
+
const isLimited = subscriptionRateLimit?.limited === true
|
|
1450
|
+
if (isLimited && !subscriptionLimitShownRef.current) {
|
|
1451
|
+
subscriptionLimitShownRef.current = true
|
|
1452
|
+
// Skip showing the banner if user prefers to always fall back to a-la-carte
|
|
1453
|
+
if (!fallbackToALaCarte) {
|
|
1454
|
+
useChatStore.getState().setInputMode('subscriptionLimit')
|
|
1455
|
+
}
|
|
1456
|
+
} else if (!isLimited) {
|
|
1457
|
+
subscriptionLimitShownRef.current = false
|
|
1458
|
+
if (useChatStore.getState().inputMode === 'subscriptionLimit') {
|
|
1459
|
+
useChatStore.getState().setInputMode('default')
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
}, [subscriptionRateLimit?.limited, fallbackToALaCarte])
|
|
1463
|
+
|
|
1464
|
+
const hasActiveAnvilSession =
|
|
1465
|
+
IS_ANVIL && anvilSession?.status === 'active'
|
|
1466
|
+
const isAnvilSessionOver =
|
|
1467
|
+
IS_ANVIL && anvilSession?.status === 'ended'
|
|
1468
|
+
const shouldShowStatusLine =
|
|
1469
|
+
!feedbackMode &&
|
|
1470
|
+
(hasStatusIndicatorContent ||
|
|
1471
|
+
shouldShowQueuePreview ||
|
|
1472
|
+
!isAtBottom ||
|
|
1473
|
+
hasActiveAnvilSession ||
|
|
1474
|
+
messages.length > 0)
|
|
1475
|
+
|
|
1476
|
+
// Track mouse movement for ad activity (throttled)
|
|
1477
|
+
const lastMouseActivityRef = useRef<number>(0)
|
|
1478
|
+
const handleMouseActivity = useCallback(() => {
|
|
1479
|
+
const now = Date.now()
|
|
1480
|
+
// Throttle to max once per second
|
|
1481
|
+
if (now - lastMouseActivityRef.current > 1000) {
|
|
1482
|
+
lastMouseActivityRef.current = now
|
|
1483
|
+
reportActivity()
|
|
1484
|
+
}
|
|
1485
|
+
}, [])
|
|
1486
|
+
|
|
1487
|
+
return (
|
|
1488
|
+
<box
|
|
1489
|
+
onMouseMove={handleMouseActivity}
|
|
1490
|
+
style={{
|
|
1491
|
+
flexDirection: 'column',
|
|
1492
|
+
gap: 0,
|
|
1493
|
+
flexGrow: 1,
|
|
1494
|
+
}}
|
|
1495
|
+
>
|
|
1496
|
+
<scrollbox
|
|
1497
|
+
ref={scrollRef as React.Ref<ScrollBoxRenderable>}
|
|
1498
|
+
stickyScroll
|
|
1499
|
+
stickyStart="bottom"
|
|
1500
|
+
scrollX={false}
|
|
1501
|
+
scrollbarOptions={{ visible: false }}
|
|
1502
|
+
verticalScrollbarOptions={{
|
|
1503
|
+
visible: !isStreaming && !isWaitingForResponse && hasOverflow,
|
|
1504
|
+
trackOptions: { width: 1 },
|
|
1505
|
+
}}
|
|
1506
|
+
{...appliedScrollboxProps}
|
|
1507
|
+
style={{
|
|
1508
|
+
flexGrow: 1,
|
|
1509
|
+
rootOptions: {
|
|
1510
|
+
flexGrow: 1,
|
|
1511
|
+
padding: 0,
|
|
1512
|
+
gap: 0,
|
|
1513
|
+
flexDirection: 'row',
|
|
1514
|
+
shouldFill: true,
|
|
1515
|
+
backgroundColor: 'transparent',
|
|
1516
|
+
},
|
|
1517
|
+
wrapperOptions: {
|
|
1518
|
+
flexGrow: 1,
|
|
1519
|
+
border: false,
|
|
1520
|
+
shouldFill: true,
|
|
1521
|
+
backgroundColor: 'transparent',
|
|
1522
|
+
flexDirection: 'column',
|
|
1523
|
+
},
|
|
1524
|
+
contentOptions: {
|
|
1525
|
+
flexDirection: 'column',
|
|
1526
|
+
gap: 0,
|
|
1527
|
+
shouldFill: true,
|
|
1528
|
+
justifyContent: 'flex-end',
|
|
1529
|
+
backgroundColor: 'transparent',
|
|
1530
|
+
paddingLeft: 1,
|
|
1531
|
+
paddingRight: 2,
|
|
1532
|
+
},
|
|
1533
|
+
}}
|
|
1534
|
+
>
|
|
1535
|
+
<TopBanner gitRoot={gitRoot} onSwitchToGitRoot={onSwitchToGitRoot} />
|
|
1536
|
+
|
|
1537
|
+
<box
|
|
1538
|
+
ref={headerRef as React.Ref<BoxRenderable>}
|
|
1539
|
+
style={{ flexDirection: 'column' }}
|
|
1540
|
+
>
|
|
1541
|
+
<ChatHeader projectRoot={getProjectRoot()} animationEnabled={true} />
|
|
1542
|
+
</box>
|
|
1543
|
+
{IS_ANVIL && (
|
|
1544
|
+
<AnvilActiveSessionSummary session={anvilSession} />
|
|
1545
|
+
)}
|
|
1546
|
+
{hiddenMessageCount > 0 && (
|
|
1547
|
+
<LoadPreviousButton
|
|
1548
|
+
hiddenCount={hiddenMessageCount}
|
|
1549
|
+
onLoadMore={handleLoadPreviousMessages}
|
|
1550
|
+
/>
|
|
1551
|
+
)}
|
|
1552
|
+
{visibleTopLevelMessages.map((message, idx) => (
|
|
1553
|
+
<MessageWithAgents
|
|
1554
|
+
key={message.id}
|
|
1555
|
+
message={message}
|
|
1556
|
+
depth={0}
|
|
1557
|
+
isLastMessage={idx === visibleTopLevelMessages.length - 1}
|
|
1558
|
+
availableWidth={messageAvailableWidth}
|
|
1559
|
+
/>
|
|
1560
|
+
))}
|
|
1561
|
+
{/* Pending bash messages as ghost messages (only show those not already in history) */}
|
|
1562
|
+
{pendingBashMessages
|
|
1563
|
+
.filter((msg) => !msg.addedToHistory)
|
|
1564
|
+
.map((msg) => (
|
|
1565
|
+
<PendingBashMessage key={`pending-bash-${msg.id}`} message={msg} />
|
|
1566
|
+
))}
|
|
1567
|
+
</scrollbox>
|
|
1568
|
+
|
|
1569
|
+
<box
|
|
1570
|
+
style={{
|
|
1571
|
+
flexShrink: 0,
|
|
1572
|
+
backgroundColor: 'transparent',
|
|
1573
|
+
}}
|
|
1574
|
+
>
|
|
1575
|
+
{showOnboardingPrompts && !reviewMode && !isAnvilSessionOver && (
|
|
1576
|
+
<SuggestedPrompts
|
|
1577
|
+
onSelect={handleSelectSuggestedPrompt}
|
|
1578
|
+
maxItems={isCompactHeight ? 2 : undefined}
|
|
1579
|
+
/>
|
|
1580
|
+
)}
|
|
1581
|
+
|
|
1582
|
+
{shouldShowStatusLine && (
|
|
1583
|
+
<StatusBar
|
|
1584
|
+
timerStartTime={timerStartTime}
|
|
1585
|
+
isAtBottom={isAtBottom}
|
|
1586
|
+
scrollToLatest={scrollToLatest}
|
|
1587
|
+
statusIndicatorState={statusIndicatorState}
|
|
1588
|
+
onStop={chatKeyboardHandlers.onInterruptStream}
|
|
1589
|
+
onEndSession={() => {
|
|
1590
|
+
setMessages((prev) => [
|
|
1591
|
+
...prev,
|
|
1592
|
+
getSystemMessage(END_SESSION_MESSAGE),
|
|
1593
|
+
])
|
|
1594
|
+
returnToAnvilLanding({ resetChat: true }).catch(() => {})
|
|
1595
|
+
}}
|
|
1596
|
+
anvilSession={anvilSession}
|
|
1597
|
+
sessionCreditsUsed={sessionCreditsUsed}
|
|
1598
|
+
contextTokensUsed={contextTokensUsed}
|
|
1599
|
+
/>
|
|
1600
|
+
)}
|
|
1601
|
+
|
|
1602
|
+
{ads?.[0] && showInlineAds && (
|
|
1603
|
+
<SingleAdBanner
|
|
1604
|
+
ad={ads[0]}
|
|
1605
|
+
onClick={recordClick}
|
|
1606
|
+
onImpression={recordImpression}
|
|
1607
|
+
/>
|
|
1608
|
+
)}
|
|
1609
|
+
|
|
1610
|
+
{reviewMode ? (
|
|
1611
|
+
// Review and ask_user take precedence over the session-ended banner:
|
|
1612
|
+
// during the grace window the agent may still be asking to run tools
|
|
1613
|
+
// or asking the user a question, and those approvals/answers must be
|
|
1614
|
+
// reachable for the run to finish — otherwise the agent hangs
|
|
1615
|
+
// waiting for input that can never be given.
|
|
1616
|
+
<ReviewScreen
|
|
1617
|
+
onSelectOption={handleReviewOptionSelect}
|
|
1618
|
+
onCustom={handleReviewCustom}
|
|
1619
|
+
onCancel={handleCloseReviewScreen}
|
|
1620
|
+
/>
|
|
1621
|
+
) : queuePanelOpen && !askUserState ? (
|
|
1622
|
+
<QueuePanel
|
|
1623
|
+
queuedMessages={queuedMessages}
|
|
1624
|
+
onEdit={editQueuedMessage}
|
|
1625
|
+
onDelete={removeQueuedMessage}
|
|
1626
|
+
onMove={moveQueuedMessage}
|
|
1627
|
+
onClose={handleCloseQueuePanel}
|
|
1628
|
+
width={separatorWidth}
|
|
1629
|
+
maxVisibleRows={isCompactHeight ? 4 : 8}
|
|
1630
|
+
/>
|
|
1631
|
+
) : isAnvilSessionOver && !askUserState ? (
|
|
1632
|
+
<SessionEndedBanner
|
|
1633
|
+
isStreaming={isStreaming || isWaitingForResponse}
|
|
1634
|
+
/>
|
|
1635
|
+
) : (
|
|
1636
|
+
<>
|
|
1637
|
+
<ChatInputBar
|
|
1638
|
+
inputValue={inputValue}
|
|
1639
|
+
cursorPosition={cursorPosition}
|
|
1640
|
+
setInputValue={setInputValue}
|
|
1641
|
+
inputFocused={inputFocused}
|
|
1642
|
+
inputRef={inputRef}
|
|
1643
|
+
inputPlaceholder={inputPlaceholder}
|
|
1644
|
+
lastEditDueToNav={lastEditDueToNav}
|
|
1645
|
+
agentMode={agentMode}
|
|
1646
|
+
toggleAgentMode={toggleAgentMode}
|
|
1647
|
+
setAgentMode={setAgentMode}
|
|
1648
|
+
hasSlashSuggestions={hasSlashSuggestions}
|
|
1649
|
+
hasMentionSuggestions={hasMentionSuggestions}
|
|
1650
|
+
hasSuggestionMenu={hasSuggestionMenu}
|
|
1651
|
+
slashSuggestionItems={slashSuggestionItems}
|
|
1652
|
+
agentSuggestionItems={agentSuggestionItems}
|
|
1653
|
+
fileSuggestionItems={fileSuggestionItems}
|
|
1654
|
+
slashSelectedIndex={slashSelectedIndex}
|
|
1655
|
+
agentSelectedIndex={agentSelectedIndex}
|
|
1656
|
+
onSlashItemClick={handleSlashItemClick}
|
|
1657
|
+
onMentionItemClick={handleMentionItemClick}
|
|
1658
|
+
theme={theme}
|
|
1659
|
+
terminalHeight={terminalHeight}
|
|
1660
|
+
separatorWidth={separatorWidth}
|
|
1661
|
+
shouldCenterInputVertically={shouldCenterInputVertically}
|
|
1662
|
+
inputBoxTitle={inputBoxTitle}
|
|
1663
|
+
onQueuePreviewClick={openQueuePanel}
|
|
1664
|
+
isCompactHeight={isCompactHeight}
|
|
1665
|
+
isNarrowWidth={isNarrowWidth}
|
|
1666
|
+
feedbackMode={feedbackMode}
|
|
1667
|
+
handleExitFeedback={handleExitFeedback}
|
|
1668
|
+
publishMode={publishMode}
|
|
1669
|
+
handleExitPublish={handleExitPublish}
|
|
1670
|
+
handlePublish={handlePublish}
|
|
1671
|
+
handleSubmit={handleSubmit}
|
|
1672
|
+
onPaste={createPasteHandler({
|
|
1673
|
+
text: inputValue,
|
|
1674
|
+
cursorPosition,
|
|
1675
|
+
onChange: setInputValue,
|
|
1676
|
+
onPasteImage: chatKeyboardHandlers.onPasteImage,
|
|
1677
|
+
onPasteImagePath: chatKeyboardHandlers.onPasteImagePath,
|
|
1678
|
+
onPasteFilePath: chatKeyboardHandlers.onPasteFilePath,
|
|
1679
|
+
onPasteLongText: (pastedText) => {
|
|
1680
|
+
const id = crypto.randomUUID()
|
|
1681
|
+
const preview = pastedText.slice(0, 100).replace(/\n/g, ' ')
|
|
1682
|
+
useChatStore.getState().addPendingTextAttachment({
|
|
1683
|
+
id,
|
|
1684
|
+
content: pastedText,
|
|
1685
|
+
preview,
|
|
1686
|
+
charCount: pastedText.length,
|
|
1687
|
+
})
|
|
1688
|
+
// Show temporary status message
|
|
1689
|
+
showClipboardMessage(
|
|
1690
|
+
`📋 Pasted text (${pastedText.length.toLocaleString()} chars)`,
|
|
1691
|
+
{ durationMs: 5000 },
|
|
1692
|
+
)
|
|
1693
|
+
},
|
|
1694
|
+
cwd: getProjectRoot() ?? process.cwd(),
|
|
1695
|
+
})}
|
|
1696
|
+
onInterruptStream={chatKeyboardHandlers.onInterruptStream}
|
|
1697
|
+
/>
|
|
1698
|
+
</>
|
|
1699
|
+
)}
|
|
1700
|
+
</box>
|
|
1701
|
+
</box>
|
|
1702
|
+
)
|
|
1703
|
+
}
|