UNPKG

@autobe/agent

Version:

AI backend server code generator

395 lines 28.5 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.orchestratePrismaComponents = orchestratePrismaComponents; const __typia_transform__validateReport = __importStar(require("typia/lib/internal/_validateReport.js")); const core_1 = require("@agentica/core"); const typia_1 = __importDefault(require("typia")); const uuid_1 = require("uuid"); const assertSchemaModel_1 = require("../../context/assertSchemaModel"); const transformPrismaComponentsHistories_1 = require("./transformPrismaComponentsHistories"); function orchestratePrismaComponents(ctx_1) { return __awaiter(this, arguments, void 0, function* (ctx, content = "Please extract files and tables from the given documents.") { var _a, _b, _c, _d, _e, _f; const start = new Date(); const pointer = { value: null, }; const prefix = (_b = (_a = ctx.state().analyze) === null || _a === void 0 ? void 0 : _a.prefix) !== null && _b !== void 0 ? _b : null; const agentica = new core_1.MicroAgentica({ model: ctx.model, vendor: ctx.vendor, config: Object.assign(Object.assign({}, ((_c = ctx.config) !== null && _c !== void 0 ? _c : {})), { executor: { describe: null, } }), histories: (0, transformPrismaComponentsHistories_1.transformPrismaComponentsHistories)(ctx.state(), prefix), controllers: [ createApplication({ model: ctx.model, build: (next) => { var _a; (_a = pointer.value) !== null && _a !== void 0 ? _a : (pointer.value = { components: [], }); pointer.value.components.push(...next.components); }, }), ], }); const histories = yield agentica .conversate(content) .finally(() => { const tokenUsage = agentica.getTokenUsage(); ctx.usage().record(tokenUsage, ["prisma"]); }); if (((_d = histories.at(-1)) === null || _d === void 0 ? void 0 : _d.type) === "assistantMessage") return Object.assign(Object.assign({}, histories.at(-1)), { created_at: start.toISOString(), completed_at: new Date().toISOString(), id: (0, uuid_1.v4)() }); else if (pointer.value === null) { throw new Error("Failed to extract files and tables."); // unreachable } return { type: "prismaComponents", created_at: start.toISOString(), components: pointer.value.components, step: (_f = (_e = ctx.state().analyze) === null || _e === void 0 ? void 0 : _e.step) !== null && _f !== void 0 ? _f : 0, }; }); } function createApplication(props) { (0, assertSchemaModel_1.assertSchemaModel)(props.model); const application = collection[props.model]; return { protocol: "class", name: "Prisma Extract Files and Tables", application, execute: { extractComponents: (next) => { props.build(next); }, }, }; } const claude = { model: "claude", options: { reference: true, separate: null }, functions: [ { name: "extractComponents", parameters: { description: " - Configuration object containing the file-to-table mapping\nstructure\n\n------------------------------\n\nCurrent Type: {@link IExtractComponentsProps}", type: "object", properties: { components: { description: "Maps Prisma schema filenames to their contained database tables.\n\n**Structure:**\n\n- Key: Prisma schema filename with .prisma extension\n- Value: Array of table names defined in that file\n\n**Example:**\n\n```typescript\n{\n {\n filename: \"schema-01-users.prisma\",\n tables: [\"user\", \"admin\", \"moderator\", \"user_profile\", \"user_settings\"]\n },\n {\n filename: \"schema-02-articles.prisma\",\n tables: [\"article\", \"article_snapshot\"]\n },\n {\n filename: \"schema-03-comments.prisma\",\n tables: [\"comment\", \"comment_like\"]\n }\n}\n```\n\n**Notes:**\n\n- Table names must match exact Prisma model names (case-sensitive)\n- Keep mapping synchronized with actual schema files\n- Use consistent naming convention for files", type: "array", items: { $ref: "#/$defs/AutoBePrisma.IComponent" } } }, required: [ "components" ], additionalProperties: false, $defs: { "AutoBePrisma.IComponent": { description: "Interface representing a logical grouping of database tables organized by\nbusiness domain for schema file generation.\n\nComponents provide a systematic way to organize database tables into\ncoherent groups following domain-driven design principles. Each component\nrepresents a specific business domain or functional area that will be\ngenerated as a separate Prisma schema file, ensuring maintainable and\nlogically structured database architecture.\n\nThis interface is primarily used during the database design phase when the\nPrisma agent analyzes requirements and determines the complete scope of\ntables needed, then organizes them into logical groups based on business\nrelationships and functional dependencies.\n\n## Usage in Schema Generation Process\n\nComponents serve as the blueprint for generating multiple Prisma schema\nfiles:\n\n1. **Requirements Analysis**: AI agent identifies all required tables from\n business requirements\n2. **Domain Grouping**: Tables are organized into components based on business\n domains and functional relationships\n3. **File Generation**: Each component becomes a separate .prisma file\n containing related models\n4. **Dependency Management**: Components are ordered to handle cross-domain\n relationships properly\n\n## Domain Organization Examples\n\nBased on typical business applications, components commonly include:\n\n- **Systematic**: Core system tables (channels, sections, configurations)\n- **Actors**: User management (customers, citizens, administrators)\n- **Sales**: Product catalog and sales entities\n- **Carts**: Shopping cart and item management\n- **Orders**: Order processing and fulfillment\n- **Coupons**: Discount and promotion systems\n- **Coins**: Digital currency and mileage systems\n- **Inquiries**: Customer support and FAQ systems\n- **Favorites**: User preference and wishlist management\n- **Articles**: Content management and BBS systems\n\n## Relationship to {@link AutoBePrisma.IFile}\n\nEach IComponent serves as a blueprint for generating one IFile during the\nschema generation process. The component's metadata (filename, namespace,\ntables) is used to structure the actual Prisma schema file with proper\nmodels, relationships, and indexes.", type: "object", properties: { filename: { description: "Target filename for the Prisma schema file containing this component's\ntables.\n\nFollows the naming convention `schema-{number}-{domain}.prisma` where the\nnumber indicates dependency order and domain represents the business\narea.", type: "string", pattern: "^[a-zA-Z0-9._-]+\\.prisma$" }, namespace: { description: "Business domain namespace that groups related models.\n\nUsed in Prisma documentation comments as \"@\\namespace directive\".\nExamples from uploaded schemas: \"Systematic\", \"Actors\", \"Sales\", \"Carts\",\n\"Orders\", \"Coupons\", \"Coins\", \"Inquiries\", \"Favorites\", \"Articles\"", type: "string" }, tables: { description: "Array of table names that will be included in this component's schema\nfile.\n\nContains all database table names that belong to this business domain,\nensuring logical grouping and proper organization of related data\nstructures.", type: "array", items: { type: "string", pattern: "^[a-z][a-z0-9_]*$" }, minItems: 1 } }, required: [ "filename", "namespace", "tables" ] } } }, description: "Extracts and organizes database schema files with their corresponding table\ndefinitions.\n\nProcesses Prisma schema files and maps each file to its contained database\ntables, enabling structured organization of schemas across multiple files\nfor large projects.", validate: (() => { const _io0 = input => Array.isArray(input.components) && input.components.every(elem => "object" === typeof elem && null !== elem && _io1(elem)); const _io1 = input => "string" === typeof input.filename && RegExp("^[a-zA-Z0-9._-]+\\.prisma$").test(input.filename) && "string" === typeof input.namespace && (Array.isArray(input.tables) && (1 <= input.tables.length && input.tables.every(elem => "string" === typeof elem && RegExp("^[a-z][a-z0-9_]*$").test(elem)))); const _vo0 = (input, _path, _exceptionable = true) => [(Array.isArray(input.components) || _report(_exceptionable, { path: _path + ".components", expected: "Array<AutoBePrisma.IComponent>", value: input.components })) && input.components.map((elem, _index3) => ("object" === typeof elem && null !== elem || _report(_exceptionable, { path: _path + ".components[" + _index3 + "]", expected: "AutoBePrisma.IComponent", value: elem })) && _vo1(elem, _path + ".components[" + _index3 + "]", true && _exceptionable) || _report(_exceptionable, { path: _path + ".components[" + _index3 + "]", expected: "AutoBePrisma.IComponent", value: elem })).every(flag => flag) || _report(_exceptionable, { path: _path + ".components", expected: "Array<AutoBePrisma.IComponent>", value: input.components })].every(flag => flag); const _vo1 = (input, _path, _exceptionable = true) => ["string" === typeof input.filename && (RegExp("^[a-zA-Z0-9._-]+\\.prisma$").test(input.filename) || _report(_exceptionable, { path: _path + ".filename", expected: "string & Pattern<\"^[a-zA-Z0-9._-]+\\\\.prisma$\">", value: input.filename })) || _report(_exceptionable, { path: _path + ".filename", expected: "(string & Pattern<\"^[a-zA-Z0-9._-]+\\\\.prisma$\">)", value: input.filename }), "string" === typeof input.namespace || _report(_exceptionable, { path: _path + ".namespace", expected: "string", value: input.namespace }), (Array.isArray(input.tables) || _report(_exceptionable, { path: _path + ".tables", expected: "(Array<string & Pattern<\"^[a-z][a-z0-9_]*$\">> & MinItems<1>)", value: input.tables })) && ((1 <= input.tables.length || _report(_exceptionable, { path: _path + ".tables", expected: "Array<> & MinItems<1>", value: input.tables })) && input.tables.map((elem, _index4) => "string" === typeof elem && (RegExp("^[a-z][a-z0-9_]*$").test(elem) || _report(_exceptionable, { path: _path + ".tables[" + _index4 + "]", expected: "string & Pattern<\"^[a-z][a-z0-9_]*$\">", value: elem })) || _report(_exceptionable, { path: _path + ".tables[" + _index4 + "]", expected: "(string & Pattern<\"^[a-z][a-z0-9_]*$\">)", value: elem })).every(flag => flag)) || _report(_exceptionable, { path: _path + ".tables", expected: "(Array<string & Pattern<\"^[a-z][a-z0-9_]*$\">> & MinItems<1>)", value: input.tables })].every(flag => flag); 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: "IExtractComponentsProps", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "IExtractComponentsProps", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() } ] }; const collection = { chatgpt: { model: "chatgpt", options: { reference: true, strict: false, separate: null }, functions: [ { name: "extractComponents", parameters: { description: " - Configuration object containing the file-to-table mapping\nstructure\n\n------------------------------\n\nCurrent Type: {@link IExtractComponentsProps}", type: "object", properties: { components: { description: "Maps Prisma schema filenames to their contained database tables.\n\n**Structure:**\n\n- Key: Prisma schema filename with .prisma extension\n- Value: Array of table names defined in that file\n\n**Example:**\n\n```typescript\n{\n {\n filename: \"schema-01-users.prisma\",\n tables: [\"user\", \"admin\", \"moderator\", \"user_profile\", \"user_settings\"]\n },\n {\n filename: \"schema-02-articles.prisma\",\n tables: [\"article\", \"article_snapshot\"]\n },\n {\n filename: \"schema-03-comments.prisma\",\n tables: [\"comment\", \"comment_like\"]\n }\n}\n```\n\n**Notes:**\n\n- Table names must match exact Prisma model names (case-sensitive)\n- Keep mapping synchronized with actual schema files\n- Use consistent naming convention for files", type: "array", items: { $ref: "#/$defs/AutoBePrisma.IComponent" } } }, required: [ "components" ], additionalProperties: false, $defs: { "AutoBePrisma.IComponent": { description: "Interface representing a logical grouping of database tables organized by\nbusiness domain for schema file generation.\n\nComponents provide a systematic way to organize database tables into\ncoherent groups following domain-driven design principles. Each component\nrepresents a specific business domain or functional area that will be\ngenerated as a separate Prisma schema file, ensuring maintainable and\nlogically structured database architecture.\n\nThis interface is primarily used during the database design phase when the\nPrisma agent analyzes requirements and determines the complete scope of\ntables needed, then organizes them into logical groups based on business\nrelationships and functional dependencies.\n\n## Usage in Schema Generation Process\n\nComponents serve as the blueprint for generating multiple Prisma schema\nfiles:\n\n1. **Requirements Analysis**: AI agent identifies all required tables from\n business requirements\n2. **Domain Grouping**: Tables are organized into components based on business\n domains and functional relationships\n3. **File Generation**: Each component becomes a separate .prisma file\n containing related models\n4. **Dependency Management**: Components are ordered to handle cross-domain\n relationships properly\n\n## Domain Organization Examples\n\nBased on typical business applications, components commonly include:\n\n- **Systematic**: Core system tables (channels, sections, configurations)\n- **Actors**: User management (customers, citizens, administrators)\n- **Sales**: Product catalog and sales entities\n- **Carts**: Shopping cart and item management\n- **Orders**: Order processing and fulfillment\n- **Coupons**: Discount and promotion systems\n- **Coins**: Digital currency and mileage systems\n- **Inquiries**: Customer support and FAQ systems\n- **Favorites**: User preference and wishlist management\n- **Articles**: Content management and BBS systems\n\n## Relationship to {@link AutoBePrisma.IFile}\n\nEach IComponent serves as a blueprint for generating one IFile during the\nschema generation process. The component's metadata (filename, namespace,\ntables) is used to structure the actual Prisma schema file with proper\nmodels, relationships, and indexes.", type: "object", properties: { filename: { description: "Target filename for the Prisma schema file containing this component's\ntables.\n\nFollows the naming convention `schema-{number}-{domain}.prisma` where the\nnumber indicates dependency order and domain represents the business\narea.\n\n\n@pattern ^[a-zA-Z0-9._-]+\\.prisma$", type: "string" }, namespace: { description: "Business domain namespace that groups related models.\n\nUsed in Prisma documentation comments as \"@\\namespace directive\".\nExamples from uploaded schemas: \"Systematic\", \"Actors\", \"Sales\", \"Carts\",\n\"Orders\", \"Coupons\", \"Coins\", \"Inquiries\", \"Favorites\", \"Articles\"", type: "string" }, tables: { description: "Array of table names that will be included in this component's schema\nfile.\n\nContains all database table names that belong to this business domain,\nensuring logical grouping and proper organization of related data\nstructures.\n\n\n@minItems 1", type: "array", items: { description: "@pattern ^[a-z][a-z0-9_]*$", type: "string" } } }, required: [ "filename", "namespace", "tables" ] } } }, description: "Extracts and organizes database schema files with their corresponding table\ndefinitions.\n\nProcesses Prisma schema files and maps each file to its contained database\ntables, enabling structured organization of schemas across multiple files\nfor large projects.", validate: (() => { const _io0 = input => Array.isArray(input.components) && input.components.every(elem => "object" === typeof elem && null !== elem && _io1(elem)); const _io1 = input => "string" === typeof input.filename && RegExp("^[a-zA-Z0-9._-]+\\.prisma$").test(input.filename) && "string" === typeof input.namespace && (Array.isArray(input.tables) && (1 <= input.tables.length && input.tables.every(elem => "string" === typeof elem && RegExp("^[a-z][a-z0-9_]*$").test(elem)))); const _vo0 = (input, _path, _exceptionable = true) => [(Array.isArray(input.components) || _report(_exceptionable, { path: _path + ".components", expected: "Array<AutoBePrisma.IComponent>", value: input.components })) && input.components.map((elem, _index3) => ("object" === typeof elem && null !== elem || _report(_exceptionable, { path: _path + ".components[" + _index3 + "]", expected: "AutoBePrisma.IComponent", value: elem })) && _vo1(elem, _path + ".components[" + _index3 + "]", true && _exceptionable) || _report(_exceptionable, { path: _path + ".components[" + _index3 + "]", expected: "AutoBePrisma.IComponent", value: elem })).every(flag => flag) || _report(_exceptionable, { path: _path + ".components", expected: "Array<AutoBePrisma.IComponent>", value: input.components })].every(flag => flag); const _vo1 = (input, _path, _exceptionable = true) => ["string" === typeof input.filename && (RegExp("^[a-zA-Z0-9._-]+\\.prisma$").test(input.filename) || _report(_exceptionable, { path: _path + ".filename", expected: "string & Pattern<\"^[a-zA-Z0-9._-]+\\\\.prisma$\">", value: input.filename })) || _report(_exceptionable, { path: _path + ".filename", expected: "(string & Pattern<\"^[a-zA-Z0-9._-]+\\\\.prisma$\">)", value: input.filename }), "string" === typeof input.namespace || _report(_exceptionable, { path: _path + ".namespace", expected: "string", value: input.namespace }), (Array.isArray(input.tables) || _report(_exceptionable, { path: _path + ".tables", expected: "(Array<string & Pattern<\"^[a-z][a-z0-9_]*$\">> & MinItems<1>)", value: input.tables })) && ((1 <= input.tables.length || _report(_exceptionable, { path: _path + ".tables", expected: "Array<> & MinItems<1>", value: input.tables })) && input.tables.map((elem, _index4) => "string" === typeof elem && (RegExp("^[a-z][a-z0-9_]*$").test(elem) || _report(_exceptionable, { path: _path + ".tables[" + _index4 + "]", expected: "string & Pattern<\"^[a-z][a-z0-9_]*$\">", value: elem })) || _report(_exceptionable, { path: _path + ".tables[" + _index4 + "]", expected: "(string & Pattern<\"^[a-z][a-z0-9_]*$\">)", value: elem })).every(flag => flag)) || _report(_exceptionable, { path: _path + ".tables", expected: "(Array<string & Pattern<\"^[a-z][a-z0-9_]*$\">> & MinItems<1>)", value: input.tables })].every(flag => flag); 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: "IExtractComponentsProps", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "IExtractComponentsProps", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() } ] }, claude, llama: claude, deepseek: claude, "3.1": claude, }; //# sourceMappingURL=orchestratePrismaComponent.js.map