@cjhyy/code-shell 0.1.0-alpha.1 → 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/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-WYKNZ54E.cjs → chunk-3CAZIWUA.cjs} +6 -6
- 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-JUHRV2XF.js → chunk-ID6EJUHP.js} +1703 -438
- package/dist/chunk-JHNCK7JP.cjs +202 -0
- package/dist/{chunk-MOILS4WE.cjs → chunk-JHXNOB5G.cjs} +3 -3
- 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-AP5F6VYE.js → chunk-REFCCVDM.js} +1 -1
- package/dist/{chunk-O6F2EF2Z.js → chunk-SCDKLTN3.js} +41 -2
- package/dist/{chunk-FECTK5KJ.js → chunk-SW3L7HIM.js} +1 -1
- package/dist/chunk-TATCTZSB.cjs +4753 -0
- package/dist/{chunk-Q6BYFYGD.cjs → chunk-VWFET3MG.cjs} +1886 -621
- 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 +3534 -1996
- package/dist/cli/main.js +3646 -2108
- 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 +29 -6
- package/dist/engine/turn-loop.d.ts +7 -0
- package/dist/engine/turn-state.d.ts +6 -0
- package/dist/index.cjs +19 -28
- 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/protocol/types.d.ts +11 -3
- package/dist/{ink → render}/hooks/use-input.d.ts +1 -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.d.ts +3 -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 +2 -0
- package/dist/types.d.ts +28 -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-2N6745WR.cjs → updater-M7L42ASZ.cjs} +4 -4
- package/dist/{updater-PV7FKSUI.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
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_esm_shims
|
|
3
|
+
} from "./chunk-DI7RDLOS.js";
|
|
4
|
+
|
|
5
|
+
// src/settings/manager.ts
|
|
6
|
+
init_esm_shims();
|
|
7
|
+
import { readFileSync, existsSync, mkdirSync, writeFileSync, renameSync } from "fs";
|
|
8
|
+
import { join, dirname } from "path";
|
|
9
|
+
import { homedir } from "os";
|
|
10
|
+
|
|
11
|
+
// src/settings/schema.ts
|
|
12
|
+
init_esm_shims();
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
var SettingsSchema = z.object({
|
|
15
|
+
agent: z.object({
|
|
16
|
+
// Use z.string() instead of z.enum() to allow custom presets registered via registerPreset()
|
|
17
|
+
preset: z.string().default("terminal-coding"),
|
|
18
|
+
enabledBuiltinTools: z.array(z.string()).default([]),
|
|
19
|
+
disabledBuiltinTools: z.array(z.string()).default([]),
|
|
20
|
+
customSystemPrompt: z.string().optional(),
|
|
21
|
+
appendSystemPrompt: z.string().optional()
|
|
22
|
+
}).default({}),
|
|
23
|
+
model: z.object({
|
|
24
|
+
provider: z.string().default("openai"),
|
|
25
|
+
name: z.string().default("anthropic/claude-opus-4-6"),
|
|
26
|
+
apiKey: z.string().optional(),
|
|
27
|
+
baseUrl: z.string().default("https://openrouter.ai/api/v1"),
|
|
28
|
+
temperature: z.number().min(0).max(2).default(0.3),
|
|
29
|
+
maxTokens: z.number().default(8192)
|
|
30
|
+
}).default({}),
|
|
31
|
+
models: z.array(
|
|
32
|
+
z.object({
|
|
33
|
+
key: z.string(),
|
|
34
|
+
label: z.string().optional(),
|
|
35
|
+
provider: z.string(),
|
|
36
|
+
model: z.string(),
|
|
37
|
+
baseUrl: z.string().optional(),
|
|
38
|
+
apiKey: z.string().optional(),
|
|
39
|
+
maxOutputTokens: z.number().optional(),
|
|
40
|
+
maxContextTokens: z.number().optional()
|
|
41
|
+
})
|
|
42
|
+
).default([]),
|
|
43
|
+
permissions: z.object({
|
|
44
|
+
defaultMode: z.enum(["default", "acceptEdits", "dontAsk", "bypassPermissions", "auto", "plan"]).default("default"),
|
|
45
|
+
rules: z.array(
|
|
46
|
+
z.object({
|
|
47
|
+
tool: z.string(),
|
|
48
|
+
argsPattern: z.record(z.string()).optional(),
|
|
49
|
+
decision: z.enum(["allow", "deny", "ask"]),
|
|
50
|
+
reason: z.string().optional()
|
|
51
|
+
})
|
|
52
|
+
).default([])
|
|
53
|
+
}).default({}),
|
|
54
|
+
context: z.object({
|
|
55
|
+
maxTokens: z.number().default(2e5),
|
|
56
|
+
compactAtRatio: z.number().default(0.6),
|
|
57
|
+
summarizeAtRatio: z.number().default(0.8)
|
|
58
|
+
}).default({}),
|
|
59
|
+
session: z.object({
|
|
60
|
+
storageDir: z.string().optional(),
|
|
61
|
+
maxHistory: z.number().default(100)
|
|
62
|
+
}).default({}),
|
|
63
|
+
mcpServers: z.record(
|
|
64
|
+
z.object({
|
|
65
|
+
name: z.string(),
|
|
66
|
+
command: z.string().optional(),
|
|
67
|
+
args: z.array(z.string()).optional(),
|
|
68
|
+
env: z.record(z.string()).optional(),
|
|
69
|
+
url: z.string().optional(),
|
|
70
|
+
transport: z.enum(["stdio", "sse", "streamable-http", "inprocess"]).optional(),
|
|
71
|
+
headers: z.record(z.string()).optional()
|
|
72
|
+
})
|
|
73
|
+
).default({}),
|
|
74
|
+
instructions: z.object({
|
|
75
|
+
fileName: z.string().default("CODESHELL.md"),
|
|
76
|
+
scanDirs: z.array(z.string()).default([]),
|
|
77
|
+
compatFileNames: z.array(z.string()).default(["CLAUDE.md", "AGENTS.md"]),
|
|
78
|
+
ignoreGitBoundary: z.boolean().default(false)
|
|
79
|
+
}).default({}),
|
|
80
|
+
arena: z.object({
|
|
81
|
+
participants: z.array(
|
|
82
|
+
z.union([
|
|
83
|
+
// Short form: just a model pool key
|
|
84
|
+
z.string(),
|
|
85
|
+
// Full form: explicit config (backward compat)
|
|
86
|
+
z.object({
|
|
87
|
+
name: z.string(),
|
|
88
|
+
model: z.string(),
|
|
89
|
+
provider: z.string().optional(),
|
|
90
|
+
apiKey: z.string().optional(),
|
|
91
|
+
baseUrl: z.string().optional()
|
|
92
|
+
})
|
|
93
|
+
])
|
|
94
|
+
).default([])
|
|
95
|
+
}).default({}),
|
|
96
|
+
search: z.object({
|
|
97
|
+
provider: z.enum(["serper", "tavily", "searxng"]).default("serper"),
|
|
98
|
+
apiKey: z.string().optional(),
|
|
99
|
+
baseUrl: z.string().optional()
|
|
100
|
+
}).default({}),
|
|
101
|
+
output: z.object({
|
|
102
|
+
format: z.enum(["text", "json", "jsonl", "stream-json"]).default("text")
|
|
103
|
+
}).default({})
|
|
104
|
+
}).passthrough();
|
|
105
|
+
function validateSettings(raw) {
|
|
106
|
+
return SettingsSchema.parse(raw);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/settings/manager.ts
|
|
110
|
+
var SettingsManager = class {
|
|
111
|
+
constructor(cwd = process.cwd()) {
|
|
112
|
+
this.cwd = cwd;
|
|
113
|
+
}
|
|
114
|
+
sources = [];
|
|
115
|
+
merged = null;
|
|
116
|
+
/**
|
|
117
|
+
* Load settings from all sources.
|
|
118
|
+
*/
|
|
119
|
+
load(flagOverrides) {
|
|
120
|
+
this.sources = [];
|
|
121
|
+
this.loadJsonFile(join(homedir(), ".code-shell", "settings.managed.json"), "managed", 0);
|
|
122
|
+
this.loadJsonFile(join(homedir(), ".code-shell", "settings.json"), "user", 1);
|
|
123
|
+
this.loadJsonFile(join(homedir(), ".claude", "settings.json"), "user", 1);
|
|
124
|
+
this.loadJsonFile(join(this.cwd, ".code-shell", "settings.json"), "project", 2);
|
|
125
|
+
this.loadJsonFile(join(this.cwd, ".claude", "settings.json"), "project", 2);
|
|
126
|
+
this.loadJsonFile(join(this.cwd, ".code-shell", "settings.local.json"), "local", 3);
|
|
127
|
+
this.loadJsonFile(join(this.cwd, ".claude", "settings.local.json"), "local", 3);
|
|
128
|
+
if (flagOverrides && Object.keys(flagOverrides).length > 0) {
|
|
129
|
+
this.sources.push({ name: "flag", priority: 4, data: flagOverrides });
|
|
130
|
+
}
|
|
131
|
+
this.sources.sort((a, b) => a.priority - b.priority);
|
|
132
|
+
const raw = this.deepMerge();
|
|
133
|
+
this.merged = validateSettings(raw);
|
|
134
|
+
return this.merged;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get current effective settings.
|
|
138
|
+
*/
|
|
139
|
+
get() {
|
|
140
|
+
if (!this.merged) return this.load();
|
|
141
|
+
return this.merged;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Invalidate cached merge.
|
|
145
|
+
*/
|
|
146
|
+
invalidate() {
|
|
147
|
+
this.merged = null;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Persist a single setting (dotted key path) to the user-level config file
|
|
151
|
+
* at ~/.code-shell/settings.json. Other sources (project / local /
|
|
152
|
+
* managed) are intentionally untouched: writing back to project/local
|
|
153
|
+
* would surprise version control, and managed is read-only.
|
|
154
|
+
*
|
|
155
|
+
* The merged cache is invalidated so the next get() picks up the change.
|
|
156
|
+
*/
|
|
157
|
+
saveUserSetting(key, value) {
|
|
158
|
+
const path = join(homedir(), ".code-shell", "settings.json");
|
|
159
|
+
let current = {};
|
|
160
|
+
if (existsSync(path)) {
|
|
161
|
+
try {
|
|
162
|
+
const raw = readFileSync(path, "utf-8");
|
|
163
|
+
const parsed = JSON.parse(raw);
|
|
164
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
165
|
+
current = parsed;
|
|
166
|
+
}
|
|
167
|
+
} catch {
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const parts = key.split(".");
|
|
171
|
+
let target = current;
|
|
172
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
173
|
+
const seg = parts[i];
|
|
174
|
+
const next = target[seg];
|
|
175
|
+
if (!next || typeof next !== "object" || Array.isArray(next)) {
|
|
176
|
+
target[seg] = {};
|
|
177
|
+
}
|
|
178
|
+
target = target[seg];
|
|
179
|
+
}
|
|
180
|
+
target[parts[parts.length - 1]] = value;
|
|
181
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
182
|
+
const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
183
|
+
writeFileSync(tmp, JSON.stringify(current, null, 2), "utf-8");
|
|
184
|
+
renameSync(tmp, path);
|
|
185
|
+
this.invalidate();
|
|
186
|
+
}
|
|
187
|
+
loadJsonFile(path, name, priority) {
|
|
188
|
+
if (!existsSync(path)) return;
|
|
189
|
+
try {
|
|
190
|
+
const content = readFileSync(path, "utf-8");
|
|
191
|
+
const data = JSON.parse(content);
|
|
192
|
+
if (typeof data === "object" && data !== null) {
|
|
193
|
+
this.sources.push({ name, priority, data });
|
|
194
|
+
}
|
|
195
|
+
} catch {
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
deepMerge() {
|
|
199
|
+
let result = {};
|
|
200
|
+
for (const source of this.sources) {
|
|
201
|
+
result = merge(result, source.data);
|
|
202
|
+
}
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
function merge(base, override) {
|
|
207
|
+
const result = { ...base };
|
|
208
|
+
for (const [key, value] of Object.entries(override)) {
|
|
209
|
+
if (value === null) {
|
|
210
|
+
delete result[key];
|
|
211
|
+
} else if (typeof value === "object" && !Array.isArray(value) && typeof result[key] === "object" && !Array.isArray(result[key]) && result[key] !== null) {
|
|
212
|
+
result[key] = merge(result[key], value);
|
|
213
|
+
} else {
|
|
214
|
+
result[key] = value;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export {
|
|
221
|
+
SettingsSchema,
|
|
222
|
+
validateSettings,
|
|
223
|
+
SettingsManager
|
|
224
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
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
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkGZBD6QRScjs = require('./chunk-GZBD6QRS.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -8,12 +8,15 @@ var _chunkDICG4AB7cjs = require('./chunk-DICG4AB7.cjs');
|
|
|
8
8
|
var _chunkEL2RL5DGcjs = require('./chunk-EL2RL5DG.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
var _chunkJHNCK7JPcjs = require('./chunk-JHNCK7JP.cjs');
|
|
12
|
+
|
|
13
|
+
|
|
11
14
|
var _chunkIJSHQGMPcjs = require('./chunk-IJSHQGMP.cjs');
|
|
12
15
|
|
|
13
16
|
// src/llm/providers/anthropic.ts
|
|
14
17
|
_chunkIJSHQGMPcjs.init_cjs_shims.call(void 0, );
|
|
15
18
|
var _sdk = require('@anthropic-ai/sdk'); var _sdk2 = _interopRequireDefault(_sdk);
|
|
16
|
-
var AnthropicClient = (_class = class extends
|
|
19
|
+
var AnthropicClient = (_class = class extends _chunkGZBD6QRScjs.LLMClientBase {
|
|
17
20
|
__init() {this._client = null}
|
|
18
21
|
constructor(config) {
|
|
19
22
|
super(config);_class.prototype.__init.call(this);;
|
|
@@ -34,10 +37,28 @@ var AnthropicClient = (_class = class extends _chunkDICG4AB7cjs.LLMClientBase {
|
|
|
34
37
|
return this.withRetry(async () => {
|
|
35
38
|
const messages = this.buildMessages(options.messages);
|
|
36
39
|
const tools = options.tools ? this.convertTools(options.tools) : void 0;
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
const span = _chunkJHNCK7JPcjs.logger.span("llm.request", {
|
|
41
|
+
cat: "llm",
|
|
42
|
+
provider: this.provider,
|
|
43
|
+
model: this.model,
|
|
44
|
+
stream: !!(options.stream && options.onChunk),
|
|
45
|
+
messageCount: messages.length,
|
|
46
|
+
toolCount: _nullishCoalesce(_optionalChain([tools, 'optionalAccess', _ => _.length]), () => ( 0))
|
|
47
|
+
});
|
|
48
|
+
try {
|
|
49
|
+
const response = options.stream && options.onChunk ? await this.streamMessage(options, messages, tools) : await this.nonStreamMessage(options, messages, tools);
|
|
50
|
+
span.end({
|
|
51
|
+
stopReason: response.stopReason,
|
|
52
|
+
promptTokens: _optionalChain([response, 'access', _2 => _2.usage, 'optionalAccess', _3 => _3.promptTokens]),
|
|
53
|
+
completionTokens: _optionalChain([response, 'access', _4 => _4.usage, 'optionalAccess', _5 => _5.completionTokens]),
|
|
54
|
+
cacheReadTokens: _optionalChain([response, 'access', _6 => _6.usage, 'optionalAccess', _7 => _7.cacheReadTokens]),
|
|
55
|
+
cacheCreationTokens: _optionalChain([response, 'access', _8 => _8.usage, 'optionalAccess', _9 => _9.cacheCreationTokens])
|
|
56
|
+
});
|
|
57
|
+
return response;
|
|
58
|
+
} catch (err) {
|
|
59
|
+
span.fail(err);
|
|
60
|
+
throw err;
|
|
39
61
|
}
|
|
40
|
-
return this.nonStreamMessage(options, messages, tools);
|
|
41
62
|
});
|
|
42
63
|
}
|
|
43
64
|
async nonStreamMessage(options, messages, tools) {
|
|
@@ -54,7 +75,7 @@ var AnthropicClient = (_class = class extends _chunkDICG4AB7cjs.LLMClientBase {
|
|
|
54
75
|
}
|
|
55
76
|
],
|
|
56
77
|
messages,
|
|
57
|
-
..._optionalChain([tools, 'optionalAccess',
|
|
78
|
+
..._optionalChain([tools, 'optionalAccess', _10 => _10.length]) ? { tools } : {},
|
|
58
79
|
...options.temperature !== void 0 ? { temperature: options.temperature } : { temperature: this.temperature }
|
|
59
80
|
},
|
|
60
81
|
{ signal: options.signal }
|
|
@@ -87,7 +108,7 @@ var AnthropicClient = (_class = class extends _chunkDICG4AB7cjs.LLMClientBase {
|
|
|
87
108
|
}
|
|
88
109
|
],
|
|
89
110
|
messages,
|
|
90
|
-
..._optionalChain([tools, 'optionalAccess',
|
|
111
|
+
..._optionalChain([tools, 'optionalAccess', _11 => _11.length]) ? { tools } : {},
|
|
91
112
|
...options.temperature !== void 0 ? { temperature: options.temperature } : { temperature: this.temperature }
|
|
92
113
|
},
|
|
93
114
|
{ signal: options.signal }
|
|
@@ -96,16 +117,27 @@ var AnthropicClient = (_class = class extends _chunkDICG4AB7cjs.LLMClientBase {
|
|
|
96
117
|
let currentToolName = "";
|
|
97
118
|
let currentToolId = "";
|
|
98
119
|
let currentToolInput = "";
|
|
120
|
+
const streamStartedAt = Date.now();
|
|
121
|
+
let firstByteLogged = false;
|
|
99
122
|
stream.on("text", (text) => {
|
|
123
|
+
if (!firstByteLogged) {
|
|
124
|
+
firstByteLogged = true;
|
|
125
|
+
_chunkJHNCK7JPcjs.logger.debug("llm.first_byte", {
|
|
126
|
+
cat: "llm",
|
|
127
|
+
provider: this.provider,
|
|
128
|
+
model: this.model,
|
|
129
|
+
ttft_ms: Date.now() - streamStartedAt
|
|
130
|
+
});
|
|
131
|
+
}
|
|
100
132
|
currentText += text;
|
|
101
|
-
_optionalChain([options, 'access',
|
|
133
|
+
_optionalChain([options, 'access', _12 => _12.onChunk, 'optionalCall', _13 => _13({ type: "text", text })]);
|
|
102
134
|
});
|
|
103
135
|
stream.on("contentBlock", (block) => {
|
|
104
136
|
if (block.type === "tool_use") {
|
|
105
137
|
currentToolName = block.name;
|
|
106
138
|
currentToolId = block.id;
|
|
107
139
|
currentToolInput = "";
|
|
108
|
-
_optionalChain([options, 'access',
|
|
140
|
+
_optionalChain([options, 'access', _14 => _14.onChunk, 'optionalCall', _15 => _15({
|
|
109
141
|
type: "tool_use_start",
|
|
110
142
|
toolCall: { id: block.id, toolName: block.name, args: {} }
|
|
111
143
|
})]);
|
|
@@ -113,6 +145,16 @@ var AnthropicClient = (_class = class extends _chunkDICG4AB7cjs.LLMClientBase {
|
|
|
113
145
|
});
|
|
114
146
|
stream.on("inputJson", (_delta, snapshot) => {
|
|
115
147
|
currentToolInput = JSON.stringify(snapshot);
|
|
148
|
+
if (currentToolId) {
|
|
149
|
+
_optionalChain([options, 'access', _16 => _16.onChunk, 'optionalCall', _17 => _17({
|
|
150
|
+
type: "tool_use_delta",
|
|
151
|
+
toolCall: {
|
|
152
|
+
id: currentToolId,
|
|
153
|
+
toolName: currentToolName,
|
|
154
|
+
args: _nullishCoalesce(snapshot, () => ( {}))
|
|
155
|
+
}
|
|
156
|
+
})]);
|
|
157
|
+
}
|
|
116
158
|
});
|
|
117
159
|
const finalMessage = await stream.finalMessage();
|
|
118
160
|
const usage = {
|
|
@@ -123,7 +165,7 @@ var AnthropicClient = (_class = class extends _chunkDICG4AB7cjs.LLMClientBase {
|
|
|
123
165
|
cacheCreationTokens: finalMessage.usage.cache_creation_input_tokens
|
|
124
166
|
};
|
|
125
167
|
this.recordUsage(usage);
|
|
126
|
-
_optionalChain([options, 'access',
|
|
168
|
+
_optionalChain([options, 'access', _18 => _18.onChunk, 'optionalCall', _19 => _19({ type: "stop", stopReason: _nullishCoalesce(finalMessage.stop_reason, () => ( void 0)) })]);
|
|
127
169
|
return this.processResponse(finalMessage, usage);
|
|
128
170
|
} catch (err) {
|
|
129
171
|
this.handleApiError(err);
|
|
@@ -206,7 +248,7 @@ var AnthropicClient = (_class = class extends _chunkDICG4AB7cjs.LLMClientBase {
|
|
|
206
248
|
if (err.status === 429) {
|
|
207
249
|
throw new (0, _chunkEL2RL5DGcjs.LLMRateLimitError)("anthropic");
|
|
208
250
|
}
|
|
209
|
-
if (_optionalChain([err, 'access',
|
|
251
|
+
if (_optionalChain([err, 'access', _20 => _20.message, 'optionalAccess', _21 => _21.includes, 'call', _22 => _22("prompt is too long")]) || _optionalChain([err, 'access', _23 => _23.message, 'optionalAccess', _24 => _24.includes, 'call', _25 => _25("context_length_exceeded")])) {
|
|
210
252
|
throw new (0, _chunkEL2RL5DGcjs.ContextLimitError)("anthropic");
|
|
211
253
|
}
|
|
212
254
|
throw new (0, _chunkEL2RL5DGcjs.LLMError)(`Anthropic API error: ${err.message}`, "anthropic", {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkJHNCK7JPcjs = require('./chunk-JHNCK7JP.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkIJSHQGMPcjs = require('./chunk-IJSHQGMP.cjs');
|
|
@@ -35,7 +35,7 @@ var MCPManager = (_class = class _MCPManager {
|
|
|
35
35
|
for (let i = 0; i < results.length; i++) {
|
|
36
36
|
const result = results[i];
|
|
37
37
|
if (result.status === "rejected") {
|
|
38
|
-
|
|
38
|
+
_chunkJHNCK7JPcjs.logger.warn("mcp.connect_failed", {
|
|
39
39
|
server: entries[i][0],
|
|
40
40
|
error: result.reason.message
|
|
41
41
|
});
|
|
@@ -47,10 +47,10 @@ var MCPManager = (_class = class _MCPManager {
|
|
|
47
47
|
*/
|
|
48
48
|
async connect(name, config) {
|
|
49
49
|
if (this.connections.has(name)) {
|
|
50
|
-
|
|
50
|
+
_chunkJHNCK7JPcjs.logger.info("mcp.already_connected", { server: name });
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
_chunkJHNCK7JPcjs.logger.info("mcp.connecting", { server: name, transport: _nullishCoalesce(config.transport, () => ( "stdio")) });
|
|
54
54
|
const client = new (0, _indexjs.Client)(
|
|
55
55
|
{ name: "code-shell", version: "0.1.0" },
|
|
56
56
|
{ capabilities: {} }
|
|
@@ -99,7 +99,7 @@ var MCPManager = (_class = class _MCPManager {
|
|
|
99
99
|
}
|
|
100
100
|
this.connections.set(name, { client, serverName: name, transport });
|
|
101
101
|
await this.discoverTools(name, client);
|
|
102
|
-
|
|
102
|
+
_chunkJHNCK7JPcjs.logger.info("mcp.connected", { server: name });
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
105
|
* Discover tools from an MCP server and register them.
|
|
@@ -131,7 +131,7 @@ var MCPManager = (_class = class _MCPManager {
|
|
|
131
131
|
}
|
|
132
132
|
return parts.join("\n") || "(no output)";
|
|
133
133
|
});
|
|
134
|
-
|
|
134
|
+
_chunkJHNCK7JPcjs.logger.info("mcp.tool_registered", { server: serverName, tool: registered.name });
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
@@ -141,9 +141,9 @@ var MCPManager = (_class = class _MCPManager {
|
|
|
141
141
|
for (const [name, conn] of this.connections) {
|
|
142
142
|
try {
|
|
143
143
|
await conn.client.close();
|
|
144
|
-
|
|
144
|
+
_chunkJHNCK7JPcjs.logger.info("mcp.disconnected", { server: name });
|
|
145
145
|
} catch (err) {
|
|
146
|
-
|
|
146
|
+
_chunkJHNCK7JPcjs.logger.warn("mcp.disconnect_error", { server: name, error: err.message });
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
this.connections.clear();
|
|
@@ -4,6 +4,17 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// src/llm/model-pool.ts
|
|
6
6
|
init_esm_shims();
|
|
7
|
+
var BUILTIN_CONTEXT_WINDOWS = [
|
|
8
|
+
// DeepSeek V4 family — 1M context (api-docs.deepseek.com)
|
|
9
|
+
[/^deepseek-v4(?:-|$)/i, 1e6],
|
|
10
|
+
[/(?:^|\/)deepseek-v4(?:-|$)/i, 1e6]
|
|
11
|
+
];
|
|
12
|
+
function lookupBuiltinContextWindow(model) {
|
|
13
|
+
for (const [re, tokens] of BUILTIN_CONTEXT_WINDOWS) {
|
|
14
|
+
if (re.test(model)) return tokens;
|
|
15
|
+
}
|
|
16
|
+
return void 0;
|
|
17
|
+
}
|
|
7
18
|
var ModelPool = class {
|
|
8
19
|
models = /* @__PURE__ */ new Map();
|
|
9
20
|
activeKey;
|
|
@@ -14,7 +25,7 @@ var ModelPool = class {
|
|
|
14
25
|
constructor(entries, defaultKey) {
|
|
15
26
|
if (entries) {
|
|
16
27
|
for (const e of entries) {
|
|
17
|
-
this.models.set(e.key, e);
|
|
28
|
+
this.models.set(e.key, this.withBuiltinDefaults(e));
|
|
18
29
|
}
|
|
19
30
|
}
|
|
20
31
|
if (defaultKey && this.models.has(defaultKey)) {
|
|
@@ -25,11 +36,18 @@ var ModelPool = class {
|
|
|
25
36
|
}
|
|
26
37
|
/** Register a model at runtime. */
|
|
27
38
|
register(entry) {
|
|
28
|
-
this.models.set(entry.key, entry);
|
|
39
|
+
this.models.set(entry.key, this.withBuiltinDefaults(entry));
|
|
29
40
|
if (!this.activeKey) {
|
|
30
41
|
this.activeKey = entry.key;
|
|
31
42
|
}
|
|
32
43
|
}
|
|
44
|
+
/** Fill in known defaults (e.g. context window for DeepSeek V4) when the entry doesn't specify them. */
|
|
45
|
+
withBuiltinDefaults(entry) {
|
|
46
|
+
if (entry.maxContextTokens != null) return entry;
|
|
47
|
+
const builtin = lookupBuiltinContextWindow(entry.model);
|
|
48
|
+
if (builtin == null) return entry;
|
|
49
|
+
return { ...entry, maxContextTokens: builtin };
|
|
50
|
+
}
|
|
33
51
|
/** Switch the active model. Throws if key not found. */
|
|
34
52
|
switch(key) {
|
|
35
53
|
const entry = this.models.get(key);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
setOpenRouterSnapshot
|
|
3
|
+
} from "./chunk-OMRGA6TI.js";
|
|
4
|
+
import {
|
|
5
|
+
init_esm_shims
|
|
6
|
+
} from "./chunk-DI7RDLOS.js";
|
|
7
|
+
|
|
8
|
+
// src/data/openrouter-sync.ts
|
|
9
|
+
init_esm_shims();
|
|
10
|
+
var ENDPOINT = "https://openrouter.ai/api/v1/models";
|
|
11
|
+
function priceToPerMillion(raw) {
|
|
12
|
+
if (!raw) return 0;
|
|
13
|
+
const n = Number(raw);
|
|
14
|
+
return Number.isFinite(n) ? n * 1e6 : 0;
|
|
15
|
+
}
|
|
16
|
+
function slim(m) {
|
|
17
|
+
return {
|
|
18
|
+
id: m.id,
|
|
19
|
+
name: m.name ?? m.id,
|
|
20
|
+
created: m.created ?? 0,
|
|
21
|
+
contextLength: m.top_provider?.context_length ?? m.context_length ?? 0,
|
|
22
|
+
maxOutputTokens: m.top_provider?.max_completion_tokens ?? 0,
|
|
23
|
+
inputPricePerMillion: priceToPerMillion(m.pricing?.prompt),
|
|
24
|
+
outputPricePerMillion: priceToPerMillion(m.pricing?.completion),
|
|
25
|
+
modalities: m.architecture?.input_modalities ?? []
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async function syncOpenRouterCatalog(timeoutMs = 15e3) {
|
|
29
|
+
try {
|
|
30
|
+
const res = await fetch(ENDPOINT, {
|
|
31
|
+
headers: { Accept: "application/json" },
|
|
32
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
33
|
+
});
|
|
34
|
+
if (!res.ok) {
|
|
35
|
+
return { ok: false, count: 0, error: `HTTP ${res.status} ${res.statusText}` };
|
|
36
|
+
}
|
|
37
|
+
const payload = await res.json();
|
|
38
|
+
const raw = payload.data ?? [];
|
|
39
|
+
const models = raw.map(slim).sort((a, b) => b.created - a.created);
|
|
40
|
+
setOpenRouterSnapshot({
|
|
41
|
+
fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
42
|
+
source: ENDPOINT,
|
|
43
|
+
count: models.length,
|
|
44
|
+
models
|
|
45
|
+
});
|
|
46
|
+
return { ok: true, count: models.length };
|
|
47
|
+
} catch (err) {
|
|
48
|
+
return { ok: false, count: 0, error: err.message };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
syncOpenRouterCatalog
|
|
54
|
+
};
|