@agentskit/react 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.cjs +277 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +56 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.js +243 -0
- package/dist/index.js.map +1 -0
- package/dist/theme/default.css +215 -0
- package/dist/theme/tokens.css +79 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Emerson Braun
|
|
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.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@agentskit/core');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
// src/index.ts
|
|
8
|
+
function useStream(source, options) {
|
|
9
|
+
const [data, setData] = react.useState(null);
|
|
10
|
+
const [text, setText] = react.useState("");
|
|
11
|
+
const [status, setStatus] = react.useState("idle");
|
|
12
|
+
const [error, setError] = react.useState(null);
|
|
13
|
+
const sourceRef = react.useRef(source);
|
|
14
|
+
const optionsRef = react.useRef(options);
|
|
15
|
+
const abortedRef = react.useRef(false);
|
|
16
|
+
sourceRef.current = source;
|
|
17
|
+
optionsRef.current = options;
|
|
18
|
+
react.useEffect(() => {
|
|
19
|
+
let cancelled = false;
|
|
20
|
+
abortedRef.current = false;
|
|
21
|
+
setStatus("streaming");
|
|
22
|
+
setText("");
|
|
23
|
+
setData(null);
|
|
24
|
+
setError(null);
|
|
25
|
+
let accumulated = "";
|
|
26
|
+
const consume = async () => {
|
|
27
|
+
try {
|
|
28
|
+
const iterator = sourceRef.current.stream();
|
|
29
|
+
for await (const chunk of iterator) {
|
|
30
|
+
if (cancelled || abortedRef.current) return;
|
|
31
|
+
setData(chunk);
|
|
32
|
+
optionsRef.current?.onChunk?.(chunk);
|
|
33
|
+
if (chunk.type === "text" && chunk.content) {
|
|
34
|
+
accumulated += chunk.content;
|
|
35
|
+
setText(accumulated);
|
|
36
|
+
} else if (chunk.type === "error") {
|
|
37
|
+
const err = new Error(chunk.content ?? "Stream error");
|
|
38
|
+
setError(err);
|
|
39
|
+
setStatus("error");
|
|
40
|
+
optionsRef.current?.onError?.(err);
|
|
41
|
+
return;
|
|
42
|
+
} else if (chunk.type === "done") {
|
|
43
|
+
setStatus("complete");
|
|
44
|
+
optionsRef.current?.onComplete?.(accumulated);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!cancelled && !abortedRef.current) {
|
|
49
|
+
setStatus("complete");
|
|
50
|
+
optionsRef.current?.onComplete?.(accumulated);
|
|
51
|
+
}
|
|
52
|
+
} catch (err) {
|
|
53
|
+
if (!cancelled && !abortedRef.current) {
|
|
54
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
55
|
+
setError(error2);
|
|
56
|
+
setStatus("error");
|
|
57
|
+
optionsRef.current?.onError?.(error2);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
consume();
|
|
62
|
+
return () => {
|
|
63
|
+
cancelled = true;
|
|
64
|
+
};
|
|
65
|
+
}, [source]);
|
|
66
|
+
const stop = react.useCallback(() => {
|
|
67
|
+
abortedRef.current = true;
|
|
68
|
+
sourceRef.current.abort();
|
|
69
|
+
}, []);
|
|
70
|
+
return { data, text, status, error, stop };
|
|
71
|
+
}
|
|
72
|
+
function useReactive(initialState) {
|
|
73
|
+
const storeRef = react.useRef(null);
|
|
74
|
+
if (storeRef.current === null) {
|
|
75
|
+
const store2 = {
|
|
76
|
+
state: { ...initialState },
|
|
77
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
78
|
+
proxy: null,
|
|
79
|
+
version: 0
|
|
80
|
+
};
|
|
81
|
+
const notify = () => {
|
|
82
|
+
store2.version++;
|
|
83
|
+
store2.listeners.forEach((listener) => listener());
|
|
84
|
+
};
|
|
85
|
+
store2.proxy = new Proxy(store2.state, {
|
|
86
|
+
get(target, prop, receiver) {
|
|
87
|
+
return Reflect.get(target, prop, receiver);
|
|
88
|
+
},
|
|
89
|
+
set(target, prop, value, receiver) {
|
|
90
|
+
const result = Reflect.set(target, prop, value, receiver);
|
|
91
|
+
notify();
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
storeRef.current = store2;
|
|
96
|
+
}
|
|
97
|
+
const store = storeRef.current;
|
|
98
|
+
const subscribe = react.useCallback((callback) => {
|
|
99
|
+
store.listeners.add(callback);
|
|
100
|
+
return () => {
|
|
101
|
+
store.listeners.delete(callback);
|
|
102
|
+
};
|
|
103
|
+
}, [store]);
|
|
104
|
+
const getSnapshot = react.useCallback(() => store.version, [store]);
|
|
105
|
+
react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
106
|
+
return store.proxy;
|
|
107
|
+
}
|
|
108
|
+
function useChat(config) {
|
|
109
|
+
const controllerRef = react.useRef(null);
|
|
110
|
+
if (!controllerRef.current) {
|
|
111
|
+
controllerRef.current = core.createChatController(config);
|
|
112
|
+
}
|
|
113
|
+
react.useEffect(() => {
|
|
114
|
+
controllerRef.current?.updateConfig(config);
|
|
115
|
+
}, [config]);
|
|
116
|
+
const state = react.useSyncExternalStore(
|
|
117
|
+
controllerRef.current.subscribe,
|
|
118
|
+
controllerRef.current.getState,
|
|
119
|
+
controllerRef.current.getState
|
|
120
|
+
);
|
|
121
|
+
return {
|
|
122
|
+
...state,
|
|
123
|
+
send: controllerRef.current.send,
|
|
124
|
+
stop: controllerRef.current.stop,
|
|
125
|
+
retry: controllerRef.current.retry,
|
|
126
|
+
setInput: controllerRef.current.setInput,
|
|
127
|
+
clear: controllerRef.current.clear
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function ChatContainer({ children, className }) {
|
|
131
|
+
const containerRef = react.useRef(null);
|
|
132
|
+
react.useEffect(() => {
|
|
133
|
+
const el = containerRef.current;
|
|
134
|
+
if (!el) return;
|
|
135
|
+
const observer = new MutationObserver(() => {
|
|
136
|
+
el.scrollTop = el.scrollHeight;
|
|
137
|
+
});
|
|
138
|
+
observer.observe(el, { childList: true, subtree: true, characterData: true });
|
|
139
|
+
return () => observer.disconnect();
|
|
140
|
+
}, []);
|
|
141
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
142
|
+
"div",
|
|
143
|
+
{
|
|
144
|
+
ref: containerRef,
|
|
145
|
+
"data-ak-chat-container": "",
|
|
146
|
+
"data-testid": "ak-chat-container",
|
|
147
|
+
className,
|
|
148
|
+
style: { overflow: "auto" },
|
|
149
|
+
children
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
function Message({ message, avatar, actions }) {
|
|
154
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
155
|
+
"div",
|
|
156
|
+
{
|
|
157
|
+
"data-ak-message": "",
|
|
158
|
+
"data-ak-role": message.role,
|
|
159
|
+
"data-ak-status": message.status,
|
|
160
|
+
children: [
|
|
161
|
+
avatar && /* @__PURE__ */ jsxRuntime.jsx("div", { "data-ak-avatar": "", children: avatar }),
|
|
162
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { "data-ak-content": "", children: message.content }),
|
|
163
|
+
actions && /* @__PURE__ */ jsxRuntime.jsx("div", { "data-ak-actions": "", children: actions })
|
|
164
|
+
]
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
function InputBar({ chat, placeholder = "Type a message...", disabled = false }) {
|
|
169
|
+
const handleSubmit = (e) => {
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
if (chat.input.trim()) {
|
|
172
|
+
chat.send(chat.input);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const handleKeyDown = (e) => {
|
|
176
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
177
|
+
e.preventDefault();
|
|
178
|
+
if (chat.input.trim()) {
|
|
179
|
+
chat.send(chat.input);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("form", { "data-ak-input-bar": "", onSubmit: handleSubmit, children: [
|
|
184
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
185
|
+
"textarea",
|
|
186
|
+
{
|
|
187
|
+
role: "textbox",
|
|
188
|
+
value: chat.input,
|
|
189
|
+
onChange: (e) => chat.setInput(e.target.value),
|
|
190
|
+
onKeyDown: handleKeyDown,
|
|
191
|
+
placeholder,
|
|
192
|
+
disabled,
|
|
193
|
+
"data-ak-input": "",
|
|
194
|
+
rows: 1
|
|
195
|
+
}
|
|
196
|
+
),
|
|
197
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", disabled: disabled || !chat.input.trim(), "data-ak-send": "", children: "Send" })
|
|
198
|
+
] });
|
|
199
|
+
}
|
|
200
|
+
function Markdown({ content, streaming = false }) {
|
|
201
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-ak-markdown": "", "data-ak-streaming": streaming ? "true" : void 0, children: content });
|
|
202
|
+
}
|
|
203
|
+
function CodeBlock({ code, language, copyable = false }) {
|
|
204
|
+
const handleCopy = react.useCallback(() => {
|
|
205
|
+
navigator.clipboard.writeText(code);
|
|
206
|
+
}, [code]);
|
|
207
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-ak-code-block": "", "data-ak-language": language, children: [
|
|
208
|
+
/* @__PURE__ */ jsxRuntime.jsx("pre", { children: /* @__PURE__ */ jsxRuntime.jsx("code", { children: code }) }),
|
|
209
|
+
copyable && /* @__PURE__ */ jsxRuntime.jsx("button", { onClick: handleCopy, "data-ak-copy": "", type: "button", children: "Copy" })
|
|
210
|
+
] });
|
|
211
|
+
}
|
|
212
|
+
function ToolCallView({ toolCall }) {
|
|
213
|
+
const [expanded, setExpanded] = react.useState(false);
|
|
214
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-ak-tool-call": "", "data-ak-tool-status": toolCall.status, children: [
|
|
215
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
216
|
+
"button",
|
|
217
|
+
{
|
|
218
|
+
onClick: () => setExpanded(!expanded),
|
|
219
|
+
"data-ak-tool-toggle": "",
|
|
220
|
+
type: "button",
|
|
221
|
+
children: toolCall.name
|
|
222
|
+
}
|
|
223
|
+
),
|
|
224
|
+
expanded && /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-ak-tool-details": "", children: [
|
|
225
|
+
/* @__PURE__ */ jsxRuntime.jsx("pre", { "data-ak-tool-args": "", children: JSON.stringify(toolCall.args, null, 2) }),
|
|
226
|
+
toolCall.result && /* @__PURE__ */ jsxRuntime.jsx("div", { "data-ak-tool-result": "", children: toolCall.result })
|
|
227
|
+
] })
|
|
228
|
+
] });
|
|
229
|
+
}
|
|
230
|
+
function ThinkingIndicator({ visible, label = "Thinking..." }) {
|
|
231
|
+
if (!visible) return null;
|
|
232
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-ak-thinking": "", "data-testid": "ak-thinking", children: [
|
|
233
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { "data-ak-thinking-dots": "", children: [
|
|
234
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u2022" }),
|
|
235
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u2022" }),
|
|
236
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u2022" })
|
|
237
|
+
] }),
|
|
238
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { "data-ak-thinking-label": "", children: label })
|
|
239
|
+
] });
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
Object.defineProperty(exports, "createChatController", {
|
|
243
|
+
enumerable: true,
|
|
244
|
+
get: function () { return core.createChatController; }
|
|
245
|
+
});
|
|
246
|
+
Object.defineProperty(exports, "createFileMemory", {
|
|
247
|
+
enumerable: true,
|
|
248
|
+
get: function () { return core.createFileMemory; }
|
|
249
|
+
});
|
|
250
|
+
Object.defineProperty(exports, "createInMemoryMemory", {
|
|
251
|
+
enumerable: true,
|
|
252
|
+
get: function () { return core.createInMemoryMemory; }
|
|
253
|
+
});
|
|
254
|
+
Object.defineProperty(exports, "createLocalStorageMemory", {
|
|
255
|
+
enumerable: true,
|
|
256
|
+
get: function () { return core.createLocalStorageMemory; }
|
|
257
|
+
});
|
|
258
|
+
Object.defineProperty(exports, "createStaticRetriever", {
|
|
259
|
+
enumerable: true,
|
|
260
|
+
get: function () { return core.createStaticRetriever; }
|
|
261
|
+
});
|
|
262
|
+
Object.defineProperty(exports, "formatRetrievedDocuments", {
|
|
263
|
+
enumerable: true,
|
|
264
|
+
get: function () { return core.formatRetrievedDocuments; }
|
|
265
|
+
});
|
|
266
|
+
exports.ChatContainer = ChatContainer;
|
|
267
|
+
exports.CodeBlock = CodeBlock;
|
|
268
|
+
exports.InputBar = InputBar;
|
|
269
|
+
exports.Markdown = Markdown;
|
|
270
|
+
exports.Message = Message;
|
|
271
|
+
exports.ThinkingIndicator = ThinkingIndicator;
|
|
272
|
+
exports.ToolCallView = ToolCallView;
|
|
273
|
+
exports.useChat = useChat;
|
|
274
|
+
exports.useReactive = useReactive;
|
|
275
|
+
exports.useStream = useStream;
|
|
276
|
+
//# sourceMappingURL=index.cjs.map
|
|
277
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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,M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EAAA,EAAI,wBAAqB,EAAA,EACxB,QAAA,EAAA;AAAA,sBAAAD,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>•</span><span>•</span><span>•</span>\n </span>\n <span data-ak-thinking-label=\"\">{label}</span>\n </div>\n )\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { StreamSource, UseStreamOptions, UseStreamReturn, ChatConfig, ChatReturn, Message as Message$1, ToolCall } from '@agentskit/core';
|
|
2
|
+
export { AdapterContext, AdapterFactory, AdapterRequest, ChatConfig, ChatController, ChatMemory, ChatReturn, ChatState, MaybePromise, MemoryRecord, MessageRole, MessageStatus, Message as MessageType, RetrievedDocument, Retriever, RetrieverRequest, StreamChunk, StreamSource, StreamStatus, StreamToolCallPayload, ToolCall, ToolCallHandlerContext, ToolCallStatus, ToolDefinition, ToolExecutionContext, UseStreamOptions, UseStreamReturn, createChatController, createFileMemory, createInMemoryMemory, createLocalStorageMemory, createStaticRetriever, formatRetrievedDocuments } from '@agentskit/core';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
declare function useStream(source: StreamSource, options?: UseStreamOptions): UseStreamReturn;
|
|
7
|
+
|
|
8
|
+
declare function useReactive<T extends Record<string, unknown>>(initialState: T): T;
|
|
9
|
+
|
|
10
|
+
declare function useChat(config: ChatConfig): ChatReturn;
|
|
11
|
+
|
|
12
|
+
interface ChatContainerProps {
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
declare function ChatContainer({ children, className }: ChatContainerProps): react_jsx_runtime.JSX.Element;
|
|
17
|
+
|
|
18
|
+
interface MessageProps {
|
|
19
|
+
message: Message$1;
|
|
20
|
+
avatar?: ReactNode;
|
|
21
|
+
actions?: ReactNode;
|
|
22
|
+
}
|
|
23
|
+
declare function Message({ message, avatar, actions }: MessageProps): react_jsx_runtime.JSX.Element;
|
|
24
|
+
|
|
25
|
+
interface InputBarProps {
|
|
26
|
+
chat: ChatReturn;
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
}
|
|
30
|
+
declare function InputBar({ chat, placeholder, disabled }: InputBarProps): react_jsx_runtime.JSX.Element;
|
|
31
|
+
|
|
32
|
+
interface MarkdownProps {
|
|
33
|
+
content: string;
|
|
34
|
+
streaming?: boolean;
|
|
35
|
+
}
|
|
36
|
+
declare function Markdown({ content, streaming }: MarkdownProps): react_jsx_runtime.JSX.Element;
|
|
37
|
+
|
|
38
|
+
interface CodeBlockProps {
|
|
39
|
+
code: string;
|
|
40
|
+
language?: string;
|
|
41
|
+
copyable?: boolean;
|
|
42
|
+
}
|
|
43
|
+
declare function CodeBlock({ code, language, copyable }: CodeBlockProps): react_jsx_runtime.JSX.Element;
|
|
44
|
+
|
|
45
|
+
interface ToolCallViewProps {
|
|
46
|
+
toolCall: ToolCall;
|
|
47
|
+
}
|
|
48
|
+
declare function ToolCallView({ toolCall }: ToolCallViewProps): react_jsx_runtime.JSX.Element;
|
|
49
|
+
|
|
50
|
+
interface ThinkingIndicatorProps {
|
|
51
|
+
visible: boolean;
|
|
52
|
+
label?: string;
|
|
53
|
+
}
|
|
54
|
+
declare function ThinkingIndicator({ visible, label }: ThinkingIndicatorProps): react_jsx_runtime.JSX.Element | null;
|
|
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 };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { StreamSource, UseStreamOptions, UseStreamReturn, ChatConfig, ChatReturn, Message as Message$1, ToolCall } from '@agentskit/core';
|
|
2
|
+
export { AdapterContext, AdapterFactory, AdapterRequest, ChatConfig, ChatController, ChatMemory, ChatReturn, ChatState, MaybePromise, MemoryRecord, MessageRole, MessageStatus, Message as MessageType, RetrievedDocument, Retriever, RetrieverRequest, StreamChunk, StreamSource, StreamStatus, StreamToolCallPayload, ToolCall, ToolCallHandlerContext, ToolCallStatus, ToolDefinition, ToolExecutionContext, UseStreamOptions, UseStreamReturn, createChatController, createFileMemory, createInMemoryMemory, createLocalStorageMemory, createStaticRetriever, formatRetrievedDocuments } from '@agentskit/core';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
declare function useStream(source: StreamSource, options?: UseStreamOptions): UseStreamReturn;
|
|
7
|
+
|
|
8
|
+
declare function useReactive<T extends Record<string, unknown>>(initialState: T): T;
|
|
9
|
+
|
|
10
|
+
declare function useChat(config: ChatConfig): ChatReturn;
|
|
11
|
+
|
|
12
|
+
interface ChatContainerProps {
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
declare function ChatContainer({ children, className }: ChatContainerProps): react_jsx_runtime.JSX.Element;
|
|
17
|
+
|
|
18
|
+
interface MessageProps {
|
|
19
|
+
message: Message$1;
|
|
20
|
+
avatar?: ReactNode;
|
|
21
|
+
actions?: ReactNode;
|
|
22
|
+
}
|
|
23
|
+
declare function Message({ message, avatar, actions }: MessageProps): react_jsx_runtime.JSX.Element;
|
|
24
|
+
|
|
25
|
+
interface InputBarProps {
|
|
26
|
+
chat: ChatReturn;
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
}
|
|
30
|
+
declare function InputBar({ chat, placeholder, disabled }: InputBarProps): react_jsx_runtime.JSX.Element;
|
|
31
|
+
|
|
32
|
+
interface MarkdownProps {
|
|
33
|
+
content: string;
|
|
34
|
+
streaming?: boolean;
|
|
35
|
+
}
|
|
36
|
+
declare function Markdown({ content, streaming }: MarkdownProps): react_jsx_runtime.JSX.Element;
|
|
37
|
+
|
|
38
|
+
interface CodeBlockProps {
|
|
39
|
+
code: string;
|
|
40
|
+
language?: string;
|
|
41
|
+
copyable?: boolean;
|
|
42
|
+
}
|
|
43
|
+
declare function CodeBlock({ code, language, copyable }: CodeBlockProps): react_jsx_runtime.JSX.Element;
|
|
44
|
+
|
|
45
|
+
interface ToolCallViewProps {
|
|
46
|
+
toolCall: ToolCall;
|
|
47
|
+
}
|
|
48
|
+
declare function ToolCallView({ toolCall }: ToolCallViewProps): react_jsx_runtime.JSX.Element;
|
|
49
|
+
|
|
50
|
+
interface ThinkingIndicatorProps {
|
|
51
|
+
visible: boolean;
|
|
52
|
+
label?: string;
|
|
53
|
+
}
|
|
54
|
+
declare function ThinkingIndicator({ visible, label }: ThinkingIndicatorProps): react_jsx_runtime.JSX.Element | null;
|
|
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 };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { createChatController } from '@agentskit/core';
|
|
2
|
+
export { createChatController, createFileMemory, createInMemoryMemory, createLocalStorageMemory, createStaticRetriever, formatRetrievedDocuments } from '@agentskit/core';
|
|
3
|
+
import { useState, useRef, useEffect, useCallback, useSyncExternalStore } from 'react';
|
|
4
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
// src/index.ts
|
|
7
|
+
function useStream(source, options) {
|
|
8
|
+
const [data, setData] = useState(null);
|
|
9
|
+
const [text, setText] = useState("");
|
|
10
|
+
const [status, setStatus] = useState("idle");
|
|
11
|
+
const [error, setError] = useState(null);
|
|
12
|
+
const sourceRef = useRef(source);
|
|
13
|
+
const optionsRef = useRef(options);
|
|
14
|
+
const abortedRef = useRef(false);
|
|
15
|
+
sourceRef.current = source;
|
|
16
|
+
optionsRef.current = options;
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
let cancelled = false;
|
|
19
|
+
abortedRef.current = false;
|
|
20
|
+
setStatus("streaming");
|
|
21
|
+
setText("");
|
|
22
|
+
setData(null);
|
|
23
|
+
setError(null);
|
|
24
|
+
let accumulated = "";
|
|
25
|
+
const consume = async () => {
|
|
26
|
+
try {
|
|
27
|
+
const iterator = sourceRef.current.stream();
|
|
28
|
+
for await (const chunk of iterator) {
|
|
29
|
+
if (cancelled || abortedRef.current) return;
|
|
30
|
+
setData(chunk);
|
|
31
|
+
optionsRef.current?.onChunk?.(chunk);
|
|
32
|
+
if (chunk.type === "text" && chunk.content) {
|
|
33
|
+
accumulated += chunk.content;
|
|
34
|
+
setText(accumulated);
|
|
35
|
+
} else if (chunk.type === "error") {
|
|
36
|
+
const err = new Error(chunk.content ?? "Stream error");
|
|
37
|
+
setError(err);
|
|
38
|
+
setStatus("error");
|
|
39
|
+
optionsRef.current?.onError?.(err);
|
|
40
|
+
return;
|
|
41
|
+
} else if (chunk.type === "done") {
|
|
42
|
+
setStatus("complete");
|
|
43
|
+
optionsRef.current?.onComplete?.(accumulated);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (!cancelled && !abortedRef.current) {
|
|
48
|
+
setStatus("complete");
|
|
49
|
+
optionsRef.current?.onComplete?.(accumulated);
|
|
50
|
+
}
|
|
51
|
+
} catch (err) {
|
|
52
|
+
if (!cancelled && !abortedRef.current) {
|
|
53
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
54
|
+
setError(error2);
|
|
55
|
+
setStatus("error");
|
|
56
|
+
optionsRef.current?.onError?.(error2);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
consume();
|
|
61
|
+
return () => {
|
|
62
|
+
cancelled = true;
|
|
63
|
+
};
|
|
64
|
+
}, [source]);
|
|
65
|
+
const stop = useCallback(() => {
|
|
66
|
+
abortedRef.current = true;
|
|
67
|
+
sourceRef.current.abort();
|
|
68
|
+
}, []);
|
|
69
|
+
return { data, text, status, error, stop };
|
|
70
|
+
}
|
|
71
|
+
function useReactive(initialState) {
|
|
72
|
+
const storeRef = useRef(null);
|
|
73
|
+
if (storeRef.current === null) {
|
|
74
|
+
const store2 = {
|
|
75
|
+
state: { ...initialState },
|
|
76
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
77
|
+
proxy: null,
|
|
78
|
+
version: 0
|
|
79
|
+
};
|
|
80
|
+
const notify = () => {
|
|
81
|
+
store2.version++;
|
|
82
|
+
store2.listeners.forEach((listener) => listener());
|
|
83
|
+
};
|
|
84
|
+
store2.proxy = new Proxy(store2.state, {
|
|
85
|
+
get(target, prop, receiver) {
|
|
86
|
+
return Reflect.get(target, prop, receiver);
|
|
87
|
+
},
|
|
88
|
+
set(target, prop, value, receiver) {
|
|
89
|
+
const result = Reflect.set(target, prop, value, receiver);
|
|
90
|
+
notify();
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
storeRef.current = store2;
|
|
95
|
+
}
|
|
96
|
+
const store = storeRef.current;
|
|
97
|
+
const subscribe = useCallback((callback) => {
|
|
98
|
+
store.listeners.add(callback);
|
|
99
|
+
return () => {
|
|
100
|
+
store.listeners.delete(callback);
|
|
101
|
+
};
|
|
102
|
+
}, [store]);
|
|
103
|
+
const getSnapshot = useCallback(() => store.version, [store]);
|
|
104
|
+
useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
105
|
+
return store.proxy;
|
|
106
|
+
}
|
|
107
|
+
function useChat(config) {
|
|
108
|
+
const controllerRef = useRef(null);
|
|
109
|
+
if (!controllerRef.current) {
|
|
110
|
+
controllerRef.current = createChatController(config);
|
|
111
|
+
}
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
controllerRef.current?.updateConfig(config);
|
|
114
|
+
}, [config]);
|
|
115
|
+
const state = useSyncExternalStore(
|
|
116
|
+
controllerRef.current.subscribe,
|
|
117
|
+
controllerRef.current.getState,
|
|
118
|
+
controllerRef.current.getState
|
|
119
|
+
);
|
|
120
|
+
return {
|
|
121
|
+
...state,
|
|
122
|
+
send: controllerRef.current.send,
|
|
123
|
+
stop: controllerRef.current.stop,
|
|
124
|
+
retry: controllerRef.current.retry,
|
|
125
|
+
setInput: controllerRef.current.setInput,
|
|
126
|
+
clear: controllerRef.current.clear
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function ChatContainer({ children, className }) {
|
|
130
|
+
const containerRef = useRef(null);
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
const el = containerRef.current;
|
|
133
|
+
if (!el) return;
|
|
134
|
+
const observer = new MutationObserver(() => {
|
|
135
|
+
el.scrollTop = el.scrollHeight;
|
|
136
|
+
});
|
|
137
|
+
observer.observe(el, { childList: true, subtree: true, characterData: true });
|
|
138
|
+
return () => observer.disconnect();
|
|
139
|
+
}, []);
|
|
140
|
+
return /* @__PURE__ */ jsx(
|
|
141
|
+
"div",
|
|
142
|
+
{
|
|
143
|
+
ref: containerRef,
|
|
144
|
+
"data-ak-chat-container": "",
|
|
145
|
+
"data-testid": "ak-chat-container",
|
|
146
|
+
className,
|
|
147
|
+
style: { overflow: "auto" },
|
|
148
|
+
children
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
function Message({ message, avatar, actions }) {
|
|
153
|
+
return /* @__PURE__ */ jsxs(
|
|
154
|
+
"div",
|
|
155
|
+
{
|
|
156
|
+
"data-ak-message": "",
|
|
157
|
+
"data-ak-role": message.role,
|
|
158
|
+
"data-ak-status": message.status,
|
|
159
|
+
children: [
|
|
160
|
+
avatar && /* @__PURE__ */ jsx("div", { "data-ak-avatar": "", children: avatar }),
|
|
161
|
+
/* @__PURE__ */ jsx("div", { "data-ak-content": "", children: message.content }),
|
|
162
|
+
actions && /* @__PURE__ */ jsx("div", { "data-ak-actions": "", children: actions })
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
function InputBar({ chat, placeholder = "Type a message...", disabled = false }) {
|
|
168
|
+
const handleSubmit = (e) => {
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
if (chat.input.trim()) {
|
|
171
|
+
chat.send(chat.input);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const handleKeyDown = (e) => {
|
|
175
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
if (chat.input.trim()) {
|
|
178
|
+
chat.send(chat.input);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
return /* @__PURE__ */ jsxs("form", { "data-ak-input-bar": "", onSubmit: handleSubmit, children: [
|
|
183
|
+
/* @__PURE__ */ jsx(
|
|
184
|
+
"textarea",
|
|
185
|
+
{
|
|
186
|
+
role: "textbox",
|
|
187
|
+
value: chat.input,
|
|
188
|
+
onChange: (e) => chat.setInput(e.target.value),
|
|
189
|
+
onKeyDown: handleKeyDown,
|
|
190
|
+
placeholder,
|
|
191
|
+
disabled,
|
|
192
|
+
"data-ak-input": "",
|
|
193
|
+
rows: 1
|
|
194
|
+
}
|
|
195
|
+
),
|
|
196
|
+
/* @__PURE__ */ jsx("button", { type: "submit", disabled: disabled || !chat.input.trim(), "data-ak-send": "", children: "Send" })
|
|
197
|
+
] });
|
|
198
|
+
}
|
|
199
|
+
function Markdown({ content, streaming = false }) {
|
|
200
|
+
return /* @__PURE__ */ jsx("div", { "data-ak-markdown": "", "data-ak-streaming": streaming ? "true" : void 0, children: content });
|
|
201
|
+
}
|
|
202
|
+
function CodeBlock({ code, language, copyable = false }) {
|
|
203
|
+
const handleCopy = useCallback(() => {
|
|
204
|
+
navigator.clipboard.writeText(code);
|
|
205
|
+
}, [code]);
|
|
206
|
+
return /* @__PURE__ */ jsxs("div", { "data-ak-code-block": "", "data-ak-language": language, children: [
|
|
207
|
+
/* @__PURE__ */ jsx("pre", { children: /* @__PURE__ */ jsx("code", { children: code }) }),
|
|
208
|
+
copyable && /* @__PURE__ */ jsx("button", { onClick: handleCopy, "data-ak-copy": "", type: "button", children: "Copy" })
|
|
209
|
+
] });
|
|
210
|
+
}
|
|
211
|
+
function ToolCallView({ toolCall }) {
|
|
212
|
+
const [expanded, setExpanded] = useState(false);
|
|
213
|
+
return /* @__PURE__ */ jsxs("div", { "data-ak-tool-call": "", "data-ak-tool-status": toolCall.status, children: [
|
|
214
|
+
/* @__PURE__ */ jsx(
|
|
215
|
+
"button",
|
|
216
|
+
{
|
|
217
|
+
onClick: () => setExpanded(!expanded),
|
|
218
|
+
"data-ak-tool-toggle": "",
|
|
219
|
+
type: "button",
|
|
220
|
+
children: toolCall.name
|
|
221
|
+
}
|
|
222
|
+
),
|
|
223
|
+
expanded && /* @__PURE__ */ jsxs("div", { "data-ak-tool-details": "", children: [
|
|
224
|
+
/* @__PURE__ */ jsx("pre", { "data-ak-tool-args": "", children: JSON.stringify(toolCall.args, null, 2) }),
|
|
225
|
+
toolCall.result && /* @__PURE__ */ jsx("div", { "data-ak-tool-result": "", children: toolCall.result })
|
|
226
|
+
] })
|
|
227
|
+
] });
|
|
228
|
+
}
|
|
229
|
+
function ThinkingIndicator({ visible, label = "Thinking..." }) {
|
|
230
|
+
if (!visible) return null;
|
|
231
|
+
return /* @__PURE__ */ jsxs("div", { "data-ak-thinking": "", "data-testid": "ak-thinking", children: [
|
|
232
|
+
/* @__PURE__ */ jsxs("span", { "data-ak-thinking-dots": "", children: [
|
|
233
|
+
/* @__PURE__ */ jsx("span", { children: "\u2022" }),
|
|
234
|
+
/* @__PURE__ */ jsx("span", { children: "\u2022" }),
|
|
235
|
+
/* @__PURE__ */ jsx("span", { children: "\u2022" })
|
|
236
|
+
] }),
|
|
237
|
+
/* @__PURE__ */ jsx("span", { "data-ak-thinking-label": "", children: label })
|
|
238
|
+
] });
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export { ChatContainer, CodeBlock, InputBar, Markdown, Message, ThinkingIndicator, ToolCallView, useChat, useReactive, useStream };
|
|
242
|
+
//# sourceMappingURL=index.js.map
|
|
243
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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","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,E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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>•</span><span>•</span><span>•</span>\n </span>\n <span data-ak-thinking-label=\"\">{label}</span>\n </div>\n )\n}\n"]}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
@import './tokens.css';
|
|
2
|
+
|
|
3
|
+
[data-ak-chat-container] {
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
gap: var(--ak-spacing-md);
|
|
7
|
+
padding: var(--ak-spacing-lg);
|
|
8
|
+
background: var(--ak-color-bg);
|
|
9
|
+
font-family: var(--ak-font-family);
|
|
10
|
+
font-size: var(--ak-font-size);
|
|
11
|
+
line-height: var(--ak-line-height);
|
|
12
|
+
color: var(--ak-color-text);
|
|
13
|
+
height: 100%;
|
|
14
|
+
overflow-y: auto;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
[data-ak-message] {
|
|
18
|
+
display: flex;
|
|
19
|
+
gap: var(--ak-spacing-sm);
|
|
20
|
+
max-width: 80%;
|
|
21
|
+
animation: ak-fade-in var(--ak-transition);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
[data-ak-role="user"] {
|
|
25
|
+
align-self: flex-end;
|
|
26
|
+
flex-direction: row-reverse;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
[data-ak-role="assistant"] {
|
|
30
|
+
align-self: flex-start;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
[data-ak-content] {
|
|
34
|
+
padding: var(--ak-spacing-md) var(--ak-spacing-lg);
|
|
35
|
+
border-radius: var(--ak-radius-lg);
|
|
36
|
+
word-break: break-word;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
[data-ak-role="user"] [data-ak-content] {
|
|
40
|
+
background: var(--ak-color-bubble-user);
|
|
41
|
+
color: var(--ak-color-bubble-user-text);
|
|
42
|
+
border-bottom-right-radius: var(--ak-spacing-xs);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
[data-ak-role="assistant"] [data-ak-content] {
|
|
46
|
+
background: var(--ak-color-bubble-assistant);
|
|
47
|
+
color: var(--ak-color-bubble-assistant-text);
|
|
48
|
+
border-bottom-left-radius: var(--ak-spacing-xs);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
[data-ak-avatar] {
|
|
52
|
+
width: 32px;
|
|
53
|
+
height: 32px;
|
|
54
|
+
border-radius: 50%;
|
|
55
|
+
display: flex;
|
|
56
|
+
align-items: center;
|
|
57
|
+
justify-content: center;
|
|
58
|
+
flex-shrink: 0;
|
|
59
|
+
background: var(--ak-color-surface);
|
|
60
|
+
border: 1px solid var(--ak-color-border);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
[data-ak-status="streaming"] [data-ak-content]::after {
|
|
64
|
+
content: '\2588';
|
|
65
|
+
animation: ak-blink 1s step-end infinite;
|
|
66
|
+
color: var(--ak-color-text-muted);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
[data-ak-input-bar] {
|
|
70
|
+
display: flex;
|
|
71
|
+
gap: var(--ak-spacing-sm);
|
|
72
|
+
padding: var(--ak-spacing-md);
|
|
73
|
+
background: var(--ak-color-surface);
|
|
74
|
+
border-top: 1px solid var(--ak-color-border);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
[data-ak-input] {
|
|
78
|
+
flex: 1;
|
|
79
|
+
padding: var(--ak-spacing-sm) var(--ak-spacing-md);
|
|
80
|
+
border: 1px solid var(--ak-color-input-border);
|
|
81
|
+
border-radius: var(--ak-radius);
|
|
82
|
+
background: var(--ak-color-input-bg);
|
|
83
|
+
color: var(--ak-color-text);
|
|
84
|
+
font-family: var(--ak-font-family);
|
|
85
|
+
font-size: var(--ak-font-size);
|
|
86
|
+
resize: none;
|
|
87
|
+
outline: none;
|
|
88
|
+
transition: border-color var(--ak-transition);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
[data-ak-input]:focus {
|
|
92
|
+
border-color: var(--ak-color-input-focus);
|
|
93
|
+
box-shadow: 0 0 0 3px color-mix(in srgb, var(--ak-color-input-focus) 20%, transparent);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
[data-ak-send] {
|
|
97
|
+
padding: var(--ak-spacing-sm) var(--ak-spacing-lg);
|
|
98
|
+
background: var(--ak-color-button);
|
|
99
|
+
color: var(--ak-color-button-text);
|
|
100
|
+
border: none;
|
|
101
|
+
border-radius: var(--ak-radius);
|
|
102
|
+
cursor: pointer;
|
|
103
|
+
font-family: var(--ak-font-family);
|
|
104
|
+
font-size: var(--ak-font-size);
|
|
105
|
+
font-weight: 500;
|
|
106
|
+
transition: opacity var(--ak-transition);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
[data-ak-send]:disabled {
|
|
110
|
+
opacity: 0.5;
|
|
111
|
+
cursor: not-allowed;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
[data-ak-markdown] {
|
|
115
|
+
line-height: var(--ak-line-height);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
[data-ak-code-block] {
|
|
119
|
+
position: relative;
|
|
120
|
+
border-radius: var(--ak-radius);
|
|
121
|
+
overflow: hidden;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
[data-ak-code-block] pre {
|
|
125
|
+
margin: 0;
|
|
126
|
+
padding: var(--ak-spacing-lg);
|
|
127
|
+
background: var(--ak-color-code-bg);
|
|
128
|
+
color: var(--ak-color-code-text);
|
|
129
|
+
font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
|
|
130
|
+
font-size: var(--ak-font-size-sm);
|
|
131
|
+
line-height: 1.6;
|
|
132
|
+
overflow-x: auto;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
[data-ak-copy] {
|
|
136
|
+
position: absolute;
|
|
137
|
+
top: var(--ak-spacing-sm);
|
|
138
|
+
right: var(--ak-spacing-sm);
|
|
139
|
+
padding: var(--ak-spacing-xs) var(--ak-spacing-sm);
|
|
140
|
+
background: rgba(255, 255, 255, 0.1);
|
|
141
|
+
color: var(--ak-color-code-text);
|
|
142
|
+
border: none;
|
|
143
|
+
border-radius: var(--ak-spacing-xs);
|
|
144
|
+
cursor: pointer;
|
|
145
|
+
font-size: var(--ak-font-size-sm);
|
|
146
|
+
opacity: 0;
|
|
147
|
+
transition: opacity var(--ak-transition);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
[data-ak-code-block]:hover [data-ak-copy] {
|
|
151
|
+
opacity: 1;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
[data-ak-tool-call] {
|
|
155
|
+
border: 1px solid var(--ak-color-tool-border);
|
|
156
|
+
border-radius: var(--ak-radius);
|
|
157
|
+
background: var(--ak-color-tool-bg);
|
|
158
|
+
overflow: hidden;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
[data-ak-tool-toggle] {
|
|
162
|
+
display: block;
|
|
163
|
+
width: 100%;
|
|
164
|
+
padding: var(--ak-spacing-sm) var(--ak-spacing-md);
|
|
165
|
+
background: none;
|
|
166
|
+
border: none;
|
|
167
|
+
text-align: left;
|
|
168
|
+
cursor: pointer;
|
|
169
|
+
font-family: var(--ak-font-family);
|
|
170
|
+
font-size: var(--ak-font-size-sm);
|
|
171
|
+
font-weight: 600;
|
|
172
|
+
color: inherit;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
[data-ak-tool-details] {
|
|
176
|
+
padding: var(--ak-spacing-sm) var(--ak-spacing-md);
|
|
177
|
+
border-top: 1px solid var(--ak-color-tool-border);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
[data-ak-tool-args] {
|
|
181
|
+
margin: 0;
|
|
182
|
+
font-size: var(--ak-font-size-sm);
|
|
183
|
+
font-family: monospace;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
[data-ak-thinking] {
|
|
187
|
+
display: flex;
|
|
188
|
+
align-items: center;
|
|
189
|
+
gap: var(--ak-spacing-sm);
|
|
190
|
+
padding: var(--ak-spacing-sm) var(--ak-spacing-md);
|
|
191
|
+
color: var(--ak-color-text-muted);
|
|
192
|
+
font-size: var(--ak-font-size-sm);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
[data-ak-thinking-dots] span {
|
|
196
|
+
animation: ak-blink 1.4s infinite both;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
[data-ak-thinking-dots] span:nth-child(2) {
|
|
200
|
+
animation-delay: 0.2s;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
[data-ak-thinking-dots] span:nth-child(3) {
|
|
204
|
+
animation-delay: 0.4s;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
@keyframes ak-fade-in {
|
|
208
|
+
from { opacity: 0; transform: translateY(4px); }
|
|
209
|
+
to { opacity: 1; transform: translateY(0); }
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
@keyframes ak-blink {
|
|
213
|
+
0%, 80%, 100% { opacity: 0.3; }
|
|
214
|
+
40% { opacity: 1; }
|
|
215
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--ak-color-bg: #ffffff;
|
|
3
|
+
--ak-color-surface: #f9fafb;
|
|
4
|
+
--ak-color-border: #e5e7eb;
|
|
5
|
+
--ak-color-text: #111827;
|
|
6
|
+
--ak-color-text-muted: #6b7280;
|
|
7
|
+
--ak-color-bubble-user: #2563eb;
|
|
8
|
+
--ak-color-bubble-user-text: #ffffff;
|
|
9
|
+
--ak-color-bubble-assistant: #f3f4f6;
|
|
10
|
+
--ak-color-bubble-assistant-text: #111827;
|
|
11
|
+
--ak-color-input-bg: #ffffff;
|
|
12
|
+
--ak-color-input-border: #d1d5db;
|
|
13
|
+
--ak-color-input-focus: #2563eb;
|
|
14
|
+
--ak-color-button: #2563eb;
|
|
15
|
+
--ak-color-button-text: #ffffff;
|
|
16
|
+
--ak-color-code-bg: #1f2937;
|
|
17
|
+
--ak-color-code-text: #e5e7eb;
|
|
18
|
+
--ak-color-tool-bg: #fef3c7;
|
|
19
|
+
--ak-color-tool-border: #f59e0b;
|
|
20
|
+
--ak-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
21
|
+
--ak-font-size: 14px;
|
|
22
|
+
--ak-font-size-sm: 12px;
|
|
23
|
+
--ak-font-size-lg: 16px;
|
|
24
|
+
--ak-line-height: 1.5;
|
|
25
|
+
--ak-radius: 8px;
|
|
26
|
+
--ak-radius-lg: 12px;
|
|
27
|
+
--ak-spacing-xs: 4px;
|
|
28
|
+
--ak-spacing-sm: 8px;
|
|
29
|
+
--ak-spacing-md: 12px;
|
|
30
|
+
--ak-spacing-lg: 16px;
|
|
31
|
+
--ak-spacing-xl: 24px;
|
|
32
|
+
--ak-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
|
33
|
+
--ak-transition: 150ms ease;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
[data-theme="dark"],
|
|
37
|
+
.dark {
|
|
38
|
+
--ak-color-bg: #111827;
|
|
39
|
+
--ak-color-surface: #1f2937;
|
|
40
|
+
--ak-color-border: #374151;
|
|
41
|
+
--ak-color-text: #f9fafb;
|
|
42
|
+
--ak-color-text-muted: #9ca3af;
|
|
43
|
+
--ak-color-bubble-user: #3b82f6;
|
|
44
|
+
--ak-color-bubble-user-text: #ffffff;
|
|
45
|
+
--ak-color-bubble-assistant: #1f2937;
|
|
46
|
+
--ak-color-bubble-assistant-text: #f9fafb;
|
|
47
|
+
--ak-color-input-bg: #1f2937;
|
|
48
|
+
--ak-color-input-border: #4b5563;
|
|
49
|
+
--ak-color-input-focus: #3b82f6;
|
|
50
|
+
--ak-color-button: #3b82f6;
|
|
51
|
+
--ak-color-button-text: #ffffff;
|
|
52
|
+
--ak-color-code-bg: #0f172a;
|
|
53
|
+
--ak-color-code-text: #e2e8f0;
|
|
54
|
+
--ak-color-tool-bg: #451a03;
|
|
55
|
+
--ak-color-tool-border: #d97706;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@media (prefers-color-scheme: dark) {
|
|
59
|
+
:root:not([data-theme="light"]) {
|
|
60
|
+
--ak-color-bg: #111827;
|
|
61
|
+
--ak-color-surface: #1f2937;
|
|
62
|
+
--ak-color-border: #374151;
|
|
63
|
+
--ak-color-text: #f9fafb;
|
|
64
|
+
--ak-color-text-muted: #9ca3af;
|
|
65
|
+
--ak-color-bubble-user: #3b82f6;
|
|
66
|
+
--ak-color-bubble-user-text: #ffffff;
|
|
67
|
+
--ak-color-bubble-assistant: #1f2937;
|
|
68
|
+
--ak-color-bubble-assistant-text: #f9fafb;
|
|
69
|
+
--ak-color-input-bg: #1f2937;
|
|
70
|
+
--ak-color-input-border: #4b5563;
|
|
71
|
+
--ak-color-input-focus: #3b82f6;
|
|
72
|
+
--ak-color-button: #3b82f6;
|
|
73
|
+
--ak-color-button-text: #ffffff;
|
|
74
|
+
--ak-color-code-bg: #0f172a;
|
|
75
|
+
--ak-color-code-text: #e2e8f0;
|
|
76
|
+
--ak-color-tool-bg: #451a03;
|
|
77
|
+
--ak-color-tool-border: #d97706;
|
|
78
|
+
}
|
|
79
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentskit/react",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "React hooks and UI components for AgentsKit.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./theme": "./dist/theme/default.css"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@agentskit/core": "0.4.0"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": ">=18.0.0",
|
|
25
|
+
"react-dom": ">=18.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@testing-library/jest-dom": "^6.0.0",
|
|
29
|
+
"@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",
|
|
36
|
+
"tsup": "^8.5.0",
|
|
37
|
+
"typescript": "^5.9.2",
|
|
38
|
+
"vitest": "^4.1.2"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"lint": "tsc --noEmit",
|
|
47
|
+
"dev": "tsup --watch"
|
|
48
|
+
}
|
|
49
|
+
}
|