@wix/ditto-codegen-public 1.0.164 → 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 +158 -86
  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);
@@ -139625,9 +139640,7 @@ var require_wdsPackage = __commonJS({
139625
139640
  })();
139626
139641
  Object.defineProperty(exports2, "__esModule", { value: true });
139627
139642
  exports2.buildWdsSystemPrompt = buildWdsSystemPrompt;
139628
- var fs4 = __importStar2(require("fs"));
139629
- var path2 = __importStar2(require("path"));
139630
- require_wds_storybook();
139643
+ var wdsJson = __importStar2(require_wds_storybook());
139631
139644
  function formatComponentAsPromptBlock(component) {
139632
139645
  const componentDescription = component?.content?.description;
139633
139646
  const features = component?.content?.featureExamples?.map((feature) => ` - ${feature.title}: ${feature.description}`).join("\n");
@@ -139643,9 +139656,7 @@ ${componentDescription}
139643
139656
  </component>`;
139644
139657
  }
139645
139658
  async function buildWdsSystemPrompt(allowedComponents) {
139646
- const storybookJsonPath = path2.join(__dirname, "wds-storybook.json");
139647
- const storybookData = fs4.readFileSync(storybookJsonPath, "utf-8");
139648
- const parsedData = JSON.parse(storybookData);
139659
+ const parsedData = wdsJson;
139649
139660
  const relevantComponents = (parsedData.items || []).filter((component) => allowedComponents.has(component.storyName));
139650
139661
  if (!relevantComponents.length) {
139651
139662
  return "";
@@ -153267,9 +153278,10 @@ var require_TypescriptValidator = __commonJS({
153267
153278
  "use strict";
153268
153279
  Object.defineProperty(exports2, "__esModule", { value: true });
153269
153280
  var child_process_1 = require("child_process");
153281
+ var ditto_codegen_types_12 = require_dist();
153270
153282
  var TypescriptValidator = class {
153271
153283
  constructor() {
153272
- this.type = "typescript";
153284
+ this.type = ditto_codegen_types_12.ValidationType.TYPESCRIPT;
153273
153285
  }
153274
153286
  async validate(projectDir) {
153275
153287
  const result = this.runTypecheck(projectDir);
@@ -153305,7 +153317,7 @@ var require_TypescriptValidator = __commonJS({
153305
153317
  }
153306
153318
  async parseTypecheckError(stdout) {
153307
153319
  const lines = stdout.split(/\r?\n/);
153308
- 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>.+)$/;
153309
153321
  const results = [];
153310
153322
  for (const line of lines) {
153311
153323
  const m = line.match(tsRegex);
@@ -153314,6 +153326,7 @@ var require_TypescriptValidator = __commonJS({
153314
153326
  filePath: m.groups["path"],
153315
153327
  line: Number(m.groups["line"]),
153316
153328
  column: Number(m.groups["col"]),
153329
+ errorCode: m.groups["code"],
153317
153330
  errorMessage: m.groups["msg"].trim()
153318
153331
  });
153319
153332
  }
@@ -153338,12 +153351,12 @@ var require_ValidatorFactory = __commonJS({
153338
153351
  var ValidatorFactory = class {
153339
153352
  constructor() {
153340
153353
  }
153341
- getValidator(type = "typescript") {
153342
- if (type === "typescript") {
153354
+ getValidator(type = ditto_codegen_types_12.ValidationType.TYPESCRIPT) {
153355
+ if (type === ditto_codegen_types_12.ValidationType.TYPESCRIPT) {
153343
153356
  return new TypescriptValidator_1.default();
153344
153357
  }
153345
- throw new ditto_codegen_types_12.ValidationConfigurationError(`Invalid validator type: ${type}`, {
153346
- validatorType: type
153358
+ throw new ditto_codegen_types_12.AutoFixError(`Invalid validator type: ${type}`, {
153359
+ validationType: type
153347
153360
  });
153348
153361
  }
153349
153362
  };
@@ -153373,6 +153386,17 @@ var require_NaiveFixerAgent = __commonJS({
153373
153386
  constructor() {
153374
153387
  this.name = "BatchFixAgent";
153375
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
+ }
153376
153400
  async fixFileWithMultipleErrors(input) {
153377
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.
153378
153402
 
@@ -153391,7 +153415,8 @@ Focus on common TypeScript errors:
153391
153415
  - Syntax errors
153392
153416
  - Missing semicolons or brackets
153393
153417
  - Incorrect component props`;
153394
- 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);
153395
153420
  const userMessage = `File: ${input.filePath}
153396
153421
  Language: ${input.language}
153397
153422
 
@@ -153401,6 +153426,8 @@ ${errorsList}
153401
153426
  CURRENT FILE CONTENT:
153402
153427
  ${input.content}
153403
153428
 
153429
+ ${previousErrorsSection}
153430
+
153404
153431
  Please provide the complete fixed file content that resolves ALL the errors listed above.`;
