@autobe/agent
Version:
AI backend server code generator
561 lines • 38.3 kB
JavaScript
"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 __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.orchestrateAnalyzeComposer = void 0;
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 enforceToolCall_1 = require("../../utils/enforceToolCall");
const orchestrateAnalyzeComposer = (ctx, setComposeInput) => {
var _a;
const controller = createController({
model: ctx.model,
execute: new AutoBeAnalyzeComposerApplication(),
preExecute: setComposeInput,
});
const agent = new core_1.MicroAgentica({
model: ctx.model,
vendor: ctx.vendor,
controllers: [controller],
config: {
locale: (_a = ctx.config) === null || _a === void 0 ? void 0 : _a.locale,
executor: {
describe: null,
},
},
histories: [
...ctx
.histories()
.filter((h) => h.type === "userMessage" || h.type === "assistantMessage"),
{
id: (0, uuid_1.v4)(),
type: "systemMessage",
text: "# Overview\n\n- You are the agent that determines the form of the entire document.\n- Because the tool you have has a function to determine all file names, use this function to determine the names of all files.\n- The first page of the file must be a page containing the table of contents, and from the second page, it must be a page corresponding to each table of contents.\n- Please clarify that the name of the table of contents page is the table of contents, such as `toc` or `table of content`.\n- Each document must begin with a number in turn, such as `00`, `01`, `02`, `03`.\n- Do not include database schema document.\n\n\n# \uD83D\uDCC4 Page Count System Prompt\n\nYou are responsible for determining the appropriate number of pages (documents) to generate.\n\n## Rules:\n\n1. **If the user explicitly requests a number of pages**, use that number *exactly*.\n2. **If the user does not specify a number**, determine a reasonable number of pages that satisfies the user's intent and scope.\n3. The final number of pages **must always match** the length of the `files` array.\n4. The total number of pages **must be greater than 1**.\n5. Always include a **Table of Contents** as one of the pages.\n6. \u2705 Example:\n\n * If the user asks for **3 pages**, then the total should be **4 pages**, including the Table of Contents.\n\n## Summary:\n\n> Total pages = (user-specified page count OR inferred appropriate count) + 1 (Table of Contents)\n\nDo **not** forget to include the Table of Contents when calculating the total number of documents." /* AutoBeSystemPromptConstant.ANALYZE_PLANNER */,
created_at: new Date().toISOString(),
},
],
});
(0, enforceToolCall_1.enforceToolCall)(agent);
return agent;
};
exports.orchestrateAnalyzeComposer = orchestrateAnalyzeComposer;
class AutoBeAnalyzeComposerApplication {
/**
* Compose project structure with roles and files.
*
* Design a list of roles and initial documents that you need to create for
* that requirement. Roles define team member responsibilities, while files
* define the documentation structure. These are managed separately. If you
* determine from the conversation that the user's requirements have not been
* fully gathered, you must stop the analysis and continue collecting the
* remaining requirements. In this case, you do not need to generate any files
* or roles. Simply pass an empty array to `input.files` and `input.roles`.
*
* @param input Prefix, roles, and files
* @returns
*/
compose(input) {
return input;
}
}
function createController(props) {
(0, assertSchemaModel_1.assertSchemaModel)(props.model);
const application = collection[props.model];
return {
protocol: "class",
name: "Compose",
application,
execute: {
compose: (input) => {
props.preExecute(input);
return props.execute.compose(input);
},
},
};
}
const claude = {
model: "claude",
options: {
reference: true,
separate: null
},
functions: [
{
name: "compose",
parameters: {
description: " Prefix, roles, and files\n\n------------------------------\n\nCurrent Type: {@link IComposeInput}",
type: "object",
properties: {
reason: {
description: "Reason for the analysis and composition of the project structure.",
type: "string"
},
prefix: {
description: "Prefix for file names and all prisma schema files, table, interface, and\nvariable names.",
type: "string"
},
roles: {
description: "Roles to be assigned for the project",
type: "array",
items: {
$ref: "#/$defs/AutoBeAnalyzeRole"
}
},
page: {
description: "If the user has requested a specific number of pages, enter that number.\nOtherwise, provide an appropriate number of documents needed to meet the\nuser's requirements. This number must always match the length of the files\nproperty, must be greater than 1, and must include the table of contents.\nFor example, if the user requests 3 pages, the total should be 4, including\nthe table of contents.",
type: "number"
},
files: {
description: "# Document files to be generated\n\nFile name must be English and it must contain the numbering and prefix.\n\nThese files represent business documentation that may include:\n\n- Business requirements and functional specifications\n- User journey mapping and use case scenarios\n- Business rules and workflow definitions\n- Service architecture and system design overview\n- Data flow and integration requirements\n- User roles and permission matrix\n- API endpoint specifications and contracts\n- Business logic and validation rules\n\nGenerate files based on actual requirements gathered from conversation. Do\nnot create unnecessary documentation - only generate what is needed to\nproperly define the business requirements and system specifications.\n\n# Page Length Rules\n\nThe number of documents must match the user's request, excluding the table\nof contents. For example, if the user requests 3 pages, a total of 4\ndocuments should be generated, including the table of contents. If the user\ndoes not specify a number, generate a sufficient number of documents to\nadequately support the service.",
type: "array",
items: {
$ref: "#/$defs/PickIFilereasonfilename"
}
}
},
required: [
"reason",
"prefix",
"roles",
"page",
"files"
],
additionalProperties: false,
$defs: {
AutoBeAnalyzeRole: {
description: "Interface representing a user role definition in the requirements analysis\nphase.\n\nThis interface defines authenticated user roles that will be used throughout\nthe application's authentication and authorization system. Each role\nrepresents a distinct type of user who can register, authenticate, and\ninteract with the system based on their specific permissions and\ncapabilities.\n\nThe roles defined here serve as the foundation for generating:\n\n- Prisma schema models for user authentication tables\n- API endpoint access control decorators\n- Role-based authorization logic in the business layer\n- Test scenarios for different user permission levels",
type: "object",
properties: {
name: {
description: "Unique identifier for the user role.\n\nThis name will be used as a reference throughout the generated codebase,\nincluding Prisma schema model names, authorization decorator parameters,\nand API documentation. Examples: \"customer\", \"admin\", \"seller\",\n\"moderator\".",
type: "string"
},
description: {
description: "Human-readable description of the role's permissions and capabilities.\n\nThis description helps the AI agents understand the business context and\naccess requirements for each role, guiding the generation of appropriate\nauthorization rules and API endpoint restrictions.",
type: "string"
}
},
required: [
"name",
"description"
]
},
PickIFilereasonfilename: {
description: "From T, pick a set of properties whose keys are in the union K",
type: "object",
properties: {
reason: {
description: "Describe briefly why you made this document, and if you have any plans for\nthe next one.",
type: "string"
},
filename: {
description: "Filename to generate or overwrite.",
type: "string",
pattern: "((.*)\\.md)$"
}
},
required: [
"reason",
"filename"
]
},
IComposeInput: {
type: "object",
properties: {
reason: {
description: "Reason for the analysis and composition of the project structure.",
type: "string"
},
prefix: {
description: "Prefix for file names and all prisma schema files, table, interface, and\nvariable names.",
type: "string"
},
roles: {
description: "Roles to be assigned for the project",
type: "array",
items: {
$ref: "#/$defs/AutoBeAnalyzeRole"
}
},
page: {
description: "If the user has requested a specific number of pages, enter that number.\nOtherwise, provide an appropriate number of documents needed to meet the\nuser's requirements. This number must always match the length of the files\nproperty, must be greater than 1, and must include the table of contents.\nFor example, if the user requests 3 pages, the total should be 4, including\nthe table of contents.",
type: "number"
},
files: {
description: "# Document files to be generated\n\nFile name must be English and it must contain the numbering and prefix.\n\nThese files represent business documentation that may include:\n\n- Business requirements and functional specifications\n- User journey mapping and use case scenarios\n- Business rules and workflow definitions\n- Service architecture and system design overview\n- Data flow and integration requirements\n- User roles and permission matrix\n- API endpoint specifications and contracts\n- Business logic and validation rules\n\nGenerate files based on actual requirements gathered from conversation. Do\nnot create unnecessary documentation - only generate what is needed to\nproperly define the business requirements and system specifications.\n\n# Page Length Rules\n\nThe number of documents must match the user's request, excluding the table\nof contents. For example, if the user requests 3 pages, a total of 4\ndocuments should be generated, including the table of contents. If the user\ndoes not specify a number, generate a sufficient number of documents to\nadequately support the service.",
type: "array",
items: {
$ref: "#/$defs/PickIFilereasonfilename"
}
}
},
required: [
"reason",
"prefix",
"roles",
"page",
"files"
]
}
}
},
output: {
$ref: "#/$defs/IComposeInput"
},
description: "Compose project structure with roles and files.\n\nDesign a list of roles and initial documents that you need to create for\nthat requirement. Roles define team member responsibilities, while files\ndefine the documentation structure. These are managed separately. If you\ndetermine from the conversation that the user's requirements have not been\nfully gathered, you must stop the analysis and continue collecting the\nremaining requirements. In this case, you do not need to generate any files\nor roles. Simply pass an empty array to `input.files` and `input.roles`.",
validate: (() => { const _io0 = input => "string" === typeof input.reason && "string" === typeof input.prefix && (Array.isArray(input.roles) && input.roles.every(elem => "object" === typeof elem && null !== elem && _io1(elem))) && "number" === typeof input.page && (Array.isArray(input.files) && input.files.every(elem => "object" === typeof elem && null !== elem && _io2(elem))); const _io1 = input => "string" === typeof input.name && "string" === typeof input.description; const _io2 = input => "string" === typeof input.reason && ("string" === typeof input.filename && RegExp(/(.*)\.md$/).test(input.filename)); const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.reason || _report(_exceptionable, {
path: _path + ".reason",
expected: "string",
value: input.reason
}), "string" === typeof input.prefix || _report(_exceptionable, {
path: _path + ".prefix",
expected: "string",
value: input.prefix
}), (Array.isArray(input.roles) || _report(_exceptionable, {
path: _path + ".roles",
expected: "Array<AutoBeAnalyzeRole>",
value: input.roles
})) && input.roles.map((elem, _index3) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
path: _path + ".roles[" + _index3 + "]",
expected: "AutoBeAnalyzeRole",
value: elem
})) && _vo1(elem, _path + ".roles[" + _index3 + "]", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".roles[" + _index3 + "]",
expected: "AutoBeAnalyzeRole",
value: elem
})).every(flag => flag) || _report(_exceptionable, {
path: _path + ".roles",
expected: "Array<AutoBeAnalyzeRole>",
value: input.roles
}), "number" === typeof input.page || _report(_exceptionable, {
path: _path + ".page",
expected: "number",
value: input.page
}), (Array.isArray(input.files) || _report(_exceptionable, {
path: _path + ".files",
expected: "Array<Pick<IFile, \"reason\" | \"filename\">>",
value: input.files
})) && input.files.map((elem, _index4) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
path: _path + ".files[" + _index4 + "]",
expected: "Pick<IFile, \"reason\" | \"filename\">",
value: elem
})) && _vo2(elem, _path + ".files[" + _index4 + "]", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".files[" + _index4 + "]",
expected: "Pick<IFile, \"reason\" | \"filename\">",
value: elem
})).every(flag => flag) || _report(_exceptionable, {
path: _path + ".files",
expected: "Array<Pick<IFile, \"reason\" | \"filename\">>",
value: input.files
})].every(flag => flag); const _vo1 = (input, _path, _exceptionable = true) => ["string" === typeof input.name || _report(_exceptionable, {
path: _path + ".name",
expected: "string",
value: input.name
}), "string" === typeof input.description || _report(_exceptionable, {
path: _path + ".description",
expected: "string",
value: input.description
})].every(flag => flag); const _vo2 = (input, _path, _exceptionable = true) => ["string" === typeof input.reason || _report(_exceptionable, {
path: _path + ".reason",
expected: "string",
value: input.reason
}), "string" === typeof input.filename && RegExp(/(.*)\.md$/).test(input.filename) || _report(_exceptionable, {
path: _path + ".filename",
expected: "`${string}.md`",
value: input.filename
})].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: "IComposeInput",
value: input
})) && _vo0(input, _path + "", true) || _report(true, {
path: _path + "",
expected: "IComposeInput",
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: "compose",
parameters: {
description: " Prefix, roles, and files\n\n------------------------------\n\nCurrent Type: {@link IComposeInput}",
type: "object",
properties: {
reason: {
description: "Reason for the analysis and composition of the project structure.",
type: "string"
},
prefix: {
description: "Prefix for file names and all prisma schema files, table, interface, and\nvariable names.",
type: "string"
},
roles: {
description: "Roles to be assigned for the project",
type: "array",
items: {
$ref: "#/$defs/AutoBeAnalyzeRole"
}
},
page: {
description: "If the user has requested a specific number of pages, enter that number.\nOtherwise, provide an appropriate number of documents needed to meet the\nuser's requirements. This number must always match the length of the files\nproperty, must be greater than 1, and must include the table of contents.\nFor example, if the user requests 3 pages, the total should be 4, including\nthe table of contents.",
type: "number"
},
files: {
description: "# Document files to be generated\n\nFile name must be English and it must contain the numbering and prefix.\n\nThese files represent business documentation that may include:\n\n- Business requirements and functional specifications\n- User journey mapping and use case scenarios\n- Business rules and workflow definitions\n- Service architecture and system design overview\n- Data flow and integration requirements\n- User roles and permission matrix\n- API endpoint specifications and contracts\n- Business logic and validation rules\n\nGenerate files based on actual requirements gathered from conversation. Do\nnot create unnecessary documentation - only generate what is needed to\nproperly define the business requirements and system specifications.\n\n# Page Length Rules\n\nThe number of documents must match the user's request, excluding the table\nof contents. For example, if the user requests 3 pages, a total of 4\ndocuments should be generated, including the table of contents. If the user\ndoes not specify a number, generate a sufficient number of documents to\nadequately support the service.",
type: "array",
items: {
$ref: "#/$defs/PickIFilereasonfilename"
}
}
},
required: [
"reason",
"prefix",
"roles",
"page",
"files"
],
additionalProperties: false,
$defs: {
AutoBeAnalyzeRole: {
description: "Interface representing a user role definition in the requirements analysis\nphase.\n\nThis interface defines authenticated user roles that will be used throughout\nthe application's authentication and authorization system. Each role\nrepresents a distinct type of user who can register, authenticate, and\ninteract with the system based on their specific permissions and\ncapabilities.\n\nThe roles defined here serve as the foundation for generating:\n\n- Prisma schema models for user authentication tables\n- API endpoint access control decorators\n- Role-based authorization logic in the business layer\n- Test scenarios for different user permission levels",
type: "object",
properties: {
name: {
description: "Unique identifier for the user role.\n\nThis name will be used as a reference throughout the generated codebase,\nincluding Prisma schema model names, authorization decorator parameters,\nand API documentation. Examples: \"customer\", \"admin\", \"seller\",\n\"moderator\".",
type: "string"
},
description: {
description: "Human-readable description of the role's permissions and capabilities.\n\nThis description helps the AI agents understand the business context and\naccess requirements for each role, guiding the generation of appropriate\nauthorization rules and API endpoint restrictions.",
type: "string"
}
},
required: [
"name",
"description"
]
},
PickIFilereasonfilename: {
description: "From T, pick a set of properties whose keys are in the union K",
type: "object",
properties: {
reason: {
description: "Describe briefly why you made this document, and if you have any plans for\nthe next one.",
type: "string"
},
filename: {
description: "Filename to generate or overwrite.\n\n\n@pattern ((.*)\\.md)$",
type: "string"
}
},
required: [
"reason",
"filename"
]
},
IComposeInput: {
type: "object",
properties: {
reason: {
description: "Reason for the analysis and composition of the project structure.",
type: "string"
},
prefix: {
description: "Prefix for file names and all prisma schema files, table, interface, and\nvariable names.",
type: "string"
},
roles: {
description: "Roles to be assigned for the project",
type: "array",
items: {
$ref: "#/$defs/AutoBeAnalyzeRole"
}
},
page: {
description: "If the user has requested a specific number of pages, enter that number.\nOtherwise, provide an appropriate number of documents needed to meet the\nuser's requirements. This number must always match the length of the files\nproperty, must be greater than 1, and must include the table of contents.\nFor example, if the user requests 3 pages, the total should be 4, including\nthe table of contents.",
type: "number"
},
files: {
description: "# Document files to be generated\n\nFile name must be English and it must contain the numbering and prefix.\n\nThese files represent business documentation that may include:\n\n- Business requirements and functional specifications\n- User journey mapping and use case scenarios\n- Business rules and workflow definitions\n- Service architecture and system design overview\n- Data flow and integration requirements\n- User roles and permission matrix\n- API endpoint specifications and contracts\n- Business logic and validation rules\n\nGenerate files based on actual requirements gathered from conversation. Do\nnot create unnecessary documentation - only generate what is needed to\nproperly define the business requirements and system specifications.\n\n# Page Length Rules\n\nThe number of documents must match the user's request, excluding the table\nof contents. For example, if the user requests 3 pages, a total of 4\ndocuments should be generated, including the table of contents. If the user\ndoes not specify a number, generate a sufficient number of documents to\nadequately support the service.",
type: "array",
items: {
$ref: "#/$defs/PickIFilereasonfilename"
}
}
},
required: [
"reason",
"prefix",
"roles",
"page",
"files"
]
}
}
},
output: {
$ref: "#/$defs/IComposeInput"
},
description: "Compose project structure with roles and files.\n\nDesign a list of roles and initial documents that you need to create for\nthat requirement. Roles define team member responsibilities, while files\ndefine the documentation structure. These are managed separately. If you\ndetermine from the conversation that the user's requirements have not been\nfully gathered, you must stop the analysis and continue collecting the\nremaining requirements. In this case, you do not need to generate any files\nor roles. Simply pass an empty array to `input.files` and `input.roles`.",
validate: (() => { const _io0 = input => "string" === typeof input.reason && "string" === typeof input.prefix && (Array.isArray(input.roles) && input.roles.every(elem => "object" === typeof elem && null !== elem && _io1(elem))) && "number" === typeof input.page && (Array.isArray(input.files) && input.files.every(elem => "object" === typeof elem && null !== elem && _io2(elem))); const _io1 = input => "string" === typeof input.name && "string" === typeof input.description; const _io2 = input => "string" === typeof input.reason && ("string" === typeof input.filename && RegExp(/(.*)\.md$/).test(input.filename)); const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.reason || _report(_exceptionable, {
path: _path + ".reason",
expected: "string",
value: input.reason
}), "string" === typeof input.prefix || _report(_exceptionable, {
path: _path + ".prefix",
expected: "string",
value: input.prefix
}), (Array.isArray(input.roles) || _report(_exceptionable, {
path: _path + ".roles",
expected: "Array<AutoBeAnalyzeRole>",
value: input.roles
})) && input.roles.map((elem, _index3) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
path: _path + ".roles[" + _index3 + "]",
expected: "AutoBeAnalyzeRole",
value: elem
})) && _vo1(elem, _path + ".roles[" + _index3 + "]", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".roles[" + _index3 + "]",
expected: "AutoBeAnalyzeRole",
value: elem
})).every(flag => flag) || _report(_exceptionable, {
path: _path + ".roles",
expected: "Array<AutoBeAnalyzeRole>",
value: input.roles
}), "number" === typeof input.page || _report(_exceptionable, {
path: _path + ".page",
expected: "number",
value: input.page
}), (Array.isArray(input.files) || _report(_exceptionable, {
path: _path + ".files",
expected: "Array<Pick<IFile, \"reason\" | \"filename\">>",
value: input.files
})) && input.files.map((elem, _index4) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
path: _path + ".files[" + _index4 + "]",
expected: "Pick<IFile, \"reason\" | \"filename\">",
value: elem
})) && _vo2(elem, _path + ".files[" + _index4 + "]", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".files[" + _index4 + "]",
expected: "Pick<IFile, \"reason\" | \"filename\">",
value: elem
})).every(flag => flag) || _report(_exceptionable, {
path: _path + ".files",
expected: "Array<Pick<IFile, \"reason\" | \"filename\">>",
value: input.files
})].every(flag => flag); const _vo1 = (input, _path, _exceptionable = true) => ["string" === typeof input.name || _report(_exceptionable, {
path: _path + ".name",
expected: "string",
value: input.name
}), "string" === typeof input.description || _report(_exceptionable, {
path: _path + ".description",
expected: "string",
value: input.description
})].every(flag => flag); const _vo2 = (input, _path, _exceptionable = true) => ["string" === typeof input.reason || _report(_exceptionable, {
path: _path + ".reason",
expected: "string",
value: input.reason
}), "string" === typeof input.filename && RegExp(/(.*)\.md$/).test(input.filename) || _report(_exceptionable, {
path: _path + ".filename",
expected: "`${string}.md`",
value: input.filename
})].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: "IComposeInput",
value: input
})) && _vo0(input, _path + "", true) || _report(true, {
path: _path + "",
expected: "IComposeInput",
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=orchestrateAnalyzeComposer.js.map