@axiom-lattice/react-sdk 1.0.11 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -16,12 +18,31 @@ var __copyProps = (to, from, except, desc) => {
16
18
  return to;
17
19
  };
18
20
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
19
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
30
 
21
31
  // src/index.ts
22
32
  var index_exports = {};
23
33
  __export(index_exports, {
24
34
  AxiomLatticeProvider: () => AxiomLatticeProvider,
35
+ Chating: () => Chating,
36
+ MDMermaid: () => MDMermaid,
37
+ MDResponse: () => MDResponse,
38
+ MDViewFormItem: () => MDViewFormItem,
39
+ SideAppViewBrowser: () => SideAppViewBrowser,
40
+ ThinkingChain: () => ThinkingChain,
41
+ ThinkingChainGroup: () => ThinkingChainGroup,
42
+ chatContext: () => chatContext,
43
+ elements: () => elements,
44
+ getElement: () => getElement,
45
+ regsiterElement: () => regsiterElement,
25
46
  useAgentGraph: () => useAgentGraph,
26
47
  useAgentState: () => useAgentState,
27
48
  useAxiomLattice: () => useAxiomLattice,
@@ -74,10 +95,28 @@ function useChat(threadId, options = {}) {
74
95
  messages: options.initialMessages || [],
75
96
  isLoading: false,
76
97
  error: null,
77
- streamingMessage: null
98
+ streamingMessage: null,
99
+ ...options.enableReturnStateWhenStreamCompleted ? { agentState: null } : {}
78
100
  });
79
101
  const stopStreamingRef = (0, import_react2.useRef)(null);
80
102
  const chunkMessageMerger = (0, import_react2.useRef)((0, import_client_sdk2.createSimpleMessageMerger)());
103
+ const fetchAndUpdateAgentState = (0, import_react2.useCallback)(
104
+ async (threadId2) => {
105
+ if (!options.enableReturnStateWhenStreamCompleted) return;
106
+ try {
107
+ const agentState = await client.getAgentState(threadId2);
108
+ setState(
109
+ (prev) => ({
110
+ ...prev,
111
+ agentState
112
+ })
113
+ );
114
+ } catch (error) {
115
+ console.warn("Failed to fetch agent state:", error);
116
+ }
117
+ },
118
+ [client, options.enableReturnStateWhenStreamCompleted]
119
+ );
81
120
  (0, import_react2.useEffect)(() => {
82
121
  if (options.initialMessages && options.initialMessages.length > 0) {
83
122
  chunkMessageMerger.current.initialMessages(options.initialMessages);
@@ -89,7 +128,7 @@ function useChat(threadId, options = {}) {
89
128
  setState((prev) => ({
90
129
  ...prev,
91
130
  messages: updatedMessages,
92
- isLoading: false,
131
+ isLoading: true,
93
132
  streamingMessage: null
94
133
  }));
95
134
  }, []);
@@ -103,7 +142,7 @@ function useChat(threadId, options = {}) {
103
142
  stopStreamingRef.current = null;
104
143
  }
105
144
  const { input, command, streaming = true } = data;
106
- const { message, files } = input || {};
145
+ const { message: message2, files, ...rest } = input || {};
107
146
  setState((prev) => ({
108
147
  ...prev,
109
148
  isLoading: true,
@@ -112,7 +151,7 @@ function useChat(threadId, options = {}) {
112
151
  }));
113
152
  const userMessage = {
114
153
  id: Date.now().toString(),
115
- content: message || command?.resume?.message || "",
154
+ content: message2 || command?.resume?.message || "",
116
155
  files,
117
156
  role: "human"
118
157
  };
@@ -132,11 +171,19 @@ function useChat(threadId, options = {}) {
132
171
  const stopStreaming2 = client.chat.stream(
133
172
  {
134
173
  threadId,
135
- messages: [userMessage]
136
- // Cast to any to avoid type conflicts
174
+ messages: [userMessage],
175
+ command,
176
+ ...rest
137
177
  },
138
178
  (chunk) => handleStreamEvent(chunk),
139
- () => {
179
+ async () => {
180
+ setState((prev) => ({
181
+ ...prev,
182
+ isLoading: false
183
+ }));
184
+ if (options.enableReturnStateWhenStreamCompleted) {
185
+ await fetchAndUpdateAgentState(threadId);
186
+ }
140
187
  stopStreamingRef.current = null;
141
188
  },
142
189
  (error) => {
@@ -153,24 +200,14 @@ function useChat(threadId, options = {}) {
153
200
  } else {
154
201
  const response = await client.chat.send({
155
202
  threadId,
156
- messages: [userMessage]
157
- // Cast to any to avoid type conflicts
158
- });
159
- chunkMessageMerger.current.push({
160
- type: "ai",
161
- data: {
162
- id: response.message.id || `assistant-${Date.now()}`,
163
- content: response.message.content || ""
164
- }
203
+ messages: [userMessage],
204
+ command,
205
+ ...rest
165
206
  });
207
+ chunkMessageMerger.current.initialMessages(response.messages);
166
208
  setState((prev) => ({
167
209
  ...prev,
168
- messages: chunkMessageMerger.current.getMessages().map((msg) => ({
169
- id: msg.id,
170
- role: msg.role === "ai" ? "assistant" : msg.role === "human" ? "user" : msg.role === "system" ? "system" : "tool",
171
- content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content || ""),
172
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
173
- })),
210
+ messages: chunkMessageMerger.current.getMessages(),
174
211
  isLoading: false
175
212
  }));
176
213
  }
@@ -182,7 +219,14 @@ function useChat(threadId, options = {}) {
182
219
  }));
183
220
  }
184
221
  },
185
- [client, threadId, options.streaming, handleStreamEvent]
222
+ [
223
+ client,
224
+ threadId,
225
+ options.streaming,
226
+ options.enableReturnStateWhenStreamCompleted,
227
+ handleStreamEvent,
228
+ fetchAndUpdateAgentState
229
+ ]
186
230
  );
187
231
  const stopStreaming = (0, import_react2.useCallback)(() => {
188
232
  if (stopStreamingRef.current) {
@@ -207,6 +251,10 @@ function useChat(threadId, options = {}) {
207
251
  if (!threadId) {
208
252
  return;
209
253
  }
254
+ if (stopStreamingRef.current) {
255
+ stopStreamingRef.current();
256
+ stopStreamingRef.current = null;
257
+ }
210
258
  setState((prev) => ({ ...prev, isLoading: true, error: null }));
211
259
  try {
212
260
  const fetchedMessages = await client.getMessages({
@@ -220,6 +268,35 @@ function useChat(threadId, options = {}) {
220
268
  messages: chunkMessageMerger.current.getMessages(),
221
269
  isLoading: false
222
270
  }));
271
+ if (options.enableResumeStream && fetchedMessages.length > 0) {
272
+ const lastMessage = fetchedMessages[fetchedMessages.length - 1];
273
+ const lastContent = typeof lastMessage.content === "string" ? lastMessage.content : JSON.stringify(lastMessage.content || "");
274
+ const stopResumeStream = client.resumeStream(
275
+ {
276
+ threadId,
277
+ messageId: lastMessage.id,
278
+ knownContent: lastContent,
279
+ pollInterval: options.resumeStreamPollInterval || 100
280
+ },
281
+ handleStreamEvent,
282
+ () => {
283
+ setState((prev) => ({
284
+ ...prev,
285
+ isLoading: false
286
+ }));
287
+ stopStreamingRef.current = null;
288
+ },
289
+ (error) => {
290
+ console.error("Resume stream error:", error);
291
+ setState((prev) => ({
292
+ ...prev,
293
+ error
294
+ }));
295
+ stopStreamingRef.current = null;
296
+ }
297
+ );
298
+ stopStreamingRef.current = stopResumeStream;
299
+ }
223
300
  } catch (error) {
224
301
  setState((prev) => ({
225
302
  ...prev,
@@ -228,7 +305,13 @@ function useChat(threadId, options = {}) {
228
305
  }));
229
306
  }
230
307
  },
231
- [client, threadId]
308
+ [
309
+ client,
310
+ threadId,
311
+ options.enableResumeStream,
312
+ options.resumeStreamPollInterval,
313
+ handleStreamEvent
314
+ ]
232
315
  );
233
316
  const clearMessages = (0, import_react2.useCallback)(() => {
234
317
  chunkMessageMerger.current.reset();
@@ -497,9 +580,1658 @@ function useAgentGraph() {
497
580
 
498
581
  // src/index.ts
499
582
  __reExport(index_exports, require("@axiom-lattice/protocols"), module.exports);
583
+
584
+ // src/components/GenUI/MDResponse.tsx
585
+ var import_react_markdown = __toESM(require("react-markdown"));
586
+ var import_react_syntax_highlighter = require("react-syntax-highlighter");
587
+ var import_prism = require("react-syntax-highlighter/dist/cjs/styles/prism");
588
+ var import_remark_gfm = __toESM(require("remark-gfm"));
589
+ var import_react9 = require("react");
590
+ var import_antd_style4 = require("antd-style");
591
+ var import_rehype_raw = __toESM(require("rehype-raw"));
592
+
593
+ // src/components/GenUI/elements/confirm_feedback.tsx
594
+ var import_antd = require("antd");
595
+ var import_react6 = require("react");
596
+ var import_antd_style = require("antd-style");
597
+ var import_jsx_runtime2 = require("react/jsx-runtime");
598
+ var { Text } = import_antd.Typography;
599
+ var useStyle = (0, import_antd_style.createStyles)(({ token, css }) => ({
600
+ card: css`
601
+ max-width: 1200px;
602
+ background: linear-gradient(
603
+ 919deg,
604
+ rgb(232 67 157 / 8%),
605
+ rgb(250 235 206 / 28%) 43%
606
+ );
607
+ `
608
+ }));
609
+ var ConfirmFeedback = ({
610
+ data,
611
+ eventHandler,
612
+ interactive = true
613
+ }) => {
614
+ const { message: message2, type, config, feedback, options } = data ?? {};
615
+ const [clicked, setClicked] = (0, import_react6.useState)(false);
616
+ const { styles } = useStyle();
617
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_antd.Card, { size: "small", className: `shadow-sm ${styles.card}`, bordered: false, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_antd.Space, { direction: "vertical", style: { width: "100%" }, children: [
618
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
619
+ import_antd.Tag,
620
+ {
621
+ bordered: false,
622
+ color: "orange",
623
+ style: {
624
+ fontSize: 14,
625
+ fontWeight: "bold",
626
+ background: "#ffffff8f",
627
+ padding: 4,
628
+ borderRadius: 8
629
+ },
630
+ children: "\u8BF7\u6C42\u786E\u8BA4"
631
+ }
632
+ ),
633
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MDResponse, { content: message2 }),
634
+ options ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_antd.Space, { style: { justifyContent: "flex-end", width: "100%" }, children: options?.map((option) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
635
+ import_antd.Button,
636
+ {
637
+ title: option.description,
638
+ disabled: !interactive || clicked || feedback,
639
+ style: {
640
+ border: feedback?.data?.action === option.value ? "2px dashed rgb(74 73 77)" : "none"
641
+ },
642
+ onClick: () => {
643
+ setClicked(true);
644
+ eventHandler(
645
+ "confirm_feedback",
646
+ { action: option.value, config },
647
+ option.label
648
+ );
649
+ },
650
+ children: option.label
651
+ },
652
+ option.value
653
+ )) }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_antd.Space, { style: { justifyContent: "flex-end", width: "100%" }, children: [
654
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
655
+ import_antd.Button,
656
+ {
657
+ disabled: !interactive || clicked || feedback,
658
+ style: {
659
+ border: feedback?.data?.action === "yes" ? "2px dashed rgb(74 73 77)" : "none"
660
+ },
661
+ type: "primary",
662
+ onClick: () => {
663
+ setClicked(true);
664
+ eventHandler(
665
+ "confirm_feedback",
666
+ {
667
+ action: "yes",
668
+ config
669
+ },
670
+ "\u786E\u8BA4"
671
+ );
672
+ },
673
+ children: "\u786E\u8BA4"
674
+ }
675
+ ),
676
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
677
+ import_antd.Button,
678
+ {
679
+ disabled: !interactive || clicked || feedback,
680
+ type: "default",
681
+ style: {
682
+ border: feedback?.data?.action === "no" ? "2px dashed rgb(74 73 77)" : "none"
683
+ },
684
+ onClick: () => {
685
+ setClicked(true);
686
+ eventHandler(
687
+ "confirm_feedback",
688
+ {
689
+ action: "no",
690
+ config
691
+ },
692
+ "\u62D2\u7EDD"
693
+ );
694
+ },
695
+ children: "\u62D2\u7EDD"
696
+ }
697
+ )
698
+ ] })
699
+ ] }) });
700
+ };
701
+
702
+ // src/components/GenUI/elements/generic_data_table.tsx
703
+ var import_antd2 = require("antd");
704
+ var import_react7 = require("react");
705
+ var import_icons = require("@ant-design/icons");
706
+ var import_jsx_runtime3 = require("react/jsx-runtime");
707
+ var { Text: Text2 } = import_antd2.Typography;
708
+ var GenericDataTable = ({
709
+ data,
710
+ eventHandler,
711
+ interactive = true,
712
+ default_open_in_side_app = true
713
+ }) => {
714
+ const { dataSource, message: message2 } = data ?? {};
715
+ const [expandedRowKeys, setExpandedRowKeys] = (0, import_react7.useState)([]);
716
+ const processedData = dataSource?.map((item, index) => ({
717
+ ...item,
718
+ key: `${index}_${JSON.stringify(item).slice(0, 20)}`
719
+ })) || [];
720
+ const generateColumns = (dataItem) => {
721
+ if (!dataItem || typeof dataItem !== "object") {
722
+ return [];
723
+ }
724
+ return Object.keys(dataItem).filter((key) => key !== "key" && key !== "expandItem").map((key) => ({
725
+ title: formatColumnTitle(key),
726
+ dataIndex: key,
727
+ key,
728
+ width: 150,
729
+ sorter: (a, b) => {
730
+ const aVal = a[key];
731
+ const bVal = b[key];
732
+ if (aVal === null || aVal === void 0) return 1;
733
+ if (bVal === null || bVal === void 0) return -1;
734
+ if (typeof aVal === "number" && typeof bVal === "number") {
735
+ return aVal - bVal;
736
+ }
737
+ const aDate = new Date(aVal);
738
+ const bDate = new Date(bVal);
739
+ if (!isNaN(aDate.getTime()) && !isNaN(bDate.getTime())) {
740
+ return aDate.getTime() - bDate.getTime();
741
+ }
742
+ return String(aVal).localeCompare(String(bVal), "zh-CN");
743
+ },
744
+ render: (value) => {
745
+ if (value === null || value === void 0) {
746
+ return "-";
747
+ }
748
+ if (typeof value === "object") {
749
+ return JSON.stringify(value);
750
+ }
751
+ return String(value);
752
+ }
753
+ }));
754
+ };
755
+ const formatColumnTitle = (key) => {
756
+ return key.replace(/([A-Z])/g, " $1").replace(/_/g, " ").replace(/^./, (str) => str.toUpperCase()).trim();
757
+ };
758
+ const columns = processedData.length > 0 ? generateColumns(processedData[0]) : [];
759
+ const expandedRowRender = (record) => {
760
+ const expandItem = record.expandItem;
761
+ if (!expandItem) {
762
+ return null;
763
+ }
764
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { padding: "16px" }, children: [
765
+ expandItem.content && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { marginBottom: "16px" }, children: [
766
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text2, { strong: true, style: { display: "block", marginBottom: "8px" }, children: "\u8BE6\u7EC6\u4FE1\u606F:" }),
767
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MDResponse, { content: expandItem.content })
768
+ ] }),
769
+ expandItem.dataSource && expandItem.dataSource.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { children: [
770
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text2, { strong: true, style: { display: "block", marginBottom: "8px" }, children: "\u5B50\u8868\u6570\u636E:" }),
771
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
772
+ GenericDataTable,
773
+ {
774
+ component_key: `nested_${record.key}`,
775
+ data: {
776
+ dataSource: expandItem.dataSource,
777
+ message: void 0
778
+ },
779
+ eventHandler,
780
+ interactive
781
+ }
782
+ )
783
+ ] })
784
+ ] });
785
+ };
786
+ const exportToExcel = () => {
787
+ if (!processedData || processedData.length === 0) return;
788
+ console.warn("Export to Excel not implemented in SDK yet (requires xlsx dependency)");
789
+ };
790
+ const hasExpandableRows = processedData.some((item) => item.expandItem);
791
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
792
+ import_antd2.Table,
793
+ {
794
+ size: "small",
795
+ title: () => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_antd2.Flex, { justify: "space-between", align: "center", children: [
796
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Space, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Text2, { strong: true, style: { fontSize: 16 }, children: message2 || "" }) }),
797
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_antd2.Space, { children: [
798
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
799
+ import_antd2.Button,
800
+ {
801
+ type: "text",
802
+ size: "small",
803
+ icon: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons.DownloadOutlined, {}),
804
+ onClick: exportToExcel,
805
+ disabled: !processedData || processedData.length === 0,
806
+ children: "\u5BFC\u51FAExcel"
807
+ }
808
+ ),
809
+ eventHandler && default_open_in_side_app && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
810
+ import_antd2.Button,
811
+ {
812
+ type: "link",
813
+ size: "small",
814
+ onClick: () => {
815
+ eventHandler(
816
+ "__open_side_app",
817
+ {
818
+ component_key: "generic_data_table",
819
+ message: message2 || "",
820
+ data: { dataSource, message: message2 },
821
+ size: "large"
822
+ },
823
+ ""
824
+ );
825
+ },
826
+ children: [
827
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons.ExpandAltOutlined, {}),
828
+ "\u5C55\u5F00"
829
+ ]
830
+ }
831
+ )
832
+ ] })
833
+ ] }),
834
+ dataSource: processedData,
835
+ columns,
836
+ pagination: {
837
+ pageSize: 10,
838
+ showSizeChanger: true,
839
+ showQuickJumper: true,
840
+ showTotal: (total, range) => `\u7B2C ${range[0]}-${range[1]} \u6761/\u5171 ${total} \u6761`
841
+ },
842
+ scroll: { x: "max-content" },
843
+ expandable: hasExpandableRows ? {
844
+ expandedRowRender,
845
+ expandedRowKeys,
846
+ onExpandedRowsChange: (keys) => setExpandedRowKeys(keys),
847
+ rowExpandable: (record) => !!record.expandItem
848
+ } : void 0,
849
+ rowKey: "key",
850
+ bordered: true
851
+ }
852
+ );
853
+ };
854
+
855
+ // src/components/GenUI/elements/generic_data_table_side_app.tsx
856
+ var import_jsx_runtime4 = require("react/jsx-runtime");
857
+ var GenericDataTableSideApp = (props) => {
858
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(GenericDataTable, { ...props, default_open_in_side_app: false });
859
+ };
860
+
861
+ // src/components/GenUI/elements/ToolCall.tsx
862
+ var import_antd4 = require("antd");
863
+ var import_CollapsePanel = __toESM(require("antd/es/collapse/CollapsePanel"));
864
+ var import_icons3 = require("@ant-design/icons");
865
+
866
+ // src/components/GenUI/elements/ToolCard.tsx
867
+ var import_antd3 = require("antd");
868
+ var import_antd_style2 = require("antd-style");
869
+ var import_icons2 = require("@ant-design/icons");
870
+ var import_jsx_runtime5 = require("react/jsx-runtime");
871
+ var { Text: Text3, Title } = import_antd3.Typography;
872
+ var useStyle2 = (0, import_antd_style2.createStyles)(({ token, css }) => ({
873
+ card: css`
874
+ max-width: 500px;
875
+ background: linear-gradient(
876
+ 135deg,
877
+ rgba(24, 144, 255, 0.05) 0%,
878
+ rgba(135, 208, 104, 0.05) 100%
879
+ );
880
+ border: 1px solid ${token.colorBorderSecondary};
881
+ border-radius: 12px;
882
+ transition: all 0.3s ease;
883
+ &:hover {
884
+ border-color: ${token.colorPrimary};
885
+ box-shadow: 0 4px 12px rgba(24, 144, 255, 0.15);
886
+ transform: translateY(-2px);
887
+ }
888
+ `,
889
+ header: css`
890
+ border-bottom: 1px solid ${token.colorBorderSecondary};
891
+ margin-bottom: 12px;
892
+ padding-bottom: 8px;
893
+ `,
894
+ toolName: css`
895
+ color: ${token.colorPrimary};
896
+ font-weight: 600;
897
+ font-size: 16px;
898
+ `,
899
+ parameterGrid: css`
900
+ display: grid;
901
+ gap: 8px;
902
+ margin-top: 8px;
903
+ `,
904
+ parameterItem: css`
905
+ background: ${token.colorBgContainer};
906
+ border: 1px solid ${token.colorBorderSecondary};
907
+ border-radius: 6px;
908
+ padding: 8px 12px;
909
+ transition: background-color 0.2s ease;
910
+ &:hover {
911
+ background: ${token.colorBgTextHover};
912
+ }
913
+ `,
914
+ parameterName: css`
915
+ color: ${token.colorTextSecondary};
916
+ font-size: 12px;
917
+ font-weight: 500;
918
+ margin-bottom: 4px;
919
+ `,
920
+ parameterValue: css`
921
+ color: ${token.colorText};
922
+ font-family: "SF Mono", "Monaco", "Inconsolata", "Roboto Mono", monospace;
923
+ font-size: 13px;
924
+ word-break: break-all;
925
+ line-height: 1.4;
926
+ `,
927
+ typeTag: css`
928
+ font-size: 10px;
929
+ border-radius: 4px;
930
+ margin-left: 8px;
931
+ `
932
+ }));
933
+ var ToolCard = ({
934
+ data,
935
+ component_key,
936
+ eventHandler,
937
+ interactive = true
938
+ }) => {
939
+ const { styles } = useStyle2();
940
+ if (!data || !data.name) {
941
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_antd3.Card, { size: "small", className: styles.card, bordered: false, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text3, { type: "secondary", children: "Invalid tool data" }) });
942
+ }
943
+ const formatToolName = (name) => {
944
+ return name.replace(/([a-z])([A-Z])/g, "$1 $2").split(/[_-]/).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
945
+ };
946
+ const formatParameterValue = (value) => {
947
+ if (value === null || value === void 0) {
948
+ return "null";
949
+ }
950
+ if (typeof value === "object") {
951
+ try {
952
+ const jsonStr = JSON.stringify(value, null, 2);
953
+ return jsonStr.length > 100 ? JSON.stringify(value) : jsonStr;
954
+ } catch {
955
+ return String(value);
956
+ }
957
+ }
958
+ if (typeof value === "string" && value.length > 150) {
959
+ return value.substring(0, 150) + "...";
960
+ }
961
+ return String(value);
962
+ };
963
+ const getTypeColor = (value) => {
964
+ const type = typeof value;
965
+ switch (type) {
966
+ case "string":
967
+ return "blue";
968
+ case "number":
969
+ return "green";
970
+ case "boolean":
971
+ return "orange";
972
+ case "object":
973
+ return value === null ? "default" : "purple";
974
+ default:
975
+ return "default";
976
+ }
977
+ };
978
+ const getTypeLabel = (value) => {
979
+ if (value === null) return "null";
980
+ if (Array.isArray(value)) return "array";
981
+ return typeof value;
982
+ };
983
+ const hasParameters = data.parameters && Object.keys(data.parameters).length > 0;
984
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
985
+ import_antd3.Card,
986
+ {
987
+ size: "small",
988
+ className: styles.card,
989
+ bordered: false,
990
+ bodyStyle: { padding: "16px" },
991
+ children: [
992
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: styles.header, children: [
993
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_antd3.Space, { align: "center", children: [
994
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_icons2.ToolOutlined, { style: { color: "#1890ff", fontSize: "18px" } }),
995
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Title, { level: 5, className: styles.toolName, style: { margin: 0 }, children: formatToolName(data.name) }),
996
+ data.type && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_antd3.Tag, { color: "blue", className: styles.typeTag, children: data.type })
997
+ ] }),
998
+ data.description && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
999
+ Text3,
1000
+ {
1001
+ type: "secondary",
1002
+ style: { fontSize: "13px", marginTop: "4px", display: "block" },
1003
+ children: data.description
1004
+ }
1005
+ )
1006
+ ] }),
1007
+ hasParameters ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1008
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_antd3.Space, { align: "center", style: { marginBottom: "12px" }, children: [
1009
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_icons2.CodeOutlined, { style: { color: "#52c41a", fontSize: "14px" } }),
1010
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(Text3, { strong: true, style: { fontSize: "14px" }, children: [
1011
+ "Parameters (",
1012
+ Object.keys(data.parameters).length,
1013
+ ")"
1014
+ ] })
1015
+ ] }),
1016
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: styles.parameterGrid, children: Object.entries(data.parameters).map(([key, value], index) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: styles.parameterItem, children: [
1017
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: styles.parameterName, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_antd3.Space, { align: "center", children: [
1018
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: key }),
1019
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1020
+ import_antd3.Tag,
1021
+ {
1022
+ color: getTypeColor(value),
1023
+ style: { fontSize: "10px", marginLeft: "auto" },
1024
+ children: getTypeLabel(value)
1025
+ }
1026
+ )
1027
+ ] }) }),
1028
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: styles.parameterValue, children: formatParameterValue(value) })
1029
+ ] }, index)) })
1030
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_antd3.Space, { align: "center", children: [
1031
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_icons2.CodeOutlined, { style: { color: "#d9d9d9", fontSize: "14px" } }),
1032
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Text3, { type: "secondary", style: { fontSize: "13px" }, children: "No parameters" })
1033
+ ] })
1034
+ ]
1035
+ }
1036
+ );
1037
+ };
1038
+
1039
+ // src/components/GenUI/elements/ToolCall.tsx
1040
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1041
+ function getStatusIcon(status) {
1042
+ switch (status) {
1043
+ case "success":
1044
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons3.CheckCircleOutlined, { style: { color: "#52c41a" } });
1045
+ case "error":
1046
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons3.InfoCircleOutlined, { style: { color: "#ff4d4f" } });
1047
+ default:
1048
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons3.LoadingOutlined, { style: { color: "#1890ff" } });
1049
+ }
1050
+ }
1051
+ var ToolCall = ({ data }) => {
1052
+ const toolCallData = data;
1053
+ const formatToolName = (name) => {
1054
+ return name.replace(/([a-z])([A-Z])/g, "$1 $2").split(/[_-]/).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
1055
+ };
1056
+ const formatArgsPreview = (args) => {
1057
+ try {
1058
+ const argsStr = Object.values(args).map((value) => {
1059
+ const valueStr = typeof value === "object" ? JSON.stringify(value).substring(0, 50) + (JSON.stringify(value).length > 50 ? "..." : "") : String(value).substring(0, 50) + (String(value).length > 50 ? "..." : "");
1060
+ return valueStr;
1061
+ }).join(" ");
1062
+ const result = argsStr.length > 100 ? argsStr.substring(0, 100) + "..." : argsStr;
1063
+ return result.replaceAll("\n", " ");
1064
+ } catch (e) {
1065
+ return "Error parsing args";
1066
+ }
1067
+ };
1068
+ const header = /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_antd4.Flex, { align: "center", wrap: "wrap", children: [
1069
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_antd4.Typography.Text, { strong: true, children: formatToolName(toolCallData.name) }),
1070
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1071
+ import_antd4.Typography.Text,
1072
+ {
1073
+ type: "secondary",
1074
+ style: { fontSize: "12px", marginLeft: "8px" },
1075
+ children: formatArgsPreview(toolCallData.args)
1076
+ }
1077
+ )
1078
+ ] });
1079
+ const toolCardData = {
1080
+ name: toolCallData.name,
1081
+ parameters: toolCallData.args,
1082
+ type: "tool_call"
1083
+ };
1084
+ const content = /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { marginTop: "8px" }, children: [
1085
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1086
+ ToolCard,
1087
+ {
1088
+ data: toolCardData,
1089
+ component_key: `${toolCallData.id}-params`,
1090
+ eventHandler: () => {
1091
+ },
1092
+ interactive: false
1093
+ }
1094
+ ),
1095
+ toolCallData.response && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { marginTop: "12px" }, children: [
1096
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1097
+ import_antd4.Typography.Text,
1098
+ {
1099
+ strong: true,
1100
+ style: { fontSize: "12px", marginBottom: "8px", display: "block" },
1101
+ children: "Response:"
1102
+ }
1103
+ ),
1104
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MDResponse, { content: toolCallData.response })
1105
+ ] })
1106
+ ] });
1107
+ const expandIcon = ({ isActive }) => {
1108
+ return getStatusIcon(toolCallData.status);
1109
+ };
1110
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1111
+ import_antd4.Collapse,
1112
+ {
1113
+ size: "small",
1114
+ bordered: false,
1115
+ defaultActiveKey: [],
1116
+ expandIcon,
1117
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1118
+ import_CollapsePanel.default,
1119
+ {
1120
+ header,
1121
+ style: { minWidth: 400 },
1122
+ children: content
1123
+ },
1124
+ toolCallData.id
1125
+ )
1126
+ }
1127
+ );
1128
+ };
1129
+
1130
+ // src/components/GenUI/elements/Todo.tsx
1131
+ var import_antd5 = require("antd");
1132
+ var import_antd_style3 = require("antd-style");
1133
+ var import_icons4 = require("@ant-design/icons");
1134
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1135
+ var { Text: Text4 } = import_antd5.Typography;
1136
+ var useStyle3 = (0, import_antd_style3.createStyles)(({ token, css }) => ({
1137
+ card: css`
1138
+ max-width: 1200px;
1139
+ background: linear-gradient(
1140
+ 919deg,
1141
+ rgb(67 232 157 / 8%),
1142
+ rgb(206 250 235 / 28%) 43%
1143
+ );
1144
+ `,
1145
+ todoItem: css`
1146
+ padding: 8px 0;
1147
+ border-bottom: 1px solid ${token.colorBorderSecondary};
1148
+ &:last-child {
1149
+ border-bottom: none;
1150
+ }
1151
+ `,
1152
+ completed: css`
1153
+ opacity: 0.7;
1154
+ `,
1155
+ inProgress: css`
1156
+ font-weight: 500;
1157
+ `,
1158
+ pending: css`
1159
+ opacity: 0.8;
1160
+ `
1161
+ }));
1162
+ var Todo = ({
1163
+ data,
1164
+ component_key,
1165
+ eventHandler,
1166
+ interactive = true
1167
+ }) => {
1168
+ const { styles } = useStyle3();
1169
+ const getStatusIcon3 = (status) => {
1170
+ switch (status) {
1171
+ case "completed":
1172
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icons4.CheckCircleOutlined, { style: { color: "#52c41a" } });
1173
+ case "in_progress":
1174
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icons4.LoadingOutlined, { style: { color: "#1890ff" } });
1175
+ case "pending":
1176
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icons4.ClockCircleOutlined, { style: { color: "gray" } });
1177
+ default:
1178
+ return null;
1179
+ }
1180
+ };
1181
+ const getStatusColor = (status) => {
1182
+ switch (status) {
1183
+ case "completed":
1184
+ return "success";
1185
+ case "in_progress":
1186
+ return "processing";
1187
+ case "pending":
1188
+ return "warning";
1189
+ default:
1190
+ return "default";
1191
+ }
1192
+ };
1193
+ const getStatusText = (status) => {
1194
+ switch (status) {
1195
+ case "completed":
1196
+ return "Completed";
1197
+ case "in_progress":
1198
+ return "In Progress";
1199
+ case "pending":
1200
+ return "Pending";
1201
+ default:
1202
+ return status;
1203
+ }
1204
+ };
1205
+ const getItemClassName = (status) => {
1206
+ switch (status) {
1207
+ case "completed":
1208
+ return styles.completed;
1209
+ case "in_progress":
1210
+ return styles.inProgress;
1211
+ case "pending":
1212
+ return styles.pending;
1213
+ default:
1214
+ return "";
1215
+ }
1216
+ };
1217
+ if (!data || !Array.isArray(data)) {
1218
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1219
+ import_antd5.Card,
1220
+ {
1221
+ size: "small",
1222
+ className: `shadow-sm ${styles.card}`,
1223
+ bordered: false,
1224
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text4, { type: "secondary", children: "No todo items available" })
1225
+ }
1226
+ );
1227
+ }
1228
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_antd5.Card, { size: "small", className: `shadow-sm ${styles.card}`, bordered: false, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_antd5.Space, { direction: "vertical", style: { width: "100%" }, children: [
1229
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1230
+ import_antd5.List,
1231
+ {
1232
+ size: "small",
1233
+ dataSource: data,
1234
+ renderItem: (item, index) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1235
+ import_antd5.List.Item,
1236
+ {
1237
+ className: `${styles.todoItem} ${getItemClassName(item.status)}`,
1238
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_antd5.Space, { align: "center", style: { width: "100%" }, children: [
1239
+ getStatusIcon3(item.status),
1240
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Text4, { style: { flex: 1 }, children: item.content })
1241
+ ] })
1242
+ }
1243
+ )
1244
+ }
1245
+ ),
1246
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Text4, { type: "secondary", style: { fontSize: 12 }, children: [
1247
+ "Total items: ",
1248
+ data.length,
1249
+ " | Completed:",
1250
+ " ",
1251
+ data.filter((item) => item.status === "completed").length,
1252
+ " | In Progress:",
1253
+ " ",
1254
+ data.filter((item) => item.status === "in_progress").length,
1255
+ " | Pending: ",
1256
+ data.filter((item) => item.status === "pending").length
1257
+ ] })
1258
+ ] }) });
1259
+ };
1260
+
1261
+ // src/components/GenUI/elements/index.tsx
1262
+ var elements = {
1263
+ action_show_attachments_uploader: {
1264
+ card_view: () => null,
1265
+ action: (data) => {
1266
+ console.log(data);
1267
+ }
1268
+ },
1269
+ generic_data_table: {
1270
+ card_view: GenericDataTable,
1271
+ side_app_view: GenericDataTableSideApp
1272
+ },
1273
+ confirm: {
1274
+ card_view: ConfirmFeedback
1275
+ },
1276
+ tool_call: {
1277
+ card_view: ToolCall
1278
+ },
1279
+ tool_card: {
1280
+ card_view: ToolCard
1281
+ },
1282
+ todo_list: {
1283
+ card_view: Todo
1284
+ }
1285
+ };
1286
+ var getElement = (language) => {
1287
+ if (language && elements[language]) {
1288
+ return elements[language];
1289
+ }
1290
+ return null;
1291
+ };
1292
+ var regsiterElement = (language, ElementMeta) => {
1293
+ console.log("regsiterElement", language, ElementMeta);
1294
+ elements[language] = ElementMeta;
1295
+ return ElementMeta;
1296
+ };
1297
+
1298
+ // src/components/GenUI/MDMermaid.tsx
1299
+ var import_mermaid = __toESM(require("mermaid"));
1300
+ var import_react8 = require("react");
1301
+ var import_uuid = require("uuid");
1302
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1303
+ var MDMermaid = ({ children = [] }) => {
1304
+ const domId = (0, import_react8.useRef)(`dom${(0, import_uuid.v4)()}`);
1305
+ const code = String(children);
1306
+ const target = (0, import_react8.useRef)(null);
1307
+ const targetInternal = (0, import_react8.useRef)(null);
1308
+ (0, import_react8.useEffect)(() => {
1309
+ if (target.current && code) {
1310
+ import_mermaid.default.initialize({
1311
+ startOnLoad: true,
1312
+ theme: "default",
1313
+ securityLevel: "loose",
1314
+ themeCSS: `
1315
+ g.classGroup rect {
1316
+ fill: #282a36;
1317
+ stroke: #6272a4;
1318
+ }
1319
+ g.classGroup text {
1320
+ fill: #f8f8f2;
1321
+ }
1322
+ g.classGroup line {
1323
+ stroke: #f8f8f2;
1324
+ stroke-width: 0.5;
1325
+ }
1326
+ .classLabel .box {
1327
+ stroke: #21222c;
1328
+ stroke-width: 3;
1329
+ fill: #21222c;
1330
+ opacity: 1;
1331
+ }
1332
+ .classLabel .label {
1333
+ fill: #f1fa8c;
1334
+ }
1335
+ .relation {
1336
+ stroke: #ff79c6;
1337
+ stroke-width: 1;
1338
+ }
1339
+ #compositionStart, #compositionEnd {
1340
+ fill: #bd93f9;
1341
+ stroke: #bd93f9;
1342
+ stroke-width: 1;
1343
+ }
1344
+ #aggregationEnd, #aggregationStart {
1345
+ fill: #21222c;
1346
+ stroke: #50fa7b;
1347
+ stroke-width: 1;
1348
+ }
1349
+ #dependencyStart, #dependencyEnd {
1350
+ fill: #00bcd4;
1351
+ stroke: #00bcd4;
1352
+ stroke-width: 1;
1353
+ }
1354
+ #extensionStart, #extensionEnd {
1355
+ fill: #f8f8f2;
1356
+ stroke: #f8f8f2;
1357
+ stroke-width: 1;
1358
+ }
1359
+ `,
1360
+ fontFamily: "Fira Code",
1361
+ sequence: { showSequenceNumbers: true }
1362
+ });
1363
+ import_mermaid.default.render(domId.current, code, target.current).then((result) => {
1364
+ target.current.innerHTML = result.svg;
1365
+ }).catch((error) => {
1366
+ console.log(error);
1367
+ });
1368
+ }
1369
+ }, [code]);
1370
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { style: { minWidth: 750 }, ref: target, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("code", { id: domId.current, style: { display: "none" } }) });
1371
+ };
1372
+
1373
+ // src/components/GenUI/MDResponse.tsx
1374
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1375
+ var SyntaxHighlighter = import_react_syntax_highlighter.Prism;
1376
+ var useStyles = (0, import_antd_style4.createStyles)(({ token, css }) => ({
1377
+ markdownTableContainer: css`
1378
+ overflow-x: auto;
1379
+ width: 100%;
1380
+ `,
1381
+ markdownTable: css`
1382
+ width: 100%;
1383
+ border-collapse: collapse;
1384
+ margin: 16px 0;
1385
+ border-radius: ${token.borderRadius}px;
1386
+ overflow: hidden;
1387
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
1388
+ white-space: nowrap;
1389
+ `,
1390
+ markdownTh: css`
1391
+ background: ${token.colorFillAlter};
1392
+ padding: 12px 16px;
1393
+ text-align: left;
1394
+ font-weight: 600;
1395
+ border-bottom: 1px solid ${token.colorBorder};
1396
+ color: ${token.colorTextHeading};
1397
+ font-size: ${token.fontSize}px;
1398
+ `,
1399
+ markdownTd: css`
1400
+ padding: 12px 16px;
1401
+ border-bottom: 1px solid ${token.colorBorder};
1402
+ color: ${token.colorText};
1403
+ font-size: ${token.fontSize}px;
1404
+
1405
+ &:last-child {
1406
+ border-right: none;
1407
+ }
1408
+ `,
1409
+ markdownTr: css`
1410
+ &:hover {
1411
+ background: ${token.colorFillTertiary};
1412
+ }
1413
+
1414
+ &:last-child td {
1415
+ border-bottom: none;
1416
+ }
1417
+ `,
1418
+ markdownContainer: css`
1419
+ white-space: normal;
1420
+
1421
+ /* 为整个markdown内容添加基础样式 */
1422
+ h1,
1423
+ h2,
1424
+ h3,
1425
+ h4,
1426
+ h5,
1427
+ h6 {
1428
+ color: ${token.colorTextHeading};
1429
+ margin-top: 24px;
1430
+ margin-bottom: 16px;
1431
+ }
1432
+
1433
+ p {
1434
+ color: ${token.colorText};
1435
+ line-height: 1.6;
1436
+ margin-bottom: 16px;
1437
+ }
1438
+
1439
+ blockquote {
1440
+ border-left: 4px solid ${token.colorPrimary};
1441
+ background: ${token.colorFillAlter};
1442
+ padding: 16px;
1443
+ margin: 16px 0;
1444
+ border-radius: 0 ${token.borderRadius}px ${token.borderRadius}px 0;
1445
+ }
1446
+
1447
+ code:not(pre code) {
1448
+ background: ${token.colorFillAlter};
1449
+ padding: 2px 6px;
1450
+ border-radius: ${token.borderRadius}px;
1451
+ font-family: ${token.fontFamilyCode};
1452
+ color: ${token.colorError};
1453
+ }
1454
+ `
1455
+ }));
1456
+ var MDResponse = ({
1457
+ content = "",
1458
+ context,
1459
+ embeddedLink,
1460
+ interactive,
1461
+ userData,
1462
+ noGenUI,
1463
+ eventHandler
1464
+ }) => {
1465
+ const { styles } = useStyles();
1466
+ const config = (0, import_react9.useMemo)(
1467
+ () => ({
1468
+ components: {
1469
+ a({ node, ...props }) {
1470
+ if (embeddedLink) {
1471
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(IFrameCard, { src: props.href });
1472
+ } else return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("a", { ...props });
1473
+ },
1474
+ table({ node, ...props }) {
1475
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: styles.markdownTableContainer, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("table", { className: styles.markdownTable, ...props }) });
1476
+ },
1477
+ th({ node, ...props }) {
1478
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("th", { className: styles.markdownTh, ...props });
1479
+ },
1480
+ td({ node, ...props }) {
1481
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("td", { className: styles.markdownTd, ...props });
1482
+ },
1483
+ tr({ node, ...props }) {
1484
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("tr", { className: styles.markdownTr, ...props });
1485
+ },
1486
+ code({ children, className, node, ...rest }) {
1487
+ const match = /language-(\w+)/.exec(className || "");
1488
+ const language = match?.[1];
1489
+ if (language) {
1490
+ const Element = getElement(language)?.card_view;
1491
+ if (Element) {
1492
+ let childrenData;
1493
+ try {
1494
+ childrenData = JSON.parse(children);
1495
+ } catch (error) {
1496
+ }
1497
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1498
+ Element,
1499
+ {
1500
+ interactive,
1501
+ component_key: language,
1502
+ data: childrenData,
1503
+ eventHandler: (e, data, message2, agent) => {
1504
+ eventHandler?.(e, data, message2, agent);
1505
+ }
1506
+ }
1507
+ );
1508
+ }
1509
+ switch (language) {
1510
+ case "mermaid":
1511
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(MDMermaid, { children });
1512
+ default:
1513
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1514
+ SyntaxHighlighter,
1515
+ {
1516
+ ...rest,
1517
+ PreTag: "div",
1518
+ language,
1519
+ style: import_prism.dark,
1520
+ children: String(children).replace(/\n$/, "")
1521
+ }
1522
+ );
1523
+ }
1524
+ } else {
1525
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("code", { ...rest, className, children });
1526
+ }
1527
+ }
1528
+ },
1529
+ remarkPlugins: [import_remark_gfm.default],
1530
+ rehypePlugins: [import_rehype_raw.default]
1531
+ }),
1532
+ [userData, interactive, embeddedLink, styles]
1533
+ );
1534
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: styles.markdownContainer, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react_markdown.default, { ...config, children: content }) });
1535
+ };
1536
+ var MDViewFormItem = ({ value }) => {
1537
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(MDResponse, { content: value || "" });
1538
+ };
1539
+ var IFrameCard = ({ src }) => {
1540
+ const containerRef = (0, import_react9.useRef)(null);
1541
+ const [width, setWidth] = (0, import_react9.useState)("640px");
1542
+ const [height, setHeight] = (0, import_react9.useState)("320px");
1543
+ const valid_images = [
1544
+ "jpg",
1545
+ "jpeg",
1546
+ "png",
1547
+ "gif",
1548
+ "bmp",
1549
+ "svg",
1550
+ "tif",
1551
+ "tiff",
1552
+ "webp"
1553
+ ];
1554
+ if (!src) {
1555
+ return null;
1556
+ }
1557
+ const spitedSrc = src.split(".");
1558
+ if (valid_images.includes(spitedSrc[spitedSrc.length - 1].toLowerCase())) {
1559
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("img", { src, style: { width: "100%" } }) });
1560
+ } else {
1561
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("a", { href: src, target: "_black", children: src }) });
1562
+ }
1563
+ };
1564
+
1565
+ // src/components/Chat/Chating.tsx
1566
+ var import_icons5 = require("@ant-design/icons");
1567
+ var import_x = require("@ant-design/x");
1568
+ var import_antd6 = require("antd");
1569
+ var import_ErrorBoundary = __toESM(require("antd/es/alert/ErrorBoundary"));
1570
+ var import_react10 = __toESM(require("react"));
1571
+ var import_react_i18next = require("react-i18next");
1572
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1573
+ var LazyBubble = ({
1574
+ message: message2,
1575
+ renderContent,
1576
+ autoLoadRightPanel
1577
+ }) => {
1578
+ const ref = (0, import_react10.useRef)(null);
1579
+ const [isVisible, setIsVisible] = (0, import_react10.useState)(false);
1580
+ const [wasEverVisible, setWasEverVisible] = (0, import_react10.useState)(false);
1581
+ (0, import_react10.useEffect)(() => {
1582
+ const observer = new IntersectionObserver(
1583
+ ([entry]) => {
1584
+ const visible = entry.isIntersecting;
1585
+ setIsVisible(visible);
1586
+ if (visible && !wasEverVisible) {
1587
+ setWasEverVisible(true);
1588
+ }
1589
+ },
1590
+ { threshold: 0.1 }
1591
+ );
1592
+ if (ref.current) {
1593
+ observer.observe(ref.current);
1594
+ }
1595
+ return () => {
1596
+ if (ref.current) {
1597
+ observer.unobserve(ref.current);
1598
+ }
1599
+ };
1600
+ }, [wasEverVisible]);
1601
+ (0, import_react10.useEffect)(() => {
1602
+ autoLoadRightPanel?.();
1603
+ }, []);
1604
+ const getPlaceholder = () => {
1605
+ const estimatedHeight = message2.content ? Math.min(100, message2.content.length / 5) : 100;
1606
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { style: { height: `${estimatedHeight}px`, minHeight: "50px" } });
1607
+ };
1608
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_ErrorBoundary.default, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { ref, style: { width: "100%" }, children: isVisible || wasEverVisible ? renderContent(message2) : getPlaceholder() }) });
1609
+ };
1610
+ var MemoizedBubbleList = (0, import_react10.memo)(
1611
+ ({
1612
+ items,
1613
+ roles,
1614
+ className
1615
+ }) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1616
+ import_x.Bubble.List,
1617
+ {
1618
+ autoScroll: true,
1619
+ items,
1620
+ roles,
1621
+ className
1622
+ },
1623
+ "messages"
1624
+ )
1625
+ );
1626
+ MemoizedBubbleList.displayName = "MemoizedBubbleList";
1627
+ var Chating = ({
1628
+ avatar,
1629
+ name,
1630
+ description,
1631
+ default_submit_message,
1632
+ tenant_id,
1633
+ messages,
1634
+ isLoading,
1635
+ sendMessage,
1636
+ stopStreaming,
1637
+ onOpenSidePanel,
1638
+ onReminderClick,
1639
+ styles,
1640
+ reminderCount,
1641
+ handleMDResponseEvent,
1642
+ senderPromptsItems,
1643
+ extra,
1644
+ attachment_placeholder,
1645
+ extraMeta = []
1646
+ }) => {
1647
+ const { t } = (0, import_react_i18next.useTranslation)();
1648
+ const [content, setContent] = (0, import_react10.useState)("");
1649
+ const [attachedFiles, setAttachedFiles] = (0, import_react10.useState)([]);
1650
+ const [headerOpen, setHeaderOpen] = (0, import_react10.useState)(false);
1651
+ const attachmentsRef = (0, import_react10.useRef)(null);
1652
+ const senderRef = import_react10.default.useRef(null);
1653
+ (0, import_react10.useEffect)(() => {
1654
+ regsiterElement("action_show_attachments_uploader", {
1655
+ card_view: () => null,
1656
+ action: (data) => {
1657
+ console.log(data);
1658
+ setHeaderOpen(true);
1659
+ }
1660
+ });
1661
+ }, []);
1662
+ const messageLengthRef = (0, import_react10.useRef)(messages?.length ?? 0);
1663
+ (0, import_react10.useEffect)(() => {
1664
+ if (messages?.length) {
1665
+ messageLengthRef.current = messages?.length;
1666
+ }
1667
+ }, [messages?.length]);
1668
+ const renderContent = (0, import_react10.useCallback)(
1669
+ (message2) => {
1670
+ const { content: content2, files, id } = message2;
1671
+ try {
1672
+ const json = JSON.parse(content2);
1673
+ if (json.action && json.message) {
1674
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1675
+ MDResponse,
1676
+ {
1677
+ content: json.message,
1678
+ eventHandler: handleMDResponseEvent
1679
+ }
1680
+ );
1681
+ }
1682
+ } catch (error) {
1683
+ }
1684
+ const tool_calls_md = message2.tool_calls?.map((tool_call) => {
1685
+ return `\`\`\`tool_call
1686
+ ${JSON.stringify(tool_call)}
1687
+ \`\`\``;
1688
+ }) || [];
1689
+ const content_md = [content2, ...tool_calls_md].join("\n");
1690
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_antd6.Space, { direction: "vertical", style: { width: "100%" }, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1691
+ MDResponse,
1692
+ {
1693
+ content: content_md,
1694
+ eventHandler: handleMDResponseEvent
1695
+ }
1696
+ ) });
1697
+ },
1698
+ [handleMDResponseEvent]
1699
+ );
1700
+ const items = (0, import_react10.useMemo)(
1701
+ () => messages.map((message2, index) => ({
1702
+ key: message2.id,
1703
+ role: message2.role,
1704
+ typing: false,
1705
+ content: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1706
+ LazyBubble,
1707
+ {
1708
+ message: message2,
1709
+ renderContent,
1710
+ autoLoadRightPanel: () => {
1711
+ const { content: content2, role } = message2;
1712
+ const isNewAddedMessage = messageLengthRef.current > 1 && messageLengthRef.current + 1 === messages.length;
1713
+ if (index === messages.length - 1 && isNewAddedMessage && role === "ai") {
1714
+ try {
1715
+ const match = content2?.match(
1716
+ /```([\w_]*)\n({.*?}|[^`]*)\n```/m
1717
+ );
1718
+ const type = match?.[1];
1719
+ const data = match?.[2];
1720
+ const jsonData = data ? JSON.parse(data) : {};
1721
+ if (type) {
1722
+ const element = getElement(type);
1723
+ if (element?.side_app_view) {
1724
+ onOpenSidePanel({
1725
+ component_key: type,
1726
+ data: jsonData
1727
+ });
1728
+ } else if (element?.action) {
1729
+ element.action(jsonData);
1730
+ }
1731
+ }
1732
+ } catch (error) {
1733
+ console.error(error);
1734
+ }
1735
+ }
1736
+ }
1737
+ }
1738
+ )
1739
+ })),
1740
+ [messages, renderContent, onOpenSidePanel]
1741
+ );
1742
+ const isArchiveFile = (file) => {
1743
+ const zipMimeTypes = ["application/zip"];
1744
+ const rarMimeTypes = [
1745
+ "application/vnd.rar",
1746
+ "application/x-rar-compressed",
1747
+ "application/rar"
1748
+ ];
1749
+ const archiveMimeTypes = [...zipMimeTypes, ...rarMimeTypes];
1750
+ return archiveMimeTypes.includes(file.type) || file.name.toLowerCase().endsWith(".zip") || file.name.toLowerCase().endsWith(".rar");
1751
+ };
1752
+ const onSubmit = (nextContent) => {
1753
+ if (!nextContent && attachedFiles.length === 0) return;
1754
+ if (attachedFiles.filter((f) => f.status !== "done").length > 0) {
1755
+ import_antd6.message.warning("\u6587\u4EF6\u8FD8\u5728\u4E0A\u4F20\u4E2D...");
1756
+ return;
1757
+ }
1758
+ if (!nextContent && attachedFiles.length > 0) {
1759
+ nextContent = default_submit_message || "\u8BB0\u8D26";
1760
+ }
1761
+ const files = attachedFiles.map(
1762
+ (file) => isArchiveFile(file) ? {
1763
+ name: file.response.zipFileName || file.response.rarFileName,
1764
+ id: file.response.zipFileId || file.response.rarFileId,
1765
+ totalFiles: file.response.totalFiles,
1766
+ processedFiles: file.response.processedFiles,
1767
+ skippedFiles: file.response.skippedFiles,
1768
+ type: file.name.toLowerCase().endsWith(".rar") ? "application/rar" : "application/zip",
1769
+ files: file.response?.results?.map((r) => ({
1770
+ name: r.fileName,
1771
+ path: r.filePath,
1772
+ id: r.fileId
1773
+ }))
1774
+ } : {
1775
+ name: file.name,
1776
+ id: file.response.id
1777
+ }
1778
+ );
1779
+ const files_md = files.length > 0 ? [
1780
+ "",
1781
+ "\u6211\u5DF2\u7ECF\u63D0\u4EA4\u4E86\u4EE5\u4E0B\u6587\u4EF6\uFF1A",
1782
+ "```attachments",
1783
+ JSON.stringify(files),
1784
+ "```"
1785
+ ].join("\n") : "";
1786
+ sendMessage({ input: { message: nextContent + files_md, files } });
1787
+ setContent("");
1788
+ setAttachedFiles([]);
1789
+ setHeaderOpen(false);
1790
+ };
1791
+ const onPromptsItemClick = (info) => {
1792
+ onSubmit(info.data.description);
1793
+ };
1794
+ const onChange = (info) => {
1795
+ if (!headerOpen) {
1796
+ setHeaderOpen(true);
1797
+ }
1798
+ if (info.file?.response?.error || info.file.status === "error") {
1799
+ import_antd6.message.error(
1800
+ `${info.file.name} file upload failed.${info.file?.response?.message}`
1801
+ );
1802
+ }
1803
+ setAttachedFiles(info.fileList);
1804
+ if (info.file.status === "done") {
1805
+ console.log(`${info.file.name} file uploaded successfully`);
1806
+ }
1807
+ };
1808
+ const beforeUpload = (file) => {
1809
+ const isLessThan20MB = file.size / 1024 / 1024 < 20;
1810
+ if (!isLessThan20MB) {
1811
+ import_antd6.message.error(
1812
+ `File must be smaller than 20MB! ${file.name} is too large.`
1813
+ );
1814
+ return false;
1815
+ }
1816
+ return true;
1817
+ };
1818
+ const attachmentsNode = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_antd6.Badge, { dot: attachedFiles.length > 0 && !headerOpen, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1819
+ import_antd6.Button,
1820
+ {
1821
+ type: "text",
1822
+ icon: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_icons5.PaperClipOutlined, {}),
1823
+ onClick: () => setHeaderOpen(!headerOpen)
1824
+ }
1825
+ ) });
1826
+ const senderHeader = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1827
+ import_x.Sender.Header,
1828
+ {
1829
+ title: "Attachments",
1830
+ open: headerOpen,
1831
+ onOpenChange: setHeaderOpen,
1832
+ styles: {
1833
+ content: {
1834
+ padding: 0
1835
+ }
1836
+ },
1837
+ forceRender: true,
1838
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1839
+ import_x.Attachments,
1840
+ {
1841
+ ref: attachmentsRef,
1842
+ items: attachedFiles,
1843
+ action: `/api/file_storage/upload?path=temp`,
1844
+ headers: {
1845
+ "x-tenant-id": tenant_id
1846
+ },
1847
+ getDropContainer: () => {
1848
+ const dropContainer = document.querySelector(".fina_chat");
1849
+ return dropContainer;
1850
+ },
1851
+ onDrop: (e) => {
1852
+ console.log(e);
1853
+ },
1854
+ onChange,
1855
+ beforeUpload,
1856
+ showUploadList: true,
1857
+ multiple: true,
1858
+ maxCount: 10,
1859
+ placeholder: (type) => ({
1860
+ icon: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_icons5.CloudUploadOutlined, {}),
1861
+ title: "\u4E0A\u4F20\u6587\u4EF6",
1862
+ description: attachment_placeholder
1863
+ })
1864
+ }
1865
+ )
1866
+ }
1867
+ );
1868
+ const roles = {
1869
+ ai: {
1870
+ placement: "start",
1871
+ typing: false,
1872
+ variant: "filled",
1873
+ styles: {
1874
+ content: {
1875
+ background: "transparent",
1876
+ padding: 0
1877
+ // "linear-gradient(149deg, rgb(160 17 2170 / 18%), rgb(226 176 176 / 18%) 43%)",
1878
+ }
1879
+ }
1880
+ },
1881
+ human: {
1882
+ placement: "end",
1883
+ variant: "filled",
1884
+ styles: {
1885
+ content: {
1886
+ maxWidth: "70%",
1887
+ background: "linear-gradient(1777deg, rgba(153, 164, 255, 0.38), rgb(231 243 248 / 38%) 27%)"
1888
+ }
1889
+ }
1890
+ }
1891
+ };
1892
+ const extraMetaComponents = (0, import_react10.useMemo)(() => {
1893
+ if (extraMeta?.length > 0) {
1894
+ return extraMeta.map((meta) => {
1895
+ const Element = getElement(meta.id)?.card_view;
1896
+ if (Element) {
1897
+ let childrenData;
1898
+ try {
1899
+ } catch (error) {
1900
+ }
1901
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1902
+ Element,
1903
+ {
1904
+ component_key: meta.id,
1905
+ data: childrenData,
1906
+ eventHandler: (e, data, message2, agent) => {
1907
+ handleMDResponseEvent?.(e, data, message2, agent);
1908
+ }
1909
+ },
1910
+ meta.id
1911
+ );
1912
+ }
1913
+ });
1914
+ }
1915
+ return void 0;
1916
+ }, [extraMeta]);
1917
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
1918
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { children: [
1919
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1920
+ import_x.Welcome,
1921
+ {
1922
+ style: { padding: 8 },
1923
+ variant: "borderless",
1924
+ description,
1925
+ icon: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_antd6.Avatar, { src: avatar || "/images/avatar.jpeg", size: 48 }),
1926
+ title: name || "Fina",
1927
+ extra: extra || extraMetaComponents && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_antd6.Space, { align: "center", style: { marginRight: 16 }, children: extraMetaComponents })
1928
+ }
1929
+ ),
1930
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1931
+ "div",
1932
+ {
1933
+ style: {
1934
+ background: "linear-gradient(rgba(41, 42, 45, .8) 0%, rgba(41, 42, 45, 0) 100%)"
1935
+ }
1936
+ }
1937
+ )
1938
+ ] }),
1939
+ items.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1940
+ MemoizedBubbleList,
1941
+ {
1942
+ items,
1943
+ roles,
1944
+ className: styles.messages
1945
+ }
1946
+ ) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { style: { flex: 1 } }),
1947
+ isLoading ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_x.Bubble, { loading: isLoading, variant: "borderless" }) }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_x.Prompts, { items: senderPromptsItems, onItemClick: onPromptsItemClick }),
1948
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1949
+ import_x.Sender,
1950
+ {
1951
+ allowSpeech: true,
1952
+ ref: senderRef,
1953
+ value: content,
1954
+ header: senderHeader,
1955
+ onSubmit,
1956
+ onCancel: stopStreaming,
1957
+ onChange: setContent,
1958
+ prefix: attachmentsNode,
1959
+ loading: isLoading,
1960
+ className: styles.sender,
1961
+ actions: (ori, { components }) => {
1962
+ const { SendButton, LoadingButton } = components;
1963
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_antd6.Flex, { justify: "space-between", align: "center", children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(LoadingButton, { type: "default" }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1964
+ SendButton,
1965
+ {
1966
+ type: "primary",
1967
+ disabled: !content && attachedFiles.length === 0,
1968
+ onClick: () => onSubmit(content)
1969
+ }
1970
+ ) });
1971
+ },
1972
+ onPasteFile: (_, files) => {
1973
+ Array.from(files).forEach((file) => {
1974
+ attachmentsRef.current?.upload(file);
1975
+ });
1976
+ setHeaderOpen(true);
1977
+ }
1978
+ }
1979
+ )
1980
+ ] });
1981
+ };
1982
+
1983
+ // src/components/Chat/ThinkingChain.tsx
1984
+ var import_icons6 = require("@ant-design/icons");
1985
+ var import_x2 = require("@ant-design/x");
1986
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1987
+ function getStatusIcon2(status) {
1988
+ switch (status) {
1989
+ case "success":
1990
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_icons6.CheckCircleOutlined, {});
1991
+ case "error":
1992
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_icons6.InfoCircleOutlined, {});
1993
+ case "pending":
1994
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_icons6.LoadingOutlined, {});
1995
+ default:
1996
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_icons6.CheckCircleOutlined, {});
1997
+ }
1998
+ }
1999
+ var ThinkingChain = ({ message: message2 }) => {
2000
+ const title = message2.name || message2.content.split("\n")[0];
2001
+ const items = [
2002
+ {
2003
+ key: message2.id,
2004
+ title,
2005
+ content: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(MDResponse, { content: message2.content }),
2006
+ status: message2.status,
2007
+ icon: getStatusIcon2(message2.status)
2008
+ }
2009
+ ];
2010
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2011
+ import_x2.ThoughtChain,
2012
+ {
2013
+ items,
2014
+ collapsible: message2.status === "success" ? true : false,
2015
+ size: "small"
2016
+ }
2017
+ );
2018
+ };
2019
+ var ThinkingChainGroup = ({ message: message2 }) => {
2020
+ const title = "\u601D\u8003\u8FC7\u7A0B";
2021
+ const children = message2.items?.map((item) => ({
2022
+ key: item.id,
2023
+ title: item.name || item.content.split("\n")[0],
2024
+ content: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(MDResponse, { content: item.content }),
2025
+ status: item.status,
2026
+ icon: getStatusIcon2(item.status)
2027
+ }));
2028
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_x2.ThoughtChain, { items: children, collapsible: true, size: "small" });
2029
+ };
2030
+
2031
+ // src/components/Chat/SideAppViewBrowser.tsx
2032
+ var import_icons7 = require("@ant-design/icons");
2033
+ var import_antd7 = require("antd");
2034
+ var import_antd_style5 = require("antd-style");
2035
+ var import_react11 = require("react");
2036
+ var import_jsx_runtime12 = require("react/jsx-runtime");
2037
+ var useStyle4 = (0, import_antd_style5.createStyles)(({ token, css }) => {
2038
+ return {
2039
+ tabContainer: css`
2040
+ .ant-tabs-content-holder {
2041
+ overflow: hidden;
2042
+ height: 100%;
2043
+ }
2044
+ .ant-tabs-content {
2045
+ overflow: hidden;
2046
+ height: 100%;
2047
+ }
2048
+ .ant-tabs-content > div {
2049
+ overflow: auto;
2050
+ height: 100%;
2051
+ }
2052
+ `
2053
+ };
2054
+ });
2055
+ var EmptySideAppView = ({ component_key, data }) => {
2056
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { children: [
2057
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { children: "\u672A\u627E\u5230\u5BF9\u5E94\u7684\u7EC4\u4EF6\u89C6\u56FE" }),
2058
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("pre", { children: JSON.stringify({ component_key, data }, null, 2) })
2059
+ ] });
2060
+ };
2061
+ var SideAppViewBrowser = ({
2062
+ open_uri,
2063
+ eventHandler,
2064
+ onClose,
2065
+ onChangeSize
2066
+ }) => {
2067
+ const { styles } = useStyle4();
2068
+ const [activeKey, setActiveKey] = (0, import_react11.useState)(JSON.stringify(open_uri));
2069
+ const [currentSize, setCurrentSize] = (0, import_react11.useState)(open_uri.size || "large");
2070
+ const [items, setItems] = (0, import_react11.useState)([]);
2071
+ const add = (key, label, children) => {
2072
+ const newActiveKey = key;
2073
+ const newPanes = [...items];
2074
+ newPanes.push({ label, children, key: newActiveKey });
2075
+ setItems(newPanes);
2076
+ setActiveKey(newActiveKey);
2077
+ };
2078
+ const remove = (targetKey) => {
2079
+ let newActiveKey = activeKey;
2080
+ let lastIndex = -1;
2081
+ items.forEach((item, i) => {
2082
+ if (item.key === targetKey) {
2083
+ lastIndex = i - 1;
2084
+ }
2085
+ });
2086
+ const newPanes = items.filter((item) => item.key !== targetKey);
2087
+ if (newPanes.length && newActiveKey === targetKey) {
2088
+ if (lastIndex >= 0) {
2089
+ newActiveKey = newPanes[lastIndex].key;
2090
+ } else {
2091
+ newActiveKey = newPanes[0].key;
2092
+ }
2093
+ }
2094
+ if (newPanes.length === 0) {
2095
+ onClose();
2096
+ return;
2097
+ }
2098
+ setItems(newPanes);
2099
+ setActiveKey(newActiveKey);
2100
+ };
2101
+ const onEdit = (targetKey, action) => {
2102
+ if (action === "remove") {
2103
+ remove(targetKey);
2104
+ }
2105
+ };
2106
+ (0, import_react11.useEffect)(() => {
2107
+ const SideAppView = getElement(open_uri.component_key).side_app_view || EmptySideAppView;
2108
+ const key = JSON.stringify(open_uri);
2109
+ if (items.find((item) => item.key === key)) {
2110
+ setActiveKey(key);
2111
+ return;
2112
+ }
2113
+ add(
2114
+ key,
2115
+ open_uri.message || open_uri.data.message || "\u672A\u547D\u540D",
2116
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2117
+ SideAppView,
2118
+ {
2119
+ component_key: open_uri.component_key,
2120
+ data: open_uri.data,
2121
+ eventHandler
2122
+ }
2123
+ )
2124
+ );
2125
+ }, [open_uri]);
2126
+ (0, import_react11.useEffect)(() => {
2127
+ if (open_uri.size && open_uri.size !== currentSize) {
2128
+ setCurrentSize(open_uri.size);
2129
+ }
2130
+ }, [open_uri.size]);
2131
+ const onChange = (newActiveKey) => {
2132
+ setActiveKey(newActiveKey);
2133
+ };
2134
+ const handleSizeChange = () => {
2135
+ const sizeOrder = [
2136
+ // 先不支持小屏和中间屏
2137
+ // "small",
2138
+ // "middle",
2139
+ "large",
2140
+ "full"
2141
+ ];
2142
+ const currentIndex = sizeOrder.indexOf(currentSize);
2143
+ const nextSize = sizeOrder[(currentIndex + 1) % sizeOrder.length];
2144
+ setCurrentSize(nextSize);
2145
+ onChangeSize(nextSize);
2146
+ };
2147
+ const getSizeLabel = (size) => {
2148
+ switch (size) {
2149
+ case "small":
2150
+ return "\u5C0F";
2151
+ case "middle":
2152
+ return "\u4E2D";
2153
+ case "large":
2154
+ return "\u5927";
2155
+ case "full":
2156
+ return "\u5168\u5C4F";
2157
+ default:
2158
+ return "\u4E2D";
2159
+ }
2160
+ };
2161
+ const getSizeIcon = (size) => {
2162
+ switch (size) {
2163
+ case "middle":
2164
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons7.CompressOutlined, {});
2165
+ case "large":
2166
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons7.ExpandOutlined, {});
2167
+ case "full":
2168
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons7.FullscreenOutlined, {});
2169
+ default:
2170
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons7.ExpandOutlined, {});
2171
+ }
2172
+ };
2173
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2174
+ import_antd7.Tabs,
2175
+ {
2176
+ className: styles.tabContainer,
2177
+ type: "editable-card",
2178
+ style: { height: "100%" },
2179
+ hideAdd: true,
2180
+ tabBarExtraContent: {
2181
+ right: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { style: { display: "flex", gap: "4px" }, children: [
2182
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2183
+ import_antd7.Button,
2184
+ {
2185
+ style: { margin: "8px 0" },
2186
+ size: "large",
2187
+ type: "text",
2188
+ icon: getSizeIcon(currentSize),
2189
+ onClick: handleSizeChange,
2190
+ title: `\u5F53\u524D\u5C3A\u5BF8: ${getSizeLabel(currentSize)}, \u70B9\u51FB\u5207\u6362`
2191
+ }
2192
+ ),
2193
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2194
+ import_antd7.Button,
2195
+ {
2196
+ style: { margin: "8px 0" },
2197
+ size: "large",
2198
+ type: "text",
2199
+ icon: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_icons7.CloseOutlined, {}),
2200
+ onClick: () => {
2201
+ onClose();
2202
+ }
2203
+ }
2204
+ )
2205
+ ] })
2206
+ },
2207
+ onChange,
2208
+ activeKey,
2209
+ onEdit,
2210
+ items
2211
+ }
2212
+ );
2213
+ };
2214
+
2215
+ // src/components/Chat/context.tsx
2216
+ var import_react12 = require("react");
2217
+ var chatContext = (0, import_react12.createContext)({
2218
+ eventHandler: (component_key, data, message2) => {
2219
+ }
2220
+ });
500
2221
  // Annotate the CommonJS export names for ESM import in node:
501
2222
  0 && (module.exports = {
502
2223
  AxiomLatticeProvider,
2224
+ Chating,
2225
+ MDMermaid,
2226
+ MDResponse,
2227
+ MDViewFormItem,
2228
+ SideAppViewBrowser,
2229
+ ThinkingChain,
2230
+ ThinkingChainGroup,
2231
+ chatContext,
2232
+ elements,
2233
+ getElement,
2234
+ regsiterElement,
503
2235
  useAgentGraph,
504
2236
  useAgentState,
505
2237
  useAxiomLattice,