@anakin824/prdg-chat-ui 0.1.0
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/NEXTJS-INTEGRATION.md +196 -0
- package/NPM-TOKEN-SETUP.md +79 -0
- package/README.md +39 -0
- package/dist/index.css +1346 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.mts +671 -0
- package/dist/index.d.ts +671 -0
- package/dist/index.js +1959 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1922 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# Embedding `@anakin824/prdg-chat-ui` in a Next.js app
|
|
2
|
+
|
|
3
|
+
Use the **App Router** (`app/`) and **React 18+**. Chat components use client hooks and must live under a **client** boundary.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @anakin824/prdg-chat-ui @tanstack/react-query date-fns framer-motion wavesurfer.js yet-another-react-lightbox react-intersection-observer
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Optional (browser NATS realtime):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install nats.ws
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Global styles
|
|
18
|
+
|
|
19
|
+
Import once in the root layout (or any layout that wraps chat):
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
// app/layout.tsx
|
|
23
|
+
import "@anakin824/prdg-chat-ui/styles";
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
If the subpath is not resolved, use:
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import "@anakin824/prdg-chat-ui/dist/index.css";
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Provider (required)
|
|
33
|
+
|
|
34
|
+
`ChatProvider` wraps **React Query** (`QueryClientProvider`) and chat context — use **one** provider around the UI that needs chat.
|
|
35
|
+
|
|
36
|
+
Create a small client file:
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
// app/chat-providers.tsx
|
|
40
|
+
"use client";
|
|
41
|
+
|
|
42
|
+
import { ChatProvider } from "@anakin824/prdg-chat-ui";
|
|
43
|
+
import type { ReactNode } from "react";
|
|
44
|
+
|
|
45
|
+
export function ChatProviders({
|
|
46
|
+
children,
|
|
47
|
+
apiUrl,
|
|
48
|
+
token,
|
|
49
|
+
userId,
|
|
50
|
+
tenantId,
|
|
51
|
+
}: {
|
|
52
|
+
children: ReactNode;
|
|
53
|
+
apiUrl: string;
|
|
54
|
+
token: string;
|
|
55
|
+
userId: string;
|
|
56
|
+
tenantId: string;
|
|
57
|
+
}) {
|
|
58
|
+
return (
|
|
59
|
+
<ChatProvider
|
|
60
|
+
apiUrl={apiUrl}
|
|
61
|
+
token={token}
|
|
62
|
+
userId={userId}
|
|
63
|
+
tenantId={tenantId}
|
|
64
|
+
natsWsUrl={process.env.NEXT_PUBLIC_NATS_WS_URL}
|
|
65
|
+
conduitlyTenantId={process.env.NEXT_PUBLIC_CONDUITLY_TENANT_ID}
|
|
66
|
+
>
|
|
67
|
+
{children}
|
|
68
|
+
</ChatProvider>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### `ChatProvider` props (common)
|
|
74
|
+
|
|
75
|
+
| Prop | Purpose |
|
|
76
|
+
|------|---------|
|
|
77
|
+
| `apiUrl` | prdg-chat HTTP API base URL (no trailing slash) |
|
|
78
|
+
| `token` | Bearer JWT for the current user |
|
|
79
|
+
| `userId` | prdg-chat **user** UUID |
|
|
80
|
+
| `tenantId` | prdg-chat **tenant** UUID |
|
|
81
|
+
| `natsWsUrl` | Optional `wss://` NATS URL (disables REST polling when connected) |
|
|
82
|
+
| `conduitlyTenantId` | Conduitly tenant id for NATS subjects (if using NATS + Conduitly) |
|
|
83
|
+
| `theme` | Optional `ChatTheme` overrides |
|
|
84
|
+
| `onTokenRefresh` | Optional callback when the API returns 401 |
|
|
85
|
+
| `callEnabled` | Show Calls UI in standalone layout |
|
|
86
|
+
|
|
87
|
+
Do **not** wrap `ChatProvider` in a second `QueryClientProvider` unless you intentionally want two React Query trees.
|
|
88
|
+
|
|
89
|
+
## `next.config` (optional)
|
|
90
|
+
|
|
91
|
+
If you `npm link` the package or consume TypeScript source, add:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
// next.config.ts
|
|
95
|
+
import type { NextConfig } from "next";
|
|
96
|
+
|
|
97
|
+
const nextConfig: NextConfig = {
|
|
98
|
+
transpilePackages: ["@anakin824/prdg-chat-ui"],
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export default nextConfig;
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Published `dist/` builds often work without this.
|
|
105
|
+
|
|
106
|
+
## Full inbox page (`StandaloneChatPage`)
|
|
107
|
+
|
|
108
|
+
Sidebar + main thread + composer + new-chat modal:
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
// app/messages/page.tsx
|
|
112
|
+
"use client";
|
|
113
|
+
|
|
114
|
+
import { StandaloneChatPage } from "@anakin824/prdg-chat-ui";
|
|
115
|
+
import { ChatProviders } from "../chat-providers";
|
|
116
|
+
|
|
117
|
+
export default function MessagesPage() {
|
|
118
|
+
return (
|
|
119
|
+
<ChatProviders
|
|
120
|
+
apiUrl={process.env.NEXT_PUBLIC_CHAT_API_URL!}
|
|
121
|
+
token={/* your session JWT */}
|
|
122
|
+
userId={/* prdg-chat user id */}
|
|
123
|
+
tenantId={/* tenant id */}
|
|
124
|
+
>
|
|
125
|
+
<div style={{ flex: 1, minHeight: 0, display: "flex", flexDirection: "column" }}>
|
|
126
|
+
<StandaloneChatPage showNewChat />
|
|
127
|
+
</div>
|
|
128
|
+
</ChatProviders>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Give the parent a bounded height (e.g. `height: 100vh` on a wrapper) so the thread scrolls correctly.
|
|
134
|
+
|
|
135
|
+
Use `StandaloneChatPage` props (`conversationId`, `entityContext`, `peerUserId`, …) from `ChatPanelProps` / `StandaloneChatPageProps` for deep links or entity chats.
|
|
136
|
+
|
|
137
|
+
## Entity / order chat (thread + composer only)
|
|
138
|
+
|
|
139
|
+
Use `useChatPanelController` to resolve or create the entity conversation, then `ChatConversationView`:
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
"use client";
|
|
143
|
+
|
|
144
|
+
import { ChatConversationView, useChatPanelController } from "@anakin824/prdg-chat-ui";
|
|
145
|
+
|
|
146
|
+
export function OrderChat({ orderUuid }: { orderUuid: string }) {
|
|
147
|
+
const { selectedId } = useChatPanelController({
|
|
148
|
+
entityContext: {
|
|
149
|
+
entity_ref: "order",
|
|
150
|
+
entity_uuid: orderUuid,
|
|
151
|
+
title: `Order ${orderUuid}`,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
if (!selectedId) return <p>Preparing chat…</p>;
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<ChatConversationView
|
|
159
|
+
conversationId={selectedId}
|
|
160
|
+
header={<h2 style={{ margin: "0 0 8px", fontSize: 16 }}>Order discussion</h2>}
|
|
161
|
+
/>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Place `OrderChat` under `ChatProviders` (or any tree wrapped by `ChatProvider`).
|
|
167
|
+
|
|
168
|
+
## Composable pieces
|
|
169
|
+
|
|
170
|
+
Import and arrange your own layout:
|
|
171
|
+
|
|
172
|
+
- `ChatInboxSidebar`, `ChatMainColumn` — split sidebar vs main (same building blocks as `StandaloneChatPage`).
|
|
173
|
+
- `MessageThread`, `MessageInput` / `ChatComposer`, `TypingIndicator`, `ConversationList` — lower-level.
|
|
174
|
+
|
|
175
|
+
See package exports in `src/chat/index.ts` (published types in `dist/index.d.ts`).
|
|
176
|
+
|
|
177
|
+
## Environment variables
|
|
178
|
+
|
|
179
|
+
| Variable | Role |
|
|
180
|
+
|----------|------|
|
|
181
|
+
| `NEXT_PUBLIC_CHAT_API_URL` | API base for `apiUrl` |
|
|
182
|
+
| `NEXT_PUBLIC_NATS_WS_URL` | Optional NATS WebSocket URL |
|
|
183
|
+
| `NEXT_PUBLIC_CONDUITLY_TENANT_ID` | Optional; aligns NATS subjects with Conduitly |
|
|
184
|
+
|
|
185
|
+
Never expose long-lived secrets in `NEXT_PUBLIC_*`. Pass `token` from your session (server component or secure client session).
|
|
186
|
+
|
|
187
|
+
## Publish to npm (maintainers)
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
cd web
|
|
191
|
+
npm run build:lib
|
|
192
|
+
npm login
|
|
193
|
+
npm publish --access public
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
If you see **`ENEEDAUTH`**, run `npm login` (or set `NPM_TOKEN` and `.npmrc` as in [NPM-TOKEN-SETUP.md](./NPM-TOKEN-SETUP.md)).
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# NPM access for `@anakin824/*` (FinPod-style)
|
|
2
|
+
|
|
3
|
+
This mirrors the workflow used for `@anakin824/finpod-embedding` in ERP-POD: scoped package on the public npm registry, token-based auth, no committed secrets.
|
|
4
|
+
|
|
5
|
+
## 1. Create an access token
|
|
6
|
+
|
|
7
|
+
1. Open [npmjs.com](https://www.npmjs.com/) and sign in.
|
|
8
|
+
2. Profile → **Access Tokens** → **Generate New Token** (Granular or Automation for CI).
|
|
9
|
+
3. Copy the token once; store it in a password manager or CI secrets.
|
|
10
|
+
|
|
11
|
+
## 2. Login locally
|
|
12
|
+
|
|
13
|
+
**Option A — interactive**
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm login
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Option B — token as password (legacy)**
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm login --auth-type=legacy
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Use your npm username, paste the **token** as the password, and your email.
|
|
26
|
+
|
|
27
|
+
## 3. Scoped registry for `@anakin824` (recommended)
|
|
28
|
+
|
|
29
|
+
Create or edit **`.npmrc`** in your user home directory or in `web/` (do **not** commit real tokens):
|
|
30
|
+
|
|
31
|
+
```ini
|
|
32
|
+
@anakin824:registry=https://registry.npmjs.org/
|
|
33
|
+
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Then:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
export NPM_TOKEN=npm_xxxxx # Windows PowerShell: $env:NPM_TOKEN="npm_xxxxx"
|
|
40
|
+
cd web
|
|
41
|
+
npm whoami
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 4. Two-factor authentication (required for publish)
|
|
45
|
+
|
|
46
|
+
npm **requires** one of the following before `npm publish` will succeed (you may see **`E403`** with a message about 2FA otherwise):
|
|
47
|
+
|
|
48
|
+
1. **Enable 2FA on your npm account**
|
|
49
|
+
[npmjs.com](https://www.npmjs.com/) → profile → **Account** → **Enable Two-Factor Authentication** (auth app or security keys).
|
|
50
|
+
|
|
51
|
+
2. **Or** use a **granular access token** that is allowed to publish and satisfies npm’s policy:
|
|
52
|
+
Profile → **Access Tokens** → **Generate New Token** → **Granular Access Token** →
|
|
53
|
+
set **Packages and scopes** to the `@anakin824` scope (or the package), permission **Read and write**, and enable **“Bypass two-factor authentication for writes”** (or equivalent) if you publish from CI/automation without interactive OTP.
|
|
54
|
+
|
|
55
|
+
After enabling 2FA, sign out and **`npm login`** again so your local session is upgraded.
|
|
56
|
+
|
|
57
|
+
## 5. Publish
|
|
58
|
+
|
|
59
|
+
Ensure the library builds:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
cd web
|
|
63
|
+
npm run build:lib
|
|
64
|
+
npm publish --access public
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`package.json` already includes `"publishConfig": { "access": "public" }` for scoped packages.
|
|
68
|
+
|
|
69
|
+
**Do not** commit `.npmrc` with a literal `_authToken`. Use environment variables in CI (e.g. GitHub Actions `secrets.NPM_TOKEN`).
|
|
70
|
+
|
|
71
|
+
### If you see `E403` / “Two-factor authentication … is required”
|
|
72
|
+
|
|
73
|
+
That is **not** a bug in this repo — npm is enforcing account security. Fix it by enabling **2FA** on the publishing account and/or using a **granular token** with publish rights to `@anakin824/prdg-chat-ui`, then retry `npm publish`.
|
|
74
|
+
|
|
75
|
+
## 6. Verify
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npm view @anakin824/prdg-chat-ui version
|
|
79
|
+
```
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# `@anakin824/prdg-chat-ui`
|
|
2
|
+
|
|
3
|
+
Embeddable chat UI (React) for Prodigee / prdg-chat: provider, inbox sidebar, main column, entity thread + composer, and hooks.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @anakin824/prdg-chat-ui
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Peer dependencies (install in your app): `react`, `react-dom`, `@tanstack/react-query`, `date-fns`, `framer-motion`, `wavesurfer.js`, `yet-another-react-lightbox`, `react-intersection-observer`. Optional: `nats.ws` for realtime.
|
|
12
|
+
|
|
13
|
+
## Styles
|
|
14
|
+
|
|
15
|
+
Import the bundled CSS once near your app root (FinPod-style subpath export):
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import "@anakin824/prdg-chat-ui/styles";
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Library build (publish)
|
|
22
|
+
|
|
23
|
+
Same pattern as FinPod embedding: **`npm run build:lib`** runs **`tsup`** and writes **`dist/`** (`index.js`, `index.mjs`, `index.d.ts`, `index.css`). **`prepublishOnly`** runs that automatically before **`npm publish`**.
|
|
24
|
+
|
|
25
|
+
## Next.js embedding
|
|
26
|
+
|
|
27
|
+
See **[NEXTJS-INTEGRATION.md](./NEXTJS-INTEGRATION.md)** for App Router setup, `ChatProvider`, `StandaloneChatPage`, and entity chat.
|
|
28
|
+
|
|
29
|
+
## Auth / publish to npm
|
|
30
|
+
|
|
31
|
+
See [NPM-TOKEN-SETUP.md](./NPM-TOKEN-SETUP.md) for scoped registry (`@anakin824`) and token-based login.
|
|
32
|
+
|
|
33
|
+
## Develop this repo
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm run dev # Next.js app
|
|
37
|
+
npm run build:lib
|
|
38
|
+
npm run build # Next production build
|
|
39
|
+
```
|