MCPcopy
hub / github.com/anomalyco/opencode / createStructuredOutputTool

Function createStructuredOutputTool

packages/opencode/src/session/prompt.ts:1564–1590  ·  view source on GitHub ↗
(input: {
  schema: Record<string, any>
  onSuccess: (output: unknown) => void
})

Source from the content-addressed store, hash-verified

1562
1563/** @internal Exported for testing */
1564export function createStructuredOutputTool(input: {
1565 schema: Record<string, any>
1566 onSuccess: (output: unknown) => void
1567}): AITool {
1568 // Remove $schema property if present (not needed for tool input)
1569 const { $schema: _, ...toolSchema } = input.schema
1570
1571 return tool({
1572 description: STRUCTURED_OUTPUT_DESCRIPTION,
1573 inputSchema: jsonSchema(toolSchema as JSONSchema7),
1574 async execute(args) {
1575 // AI SDK validates args against inputSchema before calling execute()
1576 input.onSuccess(args)
1577 return {
1578 output: "Structured output captured successfully.",
1579 title: "Structured Output",
1580 metadata: { valid: true },
1581 }
1582 },
1583 toModelOutput({ output }) {
1584 return {
1585 type: "text",
1586 value: output.output,
1587 }
1588 },
1589 })
1590}
1591const bashRegex = /!`([^`]+)`/g
1592// Match [Image N] as single token, quoted strings, or non-space sequences
1593const argsRegex = /(?:\[Image\s+\d+\]|"[^"]*"|'[^']*'|[^\s"']+)/gi

Callers 1

prompt.tsFile · 0.85

Calls 1

toolFunction · 0.50

Tested by

no test coverage detected