@autobe/agent
Version:
AI backend server code generator
812 lines • 49.1 kB
JavaScript
;
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.orchestrateRealizeCorrectCasting = void 0;
const __typia_transform__validateReport = __importStar(require("typia/lib/internal/_validateReport.js"));
const __typia_transform__llmApplicationFinalize = __importStar(require("typia/lib/internal/_llmApplicationFinalize.js"));
const typia_1 = __importDefault(require("typia"));
const uuid_1 = require("uuid");
const assertSchemaModel_1 = require("../../context/assertSchemaModel");
const executeCachedBatch_1 = require("../../utils/executeCachedBatch");
const validateEmptyCode_1 = require("../../utils/validateEmptyCode");
const transformRealizeCorrectCastingHistory_1 = require("./histories/transformRealizeCorrectCastingHistory");
const compileRealizeFiles_1 = require("./internal/compileRealizeFiles");
const replaceImportStatements_1 = require("./utils/replaceImportStatements");
const orchestrateRealizeCorrectCasting = (ctx_1, scenarios_1, authorizations_1, functions_1, progress_1, ...args_1) => __awaiter(void 0, [ctx_1, scenarios_1, authorizations_1, functions_1, progress_1, ...args_1], void 0, function* (ctx, scenarios, authorizations, functions, progress, life = ctx.retry) {
const validateEvent = yield (0, compileRealizeFiles_1.compileRealizeFiles)(ctx, {
authorizations,
functions,
});
return predicate(ctx, {
scenarios,
authorizations,
functions,
previousFailures: [],
progress,
event: validateEvent,
}, life);
});
exports.orchestrateRealizeCorrectCasting = orchestrateRealizeCorrectCasting;
const predicate = (ctx, props, life) => __awaiter(void 0, void 0, void 0, function* () {
if (props.event.result.type === "failure") {
ctx.dispatch(props.event);
return yield correct(ctx, props, life);
}
return props.functions;
});
const correct = (ctx, props, life) => __awaiter(void 0, void 0, void 0, function* () {
// Early returns for non-correctable cases
if (props.event.result.type !== "failure" || life < 0) {
return props.functions;
}
const failure = props.event.result;
const locations = diagnose(props.event).filter((l) => props.functions.map((f) => f.location).includes(l));
// If no locations to correct, return original functions
if (locations.length === 0) {
return props.functions;
}
props.progress.total += locations.length;
const converted = yield (0, executeCachedBatch_1.executeCachedBatch)(ctx, locations.map((location) => () => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c, _d;
const func = props.functions.find((f) => f.location === location);
const scenario = props.scenarios.find((s) => s.location === func.location);
const operation = scenario.operation;
const authorization = props.authorizations.find((a) => a.actor.name === operation.authorizationActor);
const pointer = {
value: null,
};
const { metric, tokenUsage } = yield ctx.conversate(Object.assign({ source: "realizeCorrect", controller: createController({
model: ctx.model,
functionName: scenario.functionName,
then: (next) => {
pointer.value = next;
},
reject: () => {
pointer.value = false;
},
}), enforceFunctionCall: true }, (0, transformRealizeCorrectCastingHistory_1.transformRealizeCorrectCastingHistory)(ctx, {
scenario,
authorization,
function: func,
failures: [
...props.previousFailures
.map((pf) => { var _a; return (_a = pf.find((f) => f.function.location === func.location)) !== null && _a !== void 0 ? _a : null; })
.filter((x) => x !== null),
{
function: func,
diagnostics: failure.diagnostics.filter((d) => d.file === func.location),
},
],
})));
++props.progress.completed;
if (pointer.value === null)
return { result: "exception", func: func };
else if (pointer.value === false)
return { result: "ignore", func: func };
pointer.value.draft = yield (0, replaceImportStatements_1.replaceImportStatements)(ctx, {
schemas: ctx.state().interface.document.components.schemas,
operation: operation,
code: pointer.value.draft,
decoratorType: authorization === null || authorization === void 0 ? void 0 : authorization.payload.name,
});
if (pointer.value.revise.final)
pointer.value.revise.final = yield (0, replaceImportStatements_1.replaceImportStatements)(ctx, {
schemas: ctx.state().interface.document.components.schemas,
operation: operation,
code: pointer.value.revise.final,
decoratorType: authorization === null || authorization === void 0 ? void 0 : authorization.payload.name,
});
ctx.dispatch({
id: (0, uuid_1.v7)(),
type: "realizeCorrect",
kind: "casting",
content: (_a = pointer.value.revise.final) !== null && _a !== void 0 ? _a : pointer.value.draft,
created_at: new Date().toISOString(),
location: func.location,
step: (_c = (_b = ctx.state().analyze) === null || _b === void 0 ? void 0 : _b.step) !== null && _c !== void 0 ? _c : 0,
metric,
tokenUsage,
completed: props.progress.completed,
total: props.progress.total,
});
return {
result: "success",
func: Object.assign(Object.assign({}, func), { content: (_d = pointer.value.revise.final) !== null && _d !== void 0 ? _d : pointer.value.draft }),
};
})));
// Get functions that were not modified (not in locations array)
const unchangedFunctions = props.functions.filter((f) => !locations.includes(f.location));
// Merge converted functions with unchanged functions for validation
const allFunctionsForValidation = [
...converted.map((c) => c.func),
...unchangedFunctions,
];
const newValidate = yield (0, compileRealizeFiles_1.compileRealizeFiles)(ctx, {
authorizations: props.authorizations,
functions: allFunctionsForValidation,
});
const newResult = newValidate.result;
if (newResult.type === "success") {
return allFunctionsForValidation;
}
else if (newResult.type === "exception") {
// Compilation exception, return current functions. because retrying won't help.
return props.functions;
}
if (newResult.diagnostics.every((d) => { var _a; return !((_a = d.file) === null || _a === void 0 ? void 0 : _a.startsWith("src/providers")); })) {
// No diagnostics related to provider functions, stop correcting
return allFunctionsForValidation;
}
const newLocations = diagnose(newValidate);
// Separate successful, failed, and ignored corrections
const { success, failed, ignored } = separateCorrectionResults(converted, newLocations);
// If no failures to retry, return all functions
if (failed.length === 0) {
return [...success, ...ignored, ...unchangedFunctions];
}
// Recursively retry failed functions
const retriedFunctions = yield predicate(ctx, {
scenarios: props.scenarios,
authorizations: props.authorizations,
functions: failed,
previousFailures: [
...props.previousFailures,
failed.map((f) => ({
function: f,
diagnostics: newValidate.result.type === "failure"
? newValidate.result.diagnostics.filter((d) => d.file === f.location)
: [],
})),
],
progress: props.progress,
event: newValidate,
}, life - 1);
return [...success, ...ignored, ...retriedFunctions, ...unchangedFunctions];
});
/**
* Extract unique file locations from validation event diagnostics
*
* @param event - Validation event containing compilation results
* @returns Array of unique file paths that have errors
*/
const diagnose = (event) => {
if (event.result.type !== "failure") {
return [];
}
const diagnostics = event.result.diagnostics;
const locations = diagnostics
.map((d) => d.file)
.filter((f) => f !== null)
.filter((f) => f.startsWith("src/providers"));
return Array.from(new Set(locations));
};
/**
* Separate correction results into successful, failed, and ignored functions
*
* @param corrections - Array of correction results
* @param errorLocations - File paths that still have errors
* @returns Object with success, failed, and ignored function arrays
*/
const separateCorrectionResults = (corrections, errorLocations) => {
const success = corrections
.filter((c) => c.result === "success" && !errorLocations.includes(c.func.location))
.map((c) => c.func);
const failed = corrections
.filter((c) => c.result === "success" && errorLocations.includes(c.func.location))
.map((c) => c.func);
const ignored = corrections
.filter((c) => c.result === "ignore" || c.result === "exception")
.map((c) => c.func);
return { success, failed, ignored };
};
const createController = (props) => {
(0, assertSchemaModel_1.assertSchemaModel)(props.model);
const validate = (input) => {
const result = (() => { const _io0 = input => "string" === typeof input.think && "string" === typeof input.draft && ("object" === typeof input.revise && null !== input.revise && _io1(input.revise)); const _io1 = input => "string" === typeof input.review && (null === input.final || "string" === typeof input.final); const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.think || _report(_exceptionable, {
path: _path + ".think",
expected: "string",
value: input.think
}), "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: "IAutoBeCommonCorrectCastingApplication.IReviseProps",
value: input.revise
})) && _vo1(input.revise, _path + ".revise", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".revise",
expected: "IAutoBeCommonCorrectCastingApplication.IReviseProps",
value: input.revise
})].every(flag => flag); const _vo1 = (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 __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: "IAutoBeCommonCorrectCastingApplication.IProps",
value: input
})) && _vo0(input, _path + "", true) || _report(true, {
path: _path + "",
expected: "IAutoBeCommonCorrectCastingApplication.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;
const errors = (0, validateEmptyCode_1.validateEmptyCode)({
functionName: props.functionName,
draft: result.data.draft,
revise: result.data.revise,
});
return errors.length
? {
success: false,
errors,
data: result.data,
}
: result;
};
const application = collection[props.model === "chatgpt"
? "chatgpt"
: props.model === "gemini"
? "gemini"
: "claude"](validate);
return {
protocol: "class",
name: "correctInvalidRequest",
application,
execute: {
rewrite: (next) => {
props.then(next);
},
reject: () => {
props.reject();
},
},
};
};
const collection = {
chatgpt: (validate) => (() => {
const application = {
model: "chatgpt",
options: {
reference: true,
strict: false,
separate: null
},
functions: [
{
name: "rewrite",
parameters: {
description: " The analysis and correction properties\n\n------------------------------\n\nCurrent Type: {@link IAutoBeCommonCorrectCastingApplication.IProps}",
type: "object",
properties: {
think: {
description: "Initial analysis of the type casting or assignment error.\n\nContains the agent's analysis of the specific type mismatch pattern:\n\n- Type of casting error (tag incompatibility, nullable assignment, literal\n type conversion, etc.)\n- Whether nullable or undefined types are involved\n- If Date to string conversions are needed\n- The chosen fix strategy for the specific error type",
type: "string"
},
draft: {
description: "Draft correction with initial type casting fixes.\n\nThe code after applying the first round of fixes:\n\n- Satisfies patterns for tag stripping\n- Date.toISOString() conversions where needed\n- Nullable type narrowing checks\n- Literal type assertions\n- Optional chaining result handling",
type: "string"
},
revise: {
description: "Review and finalization of type casting corrections.\n\nContains the review of applied corrections and the final code with all\ntype casting issues resolved while preserving type safety and validation\nintent.",
$ref: "#/$defs/IAutoBeCommonCorrectCastingApplication.IReviseProps"
}
},
required: [
"think",
"draft",
"revise"
],
additionalProperties: false,
$defs: {
"IAutoBeCommonCorrectCastingApplication.IReviseProps": {
type: "object",
properties: {
review: {
description: "Review of the type casting correction patterns applied.\n\nExplains which correction strategies were used:\n\n- Which satisfies patterns were applied for tag issues\n- Where typia.assert or assertGuard was used\n- How Date conversions were handled\n- What nullable type narrowing was applied\n- How literal type conversions were resolved\n- Confirmation that all type casting issues are resolved",
type: "string"
},
final: {
description: "Final corrected code with all type casting issues resolved.\n\nThe complete code ready for TypeScript compilation, with all type casting\nand assignment errors properly fixed using appropriate patterns while\nmaintaining type safety and the original validation logic. When the draft\nalready successfully resolves all type casting issues with no problems\nfound during review, this value can be null, indicating no further\nrefinements are necessary.\n\nA `null` value signifies the draft corrections were already optimal and\nrequire no additional modifications.",
anyOf: [
{
type: "null"
},
{
type: "string"
}
]
}
},
required: [
"review",
"final"
]
}
}
},
description: "Rewrite function to fix type casting and assignment errors.\n\nThis function is called when the agent detects any type casting or\nassignment related compilation error patterns.\n\nThe agent applies various fix strategies based on the error type:\n\n- **Typia tag incompatibilities**: Uses `satisfies ... as ...` pattern to\n strip incompatible tags, or `typia.assert<T>()` as a last resort\n- **Date conversions**: Uses `.toISOString()` method for Date to string\n conversions\n- **Nullable type narrowing**: Applies exhaustive checks (e.g., !== null &&\n !== undefined)\n- **typia.assert vs assertGuard**: Uses assert for value assignment,\n assertGuard for type narrowing\n- **Literal type conversions**: Uses `typia.assert<T>()` for runtime\n validation\n- **Optional chaining results**: Uses `=== true` or `??` operators\n- **\"No overlap\" errors**: Removes redundant comparisons",
validate: (() => { const _io0 = input => "string" === typeof input.think && "string" === typeof input.draft && ("object" === typeof input.revise && null !== input.revise && _io1(input.revise)); const _io1 = input => "string" === typeof input.review && (null === input.final || "string" === typeof input.final); const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.think || _report(_exceptionable, {
path: _path + ".think",
expected: "string",
value: input.think
}), "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: "IAutoBeCommonCorrectCastingApplication.IReviseProps",
value: input.revise
})) && _vo1(input.revise, _path + ".revise", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".revise",
expected: "IAutoBeCommonCorrectCastingApplication.IReviseProps",
value: input.revise
})].every(flag => flag); const _vo1 = (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 __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: "IAutoBeCommonCorrectCastingApplication.IProps",
value: input
})) && _vo0(input, _path + "", true) || _report(true, {
path: _path + "",
expected: "IAutoBeCommonCorrectCastingApplication.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
};
}; })()
},
{
name: "reject",
parameters: {
type: "object",
properties: {},
additionalProperties: false,
required: [],
$defs: {}
},
description: "Reject function when error is not related to type casting or assignment.\n\nThis function is called when the compilation error is unrelated to type\ncasting issues (e.g., missing imports, syntax errors, undefined variables),\nindicating the error should be handled by a different agent.",
validate: (() => { const __is = input => true; let errors; let _report; return input => {
if (false === __is(input)) {
errors = [];
_report = __typia_transform__validateReport._validateReport(errors);
((input, _path, _exceptionable = true) => true)(input, "$input", true);
const success = 0 === errors.length;
return success ? {
success,
data: input
} : {
success,
errors,
data: input
};
}
return {
success: true,
data: input
};
}; })()
}
]
};
__typia_transform__llmApplicationFinalize._llmApplicationFinalize(application, Object.assign(Object.assign({}, {
validate: {
rewrite: validate,
reject: () => ({
success: true,
data: undefined,
}),
},
}), { equals: false }));
return application;
})(),
claude: (validate) => (() => {
const application = {
model: "claude",
options: {
reference: true,
separate: null
},
functions: [
{
name: "rewrite",
parameters: {
description: " The analysis and correction properties\n\n------------------------------\n\nCurrent Type: {@link IAutoBeCommonCorrectCastingApplication.IProps}",
type: "object",
properties: {
think: {
description: "Initial analysis of the type casting or assignment error.\n\nContains the agent's analysis of the specific type mismatch pattern:\n\n- Type of casting error (tag incompatibility, nullable assignment, literal\n type conversion, etc.)\n- Whether nullable or undefined types are involved\n- If Date to string conversions are needed\n- The chosen fix strategy for the specific error type",
type: "string"
},
draft: {
description: "Draft correction with initial type casting fixes.\n\nThe code after applying the first round of fixes:\n\n- Satisfies patterns for tag stripping\n- Date.toISOString() conversions where needed\n- Nullable type narrowing checks\n- Literal type assertions\n- Optional chaining result handling",
type: "string"
},
revise: {
description: "Review and finalization of type casting corrections.\n\nContains the review of applied corrections and the final code with all\ntype casting issues resolved while preserving type safety and validation\nintent.",
$ref: "#/$defs/IAutoBeCommonCorrectCastingApplication.IReviseProps"
}
},
required: [
"think",
"draft",
"revise"
],
additionalProperties: false,
$defs: {
"IAutoBeCommonCorrectCastingApplication.IReviseProps": {
type: "object",
properties: {
review: {
description: "Review of the type casting correction patterns applied.\n\nExplains which correction strategies were used:\n\n- Which satisfies patterns were applied for tag issues\n- Where typia.assert or assertGuard was used\n- How Date conversions were handled\n- What nullable type narrowing was applied\n- How literal type conversions were resolved\n- Confirmation that all type casting issues are resolved",
type: "string"
},
final: {
description: "Final corrected code with all type casting issues resolved.\n\nThe complete code ready for TypeScript compilation, with all type casting\nand assignment errors properly fixed using appropriate patterns while\nmaintaining type safety and the original validation logic. When the draft\nalready successfully resolves all type casting issues with no problems\nfound during review, this value can be null, indicating no further\nrefinements are necessary.\n\nA `null` value signifies the draft corrections were already optimal and\nrequire no additional modifications.",
oneOf: [
{
type: "null"
},
{
type: "string"
}
]
}
},
required: [
"review",
"final"
]
}
}
},
description: "Rewrite function to fix type casting and assignment errors.\n\nThis function is called when the agent detects any type casting or\nassignment related compilation error patterns.\n\nThe agent applies various fix strategies based on the error type:\n\n- **Typia tag incompatibilities**: Uses `satisfies ... as ...` pattern to\n strip incompatible tags, or `typia.assert<T>()` as a last resort\n- **Date conversions**: Uses `.toISOString()` method for Date to string\n conversions\n- **Nullable type narrowing**: Applies exhaustive checks (e.g., !== null &&\n !== undefined)\n- **typia.assert vs assertGuard**: Uses assert for value assignment,\n assertGuard for type narrowing\n- **Literal type conversions**: Uses `typia.assert<T>()` for runtime\n validation\n- **Optional chaining results**: Uses `=== true` or `??` operators\n- **\"No overlap\" errors**: Removes redundant comparisons",
validate: (() => { const _io0 = input => "string" === typeof input.think && "string" === typeof input.draft && ("object" === typeof input.revise && null !== input.revise && _io1(input.revise)); const _io1 = input => "string" === typeof input.review && (null === input.final || "string" === typeof input.final); const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.think || _report(_exceptionable, {
path: _path + ".think",
expected: "string",
value: input.think
}), "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: "IAutoBeCommonCorrectCastingApplication.IReviseProps",
value: input.revise
})) && _vo1(input.revise, _path + ".revise", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".revise",
expected: "IAutoBeCommonCorrectCastingApplication.IReviseProps",
value: input.revise
})].every(flag => flag); const _vo1 = (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 __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: "IAutoBeCommonCorrectCastingApplication.IProps",
value: input
})) && _vo0(input, _path + "", true) || _report(true, {
path: _path + "",
expected: "IAutoBeCommonCorrectCastingApplication.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
};
}; })()
},
{
name: "reject",
parameters: {
type: "object",
properties: {},
additionalProperties: false,
required: [],
$defs: {}
},
description: "Reject function when error is not related to type casting or assignment.\n\nThis function is called when the compilation error is unrelated to type\ncasting issues (e.g., missing imports, syntax errors, undefined variables),\nindicating the error should be handled by a different agent.",
validate: (() => { const __is = input => true; let errors; let _report; return input => {
if (false === __is(input)) {
errors = [];
_report = __typia_transform__validateReport._validateReport(errors);
((input, _path, _exceptionable = true) => true)(input, "$input", true);
const success = 0 === errors.length;
return success ? {
success,
data: input
} : {
success,
errors,
data: input
};
}
return {
success: true,
data: input
};
}; })()
}
]
};
__typia_transform__llmApplicationFinalize._llmApplicationFinalize(application, Object.assign(Object.assign({}, {
validate: {
rewrite: validate,
reject: () => ({
success: true,
data: undefined,
}),
},
}), { equals: false }));
return application;
})(),
gemini: (validate) => (() => {
const application = {
model: "gemini",
options: {
reference: true,
separate: null
},
functions: [
{
name: "rewrite",
parameters: {
description: " The analysis and correction properties\n\n------------------------------\n\nCurrent Type: {@link IAutoBeCommonCorrectCastingApplication.IProps}",
type: "object",
properties: {
think: {
description: "Initial analysis of the type casting or assignment error.\n\nContains the agent's analysis of the specific type mismatch pattern:\n\n- Type of casting error (tag incompatibility, nullable assignment, literal\n type conversion, etc.)\n- Whether nullable or undefined types are involved\n- If Date to string conversions are needed\n- The chosen fix strategy for the specific error type",
type: "string"
},
draft: {
description: "Draft correction with initial type casting fixes.\n\nThe code after applying the first round of fixes:\n\n- Satisfies patterns for tag stripping\n- Date.toISOString() conversions where needed\n- Nullable type narrowing checks\n- Literal type assertions\n- Optional chaining result handling",
type: "string"
},
revise: {
description: "Review and finalization of type casting corrections.\n\nContains the review of applied corrections and the final code with all\ntype casting issues resolved while preserving type safety and validation\nintent.",
$ref: "#/$defs/IAutoBeCommonCorrectCastingApplication.IReviseProps"
}
},
required: [
"think",
"draft",
"revise"
],
additionalProperties: false,
$defs: {
"IAutoBeCommonCorrectCastingApplication.IReviseProps": {
type: "object",
properties: {
review: {
description: "Review of the type casting correction patterns applied.\n\nExplains which correction strategies were used:\n\n- Which satisfies patterns were applied for tag issues\n- Where typia.assert or assertGuard was used\n- How Date conversions were handled\n- What nullable type narrowing was applied\n- How literal type conversions were resolved\n- Confirmation that all type casting issues are resolved",
type: "string"
},
final: {
description: "Final corrected code with all type casting issues resolved.\n\nThe complete code ready for TypeScript compilation, with all type casting\nand assignment errors properly fixed using appropriate patterns while\nmaintaining type safety and the original validation logic. When the draft\nalready successfully resolves all type casting issues with no problems\nfound during review, this value can be null, indicating no further\nrefinements are necessary.\n\nA `null` value signifies the draft corrections were already optimal and\nrequire no additional modifications.",
anyOf: [
{
type: "null"
},
{
type: "string"
}
]
}
},
required: [
"review",
"final"
]
}
}
},
description: "Rewrite function to fix type casting and assignment errors.\n\nThis function is called when the agent detects any type casting or\nassignment related compilation error patterns.\n\nThe agent applies various fix strategies based on the error type:\n\n- **Typia tag incompatibilities**: Uses `satisfies ... as ...` pattern to\n strip incompatible tags, or `typia.assert<T>()` as a last resort\n- **Date conversions**: Uses `.toISOString()` method for Date to string\n conversions\n- **Nullable type narrowing**: Applies exhaustive checks (e.g., !== null &&\n !== undefined)\n- **typia.assert vs assertGuard**: Uses assert for value assignment,\n assertGuard for type narrowing\n- **Literal type conversions**: Uses `typia.assert<T>()` for runtime\n validation\n- **Optional chaining results**: Uses `=== true` or `??` operators\n- **\"No overlap\" errors**: Removes redundant comparisons",
validate: (() => { const _io0 = input => "string" === typeof input.think && "string" === typeof input.draft && ("object" === typeof input.revise && null !== input.revise && _io1(input.revise)); const _io1 = input => "string" === typeof input.review && (null === input.final || "string" === typeof input.final); const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.think || _report(_exceptionable, {
path: _path + ".think",
expected: "string",
value: input.think
}), "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: "IAutoBeCommonCorrectCastingApplication.IReviseProps",
value: input.revise
})) && _vo1(input.revise, _path + ".revise", true && _exceptionable) || _report(_exceptionable, {
path: _path + ".revise",
expected: "IAutoBeCommonCorrectCastingApplication.IReviseProps",
value: input.revise
})].every(flag => flag); const _vo1 = (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 __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: "IAutoBeCommonCorrectCastingApplication.IProps",
value: input
})) && _vo0(input, _path + "", true) || _report(true, {
path: _path + "",
expected: "IAutoBeCommonCorrectCastingApplication.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
};
}; })()
},
{
name: "reject",
parameters: {
type: "object",
properties: {},
additionalProperties: false,
required: [],
$defs: {}
},
description: "Reject function when error is not related to type casting or assignment.\n\nThis function is called when the compilation error is unrelated to type\ncasting issues (e.g., missing imports, syntax errors, undefined variables),\nindicating the error should be handled by a different agent.",
validate: (() => { const __is = input => true; let errors; let _report; return input => {
if (false === __is(input)) {
errors = [];
_report = __typia_transform__validateReport._validateReport(errors);
((input, _path, _exceptionable = true) => true)(input, "$input", true);
const success = 0 === errors.length;
return success ? {
success,
data: input
} : {
success,
errors,
data: input
};
}
return {
success: true,
data: input
};
}; })()
}
]
};
__typia_transform__llmApplicationFinalize._llmApplicationFinalize(application, Object.assign(Object.assign({}, {
validate: {
rewrite: validate,
reject: () => ({
success: true,
data: undefined,
}),
},
}), { equals: false }));
return application;
})(),
};
//# sourceMappingURL=orchestrateRealizeCorrectCasting.js.map