@qfei-design/make-ai-assistant 0.2.1 → 0.2.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/PUBLIC_API.md CHANGED
@@ -40,15 +40,21 @@ Fetch SSE 实现时,从 `/sse` 入口导入 `createSseAssistantTransport`。
40
40
  - `MakeAiAssistant`:默认右侧居中浮动入口与右侧抽屉;支持受控开关、自定义 launcher,以及
41
41
  `brandName` 对默认“{品牌名} AI 助手”标题的覆盖。`title` 可覆盖完整标题;`assistantName` /
42
42
  `userName` / `userAvatarUrl` 可显示当前登录人的名称和头像;未传入时用户侧不显示身份信息。
43
- `privacyNotice` 可展示宿主传入的广播提示内容;未传入时不展示广播。浮动入口位置可通过
43
+ `subtitle` 用于显示宿主传入的当前对象;`privacyNotice` 会在对象右侧的问号 Tooltip 中展示,
44
+ 而非单独的广播行。头栏默认高度为 50px,可通过 `headerHeight` 或
45
+ `--make-ai-header-height` 覆盖。浮动入口位置可通过
44
46
  `--make-ai-launcher-top`、`--make-ai-launcher-right` 和 `--make-ai-launcher-mobile-right` 覆盖。
47
+ 桌面端抽屉可从左边缘 12px 热区向左拖宽,初始计算宽度(默认 432px,或宿主的
48
+ `--make-ai-drawer-width`)同时作为拖拽下限;手柄支持左右方向键微调。小于 560px 的视口保持全宽,
49
+ 不提供宽度调整。
45
50
  首次打开后关闭抽屉只隐藏 Drawer,不卸载 `AssistantPanel`,不会中断正在进行的生成。
46
51
  重新打开时会恢复消息滚动意图;空闲时聚焦输入框,生成中聚焦停止按钮。
47
52
  省略 `suggestions` 时显示包内默认推荐问题,传入 `[]` 时隐藏推荐问题。
48
53
  - `AssistantPanel`:不带 Drawer 的嵌入式会话面板;支持 `brandName`、`title`、`assistantName` /
49
- `userName` / `userAvatarUrl` / `privacyNotice`。默认品牌为“Make”,默认显示“AI 助手”;
50
- 用户侧默认不展示名称或头像,广播提示默认不展示。这些字段只参与本地 React 渲染,不会进入 transport 请求。嵌入式面板包含图标化复制回答、
51
- 可选安全重新生成、图标化回到最新消息、可折叠处理步骤、错误重试、键盘提交与 reduced-motion 处理。
54
+ `subtitle` / `userName` / `userAvatarUrl` / `privacyNotice` / `headerHeight`。默认品牌为“Make”,
55
+ 默认显示“AI 助手”;用户侧默认不展示名称或头像,宿主提示默认不展示。这些字段只参与本地 React
56
+ 渲染,不会进入 transport 请求。嵌入式面板包含图标化复制回答、可选安全重新生成、图标化回到最新消息、
57
+ 仅在生成中显示的处理步骤、错误重试、键盘提交与 reduced-motion 处理。
52
58
  - `ArtifactRenderer`:注册表驱动的单 Artifact 渲染器。
53
59
  - `createPlatformArtifactRegistry`
54
60
  - `platformArtifactTemplates`
