strapi-plugin-ai-sdk 0.4.0 → 0.6.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.
Files changed (32) hide show
  1. package/README.md +99 -3
  2. package/dist/_chunks/App-DRve2JNH.js +2731 -0
  3. package/dist/_chunks/App-DeTHIZY1.mjs +2710 -0
  4. package/dist/_chunks/{index-DANEQIv3.mjs → index-Ba2NvTWa.mjs} +1 -1
  5. package/dist/_chunks/{index-50k6_o1L.js → index-BjecrblN.js} +1 -1
  6. package/dist/admin/index.js +1 -1
  7. package/dist/admin/index.mjs +1 -1
  8. package/dist/admin/src/hooks/usePublicMemories.d.ts +15 -0
  9. package/dist/admin/src/pages/PublicMemoryStorePage.d.ts +2 -0
  10. package/dist/admin/src/pages/WidgetPreviewPage.d.ts +1 -0
  11. package/dist/admin/src/utils/public-memories-api.d.ts +16 -0
  12. package/dist/server/index.js +379 -45
  13. package/dist/server/index.mjs +366 -51
  14. package/dist/server/src/config/index.d.ts +6 -0
  15. package/dist/server/src/content-types/index.d.ts +33 -0
  16. package/dist/server/src/content-types/public-memory/index.d.ts +34 -0
  17. package/dist/server/src/controllers/controller.d.ts +5 -0
  18. package/dist/server/src/controllers/index.d.ts +10 -0
  19. package/dist/server/src/controllers/public-memory.d.ts +11 -0
  20. package/dist/server/src/index.d.ts +54 -0
  21. package/dist/server/src/lib/tool-registry.d.ts +5 -1
  22. package/dist/server/src/lib/types.d.ts +9 -0
  23. package/dist/server/src/services/index.d.ts +3 -0
  24. package/dist/server/src/services/service.d.ts +6 -0
  25. package/dist/server/src/tool-logic/index.d.ts +2 -0
  26. package/dist/server/src/tool-logic/recall-public-memories.d.ts +17 -0
  27. package/dist/server/src/tools/definitions/recall-public-memories.d.ts +2 -0
  28. package/dist/server/src/tools/index.d.ts +6 -0
  29. package/dist/widget/widget.js +31 -0
  30. package/package.json +11 -2
  31. package/dist/_chunks/App-Bh3XakkL.js +0 -11930
  32. package/dist/_chunks/App-DRELwHzr.mjs +0 -11910
package/README.md CHANGED
@@ -7,6 +7,8 @@ A Strapi v5 plugin that adds an AI-powered chat assistant to the admin panel, ex
7
7
  - **Admin Chat UI** with 3D animated avatar, tool call visualization, and voice mode (TTS)
8
8
  - **Content Tools** -- the AI can list content types, search content, create/update documents, and send emails
9
9
  - **API Endpoints** -- `/ask`, `/ask-stream`, and `/chat` for frontend consumption (compatible with `useChat` from `@ai-sdk/react`)
10
+ - **Public Chat** -- sandboxed public-facing chat with read-only tools and a separate public memory store
11
+ - **Embeddable Widget** -- drop a single `<script>` tag on any website to add an AI chat bubble with 3D avatar
10
12
  - **MCP Server** -- expose tools to external AI clients (Claude Desktop, Cursor, etc.) via the Model Context Protocol
11
13
  - **Guardrails** -- regex-based input safety middleware that blocks prompt injection, jailbreaks, and destructive commands
12
14
  - **Extensible** -- register custom tools, AI providers, and TTS providers at runtime
@@ -53,6 +55,85 @@ In the Strapi admin panel:
53
55
  3. Under **Ai-sdk**, enable `ask`, `askStream`, and `chat`
54
56
  4. Save
55
57
 
