/** * 反例:dowhile 的循环体「输出形状 ≠ 输入形状」时会怎样(只做类型检查,不运行)。 * 用 tsc 单独检查这个文件:npx tsc --noEmit --strict --module esnext --moduleResolution bundler \ * --target es2022 --skipLibCheck src/negative/dowhile-shape-mismatch.ts */ import { createStep, createWorkflow } from '@mastra/core/workflows'; import { z } from 'zod'; const In = z.object({ round: z.number(), reopen: z.boolean() }); const Out = z.object({ somethingElse: z.string() }); const body = createStep({ id: 'body', inputSchema: In, outputSchema: Out, execute: async () => ({ somethingElse: 'x' }), }); const start = createStep({ id: 'start', inputSchema: z.object({}), outputSchema: In, execute: async () => ({ round: 1, reopen: false }), }); export const wf = createWorkflow({ id: 'neg', inputSchema: z.object({}), outputSchema: Out }) .then(start) // 循环体输出 Out,下一轮却要拿它当 In 用 .dowhile(body, async ({ inputData }) => inputData.reopen === true) .commit();