package/README.md CHANGED
@@ -45,8 +45,12 @@ export function AppAssistant() {
45
45
  覆盖默认的 `Make` 品牌,面板会显示为“{品牌名} AI 助手”;传入 `title` 时则使用完整标题覆盖。
46
46
  `assistantName` 可覆盖 AI 消息显示名称。这些显示配置只用于 React UI,不会随会话上下文发送到
47
47
  AI transport;进度和可重试错误会显示在对应的 AI 回合中。
48
- 宿主传入 `privacyNotice` 时,面板会展示内置广播图标和该提示内容;不传入或传入空白内容时,
49
- 默认不展示广播提示。
48
+ `subtitle` 用于展示宿主传入的当前对象;未传入时回退为当前 App 名称。宿主传入
49
+ `privacyNotice` 时,面板会在当前对象右侧显示可聚焦的问号图标,鼠标悬浮或键盘聚焦后展示该提示;
50
+ 不传入或传入空白内容时不显示图标。标题右侧固定展示“只读”状态标签,长标题会省略显示并保留原文
51
+ `title` 属性。头栏默认高度为 50px,可通过 `headerHeight` 属性或 `--make-ai-header-height` 主题变量覆盖。
52
+
53
+ 桌面端抽屉默认宽度为 432px,且该初始宽度是用户拖拽时的最小宽度。鼠标移至抽屉左边缘的 12px 热区时才会显示 3px 拖拽提示线,可向左拖宽;获得焦点后也可用左、右方向键以 16px 调整宽度。小于 560px 的视口保持全宽展示,不显示拖拽手柄。
50
54
 
51
55
  成功的 AI 回答会显示仅含图标的复制按钮,鼠标悬浮或键盘聚焦时显示“复制”提示,按钮保留
52
56
  “复制回答”的无障碍名称;复制只处理该回答的文本内容,失败时会在本地 UI 内提示,不会把回答正文写入日志。AI 回答正文会按标题、
@@ -8,6 +8,7 @@ export interface AssistantPanelProps {
8
8
  brandName?: string;
9
9
  assistantName?: string;
10
10
  privacyNotice?: string;
11
+ headerHeight?: number | string;
11
12
  userName?: string;
12
13
  userAvatarUrl?: string;
13
14
  title?: string;
package/dist/react.cjs CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),O=require("./index.cjs"),u=require("react"),l=require("./conversation-Cv1wdvCR.cjs");function Ke({artifact:s,context:t,fallback:a,onAction:n,onActionError:r,registry:i}){const d=O.resolveArtifactTemplate(i,s,t);if(!d)return a?a(s):e.jsxs("section",{className:"make-ai-artifact make-ai-artifact--unsupported",role:"status",children:[e.jsx("strong",{children:"暂不支持展示此结果"}),e.jsxs("span",{children:["结果类型:",s.kind]})]});const h={context:t,onAction:n,onActionError:r};return d.template.render(s,t,h)}const L=(s,t,a)=>{if(s==null||s==="")return"—";if(typeof s=="boolean")return s?"是":"否";if(typeof s!="number")return`${s}${t?.unit??""}`;const n=t?.precision,r={maximumFractionDigits:n??2,minimumFractionDigits:n};t?.style==="currency"&&t.currency?(r.style="currency",r.currency=t.currency):t?.style==="percent"&&(r.style="percent");try{const i=t?.style==="percent"?s/100:s;return`${new Intl.NumberFormat(a,r).format(i)}${t?.unit??""}`}catch{return`${s}${t?.unit??""}`}},Pe=s=>{let t=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(const n of s)t=Math.min(t,n),a=Math.max(a,n);return Number.isFinite(t)&&Number.isFinite(a)?{min:t,max:a}:{min:0,max:0}},Be=(s,t,a)=>{if(!a.onAction)return;const n=i=>{console.error("[make-ai-assistant] host action error handler failed",{actionId:s.id,artifactId:t.artifact.id,errorType:i instanceof Error?i.name:typeof i,intent:s.intent})},r=i=>{if(a.onActionError){try{Promise.resolve(a.onActionError(i,s,t)).catch(n)}catch(d){n(d)}return}console.error("[make-ai-assistant] host action failed",{actionId:s.id,artifactId:t.artifact.id,errorType:i instanceof Error?i.name:typeof i,intent:s.intent})};try{Promise.resolve(a.onAction(s,t)).catch(r)}catch(i){r(i)}},W=(s,t)=>s.actions?.length&&t.onAction?e.jsx("div",{className:"make-ai-artifact__actions",children:s.actions.map(a=>e.jsxs("button",{className:`make-ai-artifact__action make-ai-artifact__action--${a.appearance??"link"}`,type:"button",onClick:()=>Be(a,{artifact:s,context:t.context},t),children:[a.label,e.jsx("span",{"aria-hidden":"true",children:"→"})]},a.id))}):null,J=(s,t,a="")=>e.jsxs("section",{"aria-label":s.title??`${s.kind} result`,className:`make-ai-artifact ${a}`.trim(),"data-artifact-density":s.presentation?.density,"data-artifact-kind":s.kind,children:[s.title?e.jsx("h4",{className:"make-ai-artifact__title",children:s.title}):null,s.summary?e.jsx("p",{className:"make-ai-artifact__summary",children:s.summary}):null,t]}),ms=({artifact:s,renderContext:t})=>{const a=s.data.delta,n=a?L(a.value,a.format==="percent"?{style:"percent"}:void 0,t.context.locale):void 0;return J(s,e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"make-ai-artifact__metric-value",children:L(s.data.value,s.data.format,t.context.locale)}),a?e.jsxs("div",{className:`make-ai-artifact__delta make-ai-artifact__delta--${a.direction??"flat"}`,children:[e.jsx("span",{"aria-hidden":"true",children:a.direction==="up"?"↗":a.direction==="down"?"↘":"→"}),e.jsx("span",{children:n}),a.label?e.jsx("span",{children:a.label}):null]}):null,s.data.context?e.jsx("p",{className:"make-ai-artifact__context",children:s.data.context}):null,W(s,t)]}),"make-ai-artifact--metric")},ps=({artifact:s,renderContext:t})=>J(s,e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"make-ai-artifact__comparison",children:s.data.items.map(a=>e.jsxs("div",{className:"make-ai-artifact__comparison-item",children:[e.jsx("span",{children:a.label}),e.jsx("strong",{children:L(a.value,a.format,t.context.locale)}),a.hint?e.jsx("small",{children:a.hint}):null]},a.id))}),W(s,t)]}),"make-ai-artifact--comparison"),hs=({artifact:s,renderContext:t})=>{const a=s.data.series.flatMap(d=>d.points.map(h=>h.y)),{max:n,min:r}=Pe(a),i=n-r||1;return J(s,e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"make-ai-artifact__trend",children:s.data.series.map(d=>e.jsxs("div",{className:"make-ai-artifact__trend-series",children:[e.jsx("div",{className:"make-ai-artifact__trend-label",children:d.label}),e.jsx("div",{className:"make-ai-artifact__trend-bars",children:d.points.map((h,_)=>{const y=18+(h.y-r)/i*70;return e.jsxs("div",{className:"make-ai-artifact__trend-point",children:[e.jsx("span",{"aria-label":`${h.x}: ${L(h.y,d.format,t.context.locale)}`,className:"make-ai-artifact__trend-bar",role:"img",style:{height:`${y}%`},title:`${h.x}: ${L(h.y,d.format,t.context.locale)}`}),e.jsx("small",{children:h.x})]},`${h.x}-${_}`)})})]},d.id))}),W(s,t)]}),"make-ai-artifact--trend")},fs=({artifact:s,renderContext:t})=>{const{max:a}=Pe(s.data.items.map(r=>Math.abs(r.value))),n=Math.max(a,1);return J(s,e.jsxs(e.Fragment,{children:[e.jsx("ol",{className:"make-ai-artifact__ranking",children:s.data.items.map((r,i)=>e.jsxs("li",{children:[e.jsx("span",{className:"make-ai-artifact__rank",children:i+1}),e.jsxs("span",{className:"make-ai-artifact__ranking-label",children:[e.jsx("span",{children:r.label}),r.description?e.jsx("small",{children:r.description}):null]}),e.jsx("span",{className:"make-ai-artifact__ranking-track","aria-hidden":"true",children:e.jsx("span",{style:{width:`${Math.abs(r.value)/n*100}%`}})}),e.jsx("strong",{children:L(r.value,r.format,t.context.locale)})]},r.id))}),W(s,t)]}),"make-ai-artifact--ranking")},gs=(s,t)=>t.action??{id:`open-${t.id}`,label:t.title??t.id,intent:"open-record",target:{entityKey:s.data.entity.key,recordId:t.id}},_s=({artifact:s,renderContext:t})=>J(s,e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"make-ai-artifact__record-list",children:s.data.records.length===0?e.jsx("p",{className:"make-ai-artifact__empty",children:"没有符合条件的记录"}):s.data.records.map(a=>{const n=gs(s,a),r=e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:a.title??a.id}),e.jsx("span",{className:"make-ai-artifact__record-values",children:s.data.columns.map(i=>e.jsxs("span",{children:[e.jsx("small",{children:i.label}),L(a.values[i.key],i.format,t.context.locale)]},i.key))}),t.onAction?e.jsx("span",{"aria-hidden":"true",children:"›"}):null]});return t.onAction?e.jsx("button",{className:"make-ai-artifact__record",type:"button",onClick:()=>Be(n,{artifact:s,context:t.context},t),children:r},a.id):e.jsx("div",{className:"make-ai-artifact__record",children:r},a.id)})}),s.data.total!==void 0?e.jsxs("p",{className:"make-ai-artifact__record-total",children:["共 ",s.data.total," 条"]}):null,W(s,t)]}),"make-ai-artifact--record-list"),xs=({artifact:s,renderContext:t})=>J(s,e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`make-ai-artifact__notice make-ai-artifact__notice--${s.data.tone}`,children:[e.jsx("span",{"aria-hidden":"true",children:s.data.tone==="success"?"✓":s.data.tone==="warning"?"!":s.data.tone==="danger"?"×":"i"}),e.jsx("p",{children:s.data.body})]}),W(s,t)]}),"make-ai-artifact--notice"),Y=(s,t,a)=>({id:s,kinds:[t],priority:0,render:a}),js=[Y("platform.metric.default","metric",(s,t,a)=>e.jsx(ms,{artifact:s,renderContext:a})),Y("platform.comparison.default","comparison",(s,t,a)=>e.jsx(ps,{artifact:s,renderContext:a})),Y("platform.trend.default","trend",(s,t,a)=>e.jsx(hs,{artifact:s,renderContext:a})),Y("platform.ranking.default","ranking",(s,t,a)=>e.jsx(fs,{artifact:s,renderContext:a})),Y("platform.record-list.default","record-list",(s,t,a)=>e.jsx(_s,{artifact:s,renderContext:a})),Y("platform.notice.default","notice",(s,t,a)=>e.jsx(xs,{artifact:s,renderContext:a}))],qe=O.createArtifactTemplateRegistry(js).templates,De=(s=qe)=>O.createArtifactTemplateRegistry(s),As=s=>`${s}-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,vs="Make",Is=["总结当前页面数据","找出需要关注的记录","列出我有权限查看的数据对象"],Ue=(s,t)=>t??`${s?.trim()||vs} AI 助手`,ys=s=>s??Is;class j extends Error{}const Oe=s=>{try{const t=s?.return?.();if(!t)return;Promise.resolve(t).catch(a=>{console.error("[make-ai-assistant] transport iterator close failed",{errorType:a instanceof Error?a.name:typeof a})})}catch(t){console.error("[make-ai-assistant] transport iterator close failed",{errorType:t instanceof Error?t.name:typeof t})}},ks=async s=>{if(globalThis.navigator?.clipboard?.writeText){await globalThis.navigator.clipboard.writeText(s);return}if(typeof document>"u"||!document.body)throw new Error("Clipboard API is unavailable");const t=document.createElement("textarea");t.value=s,t.setAttribute("readonly",""),t.style.position="fixed",t.style.inset="0 auto auto 0",t.style.opacity="0",document.body.append(t),t.select();const a=document.execCommand("copy");if(t.remove(),!a)throw new Error("Clipboard copy failed")},He=()=>e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[e.jsx("path",{d:"M12 2.8c.5 4.4 2.8 6.8 7.2 7.2-4.4.5-6.8 2.8-7.2 7.2-.5-4.4-2.8-6.8-7.2-7.2 4.4-.5 6.8-2.8 7.2-7.2Z"}),e.jsx("path",{d:"M18.3 16.1c.2 1.8 1.2 2.8 3 3-1.8.2-2.8 1.2-3 3-.2-1.8-1.2-2.8-3-3 1.8-.2 2.8-1.2 3-3Z"})]}),bs=()=>e.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:e.jsx("path",{d:"m6 6 12 12M18 6 6 18"})}),Ns=()=>e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[e.jsx("path",{d:"M8 8h10v12H8z"}),e.jsx("path",{d:"M6 16H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),Ts=()=>e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[e.jsx("path",{d:"M20 11a8 8 0 0 0-14.7-4.4L4 8"}),e.jsx("path",{d:"M4 4v4h4"}),e.jsx("path",{d:"M4 13a8 8 0 0 0 14.7 4.4L20 16"}),e.jsx("path",{d:"M20 20v-4h-4"})]}),Ms=()=>e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[e.jsx("path",{d:"M5 10v4"}),e.jsx("path",{d:"M8 9v6l6 3V6L8 9Z"}),e.jsx("path",{d:"M17 9.2a4.2 4.2 0 0 1 0 5.6"}),e.jsx("path",{d:"M19.4 6.8a7.6 7.6 0 0 1 0 10.4"})]}),Es=()=>e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[e.jsx("path",{d:"M12 4v11"}),e.jsx("path",{d:"m7 10 5 5 5-5"}),e.jsx("path",{d:"M5 20h14"})]}),ws=()=>e.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),Ss=()=>e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[e.jsx("path",{d:"m4 4 17 8-17 8 3-8-3-8Z"}),e.jsx("path",{d:"M7 12h14"})]}),ae=({className:s=""})=>e.jsx("span",{className:`make-ai-assistant__avatar ${s}`.trim(),"aria-hidden":"true",children:e.jsx(He,{})}),Cs=({src:s})=>s?e.jsx("span",{className:"make-ai-assistant__user-avatar","aria-hidden":"true",children:e.jsx("img",{alt:"",src:s})}):null,Rs=({userAvatarUrl:s,userName:t})=>{const a=t?.trim();return!a&&!s?null:e.jsxs("div",{className:"make-ai-assistant__message-identity",children:[a?e.jsx("span",{className:"make-ai-assistant__message-sender",children:a}):null,e.jsx(Cs,{src:s})]})},$s=s=>{const t=[],a=[],n=[],r=[],i=()=>{const _=a.join(`
2
- `).trim();a.length=0,_&&t.push({type:"paragraph",text:_})},d=()=>{n.length&&t.push({type:"list",items:n.splice(0)})},h=()=>{const _=r.join(`
3
- `).trim();r.length=0,_&&t.push({type:"pre",text:_})};for(const _ of s.replace(/\r\n?/g,`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),q=require("./index.cjs"),u=require("react"),d=require("./conversation-Cv1wdvCR.cjs");function Ye({artifact:s,context:t,fallback:a,onAction:r,onActionError:n,registry:i}){const c=q.resolveArtifactTemplate(i,s,t);if(!c)return a?a(s):e.jsxs("section",{className:"make-ai-artifact make-ai-artifact--unsupported",role:"status",children:[e.jsx("strong",{children:"暂不支持展示此结果"}),e.jsxs("span",{children:["结果类型:",s.kind]})]});const h={context:t,onAction:r,onActionError:n};return c.template.render(s,t,h)}const U=(s,t,a)=>{if(s==null||s==="")return"—";if(typeof s=="boolean")return s?"是":"否";if(typeof s!="number")return`${s}${t?.unit??""}`;const r=t?.precision,n={maximumFractionDigits:r??2,minimumFractionDigits:r};t?.style==="currency"&&t.currency?(n.style="currency",n.currency=t.currency):t?.style==="percent"&&(n.style="percent");try{const i=t?.style==="percent"?s/100:s;return`${new Intl.NumberFormat(a,n).format(i)}${t?.unit??""}`}catch{return`${s}${t?.unit??""}`}},Ge=s=>{let t=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(const r of s)t=Math.min(t,r),a=Math.max(a,r);return Number.isFinite(t)&&Number.isFinite(a)?{min:t,max:a}:{min:0,max:0}},Qe=(s,t,a)=>{if(!a.onAction)return;const r=i=>{console.error("[make-ai-assistant] host action error handler failed",{actionId:s.id,artifactId:t.artifact.id,errorType:i instanceof Error?i.name:typeof i,intent:s.intent})},n=i=>{if(a.onActionError){try{Promise.resolve(a.onActionError(i,s,t)).catch(r)}catch(c){r(c)}return}console.error("[make-ai-assistant] host action failed",{actionId:s.id,artifactId:t.artifact.id,errorType:i instanceof Error?i.name:typeof i,intent:s.intent})};try{Promise.resolve(a.onAction(s,t)).catch(n)}catch(i){n(i)}},ae=(s,t)=>s.actions?.length&&t.onAction?e.jsx("div",{className:"make-ai-artifact__actions",children:s.actions.map(a=>e.jsxs("button",{className:`make-ai-artifact__action make-ai-artifact__action--${a.appearance??"link"}`,type:"button",onClick:()=>Qe(a,{artifact:s,context:t.context},t),children:[a.label,e.jsx("span",{"aria-hidden":"true",children:"→"})]},a.id))}):null,ne=(s,t,a="")=>e.jsxs("section",{"aria-label":s.title??`${s.kind} result`,className:`make-ai-artifact ${a}`.trim(),"data-artifact-density":s.presentation?.density,"data-artifact-kind":s.kind,children:[s.title?e.jsx("h4",{className:"make-ai-artifact__title",children:s.title}):null,s.summary?e.jsx("p",{className:"make-ai-artifact__summary",children:s.summary}):null,t]}),ys=({artifact:s,renderContext:t})=>{const a=s.data.delta,r=a?U(a.value,a.format==="percent"?{style:"percent"}:void 0,t.context.locale):void 0;return ne(s,e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"make-ai-artifact__metric-value",children:U(s.data.value,s.data.format,t.context.locale)}),a?e.jsxs("div",{className:`make-ai-artifact__delta make-ai-artifact__delta--${a.direction??"flat"}`,children:[e.jsx("span",{"aria-hidden":"true",children:a.direction==="up"?"↗":a.direction==="down"?"↘":"→"}),e.jsx("span",{children:r}),a.label?e.jsx("span",{children:a.label}):null]}):null,s.data.context?e.jsx("p",{className:"make-ai-artifact__context",children:s.data.context}):null,ae(s,t)]}),"make-ai-artifact--metric")},ks=({artifact:s,renderContext:t})=>ne(s,e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"make-ai-artifact__comparison",children:s.data.items.map(a=>e.jsxs("div",{className:"make-ai-artifact__comparison-item",children:[e.jsx("span",{children:a.label}),e.jsx("strong",{children:U(a.value,a.format,t.context.locale)}),a.hint?e.jsx("small",{children:a.hint}):null]},a.id))}),ae(s,t)]}),"make-ai-artifact--comparison"),bs=({artifact:s,renderContext:t})=>{const a=s.data.series.flatMap(c=>c.points.map(h=>h.y)),{max:r,min:n}=Ge(a),i=r-n||1;return ne(s,e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"make-ai-artifact__trend",children:s.data.series.map(c=>e.jsxs("div",{className:"make-ai-artifact__trend-series",children:[e.jsx("div",{className:"make-ai-artifact__trend-label",children:c.label}),e.jsx("div",{className:"make-ai-artifact__trend-bars",children:c.points.map((h,I)=>{const g=18+(h.y-n)/i*70;return e.jsxs("div",{className:"make-ai-artifact__trend-point",children:[e.jsx("span",{"aria-label":`${h.x}: ${U(h.y,c.format,t.context.locale)}`,className:"make-ai-artifact__trend-bar",role:"img",style:{height:`${g}%`},title:`${h.x}: ${U(h.y,c.format,t.context.locale)}`}),e.jsx("small",{children:h.x})]},`${h.x}-${I}`)})})]},c.id))}),ae(s,t)]}),"make-ai-artifact--trend")},ws=({artifact:s,renderContext:t})=>{const{max:a}=Ge(s.data.items.map(n=>Math.abs(n.value))),r=Math.max(a,1);return ne(s,e.jsxs(e.Fragment,{children:[e.jsx("ol",{className:"make-ai-artifact__ranking",children:s.data.items.map((n,i)=>e.jsxs("li",{children:[e.jsx("span",{className:"make-ai-artifact__rank",children:i+1}),e.jsxs("span",{className:"make-ai-artifact__ranking-label",children:[e.jsx("span",{children:n.label}),n.description?e.jsx("small",{children:n.description}):null]}),e.jsx("span",{className:"make-ai-artifact__ranking-track","aria-hidden":"true",children:e.jsx("span",{style:{width:`${Math.abs(n.value)/r*100}%`}})}),e.jsx("strong",{children:U(n.value,n.format,t.context.locale)})]},n.id))}),ae(s,t)]}),"make-ai-artifact--ranking")},Ns=(s,t)=>t.action??{id:`open-${t.id}`,label:t.title??t.id,intent:"open-record",target:{entityKey:s.data.entity.key,recordId:t.id}},Ms=({artifact:s,renderContext:t})=>ne(s,e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"make-ai-artifact__record-list",children:s.data.records.length===0?e.jsx("p",{className:"make-ai-artifact__empty",children:"没有符合条件的记录"}):s.data.records.map(a=>{const r=Ns(s,a),n=e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:a.title??a.id}),e.jsx("span",{className:"make-ai-artifact__record-values",children:s.data.columns.map(i=>e.jsxs("span",{children:[e.jsx("small",{children:i.label}),U(a.values[i.key],i.format,t.context.locale)]},i.key))}),t.onAction?e.jsx("span",{"aria-hidden":"true",children:"›"}):null]});return t.onAction?e.jsx("button",{className:"make-ai-artifact__record",type:"button",onClick:()=>Qe(r,{artifact:s,context:t.context},t),children:n},a.id):e.jsx("div",{className:"make-ai-artifact__record",children:n},a.id)})}),s.data.total!==void 0?e.jsxs("p",{className:"make-ai-artifact__record-total",children:["共 ",s.data.total," 条"]}):null,ae(s,t)]}),"make-ai-artifact--record-list"),Ts=({artifact:s,renderContext:t})=>ne(s,e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`make-ai-artifact__notice make-ai-artifact__notice--${s.data.tone}`,children:[e.jsx("span",{"aria-hidden":"true",children:s.data.tone==="success"?"✓":s.data.tone==="warning"?"!":s.data.tone==="danger"?"×":"i"}),e.jsx("p",{children:s.data.body})]}),ae(s,t)]}),"make-ai-artifact--notice"),te=(s,t,a)=>({id:s,kinds:[t],priority:0,render:a}),Es=[te("platform.metric.default","metric",(s,t,a)=>e.jsx(ys,{artifact:s,renderContext:a})),te("platform.comparison.default","comparison",(s,t,a)=>e.jsx(ks,{artifact:s,renderContext:a})),te("platform.trend.default","trend",(s,t,a)=>e.jsx(bs,{artifact:s,renderContext:a})),te("platform.ranking.default","ranking",(s,t,a)=>e.jsx(ws,{artifact:s,renderContext:a})),te("platform.record-list.default","record-list",(s,t,a)=>e.jsx(Ms,{artifact:s,renderContext:a})),te("platform.notice.default","notice",(s,t,a)=>e.jsx(Ts,{artifact:s,renderContext:a}))],Je=q.createArtifactTemplateRegistry(Es).templates,es=(s=Je)=>q.createArtifactTemplateRegistry(s),Ss=s=>`${s}-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,Rs="Make",Cs=["总结当前页面数据","找出需要关注的记录","列出我有权限查看的数据对象"],ss=(s,t)=>t??`${s?.trim()||Rs} AI 助手`,$s=s=>s??Cs,Ls=432,Ue=16,qe=(s,t,a)=>Math.min(Math.max(s,Math.min(t,a)),a),Fs=s=>typeof s=="number"?Number.isFinite(s)?`${s}px`:void 0:s?.trim()||void 0;class j extends Error{}const ve=(s,t)=>{if(!(typeof s!="object"||s===null))return s[t]},Os=s=>{const t=ve(s,"status");return typeof t=="number"?t:ve(ve(s,"response"),"status")},Ds=s=>{const t=ve(s,"code"),a=Os(s),r=s instanceof Error?s.message:"",n=[t,r].filter(I=>typeof I=="string").join(" ").toLowerCase(),c=globalThis.navigator?.onLine===!1||/network|fetch|timeout|offline|connection|网络|连接|超时/.test(n),h=typeof a=="number"&&a>=500||/server|service|服务器|服务异常/.test(n);return c?{actionLabel:"重新连接",description:"请检查网络后再试。",kind:"network",label:"网络连接",title:"网络连接不可用"}:h?{actionLabel:"重新加载",description:"服务暂时未能响应,请稍后重试。",kind:"service",label:"服务异常",title:"服务暂时不可用"}:{actionLabel:"重新加载",description:"请稍后重试;若问题持续出现,请联系管理员。",kind:"unknown",label:"加载异常",title:"暂时无法加载对话"}},He=s=>{try{const t=s?.return?.();if(!t)return;Promise.resolve(t).catch(a=>{console.error("[make-ai-assistant] transport iterator close failed",{errorType:a instanceof Error?a.name:typeof a})})}catch(t){console.error("[make-ai-assistant] transport iterator close failed",{errorType:t instanceof Error?t.name:typeof t})}},Ps=async s=>{if(globalThis.navigator?.clipboard?.writeText){await globalThis.navigator.clipboard.writeText(s);return}if(typeof document>"u"||!document.body)throw new Error("Clipboard API is unavailable");const t=document.createElement("textarea");t.value=s,t.setAttribute("readonly",""),t.style.position="fixed",t.style.inset="0 auto auto 0",t.style.opacity="0",document.body.append(t),t.select();const a=document.execCommand("copy");if(t.remove(),!a)throw new Error("Clipboard copy failed")},ts=()=>e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[e.jsx("path",{d:"M12 2.8c.5 4.4 2.8 6.8 7.2 7.2-4.4.5-6.8 2.8-7.2 7.2-.5-4.4-2.8-6.8-7.2-7.2 4.4-.5 6.8-2.8 7.2-7.2Z"}),e.jsx("path",{d:"M18.3 16.1c.2 1.8 1.2 2.8 3 3-1.8.2-2.8 1.2-3 3-.2-1.8-1.2-2.8-3-3 1.8-.2 2.8-1.2 3-3Z"})]}),Ks=()=>e.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:e.jsx("path",{d:"m6 6 12 12M18 6 6 18"})}),Vs=()=>e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[e.jsx("path",{d:"M8 8h10v12H8z"}),e.jsx("path",{d:"M6 16H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),Ws=()=>e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[e.jsx("path",{d:"M20 11a8 8 0 0 0-14.7-4.4L4 8"}),e.jsx("path",{d:"M4 4v4h4"}),e.jsx("path",{d:"M4 13a8 8 0 0 0 14.7 4.4L20 16"}),e.jsx("path",{d:"M20 20v-4h-4"})]}),Bs=()=>e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[e.jsx("circle",{cx:"12",cy:"12",r:"8"}),e.jsx("path",{d:"M9.8 9.4a2.35 2.35 0 1 1 3.93 1.73c-.96.86-1.73 1.42-1.73 2.87"}),e.jsx("path",{d:"M12 17h.01"})]}),zs=()=>e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[e.jsx("path",{d:"M12 4v11"}),e.jsx("path",{d:"m7 10 5 5 5-5"}),e.jsx("path",{d:"M5 20h14"})]}),Us=()=>e.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),qs=()=>e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[e.jsx("path",{d:"m4 4 17 8-17 8 3-8-3-8Z"}),e.jsx("path",{d:"M7 12h14"})]}),as=()=>e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[e.jsx("path",{d:"M20 11a8 8 0 0 0-14.7-4.4L4 8"}),e.jsx("path",{d:"M4 4v4h4"}),e.jsx("path",{d:"M4 13a8 8 0 0 0 14.7 4.4L20 16"}),e.jsx("path",{d:"M20 20v-4h-4"})]}),Hs=()=>e.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[e.jsx("circle",{cx:"12",cy:"12",r:"8"}),e.jsx("path",{d:"M12 8v4.5"}),e.jsx("path",{d:"M12 16h.01"})]}),je=({className:s=""})=>e.jsx("span",{className:`make-ai-assistant__avatar ${s}`.trim(),"aria-hidden":"true",children:e.jsx(ts,{})}),Zs=({src:s})=>s?e.jsx("span",{className:"make-ai-assistant__user-avatar","aria-hidden":"true",children:e.jsx("img",{alt:"",src:s})}):null,Xs=({userAvatarUrl:s,userName:t})=>{const a=t?.trim();return!a&&!s?null:e.jsxs("div",{className:"make-ai-assistant__message-identity",children:[a?e.jsx("span",{className:"make-ai-assistant__message-sender",children:a}):null,e.jsx(Zs,{src:s})]})},ke=s=>{const t=s.trim();if(!(!t.startsWith("|")||!t.endsWith("|")))return t.slice(1,-1).split("|").map(a=>a.trim())},Ys=s=>s.length>0&&s.every(t=>/^:?-{3,}:?$/.test(t)),Gs=(s,t)=>{const a=ke(s[t]??""),r=ke(s[t+1]??"");if(!a||!r||a.length!==r.length||!Ys(r))return;const n=[];let i=t+2;for(;i<s.length;){const c=ke(s[i]??"");if(!c||c.length!==a.length)break;n.push(c),i+=1}return{headers:a,lastIndex:i-1,rows:n}},Qs=s=>{const t=[],a=[],r=[],n=[],i=s.replace(/\r\n?/g,`
4
2
  `).split(`
