@foris/ai-agent 0.1.0
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 +282 -0
- package/dist/ai-agent.umd.js +10 -0
- package/dist/ai-chat-panel/ChatPanel.d.ts +5 -0
- package/dist/ai-chat-panel/index.d.ts +1 -0
- package/dist/ai-input-action/InputAction.d.ts +8 -0
- package/dist/ai-input-action/index.d.ts +1 -0
- package/dist/ai-summary-card/SummaryCard.d.ts +6 -0
- package/dist/ai-summary-card/index.d.ts +1 -0
- package/dist/hooks/useChat.d.ts +16 -0
- package/dist/hooks/useSplitChunks.d.ts +3 -0
- package/dist/hooks/useSummary.d.ts +14 -0
- package/dist/index.d.ts +4 -0
- package/dist/services/stream-api/StreamApi.d.ts +5 -0
- package/dist/style.css +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,282 @@
|
|
|
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 = {};
|
|
6
|
+
/**
|
|
7
|
+
* @license React
|
|
8
|
+
* react-jsx-runtime.production.min.js
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
11
|
+
*
|
|
12
|
+
* This source code is licensed under the MIT license found in the
|
|
13
|
+
* LICENSE file in the root directory of this source tree.
|
|
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 };
|
|
30
|
+
}
|
|
31
|
+
return y.Fragment = u, y.jsx = l, y.jsxs = l, y;
|
|
32
|
+
}
|
|
33
|
+
k.exports = E();
|
|
34
|
+
var a = k.exports;
|
|
35
|
+
class S {
|
|
36
|
+
constructor(t) {
|
|
37
|
+
g(this, "api");
|
|
38
|
+
this.api = t;
|
|
39
|
+
}
|
|
40
|
+
post(t) {
|
|
41
|
+
return fetch(this.api, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: {
|
|
44
|
+
"Content-Type": "application/json"
|
|
45
|
+
},
|
|
46
|
+
body: JSON.stringify(t)
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
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 }];
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
splitChunks: async (i) => {
|
|
62
|
+
if (i.body) {
|
|
63
|
+
const c = i.body.getReader(), m = new TextDecoder();
|
|
64
|
+
let l = "";
|
|
65
|
+
for (; ; ) {
|
|
66
|
+
const { done: e, value: r } = await c.read();
|
|
67
|
+
if (e)
|
|
68
|
+
break;
|
|
69
|
+
l += m.decode(r, { stream: !0 });
|
|
70
|
+
const p = l.split(`
|
|
71
|
+
`);
|
|
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]")
|
|
76
|
+
return;
|
|
77
|
+
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);
|
|
80
|
+
} catch {
|
|
81
|
+
t(n);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}, O = "demo-123", $ = (o) => {
|
|
89
|
+
const [t, u] = h([]), { splitChunks: i } = j(u);
|
|
90
|
+
return {
|
|
91
|
+
onSubmit: async ({ input: m, setInput: l, abortRef: e }) => {
|
|
92
|
+
var p;
|
|
93
|
+
if (!m.trim())
|
|
94
|
+
return;
|
|
95
|
+
const r = m;
|
|
96
|
+
l(""), u((n) => [
|
|
97
|
+
...n,
|
|
98
|
+
{ role: "user", content: r },
|
|
99
|
+
{ role: "assistant", content: "" }
|
|
100
|
+
]);
|
|
101
|
+
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
|
|
108
|
+
});
|
|
109
|
+
if (!d.ok) {
|
|
110
|
+
const C = await d.text().catch(() => "");
|
|
111
|
+
throw new Error(`HTTP ${d.status} ${d.statusText} ${C}`);
|
|
112
|
+
}
|
|
113
|
+
i(d);
|
|
114
|
+
} catch (n) {
|
|
115
|
+
console.error("Error onSubmit", n);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
messages: t
|
|
119
|
+
};
|
|
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(
|
|
131
|
+
"div",
|
|
132
|
+
{
|
|
133
|
+
style: {
|
|
134
|
+
border: "1px solid #ccc",
|
|
135
|
+
padding: 12,
|
|
136
|
+
minHeight: 300,
|
|
137
|
+
marginBottom: 12,
|
|
138
|
+
overflowY: "auto"
|
|
139
|
+
},
|
|
140
|
+
children: [
|
|
141
|
+
u.map((e, r) => /* @__PURE__ */ a.jsxs("div", { style: { marginBottom: 8 }, children: [
|
|
142
|
+
/* @__PURE__ */ a.jsxs("strong", { children: [
|
|
143
|
+
e.role,
|
|
144
|
+
":"
|
|
145
|
+
] }),
|
|
146
|
+
" ",
|
|
147
|
+
e.content
|
|
148
|
+
] }, r)),
|
|
149
|
+
/* @__PURE__ */ a.jsx("div", { ref: m })
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
),
|
|
153
|
+
/* @__PURE__ */ a.jsxs(
|
|
154
|
+
"form",
|
|
155
|
+
{
|
|
156
|
+
onSubmit: (e) => {
|
|
157
|
+
e.preventDefault(), t({ input: i, setInput: c, abortRef: l });
|
|
158
|
+
},
|
|
159
|
+
children: [
|
|
160
|
+
/* @__PURE__ */ a.jsx(
|
|
161
|
+
"input",
|
|
162
|
+
{
|
|
163
|
+
type: "text",
|
|
164
|
+
value: i,
|
|
165
|
+
onChange: (e) => c(e.target.value),
|
|
166
|
+
placeholder: "Escribe un mensaje...",
|
|
167
|
+
style: { width: "80%" }
|
|
168
|
+
}
|
|
169
|
+
),
|
|
170
|
+
/* @__PURE__ */ a.jsx("button", { type: "submit", style: { width: "20%" }, children: "Enviar" })
|
|
171
|
+
]
|
|
172
|
+
}
|
|
173
|
+
)
|
|
174
|
+
] })) : (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 = {
|
|
176
|
+
inputAction: I,
|
|
177
|
+
inputAction_input: P,
|
|
178
|
+
inputAction_button: D
|
|
179
|
+
}, tt = ({
|
|
180
|
+
onApply: o = () => {
|
|
181
|
+
},
|
|
182
|
+
disabled: t = !1,
|
|
183
|
+
initialValue: u = ""
|
|
184
|
+
}) => {
|
|
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(
|
|
190
|
+
"input",
|
|
191
|
+
{
|
|
192
|
+
className: f.inputAction_input,
|
|
193
|
+
type: "text",
|
|
194
|
+
value: i,
|
|
195
|
+
onChange: (r) => c(r.target.value),
|
|
196
|
+
onKeyDown: (r) => {
|
|
197
|
+
r.key === "Enter" && (r.preventDefault(), e());
|
|
198
|
+
},
|
|
199
|
+
placeholder: "Placeholder",
|
|
200
|
+
disabled: t
|
|
201
|
+
}
|
|
202
|
+
),
|
|
203
|
+
/* @__PURE__ */ a.jsx(
|
|
204
|
+
"button",
|
|
205
|
+
{
|
|
206
|
+
className: f.inputAction_button,
|
|
207
|
+
type: "button",
|
|
208
|
+
onClick: e,
|
|
209
|
+
disabled: !l,
|
|
210
|
+
children: "Aplicar"
|
|
211
|
+
}
|
|
212
|
+
)
|
|
213
|
+
] });
|
|
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}`);
|
|
226
|
+
}
|
|
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
|
|
238
|
+
};
|
|
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" })
|
|
259
|
+
] }),
|
|
260
|
+
/* @__PURE__ */ a.jsx(
|
|
261
|
+
"button",
|
|
262
|
+
{
|
|
263
|
+
onClick: () => i(),
|
|
264
|
+
className: _.summaryCard_button,
|
|
265
|
+
children: "Generar Resumen"
|
|
266
|
+
}
|
|
267
|
+
)
|
|
268
|
+
] }),
|
|
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..." })
|
|
273
|
+
] }),
|
|
274
|
+
t && /* @__PURE__ */ a.jsx("div", { className: _.summaryCard_summaryText, children: t.map((c) => c.content) })
|
|
275
|
+
] })
|
|
276
|
+
] });
|
|
277
|
+
};
|
|
278
|
+
export {
|
|
279
|
+
Z as ChatPanel,
|
|
280
|
+
tt as InputAction,
|
|
281
|
+
et as SummaryCard
|
|
282
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
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={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-jsx-runtime.production.min.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
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"})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ChatPanel } from './ChatPanel';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { InputAction } from './InputAction';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SummaryCard } from './SummaryCard';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
2
|
+
type Role = 'user' | 'assistant';
|
|
3
|
+
interface ChatMessage {
|
|
4
|
+
role: Role;
|
|
5
|
+
content: string;
|
|
6
|
+
}
|
|
7
|
+
interface OnSubmitProps {
|
|
8
|
+
input: string;
|
|
9
|
+
setInput: (input: string) => void;
|
|
10
|
+
abortRef: MutableRefObject<AbortController | null>;
|
|
11
|
+
}
|
|
12
|
+
export declare const useChat: (api: string) => {
|
|
13
|
+
onSubmit: ({ input, setInput, abortRef }: OnSubmitProps) => Promise<void>;
|
|
14
|
+
messages: ChatMessage[];
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
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[];
|
|
12
|
+
loading: boolean;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
package/dist/index.d.ts
ADDED
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
._inputAction_1541p_1{background-color:var(--color-neutral-00);border:1px solid var(--color-neutral-10);border-radius:8px;box-shadow:0 0 10px #0000000f;display:flex;align-items:center;gap:10px;padding:8px 10px;transition:box-shadow .2s ease,border-color .2s ease;width:100%}._inputAction_1541p_1:hover{border-color:var(--color-neutral-20);box-shadow:0 0 10px #0000001f}._inputAction_input_1541p_17{flex:1;min-width:0;border:0;background:transparent;font-family:inherit;font-size:.9375rem;line-height:1.4;color:var(--color-neutral-90);padding:6px 10px;outline:none}._inputAction_input_1541p_17::placeholder{color:var(--color-neutral-50)}._inputAction_input_1541p_17:disabled{color:var(--color-neutral-50);cursor:not-allowed}._inputAction_button_1541p_36{background-color:#9fc6d5;border:0;border-radius:10px;color:var(--color-neutral-00);cursor:pointer;font-family:inherit;font-size:.875rem;font-weight:600;padding:8px 14px;transition:filter .2s ease,transform .05s ease;white-space:nowrap}._inputAction_button_1541p_36:hover{filter:brightness(.97)}._inputAction_button_1541p_36:active{color:var(--color-primary-50)}._inputAction_button_1541p_36:focus-visible{outline:2px solid var(--color-primary-50);outline-offset:2px}._inputAction_button_1541p_36:disabled{cursor:not-allowed;opacity:.55;transform:none}._summaryCard_19k36_1{background-color:var(--color-neutral-00);border:1px solid var(--color-neutral-10);border-radius:12px;box-shadow:0 0 10px #0000001a;padding:20px;display:flex;flex-direction:column;gap:16px;transition:box-shadow .2s ease,border-color .2s ease;height:max-content}._summaryCard_19k36_1:hover{border-color:var(--color-neutral-20);box-shadow:0 0 10px #0003}._summaryCard_header_19k36_17{display:flex;flex-direction:column;gap:12px}._summaryCard_titleWrapper_19k36_22{display:flex;align-items:center;gap:8px}._summaryCard_icon_19k36_27{font-size:1.5rem;line-height:1;flex-shrink:0;filter:drop-shadow(0 1px 2px rgba(0,0,0,.1))}._summaryCard_title_19k36_22{color:var(--color-neutral-90);margin:0;font-size:1.125rem;font-weight:600;line-height:1.4}._summaryCard_button_19k36_40{background-color:var(--color-neutral-00);border:1px solid var(--color-neutral-30);border-radius:8px;color:var(--color-neutral-90);cursor:pointer;font-family:inherit;font-size:.875rem;font-weight:500;padding:8px 16px;transition:all .2s ease;align-self:flex-start}._summaryCard_button_19k36_40:hover{background-color:var(--color-neutral-05);border-color:var(--color-neutral-40);box-shadow:0 0 5px #0000001a}._summaryCard_button_19k36_40:active{background-color:var(--color-neutral-10);box-shadow:none}._summaryCard_button_19k36_40:focus{outline:2px solid var(--color-primary-50);outline-offset:2px}._summaryCard_content_19k36_66{display:flex;flex-direction:column;gap:12px;min-height:60px}._summaryCard_loading_19k36_72{display:flex;align-items:center;gap:12px;padding:16px 0}._summaryCard_spinner_19k36_78{width:20px;height:20px;border:2px solid var(--color-neutral-20);border-top-color:var(--color-primary-50);border-radius:50%;animation:_spin_19k36_1 .8s linear infinite;flex-shrink:0}._summaryCard_loadingText_19k36_87{color:var(--color-neutral-60);font-size:.875rem;line-height:1.5;margin:0}._summaryCard_summaryText_19k36_93{background-color:var(--color-neutral-05);border-left:3px solid var(--color-primary-50);border-radius:8px;color:var(--color-neutral-80);font-size:.9375rem;line-height:1.6;padding:16px}@keyframes _spin_19k36_1{to{transform:rotate(360deg)}}@media screen and (max-width: 768px){._summaryCard_19k36_1{padding:16px;gap:12px}._summaryCard_header_19k36_17{gap:8px}._summaryCard_title_19k36_22{font-size:1rem}._summaryCard_button_19k36_40{font-size:.8125rem;padding:4px 12px}._summaryCard_summaryText_19k36_93{font-size:.875rem;padding:12px}}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@foris/ai-agent",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"type": "module",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"main": "./dist/ai-agent.umd.js",
|
|
12
|
+
"module": "./dist/ai-agent.es.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/ai-agent.es.js",
|
|
18
|
+
"require": "./dist/ai-agent.umd.js",
|
|
19
|
+
"default": "./dist/ai-agent.es.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"react": "18.2.0",
|
|
24
|
+
"react-dom": "18.2.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@tailwindcss/vite": "^4.1.18",
|
|
28
|
+
"@testing-library/jest-dom": "6.4.0",
|
|
29
|
+
"@testing-library/react": "14.2.0",
|
|
30
|
+
"@testing-library/user-event": "14.5.2",
|
|
31
|
+
"@types/node": "20.2.5",
|
|
32
|
+
"@types/react": "18.0.28",
|
|
33
|
+
"@types/react-dom": "18.0.11",
|
|
34
|
+
"@types/testing-library__jest-dom": "6.0.0",
|
|
35
|
+
"@vitejs/plugin-react-swc": "3.5.0",
|
|
36
|
+
"@vitest/coverage-v8": "1.2.2",
|
|
37
|
+
"@vitest/ui": "1.2.2",
|
|
38
|
+
"classnames": "2.3.2",
|
|
39
|
+
"jsdom": "24.0.0",
|
|
40
|
+
"sass": "1.62.1",
|
|
41
|
+
"tailwindcss": "^4.1.18",
|
|
42
|
+
"typescript": "5.1.3",
|
|
43
|
+
"vite": "5.0.12",
|
|
44
|
+
"vite-plugin-dts": "3.7.1",
|
|
45
|
+
"vite-plugin-static-copy": "1.0.0",
|
|
46
|
+
"vitest": "1.2.2",
|
|
47
|
+
"@foris/tsconfig": "0.0.1"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc && vite build",
|
|
51
|
+
"test:watch": "vitest --ui",
|
|
52
|
+
"coverage": "vitest run --coverage"
|
|
53
|
+
}
|
|
54
|
+
}
|