2025-07-24 01:32:50 +08:00
|
|
|
import { createWorkflow } from '@mastra/core';
|
|
|
|
import { z } from 'zod';
|
2025-08-07 01:47:12 +08:00
|
|
|
import { DocsAgentContextSchema } from '../../agents/docs-agent/docs-agent-context';
|
2025-07-24 01:32:50 +08:00
|
|
|
import { createDocsTodosStep } from '../../steps/docs-agent/create-docs-todos-step';
|
|
|
|
import { docsAgentStep } from '../../steps/docs-agent/docs-agent-step';
|
2025-07-29 04:57:05 +08:00
|
|
|
import { getRepositoryTreeStep } from '../../steps/docs-agent/get-repository-tree-step';
|
2025-07-24 01:32:50 +08:00
|
|
|
import { initializeContextStep } from '../../steps/docs-agent/initialize-context-step';
|
|
|
|
|
2025-07-27 02:43:25 +08:00
|
|
|
// Input schema for the workflow - matches what initialize-context-step expects
|
2025-07-24 01:32:50 +08:00
|
|
|
const docsAgentWorkflowInputSchema = z.object({
|
|
|
|
message: z.string(),
|
|
|
|
organizationId: z.string(),
|
2025-07-27 02:43:25 +08:00
|
|
|
// Use the DocsAgentContextSchema directly to ensure exact match
|
|
|
|
context: DocsAgentContextSchema,
|
2025-07-24 01:32:50 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// Output schema for the workflow
|
|
|
|
const docsAgentWorkflowOutputSchema = z.object({
|
|
|
|
todos: z.array(z.string()).optional(),
|
|
|
|
todoList: z.string().optional(),
|
|
|
|
documentationCreated: z.boolean().optional(),
|
|
|
|
clarificationNeeded: z.boolean().optional(),
|
|
|
|
clarificationQuestion: z
|
|
|
|
.object({
|
|
|
|
issue: z.string(),
|
|
|
|
context: z.string(),
|
|
|
|
clarificationQuestion: z.string(),
|
|
|
|
})
|
|
|
|
.optional(),
|
|
|
|
finished: z.boolean().optional(),
|
|
|
|
metadata: z
|
|
|
|
.object({
|
|
|
|
filesCreated: z.number().optional(),
|
|
|
|
toolsUsed: z.array(z.string()).optional(),
|
|
|
|
})
|
|
|
|
.optional(),
|
|
|
|
});
|
|
|
|
|
|
|
|
// Create the workflow with initialization step first
|
|
|
|
const docsAgentWorkflow = createWorkflow({
|
|
|
|
id: 'docs-agent-workflow',
|
|
|
|
inputSchema: docsAgentWorkflowInputSchema,
|
|
|
|
outputSchema: docsAgentWorkflowOutputSchema,
|
2025-07-29 04:57:05 +08:00
|
|
|
steps: [initializeContextStep, getRepositoryTreeStep, createDocsTodosStep, docsAgentStep],
|
2025-07-24 01:32:50 +08:00
|
|
|
})
|
|
|
|
.then(initializeContextStep) // First step: initialize runtime context
|
2025-07-29 04:57:05 +08:00
|
|
|
.then(getRepositoryTreeStep) // Get repository tree structure
|
2025-07-24 01:32:50 +08:00
|
|
|
.then(createDocsTodosStep) // Then create todos
|
|
|
|
.then(docsAgentStep) // Finally run the agent
|
|
|
|
.commit();
|
|
|
|
|
|
|
|
export default docsAgentWorkflow;
|
|
|
|
export { docsAgentWorkflowInputSchema, docsAgentWorkflowOutputSchema };
|