@wix/mcp 1.0.91 → 1.0.93

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.
@@ -16289,9 +16289,12 @@ var runSemanticSearch = async (toolName, toolParams, maxResults = 20, rerank = f
16289
16289
  );
16290
16290
  return data?.results;
16291
16291
  };
16292
- var runPlatformizedSemanticSearch = async (toolName, searchTerm, maxResults = 20, linesInEachResult) => {
16292
+ var runPlatformizedSemanticSearch = async (toolName, searchTerm, maxResults = 20, linesInEachResult, extraDocumentTypes) => {
16293
16293
  const startTime = Date.now();
16294
- logger.log(`[SemanticSearch/v2] Tool: ${toolName}, Query: "${searchTerm}"`);
16294
+ const documentTypes = extraDocumentTypes?.length ? [toolName, ...extraDocumentTypes] : void 0;
16295
+ logger.log(
16296
+ `[SemanticSearch/v2] Tool: ${documentTypes ? documentTypes.join("+") : toolName}, Query: "${searchTerm}"`
16297
+ );
16295
16298
  const response = await fetch(
16296
16299
  "https://www.wixapis.com/mcp-docs-search/v1/docs/search/markdown",
16297
16300
  {
@@ -16302,7 +16305,7 @@ var runPlatformizedSemanticSearch = async (toolName, searchTerm, maxResults = 20
16302
16305
  },
16303
16306
  body: JSON.stringify({
16304
16307
  search_term: searchTerm,
16305
- document_type: toolName,
16308
+ ...documentTypes ? { document_types: documentTypes } : { document_type: toolName },
16306
16309
  maximum_results: maxResults,
16307
16310
  lines_in_each_result: linesInEachResult
16308
16311
  })
@@ -16331,14 +16334,16 @@ var runSemanticSearchAndFormat = async ({
16331
16334
  maxResults = DEFAULT_MAX_RESULTS,
16332
16335
  rerank,
16333
16336
  linesInEachResult,
16334
- usePlatformizedSearch = true
16337
+ usePlatformizedSearch = true,
16338
+ extraDocumentTypes
16335
16339
  }) => {
16336
16340
  if (usePlatformizedSearch) {
16337
16341
  return runPlatformizedSemanticSearch(
16338
16342
  toolName,
16339
16343
  toolParams.searchTerm,
16340
16344
  maxResults,
16341
- linesInEachResult
16345
+ linesInEachResult,
16346
+ extraDocumentTypes
16342
16347
  );
16343
16348
  } else {
16344
16349
  const results = await runSemanticSearch(
@@ -17782,9 +17787,11 @@ var SITE_CREATION_COPY = {
17782
17787
  }
17783
17788
  };
17784
17789
  var SITE_GUIDANCE = dedent_default`
17785
- A new-site request has two things to settle: what the site is for, and how to build it. The how is AI generation vs. starting from a template, so naming templates, a template id or Wix Studio (Wix Studio is also the template side) already settles it.
17790
+ First decide which of two different things is being asked for:
17791
+ - The site is code the user or you control — hand-written HTML/CSS/JS, a static build, a zip, another AI builder's export, or a page or design you made earlier in this conversation — and it should go live on Wix. This is also the route whenever the user wants to keep working on the site here, with you: a Wix Headless site is a regular coded site, so you keep full control of the design and can change and redeploy it from this conversation at any time, and Wix business capabilities can be added to it as a backend when they are needed. Call StartDeployWebsite: it returns the recipe to host those exact files as a Wix Headless site (updates reuse the same site and URL; the drop page is only its fallback). Do not offer AI or templates for this and do not call any site-creation tool.
17792
+ - Wix should create the site — generated with AI from a description, or started from a template — and the user will design and edit it in Wix rather than through you. That is what the site-creation tools do; they never take files you already have.
17786
17793
 
17787
- One case skips all of this: a finished page or site ALREADY EXISTS, in any form — hand-written HTML/CSS/JS, a static build, a zip, another AI builder's export, or a page you made earlier in this conversation. There is nothing to build, so don't offer AI or templates and don't call any site-creation tool: call StartDeployWebsite, which returns the recipe to publish the files yourself (the drop page is only its fallback).
17794
+ For a new site there are two things to settle: what the site is for, and how to build it. The how is AI generation vs. starting from a template, so naming templates, a template id or Wix Studio (Wix Studio is also the template side) already settles it.
17788
17795
 
17789
17796
  Settle what the site is for first: its purpose, topic, business type, audience, or main visitor action. Naming a method is not a description of the site, and neither is the business or industry on its own.
17790
17797
  If you can't tell yet, ask the preferred question below and nothing else — one question, no creation-method question in the same reply, and no internal tool names.
@@ -17881,13 +17888,14 @@ var ACCOUNT_SITE_EXECUTE_SCOPE = dedent_default`
17881
17888
  unzip(input: string | Uint8Array): Promise<Array<{ path: string; bytes: Uint8Array; text(): string }>>;
17882
17889
  };
17883
17890
  declare const siteId: string | undefined;
17884
- // Files from the ExecuteWixAPI \`files\` param. Text entries have \`content\`;
17885
- // an entry tagged \`=== FILE: <path> base64 ===\` has encoding:'base64' and
17886
- // base64 \`content\` (a binary file — image, font).
17891
+ // Files from the ExecuteWixAPI \`files\` param, followed by the resolved
17892
+ // \`attachments\`. Text entries have \`content\`; an entry tagged
17893
+ // \`=== FILE: <path> base64 ===\` — and every attachment, path = its file name —
17894
+ // has encoding:'base64' and base64 \`content\`.
17887
17895
  declare const files: Array<{ path: string; content: string; encoding?: "base64" }>;
17888
17896
  \`\`\`
17889
17897
 
17890
- FILE UPLOADS: put every file in the \`files\` param (never inline in \`code\`). Text goes raw; a small binary (icon, logo, font) rides as a \`base64\`-tagged entry — large images/video are referenced by URL (\`<img src="https://...">\`), not bundled. \`wix.multipart()\` turns the whole set into one upload body (bytes, so binary is safe):
17898
+ FILE UPLOADS: files never go inline in \`code\`; two params feed the \`files\` global. \`attachments\` takes files attached in the chat or created in your file sandbox, of any type and size up to 10 MB per call (a zip of a whole site, HTML, images, PDFs): pass the files themselves, all in one call, and the platform resolves each into \`{ download_url, file_id, file_name?, mime_type? }\` — the bytes are fetched for you and arrive as base64 entries named by file name. The \`files\` param takes content you have as text here: text goes raw; a small binary (icon, logo, font) rides as a \`base64\`-tagged entry — large images/video are referenced by URL (\`<img src="https://...">\`), not bundled. \`wix.multipart()\` turns the whole set into one upload body (bytes, so binary is safe):
17891
17899
  \`\`\`javascript
17892
17900
  // files param:
17893
17901
  // === FILE: index.html ===
@@ -17902,6 +17910,12 @@ var ACCOUNT_SITE_EXECUTE_SCOPE = dedent_default`
17902
17910
  return res.data;
17903
17911
  }
17904
17912
  \`\`\`
17913
+ A site zip passed through \`attachments\` is one base64 entry; unzip it and upload the entries:
17914
+ \`\`\`javascript
17915
+ // attachments: [site.zip] → files = [{ path: "site.zip", content: "<base64>", encoding: "base64" }]
17916
+ const entries = await wix.unzip(files[0].content); // [{ path, bytes, text() }]
17917
+ const mp = wix.multipart(entries);
17918
+ \`\`\`
17905
17919
  DOWNLOAD + EDIT + RE-UPLOAD: fetch the zip as base64, \`wix.unzip()\` it, edit text via \`entry.text()\`, keep binary as bytes, and hand the entries back to \`wix.multipart()\`:
17906
17920
  \`\`\`javascript
17907
17921
  const r = await wix.request({ scope: "account", method: "GET", responseType: "base64", url: zipUrl });
@@ -18106,12 +18120,12 @@ function buildToolDescriptions(includeReadme, includeImageUploadGuidance = true)
18106
18120
  NEVER call this tool with a missing, empty, or guessed siteId — ask first instead.
18107
18121
 
18108
18122
  Parameters — provide image input via image and/or imageUrls, OR imageBase64:
18109
- • image (array): chat file ATTACHMENTS. Each item is an object with download_url and file_id (both required), plus optional file_name and mime_type. Pass ALL attachments in one call.
18123
+ • image (array): chat file ATTACHMENTS — files the user attached, or files you created in your own file sandbox. Each item is an object with download_url and file_id (both required), plus optional file_name and mime_type. Pass ALL attachments in one call.
18110
18124
  • imageUrls (array): plain public image URLs the user pasted or other tools produced (no file_id). Pass ALL URLs in one call. Can be combined with image.
18111
18125
  • imageBase64 (string): base64-encoded image + mimeType. One image at a time. Do NOT combine with image/imageUrls.
18112
18126
 
18113
18127
  Delivering the bytes — this is where uploads most often fail:
18114
- • NEVER pass a local or sandbox file path (e.g. /mnt/..., /home/user/..., /Users/...) in any field — the server cannot reach your filesystem. Use a public http(s) URL (imageUrls) or the complete base64 (imageBase64).
18128
+ • Pass a file as a file, in image: the platform resolves it into download_url and file_id before it reaches this tool — this includes files you created in your sandbox. This server does not share your filesystem, so a bare path string (e.g. /mnt/..., /home/user/..., /Users/...) is not a file. Without a file to pass, use a public http(s) URL (imageUrls) or the complete base64 (imageBase64).
18115
18129
  • imageBase64 must be the WHOLE file, not truncated. For large images prefer imageUrls, since long base64 is easily cut off and will be rejected as unreadable.
18116
18130
  `,
18117
18131
  SupportAndFeedback: dedent_default`
@@ -18608,14 +18622,14 @@ function buildToolDescriptions(includeReadme, includeImageUploadGuidance = true)
18608
18622
  WixSiteBuilder: dedent_default`
18609
18623
  ${SITE_GUIDANCE}
18610
18624
 
18611
- Tool for generating a Wix site with AI (creating / building a site in Wix Harmony).
18625
+ Tool for generating a Wix site with AI (creating / building a site in Wix Harmony) from a description. It does not take pages or files you already have — those go to StartDeployWebsite.
18612
18626
 
18613
18627
  Call this ONLY when the user's own words name AI (for example "create a site using AI" or "build it with AI") and the site intent is clear. A description of what the site should do — reservations, online ordering, a store, bookings, menus, a portfolio, and the like — is NOT a request for AI and NOT enough to call this tool; never infer AI from features or industry.
18614
18628
  Never default to this tool: if the user hasn't explicitly named AI, don't call this tool — ${SITE_CREATION_COPY.unstatedMethod.nonWidget}.
18615
18629
 
18616
18630
  For templates or Wix Studio, call \`SearchSiteTemplates\`; for a specific template by \`metaSiteId\` or \`templateId\`, call \`CreateSiteFromTemplate\`; for a headless or classic Wix Editor site, or manual/account-API creation, call \`CreateWixBusinessGuide\`.
18617
18631
 
18618
- Do NOT suggest HTML code, prompt templates, or alternative approaches — actually build the site through this tool.
18632
+ Do NOT suggest HTML code, prompt templates, or alternative approaches instead of building — actually build the site through this tool. (HTML the user already has is the StartDeployWebsite case, not a reason to build.)
18619
18633
  `,
18620
18634
  SearchSiteTemplates: dedent_default`
18621
18635
  ${SITE_GUIDANCE}
@@ -18659,8 +18673,8 @@ function buildToolDescriptions(includeReadme, includeImageUploadGuidance = true)
18659
18673
  Set \`hasMutations: true\` for any document containing a mutation root field.
18660
18674
  `,
18661
18675
  StartDeployWebsite: dedent_default`
18662
- The user — or you, earlier in this conversation — ALREADY HAVE a finished page or site, in any form, and it should be live on Wix: HTML/CSS/JS files, a static build (dist/, out/), a zip, another AI builder's export, or a page/design you created in this conversation (export it to HTML first — a finished design IS a finished page). Call this when the user says deploy, host, publish, put online, make it live, get a URL, or upload my site / index.html.
18663
- Also for updating a site deployed this way (replace its files; same site, same URL) and for implementing a backend on one (stores, bookings, CMS, members) as a Wix Headless project — same site, same URL. Works with or without a Wix login (anonymous deploy with a save link), through the Wix MCP alone or from a shell.
18676
+ The user — or you, earlier in this conversation — ALREADY HAVE a finished page or site, in any form, and it should be live on Wix — or an already-deployed Wix Headless site whose files should be replaced. The site can be HTML/CSS/JS files, a static build (dist/, out/), a zip, another AI builder's export, or a page/design you created in this conversation (export it to HTML first — a finished design IS a finished page). Call this when the user says deploy, host, publish, put online, make it live, get a URL, update my site, or upload my site / index.html.
18677
+ Updates keep the same site and URL. Also for implementing a backend on such a site as a Wix Headless project — same site, same URL. Works with or without a Wix login (anonymous deploy with a save link), through the Wix MCP alone or from a shell.
18664
18678
  Missing real functionality — a fake checkout, a form that goes nowhere, bookings — is NOT a reason to rebuild the site with a site-creation tool: deploy the page as is, then add the backend afterwards (the recipe covers it).
18665
18679
  Returns the full recipe; follow it and run the flow yourself. The drop page is only the fallback when you can't.
18666
18680
  NOT for: a screenshot, mockup or reference image of a site the user WANTS (nothing exists to deploy yet — that is site creation: WixSiteBuilder / templates); a Claude Design share URL (import-claude-design-from-url); migrating a live site by URL or CSV exports; adding HTML or code into an existing Wix site; uploading images or documents to a site's media (UploadImageToWixSite).
@@ -19363,7 +19377,7 @@ var paramDescriptions = {
19363
19377
  },
19364
19378
  SearchWixRESTDocumentation: {
19365
19379
  searchTerm: `The search term to look up in the Wix REST API Documentation \u2014 a natural-language description of the endpoint, resource, or action you need across any Wix domain (Stores, eCommerce, Bookings, CRM, Members, CMS, Events, Blog, Forms, Media, site settings, etc.), e.g. "create a catalog item with inventory", "book a service", "update data collection items". Match the wording to how many entities you will act on: a plural term ("update products") surfaces the resource's bulk methods, which a singular term ("update a product") ranks lower or leaves out. Results are ranked by relevance, so describe the goal rather than guessing an exact API name.`,
19366
- maxResults: "The maximum number of results to return, default is 10, max is 15",
19380
+ maxResults: "The maximum number of results to return (1\u201317, default 17). Results mix REST API documentation with matching recipes and skills.",
19367
19381
  reason: "One sentence describing the original user request and the task you are trying to accomplish with this search."
19368
19382
  },
19369
19383
  WixBusinessFlowsDocumentation: {
@@ -19384,7 +19398,7 @@ var paramDescriptions = {
19384
19398
  },
19385
19399
  SearchWixHeadlessDocumentation: {
19386
19400
  searchTerm: "The search term to search for in the Headless Documentation",
19387
- maxResults: "The maximum number of results to return, default is 10, max is 15"
19401
+ maxResults: "The maximum number of results to return (1\u201317, default 17). Results mix Headless documentation with matching recipes and skills."
19388
19402
  },
19389
19403
  SearchWixVeloDocumentation: {
19390
19404
  searchTerm: "The search term to search for in the Velo Documentation",
@@ -19412,7 +19426,7 @@ var paramDescriptions = {
19412
19426
  },
19413
19427
  UploadImageToWixSite: {
19414
19428
  siteId: "The ID (UUID) of the Wix site to upload to. REQUIRED. If the user has not clearly specified which site, ASK them which site to upload to (or use ListWixSites to help them pick) BEFORE calling this tool. NEVER call this tool with a missing, empty, placeholder, or guessed siteId \u2014 ask first instead.",
19415
- image: "Array of file ATTACHMENTS the user uploaded in the chat. Each item requires download_url and file_id, and may optionally include file_name and mime_type \u2014 attached files are automatically resolved to these fields by the platform, so just include them here. For plain image URLs the user pasted, use imageUrls instead. ALWAYS pass ALL attachments together in a single call \u2014 NEVER call this tool once per image. Do NOT use together with imageBase64.",
19429
+ image: "Array of file ATTACHMENTS: files the user uploaded in the chat, or files you created in your own file sandbox. Each item requires download_url and file_id, and may optionally include file_name and mime_type \u2014 the platform resolves a file passed here into these fields automatically, so just include the files. For plain image URLs the user pasted, use imageUrls instead. ALWAYS pass ALL attachments together in a single call \u2014 NEVER call this tool once per image. Do NOT use together with imageBase64.",
19416
19430
  imageUrls: "Array of publicly accessible image URLs (e.g. links the user pasted or URLs produced by other tools). Use this for plain URLs that are NOT chat attachments \u2014 no file_id is needed. ALWAYS pass ALL URLs together in a single call. Can be combined with image; do NOT use together with imageBase64.",
19417
19431
  imageBase64: 'Base64-encoded image data. Use when the client can read a file and encode it as base64. May include a data URL prefix (e.g. "data:image/jpeg;base64,...") or be raw base64. Do NOT use together with image.',
19418
19432
  mimeType: 'MIME type of the image (e.g. "image/jpeg", "image/png", "image/webp"). Required when imageBase64 does not include a data URL prefix.',
@@ -19816,7 +19830,17 @@ ${articleContent}${nextSteps}`;
19816
19830
  }
19817
19831
 
19818
19832
  // src/docs/start-deploy-website.ts
19819
- var START_DEPLOY_WEBSITE_BRIEF_DESCRIPTION = "A few sentences covering: the user's request (quoted if short); what the site is \u2014 its purpose and who it is for \u2014 and its current form (HTML/CSS/JS files, a static build, a zip, another builder's export, a design created in this conversation), roughly how many files, and whether it includes images; what the site must be able to do for its visitors beyond showing pages, if anything \u2014 selling, bookings or reservations, tickets, menus and orders, rentals, forms, memberships or paid plans, donations, a blog, or anything else the user expects to work \u2014 described in your own words, or a note that it is a plain static site with no such needs; which agent or product you are and the harness you run in.";
19833
+ var START_DEPLOY_WEBSITE_PARAM_DESCRIPTIONS = {
19834
+ userRequest: "The user's request that led here, quoted if short, otherwise summarized in a sentence.",
19835
+ siteDescription: "What the site is: its purpose and who it is for. One or two sentences.",
19836
+ siteForm: "The form the site exists in right now (HTML/CSS/JS files, a static build, a zip, another builder's export, a design created in this conversation, or something else), roughly how many files, and whether it includes images.",
19837
+ siteFunctionality: "What the site must be able to do for its visitors beyond showing pages, if anything (for example selling, bookings or reservations, tickets, menus and orders, rentals, forms, memberships or paid plans, donations, a blog, or anything else the user expects to work), in your own words. If it is a plain static site with no such needs, say so.",
19838
+ agentIdentity: "Which agent or product you are and the harness you run in.",
19839
+ wixAccess: "How you can reach Wix from where you run: through this MCP only, or also from a shell whose network can reach wixapis.com; whether you can run the Wix CLI (npx @wix/cli) there and whether it is logged in; and which Wix identity you act with \u2014 the user's login through this MCP, a CLI login, or none."
19840
+ };
19841
+ var START_DEPLOY_WEBSITE_PARAMS = Object.keys(
19842
+ START_DEPLOY_WEBSITE_PARAM_DESCRIPTIONS
19843
+ );
19820
19844
  var START_DEPLOY_WEBSITE_TOOL_NAME = "StartDeployWebsite";
19821
19845
  var START_DEPLOY_WEBSITE_RECIPE_URL = "https://dev.wix.com/docs/api-reference/account-level/sites/skills/upload-a-website-or-html-files.md";
19822
19846
  var DROP_PAGE_URL = "https://www.wix.com/headless/drop?utm_campaign=mcp";
@@ -19842,7 +19866,12 @@ function addStartDeployWebsiteTool(server, disableTools = [], toolDescriptions,
19842
19866
  START_DEPLOY_WEBSITE_TOOL_NAME,
19843
19867
  toolDescriptions?.[START_DEPLOY_WEBSITE_TOOL_NAME] ?? defaultToolDescriptions[START_DEPLOY_WEBSITE_TOOL_NAME],
19844
19868
  {
19845
- brief: external_exports.string().min(1).describe(START_DEPLOY_WEBSITE_BRIEF_DESCRIPTION)
19869
+ userRequest: external_exports.string().min(1).describe(START_DEPLOY_WEBSITE_PARAM_DESCRIPTIONS.userRequest),
19870
+ siteDescription: external_exports.string().min(1).describe(START_DEPLOY_WEBSITE_PARAM_DESCRIPTIONS.siteDescription),
19871
+ siteForm: external_exports.string().min(1).describe(START_DEPLOY_WEBSITE_PARAM_DESCRIPTIONS.siteForm),
19872
+ siteFunctionality: external_exports.string().min(1).describe(START_DEPLOY_WEBSITE_PARAM_DESCRIPTIONS.siteFunctionality),
19873
+ agentIdentity: external_exports.string().min(1).describe(START_DEPLOY_WEBSITE_PARAM_DESCRIPTIONS.agentIdentity),
19874
+ wixAccess: external_exports.string().min(1).describe(START_DEPLOY_WEBSITE_PARAM_DESCRIPTIONS.wixAccess)
19846
19875
  },
19847
19876
  { readOnlyHint: true, destructiveHint: false, openWorldHint: false },
19848
19877
  async (_args, { httpClient }) => {
@@ -20056,7 +20085,7 @@ var addDocsTools = (server, allowedTools = [
20056
20085
  const d = desc("SearchWixRESTDocumentation");
20057
20086
  return {
20058
20087
  searchTerm: external_exports.string().describe(d.searchTerm),
20059
- maxResults: external_exports.number().describe(d.maxResults).min(1).max(15).optional().default(15),
20088
+ maxResults: external_exports.number().describe(d.maxResults).min(1).max(17).optional().default(17),
20060
20089
  reason: external_exports.string().describe(d.reason)
20061
20090
  };
20062
20091
  })(),
@@ -20071,9 +20100,12 @@ var addDocsTools = (server, allowedTools = [
20071
20100
  toolParams: {
20072
20101
  searchTerm
20073
20102
  },
20074
- maxResults: Math.max(1, Math.min(maxResults ?? 15, 15)),
20103
+ maxResults: Math.max(1, Math.min(maxResults ?? 17, 17)),
20075
20104
  linesInEachResult: 30,
20076
- usePlatformizedSearch
20105
+ usePlatformizedSearch,
20106
+ // Merge recipes/skills into the REST ranking — they live in a
20107
+ // separate corpus the REST document_type doesn't cover on its own.
20108
+ extraDocumentTypes: ["SKILLS"]
20077
20109
  });
20078
20110
  const grounding = result.includes(QUERY_CAPABILITY_MARKER) ? [
20079
20111
  REST_SEARCH_API_GROUNDING_REMINDER,
@@ -20336,7 +20368,7 @@ var addDocsTools = (server, allowedTools = [
20336
20368
  const d = desc("SearchWixHeadlessDocumentation");
20337
20369
  return {
20338
20370
  searchTerm: external_exports.string().describe(d.searchTerm),
20339
- maxResults: external_exports.number().describe(d.maxResults).min(1).max(15).optional().default(15)
20371
+ maxResults: external_exports.number().describe(d.maxResults).min(1).max(17).optional().default(17)
20340
20372
  };
20341
20373
  })(),
20342
20374
  { readOnlyHint: true, destructiveHint: false, openWorldHint: false },
@@ -20348,8 +20380,11 @@ var addDocsTools = (server, allowedTools = [
20348
20380
  toolParams: {
20349
20381
  searchTerm
20350
20382
  },
20351
- maxResults: Math.max(1, Math.min(maxResults ?? 15, 15)),
20352
- usePlatformizedSearch
20383
+ maxResults: Math.max(1, Math.min(maxResults ?? 17, 17)),
20384
+ usePlatformizedSearch,
20385
+ // Merge recipes/skills into the headless ranking — same separate
20386
+ // corpus the WIX_HEADLESS document_type doesn't cover on its own.
20387
+ extraDocumentTypes: ["SKILLS"]
20353
20388
  });
20354
20389
  return {
20355
20390
  content: [
@@ -22269,6 +22304,189 @@ ${text.slice(0, 2e3)}`
22269
22304
  );
22270
22305
  }
22271
22306
 
22307
+ // src/code-mode/attachments.ts
22308
+ var MAX_ATTACHMENTS_BYTES = 10 * 1024 * 1024;
22309
+ var MAX_REDIRECTS = 4;
22310
+ var OAI_USERCONTENT_HOST = /^[a-z0-9-]+\.oaiusercontent\.com$/;
22311
+ var OAI_BLOB_ACCOUNTS = new Set(
22312
+ [
22313
+ "australiaeast",
22314
+ "brazilsouth",
22315
+ "cacentral",
22316
+ "centralindia",
22317
+ "centralus",
22318
+ "centralusdr",
22319
+ "denmarkeast",
22320
+ "eastus",
22321
+ "eastus2",
22322
+ "indiasocentral",
22323
+ "italynorth",
22324
+ "japaneast",
22325
+ "koreacentral",
22326
+ "northcentralus",
22327
+ "northeu",
22328
+ "nznorth",
22329
+ "polandcentral",
22330
+ "seasia",
22331
+ "southcentralus",
22332
+ "southeastus3",
22333
+ "ukwest",
22334
+ "westcentralus",
22335
+ "westus",
22336
+ "westus2",
22337
+ "westus3"
22338
+ ].map((region) => `oaisdmntpr${region}.blob.core.windows.net`)
22339
+ );
22340
+ function isAllowedAttachmentHost(hostname) {
22341
+ const h = hostname.toLowerCase();
22342
+ return OAI_USERCONTENT_HOST.test(h) || OAI_BLOB_ACCOUNTS.has(h);
22343
+ }
22344
+ function checkAttachmentUrl(url) {
22345
+ if (url.protocol !== "https:") return "is not an https URL";
22346
+ if (url.port) return "uses a non-default port";
22347
+ if (!isAllowedAttachmentHost(url.hostname)) {
22348
+ return `host "${url.hostname}" is not a ChatGPT file host`;
22349
+ }
22350
+ return void 0;
22351
+ }
22352
+ var AttachmentError = class extends Error {
22353
+ };
22354
+ function attachmentPath(a, url) {
22355
+ let fromUrl = "";
22356
+ try {
22357
+ fromUrl = decodeURIComponent(
22358
+ url.pathname.split("/").filter(Boolean).pop() ?? ""
22359
+ );
22360
+ } catch {
22361
+ fromUrl = "";
22362
+ }
22363
+ const raw = (a.file_name?.trim() || fromUrl || a.file_id).replace(/\\/g, "/");
22364
+ const segments = raw.split("/").filter((s) => s && s !== "." && s !== "..");
22365
+ return segments.join("/") || a.file_id;
22366
+ }
22367
+ function toBase64(bytes) {
22368
+ let binary = "";
22369
+ const chunk = 32768;
22370
+ for (let i = 0; i < bytes.length; i += chunk) {
22371
+ binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
22372
+ }
22373
+ return btoa(binary);
22374
+ }
22375
+ async function fetchAllowed(start, fetchImpl, label) {
22376
+ let url = start;
22377
+ for (let hop = 0; ; hop++) {
22378
+ const res = await fetchImpl(url.toString(), { redirect: "manual" });
22379
+ const location = res.headers.get("location");
22380
+ const isRedirect = res.status >= 300 && res.status < 400 && location;
22381
+ if (!isRedirect) return res;
22382
+ await res.body?.cancel().catch(() => void 0);
22383
+ if (hop >= MAX_REDIRECTS) {
22384
+ throw new AttachmentError(`${label}: too many redirects.`);
22385
+ }
22386
+ let next;
22387
+ try {
22388
+ next = new URL(location, url);
22389
+ } catch {
22390
+ throw new AttachmentError(`${label}: redirect to an invalid URL.`);
22391
+ }
22392
+ const problem = checkAttachmentUrl(next);
22393
+ if (problem) {
22394
+ throw new AttachmentError(
22395
+ `${label}: the download redirected to a URL that ${problem}; refused.`
22396
+ );
22397
+ }
22398
+ url = next;
22399
+ }
22400
+ }
22401
+ async function readWithin(res, budget, overBudget) {
22402
+ const declared = Number(res.headers.get("content-length") ?? 0);
22403
+ if (declared > budget) throw overBudget();
22404
+ if (!res.body) {
22405
+ const bytes = new Uint8Array(await res.arrayBuffer());
22406
+ if (bytes.byteLength > budget) throw overBudget();
22407
+ return bytes;
22408
+ }
22409
+ const reader = res.body.getReader();
22410
+ const chunks = [];
22411
+ let total = 0;
22412
+ for (; ; ) {
22413
+ const { done, value } = await reader.read();
22414
+ if (done) break;
22415
+ total += value.byteLength;
22416
+ if (total > budget) {
22417
+ await reader.cancel().catch(() => void 0);
22418
+ throw overBudget();
22419
+ }
22420
+ chunks.push(value);
22421
+ }
22422
+ const out = new Uint8Array(total);
22423
+ let offset = 0;
22424
+ for (const c of chunks) {
22425
+ out.set(c, offset);
22426
+ offset += c.byteLength;
22427
+ }
22428
+ return out;
22429
+ }
22430
+ async function resolveAttachments(attachments, fetchImpl = fetch) {
22431
+ if (!Array.isArray(attachments) || attachments.length === 0) return [];
22432
+ const items = [];
22433
+ attachments.forEach((raw, i) => {
22434
+ const a = typeof raw === "object" && raw;
22435
+ const downloadUrl = a && typeof a.download_url === "string" ? a.download_url : "";
22436
+ let url;
22437
+ try {
22438
+ url = /^https?:\/\//i.test(downloadUrl) ? new URL(downloadUrl) : void 0;
22439
+ } catch {
22440
+ url = void 0;
22441
+ }
22442
+ if (!a || !url) {
22443
+ throw new AttachmentError(
22444
+ `attachments[${i}] was not resolved to a download URL (got ${JSON.stringify(
22445
+ typeof raw === "string" ? raw : (a && a.download_url) ?? raw
22446
+ )}). The platform did not hydrate this attachment; retry once, and if it still arrives like this put the file in the \`files\` bundle instead (\`=== FILE: <path> base64 ===\` for binary).`
22447
+ );
22448
+ }
22449
+ const problem = checkAttachmentUrl(url);
22450
+ if (problem) {
22451
+ throw new AttachmentError(
22452
+ `attachments[${i}].download_url ${problem}. Only platform-resolved attachments are accepted here; for any other URL fetch it in \`code\` via wix.request or put the bytes in the \`files\` bundle.`
22453
+ );
22454
+ }
22455
+ items.push({ a, url });
22456
+ });
22457
+ let remaining = MAX_ATTACHMENTS_BYTES;
22458
+ const out = [];
22459
+ for (const [i, { a, url }] of items.entries()) {
22460
+ const path = attachmentPath(a, url);
22461
+ const label = `attachments[${i}] (${path})`;
22462
+ let res;
22463
+ try {
22464
+ res = await fetchAllowed(url, fetchImpl, label);
22465
+ } catch (e) {
22466
+ if (e instanceof AttachmentError) throw e;
22467
+ throw new AttachmentError(
22468
+ `${label}: download failed (${e.message}).`
22469
+ );
22470
+ }
22471
+ if (!res.ok) {
22472
+ await res.body?.cancel().catch(() => void 0);
22473
+ throw new AttachmentError(
22474
+ `${label}: download returned HTTP ${res.status}. The download_url may have expired; attach the file again.`
22475
+ );
22476
+ }
22477
+ const bytes = await readWithin(
22478
+ res,
22479
+ remaining,
22480
+ () => new AttachmentError(
22481
+ `${label} pushes the attachments past ${MAX_ATTACHMENTS_BYTES} bytes in total for this call; split the upload across calls.`
22482
+ )
22483
+ );
22484
+ remaining -= bytes.byteLength;
22485
+ out.push({ path, content: toBase64(bytes), encoding: "base64" });
22486
+ }
22487
+ return out;
22488
+ }
22489
+
22272
22490
  // src/code-mode/validation.ts
22273
22491
  var EXECUTE_FUNCTION_EXPRESSION_HINT = 'ExecuteWixAPI code must be a function expression, not a script body. Pass code like: async () => { const response = await wix.request({ scope: "site", method: "GET", url: "https://www.wixapis.com/..." }); return response.data; }. Do not write top-level const/await/return outside the function and do not invoke the function yourself.';
22274
22492
  function validateExecuteCode(code) {
@@ -22480,7 +22698,7 @@ function addExecuteTool(server, options) {
22480
22698
  } = options;
22481
22699
  const executeUrl = `${codeModeBaseUrl}/api/code-mode/execute`;
22482
22700
  const d = desc("ExecuteWixAPI");
22483
- server.tool(
22701
+ const registered = server.tool(
22484
22702
  EXECUTE_TOOL_NAME,
22485
22703
  toolDescriptions?.[EXECUTE_TOOL_NAME] ?? defaultToolDescriptions.ExecuteWixAPI,
22486
22704
  {
@@ -22509,6 +22727,20 @@ function addExecuteTool(server, options) {
22509
22727
  'Use base64 entries for small assets (icons, logos, fonts) and for files you downloaded and are re-uploading; large images/video go in by URL (`<img src="https://...">`), not in the bundle. A file containing a line exactly like the delimiter is not supported.'
22510
22728
  ].join(" ")
22511
22729
  ),
22730
+ // ChatGPT file attachments (`openai/fileParams`). Item shape must match
22731
+ // OpenAI's file schema: download_url + file_id required, the rest optional.
22732
+ // Declaring it is what makes the platform hand us a download URL instead
22733
+ // of a sandbox path. Resolved host-side into base64 `files` entries.
22734
+ attachments: external_exports.array(
22735
+ external_exports.object({
22736
+ download_url: external_exports.string(),
22737
+ file_id: external_exports.string(),
22738
+ file_name: external_exports.string().optional(),
22739
+ mime_type: external_exports.string().optional()
22740
+ })
22741
+ ).optional().describe(
22742
+ 'Files attached in this chat, or files you created in your own file sandbox (any type: a zip of a site, HTML, images, PDFs). Pass the files themselves and the platform resolves each into { download_url, file_id, file_name?, mime_type? }; the bytes are fetched here and appended to the `files` global as { path, content, encoding: "base64" } entries (path = file_name), so `wix.multipart()` and `wix.unzip()` work on them unchanged. Prefer this over base64 in `files` whenever you have a file handle. Up to 10 MB per call.'
22743
+ ),
22512
22744
  // Visitor mode takes an agent-supplied token and pins the site; account/site
22513
22745
  // mode lets the agent pick the site.
22514
22746
  ...visitor ? {
@@ -22523,7 +22755,15 @@ function addExecuteTool(server, options) {
22523
22755
  },
22524
22756
  { readOnlyHint: false, destructiveHint: true, openWorldHint: false },
22525
22757
  async (rawArgs, extra) => {
22526
- const { code, reason, hasMutations, sourceDocUrls, visitorToken, files } = rawArgs;
22758
+ const {
22759
+ code,
22760
+ reason,
22761
+ hasMutations,
22762
+ sourceDocUrls,
22763
+ visitorToken,
22764
+ files,
22765
+ attachments
22766
+ } = rawArgs;
22527
22767
  const siteId = visitor ? visitor.siteId : rawArgs.siteId;
22528
22768
  logger.log(
22529
22769
  `[ExecuteWixAPI]${visitor ? " (visitor)" : ""} Executing code (${code.length} chars), siteId=${siteId ?? "none"}, hasMutations=${hasMutations}, sourceDocUrls=${JSON.stringify(sourceDocUrls)}, reason="${reason}"`
@@ -22535,6 +22775,13 @@ function addExecuteTool(server, options) {
22535
22775
  );
22536
22776
  return executeTextResult(validation.error);
22537
22777
  }
22778
+ let attachmentFiles = [];
22779
+ try {
22780
+ attachmentFiles = await resolveAttachments(attachments);
22781
+ } catch (e) {
22782
+ if (e instanceof AttachmentError) return executeErrorResult(e.message);
22783
+ throw e;
22784
+ }
22538
22785
  const accountHeaders = await authStrategy?.getAccountAuthHeaders();
22539
22786
  const siteAuthContext = !visitor && authStrategy?.getSiteAuthContext ? await authStrategy.getSiteAuthContext() : void 0;
22540
22787
  let siteHeaders;
@@ -22569,7 +22816,8 @@ function addExecuteTool(server, options) {
22569
22816
  accountToken: visitor ? visitorToken : accountHeaders?.Authorization,
22570
22817
  accountId: accountHeaders?.["wix-account-id"],
22571
22818
  siteAuthContext,
22572
- ...files ? { files } : {}
22819
+ ...files ? { files } : {},
22820
+ ...attachmentFiles.length ? { attachmentFiles } : {}
22573
22821
  },
22574
22822
  visitor ? visitorToken : accountHeaders?.Authorization ?? siteHeaders?.Authorization,
22575
22823
  codeModeFetch
@@ -22600,6 +22848,9 @@ function addExecuteTool(server, options) {
22600
22848
  }
22601
22849
  }
22602
22850
  );
22851
+ registered?.update?.({
22852
+ _meta: { ...registered._meta, "openai/fileParams": ["attachments"] }
22853
+ });
22603
22854
  }
22604
22855
 
22605
22856
  // src/infra/panorama.ts
@@ -0,0 +1,37 @@
1
+ /**
2
+ * ChatGPT file attachments for ExecuteWixAPI (`openai/fileParams`).
3
+ *
4
+ * ChatGPT resolves a file the user attached — or one the model wrote in its
5
+ * own sandbox — into `{ download_url, file_id, file_name?, mime_type? }` for a
6
+ * param the tool lists under `_meta["openai/fileParams"]`. The bytes never go
7
+ * through the model. We fetch each `download_url` host-side and hand the
8
+ * runtime ready-made base64 file entries, the same shape the `files` bundle
9
+ * parses into, so `files`, `wix.multipart()` and `wix.unzip()` are unchanged.
10
+ *
11
+ * This is additive: clients without the extension never populate the param
12
+ * and keep using the `files` bundle (text + base64 sections).
13
+ */
14
+ export interface ExecuteAttachment {
15
+ download_url: string;
16
+ file_id: string;
17
+ file_name?: string;
18
+ mime_type?: string;
19
+ }
20
+ /** Same shape as the runtime's BundledFile with encoding fixed to base64. */
21
+ export interface AttachmentFile {
22
+ path: string;
23
+ content: string;
24
+ encoding: 'base64';
25
+ }
26
+ export declare const MAX_ATTACHMENTS_BYTES: number;
27
+ export declare function isAllowedAttachmentHost(hostname: string): boolean;
28
+ export declare class AttachmentError extends Error {
29
+ }
30
+ /**
31
+ * Fetch every attachment and return base64 file entries for the runtime.
32
+ * Throws AttachmentError with an agent-facing message: an unresolved item
33
+ * (ChatGPT passed a sandbox path or a bare id instead of a URL), a host we
34
+ * don't trust, a failed download, or more bytes than MAX_ATTACHMENTS_BYTES.
35
+ */
36
+ export declare function resolveAttachments(attachments: unknown, fetchImpl?: typeof fetch): Promise<AttachmentFile[]>;
37
+ //# sourceMappingURL=attachments.d.ts.map