@21st-sdk/react 0.1.3 → 0.1.4
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/LICENSE +1 -1
- package/README.md +20 -20
- package/dist/index.cjs +17 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -36
- package/dist/index.d.ts +48 -36
- package/dist/index.js +13 -5
- package/dist/index.js.map +1 -1
- package/docs/02-getting-started.md +8 -8
- package/docs/04-react-ui.md +13 -13
- package/docs/05-nextjs.md +15 -15
- package/docs/06-node-sdk.md +8 -8
- package/docs/07-cli.md +1 -1
- package/docs/08-custom-tools.md +2 -2
- package/package.json +4 -4
- package/src/an-agent-chat.tsx +6 -3
- package/src/components/input/context-items.tsx +2 -2
- package/src/components/input/model-selector.tsx +3 -3
- package/src/components/input-bar.tsx +2 -2
- package/src/create-an-chat.ts +7 -4
- package/src/index.ts +11 -5
- package/src/models.ts +11 -6
- package/src/theme-config.ts +9 -6
- package/src/theme.ts +2 -2
- package/src/tools/tool-router.ts +3 -3
- package/src/types.ts +23 -15
|
@@ -56,11 +56,11 @@ npm install @21st-sdk/nextjs @21st-sdk/react ai @ai-sdk/react
|
|
|
56
56
|
Create a token route (keeps your API key on the server):
|
|
57
57
|
|
|
58
58
|
```ts
|
|
59
|
-
// app/api/
|
|
60
|
-
import {
|
|
59
|
+
// app/api/agent/token/route.ts
|
|
60
|
+
import { createTokenHandler } from "@21st-sdk/nextjs/server"
|
|
61
61
|
|
|
62
|
-
export const POST =
|
|
63
|
-
apiKey: process.env.
|
|
62
|
+
export const POST = createTokenHandler({
|
|
63
|
+
apiKey: process.env.API_KEY_21ST!,
|
|
64
64
|
})
|
|
65
65
|
```
|
|
66
66
|
|
|
@@ -71,15 +71,15 @@ Add the chat UI:
|
|
|
71
71
|
"use client"
|
|
72
72
|
|
|
73
73
|
import { useChat } from "@ai-sdk/react"
|
|
74
|
-
import {
|
|
74
|
+
import { AgentChat, createAgentChat } from "@21st-sdk/nextjs"
|
|
75
75
|
import "@21st-sdk/react/styles.css"
|
|
76
76
|
import { useMemo } from "react"
|
|
77
77
|
|
|
78
78
|
export default function Chat() {
|
|
79
79
|
const chat = useMemo(
|
|
80
|
-
() =>
|
|
80
|
+
() => createAgentChat({
|
|
81
81
|
agent: "your-agent-slug",
|
|
82
|
-
tokenUrl: "/api/
|
|
82
|
+
tokenUrl: "/api/agent/token",
|
|
83
83
|
}),
|
|
84
84
|
[],
|
|
85
85
|
)
|
|
@@ -87,7 +87,7 @@ export default function Chat() {
|
|
|
87
87
|
const { messages, sendMessage, status, stop, error } = useChat({ chat })
|
|
88
88
|
|
|
89
89
|
return (
|
|
90
|
-
<
|
|
90
|
+
<AgentChat
|
|
91
91
|
messages={messages}
|
|
92
92
|
onSend={(msg) =>
|
|
93
93
|
sendMessage({ parts: [{ type: "text", text: msg.content }] })
|
package/docs/04-react-ui.md
CHANGED
|
@@ -14,13 +14,13 @@ npm install @21st-sdk/react ai @ai-sdk/react
|
|
|
14
14
|
"use client"
|
|
15
15
|
|
|
16
16
|
import { useChat } from "@ai-sdk/react"
|
|
17
|
-
import {
|
|
17
|
+
import { AgentChat, createAgentChat } from "@21st-sdk/react"
|
|
18
18
|
import "@21st-sdk/react/styles.css"
|
|
19
19
|
import { useMemo } from "react"
|
|
20
20
|
|
|
21
21
|
export default function Chat() {
|
|
22
22
|
const chat = useMemo(
|
|
23
|
-
() =>
|
|
23
|
+
() => createAgentChat({
|
|
24
24
|
agent: "your-agent-slug",
|
|
25
25
|
getToken: async () => "your_an_sk_token",
|
|
26
26
|
}),
|
|
@@ -30,7 +30,7 @@ export default function Chat() {
|
|
|
30
30
|
const { messages, sendMessage, status, stop, error } = useChat({ chat })
|
|
31
31
|
|
|
32
32
|
return (
|
|
33
|
-
<
|
|
33
|
+
<AgentChat
|
|
34
34
|
messages={messages}
|
|
35
35
|
onSend={(msg) =>
|
|
36
36
|
sendMessage({ parts: [{ type: "text", text: msg.content }] })
|
|
@@ -43,12 +43,12 @@ export default function Chat() {
|
|
|
43
43
|
}
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
## `
|
|
46
|
+
## `createAgentChat(options)`
|
|
47
47
|
|
|
48
48
|
Creates an AI SDK `Chat` instance pointed at the AN Relay.
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
|
-
|
|
51
|
+
createAgentChat({
|
|
52
52
|
agent: string // Agent slug from dashboard
|
|
53
53
|
getToken: () => Promise<string> // Returns an_sk_ key or JWT
|
|
54
54
|
apiUrl?: string // Default: "https://relay.an.dev"
|
|
@@ -60,7 +60,7 @@ createAnChat({
|
|
|
60
60
|
|
|
61
61
|
For Next.js apps, use `tokenUrl` instead of `getToken` — see [Next.js Integration](./05-nextjs.md).
|
|
62
62
|
|
|
63
|
-
## `<
|
|
63
|
+
## `<AgentChat />` Props
|
|
64
64
|
|
|
65
65
|
| Prop | Type | Description |
|
|
66
66
|
|------|------|-------------|
|
|
@@ -69,10 +69,10 @@ For Next.js apps, use `tokenUrl` instead of `getToken` — see [Next.js Integrat
|
|
|
69
69
|
| `status` | `ChatStatus` | `"ready" \| "submitted" \| "streaming" \| "error"` |
|
|
70
70
|
| `onStop` | `() => void` | Stop generation |
|
|
71
71
|
| `error` | `Error` | Error to display |
|
|
72
|
-
| `theme` | `
|
|
72
|
+
| `theme` | `ChatTheme` | Theme from playground |
|
|
73
73
|
| `colorMode` | `"light" \| "dark" \| "auto"` | Color mode |
|
|
74
|
-
| `classNames` | `Partial<
|
|
75
|
-
| `slots` | `Partial<
|
|
74
|
+
| `classNames` | `Partial<ChatClassNames>` | Per-element CSS overrides |
|
|
75
|
+
| `slots` | `Partial<ChatSlots>` | Component swapping |
|
|
76
76
|
| `className` | `string` | Root element class |
|
|
77
77
|
| `style` | `CSSProperties` | Root element style |
|
|
78
78
|
|
|
@@ -85,13 +85,13 @@ Four levels, from simple to full control:
|
|
|
85
85
|
Apply a theme JSON from the [AN Playground](https://21st.dev/agents/playground):
|
|
86
86
|
|
|
87
87
|
```tsx
|
|
88
|
-
<
|
|
88
|
+
<AgentChat theme={playgroundTheme} colorMode="dark" />
|
|
89
89
|
```
|
|
90
90
|
|
|
91
91
|
### 2. Class overrides
|
|
92
92
|
|
|
93
93
|
```tsx
|
|
94
|
-
<
|
|
94
|
+
<AgentChat
|
|
95
95
|
classNames={{
|
|
96
96
|
root: "rounded-2xl border",
|
|
97
97
|
messageList: "px-8",
|
|
@@ -106,7 +106,7 @@ Apply a theme JSON from the [AN Playground](https://21st.dev/agents/playground):
|
|
|
106
106
|
Swap sub-components:
|
|
107
107
|
|
|
108
108
|
```tsx
|
|
109
|
-
<
|
|
109
|
+
<AgentChat
|
|
110
110
|
slots={{
|
|
111
111
|
InputBar: MyCustomInput,
|
|
112
112
|
UserMessage: MyUserBubble,
|
|
@@ -145,7 +145,7 @@ No Tailwind peer dependency — CSS is pre-compiled. All elements have stable `a
|
|
|
145
145
|
## Theme Type
|
|
146
146
|
|
|
147
147
|
```ts
|
|
148
|
-
interface
|
|
148
|
+
interface ChatTheme {
|
|
149
149
|
theme: Record<string, string> // Shared: font, spacing, accent
|
|
150
150
|
light: Record<string, string> // Light mode CSS vars
|
|
151
151
|
dark: Record<string, string> // Dark mode CSS vars
|
package/docs/05-nextjs.md
CHANGED
|
@@ -14,7 +14,7 @@ npm install @21st-sdk/nextjs @21st-sdk/react ai @ai-sdk/react
|
|
|
14
14
|
|
|
15
15
|
```env
|
|
16
16
|
# .env.local
|
|
17
|
-
|
|
17
|
+
API_KEY_21ST=an_sk_your_key_here
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
Get your API key from [the dashboard](https://21st.dev/agents/dashboard/api).
|
|
@@ -22,11 +22,11 @@ Get your API key from [the dashboard](https://21st.dev/agents/dashboard/api).
|
|
|
22
22
|
### 2. Create the token route
|
|
23
23
|
|
|
24
24
|
```ts
|
|
25
|
-
// app/api/
|
|
26
|
-
import {
|
|
25
|
+
// app/api/agent/token/route.ts
|
|
26
|
+
import { createTokenHandler } from "@21st-sdk/nextjs/server"
|
|
27
27
|
|
|
28
|
-
export const POST =
|
|
29
|
-
apiKey: process.env.
|
|
28
|
+
export const POST = createTokenHandler({
|
|
29
|
+
apiKey: process.env.API_KEY_21ST!,
|
|
30
30
|
})
|
|
31
31
|
```
|
|
32
32
|
|
|
@@ -37,15 +37,15 @@ export const POST = createAnTokenHandler({
|
|
|
37
37
|
"use client"
|
|
38
38
|
|
|
39
39
|
import { useChat } from "@ai-sdk/react"
|
|
40
|
-
import {
|
|
40
|
+
import { AgentChat, createAgentChat } from "@21st-sdk/nextjs"
|
|
41
41
|
import "@21st-sdk/react/styles.css"
|
|
42
42
|
import { useMemo } from "react"
|
|
43
43
|
|
|
44
44
|
export default function Chat() {
|
|
45
45
|
const chat = useMemo(
|
|
46
|
-
() =>
|
|
46
|
+
() => createAgentChat({
|
|
47
47
|
agent: "your-agent-slug",
|
|
48
|
-
tokenUrl: "/api/
|
|
48
|
+
tokenUrl: "/api/agent/token",
|
|
49
49
|
}),
|
|
50
50
|
[],
|
|
51
51
|
)
|
|
@@ -53,7 +53,7 @@ export default function Chat() {
|
|
|
53
53
|
const { messages, sendMessage, status, stop, error } = useChat({ chat })
|
|
54
54
|
|
|
55
55
|
return (
|
|
56
|
-
<
|
|
56
|
+
<AgentChat
|
|
57
57
|
messages={messages}
|
|
58
58
|
onSend={(msg) =>
|
|
59
59
|
sendMessage({ parts: [{ type: "text", text: msg.content }] })
|
|
@@ -71,7 +71,7 @@ export default function Chat() {
|
|
|
71
71
|
```
|
|
72
72
|
Browser Your Next.js Server AN Relay
|
|
73
73
|
| | |
|
|
74
|
-
|-- POST /api/
|
|
74
|
+
|-- POST /api/agent/token ------>| |
|
|
75
75
|
| |-- POST /v1/tokens -------->|
|
|
76
76
|
| | (with an_sk_ key) |
|
|
77
77
|
| |<-- { token, expiresAt } ---|
|
|
@@ -85,12 +85,12 @@ The client only receives short-lived JWTs. Your API key stays on the server.
|
|
|
85
85
|
|
|
86
86
|
## API
|
|
87
87
|
|
|
88
|
-
### `
|
|
88
|
+
### `createTokenHandler(options)`
|
|
89
89
|
|
|
90
90
|
Returns a Next.js `POST` route handler.
|
|
91
91
|
|
|
92
92
|
```ts
|
|
93
|
-
|
|
93
|
+
createTokenHandler({
|
|
94
94
|
apiKey: string // Your an_sk_ API key
|
|
95
95
|
relayUrl?: string // Default: "https://relay.an.dev"
|
|
96
96
|
expiresIn?: string // Default: "1h"
|
|
@@ -105,7 +105,7 @@ Lower-level function for custom token exchange logic.
|
|
|
105
105
|
import { exchangeToken } from "@21st-sdk/nextjs/server"
|
|
106
106
|
|
|
107
107
|
const { token, expiresAt } = await exchangeToken({
|
|
108
|
-
apiKey: process.env.
|
|
108
|
+
apiKey: process.env.API_KEY_21ST!,
|
|
109
109
|
relayUrl: "https://relay.an.dev",
|
|
110
110
|
expiresIn: "1h",
|
|
111
111
|
})
|
|
@@ -113,5 +113,5 @@ const { token, expiresAt } = await exchangeToken({
|
|
|
113
113
|
|
|
114
114
|
## Entry Points
|
|
115
115
|
|
|
116
|
-
- `@21st-sdk/nextjs` — Re-exports everything from `@21st-sdk/react` (components, types, `
|
|
117
|
-
- `@21st-sdk/nextjs/server` — Server-only: `
|
|
116
|
+
- `@21st-sdk/nextjs` — Re-exports everything from `@21st-sdk/react` (components, types, `createAgentChat`)
|
|
117
|
+
- `@21st-sdk/nextjs/server` — Server-only: `createTokenHandler`, `exchangeToken`
|
package/docs/06-node-sdk.md
CHANGED
|
@@ -11,32 +11,32 @@ npm install @21st-sdk/node
|
|
|
11
11
|
## Quick Start
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
import {
|
|
14
|
+
import { AgentClient } from "@21st-sdk/node"
|
|
15
15
|
|
|
16
|
-
const
|
|
17
|
-
apiKey: process.env.
|
|
16
|
+
const client = new AgentClient({
|
|
17
|
+
apiKey: process.env.API_KEY_21ST!, // an_sk_...
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
// Create a sandbox for your agent
|
|
21
|
-
const sandbox = await
|
|
21
|
+
const sandbox = await client.sandboxes.create({ agent: "my-agent" })
|
|
22
22
|
|
|
23
23
|
// Create a thread
|
|
24
|
-
const thread = await
|
|
24
|
+
const thread = await client.threads.create({
|
|
25
25
|
sandboxId: sandbox.sandboxId,
|
|
26
26
|
name: "Review PR #42",
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
// Generate a short-lived token for browser clients
|
|
30
|
-
const { token, expiresAt } = await
|
|
30
|
+
const { token, expiresAt } = await client.tokens.create({
|
|
31
31
|
agent: "my-agent",
|
|
32
32
|
expiresIn: "1h",
|
|
33
33
|
})
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
## `
|
|
36
|
+
## `AgentClient`
|
|
37
37
|
|
|
38
38
|
```ts
|
|
39
|
-
new
|
|
39
|
+
new AgentClient({
|
|
40
40
|
apiKey: string // Your an_sk_ API key
|
|
41
41
|
baseUrl?: string // Default: "https://relay.an.dev"
|
|
42
42
|
})
|
package/docs/07-cli.md
CHANGED
|
@@ -85,4 +85,4 @@ The CLI uses esbuild to bundle your agent code:
|
|
|
85
85
|
|
|
86
86
|
| Variable | Default | Description |
|
|
87
87
|
|----------|---------|-------------|
|
|
88
|
-
| `
|
|
88
|
+
| `API_URL_21ST` | `https://an.dev/api/v1` | Override API endpoint |
|
package/docs/08-custom-tools.md
CHANGED
|
@@ -24,7 +24,7 @@ These are rendered automatically when your agent uses standard tools:
|
|
|
24
24
|
To render your custom tools differently, use the `slots.ToolRenderer` prop:
|
|
25
25
|
|
|
26
26
|
```tsx
|
|
27
|
-
import {
|
|
27
|
+
import { AgentChat, ToolRenderer } from "@21st-sdk/react"
|
|
28
28
|
import type { ToolPart } from "@21st-sdk/react"
|
|
29
29
|
|
|
30
30
|
function MyToolRenderer(props: { part: ToolPart; status: string }) {
|
|
@@ -49,7 +49,7 @@ function MyToolRenderer(props: { part: ToolPart; status: string }) {
|
|
|
49
49
|
return <ToolRenderer part={part} status={status} />
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
<
|
|
52
|
+
<AgentChat
|
|
53
53
|
slots={{ ToolRenderer: MyToolRenderer }}
|
|
54
54
|
// ... other props
|
|
55
55
|
/>
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@21st-sdk/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"description": "React components for
|
|
5
|
+
"description": "React components for 21st Agents chat UIs",
|
|
6
6
|
"homepage": "https://21st.dev/agents",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"agent",
|
|
45
45
|
"chat",
|
|
46
46
|
"ai-sdk",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
47
|
+
"21st",
|
|
48
|
+
"21st.dev",
|
|
49
49
|
"components",
|
|
50
50
|
"ui"
|
|
51
51
|
],
|
package/src/an-agent-chat.tsx
CHANGED
|
@@ -5,9 +5,9 @@ import { WindowChrome } from "./components/window-chrome"
|
|
|
5
5
|
import { applyTheme } from "./theme"
|
|
6
6
|
import { cn } from "./utils/cn"
|
|
7
7
|
import { ThemeConfigContext, extractThemeConfig } from "./theme-config"
|
|
8
|
-
import type {
|
|
8
|
+
import type { AgentChatProps } from "./types"
|
|
9
9
|
|
|
10
|
-
export function
|
|
10
|
+
export function AgentChat({
|
|
11
11
|
messages,
|
|
12
12
|
onSend,
|
|
13
13
|
status,
|
|
@@ -24,7 +24,7 @@ export function AnAgentChat({
|
|
|
24
24
|
attachments,
|
|
25
25
|
className,
|
|
26
26
|
style,
|
|
27
|
-
}:
|
|
27
|
+
}: AgentChatProps) {
|
|
28
28
|
const rootRef = useRef<HTMLDivElement>(null)
|
|
29
29
|
|
|
30
30
|
useEffect(() => {
|
|
@@ -99,3 +99,6 @@ export function AnAgentChat({
|
|
|
99
99
|
</ThemeConfigContext.Provider>
|
|
100
100
|
)
|
|
101
101
|
}
|
|
102
|
+
|
|
103
|
+
// Legacy component alias kept for compatibility.
|
|
104
|
+
export const AnAgentChat = AgentChat
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ImageThumbInput } from "./image-thumb-input"
|
|
2
2
|
import { FileChip } from "./file-chip"
|
|
3
|
-
import type {
|
|
3
|
+
import type { ChatThemeConfig } from "../../theme-config"
|
|
4
4
|
|
|
5
5
|
export interface AttachedImage {
|
|
6
6
|
id: string
|
|
@@ -18,7 +18,7 @@ export interface AttachedFile {
|
|
|
18
18
|
interface ContextItemsProps {
|
|
19
19
|
images: AttachedImage[]
|
|
20
20
|
files: AttachedFile[]
|
|
21
|
-
previewStyle:
|
|
21
|
+
previewStyle: ChatThemeConfig["attachmentPreviewStyle"]
|
|
22
22
|
innerRadius?: number
|
|
23
23
|
onRemoveImage?: (id: string) => void
|
|
24
24
|
onRemoveFile?: (id: string) => void
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useState } from "react"
|
|
2
|
-
import type {
|
|
2
|
+
import type { ModelOption } from "../../types"
|
|
3
3
|
import { ChevronDown } from "../../icons/tool-icons"
|
|
4
4
|
import { PopoverShell } from "./popover-shell"
|
|
5
5
|
|
|
@@ -9,7 +9,7 @@ export function ModelPopover({
|
|
|
9
9
|
onModelChange,
|
|
10
10
|
innerRadius,
|
|
11
11
|
}: {
|
|
12
|
-
models:
|
|
12
|
+
models: ModelOption[]
|
|
13
13
|
activeModelId?: string
|
|
14
14
|
onModelChange?: (id: string) => void
|
|
15
15
|
innerRadius?: number
|
|
@@ -63,7 +63,7 @@ export function ModelBadge({
|
|
|
63
63
|
activeModelId,
|
|
64
64
|
innerRadius,
|
|
65
65
|
}: {
|
|
66
|
-
models:
|
|
66
|
+
models: ModelOption[]
|
|
67
67
|
activeModelId?: string
|
|
68
68
|
innerRadius?: number
|
|
69
69
|
}) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { memo, useState, useCallback, useRef, useEffect } from "react"
|
|
2
2
|
import type { ChatStatus } from "ai"
|
|
3
|
-
import type {
|
|
3
|
+
import type { ModelOption } from "../types"
|
|
4
4
|
import { cn } from "../utils/cn"
|
|
5
5
|
import { useThemeConfig } from "../theme-config"
|
|
6
6
|
import { SendButtonUnified } from "./input/send-button"
|
|
@@ -30,7 +30,7 @@ interface InputBarProps {
|
|
|
30
30
|
|
|
31
31
|
// Model selector
|
|
32
32
|
modelSelector?: {
|
|
33
|
-
models:
|
|
33
|
+
models: ModelOption[]
|
|
34
34
|
activeModelId?: string
|
|
35
35
|
onModelChange?: (id: string) => void
|
|
36
36
|
display?: "popover" | "badge"
|
package/src/create-an-chat.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Chat } from "@ai-sdk/react"
|
|
2
2
|
import { DefaultChatTransport, type UIMessage } from "ai"
|
|
3
|
-
import type {
|
|
3
|
+
import type { CreateAgentChatOptions } from "./types"
|
|
4
4
|
|
|
5
5
|
const DEFAULT_API_URL = "https://relay.an.dev"
|
|
6
6
|
|
|
@@ -29,8 +29,8 @@ function createTokenFetcher(tokenUrl: string, agent: string) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/** Create an AI SDK Chat instance pointed at the
|
|
33
|
-
export function
|
|
32
|
+
/** Create an AI SDK Chat instance pointed at the relay API */
|
|
33
|
+
export function createAgentChat(options: CreateAgentChatOptions): Chat<UIMessage> {
|
|
34
34
|
const {
|
|
35
35
|
agent,
|
|
36
36
|
tokenUrl,
|
|
@@ -44,7 +44,7 @@ export function createAnChat(options: CreateAnChatOptions): Chat<UIMessage> {
|
|
|
44
44
|
|
|
45
45
|
const getToken = getTokenFn || (tokenUrl ? createTokenFetcher(tokenUrl, agent) : null)
|
|
46
46
|
if (!getToken) {
|
|
47
|
-
throw new Error("
|
|
47
|
+
throw new Error("createAgentChat: provide either tokenUrl or getToken")
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
return new Chat({
|
|
@@ -64,3 +64,6 @@ export function createAnChat(options: CreateAnChatOptions): Chat<UIMessage> {
|
|
|
64
64
|
onError,
|
|
65
65
|
})
|
|
66
66
|
}
|
|
67
|
+
|
|
68
|
+
// Legacy factory alias kept for compatibility.
|
|
69
|
+
export const createAnChat = createAgentChat
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Main drop-in component
|
|
2
|
-
export { AnAgentChat } from "./an-agent-chat"
|
|
2
|
+
export { AgentChat, AnAgentChat } from "./an-agent-chat"
|
|
3
3
|
|
|
4
4
|
// Chat factory
|
|
5
|
-
export { createAnChat } from "./create-an-chat"
|
|
5
|
+
export { createAgentChat, createAnChat } from "./create-an-chat"
|
|
6
6
|
|
|
7
7
|
// Theme
|
|
8
8
|
export { applyTheme } from "./theme"
|
|
@@ -71,11 +71,17 @@ export { FileExtIcon } from "./icons/file-ext-icon"
|
|
|
71
71
|
export { PaperclipIcon } from "./icons/shared-icons"
|
|
72
72
|
|
|
73
73
|
// Models
|
|
74
|
-
export { AN_CLAUDE_MODELS, AN_DEFAULT_MODEL_ID } from "./models"
|
|
75
|
-
export type { AnClaudeModelId } from "./models"
|
|
74
|
+
export { CLAUDE_MODELS, DEFAULT_MODEL_ID, AN_CLAUDE_MODELS, AN_DEFAULT_MODEL_ID } from "./models"
|
|
75
|
+
export type { ClaudeModelId, AnClaudeModelId } from "./models"
|
|
76
76
|
|
|
77
77
|
// Types
|
|
78
78
|
export type {
|
|
79
|
+
ChatTheme,
|
|
80
|
+
ChatClassNames,
|
|
81
|
+
ChatSlots,
|
|
82
|
+
ModelOption,
|
|
83
|
+
CreateAgentChatOptions,
|
|
84
|
+
AgentChatProps,
|
|
79
85
|
AnTheme,
|
|
80
86
|
AnClassNames,
|
|
81
87
|
AnSlots,
|
|
@@ -84,7 +90,7 @@ export type {
|
|
|
84
90
|
AnAgentChatProps,
|
|
85
91
|
CustomToolRendererProps,
|
|
86
92
|
} from "./types"
|
|
87
|
-
export type { AnThemeConfig } from "./theme-config"
|
|
93
|
+
export type { ChatThemeConfig, AnThemeConfig } from "./theme-config"
|
|
88
94
|
export type { TimelineStep, StepState } from "./types/timeline"
|
|
89
95
|
export type { ToolSize } from "./types/tool-styles"
|
|
90
96
|
export type { SourceType } from "./icons/source-icons"
|
package/src/models.ts
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ModelOption } from "./types"
|
|
2
2
|
|
|
3
|
-
/** Claude model IDs supported by the
|
|
4
|
-
export type
|
|
3
|
+
/** Claude model IDs supported by the relay */
|
|
4
|
+
export type ClaudeModelId = "opus" | "sonnet" | "haiku"
|
|
5
5
|
|
|
6
|
-
/** Pre-defined Claude models available through
|
|
7
|
-
export const
|
|
6
|
+
/** Pre-defined Claude models available through the relay */
|
|
7
|
+
export const CLAUDE_MODELS: ModelOption[] = [
|
|
8
8
|
{ id: "sonnet", name: "Sonnet", version: "4.6" },
|
|
9
9
|
{ id: "opus", name: "Opus", version: "4.6" },
|
|
10
10
|
{ id: "haiku", name: "Haiku", version: "4.5" },
|
|
11
11
|
]
|
|
12
12
|
|
|
13
13
|
/** Default model ID */
|
|
14
|
-
export const
|
|
14
|
+
export const DEFAULT_MODEL_ID: ClaudeModelId = "sonnet"
|
|
15
|
+
|
|
16
|
+
// Legacy model aliases kept for compatibility.
|
|
17
|
+
export type AnClaudeModelId = ClaudeModelId
|
|
18
|
+
export const AN_CLAUDE_MODELS = CLAUDE_MODELS
|
|
19
|
+
export const AN_DEFAULT_MODEL_ID = DEFAULT_MODEL_ID
|
package/src/theme-config.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { createContext, useContext } from "react"
|
|
2
|
-
import type {
|
|
2
|
+
import type { ChatTheme } from "./types"
|
|
3
3
|
|
|
4
|
-
export interface
|
|
4
|
+
export interface ChatThemeConfig {
|
|
5
5
|
messageStyle: "bubble-right" | "full-width"
|
|
6
6
|
messageDensity: "relaxed" | "compact" | "dense"
|
|
7
7
|
inputStyle: "rounded" | "flat" | "bordered"
|
|
@@ -31,7 +31,10 @@ export interface AnThemeConfig {
|
|
|
31
31
|
attachmentPreviewStyle: "thumbnail" | "chip" | "hidden"
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
// Legacy type alias kept for compatibility.
|
|
35
|
+
export type AnThemeConfig = ChatThemeConfig
|
|
36
|
+
|
|
37
|
+
export const DEFAULT_THEME_CONFIG: ChatThemeConfig = {
|
|
35
38
|
messageStyle: "bubble-right",
|
|
36
39
|
messageDensity: "relaxed",
|
|
37
40
|
inputStyle: "bordered",
|
|
@@ -95,7 +98,7 @@ function readEnum<T extends string>(
|
|
|
95
98
|
return fallback
|
|
96
99
|
}
|
|
97
100
|
|
|
98
|
-
export function extractThemeConfig(theme?:
|
|
101
|
+
export function extractThemeConfig(theme?: ChatTheme): ChatThemeConfig {
|
|
99
102
|
if (!theme?.theme) return DEFAULT_THEME_CONFIG
|
|
100
103
|
const t = theme.theme
|
|
101
104
|
|
|
@@ -130,8 +133,8 @@ export function extractThemeConfig(theme?: AnTheme): AnThemeConfig {
|
|
|
130
133
|
}
|
|
131
134
|
}
|
|
132
135
|
|
|
133
|
-
export const ThemeConfigContext = createContext<
|
|
136
|
+
export const ThemeConfigContext = createContext<ChatThemeConfig>(DEFAULT_THEME_CONFIG)
|
|
134
137
|
|
|
135
|
-
export function useThemeConfig():
|
|
138
|
+
export function useThemeConfig(): ChatThemeConfig {
|
|
136
139
|
return useContext(ThemeConfigContext)
|
|
137
140
|
}
|
package/src/theme.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ChatTheme } from "./types"
|
|
2
2
|
import { contrastText } from "./utils/contrast"
|
|
3
3
|
|
|
4
4
|
export type ResolvedColorMode = "light" | "dark"
|
|
@@ -16,7 +16,7 @@ export function resolveColorMode(
|
|
|
16
16
|
/** Apply theme CSS variables from playground JSON to a DOM element */
|
|
17
17
|
export function applyTheme(
|
|
18
18
|
element: HTMLElement,
|
|
19
|
-
theme:
|
|
19
|
+
theme: ChatTheme,
|
|
20
20
|
colorMode: "light" | "dark" | "auto" = "auto",
|
|
21
21
|
) {
|
|
22
22
|
// Apply shared vars
|
package/src/tools/tool-router.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { TimelineStep, StepState } from "../types/timeline"
|
|
2
2
|
import type { ToolSize } from "../types/tool-styles"
|
|
3
|
-
import type {
|
|
3
|
+
import type { ChatThemeConfig } from "../theme-config"
|
|
4
4
|
import React from "react"
|
|
5
5
|
|
|
6
|
-
export function resolveToolSize(config:
|
|
6
|
+
export function resolveToolSize(config: ChatThemeConfig): ToolSize {
|
|
7
7
|
return config.toolCallStyle === "compact" ? "compact" : "normal"
|
|
8
8
|
}
|
|
9
9
|
|
|
@@ -16,7 +16,7 @@ function routeToolCall(
|
|
|
16
16
|
step: Extract<TimelineStep, { type: "tool-call" }>,
|
|
17
17
|
state: StepState,
|
|
18
18
|
onComplete: () => void,
|
|
19
|
-
config:
|
|
19
|
+
config: ChatThemeConfig,
|
|
20
20
|
actionIndex: number,
|
|
21
21
|
): React.ReactNode {
|
|
22
22
|
// Lazy imports to prevent circular dependency issues
|