@asgard-js/react 0.2.34-canary.2 → 0.2.34
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/README.md
CHANGED
|
@@ -317,6 +317,7 @@ config: {
|
|
|
317
317
|
- **renderHeader?**: `() => ReactNode` - Custom header renderer. When provided, completely replaces the default header. Use `useAsgardContext()` inside the render function to access `resetChannel`, `isResetting`, and other internal state.
|
|
318
318
|
- **renderMenu?**: `() => ReactNode` - Custom menu renderer. When provided, renders content between the chat body and footer. Useful for quick menus, suggested questions, or navigation panels. See [Custom Menu](#custom-menu) section for details.
|
|
319
319
|
- **renderMessageContent?**: `(props: MessageContentRendererProps) => ReactNode` - Custom renderer for message content. Allows customizing how messages are rendered based on message properties. See [Custom Message Renderer](#custom-message-renderer) section for details.
|
|
320
|
+
- **renderToolCallGroup?**: `(props: ToolCallGroupRendererProps) => ReactNode` - Custom renderer for tool call group. Return `null` to hide, return JSX to fully customize, or call `renderDefaultContent()` to use the default UI with optional overrides (e.g., `renderDefaultContent({ title: 'AI is thinking...' })`). See [Tool Call Group Renderer](#tool-call-group-renderer) section for details.
|
|
320
321
|
- **onBeforeSendMessage?**: `(params: SendMessageParams) => SendMessageParams` - Callback to modify message params before sending. Allows injecting contextual data (payload, metadata) from parent components. See [Before Send Message Hook](#before-send-message-hook) section for details.
|
|
321
322
|
- **onSseMessage**: `(response: SseResponse, ctx: AsgardServiceContextValue) => void` - Callback function when SSE message is received. It would be helpful if using with the ref to provide some context and conversation data and do some proactively actions like sending messages to the bot.
|
|
322
323
|
- **ref**: `ForwardedRef<ChatbotRef>` - Forwarded ref to access the chatbot instance. It can be used to access the chatbot instance and do some actions like sending messages to the bot. `ChatbotRef` provides `serviceContext` for interacting with the chatbot, and `setInputValue(value: string)` for programmatically setting the textarea text from outside the component.
|
|
@@ -592,7 +593,7 @@ Note: When `fullScreen` prop is set to `true`, the chatbot's width and height wi
|
|
|
592
593
|
|
|
593
594
|
### Tool Call Handler
|
|
594
595
|
|
|
595
|
-
The `onToolCall` callback allows you to handle tool call events from the bot. This handler is triggered when the bot starts or completes executing a tool call. See the [Tool Call Start documentation](https://
|
|
596
|
+
The `onToolCall` callback allows you to handle tool call events from the bot. This handler is triggered when the bot starts or completes executing a tool call. See the [Tool Call Start documentation](https://docs.asgard-ai.com/docs/developer-reference/api-doc/send-message/sse-response/asgard-tool-call-start) and [Tool Call Complete documentation](https://docs.asgard-ai.com/docs/developer-reference/api-doc/send-message/sse-response/asgard-tool-call-complete) for details.
|
|
596
597
|
|
|
597
598
|
The callback receives a `SseResponse` object with one of the following event types:
|
|
598
599
|
|
|
@@ -699,13 +700,13 @@ const handleToolCall = (response: SseResponse<EventType.TOOL_CALL_START | EventT
|
|
|
699
700
|
|
|
700
701
|
### EMIT Action
|
|
701
702
|
|
|
702
|
-
EMIT buttons allow you to handle custom actions in your application. Implement the `onTemplateBtnClick` callback to process these events. See the [EMIT Action documentation](https://
|
|
703
|
+
EMIT buttons allow you to handle custom actions in your application. Implement the `onTemplateBtnClick` callback to process these events. See the [EMIT Action documentation](https://docs.asgard-ai.com/docs/developer-reference/asgard-builtin/message-template-action-object-emit) for details.
|
|
703
704
|
|
|
704
705
|
The callback receives the following parameters:
|
|
705
706
|
|
|
706
707
|
1. `payload` (optional): Custom data from the button action
|
|
707
708
|
2. `eventName` (required): Event name specified in the button action
|
|
708
|
-
3. `raw` (required): Complete SSE response data as JSON string. Use this when you need information beyond `payload` and `eventName`. Parse it to access additional fields from the original SSE response. See [SSE Response documentation](https://
|
|
709
|
+
3. `raw` (required): Complete SSE response data as JSON string. Use this when you need information beyond `payload` and `eventName`. Parse it to access additional fields from the original SSE response. See [SSE Response documentation](https://docs.asgard-ai.com/docs/developer-reference/api-doc/send-message/sse-response/message-complete) for the complete response structure.
|
|
709
710
|
|
|
710
711
|
Configure EMIT buttons in your backend SSE response:
|
|
711
712
|
|
|
@@ -834,6 +835,75 @@ messageActions={(message) => {
|
|
|
834
835
|
<a id="custom-message-renderer"></a>
|
|
835
836
|
<br/>
|
|
836
837
|
|
|
838
|
+
<a id="tool-call-group-renderer"></a>
|
|
839
|
+
<br/>
|
|
840
|
+
|
|
841
|
+
### Tool Call Group Renderer
|
|
842
|
+
|
|
843
|
+
The `renderToolCallGroup` prop allows you to customize or hide the "Answer preparation steps" UI that appears when the bot calls tools before responding.
|
|
844
|
+
|
|
845
|
+
#### ToolCallGroupRendererProps Interface
|
|
846
|
+
|
|
847
|
+
```typescript
|
|
848
|
+
interface ToolCallGroupRendererProps {
|
|
849
|
+
/** Tool call items in the group */
|
|
850
|
+
items: ToolCallItemData[];
|
|
851
|
+
/** Timestamp of the first tool call */
|
|
852
|
+
time?: Date;
|
|
853
|
+
/** Function to render the default tool call group UI. Accepts optional overrides. */
|
|
854
|
+
renderDefaultContent: (overrides?: { title?: string }) => ReactNode;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
interface ToolCallItemData {
|
|
858
|
+
id: string;
|
|
859
|
+
label: string;
|
|
860
|
+
status: 'pending' | 'completed' | 'error';
|
|
861
|
+
initial?: Record<string, unknown>;
|
|
862
|
+
result?: Record<string, unknown>;
|
|
863
|
+
}
|
|
864
|
+
```
|
|
865
|
+
|
|
866
|
+
#### Hide completely
|
|
867
|
+
|
|
868
|
+
```typescript
|
|
869
|
+
<Chatbot
|
|
870
|
+
renderToolCallGroup={() => null}
|
|
871
|
+
...
|
|
872
|
+
/>
|
|
873
|
+
```
|
|
874
|
+
|
|
875
|
+
#### Custom title
|
|
876
|
+
|
|
877
|
+
```typescript
|
|
878
|
+
<Chatbot
|
|
879
|
+
renderToolCallGroup={({ renderDefaultContent }) =>
|
|
880
|
+
renderDefaultContent({ title: 'AI is thinking...' })
|
|
881
|
+
}
|
|
882
|
+
...
|
|
883
|
+
/>
|
|
884
|
+
```
|
|
885
|
+
|
|
886
|
+
#### Custom UI
|
|
887
|
+
|
|
888
|
+
```typescript
|
|
889
|
+
<Chatbot
|
|
890
|
+
renderToolCallGroup={({ items }) => {
|
|
891
|
+
const done = items.filter(i => i.status === 'completed').length;
|
|
892
|
+
return (
|
|
893
|
+
<div>
|
|
894
|
+
{done === items.length
|
|
895
|
+
? `✅ ${done} steps completed`
|
|
896
|
+
: `⏳ Processing...`}
|
|
897
|
+
</div>
|
|
898
|
+
);
|
|
899
|
+
}}
|
|
900
|
+
...
|
|
901
|
+
/>
|
|
902
|
+
```
|
|
903
|
+
|
|
904
|
+
<a id="custom-message-renderer"></a>
|
|
905
|
+
<br/>
|
|
906
|
+
|
|
837
907
|
### Custom Message Renderer
|
|
838
908
|
|
|
839
909
|
The `renderMessageContent` prop allows you to customize how messages are rendered based on message type, payload, or other conditions. This is useful for implementing custom message cards, special UI treatments, or integrating with your application's design system.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatbot-body.d.ts","sourceRoot":"","sources":["../../../../src/components/chatbot/chatbot-body/chatbot-body.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAA2C,MAAM,OAAO,CAAC;AAkErF,wBAAgB,WAAW,IAAI,SAAS,
|
|
1
|
+
{"version":3,"file":"chatbot-body.d.ts","sourceRoot":"","sources":["../../../../src/components/chatbot/chatbot-body/chatbot-body.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAA2C,MAAM,OAAO,CAAC;AAkErF,wBAAgB,WAAW,IAAI,SAAS,CAwHvC"}
|
|
@@ -28,6 +28,19 @@ export interface MessageContentRendererProps {
|
|
|
28
28
|
/** Container component that wraps custom content with Avatar for bot messages */
|
|
29
29
|
MessageContainer: FC<MessageContainerProps>;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Props passed to the custom tool call group renderer function
|
|
33
|
+
*/
|
|
34
|
+
export interface ToolCallGroupRendererProps {
|
|
35
|
+
/** Tool call items in the group */
|
|
36
|
+
items: ToolCallItemData[];
|
|
37
|
+
/** Timestamp of the first tool call */
|
|
38
|
+
time?: Date;
|
|
39
|
+
/** Function to render the default tool call group UI. Accepts optional overrides. */
|
|
40
|
+
renderDefaultContent: (overrides?: {
|
|
41
|
+
title?: string;
|
|
42
|
+
}) => ReactNode;
|
|
43
|
+
}
|
|
31
44
|
export interface AsgardTemplateContextValue {
|
|
32
45
|
onErrorClick?: (message: ConversationErrorMessage) => void;
|
|
33
46
|
errorMessageRenderer?: (message: ConversationErrorMessage) => ReactNode;
|
|
@@ -40,10 +53,7 @@ export interface AsgardTemplateContextValue {
|
|
|
40
53
|
/** Custom renderer for message content. Allows customizing how messages are rendered based on message properties. */
|
|
41
54
|
renderMessageContent?: (props: MessageContentRendererProps) => ReactNode;
|
|
42
55
|
/** Custom renderer for tool call group. Return null to hide, or return custom JSX. */
|
|
43
|
-
renderToolCallGroup?: (
|
|
44
|
-
time?: Date;
|
|
45
|
-
defaultRender: () => ReactNode;
|
|
46
|
-
}) => ReactNode;
|
|
56
|
+
renderToolCallGroup?: (props: ToolCallGroupRendererProps) => ReactNode;
|
|
47
57
|
}
|
|
48
58
|
export declare const AsgardTemplateContext: import('react').Context<AsgardTemplateContextValue>;
|
|
49
59
|
interface AsgardTemplateContextProviderProps extends PropsWithChildren {
|
|
@@ -54,10 +64,7 @@ interface AsgardTemplateContextProviderProps extends PropsWithChildren {
|
|
|
54
64
|
messageActions?: (message: ConversationBotMessage) => MessageActionConfig[];
|
|
55
65
|
onMessageAction?: (actionId: string, message: ConversationBotMessage) => void;
|
|
56
66
|
renderMessageContent?: (props: MessageContentRendererProps) => ReactNode;
|
|
57
|
-
renderToolCallGroup?: (
|
|
58
|
-
time?: Date;
|
|
59
|
-
defaultRender: () => ReactNode;
|
|
60
|
-
}) => ReactNode;
|
|
67
|
+
renderToolCallGroup?: (props: ToolCallGroupRendererProps) => ReactNode;
|
|
61
68
|
}
|
|
62
69
|
export declare function AsgardTemplateContextProvider(props: AsgardTemplateContextProviderProps): ReactNode;
|
|
63
70
|
export declare function useAsgardTemplateContext(): AsgardTemplateContextValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asgard-template-context.d.ts","sourceRoot":"","sources":["../../src/context/asgard-template-context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,EAAE,EAAE,iBAAiB,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AAC7F,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACxG,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,uCAAuC;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,kCAAkC;IAClC,OAAO,EAAE,mBAAmB,CAAC;IAC7B,qDAAqD;IACrD,oBAAoB,EAAE,MAAM,SAAS,CAAC;IACtC,iFAAiF;IACjF,gBAAgB,EAAE,EAAE,CAAC,qBAAqB,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,0BAA0B;IACzC,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,wBAAwB,KAAK,IAAI,CAAC;IAC3D,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,wBAAwB,KAAK,SAAS,CAAC;IACxE,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAChG,iBAAiB,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;IAC5D,uEAAuE;IACvE,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,sBAAsB,KAAK,mBAAmB,EAAE,CAAC;IAC5E,uDAAuD;IACvD,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB,KAAK,IAAI,CAAC;IAC9E,qHAAqH;IACrH,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,2BAA2B,KAAK,SAAS,CAAC;IACzE,sFAAsF;IACtF,mBAAmB,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"asgard-template-context.d.ts","sourceRoot":"","sources":["../../src/context/asgard-template-context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,EAAE,EAAE,iBAAiB,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AAC7F,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACxG,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,uCAAuC;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,kCAAkC;IAClC,OAAO,EAAE,mBAAmB,CAAC;IAC7B,qDAAqD;IACrD,oBAAoB,EAAE,MAAM,SAAS,CAAC;IACtC,iFAAiF;IACjF,gBAAgB,EAAE,EAAE,CAAC,qBAAqB,CAAC,CAAC;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,mCAAmC;IACnC,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,uCAAuC;IACvC,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,qFAAqF;IACrF,oBAAoB,EAAE,CAAC,SAAS,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,SAAS,CAAC;CACrE;AAED,MAAM,WAAW,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,sBAAsB,KAAK,mBAAmB,EAAE,CAAC;IAC5E,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB,KAAK,IAAI,CAAC;IAC9E,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,2BAA2B,KAAK,SAAS,CAAC;IACzE,mBAAmB,CAAC,EAAE,CAAC,KAAK,EAAE,0BAA0B,KAAK,SAAS,CAAC;CACxE;AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,kCAAkC,GAAG,SAAS,CAqClG;AAED,wBAAgB,wBAAwB,IAAI,0BAA0B,CAErE"}
|
package/dist/index.js
CHANGED
|
@@ -41789,11 +41789,12 @@ function i_e() {
|
|
|
41789
41789
|
children: /* @__PURE__ */ V("div", { ref: f, className: t1.chatbot_body__content, style: h, children: [
|
|
41790
41790
|
t_e(Array.from(n?.values() ?? [])).map((p, g) => {
|
|
41791
41791
|
if (p.type === "tool-call-group") {
|
|
41792
|
-
const m = p.toolCalls.map(n_e), y = p.toolCalls[0], _ = `tool-call-group-${y?.processId || g}`, b = () => /* @__PURE__ */ k(Nye, { items: m, time: y?.time });
|
|
41792
|
+
const m = p.toolCalls.map(n_e), y = p.toolCalls[0], _ = `tool-call-group-${y?.processId || g}`, b = (v) => /* @__PURE__ */ k(Nye, { items: m, time: y?.time, title: v?.title });
|
|
41793
41793
|
if (t) {
|
|
41794
|
-
const v = t(
|
|
41794
|
+
const v = t({
|
|
41795
|
+
items: m,
|
|
41795
41796
|
time: y?.time,
|
|
41796
|
-
|
|
41797
|
+
renderDefaultContent: b
|
|
41797
41798
|
});
|
|
41798
41799
|
return v === null ? null : /* @__PURE__ */ k(qk, { children: v }, _);
|
|
41799
41800
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asgard-js/react",
|
|
3
|
-
"version": "0.2.34
|
|
3
|
+
"version": "0.2.34",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"vite-plugin-svgr": "^4.3.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@asgard-js/core": "^0.2.
|
|
49
|
+
"@asgard-js/core": "^0.2.34",
|
|
50
50
|
"react": "^18.0.0 || ^19.0.0",
|
|
51
51
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
52
52
|
}
|