UNPKG

@autobe/agent

Version:

AI backend server code generator

217 lines (205 loc) 17.7 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.validatePreliminary = void 0; const utils_1 = require("@autobe/utils"); const tstl_1 = require("tstl"); const typia_1 = __importDefault(require("typia")); const validatePreliminary = (controller, data) => { const func = PreliminaryApplicationValidator[data.request.type]; return func(controller, data); }; exports.validatePreliminary = validatePreliminary; var PreliminaryApplicationValidator; (function (PreliminaryApplicationValidator) { PreliminaryApplicationValidator.getAnalysisFiles = (controller, input) => { const all = new Set(controller.getAll().analysisFiles.map((f) => f.filename)); const oldbie = new Set(controller.getLocal().analysisFiles.map((f) => f.filename)); const newbie = new Set(controller .getAll() .analysisFiles.filter((f) => oldbie.has(f.filename) === false) .map((f) => f.filename)); const description = utils_1.StringUtil.trim ` Here are the list of analysis requirement document files you can use. Please select from the below. Never type arbitrary file names. Filename | Document Type ---------|--------------- ${controller .getAll() .analysisFiles.filter((f) => newbie.has(f.filename)) .map((f) => [f.filename, f.documentType].join(" | ")) .join("\n")} ${newbie.size === 0 ? "<!--\nfilename: PRELIMINARY_ANALYSIS_FILE_EXHAUSTED.md\n-->\n> All analysis files have been loaded into memory, so no available analysis files remain.\n>\n> Therefore, never call `process()` with `type: \"getAnalysisFiles\"` again. If you're planning to request more analysis files, it is an absolutely wrong decision. You must proceed to complete your task instead.\n>\n> To reiterate: never call `process()` with `type: \"getAnalysisFiles\"` again." /* AutoBeSystemPromptConstant.PRELIMINARY_ANALYSIS_FILE_EXHAUSTED */ : ""} `; const errors = []; input.request.fileNames.forEach((key, i) => { if (all.has(key) === false) errors.push({ path: `$input.request.fileNames[${i}]`, value: key, expected: Array.from(newbie) .map((x) => JSON.stringify(x)) .join(" | "), description, }); }); if (input.request.fileNames.every((k) => oldbie.has(k))) errors.push({ path: `$input.request`, value: input.request, expected: controller .getArgumentTypeNames() .filter((k) => k !== "IAutoBePreliminaryGetAnalysisFiles") .join(" | "), description: "<!--\nfilename: PRELIMINARY_ARGUMENT_ALL_DUPLICATED.md\n-->\n# All Requested Items Already Loaded\n\nYou requested items from `\"{{REQUEST_TYPE}}\"`, but **all of them are already in your conversation history**.\n\nThe type `\"{{REQUEST_TYPE}}\"` has been **removed from the union**. You cannot call it again.\n\n## What You Should Do\n\n**Check the `expected` field in the validation error** - it shows which types are still available.\n\nCall one of those types, or call `type: \"complete\"` to finish your task.\n\n**Important:** The type **name** must be different, not just the parameters.\n\n```typescript\n// \u2705 CORRECT - Different type name\nprocess({\n request: {\n type: \"different-type\", // From 'expected' field\n ...\n }\n})\n\n// \u274C WRONG - Same type name\nprocess({\n request: {\n type: \"{{REQUEST_TYPE}}\", // Removed from union\n ...\n }\n})\n```\n\n## Why Same Type Won't Work\n\nChanging parameters doesn't change the type name:\n\n```typescript\n// All FORBIDDEN - same type name \"{{REQUEST_TYPE}}\":\nprocess({ request: { type: \"{{REQUEST_TYPE}}\", items: [\"a\"] } }) // \u274C\nprocess({ request: { type: \"{{REQUEST_TYPE}}\", items: [\"b\", \"c\"] } }) // \u274C\nprocess({ request: { type: \"{{REQUEST_TYPE}}\", items: [] } }) // \u274C\n```\n\nThe type `\"{{REQUEST_TYPE}}\"` is removed from the union. You must use a different type name.\n\n## Summary\n\n1. All requested items are already loaded\n2. Type `\"{{REQUEST_TYPE}}\"` removed from union\n3. Check `expected` field for available types\n4. Use a different type name (not just different parameters)\n5. Do NOT call `type: \"{{REQUEST_TYPE}}\"` again" /* AutoBeSystemPromptConstant.PRELIMINARY_ARGUMENT_ALL_DUPLICATED */.replaceAll("{{REQUEST_TYPE}}", [ "getAnalysisFiles" ][0]), }); return finalize(input, errors); }; PreliminaryApplicationValidator.getPrismaSchemas = (controller, input) => { const all = new Set(controller.getAll().prismaSchemas.map((s) => s.name)); const oldbie = new Set(controller.getLocal().prismaSchemas.map((s) => s.name)); const newbie = new Set(controller .getAll() .prismaSchemas.filter((s) => oldbie.has(s.name) === false) .map((s) => s.name)); const quoted = Array.from(newbie).map((x) => JSON.stringify(x)); const description = utils_1.StringUtil.trim ` Here are the list of prisma schema models you can use. Please select from the below. Never assume non-existing models. ${quoted.map((q) => `- ${q}`).join("\n")} ${newbie.size === 0 ? "<!--\nfilename: PRELIMINARY_PRISMA_SCHEMA_EXHAUSTED.md\n-->\n> All Prisma schemas have been loaded into memory, so no available Prisma schemas remain.\n>\n> Therefore, never call `process()` with `type: \"getPrismaSchemas\"` again. If you're planning to request more Prisma schemas, it is an absolutely wrong decision. You must proceed to complete your task instead.\n>\n> To reiterate: never call `process()` with `type: \"getPrismaSchemas\"` again." /* AutoBeSystemPromptConstant.PRELIMINARY_PRISMA_SCHEMA_EXHAUSTED */ : ""} `; const errors = []; input.request.schemaNames.forEach((key, i) => { if (all.has(key) === false) errors.push({ path: `$input.request.schemaNames[${i}]`, value: key, expected: quoted.join(" | "), description, }); }); if (input.request.schemaNames.every((k) => oldbie.has(k))) errors.push({ path: `$input.request`, value: input.request, expected: controller .getArgumentTypeNames() .filter((k) => k !== "IAutoBePreliminaryGetPrismaSchemas") .join(" | "), description: "<!--\nfilename: PRELIMINARY_ARGUMENT_ALL_DUPLICATED.md\n-->\n# All Requested Items Already Loaded\n\nYou requested items from `\"{{REQUEST_TYPE}}\"`, but **all of them are already in your conversation history**.\n\nThe type `\"{{REQUEST_TYPE}}\"` has been **removed from the union**. You cannot call it again.\n\n## What You Should Do\n\n**Check the `expected` field in the validation error** - it shows which types are still available.\n\nCall one of those types, or call `type: \"complete\"` to finish your task.\n\n**Important:** The type **name** must be different, not just the parameters.\n\n```typescript\n// \u2705 CORRECT - Different type name\nprocess({\n request: {\n type: \"different-type\", // From 'expected' field\n ...\n }\n})\n\n// \u274C WRONG - Same type name\nprocess({\n request: {\n type: \"{{REQUEST_TYPE}}\", // Removed from union\n ...\n }\n})\n```\n\n## Why Same Type Won't Work\n\nChanging parameters doesn't change the type name:\n\n```typescript\n// All FORBIDDEN - same type name \"{{REQUEST_TYPE}}\":\nprocess({ request: { type: \"{{REQUEST_TYPE}}\", items: [\"a\"] } }) // \u274C\nprocess({ request: { type: \"{{REQUEST_TYPE}}\", items: [\"b\", \"c\"] } }) // \u274C\nprocess({ request: { type: \"{{REQUEST_TYPE}}\", items: [] } }) // \u274C\n```\n\nThe type `\"{{REQUEST_TYPE}}\"` is removed from the union. You must use a different type name.\n\n## Summary\n\n1. All requested items are already loaded\n2. Type `\"{{REQUEST_TYPE}}\"` removed from union\n3. Check `expected` field for available types\n4. Use a different type name (not just different parameters)\n5. Do NOT call `type: \"{{REQUEST_TYPE}}\"` again" /* AutoBeSystemPromptConstant.PRELIMINARY_ARGUMENT_ALL_DUPLICATED */.replaceAll("{{REQUEST_TYPE}}", [ "getPrismaSchemas" ][0]), }); return finalize(input, errors); }; PreliminaryApplicationValidator.getInterfaceOperations = (controller, input) => { const all = new tstl_1.HashSet(controller.getAll().interfaceOperations.map((o) => ({ method: o.method, path: o.path, })), utils_1.AutoBeOpenApiEndpointComparator.hashCode, utils_1.AutoBeOpenApiEndpointComparator.equals); const oldbie = new tstl_1.HashSet(controller.getLocal().interfaceOperations.map((o) => ({ method: o.method, path: o.path, })), utils_1.AutoBeOpenApiEndpointComparator.hashCode, utils_1.AutoBeOpenApiEndpointComparator.equals); const newbie = new tstl_1.HashSet(controller .getAll() .interfaceOperations.map((o) => ({ method: o.method, path: o.path, })) .filter((e) => oldbie.has(e) === false), utils_1.AutoBeOpenApiEndpointComparator.hashCode, utils_1.AutoBeOpenApiEndpointComparator.equals); const description = utils_1.StringUtil.trim ` Here are the list of API endpoints you can use. Please select from the below. Never assume non-existing endpoints. Method | Path -------|------ ${newbie .toJSON() .map((o) => [o.method, o.path].join(" | ")) .join("\n")} ${newbie.size() === 0 ? "<!--\nfilename: PRELIMINARY_INTERFACE_OPERATION_EXHAUSTED.md\n-->\n> All API operations have been loaded into memory, so no available API operations remain.\n>\n> Therefore, never call `process()` with `type: \"getInterfaceOperations\"` again. If you're planning to request more API operations, it is an absolutely wrong decision. You must proceed to complete your task instead.\n>\n> To reiterate: never call `process()` with `type: \"getInterfaceOperations\"` again." /* AutoBeSystemPromptConstant.PRELIMINARY_INTERFACE_OPERATION_EXHAUSTED */ : ""} `; const errors = []; input.request.endpoints.forEach((key, i) => { if (all.has(key) === false) errors.push({ path: `$input.request.endpoints[${i}]`, value: key, expected: "AutoBeOpenApi.IEndpoint", description, }); }); if (input.request.endpoints.every((k) => oldbie.has(k))) errors.push({ path: `$input.request`, value: input.request, expected: controller .getArgumentTypeNames() .filter((k) => k !== "IAutoBePreliminaryGetInterfaceOperations") .join(" | "), description: "<!--\nfilename: PRELIMINARY_ARGUMENT_ALL_DUPLICATED.md\n-->\n# All Requested Items Already Loaded\n\nYou requested items from `\"{{REQUEST_TYPE}}\"`, but **all of them are already in your conversation history**.\n\nThe type `\"{{REQUEST_TYPE}}\"` has been **removed from the union**. You cannot call it again.\n\n## What You Should Do\n\n**Check the `expected` field in the validation error** - it shows which types are still available.\n\nCall one of those types, or call `type: \"complete\"` to finish your task.\n\n**Important:** The type **name** must be different, not just the parameters.\n\n```typescript\n// \u2705 CORRECT - Different type name\nprocess({\n request: {\n type: \"different-type\", // From 'expected' field\n ...\n }\n})\n\n// \u274C WRONG - Same type name\nprocess({\n request: {\n type: \"{{REQUEST_TYPE}}\", // Removed from union\n ...\n }\n})\n```\n\n## Why Same Type Won't Work\n\nChanging parameters doesn't change the type name:\n\n```typescript\n// All FORBIDDEN - same type name \"{{REQUEST_TYPE}}\":\nprocess({ request: { type: \"{{REQUEST_TYPE}}\", items: [\"a\"] } }) // \u274C\nprocess({ request: { type: \"{{REQUEST_TYPE}}\", items: [\"b\", \"c\"] } }) // \u274C\nprocess({ request: { type: \"{{REQUEST_TYPE}}\", items: [] } }) // \u274C\n```\n\nThe type `\"{{REQUEST_TYPE}}\"` is removed from the union. You must use a different type name.\n\n## Summary\n\n1. All requested items are already loaded\n2. Type `\"{{REQUEST_TYPE}}\"` removed from union\n3. Check `expected` field for available types\n4. Use a different type name (not just different parameters)\n5. Do NOT call `type: \"{{REQUEST_TYPE}}\"` again" /* AutoBeSystemPromptConstant.PRELIMINARY_ARGUMENT_ALL_DUPLICATED */.replaceAll("{{REQUEST_TYPE}}", [ "getInterfaceOperations" ][0]), }); return finalize(input, errors); }; PreliminaryApplicationValidator.getInterfaceSchemas = (controller, input) => { const all = new Set(Object.keys(controller.getAll().interfaceSchemas)); const oldbie = new Set(Object.keys(controller.getLocal().interfaceSchemas)); const newbie = new Set(Object.keys(controller.getAll().interfaceSchemas).filter((k) => oldbie.has(k) === false)); const quoted = Array.from(newbie).map((k) => JSON.stringify(k)); const description = utils_1.StringUtil.trim ` Here are the list of interface schemas you can use. Please select from the below. Never assume non-existing schemas. ${quoted.map((q) => `- ${q}`).join("\n")} ${newbie.size === 0 ? "<!--\nfilename: PRELIMINARY_INTERFACE_SCHEMA_EXHAUSTED.md\n-->\n> All TypeScript type schemas have been loaded into memory, so no available type schemas remain.\n>\n> Therefore, never call `process()` with `type: \"getInterfaceSchemas\"` again. If you're planning to request more type schemas, it is an absolutely wrong decision. You must proceed to complete your task instead.\n>\n> To reiterate: never call `process()` with `type: \"getInterfaceSchemas\"` again." /* AutoBeSystemPromptConstant.PRELIMINARY_INTERFACE_SCHEMA_EXHAUSTED */ : ""} `; const errors = []; input.request.typeNames.forEach((key, i) => { if (all.has(key) === false) errors.push({ path: `$input.request.typeNames[${i}]`, value: key, expected: quoted.join(" | "), description, }); }); if (input.request.typeNames.every((k) => oldbie.has(k))) errors.push({ path: `$input.request`, value: input.request, expected: controller .getArgumentTypeNames() .filter((k) => k !== "IAutoBePreliminaryGetInterfaceSchemas") .join(" | "), description: "<!--\nfilename: PRELIMINARY_ARGUMENT_ALL_DUPLICATED.md\n-->\n# All Requested Items Already Loaded\n\nYou requested items from `\"{{REQUEST_TYPE}}\"`, but **all of them are already in your conversation history**.\n\nThe type `\"{{REQUEST_TYPE}}\"` has been **removed from the union**. You cannot call it again.\n\n## What You Should Do\n\n**Check the `expected` field in the validation error** - it shows which types are still available.\n\nCall one of those types, or call `type: \"complete\"` to finish your task.\n\n**Important:** The type **name** must be different, not just the parameters.\n\n```typescript\n// \u2705 CORRECT - Different type name\nprocess({\n request: {\n type: \"different-type\", // From 'expected' field\n ...\n }\n})\n\n// \u274C WRONG - Same type name\nprocess({\n request: {\n type: \"{{REQUEST_TYPE}}\", // Removed from union\n ...\n }\n})\n```\n\n## Why Same Type Won't Work\n\nChanging parameters doesn't change the type name:\n\n```typescript\n// All FORBIDDEN - same type name \"{{REQUEST_TYPE}}\":\nprocess({ request: { type: \"{{REQUEST_TYPE}}\", items: [\"a\"] } }) // \u274C\nprocess({ request: { type: \"{{REQUEST_TYPE}}\", items: [\"b\", \"c\"] } }) // \u274C\nprocess({ request: { type: \"{{REQUEST_TYPE}}\", items: [] } }) // \u274C\n```\n\nThe type `\"{{REQUEST_TYPE}}\"` is removed from the union. You must use a different type name.\n\n## Summary\n\n1. All requested items are already loaded\n2. Type `\"{{REQUEST_TYPE}}\"` removed from union\n3. Check `expected` field for available types\n4. Use a different type name (not just different parameters)\n5. Do NOT call `type: \"{{REQUEST_TYPE}}\"` again" /* AutoBeSystemPromptConstant.PRELIMINARY_ARGUMENT_ALL_DUPLICATED */.replaceAll("{{REQUEST_TYPE}}", [ "getInterfaceSchemas" ][0]), }); return finalize(input, errors); }; })(PreliminaryApplicationValidator || (PreliminaryApplicationValidator = {})); const finalize = (data, errors) => errors.length === 0 ? { success: true, data, } : { success: false, data, errors, }; //# sourceMappingURL=validatePreliminary.js.map