@ai-coding-agent/react-assistant 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/index.js CHANGED
@@ -1,241 +1,64 @@
1
1
  import { useCallback as e, useEffect as t, useRef as n, useState as r } from "react";
2
- //#region \0rolldown/runtime.js
3
- var i = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), a = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
4
- if (typeof require < "u") return require.apply(this, arguments);
5
- throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
6
- }), o = /* @__PURE__ */ i(((e) => {
7
- var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
8
- function r(e, n, r) {
9
- var i = null;
10
- if (r !== void 0 && (i = "" + r), n.key !== void 0 && (i = "" + n.key), "key" in n) for (var a in r = {}, n) a !== "key" && (r[a] = n[a]);
11
- else r = n;
12
- return n = r.ref, {
13
- $$typeof: t,
14
- type: e,
15
- key: i,
16
- ref: n === void 0 ? null : n,
17
- props: r
18
- };
19
- }
20
- e.Fragment = n, e.jsx = r, e.jsxs = r;
21
- })), s = /* @__PURE__ */ i(((e) => {
22
- process.env.NODE_ENV !== "production" && (function() {
23
- function t(e) {
24
- if (e == null) return null;
25
- if (typeof e == "function") return e.$$typeof === k ? null : e.displayName || e.name || null;
26
- if (typeof e == "string") return e;
27
- switch (e) {
28
- case v: return "Fragment";
29
- case b: return "Profiler";
30
- case y: return "StrictMode";
31
- case w: return "Suspense";
32
- case T: return "SuspenseList";
33
- case O: return "Activity";
34
- }
35
- if (typeof e == "object") switch (typeof e.tag == "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), e.$$typeof) {
36
- case _: return "Portal";
37
- case S: return e.displayName || "Context";
38
- case x: return (e._context.displayName || "Context") + ".Consumer";
39
- case C:
40
- var n = e.render;
41
- return e = e.displayName, e ||= (e = n.displayName || n.name || "", e === "" ? "ForwardRef" : "ForwardRef(" + e + ")"), e;
42
- case E: return n = e.displayName || null, n === null ? t(e.type) || "Memo" : n;
43
- case D:
44
- n = e._payload, e = e._init;
45
- try {
46
- return t(e(n));
47
- } catch {}
48
- }
49
- return null;
50
- }
51
- function n(e) {
52
- return "" + e;
53
- }
54
- function r(e) {
55
- try {
56
- n(e);
57
- var t = !1;
58
- } catch {
59
- t = !0;
60
- }
61
- if (t) {
62
- t = console;
63
- var r = t.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
64
- return r.call(t, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", i), n(e);
65
- }
66
- }
67
- function i(e) {
68
- if (e === v) return "<>";
69
- if (typeof e == "object" && e && e.$$typeof === D) return "<...>";
70
- try {
71
- var n = t(e);
72
- return n ? "<" + n + ">" : "<...>";
73
- } catch {
74
- return "<...>";
75
- }
76
- }
77
- function o() {
78
- var e = A.A;
79
- return e === null ? null : e.getOwner();
80
- }
81
- function s() {
82
- return Error("react-stack-top-frame");
83
- }
84
- function c(e) {
85
- if (j.call(e, "key")) {
86
- var t = Object.getOwnPropertyDescriptor(e, "key").get;
87
- if (t && t.isReactWarning) return !1;
88
- }
89
- return e.key !== void 0;
90
- }
91
- function l(e, t) {
92
- function n() {
93
- P || (P = !0, console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", t));
94
- }
95
- n.isReactWarning = !0, Object.defineProperty(e, "key", {
96
- get: n,
97
- configurable: !0
98
- });
99
- }
100
- function u() {
101
- var e = t(this.type);
102
- return F[e] || (F[e] = !0, console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")), e = this.props.ref, e === void 0 ? null : e;
103
- }
104
- function d(e, t, n, r, i, a) {
105
- var o = n.ref;
106
- return e = {
107
- $$typeof: g,
108
- type: e,
109
- key: t,
110
- props: n,
111
- _owner: r
112
- }, (o === void 0 ? null : o) === null ? Object.defineProperty(e, "ref", {
113
- enumerable: !1,
114
- value: null
115
- }) : Object.defineProperty(e, "ref", {
116
- enumerable: !1,
117
- get: u
118
- }), e._store = {}, Object.defineProperty(e._store, "validated", {
119
- configurable: !1,
120
- enumerable: !1,
121
- writable: !0,
122
- value: 0
123
- }), Object.defineProperty(e, "_debugInfo", {
124
- configurable: !1,
125
- enumerable: !1,
126
- writable: !0,
127
- value: null
128
- }), Object.defineProperty(e, "_debugStack", {
129
- configurable: !1,
130
- enumerable: !1,
131
- writable: !0,
132
- value: i
133
- }), Object.defineProperty(e, "_debugTask", {
134
- configurable: !1,
135
- enumerable: !1,
136
- writable: !0,
137
- value: a
138
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
139
- }
140
- function f(e, n, i, a, s, u) {
141
- var f = n.children;
142
- if (f !== void 0) if (a) if (M(f)) {
143
- for (a = 0; a < f.length; a++) p(f[a]);
144
- Object.freeze && Object.freeze(f);
145
- } else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
146
- else p(f);
147
- if (j.call(n, "key")) {
148
- f = t(e);
149
- var m = Object.keys(n).filter(function(e) {
150
- return e !== "key";
151
- });
152
- a = 0 < m.length ? "{key: someKey, " + m.join(": ..., ") + ": ...}" : "{key: someKey}", R[f + a] || (m = 0 < m.length ? "{" + m.join(": ..., ") + ": ...}" : "{}", console.error("A props object containing a \"key\" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />", a, f, m, f), R[f + a] = !0);
153
- }
154
- if (f = null, i !== void 0 && (r(i), f = "" + i), c(n) && (r(n.key), f = "" + n.key), "key" in n) for (var h in i = {}, n) h !== "key" && (i[h] = n[h]);
155
- else i = n;
156
- return f && l(i, typeof e == "function" ? e.displayName || e.name || "Unknown" : e), d(e, f, i, o(), s, u);
157
- }
158
- function p(e) {
159
- m(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e && e.$$typeof === D && (e._payload.status === "fulfilled" ? m(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
160
- }
161
- function m(e) {
162
- return typeof e == "object" && !!e && e.$$typeof === g;
163
- }
164
- var h = a("react"), g = Symbol.for("react.transitional.element"), _ = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), y = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), S = Symbol.for("react.context"), C = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), E = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), O = Symbol.for("react.activity"), k = Symbol.for("react.client.reference"), A = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, M = Array.isArray, N = console.createTask ? console.createTask : function() {
165
- return null;
166
- };
167
- h = { react_stack_bottom_frame: function(e) {
168
- return e();
169
- } };
170
- var P, F = {}, I = h.react_stack_bottom_frame.bind(h, s)(), L = N(i(s)), R = {};
171
- e.Fragment = v, e.jsx = function(e, t, n) {
172
- var r = 1e4 > A.recentlyCreatedOwnerStacks++;
173
- return f(e, t, n, !1, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
174
- }, e.jsxs = function(e, t, n) {
175
- var r = 1e4 > A.recentlyCreatedOwnerStacks++;
176
- return f(e, t, n, !0, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
177
- };
178
- })();
179
- })), c = (/* @__PURE__ */ i(((e, t) => {
180
- process.env.NODE_ENV === "production" ? t.exports = o() : t.exports = s();
181
- })))(), l = ({ isOpen: e, onClick: t, position: n = "bottom-right" }) => /* @__PURE__ */ (0, c.jsx)("button", {
2
+ import { Fragment as i, jsx as a, jsxs as o } from "react/jsx-runtime";
3
+ //#region src/components/FloatingButton.tsx
4
+ var s = ({ isOpen: e, onClick: t, position: n = "bottom-right" }) => /* @__PURE__ */ a("button", {
182
5
  onClick: t,
183
6
  className: `fixed ${n === "bottom-right" ? "right-6 bottom-6" : "left-6 bottom-6"} w-14 h-14 bg-gradient-to-r from-blue-500 to-purple-600 text-white rounded-full shadow-lg hover:shadow-xl transform hover:scale-110 transition-all duration-300 flex items-center justify-center z-50`,
184
7
  "aria-label": "Toggle chat",
185
- children: e ? /* @__PURE__ */ (0, c.jsx)("svg", {
8
+ children: e ? /* @__PURE__ */ a("svg", {
186
9
  className: "w-6 h-6",
187
10
  fill: "none",
188
11
  stroke: "currentColor",
189
12
  viewBox: "0 0 24 24",
190
- children: /* @__PURE__ */ (0, c.jsx)("path", {
13
+ children: /* @__PURE__ */ a("path", {
191
14
  strokeLinecap: "round",
192
15
  strokeLinejoin: "round",
193
16
  strokeWidth: 2,
194
17
  d: "M6 18L18 6M6 6l12 12"
195
18
  })
196
- }) : /* @__PURE__ */ (0, c.jsx)("svg", {
19
+ }) : /* @__PURE__ */ a("svg", {
197
20
  className: "w-6 h-6",
198
21
  fill: "none",
199
22
  stroke: "currentColor",
200
23
  viewBox: "0 0 24 24",
201
- children: /* @__PURE__ */ (0, c.jsx)("path", {
24
+ children: /* @__PURE__ */ a("path", {
202
25
  strokeLinecap: "round",
203
26
  strokeLinejoin: "round",
204
27
  strokeWidth: 2,
205
28
  d: "M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"
206
29
  })
207
30
  })
208
- }), u = ({ messages: e, isLoading: i, onSendMessage: a, onClose: o, position: s = "bottom-right" }) => {
209
- let [l, u] = r(""), d = n(null), f = () => {
210
- d.current?.scrollIntoView({ behavior: "smooth" });
31
+ }), c = ({ messages: e, isLoading: i, onSendMessage: s, onClose: c, position: l = "bottom-right" }) => {
32
+ let [u, d] = r(""), f = n(null), p = () => {
33
+ f.current?.scrollIntoView({ behavior: "smooth" });
211
34
  };
212
35
  t(() => {
213
- f();
36
+ p();
214
37
  }, [e]);
215
- let p = (e) => {
216
- e.preventDefault(), l.trim() && !i && (a(l.trim()), u(""));
38
+ let m = (e) => {
39
+ e.preventDefault(), u.trim() && !i && (s(u.trim()), d(""));
217
40
  };
218
- return /* @__PURE__ */ (0, c.jsxs)("div", {
219
- className: `fixed bottom-20 ${s === "bottom-right" ? "right-0" : "left-0"} w-96 h-[500px] bg-white rounded-lg shadow-2xl flex flex-col overflow-hidden border border-gray-200`,
41
+ return /* @__PURE__ */ o("div", {
42
+ className: `fixed bottom-20 ${l === "bottom-right" ? "right-0" : "left-0"} w-96 h-[500px] bg-white rounded-lg shadow-2xl flex flex-col overflow-hidden border border-gray-200`,
220
43
  children: [
221
- /* @__PURE__ */ (0, c.jsxs)("div", {
44
+ /* @__PURE__ */ o("div", {
222
45
  className: "bg-gradient-to-r from-blue-500 to-purple-600 text-white px-4 py-3 flex justify-between items-center",
223
- children: [/* @__PURE__ */ (0, c.jsxs)("div", { children: [/* @__PURE__ */ (0, c.jsx)("h3", {
46
+ children: [/* @__PURE__ */ o("div", { children: [/* @__PURE__ */ a("h3", {
224
47
  className: "font-semibold text-lg",
225
48
  children: "AI Coding Assistant"
226
- }), /* @__PURE__ */ (0, c.jsx)("p", {
49
+ }), /* @__PURE__ */ a("p", {
227
50
  className: "text-xs text-blue-100",
228
51
  children: "Ask me about your code"
229
- })] }), /* @__PURE__ */ (0, c.jsx)("button", {
230
- onClick: o,
52
+ })] }), /* @__PURE__ */ a("button", {
53
+ onClick: c,
231
54
  className: "text-white hover:bg-white/20 rounded-full p-1 transition-colors",
232
55
  "aria-label": "Close chat",
233
- children: /* @__PURE__ */ (0, c.jsx)("svg", {
56
+ children: /* @__PURE__ */ a("svg", {
234
57
  className: "w-5 h-5",
235
58
  fill: "none",
236
59
  stroke: "currentColor",
237
60
  viewBox: "0 0 24 24",
238
- children: /* @__PURE__ */ (0, c.jsx)("path", {
61
+ children: /* @__PURE__ */ a("path", {
239
62
  strokeLinecap: "round",
240
63
  strokeLinejoin: "round",
241
64
  strokeWidth: 2,
@@ -244,62 +67,62 @@ var i = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), a
244
67
  })
245
68
  })]
246
69
  }),
247
- /* @__PURE__ */ (0, c.jsxs)("div", {
70
+ /* @__PURE__ */ o("div", {
248
71
  className: "flex-1 overflow-y-auto p-4 space-y-4 bg-gray-50",
249
72
  children: [
250
- e.length === 0 ? /* @__PURE__ */ (0, c.jsxs)("div", {
73
+ e.length === 0 ? /* @__PURE__ */ o("div", {
251
74
  className: "text-center text-gray-500 mt-10",
252
75
  children: [
253
- /* @__PURE__ */ (0, c.jsx)("svg", {
76
+ /* @__PURE__ */ a("svg", {
254
77
  className: "w-16 h-16 mx-auto mb-4 text-gray-300",
255
78
  fill: "none",
256
79
  stroke: "currentColor",
257
80
  viewBox: "0 0 24 24",
258
- children: /* @__PURE__ */ (0, c.jsx)("path", {
81
+ children: /* @__PURE__ */ a("path", {
259
82
  strokeLinecap: "round",
260
83
  strokeLinejoin: "round",
261
84
  strokeWidth: 1.5,
262
85
  d: "M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"
263
86
  })
264
87
  }),
265
- /* @__PURE__ */ (0, c.jsx)("p", {
88
+ /* @__PURE__ */ a("p", {
266
89
  className: "text-sm",
267
90
  children: "你好!我是你的代码助手。"
268
91
  }),
269
- /* @__PURE__ */ (0, c.jsx)("p", {
92
+ /* @__PURE__ */ a("p", {
270
93
  className: "text-xs mt-1",
271
94
  children: "问我关于这个代码库的任何问题"
272
95
  })
273
96
  ]
274
- }) : e.map((e) => /* @__PURE__ */ (0, c.jsx)("div", {
97
+ }) : e.map((e) => /* @__PURE__ */ a("div", {
275
98
  className: `flex ${e.role === "user" ? "justify-end" : "justify-start"}`,
276
- children: /* @__PURE__ */ (0, c.jsxs)("div", {
99
+ children: /* @__PURE__ */ o("div", {
277
100
  className: `max-w-[80%] rounded-2xl px-4 py-2 ${e.role === "user" ? "bg-blue-500 text-white" : "bg-white text-gray-800 border border-gray-200"}`,
278
- children: [/* @__PURE__ */ (0, c.jsx)("p", {
101
+ children: [/* @__PURE__ */ a("p", {
279
102
  className: "text-sm whitespace-pre-wrap break-words",
280
103
  children: e.content
281
- }), /* @__PURE__ */ (0, c.jsx)("span", {
104
+ }), /* @__PURE__ */ a("span", {
282
105
  className: "text-xs opacity-70 mt-1 block",
283
106
  children: new Date(e.timestamp).toLocaleTimeString()
284
107
  })]
285
108
  })
286
109
  }, e.id)),
287
- i && /* @__PURE__ */ (0, c.jsx)("div", {
110
+ i && /* @__PURE__ */ a("div", {
288
111
  className: "flex justify-start",
289
- children: /* @__PURE__ */ (0, c.jsx)("div", {
112
+ children: /* @__PURE__ */ a("div", {
290
113
  className: "bg-white border border-gray-200 rounded-2xl px-4 py-3",
291
- children: /* @__PURE__ */ (0, c.jsxs)("div", {
114
+ children: /* @__PURE__ */ o("div", {
292
115
  className: "flex space-x-2",
293
116
  children: [
294
- /* @__PURE__ */ (0, c.jsx)("div", {
117
+ /* @__PURE__ */ a("div", {
295
118
  className: "w-2 h-2 bg-gray-400 rounded-full animate-bounce",
296
119
  style: { animationDelay: "0ms" }
297
120
  }),
298
- /* @__PURE__ */ (0, c.jsx)("div", {
121
+ /* @__PURE__ */ a("div", {
299
122
  className: "w-2 h-2 bg-gray-400 rounded-full animate-bounce",
300
123
  style: { animationDelay: "150ms" }
301
124
  }),
302
- /* @__PURE__ */ (0, c.jsx)("div", {
125
+ /* @__PURE__ */ a("div", {
303
126
  className: "w-2 h-2 bg-gray-400 rounded-full animate-bounce",
304
127
  style: { animationDelay: "300ms" }
305
128
  })
@@ -307,47 +130,47 @@ var i = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), a
307
130
  })
308
131
  })
309
132
  }),
310
- /* @__PURE__ */ (0, c.jsx)("div", { ref: d })
133
+ /* @__PURE__ */ a("div", { ref: f })
311
134
  ]
312
135
  }),
313
- /* @__PURE__ */ (0, c.jsx)("form", {
314
- onSubmit: p,
136
+ /* @__PURE__ */ a("form", {
137
+ onSubmit: m,
315
138
  className: "p-4 bg-white border-t border-gray-200",
316
- children: /* @__PURE__ */ (0, c.jsxs)("div", {
139
+ children: /* @__PURE__ */ o("div", {
317
140
  className: "flex space-x-2",
318
- children: [/* @__PURE__ */ (0, c.jsx)("input", {
141
+ children: [/* @__PURE__ */ a("input", {
319
142
  type: "text",
320
- value: l,
321
- onChange: (e) => u(e.target.value),
143
+ value: u,
144
+ onChange: (e) => d(e.target.value),
322
145
  placeholder: "输入你的问题...",
323
146
  disabled: i,
324
147
  className: "flex-1 px-4 py-2 border border-gray-300 rounded-full focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:opacity-50 disabled:cursor-not-allowed"
325
- }), /* @__PURE__ */ (0, c.jsx)("button", {
148
+ }), /* @__PURE__ */ a("button", {
326
149
  type: "submit",
327
- disabled: i || !l.trim(),
150
+ disabled: i || !u.trim(),
328
151
  className: "px-4 py-2 bg-blue-500 text-white rounded-full hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",
329
- children: i ? /* @__PURE__ */ (0, c.jsxs)("svg", {
152
+ children: i ? /* @__PURE__ */ o("svg", {
330
153
  className: "w-5 h-5 animate-spin",
331
154
  fill: "none",
332
155
  viewBox: "0 0 24 24",
333
- children: [/* @__PURE__ */ (0, c.jsx)("circle", {
156
+ children: [/* @__PURE__ */ a("circle", {
334
157
  className: "opacity-25",
335
158
  cx: "12",
336
159
  cy: "12",
337
160
  r: "10",
338
161
  stroke: "currentColor",
339
162
  strokeWidth: "4"
340
- }), /* @__PURE__ */ (0, c.jsx)("path", {
163
+ }), /* @__PURE__ */ a("path", {
341
164
  className: "opacity-75",
342
165
  fill: "currentColor",
343
166
  d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
344
167
  })]
345
- }) : /* @__PURE__ */ (0, c.jsx)("svg", {
168
+ }) : /* @__PURE__ */ a("svg", {
346
169
  className: "w-5 h-5",
347
170
  fill: "none",
348
171
  stroke: "currentColor",
349
172
  viewBox: "0 0 24 24",
350
- children: /* @__PURE__ */ (0, c.jsx)("path", {
173
+ children: /* @__PURE__ */ a("path", {
351
174
  strokeLinecap: "round",
352
175
  strokeLinejoin: "round",
353
176
  strokeWidth: 2,
@@ -362,7 +185,7 @@ var i = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), a
362
185
  };
363
186
  //#endregion
364
187
  //#region src/hooks/useChat.ts
365
- function d(t) {
188
+ function l(t) {
366
189
  let [n, i] = r([]), [a, o] = r(!1), [s, c] = r(null);
367
190
  return {
368
191
  messages: n,
@@ -408,26 +231,26 @@ function d(t) {
408
231
  }
409
232
  //#endregion
410
233
  //#region src/index.tsx
411
- var f = (e) => {
412
- let [t, n] = r(!1), { messages: i, isLoading: a, error: o, sendMessage: s, clearMessages: f } = d(e);
413
- return /* @__PURE__ */ (0, c.jsxs)(c.Fragment, { children: [
414
- /* @__PURE__ */ (0, c.jsx)(l, {
234
+ var u = (e) => {
235
+ let [t, n] = r(!1), { messages: u, isLoading: d, error: f, sendMessage: p, clearMessages: m } = l(e);
236
+ return /* @__PURE__ */ o(i, { children: [
237
+ /* @__PURE__ */ a(s, {
415
238
  isOpen: t,
416
239
  onClick: () => n(!t),
417
240
  position: e.position
418
241
  }),
419
- t && /* @__PURE__ */ (0, c.jsx)(u, {
420
- messages: i,
421
- isLoading: a,
422
- onSendMessage: s,
242
+ t && /* @__PURE__ */ a(c, {
243
+ messages: u,
244
+ isLoading: d,
245
+ onSendMessage: p,
423
246
  onClose: () => n(!1),
424
247
  position: e.position
425
248
  }),
426
- o && /* @__PURE__ */ (0, c.jsxs)("div", {
249
+ f && /* @__PURE__ */ o("div", {
427
250
  className: "fixed top-4 right-4 bg-red-500 text-white px-4 py-2 rounded-lg shadow-lg z-50",
428
- children: ["Error: ", o]
251
+ children: ["Error: ", f]
429
252
  })
430
253
  ] });
431
254
  };
432
255
  //#endregion
433
- export { f as CodingAssistant, f as default };
256
+ export { u as CodingAssistant, u as default };
@@ -1,6 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`)):typeof define==`function`&&define.amd?define([`exports`,`react`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.CodingAssistant={},e.React))})(this,function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),l=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e};t=((e,t,i)=>(i=e==null?{}:n(o(e)),l(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e)))(t);var u=c((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),d=c((e=>{process.env.NODE_ENV!==`production`&&(function(){function t(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===O?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case _:return`Fragment`;case y:return`Profiler`;case v:return`StrictMode`;case C:return`Suspense`;case w:return`SuspenseList`;case D:return`Activity`}if(typeof e==`object`)switch(typeof e.tag==`number`&&console.error(`Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue.`),e.$$typeof){case g:return`Portal`;case x:return e.displayName||`Context`;case b:return(e._context.displayName||`Context`)+`.Consumer`;case S:var n=e.render;return e=e.displayName,e||=(e=n.displayName||n.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case T:return n=e.displayName||null,n===null?t(e.type)||`Memo`:n;case E:n=e._payload,e=e._init;try{return t(e(n))}catch{}}return null}function n(e){return``+e}function r(e){try{n(e);var t=!1}catch{t=!0}if(t){t=console;var r=t.error,i=typeof Symbol==`function`&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||`Object`;return r.call(t,`The provided key is an unsupported type %s. This value must be coerced to a string before using it here.`,i),n(e)}}function i(e){if(e===_)return`<>`;if(typeof e==`object`&&e&&e.$$typeof===E)return`<...>`;try{var n=t(e);return n?`<`+n+`>`:`<...>`}catch{return`<...>`}}function a(){var e=k.A;return e===null?null:e.getOwner()}function o(){return Error(`react-stack-top-frame`)}function s(e){if(A.call(e,`key`)){var t=Object.getOwnPropertyDescriptor(e,`key`).get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function c(e,t){function n(){N||(N=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,`key`,{get:n,configurable:!0})}function l(){var e=t(this.type);return P[e]||(P[e]=!0,console.error(`Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.`)),e=this.props.ref,e===void 0?null:e}function u(e,t,n,r,i,a){var o=n.ref;return e={$$typeof:h,type:e,key:t,props:n,_owner:r},(o===void 0?null:o)===null?Object.defineProperty(e,`ref`,{enumerable:!1,value:null}):Object.defineProperty(e,`ref`,{enumerable:!1,get:l}),e._store={},Object.defineProperty(e._store,`validated`,{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,`_debugInfo`,{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,`_debugStack`,{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.defineProperty(e,`_debugTask`,{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,n,i,o,l,d){var p=n.children;if(p!==void 0)if(o)if(j(p)){for(o=0;o<p.length;o++)f(p[o]);Object.freeze&&Object.freeze(p)}else console.error(`React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.`);else f(p);if(A.call(n,`key`)){p=t(e);var m=Object.keys(n).filter(function(e){return e!==`key`});o=0<m.length?`{key: someKey, `+m.join(`: ..., `)+`: ...}`:`{key: someKey}`,L[p+o]||(m=0<m.length?`{`+m.join(`: ..., `)+`: ...}`:`{}`,console.error(`A props object containing a "key" prop is being spread into JSX:
2
- let props = %s;
3
- <%s {...props} />
4
- React keys must be passed directly to JSX without using spread:
5
- let props = %s;
6
- <%s key={someKey} {...props} />`,o,p,m,p),L[p+o]=!0)}if(p=null,i!==void 0&&(r(i),p=``+i),s(n)&&(r(n.key),p=``+n.key),`key`in n)for(var h in i={},n)h!==`key`&&(i[h]=n[h]);else i=n;return p&&c(i,typeof e==`function`?e.displayName||e.name||`Unknown`:e),u(e,p,i,a(),l,d)}function f(e){p(e)?e._store&&(e._store.validated=1):typeof e==`object`&&e&&e.$$typeof===E&&(e._payload.status===`fulfilled`?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e==`object`&&!!e&&e.$$typeof===h}var m=require(`react`),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),O=Symbol.for(`react.client.reference`),k=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,A=Object.prototype.hasOwnProperty,j=Array.isArray,M=console.createTask?console.createTask:function(){return null};m={react_stack_bottom_frame:function(e){return e()}};var N,P={},F=m.react_stack_bottom_frame.bind(m,o)(),I=M(i(o)),L={};e.Fragment=_,e.jsx=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!1,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)},e.jsxs=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!0,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)}})()})),f=c(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=u():t.exports=d()}))(),p=({isOpen:e,onClick:t,position:n=`bottom-right`})=>(0,f.jsx)(`button`,{onClick:t,className:`fixed ${n===`bottom-right`?`right-6 bottom-6`:`left-6 bottom-6`} w-14 h-14 bg-gradient-to-r from-blue-500 to-purple-600 text-white rounded-full shadow-lg hover:shadow-xl transform hover:scale-110 transition-all duration-300 flex items-center justify-center z-50`,"aria-label":`Toggle chat`,children:e?(0,f.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,f.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})}):(0,f.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,f.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z`})})}),m=({messages:e,isLoading:n,onSendMessage:r,onClose:i,position:a=`bottom-right`})=>{let[o,s]=(0,t.useState)(``),c=(0,t.useRef)(null),l=()=>{c.current?.scrollIntoView({behavior:`smooth`})};(0,t.useEffect)(()=>{l()},[e]);let u=e=>{e.preventDefault(),o.trim()&&!n&&(r(o.trim()),s(``))};return(0,f.jsxs)(`div`,{className:`fixed bottom-20 ${a===`bottom-right`?`right-0`:`left-0`} w-96 h-[500px] bg-white rounded-lg shadow-2xl flex flex-col overflow-hidden border border-gray-200`,children:[(0,f.jsxs)(`div`,{className:`bg-gradient-to-r from-blue-500 to-purple-600 text-white px-4 py-3 flex justify-between items-center`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`h3`,{className:`font-semibold text-lg`,children:`AI Coding Assistant`}),(0,f.jsx)(`p`,{className:`text-xs text-blue-100`,children:`Ask me about your code`})]}),(0,f.jsx)(`button`,{onClick:i,className:`text-white hover:bg-white/20 rounded-full p-1 transition-colors`,"aria-label":`Close chat`,children:(0,f.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,f.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,f.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4 bg-gray-50`,children:[e.length===0?(0,f.jsxs)(`div`,{className:`text-center text-gray-500 mt-10`,children:[(0,f.jsx)(`svg`,{className:`w-16 h-16 mx-auto mb-4 text-gray-300`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,f.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.5,d:`M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z`})}),(0,f.jsx)(`p`,{className:`text-sm`,children:`你好!我是你的代码助手。`}),(0,f.jsx)(`p`,{className:`text-xs mt-1`,children:`问我关于这个代码库的任何问题`})]}):e.map(e=>(0,f.jsx)(`div`,{className:`flex ${e.role===`user`?`justify-end`:`justify-start`}`,children:(0,f.jsxs)(`div`,{className:`max-w-[80%] rounded-2xl px-4 py-2 ${e.role===`user`?`bg-blue-500 text-white`:`bg-white text-gray-800 border border-gray-200`}`,children:[(0,f.jsx)(`p`,{className:`text-sm whitespace-pre-wrap break-words`,children:e.content}),(0,f.jsx)(`span`,{className:`text-xs opacity-70 mt-1 block`,children:new Date(e.timestamp).toLocaleTimeString()})]})},e.id)),n&&(0,f.jsx)(`div`,{className:`flex justify-start`,children:(0,f.jsx)(`div`,{className:`bg-white border border-gray-200 rounded-2xl px-4 py-3`,children:(0,f.jsxs)(`div`,{className:`flex space-x-2`,children:[(0,f.jsx)(`div`,{className:`w-2 h-2 bg-gray-400 rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,f.jsx)(`div`,{className:`w-2 h-2 bg-gray-400 rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,f.jsx)(`div`,{className:`w-2 h-2 bg-gray-400 rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})})}),(0,f.jsx)(`div`,{ref:c})]}),(0,f.jsx)(`form`,{onSubmit:u,className:`p-4 bg-white border-t border-gray-200`,children:(0,f.jsxs)(`div`,{className:`flex space-x-2`,children:[(0,f.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`输入你的问题...`,disabled:n,className:`flex-1 px-4 py-2 border border-gray-300 rounded-full focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:opacity-50 disabled:cursor-not-allowed`}),(0,f.jsx)(`button`,{type:`submit`,disabled:n||!o.trim(),className:`px-4 py-2 bg-blue-500 text-white rounded-full hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:n?(0,f.jsxs)(`svg`,{className:`w-5 h-5 animate-spin`,fill:`none`,viewBox:`0 0 24 24`,children:[(0,f.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,f.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z`})]}):(0,f.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,f.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M12 19l9 2-9-18-9 18 9-2zm0 0v-8`})})})]})})]})};function h(e){let[n,r]=(0,t.useState)([]),[i,a]=(0,t.useState)(!1),[o,s]=(0,t.useState)(null);return{messages:n,isLoading:i,error:o,sendMessage:(0,t.useCallback)(async t=>{let n={id:Date.now().toString(),role:`user`,content:t,timestamp:new Date};r(e=>[...e,n]),a(!0),s(null);try{let n=await fetch(`${e.apiUrl}/api/chat`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({message:t,repoUrl:e.repoUrl,accessToken:e.accessToken,branch:e.branch})});if(!n.ok)throw Error(`HTTP error! status: ${n.status}`);let i=await n.json(),a={id:(Date.now()+1).toString(),role:`assistant`,content:i.response,timestamp:new Date};r(e=>[...e,a])}catch(e){s(e instanceof Error?e.message:`Unknown error`),console.error(`Error sending message:`,e)}finally{a(!1)}},[e]),clearMessages:(0,t.useCallback)(()=>{r([]),s(null)},[])}}var g=e=>{let[n,r]=(0,t.useState)(!1),{messages:i,isLoading:a,error:o,sendMessage:s,clearMessages:c}=h(e);return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(p,{isOpen:n,onClick:()=>r(!n),position:e.position}),n&&(0,f.jsx)(m,{messages:i,isLoading:a,onSendMessage:s,onClose:()=>r(!1),position:e.position}),o&&(0,f.jsxs)(`div`,{className:`fixed top-4 right-4 bg-red-500 text-white px-4 py-2 rounded-lg shadow-lg z-50`,children:[`Error: `,o]})]})};e.CodingAssistant=g,e.default=g});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.CodingAssistant={},e.React,e._jsx_runtime))})(this,function(e,t,n){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var r=Object.create,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty,l=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var s=o(t),l=0,u=s.length,d;l<u;l++)d=s[l],!c.call(e,d)&&d!==n&&i(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=a(t,d))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:r(s(e)),l(t||!e||!e.__esModule?i(n,`default`,{value:e,enumerable:!0}):n,e)))(t);var u=({isOpen:e,onClick:t,position:r=`bottom-right`})=>(0,n.jsx)(`button`,{onClick:t,className:`fixed ${r===`bottom-right`?`right-6 bottom-6`:`left-6 bottom-6`} w-14 h-14 bg-gradient-to-r from-blue-500 to-purple-600 text-white rounded-full shadow-lg hover:shadow-xl transform hover:scale-110 transition-all duration-300 flex items-center justify-center z-50`,"aria-label":`Toggle chat`,children:e?(0,n.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,n.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})}):(0,n.jsx)(`svg`,{className:`w-6 h-6`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,n.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z`})})}),d=({messages:e,isLoading:r,onSendMessage:i,onClose:a,position:o=`bottom-right`})=>{let[s,c]=(0,t.useState)(``),l=(0,t.useRef)(null),u=()=>{l.current?.scrollIntoView({behavior:`smooth`})};(0,t.useEffect)(()=>{u()},[e]);let d=e=>{e.preventDefault(),s.trim()&&!r&&(i(s.trim()),c(``))};return(0,n.jsxs)(`div`,{className:`fixed bottom-20 ${o===`bottom-right`?`right-0`:`left-0`} w-96 h-[500px] bg-white rounded-lg shadow-2xl flex flex-col overflow-hidden border border-gray-200`,children:[(0,n.jsxs)(`div`,{className:`bg-gradient-to-r from-blue-500 to-purple-600 text-white px-4 py-3 flex justify-between items-center`,children:[(0,n.jsxs)(`div`,{children:[(0,n.jsx)(`h3`,{className:`font-semibold text-lg`,children:`AI Coding Assistant`}),(0,n.jsx)(`p`,{className:`text-xs text-blue-100`,children:`Ask me about your code`})]}),(0,n.jsx)(`button`,{onClick:a,className:`text-white hover:bg-white/20 rounded-full p-1 transition-colors`,"aria-label":`Close chat`,children:(0,n.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,n.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,n.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4 bg-gray-50`,children:[e.length===0?(0,n.jsxs)(`div`,{className:`text-center text-gray-500 mt-10`,children:[(0,n.jsx)(`svg`,{className:`w-16 h-16 mx-auto mb-4 text-gray-300`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,n.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.5,d:`M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z`})}),(0,n.jsx)(`p`,{className:`text-sm`,children:`你好!我是你的代码助手。`}),(0,n.jsx)(`p`,{className:`text-xs mt-1`,children:`问我关于这个代码库的任何问题`})]}):e.map(e=>(0,n.jsx)(`div`,{className:`flex ${e.role===`user`?`justify-end`:`justify-start`}`,children:(0,n.jsxs)(`div`,{className:`max-w-[80%] rounded-2xl px-4 py-2 ${e.role===`user`?`bg-blue-500 text-white`:`bg-white text-gray-800 border border-gray-200`}`,children:[(0,n.jsx)(`p`,{className:`text-sm whitespace-pre-wrap break-words`,children:e.content}),(0,n.jsx)(`span`,{className:`text-xs opacity-70 mt-1 block`,children:new Date(e.timestamp).toLocaleTimeString()})]})},e.id)),r&&(0,n.jsx)(`div`,{className:`flex justify-start`,children:(0,n.jsx)(`div`,{className:`bg-white border border-gray-200 rounded-2xl px-4 py-3`,children:(0,n.jsxs)(`div`,{className:`flex space-x-2`,children:[(0,n.jsx)(`div`,{className:`w-2 h-2 bg-gray-400 rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,n.jsx)(`div`,{className:`w-2 h-2 bg-gray-400 rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,n.jsx)(`div`,{className:`w-2 h-2 bg-gray-400 rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})})}),(0,n.jsx)(`div`,{ref:l})]}),(0,n.jsx)(`form`,{onSubmit:d,className:`p-4 bg-white border-t border-gray-200`,children:(0,n.jsxs)(`div`,{className:`flex space-x-2`,children:[(0,n.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`输入你的问题...`,disabled:r,className:`flex-1 px-4 py-2 border border-gray-300 rounded-full focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:opacity-50 disabled:cursor-not-allowed`}),(0,n.jsx)(`button`,{type:`submit`,disabled:r||!s.trim(),className:`px-4 py-2 bg-blue-500 text-white rounded-full hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:r?(0,n.jsxs)(`svg`,{className:`w-5 h-5 animate-spin`,fill:`none`,viewBox:`0 0 24 24`,children:[(0,n.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,n.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z`})]}):(0,n.jsx)(`svg`,{className:`w-5 h-5`,fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,n.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M12 19l9 2-9-18-9 18 9-2zm0 0v-8`})})})]})})]})};function f(e){let[n,r]=(0,t.useState)([]),[i,a]=(0,t.useState)(!1),[o,s]=(0,t.useState)(null);return{messages:n,isLoading:i,error:o,sendMessage:(0,t.useCallback)(async t=>{let n={id:Date.now().toString(),role:`user`,content:t,timestamp:new Date};r(e=>[...e,n]),a(!0),s(null);try{let n=await fetch(`${e.apiUrl}/api/chat`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({message:t,repoUrl:e.repoUrl,accessToken:e.accessToken,branch:e.branch})});if(!n.ok)throw Error(`HTTP error! status: ${n.status}`);let i=await n.json(),a={id:(Date.now()+1).toString(),role:`assistant`,content:i.response,timestamp:new Date};r(e=>[...e,a])}catch(e){s(e instanceof Error?e.message:`Unknown error`),console.error(`Error sending message:`,e)}finally{a(!1)}},[e]),clearMessages:(0,t.useCallback)(()=>{r([]),s(null)},[])}}var p=e=>{let[r,i]=(0,t.useState)(!1),{messages:a,isLoading:o,error:s,sendMessage:c,clearMessages:l}=f(e);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(u,{isOpen:r,onClick:()=>i(!r),position:e.position}),r&&(0,n.jsx)(d,{messages:a,isLoading:o,onSendMessage:c,onClose:()=>i(!1),position:e.position}),s&&(0,n.jsxs)(`div`,{className:`fixed top-4 right-4 bg-red-500 text-white px-4 py-2 rounded-lg shadow-lg z-50`,children:[`Error: `,s]})]})};e.CodingAssistant=p,e.default=p});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-coding-agent/react-assistant",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "AI-powered coding assistant for React applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",