// Shared with the client settings form; keep schema code browser-safe.
import {
CustomModelSetting,
makeBinaryPathSetting,
makeProviderSettingsSchema,
secretSetting,
SettingsSecretValue,
TrimmedString,
} from "@t3tools/contracts";
import * as Effect from "effect/Effect";
import * as Schema from "effect/Schema";
export const OpenCodeSettings = makeProviderSettingsSchema(
{
enabled: Schema.Boolean.pipe(
Schema.withDecodingDefault(Effect.succeed(false)),
Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
),
binaryPath: makeBinaryPathSetting("opencode").pipe(
Schema.annotateKey({
title: "Binary path",
description: "Path to the OpenCode binary.",
providerSettingsForm: {
placeholder: "opencode",
clearWhenEmpty: "omit",
},
}),
),
serverUrl: TrimmedString.pipe(
Schema.withDecodingDefault(Effect.succeed("")),
Schema.annotateKey({
title: "Server URL",
description: "Leave blank to let T3 Code spawn the server when needed.",
providerSettingsForm: {
placeholder: "http://127.0.0.1:4096",
clearWhenEmpty: "omit",
},
}),
),
serverPassword: SettingsSecretValue.pipe(
secretSetting,
Schema.withDecodingDefault(Effect.succeed("")),
Schema.annotateKey({
title: "Server password",
description: "Stored separately on the host.",
providerSettingsForm: {
control: "password",
placeholder: "Optional",
clearWhenEmpty: "omit",
},
}),
),
customModels: Schema.Array(CustomModelSetting).pipe(
Schema.withDecodingDefault(Effect.succeed([])),
Schema.annotateKey({ providerSettingsForm: { hidden: true } }),
),
},
{
order: ["binaryPath", "serverUrl", "serverPassword"],
},
);
export type OpenCodeSettings = typeof OpenCodeSettings.Type;