Skip to content

Commit 29870bf

Browse files
kitlangtonbalcsida
authored andcommitted
refactor(effect): prune unused facades (anomalyco#20748)
1 parent 1ac4e13 commit 29870bf

File tree

19 files changed

+134
-166
lines changed

19 files changed

+134
-166
lines changed

packages/opencode/src/account/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,6 @@ export namespace Account {
417417
return Option.getOrUndefined(await runPromise((service) => service.active()))
418418
}
419419

420-
export async function config(accountID: AccountID, orgID: OrgID): Promise<Record<string, unknown> | undefined> {
421-
const cfg = await runPromise((service) => service.config(accountID, orgID))
422-
return Option.getOrUndefined(cfg)
423-
}
424-
425420
export async function token(accountID: AccountID): Promise<AccessToken | undefined> {
426421
const t = await runPromise((service) => service.token(accountID))
427422
return Option.getOrUndefined(t)

packages/opencode/src/command/index.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,24 @@ export namespace Command {
124124
source: "mcp",
125125
description: prompt.description,
126126
get template() {
127-
return new Promise<string>(async (resolve, reject) => {
128-
const template = await MCP.getPrompt(
129-
prompt.client,
130-
prompt.name,
131-
prompt.arguments
132-
? Object.fromEntries(prompt.arguments.map((argument, i) => [argument.name, `$${i + 1}`]))
133-
: {},
134-
).catch(reject)
135-
resolve(
136-
template?.messages
137-
.map((message) => (message.content.type === "text" ? message.content.text : ""))
138-
.join("\n") || "",
139-
)
140-
})
127+
return Effect.runPromise(
128+
mcp
129+
.getPrompt(
130+
prompt.client,
131+
prompt.name,
132+
prompt.arguments
133+
? Object.fromEntries(prompt.arguments.map((argument, i) => [argument.name, `$${i + 1}`]))
134+
: {},
135+
)
136+
.pipe(
137+
Effect.map(
138+
(template) =>
139+
template?.messages
140+
.map((message) => (message.content.type === "text" ? message.content.text : ""))
141+
.join("\n") || "",
142+
),
143+
),
144+
)
141145
},
142146
hints: prompt.arguments?.map((_, i) => `$${i + 1}`) ?? [],
143147
}
@@ -185,10 +189,6 @@ export namespace Command {
185189

186190
const { runPromise } = makeRuntime(Service, defaultLayer)
187191

188-
export async function get(name: string) {
189-
return runPromise((svc) => svc.get(name))
190-
}
191-
192192
export async function list() {
193193
return runPromise((svc) => svc.list())
194194
}

packages/opencode/src/installation/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,6 @@ export namespace Installation {
341341

342342
const { runPromise } = makeRuntime(Service, defaultLayer)
343343

344-
export async function info(): Promise<Info> {
345-
return runPromise((svc) => svc.info())
346-
}
347-
348344
export async function method(): Promise<Method> {
349345
return runPromise((svc) => svc.method())
350346
}

packages/opencode/src/mcp/auth.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,6 @@ export namespace McpAuth {
168168
export const updateCodeVerifier = async (mcpName: string, codeVerifier: string) =>
169169
runPromise((svc) => svc.updateCodeVerifier(mcpName, codeVerifier))
170170

171-
export const clearCodeVerifier = async (mcpName: string) => runPromise((svc) => svc.clearCodeVerifier(mcpName))
172-
173171
export const updateOAuthState = async (mcpName: string, oauthState: string) =>
174172
runPromise((svc) => svc.updateOAuthState(mcpName, oauthState))
175-
176-
export const getOAuthState = async (mcpName: string) => runPromise((svc) => svc.getOAuthState(mcpName))
177-
178-
export const clearOAuthState = async (mcpName: string) => runPromise((svc) => svc.clearOAuthState(mcpName))
179-
180-
export const isTokenExpired = async (mcpName: string) => runPromise((svc) => svc.isTokenExpired(mcpName))
181173
}

packages/opencode/src/mcp/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -889,8 +889,6 @@ export namespace MCP {
889889

890890
export const status = async () => runPromise((svc) => svc.status())
891891

892-
export const clients = async () => runPromise((svc) => svc.clients())
893-
894892
export const tools = async () => runPromise((svc) => svc.tools())
895893

896894
export const prompts = async () => runPromise((svc) => svc.prompts())
@@ -906,9 +904,6 @@ export namespace MCP {
906904
export const getPrompt = async (clientName: string, name: string, args?: Record<string, string>) =>
907905
runPromise((svc) => svc.getPrompt(clientName, name, args))
908906

909-
export const readResource = async (clientName: string, resourceUri: string) =>
910-
runPromise((svc) => svc.readResource(clientName, resourceUri))
911-
912907
export const startAuth = async (mcpName: string) => runPromise((svc) => svc.startAuth(mcpName))
913908

914909
export const authenticate = async (mcpName: string) => runPromise((svc) => svc.authenticate(mcpName))

packages/opencode/src/permission/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export namespace Permission {
140140
export const layer = Layer.effect(
141141
Service,
142142
Effect.gen(function* () {
143+
const bus = yield* Bus.Service
143144
const state = yield* InstanceState.make<State>(
144145
Effect.fn("Permission.state")(function* (ctx) {
145146
const row = Database.use((db) =>
@@ -191,7 +192,7 @@ export namespace Permission {
191192

192193
const deferred = yield* Deferred.make<void, RejectedError | CorrectedError>()
193194
pending.set(id, { info, deferred })
194-
void Bus.publish(Event.Asked, info)
195+
yield* bus.publish(Event.Asked, info)
195196
return yield* Effect.ensuring(
196197
Deferred.await(deferred),
197198
Effect.sync(() => {
@@ -206,7 +207,7 @@ export namespace Permission {
206207
if (!existing) return
207208

208209
pending.delete(input.requestID)
209-
void Bus.publish(Event.Replied, {
210+
yield* bus.publish(Event.Replied, {
210211
sessionID: existing.info.sessionID,
211212
requestID: existing.info.id,
212213
reply: input.reply,
@@ -221,7 +222,7 @@ export namespace Permission {
221222
for (const [id, item] of pending.entries()) {
222223
if (item.info.sessionID !== existing.info.sessionID) continue
223224
pending.delete(id)
224-
void Bus.publish(Event.Replied, {
225+
yield* bus.publish(Event.Replied, {
225226
sessionID: item.info.sessionID,
226227
requestID: item.info.id,
227228
reply: "reject",
@@ -249,7 +250,7 @@ export namespace Permission {
249250
)
250251
if (!ok) continue
251252
pending.delete(id)
252-
void Bus.publish(Event.Replied, {
253+
yield* bus.publish(Event.Replied, {
253254
sessionID: item.info.sessionID,
254255
requestID: item.info.id,
255256
reply: "always",
@@ -306,7 +307,9 @@ export namespace Permission {
306307
return result
307308
}
308309

309-
export const { runPromise } = makeRuntime(Service, layer)
310+
export const defaultLayer = layer.pipe(Layer.provide(Bus.layer))
311+
312+
export const { runPromise } = makeRuntime(Service, defaultLayer)
310313

311314
export async function ask(input: z.infer<typeof AskInput>) {
312315
return runPromise((s) => s.ask(input))

packages/opencode/src/plugin/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ export namespace Plugin {
7474
return result
7575
}
7676

77-
function publishPluginError(message: string) {
78-
Bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() })
77+
function publishPluginError(bus: Bus.Interface, message: string) {
78+
Effect.runFork(bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() }))
7979
}
8080

8181
async function applyPlugin(load: PluginLoader.Loaded, input: PluginInput, hooks: Hooks[]) {
@@ -161,24 +161,24 @@ export namespace Plugin {
161161
if (stage === "install") {
162162
const parsed = parsePluginSpecifier(spec)
163163
log.error("failed to install plugin", { pkg: parsed.pkg, version: parsed.version, error: message })
164-
publishPluginError(`Failed to install plugin ${parsed.pkg}@${parsed.version}: ${message}`)
164+
publishPluginError(bus, `Failed to install plugin ${parsed.pkg}@${parsed.version}: ${message}`)
165165
return
166166
}
167167

168168
if (stage === "compatibility") {
169169
log.warn("plugin incompatible", { path: spec, error: message })
170-
publishPluginError(`Plugin ${spec} skipped: ${message}`)
170+
publishPluginError(bus, `Plugin ${spec} skipped: ${message}`)
171171
return
172172
}
173173

174174
if (stage === "entry") {
175175
log.error("failed to resolve plugin server entry", { path: spec, error: message })
176-
publishPluginError(`Failed to load plugin ${spec}: ${message}`)
176+
publishPluginError(bus, `Failed to load plugin ${spec}: ${message}`)
177177
return
178178
}
179179

180180
log.error("failed to load plugin", { path: spec, target: resolved?.entry, error: message })
181-
publishPluginError(`Failed to load plugin ${spec}: ${message}`)
181+
publishPluginError(bus, `Failed to load plugin ${spec}: ${message}`)
182182
},
183183
},
184184
}),

0 commit comments

Comments
 (0)