@aizu-chat/react 0.1.1 → 0.1.3

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.
@@ -0,0 +1,17 @@
1
+ 'use client'
2
+ import {
3
+ AizuChat,
4
+ Button,
5
+ Loading,
6
+ QuickMenus,
7
+ TestComponent
8
+ } from "./chunk-XEQE67X7.mjs";
9
+ import "./chunk-NBQP747C.mjs";
10
+ import "./chunk-33CPD3DF.mjs";
11
+ export {
12
+ AizuChat,
13
+ Button,
14
+ Loading,
15
+ QuickMenus,
16
+ TestComponent
17
+ };
@@ -0,0 +1,6 @@
1
+ declare const useCustom: () => {
2
+ count: number;
3
+ increment: () => void;
4
+ };
5
+
6
+ export { useCustom };
@@ -0,0 +1,6 @@
1
+ declare const useCustom: () => {
2
+ count: number;
3
+ increment: () => void;
4
+ };
5
+
6
+ export { useCustom };
package/dist/hooks.js ADDED
@@ -0,0 +1,40 @@
1
+ 'use client'
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/hooks/index.ts
22
+ var hooks_exports = {};
23
+ __export(hooks_exports, {
24
+ useCustom: () => useCustom
25
+ });
26
+ module.exports = __toCommonJS(hooks_exports);
27
+
28
+ // src/hooks/use-custom.ts
29
+ var import_react = require("react");
30
+ var useCustom = () => {
31
+ const [count, setCount] = (0, import_react.useState)(0);
32
+ const increment = () => {
33
+ setCount(count + 1);
34
+ };
35
+ return { count, increment };
36
+ };
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ useCustom
40
+ });
package/dist/hooks.mjs ADDED
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ import {
3
+ useCustom
4
+ } from "./chunk-KLPKNMIP.mjs";
5
+ import "./chunk-33CPD3DF.mjs";
6
+ export {
7
+ useCustom
8
+ };
package/dist/index.d.mts CHANGED
@@ -39,16 +39,162 @@ declare enum TypeResponse {
39
39
  START_SHOPPING = "start_shopping"
40
40
  }
41
41
 
42
+ /**
43
+ * Aizu Chat API Client
44
+ *
45
+ * A client for interacting with the Aizu Chat API. Handles authentication,
46
+ * request timeouts, and error handling automatically.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const client = new AizuClient({
51
+ * hostUrl: 'https://api.aizu.chat',
52
+ * apiKey: 'your-api-key',
53
+ * timeout: 30000
54
+ * });
55
+ *
56
+ * const response = await client.chat({
57
+ * query: 'Hello, how are you?',
58
+ * conversationId: 'optional-conversation-id'
59
+ * });
60
+ * ```
61
+ */
42
62
  declare class AizuClient {
43
63
  private hostUrl;
44
64
  private apiKey;
45
65
  private timeout;
66
+ /**
67
+ * Creates a new AizuClient instance
68
+ *
69
+ * @param config - Configuration options for the client
70
+ * @param config.hostUrl - The base URL of the Aizu API (e.g., 'https://api.aizu.chat')
71
+ * @param config.apiKey - Your API key for authentication
72
+ * @param config.timeout - Request timeout in milliseconds (default: 30000)
73
+ *
74
+ * @throws {Error} If hostUrl is not a non-empty string
75
+ * @throws {Error} If apiKey is not a non-empty string
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const client = new AizuClient({
80
+ * hostUrl: 'https://api.aizu.chat',
81
+ * apiKey: 'sk_test_123456',
82
+ * timeout: 60000 // 60 seconds
83
+ * });
84
+ * ```
85
+ */
46
86
  constructor(config: AizuClientConfig);
87
+ /**
88
+ * Internal method for making HTTP requests to the API
89
+ *
90
+ * Handles timeout management, abort signal combination, and error handling.
91
+ * Supports both user-initiated cancellation and automatic timeout.
92
+ *
93
+ * @template T - The expected response type
94
+ * @template TBody - The request body type
95
+ *
96
+ * @param path - API endpoint path (e.g., '/chat/query')
97
+ * @param options - Request options including body and signal
98
+ *
99
+ * @returns Promise resolving to the API response
100
+ *
101
+ * @throws {Error} "Request cancelled by user" - If the request is cancelled via AbortSignal
102
+ * @throws {Error} "Request timeout: The server took too long to respond" - If the request exceeds the timeout
103
+ * @throws {Error} "API Error: {status} {statusText}" - If the API returns an error status
104
+ *
105
+ * @private
106
+ */
47
107
  private request;
108
+ /**
109
+ * Sends a chat query to the Aizu API
110
+ *
111
+ * @param params - Chat request parameters
112
+ * @param params.query - The user's message/question (required, non-empty)
113
+ * @param params.conversationId - Optional conversation ID to continue an existing conversation
114
+ * @param options - Additional options
115
+ * @param options.signal - Optional AbortSignal to cancel the request
116
+ *
117
+ * @returns Promise resolving to the chat response from the API
118
+ *
119
+ * @throws {Error} "Query is required" - If query is empty or whitespace only
120
+ * @throws {Error} "Request cancelled by user" - If the request is cancelled
121
+ * @throws {Error} "Request timeout: The server took too long to respond" - If the request times out
122
+ * @throws {Error} "API Error: {status} {statusText}" - If the API returns an error
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * // Simple query
127
+ * const response = await client.chat({
128
+ * query: 'What is the weather today?'
129
+ * });
130
+ * console.log(response.answer);
131
+ * ```
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * // Continue conversation
136
+ * const response1 = await client.chat({
137
+ * query: 'What is the weather today?'
138
+ * });
139
+ *
140
+ * const response2 = await client.chat({
141
+ * query: 'And tomorrow?',
142
+ * conversationId: response1.conversationId
143
+ * });
144
+ * ```
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // With cancellation support
149
+ * const controller = new AbortController();
150
+ *
151
+ * const promise = client.chat(
152
+ * { query: 'Long running query...' },
153
+ * { signal: controller.signal }
154
+ * );
155
+ *
156
+ * // Cancel after 5 seconds
157
+ * setTimeout(() => controller.abort(), 5000);
158
+ *
159
+ * try {
160
+ * const response = await promise;
161
+ * } catch (error) {
162
+ * console.error('Request was cancelled:', error);
163
+ * }
164
+ * ```
165
+ */
48
166
  chat(params: ChatRequest, options?: {
49
167
  signal?: AbortSignal;
50
168
  }): Promise<ChatResponse>;
51
169
  }
