@candor-ui/react 0.0.0-stage → 1.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.
Files changed (100) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +187 -2
  3. package/dist/adapters/ag-ui.d.ts +75 -0
  4. package/dist/adapters/ag-ui.js +441 -0
  5. package/dist/adapters/ai-sdk.d.ts +22 -0
  6. package/dist/adapters/ai-sdk.js +129 -0
  7. package/dist/adapters/claude-agent-sdk.d.ts +80 -0
  8. package/dist/adapters/claude-agent-sdk.js +265 -0
  9. package/dist/adapters/claude-agent-server.d.ts +53 -0
  10. package/dist/adapters/claude-agent-server.js +104 -0
  11. package/dist/adapters/use-ag-ui.d.ts +55 -0
  12. package/dist/adapters/use-ag-ui.js +168 -0
  13. package/dist/adapters/use-candor-chat.d.ts +40 -0
  14. package/dist/adapters/use-candor-chat.js +56 -0
  15. package/dist/adapters/use-claude-agent.d.ts +48 -0
  16. package/dist/adapters/use-claude-agent.js +143 -0
  17. package/dist/ag-ui.d.ts +2 -0
  18. package/dist/ag-ui.js +2 -0
  19. package/dist/ai-sdk.d.ts +2 -0
  20. package/dist/ai-sdk.js +2 -0
  21. package/dist/blocks/copy-field.d.ts +13 -0
  22. package/dist/blocks/copy-field.js +15 -0
  23. package/dist/blocks/degraded-panel.d.ts +19 -0
  24. package/dist/blocks/degraded-panel.js +14 -0
  25. package/dist/blocks/locked.d.ts +26 -0
  26. package/dist/blocks/locked.js +36 -0
  27. package/dist/blocks/relative-time.d.ts +13 -0
  28. package/dist/blocks/relative-time.js +62 -0
  29. package/dist/blocks/status-dot.d.ts +16 -0
  30. package/dist/blocks/status-dot.js +25 -0
  31. package/dist/blocks/step-list.d.ts +23 -0
  32. package/dist/blocks/step-list.js +37 -0
  33. package/dist/blocks/streaming-text.d.ts +17 -0
  34. package/dist/blocks/streaming-text.js +14 -0
  35. package/dist/blocks/surface.d.ts +9 -0
  36. package/dist/blocks/surface.js +35 -0
  37. package/dist/blocks/terms.d.ts +24 -0
  38. package/dist/blocks/terms.js +17 -0
  39. package/dist/chat/agent-avatar.d.ts +34 -0
  40. package/dist/chat/agent-avatar.js +42 -0
  41. package/dist/chat/card-registry.d.ts +39 -0
  42. package/dist/chat/card-registry.js +49 -0
  43. package/dist/chat/citation.d.ts +29 -0
  44. package/dist/chat/citation.js +44 -0
  45. package/dist/chat/composer.d.ts +54 -0
  46. package/dist/chat/composer.js +168 -0
  47. package/dist/chat/context-meter.d.ts +14 -0
  48. package/dist/chat/context-meter.js +30 -0
  49. package/dist/chat/entity-chip.d.ts +37 -0
  50. package/dist/chat/entity-chip.js +52 -0
  51. package/dist/chat/message-actions.d.ts +21 -0
  52. package/dist/chat/message-actions.js +20 -0
  53. package/dist/chat/message-content.d.ts +25 -0
  54. package/dist/chat/message-content.js +122 -0
  55. package/dist/chat/message.d.ts +39 -0
  56. package/dist/chat/message.js +44 -0
  57. package/dist/chat/payload.d.ts +16 -0
  58. package/dist/chat/payload.js +18 -0
  59. package/dist/chat/prompt-suggestions.d.ts +20 -0
  60. package/dist/chat/prompt-suggestions.js +18 -0
  61. package/dist/chat/reasoning.d.ts +18 -0
  62. package/dist/chat/reasoning.js +31 -0
  63. package/dist/chat/thread.d.ts +18 -0
  64. package/dist/chat/thread.js +60 -0
  65. package/dist/chat/tool-call.d.ts +19 -0
  66. package/dist/chat/tool-call.js +33 -0
  67. package/dist/claude-server.d.ts +1 -0
  68. package/dist/claude-server.js +2 -0
  69. package/dist/claude.d.ts +2 -0
  70. package/dist/claude.js +2 -0
  71. package/dist/index.d.ts +40 -0
  72. package/dist/index.js +38 -0
  73. package/dist/lib/chat.d.ts +241 -0
  74. package/dist/lib/chat.js +1 -0
  75. package/dist/lib/know.d.ts +123 -0
  76. package/dist/lib/know.js +1 -0
  77. package/dist/lib/render-prop.d.ts +16 -0
  78. package/dist/lib/render-prop.js +7 -0
  79. package/dist/lib/safe-markdown.d.ts +12 -0
  80. package/dist/lib/safe-markdown.js +98 -0
  81. package/dist/lib/status.d.ts +21 -0
  82. package/dist/lib/status.js +26 -0
  83. package/dist/lib/use-copy.d.ts +10 -0
  84. package/dist/lib/use-copy.js +24 -0
  85. package/dist/lib/use-shortcut.d.ts +15 -0
  86. package/dist/lib/use-shortcut.js +62 -0
  87. package/dist/lib/utils.d.ts +2 -0
  88. package/dist/lib/utils.js +5 -0
  89. package/dist/styles.css +460 -0
  90. package/dist/ui/button.d.ts +12 -0
  91. package/dist/ui/button.js +41 -0
  92. package/dist/ui/collapsible.d.ts +6 -0
  93. package/dist/ui/collapsible.js +15 -0
  94. package/dist/ui/popover.d.ts +11 -0
  95. package/dist/ui/popover.js +29 -0
  96. package/dist/ui/skeleton.d.ts +2 -0
  97. package/dist/ui/skeleton.js +6 -0
  98. package/dist/ui/tooltip.d.ts +9 -0
  99. package/dist/ui/tooltip.js +24 -0
  100. package/package.json +90 -4
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Methodic LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ This licence covers only the free-tier items listed in scripts/tiers.json. See
24
+ LICENSE.md.
package/README.md CHANGED
@@ -1,3 +1,188 @@
1
- # Temporary Holding Version
1
+ # @candor-ui/react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Candor UI's free tier as an npm package: React components and hooks for agent chat (thread, messages, tool calls,
4
+ reasoning, composer, citations), the building blocks they use, the theme, and adapters for the Vercel AI SDK, the
5
+ Claude Agent SDK and AG-UI. MIT licensed. By [Methodic LLC](https://themethodic.com).
6
+
7
+ It's the same code as the free `@candor/*` items in the shadcn registry, for people who'd rather `npm install` than
8
+ copy code into their app. If you want to own and edit the source, install with the shadcn CLI instead
9
+ (`npx shadcn@latest add @candor/thread ...`); see https://candor.themethodic.com.
10
+
11
+ > **Pro and Premium items aren't on npm.** This package contains only the free (MIT) tier. Pro components and Premium
12
+ > blocks and templates install through the licensed shadcn registry (`@candor` with your licence key), not npm.
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm install @candor-ui/react
18
+ ```
19
+
20
+ Needs React 19 and Tailwind CSS 4. Radix, lucide-react, class-variance-authority, clsx, tailwind-merge, the Inter font
21
+ and tw-animate-css come with it.
22
+
23
+ ## Styles (Tailwind 4)
24
+
25
+ The components are styled with Tailwind classes and Candor's tokens. Import the theme after Tailwind in your global CSS:
26
+
27
+ ```css
28
+ @import "tailwindcss";
29
+ @import "@candor-ui/react/styles.css";
30
+ ```
31
+
32
+ `styles.css` brings Candor's tokens (colours, type scale, radii, shadows, motion), the light, dark and high-contrast
33
+ themes, Inter, tw-animate-css and an `@source` for the package's own files, so Tailwind generates the classes the
34
+ components use even though it skips `node_modules` when scanning your app. If your setup doesn't follow `@source`
35
+ from imported CSS, add it yourself, relative to your CSS file:
36
+
37
+ ```css
38
+ @source "../node_modules/@candor-ui/react/dist";
39
+ ```
40
+
41
+ Themes switch with `data-theme="light" | "dark" | "hc"` on `<html>`; with no attribute they follow the system. To
42
+ restyle, override the roles after the import: colours by their shadcn names (`--primary`, `--background`...),
43
+ everything else by its `--cd-*` name.
44
+
45
+ If your CSS already defines shadcn's variables (e.g. `create-next-app`'s or `shadcn init`'s `globals.css`), remove
46
+ those `:root`, `.dark` and `@theme inline` blocks or put them before the import, and don't redefine `--font-sans`
47
+ after it.
48
+
49
+ ## Components
50
+
51
+ ```tsx
52
+ "use client"
53
+ import * as React from "react"
54
+ import { Thread, Message, Composer, type MessageData } from "@candor-ui/react"
55
+
56
+ const messages: MessageData[] = [
57
+ { id: "1", author: { role: "user" }, status: "complete", blocks: [{ kind: "paragraph", nodes: [{ kind: "text", text: "Hi" }] }] },
58
+ ]
59
+
60
+ export function Chat() {
61
+ const [value, setValue] = React.useState("")
62
+ return (
63
+ <Thread footer={<Composer value={value} onChange={setValue} onSubmit={() => setValue("")} />}>
64
+ {messages.map((m) => <Message key={m.id} message={m} />)}
65
+ </Thread>
66
+ )
67
+ }
68
+ ```
69
+
70
+ The main entry exports every free component, hook and type, plus `cn`. Two names are shared by a component and a data
71
+ type; the component keeps the name and the type gets a `Data` suffix: `Message` / `MessageData`, `ToolCall` /
72
+ `ToolCallData`.
73
+
74
+ Client components carry `"use client"`, so they work from Server Components in the Next.js App Router. Hooks
75
+ (`useCopy`, `useCandorChat`...) are for client components, as usual.
76
+
77
+ ## With the Vercel AI SDK: `@candor-ui/react/ai-sdk`
78
+
79
+ ```bash
80
+ npm install ai @ai-sdk/react
81
+ ```
82
+
83
+ ```tsx
84
+ "use client"
85
+ import { useChat } from "@ai-sdk/react"
86
+ import { Thread, Message, Composer } from "@candor-ui/react"
87
+ import { useCandorChat } from "@candor-ui/react/ai-sdk"
88
+
89
+ export function Chat() {
90
+ const chat = useChat()
91
+ const { messages, composer, approvals, respond } = useCandorChat(chat, { agent: { id: "a", name: "Assistant", role: "assistant" } })
92
+ return (
93
+ <Thread footer={<Composer {...composer} />}>
94
+ {messages.map((m) => <Message key={m.id} message={m} />)}
95
+ </Thread>
96
+ )
97
+ }
98
+ ```
99
+
100
+ Also exports `fromAiSdkMessages` / `fromAiSdkMessage` to map `UIMessage`s yourself.
101
+
102
+ ## With the Claude Agent SDK: `@candor-ui/react/claude` and `@candor-ui/react/claude/server`
103
+
104
+ ```bash
105
+ npm install @anthropic-ai/claude-agent-sdk
106
+ ```
107
+
108
+ The agent runs on your server. `@candor-ui/react/claude/server` is **server only** (it needs Node and your
109
+ credentials); the main entry and the client subpaths never import it.
110
+
111
+ ```ts
112
+ // app/api/agent/route.ts
113
+ import { query } from "@anthropic-ai/claude-agent-sdk"
114
+ import { streamClaudeAgent } from "@candor-ui/react/claude/server"
115
+
116
+ export async function POST(request: Request) {
117
+ const { prompt, sessionId } = await request.json()
118
+ return streamClaudeAgent(
119
+ ({ canUseTool, abortController }) =>
120
+ query({ prompt, options: { canUseTool, abortController, resume: sessionId, includePartialMessages: true } }),
121
+ { signal: request.signal, owner: userId },
122
+ )
123
+ }
124
+
125
+ // app/api/agent/approve/route.ts
126
+ import { answerClaudeAgentApproval } from "@candor-ui/react/claude/server"
127
+
128
+ export async function POST(request: Request) {
129
+ const { id, approved, reason } = await request.json()
130
+ return Response.json({ ok: answerClaudeAgentApproval(id, approved, reason, userId) })
131
+ }
132
+ ```
133
+
134
+ ```tsx
135
+ "use client"
136
+ import { useClaudeAgent } from "@candor-ui/react/claude"
137
+
138
+ const { messages, composer, approvals, respond, usage } = useClaudeAgent({ api: "/api/agent", approveApi: "/api/agent/approve", agent })
139
+ ```
140
+
141
+ `@candor-ui/react/claude` also exports `fromClaudeAgentEvents` and the event types. Waiting permission requests live
142
+ in the server process's memory: run the agent on one Node server or container, not serverless functions spread over
143
+ instances.
144
+
145
+ ## With AG-UI: `@candor-ui/react/ag-ui`
146
+
147
+ ```bash
148
+ npm install @ag-ui/client @ag-ui/core
149
+ ```
150
+
151
+ ```tsx
152
+ "use client"
153
+ import { useAgUi } from "@candor-ui/react/ag-ui"
154
+
155
+ const { messages, composer, approvals, respond } = useAgUi({ url: "/api/agent", agent })
156
+ ```
157
+
158
+ Also exports `fromAgUiEvents` and the event types.
159
+
160
+ ## Entry points
161
+
162
+ | Import | Contents | Needs |
163
+ | --- | --- | --- |
164
+ | `@candor-ui/react` | components, hooks, types, `cn` | react, react-dom |
165
+ | `@candor-ui/react/ai-sdk` | `useCandorChat`, `fromAiSdkMessages` | `ai`, `@ai-sdk/react` |
166
+ | `@candor-ui/react/claude` | `useClaudeAgent`, `fromClaudeAgentEvents` | `@anthropic-ai/claude-agent-sdk` (types) |
167
+ | `@candor-ui/react/claude/server` | `streamClaudeAgent`, `answerClaudeAgentApproval` (server only) | `@anthropic-ai/claude-agent-sdk` |
168
+ | `@candor-ui/react/ag-ui` | `useAgUi`, `fromAgUiEvents` | `@ag-ui/client`, `@ag-ui/core` |
169
+ | `@candor-ui/react/styles.css` | theme and tokens for Tailwind 4 | tailwindcss 4 |
170
+
171
+ The SDKs are optional peer dependencies: install only the ones for the subpaths you use.
172
+
173
+ ## Building this package
174
+
175
+ The contents are generated from the repo at build time, so they can't drift from the registry: the item list is
176
+ `free` in `scripts/tiers.json`, each item's file comes from `registry.json`, and the build fails if a free item imports
177
+ a non-free one.
178
+
179
+ ```bash
180
+ cd packages/react
181
+ npm install --no-package-lock
182
+ npm run build # dist/
183
+ npm pack # runs the build first
184
+ ```
185
+
186
+ ## Licence
187
+
188
+ MIT, (c) 2026 Methodic LLC. See [LICENSE](LICENSE).
@@ -0,0 +1,75 @@
1
+ import { type Event } from "@ag-ui/core";
2
+ import type { AgentIdentity, EntityRef, Message } from "../lib/chat.js";
3
+ /** Events of Candor's own, mixed into the AG-UI stream by useAgUi. */
4
+ export type CandorAgUiEvent =
5
+ /** What the user sent. Added in the browser, with the same id as the AG-UI user message. */
6
+ {
7
+ type: "candor_user";
8
+ id: string;
9
+ text: string;
10
+ references?: EntityRef[];
11
+ }
12
+ /** A person answered an interrupt; the next run resumes with it. */
13
+ | {
14
+ type: "candor_answer";
15
+ interruptId: string;
16
+ approved: boolean;
17
+ reason?: string;
18
+ }
19
+ /** The run failed outside the protocol's own events (the request, the stream). */
20
+ | {
21
+ type: "candor_error";
22
+ message: string;
23
+ };
24
+ export type AgUiEvent = Event | CandorAgUiEvent;
25
+ /** An interrupt waiting on a person. */
26
+ export type AgUiApproval = {
27
+ /** The interrupt's id; answer it with `respond(id, …)`. */
28
+ id: string;
29
+ /** The agent's machine-readable reason, e.g. "tool_approval". */
30
+ reason: string;
31
+ /** The agent's own sentence for the request, when it sent one. */
32
+ message?: string;
33
+ /** A sentence to show: the agent's message, or a plain one naming the tool. */
34
+ title: string;
35
+ /** Set when the interrupt asks to run a tool call. */
36
+ toolCallId?: string;
37
+ /** The tool's name, when the tool call is in the thread. */
38
+ tool?: string;
39
+ /** The tool call's arguments, when they arrived and parse. */
40
+ input?: unknown;
41
+ /** When the agent stops waiting (ISO 8601). */
42
+ expiresAt?: string;
43
+ /** The shape the agent expects an answer in, when it says. */
44
+ responseSchema?: Record<string, unknown>;
45
+ };
46
+ /** Tokens the runs reported, summed. A count no run reported stays unknown. AG-UI reports no cost. */
47
+ export type AgUiUsage = {
48
+ inputTokens?: number;
49
+ outputTokens?: number;
50
+ };
51
+ export type FromAgUiOptions = {
52
+ /** Who the agent is. Candor always names the agent. */
53
+ agent: AgentIdentity;
54
+ /** A run is open now: the last reply is still streaming, and no interrupt can be answered yet. */
55
+ running?: boolean;
56
+ /** A plain-words title for a tool call: "Read notes.md". `input` is undefined until the arguments arrive. */
57
+ toolTitle?: (tool: string, input: unknown) => string | undefined;
58
+ /** The time to judge interrupt expiry by. Defaults to now. */
59
+ now?: Date;
60
+ };
61
+ export type AgUiState = {
62
+ messages: Message[];
63
+ /** Interrupts waiting on a person, oldest first. Empty while a run is open; expired ones are left out. */
64
+ approvals: AgUiApproval[];
65
+ /** The thread the runs belong to. Send it back to continue the conversation. */
66
+ threadId?: string;
67
+ usage?: AgUiUsage;
68
+ /** Something the person should know that isn't part of a reply, such as an expired request. */
69
+ notice?: string;
70
+ };
71
+ /**
72
+ * Turns AG-UI events into Candor messages, waiting approvals and usage.
73
+ * Pure (given `now`), so it can run on every render; useAgUi calls it for you.
74
+ */
75
+ export declare function fromAgUiEvents(events: AgUiEvent[], options: FromAgUiOptions): AgUiState;