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

Function parseToolParams

packages/opencode/src/cli/cmd/debug/agent.handler.ts:100–124  ·  view source on GitHub ↗
(input?: string)

Source from the content-addressed store, hash-verified

98}
99
100function parseToolParams(input?: string) {
101 if (!input) return {}
102 const trimmed = input.trim()
103 if (trimmed.length === 0) return {}
104
105 const parsed = iife(() => {
106 try {
107 return JSON.parse(trimmed)
108 } catch (jsonError) {
109 try {
110 return new Function(`return (${trimmed})`)()
111 } catch (evalError) {
112 throw new Error(
113 `Failed to parse --params. Use JSON or a JS object literal. JSON error: ${jsonError}. Eval error: ${evalError}.`,
114 { cause: evalError },
115 )
116 }
117 }
118 })
119
120 if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
121 throw new Error("Tool params must be an object.")
122 }
123 return parsed as Record<string, unknown>
124}
125
126const createToolContext = Effect.fn("Cli.debug.agent.createToolContext")(function* (
127 agent: Agent.Info,

Callers 1

agent.handler.tsFile · 0.85

Calls 1

iifeFunction · 0.90

Tested by

no test coverage detected