Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions packages/opencode/src/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,6 @@ export namespace Account {
return Option.getOrUndefined(await runPromise((service) => service.active()))
}

export async function config(accountID: AccountID, orgID: OrgID): Promise<Record<string, unknown> | undefined> {
const cfg = await runPromise((service) => service.config(accountID, orgID))
return Option.getOrUndefined(cfg)
}

export async function token(accountID: AccountID): Promise<AccessToken | undefined> {
const t = await runPromise((service) => service.token(accountID))
return Option.getOrUndefined(t)
Expand Down
36 changes: 18 additions & 18 deletions packages/opencode/src/command/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,24 @@ export namespace Command {
source: "mcp",
description: prompt.description,
get template() {
return new Promise<string>(async (resolve, reject) => {
const template = await MCP.getPrompt(
prompt.client,
prompt.name,
prompt.arguments
? Object.fromEntries(prompt.arguments.map((argument, i) => [argument.name, `$${i + 1}`]))
: {},
).catch(reject)
resolve(
template?.messages
.map((message) => (message.content.type === "text" ? message.content.text : ""))
.join("\n") || "",
)
})
return Effect.runPromise(
mcp
.getPrompt(
prompt.client,
prompt.name,
prompt.arguments
? Object.fromEntries(prompt.arguments.map((argument, i) => [argument.name, `$${i + 1}`]))
: {},
)
.pipe(
Effect.map(
(template) =>
template?.messages
.map((message) => (message.content.type === "text" ? message.content.text : ""))
.join("\n") || "",
),
),
)
},
hints: prompt.arguments?.map((_, i) => `$${i + 1}`) ?? [],
}
Expand Down Expand Up @@ -185,10 +189,6 @@ export namespace Command {

const { runPromise } = makeRuntime(Service, defaultLayer)

export async function get(name: string) {
return runPromise((svc) => svc.get(name))
}

export async function list() {
return runPromise((svc) => svc.list())
}
Expand Down
4 changes: 0 additions & 4 deletions packages/opencode/src/installation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,6 @@ export namespace Installation {

const { runPromise } = makeRuntime(Service, defaultLayer)

export async function info(): Promise<Info> {
return runPromise((svc) => svc.info())
}

export async function method(): Promise<Method> {
return runPromise((svc) => svc.method())
}
Expand Down
8 changes: 0 additions & 8 deletions packages/opencode/src/mcp/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,6 @@ export namespace McpAuth {
export const updateCodeVerifier = async (mcpName: string, codeVerifier: string) =>
runPromise((svc) => svc.updateCodeVerifier(mcpName, codeVerifier))

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

export const updateOAuthState = async (mcpName: string, oauthState: string) =>
runPromise((svc) => svc.updateOAuthState(mcpName, oauthState))

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

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

export const isTokenExpired = async (mcpName: string) => runPromise((svc) => svc.isTokenExpired(mcpName))
}
5 changes: 0 additions & 5 deletions packages/opencode/src/mcp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -889,8 +889,6 @@ export namespace MCP {

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

export const clients = async () => runPromise((svc) => svc.clients())

export const tools = async () => runPromise((svc) => svc.tools())

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

export const readResource = async (clientName: string, resourceUri: string) =>
runPromise((svc) => svc.readResource(clientName, resourceUri))

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

export const authenticate = async (mcpName: string) => runPromise((svc) => svc.authenticate(mcpName))
Expand Down
13 changes: 8 additions & 5 deletions packages/opencode/src/permission/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export namespace Permission {
export const layer = Layer.effect(
Service,
Effect.gen(function* () {
const bus = yield* Bus.Service
const state = yield* InstanceState.make<State>(
Effect.fn("Permission.state")(function* (ctx) {
const row = Database.use((db) =>
Expand Down Expand Up @@ -191,7 +192,7 @@ export namespace Permission {

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

pending.delete(input.requestID)
void Bus.publish(Event.Replied, {
yield* bus.publish(Event.Replied, {
sessionID: existing.info.sessionID,
requestID: existing.info.id,
reply: input.reply,
Expand All @@ -221,7 +222,7 @@ export namespace Permission {
for (const [id, item] of pending.entries()) {
if (item.info.sessionID !== existing.info.sessionID) continue
pending.delete(id)
void Bus.publish(Event.Replied, {
yield* bus.publish(Event.Replied, {
sessionID: item.info.sessionID,
requestID: item.info.id,
reply: "reject",
Expand Down Expand Up @@ -249,7 +250,7 @@ export namespace Permission {
)
if (!ok) continue
pending.delete(id)
void Bus.publish(Event.Replied, {
yield* bus.publish(Event.Replied, {
sessionID: item.info.sessionID,
requestID: item.info.id,
reply: "always",
Expand Down Expand Up @@ -306,7 +307,9 @@ export namespace Permission {
return result
}

export const { runPromise } = makeRuntime(Service, layer)
export const defaultLayer = layer.pipe(Layer.provide(Bus.layer))

export const { runPromise } = makeRuntime(Service, defaultLayer)

export async function ask(input: z.infer<typeof AskInput>) {
return runPromise((s) => s.ask(input))
Expand Down
12 changes: 6 additions & 6 deletions packages/opencode/src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export namespace Plugin {
return result
}

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

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

if (stage === "compatibility") {
log.warn("plugin incompatible", { path: spec, error: message })
publishPluginError(`Plugin ${spec} skipped: ${message}`)
publishPluginError(bus, `Plugin ${spec} skipped: ${message}`)
return
}

if (stage === "entry") {
log.error("failed to resolve plugin server entry", { path: spec, error: message })
publishPluginError(`Failed to load plugin ${spec}: ${message}`)
publishPluginError(bus, `Failed to load plugin ${spec}: ${message}`)
return
}

log.error("failed to load plugin", { path: spec, target: resolved?.entry, error: message })
publishPluginError(`Failed to load plugin ${spec}: ${message}`)
publishPluginError(bus, `Failed to load plugin ${spec}: ${message}`)
},
},
}),
Expand Down
Loading
Loading