@alumbwe/anvil 1.0.20 → 1.0.21
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 +6 -2
- 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/state/chat-store.ts
CHANGED
|
@@ -1,544 +1,553 @@
|
|
|
1
|
-
import { castDraft, enableMapSet } from 'immer'
|
|
2
|
-
import { create } from 'zustand'
|
|
3
|
-
import { immer } from 'zustand/middleware/immer'
|
|
4
|
-
|
|
5
|
-
import { AGENT_MODES, IS_ANVIL } from '../utils/constants'
|
|
6
|
-
import { clamp } from '../utils/math'
|
|
7
|
-
import { loadModePreference, saveModePreference } from '../utils/settings'
|
|
8
|
-
|
|
9
|
-
import type { ChatMessage, ContentBlock } from '../types/chat'
|
|
10
|
-
import type { AgentMode } from '../utils/constants'
|
|
11
|
-
import type { InputMode } from '../utils/input-modes'
|
|
12
|
-
import type { RunState } from '@anvil/sdk'
|
|
13
|
-
|
|
14
|
-
// Import types from the types/store module to avoid circular dependencies
|
|
15
|
-
import type {
|
|
16
|
-
TopBannerType,
|
|
17
|
-
InputValue,
|
|
18
|
-
AskUserQuestion,
|
|
19
|
-
AnswerState,
|
|
20
|
-
AskUserState,
|
|
21
|
-
PendingImageStatus,
|
|
22
|
-
PendingImageAttachment,
|
|
23
|
-
PendingTextAttachment,
|
|
24
|
-
PendingFileAttachment,
|
|
25
|
-
PendingAttachment,
|
|
26
|
-
PendingImage,
|
|
27
|
-
PendingBashMessage,
|
|
28
|
-
SuggestedFollowup,
|
|
29
|
-
SuggestedFollowupsState,
|
|
30
|
-
ClickedFollowupsMap,
|
|
31
|
-
} from '../types/store'
|
|
32
|
-
|
|
33
|
-
// Re-export types from the types/store module to maintain backwards compatibility
|
|
34
|
-
export type {
|
|
35
|
-
TopBannerType,
|
|
36
|
-
InputValue,
|
|
37
|
-
AskUserQuestion,
|
|
38
|
-
AnswerState,
|
|
39
|
-
AskUserState,
|
|
40
|
-
PendingImageStatus,
|
|
41
|
-
PendingImageAttachment,
|
|
42
|
-
PendingTextAttachment,
|
|
43
|
-
PendingFileAttachment,
|
|
44
|
-
PendingAttachment,
|
|
45
|
-
PendingImage,
|
|
46
|
-
PendingBashMessage,
|
|
47
|
-
SuggestedFollowup,
|
|
48
|
-
SuggestedFollowupsState,
|
|
49
|
-
ClickedFollowupsMap,
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Drafts Sets (streamingAgents, activeSubagents) through immer; see
|
|
53
|
-
// message-block-store for why the store enables the plugin itself.
|
|
54
|
-
enableMapSet()
|
|
55
|
-
|
|
56
|
-
export type ChatStoreState = {
|
|
57
|
-
/** Unique ID for this chat session, regenerated on /new */
|
|
58
|
-
chatSessionId: string
|
|
59
|
-
messages: ChatMessage[]
|
|
60
|
-
streamingAgents: Set<string>
|
|
61
|
-
focusedAgentId: string | null
|
|
62
|
-
inputValue: string
|
|
63
|
-
cursorPosition: number
|
|
64
|
-
lastEditDueToNav: boolean
|
|
65
|
-
inputFocused: boolean
|
|
66
|
-
isFocusSupported: boolean
|
|
67
|
-
activeSubagents: Set<string>
|
|
68
|
-
isChainInProgress: boolean
|
|
69
|
-
slashSelectedIndex: number
|
|
70
|
-
agentSelectedIndex: number
|
|
71
|
-
agentMode: AgentMode
|
|
72
|
-
hasReceivedPlanResponse: boolean
|
|
73
|
-
lastMessageMode: AgentMode | null
|
|
74
|
-
sessionCreditsUsed: number
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
state.
|
|
343
|
-
}),
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
set((state) => {
|
|
347
|
-
state.isRetrying =
|
|
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
|
-
|
|
382
|
-
|
|
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
|
-
set((state) => {
|
|
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
|
-
state.
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
state.
|
|
523
|
-
state.
|
|
524
|
-
state.
|
|
525
|
-
state.
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
state.
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
state.
|
|
534
|
-
state.
|
|
535
|
-
state.
|
|
536
|
-
state.
|
|
537
|
-
state.
|
|
538
|
-
state.
|
|
539
|
-
state.
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
1
|
+
import { castDraft, enableMapSet } from 'immer'
|
|
2
|
+
import { create } from 'zustand'
|
|
3
|
+
import { immer } from 'zustand/middleware/immer'
|
|
4
|
+
|
|
5
|
+
import { AGENT_MODES, IS_ANVIL } from '../utils/constants'
|
|
6
|
+
import { clamp } from '../utils/math'
|
|
7
|
+
import { loadModePreference, saveModePreference } from '../utils/settings'
|
|
8
|
+
|
|
9
|
+
import type { ChatMessage, ContentBlock } from '../types/chat'
|
|
10
|
+
import type { AgentMode } from '../utils/constants'
|
|
11
|
+
import type { InputMode } from '../utils/input-modes'
|
|
12
|
+
import type { RunState } from '@anvil/sdk'
|
|
13
|
+
|
|
14
|
+
// Import types from the types/store module to avoid circular dependencies
|
|
15
|
+
import type {
|
|
16
|
+
TopBannerType,
|
|
17
|
+
InputValue,
|
|
18
|
+
AskUserQuestion,
|
|
19
|
+
AnswerState,
|
|
20
|
+
AskUserState,
|
|
21
|
+
PendingImageStatus,
|
|
22
|
+
PendingImageAttachment,
|
|
23
|
+
PendingTextAttachment,
|
|
24
|
+
PendingFileAttachment,
|
|
25
|
+
PendingAttachment,
|
|
26
|
+
PendingImage,
|
|
27
|
+
PendingBashMessage,
|
|
28
|
+
SuggestedFollowup,
|
|
29
|
+
SuggestedFollowupsState,
|
|
30
|
+
ClickedFollowupsMap,
|
|
31
|
+
} from '../types/store'
|
|
32
|
+
|
|
33
|
+
// Re-export types from the types/store module to maintain backwards compatibility
|
|
34
|
+
export type {
|
|
35
|
+
TopBannerType,
|
|
36
|
+
InputValue,
|
|
37
|
+
AskUserQuestion,
|
|
38
|
+
AnswerState,
|
|
39
|
+
AskUserState,
|
|
40
|
+
PendingImageStatus,
|
|
41
|
+
PendingImageAttachment,
|
|
42
|
+
PendingTextAttachment,
|
|
43
|
+
PendingFileAttachment,
|
|
44
|
+
PendingAttachment,
|
|
45
|
+
PendingImage,
|
|
46
|
+
PendingBashMessage,
|
|
47
|
+
SuggestedFollowup,
|
|
48
|
+
SuggestedFollowupsState,
|
|
49
|
+
ClickedFollowupsMap,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Drafts Sets (streamingAgents, activeSubagents) through immer; see
|
|
53
|
+
// message-block-store for why the store enables the plugin itself.
|
|
54
|
+
enableMapSet()
|
|
55
|
+
|
|
56
|
+
export type ChatStoreState = {
|
|
57
|
+
/** Unique ID for this chat session, regenerated on /new */
|
|
58
|
+
chatSessionId: string
|
|
59
|
+
messages: ChatMessage[]
|
|
60
|
+
streamingAgents: Set<string>
|
|
61
|
+
focusedAgentId: string | null
|
|
62
|
+
inputValue: string
|
|
63
|
+
cursorPosition: number
|
|
64
|
+
lastEditDueToNav: boolean
|
|
65
|
+
inputFocused: boolean
|
|
66
|
+
isFocusSupported: boolean
|
|
67
|
+
activeSubagents: Set<string>
|
|
68
|
+
isChainInProgress: boolean
|
|
69
|
+
slashSelectedIndex: number
|
|
70
|
+
agentSelectedIndex: number
|
|
71
|
+
agentMode: AgentMode
|
|
72
|
+
hasReceivedPlanResponse: boolean
|
|
73
|
+
lastMessageMode: AgentMode | null
|
|
74
|
+
sessionCreditsUsed: number
|
|
75
|
+
contextTokensUsed: number
|
|
76
|
+
runState: RunState | null
|
|
77
|
+
/** The currently active top banner, or null if none */
|
|
78
|
+
activeTopBanner: TopBannerType
|
|
79
|
+
inputMode: InputMode
|
|
80
|
+
isRetrying: boolean
|
|
81
|
+
/** True while the current retry wait is a server capacity deferral (free
|
|
82
|
+
* mode shed under high demand) rather than a stream recovery — the status
|
|
83
|
+
* bar says "high demand" instead of a generic "retrying". Cleared with
|
|
84
|
+
* isRetrying. */
|
|
85
|
+
isCapacityWait: boolean
|
|
86
|
+
askUserState: AskUserState
|
|
87
|
+
pendingAttachments: PendingAttachment[]
|
|
88
|
+
pendingBashMessages: PendingBashMessage[]
|
|
89
|
+
suggestedFollowups: SuggestedFollowupsState | null
|
|
90
|
+
/** Persisted clicked indices per toolCallId */
|
|
91
|
+
clickedFollowupsMap: ClickedFollowupsMap
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const findLatestFollowupInBlocks = (
|
|
95
|
+
blocks: ContentBlock[] | undefined,
|
|
96
|
+
): string | null => {
|
|
97
|
+
if (!blocks) return null
|
|
98
|
+
|
|
99
|
+
for (let i = blocks.length - 1; i >= 0; i--) {
|
|
100
|
+
const block = blocks[i]
|
|
101
|
+
if (block.type === 'tool' && block.toolName === 'suggest_followups') {
|
|
102
|
+
return block.toolCallId
|
|
103
|
+
}
|
|
104
|
+
if (block.type === 'agent') {
|
|
105
|
+
const nested = findLatestFollowupInBlocks(block.blocks)
|
|
106
|
+
if (nested) return nested
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return null
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const getLatestFollowupToolCallId = (
|
|
114
|
+
messages: ChatMessage[],
|
|
115
|
+
): string | null => {
|
|
116
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
117
|
+
const latest = findLatestFollowupInBlocks(messages[i]?.blocks)
|
|
118
|
+
if (latest) return latest
|
|
119
|
+
}
|
|
120
|
+
return null
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
type ChatStoreActions = {
|
|
124
|
+
setMessages: (
|
|
125
|
+
value: ChatMessage[] | ((prev: ChatMessage[]) => ChatMessage[]),
|
|
126
|
+
) => void
|
|
127
|
+
setStreamingAgents: (
|
|
128
|
+
value: Set<string> | ((prev: Set<string>) => Set<string>),
|
|
129
|
+
) => void
|
|
130
|
+
setFocusedAgentId: (
|
|
131
|
+
value: string | null | ((prev: string | null) => string | null),
|
|
132
|
+
) => void
|
|
133
|
+
setInputValue: (
|
|
134
|
+
value: InputValue | ((prev: InputValue) => InputValue),
|
|
135
|
+
) => void
|
|
136
|
+
setInputFocused: (focused: boolean) => void
|
|
137
|
+
setIsFocusSupported: (supported: boolean) => void
|
|
138
|
+
setActiveSubagents: (
|
|
139
|
+
value: Set<string> | ((prev: Set<string>) => Set<string>),
|
|
140
|
+
) => void
|
|
141
|
+
setIsChainInProgress: (active: boolean) => void
|
|
142
|
+
setSlashSelectedIndex: (value: number | ((prev: number) => number)) => void
|
|
143
|
+
setAgentSelectedIndex: (value: number | ((prev: number) => number)) => void
|
|
144
|
+
setAgentMode: (mode: AgentMode) => void
|
|
145
|
+
toggleAgentMode: () => void
|
|
146
|
+
setHasReceivedPlanResponse: (value: boolean) => void
|
|
147
|
+
setLastMessageMode: (mode: AgentMode | null) => void
|
|
148
|
+
addSessionCredits: (credits: number) => void
|
|
149
|
+
setContextTokensUsed: (tokens: number) => void
|
|
150
|
+
setRunState: (runState: RunState | null) => void
|
|
151
|
+
setActiveTopBanner: (banner: TopBannerType) => void
|
|
152
|
+
closeTopBanner: () => void
|
|
153
|
+
setInputMode: (mode: InputMode) => void
|
|
154
|
+
setIsRetrying: (retrying: boolean) => void
|
|
155
|
+
/** Mark the current wait as a free-mode capacity deferral (implies
|
|
156
|
+
* isRetrying). Cleared by setIsRetrying(false). */
|
|
157
|
+
noteCapacityDeferral: () => void
|
|
158
|
+
setAskUserState: (state: AskUserState) => void
|
|
159
|
+
updateAskUserAnswer: (questionIndex: number, optionIndex: number) => void
|
|
160
|
+
updateAskUserOtherText: (questionIndex: number, text: string) => void
|
|
161
|
+
addPendingAttachment: (attachment: PendingAttachment) => void
|
|
162
|
+
removePendingAttachment: (id: string) => void
|
|
163
|
+
clearPendingAttachments: () => void
|
|
164
|
+
// Convenience aliases for backwards compatibility
|
|
165
|
+
addPendingImage: (image: Omit<PendingImageAttachment, 'kind'>) => void
|
|
166
|
+
removePendingImage: (path: string) => void
|
|
167
|
+
clearPendingImages: () => void
|
|
168
|
+
addPendingTextAttachment: (attachment: Omit<PendingTextAttachment, 'kind'>) => void
|
|
169
|
+
removePendingTextAttachment: (id: string) => void
|
|
170
|
+
clearPendingTextAttachments: () => void
|
|
171
|
+
addPendingFileAttachment: (attachment: Omit<PendingFileAttachment, 'kind'>) => void
|
|
172
|
+
addPendingBashMessage: (message: PendingBashMessage) => void
|
|
173
|
+
updatePendingBashMessage: (
|
|
174
|
+
id: string,
|
|
175
|
+
updates: Partial<PendingBashMessage>,
|
|
176
|
+
) => void
|
|
177
|
+
removePendingBashMessage: (id: string) => void
|
|
178
|
+
clearPendingBashMessages: () => void
|
|
179
|
+
setSuggestedFollowups: (state: SuggestedFollowupsState | null) => void
|
|
180
|
+
markFollowupClicked: (toolCallId: string, index: number) => void
|
|
181
|
+
reset: () => void
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
type ChatStore = ChatStoreState & ChatStoreActions
|
|
185
|
+
|
|
186
|
+
const generateSessionId = () => crypto.randomUUID()
|
|
187
|
+
|
|
188
|
+
const initialState: ChatStoreState = {
|
|
189
|
+
chatSessionId: generateSessionId(),
|
|
190
|
+
messages: [],
|
|
191
|
+
streamingAgents: new Set<string>(),
|
|
192
|
+
focusedAgentId: null,
|
|
193
|
+
inputValue: '',
|
|
194
|
+
cursorPosition: 0,
|
|
195
|
+
lastEditDueToNav: false,
|
|
196
|
+
inputFocused: true, // Cursor visible by default
|
|
197
|
+
isFocusSupported: false, // Don't blink until terminal support is detected
|
|
198
|
+
activeSubagents: new Set<string>(),
|
|
199
|
+
isChainInProgress: false,
|
|
200
|
+
slashSelectedIndex: 0,
|
|
201
|
+
agentSelectedIndex: 0,
|
|
202
|
+
agentMode: IS_ANVIL ? ('LITE' as const) : loadModePreference(),
|
|
203
|
+
hasReceivedPlanResponse: false,
|
|
204
|
+
lastMessageMode: null,
|
|
205
|
+
sessionCreditsUsed: 0,
|
|
206
|
+
contextTokensUsed: 0,
|
|
207
|
+
runState: null,
|
|
208
|
+
activeTopBanner: null,
|
|
209
|
+
inputMode: 'default' as InputMode,
|
|
210
|
+
isRetrying: false,
|
|
211
|
+
isCapacityWait: false,
|
|
212
|
+
askUserState: null,
|
|
213
|
+
pendingAttachments: [],
|
|
214
|
+
pendingBashMessages: [],
|
|
215
|
+
suggestedFollowups: null,
|
|
216
|
+
clickedFollowupsMap: new Map<string, Set<number>>(),
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export const useChatStore = create<ChatStore>()(
|
|
220
|
+
immer((set) => ({
|
|
221
|
+
...initialState,
|
|
222
|
+
|
|
223
|
+
setMessages: (value) =>
|
|
224
|
+
set((state) => {
|
|
225
|
+
state.messages =
|
|
226
|
+
typeof value === 'function' ? value(state.messages) : value
|
|
227
|
+
}),
|
|
228
|
+
|
|
229
|
+
setStreamingAgents: (value) =>
|
|
230
|
+
set((state) => {
|
|
231
|
+
state.streamingAgents =
|
|
232
|
+
typeof value === 'function' ? value(state.streamingAgents) : value
|
|
233
|
+
}),
|
|
234
|
+
|
|
235
|
+
setFocusedAgentId: (value) =>
|
|
236
|
+
set((state) => {
|
|
237
|
+
state.focusedAgentId =
|
|
238
|
+
typeof value === 'function' ? value(state.focusedAgentId) : value
|
|
239
|
+
}),
|
|
240
|
+
|
|
241
|
+
setInputValue: (value) =>
|
|
242
|
+
set((state) => {
|
|
243
|
+
const { text, cursorPosition, lastEditDueToNav } =
|
|
244
|
+
typeof value === 'function'
|
|
245
|
+
? value({
|
|
246
|
+
text: state.inputValue,
|
|
247
|
+
cursorPosition: state.cursorPosition,
|
|
248
|
+
lastEditDueToNav: state.lastEditDueToNav,
|
|
249
|
+
})
|
|
250
|
+
: value
|
|
251
|
+
state.inputValue = text
|
|
252
|
+
state.cursorPosition = clamp(cursorPosition, 0, text.length)
|
|
253
|
+
state.lastEditDueToNav = lastEditDueToNav
|
|
254
|
+
}),
|
|
255
|
+
|
|
256
|
+
setInputFocused: (focused) =>
|
|
257
|
+
set((state) => {
|
|
258
|
+
state.inputFocused = focused
|
|
259
|
+
}),
|
|
260
|
+
|
|
261
|
+
setIsFocusSupported: (supported) =>
|
|
262
|
+
set((state) => {
|
|
263
|
+
state.isFocusSupported = supported
|
|
264
|
+
}),
|
|
265
|
+
|
|
266
|
+
setActiveSubagents: (value) =>
|
|
267
|
+
set((state) => {
|
|
268
|
+
state.activeSubagents =
|
|
269
|
+
typeof value === 'function' ? value(state.activeSubagents) : value
|
|
270
|
+
}),
|
|
271
|
+
|
|
272
|
+
setIsChainInProgress: (active) =>
|
|
273
|
+
set((state) => {
|
|
274
|
+
state.isChainInProgress = active
|
|
275
|
+
}),
|
|
276
|
+
|
|
277
|
+
setSlashSelectedIndex: (value) =>
|
|
278
|
+
set((state) => {
|
|
279
|
+
state.slashSelectedIndex =
|
|
280
|
+
typeof value === 'function' ? value(state.slashSelectedIndex) : value
|
|
281
|
+
}),
|
|
282
|
+
|
|
283
|
+
setAgentSelectedIndex: (value) =>
|
|
284
|
+
set((state) => {
|
|
285
|
+
state.agentSelectedIndex =
|
|
286
|
+
typeof value === 'function' ? value(state.agentSelectedIndex) : value
|
|
287
|
+
}),
|
|
288
|
+
|
|
289
|
+
setAgentMode: (mode) =>
|
|
290
|
+
set((state) => {
|
|
291
|
+
if (IS_ANVIL) return
|
|
292
|
+
state.agentMode = mode
|
|
293
|
+
saveModePreference(mode)
|
|
294
|
+
}),
|
|
295
|
+
|
|
296
|
+
toggleAgentMode: () =>
|
|
297
|
+
set((state) => {
|
|
298
|
+
if (IS_ANVIL) return
|
|
299
|
+
const currentIndex = AGENT_MODES.indexOf(state.agentMode)
|
|
300
|
+
const nextIndex = (currentIndex + 1) % AGENT_MODES.length
|
|
301
|
+
state.agentMode = AGENT_MODES[nextIndex]
|
|
302
|
+
saveModePreference(state.agentMode)
|
|
303
|
+
}),
|
|
304
|
+
|
|
305
|
+
setHasReceivedPlanResponse: (value) =>
|
|
306
|
+
set((state) => {
|
|
307
|
+
state.hasReceivedPlanResponse = value
|
|
308
|
+
}),
|
|
309
|
+
|
|
310
|
+
setLastMessageMode: (mode) =>
|
|
311
|
+
set((state) => {
|
|
312
|
+
state.lastMessageMode = mode
|
|
313
|
+
}),
|
|
314
|
+
|
|
315
|
+
addSessionCredits: (credits) =>
|
|
316
|
+
set((state) => {
|
|
317
|
+
state.sessionCreditsUsed += credits
|
|
318
|
+
}),
|
|
319
|
+
|
|
320
|
+
setContextTokensUsed: (tokens) =>
|
|
321
|
+
set((state) => {
|
|
322
|
+
state.contextTokensUsed = tokens
|
|
323
|
+
}),
|
|
324
|
+
|
|
325
|
+
setRunState: (runState) =>
|
|
326
|
+
set((state) => {
|
|
327
|
+
state.runState = runState ? castDraft(runState) : null
|
|
328
|
+
}),
|
|
329
|
+
|
|
330
|
+
setActiveTopBanner: (banner) =>
|
|
331
|
+
set((state) => {
|
|
332
|
+
state.activeTopBanner = banner
|
|
333
|
+
}),
|
|
334
|
+
|
|
335
|
+
closeTopBanner: () =>
|
|
336
|
+
set((state) => {
|
|
337
|
+
state.activeTopBanner = null
|
|
338
|
+
}),
|
|
339
|
+
|
|
340
|
+
setInputMode: (mode) =>
|
|
341
|
+
set((state) => {
|
|
342
|
+
state.inputMode = mode
|
|
343
|
+
}),
|
|
344
|
+
|
|
345
|
+
setIsRetrying: (retrying) =>
|
|
346
|
+
set((state) => {
|
|
347
|
+
state.isRetrying = retrying
|
|
348
|
+
// Any transition (fresh generic retry, or the wait ending) supersedes
|
|
349
|
+
// a capacity flavor; only noteCapacityDeferral re-establishes it.
|
|
350
|
+
state.isCapacityWait = false
|
|
351
|
+
}),
|
|
352
|
+
|
|
353
|
+
noteCapacityDeferral: () =>
|
|
354
|
+
set((state) => {
|
|
355
|
+
state.isRetrying = true
|
|
356
|
+
state.isCapacityWait = true
|
|
357
|
+
}),
|
|
358
|
+
|
|
359
|
+
setAskUserState: (askUserState) =>
|
|
360
|
+
set((state) => {
|
|
361
|
+
state.askUserState = askUserState
|
|
362
|
+
}),
|
|
363
|
+
|
|
364
|
+
addPendingAttachment: (attachment) =>
|
|
365
|
+
set((state) => {
|
|
366
|
+
// Don't add duplicates — use path for image/file, id for text
|
|
367
|
+
const id = attachment.kind === 'text' ? attachment.id : attachment.path
|
|
368
|
+
const isDuplicate = state.pendingAttachments.some((a) =>
|
|
369
|
+
a.kind === 'text' ? a.id === id : a.path === id,
|
|
370
|
+
)
|
|
371
|
+
if (!isDuplicate) {
|
|
372
|
+
state.pendingAttachments.push(attachment)
|
|
373
|
+
}
|
|
374
|
+
}),
|
|
375
|
+
|
|
376
|
+
removePendingAttachment: (id) =>
|
|
377
|
+
set((state) => {
|
|
378
|
+
state.pendingAttachments = state.pendingAttachments.filter((a) =>
|
|
379
|
+
a.kind === 'text' ? a.id !== id : a.path !== id,
|
|
380
|
+
)
|
|
381
|
+
}),
|
|
382
|
+
|
|
383
|
+
clearPendingAttachments: () =>
|
|
384
|
+
set((state) => {
|
|
385
|
+
state.pendingAttachments = []
|
|
386
|
+
}),
|
|
387
|
+
|
|
388
|
+
// Backwards-compatible convenience methods that delegate to canonical functions
|
|
389
|
+
addPendingImage: (image) => {
|
|
390
|
+
useChatStore.getState().addPendingAttachment({ ...image, kind: 'image' })
|
|
391
|
+
},
|
|
392
|
+
|
|
393
|
+
removePendingImage: (path) => {
|
|
394
|
+
// Clear any auto-remove timer to prevent memory leaks
|
|
395
|
+
// Import dynamically to avoid circular dependency
|
|
396
|
+
import('../utils/pending-attachments')
|
|
397
|
+
.then(({ clearErrorImageTimer }) => {
|
|
398
|
+
clearErrorImageTimer(path)
|
|
399
|
+
})
|
|
400
|
+
.catch(() => {
|
|
401
|
+
// Silently ignore import errors - timer cleanup is best-effort
|
|
402
|
+
})
|
|
403
|
+
useChatStore.getState().removePendingAttachment(path)
|
|
404
|
+
},
|
|
405
|
+
|
|
406
|
+
clearPendingImages: () =>
|
|
407
|
+
set((state) => {
|
|
408
|
+
state.pendingAttachments = state.pendingAttachments.filter(
|
|
409
|
+
(a) => a.kind !== 'image',
|
|
410
|
+
)
|
|
411
|
+
}),
|
|
412
|
+
|
|
413
|
+
addPendingTextAttachment: (attachment) => {
|
|
414
|
+
useChatStore.getState().addPendingAttachment({ ...attachment, kind: 'text' })
|
|
415
|
+
},
|
|
416
|
+
|
|
417
|
+
removePendingTextAttachment: (id) => {
|
|
418
|
+
useChatStore.getState().removePendingAttachment(id)
|
|
419
|
+
},
|
|
420
|
+
|
|
421
|
+
clearPendingTextAttachments: () =>
|
|
422
|
+
set((state) => {
|
|
423
|
+
state.pendingAttachments = state.pendingAttachments.filter(
|
|
424
|
+
(a) => a.kind !== 'text',
|
|
425
|
+
)
|
|
426
|
+
}),
|
|
427
|
+
|
|
428
|
+
addPendingFileAttachment: (attachment) => {
|
|
429
|
+
useChatStore.getState().addPendingAttachment({ ...attachment, kind: 'file' })
|
|
430
|
+
},
|
|
431
|
+
|
|
432
|
+
updateAskUserAnswer: (questionIndex, optionIndex) =>
|
|
433
|
+
set((state) => {
|
|
434
|
+
if (!state.askUserState) return
|
|
435
|
+
|
|
436
|
+
const question = state.askUserState.questions[questionIndex]
|
|
437
|
+
const currentAnswer = state.askUserState.selectedAnswers[questionIndex]
|
|
438
|
+
|
|
439
|
+
if (question?.multiSelect) {
|
|
440
|
+
// Multi-select: toggle option in array
|
|
441
|
+
const selected = Array.isArray(currentAnswer) ? currentAnswer : []
|
|
442
|
+
const newSelected = selected.includes(optionIndex)
|
|
443
|
+
? selected.filter((i) => i !== optionIndex) // Remove if already selected
|
|
444
|
+
: [...selected, optionIndex] // Add if not selected
|
|
445
|
+
|
|
446
|
+
state.askUserState.selectedAnswers[questionIndex] = newSelected
|
|
447
|
+
} else {
|
|
448
|
+
// Single-select: set option index
|
|
449
|
+
state.askUserState.selectedAnswers[questionIndex] = optionIndex
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// Clear other text when any option is selected (mutually exclusive)
|
|
453
|
+
state.askUserState.otherTexts[questionIndex] = ''
|
|
454
|
+
}),
|
|
455
|
+
|
|
456
|
+
updateAskUserOtherText: (questionIndex, text) =>
|
|
457
|
+
set((state) => {
|
|
458
|
+
if (!state.askUserState) return
|
|
459
|
+
|
|
460
|
+
state.askUserState.otherTexts[questionIndex] = text
|
|
461
|
+
|
|
462
|
+
// Clear selected option(s) when text is entered (mutually exclusive)
|
|
463
|
+
if (text) {
|
|
464
|
+
const question = state.askUserState.questions[questionIndex]
|
|
465
|
+
if (question?.multiSelect) {
|
|
466
|
+
state.askUserState.selectedAnswers[questionIndex] = []
|
|
467
|
+
} else {
|
|
468
|
+
state.askUserState.selectedAnswers[questionIndex] = -1
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}),
|
|
472
|
+
|
|
473
|
+
addPendingBashMessage: (message) =>
|
|
474
|
+
set((state) => {
|
|
475
|
+
state.pendingBashMessages.push(message)
|
|
476
|
+
}),
|
|
477
|
+
|
|
478
|
+
updatePendingBashMessage: (id, updates) =>
|
|
479
|
+
set((state) => {
|
|
480
|
+
const msg = state.pendingBashMessages.find((m) => m.id === id)
|
|
481
|
+
if (msg) {
|
|
482
|
+
Object.assign(msg, updates)
|
|
483
|
+
}
|
|
484
|
+
}),
|
|
485
|
+
|
|
486
|
+
removePendingBashMessage: (id) =>
|
|
487
|
+
set((state) => {
|
|
488
|
+
state.pendingBashMessages = state.pendingBashMessages.filter(
|
|
489
|
+
(m) => m.id !== id,
|
|
490
|
+
)
|
|
491
|
+
}),
|
|
492
|
+
|
|
493
|
+
clearPendingBashMessages: () =>
|
|
494
|
+
set((state) => {
|
|
495
|
+
state.pendingBashMessages = []
|
|
496
|
+
}),
|
|
497
|
+
|
|
498
|
+
setSuggestedFollowups: (suggestedFollowups) =>
|
|
499
|
+
set((state) => {
|
|
500
|
+
state.suggestedFollowups = suggestedFollowups
|
|
501
|
+
}),
|
|
502
|
+
|
|
503
|
+
markFollowupClicked: (toolCallId: string, index: number) =>
|
|
504
|
+
set((state) => {
|
|
505
|
+
// Store in the persistent map
|
|
506
|
+
if (!state.clickedFollowupsMap.has(toolCallId)) {
|
|
507
|
+
state.clickedFollowupsMap.set(toolCallId, new Set<number>())
|
|
508
|
+
}
|
|
509
|
+
state.clickedFollowupsMap.get(toolCallId)!.add(index)
|
|
510
|
+
|
|
511
|
+
// Also update the current suggestedFollowups if it matches
|
|
512
|
+
if (state.suggestedFollowups?.toolCallId === toolCallId) {
|
|
513
|
+
state.suggestedFollowups.clickedIndices.add(index)
|
|
514
|
+
}
|
|
515
|
+
}),
|
|
516
|
+
|
|
517
|
+
reset: () =>
|
|
518
|
+
set((state) => {
|
|
519
|
+
state.chatSessionId = generateSessionId()
|
|
520
|
+
state.messages = initialState.messages.slice()
|
|
521
|
+
state.streamingAgents = new Set(initialState.streamingAgents)
|
|
522
|
+
state.focusedAgentId = initialState.focusedAgentId
|
|
523
|
+
state.inputValue = initialState.inputValue
|
|
524
|
+
state.cursorPosition = initialState.cursorPosition
|
|
525
|
+
state.lastEditDueToNav = initialState.lastEditDueToNav
|
|
526
|
+
// Terminal capabilities and focus outlive a chat. Resetting these can
|
|
527
|
+
// re-enable animation while the app is still unfocused, and focus
|
|
528
|
+
// support would stay false because the mounted detector only reports
|
|
529
|
+
// support once per subscription.
|
|
530
|
+
state.activeSubagents = new Set(initialState.activeSubagents)
|
|
531
|
+
state.isChainInProgress = initialState.isChainInProgress
|
|
532
|
+
state.slashSelectedIndex = initialState.slashSelectedIndex
|
|
533
|
+
state.agentSelectedIndex = initialState.agentSelectedIndex
|
|
534
|
+
state.agentMode = initialState.agentMode
|
|
535
|
+
state.hasReceivedPlanResponse = initialState.hasReceivedPlanResponse
|
|
536
|
+
state.lastMessageMode = initialState.lastMessageMode
|
|
537
|
+
state.sessionCreditsUsed = initialState.sessionCreditsUsed
|
|
538
|
+
state.contextTokensUsed = initialState.contextTokensUsed
|
|
539
|
+
state.runState = initialState.runState
|
|
540
|
+
? castDraft(initialState.runState)
|
|
541
|
+
: null
|
|
542
|
+
state.activeTopBanner = initialState.activeTopBanner
|
|
543
|
+
state.inputMode = initialState.inputMode
|
|
544
|
+
state.isRetrying = initialState.isRetrying
|
|
545
|
+
state.isCapacityWait = initialState.isCapacityWait
|
|
546
|
+
state.askUserState = initialState.askUserState
|
|
547
|
+
state.pendingAttachments = []
|
|
548
|
+
state.pendingBashMessages = []
|
|
549
|
+
state.suggestedFollowups = null
|
|
550
|
+
state.clickedFollowupsMap = new Map<string, Set<number>>()
|
|
551
|
+
}),
|
|
552
|
+
})),
|
|
553
|
+
)
|