@foris/ai-agent 0.1.0 → 0.1.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.
@@ -1,8 +1,8 @@
1
- var w = Object.defineProperty;
2
- var A = (o, t, u) => t in o ? w(o, t, { enumerable: !0, configurable: !0, writable: !0, value: u }) : o[t] = u;
3
- var g = (o, t, u) => (A(o, typeof t != "symbol" ? t + "" : t, u), u);
4
- import R, { useState as h, useRef as b, useEffect as x, useMemo as T, useCallback as N } from "react";
5
- var k = { exports: {} }, y = {};
1
+ var T = Object.defineProperty;
2
+ var A = (a, n, m) => n in a ? T(a, n, { enumerable: !0, configurable: !0, writable: !0, value: m }) : a[n] = m;
3
+ var x = (a, n, m) => (A(a, typeof n != "symbol" ? n + "" : n, m), m);
4
+ import R, { useState as C, useRef as v, useEffect as g, useMemo as N, useCallback as E } from "react";
5
+ var k = { exports: {} }, h = {};
6
6
  /**
7
7
  * @license React
8
8
  * react-jsx-runtime.production.min.js
@@ -12,122 +12,126 @@ var k = { exports: {} }, y = {};
12
12
  * This source code is licensed under the MIT license found in the
13
13
  * LICENSE file in the root directory of this source tree.
14
14
  */
