@autobe/agent
Version:
AI backend server code generator
749 lines (748 loc) • 59.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.orchestrateRealizeCollectorWrite = orchestrateRealizeCollectorWrite;
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 transformRealizeCollectorWriteHistory_1 = require("./histories/transformRealizeCollectorWriteHistory");
const AutoBeRealizeCollectorProgrammer_1 = require("./programmers/AutoBeRealizeCollectorProgrammer");
function orchestrateRealizeCollectorWrite(ctx, props) {
return __awaiter(this, void 0, void 0, function* () {
const history = ctx.state().interface;
if (history === null)
throw new Error("Cannot realize collector 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;
const result = 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, {
document: history.document,
progress: props.progress,
counter,
neighbors: getNeighbors(x),
plan: x,
promptCacheKey,
}));
}));
return result;
});
}
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 dtoTypeName = props.plan.dtoTypeName;
const location = `src/collectors/${AutoBeRealizeCollectorProgrammer_1.AutoBeRealizeCollectorProgrammer.getName(dtoTypeName)}.ts`;
const preliminary = new AutoBePreliminaryController_1.AutoBePreliminaryController({
dispatch: (e) => ctx.dispatch(e),
state: ctx.state(),
source: SOURCE,
application: {
version: "3.1",
components: {
schemas: {
"IAutoBeRealizeCollectorWriteApplication.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/IAutoBeRealizeCollectorWriteApplication.IWrite"
}
],
discriminator: {
propertyName: "type",
mapping: {
complete: "#/components/schemas/IAutoBePreliminaryComplete",
getDatabaseSchemas: "#/components/schemas/IAutoBePreliminaryGetDatabaseSchemas",
write: "#/components/schemas/IAutoBeRealizeCollectorWriteApplication.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."
},
"IAutoBeRealizeCollectorWriteApplication.IWrite": {
type: "object",
properties: {
type: {
"const": "write",
description: "Type discriminator for write submission."
},
plan: {
type: "string",
description: "Collector 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 mapping for every field\n4. Edge Cases and Special Handling \u2014 nullable, arrays, conditionals\n\nThis forces you to READ the actual schema (not imagine it) and creates an\nexplicit specification that the draft must implement."
},
mappings: {
type: "array",
items: {
$ref: "#/components/schemas/AutoBeRealizeCollectorMapping"
},
description: "Field-by-field mapping for complete database coverage.\n\nMUST include EVERY field and relation from the database schema \u2014 no\nexceptions. Each mapping specifies:\n\n- `member`: Exact Prisma field/relation name \u2014 read from schema, NOT from\n DTO property names or FK column names\n- `kind`: scalar, belongsTo, hasOne, or hasMany\n- `nullable`: true/false for scalar/belongsTo, null for hasMany/hasOne\n- `how`: How to obtain/generate the value for that field\n\nThe `kind` property forces explicit classification BEFORE deciding how to\nhandle it, preventing errors like treating belongsTo as scalar.\n\nMissing even a single field will cause validation failure."
},
draft: {
type: "string",
description: "Complete implementation following plan's mapping table. EVERY field from\nplan Section 3 MUST appear. Implement:\n\n- Namespace with collect() function\n- All field mappings (direct, connect, nested create)\n- Neighbor collector reuse (NEVER inline when collector exists)\n- UUID generation with v4(), proper Prisma CreateInput types"
},
revise: {
$ref: "#/components/schemas/IAutoBeRealizeCollectorWriteApplication.IReviseProps",
description: "Reviews draft and produces final code."
}
},
required: [
"type",
"plan",
"mappings",
"draft",
"revise"
],
description: "Generate collector module via plan/draft/revise."
},
AutoBeRealizeCollectorMapping: {
type: "object",
properties: {
member: {
type: "string",
description: "Exact field or relation name from Prisma schema (case-sensitive).\n\n**Examples**:\n\n```typescript\n// Scalar fields\n{ member: \"id\", kind: \"scalar\", nullable: false, how: \"Generate with v4()\" }\n{ member: \"email\", kind: \"scalar\", nullable: false, how: \"From props.body.email\" }\n{ member: \"created_at\", kind: \"scalar\", nullable: false, how: \"Default to new Date()\" }\n{ member: \"description\", kind: \"scalar\", nullable: true, how: \"From props.body.description ?? null\" }\n\n// BelongsTo relations \u2014 use Prisma RELATION name, NOT FK column name\n{ member: \"customer\", kind: \"belongsTo\", nullable: false, how: \"Connect using props.customer.id\" }\n{ member: \"parent\", kind: \"belongsTo\", nullable: true, how: \"Undefined (nullable FK)\" }\n\n// HasMany relations\n{ member: \"tags\", kind: \"hasMany\", nullable: null, how: \"Nested create with TagCollector\" }\n{ member: \"comments\", kind: \"hasMany\", nullable: null, how: \"Not needed (optional has-many)\" }\n```\n\nDO NOT use FK column names (e.g., \"customer_id\" is WRONG \u2014 use \"customer\").\nInclude ALL members even if unused in this collector."
},
kind: {
oneOf: [
{
"const": "scalar"
},
{
"const": "belongsTo"
},
{
"const": "hasOne"
},
{
"const": "hasMany"
}
],
description: "Kind of Prisma schema member.\n\n- `\"scalar\"`: Regular column \u2192 direct value assignment\n- `\"belongsTo\"`: FK relation \u2192 `{ connect: { id } }`\n- `\"hasOne\"`: 1:1 relation this side owns\n- `\"hasMany\"`: 1:N or M:N \u2192 `{ create: [...] }` or omit\n\nThe kind forces explicit classification BEFORE deciding how to handle it,\npreventing confusion like treating belongsTo relations as scalar fields."
},
nullable: {
oneOf: [
{
type: "null"
},
{
type: "boolean"
}
],
description: "Whether nullable in Prisma schema.\n\n- `false`: Non-nullable \u2014 must provide value\n- `true`: Nullable \u2014 use `?? null` for scalar, `undefined` for belongsTo\n- `null`: Not applicable (hasMany/hasOne)"
},
how: {
type: "string",
description: "Brief strategy for obtaining this field's value (NOT code).\n\nWrite phase: \"Generate with v4()\", \"From props.body.email\", \"Connect using\nprops.customer.id\", \"Nested create with TagCollector\".\n\nCorrect phase: \"No change needed\", \"Fix: Wrong name 'x' \u2192 'y'\".\n\nEven if correct or unused, you MUST include it. This ensures complete\nschema coverage."
}
},
required: [
"member",
"kind",
"nullable",
"how"
],
description: "Field/relation mapping for Prisma CreateInput generation.\n\nDocuments handling strategy for ONE Prisma schema member. EVERY field and\nrelation must be listed \u2014 the validator rejects incomplete mappings."
},
"IAutoBeRealizeCollectorWriteApplication.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 is implemented\n3. System Rules \u2014 neighbor reuse, props structure, satisfies type\n4. Type Safety \u2014 compilation check, nullable handling, async/await\n\nIdentify issues with line numbers. This catches hallucinated fields,\nmissing mappings, and rule violations."
},
final: {
oneOf: [
{
type: "null"
},
{
type: "string"
}
],
description: "Final collector 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/IAutoBeRealizeCollectorWriteApplication.IProps"
}
}
],
description: "Process collector 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(ctx, {
plan: props.plan,
neighbors: props.neighbors,
build: (next) => {
pointer.value = next;
},
preliminary,
}), enforceFunctionCall: true, promptCacheKey: props.promptCacheKey }, (yield (0, transformRealizeCollectorWriteHistory_1.transformRealizeCollectorWriteHistory)(ctx, {
plan: props.plan,
neighbors: props.neighbors,
preliminary,
}))));
if (pointer.value === null)
return out(result)(null);
const content = yield AutoBeRealizeCollectorProgrammer_1.AutoBeRealizeCollectorProgrammer.replaceImportStatements(ctx, {
dtoTypeName,
schemas: props.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 body = props.document.components.schemas[props.plan.dtoTypeName];
const template = model
? AutoBeRealizeCollectorProgrammer_1.AutoBeRealizeCollectorProgrammer.writeTemplate({
plan: props.plan,
body,
model,
application: ctx.state().database.result.data,
})
: undefined;
const functor = {
type: "collector",
plan: props.plan,
neighbors: AutoBeRealizeCollectorProgrammer_1.AutoBeRealizeCollectorProgrammer.getNeighbors(content),
location,
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(ctx, 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.mappings) && input.mappings.every(elem => "object" === typeof elem && null !== elem && _io4(elem))) && "string" === typeof input.draft && ("object" === typeof input.revise && null !== input.revise && _io5(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.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 | IAutoBeRealizeCollectorWriteApplication.IWrite)",
value: input.request
})) && _vu0(input.request, _path + ".request", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".request",
expected: "(IAutoBePreliminaryComplete | IAutoBePreliminaryGetDatabaseSchemas | IAutoBeRealizeCollectorWriteApplication.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, _index3) => "string" === typeof elem || _report(_exceptionable, {
path: _path + ".schemaNames[" + _index3 + "]",
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.mappings) || _report(_exceptionable, {
path: _path + ".mappings",
expected: "Array<AutoBeRealizeCollectorMapping>",
value: input.mappings
})) && input.mappings.map((elem, _index4) => ("object" === typeof elem && null !== elem || _report(_exceptionable, {
path: _path + ".mappings[" + _index4 + "]",
expected: "AutoBeRealizeCollectorMapping",
value: elem
})) && _vo4(elem, _path + ".mappings[" + _index4 + "]", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".mappings[" + _index4 + "]",
expected: "AutoBeRealizeCollectorMapping",
value: elem
})).every(flag => flag) || _report(_exceptionable, {
path: _path + ".mappings",
expected: "Array<AutoBeRealizeCollectorMapping>",
value: input.mappings
}), "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: "IAutoBeRealizeCollectorWriteApplication.IReviseProps",
value: input.revise
})) && _vo5(input.revise, _path + ".revise", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".revise",
expected: "IAutoBeRealizeCollectorWriteApplication.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.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 | IAutoBeRealizeCollectorWriteApplication.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: "IAutoBeRealizeCollectorWriteApplication.IProps",
value: input
})) && _vo0(input, _path + "", true) || _report(true, {
path: _path + "",
expected: "IAutoBeRealizeCollectorWriteApplication.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 = AutoBeRealizeCollectorProgrammer_1.AutoBeRealizeCollectorProgrammer.validate({
application: ctx.state().database.result.data,
mappings: result.data.request.mappings,
plan: props.plan,
neighbors: props.neighbors,
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 IAutoBeRealizeCollectorWriteApplication.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/IAutoBeRealizeCollectorWriteApplication.IWrite"
}
],
"x-discriminator": {
propertyName: "type",
mapping: {
complete: "#/$defs/IAutoBePreliminaryComplete",
getDatabaseSchemas: "#/$defs/IAutoBePreliminaryGetDatabaseSchemas",
write: "#/$defs/IAutoBeRealizeCollectorWriteApplication.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"
]
},
"IAutoBeRealizeCollectorWriteApplication.IWrite": {
description: "Generate collector module via plan/draft/revise.",
type: "object",
properties: {
type: {
description: "Type discriminator for write submission.",
type: "string",
"enum": [
"write"
]
},
plan: {
description: "Collector 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 mapping for every field\n4. Edge Cases and Special Handling \u2014 nullable, arrays, conditionals\n\nThis forces you to READ the actual schema (not imagine it) and creates an\nexplicit specification that the draft must implement.",
type: "string"
},
mappings: {
description: "Field-by-field mapping for complete database coverage.\n\nMUST include EVERY field and relation from the database schema \u2014 no\nexceptions. Each mapping specifies:\n\n- `member`: Exact Prisma field/relation name \u2014 read from schema, NOT from\n DTO property names or FK column names\n- `kind`: scalar, belongsTo, hasOne, or hasMany\n- `nullable`: true/false for scalar/belongsTo, null for hasMany/hasOne\n- `how`: How to obtain/generate the value for that field\n\nThe `kind` property forces explicit classification BEFORE deciding how to\nhandle it, preventing errors like treating belongsTo as scalar.\n\nMissing even a single field will cause validation failure.",
type: "array",
items: {
$ref: "#/$defs/AutoBeRealizeCollectorMapping"
}
},
draft: {
description: "Complete implementation following plan's mapping table. EVERY field from\nplan Section 3 MUST appear. Implement:\n\n- Namespace with collect() function\n- All field mappings (direct, connect, nested create)\n- Neighbor collector reuse (NEVER inline when collector exists)\n- UUID generation with v4(), proper Prisma CreateInput types",
type: "string"
},
revise: {
description: "Reviews draft and produces final code.",
$ref: "#/$defs/IAutoBeRealizeCollectorWriteApplication.IReviseProps"
}
},
required: [
"type",
"plan",
"mappings",
"draft",
"revise"
]
},
AutoBeRealizeCollectorMapping: {
description: "Field/relation mapping for Prisma CreateInput generation.\n\nDocuments handling strategy for ONE Prisma schema member. EVERY field and\nrelation must be listed \u2014 the validator rejects incomplete mappings.",
type: "object",
properties: {
member: {
description: "Exact field or relation name from Prisma schema (case-sensitive).\n\n**Examples**:\n\n```typescript\n// Scalar fields\n{ member: \"id\", kind: \"scalar\", nullable: false, how: \"Generate with v4()\" }\n{ member: \"email\", kind: \"scalar\", nullable: false, how: \"From props.body.email\" }\n{ member: \"created_at\", kind: \"scalar\", nullable: false, how: \"Default to new Date()\" }\n{ member: \"description\", kind: \"scalar\", nullable: true, how: \"From props.body.description ?? null\" }\n\n// BelongsTo relations \u2014 use Prisma RELATION name, NOT FK column name\n{ member: \"customer\", kind: \"belongsTo\", nullable: false, how: \"Connect using props.customer.id\" }\n{ member: \"parent\", kind: \"belongsTo\", nullable: true, how: \"Undefined (nullable FK)\" }\n\n// HasMany relations\n{ member: \"tags\", kind: \"hasMany\", nullable: null, how: \"Nested create with TagCollector\" }\n{ member: \"comments\", kind: \"hasMany\", nullable: null, how: \"Not needed (optional has-many)\" }\n```\n\nDO NOT use FK column names (e.g., \"customer_id\" is WRONG \u2014 use \"customer\").\nInclude ALL members even if unused in this collector.",
type: "string"
},
kind: {
description: "Kind of Prisma schema member.\n\n- `\"scalar\"`: Regular column \u2192 direct value assignment\n- `\"belongsTo\"`: FK relation \u2192 `{ connect: { id } }`\n- `\"hasOne\"`: 1:1 relation this side owns\n- `\"hasMany\"`: 1:N or M:N \u2192 `{ create: [...] }` or omit\n\nThe kind forces explicit classification BEFORE deciding how to handle it,\npreventing confusion like treating belongsTo relations as scalar fields.",
type: "string",
"enum": [
"scalar",
"belongsTo",
"hasOne",
"hasMany"
]
},
nullable: {
description: "Whether nullable in Prisma schema.\n\n- `false`: Non-nullable \u2014 must provide value\n- `true`: Nullable \u2014 use `?? null` for scalar, `undefined` for belongsTo\n- `null`: Not applicable (hasMany/hasOne)",
anyOf: [
{
type: "null"
},
{
type: "boolean"
}
]
},
how: {
description: "Brief strategy for obtaining this field's value (NOT code).\n\nWrite phase: \"Generate with v4()\", \"From props.body.email\", \"Connect using\nprops.customer.id\", \"Nested create with TagCollector\".\n\nCorrect phase: \"No change needed\", \"Fix: Wrong name 'x' \u2192 'y'\".\n\nEven if correct or unused, you MUST include it. This ensures complete\nschema coverage.",
type: "string"
}
},
required: [
"member",
"kind",
"nullable",
"how"
]
},
"IAutoBeRealizeCollectorWriteApplication.IReviseProps": {
type: "object",
properties: {
review: {
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 is implemented\n3. System Rules \u2014 neighbor reuse, props structure, satisfies type\n4. Type Safety \u2014 compilation check, nullable handling, async/await\n\nIdentify issues with line numbers. This catches hallucinated fields,\nmissing mappings, and rule violations.",
type: "string"
},
final: {
description: "Final collector code with all review improvements applied, or null if\ndraft needs no changes.",
anyOf: [
{
type: "null"
},
{
type: "string"
}
]
}
},
required: [
"review",
"final"
]
}
}
},
description: "Process collector generation task.",
validate: (() => { 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.mappings) && input.mappings.every(elem => "object" === typeof elem && null !== elem && _io4(elem))) && "string" === typeof input.draft && ("object" === typeof input.revise && null !== input.revise && _io5(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.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 | IAutoBeRealizeCollectorWriteApplication.IWrite)",