@wix/ditto-codegen-public 1.0.517 → 1.0.519

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.
@@ -0,0 +1,387 @@
1
+ import { execFile } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import {
4
+ mkdir,
5
+ mkdtemp,
6
+ readFile,
7
+ realpath,
8
+ writeFile,
9
+ } from "node:fs/promises";
10
+ import { join, parse, resolve, sep } from "node:path";
11
+ import { setTimeout as sleep } from "node:timers/promises";
12
+ import { promisify } from "node:util";
13
+ import { tool } from "@opencode-ai/plugin";
14
+
15
+ const execFileAsync = promisify(execFile);
16
+
17
+ const MEDIA_FILES_API = "https://www.wixapis.com/site-media/v1/files";
18
+ const WORK_DIR = "/tmp/user-images";
19
+ const INSTALL_TIMEOUT_MS = 180_000;
20
+ const CHILD_TIMEOUT_MS = 120_000;
21
+ const UPLOAD_TIMEOUT_MS = 120_000;
22
+ const IMPORT_POLL_MS = 1_000;
23
+ const IMPORT_TIMEOUT_MS = 30_000;
24
+ const IMAGE_ENV = {
25
+ PATH: "/usr/local/bin:/usr/bin:/bin",
26
+ HOME: WORK_DIR,
27
+ TMPDIR: WORK_DIR,
28
+ LANG: process.env.LANG ?? "C.UTF-8",
29
+ };
30
+ const CROP =
31
+ /^(\d+(?:\.\d+)?)%,(\d+(?:\.\d+)?)%,(\d+(?:\.\d+)?)%,(\d+(?:\.\d+)?)%$/;
32
+
33
+ interface Image {
34
+ source?: string;
35
+ crop?: string;
36
+ render?: { file: string; export: string; args: unknown[] };
37
+ }
38
+
39
+ const CHILD_SOURCE = String.raw`
40
+ const fs = require("fs");
41
+ const { createRequire } = require("module");
42
+ const load = createRequire(__filename);
43
+ const [mode, input, output, ...rest] = process.argv.slice(2);
44
+
45
+ async function crop() {
46
+ const sharp = load("sharp");
47
+ const image = sharp(input).autoOrient();
48
+ const { autoOrient: { width, height } } = await image.metadata();
49
+ const [left, top, w, h] = rest.map(Number);
50
+ const x = Math.round((left / 100) * width);
51
+ const y = Math.round((top / 100) * height);
52
+ const area = {
53
+ left: x,
54
+ top: y,
55
+ width: Math.min(Math.round((w / 100) * width), width - x),
56
+ height: Math.min(Math.round((h / 100) * height), height - y),
57
+ };
58
+ fs.writeFileSync(output, await image.extract(area).webp({ quality: 90 }).toBuffer());
59
+ }
60
+
61
+ async function render() {
62
+ const canvas = load("@napi-rs/canvas");
63
+ const esbuild = load("esbuild");
64
+ globalThis.window = globalThis;
65
+ globalThis.devicePixelRatio = 1;
66
+ globalThis.document = {
67
+ hidden: false,
68
+ createElement(tag) {
69
+ if (String(tag).toLowerCase() !== "canvas") {
70
+ throw new Error("document.createElement('" + tag + "') isn't available while rendering");
71
+ }
72
+ return canvas.createCanvas(300, 150);
73
+ },
74
+ };
75
+ globalThis.OffscreenCanvas = class {
76
+ constructor(width, height) {
77
+ return canvas.createCanvas(width, height);
78
+ }
79
+ };
80
+ globalThis.Image = canvas.Image;
81
+ const [exportName, args] = rest;
82
+ const bundle = esbuild.buildSync({
83
+ entryPoints: [input],
84
+ bundle: true,
85
+ write: false,
86
+ platform: "node",
87
+ format: "cjs",
88
+ logLevel: "silent",
89
+ });
90
+ const module = { exports: {} };
91
+ new Function("module", "exports", "require", bundle.outputFiles[0].text)(
92
+ module,
93
+ module.exports,
94
+ createRequire(input),
95
+ );
96
+ const paint = module.exports[exportName];
97
+ if (typeof paint !== "function") throw new Error(input + ' exports no function "' + exportName + '"');
98
+ const result = await paint(...JSON.parse(args));
99
+ const dataUrl = typeof result === "string" && /^data:image\/[\w+.-]+;base64,(.*)$/s.exec(result);
100
+ if (dataUrl) return fs.writeFileSync(output, Buffer.from(dataUrl[1], "base64"));
101
+ if (typeof result?.toBuffer === "function") return fs.writeFileSync(output, result.toBuffer("image/png"));
102
+ throw new Error("The function returned neither a data:image URL nor a canvas");
103
+ }
104
+
105
+ (mode === "crop" ? crop() : render()).catch((error) => {
106
+ console.error(error.message);
107
+ process.exit(1);
108
+ });
109
+ `;
110
+
111
+ function imageType(bytes: Buffer): { mimeType: string; extension: string } {
112
+ const ascii = (start: number, end: number) =>
113
+ bytes.subarray(start, end).toString("latin1");
114
+ if (bytes[0] === 0x89 && ascii(1, 4) === "PNG")
115
+ return { mimeType: "image/png", extension: ".png" };
116
+ if (bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff)
117
+ return { mimeType: "image/jpeg", extension: ".jpg" };
118
+ if (ascii(0, 4) === "RIFF" && ascii(8, 12) === "WEBP")
119
+ return { mimeType: "image/webp", extension: ".webp" };
120
+ if (ascii(0, 4) === "GIF8")
121
+ return { mimeType: "image/gif", extension: ".gif" };
122
+ if (ascii(4, 12) === "ftypavif")
123
+ return { mimeType: "image/avif", extension: ".avif" };
124
+ throw new Error("Not a PNG, JPEG, WebP, GIF or AVIF image");
125
+ }
126
+
127
+ function cropPercents(crop: string): string[] {
128
+ const match = CROP.exec(crop.replace(/\s+/g, ""));
129
+ const [left, top, width, height] = (match ?? []).slice(1).map(Number);
130
+ if (!match || !width || !height || left + width > 100 || top + height > 100) {
131
+ throw new Error(
132
+ `Invalid crop "${crop}"; use left,top,width,height in % inside the image`,
133
+ );
134
+ }
135
+ return match.slice(1);
136
+ }
137
+
138
+ async function install(packages: string[]): Promise<void> {
139
+ const missing = packages.filter(
140
+ (name) => !existsSync(join(WORK_DIR, "node_modules", name, "package.json")),
141
+ );
142
+ if (missing.length === 0) return;
143
+ await execFileAsync(
144
+ "npm",
145
+ [
146
+ "install",
147
+ "--prefix",
148
+ WORK_DIR,
149
+ "--no-save",
150
+ "--no-audit",
151
+ "--no-fund",
152
+ "--loglevel=error",
153
+ ...missing,
154
+ ],
155
+ { cwd: WORK_DIR, env: IMAGE_ENV, timeout: INSTALL_TIMEOUT_MS },
156
+ );
157
+ }
158
+
159
+ async function runChild(args: string[], output: string): Promise<Buffer> {
160
+ const script = join(WORK_DIR, "media-child.cjs");
161
+ await writeFile(script, CHILD_SOURCE);
162
+ try {
163
+ await execFileAsync("node", [script, ...args], {
164
+ cwd: WORK_DIR,
165
+ env: IMAGE_ENV,
166
+ timeout: CHILD_TIMEOUT_MS,
167
+ });
168
+ } catch (error) {
169
+ const { stderr, message } = error as { stderr?: string; message: string };
170
+ throw new Error(stderr?.trim().split("\n").pop() || message);
171
+ }
172
+ return readFile(output);
173
+ }
174
+
175
+ async function allowedFile(directory: string, file: string): Promise<string> {
176
+ const path = await realpath(resolve(directory, file));
177
+ const roots = await Promise.all(
178
+ [directory, WORK_DIR].map((root) => realpath(root)),
179
+ );
180
+ if (!roots.some((root) => path.startsWith(root + sep)))
181
+ throw new Error(`${file} is outside the project and ${WORK_DIR}`);
182
+ return path;
183
+ }
184
+
185
+ async function imageBytes(
186
+ image: Image,
187
+ directory: string,
188
+ output: string,
189
+ ): Promise<Buffer> {
190
+ if (image.render) {
191
+ const { file, export: exportName, args } = image.render;
192
+ await install(["@napi-rs/canvas", "esbuild"]);
193
+ return runChild(
194
+ [
195
+ "render",
196
+ await allowedFile(directory, file),
197
+ output,
198
+ exportName,
199
+ JSON.stringify(args),
200
+ ],
201
+ output,
202
+ );
203
+ }
204
+ if (!image.source) throw new Error("Give each image a source or a render");
205
+ const source = await allowedFile(directory, image.source);
206
+ if (!image.crop) return readFile(source);
207
+ const percents = cropPercents(image.crop);
208
+ await install(["sharp"]);
209
+ return runChild(["crop", source, output, ...percents], output);
210
+ }
211
+
212
+ async function httpError(step: string, response: Response): Promise<Error> {
213
+ const body = (await response.text()).slice(0, 300);
214
+ return new Error(`${step} failed, HTTP ${response.status}: ${body}`);
215
+ }
216
+
217
+ async function mediaFile(
218
+ step: string,
219
+ response: Response,
220
+ ): Promise<{ uri: string; url: string }> {
221
+ if (!response.ok) throw await httpError(step, response);
222
+ const { file } = (await response.json()) as {
223
+ file?: { id?: string; url?: string };
224
+ };
225
+ if (!file?.id || !file.url)
226
+ throw new Error(`${step} response has no file id or url`);
227
+ return { uri: file.id, url: file.url };
228
+ }
229
+
230
+ function postMedia(
231
+ path: string,
232
+ body: object,
233
+ token: string,
234
+ signal?: AbortSignal,
235
+ ) {
236
+ return fetch(`${MEDIA_FILES_API}/${path}`, {
237
+ method: "POST",
238
+ headers: { Authorization: token, "Content-Type": "application/json" },
239
+ body: JSON.stringify(body),
240
+ signal,
241
+ });
242
+ }
243
+
244
+ async function upload(bytes: Buffer, name: string, token: string) {
245
+ const { mimeType, extension } = imageType(bytes);
246
+ const fileName = `${name.replace(/[^a-z0-9]+/gi, "-").replace(/^-|-$/g, "") || "image"}${extension}`;
247
+ const signal = AbortSignal.timeout(UPLOAD_TIMEOUT_MS);
248
+ const generated = await postMedia(
249
+ "generate-upload-url",
250
+ { mimeType, fileName },
251
+ token,
252
+ signal,
253
+ );
254
+ if (!generated.ok)
255
+ throw await httpError("Generate File Upload URL", generated);
256
+ const { uploadUrl } = (await generated.json()) as { uploadUrl: string };
257
+ const uploaded = await fetch(
258
+ `${uploadUrl}?filename=${encodeURIComponent(fileName)}`,
259
+ {
260
+ method: "PUT",
261
+ headers: { "Content-Type": mimeType },
262
+ body: bytes,
263
+ signal,
264
+ },
265
+ );
266
+ return mediaFile("Upload", uploaded);
267
+ }
268
+
269
+ // Import File answers while the file is still PENDING; wait until Wix has it.
270
+ async function importFile(url: string, token: string) {
271
+ const signal = AbortSignal.timeout(IMPORT_TIMEOUT_MS);
272
+ const file = await mediaFile(
273
+ "Import File",
274
+ await postMedia("import", { url, mediaType: "IMAGE" }, token, signal),
275
+ );
276
+ while (!signal.aborted) {
277
+ const response = await fetch(
278
+ `${MEDIA_FILES_API}/get-file-by-id?fileId=${encodeURIComponent(file.uri)}`,
279
+ { headers: { Authorization: token }, signal },
280
+ );
281
+ if (!response.ok) throw await httpError("Get File Descriptor", response);
282
+ const { file: descriptor } = (await response.json()) as {
283
+ file?: { operationStatus?: string };
284
+ };
285
+ if (descriptor?.operationStatus === "READY") return file;
286
+ if (descriptor?.operationStatus === "FAILED")
287
+ throw new Error("Wix could not import the image from this URL");
288
+ await sleep(IMPORT_POLL_MS, undefined, { signal });
289
+ }
290
+ throw new Error(
291
+ `Wix did not finish importing the image in ${IMPORT_TIMEOUT_MS / 1000} s`,
292
+ );
293
+ }
294
+
295
+ async function uploadImage(
296
+ image: Image,
297
+ directory: string,
298
+ output: string,
299
+ token: string,
300
+ ) {
301
+ if (image.source && /^https?:\/\//i.test(image.source)) {
302
+ if (image.crop) throw new Error("Only a file source can be cropped");
303
+ return importFile(image.source, token);
304
+ }
305
+ const name = image.render?.export ?? parse(image.source ?? "").name;
306
+ return upload(await imageBytes(image, directory, output), name, token);
307
+ }
308
+
309
+ async function getWixAccessToken(): Promise<string> {
310
+ const { stdout } = await execFileAsync("wix", ["token", "--json"], {
311
+ timeout: 30_000,
312
+ });
313
+ const { accessToken } = JSON.parse(stdout) as { accessToken?: string };
314
+ if (!accessToken) throw new Error("wix token returned empty accessToken");
315
+ return accessToken;
316
+ }
317
+
318
+ export default tool({
319
+ description:
320
+ "Upload images to the site's Media Manager and get the `{ uri, url }` an `Image` default needs. " +
321
+ "Each image is a project file or an image URL (`source`), a file optionally cropped to a region (`crop`), " +
322
+ "or an image the user's code paints (`render`). Returns one result per image, in order: " +
323
+ "`image` when it uploaded, `error` when it didn't, and for a crop the cropped `file` to look at.",
324
+ args: {
325
+ images: tool.schema
326
+ .array(
327
+ tool.schema.object({
328
+ source: tool.schema
329
+ .string()
330
+ .optional()
331
+ .describe(
332
+ "A project-relative file path (attachments under .wix/agentInput/attachments/ too) or an image URL.",
333
+ ),
334
+ crop: tool.schema
335
+ .string()
336
+ .optional()
337
+ .describe(
338
+ "Crop a file `source` first: `left,top,width,height` in % of the image, e.g. `0%,12%,25%,74%`.",
339
+ ),
340
+ render: tool.schema
341
+ .object({
342
+ file: tool.schema
343
+ .string()
344
+ .describe("The project file that exports the painter."),
345
+ export: tool.schema
346
+ .string()
347
+ .describe("The painter's export name."),
348
+ args: tool.schema
349
+ .array(tool.schema.unknown())
350
+ .describe("The painter's arguments for this image."),
351
+ })
352
+ .optional()
353
+ .describe(
354
+ "Paint the image with the user's function, which returns a data:image URL or a canvas.",
355
+ ),
356
+ }),
357
+ )
358
+ .min(1),
359
+ },
360
+ async execute({ images }, context) {
361
+ let token: string;
362
+ try {
363
+ token = await getWixAccessToken();
364
+ } catch (error) {
365
+ const message = `Could not get a Wix token: ${(error as Error).message}`;
366
+ return JSON.stringify(
367
+ images.map((image) => ({ ...image, error: message })),
368
+ );
369
+ }
370
+ await mkdir(WORK_DIR, { recursive: true });
371
+ const folder = await mkdtemp(join(WORK_DIR, "upload-"));
372
+ const results = [];
373
+ for (const [index, image] of images.entries()) {
374
+ const output = join(folder, `image-${index + 1}`);
375
+ try {
376
+ results.push({
377
+ ...image,
378
+ ...(image.crop ? { file: output } : {}),
379
+ image: await uploadImage(image, context.directory, output, token),
380
+ });
381
+ } catch (error) {
382
+ results.push({ ...image, error: (error as Error).message });
383
+ }
384
+ }
385
+ return JSON.stringify(results);
386
+ },
387
+ });
package/dist/out.js CHANGED
@@ -10523,6 +10523,7 @@ var require_logger = __commonJS({
10523
10523
  }
10524
10524
  exports2.logger = (() => {
10525
10525
  const environment = process.env.CODEGEN_ENVIRONMENT;
10526
+ const siteEditor = process.env.SITE_EDITOR;
10526
10527
  const modelOverride = process.env.CODEGEN_MODEL_OVERRIDE;
10527
10528
  const smallModelOverride = process.env.CODEGEN_SMALL_MODEL_OVERRIDE;
10528
10529
  const getContextLogger = () => {
@@ -10531,6 +10532,7 @@ var require_logger = __commonJS({
10531
10532
  ...jobId ? { jobId } : {},
10532
10533
  ...metasiteId ? { metasiteId } : {},
10533
10534
  ...environment ? { environment } : {},
10535
+ ...siteEditor ? { siteEditor } : {},
10534
10536
  ...modelOverride ? { modelOverride } : {},
10535
10537
  ...smallModelOverride ? { smallModelOverride } : {}
10536
10538
  };
@@ -13081,6 +13083,35 @@ ${STUDIO_2_SITE_UI_ROUTING}`
13081
13083
  }
13082
13084
  });
13083
13085
 
13086
+ // ../codegen-common-logic/dist/tool-policies/harmony.js
13087
+ var require_harmony = __commonJS({
13088
+ "../codegen-common-logic/dist/tool-policies/harmony.js"(exports2) {
13089
+ "use strict";
13090
+ Object.defineProperty(exports2, "__esModule", { value: true });
13091
+ exports2.HARMONY_CC_POLICIES = exports2.HARMONY_SKILL_ROUTING_POLICY = exports2.HARMONY_GENERATE_POLICY = exports2.HARMONY_ALLOWED_EXTENSION_TYPES = void 0;
13092
+ var studio_2_1 = require_studio_2();
13093
+ exports2.HARMONY_ALLOWED_EXTENSION_TYPES = ["EDITOR_REACT_COMPONENT"];
13094
+ exports2.HARMONY_GENERATE_POLICY = {
13095
+ type: "generate",
13096
+ allowedExtensionTypes: exports2.HARMONY_ALLOWED_EXTENSION_TYPES,
13097
+ message: `BLOCKED: this host only supports Editor React Components. Build the request as an Editor React Component (extensionType: EDITOR_REACT_COMPONENT) instead. Do not retry with another extension type.`
13098
+ };
13099
+ exports2.HARMONY_SKILL_ROUTING_POLICY = {
13100
+ type: "skillContent",
13101
+ skillNames: ["wix-app"],
13102
+ message: `ENVIRONMENT OVERRIDE: this skill's extension-type routing does not apply in this environment. Every artifact in this host is an Editor React Component (\`extensionType: EDITOR_REACT_COMPONENT\`); pages, lightboxes, site plugins, custom elements and every other extension type are unavailable, even if the prompt asks for one.`
13103
+ };
13104
+ exports2.HARMONY_CC_POLICIES = [
13105
+ studio_2_1.CUSTOM_ELEMENT_REFERENCES_POLICY,
13106
+ exports2.HARMONY_SKILL_ROUTING_POLICY,
13107
+ studio_2_1.STUDIO_2_PREVIEW_RELEASE_POLICY,
13108
+ studio_2_1.STUDIO_2_CUSTOM_ELEMENT_GENERATE_POLICY,
13109
+ studio_2_1.STUDIO_2_BRANDED_COMPONENTS_POLICY,
13110
+ exports2.HARMONY_GENERATE_POLICY
13111
+ ];
13112
+ }
13113
+ });
13114
+
13084
13115
  // ../codegen-common-logic/dist/tool-policies/index.js
13085
13116
  var require_tool_policies2 = __commonJS({
13086
13117
  "../codegen-common-logic/dist/tool-policies/index.js"(exports2) {
@@ -13104,6 +13135,7 @@ var require_tool_policies2 = __commonJS({
13104
13135
  Object.defineProperty(exports2, "__esModule", { value: true });
13105
13136
  __exportStar2(require_site(), exports2);
13106
13137
  __exportStar2(require_studio_2(), exports2);
13138
+ __exportStar2(require_harmony(), exports2);
13107
13139
  }
13108
13140
  });
13109
13141
 
@@ -14147,7 +14179,7 @@ var require_dist8 = __commonJS({
14147
14179
  "../codegen-studio-2-config/dist/index.js"(exports2) {
14148
14180
  "use strict";
14149
14181
  Object.defineProperty(exports2, "__esModule", { value: true });
14150
- exports2.studio2CodegenConfig = void 0;
14182
+ exports2.harmonyCodegenConfig = exports2.studio2CodegenConfig = void 0;
14151
14183
  var ditto_codegen_types_12 = require_dist4();
14152
14184
  var codegen_checkpoint_plugin_1 = require_dist7();
14153
14185
  var codegen_common_logic_1 = require_dist5();
@@ -14191,6 +14223,10 @@ var require_dist8 = __commonJS({
14191
14223
  moduleSpecifierPrefix: ditto_codegen_types_12.COMPANION_APP_MODULE_SPECIFIER_PREFIX,
14192
14224
  requiredPermissions: false
14193
14225
  };
14226
+ exports2.harmonyCodegenConfig = {
14227
+ ...exports2.studio2CodegenConfig,
14228
+ toolPolicies: [...codegen_common_logic_1.SITE_POLICIES, ...codegen_common_logic_1.HARMONY_CC_POLICIES]
14229
+ };
14194
14230
  }
14195
14231
  });
14196
14232
 
@@ -14374,7 +14410,7 @@ ${permissions.toolRule}${(0, shared_rules_1.buildFileOperationsRules)("fixing ty
14374
14410
  - NEVER write a Wix SDK method, field, or enum value you haven't seen in a skill or a method schema.
14375
14411
  - \`report-wix-feedback\` \u2014 report problems with the Wix docs (dev.wix.com, via wix-mcp) or the wix-mcp tools to Wix (when: workflow step ${permissions.reportDocsStep}). NOT for skill references or your own code.
14376
14412
  - NEVER run preview, dev, release, or promote commands.
14377
- - The ONE exception to YOUR BOUNDARIES' ban on uploading files: when the \`wix-app\` skill tells you to run its \`upload-media.cjs\` script, run it. It puts the user's images into the site's Media Manager and prints the \`{ uri, url }\` an \`Image\` default needs, which makes it part of writing code. Run no other script that changes the site \u2014 publishing, releasing, deleting, and every other product/platform action stay off-limits.
14413
+ - The ONE exception to YOUR BOUNDARIES' ban on uploading files: when you have the \`upload-media\` tool, upload with it every image the \`wix-app\` skill tells you to upload, also where the skill says to run its \`upload-media.cjs\` script. It puts the user's images into the site's Media Manager and returns the \`{ uri, url }\` an \`Image\` default needs, which makes it part of writing code. When the user asks to crop or render an image, its default is the \`{ uri, url }\` the tool returns, even when the request names an uploaded copy of the original. Never run that script or any other script that changes the site \u2014 publishing, releasing, deleting, and every other product/platform action stay off-limits.
14378
14414
 
14379
14415
  KNOWN WIX APIS (already documented \u2014 do NOT rediscover these from node_modules; for full detail consult the \`wix-app\` skill's references or \`ReadFullDocsMethodSchema\`):
14380
14416
  - Wix Data items CRUD: \`import { items } from "@wix/data"\` \u2014 \`items.query(collectionId)\`, \`items.get\`, \`items.insert\`, \`items.update\` (replaces the WHOLE item \u2014 send all fields), \`items.remove\`.
@@ -14564,6 +14600,28 @@ var require_telemetry_tools = __commonJS({
14564
14600
  }
14565
14601
  });
14566
14602
 
14603
+ // dist/opencode-integration/upload-media-tool.js
14604
+ var require_upload_media_tool = __commonJS({
14605
+ "dist/opencode-integration/upload-media-tool.js"(exports2) {
14606
+ "use strict";
14607
+ Object.defineProperty(exports2, "__esModule", { value: true });
14608
+ exports2.uploadMediaToolPluginFactory = void 0;
14609
+ var fs_1 = require("fs");
14610
+ var path_12 = require("path");
14611
+ var install_manifest_1 = require_install_manifest();
14612
+ var uploadMediaToolPluginFactory = () => ({
14613
+ name: "upload-media",
14614
+ tools: [
14615
+ {
14616
+ filename: "upload-media.ts",
14617
+ source: (0, fs_1.readFileSync)((0, path_12.join)(install_manifest_1.OPENCODE_TOOLS_DIR, "env-tools", "upload-media.ts"), "utf-8")
14618
+ }
14619
+ ]
14620
+ });
14621
+ exports2.uploadMediaToolPluginFactory = uploadMediaToolPluginFactory;
14622
+ }
14623
+ });
14624
+
14567
14625
  // dist/jobs/job-decision-manager.js
14568
14626
  var require_job_decision_manager = __commonJS({
14569
14627
  "dist/jobs/job-decision-manager.js"(exports2) {
@@ -14655,6 +14713,7 @@ var require_environments = __commonJS({
14655
14713
  var git_conflicts_rules_1 = require_git_conflicts_rules();
14656
14714
  var install_manifest_1 = require_install_manifest();
14657
14715
  var telemetry_tools_1 = require_telemetry_tools();
14716
+ var upload_media_tool_1 = require_upload_media_tool();
14658
14717
  var model_knobs_1 = require_model_knobs();
14659
14718
  var job_decision_manager_1 = require_job_decision_manager();
14660
14719
  var logger_12 = require_logger();
@@ -14700,11 +14759,17 @@ var require_environments = __commonJS({
14700
14759
  function getCodegenEnvironmentConfig() {
14701
14760
  const environment = getValidatedCodegenEnvironment();
14702
14761
  switch (environment) {
14703
- case types_1.Environment.STUDIO_2:
14762
+ case types_1.Environment.STUDIO_2: {
14763
+ const siteConfig = process.env.SITE_EDITOR === "harmony" ? codegen_studio_2_config_1.harmonyCodegenConfig : codegen_studio_2_config_1.studio2CodegenConfig;
14704
14764
  return withSharedRules({
14705
- ...codegen_studio_2_config_1.studio2CodegenConfig,
14706
- plugins: [...codegen_studio_2_config_1.studio2CodegenConfig.plugins, telemetry_tools_1.telemetryToolsPluginFactory]
14765
+ ...siteConfig,
14766
+ plugins: [
14767
+ ...siteConfig.plugins,
14768
+ telemetry_tools_1.telemetryToolsPluginFactory,
14769
+ upload_media_tool_1.uploadMediaToolPluginFactory
14770
+ ]
14707
14771
  });
14772
+ }
14708
14773
  case types_1.Environment.APP_BUILDER:
14709
14774
  return withSharedRules({
14710
14775
  ...codegen_app_builder_config_1.appBuilderCodegenConfig,
@@ -15042,6 +15107,10 @@ When done, summarize each error: message, file, root cause, fix. No diffs.`;
15042
15107
  [
15043
15108
  "call-telemetry-tool"
15044
15109
  /* OpenCodeTool.CallTelemetryTool */
15110
+ ]: "deny",
15111
+ [
15112
+ "upload-media"
15113
+ /* OpenCodeTool.UploadMedia */
15045
15114
  ]: "deny"
15046
15115
  };
15047
15116
  var READ_TOOLS = {
@@ -120562,6 +120631,10 @@ var require_config = __commonJS({
120562
120631
  [
120563
120632
  "call-telemetry-tool"
120564
120633
  /* OpenCodeTool.CallTelemetryTool */
120634
+ ]: "deny",
120635
+ [
120636
+ "upload-media"
120637
+ /* OpenCodeTool.UploadMedia */
120565
120638
  ]: "deny"
120566
120639
  };
120567
120640
  var ASK_PERMISSIONS = {
@@ -120590,6 +120663,10 @@ var require_config = __commonJS({
120590
120663
  "uuid"
120591
120664
  /* OpenCodeTool.Uuid */
120592
120665
  ]: "deny",
120666
+ [
120667
+ "upload-media"
120668
+ /* OpenCodeTool.UploadMedia */
120669
+ ]: "deny",
120593
120670
  external_directory: READABLE_EXTERNAL_DIRS
120594
120671
  };
120595
120672
  function buildConfig(projectId, instructionPaths, permission, { isCodeWritingFlow = false, withAgents = false } = {}) {
@@ -129433,8 +129510,9 @@ var require_tool_policies3 = __commonJS({
129433
129510
  isInstruction,
129434
129511
  message
129435
129512
  }), (policy) => policy.mode === mode);
129436
- const generatePolicies = emitKind("generate", ({ blockedExtensionTypes, whenArgsInclude, message }) => ({
129513
+ const generatePolicies = emitKind("generate", ({ blockedExtensionTypes, allowedExtensionTypes, whenArgsInclude, message }) => ({
129437
129514
  blockedExtensionTypes,
129515
+ allowedExtensionTypes,
129438
129516
  whenArgsInclude,
129439
129517
  message
129440
129518
  }));
@@ -129499,6 +129577,25 @@ function generateCommandOf(tool, args) {
129499
129577
  : null;
129500
129578
  }
129501
129579
 
129580
+ // Extension types named in a generate command: \`"extensionType":"X"\` in
129581
+ // --params, or \`--type X\` (the value may be quoted).
129582
+ function commandExtensionTypes(command) {
129583
+ const re = /(?:extensionType["'\\\\\\s:]+|--type[ =]["']?)([A-Z][A-Z0-9_]*)/g;
129584
+ return [...command.matchAll(re)].map((match) => match[1]);
129585
+ }
129586
+
129587
+ function blocksType(policy, type) {
129588
+ return policy.allowedExtensionTypes
129589
+ ? !policy.allowedExtensionTypes.includes(type)
129590
+ : policy.blockedExtensionTypes.includes(type);
129591
+ }
129592
+
129593
+ function blocksCommand(policy, command) {
129594
+ return policy.allowedExtensionTypes
129595
+ ? commandExtensionTypes(command).some((type) => blocksType(policy, type))
129596
+ : policy.blockedExtensionTypes.some((type) => command.includes(type));
129597
+ }
129598
+
129502
129599
  function generateArgsMatch(policy, haystack) {
129503
129600
  return (
129504
129601
  !policy.whenArgsInclude ||
@@ -129528,7 +129625,7 @@ export const ToolPolicies = async () => ({
129528
129625
  const serialized = JSON.stringify(params);
129529
129626
  for (const policy of GENERATE_POLICIES) {
129530
129627
  if (
129531
- policy.blockedExtensionTypes.includes(params.extensionType) &&
129628
+ blocksType(policy, params.extensionType) &&
129532
129629
  generateArgsMatch(policy, serialized)
129533
129630
  ) {
129534
129631
  throw new Error(policy.message);
@@ -129539,7 +129636,7 @@ export const ToolPolicies = async () => ({
129539
129636
  if (generateCommand) {
129540
129637
  for (const policy of GENERATE_POLICIES) {
129541
129638
  if (
129542
- policy.blockedExtensionTypes.some((type) => generateCommand.includes(type)) &&
129639
+ blocksCommand(policy, generateCommand) &&
129543
129640
  generateArgsMatch(policy, generateCommand)
129544
129641
  ) {
129545
129642
  throw new Error(policy.message);
@@ -130289,7 +130386,8 @@ async function main(ctx) {
130289
130386
  projectId: ctx.projectId,
130290
130387
  appNameSpace: ctx.appNamespace,
130291
130388
  codeIdentifier: ctx.codeIdentifier,
130292
- metasiteId: ctx.metasiteId
130389
+ metasiteId: ctx.metasiteId,
130390
+ siteEditor: process.env.SITE_EDITOR
130293
130391
  });
130294
130392
  codeGenerationService_1.codeGenerationService.setAccessTokenListener(config_1.setCurrentAccessToken);
130295
130393
  await initOpenCode();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/ditto-codegen-public",
3
- "version": "1.0.517",
3
+ "version": "1.0.519",
4
4
  "description": "AI-powered Wix CLI app generator - standalone executable",
5
5
  "scripts": {
6
6
  "build": "node build.mjs",
@@ -29,5 +29,5 @@
29
29
  "esbuild": "^0.27.2",
30
30
  "vitest": "^4.0.16"
31
31
  },
32
- "falconPackageHash": "44263e4b6b6cf9fa8ab8a1edd5ad112816f253a6507de4d4cef13c90"
32
+ "falconPackageHash": "36cc95a70649db03d44124988e86973d73a1e9fbe596505714b438eb"
33
33
  }