MCPcopy Create free account
hub / github.com/anomalyco/opencode / matchToolChoice

Function matchToolChoice

packages/llm/src/protocols/shared.ts:265–281  ·  view source on GitHub ↗
(
  route: string,
  toolChoice: NonNullable<LLMRequest["toolChoice"]>,
  cases: {
    readonly auto: () => Auto
    readonly none: () => None
    readonly required: () => Required
    readonly tool: (name: string) => Tool
  },
)

Source from the content-addressed store, hash-verified

263 })
264
265export const matchToolChoice = <Auto, None, Required, Tool>(
266 route: string,
267 toolChoice: NonNullable<LLMRequest["toolChoice"]>,
268 cases: {
269 readonly auto: () => Auto
270 readonly none: () => None
271 readonly required: () => Required
272 readonly tool: (name: string) => Tool
273 },
274) =>
275 Effect.gen(function* () {
276 if (toolChoice.type === "auto") return cases.auto()
277 if (toolChoice.type === "none") return cases.none()
278 if (toolChoice.type === "required") return cases.required()
279 if (!toolChoice.name) return yield* invalidRequest(`${route} tool choice requires a tool name`)
280 return cases.tool(toolChoice.name)
281 })
282
283type ContentType = ContentPart["type"]
284

Callers

nothing calls this directly

Calls 2

invalidRequestFunction · 0.85
toolMethod · 0.45

Tested by

no test coverage detected