aov-agent 1.0.0 → 1.0.1

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.
Files changed (30) hide show
  1. package/README.md +250 -1
  2. package/dist/agent-ui/components/Assistant/AgentButton/AgentButton.js +28 -0
  3. package/dist/agent-ui/components/Assistant/AgentButton/AgentButton.scss +40 -0
  4. package/dist/agent-ui/components/Assistant/Assistant.js +73 -0
  5. package/dist/agent-ui/components/Assistant/Assistant.scss +3 -0
  6. package/dist/agent-ui/components/Assistant/AssistantWidget/AssistantWidget.js +187 -0
  7. package/dist/agent-ui/components/Assistant/AssistantWidget/AssistantWidget.scss +211 -0
  8. package/dist/agent-ui/components/Assistant/AssistantWidget/components/CampaignRendered.js +30 -0
  9. package/dist/agent-ui/components/Assistant/AssistantWidget/components/ListChat.js +129 -0
  10. package/dist/agent-ui/components/Assistant/Markdown/MarkdownText.js +228 -0
  11. package/dist/agent-ui/components/Assistant/Markdown/MarkdownText.scss +222 -0
  12. package/dist/agent-ui/components/Assistant/Markdown/MathRenderer.js +46 -0
  13. package/dist/agent-ui/components/Assistant/Suggestions/Suggestions.js +62 -0
  14. package/dist/agent-ui/components/Assistant/Suggestions/Suggestions.scss +22 -0
  15. package/dist/agent-ui/components/Assistant/ThreadProvider.js +482 -0
  16. package/dist/agent-ui/components/Assistant/ToolResult/CardTool.js +41 -0
  17. package/dist/agent-ui/components/Assistant/ToolResult/ToolResult.js +20 -0
  18. package/dist/agent-ui/components/ResizableModal/ResizableModal.js +262 -0
  19. package/dist/agent-ui/components/ResizableModal/ResizableModal.scss +117 -0
  20. package/dist/agent-ui/contexts/AgentContext.js +39 -0
  21. package/dist/agent-ui/contexts/SuggestionsContext.js +64 -0
  22. package/dist/agent-ui/contexts/ThreadContext.js +60 -0
  23. package/dist/agent-ui/hooks/useFetchApi.js +238 -0
  24. package/dist/agent-ui/hooks/useStreamApi.js +127 -0
  25. package/dist/agent-ui/index.js +1 -0
  26. package/dist/agent-ui/services/errorService.js +39 -0
  27. package/dist/agent-ui/utils/api.js +164 -0
  28. package/package.json +26 -9
  29. package/dist/index.js +0 -7
  30. package/types/index.d.ts +0 -5
