@autobe/agent
Version:
AI backend server code generator
843 lines (840 loc) • 79.4 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.orchestrateRealizeCollectorPlan = orchestrateRealizeCollectorPlan;
const __typia_transform__isTypeUint32 = __importStar(require("typia/lib/internal/_isTypeUint32"));
const __typia_transform__validateReport = __importStar(require("typia/lib/internal/_validateReport"));
const __typia_transform__llmApplicationFinalize = __importStar(require("typia/lib/internal/_llmApplicationFinalize"));
const utils_1 = require("@autobe/utils");
const tstl_1 = require("tstl");
const typia_1 = __importDefault(require("typia"));
const uuid_1 = require("uuid");
const RAGRetrieval_1 = require("../../utils/RAGRetrieval");
const executeCachedBatch_1 = require("../../utils/executeCachedBatch");
const forceRetry_1 = require("../../utils/forceRetry");
const getEmbedder_1 = require("../../utils/getEmbedder");
const AutoBePreliminaryController_1 = require("../common/AutoBePreliminaryController");
const convertToSectionEntries_1 = require("../common/internal/convertToSectionEntries");
const transformRealizeCollectorPlanHistory_1 = require("./histories/transformRealizeCollectorPlanHistory");
const AutoBeRealizeCollectorProgrammer_1 = require("./programmers/AutoBeRealizeCollectorProgrammer");
function orchestrateRealizeCollectorPlan(ctx, props) {
return __awaiter(this, void 0, void 0, function* () {
const history = ctx.state().interface;
if (history === null)
throw new Error("Cannot realize collector plan without interface.");
const document = history.document;
const dtoTypeNames = Object.keys(document.components.schemas).filter(AutoBeRealizeCollectorProgrammer_1.AutoBeRealizeCollectorProgrammer.filter);
const prismaSchemaNames = new Set(ctx
.state()
.database.result.data.files.map((f) => f.models)
.flat()
.map((m) => m.name));
const result = yield (0, executeCachedBatch_1.executeCachedBatch)(ctx, Array.from(dtoTypeNames).map((it) => (promptCacheKey) => __awaiter(this, void 0, void 0, function* () {
const counter = new tstl_1.Singleton(() => ++props.progress.completed);
try {
return yield (0, forceRetry_1.forceRetry)(() => process(ctx, {
document,
dtoTypeName: it,
prismaSchemaNames,
promptCacheKey,
progress: props.progress,
counter,
}));
}
catch (error) {
counter.get();
throw error;
}
})));
return result.flat();
});
}
function process(ctx, props) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
const allSections = (0, convertToSectionEntries_1.convertToSectionEntries)((_b = (_a = ctx.state().analyze) === null || _a === void 0 ? void 0 : _a.files) !== null && _b !== void 0 ? _b : []);
const queryText = [
"collector",
"plan",
"dto",
"prisma",
props.dtoTypeName,
].join(" ");
const ragSections = yield (0, RAGRetrieval_1.buildAnalysisContextSections)((0, getEmbedder_1.getEmbedder)(), allSections, queryText, "TOPK", { log: false, logPrefix: "realizeCollectorPlan" });
const preliminary = new AutoBePreliminaryController_1.AutoBePreliminaryController({
dispatch: (e) => ctx.dispatch(e),
state: ctx.state(),
source: SOURCE,
application: {
version: "3.1",
components: {
schemas: {
"IAutoBeRealizeCollectorPlanApplication.IProps": {
type: "object",
properties: {
thinking: {
type: "string",
description: "Think before you act.\n\nFor preliminary requests: what schemas (database, DTO, operations) are\nmissing?\n\nFor write: is this DTO collectable or non-collectable? What database\ntable does it map to (if collectable)?\n\nFor complete: why you consider the decision final."
},
request: {
oneOf: [
{
$ref: "#/components/schemas/IAutoBePreliminaryComplete"
},
{
$ref: "#/components/schemas/IAutoBePreliminaryGetAnalysisSections"
},
{
$ref: "#/components/schemas/IAutoBePreliminaryGetDatabaseSchemas"
},
{
$ref: "#/components/schemas/IAutoBePreliminaryGetInterfaceOperations"
},
{
$ref: "#/components/schemas/IAutoBePreliminaryGetInterfaceSchemas"
},
{
$ref: "#/components/schemas/IAutoBeRealizeCollectorPlanApplication.IWrite"
}
],
discriminator: {
propertyName: "type",
mapping: {
complete: "#/components/schemas/IAutoBePreliminaryComplete",
getAnalysisSections: "#/components/schemas/IAutoBePreliminaryGetAnalysisSections",
getDatabaseSchemas: "#/components/schemas/IAutoBePreliminaryGetDatabaseSchemas",
getInterfaceOperations: "#/components/schemas/IAutoBePreliminaryGetInterfaceOperations",
getInterfaceSchemas: "#/components/schemas/IAutoBePreliminaryGetInterfaceSchemas",
write: "#/components/schemas/IAutoBeRealizeCollectorPlanApplication.IWrite"
}
},
description: "Action to perform. Exhausted preliminary types are removed from the\nunion, physically preventing repeated calls."
}
},
required: [
"thinking",
"request"
]
},
IAutoBePreliminaryComplete: {
type: "object",
properties: {
type: {
"const": "complete",
description: "Type discriminator for completion request."
}
},
required: [
"type"
],
description: "Finalize the write loop by accepting your most recent `write` as-is.\n\nAfter submitting a `write`, review it yourself thoroughly against the review\nchecklist in your instructions. If you find issues worth fixing, submit\nanother `write` with corrections. When you are satisfied with the quality,\ncall `complete` to finalize.\n\nYou have a maximum of 3 write attempts, but this is a safety cap \u2014 not a\ntarget to fill.\n\nOnly valid after at least one `write` submission \u2014 rejected otherwise."
},
IAutoBePreliminaryGetAnalysisSections: {
type: "object",
properties: {
type: {
"const": "getAnalysisSections",
description: "Type discriminator."
},
sectionIds: {
type: "array",
items: {
type: "integer",
minimum: 0
},
minItems: 1,
maxItems: 100,
description: "Section IDs to retrieve. DO NOT request same IDs already requested in\nprevious calls."
}
},
required: [
"type",
"sectionIds"
],
description: "Request to retrieve individual analysis sections by numeric ID."
},
IAutoBePreliminaryGetDatabaseSchemas: {
type: "object",
properties: {
type: {
"const": "getDatabaseSchemas",
description: "Type discriminator."
},
schemaNames: {
type: "array",
items: {
type: "string"
},
minItems: 1,
description: "Database table names to retrieve. DO NOT request same names already\nrequested in previous calls."
}
},
required: [
"type",
"schemaNames"
],
description: "Request to retrieve database schema definitions for context."
},
IAutoBePreliminaryGetInterfaceOperations: {
type: "object",
properties: {
type: {
"const": "getInterfaceOperations",
description: "Type discriminator."
},
endpoints: {
type: "array",
items: {
$ref: "#/components/schemas/AutoBeOpenApi.IEndpoint"
},
minItems: 1,
description: "API operation endpoints to retrieve. DO NOT request same endpoints already\nrequested in previous calls."
}
},
required: [
"type",
"endpoints"
],
description: "Request to retrieve existing interface operations for context."
},
"AutoBeOpenApi.IEndpoint": {
type: "object",
properties: {
path: {
type: "string",
pattern: "^\\/[a-zA-Z0-9\\/_{}.-]*$",
description: "HTTP path of the API operation.\n\nMust start with `/`. Parameters use curly braces: `{paramName}`. Resource\nnames in camelCase. No quotes, spaces, role prefixes (`/admin/`), or API\nversion prefixes (`/api/v1/`).\n\nAllowed characters: letters, digits, `/`, `{`, `}`, `-`, `_`, `.`"
},
method: {
oneOf: [
{
"const": "get"
},
{
"const": "post"
},
{
"const": "put"
},
{
"const": "delete"
},
{
"const": "patch"
}
],
description: "HTTP method (lowercase only).\n\nUse `patch` (not `get`) when a read operation needs a complex\n{@link requestBody}. `get` cannot have a request body."
}
},
required: [
"path",
"method"
],
description: "API endpoint information."
},
IAutoBePreliminaryGetInterfaceSchemas: {
type: "object",
properties: {
type: {
"const": "getInterfaceSchemas",
description: "Type discriminator."
},
typeNames: {
type: "array",
items: {
type: "string"
},
minItems: 1,
description: "Schema type names to retrieve. DO NOT request same names already requested\nin previous calls."
}
},
required: [
"type",
"typeNames"
],
description: "Request to retrieve OpenAPI schema type definitions for context."
},
"IAutoBeRealizeCollectorPlanApplication.IWrite": {
type: "object",
properties: {
type: {
"const": "write",
description: "Type discriminator for write submission."
},
plans: {
type: "array",
items: {
$ref: "#/components/schemas/IAutoBeRealizeCollectorPlanApplication.IPlan"
},
description: "Exactly ONE entry. databaseSchemaName non-null = collectable, null = no\ncollector needed."
}
},
required: [
"type",
"plans"
],
description: "Generates exactly ONE plan entry indicating collectable (has DB schema\nname) or not (null)."
},
"IAutoBeRealizeCollectorPlanApplication.IPlan": {
type: "object",
properties: {
dtoTypeName: {
type: "string",
description: "TypeScript interface type from the operation request body (e.g.,\n\"IShoppingSale.ICreate\")."
},
thinking: {
type: "string",
description: "Reasoning for this DTO's planning decision.\n\nCollectable: \"Collects IShoppingSale.ICreate to shopping_sales with\nnested category\".\n\nNon-collectable: \"IShoppingSale is read-only response DTO, not for\ncreation\"."
},
databaseSchemaName: {
oneOf: [
{
type: "null"
},
{
type: "string"
}
],
description: "Database table name if collectable (e.g., \"shopping_sales\"), null if\nnon-collectable (read-only DTO, computed type)."
},
references: {
type: "array",
items: {
$ref: "#/components/schemas/AutoBeRealizeCollectorReference"
},
description: "Referenced entities from path parameters or auth context.\n\nEach reference contains `databaseSchemaName` and `source` (e.g., \"from\npath parameter {id}\", \"from authorized actor\"). Empty array means the\nCreate DTO contains all necessary references."
}
},
required: [
"dtoTypeName",
"thinking",
"databaseSchemaName",
"references"
],
description: "Planning decision for one DTO."
},
AutoBeRealizeCollectorReference: {
type: "object",
properties: {
databaseSchemaName: {
type: "string",
description: "Prisma table name (e.g., \"shopping_sales\", \"shopping_customers\")."
},
source: {
type: "string",
description: "Source of this reference:\n\n- \"from path parameter {paramName}\" \u2014 URL path parameter\n- \"from authorized actor\" \u2014 logged-in user entity\n- \"from authorized session\" \u2014 current session entity"
}
},
required: [
"databaseSchemaName",
"source"
],
description: "External entity reference needed by a collector function.\n\nFK references not in the Create DTO come from path parameters or auth\ncontext. Each becomes an `IEntity` parameter in the collector's `collect()`\nsignature."
}
}
},
functions: [
{
name: "process",
async: false,
parameters: [
{
name: "props",
description: " Preliminary data request, write submission, or completion\nconfirmation",
required: true,
schema: {
$ref: "#/components/schemas/IAutoBeRealizeCollectorPlanApplication.IProps"
}
}
],
description: "Analyzes the given DTO type and generates a plan entry determining whether\na collector is needed. Returns exactly ONE plan entry."
}
]
},
kinds: [
"analysisSections",
"databaseSchemas",
"interfaceSchemas",
"interfaceOperations",
"complete",
],
local: {
analysisSections: ragSections,
interfaceOperations: props.document.operations.filter((op) => { var _a; return ((_a = op.requestBody) === null || _a === void 0 ? void 0 : _a.typeName) === props.dtoTypeName; }),
interfaceSchemas: Object.fromEntries(Object.entries(props.document.components.schemas).filter(([key]) => key === props.dtoTypeName)),
},
});
const event = yield preliminary.orchestrate(ctx, (out) => __awaiter(this, void 0, void 0, function* () {
var _a, _b;
const pointer = {
value: null,
};
const result = yield ctx.conversate(Object.assign({ source: "realizePlan", controller: createController({
prismaSchemaNames: props.prismaSchemaNames,
dtoTypeName: props.dtoTypeName,
build: (next) => {
pointer.value = next;
},
preliminary,
}), enforceFunctionCall: true, promptCacheKey: props.promptCacheKey }, (0, transformRealizeCollectorPlanHistory_1.transformRealizeCollectorPlanHistory)({
state: ctx.state(),
preliminary,
dtoTypeName: props.dtoTypeName,
})));
if (pointer.value === null)
return out(result)(null);
const plans = pointer.value.plans
.filter((p) => p.databaseSchemaName !== null)
.map((p) => ({
type: "collector",
dtoTypeName: p.dtoTypeName,
thinking: p.thinking,
databaseSchemaName: p.databaseSchemaName,
references: p.references,
}));
const event = {
type: "realizePlan",
id: (0, uuid_1.v4)(),
plans,
acquisition: preliminary.getAcquisition(),
metric: result.metric,
tokenUsage: result.tokenUsage,
completed: props.counter.get(),
total: props.progress.total,
step: (_b = (_a = ctx.state().analyze) === null || _a === void 0 ? void 0 : _a.step) !== null && _b !== void 0 ? _b : 0,
created_at: new Date().toISOString(),
};
return out(result)(event);
}));
ctx.dispatch(event);
return event.plans;
});
}
function createController(props) {
const validate = (input) => {
const result = (() => { const _io0 = input => "string" === typeof input.thinking && ("object" === typeof input.request && null !== input.request && _iu0(input.request)); const _io1 = input => "complete" === input.type; const _io2 = 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)))); const _io3 = input => "getDatabaseSchemas" === input.type && (Array.isArray(input.schemaNames) && (1 <= input.schemaNames.length && input.schemaNames.every(elem => "string" === typeof elem))); const _io4 = input => "getInterfaceOperations" === input.type && (Array.isArray(input.endpoints) && (1 <= input.endpoints.length && input.endpoints.every(elem => "object" === typeof elem && null !== elem && _io5(elem)))); const _io5 = 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 _io6 = input => "getInterfaceSchemas" === input.type && (Array.isArray(input.typeNames) && (1 <= input.typeNames.length && input.typeNames.every(elem => "string" === typeof elem))); const _io7 = input => "write" === input.type && (Array.isArray(input.plans) && input.plans.every(elem => "object" === typeof elem && null !== elem && _io8(elem))); const _io8 = input => "string" === typeof input.dtoTypeName && "string" === typeof input.thinking && (null === input.databaseSchemaName || "string" === typeof input.databaseSchemaName) && (Array.isArray(input.references) && input.references.every(elem => "object" === typeof elem && null !== elem && _io9(elem))); const _io9 = input => "string" === typeof input.databaseSchemaName && "string" === typeof input.source; const _iu0 = input => (() => {
if ("complete" === input.type)
return _io1(input);
else if ("getAnalysisSections" === input.type)
return _io2(input);
else if ("getDatabaseSchemas" === input.type)
return _io3(input);
else if ("getInterfaceOperations" === input.type)
return _io4(input);
else if ("getInterfaceSchemas" === input.type)
return _io6(input);
else if ("write" === input.type)
return _io7(input);
else
return false;
})(); const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.thinking || _report(_exceptionable, {
path: _path + ".thinking",
expected: "string",
value: input.thinking
}), ("object" === typeof input.request && null !== input.request || _report(_exceptionable, {
path: _path + ".request",
expected: "(IAutoBePreliminaryComplete | IAutoBePreliminaryGetAnalysisSections | IAutoBePreliminaryGetDatabaseSchemas | IAutoBePreliminaryGetInterfaceOperations | IAutoBePreliminaryGetInterfaceSchemas | IAutoBeRealizeCollectorPlanApplication.IWrite)",
value: input.request
})) && _vu0(input.request, _path + ".request", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".request",
expected: "(IAutoBePreliminaryComplete | IAutoBePreliminaryGetAnalysisSections | IAutoBePreliminaryGetDatabaseSchemas | IAutoBePreliminaryGetInterfaceOperations | IAutoBePreliminaryGetInterfaceSchemas | IAutoBeRealizeCollectorPlanApplication.IWrite)",
value: input.request
})].every(flag => flag); const _vo1 = (input, _path, _exceptionable = true) => ["complete" === input.type || _report(_exceptionable, {
path: _path + ".type",
expected: "\"complete\"",
value: input.type
})].every(flag => flag); const _vo2 = (input, _path, _exceptionable = true) => ["getAnalysisSections" === input.type || _report(_exceptionable, {
path: _path + ".type",
expected: "\"getAnalysisSections\"",
value: input.type
}), (Array.isArray(input.sectionIds) || _report(_exceptionable, {
path: _path + ".sectionIds",
expected: "(Array<number & Type<\"uint32\">> & MinItems<1> & MaxItems<100>)",
value: input.sectionIds
})) && ((1 <= input.sectionIds.length || _report(_exceptionable, {
path: _path + ".sectionIds",
expected: "Array<> & MinItems<1>",
value: input.sectionIds
})) && (input.sectionIds.length <= 100 || _report(_exceptionable, {
path: _path + ".sectionIds",
expected: "Array<> & MaxItems<100>",
value: input.sectionIds
})) && input.sectionIds.map((elem, _index7) => "number" === typeof elem && (__typia_transform__isTypeUint32._isTypeUint32(elem) || _report(_exceptionable, {
path: _path + ".sectionIds[" + _index7 + "]",
expected: "number & Type<\"uint32\">",
value: elem
})) || _report(_exceptionable, {
path: _path + ".sectionIds[" + _index7 + "]",
expected: "(number & Type<\"uint32\">)",
value: elem
})).every(flag => flag)) || _report(_exceptionable, {
path: _path + ".sectionIds",
expected: "(Array<number & Type<\"uint32\">> & MinItems<1> & MaxItems<100>)",
value: input.sectionIds
})].every(flag => flag); const _vo3 = (input, _path, _exceptionable = true) => ["getDatabaseSchemas" === input.type || _report(_exceptionable, {
path: _path + ".type",
expected: "\"getDatabaseSchemas\"",
value: input.type
}), (Array.isArray(input.schemaNames) || _report(_exceptionable, {
path: _path + ".schemaNames",
expected: "(Array<string> & MinItems<1>)",
value: input.schemaNames
})) && ((1 <= input.schemaNames.length || _report(_exceptionable, {
path: _path + ".schemaNames",
expected: "Array<> & MinItems<1>",
value: input.schemaNames
})) && input.schemaNames.map((elem, _index8) => "string" === typeof elem || _report(_exceptionable, {
path: _path + ".schemaNames[" + _index8 + "]",
expected: "string",
value: elem
})).every(flag => flag)) || _report(_exceptionable, {
path: _path + ".schemaNames",
expected: "(Array<string> & MinItems<1>)",
value: input.schemaNames
})].every(flag => flag); const _vo4 = (input, _path, _exceptionable = true) => ["getInterfaceOperations" === input.type || _report(_exceptionable, {
path: _path + ".type",
expected: "\"getInterfaceOperations\"",
value: input.type
}), (Array.isArray(input.endpoints) || _report(_exceptionable, {
path: _path + ".endpoints",
expected: "(Array<AutoBeOpenApi.IEndpoint> & MinItems<1>)",
value: input.endpoints
})) && ((1 <= input.endpoints.length || _report(_exceptionable, {
path: _path + ".endpoints",
expected: "Array<> & MinItems<1>",
value: input.endpoints
})) && input.endpoints.map((elem, _index9) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
path: _path + ".endpoints[" + _index9 + "]",
expected: "AutoBeOpenApi.IEndpoint",
value: elem
})) && _vo5(elem, _path + ".endpoints[" + _index9 + "]", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".endpoints[" + _index9 + "]",
expected: "AutoBeOpenApi.IEndpoint",
value: elem
})).every(flag => flag)) || _report(_exceptionable, {
path: _path + ".endpoints",
expected: "(Array<AutoBeOpenApi.IEndpoint> & MinItems<1>)",
value: input.endpoints
})].every(flag => flag); const _vo5 = (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 _vo6 = (input, _path, _exceptionable = true) => ["getInterfaceSchemas" === input.type || _report(_exceptionable, {
path: _path + ".type",
expected: "\"getInterfaceSchemas\"",
value: input.type
}), (Array.isArray(input.typeNames) || _report(_exceptionable, {
path: _path + ".typeNames",
expected: "(Array<string> & MinItems<1>)",
value: input.typeNames
})) && ((1 <= input.typeNames.length || _report(_exceptionable, {
path: _path + ".typeNames",
expected: "Array<> & MinItems<1>",
value: input.typeNames
})) && input.typeNames.map((elem, _index10) => "string" === typeof elem || _report(_exceptionable, {
path: _path + ".typeNames[" + _index10 + "]",
expected: "string",
value: elem
})).every(flag => flag)) || _report(_exceptionable, {
path: _path + ".typeNames",
expected: "(Array<string> & MinItems<1>)",
value: input.typeNames
})].every(flag => flag); const _vo7 = (input, _path, _exceptionable = true) => ["write" === input.type || _report(_exceptionable, {
path: _path + ".type",
expected: "\"write\"",
value: input.type
}), (Array.isArray(input.plans) || _report(_exceptionable, {
path: _path + ".plans",
expected: "Array<IAutoBeRealizeCollectorPlanApplication.IPlan>",
value: input.plans
})) && input.plans.map((elem, _index11) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
path: _path + ".plans[" + _index11 + "]",
expected: "IAutoBeRealizeCollectorPlanApplication.IPlan",
value: elem
})) && _vo8(elem, _path + ".plans[" + _index11 + "]", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".plans[" + _index11 + "]",
expected: "IAutoBeRealizeCollectorPlanApplication.IPlan",
value: elem
})).every(flag => flag) || _report(_exceptionable, {
path: _path + ".plans",
expected: "Array<IAutoBeRealizeCollectorPlanApplication.IPlan>",
value: input.plans
})].every(flag => flag); const _vo8 = (input, _path, _exceptionable = true) => ["string" === typeof input.dtoTypeName || _report(_exceptionable, {
path: _path + ".dtoTypeName",
expected: "string",
value: input.dtoTypeName
}), "string" === typeof input.thinking || _report(_exceptionable, {
path: _path + ".thinking",
expected: "string",
value: input.thinking
}), null === input.databaseSchemaName || "string" === typeof input.databaseSchemaName || _report(_exceptionable, {
path: _path + ".databaseSchemaName",
expected: "(null | string)",
value: input.databaseSchemaName
}), (Array.isArray(input.references) || _report(_exceptionable, {
path: _path + ".references",
expected: "Array<AutoBeRealizeCollectorReference>",
value: input.references
})) && input.references.map((elem, _index12) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
path: _path + ".references[" + _index12 + "]",
expected: "AutoBeRealizeCollectorReference",
value: elem
})) && _vo9(elem, _path + ".references[" + _index12 + "]", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".references[" + _index12 + "]",
expected: "AutoBeRealizeCollectorReference",
value: elem
})).every(flag => flag) || _report(_exceptionable, {
path: _path + ".references",
expected: "Array<AutoBeRealizeCollectorReference>",
value: input.references
})].every(flag => flag); const _vo9 = (input, _path, _exceptionable = true) => ["string" === typeof input.databaseSchemaName || _report(_exceptionable, {
path: _path + ".databaseSchemaName",
expected: "string",
value: input.databaseSchemaName
}), "string" === typeof input.source || _report(_exceptionable, {
path: _path + ".source",
expected: "string",
value: input.source
})].every(flag => flag); const _vu0 = (input, _path, _exceptionable = true) => (() => {
if ("complete" === input.type)
return _vo1(input, _path, true && _exceptionable);
else if ("getAnalysisSections" === input.type)
return _vo2(input, _path, true && _exceptionable);
else if ("getDatabaseSchemas" === input.type)
return _vo3(input, _path, true && _exceptionable);
else if ("getInterfaceOperations" === input.type)
return _vo4(input, _path, true && _exceptionable);
else if ("getInterfaceSchemas" === input.type)
return _vo6(input, _path, true && _exceptionable);
else if ("write" === input.type)
return _vo7(input, _path, true && _exceptionable);
else
return _report(_exceptionable, {
path: _path,
expected: "(IAutoBePreliminaryComplete | IAutoBePreliminaryGetAnalysisSections | IAutoBePreliminaryGetDatabaseSchemas | IAutoBePreliminaryGetInterfaceOperations | IAutoBePreliminaryGetInterfaceSchemas | IAutoBeRealizeCollectorPlanApplication.IWrite)",
value: input
});
})(); 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: "IAutoBeRealizeCollectorPlanApplication.IProps",
value: input
})) && _vo0(input, _path + "", true) || _report(true, {
path: _path + "",
expected: "IAutoBeRealizeCollectorPlanApplication.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
};
}; })()(input);
if (result.success === false)
return result;
else if (result.data.request.type !== "write")
return props.preliminary.validate({
thinking: result.data.thinking,
request: result.data.request,
});
const errors = [];
result.data.request.plans.map((plan, i) => {
if (props.dtoTypeName !== plan.dtoTypeName)
errors.push({
path: `$input.request.plans[${i}].dtoTypeName`,
value: plan.dtoTypeName,
expected: JSON.stringify(props.dtoTypeName),
description: utils_1.StringUtil.trim `
The DTO type name must be ${JSON.stringify(props.dtoTypeName)}.
If you have planned other DTO type's collector,
please entirely remake the plan with ONLY the DTO type
${JSON.stringify(props.dtoTypeName)}.
`,
});
if (plan.databaseSchemaName !== null &&
props.prismaSchemaNames.has(plan.databaseSchemaName) === false)
errors.push({
path: `$input.request.plans[${i}].databaseSchemaName`,
value: plan.databaseSchemaName,
expected: Array.from(props.prismaSchemaNames)
.map((s) => JSON.stringify(s))
.join(" | "),
description: utils_1.StringUtil.trim `
The database schema name must be one of the available database schemas.
${Array.from(props.prismaSchemaNames)
.map((s) => `- ${s}`)
.join("\n")}
`,
});
});
return errors.length
? {
success: false,
errors,
data: result.data,
}
: result;
};
const application = props.preliminary.fixApplication(__typia_transform__llmApplicationFinalize._llmApplicationFinalize({
functions: [
{
name: "process",
parameters: {
description: "Current Type: {@link IAutoBeRealizeCollectorPlanApplication.IProps}",
type: "object",
properties: {
thinking: {
description: "Think before you act.\n\nFor preliminary requests: what schemas (database, DTO, operations) are\nmissing?\n\nFor write: is this DTO collectable or non-collectable? What database\ntable does it map to (if collectable)?\n\nFor complete: why you consider the decision final.",
type: "string"
},
request: {
description: "Action to perform. Exhausted preliminary types are removed from the\nunion, physically preventing repeated calls.",
anyOf: [
{
$ref: "#/$defs/IAutoBePreliminaryComplete"
},
{
$ref: "#/$defs/IAutoBePreliminaryGetAnalysisSections"
},
{
$ref: "#/$defs/IAutoBePreliminaryGetDatabaseSchemas"
},
{
$ref: "#/$defs/IAutoBePreliminaryGetInterfaceOperations"
},
{
$ref: "#/$defs/IAutoBePreliminaryGetInterfaceSchemas"
},
{
$ref: "#/$defs/IAutoBeRealizeCollectorPlanApplication.IWrite"
}
],
"x-discriminator": {
propertyName: "type",
mapping: {
complete: "#/$defs/IAutoBePreliminaryComplete",
getAnalysisSections: "#/$defs/IAutoBePreliminaryGetAnalysisSections",
getDatabaseSchemas: "#/$defs/IAutoBePreliminaryGetDatabaseSchemas",
getInterfaceOperations: "#/$defs/IAutoBePreliminaryGetInterfaceOperations",
getInterfaceSchemas: "#/$defs/IAutoBePreliminaryGetInterfaceSchemas",
write: "#/$defs/IAutoBeRealizeCollectorPlanApplication.IWrite"
}
}
}
},
required: [
"thinking",
"request"
],
additionalProperties: false,
$defs: {
IAutoBePreliminaryComplete: {
description: "Finalize the write loop by accepting your most recent `write` as-is.\n\nAfter submitting a `write`, review it yourself thoroughly against the review\nchecklist in your instructions. If you find issues worth fixing, submit\nanother `write` with corrections. When you are satisfied with the quality,\ncall `complete` to finalize.\n\nYou have a maximum of 3 write attempts, but this is a safety cap \u2014 not a\ntarget to fill.\n\nOnly valid after at least one `write` submission \u2014 rejected otherwise.",
type: "object",
properties: {
type: {
description: "Type discriminator for completion request.",
type: "string",
"enum": [
"complete"
]
}
},
required: [
"type"
]
},
IAutoBePreliminaryGetAnalysisSections: {
description: "Request to retrieve individual analysis sections by numeric ID.",
type: "object",
properties: {
type: {
description: "Type discriminator.",
type: "string",
"enum": [
"getAnalysisSections"
]
},
sectionIds: {
description: "Section IDs to retrieve. DO NOT request same IDs already requested in\nprevious calls.",
type: "array",
items: {
type: "integer",
minimum: 0
},
minItems: 1,
maxItems: 100
}
},
required: [
"type",
"sectionIds"
]
},
IAutoBePreliminaryGetDatabaseSchemas: {
description: "Request to retrieve database schema definitions for context.",
type: "object",