@next-bricks/visual-builder 1.39.2 → 1.39.3
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/bricks.json +1 -1
- package/dist/chunks/3831.43a95688.js +2 -0
- package/dist/chunks/3831.43a95688.js.map +1 -0
- package/dist/chunks/chat-conversation.bcc40462.js +2 -0
- package/dist/chunks/chat-conversation.bcc40462.js.map +1 -0
- package/dist/chunks/{main.86d8f0f5.js → main.091e04e3.js} +2 -2
- package/dist/chunks/{main.86d8f0f5.js.map → main.091e04e3.js.map} +1 -1
- package/dist/{index.d9e0726f.js → index.7c65286e.js} +2 -2
- package/dist/{index.d9e0726f.js.map → index.7c65286e.js.map} +1 -1
- package/package.json +2 -2
- package/dist/chunks/3831.2665cba1.js +0 -2
- package/dist/chunks/3831.2665cba1.js.map +0 -1
- package/dist/chunks/chat-conversation.e4ca880f.js +0 -2
- package/dist/chunks/chat-conversation.e4ca880f.js.map +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";(globalThis.webpackChunk_next_bricks_visual_builder=globalThis.webpackChunk_next_bricks_visual_builder||[]).push([[3555],{24969:(e,t,n)=>{function r(e){const t=e.properties.className||[];for(const e of t)if("language-"===e.slice(0,9))return e.slice(9).toLowerCase();return null}n.d(t,{G:()=>r})},37384:(e,t,n)=>{n.d(t,{N:()=>p});var r=n(18769),o=n(31085),a=n(83091),s=n(97447),l=n(46025),i=n(23640),c=n(24360),d=n(71250),u=n(50220);const m={Fragment:o.Fragment,jsx:o.jsx,jsxs:o.jsxs};function p(e){let{content:t,components:n}=e;const[o,p]=(0,r.useState)(null);return(0,r.useEffect)((()=>{let e=!1;return(0,a.l)().use(s.A).use(l.A).use(i.A).use([d.N]).use(u.b).use(c.A,{...m,passNode:!0,components:n}).process(t).then((t=>{e||p(t.result)})).catch((t=>{e||(console.error("Convert markdown failed:",t),p(null))})),()=>{e=!0}}),[n,t]),o}},44705:(e,t,n)=>{n.r(t),n.d(t,{ChatConversation:()=>T,ChatConversationComponent:()=>R});var r,o=n(74635),a=n(70918),s=n(26902),l=n(5536),i=n(86121),c=n(70829),d=n(62740),u=n(18769),m=n.n(u),p=n(7921),g=n(11280),h=(n(65168),n(57035)),f=n(87236);let y,b,v,E,w,k,N,x,A;const{defineElement:S,property:C,event:$}=(0,p.createDecorators)();let T;var L=new WeakMap,_=new WeakMap,B=new WeakMap,M=new WeakSet,F=new WeakMap;class D extends g.ReactNextElement{constructor(){super(...arguments),(0,o.A)(this,M),(0,a.A)(this,L,b(this)),(0,a.A)(this,_,(v(this),E(this))),(0,a.A)(this,B,(w(this),k(this))),(0,a.A)(this,F,(A(this),e=>{(0,l.A)(M,this,N).emit(e)}))}get messages(){return(0,c.A)(L,this)}set messages(e){(0,i.A)(L,this,e)}get errorBoundary(){return(0,c.A)(_,this)}set errorBoundary(e){(0,i.A)(_,this,e)}render(){return m().createElement(R,{host:this,messages:this.messages,errorBoundary:this.errorBoundary,onStoryboardUpdate:(0,c.A)(F,this)})}}function R(e){let{messages:t,host:n,errorBoundary:r,onStoryboardUpdate:o}=e;const a=(0,u.useMemo)((()=>/(?:^|\n)```easy_cmd_vb_block_(page|storyboard)\n([\s\S]*?)\n```(?:$|\n)/gm),[]),s=(0,u.useRef)(new Map),[l,i]=(0,u.useState)([]),c=(0,u.useRef)(!1);(0,u.useEffect)((()=>{for(const n of null!=t?t:[]){var e;if("assistant"!==n.role)continue;let t;a.lastIndex=null!==(e=s.current.get(n.key))&&void 0!==e?e:0;const r=[];let o=!1;for(;t=a.exec(n.content);){s.current.set(n.key,a.lastIndex);const[,e,l]=t;try{const t=JSON.parse(l);"page"===e?(o=!0,r.push(...t)):r.push({...t,type:"item"})}catch(e){console.error("parse storyboard failed:",e)}}o?i(r):r.length>0&&i((e=>[...e,...r]))}}),[a,t]);const[d,p]=(0,u.useState)([]);(0,u.useEffect)((()=>{const e=[],t=new Map;for(const n of l)"block"===n.type?e.push(n):n.storyboard&&t.set(n.uuid,n.storyboard);e.sort(((e,t)=>e.seq-t.seq));const n={brick:"eo-content-layout",children:[]},o={brick:"eo-main-view",children:[{brick:"eo-page-title",slot:"pageTitle",properties:{pageTitle:"测试页面"}}]};let a=!1;for(const s of e)if("全局操作区"===s.name)for(const e of s.children){const n=t.get(e);n&&(o.children.push({...n,properties:{...n.properties,slot:void 0},errorBoundary:r,slot:"toolbar",iid:`item:${e}`,meta:{type:"item",uuid:e,block:{uuid:s.uuid,name:s.name}}}),a=!0)}else{const e=t.get(s.uuid);if(e){const o={...e,children:[],errorBoundary:r,iid:`block:${s.uuid}`,meta:{type:"block",uuid:s.uuid,name:s.name}};a=!0,n.children.push(o);for(const e of s.children){const n=t.get(e);n&&o.children.push({...n,errorBoundary:r,iid:`item:${e}`,meta:{type:"item",uuid:e}})}}else if(!s.hasContainer)for(const e of s.children){const o=t.get(e);o&&(n.children.push({...o,errorBoundary:r,iid:`item:${e}`,meta:{type:"item",uuid:e}}),a=!0)}}o.children.push(n),p((e=>a?[o]:0===e.length?e:[]))}),[l,r]),(0,u.useEffect)((()=>{null==o||o(d)}),[o,d]);const g=(0,u.useMemo)((()=>{let e=n;for(;e;){const t=getComputedStyle(e,null).getPropertyValue("overflow-y");if("auto"===t||"scroll"===t)return e;if(e.parentNode instanceof ShadowRoot)e=e.parentNode.host;else{if(!(e.parentNode instanceof Element))break;e=e.parentNode}}return document.scrollingElement||document.documentElement}),[n]);return(0,u.useEffect)((()=>{c.current||setTimeout((()=>{g.scrollTo(0,g.scrollHeight)}),1)}),[t,g]),(0,u.useEffect)((()=>{const e=()=>{c.current=g.scrollTop+g.clientHeight+6<g.scrollHeight};return g.addEventListener("scroll",e),()=>{g.removeEventListener("scroll",e)}}),[g]),m().createElement(m().Fragment,null,null==t?void 0:t.map(((e,t)=>{var n;return m().createElement(h.V,{key:null!==(n=e.key)&&void 0!==n?n:`index-${t}`,message:e})})))}r=D,({e:[b,v,E,w,k,N,x,A],c:[T,y]}=(0,d.A)(r,[S("visual-builder.chat-conversation",{styleTexts:[f.A]})],[[C({attribute:!1}),1,"messages"],[C({type:Boolean}),1,"errorBoundary"],[$({type:"storyboard.update"}),1,"storyboardUpdate",e=>(0,c.A)(B,e),(e,t)=>(0,i.A)(B,e,t)]],0,(e=>F.has((0,s.A)(e))),g.ReactNextElement)),y()},50220:(e,t,n)=>{n.d(t,{b:()=>u});var r=n(74269),o=n(74650),a=n(934),s=n(53349),l=n(24969);let i=0;a.A.initialize({startOnLoad:!1,theme:"base",themeVariables:{fontSize:"14px",lineColor:"#979797",primaryColor:"#DCD2F3",primaryBorderColor:"#0000001A"}});const c=new DOMParser,d=new XMLSerializer;function u(){return async e=>{const t=[];(0,r.YR)(e,"element",(function(e,n,r){r&&"pre"===r.tagName&&"code"===e.tagName&&"mermaid"===(0,l.G)(e)&&t.push((async()=>{const t="mermaid-"+i++,{svg:l}=await a.A.render(t,(0,o.d)(e)),u=c.parseFromString(l,"text/html"),m=u.querySelector("svg"),p=u.createElementNS("http://www.w3.org/2000/svg","defs");p.innerHTML=`<linearGradient id="linear-gradient-${t}" x1="0%" y1="0%" x2="0%" y2="100%">\n <stop offset="0%" stop-color="#F0EBFA" />\n <stop offset="75%" stop-color="#DED4F4" />\n <stop offset="100%" stop-color="#C5C7FA" />\n</linearGradient>`,m.prepend(p);const g=u.createElementNS("http://www.w3.org/2000/svg","style");g.textContent=`\n#${t} .node rect,\n#${t} .node circle,\n#${t} .node ellipse,\n#${t} .node polygon,\n#${t} .node path {\n fill: url(#linear-gradient-${t});\n}\n#${t} .node rect {\n rx: 4;\n ry: 4;\n}\n#${t} .labelBkg {\n background-color: #f5f8ff;\n}\n#${t} .edgeLabel,\n#${t} .edgeLabel p {\n background-color: transparent;\n}\n#${t} .edgeLabel {\n color: #8c8c8c;\n font-size: 12px;\n}\n`,m.appendChild(g);const h=d.serializeToString(m),f=(0,s.f)(h,{fragment:!0}).children;r.children.splice(n,1,...f),r.properties.className=(r.properties.className||[]).concat("mermaid")})())})),await Promise.all(t)}}},57035:(e,t,n)=>{n.d(t,{V:()=>c});var r=n(18769),o=n.n(r),a=n(53373),s=n.n(a),l=n(37384);const i=(0,n(11280).wrapBrick)("eo-avatar");function c(e){let{message:t}=e;const n=(0,r.useMemo)((()=>{const e=[];if("assistant"===t.role){const n=/(?:^|\n)```(easy_cmd_\S+)\n([\s\S]*?)\n```(?:$|\n)/gm;let r,o=0;for(;r=n.exec(t.content);){const[a,s,l]=r,i=r.index,c=t.content.slice(o,i).trim();c.length>0&&e.push({type:"markdown",content:c}),e.push({type:"command",command:s,content:l.trim(),raw:a}),o=n.lastIndex}const a=t.content.slice(o).trim();a.length>0&&e.push({type:"markdown",content:a})}else e.push({type:"plain",content:t.content});return e}),[t.content,t.role]),a=(0,r.useRef)(null);return(0,r.useEffect)((()=>{const e=a.current;e&&setTimeout((()=>{const n=e.parentElement.querySelectorAll(".texting");for(const e of n)e.classList.remove("texting");if(!t.partial)return;let r=e;for(;r;){const e=r.lastChild;if((null==e?void 0:e.nodeType)!==Node.ELEMENT_NODE||"DETAILS"===(null==e?void 0:e.tagName)&&!e.open){var o;if((null==e?void 0:e.nodeType)!==Node.TEXT_NODE||0!==e.textContent.trim().length||(null===(o=e.previousSibling)||void 0===o?void 0:o.nodeType)!==Node.ELEMENT_NODE)break;r=e.previousSibling}else r=e}r.classList.add("texting")}),1)}),[t.partial,t.content]),o().createElement("div",{className:s()("message",{failed:t.failed})},o().createElement("div",{className:"avatar"},o().createElement(i,{icon:{lib:"easyops",icon:"assistant"===t.role?"robot":"account"},size:"small",className:`role-${t.role}`})),o().createElement("div",{className:"main"},o().createElement("div",{className:"label"},"assistant"===t.role?"Assistant":"You"),o().createElement("div",{className:"content",ref:a},n.map(((e,t)=>o().createElement(d,{key:t,chunk:e}))))))}function d(e){let{chunk:t}=e;return o().createElement(o().Fragment,null,"markdown"===t.type?o().createElement("div",{className:"markdown"},o().createElement(l.N,{content:t.content})):"command"===t.type?o().createElement(o().Fragment,null,o().createElement("details",{className:"command"},o().createElement("summary",null,"```",t.command),o().createElement("pre",null,o().createElement("code",null,t.content)))):o().createElement("div",{className:"plain"},t.content))}},71250:(e,t,n)=>{n.d(t,{N:()=>c});var r=n(74269),o=n(74650),a=n(60798),s=n(63869),l=n(89515),i=n(24969);function c(){function e(e,t,n){if(!n||"pre"!==n.tagName||"code"!==e.tagName)return;const r=(0,i.G)(e);if(null===r||"mermaid"===r)return;let s;try{n.properties.className=(n.properties.className||[]).concat("language-"+r),s=a.L.highlight((0,o.d)(e),r)}catch{return}e.children=s.children}return t=>{(0,r.YR)(t,"element",e)}}a.L.register(s.A),a.L.register(l.A)},76131:(e,t,n)=>{n.d(t,{A:()=>c});var r=n(36758),o=n.n(r),a=n(40935),s=n.n(a),l=n(97745),i=s()(o());i.i(l.A),i.push([e.id,"",""]);const c=i.toString()},87236:(e,t,n)=>{n.d(t,{A:()=>c});var r=n(36758),o=n.n(r),a=n(40935),s=n.n(a),l=n(76131),i=s()(o());i.i(l.A),i.push([e.id,':host{display:block}:host([hidden]){display:none}*{box-sizing:border-box}.message{display:flex;gap:8px}.main{flex:1;min-width:0}.label{font-weight:bold;line-height:28px}.message:not(:last-child){margin-bottom:2em}.invisible-dots{opacity:0}.failed .content{color:var(--color-error)}.command:not(:first-child){margin-top:1em}.command:not(:last-child){margin-bottom:1em}pre{white-space:pre-wrap;background-color:var(--palette-gray-3);border-radius:6px;padding:1em}.markdown > :first-child{margin-top:0}.markdown > :last-child{margin-bottom:0}.avatar{align-self:flex-start;display:flex;align-items:center;justify-content:center}.texting::after{content:" ";animation:texting 2s infinite;white-space:pre}@keyframes texting{0%{content:" "}25%{content:". "}50%{content:".. "}75%{content:"..."}100%{content:" "}}pre[class*="language-"]{overflow:visible}pre[class*="language-"],\ncode[class*="language-"]{white-space:pre-wrap}eo-avatar.role-assistant::part(avatar-icon){background-color:var(--palette-blue-5)}.content{word-wrap:break-word}.plain{white-space:pre-wrap}',""]);const c=i.toString()}}]);
|
|
2
|
-
//# sour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,UAAU,SAASwG,EAAM7F,SAItC,C,yGCjKO,SAASY,IACd,SAASyN,EACPjP,EACAkP,EACA9D,GAEA,IAAKA,GAA6B,QAAnBA,EAAOC,SAAsC,SAAjBrL,EAAKqL,QAC9C,OAGF,MAAM8D,GAAOpP,EAAAA,EAAAA,GAAgBC,GAE7B,GAAa,OAATmP,GAA0B,YAATA,EACnB,OAGF,IAAIpN,EACJ,IACEqJ,EAAOlL,WAAWD,WACfmL,EAAOlL,WAAWD,WAA0B,IAC7CyM,OAAO,YAAcyC,GACvBpN,EAASqN,EAAAA,EAAUC,WAAU7D,EAAAA,EAAAA,GAASxL,GAAOmP,EAC/C,CAAE,MACA,MACF,CAEAnP,EAAKiH,SAAWlF,EAAOkF,QACzB,CACA,OAAQkE,KACND,EAAAA,EAAAA,IAAMC,EAAM,UAAW8D,EAAQ,CAEnC,CAnCAG,EAAAA,EAAUE,SAAS9O,EAAAA,GACnB4O,EAAAA,EAAUE,SAASnF,EAAAA,E,0FCJfoF,EAA0B,IAA4B,KAC1DA,EAAwBC,EAAE,KAE1BD,EAAwBrJ,KAAK,CAACuJ,EAAOnE,GAAI,GAAI,KAE7C,QAAeiE,EAAwB/D,U,0FCLnC+D,EAA0B,IAA4B,KAC1DA,EAAwBC,EAAE,KAE1BD,EAAwBrJ,KAAK,CAACuJ,EAAOnE,GAAI,2iCACqJ,KAE9L,QAAeiE,EAAwB/D,U","sources":["webpack:///../../src/utils.ts","webpack:///../../src/MarkdownComponent.tsx","webpack:///./src/chat-conversation/index.tsx","webpack:///../../src/rehypeMermaid.ts","webpack:///./src/chat-conversation/MessageComponent.tsx","webpack:///../../src/rehypePrism.ts","webpack:///../../shared/markdown/dist/esm/prism-tomorrow.css","webpack:///./src/chat-conversation/styles.shadow.css"],"sourcesContent":["import type { RefractorElement } from \"refractor\";\n\nexport function getCodeLanguage(node: RefractorElement) {\n const className = (node.properties.className as string[]) || [];\n\n for (const classListItem of className) {\n if (classListItem.slice(0, 9) === \"language-\") {\n return classListItem.slice(9).toLowerCase();\n }\n }\n\n return null;\n}\n","import { useEffect, useState } from \"react\";\nimport { Fragment, jsx, jsxs } from \"react/jsx-runtime\";\nimport { unified } from \"unified\";\nimport remarkParse from \"remark-parse\";\nimport remarkGfm from \"remark-gfm\";\nimport remarkToRehype from \"remark-rehype\";\nimport rehypeReact, { Options as RehypeReactOptions } from \"rehype-react\";\nimport type { Components } from \"hast-util-to-jsx-runtime\";\nimport { rehypePrism } from \"./rehypePrism.js\";\nimport { rehypeMermaid } from \"./rehypeMermaid.js\";\n\nconst production = { Fragment, jsx, jsxs };\n\nexport interface MarkdownComponentProps {\n content?: string;\n components?: Partial<Components>;\n}\n\n// Reference https://github.com/remarkjs/react-remark/blob/39553e5f5c9e9b903bebf261788ff45130668de0/src/index.ts\nexport function MarkdownComponent({\n content,\n components,\n}: MarkdownComponentProps) {\n const [reactContent, setReactContent] = useState<JSX.Element | null>(null);\n\n useEffect(() => {\n let ignore = false;\n unified()\n .use(remarkParse)\n .use(remarkGfm)\n .use(remarkToRehype)\n .use([rehypePrism])\n .use(rehypeMermaid)\n .use(rehypeReact, {\n ...production,\n passNode: true,\n components,\n } as RehypeReactOptions)\n .process(content)\n .then((vFile) => {\n if (!ignore) {\n setReactContent(vFile.result);\n }\n })\n .catch((error) => {\n if (!ignore) {\n // eslint-disable-next-line no-console\n console.error(\"Convert markdown failed:\", error);\n setReactContent(null);\n }\n });\n return () => {\n ignore = true;\n };\n }, [components, content]);\n\n return reactContent;\n}\n","import React, { useEffect, useMemo, useRef, useState } from \"react\";\nimport { createDecorators, type EventEmitter } from \"@next-core/element\";\nimport { ReactNextElement } from \"@next-core/react-element\";\nimport \"@next-core/theme\";\nimport type { BrickConf } from \"@next-core/types\";\nimport { MessageComponent } from \"./MessageComponent\";\nimport styleText from \"./styles.shadow.css\";\n\nconst { defineElement, property, event } = createDecorators();\n\nexport interface Message {\n role: \"user\" | \"assistant\";\n content: string;\n key: number;\n partial?: boolean;\n failed?: boolean;\n}\n\nexport interface ChatConversationProps {\n messages?: Message[];\n errorBoundary?: boolean;\n}\n\ntype StoryboardChunk = StoryboardChunkBlock | StoryboardChunkBlockItem;\n\ninterface StoryboardChunkBlock {\n type: \"block\";\n uuid: string;\n children: string[];\n name: string;\n seq: number;\n hasContainer?: boolean;\n}\n\ninterface StoryboardChunkBlockItem {\n type: \"item\";\n uuid: string;\n storyboard?: BrickConf;\n}\n\n/**\n * 用于 Visual Builder 的智能聊天对话列表\n */\nexport\n@defineElement(\"visual-builder.chat-conversation\", {\n styleTexts: [styleText],\n})\nclass ChatConversation\n extends ReactNextElement\n implements ChatConversationProps\n{\n @property({ attribute: false })\n accessor messages: Message[] | undefined;\n\n @property({ type: Boolean })\n accessor errorBoundary: boolean | undefined;\n\n @event({ type: \"storyboard.update\" })\n accessor #storyboardUpdate!: EventEmitter<BrickConf[]>;\n\n #handleStoryboardUpdate = (storyboard: BrickConf[]) => {\n this.#storyboardUpdate.emit(storyboard);\n };\n\n render() {\n return (\n <ChatConversationComponent\n host={this}\n messages={this.messages}\n errorBoundary={this.errorBoundary}\n onStoryboardUpdate={this.#handleStoryboardUpdate}\n />\n );\n }\n}\n\nexport interface ChatConversationComponentProps extends ChatConversationProps {\n host: Element;\n onStoryboardUpdate?: (storyboard: BrickConf[]) => void;\n}\n\nexport function ChatConversationComponent({\n messages,\n host,\n errorBoundary,\n onStoryboardUpdate,\n}: ChatConversationComponentProps) {\n const chunkRegExp = useMemo(\n () =>\n /(?:^|\\n)```easy_cmd_vb_block_(page|storyboard)\\n([\\s\\S]*?)\\n```(?:$|\\n)/gm,\n []\n );\n const lastIndexMapRef = useRef(new Map<number, number>());\n const [chunks, setChunks] = useState<StoryboardChunk[]>([]);\n const manualScrolledRef = useRef(false);\n\n useEffect(() => {\n for (const message of messages ?? []) {\n if (message.role !== \"assistant\") {\n continue;\n }\n chunkRegExp.lastIndex = lastIndexMapRef.current.get(message.key) ?? 0;\n let match: RegExpExecArray | null;\n const newChunks: StoryboardChunk[] = [];\n let newPage = false;\n while ((match = chunkRegExp.exec(message.content))) {\n lastIndexMapRef.current.set(message.key, chunkRegExp.lastIndex);\n const [, type, content] = match;\n try {\n const parsed = JSON.parse(content) as unknown;\n if (type === \"page\") {\n newPage = true;\n newChunks.push(\n ...(parsed as (StoryboardChunkBlock | StoryboardChunkBlockItem)[])\n );\n } else {\n newChunks.push({\n ...(parsed as StoryboardChunkBlockItem),\n type: \"item\",\n });\n }\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(\"parse storyboard failed:\", e);\n }\n }\n if (newPage) {\n setChunks(newChunks);\n } else if (newChunks.length > 0) {\n setChunks((prev) => [...prev, ...newChunks]);\n }\n }\n }, [chunkRegExp, messages]);\n\n const [storyboard, setStoryboard] = useState<BrickConf[]>([]);\n\n useEffect(() => {\n const blocks = [];\n const storyboardMap = new Map<string, BrickConf>();\n for (const chunk of chunks) {\n if (chunk.type === \"block\") {\n blocks.push(chunk);\n } else if (chunk.storyboard) {\n storyboardMap.set(chunk.uuid, chunk.storyboard);\n }\n }\n\n // Sort by seq ascent\n blocks.sort((a, b) => a.seq - b.seq);\n\n const contentLayout: BrickConf = {\n brick: \"eo-content-layout\",\n children: [],\n };\n const main: BrickConf = {\n brick: \"eo-main-view\",\n children: [\n {\n brick: \"eo-page-title\",\n slot: \"pageTitle\",\n properties: {\n pageTitle: \"测试页面\",\n },\n },\n ],\n };\n\n let hasContent = false;\n for (const block of blocks) {\n // No container\n if (block.name === \"全局操作区\") {\n for (const child of block.children) {\n const childBrick = storyboardMap.get(child);\n if (childBrick) {\n main.children.push({\n ...childBrick,\n properties: {\n ...childBrick.properties,\n slot: undefined,\n },\n errorBoundary,\n slot: \"toolbar\",\n iid: `item:${child}`,\n meta: {\n type: \"item\",\n uuid: child,\n block: {\n uuid: block.uuid,\n name: block.name,\n },\n },\n } as BrickConf);\n hasContent = true;\n }\n }\n } else {\n const rawBrick = storyboardMap.get(block.uuid);\n if (rawBrick) {\n const brick: BrickConf = {\n ...rawBrick,\n children: [],\n errorBoundary,\n iid: `block:${block.uuid}`,\n meta: {\n type: \"block\",\n uuid: block.uuid,\n name: block.name,\n },\n } as BrickConf;\n hasContent = true;\n contentLayout.children.push(brick);\n for (const child of block.children) {\n const childBrick = storyboardMap.get(child);\n if (childBrick) {\n brick.children.push({\n ...childBrick,\n errorBoundary,\n iid: `item:${child}`,\n meta: {\n type: \"item\",\n uuid: child,\n },\n } as BrickConf);\n }\n }\n } else if (!block.hasContainer) {\n for (const child of block.children) {\n const childBrick = storyboardMap.get(child);\n if (childBrick) {\n contentLayout.children.push({\n ...childBrick,\n errorBoundary,\n iid: `item:${child}`,\n meta: {\n type: \"item\",\n uuid: child,\n },\n } as BrickConf);\n hasContent = true;\n }\n }\n }\n }\n }\n\n main.children.push(contentLayout);\n\n setStoryboard((prev) =>\n hasContent ? [main] : prev.length === 0 ? prev : []\n );\n }, [chunks, errorBoundary]);\n\n useEffect(() => {\n onStoryboardUpdate?.(storyboard);\n }, [onStoryboardUpdate, storyboard]);\n\n const verticalScrollParent = useMemo(() => {\n // Lookup the nearest scrollable parent (on axis y)\n let current = host;\n while (current) {\n const overflowY = getComputedStyle(current, null).getPropertyValue(\n \"overflow-y\"\n );\n if (overflowY === \"auto\" || overflowY === \"scroll\") {\n return current;\n }\n if (current.parentNode instanceof ShadowRoot) {\n current = current.parentNode.host;\n } else if (current.parentNode instanceof Element) {\n current = current.parentNode;\n } else {\n break;\n }\n }\n return document.scrollingElement || document.documentElement;\n }, [host]);\n\n useEffect(() => {\n if (manualScrolledRef.current) {\n return;\n }\n setTimeout(() => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain\n verticalScrollParent.scrollTo(0, verticalScrollParent.scrollHeight!);\n }, 1);\n }, [messages, verticalScrollParent]);\n\n useEffect(() => {\n const handleScroll = () => {\n manualScrolledRef.current =\n verticalScrollParent.scrollTop +\n verticalScrollParent.clientHeight! +\n 6 <\n verticalScrollParent.scrollHeight;\n };\n verticalScrollParent.addEventListener(\"scroll\", handleScroll);\n return () => {\n verticalScrollParent.removeEventListener(\"scroll\", handleScroll);\n };\n }, [verticalScrollParent]);\n\n return (\n <>\n {messages?.map((message, index) => (\n <MessageComponent\n key={message.key ?? `index-${index}`}\n message={message}\n />\n ))}\n </>\n );\n}\n","import { visit } from \"unist-util-visit\";\nimport { toString } from \"hast-util-to-string\";\nimport type { RefractorElement } from \"refractor\";\nimport mermaid from \"mermaid\";\nimport { fromHtmlIsomorphic } from \"hast-util-from-html-isomorphic\";\nimport { getCodeLanguage } from \"./utils.js\";\n\nlet count = 0;\n\nmermaid.initialize({\n startOnLoad: false,\n theme: \"base\",\n themeVariables: {\n fontSize: \"14px\",\n lineColor: \"#979797\",\n primaryColor: \"#DCD2F3\",\n primaryBorderColor: \"#0000001A\",\n },\n});\n\nconst parser = new DOMParser();\nconst serializer = new XMLSerializer();\n\n// Reference https://github.com/remcohaszing/rehype-mermaid\nexport function rehypeMermaid() {\n return async (tree: RefractorElement) => {\n const promises: Promise<void>[] = [];\n\n function visitor(\n node: RefractorElement,\n index: number | undefined,\n parent: RefractorElement | undefined\n ) {\n if (!parent || parent.tagName !== \"pre\" || node.tagName !== \"code\") {\n return;\n }\n\n const lang = getCodeLanguage(node);\n\n if (lang !== \"mermaid\") {\n return;\n }\n\n promises.push(\n (async () => {\n const id = `mermaid-${count++}`;\n\n const { svg } = await mermaid.render(id, toString(node));\n const root = parser.parseFromString(svg, \"text/html\");\n const svgElement = root.querySelector(\"svg\") as SVGSVGElement;\n\n const defs = root.createElementNS(\n \"http://www.w3.org/2000/svg\",\n \"defs\"\n );\n defs.innerHTML = `<linearGradient id=\"linear-gradient-${id}\" x1=\"0%\" y1=\"0%\" x2=\"0%\" y2=\"100%\">\n <stop offset=\"0%\" stop-color=\"#F0EBFA\" />\n <stop offset=\"75%\" stop-color=\"#DED4F4\" />\n <stop offset=\"100%\" stop-color=\"#C5C7FA\" />\n</linearGradient>`;\n svgElement.prepend(defs);\n\n const style = root.createElementNS(\n \"http://www.w3.org/2000/svg\",\n \"style\"\n );\n style.textContent = `\n#${id} .node rect,\n#${id} .node circle,\n#${id} .node ellipse,\n#${id} .node polygon,\n#${id} .node path {\n fill: url(#linear-gradient-${id});\n}\n#${id} .node rect {\n rx: 4;\n ry: 4;\n}\n#${id} .labelBkg {\n background-color: #f5f8ff;\n}\n#${id} .edgeLabel,\n#${id} .edgeLabel p {\n background-color: transparent;\n}\n#${id} .edgeLabel {\n color: #8c8c8c;\n font-size: 12px;\n}\n`;\n svgElement.appendChild(style);\n\n const modifiedSvg = serializer.serializeToString(svgElement);\n\n const replacements = fromHtmlIsomorphic(modifiedSvg, {\n fragment: true,\n }).children as RefractorElement[];\n parent.children.splice(index!, 1, ...replacements);\n parent.properties.className = (\n (parent.properties.className as string[]) || []\n ).concat(\"mermaid\");\n })()\n );\n }\n\n visit(tree, \"element\", visitor);\n\n await Promise.all(promises);\n };\n}\n","import React, { useEffect, useMemo, useRef } from \"react\";\nimport classNames from \"classnames\";\nimport { MarkdownComponent } from \"@next-shared/markdown\";\nimport { wrapBrick } from \"@next-core/react-element\";\nimport type { AvatarProps, EoAvatar } from \"@next-bricks/basic/avatar\";\nimport type { Message } from \"./index\";\n\nconst WrappedAvatar = wrapBrick<EoAvatar, AvatarProps>(\"eo-avatar\");\n\nexport interface MessageComponentProps {\n message: Message;\n}\n\ntype MessageChunk =\n | MessageChunkPlain\n | MessageChunkMarkdown\n | MessageChunkCommand;\n\ninterface MessageChunkPlain {\n type: \"plain\";\n content: string;\n}\n\ninterface MessageChunkMarkdown {\n type: \"markdown\";\n content: string;\n}\n\ninterface MessageChunkCommand {\n type: \"command\";\n command: string;\n content: string;\n raw: string;\n}\n\nexport function MessageComponent({ message }: MessageComponentProps) {\n const messageChunks = useMemo(() => {\n const chunks: MessageChunk[] = [];\n\n if (message.role === \"assistant\") {\n const chunkRegExp =\n /(?:^|\\n)```(easy_cmd_\\S+)\\n([\\s\\S]*?)\\n```(?:$|\\n)/gm;\n\n let match: RegExpExecArray | null;\n let lastIndex = 0;\n while ((match = chunkRegExp.exec(message.content))) {\n const [fullMatch, command, content] = match;\n const start = match.index;\n const previousText = message.content.slice(lastIndex, start).trim();\n if (previousText.length > 0) {\n chunks.push({\n type: \"markdown\",\n content: previousText,\n });\n }\n chunks.push({\n type: \"command\",\n command,\n content: content.trim(),\n raw: fullMatch,\n });\n lastIndex = chunkRegExp.lastIndex;\n }\n const lastText = message.content.slice(lastIndex).trim();\n if (lastText.length > 0) {\n chunks.push({\n type: \"markdown\",\n content: lastText,\n });\n }\n } else {\n chunks.push({\n type: \"plain\",\n content: message.content,\n });\n }\n\n return chunks;\n }, [message.content, message.role]);\n\n const contentRef = useRef<HTMLDivElement>(null);\n useEffect(() => {\n const contentElement = contentRef.current;\n if (!contentElement) {\n return;\n }\n setTimeout(() => {\n const textingElements =\n contentElement.parentElement.querySelectorAll(\".texting\");\n for (const element of textingElements) {\n element.classList.remove(\"texting\");\n }\n if (!message.partial) {\n return;\n }\n // Find the last text element descendant of the message element,\n // and apply a texting effect to it.\n let current = contentElement as HTMLElement;\n while (current) {\n const lastChild = current.lastChild;\n if (\n lastChild?.nodeType === Node.ELEMENT_NODE &&\n ((lastChild as HTMLElement)?.tagName !== \"DETAILS\" ||\n (lastChild as HTMLDetailsElement).open)\n ) {\n current = lastChild as HTMLElement;\n } else {\n // Handle a special case: the last child is a text node without any\n // non-whitespace content. In such case, we should apply the texting\n // effect to the previous sibling element.\n if (\n lastChild?.nodeType === Node.TEXT_NODE &&\n lastChild.textContent.trim().length === 0 &&\n lastChild.previousSibling?.nodeType === Node.ELEMENT_NODE\n ) {\n current = lastChild.previousSibling as HTMLElement;\n } else {\n break;\n }\n }\n }\n current.classList.add(\"texting\");\n }, 1);\n }, [message.partial, message.content]);\n\n return (\n <div className={classNames(\"message\", { failed: message.failed })}>\n <div className=\"avatar\">\n <WrappedAvatar\n icon={{\n lib: \"easyops\",\n icon: message.role === \"assistant\" ? \"robot\" : \"account\",\n }}\n size=\"small\"\n className={`role-${message.role}`}\n />\n </div>\n <div className=\"main\">\n <div className=\"label\">\n {message.role === \"assistant\" ? \"Assistant\" : \"You\"}\n </div>\n <div className=\"content\" ref={contentRef}>\n {messageChunks.map((chunk, index) => (\n <MessageChunkComponent key={index} chunk={chunk} />\n ))}\n </div>\n </div>\n </div>\n );\n}\n\nfunction MessageChunkComponent({ chunk }: { chunk: MessageChunk }) {\n return (\n <>\n {chunk.type === \"markdown\" ? (\n <div className=\"markdown\">\n <MarkdownComponent content={chunk.content} />\n </div>\n ) : chunk.type === \"command\" ? (\n <>\n <details className=\"command\">\n <summary>```{chunk.command}</summary>\n <pre>\n <code>{chunk.content}</code>\n </pre>\n </details>\n </>\n ) : (\n <div className=\"plain\">{chunk.content}</div>\n )}\n </>\n );\n}\n","import { visit } from \"unist-util-visit\";\nimport { toString } from \"hast-util-to-string\";\nimport { refractor, type RefractorElement } from \"refractor\";\nimport jsx from \"refractor/lang/jsx.js\";\nimport mermaid from \"refractor/lang/mermaid.js\";\nimport { getCodeLanguage } from \"./utils.js\";\n\nrefractor.register(jsx);\nrefractor.register(mermaid);\n\n// Reference https://github.com/mapbox/rehype-prism\nexport function rehypePrism() {\n function visitor(\n node: RefractorElement,\n _index: number | undefined,\n parent: RefractorElement | undefined\n ) {\n if (!parent || parent.tagName !== \"pre\" || node.tagName !== \"code\") {\n return;\n }\n\n const lang = getCodeLanguage(node);\n\n if (lang === null || lang === \"mermaid\") {\n return;\n }\n\n let result;\n try {\n parent.properties.className = (\n (parent.properties.className as string[]) || []\n ).concat(\"language-\" + lang);\n result = refractor.highlight(toString(node), lang);\n } catch {\n return;\n }\n\n node.children = result.children;\n }\n return (tree: RefractorElement) => {\n visit(tree, \"element\", visitor);\n };\n}\n","// Imports\nimport ___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___ from \"../../../../node_modules/css-loader/dist/runtime/noSourceMaps.js\";\nimport ___CSS_LOADER_API_IMPORT___ from \"../../../../node_modules/css-loader/dist/runtime/api.js\";\nimport ___CSS_LOADER_AT_RULE_IMPORT_0___ from \"-!../../../../node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].use[0]!../../../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[1].use[1]!../../../../node_modules/prismjs/themes/prism-tomorrow.css\";\nvar ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___);\n___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___);\n// Module\n___CSS_LOADER_EXPORT___.push([module.id, ``, \"\"]);\n// Exports\nexport default ___CSS_LOADER_EXPORT___.toString();\n","// Imports\nimport ___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___ from \"../../../../node_modules/css-loader/dist/runtime/noSourceMaps.js\";\nimport ___CSS_LOADER_API_IMPORT___ from \"../../../../node_modules/css-loader/dist/runtime/api.js\";\nimport ___CSS_LOADER_AT_RULE_IMPORT_0___ from \"-!../../../../node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].use[0]!../../../../node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[1].use[1]!../../../../shared/markdown/dist/esm/prism-tomorrow.css\";\nvar ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___);\n___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___);\n// Module\n___CSS_LOADER_EXPORT___.push([module.id, `:host{display:block}:host([hidden]){display:none}*{box-sizing:border-box}.message{display:flex;gap:8px}.main{flex:1;min-width:0}.label{font-weight:bold;line-height:28px}.message:not(:last-child){margin-bottom:2em}.invisible-dots{opacity:0}.failed .content{color:var(--color-error)}.command:not(:first-child){margin-top:1em}.command:not(:last-child){margin-bottom:1em}pre{white-space:pre-wrap;background-color:var(--palette-gray-3);border-radius:6px;padding:1em}.markdown > :first-child{margin-top:0}.markdown > :last-child{margin-bottom:0}.avatar{align-self:flex-start;display:flex;align-items:center;justify-content:center}.texting::after{content:\" \";animation:texting 2s infinite;white-space:pre}@keyframes texting{0%{content:\" \"}25%{content:\". \"}50%{content:\".. \"}75%{content:\"...\"}100%{content:\" \"}}pre[class*=\"language-\"]{overflow:visible}pre[class*=\"language-\"],\ncode[class*=\"language-\"]{white-space:pre-wrap}eo-avatar.role-assistant::part(avatar-icon){background-color:var(--palette-blue-5)}.content{word-wrap:break-word}.plain{white-space:pre-wrap}`, \"\"]);\n// Exports\nexport default ___CSS_LOADER_EXPORT___.toString();\n"],"names":["getCodeLanguage","node","className","properties","classListItem","slice","toLowerCase","production","Fragment","jsx","jsxs","MarkdownComponent","_ref","content","components","reactContent","setReactContent","useState","useEffect","ignore","unified","use","remarkParse","remarkGfm","remarkToRehype","rehypePrism","rehypeMermaid","rehypeReact","passNode","process","then","vFile","result","catch","error","console","defineElement","property","event","createDecorators","_ChatConversation","_A","WeakMap","_B","_C","_ChatConversation_brand","WeakSet","_handleStoryboardUpdate","ChatConversation","ReactNextElement","constructor","arguments","_classPrivateMethodInitSpec","_classPrivateFieldInitSpec","_init_messages","_init_extra_messages","_init_errorBoundary","_init_extra_errorBoundary","_init_storyboardUpdate","_init_extra_storyboardUpdate","storyboard","_classPrivateGetter","this","_get_storyboardUpdate","emit","messages","_classPrivateFieldGet","v","_classPrivateFieldSet","errorBoundary","render","React","ChatConversationComponent","host","onStoryboardUpdate","chunkRegExp","useMemo","lastIndexMapRef","useRef","Map","chunks","setChunks","manualScrolledRef","message","_lastIndexMapRef$curr","role","match","lastIndex","current","get","key","newChunks","newPage","exec","set","type","parsed","JSON","parse","push","e","length","prev","setStoryboard","blocks","storyboardMap","chunk","uuid","sort","a","b","seq","contentLayout","brick","children","main","slot","pageTitle","hasContent","block","name","child","childBrick","undefined","iid","meta","rawBrick","hasContainer","verticalScrollParent","overflowY","getComputedStyle","getPropertyValue","parentNode","ShadowRoot","Element","document","scrollingElement","documentElement","setTimeout","scrollTo","scrollHeight","handleScroll","scrollTop","clientHeight","addEventListener","removeEventListener","map","index","_message$key","MessageComponent","_ChatConversation2","_set_storyboardUpdate","c","_initClass","_applyDecs","styleTexts","styleText","attribute","Boolean","o","_","has","_checkInRHS","count","mermaid","initialize","startOnLoad","theme","themeVariables","fontSize","lineColor","primaryColor","primaryBorderColor","parser","DOMParser","serializer","XMLSerializer","async","promises","visit","tree","parent","tagName","id","svg","toString","root","parseFromString","svgElement","querySelector","defs","createElementNS","innerHTML","prepend","style","textContent","appendChild","modifiedSvg","serializeToString","replacements","fromHtmlIsomorphic","fragment","splice","concat","Promise","all","WrappedAvatar","wrapBrick","messageChunks","fullMatch","command","start","previousText","trim","raw","lastText","contentRef","contentElement","textingElements","parentElement","querySelectorAll","element","classList","remove","partial","lastChild","nodeType","Node","ELEMENT_NODE","open","_lastChild$previousSi","TEXT_NODE","previousSibling","add","classNames","failed","icon","lib","size","ref","MessageChunkComponent","_ref2","visitor","_index","lang","refractor","highlight","register","___CSS_LOADER_EXPORT___","i","module"],"sourceRoot":""}
|