chat 4.15.0 → 4.16.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.
@@ -0,0 +1,218 @@
1
+ ---
2
+ title: Documenting your adapter
3
+ description: Write a README, configuration reference, and usage examples for your community adapter.
4
+ type: guide
5
+ prerequisites:
6
+ - /docs/contributing/building
7
+ - /docs/contributing/testing
8
+ related:
9
+ - /docs/contributing/publishing
10
+ - /docs/adapters
11
+ ---
12
+
13
+ ## Why documentation matters
14
+
15
+ Your adapter's README is the first thing developers see on npm and GitHub. Clear documentation reduces support questions, builds trust, and encourages adoption.
16
+
17
+ All Vercel-maintained adapters follow a consistent structure. Community adapters should aim for the same bar.
18
+
19
+ ## README structure
20
+
21
+ Your `README.md` should include these sections in order:
22
+
23
+ ### Title and badges
24
+
25
+ Start with the package name as an H1, followed by npm badges and a one-line description.
26
+
27
+ ````markdown title="README.md"
28
+ # chat-adapter-matrix
29
+
30
+ [![npm version](https://img.shields.io/npm/v/chat-adapter-matrix)](https://www.npmjs.com/package/chat-adapter-matrix)
31
+ [![npm downloads](https://img.shields.io/npm/dm/chat-adapter-matrix)](https://www.npmjs.com/package/chat-adapter-matrix)
32
+
33
+ Matrix adapter for [Chat SDK](https://chat-sdk.dev/docs).
34
+ ````
35
+
36
+ ### Installation
37
+
38
+ Show the install command with `chat` as a co-dependency.
39
+
40
+ ````markdown title="README.md"
41
+ ## Installation
42
+
43
+ ```bash
44
+ npm install chat chat-adapter-matrix
45
+ ```
46
+ ````
47
+
48
+ ### Quick start
49
+
50
+ A minimal working example that developers can copy-paste. Include the factory function with explicit config so readers understand what credentials are needed.
51
+
52
+ ````markdown title="README.md"
53
+ ## Usage
54
+
55
+ ```typescript
56
+ import { Chat } from "chat";
57
+ import { createMatrixAdapter } from "chat-adapter-matrix";
58
+
59
+ const bot = new Chat({
60
+ userName: "mybot",
61
+ adapters: {
62
+ matrix: createMatrixAdapter({
63
+ homeserverUrl: process.env.MATRIX_HOMESERVER_URL!,
64
+ accessToken: process.env.MATRIX_ACCESS_TOKEN!,
65
+ }),
66
+ },
67
+ });
68
+
69
+ bot.onNewMention(async (thread, message) => {
70
+ await thread.post("Hello from Matrix!");
71
+ });
72
+ ```
73
+ ````
74
+
75
+ ### Environment variables
76
+
77
+ List every environment variable your adapter reads, with a description and example value.
78
+
79
+ ````markdown title="README.md"
80
+ ## Environment variables
81
+
82
+ | Variable | Required | Description |
83
+ |----------|----------|-------------|
84
+ | `MATRIX_HOMESERVER_URL` | Yes | Matrix homeserver URL (e.g., `https://matrix.example.com`) |
85
+ | `MATRIX_ACCESS_TOKEN` | Yes | Bot account access token |
86
+ | `MATRIX_BOT_USERNAME` | No | Override the bot display name |
87
+ ````
88
+
89
+ ### Configuration reference
90
+
91
+ Document every field in your config interface, including defaults.
92
+
93
+ ````markdown title="README.md"
94
+ ## Configuration
95
+
96
+ | Option | Type | Default | Description |
97
+ |--------|------|---------|-------------|
98
+ | `homeserverUrl` | `string` | `MATRIX_HOMESERVER_URL` | Matrix homeserver URL |
99
+ | `accessToken` | `string` | `MATRIX_ACCESS_TOKEN` | Bot account access token |
100
+ | `userName` | `string` | `"matrix-bot"` | Bot display name |
101
+ | `logger` | `Logger` | `ConsoleLogger` | Custom logger instance |
102
+ ````
103
+
104
+ ### Platform setup
105
+
106
+ Walk through creating the bot account on the platform. Use numbered steps, link to the platform's developer portal, and call out where to find each credential.
107
+
108
+ ````markdown title="README.md"
109
+ ## Platform setup
110
+
111
+ 1. Create a bot account on your Matrix homeserver
112
+ 2. Generate an access token for the bot
113
+ 3. Set the webhook URL to `https://your-domain.com/api/webhooks/matrix`
114
+ ````
115
+
116
+ ### Features
117
+
118
+ List what your adapter supports. Use a feature table if it helps. Call out any limitations.
119
+
120
+ ````markdown title="README.md"
121
+ ## Features
122
+
123
+ - Mentions and DMs
124
+ - Rich text (bold, italic, code, links)
125
+ - Reactions (add and remove)
126
+ - File uploads
127
+ - Typing indicators
128
+ - Thread support
129
+ ````
130
+
131
+ ### License
132
+
133
+ ````markdown title="README.md"
134
+ ## License
135
+
136
+ MIT
137
+ ````
138
+
139
+ ## Code-level documentation
140
+
141
+ ### Exported types
142
+
143
+ Export your config and thread ID interfaces so consumers can use them in their own type annotations. TypeScript declarations generated by `tsup` serve as the primary API reference — keep your interface fields descriptive enough that hover-over docs in an editor are useful.
144
+
145
+ ```typescript title="src/types.ts" lineNumbers
146
+ /** Configuration for the Matrix adapter */
147
+ export interface MatrixAdapterConfig {
148
+ /** Matrix homeserver URL (e.g., "https://matrix.example.com") */
149
+ homeserverUrl: string;
150
+ /** Access token for the bot account */
151
+ accessToken: string;
152
+ /** Override the bot display name (default: "matrix-bot") */
153
+ userName?: string;
154
+ }
155
+ ```
156
+
157
+ <Callout type="info">
158
+ TSDoc comments on exported interfaces and functions appear in IDE tooltips and generated `.d.ts` files. Keep them concise and factual.
159
+ </Callout>
160
+
161
+ ### What not to document
162
+
163
+ - Internal/private methods — they're implementation details
164
+ - Re-exported types from `chat` or `@chat-adapter/shared` — link to the upstream docs instead
165
+ - Obvious behavior — `postMessage` posts a message, no need to elaborate
166
+
167
+ ## Sample messages file
168
+
169
+ Include a `sample-messages.md` file in your package root with real webhook payloads from the platform. This is invaluable for other contributors debugging edge cases.
170
+
171
+ ````markdown title="sample-messages.md"
172
+ # Matrix sample messages
173
+
174
+ ## Text message
175
+
176
+ ```json
177
+ {
178
+ "type": "m.room.message",
179
+ "room_id": "!abc123:matrix.org",
180
+ "event_id": "$evt456",
181
+ "sender": "@alice:matrix.org",
182
+ "content": {
183
+ "msgtype": "m.text",
184
+ "body": "Hello world"
185
+ },
186
+ "origin_server_ts": 1700000000000
187
+ }
188
+ ```
189
+
190
+ ## Bot mention
191
+
192
+ ```json
193
+ {
194
+ "type": "m.room.message",
195
+ "room_id": "!abc123:matrix.org",
196
+ "event_id": "$evt789",
197
+ "sender": "@alice:matrix.org",
198
+ "content": {
199
+ "msgtype": "m.text",
200
+ "body": "@bot help me",
201
+ "format": "org.matrix.custom.html",
202
+ "formatted_body": "<a href=\"https://matrix.to/#/@bot:matrix.org\">bot</a> help me"
203
+ },
204
+ "origin_server_ts": 1700000001000
205
+ }
206
+ ```
207
+ ````
208
+
209
+ Existing Vercel-maintained adapters include `sample-messages.md` files in their package roots — check those for format reference.
210
+
211
+ ## Checklist
212
+
213
+ Before publishing, verify your documentation covers:
214
+
215
+ - [ ] README with badges, install, quick start, env vars, config reference, platform setup
216
+ - [ ] TSDoc comments on all exported interfaces and factory functions
217
+ - [ ] `sample-messages.md` with real platform webhook payloads
218
+ - [ ] Links to Chat SDK docs (`chat-sdk.dev`) where relevant
@@ -0,0 +1,4 @@
1
+ {
2
+ "title": "Contributing",
3
+ "pages": ["building", "testing", "documenting", "publishing"]
4
+ }
@@ -0,0 +1,161 @@
1
+ ---
2
+ title: Publishing your adapter
3
+ description: Package, version, and publish your community Chat SDK adapter to npm.
4
+ type: guide
5
+ prerequisites:
6
+ - /docs/contributing/building
7
+ - /docs/contributing/testing
8
+ - /docs/contributing/documenting
9
+ related:
10
+ - /docs/adapters
11
+ ---
12
+
13
+ ## Package checklist
14
+
15
+ Before publishing, verify your `package.json` meets these requirements:
16
+
17
+ ```json title="package.json" lineNumbers
18
+ {
19
+ "name": "chat-adapter-matrix",
20
+ "version": "1.0.0",
21
+ "type": "module",
22
+ "main": "./dist/index.js",
23
+ "module": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ }
30
+ },
31
+ "files": ["dist"],
32
+ "peerDependencies": {
33
+ "chat": "^4.0.0"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "keywords": ["chat-sdk", "chat-adapter", "matrix"],
39
+ "license": "MIT"
40
+ }
41
+ ```
42
+
43
+ | Field | Why it matters |
44
+ |-------|---------------|
45
+ | `"type": "module"` | ESM-only — matches the Chat SDK ecosystem |
46
+ | `"files": ["dist"]` | Only publish compiled output, keeping the package lean |
47
+ | `"exports"` | Explicit entry points for bundlers and Node.js |
48
+ | `"peerDependencies"` | Consumers provide their own `chat` instance |
49
+ | `"publishConfig"` | Required for scoped packages (`@your-scope/chat-adapter-*`) |
50
+ | `"keywords"` | Include `chat-sdk` and `chat-adapter` for npm discoverability |
51
+
52
+ ## Naming conventions
53
+
54
+ | Convention | Example | When to use |
55
+ |------------|---------|-------------|
56
+ | Unscoped | `chat-adapter-matrix` | Most community adapters |
57
+ | Scoped | `@your-org/chat-adapter-matrix` | Optional — if you prefer publishing under your org's scope |
58
+
59
+ <Callout type="warn">
60
+ The `@chat-adapter/` npm scope is reserved for Vercel-maintained adapters. Do not publish under this scope.
61
+ </Callout>
62
+
63
+ ## Build and verify
64
+
65
+ Run a full build and verify everything compiles before publishing.
66
+
67
+ ```sh title="Terminal"
68
+ # Build
69
+ npm run build
70
+
71
+ # Type-check
72
+ npm run typecheck
73
+
74
+ # Run tests
75
+ npm test
76
+ ```
77
+
78
+ Inspect the package contents to make sure only `dist/` is included:
79
+
80
+ ```sh title="Terminal"
81
+ npm pack --dry-run
82
+ ```
83
+
84
+ You should see output like:
85
+
86
+ ```
87
+ dist/index.js
88
+ dist/index.d.ts
89
+ dist/index.js.map
90
+ package.json
91
+ README.md
92
+ LICENSE
93
+ ```
94
+
95
+ If you see `src/`, `node_modules/`, or test files in the output, update your `"files"` field or add a `.npmignore`.
96
+
97
+ ## Versioning
98
+
99
+ Follow [semver](https://semver.org):
100
+
101
+ | Change | Bump | Example |
102
+ |--------|------|---------|
103
+ | Bug fix, internal refactor | `patch` | `1.0.0` → `1.0.1` |
104
+ | New feature, new export, new config option | `minor` | `1.0.0` → `1.1.0` |
105
+ | Breaking change (removed export, changed signature) | `major` | `1.0.0` → `2.0.0` |
106
+
107
+ When the Chat SDK releases a new major version, you'll need a major bump too if your adapter's peer dependency range changes.
108
+
109
+ ## Publish to npm
110
+
111
+ ```sh title="Terminal"
112
+ npm publish
113
+ ```
114
+
115
+ For scoped packages published for the first time:
116
+
117
+ ```sh title="Terminal"
118
+ npm publish --access public
119
+ ```
120
+
121
+ ## Peer dependency compatibility
122
+
123
+ Your adapter should declare `chat` as a peer dependency with a caret range:
124
+
125
+ ```json
126
+ {
127
+ "peerDependencies": {
128
+ "chat": "^4.0.0"
129
+ }
130
+ }
131
+ ```
132
+
133
+ This means your adapter works with any `4.x` release. When the Chat SDK ships a new major version:
134
+
135
+ 1. Test your adapter against the new version
136
+ 2. Update the peer dependency range
137
+ 3. Publish a new major version of your adapter
138
+
139
+ ## Post-publish verification
140
+
141
+ After publishing, verify the package works for consumers:
142
+
143
+ ```sh title="Terminal"
144
+ # Create a temp directory
145
+ mkdir /tmp/test-adapter && cd /tmp/test-adapter
146
+ npm init -y
147
+
148
+ # Install your adapter
149
+ npm install chat chat-adapter-matrix
150
+
151
+ # Verify the import works
152
+ node -e "import('chat-adapter-matrix').then(m => console.log(Object.keys(m)))"
153
+ ```
154
+
155
+ You should see your exported symbols (`createMatrixAdapter`, `MatrixAdapter`, etc.).
156
+
157
+ ## Keeping your adapter up to date
158
+
159
+ - Watch the [Chat SDK changelog](https://github.com/vercel/chat/releases) for new features and breaking changes
160
+ - Run your test suite against new Chat SDK releases before they ship to catch compatibility issues early
161
+ - When the `Adapter` interface adds new optional methods, consider implementing them to keep your adapter feature-complete