diff --git a/packages/core/src/agent.ts b/packages/core/src/agent.ts index 14732fdd752..cd5429319e7 100644 --- a/packages/core/src/agent.ts +++ b/packages/core/src/agent.ts @@ -30,8 +30,8 @@ type Data = { } export type Editor = { - list: () => readonly Info[] - get: (id: ID) => Info | undefined + list: () => readonly Types.DeepMutable[] + get: (id: ID) => Types.DeepMutable | undefined default: (id: ID | undefined) => void update: (id: ID, fn: (agent: Types.DeepMutable) => 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 diff --git a/packages/core/src/integration.ts b/packages/core/src/integration.ts index 8e75588ce64..dc929331db3 100644 --- a/packages/core/src/integration.ts +++ b/packages/core/src/integration.ts @@ -147,8 +147,8 @@ export type Ref = Integration.Ref type Entry = { ref: Types.DeepMutable - methods: Types.DeepMutable[] - implementations: Map> + methods: Method[] + implementations: Map } type Data = { @@ -156,8 +156,8 @@ type Data = { } export type Editor = { - list: () => readonly Ref[] - get: (id: ID) => Ref | undefined + list: () => readonly Types.DeepMutable[] + get: (id: ID) => Types.DeepMutable | undefined update: (id: ID, update: (integration: Types.DeepMutable) => void) => void remove: (id: ID) => void method: { @@ -318,8 +318,8 @@ const layer = Layer.effect( name: "integration", initial: () => ({ integrations: new Map() }), 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>(), + implementations: new Map(), } 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) - else current.methods[index] = implementation.method as Types.DeepMutable - if (implementation.method.type === "oauth") { - current.implementations.set( - implementation.method.id, - implementation as Types.DeepMutable, - ) + 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) => { diff --git a/packages/core/src/plugin/host.ts b/packages/core/src/plugin/host.ts index 56f6afde336..1107dd665bb 100644 --- a/packages/core/src/plugin/host.ts +++ b/packages/core/src/plugin/host.ts @@ -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: {