170
+ /**
171
+ * Factory function to create a new AizuClient instance
172
+ *
173
+ * This is a convenience function that wraps the AizuClient constructor.
174
+ * Use this when you prefer a functional approach over instantiating the class directly.
175
+ *
176
+ * @param config - Configuration options for the client
177
+ * @param config.hostUrl - The base URL of the Aizu API
178
+ * @param config.apiKey - Your API key for authentication
179
+ * @param config.timeout - Optional request timeout in milliseconds (default: 30000)
180
+ *
181
+ * @returns A new AizuClient instance
182
+ *
183
+ * @throws {Error} If hostUrl or apiKey are invalid
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * const client = createAizuClient({
188
+ * hostUrl: process.env.AIZU_HOST_URL!,
189
+ * apiKey: process.env.AIZU_API_KEY!,
190
+ * timeout: 45000
191
+ * });
192
+ *
193
+ * const response = await client.chat({
194
+ * query: 'Hello!'
195
+ * });
196
+ * ```
197
+ */
52
198
  declare const createAizuClient: ({ hostUrl, apiKey, timeout, }: {
53
199
  hostUrl: string;
54
200
  apiKey: string;
package/dist/index.d.ts CHANGED
@@ -39,16 +39,162 @@ declare enum TypeResponse {
39
39
  START_SHOPPING = "start_shopping"
40
40
  }
41
41
 
42
+ /**
43
+ * Aizu Chat API Client
44
+ *
45
+ * A client for interacting with the Aizu Chat API. Handles authentication,
46
+ * request timeouts, and error handling automatically.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const client = new AizuClient({
51
+ * hostUrl: 'https://api.aizu.chat',
52
+ * apiKey: 'your-api-key',
53
+ * timeout: 30000
54
+ * });
55
+ *
56
+ * const response = await client.chat({
57
+ * query: 'Hello, how are you?',
58
+ * conversationId: 'optional-conversation-id'
59
+ * });
60
+ * ```
61
+ */
42
62
  declare class AizuClient {
43
63
  private hostUrl;
44
64
  private apiKey;
45
65
  private timeout;
66
+ /**
67
+ * Creates a new AizuClient instance
68
+ *
69
+ * @param config - Configuration options for the client
70
+ * @param config.hostUrl - The base URL of the Aizu API (e.g., 'https://api.aizu.chat')
71
+ * @param config.apiKey - Your API key for authentication
72
+ * @param config.timeout - Request timeout in milliseconds (default: 30000)
73
+ *
74
+ * @throws {Error} If hostUrl is not a non-empty string
75
+ * @throws {Error} If apiKey is not a non-empty string
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const client = new AizuClient({
80
+ * hostUrl: 'https://api.aizu.chat',
81
+ * apiKey: 'sk_test_123456',
82
+ * timeout: 60000 // 60 seconds
83
+ * });
84
+ * ```
85
+ */
46
86
  constructor(config: AizuClientConfig);
87
+ /**
88
+ * Internal method for making HTTP requests to the API
89
+ *
90
+ * Handles timeout management, abort signal combination, and error handling.
91
+ * Supports both user-initiated cancellation and automatic timeout.
92
+ *
93
+ * @template T - The expected response type
94
+ * @template TBody - The request body type
95
+ *
96
+ * @param path - API endpoint path (e.g., '/chat/query')
97
+ * @param options - Request options including body and signal
98
+ *
99
+ * @returns Promise resolving to the API response
100
+ *
101
+ * @throws {Error} "Request cancelled by user" - If the request is cancelled via AbortSignal
102
+ * @throws {Error} "Request timeout: The server took too long to respond" - If the request exceeds the timeout
103
+ * @throws {Error} "API Error: {status} {statusText}" - If the API returns an error status
104
+ *
105
+ * @private
106
+ */
47
107
  private request;
108
+ /**
109
+ * Sends a chat query to the Aizu API
110
+ *
111
+ * @param params - Chat request parameters
112
+ * @param params.query - The user's message/question (required, non-empty)
113
+ * @param params.conversationId - Optional conversation ID to continue an existing conversation
114
+ * @param options - Additional options
115
+ * @param options.signal - Optional AbortSignal to cancel the request
116
+ *
117
+ * @returns Promise resolving to the chat response from the API
118
+ *
119
+ * @throws {Error} "Query is required" - If query is empty or whitespace only
120
+ * @throws {Error} "Request cancelled by user" - If the request is cancelled
121
+ * @throws {Error} "Request timeout: The server took too long to respond" - If the request times out
122
+ * @throws {Error} "API Error: {status} {statusText}" - If the API returns an error
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * // Simple query
127
+ * const response = await client.chat({
128
+ * query: 'What is the weather today?'
129
+ * });
130
+ * console.log(response.answer);
131
+ * ```
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * // Continue conversation
136
+ * const response1 = await client.chat({
137
+ * query: 'What is the weather today?'
138
+ * });
139
+ *
140
+ * const response2 = await client.chat({
141
+ * query: 'And tomorrow?',
142
+ * conversationId: response1.conversationId
143
+ * });
144
+ * ```
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // With cancellation support
149
+ * const controller = new AbortController();
150
+ *
151
+ * const promise = client.chat(
152
+ * { query: 'Long running query...' },
153
+ * { signal: controller.signal }
154
+ * );
155
+ *
156
+ * // Cancel after 5 seconds
157
+ * setTimeout(() => controller.abort(), 5000);
158
+ *
159
+ * try {
160
+ * const response = await promise;
161
+ * } catch (error) {
162
+ * console.error('Request was cancelled:', error);
163
+ * }
164
+ * ```
165
+ */
48
166
  chat(params: ChatRequest, options?: {
49
167
  signal?: AbortSignal;
50
168
  }): Promise<ChatResponse>;
51
169
  }
170
+ /**
171
+ * Factory function to create a new AizuClient instance
172
+ *
173
+ * This is a convenience function that wraps the AizuClient constructor.
174
+ * Use this when you prefer a functional approach over instantiating the class directly.
175
+ *
176
+ * @param config - Configuration options for the client
177
+ * @param config.hostUrl - The base URL of the Aizu API
178
+ * @param config.apiKey - Your API key for authentication
179
+ * @param config.timeout - Optional request timeout in milliseconds (default: 30000)
180
+ *
181
+ * @returns A new AizuClient instance
182
+ *
183
+ * @throws {Error} If hostUrl or apiKey are invalid
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * const client = createAizuClient({
188
+ * hostUrl: process.env.AIZU_HOST_URL!,
189
+ * apiKey: process.env.AIZU_API_KEY!,
190
+ * timeout: 45000
191
+ * });
192
+ *
193
+ * const response = await client.chat({
194
+ * query: 'Hello!'
195
+ * });
196
+ * ```
197
+ */
52
198
  declare const createAizuClient: ({ hostUrl, apiKey, timeout, }: {
53
199
  hostUrl: string;
54
200
  apiKey: string;
package/dist/index.js CHANGED
@@ -1024,6 +1024,26 @@ var useChatContext = () => {
1024
1024
 
1025
1025
  // src/sdk/client.ts
1026
1026
  var AizuClient = class {
1027
+ /**
1028
+ * Creates a new AizuClient instance
1029
+ *
1030
+ * @param config - Configuration options for the client
1031
+ * @param config.hostUrl - The base URL of the Aizu API (e.g., 'https://api.aizu.chat')
1032
+ * @param config.apiKey - Your API key for authentication
1033
+ * @param config.timeout - Request timeout in milliseconds (default: 30000)
1034
+ *
1035
+ * @throws {Error} If hostUrl is not a non-empty string
1036
+ * @throws {Error} If apiKey is not a non-empty string
1037
+ *
1038
+ * @example
1039
+ * ```typescript
1040
+ * const client = new AizuClient({
1041
+ * hostUrl: 'https://api.aizu.chat',
1042
+ * apiKey: 'sk_test_123456',
1043
+ * timeout: 60000 // 60 seconds
1044
+ * });
1045
+ * ```
1046
+ */
1027
1047
  constructor(config) {
1028
1048
  const { hostUrl, apiKey, timeout } = config;
1029
1049
  if (typeof hostUrl !== "string" || hostUrl.trim().length === 0) {
@@ -1040,6 +1060,26 @@ var AizuClient = class {
1040
1060
  this.apiKey = apiKey;
1041
1061
  this.timeout = timeout != null ? timeout : 3e4;
1042
1062
  }
1063
+ /**
1064
+ * Internal method for making HTTP requests to the API
1065
+ *
1066
+ * Handles timeout management, abort signal combination, and error handling.
1067
+ * Supports both user-initiated cancellation and automatic timeout.
1068
+ *
1069
+ * @template T - The expected response type
1070
+ * @template TBody - The request body type
1071
+ *
1072
+ * @param path - API endpoint path (e.g., '/chat/query')
1073
+ * @param options - Request options including body and signal
1074
+ *
1075
+ * @returns Promise resolving to the API response
1076
+ *
1077
+ * @throws {Error} "Request cancelled by user" - If the request is cancelled via AbortSignal
1078
+ * @throws {Error} "Request timeout: The server took too long to respond" - If the request exceeds the timeout
1079
+ * @throws {Error} "API Error: {status} {statusText}" - If the API returns an error status
1080
+ *
1081
+ * @private
1082
+ */
1043
1083
  request(_0) {
1044
1084
  return __async(this, arguments, function* (path, options = {}) {
1045
1085
  const url = `${this.hostUrl}${path}`;
@@ -1110,6 +1150,64 @@ var AizuClient = class {
1110
1150
  }
1111
1151
  });
1112
1152
  }
1153
+ /**
1154
+ * Sends a chat query to the Aizu API
1155
+ *
1156
+ * @param params - Chat request parameters
1157
+ * @param params.query - The user's message/question (required, non-empty)
1158
+ * @param params.conversationId - Optional conversation ID to continue an existing conversation
1159
+ * @param options - Additional options
1160
+ * @param options.signal - Optional AbortSignal to cancel the request
1161
+ *
1162
+ * @returns Promise resolving to the chat response from the API
1163
+ *
1164
+ * @throws {Error} "Query is required" - If query is empty or whitespace only
1165
+ * @throws {Error} "Request cancelled by user" - If the request is cancelled
1166
+ * @throws {Error} "Request timeout: The server took too long to respond" - If the request times out
1167
+ * @throws {Error} "API Error: {status} {statusText}" - If the API returns an error
1168
+ *
1169
+ * @example
1170
+ * ```typescript
1171
+ * // Simple query
1172
+ * const response = await client.chat({
1173
+ * query: 'What is the weather today?'
1174
+ * });
1175
+ * console.log(response.answer);
1176
+ * ```
1177
+ *
1178
+ * @example
1179
+ * ```typescript
1180
+ * // Continue conversation
1181
+ * const response1 = await client.chat({
1182
+ * query: 'What is the weather today?'
1183
+ * });
1184
+ *
1185
+ * const response2 = await client.chat({
1186
+ * query: 'And tomorrow?',
1187
+ * conversationId: response1.conversationId
1188
+ * });
1189
+ * ```
1190
+ *
1191
+ * @example
1192
+ * ```typescript
1193
+ * // With cancellation support
1194
+ * const controller = new AbortController();
1195
+ *
1196
+ * const promise = client.chat(
1197
+ * { query: 'Long running query...' },
1198
+ * { signal: controller.signal }
1199
+ * );
1200
+ *
1201
+ * // Cancel after 5 seconds
1202
+ * setTimeout(() => controller.abort(), 5000);
1203
+ *
1204
+ * try {
1205
+ * const response = await promise;
1206
+ * } catch (error) {
1207
+ * console.error('Request was cancelled:', error);
1208
+ * }
1209
+ * ```
1210
+ */
1113
1211
  chat(params, options) {
1114
1212
  return __async(this, null, function* () {
1115
1213
  if (!params.query.trim()) {
@@ -1224,12 +1322,15 @@ var import_react9 = require("react");
1224
1322
 
1225
1323
  // src/hooks/use-keyboard.ts
1226
1324
  var import_react7 = require("react");
1325
+ var MAX_LENGTH = 300;
1227
1326
  var useKeyboard = ({ userMessages, isLoading, onSend }) => {
1228
1327
  const [value, setValue] = (0, import_react7.useState)("");
1229
1328
  const [historyIndex, setHistoryIndex] = (0, import_react7.useState)((userMessages == null ? void 0 : userMessages.length) || 0);
1230
1329
  const textareaRef = (0, import_react7.useRef)(null);
1231
1330
  const handleChange = (e) => {
1232
- setValue(e.target.value);
1331
+ const currentValue = e.target.value;
1332
+ const truncatedValue = currentValue.length > MAX_LENGTH ? currentValue.slice(0, MAX_LENGTH) : currentValue;
1333
+ setValue(truncatedValue);
1233
1334
  };
1234
1335
  const handleSubmit = (e) => {
1235
1336
  e.preventDefault();
@@ -1253,17 +1354,21 @@ var useKeyboard = ({ userMessages, isLoading, onSend }) => {
1253
1354
  if (key === "ArrowUp") {
1254
1355
  e.preventDefault();
1255
1356
  if (userMessages.length === 0) return;
1256
- const next = historyIndex === userMessages.length ? userMessages.length - 1 : Math.max(0, historyIndex - 1);
1257
- setHistoryIndex(next);
1258
- setValue((_b = (_a = userMessages[next]) == null ? void 0 : _a.text) != null ? _b : "");
1357
+ const nextIndex = historyIndex === userMessages.length ? userMessages.length - 1 : Math.max(0, historyIndex - 1);
1358
+ setHistoryIndex(nextIndex);
1359
+ const nextValue = (_b = (_a = userMessages[nextIndex]) == null ? void 0 : _a.text) != null ? _b : "";
1360
+ const truncatedValue = nextValue.slice(0, MAX_LENGTH);
1361
+ setValue(truncatedValue);
1259
1362
  return;
1260
1363
  }
1261
1364
  if (key === "ArrowDown") {
1262
1365
  e.preventDefault();
1263
1366
  if (userMessages.length === 0) return;
1264
- const next = historyIndex >= userMessages.length - 1 ? userMessages.length : historyIndex + 1;
1265
- setHistoryIndex(next);
1266
- setValue(next === userMessages.length ? "" : (_d = (_c = userMessages[next]) == null ? void 0 : _c.text) != null ? _d : "");
1367
+ const nextIndex = historyIndex >= userMessages.length - 1 ? userMessages.length : historyIndex + 1;
1368
+ setHistoryIndex(nextIndex);
1369
+ const nextValue = nextIndex === userMessages.length ? "" : (_d = (_c = userMessages[nextIndex]) == null ? void 0 : _c.text) != null ? _d : "";
1370
+ const truncatedValue = nextValue.slice(0, MAX_LENGTH);
1371
+ setValue(truncatedValue);
1267
1372
  }
1268
1373
  };
1269
1374
  const adjustTextareaHeight = (0, import_react7.useCallback)(() => {