@ray-js/t-agent-ui-ray 0.0.9-beta-1 → 0.0.9-beta-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ChatContainer/index.js +21 -1
- package/dist/CustomCardRender/index.js +21 -3
- package/dist/MessageList/index.js +2 -0
- package/dist/MessageList/index.less +2 -0
- package/dist/TileRender/index.js +1 -1
- package/dist/contexts.d.ts +6 -1
- package/dist/contexts.js +2 -1
- package/dist/hooks/context.d.ts +1 -1
- package/dist/tiles/BubbleTile/index.js +1 -0
- package/dist/tiles/CardTile/index.js +2 -1
- package/dist/types.d.ts +9 -3
- package/package.json +2 -2
|
@@ -29,6 +29,26 @@ export default function ChatContainer(props) {
|
|
|
29
29
|
}
|
|
30
30
|
return agent;
|
|
31
31
|
});
|
|
32
|
+
const uiAgent = useMemo(() => {
|
|
33
|
+
const session = {
|
|
34
|
+
get: agent.session.get,
|
|
35
|
+
set: agent.session.set,
|
|
36
|
+
sessionId: agent.session.sessionId,
|
|
37
|
+
getData: agent.session.getData
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(session, 'sessionId', {
|
|
40
|
+
get() {
|
|
41
|
+
return agent.session.sessionId;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
session,
|
|
46
|
+
plugins: agent.plugins,
|
|
47
|
+
pushInputBlocks: agent.pushInputBlocks,
|
|
48
|
+
emitTileEvent: agent.emitTileEvent,
|
|
49
|
+
removeMessage: agent.removeMessage
|
|
50
|
+
};
|
|
51
|
+
}, [agent]);
|
|
32
52
|
useEffect(() => {
|
|
33
53
|
const {
|
|
34
54
|
onEvent,
|
|
@@ -138,7 +158,7 @@ export default function ChatContainer(props) {
|
|
|
138
158
|
't-agent-chat-container-keyboard-show': keyboardHeight > 0
|
|
139
159
|
})
|
|
140
160
|
}, /*#__PURE__*/React.createElement(ChatAgentContext.Provider, {
|
|
141
|
-
value:
|
|
161
|
+
value: uiAgent
|
|
142
162
|
}, /*#__PURE__*/React.createElement(RenderContext.Provider, {
|
|
143
163
|
value: renderOptions
|
|
144
164
|
}, /*#__PURE__*/React.createElement(MessageContext.Provider, {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import './index.less';
|
|
2
2
|
import { View } from '@ray-js/components';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { useRenderOptions } from '../hooks';
|
|
3
|
+
import React, { useCallback, useEffect, useRef } from 'react';
|
|
4
|
+
import { useRenderOptions, useTileProps } from '../hooks';
|
|
5
5
|
export default function CustomCardRender(_ref) {
|
|
6
6
|
let {
|
|
7
7
|
card
|
|
@@ -9,6 +9,23 @@ export default function CustomCardRender(_ref) {
|
|
|
9
9
|
const {
|
|
10
10
|
customCardMap
|
|
11
11
|
} = useRenderOptions();
|
|
12
|
+
const {
|
|
13
|
+
emitEvent
|
|
14
|
+
} = useTileProps();
|
|
15
|
+
const ref = useRef(card);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
ref.current = card;
|
|
18
|
+
});
|
|
19
|
+
const setCardState = useCallback((state, options) => {
|
|
20
|
+
if (typeof state === 'function') {
|
|
21
|
+
state = state(ref.current.cardState);
|
|
22
|
+
}
|
|
23
|
+
emitEvent({
|
|
24
|
+
type: '@buildIn/setCardState',
|
|
25
|
+
state,
|
|
26
|
+
options: options || {}
|
|
27
|
+
});
|
|
28
|
+
}, [emitEvent]);
|
|
12
29
|
const Card = customCardMap[card.cardCode];
|
|
13
30
|
if (!Card) {
|
|
14
31
|
return null;
|
|
@@ -16,6 +33,7 @@ export default function CustomCardRender(_ref) {
|
|
|
16
33
|
return /*#__PURE__*/React.createElement(View, {
|
|
17
34
|
className: "t-agent-custom-card-render"
|
|
18
35
|
}, /*#__PURE__*/React.createElement(Card, {
|
|
19
|
-
card: card
|
|
36
|
+
card: card,
|
|
37
|
+
setCardState: setCardState
|
|
20
38
|
}));
|
|
21
39
|
}
|
package/dist/TileRender/index.js
CHANGED
|
@@ -10,7 +10,7 @@ const TileRender = _ref => {
|
|
|
10
10
|
side
|
|
11
11
|
} = _ref;
|
|
12
12
|
const agent = useChatAgent();
|
|
13
|
-
const emitEvent = useCallback(async payload => agent.emitTileEvent(tile.id, payload), [tile.id]);
|
|
13
|
+
const emitEvent = useCallback(async payload => agent.emitTileEvent(tile.id, payload), [agent, tile.id]);
|
|
14
14
|
const {
|
|
15
15
|
renderTileAs
|
|
16
16
|
} = useRenderOptions();
|
package/dist/contexts.d.ts
CHANGED
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
import { ChatAgent, ChatMessageObject, UIPlugin } from '@ray-js/t-agent';
|
|
3
3
|
import { AssistantPlugin } from '@ray-js/t-agent-plugin-assistant';
|
|
4
4
|
import { RenderOptions, TileProps } from './types';
|
|
5
|
+
import { ChatSession } from '@ray-js/t-agent';
|
|
5
6
|
export declare const MessageContext: import("react").Context<{
|
|
6
7
|
messages: ChatMessageObject[];
|
|
7
8
|
keyboardHeight: number;
|
|
8
9
|
}>;
|
|
9
10
|
export declare const RenderContext: import("react").Context<RenderOptions>;
|
|
10
|
-
export
|
|
11
|
+
export type UIChatSession = Pick<ChatSession, 'get' | 'getData' | 'set' | 'sessionId'>;
|
|
12
|
+
export type UIChatAgent = Pick<ChatAgent<UIPlugin & AssistantPlugin>, 'pushInputBlocks' | 'plugins' | 'emitTileEvent' | 'removeMessage'> & {
|
|
13
|
+
session: UIChatSession;
|
|
14
|
+
};
|
|
15
|
+
export declare const ChatAgentContext: import("react").Context<UIChatAgent>;
|
|
11
16
|
export declare const TilePropsContext: import("react").Context<TileProps<any, any>>;
|
package/dist/contexts.js
CHANGED
|
@@ -9,7 +9,8 @@ export const RenderContext = /*#__PURE__*/createContext({
|
|
|
9
9
|
renderCardAs: () => null,
|
|
10
10
|
customBlockTypes: [],
|
|
11
11
|
customCardMap: {},
|
|
12
|
-
getStaticResourceBizType: () => ''
|
|
12
|
+
getStaticResourceBizType: () => '',
|
|
13
|
+
i18nTranslate: key => key
|
|
13
14
|
});
|
|
14
15
|
export const ChatAgentContext = /*#__PURE__*/createContext({});
|
|
15
16
|
export const TilePropsContext = /*#__PURE__*/createContext({});
|
package/dist/hooks/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TTTAction } from '@ray-js/t-agent-plugin-assistant';
|
|
2
|
-
export declare const useChatAgent: () => import("
|
|
2
|
+
export declare const useChatAgent: () => import("../contexts").UIChatAgent;
|
|
3
3
|
export declare const useAgentMessage: () => {
|
|
4
4
|
messages: import("@ray-js/t-agent").ChatMessageObject[];
|
|
5
5
|
keyboardHeight: number;
|
|
@@ -85,6 +85,7 @@ const BubbleTile = props => {
|
|
|
85
85
|
}
|
|
86
86
|
return /*#__PURE__*/React.createElement(View, {
|
|
87
87
|
className: "t-agent-bubble-tile t-agent-bubble-tile-".concat(side),
|
|
88
|
+
"data-testid": "t-agent-bubble-tile",
|
|
88
89
|
onLongPress: () => {}
|
|
89
90
|
}, side === 'end' && errorNode, /*#__PURE__*/React.createElement(View, {
|
|
90
91
|
className: "t-agent-bubble-tile-bubble ".concat(loading ? 't-agent-bubble-tile-bubble-loading' : '')
|
|
@@ -14,7 +14,8 @@ const CardTile = props => {
|
|
|
14
14
|
return null;
|
|
15
15
|
}
|
|
16
16
|
return /*#__PURE__*/React.createElement(View, {
|
|
17
|
-
className: "t-agent-card-tile"
|
|
17
|
+
className: "t-agent-card-tile",
|
|
18
|
+
"data-testid": "t-agent-bubble-tile"
|
|
18
19
|
}, node);
|
|
19
20
|
};
|
|
20
21
|
export default /*#__PURE__*/React.memo(CardTile);
|
package/dist/types.d.ts
CHANGED
|
@@ -14,14 +14,20 @@ export interface MarkdownBlock {
|
|
|
14
14
|
children: string;
|
|
15
15
|
map: [number, number];
|
|
16
16
|
}
|
|
17
|
+
export type ChatCardComponent<T = any, S = any> = React.ComponentType<{
|
|
18
|
+
card: ChatCardObject<T, S>;
|
|
19
|
+
setCardState: ChatCardComponentSetCardState<S>;
|
|
20
|
+
}>;
|
|
21
|
+
export interface ChatCardComponentSetCardStateOptions {
|
|
22
|
+
persist?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export type ChatCardComponentSetCardState<S = any> = (state: S | ((prev: S | undefined) => S), options?: ChatCardComponentSetCardStateOptions) => void;
|
|
17
25
|
export interface RenderOptions {
|
|
18
26
|
renderTileAs: (props: TileProps) => React.ReactNode;
|
|
19
27
|
renderCustomBlockAs: (block: MarkdownBlock) => React.ReactNode;
|
|
20
28
|
renderCardAs: (card: ChatCardObject) => React.ReactNode;
|
|
21
29
|
customBlockTypes: string[];
|
|
22
|
-
customCardMap: Record<string,
|
|
23
|
-
card: ChatCardObject;
|
|
24
|
-
}>>;
|
|
30
|
+
customCardMap: Record<string, ChatCardComponent>;
|
|
25
31
|
getStaticResourceBizType: (src: string, scene?: string, data?: any) => string;
|
|
26
32
|
i18nTranslate: (key: string) => string;
|
|
27
33
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/t-agent-ui-ray",
|
|
3
|
-
"version": "0.0.9-beta-
|
|
3
|
+
"version": "0.0.9-beta-3",
|
|
4
4
|
"author": "Tuya.inc",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"@types/echarts": "^4.9.22",
|
|
42
42
|
"@types/markdown-it": "^14.1.1"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "7330e1a07e32629668a6edf933d4682f286d957a"
|
|
45
45
|
}
|