@wix/ditto-codegen-public 1.0.191 → 1.0.193

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 +97 -39
  2. package/package.json +2 -2
package/dist/out.js CHANGED
@@ -36576,6 +36576,7 @@ var require_CodegenAIProxyService = __commonJS({
36576
36576
  isEnabled: true,
36577
36577
  functionId: payload.agentName
36578
36578
  },
36579
+ ...payload.experimental_repairText ? { experimental_repairText: payload.experimental_repairText } : {},
36579
36580
  maxOutputTokens: 1e4,
36580
36581
  maxRetries: 3,
36581
36582
  temperature: 0
@@ -72986,6 +72987,7 @@ var require_IterationAgent = __commonJS({
72986
72987
  Object.defineProperty(exports2, "__esModule", { value: true });
72987
72988
  exports2.IterationAgent = void 0;
72988
72989
  var zod_1 = require_zod();
72990
+ var ai_1 = require_dist8();
72989
72991
  var iteration_agent_prompt_1 = require_iteration_agent_prompt();
72990
72992
  var AgentsRegistry_1 = require_AgentsRegistry();
72991
72993
  var codegen_common_logic_1 = require_dist9();
@@ -72994,16 +72996,17 @@ var require_IterationAgent = __commonJS({
72994
72996
  var codeGenerationService_12 = require_codeGenerationService();
72995
72997
  var extensionFormatters_1 = require_extensionFormatters();
72996
72998
  var contextBuilders_1 = require_contextBuilders();
72999
+ var MAX_NAME_LENGTH = 30;
72997
73000
  var CurrentExtensionSchema = zod_1.z.object({
72998
73001
  extensionType: zod_1.z.enum(codegen_common_logic_1.codeGenerationExtensionTypes).describe("The extension kind to trigger"),
72999
- name: zod_1.z.string().min(2).describe("Short, human-readable name for the extension. Less than 30 chars."),
73002
+ name: zod_1.z.string().min(2).max(MAX_NAME_LENGTH).describe(`Short, human-readable name for the extension. Less than ${MAX_NAME_LENGTH} chars.`),
73000
73003
  relatedSpis: zod_1.z.array(zod_1.z.string()).optional().describe("Optional value, only for SPI extensions - specify the SPI types"),
73001
73004
  paths: zod_1.z.array(zod_1.z.string()).describe("Paths relevant for this extension"),
73002
73005
  relevantUserRequest: zod_1.z.string().describe("What part of the user request this extension should do, do not reference other extensions.")
73003
73006
  });
73004
73007
  var AdditionalExtensionSchema = zod_1.z.object({
73005
73008
  extensionType: zod_1.z.enum(codegen_common_logic_1.codeGenerationExtensionTypes).describe("The extension kind to add"),
73006
- name: zod_1.z.string().min(2).max(30).describe("Short, human-readable name for the extension. Less than 30 chars."),
73009
+ name: zod_1.z.string().min(2).max(MAX_NAME_LENGTH).describe(`Short, human-readable name for the extension. Less than ${MAX_NAME_LENGTH} chars.`),
73007
73010
  relatedSpis: zod_1.z.array(zod_1.z.string()).optional().describe("Optional value, only for SPI extensions - specify the SPI types"),
73008
73011
  relevantUserRequest: zod_1.z.string().describe("What part of the user request this extension should do, do not reference other extensions.")
73009
73012
  });
@@ -73040,6 +73043,34 @@ var require_IterationAgent = __commonJS({
73040
73043
  })) || []
73041
73044
  };
73042
73045
  }
73046
+ async repairNameTooLong({ text, error }) {
73047
+ if (!ai_1.TypeValidationError.isInstance(error)) {
73048
+ return text;
73049
+ }
73050
+ const cause = error.cause;
73051
+ const hasNameTooLongIssue = cause?.issues?.some((issue) => issue.code === "too_big" && issue.path?.at(-1) === "name");
73052
+ if (!hasNameTooLongIssue) {
73053
+ return text;
73054
+ }
73055
+ const parsed = JSON.parse(text);
73056
+ const hasCurrentExtensionsIssue = parsed.currentExtensions && cause?.issues?.some((issue) => issue.path?.includes("currentExtensions"));
73057
+ const hasAdditionalExtensionsIssue = parsed.additionalExtensions && cause?.issues?.some((issue) => issue.path?.includes("additionalExtensions"));
73058
+ if (hasCurrentExtensionsIssue) {
73059
+ for (const ext of parsed.currentExtensions) {
73060
+ if (ext.name && ext.name.length > MAX_NAME_LENGTH) {
73061
+ ext.name = ext.name.slice(0, MAX_NAME_LENGTH);
73062
+ }
73063
+ }
73064
+ }
73065
+ if (hasAdditionalExtensionsIssue) {
73066
+ for (const ext of parsed.additionalExtensions) {
73067
+ if (ext.name && ext.name.length > MAX_NAME_LENGTH) {
73068
+ ext.name = ext.name.slice(0, MAX_NAME_LENGTH);
73069
+ }
73070
+ }
73071
+ }
73072
+ return JSON.stringify(parsed);
73073
+ }
73043
73074
  buildUserPrompt({ chatHistory, currentUserRequest, previousResources, extensionSelectorResult }) {
73044
73075
  const sections = (0, contextBuilders_1.buildContextSections)(chatHistory, currentUserRequest, previousResources);
73045
73076
  sections.push(`
@@ -73063,7 +73094,8 @@ ${(0, extensionFormatters_1.formatContextExtensions)(extensionSelectorResult.con
73063
73094
  provider: constants_1.LLM_PROVIDERS.ANTHROPIC,
73064
73095
  model: constants_1.LLM_MODELS.CLAUDE_3_5_HAIKU_LATEST,
73065
73096
  schema: IterationPlanSchema,
73066
- agentName: this.name
73097
+ agentName: this.name,
73098
+ experimental_repairText: this.repairNameTooLong
73067
73099
  });
73068
73100
  const resultObject = {
73069
73101
  currentExtensions: result.object.currentExtensions.map((ext) => ({
@@ -83795,8 +83827,8 @@ var require_ValidatorFactory = __commonJS({
83795
83827
  if (type === ditto_codegen_types_12.ValidationType.TYPESCRIPT) {
83796
83828
  return new TypescriptValidator_1.default();
83797
83829
  }
83798
- throw new ditto_codegen_types_12.AutoFixError(`Invalid validator type: ${type}`, {
83799
- validationType: type
83830
+ throw new ditto_codegen_types_12.ValidationConfigurationError(`Invalid validator type: ${type}`, {
83831
+ validatorType: type
83800
83832
  });
83801
83833
  }
83802
83834
  };
@@ -84002,14 +84034,23 @@ var require_fixFlow = __commonJS({
84002
84034
  var job_context_storage_12 = require_job_context_storage();
84003
84035
  var codeGenerationService_12 = require_codeGenerationService();
84004
84036
  var MAX_ERRORS_PER_BATCH = 20;
84037
+ var MAX_FIX_ATTEMPTS = 3;
84038
+ var toErrorSummary = (error) => ({
84039
+ filePath: error.filePath,
84040
+ line: error.line,
84041
+ message: error.errorMessage
84042
+ });
84043
+ var createErrorComparisonKey = (e) => `${e.filePath}:${e.line ?? "unknown"}:${e.errorMessage}`;
84005
84044
  async function startFixFlow(request) {
84006
84045
  const { projectDir } = request;
84007
84046
  const fixerFactory = new FixerFactory_1.default();
84008
84047
  const validatorFactory = new ValidatorFactory_1.default();
84009
84048
  const validator = validatorFactory.getValidator();
84010
84049
  const fixer = fixerFactory.getFixer();
84011
- const MAX_FIX_ATTEMPTS = 3;
84012
84050
  const parentContext = job_context_storage_12.jobContextStorage.getStore();
84051
+ if (!parentContext?.jobId) {
84052
+ throw new Error("Fix flow must be called within a job context");
84053
+ }
84013
84054
  const fixTaskId = `fix-flow`;
84014
84055
  const updateFixTask = async (status, payload = {}) => {
84015
84056
  await codeGenerationService_12.codeGenerationService.updateTask(parentContext.jobId, fixTaskId, status, payload);
@@ -84020,9 +84061,13 @@ var require_fixFlow = __commonJS({
84020
84061
  name: "Auto-Fixer",
84021
84062
  status: ditto_codegen_types_12.Status.RUNNING,
84022
84063
  description: "Running automatic code fixes",
84023
- agentName: "NaiveFixerAgent"
84064
+ agentName: "FixerAgent"
84024
84065
  });
84025
84066
  console.log("\u{1F50D} Running validation and batch fix...");
84067
+ const fixState = {
84068
+ initialErrors: [],
84069
+ lastRunErrors: /* @__PURE__ */ new Map()
84070
+ };
84026
84071
  const processFiles = async (fileEntries, lastRunErrors) => {
84027
84072
  for (const [filePath, fileErrors] of fileEntries) {
84028
84073
  const errorsToFix = fileErrors.slice(0, MAX_ERRORS_PER_BATCH);
@@ -84040,48 +84085,62 @@ var require_fixFlow = __commonJS({
84040
84085
  }
84041
84086
  }
84042
84087
  };
84043
- const fixState = {
84044
- accumulatedFixes: 0,
84045
- lastRunErrors: /* @__PURE__ */ new Map()
84088
+ const getFixedErrors = (remainingErrors) => {
84089
+ const remainingKeys = new Set(remainingErrors.map(createErrorComparisonKey));
84090
+ return fixState.initialErrors.filter((e) => !remainingKeys.has(createErrorComparisonKey(e)));
84046
84091
  };
84047
- const handleValidationFailure = async (validation, reason) => {
84048
- const remainingErrors = validation.parsedValidationErrors?.length || 0;
84049
- const unfixedValidationErrors = validation.validationErrors || "Unknown validation errors";
84050
- console.log(`\u{1F4CB} ${remainingErrors} errors remaining after fixes`);
84051
- const errorMessage = `Validation failed: ${reason}. Fixed ${fixState.accumulatedFixes} errors, but ${remainingErrors} remain:
84052
- ${unfixedValidationErrors}`;
84053
- const validationErrors = validation.parsedValidationErrors || [];
84092
+ const buildExhaustedResult = (validation, attemptsMade) => {
84093
+ const remainingErrors = validation.parsedValidationErrors ?? [];
84094
+ const fixedErrors = getFixedErrors(remainingErrors);
84095
+ console.log(`\u{1F4CB} ${remainingErrors.length} errors remaining after ${attemptsMade} fix attempts (fixed ${fixedErrors.length})`);
84096
+ const hasNoParseableErrors = remainingErrors.length === 0;
84097
+ const errorMessage = hasNoParseableErrors ? `Auto-fix exhausted: validation still failing after ${attemptsMade} attempts (no parseable errors)` : `Auto-fix exhausted: ${remainingErrors.length} TypeScript errors remain after ${attemptsMade} attempts`;
84054
84098
  const error = new ditto_codegen_types_12.CodeValidationError(errorMessage, {
84055
84099
  validationType: ditto_codegen_types_12.ValidationType.TYPESCRIPT,
84056
- errors: validationErrors
84100
+ errors: remainingErrors
84057
84101
  });
84058
- await updateFixTask(ditto_codegen_types_12.Status.FAILED, { error: errorMessage });
84059
- throw error;
84102
+ return { error, fixedErrors };
84060
84103
  };
84061
- const ensureParsedErrorsExist = async (validation) => {
84062
- const hasParsedErrorsToFix = validation.parsedValidationErrors.length > 0;
84063
- if (!hasParsedErrorsToFix) {
84064
- const errorMessage = `Validation failed but no parsed errors available. Raw errors: ${validation.validationErrors}`;
84104
+ const ensureParsedErrorsExist = (validation) => {
84105
+ const parsedErrors = validation.parsedValidationErrors ?? [];
84106
+ if (parsedErrors.length === 0) {
84107
+ const errorMessage = `Validation failed but no parsed errors available. Raw errors: ${validation.validationErrors ?? "No errors"}`;
84065
84108
  console.warn(`\u26A0\uFE0F ${errorMessage}`);
84066
- await updateFixTask(ditto_codegen_types_12.Status.FAILED, { error: errorMessage });
84067
- throw new Error(errorMessage);
84109
+ throw new ditto_codegen_types_12.ValidationConfigurationError(errorMessage, {
84110
+ validatorType: validator.type
84111
+ });
84068
84112
  }
84069
84113
  };
84070
84114
  try {
84071
- for (let attempt = 0; attempt < MAX_FIX_ATTEMPTS; attempt++) {
84115
+ for (let attempt = 1; attempt <= MAX_FIX_ATTEMPTS; attempt++) {
84072
84116
  console.log(`\u{1F504} Fix Attempt ${attempt}/${MAX_FIX_ATTEMPTS}`);
84073
84117
  const currentValidation = await validator.validate(projectDir);
84074
- if (currentValidation.status === 0) {
84118
+ const validationPassed = currentValidation.status === 0;
84119
+ const isFirstAttempt = attempt === 1;
84120
+ const isLastAttempt = attempt === MAX_FIX_ATTEMPTS;
84121
+ if (validationPassed) {
84122
+ const fixedErrors = getFixedErrors([]);
84075
84123
  console.log(`\u2705 ${validator.type} validation passed - no fixes needed`);
84076
84124
  await updateFixTask(ditto_codegen_types_12.Status.COMPLETED, {
84077
- description: `Fixed ${fixState.accumulatedFixes} errors.`
84125
+ description: `Fixed ${fixedErrors.length} errors.`,
84126
+ fixedErrors: fixedErrors.map(toErrorSummary)
84078
84127
  });
84079
84128
  return;
84080
84129
  }
84081
- if (attempt === MAX_FIX_ATTEMPTS - 1) {
84082
- await handleValidationFailure(currentValidation, `after ${MAX_FIX_ATTEMPTS} fix attempts`);
84130
+ if (isFirstAttempt) {
84131
+ fixState.initialErrors = currentValidation.parsedValidationErrors ?? [];
84132
+ }
84133
+ if (isLastAttempt) {
84134
+ const { error, fixedErrors } = buildExhaustedResult(currentValidation, attempt);
84135
+ await updateFixTask(ditto_codegen_types_12.Status.COMPLETED, {
84136
+ description: `Completed with ${error.errors.length} unresolved errors after ${attempt} attempts`,
84137
+ warning: error.message,
84138
+ fixedErrors: fixedErrors.map(toErrorSummary),
84139
+ remainingErrors: error.errors.map(toErrorSummary)
84140
+ });
84141
+ throw error;
84083
84142
  }
84084
- await ensureParsedErrorsExist(currentValidation);
84143
+ ensureParsedErrorsExist(currentValidation);
84085
84144
  const totalErrors = currentValidation.parsedValidationErrors.length;
84086
84145
  console.log(`\u{1F4DD} Found ${totalErrors} errors to fix`);
84087
84146
  const errorsByFile = (0, utils_1.mapGroupBy)(currentValidation.parsedValidationErrors, (error) => error.filePath);
@@ -84090,15 +84149,14 @@ ${unfixedValidationErrors}`;
84090
84149
  fixState.lastRunErrors = errorsByFile;
84091
84150
  }
84092
84151
  } catch (error) {
84093
- const errorMessage = error instanceof Error ? error.message : String(error);
84094
- const finalError = new ditto_codegen_types_12.AutoFixError(errorMessage, {
84095
- validationType: validator.type,
84096
- cause: error
84097
- });
84152
+ if (error instanceof ditto_codegen_types_12.CodeValidationError) {
84153
+ throw error;
84154
+ }
84155
+ const codegenError = (0, ditto_codegen_types_12.toCodegenError)(error);
84098
84156
  await updateFixTask(ditto_codegen_types_12.Status.FAILED, {
84099
- error: finalError.message
84157
+ error: codegenError.message
84100
84158
  });
84101
- throw finalError;
84159
+ throw codegenError;
84102
84160
  }
84103
84161
  }
84104
84162
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/ditto-codegen-public",
3
- "version": "1.0.191",
3
+ "version": "1.0.193",
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": "5b67b19500c5227d223ef15b69d91c8c965fbd2aa2cabee9f5ac410a"
27
+ "falconPackageHash": "416717af517d1fd26dd71583134531f28a30e81a627516f294036aaa"
28
28
  }