UNPKG

@autobe/agent

Version:

AI backend server code generator

90 lines (71 loc) 3.12 kB
import { AutoBeOpenApi } from "@autobe/interface"; import { StringUtil } from "@autobe/utils"; import { v7 } from "uuid"; import { AutoBeSystemPromptConstant } from "../../../constants/AutoBeSystemPromptConstant"; import { IAutoBeOrchestrateHistory } from "../../../structures/IAutoBeOrchestrateHistory"; import { AutoBePreliminaryController } from "../../common/AutoBePreliminaryController"; export const transformInterfaceSchemaWriteHistory = (props: { operations: AutoBeOpenApi.IOperation[]; typeName: string; otherTypeNames: string[]; preliminary: AutoBePreliminaryController< | "analysisSections" | "databaseSchemas" | "interfaceOperations" | "previousAnalysisSections" | "previousDatabaseSchemas" | "previousInterfaceOperations" | "previousInterfaceSchemas" | "complete" >; instruction: string; }): IAutoBeOrchestrateHistory => { return { histories: [ { type: "systemMessage", id: v7(), created_at: new Date().toISOString(), text: AutoBeSystemPromptConstant.INTERFACE_SCHEMA, }, ...props.preliminary.getHistories(), { type: "assistantMessage", id: v7(), created_at: new Date().toISOString(), text: StringUtil.trim` ## API Design Instructions The following API-specific instructions were extracted from the user's requirements. These focus on API interface design aspects such as endpoint patterns, request/response formats, DTO schemas, and operation specifications. Follow these instructions when creating JSON schema. Carefully distinguish between: - Suggestions or recommendations (consider these as guidance) - Direct specifications or explicit commands (these must be followed exactly) When instructions contain direct specifications or explicit design decisions, follow them precisely even if you believe you have better alternatives. ${props.instruction} ## Operations (Filtered for Target Schemas) Here is the list of API operations that directly use the schemas you need to generate (via requestBody.typeName or responseBody.typeName). These are the ONLY operations relevant to your current task - other operations have been filtered out to reduce noise and improve focus: \`\`\`json ${JSON.stringify(props.operations)} \`\`\` ## Other DTO Type names you can reference While creating the JSON schema for the target type, you can reference other DTO types defined in the API. Here are their type names: - ${props.otherTypeNames.map((name) => `- ${name}`).join("\n")} ## DTO type to create Here is the specific type you need to create a JSON schema component for. - ${JSON.stringify(props.typeName)} `, }, ], userMessage: StringUtil.trim` Design the JSON schema for ${JSON.stringify(props.typeName)} type. `, }; };