@wix/ditto-codegen-public 1.0.203 → 1.0.205

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.
package/dist/out.js CHANGED
@@ -38994,6 +38994,58 @@ var require_sdkConfig = __commonJS({
38994
38994
  }
38995
38995
  });
38996
38996
 
38997
+ // ../codegen-common-logic/dist/generate-text-helpers.js
38998
+ var require_generate_text_helpers = __commonJS({
38999
+ "../codegen-common-logic/dist/generate-text-helpers.js"(exports2) {
39000
+ "use strict";
39001
+ Object.defineProperty(exports2, "__esModule", { value: true });
39002
+ exports2.extractToolResult = extractToolResult;
39003
+ exports2.stopOnToolCall = stopOnToolCall;
39004
+ exports2.stopOnNoToolCalls = stopOnNoToolCalls;
39005
+ exports2.generateAgentText = generateAgentText;
39006
+ var ai_1 = require_dist8();
39007
+ var ditto_codegen_types_12 = require_dist();
39008
+ function extractToolResult(toolCalls, toolName) {
39009
+ const call = toolCalls.find((tc) => tc.toolName === toolName);
39010
+ return call?.input ?? null;
39011
+ }
39012
+ function stopOnToolCall(toolName) {
39013
+ return ({ steps }) => {
39014
+ const lastStep = steps[steps.length - 1];
39015
+ return lastStep?.toolCalls.some((tc) => tc.toolName === toolName && !("invalid" in tc) && !("error" in tc)) ?? false;
39016
+ };
39017
+ }
39018
+ function stopOnNoToolCalls(maxSteps) {
39019
+ return ({ steps }) => {
39020
+ if (steps.length >= maxSteps) {
39021
+ return true;
39022
+ }
39023
+ const lastStep = steps[steps.length - 1];
39024
+ return lastStep?.toolCalls.length === 0;
39025
+ };
39026
+ }
39027
+ async function generateAgentText(options) {
39028
+ return (0, ai_1.generateText)({
39029
+ model: options.model,
39030
+ tools: options.tools,
39031
+ stopWhen: options.stopWhen,
39032
+ messages: [
39033
+ {
39034
+ role: "system",
39035
+ content: options.systemPrompt,
39036
+ // Anthropic-specific: enables prompt caching. Ignored by other providers.
39037
+ providerOptions: (0, ditto_codegen_types_12.withCaching)("1h")
39038
+ },
39039
+ { role: "user", content: options.userMessage }
39040
+ ],
39041
+ maxRetries: 3,
39042
+ temperature: 0,
39043
+ experimental_telemetry: { isEnabled: true, functionId: options.agentName }
39044
+ });
39045
+ }
39046
+ }
39047
+ });
39048
+
38997
39049
  // ../codegen-common-logic/dist/index.js
