@qfei-design/make-ai-assistant 0.2.4 → 0.2.6

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
@@ -45,7 +45,7 @@ Fetch SSE 实现时,从 `/sse` 入口导入 `createSseAssistantTransport`。
45
45
  `--make-ai-header-height` 覆盖。浮动入口位置可通过
46
46
  `--make-ai-launcher-top`、`--make-ai-launcher-right` 和 `--make-ai-launcher-mobile-right` 覆盖。
47
47
  桌面端抽屉可从左边缘 12px 热区向左拖宽,初始计算宽度(默认 432px,或宿主的
48
- `--make-ai-drawer-width`)同时作为拖拽下限;热区激活时展示 2px 纯紫色提示线,宿主可通过
48
+ `--make-ai-drawer-width`)同时作为拖拽下限;热区激活时展示 2px 主题色提示线,宿主可通过
49
49
  `--make-ai-drawer-resize-line` 覆盖其颜色;手柄支持左右方向键微调。小于 560px 的视口保持全宽,
50
50
  不提供宽度调整。
51
51
  面板按自身容器宽度适配:达到 560px 时扩展内容区间距和阅读宽度,达到 760px 时 Markdown 表格
@@ -65,6 +65,17 @@ Fetch SSE 实现时,从 `/sse` 入口导入 `createSseAssistantTransport`。
65
65
  - `ReactArtifactTemplateRegistry`
66
66
  - `formatArtifactValue`
67
67
 
68
+ `MakeAiAssistant`、`AssistantPanel` 和 `ArtifactRenderer` 均支持 `theme?: MakeAiTheme`。`primary` 为必填,
69
+ 其余可选字段包括 `primaryHover`、`onPrimary`、`background`、`surface`、`surfaceStrong`、`text`、
70
+ `textSecondary`、`border`、`overlay` 和 `onOverlay`。主题仅写入组件根节点的局部
71
+ `--make-ai-theme-*` 变量,不覆盖宿主全局样式。颜色优先级为 `theme` 属性 >
72
+ `--make-ai-theme-*` 变量 > 其他 `--make-ai-*` 覆盖变量 > 宿主 `--make-color-*` 变量 > 包内默认值;传入
73
+ `theme` 后,未提供的可选颜色也会由 `primary` 派生,确保 AI 包不混入宿主另一套颜色。边框、表面、阴影、
74
+ Tooltip、强调图标和拖拽线均会跟随主题主色,语义成功/告警/错误色保持独立。主色偏浅时,宿主应提供有足够对比度的
75
+ `onPrimary`。`ArtifactRenderer` 的平台内置模板会将主题变量
76
+ 直接写入既有 Artifact 根节点,不新增 DOM 包装;自定义模板可从 `ArtifactTemplateRenderContext.theme` 与
77
+ `themeStyle` 读取同一主题并应用到自身根节点。
78
+
68
79
  `ArtifactRenderer`、`AssistantPanel` 和 `MakeAiAssistant` 支持 `onActionError`。当宿主
69
80
  `onAction` 同步抛错或返回 rejected Promise 时,包会把错误、动作和上下文交还给
70
81
  `onActionError`;未提供回调时只记录不含敏感上下文的失败日志,不产生未处理的
