chat 4.18.0 → 4.19.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/README.md +2 -0
- package/dist/index.d.ts +87 -9
- package/dist/index.js +57 -10
- package/dist/index.js.map +1 -1
- package/docs/adapters.mdx +56 -0
- package/docs/error-handling.mdx +1 -1
- package/docs/guides/code-review-hono.mdx +3 -3
- package/docs/guides/discord-nuxt.mdx +3 -2
- package/docs/guides/slack-nextjs.mdx +3 -2
- package/docs/meta.json +3 -4
- package/docs/slash-commands.mdx +4 -4
- package/docs/{state/index.mdx → state.mdx} +24 -12
- package/docs/usage.mdx +5 -0
- package/package.json +1 -1
- package/docs/adapters/discord.mdx +0 -217
- package/docs/adapters/gchat.mdx +0 -237
- package/docs/adapters/github.mdx +0 -222
- package/docs/adapters/index.mdx +0 -129
- package/docs/adapters/linear.mdx +0 -206
- package/docs/adapters/meta.json +0 -13
- package/docs/adapters/slack.mdx +0 -314
- package/docs/adapters/teams.mdx +0 -287
- package/docs/adapters/telegram.mdx +0 -161
- package/docs/state/ioredis.mdx +0 -81
- package/docs/state/memory.mdx +0 -52
- package/docs/state/meta.json +0 -4
- package/docs/state/postgres.mdx +0 -98
- package/docs/state/redis.mdx +0 -100
package/docs/state/redis.mdx
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Redis
|
|
3
|
-
description: Production state adapter using the official redis package.
|
|
4
|
-
type: reference
|
|
5
|
-
prerequisites:
|
|
6
|
-
- /docs/getting-started
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
The recommended state adapter for production. Uses the official [redis](https://www.npmjs.com/package/redis) package.
|
|
10
|
-
|
|
11
|
-
## Installation
|
|
12
|
-
|
|
13
|
-
```sh title="Terminal"
|
|
14
|
-
pnpm add @chat-adapter/state-redis
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Usage
|
|
18
|
-
|
|
19
|
-
`createRedisState()` auto-detects the `REDIS_URL` environment variable, so you can call it with no arguments:
|
|
20
|
-
|
|
21
|
-
```typescript title="lib/bot.ts" lineNumbers
|
|
22
|
-
import { Chat } from "chat";
|
|
23
|
-
import { createRedisState } from "@chat-adapter/state-redis";
|
|
24
|
-
|
|
25
|
-
const bot = new Chat({
|
|
26
|
-
userName: "mybot",
|
|
27
|
-
adapters: { /* ... */ },
|
|
28
|
-
state: createRedisState(),
|
|
29
|
-
});
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
To provide a URL explicitly:
|
|
33
|
-
|
|
34
|
-
```typescript title="lib/bot.ts"
|
|
35
|
-
const state = createRedisState({ url: "redis://localhost:6379" });
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
### Using an existing client
|
|
39
|
-
|
|
40
|
-
If you already have a connected Redis client, pass it directly:
|
|
41
|
-
|
|
42
|
-
```typescript title="lib/bot.ts" lineNumbers
|
|
43
|
-
import { createClient } from "redis";
|
|
44
|
-
|
|
45
|
-
const client = createClient({ url: "redis://localhost:6379" });
|
|
46
|
-
await client.connect();
|
|
47
|
-
|
|
48
|
-
const state = createRedisState({ client });
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Key prefix
|
|
52
|
-
|
|
53
|
-
All keys are namespaced under a configurable prefix (default: `"chat-sdk"`):
|
|
54
|
-
|
|
55
|
-
```typescript title="lib/bot.ts" lineNumbers
|
|
56
|
-
const state = createRedisState({
|
|
57
|
-
url: process.env.REDIS_URL!,
|
|
58
|
-
keyPrefix: "my-bot",
|
|
59
|
-
});
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Configuration
|
|
63
|
-
|
|
64
|
-
| Option | Required | Description |
|
|
65
|
-
|--------|----------|-------------|
|
|
66
|
-
| `url` | No* | Redis connection URL (auto-detected from `REDIS_URL`) |
|
|
67
|
-
| `client` | No | Existing `redis` client instance |
|
|
68
|
-
| `keyPrefix` | No | Prefix for all keys (default: `"chat-sdk"`) |
|
|
69
|
-
| `logger` | No | Logger instance (defaults to `ConsoleLogger("info")`) |
|
|
70
|
-
|
|
71
|
-
*Either `url`, `REDIS_URL` env var, or `client` is required.
|
|
72
|
-
|
|
73
|
-
## Environment variables
|
|
74
|
-
|
|
75
|
-
```bash title=".env.local"
|
|
76
|
-
REDIS_URL=redis://localhost:6379
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
For serverless deployments (Vercel, AWS Lambda), use a serverless-compatible Redis provider like [Upstash](https://upstash.com).
|
|
80
|
-
|
|
81
|
-
## Key structure
|
|
82
|
-
|
|
83
|
-
```
|
|
84
|
-
{keyPrefix}:subscriptions - SET of subscribed thread IDs
|
|
85
|
-
{keyPrefix}:lock:{threadId} - Lock key with TTL
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
## Production recommendations
|
|
89
|
-
|
|
90
|
-
- Use Redis 6.0+ for best performance
|
|
91
|
-
- Enable Redis persistence (RDB or AOF)
|
|
92
|
-
- Use Redis Cluster for high availability
|
|
93
|
-
- Set appropriate memory limits
|
|
94
|
-
|
|
95
|
-
## Features
|
|
96
|
-
|
|
97
|
-
- Persistent subscriptions across restarts
|
|
98
|
-
- Distributed locking across multiple instances
|
|
99
|
-
- Automatic reconnection
|
|
100
|
-
- Key prefix namespacing
|