@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/sdk.d.ts 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 };
package/dist/sdk.js ADDED
@@ -0,0 +1,200 @@
1
+ 'use client'
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __objRest = (source, exclude) => {
25
+ var target = {};
26
+ for (var prop in source)
27
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
28
+ target[prop] = source[prop];
29
+ if (source != null && __getOwnPropSymbols)
30
+ for (var prop of __getOwnPropSymbols(source)) {
31
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
32
+ target[prop] = source[prop];
33
+ }
34
+ return target;
35
+ };
36
+ var __export = (target, all) => {
37
+ for (var name in all)
38
+ __defProp(target, name, { get: all[name], enumerable: true });
39
+ };
40
+ var __copyProps = (to, from, except, desc) => {
41
+ if (from && typeof from === "object" || typeof from === "function") {
42
+ for (let key of __getOwnPropNames(from))
43
+ if (!__hasOwnProp.call(to, key) && key !== except)
44
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
45
+ }
46
+ return to;
47
+ };
48
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
49
+ var __async = (__this, __arguments, generator) => {
50
+ return new Promise((resolve, reject) => {
51
+ var fulfilled = (value) => {
52
+ try {
53
+ step(generator.next(value));
54
+ } catch (e) {
55
+ reject(e);
56
+ }
57
+ };
58
+ var rejected = (value) => {
59
+ try {
60
+ step(generator.throw(value));
61
+ } catch (e) {
62
+ reject(e);
63
+ }
64
+ };
65
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
66
+ step((generator = generator.apply(__this, __arguments)).next());
67
+ });
68
+ };
69
+
70
+ // src/sdk/index.ts
71
+ var sdk_exports = {};
72
+ __export(sdk_exports, {
73
+ AizuClient: () => AizuClient,
74
+ TypeResponse: () => TypeResponse,
75
+ createAizuClient: () => createAizuClient
76
+ });
77
+ module.exports = __toCommonJS(sdk_exports);
78
+
79
+ // src/sdk/client.ts
80
+ var AizuClient = class {
81
+ constructor(config) {
82
+ const { hostUrl, apiKey, timeout } = config;
83
+ if (typeof hostUrl !== "string" || hostUrl.trim().length === 0) {
84
+ throw new Error(
85
+ "Invalid AizuClient configuration: 'hostUrl' must be a non-empty string."
86
+ );
87
+ }
88
+ if (typeof apiKey !== "string" || apiKey.trim().length === 0) {
89
+ throw new Error(
90
+ "Invalid AizuClient configuration: 'apiKey' must be a non-empty string."
91
+ );
92
+ }
93
+ this.hostUrl = hostUrl;
94
+ this.apiKey = apiKey;
95
+ this.timeout = timeout != null ? timeout : 3e4;
96
+ }
97
+ request(_0) {
98
+ return __async(this, arguments, function* (path, options = {}) {
99
+ const url = `${this.hostUrl}${path}`;
100
+ const _a = options, { body, signal: externalSignal } = _a, restOptions = __objRest(_a, ["body", "signal"]);
101
+ const timeoutController = new AbortController();
102
+ const timeoutId = setTimeout(() => timeoutController.abort(), this.timeout);
103
+ let abortController = null;
104
+ let abortHandler = null;
105
+ let abortReason = null;
106
+ const combinedSignal = externalSignal ? (() => {
107
+ abortController = new AbortController();
108
+ const userAbortHandler = () => {
109
+ if (!abortReason) abortReason = "user";
110
+ abortController == null ? void 0 : abortController.abort();
111
+ clearTimeout(timeoutId);
112
+ };
113
+ const timeoutAbortHandler = () => {
114
+ if (!abortReason) abortReason = "timeout";
115
+ abortController == null ? void 0 : abortController.abort();
116
+ };
117
+ const listeners = [
118
+ { signal: externalSignal, handler: userAbortHandler },
119
+ { signal: timeoutController.signal, handler: timeoutAbortHandler }
120
+ ];
121
+ listeners.forEach(({ signal, handler }) => {
122
+ signal.addEventListener("abort", handler);
123
+ });
124
+ abortHandler = () => {
125
+ listeners.forEach(({ signal, handler }) => {
126
+ signal.removeEventListener("abort", handler);
127
+ });
128
+ };
129
+ return abortController.signal;
130
+ })() : timeoutController.signal;
131
+ try {
132
+ const response = yield fetch(url, __spreadProps(__spreadValues({}, restOptions), {
133
+ signal: combinedSignal,
134
+ headers: __spreadValues({
135
+ "Content-Type": "application/json",
136
+ "x-api-key": this.apiKey
137
+ }, options.headers),
138
+ body: body ? JSON.stringify(body) : void 0
139
+ }));
140
+ if (!response.ok) {
141
+ const errorBody = yield response.text().catch(() => "");
142
+ const errorMessage = `API Error: ${response.status} ${response.statusText}${errorBody ? ` - ${errorBody}` : ""}`;
143
+ throw new Error(errorMessage);
144
+ }
145
+ return yield response.json();
146
+ } catch (error) {
147
+ if (error instanceof Error && error.name === "AbortError") {
148
+ if (abortReason === "user") {
149
+ throw new Error("Request cancelled by user");
150
+ }
151
+ if (abortReason === "timeout") {
152
+ throw new Error(
153
+ "Request timeout: The server took too long to respond"
154
+ );
155
+ }
156
+ throw new Error("Request was aborted");
157
+ }
158
+ throw error;
159
+ } finally {
160
+ clearTimeout(timeoutId);
161
+ if (abortHandler) {
162
+ abortHandler();
163
+ }
164
+ }
165
+ });
166
+ }
167
+ chat(params, options) {
168
+ return __async(this, null, function* () {
169
+ if (!params.query.trim()) {
170
+ throw new Error("Query is required");
171
+ }
172
+ return this.request("/chat/query", {
173
+ method: "POST",
174
+ body: params,
175
+ signal: options == null ? void 0 : options.signal
176
+ });
177
+ });
178
+ }
179
+ };
180
+ var createAizuClient = ({
181
+ hostUrl,
182
+ apiKey,
183
+ timeout
184
+ }) => {
185
+ return new AizuClient({ hostUrl, apiKey, timeout });
186
+ };
187
+
188
+ // src/sdk/types.ts
189
+ var TypeResponse = /* @__PURE__ */ ((TypeResponse2) => {
190
+ TypeResponse2["SUGGEST_PRODUCTS"] = "suggest_products";
191
+ TypeResponse2["REQUEST_CLARIFICATION"] = "request_clarification";
192
+ TypeResponse2["START_SHOPPING"] = "start_shopping";
193
+ return TypeResponse2;
194
+ })(TypeResponse || {});
195
+ // Annotate the CommonJS export names for ESM import in node:
196
+ 0 && (module.exports = {
197
+ AizuClient,
198
+ TypeResponse,
199
+ createAizuClient
200
+ });
package/dist/sdk.mjs ADDED
@@ -0,0 +1,12 @@
1
+ 'use client'
2
+ import {
3
+ AizuClient,
4
+ TypeResponse,
5
+ createAizuClient
6
+ } from "./chunk-NBQP747C.mjs";
7
+ import "./chunk-33CPD3DF.mjs";
8
+ export {
9
+ AizuClient,
10
+ TypeResponse,
11
+ createAizuClient
12
+ };
package/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "@aizu-chat/react",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
7
- "sideEffects": ["*.css", "dist/**/*.css"],
7
+ "sideEffects": [
8
+ "*.css",
9
+ "dist/**/*.css"
10
+ ],
8
11
  "license": "MIT",
9
- "files": ["dist/**"],
12
+ "files": [
13
+ "dist/**"
14
+ ],
10
15
  "scripts": {
11
16
  "build": "tsup",
12
17
  "dev": "tsup --watch",
@@ -44,4 +49,4 @@
44
49
  "clsx": "^2.1.1",
45
50
  "tailwind-merge": "^3.4.0"
46
51
  }
47
- }
52
+ }