@aizu-chat/react 0.0.9 → 0.0.10

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,67 @@
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 } = 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
+ }
26
+ request(_0) {
27
+ return __async(this, arguments, function* (path, options = {}) {
28
+ const url = `${this.hostUrl}${path}`;
29
+ const _a = options, { body } = _a, restOptions = __objRest(_a, ["body"]);
30
+ const response = yield fetch(url, __spreadProps(__spreadValues({}, restOptions), {
31
+ headers: __spreadValues({
32
+ "Content-Type": "application/json",
33
+ "x-api-key": this.apiKey
34
+ }, options.headers),
35
+ body: body ? JSON.stringify(body) : void 0
36
+ }));
37
+ if (!response.ok) {
38
+ const errorBody = yield response.text().catch(() => "");
39
+ const errorMessage = `API Error: ${response.status} ${response.statusText}${errorBody ? ` - ${errorBody}` : ""}`;
40
+ throw new Error(errorMessage);
41
+ }
42
+ return yield response.json();
43
+ });
44
+ }
45
+ chat(params) {
46
+ return __async(this, null, function* () {
47
+ if (!params.query.trim()) {
48
+ throw new Error("Query is required");
49
+ }
50
+ return this.request("/chat/query", {
51
+ method: "POST",
52
+ body: params
53
+ });
54
+ });
55
+ }
56
+ };
57
+ var createAizuClient = ({
58
+ hostUrl,
59
+ apiKey
60
+ }) => {
61
+ return new AizuClient({ hostUrl, apiKey });
62
+ };
63
+
64
+ export {
65
+ AizuClient,
66
+ createAizuClient
67
+ };