@agentskit/react 0.4.0 → 0.4.2

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 ADDED
@@ -0,0 +1,53 @@
1
+ # @agentskit/react
2
+
3
+ Add streaming AI chat to any React app in 10 lines of code.
4
+
5
+ ## Why
6
+
7
+ - **Ship faster** — streaming chat with tool calls, memory, and markdown rendering works out of the box, no wiring required
8
+ - **Works with your design system** — completely headless; style it with Tailwind, MUI, shadcn, or plain CSS via `data-ak-*` attributes
9
+ - **Agent-ready by default** — built-in support for tool calls, thinking indicators, and multi-turn memory so you never hit a wall as your product grows
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @agentskit/react @agentskit/adapters
15
+ ```
16
+
17
+ ## Quick example
18
+
19
+ ```tsx
20
+ import { useChat, ChatContainer, Message, InputBar } from '@agentskit/react'
21
+ import { anthropic } from '@agentskit/adapters'
22
+ import '@agentskit/react/theme'
23
+
24
+ function Chat() {
25
+ const chat = useChat({
26
+ adapter: anthropic({ apiKey: process.env.ANTHROPIC_API_KEY, model: 'claude-sonnet-4-6' }),
27
+ })
28
+ return (
29
+ <ChatContainer>
30
+ {chat.messages.map(msg => <Message key={msg.id} message={msg} />)}
31
+ <InputBar chat={chat} />
32
+ </ChatContainer>
33
+ )
34
+ }
35
+ ```
36
+
37
+ ## Next steps
38
+
39
+ - Add **tools** and **memory** via `useChat` options (same contracts as [`@agentskit/core`](https://www.npmjs.com/package/@agentskit/core))
40
+ - For **terminal** apps with the same hook names, use [`@agentskit/ink`](https://www.npmjs.com/package/@agentskit/ink); for **CLI** prototyping without embedding React, try [`@agentskit/cli`](https://www.npmjs.com/package/@agentskit/cli) `agentskit chat`
41
+
42
+ ## Ecosystem
43
+
44
+ | Package | Role |
45
+ |---------|------|
46
+ | [@agentskit/core](https://www.npmjs.com/package/@agentskit/core) | Chat controller types, events |
47
+ | [@agentskit/adapters](https://www.npmjs.com/package/@agentskit/adapters) | `anthropic`, `openai`, `ollama`, … |
48
+ | [@agentskit/runtime](https://www.npmjs.com/package/@agentskit/runtime) | Same stack without a browser |
49
+ | [@agentskit/tools](https://www.npmjs.com/package/@agentskit/tools) | Tool definitions for `useChat` |
50
+
51
+ ## Docs
52
+
53
+ [Full documentation](https://emersonbraun.github.io/agentskit/)
package/dist/index.cjs CHANGED
@@ -124,7 +124,9 @@ function useChat(config) {
124
124
  stop: controllerRef.current.stop,
125
125
  retry: controllerRef.current.retry,
126
126
  setInput: controllerRef.current.setInput,
127
- clear: controllerRef.current.clear
127
+ clear: controllerRef.current.clear,
128
+ approve: controllerRef.current.approve,
129
+ deny: controllerRef.current.deny
128
130
  };
129
131
  }
130
132
  function ChatContainer({ children, className }) {
@@ -238,6 +240,34 @@ function ThinkingIndicator({ visible, label = "Thinking..." }) {
238
240
  /* @__PURE__ */ jsxRuntime.jsx("span", { "data-ak-thinking-label": "", children: label })
239
241
  ] });
240
242
  }
243
+ function ToolConfirmation({ toolCall, onApprove, onDeny }) {
244
+ if (toolCall.status !== "requires_confirmation") return null;
245
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-ak-tool-confirmation": true, "data-ak-tool-name": toolCall.name, children: [
246
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-ak-tool-confirmation-header": true, children: [
247
+ /* @__PURE__ */ jsxRuntime.jsx("span", { "data-ak-tool-confirmation-name": true, children: toolCall.name }),
248
+ /* @__PURE__ */ jsxRuntime.jsx("span", { "data-ak-tool-confirmation-status": true, children: "requires confirmation" })
249
+ ] }),
250
+ /* @__PURE__ */ jsxRuntime.jsx("div", { "data-ak-tool-confirmation-args": true, children: JSON.stringify(toolCall.args, null, 2) }),
251
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-ak-tool-confirmation-actions": true, children: [
252
+ /* @__PURE__ */ jsxRuntime.jsx(
253
+ "button",
254
+ {
255
+ "data-ak-tool-confirmation-approve": true,
256
+ onClick: () => onApprove(toolCall.id),
257
+ children: "Approve"
258
+ }
259
+ ),
260
+ /* @__PURE__ */ jsxRuntime.jsx(
261
+ "button",
262
+ {
263
+ "data-ak-tool-confirmation-deny": true,
264
+ onClick: () => onDeny(toolCall.id),
265
+ children: "Deny"
266
+ }
267
+ )
268
+ ] })
269
+ ] });
270
+ }
241
271
 
242
272
  Object.defineProperty(exports, "createChatController", {
243
273
  enumerable: true,
@@ -270,6 +300,7 @@ exports.Markdown = Markdown;
270
300
  exports.Message = Message;
271
301
  exports.ThinkingIndicator = ThinkingIndicator;
272
302
  exports.ToolCallView = ToolCallView;
303
+ exports.ToolConfirmation = ToolConfirmation;
273
304
  exports.useChat = useChat;
274
305
  exports.useReactive = useReactive;
275
306
  exports.useStream = useStream;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/useStream.ts","../src/useReactive.ts","../src/useChat.ts","../src/components/ChatContainer.tsx","../src/components/Message.tsx","../src/components/InputBar.tsx","../src/components/Markdown.tsx","../src/components/CodeBlock.tsx","../src/components/ToolCallView.tsx","../src/components/ThinkingIndicator.tsx"],"names":["useState","useRef","useEffect","error","useCallback","store","useSyncExternalStore","createChatController","jsx","jsxs"],"mappings":";;;;;;;AAGO,SAAS,SAAA,CACd,QACA,OAAA,EACiB;AACjB,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAIA,eAA6B,IAAI,CAAA;AACzD,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAIA,eAAS,EAAE,CAAA;AACnC,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAIA,eAAuB,MAAM,CAAA;AACzD,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAIA,eAAuB,IAAI,CAAA;AACrD,EAAA,MAAM,SAAA,GAAYC,aAAO,MAAM,CAAA;AAC/B,EAAA,MAAM,UAAA,GAAaA,aAAO,OAAO,CAAA;AACjC,EAAA,MAAM,UAAA,GAAaA,aAAO,KAAK,CAAA;AAE/B,EAAA,SAAA,CAA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cAAAA,CAAC,KAAA,EAAA,EAAI,mBAAA,EAAkB,EAAA,EACpB,QAAA,EAAA,IAAA,CAAK,UAAU,QAAA,CAAS,IAAA,EAAM,IAAA,EAAM,CAAC,CAAA,EACxC,CAAA;AAAA,MACC,QAAA,CAAS,0BACRA,cAAAA,CAAC,SAAI,qBAAA,EAAoB,EAAA,EAAI,mBAAS,MAAA,EAAO;AAAA,KAAA,EAEjD;AAAA,GAAA,EAEJ,CAAA;AAEJ;ACxBO,SAAS,iBAAA,CAAkB,EAAE,OAAA,EAAS,KAAA,GAAQ,eAAc,EAA2B;AAC5F,EAAA,IAAI,CAAC,SAAS,OAAO,IAAA;AAErB,EAAA,uBACEC,eAAAA,CAAC,KAAA,EAAA,EAAI,kBAAA,EAAiB,EAAA,EAAG,eAAY,aAAA,EACnC,QAAA,EAAA;AAAA,oBAAAA,eAAAA,CAAC,MAAA,EAAA,EAAK,uBAAA,EAAsB,EAAA,EAC1B,QAAA,EAAA;AAAA,sBAAAD,cAAAA,CAAC,UAAK,QAAA,EAAA,QAAA,EAAM,CAAA;AAAA,sBAAOA,cAAAA,CAAC,MAAA,EAAA,EAAK,QAAA,EAAA,QAAA,EAAM,CAAA;AAAA,sBAAOA,cAAAA,CAAC,MAAA,EAAA,EAAK,QAAA,EAAA,QAAA,EAAM;AAAA,KAAA,EACpD,CAAA;AAAA,oBACAA,cAAAA,CAAC,MAAA,EAAA,EAAK,wBAAA,EAAuB,IAAI,QAAA,EAAA,KAAA,EAAM;AAAA,GAAA,EACzC,CAAA;AAEJ","file":"index.cjs","sourcesContent":["import { useState, useEffect, useRef, useCallback } from 'react'\nimport type { StreamSource, StreamChunk, StreamStatus, UseStreamOptions, UseStreamReturn } from '@agentskit/core'\n\nexport function useStream(\n source: StreamSource,\n options?: UseStreamOptions\n): UseStreamReturn {\n const [data, setData] = useState<StreamChunk | null>(null)\n const [text, setText] = useState('')\n const [status, setStatus] = useState<StreamStatus>('idle')\n const [error, setError] = useState<Error | null>(null)\n const sourceRef = useRef(source)\n const optionsRef = useRef(options)\n const abortedRef = useRef(false)\n\n sourceRef.current = source\n optionsRef.current = options\n\n useEffect(() => {\n let cancelled = false\n abortedRef.current = false\n setStatus('streaming')\n setText('')\n setData(null)\n setError(null)\n\n let accumulated = ''\n\n const consume = async () => {\n try {\n const iterator = sourceRef.current.stream()\n for await (const chunk of iterator) {\n if (cancelled || abortedRef.current) return\n\n setData(chunk)\n optionsRef.current?.onChunk?.(chunk)\n\n if (chunk.type === 'text' && chunk.content) {\n accumulated += chunk.content\n setText(accumulated)\n } else if (chunk.type === 'error') {\n const err = new Error(chunk.content ?? 'Stream error')\n setError(err)\n setStatus('error')\n optionsRef.current?.onError?.(err)\n return\n } else if (chunk.type === 'done') {\n setStatus('complete')\n optionsRef.current?.onComplete?.(accumulated)\n return\n }\n }\n\n if (!cancelled && !abortedRef.current) {\n setStatus('complete')\n optionsRef.current?.onComplete?.(accumulated)\n }\n } catch (err) {\n if (!cancelled && !abortedRef.current) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n setStatus('error')\n optionsRef.current?.onError?.(error)\n }\n }\n }\n\n consume()\n\n return () => {\n cancelled = true\n }\n }, [source])\n\n const stop = useCallback(() => {\n abortedRef.current = true\n sourceRef.current.abort()\n }, [])\n\n return { data, text, status, error, stop }\n}\n","import { useRef, useSyncExternalStore, useCallback } from 'react'\n\nexport function useReactive<T extends Record<string, unknown>>(initialState: T): T {\n const storeRef = useRef<{\n state: T\n listeners: Set<() => void>\n proxy: T\n version: number\n } | null>(null)\n\n if (storeRef.current === null) {\n const store = {\n state: { ...initialState },\n listeners: new Set<() => void>(),\n proxy: null as unknown as T,\n version: 0,\n }\n\n const notify = () => {\n store.version++\n store.listeners.forEach(listener => listener())\n }\n\n store.proxy = new Proxy(store.state, {\n get(target, prop, receiver) {\n return Reflect.get(target, prop, receiver)\n },\n set(target, prop, value, receiver) {\n const result = Reflect.set(target, prop, value, receiver)\n notify()\n return result\n },\n }) as T\n\n storeRef.current = store\n }\n\n const store = storeRef.current\n\n const subscribe = useCallback((callback: () => void) => {\n store.listeners.add(callback)\n return () => { store.listeners.delete(callback) }\n }, [store])\n\n const getSnapshot = useCallback(() => store.version, [store])\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot)\n\n return store.proxy\n}\n","// NOTE: This hook is identical in @agentskit/react and @agentskit/ink.\n// Changes here must be mirrored in packages/ink/src/useChat.ts.\nimport { useEffect, useRef, useSyncExternalStore } from 'react'\nimport { createChatController } from '@agentskit/core'\nimport type { ChatConfig, ChatController, ChatReturn } from '@agentskit/core'\n\nexport function useChat(config: ChatConfig): ChatReturn {\n const controllerRef = useRef<ChatController | null>(null)\n\n if (!controllerRef.current) {\n controllerRef.current = createChatController(config)\n }\n\n useEffect(() => {\n controllerRef.current?.updateConfig(config)\n }, [config])\n\n const state = useSyncExternalStore(\n controllerRef.current.subscribe,\n controllerRef.current.getState,\n controllerRef.current.getState\n )\n\n return {\n ...state,\n send: controllerRef.current.send,\n stop: controllerRef.current.stop,\n retry: controllerRef.current.retry,\n setInput: controllerRef.current.setInput,\n clear: controllerRef.current.clear,\n }\n}\n","import React, { useRef, useEffect, type ReactNode } from 'react'\n\nexport interface ChatContainerProps {\n children: ReactNode\n className?: string\n}\n\nexport function ChatContainer({ children, className }: ChatContainerProps) {\n const containerRef = useRef<HTMLDivElement>(null)\n\n useEffect(() => {\n const el = containerRef.current\n if (!el) return\n\n const observer = new MutationObserver(() => {\n el.scrollTop = el.scrollHeight\n })\n\n observer.observe(el, { childList: true, subtree: true, characterData: true })\n return () => observer.disconnect()\n }, [])\n\n return (\n <div\n ref={containerRef}\n data-ak-chat-container=\"\"\n data-testid=\"ak-chat-container\"\n className={className}\n style={{ overflow: 'auto' }}\n >\n {children}\n </div>\n )\n}\n","import React, { type ReactNode } from 'react'\nimport type { Message as MessageType } from '@agentskit/core'\n\nexport interface MessageProps {\n message: MessageType\n avatar?: ReactNode\n actions?: ReactNode\n}\n\nexport function Message({ message, avatar, actions }: MessageProps) {\n return (\n <div\n data-ak-message=\"\"\n data-ak-role={message.role}\n data-ak-status={message.status}\n >\n {avatar && <div data-ak-avatar=\"\">{avatar}</div>}\n <div data-ak-content=\"\">{message.content}</div>\n {actions && <div data-ak-actions=\"\">{actions}</div>}\n </div>\n )\n}\n","import React, { type FormEvent, type KeyboardEvent } from 'react'\nimport type { ChatReturn } from '@agentskit/core'\n\nexport interface InputBarProps {\n chat: ChatReturn\n placeholder?: string\n disabled?: boolean\n}\n\nexport function InputBar({ chat, placeholder = 'Type a message...', disabled = false }: InputBarProps) {\n const handleSubmit = (e: FormEvent) => {\n e.preventDefault()\n if (chat.input.trim()) {\n chat.send(chat.input)\n }\n }\n\n const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault()\n if (chat.input.trim()) {\n chat.send(chat.input)\n }\n }\n }\n\n return (\n <form data-ak-input-bar=\"\" onSubmit={handleSubmit}>\n <textarea\n role=\"textbox\"\n value={chat.input}\n onChange={(e) => chat.setInput(e.target.value)}\n onKeyDown={handleKeyDown}\n placeholder={placeholder}\n disabled={disabled}\n data-ak-input=\"\"\n rows={1}\n />\n <button type=\"submit\" disabled={disabled || !chat.input.trim()} data-ak-send=\"\">\n Send\n </button>\n </form>\n )\n}\n","import React from 'react'\n\nexport interface MarkdownProps {\n content: string\n streaming?: boolean\n}\n\nexport function Markdown({ content, streaming = false }: MarkdownProps) {\n return (\n <div data-ak-markdown=\"\" data-ak-streaming={streaming ? 'true' : undefined}>\n {content}\n </div>\n )\n}\n","import React, { useCallback } from 'react'\n\nexport interface CodeBlockProps {\n code: string\n language?: string\n copyable?: boolean\n}\n\nexport function CodeBlock({ code, language, copyable = false }: CodeBlockProps) {\n const handleCopy = useCallback(() => {\n navigator.clipboard.writeText(code)\n }, [code])\n\n return (\n <div data-ak-code-block=\"\" data-ak-language={language}>\n <pre>\n <code>{code}</code>\n </pre>\n {copyable && (\n <button onClick={handleCopy} data-ak-copy=\"\" type=\"button\">\n Copy\n </button>\n )}\n </div>\n )\n}\n","import React, { useState } from 'react'\nimport type { ToolCall } from '@agentskit/core'\n\nexport interface ToolCallViewProps {\n toolCall: ToolCall\n}\n\nexport function ToolCallView({ toolCall }: ToolCallViewProps) {\n const [expanded, setExpanded] = useState(false)\n\n return (\n <div data-ak-tool-call=\"\" data-ak-tool-status={toolCall.status}>\n <button\n onClick={() => setExpanded(!expanded)}\n data-ak-tool-toggle=\"\"\n type=\"button\"\n >\n {toolCall.name}\n </button>\n {expanded && (\n <div data-ak-tool-details=\"\">\n <pre data-ak-tool-args=\"\">\n {JSON.stringify(toolCall.args, null, 2)}\n </pre>\n {toolCall.result && (\n <div data-ak-tool-result=\"\">{toolCall.result}</div>\n )}\n </div>\n )}\n </div>\n )\n}\n","import React from 'react'\n\nexport interface ThinkingIndicatorProps {\n visible: boolean\n label?: string\n}\n\nexport function ThinkingIndicator({ visible, label = 'Thinking...' }: ThinkingIndicatorProps) {\n if (!visible) return null\n\n return (\n <div data-ak-thinking=\"\" data-testid=\"ak-thinking\">\n <span data-ak-thinking-dots=\"\">\n <span>&bull;</span><span>&bull;</span><span>&bull;</span>\n </span>\n <span data-ak-thinking-label=\"\">{label}</span>\n </div>\n )\n}\n"]}
1
+ {"version":3,"sources":["../src/useStream.ts","../src/useReactive.ts","../src/useChat.ts","../src/components/ChatContainer.tsx","../src/components/Message.tsx","../src/components/InputBar.tsx","../src/components/Markdown.tsx","../src/components/CodeBlock.tsx","../src/components/ToolCallView.tsx","../src/components/ThinkingIndicator.tsx","../src/components/ToolConfirmation.tsx"],"names":["useState","useRef","useEffect","error","useCallback","store","useSyncExternalStore","createChatController","jsx","jsxs"],"mappings":";;;;;;;AAGO,SAAS,SAAA,CACd,QACA,OAAA,EACiB;AACjB,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAIA,eAA6B,IAAI,CAAA;AACzD,EAAA,MAAM,CAAC,IAAA,EAAM,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AAA,UACC,gCAAA,EAA8B,IAAA;AAAA,UAC9B,OAAA,EAAS,MAAM,MAAA,CAAO,QAAA,CAAS,EAAE,CAAA;AAAA,UAClC,QAAA,EAAA;AAAA;AAAA;AAED,KAAA,EACF;AAAA,GAAA,EACF,CAAA;AAEJ","file":"index.cjs","sourcesContent":["import { useState, useEffect, useRef, useCallback } from 'react'\nimport type { StreamSource, StreamChunk, StreamStatus, UseStreamOptions, UseStreamReturn } from '@agentskit/core'\n\nexport function useStream(\n source: StreamSource,\n options?: UseStreamOptions\n): UseStreamReturn {\n const [data, setData] = useState<StreamChunk | null>(null)\n const [text, setText] = useState('')\n const [status, setStatus] = useState<StreamStatus>('idle')\n const [error, setError] = useState<Error | null>(null)\n const sourceRef = useRef(source)\n const optionsRef = useRef(options)\n const abortedRef = useRef(false)\n\n sourceRef.current = source\n optionsRef.current = options\n\n useEffect(() => {\n let cancelled = false\n abortedRef.current = false\n setStatus('streaming')\n setText('')\n setData(null)\n setError(null)\n\n let accumulated = ''\n\n const consume = async () => {\n try {\n const iterator = sourceRef.current.stream()\n for await (const chunk of iterator) {\n if (cancelled || abortedRef.current) return\n\n setData(chunk)\n optionsRef.current?.onChunk?.(chunk)\n\n if (chunk.type === 'text' && chunk.content) {\n accumulated += chunk.content\n setText(accumulated)\n } else if (chunk.type === 'error') {\n const err = new Error(chunk.content ?? 'Stream error')\n setError(err)\n setStatus('error')\n optionsRef.current?.onError?.(err)\n return\n } else if (chunk.type === 'done') {\n setStatus('complete')\n optionsRef.current?.onComplete?.(accumulated)\n return\n }\n }\n\n if (!cancelled && !abortedRef.current) {\n setStatus('complete')\n optionsRef.current?.onComplete?.(accumulated)\n }\n } catch (err) {\n if (!cancelled && !abortedRef.current) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n setStatus('error')\n optionsRef.current?.onError?.(error)\n }\n }\n }\n\n consume()\n\n return () => {\n cancelled = true\n }\n }, [source])\n\n const stop = useCallback(() => {\n abortedRef.current = true\n sourceRef.current.abort()\n }, [])\n\n return { data, text, status, error, stop }\n}\n","import { useRef, useSyncExternalStore, useCallback } from 'react'\n\nexport function useReactive<T extends Record<string, unknown>>(initialState: T): T {\n const storeRef = useRef<{\n state: T\n listeners: Set<() => void>\n proxy: T\n version: number\n } | null>(null)\n\n if (storeRef.current === null) {\n const store = {\n state: { ...initialState },\n listeners: new Set<() => void>(),\n proxy: null as unknown as T,\n version: 0,\n }\n\n const notify = () => {\n store.version++\n store.listeners.forEach(listener => listener())\n }\n\n store.proxy = new Proxy(store.state, {\n get(target, prop, receiver) {\n return Reflect.get(target, prop, receiver)\n },\n set(target, prop, value, receiver) {\n const result = Reflect.set(target, prop, value, receiver)\n notify()\n return result\n },\n }) as T\n\n storeRef.current = store\n }\n\n const store = storeRef.current\n\n const subscribe = useCallback((callback: () => void) => {\n store.listeners.add(callback)\n return () => { store.listeners.delete(callback) }\n }, [store])\n\n const getSnapshot = useCallback(() => store.version, [store])\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot)\n\n return store.proxy\n}\n","// NOTE: This hook is intentionally duplicated in @agentskit/ink (packages/ink/src/useChat.ts).\n// The two packages are React siblings and cannot cross-depend, so the hook is kept in sync\n// manually. A sync-guard test at packages/ink/tests/useChat-sync.test.ts will fail if they drift.\n// When changing this file, mirror the same change in packages/ink/src/useChat.ts.\nimport { useEffect, useRef, useSyncExternalStore } from 'react'\nimport { createChatController } from '@agentskit/core'\nimport type { ChatConfig, ChatController, ChatReturn } from '@agentskit/core'\n\nexport function useChat(config: ChatConfig): ChatReturn {\n const controllerRef = useRef<ChatController | null>(null)\n\n if (!controllerRef.current) {\n controllerRef.current = createChatController(config)\n }\n\n useEffect(() => {\n controllerRef.current?.updateConfig(config)\n }, [config])\n\n const state = useSyncExternalStore(\n controllerRef.current.subscribe,\n controllerRef.current.getState,\n controllerRef.current.getState\n )\n\n return {\n ...state,\n send: controllerRef.current.send,\n stop: controllerRef.current.stop,\n retry: controllerRef.current.retry,\n setInput: controllerRef.current.setInput,\n clear: controllerRef.current.clear,\n approve: controllerRef.current.approve,\n deny: controllerRef.current.deny,\n }\n}\n","import React, { useRef, useEffect, type ReactNode } from 'react'\n\nexport interface ChatContainerProps {\n children: ReactNode\n className?: string\n}\n\nexport function ChatContainer({ children, className }: ChatContainerProps) {\n const containerRef = useRef<HTMLDivElement>(null)\n\n useEffect(() => {\n const el = containerRef.current\n if (!el) return\n\n const observer = new MutationObserver(() => {\n el.scrollTop = el.scrollHeight\n })\n\n observer.observe(el, { childList: true, subtree: true, characterData: true })\n return () => observer.disconnect()\n }, [])\n\n return (\n <div\n ref={containerRef}\n data-ak-chat-container=\"\"\n data-testid=\"ak-chat-container\"\n className={className}\n style={{ overflow: 'auto' }}\n >\n {children}\n </div>\n )\n}\n","import React, { type ReactNode } from 'react'\nimport type { Message as MessageType } from '@agentskit/core'\n\nexport interface MessageProps {\n message: MessageType\n avatar?: ReactNode\n actions?: ReactNode\n}\n\nexport function Message({ message, avatar, actions }: MessageProps) {\n return (\n <div\n data-ak-message=\"\"\n data-ak-role={message.role}\n data-ak-status={message.status}\n >\n {avatar && <div data-ak-avatar=\"\">{avatar}</div>}\n <div data-ak-content=\"\">{message.content}</div>\n {actions && <div data-ak-actions=\"\">{actions}</div>}\n </div>\n )\n}\n","import React, { type FormEvent, type KeyboardEvent } from 'react'\nimport type { ChatReturn } from '@agentskit/core'\n\nexport interface InputBarProps {\n chat: ChatReturn\n placeholder?: string\n disabled?: boolean\n}\n\nexport function InputBar({ chat, placeholder = 'Type a message...', disabled = false }: InputBarProps) {\n const handleSubmit = (e: FormEvent) => {\n e.preventDefault()\n if (chat.input.trim()) {\n chat.send(chat.input)\n }\n }\n\n const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault()\n if (chat.input.trim()) {\n chat.send(chat.input)\n }\n }\n }\n\n return (\n <form data-ak-input-bar=\"\" onSubmit={handleSubmit}>\n <textarea\n role=\"textbox\"\n value={chat.input}\n onChange={(e) => chat.setInput(e.target.value)}\n onKeyDown={handleKeyDown}\n placeholder={placeholder}\n disabled={disabled}\n data-ak-input=\"\"\n rows={1}\n />\n <button type=\"submit\" disabled={disabled || !chat.input.trim()} data-ak-send=\"\">\n Send\n </button>\n </form>\n )\n}\n","import React from 'react'\n\nexport interface MarkdownProps {\n content: string\n streaming?: boolean\n}\n\nexport function Markdown({ content, streaming = false }: MarkdownProps) {\n return (\n <div data-ak-markdown=\"\" data-ak-streaming={streaming ? 'true' : undefined}>\n {content}\n </div>\n )\n}\n","import React, { useCallback } from 'react'\n\nexport interface CodeBlockProps {\n code: string\n language?: string\n copyable?: boolean\n}\n\nexport function CodeBlock({ code, language, copyable = false }: CodeBlockProps) {\n const handleCopy = useCallback(() => {\n navigator.clipboard.writeText(code)\n }, [code])\n\n return (\n <div data-ak-code-block=\"\" data-ak-language={language}>\n <pre>\n <code>{code}</code>\n </pre>\n {copyable && (\n <button onClick={handleCopy} data-ak-copy=\"\" type=\"button\">\n Copy\n </button>\n )}\n </div>\n )\n}\n","import React, { useState } from 'react'\nimport type { ToolCall } from '@agentskit/core'\n\nexport interface ToolCallViewProps {\n toolCall: ToolCall\n}\n\nexport function ToolCallView({ toolCall }: ToolCallViewProps) {\n const [expanded, setExpanded] = useState(false)\n\n return (\n <div data-ak-tool-call=\"\" data-ak-tool-status={toolCall.status}>\n <button\n onClick={() => setExpanded(!expanded)}\n data-ak-tool-toggle=\"\"\n type=\"button\"\n >\n {toolCall.name}\n </button>\n {expanded && (\n <div data-ak-tool-details=\"\">\n <pre data-ak-tool-args=\"\">\n {JSON.stringify(toolCall.args, null, 2)}\n </pre>\n {toolCall.result && (\n <div data-ak-tool-result=\"\">{toolCall.result}</div>\n )}\n </div>\n )}\n </div>\n )\n}\n","import React from 'react'\n\nexport interface ThinkingIndicatorProps {\n visible: boolean\n label?: string\n}\n\nexport function ThinkingIndicator({ visible, label = 'Thinking...' }: ThinkingIndicatorProps) {\n if (!visible) return null\n\n return (\n <div data-ak-thinking=\"\" data-testid=\"ak-thinking\">\n <span data-ak-thinking-dots=\"\">\n <span>&bull;</span><span>&bull;</span><span>&bull;</span>\n </span>\n <span data-ak-thinking-label=\"\">{label}</span>\n </div>\n )\n}\n","import React from 'react'\nimport type { ToolCall } from '@agentskit/core'\n\nexport interface ToolConfirmationProps {\n toolCall: ToolCall\n onApprove: (toolCallId: string) => void\n onDeny: (toolCallId: string, reason?: string) => void\n}\n\nexport function ToolConfirmation({ toolCall, onApprove, onDeny }: ToolConfirmationProps) {\n if (toolCall.status !== 'requires_confirmation') return null\n\n return (\n <div data-ak-tool-confirmation data-ak-tool-name={toolCall.name}>\n <div data-ak-tool-confirmation-header>\n <span data-ak-tool-confirmation-name>{toolCall.name}</span>\n <span data-ak-tool-confirmation-status>requires confirmation</span>\n </div>\n <div data-ak-tool-confirmation-args>\n {JSON.stringify(toolCall.args, null, 2)}\n </div>\n <div data-ak-tool-confirmation-actions>\n <button\n data-ak-tool-confirmation-approve\n onClick={() => onApprove(toolCall.id)}\n >\n Approve\n </button>\n <button\n data-ak-tool-confirmation-deny\n onClick={() => onDeny(toolCall.id)}\n >\n Deny\n </button>\n </div>\n </div>\n )\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -53,4 +53,11 @@ interface ThinkingIndicatorProps {
53
53
  }
54
54
  declare function ThinkingIndicator({ visible, label }: ThinkingIndicatorProps): react_jsx_runtime.JSX.Element | null;
55
55
 
56
- export { ChatContainer, type ChatContainerProps, CodeBlock, type CodeBlockProps, InputBar, type InputBarProps, Markdown, type MarkdownProps, Message, type MessageProps, ThinkingIndicator, type ThinkingIndicatorProps, ToolCallView, type ToolCallViewProps, useChat, useReactive, useStream };
56
+ interface ToolConfirmationProps {
57
+ toolCall: ToolCall;
58
+ onApprove: (toolCallId: string) => void;
59
+ onDeny: (toolCallId: string, reason?: string) => void;
60
+ }
61
+ declare function ToolConfirmation({ toolCall, onApprove, onDeny }: ToolConfirmationProps): react_jsx_runtime.JSX.Element | null;
62
+
63
+ export { ChatContainer, type ChatContainerProps, CodeBlock, type CodeBlockProps, InputBar, type InputBarProps, Markdown, type MarkdownProps, Message, type MessageProps, ThinkingIndicator, type ThinkingIndicatorProps, ToolCallView, type ToolCallViewProps, ToolConfirmation, type ToolConfirmationProps, useChat, useReactive, useStream };
package/dist/index.d.ts CHANGED
@@ -53,4 +53,11 @@ interface ThinkingIndicatorProps {
53
53
  }
54
54
  declare function ThinkingIndicator({ visible, label }: ThinkingIndicatorProps): react_jsx_runtime.JSX.Element | null;
55
55
 
56
- export { ChatContainer, type ChatContainerProps, CodeBlock, type CodeBlockProps, InputBar, type InputBarProps, Markdown, type MarkdownProps, Message, type MessageProps, ThinkingIndicator, type ThinkingIndicatorProps, ToolCallView, type ToolCallViewProps, useChat, useReactive, useStream };
56
+ interface ToolConfirmationProps {
57
+ toolCall: ToolCall;
58
+ onApprove: (toolCallId: string) => void;
59
+ onDeny: (toolCallId: string, reason?: string) => void;
60
+ }
61
+ declare function ToolConfirmation({ toolCall, onApprove, onDeny }: ToolConfirmationProps): react_jsx_runtime.JSX.Element | null;
62
+
63
+ export { ChatContainer, type ChatContainerProps, CodeBlock, type CodeBlockProps, InputBar, type InputBarProps, Markdown, type MarkdownProps, Message, type MessageProps, ThinkingIndicator, type ThinkingIndicatorProps, ToolCallView, type ToolCallViewProps, ToolConfirmation, type ToolConfirmationProps, useChat, useReactive, useStream };
package/dist/index.js CHANGED
@@ -123,7 +123,9 @@ function useChat(config) {
123
123
  stop: controllerRef.current.stop,
124
124
  retry: controllerRef.current.retry,
125
125
  setInput: controllerRef.current.setInput,
126
- clear: controllerRef.current.clear
126
+ clear: controllerRef.current.clear,
127
+ approve: controllerRef.current.approve,
128
+ deny: controllerRef.current.deny
127
129
  };
128
130
  }
129
131
  function ChatContainer({ children, className }) {
@@ -237,7 +239,35 @@ function ThinkingIndicator({ visible, label = "Thinking..." }) {
237
239
  /* @__PURE__ */ jsx("span", { "data-ak-thinking-label": "", children: label })
238
240
  ] });
239
241
  }
242
+ function ToolConfirmation({ toolCall, onApprove, onDeny }) {
243
+ if (toolCall.status !== "requires_confirmation") return null;
244
+ return /* @__PURE__ */ jsxs("div", { "data-ak-tool-confirmation": true, "data-ak-tool-name": toolCall.name, children: [
245
+ /* @__PURE__ */ jsxs("div", { "data-ak-tool-confirmation-header": true, children: [
246
+ /* @__PURE__ */ jsx("span", { "data-ak-tool-confirmation-name": true, children: toolCall.name }),
247
+ /* @__PURE__ */ jsx("span", { "data-ak-tool-confirmation-status": true, children: "requires confirmation" })
248
+ ] }),
249
+ /* @__PURE__ */ jsx("div", { "data-ak-tool-confirmation-args": true, children: JSON.stringify(toolCall.args, null, 2) }),
250
+ /* @__PURE__ */ jsxs("div", { "data-ak-tool-confirmation-actions": true, children: [
251
+ /* @__PURE__ */ jsx(
252
+ "button",
253
+ {
254
+ "data-ak-tool-confirmation-approve": true,
255
+ onClick: () => onApprove(toolCall.id),
256
+ children: "Approve"
257
+ }
258
+ ),
259
+ /* @__PURE__ */ jsx(
260
+ "button",
261
+ {
262
+ "data-ak-tool-confirmation-deny": true,
263
+ onClick: () => onDeny(toolCall.id),
264
+ children: "Deny"
265
+ }
266
+ )
267
+ ] })
268
+ ] });
269
+ }
240
270
 
241
- export { ChatContainer, CodeBlock, InputBar, Markdown, Message, ThinkingIndicator, ToolCallView, useChat, useReactive, useStream };
271
+ export { ChatContainer, CodeBlock, InputBar, Markdown, Message, ThinkingIndicator, ToolCallView, ToolConfirmation, useChat, useReactive, useStream };
242
272
  //# sourceMappingURL=index.js.map
243
273
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/useStream.ts","../src/useReactive.ts","../src/useChat.ts","../src/components/ChatContainer.tsx","../src/components/Message.tsx","../src/components/InputBar.tsx","../src/components/Markdown.tsx","../src/components/CodeBlock.tsx","../src/components/ToolCallView.tsx","../src/components/ThinkingIndicator.tsx"],"names":["error","useRef","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CAAC,MAAA,EAAA,EAAK,QAAA,EAAA,QAAA,EAAM,CAAA;AAAA,sBAAOA,GAAAA,CAAC,MAAA,EAAA,EAAK,QAAA,EAAA,QAAA,EAAM;AAAA,KAAA,EACpD,CAAA;AAAA,oBACAA,GAAAA,CAAC,MAAA,EAAA,EAAK,wBAAA,EAAuB,IAAI,QAAA,EAAA,KAAA,EAAM;AAAA,GAAA,EACzC,CAAA;AAEJ","file":"index.js","sourcesContent":["import { useState, useEffect, useRef, useCallback } from 'react'\nimport type { StreamSource, StreamChunk, StreamStatus, UseStreamOptions, UseStreamReturn } from '@agentskit/core'\n\nexport function useStream(\n source: StreamSource,\n options?: UseStreamOptions\n): UseStreamReturn {\n const [data, setData] = useState<StreamChunk | null>(null)\n const [text, setText] = useState('')\n const [status, setStatus] = useState<StreamStatus>('idle')\n const [error, setError] = useState<Error | null>(null)\n const sourceRef = useRef(source)\n const optionsRef = useRef(options)\n const abortedRef = useRef(false)\n\n sourceRef.current = source\n optionsRef.current = options\n\n useEffect(() => {\n let cancelled = false\n abortedRef.current = false\n setStatus('streaming')\n setText('')\n setData(null)\n setError(null)\n\n let accumulated = ''\n\n const consume = async () => {\n try {\n const iterator = sourceRef.current.stream()\n for await (const chunk of iterator) {\n if (cancelled || abortedRef.current) return\n\n setData(chunk)\n optionsRef.current?.onChunk?.(chunk)\n\n if (chunk.type === 'text' && chunk.content) {\n accumulated += chunk.content\n setText(accumulated)\n } else if (chunk.type === 'error') {\n const err = new Error(chunk.content ?? 'Stream error')\n setError(err)\n setStatus('error')\n optionsRef.current?.onError?.(err)\n return\n } else if (chunk.type === 'done') {\n setStatus('complete')\n optionsRef.current?.onComplete?.(accumulated)\n return\n }\n }\n\n if (!cancelled && !abortedRef.current) {\n setStatus('complete')\n optionsRef.current?.onComplete?.(accumulated)\n }\n } catch (err) {\n if (!cancelled && !abortedRef.current) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n setStatus('error')\n optionsRef.current?.onError?.(error)\n }\n }\n }\n\n consume()\n\n return () => {\n cancelled = true\n }\n }, [source])\n\n const stop = useCallback(() => {\n abortedRef.current = true\n sourceRef.current.abort()\n }, [])\n\n return { data, text, status, error, stop }\n}\n","import { useRef, useSyncExternalStore, useCallback } from 'react'\n\nexport function useReactive<T extends Record<string, unknown>>(initialState: T): T {\n const storeRef = useRef<{\n state: T\n listeners: Set<() => void>\n proxy: T\n version: number\n } | null>(null)\n\n if (storeRef.current === null) {\n const store = {\n state: { ...initialState },\n listeners: new Set<() => void>(),\n proxy: null as unknown as T,\n version: 0,\n }\n\n const notify = () => {\n store.version++\n store.listeners.forEach(listener => listener())\n }\n\n store.proxy = new Proxy(store.state, {\n get(target, prop, receiver) {\n return Reflect.get(target, prop, receiver)\n },\n set(target, prop, value, receiver) {\n const result = Reflect.set(target, prop, value, receiver)\n notify()\n return result\n },\n }) as T\n\n storeRef.current = store\n }\n\n const store = storeRef.current\n\n const subscribe = useCallback((callback: () => void) => {\n store.listeners.add(callback)\n return () => { store.listeners.delete(callback) }\n }, [store])\n\n const getSnapshot = useCallback(() => store.version, [store])\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot)\n\n return store.proxy\n}\n","// NOTE: This hook is identical in @agentskit/react and @agentskit/ink.\n// Changes here must be mirrored in packages/ink/src/useChat.ts.\nimport { useEffect, useRef, useSyncExternalStore } from 'react'\nimport { createChatController } from '@agentskit/core'\nimport type { ChatConfig, ChatController, ChatReturn } from '@agentskit/core'\n\nexport function useChat(config: ChatConfig): ChatReturn {\n const controllerRef = useRef<ChatController | null>(null)\n\n if (!controllerRef.current) {\n controllerRef.current = createChatController(config)\n }\n\n useEffect(() => {\n controllerRef.current?.updateConfig(config)\n }, [config])\n\n const state = useSyncExternalStore(\n controllerRef.current.subscribe,\n controllerRef.current.getState,\n controllerRef.current.getState\n )\n\n return {\n ...state,\n send: controllerRef.current.send,\n stop: controllerRef.current.stop,\n retry: controllerRef.current.retry,\n setInput: controllerRef.current.setInput,\n clear: controllerRef.current.clear,\n }\n}\n","import React, { useRef, useEffect, type ReactNode } from 'react'\n\nexport interface ChatContainerProps {\n children: ReactNode\n className?: string\n}\n\nexport function ChatContainer({ children, className }: ChatContainerProps) {\n const containerRef = useRef<HTMLDivElement>(null)\n\n useEffect(() => {\n const el = containerRef.current\n if (!el) return\n\n const observer = new MutationObserver(() => {\n el.scrollTop = el.scrollHeight\n })\n\n observer.observe(el, { childList: true, subtree: true, characterData: true })\n return () => observer.disconnect()\n }, [])\n\n return (\n <div\n ref={containerRef}\n data-ak-chat-container=\"\"\n data-testid=\"ak-chat-container\"\n className={className}\n style={{ overflow: 'auto' }}\n >\n {children}\n </div>\n )\n}\n","import React, { type ReactNode } from 'react'\nimport type { Message as MessageType } from '@agentskit/core'\n\nexport interface MessageProps {\n message: MessageType\n avatar?: ReactNode\n actions?: ReactNode\n}\n\nexport function Message({ message, avatar, actions }: MessageProps) {\n return (\n <div\n data-ak-message=\"\"\n data-ak-role={message.role}\n data-ak-status={message.status}\n >\n {avatar && <div data-ak-avatar=\"\">{avatar}</div>}\n <div data-ak-content=\"\">{message.content}</div>\n {actions && <div data-ak-actions=\"\">{actions}</div>}\n </div>\n )\n}\n","import React, { type FormEvent, type KeyboardEvent } from 'react'\nimport type { ChatReturn } from '@agentskit/core'\n\nexport interface InputBarProps {\n chat: ChatReturn\n placeholder?: string\n disabled?: boolean\n}\n\nexport function InputBar({ chat, placeholder = 'Type a message...', disabled = false }: InputBarProps) {\n const handleSubmit = (e: FormEvent) => {\n e.preventDefault()\n if (chat.input.trim()) {\n chat.send(chat.input)\n }\n }\n\n const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault()\n if (chat.input.trim()) {\n chat.send(chat.input)\n }\n }\n }\n\n return (\n <form data-ak-input-bar=\"\" onSubmit={handleSubmit}>\n <textarea\n role=\"textbox\"\n value={chat.input}\n onChange={(e) => chat.setInput(e.target.value)}\n onKeyDown={handleKeyDown}\n placeholder={placeholder}\n disabled={disabled}\n data-ak-input=\"\"\n rows={1}\n />\n <button type=\"submit\" disabled={disabled || !chat.input.trim()} data-ak-send=\"\">\n Send\n </button>\n </form>\n )\n}\n","import React from 'react'\n\nexport interface MarkdownProps {\n content: string\n streaming?: boolean\n}\n\nexport function Markdown({ content, streaming = false }: MarkdownProps) {\n return (\n <div data-ak-markdown=\"\" data-ak-streaming={streaming ? 'true' : undefined}>\n {content}\n </div>\n )\n}\n","import React, { useCallback } from 'react'\n\nexport interface CodeBlockProps {\n code: string\n language?: string\n copyable?: boolean\n}\n\nexport function CodeBlock({ code, language, copyable = false }: CodeBlockProps) {\n const handleCopy = useCallback(() => {\n navigator.clipboard.writeText(code)\n }, [code])\n\n return (\n <div data-ak-code-block=\"\" data-ak-language={language}>\n <pre>\n <code>{code}</code>\n </pre>\n {copyable && (\n <button onClick={handleCopy} data-ak-copy=\"\" type=\"button\">\n Copy\n </button>\n )}\n </div>\n )\n}\n","import React, { useState } from 'react'\nimport type { ToolCall } from '@agentskit/core'\n\nexport interface ToolCallViewProps {\n toolCall: ToolCall\n}\n\nexport function ToolCallView({ toolCall }: ToolCallViewProps) {\n const [expanded, setExpanded] = useState(false)\n\n return (\n <div data-ak-tool-call=\"\" data-ak-tool-status={toolCall.status}>\n <button\n onClick={() => setExpanded(!expanded)}\n data-ak-tool-toggle=\"\"\n type=\"button\"\n >\n {toolCall.name}\n </button>\n {expanded && (\n <div data-ak-tool-details=\"\">\n <pre data-ak-tool-args=\"\">\n {JSON.stringify(toolCall.args, null, 2)}\n </pre>\n {toolCall.result && (\n <div data-ak-tool-result=\"\">{toolCall.result}</div>\n )}\n </div>\n )}\n </div>\n )\n}\n","import React from 'react'\n\nexport interface ThinkingIndicatorProps {\n visible: boolean\n label?: string\n}\n\nexport function ThinkingIndicator({ visible, label = 'Thinking...' }: ThinkingIndicatorProps) {\n if (!visible) return null\n\n return (\n <div data-ak-thinking=\"\" data-testid=\"ak-thinking\">\n <span data-ak-thinking-dots=\"\">\n <span>&bull;</span><span>&bull;</span><span>&bull;</span>\n </span>\n <span data-ak-thinking-label=\"\">{label}</span>\n </div>\n )\n}\n"]}
1
+ {"version":3,"sources":["../src/useStream.ts","../src/useReactive.ts","../src/useChat.ts","../src/components/ChatContainer.tsx","../src/components/Message.tsx","../src/components/InputBar.tsx","../src/components/Markdown.tsx","../src/components/CodeBlock.tsx","../src/components/ToolCallView.tsx","../src/components/ThinkingIndicator.tsx","../src/components/ToolConfirmation.tsx"],"names":["error","useRef","store","useCallback","useEffect","useSyncExternalStore","jsx","jsxs","useState"],"mappings":";;;;;;AAGO,SAAS,SAAA,CACd,QACA,OAAA,EACiB;AACjB,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAI,SAA6B,IAAI,CAAA;AACzD,EAAA,MAAM,CAAC,IAAA,EAAM,OAAO,CAAA,GAAI,SAAS,EAAE,CAAA;AACnC,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAI,SAAuB,MAAM,CAAA;AACzD,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,SAAuB,IAAI,CAAA;AACrD,EAAA,MAAM,SAAA,GAAY,OAAO,MAAM,CAAA;AAC/B,EAAA,MAAM,UAAA,GAAa,OAAO,OAAO,CAAA;AACjC,EAAA,MAAM,UAAA,GAAa,OAAO,KAAK,CAAA;AAE/B,EAAA,SAAA,CAAU,OAAA,GAAU,MAAA;AACpB,EAAA,UAAA,CAAW,OAAA,GAAU,OAAA;AAErB,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,SAAA,GAAY,KAAA;AAChB,IAAA,UAAA,CAAW,OAAA,GAAU,KAAA;AACrB,IAAA,SAAA,CAAU,WAAW,CAAA;AACrB,IAAA,OAAA,CAAQ,EAAE,CAAA;AACV,IAAA,OAAA,CAAQ,IAAI,CAAA;AACZ,IAAA,QAAA,CAAS,IAAI,CAAA;AAEb,IAAA,IAAI,WAAA,GAAc,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KAAA,EAC9D,CAAA;AAAA,oBACAA,GAAAA,CAAC,KAAA,EAAA,EAAI,gCAAA,EAA8B,IAAA,EAChC,QAAA,EAAA,IAAA,CAAK,SAAA,CAAU,QAAA,CAAS,IAAA,EAAM,IAAA,EAAM,CAAC,CAAA,EACxC,CAAA;AAAA,oBACAC,IAAAA,CAAC,KAAA,EAAA,EAAI,mCAAA,EAAiC,IAAA,EACpC,QAAA,EAAA;AAAA,sBAAAD,GAAAA;AAAA,QAAC,QAAA;AAAA,QAAA;AAAA,UACC,mCAAA,EAAiC,IAAA;AAAA,UACjC,OAAA,EAAS,MAAM,SAAA,CAAU,QAAA,CAAS,EAAE,CAAA;AAAA,UACrC,QAAA,EAAA;AAAA;AAAA,OAED;AAAA,sBACAA,GAAAA;AAAA,QAAC,QAAA;AAAA,QAAA;AAAA,UACC,gCAAA,EAA8B,IAAA;AAAA,UAC9B,OAAA,EAAS,MAAM,MAAA,CAAO,QAAA,CAAS,EAAE,CAAA;AAAA,UAClC,QAAA,EAAA;AAAA;AAAA;AAED,KAAA,EACF;AAAA,GAAA,EACF,CAAA;AAEJ","file":"index.js","sourcesContent":["import { useState, useEffect, useRef, useCallback } from 'react'\nimport type { StreamSource, StreamChunk, StreamStatus, UseStreamOptions, UseStreamReturn } from '@agentskit/core'\n\nexport function useStream(\n source: StreamSource,\n options?: UseStreamOptions\n): UseStreamReturn {\n const [data, setData] = useState<StreamChunk | null>(null)\n const [text, setText] = useState('')\n const [status, setStatus] = useState<StreamStatus>('idle')\n const [error, setError] = useState<Error | null>(null)\n const sourceRef = useRef(source)\n const optionsRef = useRef(options)\n const abortedRef = useRef(false)\n\n sourceRef.current = source\n optionsRef.current = options\n\n useEffect(() => {\n let cancelled = false\n abortedRef.current = false\n setStatus('streaming')\n setText('')\n setData(null)\n setError(null)\n\n let accumulated = ''\n\n const consume = async () => {\n try {\n const iterator = sourceRef.current.stream()\n for await (const chunk of iterator) {\n if (cancelled || abortedRef.current) return\n\n setData(chunk)\n optionsRef.current?.onChunk?.(chunk)\n\n if (chunk.type === 'text' && chunk.content) {\n accumulated += chunk.content\n setText(accumulated)\n } else if (chunk.type === 'error') {\n const err = new Error(chunk.content ?? 'Stream error')\n setError(err)\n setStatus('error')\n optionsRef.current?.onError?.(err)\n return\n } else if (chunk.type === 'done') {\n setStatus('complete')\n optionsRef.current?.onComplete?.(accumulated)\n return\n }\n }\n\n if (!cancelled && !abortedRef.current) {\n setStatus('complete')\n optionsRef.current?.onComplete?.(accumulated)\n }\n } catch (err) {\n if (!cancelled && !abortedRef.current) {\n const error = err instanceof Error ? err : new Error(String(err))\n setError(error)\n setStatus('error')\n optionsRef.current?.onError?.(error)\n }\n }\n }\n\n consume()\n\n return () => {\n cancelled = true\n }\n }, [source])\n\n const stop = useCallback(() => {\n abortedRef.current = true\n sourceRef.current.abort()\n }, [])\n\n return { data, text, status, error, stop }\n}\n","import { useRef, useSyncExternalStore, useCallback } from 'react'\n\nexport function useReactive<T extends Record<string, unknown>>(initialState: T): T {\n const storeRef = useRef<{\n state: T\n listeners: Set<() => void>\n proxy: T\n version: number\n } | null>(null)\n\n if (storeRef.current === null) {\n const store = {\n state: { ...initialState },\n listeners: new Set<() => void>(),\n proxy: null as unknown as T,\n version: 0,\n }\n\n const notify = () => {\n store.version++\n store.listeners.forEach(listener => listener())\n }\n\n store.proxy = new Proxy(store.state, {\n get(target, prop, receiver) {\n return Reflect.get(target, prop, receiver)\n },\n set(target, prop, value, receiver) {\n const result = Reflect.set(target, prop, value, receiver)\n notify()\n return result\n },\n }) as T\n\n storeRef.current = store\n }\n\n const store = storeRef.current\n\n const subscribe = useCallback((callback: () => void) => {\n store.listeners.add(callback)\n return () => { store.listeners.delete(callback) }\n }, [store])\n\n const getSnapshot = useCallback(() => store.version, [store])\n\n useSyncExternalStore(subscribe, getSnapshot, getSnapshot)\n\n return store.proxy\n}\n","// NOTE: This hook is intentionally duplicated in @agentskit/ink (packages/ink/src/useChat.ts).\n// The two packages are React siblings and cannot cross-depend, so the hook is kept in sync\n// manually. A sync-guard test at packages/ink/tests/useChat-sync.test.ts will fail if they drift.\n// When changing this file, mirror the same change in packages/ink/src/useChat.ts.\nimport { useEffect, useRef, useSyncExternalStore } from 'react'\nimport { createChatController } from '@agentskit/core'\nimport type { ChatConfig, ChatController, ChatReturn } from '@agentskit/core'\n\nexport function useChat(config: ChatConfig): ChatReturn {\n const controllerRef = useRef<ChatController | null>(null)\n\n if (!controllerRef.current) {\n controllerRef.current = createChatController(config)\n }\n\n useEffect(() => {\n controllerRef.current?.updateConfig(config)\n }, [config])\n\n const state = useSyncExternalStore(\n controllerRef.current.subscribe,\n controllerRef.current.getState,\n controllerRef.current.getState\n )\n\n return {\n ...state,\n send: controllerRef.current.send,\n stop: controllerRef.current.stop,\n retry: controllerRef.current.retry,\n setInput: controllerRef.current.setInput,\n clear: controllerRef.current.clear,\n approve: controllerRef.current.approve,\n deny: controllerRef.current.deny,\n }\n}\n","import React, { useRef, useEffect, type ReactNode } from 'react'\n\nexport interface ChatContainerProps {\n children: ReactNode\n className?: string\n}\n\nexport function ChatContainer({ children, className }: ChatContainerProps) {\n const containerRef = useRef<HTMLDivElement>(null)\n\n useEffect(() => {\n const el = containerRef.current\n if (!el) return\n\n const observer = new MutationObserver(() => {\n el.scrollTop = el.scrollHeight\n })\n\n observer.observe(el, { childList: true, subtree: true, characterData: true })\n return () => observer.disconnect()\n }, [])\n\n return (\n <div\n ref={containerRef}\n data-ak-chat-container=\"\"\n data-testid=\"ak-chat-container\"\n className={className}\n style={{ overflow: 'auto' }}\n >\n {children}\n </div>\n )\n}\n","import React, { type ReactNode } from 'react'\nimport type { Message as MessageType } from '@agentskit/core'\n\nexport interface MessageProps {\n message: MessageType\n avatar?: ReactNode\n actions?: ReactNode\n}\n\nexport function Message({ message, avatar, actions }: MessageProps) {\n return (\n <div\n data-ak-message=\"\"\n data-ak-role={message.role}\n data-ak-status={message.status}\n >\n {avatar && <div data-ak-avatar=\"\">{avatar}</div>}\n <div data-ak-content=\"\">{message.content}</div>\n {actions && <div data-ak-actions=\"\">{actions}</div>}\n </div>\n )\n}\n","import React, { type FormEvent, type KeyboardEvent } from 'react'\nimport type { ChatReturn } from '@agentskit/core'\n\nexport interface InputBarProps {\n chat: ChatReturn\n placeholder?: string\n disabled?: boolean\n}\n\nexport function InputBar({ chat, placeholder = 'Type a message...', disabled = false }: InputBarProps) {\n const handleSubmit = (e: FormEvent) => {\n e.preventDefault()\n if (chat.input.trim()) {\n chat.send(chat.input)\n }\n }\n\n const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {\n if (e.key === 'Enter' && !e.shiftKey) {\n e.preventDefault()\n if (chat.input.trim()) {\n chat.send(chat.input)\n }\n }\n }\n\n return (\n <form data-ak-input-bar=\"\" onSubmit={handleSubmit}>\n <textarea\n role=\"textbox\"\n value={chat.input}\n onChange={(e) => chat.setInput(e.target.value)}\n onKeyDown={handleKeyDown}\n placeholder={placeholder}\n disabled={disabled}\n data-ak-input=\"\"\n rows={1}\n />\n <button type=\"submit\" disabled={disabled || !chat.input.trim()} data-ak-send=\"\">\n Send\n </button>\n </form>\n )\n}\n","import React from 'react'\n\nexport interface MarkdownProps {\n content: string\n streaming?: boolean\n}\n\nexport function Markdown({ content, streaming = false }: MarkdownProps) {\n return (\n <div data-ak-markdown=\"\" data-ak-streaming={streaming ? 'true' : undefined}>\n {content}\n </div>\n )\n}\n","import React, { useCallback } from 'react'\n\nexport interface CodeBlockProps {\n code: string\n language?: string\n copyable?: boolean\n}\n\nexport function CodeBlock({ code, language, copyable = false }: CodeBlockProps) {\n const handleCopy = useCallback(() => {\n navigator.clipboard.writeText(code)\n }, [code])\n\n return (\n <div data-ak-code-block=\"\" data-ak-language={language}>\n <pre>\n <code>{code}</code>\n </pre>\n {copyable && (\n <button onClick={handleCopy} data-ak-copy=\"\" type=\"button\">\n Copy\n </button>\n )}\n </div>\n )\n}\n","import React, { useState } from 'react'\nimport type { ToolCall } from '@agentskit/core'\n\nexport interface ToolCallViewProps {\n toolCall: ToolCall\n}\n\nexport function ToolCallView({ toolCall }: ToolCallViewProps) {\n const [expanded, setExpanded] = useState(false)\n\n return (\n <div data-ak-tool-call=\"\" data-ak-tool-status={toolCall.status}>\n <button\n onClick={() => setExpanded(!expanded)}\n data-ak-tool-toggle=\"\"\n type=\"button\"\n >\n {toolCall.name}\n </button>\n {expanded && (\n <div data-ak-tool-details=\"\">\n <pre data-ak-tool-args=\"\">\n {JSON.stringify(toolCall.args, null, 2)}\n </pre>\n {toolCall.result && (\n <div data-ak-tool-result=\"\">{toolCall.result}</div>\n )}\n </div>\n )}\n </div>\n )\n}\n","import React from 'react'\n\nexport interface ThinkingIndicatorProps {\n visible: boolean\n label?: string\n}\n\nexport function ThinkingIndicator({ visible, label = 'Thinking...' }: ThinkingIndicatorProps) {\n if (!visible) return null\n\n return (\n <div data-ak-thinking=\"\" data-testid=\"ak-thinking\">\n <span data-ak-thinking-dots=\"\">\n <span>&bull;</span><span>&bull;</span><span>&bull;</span>\n </span>\n <span data-ak-thinking-label=\"\">{label}</span>\n </div>\n )\n}\n","import React from 'react'\nimport type { ToolCall } from '@agentskit/core'\n\nexport interface ToolConfirmationProps {\n toolCall: ToolCall\n onApprove: (toolCallId: string) => void\n onDeny: (toolCallId: string, reason?: string) => void\n}\n\nexport function ToolConfirmation({ toolCall, onApprove, onDeny }: ToolConfirmationProps) {\n if (toolCall.status !== 'requires_confirmation') return null\n\n return (\n <div data-ak-tool-confirmation data-ak-tool-name={toolCall.name}>\n <div data-ak-tool-confirmation-header>\n <span data-ak-tool-confirmation-name>{toolCall.name}</span>\n <span data-ak-tool-confirmation-status>requires confirmation</span>\n </div>\n <div data-ak-tool-confirmation-args>\n {JSON.stringify(toolCall.args, null, 2)}\n </div>\n <div data-ak-tool-confirmation-actions>\n <button\n data-ak-tool-confirmation-approve\n onClick={() => onApprove(toolCall.id)}\n >\n Approve\n </button>\n <button\n data-ak-tool-confirmation-deny\n onClick={() => onDeny(toolCall.id)}\n >\n Deny\n </button>\n </div>\n </div>\n )\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,18 @@
1
1
  {
2
2
  "name": "@agentskit/react",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "React hooks and UI components for AgentsKit.",
5
+ "keywords": [
6
+ "agentskit",
7
+ "ai",
8
+ "agents",
9
+ "llm",
10
+ "chat",
11
+ "typescript",
12
+ "react",
13
+ "hooks",
14
+ "ui"
15
+ ],
5
16
  "type": "module",
6
17
  "main": "./dist/index.cjs",
7
18
  "module": "./dist/index.js",
@@ -18,7 +29,7 @@
18
29
  "dist"
19
30
  ],
20
31
  "dependencies": {
21
- "@agentskit/core": "0.4.0"
32
+ "@agentskit/core": "0.4.2"
22
33
  },
23
34
  "peerDependencies": {
24
35
  "react": ">=18.0.0",
@@ -27,14 +38,15 @@
27
38
  "devDependencies": {
28
39
  "@testing-library/jest-dom": "^6.0.0",
29
40
  "@testing-library/react": "^16.0.0",
30
- "@types/node": "^24.0.0",
31
- "@types/react": "^18.3.0",
32
- "@types/react-dom": "^18.3.0",
33
- "jsdom": "^24.0.0",
34
- "react": "^18.3.1",
35
- "react-dom": "^18.3.1",
41
+ "@types/node": "^25.5.2",
42
+ "@types/react": "^19.2.14",
43
+ "@types/react-dom": "^19.2.3",
44
+ "happy-dom": "^20.8.9",
45
+ "jsdom": "^29.0.1",
46
+ "react": "^19.2.4",
47
+ "react-dom": "^19.2.4",
36
48
  "tsup": "^8.5.0",
37
- "typescript": "^5.9.2",
49
+ "typescript": "^6.0.2",
38
50
  "vitest": "^4.1.2"
39
51
  },
40
52
  "publishConfig": {