@qfei-design/make-ai-assistant 0.2.4 → 0.2.5
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 +12 -1
- package/README.md +39 -1
- package/dist/react/artifact-renderer.d.ts +4 -2
- package/dist/react/artifact-templates.d.ts +3 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/make-ai-assistant.d.ts +2 -0
- package/dist/react/theme.d.ts +45 -0
- package/dist/react.cjs +4 -4
- package/dist/react.mjs +706 -631
- package/dist/styles.css +38 -33
- package/package.json +1 -1
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,7 +51,44 @@ AI transport;进度和可重试错误会显示在对应的 AI 回合中。
|
|
|
50
51
|
不传入或传入空白内容时不显示图标。标题右侧紧随标题展示“只读”状态标签,长标题会省略显示并保留原文
|
|
51
52
|
`title` 属性。头栏默认高度为 50px,可通过 `headerHeight` 属性或 `--make-ai-header-height` 主题变量覆盖。
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
## Theme integration
|
|
55
|
+
|
|
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,且该初始宽度是用户拖拽时的最小宽度。鼠标移至抽屉左边缘的 12px 热区时才会显示 2px 主题色拖拽提示线(可通过 `--make-ai-drawer-resize-line` 覆盖),可向左拖宽;获得焦点后也可用左、右方向键以 16px 调整宽度。小于 560px 的视口保持全宽展示,不显示拖拽手柄。
|
|
54
92
|
|
|
55
93
|
面板使用容器查询而非页面视口响应宽度:抽屉达到 560px 时会增加内边距、正文可读宽度和结构化内容密度;达到 760px 时 Markdown 表格会优先按可用宽度分列并换行。宿主可通过 `--make-ai-panel-gutter-wide` 覆盖扩展抽屉的内边距。
|
|
56
94
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type
|
|
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):
|
|
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>;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -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;
|
|
@@ -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"),G=require("./index.cjs"),m=require("./conversation-Cv1wdvCR.cjs"),ht=e=>e?.trim()||void 0,O=(e,s)=>ht(e)??s,Ce=e=>{const s=ht(e?.primary);if(s)return{"--make-ai-theme-primary":s,"--make-ai-theme-primary-hover":O(e?.primaryHover,"color-mix(in srgb, var(--make-ai-theme-primary) 84%, var(--make-ai-theme-text))"),"--make-ai-theme-on-primary":O(e?.onPrimary,"#fcfcff"),"--make-ai-theme-bg":O(e?.background,"color-mix(in srgb, var(--make-ai-theme-primary) 2%, #fcfcff)"),"--make-ai-theme-surface":O(e?.surface,"color-mix(in srgb, var(--make-ai-theme-primary) 4%, var(--make-ai-theme-bg))"),"--make-ai-theme-surface-strong":O(e?.surfaceStrong,"color-mix(in srgb, var(--make-ai-theme-primary) 8%, var(--make-ai-theme-bg))"),"--make-ai-theme-text":O(e?.text,"color-mix(in srgb, var(--make-ai-theme-primary) 12%, #252631)"),"--make-ai-theme-text-secondary":O(e?.textSecondary,"color-mix(in srgb, var(--make-ai-theme-text) 74%, var(--make-ai-theme-primary))"),"--make-ai-theme-border":O(e?.border,"color-mix(in srgb, var(--make-ai-theme-primary) 14%, var(--make-ai-theme-bg))"),"--make-ai-theme-overlay":O(e?.overlay,"color-mix(in srgb, var(--make-ai-theme-text) 88%, var(--make-ai-theme-primary))"),"--make-ai-theme-on-overlay":O(e?.onOverlay,"#fcfcff")}},ot=(e,s)=>!s||!l.isValidElement(e)||typeof e.type!="string"?e:l.cloneElement(e,{style:{...e.props.style,...s}});function ft({artifact:e,context:s,fallback:a,onAction:r,onActionError:n,registry:i,theme:c}){const p=Ce(c),v=G.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 ot(T,p)}const f={context:s,onAction:r,onActionError:n,theme:c,themeStyle:p},w=v.template.render(e,s,f);return ot(w,p)}const Y=(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??""}`}},gt=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}},xt=(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)}},oe=(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:()=>xt(a,{artifact:e,context:s.context},s),children:[a.label,t.jsx("span",{"aria-hidden":"true",children:"→"})]},a.id))}):null,ce=(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?Y(a.value,a.format==="percent"?{style:"percent"}:void 0,s.context.locale):void 0;return ce(e,t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"make-ai-artifact__metric-value",children:Y(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,oe(e,s)]}),"make-ai-artifact--metric",s.themeStyle)},Wt=({artifact:e,renderContext:s})=>ce(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:Y(a.value,a.format,s.context.locale)}),a.hint?t.jsx("small",{children:a.hint}):null]},a.id))}),oe(e,s)]}),"make-ai-artifact--comparison",s.themeStyle),zt=({artifact:e,renderContext:s})=>{const a=e.data.series.flatMap(c=>c.points.map(p=>p.y)),{max:r,min:n}=gt(a),i=r-n||1;return ce(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((p,v)=>{const f=18+(p.y-n)/i*70;return t.jsxs("div",{className:"make-ai-artifact__trend-point",children:[t.jsx("span",{"aria-label":`${p.x}: ${Y(p.y,c.format,s.context.locale)}`,className:"make-ai-artifact__trend-bar",role:"img",style:{height:`${f}%`},title:`${p.x}: ${Y(p.y,c.format,s.context.locale)}`}),t.jsx("small",{children:p.x})]},`${p.x}-${v}`)})})]},c.id))}),oe(e,s)]}),"make-ai-artifact--trend",s.themeStyle)},Ut=({artifact:e,renderContext:s})=>{const{max:a}=gt(e.data.items.map(n=>Math.abs(n.value))),r=Math.max(a,1);return ce(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:Y(n.value,n.format,s.context.locale)})]},n.id))}),oe(e,s)]}),"make-ai-artifact--ranking",s.themeStyle)},qt=(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}},Xt=({artifact:e,renderContext:s})=>ce(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=qt(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}),Y(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:()=>xt(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,oe(e,s)]}),"make-ai-artifact--record-list",s.themeStyle),Yt=({artifact:e,renderContext:s})=>ce(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})]}),oe(e,s)]}),"make-ai-artifact--notice",s.themeStyle),ie=(e,s,a)=>({id:e,kinds:[s],priority:0,render:a}),Gt=[ie("platform.metric.default","metric",(e,s,a)=>t.jsx(Bt,{artifact:e,renderContext:a})),ie("platform.comparison.default","comparison",(e,s,a)=>t.jsx(Wt,{artifact:e,renderContext:a})),ie("platform.trend.default","trend",(e,s,a)=>t.jsx(zt,{artifact:e,renderContext:a})),ie("platform.ranking.default","ranking",(e,s,a)=>t.jsx(Ut,{artifact:e,renderContext:a})),ie("platform.record-list.default","record-list",(e,s,a)=>t.jsx(Xt,{artifact:e,renderContext:a})),ie("platform.notice.default","notice",(e,s,a)=>t.jsx(Yt,{artifact:e,renderContext:a}))],_t=G.createArtifactTemplateRegistry(Gt).templates,vt=(e=_t)=>G.createArtifactTemplateRegistry(e),Zt=e=>`${e}-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,Qt="Make",Jt=["总结当前页面数据","找出需要关注的记录","列出我有权限查看的数据对象"],jt=(e,s)=>s??`${e?.trim()||Qt} AI 助手`,es=e=>e??Jt,ts=/^只读分析\s*[·•]\s*/u,ss=(e,s)=>e?.trim().replace(ts,"").trim()||`当前对象:${s??"未命名应用"}`,as=432,ct=16,F=16,fe=8,lt=(e,s,a)=>Math.min(Math.max(e,Math.min(s,a)),a),dt=(e,s,a)=>Math.min(Math.max(e,s),Math.max(s,a)),ns=(e,s,a,r)=>{const n=Math.min(Math.max(s.width,1),Math.max(1,r-F*2)),i=Math.min(Math.max(s.height,1),Math.max(1,a-F*2)),c=e.left+e.width/2,p=e.top+e.height/2,f=[{left:e.right+fe,placement:"right",top:p-i/2},{left:e.left-fe-n,placement:"left",top:p-i/2},{left:c-n/2,placement:"bottom",top:e.bottom+fe},{left:c-n/2,placement:"top",top:e.top-fe-i}].find(({left:w,top:T})=>w>=F&&T>=F&&w+n<=r-F&&T+i<=a-F);return f||{left:dt(c-n/2,F,r-F-n),placement:"bottom",top:dt(e.bottom+fe,F,a-F-i)}},rs=e=>typeof e=="number"?Number.isFinite(e)?`${e}px`:void 0:e?.trim()||void 0;class k extends Error{}const we=(e,s)=>{if(!(typeof e!="object"||e===null))return e[s]},is=e=>{const s=we(e,"status");return typeof s=="number"?s:we(we(e,"response"),"status")},os=e=>{const s=we(e,"code"),a=is(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),p=typeof a=="number"&&a>=500||/server|service|服务器|服务异常/.test(n);return c?{actionLabel:"重新连接",description:"请检查网络后再试。",kind:"network",label:"网络连接",title:"网络连接不可用"}:p?{actionLabel:"重新加载",description:"服务暂时未能响应,请稍后重试。",kind:"service",label:"服务异常",title:"服务暂时不可用"}:{actionLabel:"重新加载",description:"请稍后重试;若问题持续出现,请联系管理员。",kind:"unknown",label:"加载异常",title:"暂时无法加载对话"}},mt=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})}},cs=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")},yt=()=>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"})]}),ls=()=>t.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:t.jsx("path",{d:"m6 6 12 12M18 6 6 18"})}),ds=()=>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"})]}),ms=()=>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"})]}),us=()=>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"})]}),ps=()=>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"})]}),hs=()=>t.jsx("svg",{"aria-hidden":"true",viewBox:"0 0 24 24",children:t.jsx("path",{d:"M12 5v14M5 12h14"})}),fs=()=>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"})]}),At=()=>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:"M12 8v4.5"}),t.jsx("path",{d:"M12 16h.01"})]}),Te=({className:e=""})=>t.jsx("span",{className:`make-ai-assistant__avatar ${e}`.trim(),"aria-hidden":"true",children:t.jsx(yt,{})}),xs=({src:e})=>e?t.jsx("span",{className:"make-ai-assistant__user-avatar","aria-hidden":"true",children:t.jsx("img",{alt:"",src:e})}):null,_s=({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(xs,{src:e})]})},Se=e=>{const s=e.trim();if(!(!s.startsWith("|")||!s.endsWith("|")))return s.slice(1,-1).split("|").map(a=>a.trim())},vs=e=>e.length>0&&e.every(s=>/^:?-{3,}:?$/.test(s)),js=(e,s)=>{const a=Se(e[s]??""),r=Se(e[s+1]??"");if(!a||!r||a.length!==r.length||!vs(r))return;const n=[];let i=s+2;for(;i<e.length;){const c=Se(e[i]??"");if(!c||c.length!==a.length)break;n.push(c),i+=1}return{headers:a,lastIndex:i-1,rows:n}},ys=e=>{const s=[],a=[],r=[],n=[],i=e.replace(/\r\n?/g,`
|
|
2
2
|
`).split(`
|
|
3
|
-
`),c=()=>{const
|
|
4
|
-
`).trim();a.length=0,
|
|
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;
|
|
3
|
+
`),c=()=>{const f=a.join(`
|
|
4
|
+
`).trim();a.length=0,f&&s.push({type:"paragraph",text:f})},p=()=>{r.length&&s.push({type:"list",items:r.splice(0)})},v=()=>{const f=n.join(`
|
|
5
|
+
`).trim();n.length=0,f&&s.push({type:"pre",text:f})};for(let f=0;f<i.length;f+=1){const w=i[f]??"",T=w.trim();if(!T){c(),p(),v();continue}const S=js(i,f);if(S){c(),p(),v(),s.push({headers:S.headers,rows:S.rows,type:"table"}),f=S.lastIndex;continue}const M=/^(#{1,6})\s+(.+)$/.exec(T);if(M){c(),p(),v();const P=(M[2]??"").replace(/\s+#+\s*$/,"").trim();P&&s.push({type:"heading",level:M[1]?.length,text:P});continue}if(/^\s*\|.+\|\s*$/.test(w)){c(),p(),n.push(w.trim());continue}const _=/^\s*[-*]\s+(.+)$/.exec(w);if(_){c(),v(),r.push(_[1]?.trim()??"");continue}p(),v(),a.push(T)}return c(),p(),v(),s},ge=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},As=({content:e})=>{const s=ys(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:ge(a.text)},`${r}-heading`)}return a.type==="paragraph"?t.jsx("p",{children:ge(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:ge(n)},`${i}-${n}`))})}),t.jsx("tbody",{children:a.rows.map((n,i)=>t.jsx("tr",{children:n.map((c,p)=>t.jsx("td",{children:ge(c)},`${p}-${c}`))},`${i}-${n.join("|")}`))})]})},`${r}-table`):t.jsx("ul",{children:a.items.map((n,i)=>t.jsx("li",{children:ge(n)},`${i}-${n}`))},`${r}-list`)})}):null},kt=({assistantName:e})=>t.jsxs("div",{className:"make-ai-assistant__message-identity",children:[t.jsx(Te,{className:"make-ai-assistant__avatar--message"}),t.jsx("span",{className:"make-ai-assistant__message-sender",children:e})]}),It=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}},ks=e=>{for(let s=e.messages.length-1;s>=0;s-=1)if(e.messages[s].role==="user")return s;return-1},bt=e=>{const s=ks(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}},Is=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}},bs=e=>{for(let s=e.messages.length-1;s>=0;s-=1){const a=e.messages[s];if(a.role==="user")return a}},ws=(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)}},Ts=e=>e.scrollHeight-e.scrollTop-e.clientHeight<=48,ut=(e="smooth")=>globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches?"auto":e,Re=(e,s)=>{typeof e.scrollTo=="function"?e.scrollTo({top:e.scrollHeight,behavior:s}):e.scrollTop=e.scrollHeight},wt=({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(gs,{})}),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(At,{}),"重新发送"]}):null]}),Ns=({error:e,onRetry:s})=>{const a=os(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(At,{}),a.actionLabel]})]})},Tt=({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}`))})]})},Ms=({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(ds,{})}):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(ms,{})}):null,e?t.jsx("span",{className:"make-ai-assistant__reply-feedback","data-copy-status":e.status,role:"status",children:e.message}):null]}),pt=({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(kt,{assistantName:e}),t.jsx("div",{className:"make-ai-assistant__message-stack",children:s?t.jsx(wt,{error:s,onRetry:a}):t.jsx(Tt,{active:!0,steps:r?.steps})})]})}):null},Es=(e,s,a,r,n,i,c,p,v,f,w,T,S,M)=>{const _=bt(e),P=It(e),C=Is(e);let $;return e.messages.map(h=>{const A=h.role==="assistant",I=$;A||($=h);const Z=h.id===P,Q=h.id===_?e.error:void 0,W=h.error??Q,L=!A&&!!(v?.trim()||f),D=A?c:v?.trim()||"用户",j=A&&h.status==="complete"&&!W&&(h.content.trim()||h.id===C);return t.jsx("article",{"aria-label":`${D}的消息`,className:`make-ai-assistant__message make-ai-assistant__message--${h.role}`,"data-message-role":h.role,"data-message-state":W?"error":void 0,"data-message-status":h.status,"data-message-has-identity":A||L?!0:void 0,children:t.jsxs("div",{className:"make-ai-assistant__message-turn",children:[A?t.jsx(kt,{assistantName:c}):L?t.jsx(_s,{userAvatarUrl:f,userName:v}):null,t.jsxs("div",{className:"make-ai-assistant__message-stack",children:[h.content?A?t.jsx(As,{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,A?t.jsx(Tt,{active:Z&&e.status==="streaming",steps:h.progressSteps}):null,W?t.jsx(wt,{error:W,onRetry:Q?p:void 0}):null,h.artifacts.map(E=>t.jsx(ft,{artifact:E,context:s,onAction:n,onActionError:i,registry:a,theme:r},E.id)),j?t.jsx(Ms,{copyFeedback:w?.messageId===h.id?{message:w.message,status:w.status}:void 0,onCopy:h.content.trim()?()=>S(h.id,h.content):void 0,onRegenerate:T&&h.id===C&&I?()=>M({userMessage:I,assistantMessage:h}):void 0}):null]})]})},h.id)})};function Nt({assistantName:e="AI 助手",brandName:s,context:a,onAction:r,onActionError:n,onClose:i,onNewConversation:c,headerHeight:p,privacyNotice:v,registry:f,subtitle:w,suggestions:T,title:S,theme:M,transport:_,userAvatarUrl:P,userName:C,visible:$}){const h=jt(s,S),A=v?.trim(),I=ss(w,a.app.name),Z=rs(p),Q=Ce(M),W=Q||Z?{...Q,...Z?{"--make-ai-internal-header-height":Z}:{}}:void 0,[L,D]=l.useState(""),[j,E]=l.useState(m.createAssistantConversationState),z=l.useRef(j);z.current=j;const[J,V]=l.useState(void 0),[xe,u]=l.useState(void 0),[b,K]=l.useState(0),[H,_e]=l.useState(()=>_.loadConversation?"loading":"ready"),[Mt,Ne]=l.useState(void 0),[Et,U]=l.useState(!1),[ee,$e]=l.useState(!1),[le,Le]=l.useState(void 0),te=l.useRef(void 0),se=l.useRef(void 0),ae=l.useRef(0),Oe=l.useRef(null),de=l.useRef(null),Fe=l.useRef(null),Pe=l.useRef(null),De=l.useRef(null),Ve=l.useRef(null),q=l.useRef(!0),Ke=l.useRef(a.app.id),He=l.useRef($),Be=l.useId(),We=l.useMemo(()=>f??vt(),[f]),ze=l.useMemo(()=>es(T),[T]),Ue=()=>{const o=Pe.current,x=De.current;if(!o||!x||typeof window>"u")return;const g=ns(o.getBoundingClientRect(),x.getBoundingClientRect(),window.innerHeight,window.innerWidth);Le(y=>y?.left===g.left&&y.top===g.top&&y.placement===g.placement?y:g)},qe=()=>$e(!0),Xe=()=>$e(!1),St=le?{left:`${le.left}px`,top:`${le.top}px`}:void 0;l.useLayoutEffect(()=>{if(!ee||!A){Le(void 0);return}Ue()},[ee,A]),l.useEffect(()=>{if(!ee||!A)return;const o=()=>Ue();return window.addEventListener("resize",o),window.addEventListener("scroll",o,!0),()=>{window.removeEventListener("resize",o),window.removeEventListener("scroll",o,!0)}},[ee,A]);const ve=o=>{const x=te.current,g=se.current?.iterator;return!x&&!g?!1:(ae.current+=1,te.current=void 0,se.current=void 0,console.info("[make-ai-assistant] local run cancellation requested",{reason:o}),x?.abort(),mt(g),!0)};l.useEffect(()=>()=>{ve("unmount")},[]),l.useEffect(()=>{const o=_.loadConversation,x=Ke.current!==a.app.id;if(Ke.current=a.app.id,ve("reinitialize"),x&&(D(""),q.current=!0),V(void 0),u(void 0),U(!1),E(m.createAssistantConversationState()),!o){Ne(void 0),_e("ready");return}const g=new AbortController;return Ne(void 0),_e("loading"),console.info("[make-ai-assistant] conversation load start",{appId:a.app.id}),o.call(_,a,{signal:g.signal}).then(y=>{g.signal.aborted||(E(m.createAssistantConversationState(y)),_e("ready"),console.info("[make-ai-assistant] conversation load success",{appId:a.app.id,messageCount:y.messages.length}))}).catch(y=>{g.signal.aborted||(console.error("[make-ai-assistant] conversation load failed",{appId:a.app.id,errorType:y instanceof Error?y.name:typeof y}),Ne(y),_e("error"))}),()=>g.abort()},[a.app.id,b,_]),l.useEffect(()=>{const o=de.current;if(!o||!q.current)return;U(!1);const x=requestAnimationFrame(()=>{if(!q.current)return;const g=j.status==="streaming"||globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches?"auto":"smooth";Re(o,g)});return()=>cancelAnimationFrame(x)},[j.messages,j.progress,j.status]),l.useEffect(()=>{const o=$&&!He.current;if(He.current=$,!o)return;const x=requestAnimationFrame(()=>{const g=de.current;if(g&&q.current){U(!1);const me=z.current.status==="streaming"?"auto":ut();Re(g,me)}else g&&U(z.current.messages.length>0);const y=Fe.current;(y&&!y.disabled?y:Ve.current??Oe.current?.querySelector("button:not(:disabled)"))?.focus()});return()=>cancelAnimationFrame(x)},[$]);const Rt=()=>{const o=de.current;if(!o)return;const x=Ts(o);q.current=x,U(!x&&z.current.messages.length>0)},Ct=()=>{const o=de.current;if(!o)return;q.current=!0,U(!1);const x=ut();Re(o,x)},Ye=async(o,x)=>{const g=o.trim(),y=z.current,B=x?.regenerateFrom,me=_.regenerate;if(!g||H!=="ready"||y.status==="streaming"||te.current||B&&!me)return;if(m.countCodePointsUpTo(g,m.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)>m.MAKE_AI_CONVERSATION_LIMITS.messageCharacters){V(`输入内容过长,请控制在 ${m.MAKE_AI_CONVERSATION_LIMITS.messageCharacters} 个字符以内`);return}const Ae={id:B?.userMessage.id??Zt("user"),content:g},ke=B?ws(y,B.userMessage.id):m.appendUserMessage(y,Ae),Ie=new AbortController,ne=ae.current+1;ae.current=ne,te.current=Ie,V(void 0),u(void 0),U(!q.current&&y.messages.length>0),B||D(""),E(ke);try{let X=!1,N,Qe=0,Je=0,et=0,Me=0,ue=0;const pe=new Map,tt=new Set,st=new Set([...ke.messages.map(be=>be.id),Ae.id]),he=new Set,at=G.createArtifactCapabilities(We),nt={signal:Ie.signal};let Ee;if(B){if(!me)throw new k("当前 AI 助手不支持重新生成");Ee=me({threadId:ke.threadId,message:Ae,assistantMessage:{id:B.assistantMessage.id,content:B.assistantMessage.content},context:a,capabilities:at},nt)}else Ee=_.run({threadId:ke.threadId,message:Ae,context:a,capabilities:at},nt);const rt=Ee[Symbol.asyncIterator]();for(se.current={iterator:rt,requestVersion:ne};;){const be=await rt.next();if(ae.current!==ne||be.done)break;let d;try{d=m.parseAssistantEvent(be.value)}catch(R){throw new k(R instanceof Error?R.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,Je+=1,Je>m.MAKE_AI_CONVERSATION_LIMITS.assistantMessagesPerRun)throw new k("AI 助手单次响应消息数量超过限制");if(st.has(d.messageId))throw new k("AI 助手响应包含重复的 message id");st.add(d.messageId),he.add(d.messageId),pe.set(d.messageId,0)}if(d.type==="message.delta"){if(!he.has(d.messageId))throw new k("AI 助手响应事件顺序无效");const R=pe.get(d.messageId)??0,re=m.countCodePointsUpTo(d.delta,m.MAKE_AI_CONVERSATION_LIMITS.messageCharacters-ue);if(ue+re>m.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)throw new k("AI 助手响应文本超过大小限制");ue+=re,pe.set(d.messageId,R+re)}if(d.type==="message.replace"){if(!he.has(d.messageId))throw new k("AI 助手响应事件顺序无效");const R=pe.get(d.messageId)??0,re=m.countCodePointsUpTo(d.content,m.MAKE_AI_CONVERSATION_LIMITS.messageCharacters),it=ue-R+re;if(it>m.MAKE_AI_CONVERSATION_LIMITS.messageCharacters)throw new k("AI 助手响应文本超过大小限制");ue=it,pe.set(d.messageId,re)}if(d.type==="run.progress"){if(N!==void 0&&N!==d.runId)throw new k("AI 助手响应 run id 不一致");if(N??=d.runId,et+=1,et>m.MAKE_AI_CONVERSATION_LIMITS.progressStepsPerRun)throw new k("AI 助手处理过程数量超过限制");const R=m.countCodePointsUpTo(d.message,m.MAKE_AI_CONVERSATION_LIMITS.progressCharactersPerRun-Me);if(Me+R>m.MAKE_AI_CONVERSATION_LIMITS.progressCharactersPerRun)throw new k("AI 助手处理过程文本超过大小限制");Me+=R}if(d.type==="artifact"){if(!he.has(d.messageId))throw new k("AI 助手响应事件顺序无效");if(Qe+=1,Qe>m.MAKE_AI_CONVERSATION_LIMITS.artifactsPerRun)throw new k("AI 助手单次响应 Artifact 数量超过限制");if(tt.has(d.artifact.id))throw new k("AI 助手响应包含重复的 Artifact id");tt.add(d.artifact.id)}if(d.type==="message.complete"&&!he.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(E(R=>m.reduceAssistantEvent(R,d)),d.type==="error"||d.type==="run.cancelled"||d.type==="run.complete"){X=!0;break}}if(!X)throw new k("AI 助手流式响应在终止事件前结束")}catch(X){if(ae.current!==ne)return;if(Ie.signal.aborted){E(N=>m.reduceAssistantEvent(N,{type:"run.cancelled"}));return}console.error("[make-ai-assistant] assistant run failed",{appId:a.app.id,errorType:X instanceof Error?X.name:typeof X}),E(N=>m.reduceAssistantEvent(N,{type:"error",code:"TRANSPORT_ERROR",message:X instanceof k?X.message:"连接失败,请重试",retryable:!0}))}finally{ae.current===ne&&te.current===Ie&&(te.current=void 0),se.current?.requestVersion===ne&&(mt(se.current.iterator),se.current=void 0)}},je=o=>Ye(o),$t=o=>Ye(o.userMessage.content,{regenerateFrom:o}),Lt=async(o,x)=>{try{await cs(x),u({messageId:o,message:"已复制",status:"success"})}catch(g){console.error("[make-ai-assistant] copy answer failed",{errorType:g instanceof Error?g.name:typeof g}),u({messageId:o,message:"复制失败",status:"error"})}},Ot=o=>{o.preventDefault(),je(L)},Ft=o=>{o.key==="Enter"&&!o.shiftKey&&!o.nativeEvent.isComposing&&(o.preventDefault(),je(L))},Pt=()=>{ve("stop")&&E(o=>m.reduceAssistantEvent(o,{type:"run.cancelled"}))},Dt=()=>{ve("new-conversation"),D(""),V(void 0),u(void 0),U(!1),q.current=!0,E(m.createAssistantConversationState()),c?.()},Ge=_.features?.remoteCancellation===!1?"停止接收":"停止生成",Vt=It(j),Kt=bt(j),ye=bs(j),Ht=typeof _.regenerate=="function"&&_.features?.regeneration!==!1,Ze=()=>{ye&&je(ye.content)};return t.jsxs("section",{className:"make-ai-assistant make-ai-assistant__panel",ref:Oe,style:W,children:[t.jsxs("header",{className:"make-ai-assistant__header",children:[t.jsx(Te,{}),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:I,children:I}),A?t.jsxs(t.Fragment,{children:[t.jsx("span",{"aria-describedby":Be,"aria-label":`使用提示:${A}`,className:"make-ai-assistant__header-context-help","data-tooltip":A,ref:Pe,role:"note",tabIndex:0,onBlur:Xe,onFocus:qe,onPointerEnter:qe,onPointerLeave:Xe,children:t.jsx(us,{})}),t.jsx("span",{"aria-hidden":!ee,className:"make-ai-assistant__header-context-tooltip","data-placement":le?.placement,"data-positioned":le?!0:void 0,"data-visible":ee||void 0,id:Be,ref:De,role:"tooltip",style:St,children:A})]}):null]})]}),t.jsxs("div",{className:"make-ai-assistant__header-actions",children:[_.features?.newConversation!==!1?t.jsx("button",{"aria-label":"新建对话",className:"make-ai-assistant__icon-button",type:"button",onClick:Dt,children:t.jsx(hs,{})}):null,i?t.jsx("button",{"aria-label":`关闭 ${h}`,className:"make-ai-assistant__icon-button",type:"button",onClick:i,children:t.jsx(ls,{})}):null]})]}),t.jsxs("div",{className:"make-ai-assistant__body","aria-live":"polite","aria-relevant":"additions text",ref:de,role:"log",onScroll:Rt,children:[H==="loading"?t.jsxs("div",{className:"make-ai-assistant__empty",role:"status",children:[t.jsx(Te,{}),t.jsx("h3",{children:"正在恢复对话"}),t.jsx("p",{children:"正在读取当前 App 的历史消息…"})]}):H==="error"?t.jsx("div",{className:"make-ai-assistant__empty",children:t.jsx(Ns,{error:Mt,onRetry:()=>K(o=>o+1)})}):j.messages.length===0?t.jsxs("div",{className:"make-ai-assistant__empty",children:[t.jsx(Te,{}),t.jsx("h3",{children:"有什么可以帮你?"}),t.jsx("p",{children:"我会结合当前 App、页面位置和宿主允许的上下文回答,并把过程与结果分开展示。"})]}):Es(j,a,We,M,r,n,e,ye?Ze:void 0,C,P,xe,Ht,(o,x)=>{Lt(o,x)},o=>{$t(o)}),j.progress&&!Vt?t.jsx(pt,{assistantName:e,progress:j.progress}):null,j.error&&!Kt?t.jsx(pt,{assistantName:e,error:j.error,onRetry:ye?Ze:void 0}):null]}),Et?t.jsx("button",{"aria-label":"回到最新消息",className:"make-ai-assistant__back-to-latest",type:"button",onClick:Ct,children:t.jsx(ps,{})}):null,t.jsxs("footer",{className:"make-ai-assistant__composer-region",children:[H==="ready"&&ze.length>0&&j.messages.length===0?t.jsx("div",{className:"make-ai-assistant__suggestions","aria-label":"推荐问题",children:ze.map((o,x)=>t.jsx("button",{type:"button",onClick:()=>{je(o)},children:o},`${x}-${o}`))}):null,t.jsxs("form",{className:"make-ai-assistant__composer",onSubmit:Ot,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:H!=="ready"||j.status==="streaming",placeholder:`询问当前 ${a.app.name??"App"} 中的数据…`,ref:Fe,rows:2,value:L,onChange:o=>{D(o.currentTarget.value),V(void 0)},onKeyDown:Ft}),j.status==="streaming"?t.jsx("button",{"aria-label":Ge,className:"make-ai-assistant__send make-ai-assistant__send--stop","data-tooltip":Ge,ref:Ve,type:"button",onClick:Pt,children:t.jsx("span",{"aria-hidden":"true"})}):t.jsx("button",{"aria-label":"发送",className:"make-ai-assistant__send",disabled:H!=="ready"||!L.trim(),type:"submit",children:t.jsx(fs,{})})]}),J?t.jsx("p",{id:"make-ai-composer-error",role:"alert",children:J}):null,t.jsx("p",{children:"AI 生成的结果可能存在偏差,重要数据请核对明细。"})]})]})}function Ss(e){return t.jsx(Nt,{...e,visible:!0})}function Rs({defaultOpen:e=!1,hideLauncher:s=!1,launcher:a,onOpenChange:r,open:n,...i}){const c=jt(i.brandName,i.title),[p,v]=l.useState(e),[f,w]=l.useState(()=>e||n===!0),T=l.useRef(null),S=l.useRef(null),M=l.useRef(void 0),[_,P]=l.useState(),[C,$]=l.useState(as),[h,A]=l.useState(!1),I=n??p,Z=Ce(i.theme),Q=typeof window>"u"?void 0:window.innerWidth,W=_===void 0?void 0:{"--make-ai-internal-drawer-width":`${_}px`},L=()=>{if(_!==void 0)return _;const u=S.current?.getBoundingClientRect().width;return u&&Number.isFinite(u)&&u>0?u:C},D=()=>typeof window>"u"?Number.POSITIVE_INFINITY:window.innerWidth,j=u=>{if(u.button!==0)return;const b=L(),K=_===void 0?b:C;$(K),M.current={minimumWidth:K,pointerId:u.pointerId,startWidth:b,startX:u.clientX},A(!0),typeof u.currentTarget.setPointerCapture=="function"&&u.currentTarget.setPointerCapture(u.pointerId),u.preventDefault()},E=u=>{const b=M.current;if(!b||b.pointerId!==u.pointerId)return;const K=lt(b.startWidth+b.startX-u.clientX,b.minimumWidth,D());P(K)},z=u=>{const b=M.current;!b||b.pointerId!==u.pointerId||(M.current=void 0,A(!1))},J=u=>{const b=u.key==="ArrowLeft"?ct:u.key==="ArrowRight"?-ct:void 0;if(b===void 0)return;u.preventDefault();const K=L(),H=_===void 0?K:C;$(H),P(lt(K+b,H,D()))},V=u=>{n===void 0&&v(u),r?.(u),u||requestAnimationFrame(()=>T.current?.focus())},xe=()=>V(!I);return l.useEffect(()=>{I&&w(!0)},[I]),l.useEffect(()=>{if(!I)return;const u=b=>{b.key==="Escape"&&(V(!1),requestAnimationFrame(()=>T.current?.focus()))};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[r,I]),t.jsxs("div",{className:"make-ai-assistant","data-open":I||void 0,style:Z,children:[!s&&(!I||a)?a?a({open:I,toggle:xe}):t.jsxs("button",{"aria-label":I?`关闭 ${c}`:`打开 ${c}`,"aria-expanded":I,className:"make-ai-assistant__launcher",ref:T,type:"button",onClick:xe,children:[t.jsx("span",{className:"make-ai-assistant__launcher-orbit","aria-hidden":"true"}),t.jsx(yt,{})]}):null,f?t.jsxs("aside",{"aria-label":c,"aria-modal":"false",className:"make-ai-assistant__drawer","data-resizing":h||void 0,hidden:!I,ref:S,role:"dialog",style:W,children:[t.jsx("div",{"aria-label":"调整对话框宽度","aria-orientation":"vertical","aria-valuemax":Q,"aria-valuemin":C,"aria-valuenow":_??C,className:"make-ai-assistant__drawer-resize-handle",role:"separator",tabIndex:0,onKeyDown:J,onPointerCancel:z,onPointerDown:j,onPointerMove:E,onPointerUp:z}),t.jsx(Nt,{...i,onClose:()=>V(!1),visible:I})]}):null]})}exports.createArtifactCapabilities=G.createArtifactCapabilities;exports.createArtifactTemplateRegistry=G.createArtifactTemplateRegistry;exports.extendArtifactTemplateRegistry=G.extendArtifactTemplateRegistry;exports.resolveArtifactTemplate=G.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=ft;exports.AssistantPanel=Ss;exports.MakeAiAssistant=Rs;exports.createPlatformArtifactRegistry=vt;exports.formatArtifactValue=Y;exports.platformArtifactTemplates=_t;
|