@wix/ditto-codegen-public 1.0.298 → 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 +351 -283
  2. package/package.json +2 -2
package/dist/out.js CHANGED
@@ -11665,6 +11665,75 @@ ${closeBrace}${tail}`;
11665
11665
  }
11666
11666
  });
11667
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
+
11668
11737
  // dist/opencode-integration/rules/codegen-rules.js
11669
11738
  var require_codegen_rules = __commonJS({
11670
11739
  "dist/opencode-integration/rules/codegen-rules.js"(exports2) {
@@ -11752,70 +11821,276 @@ IMPORTANT INSTRUCTIONS:
11752
11821
  }
11753
11822
  });
11754
11823
 
11755
- // dist/opencode-integration/rules-writer.js
11756
- var require_rules_writer = __commonJS({
11757
- "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) {
11758
12061
  "use strict";
11759
12062
  Object.defineProperty(exports2, "__esModule", { value: true });
11760
- exports2.ASK_RULES_PATH = exports2.CODEGEN_RULES_PATH = void 0;
11761
- exports2.writeRuleFiles = writeRuleFiles;
11762
- var promises_1 = require("fs/promises");
11763
- var os_1 = require("os");
11764
- var path_1 = require("path");
12063
+ exports2.studio2CodegenConfig = void 0;
11765
12064
  var codegen_rules_1 = require_codegen_rules();
11766
12065
  var ask_rules_1 = require_ask_rules();
11767
- var logger_12 = require_logger();
11768
- var GLOBAL_RULES_DIR = (0, path_1.join)((0, os_1.homedir)(), ".config", "opencode", "rules");
11769
- exports2.CODEGEN_RULES_PATH = (0, path_1.join)(GLOBAL_RULES_DIR, "codegen-instructions.md");
11770
- exports2.ASK_RULES_PATH = (0, path_1.join)(GLOBAL_RULES_DIR, "ask-instructions.md");
11771
- async function writeRuleFiles() {
11772
- await (0, promises_1.mkdir)(GLOBAL_RULES_DIR, { recursive: true });
11773
- await Promise.all([
11774
- (0, promises_1.writeFile)(exports2.CODEGEN_RULES_PATH, codegen_rules_1.CODEGEN_RULES, "utf-8"),
11775
- (0, promises_1.writeFile)(exports2.ASK_RULES_PATH, ask_rules_1.ASK_RULES, "utf-8")
11776
- ]);
11777
- logger_12.logger.info("[OpenCode] Wrote global rule files", { dir: GLOBAL_RULES_DIR });
11778
- }
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
+ };
11779
12073
  }
11780
12074
  });
11781
12075
 
11782
- // dist/experiments.js
11783
- var require_experiments = __commonJS({
11784
- "dist/experiments.js"(exports2) {
12076
+ // dist/environments/index.js
12077
+ var require_environments = __commonJS({
12078
+ "dist/environments/index.js"(exports2) {
11785
12079
  "use strict";
11786
12080
  Object.defineProperty(exports2, "__esModule", { value: true });
11787
- exports2.isExperimentEnabled = isExperimentEnabled;
11788
- exports2.isUserDecisionsEnabled = isUserDecisionsEnabled;
11789
- exports2.isUseWixAiGatewayEnabled = isUseWixAiGatewayEnabled;
11790
- var logger_12 = require_logger();
11791
- var parsedExperiments = null;
11792
- function getExperiments() {
11793
- if (parsedExperiments !== null) {
11794
- return parsedExperiments;
11795
- }
11796
- const raw = process.env.CODEGEN_EXPERIMENTS;
11797
- if (!raw) {
11798
- parsedExperiments = {};
11799
- return parsedExperiments;
11800
- }
11801
- try {
11802
- parsedExperiments = JSON.parse(raw);
11803
- } catch (error) {
11804
- logger_12.logger.error("[Experiments] Failed to parse CODEGEN_EXPERIMENTS", {
11805
- error: error instanceof Error ? error.message : String(error)
11806
- });
11807
- 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;
11808
12093
  }
11809
- return parsedExperiments;
11810
- }
11811
- function isExperimentEnabled(specName) {
11812
- return getExperiments()[specName] === "true";
11813
- }
11814
- function isUserDecisionsEnabled() {
11815
- return isExperimentEnabled("specs.ditto.CodegenUserDecisions");
11816
- }
11817
- function isUseWixAiGatewayEnabled() {
11818
- return isExperimentEnabled("specs.ditto.CodegenUseWixAiGateway");
11819
12094
  }
11820
12095
  }
11821
12096
  });
@@ -11828,11 +12103,11 @@ var require_config = __commonJS({
11828
12103
  exports2.DEFAULT_MODEL = exports2.DEFAULT_TIMEOUT_MS = void 0;
11829
12104
  exports2.getAnthropicBaseUrl = getAnthropicBaseUrl;
11830
12105
  exports2.getOpenCodeEnv = getOpenCodeEnv;
11831
- exports2.getOpenCodeAskEnv = getOpenCodeAskEnv;
11832
12106
  var os_1 = require("os");
11833
12107
  var constants_1 = require_constants5();
11834
- var rules_writer_12 = require_rules_writer();
11835
12108
  var experiments_1 = require_experiments();
12109
+ var rules_writer_12 = require_rules_writer();
12110
+ var environments_12 = require_environments();
11836
12111
  exports2.DEFAULT_TIMEOUT_MS = 20 * 60 * 1e3;
11837
12112
  exports2.DEFAULT_MODEL = "anthropic/claude-sonnet-4-6";
11838
12113
  var AI_PROXY_BASE_URL = process.env.CODEGEN_AI_PROXY_BASE_URL || "http://localhost:3001";
@@ -11868,7 +12143,7 @@ var require_config = __commonJS({
11868
12143
  enabled: true
11869
12144
  }
11870
12145
  };
11871
- function getOpenCodeConfig() {
12146
+ function getOpenCodeConfig(instructionPaths) {
11872
12147
  return {
11873
12148
  model: exports2.DEFAULT_MODEL,
11874
12149
  provider: getProviderConfig(),
@@ -11895,14 +12170,14 @@ var require_config = __commonJS({
11895
12170
  "/root/.opencode/**": "allow"
11896
12171
  }
11897
12172
  },
11898
- instructions: [rules_writer_12.CODEGEN_RULES_PATH],
12173
+ instructions: instructionPaths,
11899
12174
  autoupdate: false,
11900
12175
  share: "disabled",
11901
12176
  lsp: false,
11902
12177
  mcp: WIX_MCP_CONFIG
11903
12178
  };
11904
12179
  }
11905
- function getOpenCodeAskConfig() {
12180
+ function getOpenCodeAskConfig(instructionPaths) {
11906
12181
  return {
11907
12182
  model: exports2.DEFAULT_MODEL,
11908
12183
  provider: getProviderConfig(),
@@ -11929,7 +12204,7 @@ var require_config = __commonJS({
11929
12204
  /* OpenCodeTool.Uuid */
11930
12205
  ]: "deny"
11931
12206
  },
11932
- instructions: [rules_writer_12.ASK_RULES_PATH],
12207
+ instructions: instructionPaths,
11933
12208
  lsp: false,
11934
12209
  mcp: WIX_MCP_CONFIG
11935
12210
  };
@@ -11954,11 +12229,12 @@ var require_config = __commonJS({
11954
12229
  OPENCODE_DISABLE_FILETIME_CHECK: "true"
11955
12230
  };
11956
12231
  }
11957
- function getOpenCodeEnv(projectId) {
11958
- return buildOpenCodeEnv(projectId, getOpenCodeConfig());
11959
- }
11960
- function getOpenCodeAskEnv(projectId) {
11961
- 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);
11962
12238
  }
11963
12239
  }
11964
12240
  });
@@ -12902,7 +13178,7 @@ var require_executor = __commonJS({
12902
13178
  }
12903
13179
  async function logOpenCodeStats(options) {
12904
13180
  const isAsk = job_context_storage_12.jobContextStorage.getStore()?.kind === ditto_codegen_types_12.TaskKind.ASK_CODEGEN;
12905
- 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);
12906
13182
  const stats = await (0, cost_tracker_1.fetchOpenCodeStats)(options.outputPath, env);
12907
13183
  if (stats) {
12908
13184
  console.log("[OpenCode] Stats\n", stats);
@@ -12958,7 +13234,7 @@ var require_executor = __commonJS({
12958
13234
  workingDirectory: outputPath
12959
13235
  });
12960
13236
  const isAsk = job_context_storage_12.jobContextStorage.getStore()?.kind === ditto_codegen_types_12.TaskKind.ASK_CODEGEN;
12961
- const env = isAsk ? (0, config_1.getOpenCodeAskEnv)(projectId) : (0, config_1.getOpenCodeEnv)(projectId);
13237
+ const env = (0, config_1.getOpenCodeEnv)(projectId, isAsk);
12962
13238
  ctx.child = (0, child_process_1.spawn)("opencode", args, {
12963
13239
  cwd: outputPath,
12964
13240
  env,
@@ -17490,219 +17766,6 @@ var require_biEvents = __commonJS({
17490
17766
  }
17491
17767
  });
17492
17768
 
17493
- // ../../node_modules/@wix/ambassador-ctp-ditto-v1-blueprint/cjs/build/types.impl.js
17494
- var require_types_impl2 = __commonJS({
17495
- "../../node_modules/@wix/ambassador-ctp-ditto-v1-blueprint/cjs/build/types.impl.js"(exports2) {
17496
- "use strict";
17497
- Object.defineProperty(exports2, "__esModule", { value: true });
17498
- exports2.ExtensionType = void 0;
17499
- var ExtensionType;
17500
- (function(ExtensionType2) {
17501
- ExtensionType2["UNDEFINED_EXTENSION_TYPE"] = "UNDEFINED_EXTENSION_TYPE";
17502
- ExtensionType2["DASHBOARD_PAGE"] = "DASHBOARD_PAGE";
17503
- ExtensionType2["DASHBOARD_PLUGIN"] = "DASHBOARD_PLUGIN";
17504
- ExtensionType2["DASHBOARD_MODAL"] = "DASHBOARD_MODAL";
17505
- ExtensionType2["SITE_WIDGET"] = "SITE_WIDGET";
17506
- ExtensionType2["EMBEDDED_SCRIPT"] = "EMBEDDED_SCRIPT";
17507
- ExtensionType2["BACKEND_API"] = "BACKEND_API";
17508
- ExtensionType2["BACKEND_EVENT"] = "BACKEND_EVENT";
17509
- ExtensionType2["SERVICE_PLUGIN"] = "SERVICE_PLUGIN";
17510
- ExtensionType2["WEB_METHODS"] = "WEB_METHODS";
17511
- ExtensionType2["SITE_COMPONENT"] = "SITE_COMPONENT";
17512
- ExtensionType2["WEBHOOK"] = "WEBHOOK";
17513
- ExtensionType2["SITE_PLUGIN"] = "SITE_PLUGIN";
17514
- ExtensionType2["DATA_COLLECTION"] = "DATA_COLLECTION";
17515
- ExtensionType2["DASHBOARD_MENU_PLUGIN"] = "DASHBOARD_MENU_PLUGIN";
17516
- ExtensionType2["CUSTOM_ELEMENT_WIDGET"] = "CUSTOM_ELEMENT_WIDGET";
17517
- ExtensionType2["EDITOR_REACT_COMPONENT"] = "EDITOR_REACT_COMPONENT";
17518
- })(ExtensionType || (exports2.ExtensionType = ExtensionType = {}));
17519
- }
17520
- });
17521
-
17522
- // dist/job-decision-manager.js
17523
- var require_job_decision_manager = __commonJS({
17524
- "dist/job-decision-manager.js"(exports2) {
17525
- "use strict";
17526
- Object.defineProperty(exports2, "__esModule", { value: true });
17527
- exports2.UserDecisionCancelledError = void 0;
17528
- exports2.pauseForUserDecision = pauseForUserDecision;
17529
- exports2.askJobChoice = askJobChoice;
17530
- exports2.askJobConfirmation = askJobConfirmation;
17531
- var types_1 = require_types_impl();
17532
- var codeGenerationService_12 = require_codeGenerationService();
17533
- var CodeGenService_12 = require_CodeGenService();
17534
- var logger_12 = require_logger();
17535
- var DECISION_POLL_INTERVAL_MS = 2e3;
17536
- var UserDecisionCancelledError = class extends Error {
17537
- constructor(jobId, decisionId) {
17538
- super(`User decision ${decisionId} cancelled for job ${jobId}`);
17539
- this.jobId = jobId;
17540
- this.decisionId = decisionId;
17541
- this.name = "UserDecisionCancelledError";
17542
- }
17543
- };
17544
- exports2.UserDecisionCancelledError = UserDecisionCancelledError;
17545
- async function pauseForUserDecision(jobId, request) {
17546
- const decisionId = crypto.randomUUID();
17547
- const userDecision = {
17548
- id: decisionId,
17549
- request: {
17550
- ...request,
17551
- requestedAt: /* @__PURE__ */ new Date()
17552
- }
17553
- };
17554
- await codeGenerationService_12.codeGenerationService.updateJobWithPendingDecision(jobId, userDecision);
17555
- logger_12.logger.info("[JobDecision] Paused for user input", {
17556
- question: request.question
17557
- });
17558
- const startTime = Date.now();
17559
- const response = await pollForJobDecisionResponse(jobId, decisionId);
17560
- const durationMs = Date.now() - startTime;
17561
- await codeGenerationService_12.codeGenerationService.resumeJobFromDecision(jobId);
17562
- logger_12.logger.info("[JobDecision] Resumed after user decision", {
17563
- selectedOptionId: response.selectedOptionId,
17564
- durationMs
17565
- });
17566
- return response;
17567
- }
17568
- async function pollForJobDecisionResponse(jobId, decisionId) {
17569
- logger_12.logger.info("[JobDecision] Polling for user decision response", {
17570
- decisionId
17571
- });
17572
- while (true) {
17573
- const job = await codeGenerationService_12.codeGenerationService.getJob(jobId);
17574
- if (!job) {
17575
- throw new Error(`Job ${jobId} not found`);
17576
- }
17577
- if (job.status === CodeGenService_12.Status.CANCELLED || job.status === CodeGenService_12.Status.PENDING_CANCEL) {
17578
- logger_12.logger.warn("[JobDecision] Job cancelled while waiting for user decision", { decisionId });
17579
- throw new UserDecisionCancelledError(jobId, decisionId);
17580
- }
17581
- const decision = job.pendingUserDecisions?.find((d) => d.id === decisionId) ?? job.userDecisionHistory?.find((d) => d.id === decisionId);
17582
- if (decision?.response?.selectedOptionId) {
17583
- return {
17584
- selectedOptionId: decision.response.selectedOptionId,
17585
- respondedAt: decision.response.respondedAt ?? /* @__PURE__ */ new Date()
17586
- };
17587
- }
17588
- await new Promise((resolve) => setTimeout(resolve, DECISION_POLL_INTERVAL_MS));
17589
- }
17590
- }
17591
- async function askJobChoice(jobId, question, options, context) {
17592
- const response = await pauseForUserDecision(jobId, {
17593
- question,
17594
- questionType: types_1.UserDecisionQuestionType.UI_COMPONENT_TYPE,
17595
- options,
17596
- context
17597
- });
17598
- if (!response.selectedOptionId) {
17599
- throw new Error("No option selected in user decision response");
17600
- }
17601
- return response.selectedOptionId;
17602
- }
17603
- async function askJobConfirmation(jobId, question, context) {
17604
- const response = await pauseForUserDecision(jobId, {
17605
- question,
17606
- questionType: types_1.UserDecisionQuestionType.UI_COMPONENT_TYPE,
17607
- options: [
17608
- { id: "yes", label: "Yes" },
17609
- { id: "no", label: "No" }
17610
- ],
17611
- context
17612
- });
17613
- return response.selectedOptionId === "yes";
17614
- }
17615
- }
17616
- });
17617
-
17618
- // dist/pre-run-decision.js
17619
- var require_pre_run_decision = __commonJS({
17620
- "dist/pre-run-decision.js"(exports2) {
17621
- "use strict";
17622
- Object.defineProperty(exports2, "__esModule", { value: true });
17623
- exports2.runPreDecisionCheck = runPreDecisionCheck;
17624
- exports2.checkSiteUIDecision = checkSiteUIDecision;
17625
- var types_1 = require_types_impl2();
17626
- var job_decision_manager_1 = require_job_decision_manager();
17627
- var logger_12 = require_logger();
17628
- async function runPreDecisionCheck(jobId, context, checkers) {
17629
- const allDecisions = [];
17630
- let modifiedBlueprint = context.blueprint;
17631
- for (const checker of checkers) {
17632
- const result = await checker(jobId, {
17633
- blueprint: modifiedBlueprint
17634
- });
17635
- if (result) {
17636
- allDecisions.push(...result.decisionsApplied);
17637
- if (result.modifiedBlueprint) {
17638
- modifiedBlueprint = result.modifiedBlueprint;
17639
- }
17640
- }
17641
- }
17642
- return {
17643
- decisionsApplied: allDecisions,
17644
- modifiedBlueprint
17645
- };
17646
- }
17647
- async function checkSiteUIDecision(jobId, context) {
17648
- const extensions = context.blueprint?.extensions ?? [];
17649
- const siteUIExtension = extensions.find((ext) => isSiteUIExtension(ext));
17650
- if (!siteUIExtension?.name) {
17651
- return null;
17652
- }
17653
- const extensionName = siteUIExtension.name;
17654
- const currentType = siteUIExtension.type;
17655
- logger_12.logger.info(`[PreDecision] Found site UI extension: "${extensionName}" (current type: ${currentType})`);
17656
- const options = [
17657
- {
17658
- id: types_1.ExtensionType.SITE_WIDGET,
17659
- label: "Custom Element Widget",
17660
- description: "A self-contained widget built as a Custom Element, embedded on the site. Best for standalone, reusable components."
17661
- },
17662
- {
17663
- id: types_1.ExtensionType.SITE_COMPONENT,
17664
- label: "Editor React Component",
17665
- description: "A React component that integrates with the site builder. Best for components that need to work with Wix editor features."
17666
- }
17667
- ];
17668
- 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.");
17669
- const selectedLabel = options.find((o) => o.id === selectedType)?.label ?? selectedType;
17670
- const isTypeChanged = selectedType !== currentType;
17671
- logger_12.logger.info(`[PreDecision] User selected ${selectedType} for "${extensionName}"${isTypeChanged ? ` (changed from ${currentType})` : " (unchanged)"}`);
17672
- const appliedDecision = {
17673
- type: "SITE_UI_TYPE",
17674
- question: "Custom Element Widget vs Editor React Component",
17675
- selectedOptionId: selectedType
17676
- };
17677
- return {
17678
- decisionsApplied: [appliedDecision],
17679
- modifiedBlueprint: context.blueprint ? applyTypeToBlueprint(context.blueprint, extensionName, selectedType, selectedLabel) : void 0
17680
- };
17681
- }
17682
- function isSiteUIExtension(extension) {
17683
- return extension.type === types_1.ExtensionType.SITE_WIDGET || extension.type === types_1.ExtensionType.SITE_COMPONENT;
17684
- }
17685
- function applyTypeToBlueprint(blueprint, extensionName, type, label) {
17686
- 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.`;
17687
- const descriptionNotice = `[USER DECISION] This extension MUST be a ${label} (type: ${type}). The user explicitly chose this. Do NOT change it.`;
17688
- return {
17689
- ...blueprint,
17690
- summary: `${summaryNotice}
17691
-
17692
- ${blueprint.summary ?? ""}`.trim(),
17693
- extensions: blueprint.extensions?.map((ext) => ext.name === extensionName ? {
17694
- ...ext,
17695
- type,
17696
- description: `${descriptionNotice}
17697
-
17698
- ${ext.description ?? ""}`.trim(),
17699
- _userDecision: "IMPORTANT: The user explicitly chose this extension type. You MUST use this exact type."
17700
- } : ext)
17701
- };
17702
- }
17703
- }
17704
- });
17705
-
17706
17769
  // dist/flows/opencode-init.js
