@cjhyy/code-shell 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +109 -0
- package/LICENSE +21 -0
- package/README.md +177 -0
- package/dist/agent/coordinator.d.ts +49 -0
- package/dist/anthropic-NENYS535.js +9 -0
- package/dist/anthropic-XMTTVNSH.cjs +9 -0
- package/dist/arena/arena.d.ts +43 -0
- package/dist/arena/context/context-tools.d.ts +16 -0
- package/dist/arena/detect-mode.d.ts +20 -0
- package/dist/arena/digest-builder.d.ts +25 -0
- package/dist/arena/index.cjs +103 -0
- package/dist/arena/index.d.ts +29 -0
- package/dist/arena/index.js +103 -0
- package/dist/arena/iterate/convergence.d.ts +25 -0
- package/dist/arena/iterate/formats/index.d.ts +22 -0
- package/dist/arena/iterate/index.d.ts +11 -0
- package/dist/arena/iterate/iterative-arena.d.ts +23 -0
- package/dist/arena/iterate/parse.d.ts +42 -0
- package/dist/arena/iterate/phases/argue.d.ts +22 -0
- package/dist/arena/iterate/phases/revise.d.ts +16 -0
- package/dist/arena/iterate/phases/tournament.d.ts +34 -0
- package/dist/arena/iterate/tools/web-tools.d.ts +13 -0
- package/dist/arena/iterate/types.d.ts +152 -0
- package/dist/arena/ledger.d.ts +47 -0
- package/dist/arena/lenses/architecture.d.ts +5 -0
- package/dist/arena/lenses/engineering.d.ts +5 -0
- package/dist/arena/lenses/general.d.ts +5 -0
- package/dist/arena/lenses/index.d.ts +16 -0
- package/dist/arena/lenses/product.d.ts +5 -0
- package/dist/arena/model-presets.d.ts +14 -0
- package/dist/arena/phases/adjudication.d.ts +24 -0
- package/dist/arena/phases/build-consensus.d.ts +29 -0
- package/dist/arena/phases/claim-registry.d.ts +26 -0
- package/dist/arena/phases/cross-review.d.ts +45 -0
- package/dist/arena/phases/debate-rounds.d.ts +27 -0
- package/dist/arena/phases/participant-research.d.ts +38 -0
- package/dist/arena/phases/planning-detail-expansion.d.ts +38 -0
- package/dist/arena/planner.d.ts +27 -0
- package/dist/arena/providers/docs.d.ts +6 -0
- package/dist/arena/providers/git.d.ts +8 -0
- package/dist/arena/providers/index.d.ts +16 -0
- package/dist/arena/providers/none.d.ts +7 -0
- package/dist/arena/providers/repo.d.ts +6 -0
- package/dist/arena/render/session.d.ts +17 -0
- package/dist/arena/render/terminal.d.ts +33 -0
- package/dist/arena/strategies/discussion.d.ts +25 -0
- package/dist/arena/strategies/index.d.ts +15 -0
- package/dist/arena/strategies/language-wrapper.d.ts +17 -0
- package/dist/arena/strategies/lens-wrapper.d.ts +16 -0
- package/dist/arena/strategies/planning.d.ts +30 -0
- package/dist/arena/strategies/review.d.ts +26 -0
- package/dist/arena/strategies/utils.d.ts +34 -0
- package/dist/arena/tools/selector.d.ts +17 -0
- package/dist/arena/transitions.d.ts +48 -0
- package/dist/arena/types.d.ts +499 -0
- package/dist/arena-46QQ6BZQ.js +261 -0
- package/dist/arena-HZZZ2GJH.cjs +261 -0
- package/dist/bootstrap/setup.d.ts +14 -0
- package/dist/bootstrap/state.d.ts +160 -0
- package/dist/bridge-4ZRXVWBN.js +98 -0
- package/dist/bridge-W476QDFH.cjs +98 -0
- package/dist/chunk-3EAEC566.cjs +136 -0
- package/dist/chunk-3EUDE77E.cjs +1252 -0
- package/dist/chunk-3QR52LL5.cjs +105 -0
- package/dist/chunk-4PKZPFCD.js +136 -0
- package/dist/chunk-4RRUP4MM.js +86 -0
- package/dist/chunk-4SFPFHMG.js +132 -0
- package/dist/chunk-5LHVI777.cjs +246 -0
- package/dist/chunk-6JOOLG6F.js +104 -0
- package/dist/chunk-6ZIROYXX.js +207 -0
- package/dist/chunk-7RMAR2Y3.js +6511 -0
- package/dist/chunk-BE6IPRDM.js +224 -0
- package/dist/chunk-BHGIJ2DJ.js +41 -0
- package/dist/chunk-BMH65OVB.cjs +224 -0
- package/dist/chunk-C7JBCO5V.js +80 -0
- package/dist/chunk-CSO5EOEP.cjs +132 -0
- package/dist/chunk-DI7RDLOS.js +47 -0
- package/dist/chunk-DICG4AB7.cjs +73 -0
- package/dist/chunk-EL2RL5DG.cjs +101 -0
- package/dist/chunk-FGZGCFJX.cjs +207 -0
- package/dist/chunk-FUOKLKR2.js +101 -0
- package/dist/chunk-FVP7XJGS.cjs +4577 -0
- package/dist/chunk-HD7MT5XU.cjs +86 -0
- package/dist/chunk-IJSHQGMP.cjs +45 -0
- package/dist/chunk-IMMTBZ33.cjs +63 -0
- package/dist/chunk-J5XW6UYL.js +291 -0
- package/dist/chunk-JT2WSQSR.cjs +335 -0
- package/dist/chunk-KO2FPF7G.js +93 -0
- package/dist/chunk-LRAY5IYC.cjs +291 -0
- package/dist/chunk-NG73UR3L.cjs +285 -0
- package/dist/chunk-NZ4DQ72D.cjs +664 -0
- package/dist/chunk-O6F2EF2Z.js +73 -0
- package/dist/chunk-OG4MIQJ6.js +335 -0
- package/dist/chunk-QHDYFC5U.cjs +6511 -0
- package/dist/chunk-R32DJSJE.cjs +41 -0
- package/dist/chunk-S74VVJBF.js +285 -0
- package/dist/chunk-SK62UVS6.js +105 -0
- package/dist/chunk-SQZHPD3S.js +4577 -0
- package/dist/chunk-UK2SU23S.cjs +93 -0
- package/dist/chunk-VKGNCYRL.js +258 -0
- package/dist/chunk-WFQF3RT4.cjs +104 -0
- package/dist/chunk-WHRTARDJ.cjs +258 -0
- package/dist/chunk-WRZJUQ5Z.js +664 -0
- package/dist/chunk-X4HAERTQ.js +63 -0
- package/dist/chunk-XHC2JMEC.cjs +80 -0
- package/dist/chunk-YZ25SSWJ.js +222 -0
- package/dist/chunk-ZJV3YSY3.cjs +222 -0
- package/dist/chunk-ZRSSGYA5.js +246 -0
- package/dist/chunk-ZXYDDJEJ.js +1252 -0
- package/dist/cli/commands/arena.d.ts +29 -0
- package/dist/cli/commands/builtin/advanced-commands.d.ts +5 -0
- package/dist/cli/commands/builtin/core-commands.d.ts +5 -0
- package/dist/cli/commands/builtin/extra-commands.d.ts +6 -0
- package/dist/cli/commands/builtin/git-commands.d.ts +5 -0
- package/dist/cli/commands/builtin/more-commands.d.ts +7 -0
- package/dist/cli/commands/builtin/permissions-command.d.ts +5 -0
- package/dist/cli/commands/builtin/utility-commands.d.ts +5 -0
- package/dist/cli/commands/registry.d.ts +64 -0
- package/dist/cli/commands/repl.d.ts +21 -0
- package/dist/cli/commands/run.d.ts +21 -0
- package/dist/cli/commands/runs.d.ts +14 -0
- package/dist/cli/cost-tracker.d.ts +57 -0
- package/dist/cli/exit.d.ts +12 -0
- package/dist/cli/input/ndjson-reader.d.ts +31 -0
- package/dist/cli/input-compiler.d.ts +5 -0
- package/dist/cli/main.cjs +19674 -0
- package/dist/cli/main.d.ts +5 -0
- package/dist/cli/main.js +19674 -0
- package/dist/cli/onboarding.d.ts +26 -0
- package/dist/cli/output/renderer.d.ts +28 -0
- package/dist/cli/output/terminal-ui.d.ts +50 -0
- package/dist/cli/updater.d.ts +10 -0
- package/dist/compaction-44I55TLI.cjs +32 -0
- package/dist/compaction-CCHWA4G6.js +32 -0
- package/dist/context/compaction.d.ts +83 -0
- package/dist/context/manager.d.ts +99 -0
- package/dist/context/token-counter.d.ts +27 -0
- package/dist/coordinator-5HY7ALO2.js +7 -0
- package/dist/coordinator-INDLPVMF.cjs +7 -0
- package/dist/cost-tracker-IWYAUPXH.js +9 -0
- package/dist/cost-tracker-JXTJQQWE.cjs +9 -0
- package/dist/cron/scheduler.d.ts +34 -0
- package/dist/devtools-KIY3LWQJ.js +6 -0
- package/dist/devtools-LRP47DDV.cjs +6 -0
- package/dist/engine/cost-store.d.ts +22 -0
- package/dist/engine/engine.d.ts +101 -0
- package/dist/engine/model-facade.d.ts +24 -0
- package/dist/engine/query.d.ts +50 -0
- package/dist/engine/streaming-tool-queue.d.ts +34 -0
- package/dist/engine/token-budget.d.ts +22 -0
- package/dist/engine/tool-summary.d.ts +13 -0
- package/dist/engine/turn-loop.d.ts +62 -0
- package/dist/engine/turn-state.d.ts +14 -0
- package/dist/exceptions.d.ts +44 -0
- package/dist/file-history-HZWO2WQ5.js +7 -0
- package/dist/file-history-UQQILIY7.cjs +7 -0
- package/dist/git/utils.d.ts +35 -0
- package/dist/git/worktree.d.ts +36 -0
- package/dist/hooks/events.d.ts +35 -0
- package/dist/hooks/registry.d.ts +15 -0
- package/dist/index.cjs +336 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +336 -0
- package/dist/ink/Ansi.d.ts +10 -0
- package/dist/ink/bidi.d.ts +15 -0
- package/dist/ink/clearTerminal.d.ts +13 -0
- package/dist/ink/colorize.d.ts +16 -0
- package/dist/ink/components/AlternateScreen.d.ts +21 -0
- package/dist/ink/components/App.d.ts +70 -0
- package/dist/ink/components/AppContext.d.ts +11 -0
- package/dist/ink/components/Box.d.ts +49 -0
- package/dist/ink/components/Button.d.ts +36 -0
- package/dist/ink/components/ClockContext.d.ts +9 -0
- package/dist/ink/components/CursorDeclarationContext.d.ts +22 -0
- package/dist/ink/components/ErrorOverview.d.ts +5 -0
- package/dist/ink/components/Link.d.ts +7 -0
- package/dist/ink/components/Newline.d.ts +12 -0
- package/dist/ink/components/NoSelect.d.ts +19 -0
- package/dist/ink/components/RawAnsi.d.ts +16 -0
- package/dist/ink/components/ScrollBox.d.ts +78 -0
- package/dist/ink/components/Spacer.d.ts +5 -0
- package/dist/ink/components/StdinContext.d.ts +27 -0
- package/dist/ink/components/TerminalFocusContext.d.ts +10 -0
- package/dist/ink/components/TerminalSizeContext.d.ts +5 -0
- package/dist/ink/components/Text.d.ts +55 -0
- package/dist/ink/constants.d.ts +1 -0
- package/dist/ink/cursor.d.ts +8 -0
- package/dist/ink/devtools.d.ts +5 -0
- package/dist/ink/dom.d.ts +76 -0
- package/dist/ink/events/click-event.d.ts +31 -0
- package/dist/ink/events/dispatcher.d.ts +40 -0
- package/dist/ink/events/emitter.d.ts +5 -0
- package/dist/ink/events/event-handlers.d.ts +46 -0
- package/dist/ink/events/event.d.ts +5 -0
- package/dist/ink/events/focus-event.d.ts +13 -0
- package/dist/ink/events/input-event.d.ts +30 -0
- package/dist/ink/events/keyboard-event.d.ts +19 -0
- package/dist/ink/events/paste-event.d.ts +8 -0
- package/dist/ink/events/resize-event.d.ts +9 -0
- package/dist/ink/events/terminal-event.d.ts +54 -0
- package/dist/ink/events/terminal-focus-event.d.ts +13 -0
- package/dist/ink/focus.d.ts +43 -0
- package/dist/ink/frame.d.ts +94 -0
- package/dist/ink/get-max-width.d.ts +17 -0
- package/dist/ink/hit-test.d.ts +33 -0
- package/dist/ink/hooks/use-animation-frame.d.ts +26 -0
- package/dist/ink/hooks/use-app.d.ts +5 -0
- package/dist/ink/hooks/use-declared-cursor.d.ts +26 -0
- package/dist/ink/hooks/use-input.d.ts +37 -0
- package/dist/ink/hooks/use-interval.d.ts +18 -0
- package/dist/ink/hooks/use-search-highlight.d.ts +30 -0
- package/dist/ink/hooks/use-selection.d.ts +39 -0
- package/dist/ink/hooks/use-stdin.d.ts +5 -0
- package/dist/ink/hooks/use-tab-status.d.ts +13 -0
- package/dist/ink/hooks/use-terminal-focus.d.ts +10 -0
- package/dist/ink/hooks/use-terminal-title.d.ts +12 -0
- package/dist/ink/hooks/use-terminal-viewport.d.ts +29 -0
- package/dist/ink/index.d.ts +20 -0
- package/dist/ink/ink.d.ts +369 -0
- package/dist/ink/instances.d.ts +3 -0
- package/dist/ink/layout/engine.d.ts +2 -0
- package/dist/ink/layout/geometry.d.ts +30 -0
- package/dist/ink/layout/node.d.ts +125 -0
- package/dist/ink/layout/yoga.d.ts +56 -0
- package/dist/ink/line-width-cache.d.ts +1 -0
- package/dist/ink/log-update.d.ts +17 -0
- package/dist/ink/measure-element.d.ts +16 -0
- package/dist/ink/measure-text.d.ts +6 -0
- package/dist/ink/node-cache.d.ts +20 -0
- package/dist/ink/optimizer.d.ts +15 -0
- package/dist/ink/output.d.ts +119 -0
- package/dist/ink/parse-keypress.d.ts +111 -0
- package/dist/ink/reconciler.d.ts +11 -0
- package/dist/ink/render-border.d.ts +24 -0
- package/dist/ink/render-node-to-output.d.ts +45 -0
- package/dist/ink/render-to-screen.d.ts +46 -0
- package/dist/ink/renderer.d.ts +14 -0
- package/dist/ink/root.d.ts +74 -0
- package/dist/ink/screen.d.ts +269 -0
- package/dist/ink/searchHighlight.d.ts +20 -0
- package/dist/ink/selection.d.ts +229 -0
- package/dist/ink/squash-text-nodes.d.ts +22 -0
- package/dist/ink/stringWidth.d.ts +1 -0
- package/dist/ink/styles.d.ts +306 -0
- package/dist/ink/supports-hyperlinks.d.ts +13 -0
- package/dist/ink/tabstops.d.ts +1 -0
- package/dist/ink/terminal-focus-state.d.ts +6 -0
- package/dist/ink/terminal-querier.d.ts +129 -0
- package/dist/ink/terminal.d.ts +46 -0
- package/dist/ink/termio/ansi.d.ts +65 -0
- package/dist/ink/termio/csi.d.ts +165 -0
- package/dist/ink/termio/dec.d.ts +37 -0
- package/dist/ink/termio/esc.d.ts +12 -0
- package/dist/ink/termio/osc.d.ts +173 -0
- package/dist/ink/termio/parser.d.ts +35 -0
- package/dist/ink/termio/sgr.d.ts +8 -0
- package/dist/ink/termio/tokenize.d.ts +45 -0
- package/dist/ink/termio/types.d.ts +190 -0
- package/dist/ink/termio.d.ts +24 -0
- package/dist/ink/useTerminalNotification.d.ts +28 -0
- package/dist/ink/warn.d.ts +1 -0
- package/dist/ink/widest-line.d.ts +1 -0
- package/dist/ink/wrap-text.d.ts +2 -0
- package/dist/ink/wrapAnsi.d.ts +7 -0
- package/dist/llm/client-base.d.ts +22 -0
- package/dist/llm/client-factory.d.ts +10 -0
- package/dist/llm/model-pool.d.ts +60 -0
- package/dist/llm/providers/anthropic.d.ts +19 -0
- package/dist/llm/providers/openai.d.ts +19 -0
- package/dist/llm/types.d.ts +21 -0
- package/dist/loader-DXFSUB4R.cjs +91 -0
- package/dist/loader-J5UID6CV.js +91 -0
- package/dist/logging/logger.d.ts +19 -0
- package/dist/lsp/client.d.ts +41 -0
- package/dist/lsp/manager.d.ts +40 -0
- package/dist/lsp/servers.d.ts +16 -0
- package/dist/manager-ETWDOCHN.cjs +9 -0
- package/dist/manager-HGMQNEJB.cjs +11 -0
- package/dist/manager-HUAQOORS.js +9 -0
- package/dist/manager-VJIZ2CQC.js +11 -0
- package/dist/mcp-manager-G4G2QASE.cjs +8 -0
- package/dist/mcp-manager-OKXHHWYR.js +8 -0
- package/dist/memory-AP747G5H.js +7 -0
- package/dist/memory-BH3BYUN5.cjs +7 -0
- package/dist/native-ts/yoga-layout/enums.d.ts +117 -0
- package/dist/native-ts/yoga-layout/index.d.ts +270 -0
- package/dist/onboarding-6WEPV7C2.js +11 -0
- package/dist/onboarding-QM5DY2TU.cjs +11 -0
- package/dist/openai-5HQGBL4L.js +9 -0
- package/dist/openai-656VWUQW.cjs +9 -0
- package/dist/plugins/loader.d.ts +72 -0
- package/dist/plugins/types.d.ts +4 -0
- package/dist/preset/index.d.ts +60 -0
- package/dist/product/define.d.ts +60 -0
- package/dist/product/index.cjs +23 -0
- package/dist/product/index.d.ts +5 -0
- package/dist/product/index.js +23 -0
- package/dist/product/types.d.ts +116 -0
- package/dist/prompt/composer.d.ts +42 -0
- package/dist/prompt/instruction-scanner.d.ts +54 -0
- package/dist/prompt/section-cache.d.ts +15 -0
- package/dist/prompt/section-loader.d.ts +26 -0
- package/dist/protocol/client.d.ts +64 -0
- package/dist/protocol/index.d.ts +4 -0
- package/dist/protocol/server.d.ts +49 -0
- package/dist/protocol/transport.d.ts +36 -0
- package/dist/protocol/types.d.ts +150 -0
- package/dist/react-compiler-runtime-shim.d.ts +1 -0
- package/dist/remote/bridge.d.ts +37 -0
- package/dist/run/ArtifactTracker.d.ts +38 -0
- package/dist/run/CheckpointWriter.d.ts +53 -0
- package/dist/run/EngineRunner.d.ts +70 -0
- package/dist/run/Evaluator.d.ts +56 -0
- package/dist/run/FileRunStore.d.ts +39 -0
- package/dist/run/Heartbeat.d.ts +54 -0
- package/dist/run/RunApprovalBackend.d.ts +53 -0
- package/dist/run/RunLock.d.ts +40 -0
- package/dist/run/RunManager.d.ts +76 -0
- package/dist/run/RunQueue.d.ts +27 -0
- package/dist/run/RunStore.d.ts +25 -0
- package/dist/run/factory.d.ts +57 -0
- package/dist/run/index.cjs +50 -0
- package/dist/run/index.d.ts +17 -0
- package/dist/run/index.js +50 -0
- package/dist/run/types.d.ts +136 -0
- package/dist/services/analytics.d.ts +29 -0
- package/dist/services/auto-dream.d.ts +35 -0
- package/dist/services/compact.d.ts +56 -0
- package/dist/services/diagnostics.d.ts +41 -0
- package/dist/services/extract-memories.d.ts +27 -0
- package/dist/services/index.d.ts +11 -0
- package/dist/services/notifier.d.ts +25 -0
- package/dist/services/oauth.d.ts +27 -0
- package/dist/services/session-memory.d.ts +37 -0
- package/dist/session/file-history.d.ts +41 -0
- package/dist/session/memory.d.ts +45 -0
- package/dist/session/session-manager.d.ts +23 -0
- package/dist/session/transcript.d.ts +39 -0
- package/dist/session-manager-JIIBCFTC.js +8 -0
- package/dist/session-manager-UQKB564H.cjs +8 -0
- package/dist/settings/manager.d.ts +27 -0
- package/dist/settings/schema.d.ts +676 -0
- package/dist/skills/index.d.ts +7 -0
- package/dist/skills/matcher.d.ts +21 -0
- package/dist/skills/scanner.d.ts +30 -0
- package/dist/skills-63RBYQRX.js +13 -0
- package/dist/skills-V3BPLW3D.cjs +13 -0
- package/dist/token-counter-CHAXW5O7.cjs +13 -0
- package/dist/token-counter-DSOZGZ5Q.js +13 -0
- package/dist/tool-summary-5P2GKRA4.cjs +31 -0
- package/dist/tool-summary-J2ICNMWP.js +31 -0
- package/dist/tool-system/builtin/agent.d.ts +35 -0
- package/dist/tool-system/builtin/arena.d.ts +18 -0
- package/dist/tool-system/builtin/ask-user.d.ts +12 -0
- package/dist/tool-system/builtin/bash.d.ts +6 -0
- package/dist/tool-system/builtin/brief.d.ts +6 -0
- package/dist/tool-system/builtin/config.d.ts +6 -0
- package/dist/tool-system/builtin/cron.d.ts +10 -0
- package/dist/tool-system/builtin/edit.d.ts +6 -0
- package/dist/tool-system/builtin/file-cache.d.ts +11 -0
- package/dist/tool-system/builtin/glob.d.ts +6 -0
- package/dist/tool-system/builtin/grep.d.ts +6 -0
- package/dist/tool-system/builtin/index.d.ts +10 -0
- package/dist/tool-system/builtin/lsp.d.ts +6 -0
- package/dist/tool-system/builtin/mcp-tools.d.ts +10 -0
- package/dist/tool-system/builtin/notebook-edit.d.ts +6 -0
- package/dist/tool-system/builtin/plan.d.ts +18 -0
- package/dist/tool-system/builtin/powershell.d.ts +6 -0
- package/dist/tool-system/builtin/read.d.ts +6 -0
- package/dist/tool-system/builtin/remote-trigger.d.ts +6 -0
- package/dist/tool-system/builtin/repl.d.ts +6 -0
- package/dist/tool-system/builtin/send-message.d.ts +6 -0
- package/dist/tool-system/builtin/skill.d.ts +6 -0
- package/dist/tool-system/builtin/sleep.d.ts +6 -0
- package/dist/tool-system/builtin/task.d.ts +51 -0
- package/dist/tool-system/builtin/tool-search.d.ts +12 -0
- package/dist/tool-system/builtin/web-fetch.d.ts +6 -0
- package/dist/tool-system/builtin/web-search.d.ts +6 -0
- package/dist/tool-system/builtin/worktree.d.ts +10 -0
- package/dist/tool-system/builtin/write.d.ts +6 -0
- package/dist/tool-system/executor.d.ts +25 -0
- package/dist/tool-system/mcp-manager.d.ts +50 -0
- package/dist/tool-system/permission.d.ts +69 -0
- package/dist/tool-system/registry.d.ts +24 -0
- package/dist/tool-system/validation.d.ts +5 -0
- package/dist/types.d.ts +260 -0
- package/dist/ui/App.d.ts +14 -0
- package/dist/ui/components/AgentBlock.d.ts +32 -0
- package/dist/ui/components/BabyHand.d.ts +1 -0
- package/dist/ui/components/Banner.d.ts +8 -0
- package/dist/ui/components/CodeBlock.d.ts +7 -0
- package/dist/ui/components/CommandInput.d.ts +13 -0
- package/dist/ui/components/ContextUsageBar.d.ts +7 -0
- package/dist/ui/components/DiffView.d.ts +6 -0
- package/dist/ui/components/DogLogo.d.ts +1 -0
- package/dist/ui/components/FullscreenLayout.d.ts +51 -0
- package/dist/ui/components/KunHead.d.ts +1 -0
- package/dist/ui/components/KunLogo.d.ts +1 -0
- package/dist/ui/components/MessageContent.d.ts +22 -0
- package/dist/ui/components/PermissionDialog.d.ts +8 -0
- package/dist/ui/components/PermissionPrompt.d.ts +8 -0
- package/dist/ui/components/ScrollView.d.ts +34 -0
- package/dist/ui/components/Spinner.d.ts +8 -0
- package/dist/ui/components/SpinnerWithVerb.d.ts +13 -0
- package/dist/ui/components/StatusLine.d.ts +22 -0
- package/dist/ui/components/StructuredDiff.d.ts +8 -0
- package/dist/ui/components/TaskList.d.ts +6 -0
- package/dist/ui/components/TextInput.d.ts +9 -0
- package/dist/ui/components/ThemedBox.d.ts +19 -0
- package/dist/ui/components/ThemedText.d.ts +26 -0
- package/dist/ui/components/ToolCall.d.ts +21 -0
- package/dist/ui/components/VirtualMessageList.d.ts +24 -0
- package/dist/ui/hooks/useCostSummary.d.ts +1 -0
- package/dist/ui/index.d.ts +12 -0
- package/dist/ui/input-history.d.ts +61 -0
- package/dist/ui/store.d.ts +82 -0
- package/dist/ui/terminal-renderer.d.ts +45 -0
- package/dist/ui/theme.d.ts +36 -0
- package/dist/ui/vim-mode.d.ts +25 -0
- package/dist/updater-AVD4LKTQ.js +183 -0
- package/dist/updater-URVNPDPW.cjs +183 -0
- package/dist/utils/debug.d.ts +57 -0
- package/dist/utils/earlyInput.d.ts +43 -0
- package/dist/utils/env.d.ts +24 -0
- package/dist/utils/envUtils.d.ts +51 -0
- package/dist/utils/execFileNoThrow.d.ts +39 -0
- package/dist/utils/format.d.ts +44 -0
- package/dist/utils/fullscreen.d.ts +47 -0
- package/dist/utils/intl.d.ts +22 -0
- package/dist/utils/lockfile.d.ts +15 -0
- package/dist/utils/log.d.ts +56 -0
- package/dist/utils/semver.d.ts +5 -0
- package/dist/utils/sliceAnsi.d.ts +12 -0
- package/dist/utils/systemTheme.d.ts +40 -0
- package/dist/utils/theme.d.ts +91 -0
- package/dist/utils/toolDisplay.d.ts +31 -0
- package/dist/utils/truncate.d.ts +40 -0
- package/dist/voice/index.d.ts +35 -0
- package/dist/voice-KTZ7PAGO.js +80 -0
- package/dist/voice-KZE25GKB.cjs +80 -0
- package/package.json +130 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_esm_shims
|
|
3
|
+
} from "./chunk-DI7RDLOS.js";
|
|
4
|
+
|
|
5
|
+
// src/logging/logger.ts
|
|
6
|
+
init_esm_shims();
|
|
7
|
+
import { appendFileSync, mkdirSync, existsSync } from "fs";
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
import { homedir } from "os";
|
|
10
|
+
var LEVEL_ORDER = {
|
|
11
|
+
debug: 0,
|
|
12
|
+
info: 1,
|
|
13
|
+
warn: 2,
|
|
14
|
+
error: 3
|
|
15
|
+
};
|
|
16
|
+
var Logger = class {
|
|
17
|
+
logDir;
|
|
18
|
+
minLevel;
|
|
19
|
+
enabled;
|
|
20
|
+
constructor() {
|
|
21
|
+
this.logDir = join(homedir(), ".code-shell", "logs");
|
|
22
|
+
this.minLevel = process.env.CODE_SHELL_LOG_LEVEL ?? "info";
|
|
23
|
+
this.enabled = process.env.CODE_SHELL_LOG !== "0";
|
|
24
|
+
}
|
|
25
|
+
debug(msg, data) {
|
|
26
|
+
this.log("debug", msg, data);
|
|
27
|
+
}
|
|
28
|
+
info(msg, data) {
|
|
29
|
+
this.log("info", msg, data);
|
|
30
|
+
}
|
|
31
|
+
warn(msg, data) {
|
|
32
|
+
this.log("warn", msg, data);
|
|
33
|
+
}
|
|
34
|
+
error(msg, data) {
|
|
35
|
+
this.log("error", msg, data);
|
|
36
|
+
}
|
|
37
|
+
log(level, msg, data) {
|
|
38
|
+
if (!this.enabled) return;
|
|
39
|
+
if (LEVEL_ORDER[level] < LEVEL_ORDER[this.minLevel]) return;
|
|
40
|
+
const now = /* @__PURE__ */ new Date();
|
|
41
|
+
const timestamp = now.toISOString();
|
|
42
|
+
const dateStr = timestamp.split("T")[0];
|
|
43
|
+
const entry = {
|
|
44
|
+
t: timestamp,
|
|
45
|
+
l: level,
|
|
46
|
+
msg
|
|
47
|
+
};
|
|
48
|
+
if (data) entry.d = data;
|
|
49
|
+
try {
|
|
50
|
+
if (!existsSync(this.logDir)) {
|
|
51
|
+
mkdirSync(this.logDir, { recursive: true });
|
|
52
|
+
}
|
|
53
|
+
const logFile = join(this.logDir, `${dateStr}.log`);
|
|
54
|
+
appendFileSync(logFile, JSON.stringify(entry) + "\n", "utf-8");
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var logger = new Logger();
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
logger
|
|
63
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
|
|
2
|
+
|
|
3
|
+
var _chunkIJSHQGMPcjs = require('./chunk-IJSHQGMP.cjs');
|
|
4
|
+
|
|
5
|
+
// src/agent/coordinator.ts
|
|
6
|
+
_chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
|
|
7
|
+
var AgentCoordinator = (_class = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this); }
|
|
8
|
+
__init() {this.agents = /* @__PURE__ */ new Map()}
|
|
9
|
+
__init2() {this.inbox = /* @__PURE__ */ new Map()}
|
|
10
|
+
/** Register a named agent. */
|
|
11
|
+
register(id, name, description) {
|
|
12
|
+
this.agents.set(name, {
|
|
13
|
+
id,
|
|
14
|
+
name,
|
|
15
|
+
status: "running",
|
|
16
|
+
description,
|
|
17
|
+
startedAt: Date.now()
|
|
18
|
+
});
|
|
19
|
+
if (!this.inbox.has(name)) {
|
|
20
|
+
this.inbox.set(name, []);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Mark an agent as completed. */
|
|
24
|
+
complete(name, result) {
|
|
25
|
+
const agent = this.agents.get(name);
|
|
26
|
+
if (agent) {
|
|
27
|
+
agent.status = "completed";
|
|
28
|
+
agent.completedAt = Date.now();
|
|
29
|
+
agent.result = result;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Mark an agent as failed. */
|
|
33
|
+
fail(name) {
|
|
34
|
+
const agent = this.agents.get(name);
|
|
35
|
+
if (agent) {
|
|
36
|
+
agent.status = "failed";
|
|
37
|
+
agent.completedAt = Date.now();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Get agent info by name. */
|
|
41
|
+
get(name) {
|
|
42
|
+
return this.agents.get(name);
|
|
43
|
+
}
|
|
44
|
+
/** List all agents. */
|
|
45
|
+
list() {
|
|
46
|
+
return [...this.agents.values()];
|
|
47
|
+
}
|
|
48
|
+
/** List active (running) agents. */
|
|
49
|
+
listActive() {
|
|
50
|
+
return [...this.agents.values()].filter((a) => a.status === "running");
|
|
51
|
+
}
|
|
52
|
+
/** Send a message to a named agent. */
|
|
53
|
+
send(from, to, content) {
|
|
54
|
+
if (!this.agents.has(to)) return false;
|
|
55
|
+
const messages = _nullishCoalesce(this.inbox.get(to), () => ( []));
|
|
56
|
+
messages.push({ from, to, content, timestamp: Date.now() });
|
|
57
|
+
this.inbox.set(to, messages);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
/** Read messages for a named agent (drains the inbox). */
|
|
61
|
+
receive(name) {
|
|
62
|
+
const messages = _nullishCoalesce(this.inbox.get(name), () => ( []));
|
|
63
|
+
this.inbox.set(name, []);
|
|
64
|
+
return messages;
|
|
65
|
+
}
|
|
66
|
+
/** Peek at messages without draining. */
|
|
67
|
+
peek(name) {
|
|
68
|
+
return _nullishCoalesce(this.inbox.get(name), () => ( []));
|
|
69
|
+
}
|
|
70
|
+
/** Reset all state. */
|
|
71
|
+
reset() {
|
|
72
|
+
this.agents.clear();
|
|
73
|
+
this.inbox.clear();
|
|
74
|
+
}
|
|
75
|
+
}, _class);
|
|
76
|
+
var agentCoordinator = new AgentCoordinator();
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
exports.agentCoordinator = agentCoordinator;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LLMClientBase
|
|
3
|
+
} from "./chunk-O6F2EF2Z.js";
|
|
4
|
+
import {
|
|
5
|
+
ContextLimitError,
|
|
6
|
+
LLMError,
|
|
7
|
+
LLMRateLimitError
|
|
8
|
+
} from "./chunk-FUOKLKR2.js";
|
|
9
|
+
import {
|
|
10
|
+
init_esm_shims
|
|
11
|
+
} from "./chunk-DI7RDLOS.js";
|
|
12
|
+
|
|
13
|
+
// src/llm/providers/anthropic.ts
|
|
14
|
+
init_esm_shims();
|
|
15
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
16
|
+
var AnthropicClient = class extends LLMClientBase {
|
|
17
|
+
_client = null;
|
|
18
|
+
constructor(config) {
|
|
19
|
+
super(config);
|
|
20
|
+
}
|
|
21
|
+
initClient() {
|
|
22
|
+
}
|
|
23
|
+
get client() {
|
|
24
|
+
if (!this._client) {
|
|
25
|
+
this._client = new Anthropic({
|
|
26
|
+
apiKey: this.config.apiKey ?? process.env.ANTHROPIC_API_KEY,
|
|
27
|
+
...this.config.baseUrl ? { baseURL: this.config.baseUrl } : {},
|
|
28
|
+
timeout: this.timeout
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return this._client;
|
|
32
|
+
}
|
|
33
|
+
async createMessage(options) {
|
|
34
|
+
return this.withRetry(async () => {
|
|
35
|
+
const messages = this.buildMessages(options.messages);
|
|
36
|
+
const tools = options.tools ? this.convertTools(options.tools) : void 0;
|
|
37
|
+
if (options.stream && options.onChunk) {
|
|
38
|
+
return this.streamMessage(options, messages, tools);
|
|
39
|
+
}
|
|
40
|
+
return this.nonStreamMessage(options, messages, tools);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async nonStreamMessage(options, messages, tools) {
|
|
44
|
+
try {
|
|
45
|
+
const response = await this.client.messages.create(
|
|
46
|
+
{
|
|
47
|
+
model: this.model,
|
|
48
|
+
max_tokens: options.maxTokens ?? this.maxTokens,
|
|
49
|
+
system: [
|
|
50
|
+
{
|
|
51
|
+
type: "text",
|
|
52
|
+
text: options.systemPrompt,
|
|
53
|
+
cache_control: { type: "ephemeral" }
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
messages,
|
|
57
|
+
...tools?.length ? { tools } : {},
|
|
58
|
+
...options.temperature !== void 0 ? { temperature: options.temperature } : { temperature: this.temperature }
|
|
59
|
+
},
|
|
60
|
+
{ signal: options.signal }
|
|
61
|
+
);
|
|
62
|
+
const usage = {
|
|
63
|
+
promptTokens: response.usage.input_tokens,
|
|
64
|
+
completionTokens: response.usage.output_tokens,
|
|
65
|
+
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
66
|
+
cacheReadTokens: response.usage.cache_read_input_tokens,
|
|
67
|
+
cacheCreationTokens: response.usage.cache_creation_input_tokens
|
|
68
|
+
};
|
|
69
|
+
this.recordUsage(usage);
|
|
70
|
+
return this.processResponse(response, usage);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
this.handleApiError(err);
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async streamMessage(options, messages, tools) {
|
|
77
|
+
try {
|
|
78
|
+
const stream = this.client.messages.stream(
|
|
79
|
+
{
|
|
80
|
+
model: this.model,
|
|
81
|
+
max_tokens: options.maxTokens ?? this.maxTokens,
|
|
82
|
+
system: [
|
|
83
|
+
{
|
|
84
|
+
type: "text",
|
|
85
|
+
text: options.systemPrompt,
|
|
86
|
+
cache_control: { type: "ephemeral" }
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
messages,
|
|
90
|
+
...tools?.length ? { tools } : {},
|
|
91
|
+
...options.temperature !== void 0 ? { temperature: options.temperature } : { temperature: this.temperature }
|
|
92
|
+
},
|
|
93
|
+
{ signal: options.signal }
|
|
94
|
+
);
|
|
95
|
+
let currentText = "";
|
|
96
|
+
let currentToolName = "";
|
|
97
|
+
let currentToolId = "";
|
|
98
|
+
let currentToolInput = "";
|
|
99
|
+
stream.on("text", (text) => {
|
|
100
|
+
currentText += text;
|
|
101
|
+
options.onChunk?.({ type: "text", text });
|
|
102
|
+
});
|
|
103
|
+
stream.on("contentBlock", (block) => {
|
|
104
|
+
if (block.type === "tool_use") {
|
|
105
|
+
currentToolName = block.name;
|
|
106
|
+
currentToolId = block.id;
|
|
107
|
+
currentToolInput = "";
|
|
108
|
+
options.onChunk?.({
|
|
109
|
+
type: "tool_use_start",
|
|
110
|
+
toolCall: { id: block.id, toolName: block.name, args: {} }
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
stream.on("inputJson", (_delta, snapshot) => {
|
|
115
|
+
currentToolInput = JSON.stringify(snapshot);
|
|
116
|
+
});
|
|
117
|
+
const finalMessage = await stream.finalMessage();
|
|
118
|
+
const usage = {
|
|
119
|
+
promptTokens: finalMessage.usage.input_tokens,
|
|
120
|
+
completionTokens: finalMessage.usage.output_tokens,
|
|
121
|
+
totalTokens: finalMessage.usage.input_tokens + finalMessage.usage.output_tokens,
|
|
122
|
+
cacheReadTokens: finalMessage.usage.cache_read_input_tokens,
|
|
123
|
+
cacheCreationTokens: finalMessage.usage.cache_creation_input_tokens
|
|
124
|
+
};
|
|
125
|
+
this.recordUsage(usage);
|
|
126
|
+
options.onChunk?.({ type: "stop", stopReason: finalMessage.stop_reason ?? void 0 });
|
|
127
|
+
return this.processResponse(finalMessage, usage);
|
|
128
|
+
} catch (err) {
|
|
129
|
+
this.handleApiError(err);
|
|
130
|
+
throw err;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
processResponse(response, usage) {
|
|
134
|
+
let text = "";
|
|
135
|
+
const toolCalls = [];
|
|
136
|
+
for (const block of response.content) {
|
|
137
|
+
if (block.type === "text") {
|
|
138
|
+
text += block.text;
|
|
139
|
+
} else if (block.type === "tool_use") {
|
|
140
|
+
toolCalls.push({
|
|
141
|
+
id: block.id,
|
|
142
|
+
toolName: block.name,
|
|
143
|
+
args: block.input ?? {}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
text,
|
|
149
|
+
toolCalls,
|
|
150
|
+
usage,
|
|
151
|
+
stopReason: response.stop_reason ?? void 0
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
buildMessages(messages) {
|
|
155
|
+
const result = [];
|
|
156
|
+
for (const msg of messages) {
|
|
157
|
+
if (msg.role === "system") continue;
|
|
158
|
+
const role = msg.role === "tool" ? "user" : msg.role;
|
|
159
|
+
if (typeof msg.content === "string") {
|
|
160
|
+
result.push({ role, content: msg.content });
|
|
161
|
+
} else {
|
|
162
|
+
const blocks = [];
|
|
163
|
+
for (const block of msg.content) {
|
|
164
|
+
if (block.type === "text" && block.text) {
|
|
165
|
+
blocks.push({ type: "text", text: block.text });
|
|
166
|
+
} else if (block.type === "tool_use" && block.id && block.name && block.input) {
|
|
167
|
+
blocks.push({
|
|
168
|
+
type: "tool_use",
|
|
169
|
+
id: block.id,
|
|
170
|
+
name: block.name,
|
|
171
|
+
input: block.input
|
|
172
|
+
});
|
|
173
|
+
} else if (block.type === "tool_result" && block.tool_use_id) {
|
|
174
|
+
blocks.push({
|
|
175
|
+
type: "tool_result",
|
|
176
|
+
tool_use_id: block.tool_use_id,
|
|
177
|
+
content: typeof block.content === "string" ? block.content : ""
|
|
178
|
+
});
|
|
179
|
+
} else if (block.type === "image" && block.source) {
|
|
180
|
+
blocks.push({
|
|
181
|
+
type: "image",
|
|
182
|
+
source: {
|
|
183
|
+
type: "base64",
|
|
184
|
+
media_type: block.source.media_type,
|
|
185
|
+
data: block.source.data
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (blocks.length > 0) {
|
|
191
|
+
result.push({ role, content: blocks });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
convertTools(tools) {
|
|
198
|
+
return tools.map((t) => ({
|
|
199
|
+
name: t.name,
|
|
200
|
+
description: t.description,
|
|
201
|
+
input_schema: t.inputSchema
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
handleApiError(err) {
|
|
205
|
+
if (err instanceof Anthropic.APIError) {
|
|
206
|
+
if (err.status === 429) {
|
|
207
|
+
throw new LLMRateLimitError("anthropic");
|
|
208
|
+
}
|
|
209
|
+
if (err.message?.includes("prompt is too long") || err.message?.includes("context_length_exceeded")) {
|
|
210
|
+
throw new ContextLimitError("anthropic");
|
|
211
|
+
}
|
|
212
|
+
throw new LLMError(`Anthropic API error: ${err.message}`, "anthropic", {
|
|
213
|
+
status: err.status
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
throw err;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
export {
|
|
221
|
+
AnthropicClient
|
|
222
|
+
};
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
|
+
|
|
3
|
+
var _chunkDICG4AB7cjs = require('./chunk-DICG4AB7.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkEL2RL5DGcjs = require('./chunk-EL2RL5DG.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkIJSHQGMPcjs = require('./chunk-IJSHQGMP.cjs');
|
|
12
|
+
|
|
13
|
+
// src/llm/providers/anthropic.ts
|
|
14
|
+
_chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
|
|
15
|
+
var _sdk = require('@anthropic-ai/sdk'); var _sdk2 = _interopRequireDefault(_sdk);
|
|
16
|
+
var AnthropicClient = (_class = class extends _chunkDICG4AB7cjs.LLMClientBase {
|
|
17
|
+
__init() {this._client = null}
|
|
18
|
+
constructor(config) {
|
|
19
|
+
super(config);_class.prototype.__init.call(this);;
|
|
20
|
+
}
|
|
21
|
+
initClient() {
|
|
22
|
+
}
|
|
23
|
+
get client() {
|
|
24
|
+
if (!this._client) {
|
|
25
|
+
this._client = new (0, _sdk2.default)({
|
|
26
|
+
apiKey: _nullishCoalesce(this.config.apiKey, () => ( process.env.ANTHROPIC_API_KEY)),
|
|
27
|
+
...this.config.baseUrl ? { baseURL: this.config.baseUrl } : {},
|
|
28
|
+
timeout: this.timeout
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return this._client;
|
|
32
|
+
}
|
|
33
|
+
async createMessage(options) {
|
|
34
|
+
return this.withRetry(async () => {
|
|
35
|
+
const messages = this.buildMessages(options.messages);
|
|
36
|
+
const tools = options.tools ? this.convertTools(options.tools) : void 0;
|
|
37
|
+
if (options.stream && options.onChunk) {
|
|
38
|
+
return this.streamMessage(options, messages, tools);
|
|
39
|
+
}
|
|
40
|
+
return this.nonStreamMessage(options, messages, tools);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async nonStreamMessage(options, messages, tools) {
|
|
44
|
+
try {
|
|
45
|
+
const response = await this.client.messages.create(
|
|
46
|
+
{
|
|
47
|
+
model: this.model,
|
|
48
|
+
max_tokens: _nullishCoalesce(options.maxTokens, () => ( this.maxTokens)),
|
|
49
|
+
system: [
|
|
50
|
+
{
|
|
51
|
+
type: "text",
|
|
52
|
+
text: options.systemPrompt,
|
|
53
|
+
cache_control: { type: "ephemeral" }
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
messages,
|
|
57
|
+
..._optionalChain([tools, 'optionalAccess', _ => _.length]) ? { tools } : {},
|
|
58
|
+
...options.temperature !== void 0 ? { temperature: options.temperature } : { temperature: this.temperature }
|
|
59
|
+
},
|
|
60
|
+
{ signal: options.signal }
|
|
61
|
+
);
|
|
62
|
+
const usage = {
|
|
63
|
+
promptTokens: response.usage.input_tokens,
|
|
64
|
+
completionTokens: response.usage.output_tokens,
|
|
65
|
+
totalTokens: response.usage.input_tokens + response.usage.output_tokens,
|
|
66
|
+
cacheReadTokens: response.usage.cache_read_input_tokens,
|
|
67
|
+
cacheCreationTokens: response.usage.cache_creation_input_tokens
|
|
68
|
+
};
|
|
69
|
+
this.recordUsage(usage);
|
|
70
|
+
return this.processResponse(response, usage);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
this.handleApiError(err);
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async streamMessage(options, messages, tools) {
|
|
77
|
+
try {
|
|
78
|
+
const stream = this.client.messages.stream(
|
|
79
|
+
{
|
|
80
|
+
model: this.model,
|
|
81
|
+
max_tokens: _nullishCoalesce(options.maxTokens, () => ( this.maxTokens)),
|
|
82
|
+
system: [
|
|
83
|
+
{
|
|
84
|
+
type: "text",
|
|
85
|
+
text: options.systemPrompt,
|
|
86
|
+
cache_control: { type: "ephemeral" }
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
messages,
|
|
90
|
+
..._optionalChain([tools, 'optionalAccess', _2 => _2.length]) ? { tools } : {},
|
|
91
|
+
...options.temperature !== void 0 ? { temperature: options.temperature } : { temperature: this.temperature }
|
|
92
|
+
},
|
|
93
|
+
{ signal: options.signal }
|
|
94
|
+
);
|
|
95
|
+
let currentText = "";
|
|
96
|
+
let currentToolName = "";
|
|
97
|
+
let currentToolId = "";
|
|
98
|
+
let currentToolInput = "";
|
|
99
|
+
stream.on("text", (text) => {
|
|
100
|
+
currentText += text;
|
|
101
|
+
_optionalChain([options, 'access', _3 => _3.onChunk, 'optionalCall', _4 => _4({ type: "text", text })]);
|
|
102
|
+
});
|
|
103
|
+
stream.on("contentBlock", (block) => {
|
|
104
|
+
if (block.type === "tool_use") {
|
|
105
|
+
currentToolName = block.name;
|
|
106
|
+
currentToolId = block.id;
|
|
107
|
+
currentToolInput = "";
|
|
108
|
+
_optionalChain([options, 'access', _5 => _5.onChunk, 'optionalCall', _6 => _6({
|
|
109
|
+
type: "tool_use_start",
|
|
110
|
+
toolCall: { id: block.id, toolName: block.name, args: {} }
|
|
111
|
+
})]);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
stream.on("inputJson", (_delta, snapshot) => {
|
|
115
|
+
currentToolInput = JSON.stringify(snapshot);
|
|
116
|
+
});
|
|
117
|
+
const finalMessage = await stream.finalMessage();
|
|
118
|
+
const usage = {
|
|
119
|
+
promptTokens: finalMessage.usage.input_tokens,
|
|
120
|
+
completionTokens: finalMessage.usage.output_tokens,
|
|
121
|
+
totalTokens: finalMessage.usage.input_tokens + finalMessage.usage.output_tokens,
|
|
122
|
+
cacheReadTokens: finalMessage.usage.cache_read_input_tokens,
|
|
123
|
+
cacheCreationTokens: finalMessage.usage.cache_creation_input_tokens
|
|
124
|
+
};
|
|
125
|
+
this.recordUsage(usage);
|
|
126
|
+
_optionalChain([options, 'access', _7 => _7.onChunk, 'optionalCall', _8 => _8({ type: "stop", stopReason: _nullishCoalesce(finalMessage.stop_reason, () => ( void 0)) })]);
|
|
127
|
+
return this.processResponse(finalMessage, usage);
|
|
128
|
+
} catch (err) {
|
|
129
|
+
this.handleApiError(err);
|
|
130
|
+
throw err;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
processResponse(response, usage) {
|
|
134
|
+
let text = "";
|
|
135
|
+
const toolCalls = [];
|
|
136
|
+
for (const block of response.content) {
|
|
137
|
+
if (block.type === "text") {
|
|
138
|
+
text += block.text;
|
|
139
|
+
} else if (block.type === "tool_use") {
|
|
140
|
+
toolCalls.push({
|
|
141
|
+
id: block.id,
|
|
142
|
+
toolName: block.name,
|
|
143
|
+
args: _nullishCoalesce(block.input, () => ( {}))
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
text,
|
|
149
|
+
toolCalls,
|
|
150
|
+
usage,
|
|
151
|
+
stopReason: _nullishCoalesce(response.stop_reason, () => ( void 0))
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
buildMessages(messages) {
|
|
155
|
+
const result = [];
|
|
156
|
+
for (const msg of messages) {
|
|
157
|
+
if (msg.role === "system") continue;
|
|
158
|
+
const role = msg.role === "tool" ? "user" : msg.role;
|
|
159
|
+
if (typeof msg.content === "string") {
|
|
160
|
+
result.push({ role, content: msg.content });
|
|
161
|
+
} else {
|
|
162
|
+
const blocks = [];
|
|
163
|
+
for (const block of msg.content) {
|
|
164
|
+
if (block.type === "text" && block.text) {
|
|
165
|
+
blocks.push({ type: "text", text: block.text });
|
|
166
|
+
} else if (block.type === "tool_use" && block.id && block.name && block.input) {
|
|
167
|
+
blocks.push({
|
|
168
|
+
type: "tool_use",
|
|
169
|
+
id: block.id,
|
|
170
|
+
name: block.name,
|
|
171
|
+
input: block.input
|
|
172
|
+
});
|
|
173
|
+
} else if (block.type === "tool_result" && block.tool_use_id) {
|
|
174
|
+
blocks.push({
|
|
175
|
+
type: "tool_result",
|
|
176
|
+
tool_use_id: block.tool_use_id,
|
|
177
|
+
content: typeof block.content === "string" ? block.content : ""
|
|
178
|
+
});
|
|
179
|
+
} else if (block.type === "image" && block.source) {
|
|
180
|
+
blocks.push({
|
|
181
|
+
type: "image",
|
|
182
|
+
source: {
|
|
183
|
+
type: "base64",
|
|
184
|
+
media_type: block.source.media_type,
|
|
185
|
+
data: block.source.data
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (blocks.length > 0) {
|
|
191
|
+
result.push({ role, content: blocks });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
convertTools(tools) {
|
|
198
|
+
return tools.map((t) => ({
|
|
199
|
+
name: t.name,
|
|
200
|
+
description: t.description,
|
|
201
|
+
input_schema: t.inputSchema
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
handleApiError(err) {
|
|
205
|
+
if (err instanceof _sdk2.default.APIError) {
|
|
206
|
+
if (err.status === 429) {
|
|
207
|
+
throw new (0, _chunkEL2RL5DGcjs.LLMRateLimitError)("anthropic");
|
|
208
|
+
}
|
|
209
|
+
if (_optionalChain([err, 'access', _9 => _9.message, 'optionalAccess', _10 => _10.includes, 'call', _11 => _11("prompt is too long")]) || _optionalChain([err, 'access', _12 => _12.message, 'optionalAccess', _13 => _13.includes, 'call', _14 => _14("context_length_exceeded")])) {
|
|
210
|
+
throw new (0, _chunkEL2RL5DGcjs.ContextLimitError)("anthropic");
|
|
211
|
+
}
|
|
212
|
+
throw new (0, _chunkEL2RL5DGcjs.LLMError)(`Anthropic API error: ${err.message}`, "anthropic", {
|
|
213
|
+
status: err.status
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
throw err;
|
|
217
|
+
}
|
|
218
|
+
}, _class);
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
exports.AnthropicClient = AnthropicClient;
|