@wix/ditto-codegen-public 1.0.297 → 1.0.299

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 +355 -285
  2. package/package.json +2 -2
package/dist/out.js CHANGED
@@ -11609,7 +11609,9 @@ var require_constants5 = __commonJS({
11609
11609
  ecomDiscountTriggers: "service plugin",
11610
11610
  ecomGiftCards: "service plugin",
11611
11611
  ecomPaymentSettings: "service plugin",
11612
- bookingsStaffSortingProvider: "service plugin"
11612
+ bookingsStaffSortingProvider: "service plugin",
11613
+ contextProvider: "context provider",
11614
+ functionLibrary: "function library"
11613
11615
  };
11614
11616
  function isMcpTool(tool) {
11615
11617
  return tool.startsWith(exports2.WIX_MCP_SERVER_NAME);
@@ -11625,7 +11627,7 @@ var require_constants5 = __commonJS({
11625
11627
  return { extensionType: "dataCollection", label: "collection" };
11626
11628
  }
11627
11629
  for (const [extensionType, label] of Object.entries(exports2.BUILDER_TO_EXTENSION_LABEL)) {
11628
- if (content.includes(`extensions.${extensionType}(`)) {
11630
+ if (content.includes(`extensions.${extensionType}(`) || content.includes(`experimentalExtensions.${extensionType}(`)) {
11629
11631
  return { extensionType, label };
11630
11632
  }
11631
11633
  }
@@ -11663,6 +11665,75 @@ ${closeBrace}${tail}`;
11663
11665
  }
11664
11666
  });
11665
11667
 
11668
+ // dist/experiments.js
11669
+ var require_experiments = __commonJS({
11670
+ "dist/experiments.js"(exports2) {
11671
+ "use strict";
11672
+ Object.defineProperty(exports2, "__esModule", { value: true });
11673
+ exports2.isExperimentEnabled = isExperimentEnabled;
11674
+ exports2.isUserDecisionsEnabled = isUserDecisionsEnabled;
11675
+ exports2.isUseWixAiGatewayEnabled = isUseWixAiGatewayEnabled;
11676
+ var logger_12 = require_logger();
11677
+ var parsedExperiments = null;
11678
+ function getExperiments() {
11679
+ if (parsedExperiments !== null) {
11680
+ return parsedExperiments;
11681
+ }
11682
+ const raw = process.env.CODEGEN_EXPERIMENTS;
11683
+ if (!raw) {
11684
+ parsedExperiments = {};
11685
+ return parsedExperiments;
11686
+ }
11687
+ try {
11688
+ parsedExperiments = JSON.parse(raw);
11689
+ } catch (error) {
11690
+ logger_12.logger.error("[Experiments] Failed to parse CODEGEN_EXPERIMENTS", {
11691
+ error: error instanceof Error ? error.message : String(error)
11692
+ });
11693
+ parsedExperiments = {};
11694
+ }
11695
+ return parsedExperiments;
11696
+ }
11697
+ function isExperimentEnabled(specName) {
11698
+ return getExperiments()[specName] === "true";
11699
+ }
11700
+ function isUserDecisionsEnabled() {
11701
+ return isExperimentEnabled("specs.ditto.CodegenUserDecisions");
11702
+ }
11703
+ function isUseWixAiGatewayEnabled() {
11704
+ return isExperimentEnabled("specs.ditto.CodegenUseWixAiGateway");
11705
+ }
11706
+ }
11707
+ });
11708
+
11709
+ // dist/opencode-integration/rules-writer.js
11710
+ var require_rules_writer = __commonJS({
11711
+ "dist/opencode-integration/rules-writer.js"(exports2) {
11712
+ "use strict";
11713
+ Object.defineProperty(exports2, "__esModule", { value: true });
11714
+ exports2.getRulePath = getRulePath;
11715
+ exports2.writeRuleFiles = writeRuleFiles;
11716
+ var promises_1 = require("fs/promises");
11717
+ var os_1 = require("os");
11718
+ var path_1 = require("path");
11719
+ var logger_12 = require_logger();
11720
+ var GLOBAL_RULES_DIR = (0, path_1.join)((0, os_1.homedir)(), ".config", "opencode", "rules");
11721
+ function getRulePath(filename) {
11722
+ return (0, path_1.join)(GLOBAL_RULES_DIR, filename);
11723
+ }
11724
+ async function writeRuleFiles(rules) {
11725
+ await (0, promises_1.mkdir)(GLOBAL_RULES_DIR, { recursive: true });
11726
+ const paths = rules.map((rule) => getRulePath(rule.filename));
11727
+ await Promise.all(rules.map((rule) => (0, promises_1.writeFile)(getRulePath(rule.filename), rule.content, "utf-8")));
11728
+ logger_12.logger.info("[OpenCode] Wrote global rule files", {
11729
+ dir: GLOBAL_RULES_DIR,
11730
+ files: rules.map((r) => r.filename)
11731
+ });
11732
+ return paths;
11733
+ }
11734
+ }
11735
+ });
11736
+
11666
11737
  // dist/opencode-integration/rules/codegen-rules.js
11667
11738
  var require_codegen_rules = __commonJS({
11668
11739
  "dist/opencode-integration/rules/codegen-rules.js"(exports2) {
@@ -11750,70 +11821,276 @@ IMPORTANT INSTRUCTIONS:
11750
11821
  }
11751
11822
  });
11752
11823
 
11753
- // dist/opencode-integration/rules-writer.js
11754
- var require_rules_writer = __commonJS({
11755
- "dist/opencode-integration/rules-writer.js"(exports2) {
11824
+ // ../../node_modules/@wix/ambassador-ctp-ditto-v1-blueprint/cjs/build/types.impl.js
11825
+ var require_types_impl2 = __commonJS({
11826
+ "../../node_modules/@wix/ambassador-ctp-ditto-v1-blueprint/cjs/build/types.impl.js"(exports2) {
11827
+ "use strict";
11828
+ Object.defineProperty(exports2, "__esModule", { value: true });
11829
+ exports2.ExtensionType = void 0;
11830
+ var ExtensionType;
11831
+ (function(ExtensionType2) {
11832
+ ExtensionType2["UNDEFINED_EXTENSION_TYPE"] = "UNDEFINED_EXTENSION_TYPE";
11833
+ ExtensionType2["DASHBOARD_PAGE"] = "DASHBOARD_PAGE";
11834
+ ExtensionType2["DASHBOARD_PLUGIN"] = "DASHBOARD_PLUGIN";
11835
+ ExtensionType2["DASHBOARD_MODAL"] = "DASHBOARD_MODAL";
11836
+ ExtensionType2["SITE_WIDGET"] = "SITE_WIDGET";
11837
+ ExtensionType2["EMBEDDED_SCRIPT"] = "EMBEDDED_SCRIPT";
11838
+ ExtensionType2["BACKEND_API"] = "BACKEND_API";
11839
+ ExtensionType2["BACKEND_EVENT"] = "BACKEND_EVENT";
11840
+ ExtensionType2["SERVICE_PLUGIN"] = "SERVICE_PLUGIN";
11841
+ ExtensionType2["WEB_METHODS"] = "WEB_METHODS";
11842
+ ExtensionType2["SITE_COMPONENT"] = "SITE_COMPONENT";
11843
+ ExtensionType2["WEBHOOK"] = "WEBHOOK";
11844
+ ExtensionType2["SITE_PLUGIN"] = "SITE_PLUGIN";
11845
+ ExtensionType2["DATA_COLLECTION"] = "DATA_COLLECTION";
11846
+ ExtensionType2["DASHBOARD_MENU_PLUGIN"] = "DASHBOARD_MENU_PLUGIN";
11847
+ ExtensionType2["CUSTOM_ELEMENT_WIDGET"] = "CUSTOM_ELEMENT_WIDGET";
11848
+ ExtensionType2["EDITOR_REACT_COMPONENT"] = "EDITOR_REACT_COMPONENT";
11849
+ })(ExtensionType || (exports2.ExtensionType = ExtensionType = {}));
11850
+ }
11851
+ });
11852
+
11853
+ // dist/job-decision-manager.js
11854
+ var require_job_decision_manager = __commonJS({
11855
+ "dist/job-decision-manager.js"(exports2) {
11856
+ "use strict";
11857
+ Object.defineProperty(exports2, "__esModule", { value: true });
11858
+ exports2.UserDecisionCancelledError = void 0;
11859
+ exports2.pauseForUserDecision = pauseForUserDecision;
11860
+ exports2.askJobChoice = askJobChoice;
11861
+ exports2.askJobConfirmation = askJobConfirmation;
11862
+ var types_1 = require_types_impl();
11863
+ var codeGenerationService_12 = require_codeGenerationService();
11864
+ var CodeGenService_12 = require_CodeGenService();
11865
+ var logger_12 = require_logger();
11866
+ var DECISION_POLL_INTERVAL_MS = 2e3;
11867
+ var UserDecisionCancelledError = class extends Error {
11868
+ constructor(jobId, decisionId) {
11869
+ super(`User decision ${decisionId} cancelled for job ${jobId}`);
11870
+ this.jobId = jobId;
11871
+ this.decisionId = decisionId;
11872
+ this.name = "UserDecisionCancelledError";
11873
+ }
11874
+ };
11875
+ exports2.UserDecisionCancelledError = UserDecisionCancelledError;
11876
+ async function pauseForUserDecision(jobId, request) {
11877
+ const decisionId = crypto.randomUUID();
11878
+ const userDecision = {
11879
+ id: decisionId,
11880
+ request: {
11881
+ ...request,
11882
+ requestedAt: /* @__PURE__ */ new Date()
11883
+ }
11884
+ };
11885
+ await codeGenerationService_12.codeGenerationService.updateJobWithPendingDecision(jobId, userDecision);
11886
+ logger_12.logger.info("[JobDecision] Paused for user input", {
11887
+ question: request.question
11888
+ });
11889
+ const startTime = Date.now();
11890
+ const response = await pollForJobDecisionResponse(jobId, decisionId);
11891
+ const durationMs = Date.now() - startTime;
11892
+ await codeGenerationService_12.codeGenerationService.resumeJobFromDecision(jobId);
11893
+ logger_12.logger.info("[JobDecision] Resumed after user decision", {
11894
+ selectedOptionId: response.selectedOptionId,
11895
+ durationMs
11896
+ });
11897
+ return response;
11898
+ }
11899
+ async function pollForJobDecisionResponse(jobId, decisionId) {
11900
+ logger_12.logger.info("[JobDecision] Polling for user decision response", {
11901
+ decisionId
11902
+ });
11903
+ while (true) {
11904
+ const job = await codeGenerationService_12.codeGenerationService.getJob(jobId);
11905
+ if (!job) {
11906
+ throw new Error(`Job ${jobId} not found`);
11907
+ }
11908
+ if (job.status === CodeGenService_12.Status.CANCELLED || job.status === CodeGenService_12.Status.PENDING_CANCEL) {
11909
+ logger_12.logger.warn("[JobDecision] Job cancelled while waiting for user decision", { decisionId });
11910
+ throw new UserDecisionCancelledError(jobId, decisionId);
11911
+ }
11912
+ const decision = job.pendingUserDecisions?.find((d) => d.id === decisionId) ?? job.userDecisionHistory?.find((d) => d.id === decisionId);
11913
+ if (decision?.response?.selectedOptionId) {
11914
+ return {
11915
+ selectedOptionId: decision.response.selectedOptionId,
11916
+ respondedAt: decision.response.respondedAt ?? /* @__PURE__ */ new Date()
11917
+ };
11918
+ }
11919
+ await new Promise((resolve) => setTimeout(resolve, DECISION_POLL_INTERVAL_MS));
11920
+ }
11921
+ }
11922
+ async function askJobChoice(jobId, question, options, context) {
11923
+ const response = await pauseForUserDecision(jobId, {
11924
+ question,
11925
+ questionType: types_1.UserDecisionQuestionType.UI_COMPONENT_TYPE,
11926
+ options,
11927
+ context
11928
+ });
11929
+ if (!response.selectedOptionId) {
11930
+ throw new Error("No option selected in user decision response");
11931
+ }
11932
+ return response.selectedOptionId;
11933
+ }
11934
+ async function askJobConfirmation(jobId, question, context) {
11935
+ const response = await pauseForUserDecision(jobId, {
11936
+ question,
11937
+ questionType: types_1.UserDecisionQuestionType.UI_COMPONENT_TYPE,
11938
+ options: [
11939
+ { id: "yes", label: "Yes" },
11940
+ { id: "no", label: "No" }
11941
+ ],
11942
+ context
11943
+ });
11944
+ return response.selectedOptionId === "yes";
11945
+ }
11946
+ }
11947
+ });
11948
+
11949
+ // dist/pre-run-decision.js
11950
+ var require_pre_run_decision = __commonJS({
11951
+ "dist/pre-run-decision.js"(exports2) {
11952
+ "use strict";
11953
+ Object.defineProperty(exports2, "__esModule", { value: true });
11954
+ exports2.checkSiteUIDecision = void 0;
11955
+ exports2.runPreDecisionCheck = runPreDecisionCheck;
11956
+ var types_1 = require_types_impl2();
11957
+ var job_decision_manager_1 = require_job_decision_manager();
11958
+ var logger_12 = require_logger();
11959
+ async function runPreDecisionCheck(jobId, context, checkers) {
11960
+ const allDecisions = [];
11961
+ let modifiedPayload = context.payload;
11962
+ for (const checker of checkers) {
11963
+ const result = await checker(jobId, {
11964
+ payload: modifiedPayload
11965
+ });
11966
+ if (result) {
11967
+ allDecisions.push(...result.decisionsApplied);
11968
+ if (result.modifiedPayload) {
11969
+ modifiedPayload = result.modifiedPayload;
11970
+ }
11971
+ }
11972
+ }
11973
+ return {
11974
+ decisionsApplied: allDecisions,
11975
+ modifiedPayload
11976
+ };
11977
+ }
11978
+ var checkSiteUIDecision = async (jobId, context) => {
11979
+ const blueprint = context.payload;
11980
+ const extensions = blueprint?.extensions ?? [];
11981
+ const siteUIExtension = extensions.find((ext) => isSiteUIExtension(ext));
11982
+ if (!siteUIExtension?.name) {
11983
+ return null;
11984
+ }
11985
+ const extensionName = siteUIExtension.name;
11986
+ const currentType = siteUIExtension.type;
11987
+ logger_12.logger.info(`[PreDecision] Found site UI extension: "${extensionName}" (current type: ${currentType})`);
11988
+ const options = [
11989
+ {
11990
+ id: types_1.ExtensionType.SITE_WIDGET,
11991
+ label: "Custom Element Widget",
11992
+ description: "A self-contained widget built as a Custom Element, embedded on the site. Best for standalone, reusable components."
11993
+ },
11994
+ {
11995
+ id: types_1.ExtensionType.SITE_COMPONENT,
11996
+ label: "Editor React Component",
11997
+ description: "A React component that integrates with the site builder. Best for components that need to work with Wix editor features."
11998
+ }
11999
+ ];
12000
+ const selectedType = await (0, job_decision_manager_1.askJobChoice)(jobId, `What type of site UI element would you like to create for "${extensionName}"?`, options, "Custom Element Widgets are standalone embeddable units with their own styling, while Editor React Components integrate more deeply with the Wix editor and builder.");
12001
+ const selectedLabel = options.find((o) => o.id === selectedType)?.label ?? selectedType;
12002
+ const isTypeChanged = selectedType !== currentType;
12003
+ logger_12.logger.info(`[PreDecision] User selected ${selectedType} for "${extensionName}"${isTypeChanged ? ` (changed from ${currentType})` : " (unchanged)"}`);
12004
+ const appliedDecision = {
12005
+ type: "SITE_UI_TYPE",
12006
+ question: "Custom Element Widget vs Editor React Component",
12007
+ selectedOptionId: selectedType
12008
+ };
12009
+ return {
12010
+ decisionsApplied: [appliedDecision],
12011
+ modifiedPayload: blueprint ? applyTypeToBlueprint(blueprint, extensionName, selectedType, selectedLabel) : void 0
12012
+ };
12013
+ };
12014
+ exports2.checkSiteUIDecision = checkSiteUIDecision;
12015
+ function isSiteUIExtension(extension) {
12016
+ return extension.type === types_1.ExtensionType.SITE_WIDGET || extension.type === types_1.ExtensionType.SITE_COMPONENT;
12017
+ }
12018
+ function applyTypeToBlueprint(blueprint, extensionName, type, label) {
12019
+ const summaryNotice = `[USER DECISION] The user explicitly chose "${label}" for the "${extensionName}" extension. You MUST generate it as type ${type}. Do NOT use any other type.`;
12020
+ const descriptionNotice = `[USER DECISION] This extension MUST be a ${label} (type: ${type}). The user explicitly chose this. Do NOT change it.`;
12021
+ return {
12022
+ ...blueprint,
12023
+ summary: `${summaryNotice}
12024
+
12025
+ ${blueprint.summary ?? ""}`.trim(),
12026
+ extensions: blueprint.extensions?.map((ext) => ext.name === extensionName ? {
12027
+ ...ext,
12028
+ type,
12029
+ description: `${descriptionNotice}
12030
+
12031
+ ${ext.description ?? ""}`.trim(),
12032
+ _userDecision: "IMPORTANT: The user explicitly chose this extension type. You MUST use this exact type."
12033
+ } : ext)
12034
+ };
12035
+ }
12036
+ }
12037
+ });
12038
+
12039
+ // dist/environments/app-builder.js
12040
+ var require_app_builder = __commonJS({
12041
+ "dist/environments/app-builder.js"(exports2) {
12042
+ "use strict";
12043
+ Object.defineProperty(exports2, "__esModule", { value: true });
12044
+ exports2.appBuilderCodegenConfig = void 0;
12045
+ var codegen_rules_1 = require_codegen_rules();
12046
+ var ask_rules_1 = require_ask_rules();
12047
+ var pre_run_decision_1 = require_pre_run_decision();
12048
+ exports2.appBuilderCodegenConfig = {
12049
+ codegenRules: [
12050
+ { filename: "codegen-instructions.md", content: codegen_rules_1.CODEGEN_RULES }
12051
+ ],
12052
+ askRules: [{ filename: "ask-instructions.md", content: ask_rules_1.ASK_RULES }],
12053
+ decisionCheckers: [pre_run_decision_1.checkSiteUIDecision]
12054
+ };
12055
+ }
12056
+ });
12057
+
12058
+ // dist/environments/studio-2.js
12059
+ var require_studio_2 = __commonJS({
12060
+ "dist/environments/studio-2.js"(exports2) {
11756
12061
  "use strict";
11757
12062
  Object.defineProperty(exports2, "__esModule", { value: true });
11758
- exports2.ASK_RULES_PATH = exports2.CODEGEN_RULES_PATH = void 0;
11759
- exports2.writeRuleFiles = writeRuleFiles;
11760
- var promises_1 = require("fs/promises");
11761
- var os_1 = require("os");
11762
- var path_1 = require("path");
12063
+ exports2.studio2CodegenConfig = void 0;
11763
12064
  var codegen_rules_1 = require_codegen_rules();
11764
12065
  var ask_rules_1 = require_ask_rules();
11765
- var logger_12 = require_logger();
11766
- var GLOBAL_RULES_DIR = (0, path_1.join)((0, os_1.homedir)(), ".config", "opencode", "rules");
11767
- exports2.CODEGEN_RULES_PATH = (0, path_1.join)(GLOBAL_RULES_DIR, "codegen-instructions.md");
11768
- exports2.ASK_RULES_PATH = (0, path_1.join)(GLOBAL_RULES_DIR, "ask-instructions.md");
11769
- async function writeRuleFiles() {
11770
- await (0, promises_1.mkdir)(GLOBAL_RULES_DIR, { recursive: true });
11771
- await Promise.all([
11772
- (0, promises_1.writeFile)(exports2.CODEGEN_RULES_PATH, codegen_rules_1.CODEGEN_RULES, "utf-8"),
11773
- (0, promises_1.writeFile)(exports2.ASK_RULES_PATH, ask_rules_1.ASK_RULES, "utf-8")
11774
- ]);
11775
- logger_12.logger.info("[OpenCode] Wrote global rule files", { dir: GLOBAL_RULES_DIR });
11776
- }
12066
+ exports2.studio2CodegenConfig = {
12067
+ codegenRules: [
12068
+ { filename: "codegen-instructions.md", content: codegen_rules_1.CODEGEN_RULES }
12069
+ ],
12070
+ askRules: [{ filename: "ask-instructions.md", content: ask_rules_1.ASK_RULES }],
12071
+ decisionCheckers: []
12072
+ };
11777
12073
  }
11778
12074
  });
11779
12075
 
11780
- // dist/experiments.js
11781
- var require_experiments = __commonJS({
11782
- "dist/experiments.js"(exports2) {
12076
+ // dist/environments/index.js
12077
+ var require_environments = __commonJS({
12078
+ "dist/environments/index.js"(exports2) {
11783
12079
  "use strict";
11784
12080
  Object.defineProperty(exports2, "__esModule", { value: true });
11785
- exports2.isExperimentEnabled = isExperimentEnabled;
11786
- exports2.isUserDecisionsEnabled = isUserDecisionsEnabled;
11787
- exports2.isUseWixAiGatewayEnabled = isUseWixAiGatewayEnabled;
11788
- var logger_12 = require_logger();
11789
- var parsedExperiments = null;
11790
- function getExperiments() {
11791
- if (parsedExperiments !== null) {
11792
- return parsedExperiments;
11793
- }
11794
- const raw = process.env.CODEGEN_EXPERIMENTS;
11795
- if (!raw) {
11796
- parsedExperiments = {};
11797
- return parsedExperiments;
11798
- }
11799
- try {
11800
- parsedExperiments = JSON.parse(raw);
11801
- } catch (error) {
11802
- logger_12.logger.error("[Experiments] Failed to parse CODEGEN_EXPERIMENTS", {
11803
- error: error instanceof Error ? error.message : String(error)
11804
- });
11805
- parsedExperiments = {};
12081
+ exports2.getCodegenEnvironmentConfig = getCodegenEnvironmentConfig;
12082
+ var types_1 = require_types_impl();
12083
+ var app_builder_1 = require_app_builder();
12084
+ var studio_2_1 = require_studio_2();
12085
+ function getCodegenEnvironmentConfig(environment) {
12086
+ switch (environment) {
12087
+ case types_1.Environment.STUDIO_2:
12088
+ return studio_2_1.studio2CodegenConfig;
12089
+ case types_1.Environment.APP_BUILDER:
12090
+ case types_1.Environment.UNKNOWN_ENVIRONMENT:
12091
+ default:
12092
+ return app_builder_1.appBuilderCodegenConfig;
11806
12093
  }
11807
- return parsedExperiments;
11808
- }
11809
- function isExperimentEnabled(specName) {
11810
- return getExperiments()[specName] === "true";
11811
- }
11812
- function isUserDecisionsEnabled() {
11813
- return isExperimentEnabled("specs.ditto.CodegenUserDecisions");
11814
- }
11815
- function isUseWixAiGatewayEnabled() {
11816
- return isExperimentEnabled("specs.ditto.CodegenUseWixAiGateway");
11817
12094
  }
11818
12095
  }
11819
12096
  });
@@ -11826,11 +12103,11 @@ var require_config = __commonJS({
11826
12103
  exports2.DEFAULT_MODEL = exports2.DEFAULT_TIMEOUT_MS = void 0;
11827
12104
  exports2.getAnthropicBaseUrl = getAnthropicBaseUrl;
11828
12105
  exports2.getOpenCodeEnv = getOpenCodeEnv;
11829
- exports2.getOpenCodeAskEnv = getOpenCodeAskEnv;
11830
12106
  var os_1 = require("os");
11831
12107
  var constants_1 = require_constants5();
11832
- var rules_writer_12 = require_rules_writer();
11833
12108
  var experiments_1 = require_experiments();
12109
+ var rules_writer_12 = require_rules_writer();
12110
+ var environments_12 = require_environments();
11834
12111
  exports2.DEFAULT_TIMEOUT_MS = 20 * 60 * 1e3;
11835
12112
  exports2.DEFAULT_MODEL = "anthropic/claude-sonnet-4-6";
11836
12113
  var AI_PROXY_BASE_URL = process.env.CODEGEN_AI_PROXY_BASE_URL || "http://localhost:3001";
@@ -11866,7 +12143,7 @@ var require_config = __commonJS({
11866
12143
  enabled: true
11867
12144
  }
11868
12145
  };
11869
- function getOpenCodeConfig() {
12146
+ function getOpenCodeConfig(instructionPaths) {
11870
12147
  return {
11871
12148
  model: exports2.DEFAULT_MODEL,
11872
12149
  provider: getProviderConfig(),
@@ -11893,14 +12170,14 @@ var require_config = __commonJS({
11893
12170
  "/root/.opencode/**": "allow"
11894
12171
  }
11895
12172
  },
11896
- instructions: [rules_writer_12.CODEGEN_RULES_PATH],
12173
+ instructions: instructionPaths,
11897
12174
  autoupdate: false,
11898
12175
  share: "disabled",
11899
12176
  lsp: false,
11900
12177
  mcp: WIX_MCP_CONFIG
11901
12178
  };
11902
12179
  }
11903
- function getOpenCodeAskConfig() {
12180
+ function getOpenCodeAskConfig(instructionPaths) {
11904
12181
  return {
11905
12182
  model: exports2.DEFAULT_MODEL,
11906
12183
  provider: getProviderConfig(),
@@ -11927,7 +12204,7 @@ var require_config = __commonJS({
11927
12204
  /* OpenCodeTool.Uuid */
11928
12205
  ]: "deny"
11929
12206
  },
11930
- instructions: [rules_writer_12.ASK_RULES_PATH],
12207
+ instructions: instructionPaths,
11931
12208
  lsp: false,
11932
12209
  mcp: WIX_MCP_CONFIG
11933
12210
  };
@@ -11952,11 +12229,12 @@ var require_config = __commonJS({
11952
12229
  OPENCODE_DISABLE_FILETIME_CHECK: "true"
11953
12230
  };
11954
12231
  }
11955
- function getOpenCodeEnv(projectId) {
11956
- return buildOpenCodeEnv(projectId, getOpenCodeConfig());
11957
- }
11958
- function getOpenCodeAskEnv(projectId) {
11959
- return buildOpenCodeEnv(projectId, getOpenCodeAskConfig());
12232
+ function getOpenCodeEnv(projectId, isAsk = false) {
12233
+ const envConfig = (0, environments_12.getCodegenEnvironmentConfig)();
12234
+ const rules = isAsk ? envConfig.askRules : envConfig.codegenRules;
12235
+ const paths = rules.map((r) => (0, rules_writer_12.getRulePath)(r.filename));
12236
+ const config = isAsk ? getOpenCodeAskConfig(paths) : getOpenCodeConfig(paths);
12237
+ return buildOpenCodeEnv(projectId, config);
11960
12238
  }
11961
12239
  }
11962
12240
  });
@@ -12900,7 +13178,7 @@ var require_executor = __commonJS({
12900
13178
  }
12901
13179
  async function logOpenCodeStats(options) {
12902
13180
  const isAsk = job_context_storage_12.jobContextStorage.getStore()?.kind === ditto_codegen_types_12.TaskKind.ASK_CODEGEN;
12903
- const env = isAsk ? (0, config_1.getOpenCodeAskEnv)(options.projectId) : (0, config_1.getOpenCodeEnv)(options.projectId);
13181
+ const env = (0, config_1.getOpenCodeEnv)(options.projectId, isAsk);
12904
13182
  const stats = await (0, cost_tracker_1.fetchOpenCodeStats)(options.outputPath, env);
12905
13183
  if (stats) {
12906
13184
  console.log("[OpenCode] Stats\n", stats);
@@ -12956,7 +13234,7 @@ var require_executor = __commonJS({
12956
13234
  workingDirectory: outputPath
12957
13235
  });
12958
13236
  const isAsk = job_context_storage_12.jobContextStorage.getStore()?.kind === ditto_codegen_types_12.TaskKind.ASK_CODEGEN;
12959
- const env = isAsk ? (0, config_1.getOpenCodeAskEnv)(projectId) : (0, config_1.getOpenCodeEnv)(projectId);
13237
+ const env = (0, config_1.getOpenCodeEnv)(projectId, isAsk);
12960
13238
  ctx.child = (0, child_process_1.spawn)("opencode", args, {
12961
13239
  cwd: outputPath,
12962
13240
  env,
@@ -17488,219 +17766,6 @@ var require_biEvents = __commonJS({
17488
17766
  }
17489
17767
  });
17490
17768
 
17491
- // ../../node_modules/@wix/ambassador-ctp-ditto-v1-blueprint/cjs/build/types.impl.js
17492
- var require_types_impl2 = __commonJS({
17493
- "../../node_modules/@wix/ambassador-ctp-ditto-v1-blueprint/cjs/build/types.impl.js"(exports2) {
17494
- "use strict";
17495
- Object.defineProperty(exports2, "__esModule", { value: true });
17496
- exports2.ExtensionType = void 0;
17497
- var ExtensionType;
17498
- (function(ExtensionType2) {
17499
- ExtensionType2["UNDEFINED_EXTENSION_TYPE"] = "UNDEFINED_EXTENSION_TYPE";
17500
- ExtensionType2["DASHBOARD_PAGE"] = "DASHBOARD_PAGE";
17501
- ExtensionType2["DASHBOARD_PLUGIN"] = "DASHBOARD_PLUGIN";
17502
- ExtensionType2["DASHBOARD_MODAL"] = "DASHBOARD_MODAL";
17503
- ExtensionType2["SITE_WIDGET"] = "SITE_WIDGET";
17504
- ExtensionType2["EMBEDDED_SCRIPT"] = "EMBEDDED_SCRIPT";
17505
- ExtensionType2["BACKEND_API"] = "BACKEND_API";
17506
- ExtensionType2["BACKEND_EVENT"] = "BACKEND_EVENT";
17507
- ExtensionType2["SERVICE_PLUGIN"] = "SERVICE_PLUGIN";
17508
- ExtensionType2["WEB_METHODS"] = "WEB_METHODS";
17509
- ExtensionType2["SITE_COMPONENT"] = "SITE_COMPONENT";
17510
- ExtensionType2["WEBHOOK"] = "WEBHOOK";
17511
- ExtensionType2["SITE_PLUGIN"] = "SITE_PLUGIN";
17512
- ExtensionType2["DATA_COLLECTION"] = "DATA_COLLECTION";
17513
- ExtensionType2["DASHBOARD_MENU_PLUGIN"] = "DASHBOARD_MENU_PLUGIN";
17514
- ExtensionType2["CUSTOM_ELEMENT_WIDGET"] = "CUSTOM_ELEMENT_WIDGET";
17515
- ExtensionType2["EDITOR_REACT_COMPONENT"] = "EDITOR_REACT_COMPONENT";
17516
- })(ExtensionType || (exports2.ExtensionType = ExtensionType = {}));
17517
- }
17518
- });
17519
-
17520
- // dist/job-decision-manager.js
17521
- var require_job_decision_manager = __commonJS({
17522
- "dist/job-decision-manager.js"(exports2) {
17523
- "use strict";
17524
- Object.defineProperty(exports2, "__esModule", { value: true });
17525
- exports2.UserDecisionCancelledError = void 0;
17526
- exports2.pauseForUserDecision = pauseForUserDecision;
17527
- exports2.askJobChoice = askJobChoice;
17528
- exports2.askJobConfirmation = askJobConfirmation;
17529
- var types_1 = require_types_impl();
17530
- var codeGenerationService_12 = require_codeGenerationService();
17531
- var CodeGenService_12 = require_CodeGenService();
17532
- var logger_12 = require_logger();
17533
- var DECISION_POLL_INTERVAL_MS = 2e3;
17534
- var UserDecisionCancelledError = class extends Error {
17535
- constructor(jobId, decisionId) {
17536
- super(`User decision ${decisionId} cancelled for job ${jobId}`);
17537
- this.jobId = jobId;
17538
- this.decisionId = decisionId;
17539
- this.name = "UserDecisionCancelledError";
17540
- }
17541
- };
17542
- exports2.UserDecisionCancelledError = UserDecisionCancelledError;
17543
- async function pauseForUserDecision(jobId, request) {
17544
- const decisionId = crypto.randomUUID();
17545
- const userDecision = {
17546
- id: decisionId,
17547
- request: {
17548
- ...request,
17549
- requestedAt: /* @__PURE__ */ new Date()
17550
- }
17551
- };
17552
- await codeGenerationService_12.codeGenerationService.updateJobWithPendingDecision(jobId, userDecision);
17553
- logger_12.logger.info("[JobDecision] Paused for user input", {
17554
- question: request.question
17555
- });
17556
- const startTime = Date.now();
17557
- const response = await pollForJobDecisionResponse(jobId, decisionId);
17558
- const durationMs = Date.now() - startTime;
17559
- await codeGenerationService_12.codeGenerationService.resumeJobFromDecision(jobId);
17560
- logger_12.logger.info("[JobDecision] Resumed after user decision", {
17561
- selectedOptionId: response.selectedOptionId,
17562
- durationMs
17563
- });
17564
- return response;
17565
- }
17566
- async function pollForJobDecisionResponse(jobId, decisionId) {
17567
- logger_12.logger.info("[JobDecision] Polling for user decision response", {
17568
- decisionId
17569
- });
17570
- while (true) {
17571
- const job = await codeGenerationService_12.codeGenerationService.getJob(jobId);
17572
- if (!job) {
17573
- throw new Error(`Job ${jobId} not found`);
17574
- }
17575
- if (job.status === CodeGenService_12.Status.CANCELLED || job.status === CodeGenService_12.Status.PENDING_CANCEL) {
17576
- logger_12.logger.warn("[JobDecision] Job cancelled while waiting for user decision", { decisionId });
17577
- throw new UserDecisionCancelledError(jobId, decisionId);
17578
- }
17579
- const decision = job.pendingUserDecisions?.find((d) => d.id === decisionId) ?? job.userDecisionHistory?.find((d) => d.id === decisionId);
17580
- if (decision?.response?.selectedOptionId) {
17581
- return {
17582
- selectedOptionId: decision.response.selectedOptionId,
17583
- respondedAt: decision.response.respondedAt ?? /* @__PURE__ */ new Date()
17584
- };
17585
- }
17586
- await new Promise((resolve) => setTimeout(resolve, DECISION_POLL_INTERVAL_MS));
17587
- }
17588
- }
17589
- async function askJobChoice(jobId, question, options, context) {
17590
- const response = await pauseForUserDecision(jobId, {
17591
- question,
17592
- questionType: types_1.UserDecisionQuestionType.UI_COMPONENT_TYPE,
17593
- options,
17594
- context
17595
- });
17596
- if (!response.selectedOptionId) {
17597
- throw new Error("No option selected in user decision response");
17598
- }
17599
- return response.selectedOptionId;
17600
- }
17601
- async function askJobConfirmation(jobId, question, context) {
17602
- const response = await pauseForUserDecision(jobId, {
17603
- question,
17604
- questionType: types_1.UserDecisionQuestionType.UI_COMPONENT_TYPE,
17605
- options: [
17606
- { id: "yes", label: "Yes" },
17607
- { id: "no", label: "No" }
17608
- ],
17609
- context
17610
- });
17611
- return response.selectedOptionId === "yes";
17612
- }
17613
- }
17614
- });
17615
-
17616
- // dist/pre-run-decision.js
17617
- var require_pre_run_decision = __commonJS({
17618
- "dist/pre-run-decision.js"(exports2) {
17619
- "use strict";
17620
- Object.defineProperty(exports2, "__esModule", { value: true });
17621
- exports2.runPreDecisionCheck = runPreDecisionCheck;
17622
- exports2.checkSiteUIDecision = checkSiteUIDecision;
17623
- var types_1 = require_types_impl2();
17624
- var job_decision_manager_1 = require_job_decision_manager();
17625
- var logger_12 = require_logger();
17626
- async function runPreDecisionCheck(jobId, context, checkers) {
17627
- const allDecisions = [];
17628
- let modifiedBlueprint = context.blueprint;
17629
- for (const checker of checkers) {
17630
- const result = await checker(jobId, {
17631
- blueprint: modifiedBlueprint
17632
- });
17633
- if (result) {
17634
- allDecisions.push(...result.decisionsApplied);
17635
- if (result.modifiedBlueprint) {
17636
- modifiedBlueprint = result.modifiedBlueprint;
17637
- }
17638
- }
17639
- }
17640
- return {
17641
- decisionsApplied: allDecisions,
17642
- modifiedBlueprint
17643
- };
17644
- }
17645
- async function checkSiteUIDecision(jobId, context) {
17646
- const extensions = context.blueprint?.extensions ?? [];
17647
- const siteUIExtension = extensions.find((ext) => isSiteUIExtension(ext));
17648
- if (!siteUIExtension?.name) {
17649
- return null;
17650
- }
17651
- const extensionName = siteUIExtension.name;
17652
- const currentType = siteUIExtension.type;
17653
- logger_12.logger.info(`[PreDecision] Found site UI extension: "${extensionName}" (current type: ${currentType})`);
17654
- const options = [
17655
- {
17656
- id: types_1.ExtensionType.SITE_WIDGET,
17657
- label: "Custom Element Widget",
17658
- description: "A self-contained widget built as a Custom Element, embedded on the site. Best for standalone, reusable components."
17659
- },
17660
- {
17661
- id: types_1.ExtensionType.SITE_COMPONENT,
17662
- label: "Editor React Component",
17663
- description: "A React component that integrates with the site builder. Best for components that need to work with Wix editor features."
17664
- }
17665
- ];
17666
- const selectedType = await (0, job_decision_manager_1.askJobChoice)(jobId, `What type of site UI element would you like to create for "${extensionName}"?`, options, "Custom Element Widgets are standalone embeddable units with their own styling, while Editor React Components integrate more deeply with the Wix editor and builder.");
17667
- const selectedLabel = options.find((o) => o.id === selectedType)?.label ?? selectedType;
17668
- const isTypeChanged = selectedType !== currentType;
17669
- logger_12.logger.info(`[PreDecision] User selected ${selectedType} for "${extensionName}"${isTypeChanged ? ` (changed from ${currentType})` : " (unchanged)"}`);
17670
- const appliedDecision = {
17671
- type: "SITE_UI_TYPE",
17672
- question: "Custom Element Widget vs Editor React Component",
17673
- selectedOptionId: selectedType
17674
- };
17675
- return {
17676
- decisionsApplied: [appliedDecision],
17677
- modifiedBlueprint: context.blueprint ? applyTypeToBlueprint(context.blueprint, extensionName, selectedType, selectedLabel) : void 0
17678
- };
17679
- }
17680
- function isSiteUIExtension(extension) {
17681
- return extension.type === types_1.ExtensionType.SITE_WIDGET || extension.type === types_1.ExtensionType.SITE_COMPONENT;
17682
- }
17683
- function applyTypeToBlueprint(blueprint, extensionName, type, label) {
17684
- const summaryNotice = `[USER DECISION] The user explicitly chose "${label}" for the "${extensionName}" extension. You MUST generate it as type ${type}. Do NOT use any other type.`;
17685
- const descriptionNotice = `[USER DECISION] This extension MUST be a ${label} (type: ${type}). The user explicitly chose this. Do NOT change it.`;
17686
- return {
17687
- ...blueprint,
17688
- summary: `${summaryNotice}
17689
-
17690
- ${blueprint.summary ?? ""}`.trim(),
17691
- extensions: blueprint.extensions?.map((ext) => ext.name === extensionName ? {
17692
- ...ext,
17693
- type,
17694
- description: `${descriptionNotice}
17695
-
17696
- ${ext.description ?? ""}`.trim(),
17697
- _userDecision: "IMPORTANT: The user explicitly chose this extension type. You MUST use this exact type."
17698
- } : ext)
17699
- };
17700
- }
17701
- }
17702
- });
17703
-
17704
17769
  // dist/flows/opencode-init.js
17705
17770
  var require_opencode_init = __commonJS({
17706
17771
  "dist/flows/opencode-init.js"(exports2) {
@@ -17720,6 +17785,7 @@ var require_opencode_init = __commonJS({
17720
17785
  var biEvents_1 = require_biEvents();
17721
17786
  var pre_run_decision_1 = require_pre_run_decision();
17722
17787
  var experiments_1 = require_experiments();
17788
+ var environments_12 = require_environments();
17723
17789
  var runOpencodeInitFlow = async (blueprint, history) => {
17724
17790
  const store = job_context_storage_12.jobContextStorage.getStore();
17725
17791
  if (!store?.jobId || !store?.taskId) {
@@ -17747,8 +17813,9 @@ var require_opencode_init = __commonJS({
17747
17813
  const outputPath = (0, codegen_flow_helpers_12.getOutputPath)();
17748
17814
  let finalBlueprint = blueprint;
17749
17815
  if ((0, experiments_1.isUserDecisionsEnabled)()) {
17750
- const preDecisionResult = await (0, pre_run_decision_1.runPreDecisionCheck)(localJobContext.jobId, { blueprint }, [pre_run_decision_1.checkSiteUIDecision]);
17751
- finalBlueprint = preDecisionResult.modifiedBlueprint ?? blueprint;
17816
+ const envConfig = (0, environments_12.getCodegenEnvironmentConfig)();
17817
+ const preDecisionResult = await (0, pre_run_decision_1.runPreDecisionCheck)(localJobContext.jobId, { payload: blueprint }, envConfig.decisionCheckers);
17818
+ finalBlueprint = preDecisionResult.modifiedPayload ?? blueprint;
17752
17819
  if (preDecisionResult.decisionsApplied.length > 0) {
17753
17820
  logger_12.logger.info("[OpenCode Init] Applied pre-decision", {
17754
17821
  decisions: preDecisionResult.decisionsApplied,
@@ -18389,6 +18456,7 @@ var logger_1 = require_logger();
18389
18456
  var skills_installer_1 = require_skills_installer();
18390
18457
  var rules_writer_1 = require_rules_writer();
18391
18458
  var tools_writer_1 = require_tools_writer();
18459
+ var environments_1 = require_environments();
18392
18460
  var sessionId = process.env.CODEGEN_SESSION_ID || (0, crypto_1.randomUUID)();
18393
18461
  process.env.CODEGEN_SESSION_ID = sessionId;
18394
18462
  (0, logger_1.initLogger)(sessionId);
@@ -18435,9 +18503,11 @@ var alwaysOnLoop = async () => {
18435
18503
  }
18436
18504
  };
18437
18505
  async function initOpenCode() {
18506
+ const envConfig = (0, environments_1.getCodegenEnvironmentConfig)();
18438
18507
  await Promise.all([
18508
+ (0, rules_writer_1.writeRuleFiles)(envConfig.codegenRules),
18509
+ (0, rules_writer_1.writeRuleFiles)(envConfig.askRules),
18439
18510
  (0, skills_installer_1.installSkills)((0, codegen_flow_helpers_1.getOutputPath)(), logger_1.logger),
18440
- (0, rules_writer_1.writeRuleFiles)(),
18441
18511
  (0, tools_writer_1.writeToolFiles)()
18442
18512
  ]);
18443
18513
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/ditto-codegen-public",
3
- "version": "1.0.297",
3
+ "version": "1.0.299",
4
4
  "description": "AI-powered Wix CLI app generator - standalone executable",
5
5
  "scripts": {
6
6
  "build": "node build.mjs",
@@ -27,5 +27,5 @@
27
27
  "@wix/ditto-codegen": "1.0.0",
28
28
  "esbuild": "^0.27.2"
29
29
  },
30
- "falconPackageHash": "8d59424804af593c7815d740ffb2d63bccfc1a551a5bf81c8a306613"
30
+ "falconPackageHash": "a01dca5cf215678ea67a1d956dd4f31273b544e5b2fd4bf54bc84ca0"
31
31
  }