MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / handleHookInvoke

Function handleHookInvoke

crates/opencode-plugin/host/plugin-host.ts:452–481  ·  view source on GitHub ↗
(
  id: number,
  params: { hook: string; input: unknown; output: unknown },
)

Source from the content-addressed store, hash-verified

450}
451
452async function handleHookInvoke(
453 id: number,
454 params: { hook: string; input: unknown; output: unknown },
455): Promise<void> {
456 const handler = pluginHooks[params.hook];
457 if (typeof handler !== "function") {
458 sendError(id, -32601, `Hook not found: ${params.hook}`);
459 return;
460 }
461
462 try {
463 // TS parity: `config` hooks mutate the first argument in-place.
464 // Use one shared object for both input/output so in-place edits are preserved.
465 if (params.hook === "config") {
466 const seed =
467 (params.output as UnknownRecord | null) ??
468 (params.input as UnknownRecord | null) ??
469 ({} as UnknownRecord);
470 const result = await handler(seed, seed);
471 sendResult(id, { output: result ?? seed });
472 return;
473 }
474
475 const result = await handler(params.input, params.output);
476 sendResult(id, { output: result ?? params.output });
477 } catch (err: unknown) {
478 const msg = err instanceof Error ? err.message : String(err);
479 sendError(id, -32603, `Hook ${params.hook} failed: ${msg}`);
480 }
481}
482
483async function handleAuthAuthorize(
484 id: number,

Callers 1

mainFunction · 0.85

Calls 2

sendErrorFunction · 0.85
sendResultFunction · 0.85

Tested by

no test coverage detected