ai.matey.react.core 0.2.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 AI Matey Contributors
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.
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ /**
3
+ * AI Matey React Core
4
+ *
5
+ * Core React hooks for building AI-powered applications.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.useObject = exports.useCompletion = exports.useChat = void 0;
11
+ // Hooks
12
+ var use_chat_js_1 = require("./use-chat.js");
13
+ Object.defineProperty(exports, "useChat", { enumerable: true, get: function () { return use_chat_js_1.useChat; } });
14
+ var use_completion_js_1 = require("./use-completion.js");
15
+ Object.defineProperty(exports, "useCompletion", { enumerable: true, get: function () { return use_completion_js_1.useCompletion; } });
16
+ var use_object_js_1 = require("./use-object.js");
17
+ Object.defineProperty(exports, "useObject", { enumerable: true, get: function () { return use_object_js_1.useObject; } });
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,QAAQ;AACR,6CAAwC;AAA/B,sGAAA,OAAO,OAAA;AAChB,yDAAoD;AAA3C,kHAAA,aAAa,OAAA;AACtB,iDAA4C;AAAnC,0GAAA,SAAS,OAAA"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /**
3
+ * React Core Types
4
+ *
5
+ * Type definitions for React hooks and utilities.
6
+ *
7
+ * @module
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG"}
@@ -0,0 +1,418 @@
1
+ "use strict";
2
+ /**
3
+ * useChat Hook
4
+ *
5
+ * React hook for building chat interfaces with streaming support.
6
+ * Supports both HTTP API mode and direct backend mode.
7
+ *
8
+ * @module
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.useChat = useChat;
12
+ const react_1 = require("react");
13
+ const ai_matey_wrapper_1 = require("ai.matey.wrapper");
14
+ /**
15
+ * Generate a unique ID.
16
+ */
17
+ function generateUniqueId() {
18
+ return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
19
+ }
20
+ /**
21
+ * Convert React Message to IR message format.
22
+ */
23
+ function messageToIR(message) {
24
+ return {
25
+ role: message.role,
26
+ content: message.content,
27
+ };
28
+ }
29
+ /**
30
+ * useChat - React hook for chat interfaces.
31
+ *
32
+ * Provides state management, streaming, and utilities for building
33
+ * chat applications with AI backends.
34
+ *
35
+ * Supports two modes:
36
+ * 1. HTTP Mode (default): Uses `api` endpoint with fetch
37
+ * 2. Direct Mode: Uses `direct.backend` for direct backend access
38
+ *
39
+ * @example HTTP Mode
40
+ * ```tsx
41
+ * import { useChat } from 'ai.matey.react.core';
42
+ *
43
+ * function ChatComponent() {
44
+ * const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat({
45
+ * api: '/api/chat',
46
+ * });
47
+ *
48
+ * return (
49
+ * <div>
50
+ * {messages.map((m) => (
51
+ * <div key={m.id}>{m.role}: {m.content}</div>
52
+ * ))}
53
+ * <form onSubmit={handleSubmit}>
54
+ * <input value={input} onChange={handleInputChange} />
55
+ * <button type="submit" disabled={isLoading}>Send</button>
56
+ * </form>
57
+ * </div>
58
+ * );
59
+ * }
60
+ * ```
61
+ *
62
+ * @example Direct Mode
63
+ * ```tsx
64
+ * import { useChat } from 'ai.matey.react.core';
65
+ * import { AnthropicBackend } from 'ai.matey.backend/anthropic';
66
+ *
67
+ * const backend = new AnthropicBackend({ apiKey: process.env.ANTHROPIC_API_KEY });
68
+ *
69
+ * function ChatComponent() {
70
+ * const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat({
71
+ * direct: {
72
+ * backend,
73
+ * systemPrompt: 'You are a helpful assistant.',
74
+ * },
75
+ * });
76
+ *
77
+ * return (
78
+ * <div>
79
+ * {messages.map((m) => (
80
+ * <div key={m.id}>{m.role}: {m.content}</div>
81
+ * ))}
82
+ * <form onSubmit={handleSubmit}>
83
+ * <input value={input} onChange={handleInputChange} />
84
+ * <button type="submit" disabled={isLoading}>Send</button>
85
+ * </form>
86
+ * </div>
87
+ * );
88
+ * }
89
+ * ```
90
+ */
91
+ function useChat(options = {}) {
92
+ const { initialMessages = [], initialInput = '', id,
93
+ // HTTP mode options
94
+ api = '/api/chat', headers = {}, body = {}, streamProtocol = 'data', onResponse,
95
+ // Direct mode options
96
+ direct,
97
+ // Common options
98
+ generateId = generateUniqueId, onFinish, onError, keepLastMessageOnError = true, maxToolRoundtrips = 0, sendExtraMessageFields = false, } = options;
99
+ // Determine mode
100
+ const isDirectMode = !!direct;
101
+ // Generate a stable ID for this chat instance
102
+ const hookId = (0, react_1.useId)();
103
+ const chatId = id ?? hookId;
104
+ // State
105
+ const [messages, setMessages] = (0, react_1.useState)(initialMessages);
106
+ const [input, setInput] = (0, react_1.useState)(initialInput);
107
+ const [isLoading, setIsLoading] = (0, react_1.useState)(false);
108
+ const [error, setError] = (0, react_1.useState)(undefined);
109
+ const [data, _setData] = (0, react_1.useState)(undefined);
110
+ // Refs
111
+ const abortControllerRef = (0, react_1.useRef)(null);
112
+ const chatRef = (0, react_1.useRef)(null);
113
+ // Create Chat instance for direct mode
114
+ (0, react_1.useEffect)(() => {
115
+ if (isDirectMode && direct) {
116
+ chatRef.current = (0, ai_matey_wrapper_1.createChat)({
117
+ backend: direct.backend,
118
+ systemPrompt: direct.systemPrompt,
119
+ defaultParameters: direct.defaultParameters,
120
+ tools: direct.tools,
121
+ onToolCall: direct.onToolCall,
122
+ autoExecuteTools: direct.autoExecuteTools,
123
+ maxToolRounds: direct.maxToolRounds ?? maxToolRoundtrips,
124
+ });
125
+ }
126
+ return () => {
127
+ chatRef.current = null;
128
+ };
129
+ }, [isDirectMode, direct, maxToolRoundtrips]);
130
+ /**
131
+ * Handle input change from form elements.
132
+ */
133
+ const handleInputChange = (0, react_1.useCallback)((e) => {
134
+ setInput(e.target.value);
135
+ }, []);
136
+ /**
137
+ * Stop current streaming request.
138
+ */
139
+ const stop = (0, react_1.useCallback)(() => {
140
+ if (abortControllerRef.current) {
141
+ abortControllerRef.current.abort();
142
+ abortControllerRef.current = null;
143
+ }
144
+ }, []);
145
+ /**
146
+ * Send request in direct mode using wrapper-ir Chat.
147
+ */
148
+ const sendDirectRequest = (0, react_1.useCallback)(async (messagesToSend, _requestOptions) => {
149
+ const chat = chatRef.current;
150
+ if (!chat) {
151
+ throw new Error('Chat instance not initialized');
152
+ }
153
+ try {
154
+ setIsLoading(true);
155
+ setError(undefined);
156
+ // Create abort controller
157
+ abortControllerRef.current = new AbortController();
158
+ const { signal } = abortControllerRef.current;
159
+ // Clear chat and restore messages
160
+ chat.clear();
161
+ for (const msg of messagesToSend.slice(0, -1)) {
162
+ chat.addMessage(messageToIR(msg));
163
+ }
164
+ // Get the last user message content
165
+ const lastMessage = messagesToSend[messagesToSend.length - 1];
166
+ if (!lastMessage || lastMessage.role !== 'user') {
167
+ throw new Error('Last message must be a user message');
168
+ }
169
+ // Add placeholder assistant message
170
+ const assistantId = generateId();
171
+ const assistantMessage = {
172
+ id: assistantId,
173
+ role: 'assistant',
174
+ content: '',
175
+ createdAt: new Date(),
176
+ };
177
+ setMessages((prev) => [...prev, assistantMessage]);
178
+ // Stream the response
179
+ const response = await chat.stream(lastMessage.content, {
180
+ signal,
181
+ onChunk: ({ accumulated }) => {
182
+ setMessages((prev) => prev.map((msg) => (msg.id === assistantId ? { ...msg, content: accumulated } : msg)));
183
+ },
184
+ });
185
+ // Finalize message
186
+ const finalMessage = {
187
+ id: assistantId,
188
+ role: 'assistant',
189
+ content: response.content,
190
+ createdAt: new Date(),
191
+ };
192
+ setMessages((prev) => prev.map((msg) => (msg.id === assistantId ? finalMessage : msg)));
193
+ onFinish?.(finalMessage);
194
+ return response.content;
195
+ }
196
+ catch (err) {
197
+ if (err instanceof Error && err.name === 'AbortError') {
198
+ return null;
199
+ }
200
+ const error = err instanceof Error ? err : new Error(String(err));
201
+ setError(error);
202
+ onError?.(error);
203
+ if (!keepLastMessageOnError) {
204
+ setMessages((prev) => prev.slice(0, -1));
205
+ }
206
+ return undefined;
207
+ }
208
+ finally {
209
+ setIsLoading(false);
210
+ abortControllerRef.current = null;
211
+ }
212
+ }, [generateId, onFinish, onError, keepLastMessageOnError]);
213
+ /**
214
+ * Send request in HTTP mode using fetch.
215
+ */
216
+ const sendHttpRequest = (0, react_1.useCallback)(async (messagesToSend, requestOptions) => {
217
+ try {
218
+ setIsLoading(true);
219
+ setError(undefined);
220
+ // Create abort controller
221
+ abortControllerRef.current = new AbortController();
222
+ const { signal } = abortControllerRef.current;
223
+ // Prepare request body
224
+ const requestBody = {
225
+ messages: sendExtraMessageFields
226
+ ? messagesToSend
227
+ : messagesToSend.map(({ role, content }) => ({ role, content })),
228
+ id: chatId,
229
+ ...body,
230
+ ...requestOptions?.body,
231
+ };
232
+ // Make request
233
+ const response = await fetch(api, {
234
+ method: 'POST',
235
+ headers: {
236
+ 'Content-Type': 'application/json',
237
+ ...headers,
238
+ ...requestOptions?.headers,
239
+ },
240
+ body: JSON.stringify(requestBody),
241
+ signal,
242
+ });
243
+ // Call onResponse callback
244
+ onResponse?.(response);
245
+ if (!response.ok) {
246
+ throw new Error(`HTTP error! status: ${response.status}`);
247
+ }
248
+ if (!response.body) {
249
+ throw new Error('Response body is null');
250
+ }
251
+ // Handle streaming response
252
+ const reader = response.body.getReader();
253
+ const decoder = new TextDecoder();
254
+ let assistantContent = '';
255
+ const assistantId = generateId();
256
+ // Add placeholder message
257
+ const assistantMessage = {
258
+ id: assistantId,
259
+ role: 'assistant',
260
+ content: '',
261
+ createdAt: new Date(),
262
+ };
263
+ setMessages((prev) => [...prev, assistantMessage]);
264
+ // Read stream
265
+ while (true) {
266
+ const { done, value } = await reader.read();
267
+ if (done) {
268
+ break;
269
+ }
270
+ const chunk = decoder.decode(value, { stream: true });
271
+ if (streamProtocol === 'data') {
272
+ // Parse SSE data format
273
+ const lines = chunk.split('\n');
274
+ for (const line of lines) {
275
+ if (line.startsWith('data: ')) {
276
+ const data = line.slice(6);
277
+ if (data === '[DONE]') {
278
+ break;
279
+ }
280
+ try {
281
+ const parsed = JSON.parse(data);
282
+ if (parsed.content) {
283
+ assistantContent += parsed.content;
284
+ }
285
+ else if (parsed.choices?.[0]?.delta?.content) {
286
+ assistantContent += parsed.choices[0].delta.content;
287
+ }
288
+ }
289
+ catch {
290
+ // Ignore parse errors for incomplete JSON
291
+ }
292
+ }
293
+ }
294
+ }
295
+ else {
296
+ // Raw text protocol
297
+ assistantContent += chunk;
298
+ }
299
+ // Update message content
300
+ setMessages((prev) => prev.map((msg) => msg.id === assistantId ? { ...msg, content: assistantContent } : msg));
301
+ }
302
+ // Finalize message
303
+ const finalMessage = {
304
+ id: assistantId,
305
+ role: 'assistant',
306
+ content: assistantContent,
307
+ createdAt: new Date(),
308
+ };
309
+ setMessages((prev) => prev.map((msg) => (msg.id === assistantId ? finalMessage : msg)));
310
+ onFinish?.(finalMessage);
311
+ return assistantContent;
312
+ }
313
+ catch (err) {
314
+ if (err instanceof Error && err.name === 'AbortError') {
315
+ // Request was aborted, not an error
316
+ return null;
317
+ }
318
+ const error = err instanceof Error ? err : new Error(String(err));
319
+ setError(error);
320
+ onError?.(error);
321
+ if (!keepLastMessageOnError) {
322
+ // Remove the last user message on error
323
+ setMessages((prev) => prev.slice(0, -1));
324
+ }
325
+ return undefined;
326
+ }
327
+ finally {
328
+ setIsLoading(false);
329
+ abortControllerRef.current = null;
330
+ }
331
+ }, [
332
+ api,
333
+ body,
334
+ chatId,
335
+ generateId,
336
+ headers,
337
+ keepLastMessageOnError,
338
+ onError,
339
+ onFinish,
340
+ onResponse,
341
+ sendExtraMessageFields,
342
+ streamProtocol,
343
+ ]);
344
+ /**
345
+ * Send request using the appropriate mode.
346
+ */
347
+ const sendRequest = (0, react_1.useCallback)(async (messagesToSend, requestOptions) => {
348
+ return isDirectMode
349
+ ? sendDirectRequest(messagesToSend, requestOptions)
350
+ : sendHttpRequest(messagesToSend, requestOptions);
351
+ }, [isDirectMode, sendDirectRequest, sendHttpRequest]);
352
+ /**
353
+ * Append a message and send.
354
+ */
355
+ const append = (0, react_1.useCallback)(async (message, options) => {
356
+ const newMessage = typeof message === 'string'
357
+ ? {
358
+ id: generateId(),
359
+ role: 'user',
360
+ content: message,
361
+ createdAt: new Date(),
362
+ }
363
+ : message;
364
+ const newMessages = [...messages, newMessage];
365
+ setMessages(newMessages);
366
+ return sendRequest(newMessages, options);
367
+ }, [generateId, messages, sendRequest]);
368
+ /**
369
+ * Handle form submission.
370
+ */
371
+ const handleSubmit = (0, react_1.useCallback)((e, options) => {
372
+ e?.preventDefault();
373
+ if (!input.trim()) {
374
+ return;
375
+ }
376
+ const userMessage = {
377
+ id: generateId(),
378
+ role: 'user',
379
+ content: input,
380
+ createdAt: new Date(),
381
+ };
382
+ const newMessages = [...messages, userMessage];
383
+ setMessages(newMessages);
384
+ setInput('');
385
+ sendRequest(newMessages, options);
386
+ }, [generateId, input, messages, sendRequest]);
387
+ /**
388
+ * Reload the last assistant message.
389
+ */
390
+ const reload = (0, react_1.useCallback)(async (options) => {
391
+ if (messages.length === 0) {
392
+ return null;
393
+ }
394
+ // Find messages up to the last user message
395
+ const lastUserIndex = messages.findLastIndex((m) => m.role === 'user');
396
+ if (lastUserIndex === -1) {
397
+ return null;
398
+ }
399
+ const messagesToReload = messages.slice(0, lastUserIndex + 1);
400
+ setMessages(messagesToReload);
401
+ return sendRequest(messagesToReload, options);
402
+ }, [messages, sendRequest]);
403
+ return {
404
+ messages,
405
+ input,
406
+ setInput,
407
+ handleInputChange,
408
+ handleSubmit,
409
+ append,
410
+ reload,
411
+ stop,
412
+ setMessages,
413
+ isLoading,
414
+ error,
415
+ data,
416
+ };
417
+ }
418
+ //# sourceMappingURL=use-chat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-chat.js","sourceRoot":"","sources":["../../src/use-chat.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAsFH,0BA6aC;AAjgBD,iCAAwE;AACxE,uDAAoD;AAIpD;;GAEG;AACH,SAAS,gBAAgB;IACvB,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;AACnE,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,OAAgB;IACnC,OAAO;QACL,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,OAAO,EAAE,OAAO,CAAC,OAAO;KAC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