Skip to content

Commit 79dd081

Browse files
committed
ci fixes
1 parent 6aa56b6 commit 79dd081

15 files changed

Lines changed: 117 additions & 176 deletions

File tree

packages/opencode/src/cli/cmd/tui/component/dialog-command.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,22 @@ import {
1111
} from "solid-js"
1212
import { useKeyboard } from "@opentui/solid"
1313
import { useKeybind } from "@tui/context/keybind"
14+
import type { KeybindsConfig } from "@opencode-ai/sdk"
1415

1516
type Context = ReturnType<typeof init>
1617
const ctx = createContext<Context>()
1718

19+
export type CommandOption = DialogSelectOption & {
20+
keybind?: keyof KeybindsConfig
21+
}
22+
1823
function init() {
19-
const [registrations, setRegistrations] = createSignal<Accessor<DialogSelectOption[]>[]>([])
24+
const [registrations, setRegistrations] = createSignal<Accessor<CommandOption[]>[]>([])
2025
const dialog = useDialog()
26+
const keybind = useKeybind()
2127
const options = createMemo(() => {
2228
return registrations().flatMap((x) => x())
2329
})
24-
const keybind = useKeybind()
2530

2631
useKeyboard((evt) => {
2732
for (const option of options()) {
@@ -42,7 +47,7 @@ function init() {
4247
}
4348
}
4449
},
45-
register(cb: () => DialogSelectOption[]) {
50+
register(cb: () => CommandOption[]) {
4651
const results = createMemo(cb)
4752
setRegistrations((arr) => [results, ...arr])
4853
onCleanup(() => {
@@ -78,6 +83,12 @@ export function CommandProvider(props: ParentProps) {
7883
return <ctx.Provider value={value}>{props.children}</ctx.Provider>
7984
}
8085

81-
function DialogCommand(props: { options: DialogSelectOption[] }) {
82-
return <DialogSelect title="Commands" options={props.options} />
86+
function DialogCommand(props: { options: CommandOption[] }) {
87+
const keybind = useKeybind()
88+
return (
89+
<DialogSelect
90+
title="Commands"
91+
options={props.options.map((x) => ({ ...x, footer: x.keybind ? keybind.print(x.keybind) : undefined }))}
92+
/>
93+
)
8394
}

packages/opencode/src/cli/cmd/tui/component/dialog-model.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useSync } from "@tui/context/sync"
44
import { map, pipe, flatMap, entries, filter, isDeepEqual } from "remeda"
55
import { DialogSelect } from "@tui/ui/dialog-select"
66
import { useDialog } from "@tui/ui/dialog"
7+
import { Keybind } from "@/util/keybind"
78

89
export function DialogModel() {
910
const local = useLocal()

packages/opencode/src/cli/cmd/tui/component/dialog-session-list.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useRoute } from "@tui/context/route"
44
import { useSync } from "@tui/context/sync"
55
import { createMemo, onMount } from "solid-js"
66
import { Locale } from "@/util/locale"
7+
import { Keybind } from "@/util/keybind"
78

89
export function DialogSessionList() {
910
const dialog = useDialog()
@@ -45,6 +46,13 @@ export function DialogSessionList() {
4546
})
4647
dialog.clear()
4748
}}
49+
keybind={[
50+
{
51+
keybind: Keybind.parse("del")[0],
52+
title: "delete",
53+
onTrigger: (option) => {},
54+
},
55+
]}
4856
/>
4957
)
5058
}

packages/opencode/src/cli/cmd/tui/context/keybind.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,19 @@ export const { use: useKeybind, provider: KeybindProvider } = createSimpleContex
7676
get leader() {
7777
return store.leader
7878
},
79-
match(key: keyof KeybindsConfig, evt: ParsedKey) {
80-
const keybind = keybinds()[key]
81-
if (!keybind) return false
82-
const parsed: Keybind.Info = {
79+
parse(evt: ParsedKey) {
80+
return {
8381
ctrl: evt.ctrl,
8482
name: evt.name,
8583
shift: false,
8684
leader: store.leader,
8785
option: evt.option,
8886
}
87+
},
88+
match(key: keyof KeybindsConfig, evt: ParsedKey) {
89+
const keybind = keybinds()[key]
90+
if (!keybind) return false
91+
const parsed: Keybind.Info = result.parse(evt)
8992
for (const key of keybind) {
9093
if (Keybind.match(key, parsed)) {
9194
return true

packages/opencode/src/cli/cmd/tui/routes/session/dialog-message.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function DialogMessage(props: { messageID: string; sessionID: string }) {
1010

1111
return (
1212
<DialogSelect
13-
title="Message"
13+
title="Message Actions"
1414
options={[
1515
{
1616
title: "Revert",

packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,26 @@ import { useKeyboard } from "@opentui/solid"
77
import * as fuzzysort from "fuzzysort"
88
import { isDeepEqual } from "remeda"
99
import { useDialog, type DialogContext } from "@tui/ui/dialog"
10-
import type { KeybindsConfig } from "@opencode-ai/sdk"
1110
import { useKeybind } from "@tui/context/keybind"
11+
import { Keybind } from "@/util/keybind"
1212

1313
export interface DialogSelectProps<T> {
1414
title: string
1515
options: DialogSelectOption<T>[]
1616
onFilter?: (query: string) => void
1717
onSelect?: (option: DialogSelectOption<T>) => void
18+
keybind?: {
19+
keybind: Keybind.Info
20+
title: string
21+
onTrigger: (option: DialogSelectOption<T>) => void
22+
}[]
1823
limit?: number
1924
current?: T
2025
}
2126

2227
export interface DialogSelectOption<T = any> {
2328
title: string
2429
value: T
25-
keybind?: keyof KeybindsConfig
2630
description?: string
2731
footer?: string
2832
category?: string
@@ -99,6 +103,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
99103
}
100104
}
101105

106+
const keybind = useKeybind()
102107
useKeyboard((evt) => {
103108
if (evt.name === "up") move(-1)
104109
if (evt.name === "down") move(1)
@@ -109,10 +114,15 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
109114
if (option.onSelect) option.onSelect(dialog)
110115
props.onSelect?.(option)
111116
}
117+
118+
for (const item of props.keybind ?? []) {
119+
if (Keybind.match(item.keybind, keybind.parse(evt))) {
120+
item.onTrigger(selected())
121+
}
122+
}
112123
})
113124

114125
let scroll: ScrollBoxRenderable
115-
const keybind = useKeybind()
116126

117127
return (
118128
<box gap={1}>
@@ -179,7 +189,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
179189
>
180190
<Option
181191
title={option.title}
182-
footer={option.footer ?? (option.keybind ? keybind.print(option.keybind as any) : undefined)}
192+
footer={option.footer}
183193
description={option.description !== category ? option.description : undefined}
184194
active={active()}
185195
current={isDeepEqual(option.value, props.current)}
@@ -192,17 +202,15 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
192202
)}
193203
</For>
194204
</scrollbox>
195-
<box paddingRight={2} paddingLeft={3} flexDirection="row">
196-
{/*
197-
<text fg={Theme.text} attributes={TextAttributes.BOLD}>
198-
n
199-
</text>
200-
<text fg={Theme.textMuted}> new</text>
201-
<text fg={Theme.text} attributes={TextAttributes.BOLD}>
202-
{" "}r
203-
</text>
204-
<text fg={Theme.textMuted}> rename</text>
205-
*/}
205+
<box paddingRight={2} paddingLeft={3} flexDirection="row" paddingBottom={1}>
206+
<For each={props.keybind ?? []}>
207+
{(item) => (
208+
<text>
209+
<span style={{ fg: Theme.text, attributes: TextAttributes.BOLD }}>{Keybind.toString(item.keybind)}</span>
210+
<span style={{ fg: Theme.textMuted }}> {item.title}</span>
211+
</text>
212+
)}
213+
</For>
206214
</box>
207215
</box>
208216
)

packages/plugin/script/publish.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import { $ } from "bun"
77

88
await $`bun tsc`
99

10-
const pkg = await import("../package.json")
10+
const pkg = await import("../package.json").then((m) => m.default)
11+
// @ts-expect-error
12+
delete pkg.devDependencies
1113
for (const [key, value] of Object.entries(pkg.exports)) {
1214
const file = value.replace("./src/", "./").replace(".ts", "")
13-
// @ts-expect-error
1415
pkg.exports[key] = {
1516
import: file + ".js",
1617
types: file + ".d.ts",

packages/sdk/js/script/publish.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import { $ } from "bun"
77

88
await import("./build")
99

10-
const pkg = await import("../package.json")
10+
const pkg = await import("../package.json").then((m) => m.default)
11+
// @ts-expect-error
12+
delete pkg["devDependencies"]
1113
for (const [key, value] of Object.entries(pkg.exports)) {
1214
const file = value.replace("./src/", "./").replace(".ts", "")
13-
// @ts-expect-error
1415
pkg.exports[key] = {
1516
import: file + ".js",
1617
types: file + ".d.ts",

packages/sdk/js/src/gen/client/client.gen.ts

Lines changed: 30 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

33
import { createSseClient } from "../core/serverSentEvents.gen.js"
4-
import type { HttpMethod } from "../core/types.gen.js"
5-
import { getValidRequestBody } from "../core/utils.gen.js"
64
import type { Client, Config, RequestOptions, ResolvedRequestOptions } from "./types.gen.js"
75
import {
86
buildUrl,
@@ -51,12 +49,12 @@ export const createClient = (config: Config = {}): Client => {
5149
await opts.requestValidator(opts)
5250
}
5351

54-
if (opts.body !== undefined && opts.bodySerializer) {
52+
if (opts.body && opts.bodySerializer) {
5553
opts.serializedBody = opts.bodySerializer(opts.body)
5654
}
5755

5856
// remove Content-Type header if body is empty to avoid sending invalid requests
59-
if (opts.body === undefined || opts.serializedBody === "") {
57+
if (opts.serializedBody === undefined || opts.serializedBody === "") {
6058
opts.headers.delete("Content-Type")
6159
}
6260

@@ -71,7 +69,7 @@ export const createClient = (config: Config = {}): Client => {
7169
const requestInit: ReqInit = {
7270
redirect: "follow",
7371
...opts,
74-
body: getValidRequestBody(opts),
72+
body: opts.serializedBody,
7573
}
7674

7775
let request = new Request(url, requestInit)
@@ -99,36 +97,18 @@ export const createClient = (config: Config = {}): Client => {
9997
}
10098

10199
if (response.ok) {
102-
const parseAs =
103-
(opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json"
104-
105100
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
106-
let emptyData: any
107-
switch (parseAs) {
108-
case "arrayBuffer":
109-
case "blob":
110-
case "text":
111-
emptyData = await response[parseAs]()
112-
break
113-
case "formData":
114-
emptyData = new FormData()
115-
break
116-
case "stream":
117-
emptyData = response.body
118-
break
119-
case "json":
120-
default:
121-
emptyData = {}
122-
break
123-
}
124101
return opts.responseStyle === "data"
125-
? emptyData
102+
? {}
126103
: {
127-
data: emptyData,
104+
data: {},
128105
...result,
129106
}
130107
}
131108

109+
const parseAs =
110+
(opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json"
111+
132112
let data: any
133113
switch (parseAs) {
134114
case "arrayBuffer":
@@ -198,53 +178,35 @@ export const createClient = (config: Config = {}): Client => {
198178
}
199179
}
200180

201-
const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) => request({ ...options, method })
202-
203-
const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
204-
const { opts, url } = await beforeRequest(options)
205-
return createSseClient({
206-
...opts,
207-
body: opts.body as BodyInit | null | undefined,
208-
headers: opts.headers as unknown as Record<string, string>,
209-
method,
210-
onRequest: async (url, init) => {
211-
let request = new Request(url, init)
212-
for (const fn of interceptors.request._fns) {
213-
if (fn) {
214-
request = await fn(request, opts)
215-
}
216-
}
217-
return request
218-
},
219-
url,
220-
})
181+
const makeMethod = (method: Required<Config>["method"]) => {
182+
const fn = (options: RequestOptions) => request({ ...options, method })
183+
fn.sse = async (options: RequestOptions) => {
184+
const { opts, url } = await beforeRequest(options)
185+
return createSseClient({
186+
...opts,
187+
body: opts.body as BodyInit | null | undefined,
188+
headers: opts.headers as unknown as Record<string, string>,
189+
method,
190+
url,
191+
})
192+
}
193+
return fn
221194
}
222195

223196
return {
224197
buildUrl,
225-
connect: makeMethodFn("CONNECT"),
226-
delete: makeMethodFn("DELETE"),
227-
get: makeMethodFn("GET"),
198+
connect: makeMethod("CONNECT"),
199+
delete: makeMethod("DELETE"),
200+
get: makeMethod("GET"),
228201
getConfig,
229-
head: makeMethodFn("HEAD"),
202+
head: makeMethod("HEAD"),
230203
interceptors,
231-
options: makeMethodFn("OPTIONS"),
232-
patch: makeMethodFn("PATCH"),
233-
post: makeMethodFn("POST"),
234-
put: makeMethodFn("PUT"),
204+
options: makeMethod("OPTIONS"),
205+
patch: makeMethod("PATCH"),
206+
post: makeMethod("POST"),
207+
put: makeMethod("PUT"),
235208
request,
236209
setConfig,
237-
sse: {
238-
connect: makeSseFn("CONNECT"),
239-
delete: makeSseFn("DELETE"),
240-
get: makeSseFn("GET"),
241-
head: makeSseFn("HEAD"),
242-
options: makeSseFn("OPTIONS"),
243-
patch: makeSseFn("PATCH"),
244-
post: makeSseFn("POST"),
245-
put: makeSseFn("PUT"),
246-
trace: makeSseFn("TRACE"),
247-
},
248-
trace: makeMethodFn("TRACE"),
210+
trace: makeMethod("TRACE"),
249211
} as Client
250212
}

0 commit comments

Comments
 (0)