@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.
- package/dist/ai-agent.es.js +179 -174
- package/dist/ai-agent.umd.js +3 -3
- package/dist/ai-chat-panel/ChatPanel.d.ts +1 -0
- package/dist/ai-summary-card/SummaryCard.d.ts +3 -0
- package/dist/hooks/useChat.d.ts +1 -1
- package/dist/hooks/useSummary.d.ts +3 -12
- package/dist/services/fetch-api/FetchApi.d.ts +6 -0
- package/package.json +1 -1
- package/dist/services/stream-api/StreamApi.d.ts +0 -5
package/dist/ai-agent.es.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
var A = (
|
|
3
|
-
var
|
|
4
|
-
import R, { useState as
|
|
5
|
-
var k = { exports: {} },
|
|
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
|
|
16
|
-
function
|
|
17
|
-
if (
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
function l(
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
for (
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
for (
|
|
28
|
-
|
|
29
|
-
return { $$typeof:
|
|
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
|
|
31
|
+
return h.Fragment = m, h.jsx = l, h.jsxs = l, h;
|
|
32
32
|
}
|
|
33
|
-
k.exports =
|
|
34
|
-
var
|
|
33
|
+
k.exports = O();
|
|
34
|
+
var i = k.exports;
|
|
35
35
|
class S {
|
|
36
|
-
constructor(
|
|
37
|
-
|
|
38
|
-
this
|
|
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(
|
|
43
|
+
post(n) {
|
|
41
44
|
return fetch(this.api, {
|
|
42
45
|
method: "POST",
|
|
43
|
-
headers:
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
body: JSON.stringify(t)
|
|
46
|
+
headers: this.headers,
|
|
47
|
+
body: JSON.stringify(n)
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
return (
|
|
55
|
-
...
|
|
56
|
-
{ role: "assistant", content:
|
|
57
|
-
] : [...
|
|
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 (
|
|
62
|
-
if (
|
|
63
|
-
const
|
|
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:
|
|
67
|
-
if (
|
|
67
|
+
const { done: r, value: s } = await u.read();
|
|
68
|
+
if (r)
|
|
68
69
|
break;
|
|
69
|
-
l +=
|
|
70
|
-
const
|
|
70
|
+
l += o.decode(s, { stream: !0 });
|
|
71
|
+
const _ = l.split(`
|
|
71
72
|
`);
|
|
72
|
-
l =
|
|
73
|
-
for (let
|
|
74
|
-
if (
|
|
75
|
-
if (
|
|
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
|
|
79
|
-
|
|
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
|
-
|
|
82
|
+
n(e);
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
};
|
|
88
|
-
},
|
|
89
|
-
const [
|
|
89
|
+
}, $ = "demo-123", D = (a, n) => {
|
|
90
|
+
const [m, c] = C([]), { splitChunks: u } = P(c);
|
|
90
91
|
return {
|
|
91
|
-
onSubmit: async ({ input:
|
|
92
|
-
var
|
|
93
|
-
if (!
|
|
92
|
+
onSubmit: async ({ input: l, setInput: r, abortRef: s }) => {
|
|
93
|
+
var e;
|
|
94
|
+
if (!l.trim())
|
|
94
95
|
return;
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
...
|
|
98
|
-
{ role: "user", content:
|
|
96
|
+
const _ = l;
|
|
97
|
+
r(""), c((t) => [
|
|
98
|
+
...t,
|
|
99
|
+
{ role: "user", content: _ },
|
|
99
100
|
{ role: "assistant", content: "" }
|
|
100
101
|
]);
|
|
101
102
|
try {
|
|
102
|
-
(
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
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 (!
|
|
110
|
-
const
|
|
111
|
-
throw new Error(`HTTP ${
|
|
113
|
+
if (!y.ok) {
|
|
114
|
+
const w = await y.text().catch(() => "");
|
|
115
|
+
throw new Error(`HTTP ${y.status} ${y.statusText} ${w}`);
|
|
112
116
|
}
|
|
113
|
-
|
|
114
|
-
} catch (
|
|
115
|
-
console.error("Error onSubmit",
|
|
117
|
+
u(y);
|
|
118
|
+
} catch (t) {
|
|
119
|
+
console.error("Error onSubmit", t);
|
|
116
120
|
}
|
|
117
121
|
},
|
|
118
|
-
messages:
|
|
122
|
+
messages: m
|
|
119
123
|
};
|
|
120
|
-
},
|
|
121
|
-
const { onSubmit:
|
|
122
|
-
return
|
|
123
|
-
var
|
|
124
|
-
(
|
|
125
|
-
}, [
|
|
126
|
-
var
|
|
127
|
-
(
|
|
128
|
-
}, []), /* @__PURE__ */
|
|
129
|
-
/* @__PURE__ */
|
|
130
|
-
/* @__PURE__ */
|
|
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
|
-
|
|
142
|
-
/* @__PURE__ */
|
|
143
|
-
|
|
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
|
-
|
|
148
|
-
] },
|
|
149
|
-
/* @__PURE__ */
|
|
151
|
+
r.content
|
|
152
|
+
] }, s)),
|
|
153
|
+
/* @__PURE__ */ i.jsx("div", { ref: o })
|
|
150
154
|
]
|
|
151
155
|
}
|
|
152
156
|
),
|
|
153
|
-
/* @__PURE__ */
|
|
157
|
+
/* @__PURE__ */ i.jsxs(
|
|
154
158
|
"form",
|
|
155
159
|
{
|
|
156
|
-
onSubmit: (
|
|
157
|
-
|
|
160
|
+
onSubmit: (r) => {
|
|
161
|
+
r.preventDefault(), n({ input: c, setInput: u, abortRef: l });
|
|
158
162
|
},
|
|
159
163
|
children: [
|
|
160
|
-
/* @__PURE__ */
|
|
164
|
+
/* @__PURE__ */ i.jsx(
|
|
161
165
|
"input",
|
|
162
166
|
{
|
|
163
167
|
type: "text",
|
|
164
|
-
value:
|
|
165
|
-
onChange: (
|
|
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__ */
|
|
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",
|
|
179
|
+
}, I = "_inputAction_1541p_1", W = "_inputAction_input_1541p_17", q = "_inputAction_button_1541p_36", b = {
|
|
176
180
|
inputAction: I,
|
|
177
|
-
inputAction_input:
|
|
178
|
-
inputAction_button:
|
|
179
|
-
},
|
|
180
|
-
onApply:
|
|
181
|
+
inputAction_input: W,
|
|
182
|
+
inputAction_button: q
|
|
183
|
+
}, et = ({
|
|
184
|
+
onApply: a = () => {
|
|
181
185
|
},
|
|
182
|
-
disabled:
|
|
183
|
-
initialValue:
|
|
186
|
+
disabled: n = !1,
|
|
187
|
+
initialValue: m = ""
|
|
184
188
|
}) => {
|
|
185
|
-
const [
|
|
186
|
-
l && o
|
|
187
|
-
}, [l,
|
|
188
|
-
return /* @__PURE__ */
|
|
189
|
-
/* @__PURE__ */
|
|
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:
|
|
196
|
+
className: b.inputAction_input,
|
|
193
197
|
type: "text",
|
|
194
|
-
value:
|
|
195
|
-
onChange: (
|
|
196
|
-
onKeyDown: (
|
|
197
|
-
|
|
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:
|
|
204
|
+
disabled: n
|
|
201
205
|
}
|
|
202
206
|
),
|
|
203
|
-
/* @__PURE__ */
|
|
207
|
+
/* @__PURE__ */ i.jsx(
|
|
204
208
|
"button",
|
|
205
209
|
{
|
|
206
|
-
className:
|
|
210
|
+
className: b.inputAction_button,
|
|
207
211
|
type: "button",
|
|
208
|
-
onClick:
|
|
212
|
+
onClick: r,
|
|
209
213
|
disabled: !l,
|
|
210
214
|
children: "Aplicar"
|
|
211
215
|
}
|
|
212
216
|
)
|
|
213
217
|
] });
|
|
214
|
-
},
|
|
215
|
-
const [
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
},
|
|
240
|
-
summaryCard:
|
|
241
|
-
summaryCard_header:
|
|
242
|
-
summaryCard_titleWrapper:
|
|
243
|
-
summaryCard_icon:
|
|
244
|
-
summaryCard_title:
|
|
245
|
-
summaryCard_button:
|
|
246
|
-
summaryCard_content:
|
|
247
|
-
summaryCard_loading:
|
|
248
|
-
summaryCard_spinner:
|
|
249
|
-
spin:
|
|
250
|
-
summaryCard_loadingText:
|
|
251
|
-
summaryCard_summaryText:
|
|
252
|
-
},
|
|
253
|
-
const {
|
|
254
|
-
return /* @__PURE__ */
|
|
255
|
-
/* @__PURE__ */
|
|
256
|
-
/* @__PURE__ */
|
|
257
|
-
/* @__PURE__ */
|
|
258
|
-
/* @__PURE__ */
|
|
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__ */
|
|
265
|
+
!o && !u && /* @__PURE__ */ i.jsx(
|
|
261
266
|
"button",
|
|
262
267
|
{
|
|
263
|
-
onClick: () =>
|
|
264
|
-
className:
|
|
268
|
+
onClick: () => l(n),
|
|
269
|
+
className: d.summaryCard_button,
|
|
265
270
|
children: "Generar Resumen"
|
|
266
271
|
}
|
|
267
272
|
)
|
|
268
273
|
] }),
|
|
269
|
-
/* @__PURE__ */
|
|
270
|
-
|
|
271
|
-
/* @__PURE__ */
|
|
272
|
-
/* @__PURE__ */
|
|
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
|
-
|
|
279
|
+
u && /* @__PURE__ */ i.jsx("div", { className: d.summaryCard_summaryText, children: u })
|
|
275
280
|
] })
|
|
276
281
|
] });
|
|
277
282
|
};
|
|
278
283
|
export {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
284
|
+
tt as ChatPanel,
|
|
285
|
+
et as InputAction,
|
|
286
|
+
nt as SummaryCard
|
|
282
287
|
};
|
package/dist/ai-agent.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
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
|
|
10
|
-
`);m=
|
|
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"})});
|
package/dist/hooks/useChat.d.ts
CHANGED
|
@@ -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
|
-
|
|
2
|
-
|
|
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 {};
|
package/package.json
CHANGED