mirror of
https://github.com/different-ai/openwork
synced 2026-05-15 03:26:24 +02:00
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { Buffer } from "node:buffer";
|
|
|
|
import { createOpencodeClient } from "@opencode-ai/sdk/v2/client";
|
|
|
|
import type { Config } from "./config.js";
|
|
|
|
type Client = ReturnType<typeof createOpencodeClient>;
|
|
|
|
export function createClient(config: Config, directory?: string): Client {
|
|
const headers: Record<string, string> = {};
|
|
if (config.opencodeUsername && config.opencodePassword) {
|
|
const token = Buffer.from(`${config.opencodeUsername}:${config.opencodePassword}`).toString("base64");
|
|
headers.Authorization = `Basic ${token}`;
|
|
}
|
|
|
|
return createOpencodeClient({
|
|
baseUrl: config.opencodeUrl,
|
|
directory: directory ?? config.opencodeDirectory,
|
|
headers: Object.keys(headers).length ? headers : undefined,
|
|
responseStyle: "data",
|
|
throwOnError: true,
|
|
});
|
|
}
|
|
|
|
export function buildPermissionRules(mode: Config["permissionMode"]) {
|
|
if (mode === "deny") {
|
|
return [
|
|
{
|
|
permission: "*",
|
|
pattern: "*",
|
|
action: "deny" as const,
|
|
},
|
|
];
|
|
}
|
|
|
|
return [
|
|
{
|
|
permission: "*",
|
|
pattern: "*",
|
|
action: "allow" as const,
|
|
},
|
|
];
|
|
}
|