chat 3.0.0 → 4.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.
@@ -0,0 +1,349 @@
1
+ /**
2
+ * Card elements for cross-platform rich messaging.
3
+ *
4
+ * Provides a builder API for creating rich cards that automatically
5
+ * convert to platform-specific formats:
6
+ * - Slack: Block Kit
7
+ * - Teams: Adaptive Cards
8
+ * - Google Chat: Card v2
9
+ *
10
+ * Supports both function-call and JSX syntax:
11
+ *
12
+ * @example Function API
13
+ * ```ts
14
+ * import { Card, Text, Actions, Button } from "chat";
15
+ *
16
+ * await thread.post(
17
+ * Card({
18
+ * title: "Order #1234",
19
+ * children: [
20
+ * Text("Total: $50.00"),
21
+ * Actions([
22
+ * Button({ id: "approve", label: "Approve", style: "primary" }),
23
+ * Button({ id: "reject", label: "Reject", style: "danger" }),
24
+ * ]),
25
+ * ],
26
+ * })
27
+ * );
28
+ * ```
29
+ *
30
+ * @example JSX API (requires jsxImportSource: "chat" in tsconfig)
31
+ * ```tsx
32
+ * /** @jsxImportSource chat *\/
33
+ * import { Card, Text, Actions, Button } from "chat";
34
+ *
35
+ * await thread.post(
36
+ * <Card title="Order #1234">
37
+ * <Text>Total: $50.00</Text>
38
+ * <Actions>
39
+ * <Button id="approve" style="primary">Approve</Button>
40
+ * <Button id="reject" style="danger">Reject</Button>
41
+ * </Actions>
42
+ * </Card>
43
+ * );
44
+ * ```
45
+ */
46
+ /** Button style options */
47
+ type ButtonStyle = "primary" | "danger" | "default";
48
+ /** Text style options */
49
+ type TextStyle = "plain" | "bold" | "muted";
50
+ /** Button element for interactive actions */
51
+ interface ButtonElement {
52
+ type: "button";
53
+ /** Unique action ID for callback routing */
54
+ id: string;
55
+ /** Button label text */
56
+ label: string;
57
+ /** Visual style */
58
+ style?: ButtonStyle;
59
+ /** Optional payload value sent with action callback */
60
+ value?: string;
61
+ }
62
+ /** Text content element */
63
+ interface TextElement {
64
+ type: "text";
65
+ /** Text content (supports markdown in some platforms) */
66
+ content: string;
67
+ /** Text style */
68
+ style?: TextStyle;
69
+ }
70
+ /** Image element */
71
+ interface ImageElement {
72
+ type: "image";
73
+ /** Image URL */
74
+ url: string;
75
+ /** Alt text for accessibility */
76
+ alt?: string;
77
+ }
78
+ /** Visual divider/separator */
79
+ interface DividerElement {
80
+ type: "divider";
81
+ }
82
+ /** Container for action buttons */
83
+ interface ActionsElement {
84
+ type: "actions";
85
+ /** Button elements */
86
+ children: ButtonElement[];
87
+ }
88
+ /** Section container for grouping elements */
89
+ interface SectionElement {
90
+ type: "section";
91
+ /** Section children */
92
+ children: CardChild[];
93
+ }
94
+ /** Field for key-value display */
95
+ interface FieldElement {
96
+ type: "field";
97
+ /** Field label */
98
+ label: string;
99
+ /** Field value */
100
+ value: string;
101
+ }
102
+ /** Fields container for multi-column layout */
103
+ interface FieldsElement {
104
+ type: "fields";
105
+ /** Field elements */
106
+ children: FieldElement[];
107
+ }
108
+ /** Union of all card child element types */
109
+ type CardChild = TextElement | ImageElement | DividerElement | ActionsElement | SectionElement | FieldsElement;
110
+ /** Union of all element types (including nested children) */
111
+ type AnyCardElement = CardChild | CardElement | ButtonElement | FieldElement;
112
+ /** Root card element */
113
+ interface CardElement {
114
+ type: "card";
115
+ /** Card title */
116
+ title?: string;
117
+ /** Card subtitle */
118
+ subtitle?: string;
119
+ /** Header image URL */
120
+ imageUrl?: string;
121
+ /** Card content */
122
+ children: CardChild[];
123
+ }
124
+ /** Type guard for CardElement */
125
+ declare function isCardElement(value: unknown): value is CardElement;
126
+ /** Options for Card */
127
+ interface CardOptions {
128
+ title?: string;
129
+ subtitle?: string;
130
+ imageUrl?: string;
131
+ children?: CardChild[];
132
+ }
133
+ /**
134
+ * Create a Card element.
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * Card({
139
+ * title: "Welcome",
140
+ * children: [Text("Hello!")],
141
+ * })
142
+ * ```
143
+ */
144
+ declare function Card(options?: CardOptions): CardElement;
145
+ /**
146
+ * Create a Text element.
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * Text("Hello, world!")
151
+ * Text("Important", { style: "bold" })
152
+ * ```
153
+ */
154
+ declare function Text(content: string, options?: {
155
+ style?: TextStyle;
156
+ }): TextElement;
157
+ /**
158
+ * Create an Image element.
159
+ *
160
+ * @example
161
+ * ```ts
162
+ * Image({ url: "https://example.com/image.png", alt: "Description" })
163
+ * ```
164
+ */
165
+ declare function Image(options: {
166
+ url: string;
167
+ alt?: string;
168
+ }): ImageElement;
169
+ /**
170
+ * Create a Divider element.
171
+ *
172
+ * @example
173
+ * ```ts
174
+ * Divider()
175
+ * ```
176
+ */
177
+ declare function Divider(): DividerElement;
178
+ /**
179
+ * Create a Section container.
180
+ *
181
+ * @example
182
+ * ```ts
183
+ * Section([
184
+ * Text("Grouped content"),
185
+ * Image({ url: "..." }),
186
+ * ])
187
+ * ```
188
+ */
189
+ declare function Section(children: CardChild[]): SectionElement;
190
+ /**
191
+ * Create an Actions container for buttons.
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * Actions([
196
+ * Button({ id: "ok", label: "OK" }),
197
+ * Button({ id: "cancel", label: "Cancel" }),
198
+ * ])
199
+ * ```
200
+ */
201
+ declare function Actions(children: ButtonElement[]): ActionsElement;
202
+ /** Options for Button */
203
+ interface ButtonOptions {
204
+ /** Unique action ID for callback routing */
205
+ id: string;
206
+ /** Button label text */
207
+ label: string;
208
+ /** Visual style */
209
+ style?: ButtonStyle;
210
+ /** Optional payload value sent with action callback */
211
+ value?: string;
212
+ }
213
+ /**
214
+ * Create a Button element.
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * Button({ id: "submit", label: "Submit", style: "primary" })
219
+ * Button({ id: "delete", label: "Delete", style: "danger", value: "item-123" })
220
+ * ```
221
+ */
222
+ declare function Button(options: ButtonOptions): ButtonElement;
223
+ /**
224
+ * Create a Field element for key-value display.
225
+ *
226
+ * @example
227
+ * ```ts
228
+ * Field({ label: "Status", value: "Active" })
229
+ * ```
230
+ */
231
+ declare function Field(options: {
232
+ label: string;
233
+ value: string;
234
+ }): FieldElement;
235
+ /**
236
+ * Create a Fields container for multi-column layout.
237
+ *
238
+ * @example
239
+ * ```ts
240
+ * Fields([
241
+ * Field({ label: "Name", value: "John" }),
242
+ * Field({ label: "Email", value: "john@example.com" }),
243
+ * ])
244
+ * ```
245
+ */
246
+ declare function Fields(children: FieldElement[]): FieldsElement;
247
+ /**
248
+ * Convert a React element tree to a CardElement tree.
249
+ * This allows using React's JSX with our card components.
250
+ *
251
+ * @example
252
+ * ```tsx
253
+ * import React from "react";
254
+ * import { Card, Text, fromReactElement } from "chat";
255
+ *
256
+ * const element = (
257
+ * <Card title="Hello">
258
+ * <Text>World</Text>
259
+ * </Card>
260
+ * );
261
+ *
262
+ * const card = fromReactElement(element);
263
+ * await thread.post(card);
264
+ * ```
265
+ */
266
+ declare function fromReactElement(element: unknown): AnyCardElement | null;
267
+
268
+ /**
269
+ * Custom JSX runtime for chat cards.
270
+ *
271
+ * This allows using JSX syntax without React. Configure your bundler:
272
+ *
273
+ * tsconfig.json:
274
+ * {
275
+ * "compilerOptions": {
276
+ * "jsx": "react-jsx",
277
+ * "jsxImportSource": "chat"
278
+ * }
279
+ * }
280
+ *
281
+ * Or per-file:
282
+ * /** @jsxImportSource chat *\/
283
+ *
284
+ * Usage:
285
+ * ```tsx
286
+ * import { Card, Text, Button, Actions } from "chat";
287
+ *
288
+ * const card = (
289
+ * <Card title="Order #1234">
290
+ * <Text>Your order is ready!</Text>
291
+ * <Actions>
292
+ * <Button id="pickup" style="primary">Schedule Pickup</Button>
293
+ * </Actions>
294
+ * </Card>
295
+ * );
296
+ * ```
297
+ */
298
+
299
+ declare const JSX_ELEMENT: unique symbol;
300
+ /**
301
+ * Represents a JSX element from the chat JSX runtime.
302
+ * This is the type returned when using JSX syntax with chat components.
303
+ */
304
+ interface CardJSXElement {
305
+ $$typeof: typeof JSX_ELEMENT;
306
+ type: CardComponentFunction;
307
+ props: Record<string, unknown>;
308
+ children: unknown[];
309
+ }
310
+ type JSXElement = CardJSXElement;
311
+ type CardComponentFunction = (...args: any[]) => CardElement | CardChild;
312
+ /**
313
+ * JSX factory function (used by the JSX transform).
314
+ * Creates a lazy JSX element that will be resolved when needed.
315
+ */
316
+ declare function jsx(type: CardComponentFunction, props: Record<string, unknown>, _key?: string): JSXElement;
317
+ /**
318
+ * JSX factory for elements with multiple children.
319
+ */
320
+ declare function jsxs(type: CardComponentFunction, props: Record<string, unknown>, _key?: string): JSXElement;
321
+ /**
322
+ * Development JSX factory (same as jsx, but called in dev mode).
323
+ */
324
+ declare const jsxDEV: typeof jsx;
325
+ /**
326
+ * Fragment support (flattens children).
327
+ */
328
+ declare function Fragment(props: {
329
+ children?: unknown;
330
+ }): CardChild[];
331
+ /**
332
+ * Convert a JSX element tree to a CardElement.
333
+ * Call this on the root JSX element to get a usable CardElement.
334
+ */
335
+ declare function toCardElement(jsxElement: unknown): CardElement | null;
336
+ /**
337
+ * Check if a value is a JSX element (from our runtime or React).
338
+ */
339
+ declare function isJSX(value: unknown): boolean;
340
+ declare namespace JSX {
341
+ interface Element extends JSXElement {
342
+ }
343
+ type IntrinsicElements = {};
344
+ interface ElementChildrenAttribute {
345
+ children: {};
346
+ }
347
+ }
348
+
349
+ export { Actions as A, Button as B, type CardElement as C, Divider as D, Field as F, Image as I, JSX as J, Section as S, Text as T, type CardJSXElement as a, type CardChild as b, Card as c, Fields as d, isJSX as e, fromReactElement as f, type ActionsElement as g, type ButtonElement as h, isCardElement as i, type ButtonOptions as j, type ButtonStyle as k, type CardOptions as l, type DividerElement as m, type FieldElement as n, type FieldsElement as o, type ImageElement as p, type SectionElement as q, type TextElement as r, type TextStyle as s, toCardElement as t, jsx as u, jsxs as v, jsxDEV as w, Fragment as x };
@@ -0,0 +1 @@
1
+ export { a as CardJSXElement, x as Fragment, J as JSX, e as isJSX, u as jsx, w as jsxDEV, v as jsxs, t as toCardElement } from './jsx-runtime-D7zHSnXe.js';
@@ -0,0 +1,17 @@
1
+ import {
2
+ Fragment,
3
+ isJSX,
4
+ jsx,
5
+ jsxDEV,
6
+ jsxs,
7
+ toCardElement
8
+ } from "./chunk-ACQNDPTB.js";
9
+ export {
10
+ Fragment,
11
+ isJSX,
12
+ jsx,
13
+ jsxDEV,
14
+ jsxs,
15
+ toCardElement
16
+ };
17
+ //# sourceMappingURL=jsx-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,4 +1,71 @@
1
1
  {
2
2
  "name": "chat",
3
- "version": "3.0.0"
4
- }
3
+ "version": "4.0.1",
4
+ "description": "Unified chat abstraction for Slack, Teams, Google Chat, and Discord",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./jsx-runtime": {
15
+ "types": "./dist/jsx-runtime.d.ts",
16
+ "import": "./dist/jsx-runtime.js"
17
+ },
18
+ "./jsx-dev-runtime": {
19
+ "types": "./dist/jsx-runtime.d.ts",
20
+ "import": "./dist/jsx-runtime.js"
21
+ }
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "dependencies": {
27
+ "unified": "^11.0.5",
28
+ "remark-parse": "^11.0.0",
29
+ "remark-stringify": "^11.0.0",
30
+ "remark-gfm": "^4.0.0",
31
+ "mdast-util-to-string": "^4.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^22.10.2",
35
+ "@types/mdast": "^4.0.4",
36
+ "tsup": "^8.3.5",
37
+ "typescript": "^5.7.2",
38
+ "vitest": "^2.1.8"
39
+ },
40
+ "peerDependencies": {},
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/vercel-labs/chat.git",
44
+ "directory": "packages/chat-sdk"
45
+ },
46
+ "homepage": "https://github.com/vercel-labs/chat#readme",
47
+ "bugs": {
48
+ "url": "https://github.com/vercel-labs/chat/issues"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "keywords": [
54
+ "chat",
55
+ "slack",
56
+ "teams",
57
+ "discord",
58
+ "google-chat",
59
+ "bot"
60
+ ],
61
+ "license": "MIT",
62
+ "scripts": {
63
+ "build": "rm -rf dist && tsup",
64
+ "dev": "tsup --watch",
65
+ "test": "vitest run",
66
+ "test:watch": "vitest",
67
+ "typecheck": "tsc --noEmit",
68
+ "lint": "biome check src",
69
+ "clean": "rm -rf dist"
70
+ }
71
+ }
package/readme.md DELETED
@@ -1 +0,0 @@
1
- # chat