wealth-alpha-chat-widget 1.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/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # wealth-alpha-chat
2
+
3
+ > Drop-in React / Next.js chat widget for **Wealth Alpha AI** — chip-driven flows, JWT auth, 30-minute sliding session, full markdown rendering, AI free-text routing via `/intent/detect` + `/ama/follow-up`.
4
+
5
+ The library is one component (`<WealthChat />`) plus a backend chat router (`chat_widget.py`) that proxies your 20 telegram-api endpoints, persists every turn, and returns chip + message responses ready to render.
6
+
7
+ ---
8
+
9
+ ## What you get
10
+
11
+ - **8 root chips** matching the Telegram bot: Stock Analysis, Stock Discovery, New Listings, Portfolio Risk, Market Forecast, Crypto, Tradable Picks, Peer Comparison
12
+ - **Multi-step flows** with chip + free-text inputs (`symbol → date → price → result`)
13
+ - **Drill-down chips** on every list result — click a stock row to dive into its analysis
14
+ - **AI free-text** — typed queries get classified by `/intent/detect` and routed to the right chip flow, with `/ama/follow-up` for ambiguous queries
15
+ - **30-minute sliding session** stored in `localStorage["wac_session"]`
16
+ - **Auto-discovers JWT** from `localStorage["token"]` (or `access_token` / `auth_token` / `jwt`) — no bridge code required in the host app
17
+ - **Auto-logout** — when the host app removes its token (user signs out), the chat clears its session on next render and shows the AuthGate
18
+ - **Server-side history** — every turn saved to `chat_messages` via the team's `ChatService`
19
+ - **Markdown rendering** with `markdown-it` — bold, italic, bullets, links, code, headings
20
+
21
+ ---
22
+
23
+ ## Repo layout
24
+
25
+ ```
26
+ Wealth-alpha-chat-UI/ ← the npm library
27
+ ├── src/
28
+ │ ├── components/ WealthChat, AuthGate, ChatBody, MessageBubble, ChipRow, …
29
+ │ ├── hooks/ useAuth, useSession, useChat, useChip
30
+ │ ├── api/ chatApi.ts (fetch wrapper: timeout, retry, abort, X-Request-Id)
31
+ │ ├── utils/ session.ts (JWT auto-discover), markdown.ts (markdown-it)
32
+ │ └── styles/ chat.module.css (CSS Modules, brand color via --wac-brand)
33
+ ├── dist/ tsup build output (ESM + CJS + .d.ts + .css)
34
+ ├── tsup.config.ts bundler (preserves "use client" for Next.js App Router)
35
+ ├── scripts/add-use-client.mjs post-build directive injector
36
+ └── docs/ SETUP.md · PUBLISH.md · DEPLOY.md · BACKEND_CHAT_WIDGET.md
37
+
38
+ WealthAlpha-Backend/app/api_v1/ ← team's FastAPI backend
39
+ ├── chat_widget.py chat router + chip tree + multi-step state + intent routing
40
+ ├── chat_formatters.py 18 template formatters (LONG_TERM, CRYPTO_ANALYSIS, …)
41
+ ├── chat.py team's chat persistence (CRUD)
42
+ ├── intent.py team's intent classifier
43
+ └── ama.py team's clarifying-question LLM
44
+ ```
45
+
46
+ ---
47
+
48
+ ## Quick install
49
+
50
+ ```bash
51
+ npm install wealth-alpha-chat
52
+ ```
53
+
54
+ In your app's root (e.g. `src/app/layout.tsx` for Next.js App Router):
55
+
56
+ ```tsx
57
+ import { WealthChat } from "wealth-alpha-chat";
58
+ import "wealth-alpha-chat/styles.css";
59
+
60
+ export default function RootLayout({ children }) {
61
+ return (
62
+ <html>
63
+ <body>
64
+ {children}
65
+ <WealthChat
66
+ apiBase={process.env.NEXT_PUBLIC_API_BASE ?? "http://localhost:8013/api/v1/chat-widget"}
67
+ authCheck="/me"
68
+ loginUrl="/login"
69
+ sessionTTL={1800}
70
+ brandName="Wealth Alpha AI"
71
+ brandColor="#1a2d5a"
72
+ position="bottom-right"
73
+ />
74
+ </body>
75
+ </html>
76
+ );
77
+ }
78
+ ```
79
+
80
+ Your existing JWT login (stored under `localStorage["token"]`) is automatically picked up — no bridge component needed.
81
+
82
+ For the full integration walkthrough see **[docs/SETUP.md](./docs/SETUP.md)**.
83
+
84
+ ---
85
+
86
+ ## Documentation
87
+
88
+ | Doc | Audience | What it covers |
89
+ |---|---|---|
90
+ | **[SETUP.md](./docs/SETUP.md)** | App developers integrating the widget | Install, mount, env vars, auth bridging, customization |
91
+ | **[PUBLISH.md](./docs/PUBLISH.md)** | Library maintainers | Version bump, build, npm pack, npm publish, pre-flight checklist |
92
+ | **[DEPLOY.md](./docs/DEPLOY.md)** | Ops / DevOps | Backend deploy (uvicorn + reverse proxy), frontend deploy, env config, scaling notes |
93
+ | **[BACKEND_CHAT_WIDGET.md](./docs/BACKEND_CHAT_WIDGET.md)** | Backend developers extending the chip tree | How `chat_widget.py` works, chip kinds, multi-step state, formatters, intent routing, drill-down chips |
94
+
95
+ ---
96
+
97
+ ## Tech stack
98
+
99
+ | Layer | Tool |
100
+ |---|---|
101
+ | UI | React 18 + TypeScript |
102
+ | Bundler | tsup (esbuild) → ESM + CJS + .d.ts + scoped CSS |
103
+ | Styles | CSS Modules — no global pollution |
104
+ | Markdown | markdown-it (XSS-safe, +27 KB) |
105
+ | HTTP | native `fetch` with retry/timeout/abort wrapper |
106
+ | Auth | JWT in `localStorage` (host app key — auto-discovered) |
107
+ | Backend | FastAPI + httpx (loopback to upstream telegram-api endpoints) |
108
+ | State | React Context-less — local hooks per component |
109
+ | Session storage | `localStorage` + in-memory dict per `sessionId` server-side |
110
+
111
+ ---
112
+
113
+ ## Development
114
+
115
+ ```bash
116
+ # Library
117
+ cd Wealth-alpha-chat-UI
118
+ npm install
119
+ npm run dev # tsup --watch (rebuilds on save)
120
+ npm run typecheck # tsc --noEmit
121
+ npm run build # production bundle to dist/
122
+
123
+ # Backend (separate terminal)
124
+ cd ../WealthAlpha-Backend
125
+ source venv/bin/activate
126
+ uvicorn main:app --reload --port 8013
127
+
128
+ # Frontend (separate terminal)
129
+ cd ../WealthAlpha-Frontend
130
+ npm install ../Wealth-alpha-chat-UI/wealth-alpha-chat-0.1.0.tgz --force
131
+ npm run dev # http://localhost:3000
132
+ ```
133
+
134
+ ---
135
+
136
+ ## License
137
+
138
+ MIT
139
+