38998
39050
  var require_dist9 = __commonJS({
38999
39051
  "../codegen-common-logic/dist/index.js"(exports2) {
@@ -39033,6 +39085,7 @@ var require_dist9 = __commonJS({
39033
39085
  __exportStar2(require_commonUseCasesGuide(), exports2);
39034
39086
  __exportStar2(require_system_prompts(), exports2);
39035
39087
  __exportStar2(require_sdkConfig(), exports2);
39088
+ __exportStar2(require_generate_text_helpers(), exports2);
39036
39089
  }
39037
39090
  });
39038
39091
 
@@ -72599,6 +72652,104 @@ var require_prompt_selectors = __commonJS({
72599
72652
  }
72600
72653
  });
72601
72654
 
72655
+ // dist/agents/utils/api.js
72656
+ var require_api2 = __commonJS({
72657
+ "dist/agents/utils/api.js"(exports2) {
72658
+ "use strict";
72659
+ Object.defineProperty(exports2, "__esModule", { value: true });
72660
+ exports2.getApiDocumentation = exports2.extractApis = exports2.extractApiNames = exports2.extractApiDocumentation = void 0;
72661
+ var isExtensionEnriched = (extension) => {
72662
+ return extension.relatedApis?.some((api) => "documentation" in api || "methodSchema" in api) ?? false;
72663
+ };
72664
+ var extractApiDocumentation = (extension) => {
72665
+ if (isExtensionEnriched(extension)) {
72666
+ return { apiDocumentation: (0, exports2.getApiDocumentation)(extension), apiNames: [] };
72667
+ }
72668
+ return { apiDocumentation: "", apiNames: (0, exports2.extractApiNames)(extension) };
72669
+ };
72670
+ exports2.extractApiDocumentation = extractApiDocumentation;
72671
+ var extractApiNames = (extension) => {
72672
+ return extension.relatedApis?.map((api) => api.name).filter((name) => !!name) || [];
72673
+ };
72674
+ exports2.extractApiNames = extractApiNames;
72675
+ var extractApis = (extension) => {
72676
+ return extension.relatedApis?.map((api) => ({
72677
+ name: api.name,
72678
+ purpose: api.purpose,
72679
+ documentation: api.documentation,
72680
+ methodSchema: api.methodSchema
72681
+ })) || [];
72682
+ };
72683
+ exports2.extractApis = extractApis;
72684
+ var getApiDocumentation = (extension) => {
72685
+ const apis = (0, exports2.extractApis)(extension);
72686
+ const docsWithContent = apis.filter((api) => api.documentation || api.methodSchema);
72687
+ if (docsWithContent.length === 0) {
72688
+ return "";
72689
+ }
72690
+ return docsWithContent.map((api) => {
72691
+ const parts = [];
72692
+ parts.push(`<api name="${api.name}">`);
72693
+ if (api.purpose) {
72694
+ parts.push(`<purpose>${api.purpose}</purpose>`);
72695
+ }
72696
+ if (api.documentation) {
72697
+ parts.push(`<documentation>${api.documentation}</documentation>`);
72698
+ }
72699
+ if (api.methodSchema) {
72700
+ parts.push(`<methodSchema>${api.methodSchema}</methodSchema>`);
72701
+ }
72702
+ parts.push(`</api>`);
72703
+ return parts.join("\n");
72704
+ }).join("\n\n");
72705
+ };
72706
+ exports2.getApiDocumentation = getApiDocumentation;
72707
+ }
72708
+ });
72709
+
72710
+ // dist/agents/utils/file-operations.js
72711
+ var require_file_operations = __commonJS({
72712
+ "dist/agents/utils/file-operations.js"(exports2) {
72713
+ "use strict";
72714
+ Object.defineProperty(exports2, "__esModule", { value: true });
72715
+ exports2.FilesSchema = exports2.FileItemSchema = exports2.FileCreateOrUpdateSchema = void 0;
72716
+ var zod_1 = require_zod();
72717
+ var ditto_codegen_types_12 = require_dist();
72718
+ exports2.FileCreateOrUpdateSchema = zod_1.z.object({
72719
+ operation: zod_1.z.union([
72720
+ zod_1.z.literal(ditto_codegen_types_12.ExtensionGenerationOperation.INSERT),
72721
+ zod_1.z.literal(ditto_codegen_types_12.ExtensionGenerationOperation.UPDATE)
72722
+ ]).describe("File operation: insert (new file), update (modify existing)").default(ditto_codegen_types_12.ExtensionGenerationOperation.INSERT),
72723
+ path: zod_1.z.string().describe("Relative file path from project root"),
72724
+ content: zod_1.z.string().describe("Complete file content as a string (for JSON files, stringify the object). Required for insert and update operations.")
72725
+ });
72726
+ var FileEditSchema = zod_1.z.object({
72727
+ operation: zod_1.z.literal(ditto_codegen_types_12.ExtensionGenerationOperation.EDIT),
72728
+ path: zod_1.z.string().describe("Relative file path from project root"),
72729
+ replacements: zod_1.z.array(zod_1.z.object({
72730
+ oldString: zod_1.z.string().describe("The text to replace (must match the file contents exactly, including all whitespace and indentation)"),
72731
+ newString: zod_1.z.string().describe("The edited text to replace the oldString"),
72732
+ replaceAll: zod_1.z.boolean().optional().describe("Replace all occurrences of oldString (default false)")
72733
+ })).min(1).describe("List of string replacements to apply")
72734
+ });
72735
+ var FileDeleteSchema = zod_1.z.object({
72736
+ operation: zod_1.z.literal(ditto_codegen_types_12.ExtensionGenerationOperation.DELETE),
72737
+ path: zod_1.z.string().describe("Relative file path from project root")
72738
+ });
72739
+ exports2.FileItemSchema = zod_1.z.discriminatedUnion("operation", [
72740
+ exports2.FileCreateOrUpdateSchema,
72741
+ FileDeleteSchema,
72742
+ FileEditSchema
72743
+ ]).describe(`Representation of an operation that modifies a file on the local file system.
72744
+ Use the 'insert' operation to create a new file.
72745
+ Use the 'delete' operation to remove a file.
72746
+ To modify a file, you can either use the 'edit' operation to replace a specific strings with new strings (THIS IS THE PREFERRED WAY TO MODIFY A FILE), or use the 'update' operation to replace the entire file with new content.`);
72747
+ exports2.FilesSchema = zod_1.z.object({
72748
+ files: zod_1.z.array(exports2.FileItemSchema).default([]).describe("An array of files")
72749
+ });
72750
+ }
72751
+ });
72752
+
72602
72753
  // dist/agents/utils/file-loading.js
72603
72754
  var require_file_loading = __commonJS({
72604
72755
  "dist/agents/utils/file-loading.js"(exports2) {
@@ -72765,101 +72916,43 @@ ${JSON.stringify(formattedOps, null, 2)}`;
72765
72916
  }
72766
72917
  });
72767
72918
 
72768
- // dist/agents/utils/file-operations.js
72769
- var require_file_operations = __commonJS({
72770
- "dist/agents/utils/file-operations.js"(exports2) {
72771
- "use strict";
72772
- Object.defineProperty(exports2, "__esModule", { value: true });
72773
- exports2.FilesSchema = exports2.FileItemSchema = exports2.FileCreateOrUpdateSchema = void 0;
72774
- var zod_1 = require_zod();
72775
- var ditto_codegen_types_12 = require_dist();
72776
- exports2.FileCreateOrUpdateSchema = zod_1.z.object({
72777
- operation: zod_1.z.union([
72778
- zod_1.z.literal(ditto_codegen_types_12.ExtensionGenerationOperation.INSERT),
72779
- zod_1.z.literal(ditto_codegen_types_12.ExtensionGenerationOperation.UPDATE)
72780
- ]).describe("File operation: insert (new file), update (modify existing)").default(ditto_codegen_types_12.ExtensionGenerationOperation.INSERT),
72781
- path: zod_1.z.string().describe("Relative file path from project root"),
72782
- content: zod_1.z.string().describe("Complete file content as a string (for JSON files, stringify the object). Required for insert and update operations.")
72783
- });
72784
- var FileEditSchema = zod_1.z.object({
72785
- operation: zod_1.z.literal(ditto_codegen_types_12.ExtensionGenerationOperation.EDIT),
72786
- path: zod_1.z.string().describe("Relative file path from project root"),
72787
- replacements: zod_1.z.array(zod_1.z.object({
72788
- oldString: zod_1.z.string().describe("The text to replace (must match the file contents exactly, including all whitespace and indentation)"),
72789
- newString: zod_1.z.string().describe("The edited text to replace the oldString"),
72790
- replaceAll: zod_1.z.boolean().optional().describe("Replace all occurrences of oldString (default false)")
72791
- })).min(1).describe("List of string replacements to apply")
72792
- });
72793
- var FileDeleteSchema = zod_1.z.object({
72794
- operation: zod_1.z.literal(ditto_codegen_types_12.ExtensionGenerationOperation.DELETE),
72795
- path: zod_1.z.string().describe("Relative file path from project root")
72796
- });
72797
- exports2.FileItemSchema = zod_1.z.discriminatedUnion("operation", [
72798
- exports2.FileCreateOrUpdateSchema,
72799
- FileDeleteSchema,
72800
- FileEditSchema
72801
- ]).describe(`Representation of an operation that modifies a file on the local file system.
72802
- Use the 'insert' operation to create a new file.
72803
- Use the 'delete' operation to remove a file.
72804
- To modify a file, you can either use the 'edit' operation to replace a specific strings with new strings (THIS IS THE PREFERRED WAY TO MODIFY A FILE), or use the 'update' operation to replace the entire file with new content.`);
72805
- exports2.FilesSchema = zod_1.z.object({
72806
- files: zod_1.z.array(exports2.FileItemSchema).default([]).describe("An array of files")
72807
- });
72808
- }
72809
- });
72810
-
72811
- // dist/agents/utils/api.js
72812
- var require_api2 = __commonJS({
72813
- "dist/agents/utils/api.js"(exports2) {
72919
+ // dist/agents/BaseCodeGenerationAgent.js
72920
+ var require_BaseCodeGenerationAgent = __commonJS({
72921
+ "dist/agents/BaseCodeGenerationAgent.js"(exports2) {
72814
72922
  "use strict";
72815
72923
  Object.defineProperty(exports2, "__esModule", { value: true });
72816
- exports2.getApiDocumentation = exports2.extractApis = exports2.extractApiNames = exports2.extractApiDocumentation = void 0;
72817
- var isExtensionEnriched = (extension) => {
72818
- return extension.relatedApis?.some((api) => "documentation" in api || "methodSchema" in api) ?? false;
72819
- };
72820
- var extractApiDocumentation = (extension) => {
72821
- if (isExtensionEnriched(extension)) {
72822
- return { apiDocumentation: (0, exports2.getApiDocumentation)(extension), apiNames: [] };
72924
+ exports2.BaseCodeGenerationAgent = void 0;
72925
+ var file_operations_1 = require_file_operations();
72926
+ var userPrompt_1 = require_userPrompt();
72927
+ var codeGenerationService_12 = require_codeGenerationService();
72928
+ var constants_1 = require_constants();
72929
+ var BaseCodeGenerationAgent = class {
72930
+ constructor(useIteration = false) {
72931
+ this.useIteration = useIteration;
72823
72932
  }
72824
- return { apiDocumentation: "", apiNames: (0, exports2.extractApiNames)(extension) };
72825
- };
72826
- exports2.extractApiDocumentation = extractApiDocumentation;
72827
- var extractApiNames = (extension) => {
72828
- return extension.relatedApis?.map((api) => api.name).filter((name) => !!name) || [];
72829
- };
72830
- exports2.extractApiNames = extractApiNames;
72831
- var extractApis = (extension) => {
72832
- return extension.relatedApis?.map((api) => ({
72833
- name: api.name,
72834
- purpose: api.purpose,
72835
- documentation: api.documentation,
72836
- methodSchema: api.methodSchema
72837
- })) || [];
72838
- };
72839
- exports2.extractApis = extractApis;
72840
- var getApiDocumentation = (extension) => {
72841
- const apis = (0, exports2.extractApis)(extension);
72842
- const docsWithContent = apis.filter((api) => api.documentation || api.methodSchema);
72843
- if (docsWithContent.length === 0) {
72844
- return "";
72933
+ getGenerateOptions() {
72934
+ return {
72935
+ schema: file_operations_1.FilesSchema,
72936
+ extractResult: (obj) => obj.files
72937
+ };
72938
+ }
72939
+ async generate(params) {
72940
+ const systemPrompt = await this.buildSystemPrompt(params);
72941
+ const primaryAction = this.getPrimaryAction(params);
72942
+ const userMessage = (0, userPrompt_1.buildUserPromptForCodeGenerationAgent)(params, primaryAction);
72943
+ const { schema, model, extractResult } = this.getGenerateOptions();
72944
+ const result = await codeGenerationService_12.codegenAIProxyService.generateCodegenObject({
72945
+ userMessage,
72946
+ systemPrompt,
72947
+ provider: constants_1.LLM_PROVIDERS.ANTHROPIC,
72948
+ model: model ?? constants_1.LLM_MODELS.CLAUDE_SONNET_4_5_20250929,
72949
+ schema,
72950
+ agentName: this.name
72951
+ });
72952
+ return extractResult(result.object);
72845
72953
  }
72846
- return docsWithContent.map((api) => {
72847
- const parts = [];
72848
- parts.push(`<api name="${api.name}">`);
72849
- if (api.purpose) {
72850
- parts.push(`<purpose>${api.purpose}</purpose>`);
72851
- }
72852
- if (api.documentation) {
72853
- parts.push(`<documentation>${api.documentation}</documentation>`);
72854
- }
72855
- if (api.methodSchema) {
72856
- parts.push(`<methodSchema>${api.methodSchema}</methodSchema>`);
72857
- }
72858
- parts.push(`</api>`);
72859
- return parts.join("\n");
72860
- }).join("\n\n");
72861
72954
  };
72862
- exports2.getApiDocumentation = getApiDocumentation;
72955
+ exports2.BaseCodeGenerationAgent = BaseCodeGenerationAgent;
72863
72956
  }
72864
72957
  });
72865
72958
 
@@ -72877,33 +72970,19 @@ var require_DashboardPageAgent2 = __commonJS({
72877
72970
  var dashboard_page_prompt_1 = require_dashboard_page_prompt();
72878
72971
  var prompt_selectors_1 = require_prompt_selectors();
72879
72972
  var codegen_common_logic_1 = require_dist9();
72880
- var userPrompt_1 = require_userPrompt();
72881
- var file_operations_1 = require_file_operations();
72882
72973
  var codeGenerationService_12 = require_codeGenerationService();
72883
72974
  var constants_1 = require_constants();
72884
72975
  var codegen_dashboard_agents_1 = require_dist11();
72885
72976
  var api_1 = require_api2();
72886
- var DashboardPageAgent = class {
72887
- constructor(useIteration = false) {
72888
- this.useIteration = useIteration;
72977
+ var BaseCodeGenerationAgent_1 = require_BaseCodeGenerationAgent();
72978
+ var DashboardPageAgent = class extends BaseCodeGenerationAgent_1.BaseCodeGenerationAgent {
72979
+ constructor() {
72980
+ super(...arguments);
72889
72981
  this.name = "DashboardPageAgent";
72890
72982
  }
72891
72983
  getAgentDocumentation() {
72892
72984
  return (0, codegen_common_logic_1.getDashboardPageAgentDocumentation)();
72893
72985
  }
72894
- async buildSystemPrompt({ useData, useAutoPatterns, useApiSpec, useDynamicParameters, apiNames, apiDocumentation, autoPatternsSectionIds }) {
72895
- const systemPrompt = await (0, dashboard_page_prompt_1.dashboardPagePrompt)({
72896
- useData,
72897
- useAutoPatterns,
72898
- useApiSpec,
72899
- useDynamicParameters,
72900
- apiNames,
72901
- apiDocumentation,
72902
- useIteration: this.useIteration,
72903
- autoPatternsSectionIds
72904
- });
72905
- return systemPrompt;
72906
- }
72907
72986
  async getAutoPatternsSectionIds(useAutoPatterns, userRequestSummary) {
72908
72987
  if (!useAutoPatterns || !this.useIteration || !userRequestSummary) {
72909
72988
  return void 0;
@@ -72917,7 +72996,7 @@ var require_DashboardPageAgent2 = __commonJS({
72917
72996
  const result = await autoPatternsDocSelector.generate(userRequestSummary);
72918
72997
  return result.selectedSectionIds;
72919
72998
  }
72920
- // temporary fix to add all files in the auto patterns directory as relevant files
72999
+ // Temporary fix to add all files in the auto patterns directory as relevant files
72921
73000
  addAutoPatternsRelevantFiles(params) {
72922
73001
  const relevantFilePaths = params.relevantFilePaths ?? [];
72923
73002
  const patternsJsonPath = relevantFilePaths.find((p) => p.endsWith("patterns.json"));
@@ -72935,8 +73014,8 @@ var require_DashboardPageAgent2 = __commonJS({
72935
73014
  }
72936
73015
  }
72937
73016
  }
72938
- async generate(params) {
72939
- const { blueprint, plan, userRequestSummary } = params;
73017
+ async buildSystemPrompt(params) {
73018
+ const { plan, userRequestSummary } = params;
72940
73019
  const useData = (0, prompt_selectors_1.shouldUseDataPrompt)(params);
72941
73020
  const useAutoPatterns = (0, prompt_selectors_1.shouldUseAutoPatterns)(params);
72942
73021
  const useApiSpec = Boolean(plan?.apiSpec);
@@ -72946,27 +73025,20 @@ var require_DashboardPageAgent2 = __commonJS({
72946
73025
  this.addAutoPatternsRelevantFiles(params);
72947
73026
  }
72948
73027
  const { apiDocumentation, apiNames } = (0, api_1.extractApiDocumentation)(params.extension);
72949
- const systemPrompt = await this.buildSystemPrompt({
73028
+ return (0, dashboard_page_prompt_1.dashboardPagePrompt)({
72950
73029
  useData,
72951
73030
  useAutoPatterns,
72952
73031
  useApiSpec,
72953
73032
  useDynamicParameters,
72954
73033
  apiNames,
72955
73034
  apiDocumentation,
73035
+ useIteration: this.useIteration,
72956
73036
  autoPatternsSectionIds
72957
73037
  });
72958
- const appName = blueprint?.appName ? `'${blueprint.appName}'` : "";
72959
- const primaryAction = `Customize the Wix CLI dashboard page scaffolding for the app ${appName}`;
72960
- const userMessage = (0, userPrompt_1.buildUserPromptForCodeGenerationAgent)(params, primaryAction);
72961
- const result = await codeGenerationService_12.codegenAIProxyService.generateCodegenObject({
72962
- userMessage,
72963
- systemPrompt,
72964
- provider: constants_1.LLM_PROVIDERS.ANTHROPIC,
72965
- model: constants_1.LLM_MODELS.CLAUDE_SONNET_4_5_20250929,
72966
- schema: file_operations_1.FilesSchema,
72967
- agentName: this.name
72968
- });
72969
- return result.object.files;
73038
+ }
73039
+ getPrimaryAction(params) {
73040
+ const appName = params.blueprint?.appName ? `'${params.blueprint.appName}'` : "";
73041
+ return `Customize the Wix CLI dashboard page scaffolding for the app ${appName}`;
72970
73042
  }
72971
73043
  };
72972
73044
  exports2.DashboardPageAgent = DashboardPageAgent;
@@ -73043,19 +73115,18 @@ var require_SiteComponentAgent2 = __commonJS({
73043
73115
  var api_1 = require_api2();
73044
73116
  var site_component_prompt_1 = require_site_component_prompt();
73045
73117
  var codegen_common_logic_1 = require_dist9();
73046
- var userPrompt_1 = require_userPrompt();
73047
- var file_operations_1 = require_file_operations();
73048
- var constants_1 = require_constants();
73049
- var codeGenerationService_12 = require_codeGenerationService();
73050
- var SiteComponentAgent = class {
73051
- constructor(useIteration = false) {
73052
- this.useIteration = useIteration;
73118
+ var BaseCodeGenerationAgent_1 = require_BaseCodeGenerationAgent();
73119
+ var SiteComponentAgent = class extends BaseCodeGenerationAgent_1.BaseCodeGenerationAgent {
73120
+ constructor() {
73121
+ super(...arguments);
73053
73122
  this.name = "SiteComponentAgent";
73054
73123
  }
73055
73124
  getAgentDocumentation() {
73056
73125
  return (0, codegen_common_logic_1.getSiteComponentAgentDocumentation)();
73057
73126
  }
73058
- buildSystemPrompt({ apiNames, apiDocumentation, useData }) {
73127
+ buildSystemPrompt(params) {
73128
+ const { apiDocumentation, apiNames } = (0, api_1.extractApiDocumentation)(params.extension);
73129
+ const useData = Boolean(params.plan?.collections?.length);
73059
73130
  return (0, site_component_prompt_1.siteComponentPrompt)({
73060
73131
  apiNames,
73061
73132
  useData,
@@ -73063,27 +73134,9 @@ var require_SiteComponentAgent2 = __commonJS({
73063
73134
  apiDocumentation
73064
73135
  });
73065
73136
  }
73066
- async generate(params) {
73067
- const { blueprint, plan } = params;
73068
- const { apiDocumentation, apiNames } = (0, api_1.extractApiDocumentation)(params.extension);
73069
- const useData = Boolean(plan?.collections?.length);
73070
- const systemPrompt = this.buildSystemPrompt({
73071
- apiNames,
73072
- apiDocumentation,
73073
- useData
73074
- });
73075
- const appName = blueprint?.appName ? `'${blueprint.appName}'` : "";
73076
- const primaryAction = `Customize the Wix CLI site component scaffolding for the app ${appName}`;
73077
- const userMessage = (0, userPrompt_1.buildUserPromptForCodeGenerationAgent)(params, primaryAction);
73078
- const result = await codeGenerationService_12.codegenAIProxyService.generateCodegenObject({
73079
- userMessage,
73080
- systemPrompt,
73081
- provider: constants_1.LLM_PROVIDERS.ANTHROPIC,
73082
- model: constants_1.LLM_MODELS.CLAUDE_SONNET_4_5_20250929,
73083
- schema: file_operations_1.FilesSchema,
73084
- agentName: this.name
73085
- });
73086
- return result.object.files;
73137
+ getPrimaryAction(params) {
73138
+ const appName = params.blueprint?.appName ? `'${params.blueprint.appName}'` : "";
73139
+ return `Customize the Wix CLI site component scaffolding for the app ${appName}`;
73087
73140
  }
73088
73141
  };
73089
73142
  exports2.SiteComponentAgent = SiteComponentAgent;
@@ -73206,19 +73259,18 @@ var require_CustomElementAgent2 = __commonJS({
73206
73259
  var api_1 = require_api2();
73207
73260
  var custom_element_prompt_1 = require_custom_element_prompt();
73208
73261
  var codegen_common_logic_1 = require_dist9();
73209
- var userPrompt_1 = require_userPrompt();
73210
- var codeGenerationService_12 = require_codeGenerationService();
73211
- var file_operations_1 = require_file_operations();
73212
- var constants_1 = require_constants();
73213
- var CustomElementAgent = class {
73214
- constructor(useIteration = false) {
73215
- this.useIteration = useIteration;
73262
+ var BaseCodeGenerationAgent_1 = require_BaseCodeGenerationAgent();
73263
+ var CustomElementAgent = class extends BaseCodeGenerationAgent_1.BaseCodeGenerationAgent {
73264
+ constructor() {
73265
+ super(...arguments);
73216
73266
  this.name = "CustomElementAgent";
73217
73267
  }
73218
73268
  getAgentDocumentation() {
73219
73269
  return (0, codegen_common_logic_1.getCustomElementAgentDocumentation)();
73220
73270
  }
73221
- buildSystemPrompt({ apiNames, apiDocumentation, useData }) {
73271
+ buildSystemPrompt(params) {
73272
+ const { apiDocumentation, apiNames } = (0, api_1.extractApiDocumentation)(params.extension);
73273
+ const useData = Boolean(params.plan?.collections?.length);
73222
73274
  return (0, custom_element_prompt_1.customElementPrompt)({
73223
73275
  apiNames,
73224
73276
  useData,
@@ -73226,27 +73278,9 @@ var require_CustomElementAgent2 = __commonJS({
73226
73278
  apiDocumentation
73227
73279
  });
73228
73280
  }
73229
- async generate(params) {
73230
- const { blueprint, plan } = params;
73231
- const { apiDocumentation, apiNames } = (0, api_1.extractApiDocumentation)(params.extension);
73232
- const useData = Boolean(plan?.collections?.length);
73233
- const systemPrompt = this.buildSystemPrompt({
73234
- apiNames,
73235
- apiDocumentation,
73236
- useData
73237
- });
73238
- const appName = blueprint?.appName ? `'${blueprint.appName}'` : "";
73239
- const primaryAction = `Customize the Wix CLI custom element / site widget scaffolding for the app ${appName}`;
73240
- const userMessage = (0, userPrompt_1.buildUserPromptForCodeGenerationAgent)(params, primaryAction);
73241
- const result = await codeGenerationService_12.codegenAIProxyService.generateCodegenObject({
73242
- userMessage,
73243
- systemPrompt,
73244
- provider: constants_1.LLM_PROVIDERS.ANTHROPIC,
73245
- model: constants_1.LLM_MODELS.CLAUDE_SONNET_4_5_20250929,
73246
- schema: file_operations_1.FilesSchema,
73247
- agentName: this.name
73248
- });
73249
- return result?.object.files;
73281
+ getPrimaryAction(params) {
73282
+ const appName = params.blueprint?.appName ? `'${params.blueprint.appName}'` : "";
73283
+ return `Customize the Wix CLI custom element / site widget scaffolding for the app ${appName}`;
73250
73284
  }
73251
73285
  };
73252
73286
  exports2.CustomElementAgent = CustomElementAgent;
@@ -73450,51 +73484,31 @@ var require_SPIAgent2 = __commonJS({
73450
73484
  var api_1 = require_api2();
73451
73485
  var prompt_selectors_1 = require_prompt_selectors();
73452
73486
  var codegen_common_logic_1 = require_dist9();
73453
- var userPrompt_1 = require_userPrompt();
73454
- var file_operations_1 = require_file_operations();
73455
- var constants_1 = require_constants();
73456
- var codeGenerationService_12 = require_codeGenerationService();
73457
- var SPIAgent = class {
73458
- constructor(useIteration = false) {
73459
- this.useIteration = useIteration;
73487
+ var BaseCodeGenerationAgent_1 = require_BaseCodeGenerationAgent();
73488
+ var SPIAgent = class extends BaseCodeGenerationAgent_1.BaseCodeGenerationAgent {
73489
+ constructor() {
73490
+ super(...arguments);
73460
73491
  this.name = "SPIAgent";
73461
73492
  }
73462
73493
  getAgentDocumentation() {
73463
73494
  return (0, codegen_common_logic_1.getSPIAgentDocumentation)();
73464
73495
  }
73465
- buildSystemPrompt({ apiNames, apiDocumentation, useData, spiNames }) {
73466
- const systemPrompt = (0, service_plugin_prompt_1.servicePluginPrompt)({
73496
+ buildSystemPrompt(params) {
73497
+ const { extension } = params;
73498
+ const spiNames = extension.relatedSpis?.map((spi) => spi.name).filter((name) => !!name) || [];
73499
+ const { apiDocumentation, apiNames } = (0, api_1.extractApiDocumentation)(params.extension);
73500
+ const useData = (0, prompt_selectors_1.shouldUseDataPrompt)(params);
73501
+ return (0, service_plugin_prompt_1.servicePluginPrompt)({
73467
73502
  apiNames,
73468
73503
  apiDocumentation,
73469
73504
  useData,
73470
73505
  useIteration: this.useIteration,
73471
73506
  spiNames
73472
73507
  });
73473
- return systemPrompt;
73474
73508
  }
73475
- async generate(params) {
73476
- const { extension, blueprint } = params;
73477
- const allSpiNames = extension.relatedSpis?.map((spi) => spi.name).filter((name) => !!name) || [];
73478
- const { apiDocumentation, apiNames } = (0, api_1.extractApiDocumentation)(params.extension);
73479
- const useData = (0, prompt_selectors_1.shouldUseDataPrompt)(params);
73480
- const systemPrompt = this.buildSystemPrompt({
73481
- apiNames,
73482
- apiDocumentation,
73483
- useData,
73484
- spiNames: allSpiNames
73485
- });
73486
- const appName = blueprint?.appName ? `'${blueprint.appName}'` : "";
73487
- const primaryAction = `Customize the Wix CLI service plugin scaffolding for the app ${appName}`;
73488
- const userMessage = (0, userPrompt_1.buildUserPromptForCodeGenerationAgent)(params, primaryAction);
73489
- const result = await codeGenerationService_12.codegenAIProxyService.generateCodegenObject({
73490
- userMessage,
73491
- systemPrompt,
73492
- provider: constants_1.LLM_PROVIDERS.ANTHROPIC,
73493
- model: constants_1.LLM_MODELS.CLAUDE_SONNET_4_5_20250929,
73494
- schema: file_operations_1.FilesSchema,
73495
- agentName: this.name
73496
- });
73497
- return result.object.files;
73509
+ getPrimaryAction(params) {
73510
+ const appName = params.blueprint?.appName ? `'${params.blueprint.appName}'` : "";
73511
+ return `Customize the Wix CLI service plugin scaffolding for the app ${appName}`;
73498
73512
  }
73499
73513
  };
73500
73514
  exports2.SPIAgent = SPIAgent;
@@ -73573,19 +73587,18 @@ var require_BackendEventAgent2 = __commonJS({
73573
73587
  var api_1 = require_api2();
73574
73588
  var backend_event_prompt_1 = require_backend_event_prompt();
73575
73589
  var codegen_common_logic_1 = require_dist9();
73576
- var userPrompt_1 = require_userPrompt();
73577
- var file_operations_1 = require_file_operations();
73578
- var constants_1 = require_constants();
73579
- var codeGenerationService_12 = require_codeGenerationService();
73580
- var BackendEventAgent = class {
73581
- constructor(useIteration = false) {
73582
- this.useIteration = useIteration;
73590
+ var BaseCodeGenerationAgent_1 = require_BaseCodeGenerationAgent();
73591
+ var BackendEventAgent = class extends BaseCodeGenerationAgent_1.BaseCodeGenerationAgent {
73592
+ constructor() {
73593
+ super(...arguments);
73583
73594
  this.name = "BackendEventAgent";
73584
73595
  }
73585
73596
  getAgentDocumentation() {
73586
73597
  return (0, codegen_common_logic_1.getBackendEventAgentDocumentation)();
73587
73598
  }
73588
- buildSystemPrompt({ apiNames, apiDocumentation, useData }) {
73599
+ buildSystemPrompt(params) {
73600
+ const { apiDocumentation, apiNames } = (0, api_1.extractApiDocumentation)(params.extension);
73601
+ const useData = (0, prompt_selectors_1.shouldUseDataPrompt)(params);
73589
73602
  return (0, backend_event_prompt_1.backendEventPrompt)({
73590
73603
  apiNames,
73591
73604
  useData,
@@ -73593,27 +73606,9 @@ var require_BackendEventAgent2 = __commonJS({
73593
73606
  apiDocumentation
73594
73607
  });
73595
73608
  }
73596
- async generate(params) {
73597
- const { blueprint } = params;
73598
- const { apiDocumentation, apiNames } = (0, api_1.extractApiDocumentation)(params.extension);
73599
- const useData = (0, prompt_selectors_1.shouldUseDataPrompt)(params);
73600
- const systemPrompt = this.buildSystemPrompt({
73601
- apiNames,
73602
- apiDocumentation,
73603
- useData
73604
- });
73605
- const appName = blueprint?.appName ? `'${blueprint.appName}'` : "";
73606
- const primaryAction = `Customize backend event scaffolding for the app ${appName}`;
73607
- const userMessage = (0, userPrompt_1.buildUserPromptForCodeGenerationAgent)(params, primaryAction);
73608
- const result = await codeGenerationService_12.codegenAIProxyService.generateCodegenObject({
73609
- userMessage,
73610
- systemPrompt,
73611
- provider: constants_1.LLM_PROVIDERS.ANTHROPIC,
73612
- model: constants_1.LLM_MODELS.CLAUDE_SONNET_4_5_20250929,
73613
- schema: file_operations_1.FilesSchema,
73614
- agentName: this.name
73615
- });
73616
- return result.object.files;
73609
+ getPrimaryAction(params) {
73610
+ const appName = params.blueprint?.appName ? `'${params.blueprint.appName}'` : "";
73611
+ return `Customize backend event scaffolding for the app ${appName}`;
73617
73612
  }
73618
73613
  };
73619
73614
  exports2.BackendEventAgent = BackendEventAgent;
@@ -73637,7 +73632,8 @@ Focus on creating maintainable, secure, and efficient API routes that integrate
73637
73632
  </astro_server_endpoints_overview>
73638
73633
  <file_structure_and_naming>
73639
73634
  - API routes are created in \`src/pages/api/\` directory
73640
- - File names become the endpoint path (e.g., \`users.ts\` \u2192 \`/api/users\`)
73635
+ - File names become the endpoint path (e.g., \`/api/users.ts\` \u2192 \`/api/users\`)
73636
+ - The file name should be the same as the endpoint path (e.g., \`/api/users.ts\` \u2192 \`/api/users\`)
73641
73637
  - For dynamic routes with parameters, use square brackets in the filename (e.g., \`/api/users/[id]\`)
73642
73638
  - Dynamic parameters can be extracted at runtime using the \`params\` parameter in the function
73643
73639
 
@@ -73737,21 +73733,20 @@ var require_BackendApiAgent2 = __commonJS({
73737
73733
  exports2.BackendApiAgent = void 0;
73738
73734
  var backend_api_prompt_1 = require_backend_api_prompt();
73739
73735
  var codegen_common_logic_1 = require_dist9();
73740
- var userPrompt_1 = require_userPrompt();
73741
- var file_operations_1 = require_file_operations();
73742
- var constants_1 = require_constants();
73743
73736
  var api_1 = require_api2();
73744
73737
  var prompt_selectors_1 = require_prompt_selectors();
73745
- var codeGenerationService_12 = require_codeGenerationService();
73746
- var BackendApiAgent = class {
73747
- constructor(useIteration = false) {
73748
- this.useIteration = useIteration;
73738
+ var BaseCodeGenerationAgent_1 = require_BaseCodeGenerationAgent();
73739
+ var BackendApiAgent = class extends BaseCodeGenerationAgent_1.BaseCodeGenerationAgent {
73740
+ constructor() {
73741
+ super(...arguments);
73749
73742
  this.name = "BackendApiAgent";
73750
73743
  }
73751
73744
  getAgentDocumentation() {
73752
73745
  return (0, codegen_common_logic_1.getBackendApiAgentDocumentation)();
73753
73746
  }
73754
- buildSystemPrompt({ apiNames, apiDocumentation, useData }) {
73747
+ buildSystemPrompt(params) {
73748
+ const { apiDocumentation, apiNames } = (0, api_1.extractApiDocumentation)(params.extension);
73749
+ const useData = (0, prompt_selectors_1.shouldUseDataPrompt)(params);
73755
73750
  return (0, backend_api_prompt_1.backendApiPrompt)({
73756
73751
  apiNames,
73757
73752
  useData,
@@ -73759,26 +73754,8 @@ var require_BackendApiAgent2 = __commonJS({
73759
73754
  apiDocumentation
73760
73755
  });
73761
73756
  }
73762
- async generate(params) {
73763
- const { blueprint } = params;
73764
- const { apiDocumentation, apiNames } = (0, api_1.extractApiDocumentation)(params.extension);
73765
- const useData = (0, prompt_selectors_1.shouldUseDataPrompt)(params);
73766
- const systemPrompt = this.buildSystemPrompt({
73767
- apiNames,
73768
- apiDocumentation,
73769
- useData
73770
- });
73771
- const primaryAction = `Create Astro Server Endpoints for the app ${blueprint?.appName}`;
73772
- const userMessage = (0, userPrompt_1.buildUserPromptForCodeGenerationAgent)(params, primaryAction);
73773
- const result = await codeGenerationService_12.codegenAIProxyService.generateCodegenObject({
73774
- userMessage,
73775
- systemPrompt,
73776
- provider: constants_1.LLM_PROVIDERS.ANTHROPIC,
73777
- model: constants_1.LLM_MODELS.CLAUDE_SONNET_4_5_20250929,
73778
- schema: file_operations_1.FilesSchema,
73779
- agentName: this.name
73780
- });
73781
- return result.object.files;
73757
+ getPrimaryAction(params) {
73758
+ return `Create Astro Server Endpoints for the app ${params.blueprint?.appName}`;
73782
73759
  }
73783
73760
  };
73784
73761
  exports2.BackendApiAgent = BackendApiAgent;
@@ -74027,10 +74004,8 @@ var require_EmbeddedScriptAgent2 = __commonJS({
74027
74004
  var zod_1 = __importDefault2(require_zod());
74028
74005
  var embedded_script_prompt_1 = require_embedded_script_prompt();
74029
74006
  var codegen_common_logic_1 = require_dist9();
74030
- var userPrompt_1 = require_userPrompt();
74031
74007
  var file_operations_1 = require_file_operations();
74032
- var constants_1 = require_constants();
74033
- var codeGenerationService_12 = require_codeGenerationService();
74008
+ var BaseCodeGenerationAgent_1 = require_BaseCodeGenerationAgent();
74034
74009
  var EmbeddedScriptPlacement;
74035
74010
  (function(EmbeddedScriptPlacement2) {
74036
74011
  EmbeddedScriptPlacement2["HEAD"] = "HEAD";
@@ -74049,15 +74024,18 @@ var require_EmbeddedScriptAgent2 = __commonJS({
74049
74024
  scriptType: zod_1.default.enum(Object.values(EmbeddedScriptType)),
74050
74025
  placement: zod_1.default.enum(Object.values(EmbeddedScriptPlacement))
74051
74026
  });
74052
- var EmbeddedScriptAgent = class {
74053
- constructor(useIteration = false) {
74054
- this.useIteration = useIteration;
74027
+ var EmbeddedScriptAgent = class extends BaseCodeGenerationAgent_1.BaseCodeGenerationAgent {
74028
+ constructor() {
74029
+ super(...arguments);
74055
74030
  this.name = "EmbeddedScriptAgent";
74056
74031
  }
74057
74032
  getAgentDocumentation() {
74058
74033
  return (0, codegen_common_logic_1.getEmbeddedScriptAgentDocumentation)();
74059
74034
  }
74060
- buildSystemPrompt({ hasDynamicParameters, apiNames, apiDocumentation, useData }) {
74035
+ buildSystemPrompt(params) {
74036
+ const hasDynamicParameters = (0, prompt_selectors_1.shouldUseDynamicParametersPrompt)(params);
74037
+ const { apiDocumentation, apiNames } = (0, api_1.extractApiDocumentation)(params.extension);
74038
+ const useData = (0, prompt_selectors_1.shouldUseDataPrompt)(params);
74061
74039
  return (0, embedded_script_prompt_1.embeddedScriptPrompt)({
74062
74040
  hasDynamicParameters,
74063
74041
  apiNames,
@@ -74066,32 +74044,21 @@ var require_EmbeddedScriptAgent2 = __commonJS({
74066
74044
  apiDocumentation
74067
74045
  });
74068
74046
  }
74069
- async generate(params) {
74070
- const { blueprint } = params;
74071
- const hasDynamicParameters = (0, prompt_selectors_1.shouldUseDynamicParametersPrompt)(params);
74072
- const { apiDocumentation, apiNames } = (0, api_1.extractApiDocumentation)(params.extension);
74073
- const useData = (0, prompt_selectors_1.shouldUseDataPrompt)(params);
74074
- const systemPrompt = this.buildSystemPrompt({
74075
- hasDynamicParameters,
74076
- apiNames,
74077
- apiDocumentation,
74078
- useData
74079
- });
74080
- const appName = blueprint?.appName ? `'${blueprint.appName}'` : "";
74081
- const primaryAction = `Customize the Wix CLI embedded script scaffolding for the app ${appName}`;
74082
- const userMessage = (0, userPrompt_1.buildUserPromptForCodeGenerationAgent)(params, primaryAction);
74083
- const result = await codeGenerationService_12.codegenAIProxyService.generateCodegenObject({
74084
- userMessage,
74085
- systemPrompt,
74086
- provider: constants_1.LLM_PROVIDERS.ANTHROPIC,
74087
- model: constants_1.LLM_MODELS.CLAUDE_SONNET_4_5_20250929,
74088
- schema: EmbeddedScriptSchema,
74089
- agentName: this.name
74090
- });
74047
+ getPrimaryAction(params) {
74048
+ const appName = params.blueprint?.appName ? `'${params.blueprint.appName}'` : "";
74049
+ return `Customize the Wix CLI embedded script scaffolding for the app ${appName}`;
74050
+ }
74051
+ getGenerateOptions() {
74091
74052
  return {
74092
- files: result.object.files,
74093
- scriptType: result.object.scriptType,
74094
- placement: result.object.placement
74053
+ schema: EmbeddedScriptSchema,
74054
+ extractResult: (obj) => {
74055
+ const result = obj;
74056
+ return {
74057
+ files: result.files,
74058
+ scriptType: result.scriptType,
74059
+ placement: result.placement
74060
+ };
74061
+ }
74095
74062
  };
74096
74063
  }
74097
74064
  };
@@ -82207,9 +82174,9 @@ var require_IterationAgent = __commonJS({
82207
82174
  "use strict";
82208
82175
  Object.defineProperty(exports2, "__esModule", { value: true });
82209
82176
  exports2.IterationAgent = void 0;
82210
- var ai_1 = require_dist8();
82211
82177
  var iteration_agent_prompt_1 = require_iteration_agent_prompt();
82212
82178
  var AgentsRegistry_1 = require_AgentsRegistry();
82179
+ var codegen_common_logic_1 = require_dist9();
82213
82180
  var ditto_codegen_types_12 = require_dist();
82214
82181
  var constants_1 = require_constants();
82215
82182
  var contextBuilders_1 = require_contextBuilders();
@@ -82223,13 +82190,6 @@ var require_IterationAgent = __commonJS({
82223
82190
  buildSystemPrompt() {
82224
82191
  return (0, iteration_agent_prompt_1.iterationAgentPrompt)();
82225
82192
  }
82226
- extractPlanResult(toolCalls) {
82227
- const submitCall = toolCalls.find((call) => call.toolName === SUBMIT_PLAN_TOOL_NAME);
82228
- if (!submitCall) {
82229
- throw new Error("Failed to generate iteration plan");
82230
- }
82231
- return submitCall.input;
82232
- }
82233
82193
  mapExtensionType(extensionType) {
82234
82194
  const supportedExtensionTypes = (0, AgentsRegistry_1.getSupportedExtensionTypes)();
82235
82195
  if (supportedExtensionTypes.includes(extensionType)) {
@@ -82267,7 +82227,8 @@ var require_IterationAgent = __commonJS({
82267
82227
  const model = (0, customAnthropicProvider_1.createCustomTextModel)()(constants_1.LLM_MODELS.CLAUDE_SONNET_4_5_20250929, {
82268
82228
  agentName: this.name
82269
82229
  });
82270
- const result = await (0, ai_1.generateText)({
82230
+ const result = await (0, codegen_common_logic_1.generateAgentText)({
82231
+ agentName: this.name,
82271
82232
  model,
82272
82233
  tools: {
82273
82234
  [tools_1.TOOL_NAMES.READ_FILE]: (0, tools_1.createReadFileTool)(outputPath),
@@ -82275,23 +82236,14 @@ var require_IterationAgent = __commonJS({
82275
82236
  [tools_1.TOOL_NAMES.GLOB]: (0, tools_1.createGlobTool)(outputPath),
82276
82237
  [SUBMIT_PLAN_TOOL_NAME]: (0, tools_1.createSubmitPlanTool)()
82277
82238
  },
82278
- stopWhen: ({ steps }) => {
82279
- const lastStep = steps[steps.length - 1];
82280
- return lastStep?.toolCalls.some((toolCall) => toolCall.toolName === SUBMIT_PLAN_TOOL_NAME && !("invalid" in toolCall) && !("error" in toolCall)) ?? false;
82281
- },
82282
- messages: [
82283
- {
82284
- role: "system",
82285
- content: this.buildSystemPrompt(),
82286
- providerOptions: (0, ditto_codegen_types_12.withCaching)("1h")
82287
- },
82288
- { role: "user", content: userMessage }
82289
- ],
82290
- maxRetries: 3,
82291
- temperature: 0,
82292
- experimental_telemetry: { isEnabled: true, functionId: this.name }
82239
+ systemPrompt: this.buildSystemPrompt(),
82240
+ userMessage,
82241
+ stopWhen: (0, codegen_common_logic_1.stopOnToolCall)(SUBMIT_PLAN_TOOL_NAME)
82293
82242
  });
82294
- const planResult = this.extractPlanResult(result.toolCalls);
82243
+ const planResult = (0, codegen_common_logic_1.extractToolResult)(result.toolCalls, SUBMIT_PLAN_TOOL_NAME);
82244
+ if (!planResult) {
82245
+ throw new Error("Failed to generate iteration plan");
82246
+ }
82295
82247
  console.log("IterationAgent planResult:", JSON.stringify(planResult, null, 2));
82296
82248
  const resultObject = {
82297
82249
  currentExtensions: planResult.currentExtensions.map((ext) => ({
@@ -82525,8 +82477,6 @@ var require_scaffolding = __commonJS({
82525
82477
  return copyCustomElementScaffolding(extension, outputPath);
82526
82478
  case types_1.ExtensionType.EMBEDDED_SCRIPT:
82527
82479
  return copyEmbeddedScriptScaffolding(extension, outputPath);
82528
- case types_1.ExtensionType.BACKEND_API:
82529
- return copyBackendApiScaffolding(extension, outputPath);
82530
82480
  case types_1.ExtensionType.BACKEND_EVENT:
82531
82481
  return copyBackendEventScaffolding(extension, outputPath);
82532
82482
  case types_1.ExtensionType.SITE_COMPONENT:
@@ -82591,14 +82541,6 @@ var require_scaffolding = __commonJS({
82591
82541
  console.log(` \u{1F4DC} Copying embedded script scaffolding from: ${scaffoldingSubPath} to ${outputFolder}`);
82592
82542
  return (0, tools_1.copyScaffolding)(scaffoldingSubPath, outputPath, outputFolder);
82593
82543
  }
82594
- async function copyBackendApiScaffolding(extension, outputPath) {
82595
- const uniqueFolderName = toKebabCase(extension.name || "my-api");
82596
- const apiScaffoldingFile = "src/pages/api/my-api.ts";
82597
- const apiOutputFile = `src/pages/api/${uniqueFolderName}.ts`;
82598
- console.log(` \u{1F50C} Copying backend API scaffolding from: ${apiScaffoldingFile} to ${apiOutputFile}`);
82599
- const apiFiles = (0, tools_1.copyScaffolding)(apiScaffoldingFile, outputPath, apiOutputFile);
82600
- return apiFiles;
82601
- }
82602
82544
  async function copyBackendEventScaffolding(extension, outputPath) {
82603
82545
  const scaffoldingSubPath = "src/backend/events/my-event";
82604
82546
  const uniqueFolderName = toKebabCase(extension.name || "my-event");
@@ -97706,7 +97648,7 @@ var require_SDKPickerAgent = __commonJS({
97706
97648
  Object.defineProperty(exports2, "__esModule", { value: true });
97707
97649
  exports2.SDKPickerAgent = void 0;
97708
97650
  var ditto_codegen_types_12 = require_dist();
97709
- var ai_1 = require_dist8();
97651
+ var codegen_common_logic_1 = require_dist9();
97710
97652
  var WixMCPClient_1 = require_WixMCPClient();
97711
97653
  var tools_1 = require_tools3();
97712
97654
  var sdkEnricher_1 = require_sdkEnricher();
@@ -97717,21 +97659,6 @@ var require_SDKPickerAgent = __commonJS({
97717
97659
  this.mcpClient = new WixMCPClient_1.WixMCPClient();
97718
97660
  this.model = model;
97719
97661
  }
97720
- createStopCondition() {
97721
- return ({ steps }) => {
97722
- const lastStep = steps[steps.length - 1];
97723
- const hasSuccessfulSubmit = lastStep?.toolCalls.some((toolCall) => toolCall.toolName === tools_1.SDK_PICKER_TOOL_NAMES.SUBMIT_PLAN && !("invalid" in toolCall) && !("error" in toolCall)) ?? false;
97724
- return hasSuccessfulSubmit;
97725
- };
97726
- }
97727
- extractSDKPickerResult({ toolCalls }) {
97728
- const submitCall = toolCalls.find((call) => call.toolName === tools_1.SDK_PICKER_TOOL_NAMES.SUBMIT_PLAN);
97729
- if (!submitCall) {
97730
- console.error("No submit_plan tool call found");
97731
- return null;
97732
- }
97733
- return submitCall.input;
97734
- }
97735
97662
  async generate({ validIds, extensionDocumentation, userPrompt }) {
97736
97663
  if (validIds.length === 0) {
97737
97664
  return { extensions: [] };
@@ -97742,26 +97669,15 @@ var require_SDKPickerAgent = __commonJS({
97742
97669
  mcpClient: this.mcpClient,
97743
97670
  validIds
97744
97671
  });
97745
- const systemPrompt = (0, sdk_picker_agent_prompt_1.sdkPickerAgentPrompt)(extensionDocumentation);
97746
- const result = await (0, ai_1.generateText)({
97672
+ const result = await (0, codegen_common_logic_1.generateAgentText)({
97673
+ agentName: this.name,
97747
97674
  model: this.model,
97748
97675
  tools,
97749
- stopWhen: this.createStopCondition(),
97750
- messages: [
97751
- {
97752
- role: "system",
97753
- content: systemPrompt,
97754
- providerOptions: (0, ditto_codegen_types_12.withCaching)("1h")
97755
- },
97756
- { role: "user", content: userPrompt }
97757
- ],
97758
- maxRetries: 3,
97759
- temperature: 0,
97760
- experimental_telemetry: { isEnabled: true, functionId: this.name }
97761
- });
97762
- const apiResult = this.extractSDKPickerResult({
97763
- toolCalls: result.toolCalls
97676
+ systemPrompt: (0, sdk_picker_agent_prompt_1.sdkPickerAgentPrompt)(extensionDocumentation),
97677
+ userMessage: userPrompt,
97678
+ stopWhen: (0, codegen_common_logic_1.stopOnToolCall)(tools_1.SDK_PICKER_TOOL_NAMES.SUBMIT_PLAN)
97764
97679
  });
97680
+ const apiResult = (0, codegen_common_logic_1.extractToolResult)(result.toolCalls, tools_1.SDK_PICKER_TOOL_NAMES.SUBMIT_PLAN);
97765
97681
  if (!apiResult) {
97766
97682
  throw new Error("Failed to extract SDK picker result from tool calls");
97767
97683
  }
@@ -98142,8 +98058,8 @@ var require_ExtensionIndexerAgent = __commonJS({
98142
98058
  };
98143
98059
  Object.defineProperty(exports2, "__esModule", { value: true });
98144
98060
  exports2.ExtensionIndexerAgent = void 0;
98145
- var ai_1 = require_dist8();
98146
98061
  var ditto_codegen_types_12 = require_dist();
98062
+ var codegen_common_logic_1 = require_dist9();
98147
98063
  var constants_1 = require_constants();
98148
98064
  var customAnthropicProvider_1 = require_customAnthropicProvider();
98149
98065
  var tools_1 = require_tools();
@@ -98184,7 +98100,8 @@ ${srcFolderStructure}
98184
98100
  const model = (0, customAnthropicProvider_1.createCustomTextModel)()(constants_1.LLM_MODELS.CLAUDE_HAIKU_4_5, {
98185
98101
  agentName: this.name
98186
98102
  });
98187
- await (0, ai_1.generateText)({
98103
+ await (0, codegen_common_logic_1.generateAgentText)({
98104
+ agentName: this.name,
98188
98105
  model,
98189
98106
  tools: {
98190
98107
  [tools_1.TOOL_NAMES.READ_FILE]: (0, tools_1.createReadFileTool)(outputPath),
@@ -98193,24 +98110,9 @@ ${srcFolderStructure}
98193
98110
  [tools_1.TOOL_NAMES.GREP]: (0, tools_1.createGrepTool)(outputPath),
98194
98111
  [tools_1.TOOL_NAMES.GLOB]: (0, tools_1.createGlobTool)(outputPath)
98195
98112
  },
98196
- stopWhen: ({ steps }) => {
98197
- if (steps.length >= MAX_STEPS) {
98198
- return true;
98199
- }
98200
- const lastStep = steps[steps.length - 1];
98201
- return lastStep?.toolCalls.length === 0;
98202
- },
98203
- messages: [
98204
- {
98205
- role: "system",
98206
- content: systemPrompt,
98207
- providerOptions: (0, ditto_codegen_types_12.withCaching)("1h")
98208
- },
98209
- { role: "user", content: userMessage }
98210
- ],
98211
- maxRetries: 3,
98212
- temperature: 0,
98213
- experimental_telemetry: { isEnabled: true, functionId: this.name }
98113
+ systemPrompt,
98114
+ userMessage,
98115
+ stopWhen: (0, codegen_common_logic_1.stopOnNoToolCalls)(MAX_STEPS)
98214
98116
  });
98215
98117
  } catch (error) {
98216
98118
  throw (0, ditto_codegen_types_12.toCodegenError)(error);
@@ -101756,7 +101658,7 @@ var require_extensionProcessors = __commonJS({
101756
101658
  agentName: agent.name,
101757
101659
  agentFiles: files,
101758
101660
  scaffolds,
101759
- scaffoldPath: scaffolds[0].path,
101661
+ scaffoldPath: scaffolds[0]?.path || "",
101760
101662
  outputPath
101761
101663
  }, eventEmitter);
101762
101664
  }
@@ -102003,6 +101905,40 @@ var require_embeddedScript = __commonJS({
102003
101905
  }
102004
101906
  });
102005
101907
 
101908
+ // dist/extensions/backendApi.js
101909
+ var require_backendApi = __commonJS({
101910
+ "dist/extensions/backendApi.js"(exports2) {
101911
+ "use strict";
101912
+ Object.defineProperty(exports2, "__esModule", { value: true });
101913
+ exports2.processBackendApiExtension = processBackendApiExtension;
101914
+ var finalize_extension_generation_1 = require_finalize_extension_generation();
101915
+ async function processBackendApiExtension(params) {
101916
+ const { extension, outputPath, plan, agentsFactory, eventEmitter, blueprint, userRequestSummary, previousResources } = params;
101917
+ const backendApiAgent = agentsFactory.getAgent(extension);
101918
+ eventEmitter.emitEvent("agent:start", {
101919
+ extension,
101920
+ name: backendApiAgent.name
101921
+ });
101922
+ const files = await backendApiAgent.generate({
101923
+ extension,
101924
+ basePath: outputPath,
101925
+ plan,
101926
+ ...blueprint && { blueprint },
101927
+ ...userRequestSummary && { userRequestSummary },
101928
+ ...previousResources && { previousResources }
101929
+ });
101930
+ (0, finalize_extension_generation_1.finalizeExtensionGeneration)({
101931
+ extension,
101932
+ agentName: backendApiAgent.name,
101933
+ agentFiles: files,
101934
+ scaffolds: [],
101935
+ scaffoldPath: "",
101936
+ outputPath
101937
+ }, eventEmitter);
101938
+ }
101939
+ }
101940
+ });
101941
+
102006
101942
  // dist/cms/index.js
102007
101943
  var require_cms = __commonJS({
102008
101944
  "dist/cms/index.js"(exports2) {
@@ -102142,6 +102078,7 @@ var require_orchestrator = __commonJS({
102142
102078
  var dashboardPage_1 = require_dashboardPage();
102143
102079
  var servicePlugin_1 = require_servicePlugin();
102144
102080
  var embeddedScript_1 = require_embeddedScript();
102081
+ var backendApi_1 = require_backendApi();
102145
102082
  var cms_1 = require_cms();
102146
102083
  var write_file_1 = require_write_file();
102147
102084
  var DittoOrchestrator = class extends DittoEventEmitter_1.DittoEventEmitter {
@@ -102189,6 +102126,15 @@ var require_orchestrator = __commonJS({
102189
102126
  eventEmitter: this,
102190
102127
  blueprint
102191
102128
  });
102129
+ case types_1.ExtensionType.BACKEND_API:
102130
+ return (0, backendApi_1.processBackendApiExtension)({
102131
+ extension,
102132
+ outputPath,
102133
+ plan,
102134
+ agentsFactory: this.agentsFactory,
102135
+ eventEmitter: this,
102136
+ blueprint
102137
+ });
102192
102138
  default:
102193
102139
  return (0, extensionProcessors_1.processStandardExtension)({
102194
102140
  extension,
@@ -322270,6 +322216,7 @@ var require_IterationOrchestrator = __commonJS({
322270
322216
  var embeddedScript_1 = require_embeddedScript();
322271
322217
  var servicePlugin_1 = require_servicePlugin();
322272
322218
  var dashboardPage_1 = require_dashboardPage();
322219
+ var backendApi_1 = require_backendApi();
322273
322220
  var cms_1 = require_cms();
322274
322221
  var write_file_1 = require_write_file();
322275
322222
  var projectContext_1 = require_projectContext();
@@ -322469,6 +322416,15 @@ var require_IterationOrchestrator = __commonJS({
322469
322416
  previousResources
322470
322417
  });
322471
322418
  case types_1.ExtensionType.BACKEND_API:
322419
+ return (0, backendApi_1.processBackendApiExtension)({
322420
+ extension,
322421
+ outputPath,
322422
+ plan,
322423
+ agentsFactory: this.agentsFactory,
322424
+ eventEmitter: this,
322425
+ userRequestSummary: relevantUserRequest,
322426
+ previousResources
322427
+ });
322472
322428
  case types_1.ExtensionType.BACKEND_EVENT:
322473
322429
  case types_1.ExtensionType.SITE_COMPONENT:
322474
322430
  case types_1.ExtensionType.SITE_WIDGET:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/ditto-codegen-public",
3
- "version": "1.0.203",
3
+ "version": "1.0.205",
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.27.2"
26
26
  },
27
- "falconPackageHash": "bc0000ad46cd0244ee27c7b750e385a7bbaac900425d0d8eb04351c5"
27
+ "falconPackageHash": "30c73c66aeeddb26c76b80c1f980e0ffe8c2698f2958772df94da841"
28
28
  }
@@ -1,31 +0,0 @@
1
- // A frontend API based on Astor's Server Endpoints (API Routes)
2
- // See https://docs.astro.build/en/guides/endpoints/#server-endpoints-api-routes
3
- import type { APIRoute } from "astro";
4
-
5
- export const GET: APIRoute = async ({ request }) => {
6
- return new Response(
7
- JSON.stringify({
8
- message: `This was a GET to ${request.url}`,
9
- }),
10
- );
11
- };
12
-
13
- export const POST: APIRoute = async ({ request }) => {
14
- const body = await request.json();
15
-
16
- const { name } = body;
17
-
18
- console.log("name:", name);
19
-
20
- return new Response(
21
- JSON.stringify({
22
- greeting: `Hello ${name}`,
23
- }),
24
- {
25
- status: 200,
26
- headers: {
27
- "Content-Type": "application/json",
28
- },
29
- },
30
- );
31
- };