@aizu-chat/react 0.1.2 → 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.
- package/dist/chunk-33CPD3DF.mjs +59 -0
- package/dist/chunk-KLPKNMIP.mjs +15 -0
- package/dist/chunk-NBQP747C.mjs +130 -0
- package/dist/chunk-XEQE67X7.mjs +1858 -0
- package/dist/components.d.mts +69 -0
- package/dist/components.d.ts +69 -0
- package/dist/components.js +1922 -0
- package/dist/components.mjs +17 -0
- package/dist/hooks.d.mts +6 -0
- package/dist/hooks.d.ts +6 -0
- package/dist/hooks.js +40 -0
- package/dist/hooks.mjs +8 -0
- package/dist/index.d.mts +146 -0
- package/dist/index.d.ts +146 -0
- package/dist/index.js +98 -0
- package/dist/index.mjs +98 -0
- package/dist/sdk.d.mts +55 -0
- package/dist/sdk.d.ts +55 -0
- package/dist/sdk.js +200 -0
- package/dist/sdk.mjs +12 -0
- package/package.json +9 -4
|
@@ -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
|
+
};
|
package/dist/hooks.d.mts
ADDED
package/dist/hooks.d.ts
ADDED
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
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()) {
|
package/dist/index.mjs
CHANGED
|
@@ -997,6 +997,26 @@ var useChatContext = () => {
|
|
|
997
997
|
|
|
998
998
|
// src/sdk/client.ts
|
|
999
999
|
var AizuClient = class {
|
|
1000
|
+
/**
|
|
1001
|
+
* Creates a new AizuClient instance
|
|
1002
|
+
*
|
|
1003
|
+
* @param config - Configuration options for the client
|
|
1004
|
+
* @param config.hostUrl - The base URL of the Aizu API (e.g., 'https://api.aizu.chat')
|
|
1005
|
+
* @param config.apiKey - Your API key for authentication
|
|
1006
|
+
* @param config.timeout - Request timeout in milliseconds (default: 30000)
|
|
1007
|
+
*
|
|
1008
|
+
* @throws {Error} If hostUrl is not a non-empty string
|
|
1009
|
+
* @throws {Error} If apiKey is not a non-empty string
|
|
1010
|
+
*
|
|
1011
|
+
* @example
|
|
1012
|
+
* ```typescript
|
|
1013
|
+
* const client = new AizuClient({
|
|
1014
|
+
* hostUrl: 'https://api.aizu.chat',
|
|
1015
|
+
* apiKey: 'sk_test_123456',
|
|
1016
|
+
* timeout: 60000 // 60 seconds
|
|
1017
|
+
* });
|
|
1018
|
+
* ```
|
|
1019
|
+
*/
|
|
1000
1020
|
constructor(config) {
|
|
1001
1021
|
const { hostUrl, apiKey, timeout } = config;
|
|
1002
1022
|
if (typeof hostUrl !== "string" || hostUrl.trim().length === 0) {
|
|
@@ -1013,6 +1033,26 @@ var AizuClient = class {
|
|
|
1013
1033
|
this.apiKey = apiKey;
|
|
1014
1034
|
this.timeout = timeout != null ? timeout : 3e4;
|
|
1015
1035
|
}
|
|
1036
|
+
/**
|
|
1037
|
+
* Internal method for making HTTP requests to the API
|
|
1038
|
+
*
|
|
1039
|
+
* Handles timeout management, abort signal combination, and error handling.
|
|
1040
|
+
* Supports both user-initiated cancellation and automatic timeout.
|
|
1041
|
+
*
|
|
1042
|
+
* @template T - The expected response type
|
|
1043
|
+
* @template TBody - The request body type
|
|
1044
|
+
*
|
|
1045
|
+
* @param path - API endpoint path (e.g., '/chat/query')
|
|
1046
|
+
* @param options - Request options including body and signal
|
|
1047
|
+
*
|
|
1048
|
+
* @returns Promise resolving to the API response
|
|
1049
|
+
*
|
|
1050
|
+
* @throws {Error} "Request cancelled by user" - If the request is cancelled via AbortSignal
|
|
1051
|
+
* @throws {Error} "Request timeout: The server took too long to respond" - If the request exceeds the timeout
|
|
1052
|
+
* @throws {Error} "API Error: {status} {statusText}" - If the API returns an error status
|
|
1053
|
+
*
|
|
1054
|
+
* @private
|
|
1055
|
+
*/
|
|
1016
1056
|
request(_0) {
|
|
1017
1057
|
return __async(this, arguments, function* (path, options = {}) {
|
|
1018
1058
|
const url = `${this.hostUrl}${path}`;
|
|
@@ -1083,6 +1123,64 @@ var AizuClient = class {
|
|
|
1083
1123
|
}
|
|
1084
1124
|
});
|
|
1085
1125
|
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Sends a chat query to the Aizu API
|
|
1128
|
+
*
|
|
1129
|
+
* @param params - Chat request parameters
|
|
1130
|
+
* @param params.query - The user's message/question (required, non-empty)
|
|
1131
|
+
* @param params.conversationId - Optional conversation ID to continue an existing conversation
|
|
1132
|
+
* @param options - Additional options
|
|
1133
|
+
* @param options.signal - Optional AbortSignal to cancel the request
|
|
1134
|
+
*
|
|
1135
|
+
* @returns Promise resolving to the chat response from the API
|
|
1136
|
+
*
|
|
1137
|
+
* @throws {Error} "Query is required" - If query is empty or whitespace only
|
|
1138
|
+
* @throws {Error} "Request cancelled by user" - If the request is cancelled
|
|
1139
|
+
* @throws {Error} "Request timeout: The server took too long to respond" - If the request times out
|
|
1140
|
+
* @throws {Error} "API Error: {status} {statusText}" - If the API returns an error
|
|
1141
|
+
*
|
|
1142
|
+
* @example
|
|
1143
|
+
* ```typescript
|
|
1144
|
+
* // Simple query
|
|
1145
|
+
* const response = await client.chat({
|
|
1146
|
+
* query: 'What is the weather today?'
|
|
1147
|
+
* });
|
|
1148
|
+
* console.log(response.answer);
|
|
1149
|
+
* ```
|
|
1150
|
+
*
|
|
1151
|
+
* @example
|
|
1152
|
+
* ```typescript
|
|
1153
|
+
* // Continue conversation
|
|
1154
|
+
* const response1 = await client.chat({
|
|
1155
|
+
* query: 'What is the weather today?'
|
|
1156
|
+
* });
|
|
1157
|
+
*
|
|
1158
|
+
* const response2 = await client.chat({
|
|
1159
|
+
* query: 'And tomorrow?',
|
|
1160
|
+
* conversationId: response1.conversationId
|
|
1161
|
+
* });
|
|
1162
|
+
* ```
|
|
1163
|
+
*
|
|
1164
|
+
* @example
|
|
1165
|
+
* ```typescript
|
|
1166
|
+
* // With cancellation support
|
|
1167
|
+
* const controller = new AbortController();
|
|
1168
|
+
*
|
|
1169
|
+
* const promise = client.chat(
|
|
1170
|
+
* { query: 'Long running query...' },
|
|
1171
|
+
* { signal: controller.signal }
|
|
1172
|
+
* );
|
|
1173
|
+
*
|
|
1174
|
+
* // Cancel after 5 seconds
|
|
1175
|
+
* setTimeout(() => controller.abort(), 5000);
|
|
1176
|
+
*
|
|
1177
|
+
* try {
|
|
1178
|
+
* const response = await promise;
|
|
1179
|
+
* } catch (error) {
|
|
1180
|
+
* console.error('Request was cancelled:', error);
|
|
1181
|
+
* }
|
|
1182
|
+
* ```
|
|
1183
|
+
*/
|
|
1086
1184
|
chat(params, options) {
|
|
1087
1185
|
return __async(this, null, function* () {
|
|
1088
1186
|
if (!params.query.trim()) {
|
package/dist/sdk.d.mts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
interface AizuClientConfig {
|
|
2
|
+
hostUrl: string;
|
|
3
|
+
apiKey: string;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
}
|
|
6
|
+
interface ChatRequest {
|
|
7
|
+
query: string;
|
|
8
|
+
thread_id?: string;
|
|
9
|
+
resource_id?: string;
|
|
10
|
+
}
|
|
11
|
+
interface ChatResponse {
|
|
12
|
+
thread_id: string;
|
|
13
|
+
resource_id: string;
|
|
14
|
+
response: string;
|
|
15
|
+
products?: Product[];
|
|
16
|
+
type?: TypeResponse;
|
|
17
|
+
}
|
|
18
|
+
interface Product {
|
|
19
|
+
product_id: string;
|
|
20
|
+
spu?: string;
|
|
21
|
+
sku: string;
|
|
22
|
+
title: string;
|
|
23
|
+
description: string;
|
|
24
|
+
handle: string;
|
|
25
|
+
price: number;
|
|
26
|
+
stock: number;
|
|
27
|
+
thumbnail?: string | null;
|
|
28
|
+
rating?: number;
|
|
29
|
+
review_count?: number;
|
|
30
|
+
estimated_delivery_days?: number;
|
|
31
|
+
similarity?: number;
|
|
32
|
+
}
|
|
33
|
+
declare enum TypeResponse {
|
|
34
|
+
SUGGEST_PRODUCTS = "suggest_products",
|
|
35
|
+
REQUEST_CLARIFICATION = "request_clarification",
|
|
36
|
+
START_SHOPPING = "start_shopping"
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare class AizuClient {
|
|
40
|
+
private hostUrl;
|
|
41
|
+
private apiKey;
|
|
42
|
+
private timeout;
|
|
43
|
+
constructor(config: AizuClientConfig);
|
|
44
|
+
private request;
|
|
45
|
+
chat(params: ChatRequest, options?: {
|
|
46
|
+
signal?: AbortSignal;
|
|
47
|
+
}): Promise<ChatResponse>;
|
|
48
|
+
}
|
|
49
|
+
declare const createAizuClient: ({ hostUrl, apiKey, timeout, }: {
|
|
50
|
+
hostUrl: string;
|
|
51
|
+
apiKey: string;
|
|
52
|
+
timeout?: number;
|
|
53
|
+
}) => AizuClient;
|
|
54
|
+
|
|
55
|
+
export { AizuClient, type AizuClientConfig, type ChatRequest, type ChatResponse, type Product, TypeResponse, createAizuClient };
|