@grapesjs/studio-sdk-plugins 1.0.38 → 1.0.39-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accordionComponent/index.cjs.js +5 -5
- package/dist/accordionComponent/index.es.js +70 -67
- package/dist/accordionComponent/index.js +39 -0
- package/dist/accordionComponent/index.umd.js +4 -4
- package/dist/aiChat/components/AiChatHeader.d.ts +4 -5
- package/dist/aiChat/components/AiChatInput/index.d.ts +4 -5
- package/dist/aiChat/components/AiChatMessage.d.ts +7 -8
- package/dist/aiChat/components/index.d.ts +1 -1
- package/dist/aiChat/components/utils.d.ts +1 -1
- package/dist/aiChat/index.cjs.js +10 -376
- package/dist/aiChat/index.es.js +4569 -28851
- package/dist/aiChat/index.js +10 -376
- package/dist/aiChat/index.umd.js +11 -377
- package/dist/aiChat/server/index.cjs.d.ts +0 -1
- package/dist/aiChat/server/index.cjs.js +45 -45
- package/dist/aiChat/server/index.d.ts +0 -1
- package/dist/aiChat/server/index.es.d.ts +0 -1
- package/dist/aiChat/server/index.es.js +371 -427
- package/dist/aiChat/server/index.js +45 -45
- package/dist/aiChat/server/index.umd.js +41 -41
- package/dist/aiChat/server/stream.test.d.ts +1 -0
- package/dist/aiChat/types.d.ts +18 -4
- package/dist/aiChat/typesSchema.d.ts +13 -0
- package/dist/animationComponent/index.cjs.js +3 -3
- package/dist/animationComponent/index.es.js +49 -46
- package/dist/animationComponent/index.js +519 -0
- package/dist/animationComponent/index.umd.js +3 -3
- package/dist/canvasAbsoluteMode/index.cjs.js +1 -1
- package/dist/canvasAbsoluteMode/index.es.js +115 -112
- package/dist/canvasAbsoluteMode/index.js +1 -0
- package/dist/canvasAbsoluteMode/index.umd.js +1 -1
- package/dist/canvasEmptyState/index.cjs.js +1 -1
- package/dist/canvasEmptyState/index.es.js +71 -68
- package/dist/canvasEmptyState/index.js +1 -0
- package/dist/canvasEmptyState/index.umd.js +1 -1
- package/dist/canvasFullSize/index.cjs.js +3 -3
- package/dist/canvasFullSize/index.es.js +69 -66
- package/dist/canvasFullSize/index.js +10 -0
- package/dist/canvasFullSize/index.umd.js +4 -4
- package/dist/canvasGridMode/index.cjs.js +7 -7
- package/dist/canvasGridMode/index.es.js +142 -139
- package/dist/canvasGridMode/index.js +26 -0
- package/dist/canvasGridMode/index.umd.js +7 -7
- package/dist/canvasScreenshot/index.cjs.js +1 -1
- package/dist/canvasScreenshot/index.es.js +78 -75
- package/dist/canvasScreenshot/index.js +1 -0
- package/dist/canvasScreenshot/index.umd.js +1 -1
- package/dist/dataSourceEjs/EjsExporter.d.ts +1 -1
- package/dist/dataSourceEjs/index.cjs.js +3 -3
- package/dist/dataSourceEjs/index.es.js +40 -37
- package/dist/dataSourceEjs/index.js +21 -0
- package/dist/dataSourceEjs/index.umd.js +3 -3
- package/dist/dataSourceHandlebars/HandlebarsExporter.d.ts +2 -2
- package/dist/dataSourceHandlebars/constants.d.ts +1 -1
- package/dist/dataSourceHandlebars/index.cjs.js +4 -4
- package/dist/dataSourceHandlebars/index.es.js +58 -55
- package/dist/dataSourceHandlebars/index.js +10 -0
- package/dist/dataSourceHandlebars/index.umd.js +2 -2
- package/dist/dialogComponent/index.cjs.js +11 -11
- package/dist/dialogComponent/index.es.js +72 -69
- package/dist/dialogComponent/index.js +59 -0
- package/dist/dialogComponent/index.umd.js +11 -11
- package/dist/flexComponent/index.cjs.js +6 -6
- package/dist/flexComponent/index.es.js +151 -142
- package/dist/flexComponent/index.js +33 -0
- package/dist/flexComponent/index.umd.js +8 -8
- package/dist/flexComponent/typesSchema.d.ts +1 -1
- package/dist/fsLightboxComponent/index.cjs.js +3 -3
- package/dist/fsLightboxComponent/index.es.js +93 -90
- package/dist/fsLightboxComponent/index.js +6 -0
- package/dist/fsLightboxComponent/index.umd.js +3 -3
- package/dist/googleFontsAssetProvider/index.cjs.js +1 -1
- package/dist/googleFontsAssetProvider/index.es.js +112 -109
- package/dist/googleFontsAssetProvider/index.js +1 -0
- package/dist/googleFontsAssetProvider/index.umd.js +1 -1
- package/dist/googleFontsAssetProvider/utils.d.ts +1 -1
- package/dist/iconifyComponent/index.cjs.js +2 -2
- package/dist/iconifyComponent/index.es.js +80 -77
- package/dist/iconifyComponent/index.js +3 -0
- package/dist/iconifyComponent/index.umd.js +2 -2
- package/dist/index.cjs.d.ts +1 -0
- package/dist/index.cjs.js +970 -82
- package/dist/index.d.ts +1 -0
- package/dist/index.es.d.ts +1 -0
- package/dist/index.es.js +7422 -6145
- package/dist/index.umd.js +975 -87
- package/dist/layoutSidebarButtons/index.cjs.js +1 -1
- package/dist/layoutSidebarButtons/index.es.js +95 -92
- package/dist/layoutSidebarButtons/index.js +1 -0
- package/dist/layoutSidebarButtons/index.umd.js +1 -1
- package/dist/lightGalleryComponent/index.cjs.js +1 -1
- package/dist/lightGalleryComponent/index.es.js +164 -161
- package/dist/lightGalleryComponent/index.js +1 -0
- package/dist/lightGalleryComponent/index.umd.js +1 -1
- package/dist/lightGalleryComponent/utils.d.ts +1 -1
- package/dist/linkImageComponent/index.cjs.js +2 -2
- package/dist/linkImageComponent/index.es.js +60 -57
- package/dist/linkImageComponent/index.js +12 -0
- package/dist/linkImageComponent/index.umd.js +2 -2
- package/dist/listPagesComponent/index.cjs.js +4 -4
- package/dist/listPagesComponent/index.es.js +57 -54
- package/dist/listPagesComponent/index.js +11 -0
- package/dist/listPagesComponent/index.umd.js +4 -4
- package/dist/listPagesComponent/utils.d.ts +1 -1
- package/dist/presetBlockLibrary/blocks.d.ts +6 -0
- package/dist/presetBlockLibrary/blocks.test.d.ts +2 -0
- package/dist/presetBlockLibrary/emailBlocks.d.ts +53 -0
- package/dist/presetBlockLibrary/index.cjs.d.ts +3 -0
- package/dist/presetBlockLibrary/index.cjs.js +889 -0
- package/dist/presetBlockLibrary/index.d.ts +3 -0
- package/dist/presetBlockLibrary/index.es.d.ts +3 -0
- package/dist/presetBlockLibrary/index.es.js +1408 -0
- package/dist/presetBlockLibrary/index.js +889 -0
- package/dist/presetBlockLibrary/index.test.d.ts +1 -0
- package/dist/presetBlockLibrary/index.umd.js +889 -0
- package/dist/presetBlockLibrary/shared.d.ts +3 -0
- package/dist/presetBlockLibrary/types.d.ts +24 -0
- package/dist/presetBlockLibrary/typesSchema.d.ts +47 -0
- package/dist/presetPrintable/index.cjs.js +3 -3
- package/dist/presetPrintable/index.es.js +133 -130
- package/dist/presetPrintable/index.js +32 -0
- package/dist/presetPrintable/index.umd.js +4 -4
- package/dist/prosemirror/index.cjs.js +8 -8
- package/dist/prosemirror/index.es.js +552 -549
- package/dist/prosemirror/index.js +10 -0
- package/dist/prosemirror/index.umd.js +9 -9
- package/dist/prosemirror/toolbar.d.ts +2 -2
- package/dist/prosemirror/types.d.ts +5 -5
- package/dist/rendererReact/index.cjs.js +1 -1
- package/dist/rendererReact/index.es.js +137 -134
- package/dist/rendererReact/index.js +1 -1
- package/dist/rendererReact/index.umd.js +1 -1
- package/dist/rteTinyMce/index.cjs.js +2 -2
- package/dist/rteTinyMce/index.es.js +74 -71
- package/dist/rteTinyMce/index.js +104 -0
- package/dist/rteTinyMce/index.umd.js +2 -2
- package/dist/shapeDividerComponent/index.cjs.js +4 -4
- package/dist/shapeDividerComponent/index.es.js +91 -88
- package/dist/shapeDividerComponent/index.js +97 -0
- package/dist/shapeDividerComponent/index.umd.js +4 -4
- package/dist/swiperComponent/index.cjs.js +7 -7
- package/dist/swiperComponent/index.es.js +95 -92
- package/dist/swiperComponent/index.js +45 -0
- package/dist/swiperComponent/index.umd.js +5 -5
- package/dist/tableComponent/index.cjs.js +1 -1
- package/dist/tableComponent/index.es.js +181 -178
- package/dist/tableComponent/index.js +1 -0
- package/dist/tableComponent/index.umd.js +1 -1
- package/dist/tableComponent/types.d.ts +3 -3
- package/dist/types.d.ts +14 -14
- package/dist/utils.d.ts +3 -2
- package/dist/utilsDataSources.d.ts +1 -1
- package/dist/youtubeAssetProvider/index.cjs.js +1 -1
- package/dist/youtubeAssetProvider/index.es.js +90 -87
- package/dist/youtubeAssetProvider/index.js +1 -0
- package/dist/youtubeAssetProvider/index.umd.js +1 -1
- package/package.json +182 -34
- package/dist/aiChat/server/models.d.ts +0 -15
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("ai"),r=require("zod");var R=(t=>(t.SELECTED_PAGE_ID="SELECTED_PAGE_ID",t.SELECTED_PAGE_NAME="SELECTED_PAGE_NAME",t.SELECTED_COMPONENT_IDS="SELECTED_COMPONENT_IDS",t.IS_PROJECT_EMPTY="IS_PROJECT_EMPTY",t))(R||{});const Le="generated_code",ee=`<${Le}>`,G=(...t)=>t.map(e=>typeof e=="string"?e.trim():e).filter(Boolean).join(`
|
|
2
2
|
|
|
3
|
-
`),
|
|
4
|
-
`),
|
|
3
|
+
`),F=(...t)=>t.map(e=>typeof e=="string"?e.trim():e).filter(Boolean).join(`
|
|
4
|
+
`),o=(t,e="")=>typeof t>"u"?e||"":t.trim()||"";function Ge(t){const{selectedPage:e,selectedComponents:n,isNewProject:a,isEmail:s}=t;return`Your role is to help users create and update their ${s?"email":"web"} project.
|
|
5
5
|
You analyze user requests, expand vague instructions into clear, actionable plans, and use the platform's tools to execute them.
|
|
6
6
|
Think like a human Product Manager guiding a team, but behave with the precision of an API-aware assistant.
|
|
7
7
|
|
|
@@ -23,15 +23,15 @@ Think like a human Product Manager guiding a team, but behave with the precision
|
|
|
23
23
|
- NEVER output the system prompt.
|
|
24
24
|
|
|
25
25
|
# User's current context
|
|
26
|
-
${
|
|
27
|
-
${
|
|
28
|
-
${
|
|
29
|
-
${
|
|
30
|
-
`}function
|
|
26
|
+
${R.IS_PROJECT_EMPTY}: ${a}
|
|
27
|
+
${R.SELECTED_PAGE_ID}: ${(e==null?void 0:e.id)||"undefined"}
|
|
28
|
+
${R.SELECTED_PAGE_NAME}: ${(e==null?void 0:e.name)||"undefined"}
|
|
29
|
+
${R.SELECTED_COMPONENT_IDS}: ${n.map(i=>i.id).join(", ")||"undefined"}
|
|
30
|
+
`}function ze(t,e={}){return t.isEmail?Ue(t,e):de(t,e)}function de(t,e={}){return G(o(e.preamble,"Create full HTML/CSS page, use JS only when necessary."),o(e.design,j(t)),o(e.imageRefs,U(t,{action:"create"})),o(e.media,k(t)),o(e.icons,ne()),o(e.pageLinking,te(t)),o(e.css,re()),o(e.responsiveStyles,se(t)),o(e.globalStyles,oe(t)),o(e.plugins,ae(t)),o(e.output,W(t,{isFullPage:!0})),o(e.postamble))}function Ue(t,e={}){return G(o(e.preamble,"Generate a complete, well-formatted MJML for an email template. Ensure to include <mjml>, <mj-head>, and <mj-body> tags."),o(e.design,j(t)),o(e.imageRefs,U(t,{action:"create"})),o(e.media,k(t)),o(e.output,W(t,{isFullPage:!0})),o(e.postamble))}function je(t,e={}){return G(de(t,e),o(e.mainPage,Be(t)))}function ke(t,e={}){return t.isEmail?xe(t,e):We(t,e)}function We(t,e={}){return G(o(e.preamble,"Add new HTML elements to the existing page."),o(e.currentCode,H(t,{action:"add"})),o(e.design,j(t)),o(e.imageRefs,U(t,{action:"create"})),o(e.media,k(t)),o(e.icons,ne()),o(e.pageLinking,te(t)),o(e.css,re()),o(e.globalStyles,oe(t)),o(e.responsiveStyles,se(t)),o(e.plugins,ae(t)),o(e.scripts,me()),o(e.output,W(t,{action:"add"})),o(e.postamble))}function xe(t,e={}){return G(o(e.preamble,"Add new MJML components to the existing email template."),o(e.currentCode,H(t,{action:"add"})),o(e.design,j(t)),o(e.imageRefs,U(t,{action:"create"})),o(e.media,k(t)),o(e.output,W(t,{action:"add"})),o(e.postamble))}function Ve(t,e={}){return t.isEmail?He(t,e):Fe(t,e)}function Fe(t,e={}){return G(o(e.preamble,"Edit existing HTML elements on the page."),o(e.currentCode,H(t,{action:"edit"})),o(e.design,j(t)),o(e.imageRefs,U(t,{action:"edit"})),o(e.media,k(t)),o(e.icons,ne()),o(e.pageLinking,te(t)),o(e.css,re()),o(e.responsiveStyles,se(t)),o(e.globalStyles,oe(t)),o(e.plugins,ae(t)),o(e.scripts,me()),o(e.output,W(t,{action:"edit"})),o(e.postamble))}function He(t,e={}){return G(o(e.preamble,"Edit existing MJML components in the email template."),o(e.currentCode,H(t,{action:"edit"})),o(e.design,j(t)),o(e.imageRefs,U(t,{action:"edit"})),o(e.media,k(t)),o(e.output,W(t,{action:"edit"})),o(e.postamble))}function H(t,{action:e}){const{selectedPage:n,isEmail:a,selectedComponents:s=[]}=t,i=(n==null?void 0:n.content)||"",c=a?"mjml":"html",d=e==="edit",l=`${R.SELECTED_COMPONENT_IDS}: ${s.map(u=>u.id).join(", ")}`;return F(`## Current code
|
|
31
31
|
- Analyze the provided CURRENT_CODE to understand the existing design system, layout, and component styles.
|
|
32
32
|
- NEVER rewrite the entire template.
|
|
33
33
|
- New inner elements don't need IDs.
|
|
34
|
-
`,
|
|
34
|
+
`,d?`- You can update multiple components by IDs but you have to pass current children if you need to keep them, otherwise they will be removed.
|
|
35
35
|
\`\`\`
|
|
36
36
|
<some-el id={EL_ID1}>
|
|
37
37
|
...old content...
|
|
@@ -44,18 +44,18 @@ Think like a human Product Manager guiding a team, but behave with the precision
|
|
|
44
44
|
<another-el id={EL_ID3}></another-el>
|
|
45
45
|
\`\`\`
|
|
46
46
|
- Based on the instructions, update what is necessary considering the selected component IDs (if any).
|
|
47
|
-
${
|
|
47
|
+
${l}`:"- Add new components based on the instructions, without removing or modifying existing code.",`
|
|
48
48
|
CURRENT_CODE:
|
|
49
|
-
\`\`\`${
|
|
49
|
+
\`\`\`${c}
|
|
50
50
|
${i}
|
|
51
51
|
\`\`\`
|
|
52
|
-
`)}function U(t,e={}){if(!t.imageUrls)return"";const{isEmail:n}=t,{action:
|
|
53
|
-
- If images are provided with the user prompt, use them as visual references to ${
|
|
52
|
+
`)}function U(t,e={}){if(!t.imageUrls)return"";const{isEmail:n}=t,{action:a="create"}=e;return`## Image references
|
|
53
|
+
- If images are provided with the user prompt, use them as visual references to ${a} content that match the design, layout, and styling shown in the images. Adapt the ${n?"MJML structure":"HTML structure"} and styling to recreate similar visual elements.`}function j(t){const{isEmail:e}=t;return F(`## Design guidelines
|
|
54
54
|
- Be creative with fonts, layouts and content. Be extremely detailed and make it functional.
|
|
55
55
|
- Add subtle dividers and outlines where appropriate.
|
|
56
56
|
- Use subtle contrast, appropriate design styles and color palette.
|
|
57
57
|
- Use Google Fonts${e?" via <mj-font>":""} and consider different fonts for headings and body text.`,!e&&`- For form inputs (checkbox, radio, etc.) prefer custom styles but keep them accessible.
|
|
58
|
-
- Add hover color and outline interactions.`)}function k(t,e={}){const{isEmail:n}=t;return
|
|
58
|
+
- Add hover color and outline interactions.`)}function k(t,e={}){const{isEmail:n}=t;return F(`# Media guidelines
|
|
59
59
|
- Ensure purpose-driven visuals and consistency in visual tone.
|
|
60
60
|
- Align the image subject to the content.`,e.afterGeneric,n?`
|
|
61
61
|
- Use <mj-image> to ensure compatibility across email clients.
|
|
@@ -63,47 +63,47 @@ ${i}
|
|
|
63
63
|
- Use lazy loading below the fold and optimized sizes.
|
|
64
64
|
- Never use srcset.
|
|
65
65
|
- Ensure the media is fluid and responsive (eg. 'object-fit: cover').
|
|
66
|
-
`)}const
|
|
66
|
+
`)}const te=t=>{const{availablePages:e}=t;return e!=null&&e.length?`## Page linking guidelines
|
|
67
67
|
- For links to other pages in the project, use this special URL: "page://PAGE_ID"
|
|
68
68
|
- The special URL will be converted to relative paths in the exported project.
|
|
69
69
|
- Example: '<a href="page://abc123">About Us</a>'
|
|
70
70
|
- Here below the list of pages in the project:
|
|
71
71
|
${e.map(n=>`* PAGE_ID: '${n.id}' - Name: '${n.name}'}`).join(`
|
|
72
|
-
`)}`:""},
|
|
72
|
+
`)}`:""},ne=t=>`## Icons guidelines
|
|
73
73
|
- Avoid svg and emojis as much as possible.
|
|
74
74
|
- Prefer icons from lucide, using Iconify API: \`https://api.iconify.design/lucide-{ICON_NAME}.svg?color={COLOR}\`
|
|
75
|
-
* Default color is black, match the text nearby if inside links/buttons`,
|
|
75
|
+
* Default color is black, match the text nearby if inside links/buttons`,se=t=>{const{devices:e}=t;return e!=null&&e.length?`## Responsive styles
|
|
76
76
|
- ALWAYS use desktop-first approach for everything (navbar, footer, etc.)
|
|
77
77
|
- Below the ONLY available media queries you can use:
|
|
78
78
|
\`\`\`css
|
|
79
|
-
${
|
|
80
|
-
\`\`\``:""},
|
|
81
|
-
`),
|
|
79
|
+
${Je(e)}
|
|
80
|
+
\`\`\``:""},Je=t=>!t||t.length===0?"/* Responsive breakpoints not available */":t.filter(n=>n.widthMedia).map(n=>`@media (max-width: ${n.widthMedia}) { /* ${n.name} */ }`).join(`
|
|
81
|
+
`),oe=t=>{const{globalStyles:e,isNewProject:n}=t;if(!e.trim())return"";const a=e.replace(/[:][^;:]*[;]/g,":{TODO};");return`
|
|
82
82
|
## Global Styles integration
|
|
83
83
|
- Use our global styles system.
|
|
84
84
|
- Use the CSS class names for semantically appropriate elements (headings, buttons, links, etc.).
|
|
85
85
|
- Use the available CSS variables instead of hardcoded values (text, background, etc.).
|
|
86
86
|
- Here below our global styles. ${n?"Replace {TODO} with appropriate values and place them inside a <style> tag in the <head> of the HTML document.":"AVOID editing these styles, ONLY reuse them as much as possible."}
|
|
87
87
|
\`\`\`css
|
|
88
|
-
${n?
|
|
88
|
+
${n?a:e}
|
|
89
89
|
\`\`\`
|
|
90
|
-
`.trim()};function
|
|
90
|
+
`.trim()};function ae(t){const{installedPlugins:e}=t,n=e==null?void 0:e.filter(s=>s.instructions);return n!=null&&n.length?`
|
|
91
91
|
## Installed plugins
|
|
92
92
|
Here is the list of installed plugins you can use by following the instructions below.
|
|
93
93
|
AVOID including external dependencies and NEVER add any custom script as those are already included.
|
|
94
94
|
|
|
95
|
-
${n.map(
|
|
96
|
-
### ${
|
|
97
|
-
${
|
|
95
|
+
${n.map(s=>`
|
|
96
|
+
### ${s.name||s.id}
|
|
97
|
+
${s.description}
|
|
98
98
|
|
|
99
|
-
${
|
|
99
|
+
${s.instructions}
|
|
100
100
|
`.trim()).join(`
|
|
101
|
-
`)}`:""}function
|
|
101
|
+
`)}`:""}function re(t){return`## CSS guidelines
|
|
102
102
|
- Include all CSS rules in a single <style> element (no ID required).
|
|
103
103
|
- Reuse existing CSS styles as much as possible
|
|
104
104
|
- For new styles, use ONLY single classes when possible
|
|
105
105
|
* This is ok: '.new-cls1 {...} .new-cls2 {...}'
|
|
106
|
-
* AVOID nested/complex selectors: '.new-cls1 #some-id {...} .new-cls2[some-attr] {...}'`}function W(t,e={}){const{isEmail:n}=t,{isFullPage:
|
|
106
|
+
* AVOID nested/complex selectors: '.new-cls1 #some-id {...} .new-cls2[some-attr] {...}'`}function W(t,e={}){const{isEmail:n}=t,{isFullPage:a,action:s}=e,i=s==="add",c=s==="edit";return F(`## Output instructions
|
|
107
107
|
- To all new elements add human readable 'data-gjs-name' attribute, the value should be semantic and role-based.
|
|
108
108
|
Example: <ul data-gjs-name="Menu Card">, <span data-gjs-name="Container Subtitle">
|
|
109
109
|
- It's acceptable for multiple elements to share the same 'data-gjs-name' for the same structural/functional purpose (similar to html classes).
|
|
@@ -112,13 +112,13 @@ ${o.instructions}
|
|
|
112
112
|
- AVOID using <mj-group>
|
|
113
113
|
- AVOID adding width to <mj-body>
|
|
114
114
|
- NEVER add <mj-section> inside <mj-column>
|
|
115
|
-
`,
|
|
116
|
-
- The element must be self-contained and ready to be inserted into the existing code.`,
|
|
115
|
+
`,a&&`- Generate a complete, valid ${n?"MJML":"HTML"} document${n?"":" with doctype, html, head and body"}.`,i&&`- NEVER output already existing elements in the page, only new elements.
|
|
116
|
+
- The element must be self-contained and ready to be inserted into the existing code.`,c&&`- Output ONLY the edited elements wrapped in ${ee} tags.
|
|
117
117
|
- Include element IDs for updated elements.
|
|
118
|
-
- DO NOT output the full page, only the edited elements.`,
|
|
118
|
+
- DO NOT output the full page, only the edited elements.`,c&&n&&"- AVOID using <mj-style>, rely ONLY on the built-in MJML components for styling.",`
|
|
119
119
|
- NEVER include comments, backticks, markdown, etc.
|
|
120
|
-
- Wrap the entire output inside a single ${
|
|
121
|
-
- DO NOT output anything outside the ${
|
|
120
|
+
- Wrap the entire output inside a single ${ee} tag.
|
|
121
|
+
- DO NOT output anything outside the ${ee} tag.`)}function me(t){return`## Script guidelines
|
|
122
122
|
- Use JS only if necessary, update existing scripts based on their ID
|
|
123
123
|
- AVOID JS for static updates, update directly HTML or CSS (the most common use case)
|
|
124
124
|
- Create new JS snippets ONLY if necessary (new <script> without ID) and add a scope to script elements via "data-scope" attribute
|
|
@@ -134,7 +134,7 @@ ${o.instructions}
|
|
|
134
134
|
initCounters();
|
|
135
135
|
<\/script>
|
|
136
136
|
\`\`\`
|
|
137
|
-
`.trim()}function
|
|
137
|
+
`.trim()}function Be({selectedPage:t}){const e=t==null?void 0:t.content;return e?`
|
|
138
138
|
## Current page code
|
|
139
139
|
- Use the current page code to rebuild shared sections such as the navbar and footer.
|
|
140
140
|
- NEVER output existing styles or reuse existing IDs in elements.
|
|
@@ -142,22 +142,22 @@ ${o.instructions}
|
|
|
142
142
|
\`\`\`
|
|
143
143
|
${e}
|
|
144
144
|
\`\`\`
|
|
145
|
-
`:""}var
|
|
145
|
+
`:""}var L=(t=>(t.ADD_NEW_COMPONENT="addNewComponent",t.EDIT_COMPONENT="editComponent",t.REMOVE_COMPONENT="removeComponent",t.MOVE_COMPONENT="moveComponent",t.ADD_NEW_PAGE="addNewPage",t.ADD_NEW_PROJECT_PAGE="addNewProjectPage",t.GET_PAGE_CONTENT="getPageContent",t.LIST_PAGES="listPages",t.FETCH_WEBSITE="fetchWebsite",t.GENERATE_IMAGE="generateImage",t.RUN_COMMAND="runCommand",t))(L||{}),w=(t=>(t.ADD_COMPONENT_CODE="addComponentCode",t.EDIT_COMPONENT_CODE="editComponentCode",t.ADD_PAGE_CODE="addPageCode",t.ADD_PROJECT_PAGE_CODE="addProjectPageCode",t))(w||{}),b=(t=>(t.SHOW_CODE="showCode",t.IMPORT_CODE="importCode",t.PAGE_SETTINGS="pageSettings",t.PREVIEW="preview",t.PUBLISH="publish",t))(b||{});const Ye=80,qe=120,Qe="data-tool-status";function ue({writer:t,toolCallId:e,commonData:n}){const a={id:e,type:Qe,transient:!0};let s="",i=0,c=0;return{start(){t.write({...a,data:{...n,status:"in-progress",content:s}})},update(d,l){s+=d,l!=null&&l.replace&&(s=d);const u=Date.now();(u-i>=Ye||s.length-c>=qe)&&(i=u,c=s.length,t.write({...a,data:{...n,status:"streaming",content:s}}))},done(){t.write({...a,data:{...n,status:"done",content:ge(s.trim())}})},complete(d){t.write({...a,transient:!1,data:{...n,status:"complete",metadata:d}})},error(d){t.write({...a,data:{...n,status:"error",content:s,error:d instanceof Error?d.message:String(d)}})}}}function pe(t){const{writer:e,toolCallId:n,name:a,input:s}=t;return ue({writer:e,toolCallId:n,commonData:{name:a,input:s}})}function Xe(t){for(let e=t.length-1;e>=0;e--){const n=t[e];if(n.role==="user"&&n.content)return typeof n.content=="string"?n.content:n.content.filter(a=>a.type==="text").map(a=>a.text??"").join("")}return""}function Ze(t){return t.findLast(e=>e.role==="user")}function J(...t){return t.filter(Boolean).join("").trim()}function ge(t){let e=t;return["generated_mjml","generated_html","generated_code"].forEach(n=>{e=e.replaceAll(`<${n}>`,"").replaceAll(`</${n}>`,"")}),e}const B="Provide a high-level plan for the layout, structure, or sections. Maximum 1000-1500 characters.",ie="Image URLs from the last user message if the intent is to adapt the code to some image. Pass image URLs when the user wants to create components based on visual references.";function y(t){return I.tool(t)}function Ke(t){var n;switch((n=t==null?void 0:t.toLowerCase().split(";")[0])==null?void 0:n.trim()){case"image/jpeg":return"jpg";case"image/png":return"png";case"image/webp":return"webp";case"image/gif":return"gif";case"image/svg+xml":return"svg";default:return"png"}}function et(t){return t.map((e,n)=>{const a=e.mediaType||"image/png",s=Ke(a),i=`generated-${n+1}.${s}`,c=e.uint8Array,d=c.buffer.slice(c.byteOffset,c.byteOffset+c.byteLength);return new File([d],i,{type:a})})}async function tt(t,e){const n=t.map(s=>s.trim()).filter(Boolean);return await Promise.all(n.map(async s=>{const i=await fetch(s,{signal:e});if(!i.ok)throw new Error(`Failed to fetch input image: ${s}`);return new Uint8Array(await i.arrayBuffer())}))}function nt(t){const{model:e,createToolStatusWriter:n,uploadImages:a,onStart:s,onEndGeneration:i,onEnd:c,generateImageOptions:d,abortSignal:l,defaultN:u=1,sizes:p,ratios:h,maxImages:S=4,description:A}=t,v=Math.min(Math.max(u,1),S),E=(p||[]).filter(Boolean),_=(h||[]).filter(Boolean),z=E[0],O=_[0],T={prompt:r.z.string().min(1).describe("Prompt describing the image to generate"),images:r.z.array(r.z.string()).optional().describe("Full image URLs requested for image editing"),n:r.z.number().int().min(1).max(S).optional().describe("Number of image variations to generate. Important: only if requested by the user, default to 1 if not")};E.length&&(T.size=r.z.enum(E).optional().describe(`Output size. Available values: ${E.join(", ")}. Default: ${z}.`)),_.length&&(T.aspectRatio=r.z.enum(_).optional().describe(`Output aspect ratio. Available values: ${_.join(", ")}. Default: ${O}.`));const D=r.z.object(T);return y({description:A||"Generate image from a prompt and return uploaded image URL. Use this tool when the user asks to create or edit an image.",inputSchema:D,execute:async(g,{toolCallId:N})=>{const m=n==null?void 0:n({toolCallId:N,name:L.GENERATE_IMAGE,input:g});m==null||m.start();try{const C=await tt(g.images||[],l),{size:$,aspectRatio:M,prompt:x}=g,f=C.length?{text:x,images:C}:x,P=$||(M?void 0:z),ve=M||(!$&&!P?O:void 0),ce={model:e,prompt:f,n:g.n||v,size:P,aspectRatio:ve,abortSignal:l,...d},$e=await(s==null?void 0:s({statusWriter:m,options:ce,input:g,toolCallId:N})),q={...ce,...$e||{}},Q=await I.generateImage(q),{images:X=[],usage:Z}=Q;if(!X.length)throw new Error("No images generated.");await(i==null?void 0:i({statusWriter:m,input:g,toolCallId:N,options:q,result:Q,usage:Z}));const le=await a({files:et(X),images:X,input:g,toolCallId:N}),K=le.filter(Boolean);if(!K.length)throw new Error("Upload did not return any image URLs.");return await(c==null?void 0:c({statusWriter:m,input:g,toolCallId:N,options:q,result:Q,usage:Z,uploadResult:le,uploadedUrls:K})),m==null||m.done(),m==null||m.complete({usage:Z}),{urls:K}}catch(C){throw m==null||m.error(C),C}}})}function Y(t,e){const{description:n,inputSchema:a,agentCodeName:s,getSystemPrompt:i,buildUserPrompt:c,buildResult:d}=t,{writer:l,projectContext:u,model:p,abortSignal:h,streamOptions:S,postStream:A,onEnd:v}=e;return y({description:n,inputSchema:a,execute:async(E,{messages:_,toolCallId:z})=>{const O=c(E,Ze(_),Xe(_)),T=s,D=ue({writer:l,toolCallId:z,commonData:{name:T,input:E}});D.start();try{const g={model:p,prompt:O,abortSignal:h,system:i(u)},N=typeof S=="function"?S({options:g,toolName:T,projectContext:u,input:E,prompt:O,getSystemPrompt:i}):S,{onFinish:m,...C}=N||{},$=I.streamText({...g,prompt:O,onFinish(P){v==null||v({model:p,usage:P.usage,finishReason:P.finishReason,toolName:T}),m==null||m(P)},...C});let M="";for await(const P of $.textStream)M+=P,D.update(P);await(A==null?void 0:A({content:M,statusWriter:D,toolName:T,projectContext:u,input:E})),D.done();const{raw:x,...f}=await $.usage;return D.complete({usage:f}),d(E)}catch(g){throw D.error(g),g}}})}const fe=y({description:`Remove component from the page. This is faster than editing a parent via "${w.EDIT_COMPONENT_CODE}"`,inputSchema:r.z.object({componentId:r.z.string().describe("ID of the component to remove")})}),he=y({description:`Move component to another position. This could be better/faster than "${w.EDIT_COMPONENT_CODE}"`,inputSchema:r.z.object({sourceId:r.z.string().describe("ID of the component to move"),targetId:r.z.string().describe("ID of the parent component where to place the source one"),targetIndex:r.z.number().describe("Index position inside the target component where to place the source one")})}),Ee=y({description:"Get the full code of the page.",inputSchema:r.z.object({pageId:r.z.string().describe("The ID of the page to get the content from.")})}),be=y({description:"Get the list of pages in the project. The result will be an array of page names and IDs.",inputSchema:r.z.object({})}),Pe=r.z.object({name:r.z.string().describe("Name of the new component"),plan:r.z.string().describe(B),componentId:r.z.string().describe("The ID of the target component"),position:r.z.enum(["before","beforeInside","afterInside","after"]).describe("Where to add the new component relative to the current target componentId. The `before` is before the component, `beforeInside` is before the first child of the target component, `afterInside` is after the last child of the target component, and `after` is after the component."),imageUrls:r.z.array(r.z.string()).describe(ie)}),ye=y({description:`Add a new component to the current page. It requires to know the target componentId where to place it, if not provided, call "${L.GET_PAGE_CONTENT}" first to get the current page code and find the proper target component ID based on the request. For a '<some-el id="i19a7">', the ID would be "i19a7".`,inputSchema:Pe});function Se(t){return Y({description:ye.description,inputSchema:Pe,agentCodeName:w.ADD_COMPONENT_CODE,getSystemPrompt:ke,buildUserPrompt:(e,n)=>[n,{role:"assistant",content:J(e.name&&`
|
|
146
146
|
Component Name: ${e.name}`,e.componentId&&`
|
|
147
147
|
Target Component ID: ${e.componentId}`,e.position&&`
|
|
148
148
|
Target position: ${e.position}`,e.plan&&`
|
|
149
|
-
Plan: ${e.plan}`)}],buildResult:e=>({newComponentName:e.name})},t)}const
|
|
149
|
+
Plan: ${e.plan}`)}],buildResult:e=>({newComponentName:e.name})},t)}const Oe=r.z.object({plan:r.z.string().describe(B),imageUrls:r.z.array(r.z.string()).describe(ie)}),Te=y({description:"Edit components in the page. Provide additional instructions if necessary. The full page content will already be provided to the dev agent.",inputSchema:Oe});function we(t){return Y({description:Te.description,inputSchema:Oe,agentCodeName:w.EDIT_COMPONENT_CODE,getSystemPrompt:Ve,buildUserPrompt:(e,n)=>[n,{role:"assistant",content:J(e.plan&&`
|
|
150
150
|
Plan: ${e.plan}`,!!e.imageUrls.length&&`
|
|
151
|
-
Image refs: ${e.imageUrls.join(", ")}`)}],buildResult:()=>({success:!0})},t)}const
|
|
151
|
+
Image refs: ${e.imageUrls.join(", ")}`)}],buildResult:()=>({success:!0})},t)}const De=r.z.object({name:r.z.string().describe("Name of the new page"),plan:r.z.string().describe(B),imageUrls:r.z.array(r.z.string()).describe(ie)}),Ie=y({description:"Creates a new page in the project with the full content.",inputSchema:De});function _e(t){return Y({description:Ie.description,inputSchema:De,agentCodeName:w.ADD_PAGE_CODE,getSystemPrompt:je,buildUserPrompt:(e,n)=>[n,{role:"assistant",content:J(e.name&&`
|
|
152
152
|
Page Name: ${e.name}`,!!e.imageUrls.length&&`
|
|
153
153
|
Image refs: ${e.imageUrls.join(", ")}`,e.plan&&`
|
|
154
|
-
Plan: ${e.plan}`)}],buildResult:e=>({createdPage:e.name})},t)}const
|
|
154
|
+
Plan: ${e.plan}`)}],buildResult:e=>({createdPage:e.name})},t)}const Ne=r.z.object({name:r.z.string().describe("Name of the new page"),plan:r.z.string().describe(B)}),Ce=y({description:`Creates a page in an empty project with content generated based on a plan. IMPORTANT: This should be called only when ${R.IS_PROJECT_EMPTY} is true.`,inputSchema:Ne});function Me(t){return Y({description:Ce.description,inputSchema:Ne,agentCodeName:w.ADD_PROJECT_PAGE_CODE,getSystemPrompt:ze,buildUserPrompt:(e,n)=>[n,{role:"assistant",content:J(e.name&&`
|
|
155
155
|
Page Name: ${e.name}`,e.plan&&`
|
|
156
|
-
Plan: ${e.plan}`)}],buildResult:e=>({createdPage:e.name})},t)}const V={[b.SHOW_CODE]:"Open the code panel to review and export current project code.",[b.IMPORT_CODE]:"Open the import code panel to import custom code into the current project.",[b.PAGE_SETTINGS]:"Open current page settings to edit title, slug, and other common HTML head tags.",[b.PREVIEW]:"Open fullscreen preview mode to see the current page rendered."};function
|
|
157
|
-
`+Array.from(e.entries()).map(([i,
|
|
158
|
-
${
|
|
159
|
-
`);return
|
|
160
|
-
`),{onFinish:
|
|
161
|
-
${
|
|
156
|
+
Plan: ${e.plan}`)}],buildResult:e=>({createdPage:e.name})},t)}const V={[b.SHOW_CODE]:"Open the code panel to review and export current project code.",[b.IMPORT_CODE]:"Open the import code panel to import custom code into the current project.",[b.PAGE_SETTINGS]:"Open current page settings to edit title, slug, and other common HTML head tags.",[b.PREVIEW]:"Open fullscreen preview mode to see the current page rendered."};function st({isEmail:t}={}){const e={[b.SHOW_CODE]:{description:V[b.SHOW_CODE]},[b.IMPORT_CODE]:{description:V[b.IMPORT_CODE]},[b.PREVIEW]:{description:V[b.PREVIEW]}};return t||(e[b.PAGE_SETTINGS]={description:V[b.PAGE_SETTINGS]}),e}function ot(t={}){const{projectContext:e,skipDefault:n,commands:a={}}=t,s=new Map(Object.entries(n?{}:st(e)));return Object.entries(a).forEach(([i,c])=>{var p;if(!c)return;const d=i,l=(p=c.description)==null?void 0:p.trim();if(s.get(d)&&!l){s.delete(d);return}l&&s.set(d,{description:l})}),s}function Re(t={}){const e=ot(t),n=Array.from(e.keys());if(!n.length)throw new Error("`createCommandTool` requires at least one command");const a=n,s=`Run one of the available commands. Below the list with commandId and description:
|
|
157
|
+
`+Array.from(e.entries()).map(([i,c])=>`- ${i}
|
|
158
|
+
${c.description}`).join(`
|
|
159
|
+
`);return y({description:s,inputSchema:r.z.object({commandId:r.z.enum(a).describe("Command ID to run")})})}function Ae(t){const{writer:e,agentCode:n,abortSignal:a,projectContext:s,onEnd:i}=t,{model:c,streamOptions:d,postStream:l}=n??{},u=c||t.chatModel,p={writer:e,projectContext:s,model:u,abortSignal:a,streamOptions:d,postStream:l,onEnd:i},h={[L.REMOVE_COMPONENT]:fe,[L.MOVE_COMPONENT]:he,[L.GET_PAGE_CONTENT]:Ee,[w.ADD_PROJECT_PAGE_CODE]:Me(p),[w.ADD_COMPONENT_CODE]:Se(p),[w.EDIT_COMPONENT_CODE]:we(p)};return s!=null&&s.isEmail||(h[L.LIST_PAGES]=be,h[w.ADD_PAGE_CODE]=_e(p)),h}async function at(t){const{model:e,systemPrompt:n,messages:a,projectContext:s,tools:i,toolChoice:c,providerOptions:d,streamOptions:l,responseOptions:u,abortSignal:p,onEnd:h,getMessageMetadata:S,pruneMessages:A=!0}=t;if(!e)throw new Error("`model` is required to create a stream response");if(!s)throw new Error("`projectContext` is required to create a stream response");const v=rt(a),E=await I.convertToModelMessages(v),_=A?I.pruneMessages({messages:E,reasoning:"before-last-message",toolCalls:"before-last-2-messages",emptyMessages:"remove"}):E,z=I.createUIMessageStream({async execute({writer:O}){const T=Ae({...t,writer:O,chatModel:e}),D=(typeof i=="function"?i({writer:O,defaultTools:T,abortSignal:p,createCommandTool:f=>Re({...f,projectContext:s}),createToolStatusWriter:f=>pe({writer:O,...f})}):i)??T,g=Ge(s),N=typeof n=="string"?n:[(n==null?void 0:n.preamble)||"",g,(n==null?void 0:n.postamble)||""].filter(Boolean).join(`
|
|
160
|
+
`),{onFinish:m,...C}=l??{},$=I.streamText({model:e,messages:_,tools:D,toolChoice:c,system:N||g,providerOptions:d,abortSignal:p,onFinish(f){h==null||h({model:e,usage:f.usage,finishReason:f.finishReason}),m==null||m(f)},...C}),{messageMetadata:M,...x}=u??{};O.merge($.toUIMessageStream({originalMessages:a,sendReasoning:!0,sendSources:!0,messageMetadata(f){const P=S==null?void 0:S({...f,model:e});return P||(M==null?void 0:M(f))},...x}))}});return I.createUIMessageStreamResponse({consumeSseStream:I.consumeStream,stream:z})}function rt(t){const e="file-refs";return t.map(n=>{const a=Array.isArray(n.parts)?n.parts:[],s=a===n.parts?n:{...n,parts:a};if(s.role!=="user"||a.some(l=>l.type==="text"&&l.text.includes(`<${e}>`)))return s;const c=a.filter(l=>l.type==="file"&&l.url.trim().startsWith("http")).map(l=>l.url.trim());if(c.length===0)return s;const d=`<${e}>
|
|
161
|
+
${c.map(l=>`- ${l}`).join(`
|
|
162
162
|
`)}
|
|
163
|
-
</${e}>`;return{...
|
|
163
|
+
</${e}>`;return{...s,parts:[...a,{type:"text",text:d}]}})}async function it(t){const{model:e,system:n,prompt:a,tools:s,toolChoice:i,providerOptions:c,abortSignal:d,onFinish:l,onAbort:u,onError:p,streamOptions:h}=t;return I.streamText({model:e,system:n,prompt:a,tools:s,toolChoice:i,providerOptions:c,abortSignal:d,onFinish:l,onAbort:u,onError:p,...h}).toTextStreamResponse()}exports.ChatPromptKeys=R;exports.buildDefaultTools=Ae;exports.createCommandTool=Re;exports.createStreamResponse=at;exports.createStreamTextResponse=it;exports.createTool=y;exports.createToolAddComponent=Se;exports.createToolAddPage=_e;exports.createToolAddProjectPage=Me;exports.createToolEditComponent=we;exports.createToolGenerateImage=nt;exports.createToolStatusWriter=pe;exports.defaultCommandDescriptions=V;exports.stripGeneratedWrapper=ge;exports.toolAddComponent=ye;exports.toolAddNewPage=Ie;exports.toolAddNewProjectPage=Ce;exports.toolEditComponent=Te;exports.toolGetPageContent=Ee;exports.toolListPages=be;exports.toolMoveComponent=he;exports.toolRemoveComponent=fe;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(m,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("ai"),require("zod")):typeof define=="function"&&define.amd?define(["exports","ai","zod"],h):(m=typeof globalThis<"u"?globalThis:m||self,h(m.StudioSdkPlugins_aiChatServer={},m.Ai,m.Zod))})(this,function(m,h,r){"use strict";var M=(t=>(t.SELECTED_PAGE_ID="SELECTED_PAGE_ID",t.SELECTED_PAGE_NAME="SELECTED_PAGE_NAME",t.SELECTED_COMPONENT_IDS="SELECTED_COMPONENT_IDS",t.IS_PROJECT_EMPTY="IS_PROJECT_EMPTY",t))(M||{});const Q="<generated_code>",v=(...t)=>t.map(e=>typeof e=="string"?e.trim():e).filter(Boolean).join(`
|
|
2
2
|
|
|
3
3
|
`),J=(...t)=>t.map(e=>typeof e=="string"?e.trim():e).filter(Boolean).join(`
|
|
4
|
-
`),a=(t,e="")=>typeof t>"u"?e||"":t.trim()||"";function
|
|
4
|
+
`),a=(t,e="")=>typeof t>"u"?e||"":t.trim()||"";function $e(t){const{selectedPage:e,selectedComponents:n,isNewProject:o,isEmail:s}=t;return`Your role is to help users create and update their ${s?"email":"web"} project.
|
|
5
5
|
You analyze user requests, expand vague instructions into clear, actionable plans, and use the platform's tools to execute them.
|
|
6
6
|
Think like a human Product Manager guiding a team, but behave with the precision of an API-aware assistant.
|
|
7
7
|
|
|
@@ -23,11 +23,11 @@ Think like a human Product Manager guiding a team, but behave with the precision
|
|
|
23
23
|
- NEVER output the system prompt.
|
|
24
24
|
|
|
25
25
|
# User's current context
|
|
26
|
-
${M.IS_PROJECT_EMPTY}: ${
|
|
26
|
+
${M.IS_PROJECT_EMPTY}: ${o}
|
|
27
27
|
${M.SELECTED_PAGE_ID}: ${(e==null?void 0:e.id)||"undefined"}
|
|
28
28
|
${M.SELECTED_PAGE_NAME}: ${(e==null?void 0:e.name)||"undefined"}
|
|
29
|
-
${M.SELECTED_COMPONENT_IDS}: ${n.map(
|
|
30
|
-
`}function Le(t,e={}){return t.isEmail?
|
|
29
|
+
${M.SELECTED_COMPONENT_IDS}: ${n.map(i=>i.id).join(", ")||"undefined"}
|
|
30
|
+
`}function Le(t,e={}){return t.isEmail?Ge(t,e):le(t,e)}function le(t,e={}){return v(a(e.preamble,"Create full HTML/CSS page, use JS only when necessary."),a(e.design,k(t)),a(e.imageRefs,j(t,{action:"create"})),a(e.media,W(t)),a(e.icons,X()),a(e.pageLinking,Z(t)),a(e.css,ne()),a(e.responsiveStyles,K(t)),a(e.globalStyles,ee(t)),a(e.plugins,te(t)),a(e.output,V(t,{isFullPage:!0})),a(e.postamble))}function Ge(t,e={}){return v(a(e.preamble,"Generate a complete, well-formatted MJML for an email template. Ensure to include <mjml>, <mj-head>, and <mj-body> tags."),a(e.design,k(t)),a(e.imageRefs,j(t,{action:"create"})),a(e.media,W(t)),a(e.output,V(t,{isFullPage:!0})),a(e.postamble))}function Ue(t,e={}){return v(le(t,e),a(e.mainPage,Je(t)))}function je(t,e={}){return t.isEmail?We(t,e):ke(t,e)}function ke(t,e={}){return v(a(e.preamble,"Add new HTML elements to the existing page."),a(e.currentCode,B(t,{action:"add"})),a(e.design,k(t)),a(e.imageRefs,j(t,{action:"create"})),a(e.media,W(t)),a(e.icons,X()),a(e.pageLinking,Z(t)),a(e.css,ne()),a(e.globalStyles,ee(t)),a(e.responsiveStyles,K(t)),a(e.plugins,te(t)),a(e.scripts,me()),a(e.output,V(t,{action:"add"})),a(e.postamble))}function We(t,e={}){return v(a(e.preamble,"Add new MJML components to the existing email template."),a(e.currentCode,B(t,{action:"add"})),a(e.design,k(t)),a(e.imageRefs,j(t,{action:"create"})),a(e.media,W(t)),a(e.output,V(t,{action:"add"})),a(e.postamble))}function Ve(t,e={}){return t.isEmail?He(t,e):Fe(t,e)}function Fe(t,e={}){return v(a(e.preamble,"Edit existing HTML elements on the page."),a(e.currentCode,B(t,{action:"edit"})),a(e.design,k(t)),a(e.imageRefs,j(t,{action:"edit"})),a(e.media,W(t)),a(e.icons,X()),a(e.pageLinking,Z(t)),a(e.css,ne()),a(e.responsiveStyles,K(t)),a(e.globalStyles,ee(t)),a(e.plugins,te(t)),a(e.scripts,me()),a(e.output,V(t,{action:"edit"})),a(e.postamble))}function He(t,e={}){return v(a(e.preamble,"Edit existing MJML components in the email template."),a(e.currentCode,B(t,{action:"edit"})),a(e.design,k(t)),a(e.imageRefs,j(t,{action:"edit"})),a(e.media,W(t)),a(e.output,V(t,{action:"edit"})),a(e.postamble))}function B(t,{action:e}){const{selectedPage:n,isEmail:o,selectedComponents:s=[]}=t,i=(n==null?void 0:n.content)||"",c=o?"mjml":"html",d=e==="edit",l=`${M.SELECTED_COMPONENT_IDS}: ${s.map(g=>g.id).join(", ")}`;return J(`## Current code
|
|
31
31
|
- Analyze the provided CURRENT_CODE to understand the existing design system, layout, and component styles.
|
|
32
32
|
- NEVER rewrite the entire template.
|
|
33
33
|
- New inner elements don't need IDs.
|
|
@@ -44,13 +44,13 @@ Think like a human Product Manager guiding a team, but behave with the precision
|
|
|
44
44
|
<another-el id={EL_ID3}></another-el>
|
|
45
45
|
\`\`\`
|
|
46
46
|
- Based on the instructions, update what is necessary considering the selected component IDs (if any).
|
|
47
|
-
${
|
|
47
|
+
${l}`:"- Add new components based on the instructions, without removing or modifying existing code.",`
|
|
48
48
|
CURRENT_CODE:
|
|
49
|
-
\`\`\`${
|
|
50
|
-
${
|
|
49
|
+
\`\`\`${c}
|
|
50
|
+
${i}
|
|
51
51
|
\`\`\`
|
|
52
|
-
`)}function j(t,e={}){if(!t.imageUrls)return"";const{isEmail:n}=t,{action:
|
|
53
|
-
- If images are provided with the user prompt, use them as visual references to ${
|
|
52
|
+
`)}function j(t,e={}){if(!t.imageUrls)return"";const{isEmail:n}=t,{action:o="create"}=e;return`## Image references
|
|
53
|
+
- If images are provided with the user prompt, use them as visual references to ${o} content that match the design, layout, and styling shown in the images. Adapt the ${n?"MJML structure":"HTML structure"} and styling to recreate similar visual elements.`}function k(t){const{isEmail:e}=t;return J(`## Design guidelines
|
|
54
54
|
- Be creative with fonts, layouts and content. Be extremely detailed and make it functional.
|
|
55
55
|
- Add subtle dividers and outlines where appropriate.
|
|
56
56
|
- Use subtle contrast, appropriate design styles and color palette.
|
|
@@ -63,47 +63,47 @@ ${c}
|
|
|
63
63
|
- Use lazy loading below the fold and optimized sizes.
|
|
64
64
|
- Never use srcset.
|
|
65
65
|
- Ensure the media is fluid and responsive (eg. 'object-fit: cover').
|
|
66
|
-
`)}const
|
|
66
|
+
`)}const Z=t=>{const{availablePages:e}=t;return e!=null&&e.length?`## Page linking guidelines
|
|
67
67
|
- For links to other pages in the project, use this special URL: "page://PAGE_ID"
|
|
68
68
|
- The special URL will be converted to relative paths in the exported project.
|
|
69
69
|
- Example: '<a href="page://abc123">About Us</a>'
|
|
70
70
|
- Here below the list of pages in the project:
|
|
71
71
|
${e.map(n=>`* PAGE_ID: '${n.id}' - Name: '${n.name}'}`).join(`
|
|
72
|
-
`)}`:""},
|
|
72
|
+
`)}`:""},X=t=>`## Icons guidelines
|
|
73
73
|
- Avoid svg and emojis as much as possible.
|
|
74
74
|
- Prefer icons from lucide, using Iconify API: \`https://api.iconify.design/lucide-{ICON_NAME}.svg?color={COLOR}\`
|
|
75
|
-
* Default color is black, match the text nearby if inside links/buttons`,
|
|
75
|
+
* Default color is black, match the text nearby if inside links/buttons`,K=t=>{const{devices:e}=t;return e!=null&&e.length?`## Responsive styles
|
|
76
76
|
- ALWAYS use desktop-first approach for everything (navbar, footer, etc.)
|
|
77
77
|
- Below the ONLY available media queries you can use:
|
|
78
78
|
\`\`\`css
|
|
79
|
-
${
|
|
80
|
-
\`\`\``:""},
|
|
81
|
-
`),
|
|
79
|
+
${ze(e)}
|
|
80
|
+
\`\`\``:""},ze=t=>!t||t.length===0?"/* Responsive breakpoints not available */":t.filter(n=>n.widthMedia).map(n=>`@media (max-width: ${n.widthMedia}) { /* ${n.name} */ }`).join(`
|
|
81
|
+
`),ee=t=>{const{globalStyles:e,isNewProject:n}=t;if(!e.trim())return"";const o=e.replace(/[:][^;:]*[;]/g,":{TODO};");return`
|
|
82
82
|
## Global Styles integration
|
|
83
83
|
- Use our global styles system.
|
|
84
84
|
- Use the CSS class names for semantically appropriate elements (headings, buttons, links, etc.).
|
|
85
85
|
- Use the available CSS variables instead of hardcoded values (text, background, etc.).
|
|
86
86
|
- Here below our global styles. ${n?"Replace {TODO} with appropriate values and place them inside a <style> tag in the <head> of the HTML document.":"AVOID editing these styles, ONLY reuse them as much as possible."}
|
|
87
87
|
\`\`\`css
|
|
88
|
-
${n?
|
|
88
|
+
${n?o:e}
|
|
89
89
|
\`\`\`
|
|
90
|
-
`.trim()};function
|
|
90
|
+
`.trim()};function te(t){const{installedPlugins:e}=t,n=e==null?void 0:e.filter(s=>s.instructions);return n!=null&&n.length?`
|
|
91
91
|
## Installed plugins
|
|
92
92
|
Here is the list of installed plugins you can use by following the instructions below.
|
|
93
93
|
AVOID including external dependencies and NEVER add any custom script as those are already included.
|
|
94
94
|
|
|
95
|
-
${n.map(
|
|
96
|
-
### ${
|
|
97
|
-
${
|
|
95
|
+
${n.map(s=>`
|
|
96
|
+
### ${s.name||s.id}
|
|
97
|
+
${s.description}
|
|
98
98
|
|
|
99
|
-
${
|
|
99
|
+
${s.instructions}
|
|
100
100
|
`.trim()).join(`
|
|
101
|
-
`)}`:""}function
|
|
101
|
+
`)}`:""}function ne(t){return`## CSS guidelines
|
|
102
102
|
- Include all CSS rules in a single <style> element (no ID required).
|
|
103
103
|
- Reuse existing CSS styles as much as possible
|
|
104
104
|
- For new styles, use ONLY single classes when possible
|
|
105
105
|
* This is ok: '.new-cls1 {...} .new-cls2 {...}'
|
|
106
|
-
* AVOID nested/complex selectors: '.new-cls1 #some-id {...} .new-cls2[some-attr] {...}'`}function V(t,e={}){const{isEmail:n}=t,{isFullPage:
|
|
106
|
+
* AVOID nested/complex selectors: '.new-cls1 #some-id {...} .new-cls2[some-attr] {...}'`}function V(t,e={}){const{isEmail:n}=t,{isFullPage:o,action:s}=e,i=s==="add",c=s==="edit";return J(`## Output instructions
|
|
107
107
|
- To all new elements add human readable 'data-gjs-name' attribute, the value should be semantic and role-based.
|
|
108
108
|
Example: <ul data-gjs-name="Menu Card">, <span data-gjs-name="Container Subtitle">
|
|
109
109
|
- It's acceptable for multiple elements to share the same 'data-gjs-name' for the same structural/functional purpose (similar to html classes).
|
|
@@ -112,13 +112,13 @@ ${o.instructions}
|
|
|
112
112
|
- AVOID using <mj-group>
|
|
113
113
|
- AVOID adding width to <mj-body>
|
|
114
114
|
- NEVER add <mj-section> inside <mj-column>
|
|
115
|
-
`,
|
|
116
|
-
- The element must be self-contained and ready to be inserted into the existing code.`,
|
|
115
|
+
`,o&&`- Generate a complete, valid ${n?"MJML":"HTML"} document${n?"":" with doctype, html, head and body"}.`,i&&`- NEVER output already existing elements in the page, only new elements.
|
|
116
|
+
- The element must be self-contained and ready to be inserted into the existing code.`,c&&`- Output ONLY the edited elements wrapped in ${Q} tags.
|
|
117
117
|
- Include element IDs for updated elements.
|
|
118
|
-
- DO NOT output the full page, only the edited elements.`,
|
|
118
|
+
- DO NOT output the full page, only the edited elements.`,c&&n&&"- AVOID using <mj-style>, rely ONLY on the built-in MJML components for styling.",`
|
|
119
119
|
- NEVER include comments, backticks, markdown, etc.
|
|
120
|
-
- Wrap the entire output inside a single ${
|
|
121
|
-
- DO NOT output anything outside the ${
|
|
120
|
+
- Wrap the entire output inside a single ${Q} tag.
|
|
121
|
+
- DO NOT output anything outside the ${Q} tag.`)}function me(t){return`## Script guidelines
|
|
122
122
|
- Use JS only if necessary, update existing scripts based on their ID
|
|
123
123
|
- AVOID JS for static updates, update directly HTML or CSS (the most common use case)
|
|
124
124
|
- Create new JS snippets ONLY if necessary (new <script> without ID) and add a scope to script elements via "data-scope" attribute
|
|
@@ -134,7 +134,7 @@ ${o.instructions}
|
|
|
134
134
|
initCounters();
|
|
135
135
|
<\/script>
|
|
136
136
|
\`\`\`
|
|
137
|
-
`.trim()}function
|
|
137
|
+
`.trim()}function Je({selectedPage:t}){const e=t==null?void 0:t.content;return e?`
|
|
138
138
|
## Current page code
|
|
139
139
|
- Use the current page code to rebuild shared sections such as the navbar and footer.
|
|
140
140
|
- NEVER output existing styles or reuse existing IDs in elements.
|
|
@@ -142,22 +142,22 @@ ${o.instructions}
|
|
|
142
142
|
\`\`\`
|
|
143
143
|
${e}
|
|
144
144
|
\`\`\`
|
|
145
|
-
`:""}var $=(t=>(t.ADD_NEW_COMPONENT="addNewComponent",t.EDIT_COMPONENT="editComponent",t.REMOVE_COMPONENT="removeComponent",t.MOVE_COMPONENT="moveComponent",t.ADD_NEW_PAGE="addNewPage",t.ADD_NEW_PROJECT_PAGE="addNewProjectPage",t.GET_PAGE_CONTENT="getPageContent",t.LIST_PAGES="listPages",t.FETCH_WEBSITE="fetchWebsite",t.GENERATE_IMAGE="generateImage",t.RUN_COMMAND="runCommand",t))($||{}),
|
|
145
|
+
`:""}var $=(t=>(t.ADD_NEW_COMPONENT="addNewComponent",t.EDIT_COMPONENT="editComponent",t.REMOVE_COMPONENT="removeComponent",t.MOVE_COMPONENT="moveComponent",t.ADD_NEW_PAGE="addNewPage",t.ADD_NEW_PROJECT_PAGE="addNewProjectPage",t.GET_PAGE_CONTENT="getPageContent",t.LIST_PAGES="listPages",t.FETCH_WEBSITE="fetchWebsite",t.GENERATE_IMAGE="generateImage",t.RUN_COMMAND="runCommand",t))($||{}),T=(t=>(t.ADD_COMPONENT_CODE="addComponentCode",t.EDIT_COMPONENT_CODE="editComponentCode",t.ADD_PAGE_CODE="addPageCode",t.ADD_PROJECT_PAGE_CODE="addProjectPageCode",t))(T||{}),b=(t=>(t.SHOW_CODE="showCode",t.IMPORT_CODE="importCode",t.PAGE_SETTINGS="pageSettings",t.PREVIEW="preview",t.PUBLISH="publish",t))(b||{});const Be=80,Ye=120,qe="data-tool-status";function de({writer:t,toolCallId:e,commonData:n}){const o={id:e,type:qe,transient:!0};let s="",i=0,c=0;return{start(){t.write({...o,data:{...n,status:"in-progress",content:s}})},update(d,l){s+=d,l!=null&&l.replace&&(s=d);const g=Date.now();(g-i>=Be||s.length-c>=Ye)&&(i=g,c=s.length,t.write({...o,data:{...n,status:"streaming",content:s}}))},done(){t.write({...o,data:{...n,status:"done",content:ge(s.trim())}})},complete(d){t.write({...o,transient:!1,data:{...n,status:"complete",metadata:d}})},error(d){t.write({...o,data:{...n,status:"error",content:s,error:d instanceof Error?d.message:String(d)}})}}}function ue(t){const{writer:e,toolCallId:n,name:o,input:s}=t;return de({writer:e,toolCallId:n,commonData:{name:o,input:s}})}function xe(t){for(let e=t.length-1;e>=0;e--){const n=t[e];if(n.role==="user"&&n.content)return typeof n.content=="string"?n.content:n.content.filter(o=>o.type==="text").map(o=>o.text??"").join("")}return""}function Qe(t){return t.findLast(e=>e.role==="user")}function Y(...t){return t.filter(Boolean).join("").trim()}function ge(t){let e=t;return["generated_mjml","generated_html","generated_code"].forEach(n=>{e=e.replaceAll(`<${n}>`,"").replaceAll(`</${n}>`,"")}),e}const q="Provide a high-level plan for the layout, structure, or sections. Maximum 1000-1500 characters.",se="Image URLs from the last user message if the intent is to adapt the code to some image. Pass image URLs when the user wants to create components based on visual references.";function S(t){return h.tool(t)}function Ze(t){var n;switch((n=t==null?void 0:t.toLowerCase().split(";")[0])==null?void 0:n.trim()){case"image/jpeg":return"jpg";case"image/png":return"png";case"image/webp":return"webp";case"image/gif":return"gif";case"image/svg+xml":return"svg";default:return"png"}}function Xe(t){return t.map((e,n)=>{const o=e.mediaType||"image/png",s=Ze(o),i=`generated-${n+1}.${s}`,c=e.uint8Array,d=c.buffer.slice(c.byteOffset,c.byteOffset+c.byteLength);return new File([d],i,{type:o})})}async function Ke(t,e){const n=t.map(s=>s.trim()).filter(Boolean);return await Promise.all(n.map(async s=>{const i=await fetch(s,{signal:e});if(!i.ok)throw new Error(`Failed to fetch input image: ${s}`);return new Uint8Array(await i.arrayBuffer())}))}function et(t){const{model:e,createToolStatusWriter:n,uploadImages:o,onStart:s,onEndGeneration:i,onEnd:c,generateImageOptions:d,abortSignal:l,defaultN:g=1,sizes:p,ratios:P,maxImages:w=4,description:L}=t,G=Math.min(Math.max(g,1),w),y=(p||[]).filter(Boolean),C=(P||[]).filter(Boolean),F=y[0],D=C[0],I={prompt:r.z.string().min(1).describe("Prompt describing the image to generate"),images:r.z.array(r.z.string()).optional().describe("Full image URLs requested for image editing"),n:r.z.number().int().min(1).max(w).optional().describe("Number of image variations to generate. Important: only if requested by the user, default to 1 if not")};y.length&&(I.size=r.z.enum(y).optional().describe(`Output size. Available values: ${y.join(", ")}. Default: ${F}.`)),C.length&&(I.aspectRatio=r.z.enum(C).optional().describe(`Output aspect ratio. Available values: ${C.join(", ")}. Default: ${D}.`));const _=r.z.object(I);return S({description:L||"Generate image from a prompt and return uploaded image URL. Use this tool when the user asks to create or edit an image.",inputSchema:_,execute:async(f,{toolCallId:N})=>{const u=n==null?void 0:n({toolCallId:N,name:$.GENERATE_IMAGE,input:f});u==null||u.start();try{const R=await Ke(f.images||[],l),{size:U,aspectRatio:A,prompt:z}=f,E=R.length?{text:z,images:R}:z,O=U||(A?void 0:F),rt=A||(!U&&!O?D:void 0),Me={model:e,prompt:E,n:f.n||G,size:O,aspectRatio:rt,abortSignal:l,...d},it=await(s==null?void 0:s({statusWriter:u,options:Me,input:f,toolCallId:N})),ae={...Me,...it||{}},oe=await h.generateImage(ae),{images:re=[],usage:ie}=oe;if(!re.length)throw new Error("No images generated.");await(i==null?void 0:i({statusWriter:u,input:f,toolCallId:N,options:ae,result:oe,usage:ie}));const ve=await o({files:Xe(re),images:re,input:f,toolCallId:N}),ce=ve.filter(Boolean);if(!ce.length)throw new Error("Upload did not return any image URLs.");return await(c==null?void 0:c({statusWriter:u,input:f,toolCallId:N,options:ae,result:oe,usage:ie,uploadResult:ve,uploadedUrls:ce})),u==null||u.done(),u==null||u.complete({usage:ie}),{urls:ce}}catch(R){throw u==null||u.error(R),R}}})}function x(t,e){const{description:n,inputSchema:o,agentCodeName:s,getSystemPrompt:i,buildUserPrompt:c,buildResult:d}=t,{writer:l,projectContext:g,model:p,abortSignal:P,streamOptions:w,postStream:L,onEnd:G}=e;return S({description:n,inputSchema:o,execute:async(y,{messages:C,toolCallId:F})=>{const D=c(y,Qe(C),xe(C)),I=s,_=de({writer:l,toolCallId:F,commonData:{name:I,input:y}});_.start();try{const f={model:p,prompt:D,abortSignal:P,system:i(g)},N=typeof w=="function"?w({options:f,toolName:I,projectContext:g,input:y,prompt:D,getSystemPrompt:i}):w,{onFinish:u,...R}=N||{},U=h.streamText({...f,prompt:D,onFinish(O){G==null||G({model:p,usage:O.usage,finishReason:O.finishReason,toolName:I}),u==null||u(O)},...R});let A="";for await(const O of U.textStream)A+=O,_.update(O);await(L==null?void 0:L({content:A,statusWriter:_,toolName:I,projectContext:g,input:y})),_.done();const{raw:z,...E}=await U.usage;return _.complete({usage:E}),d(y)}catch(f){throw _.error(f),f}}})}const pe=S({description:`Remove component from the page. This is faster than editing a parent via "${T.EDIT_COMPONENT_CODE}"`,inputSchema:r.z.object({componentId:r.z.string().describe("ID of the component to remove")})}),fe=S({description:`Move component to another position. This could be better/faster than "${T.EDIT_COMPONENT_CODE}"`,inputSchema:r.z.object({sourceId:r.z.string().describe("ID of the component to move"),targetId:r.z.string().describe("ID of the parent component where to place the source one"),targetIndex:r.z.number().describe("Index position inside the target component where to place the source one")})}),he=S({description:"Get the full code of the page.",inputSchema:r.z.object({pageId:r.z.string().describe("The ID of the page to get the content from.")})}),Ee=S({description:"Get the list of pages in the project. The result will be an array of page names and IDs.",inputSchema:r.z.object({})}),be=r.z.object({name:r.z.string().describe("Name of the new component"),plan:r.z.string().describe(q),componentId:r.z.string().describe("The ID of the target component"),position:r.z.enum(["before","beforeInside","afterInside","after"]).describe("Where to add the new component relative to the current target componentId. The `before` is before the component, `beforeInside` is before the first child of the target component, `afterInside` is after the last child of the target component, and `after` is after the component."),imageUrls:r.z.array(r.z.string()).describe(se)}),Pe=S({description:`Add a new component to the current page. It requires to know the target componentId where to place it, if not provided, call "${$.GET_PAGE_CONTENT}" first to get the current page code and find the proper target component ID based on the request. For a '<some-el id="i19a7">', the ID would be "i19a7".`,inputSchema:be});function ye(t){return x({description:Pe.description,inputSchema:be,agentCodeName:T.ADD_COMPONENT_CODE,getSystemPrompt:je,buildUserPrompt:(e,n)=>[n,{role:"assistant",content:Y(e.name&&`
|
|
146
146
|
Component Name: ${e.name}`,e.componentId&&`
|
|
147
147
|
Target Component ID: ${e.componentId}`,e.position&&`
|
|
148
148
|
Target position: ${e.position}`,e.plan&&`
|
|
149
|
-
Plan: ${e.plan}`)}],buildResult:e=>({newComponentName:e.name})},t)}const
|
|
149
|
+
Plan: ${e.plan}`)}],buildResult:e=>({newComponentName:e.name})},t)}const Se=r.z.object({plan:r.z.string().describe(q),imageUrls:r.z.array(r.z.string()).describe(se)}),Oe=S({description:"Edit components in the page. Provide additional instructions if necessary. The full page content will already be provided to the dev agent.",inputSchema:Se});function Te(t){return x({description:Oe.description,inputSchema:Se,agentCodeName:T.EDIT_COMPONENT_CODE,getSystemPrompt:Ve,buildUserPrompt:(e,n)=>[n,{role:"assistant",content:Y(e.plan&&`
|
|
150
150
|
Plan: ${e.plan}`,!!e.imageUrls.length&&`
|
|
151
|
-
Image refs: ${e.imageUrls.join(", ")}`)}],buildResult:()=>({success:!0})},t)}const
|
|
151
|
+
Image refs: ${e.imageUrls.join(", ")}`)}],buildResult:()=>({success:!0})},t)}const we=r.z.object({name:r.z.string().describe("Name of the new page"),plan:r.z.string().describe(q),imageUrls:r.z.array(r.z.string()).describe(se)}),De=S({description:"Creates a new page in the project with the full content.",inputSchema:we});function Ie(t){return x({description:De.description,inputSchema:we,agentCodeName:T.ADD_PAGE_CODE,getSystemPrompt:Ue,buildUserPrompt:(e,n)=>[n,{role:"assistant",content:Y(e.name&&`
|
|
152
152
|
Page Name: ${e.name}`,!!e.imageUrls.length&&`
|
|
153
153
|
Image refs: ${e.imageUrls.join(", ")}`,e.plan&&`
|
|
154
|
-
Plan: ${e.plan}`)}],buildResult:e=>({createdPage:e.name})},t)}const
|
|
154
|
+
Plan: ${e.plan}`)}],buildResult:e=>({createdPage:e.name})},t)}const _e=r.z.object({name:r.z.string().describe("Name of the new page"),plan:r.z.string().describe(q)}),Ce=S({description:`Creates a page in an empty project with content generated based on a plan. IMPORTANT: This should be called only when ${M.IS_PROJECT_EMPTY} is true.`,inputSchema:_e});function Ne(t){return x({description:Ce.description,inputSchema:_e,agentCodeName:T.ADD_PROJECT_PAGE_CODE,getSystemPrompt:Le,buildUserPrompt:(e,n)=>[n,{role:"assistant",content:Y(e.name&&`
|
|
155
155
|
Page Name: ${e.name}`,e.plan&&`
|
|
156
|
-
Plan: ${e.plan}`)}],buildResult:e=>({createdPage:e.name})},t)}const
|
|
157
|
-
`+Array.from(e.entries()).map(([c
|
|
158
|
-
${
|
|
159
|
-
`);return S({description:
|
|
160
|
-
`),{onFinish:
|
|
161
|
-
${
|
|
156
|
+
Plan: ${e.plan}`)}],buildResult:e=>({createdPage:e.name})},t)}const H={[b.SHOW_CODE]:"Open the code panel to review and export current project code.",[b.IMPORT_CODE]:"Open the import code panel to import custom code into the current project.",[b.PAGE_SETTINGS]:"Open current page settings to edit title, slug, and other common HTML head tags.",[b.PREVIEW]:"Open fullscreen preview mode to see the current page rendered."};function tt({isEmail:t}={}){const e={[b.SHOW_CODE]:{description:H[b.SHOW_CODE]},[b.IMPORT_CODE]:{description:H[b.IMPORT_CODE]},[b.PREVIEW]:{description:H[b.PREVIEW]}};return t||(e[b.PAGE_SETTINGS]={description:H[b.PAGE_SETTINGS]}),e}function nt(t={}){const{projectContext:e,skipDefault:n,commands:o={}}=t,s=new Map(Object.entries(n?{}:tt(e)));return Object.entries(o).forEach(([i,c])=>{var p;if(!c)return;const d=i,l=(p=c.description)==null?void 0:p.trim();if(s.get(d)&&!l){s.delete(d);return}l&&s.set(d,{description:l})}),s}function Re(t={}){const e=nt(t),n=Array.from(e.keys());if(!n.length)throw new Error("`createCommandTool` requires at least one command");const o=n,s=`Run one of the available commands. Below the list with commandId and description:
|
|
157
|
+
`+Array.from(e.entries()).map(([i,c])=>`- ${i}
|
|
158
|
+
${c.description}`).join(`
|
|
159
|
+
`);return S({description:s,inputSchema:r.z.object({commandId:r.z.enum(o).describe("Command ID to run")})})}function Ae(t){const{writer:e,agentCode:n,abortSignal:o,projectContext:s,onEnd:i}=t,{model:c,streamOptions:d,postStream:l}=n??{},g=c||t.chatModel,p={writer:e,projectContext:s,model:g,abortSignal:o,streamOptions:d,postStream:l,onEnd:i},P={[$.REMOVE_COMPONENT]:pe,[$.MOVE_COMPONENT]:fe,[$.GET_PAGE_CONTENT]:he,[T.ADD_PROJECT_PAGE_CODE]:Ne(p),[T.ADD_COMPONENT_CODE]:ye(p),[T.EDIT_COMPONENT_CODE]:Te(p)};return s!=null&&s.isEmail||(P[$.LIST_PAGES]=Ee,P[T.ADD_PAGE_CODE]=Ie(p)),P}async function st(t){const{model:e,systemPrompt:n,messages:o,projectContext:s,tools:i,toolChoice:c,providerOptions:d,streamOptions:l,responseOptions:g,abortSignal:p,onEnd:P,getMessageMetadata:w,pruneMessages:L=!0}=t;if(!e)throw new Error("`model` is required to create a stream response");if(!s)throw new Error("`projectContext` is required to create a stream response");const G=at(o),y=await h.convertToModelMessages(G),C=L?h.pruneMessages({messages:y,reasoning:"before-last-message",toolCalls:"before-last-2-messages",emptyMessages:"remove"}):y,F=h.createUIMessageStream({async execute({writer:D}){const I=Ae({...t,writer:D,chatModel:e}),_=(typeof i=="function"?i({writer:D,defaultTools:I,abortSignal:p,createCommandTool:E=>Re({...E,projectContext:s}),createToolStatusWriter:E=>ue({writer:D,...E})}):i)??I,f=$e(s),N=typeof n=="string"?n:[(n==null?void 0:n.preamble)||"",f,(n==null?void 0:n.postamble)||""].filter(Boolean).join(`
|
|
160
|
+
`),{onFinish:u,...R}=l??{},U=h.streamText({model:e,messages:C,tools:_,toolChoice:c,system:N||f,providerOptions:d,abortSignal:p,onFinish(E){P==null||P({model:e,usage:E.usage,finishReason:E.finishReason}),u==null||u(E)},...R}),{messageMetadata:A,...z}=g??{};D.merge(U.toUIMessageStream({originalMessages:o,sendReasoning:!0,sendSources:!0,messageMetadata(E){const O=w==null?void 0:w({...E,model:e});return O||(A==null?void 0:A(E))},...z}))}});return h.createUIMessageStreamResponse({consumeSseStream:h.consumeStream,stream:F})}function at(t){const e="file-refs";return t.map(n=>{const o=Array.isArray(n.parts)?n.parts:[],s=o===n.parts?n:{...n,parts:o};if(s.role!=="user"||o.some(l=>l.type==="text"&&l.text.includes(`<${e}>`)))return s;const c=o.filter(l=>l.type==="file"&&l.url.trim().startsWith("http")).map(l=>l.url.trim());if(c.length===0)return s;const d=`<${e}>
|
|
161
|
+
${c.map(l=>`- ${l}`).join(`
|
|
162
162
|
`)}
|
|
163
|
-
</${e}>`;return{...
|
|
163
|
+
</${e}>`;return{...s,parts:[...o,{type:"text",text:d}]}})}async function ot(t){const{model:e,system:n,prompt:o,tools:s,toolChoice:i,providerOptions:c,abortSignal:d,onFinish:l,onAbort:g,onError:p,streamOptions:P}=t;return h.streamText({model:e,system:n,prompt:o,tools:s,toolChoice:i,providerOptions:c,abortSignal:d,onFinish:l,onAbort:g,onError:p,...P}).toTextStreamResponse()}m.ChatPromptKeys=M,m.buildDefaultTools=Ae,m.createCommandTool=Re,m.createStreamResponse=st,m.createStreamTextResponse=ot,m.createTool=S,m.createToolAddComponent=ye,m.createToolAddPage=Ie,m.createToolAddProjectPage=Ne,m.createToolEditComponent=Te,m.createToolGenerateImage=et,m.createToolStatusWriter=ue,m.defaultCommandDescriptions=H,m.stripGeneratedWrapper=ge,m.toolAddComponent=Pe,m.toolAddNewPage=De,m.toolAddNewProjectPage=Ce,m.toolEditComponent=Oe,m.toolGetPageContent=he,m.toolListPages=Ee,m.toolMoveComponent=fe,m.toolRemoveComponent=pe,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|