UNPKG

@autobe/agent

Version:

AI backend server code generator

968 lines (951 loc) 1.1 MB
import { MicroAgentica, AgenticaTokenUsage } from "@agentica/core"; import { hash, HashSet, HashMap, Semaphore } from "tstl"; import { v4 } from "uuid"; import * as __typia_transform__validateReport from "typia/lib/internal/_validateReport.js"; import "typia"; import * as __typia_transform__accessExpressionAsString from "typia/lib/internal/_accessExpressionAsString.js"; import { OpenApiTypeChecker, HttpMigration } from "@samchon/openapi"; import { OpenApiV3_1Emender } from "@samchon/openapi/lib/converters/OpenApiV3_1Emender"; import * as __typia_transform__isUniqueItems from "typia/lib/internal/_isUniqueItems.js"; function createAgenticaHistory(props) { if (props.history.type === "userMessage") return { ...props.history, toJSON: () => props.history }; else if (props.history.type === "assistantMessage") return { ...props.history, toJSON: () => props.history }; const operation = props.operations.find((op => op.function.name === props.history.type)); if (operation === undefined) return null; const partial = { id: props.history.id, created_at: props.history.created_at, type: "execute", arguments: { reason: props.history.reason }, value: { success: props.history.type === "analyze" || props.history.type === "interface" ? true : props.history.compiled.type === "success" } }; return { ...partial, protocol: operation.protocol, operation, toJSON: () => ({ ...partial, protocol: operation.protocol, operation: operation.toJSON() }) }; } function assertSchemaModel(model) { if (model === "gemini") throw new Error([ "Error on AutoBeAgent.constructor(): gemini is not supported", "because it does not follow standard JSON schema specification.", "@autobe requires union type (`oneOf` or `anyOf`) for backend code generation,", "but gemini has banned them. Please wait until when `@agentica`", "supports prompt based function calling which can detour gemini's", "restriction of JSON schema specification." ].join(" ")); } function enforceToolCall(agent) { agent.on("request", (event => { if (event.body.tools) event.body.tool_choice = "required"; if (event.body.parallel_tool_calls !== undefined) delete event.body.parallel_tool_calls; })); return agent; } class AutoBeAnalyzeFileSystem { constructor(fileMap = {}) { this.fileMap = fileMap; } async createOrUpdateFiles(input) { input.files.forEach((file => { this.fileMap[file.filename] = file.markdown; })); } async removeFile(input) { delete this.fileMap[input.filename]; } abort(_input) { return "OK"; } allFiles() { return this.fileMap; } } class AutoBeAnalyzeAgent { constructor(createReviewerAgentFn, ctx, pointer, filenames) { this.createReviewerAgentFn = createReviewerAgentFn; this.ctx = ctx; this.pointer = pointer; this.filenames = filenames; this.fileMap = {}; assertSchemaModel(ctx.model); const controller = createController$1({ model: ctx.model, execute: new AutoBeAnalyzeFileSystem(this.fileMap), build: async files => { var _a; (_a = this.pointer).value ?? (_a.value = { files: {} }); Object.assign(this.pointer.value.files, files); } }); this.createAnalyzeAgent = () => { const agent = new MicroAgentica({ controllers: [ controller ], model: ctx.model, vendor: ctx.vendor, config: { locale: ctx.config?.locale, executor: { describe: null } }, tokenUsage: ctx.usage(), histories: [ { id: v4(), created_at: (new Date).toISOString(), type: "systemMessage", text: "# Overview\nYou are the best planner.\nYou will write documents and hand it over to the developer.\nYou are only asked to fill out one document.\n\nLike revision_history.md, you should not write fakes for content that does not exist yet. If written, it is only allowed if there is a user's request directly.\n\nPlease converse with the user based on the following guidelines and example templates. \nYou have to make a plan for the success of the user, and it has to be written in great detail to make the business successful. \nYour performance is measured by your customer's success. \nYou should listen to the reviewer and not make any requests to the reviewer. \nIf the reviewer asks for changes, revise the entire document from top to bottom,\nincorporating both the existing content and the requested changes. Do not add only the new parts—integrate them into a full rewrite of the document. \nFor example, if you are asked to modify or expand 'internal_bulletin_board_service_plan.md',\ndo not create a document such as 'internal_bulletin_board_service_plan_expanded.md'. \nonly update 'internal_bulletin_board_service_plan.md' file. \n\nWrite a long document, but keep your answer short.\n\n# Number of documents that need to be created\nThe number of documents requested by the user, or the amount of documents sufficient for developers to develop\n\n# user information\n- user locale: {% User Locale %}\n\nCreate and review documents for your locale.\nIt must match the language of the user.\n\n# Documentation Style\nFor readability, even if the user requests it, a file should not exceed 3,000 characters. (The amount of text is measured in String(content).length)\nHyperlink features allow you to create more colorful documents.\n\nPlease make the file appropriate for user's language.\nDocuments and descriptions should be tailored to the language of the user.\n\nPlease refer to the document below. The document below has a total of 1,500 characters and should be longer.\nNever insert a question in the document.\n\n\n# abort\nIf you have no further requests or questions, immediately call the 'abort' function instead of replying with text. Never respond with additional text.\n\nWhen the reviewer determines the document is perfect and requires no more modifications, they must call the 'abort' function without hesitation.\n\n'abort' is a tool you must use to signal completion.\n\nDo not delay or avoid calling 'abort' once the document is complete.\n\nIf the reviewer says the document is complete but only one document out of multiple remains unfinished, do NOT call 'abort' yet.\n\nIf the reviewer requests creation or modification of any document other than the current assigned one, **ignore such requests** and continue focusing only on the current document. \nIn this case, the reviewer may call 'abort' to forcibly terminate the review.\n\nWrite a long document, but keep your answer short.".replace("{% User Locale %}", ctx.config?.locale ?? "en-US") }, { id: v4(), created_at: (new Date).toISOString(), type: "systemMessage", text: [ "# Guidelines", "If the user specifies the exact number of pages, please follow it precisely.", "You are the “Planning Expert (PlannerAgent)” system agent.\nYou take full responsibility for all planning activities—from product planning through requirements analysis, design, and documentation—and you have extensive experience drafting planning documents.\n\n────────────────────────────────────────────────\n1. Persona & Roles\n • **Planning Expert**: Establish business objectives, craft user scenarios, and develop a strategic roadmap \n • **Communication Specialist**: Use a friendly yet professional tone, actively engaging with stakeholders \n • **Documentation Specialist**: Follow a structured approach (Table of Contents → Detailed TOC → Final Document) and deliver outputs in Markdown\n\n2. Conversation-Driven Extraction Framework (WHY → WHAT → HOW)\n 1. **WHY (Reason for the Problem)**\n * “Why is this feature/project needed?” “What business or user problem does it solve?” \n * Ask questions to clearly gather background, KPIs, and success criteria \n 2. **WHAT (What to Solve)**\n * “What must be implemented?” “What are the key functional and non-functional requirements?” \n * Distinguish between functional vs. non-functional, organize business requirements and user scenarios \n 3. **HOW (How to Execute)**\n * “What flow and structure will the service follow?” “How should the data model and ERD be designed?”\n\n3. Scope & Constraints\n • Do **not** produce development-level documentation (backend, frontend, or infrastructure tech stacks). \n • API design, database structure, and architecture reviews should be suggested only at a high level from a planning perspective—avoid any detailed code or configuration references.\n\n4. Deliverable Structuring Guidelines\n 1. **Present the TOC First**\n * Propose only the top-level Table of Contents initially; generate detailed sub-headings after user approval \n * When sub-TOCs grow large, split them into separate Markdown files and interlink them \n 2. **Document Augmentation**\n * Each document may be continuously updated; you may pre-link to future documents as placeholders \n * Only use links to actual, existing document paths—external URLs that don’t exist are prohibited \n 3. **Document Components**\n * Include: Overview, Objectives, User Personas, User Journeys, Functional & Non-Functional Requirements, Acceptance Criteria, ERD \n * Use tables, lists, and diagrams (ASCII or Mermaid) wherever helpful\n\n5. Communication & Feedback\n • After each phase, summarize progress and ask for the user’s confirmation (e.g., “Shall we proceed with this TOC?”) \n • Upon completing a document: include a feedback prompt such as “Is there anything else to refine?”\n\n6. Final Deliverables\n • Provide everything in Markdown (`.md`) format \n • Include inter-document reference links \n • Do **not** finalize the “completed” version until the user has given explicit approval\n\n7. Review Loop\n • Use a while-loop process: after drafting any part, send it to the review agent and iterate until they grant approval. \n • Do not advance to the next section until the review agent confirms the current one meets quality standards.\n\n8. Approval & File Generation\n • Once the review agent approves the final draft, use the available tools to generate and export the document file. \n\n9. Iterative Writing Flow\n • Always start by proposing the top-level Table of Contents. \n • After TOC approval, draft the document one section (paragraph) at a time, submitting each for review before proceeding." ].join("\n") }, { id: v4(), created_at: (new Date).toISOString(), type: "systemMessage", text: [ "The following is the name of the entire file.", "Use it to build a table of contents.", this.filenames.map((filename => `- ${filename}`)), "", "However, do not touch other than the file you have to create." ].join("\n") } ] }); return enforceToolCall(agent); }; } async conversate(content, retry = 3) { if (retry === 0) { return "Abort due to excess retry count"; } const response = await this.createAnalyzeAgent().conversate(content); const lastMessage = response[response.length - 1]; if ("text" in lastMessage) { this.ctx.dispatch({ type: "analyzeWriteDocument", files: this.fileMap, created_at: (new Date).toISOString(), step: this.ctx.state().analyze?.step ?? 0 }); const aborted = lastMessage.type === "describe" && lastMessage.executes.some((el => { if (el.protocol === "class" && el.operation.function.name === "abort") { el.arguments; return true; } })); if (aborted === true) { return lastMessage.text; } const reviewer = this.createReviewerAgentFn(this.ctx, { query: content, files: JSON.stringify(this.fileMap) }); const filenames = Object.keys(this.fileMap).join(","); const command = `Please proceed with the review of these files only.: ${filenames}`; const response = await reviewer.conversate(command); const review = response.find((el => el.type === "assistantMessage")); if (review) { this.ctx.dispatch({ type: "analyzeReview", review: review.text, created_at: (new Date).toISOString(), step: this.ctx.state().analyze?.step ?? 0 }); return this.conversate(JSON.stringify({ user_query: content, message: `THIS IS ANSWER OF REVIEW AGENT. FOLLOW THIS INSTRUCTIONS. AND DON'T REQUEST ANYTHING.`, review: review.text }), retry - 1); } return `COMPLETE WITHOUT REVIEW`; } return "COMPLETE"; } } function createController$1(props) { assertSchemaModel(props.model); const application = collection$c[props.model]; return { protocol: "class", name: "Planning", application, execute: { removeFile: input => { const response = props.execute.removeFile(input); props.build(props.execute.allFiles()); return response; }, abort: input => { const response = props.execute.abort(input); props.build(props.execute.allFiles()); return response; }, createOrUpdateFiles: input => { const response = props.execute.createOrUpdateFiles(input); props.build(props.execute.allFiles()); return response; } } }; } const claude$c = { model: "claude", options: { reference: true, separate: null }, functions: [ { name: "createOrUpdateFiles", parameters: { type: "object", properties: { files: { type: "array", items: { description: "Current Type: {@link IFile}", 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: { title: "Filename to generate or overwrite", description: "Filename to generate or overwrite.", type: "string", pattern: "((.*)\\.md)$" }, markdown: { description: 'Markdown file content. Only write the content of the file. Do not include\nany questions. This should contain only the contents of the file. Do not\nwrite down any questions or appreciation. For example, remove a sentence\nsuch as "Is it okay if we proceed with the table of contents? Please let me\nknow if there is anything to add or exclude from the table of contents!"', type: "string" } }, required: [ "reason", "filename", "markdown" ] }, minItems: 1 } }, required: [ "files" ], additionalProperties: false, $defs: {} }, validate: (() => { const _io0 = input => Array.isArray(input.files) && (1 <= input.files.length && input.files.every((elem => "object" === typeof elem && null !== elem && _io1(elem)))); const _io1 = input => "string" === typeof input.reason && ("string" === typeof input.filename && RegExp(/(.*)\.md$/).test(input.filename)) && "string" === typeof input.markdown; const _vo0 = (input, _path, _exceptionable = true) => [ (Array.isArray(input.files) || _report(_exceptionable, { path: _path + ".files", expected: "(Array<IFile> & MinItems<1>)", value: input.files })) && ((1 <= input.files.length || _report(_exceptionable, { path: _path + ".files", expected: "Array<> & MinItems<1>", value: input.files })) && input.files.map(((elem, _index2) => ("object" === typeof elem && null !== elem || _report(_exceptionable, { path: _path + ".files[" + _index2 + "]", expected: "IFile", value: elem })) && _vo1(elem, _path + ".files[" + _index2 + "]", _exceptionable) || _report(_exceptionable, { path: _path + ".files[" + _index2 + "]", expected: "IFile", value: elem }))).every((flag => flag))) || _report(_exceptionable, { path: _path + ".files", expected: "(Array<IFile> & MinItems<1>)", value: input.files }) ].every((flag => flag)); const _vo1 = (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 }), "string" === typeof input.markdown || _report(_exceptionable, { path: _path + ".markdown", expected: "string", value: input.markdown }) ].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: "__type", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "__type", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() }, { name: "removeFile", parameters: { description: "Description of the current {@link PickIFilefilename} type:\n\n> From T, pick a set of properties whose keys are in the union K", type: "object", properties: { filename: { title: "Filename to generate or overwrite", description: "Filename to generate or overwrite.", type: "string", pattern: "((.*)\\.md)$" } }, required: [ "filename" ], additionalProperties: false, $defs: {} }, validate: (() => { const _io0 = input => "string" === typeof input.filename && RegExp(/(.*)\.md$/).test(input.filename); const _vo0 = (input, _path, _exceptionable = true) => [ "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: 'Pick<IFile, "filename">', value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: 'Pick<IFile, "filename">', value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() }, { name: "abort", parameters: { type: "object", properties: { reason: { type: "string" } }, required: [ "reason" ], additionalProperties: false, $defs: {} }, output: { const: "OK" }, validate: (() => { const _io0 = input => "string" === typeof input.reason; const _vo0 = (input, _path, _exceptionable = true) => [ "string" === typeof input.reason || _report(_exceptionable, { path: _path + ".reason", expected: "string", value: input.reason }) ].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: "__type", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "__type", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() }, { name: "allFiles", parameters: { type: "object", properties: {}, additionalProperties: false, required: [], $defs: {} }, output: { description: "Description of the current {@link Recordstringstring} type:\n\n> Construct a type with a set of properties K of type T", type: "object", properties: {}, required: [], additionalProperties: { type: "string" } }, validate: (() => input => ({ success: true, data: input }))() } ] }; const collection$c = { chatgpt: { model: "chatgpt", options: { reference: true, strict: false, separate: null }, functions: [ { name: "createOrUpdateFiles", parameters: { type: "object", properties: { files: { description: "@minItems 1", type: "array", items: { description: "Current Type: {@link IFile}", 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: { title: "Filename to generate or overwrite", description: "Filename to generate or overwrite.\n\n\n@pattern ((.*)\\.md)$", type: "string" }, markdown: { description: 'Markdown file content. Only write the content of the file. Do not include\nany questions. This should contain only the contents of the file. Do not\nwrite down any questions or appreciation. For example, remove a sentence\nsuch as "Is it okay if we proceed with the table of contents? Please let me\nknow if there is anything to add or exclude from the table of contents!"', type: "string" } }, required: [ "reason", "filename", "markdown" ] } } }, required: [ "files" ], additionalProperties: false, $defs: {} }, validate: (() => { const _io0 = input => Array.isArray(input.files) && (1 <= input.files.length && input.files.every((elem => "object" === typeof elem && null !== elem && _io1(elem)))); const _io1 = input => "string" === typeof input.reason && ("string" === typeof input.filename && RegExp(/(.*)\.md$/).test(input.filename)) && "string" === typeof input.markdown; const _vo0 = (input, _path, _exceptionable = true) => [ (Array.isArray(input.files) || _report(_exceptionable, { path: _path + ".files", expected: "(Array<IFile> & MinItems<1>)", value: input.files })) && ((1 <= input.files.length || _report(_exceptionable, { path: _path + ".files", expected: "Array<> & MinItems<1>", value: input.files })) && input.files.map(((elem, _index2) => ("object" === typeof elem && null !== elem || _report(_exceptionable, { path: _path + ".files[" + _index2 + "]", expected: "IFile", value: elem })) && _vo1(elem, _path + ".files[" + _index2 + "]", _exceptionable) || _report(_exceptionable, { path: _path + ".files[" + _index2 + "]", expected: "IFile", value: elem }))).every((flag => flag))) || _report(_exceptionable, { path: _path + ".files", expected: "(Array<IFile> & MinItems<1>)", value: input.files }) ].every((flag => flag)); const _vo1 = (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 }), "string" === typeof input.markdown || _report(_exceptionable, { path: _path + ".markdown", expected: "string", value: input.markdown }) ].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: "__type", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "__type", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() }, { name: "removeFile", parameters: { description: "Description of the current {@link PickIFilefilename} type:\n\n> From T, pick a set of properties whose keys are in the union K", type: "object", properties: { filename: { title: "Filename to generate or overwrite", description: "Filename to generate or overwrite.\n\n\n@pattern ((.*)\\.md)$", type: "string" } }, required: [ "filename" ], additionalProperties: false, $defs: {} }, validate: (() => { const _io0 = input => "string" === typeof input.filename && RegExp(/(.*)\.md$/).test(input.filename); const _vo0 = (input, _path, _exceptionable = true) => [ "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: 'Pick<IFile, "filename">', value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: 'Pick<IFile, "filename">', value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() }, { name: "abort", parameters: { type: "object", properties: { reason: { type: "string" } }, required: [ "reason" ], additionalProperties: false, $defs: {} }, output: { type: "string", enum: [ "OK" ] }, validate: (() => { const _io0 = input => "string" === typeof input.reason; const _vo0 = (input, _path, _exceptionable = true) => [ "string" === typeof input.reason || _report(_exceptionable, { path: _path + ".reason", expected: "string", value: input.reason }) ].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: "__type", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "__type", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() }, { name: "allFiles", parameters: { type: "object", properties: {}, additionalProperties: false, required: [], $defs: {} }, output: { description: "Description of the current {@link Recordstringstring} type:\n\n> Construct a type with a set of properties K of type T", type: "object", properties: {}, required: [], additionalProperties: { type: "string" } }, validate: (() => input => ({ success: true, data: input }))() } ] }, claude: claude$c, llama: claude$c, deepseek: claude$c, 3.1: claude$c, "3.0": { model: "3.0", options: { constraint: true, recursive: 3, separate: null }, functions: [ { name: "createOrUpdateFiles", parameters: { type: "object", properties: { files: { type: "array", items: { type: "object", properties: { reason: { type: "string", description: "Describe briefly why you made this document, and if you have any plans for\nthe next one." }, filename: { type: "string", pattern: "((.*)\\.md)$", title: "Filename to generate or overwrite", description: "Filename to generate or overwrite." }, markdown: { type: "string", description: 'Markdown file content. Only write the content of the file. Do not include\nany questions. This should contain only the contents of the file. Do not\nwrite down any questions or appreciation. For example, remove a sentence\nsuch as "Is it okay if we proceed with the table of contents? Please let me\nknow if there is anything to add or exclude from the table of contents!"' } }, required: [ "reason", "filename", "markdown" ], description: "Current Type: {@link IFile}", additionalProperties: false }, minItems: 1 } }, required: [ "files" ], additionalProperties: false }, validate: (() => { const _io0 = input => Array.isArray(input.files) && (1 <= input.files.length && input.files.every((elem => "object" === typeof elem && null !== elem && _io1(elem)))); const _io1 = input => "string" === typeof input.reason && ("string" === typeof input.filename && RegExp(/(.*)\.md$/).test(input.filename)) && "string" === typeof input.markdown; const _vo0 = (input, _path, _exceptionable = true) => [ (Array.isArray(input.files) || _report(_exceptionable, { path: _path + ".files", expected: "(Array<IFile> & MinItems<1>)", value: input.files })) && ((1 <= input.files.length || _report(_exceptionable, { path: _path + ".files", expected: "Array<> & MinItems<1>", value: input.files })) && input.files.map(((elem, _index2) => ("object" === typeof elem && null !== elem || _report(_exceptionable, { path: _path + ".files[" + _index2 + "]", expected: "IFile", value: elem })) && _vo1(elem, _path + ".files[" + _index2 + "]", _exceptionable) || _report(_exceptionable, { path: _path + ".files[" + _index2 + "]", expected: "IFile", value: elem }))).every((flag => flag))) || _report(_exceptionable, { path: _path + ".files", expected: "(Array<IFile> & MinItems<1>)", value: input.files }) ].every((flag => flag)); const _vo1 = (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 }), "string" === typeof input.markdown || _report(_exceptionable, { path: _path + ".markdown", expected: "string", value: input.markdown }) ].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: "__type", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "__type", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() }, { name: "removeFile", parameters: { type: "object", properties: { filename: { type: "string", pattern: "((.*)\\.md)$", title: "Filename to generate or overwrite", description: "Filename to generate or overwrite." } }, required: [ "filename" ], description: "Description of the current {@link PickIFilefilename} type:\n\n> From T, pick a set of properties whose keys are in the union K", additionalProperties: false }, validate: (() => { const _io0 = input => "string" === typeof input.filename && RegExp(/(.*)\.md$/).test(input.filename); const _vo0 = (input, _path, _exceptionable = true) => [ "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: 'Pick<IFile, "filename">', value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: 'Pick<IFile, "filename">', value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() }, { name: "abort", parameters: { type: "object", properties: { reason: { type: "string" } }, required: [ "reason" ], additionalProperties: false }, output: { type: "string", enum: [ "OK" ] }, validate: (() => { const _io0 = input => "string" === typeof input.reason; const _vo0 = (input, _path, _exceptionable = true) => [ "string" === typeof input.reason || _report(_exceptionable, { path: _path + ".reason", expected: "string", value: input.reason }) ].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: "__type", value: input })) && _vo0(input, _path + "", true) || _report(true, { path: _path + "", expected: "__type", value: input }))(input, "$input", true); const success = 0 === errors.length; return success ? { success, data: input } : { success, errors, data: input }; } return { success: true, data: input }; }; })() }, { name: "allFiles", parameters: { type: "object", properties: {}, additionalProperties: false, required: [] }, output: { type: "object", properties: {}, required: [], description: "Description of the current {@link Recordstringstring} type:\n\n> Construct a type with a set of properties K of type T", additionalProperties: { type: "string" } }, validate: (() => input => ({ success: true, data: input }))() } ] } }; const AutoBeAnalyzeReviewer = (ctx, input) => { const agent = new MicroAgentica({ model: ctx.model, vendor: ctx.vendor, controllers: [], config: { executor: { describe: null }, locale: ctx.config?.locale }, histories: [ ...ctx.histories().filter((el => el.type === "assistantMessage" || el.type === "userMessage")), { id: v4(), created_at: (new Date).toISOString(), type: "systemMessage", text: "# Reviewer Agent Operating Guidelines\n\n## Core Principles\n\n* **Only review the document currently being viewed.**\n* Even if there is a section that implies another document, **ignore it.**\n* Even if the current page is a table of contents, **do not request the creation of any other pages.**\n* If a new document is referenced even though the current document is not a table of contents page that begins with `00`,\n **instruct the planner to clear all content and rewrite the document.**\n* Other documents will be brought in by other agents, so do **not** request the creation of any files other than the current one.\n* **Each agent must write only the single page assigned to them.** \n Requests or attempts to wr