@smarter.sh/ui-chat 0.8.0 → 0.9.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 +328 -107
- package/dist/embed/katex/fonts/KaTeX_AMS-Regular.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_Main-Bold.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_Main-Italic.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_Main-Regular.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_Math-Italic.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_Script-Regular.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_Size1-Regular.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_Size2-Regular.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_Size3-Regular.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_Size4-Regular.woff2 +0 -0
- package/dist/embed/katex/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
- package/dist/embed/mermaid/abnfDiagram-VCTEODGH-CGtrctwA.js +89 -0
- package/dist/embed/mermaid/arc-DlzgcAgU.js +82 -0
- package/dist/embed/mermaid/architecture-7GRP2DOG-D66ObL4C.js +3 -0
- package/dist/embed/mermaid/architectureDiagram-5GKGNRK7-CgMNWdVn.js +4148 -0
- package/dist/embed/mermaid/array-CApNbSU9.js +6 -0
- package/dist/embed/mermaid/blockDiagram-I7D4REHJ-Q2YOF2Nl.js +1922 -0
- package/dist/embed/mermaid/c4Diagram-7LVT6UL2-DI7_cX7n.js +3010 -0
- package/dist/embed/mermaid/channel-CxRe6Ync.js +5 -0
- package/dist/embed/mermaid/chunk-2E4U76K2-DPc-jkQd.js +348 -0
- package/dist/embed/mermaid/chunk-2Q5K7J3B-C1pX24ft.js +15 -0
- package/dist/embed/mermaid/chunk-4HAMMTFA-DY_JmJA2.js +4188 -0
- package/dist/embed/mermaid/chunk-5VM5RSS4-BFskf6Qk.js +5 -0
- package/dist/embed/mermaid/chunk-75Z2AOVW-BugNeXEB.js +1330 -0
- package/dist/embed/mermaid/chunk-CLGD4ZFX-BOKCMNQY.js +14 -0
- package/dist/embed/mermaid/chunk-DU6HZSFF-C09wkxIu.js +3897 -0
- package/dist/embed/mermaid/chunk-F27PBJKO-C69L38at.js +61 -0
- package/dist/embed/mermaid/chunk-FOHPRMQF-CLLDWcGe.js +21458 -0
- package/dist/embed/mermaid/chunk-GMAD6QVW-NxqJJwNT.js +1863 -0
- package/dist/embed/mermaid/chunk-GVQU2GXP-D4WoQcNg.js +37 -0
- package/dist/embed/mermaid/chunk-IMKFNOWR-DE94S7XC.js +2042 -0
- package/dist/embed/mermaid/chunk-JWPE2WC7-BGVSGRTC.js +8 -0
- package/dist/embed/mermaid/chunk-L3NEJ4N5-CqdtyK-9.js +245 -0
- package/dist/embed/mermaid/chunk-LNGE3PJU-DqC_0r8u.js +1521 -0
- package/dist/embed/mermaid/chunk-OSK3NFVY-B1KjtHOy.js +672 -0
- package/dist/embed/mermaid/chunk-P2QGCYS3-CP_jp-eQ.js +67 -0
- package/dist/embed/mermaid/chunk-POPQ4Y6H-CSwFrYKY.js +26 -0
- package/dist/embed/mermaid/chunk-PWAF6VOD-qhXJD1mO.js +275 -0
- package/dist/embed/mermaid/chunk-SHT3W25Y-a5ik03bR.js +4183 -0
- package/dist/embed/mermaid/chunk-SVP7TREG-67QXjHHx.js +490 -0
- package/dist/embed/mermaid/chunk-TICWLB2K-DHg0COuy.js +3357 -0
- package/dist/embed/mermaid/chunk-TLUHSLCS-BwEhuf5d.js +59 -0
- package/dist/embed/mermaid/chunk-XXDRQBXY-BJjzBm4h.js +9 -0
- package/dist/embed/mermaid/chunk-Y2CYZVJY-BAad7w_K.js +12 -0
- package/dist/embed/mermaid/classDiagram-ZZMXUADV-BlIPVBOk.js +30 -0
- package/dist/embed/mermaid/classDiagram-v2-VYDZK3BY-BavoJkSK.js +30 -0
- package/dist/embed/mermaid/cose-bilkent-JH36ORCC-Cx3-7Rca.js +2248 -0
- package/dist/embed/mermaid/cynefin-OW5HDTMX-Cfa1-YuM.js +3 -0
- package/dist/embed/mermaid/cynefinDiagram-5FMLGOSQ-CsV1I6A_.js +355 -0
- package/dist/embed/mermaid/cytoscape.esm-CLcfvFJ6.js +18145 -0
- package/dist/embed/mermaid/dagre-COnXXJRS.js +1934 -0
- package/dist/embed/mermaid/dagre-GXQ25YYZ-BzZWpDkI.js +425 -0
- package/dist/embed/mermaid/defaultLocale-CQ4Nl88y.js +198 -0
- package/dist/embed/mermaid/diagram-S7CK7UJ4-CShsH_ul.js +301 -0
- package/dist/embed/mermaid/diagram-UQ7AKVKN-Bb0mFpt2.js +214 -0
- package/dist/embed/mermaid/diagram-VSXAHHWV-DUq5PKM1.js +432 -0
- package/dist/embed/mermaid/diagram-VX7I27RA-Co2uyrw2.js +527 -0
- package/dist/embed/mermaid/diagram-Z3DM3KII-CTdPPkZs.js +134 -0
- package/dist/embed/mermaid/dist-CjR2JtV-.js +59 -0
- package/dist/embed/mermaid/ebnfDiagram-PWID7BFC-CAQNT7Vt.js +100 -0
- package/dist/embed/mermaid/erDiagram-RLTQ6QDP-DluYOFtk.js +1966 -0
- package/dist/embed/mermaid/eventmodeling-NTZA5JFV-DFSPvGS4.js +3 -0
- package/dist/embed/mermaid/flowDiagram-HODETNUW-BKXSV8xL.js +17 -0
- package/dist/embed/mermaid/ganttDiagram-EL5Y4UJY-D2BBzcpY.js +3072 -0
- package/dist/embed/mermaid/gitGraph-4MIJSDKK-BTHPY7Tg.js +3 -0
- package/dist/embed/mermaid/gitGraphDiagram-WWUBYQGX-BzZ3sE3s.js +733 -0
- package/dist/embed/mermaid/graphlib-D8JS7ydf.js +1267 -0
- package/dist/embed/mermaid/info-A6RAGUB7-4Mm0OyB8.js +3 -0
- package/dist/embed/mermaid/infoDiagram-27XIBGKW-DcbKIVvy.js +20 -0
- package/dist/embed/mermaid/init-CFNf60QB.js +13 -0
- package/dist/embed/mermaid/ishikawaDiagram-5VMMS53U-B6q3rvke.js +719 -0
- package/dist/embed/mermaid/journeyDiagram-3NMN7TZE-CDDY2Xma.js +884 -0
- package/dist/embed/mermaid/kanban-definition-UXKFOSKX-w7v22sq3.js +976 -0
- package/dist/embed/mermaid/katex-BqirFtOb.js +21977 -0
- package/dist/embed/mermaid/line-DoUHpRzu.js +34 -0
- package/dist/embed/mermaid/linear-CLS335Sc.js +287 -0
- package/dist/embed/mermaid/mermaid-parser.core-BoI6HFCg.js +638 -0
- package/dist/embed/mermaid/mermaid.js +1092 -0
- package/dist/embed/mermaid/mindmap-definition-YA3MSWOX-1bs_tKMD.js +1006 -0
- package/dist/embed/mermaid/ordinal-Da0rnhxr.js +65 -0
- package/dist/embed/mermaid/packet-AYTQ26CC-BAodtDR3.js +3 -0
- package/dist/embed/mermaid/path-hN9ktzbr.js +84 -0
- package/dist/embed/mermaid/pegDiagram-XKGWAZYB-DsrQs7Qo.js +94 -0
- package/dist/embed/mermaid/pie-WAS4IAKB-Yw-9-2EN.js +3 -0
- package/dist/embed/mermaid/pieDiagram-E7YTZNPT-BvkRs6Xl.js +203 -0
- package/dist/embed/mermaid/quadrantDiagram-AXDQQJYC-DDSDkbcq.js +2001 -0
- package/dist/embed/mermaid/radar-RG4KPBEZ-BtjjaEPe.js +3 -0
- package/dist/embed/mermaid/railroad-74A4TZTK-Du7TjeaO.js +3 -0
- package/dist/embed/mermaid/railroad-abnf-HS5TGJTU-D3flpty6.js +3 -0
- package/dist/embed/mermaid/railroad-ebnf-LZEXJU2U-DWpeYHWC.js +3 -0
- package/dist/embed/mermaid/railroad-peg-WCYAUIDC-DKiyz9fh.js +3 -0
- package/dist/embed/mermaid/railroadDiagram-O6MQD6OU-T__Cw3ez.js +76 -0
- package/dist/embed/mermaid/requirementDiagram-BXWQKSXE-ADir8pgL.js +2224 -0
- package/dist/embed/mermaid/rough.esm-XhrPyaQA.js +1361 -0
- package/dist/embed/mermaid/sankeyDiagram-P5KCCOFB-YTgoqhmd.js +972 -0
- package/dist/embed/mermaid/sequenceDiagram-WJ2MYXX4-Dpn6ph0n.js +4156 -0
- package/dist/embed/mermaid/sizeCapture-INFHLROL-C2wlw8KF.js +46 -0
- package/dist/embed/mermaid/src-CH4XuqUv.js +2147 -0
- package/dist/embed/mermaid/stateDiagram-D77RDMKH-V_8TbftV.js +220 -0
- package/dist/embed/mermaid/stateDiagram-v2-MP3YSRHH-us7SNDcU.js +30 -0
- package/dist/embed/mermaid/swimlanes-42K2YHIH-wzihXC1V.js +4979 -0
- package/dist/embed/mermaid/swimlanesDiagram-VR7AAH4N-BML-4Vp0.js +31 -0
- package/dist/embed/mermaid/timeline-definition-24CTP7MA-C3BzP6RA.js +1069 -0
- package/dist/embed/mermaid/treeView-Q6P3EWNA-Ba1dLcIR.js +3 -0
- package/dist/embed/mermaid/treemap-WGGIJYW6-D9G3ZsOW.js +3 -0
- package/dist/embed/mermaid/vennDiagram-4TSXK5OY-Cq1JumSe.js +1880 -0
- package/dist/embed/mermaid/wardley-WFR3VGLG-gAtip5-G.js +3 -0
- package/dist/embed/mermaid/wardleyDiagram-VM6X3IG4-HtzestuU.js +645 -0
- package/dist/embed/mermaid/xychartDiagram-S5SC5T6Z-BE-W0B_D.js +2210 -0
- package/dist/embed.js +903 -0
- package/dist/embed.js.map +1 -0
- package/dist/smarter-chat-library.es.js +1592 -1583
- package/dist/smarter-chat-library.es.js.map +1 -1
- package/dist/smarter-chat-library.umd.js +43 -43
- package/dist/smarter-chat-library.umd.js.map +1 -1
- package/dist/types/src/components/SmarterChat/Component.d.ts +1 -1
- package/dist/types/src/contract.gen.d.ts +41 -26
- package/dist/types/src/embed/EmbedApp.d.ts +10 -0
- package/dist/types/src/embed/assets.d.ts +7 -0
- package/dist/types/src/embed/autoMount.d.ts +18 -0
- package/dist/types/src/embed/css.d.ts +15 -0
- package/dist/types/src/embed/element.d.ts +19 -0
- package/dist/types/src/embed/index.d.ts +17 -0
- package/dist/types/src/embed/mermaid.d.ts +2 -0
- package/dist/types/src/embed/mermaidImport.d.ts +1 -0
- package/dist/types/src/embed/options.d.ts +69 -0
- package/dist/types/src/lib/cookie.d.ts +4 -3
- package/dist/types/src/lib/mermaidImport.d.ts +8 -0
- package/dist/types/src/types.d.ts +7 -0
- package/dist/ui-chat.css +1 -1
- package/package.json +10 -4
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# @smarter.sh/ui-chat
|
|
2
2
|
|
|
3
|
-
>
|
|
4
|
-
>
|
|
3
|
+
> The official chat UI for [Smarter](https://smarter.sh) LLMClients. Drop it into any website, whether React, Next.js,
|
|
4
|
+
> WordPress, Django, Flask, Node.js or plain HTML, and it gets its behavior and its look from the LLMClient's YAML
|
|
5
|
+
> manifest.
|
|
5
6
|
|
|
6
7
|
[](https://github.com/smarter-sh/smarter-chat)
|
|
7
8
|
[](https://www.npmjs.com/package/@smarter.sh/ui-chat)
|
|
@@ -15,49 +16,114 @@
|
|
|
15
16
|
|
|
16
17
|

|
|
17
18
|
|
|
18
|
-
Smarter Chat is the chat
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
Smarter Chat is the chat window of the Smarter web console's prompt engineering workbench, published on npm so you can
|
|
20
|
+
put the same chat on your own website: a marketing site, a customer portal, a storefront, an intranet or an application.
|
|
21
|
+
You build and run the chatbot on Smarter, and this package displays it on your pages. The complete guide is at
|
|
22
|
+
[docs.smarter.sh](https://docs.smarter.sh/smarter-framework/smarter-chat.html).
|
|
21
23
|
|
|
22
|
-
**[Documentation](https://docs.smarter.sh/
|
|
24
|
+
**[Documentation](https://docs.smarter.sh/smarter-framework/smarter-chat.html)** ·
|
|
23
25
|
**[Storybook](#development)** · **[Changelog](https://github.com/smarter-sh/smarter-chat/blob/main/CHANGELOG.md)** ·
|
|
24
26
|
**[Issues](https://github.com/smarter-sh/smarter-chat/issues)**
|
|
25
27
|
|
|
26
28
|
## Contents
|
|
27
29
|
|
|
30
|
+
- [How it works](#how-it-works)
|
|
28
31
|
- [Features](#features)
|
|
29
32
|
- [Installation](#installation)
|
|
30
|
-
- [Quick start](#quick-start)
|
|
33
|
+
- [Quick start (React)](#quick-start-react)
|
|
34
|
+
- [Embedding in any website](#embedding-in-any-website)
|
|
31
35
|
- [Requirements on the Smarter side](#requirements-on-the-smarter-side)
|
|
36
|
+
- [Behavior: `spec.config.prompt`](#behavior-specconfigprompt)
|
|
37
|
+
- [Styling: `spec.config.styles`](#styling-specconfigstyles)
|
|
32
38
|
- [Props](#props)
|
|
33
|
-
- [
|
|
34
|
-
- [Styling](#styling)
|
|
39
|
+
- [More examples](#more-examples)
|
|
35
40
|
- [TypeScript](#typescript)
|
|
36
|
-
- [
|
|
41
|
+
- [The api contract](#the-api-contract)
|
|
37
42
|
- [Browser support](#browser-support)
|
|
38
43
|
- [Development](#development)
|
|
39
44
|
- [License](#license)
|
|
40
45
|
|
|
46
|
+
## How it works
|
|
47
|
+
|
|
48
|
+
Smarter Chat isn't a general-purpose chat UI. It works only with a Smarter
|
|
49
|
+
[LLMClient](https://docs.smarter.sh/smarter-resources/smarter-llmclient.html), which is a chatbot that you declare in a
|
|
50
|
+
YAML manifest and apply to a Smarter platform with the `smarter` CLI or the REST API. The platform runs the
|
|
51
|
+
chatbot, and this component is its front end. It can't call OpenAI, Anthropic or any other LLM provider directly.
|
|
52
|
+
|
|
53
|
+
The `SmarterChat` component has a single required prop, `apiUrl`, which is the url of a deployed LLMClient. Everything
|
|
54
|
+
else comes from the LLMClient's manifest, so you change the chat by applying a new manifest, not by redeploying your
|
|
55
|
+
website:
|
|
56
|
+
|
|
57
|
+
| You want to change | Where it's set |
|
|
58
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------- |
|
|
59
|
+
| What the chatbot says and does: its LLM, model, system prompt, name, welcome message and examples | The manifest's [`spec.config.prompt`](#behavior-specconfigprompt) |
|
|
60
|
+
| Its tools and safety: [Plugins](https://docs.smarter.sh/smarter-resources/smarter-llmtool.html), Functions, [Guardrails](https://docs.smarter.sh/smarter-resources/smarter-guardrail.html) | The manifest's `spec.plugins`, `spec.functions` and `spec.guardrails` |
|
|
61
|
+
| How it looks: its logo, avatars, background image, font and colors | The manifest's [`spec.config.styles`](#styling-specconfigstyles) |
|
|
62
|
+
| Where it appears on your page and its size, plus any extra CSS | Your page: the component's [props](#props) and your [stylesheet](#your-own-css) |
|
|
63
|
+
| The data exchanged between browser and server | [The api contract](#the-api-contract), generated from Smarter's Pydantic models. You don't change it yourself |
|
|
64
|
+
|
|
65
|
+
```yaml
|
|
66
|
+
apiVersion: smarter.sh/v1
|
|
67
|
+
kind: LLMClient
|
|
68
|
+
metadata:
|
|
69
|
+
name: support
|
|
70
|
+
description: Customer support for example.com
|
|
71
|
+
version: 1.0.0
|
|
72
|
+
spec:
|
|
73
|
+
config:
|
|
74
|
+
prompt: # behavior: what the chatbot is and does
|
|
75
|
+
deployed: true
|
|
76
|
+
provider: openai
|
|
77
|
+
defaultModel: gpt-4o-mini
|
|
78
|
+
defaultSystemRole: You are a friendly support agent for example.com. Answer briefly.
|
|
79
|
+
appName: Example Support
|
|
80
|
+
appAssistant: Sam
|
|
81
|
+
appWelcomeMessage: Hi, I'm Sam. How can I help?
|
|
82
|
+
appExamplePrompts:
|
|
83
|
+
- How do I reset my password?
|
|
84
|
+
- What is your return policy?
|
|
85
|
+
appPlaceholder: Ask me anything...
|
|
86
|
+
allowedOrigins:
|
|
87
|
+
- https://www.example.com
|
|
88
|
+
styles: # look: how the chat is displayed, on every page that embeds it
|
|
89
|
+
appLogoUrl: https://cdn.example.com/logo.png
|
|
90
|
+
googleFont: Nunito
|
|
91
|
+
conversationHeader: { backgroundColor: "#14213d", color: "#ffffff" }
|
|
92
|
+
outgoingMessage: { backgroundColor: "#fca311", color: "#14213d" }
|
|
93
|
+
plugins:
|
|
94
|
+
- order-status
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
<SmarterChat apiUrl="https://support.3141-5926-5359.api.example.com/" showConsole={false} />
|
|
99
|
+
```
|
|
100
|
+
|
|
41
101
|
## Features
|
|
42
102
|
|
|
43
|
-
- **
|
|
44
|
-
message, example prompts and
|
|
103
|
+
- **Configured by its manifest.** You give it the url of a deployed LLMClient, and it loads the LLMClient's name,
|
|
104
|
+
welcome message, example prompts, placeholder and styles from Smarter.
|
|
105
|
+
- **Embed it anywhere.** You can use it as a React component, or build it once into a small script that WordPress,
|
|
106
|
+
Django, Flask, Express or a plain HTML page includes.
|
|
107
|
+
- **Themeable without CSS.** The logo, avatars, background image, Google font, font size, corner radius and the colors
|
|
108
|
+
of every part of the chat are set in the manifest and validated by Smarter.
|
|
45
109
|
- **Persistent chat sessions.** The conversation survives page reloads, and each LLMClient on a site keeps its own
|
|
46
110
|
session.
|
|
47
|
-
- **Live progress.** While a prompt runs, the chat shows each LLM request
|
|
48
|
-
as Server-Sent Events.
|
|
49
|
-
- **Rich responses.** GitHub flavored markdown (tables, lists, block quotes, images, links),
|
|
50
|
-
blocks with a copy button, LaTeX math typeset by [KaTeX](https://katex.org), and
|
|
111
|
+
- **Live progress.** While a prompt runs, the chat shows each LLM request and each tool, Plugin and MCP server call,
|
|
112
|
+
streamed as Server-Sent Events.
|
|
113
|
+
- **Rich responses.** It renders GitHub flavored markdown (tables, lists, block quotes, images, links),
|
|
114
|
+
syntax-highlighted code blocks with a copy button, LaTeX math typeset by [KaTeX](https://katex.org), and
|
|
51
115
|
[Mermaid](https://mermaid.js.org) diagrams.
|
|
52
|
-
- **Safe by default.** Raw
|
|
53
|
-
`data:` urls
|
|
116
|
+
- **Safe by default.** Raw HTML is displayed as text. Links and images are restricted to `http(s)`, relative and
|
|
117
|
+
raster `data:` urls. The rendered HTML and Mermaid's SVG are sanitized with
|
|
54
118
|
[DOMPurify](https://github.com/cure53/DOMPurify).
|
|
55
|
-
- **Lightweight where it counts.** React is a peer dependency
|
|
119
|
+
- **Lightweight where it counts.** React is a peer dependency. Mermaid is loaded only when a message first has a
|
|
56
120
|
diagram, and KaTeX's fonts are downloaded only when an equation uses them.
|
|
57
|
-
- **Optional developer Console.**
|
|
58
|
-
tool calls and
|
|
59
|
-
- **Accessible.**
|
|
60
|
-
- **Typed.**
|
|
121
|
+
- **Optional developer Console.** As in the Smarter workbench, a resizable side panel can show the LLMClient's
|
|
122
|
+
configuration, the session's api calls, tool calls and Plugin usage, and a live server log stream.
|
|
123
|
+
- **Accessible.** It has labeled regions and controls, keyboard-resizable panels, and MathML for screen readers.
|
|
124
|
+
- **Typed.** It's written in TypeScript, and its types are generated from Smarter's api contract.
|
|
125
|
+
|
|
126
|
+
See [Features](https://docs.smarter.sh/smarter-framework/smarter-chat/features.html) for details.
|
|
61
127
|
|
|
62
128
|
## Installation
|
|
63
129
|
|
|
@@ -74,9 +140,10 @@ pnpm add @smarter.sh/ui-chat
|
|
|
74
140
|
```
|
|
75
141
|
|
|
76
142
|
`react` and `react-dom` 19 are peer dependencies. The package is published as ES and UMD bundles, and is meant to be
|
|
77
|
-
used with a bundler such as Vite, webpack, Rollup or Next.js.
|
|
143
|
+
used with a bundler such as Vite, webpack, Rollup or Next.js. If your site isn't built with React, see
|
|
144
|
+
[Embedding in any website](#embedding-in-any-website).
|
|
78
145
|
|
|
79
|
-
## Quick start
|
|
146
|
+
## Quick start (React)
|
|
80
147
|
|
|
81
148
|
```tsx
|
|
82
149
|
import { createRoot } from "react-dom/client";
|
|
@@ -95,17 +162,97 @@ createRoot(document.getElementById("chat")!).render(
|
|
|
95
162
|
);
|
|
96
163
|
```
|
|
97
164
|
|
|
98
|
-
The chat fills the height of its parent element, so give the parent a height.
|
|
165
|
+
The chat fills the height of its parent element, so give the parent a height. Before it can connect, the LLMClient
|
|
166
|
+
must be deployed and must allow your page's origin. See
|
|
167
|
+
[Requirements on the Smarter side](#requirements-on-the-smarter-side).
|
|
168
|
+
|
|
169
|
+
## Embedding in any website
|
|
170
|
+
|
|
171
|
+
If your site isn't built with React, such as a WordPress, Drupal, Shopify, Squarespace or SharePoint site, a
|
|
172
|
+
documentation site, or a server-rendered or plain HTML page, add the **embed script**. It's one prebuilt file,
|
|
173
|
+
`dist/embed.js`, that includes React and Smarter Chat, so your page needs nothing else, and it renders the chat in a
|
|
174
|
+
[Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM), so your site's theme
|
|
175
|
+
can't break it, and it can't change your site.
|
|
176
|
+
|
|
177
|
+
```html
|
|
178
|
+
<script
|
|
179
|
+
src="https://cdn.jsdelivr.net/npm/@smarter.sh/ui-chat@0/dist/embed.js"
|
|
180
|
+
data-chatbot="https://support.3141-5926-5359.api.example.com/"
|
|
181
|
+
async
|
|
182
|
+
></script>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
That adds a chat button to the bottom right corner of every page that has the tag. The button opens the chat, which
|
|
186
|
+
loads only then, and the conversation follows the visitor from page to page. To put the chat in the page instead, use
|
|
187
|
+
the `<smarter-chat>` element, wherever the script is loaded:
|
|
188
|
+
|
|
189
|
+
```html
|
|
190
|
+
<smarter-chat chatbot="https://support.3141-5926-5359.api.example.com/" height="600px"></smarter-chat>
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Options
|
|
194
|
+
|
|
195
|
+
The element's attributes, the script tag's `data-` attributes and the properties of `window.SmarterChatConfig` (in
|
|
196
|
+
camelCase, e.g. `apiKey`) are the same options. Only `chatbot` is required.
|
|
197
|
+
|
|
198
|
+
| Option | Default | Description |
|
|
199
|
+
| --------------------- | --------------------- | ------------------------------------------------------------------------------------- |
|
|
200
|
+
| `chatbot` | (required) | The deployed LLMClient's url. |
|
|
201
|
+
| `api-key` | | A Smarter api key, for LLMClients that require one. It's public in the page. |
|
|
202
|
+
| `mode` | `launcher` / `inline` | `launcher` (the script tag's default) or `inline` (the element's default). |
|
|
203
|
+
| `position` | `bottom-right` | The launcher's corner: `bottom-right` or `bottom-left`. |
|
|
204
|
+
| `open` | `false` | Start with the launcher open. |
|
|
205
|
+
| `label` | `Chat` | The launcher's accessible name. |
|
|
206
|
+
| `color` | `#ff5733` | The launcher button's color. |
|
|
207
|
+
| `width`, `height` | `400px`, `600px` | The launcher's panel, or the inline chat (`100%`, `600px`). Any css length. |
|
|
208
|
+
| `z-index` | `2147483000` | The launcher's stacking order. |
|
|
209
|
+
| `session-cookie-name` | one per chatbot host | The cookie that keeps the chat session. |
|
|
210
|
+
| `cookie-path` | `/` | The session cookie's path. `/` keeps one conversation across the whole site. |
|
|
211
|
+
| `stream-progress` | `true` | Show a running prompt's steps, e.g. its tool calls. |
|
|
212
|
+
| `debug` | `false` | Log to the browser console. |
|
|
213
|
+
| `target` | | Script tag and `SmarterChatConfig` only: a css selector to render the chat inline in. |
|
|
214
|
+
|
|
215
|
+
Where you can't set a script tag's attributes, as in Google Tag Manager, set `window.SmarterChatConfig` (an object, or
|
|
216
|
+
an array of them) before the script runs:
|
|
217
|
+
|
|
218
|
+
```html
|
|
219
|
+
<script>
|
|
220
|
+
window.SmarterChatConfig = { chatbot: "https://support.3141-5926-5359.api.example.com/", position: "bottom-left" };
|
|
221
|
+
</script>
|
|
222
|
+
<script src="https://cdn.jsdelivr.net/npm/@smarter.sh/ui-chat@0/dist/embed.js" async></script>
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Your own buttons can open the launcher with `SmarterChat.open()`, `SmarterChat.close()` and `SmarterChat.toggle()`,
|
|
226
|
+
and the element dispatches a `smarter-chat-toggle` event, with `event.detail.open`, when it opens or closes. Style the
|
|
227
|
+
launcher from your css with `smarter-chat::part(launcher)`, `::part(panel)` and `::part(chat)`.
|
|
228
|
+
|
|
229
|
+
### Hosting the script yourself
|
|
230
|
+
|
|
231
|
+
`embed.js` loads its other files from an `embed/` directory beside it: Mermaid, which is downloaded only when a
|
|
232
|
+
message has a diagram, and KaTeX's fonts, only when one has math. To serve it from your own site, copy `dist/embed.js`
|
|
233
|
+
and `dist/embed/` together, e.g. from `npm pack @smarter.sh/ui-chat`. Pin a version (`@0.9.0`) on a CDN url if you want
|
|
234
|
+
to review changes before your visitors see them; `@0` follows the latest 0.x release.
|
|
235
|
+
|
|
236
|
+
### Platforms
|
|
237
|
+
|
|
238
|
+
Plugins that write the tag for you, with a settings screen:
|
|
239
|
+
[WordPress](https://github.com/smarter-sh/smarter-wordpress), [Drupal](https://github.com/smarter-sh/smarter-drupal),
|
|
240
|
+
[Shopify](https://github.com/smarter-sh/smarter-shopify),
|
|
241
|
+
[Google Tag Manager](https://github.com/smarter-sh/smarter-gtm-template), and Docusaurus, MkDocs, Sphinx and VitePress
|
|
242
|
+
([smarter-docs-site-generators](https://github.com/smarter-sh/smarter-docs-site-generators)). Every other platform that
|
|
243
|
+
lets you add a script to its pages needs only the tag above. See
|
|
244
|
+
[Embedding Smarter Chat](https://docs.smarter.sh/smarter-framework/smarter-chat/embedding.html).
|
|
99
245
|
|
|
100
246
|
## Requirements on the Smarter side
|
|
101
247
|
|
|
102
|
-
The component
|
|
248
|
+
The component calls the Smarter platform directly from your visitors' browsers, so three things must be true:
|
|
103
249
|
|
|
104
|
-
1. **The LLMClient is deployed
|
|
105
|
-
`https://<name>.<account-number>.api.<your-smarter-domain>/`, or its verified
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
250
|
+
1. **The LLMClient is deployed** (`spec.config.prompt.deployed: true`). `apiUrl` is its url, for example
|
|
251
|
+
`https://<name>.<account-number>.api.<your-smarter-domain>/`, or its verified
|
|
252
|
+
[custom domain](https://docs.smarter.sh/smarter-resources/smarter-custom-domain.html). The chat calls only
|
|
253
|
+
that host.
|
|
254
|
+
2. **Your page's origin is allowed.** Requests from your page are cross-origin and include credentials, so list your
|
|
255
|
+
site's origins in the LLMClient's manifest and apply it:
|
|
109
256
|
|
|
110
257
|
```yaml
|
|
111
258
|
spec:
|
|
@@ -116,16 +263,114 @@ The component talks directly to the Smarter platform from your visitors' browser
|
|
|
116
263
|
- http://localhost:5173
|
|
117
264
|
```
|
|
118
265
|
|
|
119
|
-
3. **The browser can authenticate, if the LLMClient requires it.** A deployed LLMClient without api keys is public
|
|
120
|
-
|
|
121
|
-
key as `apiKey`, which is sent as `Authorization: Token <apiKey>`. Anyone who can view your page can
|
|
122
|
-
a key
|
|
266
|
+
3. **The browser can authenticate, if the LLMClient requires it.** A deployed LLMClient without api keys is public.
|
|
267
|
+
Pass no `apiKey`, and every prompt is charged to the LLMClient's owner. If the LLMClient has an api key, pass a
|
|
268
|
+
[Smarter api key](https://docs.smarter.sh/smarter-resources/smarter-authtoken.html) as `apiKey`, which is sent as `Authorization: Token <apiKey>`. Anyone who can view your page can
|
|
269
|
+
read it, so create a key just for that page.
|
|
123
270
|
|
|
124
|
-
The page receives the LLMClient's public configuration (its name, welcome message, example prompts, model
|
|
125
|
-
prompt)
|
|
271
|
+
The page receives only the LLMClient's public configuration (its name, welcome message, example prompts, model,
|
|
272
|
+
system prompt and styles). It never receives, for example, its owner's profile or the session's diagnostic history.
|
|
126
273
|
|
|
127
|
-
|
|
128
|
-
|
|
274
|
+
For details and troubleshooting, see
|
|
275
|
+
[Embedding Smarter Chat](https://docs.smarter.sh/smarter-framework/smarter-chat/embedding.html).
|
|
276
|
+
|
|
277
|
+
## Behavior: `spec.config.prompt`
|
|
278
|
+
|
|
279
|
+
You configure the chatbot's behavior in its manifest, not in this package. The section is validated on the platform by
|
|
280
|
+
the Pydantic model
|
|
281
|
+
[`SAMLLMClientSpecConfigPrompt`](https://docs.smarter.sh/smarter-resources/llmclient/sam.html)
|
|
282
|
+
(`smarter.apps.llmclient.manifest.models.llmclient.spec`). The settings fall into three groups: what Smarter sends to the
|
|
283
|
+
LLM, what the chat displays, and who may use it.
|
|
284
|
+
|
|
285
|
+
| Setting | Effect in the chat |
|
|
286
|
+
| ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
287
|
+
| `provider`, `defaultModel` | The LLM that answers. They're also shown under the name in the header, as in "openai gpt-4o-mini with 2 additional plugins". |
|
|
288
|
+
| `defaultSystemRole` | The system prompt that starts every new session. It's visible in sandbox mode (`toggleMetadata`). |
|
|
289
|
+
| `defaultTemperature`, `defaultMaxTokens` | Sent to the LLM with each prompt. |
|
|
290
|
+
| `appName` | The title in the header, followed by the manifest's `metadata.version`. |
|
|
291
|
+
| `appAssistant` | The sender name on the assistant's messages. The default is "Assistant". |
|
|
292
|
+
| `appWelcomeMessage` | The first assistant message of a new session. |
|
|
293
|
+
| `appExamplePrompts` | A second assistant message that lists them: "Some example prompts to get you started". |
|
|
294
|
+
| `appPlaceholder` | The hint in the empty message box. |
|
|
295
|
+
| `appFileAttachment` | Shows the attach button in the message box. |
|
|
296
|
+
| `deployed`, `subdomain`, `customDomain` | Whether the LLMClient has a public url, and what that url is, which you pass as `apiUrl`. |
|
|
297
|
+
| `allowedOrigins` | The websites that may embed the chat. |
|
|
298
|
+
|
|
299
|
+
The chatbot's tools are set beside `config`: `spec.plugins`, `spec.functions` and `spec.guardrails` are run by the
|
|
300
|
+
platform. The chat displays their calls as progress while a prompt runs.
|
|
301
|
+
|
|
302
|
+
Apply a changed manifest with `smarter apply -f llmclient.yaml`. A new chat session picks up the change without any
|
|
303
|
+
change to your website.
|
|
304
|
+
|
|
305
|
+
## Styling: `spec.config.styles`
|
|
306
|
+
|
|
307
|
+
### The LLMClient's styles
|
|
308
|
+
|
|
309
|
+
The chat takes its look from the LLMClient's manifest, so most pages need no CSS of their own. `spec.config.styles` is
|
|
310
|
+
validated on the platform by the Pydantic model
|
|
311
|
+
[`SAMLLMClientSpecConfigStyles`](https://docs.smarter.sh/smarter-resources/llmclient/sam.html)
|
|
312
|
+
(`smarter.apps.llmclient.manifest.models.llmclient.styles`). Every setting is optional, and a setting that is left out
|
|
313
|
+
keeps the default. Colors, lengths and font names must be plain CSS values, and images must be `https` urls that
|
|
314
|
+
Smarter can fetch when the manifest is applied.
|
|
315
|
+
|
|
316
|
+
```yaml
|
|
317
|
+
spec:
|
|
318
|
+
config:
|
|
319
|
+
styles:
|
|
320
|
+
# images
|
|
321
|
+
appLogoUrl: https://cdn.example.com/logo.png # in a circle at the left of the header
|
|
322
|
+
assistantAvatarUrl: https://cdn.example.com/assistant.png
|
|
323
|
+
userAvatarUrl: https://cdn.example.com/user.png
|
|
324
|
+
appBackgroundImageUrl: https://cdn.example.com/background.jpg
|
|
325
|
+
appBackgroundImageSize: cover # cover | contain | auto
|
|
326
|
+
# typography and shape
|
|
327
|
+
googleFont: Nunito # downloaded from fonts.google.com
|
|
328
|
+
fontFamily: '"Nunito", system-ui, sans-serif' # overrides googleFont's stack
|
|
329
|
+
fontSize: 16px
|
|
330
|
+
borderRadius: 0.7em
|
|
331
|
+
# colors, one section per part of the chat
|
|
332
|
+
mainContainer: { backgroundColor: "#ffffff", color: "#212121", borderColor: "#d1dbe3" }
|
|
333
|
+
conversationHeader: { backgroundColor: "#14213d", color: "#ffffff", infoColor: "#c0c4e0", borderColor: "#14213d" }
|
|
334
|
+
messageList: { backgroundColor: "rgba(255, 255, 255, 0.6)", color: "#212121" } # tints the background image
|
|
335
|
+
incomingMessage: { backgroundColor: "#e5e5e5", color: "#14213d", borderColor: "#d1dbe3", linkColor: "#0b57d0" }
|
|
336
|
+
outgoingMessage: { backgroundColor: "#fca311", color: "#14213d", linkColor: "#14213d" }
|
|
337
|
+
messageInput:
|
|
338
|
+
backgroundColor: "#ffffff"
|
|
339
|
+
editorBackgroundColor: "#f6fbff"
|
|
340
|
+
color: "#212121"
|
|
341
|
+
placeholderColor: "#9e9e9e"
|
|
342
|
+
borderColor: "#d1dbe3"
|
|
343
|
+
buttons: { color: "#fca311" }
|
|
344
|
+
typingIndicator: { color: "#fca311" }
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
The sections correspond to the [chatscope](https://github.com/chatscope/chat-ui-kit-react) components that the chat is
|
|
348
|
+
built on: `MainContainer`, `ConversationHeader`, `MessageList`, `Message`, `MessageInput`, `Button` and
|
|
349
|
+
`TypingIndicator`. The same styles apply in the Smarter workbench and on every page that embeds the LLMClient.
|
|
350
|
+
|
|
351
|
+
The chat sets the styles as CSS custom properties on its root `.SmarterChat` element, such as
|
|
352
|
+
`--smarter-chat-header-bg` and `--smarter-chat-outgoing-bg`. Their fallbacks are chatscope's own colors. See
|
|
353
|
+
[Styling Your LLMClient's Chat](https://docs.smarter.sh/smarter-resources/llmclient/styles.html) for every
|
|
354
|
+
setting.
|
|
355
|
+
|
|
356
|
+
### Your own CSS
|
|
357
|
+
|
|
358
|
+
Import the stylesheets once, anywhere in your app:
|
|
359
|
+
|
|
360
|
+
```ts
|
|
361
|
+
import "@smarter.sh/ui-chat/dist/ui-chat.css"; // or "@smarter.sh/ui-chat/style.css"
|
|
362
|
+
import "katex/dist/katex.min.css";
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
- **`ui-chat.css`** is the component's own CSS, including chatscope's chat styles.
|
|
366
|
+
- **`katex/dist/katex.min.css`** styles math in responses. It's kept out of `ui-chat.css` so that pages without math
|
|
367
|
+
don't download KaTeX's fonts. Without it, each equation is displayed twice, once as text and once as unstyled
|
|
368
|
+
MathML.
|
|
369
|
+
|
|
370
|
+
The component's elements have stable class names prefixed `smarter-chat-` (for example `.smarter-chat-message-list`,
|
|
371
|
+
`.smarter-chat-code`, `.smarter-chat-image`), under a root `.SmarterChat` element. Your stylesheet can override them,
|
|
372
|
+
or set the `--smarter-chat-*` properties, for anything the manifest doesn't cover. If a setting is in the manifest,
|
|
373
|
+
prefer setting it there, so that it applies everywhere the LLMClient is embedded.
|
|
129
374
|
|
|
130
375
|
## Props
|
|
131
376
|
|
|
@@ -149,7 +394,10 @@ Only `apiUrl` is required.
|
|
|
149
394
|
| `smarterRequestId` | `string` | `""` | A unique id of the page request, sent as the `X-Smarter-RequestId` header, for tracing. |
|
|
150
395
|
| `logStreamUrl` | `string \| null` | `null` | The url of a server log stream (Server-Sent Events), for the Console's Server Logs tab. |
|
|
151
396
|
|
|
152
|
-
|
|
397
|
+
The props control where and how the chat runs on your page. Its content and look come from the manifest, so there is
|
|
398
|
+
no prop for the welcome message, the colors or the model.
|
|
399
|
+
|
|
400
|
+
## More examples
|
|
153
401
|
|
|
154
402
|
### A chat widget in a corner of the page
|
|
155
403
|
|
|
@@ -196,7 +444,7 @@ export default function Chat() {
|
|
|
196
444
|
|
|
197
445
|
### A prompt engineering workbench
|
|
198
446
|
|
|
199
|
-
|
|
447
|
+
This is the full workbench, as in the Smarter web console, with the Console, the mode toggle and your server logs:
|
|
200
448
|
|
|
201
449
|
```tsx
|
|
202
450
|
<SmarterChat
|
|
@@ -208,84 +456,56 @@ The full workbench, as in the Smarter web console: the Console, the mode toggle,
|
|
|
208
456
|
/>
|
|
209
457
|
```
|
|
210
458
|
|
|
211
|
-
## Styling
|
|
212
|
-
|
|
213
|
-
Import the stylesheet once, anywhere in your app:
|
|
214
|
-
|
|
215
|
-
```ts
|
|
216
|
-
import "@smarter.sh/ui-chat/dist/ui-chat.css"; // or "@smarter.sh/ui-chat/style.css"
|
|
217
|
-
import "katex/dist/katex.min.css";
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
- **`ui-chat.css`** is the component's own css, including
|
|
221
|
-
[chatscope](https://github.com/chatscope/chat-ui-kit-react)'s chat styles, which it is built on.
|
|
222
|
-
- **`katex/dist/katex.min.css`** is the stylesheet of math in responses. It's left out of `ui-chat.css` so that pages
|
|
223
|
-
without math don't pay for KaTeX's fonts. Without it, math is displayed twice: as text, and as unstyled MathML.
|
|
224
|
-
|
|
225
|
-
### The LLMClient's styles
|
|
226
|
-
|
|
227
|
-
The chat takes its look from the LLMClient's manifest, so most pages need no css of their own. Its
|
|
228
|
-
`spec.config.styles` sets the logo in the header, avatars beside the messages, a background image, a Google font, and
|
|
229
|
-
the colors of each part of the chat, which are chatscope's components:
|
|
230
|
-
|
|
231
|
-
```yaml
|
|
232
|
-
spec:
|
|
233
|
-
config:
|
|
234
|
-
styles:
|
|
235
|
-
appLogoUrl: https://cdn.example.com/logo.png
|
|
236
|
-
googleFont: Nunito
|
|
237
|
-
conversationHeader: { backgroundColor: "#14213d", color: "#ffffff" }
|
|
238
|
-
outgoingMessage: { backgroundColor: "#fca311", color: "#14213d" }
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
The chat sets them as css custom properties on its root `.SmarterChat` element, e.g. `--smarter-chat-header-bg` and
|
|
242
|
-
`--smarter-chat-outgoing-bg`, whose fallbacks are chatscope's own colors. Your stylesheet can set the same properties.
|
|
243
|
-
See [Styling Your LLMClient's Chat](https://docs.smarter.sh/en/latest/smarter-resources/llmclient/styles.html) for every
|
|
244
|
-
setting.
|
|
245
|
-
|
|
246
|
-
### Your own css
|
|
247
|
-
|
|
248
|
-
The component's elements have stable class names, prefixed `smarter-chat-` (for example `.smarter-chat-message-list`,
|
|
249
|
-
`.smarter-chat-code`, `.smarter-chat-image`), under a root `.SmarterChat` element, so you can override their styles
|
|
250
|
-
from your own stylesheet.
|
|
251
|
-
|
|
252
459
|
## TypeScript
|
|
253
460
|
|
|
254
461
|
Type declarations are included. Besides the components, the package exports:
|
|
255
462
|
|
|
256
|
-
| Export | What it is
|
|
257
|
-
| ------------------------------------------------------------------------------ |
|
|
258
|
-
| `SmarterChat` | The chat component.
|
|
259
|
-
| `Console` | The developer Console, on its own.
|
|
260
|
-
| `SmarterChatProps` | The chat's props.
|
|
261
|
-
| `ChatConfig`, `LLMClientConfig`, `ChatHistory`, `ChatMetaData` | The LLMClient configuration that the Smarter config api returns.
|
|
262
|
-
| `Contract` | Every type of the api contract, generated from its JSON Schema.
|
|
263
|
-
| `normalizeConfig`, `CHAT_CONTRACT_V2_CAPABILITY` | Converts an older platform's configuration to the current
|
|
264
|
-
| `ApiMessage`, `ChatMessage` | A message as the api sends it, and as the chat thread holds it.
|
|
265
|
-
| `PromptProgressEvent` | A step of a running prompt, as the prompt api streams it.
|
|
266
|
-
| `MessageDirectionEnum`, `SenderRoleEnum`, `ValidMessageRolesEnum`, `MenuItems` | Message directions and roles, and the Console's tabs.
|
|
267
|
-
| `version` | The package's version.
|
|
268
|
-
|
|
269
|
-
##
|
|
463
|
+
| Export | What it is |
|
|
464
|
+
| ------------------------------------------------------------------------------ | ------------------------------------------------------------------ |
|
|
465
|
+
| `SmarterChat` | The chat component. |
|
|
466
|
+
| `Console` | The developer Console, on its own. |
|
|
467
|
+
| `SmarterChatProps` | The chat's props. |
|
|
468
|
+
| `ChatConfig`, `LLMClientConfig`, `ChatHistory`, `ChatMetaData` | The LLMClient configuration that the Smarter config api returns. |
|
|
469
|
+
| `Contract` | Every type of the api contract, generated from its JSON Schema. |
|
|
470
|
+
| `normalizeConfig`, `CHAT_CONTRACT_V2_CAPABILITY` | Converts an older platform's configuration to the current version. |
|
|
471
|
+
| `ApiMessage`, `ChatMessage` | A message as the api sends it, and as the chat thread holds it. |
|
|
472
|
+
| `PromptProgressEvent` | A step of a running prompt, as the prompt api streams it. |
|
|
473
|
+
| `MessageDirectionEnum`, `SenderRoleEnum`, `ValidMessageRolesEnum`, `MenuItems` | Message directions and roles, and the Console's tabs. |
|
|
474
|
+
| `version` | The package's version. |
|
|
475
|
+
|
|
476
|
+
## The api contract
|
|
477
|
+
|
|
478
|
+
The component and the Smarter platform share a single, versioned api contract. The contract is defined by Pydantic
|
|
479
|
+
models in the Smarter backend, in
|
|
480
|
+
[`smarter.apps.prompt.contract`](https://docs.smarter.sh/smarter-framework/smarter-chat/technical-reference/contract.html):
|
|
481
|
+
|
|
482
|
+
1. The platform builds its responses from those models.
|
|
483
|
+
2. `manage.py export_chat_contract_schema` exports the models as a JSON Schema, `chat-contract.schema.json`.
|
|
484
|
+
3. This package keeps a copy of the schema in `contract/`, generates its TypeScript types from it (`src/contract.gen.ts`,
|
|
485
|
+
exported as `Contract`), and validates its test fixtures against it.
|
|
486
|
+
|
|
487
|
+
A change to the backend's models therefore reaches the component's types, and a test on each side fails if its copy of
|
|
488
|
+
the schema is out of date. This is why the component works only with a Smarter backend.
|
|
270
489
|
|
|
271
490
|
The component makes two kinds of POST requests to Smarter, with the browser's cookies:
|
|
272
491
|
|
|
273
|
-
1. **`<apiUrl>config/`** returns the LLMClient's configuration
|
|
274
|
-
thread when the page reloads. A new session's key
|
|
492
|
+
1. **`<apiUrl>config/`** returns the LLMClient's public configuration, including its `spec.config.prompt` settings and
|
|
493
|
+
its `styles`, plus the chat session's history, which restores the thread when the page reloads. A new session's key
|
|
494
|
+
is saved in a cookie.
|
|
275
495
|
2. **The LLMClient's prompt api** (`llmclient.url_llmclient` in the configuration) receives the thread with each new
|
|
276
|
-
message, and returns the messages to add to it. With `streamProgress`, it
|
|
496
|
+
message, and returns the messages to add to it. With `streamProgress`, it responds with Server-Sent Events: progress
|
|
277
497
|
events while the prompt runs, then the result.
|
|
278
498
|
|
|
279
|
-
The
|
|
280
|
-
version
|
|
499
|
+
The component asks for version 2 of the contract with the `X-Smarter-Capabilities: chat-contract-v2` header. It also
|
|
500
|
+
reads version 1 from older Smarter platforms, and converts it with `normalizeConfig`.
|
|
281
501
|
|
|
282
502
|
The complete contract, with every request, response, header, cookie and event, is in
|
|
283
|
-
[The Chat API Contract](https://docs.smarter.sh/
|
|
503
|
+
[The Chat API Contract](https://docs.smarter.sh/smarter-framework/smarter-chat/api-contract.html).
|
|
284
504
|
|
|
285
505
|
## Browser support
|
|
286
506
|
|
|
287
|
-
|
|
288
|
-
`localStorage` and the `inert` attribute.
|
|
507
|
+
Smarter Chat supports current versions of Chrome, Edge, Firefox and Safari. It uses `fetch` response streams,
|
|
508
|
+
`EventSource`, `localStorage` and the `inert` attribute.
|
|
289
509
|
|
|
290
510
|
## Development
|
|
291
511
|
|
|
@@ -297,10 +517,11 @@ make serve # Storybook at http://localhost:6006, with the Smarter api mocked
|
|
|
297
517
|
make test # Vitest; every story is also rendered as a test
|
|
298
518
|
```
|
|
299
519
|
|
|
300
|
-
|
|
520
|
+
You don't need a Smarter backend: the stories mock the api with [MSW](https://mswjs.io/), using fixtures that are
|
|
521
|
+
validated against the contract's schema. See
|
|
301
522
|
[CONTRIBUTING.md](https://github.com/smarter-sh/smarter-chat/blob/main/.github/CONTRIBUTING.md) for the rest of the
|
|
302
523
|
workflow (every `make` target, working inside the Smarter repository, commits and releases), and the
|
|
303
|
-
[developer guide](https://docs.smarter.sh/
|
|
524
|
+
[developer guide](https://docs.smarter.sh/smarter-framework/smarter-chat/development.html) for the
|
|
304
525
|
architecture.
|
|
305
526
|
|
|
306
527
|
## License
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|