cerebras-cli 1.0.1 → 1.0.4
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 +3 -5
- package/cerebras-cli-1.0.0.tgz +0 -0
- package/package.json +7 -88
- package/AGENTS.md +0 -27
- package/Dockerfile +0 -10
- package/bunfig.toml +0 -4
- package/parsers-config.ts +0 -239
- package/script/build.ts +0 -151
- package/script/postinstall.mjs +0 -122
- package/script/publish.ts +0 -256
- package/script/schema.ts +0 -47
- package/src/acp/README.md +0 -164
- package/src/acp/agent.ts +0 -812
- package/src/acp/session.ts +0 -70
- package/src/acp/types.ts +0 -22
- package/src/agent/agent.ts +0 -310
- package/src/agent/generate.txt +0 -75
- package/src/auth/index.ts +0 -70
- package/src/bun/index.ts +0 -152
- package/src/bus/global.ts +0 -10
- package/src/bus/index.ts +0 -142
- package/src/cli/bootstrap.ts +0 -17
- package/src/cli/cmd/acp.ts +0 -88
- package/src/cli/cmd/agent.ts +0 -165
- package/src/cli/cmd/auth.ts +0 -369
- package/src/cli/cmd/cmd.ts +0 -7
- package/src/cli/cmd/debug/config.ts +0 -15
- package/src/cli/cmd/debug/file.ts +0 -91
- package/src/cli/cmd/debug/index.ts +0 -41
- package/src/cli/cmd/debug/lsp.ts +0 -47
- package/src/cli/cmd/debug/ripgrep.ts +0 -83
- package/src/cli/cmd/debug/scrap.ts +0 -15
- package/src/cli/cmd/debug/snapshot.ts +0 -48
- package/src/cli/cmd/export.ts +0 -88
- package/src/cli/cmd/generate.ts +0 -38
- package/src/cli/cmd/github.ts +0 -1200
- package/src/cli/cmd/import.ts +0 -98
- package/src/cli/cmd/mcp.ts +0 -400
- package/src/cli/cmd/models.ts +0 -77
- package/src/cli/cmd/pr.ts +0 -112
- package/src/cli/cmd/run.ts +0 -342
- package/src/cli/cmd/serve.ts +0 -31
- package/src/cli/cmd/session.ts +0 -106
- package/src/cli/cmd/stats.ts +0 -298
- package/src/cli/cmd/tui/app.tsx +0 -732
- package/src/cli/cmd/tui/attach.ts +0 -25
- package/src/cli/cmd/tui/component/border.tsx +0 -21
- package/src/cli/cmd/tui/component/dialog-agent.tsx +0 -31
- package/src/cli/cmd/tui/component/dialog-command.tsx +0 -124
- package/src/cli/cmd/tui/component/dialog-feedback.tsx +0 -160
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +0 -86
- package/src/cli/cmd/tui/component/dialog-model.tsx +0 -223
- package/src/cli/cmd/tui/component/dialog-notification.tsx +0 -78
- package/src/cli/cmd/tui/component/dialog-provider.tsx +0 -222
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +0 -97
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +0 -31
- package/src/cli/cmd/tui/component/dialog-status.tsx +0 -114
- package/src/cli/cmd/tui/component/dialog-tag.tsx +0 -44
- package/src/cli/cmd/tui/component/dialog-theme-list.tsx +0 -50
- package/src/cli/cmd/tui/component/logo.tsx +0 -37
- package/src/cli/cmd/tui/component/notification-banner.tsx +0 -58
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +0 -530
- package/src/cli/cmd/tui/component/prompt/history.tsx +0 -107
- package/src/cli/cmd/tui/component/prompt/index.tsx +0 -931
- package/src/cli/cmd/tui/context/args.tsx +0 -14
- package/src/cli/cmd/tui/context/directory.ts +0 -12
- package/src/cli/cmd/tui/context/exit.tsx +0 -23
- package/src/cli/cmd/tui/context/helper.tsx +0 -25
- package/src/cli/cmd/tui/context/keybind.tsx +0 -111
- package/src/cli/cmd/tui/context/kv.tsx +0 -49
- package/src/cli/cmd/tui/context/local.tsx +0 -339
- package/src/cli/cmd/tui/context/prompt.tsx +0 -18
- package/src/cli/cmd/tui/context/route.tsx +0 -45
- package/src/cli/cmd/tui/context/sdk.tsx +0 -75
- package/src/cli/cmd/tui/context/sync.tsx +0 -374
- package/src/cli/cmd/tui/context/theme/aura.json +0 -69
- package/src/cli/cmd/tui/context/theme/ayu.json +0 -80
- package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +0 -233
- package/src/cli/cmd/tui/context/theme/catppuccin.json +0 -112
- package/src/cli/cmd/tui/context/theme/cobalt2.json +0 -228
- package/src/cli/cmd/tui/context/theme/dracula.json +0 -219
- package/src/cli/cmd/tui/context/theme/everforest.json +0 -241
- package/src/cli/cmd/tui/context/theme/flexoki.json +0 -237
- package/src/cli/cmd/tui/context/theme/github.json +0 -233
- package/src/cli/cmd/tui/context/theme/gruvbox.json +0 -95
- package/src/cli/cmd/tui/context/theme/kanagawa.json +0 -77
- package/src/cli/cmd/tui/context/theme/material.json +0 -235
- package/src/cli/cmd/tui/context/theme/matrix.json +0 -77
- package/src/cli/cmd/tui/context/theme/mercury.json +0 -252
- package/src/cli/cmd/tui/context/theme/monokai.json +0 -221
- package/src/cli/cmd/tui/context/theme/nightowl.json +0 -221
- package/src/cli/cmd/tui/context/theme/nord.json +0 -223
- package/src/cli/cmd/tui/context/theme/one-dark.json +0 -84
- package/src/cli/cmd/tui/context/theme/orng.json +0 -245
- package/src/cli/cmd/tui/context/theme/palenight.json +0 -222
- package/src/cli/cmd/tui/context/theme/rosepine.json +0 -234
- package/src/cli/cmd/tui/context/theme/solarized.json +0 -223
- package/src/cli/cmd/tui/context/theme/synthwave84.json +0 -226
- package/src/cli/cmd/tui/context/theme/tokyonight.json +0 -243
- package/src/cli/cmd/tui/context/theme/vercel.json +0 -245
- package/src/cli/cmd/tui/context/theme/vesper.json +0 -218
- package/src/cli/cmd/tui/context/theme/zenburn.json +0 -223
- package/src/cli/cmd/tui/context/theme.tsx +0 -1077
- package/src/cli/cmd/tui/event.ts +0 -39
- package/src/cli/cmd/tui/routes/home.tsx +0 -104
- package/src/cli/cmd/tui/routes/session/dialog-message.tsx +0 -93
- package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +0 -37
- package/src/cli/cmd/tui/routes/session/footer.tsx +0 -76
- package/src/cli/cmd/tui/routes/session/header.tsx +0 -183
- package/src/cli/cmd/tui/routes/session/index.tsx +0 -1703
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +0 -586
- package/src/cli/cmd/tui/spawn.ts +0 -60
- package/src/cli/cmd/tui/thread.ts +0 -120
- package/src/cli/cmd/tui/ui/dialog-alert.tsx +0 -55
- package/src/cli/cmd/tui/ui/dialog-confirm.tsx +0 -81
- package/src/cli/cmd/tui/ui/dialog-help.tsx +0 -36
- package/src/cli/cmd/tui/ui/dialog-prompt.tsx +0 -75
- package/src/cli/cmd/tui/ui/dialog-select.tsx +0 -317
- package/src/cli/cmd/tui/ui/dialog.tsx +0 -170
- package/src/cli/cmd/tui/ui/spinner.ts +0 -368
- package/src/cli/cmd/tui/ui/toast.tsx +0 -100
- package/src/cli/cmd/tui/util/clipboard.ts +0 -127
- package/src/cli/cmd/tui/util/editor.ts +0 -32
- package/src/cli/cmd/tui/util/terminal.ts +0 -114
- package/src/cli/cmd/tui/worker.ts +0 -63
- package/src/cli/cmd/uninstall.ts +0 -344
- package/src/cli/cmd/upgrade.ts +0 -67
- package/src/cli/cmd/web.ts +0 -84
- package/src/cli/error.ts +0 -55
- package/src/cli/ui.ts +0 -84
- package/src/cli/upgrade.ts +0 -25
- package/src/command/index.ts +0 -79
- package/src/command/template/initialize.txt +0 -10
- package/src/command/template/review.txt +0 -73
- package/src/config/config.ts +0 -886
- package/src/config/markdown.ts +0 -41
- package/src/env/index.ts +0 -26
- package/src/file/fzf.ts +0 -124
- package/src/file/ignore.ts +0 -83
- package/src/file/index.ts +0 -326
- package/src/file/ripgrep.ts +0 -391
- package/src/file/time.ts +0 -38
- package/src/file/watcher.ts +0 -89
- package/src/flag/flag.ts +0 -28
- package/src/format/formatter.ts +0 -277
- package/src/format/index.ts +0 -137
- package/src/global/index.ts +0 -52
- package/src/id/id.ts +0 -73
- package/src/ide/index.ts +0 -75
- package/src/index.ts +0 -158
- package/src/installation/index.ts +0 -194
- package/src/lsp/client.ts +0 -215
- package/src/lsp/index.ts +0 -370
- package/src/lsp/language.ts +0 -111
- package/src/lsp/server.ts +0 -1327
- package/src/mcp/auth.ts +0 -82
- package/src/mcp/index.ts +0 -576
- package/src/mcp/oauth-callback.ts +0 -203
- package/src/mcp/oauth-provider.ts +0 -132
- package/src/notification/index.ts +0 -101
- package/src/patch/index.ts +0 -622
- package/src/permission/index.ts +0 -198
- package/src/plugin/index.ts +0 -95
- package/src/project/bootstrap.ts +0 -31
- package/src/project/instance.ts +0 -68
- package/src/project/project.ts +0 -133
- package/src/project/state.ts +0 -65
- package/src/project/vcs.ts +0 -77
- package/src/provider/auth.ts +0 -143
- package/src/provider/models-macro.ts +0 -11
- package/src/provider/models.ts +0 -93
- package/src/provider/provider.ts +0 -996
- package/src/provider/sdk/openai-compatible/src/README.md +0 -5
- package/src/provider/sdk/openai-compatible/src/index.ts +0 -2
- package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +0 -100
- package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +0 -303
- package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +0 -27
- package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +0 -18
- package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +0 -22
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +0 -207
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +0 -1713
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +0 -177
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +0 -1
- package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +0 -88
- package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +0 -128
- package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +0 -115
- package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +0 -65
- package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +0 -104
- package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +0 -103
- package/src/provider/transform.ts +0 -406
- package/src/pty/index.ts +0 -226
- package/src/ratelimit/index.ts +0 -185
- package/src/server/error.ts +0 -36
- package/src/server/project.ts +0 -50
- package/src/server/server.ts +0 -2463
- package/src/server/tui.ts +0 -71
- package/src/session/compaction.ts +0 -257
- package/src/session/index.ts +0 -470
- package/src/session/message-v2.ts +0 -641
- package/src/session/message.ts +0 -189
- package/src/session/processor.ts +0 -443
- package/src/session/prompt/anthropic-20250930.txt +0 -166
- package/src/session/prompt/anthropic.txt +0 -105
- package/src/session/prompt/anthropic_spoof.txt +0 -1
- package/src/session/prompt/beast.txt +0 -147
- package/src/session/prompt/build-switch.txt +0 -5
- package/src/session/prompt/codex.txt +0 -318
- package/src/session/prompt/compaction.txt +0 -12
- package/src/session/prompt/copilot-gpt-5.txt +0 -143
- package/src/session/prompt/gemini.txt +0 -155
- package/src/session/prompt/max-steps.txt +0 -16
- package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
- package/src/session/prompt/plan.txt +0 -26
- package/src/session/prompt/polaris.txt +0 -107
- package/src/session/prompt/qwen.txt +0 -109
- package/src/session/prompt/summarize.txt +0 -4
- package/src/session/prompt/title.txt +0 -36
- package/src/session/prompt.ts +0 -1541
- package/src/session/retry.ts +0 -82
- package/src/session/revert.ts +0 -108
- package/src/session/status.ts +0 -75
- package/src/session/summary.ts +0 -203
- package/src/session/system.ts +0 -148
- package/src/session/todo.ts +0 -36
- package/src/share/share-next.ts +0 -195
- package/src/share/share.ts +0 -87
- package/src/snapshot/index.ts +0 -197
- package/src/storage/storage.ts +0 -226
- package/src/telemetry/index.ts +0 -232
- package/src/tool/bash.ts +0 -365
- package/src/tool/bash.txt +0 -128
- package/src/tool/batch.ts +0 -173
- package/src/tool/batch.txt +0 -28
- package/src/tool/codesearch.ts +0 -138
- package/src/tool/codesearch.txt +0 -12
- package/src/tool/edit.ts +0 -674
- package/src/tool/edit.txt +0 -10
- package/src/tool/glob.ts +0 -65
- package/src/tool/glob.txt +0 -6
- package/src/tool/grep.ts +0 -120
- package/src/tool/grep.txt +0 -8
- package/src/tool/invalid.ts +0 -17
- package/src/tool/ls.ts +0 -110
- package/src/tool/ls.txt +0 -1
- package/src/tool/lsp-diagnostics.ts +0 -26
- package/src/tool/lsp-diagnostics.txt +0 -1
- package/src/tool/lsp-hover.ts +0 -31
- package/src/tool/lsp-hover.txt +0 -1
- package/src/tool/multiedit.ts +0 -46
- package/src/tool/multiedit.txt +0 -41
- package/src/tool/patch.ts +0 -233
- package/src/tool/patch.txt +0 -1
- package/src/tool/read.ts +0 -217
- package/src/tool/read.txt +0 -12
- package/src/tool/registry.ts +0 -148
- package/src/tool/task.ts +0 -135
- package/src/tool/task.txt +0 -60
- package/src/tool/todo.ts +0 -39
- package/src/tool/todoread.txt +0 -14
- package/src/tool/todowrite.txt +0 -167
- package/src/tool/tool.ts +0 -66
- package/src/tool/webfetch.ts +0 -187
- package/src/tool/webfetch.txt +0 -14
- package/src/tool/websearch.ts +0 -150
- package/src/tool/websearch.txt +0 -11
- package/src/tool/write.ts +0 -99
- package/src/tool/write.txt +0 -8
- package/src/types/shims.d.ts +0 -3
- package/src/util/color.ts +0 -19
- package/src/util/context.ts +0 -25
- package/src/util/defer.ts +0 -12
- package/src/util/eventloop.ts +0 -20
- package/src/util/filesystem.ts +0 -69
- package/src/util/fn.ts +0 -11
- package/src/util/iife.ts +0 -3
- package/src/util/keybind.ts +0 -79
- package/src/util/lazy.ts +0 -11
- package/src/util/locale.ts +0 -81
- package/src/util/lock.ts +0 -98
- package/src/util/log.ts +0 -177
- package/src/util/queue.ts +0 -32
- package/src/util/rpc.ts +0 -42
- package/src/util/scrap.ts +0 -10
- package/src/util/signal.ts +0 -12
- package/src/util/timeout.ts +0 -14
- package/src/util/token.ts +0 -7
- package/src/util/wildcard.ts +0 -54
- package/sst-env.d.ts +0 -9
- package/test/bun.test.ts +0 -53
- package/test/config/agent-color.test.ts +0 -66
- package/test/config/config.test.ts +0 -503
- package/test/config/markdown.test.ts +0 -89
- package/test/file/ignore.test.ts +0 -10
- package/test/fixture/fixture.ts +0 -28
- package/test/fixture/lsp/fake-lsp-server.js +0 -77
- package/test/ide/ide.test.ts +0 -82
- package/test/keybind.test.ts +0 -317
- package/test/lsp/client.test.ts +0 -95
- package/test/patch/patch.test.ts +0 -348
- package/test/preload.ts +0 -38
- package/test/project/project.test.ts +0 -42
- package/test/provider/provider.test.ts +0 -1809
- package/test/provider/transform.test.ts +0 -305
- package/test/session/retry.test.ts +0 -61
- package/test/session/session.test.ts +0 -71
- package/test/snapshot/snapshot.test.ts +0 -939
- package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
- package/test/tool/bash.test.ts +0 -55
- package/test/tool/patch.test.ts +0 -259
- package/test/util/iife.test.ts +0 -36
- package/test/util/lazy.test.ts +0 -50
- package/test/util/timeout.test.ts +0 -21
- package/test/util/wildcard.test.ts +0 -55
- package/tsconfig.json +0 -17
package/src/pty/index.ts
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { type IPty } from "bun-pty"
|
|
2
|
-
import z from "zod"
|
|
3
|
-
import { Identifier } from "../id/id"
|
|
4
|
-
import { Log } from "../util/log"
|
|
5
|
-
import { Bus } from "../bus"
|
|
6
|
-
import type { WSContext } from "hono/ws"
|
|
7
|
-
import { Instance } from "../project/instance"
|
|
8
|
-
import { shell } from "@opencode-ai/util/shell"
|
|
9
|
-
import { lazy } from "@opencode-ai/util/lazy"
|
|
10
|
-
import {} from "process"
|
|
11
|
-
import { Installation } from "@/installation"
|
|
12
|
-
|
|
13
|
-
export namespace Pty {
|
|
14
|
-
const log = Log.create({ service: "pty" })
|
|
15
|
-
|
|
16
|
-
const pty = lazy(async () => {
|
|
17
|
-
if (!Installation.isLocal()) {
|
|
18
|
-
const path = require(
|
|
19
|
-
`bun-pty/rust-pty/target/release/${
|
|
20
|
-
process.platform === "win32"
|
|
21
|
-
? "rust_pty.dll"
|
|
22
|
-
: process.platform === "linux" && process.arch === "x64"
|
|
23
|
-
? "librust_pty.so"
|
|
24
|
-
: process.platform === "darwin" && process.arch === "x64"
|
|
25
|
-
? "librust_pty.dylib"
|
|
26
|
-
: process.platform === "darwin" && process.arch === "arm64"
|
|
27
|
-
? "librust_pty_arm64.dylib"
|
|
28
|
-
: process.platform === "linux" && process.arch === "arm64"
|
|
29
|
-
? "librust_pty_arm64.so"
|
|
30
|
-
: ""
|
|
31
|
-
}`,
|
|
32
|
-
)
|
|
33
|
-
process.env.BUN_PTY_LIB = path
|
|
34
|
-
}
|
|
35
|
-
const { spawn } = await import("bun-pty")
|
|
36
|
-
return spawn
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
export const Info = z
|
|
40
|
-
.object({
|
|
41
|
-
id: Identifier.schema("pty"),
|
|
42
|
-
title: z.string(),
|
|
43
|
-
command: z.string(),
|
|
44
|
-
args: z.array(z.string()),
|
|
45
|
-
cwd: z.string(),
|
|
46
|
-
status: z.enum(["running", "exited"]),
|
|
47
|
-
pid: z.number(),
|
|
48
|
-
})
|
|
49
|
-
.meta({ ref: "Pty" })
|
|
50
|
-
|
|
51
|
-
export type Info = z.infer<typeof Info>
|
|
52
|
-
|
|
53
|
-
export const CreateInput = z.object({
|
|
54
|
-
command: z.string().optional(),
|
|
55
|
-
args: z.array(z.string()).optional(),
|
|
56
|
-
cwd: z.string().optional(),
|
|
57
|
-
title: z.string().optional(),
|
|
58
|
-
env: z.record(z.string(), z.string()).optional(),
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
export type CreateInput = z.infer<typeof CreateInput>
|
|
62
|
-
|
|
63
|
-
export const UpdateInput = z.object({
|
|
64
|
-
title: z.string().optional(),
|
|
65
|
-
size: z
|
|
66
|
-
.object({
|
|
67
|
-
rows: z.number(),
|
|
68
|
-
cols: z.number(),
|
|
69
|
-
})
|
|
70
|
-
.optional(),
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
export type UpdateInput = z.infer<typeof UpdateInput>
|
|
74
|
-
|
|
75
|
-
export const Event = {
|
|
76
|
-
Created: Bus.event("pty.created", z.object({ info: Info })),
|
|
77
|
-
Updated: Bus.event("pty.updated", z.object({ info: Info })),
|
|
78
|
-
Exited: Bus.event("pty.exited", z.object({ id: Identifier.schema("pty"), exitCode: z.number() })),
|
|
79
|
-
Deleted: Bus.event("pty.deleted", z.object({ id: Identifier.schema("pty") })),
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
interface ActiveSession {
|
|
83
|
-
info: Info
|
|
84
|
-
process: IPty
|
|
85
|
-
buffer: string
|
|
86
|
-
subscribers: Set<WSContext>
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const state = Instance.state(
|
|
90
|
-
() => new Map<string, ActiveSession>(),
|
|
91
|
-
async (sessions) => {
|
|
92
|
-
for (const session of sessions.values()) {
|
|
93
|
-
try {
|
|
94
|
-
session.process.kill()
|
|
95
|
-
} catch {}
|
|
96
|
-
for (const ws of session.subscribers) {
|
|
97
|
-
ws.close()
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
sessions.clear()
|
|
101
|
-
},
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
export function list() {
|
|
105
|
-
return Array.from(state().values()).map((s) => s.info)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function get(id: string) {
|
|
109
|
-
return state().get(id)?.info
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export async function create(input: CreateInput) {
|
|
113
|
-
const id = Identifier.create("pty", false)
|
|
114
|
-
const command = input.command || shell()
|
|
115
|
-
const args = input.args || []
|
|
116
|
-
const cwd = input.cwd || Instance.directory
|
|
117
|
-
const env = { ...process.env, ...input.env } as Record<string, string>
|
|
118
|
-
log.info("creating session", { id, cmd: command, args, cwd })
|
|
119
|
-
|
|
120
|
-
const spawn = await pty()
|
|
121
|
-
const ptyProcess = spawn(command, args, {
|
|
122
|
-
name: "xterm-256color",
|
|
123
|
-
cwd,
|
|
124
|
-
env,
|
|
125
|
-
})
|
|
126
|
-
const info = {
|
|
127
|
-
id,
|
|
128
|
-
title: input.title || `Terminal ${id.slice(-4)}`,
|
|
129
|
-
command,
|
|
130
|
-
args,
|
|
131
|
-
cwd,
|
|
132
|
-
status: "running",
|
|
133
|
-
pid: ptyProcess.pid,
|
|
134
|
-
} as const
|
|
135
|
-
const session: ActiveSession = {
|
|
136
|
-
info,
|
|
137
|
-
process: ptyProcess,
|
|
138
|
-
buffer: "",
|
|
139
|
-
subscribers: new Set(),
|
|
140
|
-
}
|
|
141
|
-
state().set(id, session)
|
|
142
|
-
ptyProcess.onData((data) => {
|
|
143
|
-
if (session.subscribers.size === 0) {
|
|
144
|
-
session.buffer += data
|
|
145
|
-
return
|
|
146
|
-
}
|
|
147
|
-
for (const ws of session.subscribers) {
|
|
148
|
-
if (ws.readyState === 1) {
|
|
149
|
-
ws.send(data)
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
})
|
|
153
|
-
ptyProcess.onExit(({ exitCode }) => {
|
|
154
|
-
log.info("session exited", { id, exitCode })
|
|
155
|
-
session.info.status = "exited"
|
|
156
|
-
Bus.publish(Event.Exited, { id, exitCode })
|
|
157
|
-
state().delete(id)
|
|
158
|
-
})
|
|
159
|
-
Bus.publish(Event.Created, { info })
|
|
160
|
-
return info
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export async function update(id: string, input: UpdateInput) {
|
|
164
|
-
const session = state().get(id)
|
|
165
|
-
if (!session) return
|
|
166
|
-
if (input.title) {
|
|
167
|
-
session.info.title = input.title
|
|
168
|
-
}
|
|
169
|
-
if (input.size) {
|
|
170
|
-
session.process.resize(input.size.cols, input.size.rows)
|
|
171
|
-
}
|
|
172
|
-
Bus.publish(Event.Updated, { info: session.info })
|
|
173
|
-
return session.info
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export async function remove(id: string) {
|
|
177
|
-
const session = state().get(id)
|
|
178
|
-
if (!session) return
|
|
179
|
-
log.info("removing session", { id })
|
|
180
|
-
try {
|
|
181
|
-
session.process.kill()
|
|
182
|
-
} catch {}
|
|
183
|
-
for (const ws of session.subscribers) {
|
|
184
|
-
ws.close()
|
|
185
|
-
}
|
|
186
|
-
state().delete(id)
|
|
187
|
-
Bus.publish(Event.Deleted, { id })
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export function resize(id: string, cols: number, rows: number) {
|
|
191
|
-
const session = state().get(id)
|
|
192
|
-
if (session && session.info.status === "running") {
|
|
193
|
-
session.process.resize(cols, rows)
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export function write(id: string, data: string) {
|
|
198
|
-
const session = state().get(id)
|
|
199
|
-
if (session && session.info.status === "running") {
|
|
200
|
-
session.process.write(data)
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export function connect(id: string, ws: WSContext) {
|
|
205
|
-
const session = state().get(id)
|
|
206
|
-
if (!session) {
|
|
207
|
-
ws.close()
|
|
208
|
-
return
|
|
209
|
-
}
|
|
210
|
-
log.info("client connected to session", { id })
|
|
211
|
-
session.subscribers.add(ws)
|
|
212
|
-
if (session.buffer) {
|
|
213
|
-
ws.send(session.buffer)
|
|
214
|
-
session.buffer = ""
|
|
215
|
-
}
|
|
216
|
-
return {
|
|
217
|
-
onMessage: (message: string | ArrayBuffer) => {
|
|
218
|
-
session.process.write(String(message))
|
|
219
|
-
},
|
|
220
|
-
onClose: () => {
|
|
221
|
-
log.info("client disconnected from session", { id })
|
|
222
|
-
session.subscribers.delete(ws)
|
|
223
|
-
},
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
package/src/ratelimit/index.ts
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { Bus } from "@/bus"
|
|
2
|
-
import z from "zod"
|
|
3
|
-
|
|
4
|
-
export namespace RateLimit {
|
|
5
|
-
export const WindowInfo = z.object({
|
|
6
|
-
remaining: z.number(),
|
|
7
|
-
limit: z.number(),
|
|
8
|
-
reset: z.string().optional(),
|
|
9
|
-
window: z.string(), // "minute", "hour", "day", or "unknown"
|
|
10
|
-
})
|
|
11
|
-
export type WindowInfo = z.infer<typeof WindowInfo>
|
|
12
|
-
|
|
13
|
-
export const Info = z.object({
|
|
14
|
-
providerID: z.string(),
|
|
15
|
-
// Legacy fields for backwards compatibility
|
|
16
|
-
remainingRequests: z.number().optional(),
|
|
17
|
-
limitRequests: z.number().optional(),
|
|
18
|
-
remainingTokens: z.number().optional(),
|
|
19
|
-
limitTokens: z.number().optional(),
|
|
20
|
-
resetRequests: z.string().optional(),
|
|
21
|
-
resetTokens: z.string().optional(),
|
|
22
|
-
updatedAt: z.number().optional(),
|
|
23
|
-
// All rate limits by window
|
|
24
|
-
requestLimits: z.array(WindowInfo).optional(),
|
|
25
|
-
tokenLimits: z.array(WindowInfo).optional(),
|
|
26
|
-
})
|
|
27
|
-
export type Info = z.infer<typeof Info>
|
|
28
|
-
|
|
29
|
-
export const Event = {
|
|
30
|
-
Update: Bus.event(
|
|
31
|
-
"ratelimit.update",
|
|
32
|
-
z.object({
|
|
33
|
-
providerID: z.string(),
|
|
34
|
-
info: Info,
|
|
35
|
-
}),
|
|
36
|
-
),
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Simple global state (not instance-scoped since rate limits are global)
|
|
40
|
-
const globalState = {
|
|
41
|
-
data: {} as Record<string, Info>,
|
|
42
|
-
}
|
|
43
|
-
const state = () => globalState
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Parse rate limit info from response headers.
|
|
47
|
-
* Supports common header formats from various providers.
|
|
48
|
-
* Captures all time windows (minute, hour, day) and finds the most restrictive.
|
|
49
|
-
*/
|
|
50
|
-
export function parseHeaders(
|
|
51
|
-
headers: Record<string, string | undefined> | Headers | undefined,
|
|
52
|
-
providerID: string,
|
|
53
|
-
): Info | undefined {
|
|
54
|
-
if (!headers) return undefined
|
|
55
|
-
|
|
56
|
-
// Normalize headers to a simple object
|
|
57
|
-
const h: Record<string, string | undefined> = {}
|
|
58
|
-
if (headers instanceof Headers) {
|
|
59
|
-
headers.forEach((value, key) => {
|
|
60
|
-
h[key.toLowerCase()] = value
|
|
61
|
-
})
|
|
62
|
-
} else {
|
|
63
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
64
|
-
h[key.toLowerCase()] = value
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const info: Info = { providerID, requestLimits: [], tokenLimits: [] }
|
|
69
|
-
|
|
70
|
-
// Helper to parse a window's limits
|
|
71
|
-
const parseWindow = (
|
|
72
|
-
type: "requests" | "tokens",
|
|
73
|
-
window: string,
|
|
74
|
-
remainingKey: string,
|
|
75
|
-
limitKey: string,
|
|
76
|
-
resetKey: string,
|
|
77
|
-
) => {
|
|
78
|
-
const remaining = h[remainingKey]
|
|
79
|
-
const limit = h[limitKey]
|
|
80
|
-
const reset = h[resetKey]
|
|
81
|
-
|
|
82
|
-
if (remaining !== undefined && limit !== undefined) {
|
|
83
|
-
const remainingNum = parseInt(remaining, 10)
|
|
84
|
-
const limitNum = parseInt(limit, 10)
|
|
85
|
-
// Skip if values aren't valid numbers
|
|
86
|
-
if (isNaN(remainingNum) || isNaN(limitNum)) return
|
|
87
|
-
|
|
88
|
-
const windowInfo: WindowInfo = {
|
|
89
|
-
remaining: remainingNum,
|
|
90
|
-
limit: limitNum,
|
|
91
|
-
reset,
|
|
92
|
-
window,
|
|
93
|
-
}
|
|
94
|
-
if (type === "requests") {
|
|
95
|
-
info.requestLimits!.push(windowInfo)
|
|
96
|
-
} else {
|
|
97
|
-
info.tokenLimits!.push(windowInfo)
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Parse all time windows for requests
|
|
103
|
-
parseWindow("requests", "minute", "x-ratelimit-remaining-requests-minute", "x-ratelimit-limit-requests-minute", "x-ratelimit-reset-requests-minute")
|
|
104
|
-
parseWindow("requests", "hour", "x-ratelimit-remaining-requests-hour", "x-ratelimit-limit-requests-hour", "x-ratelimit-reset-requests-hour")
|
|
105
|
-
parseWindow("requests", "day", "x-ratelimit-remaining-requests-day", "x-ratelimit-limit-requests-day", "x-ratelimit-reset-requests-day")
|
|
106
|
-
parseWindow("requests", "unknown", "x-ratelimit-remaining-requests", "x-ratelimit-limit-requests", "x-ratelimit-reset-requests")
|
|
107
|
-
parseWindow("requests", "unknown", "ratelimit-remaining-requests", "ratelimit-limit-requests", "ratelimit-reset-requests")
|
|
108
|
-
|
|
109
|
-
// Parse all time windows for tokens
|
|
110
|
-
parseWindow("tokens", "minute", "x-ratelimit-remaining-tokens-minute", "x-ratelimit-limit-tokens-minute", "x-ratelimit-reset-tokens-minute")
|
|
111
|
-
parseWindow("tokens", "hour", "x-ratelimit-remaining-tokens-hour", "x-ratelimit-limit-tokens-hour", "x-ratelimit-reset-tokens-hour")
|
|
112
|
-
parseWindow("tokens", "day", "x-ratelimit-remaining-tokens-day", "x-ratelimit-limit-tokens-day", "x-ratelimit-reset-tokens-day")
|
|
113
|
-
parseWindow("tokens", "unknown", "x-ratelimit-remaining-tokens", "x-ratelimit-limit-tokens", "x-ratelimit-reset-tokens")
|
|
114
|
-
parseWindow("tokens", "unknown", "ratelimit-remaining-tokens", "ratelimit-limit-tokens", "ratelimit-reset-tokens")
|
|
115
|
-
|
|
116
|
-
// Find the most restrictive limits (lowest percentage remaining)
|
|
117
|
-
const findMostRestrictive = (limits: WindowInfo[]): WindowInfo | undefined => {
|
|
118
|
-
if (limits.length === 0) return undefined
|
|
119
|
-
return limits.reduce((most, current) => {
|
|
120
|
-
const mostPct = most.limit > 0 ? most.remaining / most.limit : 1
|
|
121
|
-
const currentPct = current.limit > 0 ? current.remaining / current.limit : 1
|
|
122
|
-
return currentPct < mostPct ? current : most
|
|
123
|
-
})
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const mostRestrictiveRequests = findMostRestrictive(info.requestLimits!)
|
|
127
|
-
const mostRestrictiveTokens = findMostRestrictive(info.tokenLimits!)
|
|
128
|
-
|
|
129
|
-
// Set legacy fields from most restrictive limits
|
|
130
|
-
if (mostRestrictiveRequests) {
|
|
131
|
-
info.remainingRequests = mostRestrictiveRequests.remaining
|
|
132
|
-
info.limitRequests = mostRestrictiveRequests.limit
|
|
133
|
-
info.resetRequests = mostRestrictiveRequests.reset
|
|
134
|
-
}
|
|
135
|
-
if (mostRestrictiveTokens) {
|
|
136
|
-
info.remainingTokens = mostRestrictiveTokens.remaining
|
|
137
|
-
info.limitTokens = mostRestrictiveTokens.limit
|
|
138
|
-
info.resetTokens = mostRestrictiveTokens.reset
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Only return if we found any rate limit info
|
|
142
|
-
if (
|
|
143
|
-
info.remainingRequests !== undefined ||
|
|
144
|
-
info.remainingTokens !== undefined ||
|
|
145
|
-
info.limitRequests !== undefined ||
|
|
146
|
-
info.limitTokens !== undefined
|
|
147
|
-
) {
|
|
148
|
-
return info
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return undefined
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export function get(providerID: string): Info | undefined {
|
|
155
|
-
return state().data[providerID]
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Store the latest rate limit info from a fetch response.
|
|
160
|
-
* This is called from the provider's fetch wrapper.
|
|
161
|
-
*/
|
|
162
|
-
export function setLatest(providerID: string, info: Info): void {
|
|
163
|
-
const s = state()
|
|
164
|
-
|
|
165
|
-
const infoWithTimestamp: Info = {
|
|
166
|
-
...info,
|
|
167
|
-
updatedAt: Date.now(),
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
s.data[providerID] = infoWithTimestamp
|
|
171
|
-
|
|
172
|
-
// Publish update event so UI can show progress bar
|
|
173
|
-
Bus.publish(Event.Update, {
|
|
174
|
-
providerID,
|
|
175
|
-
info: infoWithTimestamp,
|
|
176
|
-
})
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Get all rate limit info for all providers
|
|
181
|
-
*/
|
|
182
|
-
export function getAll(): Record<string, Info> {
|
|
183
|
-
return { ...state().data }
|
|
184
|
-
}
|
|
185
|
-
}
|
package/src/server/error.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { resolver } from "hono-openapi"
|
|
2
|
-
import z from "zod"
|
|
3
|
-
import { Storage } from "../storage/storage"
|
|
4
|
-
|
|
5
|
-
export const ERRORS = {
|
|
6
|
-
400: {
|
|
7
|
-
description: "Bad request",
|
|
8
|
-
content: {
|
|
9
|
-
"application/json": {
|
|
10
|
-
schema: resolver(
|
|
11
|
-
z
|
|
12
|
-
.object({
|
|
13
|
-
data: z.any(),
|
|
14
|
-
errors: z.array(z.record(z.string(), z.any())),
|
|
15
|
-
success: z.literal(false),
|
|
16
|
-
})
|
|
17
|
-
.meta({
|
|
18
|
-
ref: "BadRequestError",
|
|
19
|
-
}),
|
|
20
|
-
),
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
404: {
|
|
25
|
-
description: "Not found",
|
|
26
|
-
content: {
|
|
27
|
-
"application/json": {
|
|
28
|
-
schema: resolver(Storage.NotFoundError.Schema),
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
} as const
|
|
33
|
-
|
|
34
|
-
export function errors(...codes: number[]) {
|
|
35
|
-
return Object.fromEntries(codes.map((code) => [code, ERRORS[code as keyof typeof ERRORS]]))
|
|
36
|
-
}
|
package/src/server/project.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Hono } from "hono"
|
|
2
|
-
import { describeRoute } from "hono-openapi"
|
|
3
|
-
import { resolver } from "hono-openapi"
|
|
4
|
-
import { Instance } from "../project/instance"
|
|
5
|
-
import { Project } from "../project/project"
|
|
6
|
-
|
|
7
|
-
export const ProjectRoute = new Hono()
|
|
8
|
-
.get(
|
|
9
|
-
"/",
|
|
10
|
-
describeRoute({
|
|
11
|
-
summary: "List all projects",
|
|
12
|
-
description: "Get a list of projects that have been opened with OpenCode.",
|
|
13
|
-
operationId: "project.list",
|
|
14
|
-
responses: {
|
|
15
|
-
200: {
|
|
16
|
-
description: "List of projects",
|
|
17
|
-
content: {
|
|
18
|
-
"application/json": {
|
|
19
|
-
schema: resolver(Project.Info.array()),
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
}),
|
|
25
|
-
async (c) => {
|
|
26
|
-
const projects = await Project.list()
|
|
27
|
-
return c.json(projects)
|
|
28
|
-
},
|
|
29
|
-
)
|
|
30
|
-
.get(
|
|
31
|
-
"/current",
|
|
32
|
-
describeRoute({
|
|
33
|
-
summary: "Get current project",
|
|
34
|
-
description: "Retrieve the currently active project that OpenCode is working with.",
|
|
35
|
-
operationId: "project.current",
|
|
36
|
-
responses: {
|
|
37
|
-
200: {
|
|
38
|
-
description: "Current project information",
|
|
39
|
-
content: {
|
|
40
|
-
"application/json": {
|
|
41
|
-
schema: resolver(Project.Info),
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
}),
|
|
47
|
-
async (c) => {
|
|
48
|
-
return c.json(Instance.project)
|
|
49
|
-
},
|
|
50
|
-
)
|