@autobe/agent
Version:
AI backend server code generator
873 lines (872 loc) • 65.3 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __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.orchestrateRealizeOperationWrite = orchestrateRealizeOperationWrite;
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 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 validateEmptyCode_1 = require("../../utils/validateEmptyCode");
const AutoBePreliminaryController_1 = require("../common/AutoBePreliminaryController");
const convertToSectionEntries_1 = require("../common/internal/convertToSectionEntries");
const transformRealizeOperationWriteHistory_1 = require("./histories/transformRealizeOperationWriteHistory");
const AutoBeRealizeOperationProgrammer_1 = require("./programmers/AutoBeRealizeOperationProgrammer");
function orchestrateRealizeOperationWrite(ctx, props) {
return __awaiter(this, void 0, void 0, function* () {
const document = ctx.state().interface.document;
const allScenarios = document.operations.map((operation) => AutoBeRealizeOperationProgrammer_1.AutoBeRealizeOperationProgrammer.getScenario({
authorizations: props.authorizations,
operation,
}));
const scenarios = props.targetEndpoints
? allScenarios.filter((s) => props.targetEndpoints.some((e) => e.method === s.operation.method && e.path === s.operation.path))
: allScenarios;
return yield (0, executeCachedBatch_1.executeCachedBatch)(ctx, scenarios.map((s) => {
const counter = new tstl_1.Singleton(() => ++props.progress.completed);
return (promptCacheKey) => __awaiter(this, void 0, void 0, function* () {
try {
return yield (0, forceRetry_1.forceRetry)(() => {
var _a;
return process(ctx, {
document,
totalAuthorizations: props.authorizations,
collectors: props.collectors,
transformers: props.transformers,
authorization: (_a = s.decoratorEvent) !== null && _a !== void 0 ? _a : null,
scenario: s,
progress: props.progress,
counter,
promptCacheKey,
});
});
}
catch (error) {
counter.get();
throw error;
}
});
}));
});
}
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 pathSegments = props.scenario.operation.path
.split("/")
.filter((p) => p && !p.startsWith(":") && !p.startsWith("{"));
const queryText = [
"operation",
"write",
props.scenario.operation.method,
...pathSegments,
props.scenario.functionName,
].join(" ");
const ragSections = yield (0, RAGRetrieval_1.buildAnalysisContextSections)((0, getEmbedder_1.getEmbedder)(), allSections, queryText, "TOPK", { log: false, logPrefix: "realizeOperationWrite" });
const preliminary = new AutoBePreliminaryController_1.AutoBePreliminaryController({
source: SOURCE,
application: {
version: "3.1",
components: {
schemas: {
"IAutoBeRealizeOperationWriteApplication.IProps": {
type: "object",
properties: {
thinking: {
type: "string",
description: "Think before you act.\n\nFor preliminary requests: what information is missing and why?\n\nFor write: what you're submitting and key decisions made.\n\nFor complete: why you consider the last write final."
},
request: {
oneOf: [
{
$ref: "#/components/schemas/IAutoBePreliminaryComplete"
},
{
$ref: "#/components/schemas/IAutoBePreliminaryGetAnalysisSections"
},
{
$ref: "#/components/schemas/IAutoBePreliminaryGetDatabaseSchemas"
},
{
$ref: "#/components/schemas/IAutoBePreliminaryGetRealizeTransformers"
},
{
$ref: "#/components/schemas/IAutoBePreliminaryGetRealizeCollectors"
},
{
$ref: "#/components/schemas/IAutoBeRealizeOperationWriteApplication.IWrite"
}
],
discriminator: {
propertyName: "type",
mapping: {
complete: "#/components/schemas/IAutoBePreliminaryComplete",
getAnalysisSections: "#/components/schemas/IAutoBePreliminaryGetAnalysisSections",
getDatabaseSchemas: "#/components/schemas/IAutoBePreliminaryGetDatabaseSchemas",
getRealizeTransformers: "#/components/schemas/IAutoBePreliminaryGetRealizeTransformers",
getRealizeCollectors: "#/components/schemas/IAutoBePreliminaryGetRealizeCollectors",
write: "#/components/schemas/IAutoBeRealizeOperationWriteApplication.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."
},
IAutoBePreliminaryGetRealizeTransformers: {
type: "object",
properties: {
type: {
"const": "getRealizeTransformers",
description: "Type discriminator."
},
dtoTypeNames: {
type: "array",
items: {
type: "string"
},
minItems: 1,
description: "Transformer DTO type names to retrieve. DO NOT request same names already\nrequested in previous calls."
}
},
required: [
"type",
"dtoTypeNames"
],
description: "Request to retrieve Realize Transformer function definitions for context."
},
IAutoBePreliminaryGetRealizeCollectors: {
type: "object",
properties: {
type: {
"const": "getRealizeCollectors",
description: "Type discriminator."
},
dtoTypeNames: {
type: "array",
items: {
type: "string"
},
minItems: 1,
description: "Collector DTO type names to retrieve. DO NOT request same names already\nrequested in previous calls."
}
},
required: [
"type",
"dtoTypeNames"
],
description: "Request to retrieve Realize Collector function definitions for context."
},
"IAutoBeRealizeOperationWriteApplication.IWrite": {
type: "object",
properties: {
type: {
"const": "write",
description: "Type discriminator for write submission."
},
plan: {
type: "string",
description: "Operation implementation plan. Analyze requirements, identify related\ndatabase schemas, and outline implementation approach including schema\nvalidation and API contract verification."
},
draft: {
type: "string",
description: "First complete implementation attempt based on the plan."
},
revise: {
$ref: "#/components/schemas/IAutoBeRealizeOperationWriteApplication.IReviseProps",
description: "Reviews draft and produces final code."
}
},
required: [
"type",
"plan",
"draft",
"revise"
],
description: "Generate operation implementation via plan/draft/revise."
},
"IAutoBeRealizeOperationWriteApplication.IReviseProps": {
type: "object",
properties: {
review: {
type: "string",
description: "Identify improvements:\n\n- Type safety enhancements\n- Database query optimizations\n- Null/undefined handling corrections\n- Authentication/authorization improvements\n- Error handling refinements"
},
final: {
oneOf: [
{
type: "null"
},
{
type: "string"
}
],
description: "Final operation function code with all review improvements applied, or\nnull if draft needs no changes."
}
},
required: [
"review",
"final"
]
}
}
},
functions: [
{
name: "process",
async: false,
parameters: [
{
name: "props",
description: " Preliminary data request, write submission, or completion\nconfirmation",
required: true,
schema: {
$ref: "#/components/schemas/IAutoBeRealizeOperationWriteApplication.IProps"
}
}
],
description: "Process operation function generation task."
}
]
},
kinds: [
"analysisSections",
"databaseSchemas",
"realizeCollectors",
"realizeTransformers",
"complete",
],
dispatch: (e) => ctx.dispatch(e),
state: ctx.state(),
all: {
realizeCollectors: props.collectors,
realizeTransformers: props.transformers,
},
local: {
realizeCollectors: props.collectors.filter((c) => { var _a; return c.plan.dtoTypeName === ((_a = props.scenario.operation.requestBody) === null || _a === void 0 ? void 0 : _a.typeName); }),
realizeTransformers: AutoBeRealizeOperationProgrammer_1.AutoBeRealizeOperationProgrammer.getLocalTransformers({
operation: props.scenario.operation,
schemas: props.document.components.schemas,
transformers: props.transformers,
}),
analysisSections: ragSections,
},
});
const event = yield preliminary.orchestrate(ctx, (out) => __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d;
const pointer = {
value: null,
};
const dto = yield AutoBeRealizeOperationProgrammer_1.AutoBeRealizeOperationProgrammer.writeStructures(ctx, props.scenario.operation);
const result = yield ctx.conversate(Object.assign({ source: "realizeWrite", controller: createController({
functionName: props.scenario.functionName,
build: (next) => {
pointer.value = next;
},
preliminary,
}), enforceFunctionCall: true, promptCacheKey: props.promptCacheKey }, (0, transformRealizeOperationWriteHistory_1.transformRealizeOperationWriteHistory)({
state: ctx.state(),
scenario: props.scenario,
authorization: props.authorization,
totalAuthorizations: props.totalAuthorizations,
collectors: props.collectors,
transformers: props.transformers,
dto,
preliminary,
})));
if (pointer.value === null)
return out(result)(null);
const template = AutoBeRealizeOperationProgrammer_1.AutoBeRealizeOperationProgrammer.writeTemplate({
authorizations: props.totalAuthorizations,
schemas: props.document.components.schemas,
operation: props.scenario.operation,
collectors: props.collectors,
transformers: props.transformers,
});
const functor = {
type: "operation",
endpoint: {
method: props.scenario.operation.method,
path: props.scenario.operation.path,
},
location: props.scenario.location,
name: props.scenario.functionName,
content: yield AutoBeRealizeOperationProgrammer_1.AutoBeRealizeOperationProgrammer.replaceImportStatements(ctx, {
operation: props.scenario.operation,
schemas: props.document.components.schemas,
code: (_a = pointer.value.revise.final) !== null && _a !== void 0 ? _a : pointer.value.draft,
payload: (_b = props.authorization) === null || _b === void 0 ? void 0 : _b.payload.name,
}),
template,
};
return out(result)({
id: (0, uuid_1.v7)(),
type: "realizeWrite",
function: functor,
acquisition: preliminary.getAcquisition(),
metric: result.metric,
tokenUsage: result.tokenUsage,
completed: props.counter.get(),
total: props.progress.total,
step: (_d = (_c = ctx.state().analyze) === null || _c === void 0 ? void 0 : _c.step) !== null && _d !== void 0 ? _d : 0,
created_at: new Date().toISOString(),
});
}));
ctx.dispatch(event);
return event.function;
});
}
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 => "getRealizeCollectors" === input.type && (Array.isArray(input.dtoTypeNames) && (1 <= input.dtoTypeNames.length && input.dtoTypeNames.every(elem => "string" === typeof elem))); const _io5 = input => "getRealizeTransformers" === input.type && (Array.isArray(input.dtoTypeNames) && (1 <= input.dtoTypeNames.length && input.dtoTypeNames.every(elem => "string" === typeof elem))); const _io6 = input => "write" === input.type && "string" === typeof input.plan && "string" === typeof input.draft && ("object" === typeof input.revise && null !== input.revise && _io7(input.revise)); const _io7 = input => "string" === typeof input.review && (null === input.final || "string" === typeof input.final); 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 ("getRealizeTransformers" === input.type)
return _io5(input);
else if ("getRealizeCollectors" === input.type)
return _io4(input);
else if ("write" === input.type)
return _io6(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 | IAutoBePreliminaryGetRealizeCollectors | IAutoBePreliminaryGetRealizeTransformers | IAutoBeRealizeOperationWriteApplication.IWrite)",
value: input.request
})) && _vu0(input.request, _path + ".request", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".request",
expected: "(IAutoBePreliminaryComplete | IAutoBePreliminaryGetAnalysisSections | IAutoBePreliminaryGetDatabaseSchemas | IAutoBePreliminaryGetRealizeCollectors | IAutoBePreliminaryGetRealizeTransformers | IAutoBeRealizeOperationWriteApplication.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, _index5) => "number" === typeof elem && (__typia_transform__isTypeUint32._isTypeUint32(elem) || _report(_exceptionable, {
path: _path + ".sectionIds[" + _index5 + "]",
expected: "number & Type<\"uint32\">",
value: elem
})) || _report(_exceptionable, {
path: _path + ".sectionIds[" + _index5 + "]",
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, _index6) => "string" === typeof elem || _report(_exceptionable, {
path: _path + ".schemaNames[" + _index6 + "]",
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) => ["getRealizeCollectors" === input.type || _report(_exceptionable, {
path: _path + ".type",
expected: "\"getRealizeCollectors\"",
value: input.type
}), (Array.isArray(input.dtoTypeNames) || _report(_exceptionable, {
path: _path + ".dtoTypeNames",
expected: "(Array<string> & MinItems<1>)",
value: input.dtoTypeNames
})) && ((1 <= input.dtoTypeNames.length || _report(_exceptionable, {
path: _path + ".dtoTypeNames",
expected: "Array<> & MinItems<1>",
value: input.dtoTypeNames
})) && input.dtoTypeNames.map((elem, _index7) => "string" === typeof elem || _report(_exceptionable, {
path: _path + ".dtoTypeNames[" + _index7 + "]",
expected: "string",
value: elem
})).every(flag => flag)) || _report(_exceptionable, {
path: _path + ".dtoTypeNames",
expected: "(Array<string> & MinItems<1>)",
value: input.dtoTypeNames
})].every(flag => flag); const _vo5 = (input, _path, _exceptionable = true) => ["getRealizeTransformers" === input.type || _report(_exceptionable, {
path: _path + ".type",
expected: "\"getRealizeTransformers\"",
value: input.type
}), (Array.isArray(input.dtoTypeNames) || _report(_exceptionable, {
path: _path + ".dtoTypeNames",
expected: "(Array<string> & MinItems<1>)",
value: input.dtoTypeNames
})) && ((1 <= input.dtoTypeNames.length || _report(_exceptionable, {
path: _path + ".dtoTypeNames",
expected: "Array<> & MinItems<1>",
value: input.dtoTypeNames
})) && input.dtoTypeNames.map((elem, _index8) => "string" === typeof elem || _report(_exceptionable, {
path: _path + ".dtoTypeNames[" + _index8 + "]",
expected: "string",
value: elem
})).every(flag => flag)) || _report(_exceptionable, {
path: _path + ".dtoTypeNames",
expected: "(Array<string> & MinItems<1>)",
value: input.dtoTypeNames
})].every(flag => flag); const _vo6 = (input, _path, _exceptionable = true) => ["write" === input.type || _report(_exceptionable, {
path: _path + ".type",
expected: "\"write\"",
value: input.type
}), "string" === typeof input.plan || _report(_exceptionable, {
path: _path + ".plan",
expected: "string",
value: input.plan
}), "string" === typeof input.draft || _report(_exceptionable, {
path: _path + ".draft",
expected: "string",
value: input.draft
}), ("object" === typeof input.revise && null !== input.revise || _report(_exceptionable, {
path: _path + ".revise",
expected: "IAutoBeRealizeOperationWriteApplication.IReviseProps",
value: input.revise
})) && _vo7(input.revise, _path + ".revise", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".revise",
expected: "IAutoBeRealizeOperationWriteApplication.IReviseProps",
value: input.revise
})].every(flag => flag); const _vo7 = (input, _path, _exceptionable = true) => ["string" === typeof input.review || _report(_exceptionable, {
path: _path + ".review",
expected: "string",
value: input.review
}), null === input.final || "string" === typeof input.final || _report(_exceptionable, {
path: _path + ".final",
expected: "(null | string)",
value: input.final
})].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 ("getRealizeTransformers" === input.type)
return _vo5(input, _path, true && _exceptionable);
else if ("getRealizeCollectors" === input.type)
return _vo4(input, _path, true && _exceptionable);
else if ("write" === input.type)
return _vo6(input, _path, true && _exceptionable);
else
return _report(_exceptionable, {
path: _path,
expected: "(IAutoBePreliminaryComplete | IAutoBePreliminaryGetAnalysisSections | IAutoBePreliminaryGetDatabaseSchemas | IAutoBePreliminaryGetRealizeTransformers | IAutoBePreliminaryGetRealizeCollectors | IAutoBeRealizeOperationWriteApplication.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: "IAutoBeRealizeOperationWriteApplication.IProps",
value: input
})) && _vo0(input, _path + "", true) || _report(true, {
path: _path + "",
expected: "IAutoBeRealizeOperationWriteApplication.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 = [
...(0, validateEmptyCode_1.validateEmptyCode)({
name: props.functionName,
draft: result.data.request.draft,
revise: result.data.request.revise,
path: "$input.request",
asynchronous: true,
}),
...AutoBeRealizeOperationProgrammer_1.AutoBeRealizeOperationProgrammer.validateSelectTransformContract({
draft: result.data.request.draft,
revise: result.data.request.revise,
}),
];
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 IAutoBeRealizeOperationWriteApplication.IProps}",
type: "object",
properties: {
thinking: {
description: "Think before you act.\n\nFor preliminary requests: what information is missing and why?\n\nFor write: what you're submitting and key decisions made.\n\nFor complete: why you consider the last write 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/IAutoBePreliminaryGetRealizeTransformers"
},
{
$ref: "#/$defs/IAutoBePreliminaryGetRealizeCollectors"
},
{
$ref: "#/$defs/IAutoBeRealizeOperationWriteApplication.IWrite"
}
],
"x-discriminator": {
propertyName: "type",
mapping: {
complete: "#/$defs/IAutoBePreliminaryComplete",
getAnalysisSections: "#/$defs/IAutoBePreliminaryGetAnalysisSections",
getDatabaseSchemas: "#/$defs/IAutoBePreliminaryGetDatabaseSchemas",
getRealizeTransformers: "#/$defs/IAutoBePreliminaryGetRealizeTransformers",
getRealizeCollectors: "#/$defs/IAutoBePreliminaryGetRealizeCollectors",
write: "#/$defs/IAutoBeRealizeOperationWriteApplication.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",
properties: {
type: {
description: "Type discriminator.",
type: "string",
"enum": [
"getDatabaseSchemas"
]
},
schemaNames: {
description: "Database table names to retrieve. DO NOT request same names already\nrequested in previous calls.",
type: "array",
items: {
type: "string"
},
minItems: 1
}
},
required: [
"type",
"schemaNames"
]
},
IAutoBePreliminaryGetRealizeTransformers: {
description: "Request to retrieve Realize Transformer function definitions for context.",
type: "object",
properties: {
type: {
description: "Type discriminator.",
type: "string",
"enum": [
"getRealizeTransformers"
]
},
dtoTypeNames: {
description: "Transformer DTO type names to retrieve. DO NOT request same names already\nrequested in previous calls.",
type: "array",
items: {
type: "string"
},
minItems: 1
}
},
required: [
"type",
"dtoTypeNames"
]
},
IAutoBePreliminaryGetRealizeCollectors: {
description: "Request to retrieve Realize Collector function definitions for context.",
type: "object",
properties: {
type: {
description: "Type discriminator.",
type: "string",
"enum": [
"getRealizeCollectors"
]
},
dtoTypeNames: {
description: "Collector DTO type names to retrieve. DO NOT request same names already\nrequested in previous calls.",
type: "array",
items: {
type: "string"
},
minItems: 1
}
},
required: [
"type",
"dtoTypeNames"
]
},
"IAutoBeRealizeOperationWriteApplication.IWrite": {
description: "Generate operation implementation via plan/draft/revise.",
type: "object",
properties: {
type: {
description: "Type discriminator for write submission.",
type: "string",
"enum": [
"write"
]
},
plan: {
description: "Operation implementation plan. Analyze requirements, identify related\ndatabase schemas, and outline implementation approach including schema\nvalidation and API contract verification.",
type: "string"
},
draft: {
description: "First complete implementation attempt based on the plan.",
type: "string"
},
revise: {
description: "Reviews draft and produces final code.",
$ref: "#/$defs/IAutoBeRealizeOperationWriteApplication.IReviseProps"
}
},
required: [
"type",
"plan",
"draft",
"revise"
]
},
"IAutoBeRealizeOperationWriteApplication.IReviseProps": {
type: "object",
properties: {
review: {
description: "Identify improvements:\n\n- Type safety enhancements\n- Database query optimizations\n- Null/undefined handling corrections\n- Authentication/authorization improvements\n- Error handling refinements",
type: "string"
},
final: {
description: "Final operation function code with all review improvements applied, or\nnull if draft needs no changes.",
anyOf: [
{
type: "null"
},
{
type: "string"
}