mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-13 11:39:41 +03:00
refactor(core): drop redundant decoding and branding in config, agent, and skill (#57953)
This commit is contained in:
committed by
GitHub
Unverified
parent
cef9718165
commit
cfcf754314
@@ -40,7 +40,7 @@ export type Editor = {
|
||||
export interface Interface extends State.Transformable<Editor> {
|
||||
readonly get: (id: ID) => Effect.Effect<Info | undefined>
|
||||
readonly resolve: (id?: ID | string) => Effect.Effect<Info | undefined>
|
||||
readonly select: (id?: ID | string) => Effect.Effect<Selection>
|
||||
readonly select: (id?: ID) => Effect.Effect<Selection>
|
||||
readonly list: () => Effect.Effect<Info[]>
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ const layer = Layer.effect(
|
||||
const data = state.get()
|
||||
const configured = data.default ? selectable(data.agents.get(data.default)) : undefined
|
||||
if (configured) return configured
|
||||
const build = selectable(data.agents.get(ID.make("build")))
|
||||
const build = selectable(data.agents.get(defaultID))
|
||||
if (build) return build
|
||||
for (const agent of data.agents.values()) {
|
||||
const fallback = selectable(agent)
|
||||
@@ -96,10 +96,7 @@ const layer = Layer.effect(
|
||||
return selectedDefault()
|
||||
}),
|
||||
select: Effect.fn("Agent.select")(function* (id) {
|
||||
if (id !== undefined) {
|
||||
const selected = ID.make(id)
|
||||
return { id: selected, info: state.get().agents.get(selected) }
|
||||
}
|
||||
if (id !== undefined) return { id, info: state.get().agents.get(id) }
|
||||
const info = selectedDefault()
|
||||
return { id: info?.id ?? defaultID, info }
|
||||
}),
|
||||
|
||||
@@ -26,7 +26,6 @@ const legacySources = [
|
||||
const sourceDirectories = ["agent", "agents", "mode", "modes"] as const
|
||||
const decodeAgent = Schema.decodeUnknownOption(ConfigAgent.Info)
|
||||
const decodeLegacyAgent = Schema.decodeUnknownOption(ConfigAgentV1.Info)
|
||||
const decodeConfig = Schema.decodeUnknownOption(Info)
|
||||
type PathAction = FileAccess.ExternalDirectoryAuthorization["action"] | typeof ReadTool.name | typeof EditTool.name
|
||||
const pathActions = ["external_directory", "read", "edit"] as const satisfies readonly PathAction[]
|
||||
const agentKeys = new Set(["variant", ...Object.keys(ConfigAgent.Info.fields)])
|
||||
@@ -202,11 +201,8 @@ function decode(file: { directory: string; filepath: string; primary: boolean },
|
||||
)
|
||||
: Option.getOrUndefined(decodeAgent({ ...data, system: body }, { errors: "all" }))
|
||||
if (!agent) return
|
||||
const info = Option.getOrUndefined(
|
||||
decodeConfig({
|
||||
agents: { [name]: file.primary ? { ...agent, mode: "primary" } : agent },
|
||||
}),
|
||||
)
|
||||
if (!info) return
|
||||
const info = Info.make({
|
||||
agents: { [name]: file.primary ? ConfigAgent.Info.make({ ...agent, mode: "primary" }) : agent },
|
||||
})
|
||||
return new Document({ type: "document", path: AbsolutePath.make(file.filepath), info })
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ export * as ConfigCommandPlugin from "./command.js"
|
||||
import { define } from "@opencode/plugin/effect/plugin"
|
||||
import { Info, type Entry } from "@opencode/schema/config"
|
||||
import { ConfigCommand } from "@opencode/schema/config/command"
|
||||
import { Model } from "@opencode/schema/model"
|
||||
import { Provider } from "@opencode/schema/provider"
|
||||
import { AppProcess } from "@opencode/util/process"
|
||||
import path from "path"
|
||||
import { Effect, Option, PubSub, Schema, Stream } from "effect"
|
||||
@@ -84,11 +82,9 @@ export const Plugin = define({
|
||||
command.model === undefined
|
||||
? commandAgent?.model
|
||||
: {
|
||||
id: Model.ID.make(command.model.model),
|
||||
providerID: Provider.ID.make(command.model.providerID),
|
||||
...(command.model.variant === undefined
|
||||
? {}
|
||||
: { variant: Model.VariantID.make(command.model.variant) }),
|
||||
id: command.model.model,
|
||||
providerID: command.model.providerID,
|
||||
...(command.model.variant === undefined ? {} : { variant: command.model.variant }),
|
||||
}
|
||||
const text = yield* evaluateTemplate(command.template, input.prompt.text, {
|
||||
location,
|
||||
|
||||
@@ -104,13 +104,14 @@ const layer = Layer.effect(
|
||||
list: () => Array.from(editor.skills.values()),
|
||||
get: (id) => editor.skills.get(ID.make(id)),
|
||||
add: (skill) => {
|
||||
editor.skills.set(skill.id, { ...skill } as Types.DeepMutable<Info>)
|
||||
editor.skills.set(skill.id, { ...skill })
|
||||
},
|
||||
update: (id, update) => {
|
||||
const current = editor.skills.get(ID.make(id))
|
||||
const key = ID.make(id)
|
||||
const current = editor.skills.get(key)
|
||||
if (!current) return
|
||||
update(current)
|
||||
current.id = ID.make(id)
|
||||
current.id = key
|
||||
},
|
||||
remove: (id) => {
|
||||
editor.skills.delete(ID.make(id))
|
||||
|
||||
@@ -13,7 +13,6 @@ import { Model } from "../../model.js"
|
||||
|
||||
const decodeOptions = { errors: "all", onExcessProperty: "ignore" } as const
|
||||
const decodeAgent = Schema.decodeUnknownSync(Schema.fromJsonString(ConfigAgent.Info), decodeOptions)
|
||||
const encodeAgent = Schema.encodeSync(ConfigAgent.Info)
|
||||
|
||||
function permissions(info?: ConfigPermissionV1.Info) {
|
||||
const rules = (info ?? []).flatMap(([key, rule]) => {
|
||||
@@ -38,21 +37,19 @@ export function migrateAgent(info: ConfigAgentV1.Info) {
|
||||
...(info.temperature === undefined ? {} : { temperature: info.temperature }),
|
||||
...(info.top_p === undefined ? {} : { top_p: info.top_p }),
|
||||
}
|
||||
return encodeAgent(
|
||||
decodeAgent(
|
||||
JSON.stringify({
|
||||
model: modelSelection(info.model, info.variant),
|
||||
request: Object.keys(body).length ? { body } : undefined,
|
||||
system: info.prompt,
|
||||
description: info.description,
|
||||
mode: info.mode,
|
||||
hidden: info.hidden,
|
||||
color: info.color === undefined ? undefined : info.color.startsWith("#") ? info.color : "#aaaaaa",
|
||||
steps: info.steps,
|
||||
disabled: info.disable,
|
||||
permissions: permissions(info.permission),
|
||||
}),
|
||||
),
|
||||
return decodeAgent(
|
||||
JSON.stringify({
|
||||
model: modelSelection(info.model, info.variant),
|
||||
request: Object.keys(body).length ? { body } : undefined,
|
||||
system: info.prompt,
|
||||
description: info.description,
|
||||
mode: info.mode,
|
||||
hidden: info.hidden,
|
||||
color: info.color === undefined ? undefined : info.color.startsWith("#") ? info.color : "#aaaaaa",
|
||||
steps: info.steps,
|
||||
disabled: info.disable,
|
||||
permissions: permissions(info.permission),
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user