mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
refactor(core): remove redundant DeepMutable wrappers and casts in integration, agent, and plugin host (#57825)
This commit is contained in:
committed by
GitHub
Unverified
parent
0c8e7a9615
commit
bddf5346c8
@@ -30,8 +30,8 @@ type Data = {
|
||||
}
|
||||
|
||||
export type Editor = {
|
||||
list: () => readonly Info[]
|
||||
get: (id: ID) => Info | undefined
|
||||
list: () => readonly Types.DeepMutable<Info>[]
|
||||
get: (id: ID) => Types.DeepMutable<Info> | undefined
|
||||
default: (id: ID | undefined) => void
|
||||
update: (id: ID, fn: (agent: Types.DeepMutable<Info>) => void) => void
|
||||
remove: (id: ID) => void
|
||||
@@ -54,7 +54,7 @@ const layer = Layer.effect(
|
||||
name: "agent",
|
||||
initial: () => ({ agents: new Map() }),
|
||||
editor: (editor) => ({
|
||||
list: () => Array.fromIterable(editor.agents.values()) as Info[],
|
||||
list: () => Array.fromIterable(editor.agents.values()),
|
||||
get: (id) => editor.agents.get(id),
|
||||
default: (id) => {
|
||||
editor.default = id
|
||||
|
||||
@@ -147,8 +147,8 @@ export type Ref = Integration.Ref
|
||||
|
||||
type Entry = {
|
||||
ref: Types.DeepMutable<Ref>
|
||||
methods: Types.DeepMutable<Method>[]
|
||||
implementations: Map<MethodID, Types.DeepMutable<OAuthImplementation>>
|
||||
methods: Method[]
|
||||
implementations: Map<MethodID, OAuthImplementation>
|
||||
}
|
||||
|
||||
type Data = {
|
||||
@@ -156,8 +156,8 @@ type Data = {
|
||||
}
|
||||
|
||||
export type Editor = {
|
||||
list: () => readonly Ref[]
|
||||
get: (id: ID) => Ref | undefined
|
||||
list: () => readonly Types.DeepMutable<Ref>[]
|
||||
get: (id: ID) => Types.DeepMutable<Ref> | undefined
|
||||
update: (id: ID, update: (integration: Types.DeepMutable<Ref>) => void) => void
|
||||
remove: (id: ID) => void
|
||||
method: {
|
||||
@@ -318,8 +318,8 @@ const layer = Layer.effect(
|
||||
name: "integration",
|
||||
initial: () => ({ integrations: new Map<ID, Entry>() }),
|
||||
editor: (editor) => ({
|
||||
list: () => Array.from(editor.integrations.values(), (entry) => entry.ref) as Ref[],
|
||||
get: (id) => editor.integrations.get(id)?.ref as Ref | undefined,
|
||||
list: () => Array.from(editor.integrations.values(), (entry) => entry.ref),
|
||||
get: (id) => editor.integrations.get(id)?.ref,
|
||||
update: (id, update) => {
|
||||
const current = editor.integrations.get(id) ?? {
|
||||
ref: { id, name: id },
|
||||
@@ -332,7 +332,7 @@ const layer = Layer.effect(
|
||||
},
|
||||
remove: (id) => editor.integrations.delete(id),
|
||||
method: {
|
||||
list: (integrationID) => (editor.integrations.get(integrationID)?.methods as Method[] | undefined) ?? [],
|
||||
list: (integrationID) => editor.integrations.get(integrationID)?.methods ?? [],
|
||||
update: (implementation) => {
|
||||
const current = editor.integrations.get(implementation.integrationID) ?? {
|
||||
ref: {
|
||||
@@ -340,7 +340,7 @@ const layer = Layer.effect(
|
||||
name: implementation.integrationID,
|
||||
},
|
||||
methods: [],
|
||||
implementations: new Map<MethodID, Types.DeepMutable<OAuthImplementation>>(),
|
||||
implementations: new Map<MethodID, OAuthImplementation>(),
|
||||
}
|
||||
if (!editor.integrations.has(implementation.integrationID)) {
|
||||
editor.integrations.set(implementation.integrationID, current)
|
||||
@@ -355,13 +355,10 @@ const layer = Layer.effect(
|
||||
return method.id === implementation.method.id
|
||||
return true
|
||||
})
|
||||
if (index === -1) current.methods.push(implementation.method as Types.DeepMutable<Method>)
|
||||
else current.methods[index] = implementation.method as Types.DeepMutable<Method>
|
||||
if (implementation.method.type === "oauth") {
|
||||
current.implementations.set(
|
||||
implementation.method.id,
|
||||
implementation as Types.DeepMutable<OAuthImplementation>,
|
||||
)
|
||||
if (index === -1) current.methods.push(implementation.method)
|
||||
else current.methods[index] = implementation.method
|
||||
if ("authorize" in implementation) {
|
||||
current.implementations.set(implementation.method.id, implementation)
|
||||
}
|
||||
},
|
||||
remove: (integrationID, method) => {
|
||||
|
||||
@@ -146,8 +146,8 @@ export const make = Effect.fn("PluginHost.make")(function* (
|
||||
transform: (callback) =>
|
||||
agents.transform((editor) => {
|
||||
callback({
|
||||
list: () => mutable(editor.list()),
|
||||
get: (id) => mutable(editor.get(Agent.ID.make(id))),
|
||||
list: editor.list,
|
||||
get: (id) => editor.get(Agent.ID.make(id)),
|
||||
default: (id) => editor.default(id === undefined ? undefined : Agent.ID.make(id)),
|
||||
update: (id, update) => editor.update(Agent.ID.make(id), update),
|
||||
remove: (id) => editor.remove(Agent.ID.make(id)),
|
||||
@@ -368,8 +368,8 @@ export const make = Effect.fn("PluginHost.make")(function* (
|
||||
transform: (callback) =>
|
||||
integration.transform((editor) => {
|
||||
callback({
|
||||
list: () => mutable(editor.list()),
|
||||
get: (id) => mutable(editor.get(Integration.ID.make(id))),
|
||||
list: editor.list,
|
||||
get: (id) => editor.get(Integration.ID.make(id)),
|
||||
update: (id, update) => editor.update(Integration.ID.make(id), update),
|
||||
remove: (id) => editor.remove(Integration.ID.make(id)),
|
||||
method: {
|
||||
|
||||
Reference in New Issue
Block a user