mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-24 04:01:10 -04:00
refactor(core): defer mcp prompt commands
This commit is contained in:
@@ -20,7 +20,6 @@ import { FSUtil } from "../fs-util"
|
||||
import { Global } from "../global"
|
||||
import { Integration } from "../integration"
|
||||
import { Location } from "../location"
|
||||
import { MCP } from "../mcp"
|
||||
import { ModelsDev } from "../models-dev"
|
||||
import { Npm } from "../npm"
|
||||
import { PluginV2 } from "../plugin"
|
||||
@@ -30,7 +29,6 @@ import { State } from "../state"
|
||||
import { FetchHttpClient, HttpClient } from "effect/unstable/http"
|
||||
import { AgentPlugin } from "./agent"
|
||||
import { CommandPlugin } from "./command"
|
||||
import { McpCommandPlugin } from "./mcp-command"
|
||||
import { ModelsDevPlugin } from "./models-dev"
|
||||
import { ProviderPlugins } from "./provider"
|
||||
import { SdkPlugins } from "./sdk"
|
||||
@@ -49,7 +47,6 @@ export type Requirements =
|
||||
| HttpClient.HttpClient
|
||||
| Integration.Service
|
||||
| Location.Service
|
||||
| MCP.Service
|
||||
| ModelsDev.Service
|
||||
| Npm.Service
|
||||
| Reference.Service
|
||||
@@ -74,7 +71,6 @@ const layer = Layer.effectDiscard(
|
||||
const agents = yield* AgentV2.Service
|
||||
const config = yield* Config.Service
|
||||
const location = yield* Location.Service
|
||||
const mcp = yield* MCP.Service
|
||||
const modelsDev = yield* ModelsDev.Service
|
||||
const npm = yield* Npm.Service
|
||||
const events = yield* EventV2.Service
|
||||
@@ -97,7 +93,6 @@ const layer = Layer.effectDiscard(
|
||||
Effect.provideService(AgentV2.Service, agents),
|
||||
Effect.provideService(Config.Service, config),
|
||||
Effect.provideService(Location.Service, location),
|
||||
Effect.provideService(MCP.Service, mcp),
|
||||
Effect.provideService(ModelsDev.Service, modelsDev),
|
||||
Effect.provideService(Npm.Service, npm),
|
||||
Effect.provideService(EventV2.Service, events),
|
||||
@@ -121,7 +116,6 @@ const layer = Layer.effectDiscard(
|
||||
yield* add(ModelsDevPlugin)
|
||||
yield* add(ConfigAgentPlugin.Plugin)
|
||||
yield* add(ConfigCommandPlugin.Plugin)
|
||||
yield* add(McpCommandPlugin.Plugin)
|
||||
yield* add(ConfigSkillPlugin.Plugin)
|
||||
for (const item of ProviderPlugins) yield* add(item)
|
||||
yield* add(ConfigExternalPlugin.Plugin)
|
||||
@@ -152,7 +146,6 @@ export const node = makeLocationNode({
|
||||
AgentV2.node,
|
||||
Config.node,
|
||||
Location.node,
|
||||
MCP.node,
|
||||
ModelsDev.node,
|
||||
Npm.node,
|
||||
EventV2.node,
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
export * as McpCommandPlugin from "./mcp-command"
|
||||
|
||||
import { McpEvent } from "@opencode-ai/schema/mcp-event"
|
||||
import { Effect, Stream } from "effect"
|
||||
import { EventV2 } from "../event"
|
||||
import { MCP } from "../mcp"
|
||||
import { define } from "./internal"
|
||||
|
||||
export const Plugin = define({
|
||||
id: "mcp-command",
|
||||
effect: Effect.fn(function* (ctx) {
|
||||
const mcp = yield* MCP.Service
|
||||
const events = yield* EventV2.Service
|
||||
yield* ctx.command.transform(
|
||||
Effect.fn(function* (draft) {
|
||||
for (const prompt of yield* mcp.prompts()) {
|
||||
draft.update(commandName(prompt), (command) => {
|
||||
command.template = ""
|
||||
command.description = prompt.description
|
||||
})
|
||||
}
|
||||
}),
|
||||
)
|
||||
yield* events
|
||||
.subscribe(McpEvent.PromptsChanged)
|
||||
.pipe(Stream.runForEach(() => ctx.command.reload()), Effect.forkScoped({ startImmediately: true }))
|
||||
}),
|
||||
})
|
||||
|
||||
const commandName = (prompt: MCP.Prompt) => `${sanitize(prompt.server)}:${sanitize(prompt.name)}`
|
||||
|
||||
const sanitize = (value: string) => value.replace(/[^a-zA-Z0-9_-]/g, "_")
|
||||
Reference in New Issue
Block a user