UNPKG

@autobe/agent

Version:

AI backend server code generator

444 lines 27.7 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.orchestratePreliminary = void 0; const __typia_transform__isTypeUint32 = __importStar(require("typia/lib/internal/_isTypeUint32")); const utils_1 = require("@typia/utils"); const typia_1 = __importDefault(require("typia")); const uuid_1 = require("uuid"); const complementPreliminaryCollection_1 = require("./internal/complementPreliminaryCollection"); const orchestratePreliminary = (ctx, props) => __awaiter(void 0, void 0, void 0, function* () { var _a; const executes = props.histories.filter((h) => h.type === "execute"); if (executes.length === 0) { // Some vendors (notably certain Qwen/OpenRouter routes) occasionally return // an empty turn where only the user message is recorded. Treat it as a // transient no-op so the outer RAG loop can retry instead of failing fast. if (props.histories.every((h) => h.type === "userMessage")) return; throw new Error("Failed to function calling from the preliminary step."); } for (const exec of executes) { // COMPLETE if ((() => { const _io0 = input => "object" === typeof input.request && null !== input.request && _io1(input.request); const _io1 = input => "complete" === input.type; return input => "object" === typeof input && null !== input && _io0(input); })()(exec.arguments)) { (_a = props.completed).value || (_a.value = true); } // ANALYSIS else if (isAnalysisSections(props.preliminary, exec.arguments)) { const ps = props.preliminary; orchestrateAnalysisSections(ctx, { source: props.source, source_id: props.source_id, trial: props.trial, all: ps.getAll().analysisSections, local: ps.getLocal().analysisSections, arguments: exec.arguments, previous: false, }); props.preliminary.advanceAnalysisPage(); } else if (isPreviousAnalysisSections(props.preliminary, exec.arguments)) { const ps = props.preliminary; orchestrateAnalysisSections(ctx, { source: props.source, source_id: props.source_id, trial: props.trial, all: ps.getAll().previousAnalysisSections, local: ps.getLocal().previousAnalysisSections, arguments: exec.arguments, previous: true, }); props.preliminary.advanceAnalysisPage(); } // PRISMA SCHEMAS else if (isPrismaSchemas(props.preliminary, exec.arguments)) { const pp = props.preliminary; orchestratePrismaSchemas(ctx, { source: props.source, source_id: props.source_id, trial: props.trial, all: pp.getAll().databaseSchemas, local: pp.getLocal().databaseSchemas, arguments: exec.arguments, previous: false, }); } else if (isPreviousPrismaSchemas(props.preliminary, exec.arguments)) { const pp = props.preliminary; orchestratePrismaSchemas(ctx, { source: props.source, source_id: props.source_id, trial: props.trial, all: pp.getAll().previousDatabaseSchemas, local: pp.getLocal().previousDatabaseSchemas, arguments: exec.arguments, previous: true, }); } // INTERFACE OPERATIONS else if (isInterfaceOperations(props.preliminary, exec.arguments)) { const pi = props.preliminary; orchestrateInterfaceOperations(ctx, { source: props.source, source_id: props.source_id, trial: props.trial, all: pi.getAll().interfaceOperations, local: pi.getLocal().interfaceOperations, arguments: exec.arguments, previous: false, }); } else if (isPreviousInterfaceOperations(props.preliminary, exec.arguments)) { const pi = props.preliminary; orchestrateInterfaceOperations(ctx, { source: props.source, source_id: props.source_id, trial: props.trial, all: pi.getAll().previousInterfaceOperations, local: pi.getLocal().previousInterfaceOperations, arguments: exec.arguments, previous: true, }); } // INTERFACE SCHEMAS else if (isInterfaceSchemas(props.preliminary, exec.arguments)) { const ps = props.preliminary; orchestrateInterfaceSchemas(ctx, { source: props.source, source_id: props.source_id, trial: props.trial, all: ps.getAll().interfaceSchemas, local: ps.getLocal().interfaceSchemas, arguments: exec.arguments, previous: false, }); } else if (isPreviousInterfaceSchemas(props.preliminary, exec.arguments)) { const ps = props.preliminary; orchestrateInterfaceSchemas(ctx, { source: props.source, source_id: props.source_id, trial: props.trial, all: ps.getAll().previousInterfaceSchemas, local: ps.getLocal().previousInterfaceSchemas, arguments: exec.arguments, previous: true, }); } // REALIZE COLLECTORS else if (isRealizeCollectors(props.preliminary, exec.arguments)) { const rc = props.preliminary; orchestrateRealizeCollectors(ctx, { source: props.source, source_id: props.source_id, trial: props.trial, all: rc.getAll().realizeCollectors, local: rc.getLocal().realizeCollectors, arguments: exec.arguments, }); } // REALIZE TRANSFORMERS else if (isRealizeTransformers(props.preliminary, exec.arguments)) { const rt = props.preliminary; orchestrateRealizeTransformers(ctx, { source: props.source, source_id: props.source_id, trial: props.trial, all: rt.getAll().realizeTransformers, local: rt.getLocal().realizeTransformers, arguments: exec.arguments, }); } } (0, complementPreliminaryCollection_1.complementPreliminaryCollection)({ kinds: props.preliminary.getKinds(), all: props.preliminary.getAll(), local: props.preliminary.getLocal(), prerequisite: false, }); }); exports.orchestratePreliminary = orchestratePreliminary; /* ----------------------------------------------------------- TYPE CHECKERS ----------------------------------------------------------- */ const isAnalysisSections = ( // biome-ignore lint: intended preliminary, input) => (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getAnalysisSections" === input.type && (Array.isArray(input.sectionIds) && (1 <= input.sectionIds.length && input.sectionIds.length <= 100 && input.sectionIds.every(elem => "number" === typeof elem && __typia_transform__isTypeUint32._isTypeUint32(elem)))); return input => "object" === typeof input && null !== input && _io0(input); })()(input) && preliminary.getAll()[[ "analysisSections" ][0]] !== undefined; const isPreviousAnalysisSections = ( // biome-ignore lint: intended preliminary, input) => (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getPreviousAnalysisSections" === input.type && (Array.isArray(input.sectionIds) && (1 <= input.sectionIds.length && input.sectionIds.every(elem => "number" === typeof elem && __typia_transform__isTypeUint32._isTypeUint32(elem)))); return input => "object" === typeof input && null !== input && _io0(input); })()(input) && preliminary.getAll()[[ "previousAnalysisSections" ][0]] !== undefined; const isPrismaSchemas = ( // biome-ignore lint: intended preliminary, input) => (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getDatabaseSchemas" === input.type && (Array.isArray(input.schemaNames) && (1 <= input.schemaNames.length && input.schemaNames.every(elem => "string" === typeof elem))); return input => "object" === typeof input && null !== input && _io0(input); })()(input) && preliminary.getAll()[[ "databaseSchemas" ][0]] !== undefined; const isPreviousPrismaSchemas = ( // biome-ignore lint: intended preliminary, input) => (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getPreviousDatabaseSchemas" === input.type && (Array.isArray(input.schemaNames) && (1 <= input.schemaNames.length && input.schemaNames.every(elem => "string" === typeof elem))); return input => "object" === typeof input && null !== input && _io0(input); })()(input) && preliminary.getAll()[[ "previousDatabaseSchemas" ][0]] !== undefined; const isInterfaceOperations = ( // biome-ignore lint: intended preliminary, input) => (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getInterfaceOperations" === input.type && (Array.isArray(input.endpoints) && (1 <= input.endpoints.length && input.endpoints.every(elem => "object" === typeof elem && null !== elem && _io2(elem)))); const _io2 = 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); return input => "object" === typeof input && null !== input && _io0(input); })()(input) && preliminary.getAll()[[ "interfaceOperations" ][0]] !== undefined; const isPreviousInterfaceOperations = ( // biome-ignore lint: intended preliminary, input) => (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getPreviousInterfaceOperations" === input.type && (Array.isArray(input.endpoints) && (1 <= input.endpoints.length && input.endpoints.every(elem => "object" === typeof elem && null !== elem && _io2(elem)))); const _io2 = 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); return input => "object" === typeof input && null !== input && _io0(input); })()(input) && preliminary.getAll()[[ "previousInterfaceOperations" ][0]] !== undefined; const isInterfaceSchemas = ( // biome-ignore lint: intended preliminary, input) => (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getInterfaceSchemas" === input.type && (Array.isArray(input.typeNames) && (1 <= input.typeNames.length && input.typeNames.every(elem => "string" === typeof elem))); return input => "object" === typeof input && null !== input && _io0(input); })()(input) && preliminary.getAll()[[ "interfaceSchemas" ][0]] !== undefined; const isPreviousInterfaceSchemas = ( // biome-ignore lint: intended preliminary, input) => (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getPreviousInterfaceSchemas" === input.type && (Array.isArray(input.typeNames) && (1 <= input.typeNames.length && input.typeNames.every(elem => "string" === typeof elem))); return input => "object" === typeof input && null !== input && _io0(input); })()(input) && preliminary.getAll()[[ "previousInterfaceSchemas" ][0]] !== undefined; const isRealizeCollectors = ( // biome-ignore lint: intended preliminary, input) => (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getRealizeCollectors" === input.type && (Array.isArray(input.dtoTypeNames) && (1 <= input.dtoTypeNames.length && input.dtoTypeNames.every(elem => "string" === typeof elem))); return input => "object" === typeof input && null !== input && _io0(input); })()(input) && preliminary.getAll()[[ "realizeCollectors" ][0]] !== undefined; const isRealizeTransformers = ( // biome-ignore lint: intended preliminary, input) => (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getRealizeTransformers" === input.type && (Array.isArray(input.dtoTypeNames) && (1 <= input.dtoTypeNames.length && input.dtoTypeNames.every(elem => "string" === typeof elem))); return input => "object" === typeof input && null !== input && _io0(input); })()(input) && preliminary.getAll()[[ "realizeTransformers" ][0]] !== undefined; /* ----------------------------------------------------------- ORCHESTRATORS ----------------------------------------------------------- */ const orchestrateAnalysisSections = (ctx, props) => { if (props.previous) { if (false === (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getPreviousAnalysisSections" === input.type && (Array.isArray(input.sectionIds) && (1 <= input.sectionIds.length && input.sectionIds.every(elem => "number" === typeof elem && __typia_transform__isTypeUint32._isTypeUint32(elem)))); return input => "object" === typeof input && null !== input && _io0(input); })()(props.arguments)) return; } else if (false === (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getAnalysisSections" === input.type && (Array.isArray(input.sectionIds) && (1 <= input.sectionIds.length && input.sectionIds.length <= 100 && input.sectionIds.every(elem => "number" === typeof elem && __typia_transform__isTypeUint32._isTypeUint32(elem)))); return input => "object" === typeof input && null !== input && _io0(input); })()(props.arguments)) return; const existing = props.local.map((s) => s.id); for (const sectionId of props.arguments.request.sectionIds) { const section = props.all.find((s) => s.id === sectionId); if (section === undefined) continue; else if (props.local.find((s) => s.id === sectionId) === undefined) props.local.push(section); } ctx.dispatch({ type: "preliminaryAcquire", id: (0, uuid_1.v7)(), function: props.previous ? "previousAnalysisSections" : "analysisSections", source: props.source, source_id: props.source_id, // biome-ignore lint/suspicious/noExplicitAny: conditional type narrowing not available at dispatch site existing: existing, // biome-ignore lint/suspicious/noExplicitAny: conditional type narrowing not available at dispatch site requested: props.arguments.request.sectionIds, trial: props.trial, created_at: new Date().toISOString(), }); }; const orchestratePrismaSchemas = (ctx, props) => { if (props.previous) { if (false === (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getPreviousDatabaseSchemas" === input.type && (Array.isArray(input.schemaNames) && (1 <= input.schemaNames.length && input.schemaNames.every(elem => "string" === typeof elem))); return input => "object" === typeof input && null !== input && _io0(input); })()(props.arguments)) return; } else if (false === (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getDatabaseSchemas" === input.type && (Array.isArray(input.schemaNames) && (1 <= input.schemaNames.length && input.schemaNames.every(elem => "string" === typeof elem))); return input => "object" === typeof input && null !== input && _io0(input); })()(props.arguments)) return; const existing = props.local.map((m) => m.name); for (const name of props.arguments.request.schemaNames) { const model = props.all.find((m) => m.name === name); if (model === undefined) continue; else if (props.local.find((m) => m.name === name) === undefined) props.local.push(model); } ctx.dispatch({ type: "preliminaryAcquire", id: (0, uuid_1.v7)(), function: props.previous ? "previousDatabaseSchemas" : "databaseSchemas", source: props.source, source_id: props.source_id, existing, requested: props.arguments.request.schemaNames, trial: props.trial, created_at: new Date().toISOString(), }); }; const orchestrateInterfaceOperations = (ctx, props) => { if (props.previous) { if (false === (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getPreviousInterfaceOperations" === input.type && (Array.isArray(input.endpoints) && (1 <= input.endpoints.length && input.endpoints.every(elem => "object" === typeof elem && null !== elem && _io2(elem)))); const _io2 = 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); return input => "object" === typeof input && null !== input && _io0(input); })()(props.arguments)) return; } else if (false === (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getInterfaceOperations" === input.type && (Array.isArray(input.endpoints) && (1 <= input.endpoints.length && input.endpoints.every(elem => "object" === typeof elem && null !== elem && _io2(elem)))); const _io2 = 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); return input => "object" === typeof input && null !== input && _io0(input); })()(props.arguments)) return; const existing = props.local.map((o) => ({ method: o.method, path: o.path, })); for (const endpoint of props.arguments.request.endpoints) { if (props.local.find((v) => v.method === endpoint.method && v.path === endpoint.path) !== undefined) continue; // duplicated const operation = props.all.find((v) => v.method === endpoint.method && v.path === endpoint.path); if (operation !== undefined) props.local.push(operation); } ctx.dispatch({ type: "preliminaryAcquire", id: (0, uuid_1.v7)(), function: props.previous ? "previousInterfaceOperations" : "interfaceOperations", source: props.source, source_id: props.source_id, existing, requested: props.arguments.request.endpoints, trial: props.trial, created_at: new Date().toISOString(), }); }; const orchestrateInterfaceSchemas = (ctx, props, dispatch = true) => { if (props.previous) { if (false === (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getPreviousInterfaceSchemas" === input.type && (Array.isArray(input.typeNames) && (1 <= input.typeNames.length && input.typeNames.every(elem => "string" === typeof elem))); return input => "object" === typeof input && null !== input && _io0(input); })()(props.arguments)) return; } else if (false === (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getInterfaceSchemas" === input.type && (Array.isArray(input.typeNames) && (1 <= input.typeNames.length && input.typeNames.every(elem => "string" === typeof elem))); return input => "object" === typeof input && null !== input && _io0(input); })()(props.arguments)) return; const existing = Object.keys(props.local); const collected = {}; for (const key of props.arguments.request.typeNames) { utils_1.OpenApiTypeChecker.visit({ components: { schemas: props.all, }, schema: { $ref: `#/components/schemas/${key}` }, closure: (next) => { if (utils_1.OpenApiTypeChecker.isReference(next)) { const last = next.$ref.split("/").pop(); if (props.all[last] !== undefined) collected[last] = props.all[last]; } }, }); } Object.assign(props.local, collected); if (dispatch === true) ctx.dispatch({ type: "preliminaryAcquire", id: (0, uuid_1.v7)(), function: props.previous ? "previousInterfaceSchemas" : "interfaceSchemas", source: props.source, source_id: props.source_id, existing, requested: props.arguments.request.typeNames, trial: props.trial, created_at: new Date().toISOString(), }); }; const orchestrateRealizeCollectors = (ctx, props) => { if (false === (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getRealizeCollectors" === input.type && (Array.isArray(input.dtoTypeNames) && (1 <= input.dtoTypeNames.length && input.dtoTypeNames.every(elem => "string" === typeof elem))); return input => "object" === typeof input && null !== input && _io0(input); })()(props.arguments)) return; const existing = props.local.map((c) => c.plan.dtoTypeName); for (const dtoTypeName of props.arguments.request.dtoTypeNames) { const collector = props.all.find((c) => c.plan.dtoTypeName === dtoTypeName); if (collector === undefined) continue; else if (props.local.find((c) => c.plan.dtoTypeName === dtoTypeName) === undefined) props.local.push(collector); } ctx.dispatch({ type: "preliminaryAcquire", id: (0, uuid_1.v7)(), function: "realizeCollectors", source: props.source, source_id: props.source_id, existing, requested: props.arguments.request.dtoTypeNames, trial: props.trial, created_at: new Date().toISOString(), }); }; const orchestrateRealizeTransformers = (ctx, props) => { if (false === (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _io1(input.request)); const _io1 = input => "getRealizeTransformers" === input.type && (Array.isArray(input.dtoTypeNames) && (1 <= input.dtoTypeNames.length && input.dtoTypeNames.every(elem => "string" === typeof elem))); return input => "object" === typeof input && null !== input && _io0(input); })()(props.arguments)) return; const existing = props.local.map((t) => t.plan.dtoTypeName); for (const dtoTypeName of props.arguments.request.dtoTypeNames) { const transformer = props.all.find((t) => t.plan.dtoTypeName === dtoTypeName); if (transformer !== undefined && existing.find((e) => e === dtoTypeName) === undefined) props.local.push(transformer); } ctx.dispatch({ type: "preliminaryAcquire", id: (0, uuid_1.v7)(), function: "realizeTransformers", source: props.source, source_id: props.source_id, existing, requested: props.arguments.request.dtoTypeNames, trial: props.trial, created_at: new Date().toISOString(), }); }; //# sourceMappingURL=orchestratePreliminary.js.map