@wix/ditto-codegen-public 1.0.165 → 1.0.166

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/out.js +156 -80
  2. package/package.json +2 -2
package/dist/out.js CHANGED
@@ -65677,6 +65677,7 @@ var require_ErrorTypes = __commonJS({
65677
65677
  ErrorType2["EXTENSION_GENERATION_ERROR"] = "EXTENSION_GENERATION_ERROR";
65678
65678
  ErrorType2["VALIDATION_CONFIGURATION_ERROR"] = "VALIDATION_CONFIGURATION_ERROR";
65679
65679
  ErrorType2["GENERATE_OBJECT_ERROR"] = "GENERATE_OBJECT_ERROR";
65680
+ ErrorType2["AUTO_FIX_ERROR"] = "AUTO_FIX_ERROR";
65680
65681
  ErrorType2["UNEXPECTED_ERROR"] = "UNEXPECTED_ERROR";
65681
65682
  })(ErrorType || (exports2.ErrorType = ErrorType = {}));
65682
65683
  }
@@ -65691,8 +65692,7 @@ var require_enums2 = __commonJS({
65691
65692
  var ValidationType;
65692
65693
  (function(ValidationType2) {
65693
65694
  ValidationType2["TYPESCRIPT"] = "typescript";
65694
- ValidationType2["JAVASCRIPT"] = "javascript";
65695
- ValidationType2["JSON"] = "json";
65695
+ ValidationType2["BUILD"] = "build";
65696
65696
  })(ValidationType || (exports2.ValidationType = ValidationType = {}));
65697
65697
  var ProcessType;
65698
65698
  (function(ProcessType2) {
@@ -65779,27 +65779,12 @@ var require_CodeValidationError = __commonJS({
65779
65779
  this.expected = true;
65780
65780
  this.retryable = false;
65781
65781
  this.validationType = options.validationType;
65782
- this.file = options.file;
65783
- this.line = options.line;
65784
- this.column = options.column;
65785
- this.errorCode = options.errorCode;
65786
- this.errorMessage = options.errorMessage;
65787
- this.errors = options.errors;
65782
+ this.errors = options.errors || [];
65788
65783
  }
65789
65784
  getAdditionalProperties() {
65790
65785
  const props = {
65791
65786
  validationType: this.validationType
65792
65787
  };
65793
- if (this.file)
65794
- props.file = this.file;
65795
- if (this.line !== void 0)
65796
- props.line = this.line;
65797
- if (this.column !== void 0)
65798
- props.column = this.column;
65799
- if (this.errorCode)
65800
- props.errorCode = this.errorCode;
65801
- if (this.errorMessage)
65802
- props.errorMessage = this.errorMessage;
65803
65788
  if (this.errors && this.errors.length > 0)
65804
65789
  props.errors = this.errors;
65805
65790
  return props;
@@ -66175,6 +66160,35 @@ var require_ValidationConfigurationError = __commonJS({
66175
66160
  }
66176
66161
  });
66177
66162
 
66163
+ // ../codegen-types/dist/errors/AutoFixError.js
66164
+ var require_AutoFixError = __commonJS({
66165
+ "../codegen-types/dist/errors/AutoFixError.js"(exports2) {
66166
+ "use strict";
66167
+ Object.defineProperty(exports2, "__esModule", { value: true });
66168
+ exports2.AutoFixError = void 0;
66169
+ var BaseCodegenError_1 = require_BaseCodegenError();
66170
+ var ErrorTypes_1 = require_ErrorTypes();
66171
+ var AutoFixError = class extends BaseCodegenError_1.BaseCodegenError {
66172
+ constructor(message, options) {
66173
+ super(message);
66174
+ this.name = "AutoFixError";
66175
+ this.errorType = ErrorTypes_1.ErrorType.AUTO_FIX_ERROR;
66176
+ this.expected = false;
66177
+ this.retryable = true;
66178
+ this.validationType = options?.validationType;
66179
+ this.cause = options?.cause;
66180
+ }
66181
+ getAdditionalProperties() {
66182
+ return {
66183
+ validationType: this.validationType,
66184
+ cause: this.cause
66185
+ };
66186
+ }
66187
+ };
66188
+ exports2.AutoFixError = AutoFixError;
66189
+ }
66190
+ });
66191
+
66178
66192
  // ../codegen-types/dist/errors/UnexpectedError.js
66179
66193
  var require_UnexpectedError = __commonJS({
66180
66194
  "../codegen-types/dist/errors/UnexpectedError.js"(exports2) {
@@ -66352,6 +66366,7 @@ var require_errors = __commonJS({
66352
66366
  __exportStar2(require_PlanningError(), exports2);
66353
66367
  __exportStar2(require_ExtensionGenerationError(), exports2);
66354
66368
  __exportStar2(require_ValidationConfigurationError(), exports2);
66369
+ __exportStar2(require_AutoFixError(), exports2);
66355
66370
  __exportStar2(require_UnexpectedError(), exports2);
66356
66371
  __exportStar2(require_TimeoutError(), exports2);
66357
66372
  __exportStar2(require_GenerateCodegenObjectError(), exports2);
@@ -153263,9 +153278,10 @@ var require_TypescriptValidator = __commonJS({
153263
153278
  "use strict";
153264
153279
  Object.defineProperty(exports2, "__esModule", { value: true });
153265
153280
  var child_process_1 = require("child_process");
153281
+ var ditto_codegen_types_12 = require_dist();
153266
153282
  var TypescriptValidator = class {
153267
153283
  constructor() {
153268
- this.type = "typescript";
153284
+ this.type = ditto_codegen_types_12.ValidationType.TYPESCRIPT;
153269
153285
  }
153270
153286
  async validate(projectDir) {
153271
153287
  const result = this.runTypecheck(projectDir);
@@ -153301,7 +153317,7 @@ var require_TypescriptValidator = __commonJS({
153301
153317
  }
153302
153318
  async parseTypecheckError(stdout) {
153303
153319
  const lines = stdout.split(/\r?\n/);
153304
- const tsRegex = /^(?<path>.+?)\((?<line>\d+),(?<col>\d+)\):\s*error\s+TS\d+:\s*(?<msg>.+)$/;
153320
+ const tsRegex = /^(?<path>.+?)\((?<line>\d+),(?<col>\d+)\):\s*error\s+(?<code>TS\d+):\s*(?<msg>.+)$/;
153305
153321
  const results = [];
153306
153322
  for (const line of lines) {
153307
153323
  const m = line.match(tsRegex);
@@ -153310,6 +153326,7 @@ var require_TypescriptValidator = __commonJS({
153310
153326
  filePath: m.groups["path"],
153311
153327
  line: Number(m.groups["line"]),
153312
153328
  column: Number(m.groups["col"]),
153329
+ errorCode: m.groups["code"],
153313
153330
  errorMessage: m.groups["msg"].trim()
153314
153331
  });
153315
153332
  }
@@ -153334,12 +153351,12 @@ var require_ValidatorFactory = __commonJS({
153334
153351
  var ValidatorFactory = class {
153335
153352
  constructor() {
153336
153353
  }
153337
- getValidator(type = "typescript") {
153338
- if (type === "typescript") {
153354
+ getValidator(type = ditto_codegen_types_12.ValidationType.TYPESCRIPT) {
153355
+ if (type === ditto_codegen_types_12.ValidationType.TYPESCRIPT) {
153339
153356
  return new TypescriptValidator_1.default();
153340
153357
  }
153341
- throw new ditto_codegen_types_12.ValidationConfigurationError(`Invalid validator type: ${type}`, {
153342
- validatorType: type
153358
+ throw new ditto_codegen_types_12.AutoFixError(`Invalid validator type: ${type}`, {
153359
+ validationType: type
153343
153360
  });
153344
153361
  }
153345
153362
  };
@@ -153369,6 +153386,17 @@ var require_NaiveFixerAgent = __commonJS({
153369
153386
  constructor() {
153370
153387
  this.name = "BatchFixAgent";
153371
153388
  }
153389
+ formatErrors(errors) {
153390
+ return errors.map((error, index) => `${index + 1}. Line ${error.line}, Column ${error.column}${error.errorCode ? ` (${error.errorCode})` : ""}: ${error.message}`).join("\n");
153391
+ }
153392
+ formatPreviousErrors(previousErrors) {
153393
+ if (!previousErrors || previousErrors.length === 0) {
153394
+ return "";
153395
+ }
153396
+ return `The following errors persisted after your last fix attempt.
153397
+ Please try a DIFFERENT approach to solve them:
153398
+ ${previousErrors.map((err) => `- ${err}`).join("\n")}`;
153399
+ }
153372
153400
  async fixFileWithMultipleErrors(input) {
153373
153401
  const systemPrompt = (0, dedent_1.default)`You are an expert TypeScript/JavaScript developer. Your task is to fix ALL compilation errors in a file by providing the complete corrected file content.
153374
153402
 
@@ -153387,7 +153415,8 @@ Focus on common TypeScript errors:
153387
153415
  - Syntax errors
153388
153416
  - Missing semicolons or brackets
153389
153417
  - Incorrect component props`;
153390
- const errorsList = input.errors.map((error, index) => `${index + 1}. Line ${error.line}, Column ${error.column}: ${error.message}`).join("\n");
153418
+ const errorsList = this.formatErrors(input.errors);
153419
+ const previousErrorsSection = this.formatPreviousErrors(input.previousErrors);
153391
153420
  const userMessage = `File: ${input.filePath}
153392
153421
  Language: ${input.language}
153393
153422
 
@@ -153397,6 +153426,8 @@ ${errorsList}
153397
153426
  CURRENT FILE CONTENT:
153398
153427
  ${input.content}
153399
153428
 
153429
+ ${previousErrorsSection}
153430
+
153400
153431
  Please provide the complete fixed file content that resolves ALL the errors listed above.`;
153401
153432
  try {
153402
153433
  const result = await codeGenerationService_12.codegenAIProxyService.generateCodegenObject({
@@ -153443,7 +153474,7 @@ var require_NaiveErrorFixer = __commonJS({
153443
153474
  var NaiveErrorFixer = class {
153444
153475
  constructor() {
153445
153476
  }
153446
- async fixMultipleErrors(projectDir, filePath, errors) {
153477
+ async fixMultipleErrors(projectDir, filePath, errors, previousErrors) {
153447
153478
  if (errors.length === 0) {
153448
153479
  return;
153449
153480
  }
@@ -153461,9 +153492,11 @@ var require_NaiveErrorFixer = __commonJS({
153461
153492
  errors: errors.map((error) => ({
153462
153493
  line: error.line || 1,
153463
153494
  column: error.column || 1,
153495
+ errorCode: error.errorCode,
153464
153496
  message: error.errorMessage || "Unknown error"
153465
153497
  })),
153466
- language: "typescript"
153498
+ language: "typescript",
153499
+ previousErrors: previousErrors?.map(formatErrorToString)
153467
153500
  });
153468
153501
  if (batchResult.fixedContent) {
153469
153502
  fs_1.default.writeFileSync(absolutePath, batchResult.fixedContent, "utf8");
@@ -153481,6 +153514,9 @@ var require_NaiveErrorFixer = __commonJS({
153481
153514
  }
153482
153515
  };
153483
153516
  exports2.default = NaiveErrorFixer;
153517
+ var formatErrorToString = (err) => {
153518
+ return `Line ${err.line}${err.errorCode ? ` (${err.errorCode})` : ""}: ${err.errorMessage}`;
153519
+ };
153484
153520
  }
153485
153521
  });
153486
153522
 
@@ -153523,66 +153559,106 @@ var require_fixFlow = __commonJS({
153523
153559
  var ValidatorFactory_1 = __importDefault2(require_ValidatorFactory());
153524
153560
  var FixerFactory_1 = __importDefault2(require_FixerFactory());
153525
153561
  var ditto_codegen_types_12 = require_dist();
153562
+ var job_context_storage_12 = require_job_context_storage();
153563
+ var codeGenerationService_12 = require_codeGenerationService();
153526
153564
  var MAX_ERRORS_PER_BATCH = 20;
153527
- async function startFixFlow(request, eventEmitter) {
153565
+ async function startFixFlow(request) {
153528
153566
  const { projectDir } = request;
153529
- eventEmitter.emitEvent("validation:start", { outputPath: projectDir });
153530
153567
  const fixerFactory = new FixerFactory_1.default();
153531
153568
  const validatorFactory = new ValidatorFactory_1.default();
153532
153569
  const validator = validatorFactory.getValidator();
153533
- console.log("\u{1F50D} Running validation and batch fix...");
153534
- const initialValidation = await validator.validate(projectDir);
153535
- if (initialValidation.status === 0) {
153536
- console.log(`\u2705 ${validator.type} validation passed - no fixes needed`);
153537
- eventEmitter.emitEvent("validation:done", { outputPath: projectDir });
153538
- return;
153539
- }
153540
- if (!initialValidation.parsedValidationErrors || initialValidation.parsedValidationErrors.length === 0) {
153541
- const errorMessage2 = `Validation failed but no parsed errors available. Raw errors: ${initialValidation.validationErrors}`;
153542
- console.warn(`\u26A0\uFE0F ${errorMessage2}`);
153543
- const error2 = new ditto_codegen_types_12.ValidationConfigurationError(errorMessage2);
153544
- throw error2;
153545
- }
153546
- const totalErrors = initialValidation.parsedValidationErrors.length;
153547
- console.log(`\u{1F4DD} Found ${totalErrors} errors to fix`);
153548
- const errorsByFile = (0, utils_1.mapGroupBy)(initialValidation.parsedValidationErrors, (error2) => error2.filePath);
153549
- console.log(`\u{1F4C1} Errors span ${errorsByFile.size} files`);
153550
- let totalFixesApplied = 0;
153551
153570
  const fixer = fixerFactory.getFixer();
153552
- for (const [filePath, fileErrors] of errorsByFile) {
153553
- const errorsToFix = fileErrors.slice(0, MAX_ERRORS_PER_BATCH);
153554
- if (errorsToFix.length < fileErrors.length) {
153555
- console.log(`\u{1F4CB} Processing ${errorsToFix.length}/${fileErrors.length} errors for ${filePath} (batching to prevent AI overload)`);
153556
- } else {
153557
- console.log(`\u{1F4CB} Processing ${errorsToFix.length} errors for ${filePath}`);
153571
+ const MAX_FIX_ATTEMPTS = 3;
153572
+ const parentContext = job_context_storage_12.jobContextStorage.getStore();
153573
+ const fixTaskId = `fix-flow`;
153574
+ const updateFixTask = async (status, payload = {}) => {
153575
+ await codeGenerationService_12.codeGenerationService.updateTask(parentContext.jobId, fixTaskId, status, payload);
153576
+ };
153577
+ await codeGenerationService_12.codeGenerationService.addTask(parentContext.jobId, {
153578
+ id: fixTaskId,
153579
+ kind: "fix_code",
153580
+ name: "Auto-Fixer",
153581
+ status: ditto_codegen_types_12.Status.RUNNING,
153582
+ description: "Running automatic code fixes"
153583
+ });
153584
+ console.log("\u{1F50D} Running validation and batch fix...");
153585
+ const processFiles = async (fileEntries, lastRunErrors) => {
153586
+ for (const [filePath, fileErrors] of fileEntries) {
153587
+ const errorsToFix = fileErrors.slice(0, MAX_ERRORS_PER_BATCH);
153588
+ if (errorsToFix.length < fileErrors.length) {
153589
+ console.log(`\u{1F4CB} Processing ${errorsToFix.length}/${fileErrors.length} errors for ${filePath} (batching to prevent AI overload)`);
153590
+ } else {
153591
+ console.log(`\u{1F4CB} Processing ${errorsToFix.length} errors for ${filePath}`);
153592
+ }
153593
+ const previousErrors = lastRunErrors.get(filePath);
153594
+ try {
153595
+ await fixer.fixMultipleErrors(projectDir, filePath, errorsToFix, previousErrors);
153596
+ console.log(`\u2705 Applied batch fixes for ${filePath}`);
153597
+ } catch (fixError) {
153598
+ console.error(`\u274C Failed to fix errors in ${filePath}: ${fixError instanceof Error ? fixError.message : String(fixError)}`);
153599
+ }
153558
153600
  }
153559
- try {
153560
- await fixer.fixMultipleErrors(projectDir, filePath, errorsToFix);
153561
- totalFixesApplied += errorsToFix.length;
153562
- console.log(`\u2705 Applied batch fixes for ${filePath}`);
153563
- } catch (fixError) {
153564
- console.error(`\u274C Failed to fix errors in ${filePath}: ${fixError instanceof Error ? fixError.message : String(fixError)}`);
153565
- continue;
153601
+ };
153602
+ const fixState = {
153603
+ accumulatedFixes: 0,
153604
+ lastRunErrors: /* @__PURE__ */ new Map()
153605
+ };
153606
+ const handleValidationFailure = async (validation, reason) => {
153607
+ const remainingErrors = validation.parsedValidationErrors?.length || 0;
153608
+ const unfixedValidationErrors = validation.validationErrors || "Unknown validation errors";
153609
+ console.log(`\u{1F4CB} ${remainingErrors} errors remaining after fixes`);
153610
+ const errorMessage = `Validation failed: ${reason}. Fixed ${fixState.accumulatedFixes} errors, but ${remainingErrors} remain:
153611
+ ${unfixedValidationErrors}`;
153612
+ const validationErrors = validation.parsedValidationErrors || [];
153613
+ const error = new ditto_codegen_types_12.CodeValidationError(errorMessage, {
153614
+ validationType: ditto_codegen_types_12.ValidationType.TYPESCRIPT,
153615
+ errors: validationErrors
153616
+ });
153617
+ await updateFixTask(ditto_codegen_types_12.Status.FAILED, { error: errorMessage });
153618
+ throw error;
153619
+ };
153620
+ const ensureParsedErrorsExist = async (validation) => {
153621
+ const hasParsedErrorsToFix = validation.parsedValidationErrors.length > 0;
153622
+ if (!hasParsedErrorsToFix) {
153623
+ const errorMessage = `Validation failed but no parsed errors available. Raw errors: ${validation.validationErrors}`;
153624
+ console.warn(`\u26A0\uFE0F ${errorMessage}`);
153625
+ await updateFixTask(ditto_codegen_types_12.Status.FAILED, { error: errorMessage });
153626
+ throw new Error(errorMessage);
153566
153627
  }
153628
+ };
153629
+ try {
153630
+ for (let attempt = 0; attempt < MAX_FIX_ATTEMPTS; attempt++) {
153631
+ console.log(`\u{1F504} Fix Attempt ${attempt}/${MAX_FIX_ATTEMPTS}`);
153632
+ const currentValidation = await validator.validate(projectDir);
153633
+ if (currentValidation.status === 0) {
153634
+ console.log(`\u2705 ${validator.type} validation passed - no fixes needed`);
153635
+ await updateFixTask(ditto_codegen_types_12.Status.COMPLETED, {
153636
+ description: `Fixed ${fixState.accumulatedFixes} errors.`
153637
+ });
153638
+ return;
153639
+ }
153640
+ if (attempt === MAX_FIX_ATTEMPTS - 1) {
153641
+ await handleValidationFailure(currentValidation, `after ${MAX_FIX_ATTEMPTS} fix attempts`);
153642
+ }
153643
+ await ensureParsedErrorsExist(currentValidation);
153644
+ const totalErrors = currentValidation.parsedValidationErrors.length;
153645
+ console.log(`\u{1F4DD} Found ${totalErrors} errors to fix`);
153646
+ const errorsByFile = (0, utils_1.mapGroupBy)(currentValidation.parsedValidationErrors, (error) => error.filePath);
153647
+ console.log(`\u{1F4C1} Errors span ${errorsByFile.size} files`);
153648
+ await processFiles(Array.from(errorsByFile), fixState.lastRunErrors);
153649
+ fixState.lastRunErrors = errorsByFile;
153650
+ }
153651
+ } catch (error) {
153652
+ const errorMessage = error instanceof Error ? error.message : String(error);
153653
+ const finalError = new ditto_codegen_types_12.AutoFixError(errorMessage, {
153654
+ validationType: validator.type,
153655
+ cause: error
153656
+ });
153657
+ await updateFixTask(ditto_codegen_types_12.Status.FAILED, {
153658
+ error: finalError.message
153659
+ });
153660
+ throw finalError;
153567
153661
  }
153568
- console.log(`\u{1F4CA} Batch fix completed: ${totalFixesApplied} fixes applied across ${errorsByFile.size} files`);
153569
- const finalValidation = await validator.validate(projectDir);
153570
- if (finalValidation.status === 0) {
153571
- console.log(`\u2705 ${validator.type} validation passed after batch fixes`);
153572
- eventEmitter.emitEvent("validation:done", { outputPath: projectDir });
153573
- return;
153574
- }
153575
- const remainingErrors = finalValidation.parsedValidationErrors?.length || 0;
153576
- const unfixedValidationErrors = finalValidation.validationErrors || "Unknown validation errors";
153577
- console.log(`\u{1F4CB} ${remainingErrors} errors remaining after fixes`);
153578
- const errorMessage = `Validation failed after batch fix attempt. Fixed ${totalFixesApplied} errors, but ${remainingErrors} remain:
153579
- ${unfixedValidationErrors}`;
153580
- const validationErrors = finalValidation.parsedValidationErrors || [];
153581
- const error = new ditto_codegen_types_12.CodeValidationError(errorMessage, {
153582
- validationType: ditto_codegen_types_12.ValidationType.TYPESCRIPT,
153583
- errors: validationErrors
153584
- });
153585
- throw error;
153586
153662
  }
153587
153663
  }
153588
153664
  });
@@ -154714,7 +154790,7 @@ var require_orchestrator = __commonJS({
154714
154790
  });
154715
154791
  await (0, fixFlow_1.startFixFlow)({
154716
154792
  projectDir: outputPath
154717
- }, this);
154793
+ });
154718
154794
  const durationMs = Date.now() - start;
154719
154795
  this.emitEvent("finish", { outputPath, durationMs });
154720
154796
  }
@@ -374032,7 +374108,7 @@ var require_IterationOrchestrator = __commonJS({
374032
374108
  });
374033
374109
  await (0, fixFlow_1.startFixFlow)({
374034
374110
  projectDir: outputPath
374035
- }, this);
374111
+ });
374036
374112
  const durationMs = Date.now() - start;
374037
374113
  this.emitEvent("finish:iteration", { outputPath, durationMs });
374038
374114
  return iterationPlan;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/ditto-codegen-public",
3
- "version": "1.0.165",
3
+ "version": "1.0.166",
4
4
  "description": "AI-powered Wix CLI app generator - standalone executable",
5
5
  "scripts": {
6
6
  "build": "node build.mjs",
@@ -24,5 +24,5 @@
24
24
  "@wix/ditto-codegen": "1.0.0",
25
25
  "esbuild": "^0.25.9"
26
26
  },
27
- "falconPackageHash": "0b13a4cd183dcf4fcac15d021bc0c4ff6e6dbc4052a27bf1b9d2c706"
27
+ "falconPackageHash": "f4fa79a226dd76d71e7123b20e0cc77f46c96764501c9af43a76a455"
28
28
  }