17707
17770
  var require_opencode_init = __commonJS({
17708
17771
  "dist/flows/opencode-init.js"(exports2) {
@@ -17722,6 +17785,7 @@ var require_opencode_init = __commonJS({
17722
17785
  var biEvents_1 = require_biEvents();
17723
17786
  var pre_run_decision_1 = require_pre_run_decision();
17724
17787
  var experiments_1 = require_experiments();
17788
+ var environments_12 = require_environments();
17725
17789
  var runOpencodeInitFlow = async (blueprint, history) => {
17726
17790
  const store = job_context_storage_12.jobContextStorage.getStore();
17727
17791
  if (!store?.jobId || !store?.taskId) {
@@ -17749,8 +17813,9 @@ var require_opencode_init = __commonJS({
17749
17813
  const outputPath = (0, codegen_flow_helpers_12.getOutputPath)();
17750
17814
  let finalBlueprint = blueprint;
17751
17815
  if ((0, experiments_1.isUserDecisionsEnabled)()) {
17752
- const preDecisionResult = await (0, pre_run_decision_1.runPreDecisionCheck)(localJobContext.jobId, { blueprint }, [pre_run_decision_1.checkSiteUIDecision]);
17753
- 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;
17754
17819
  if (preDecisionResult.decisionsApplied.length > 0) {
17755
17820
  logger_12.logger.info("[OpenCode Init] Applied pre-decision", {
17756
17821
  decisions: preDecisionResult.decisionsApplied,
@@ -18391,6 +18456,7 @@ var logger_1 = require_logger();
18391
18456
  var skills_installer_1 = require_skills_installer();
18392
18457
  var rules_writer_1 = require_rules_writer();
18393
18458
  var tools_writer_1 = require_tools_writer();
18459
+ var environments_1 = require_environments();
18394
18460
  var sessionId = process.env.CODEGEN_SESSION_ID || (0, crypto_1.randomUUID)();
18395
18461
  process.env.CODEGEN_SESSION_ID = sessionId;
18396
18462
  (0, logger_1.initLogger)(sessionId);
@@ -18437,9 +18503,11 @@ var alwaysOnLoop = async () => {
18437
18503
  }
18438
18504
  };
18439
18505
  async function initOpenCode() {
18506
+ const envConfig = (0, environments_1.getCodegenEnvironmentConfig)();
18440
18507
  await Promise.all([
18508
+ (0, rules_writer_1.writeRuleFiles)(envConfig.codegenRules),
18509
+ (0, rules_writer_1.writeRuleFiles)(envConfig.askRules),
18441
18510
  (0, skills_installer_1.installSkills)((0, codegen_flow_helpers_1.getOutputPath)(), logger_1.logger),
18442
- (0, rules_writer_1.writeRuleFiles)(),
18443
18511
  (0, tools_writer_1.writeToolFiles)()
18444
18512
  ]);
18445
18513
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/ditto-codegen-public",
3
- "version": "1.0.298",
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": "0f1ec70edca7d80ecbbd7fb2f50b89252a05883a7ce6db68591583d7"
30
+ "falconPackageHash": "a01dca5cf215678ea67a1d956dd4f31273b544e5b2fd4bf54bc84ca0"
31
31
  }