5
- `)){const y=_.trim();if(!y){i(),d(),h();continue}const T=/^(#{1,6})\s+(.+)$/.exec(y);if(T){i(),d(),h();const m=(T[2]??"").replace(/\s+#+\s*$/,"").trim();m&&t.push({type:"heading",level:T[1]?.length,text:m});continue}if(/^\s*\|.+\|\s*$/.test(_)){i(),d(),r.push(_.trim());continue}const M=/^\s*[-*]\s+(.+)$/.exec(_);if(M){i(),h(),n.push(M[1]?.trim()??"");continue}d(),h(),a.push(y)}return i(),d(),h(),t},fe=s=>{const t=[],a=/(\*\*[^*]+\*\*|`[^`]+`)/g;let n=0;for(const r of s.matchAll(a)){const i=r[0],d=r.index??0;d>n&&t.push(s.slice(n,d)),i.startsWith("**")?t.push(e.jsx("strong",{children:i.slice(2,-2)},`${d}-strong`)):t.push(e.jsx("code",{children:i.slice(1,-1)},`${d}-code`)),n=d+i.length}return n<s.length&&t.push(s.slice(n)),t},Ls=({content:s})=>{const t=$s(s);return t.length?e.jsx("div",{className:"make-ai-assistant__bubble make-ai-assistant__assistant-text",children:t.map((a,n)=>{if(a.type==="heading"){const r=a.level<=2?"h3":"h4";return e.jsx(r,{className:`make-ai-assistant__markdown-heading make-ai-assistant__markdown-heading--${a.level}`,children:fe(a.text)},`${n}-heading`)}return a.type==="paragraph"?e.jsx("p",{children:fe(a.text)},`${n}-paragraph`):a.type==="pre"?e.jsx("pre",{children:e.jsx("code",{children:a.text})},`${n}-pre`):e.jsx("ul",{children:a.items.map((r,i)=>e.jsx("li",{children:fe(r)},`${i}-${r}`))},`${n}-list`)})}):null},ze=({assistantName:s})=>e.jsxs("div",{className:"make-ai-assistant__message-identity",children:[e.jsx(ae,{className:"make-ai-assistant__avatar--message"}),e.jsx("span",{className:"make-ai-assistant__message-sender",children:s})]}),Ze=s=>{for(let t=s.messages.length-1;t>=0;t-=1){const a=s.messages[t];if(a.role==="assistant"&&a.status==="streaming")return a.id}},Os=s=>{for(let t=s.messages.length-1;t>=0;t-=1)if(s.messages[t].role==="user")return t;return-1},Ge=s=>{const t=Os(s);if(!(t<0))for(let a=s.messages.length-1;a>t;a-=1){const n=s.messages[a];if(n.role==="assistant")return n.id}},Fs=s=>{if(s.status==="idle")for(let t=s.messages.length-1;t>=0;t-=1){const a=s.messages[t];if(a.role==="assistant"&&a.status==="complete")return a.id}},Vs=s=>{for(let t=s.messages.length-1;t>=0;t-=1){const a=s.messages[t];if(a.role==="user")return a}},Ks=(s,t)=>{const a=s.messages.findIndex(n=>n.id===t&&n.role==="user");return{...s,error:void 0,progress:void 0,status:"streaming",messages:a<0?s.messages:s.messages.slice(0,a+1)}},Ps=s=>s.scrollHeight-s.scrollTop-s.clientHeight<=48,Fe=(s="smooth")=>globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches?"auto":s,ge=(s,t)=>{typeof s.scrollTo=="function"?s.scrollTo({top:s.scrollHeight,behavior:t}):s.scrollTop=s.scrollHeight},Ye=({error:s,onRetry:t})=>e.jsxs("div",{className:"make-ai-assistant__message-status make-ai-assistant__message-status--error",role:"alert",children:[e.jsx("strong",{children:"本次请求未完成"}),e.jsx("span",{children:s.message}),s.retryable&&t?e.jsx("button",{className:"make-ai-assistant__retry",type:"button",onClick:t,children:"重新发送"}):null]}),We=({active:s,steps:t})=>{if(!t?.length)return null;const a=t[t.length-1]??"处理中";return e.jsxs("details",{className:"make-ai-assistant__process",open:s,children:[e.jsxs("summary",{children:[s?e.jsxs("span",{className:"make-ai-assistant__progress",role:"status",children:[e.jsx("span",{"aria-hidden":"true"}),e.jsx("span",{children:a})]}):e.jsx("span",{className:"make-ai-assistant__process-title",children:"处理过程"}),e.jsxs("span",{className:"make-ai-assistant__process-count",children:[t.length," 步"]})]}),e.jsx("ol",{children:t.map((n,r)=>e.jsxs("li",{"data-step-active":s&&r===t.length-1?!0:void 0,children:[e.jsx("span",{"aria-hidden":"true"}),e.jsx("span",{children:n})]},`${r}-${n}`))})]})},Bs=({copyFeedback:s,onCopy:t,onRegenerate:a})=>!t&&!a?null:e.jsxs("div",{className:"make-ai-assistant__reply-actions","aria-label":"回复操作",children:[t?e.jsx("button",{"aria-label":"复制回答",className:"make-ai-assistant__reply-action make-ai-assistant__reply-copy","data-tooltip":"复制",type:"button",onClick:t,children:e.jsx(Ns,{})}):null,a?e.jsx("button",{"aria-label":"重新生成",className:"make-ai-assistant__reply-action make-ai-assistant__reply-regenerate","data-tooltip":"重新生成",type:"button",onClick:a,children:e.jsx(Ts,{})}):null,s?e.jsx("span",{className:"make-ai-assistant__reply-feedback","data-copy-status":s.status,role:"status",children:s.message}):null]}),Ve=({assistantName:s,error:t,onRetry:a,progress:n})=>{const r=t?"error":"progress";return t?.message??n?.message?e.jsx("article",{"aria-label":`${s}的${r==="error"?"错误消息":"状态消息"}`,className:`make-ai-assistant__message make-ai-assistant__message--assistant make-ai-assistant__message--${r}`,"data-message-role":"assistant","data-message-state":r,children:e.jsxs("div",{className:"make-ai-assistant__message-turn",children:[e.jsx(ze,{assistantName:s}),e.jsx("div",{className:"make-ai-assistant__message-stack",children:t?e.jsx(Ye,{error:t,onRetry:a}):e.jsx(We,{active:!0,steps:n?.steps})})]})}):null},qs=(s,t,a,n,r,i,d,h,_,y,T,M,m)=>{const F=Ge(s),q=Ze(s),v=Fs(s);let V;return s.messages.map(p=>{const k=p.role==="assistant",K=V;k||(V=p);const x=p.id===q,b=p.id===F?s.error:void 0,E=p.error??b,P=!k&&!!(h?.trim()||_),B=k?i:h?.trim()||"用户",me=k&&p.status==="complete"&&!E&&(p.content.trim()||p.id===v);return e.jsx("article",{"aria-label":`${B}的消息`,className:`make-ai-assistant__message make-ai-assistant__message--${p.role}`,"data-message-role":p.role,"data-message-state":E?"error":void 0,"data-message-status":p.status,"data-message-has-identity":k||P?!0:void 0,children:e.jsxs("div",{className:"make-ai-assistant__message-turn",children:[k?e.jsx(ze,{assistantName:i}):P?e.jsx(Rs,{userAvatarUrl:_,userName:h}):null,e.jsxs("div",{className:"make-ai-assistant__message-stack",children:[p.content?k?e.jsx(Ls,{content:p.content}):e.jsx("div",{className:"make-ai-assistant__bubble",children:p.content}):p.status==="streaming"?e.jsxs("div",{className:"make-ai-assistant__typing","aria-label":`${i}正在思考`,children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null,k?e.jsx(We,{active:x&&s.status==="streaming",steps:p.progressSteps}):null,E?e.jsx(Ye,{error:E,onRetry:b?d:void 0}):null,p.artifacts.map(S=>e.jsx(Ke,{artifact:S,context:t,onAction:n,onActionError:r,registry:a},S.id)),me?e.jsx(Bs,{copyFeedback:y?.messageId===p.id?{message:y.message,status:y.status}:void 0,onCopy:p.content.trim()?()=>M(p.id,p.content):void 0,onRegenerate:T&&p.id===v&&K?()=>m({userMessage:K,assistantMessage:p}):void 0}):null]})]})},p.id)})};function Je({assistantName:s="AI 助手",brandName:t,context:a,onAction:n,onActionError:r,onClose:i,onNewConversation:d,privacyNotice:h,registry:_,subtitle:y,suggestions:T,title:M,transport:m,userAvatarUrl:F,userName:q,visible:v}){const V=Ue(t,M),p=h?.trim(),[k,K]=u.useState(""),[x,b]=u.useState(l.createAssistantConversationState),E=u.useRef(x);E.current=x;const[P,B]=u.useState(void 0),[me,S]=u.useState(void 0),[Qe,Xe]=u.useState(0),[D,ne]=u.useState(()=>m.loadConversation?"loading":"ready"),[es,C]=u.useState(!1),U=u.useRef(void 0),H=u.useRef(void 0),z=u.useRef(0),_e=u.useRef(null),Q=u.useRef(null),xe=u.useRef(null),je=u.useRef(null),R=u.useRef(!0),Ae=u.useRef(a.app.id),ve=u.useRef(v),Ie=u.useMemo(()=>_??De(),[_]),ye=u.useMemo(()=>ys(T),[T]),re=o=>{const f=U.current,g=H.current?.iterator;return!f&&!g?!1:(z.current+=1,U.current=void 0,H.current=void 0,console.info("[make-ai-assistant] local run cancellation requested",{reason:o}),f?.abort(),Oe(g),!0)};u.useEffect(()=>()=>{re("unmount")},[]),u.useEffect(()=>{const o=m.loadConversation,f=Ae.current!==a.app.id;if(Ae.current=a.app.id,re("reinitialize"),f&&(K(""),R.current=!0),B(void 0),S(void 0),C(!1),b(l.createAssistantConversationState()),!o){ne("ready");return}const g=new AbortController;return ne("loading"),console.info("[make-ai-assistant] conversation load start",{appId:a.app.id}),o.call(m,a,{signal:g.signal}).then(A=>{g.signal.aborted||(b(l.createAssistantConversationState(A)),ne("ready"),console.info("[make-ai-assistant] conversation load success",{appId:a.app.id,messageCount:A.messages.length}))}).catch(A=>{g.signal.aborted||(console.error("[make-ai-assistant] conversation load failed",{appId:a.app.id,errorType:A instanceof Error?A.name:typeof A}),ne("error"))}),()=>g.abort()},[a.app.id,Qe,m]),u.useEffect(()=>{const o=Q.current;if(!o||!R.current)return;C(!1);const f=requestAnimationFrame(()=>{if(!R.current)return;const g=x.status==="streaming"||globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches?"auto":"smooth";ge(o,g)});return()=>cancelAnimationFrame(f)},[x.messages,x.progress,x.status]),u.useEffect(()=>{const o=v&&!ve.current;if(ve.current=v,!o)return;const f=requestAnimationFrame(()=>{const g=Q.current;if(g&&R.current){C(!1);const X=E.current.status==="streaming"?"auto":Fe();ge(g,X)}else g&&C(E.current.messages.length>0);const A=xe.current;(A&&!A.disabled?A:je.current??_e.current?.querySelector("button:not(:disabled)"))?.focus()});return()=>cancelAnimationFrame(f)},[v]);const ss=()=>{const o=Q.current;if(!o)return;const f=Ps(o);R.current=f,C(!f&&E.current.messages.length>0)},ts=()=>{const o=Q.current;if(!o)return;R.current=!0,C(!1);const f=Fe();ge(o,f)},ke=async(o,f)=>{const g=o.trim(),A=E.current,w=f?.regenerateFrom,X=m.regenerate;if(!g||D!=="ready"||A.status==="streaming"||U.current||w&&!X)return;if(l.countCodePointsUpTo(g,l.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)>l.MAKE_AI_CONVERSATION_LIMITS.messageCharacters){B(`输入内容过长,请控制在 ${l.MAKE_AI_CONVERSATION_LIMITS.messageCharacters} 个字符以内`);return}const ce={id:w?.userMessage.id??As("user"),content:g},le=w?Ks(A,w.userMessage.id):l.appendUserMessage(A,ce),de=new AbortController,Z=z.current+1;z.current=Z,U.current=de,B(void 0),S(void 0),C(!R.current&&A.messages.length>0),w||K(""),b(le);try{let $=!1,I,Te=0,Me=0,Ee=0,pe=0,ee=0;const se=new Map,we=new Set,Se=new Set([...le.messages.map(ue=>ue.id),ce.id]),te=new Set,Ce=O.createArtifactCapabilities(Ie),Re={signal:de.signal};let he;if(w){if(!X)throw new j("当前 AI 助手不支持重新生成");he=X({threadId:le.threadId,message:ce,assistantMessage:{id:w.assistantMessage.id,content:w.assistantMessage.content},context:a,capabilities:Ce},Re)}else he=m.run({threadId:le.threadId,message:ce,context:a,capabilities:Ce},Re);const $e=he[Symbol.asyncIterator]();for(H.current={iterator:$e,requestVersion:Z};;){const ue=await $e.next();if(z.current!==Z||ue.done)break;let c;try{c=l.parseAssistantEvent(ue.value)}catch(N){throw new j(N instanceof Error?N.message:"Invalid assistant event")}if(c.type==="message.start"){if(I!==void 0&&I!==c.runId)throw new j("AI 助手响应 run id 不一致");if(I??=c.runId,Me+=1,Me>l.MAKE_AI_CONVERSATION_LIMITS.assistantMessagesPerRun)throw new j("AI 助手单次响应消息数量超过限制");if(Se.has(c.messageId))throw new j("AI 助手响应包含重复的 message id");Se.add(c.messageId),te.add(c.messageId),se.set(c.messageId,0)}if(c.type==="message.delta"){if(!te.has(c.messageId))throw new j("AI 助手响应事件顺序无效");const N=se.get(c.messageId)??0,G=l.countCodePointsUpTo(c.delta,l.MAKE_AI_CONVERSATION_LIMITS.messageCharacters-ee);if(ee+G>l.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)throw new j("AI 助手响应文本超过大小限制");ee+=G,se.set(c.messageId,N+G)}if(c.type==="message.replace"){if(!te.has(c.messageId))throw new j("AI 助手响应事件顺序无效");const N=se.get(c.messageId)??0,G=l.countCodePointsUpTo(c.content,l.MAKE_AI_CONVERSATION_LIMITS.messageCharacters),Le=ee-N+G;if(Le>l.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)throw new j("AI 助手响应文本超过大小限制");ee=Le,se.set(c.messageId,G)}if(c.type==="run.progress"){if(I!==void 0&&I!==c.runId)throw new j("AI 助手响应 run id 不一致");if(I??=c.runId,Ee+=1,Ee>l.MAKE_AI_CONVERSATION_LIMITS.progressStepsPerRun)throw new j("AI 助手处理过程数量超过限制");const N=l.countCodePointsUpTo(c.message,l.MAKE_AI_CONVERSATION_LIMITS.progressCharactersPerRun-pe);if(pe+N>l.MAKE_AI_CONVERSATION_LIMITS.progressCharactersPerRun)throw new j("AI 助手处理过程文本超过大小限制");pe+=N}if(c.type==="artifact"){if(!te.has(c.messageId))throw new j("AI 助手响应事件顺序无效");if(Te+=1,Te>l.MAKE_AI_CONVERSATION_LIMITS.artifactsPerRun)throw new j("AI 助手单次响应 Artifact 数量超过限制");if(we.has(c.artifact.id))throw new j("AI 助手响应包含重复的 Artifact id");we.add(c.artifact.id)}if(c.type==="message.complete"&&!te.delete(c.messageId))throw new j("AI 助手响应事件顺序无效");if(c.type==="run.complete"&&I!==void 0&&I!==c.runId)throw new j("AI 助手响应 run id 不一致");if(c.type==="run.cancelled"&&c.runId!==void 0&&I!==void 0&&I!==c.runId)throw new j("AI 助手响应 run id 不一致");if(b(N=>l.reduceAssistantEvent(N,c)),c.type==="error"||c.type==="run.cancelled"||c.type==="run.complete"){$=!0;break}}if(!$)throw new j("AI 助手流式响应在终止事件前结束")}catch($){if(z.current!==Z)return;if(de.signal.aborted){b(I=>l.reduceAssistantEvent(I,{type:"run.cancelled"}));return}console.error("[make-ai-assistant] assistant run failed",{appId:a.app.id,errorType:$ instanceof Error?$.name:typeof $}),b(I=>l.reduceAssistantEvent(I,{type:"error",code:"TRANSPORT_ERROR",message:$ instanceof j?$.message:"连接失败,请重试",retryable:!0}))}finally{z.current===Z&&U.current===de&&(U.current=void 0),H.current?.requestVersion===Z&&(Oe(H.current.iterator),H.current=void 0)}},ie=o=>ke(o),as=o=>ke(o.userMessage.content,{regenerateFrom:o}),ns=async(o,f)=>{try{await ks(f),S({messageId:o,message:"已复制",status:"success"})}catch(g){console.error("[make-ai-assistant] copy answer failed",{errorType:g instanceof Error?g.name:typeof g}),S({messageId:o,message:"复制失败",status:"error"})}},rs=o=>{o.preventDefault(),ie(k)},is=o=>{o.key==="Enter"&&!o.shiftKey&&!o.nativeEvent.isComposing&&(o.preventDefault(),ie(k))},os=()=>{re("stop")&&b(o=>l.reduceAssistantEvent(o,{type:"run.cancelled"}))},cs=()=>{re("new-conversation"),K(""),B(void 0),S(void 0),C(!1),R.current=!0,b(l.createAssistantConversationState()),d?.()},be=m.features?.remoteCancellation===!1?"停止接收":"停止生成",ls=Ze(x),ds=Ge(x),oe=Vs(x),us=typeof m.regenerate=="function"&&m.features?.regeneration!==!1,Ne=()=>{oe&&ie(oe.content)};return e.jsxs("section",{className:"make-ai-assistant make-ai-assistant__panel",ref:_e,children:[e.jsxs("header",{className:"make-ai-assistant__header",children:[e.jsx(ae,{}),e.jsxs("div",{children:[e.jsx("h2",{children:V}),e.jsx("p",{children:y??`当前应用:${a.app.name??"未命名应用"}`})]}),e.jsxs("div",{className:"make-ai-assistant__header-actions",children:[m.features?.newConversation!==!1?e.jsx("button",{"aria-label":"新建对话",className:"make-ai-assistant__icon-button",type:"button",onClick:cs,children:e.jsx(ws,{})}):null,i?e.jsx("button",{"aria-label":`关闭 ${V}`,className:"make-ai-assistant__icon-button",type:"button",onClick:i,children:e.jsx(bs,{})}):null]})]}),p?e.jsxs("div",{className:"make-ai-assistant__privacy-note",role:"note",children:[e.jsx("span",{className:"make-ai-assistant__privacy-icon","aria-hidden":"true",children:e.jsx(Ms,{})}),e.jsx("span",{children:p})]}):null,e.jsxs("div",{className:"make-ai-assistant__body","aria-live":"polite","aria-relevant":"additions text",ref:Q,role:"log",onScroll:ss,children:[D==="loading"?e.jsxs("div",{className:"make-ai-assistant__empty",role:"status",children:[e.jsx(ae,{}),e.jsx("h3",{children:"正在恢复对话"}),e.jsx("p",{children:"正在读取当前 App 的历史消息…"})]}):D==="error"?e.jsxs("div",{className:"make-ai-assistant__empty",role:"alert",children:[e.jsx(ae,{}),e.jsx("h3",{children:"暂时无法加载对话"}),e.jsx("p",{children:"请检查网络后重试。"}),e.jsx("button",{className:"make-ai-assistant__retry",type:"button",onClick:()=>Xe(o=>o+1),children:"重新加载"})]}):x.messages.length===0?e.jsxs("div",{className:"make-ai-assistant__empty",children:[e.jsx(ae,{}),e.jsx("h3",{children:"有什么可以帮你?"}),e.jsx("p",{children:"我会结合当前 App、页面位置和宿主允许的上下文回答,并把过程与结果分开展示。"})]}):qs(x,a,Ie,n,r,s,oe?Ne:void 0,q,F,me,us,(o,f)=>{ns(o,f)},o=>{as(o)}),x.progress&&!ls?e.jsx(Ve,{assistantName:s,progress:x.progress}):null,x.error&&!ds?e.jsx(Ve,{assistantName:s,error:x.error,onRetry:oe?Ne:void 0}):null]}),es?e.jsx("button",{"aria-label":"回到最新消息",className:"make-ai-assistant__back-to-latest",type:"button",onClick:ts,children:e.jsx(Es,{})}):null,e.jsxs("footer",{className:"make-ai-assistant__composer-region",children:[D==="ready"&&ye.length>0&&x.messages.length===0?e.jsx("div",{className:"make-ai-assistant__suggestions","aria-label":"推荐问题",children:ye.map((o,f)=>e.jsx("button",{type:"button",onClick:()=>{ie(o)},children:o},`${f}-${o}`))}):null,e.jsxs("form",{className:"make-ai-assistant__composer",onSubmit:rs,children:[e.jsx("textarea",{"aria-label":`向 ${s} 提问`,"aria-describedby":P?"make-ai-composer-error":void 0,"aria-invalid":P?!0:void 0,autoFocus:!0,disabled:D!=="ready"||x.status==="streaming",placeholder:`询问当前 ${a.app.name??"App"} 中的数据…`,ref:xe,rows:2,value:k,onChange:o=>{K(o.currentTarget.value),B(void 0)},onKeyDown:is}),x.status==="streaming"?e.jsx("button",{"aria-label":be,className:"make-ai-assistant__send make-ai-assistant__send--stop","data-tooltip":be,ref:je,type:"button",onClick:os,children:e.jsx("span",{"aria-hidden":"true"})}):e.jsx("button",{"aria-label":"发送",className:"make-ai-assistant__send",disabled:D!=="ready"||!k.trim(),type:"submit",children:e.jsx(Ss,{})})]}),P?e.jsx("p",{id:"make-ai-composer-error",role:"alert",children:P}):null,e.jsx("p",{children:"AI 生成的结果可能存在偏差,重要数据请核对明细。"})]})]})}function Ds(s){return e.jsx(Je,{...s,visible:!0})}function Us({defaultOpen:s=!1,hideLauncher:t=!1,launcher:a,onOpenChange:n,open:r,...i}){const d=Ue(i.brandName,i.title),[h,_]=u.useState(s),[y,T]=u.useState(()=>s||r===!0),M=u.useRef(null),m=r??h,F=v=>{r===void 0&&_(v),n?.(v),v||requestAnimationFrame(()=>M.current?.focus())},q=()=>F(!m);return u.useEffect(()=>{m&&T(!0)},[m]),u.useEffect(()=>{if(!m)return;const v=V=>{V.key==="Escape"&&(F(!1),requestAnimationFrame(()=>M.current?.focus()))};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[n,m]),e.jsxs("div",{className:"make-ai-assistant","data-open":m||void 0,children:[!t&&(!m||a)?a?a({open:m,toggle:q}):e.jsxs("button",{"aria-label":m?`关闭 ${d}`:`打开 ${d}`,"aria-expanded":m,className:"make-ai-assistant__launcher",ref:M,type:"button",onClick:q,children:[e.jsx("span",{className:"make-ai-assistant__launcher-orbit","aria-hidden":"true"}),e.jsx(He,{})]}):null,y?e.jsx("aside",{"aria-label":d,"aria-modal":"false",className:"make-ai-assistant__drawer",hidden:!m,role:"dialog",children:e.jsx(Je,{...i,onClose:()=>F(!1),visible:m})}):null]})}exports.createArtifactCapabilities=O.createArtifactCapabilities;exports.createArtifactTemplateRegistry=O.createArtifactTemplateRegistry;exports.extendArtifactTemplateRegistry=O.extendArtifactTemplateRegistry;exports.resolveArtifactTemplate=O.resolveArtifactTemplate;exports.MAKE_AI_ARTIFACT_KINDS=l.MAKE_AI_ARTIFACT_KINDS;exports.MAKE_AI_ARTIFACT_LIMITS=l.MAKE_AI_ARTIFACT_LIMITS;exports.MAKE_AI_ARTIFACT_SCHEMA_VERSION=l.MAKE_AI_ARTIFACT_SCHEMA_VERSION;exports.MAKE_AI_CONVERSATION_LIMITS=l.MAKE_AI_CONVERSATION_LIMITS;exports.appendUserMessage=l.appendUserMessage;exports.createAssistantConversationState=l.createAssistantConversationState;exports.parseArtifact=l.parseArtifact;exports.parseAssistantEvent=l.parseAssistantEvent;exports.reduceAssistantEvent=l.reduceAssistantEvent;exports.validateArtifact=l.validateArtifact;exports.ArtifactRenderer=Ke;exports.AssistantPanel=Ds;exports.MakeAiAssistant=Us;exports.createPlatformArtifactRegistry=De;exports.formatArtifactValue=L;exports.platformArtifactTemplates=qe;
3
+ `),c=()=>{const g=a.join(`
4
+ `).trim();a.length=0,g&&t.push({type:"paragraph",text:g})},h=()=>{r.length&&t.push({type:"list",items:r.splice(0)})},I=()=>{const g=n.join(`
5
+ `).trim();n.length=0,g&&t.push({type:"pre",text:g})};for(let g=0;g<i.length;g+=1){const L=i[g]??"",E=L.trim();if(!E){c(),h(),I();continue}const R=Gs(i,g);if(R){c(),h(),I(),t.push({headers:R.headers,rows:R.rows,type:"table"}),g=R.lastIndex;continue}const x=/^(#{1,6})\s+(.+)$/.exec(E);if(x){c(),h(),I();const F=(x[2]??"").replace(/\s+#+\s*$/,"").trim();F&&t.push({type:"heading",level:x[1]?.length,text:F});continue}if(/^\s*\|.+\|\s*$/.test(L)){c(),h(),n.push(L.trim());continue}const b=/^\s*[-*]\s+(.+)$/.exec(L);if(b){c(),I(),r.push(b[1]?.trim()??"");continue}h(),I(),a.push(E)}return c(),h(),I(),t},ue=s=>{const t=[],a=/(\*\*[^*]+\*\*|`[^`]+`)/g;let r=0;for(const n of s.matchAll(a)){const i=n[0],c=n.index??0;c>r&&t.push(s.slice(r,c)),i.startsWith("**")?t.push(e.jsx("strong",{children:i.slice(2,-2)},`${c}-strong`)):t.push(e.jsx("code",{children:i.slice(1,-1)},`${c}-code`)),r=c+i.length}return r<s.length&&t.push(s.slice(r)),t},Js=({content:s})=>{const t=Qs(s);return t.length?e.jsx("div",{className:"make-ai-assistant__bubble make-ai-assistant__assistant-text",children:t.map((a,r)=>{if(a.type==="heading"){const n=a.level<=2?"h3":"h4";return e.jsx(n,{className:`make-ai-assistant__markdown-heading make-ai-assistant__markdown-heading--${a.level}`,children:ue(a.text)},`${r}-heading`)}return a.type==="paragraph"?e.jsx("p",{children:ue(a.text)},`${r}-paragraph`):a.type==="pre"?e.jsx("pre",{children:e.jsx("code",{children:a.text})},`${r}-pre`):a.type==="table"?e.jsx("div",{"aria-label":"表格内容,可横向滚动",className:"make-ai-assistant__markdown-table-scroll",role:"region",tabIndex:0,children:e.jsxs("table",{className:"make-ai-assistant__markdown-table",children:[e.jsx("thead",{children:e.jsx("tr",{children:a.headers.map((n,i)=>e.jsx("th",{scope:"col",children:ue(n)},`${i}-${n}`))})}),e.jsx("tbody",{children:a.rows.map((n,i)=>e.jsx("tr",{children:n.map((c,h)=>e.jsx("td",{children:ue(c)},`${h}-${c}`))},`${i}-${n.join("|")}`))})]})},`${r}-table`):e.jsx("ul",{children:a.items.map((n,i)=>e.jsx("li",{children:ue(n)},`${i}-${n}`))},`${r}-list`)})}):null},ns=({assistantName:s})=>e.jsxs("div",{className:"make-ai-assistant__message-identity",children:[e.jsx(je,{className:"make-ai-assistant__avatar--message"}),e.jsx("span",{className:"make-ai-assistant__message-sender",children:s})]}),rs=s=>{for(let t=s.messages.length-1;t>=0;t-=1){const a=s.messages[t];if(a.role==="assistant"&&a.status==="streaming")return a.id}},et=s=>{for(let t=s.messages.length-1;t>=0;t-=1)if(s.messages[t].role==="user")return t;return-1},is=s=>{const t=et(s);if(!(t<0))for(let a=s.messages.length-1;a>t;a-=1){const r=s.messages[a];if(r.role==="assistant")return r.id}},st=s=>{if(s.status==="idle")for(let t=s.messages.length-1;t>=0;t-=1){const a=s.messages[t];if(a.role==="assistant"&&a.status==="complete")return a.id}},tt=s=>{for(let t=s.messages.length-1;t>=0;t-=1){const a=s.messages[t];if(a.role==="user")return a}},at=(s,t)=>{const a=s.messages.findIndex(r=>r.id===t&&r.role==="user");return{...s,error:void 0,progress:void 0,status:"streaming",messages:a<0?s.messages:s.messages.slice(0,a+1)}},nt=s=>s.scrollHeight-s.scrollTop-s.clientHeight<=48,Ze=(s="smooth")=>globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches?"auto":s,be=(s,t)=>{typeof s.scrollTo=="function"?s.scrollTo({top:s.scrollHeight,behavior:t}):s.scrollTop=s.scrollHeight},os=({error:s,onRetry:t})=>e.jsxs("div",{className:"make-ai-assistant__message-status make-ai-assistant__message-status--error","data-error-presentation":"request-failed",role:"alert",children:[e.jsxs("div",{className:"make-ai-assistant__message-status-header",children:[e.jsx("span",{className:"make-ai-assistant__message-status-icon","aria-hidden":"true",children:e.jsx(Hs,{})}),e.jsx("strong",{children:"请求未完成"})]}),e.jsx("span",{className:"make-ai-assistant__message-status-message",children:s.message}),s.retryable&&t?e.jsxs("button",{className:"make-ai-assistant__retry",type:"button",onClick:t,children:[e.jsx(as,{}),"重新发送"]}):null]}),rt=({error:s,onRetry:t})=>{const a=Ds(s);return e.jsxs("section",{"aria-live":"assertive",className:"make-ai-assistant__load-failure","data-load-failure-kind":a.kind,role:"alert",children:[e.jsx("span",{className:"make-ai-assistant__load-failure-icon","aria-hidden":"true",children:e.jsxs("svg",{viewBox:"0 0 24 24",children:[e.jsx("path",{d:"M5 12a7 7 0 0 1 13.4-2.8A4.5 4.5 0 0 1 18 18H7.5A4.5 4.5 0 0 1 5 12Z"}),e.jsx("path",{d:"m9.2 14.8 5.6-5.6M9.2 9.2l5.6 5.6"})]})}),e.jsxs("div",{className:"make-ai-assistant__load-failure-copy",children:[e.jsx("span",{className:"make-ai-assistant__load-failure-label",children:a.label}),e.jsx("h3",{children:a.title}),e.jsx("p",{children:a.description})]}),e.jsxs("button",{className:"make-ai-assistant__retry make-ai-assistant__retry--primary",type:"button",onClick:t,children:[e.jsx(as,{}),a.actionLabel]})]})},cs=({active:s,steps:t})=>{if(!s||!t?.length)return null;const a=t[t.length-1]??"处理中";return e.jsxs("details",{className:"make-ai-assistant__process",open:!0,children:[e.jsxs("summary",{children:[e.jsxs("span",{className:"make-ai-assistant__progress",role:"status",children:[e.jsx("span",{"aria-hidden":"true"}),e.jsx("span",{children:a})]}),e.jsxs("span",{className:"make-ai-assistant__process-count",children:[t.length," 步"]})]}),e.jsx("ol",{children:t.map((r,n)=>e.jsxs("li",{"data-step-active":n===t.length-1?!0:void 0,children:[e.jsx("span",{"aria-hidden":"true"}),e.jsx("span",{children:r})]},`${n}-${r}`))})]})},it=({copyFeedback:s,onCopy:t,onRegenerate:a})=>!t&&!a?null:e.jsxs("div",{className:"make-ai-assistant__reply-actions","aria-label":"回复操作",children:[t?e.jsx("button",{"aria-label":"复制回答",className:"make-ai-assistant__reply-action make-ai-assistant__reply-copy","data-tooltip":"复制",type:"button",onClick:t,children:e.jsx(Vs,{})}):null,a?e.jsx("button",{"aria-label":"重新生成",className:"make-ai-assistant__reply-action make-ai-assistant__reply-regenerate","data-tooltip":"重新生成",type:"button",onClick:a,children:e.jsx(Ws,{})}):null,s?e.jsx("span",{className:"make-ai-assistant__reply-feedback","data-copy-status":s.status,role:"status",children:s.message}):null]}),Xe=({assistantName:s,error:t,onRetry:a,progress:r})=>{const n=t?"error":"progress";return t?.message??r?.message?e.jsx("article",{"aria-label":`${s}的${n==="error"?"错误消息":"状态消息"}`,className:`make-ai-assistant__message make-ai-assistant__message--assistant make-ai-assistant__message--${n}`,"data-message-role":"assistant","data-message-state":n,children:e.jsxs("div",{className:"make-ai-assistant__message-turn",children:[e.jsx(ns,{assistantName:s}),e.jsx("div",{className:"make-ai-assistant__message-stack",children:t?e.jsx(os,{error:t,onRetry:a}):e.jsx(cs,{active:!0,steps:r?.steps})})]})}):null},ot=(s,t,a,r,n,i,c,h,I,g,L,E,R)=>{const x=is(s),b=rs(s),F=st(s);let T;return s.messages.map(m=>{const w=m.role==="assistant",K=T;w||(T=m);const y=m.id===b,Y=m.id===x?s.error:void 0,C=m.error??Y,O=!w&&!!(h?.trim()||I),f=w?i:h?.trim()||"用户",S=w&&m.status==="complete"&&!C&&(m.content.trim()||m.id===F);return e.jsx("article",{"aria-label":`${f}的消息`,className:`make-ai-assistant__message make-ai-assistant__message--${m.role}`,"data-message-role":m.role,"data-message-state":C?"error":void 0,"data-message-status":m.status,"data-message-has-identity":w||O?!0:void 0,children:e.jsxs("div",{className:"make-ai-assistant__message-turn",children:[w?e.jsx(ns,{assistantName:i}):O?e.jsx(Xs,{userAvatarUrl:I,userName:h}):null,e.jsxs("div",{className:"make-ai-assistant__message-stack",children:[m.content?w?e.jsx(Js,{content:m.content}):e.jsx("div",{className:"make-ai-assistant__bubble",children:m.content}):m.status==="streaming"?e.jsxs("div",{className:"make-ai-assistant__typing","aria-label":`${i}正在思考`,children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}):null,w?e.jsx(cs,{active:y&&s.status==="streaming",steps:m.progressSteps}):null,C?e.jsx(os,{error:C,onRetry:Y?c:void 0}):null,m.artifacts.map(D=>e.jsx(Ye,{artifact:D,context:t,onAction:r,onActionError:n,registry:a},D.id)),S?e.jsx(it,{copyFeedback:g?.messageId===m.id?{message:g.message,status:g.status}:void 0,onCopy:m.content.trim()?()=>E(m.id,m.content):void 0,onRegenerate:L&&m.id===F&&K?()=>R({userMessage:K,assistantMessage:m}):void 0}):null]})]})},m.id)})};function ls({assistantName:s="AI 助手",brandName:t,context:a,onAction:r,onActionError:n,onClose:i,onNewConversation:c,headerHeight:h,privacyNotice:I,registry:g,subtitle:L,suggestions:E,title:R,transport:x,userAvatarUrl:b,userName:F,visible:T}){const m=ss(t,R),w=I?.trim(),K=L?.trim()||`当前对象:${a.app.name??"未命名应用"}`,y=Fs(h),Y=y?{"--make-ai-internal-header-height":y}:void 0,[C,O]=u.useState(""),[f,S]=u.useState(d.createAssistantConversationState),D=u.useRef(f);D.current=f;const[H,Z]=u.useState(void 0),[re,V]=u.useState(void 0),[p,A]=u.useState(0),[N,X]=u.useState(()=>x.loadConversation?"loading":"ready"),[ds,Ae]=u.useState(void 0),[us,W]=u.useState(!1),G=u.useRef(void 0),Q=u.useRef(void 0),J=u.useRef(0),we=u.useRef(null),ie=u.useRef(null),Ne=u.useRef(null),Me=u.useRef(null),B=u.useRef(!0),Te=u.useRef(a.app.id),Ee=u.useRef(T),Se=u.useMemo(()=>g??es(),[g]),Re=u.useMemo(()=>$s(E),[E]),me=o=>{const _=G.current,v=Q.current?.iterator;return!_&&!v?!1:(J.current+=1,G.current=void 0,Q.current=void 0,console.info("[make-ai-assistant] local run cancellation requested",{reason:o}),_?.abort(),He(v),!0)};u.useEffect(()=>()=>{me("unmount")},[]),u.useEffect(()=>{const o=x.loadConversation,_=Te.current!==a.app.id;if(Te.current=a.app.id,me("reinitialize"),_&&(O(""),B.current=!0),Z(void 0),V(void 0),W(!1),S(d.createAssistantConversationState()),!o){Ae(void 0),X("ready");return}const v=new AbortController;return Ae(void 0),X("loading"),console.info("[make-ai-assistant] conversation load start",{appId:a.app.id}),o.call(x,a,{signal:v.signal}).then(k=>{v.signal.aborted||(S(d.createAssistantConversationState(k)),X("ready"),console.info("[make-ai-assistant] conversation load success",{appId:a.app.id,messageCount:k.messages.length}))}).catch(k=>{v.signal.aborted||(console.error("[make-ai-assistant] conversation load failed",{appId:a.app.id,errorType:k instanceof Error?k.name:typeof k}),Ae(k),X("error"))}),()=>v.abort()},[a.app.id,p,x]),u.useEffect(()=>{const o=ie.current;if(!o||!B.current)return;W(!1);const _=requestAnimationFrame(()=>{if(!B.current)return;const v=f.status==="streaming"||globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches?"auto":"smooth";be(o,v)});return()=>cancelAnimationFrame(_)},[f.messages,f.progress,f.status]),u.useEffect(()=>{const o=T&&!Ee.current;if(Ee.current=T,!o)return;const _=requestAnimationFrame(()=>{const v=ie.current;if(v&&B.current){W(!1);const oe=D.current.status==="streaming"?"auto":Ze();be(v,oe)}else v&&W(D.current.messages.length>0);const k=Ne.current;(k&&!k.disabled?k:Me.current??we.current?.querySelector("button:not(:disabled)"))?.focus()});return()=>cancelAnimationFrame(_)},[T]);const ms=()=>{const o=ie.current;if(!o)return;const _=nt(o);B.current=_,W(!_&&D.current.messages.length>0)},hs=()=>{const o=ie.current;if(!o)return;B.current=!0,W(!1);const _=Ze();be(o,_)},Ce=async(o,_)=>{const v=o.trim(),k=D.current,P=_?.regenerateFrom,oe=x.regenerate;if(!v||N!=="ready"||k.status==="streaming"||G.current||P&&!oe)return;if(d.countCodePointsUpTo(v,d.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)>d.MAKE_AI_CONVERSATION_LIMITS.messageCharacters){Z(`输入内容过长,请控制在 ${d.MAKE_AI_CONVERSATION_LIMITS.messageCharacters} 个字符以内`);return}const fe={id:P?.userMessage.id??Ss("user"),content:v},ge=P?at(k,P.userMessage.id):d.appendUserMessage(k,fe),xe=new AbortController,ee=J.current+1;J.current=ee,G.current=xe,Z(void 0),V(void 0),W(!B.current&&k.messages.length>0),P||O(""),S(ge);try{let z=!1,M,Fe=0,Oe=0,De=0,Ie=0,ce=0;const le=new Map,Pe=new Set,Ke=new Set([...ge.messages.map(_e=>_e.id),fe.id]),de=new Set,Ve=q.createArtifactCapabilities(Se),We={signal:xe.signal};let ye;if(P){if(!oe)throw new j("当前 AI 助手不支持重新生成");ye=oe({threadId:ge.threadId,message:fe,assistantMessage:{id:P.assistantMessage.id,content:P.assistantMessage.content},context:a,capabilities:Ve},We)}else ye=x.run({threadId:ge.threadId,message:fe,context:a,capabilities:Ve},We);const Be=ye[Symbol.asyncIterator]();for(Q.current={iterator:Be,requestVersion:ee};;){const _e=await Be.next();if(J.current!==ee||_e.done)break;let l;try{l=d.parseAssistantEvent(_e.value)}catch($){throw new j($ instanceof Error?$.message:"Invalid assistant event")}if(l.type==="message.start"){if(M!==void 0&&M!==l.runId)throw new j("AI 助手响应 run id 不一致");if(M??=l.runId,Oe+=1,Oe>d.MAKE_AI_CONVERSATION_LIMITS.assistantMessagesPerRun)throw new j("AI 助手单次响应消息数量超过限制");if(Ke.has(l.messageId))throw new j("AI 助手响应包含重复的 message id");Ke.add(l.messageId),de.add(l.messageId),le.set(l.messageId,0)}if(l.type==="message.delta"){if(!de.has(l.messageId))throw new j("AI 助手响应事件顺序无效");const $=le.get(l.messageId)??0,se=d.countCodePointsUpTo(l.delta,d.MAKE_AI_CONVERSATION_LIMITS.messageCharacters-ce);if(ce+se>d.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)throw new j("AI 助手响应文本超过大小限制");ce+=se,le.set(l.messageId,$+se)}if(l.type==="message.replace"){if(!de.has(l.messageId))throw new j("AI 助手响应事件顺序无效");const $=le.get(l.messageId)??0,se=d.countCodePointsUpTo(l.content,d.MAKE_AI_CONVERSATION_LIMITS.messageCharacters),ze=ce-$+se;if(ze>d.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)throw new j("AI 助手响应文本超过大小限制");ce=ze,le.set(l.messageId,se)}if(l.type==="run.progress"){if(M!==void 0&&M!==l.runId)throw new j("AI 助手响应 run id 不一致");if(M??=l.runId,De+=1,De>d.MAKE_AI_CONVERSATION_LIMITS.progressStepsPerRun)throw new j("AI 助手处理过程数量超过限制");const $=d.countCodePointsUpTo(l.message,d.MAKE_AI_CONVERSATION_LIMITS.progressCharactersPerRun-Ie);if(Ie+$>d.MAKE_AI_CONVERSATION_LIMITS.progressCharactersPerRun)throw new j("AI 助手处理过程文本超过大小限制");Ie+=$}if(l.type==="artifact"){if(!de.has(l.messageId))throw new j("AI 助手响应事件顺序无效");if(Fe+=1,Fe>d.MAKE_AI_CONVERSATION_LIMITS.artifactsPerRun)throw new j("AI 助手单次响应 Artifact 数量超过限制");if(Pe.has(l.artifact.id))throw new j("AI 助手响应包含重复的 Artifact id");Pe.add(l.artifact.id)}if(l.type==="message.complete"&&!de.delete(l.messageId))throw new j("AI 助手响应事件顺序无效");if(l.type==="run.complete"&&M!==void 0&&M!==l.runId)throw new j("AI 助手响应 run id 不一致");if(l.type==="run.cancelled"&&l.runId!==void 0&&M!==void 0&&M!==l.runId)throw new j("AI 助手响应 run id 不一致");if(S($=>d.reduceAssistantEvent($,l)),l.type==="error"||l.type==="run.cancelled"||l.type==="run.complete"){z=!0;break}}if(!z)throw new j("AI 助手流式响应在终止事件前结束")}catch(z){if(J.current!==ee)return;if(xe.signal.aborted){S(M=>d.reduceAssistantEvent(M,{type:"run.cancelled"}));return}console.error("[make-ai-assistant] assistant run failed",{appId:a.app.id,errorType:z instanceof Error?z.name:typeof z}),S(M=>d.reduceAssistantEvent(M,{type:"error",code:"TRANSPORT_ERROR",message:z instanceof j?z.message:"连接失败,请重试",retryable:!0}))}finally{J.current===ee&&G.current===xe&&(G.current=void 0),Q.current?.requestVersion===ee&&(He(Q.current.iterator),Q.current=void 0)}},he=o=>Ce(o),ps=o=>Ce(o.userMessage.content,{regenerateFrom:o}),fs=async(o,_)=>{try{await Ps(_),V({messageId:o,message:"已复制",status:"success"})}catch(v){console.error("[make-ai-assistant] copy answer failed",{errorType:v instanceof Error?v.name:typeof v}),V({messageId:o,message:"复制失败",status:"error"})}},gs=o=>{o.preventDefault(),he(C)},xs=o=>{o.key==="Enter"&&!o.shiftKey&&!o.nativeEvent.isComposing&&(o.preventDefault(),he(C))},_s=()=>{me("stop")&&S(o=>d.reduceAssistantEvent(o,{type:"run.cancelled"}))},vs=()=>{me("new-conversation"),O(""),Z(void 0),V(void 0),W(!1),B.current=!0,S(d.createAssistantConversationState()),c?.()},$e=x.features?.remoteCancellation===!1?"停止接收":"停止生成",js=rs(f),As=is(f),pe=tt(f),Is=typeof x.regenerate=="function"&&x.features?.regeneration!==!1,Le=()=>{pe&&he(pe.content)};return e.jsxs("section",{className:"make-ai-assistant make-ai-assistant__panel",ref:we,style:Y,children:[e.jsxs("header",{className:"make-ai-assistant__header",children:[e.jsx(je,{}),e.jsxs("div",{className:"make-ai-assistant__header-content",children:[e.jsxs("div",{className:"make-ai-assistant__header-title-row",children:[e.jsx("h2",{className:"make-ai-assistant__header-title",title:m,children:m}),e.jsx("span",{className:"make-ai-assistant__read-only-tag",children:"只读"})]}),e.jsxs("div",{className:"make-ai-assistant__header-context",children:[e.jsx("p",{title:K,children:K}),w?e.jsx("span",{"aria-label":`使用提示:${w}`,className:"make-ai-assistant__header-context-help","data-tooltip":w,role:"note",tabIndex:0,children:e.jsx(Bs,{})}):null]})]}),e.jsxs("div",{className:"make-ai-assistant__header-actions",children:[x.features?.newConversation!==!1?e.jsx("button",{"aria-label":"新建对话",className:"make-ai-assistant__icon-button",type:"button",onClick:vs,children:e.jsx(Us,{})}):null,i?e.jsx("button",{"aria-label":`关闭 ${m}`,className:"make-ai-assistant__icon-button",type:"button",onClick:i,children:e.jsx(Ks,{})}):null]})]}),e.jsxs("div",{className:"make-ai-assistant__body","aria-live":"polite","aria-relevant":"additions text",ref:ie,role:"log",onScroll:ms,children:[N==="loading"?e.jsxs("div",{className:"make-ai-assistant__empty",role:"status",children:[e.jsx(je,{}),e.jsx("h3",{children:"正在恢复对话"}),e.jsx("p",{children:"正在读取当前 App 的历史消息…"})]}):N==="error"?e.jsx("div",{className:"make-ai-assistant__empty",children:e.jsx(rt,{error:ds,onRetry:()=>A(o=>o+1)})}):f.messages.length===0?e.jsxs("div",{className:"make-ai-assistant__empty",children:[e.jsx(je,{}),e.jsx("h3",{children:"有什么可以帮你?"}),e.jsx("p",{children:"我会结合当前 App、页面位置和宿主允许的上下文回答,并把过程与结果分开展示。"})]}):ot(f,a,Se,r,n,s,pe?Le:void 0,F,b,re,Is,(o,_)=>{fs(o,_)},o=>{ps(o)}),f.progress&&!js?e.jsx(Xe,{assistantName:s,progress:f.progress}):null,f.error&&!As?e.jsx(Xe,{assistantName:s,error:f.error,onRetry:pe?Le:void 0}):null]}),us?e.jsx("button",{"aria-label":"回到最新消息",className:"make-ai-assistant__back-to-latest",type:"button",onClick:hs,children:e.jsx(zs,{})}):null,e.jsxs("footer",{className:"make-ai-assistant__composer-region",children:[N==="ready"&&Re.length>0&&f.messages.length===0?e.jsx("div",{className:"make-ai-assistant__suggestions","aria-label":"推荐问题",children:Re.map((o,_)=>e.jsx("button",{type:"button",onClick:()=>{he(o)},children:o},`${_}-${o}`))}):null,e.jsxs("form",{className:"make-ai-assistant__composer",onSubmit:gs,children:[e.jsx("textarea",{"aria-label":`向 ${s} 提问`,"aria-describedby":H?"make-ai-composer-error":void 0,"aria-invalid":H?!0:void 0,autoFocus:!0,disabled:N!=="ready"||f.status==="streaming",placeholder:`询问当前 ${a.app.name??"App"} 中的数据…`,ref:Ne,rows:2,value:C,onChange:o=>{O(o.currentTarget.value),Z(void 0)},onKeyDown:xs}),f.status==="streaming"?e.jsx("button",{"aria-label":$e,className:"make-ai-assistant__send make-ai-assistant__send--stop","data-tooltip":$e,ref:Me,type:"button",onClick:_s,children:e.jsx("span",{"aria-hidden":"true"})}):e.jsx("button",{"aria-label":"发送",className:"make-ai-assistant__send",disabled:N!=="ready"||!C.trim(),type:"submit",children:e.jsx(qs,{})})]}),H?e.jsx("p",{id:"make-ai-composer-error",role:"alert",children:H}):null,e.jsx("p",{children:"AI 生成的结果可能存在偏差,重要数据请核对明细。"})]})]})}function ct(s){return e.jsx(ls,{...s,visible:!0})}function lt({defaultOpen:s=!1,hideLauncher:t=!1,launcher:a,onOpenChange:r,open:n,...i}){const c=ss(i.brandName,i.title),[h,I]=u.useState(s),[g,L]=u.useState(()=>s||n===!0),E=u.useRef(null),R=u.useRef(null),x=u.useRef(void 0),[b,F]=u.useState(),[T,m]=u.useState(Ls),[w,K]=u.useState(!1),y=n??h,Y=typeof window>"u"?void 0:window.innerWidth,C=b===void 0?void 0:{"--make-ai-internal-drawer-width":`${b}px`},O=()=>{if(b!==void 0)return b;const p=R.current?.getBoundingClientRect().width;return p&&Number.isFinite(p)&&p>0?p:T},f=()=>typeof window>"u"?Number.POSITIVE_INFINITY:window.innerWidth,S=p=>{if(p.button!==0)return;const A=O(),N=b===void 0?A:T;m(N),x.current={minimumWidth:N,pointerId:p.pointerId,startWidth:A,startX:p.clientX},K(!0),typeof p.currentTarget.setPointerCapture=="function"&&p.currentTarget.setPointerCapture(p.pointerId),p.preventDefault()},D=p=>{const A=x.current;if(!A||A.pointerId!==p.pointerId)return;const N=qe(A.startWidth+A.startX-p.clientX,A.minimumWidth,f());F(N)},H=p=>{const A=x.current;!A||A.pointerId!==p.pointerId||(x.current=void 0,K(!1))},Z=p=>{const A=p.key==="ArrowLeft"?Ue:p.key==="ArrowRight"?-Ue:void 0;if(A===void 0)return;p.preventDefault();const N=O(),X=b===void 0?N:T;m(X),F(qe(N+A,X,f()))},re=p=>{n===void 0&&I(p),r?.(p),p||requestAnimationFrame(()=>E.current?.focus())},V=()=>re(!y);return u.useEffect(()=>{y&&L(!0)},[y]),u.useEffect(()=>{if(!y)return;const p=A=>{A.key==="Escape"&&(re(!1),requestAnimationFrame(()=>E.current?.focus()))};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[r,y]),e.jsxs("div",{className:"make-ai-assistant","data-open":y||void 0,children:[!t&&(!y||a)?a?a({open:y,toggle:V}):e.jsxs("button",{"aria-label":y?`关闭 ${c}`:`打开 ${c}`,"aria-expanded":y,className:"make-ai-assistant__launcher",ref:E,type:"button",onClick:V,children:[e.jsx("span",{className:"make-ai-assistant__launcher-orbit","aria-hidden":"true"}),e.jsx(ts,{})]}):null,g?e.jsxs("aside",{"aria-label":c,"aria-modal":"false",className:"make-ai-assistant__drawer","data-resizing":w||void 0,hidden:!y,ref:R,role:"dialog",style:C,children:[e.jsx("div",{"aria-label":"调整对话框宽度","aria-orientation":"vertical","aria-valuemax":Y,"aria-valuemin":T,"aria-valuenow":b??T,className:"make-ai-assistant__drawer-resize-handle",role:"separator",tabIndex:0,onKeyDown:Z,onPointerCancel:H,onPointerDown:S,onPointerMove:D,onPointerUp:H}),e.jsx(ls,{...i,onClose:()=>re(!1),visible:y})]}):null]})}exports.createArtifactCapabilities=q.createArtifactCapabilities;exports.createArtifactTemplateRegistry=q.createArtifactTemplateRegistry;exports.extendArtifactTemplateRegistry=q.extendArtifactTemplateRegistry;exports.resolveArtifactTemplate=q.resolveArtifactTemplate;exports.MAKE_AI_ARTIFACT_KINDS=d.MAKE_AI_ARTIFACT_KINDS;exports.MAKE_AI_ARTIFACT_LIMITS=d.MAKE_AI_ARTIFACT_LIMITS;exports.MAKE_AI_ARTIFACT_SCHEMA_VERSION=d.MAKE_AI_ARTIFACT_SCHEMA_VERSION;exports.MAKE_AI_CONVERSATION_LIMITS=d.MAKE_AI_CONVERSATION_LIMITS;exports.appendUserMessage=d.appendUserMessage;exports.createAssistantConversationState=d.createAssistantConversationState;exports.parseArtifact=d.parseArtifact;exports.parseAssistantEvent=d.parseAssistantEvent;exports.reduceAssistantEvent=d.reduceAssistantEvent;exports.validateArtifact=d.validateArtifact;exports.ArtifactRenderer=Ye;exports.AssistantPanel=ct;exports.MakeAiAssistant=lt;exports.createPlatformArtifactRegistry=es;exports.formatArtifactValue=U;exports.platformArtifactTemplates=Je;