(
handlerContext: ToolHandlerContext,
session: ReturnType<typeof createRenderSession>,
options: { outputStyle: OutputStyle; verbose?: boolean },
)
| 100 | const UI_ACTION_RESULT_VERBOSE_SCHEMA_VERSION = '3'; |
| 101 | |
| 102 | function writeJsonOutput( |
| 103 | handlerContext: ToolHandlerContext, |
| 104 | session: ReturnType<typeof createRenderSession>, |
| 105 | options: { outputStyle: OutputStyle; verbose?: boolean }, |
| 106 | ): boolean { |
| 107 | const { structuredOutput } = handlerContext; |
| 108 | const envelope = structuredOutput |
| 109 | ? toStructuredEnvelope( |
| 110 | structuredOutput.result, |
| 111 | structuredOutput.schema, |
| 112 | structuredOutput.schema === UI_ACTION_RESULT_SCHEMA && options.verbose === true |
| 113 | ? UI_ACTION_RESULT_VERBOSE_SCHEMA_VERSION |
| 114 | : structuredOutput.schemaVersion, |
| 115 | { |
| 116 | nextSteps: session.getNextSteps?.(), |
| 117 | nextStepRuntime: session.getNextStepsRuntime?.(), |
| 118 | outputStyle: options.outputStyle, |
| 119 | runtimeSnapshot: options.verbose ? 'full' : 'compact', |
| 120 | }, |
| 121 | ) |
| 122 | : toStructuredEnvelope( |
| 123 | createStructuredErrorOutput({ |
| 124 | category: 'runtime', |
| 125 | code: 'STRUCTURED_OUTPUT_MISSING', |
| 126 | message: 'Tool did not produce structured output for --output json', |
| 127 | }).result, |
| 128 | STRUCTURED_ERROR_SCHEMA, |
| 129 | STRUCTURED_ERROR_SCHEMA_VERSION, |
| 130 | { outputStyle: options.outputStyle }, |
| 131 | ); |
| 132 | |
| 133 | process.stdout.write(JSON.stringify(envelope, null, 2) + '\n'); |
| 134 | return envelope.didError; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Register all tool commands from the catalog with yargs, grouped by workflow. |
no test coverage detected