@@ -0,0 +1,238 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
3
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
4
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
5
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
7
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
8
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
11
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
12
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
14
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
15
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
16
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
17
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
18
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
19
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
20
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
21
+ import { useEffect, useState } from "react";
22
+ import { fetchAuthenticateApi } from "../utils/api.js";
23
+ import queryString from "query-string";
24
+ import { handleApiError } from "../services/errorService.js";
25
+
26
+ /**
27
+ * Custom hook for fetching data from API endpoints
28
+ *
29
+ * @param {Object} config - Configuration object
30
+ * @param {string} config.url - API endpoint URL
31
+ * @param {Array|Object} config.defaultData - Default data structure
32
+ * @param {boolean} config.initLoad - Whether to load data on mount
33
+ * @param {Function} config.presentData - Data transformation function
34
+ * @param {boolean} config.keepPreviousData - Keep previous data when fetching more
35
+ * @param {Object} config.initQueries - Initial query parameters
36
+ * @param {Function} config.successCallback - Callback on successful fetch
37
+ * @param {string} config.method - HTTP method (GET, POST, etc.)
38
+ * @param {Object} config.postData - Data to send in POST requests
39
+ * @returns {Object} Hook return object with data, loading state, and fetch functions
40
+ */
41
+ export default function useFetchApi(_ref) {
42
+ var url = _ref.url,
43
+ _ref$defaultData = _ref.defaultData,
44
+ defaultData = _ref$defaultData === void 0 ? [] : _ref$defaultData,
45
+ _ref$initLoad = _ref.initLoad,
46
+ initLoad = _ref$initLoad === void 0 ? true : _ref$initLoad,
47
+ _ref$presentData = _ref.presentData,
48
+ presentData = _ref$presentData === void 0 ? function (data) {
49
+ return data;
50
+ } : _ref$presentData,
51
+ _ref$keepPreviousData = _ref.keepPreviousData,
52
+ keepPreviousData = _ref$keepPreviousData === void 0 ? false : _ref$keepPreviousData,
53
+ _ref$initQueries = _ref.initQueries,
54
+ initQueries = _ref$initQueries === void 0 ? {} : _ref$initQueries,
55
+ _ref$successCallback = _ref.successCallback,
56
+ successCallback = _ref$successCallback === void 0 ? function () {} : _ref$successCallback,
57
+ _ref$method = _ref.method,
58
+ method = _ref$method === void 0 ? "GET" : _ref$method,
59
+ _ref$postData = _ref.postData,
60
+ postData = _ref$postData === void 0 ? {} : _ref$postData;
61
+ var _useState = useState(initLoad),
62
+ _useState2 = _slicedToArray(_useState, 2),
63
+ loading = _useState2[0],
64
+ setLoading = _useState2[1];
65
+ var _useState3 = useState(false),
66
+ _useState4 = _slicedToArray(_useState3, 2),
67
+ fetched = _useState4[0],
68
+ setFetched = _useState4[1];
69
+ var _useState5 = useState(defaultData),
70
+ _useState6 = _slicedToArray(_useState5, 2),
71
+ data = _useState6[0],
72
+ setData = _useState6[1];
73
+ var _useState7 = useState({}),
74
+ _useState8 = _slicedToArray(_useState7, 2),
75
+ pagination = _useState8[0],
76
+ setPagination = _useState8[1];
77
+ var _useState9 = useState({}),
78
+ _useState0 = _slicedToArray(_useState9, 2),
79
+ pageInfo = _useState0[0],
80
+ setPageInfo = _useState0[1];
81
+ var _useState1 = useState(0),
82
+ _useState10 = _slicedToArray(_useState1, 2),
83
+ total = _useState10[0],
84
+ setTotal = _useState10[1];
85
+ var _useState11 = useState(null),
86
+ _useState12 = _slicedToArray(_useState11, 2),
87
+ endCursor = _useState12[0],
88
+ setEndCursor = _useState12[1];
89
+ var _useState13 = useState(0),
90
+ _useState14 = _slicedToArray(_useState13, 2),
91
+ count = _useState14[0],
92
+ setCount = _useState14[1];
93
+ var _useState15 = useState(null),
94
+ _useState16 = _slicedToArray(_useState15, 2),
95
+ error = _useState16[0],
96
+ setError = _useState16[1];
97
+ function fetchApi() {
98
+ return _fetchApi.apply(this, arguments);
99
+ }
100
+ function _fetchApi() {
101
+ _fetchApi = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
102
+ var apiUrl,
103
+ _ref2,
104
+ _ref2$params,
105
+ params,
106
+ _ref2$keepPreviousDat,
107
+ keepPreviousData,
108
+ path,
109
+ separateChar,
110
+ query,
111
+ options,
112
+ resp,
113
+ newData,
114
+ _pagination,
115
+ hasPre,
116
+ hasNext,
117
+ _args = arguments,
118
+ _t;
119
+ return _regenerator().w(function (_context) {
120
+ while (1) switch (_context.p = _context.n) {
121
+ case 0:
122
+ apiUrl = _args.length > 0 && _args[0] !== undefined ? _args[0] : url;
123
+ _ref2 = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}, _ref2$params = _ref2.params, params = _ref2$params === void 0 ? null : _ref2$params, _ref2$keepPreviousDat = _ref2.keepPreviousData, keepPreviousData = _ref2$keepPreviousDat === void 0 ? false : _ref2$keepPreviousDat;
124
+ _context.p = 1;
125
+ setLoading(true);
126
+ path = apiUrl;
127
+ separateChar = path.includes("?") ? "&" : "?";
128
+ query = params ? separateChar + queryString.stringify(params) : "";
129
+ options = {};
130
+ if (method !== "GET") {
131
+ options = {
132
+ body: postData,
133
+ method: method
134
+ };
135
+ }
136
+ _context.n = 2;
137
+ return fetchAuthenticateApi({
138
+ uri: path + query,
139
+ options: options,
140
+ clientConfig: {
141
+ baseURL: "/api"
142
+ }
143
+ });
144
+ case 2:
145
+ resp = _context.v;
146
+ if (!resp.error) {
147
+ _context.n = 3;
148
+ break;
149
+ }
150
+ throw new Error(resp.error);
151
+ case 3:
152
+ if (Object.hasOwn(resp, "endCursor")) setEndCursor(resp.endCursor);
153
+ if (Object.hasOwn(resp, "pageInfo")) setPageInfo(resp.pageInfo);
154
+ if (Object.hasOwn(resp, "count")) setCount(resp.count);
155
+ if (Object.hasOwn(resp, "data")) {
156
+ newData = presentData(resp.data);
157
+ if (!Array.isArray(newData)) {
158
+ newData = _objectSpread(_objectSpread({}, defaultData), newData);
159
+ }
160
+ setData(function (prev) {
161
+ if (!keepPreviousData) {
162
+ return newData;
163
+ }
164
+ return Array.isArray(newData) ? [].concat(_toConsumableArray(prev), _toConsumableArray(newData)) : _objectSpread(_objectSpread({}, prev), newData);
165
+ });
166
+ successCallback(newData);
167
+ }
168
+ if (resp.pagination) {
169
+ _pagination = resp.pagination;
170
+ setPagination(_pagination);
171
+ if (Object.hasOwn(_pagination, "total")) setTotal(_pagination.total);
172
+ } else if (Object.hasOwn(resp, "hasPre") || Object.hasOwn(resp, "hasNext")) {
173
+ hasPre = resp.hasPre, hasNext = resp.hasNext;
174
+ setPagination({
175
+ hasPre: hasPre,
176
+ hasNext: hasNext
177
+ });
178
+ }
179
+ _context.n = 5;
180
+ break;
181
+ case 4:
182
+ _context.p = 4;
183
+ _t = _context.v;
184
+ handleApiError(_t);
185
+ setError((_t === null || _t === void 0 ? void 0 : _t.message) || "Something went wrong");
186
+ case 5:
187
+ _context.p = 5;
188
+ setLoading(false);
189
+ setFetched(true);
190
+ return _context.f(5);
191
+ case 6:
192
+ return _context.a(2);
193
+ }
194
+ }, _callee, null, [[1, 4, 5, 6]]);
195
+ }));
196
+ return _fetchApi.apply(this, arguments);
197
+ }
198
+ useEffect(function () {
199
+ if (initLoad && !fetched) {
200
+ fetchApi(url, {
201
+ params: initQueries,
202
+ keepPreviousData: keepPreviousData
203
+ }).then(function () {});
204
+ }
205
+ }, []);
206
+ var handleChangeInput = function handleChangeInput(key, value) {
207
+ return setData(function (prev) {
208
+ return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, key, value));
209
+ });
210
+ };
211
+ var handleRowChange = function handleRowChange(index, key, value) {
212
+ setData(function (prev) {
213
+ var row = _objectSpread(_objectSpread({}, prev[index]), {}, _defineProperty({}, key, value));
214
+ return [].concat(_toConsumableArray(prev.slice(0, index)), [row], _toConsumableArray(prev.slice(index + 1)));
215
+ });
216
+ };
217
+ return {
218
+ fetchApi: fetchApi,
219
+ data: data,
220
+ endCursor: endCursor,
221
+ setData: setData,
222
+ pageInfo: pageInfo,
223
+ total: total,
224
+ setTotal: setTotal,
225
+ loading: loading,
226
+ setLoading: setLoading,
227
+ fetched: fetched,
228
+ setFetched: setFetched,
229
+ pagination: pagination,
230
+ setPagination: setPagination,
231
+ count: count,
232
+ setCount: setCount,
233
+ handleChangeInput: handleChangeInput,
234
+ handleRowChange: handleRowChange,
235
+ reFetch: fetchApi,
236
+ error: error
237
+ };
238
+ }
@@ -0,0 +1,127 @@
1
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
2
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
3
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
4
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
5
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
6
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
7
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
9
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
10
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
11
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
12
+ import { useState, useCallback } from "react";
13
+ import { streamApi } from "../utils/api.js";
14
+
15
+ /**
16
+ * Custom hook for Server-Sent Events (SSE) streaming API calls
17
+ *
18
+ * @param {string} apiUrl - API endpoint URL for streaming
19
+ * @returns {Object} Object containing stream function and streaming state
20
+ */
21
+ export var useStreamApi = function useStreamApi(apiUrl) {
22
+ var _useState = useState(false),
23
+ _useState2 = _slicedToArray(_useState, 2),
24
+ isStreaming = _useState2[0],
25
+ setIsStreaming = _useState2[1];
26
+ var stream = useCallback(/*#__PURE__*/function () {
27
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
28
+ var _ref$method, method, _ref$data, data, onStart, onContent, onSuggestions, onTool, abortSignal, pendingChunks, lastIndex, _t;
29
+ return _regenerator().w(function (_context) {
30
+ while (1) switch (_context.p = _context.n) {
31
+ case 0:
32
+ _ref$method = _ref.method, method = _ref$method === void 0 ? "POST" : _ref$method, _ref$data = _ref.data, data = _ref$data === void 0 ? {} : _ref$data, onStart = _ref.onStart, onContent = _ref.onContent, onSuggestions = _ref.onSuggestions, onTool = _ref.onTool, abortSignal = _ref.abortSignal;
33
+ setIsStreaming(true);
34
+ _context.p = 1;
35
+ pendingChunks = "";
36
+ lastIndex = 0;
37
+ _context.n = 2;
38
+ return streamApi({
39
+ apiUrl: apiUrl,
40
+ method: method,
41
+ data: data,
42
+ signal: abortSignal,
43
+ onChunk: function onChunk(progressEvent) {
44
+ var fullResp = progressEvent.currentTarget.response;
45
+ if (!fullResp) return;
46
+ var chunk = fullResp.slice(lastIndex);
47
+ lastIndex = fullResp.length;
48
+ if (!chunk) return;
49
+ pendingChunks += chunk;
50
+ var events = pendingChunks.split("\n\n");
51
+ pendingChunks = events.pop() || "";
52
+ var _iterator = _createForOfIteratorHelper(events),
53
+ _step;
54
+ try {
55
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
56
+ var evt = _step.value;
57
+ var lines = evt.split("\n");
58
+ var dataLines = [];
59
+ var _iterator2 = _createForOfIteratorHelper(lines),
60
+ _step2;
61
+ try {
62
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
63
+ var line = _step2.value;
64
+ if (line.startsWith("data:")) {
65
+ dataLines.push(line.slice(5).trimStart());
66
+ }
67
+ }
68
+ } catch (err) {
69
+ _iterator2.e(err);
70
+ } finally {
71
+ _iterator2.f();
72
+ }
73
+ var payload = dataLines.join("\n").trim();
74
+ if (!payload) continue;
75
+ try {
76
+ var resp = JSON.parse(payload);
77
+ var _data = resp.data;
78
+ switch (resp.type) {
79
+ case "chat-created":
80
+ if (onStart) onStart(_data);
81
+ break;
82
+ case "text-content":
83
+ if (onContent) onContent(_data);
84
+ break;
85
+ case "tool-call":
86
+ if (onTool) onTool(_data);
87
+ break;
88
+ case "suggestions":
89
+ var listSuggestions = _data.split("\n");
90
+ if (onSuggestions) onSuggestions(listSuggestions);
91
+ break;
92
+ }
93
+ } catch (e) {
94
+ console.error("Error parsing SSE data:", e);
95
+ }
96
+ }
97
+ } catch (err) {
98
+ _iterator.e(err);
99
+ } finally {
100
+ _iterator.f();
101
+ }
102
+ }
103
+ });
104
+ case 2:
105
+ return _context.a(2, Promise.resolve());
106
+ case 3:
107
+ _context.p = 3;
108
+ _t = _context.v;
109
+ console.error("Stream API error:", _t);
110
+ case 4:
111
+ _context.p = 4;
112
+ setIsStreaming(false);
113
+ return _context.f(4);
114
+ case 5:
115
+ return _context.a(2);
116
+ }
117
+ }, _callee, null, [[1, 3, 4, 5]]);
118
+ }));
119
+ return function (_x) {
120
+ return _ref2.apply(this, arguments);
121
+ };
122
+ }(), []);
123
+ return {
124
+ stream: stream,
125
+ isStreaming: isStreaming
126
+ };
127
+ };
@@ -0,0 +1 @@
1
+ export { default as Assistant } from "./components/Assistant/Assistant.js";
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Handle API errors with structured logging
3
+ *
4
+ * @param {Error|Object} error - Error object from API call
5
+ * @param {Object} context - Additional context for debugging
6
+ * @returns {string} User-friendly error message
7
+ */
8
+ export function handleApiError(error) {
9
+ var _error$toJSON;
10
+ var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
11
+ var errorData = error.response || ((_error$toJSON = error.toJSON) === null || _error$toJSON === void 0 ? void 0 : _error$toJSON.call(error)) || error;
12
+ var errorMessage = error.message || 'An unexpected error occurred';
13
+
14
+ // Log detailed error for debugging
15
+ console.error('API Error:', {
16
+ message: errorMessage,
17
+ error: errorData,
18
+ context: context,
19
+ timestamp: new Date().toISOString()
20
+ });
21
+ return errorMessage;
22
+ }
23
+
24
+ /**
25
+ * Get user-friendly error message from error object
26
+ *
27
+ * @param {Error|Object} error - Error object
28
+ * @returns {string} User-friendly error message
29
+ */
30
+ export function getUserErrorMessage(error) {
31
+ var _error$response;
32
+ if ((_error$response = error.response) !== null && _error$response !== void 0 && (_error$response = _error$response.data) !== null && _error$response !== void 0 && _error$response.error) {
33
+ return error.response.data.error;
34
+ }
35
+ if (error.message) {
36
+ return error.message;
37
+ }
38
+ return 'Something went wrong. Please try again.';
39
+ }
@@ -0,0 +1,164 @@
1
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
2
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
3
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
4
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
5
+ var isFormData = function isFormData(value) {
6
+ return value instanceof FormData;
7
+ };
8
+
9
+ /**
10
+ *
11
+ * @param {string} uri
12
+ * @param {Object} options
13
+ * @param {Object} clientConfig
14
+ * @returns
15
+ */
16
+ export var fetchAuthenticateApi = /*#__PURE__*/function () {
17
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
18
+ var uri, _ref$options, options, _ref$clientConfig, clientConfig, response;
19
+ return _regenerator().w(function (_context) {
20
+ while (1) switch (_context.n) {
21
+ case 0:
22
+ uri = _ref.uri, _ref$options = _ref.options, options = _ref$options === void 0 ? {} : _ref$options, _ref$clientConfig = _ref.clientConfig, clientConfig = _ref$clientConfig === void 0 ? {
23
+ baseURL: "/api"
24
+ } : _ref$clientConfig;
25
+ if (options !== null && options !== void 0 && options.body && !isFormData(options.body)) {
26
+ options.body = JSON.stringify(options.body);
27
+ options.headers = options.headers || {};
28
+ options.headers["Content-Type"] = "application/json";
29
+ }
30
+ _context.n = 1;
31
+ return fetch(clientConfig.baseURL + uri, options);
32
+ case 1:
33
+ response = _context.v;
34
+ _context.n = 2;
35
+ return response.json();
36
+ case 2:
37
+ return _context.a(2, _context.v);
38
+ }
39
+ }, _callee);
40
+ }));
41
+ return function fetchAuthenticateApi(_x) {
42
+ return _ref2.apply(this, arguments);
43
+ };
44
+ }();
45
+
46
+ /**
47
+ *
48
+ * @param {Object} options.data
49
+ * @param {string} options.method
50
+ * @param {function} options.onChunk
51
+ * @param {AbortSignal} options.signal
52
+ * @returns
53
+ */
54
+ export var streamApi = /*#__PURE__*/function () {
55
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref3) {
56
+ var apiUrl, _ref3$data, data, _ref3$method, method, onChunk, signal, idToken, fullUrl, resp, text, reader, decoder, accumulated, readResult, _readResult, value, done, str, _t;
57
+ return _regenerator().w(function (_context2) {
58
+ while (1) switch (_context2.p = _context2.n) {
59
+ case 0:
60
+ apiUrl = _ref3.apiUrl, _ref3$data = _ref3.data, data = _ref3$data === void 0 ? {} : _ref3$data, _ref3$method = _ref3.method, method = _ref3$method === void 0 ? "POST" : _ref3$method, onChunk = _ref3.onChunk, signal = _ref3.signal;
61
+ _context2.n = 1;
62
+ return window.shopify.idToken();
63
+ case 1:
64
+ idToken = _context2.v;
65
+ fullUrl = apiUrl || "/public/api/chat/message";
66
+ _context2.n = 2;
67
+ return fetch(fullUrl, {
68
+ method: method,
69
+ headers: {
70
+ accept: "text/event-stream",
71
+ "Content-Type": "application/json",
72
+ Connection: "keep-alive",
73
+ "Cache-Control": "no-cache",
74
+ Authorization: "Bearer ".concat(idToken),
75
+ "X-Auth-Token": idToken
76
+ },
77
+ body: JSON.stringify(data),
78
+ signal: signal
79
+ });
80
+ case 2:
81
+ resp = _context2.v;
82
+ if (!(!resp.body || !resp.body.getReader)) {
83
+ _context2.n = 4;
84
+ break;
85
+ }
86
+ _context2.n = 3;
87
+ return resp.text();
88
+ case 3:
89
+ text = _context2.v;
90
+ if (onChunk) {
91
+ onChunk({
92
+ currentTarget: {
93
+ response: text,
94
+ responseText: text
95
+ }
96
+ });
97
+ }
98
+ return _context2.a(2, text);
99
+ case 4:
100
+ reader = resp.body.getReader();
101
+ decoder = new TextDecoder();
102
+ accumulated = "";
103
+ _context2.p = 5;
104
+ case 6:
105
+ if (!true) {
106
+ _context2.n = 13;
107
+ break;
108
+ }
109
+ readResult = void 0;
110
+ _context2.p = 7;
111
+ _context2.n = 8;
112
+ return reader.read();
113
+ case 8:
114
+ readResult = _context2.v;
115
+ _context2.n = 11;
116
+ break;
117
+ case 9:
118
+ _context2.p = 9;
119
+ _t = _context2.v;
120
+ console.warn("AbortError", _t);
121
+ if (!((_t === null || _t === void 0 ? void 0 : _t.name) === "AbortError" || signal !== null && signal !== void 0 && signal.aborted)) {
122
+ _context2.n = 10;
123
+ break;
124
+ }
125
+ return _context2.a(3, 13);
126
+ case 10:
127
+ throw _t;
128
+ case 11:
129
+ _readResult = readResult, value = _readResult.value, done = _readResult.done;
130
+ if (!done) {
131
+ _context2.n = 12;
132
+ break;
133
+ }
134
+ return _context2.a(3, 13);
135
+ case 12:
136
+ str = decoder.decode(value, {
137
+ stream: true
138
+ });
139
+ accumulated += str;
140
+ if (onChunk) {
141
+ onChunk({
142
+ currentTarget: {
143
+ response: accumulated,
144
+ responseText: accumulated
145
+ }
146
+ });
147
+ }
148
+ _context2.n = 6;
149
+ break;
150
+ case 13:
151
+ _context2.p = 13;
152
+ try {
153
+ reader.releaseLock();
154
+ } catch (_unused) {}
155
+ return _context2.f(13);
156
+ case 14:
157
+ return _context2.a(2, accumulated);
158
+ }
159
+ }, _callee2, null, [[7, 9], [5,, 13, 14]]);
160
+ }));
161
+ return function streamApi(_x2) {
162
+ return _ref4.apply(this, arguments);
163
+ };
164
+ }();
package/package.json CHANGED
@@ -1,12 +1,21 @@
1
1
  {
2
2
  "name": "aov-agent",
3
- "version": "1.0.0",
4
- "description": "AOV Agent",
5
- "main": "dist/index.js",
3
+ "version": "1.0.1",
4
+ "description": "AOV AI Agent - Monorepo for AI Assistant Components",
6
5
  "type": "module",
6
+ "exports": {
7
+ "./agent-ui": "./dist/agent-ui/index.js",
8
+ "./agent-ui/*": "./dist/agent-ui/*"
9
+ },
10
+ "workspaces": [
11
+ "packages/*"
12
+ ],
7
13
  "scripts": {
8
- "build": "babel src --out-dir dist --extensions \".ts\"",
9
- "build:watch": "babel src --out-dir dist --extensions \".ts\" --watch"
14
+ "build": "npm run build:ui",
15
+ "build:ui": "cd packages/ui && npm run build",
16
+ "build:watch": "cd packages/ui && npm run build:watch",
17
+ "clean": "rimraf dist",
18
+ "prepublishOnly": "npm run clean && npm run build"
10
19
  },
11
20
  "repository": {
12
21
  "type": "git",
@@ -14,7 +23,12 @@
14
23
  },
15
24
  "keywords": [
16
25
  "AOV",
17
- "Agent"
26
+ "Agent",
27
+ "AI",
28
+ "Assistant",
29
+ "React",
30
+ "UI Components",
31
+ "Shopify"
18
32
  ],
19
33
  "author": "AOV.ai",
20
34
  "license": "ISC",
@@ -26,11 +40,14 @@
26
40
  "@babel/cli": "^7.28.3",
27
41
  "@babel/core": "^7.28.5",
28
42
  "@babel/preset-env": "^7.28.5",
29
- "@babel/preset-typescript": "^7.28.5"
43
+ "@babel/preset-react": "^7.28.0",
44
+ "babel-plugin-module-resolver": "^5.0.2",
45
+ "concurrently": "^9.2.1",
46
+ "cpx": "^1.5.0",
47
+ "rimraf": "^5.0.10"
30
48
  },
31
49
  "files": [
32
- "dist",
33
- "types"
50
+ "dist"
34
51
  ],
35
52
  "publishConfig": {
36
53
  "access": "public"
package/dist/index.js DELETED
@@ -1,7 +0,0 @@
1
- export default function getAgent() {
2
- return {
3
- name: "Agent",
4
- description: "Agent",
5
- version: "1.0.0"
6
- };
7
- }
package/types/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export declare function getAgent(): {
2
- name: string;
3
- description: string;
4
- version: string;
5
- };