MCPcopy Index your code
hub / github.com/anomalyco/opencode / readV1Plugin

Function readV1Plugin

packages/opencode/src/plugin/shared.ts:272–304  ·  view source on GitHub ↗
(
  mod: Record<string, unknown>,
  spec: string,
  kind: PluginKind,
  mode: PluginMode = "strict",
)

Source from the content-addressed store, hash-verified

270}
271
272export function readV1Plugin(
273 mod: Record<string, unknown>,
274 spec: string,
275 kind: PluginKind,
276 mode: PluginMode = "strict",
277) {
278 const value = mod.default
279 if (!isRecord(value)) {
280 if (mode === "detect") return
281 throw new TypeError(`Plugin ${spec} must default export an object with ${kind}()`)
282 }
283 if (mode === "detect" && !("id" in value) && !("server" in value) && !("tui" in value)) return
284
285 const server = "server" in value ? value.server : undefined
286 const tui = "tui" in value ? value.tui : undefined
287 if (server !== undefined && typeof server !== "function") {
288 throw new TypeError(`Plugin ${spec} has invalid server export`)
289 }
290 if (tui !== undefined && typeof tui !== "function") {
291 throw new TypeError(`Plugin ${spec} has invalid tui export`)
292 }
293 if (server !== undefined && tui !== undefined) {
294 throw new TypeError(`Plugin ${spec} must default export either server() or tui(), not both`)
295 }
296 if (kind === "server" && server === undefined) {
297 throw new TypeError(`Plugin ${spec} must default export an object with server()`)
298 }
299 if (kind === "tui" && tui === undefined) {
300 throw new TypeError(`Plugin ${spec} must default export an object with tui()`)
301 }
302
303 return value
304}
305
306export async function resolvePluginId(
307 source: PluginSource,

Callers 2

applyPluginFunction · 0.90
resolveExternalPluginsFunction · 0.90

Calls 1

isRecordFunction · 0.90

Tested by

no test coverage detected