@autobe/agent
Version:
AI backend server code generator
368 lines • 22.9 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 __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.orchestrateInterfaceEndpoints = orchestrateInterfaceEndpoints;
const __typia_transform__validateReport = __importStar(require("typia/lib/internal/_validateReport.js"));
const core_1 = require("@agentica/core");
const tstl_1 = require("tstl");
const typia_1 = __importDefault(require("typia"));
const assertSchemaModel_1 = require("../../context/assertSchemaModel");
const enforceToolCall_1 = require("../../utils/enforceToolCall");
const transformInterfaceEndpointHistories_1 = require("./histories/transformInterfaceEndpointHistories");
const OpenApiEndpointComparator_1 = require("./utils/OpenApiEndpointComparator");
function orchestrateInterfaceEndpoints(ctx_1, groups_1) {
return __awaiter(this, arguments, void 0, function* (ctx, groups, content = `Make endpoints for the given assets`) {
const progress = {
total: groups.length,
completed: 0,
};
const endpoints = (yield Promise.all(groups.map((g) => process(ctx, g, content, progress)))).flat();
return new tstl_1.HashSet(endpoints, OpenApiEndpointComparator_1.OpenApiEndpointComparator.hashCode, OpenApiEndpointComparator_1.OpenApiEndpointComparator.equals).toJSON();
});
}
function process(ctx, group, content, progress) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c;
const start = new Date();
const pointer = {
value: null,
};
const agentica = new core_1.MicroAgentica({
model: ctx.model,
vendor: ctx.vendor,
config: Object.assign(Object.assign({}, ((_a = ctx.config) !== null && _a !== void 0 ? _a : {})), { executor: {
describe: null,
} }),
histories: (0, transformInterfaceEndpointHistories_1.transformInterfaceEndpointHistories)(ctx.state(), group),
controllers: [
createApplication({
model: ctx.model,
build: (endpoints) => {
var _a;
(_a = pointer.value) !== null && _a !== void 0 ? _a : (pointer.value = endpoints);
pointer.value.push(...endpoints);
},
}),
],
});
(0, enforceToolCall_1.enforceToolCall)(agentica);
yield agentica.conversate(content).finally(() => {
const tokenUsage = agentica.getTokenUsage();
ctx.usage().record(tokenUsage, ["interface"]);
});
if (pointer.value === null)
throw new Error("Failed to generate endpoints."); // unreachable
const event = {
type: "interfaceEndpoints",
endpoints: new tstl_1.HashSet(pointer.value, OpenApiEndpointComparator_1.OpenApiEndpointComparator.hashCode, OpenApiEndpointComparator_1.OpenApiEndpointComparator.equals).toJSON(),
created_at: start.toISOString(),
step: (_c = (_b = ctx.state().analyze) === null || _b === void 0 ? void 0 : _b.step) !== null && _c !== void 0 ? _c : 0,
completed: ++progress.completed,
total: progress.total,
};
ctx.dispatch(event);
return pointer.value;
});
}
function createApplication(props) {
(0, assertSchemaModel_1.assertSchemaModel)(props.model);
const application = collection[props.model];
return {
protocol: "class",
name: "interface",
application,
execute: {
makeEndpoints: (next) => {
props.build(next.endpoints);
},
},
};
}
const claude = {
model: "claude",
options: {
reference: true,
separate: null
},
functions: [
{
name: "makeEndpoints",
parameters: {
description: " Properties containing the endpoints\n\n------------------------------\n\nCurrent Type: {@link IAutoBeInterfaceEndpointApplication.IProps}",
type: "object",
properties: {
endpoints: {
description: "The endpoints to generate.",
type: "array",
items: {
$ref: "#/$defs/AutoBeOpenApi.IEndpoint"
}
}
},
required: [
"endpoints"
],
additionalProperties: false,
$defs: {
"AutoBeOpenApi.IEndpoint": {
description: "API endpoint information.",
type: "object",
properties: {
path: {
description: "HTTP path of the API operation.\n\nThe URL path for accessing this API operation, using path parameters\nenclosed in curly braces (e.g., `/shoppings/customers/sales/{saleId}`).\n\nIt must be corresponded to the {@link parameters path parameters}.\n\nThe path structure should clearly indicate which database entity this\noperation is manipulating, helping to ensure all entities have\nappropriate API coverage.\n\nPath validation rules:\n\n- Must start with a forward slash (/)\n- Can contain only: letters (a-z, A-Z), numbers (0-9), forward slashes (/),\n curly braces for parameters ({paramName}), hyphens (-), and underscores\n (_)\n- Parameters must be enclosed in curly braces: {paramName}\n- Resource names should be in camelCase\n- No quotes, spaces, or invalid special characters allowed\n- No domain or role-based prefixes\n\nValid examples:\n\n- \"/users\"\n- \"/users/{userId}\"\n- \"/articles/{articleId}/comments\"\n- \"/attachmentFiles\"\n- \"/orders/{orderId}/items/{itemId}\"\n\nInvalid examples:\n\n- \"'/users'\" (contains quotes)\n- \"/user profile\" (contains space)\n- \"/users/[userId]\" (wrong bracket format)\n- \"/admin/users\" (role prefix)\n- \"/api/v1/users\" (API prefix)",
type: "string",
pattern: "^\\/[a-zA-Z0-9\\/_{}.-]*$"
},
method: {
description: "HTTP method of the API operation.\n\nNote that, if the API operation has {@link requestBody}, method must not\nbe `get`.\n\nAlso, even though the API operation has been designed to only get\ninformation, but it needs complicated request information, it must be\ndefined as `patch` method with {@link requestBody} data specification.\n\n- `get`: get information\n- `patch`: get information with complicated request data\n ({@link requestBody})\n- `post`: create new record\n- `put`: update existing record\n- `delete`: remove record",
oneOf: [
{
"const": "get"
},
{
"const": "post"
},
{
"const": "put"
},
{
"const": "delete"
},
{
"const": "patch"
}
]
}
},
required: [
"path",
"method"
]
}
}
},
description: "Create Restful API endpoints.\n\nCreate Restful API endpoints referencing the given documents; requirement\nanalysis documents, and Prisma schema files with ERD descriptions. The API\nendpoints must cover every requirements and every entities in the ERD.\n\nAlso, each combination of {@link AutoBeOpenApi.IEndpoint.path} and\n{@link AutoBeOpenApi.IEndpoint.method} must be unique to avoid duplicates.\nPlease don't make any duplicates.",
validate: (() => { const _io0 = input => Array.isArray(input.endpoints) && input.endpoints.every(elem => "object" === typeof elem && null !== elem && _io1(elem)); const _io1 = input => "string" === typeof input.path && RegExp("^\\/[a-zA-Z0-9\\/_{}.-]*$").test(input.path) && ("get" === input.method || "post" === input.method || "put" === input.method || "delete" === input.method || "patch" === input.method); const _vo0 = (input, _path, _exceptionable = true) => [(Array.isArray(input.endpoints) || _report(_exceptionable, {
path: _path + ".endpoints",
expected: "Array<AutoBeOpenApi.IEndpoint>",
value: input.endpoints
})) && input.endpoints.map((elem, _index2) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
path: _path + ".endpoints[" + _index2 + "]",
expected: "AutoBeOpenApi.IEndpoint",
value: elem
})) && _vo1(elem, _path + ".endpoints[" + _index2 + "]", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".endpoints[" + _index2 + "]",
expected: "AutoBeOpenApi.IEndpoint",
value: elem
})).every(flag => flag) || _report(_exceptionable, {
path: _path + ".endpoints",
expected: "Array<AutoBeOpenApi.IEndpoint>",
value: input.endpoints
})].every(flag => flag); const _vo1 = (input, _path, _exceptionable = true) => ["string" === typeof input.path && (RegExp("^\\/[a-zA-Z0-9\\/_{}.-]*$").test(input.path) || _report(_exceptionable, {
path: _path + ".path",
expected: "string & Pattern<\"^\\\\/[a-zA-Z0-9\\\\/_{}.-]*$\">",
value: input.path
})) || _report(_exceptionable, {
path: _path + ".path",
expected: "(string & Pattern<\"^\\\\/[a-zA-Z0-9\\\\/_{}.-]*$\">)",
value: input.path
}), "get" === input.method || "post" === input.method || "put" === input.method || "delete" === input.method || "patch" === input.method || _report(_exceptionable, {
path: _path + ".method",
expected: "(\"delete\" | \"get\" | \"patch\" | \"post\" | \"put\")",
value: input.method
})].every(flag => flag); const __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: "IAutoBeInterfaceEndpointApplication.IProps",
value: input
})) && _vo0(input, _path + "", true) || _report(true, {
path: _path + "",
expected: "IAutoBeInterfaceEndpointApplication.IProps",
value: input
}))(input, "$input", true);
const success = 0 === errors.length;
return success ? {
success,
data: input
} : {
success,
errors,
data: input
};
}
return {
success: true,
data: input
};
}; })()
}
]
};
const collection = {
chatgpt: {
model: "chatgpt",
options: {
reference: true,
strict: false,
separate: null
},
functions: [
{
name: "makeEndpoints",
parameters: {
description: " Properties containing the endpoints\n\n------------------------------\n\nCurrent Type: {@link IAutoBeInterfaceEndpointApplication.IProps}",
type: "object",
properties: {
endpoints: {
description: "The endpoints to generate.",
type: "array",
items: {
$ref: "#/$defs/AutoBeOpenApi.IEndpoint"
}
}
},
required: [
"endpoints"
],
additionalProperties: false,
$defs: {
"AutoBeOpenApi.IEndpoint": {
description: "API endpoint information.",
type: "object",
properties: {
path: {
description: "HTTP path of the API operation.\n\nThe URL path for accessing this API operation, using path parameters\nenclosed in curly braces (e.g., `/shoppings/customers/sales/{saleId}`).\n\nIt must be corresponded to the {@link parameters path parameters}.\n\nThe path structure should clearly indicate which database entity this\noperation is manipulating, helping to ensure all entities have\nappropriate API coverage.\n\nPath validation rules:\n\n- Must start with a forward slash (/)\n- Can contain only: letters (a-z, A-Z), numbers (0-9), forward slashes (/),\n curly braces for parameters ({paramName}), hyphens (-), and underscores\n (_)\n- Parameters must be enclosed in curly braces: {paramName}\n- Resource names should be in camelCase\n- No quotes, spaces, or invalid special characters allowed\n- No domain or role-based prefixes\n\nValid examples:\n\n- \"/users\"\n- \"/users/{userId}\"\n- \"/articles/{articleId}/comments\"\n- \"/attachmentFiles\"\n- \"/orders/{orderId}/items/{itemId}\"\n\nInvalid examples:\n\n- \"'/users'\" (contains quotes)\n- \"/user profile\" (contains space)\n- \"/users/[userId]\" (wrong bracket format)\n- \"/admin/users\" (role prefix)\n- \"/api/v1/users\" (API prefix)\n\n\n@pattern ^\\/[a-zA-Z0-9\\/_{}.-]*$",
type: "string"
},
method: {
description: "HTTP method of the API operation.\n\nNote that, if the API operation has {@link requestBody}, method must not\nbe `get`.\n\nAlso, even though the API operation has been designed to only get\ninformation, but it needs complicated request information, it must be\ndefined as `patch` method with {@link requestBody} data specification.\n\n- `get`: get information\n- `patch`: get information with complicated request data\n ({@link requestBody})\n- `post`: create new record\n- `put`: update existing record\n- `delete`: remove record",
type: "string",
"enum": [
"get",
"post",
"put",
"delete",
"patch"
]
}
},
required: [
"path",
"method"
]
}
}
},
description: "Create Restful API endpoints.\n\nCreate Restful API endpoints referencing the given documents; requirement\nanalysis documents, and Prisma schema files with ERD descriptions. The API\nendpoints must cover every requirements and every entities in the ERD.\n\nAlso, each combination of {@link AutoBeOpenApi.IEndpoint.path} and\n{@link AutoBeOpenApi.IEndpoint.method} must be unique to avoid duplicates.\nPlease don't make any duplicates.",
validate: (() => { const _io0 = input => Array.isArray(input.endpoints) && input.endpoints.every(elem => "object" === typeof elem && null !== elem && _io1(elem)); const _io1 = input => "string" === typeof input.path && RegExp("^\\/[a-zA-Z0-9\\/_{}.-]*$").test(input.path) && ("get" === input.method || "post" === input.method || "put" === input.method || "delete" === input.method || "patch" === input.method); const _vo0 = (input, _path, _exceptionable = true) => [(Array.isArray(input.endpoints) || _report(_exceptionable, {
path: _path + ".endpoints",
expected: "Array<AutoBeOpenApi.IEndpoint>",
value: input.endpoints
})) && input.endpoints.map((elem, _index2) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
path: _path + ".endpoints[" + _index2 + "]",
expected: "AutoBeOpenApi.IEndpoint",
value: elem
})) && _vo1(elem, _path + ".endpoints[" + _index2 + "]", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".endpoints[" + _index2 + "]",
expected: "AutoBeOpenApi.IEndpoint",
value: elem
})).every(flag => flag) || _report(_exceptionable, {
path: _path + ".endpoints",
expected: "Array<AutoBeOpenApi.IEndpoint>",
value: input.endpoints
})].every(flag => flag); const _vo1 = (input, _path, _exceptionable = true) => ["string" === typeof input.path && (RegExp("^\\/[a-zA-Z0-9\\/_{}.-]*$").test(input.path) || _report(_exceptionable, {
path: _path + ".path",
expected: "string & Pattern<\"^\\\\/[a-zA-Z0-9\\\\/_{}.-]*$\">",
value: input.path
})) || _report(_exceptionable, {
path: _path + ".path",
expected: "(string & Pattern<\"^\\\\/[a-zA-Z0-9\\\\/_{}.-]*$\">)",
value: input.path
}), "get" === input.method || "post" === input.method || "put" === input.method || "delete" === input.method || "patch" === input.method || _report(_exceptionable, {
path: _path + ".method",
expected: "(\"delete\" | \"get\" | \"patch\" | \"post\" | \"put\")",
value: input.method
})].every(flag => flag); const __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: "IAutoBeInterfaceEndpointApplication.IProps",
value: input
})) && _vo0(input, _path + "", true) || _report(true, {
path: _path + "",
expected: "IAutoBeInterfaceEndpointApplication.IProps",
value: input
}))(input, "$input", true);
const success = 0 === errors.length;
return success ? {
success,
data: input
} : {
success,
errors,
data: input
};
}
return {
success: true,
data: input
};
}; })()
}
]
},
claude,
llama: claude,
deepseek: claude,
"3.1": claude,
};
//# sourceMappingURL=orchestrateInterfaceEndpoints.js.map