@renxqoo/renx-code 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -223
- package/bin/renx.cjs +50 -0
- package/package.json +12 -111
- package/src/App.tsx +297 -0
- package/src/agent/runtime/event-format.ts +258 -0
- package/src/agent/runtime/model-types.ts +13 -0
- package/src/agent/runtime/runtime.context-usage.test.ts +192 -0
- package/src/agent/runtime/runtime.error-handling.test.ts +235 -0
- package/src/agent/runtime/runtime.simple.test.ts +16 -0
- package/src/agent/runtime/runtime.test.ts +296 -0
- package/src/agent/runtime/runtime.ts +875 -0
- package/src/agent/runtime/runtime.usage-forwarding.test.ts +228 -0
- package/src/agent/runtime/source-modules.test.ts +38 -0
- package/src/agent/runtime/source-modules.ts +370 -0
- package/src/agent/runtime/tool-call-buffer.test.ts +65 -0
- package/src/agent/runtime/tool-call-buffer.ts +60 -0
- package/src/agent/runtime/tool-confirmation.test.ts +56 -0
- package/src/agent/runtime/tool-confirmation.ts +15 -0
- package/src/agent/runtime/types.ts +99 -0
- package/src/commands/slash-commands.test.ts +216 -0
- package/src/commands/slash-commands.ts +64 -0
- package/src/components/chat/assistant-reply.test.tsx +47 -0
- package/src/components/chat/assistant-reply.tsx +136 -0
- package/src/components/chat/assistant-segment.test.ts +99 -0
- package/src/components/chat/assistant-segment.tsx +125 -0
- package/src/components/chat/assistant-tool-group.tsx +900 -0
- package/src/components/chat/code-block.test.tsx +206 -0
- package/src/components/chat/code-block.tsx +313 -0
- package/src/components/chat/prompt-card.tsx +81 -0
- package/src/components/chat/segment-groups.test.ts +52 -0
- package/src/components/chat/segment-groups.ts +106 -0
- package/src/components/chat/turn-item.tsx +39 -0
- package/src/components/conversation-panel.tsx +43 -0
- package/src/components/file-mention-menu.tsx +77 -0
- package/src/components/file-picker-dialog.tsx +206 -0
- package/src/components/footer-hints.tsx +75 -0
- package/src/components/model-picker-dialog.tsx +248 -0
- package/src/components/prompt.tsx +233 -0
- package/src/components/slash-command-menu.tsx +65 -0
- package/src/components/tool-confirm-dialog-content.test.ts +103 -0
- package/src/components/tool-confirm-dialog-content.ts +186 -0
- package/src/components/tool-confirm-dialog.tsx +187 -0
- package/src/components/tool-display-config.ts +119 -0
- package/src/context-usage-regressions.test.ts +26 -0
- package/src/files/attachment-capabilities.test.ts +30 -0
- package/src/files/attachment-capabilities.ts +50 -0
- package/src/files/attachment-content.ts +153 -0
- package/src/files/file-mention-query.test.ts +34 -0
- package/src/files/file-mention-query.ts +32 -0
- package/src/files/prompt-display.ts +13 -0
- package/src/files/types.ts +5 -0
- package/src/files/workspace-files.ts +63 -0
- package/src/hooks/agent-event-handlers.test.ts +207 -0
- package/src/hooks/agent-event-handlers.ts +196 -0
- package/src/hooks/chat-local-replies.fixed.test.ts +119 -0
- package/src/hooks/chat-local-replies.test.ts +153 -0
- package/src/hooks/chat-local-replies.ts +63 -0
- package/src/hooks/turn-updater.test.ts +70 -0
- package/src/hooks/turn-updater.ts +166 -0
- package/src/hooks/use-agent-chat.context.test.ts +10 -0
- package/src/hooks/use-agent-chat.status.test.ts +14 -0
- package/src/hooks/use-agent-chat.test.ts +80 -0
- package/src/hooks/use-agent-chat.ts +621 -0
- package/src/hooks/use-file-mention-menu.ts +196 -0
- package/src/hooks/use-file-picker.ts +185 -0
- package/src/hooks/use-model-picker.ts +196 -0
- package/src/hooks/use-slash-command-menu.ts +154 -0
- package/src/index.tsx +55 -0
- package/src/runtime/clipboard.test.ts +43 -0
- package/src/runtime/clipboard.ts +89 -0
- package/src/runtime/exit.test.ts +177 -0
- package/src/runtime/exit.ts +98 -0
- package/src/runtime/runtime-support.test.ts +31 -0
- package/src/runtime/terminal-theme.test.ts +55 -0
- package/src/runtime/terminal-theme.ts +196 -0
- package/src/types/chat.ts +32 -0
- package/src/types/message-content.ts +48 -0
- package/src/ui/open-code-theme.ts +176 -0
- package/src/ui/opencode-markdown.ts +211 -0
- package/src/ui/theme.simple.test.ts +52 -0
- package/src/ui/theme.test.ts +151 -0
- package/src/ui/theme.ts +152 -0
- package/src/utils/time.test.ts +144 -0
- package/src/utils/time.ts +7 -0
- package/tsconfig.json +30 -0
- package/vendor/agent-root/src/agent/ENTERPRISE_ACCEPTANCE_CHECKLIST.md +95 -0
- package/vendor/agent-root/src/agent/ENTERPRISE_REALTIME.html +1345 -0
- package/vendor/agent-root/src/agent/ENTERPRISE_REALTIME.md +1353 -0
- package/vendor/agent-root/src/agent/ERROR_CONTRACT.md +60 -0
- package/vendor/agent-root/src/agent/TEST_COVERAGE_ANALYSIS.md +278 -0
- package/vendor/agent-root/src/agent/__test__/error-contract.test.ts +72 -0
- package/vendor/agent-root/src/agent/__test__/types.test.ts +137 -0
- package/vendor/agent-root/src/agent/agent/__test__/abort-runtime.test.ts +83 -0
- package/vendor/agent-root/src/agent/agent/__test__/callback-safety.test.ts +34 -0
- package/vendor/agent-root/src/agent/agent/__test__/compaction.test.ts +323 -0
- package/vendor/agent-root/src/agent/agent/__test__/concurrency.test.ts +290 -0
- package/vendor/agent-root/src/agent/agent/__test__/error-normalizer.test.ts +377 -0
- package/vendor/agent-root/src/agent/agent/__test__/error.test.ts +212 -0
- package/vendor/agent-root/src/agent/agent/__test__/fault-injection.test.ts +295 -0
- package/vendor/agent-root/src/agent/agent/__test__/index.test.ts +3607 -0
- package/vendor/agent-root/src/agent/agent/__test__/logger.test.ts +35 -0
- package/vendor/agent-root/src/agent/agent/__test__/message-utils.test.ts +517 -0
- package/vendor/agent-root/src/agent/agent/__test__/telemetry.test.ts +97 -0
- package/vendor/agent-root/src/agent/agent/__test__/timeout-budget.test.ts +479 -0
- package/vendor/agent-root/src/agent/agent/__test__/tool-call-merge.test.ts +80 -0
- package/vendor/agent-root/src/agent/agent/__test__/tool-execution-ledger.test.ts +76 -0
- package/vendor/agent-root/src/agent/agent/__test__/write-buffer.test.ts +173 -0
- package/vendor/agent-root/src/agent/agent/__test__/write-file-session.test.ts +109 -0
- package/vendor/agent-root/src/agent/agent/abort-runtime.ts +71 -0
- package/vendor/agent-root/src/agent/agent/callback-safety.ts +33 -0
- package/vendor/agent-root/src/agent/agent/compaction.ts +291 -0
- package/vendor/agent-root/src/agent/agent/concurrency.ts +103 -0
- package/vendor/agent-root/src/agent/agent/error-normalizer.ts +190 -0
- package/vendor/agent-root/src/agent/agent/error.ts +198 -0
- package/vendor/agent-root/src/agent/agent/index.ts +1772 -0
- package/vendor/agent-root/src/agent/agent/logger.ts +65 -0
- package/vendor/agent-root/src/agent/agent/message-utils.ts +101 -0
- package/vendor/agent-root/src/agent/agent/stream-events.ts +61 -0
- package/vendor/agent-root/src/agent/agent/telemetry.ts +123 -0
- package/vendor/agent-root/src/agent/agent/timeout-budget.ts +227 -0
- package/vendor/agent-root/src/agent/agent/tool-call-merge.ts +111 -0
- package/vendor/agent-root/src/agent/agent/tool-execution-ledger.ts +164 -0
- package/vendor/agent-root/src/agent/agent/write-buffer.ts +188 -0
- package/vendor/agent-root/src/agent/agent/write-file-session.ts +238 -0
- package/vendor/agent-root/src/agent/app/__test__/agent-app-service.test.ts +1053 -0
- package/vendor/agent-root/src/agent/app/__test__/minimal-agent-application.test.ts +158 -0
- package/vendor/agent-root/src/agent/app/__test__/sqlite-agent-app-store.test.ts +437 -0
- package/vendor/agent-root/src/agent/app/agent-app-service.ts +748 -0
- package/vendor/agent-root/src/agent/app/contracts.ts +109 -0
- package/vendor/agent-root/src/agent/app/index.ts +5 -0
- package/vendor/agent-root/src/agent/app/minimal-agent-application.ts +151 -0
- package/vendor/agent-root/src/agent/app/ports.ts +72 -0
- package/vendor/agent-root/src/agent/app/sqlite-agent-app-store.ts +1182 -0
- package/vendor/agent-root/src/agent/app/sqlite-client.ts +177 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/00-README.md +36 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/01-scope-and-goals.md +33 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/02-architecture-overview.md +40 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/03-domain-model-and-contracts.md +91 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/04-ports-and-interfaces.md +116 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/05-run-orchestration-and-state-machine.md +52 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/06-cli-commands-and-ux.md +53 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/07-storage-design-local.md +52 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/08-error-and-observability.md +40 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/09-security-and-policy-boundary.md +19 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/10-test-plan-and-acceptance.md +28 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/11-implementation-phases.md +26 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/12-open-questions-and-risks.md +30 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/13-sqlite-schema-fields-and-rationale.md +567 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/14-project-flow-mermaid.md +583 -0
- package/vendor/agent-root/src/agent/docs/cli-app-layer/15-openclaw-style-project-blueprint.md +972 -0
- package/vendor/agent-root/src/agent/error-contract.ts +154 -0
- package/{dist/agent/prompts/system.js → vendor/agent-root/src/agent/prompts/system.ts} +47 -23
- package/vendor/agent-root/src/agent/prompts/system1.ts +208 -0
- package/vendor/agent-root/src/agent/storage/__test__/file-history-store.test.ts +98 -0
- package/vendor/agent-root/src/agent/storage/file-history-store.ts +313 -0
- package/vendor/agent-root/src/agent/storage/file-storage-config.ts +94 -0
- package/vendor/agent-root/src/agent/storage/file-system.ts +31 -0
- package/vendor/agent-root/src/agent/storage/file-write-service.ts +21 -0
- package/vendor/agent-root/src/agent/tool/__test__/base-tool.test.ts +413 -0
- package/vendor/agent-root/src/agent/tool/__test__/bash-policy.test.ts +356 -0
- package/vendor/agent-root/src/agent/tool/__test__/bash.mocked-coverage.test.ts +375 -0
- package/vendor/agent-root/src/agent/tool/__test__/bash.test.ts +372 -0
- package/vendor/agent-root/src/agent/tool/__test__/error.test.ts +108 -0
- package/vendor/agent-root/src/agent/tool/__test__/file-edit-tool.test.ts +258 -0
- package/vendor/agent-root/src/agent/tool/__test__/file-history-tools.test.ts +121 -0
- package/vendor/agent-root/src/agent/tool/__test__/file-read-tool.test.ts +210 -0
- package/vendor/agent-root/src/agent/tool/__test__/glob.test.ts +139 -0
- package/vendor/agent-root/src/agent/tool/__test__/grep.mocked-coverage.test.ts +456 -0
- package/vendor/agent-root/src/agent/tool/__test__/grep.test.ts +192 -0
- package/vendor/agent-root/src/agent/tool/__test__/lsp.test.ts +300 -0
- package/vendor/agent-root/src/agent/tool/__test__/outside-workspace-confirmation.test.ts +214 -0
- package/vendor/agent-root/src/agent/tool/__test__/path-security.test.ts +336 -0
- package/vendor/agent-root/src/agent/tool/__test__/skill-loader.test.ts +494 -0
- package/vendor/agent-root/src/agent/tool/__test__/skill-parser.test.ts +543 -0
- package/vendor/agent-root/src/agent/tool/__test__/skill-tool.test.ts +172 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-concurrency-and-version.test.ts +116 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-create-get-list-update.test.ts +267 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-create.test.ts +519 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-errors.test.ts +225 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-output-blocking.test.ts +223 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-output.test.ts +184 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-parent-abort.test.ts +287 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-real-runner-adapter.test.ts +190 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-run-lifecycle.test.ts +352 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-store-runner-branches.test.ts +395 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-store.test.ts +391 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-subagent-config-integration.test.ts +176 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-subagent-config.test.ts +68 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-tools-core-edges.test.ts +630 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-tools-runtime-edges.test.ts +732 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-types.test.ts +494 -0
- package/vendor/agent-root/src/agent/tool/__test__/task-utils-branches.test.ts +175 -0
- package/vendor/agent-root/src/agent/tool/__test__/tool-manager.test.ts +505 -0
- package/vendor/agent-root/src/agent/tool/__test__/types.test.ts +55 -0
- package/vendor/agent-root/src/agent/tool/__test__/web-fetch.test.ts +244 -0
- package/vendor/agent-root/src/agent/tool/__test__/web-search.test.ts +290 -0
- package/vendor/agent-root/src/agent/tool/__test__/write-file.test.ts +368 -0
- package/vendor/agent-root/src/agent/tool/base-tool.ts +345 -0
- package/vendor/agent-root/src/agent/tool/bash-policy.ts +636 -0
- package/vendor/agent-root/src/agent/tool/bash.ts +688 -0
- package/vendor/agent-root/src/agent/tool/error.ts +131 -0
- package/vendor/agent-root/src/agent/tool/file-edit-tool.ts +264 -0
- package/vendor/agent-root/src/agent/tool/file-history-list.ts +103 -0
- package/vendor/agent-root/src/agent/tool/file-history-restore.ts +149 -0
- package/vendor/agent-root/src/agent/tool/file-read-tool.ts +211 -0
- package/vendor/agent-root/src/agent/tool/glob.ts +171 -0
- package/vendor/agent-root/src/agent/tool/grep.ts +496 -0
- package/vendor/agent-root/src/agent/tool/lsp.ts +481 -0
- package/vendor/agent-root/src/agent/tool/path-security.ts +117 -0
- package/vendor/agent-root/src/agent/tool/search/common.ts +153 -0
- package/vendor/agent-root/src/agent/tool/skill/index.ts +13 -0
- package/vendor/agent-root/src/agent/tool/skill/loader.ts +229 -0
- package/vendor/agent-root/src/agent/tool/skill/parser.ts +124 -0
- package/vendor/agent-root/src/agent/tool/skill/types.ts +27 -0
- package/vendor/agent-root/src/agent/tool/skill-tool.ts +143 -0
- package/vendor/agent-root/src/agent/tool/task-create.ts +186 -0
- package/vendor/agent-root/src/agent/tool/task-errors.ts +42 -0
- package/vendor/agent-root/src/agent/tool/task-get.ts +116 -0
- package/vendor/agent-root/src/agent/tool/task-graph.ts +78 -0
- package/vendor/agent-root/src/agent/tool/task-list.ts +141 -0
- package/vendor/agent-root/src/agent/tool/task-mock-runner-adapter.ts +232 -0
- package/vendor/agent-root/src/agent/tool/task-output.ts +223 -0
- package/vendor/agent-root/src/agent/tool/task-parent-abort.ts +115 -0
- package/vendor/agent-root/src/agent/tool/task-real-runner-adapter.ts +336 -0
- package/vendor/agent-root/src/agent/tool/task-runner-adapter.ts +55 -0
- package/vendor/agent-root/src/agent/tool/task-stop.ts +187 -0
- package/vendor/agent-root/src/agent/tool/task-store.ts +217 -0
- package/vendor/agent-root/src/agent/tool/task-subagent-config.ts +149 -0
- package/vendor/agent-root/src/agent/tool/task-types.ts +264 -0
- package/vendor/agent-root/src/agent/tool/task-update.ts +315 -0
- package/vendor/agent-root/src/agent/tool/task.ts +209 -0
- package/vendor/agent-root/src/agent/tool/tool-manager.ts +362 -0
- package/vendor/agent-root/src/agent/tool/tool-prompts.ts +242 -0
- package/vendor/agent-root/src/agent/tool/types.ts +116 -0
- package/vendor/agent-root/src/agent/tool/web-fetch.ts +227 -0
- package/vendor/agent-root/src/agent/tool/web-search.ts +208 -0
- package/vendor/agent-root/src/agent/tool/write-file.ts +497 -0
- package/vendor/agent-root/src/agent/types.ts +232 -0
- package/vendor/agent-root/src/agent/utils/__tests__/index.test.ts +18 -0
- package/vendor/agent-root/src/agent/utils/__tests__/message-utils.test.ts +610 -0
- package/vendor/agent-root/src/agent/utils/__tests__/message.test.ts +223 -0
- package/vendor/agent-root/src/agent/utils/__tests__/token.test.ts +42 -0
- package/vendor/agent-root/src/agent/utils/index.ts +16 -0
- package/vendor/agent-root/src/agent/utils/message.ts +171 -0
- package/vendor/agent-root/src/agent/utils/token.ts +28 -0
- package/vendor/agent-root/src/config/__tests__/load-config-to-env.test.ts +129 -0
- package/vendor/agent-root/src/config/__tests__/loader.test.ts +247 -0
- package/vendor/agent-root/src/config/__tests__/runtime.test.ts +88 -0
- package/vendor/agent-root/src/config/index.ts +54 -0
- package/vendor/agent-root/src/config/loader.ts +431 -0
- package/vendor/agent-root/src/config/paths.ts +30 -0
- package/vendor/agent-root/src/config/runtime.ts +163 -0
- package/vendor/agent-root/src/config/types.ts +70 -0
- package/vendor/agent-root/src/logger/index.ts +57 -0
- package/vendor/agent-root/src/logger/logger.ts +819 -0
- package/vendor/agent-root/src/logger/types.ts +150 -0
- package/vendor/agent-root/src/providers/__tests__/errors.test.ts +441 -0
- package/vendor/agent-root/src/providers/__tests__/index.test.ts +16 -0
- package/vendor/agent-root/src/providers/__tests__/openai-compatible.options.test.ts +318 -0
- package/vendor/agent-root/src/providers/__tests__/openai-compatible.test.ts +600 -0
- package/vendor/agent-root/src/providers/__tests__/registry.test.ts +449 -0
- package/vendor/agent-root/src/providers/__tests__/responses-adapter.test.ts +298 -0
- package/vendor/agent-root/src/providers/adapters/__tests__/anthropic.test.ts +354 -0
- package/vendor/agent-root/src/providers/adapters/__tests__/kimi.test.ts +58 -0
- package/vendor/agent-root/src/providers/adapters/__tests__/standard.test.ts +261 -0
- package/vendor/agent-root/src/providers/adapters/anthropic.ts +572 -0
- package/vendor/agent-root/src/providers/adapters/base.ts +131 -0
- package/vendor/agent-root/src/providers/adapters/kimi.ts +48 -0
- package/vendor/agent-root/src/providers/adapters/responses.ts +732 -0
- package/vendor/agent-root/src/providers/adapters/standard.ts +120 -0
- package/vendor/agent-root/src/providers/http/__tests__/client.timeout.test.ts +313 -0
- package/vendor/agent-root/src/providers/http/client.ts +289 -0
- package/vendor/agent-root/src/providers/http/stream-parser.ts +109 -0
- package/vendor/agent-root/src/providers/index.ts +76 -0
- package/vendor/agent-root/src/providers/kimi-headers.ts +177 -0
- package/vendor/agent-root/src/providers/openai-compatible.ts +387 -0
- package/vendor/agent-root/src/providers/registry/model-config.ts +230 -0
- package/vendor/agent-root/src/providers/registry/provider-factory.ts +123 -0
- package/vendor/agent-root/src/providers/registry.ts +135 -0
- package/vendor/agent-root/src/providers/types/api.ts +284 -0
- package/vendor/agent-root/src/providers/types/config.ts +58 -0
- package/vendor/agent-root/src/providers/types/errors.ts +323 -0
- package/vendor/agent-root/src/providers/types/index.ts +72 -0
- package/vendor/agent-root/src/providers/types/provider.ts +45 -0
- package/vendor/agent-root/src/providers/types/registry.ts +88 -0
- package/LICENSE +0 -21
- package/dist/App.d.ts +0 -2
- package/dist/App.d.ts.map +0 -1
- package/dist/App.js +0 -170
- package/dist/App.js.map +0 -1
- package/dist/agent/prompts/system.d.ts +0 -24
- package/dist/agent/prompts/system.d.ts.map +0 -1
- package/dist/agent/prompts/system.js.map +0 -1
- package/dist/agent/runtime/event-format.d.ts +0 -17
- package/dist/agent/runtime/event-format.d.ts.map +0 -1
- package/dist/agent/runtime/event-format.js +0 -194
- package/dist/agent/runtime/event-format.js.map +0 -1
- package/dist/agent/runtime/model-types.d.ts +0 -13
- package/dist/agent/runtime/model-types.d.ts.map +0 -1
- package/dist/agent/runtime/model-types.js +0 -1
- package/dist/agent/runtime/model-types.js.map +0 -1
- package/dist/agent/runtime/runtime.d.ts +0 -16
- package/dist/agent/runtime/runtime.d.ts.map +0 -1
- package/dist/agent/runtime/runtime.js +0 -691
- package/dist/agent/runtime/runtime.js.map +0 -1
- package/dist/agent/runtime/source-modules.d.ts +0 -176
- package/dist/agent/runtime/source-modules.d.ts.map +0 -1
- package/dist/agent/runtime/source-modules.js +0 -110
- package/dist/agent/runtime/source-modules.js.map +0 -1
- package/dist/agent/runtime/tool-call-buffer.d.ts +0 -12
- package/dist/agent/runtime/tool-call-buffer.d.ts.map +0 -1
- package/dist/agent/runtime/tool-call-buffer.js +0 -48
- package/dist/agent/runtime/tool-call-buffer.js.map +0 -1
- package/dist/agent/runtime/tool-confirmation.d.ts +0 -3
- package/dist/agent/runtime/tool-confirmation.d.ts.map +0 -1
- package/dist/agent/runtime/tool-confirmation.js +0 -9
- package/dist/agent/runtime/tool-confirmation.js.map +0 -1
- package/dist/agent/runtime/types.d.ts +0 -86
- package/dist/agent/runtime/types.d.ts.map +0 -1
- package/dist/agent/runtime/types.js +0 -1
- package/dist/agent/runtime/types.js.map +0 -1
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -12
- package/dist/cli.js.map +0 -1
- package/dist/commands/slash-commands.d.ts +0 -11
- package/dist/commands/slash-commands.d.ts.map +0 -1
- package/dist/commands/slash-commands.js +0 -48
- package/dist/commands/slash-commands.js.map +0 -1
- package/dist/components/chat/assistant-reply.d.ts +0 -13
- package/dist/components/chat/assistant-reply.d.ts.map +0 -1
- package/dist/components/chat/assistant-reply.js +0 -78
- package/dist/components/chat/assistant-reply.js.map +0 -1
- package/dist/components/chat/assistant-segment.d.ts +0 -8
- package/dist/components/chat/assistant-segment.d.ts.map +0 -1
- package/dist/components/chat/assistant-segment.js +0 -54
- package/dist/components/chat/assistant-segment.js.map +0 -1
- package/dist/components/chat/assistant-tool-group.d.ts +0 -7
- package/dist/components/chat/assistant-tool-group.d.ts.map +0 -1
- package/dist/components/chat/assistant-tool-group.js +0 -695
- package/dist/components/chat/assistant-tool-group.js.map +0 -1
- package/dist/components/chat/code-block.d.ts +0 -16
- package/dist/components/chat/code-block.d.ts.map +0 -1
- package/dist/components/chat/code-block.js +0 -194
- package/dist/components/chat/code-block.js.map +0 -1
- package/dist/components/chat/prompt-card.d.ts +0 -9
- package/dist/components/chat/prompt-card.d.ts.map +0 -1
- package/dist/components/chat/prompt-card.js +0 -18
- package/dist/components/chat/prompt-card.js.map +0 -1
- package/dist/components/chat/segment-groups.d.ts +0 -24
- package/dist/components/chat/segment-groups.d.ts.map +0 -1
- package/dist/components/chat/segment-groups.js +0 -69
- package/dist/components/chat/segment-groups.js.map +0 -1
- package/dist/components/chat/turn-item.d.ts +0 -9
- package/dist/components/chat/turn-item.d.ts.map +0 -1
- package/dist/components/chat/turn-item.js +0 -11
- package/dist/components/chat/turn-item.js.map +0 -1
- package/dist/components/conversation-panel.d.ts +0 -8
- package/dist/components/conversation-panel.d.ts.map +0 -1
- package/dist/components/conversation-panel.js +0 -8
- package/dist/components/conversation-panel.js.map +0 -1
- package/dist/components/file-mention-menu.d.ts +0 -11
- package/dist/components/file-mention-menu.d.ts.map +0 -1
- package/dist/components/file-mention-menu.js +0 -15
- package/dist/components/file-mention-menu.js.map +0 -1
- package/dist/components/file-picker-dialog.d.ts +0 -21
- package/dist/components/file-picker-dialog.d.ts.map +0 -1
- package/dist/components/file-picker-dialog.js +0 -48
- package/dist/components/file-picker-dialog.js.map +0 -1
- package/dist/components/footer-hints.d.ts +0 -7
- package/dist/components/footer-hints.d.ts.map +0 -1
- package/dist/components/footer-hints.js +0 -29
- package/dist/components/footer-hints.js.map +0 -1
- package/dist/components/model-picker-dialog.d.ts +0 -20
- package/dist/components/model-picker-dialog.d.ts.map +0 -1
- package/dist/components/model-picker-dialog.js +0 -72
- package/dist/components/model-picker-dialog.js.map +0 -1
- package/dist/components/prompt.d.ts +0 -18
- package/dist/components/prompt.d.ts.map +0 -1
- package/dist/components/prompt.js +0 -96
- package/dist/components/prompt.js.map +0 -1
- package/dist/components/slash-command-menu.d.ts +0 -9
- package/dist/components/slash-command-menu.d.ts.map +0 -1
- package/dist/components/slash-command-menu.js +0 -20
- package/dist/components/slash-command-menu.js.map +0 -1
- package/dist/components/tool-confirm-dialog-content.d.ts +0 -15
- package/dist/components/tool-confirm-dialog-content.d.ts.map +0 -1
- package/dist/components/tool-confirm-dialog-content.js +0 -143
- package/dist/components/tool-confirm-dialog-content.js.map +0 -1
- package/dist/components/tool-confirm-dialog.d.ts +0 -12
- package/dist/components/tool-confirm-dialog.d.ts.map +0 -1
- package/dist/components/tool-confirm-dialog.js +0 -21
- package/dist/components/tool-confirm-dialog.js.map +0 -1
- package/dist/components/tool-display-config.d.ts +0 -11
- package/dist/components/tool-display-config.d.ts.map +0 -1
- package/dist/components/tool-display-config.js +0 -94
- package/dist/components/tool-display-config.js.map +0 -1
- package/dist/config/paths.d.ts +0 -7
- package/dist/config/paths.d.ts.map +0 -1
- package/dist/config/paths.js +0 -24
- package/dist/config/paths.js.map +0 -1
- package/dist/files/attachment-capabilities.d.ts +0 -19
- package/dist/files/attachment-capabilities.d.ts.map +0 -1
- package/dist/files/attachment-capabilities.js +0 -26
- package/dist/files/attachment-capabilities.js.map +0 -1
- package/dist/files/attachment-content.d.ts +0 -5
- package/dist/files/attachment-content.d.ts.map +0 -1
- package/dist/files/attachment-content.js +0 -117
- package/dist/files/attachment-content.js.map +0 -1
- package/dist/files/file-mention-query.d.ts +0 -9
- package/dist/files/file-mention-query.d.ts.map +0 -1
- package/dist/files/file-mention-query.js +0 -23
- package/dist/files/file-mention-query.js.map +0 -1
- package/dist/files/prompt-display.d.ts +0 -3
- package/dist/files/prompt-display.d.ts.map +0 -1
- package/dist/files/prompt-display.js +0 -11
- package/dist/files/prompt-display.js.map +0 -1
- package/dist/files/types.d.ts +0 -6
- package/dist/files/types.d.ts.map +0 -1
- package/dist/files/types.js +0 -1
- package/dist/files/types.js.map +0 -1
- package/dist/files/workspace-files.d.ts +0 -3
- package/dist/files/workspace-files.d.ts.map +0 -1
- package/dist/files/workspace-files.js +0 -48
- package/dist/files/workspace-files.js.map +0 -1
- package/dist/hooks/agent-event-handlers.d.ts +0 -11
- package/dist/hooks/agent-event-handlers.d.ts.map +0 -1
- package/dist/hooks/agent-event-handlers.js +0 -137
- package/dist/hooks/agent-event-handlers.js.map +0 -1
- package/dist/hooks/chat-local-replies.d.ts +0 -9
- package/dist/hooks/chat-local-replies.d.ts.map +0 -1
- package/dist/hooks/chat-local-replies.js +0 -54
- package/dist/hooks/chat-local-replies.js.map +0 -1
- package/dist/hooks/turn-updater.d.ts +0 -9
- package/dist/hooks/turn-updater.d.ts.map +0 -1
- package/dist/hooks/turn-updater.js +0 -103
- package/dist/hooks/turn-updater.js.map +0 -1
- package/dist/hooks/use-agent-chat.d.ts +0 -29
- package/dist/hooks/use-agent-chat.d.ts.map +0 -1
- package/dist/hooks/use-agent-chat.js +0 -455
- package/dist/hooks/use-agent-chat.js.map +0 -1
- package/dist/hooks/use-file-mention-menu.d.ts +0 -22
- package/dist/hooks/use-file-mention-menu.d.ts.map +0 -1
- package/dist/hooks/use-file-mention-menu.js +0 -137
- package/dist/hooks/use-file-mention-menu.js.map +0 -1
- package/dist/hooks/use-file-picker.d.ts +0 -21
- package/dist/hooks/use-file-picker.d.ts.map +0 -1
- package/dist/hooks/use-file-picker.js +0 -145
- package/dist/hooks/use-file-picker.js.map +0 -1
- package/dist/hooks/use-model-picker.d.ts +0 -23
- package/dist/hooks/use-model-picker.d.ts.map +0 -1
- package/dist/hooks/use-model-picker.js +0 -151
- package/dist/hooks/use-model-picker.js.map +0 -1
- package/dist/hooks/use-slash-command-menu.d.ts +0 -19
- package/dist/hooks/use-slash-command-menu.d.ts.map +0 -1
- package/dist/hooks/use-slash-command-menu.js +0 -101
- package/dist/hooks/use-slash-command-menu.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -6
- package/dist/index.js.map +0 -1
- package/dist/run-cli-app.d.ts +0 -2
- package/dist/run-cli-app.d.ts.map +0 -1
- package/dist/run-cli-app.js +0 -41
- package/dist/run-cli-app.js.map +0 -1
- package/dist/runtime/clipboard.d.ts +0 -10
- package/dist/runtime/clipboard.d.ts.map +0 -1
- package/dist/runtime/clipboard.js +0 -64
- package/dist/runtime/clipboard.js.map +0 -1
- package/dist/runtime/exit.d.ts +0 -7
- package/dist/runtime/exit.d.ts.map +0 -1
- package/dist/runtime/exit.js +0 -85
- package/dist/runtime/exit.js.map +0 -1
- package/dist/runtime/runtime-support.d.ts +0 -4
- package/dist/runtime/runtime-support.d.ts.map +0 -1
- package/dist/runtime/runtime-support.js +0 -19
- package/dist/runtime/runtime-support.js.map +0 -1
- package/dist/runtime/terminal-theme.d.ts +0 -25
- package/dist/runtime/terminal-theme.d.ts.map +0 -1
- package/dist/runtime/terminal-theme.js +0 -148
- package/dist/runtime/terminal-theme.js.map +0 -1
- package/dist/types/chat.d.ts +0 -29
- package/dist/types/chat.d.ts.map +0 -1
- package/dist/types/chat.js +0 -1
- package/dist/types/chat.js.map +0 -1
- package/dist/types/message-content.d.ts +0 -38
- package/dist/types/message-content.d.ts.map +0 -1
- package/dist/types/message-content.js +0 -1
- package/dist/types/message-content.js.map +0 -1
- package/dist/ui/open-code-theme.d.ts +0 -58
- package/dist/ui/open-code-theme.d.ts.map +0 -1
- package/dist/ui/open-code-theme.js +0 -113
- package/dist/ui/open-code-theme.js.map +0 -1
- package/dist/ui/opencode-markdown.d.ts +0 -7
- package/dist/ui/opencode-markdown.d.ts.map +0 -1
- package/dist/ui/opencode-markdown.js +0 -169
- package/dist/ui/opencode-markdown.js.map +0 -1
- package/dist/ui/theme.d.ts +0 -68
- package/dist/ui/theme.d.ts.map +0 -1
- package/dist/ui/theme.js +0 -80
- package/dist/ui/theme.js.map +0 -1
- package/dist/utils/time.d.ts +0 -2
- package/dist/utils/time.d.ts.map +0 -1
- package/dist/utils/time.js +0 -7
- package/dist/utils/time.js.map +0 -1
|
@@ -1,455 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { resolveSlashCommand } from '../commands/slash-commands.js';
|
|
3
|
-
import { getAgentModelAttachmentCapabilities, getAgentModelLabel, runAgentPrompt, } from '../agent/runtime/runtime.js';
|
|
4
|
-
import { requestExit } from '../runtime/exit.js';
|
|
5
|
-
import { buildAgentEventHandlers } from './agent-event-handlers.js';
|
|
6
|
-
import { buildHelpSegments, buildUnsupportedSegments, extractErrorMessage, } from './chat-local-replies.js';
|
|
7
|
-
import { appendNoteLine, appendToSegment, createStreamingReply, orderReplySegments, patchTurn, setReplyStatus, } from './turn-updater.js';
|
|
8
|
-
import { DEFAULT_ATTACHMENT_MODEL_CAPABILITIES, } from '../files/attachment-capabilities.js';
|
|
9
|
-
import { buildPromptContent } from '../files/attachment-content.js';
|
|
10
|
-
import { buildPromptDisplay } from '../files/prompt-display.js';
|
|
11
|
-
const INITIAL_MODEL_LABEL = process.env.AGENT_MODEL?.trim() || '';
|
|
12
|
-
const normalizeTokenCount = (value) => {
|
|
13
|
-
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
return Math.max(0, Math.round(value));
|
|
17
|
-
};
|
|
18
|
-
/** Normalizes context usage percent, ensuring it's a finite non-negative number. */
|
|
19
|
-
const normalizeContextUsagePercent = (value) => {
|
|
20
|
-
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
21
|
-
return Math.max(0, value);
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
};
|
|
25
|
-
const toReplyUsage = (usage) => {
|
|
26
|
-
if (!usage) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
const usagePromptTokens = normalizeTokenCount(usage.cumulativePromptTokens ?? usage.promptTokens);
|
|
30
|
-
const usageCompletionTokens = normalizeTokenCount(usage.cumulativeCompletionTokens ?? usage.completionTokens);
|
|
31
|
-
const usageTotalTokens = normalizeTokenCount(usage.cumulativeTotalTokens ?? usage.totalTokens);
|
|
32
|
-
if (typeof usagePromptTokens !== 'number' &&
|
|
33
|
-
typeof usageCompletionTokens !== 'number' &&
|
|
34
|
-
typeof usageTotalTokens !== 'number') {
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
usagePromptTokens,
|
|
39
|
-
usageCompletionTokens,
|
|
40
|
-
usageTotalTokens,
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
export const resolveReplyStatus = (completionReason) => {
|
|
44
|
-
return completionReason === 'error' ? 'error' : 'done';
|
|
45
|
-
};
|
|
46
|
-
export const useAgentChat = () => {
|
|
47
|
-
const [turns, setTurns] = useState([]);
|
|
48
|
-
const [inputValue, setInputValue] = useState('');
|
|
49
|
-
const [selectedFiles, setSelectedFiles] = useState([]);
|
|
50
|
-
const [isThinking, setIsThinking] = useState(false);
|
|
51
|
-
const [modelLabel, setModelLabel] = useState(INITIAL_MODEL_LABEL);
|
|
52
|
-
const [contextUsagePercent, setContextUsagePercent] = useState(null);
|
|
53
|
-
const [attachmentCapabilities, setAttachmentCapabilities] = useState(DEFAULT_ATTACHMENT_MODEL_CAPABILITIES);
|
|
54
|
-
const [pendingToolConfirm, setPendingToolConfirm] = useState(null);
|
|
55
|
-
const removeSelectedFile = useCallback((absolutePath) => {
|
|
56
|
-
setSelectedFiles(current => current.filter(file => file.absolutePath !== absolutePath));
|
|
57
|
-
}, []);
|
|
58
|
-
const appendSelectedFiles = useCallback((files) => {
|
|
59
|
-
if (files.length === 0) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
setSelectedFiles(current => {
|
|
63
|
-
const seen = new Set(current.map(file => file.absolutePath));
|
|
64
|
-
const next = [...current];
|
|
65
|
-
for (const file of files) {
|
|
66
|
-
if (seen.has(file.absolutePath)) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
next.push(file);
|
|
70
|
-
seen.add(file.absolutePath);
|
|
71
|
-
}
|
|
72
|
-
return next;
|
|
73
|
-
});
|
|
74
|
-
}, []);
|
|
75
|
-
const turnIdRef = useRef(1);
|
|
76
|
-
const requestIdRef = useRef(0);
|
|
77
|
-
const activeTurnIdRef = useRef(null);
|
|
78
|
-
const activeAbortControllerRef = useRef(null);
|
|
79
|
-
const activeRunPromiseRef = useRef(null);
|
|
80
|
-
const pendingToolConfirmResolverRef = useRef(null);
|
|
81
|
-
const resolvePendingToolConfirm = useCallback((decision) => {
|
|
82
|
-
const resolver = pendingToolConfirmResolverRef.current;
|
|
83
|
-
pendingToolConfirmResolverRef.current = null;
|
|
84
|
-
setPendingToolConfirm(null);
|
|
85
|
-
resolver?.(decision);
|
|
86
|
-
}, []);
|
|
87
|
-
useEffect(() => {
|
|
88
|
-
let disposed = false;
|
|
89
|
-
void getAgentModelLabel()
|
|
90
|
-
.then(label => {
|
|
91
|
-
if (!disposed) {
|
|
92
|
-
setModelLabel(label);
|
|
93
|
-
}
|
|
94
|
-
})
|
|
95
|
-
.catch(() => { });
|
|
96
|
-
void getAgentModelAttachmentCapabilities()
|
|
97
|
-
.then(capabilities => {
|
|
98
|
-
if (!disposed) {
|
|
99
|
-
setAttachmentCapabilities(capabilities);
|
|
100
|
-
}
|
|
101
|
-
})
|
|
102
|
-
.catch(() => { });
|
|
103
|
-
return () => {
|
|
104
|
-
disposed = true;
|
|
105
|
-
};
|
|
106
|
-
}, []);
|
|
107
|
-
useEffect(() => {
|
|
108
|
-
return () => {
|
|
109
|
-
// 清理活动的Promise以防止内存泄漏
|
|
110
|
-
const currentPromise = activeRunPromiseRef.current;
|
|
111
|
-
if (currentPromise) {
|
|
112
|
-
currentPromise.catch(() => { }); // 防止未处理的rejection
|
|
113
|
-
}
|
|
114
|
-
activeAbortControllerRef.current?.abort();
|
|
115
|
-
const resolver = pendingToolConfirmResolverRef.current;
|
|
116
|
-
pendingToolConfirmResolverRef.current = null;
|
|
117
|
-
resolver?.({
|
|
118
|
-
approved: false,
|
|
119
|
-
message: 'Tool confirmation cancelled because the UI was closed.',
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
}, []);
|
|
123
|
-
const appendSegment = useCallback((turnId, segmentId, type, chunk, data) => {
|
|
124
|
-
setTurns(prev => patchTurn(prev, turnId, turn => {
|
|
125
|
-
if (!turn.reply) {
|
|
126
|
-
return turn;
|
|
127
|
-
}
|
|
128
|
-
return {
|
|
129
|
-
...turn,
|
|
130
|
-
reply: {
|
|
131
|
-
...turn.reply,
|
|
132
|
-
segments: orderReplySegments(appendToSegment(turn.reply.segments, segmentId, type, chunk, data)),
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
}));
|
|
136
|
-
}, []);
|
|
137
|
-
const appendEventLine = useCallback((turnId, text) => {
|
|
138
|
-
setTurns(prev => patchTurn(prev, turnId, turn => {
|
|
139
|
-
if (!turn.reply) {
|
|
140
|
-
return turn;
|
|
141
|
-
}
|
|
142
|
-
return {
|
|
143
|
-
...turn,
|
|
144
|
-
reply: {
|
|
145
|
-
...turn.reply,
|
|
146
|
-
segments: orderReplySegments(appendNoteLine(turn.reply.segments, `${turnId}:events`, text)),
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
}));
|
|
150
|
-
}, []);
|
|
151
|
-
const stopActiveReply = useCallback(() => {
|
|
152
|
-
if (!isThinking) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
requestIdRef.current += 1;
|
|
156
|
-
activeAbortControllerRef.current?.abort();
|
|
157
|
-
activeAbortControllerRef.current = null;
|
|
158
|
-
setIsThinking(false);
|
|
159
|
-
const activeTurnId = activeTurnIdRef.current;
|
|
160
|
-
activeTurnIdRef.current = null;
|
|
161
|
-
if (typeof activeTurnId !== 'number') {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
appendEventLine(activeTurnId, '[stop] aborted by user');
|
|
165
|
-
setTurns(prev => setReplyStatus(prev, activeTurnId, 'done', {
|
|
166
|
-
completionReason: 'cancelled',
|
|
167
|
-
completionMessage: 'Stopped by user.',
|
|
168
|
-
}));
|
|
169
|
-
}, [appendEventLine, isThinking]);
|
|
170
|
-
const resetConversation = useCallback(() => {
|
|
171
|
-
resolvePendingToolConfirm({
|
|
172
|
-
approved: false,
|
|
173
|
-
message: 'Tool confirmation cancelled because the conversation was reset.',
|
|
174
|
-
});
|
|
175
|
-
requestIdRef.current += 1;
|
|
176
|
-
activeAbortControllerRef.current?.abort();
|
|
177
|
-
activeAbortControllerRef.current = null;
|
|
178
|
-
activeTurnIdRef.current = null;
|
|
179
|
-
setIsThinking(false);
|
|
180
|
-
setTurns([]);
|
|
181
|
-
setSelectedFiles([]);
|
|
182
|
-
setContextUsagePercent(() => null);
|
|
183
|
-
}, [resolvePendingToolConfirm]);
|
|
184
|
-
const addTurn = useCallback((prompt, withStreamingReply = false, files = []) => {
|
|
185
|
-
const turnId = turnIdRef.current++;
|
|
186
|
-
const displayPrompt = buildPromptDisplay(prompt, files);
|
|
187
|
-
setTurns(prev => [
|
|
188
|
-
...prev,
|
|
189
|
-
{
|
|
190
|
-
id: turnId,
|
|
191
|
-
prompt: displayPrompt,
|
|
192
|
-
files: files.map(file => file.relativePath),
|
|
193
|
-
createdAtMs: Date.now(),
|
|
194
|
-
reply: withStreamingReply ? createStreamingReply(modelLabel) : undefined,
|
|
195
|
-
},
|
|
196
|
-
]);
|
|
197
|
-
return turnId;
|
|
198
|
-
}, [modelLabel]);
|
|
199
|
-
const setImmediateReply = useCallback((turnId, segments) => {
|
|
200
|
-
setTurns(prev => patchTurn(prev, turnId, turn => ({
|
|
201
|
-
...turn,
|
|
202
|
-
reply: {
|
|
203
|
-
...createStreamingReply(modelLabel),
|
|
204
|
-
status: 'done',
|
|
205
|
-
durationSeconds: 0,
|
|
206
|
-
segments,
|
|
207
|
-
},
|
|
208
|
-
})));
|
|
209
|
-
}, [modelLabel]);
|
|
210
|
-
const runCommand = useCallback((commandText) => {
|
|
211
|
-
const command = resolveSlashCommand(commandText);
|
|
212
|
-
if (!command) {
|
|
213
|
-
return false;
|
|
214
|
-
}
|
|
215
|
-
if (command.action === 'clear') {
|
|
216
|
-
resetConversation();
|
|
217
|
-
return true;
|
|
218
|
-
}
|
|
219
|
-
if (command.action === 'exit') {
|
|
220
|
-
requestExit(0);
|
|
221
|
-
return true;
|
|
222
|
-
}
|
|
223
|
-
if (command.action === 'help') {
|
|
224
|
-
const turnId = addTurn(commandText.trim(), true);
|
|
225
|
-
setImmediateReply(turnId, buildHelpSegments(turnId));
|
|
226
|
-
return true;
|
|
227
|
-
}
|
|
228
|
-
const turnId = addTurn(commandText.trim(), true);
|
|
229
|
-
setImmediateReply(turnId, buildUnsupportedSegments(turnId, command.name));
|
|
230
|
-
return true;
|
|
231
|
-
}, [addTurn, resetConversation, setImmediateReply]);
|
|
232
|
-
const submitInput = useCallback(() => {
|
|
233
|
-
const text = inputValue.trim();
|
|
234
|
-
const attachedFiles = selectedFiles;
|
|
235
|
-
if ((text.length === 0 && attachedFiles.length === 0) || isThinking) {
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
setInputValue('');
|
|
239
|
-
if (attachedFiles.length === 0 && text.startsWith('/') && runCommand(text)) {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
setSelectedFiles([]);
|
|
243
|
-
void (async () => {
|
|
244
|
-
const previousRun = activeRunPromiseRef.current;
|
|
245
|
-
if (previousRun) {
|
|
246
|
-
await previousRun.catch(error => {
|
|
247
|
-
console.debug('Previous run failed:', error instanceof Error ? error.message : String(error));
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
const turnId = addTurn(text, true, attachedFiles);
|
|
251
|
-
activeTurnIdRef.current = turnId;
|
|
252
|
-
const currentRequestId = ++requestIdRef.current;
|
|
253
|
-
const isCurrentRequest = () => currentRequestId === requestIdRef.current;
|
|
254
|
-
const abortController = new AbortController();
|
|
255
|
-
activeAbortControllerRef.current = abortController;
|
|
256
|
-
setIsThinking(true);
|
|
257
|
-
const baseHandlers = buildAgentEventHandlers({
|
|
258
|
-
turnId,
|
|
259
|
-
isCurrentRequest,
|
|
260
|
-
appendSegment,
|
|
261
|
-
appendEventLine,
|
|
262
|
-
});
|
|
263
|
-
const handlers = {
|
|
264
|
-
...baseHandlers,
|
|
265
|
-
onToolConfirmRequest: (event) => {
|
|
266
|
-
if (!isCurrentRequest()) {
|
|
267
|
-
return Promise.resolve({
|
|
268
|
-
approved: false,
|
|
269
|
-
message: 'Tool confirmation denied because the request is no longer active.',
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
if (pendingToolConfirmResolverRef.current) {
|
|
273
|
-
pendingToolConfirmResolverRef.current({
|
|
274
|
-
approved: false,
|
|
275
|
-
message: 'Superseded by a newer tool confirmation request.',
|
|
276
|
-
});
|
|
277
|
-
pendingToolConfirmResolverRef.current = null;
|
|
278
|
-
}
|
|
279
|
-
return new Promise(resolve => {
|
|
280
|
-
pendingToolConfirmResolverRef.current = resolve;
|
|
281
|
-
setPendingToolConfirm({
|
|
282
|
-
...event,
|
|
283
|
-
selectedAction: 'approve',
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
},
|
|
287
|
-
onUsage: (event) => {
|
|
288
|
-
if (!isCurrentRequest()) {
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
const normalized = normalizeContextUsagePercent(event.contextUsagePercent);
|
|
292
|
-
if (normalized !== null) {
|
|
293
|
-
setContextUsagePercent(normalized);
|
|
294
|
-
}
|
|
295
|
-
const replyUsage = toReplyUsage(event);
|
|
296
|
-
if (!replyUsage) {
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
setTurns(prev => patchTurn(prev, turnId, turn => {
|
|
300
|
-
if (!turn.reply) {
|
|
301
|
-
return turn;
|
|
302
|
-
}
|
|
303
|
-
return {
|
|
304
|
-
...turn,
|
|
305
|
-
reply: {
|
|
306
|
-
...turn.reply,
|
|
307
|
-
...replyUsage,
|
|
308
|
-
},
|
|
309
|
-
};
|
|
310
|
-
}));
|
|
311
|
-
},
|
|
312
|
-
onContextUsage: (event) => {
|
|
313
|
-
if (!isCurrentRequest()) {
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
const normalized = normalizeContextUsagePercent(event.contextUsagePercent);
|
|
317
|
-
if (normalized !== null) {
|
|
318
|
-
setContextUsagePercent(normalized);
|
|
319
|
-
}
|
|
320
|
-
},
|
|
321
|
-
};
|
|
322
|
-
const runPromise = buildPromptContent(text, attachedFiles, attachmentCapabilities)
|
|
323
|
-
.then(promptContent => runAgentPrompt(promptContent, handlers, {
|
|
324
|
-
abortSignal: abortController.signal,
|
|
325
|
-
}))
|
|
326
|
-
.then(result => {
|
|
327
|
-
if (!isCurrentRequest()) {
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
setModelLabel(result.modelLabel);
|
|
331
|
-
if (result.usage) {
|
|
332
|
-
const normalized = normalizeContextUsagePercent(result.usage.contextUsagePercent);
|
|
333
|
-
if (normalized !== null) {
|
|
334
|
-
setContextUsagePercent(normalized);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
const replyUsage = toReplyUsage(result.usage);
|
|
338
|
-
setTurns(prev => {
|
|
339
|
-
const withFallbackText = patchTurn(prev, turnId, turn => {
|
|
340
|
-
if (!turn.reply || !result.text) {
|
|
341
|
-
return turn;
|
|
342
|
-
}
|
|
343
|
-
const hasAssistantText = turn.reply.segments.some(segment => (segment.type === 'text' || segment.type === 'thinking') &&
|
|
344
|
-
segment.content.trim().length > 0);
|
|
345
|
-
if (hasAssistantText) {
|
|
346
|
-
return turn;
|
|
347
|
-
}
|
|
348
|
-
return {
|
|
349
|
-
...turn,
|
|
350
|
-
reply: {
|
|
351
|
-
...turn.reply,
|
|
352
|
-
segments: orderReplySegments(appendToSegment(turn.reply.segments, `${turnId}:text`, 'text', result.text)),
|
|
353
|
-
},
|
|
354
|
-
};
|
|
355
|
-
});
|
|
356
|
-
return setReplyStatus(withFallbackText, turnId, resolveReplyStatus(result.completionReason), {
|
|
357
|
-
durationSeconds: result.durationSeconds,
|
|
358
|
-
completionReason: result.completionReason,
|
|
359
|
-
completionMessage: result.completionMessage,
|
|
360
|
-
modelLabel: result.modelLabel,
|
|
361
|
-
...(replyUsage ?? {}),
|
|
362
|
-
});
|
|
363
|
-
});
|
|
364
|
-
})
|
|
365
|
-
.catch(error => {
|
|
366
|
-
if (!isCurrentRequest()) {
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
appendEventLine(turnId, `[error] ${extractErrorMessage(error)}`);
|
|
370
|
-
setTurns(prev => setReplyStatus(prev, turnId, 'error'));
|
|
371
|
-
})
|
|
372
|
-
.finally(() => {
|
|
373
|
-
if (activeAbortControllerRef.current === abortController) {
|
|
374
|
-
activeAbortControllerRef.current = null;
|
|
375
|
-
}
|
|
376
|
-
if (activeTurnIdRef.current === turnId) {
|
|
377
|
-
activeTurnIdRef.current = null;
|
|
378
|
-
}
|
|
379
|
-
if (!isCurrentRequest()) {
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
setIsThinking(false);
|
|
383
|
-
});
|
|
384
|
-
const trackedRunPromise = runPromise.finally(() => {
|
|
385
|
-
if (activeRunPromiseRef.current === trackedRunPromise) {
|
|
386
|
-
activeRunPromiseRef.current = null;
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
activeRunPromiseRef.current = trackedRunPromise;
|
|
390
|
-
await trackedRunPromise;
|
|
391
|
-
})();
|
|
392
|
-
}, [
|
|
393
|
-
addTurn,
|
|
394
|
-
appendEventLine,
|
|
395
|
-
appendSegment,
|
|
396
|
-
attachmentCapabilities,
|
|
397
|
-
inputValue,
|
|
398
|
-
isThinking,
|
|
399
|
-
runCommand,
|
|
400
|
-
selectedFiles,
|
|
401
|
-
]);
|
|
402
|
-
const clearInput = useCallback(() => {
|
|
403
|
-
setInputValue('');
|
|
404
|
-
setSelectedFiles([]);
|
|
405
|
-
}, []);
|
|
406
|
-
const setModelLabelDisplay = useCallback((label) => {
|
|
407
|
-
setModelLabel(label);
|
|
408
|
-
void getAgentModelAttachmentCapabilities()
|
|
409
|
-
.then(capabilities => {
|
|
410
|
-
setAttachmentCapabilities(capabilities);
|
|
411
|
-
})
|
|
412
|
-
.catch(() => { });
|
|
413
|
-
}, []);
|
|
414
|
-
const setToolConfirmSelection = useCallback((selection) => {
|
|
415
|
-
setPendingToolConfirm(current => current ? { ...current, selectedAction: selection } : current);
|
|
416
|
-
}, []);
|
|
417
|
-
const rejectPendingToolConfirm = useCallback(() => {
|
|
418
|
-
resolvePendingToolConfirm({
|
|
419
|
-
approved: false,
|
|
420
|
-
message: 'Tool call denied by user.',
|
|
421
|
-
});
|
|
422
|
-
}, [resolvePendingToolConfirm]);
|
|
423
|
-
const submitToolConfirmSelection = useCallback(() => {
|
|
424
|
-
if (!pendingToolConfirm) {
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
if (pendingToolConfirm.selectedAction === 'deny') {
|
|
428
|
-
rejectPendingToolConfirm();
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
resolvePendingToolConfirm({ approved: true });
|
|
432
|
-
}, [pendingToolConfirm, rejectPendingToolConfirm, resolvePendingToolConfirm]);
|
|
433
|
-
return {
|
|
434
|
-
turns,
|
|
435
|
-
inputValue,
|
|
436
|
-
selectedFiles,
|
|
437
|
-
isThinking,
|
|
438
|
-
modelLabel,
|
|
439
|
-
contextUsagePercent,
|
|
440
|
-
pendingToolConfirm,
|
|
441
|
-
setInputValue,
|
|
442
|
-
setSelectedFiles,
|
|
443
|
-
appendSelectedFiles,
|
|
444
|
-
removeSelectedFile,
|
|
445
|
-
submitInput,
|
|
446
|
-
stopActiveReply,
|
|
447
|
-
clearInput,
|
|
448
|
-
resetConversation,
|
|
449
|
-
setModelLabelDisplay,
|
|
450
|
-
setToolConfirmSelection,
|
|
451
|
-
submitToolConfirmSelection,
|
|
452
|
-
rejectPendingToolConfirm,
|
|
453
|
-
};
|
|
454
|
-
};
|
|
455
|
-
//# sourceMappingURL=use-agent-chat.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-agent-chat.js","sourceRoot":"","sources":["../../src/hooks/use-agent-chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EACL,mCAAmC,EACnC,kBAAkB,EAClB,cAAc,GACf,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EAAE,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QAClB,WAAW;QACX,eAAe;QACf,UAAU;QACV,iBAAiB;QACjB,oBAAoB;QACpB,uBAAuB;QACvB,0BAA0B;QAC1B,wBAAwB;KACzB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { KeyEvent, TextareaRenderable } from '@opentui/core';
|
|
2
|
-
import { type RefObject } from 'react';
|
|
3
|
-
import type { PromptFileSelection } from '../files/types.js';
|
|
4
|
-
type UseFileMentionMenuParams = {
|
|
5
|
-
value: string;
|
|
6
|
-
textareaRef: RefObject<TextareaRenderable | null>;
|
|
7
|
-
selectedFiles: PromptFileSelection[];
|
|
8
|
-
onFilesSelected: (files: PromptFileSelection[]) => void;
|
|
9
|
-
onValueChange: (value: string) => void;
|
|
10
|
-
disabled?: boolean;
|
|
11
|
-
};
|
|
12
|
-
type UseFileMentionMenuResult = {
|
|
13
|
-
visible: boolean;
|
|
14
|
-
loading: boolean;
|
|
15
|
-
error: string | null;
|
|
16
|
-
options: PromptFileSelection[];
|
|
17
|
-
selectedIndex: number;
|
|
18
|
-
handleKeyDown: (event: KeyEvent) => boolean;
|
|
19
|
-
};
|
|
20
|
-
export declare const useFileMentionMenu: ({ value, textareaRef, selectedFiles, onFilesSelected, onValueChange, disabled, }: UseFileMentionMenuParams) => UseFileMentionMenuResult;
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=use-file-mention-menu.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-file-mention-menu.d.ts","sourceRoot":"","sources":["../../src/hooks/use-file-mention-menu.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAqD,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAG1F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAI1D,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,SAAS,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;IAClD,aAAa,EAAE,mBAAmB,EAAE,CAAC;IACrC,eAAe,EAAE,CAAC,KAAK,EAAE,mBAAmB,EAAE,KAAK,IAAI,CAAC;IACxD,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,OAAO,EAAE,mBAAmB,EAAE,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC;CAC7C,CAAC;AAIF,eAAO,MAAM,kBAAkB,GAAI,kFAOhC,wBAAwB,KAAG,wBAgK7B,CAAC"}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import { findTrailingFileMention } from '../files/file-mention-query.js';
|
|
3
|
-
import { isMediaSelection } from '../files/attachment-capabilities.js';
|
|
4
|
-
import { listWorkspaceFiles } from '../files/workspace-files.js';
|
|
5
|
-
const normalize = (value) => value.trim().toLowerCase();
|
|
6
|
-
export const useFileMentionMenu = ({ value, textareaRef, selectedFiles, onFilesSelected, onValueChange, disabled = false, }) => {
|
|
7
|
-
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
8
|
-
const [dismissedToken, setDismissedToken] = useState(null);
|
|
9
|
-
const [loading, setLoading] = useState(false);
|
|
10
|
-
const [error, setError] = useState(null);
|
|
11
|
-
const [allOptions, setAllOptions] = useState([]);
|
|
12
|
-
const hasLoadedRef = useRef(false);
|
|
13
|
-
const requestIdRef = useRef(0);
|
|
14
|
-
const mention = useMemo(() => findTrailingFileMention(value), [value]);
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
if (!mention || mention.token !== dismissedToken) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
setDismissedToken(null);
|
|
20
|
-
}, [dismissedToken, mention]);
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
if (disabled || !mention || hasLoadedRef.current) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
hasLoadedRef.current = true;
|
|
26
|
-
setLoading(true);
|
|
27
|
-
setError(null);
|
|
28
|
-
requestIdRef.current += 1;
|
|
29
|
-
const requestId = requestIdRef.current;
|
|
30
|
-
void listWorkspaceFiles()
|
|
31
|
-
.then(files => {
|
|
32
|
-
if (requestId !== requestIdRef.current) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
setAllOptions(files);
|
|
36
|
-
})
|
|
37
|
-
.catch(loadError => {
|
|
38
|
-
if (requestId !== requestIdRef.current) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
setError(loadError instanceof Error ? loadError.message : String(loadError));
|
|
42
|
-
})
|
|
43
|
-
.finally(() => {
|
|
44
|
-
if (requestId !== requestIdRef.current) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
setLoading(false);
|
|
48
|
-
});
|
|
49
|
-
}, [disabled, mention]);
|
|
50
|
-
const options = useMemo(() => {
|
|
51
|
-
if (!mention) {
|
|
52
|
-
return [];
|
|
53
|
-
}
|
|
54
|
-
const selectedPaths = new Set(selectedFiles.map(file => file.absolutePath));
|
|
55
|
-
const query = normalize(mention.query);
|
|
56
|
-
return allOptions.filter(item => {
|
|
57
|
-
if (selectedPaths.has(item.absolutePath)) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
return query.length === 0 || item.relativePath.toLowerCase().includes(query);
|
|
61
|
-
});
|
|
62
|
-
}, [allOptions, mention, selectedFiles]);
|
|
63
|
-
const visible = !disabled && !!mention && mention.token !== dismissedToken;
|
|
64
|
-
useEffect(() => {
|
|
65
|
-
setSelectedIndex(0);
|
|
66
|
-
}, [mention?.token]);
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
if (selectedIndex < options.length) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
setSelectedIndex(0);
|
|
72
|
-
}, [options.length, selectedIndex]);
|
|
73
|
-
const applySelection = useCallback((index) => {
|
|
74
|
-
const selected = options[index];
|
|
75
|
-
if (!selected || !mention) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
onFilesSelected([selected]);
|
|
79
|
-
const nextValue = isMediaSelection(selected)
|
|
80
|
-
? value.slice(0, mention.start)
|
|
81
|
-
: `${value.slice(0, mention.start)}@/${selected.relativePath} `;
|
|
82
|
-
onValueChange(nextValue);
|
|
83
|
-
const textarea = textareaRef.current;
|
|
84
|
-
if (textarea) {
|
|
85
|
-
textarea.setText(nextValue);
|
|
86
|
-
textarea.cursorOffset = nextValue.length;
|
|
87
|
-
}
|
|
88
|
-
return true;
|
|
89
|
-
}, [mention, onFilesSelected, onValueChange, options, textareaRef, value]);
|
|
90
|
-
const moveSelection = useCallback((step) => {
|
|
91
|
-
if (!visible || options.length === 0) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
setSelectedIndex(current => (current + step + options.length) % options.length);
|
|
95
|
-
}, [options.length, visible]);
|
|
96
|
-
const handleKeyDown = useCallback((event) => {
|
|
97
|
-
if (!visible) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
const name = (event.name ?? '').toLowerCase();
|
|
101
|
-
const ctrlOnly = !!event.ctrl && !event.shift && !event.meta;
|
|
102
|
-
const isUp = name === 'up' || (ctrlOnly && name === 'p');
|
|
103
|
-
const isDown = name === 'down' || (ctrlOnly && name === 'n');
|
|
104
|
-
if (isUp) {
|
|
105
|
-
moveSelection(-1);
|
|
106
|
-
event.preventDefault();
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
if (isDown) {
|
|
110
|
-
moveSelection(1);
|
|
111
|
-
event.preventDefault();
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
if (name === 'escape') {
|
|
115
|
-
setDismissedToken(mention?.token ?? null);
|
|
116
|
-
event.preventDefault();
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
if (name === 'return' || name === 'enter' || name === 'tab') {
|
|
120
|
-
const applied = applySelection(selectedIndex);
|
|
121
|
-
if (applied || options.length === 0) {
|
|
122
|
-
event.preventDefault();
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return false;
|
|
127
|
-
}, [applySelection, mention?.token, moveSelection, options.length, selectedIndex, visible]);
|
|
128
|
-
return {
|
|
129
|
-
visible,
|
|
130
|
-
loading,
|
|
131
|
-
error,
|
|
132
|
-
options,
|
|
133
|
-
selectedIndex,
|
|
134
|
-
handleKeyDown,
|
|
135
|
-
};
|
|
136
|
-
};
|
|
137
|
-
//# sourceMappingURL=use-file-mention-menu.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-file-mention-menu.js","sourceRoot":"","sources":["../../src/hooks/use-file-mention-menu.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AAE1F,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAoB9D,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAEhE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EACjC,KAAK,EACL,WAAW,EACX,aAAa,EACb,eAAe,EACf,aAAa,EACb,Q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