@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.
- 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 +112 -7
- package/dist/index.mjs +112 -7
- 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 +2 -2
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
var __async = (__this, __arguments, generator) => {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
var fulfilled = (value) => {
|
|
36
|
+
try {
|
|
37
|
+
step(generator.next(value));
|
|
38
|
+
} catch (e) {
|
|
39
|
+
reject(e);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var rejected = (value) => {
|
|
43
|
+
try {
|
|
44
|
+
step(generator.throw(value));
|
|
45
|
+
} catch (e) {
|
|
46
|
+
reject(e);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
50
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export {
|
|
55
|
+
__spreadValues,
|
|
56
|
+
__spreadProps,
|
|
57
|
+
__objRest,
|
|
58
|
+
__async
|
|
59
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
// src/hooks/use-custom.ts
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
var useCustom = () => {
|
|
6
|
+
const [count, setCount] = useState(0);
|
|
7
|
+
const increment = () => {
|
|
8
|
+
setCount(count + 1);
|
|
9
|
+
};
|
|
10
|
+
return { count, increment };
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
useCustom
|
|
15
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import {
|
|
3
|
+
__async,
|
|
4
|
+
__objRest,
|
|
5
|
+
__spreadProps,
|
|
6
|
+
__spreadValues
|
|
7
|
+
} from "./chunk-33CPD3DF.mjs";
|
|
8
|
+
|
|
9
|
+
// src/sdk/client.ts
|
|
10
|
+
var AizuClient = class {
|
|
11
|
+
constructor(config) {
|
|
12
|
+
const { hostUrl, apiKey, timeout } = config;
|
|
13
|
+
if (typeof hostUrl !== "string" || hostUrl.trim().length === 0) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
"Invalid AizuClient configuration: 'hostUrl' must be a non-empty string."
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
if (typeof apiKey !== "string" || apiKey.trim().length === 0) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"Invalid AizuClient configuration: 'apiKey' must be a non-empty string."
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
this.hostUrl = hostUrl;
|
|
24
|
+
this.apiKey = apiKey;
|
|
25
|
+
this.timeout = timeout != null ? timeout : 3e4;
|
|
26
|
+
}
|
|
27
|
+
request(_0) {
|
|
28
|
+
return __async(this, arguments, function* (path, options = {}) {
|
|
29
|
+
const url = `${this.hostUrl}${path}`;
|
|
30
|
+
const _a = options, { body, signal: externalSignal } = _a, restOptions = __objRest(_a, ["body", "signal"]);
|
|
31
|
+
const timeoutController = new AbortController();
|
|
32
|
+
const timeoutId = setTimeout(() => timeoutController.abort(), this.timeout);
|
|
33
|
+
let abortController = null;
|
|
34
|
+
let abortHandler = null;
|
|
35
|
+
let abortReason = null;
|
|
36
|
+
const combinedSignal = externalSignal ? (() => {
|
|
37
|
+
abortController = new AbortController();
|
|
38
|
+
const userAbortHandler = () => {
|
|
39
|
+
if (!abortReason) abortReason = "user";
|
|
40
|
+
abortController == null ? void 0 : abortController.abort();
|
|
41
|
+
clearTimeout(timeoutId);
|
|
42
|
+
};
|
|
43
|
+
const timeoutAbortHandler = () => {
|
|
44
|
+
if (!abortReason) abortReason = "timeout";
|
|
45
|
+
abortController == null ? void 0 : abortController.abort();
|
|
46
|
+
};
|
|
47
|
+
const listeners = [
|
|
48
|
+
{ signal: externalSignal, handler: userAbortHandler },
|
|
49
|
+
{ signal: timeoutController.signal, handler: timeoutAbortHandler }
|
|
50
|
+
];
|
|
51
|
+
listeners.forEach(({ signal, handler }) => {
|
|
52
|
+
signal.addEventListener("abort", handler);
|
|
53
|
+
});
|
|
54
|
+
abortHandler = () => {
|
|
55
|
+
listeners.forEach(({ signal, handler }) => {
|
|
56
|
+
signal.removeEventListener("abort", handler);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
return abortController.signal;
|
|
60
|
+
})() : timeoutController.signal;
|
|
61
|
+
try {
|
|
62
|
+
const response = yield fetch(url, __spreadProps(__spreadValues({}, restOptions), {
|
|
63
|
+
signal: combinedSignal,
|
|
64
|
+
headers: __spreadValues({
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
"x-api-key": this.apiKey
|
|
67
|
+
}, options.headers),
|
|
68
|
+
body: body ? JSON.stringify(body) : void 0
|
|
69
|
+
}));
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
const errorBody = yield response.text().catch(() => "");
|
|
72
|
+
const errorMessage = `API Error: ${response.status} ${response.statusText}${errorBody ? ` - ${errorBody}` : ""}`;
|
|
73
|
+
throw new Error(errorMessage);
|
|
74
|
+
}
|
|
75
|
+
return yield response.json();
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
78
|
+
if (abortReason === "user") {
|
|
79
|
+
throw new Error("Request cancelled by user");
|
|
80
|
+
}
|
|
81
|
+
if (abortReason === "timeout") {
|
|
82
|
+
throw new Error(
|
|
83
|
+
"Request timeout: The server took too long to respond"
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
throw new Error("Request was aborted");
|
|
87
|
+
}
|
|
88
|
+
throw error;
|
|
89
|
+
} finally {
|
|
90
|
+
clearTimeout(timeoutId);
|
|
91
|
+
if (abortHandler) {
|
|
92
|
+
abortHandler();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
chat(params, options) {
|
|
98
|
+
return __async(this, null, function* () {
|
|
99
|
+
if (!params.query.trim()) {
|
|
100
|
+
throw new Error("Query is required");
|
|
101
|
+
}
|
|
102
|
+
return this.request("/chat/query", {
|
|
103
|
+
method: "POST",
|
|
104
|
+
body: params,
|
|
105
|
+
signal: options == null ? void 0 : options.signal
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
var createAizuClient = ({
|
|
111
|
+
hostUrl,
|
|
112
|
+
apiKey,
|
|
113
|
+
timeout
|
|
114
|
+
}) => {
|
|
115
|
+
return new AizuClient({ hostUrl, apiKey, timeout });
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// src/sdk/types.ts
|
|
119
|
+
var TypeResponse = /* @__PURE__ */ ((TypeResponse2) => {
|
|
120
|
+
TypeResponse2["SUGGEST_PRODUCTS"] = "suggest_products";
|
|
121
|
+
TypeResponse2["REQUEST_CLARIFICATION"] = "request_clarification";
|
|
122
|
+
TypeResponse2["START_SHOPPING"] = "start_shopping";
|
|
123
|
+
return TypeResponse2;
|
|
124
|
+
})(TypeResponse || {});
|
|
125
|
+
|
|
126
|
+
export {
|
|
127
|
+
AizuClient,
|
|
128
|
+
createAizuClient,
|
|
129
|
+
TypeResponse
|
|
130
|
+
};
|