15
- var v;
16
- function E() {
17
- if (v)
18
- return y;
19
- v = 1;
20
- var o = R, t = Symbol.for("react.element"), u = Symbol.for("react.fragment"), i = Object.prototype.hasOwnProperty, c = o.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, m = { key: !0, ref: !0, __self: !0, __source: !0 };
21
- function l(e, r, p) {
22
- var n, s = {}, d = null, C = null;
23
- p !== void 0 && (d = "" + p), r.key !== void 0 && (d = "" + r.key), r.ref !== void 0 && (C = r.ref);
24
- for (n in r)
25
- i.call(r, n) && !m.hasOwnProperty(n) && (s[n] = r[n]);
26
- if (e && e.defaultProps)
27
- for (n in r = e.defaultProps, r)
28
- s[n] === void 0 && (s[n] = r[n]);
29
- return { $$typeof: t, type: e, key: d, ref: C, props: s, _owner: c.current };
15
+ var j;
16
+ function O() {
17
+ if (j)
18
+ return h;
19
+ j = 1;
20
+ var a = R, n = Symbol.for("react.element"), m = Symbol.for("react.fragment"), c = Object.prototype.hasOwnProperty, u = a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, o = { key: !0, ref: !0, __self: !0, __source: !0 };
21
+ function l(r, s, _) {
22
+ var e, t = {}, p = null, f = null;
23
+ _ !== void 0 && (p = "" + _), s.key !== void 0 && (p = "" + s.key), s.ref !== void 0 && (f = s.ref);
24
+ for (e in s)
25
+ c.call(s, e) && !o.hasOwnProperty(e) && (t[e] = s[e]);
26
+ if (r && r.defaultProps)
27
+ for (e in s = r.defaultProps, s)
28
+ t[e] === void 0 && (t[e] = s[e]);
29
+ return { $$typeof: n, type: r, key: p, ref: f, props: t, _owner: u.current };
30
30
  }
31
- return y.Fragment = u, y.jsx = l, y.jsxs = l, y;
31
+ return h.Fragment = m, h.jsx = l, h.jsxs = l, h;
32
32
  }
33
- k.exports = E();
34
- var a = k.exports;
33
+ k.exports = O();
34
+ var i = k.exports;
35
35
  class S {
36
- constructor(t) {
37
- g(this, "api");
38
- this.api = t;
36
+ constructor(n, m) {
37
+ x(this, "api");
38
+ x(this, "headers", {
39
+ "Content-Type": "application/json"
40
+ });
41
+ this.api = n, this.headers = m ?? this.headers;
39
42
  }
40
- post(t) {
43
+ post(n) {
41
44
  return fetch(this.api, {
42
45
  method: "POST",
43
- headers: {
44
- "Content-Type": "application/json"
45
- },
46
- body: JSON.stringify(t)
46
+ headers: this.headers,
47
+ body: JSON.stringify(n)
47
48
  });
48
49
  }
49
50
  }
50
- const j = (o) => {
51
- const t = (i) => {
52
- i && o((c) => {
53
- const m = c[c.length - 1];
54
- return (m == null ? void 0 : m.role) === "assistant" ? [
55
- ...c.slice(0, -1),
56
- { role: "assistant", content: m.content + i }
57
- ] : [...c, { role: "assistant", content: i }];
51
+ const P = (a) => {
52
+ const n = (c) => {
53
+ c && a((u) => {
54
+ const o = u[u.length - 1];
55
+ return (o == null ? void 0 : o.role) === "assistant" ? [
56
+ ...u.slice(0, -1),
57
+ { role: "assistant", content: o.content + c }
58
+ ] : [...u, { role: "assistant", content: c }];
58
59
  });
59
60
  };
60
61
  return {
61
- splitChunks: async (i) => {
62
- if (i.body) {
63
- const c = i.body.getReader(), m = new TextDecoder();
62
+ splitChunks: async (c) => {
63
+ if (c.body) {
64
+ const u = c.body.getReader(), o = new TextDecoder();
64
65
  let l = "";
65
66
  for (; ; ) {
66
- const { done: e, value: r } = await c.read();
67
- if (e)
67
+ const { done: r, value: s } = await u.read();
68
+ if (r)
68
69
  break;
69
- l += m.decode(r, { stream: !0 });
70
- const p = l.split(`
70
+ l += o.decode(s, { stream: !0 });
71
+ const _ = l.split(`
71
72
  `);
72
- l = p.pop() ?? "";
73
- for (let n of p)
74
- if (n = n.trim(), !!n && !n.startsWith(":") && !n.startsWith("event:") && (n.startsWith("data:") && (n = n.slice(5).trim()), !!n)) {
75
- if (n === "[DONE]")
73
+ l = _.pop() ?? "";
74
+ for (let e of _)
75
+ if (e = e.trim(), !!e && !e.startsWith(":") && !e.startsWith("event:") && (e.startsWith("data:") && (e = e.slice(5).trim()), !!e)) {
76
+ if (e === "[DONE]")
76
77
  return;
77
78
  try {
78
- const s = JSON.parse(n), d = (s == null ? void 0 : s.type) === "token" ? typeof s.value == "string" ? s.value : typeof s.content == "string" ? s.content : "" : (s == null ? void 0 : s.type) === "chunk" ? typeof s.content == "string" ? s.content : typeof s.value == "string" ? s.value : "" : typeof (s == null ? void 0 : s.message) == "string" ? s.message : "";
79
- d && t(d);
79
+ const t = JSON.parse(e), p = (t == null ? void 0 : t.type) === "token" ? typeof t.value == "string" ? t.value : typeof t.content == "string" ? t.content : "" : (t == null ? void 0 : t.type) === "chunk" ? typeof t.content == "string" ? t.content : typeof t.value == "string" ? t.value : "" : typeof (t == null ? void 0 : t.message) == "string" ? t.message : "";
80
+ p && n(p);
80
81
  } catch {
81
- t(n);
82
+ n(e);
82
83
  }
83
84
  }
84
85
  }
85
86
  }
86
87
  }
87
88
  };
88
- }, O = "demo-123", $ = (o) => {
89
- const [t, u] = h([]), { splitChunks: i } = j(u);
89
+ }, $ = "demo-123", D = (a, n) => {
90
+ const [m, c] = C([]), { splitChunks: u } = P(c);
90
91
  return {
91
- onSubmit: async ({ input: m, setInput: l, abortRef: e }) => {
92
- var p;
93
- if (!m.trim())
92
+ onSubmit: async ({ input: l, setInput: r, abortRef: s }) => {
93
+ var e;
94
+ if (!l.trim())
94
95
  return;
95
- const r = m;
96
- l(""), u((n) => [
97
- ...n,
98
- { role: "user", content: r },
96
+ const _ = l;
97
+ r(""), c((t) => [
98
+ ...t,
99
+ { role: "user", content: _ },
99
100
  { role: "assistant", content: "" }
100
101
  ]);
101
102
  try {
102
- (p = e.current) == null || p.abort();
103
- const n = new AbortController();
104
- e.current = n;
105
- const d = await new S(o).post({
106
- chat_id: O,
107
- message: r
103
+ (e = s.current) == null || e.abort();
104
+ const t = new AbortController();
105
+ s.current = t;
106
+ const p = n ? {
107
+ "Content-Type": "application/json",
108
+ ...n
109
+ } : {}, y = await new S(a, p).post({
110
+ chat_id: $,
111
+ message: _
108
112
  });
109
- if (!d.ok) {
110
- const C = await d.text().catch(() => "");
111
- throw new Error(`HTTP ${d.status} ${d.statusText} ${C}`);
113
+ if (!y.ok) {
114
+ const w = await y.text().catch(() => "");
115
+ throw new Error(`HTTP ${y.status} ${y.statusText} ${w}`);
112
116
  }
113
- i(d);
114
- } catch (n) {
115
- console.error("Error onSubmit", n);
117
+ u(y);
118
+ } catch (t) {
119
+ console.error("Error onSubmit", t);
116
120
  }
117
121
  },
118
- messages: t
122
+ messages: m
119
123
  };
120
- }, Z = (o) => {
121
- const { onSubmit: t, messages: u } = $(o.api), [i, c] = h(""), m = b(null), l = b(null);
122
- return o.api ? (x(() => {
123
- var e;
124
- (e = m.current) == null || e.scrollIntoView({ behavior: "smooth" });
125
- }, [u]), x(() => () => {
126
- var e;
127
- (e = l.current) == null || e.abort();
128
- }, []), /* @__PURE__ */ a.jsxs("div", { style: { maxWidth: 600, margin: "0 auto" }, children: [
129
- /* @__PURE__ */ a.jsx("h3", { children: "Chat SSE" }),
130
- /* @__PURE__ */ a.jsxs(
124
+ }, tt = (a) => {
125
+ const { onSubmit: n, messages: m } = D(a.api, a.headers), [c, u] = C(""), o = v(null), l = v(null);
126
+ return a.api ? (g(() => {
127
+ var r;
128
+ (r = o.current) == null || r.scrollIntoView({ behavior: "smooth" });
129
+ }, [m]), g(() => () => {
130
+ var r;
131
+ (r = l.current) == null || r.abort();
132
+ }, []), /* @__PURE__ */ i.jsxs("div", { style: { maxWidth: 600, margin: "0 auto" }, children: [
133
+ /* @__PURE__ */ i.jsx("h3", { children: "Chat SSE" }),
134
+ /* @__PURE__ */ i.jsxs(
131
135
  "div",
132
136
  {
133
137
  style: {
@@ -138,145 +142,146 @@ const j = (o) => {
138
142
  overflowY: "auto"
139
143
  },
140
144
  children: [
141
- u.map((e, r) => /* @__PURE__ */ a.jsxs("div", { style: { marginBottom: 8 }, children: [
142
- /* @__PURE__ */ a.jsxs("strong", { children: [
143
- e.role,
145
+ m.map((r, s) => /* @__PURE__ */ i.jsxs("div", { style: { marginBottom: 8 }, children: [
146
+ /* @__PURE__ */ i.jsxs("strong", { children: [
147
+ r.role,
144
148
  ":"
145
149
  ] }),
146
150
  " ",
147
- e.content
148
- ] }, r)),
149
- /* @__PURE__ */ a.jsx("div", { ref: m })
151
+ r.content
152
+ ] }, s)),
153
+ /* @__PURE__ */ i.jsx("div", { ref: o })
150
154
  ]
151
155
  }
152
156
  ),
153
- /* @__PURE__ */ a.jsxs(
157
+ /* @__PURE__ */ i.jsxs(
154
158
  "form",
155
159
  {
156
- onSubmit: (e) => {
157
- e.preventDefault(), t({ input: i, setInput: c, abortRef: l });
160
+ onSubmit: (r) => {
161
+ r.preventDefault(), n({ input: c, setInput: u, abortRef: l });
158
162
  },
159
163
  children: [
160
- /* @__PURE__ */ a.jsx(
164
+ /* @__PURE__ */ i.jsx(
161
165
  "input",
162
166
  {
163
167
  type: "text",
164
- value: i,
165
- onChange: (e) => c(e.target.value),
168
+ value: c,
169
+ onChange: (r) => u(r.target.value),
166
170
  placeholder: "Escribe un mensaje...",
167
171
  style: { width: "80%" }
168
172
  }
169
173
  ),
170
- /* @__PURE__ */ a.jsx("button", { type: "submit", style: { width: "20%" }, children: "Enviar" })
174
+ /* @__PURE__ */ i.jsx("button", { type: "submit", style: { width: "20%" }, children: "Enviar" })
171
175
  ]
172
176
  }
173
177
  )
174
178
  ] })) : (console.error("API is required for the ChatPanel"), null);
175
- }, I = "_inputAction_1541p_1", P = "_inputAction_input_1541p_17", D = "_inputAction_button_1541p_36", f = {
179
+ }, I = "_inputAction_1541p_1", W = "_inputAction_input_1541p_17", q = "_inputAction_button_1541p_36", b = {
176
180
  inputAction: I,
177
- inputAction_input: P,
178
- inputAction_button: D
179
- }, tt = ({
180
- onApply: o = () => {
181
+ inputAction_input: W,
182
+ inputAction_button: q
183
+ }, et = ({
184
+ onApply: a = () => {
181
185
  },
182
- disabled: t = !1,
183
- initialValue: u = ""
186
+ disabled: n = !1,
187
+ initialValue: m = ""
184
188
  }) => {
185
- const [i, c] = h(u), m = T(() => i.trim(), [i]), l = !t && m.length > 0, e = N(() => {
186
- l && o(m);
187
- }, [l, o, m]);
188
- return /* @__PURE__ */ a.jsxs("div", { className: f.inputAction, children: [
189
- /* @__PURE__ */ a.jsx(
189
+ const [c, u] = C(m), o = N(() => c.trim(), [c]), l = !n && o.length > 0, r = E(() => {
190
+ l && a(o);
191
+ }, [l, a, o]);
192
+ return /* @__PURE__ */ i.jsxs("div", { className: b.inputAction, children: [
193
+ /* @__PURE__ */ i.jsx(
190
194
  "input",
191
195
  {
192
- className: f.inputAction_input,
196
+ className: b.inputAction_input,
193
197
  type: "text",
194
- value: i,
195
- onChange: (r) => c(r.target.value),
196
- onKeyDown: (r) => {
197
- r.key === "Enter" && (r.preventDefault(), e());
198
+ value: c,
199
+ onChange: (s) => u(s.target.value),
200
+ onKeyDown: (s) => {
201
+ s.key === "Enter" && (s.preventDefault(), r());
198
202
  },
199
203
  placeholder: "Placeholder",
200
- disabled: t
204
+ disabled: n
201
205
  }
202
206
  ),
203
- /* @__PURE__ */ a.jsx(
207
+ /* @__PURE__ */ i.jsx(
204
208
  "button",
205
209
  {
206
- className: f.inputAction_button,
210
+ className: b.inputAction_button,
207
211
  type: "button",
208
- onClick: e,
212
+ onClick: r,
209
213
  disabled: !l,
210
214
  children: "Aplicar"
211
215
  }
212
216
  )
213
217
  ] });
214
- }, W = "demo-123", H = (o) => {
215
- const [t, u] = h([]), [i, c] = h(!1), { splitChunks: m } = j(u), l = async () => {
216
- try {
217
- c(!0);
218
- const r = await new S(o).post({
219
- chat_id: W,
220
- message: "Hola"
221
- });
222
- if (!r.ok) {
223
- c(!1);
224
- const p = await r.text().catch(() => "");
225
- throw console.error("Error onSubmit"), new Error(`HTTP ${r.status} ${r.statusText} ${p}`);
218
+ }, J = (a, n) => {
219
+ const [m, c] = C(""), [u, o] = C(!1);
220
+ return {
221
+ onSubmit: async (r) => {
222
+ o(!0);
223
+ try {
224
+ const s = n ? {
225
+ "Content-Type": "application/json",
226
+ ...n
227
+ } : {}, e = await new S(a, s).post(r);
228
+ if (e.ok) {
229
+ const t = await e.json();
230
+ c((t == null ? void 0 : t.description) ?? ""), o(!1);
231
+ }
232
+ if (!e.ok) {
233
+ o(!1);
234
+ const t = await e.text().catch(() => "");
235
+ throw new Error(`HTTP ${e.status} ${e.statusText} ${t}`);
236
+ }
237
+ } catch (s) {
238
+ console.error("Error onSubmit", s);
226
239
  }
227
- m(r), c(!1);
228
- } catch (e) {
229
- c(!1), console.error("Error onSubmit", e);
230
- }
231
- };
232
- return x(() => (l(), () => {
233
- console.debug("useSummary: onSubmit: abort");
234
- }), []), {
235
- onSubmit: l,
236
- message: t,
237
- loading: i
240
+ },
241
+ loading: u,
242
+ summary: m
238
243
  };
239
- }, q = "_summaryCard_19k36_1", J = "_summaryCard_header_19k36_17", L = "_summaryCard_titleWrapper_19k36_22", B = "_summaryCard_icon_19k36_27", M = "_summaryCard_title_19k36_22", V = "_summaryCard_button_19k36_40", F = "_summaryCard_content_19k36_66", U = "_summaryCard_loading_19k36_72", Y = "_summaryCard_spinner_19k36_78", z = "_spin_19k36_1", G = "_summaryCard_loadingText_19k36_87", K = "_summaryCard_summaryText_19k36_93", _ = {
240
- summaryCard: q,
241
- summaryCard_header: J,
242
- summaryCard_titleWrapper: L,
243
- summaryCard_icon: B,
244
- summaryCard_title: M,
245
- summaryCard_button: V,
246
- summaryCard_content: F,
247
- summaryCard_loading: U,
248
- summaryCard_spinner: Y,
249
- spin: z,
250
- summaryCard_loadingText: G,
251
- summaryCard_summaryText: K
252
- }, et = ({ api: o }) => {
253
- const { message: t, loading: u, onSubmit: i } = H(o);
254
- return /* @__PURE__ */ a.jsxs("div", { className: _.summaryCard, children: [
255
- /* @__PURE__ */ a.jsxs("div", { className: _.summaryCard_header, children: [
256
- /* @__PURE__ */ a.jsxs("div", { className: _.summaryCard_titleWrapper, children: [
257
- /* @__PURE__ */ a.jsx("span", { className: _.summaryCard_icon, children: "✨" }),
258
- /* @__PURE__ */ a.jsx("h3", { className: _.summaryCard_title, children: "Resumen Inteligente" })
244
+ }, H = "_summaryCard_19k36_1", L = "_summaryCard_header_19k36_17", B = "_summaryCard_titleWrapper_19k36_22", F = "_summaryCard_icon_19k36_27", V = "_summaryCard_title_19k36_22", M = "_summaryCard_button_19k36_40", U = "_summaryCard_content_19k36_66", Y = "_summaryCard_loading_19k36_72", z = "_summaryCard_spinner_19k36_78", G = "_spin_19k36_1", K = "_summaryCard_loadingText_19k36_87", Q = "_summaryCard_summaryText_19k36_93", d = {
245
+ summaryCard: H,
246
+ summaryCard_header: L,
247
+ summaryCard_titleWrapper: B,
248
+ summaryCard_icon: F,
249
+ summaryCard_title: V,
250
+ summaryCard_button: M,
251
+ summaryCard_content: U,
252
+ summaryCard_loading: Y,
253
+ summaryCard_spinner: z,
254
+ spin: G,
255
+ summaryCard_loadingText: K,
256
+ summaryCard_summaryText: Q
257
+ }, nt = ({ api: a, body: n, title: m, headers: c }) => {
258
+ const { summary: u, loading: o, onSubmit: l } = J(a, c);
259
+ return /* @__PURE__ */ i.jsxs("div", { className: d.summaryCard, children: [
260
+ /* @__PURE__ */ i.jsxs("div", { className: d.summaryCard_header, children: [
261
+ /* @__PURE__ */ i.jsxs("div", { className: d.summaryCard_titleWrapper, children: [
262
+ /* @__PURE__ */ i.jsx("span", { className: d.summaryCard_icon, children: "✨" }),
263
+ /* @__PURE__ */ i.jsx("h3", { className: d.summaryCard_title, children: m })
259
264
  ] }),
260
- /* @__PURE__ */ a.jsx(
265
+ !o && !u && /* @__PURE__ */ i.jsx(
261
266
  "button",
262
267
  {
263
- onClick: () => i(),
264
- className: _.summaryCard_button,
268
+ onClick: () => l(n),
269
+ className: d.summaryCard_button,
265
270
  children: "Generar Resumen"
266
271
  }
267
272
  )
268
273
  ] }),
269
- /* @__PURE__ */ a.jsxs("div", { className: _.summaryCard_content, children: [
270
- u && !t && /* @__PURE__ */ a.jsxs("div", { className: _.summaryCard_loading, children: [
271
- /* @__PURE__ */ a.jsx("div", { className: _.summaryCard_spinner }),
272
- /* @__PURE__ */ a.jsx("p", { className: _.summaryCard_loadingText, children: "Analizando contenido..." })
274
+ /* @__PURE__ */ i.jsxs("div", { className: d.summaryCard_content, children: [
275
+ o && !u && /* @__PURE__ */ i.jsxs("div", { className: d.summaryCard_loading, children: [
276
+ /* @__PURE__ */ i.jsx("div", { className: d.summaryCard_spinner }),
277
+ /* @__PURE__ */ i.jsx("p", { className: d.summaryCard_loadingText, children: "Analizando contenido..." })
273
278
  ] }),
274
- t && /* @__PURE__ */ a.jsx("div", { className: _.summaryCard_summaryText, children: t.map((c) => c.content) })
279
+ u && /* @__PURE__ */ i.jsx("div", { className: d.summaryCard_summaryText, children: u })
275
280
  ] })
276
281
  ] });
277
282
  };
278
283
  export {
279
- Z as ChatPanel,
280
- tt as InputAction,
281
- et as SummaryCard
284
+ tt as ChatPanel,
285
+ et as InputAction,
286
+ nt as SummaryCard
282
287
  };
@@ -1,4 +1,4 @@
1
- (function(d,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],s):(d=typeof globalThis<"u"?globalThis:d||self,s(d["foris-ai-agent"]={},d.React))})(this,function(d,s){"use strict";var P=Object.defineProperty;var I=(d,s,f)=>s in d?P(d,s,{enumerable:!0,configurable:!0,writable:!0,value:f}):d[s]=f;var j=(d,s,f)=>(I(d,typeof s!="symbol"?s+"":s,f),f);var f={exports:{}},C={};/**
1
+ (function(l,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],r):(l=typeof globalThis<"u"?globalThis:l||self,r(l["foris-ai-agent"]={},l.React))})(this,function(l,r){"use strict";var I=Object.defineProperty;var W=(l,r,h)=>r in l?I(l,r,{enumerable:!0,configurable:!0,writable:!0,value:h}):l[r]=h;var v=(l,r,h)=>(W(l,typeof r!="symbol"?r+"":r,h),h);var h={exports:{}},f={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,5 +6,5 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var b;function k(){if(b)return C;b=1;var l=s,o=Symbol.for("react.element"),_=Symbol.for("react.fragment"),i=Object.prototype.hasOwnProperty,u=l.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c={key:!0,ref:!0,__self:!0,__source:!0};function m(t,e,h){var n,r={},p=null,x=null;h!==void 0&&(p=""+h),e.key!==void 0&&(p=""+e.key),e.ref!==void 0&&(x=e.ref);for(n in e)i.call(e,n)&&!c.hasOwnProperty(n)&&(r[n]=e[n]);if(t&&t.defaultProps)for(n in e=t.defaultProps,e)r[n]===void 0&&(r[n]=e[n]);return{$$typeof:o,type:t,key:p,ref:x,props:r,_owner:u.current}}return C.Fragment=_,C.jsx=m,C.jsxs=m,C}f.exports=k();var a=f.exports;class v{constructor(o){j(this,"api");this.api=o}post(o){return fetch(this.api,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)})}}const S=l=>{const o=i=>{i&&l(u=>{const c=u[u.length-1];return(c==null?void 0:c.role)==="assistant"?[...u.slice(0,-1),{role:"assistant",content:c.content+i}]:[...u,{role:"assistant",content:i}]})};return{splitChunks:async i=>{if(i.body){const u=i.body.getReader(),c=new TextDecoder;let m="";for(;;){const{done:t,value:e}=await u.read();if(t)break;m+=c.decode(e,{stream:!0});const h=m.split(`
10
- `);m=h.pop()??"";for(let n of h)if(n=n.trim(),!!n&&!n.startsWith(":")&&!n.startsWith("event:")&&(n.startsWith("data:")&&(n=n.slice(5).trim()),!!n)){if(n==="[DONE]")return;try{const r=JSON.parse(n),p=(r==null?void 0:r.type)==="token"?typeof r.value=="string"?r.value:typeof r.content=="string"?r.content:"":(r==null?void 0:r.type)==="chunk"?typeof r.content=="string"?r.content:typeof r.value=="string"?r.value:"":typeof(r==null?void 0:r.message)=="string"?r.message:"";p&&o(p)}catch{o(n)}}}}}}},A="demo-123",T=l=>{const[o,_]=s.useState([]),{splitChunks:i}=S(_);return{onSubmit:async({input:c,setInput:m,abortRef:t})=>{var h;if(!c.trim())return;const e=c;m(""),_(n=>[...n,{role:"user",content:e},{role:"assistant",content:""}]);try{(h=t.current)==null||h.abort();const n=new AbortController;t.current=n;const p=await new v(l).post({chat_id:A,message:e});if(!p.ok){const x=await p.text().catch(()=>"");throw new Error(`HTTP ${p.status} ${p.statusText} ${x}`)}i(p)}catch(n){console.error("Error onSubmit",n)}},messages:o}},R=l=>{const{onSubmit:o,messages:_}=T(l.api),[i,u]=s.useState(""),c=s.useRef(null),m=s.useRef(null);return l.api?(s.useEffect(()=>{var t;(t=c.current)==null||t.scrollIntoView({behavior:"smooth"})},[_]),s.useEffect(()=>()=>{var t;(t=m.current)==null||t.abort()},[]),a.jsxs("div",{style:{maxWidth:600,margin:"0 auto"},children:[a.jsx("h3",{children:"Chat SSE"}),a.jsxs("div",{style:{border:"1px solid #ccc",padding:12,minHeight:300,marginBottom:12,overflowY:"auto"},children:[_.map((t,e)=>a.jsxs("div",{style:{marginBottom:8},children:[a.jsxs("strong",{children:[t.role,":"]})," ",t.content]},e)),a.jsx("div",{ref:c})]}),a.jsxs("form",{onSubmit:t=>{t.preventDefault(),o({input:i,setInput:u,abortRef:m})},children:[a.jsx("input",{type:"text",value:i,onChange:t=>u(t.target.value),placeholder:"Escribe un mensaje...",style:{width:"80%"}}),a.jsx("button",{type:"submit",style:{width:"20%"},children:"Enviar"})]})]})):(console.error("API is required for the ChatPanel"),null)},g={inputAction:"_inputAction_1541p_1",inputAction_input:"_inputAction_input_1541p_17",inputAction_button:"_inputAction_button_1541p_36"},w=({onApply:l=()=>{},disabled:o=!1,initialValue:_=""})=>{const[i,u]=s.useState(_),c=s.useMemo(()=>i.trim(),[i]),m=!o&&c.length>0,t=s.useCallback(()=>{m&&l(c)},[m,l,c]);return a.jsxs("div",{className:g.inputAction,children:[a.jsx("input",{className:g.inputAction_input,type:"text",value:i,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.preventDefault(),t())},placeholder:"Placeholder",disabled:o}),a.jsx("button",{className:g.inputAction_button,type:"button",onClick:t,disabled:!m,children:"Aplicar"})]})},E="demo-123",N=l=>{const[o,_]=s.useState([]),[i,u]=s.useState(!1),{splitChunks:c}=S(_),m=async()=>{try{u(!0);const e=await new v(l).post({chat_id:E,message:"Hola"});if(!e.ok){u(!1);const h=await e.text().catch(()=>"");throw console.error("Error onSubmit"),new Error(`HTTP ${e.status} ${e.statusText} ${h}`)}c(e),u(!1)}catch(t){u(!1),console.error("Error onSubmit",t)}};return s.useEffect(()=>(m(),()=>{console.debug("useSummary: onSubmit: abort")}),[]),{onSubmit:m,message:o,loading:i}},y={summaryCard:"_summaryCard_19k36_1",summaryCard_header:"_summaryCard_header_19k36_17",summaryCard_titleWrapper:"_summaryCard_titleWrapper_19k36_22",summaryCard_icon:"_summaryCard_icon_19k36_27",summaryCard_title:"_summaryCard_title_19k36_22",summaryCard_button:"_summaryCard_button_19k36_40",summaryCard_content:"_summaryCard_content_19k36_66",summaryCard_loading:"_summaryCard_loading_19k36_72",summaryCard_spinner:"_summaryCard_spinner_19k36_78",spin:"_spin_19k36_1",summaryCard_loadingText:"_summaryCard_loadingText_19k36_87",summaryCard_summaryText:"_summaryCard_summaryText_19k36_93"},O=({api:l})=>{const{message:o,loading:_,onSubmit:i}=N(l);return a.jsxs("div",{className:y.summaryCard,children:[a.jsxs("div",{className:y.summaryCard_header,children:[a.jsxs("div",{className:y.summaryCard_titleWrapper,children:[a.jsx("span",{className:y.summaryCard_icon,children:"✨"}),a.jsx("h3",{className:y.summaryCard_title,children:"Resumen Inteligente"})]}),a.jsx("button",{onClick:()=>i(),className:y.summaryCard_button,children:"Generar Resumen"})]}),a.jsxs("div",{className:y.summaryCard_content,children:[_&&!o&&a.jsxs("div",{className:y.summaryCard_loading,children:[a.jsx("div",{className:y.summaryCard_spinner}),a.jsx("p",{className:y.summaryCard_loadingText,children:"Analizando contenido..."})]}),o&&a.jsx("div",{className:y.summaryCard_summaryText,children:o.map(u=>u.content)})]})]})};d.ChatPanel=R,d.InputAction=w,d.SummaryCard=O,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
9
+ */var j;function k(){if(j)return f;j=1;var d=r,u=Symbol.for("react.element"),_=Symbol.for("react.fragment"),i=Object.prototype.hasOwnProperty,c=d.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function m(n,s,y){var e,t={},C=null,g=null;y!==void 0&&(C=""+y),s.key!==void 0&&(C=""+s.key),s.ref!==void 0&&(g=s.ref);for(e in s)i.call(s,e)&&!o.hasOwnProperty(e)&&(t[e]=s[e]);if(n&&n.defaultProps)for(e in s=n.defaultProps,s)t[e]===void 0&&(t[e]=s[e]);return{$$typeof:u,type:n,key:C,ref:g,props:t,_owner:c.current}}return f.Fragment=_,f.jsx=m,f.jsxs=m,f}h.exports=k();var a=h.exports;class S{constructor(u,_){v(this,"api");v(this,"headers",{"Content-Type":"application/json"});this.api=u,this.headers=_??this.headers}post(u){return fetch(this.api,{method:"POST",headers:this.headers,body:JSON.stringify(u)})}}const T=d=>{const u=i=>{i&&d(c=>{const o=c[c.length-1];return(o==null?void 0:o.role)==="assistant"?[...c.slice(0,-1),{role:"assistant",content:o.content+i}]:[...c,{role:"assistant",content:i}]})};return{splitChunks:async i=>{if(i.body){const c=i.body.getReader(),o=new TextDecoder;let m="";for(;;){const{done:n,value:s}=await c.read();if(n)break;m+=o.decode(s,{stream:!0});const y=m.split(`
10
+ `);m=y.pop()??"";for(let e of y)if(e=e.trim(),!!e&&!e.startsWith(":")&&!e.startsWith("event:")&&(e.startsWith("data:")&&(e=e.slice(5).trim()),!!e)){if(e==="[DONE]")return;try{const t=JSON.parse(e),C=(t==null?void 0:t.type)==="token"?typeof t.value=="string"?t.value:typeof t.content=="string"?t.content:"":(t==null?void 0:t.type)==="chunk"?typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:"":typeof(t==null?void 0:t.message)=="string"?t.message:"";C&&u(C)}catch{u(e)}}}}}}},A="demo-123",w=(d,u)=>{const[_,i]=r.useState([]),{splitChunks:c}=T(i);return{onSubmit:async({input:m,setInput:n,abortRef:s})=>{var e;if(!m.trim())return;const y=m;n(""),i(t=>[...t,{role:"user",content:y},{role:"assistant",content:""}]);try{(e=s.current)==null||e.abort();const t=new AbortController;s.current=t;const C=u?{"Content-Type":"application/json",...u}:{},x=await new S(d,C).post({chat_id:A,message:y});if(!x.ok){const P=await x.text().catch(()=>"");throw new Error(`HTTP ${x.status} ${x.statusText} ${P}`)}c(x)}catch(t){console.error("Error onSubmit",t)}},messages:_}},R=d=>{const{onSubmit:u,messages:_}=w(d.api,d.headers),[i,c]=r.useState(""),o=r.useRef(null),m=r.useRef(null);return d.api?(r.useEffect(()=>{var n;(n=o.current)==null||n.scrollIntoView({behavior:"smooth"})},[_]),r.useEffect(()=>()=>{var n;(n=m.current)==null||n.abort()},[]),a.jsxs("div",{style:{maxWidth:600,margin:"0 auto"},children:[a.jsx("h3",{children:"Chat SSE"}),a.jsxs("div",{style:{border:"1px solid #ccc",padding:12,minHeight:300,marginBottom:12,overflowY:"auto"},children:[_.map((n,s)=>a.jsxs("div",{style:{marginBottom:8},children:[a.jsxs("strong",{children:[n.role,":"]})," ",n.content]},s)),a.jsx("div",{ref:o})]}),a.jsxs("form",{onSubmit:n=>{n.preventDefault(),u({input:i,setInput:c,abortRef:m})},children:[a.jsx("input",{type:"text",value:i,onChange:n=>c(n.target.value),placeholder:"Escribe un mensaje...",style:{width:"80%"}}),a.jsx("button",{type:"submit",style:{width:"20%"},children:"Enviar"})]})]})):(console.error("API is required for the ChatPanel"),null)},b={inputAction:"_inputAction_1541p_1",inputAction_input:"_inputAction_input_1541p_17",inputAction_button:"_inputAction_button_1541p_36"},N=({onApply:d=()=>{},disabled:u=!1,initialValue:_=""})=>{const[i,c]=r.useState(_),o=r.useMemo(()=>i.trim(),[i]),m=!u&&o.length>0,n=r.useCallback(()=>{m&&d(o)},[m,d,o]);return a.jsxs("div",{className:b.inputAction,children:[a.jsx("input",{className:b.inputAction_input,type:"text",value:i,onChange:s=>c(s.target.value),onKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),n())},placeholder:"Placeholder",disabled:u}),a.jsx("button",{className:b.inputAction_button,type:"button",onClick:n,disabled:!m,children:"Aplicar"})]})},E=(d,u)=>{const[_,i]=r.useState(""),[c,o]=r.useState(!1);return{onSubmit:async n=>{o(!0);try{const s=u?{"Content-Type":"application/json",...u}:{},e=await new S(d,s).post(n);if(e.ok){const t=await e.json();i((t==null?void 0:t.description)??""),o(!1)}if(!e.ok){o(!1);const t=await e.text().catch(()=>"");throw new Error(`HTTP ${e.status} ${e.statusText} ${t}`)}}catch(s){console.error("Error onSubmit",s)}},loading:c,summary:_}},p={summaryCard:"_summaryCard_19k36_1",summaryCard_header:"_summaryCard_header_19k36_17",summaryCard_titleWrapper:"_summaryCard_titleWrapper_19k36_22",summaryCard_icon:"_summaryCard_icon_19k36_27",summaryCard_title:"_summaryCard_title_19k36_22",summaryCard_button:"_summaryCard_button_19k36_40",summaryCard_content:"_summaryCard_content_19k36_66",summaryCard_loading:"_summaryCard_loading_19k36_72",summaryCard_spinner:"_summaryCard_spinner_19k36_78",spin:"_spin_19k36_1",summaryCard_loadingText:"_summaryCard_loadingText_19k36_87",summaryCard_summaryText:"_summaryCard_summaryText_19k36_93"},O=({api:d,body:u,title:_,headers:i})=>{const{summary:c,loading:o,onSubmit:m}=E(d,i);return a.jsxs("div",{className:p.summaryCard,children:[a.jsxs("div",{className:p.summaryCard_header,children:[a.jsxs("div",{className:p.summaryCard_titleWrapper,children:[a.jsx("span",{className:p.summaryCard_icon,children:"✨"}),a.jsx("h3",{className:p.summaryCard_title,children:_})]}),!o&&!c&&a.jsx("button",{onClick:()=>m(u),className:p.summaryCard_button,children:"Generar Resumen"})]}),a.jsxs("div",{className:p.summaryCard_content,children:[o&&!c&&a.jsxs("div",{className:p.summaryCard_loading,children:[a.jsx("div",{className:p.summaryCard_spinner}),a.jsx("p",{className:p.summaryCard_loadingText,children:"Analizando contenido..."})]}),c&&a.jsx("div",{className:p.summaryCard_summaryText,children:c})]})]})};l.ChatPanel=R,l.InputAction=N,l.SummaryCard=O,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
@@ -1,5 +1,6 @@
1
1
  interface ChatPanelProps {
2
2
  api: string;
3
+ headers?: any;
3
4
  }
4
5
  export declare const ChatPanel: (props: ChatPanelProps) => JSX.Element | null;
5
6
  export default ChatPanel;
@@ -1,6 +1,9 @@
1
1
  import React from 'react';
2
2
  interface Props {
3
+ title: string;
3
4
  api: string;
5
+ body: any;
6
+ headers?: any;
4
7
  }
5
8
  export declare const SummaryCard: React.FC<Props>;
6
9
  export {};
@@ -9,7 +9,7 @@ interface OnSubmitProps {
9
9
  setInput: (input: string) => void;
10
10
  abortRef: MutableRefObject<AbortController | null>;
11
11
  }
12
- export declare const useChat: (api: string) => {
12
+ export declare const useChat: (api: string, headers?: any) => {
13
13
  onSubmit: ({ input, setInput, abortRef }: OnSubmitProps) => Promise<void>;
14
14
  messages: ChatMessage[];
15
15
  };
@@ -1,14 +1,5 @@
1
- type Role = 'user' | 'assistant';
2
- interface ChatMessage {
3
- role: Role;
4
- content: string;
5
- }
6
- /**
7
- * TODO: Implement the useSummary hook
8
- */
9
- export declare const useSummary: (api: string) => {
10
- onSubmit: () => Promise<void>;
11
- message: ChatMessage[];
1
+ export declare const useSummary: (api: string, headers?: any) => {
2
+ onSubmit: (body: any) => Promise<void>;
12
3
  loading: boolean;
4
+ summary: string;
13
5
  };
14
- export {};
@@ -0,0 +1,6 @@
1
+ export declare class FetchApi {
2
+ private api;
3
+ private headers;
4
+ constructor(api: string, headers?: any);
5
+ post(body: any): Promise<Response>;
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foris/ai-agent",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -1,5 +0,0 @@
1
- export declare class StreamApiService {
2
- private api;
3
- constructor(api: string);
4
- post(body: any): Promise<Response>;
5
- }