153405
153432
  try {
153406
153433
  const result = await codeGenerationService_12.codegenAIProxyService.generateCodegenObject({
@@ -153447,7 +153474,7 @@ var require_NaiveErrorFixer = __commonJS({
153447
153474
  var NaiveErrorFixer = class {
153448
153475
  constructor() {
153449
153476
  }
153450
- async fixMultipleErrors(projectDir, filePath, errors) {
153477
+ async fixMultipleErrors(projectDir, filePath, errors, previousErrors) {
153451
153478
  if (errors.length === 0) {
153452
153479
  return;
153453
153480
  }
@@ -153465,9 +153492,11 @@ var require_NaiveErrorFixer = __commonJS({
153465
153492
  errors: errors.map((error) => ({
153466
153493
  line: error.line || 1,
153467
153494
  column: error.column || 1,
153495
+ errorCode: error.errorCode,
153468
153496
  message: error.errorMessage || "Unknown error"
153469
153497
  })),
153470
- language: "typescript"
153498
+ language: "typescript",
153499
+ previousErrors: previousErrors?.map(formatErrorToString)
153471
153500
  });
153472
153501
  if (batchResult.fixedContent) {
153473
153502
  fs_1.default.writeFileSync(absolutePath, batchResult.fixedContent, "utf8");
@@ -153485,6 +153514,9 @@ var require_NaiveErrorFixer = __commonJS({
153485
153514
  }
153486
153515
  };
153487
153516
  exports2.default = NaiveErrorFixer;
153517
+ var formatErrorToString = (err) => {
153518
+ return `Line ${err.line}${err.errorCode ? ` (${err.errorCode})` : ""}: ${err.errorMessage}`;
153519
+ };
153488
153520
  }
153489
153521
  });
153490
153522
 
@@ -153527,66 +153559,106 @@ var require_fixFlow = __commonJS({
153527
153559
  var ValidatorFactory_1 = __importDefault2(require_ValidatorFactory());
153528
153560
  var FixerFactory_1 = __importDefault2(require_FixerFactory());
153529
153561
  var ditto_codegen_types_12 = require_dist();
153562
+ var job_context_storage_12 = require_job_context_storage();
153563
+ var codeGenerationService_12 = require_codeGenerationService();
153530
153564
  var MAX_ERRORS_PER_BATCH = 20;
153531
- async function startFixFlow(request, eventEmitter) {
153565
+ async function startFixFlow(request) {
153532
153566
  const { projectDir } = request;
153533
- eventEmitter.emitEvent("validation:start", { outputPath: projectDir });
153534
153567
  const fixerFactory = new FixerFactory_1.default();
153535
153568
  const validatorFactory = new ValidatorFactory_1.default();
153536
153569
  const validator = validatorFactory.getValidator();
153537
- console.log("\u{1F50D} Running validation and batch fix...");
153538
- const initialValidation = await validator.validate(projectDir);
153539
- if (initialValidation.status === 0) {
153540
- console.log(`\u2705 ${validator.type} validation passed - no fixes needed`);
153541
- eventEmitter.emitEvent("validation:done", { outputPath: projectDir });
153542
- return;
153543
- }
153544
- if (!initialValidation.parsedValidationErrors || initialValidation.parsedValidationErrors.length === 0) {
153545
- const errorMessage2 = `Validation failed but no parsed errors available. Raw errors: ${initialValidation.validationErrors}`;
153546
- console.warn(`\u26A0\uFE0F ${errorMessage2}`);
153547
- const error2 = new ditto_codegen_types_12.ValidationConfigurationError(errorMessage2);
153548
- throw error2;
153549
- }
153550
- const totalErrors = initialValidation.parsedValidationErrors.length;
153551
- console.log(`\u{1F4DD} Found ${totalErrors} errors to fix`);
153552
- const errorsByFile = (0, utils_1.mapGroupBy)(initialValidation.parsedValidationErrors, (error2) => error2.filePath);
153553
- console.log(`\u{1F4C1} Errors span ${errorsByFile.size} files`);
153554
- let totalFixesApplied = 0;
153555
153570
  const fixer = fixerFactory.getFixer();
153556
- for (const [filePath, fileErrors] of errorsByFile) {
153557
- const errorsToFix = fileErrors.slice(0, MAX_ERRORS_PER_BATCH);
153558
- if (errorsToFix.length < fileErrors.length) {
153559
- console.log(`\u{1F4CB} Processing ${errorsToFix.length}/${fileErrors.length} errors for ${filePath} (batching to prevent AI overload)`);
153560
- } else {
153561
- 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
+ }
153562
153600
  }
153563
- try {
153564
- await fixer.fixMultipleErrors(projectDir, filePath, errorsToFix);
153565
- totalFixesApplied += errorsToFix.length;
153566
- console.log(`\u2705 Applied batch fixes for ${filePath}`);
153567
- } catch (fixError) {
153568
- console.error(`\u274C Failed to fix errors in ${filePath}: ${fixError instanceof Error ? fixError.message : String(fixError)}`);
153569
- 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);
153570
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;
153571
153661
  }
153572
- console.log(`\u{1F4CA} Batch fix completed: ${totalFixesApplied} fixes applied across ${errorsByFile.size} files`);
153573
- const finalValidation = await validator.validate(projectDir);
153574
- if (finalValidation.status === 0) {
153575
- console.log(`\u2705 ${validator.type} validation passed after batch fixes`);
153576
- eventEmitter.emitEvent("validation:done", { outputPath: projectDir });
153577
- return;
153578
- }
153579
- const remainingErrors = finalValidation.parsedValidationErrors?.length || 0;
153580
- const unfixedValidationErrors = finalValidation.validationErrors || "Unknown validation errors";
153581
- console.log(`\u{1F4CB} ${remainingErrors} errors remaining after fixes`);
153582
- const errorMessage = `Validation failed after batch fix attempt. Fixed ${totalFixesApplied} errors, but ${remainingErrors} remain:
153583
- ${unfixedValidationErrors}`;
153584
- const validationErrors = finalValidation.parsedValidationErrors || [];
153585
- const error = new ditto_codegen_types_12.CodeValidationError(errorMessage, {
153586
- validationType: ditto_codegen_types_12.ValidationType.TYPESCRIPT,
153587
- errors: validationErrors
153588
- });
153589
- throw error;
153590
153662
  }
153591
153663
  }
153592
153664
  });
@@ -154718,7 +154790,7 @@ var require_orchestrator = __commonJS({
154718
154790
  });
154719
154791
  await (0, fixFlow_1.startFixFlow)({
154720
154792
  projectDir: outputPath
154721
- }, this);
154793
+ });
154722
154794
  const durationMs = Date.now() - start;
154723
154795
  this.emitEvent("finish", { outputPath, durationMs });
154724
154796
  }
@@ -374036,7 +374108,7 @@ var require_IterationOrchestrator = __commonJS({
374036
374108
  });
374037
374109
  await (0, fixFlow_1.startFixFlow)({
374038
374110
  projectDir: outputPath
374039
- }, this);
374111
+ });
374040
374112
  const durationMs = Date.now() - start;
374041
374113
  this.emitEvent("finish:iteration", { outputPath, durationMs });
374042
374114
  return iterationPlan;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/ditto-codegen-public",
3
- "version": "1.0.164",
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": "73292fd1b72e5f37603b50c29a72115965d1026e4136e3f84df23c14"
27
+ "falconPackageHash": "f4fa79a226dd76d71e7123b20e0cc77f46c96764501c9af43a76a455"
28
28
  }