package/README.md CHANGED
@@ -18,6 +18,7 @@ export function AppAssistant() {
18
18
  return (
19
19
  <MakeAiAssistant
20
20
  brandName="销售管理"
21
+ theme={{ primary: "#0f8277" }}
21
22
  context={{
22
23
  app: { id: "sales-app", name: "销售管理" },
23
24
  location: { pathname: window.location.pathname },
@@ -50,9 +51,46 @@ AI transport;进度和可重试错误会显示在对应的 AI 回合中。
50
51
  不传入或传入空白内容时不显示图标。标题右侧紧随标题展示“只读”状态标签,长标题会省略显示并保留原文
51
52
  `title` 属性。头栏默认高度为 50px,可通过 `headerHeight` 属性或 `--make-ai-header-height` 主题变量覆盖。
52
53
 
53
- 桌面端抽屉默认宽度为 432px,且该初始宽度是用户拖拽时的最小宽度。鼠标移至抽屉左边缘的 12px 热区时才会显示 2px 纯紫色拖拽提示线(可通过 `--make-ai-drawer-resize-line` 覆盖),可向左拖宽;获得焦点后也可用左、右方向键以 16px 调整宽度。小于 560px 的视口保持全宽展示,不显示拖拽手柄。
54
+ ## Theme integration
54
55
 
55
- 面板使用容器查询而非页面视口响应宽度:抽屉达到 560px 时会增加内边距、正文可读宽度和结构化内容密度;达到 760px 时 Markdown 表格会优先按可用宽度分列并换行。宿主可通过 `--make-ai-panel-gutter-wide` 覆盖扩展抽屉的内边距。
56
+ `MakeAiAssistant`、`AssistantPanel` `ArtifactRenderer` 都支持同一个 `theme` 属性。传入宿主主色后,
57
+ 入口、图标、只读标签、焦点、主操作、进度点、结构化结果、边框、浅色表面、浮层阴影及抽屉拖拽线会从该主色派生,
58
+ 避免与宿主应用主题割裂;成功、告警和错误仍使用独立语义色。
59
+
60
+ ```tsx
61
+ import type { MakeAiTheme } from "@qfei-design/make-ai-assistant/react";
62
+
63
+ const hostTheme: MakeAiTheme = {
64
+ primary: "#0f8277",
65
+ primaryHover: "#09685f",
66
+ onPrimary: "#f7fffc",
67
+ background: "#f5fbf8",
68
+ surface: "#eef8f4",
69
+ surfaceStrong: "#dff2eb",
70
+ text: "#173f38",
71
+ textSecondary: "#3c685f",
72
+ border: "#b8d8cf",
73
+ overlay: "#123f37",
74
+ onOverlay: "#f7fffc",
75
+ };
76
+
77
+ <MakeAiAssistant theme={hostTheme} {...assistantProps} />;
78
+ ```
79
+
80
+ `primary` 为必填项;其余字段可省略并直接由主色派生,因此传入 `theme` 后不会再混入宿主已有的其他颜色变量。
81
+ 若主色偏浅,请传入具有足够对比度的
82
+ `onPrimary`。优先级为 `theme` 属性 > `--make-ai-theme-*` 变量 > 其他 `--make-ai-*` 变量 >
83
+ 宿主 `--make-color-*` 变量 > 包内默认值。
84
+ 不使用 React 属性时,也可在组件外层设置 `--make-ai-theme-primary`、`--make-ai-theme-primary-hover`、
85
+ `--make-ai-theme-on-primary`、`--make-ai-theme-bg`、`--make-ai-theme-surface`、`--make-ai-theme-text` 和
86
+ `--make-ai-theme-surface-strong`、`--make-ai-theme-text-secondary`、`--make-ai-theme-border`、
87
+ `--make-ai-theme-overlay`、`--make-ai-theme-on-overlay`;这些变量只在 AI 包的命名空间内生效。
88
+ 平台内置 Artifact 会把主题变量直接写入原有根节点,不增加布局或 DOM 层级;自定义模板如返回自定义组件或
89
+ Fragment,可从 `renderContext.themeStyle` 取到同一组变量并应用到自身根节点。
90
+
91
+ 桌面端抽屉默认宽度为 432px,且该初始宽度是用户拖拽时的最小宽度。最大宽度默认是 `min(1024px, 72vw)`,宿主可通过 `maxDrawerWidth` 传入像素值覆盖;小于最小宽度的配置会回退至最小宽度。鼠标移至抽屉左边缘的 12px 热区时才会显示 2px 主题色拖拽提示线(可通过 `--make-ai-drawer-resize-line` 覆盖),可向左拖宽;获得焦点后也可用左、右方向键以 16px 调整宽度。小于 560px 的视口保持全宽展示,不显示拖拽手柄。
92
+
93
+ 面板使用容器查询而非页面视口响应宽度:回答区、结构化结果、代码块和 Markdown 表格会随抽屉可用宽度扩展;达到 760px 时,表格优先按可用宽度分列并换行,长段落和列表仍限制在 96ch 内以保障阅读性。窄容器中的 Markdown 表格保留横向滚动保护,并使用细窄、跟随主题色的滚动条。宿主可通过 `--make-ai-panel-gutter-wide` 覆盖扩展抽屉的内边距。
56
94
 
57
95
  成功的 AI 回答会显示仅含图标的复制按钮,鼠标悬浮或键盘聚焦时显示“复制”提示,按钮保留
58
96
  “复制回答”的无障碍名称;复制只处理该回答的文本内容,失败时会在本地 UI 内提示,不会把回答正文写入日志。AI 回答正文会按标题、
@@ -1,6 +1,7 @@
1
- import type { ReactNode } from "react";
1
+ import { type ReactNode } from "react";
2
2
  import { type ArtifactActionErrorHandler, type ArtifactActionHandler, type ArtifactTemplateRegistry, type MakeAiArtifact, type MakeAssistantHostContext } from "../core/index.js";
3
3
  import type { ArtifactTemplateRenderContext } from "./artifact-templates.js";
4
+ import { type MakeAiTheme } from "./theme.js";
4
5
  export interface ArtifactRendererProps {
5
6
  artifact: MakeAiArtifact;
6
7
  context: MakeAssistantHostContext;
@@ -8,5 +9,6 @@ export interface ArtifactRendererProps {
8
9
  onAction?: ArtifactActionHandler;
9
10
  onActionError?: ArtifactActionErrorHandler;
10
11
  fallback?: (artifact: MakeAiArtifact) => ReactNode;
12
+ theme?: MakeAiTheme;
11
13
  }
12
- export declare function ArtifactRenderer({ artifact, context, fallback, onAction, onActionError, registry, }: ArtifactRendererProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null | undefined;
14
+ export declare function ArtifactRenderer({ artifact, context, fallback, onAction, onActionError, registry, theme, }: ArtifactRendererProps): ReactNode;
@@ -1,9 +1,12 @@
1
1
  import type { ReactNode } from "react";
2
2
  import { type ArtifactActionErrorHandler, type ArtifactActionHandler, type ArtifactTemplate, type ArtifactTemplateRegistry, type MakeAssistantHostContext } from "../core/index.js";
3
+ import type { MakeAiTheme, MakeAiThemeStyle } from "./theme.js";
3
4
  export interface ArtifactTemplateRenderContext {
4
5
  context: MakeAssistantHostContext;
5
6
  onAction?: ArtifactActionHandler;
6
7
  onActionError?: ArtifactActionErrorHandler;
8
+ theme?: MakeAiTheme;
9
+ themeStyle?: MakeAiThemeStyle;
7
10
  }
8
11
  export type ReactArtifactTemplate = ArtifactTemplate<ReactNode, ArtifactTemplateRenderContext>;
9
12
  export type ReactArtifactTemplateRegistry = ArtifactTemplateRegistry<ReactNode, ArtifactTemplateRenderContext>;
@@ -3,3 +3,4 @@ export * from "./artifact-renderer.js";
3
3
  export * from "./artifact-templates.js";
4
4
  export * from "./format.js";
5
5
  export * from "./make-ai-assistant.js";
6
+ export type { MakeAiTheme } from "./theme.js";
@@ -1,12 +1,14 @@
1
1
  import { type ReactNode } from "react";
2
2
  import { type ArtifactActionHandler, type ArtifactActionErrorHandler, type AssistantTransport, type MakeAssistantHostContext } from "../core/index.js";
3
3
  import { type ReactArtifactTemplateRegistry } from "./artifact-templates.js";
4
+ import { type MakeAiTheme } from "./theme.js";
4
5
  export interface AssistantPanelProps {
5
6
  context: MakeAssistantHostContext;
6
7
  transport: AssistantTransport;
7
8
  registry?: ReactArtifactTemplateRegistry;
8
9
  brandName?: string;
9
10
  assistantName?: string;
11
+ theme?: MakeAiTheme;
10
12
  privacyNotice?: string;
11
13
  headerHeight?: number | string;
12
14
  userName?: string;
@@ -23,6 +25,11 @@ export declare function AssistantPanel(props: AssistantPanelProps): import("reac
23
25
  export interface MakeAiAssistantProps extends Omit<AssistantPanelProps, "onClose"> {
24
26
  open?: boolean;
25
27
  defaultOpen?: boolean;
28
+ /**
29
+ * Maximum desktop drawer width in pixels. Values below the drawer minimum use
30
+ * the minimum instead. Defaults to `min(1024px, 72vw)`.
31
+ */
32
+ maxDrawerWidth?: number;
26
33
  onOpenChange?: (open: boolean) => void;
27
34
  launcher?: (options: {
28
35
  open: boolean;
@@ -30,4 +37,4 @@ export interface MakeAiAssistantProps extends Omit<AssistantPanelProps, "onClose
30
37
  }) => ReactNode;
31
38
  hideLauncher?: boolean;
32
39
  }
33
- export declare function MakeAiAssistant({ defaultOpen, hideLauncher, launcher, onOpenChange, open: controlledOpen, ...panelProps }: MakeAiAssistantProps): import("react").JSX.Element;
40
+ export declare function MakeAiAssistant({ defaultOpen, hideLauncher, launcher, maxDrawerWidth, onOpenChange, open: controlledOpen, ...panelProps }: MakeAiAssistantProps): import("react").JSX.Element;
@@ -0,0 +1,45 @@
1
+ import type { CSSProperties } from "react";
2
+ /**
3
+ * 宿主传入的 AI 助手主题。未提供的字段会继续使用 CSS 主题变量与默认值。
4
+ */
5
+ export interface MakeAiTheme {
6
+ /** 宿主主色,用于入口、强调、焦点与主要操作。 */
7
+ primary: string;
8
+ /** 主色的悬浮态;未提供时由主色与文字色自动混合。 */
9
+ primaryHover?: string;
10
+ /** 主色背景上的前景色;主色偏浅时应显式传入深色。 */
11
+ onPrimary?: string;
12
+ /** 面板基础背景色。 */
13
+ background?: string;
14
+ /** 卡片、输入框等承载内容的表面色。 */
15
+ surface?: string;
16
+ /** 禁用态、头像底色和轨道等更深一层的表面色。 */
17
+ surfaceStrong?: string;
18
+ /** 主文字色。 */
19
+ text?: string;
20
+ /** 辅助说明、次要标签和坐标文字色。 */
21
+ textSecondary?: string;
22
+ /** 分隔线与边框色。 */
23
+ border?: string;
24
+ /** Tooltip 等高对比浮层背景色。 */
25
+ overlay?: string;
26
+ /** 浮层背景上的前景色。 */
27
+ onOverlay?: string;
28
+ }
29
+ export type MakeAiThemeStyle = CSSProperties & {
30
+ "--make-ai-theme-bg"?: string;
31
+ "--make-ai-theme-border"?: string;
32
+ "--make-ai-theme-on-primary"?: string;
33
+ "--make-ai-theme-primary"?: string;
34
+ "--make-ai-theme-primary-hover"?: string;
35
+ "--make-ai-theme-surface"?: string;
36
+ "--make-ai-theme-surface-strong"?: string;
37
+ "--make-ai-theme-text"?: string;
38
+ "--make-ai-theme-text-secondary"?: string;
39
+ "--make-ai-theme-overlay"?: string;
40
+ "--make-ai-theme-on-overlay"?: string;
41
+ };
42
+ /**
43
+ * 将公开主题输入收敛为局部 CSS 变量,避免修改宿主全局主题。
44
+ */
45
+ export declare const createMakeAiThemeStyle: (theme: MakeAiTheme | undefined) => MakeAiThemeStyle | undefined;
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"),q=require("./index.cjs"),l=require("react"),u=require("./conversation-Cv1wdvCR.cjs");function lt({artifact:t,context:s,fallback:a,onAction:r,onActionError:n,registry:i}){const c=q.resolveArtifactTemplate(i,t,s);if(!c)return a?a(t):e.jsxs("section",{className:"make-ai-artifact make-ai-artifact--unsupported",role:"status",children:[e.jsx("strong",{children:"暂不支持展示此结果"}),e.jsxs("span",{children:["结果类型:",t.kind]})]});const m={context:s,onAction:r,onActionError:n};return c.template.render(t,s,m)}const U=(t,s,a)=>{if(t==null||t==="")return"—";if(typeof t=="boolean")return t?"是":"否";if(typeof t!="number")return`${t}${s?.unit??""}`;const r=s?.precision,n={maximumFractionDigits:r??2,minimumFractionDigits:r};s?.style==="currency"&&s.currency?(n.style="currency",n.currency=s.currency):s?.style==="percent"&&(n.style="percent");try{const i=s?.style==="percent"?t/100:t;return`${new Intl.NumberFormat(a,n).format(i)}${s?.unit??""}`}catch{return`${t}${s?.unit??""}`}},dt=t=>{let s=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(const r of t)s=Math.min(s,r),a=Math.max(a,r);return Number.isFinite(s)&&Number.isFinite(a)?{min:s,max:a}:{min:0,max:0}},ut=(t,s,a)=>{if(!a.onAction)return;const r=i=>{console.error("[make-ai-assistant] host action error handler failed",{actionId:t.id,artifactId:s.artifact.id,errorType:i instanceof Error?i.name:typeof i,intent:t.intent})},n=i=>{if(a.onActionError){try{Promise.resolve(a.onActionError(i,t,s)).catch(r)}catch(c){r(c)}return}console.error("[make-ai-assistant] host action failed",{actionId:t.id,artifactId:s.artifact.id,errorType:i instanceof Error?i.name:typeof i,intent:t.intent})};try{Promise.resolve(a.onAction(t,s)).catch(n)}catch(i){n(i)}},re=(t,s)=>t.actions?.length&&s.onAction?e.jsx("div",{className:"make-ai-artifact__actions",children:t.actions.map(a=>e.jsxs("button",{className:`make-ai-artifact__action make-ai-artifact__action--${a.appearance??"link"}`,type:"button",onClick:()=>ut(a,{artifact:t,context:s.context},s),children:[a.label,e.jsx("span",{"aria-hidden":"true",children:"→"})]},a.id))}):null,ie=(t,s,a="")=>e.jsxs("section",{"aria-label":t.title??`${t.kind} result`,className:`make-ai-artifact ${a}`.trim(),"data-artifact-density":t.presentation?.density,"data-artifact-kind":t.kind,children:[t.title?e.jsx("h4",{className:"make-ai-artifact__title",children:t.title}):null,t.summary?e.jsx("p",{className:"make-ai-artifact__summary",children:t.summary}):null,s]}),Ft=({artifact:t,renderContext:s})=>{const a=t.data.delta,r=a?U(a.value,a.format==="percent"?{style:"percent"}:void 0,s.context.locale):void 0;return ie(t,e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"make-ai-artifact__metric-value",children:U(t.data.value,t.data.format,s.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,t.data.context?e.jsx("p",{className:"make-ai-artifact__context",children:t.data.context}):null,re(t,s)]}),"make-ai-artifact--metric")},Pt=({artifact:t,renderContext:s})=>ie(t,e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"make-ai-artifact__comparison",children:t.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,s.context.locale)}),a.hint?e.jsx("small",{children:a.hint}):null]},a.id))}),re(t,s)]}),"make-ai-artifact--comparison"),Dt=({artifact:t,renderContext:s})=>{const a=t.data.series.flatMap(c=>c.points.map(m=>m.y)),{max:r,min:n}=dt(a),i=r-n||1;return ie(t,e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"make-ai-artifact__trend",children:t.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((m,y)=>{const g=18+(m.y-n)/i*70;return e.jsxs("div",{className:"make-ai-artifact__trend-point",children:[e.jsx("span",{"aria-label":`${m.x}: ${U(m.y,c.format,s.context.locale)}`,className:"make-ai-artifact__trend-bar",role:"img",style:{height:`${g}%`},title:`${m.x}: ${U(m.y,c.format,s.context.locale)}`}),e.jsx("small",{children:m.x})]},`${m.x}-${y}`)})})]},c.id))}),re(t,s)]}),"make-ai-artifact--trend")},Vt=({artifact:t,renderContext:s})=>{const{max:a}=dt(t.data.items.map(n=>Math.abs(n.value))),r=Math.max(a,1);return ie(t,e.jsxs(e.Fragment,{children:[e.jsx("ol",{className:"make-ai-artifact__ranking",children:t.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,s.context.locale)})]},n.id))}),re(t,s)]}),"make-ai-artifact--ranking")},Kt=(t,s)=>s.action??{id:`open-${s.id}`,label:s.title??s.id,intent:"open-record",target:{entityKey:t.data.entity.key,recordId:s.id}},Ht=({artifact:t,renderContext:s})=>ie(t,e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"make-ai-artifact__record-list",children:t.data.records.length===0?e.jsx("p",{className:"make-ai-artifact__empty",children:"没有符合条件的记录"}):t.data.records.map(a=>{const r=Kt(t,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:t.data.columns.map(i=>e.jsxs("span",{children:[e.jsx("small",{children:i.label}),U(a.values[i.key],i.format,s.context.locale)]},i.key))}),s.onAction?e.jsx("span",{"aria-hidden":"true",children:"›"}):null]});return s.onAction?e.jsx("button",{className:"make-ai-artifact__record",type:"button",onClick:()=>ut(r,{artifact:t,context:s.context},s),children:n},a.id):e.jsx("div",{className:"make-ai-artifact__record",children:n},a.id)})}),t.data.total!==void 0?e.jsxs("p",{className:"make-ai-artifact__record-total",children:["共 ",t.data.total," 条"]}):null,re(t,s)]}),"make-ai-artifact--record-list"),Bt=({artifact:t,renderContext:s})=>ie(t,e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`make-ai-artifact__notice make-ai-artifact__notice--${t.data.tone}`,children:[e.jsx("span",{"aria-hidden":"true",children:t.data.tone==="success"?"✓":t.data.tone==="warning"?"!":t.data.tone==="danger"?"×":"i"}),e.jsx("p",{children:t.data.body})]}),re(t,s)]}),"make-ai-artifact--notice"),ne=(t,s,a)=>({id:t,kinds:[s],priority:0,render:a}),Wt=[ne("platform.metric.default","metric",(t,s,a)=>e.jsx(Ft,{artifact:t,renderContext:a})),ne("platform.comparison.default","comparison",(t,s,a)=>e.jsx(Pt,{artifact:t,renderContext:a})),ne("platform.trend.default","trend",(t,s,a)=>e.jsx(Dt,{artifact:t,renderContext:a})),ne("platform.ranking.default","ranking",(t,s,a)=>e.jsx(Vt,{artifact:t,renderContext:a})),ne("platform.record-list.default","record-list",(t,s,a)=>e.jsx(Ht,{artifact:t,renderContext:a})),ne("platform.notice.default","notice",(t,s,a)=>e.jsx(Bt,{artifact:t,renderContext:a}))],mt=q.createArtifactTemplateRegistry(Wt).templates,pt=(t=mt)=>q.createArtifactTemplateRegistry(t),zt=t=>`${t}-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,Ut="Make",qt=["总结当前页面数据","找出需要关注的记录","列出我有权限查看的数据对象"],ht=(t,s)=>s??`${t?.trim()||Ut} AI 助手`,Xt=t=>t??qt,Yt=/^只读分析\s*[·•]\s*/u,Gt=(t,s)=>t?.trim().replace(Yt,"").trim()||`当前对象:${s??"未命名应用"}`,Zt=432,at=16,D=16,he=8,nt=(t,s,a)=>Math.min(Math.max(t,Math.min(s,a)),a),rt=(t,s,a)=>Math.min(Math.max(t,s),Math.max(s,a)),Qt=(t,s,a,r)=>{const n=Math.min(Math.max(s.width,1),Math.max(1,r-D*2)),i=Math.min(Math.max(s.height,1),Math.max(1,a-D*2)),c=t.left+t.width/2,m=t.top+t.height/2,g=[{left:t.right+he,placement:"right",top:m-i/2},{left:t.left-he-n,placement:"left",top:m-i/2},{left:c-n/2,placement:"bottom",top:t.bottom+he},{left:c-n/2,placement:"top",top:t.top-he-i}].find(({left:E,top:w})=>E>=D&&w>=D&&E+n<=r-D&&w+i<=a-D);return g||{left:rt(c-n/2,D,r-D-n),placement:"bottom",top:rt(t.bottom+he,D,a-D-i)}},Jt=t=>typeof t=="number"?Number.isFinite(t)?`${t}px`:void 0:t?.trim()||void 0;class A extends Error{}const ye=(t,s)=>{if(!(typeof t!="object"||t===null))return t[s]},es=t=>{const s=ye(t,"status");return typeof s=="number"?s:ye(ye(t,"response"),"status")},ts=t=>{const s=ye(t,"code"),a=es(t),r=t instanceof Error?t.message:"",n=[s,r].filter(y=>typeof y=="string").join(" ").toLowerCase(),c=globalThis.navigator?.onLine===!1||/network|fetch|timeout|offline|connection|网络|连接|超时/.test(n),m=typeof a=="number"&&a>=500||/server|service|服务器|服务异常/.test(n);return c?{actionLabel:"重新连接",description:"请检查网络后再试。",kind:"network",label:"网络连接",title:"网络连接不可用"}:m?{actionLabel:"重新加载",description:"服务暂时未能响应,请稍后重试。",kind:"service",label:"服务异常",title:"服务暂时不可用"}:{actionLabel:"重新加载",description:"请稍后重试;若问题持续出现,请联系管理员。",kind:"unknown",label:"加载异常",title:"暂时无法加载对话"}},it=t=>{try{const s=t?.return?.();if(!s)return;Promise.resolve(s).catch(a=>{console.error("[make-ai-assistant] transport iterator close failed",{errorType:a instanceof Error?a.name:typeof a})})}catch(s){console.error("[make-ai-assistant] transport iterator close failed",{errorType:s instanceof Error?s.name:typeof s})}},ss=async t=>{if(globalThis.navigator?.clipboard?.writeText){await globalThis.navigator.clipboard.writeText(t);return}if(typeof document>"u"||!document.body)throw new Error("Clipboard API is unavailable");const s=document.createElement("textarea");s.value=t,s.setAttribute("readonly",""),s.style.position="fixed",s.style.inset="0 auto auto 0",s.style.opacity="0",document.body.append(s),s.select();const a=document.execCommand("copy");if(s.remove(),!a)throw new Error("Clipboard copy failed")},ft=()=>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"})]}),as=()=>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"})]}),rs=()=>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"})]}),is=()=>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"})]}),os=()=>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"})]}),cs=()=>e.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),ls=()=>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"})]}),gt=()=>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"})]}),ds=()=>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"})]}),ke=({className:t=""})=>e.jsx("span",{className:`make-ai-assistant__avatar ${t}`.trim(),"aria-hidden":"true",children:e.jsx(ft,{})}),us=({src:t})=>t?e.jsx("span",{className:"make-ai-assistant__user-avatar","aria-hidden":"true",children:e.jsx("img",{alt:"",src:t})}):null,ms=({userAvatarUrl:t,userName:s})=>{const a=s?.trim();return!a&&!t?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(us,{src:t})]})},Ne=t=>{const s=t.trim();if(!(!s.startsWith("|")||!s.endsWith("|")))return s.slice(1,-1).split("|").map(a=>a.trim())},ps=t=>t.length>0&&t.every(s=>/^:?-{3,}:?$/.test(s)),hs=(t,s)=>{const a=Ne(t[s]??""),r=Ne(t[s+1]??"");if(!a||!r||a.length!==r.length||!ps(r))return;const n=[];let i=s+2;for(;i<t.length;){const c=Ne(t[i]??"");if(!c||c.length!==a.length)break;n.push(c),i+=1}return{headers:a,lastIndex:i-1,rows:n}},fs=t=>{const s=[],a=[],r=[],n=[],i=t.replace(/\r\n?/g,`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),l=require("react"),Y=require("./index.cjs"),m=require("./conversation-Cv1wdvCR.cjs"),ft=e=>e?.trim()||void 0,F=(e,s)=>ft(e)??s,Le=e=>{const s=ft(e?.primary);if(s)return{"--make-ai-theme-primary":s,"--make-ai-theme-primary-hover":F(e?.primaryHover,"color-mix(in srgb, var(--make-ai-theme-primary) 84%, var(--make-ai-theme-text))"),"--make-ai-theme-on-primary":F(e?.onPrimary,"#fcfcff"),"--make-ai-theme-bg":F(e?.background,"color-mix(in srgb, var(--make-ai-theme-primary) 2%, #fcfcff)"),"--make-ai-theme-surface":F(e?.surface,"color-mix(in srgb, var(--make-ai-theme-primary) 4%, var(--make-ai-theme-bg))"),"--make-ai-theme-surface-strong":F(e?.surfaceStrong,"color-mix(in srgb, var(--make-ai-theme-primary) 8%, var(--make-ai-theme-bg))"),"--make-ai-theme-text":F(e?.text,"color-mix(in srgb, var(--make-ai-theme-primary) 12%, #252631)"),"--make-ai-theme-text-secondary":F(e?.textSecondary,"color-mix(in srgb, var(--make-ai-theme-text) 74%, var(--make-ai-theme-primary))"),"--make-ai-theme-border":F(e?.border,"color-mix(in srgb, var(--make-ai-theme-primary) 14%, var(--make-ai-theme-bg))"),"--make-ai-theme-overlay":F(e?.overlay,"color-mix(in srgb, var(--make-ai-theme-text) 88%, var(--make-ai-theme-primary))"),"--make-ai-theme-on-overlay":F(e?.onOverlay,"#fcfcff")}},lt=(e,s)=>!s||!l.isValidElement(e)||typeof e.type!="string"?e:l.cloneElement(e,{style:{...e.props.style,...s}});function gt({artifact:e,context:s,fallback:a,onAction:r,onActionError:n,registry:i,theme:c}){const u=Le(c),v=Y.resolveArtifactTemplate(i,e,s);if(!v){const T=a?a(e):t.jsxs("section",{className:"make-ai-artifact make-ai-artifact--unsupported",role:"status",children:[t.jsx("strong",{children:"暂不支持展示此结果"}),t.jsxs("span",{children:["结果类型:",e.kind]})]});return lt(T,u)}const g={context:s,onAction:r,onActionError:n,theme:c,themeStyle:u},w=v.template.render(e,s,g);return lt(w,u)}const X=(e,s,a)=>{if(e==null||e==="")return"—";if(typeof e=="boolean")return e?"是":"否";if(typeof e!="number")return`${e}${s?.unit??""}`;const r=s?.precision,n={maximumFractionDigits:r??2,minimumFractionDigits:r};s?.style==="currency"&&s.currency?(n.style="currency",n.currency=s.currency):s?.style==="percent"&&(n.style="percent");try{const i=s?.style==="percent"?e/100:e;return`${new Intl.NumberFormat(a,n).format(i)}${s?.unit??""}`}catch{return`${e}${s?.unit??""}`}},xt=e=>{let s=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(const r of e)s=Math.min(s,r),a=Math.max(a,r);return Number.isFinite(s)&&Number.isFinite(a)?{min:s,max:a}:{min:0,max:0}},_t=(e,s,a)=>{if(!a.onAction)return;const r=i=>{console.error("[make-ai-assistant] host action error handler failed",{actionId:e.id,artifactId:s.artifact.id,errorType:i instanceof Error?i.name:typeof i,intent:e.intent})},n=i=>{if(a.onActionError){try{Promise.resolve(a.onActionError(i,e,s)).catch(r)}catch(c){r(c)}return}console.error("[make-ai-assistant] host action failed",{actionId:e.id,artifactId:s.artifact.id,errorType:i instanceof Error?i.name:typeof i,intent:e.intent})};try{Promise.resolve(a.onAction(e,s)).catch(n)}catch(i){n(i)}},ce=(e,s)=>e.actions?.length&&s.onAction?t.jsx("div",{className:"make-ai-artifact__actions",children:e.actions.map(a=>t.jsxs("button",{className:`make-ai-artifact__action make-ai-artifact__action--${a.appearance??"link"}`,type:"button",onClick:()=>_t(a,{artifact:e,context:s.context},s),children:[a.label,t.jsx("span",{"aria-hidden":"true",children:"→"})]},a.id))}):null,le=(e,s,a="",r)=>t.jsxs("section",{"aria-label":e.title??`${e.kind} result`,className:`make-ai-artifact ${a}`.trim(),"data-artifact-density":e.presentation?.density,"data-artifact-kind":e.kind,style:r,children:[e.title?t.jsx("h4",{className:"make-ai-artifact__title",children:e.title}):null,e.summary?t.jsx("p",{className:"make-ai-artifact__summary",children:e.summary}):null,s]}),Bt=({artifact:e,renderContext:s})=>{const a=e.data.delta,r=a?X(a.value,a.format==="percent"?{style:"percent"}:void 0,s.context.locale):void 0;return le(e,t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"make-ai-artifact__metric-value",children:X(e.data.value,e.data.format,s.context.locale)}),a?t.jsxs("div",{className:`make-ai-artifact__delta make-ai-artifact__delta--${a.direction??"flat"}`,children:[t.jsx("span",{"aria-hidden":"true",children:a.direction==="up"?"↗":a.direction==="down"?"↘":"→"}),t.jsx("span",{children:r}),a.label?t.jsx("span",{children:a.label}):null]}):null,e.data.context?t.jsx("p",{className:"make-ai-artifact__context",children:e.data.context}):null,ce(e,s)]}),"make-ai-artifact--metric",s.themeStyle)},Ut=({artifact:e,renderContext:s})=>le(e,t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"make-ai-artifact__comparison",children:e.data.items.map(a=>t.jsxs("div",{className:"make-ai-artifact__comparison-item",children:[t.jsx("span",{children:a.label}),t.jsx("strong",{children:X(a.value,a.format,s.context.locale)}),a.hint?t.jsx("small",{children:a.hint}):null]},a.id))}),ce(e,s)]}),"make-ai-artifact--comparison",s.themeStyle),zt=({artifact:e,renderContext:s})=>{const a=e.data.series.flatMap(c=>c.points.map(u=>u.y)),{max:r,min:n}=xt(a),i=r-n||1;return le(e,t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"make-ai-artifact__trend",children:e.data.series.map(c=>t.jsxs("div",{className:"make-ai-artifact__trend-series",children:[t.jsx("div",{className:"make-ai-artifact__trend-label",children:c.label}),t.jsx("div",{className:"make-ai-artifact__trend-bars",children:c.points.map((u,v)=>{const g=18+(u.y-n)/i*70;return t.jsxs("div",{className:"make-ai-artifact__trend-point",children:[t.jsx("span",{"aria-label":`${u.x}: ${X(u.y,c.format,s.context.locale)}`,className:"make-ai-artifact__trend-bar",role:"img",style:{height:`${g}%`},title:`${u.x}: ${X(u.y,c.format,s.context.locale)}`}),t.jsx("small",{children:u.x})]},`${u.x}-${v}`)})})]},c.id))}),ce(e,s)]}),"make-ai-artifact--trend",s.themeStyle)},qt=({artifact:e,renderContext:s})=>{const{max:a}=xt(e.data.items.map(n=>Math.abs(n.value))),r=Math.max(a,1);return le(e,t.jsxs(t.Fragment,{children:[t.jsx("ol",{className:"make-ai-artifact__ranking",children:e.data.items.map((n,i)=>t.jsxs("li",{children:[t.jsx("span",{className:"make-ai-artifact__rank",children:i+1}),t.jsxs("span",{className:"make-ai-artifact__ranking-label",children:[t.jsx("span",{children:n.label}),n.description?t.jsx("small",{children:n.description}):null]}),t.jsx("span",{className:"make-ai-artifact__ranking-track","aria-hidden":"true",children:t.jsx("span",{style:{width:`${Math.abs(n.value)/r*100}%`}})}),t.jsx("strong",{children:X(n.value,n.format,s.context.locale)})]},n.id))}),ce(e,s)]}),"make-ai-artifact--ranking",s.themeStyle)},Xt=(e,s)=>s.action??{id:`open-${s.id}`,label:s.title??s.id,intent:"open-record",target:{entityKey:e.data.entity.key,recordId:s.id}},Yt=({artifact:e,renderContext:s})=>le(e,t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"make-ai-artifact__record-list",children:e.data.records.length===0?t.jsx("p",{className:"make-ai-artifact__empty",children:"没有符合条件的记录"}):e.data.records.map(a=>{const r=Xt(e,a),n=t.jsxs(t.Fragment,{children:[t.jsx("strong",{children:a.title??a.id}),t.jsx("span",{className:"make-ai-artifact__record-values",children:e.data.columns.map(i=>t.jsxs("span",{children:[t.jsx("small",{children:i.label}),X(a.values[i.key],i.format,s.context.locale)]},i.key))}),s.onAction?t.jsx("span",{"aria-hidden":"true",children:"›"}):null]});return s.onAction?t.jsx("button",{className:"make-ai-artifact__record",type:"button",onClick:()=>_t(r,{artifact:e,context:s.context},s),children:n},a.id):t.jsx("div",{className:"make-ai-artifact__record",children:n},a.id)})}),e.data.total!==void 0?t.jsxs("p",{className:"make-ai-artifact__record-total",children:["共 ",e.data.total," 条"]}):null,ce(e,s)]}),"make-ai-artifact--record-list",s.themeStyle),Gt=({artifact:e,renderContext:s})=>le(e,t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:`make-ai-artifact__notice make-ai-artifact__notice--${e.data.tone}`,children:[t.jsx("span",{"aria-hidden":"true",children:e.data.tone==="success"?"✓":e.data.tone==="warning"?"!":e.data.tone==="danger"?"×":"i"}),t.jsx("p",{children:e.data.body})]}),ce(e,s)]}),"make-ai-artifact--notice",s.themeStyle),oe=(e,s,a)=>({id:e,kinds:[s],priority:0,render:a}),Zt=[oe("platform.metric.default","metric",(e,s,a)=>t.jsx(Bt,{artifact:e,renderContext:a})),oe("platform.comparison.default","comparison",(e,s,a)=>t.jsx(Ut,{artifact:e,renderContext:a})),oe("platform.trend.default","trend",(e,s,a)=>t.jsx(zt,{artifact:e,renderContext:a})),oe("platform.ranking.default","ranking",(e,s,a)=>t.jsx(qt,{artifact:e,renderContext:a})),oe("platform.record-list.default","record-list",(e,s,a)=>t.jsx(Yt,{artifact:e,renderContext:a})),oe("platform.notice.default","notice",(e,s,a)=>t.jsx(Gt,{artifact:e,renderContext:a}))],vt=Y.createArtifactTemplateRegistry(Zt).templates,jt=(e=vt)=>Y.createArtifactTemplateRegistry(e),Qt=e=>`${e}-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,Jt="Make",es=["总结当前页面数据","找出需要关注的记录","列出我有权限查看的数据对象"],yt=(e,s)=>s??`${e?.trim()||Jt} AI 助手`,ts=e=>e??es,ss=/^只读分析\s*[·•]\s*/u,as=(e,s)=>e?.trim().replace(ss,"").trim()||`当前对象:${s??"未命名应用"}`,ns=432,At=1024,rs=.72,dt=16,D=16,xe=8,Re=(e,s,a)=>Math.min(Math.max(e,Math.min(s,a)),a),is=e=>typeof e=="number"&&Number.isFinite(e)&&e>0?e:void 0,os=(e,s,a)=>{const r=Math.min(At,a*rs);return Math.max(e,Math.min(s??r,a))},mt=(e,s,a)=>Math.min(Math.max(e,s),Math.max(s,a)),cs=(e,s,a,r)=>{const n=Math.min(Math.max(s.width,1),Math.max(1,r-D*2)),i=Math.min(Math.max(s.height,1),Math.max(1,a-D*2)),c=e.left+e.width/2,u=e.top+e.height/2,g=[{left:e.right+xe,placement:"right",top:u-i/2},{left:e.left-xe-n,placement:"left",top:u-i/2},{left:c-n/2,placement:"bottom",top:e.bottom+xe},{left:c-n/2,placement:"top",top:e.top-xe-i}].find(({left:w,top:T})=>w>=D&&T>=D&&w+n<=r-D&&T+i<=a-D);return g||{left:mt(c-n/2,D,r-D-n),placement:"bottom",top:mt(e.bottom+xe,D,a-D-i)}},ls=e=>typeof e=="number"?Number.isFinite(e)?`${e}px`:void 0:e?.trim()||void 0;class k extends Error{}const Me=(e,s)=>{if(!(typeof e!="object"||e===null))return e[s]},ds=e=>{const s=Me(e,"status");return typeof s=="number"?s:Me(Me(e,"response"),"status")},ms=e=>{const s=Me(e,"code"),a=ds(e),r=e instanceof Error?e.message:"",n=[s,r].filter(v=>typeof v=="string").join(" ").toLowerCase(),c=globalThis.navigator?.onLine===!1||/network|fetch|timeout|offline|connection|网络|连接|超时/.test(n),u=typeof a=="number"&&a>=500||/server|service|服务器|服务异常/.test(n);return c?{actionLabel:"重新连接",description:"请检查网络后再试。",kind:"network",label:"网络连接",title:"网络连接不可用"}:u?{actionLabel:"重新加载",description:"服务暂时未能响应,请稍后重试。",kind:"service",label:"服务异常",title:"服务暂时不可用"}:{actionLabel:"重新加载",description:"请稍后重试;若问题持续出现,请联系管理员。",kind:"unknown",label:"加载异常",title:"暂时无法加载对话"}},ut=e=>{try{const s=e?.return?.();if(!s)return;Promise.resolve(s).catch(a=>{console.error("[make-ai-assistant] transport iterator close failed",{errorType:a instanceof Error?a.name:typeof a})})}catch(s){console.error("[make-ai-assistant] transport iterator close failed",{errorType:s instanceof Error?s.name:typeof s})}},us=async e=>{if(globalThis.navigator?.clipboard?.writeText){await globalThis.navigator.clipboard.writeText(e);return}if(typeof document>"u"||!document.body)throw new Error("Clipboard API is unavailable");const s=document.createElement("textarea");s.value=e,s.setAttribute("readonly",""),s.style.position="fixed",s.style.inset="0 auto auto 0",s.style.opacity="0",document.body.append(s),s.select();const a=document.execCommand("copy");if(s.remove(),!a)throw new Error("Clipboard copy failed")},kt=()=>t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[t.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"}),t.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"})]}),ps=()=>t.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:t.jsx("path",{d:"m6 6 12 12M18 6 6 18"})}),hs=()=>t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[t.jsx("path",{d:"M8 8h10v12H8z"}),t.jsx("path",{d:"M6 16H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),fs=()=>t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[t.jsx("path",{d:"M20 11a8 8 0 0 0-14.7-4.4L4 8"}),t.jsx("path",{d:"M4 4v4h4"}),t.jsx("path",{d:"M4 13a8 8 0 0 0 14.7 4.4L20 16"}),t.jsx("path",{d:"M20 20v-4h-4"})]}),gs=()=>t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[t.jsx("circle",{cx:"12",cy:"12",r:"8"}),t.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"}),t.jsx("path",{d:"M12 17h.01"})]}),xs=()=>t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[t.jsx("path",{d:"M12 4v11"}),t.jsx("path",{d:"m7 10 5 5 5-5"}),t.jsx("path",{d:"M5 20h14"})]}),_s=()=>t.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:t.jsx("path",{d:"M12 5v14M5 12h14"})}),vs=()=>t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[t.jsx("path",{d:"m4 4 17 8-17 8 3-8-3-8Z"}),t.jsx("path",{d:"M7 12h14"})]}),It=()=>t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[t.jsx("path",{d:"M20 11a8 8 0 0 0-14.7-4.4L4 8"}),t.jsx("path",{d:"M4 4v4h4"}),t.jsx("path",{d:"M4 13a8 8 0 0 0 14.7 4.4L20 16"}),t.jsx("path",{d:"M20 20v-4h-4"})]}),js=()=>t.jsxs("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:[t.jsx("circle",{cx:"12",cy:"12",r:"8"}),t.jsx("path",{d:"M12 8v4.5"}),t.jsx("path",{d:"M12 16h.01"})]}),Ne=({className:e=""})=>t.jsx("span",{className:`make-ai-assistant__avatar ${e}`.trim(),"aria-hidden":"true",children:t.jsx(kt,{})}),ys=({src:e})=>e?t.jsx("span",{className:"make-ai-assistant__user-avatar","aria-hidden":"true",children:t.jsx("img",{alt:"",src:e})}):null,As=({userAvatarUrl:e,userName:s})=>{const a=s?.trim();return!a&&!e?null:t.jsxs("div",{className:"make-ai-assistant__message-identity",children:[a?t.jsx("span",{className:"make-ai-assistant__message-sender",children:a}):null,t.jsx(ys,{src:e})]})},Ce=e=>{const s=e.trim();if(!(!s.startsWith("|")||!s.endsWith("|")))return s.slice(1,-1).split("|").map(a=>a.trim())},ks=e=>e.length>0&&e.every(s=>/^:?-{3,}:?$/.test(s)),Is=(e,s)=>{const a=Ce(e[s]??""),r=Ce(e[s+1]??"");if(!a||!r||a.length!==r.length||!ks(r))return;const n=[];let i=s+2;for(;i<e.length;){const c=Ce(e[i]??"");if(!c||c.length!==a.length)break;n.push(c),i+=1}return{headers:a,lastIndex:i-1,rows:n}},bs=e=>{const s=[],a=[],r=[],n=[],i=e.replace(/\r\n?/g,`
2
2
  `).split(`
