{"record":{"id":"4497576fc2ec37a9","repo":"eyaltoledano/claude-task-master","slug":"streamobjectservice-requires-a-schema-parameter","errorCode":null,"errorMessage":"streamObjectService requires a schema parameter","messagePattern":"streamObjectService requires a schema parameter","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/modules/ai-services-unified.js","lineNumber":847,"sourceCode":" * Uses Vercel AI SDK's streamObject for proper JSON streaming.\n *\n * @param {object} params - Parameters for the service call.\n * @param {string} params.role - The initial client role ('main', 'research', 'fallback').\n * @param {object} [params.session=null] - Optional MCP session object.\n * @param {string} [params.projectRoot=null] - Optional project root path for .env fallback.\n * @param {import('zod').ZodSchema} params.schema - The Zod schema for the expected object.\n * @param {string} params.prompt - The prompt for the AI.\n * @param {string} [params.systemPrompt] - Optional system prompt.\n * @param {string} params.commandName - Name of the command invoking the service.\n * @param {string} [params.outputType='cli'] - 'cli' or 'mcp'.\n * @returns {Promise<object>} Result object containing the stream and usage data.\n */\nasync function streamObjectService(params) {\n\tconst defaults = { outputType: 'cli' };\n\tconst combinedParams = { ...defaults, ...params };\n\t// Stream object requires a schema\n\tif (!combinedParams.schema) {\n\t\tthrow new Error('streamObjectService requires a schema parameter');\n\t}\n\treturn _unifiedServiceRunner('streamObject', combinedParams);\n}\n\n/**\n * Unified service function for generating structured objects.\n * Handles client retrieval, retries, and fallback sequence.\n *\n * @param {object} params - Parameters for the service call.\n * @param {string} params.role - The initial client role ('main', 'research', 'fallback').\n * @param {object} [params.session=null] - Optional MCP session object.\n * @param {string} [params.projectRoot=null] - Optional project root path for .env fallback.\n * @param {import('zod').ZodSchema} params.schema - The Zod schema for the expected object.\n * @param {string} params.prompt - The prompt for the AI.\n * @param {string} [params.systemPrompt] - Optional system prompt.\n * @param {string} [params.objectName='generated_object'] - Name for object/tool.\n * @param {number} [params.maxRetries=3] - Max retries for object generation.\n * @param {string} params.commandName - Name of the command invoking the service.","sourceCodeStart":829,"sourceCodeEnd":865,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/ai-services-unified.js#L829-L865","documentation":"A synchronous argument-validation error thrown at the top of streamObjectService. Streaming structured objects requires a Zod/JSON schema to validate and shape each streamed output, so calling without one is rejected before any client or API call is made.","triggerScenarios":"Calling streamObjectService({ ... }) where params omits the schema property — e.g. copying a generateTextService call and only renaming the function, or building params dynamically where schema is conditionally undefined.","commonSituations":"Refactoring from generateTextService to streaming without migrating the schema, passing a schema variable that is undefined due to a failed import or typo, or building a generic AI helper that only sometimes supplies a schema.","solutions":["Pass a schema: streamObjectService({ ..., schema: myZodObject }).","Ensure the schema import is defined (not undefined) before the call.","If you don't need structured output, use streamTextService instead.","Wrap schema construction so defaults exist for the streaming path."],"exampleFix":"// before\nawait streamObjectService({ role: 'main', prompt });\n// after\nawait streamObjectService({ role: 'main', prompt, schema: TaskSchema });","handlingStrategy":"validation","validationCode":"function assertSchema(schema) {\n  if (schema == null) throw new TypeError('streamObjectService: schema is required');\n  const isZod = typeof schema === 'object' && typeof schema.parse === 'function' && typeof schema.safeParse === 'function';\n  if (!isZod) throw new TypeError('streamObjectService: schema must be a Zod schema');\n}\nassertSchema(schema);","typeGuard":"function isZodSchema(s) {\n  return s != null && typeof s === 'object' && typeof s.safeParse === 'function';\n}","tryCatchPattern":"if (!isZodSchema(schema)) {\n  throw new TypeError('A Zod schema is required before calling streamObjectService');\n}\ntry {\n  await streamObjectService({ role: 'main', prompt, schema });\n} catch (e) {\n  if (e.message.includes('requires a schema parameter')) return streamTextService({ role: 'main', prompt });\n  throw e;\n}","preventionTips":["Always co-locate the schema with the streaming call in a single object literal.","Type helpers so schema is a required parameter, catching omissions at compile time.","Don't conditionally build params objects that can omit schema."],"tags":["validation","schema","api-misuse","arguments"],"backgroundTag":"missing-required-parameter","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}