@autobe/agent
Version:
AI backend server code generator
732 lines • 72.1 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.orchestrateRealizeTransformerWrite = orchestrateRealizeTransformerWrite;
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 executeCachedBatch_1 = require("../../utils/executeCachedBatch");
const forceRetry_1 = require("../../utils/forceRetry");
const AutoBePreliminaryController_1 = require("../common/AutoBePreliminaryController");
const transformRealizeTransformerWriteHistory_1 = require("./histories/transformRealizeTransformerWriteHistory");
const AutoBeRealizeTransformerProgrammer_1 = require("./programmers/AutoBeRealizeTransformerProgrammer");
function orchestrateRealizeTransformerWrite(ctx, props) {
return __awaiter(this, void 0, void 0, function* () {
const history = ctx.state().interface;
if (history === null)
throw new Error("Cannot realize transformer write without interface.");
const document = history.document;
const getNeighbors = (plan) => {
const visited = new Set();
utils_1.AutoBeOpenApiTypeChecker.visit({
components: document.components,
schema: { $ref: `#/components/schemas/${plan.dtoTypeName}` },
closure: (next) => {
if (utils_1.AutoBeOpenApiTypeChecker.isReference(next)) {
const key = next.$ref.split("/").pop();
visited.add(key);
}
},
});
return props.plans.filter((p) => p.dtoTypeName !== plan.dtoTypeName && visited.has(p.dtoTypeName));
};
props.progress.total += props.plans.length;
return yield (0, executeCachedBatch_1.executeCachedBatch)(ctx, props.plans.map((x) => {
const counter = new tstl_1.Singleton(() => ++props.progress.completed);
return (promptCacheKey) => (0, forceRetry_1.forceRetry)(() => process(ctx, {
progress: props.progress,
counter,
neighbors: getNeighbors(x),
plan: x,
promptCacheKey,
}));
}));
});
}
function process(ctx, props) {
return __awaiter(this, void 0, void 0, function* () {
const models = ctx
.state()
.database.result.data.files.map((f) => f.models)
.flat();
const document = ctx.state().interface.document;
const dtoTypeName = props.plan.dtoTypeName;
const preliminary = new AutoBePreliminaryController_1.AutoBePreliminaryController({
dispatch: (e) => ctx.dispatch(e),
state: ctx.state(),
source: SOURCE,
application: {
version: "3.1",
components: {
schemas: {
"IAutoBeRealizeTransformerWriteApplication.IProps": {
type: "object",
properties: {
thinking: {
type: "string",
description: "Think before you act.\n\nFor preliminary requests: what database schemas are missing and why?\n\nFor write: what you're submitting and key mapping decisions.\n\nFor complete: why you consider the last write final.\n\nNote: All DTO type information is available transitively from the plan's\nDTO type names. You only need to request database schemas."
},
request: {
oneOf: [
{
$ref: "#/components/schemas/IAutoBePreliminaryComplete"
},
{
$ref: "#/components/schemas/IAutoBePreliminaryGetDatabaseSchemas"
},
{
$ref: "#/components/schemas/IAutoBeRealizeTransformerWriteApplication.IWrite"
}
],
discriminator: {
propertyName: "type",
mapping: {
complete: "#/components/schemas/IAutoBePreliminaryComplete",
getDatabaseSchemas: "#/components/schemas/IAutoBePreliminaryGetDatabaseSchemas",
write: "#/components/schemas/IAutoBeRealizeTransformerWriteApplication.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."
},
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."
},
"IAutoBeRealizeTransformerWriteApplication.IWrite": {
type: "object",
properties: {
type: {
"const": "write",
description: "Type discriminator for write submission."
},
plan: {
type: "string",
description: "Transformer implementation plan. MUST contain four sections:\n\n1. Database Schema Field Inventory \u2014 ALL fields with exact names from schema\n2. DTO Property Inventory \u2014 ALL properties with types\n3. Field-by-Field Mapping Strategy \u2014 explicit table for BOTH select() and\n transform()\n4. Edge Cases and Special Handling \u2014 type casts (Decimal, DateTime),\n nullables\n\nThis forces you to READ the actual schema (not imagine it) and creates an\nexplicit specification for both select() and transform() functions."
},
selectMappings: {
type: "array",
items: {
$ref: "#/components/schemas/AutoBeRealizeTransformerSelectMapping"
},
description: "Database field-by-field selection mapping for select().\n\nMUST include EVERY database field needed by transform() \u2014 no exceptions.\nEach mapping specifies:\n\n- `member`: Exact Prisma field/relation name (snake_case) \u2014 read from the\n Relation Mapping Table and member list, NOT from DTO property names\n- `kind`: scalar, belongsTo, hasOne, or hasMany\n- `nullable`: true/false for scalar/belongsTo, null for hasMany/hasOne\n- `how`: Which DTO property needs it\n\nThe `kind` property forces explicit classification of each member BEFORE\ndeciding select syntax, preventing confusion between scalars and\nrelations.\n\nMissing even a single required field will cause validation failure."
},
transformMappings: {
type: "array",
items: {
$ref: "#/components/schemas/AutoBeRealizeTransformerTransformMapping"
},
description: "DTO property-by-property transformation mapping for transform().\n\nMUST include EVERY property from the DTO type definition \u2014 no exceptions.\nEach mapping specifies:\n\n- `property`: Exact DTO property name (camelCase)\n- `how`: How to obtain from Prisma payload\n\n**Common transformation patterns**:\n\n- Direct mapping: snake_case \u2192 camelCase\n- Type conversion: Decimal \u2192 Number, DateTime \u2192 ISO string\n- Nullable: DateTime? \u2192 string | null\n- Nested objects: Reuse neighbor transformers\n- Arrays: ArrayUtil.asyncMap + neighbor transformer\n\nMissing even a single property will cause validation failure."
},
draft: {
type: "string",
description: "Complete implementation following plan's mapping table. EVERY field from\nplan Section 3 MUST appear in BOTH select() and transform(). Implement:\n\n- Transform() first, select() second, Payload last (correct order)\n- All field mappings from plan with correct transformations\n- Neighbor transformer reuse (NEVER inline when transformer exists)\n- ALWAYS use `select`, NEVER use `include`"
},
revise: {
$ref: "#/components/schemas/IAutoBeRealizeTransformerWriteApplication.IReviseProps",
description: "Reviews draft and produces final code."
}
},
required: [
"type",
"plan",
"selectMappings",
"transformMappings",
"draft",
"revise"
],
description: "Generate transformer module (select + transform functions) via\nplan/draft/revise."
},
AutoBeRealizeTransformerSelectMapping: {
type: "object",
properties: {
member: {
type: "string",
description: "Exact Prisma field or relation name from the Prisma schema.\n\nMUST match the Prisma schema exactly (case-sensitive, snake_case).\n\n**Field Types**:\n\n- **Scalar fields**: Database columns (id, email, created_at, unit_price)\n- **BelongsTo relations**: FK relations (customer, article, category)\n- **HasMany relations**: 1:N arrays (tags, comments, reviews)\n- **Aggregations**: Prisma computed fields (_count, _sum, _avg)\n\n**Examples**:\n\n```typescript\n// Scalar fields\n{ member: \"id\", kind: \"scalar\", nullable: false, how: \"For DTO.id\" }\n{ member: \"created_at\", kind: \"scalar\", nullable: false, how: \"For DTO.createdAt (needs .toISOString())\" }\n{ member: \"unit_price\", kind: \"scalar\", nullable: false, how: \"For DTO.price (Decimal \u2192 Number)\" }\n{ member: \"deleted_at\", kind: \"scalar\", nullable: true, how: \"For DTO.deletedAt (nullable DateTime)\" }\n\n// BelongsTo relations \u2014 member is ALWAYS the Prisma relation name,\n// which may differ from the DTO property name\n{ member: \"customer\", kind: \"belongsTo\", nullable: false, how: \"For DTO.buyer (nested transformer)\" }\n{ member: \"user\", kind: \"belongsTo\", nullable: true, how: \"For DTO.voter (optional nested)\" }\n\n// HasMany relations\n{ member: \"tags\", kind: \"hasMany\", nullable: null, how: \"For DTO.tags (array transformer)\" }\n```\n\nDO NOT use DTO property names \u2014 this is about Prisma schema members. Read\nthe Relation Mapping Table and member list to find correct names."
},
kind: {
oneOf: [
{
"const": "scalar"
},
{
"const": "belongsTo"
},
{
"const": "hasOne"
},
{
"const": "hasMany"
}
],
description: "Kind of Prisma schema member.\n\n- `\"scalar\"`: Regular column \u2192 `{ field: true }`\n- `\"belongsTo\"`: FK relation \u2192 `{ relation: { select: ... } }`\n- `\"hasOne\"`: 1:1 relation \u2192 nested select\n- `\"hasMany\"`: 1:N relation \u2192 `{ relation: { select: ... } }`\n\nThe kind forces explicit classification of each member BEFORE deciding\nselect syntax, preventing confusion between scalars and relations."
},
nullable: {
oneOf: [
{
type: "null"
},
{
type: "boolean"
}
],
description: "Whether nullable in Prisma schema.\n\n- `false`: Always present \u2014 transform() can safely access\n- `true`: May be null \u2014 transform() must handle null case\n- `null`: Not applicable (hasMany/hasOne)"
},
how: {
type: "string",
description: "Brief reason for selecting this field (NOT code).\n\nWrite phase: \"For DTO.id\", \"For DTO.createdAt (needs .toISOString())\", \"For\nDTO.customer (nested transformer)\".\n\nCorrect phase: \"No change needed\", \"Fix: Missing field \u2014 add for\nDTO.totalPrice\".\n\nEven if correct, you MUST include it in the mapping. This ensures complete\ncoverage and alignment with transform()."
}
},
required: [
"member",
"kind",
"nullable",
"how"
],
description: "Prisma field selection mapping for the select() function.\n\nDocuments which Prisma fields/relations must be selected to enable\ntransform() to build the DTO. EVERY required field must be listed \u2014 the\nvalidator rejects incomplete selections."
},
AutoBeRealizeTransformerTransformMapping: {
type: "object",
properties: {
property: {
type: "string",
description: "Exact DTO property name (case-sensitive, camelCase).\n\nInclude ALL properties: direct mappings, type conversions, computed values,\nand nested transformations.\n\n**Examples**:\n\n```typescript\n// Direct scalar mappings\n{ property: \"id\", how: \"From prisma.id\" }\n{ property: \"createdAt\", how: \"From prisma.created_at.toISOString()\" }\n\n// Type conversions\n{ property: \"price\", how: \"From prisma.unit_price (Decimal \u2192 Number)\" }\n{ property: \"deletedAt\", how: \"From prisma.deleted_at?.toISOString() ?? null\" }\n\n// Computed properties\n{ property: \"totalPrice\", how: \"Compute: prisma.unit_price * prisma.quantity\" }\n{ property: \"reviewCount\", how: \"From prisma._count.reviews\" }\n\n// Nested transformations (reuse neighbor transformers)\n{ property: \"customer\", how: \"Transform with CustomerTransformer\" }\n{ property: \"tags\", how: \"Array map with TagTransformer\" }\n```"
},
how: {
type: "string",
description: "Brief strategy for obtaining this property's value (NOT code).\n\nWrite phase: \"From prisma.email\", \"From prisma.created_at.toISOString()\",\n\"From prisma.deleted_at?.toISOString() ?? null\", \"From prisma.unit_price\n(Decimal \u2192 Number)\", \"Transform with CustomerTransformer\", \"Array map with\nTagTransformer\", \"Compute: prisma.unit_price * prisma.quantity\".\n\nCorrect phase: \"No change needed\", \"Fix: Missing Decimal conversion\", \"Fix:\nShould use TagTransformer instead of inline\".\n\nEven if correct, you MUST include it. This ensures complete DTO coverage."
}
},
required: [
"property",
"how"
],
description: "DTO property transformation mapping for the transform() function.\n\nDocuments how to transform Prisma payload data into each DTO property. EVERY\nDTO property must be listed \u2014 the validator rejects incomplete mappings."
},
"IAutoBeRealizeTransformerWriteApplication.IReviseProps": {
type: "object",
properties: {
review: {
type: "string",
description: "MUST systematically verify four checklists:\n\n1. Schema Fidelity \u2014 cross-check EVERY field name against plan Section 1\n2. Plan Adherence \u2014 verify EVERY mapping from Section 3 in BOTH select() and\n transform()\n3. System Rules \u2014 neighbor reuse, function order, select (not include)\n4. Type Safety \u2014 Decimal\u2192Number, DateTime\u2192ISO, nullable handling\n\nIdentify issues with line numbers. This catches hallucinated fields,\nmissing transformations, and rule violations."
},
final: {
oneOf: [
{
type: "null"
},
{
type: "string"
}
],
description: "Final transformer code with all review improvements applied, or null if\ndraft 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/IAutoBeRealizeTransformerWriteApplication.IProps"
}
}
],
description: "Process transformer generation task."
}
]
},
kinds: ["databaseSchemas", "complete"],
local: {
databaseSchemas: models.filter((m) => m.name === props.plan.databaseSchemaName),
},
});
const event = yield preliminary.orchestrate(ctx, (out) => __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c;
const pointer = {
value: null,
};
const result = yield ctx.conversate(Object.assign({ source: "realizeWrite", controller: createController({
application: ctx.state().database.result.data,
document,
plan: props.plan,
neighbors: props.neighbors,
build: (next) => {
pointer.value = next;
},
preliminary,
}), enforceFunctionCall: true, promptCacheKey: props.promptCacheKey }, (yield (0, transformRealizeTransformerWriteHistory_1.transformRealizeTransformerWriteHistory)(ctx, {
plan: props.plan,
neighbors: props.neighbors,
preliminary,
}))));
if (pointer.value === null)
return out(result)(null);
const content = yield AutoBeRealizeTransformerProgrammer_1.AutoBeRealizeTransformerProgrammer.replaceImportStatements(ctx, {
dtoTypeName,
schemas: document.components.schemas,
code: (_a = pointer.value.revise.final) !== null && _a !== void 0 ? _a : pointer.value.draft,
});
const model = models.find((m) => m.name === props.plan.databaseSchemaName);
const schema = document
.components.schemas[dtoTypeName];
const template = model
? AutoBeRealizeTransformerProgrammer_1.AutoBeRealizeTransformerProgrammer.writeTemplate({
plan: props.plan,
schema,
schemas: document.components.schemas,
neighbors: props.neighbors,
relations: AutoBeRealizeTransformerProgrammer_1.AutoBeRealizeTransformerProgrammer.getRelationMappingTable({
application: ctx.state().database.result.data,
model,
}),
model,
})
: undefined;
const functor = {
type: "transformer",
plan: props.plan,
neighbors: AutoBeRealizeTransformerProgrammer_1.AutoBeRealizeTransformerProgrammer.getNeighbors(content),
location: `src/transformers/${AutoBeRealizeTransformerProgrammer_1.AutoBeRealizeTransformerProgrammer.getName(dtoTypeName)}.ts`,
content,
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: (_c = (_b = ctx.state().analyze) === null || _b === void 0 ? void 0 : _b.step) !== null && _c !== void 0 ? _c : 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 => "getDatabaseSchemas" === input.type && (Array.isArray(input.schemaNames) && (1 <= input.schemaNames.length && input.schemaNames.every(elem => "string" === typeof elem))); const _io3 = input => "write" === input.type && "string" === typeof input.plan && (Array.isArray(input.selectMappings) && input.selectMappings.every(elem => "object" === typeof elem && null !== elem && _io4(elem))) && (Array.isArray(input.transformMappings) && input.transformMappings.every(elem => "object" === typeof elem && null !== elem && _io5(elem))) && "string" === typeof input.draft && ("object" === typeof input.revise && null !== input.revise && _io6(input.revise)); const _io4 = input => "string" === typeof input.member && ("scalar" === input.kind || "belongsTo" === input.kind || "hasOne" === input.kind || "hasMany" === input.kind) && (null === input.nullable || "boolean" === typeof input.nullable) && "string" === typeof input.how; const _io5 = input => "string" === typeof input.property && "string" === typeof input.how; const _io6 = input => "string" === typeof input.review && (null === input.final || "string" === typeof input.final); const _iu0 = input => (() => {
if ("complete" === input.type)
return _io1(input);
else if ("getDatabaseSchemas" === input.type)
return _io2(input);
else if ("write" === input.type)
return _io3(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 | IAutoBePreliminaryGetDatabaseSchemas | IAutoBeRealizeTransformerWriteApplication.IWrite)",
value: input.request
})) && _vu0(input.request, _path + ".request", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".request",
expected: "(IAutoBePreliminaryComplete | IAutoBePreliminaryGetDatabaseSchemas | IAutoBeRealizeTransformerWriteApplication.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) => ["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, _index4) => "string" === typeof elem || _report(_exceptionable, {
path: _path + ".schemaNames[" + _index4 + "]",
expected: "string",
value: elem
})).every(flag => flag)) || _report(_exceptionable, {
path: _path + ".schemaNames",
expected: "(Array<string> & MinItems<1>)",
value: input.schemaNames
})].every(flag => flag); const _vo3 = (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
}), (Array.isArray(input.selectMappings) || _report(_exceptionable, {
path: _path + ".selectMappings",
expected: "Array<AutoBeRealizeTransformerSelectMapping>",
value: input.selectMappings
})) && input.selectMappings.map((elem, _index5) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
path: _path + ".selectMappings[" + _index5 + "]",
expected: "AutoBeRealizeTransformerSelectMapping",
value: elem
})) && _vo4(elem, _path + ".selectMappings[" + _index5 + "]", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".selectMappings[" + _index5 + "]",
expected: "AutoBeRealizeTransformerSelectMapping",
value: elem
})).every(flag => flag) || _report(_exceptionable, {
path: _path + ".selectMappings",
expected: "Array<AutoBeRealizeTransformerSelectMapping>",
value: input.selectMappings
}), (Array.isArray(input.transformMappings) || _report(_exceptionable, {
path: _path + ".transformMappings",
expected: "Array<AutoBeRealizeTransformerTransformMapping>",
value: input.transformMappings
})) && input.transformMappings.map((elem, _index6) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
path: _path + ".transformMappings[" + _index6 + "]",
expected: "AutoBeRealizeTransformerTransformMapping",
value: elem
})) && _vo5(elem, _path + ".transformMappings[" + _index6 + "]", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".transformMappings[" + _index6 + "]",
expected: "AutoBeRealizeTransformerTransformMapping",
value: elem
})).every(flag => flag) || _report(_exceptionable, {
path: _path + ".transformMappings",
expected: "Array<AutoBeRealizeTransformerTransformMapping>",
value: input.transformMappings
}), "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: "IAutoBeRealizeTransformerWriteApplication.IReviseProps",
value: input.revise
})) && _vo6(input.revise, _path + ".revise", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".revise",
expected: "IAutoBeRealizeTransformerWriteApplication.IReviseProps",
value: input.revise
})].every(flag => flag); const _vo4 = (input, _path, _exceptionable = true) => ["string" === typeof input.member || _report(_exceptionable, {
path: _path + ".member",
expected: "string",
value: input.member
}), "scalar" === input.kind || "belongsTo" === input.kind || "hasOne" === input.kind || "hasMany" === input.kind || _report(_exceptionable, {
path: _path + ".kind",
expected: "(\"belongsTo\" | \"hasMany\" | \"hasOne\" | \"scalar\")",
value: input.kind
}), null === input.nullable || "boolean" === typeof input.nullable || _report(_exceptionable, {
path: _path + ".nullable",
expected: "(boolean | null)",
value: input.nullable
}), "string" === typeof input.how || _report(_exceptionable, {
path: _path + ".how",
expected: "string",
value: input.how
})].every(flag => flag); const _vo5 = (input, _path, _exceptionable = true) => ["string" === typeof input.property || _report(_exceptionable, {
path: _path + ".property",
expected: "string",
value: input.property
}), "string" === typeof input.how || _report(_exceptionable, {
path: _path + ".how",
expected: "string",
value: input.how
})].every(flag => flag); const _vo6 = (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 ("getDatabaseSchemas" === input.type)
return _vo2(input, _path, true && _exceptionable);
else if ("write" === input.type)
return _vo3(input, _path, true && _exceptionable);
else
return _report(_exceptionable, {
path: _path,
expected: "(IAutoBePreliminaryComplete | IAutoBePreliminaryGetDatabaseSchemas | IAutoBeRealizeTransformerWriteApplication.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: "IAutoBeRealizeTransformerWriteApplication.IProps",
value: input
})) && _vo0(input, _path + "", true) || _report(true, {
path: _path + "",
expected: "IAutoBeRealizeTransformerWriteApplication.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 = AutoBeRealizeTransformerProgrammer_1.AutoBeRealizeTransformerProgrammer.validate({
application: props.application,
document: props.document,
plan: props.plan,
neighbors: props.neighbors,
transformMappings: result.data.request.transformMappings,
selectMappings: result.data.request.selectMappings,
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 IAutoBeRealizeTransformerWriteApplication.IProps}",
type: "object",
properties: {
thinking: {
description: "Think before you act.\n\nFor preliminary requests: what database schemas are missing and why?\n\nFor write: what you're submitting and key mapping decisions.\n\nFor complete: why you consider the last write final.\n\nNote: All DTO type information is available transitively from the plan's\nDTO type names. You only need to request database schemas.",
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/IAutoBePreliminaryGetDatabaseSchemas"
},
{
$ref: "#/$defs/IAutoBeRealizeTransformerWriteApplication.IWrite"
}
],
"x-discriminator": {
propertyName: "type",
mapping: {
complete: "#/$defs/IAutoBePreliminaryComplete",
getDatabaseSchemas: "#/$defs/IAutoBePreliminaryGetDatabaseSchemas",
write: "#/$defs/IAutoBeRealizeTransformerWriteApplication.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"
]
},
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"
]
},
"IAutoBeRealizeTransformerWriteApplication.IWrite": {
description: "Generate transformer module (select + transform functions) via\nplan/draft/revise.",
type: "object",
properties: {
type: {
description: "Type discriminator for write submission.",
type: "string",
"enum": [
"write"
]
},
plan: {
description: "Transformer implementation plan. MUST contain four sections:\n\n1. Database Schema Field Inventory \u2014 ALL fields with exact names from schema\n2. DTO Property Inventory \u2014 ALL properties with types\n3. Field-by-Field Mapping Strategy \u2014 explicit table for BOTH select() and\n transform()\n4. Edge Cases and Special Handling \u2014 type casts (Decimal, DateTime),\n nullables\n\nThis forces you to READ the actual schema (not imagine it) and creates an\nexplicit specification for both select() and transform() functions.",
type: "string"
},
selectMappings: {
description: "Database field-by-field selection mapping for select().\n\nMUST include EVERY database field needed by transform() \u2014 no exceptions.\nEach mapping specifies:\n\n- `member`: Exact Prisma field/relation name (snake_case) \u2014 read from the\n Relation Mapping Table and member list, NOT from DTO property names\n- `kind`: scalar, belongsTo, hasOne, or hasMany\n- `nullable`: true/false for scalar/belongsTo, null for hasMany/hasOne\n- `how`: Which DTO property needs it\n\nThe `kind` property forces explicit classification of each member BEFORE\ndeciding select syntax, preventing confusion between scalars and\nrelations.\n\nMissing even a single required field will cause validation failure.",
type: "array",
items: {
$ref: "#/$defs/AutoBeRealizeTransformerSelectMapping"
}
},
transformMappings: {
description: "DTO property-by-property transformation mapping for transform().\n\nMUST include EVERY property from the DTO type definition \u2014 no exceptions.\nEach mapping specifies:\n\n- `property`: Exact DTO property name (camelCase)\n- `how`: How to obtain from Prisma payload\n\n**Common transformation patterns**:\n\n- Direct mapping: snake_case \u2192 camelCase\n- Type conversion: Decimal \u2192 Number, DateTime \u2192 ISO string\n- Nullable: DateTime? \u2192 string | null\n- Nested objects: Reuse neighbor transformers\n- Arrays: ArrayUtil.asyncMap + neighbor transformer\n\nMissing even a single property will cause validation failure.",
type: "array",
items: {
$ref: "#/$defs/AutoBeRealizeTransformerTransformMapping"
}
},
draft: {
description: "Complete implementation following plan's mapping table. EVERY field from\nplan Section 3 MUST appear in BOTH select() and transform(). Implement:\n\n- Transform() first, select() second, Payload last (correct order)\n- All field mappings from plan with correct transformations\n- Neighbor transformer reuse (NEVER inline when transformer exists)\n- ALWAYS use `select`, NEVER use `include`",
type: "string"
},
revise: {
description: "Reviews draft and produces final code.",
$ref: "#/$defs/IAutoBeRealizeTransformerWriteApplication.IReviseProps"
}
},
required: [
"type",
"plan",
"selectMappings",
"transformMappings",
"draft",
"revise"
]
},
AutoBeRealizeTransformerSelectMapping: {
description: "Prisma field selection mapping for t