UNPKG

@autobe/agent

Version:

AI backend server code generator

723 lines (722 loc) 176 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.orchestrateInterfacePrerequisite = orchestrateInterfacePrerequisite; const __typia_transform__validateReport = __importStar(require("typia/lib/internal/_validateReport.js")); const __typia_transform__llmApplicationFinalize = __importStar(require("typia/lib/internal/_llmApplicationFinalize.js")); const utils_1 = require("@autobe/utils"); const tstl_1 = require("tstl"); const typia_1 = __importDefault(require("typia")); const uuid_1 = require("uuid"); const assertSchemaModel_1 = require("../../context/assertSchemaModel"); const divideArray_1 = require("../../utils/divideArray"); const executeCachedBatch_1 = require("../../utils/executeCachedBatch"); const AutoBePreliminaryController_1 = require("../common/AutoBePreliminaryController"); const transformInterfacePrerequisiteHistory_1 = require("./histories/transformInterfacePrerequisiteHistory"); function orchestrateInterfacePrerequisite(ctx, document) { return __awaiter(this, void 0, void 0, function* () { var _a; const operations = (_a = document.operations.filter((op) => op.authorizationType === null)) !== null && _a !== void 0 ? _a : []; const progress = { total: operations.length, completed: 0, }; const prerequisiteOperations = document.operations.filter((op) => op.authorizationType === null && op.method === "post"); const dict = new tstl_1.HashMap(prerequisiteOperations.map((op) => new tstl_1.Pair({ path: op.path, method: op.method }, op)), utils_1.AutoBeOpenApiEndpointComparator.hashCode, utils_1.AutoBeOpenApiEndpointComparator.equals); const prerequisitesNotFound = [ `You have to select one of the endpoints below`, "", " method | path ", "--------|------", ...prerequisiteOperations .map((op) => `\`${op.method}\` | \`${op.path}\``) .join("\n"), ].join("\n"); const exclude = []; let include = [...operations]; let trial = 0; do { const matrix = (0, divideArray_1.divideArray)({ array: include, capacity: 2 /* AutoBeConfigConstant.INTERFACE_CAPACITY */, }); yield (0, executeCachedBatch_1.executeCachedBatch)(ctx, matrix.map((ops) => (promptCacheKey) => __awaiter(this, void 0, void 0, function* () { const row = yield divideAndConquer(ctx, { dict: dict, document, includes: ops, progress, promptCacheKey, prerequisitesNotFound, }); exclude.push(...row); return row; }))); include = include.filter((op) => { if (exclude.some((el) => el.endpoint.method === op.method && el.endpoint.path === op.path)) { return false; } return true; }); } while (include.length > 0 && ++trial < ctx.retry); return exclude; }); } function divideAndConquer(ctx, props) { return __awaiter(this, void 0, void 0, function* () { try { return yield process(ctx, props); } catch (_a) { props.progress.completed += props.includes.length; return []; } }); } function process(ctx, props) { return __awaiter(this, void 0, void 0, function* () { const preliminary = new AutoBePreliminaryController_1.AutoBePreliminaryController({ application: { version: "3.1", components: { schemas: { "IAutoBeInterfacePrerequisiteApplication.IProps": { type: "object", properties: { thinking: { type: "string", description: "Think before you act.\n\nBefore requesting preliminary data or completing your task, reflect on your\ncurrent state and explain your reasoning:\n\nFor preliminary requests (getAnalysisFiles, getPrismaSchemas, etc.):\n- What critical information is missing that you don't already have?\n- Why do you need it specifically right now?\n- Be brief - state the gap, don't list everything you have.\n\nFor completion (complete):\n- What key assets did you acquire?\n- What did you accomplish?\n- Why is it sufficient to complete?\n- Summarize - don't enumerate every single item.\n\nThis reflection helps you avoid duplicate requests and premature completion." }, request: { oneOf: [ { $ref: "#/components/schemas/IAutoBePreliminaryGetAnalysisFiles" }, { $ref: "#/components/schemas/IAutoBePreliminaryGetInterfaceOperations" }, { $ref: "#/components/schemas/IAutoBePreliminaryGetInterfaceSchemas" }, { $ref: "#/components/schemas/IAutoBePreliminaryGetPrismaSchemas" }, { $ref: "#/components/schemas/IAutoBeInterfacePrerequisiteApplication.IComplete" } ], discriminator: { propertyName: "type", mapping: { getAnalysisFiles: "#/components/schemas/IAutoBePreliminaryGetAnalysisFiles", getInterfaceOperations: "#/components/schemas/IAutoBePreliminaryGetInterfaceOperations", getInterfaceSchemas: "#/components/schemas/IAutoBePreliminaryGetInterfaceSchemas", getPrismaSchemas: "#/components/schemas/IAutoBePreliminaryGetPrismaSchemas", complete: "#/components/schemas/IAutoBeInterfacePrerequisiteApplication.IComplete" } }, description: "Type discriminator for the request.\n\nDetermines which action to perform: preliminary data retrieval\n(getAnalysisFiles, getPrismaSchemas, getInterfaceOperations,\ngetInterfaceSchemas) or final prerequisite analysis (complete). When\npreliminary returns empty array, that type is removed from the union,\nphysically preventing repeated calls." } }, required: [ "thinking", "request" ] }, IAutoBePreliminaryGetAnalysisFiles: { type: "object", properties: { type: { "const": "getAnalysisFiles", description: "Type discriminator for the request.\n\nDetermines which action to perform: preliminary data retrieval or actual\ntask execution. Value \"getAnalysisFiles\" indicates this is a preliminary\ndata request for analysis files." }, fileNames: { type: "array", items: { type: "string" }, minItems: 1, description: "List of analysis file names to retrieve.\n\nFile names from the analyze phase containing requirements, use cases, and\nbusiness logic documentation.\n\nCRITICAL: DO NOT request the same file names that you have already\nrequested in previous calls." } }, required: [ "type", "fileNames" ], description: "Request to retrieve requirements analysis files for context.\n\nThis type is used in the preliminary phase to request specific analysis files\nthat provide business requirements and domain context." }, IAutoBePreliminaryGetInterfaceOperations: { type: "object", properties: { type: { "const": "getInterfaceOperations", description: "Type discriminator for the request.\n\nDetermines which action to perform: preliminary data retrieval or actual\ntask execution. Value \"getInterfaceOperations\" indicates this is a\npreliminary data request for interface operations." }, endpoints: { type: "array", items: { $ref: "#/components/schemas/AutoBeOpenApi.IEndpoint" }, minItems: 1, description: "List of existing API operation endpoints to retrieve.\n\nOperations that have been generated in previous phases, containing paths,\nmethods, parameters, and request/response bodies.\n\nCRITICAL: DO NOT request the same endpoints that you have already requested\nin previous calls." } }, required: [ "type", "endpoints" ], description: "Request to retrieve existing interface operations for context.\n\nThis type is used in the preliminary phase to request already-generated API\noperations for review, validation, or complementary generation tasks." }, "AutoBeOpenApi.IEndpoint": { type: "object", properties: { path: { type: "string", pattern: "^\\/[a-zA-Z0-9\\/_{}.-]*$", description: "HTTP path of the API operation.\n\nThe URL path for accessing this API operation, using path parameters\nenclosed in curly braces (e.g., `/shoppings/customers/sales/{saleId}`).\n\nIt must be corresponded to the {@link parameters path parameters}.\n\nThe path structure should clearly indicate which database entity this\noperation is manipulating, helping to ensure all entities have\nappropriate API coverage.\n\nPath validation rules:\n\n- Must start with a forward slash (/)\n- Can contain only: letters (a-z, A-Z), numbers (0-9), forward slashes (/),\n curly braces for parameters ({paramName}), hyphens (-), and underscores\n (_)\n- Parameters must be enclosed in curly braces: {paramName}\n- Resource names should be in camelCase\n- No quotes, spaces, or invalid special characters allowed\n- No domain or role-based prefixes\n\nValid examples:\n\n- \"/users\"\n- \"/users/{userId}\"\n- \"/articles/{articleId}/comments\"\n- \"/attachmentFiles\"\n- \"/orders/{orderId}/items/{itemId}\"\n\nInvalid examples:\n\n- \"'/users'\" (contains quotes)\n- \"/user profile\" (contains space)\n- \"/users/[userId]\" (wrong bracket format)\n- \"/admin/users\" (role prefix)\n- \"/api/v1/users\" (API prefix)" }, method: { oneOf: [ { "const": "get" }, { "const": "post" }, { "const": "put" }, { "const": "delete" }, { "const": "patch" } ], description: "HTTP method of the API operation.\n\n**IMPORTANT**: Methods must be written in lowercase only (e.g., \"get\",\nnot \"GET\").\n\nNote that, if the API operation has {@link requestBody}, method must not\nbe `get`.\n\nAlso, even though the API operation has been designed to only get\ninformation, but it needs complicated request information, it must be\ndefined as `patch` method with {@link requestBody} data specification.\n\n- `get`: get information\n- `patch`: get information with complicated request data\n ({@link requestBody})\n- `post`: create new record\n- `put`: update existing record\n- `delete`: remove record" } }, required: [ "path", "method" ], description: "API endpoint information." }, IAutoBePreliminaryGetInterfaceSchemas: { type: "object", properties: { type: { "const": "getInterfaceSchemas", description: "Type discriminator for the request.\n\nDetermines which action to perform: preliminary data retrieval or actual\ntask execution. Value \"getInterfaceSchemas\" indicates this is a preliminary\ndata request for interface schemas." }, typeNames: { type: "array", items: { type: "string" }, minItems: 1, description: "List of schema type names to retrieve.\n\nSchema names from the OpenAPI components.schemas section (e.g., \"IUser\",\n\"IUser.ICreate\", \"IPost.IUpdate\").\n\nCRITICAL: DO NOT request the same type names that you have already\nrequested in previous calls." } }, required: [ "type", "typeNames" ], description: "Request to retrieve OpenAPI schema type definitions for context.\n\nThis type is used in the preliminary phase to request specific schema\ndefinitions from components.schemas for review or complementary generation." }, IAutoBePreliminaryGetPrismaSchemas: { type: "object", properties: { type: { "const": "getPrismaSchemas", description: "Type discriminator for the request.\n\nDetermines which action to perform: preliminary data retrieval or actual\ntask execution. Value \"getPrismaSchemas\" indicates this is a preliminary\ndata request for Prisma schemas." }, schemaNames: { type: "array", items: { type: "string" }, minItems: 1, description: "List of Prisma table names to retrieve.\n\nTable names from the Prisma schema file representing database entities\n(e.g., \"user\", \"post\", \"comment\").\n\nCRITICAL: DO NOT request the same schema names that you have already\nrequested in previous calls." } }, required: [ "type", "schemaNames" ], description: "Request to retrieve Prisma database schema definitions for context.\n\nThis type is used in the preliminary phase to request specific Prisma table\nschemas needed for generating type-safe API operations." }, "IAutoBeInterfacePrerequisiteApplication.IComplete": { type: "object", properties: { type: { "const": "complete", description: "Type discriminator for the request.\n\nDetermines which action to perform: preliminary data retrieval or actual\ntask execution. Value \"complete\" indicates this is the final task\nexecution request." }, operations: { type: "array", items: { $ref: "#/components/schemas/IAutoBeInterfacePrerequisiteApplication.IOperation" }, description: "Target operations requiring prerequisite analysis.\n\nEach operation will be analyzed for dependency requirements and returned\nwith appropriate prerequisites from Available API Operations." } }, required: [ "type", "operations" ], description: "Request to analyze and generate API operation prerequisites.\n\nExecutes prerequisite analysis to determine which Available API Operations\nmust be executed before each Target Operation based on resource creation\ndependencies and existence validations." }, "IAutoBeInterfacePrerequisiteApplication.IOperation": { type: "object", properties: { endpoint: { $ref: "#/components/schemas/AutoBeOpenApi.IEndpoint", description: "The API endpoint being analyzed.\n\nIdentifies the specific operation (method + path) that needs\nprerequisites." }, prerequisites: { type: "array", items: { $ref: "#/components/schemas/AutoBeOpenApi.IPrerequisite" }, description: "Required prerequisite operations.\n\nList of API operations that must be successfully executed before this\noperation can be performed. Based on resource creation dependencies and\nexistence validations from the analysis." } }, required: [ "endpoint", "prerequisites" ], description: "Operation with its analyzed prerequisite dependencies.\n\nRepresents a single API operation and its complete prerequisite chain\nneeded for successful execution." }, "AutoBeOpenApi.IPrerequisite": { type: "object", properties: { endpoint: { $ref: "#/components/schemas/AutoBeOpenApi.IEndpoint", description: "The API endpoint that must be called before the main operation.\n\nThis specifies the exact HTTP method and path of the prerequisite API.\nThe endpoint must be a valid operation defined elsewhere in the API\nspecification. Path parameters in the prerequisite endpoint can reference\nthe same parameters available in the main operation." }, description: { type: "string", description: "Clear description of why this prerequisite is required.\n\nThis description should explain:\n\n- What validation or check this prerequisite performs\n- What state or condition must be satisfied\n- What happens if this prerequisite fails\n- Any specific data from the prerequisite used by the main operation\n\nThe description helps developers understand the dependency relationship\nand aids in debugging when prerequisites fail.\n\nGuidelines for good descriptions:\n\n- Be specific about the requirement (e.g., \"must be in 'active' state\")\n- Explain business logic constraints (e.g., \"budget must not be exceeded\")\n- Explain data dependencies (e.g., \"provides pricing information needed\")\n- Keep it concise but complete\n\n> MUST be written in English. Never use other languages." } }, required: [ "endpoint", "description" ], description: "Prerequisite API operation dependency.\n\n`IPrerequisite` defines a dependency relationship between API operations,\nspecifying that certain endpoints must be successfully called before the\ncurrent operation can proceed. This ensures proper resource validation,\nstate checking, and data availability in complex API workflows.\n\n## CRITICAL WARNING: Authentication is NOT a Prerequisite\n\n**NEVER use prerequisites for authentication or authorization checks!**\n\nPrerequisites are ONLY for business logic dependencies such as:\n\n- Checking if a resource exists\n- Verifying resource state\n- Loading required data\n\nDo NOT create prerequisites for:\n\n- Login/authentication endpoints\n- Token validation\n- Permission checks\n- User authorization verification\n\nAuthentication is handled separately via the `authorizationActor` field on\nthe operation itself. Mixing authentication with business prerequisites\ncreates confusion and incorrect test scenarios.\n\n## Core Concept\n\nPrerequisites create an execution dependency graph for API operations. They\nexplicitly declare which APIs must succeed before attempting the current\noperation, preventing invalid states and ensuring data consistency.\n\n## Structure\n\nEach prerequisite consists of:\n\n1. **endpoint**: The API endpoint that must be called first\n2. **description**: Clear explanation of why this prerequisite is required\n\n## Common Use Cases\n\n### 1. Resource Existence Validation\n\n```typescript\n{\n \"endpoint\": { \"path\": \"/users/{userId}\", \"method\": \"get\" },\n \"description\": \"User must exist before updating their profile\"\n}\n```\n\n### 2. Parent-Child Relationships\n\n```typescript\n{\n \"endpoint\": { \"path\": \"/posts/{postId}\", \"method\": \"get\" },\n \"description\": \"Post must exist before adding comments\"\n}\n```\n\n### 3. State Prerequisites\n\n```typescript\n{\n \"endpoint\": { \"path\": \"/orders/{orderId}/status\", \"method\": \"get\" },\n \"description\": \"Order must be in 'confirmed' state before shipping\"\n}\n```\n\n### 4. Business Logic Dependencies\n\n```typescript\n{\n \"endpoint\": {\n \"path\": \"/inventory/{productId}/stock\",\n \"method\": \"get\"\n },\n \"description\": \"Product must have sufficient stock before creating order\"\n}\n```\n\n## Implementation Guidelines\n\n1. **Clear Descriptions**: Always explain WHY the prerequisite is needed\n2. **Minimal Dependencies**: Only include truly necessary prerequisites\n3. **Logical Order**: If multiple prerequisites exist, order them logically\n4. **Error Context**: Description should help understand failure scenarios\n5. **No Authentication**: Prerequisites must NEVER be authentication checks\n\n## Test Generation Usage\n\nThe Test Agent utilizes prerequisites to:\n\n- Set up test data in the correct sequence\n- Generate realistic test scenarios\n- Create both positive and negative test cases\n- Ensure proper cleanup in reverse dependency order\n\n## Best Practices\n\n- Keep prerequisite chains as short as possible for performance\n- Consider caching prerequisite results when safe to do so\n- Ensure prerequisite descriptions are specific, not generic\n- Validate that circular dependencies don't exist\n- Document any side effects of prerequisite calls\n- NEVER use for authentication/authorization validation" } } }, functions: [ { name: "process", async: false, parameters: [ { name: "props", description: " Request containing either preliminary data request or complete\ntask", required: true, schema: { $ref: "#/components/schemas/IAutoBeInterfacePrerequisiteApplication.IProps" } } ], description: "Process prerequisite analysis task or preliminary data requests.\n\nAnalyzes each operation's dependencies and returns complete list with\nrequired prerequisite chains based on resource relationships." } ] }, source: SOURCE, kinds: [ "analysisFiles", "prismaSchemas", "interfaceOperations", "interfaceSchemas", ], state: ctx.state(), all: { interfaceOperations: props.document.operations, interfaceSchemas: props.document.components.schemas, }, local: { interfaceOperations: props.includes, }, }); return yield preliminary.orchestrate(ctx, (out) => __awaiter(this, void 0, void 0, function* () { var _a, _b; const pointer = { value: null, }; const result = yield ctx.conversate(Object.assign({ source: SOURCE, controller: createController({ model: ctx.model, document: props.document, dict: props.dict, includes: props.includes, prerequisitesNotFound: props.prerequisitesNotFound, preliminary, build: (next) => { pointer.value = next; }, }), enforceFunctionCall: true, promptCacheKey: props.promptCacheKey }, (0, transformInterfacePrerequisiteHistory_1.transformInterfacePrerequisiteHistory)({ document: props.document, includes: props.includes, preliminary, }))); if (pointer.value !== null) { props.progress.completed += pointer.value.length; ctx.dispatch({ type: SOURCE, id: (0, uuid_1.v7)(), created_at: new Date().toISOString(), metric: result.metric, tokenUsage: result.tokenUsage, operations: pointer.value, total: props.progress.total, completed: props.progress.completed, step: (_b = (_a = ctx.state().prisma) === null || _a === void 0 ? void 0 : _a.step) !== null && _b !== void 0 ? _b : 0, }); return out(result)(pointer.value); } return out(result)(null); })); }); } function createController(props) { (0, assertSchemaModel_1.assertSchemaModel)(props.model); const validate = (next) => { const result = (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _iu0(input.request)); const _io1 = input => "getAnalysisFiles" === input.type && (Array.isArray(input.fileNames) && (1 <= input.fileNames.length && input.fileNames.every(elem => "string" === typeof elem))); const _io2 = input => "getInterfaceOperations" === input.type && (Array.isArray(input.endpoints) && (1 <= input.endpoints.length && input.endpoints.every(elem => "object" === typeof elem && null !== elem && _io3(elem)))); const _io3 = input => "string" === typeof input.path && RegExp("^\\/[a-zA-Z0-9\\/_{}.-]*$").test(input.path) && ("get" === input.method || "post" === input.method || "put" === input.method || "delete" === input.method || "patch" === input.method); const _io4 = input => "getInterfaceSchemas" === input.type && (Array.isArray(input.typeNames) && (1 <= input.typeNames.length && input.typeNames.every(elem => "string" === typeof elem))); const _io5 = input => "getPrismaSchemas" === input.type && (Array.isArray(input.schemaNames) && (1 <= input.schemaNames.length && input.schemaNames.every(elem => "string" === typeof elem))); const _io6 = input => "complete" === input.type && (Array.isArray(input.operations) && input.operations.every(elem => "object" === typeof elem && null !== elem && _io7(elem))); const _io7 = input => "object" === typeof input.endpoint && null !== input.endpoint && _io3(input.endpoint) && (Array.isArray(input.prerequisites) && input.prerequisites.every(elem => "object" === typeof elem && null !== elem && _io8(elem))); const _io8 = input => "object" === typeof input.endpoint && null !== input.endpoint && _io3(input.endpoint) && "string" === typeof input.description; const _iu0 = input => (() => { if ("getAnalysisFiles" === input.type) return _io1(input); else if ("getInterfaceOperations" === input.type) return _io2(input); else if ("getInterfaceSchemas" === input.type) return _io4(input); else if ("getPrismaSchemas" === input.type) return _io5(input); else if ("complete" === input.type) return _io6(input); else return false; })(); const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.thinking || _report(_exceptionable, { path: _path + ".thinking", expected: "string", value: input.thinking }), ("object" === typeof input.request && null !== input.request || _report(_exceptionable, { path: _path + ".request", expected: "(IAutoBeInterfacePrerequisiteApplication.IComplete | IAutoBePreliminaryGetAnalysisFiles | IAutoBePreliminaryGetInterfaceOperations | IAutoBePreliminaryGetInterfaceSchemas | IAutoBePreliminaryGetPrismaSchemas)", value: input.request })) && _vu0(input.request, _path + ".request", true && _exceptionable) || _report(_exceptionable, { path: _path + ".request", expected: "(IAutoBeInterfacePrerequisiteApplication.IComplete | IAutoBePreliminaryGetAnalysisFiles | IAutoBePreliminaryGetInterfaceOperations | IAutoBePreliminaryGetInterfaceSchemas | IAutoBePreliminaryGetPrismaSchemas)", value: input.request })].every(flag => flag); const _vo1 = (input, _path, _exceptionable = true) => ["getAnalysisFiles" === input.type || _report(_exceptionable, { path: _path + ".type", expected: "\"getAnalysisFiles\"", value: input.type }), (Array.isArray(input.fileNames) || _report(_exceptionable, { path: _path + ".fileNames", expected: "(Array<string> & MinItems<1>)", value: input.fileNames })) && ((1 <= input.fileNames.length || _report(_exceptionable, { path: _path + ".fileNames", expected: "Array<> & MinItems<1>", value: input.fileNames })) && input.fileNames.map((elem, _index7) => "string" === typeof elem || _report(_exceptionable, { path: _path + ".fileNames[" + _index7 + "]", expected: "string", value: elem })).every(flag => flag)) || _report(_exceptionable, { path: _path + ".fileNames", expected: "(Array<string> & MinItems<1>)", value: input.fileNames })].every(flag => flag); const _vo2 = (input, _path, _exceptionable = true) => ["getInterfaceOperations" === input.type || _report(_exceptionable, { path: _path + ".type", expected: "\"getInterfaceOperations\"", value: input.type }), (Array.isArray(input.endpoints) || _report(_exceptionable, { path: _path + ".endpoints", expected: "(Array<AutoBeOpenApi.IEndpoint> & MinItems<1>)", value: input.endpoints })) && ((1 <= input.endpoints.length || _report(_exceptionable, { path: _path + ".endpoints", expected: "Array<> & MinItems<1>", value: input.endpoints })) && input.endpoints.map((elem, _index8) => ("object" === typeof elem && null !== elem || _report(_exceptionable, { path: _path + ".endpoints[" + _index8 + "]", expected: "AutoBeOpenApi.IEndpoint", value: elem })) && _vo3(elem, _path + ".endpoints[" + _index8 + "]", true && _exceptionable) || _report(_exceptionable, { path: _path + ".endpoints[" + _index8 + "]", expected: "AutoBeOpenApi.IEndpoint", value: elem })).every(flag => flag)) || _report(_exceptionable, { path: _path + ".endpoints", expected: "(Array<AutoBeOpenApi.IEndpoint> & MinItems<1>)", value: input.endpoints })].every(flag => flag); const _vo3 = (input, _path, _exceptionable = true) => ["string" === typeof input.path && (RegExp("^\\/[a-zA-Z0-9\\/_{}.-]*$").test(input.path) || _report(_exceptionable, { path: _path + ".path", expected: "string & Pattern<\"^\\\\/[a-zA-Z0-9\\\\/_{}.-]*$\">", value: input.path })) || _report(_exceptionable, { path: _path + ".path", expected: "(string & Pattern<\"^\\\\/[a-zA-Z0-9\\\\/_{}.-]*$\">)", value: input.path }), "get" === input.method || "post" === input.method || "put" === input.method || "delete" === input.method || "patch" === input.method || _report(_exceptionable, { path: _path + ".method", expected: "(\"delete\" | \"get\" | \"patch\" | \"post\" | \"put\")", value: input.method })].every(flag => flag); const _vo4 = (input, _path, _exceptionable = true) => ["getInterfaceSchemas" === input.type || _report(_exceptionable, { path: _path + ".type", expected: "\"getInterfaceSchemas\"", value: input.type }), (Array.isArray(input.typeNames) || _report(_exceptionable, { path: _path + ".typeNames", expected: "(Array<string> & MinItems<1>)", value: input.typeNames })) && ((1 <= input.typeNames.length || _report(_exceptionable, { path: _path + ".typeNames", expected: "Array<> & MinItems<1>", value: input.typeNames })) && input.typeNames.map((elem, _index9) => "string" === typeof elem || _report(_exceptionable, { path: _path + ".typeNames[" + _index9 + "]", expected: "string", value: elem })).every(flag => flag)) || _report(_exceptionable, { path: _path + ".typeNames", expected: "(Array<string> & MinItems<1>)", value: input.typeNames })].every(flag => flag); const _vo5 = (input, _path, _exceptionable = true) => ["getPrismaSchemas" === input.type || _report(_exceptionable, { path: _path + ".type", expected: "\"getPrismaSchemas\"", value: input.type }), (Array.isArray(input.schemaNames) || _report(_exceptionable, { path: _path + ".schemaNames", expected: "(Array<string> & MinItems<1>)", value: input.schemaNames })) && ((1 <= input.schemaNames.length || _report(_exceptionable, { path: _path + ".schemaNames", expected: "Array<> & MinItems<1>", value: input.schemaNames })) && input.schemaNames.map((elem, _index10) => "string" === typeof elem || _report(_exceptionable, { path: _path + ".schemaNames[" + _index10 + "]", expected: "string", value: elem })).every(flag => flag)) || _report(_exceptionable, { path: _path + ".schemaNames", expected: "(Array<string> & MinItems<1>)", value: input.schemaNames })].every(flag => flag); const _vo6 = (input, _path, _exceptionable = true) => ["complete" === input.type || _report(_exceptionable, { path: _path + ".type", expected: "\"complete\"", value: input.type }), (Array.isArray(input.operations) || _report(_exceptionable, { path: _path + ".operations", expected: "Array<IAutoBeInterfacePrerequisiteApplication.IOperation>", value: input.operations })) && input.operations.map((elem, _index11) => ("object" === typeof elem && null !== elem || _report(_exceptionable, { path: _path + ".operations[" + _index11 + "]", expected: "IAutoBeInterfacePrerequisiteApplication.IOperation", value: elem })) && _vo7(elem, _path + ".operations[" + _index11 + "]", true && _exceptionable) || _report(_exceptionable, { path: _path + ".operations[" + _index11 + "]", expected: "IAutoBeInterfacePrerequisiteApplication.IOperation", value: elem })).every(flag => flag) || _report(_exceptionable, { path: _path + ".operations", expected: "Array<IAutoBeInterfacePrerequisiteApplication.IOperation>", value: input.operations })].every(flag => flag); const _vo7 = (input, _path, _exceptionable = true) => [("object" === typeof input.endpoint && null !== input.endpoint || _report(_exceptionable, { path: _path + ".endpoint", expected: "AutoBeOpenApi.IEndpoint", value: input.endpoint })) && _vo3(input.endpoint, _path + ".endpoint", true && _exceptionable) || _report(_exceptionable, { path: _path + ".endpoint", expected: "AutoBeOpenApi.IEndpoint", value: input.endpoint }), (Array.isArray(input.prerequisites) || _report(_exceptionable, { path: _path + ".prerequisites", expected: "Array<AutoBeOpenApi.IPrerequisite>", value: input.prerequisites })) && input.prerequisites.map((elem, _index12) => ("object" === typeof elem && null !== elem || _report(_exceptionable, { path: _path + ".prerequisites[" + _index12 + "]", expected: "AutoBeOpenApi.IPrerequisite", value: elem })) && _vo8(elem, _path + ".prerequisites[" + _index12 + "]", true && _exceptionable) || _report(_exceptionable, { path: _path + ".prerequisites[" + _index12 + "]", expected: "AutoBeOpenApi.IPrerequisite", value: elem })).every(flag => flag) || _report(_exceptionable, { path: _path + ".prerequisites", expected: "Array<AutoBeOpenApi.IPrerequisite>", value: input.prerequisites })].every(flag => flag); const _vo8 = (input, _path, _exceptionable = true) => [("object" === typeof input.endpoint && null !== input.endpoint || _report(_exceptionable, { path: _path + ".endpoint", expected: "AutoBeOpenApi.IEndpoint", value: input.endpoint })) && _vo3(input.endpoint, _path + ".endpoint", true && _exceptionable) || _report(_exceptionable, { path: _path + ".endpoint", expected: "AutoBeOpenApi.IEndpoint", value: input.endpoint }), "string" === typeof input.description || _report(_exceptionable, { path: _path + ".description", expected: "string", value: input.description })].every(flag => flag); const _vu0 = (input, _path, _exceptionable = true) => (() => { if ("getAnalysisFiles" === input.type) return _vo1(input, _path, true && _exceptionable); else if ("getInterfaceOperations" === input.type) return _vo2(input, _path, true && _exceptionable); else if ("getInterfaceSchemas" === input.type) return _vo4(input, _path, true && _exceptionable); else if ("getPrismaSchemas" === input.type) return _vo5(input, _path, true && _exceptionable); else if ("complete" === input.type) return _vo6(input, _path, true && _exceptionable); else return _report(_exceptionable, { path: _path, expected: "(IAutoBePreliminaryGetAnalysisFiles | IAutoBePreliminaryGetInterfaceOperations | IAutoBePreliminaryGetInterfaceSchemas | IAutoBePreliminaryGetPrismaSchemas | IAutoBeInterfacePrerequisiteApplication.IComplete)", value: input }); })(); const __is = input => "object" === typeof input && null !== input && _io0(input); let errors; let _report; return input => { if (false === __is(input)) { errors = []; _report = __typia_transform__validateReport._validateReport(errors); ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, { path: _path + "", expected: "IAutoBeInterfacePrerequisiteApplication.IProps", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "IAutoBeInterfacePrerequisiteApplication.IProps", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })()(next); if (result.success === false) return result; else if (result.data.request.type !== "complete") return props.preliminary.validate({ thinking: result.data.thinking, request: result.data.request, }); const operations = result.data.request.operations; const filteredOperations = []; const errors = []; props.includes.forEach((el) => { // Find the matched operation in the includes const matched = operations.find((op) => op.endpoint.method === el.method && op.endpoint.path === el.path); // Remove duplicate operations in Prerequisites if (matched) { const prerequisites = new Map(); matched.prerequisites.forEach((op) => { if (prerequisites.get(op.endpoint.method + op.endpoint.path) !== undefined) { return; } prerequisites.set(op.endpoint.method + op.endpoint.path, op); }); matched.prerequisites = Array.from(prerequisites.values()); filteredOperations.push(matched); } }); filteredOperations.forEach((op, i) => { op.prerequisites.forEach((p, j) => { if (props.dict.has(p.endpoint) === false) { errors.push({ value: p.endpoint, path: `$input.request.operations[${i}].prerequisites[${j}].endpoint`, expected: "AutoBeOpenApi.IEndpoint", description: props.prerequisitesNotFound, }); } if (p.endpoint.method === op.endpoint.method && p.endpoint.path === op.endpoint.path) { errors.push({ value: p.endpoint, path: `$input.request.operations[${i}].prerequisites[${j}].endpoint`, expected: "AutoBeOpenApi.IEndpoint", description: "Self-reference is not allowed.", }); } }); }); return errors.length === 0 ? { success: true, data: Object.assign(Object.assign({}, result.data), { request: Object.assign(Object.assign({}, result.data.request), { operations: filteredOperations }) }), } : { success: false, data: Object.assign(Object.assign({}, result.data), { request: Object.assign(Object.assign({}, result.data.request), { operations: filteredOperations }) }), errors, }; }; const application = collection[props.model === "chatgpt" ? "chatgpt" : props.model === "gemini" ? "gemini" : "claude"](validate); return { protocol: "class", name: SOURCE, application, execute: { process: (next) => {