@luma-ai/react 0.1.0 → 2.0.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/CHANGELOG.md +51 -0
- package/README.md +18 -12
- package/dist/chunks/src-C48p0wsr.js +7647 -0
- package/dist/chunks/src-C48p0wsr.js.map +1 -0
- package/dist/chunks/support-cursor-BU9gztRA.js +131 -0
- package/dist/chunks/support-cursor-BU9gztRA.js.map +1 -0
- package/dist/chunks/visitor-call-CoKCjk8c.js +1129 -0
- package/dist/chunks/visitor-call-CoKCjk8c.js.map +1 -0
- package/dist/chunks/visitor-cobrowse-Ba7H1VtS.js +1415 -0
- package/dist/chunks/visitor-cobrowse-Ba7H1VtS.js.map +1 -0
- package/dist/{config-CCT7m9eE.d.ts → config-BAC3xPNG.d.ts} +1 -6
- package/dist/index-ByvZMuLw.d.ts +415 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -2
- package/dist/next.d.ts +3 -5
- package/dist/next.js +2 -3
- package/dist/next.js.map +1 -1
- package/dist/react-router.d.ts +3 -5
- package/dist/react-router.js +2 -3
- package/dist/react-router.js.map +1 -1
- package/dist/server.d.ts +1 -3
- package/dist/server.js +11 -12
- package/dist/server.js.map +1 -1
- package/dist/tanstack.d.ts +3 -5
- package/dist/tanstack.js +2 -3
- package/dist/tanstack.js.map +1 -1
- package/docs/ai-agents.md +5 -5
- package/docs/appearance.md +92 -0
- package/docs/data-sources.md +18 -18
- package/docs/features.md +62 -0
- package/docs/hooks.md +22 -8
- package/docs/index.md +17 -7
- package/docs/options.md +58 -51
- package/docs/privacy.md +29 -6
- package/docs/server.md +11 -7
- package/docs/troubleshooting.md +16 -8
- package/package.json +28 -21
- package/skills/luma-ai-react/SKILL.md +32 -13
- package/dist/chunks/src-dnp1waFV.js +0 -3100
- package/dist/chunks/src-dnp1waFV.js.map +0 -1
- package/dist/index-BdkoFDyP.d.ts +0 -189
|
@@ -34,12 +34,12 @@ React Router framework mode: `export const action = ({ request }) => handler(req
|
|
|
34
34
|
|
|
35
35
|
Provider, once, near the root. Import from the framework entry so navigation is client-side:
|
|
36
36
|
|
|
37
|
-
| Framework
|
|
38
|
-
|
|
|
39
|
-
| Next.js App Router
|
|
40
|
-
| TanStack Router/Start | `@luma-ai/react/tanstack` (root route)
|
|
41
|
-
| React Router 7/8
|
|
42
|
-
| No router
|
|
37
|
+
| Framework | Import |
|
|
38
|
+
| --------------------- | ------------------------------------------------------------- |
|
|
39
|
+
| Next.js App Router | `@luma-ai/react/next` (works directly in `app/layout.tsx`) |
|
|
40
|
+
| TanStack Router/Start | `@luma-ai/react/tanstack` (root route) |
|
|
41
|
+
| React Router 7/8 | `@luma-ai/react/react-router` (root route, inside the router) |
|
|
42
|
+
| No router | `@luma-ai/react` |
|
|
43
43
|
|
|
44
44
|
```tsx
|
|
45
45
|
<LumaProvider sessionEndpoint="/api/luma/session">{children}</LumaProvider>
|
|
@@ -49,7 +49,9 @@ Provider, once, near the root. Import from the framework entry so navigation is
|
|
|
49
49
|
|
|
50
50
|
```tsx
|
|
51
51
|
import { LumaProvider } from "@luma-ai/react"; // or /react-router, /tanstack
|
|
52
|
-
<LumaProvider assistantId="<uuid>" actions={[addToCart]}>
|
|
52
|
+
<LumaProvider assistantId="<uuid>" actions={[addToCart]}>
|
|
53
|
+
{children}
|
|
54
|
+
</LumaProvider>;
|
|
53
55
|
```
|
|
54
56
|
|
|
55
57
|
## 4. Live data
|
|
@@ -58,10 +60,19 @@ import { LumaProvider } from "@luma-ai/react"; // or /react-router, /tanstack
|
|
|
58
60
|
<LumaProvider
|
|
59
61
|
sessionEndpoint="/api/luma/session"
|
|
60
62
|
dataSources={{
|
|
61
|
-
site: {
|
|
63
|
+
site: {
|
|
64
|
+
name: "My shop",
|
|
65
|
+
currency: "تومان",
|
|
66
|
+
menus: [{ title: "Shipping", url: "/shipping" }],
|
|
67
|
+
},
|
|
62
68
|
// Resolves to { items: LumaProduct[], hasMore?: boolean }
|
|
63
69
|
searchProducts: async ({ query, maxPrice, inStock, page }, { signal }) =>
|
|
64
|
-
(
|
|
70
|
+
(
|
|
71
|
+
await fetch(
|
|
72
|
+
`/api/products?q=${encodeURIComponent(query)}&page=${page}`,
|
|
73
|
+
{ signal },
|
|
74
|
+
)
|
|
75
|
+
).json(),
|
|
65
76
|
// Resolves to LumaProduct | null
|
|
66
77
|
getProduct: async ({ productId }, { signal }) =>
|
|
67
78
|
(await fetch(`/api/products/${productId}`, { signal })).json(),
|
|
@@ -78,10 +89,13 @@ import { LumaProvider } from "@luma-ai/react"; // or /react-router, /tanstack
|
|
|
78
89
|
import { z } from "zod";
|
|
79
90
|
import { defineAction } from "@luma-ai/react/server";
|
|
80
91
|
export const addToCart = defineAction({
|
|
81
|
-
name: "addToCart",
|
|
82
|
-
title: "افزودن به سبد خرید",
|
|
92
|
+
name: "addToCart", // /^[A-Za-z][\w-]{0,63}$/
|
|
93
|
+
title: "افزودن به سبد خرید", // Persian label on the approval card
|
|
83
94
|
description: "Add the product the visitor is viewing to their cart.",
|
|
84
|
-
input: z.object({
|
|
95
|
+
input: z.object({
|
|
96
|
+
productId: z.string(),
|
|
97
|
+
quantity: z.number().int().min(1).max(5),
|
|
98
|
+
}),
|
|
85
99
|
});
|
|
86
100
|
```
|
|
87
101
|
|
|
@@ -89,7 +103,7 @@ export const addToCart = defineAction({
|
|
|
89
103
|
// in the component that owns the state
|
|
90
104
|
useLumaAction(addToCart, async ({ productId, quantity }) => {
|
|
91
105
|
await cart.add(productId, quantity);
|
|
92
|
-
return { cartItems: cart.count };
|
|
106
|
+
return { cartItems: cart.count }; // JSON result reported to the assistant
|
|
93
107
|
});
|
|
94
108
|
```
|
|
95
109
|
|
|
@@ -99,6 +113,9 @@ Declare the action in `createLumaSessionHandler({ actions })` (server) or `<Luma
|
|
|
99
113
|
|
|
100
114
|
- `useLuma()` returns `{ isOpen, status, open, close, toggle, ask(text), newChat }`.
|
|
101
115
|
- `useLumaContext("product", { id, selectedSize })` shares small JSON page state (8 KB total). No secrets.
|
|
116
|
+
- Light/dark: the dashboard's designer sets the look. To follow the site's own theme switch pass `colorScheme` (`"auto" | "light" | "dark"`, wins over the designer, can change at runtime). With next-themes: `colorScheme={resolvedTheme === "dark" ? "dark" : resolvedTheme === "light" ? "light" : "auto"}`. The widget does not read `class="dark"` on `<html>`.
|
|
117
|
+
- `layout="page"` fills its parent (give it a height) instead of a floating launcher.
|
|
118
|
+
- Live support, rating, voice, forms, product cards, quick calls, on-page pointing and co-browsing with support's cursor need no code; the owner switches them on in the dashboard or asks in the inbox. Calls need https and `Permissions-Policy: microphone=(self)` (screen sharing in a call also `display-capture=(self)`); the call engine and the co-browsing recorder are separate chunks loaded by `import()` only when a call rings or the visitor allows co-browsing. `LumaPrivate` regions and `privateSelectors` are never copied. A strict CSP must allow the Luma API host in `connect-src`, `img-src` and `media-src` (plus `blob:`); `data:` in `img-src` is optional (it lets the logo show at once on later pages).
|
|
102
119
|
- Use `<LumaPrivate>`, `{...lumaPrivate()}` or `privateSelectors` for regions the assistant must never read. Use `restrictedPaths={["/admin"]}` for pages it must not inspect or open. Use `{...lumaLabel("…")}` to name unlabeled sections for guides.
|
|
103
120
|
|
|
104
121
|
## Common mistakes
|
|
@@ -107,11 +124,13 @@ Declare the action in `createLumaSessionHandler({ actions })` (server) or `<Luma
|
|
|
107
124
|
- Wrong: importing `LumaProvider` from `@luma-ai/react` in a Next.js app. Pages then reload on navigation. Use `@luma-ai/react/next`.
|
|
108
125
|
- Wrong: defining `defineAction(...)` inside a component. Define it at module level.
|
|
109
126
|
- Wrong: registering `useLumaAction` without declaring the action. The console warns `LUMA_ACTION_NOT_DECLARED`.
|
|
127
|
+
- Wrong: rewriting or filtering the session handler's response (it carries the routed logo `avatar`/`avatarPath`) or the chat request body (`clientMessageId` lets the server recognise a resend after a dropped connection). Return and forward them unchanged.
|
|
110
128
|
- Wrong: an auth middleware that redirects `/api/luma/session`. The console reports `LUMA_INVALID_SESSION_RESPONSE`. Exclude the route.
|
|
111
129
|
|
|
112
130
|
## Steps only the owner can do
|
|
113
131
|
|
|
114
132
|
Ask the user. Do not invent values:
|
|
133
|
+
|
|
115
134
|
- the assistant ID (UUID);
|
|
116
135
|
- creating an API key at https://dash.lumai.ir/developers/api/keys;
|
|
117
136
|
- for keyless mode, enabling keyless access and adding the exact origin in the dashboard (assistant → overview).
|