mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-22 11:25:15 +00:00
Update plugin and SDK auth types
This commit is contained in:
parent
8d71e43508
commit
1527a2260f
5 changed files with 28 additions and 9 deletions
|
|
@ -433,7 +433,7 @@ export async function CodexAuthPlugin(input: PluginInput): Promise<Hooks> {
|
|||
const tokens = await refreshAccessToken(currentAuth.refresh)
|
||||
const newAccountId = extractAccountId(tokens) || authWithAccount.accountId
|
||||
await input.client.auth.set({
|
||||
path: { id: "openai" },
|
||||
path: { providerID: "openai" },
|
||||
body: {
|
||||
type: "oauth",
|
||||
refresh: tokens.refresh_token,
|
||||
|
|
|
|||
|
|
@ -332,7 +332,7 @@ export async function DigitalOceanAuthPlugin(input: PluginInput): Promise<Hooks>
|
|||
}
|
||||
await input.client.auth
|
||||
.set({
|
||||
path: { id: "digitalocean" },
|
||||
path: { providerID: "digitalocean" },
|
||||
body: { type: "api", key: ctx.auth.key, metadata: updated },
|
||||
})
|
||||
.catch((err) => log.warn("failed to persist refreshed routers", { error: err }))
|
||||
|
|
|
|||
|
|
@ -124,7 +124,6 @@ export const layer = Layer.effect(
|
|||
}
|
||||
|
||||
const { Server } = yield* Effect.promise(() => import("../server/server"))
|
||||
|
||||
const client = createOpencodeClient({
|
||||
baseUrl: "http://localhost:4096",
|
||||
directory: ctx.directory,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import type {
|
|||
Project,
|
||||
Model,
|
||||
Provider,
|
||||
Permission,
|
||||
PermissionRequest,
|
||||
UserMessage,
|
||||
Message,
|
||||
Part,
|
||||
|
|
@ -67,8 +67,16 @@ export type PluginInput = {
|
|||
|
||||
export type PluginOptions = Record<string, unknown>
|
||||
|
||||
type TuiConfig = {
|
||||
scroll_speed?: number
|
||||
scroll_acceleration?: { enabled?: boolean }
|
||||
diff_style?: "auto" | "stacked"
|
||||
}
|
||||
|
||||
export type Config = Omit<SDKConfig, "plugin"> & {
|
||||
plugin?: Array<string | [string, PluginOptions]>
|
||||
theme?: string
|
||||
tui?: TuiConfig
|
||||
}
|
||||
|
||||
export type Plugin = (input: PluginInput, options?: PluginOptions) => Promise<Hooks>
|
||||
|
|
@ -257,7 +265,7 @@ export interface Hooks {
|
|||
input: { sessionID: string; agent: string; model: Model; provider: ProviderContext; message: UserMessage },
|
||||
output: { headers: Record<string, string> },
|
||||
) => Promise<void>
|
||||
"permission.ask"?: (input: Permission, output: { status: "ask" | "deny" | "allow" }) => Promise<void>
|
||||
"permission.ask"?: (input: PermissionRequest, output: { status: "ask" | "deny" | "allow" }) => Promise<void>
|
||||
"command.execute.before"?: (
|
||||
input: { command: string; sessionID: string; arguments: string },
|
||||
output: { parts: Part[] },
|
||||
|
|
|
|||
|
|
@ -4,7 +4,10 @@ import { createClient } from "./gen/client/client.gen.js"
|
|||
import { type Config } from "./gen/client/types.gen.js"
|
||||
import { OpencodeClient } from "./gen/sdk.gen.js"
|
||||
import { wrapClientError } from "./error-interceptor.js"
|
||||
export { type Config as OpencodeClientConfig, OpencodeClient }
|
||||
export { OpencodeClient }
|
||||
|
||||
type Fetch = (request: Request) => ReturnType<typeof fetch>
|
||||
export type OpencodeClientConfig = Omit<Config, "fetch"> & { fetch?: Fetch; directory?: string }
|
||||
|
||||
function pick(value: string | null, fallback?: string) {
|
||||
if (!value) return
|
||||
|
|
@ -30,9 +33,18 @@ function rewrite(request: Request, directory?: string) {
|
|||
return next
|
||||
}
|
||||
|
||||
export function createOpencodeClient(config?: Config & { directory?: string }) {
|
||||
function toFetch(input: Fetch | undefined): typeof fetch | undefined {
|
||||
if (!input) return
|
||||
return Object.assign(
|
||||
async (value: Parameters<typeof fetch>[0], init?: Parameters<typeof fetch>[1]) =>
|
||||
input(value instanceof Request && init === undefined ? value : new Request(value, init)),
|
||||
fetch,
|
||||
)
|
||||
}
|
||||
|
||||
export function createOpencodeClient(config?: OpencodeClientConfig) {
|
||||
if (!config?.fetch) {
|
||||
const customFetch: any = (req: any) => {
|
||||
const customFetch: Fetch = (req) => {
|
||||
// @ts-ignore
|
||||
req.timeout = false
|
||||
return fetch(req)
|
||||
|
|
@ -50,7 +62,7 @@ export function createOpencodeClient(config?: Config & { directory?: string }) {
|
|||
}
|
||||
}
|
||||
|
||||
const client = createClient(config)
|
||||
const client = createClient({ ...config, fetch: toFetch(config?.fetch) })
|
||||
client.interceptors.request.use((request) => rewrite(request, config?.directory))
|
||||
client.interceptors.error.use(wrapClientError)
|
||||
return new OpencodeClient({ client })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue