@asgard-js/react 0.2.39 → 0.2.40-canary.1
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 +69 -0
- package/dist/components/chatbot/chatbot.d.ts +7 -0
- package/dist/components/chatbot/chatbot.d.ts.map +1 -1
- package/dist/index.js +6745 -6744
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -318,6 +318,7 @@ config: {
|
|
|
318
318
|
- **messageActions?**: `(message: ConversationBotMessage) => MessageActionConfig[]` - Function to define which action buttons to display for each bot message. Returns an array of `{ id: string, label: string }` objects. See [Message Actions](#message-actions) section for details.
|
|
319
319
|
- **onMessageAction?**: `(actionId: string, message: ConversationBotMessage) => void` - Callback when a message action button is clicked. Receives the action ID and the associated bot message.
|
|
320
320
|
- **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.
|
|
321
|
+
- **renderFooter?**: `() => ReactNode` - Custom footer renderer. When provided, completely replaces the default footer. Use `useAsgardContext()` inside the render function to access `sendMessage`, `isConnecting`, `pendingInputValue`, `setPendingInputValue`, etc. See [Custom Footer](#custom-footer) section for details.
|
|
321
322
|
- **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.
|
|
322
323
|
- **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.
|
|
323
324
|
- **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.
|
|
@@ -1320,6 +1321,74 @@ const App = () => {
|
|
|
1320
1321
|
};
|
|
1321
1322
|
```
|
|
1322
1323
|
|
|
1324
|
+
<a id="custom-footer"></a>
|
|
1325
|
+
<br/>
|
|
1326
|
+
|
|
1327
|
+
### Custom Footer
|
|
1328
|
+
|
|
1329
|
+
The `renderFooter` prop allows you to completely replace the default chatbot footer with your own implementation. This is useful when the built-in input bar does not match your product's interaction pattern (e.g. fixed quick-reply buttons, custom send mechanics, or extra action buttons that cannot be expressed via `enableUpload` / `enableExport` / `enableDocumentUpload`).
|
|
1330
|
+
|
|
1331
|
+
Use `useAsgardContext()` inside your custom footer to access `sendMessage`, `isConnecting`, `pendingInputValue`, `setPendingInputValue`, and other internal state. When `sendMessage` is `undefined`, the chatbot is in preview mode — disable input accordingly.
|
|
1332
|
+
|
|
1333
|
+
#### Usage Example
|
|
1334
|
+
|
|
1335
|
+
```typescript
|
|
1336
|
+
import { useEffect, useRef, useState } from 'react';
|
|
1337
|
+
import { Chatbot, useAsgardContext } from '@asgard-js/react';
|
|
1338
|
+
|
|
1339
|
+
function CustomFooter() {
|
|
1340
|
+
const { sendMessage, isConnecting, pendingInputValue, setPendingInputValue } = useAsgardContext();
|
|
1341
|
+
const [value, setValue] = useState('');
|
|
1342
|
+
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
|
1343
|
+
|
|
1344
|
+
useEffect(() => {
|
|
1345
|
+
if (pendingInputValue === null) return;
|
|
1346
|
+
|
|
1347
|
+
setValue(pendingInputValue);
|
|
1348
|
+
setPendingInputValue(null);
|
|
1349
|
+
textareaRef.current?.focus();
|
|
1350
|
+
}, [pendingInputValue, setPendingInputValue]);
|
|
1351
|
+
|
|
1352
|
+
const isPreviewMode = !sendMessage;
|
|
1353
|
+
const trimmed = value.trim();
|
|
1354
|
+
const disabled = isPreviewMode || isConnecting || !trimmed;
|
|
1355
|
+
|
|
1356
|
+
const submit = () => {
|
|
1357
|
+
if (disabled) return;
|
|
1358
|
+
|
|
1359
|
+
sendMessage?.({ text: trimmed });
|
|
1360
|
+
setValue('');
|
|
1361
|
+
};
|
|
1362
|
+
|
|
1363
|
+
return (
|
|
1364
|
+
<div style={{ display: 'flex', gap: 8, padding: '12px 16px', borderTop: '1px solid #eee' }}>
|
|
1365
|
+
<textarea
|
|
1366
|
+
ref={textareaRef}
|
|
1367
|
+
value={value}
|
|
1368
|
+
onChange={e => setValue(e.target.value)}
|
|
1369
|
+
disabled={isPreviewMode}
|
|
1370
|
+
placeholder={isPreviewMode ? 'Preview mode' : 'Type a message'}
|
|
1371
|
+
style={{ flex: 1 }}
|
|
1372
|
+
/>
|
|
1373
|
+
<button onClick={submit} disabled={disabled}>
|
|
1374
|
+
Send
|
|
1375
|
+
</button>
|
|
1376
|
+
</div>
|
|
1377
|
+
);
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
const App = () => (
|
|
1381
|
+
<Chatbot
|
|
1382
|
+
config={{
|
|
1383
|
+
apiKey: 'your-api-key',
|
|
1384
|
+
botProviderEndpoint: 'https://api.asgard-ai.com/ns/{namespace}/bot-provider/{botProviderId}',
|
|
1385
|
+
}}
|
|
1386
|
+
customChannelId="your-channel-id"
|
|
1387
|
+
renderFooter={() => <CustomFooter />}
|
|
1388
|
+
/>
|
|
1389
|
+
);
|
|
1390
|
+
```
|
|
1391
|
+
|
|
1323
1392
|
<a id="custom-menu"></a>
|
|
1324
1393
|
<br/>
|
|
1325
1394
|
|
|
@@ -52,6 +52,13 @@ interface ChatbotProps extends AsgardTemplateContextValue {
|
|
|
52
52
|
onChannelReady?: () => void;
|
|
53
53
|
/** Custom header renderer. When provided, replaces the default header entirely. */
|
|
54
54
|
renderHeader?: () => ReactNode;
|
|
55
|
+
/**
|
|
56
|
+
* Custom footer renderer. When provided, replaces the default footer
|
|
57
|
+
* entirely. Use `useAsgardContext()` inside the renderer to access
|
|
58
|
+
* `sendMessage`, `isConnecting`, `pendingInputValue`, `setPendingInputValue`,
|
|
59
|
+
* etc. Mirrors the pattern of `renderHeader`.
|
|
60
|
+
*/
|
|
61
|
+
renderFooter?: () => ReactNode;
|
|
55
62
|
/** Custom menu renderer. When provided, renders between chat body and footer. */
|
|
56
63
|
renderMenu?: () => ReactNode;
|
|
57
64
|
/** Custom renderer for tool call group. Return null to hide, or return custom JSX. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatbot.d.ts","sourceRoot":"","sources":["../../../src/components/chatbot/chatbot.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,SAAS,EACT,aAAa,EAId,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAA8B,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AACzG,OAAO,EAEL,yBAAyB,EAEzB,0BAA0B,EAE1B,iCAAiC,EAGjC,iBAAiB,EAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAY5C,UAAU,YAAa,SAAQ,0BAA0B;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,SAAS,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACzC,MAAM,EAAE,YAAY,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACrC,YAAY,CAAC,EAAE,iCAAiC,CAAC,cAAc,CAAC,CAAC;IACjE,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB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