@ray-js/t-agent-ui-ray 0.2.1-beta.3 → 0.2.2-beta-2

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.
Files changed (38) hide show
  1. package/dist/ChatContainer/index.d.ts +2 -1
  2. package/dist/ChatContainer/index.js +53 -48
  3. package/dist/EchartsBlockRender/index.js +6 -4
  4. package/dist/EchartsBlockRender/index.rjs +35 -9
  5. package/dist/MessageInput/MessageInputAIStream/WaveformVisualizer.d.ts +2 -2
  6. package/dist/MessageInput/MessageInputAIStream/WaveformVisualizer.js +30 -23
  7. package/dist/MessageInput/MessageInputAIStream/index.d.ts +8 -0
  8. package/dist/MessageInput/MessageInputAIStream/index.js +52 -41
  9. package/dist/MessageInput/index.d.ts +2 -1
  10. package/dist/MessageInput/index.js +2 -1
  11. package/dist/MessageList/LazyView.d.ts +9 -0
  12. package/dist/MessageList/LazyView.js +57 -0
  13. package/dist/MessageList/ScrollBottomView.d.ts +47 -0
  14. package/dist/MessageList/ScrollBottomView.js +205 -0
  15. package/dist/MessageList/index.d.ts +5 -2
  16. package/dist/MessageList/index.js +26 -88
  17. package/dist/MessageList/index.less +15 -4
  18. package/dist/MessageRender/index.less +1 -0
  19. package/dist/TileRender/index.js +5 -3
  20. package/dist/contexts.d.ts +18 -6
  21. package/dist/contexts.js +5 -17
  22. package/dist/hooks/context.d.ts +4 -4
  23. package/dist/hooks/context.js +13 -4
  24. package/dist/hooks/useStableCallback.d.ts +1 -0
  25. package/dist/hooks/useStableCallback.js +13 -0
  26. package/dist/tiles/BubbleTile/index.js +4 -4
  27. package/dist/tiles/ExecuteCardTile/index.d.ts +1 -8
  28. package/dist/tiles/ExecuteCardTile/index.js +7 -15
  29. package/dist/tiles/ExecuteCardTile/index.less +177 -151
  30. package/dist/tiles/OperateCardTile/index.d.ts +2 -6
  31. package/dist/tiles/OperateCardTile/index.js +6 -4
  32. package/dist/tiles/types.d.ts +31 -0
  33. package/dist/tiles/types.js +5 -0
  34. package/dist/types.d.ts +1 -0
  35. package/dist/utils/createSharedStore.d.ts +4 -0
  36. package/dist/utils/createSharedStore.js +64 -0
  37. package/dist/utils/index.js +1 -1
  38. package/package.json +2 -2