58
+ ## Embeddable Chat Widget
59
+
60
+ Add a floating AI chat bubble to **any website** with a single script tag. No npm install, no build step, no React required.
61
+
62
+ ### 1. Enable the public chat endpoint
63
+
64
+ In the Strapi admin panel:
65
+
66
+ 1. Go to **Settings > Users & Permissions > Roles > Public**
67
+ 2. Under **Ai-sdk**, enable `publicChat` and `serveWidget`
68
+ 3. Save
69
+
70
+ ### 2. Add the script tag
71
+
72
+ ```html
73
+ <script src="https://your-strapi-url.com/api/ai-sdk/widget.js"></script>
74
+ ```
75
+
76
+ That's it. A floating chat button appears in the bottom-right corner. The widget auto-detects its Strapi URL from the script `src`.
77
+
78
+ ### Configuration via data attributes
79
+
80
+ ```html
81
+ <script
82
+ src="https://your-strapi-url.com/api/ai-sdk/widget.js"
83
+ data-api-token="your-api-token"
84
+ data-system-prompt="You are a helpful assistant for our store."
85
+ ></script>
86
+ ```
87
+
88
+ | Attribute | Description |
89
+ |-----------|-------------|
90
+ | `data-api-token` | Optional API token for authenticated requests |
91
+ | `data-system-prompt` | Override the default system prompt |
92
+
93
+ ### How it works
94
+
95
+ - The widget bundles React, Three.js, and AI SDK internally (~276KB gzipped)
96
+ - It renders inside a Shadow DOM so styles never conflict with your page
97
+ - It uses the `/api/ai-sdk/public-chat` endpoint which only exposes read-only tools
98
+ - The 3D avatar loads from `/models/avatar.glb` on your Strapi server (optional -- falls back to a procedural avatar)
99
+
100
+ ### Public Chat vs Admin Chat
101
+
102
+ | Feature | Admin Chat (`/chat`) | Public Chat (`/public-chat`) |
103
+ |---------|---------------------|------------------------------|
104
+ | Authentication | Admin JWT required | None (public endpoint) |
105
+ | Tools available | All tools (read + write) | Read-only tools only |
106
+ | Memory store | Per-user private memories | Shared public memories |
107
+ | Content access | All content types | Only configured `allowedContentTypes` |
108
+
109
+ ### Configuring public chat
110
+
111
+ In `config/plugins.ts`, add `publicChat` with the content types visitors can query:
112
+
113
+ ```typescript
114
+ 'ai-sdk': {
115
+ enabled: true,
116
+ config: {
117
+ anthropicApiKey: env('ANTHROPIC_API_KEY'),
118
+ publicChat: {
119
+ allowedContentTypes: [
120
+ 'api::article.article',
121
+ 'api::category.category',
122
+ 'api::product.product',
123
+ ],
124
+ },
125
+ },
126
+ },
127
+ ```
128
+
129
+ ### Managing public memories
130
+
131
+ Public memories are facts the AI knows when talking to visitors (e.g., "Our return policy is 30 days"). Manage them from the Strapi admin panel:
132
+
133
+ 1. Go to the **AI SDK** plugin page
134
+ 2. Click the globe icon in the chat toolbar
135
+ 3. Add, edit, or delete public memories with categories: General, FAQ, Product, Policy
136
+
56
137
  ## Configuration
57
138
 
58
139
  All plugin settings go in `config/plugins.ts` under the `ai-sdk` key:
@@ -82,6 +163,11 @@ export default ({ env }) => ({
82
163
  cleanupInterval: 100, // cleanup every N requests
83
164
  },
84
165
 
166
+ // Public Chat (optional)
167
+ publicChat: {
168
+ allowedContentTypes: ['api::article.article'],
169
+ },
170
+
85
171
  // Guardrails (optional)
86
172
  guardrails: {
87
173
  enabled: true, // default
@@ -112,6 +198,8 @@ export default ({ env }) => ({
112
198
  | `POST` | `/api/ai-sdk/ask` | Non-streaming text generation |
113
199
  | `POST` | `/api/ai-sdk/ask-stream` | Streaming text via Server-Sent Events |
114
200
  | `POST` | `/api/ai-sdk/chat` | Chat with AI SDK UI message stream protocol |
201
+ | `POST` | `/api/ai-sdk/public-chat` | Public chat with read-only tools and public memories |
202
+ | `GET` | `/api/ai-sdk/widget.js` | Embeddable chat widget script |
115
203
  | `POST` | `/api/ai-sdk/mcp` | MCP JSON-RPC requests |
116
204
  | `GET` | `/api/ai-sdk/mcp` | MCP session management |
117
205
  | `DELETE` | `/api/ai-sdk/mcp` | MCP session cleanup |
@@ -504,7 +592,8 @@ server/src/
504
592
  utils.ts # Controller helpers
505
593
  tts/ # TTS provider registry + Typecast
506
594
  controllers/
507
- controller.ts # ask, askStream, chat, tts handlers
595
+ controller.ts # ask, askStream, chat, publicChat, tts, serveWidget handlers
596
+ public-memory.ts # CRUD for public memories
508
597
  mcp.ts # MCP session management
509
598
  services/service.ts # AI service facade
510
599
  routes/
@@ -533,8 +622,15 @@ admin/src/
533
622
  useTextReveal.ts # Word-by-word text reveal
534
623
  context/ # Avatar animation context
535
624
 
536
- tests/ # E2E integration tests
537
- docs/ # Architecture + guardrails + email guides
625
+ widget/src/ # Embeddable chat widget (separate Vite build)
626
+ embed.tsx # Auto-mount entry (Shadow DOM)
627
+ react.tsx # React component export
628
+ auto-detect.ts # Script URL detection
629
+ styles.css # Scoped CSS (no Tailwind)
630
+ components/ # Chat + Avatar3D + animations
631
+
632
+ tests/ # E2E integration tests
633
+ docs/ # Architecture + guardrails + email guides
538
634
  ```
539
635
 
540
636
  ## Testing