(
result: TResult,
schema: string,
schemaVersion: string,
options: StructuredEnvelopeOptions = {},
)
| 380 | } |
| 381 | |
| 382 | export function toStructuredEnvelope<TResult extends ToolDomainResult>( |
| 383 | result: TResult, |
| 384 | schema: string, |
| 385 | schemaVersion: string, |
| 386 | options: StructuredEnvelopeOptions = {}, |
| 387 | ): StructuredOutputEnvelope<unknown> { |
| 388 | const { nextSteps, nextStepRuntime = 'cli', outputStyle = 'normal' } = options; |
| 389 | const { kind: neverKind, didError, error, ...data } = result; |
| 390 | const projectedData = projectRuntimeSnapshotData(data as DomainResultData<TResult>, options); |
| 391 | const serializedNextSteps = |
| 392 | schema === 'xcodebuildmcp.output.error' |
| 393 | ? undefined |
| 394 | : serializeNextSteps(nextSteps, { |
| 395 | runtime: nextStepRuntime, |
| 396 | }); |
| 397 | |
| 398 | const envelope: StructuredOutputEnvelope<unknown> = { |
| 399 | schema, |
| 400 | schemaVersion, |
| 401 | didError, |
| 402 | error, |
| 403 | data: isRecord(projectedData) && Object.keys(projectedData).length === 0 ? null : projectedData, |
| 404 | ...(serializedNextSteps ? { nextSteps: serializedNextSteps } : {}), |
| 405 | }; |
| 406 | |
| 407 | return applyStructuredOutputStyle(envelope, outputStyle); |
| 408 | } |
no test coverage detected