@cjhyy/code-shell 0.1.0-alpha.0 → 0.1.0-alpha.2
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 +39 -0
- package/README.md +8 -0
- package/dist/anthropic-P5VETAFI.cjs +10 -0
- package/dist/{anthropic-NENYS535.js → anthropic-W2GU3D76.js} +3 -2
- package/dist/arena/context/context-tools.d.ts +1 -1
- package/dist/arena/index.cjs +4 -4
- package/dist/arena/index.js +3 -3
- package/dist/arena/providers/index.d.ts +19 -3
- package/dist/arena/strategies/utils.d.ts +6 -1
- package/dist/arena/types.d.ts +10 -1
- package/dist/{arena-46QQ6BZQ.js → arena-ENHBHB2W.js} +5 -7
- package/dist/{arena-HZZZ2GJH.cjs → arena-HHDYYVHJ.cjs} +19 -21
- package/dist/{chunk-BE6IPRDM.js → chunk-2EUAE7AY.js} +1 -1
- package/dist/{chunk-WFQF3RT4.cjs → chunk-3CAZIWUA.cjs} +11 -8
- package/dist/{chunk-J5XW6UYL.js → chunk-5C5HIOML.js} +63 -4
- package/dist/chunk-75E4BBFC.js +224 -0
- package/dist/{chunk-ZJV3YSY3.cjs → chunk-BUJ5KYCI.cjs} +53 -11
- package/dist/{chunk-BMH65OVB.cjs → chunk-C7C7ZZY4.cjs} +8 -8
- package/dist/{chunk-KO2FPF7G.js → chunk-F5BS3GUC.js} +20 -2
- package/dist/chunk-FA5KD34T.js +54 -0
- package/dist/chunk-FV2ARONZ.cjs +224 -0
- package/dist/chunk-G76E5FOB.cjs +54 -0
- package/dist/{chunk-DICG4AB7.cjs → chunk-GZBD6QRS.cjs} +42 -3
- package/dist/{chunk-FVP7XJGS.cjs → chunk-HOXQLX5R.cjs} +406 -196
- package/dist/{chunk-4PKZPFCD.js → chunk-I57ZD5IQ.js} +47 -14
- package/dist/{chunk-7RMAR2Y3.js → chunk-ID6EJUHP.js} +1959 -473
- package/dist/chunk-JHNCK7JP.cjs +202 -0
- package/dist/{chunk-R32DJSJE.cjs → chunk-JHXNOB5G.cjs} +8 -5
- package/dist/{chunk-UK2SU23S.cjs → chunk-KOGV6PDQ.cjs} +20 -2
- package/dist/{chunk-VKGNCYRL.js → chunk-LMEKCQX4.js} +95 -13
- package/dist/{chunk-3EAEC566.cjs → chunk-M2QI5X3X.cjs} +51 -18
- package/dist/{chunk-YZ25SSWJ.js → chunk-M2SVOKC6.js} +46 -4
- package/dist/chunk-OMRGA6TI.js +4753 -0
- package/dist/{chunk-NG73UR3L.cjs → chunk-OP57WUWQ.cjs} +23 -1
- package/dist/{chunk-ZXYDDJEJ.js → chunk-OUC2DFA7.js} +2 -2
- package/dist/{chunk-6JOOLG6F.js → chunk-REFCCVDM.js} +5 -2
- package/dist/{chunk-O6F2EF2Z.js → chunk-SCDKLTN3.js} +41 -2
- package/dist/{chunk-BHGIJ2DJ.js → chunk-SW3L7HIM.js} +6 -3
- package/dist/chunk-TATCTZSB.cjs +4753 -0
- package/dist/{chunk-QHDYFC5U.cjs → chunk-VWFET3MG.cjs} +2132 -646
- package/dist/{chunk-3EUDE77E.cjs → chunk-X2DNIMPC.cjs} +19 -19
- package/dist/{chunk-SQZHPD3S.js → chunk-Y7TSCDF6.js} +297 -87
- package/dist/{chunk-WHRTARDJ.cjs → chunk-YAFCN7ZW.cjs} +112 -30
- package/dist/{chunk-LRAY5IYC.cjs → chunk-YD7XTI7T.cjs} +65 -6
- package/dist/{chunk-S74VVJBF.js → chunk-ZLPJJZUW.js} +23 -1
- package/dist/chunk-ZRVPCXI7.js +202 -0
- package/dist/cli/commands/builtin/advanced-commands.d.ts +1 -1
- package/dist/cli/commands/builtin/extra-commands.d.ts +2 -2
- package/dist/cli/commands/builtin/more-commands.d.ts +1 -3
- package/dist/cli/commands/registry.d.ts +8 -0
- package/dist/cli/cost-tracker.d.ts +6 -0
- package/dist/cli/main.cjs +3576 -2036
- package/dist/cli/main.js +3613 -2073
- package/dist/cli/onboarding.d.ts +67 -14
- package/dist/client-base-TOVE25FA.js +9 -0
- package/dist/client-base-VDDIADAC.cjs +9 -0
- package/dist/compaction-D3KV2NWY.cjs +31 -0
- package/dist/{compaction-CCHWA4G6.js → compaction-YNWCEF7B.js} +1 -2
- package/dist/context/manager.d.ts +9 -0
- package/dist/data/openrouter-models.d.ts +35 -0
- package/dist/data/openrouter-sync.d.ts +16 -0
- package/dist/{devtools-KIY3LWQJ.js → devtools-IRQQPIRY.js} +1 -1
- package/dist/{devtools-LRP47DDV.cjs → devtools-WTC3NFNE.cjs} +1 -1
- package/dist/engine/engine.d.ts +39 -4
- package/dist/engine/turn-loop.d.ts +13 -4
- package/dist/engine/turn-state.d.ts +6 -0
- package/dist/index.cjs +19 -28
- package/dist/index.d.ts +1 -1
- package/dist/index.js +28 -37
- package/dist/llm/client-base.d.ts +7 -0
- package/dist/llm/model-pool.d.ts +4 -0
- package/dist/logging/logger.d.ts +69 -8
- package/dist/manager-FWLOVEEK.cjs +7 -0
- package/dist/manager-GEXJLOIS.js +7 -0
- package/dist/{mcp-manager-OKXHHWYR.js → mcp-manager-37GQLFGX.js} +2 -2
- package/dist/mcp-manager-U77NEXBY.cjs +8 -0
- package/dist/memory-ADGOWADP.cjs +9 -0
- package/dist/memory-EPFDBPII.js +9 -0
- package/dist/native-ts/yoga-layout/index.d.ts +2 -2
- package/dist/{openai-5HQGBL4L.js → openai-RXU5URYI.js} +3 -2
- package/dist/openai-SQW4H2K4.cjs +10 -0
- package/dist/openrouter-models-OL725CL6.js +15 -0
- package/dist/openrouter-models-UM3AOGZ4.cjs +15 -0
- package/dist/openrouter-sync-CWD5VNW2.js +11 -0
- package/dist/openrouter-sync-HYZZC6RX.cjs +11 -0
- package/dist/product/index.cjs +12 -16
- package/dist/product/index.js +11 -15
- package/dist/product/types.d.ts +2 -7
- package/dist/protocol/types.d.ts +11 -3
- package/dist/{ink → render}/hooks/use-input.d.ts +1 -1
- package/dist/run/EngineRunner.d.ts +3 -1
- package/dist/run/RunManager.d.ts +6 -0
- package/dist/run/factory.d.ts +7 -1
- package/dist/run/index.cjs +12 -16
- package/dist/run/index.js +11 -15
- package/dist/session/memory.d.ts +23 -3
- package/dist/session/session-manager.d.ts +4 -1
- package/dist/{session-manager-UQKB564H.cjs → session-manager-HRSKENKB.cjs} +2 -2
- package/dist/{session-manager-JIIBCFTC.js → session-manager-NEKFEHF3.js} +1 -1
- package/dist/settings/manager.d.ts +9 -0
- package/dist/settings/schema.d.ts +48 -39
- package/dist/{tool-summary-J2ICNMWP.js → tool-summary-2RUFL5QK.js} +1 -1
- package/dist/{tool-summary-5P2GKRA4.cjs → tool-summary-RYNR4DDB.cjs} +2 -2
- package/dist/tool-system/builtin/agent-registry.d.ts +36 -0
- package/dist/tool-system/builtin/agent.d.ts +7 -26
- package/dist/tool-system/builtin/apply-patch/applier.d.ts +26 -0
- package/dist/tool-system/builtin/apply-patch/index.d.ts +19 -0
- package/dist/tool-system/builtin/apply-patch/parser.d.ts +17 -0
- package/dist/tool-system/builtin/apply-patch/seek-sequence.d.ts +18 -0
- package/dist/tool-system/builtin/apply-patch/types.d.ts +49 -0
- package/dist/tool-system/builtin/arena.d.ts +18 -5
- package/dist/tool-system/builtin/ask-user.d.ts +6 -6
- package/dist/tool-system/builtin/index.d.ts +11 -1
- package/dist/tool-system/builtin/tool-search.d.ts +2 -3
- package/dist/tool-system/context.d.ts +74 -0
- package/dist/tool-system/executor.d.ts +16 -0
- package/dist/tool-system/permission.d.ts +40 -5
- package/dist/tool-system/registry.d.ts +8 -0
- package/dist/types.d.ts +34 -1
- package/dist/ui/App.d.ts +1 -1
- package/dist/ui/components/AgentBlock.d.ts +1 -1
- package/dist/ui/components/AskUserPrompt.d.ts +7 -0
- package/dist/ui/components/MessageContent.d.ts +7 -3
- package/dist/ui/components/ModelManager.d.ts +35 -0
- package/dist/ui/components/ModelSelector.d.ts +10 -0
- package/dist/ui/components/OnboardingPrompt.d.ts +7 -0
- package/dist/ui/components/PermissionPrompt.d.ts +5 -2
- package/dist/ui/components/SessionPicker.d.ts +14 -0
- package/dist/ui/components/StatusLine.d.ts +4 -2
- package/dist/ui/components/ThemedBox.d.ts +1 -1
- package/dist/ui/components/ToolCall.d.ts +8 -1
- package/dist/ui/components/WelcomeTips.d.ts +5 -0
- package/dist/ui/onboarding-runner.d.ts +2 -0
- package/dist/ui/store.d.ts +1 -0
- package/dist/{updater-URVNPDPW.cjs → updater-M7L42ASZ.cjs} +4 -4
- package/dist/{updater-AVD4LKTQ.js → updater-ZRTONIR4.js} +4 -4
- package/dist/utils/debug.d.ts +17 -33
- package/package.json +4 -4
- package/dist/anthropic-XMTTVNSH.cjs +0 -9
- package/dist/bridge-4ZRXVWBN.js +0 -98
- package/dist/bridge-W476QDFH.cjs +0 -98
- package/dist/chunk-4RRUP4MM.js +0 -86
- package/dist/chunk-4SFPFHMG.js +0 -132
- package/dist/chunk-5LHVI777.cjs +0 -246
- package/dist/chunk-6ZIROYXX.js +0 -207
- package/dist/chunk-C7JBCO5V.js +0 -80
- package/dist/chunk-CSO5EOEP.cjs +0 -132
- package/dist/chunk-FGZGCFJX.cjs +0 -207
- package/dist/chunk-HD7MT5XU.cjs +0 -86
- package/dist/chunk-IMMTBZ33.cjs +0 -63
- package/dist/chunk-JT2WSQSR.cjs +0 -335
- package/dist/chunk-NZ4DQ72D.cjs +0 -664
- package/dist/chunk-OG4MIQJ6.js +0 -335
- package/dist/chunk-WRZJUQ5Z.js +0 -664
- package/dist/chunk-X4HAERTQ.js +0 -63
- package/dist/chunk-XHC2JMEC.cjs +0 -80
- package/dist/chunk-ZRSSGYA5.js +0 -246
- package/dist/compaction-44I55TLI.cjs +0 -32
- package/dist/coordinator-5HY7ALO2.js +0 -7
- package/dist/coordinator-INDLPVMF.cjs +0 -7
- package/dist/cost-tracker-IWYAUPXH.js +0 -9
- package/dist/cost-tracker-JXTJQQWE.cjs +0 -9
- package/dist/loader-DXFSUB4R.cjs +0 -91
- package/dist/loader-J5UID6CV.js +0 -91
- package/dist/manager-ETWDOCHN.cjs +0 -9
- package/dist/manager-HGMQNEJB.cjs +0 -11
- package/dist/manager-HUAQOORS.js +0 -9
- package/dist/manager-VJIZ2CQC.js +0 -11
- package/dist/mcp-manager-G4G2QASE.cjs +0 -8
- package/dist/memory-AP747G5H.js +0 -7
- package/dist/memory-BH3BYUN5.cjs +0 -7
- package/dist/onboarding-6WEPV7C2.js +0 -11
- package/dist/onboarding-QM5DY2TU.cjs +0 -11
- package/dist/openai-656VWUQW.cjs +0 -9
- package/dist/skills-63RBYQRX.js +0 -13
- package/dist/skills-V3BPLW3D.cjs +0 -13
- package/dist/token-counter-CHAXW5O7.cjs +0 -13
- package/dist/token-counter-DSOZGZ5Q.js +0 -13
- package/dist/utils/log.d.ts +0 -56
- package/dist/voice-KTZ7PAGO.js +0 -80
- package/dist/voice-KZE25GKB.cjs +0 -80
- /package/dist/{ink → render}/Ansi.d.ts +0 -0
- /package/dist/{ink → render}/bidi.d.ts +0 -0
- /package/dist/{ink → render}/clearTerminal.d.ts +0 -0
- /package/dist/{ink → render}/colorize.d.ts +0 -0
- /package/dist/{ink → render}/components/AlternateScreen.d.ts +0 -0
- /package/dist/{ink → render}/components/App.d.ts +0 -0
- /package/dist/{ink → render}/components/AppContext.d.ts +0 -0
- /package/dist/{ink → render}/components/Box.d.ts +0 -0
- /package/dist/{ink → render}/components/Button.d.ts +0 -0
- /package/dist/{ink → render}/components/ClockContext.d.ts +0 -0
- /package/dist/{ink → render}/components/CursorDeclarationContext.d.ts +0 -0
- /package/dist/{ink → render}/components/ErrorOverview.d.ts +0 -0
- /package/dist/{ink → render}/components/Link.d.ts +0 -0
- /package/dist/{ink → render}/components/Newline.d.ts +0 -0
- /package/dist/{ink → render}/components/NoSelect.d.ts +0 -0
- /package/dist/{ink → render}/components/RawAnsi.d.ts +0 -0
- /package/dist/{ink → render}/components/ScrollBox.d.ts +0 -0
- /package/dist/{ink → render}/components/Spacer.d.ts +0 -0
- /package/dist/{ink → render}/components/StdinContext.d.ts +0 -0
- /package/dist/{ink → render}/components/TerminalFocusContext.d.ts +0 -0
- /package/dist/{ink → render}/components/TerminalSizeContext.d.ts +0 -0
- /package/dist/{ink → render}/components/Text.d.ts +0 -0
- /package/dist/{ink → render}/constants.d.ts +0 -0
- /package/dist/{ink → render}/cursor.d.ts +0 -0
- /package/dist/{ink → render}/devtools.d.ts +0 -0
- /package/dist/{ink → render}/dom.d.ts +0 -0
- /package/dist/{ink → render}/events/click-event.d.ts +0 -0
- /package/dist/{ink → render}/events/dispatcher.d.ts +0 -0
- /package/dist/{ink → render}/events/emitter.d.ts +0 -0
- /package/dist/{ink → render}/events/event-handlers.d.ts +0 -0
- /package/dist/{ink → render}/events/event.d.ts +0 -0
- /package/dist/{ink → render}/events/focus-event.d.ts +0 -0
- /package/dist/{ink → render}/events/input-event.d.ts +0 -0
- /package/dist/{ink → render}/events/keyboard-event.d.ts +0 -0
- /package/dist/{ink → render}/events/paste-event.d.ts +0 -0
- /package/dist/{ink → render}/events/resize-event.d.ts +0 -0
- /package/dist/{ink → render}/events/terminal-event.d.ts +0 -0
- /package/dist/{ink → render}/events/terminal-focus-event.d.ts +0 -0
- /package/dist/{ink → render}/focus.d.ts +0 -0
- /package/dist/{ink → render}/frame.d.ts +0 -0
- /package/dist/{ink → render}/get-max-width.d.ts +0 -0
- /package/dist/{ink → render}/hit-test.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-animation-frame.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-app.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-declared-cursor.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-interval.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-search-highlight.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-selection.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-stdin.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-tab-status.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-terminal-focus.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-terminal-title.d.ts +0 -0
- /package/dist/{ink → render}/hooks/use-terminal-viewport.d.ts +0 -0
- /package/dist/{ink → render}/index.d.ts +0 -0
- /package/dist/{ink → render}/ink.d.ts +0 -0
- /package/dist/{ink → render}/instances.d.ts +0 -0
- /package/dist/{ink → render}/layout/engine.d.ts +0 -0
- /package/dist/{ink → render}/layout/geometry.d.ts +0 -0
- /package/dist/{ink → render}/layout/node.d.ts +0 -0
- /package/dist/{ink → render}/layout/yoga.d.ts +0 -0
- /package/dist/{ink → render}/line-width-cache.d.ts +0 -0
- /package/dist/{ink → render}/log-update.d.ts +0 -0
- /package/dist/{ink → render}/measure-element.d.ts +0 -0
- /package/dist/{ink → render}/measure-text.d.ts +0 -0
- /package/dist/{ink → render}/node-cache.d.ts +0 -0
- /package/dist/{ink → render}/optimizer.d.ts +0 -0
- /package/dist/{ink → render}/output.d.ts +0 -0
- /package/dist/{ink → render}/parse-keypress.d.ts +0 -0
- /package/dist/{ink → render}/reconciler.d.ts +0 -0
- /package/dist/{ink → render}/render-border.d.ts +0 -0
- /package/dist/{ink → render}/render-node-to-output.d.ts +0 -0
- /package/dist/{ink → render}/render-to-screen.d.ts +0 -0
- /package/dist/{ink → render}/renderer.d.ts +0 -0
- /package/dist/{ink → render}/root.d.ts +0 -0
- /package/dist/{ink → render}/screen.d.ts +0 -0
- /package/dist/{ink → render}/searchHighlight.d.ts +0 -0
- /package/dist/{ink → render}/selection.d.ts +0 -0
- /package/dist/{ink → render}/squash-text-nodes.d.ts +0 -0
- /package/dist/{ink → render}/stringWidth.d.ts +0 -0
- /package/dist/{ink → render}/styles.d.ts +0 -0
- /package/dist/{ink → render}/supports-hyperlinks.d.ts +0 -0
- /package/dist/{ink → render}/tabstops.d.ts +0 -0
- /package/dist/{ink → render}/terminal-focus-state.d.ts +0 -0
- /package/dist/{ink → render}/terminal-querier.d.ts +0 -0
- /package/dist/{ink → render}/terminal.d.ts +0 -0
- /package/dist/{ink → render}/termio/ansi.d.ts +0 -0
- /package/dist/{ink → render}/termio/csi.d.ts +0 -0
- /package/dist/{ink → render}/termio/dec.d.ts +0 -0
- /package/dist/{ink → render}/termio/esc.d.ts +0 -0
- /package/dist/{ink → render}/termio/osc.d.ts +0 -0
- /package/dist/{ink → render}/termio/parser.d.ts +0 -0
- /package/dist/{ink → render}/termio/sgr.d.ts +0 -0
- /package/dist/{ink → render}/termio/tokenize.d.ts +0 -0
- /package/dist/{ink → render}/termio/types.d.ts +0 -0
- /package/dist/{ink → render}/termio.d.ts +0 -0
- /package/dist/{ink → render}/useTerminalNotification.d.ts +0 -0
- /package/dist/{ink → render}/warn.d.ts +0 -0
- /package/dist/{ink → render}/widest-line.d.ts +0 -0
- /package/dist/{ink → render}/wrap-text.d.ts +0 -0
- /package/dist/{ink → render}/wrapAnsi.d.ts +0 -0
package/dist/chunk-WRZJUQ5Z.js
DELETED
|
@@ -1,664 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
init_esm_shims
|
|
3
|
-
} from "./chunk-DI7RDLOS.js";
|
|
4
|
-
|
|
5
|
-
// src/cli/onboarding.ts
|
|
6
|
-
init_esm_shims();
|
|
7
|
-
import chalk from "chalk";
|
|
8
|
-
import { mkdirSync, writeFileSync, readFileSync, existsSync } from "fs";
|
|
9
|
-
import { join } from "path";
|
|
10
|
-
import { homedir } from "os";
|
|
11
|
-
var PROVIDERS = [
|
|
12
|
-
{
|
|
13
|
-
id: "openrouter",
|
|
14
|
-
name: "OpenRouter (\u63A8\u8350 \u2014 \u652F\u6301\u6240\u6709\u6A21\u578B)",
|
|
15
|
-
envKey: "OPENROUTER_API_KEY",
|
|
16
|
-
provider: "openai",
|
|
17
|
-
baseUrl: "https://openrouter.ai/api/v1",
|
|
18
|
-
defaultModel: "anthropic/claude-sonnet-4.6",
|
|
19
|
-
keyUrl: "https://openrouter.ai/keys",
|
|
20
|
-
keyPrefix: "sk-or-",
|
|
21
|
-
models: [
|
|
22
|
-
"anthropic/claude-opus-4.6",
|
|
23
|
-
"anthropic/claude-sonnet-4.6",
|
|
24
|
-
"anthropic/claude-haiku-4.5",
|
|
25
|
-
"openai/gpt-5.4",
|
|
26
|
-
"openai/gpt-4o",
|
|
27
|
-
"openai/o4-mini",
|
|
28
|
-
"google/gemini-3.1-pro-preview",
|
|
29
|
-
"google/gemini-3-flash-preview",
|
|
30
|
-
"google/gemini-2.5-pro",
|
|
31
|
-
"deepseek/deepseek-v3.2",
|
|
32
|
-
"deepseek/deepseek-r1",
|
|
33
|
-
"qwen/qwen3-coder",
|
|
34
|
-
"qwen/qwen3-235b-a22b",
|
|
35
|
-
"meta-llama/llama-4-maverick",
|
|
36
|
-
"mistralai/devstral-medium"
|
|
37
|
-
]
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
id: "anthropic",
|
|
41
|
-
name: "Anthropic (\u76F4\u8FDE Claude API)",
|
|
42
|
-
envKey: "ANTHROPIC_API_KEY",
|
|
43
|
-
provider: "anthropic",
|
|
44
|
-
baseUrl: "https://api.anthropic.com",
|
|
45
|
-
defaultModel: "claude-sonnet-4-6",
|
|
46
|
-
keyUrl: "https://console.anthropic.com/settings/keys",
|
|
47
|
-
keyPrefix: "sk-ant-",
|
|
48
|
-
models: [
|
|
49
|
-
"claude-opus-4-6",
|
|
50
|
-
"claude-sonnet-4-6",
|
|
51
|
-
"claude-haiku-4-5"
|
|
52
|
-
]
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
id: "openai",
|
|
56
|
-
name: "OpenAI",
|
|
57
|
-
envKey: "OPENAI_API_KEY",
|
|
58
|
-
provider: "openai",
|
|
59
|
-
baseUrl: "https://api.openai.com/v1",
|
|
60
|
-
defaultModel: "gpt-5.4",
|
|
61
|
-
keyUrl: "https://platform.openai.com/api-keys",
|
|
62
|
-
keyPrefix: "sk-",
|
|
63
|
-
models: ["gpt-5.4", "gpt-5.4-mini", "gpt-4o", "o4-mini", "o3"]
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
id: "custom",
|
|
67
|
-
name: "\u81EA\u5B9A\u4E49 (\u4EFB\u4F55 OpenAI \u517C\u5BB9 API)",
|
|
68
|
-
envKey: "",
|
|
69
|
-
provider: "openai",
|
|
70
|
-
baseUrl: "",
|
|
71
|
-
defaultModel: "",
|
|
72
|
-
keyUrl: "",
|
|
73
|
-
keyPrefix: "",
|
|
74
|
-
models: []
|
|
75
|
-
}
|
|
76
|
-
];
|
|
77
|
-
var BACK = /* @__PURE__ */ Symbol("back");
|
|
78
|
-
function arrowSelect(options, title, opts) {
|
|
79
|
-
return new Promise((resolve, reject) => {
|
|
80
|
-
let cursor = 0;
|
|
81
|
-
const stdin = process.stdin;
|
|
82
|
-
const allowBack = opts?.allowBack ?? true;
|
|
83
|
-
if (typeof stdin.setRawMode !== "function") {
|
|
84
|
-
reject(new Error("Interactive onboarding requires a TTY. Set an API key via environment variable instead."));
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const wasRaw = stdin.isRaw;
|
|
88
|
-
const wasFlowing = stdin.readableFlowing;
|
|
89
|
-
const backHint = allowBack ? chalk.dim(" (ESC \u8FD4\u56DE)") : "";
|
|
90
|
-
function render() {
|
|
91
|
-
const lines = options.length + 1;
|
|
92
|
-
process.stdout.write(`\x1B[${lines}A\x1B[J`);
|
|
93
|
-
console.log(chalk.dim(` ${title}`) + backHint);
|
|
94
|
-
for (let i = 0; i < options.length; i++) {
|
|
95
|
-
const opt = options[i];
|
|
96
|
-
const selected = i === cursor;
|
|
97
|
-
const prefix = selected ? chalk.cyan("\u276F ") : " ";
|
|
98
|
-
const label = selected ? chalk.bold.cyan(opt.label) : chalk.white(opt.label);
|
|
99
|
-
const hint = opt.hint ? chalk.dim(` ${opt.hint}`) : "";
|
|
100
|
-
console.log(` ${prefix}${label}${hint}`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
console.log(chalk.dim(` ${title}`) + backHint);
|
|
104
|
-
for (const opt of options) {
|
|
105
|
-
const hint = opt.hint ? chalk.dim(` ${opt.hint}`) : "";
|
|
106
|
-
console.log(` ${opt.label}${hint}`);
|
|
107
|
-
}
|
|
108
|
-
render();
|
|
109
|
-
stdin.setRawMode(true);
|
|
110
|
-
stdin.resume();
|
|
111
|
-
function onData(data) {
|
|
112
|
-
const key = data.toString();
|
|
113
|
-
if (key === "\x1B[A" || key === "k") {
|
|
114
|
-
cursor = cursor > 0 ? cursor - 1 : options.length - 1;
|
|
115
|
-
render();
|
|
116
|
-
} else if (key === "\x1B[B" || key === "j") {
|
|
117
|
-
cursor = cursor < options.length - 1 ? cursor + 1 : 0;
|
|
118
|
-
render();
|
|
119
|
-
} else if (key === "\r" || key === "\n") {
|
|
120
|
-
cleanup();
|
|
121
|
-
resolve(options[cursor].value);
|
|
122
|
-
} else if (key === "\x1B" && allowBack) {
|
|
123
|
-
cleanup();
|
|
124
|
-
resolve(BACK);
|
|
125
|
-
} else if (key === "") {
|
|
126
|
-
cleanup();
|
|
127
|
-
process.exit(1);
|
|
128
|
-
} else {
|
|
129
|
-
const num = parseInt(key, 10);
|
|
130
|
-
if (num >= 1 && num <= options.length) {
|
|
131
|
-
cursor = num - 1;
|
|
132
|
-
render();
|
|
133
|
-
cleanup();
|
|
134
|
-
resolve(options[cursor].value);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
function cleanup() {
|
|
139
|
-
stdin.removeListener("data", onData);
|
|
140
|
-
stdin.setRawMode(wasRaw ?? false);
|
|
141
|
-
if (wasFlowing) {
|
|
142
|
-
stdin.resume();
|
|
143
|
-
} else {
|
|
144
|
-
stdin.pause();
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
stdin.on("data", onData);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
function textPrompt(question) {
|
|
151
|
-
return new Promise((resolve, reject) => {
|
|
152
|
-
const stdin = process.stdin;
|
|
153
|
-
let buffer = "";
|
|
154
|
-
if (typeof stdin.setRawMode !== "function") {
|
|
155
|
-
reject(new Error("Interactive onboarding requires a TTY. Set an API key via environment variable instead."));
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const wasRaw = stdin.isRaw;
|
|
159
|
-
const wasFlowing = stdin.readableFlowing;
|
|
160
|
-
process.stdout.write(question);
|
|
161
|
-
stdin.setRawMode(true);
|
|
162
|
-
stdin.resume();
|
|
163
|
-
function onData(data) {
|
|
164
|
-
const ch = data.toString();
|
|
165
|
-
if (ch === "\x1B") {
|
|
166
|
-
cleanup();
|
|
167
|
-
process.stdout.write("\n");
|
|
168
|
-
resolve(BACK);
|
|
169
|
-
} else if (ch === "") {
|
|
170
|
-
cleanup();
|
|
171
|
-
process.exit(1);
|
|
172
|
-
} else if (ch === "\r" || ch === "\n") {
|
|
173
|
-
cleanup();
|
|
174
|
-
process.stdout.write("\n");
|
|
175
|
-
resolve(buffer.trim());
|
|
176
|
-
} else if (ch === "\x7F" || ch === "\b") {
|
|
177
|
-
if (buffer.length > 0) {
|
|
178
|
-
buffer = buffer.slice(0, -1);
|
|
179
|
-
process.stdout.write("\b \b");
|
|
180
|
-
}
|
|
181
|
-
} else if (ch >= " ") {
|
|
182
|
-
buffer += ch;
|
|
183
|
-
process.stdout.write(ch);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
function cleanup() {
|
|
187
|
-
stdin.removeListener("data", onData);
|
|
188
|
-
stdin.setRawMode(wasRaw ?? false);
|
|
189
|
-
if (wasFlowing) {
|
|
190
|
-
stdin.resume();
|
|
191
|
-
} else {
|
|
192
|
-
stdin.pause();
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
stdin.on("data", onData);
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
async function confirm(question) {
|
|
199
|
-
const result = await arrowSelect(
|
|
200
|
-
[
|
|
201
|
-
{ label: "\u662F", value: "yes" },
|
|
202
|
-
{ label: "\u5426", value: "no" }
|
|
203
|
-
],
|
|
204
|
-
question
|
|
205
|
-
);
|
|
206
|
-
if (result === BACK) return BACK;
|
|
207
|
-
return result === "yes";
|
|
208
|
-
}
|
|
209
|
-
async function validateApiKey(baseUrl, apiKey) {
|
|
210
|
-
try {
|
|
211
|
-
if (baseUrl.includes("openrouter")) {
|
|
212
|
-
const res2 = await fetch("https://openrouter.ai/api/v1/auth/key", {
|
|
213
|
-
headers: { Authorization: `Bearer ${apiKey}` }
|
|
214
|
-
});
|
|
215
|
-
const data = await res2.json();
|
|
216
|
-
return !data.error;
|
|
217
|
-
}
|
|
218
|
-
const url = baseUrl.replace(/\/$/, "") + "/models";
|
|
219
|
-
const res = await fetch(url, {
|
|
220
|
-
headers: { Authorization: `Bearer ${apiKey}` }
|
|
221
|
-
});
|
|
222
|
-
return res.status !== 401 && res.status !== 403;
|
|
223
|
-
} catch {
|
|
224
|
-
return true;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
function hasApiKey() {
|
|
228
|
-
if (process.env.OPENROUTER_API_KEY || process.env.ANTHROPIC_API_KEY || process.env.OPENAI_API_KEY) {
|
|
229
|
-
return true;
|
|
230
|
-
}
|
|
231
|
-
const settingsPaths = [
|
|
232
|
-
join(homedir(), ".code-shell", "settings.json"),
|
|
233
|
-
join(homedir(), ".claude", "settings.json")
|
|
234
|
-
];
|
|
235
|
-
for (const p of settingsPaths) {
|
|
236
|
-
if (existsSync(p)) {
|
|
237
|
-
try {
|
|
238
|
-
const data = JSON.parse(readFileSync(p, "utf-8"));
|
|
239
|
-
if (data?.model?.apiKey) return true;
|
|
240
|
-
} catch {
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
async function runOnboarding() {
|
|
247
|
-
console.log();
|
|
248
|
-
console.log(chalk.bold.cyan(" \u2726 Code Shell \u2014 \u9996\u6B21\u914D\u7F6E"));
|
|
249
|
-
console.log(chalk.dim(" \u2500".repeat(25)));
|
|
250
|
-
let step = "provider";
|
|
251
|
-
let selected = PROVIDERS[0];
|
|
252
|
-
let apiKey = "";
|
|
253
|
-
let model = "";
|
|
254
|
-
let poolModels = [];
|
|
255
|
-
while (step !== "done") {
|
|
256
|
-
switch (step) {
|
|
257
|
-
// ─── Step 1: Provider ────────────────────────────────────
|
|
258
|
-
case "provider": {
|
|
259
|
-
console.log();
|
|
260
|
-
const providerId = await arrowSelect(
|
|
261
|
-
PROVIDERS.map((p) => ({ label: p.name, value: p.id })),
|
|
262
|
-
"\u9009\u62E9 API \u63D0\u4F9B\u5546 (\u2191\u2193 \u79FB\u52A8, Enter \u786E\u8BA4):",
|
|
263
|
-
{ allowBack: false }
|
|
264
|
-
// first step, no back
|
|
265
|
-
);
|
|
266
|
-
if (providerId === BACK) break;
|
|
267
|
-
selected = PROVIDERS.find((p) => p.id === providerId);
|
|
268
|
-
if (selected.id === "custom") {
|
|
269
|
-
const customResult = await configureCustomProvider();
|
|
270
|
-
if (customResult === BACK) break;
|
|
271
|
-
saveSettings(customResult);
|
|
272
|
-
printSuccess(selected.name, customResult.model);
|
|
273
|
-
return customResult;
|
|
274
|
-
}
|
|
275
|
-
step = "apikey";
|
|
276
|
-
break;
|
|
277
|
-
}
|
|
278
|
-
// ─── Step 2: API Key ─────────────────────────────────────
|
|
279
|
-
case "apikey": {
|
|
280
|
-
console.log();
|
|
281
|
-
if (selected.keyUrl) {
|
|
282
|
-
console.log(chalk.dim(` \u83B7\u53D6 API Key: ${chalk.underline(selected.keyUrl)}`));
|
|
283
|
-
}
|
|
284
|
-
console.log();
|
|
285
|
-
const keyResult = await textPrompt(chalk.cyan(` ${selected.envKey || "API Key"}: `));
|
|
286
|
-
if (keyResult === BACK) {
|
|
287
|
-
step = "provider";
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
290
|
-
if (!keyResult) {
|
|
291
|
-
console.log(chalk.yellow(" \u26A0 \u8BF7\u8F93\u5165 API Key (ESC \u8FD4\u56DE\u4E0A\u4E00\u6B65)"));
|
|
292
|
-
break;
|
|
293
|
-
}
|
|
294
|
-
process.stdout.write(chalk.dim(" \u9A8C\u8BC1 Key..."));
|
|
295
|
-
const valid = await validateApiKey(selected.baseUrl, keyResult);
|
|
296
|
-
if (!valid) {
|
|
297
|
-
console.log(chalk.red(" \u2717 \u65E0\u6548"));
|
|
298
|
-
console.log(chalk.yellow(" \u26A0 API Key \u9A8C\u8BC1\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u8BD5 (ESC \u8FD4\u56DE\u4E0A\u4E00\u6B65)"));
|
|
299
|
-
break;
|
|
300
|
-
}
|
|
301
|
-
console.log(chalk.green(" \u2713"));
|
|
302
|
-
apiKey = keyResult;
|
|
303
|
-
step = "model_pool";
|
|
304
|
-
break;
|
|
305
|
-
}
|
|
306
|
-
// ─── Step 3: Model Pool — select which models to enable ──
|
|
307
|
-
case "model_pool": {
|
|
308
|
-
if (selected.models.length <= 1) {
|
|
309
|
-
poolModels = [...selected.models];
|
|
310
|
-
model = selected.defaultModel;
|
|
311
|
-
step = "arena_ask";
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
314
|
-
console.log();
|
|
315
|
-
console.log(chalk.dim(" \u9009\u62E9\u8981\u52A0\u5165\u6A21\u578B\u6C60\u7684\u6A21\u578B (\u6A21\u578B\u6C60\u4E2D\u7684\u6A21\u578B\u53EF\u901A\u8FC7 /model \u968F\u65F6\u5207\u6362)"));
|
|
316
|
-
const poolResult = await selectModelPool(selected.models, selected.defaultModel);
|
|
317
|
-
if (poolResult === BACK) {
|
|
318
|
-
step = "apikey";
|
|
319
|
-
break;
|
|
320
|
-
}
|
|
321
|
-
poolModels = poolResult;
|
|
322
|
-
if (poolModels.length === 0) {
|
|
323
|
-
poolModels = [selected.defaultModel];
|
|
324
|
-
}
|
|
325
|
-
step = "default_model";
|
|
326
|
-
break;
|
|
327
|
-
}
|
|
328
|
-
// ─── Step 4: Default Model — pick from pool ──────────────
|
|
329
|
-
case "default_model": {
|
|
330
|
-
if (poolModels.length === 1) {
|
|
331
|
-
model = poolModels[0];
|
|
332
|
-
saveSettings({ provider: selected.provider, model, apiKey, baseUrl: selected.baseUrl }, selected, poolModels);
|
|
333
|
-
step = "arena_ask";
|
|
334
|
-
break;
|
|
335
|
-
}
|
|
336
|
-
console.log();
|
|
337
|
-
const modelResult = await arrowSelect(
|
|
338
|
-
poolModels.map((m) => ({
|
|
339
|
-
label: m,
|
|
340
|
-
value: m,
|
|
341
|
-
hint: m === selected.defaultModel ? "(\u63A8\u8350)" : void 0
|
|
342
|
-
})),
|
|
343
|
-
"\u9009\u62E9\u9ED8\u8BA4\u6A21\u578B (\u65E5\u5E38\u5BF9\u8BDD\u4F7F\u7528):"
|
|
344
|
-
);
|
|
345
|
-
if (modelResult === BACK) {
|
|
346
|
-
step = "model_pool";
|
|
347
|
-
break;
|
|
348
|
-
}
|
|
349
|
-
model = modelResult;
|
|
350
|
-
saveSettings({ provider: selected.provider, model, apiKey, baseUrl: selected.baseUrl }, selected, poolModels);
|
|
351
|
-
step = "arena_ask";
|
|
352
|
-
break;
|
|
353
|
-
}
|
|
354
|
-
// ─── Step 5: Arena? ─────────────────────────────────────
|
|
355
|
-
case "arena_ask": {
|
|
356
|
-
saveSettings({ provider: selected.provider, model, apiKey, baseUrl: selected.baseUrl }, selected, poolModels);
|
|
357
|
-
if (poolModels.length < 2) {
|
|
358
|
-
step = "done";
|
|
359
|
-
break;
|
|
360
|
-
}
|
|
361
|
-
console.log();
|
|
362
|
-
const wantArena = await confirm("\u662F\u5426\u914D\u7F6E Arena \u591A\u6A21\u578B\u5BF9\u6BD4? (\u53EF\u5728 /arena \u4E2D\u4F7F\u7528\u591A\u4E2A\u6A21\u578B)");
|
|
363
|
-
if (wantArena === BACK) {
|
|
364
|
-
step = "default_model";
|
|
365
|
-
break;
|
|
366
|
-
}
|
|
367
|
-
if (wantArena) {
|
|
368
|
-
step = "arena_config";
|
|
369
|
-
} else {
|
|
370
|
-
step = "done";
|
|
371
|
-
}
|
|
372
|
-
break;
|
|
373
|
-
}
|
|
374
|
-
// ─── Step 6: Arena config — pick from pool ───────────────
|
|
375
|
-
case "arena_config": {
|
|
376
|
-
await configureArenaFromPool(poolModels, model);
|
|
377
|
-
step = "done";
|
|
378
|
-
break;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
const result = { provider: selected.provider, model, apiKey, baseUrl: selected.baseUrl };
|
|
383
|
-
printSuccess(selected.name, model);
|
|
384
|
-
const stdin = process.stdin;
|
|
385
|
-
if (typeof stdin.setRawMode === "function") {
|
|
386
|
-
stdin.setRawMode(false);
|
|
387
|
-
}
|
|
388
|
-
stdin.removeAllListeners("data");
|
|
389
|
-
return result;
|
|
390
|
-
}
|
|
391
|
-
async function selectModelPool(available, defaultModel) {
|
|
392
|
-
const preselected = /* @__PURE__ */ new Set();
|
|
393
|
-
preselected.add(defaultModel);
|
|
394
|
-
const selected = new Set(preselected);
|
|
395
|
-
while (true) {
|
|
396
|
-
console.log();
|
|
397
|
-
console.log(chalk.dim(" \u5F53\u524D\u6A21\u578B\u6C60:"));
|
|
398
|
-
if (selected.size === 0) {
|
|
399
|
-
console.log(chalk.dim(" (\u7A7A)"));
|
|
400
|
-
} else {
|
|
401
|
-
for (const m of selected) {
|
|
402
|
-
console.log(` ${chalk.cyan("\u2713")} ${m}`);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
console.log();
|
|
406
|
-
const notInPool = available.filter((m) => !selected.has(m));
|
|
407
|
-
const options = [
|
|
408
|
-
...notInPool.length > 0 ? [{ label: "\u6DFB\u52A0\u6A21\u578B", value: "add" }] : [],
|
|
409
|
-
...selected.size > 0 ? [{ label: "\u79FB\u9664\u6A21\u578B", value: "remove" }] : [],
|
|
410
|
-
{ label: selected.size > 0 ? `\u2713 \u786E\u8BA4 (${selected.size} \u4E2A\u6A21\u578B)` : "\u8DF3\u8FC7", value: "done" }
|
|
411
|
-
];
|
|
412
|
-
const action = await arrowSelect(options, "\u6A21\u578B\u6C60\u64CD\u4F5C:", { allowBack: true });
|
|
413
|
-
if (action === BACK) return BACK;
|
|
414
|
-
if (action === "done") return [...selected];
|
|
415
|
-
if (action === "add") {
|
|
416
|
-
console.log();
|
|
417
|
-
const choice = await arrowSelect(
|
|
418
|
-
notInPool.map((m) => ({
|
|
419
|
-
label: m,
|
|
420
|
-
value: m,
|
|
421
|
-
hint: m === defaultModel ? "(\u63A8\u8350)" : void 0
|
|
422
|
-
})),
|
|
423
|
-
"\u6DFB\u52A0\u5230\u6A21\u578B\u6C60:"
|
|
424
|
-
);
|
|
425
|
-
if (choice !== BACK) {
|
|
426
|
-
selected.add(choice);
|
|
427
|
-
console.log(chalk.green(` \u2713 \u5DF2\u6DFB\u52A0: ${modelDisplayName(choice)}`));
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
if (action === "remove") {
|
|
431
|
-
const inPool = [...selected];
|
|
432
|
-
console.log();
|
|
433
|
-
const choice = await arrowSelect(
|
|
434
|
-
inPool.map((m) => ({ label: m, value: m })),
|
|
435
|
-
"\u4ECE\u6A21\u578B\u6C60\u79FB\u9664:"
|
|
436
|
-
);
|
|
437
|
-
if (choice !== BACK) {
|
|
438
|
-
selected.delete(choice);
|
|
439
|
-
console.log(chalk.yellow(` \u2717 \u5DF2\u79FB\u9664: ${modelDisplayName(choice)}`));
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
async function configureArenaFromPool(poolModels, defaultModel) {
|
|
445
|
-
const participants = /* @__PURE__ */ new Set();
|
|
446
|
-
console.log();
|
|
447
|
-
console.log(chalk.dim(` \u4ECE\u6A21\u578B\u6C60\u4E2D\u9009\u62E9\u53C2\u4E0E Arena \u5BF9\u6BD4\u7684\u6A21\u578B (\u9ED8\u8BA4\u5BF9\u8BDD\u6A21\u578B: ${chalk.white(defaultModel)})`));
|
|
448
|
-
while (true) {
|
|
449
|
-
console.log();
|
|
450
|
-
if (participants.size > 0) {
|
|
451
|
-
console.log(chalk.dim(" \u5F53\u524D Arena \u9635\u5BB9:"));
|
|
452
|
-
let idx = 0;
|
|
453
|
-
for (const m of participants) {
|
|
454
|
-
idx++;
|
|
455
|
-
console.log(` ${chalk.dim(`${idx}.`)} ${chalk.cyan(modelDisplayName(m))} ${chalk.dim(`(${m})`)}`);
|
|
456
|
-
}
|
|
457
|
-
} else {
|
|
458
|
-
console.log(chalk.dim(" \u5F53\u524D Arena \u9635\u5BB9: (\u7A7A)"));
|
|
459
|
-
}
|
|
460
|
-
console.log();
|
|
461
|
-
const notInArena = poolModels.filter((m) => !participants.has(m));
|
|
462
|
-
const options = [
|
|
463
|
-
...notInArena.length > 0 ? [{ label: "\u4ECE\u6A21\u578B\u6C60\u6DFB\u52A0", value: "add" }] : [],
|
|
464
|
-
...participants.size > 0 ? [{ label: "\u79FB\u9664\u6700\u540E\u6DFB\u52A0\u7684", value: "remove" }] : [],
|
|
465
|
-
{
|
|
466
|
-
label: participants.size >= 2 ? `\u2713 \u5B8C\u6210\u914D\u7F6E (${participants.size} \u4E2A\u6A21\u578B)` : "\u8DF3\u8FC7 (\u81F3\u5C11\u9700\u8981 2 \u4E2A\u6A21\u578B)",
|
|
467
|
-
value: "done"
|
|
468
|
-
}
|
|
469
|
-
];
|
|
470
|
-
const action = await arrowSelect(options, "\u64CD\u4F5C:", { allowBack: true });
|
|
471
|
-
if (action === BACK || action === "done") break;
|
|
472
|
-
if (action === "add") {
|
|
473
|
-
console.log();
|
|
474
|
-
const choice = await arrowSelect(
|
|
475
|
-
notInArena.map((m) => ({ label: `${modelDisplayName(m)} ${chalk.dim(m)}`, value: m })),
|
|
476
|
-
"\u9009\u62E9\u6A21\u578B:"
|
|
477
|
-
);
|
|
478
|
-
if (choice !== BACK) {
|
|
479
|
-
participants.add(choice);
|
|
480
|
-
console.log(chalk.green(` \u2713 \u5DF2\u6DFB\u52A0: ${modelDisplayName(choice)}`));
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
if (action === "remove" && participants.size > 0) {
|
|
484
|
-
const arr = [...participants];
|
|
485
|
-
const removed = arr.pop();
|
|
486
|
-
participants.delete(removed);
|
|
487
|
-
console.log(chalk.yellow(` \u2717 \u5DF2\u79FB\u9664: ${modelDisplayName(removed)}`));
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
if (participants.size >= 2) {
|
|
491
|
-
const arenaKeys = [...participants].map((m) => modelKey(m));
|
|
492
|
-
saveArenaSettingsByKeys(arenaKeys);
|
|
493
|
-
console.log();
|
|
494
|
-
console.log(chalk.green(` \u2713 Arena \u5DF2\u914D\u7F6E ${participants.size} \u4E2A\u6A21\u578B`));
|
|
495
|
-
} else {
|
|
496
|
-
console.log(chalk.dim(" \u8DF3\u8FC7 Arena \u914D\u7F6E (\u9700\u8981\u81F3\u5C11 2 \u4E2A\u6A21\u578B)"));
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
async function configureCustomProvider() {
|
|
500
|
-
console.log();
|
|
501
|
-
const baseUrl = await textPrompt(chalk.cyan(" API Base URL: "));
|
|
502
|
-
if (baseUrl === BACK) return BACK;
|
|
503
|
-
const apiKey = await textPrompt(chalk.cyan(" API Key: "));
|
|
504
|
-
if (apiKey === BACK) return BACK;
|
|
505
|
-
const model = await textPrompt(chalk.cyan(" \u6A21\u578B\u540D\u79F0: "));
|
|
506
|
-
if (model === BACK) return BACK;
|
|
507
|
-
return {
|
|
508
|
-
provider: "openai",
|
|
509
|
-
model: model || "gpt-4o",
|
|
510
|
-
apiKey: apiKey || "",
|
|
511
|
-
baseUrl: baseUrl || "http://localhost:11434/v1"
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
var KNOWN_MAX_OUTPUT = {
|
|
515
|
-
"anthropic/claude-opus-4.6": 32e3,
|
|
516
|
-
"anthropic/claude-opus-4-6": 32e3,
|
|
517
|
-
"claude-opus-4-6": 32e3,
|
|
518
|
-
"anthropic/claude-sonnet-4.6": 16e3,
|
|
519
|
-
"anthropic/claude-sonnet-4-6": 16e3,
|
|
520
|
-
"claude-sonnet-4-6": 16e3,
|
|
521
|
-
"anthropic/claude-haiku-4.5": 8192,
|
|
522
|
-
"anthropic/claude-haiku-4-5": 8192,
|
|
523
|
-
"claude-haiku-4-5": 8192,
|
|
524
|
-
"openai/gpt-5.4": 32e3,
|
|
525
|
-
"gpt-5.4": 32e3,
|
|
526
|
-
"openai/gpt-4o": 16384,
|
|
527
|
-
"gpt-4o": 16384,
|
|
528
|
-
"openai/o4-mini": 1e5,
|
|
529
|
-
"o4-mini": 1e5,
|
|
530
|
-
"openai/o3": 1e5,
|
|
531
|
-
"o3": 1e5,
|
|
532
|
-
"google/gemini-3.1-pro-preview": 65536,
|
|
533
|
-
"google/gemini-3-flash-preview": 65536,
|
|
534
|
-
"google/gemini-2.5-pro": 65536,
|
|
535
|
-
"deepseek/deepseek-v3.2": 8192,
|
|
536
|
-
"deepseek/deepseek-r1": 8192,
|
|
537
|
-
"qwen/qwen3-coder": 16384,
|
|
538
|
-
"qwen/qwen3-235b-a22b": 8192,
|
|
539
|
-
"meta-llama/llama-4-maverick": 32e3,
|
|
540
|
-
"mistralai/devstral-medium": 24e3
|
|
541
|
-
};
|
|
542
|
-
function modelKey(model) {
|
|
543
|
-
const slash = model.lastIndexOf("/");
|
|
544
|
-
const base = slash >= 0 ? model.slice(slash + 1) : model;
|
|
545
|
-
if (base.startsWith("claude-")) {
|
|
546
|
-
const parts = base.split("-");
|
|
547
|
-
return parts.length >= 2 ? `${parts[0]}-${parts[1]}` : parts[0];
|
|
548
|
-
}
|
|
549
|
-
if (base.startsWith("gpt-")) {
|
|
550
|
-
const rest = base.slice(4);
|
|
551
|
-
if (/^\d/.test(rest)) return "gpt";
|
|
552
|
-
return `gpt${rest.split("-")[0]}`;
|
|
553
|
-
}
|
|
554
|
-
if (base.startsWith("gemini-")) {
|
|
555
|
-
if (base.includes("flash")) return "gemini-flash";
|
|
556
|
-
if (base.includes("pro")) return "gemini-pro";
|
|
557
|
-
return "gemini";
|
|
558
|
-
}
|
|
559
|
-
if (base.startsWith("deepseek-")) {
|
|
560
|
-
if (base.includes("r1")) return "deepseek-r1";
|
|
561
|
-
return "deepseek";
|
|
562
|
-
}
|
|
563
|
-
if (base.startsWith("qwen")) {
|
|
564
|
-
if (base.includes("coder")) return "qwen-coder";
|
|
565
|
-
return "qwen";
|
|
566
|
-
}
|
|
567
|
-
if (/^o\d/.test(base)) return base.split("-")[0];
|
|
568
|
-
if (base.startsWith("llama")) return "llama";
|
|
569
|
-
if (base.startsWith("devstral")) return "devstral";
|
|
570
|
-
return base.split("-")[0] ?? base;
|
|
571
|
-
}
|
|
572
|
-
function buildModelPool(provider, apiKey) {
|
|
573
|
-
return provider.models.map((m) => ({
|
|
574
|
-
key: modelKey(m),
|
|
575
|
-
label: modelDisplayName(m),
|
|
576
|
-
provider: provider.provider,
|
|
577
|
-
model: m,
|
|
578
|
-
baseUrl: provider.baseUrl,
|
|
579
|
-
apiKey,
|
|
580
|
-
maxOutputTokens: KNOWN_MAX_OUTPUT[m]
|
|
581
|
-
}));
|
|
582
|
-
}
|
|
583
|
-
function modelDisplayName(model) {
|
|
584
|
-
const slash = model.lastIndexOf("/");
|
|
585
|
-
const base = slash >= 0 ? model.slice(slash + 1) : model;
|
|
586
|
-
const parts = base.split("-");
|
|
587
|
-
if (parts[0] === "claude") {
|
|
588
|
-
const variant = parts[1] ?? "";
|
|
589
|
-
return `Claude ${variant.charAt(0).toUpperCase() + variant.slice(1)}`;
|
|
590
|
-
}
|
|
591
|
-
if (base.startsWith("gpt-")) return `GPT-${parts.slice(1).join("-")}`;
|
|
592
|
-
if (base.startsWith("gemini-")) return `Gemini ${parts.slice(1).join("-")}`;
|
|
593
|
-
return base.charAt(0).toUpperCase() + base.slice(1);
|
|
594
|
-
}
|
|
595
|
-
function printSuccess(providerName, model) {
|
|
596
|
-
console.log();
|
|
597
|
-
console.log(chalk.green(" \u2713 \u914D\u7F6E\u5DF2\u4FDD\u5B58"));
|
|
598
|
-
console.log(chalk.dim(` Provider: ${providerName}`));
|
|
599
|
-
console.log(chalk.dim(` Model: ${model}`));
|
|
600
|
-
console.log(chalk.dim(` Config: ~/.code-shell/settings.json`));
|
|
601
|
-
console.log();
|
|
602
|
-
}
|
|
603
|
-
function saveSettings(result, providerDef, poolModels) {
|
|
604
|
-
const dir = join(homedir(), ".code-shell");
|
|
605
|
-
const file = join(dir, "settings.json");
|
|
606
|
-
mkdirSync(dir, { recursive: true });
|
|
607
|
-
let existing = {};
|
|
608
|
-
if (existsSync(file)) {
|
|
609
|
-
try {
|
|
610
|
-
existing = JSON.parse(readFileSync(file, "utf-8"));
|
|
611
|
-
} catch {
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
const updated = {
|
|
615
|
-
...existing,
|
|
616
|
-
model: {
|
|
617
|
-
...typeof existing.model === "object" ? existing.model : {},
|
|
618
|
-
provider: result.provider,
|
|
619
|
-
name: result.model,
|
|
620
|
-
apiKey: result.apiKey,
|
|
621
|
-
baseUrl: result.baseUrl
|
|
622
|
-
}
|
|
623
|
-
};
|
|
624
|
-
if (providerDef && poolModels && poolModels.length > 0) {
|
|
625
|
-
const allEntries = buildModelPool(providerDef, result.apiKey);
|
|
626
|
-
const selectedSet = new Set(poolModels);
|
|
627
|
-
updated.models = allEntries.filter((e) => selectedSet.has(e.model));
|
|
628
|
-
}
|
|
629
|
-
writeFileSync(file, JSON.stringify(updated, null, 2) + "\n", "utf-8");
|
|
630
|
-
}
|
|
631
|
-
function saveArenaSettingsByKeys(keys) {
|
|
632
|
-
const dir = join(homedir(), ".code-shell");
|
|
633
|
-
const file = join(dir, "settings.json");
|
|
634
|
-
let existing = {};
|
|
635
|
-
if (existsSync(file)) {
|
|
636
|
-
try {
|
|
637
|
-
existing = JSON.parse(readFileSync(file, "utf-8"));
|
|
638
|
-
} catch {
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
const updated = {
|
|
642
|
-
...existing,
|
|
643
|
-
arena: { participants: keys }
|
|
644
|
-
};
|
|
645
|
-
writeFileSync(file, JSON.stringify(updated, null, 2) + "\n", "utf-8");
|
|
646
|
-
}
|
|
647
|
-
async function reconfigure() {
|
|
648
|
-
const file = join(homedir(), ".code-shell", "settings.json");
|
|
649
|
-
if (existsSync(file)) {
|
|
650
|
-
try {
|
|
651
|
-
const settings = JSON.parse(readFileSync(file, "utf-8"));
|
|
652
|
-
delete settings.model?.apiKey;
|
|
653
|
-
writeFileSync(file, JSON.stringify(settings, null, 2) + "\n", "utf-8");
|
|
654
|
-
} catch {
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
return runOnboarding();
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
export {
|
|
661
|
-
hasApiKey,
|
|
662
|
-
runOnboarding,
|
|
663
|
-
reconfigure
|
|
664
|
-
};
|