@@ -0,0 +1,205 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import "core-js/modules/es.regexp.exec.js";
3
+ import "core-js/modules/web.dom-collections.iterator.js";
4
+ import React, { useCallback, useEffect, useRef, useState, forwardRef, useImperativeHandle } from 'react';
5
+ import { useSleep } from '../hooks/useSleep';
6
+ import { generateId } from '@ray-js/t-agent';
7
+ import { useOnEvent, useTick } from '../hooks';
8
+ import { ScrollView } from '@ray-js/ray';
9
+ import { View } from '@ray-js/components';
10
+ export function useScrollBottomView(params) {
11
+ const [scrollViewId] = useState(() => "ScrollView-".concat(generateId()));
12
+ const contentViewId = "".concat(scrollViewId, "-content");
13
+ const tickValue = useTick();
14
+ const [ready, setReady] = useState(false);
15
+ const [scrollIntoViewFlag, setScrollIntoViewIdFlag] = useState(() => "".concat(Date.now()));
16
+ const [scrollWithAnimation, setScrollWithAnimation] = useState(false);
17
+ const ref = useRef({
18
+ clientHeight: 0,
19
+ needFollow: true,
20
+ following: false,
21
+ lastScrollEvent: null,
22
+ startTimestamp: 0
23
+ });
24
+ const sleep = useSleep();
25
+ const makeScrollBottomEvent = useCallback(() => {
26
+ if (ref.current.lastScrollEvent) {
27
+ const {
28
+ detail,
29
+ currentTarget,
30
+ target
31
+ } = ref.current.lastScrollEvent;
32
+ const {
33
+ scrollTop,
34
+ scrollHeight
35
+ } = detail;
36
+ const newDetail = {
37
+ deltaX: 0,
38
+ scrollLeft: 0,
39
+ scrollTop: scrollHeight - ref.current.clientHeight,
40
+ scrollWidth: detail.scrollWidth,
41
+ scrollHeight,
42
+ deltaY: scrollTop - (scrollHeight - ref.current.clientHeight)
43
+ };
44
+ if (scrollTop === newDetail.scrollTop) {
45
+ // 如果滚动位置没有变化,则不触发事件
46
+ return null;
47
+ }
48
+ return {
49
+ type: 'scroll',
50
+ timeStamp: Date.now() - ref.current.startTimestamp,
51
+ currentTarget,
52
+ target,
53
+ stopPropagation: () => {},
54
+ detail: newDetail
55
+ };
56
+ }
57
+ return null;
58
+ }, []);
59
+ const scrollToBottom = useCallback(_ref => {
60
+ let {
61
+ animation,
62
+ follow
63
+ } = _ref;
64
+ if (follow) {
65
+ if (ref.current.needFollow) {
66
+ setScrollIntoViewIdFlag("".concat(Date.now()));
67
+ ref.current.needFollow = true;
68
+ const event = makeScrollBottomEvent();
69
+ if (event) {
70
+ sleep(10).then(() => {
71
+ var _params$onScroll;
72
+ params === null || params === void 0 || (_params$onScroll = params.onScroll) === null || _params$onScroll === void 0 || _params$onScroll.call(params, event);
73
+ });
74
+ }
75
+ }
76
+ } else {
77
+ if (animation) {
78
+ setScrollWithAnimation(true);
79
+ }
80
+ ref.current.needFollow = true;
81
+ setScrollIntoViewIdFlag("".concat(Date.now()));
82
+ const event = makeScrollBottomEvent();
83
+ if (event) {
84
+ sleep(100).then(() => {
85
+ var _params$onScroll2;
86
+ params === null || params === void 0 || (_params$onScroll2 = params.onScroll) === null || _params$onScroll2 === void 0 || _params$onScroll2.call(params, event);
87
+ });
88
+ }
89
+ if (animation) {
90
+ sleep(10).then(() => {
91
+ setScrollWithAnimation(false);
92
+ });
93
+ }
94
+ }
95
+ }, []);
96
+ useEffect(() => {
97
+ const getDomTick = () => {
98
+ return new Promise(resolve => {
99
+ // @ts-ignore
100
+ const query = ty.createSelectorQuery();
101
+ query.select("#".concat(scrollViewId)).fields({
102
+ dataset: true
103
+ }, res => {
104
+ resolve(res.dataset.renderTick);
105
+ }).exec();
106
+ });
107
+ };
108
+ const getClientHeight = () => {
109
+ return new Promise(resolve => {
110
+ // @ts-ignore
111
+ const query = ty.createSelectorQuery();
112
+ query.select("#".concat(scrollViewId)).fields({
113
+ size: true
114
+ }, res => {
115
+ resolve(res.height);
116
+ }).exec();
117
+ });
118
+ };
119
+ const scrollViewInterval = setInterval(() => {
120
+ // 外部容器高度变化不频繁,1 秒查一次
121
+ getClientHeight().then(height => {
122
+ ref.current.clientHeight = height;
123
+ });
124
+ }, 1000);
125
+
126
+ // 初始化好 clientHeight
127
+ (async () => {
128
+ let tick = await getDomTick();
129
+ while (tick <= 0) {
130
+ await sleep(1);
131
+ tick = await getDomTick();
132
+ }
133
+ return tick;
134
+ })().then(() => getClientHeight()).then(height => {
135
+ console.log('scrollView clientHeight', height);
136
+ ref.current.clientHeight = height;
137
+ })
138
+ // 渲染完毕后,开始滚动到最底部
139
+ .then(() => scrollToBottom({}))
140
+ // 展示列表
141
+ .then(() => setReady(true));
142
+ return () => {
143
+ clearInterval(scrollViewInterval);
144
+ };
145
+ }, [scrollViewId]);
146
+ let scrollIntoViewId = "".concat(scrollViewId, "-toView-").concat(tickValue, "-").concat(scrollIntoViewFlag);
147
+ if (!ref.current.needFollow) {
148
+ scrollIntoViewId = null;
149
+ }
150
+ return {
151
+ scrollToBottom,
152
+ scrollViewLoading: !ready,
153
+ scrollIntoViewId,
154
+ contentViewProps: {
155
+ contentViewId
156
+ },
157
+ scrollViewProps: {
158
+ 'data-render-tick': tickValue,
159
+ id: scrollViewId,
160
+ scrollY: true,
161
+ onScroll: event => {
162
+ var _params$onScroll3;
163
+ ref.current.lastScrollEvent = event;
164
+ const {
165
+ scrollTop,
166
+ scrollHeight
167
+ } = event.detail;
168
+ ref.current.needFollow = scrollHeight - scrollTop <= ref.current.clientHeight + 25;
169
+ params === null || params === void 0 || (_params$onScroll3 = params.onScroll) === null || _params$onScroll3 === void 0 || _params$onScroll3.call(params, event);
170
+ if (!ref.current.startTimestamp) {
171
+ ref.current.startTimestamp = Date.now() - event.timeStamp;
172
+ }
173
+ },
174
+ scrollWithAnimation,
175
+ scrollIntoView: scrollIntoViewId
176
+ }
177
+ };
178
+ }
179
+ const ScrollBottomView = /*#__PURE__*/forwardRef((props, ref) => {
180
+ const {
181
+ scrollToBottom,
182
+ scrollViewProps,
183
+ scrollIntoViewId,
184
+ contentViewProps,
185
+ scrollViewLoading
186
+ } = useScrollBottomView({
187
+ onScroll: props.onScroll
188
+ });
189
+ useOnEvent('scrollToBottom', scrollToBottom);
190
+ useImperativeHandle(ref, () => ({
191
+ scrollToBottom
192
+ }), [scrollToBottom]);
193
+ return /*#__PURE__*/React.createElement(ScrollView, _extends({
194
+ className: "".concat(props.className || '', " ").concat(scrollViewLoading ? 't-agent-message-list-hide' : ''),
195
+ style: props.style
196
+ // @ts-ignore
197
+ ,
198
+ hideScrollbar: props.hideScrollbar
199
+ }, scrollViewProps), /*#__PURE__*/React.createElement(View, _extends({}, contentViewProps, {
200
+ className: "".concat(props.contentClassName || '')
201
+ }), props.children, /*#__PURE__*/React.createElement(View, {
202
+ id: scrollIntoViewId
203
+ })));
204
+ });
205
+ export default /*#__PURE__*/React.memo(ScrollBottomView);
@@ -6,6 +6,9 @@ interface Props {
6
6
  wrapperClassName?: string;
7
7
  wrapperStyle?: React.CSSProperties;
8
8
  renderTop?: React.ReactNode;
9
+ renderBottom?: React.ReactNode;
10
+ onScroll?: (event: any) => void;
11
+ hideScrollbar?: boolean;
9
12
  roleSide?: {
10
13
  user?: 'start' | 'end' | string;
11
14
  assistant?: 'start' | 'end' | string;
@@ -18,5 +21,5 @@ interface Props {
18
21
  tipText: string;
19
22
  };
20
23
  }
21
- export default function MessageList(props: Props): React.JSX.Element;
22
- export {};
24
+ declare const MessageList: (props: Props) => React.JSX.Element;
25
+ export default MessageList;
@@ -1,118 +1,56 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import "core-js/modules/es.array.reverse.js";
3
1
  import "core-js/modules/esnext.iterator.constructor.js";
4
2
  import "core-js/modules/esnext.iterator.map.js";
5
3
  import "core-js/modules/web.dom-collections.iterator.js";
6
4
  import './index.less';
7
5
  import { View } from '@ray-js/components';
8
- import React, { useMemo, useRef, useState } from 'react';
9
- import { ScrollView } from '@ray-js/ray';
10
- import { generateId } from '@ray-js/t-agent';
6
+ import React from 'react';
11
7
  import MessageRender from '../MessageRender';
12
- import { useAgentMessage, useAgentSessionValue, useOnEvent } from '../hooks';
13
- import { useDebouncedFn } from '../hooks/useDebouncedFn';
14
- import { useSleep } from '../hooks/useSleep';
15
- import { systemInfo } from '../utils';
16
- export default function MessageList(props) {
8
+ import { useAgentMessage, useAgentSessionValue } from '../hooks';
9
+ import ScrollBottomView from './ScrollBottomView';
10
+ import { useStableCallback } from '../hooks/useStableCallback';
11
+ const MessageList = props => {
17
12
  const {
18
13
  className,
19
14
  roleSide,
20
15
  style,
21
16
  wrapperClassName,
22
17
  wrapperStyle,
23
- historyLimit
18
+ historyLimit,
19
+ hideScrollbar
24
20
  } = props;
25
- const {
26
- messages
27
- } = useAgentMessage();
28
- const [id] = useState(() => "ScrollView-".concat(generateId()));
29
- const [scrollAnimation, setScrollAnimation] = useState(false);
30
- // 最大整数位数,用于强制滚动到底部,收到连续 scrollToBottom 时,每 10 毫秒更新一次
31
- const [scrollTop, setScrollTop] = useState(() => 1000000000000000 + Math.floor(Date.now() / 10));
32
- const followNewMessageRef = useRef(true);
33
- const sleep = useSleep();
21
+ const messages = useAgentMessage();
22
+ const onScroll = useStableCallback(props.onScroll);
34
23
  const [showSelect] = useAgentSessionValue('UIRay.multiSelect.show');
35
- const canIUse = useMemo(() => {
36
- // @ts-ignore
37
- const {
38
- containerVersion
39
- } = systemInfo;
40
- return {
41
- // 在 2.27.2 版本之前,pageScrollTo 在某些场景不生效
42
- scroll: false
43
- };
44
- }, []);
45
- const scroll = useDebouncedFn(animation => {
46
- // @ts-ignore
47
- ty.pageScrollTo({
48
- scrollTop: 0,
49
- duration: animation ? 100 : 1,
50
- selector: "#".concat(id)
51
- });
52
- }, 100);
53
-
54
- // 强制滚动到底部
55
- useOnEvent('scrollToBottom', _ref => {
56
- let {
57
- animation,
58
- follow
59
- } = _ref;
60
- // 如果发送的跟随新消息的滚动,判断当前是不是滚动到了底部,如果没有滚动到底部,不执行滚动
61
- if (follow && !followNewMessageRef.current) {
62
- return;
63
- }
64
- if (canIUse.scroll) {
65
- scroll(animation);
66
- } else {
67
- sleep(100).then(() => {
68
- setScrollAnimation(!!animation);
69
- const top = 1000000000000000 + Math.floor(Date.now() / 10);
70
- if (top !== scrollTop) {
71
- setScrollTop(top);
72
- }
73
- });
74
- }
75
- });
76
-
77
- // 使用翻转列表,让滚动和新消息出现在第一条,这样可以避免滚动到底部时的闪烁
78
- const reversed = useMemo(() => [...messages].reverse(), [messages]);
79
- const scrollProps = canIUse.scroll ? {} : {
80
- scrollWithAnimation: scrollAnimation,
81
- scrollTop
82
- };
83
24
  return /*#__PURE__*/React.createElement(View, {
84
25
  className: "t-agent-message-list ".concat(wrapperClassName || ''),
85
26
  "data-testid": "t-agent-message-list",
86
- style: wrapperStyle
87
- }, /*#__PURE__*/React.createElement(ScrollView, _extends({
27
+ style: wrapperStyle,
28
+ id: "message-list"
29
+ }, /*#__PURE__*/React.createElement(ScrollBottomView, {
88
30
  className: "".concat(className || '', " t-agent-message-list-scroll"),
31
+ contentClassName: "t-agent-message-list-scroll-content",
89
32
  style: style,
90
- id: id
91
- }, scrollProps, {
92
- refresherTriggered: false,
93
- enableFlex: true,
94
- scrollY: true,
95
- onScroll: event => {
96
- // 使用了 flex-direction: column-reverse,所以滚动到顶部时,scrollTop = 0
97
- followNewMessageRef.current = event.detail.scrollTop > -10;
98
- }
99
- }), /*#__PURE__*/React.createElement(View, {
100
- className: "t-agent-message-list-padding"
101
- }), reversed.map((msg, index) => {
33
+ onScroll: onScroll,
34
+ hideScrollbar: hideScrollbar
35
+ }, historyLimit && historyLimit.count < messages.length && /*#__PURE__*/React.createElement(View, {
36
+ className: "t-agent-message-list-history-tip"
37
+ }, historyLimit.tipText), /*#__PURE__*/React.createElement(View, {
38
+ className: "t-agent-message-list-padding-start"
39
+ }), props.renderTop, messages.map((msg, index) => {
102
40
  let side = roleSide === null || roleSide === void 0 ? void 0 : roleSide[msg.role];
103
41
  if (!side) {
104
42
  side = msg.role === 'user' ? 'end' : 'start';
105
43
  }
44
+ const isLatestMessage = index === messages.length - 1;
106
45
  return /*#__PURE__*/React.createElement(MessageRender, {
107
46
  showSelect: showSelect,
108
47
  key: msg.id,
109
48
  message: msg,
110
- isLatestMessage: index === 0,
49
+ isLatestMessage: isLatestMessage,
111
50
  side: side
112
51
  });
113
- }), historyLimit && historyLimit.count < reversed.length && /*#__PURE__*/React.createElement(View, {
114
- className: "t-agent-message-list-history-tip"
115
- }, historyLimit.tipText), props.renderTop, /*#__PURE__*/React.createElement(View, {
116
- className: "t-agent-message-list-padding-start"
52
+ }), props.renderBottom, /*#__PURE__*/React.createElement(View, {
53
+ className: "t-agent-message-list-padding"
117
54
  })));
118
- }
55
+ };
56
+ export default MessageList;
@@ -4,21 +4,32 @@
4
4
  overflow-x: hidden;
5
5
  position: relative;
6
6
  background: var(--app-B1);
7
- padding: 16rpx 32rpx 0;
8
7
  }
9
8
 
10
9
  .t-agent-message-list-scroll {
11
- display: flex;
12
10
  width: 100%;
13
11
  height: 100%;
14
- flex-direction: column-reverse;
12
+ }
13
+
14
+ .t-agent-message-list-scroll-content {
15
+ padding: 0 32rpx;
16
+ }
17
+
18
+ .t-agent-message-list-block {
19
+ border: 2rpx solid green;
20
+ }
21
+
22
+ .t-agent-message-list-padding-start {
23
+ height: 16rpx;
15
24
  }
16
25
 
17
26
  .t-agent-message-list-padding {
18
27
  flex: 1
19
28
  }
20
29
 
21
- .t-agent-message-list-padding-start {}
30
+ .t-agent-message-list-hide {
31
+ opacity: 0;
32
+ }
22
33
 
23
34
  .t-agent-message-list-history-tip {
24
35
  width: 100%;
@@ -14,6 +14,7 @@
14
14
  display: flex;
15
15
  flex-direction: column;
16
16
  flex: 1 0 auto;
17
+ width: 100%;
17
18
  }
18
19
 
19
20
  .t-agent-message-list-row-start {
@@ -1,6 +1,6 @@
1
1
  import './index.less';
2
2
  import React, { useCallback, useMemo } from 'react';
3
- import { useChatAgent, useRenderOptions } from '../hooks';
3
+ import { useChatAgent, useNotifyHeightChanged, useRenderOptions } from '../hooks';
4
4
  import { TilePropsContext } from '../contexts';
5
5
  const TileRender = _ref => {
6
6
  let {
@@ -11,6 +11,7 @@ const TileRender = _ref => {
11
11
  } = _ref;
12
12
  const agent = useChatAgent();
13
13
  const emitTileEvent = useCallback(async payload => agent.emitTileEvent(tile.id, payload), [agent, tile.id]);
14
+ const notifyHeightChanged = useNotifyHeightChanged();
14
15
  const {
15
16
  renderTileAs
16
17
  } = useRenderOptions();
@@ -22,9 +23,10 @@ const TileRender = _ref => {
22
23
  side,
23
24
  isLatestMessage,
24
25
  emitEvent: emitTileEvent,
25
- emitTileEvent
26
+ emitTileEvent,
27
+ notifyHeightChanged
26
28
  };
27
- }, [agent, tile, message, side, isLatestMessage, emitTileEvent]);
29
+ }, [agent, tile, message, side, isLatestMessage, emitTileEvent, notifyHeightChanged]);
28
30
  const node = renderTileAs(props);
29
31
  return /*#__PURE__*/React.createElement(TilePropsContext.Provider, {
30
32
  value: props
@@ -2,14 +2,26 @@
2
2
  import { ChatAgent, ChatMessageObject, UIPlugin } from '@ray-js/t-agent';
3
3
  import { RenderOptions, TileProps } from './types';
4
4
  import { ChatSession } from '@ray-js/t-agent';
5
- export declare const MessageContext: import("react").Context<{
6
- messages: ChatMessageObject[];
7
- keyboardHeight: number;
8
- }>;
9
- export declare const RenderContext: import("react").Context<RenderOptions>;
10
5
  export type UIChatSession = Pick<ChatSession, 'get' | 'getData' | 'set' | 'sessionId'>;
11
6
  export type UIChatAgent = Pick<ChatAgent<UIPlugin>, 'pushInputBlocks' | 'plugins' | 'emitTileEvent' | 'removeMessage'> & {
12
7
  session: UIChatSession;
13
8
  };
14
- export declare const ChatAgentContext: import("react").Context<UIChatAgent>;
15
9
  export declare const TilePropsContext: import("react").Context<TileProps<any, any>>;
10
+ declare const SharedProvider: ({ value, children }: import("react").PropsWithChildren<{
11
+ value: {
12
+ agent: UIChatAgent;
13
+ messages: ChatMessageObject[];
14
+ keyboardHeight: number;
15
+ renderOptions: RenderOptions;
16
+ notifyHeightChanged: () => void;
17
+ tickValue: number;
18
+ };
19
+ }>) => import("react").JSX.Element, useSharedState: <K extends "agent" | "messages" | "keyboardHeight" | "renderOptions" | "notifyHeightChanged" | "tickValue">(key: K) => {
20
+ agent: UIChatAgent;
21
+ messages: ChatMessageObject[];
22
+ keyboardHeight: number;
23
+ renderOptions: RenderOptions;
24
+ notifyHeightChanged: () => void;
25
+ tickValue: number;
26
+ }[K];
27
+ export { SharedProvider, useSharedState };
package/dist/contexts.js CHANGED
@@ -1,18 +1,6 @@
1
+ import "core-js/modules/web.dom-collections.iterator.js";
1
2
  import { createContext } from 'react';
2
- export const MessageContext = /*#__PURE__*/createContext({
3
- messages: [],
4
- keyboardHeight: 0
5
- });
6
- export const RenderContext = /*#__PURE__*/createContext({
7
- formatErrorMessageAs: message => message,
8
- renderTileAs: () => null,
9
- renderCustomBlockAs: () => null,
10
- renderCardAs: () => null,
11
- renderLongPressAs: () => null,
12
- customBlockTypes: [],
13
- customCardMap: {},
14
- getStaticResourceBizType: () => '',
15
- i18nTranslate: key => key
16
- });
17
- export const ChatAgentContext = /*#__PURE__*/createContext({});
18
- export const TilePropsContext = /*#__PURE__*/createContext({});
3
+ import { createSharedStore } from './utils/createSharedStore';
4
+ export const TilePropsContext = /*#__PURE__*/createContext({});
5
+ const [SharedProvider, useSharedState] = createSharedStore();
6
+ export { SharedProvider, useSharedState };
@@ -1,11 +1,11 @@
1
1
  import { Dispatch, SetStateAction } from 'react';
2
2
  import { TTTAction } from '../types';
3
3
  export declare const useChatAgent: () => import("../contexts").UIChatAgent;
4
- export declare const useAgentMessage: () => {
5
- messages: import("@ray-js/t-agent").ChatMessageObject[];
6
- keyboardHeight: number;
7
- };
4
+ export declare const useTick: () => number;
5
+ export declare const useNotifyHeightChanged: () => () => void;
6
+ export declare const useAgentMessage: () => import("@ray-js/t-agent").ChatMessageObject[];
8
7
  export declare const useRenderOptions: () => import("../types").RenderOptions;
8
+ export declare const useKeyboardHeight: () => number;
9
9
  export declare const useOnEvent: (eventName: string, callback: (details: any) => void) => void;
10
10
  export declare const useEmitEvent: () => <T extends keyof import("@ray-js/t-agent").UIEventMap>(eventName: T, detail: import("@ray-js/t-agent").UIEventMap[T]) => void;
11
11
  export declare const useTileProps: () => import("../types").TileProps<any, any>;
@@ -1,14 +1,23 @@
1
1
  import "core-js/modules/web.dom-collections.iterator.js";
2
2
  import { useEffect, useContext, useCallback, useRef, useState } from 'react';
3
- import { TilePropsContext, ChatAgentContext, MessageContext, RenderContext } from '../contexts';
3
+ import { TilePropsContext, useSharedState } from '../contexts';
4
4
  export const useChatAgent = () => {
5
- return useContext(ChatAgentContext);
5
+ return useSharedState('agent');
6
+ };
7
+ export const useTick = () => {
8
+ return useSharedState('tickValue');
9
+ };
10
+ export const useNotifyHeightChanged = () => {
11
+ return useSharedState('notifyHeightChanged');
6
12
  };
7
13
  export const useAgentMessage = () => {
8
- return useContext(MessageContext);
14
+ return useSharedState('messages');
9
15
  };
10
16
  export const useRenderOptions = () => {
11
- return useContext(RenderContext);
17
+ return useSharedState('renderOptions');
18
+ };
19
+ export const useKeyboardHeight = () => {
20
+ return useSharedState('keyboardHeight');
12
21
  };
13
22
  export const useOnEvent = (eventName, callback) => {
14
23
  const callbackRef = useRef(callback);
@@ -0,0 +1 @@
1
+ export declare const useStableCallback: <T extends (...args: any[]) => any>(fn: T) => T;
@@ -0,0 +1,13 @@
1
+ import "core-js/modules/web.dom-collections.iterator.js";
2
+ import { useCallback, useRef } from 'react';
3
+ export const useStableCallback = fn => {
4
+ const ref = useRef(fn);
5
+ ref.current = fn;
6
+ const cb = useCallback(function () {
7
+ return ref.current(...arguments);
8
+ }, []);
9
+ if (!fn) {
10
+ return fn;
11
+ }
12
+ return cb;
13
+ };
@@ -108,13 +108,13 @@ const BubbleTile = props => {
108
108
  }), /*#__PURE__*/React.createElement(View, {
109
109
  className: "t-agent-bubble-tile-bubble ".concat(loading ? 't-agent-bubble-tile-bubble-loading' : '')
110
110
  }, (() => {
111
- return /*#__PURE__*/React.createElement(React.Fragment, null, children.map(t => /*#__PURE__*/React.createElement(TileRender, {
111
+ return children.map(t => /*#__PURE__*/React.createElement(TileRender, {
112
112
  side: side,
113
113
  tile: t,
114
114
  message: message,
115
115
  key: t.id,
116
116
  isLatestMessage: isLatestMessage
117
- })));
117
+ }));
118
118
  })(), /*#__PURE__*/React.createElement(LoadingIndicator, {
119
119
  status: status
120
120
  }), showAbortedMessage && /*#__PURE__*/React.createElement(View, {
@@ -126,7 +126,6 @@ const BubbleTile = props => {
126
126
  nodeId: workflowNode
127
127
  }));
128
128
  };
129
- export default /*#__PURE__*/React.memo(BubbleTile);
130
129
  const ErrorNotice = /*#__PURE__*/memo(_ref => {
131
130
  let {
132
131
  bubbleStatus,
@@ -172,4 +171,5 @@ const LoadingIndicator = /*#__PURE__*/memo(_ref2 => {
172
171
  }));
173
172
  }
174
173
  return null;
175
- });
174
+ });
175
+ export default /*#__PURE__*/React.memo(BubbleTile);
@@ -1,17 +1,10 @@
1
1
  import React from 'react';
2
2
  import './index.less';
3
3
  import { TileProps } from '../../types';
4
- export declare enum SceneType {
5
- EXECUTE = 1,
6
- AUTO = 2
7
- }
8
- type DeviceInfoItem = any;
9
- type SceneInfoItem = any;
10
- type ChangeInfoItem = any;
4
+ import { ChangeInfoItem, DeviceInfoItem, SceneInfoItem } from '../types';
11
5
  export interface ExecuteCardTileData {
12
6
  deviceInfo: DeviceInfoItem[];
13
7
  sceneInfo: SceneInfoItem[];
14
8
  deviceShareInfo: ChangeInfoItem[];
15
9
  }
16
10
  export default function ExecuteCardTile(props: TileProps<ExecuteCardTileData>): React.JSX.Element | null;
17
- export {};