3
3
  `),c=()=>{const g=a.join(`
4
- `).trim();a.length=0,g&&s.push({type:"paragraph",text:g})},m=()=>{r.length&&s.push({type:"list",items:r.splice(0)})},y=()=>{const g=n.join(`
5
- `).trim();n.length=0,g&&s.push({type:"pre",text:g})};for(let g=0;g<i.length;g+=1){const E=i[g]??"",w=E.trim();if(!w){c(),m(),y();continue}const C=hs(i,g);if(C){c(),m(),y(),s.push({headers:C.headers,rows:C.rows,type:"table"}),g=C.lastIndex;continue}const v=/^(#{1,6})\s+(.+)$/.exec(w);if(v){c(),m(),y();const O=(v[2]??"").replace(/\s+#+\s*$/,"").trim();O&&s.push({type:"heading",level:v[1]?.length,text:O});continue}if(/^\s*\|.+\|\s*$/.test(E)){c(),m(),n.push(E.trim());continue}const T=/^\s*[-*]\s+(.+)$/.exec(E);if(T){c(),y(),r.push(T[1]?.trim()??"");continue}m(),y(),a.push(w)}return c(),m(),y(),s},fe=t=>{const s=[],a=/(\*\*[^*]+\*\*|`[^`]+`)/g;let r=0;for(const n of t.matchAll(a)){const i=n[0],c=n.index??0;c>r&&s.push(t.slice(r,c)),i.startsWith("**")?s.push(e.jsx("strong",{children:i.slice(2,-2)},`${c}-strong`)):s.push(e.jsx("code",{children:i.slice(1,-1)},`${c}-code`)),r=c+i.length}return r<t.length&&s.push(t.slice(r)),s},gs=({content:t})=>{const s=fs(t);return s.length?e.jsx("div",{className:"make-ai-assistant__bubble make-ai-assistant__assistant-text",children:s.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:fe(a.text)},`${r}-heading`)}return a.type==="paragraph"?e.jsx("p",{children:fe(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:fe(n)},`${i}-${n}`))})}),e.jsx("tbody",{children:a.rows.map((n,i)=>e.jsx("tr",{children:n.map((c,m)=>e.jsx("td",{children:fe(c)},`${m}-${c}`))},`${i}-${n.join("|")}`))})]})},`${r}-table`):e.jsx("ul",{children:a.items.map((n,i)=>e.jsx("li",{children:fe(n)},`${i}-${n}`))},`${r}-list`)})}):null},xt=({assistantName:t})=>e.jsxs("div",{className:"make-ai-assistant__message-identity",children:[e.jsx(ke,{className:"make-ai-assistant__avatar--message"}),e.jsx("span",{className:"make-ai-assistant__message-sender",children:t})]}),_t=t=>{for(let s=t.messages.length-1;s>=0;s-=1){const a=t.messages[s];if(a.role==="assistant"&&a.status==="streaming")return a.id}},xs=t=>{for(let s=t.messages.length-1;s>=0;s-=1)if(t.messages[s].role==="user")return s;return-1},vt=t=>{const s=xs(t);if(!(s<0))for(let a=t.messages.length-1;a>s;a-=1){const r=t.messages[a];if(r.role==="assistant")return r.id}},_s=t=>{if(t.status==="idle")for(let s=t.messages.length-1;s>=0;s-=1){const a=t.messages[s];if(a.role==="assistant"&&a.status==="complete")return a.id}},vs=t=>{for(let s=t.messages.length-1;s>=0;s-=1){const a=t.messages[s];if(a.role==="user")return a}},js=(t,s)=>{const a=t.messages.findIndex(r=>r.id===s&&r.role==="user");return{...t,error:void 0,progress:void 0,status:"streaming",messages:a<0?t.messages:t.messages.slice(0,a+1)}},As=t=>t.scrollHeight-t.scrollTop-t.clientHeight<=48,ot=(t="smooth")=>globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches?"auto":t,Me=(t,s)=>{typeof t.scrollTo=="function"?t.scrollTo({top:t.scrollHeight,behavior:s}):t.scrollTop=t.scrollHeight},jt=({error:t,onRetry:s})=>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(ds,{})}),e.jsx("strong",{children:"请求未完成"})]}),e.jsx("span",{className:"make-ai-assistant__message-status-message",children:t.message}),t.retryable&&s?e.jsxs("button",{className:"make-ai-assistant__retry",type:"button",onClick:s,children:[e.jsx(gt,{}),"重新发送"]}):null]}),Is=({error:t,onRetry:s})=>{const a=ts(t);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:s,children:[e.jsx(gt,{}),a.actionLabel]})]})},At=({active:t,steps:s})=>{if(!t||!s?.length)return null;const a=s[s.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:[s.length," 步"]})]}),e.jsx("ol",{children:s.map((r,n)=>e.jsxs("li",{"data-step-active":n===s.length-1?!0:void 0,children:[e.jsx("span",{"aria-hidden":"true"}),e.jsx("span",{children:r})]},`${n}-${r}`))})]})},ys=({copyFeedback:t,onCopy:s,onRegenerate:a})=>!s&&!a?null:e.jsxs("div",{className:"make-ai-assistant__reply-actions","aria-label":"回复操作",children:[s?e.jsx("button",{"aria-label":"复制回答",className:"make-ai-assistant__reply-action make-ai-assistant__reply-copy","data-tooltip":"复制",type:"button",onClick:s,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(rs,{})}):null,t?e.jsx("span",{className:"make-ai-assistant__reply-feedback","data-copy-status":t.status,role:"status",children:t.message}):null]}),ct=({assistantName:t,error:s,onRetry:a,progress:r})=>{const n=s?"error":"progress";return s?.message??r?.message?e.jsx("article",{"aria-label":`${t}的${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(xt,{assistantName:t}),e.jsx("div",{className:"make-ai-assistant__message-stack",children:s?e.jsx(jt,{error:s,onRetry:a}):e.jsx(At,{active:!0,steps:r?.steps})})]})}):null},ks=(t,s,a,r,n,i,c,m,y,g,E,w,C)=>{const v=vt(t),T=_t(t),O=_s(t);let S;return t.messages.map(p=>{const I=p.role==="assistant",K=S;I||(S=p);const b=p.id===T,Z=p.id===v?t.error:void 0,$=p.error??Z,F=!I&&!!(m?.trim()||y),_=I?i:m?.trim()||"用户",R=I&&p.status==="complete"&&!$&&(p.content.trim()||p.id===O);return e.jsx("article",{"aria-label":`${_}的消息`,className:`make-ai-assistant__message make-ai-assistant__message--${p.role}`,"data-message-role":p.role,"data-message-state":$?"error":void 0,"data-message-status":p.status,"data-message-has-identity":I||F?!0:void 0,children:e.jsxs("div",{className:"make-ai-assistant__message-turn",children:[I?e.jsx(xt,{assistantName:i}):F?e.jsx(ms,{userAvatarUrl:y,userName:m}):null,e.jsxs("div",{className:"make-ai-assistant__message-stack",children:[p.content?I?e.jsx(gs,{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,I?e.jsx(At,{active:b&&t.status==="streaming",steps:p.progressSteps}):null,$?e.jsx(jt,{error:$,onRetry:Z?c:void 0}):null,p.artifacts.map(P=>e.jsx(lt,{artifact:P,context:s,onAction:r,onActionError:n,registry:a},P.id)),R?e.jsx(ys,{copyFeedback:g?.messageId===p.id?{message:g.message,status:g.status}:void 0,onCopy:p.content.trim()?()=>w(p.id,p.content):void 0,onRegenerate:E&&p.id===O&&K?()=>C({userMessage:K,assistantMessage:p}):void 0}):null]})]})},p.id)})};function It({assistantName:t="AI 助手",brandName:s,context:a,onAction:r,onActionError:n,onClose:i,onNewConversation:c,headerHeight:m,privacyNotice:y,registry:g,subtitle:E,suggestions:w,title:C,transport:v,userAvatarUrl:T,userName:O,visible:S}){const p=ht(s,C),I=y?.trim(),K=Gt(E,a.app.name),b=Jt(m),Z=b?{"--make-ai-internal-header-height":b}:void 0,[$,F]=l.useState(""),[_,R]=l.useState(u.createAssistantConversationState),P=l.useRef(_);P.current=_;const[X,Y]=l.useState(void 0),[oe,H]=l.useState(void 0),[h,k]=l.useState(0),[N,G]=l.useState(()=>v.loadConversation?"loading":"ready"),[yt,be]=l.useState(void 0),[kt,B]=l.useState(!1),[Q,Ee]=l.useState(!1),[ce,Se]=l.useState(void 0),J=l.useRef(void 0),ee=l.useRef(void 0),te=l.useRef(0),Re=l.useRef(null),le=l.useRef(null),Ce=l.useRef(null),$e=l.useRef(null),Le=l.useRef(null),Oe=l.useRef(null),W=l.useRef(!0),Fe=l.useRef(a.app.id),Pe=l.useRef(S),De=l.useId(),Ve=l.useMemo(()=>g??pt(),[g]),Ke=l.useMemo(()=>Xt(w),[w]),He=()=>{const o=$e.current,x=Le.current;if(!o||!x||typeof window>"u")return;const f=Qt(o.getBoundingClientRect(),x.getBoundingClientRect(),window.innerHeight,window.innerWidth);Se(j=>j?.left===f.left&&j.top===f.top&&j.placement===f.placement?j:f)},Be=()=>Ee(!0),We=()=>Ee(!1),bt=ce?{left:`${ce.left}px`,top:`${ce.top}px`}:void 0;l.useLayoutEffect(()=>{if(!Q||!I){Se(void 0);return}He()},[Q,I]),l.useEffect(()=>{if(!Q||!I)return;const o=()=>He();return window.addEventListener("resize",o),window.addEventListener("scroll",o,!0),()=>{window.removeEventListener("resize",o),window.removeEventListener("scroll",o,!0)}},[Q,I]);const ge=o=>{const x=J.current,f=ee.current?.iterator;return!x&&!f?!1:(te.current+=1,J.current=void 0,ee.current=void 0,console.info("[make-ai-assistant] local run cancellation requested",{reason:o}),x?.abort(),it(f),!0)};l.useEffect(()=>()=>{ge("unmount")},[]),l.useEffect(()=>{const o=v.loadConversation,x=Fe.current!==a.app.id;if(Fe.current=a.app.id,ge("reinitialize"),x&&(F(""),W.current=!0),Y(void 0),H(void 0),B(!1),R(u.createAssistantConversationState()),!o){be(void 0),G("ready");return}const f=new AbortController;return be(void 0),G("loading"),console.info("[make-ai-assistant] conversation load start",{appId:a.app.id}),o.call(v,a,{signal:f.signal}).then(j=>{f.signal.aborted||(R(u.createAssistantConversationState(j)),G("ready"),console.info("[make-ai-assistant] conversation load success",{appId:a.app.id,messageCount:j.messages.length}))}).catch(j=>{f.signal.aborted||(console.error("[make-ai-assistant] conversation load failed",{appId:a.app.id,errorType:j instanceof Error?j.name:typeof j}),be(j),G("error"))}),()=>f.abort()},[a.app.id,h,v]),l.useEffect(()=>{const o=le.current;if(!o||!W.current)return;B(!1);const x=requestAnimationFrame(()=>{if(!W.current)return;const f=_.status==="streaming"||globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches?"auto":"smooth";Me(o,f)});return()=>cancelAnimationFrame(x)},[_.messages,_.progress,_.status]),l.useEffect(()=>{const o=S&&!Pe.current;if(Pe.current=S,!o)return;const x=requestAnimationFrame(()=>{const f=le.current;if(f&&W.current){B(!1);const de=P.current.status==="streaming"?"auto":ot();Me(f,de)}else f&&B(P.current.messages.length>0);const j=Ce.current;(j&&!j.disabled?j:Oe.current??Re.current?.querySelector("button:not(:disabled)"))?.focus()});return()=>cancelAnimationFrame(x)},[S]);const wt=()=>{const o=le.current;if(!o)return;const x=As(o);W.current=x,B(!x&&P.current.messages.length>0)},Tt=()=>{const o=le.current;if(!o)return;W.current=!0,B(!1);const x=ot();Me(o,x)},ze=async(o,x)=>{const f=o.trim(),j=P.current,V=x?.regenerateFrom,de=v.regenerate;if(!f||N!=="ready"||j.status==="streaming"||J.current||V&&!de)return;if(u.countCodePointsUpTo(f,u.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)>u.MAKE_AI_CONVERSATION_LIMITS.messageCharacters){Y(`输入内容过长,请控制在 ${u.MAKE_AI_CONVERSATION_LIMITS.messageCharacters} 个字符以内`);return}const ve={id:V?.userMessage.id??zt("user"),content:f},je=V?js(j,V.userMessage.id):u.appendUserMessage(j,ve),Ae=new AbortController,se=te.current+1;te.current=se,J.current=Ae,Y(void 0),H(void 0),B(!W.current&&j.messages.length>0),V||F(""),R(je);try{let z=!1,M,Xe=0,Ye=0,Ge=0,we=0,ue=0;const me=new Map,Ze=new Set,Qe=new Set([...je.messages.map(Ie=>Ie.id),ve.id]),pe=new Set,Je=q.createArtifactCapabilities(Ve),et={signal:Ae.signal};let Te;if(V){if(!de)throw new A("当前 AI 助手不支持重新生成");Te=de({threadId:je.threadId,message:ve,assistantMessage:{id:V.assistantMessage.id,content:V.assistantMessage.content},context:a,capabilities:Je},et)}else Te=v.run({threadId:je.threadId,message:ve,context:a,capabilities:Je},et);const tt=Te[Symbol.asyncIterator]();for(ee.current={iterator:tt,requestVersion:se};;){const Ie=await tt.next();if(te.current!==se||Ie.done)break;let d;try{d=u.parseAssistantEvent(Ie.value)}catch(L){throw new A(L instanceof Error?L.message:"Invalid assistant event")}if(d.type==="message.start"){if(M!==void 0&&M!==d.runId)throw new A("AI 助手响应 run id 不一致");if(M??=d.runId,Ye+=1,Ye>u.MAKE_AI_CONVERSATION_LIMITS.assistantMessagesPerRun)throw new A("AI 助手单次响应消息数量超过限制");if(Qe.has(d.messageId))throw new A("AI 助手响应包含重复的 message id");Qe.add(d.messageId),pe.add(d.messageId),me.set(d.messageId,0)}if(d.type==="message.delta"){if(!pe.has(d.messageId))throw new A("AI 助手响应事件顺序无效");const L=me.get(d.messageId)??0,ae=u.countCodePointsUpTo(d.delta,u.MAKE_AI_CONVERSATION_LIMITS.messageCharacters-ue);if(ue+ae>u.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)throw new A("AI 助手响应文本超过大小限制");ue+=ae,me.set(d.messageId,L+ae)}if(d.type==="message.replace"){if(!pe.has(d.messageId))throw new A("AI 助手响应事件顺序无效");const L=me.get(d.messageId)??0,ae=u.countCodePointsUpTo(d.content,u.MAKE_AI_CONVERSATION_LIMITS.messageCharacters),st=ue-L+ae;if(st>u.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)throw new A("AI 助手响应文本超过大小限制");ue=st,me.set(d.messageId,ae)}if(d.type==="run.progress"){if(M!==void 0&&M!==d.runId)throw new A("AI 助手响应 run id 不一致");if(M??=d.runId,Ge+=1,Ge>u.MAKE_AI_CONVERSATION_LIMITS.progressStepsPerRun)throw new A("AI 助手处理过程数量超过限制");const L=u.countCodePointsUpTo(d.message,u.MAKE_AI_CONVERSATION_LIMITS.progressCharactersPerRun-we);if(we+L>u.MAKE_AI_CONVERSATION_LIMITS.progressCharactersPerRun)throw new A("AI 助手处理过程文本超过大小限制");we+=L}if(d.type==="artifact"){if(!pe.has(d.messageId))throw new A("AI 助手响应事件顺序无效");if(Xe+=1,Xe>u.MAKE_AI_CONVERSATION_LIMITS.artifactsPerRun)throw new A("AI 助手单次响应 Artifact 数量超过限制");if(Ze.has(d.artifact.id))throw new A("AI 助手响应包含重复的 Artifact id");Ze.add(d.artifact.id)}if(d.type==="message.complete"&&!pe.delete(d.messageId))throw new A("AI 助手响应事件顺序无效");if(d.type==="run.complete"&&M!==void 0&&M!==d.runId)throw new A("AI 助手响应 run id 不一致");if(d.type==="run.cancelled"&&d.runId!==void 0&&M!==void 0&&M!==d.runId)throw new A("AI 助手响应 run id 不一致");if(R(L=>u.reduceAssistantEvent(L,d)),d.type==="error"||d.type==="run.cancelled"||d.type==="run.complete"){z=!0;break}}if(!z)throw new A("AI 助手流式响应在终止事件前结束")}catch(z){if(te.current!==se)return;if(Ae.signal.aborted){R(M=>u.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}),R(M=>u.reduceAssistantEvent(M,{type:"error",code:"TRANSPORT_ERROR",message:z instanceof A?z.message:"连接失败,请重试",retryable:!0}))}finally{te.current===se&&J.current===Ae&&(J.current=void 0),ee.current?.requestVersion===se&&(it(ee.current.iterator),ee.current=void 0)}},xe=o=>ze(o),Nt=o=>ze(o.userMessage.content,{regenerateFrom:o}),Mt=async(o,x)=>{try{await ss(x),H({messageId:o,message:"已复制",status:"success"})}catch(f){console.error("[make-ai-assistant] copy answer failed",{errorType:f instanceof Error?f.name:typeof f}),H({messageId:o,message:"复制失败",status:"error"})}},Et=o=>{o.preventDefault(),xe($)},St=o=>{o.key==="Enter"&&!o.shiftKey&&!o.nativeEvent.isComposing&&(o.preventDefault(),xe($))},Rt=()=>{ge("stop")&&R(o=>u.reduceAssistantEvent(o,{type:"run.cancelled"}))},Ct=()=>{ge("new-conversation"),F(""),Y(void 0),H(void 0),B(!1),W.current=!0,R(u.createAssistantConversationState()),c?.()},Ue=v.features?.remoteCancellation===!1?"停止接收":"停止生成",$t=_t(_),Lt=vt(_),_e=vs(_),Ot=typeof v.regenerate=="function"&&v.features?.regeneration!==!1,qe=()=>{_e&&xe(_e.content)};return e.jsxs("section",{className:"make-ai-assistant make-ai-assistant__panel",ref:Re,style:Z,children:[e.jsxs("header",{className:"make-ai-assistant__header",children:[e.jsx(ke,{}),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:p,children:p}),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}),I?e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-describedby":De,"aria-label":`使用提示:${I}`,className:"make-ai-assistant__header-context-help","data-tooltip":I,ref:$e,role:"note",tabIndex:0,onBlur:We,onFocus:Be,onPointerEnter:Be,onPointerLeave:We,children:e.jsx(is,{})}),e.jsx("span",{"aria-hidden":!Q,className:"make-ai-assistant__header-context-tooltip","data-placement":ce?.placement,"data-positioned":ce?!0:void 0,"data-visible":Q||void 0,id:De,ref:Le,role:"tooltip",style:bt,children:I})]}):null]})]}),e.jsxs("div",{className:"make-ai-assistant__header-actions",children:[v.features?.newConversation!==!1?e.jsx("button",{"aria-label":"新建对话",className:"make-ai-assistant__icon-button",type:"button",onClick:Ct,children:e.jsx(cs,{})}):null,i?e.jsx("button",{"aria-label":`关闭 ${p}`,className:"make-ai-assistant__icon-button",type:"button",onClick:i,children:e.jsx(as,{})}):null]})]}),e.jsxs("div",{className:"make-ai-assistant__body","aria-live":"polite","aria-relevant":"additions text",ref:le,role:"log",onScroll:wt,children:[N==="loading"?e.jsxs("div",{className:"make-ai-assistant__empty",role:"status",children:[e.jsx(ke,{}),e.jsx("h3",{children:"正在恢复对话"}),e.jsx("p",{children:"正在读取当前 App 的历史消息…"})]}):N==="error"?e.jsx("div",{className:"make-ai-assistant__empty",children:e.jsx(Is,{error:yt,onRetry:()=>k(o=>o+1)})}):_.messages.length===0?e.jsxs("div",{className:"make-ai-assistant__empty",children:[e.jsx(ke,{}),e.jsx("h3",{children:"有什么可以帮你?"}),e.jsx("p",{children:"我会结合当前 App、页面位置和宿主允许的上下文回答,并把过程与结果分开展示。"})]}):ks(_,a,Ve,r,n,t,_e?qe:void 0,O,T,oe,Ot,(o,x)=>{Mt(o,x)},o=>{Nt(o)}),_.progress&&!$t?e.jsx(ct,{assistantName:t,progress:_.progress}):null,_.error&&!Lt?e.jsx(ct,{assistantName:t,error:_.error,onRetry:_e?qe:void 0}):null]}),kt?e.jsx("button",{"aria-label":"回到最新消息",className:"make-ai-assistant__back-to-latest",type:"button",onClick:Tt,children:e.jsx(os,{})}):null,e.jsxs("footer",{className:"make-ai-assistant__composer-region",children:[N==="ready"&&Ke.length>0&&_.messages.length===0?e.jsx("div",{className:"make-ai-assistant__suggestions","aria-label":"推荐问题",children:Ke.map((o,x)=>e.jsx("button",{type:"button",onClick:()=>{xe(o)},children:o},`${x}-${o}`))}):null,e.jsxs("form",{className:"make-ai-assistant__composer",onSubmit:Et,children:[e.jsx("textarea",{"aria-label":`向 ${t} 提问`,"aria-describedby":X?"make-ai-composer-error":void 0,"aria-invalid":X?!0:void 0,autoFocus:!0,disabled:N!=="ready"||_.status==="streaming",placeholder:`询问当前 ${a.app.name??"App"} 中的数据…`,ref:Ce,rows:2,value:$,onChange:o=>{F(o.currentTarget.value),Y(void 0)},onKeyDown:St}),_.status==="streaming"?e.jsx("button",{"aria-label":Ue,className:"make-ai-assistant__send make-ai-assistant__send--stop","data-tooltip":Ue,ref:Oe,type:"button",onClick:Rt,children:e.jsx("span",{"aria-hidden":"true"})}):e.jsx("button",{"aria-label":"发送",className:"make-ai-assistant__send",disabled:N!=="ready"||!$.trim(),type:"submit",children:e.jsx(ls,{})})]}),X?e.jsx("p",{id:"make-ai-composer-error",role:"alert",children:X}):null,e.jsx("p",{children:"AI 生成的结果可能存在偏差,重要数据请核对明细。"})]})]})}function bs(t){return e.jsx(It,{...t,visible:!0})}function ws({defaultOpen:t=!1,hideLauncher:s=!1,launcher:a,onOpenChange:r,open:n,...i}){const c=ht(i.brandName,i.title),[m,y]=l.useState(t),[g,E]=l.useState(()=>t||n===!0),w=l.useRef(null),C=l.useRef(null),v=l.useRef(void 0),[T,O]=l.useState(),[S,p]=l.useState(Zt),[I,K]=l.useState(!1),b=n??m,Z=typeof window>"u"?void 0:window.innerWidth,$=T===void 0?void 0:{"--make-ai-internal-drawer-width":`${T}px`},F=()=>{if(T!==void 0)return T;const h=C.current?.getBoundingClientRect().width;return h&&Number.isFinite(h)&&h>0?h:S},_=()=>typeof window>"u"?Number.POSITIVE_INFINITY:window.innerWidth,R=h=>{if(h.button!==0)return;const k=F(),N=T===void 0?k:S;p(N),v.current={minimumWidth:N,pointerId:h.pointerId,startWidth:k,startX:h.clientX},K(!0),typeof h.currentTarget.setPointerCapture=="function"&&h.currentTarget.setPointerCapture(h.pointerId),h.preventDefault()},P=h=>{const k=v.current;if(!k||k.pointerId!==h.pointerId)return;const N=nt(k.startWidth+k.startX-h.clientX,k.minimumWidth,_());O(N)},X=h=>{const k=v.current;!k||k.pointerId!==h.pointerId||(v.current=void 0,K(!1))},Y=h=>{const k=h.key==="ArrowLeft"?at:h.key==="ArrowRight"?-at:void 0;if(k===void 0)return;h.preventDefault();const N=F(),G=T===void 0?N:S;p(G),O(nt(N+k,G,_()))},oe=h=>{n===void 0&&y(h),r?.(h),h||requestAnimationFrame(()=>w.current?.focus())},H=()=>oe(!b);return l.useEffect(()=>{b&&E(!0)},[b]),l.useEffect(()=>{if(!b)return;const h=k=>{k.key==="Escape"&&(oe(!1),requestAnimationFrame(()=>w.current?.focus()))};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[r,b]),e.jsxs("div",{className:"make-ai-assistant","data-open":b||void 0,children:[!s&&(!b||a)?a?a({open:b,toggle:H}):e.jsxs("button",{"aria-label":b?`关闭 ${c}`:`打开 ${c}`,"aria-expanded":b,className:"make-ai-assistant__launcher",ref:w,type:"button",onClick:H,children:[e.jsx("span",{className:"make-ai-assistant__launcher-orbit","aria-hidden":"true"}),e.jsx(ft,{})]}):null,g?e.jsxs("aside",{"aria-label":c,"aria-modal":"false",className:"make-ai-assistant__drawer","data-resizing":I||void 0,hidden:!b,ref:C,role:"dialog",style:$,children:[e.jsx("div",{"aria-label":"调整对话框宽度","aria-orientation":"vertical","aria-valuemax":Z,"aria-valuemin":S,"aria-valuenow":T??S,className:"make-ai-assistant__drawer-resize-handle",role:"separator",tabIndex:0,onKeyDown:Y,onPointerCancel:X,onPointerDown:R,onPointerMove:P,onPointerUp:X}),e.jsx(It,{...i,onClose:()=>oe(!1),visible:b})]}):null]})}exports.createArtifactCapabilities=q.createArtifactCapabilities;exports.createArtifactTemplateRegistry=q.createArtifactTemplateRegistry;exports.extendArtifactTemplateRegistry=q.extendArtifactTemplateRegistry;exports.resolveArtifactTemplate=q.resolveArtifactTemplate;exports.MAKE_AI_ARTIFACT_KINDS=u.MAKE_AI_ARTIFACT_KINDS;exports.MAKE_AI_ARTIFACT_LIMITS=u.MAKE_AI_ARTIFACT_LIMITS;exports.MAKE_AI_ARTIFACT_SCHEMA_VERSION=u.MAKE_AI_ARTIFACT_SCHEMA_VERSION;exports.MAKE_AI_CONVERSATION_LIMITS=u.MAKE_AI_CONVERSATION_LIMITS;exports.appendUserMessage=u.appendUserMessage;exports.createAssistantConversationState=u.createAssistantConversationState;exports.parseArtifact=u.parseArtifact;exports.parseAssistantEvent=u.parseAssistantEvent;exports.reduceAssistantEvent=u.reduceAssistantEvent;exports.validateArtifact=u.validateArtifact;exports.ArtifactRenderer=lt;exports.AssistantPanel=bs;exports.MakeAiAssistant=ws;exports.createPlatformArtifactRegistry=pt;exports.formatArtifactValue=U;exports.platformArtifactTemplates=mt;
4
+ `).trim();a.length=0,g&&s.push({type:"paragraph",text:g})},u=()=>{r.length&&s.push({type:"list",items:r.splice(0)})},v=()=>{const g=n.join(`
5
+ `).trim();n.length=0,g&&s.push({type:"pre",text:g})};for(let g=0;g<i.length;g+=1){const w=i[g]??"",T=w.trim();if(!T){c(),u(),v();continue}const R=Is(i,g);if(R){c(),u(),v(),s.push({headers:R.headers,rows:R.rows,type:"table"}),g=R.lastIndex;continue}const C=/^(#{1,6})\s+(.+)$/.exec(T);if(C){c(),u(),v();const E=(C[2]??"").replace(/\s+#+\s*$/,"").trim();E&&s.push({type:"heading",level:C[1]?.length,text:E});continue}if(/^\s*\|.+\|\s*$/.test(w)){c(),u(),n.push(w.trim());continue}const A=/^\s*[-*]\s+(.+)$/.exec(w);if(A){c(),v(),r.push(A[1]?.trim()??"");continue}u(),v(),a.push(T)}return c(),u(),v(),s},_e=e=>{const s=[],a=/(\*\*[^*]+\*\*|`[^`]+`)/g;let r=0;for(const n of e.matchAll(a)){const i=n[0],c=n.index??0;c>r&&s.push(e.slice(r,c)),i.startsWith("**")?s.push(t.jsx("strong",{children:i.slice(2,-2)},`${c}-strong`)):s.push(t.jsx("code",{children:i.slice(1,-1)},`${c}-code`)),r=c+i.length}return r<e.length&&s.push(e.slice(r)),s},ws=({content:e})=>{const s=bs(e);return s.length?t.jsx("div",{className:"make-ai-assistant__bubble make-ai-assistant__assistant-text",children:s.map((a,r)=>{if(a.type==="heading"){const n=a.level<=2?"h3":"h4";return t.jsx(n,{className:`make-ai-assistant__markdown-heading make-ai-assistant__markdown-heading--${a.level}`,children:_e(a.text)},`${r}-heading`)}return a.type==="paragraph"?t.jsx("p",{children:_e(a.text)},`${r}-paragraph`):a.type==="pre"?t.jsx("pre",{children:t.jsx("code",{children:a.text})},`${r}-pre`):a.type==="table"?t.jsx("div",{"aria-label":"表格内容,可横向滚动",className:"make-ai-assistant__markdown-table-scroll",role:"region",tabIndex:0,children:t.jsxs("table",{className:"make-ai-assistant__markdown-table",children:[t.jsx("thead",{children:t.jsx("tr",{children:a.headers.map((n,i)=>t.jsx("th",{scope:"col",children:_e(n)},`${i}-${n}`))})}),t.jsx("tbody",{children:a.rows.map((n,i)=>t.jsx("tr",{children:n.map((c,u)=>t.jsx("td",{children:_e(c)},`${u}-${c}`))},`${i}-${n.join("|")}`))})]})},`${r}-table`):t.jsx("ul",{children:a.items.map((n,i)=>t.jsx("li",{children:_e(n)},`${i}-${n}`))},`${r}-list`)})}):null},bt=({assistantName:e})=>t.jsxs("div",{className:"make-ai-assistant__message-identity",children:[t.jsx(Ne,{className:"make-ai-assistant__avatar--message"}),t.jsx("span",{className:"make-ai-assistant__message-sender",children:e})]}),wt=e=>{for(let s=e.messages.length-1;s>=0;s-=1){const a=e.messages[s];if(a.role==="assistant"&&a.status==="streaming")return a.id}},Ts=e=>{for(let s=e.messages.length-1;s>=0;s-=1)if(e.messages[s].role==="user")return s;return-1},Tt=e=>{const s=Ts(e);if(!(s<0))for(let a=e.messages.length-1;a>s;a-=1){const r=e.messages[a];if(r.role==="assistant")return r.id}},Ms=e=>{if(e.status==="idle")for(let s=e.messages.length-1;s>=0;s-=1){const a=e.messages[s];if(a.role==="assistant"&&a.status==="complete")return a.id}},Ns=e=>{for(let s=e.messages.length-1;s>=0;s-=1){const a=e.messages[s];if(a.role==="user")return a}},Es=(e,s)=>{const a=e.messages.findIndex(r=>r.id===s&&r.role==="user");return{...e,error:void 0,progress:void 0,status:"streaming",messages:a<0?e.messages:e.messages.slice(0,a+1)}},Ss=e=>e.scrollHeight-e.scrollTop-e.clientHeight<=48,pt=(e="smooth")=>globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches?"auto":e,$e=(e,s)=>{typeof e.scrollTo=="function"?e.scrollTo({top:e.scrollHeight,behavior:s}):e.scrollTop=e.scrollHeight},Mt=({error:e,onRetry:s})=>t.jsxs("div",{className:"make-ai-assistant__message-status make-ai-assistant__message-status--error","data-error-presentation":"request-failed",role:"alert",children:[t.jsxs("div",{className:"make-ai-assistant__message-status-header",children:[t.jsx("span",{className:"make-ai-assistant__message-status-icon","aria-hidden":"true",children:t.jsx(js,{})}),t.jsx("strong",{children:"请求未完成"})]}),t.jsx("span",{className:"make-ai-assistant__message-status-message",children:e.message}),e.retryable&&s?t.jsxs("button",{className:"make-ai-assistant__retry",type:"button",onClick:s,children:[t.jsx(It,{}),"重新发送"]}):null]}),Rs=({error:e,onRetry:s})=>{const a=ms(e);return t.jsxs("section",{"aria-live":"assertive",className:"make-ai-assistant__load-failure","data-load-failure-kind":a.kind,role:"alert",children:[t.jsx("span",{className:"make-ai-assistant__load-failure-icon","aria-hidden":"true",children:t.jsxs("svg",{viewBox:"0 0 24 24",children:[t.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"}),t.jsx("path",{d:"m9.2 14.8 5.6-5.6M9.2 9.2l5.6 5.6"})]})}),t.jsxs("div",{className:"make-ai-assistant__load-failure-copy",children:[t.jsx("span",{className:"make-ai-assistant__load-failure-label",children:a.label}),t.jsx("h3",{children:a.title}),t.jsx("p",{children:a.description})]}),t.jsxs("button",{className:"make-ai-assistant__retry make-ai-assistant__retry--primary",type:"button",onClick:s,children:[t.jsx(It,{}),a.actionLabel]})]})},Nt=({active:e,steps:s})=>{if(!e||!s?.length)return null;const a=s[s.length-1]??"处理中";return t.jsxs("details",{className:"make-ai-assistant__process",open:!0,children:[t.jsxs("summary",{children:[t.jsxs("span",{className:"make-ai-assistant__progress",role:"status",children:[t.jsx("span",{"aria-hidden":"true"}),t.jsx("span",{children:a})]}),t.jsxs("span",{className:"make-ai-assistant__process-count",children:[s.length," 步"]})]}),t.jsx("ol",{children:s.map((r,n)=>t.jsxs("li",{"data-step-active":n===s.length-1?!0:void 0,children:[t.jsx("span",{"aria-hidden":"true"}),t.jsx("span",{children:r})]},`${n}-${r}`))})]})},Cs=({copyFeedback:e,onCopy:s,onRegenerate:a})=>!s&&!a?null:t.jsxs("div",{className:"make-ai-assistant__reply-actions","aria-label":"回复操作",children:[s?t.jsx("button",{"aria-label":"复制回答",className:"make-ai-assistant__reply-action make-ai-assistant__reply-copy","data-tooltip":"复制",type:"button",onClick:s,children:t.jsx(hs,{})}):null,a?t.jsx("button",{"aria-label":"重新生成",className:"make-ai-assistant__reply-action make-ai-assistant__reply-regenerate","data-tooltip":"重新生成",type:"button",onClick:a,children:t.jsx(fs,{})}):null,e?t.jsx("span",{className:"make-ai-assistant__reply-feedback","data-copy-status":e.status,role:"status",children:e.message}):null]}),ht=({assistantName:e,error:s,onRetry:a,progress:r})=>{const n=s?"error":"progress";return s?.message??r?.message?t.jsx("article",{"aria-label":`${e}的${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:t.jsxs("div",{className:"make-ai-assistant__message-turn",children:[t.jsx(bt,{assistantName:e}),t.jsx("div",{className:"make-ai-assistant__message-stack",children:s?t.jsx(Mt,{error:s,onRetry:a}):t.jsx(Nt,{active:!0,steps:r?.steps})})]})}):null},$s=(e,s,a,r,n,i,c,u,v,g,w,T,R,C)=>{const A=Tt(e),E=wt(e),H=Ms(e);let M;return e.messages.map(h=>{const I=h.role==="assistant",K=M;I||(M=h);const b=h.id===E,G=h.id===A?e.error:void 0,$=h.error??G,L=!I&&!!(v?.trim()||g),P=I?c:v?.trim()||"用户",f=I&&h.status==="complete"&&!$&&(h.content.trim()||h.id===H);return t.jsx("article",{"aria-label":`${P}的消息`,className:`make-ai-assistant__message make-ai-assistant__message--${h.role}`,"data-message-role":h.role,"data-message-state":$?"error":void 0,"data-message-status":h.status,"data-message-has-identity":I||L?!0:void 0,children:t.jsxs("div",{className:"make-ai-assistant__message-turn",children:[I?t.jsx(bt,{assistantName:c}):L?t.jsx(As,{userAvatarUrl:g,userName:v}):null,t.jsxs("div",{className:"make-ai-assistant__message-stack",children:[h.content?I?t.jsx(ws,{content:h.content}):t.jsx("div",{className:"make-ai-assistant__bubble",children:h.content}):h.status==="streaming"?t.jsxs("div",{className:"make-ai-assistant__typing","aria-label":`${c}正在思考`,children:[t.jsx("span",{}),t.jsx("span",{}),t.jsx("span",{})]}):null,I?t.jsx(Nt,{active:b&&e.status==="streaming",steps:h.progressSteps}):null,$?t.jsx(Mt,{error:$,onRetry:G?u:void 0}):null,h.artifacts.map(S=>t.jsx(gt,{artifact:S,context:s,onAction:n,onActionError:i,registry:a,theme:r},S.id)),f?t.jsx(Cs,{copyFeedback:w?.messageId===h.id?{message:w.message,status:w.status}:void 0,onCopy:h.content.trim()?()=>R(h.id,h.content):void 0,onRegenerate:T&&h.id===H&&K?()=>C({userMessage:K,assistantMessage:h}):void 0}):null]})]})},h.id)})};function Et({assistantName:e="AI 助手",brandName:s,context:a,onAction:r,onActionError:n,onClose:i,onNewConversation:c,headerHeight:u,privacyNotice:v,registry:g,subtitle:w,suggestions:T,title:R,theme:C,transport:A,userAvatarUrl:E,userName:H,visible:M}){const h=yt(s,R),I=v?.trim(),K=as(w,a.app.name),b=ls(u),G=Le(C),$=G||b?{...G,...b?{"--make-ai-internal-header-height":b}:{}}:void 0,[L,P]=l.useState(""),[f,S]=l.useState(m.createAssistantConversationState),B=l.useRef(f);B.current=f;const[J,Z]=l.useState(void 0),[ve,Q]=l.useState(void 0),[de,je]=l.useState(0),[p,j]=l.useState(()=>A.loadConversation?"loading":"ready"),[V,ee]=l.useState(void 0),[St,U]=l.useState(!1),[te,Oe]=l.useState(!1),[me,Fe]=l.useState(void 0),se=l.useRef(void 0),ae=l.useRef(void 0),ne=l.useRef(0),De=l.useRef(null),ue=l.useRef(null),Pe=l.useRef(null),Ve=l.useRef(null),We=l.useRef(null),He=l.useRef(null),z=l.useRef(!0),Ke=l.useRef(a.app.id),Be=l.useRef(M),Ue=l.useId(),ze=l.useMemo(()=>g??jt(),[g]),qe=l.useMemo(()=>ts(T),[T]),Xe=()=>{const o=Ve.current,_=We.current;if(!o||!_||typeof window>"u")return;const x=cs(o.getBoundingClientRect(),_.getBoundingClientRect(),window.innerHeight,window.innerWidth);Fe(y=>y?.left===x.left&&y.top===x.top&&y.placement===x.placement?y:x)},Ye=()=>Oe(!0),Ge=()=>Oe(!1),Rt=me?{left:`${me.left}px`,top:`${me.top}px`}:void 0;l.useLayoutEffect(()=>{if(!te||!I){Fe(void 0);return}Xe()},[te,I]),l.useEffect(()=>{if(!te||!I)return;const o=()=>Xe();return window.addEventListener("resize",o),window.addEventListener("scroll",o,!0),()=>{window.removeEventListener("resize",o),window.removeEventListener("scroll",o,!0)}},[te,I]);const ye=o=>{const _=se.current,x=ae.current?.iterator;return!_&&!x?!1:(ne.current+=1,se.current=void 0,ae.current=void 0,console.info("[make-ai-assistant] local run cancellation requested",{reason:o}),_?.abort(),ut(x),!0)};l.useEffect(()=>()=>{ye("unmount")},[]),l.useEffect(()=>{const o=A.loadConversation,_=Ke.current!==a.app.id;if(Ke.current=a.app.id,ye("reinitialize"),_&&(P(""),z.current=!0),Z(void 0),Q(void 0),U(!1),S(m.createAssistantConversationState()),!o){ee(void 0),j("ready");return}const x=new AbortController;return ee(void 0),j("loading"),console.info("[make-ai-assistant] conversation load start",{appId:a.app.id}),o.call(A,a,{signal:x.signal}).then(y=>{x.signal.aborted||(S(m.createAssistantConversationState(y)),j("ready"),console.info("[make-ai-assistant] conversation load success",{appId:a.app.id,messageCount:y.messages.length}))}).catch(y=>{x.signal.aborted||(console.error("[make-ai-assistant] conversation load failed",{appId:a.app.id,errorType:y instanceof Error?y.name:typeof y}),ee(y),j("error"))}),()=>x.abort()},[a.app.id,de,A]),l.useEffect(()=>{const o=ue.current;if(!o||!z.current)return;U(!1);const _=requestAnimationFrame(()=>{if(!z.current)return;const x=f.status==="streaming"||globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches?"auto":"smooth";$e(o,x)});return()=>cancelAnimationFrame(_)},[f.messages,f.progress,f.status]),l.useEffect(()=>{const o=M&&!Be.current;if(Be.current=M,!o)return;const _=requestAnimationFrame(()=>{const x=ue.current;if(x&&z.current){U(!1);const pe=B.current.status==="streaming"?"auto":pt();$e(x,pe)}else x&&U(B.current.messages.length>0);const y=Pe.current;(y&&!y.disabled?y:He.current??De.current?.querySelector("button:not(:disabled)"))?.focus()});return()=>cancelAnimationFrame(_)},[M]);const Ct=()=>{const o=ue.current;if(!o)return;const _=Ss(o);z.current=_,U(!_&&B.current.messages.length>0)},$t=()=>{const o=ue.current;if(!o)return;z.current=!0,U(!1);const _=pt();$e(o,_)},Ze=async(o,_)=>{const x=o.trim(),y=B.current,W=_?.regenerateFrom,pe=A.regenerate;if(!x||p!=="ready"||y.status==="streaming"||se.current||W&&!pe)return;if(m.countCodePointsUpTo(x,m.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)>m.MAKE_AI_CONVERSATION_LIMITS.messageCharacters){Z(`输入内容过长,请控制在 ${m.MAKE_AI_CONVERSATION_LIMITS.messageCharacters} 个字符以内`);return}const Ie={id:W?.userMessage.id??Qt("user"),content:x},be=W?Es(y,W.userMessage.id):m.appendUserMessage(y,Ie),we=new AbortController,re=ne.current+1;ne.current=re,se.current=we,Z(void 0),Q(void 0),U(!z.current&&y.messages.length>0),W||P(""),S(be);try{let q=!1,N,et=0,tt=0,st=0,Ee=0,he=0;const fe=new Map,at=new Set,nt=new Set([...be.messages.map(Te=>Te.id),Ie.id]),ge=new Set,rt=Y.createArtifactCapabilities(ze),it={signal:we.signal};let Se;if(W){if(!pe)throw new k("当前 AI 助手不支持重新生成");Se=pe({threadId:be.threadId,message:Ie,assistantMessage:{id:W.assistantMessage.id,content:W.assistantMessage.content},context:a,capabilities:rt},it)}else Se=A.run({threadId:be.threadId,message:Ie,context:a,capabilities:rt},it);const ot=Se[Symbol.asyncIterator]();for(ae.current={iterator:ot,requestVersion:re};;){const Te=await ot.next();if(ne.current!==re||Te.done)break;let d;try{d=m.parseAssistantEvent(Te.value)}catch(O){throw new k(O instanceof Error?O.message:"Invalid assistant event")}if(d.type==="message.start"){if(N!==void 0&&N!==d.runId)throw new k("AI 助手响应 run id 不一致");if(N??=d.runId,tt+=1,tt>m.MAKE_AI_CONVERSATION_LIMITS.assistantMessagesPerRun)throw new k("AI 助手单次响应消息数量超过限制");if(nt.has(d.messageId))throw new k("AI 助手响应包含重复的 message id");nt.add(d.messageId),ge.add(d.messageId),fe.set(d.messageId,0)}if(d.type==="message.delta"){if(!ge.has(d.messageId))throw new k("AI 助手响应事件顺序无效");const O=fe.get(d.messageId)??0,ie=m.countCodePointsUpTo(d.delta,m.MAKE_AI_CONVERSATION_LIMITS.messageCharacters-he);if(he+ie>m.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)throw new k("AI 助手响应文本超过大小限制");he+=ie,fe.set(d.messageId,O+ie)}if(d.type==="message.replace"){if(!ge.has(d.messageId))throw new k("AI 助手响应事件顺序无效");const O=fe.get(d.messageId)??0,ie=m.countCodePointsUpTo(d.content,m.MAKE_AI_CONVERSATION_LIMITS.messageCharacters),ct=he-O+ie;if(ct>m.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)throw new k("AI 助手响应文本超过大小限制");he=ct,fe.set(d.messageId,ie)}if(d.type==="run.progress"){if(N!==void 0&&N!==d.runId)throw new k("AI 助手响应 run id 不一致");if(N??=d.runId,st+=1,st>m.MAKE_AI_CONVERSATION_LIMITS.progressStepsPerRun)throw new k("AI 助手处理过程数量超过限制");const O=m.countCodePointsUpTo(d.message,m.MAKE_AI_CONVERSATION_LIMITS.progressCharactersPerRun-Ee);if(Ee+O>m.MAKE_AI_CONVERSATION_LIMITS.progressCharactersPerRun)throw new k("AI 助手处理过程文本超过大小限制");Ee+=O}if(d.type==="artifact"){if(!ge.has(d.messageId))throw new k("AI 助手响应事件顺序无效");if(et+=1,et>m.MAKE_AI_CONVERSATION_LIMITS.artifactsPerRun)throw new k("AI 助手单次响应 Artifact 数量超过限制");if(at.has(d.artifact.id))throw new k("AI 助手响应包含重复的 Artifact id");at.add(d.artifact.id)}if(d.type==="message.complete"&&!ge.delete(d.messageId))throw new k("AI 助手响应事件顺序无效");if(d.type==="run.complete"&&N!==void 0&&N!==d.runId)throw new k("AI 助手响应 run id 不一致");if(d.type==="run.cancelled"&&d.runId!==void 0&&N!==void 0&&N!==d.runId)throw new k("AI 助手响应 run id 不一致");if(S(O=>m.reduceAssistantEvent(O,d)),d.type==="error"||d.type==="run.cancelled"||d.type==="run.complete"){q=!0;break}}if(!q)throw new k("AI 助手流式响应在终止事件前结束")}catch(q){if(ne.current!==re)return;if(we.signal.aborted){S(N=>m.reduceAssistantEvent(N,{type:"run.cancelled"}));return}console.error("[make-ai-assistant] assistant run failed",{appId:a.app.id,errorType:q instanceof Error?q.name:typeof q}),S(N=>m.reduceAssistantEvent(N,{type:"error",code:"TRANSPORT_ERROR",message:q instanceof k?q.message:"连接失败,请重试",retryable:!0}))}finally{ne.current===re&&se.current===we&&(se.current=void 0),ae.current?.requestVersion===re&&(ut(ae.current.iterator),ae.current=void 0)}},Ae=o=>Ze(o),Lt=o=>Ze(o.userMessage.content,{regenerateFrom:o}),Ot=async(o,_)=>{try{await us(_),Q({messageId:o,message:"已复制",status:"success"})}catch(x){console.error("[make-ai-assistant] copy answer failed",{errorType:x instanceof Error?x.name:typeof x}),Q({messageId:o,message:"复制失败",status:"error"})}},Ft=o=>{o.preventDefault(),Ae(L)},Dt=o=>{o.key==="Enter"&&!o.shiftKey&&!o.nativeEvent.isComposing&&(o.preventDefault(),Ae(L))},Pt=()=>{ye("stop")&&S(o=>m.reduceAssistantEvent(o,{type:"run.cancelled"}))},Vt=()=>{ye("new-conversation"),P(""),Z(void 0),Q(void 0),U(!1),z.current=!0,S(m.createAssistantConversationState()),c?.()},Qe=A.features?.remoteCancellation===!1?"停止接收":"停止生成",Wt=wt(f),Ht=Tt(f),ke=Ns(f),Kt=typeof A.regenerate=="function"&&A.features?.regeneration!==!1,Je=()=>{ke&&Ae(ke.content)};return t.jsxs("section",{className:"make-ai-assistant make-ai-assistant__panel",ref:De,style:$,children:[t.jsxs("header",{className:"make-ai-assistant__header",children:[t.jsx(Ne,{}),t.jsxs("div",{className:"make-ai-assistant__header-content",children:[t.jsxs("div",{className:"make-ai-assistant__header-title-row",children:[t.jsx("h2",{className:"make-ai-assistant__header-title",title:h,children:h}),t.jsx("span",{className:"make-ai-assistant__read-only-tag",children:"只读"})]}),t.jsxs("div",{className:"make-ai-assistant__header-context",children:[t.jsx("p",{title:K,children:K}),I?t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-describedby":Ue,"aria-label":`使用提示:${I}`,className:"make-ai-assistant__header-context-help","data-tooltip":I,ref:Ve,role:"note",tabIndex:0,onBlur:Ge,onFocus:Ye,onPointerEnter:Ye,onPointerLeave:Ge,children:t.jsx(gs,{})}),t.jsx("span",{"aria-hidden":!te,className:"make-ai-assistant__header-context-tooltip","data-placement":me?.placement,"data-positioned":me?!0:void 0,"data-visible":te||void 0,id:Ue,ref:We,role:"tooltip",style:Rt,children:I})]}):null]})]}),t.jsxs("div",{className:"make-ai-assistant__header-actions",children:[A.features?.newConversation!==!1?t.jsx("button",{"aria-label":"新建对话",className:"make-ai-assistant__icon-button",type:"button",onClick:Vt,children:t.jsx(_s,{})}):null,i?t.jsx("button",{"aria-label":`关闭 ${h}`,className:"make-ai-assistant__icon-button",type:"button",onClick:i,children:t.jsx(ps,{})}):null]})]}),t.jsxs("div",{className:"make-ai-assistant__body","aria-live":"polite","aria-relevant":"additions text",ref:ue,role:"log",onScroll:Ct,children:[p==="loading"?t.jsxs("div",{className:"make-ai-assistant__empty",role:"status",children:[t.jsx(Ne,{}),t.jsx("h3",{children:"正在恢复对话"}),t.jsx("p",{children:"正在读取当前 App 的历史消息…"})]}):p==="error"?t.jsx("div",{className:"make-ai-assistant__empty",children:t.jsx(Rs,{error:V,onRetry:()=>je(o=>o+1)})}):f.messages.length===0?t.jsxs("div",{className:"make-ai-assistant__empty",children:[t.jsx(Ne,{}),t.jsx("h3",{children:"有什么可以帮你?"}),t.jsx("p",{children:"我会结合当前 App、页面位置和宿主允许的上下文回答,并把过程与结果分开展示。"})]}):$s(f,a,ze,C,r,n,e,ke?Je:void 0,H,E,ve,Kt,(o,_)=>{Ot(o,_)},o=>{Lt(o)}),f.progress&&!Wt?t.jsx(ht,{assistantName:e,progress:f.progress}):null,f.error&&!Ht?t.jsx(ht,{assistantName:e,error:f.error,onRetry:ke?Je:void 0}):null]}),St?t.jsx("button",{"aria-label":"回到最新消息",className:"make-ai-assistant__back-to-latest",type:"button",onClick:$t,children:t.jsx(xs,{})}):null,t.jsxs("footer",{className:"make-ai-assistant__composer-region",children:[p==="ready"&&qe.length>0&&f.messages.length===0?t.jsx("div",{className:"make-ai-assistant__suggestions","aria-label":"推荐问题",children:qe.map((o,_)=>t.jsx("button",{type:"button",onClick:()=>{Ae(o)},children:o},`${_}-${o}`))}):null,t.jsxs("form",{className:"make-ai-assistant__composer",onSubmit:Ft,children:[t.jsx("textarea",{"aria-label":`向 ${e} 提问`,"aria-describedby":J?"make-ai-composer-error":void 0,"aria-invalid":J?!0:void 0,autoFocus:!0,disabled:p!=="ready"||f.status==="streaming",placeholder:`询问当前 ${a.app.name??"App"} 中的数据…`,ref:Pe,rows:2,value:L,onChange:o=>{P(o.currentTarget.value),Z(void 0)},onKeyDown:Dt}),f.status==="streaming"?t.jsx("button",{"aria-label":Qe,className:"make-ai-assistant__send make-ai-assistant__send--stop","data-tooltip":Qe,ref:He,type:"button",onClick:Pt,children:t.jsx("span",{"aria-hidden":"true"})}):t.jsx("button",{"aria-label":"发送",className:"make-ai-assistant__send",disabled:p!=="ready"||!L.trim(),type:"submit",children:t.jsx(vs,{})})]}),J?t.jsx("p",{id:"make-ai-composer-error",role:"alert",children:J}):null,t.jsx("p",{children:"AI 生成的结果可能存在偏差,重要数据请核对明细。"})]})]})}function Ls(e){return t.jsx(Et,{...e,visible:!0})}function Os({defaultOpen:e=!1,hideLauncher:s=!1,launcher:a,maxDrawerWidth:r,onOpenChange:n,open:i,...c}){const u=yt(c.brandName,c.title),[v,g]=l.useState(e),[w,T]=l.useState(()=>e||i===!0),R=l.useRef(null),C=l.useRef(null),A=l.useRef(void 0),[E,H]=l.useState(),[M,h]=l.useState(ns),[I,K]=l.useState(!1),b=i??v,G=Le(c.theme),$=is(r),L=()=>os(M,$,typeof window>"u"?At:window.innerWidth),P=L(),f=E===void 0?void 0:Re(E,M,P),S=f===void 0&&$===void 0?void 0:{...f===void 0?{}:{"--make-ai-internal-drawer-width":`${f}px`},...$===void 0?{}:{"--make-ai-internal-drawer-max-width":`max(var(--make-ai-internal-drawer-min-width), ${$}px)`}};l.useLayoutEffect(()=>{f!==void 0&&f!==E&&H(f)},[f,E]);const B=()=>{if(f!==void 0)return f;const p=C.current?.getBoundingClientRect().width;return p&&Number.isFinite(p)&&p>0?p:M},J=p=>{if(p.button!==0)return;const j=B(),V=E===void 0?j:M;h(V),A.current={minimumWidth:V,pointerId:p.pointerId,startWidth:j,startX:p.clientX},K(!0),typeof p.currentTarget.setPointerCapture=="function"&&p.currentTarget.setPointerCapture(p.pointerId),p.preventDefault()},Z=p=>{const j=A.current;if(!j||j.pointerId!==p.pointerId)return;const V=Re(j.startWidth+j.startX-p.clientX,j.minimumWidth,L());H(V)},ve=p=>{const j=A.current;!j||j.pointerId!==p.pointerId||(A.current=void 0,K(!1))},Q=p=>{const j=p.key==="ArrowLeft"?dt:p.key==="ArrowRight"?-dt:void 0;if(j===void 0)return;p.preventDefault();const V=B(),ee=E===void 0?V:M;h(ee),H(Re(V+j,ee,L()))},de=p=>{i===void 0&&g(p),n?.(p),p||requestAnimationFrame(()=>R.current?.focus())},je=()=>de(!b);return l.useEffect(()=>{b&&T(!0)},[b]),l.useEffect(()=>{if(!b)return;const p=j=>{j.key==="Escape"&&(de(!1),requestAnimationFrame(()=>R.current?.focus()))};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[n,b]),t.jsxs("div",{className:"make-ai-assistant","data-open":b||void 0,style:G,children:[!s&&(!b||a)?a?a({open:b,toggle:je}):t.jsxs("button",{"aria-label":b?`关闭 ${u}`:`打开 ${u}`,"aria-expanded":b,className:"make-ai-assistant__launcher",ref:R,type:"button",onClick:je,children:[t.jsx("span",{className:"make-ai-assistant__launcher-orbit","aria-hidden":"true"}),t.jsx(kt,{})]}):null,w?t.jsxs("aside",{"aria-label":u,"aria-modal":"false",className:"make-ai-assistant__drawer","data-resizing":I||void 0,hidden:!b,ref:C,role:"dialog",style:S,children:[t.jsx("div",{"aria-label":"调整对话框宽度","aria-orientation":"vertical","aria-valuemax":P,"aria-valuemin":M,"aria-valuenow":f??M,className:"make-ai-assistant__drawer-resize-handle",role:"separator",tabIndex:0,onKeyDown:Q,onPointerCancel:ve,onPointerDown:J,onPointerMove:Z,onPointerUp:ve}),t.jsx(Et,{...c,onClose:()=>de(!1),visible:b})]}):null]})}exports.createArtifactCapabilities=Y.createArtifactCapabilities;exports.createArtifactTemplateRegistry=Y.createArtifactTemplateRegistry;exports.extendArtifactTemplateRegistry=Y.extendArtifactTemplateRegistry;exports.resolveArtifactTemplate=Y.resolveArtifactTemplate;exports.MAKE_AI_ARTIFACT_KINDS=m.MAKE_AI_ARTIFACT_KINDS;exports.MAKE_AI_ARTIFACT_LIMITS=m.MAKE_AI_ARTIFACT_LIMITS;exports.MAKE_AI_ARTIFACT_SCHEMA_VERSION=m.MAKE_AI_ARTIFACT_SCHEMA_VERSION;exports.MAKE_AI_CONVERSATION_LIMITS=m.MAKE_AI_CONVERSATION_LIMITS;exports.appendUserMessage=m.appendUserMessage;exports.createAssistantConversationState=m.createAssistantConversationState;exports.parseArtifact=m.parseArtifact;exports.parseAssistantEvent=m.parseAssistantEvent;exports.reduceAssistantEvent=m.reduceAssistantEvent;exports.validateArtifact=m.validateArtifact;exports.ArtifactRenderer=gt;exports.AssistantPanel=Ls;exports.MakeAiAssistant=Os;exports.createPlatformArtifactRegistry=jt;exports.formatArtifactValue=X;exports.platformArtifactTemplates=vt;