@apteva/apteva-kit 0.1.3 → 0.1.9
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.d.mts +82 -6
- package/dist/index.d.ts +82 -6
- package/dist/index.js +1349 -200
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1336 -187
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2
5
|
|
|
3
6
|
// src/components/Chat/Chat.tsx
|
|
4
|
-
var _react = require('react');
|
|
7
|
+
var _react = require('react'); var _react2 = _interopRequireDefault(_react);
|
|
5
8
|
|
|
6
9
|
// src/components/Chat/MessageList.tsx
|
|
7
10
|
|
|
@@ -182,6 +185,237 @@ function generateMockStreamingResponse(text, onChunk, typingSpeed = 30) {
|
|
|
182
185
|
}, typingSpeed);
|
|
183
186
|
});
|
|
184
187
|
}
|
|
188
|
+
function generateMockPlan(command) {
|
|
189
|
+
const lowerCommand = command.toLowerCase();
|
|
190
|
+
if (lowerCommand.includes("analyze") || lowerCommand.includes("analysis")) {
|
|
191
|
+
return `**Plan:**
|
|
192
|
+
|
|
193
|
+
1. Fetch data from the analytics database
|
|
194
|
+
2. Apply filters and aggregations
|
|
195
|
+
3. Calculate key metrics and trends
|
|
196
|
+
4. Generate visualization data
|
|
197
|
+
5. Compile insights and recommendations`;
|
|
198
|
+
}
|
|
199
|
+
if (lowerCommand.includes("sales") || lowerCommand.includes("revenue")) {
|
|
200
|
+
return `**Plan:**
|
|
201
|
+
|
|
202
|
+
1. Query sales records for the specified period
|
|
203
|
+
2. Calculate total revenue and growth rates
|
|
204
|
+
3. Break down performance by product category
|
|
205
|
+
4. Analyze regional distribution
|
|
206
|
+
5. Present findings in charts and summary`;
|
|
207
|
+
}
|
|
208
|
+
if (lowerCommand.includes("report") || lowerCommand.includes("summary")) {
|
|
209
|
+
return `**Plan:**
|
|
210
|
+
|
|
211
|
+
1. Gather data from all relevant sources
|
|
212
|
+
2. Aggregate metrics across categories
|
|
213
|
+
3. Identify key trends and anomalies
|
|
214
|
+
4. Generate executive summary
|
|
215
|
+
5. Create detailed breakdowns with visualizations`;
|
|
216
|
+
}
|
|
217
|
+
if (lowerCommand.includes("customer") || lowerCommand.includes("user")) {
|
|
218
|
+
return `**Plan:**
|
|
219
|
+
|
|
220
|
+
1. Pull customer data from CRM
|
|
221
|
+
2. Calculate engagement metrics
|
|
222
|
+
3. Segment users by behavior patterns
|
|
223
|
+
4. Analyze satisfaction scores
|
|
224
|
+
5. Generate customer insights report`;
|
|
225
|
+
}
|
|
226
|
+
if (lowerCommand.includes("task") || lowerCommand.includes("todo") || lowerCommand.includes("work") || lowerCommand.includes("completed")) {
|
|
227
|
+
return `**Plan:**
|
|
228
|
+
|
|
229
|
+
1. Retrieve task records from the database
|
|
230
|
+
2. Filter by status and date range
|
|
231
|
+
3. Organize by priority and category
|
|
232
|
+
4. Calculate completion metrics
|
|
233
|
+
5. Display in interactive list format`;
|
|
234
|
+
}
|
|
235
|
+
return `**Plan:**
|
|
236
|
+
|
|
237
|
+
1. Parse and understand the command requirements
|
|
238
|
+
2. Gather necessary data from available sources
|
|
239
|
+
3. Process and analyze the information
|
|
240
|
+
4. Format results for optimal presentation
|
|
241
|
+
5. Return response with any relevant visualizations`;
|
|
242
|
+
}
|
|
243
|
+
function generateMockCommandResponse(command) {
|
|
244
|
+
const lowerCommand = command.toLowerCase();
|
|
245
|
+
if (lowerCommand.includes("analyze") || lowerCommand.includes("analysis")) {
|
|
246
|
+
return `Analysis complete for "${command}". Found 247 records with an average value of $1,234. The data shows a 23% increase compared to last quarter. Key insights: Revenue is up, customer satisfaction improved by 15%, and operational costs decreased by 8%.`;
|
|
247
|
+
}
|
|
248
|
+
if (lowerCommand.includes("sales") || lowerCommand.includes("revenue")) {
|
|
249
|
+
return `Sales data processed: Q4 2024 revenue reached $2.4M, representing 18% growth year-over-year. Top performing products: Enterprise Plan (+45%), Pro Plan (+32%), Basic Plan (+12%). Regional breakdown: North America (52%), Europe (31%), APAC (17%).`;
|
|
250
|
+
}
|
|
251
|
+
if (lowerCommand.includes("report") || lowerCommand.includes("summary")) {
|
|
252
|
+
return `Report generated successfully. Executive Summary: Overall performance exceeded targets by 12%. Marketing ROI improved to 3.2x, customer acquisition cost reduced by 18%, and lifetime value increased by 24%. Detailed breakdown available in attached widgets.`;
|
|
253
|
+
}
|
|
254
|
+
if (lowerCommand.includes("data") || lowerCommand.includes("metrics")) {
|
|
255
|
+
return `Data metrics retrieved: 1,847 active users, 12,394 sessions this month, 94.2% uptime, average response time 127ms. Performance is within acceptable parameters. No critical issues detected.`;
|
|
256
|
+
}
|
|
257
|
+
if (lowerCommand.includes("customer") || lowerCommand.includes("user")) {
|
|
258
|
+
return `Customer analysis complete: 523 new customers this month, 89% retention rate, average satisfaction score 4.6/5. Top feedback themes: excellent support (87%), easy to use (72%), good value (68%). 3 support tickets pending review.`;
|
|
259
|
+
}
|
|
260
|
+
return `This is a mock response showing how your agent would process and respond to commands. The actual response would be generated by your AI agent based on real data and context.`;
|
|
261
|
+
}
|
|
262
|
+
function generateMockCommandWithWidgets(command) {
|
|
263
|
+
const message = generateMockCommandResponse(command);
|
|
264
|
+
const lowerCommand = command.toLowerCase();
|
|
265
|
+
let widgets = [];
|
|
266
|
+
let action;
|
|
267
|
+
if (lowerCommand.includes("sales") || lowerCommand.includes("revenue") || lowerCommand.includes("analyze")) {
|
|
268
|
+
widgets.push({
|
|
269
|
+
type: "card",
|
|
270
|
+
id: `widget-${Date.now()}-1`,
|
|
271
|
+
props: {
|
|
272
|
+
title: "Q4 2024 Performance",
|
|
273
|
+
description: "Revenue: $2.4M (+18% YoY)",
|
|
274
|
+
footer: "Updated: " + (/* @__PURE__ */ new Date()).toLocaleDateString()
|
|
275
|
+
},
|
|
276
|
+
actions: [
|
|
277
|
+
{
|
|
278
|
+
type: "view_details",
|
|
279
|
+
label: "View Details",
|
|
280
|
+
handler: "client",
|
|
281
|
+
payload: { reportId: "q4-2024" }
|
|
282
|
+
}
|
|
283
|
+
]
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
if (lowerCommand.includes("customer") || lowerCommand.includes("user")) {
|
|
287
|
+
widgets.push({
|
|
288
|
+
type: "list",
|
|
289
|
+
id: `widget-${Date.now()}-2`,
|
|
290
|
+
props: {
|
|
291
|
+
items: [
|
|
292
|
+
{
|
|
293
|
+
id: "metric-1",
|
|
294
|
+
title: "Active Users",
|
|
295
|
+
subtitle: "1,847 users",
|
|
296
|
+
description: "+12% from last month"
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
id: "metric-2",
|
|
300
|
+
title: "Retention Rate",
|
|
301
|
+
subtitle: "89%",
|
|
302
|
+
description: "Above industry average"
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
id: "metric-3",
|
|
306
|
+
title: "Satisfaction Score",
|
|
307
|
+
subtitle: "4.6/5",
|
|
308
|
+
description: "Based on 234 reviews"
|
|
309
|
+
}
|
|
310
|
+
]
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
if (lowerCommand.includes("task") || lowerCommand.includes("todo") || lowerCommand.includes("work") || lowerCommand.includes("completed")) {
|
|
315
|
+
widgets.push({
|
|
316
|
+
type: "list",
|
|
317
|
+
id: `widget-${Date.now()}-tasks`,
|
|
318
|
+
props: {
|
|
319
|
+
items: [
|
|
320
|
+
{
|
|
321
|
+
id: "task-1",
|
|
322
|
+
title: "Implement user authentication",
|
|
323
|
+
subtitle: "Created just now",
|
|
324
|
+
description: "Added OAuth 2.0 support with Google and GitHub providers",
|
|
325
|
+
backgroundColor: "rgba(59, 130, 246, 0.15)",
|
|
326
|
+
metadata: {
|
|
327
|
+
status: "created",
|
|
328
|
+
priority: "high",
|
|
329
|
+
tags: ["backend", "security"]
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
id: "task-2",
|
|
334
|
+
title: "Update API documentation",
|
|
335
|
+
subtitle: "Modified 2 minutes ago",
|
|
336
|
+
description: "Changed endpoint descriptions and added new examples",
|
|
337
|
+
backgroundColor: "rgba(234, 179, 8, 0.15)",
|
|
338
|
+
metadata: {
|
|
339
|
+
status: "modified",
|
|
340
|
+
priority: "medium",
|
|
341
|
+
tags: ["docs"]
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
id: "task-3",
|
|
346
|
+
title: "Fix login redirect bug",
|
|
347
|
+
subtitle: "Completed 5 minutes ago",
|
|
348
|
+
description: "Users now properly redirected after successful login",
|
|
349
|
+
backgroundColor: "rgba(34, 197, 94, 0.15)",
|
|
350
|
+
metadata: {
|
|
351
|
+
status: "completed",
|
|
352
|
+
priority: "urgent",
|
|
353
|
+
tags: ["bugfix", "auth"]
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
]
|
|
357
|
+
},
|
|
358
|
+
actions: [
|
|
359
|
+
{
|
|
360
|
+
type: "view_task",
|
|
361
|
+
label: "View",
|
|
362
|
+
handler: "client",
|
|
363
|
+
payload: {}
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
type: "undo",
|
|
367
|
+
label: "Undo",
|
|
368
|
+
handler: "server",
|
|
369
|
+
payload: {}
|
|
370
|
+
}
|
|
371
|
+
]
|
|
372
|
+
});
|
|
373
|
+
action = {
|
|
374
|
+
type: "update_database",
|
|
375
|
+
payload: {
|
|
376
|
+
table: "tasks",
|
|
377
|
+
operation: "mark_as_viewed",
|
|
378
|
+
taskIds: ["task-1", "task-2", "task-3"],
|
|
379
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
if (lowerCommand.includes("analyze") || lowerCommand.includes("analysis")) {
|
|
384
|
+
action = {
|
|
385
|
+
type: "send_notification",
|
|
386
|
+
payload: {
|
|
387
|
+
recipient: "team@company.com",
|
|
388
|
+
subject: "Analysis Complete",
|
|
389
|
+
message: "Your requested analysis has been completed and is ready for review."
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
return { message, widgets, action };
|
|
394
|
+
}
|
|
395
|
+
function generateMockCommandStream(command, onChunk, onComplete, onError, typingSpeed = 30) {
|
|
396
|
+
const { message, widgets } = generateMockCommandWithWidgets(command);
|
|
397
|
+
const words = message.split(" ");
|
|
398
|
+
let currentIndex = 0;
|
|
399
|
+
const interval = setInterval(() => {
|
|
400
|
+
try {
|
|
401
|
+
if (currentIndex < words.length) {
|
|
402
|
+
onChunk({ type: "token", content: words[currentIndex] + " " });
|
|
403
|
+
currentIndex++;
|
|
404
|
+
} else {
|
|
405
|
+
clearInterval(interval);
|
|
406
|
+
widgets.forEach((widget) => {
|
|
407
|
+
onChunk({ type: "widget", widget });
|
|
408
|
+
});
|
|
409
|
+
const threadId = `mock_thread_${Date.now()}`;
|
|
410
|
+
onChunk({ type: "complete" });
|
|
411
|
+
onComplete(threadId);
|
|
412
|
+
}
|
|
413
|
+
} catch (error) {
|
|
414
|
+
clearInterval(interval);
|
|
415
|
+
onError(error instanceof Error ? error : new Error("Mock streaming error"));
|
|
416
|
+
}
|
|
417
|
+
}, typingSpeed);
|
|
418
|
+
}
|
|
185
419
|
|
|
186
420
|
// src/components/Widgets/Widgets.tsx
|
|
187
421
|
|
|
@@ -190,24 +424,24 @@ function generateMockStreamingResponse(text, onChunk, typingSpeed = 30) {
|
|
|
190
424
|
var _jsxruntime = require('react/jsx-runtime');
|
|
191
425
|
function Card({ widget, onAction }) {
|
|
192
426
|
const { title, description, image, footer } = widget.props;
|
|
193
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "
|
|
427
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "border border-gray-200 dark:border-gray-700 rounded-xl bg-white dark:bg-gray-900 overflow-hidden", children: [
|
|
194
428
|
image && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "img", { src: image, alt: title, className: "w-full h-48 object-cover" }),
|
|
195
429
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "p-4", children: [
|
|
196
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { className: "text-lg font-semibold text-gray-900 dark
|
|
197
|
-
description && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-gray-600 dark
|
|
430
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { className: "!text-lg font-semibold !text-gray-900 dark:!text-white", children: title }),
|
|
431
|
+
description && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "!text-gray-600 dark:!text-gray-400 mt-2", children: description })
|
|
198
432
|
] }),
|
|
199
433
|
(footer || widget.actions && widget.actions.length > 0) && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "border-t border-gray-200 dark:border-gray-700 p-4 flex justify-between items-center", children: [
|
|
200
|
-
footer && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-sm text-gray-600 dark
|
|
434
|
+
footer && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "!text-sm !text-gray-600 dark:!text-gray-400", children: footer }),
|
|
201
435
|
widget.actions && widget.actions.length > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex gap-2", children: widget.actions.map((action, idx) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
202
436
|
"button",
|
|
203
437
|
{
|
|
204
|
-
onClick: () => _optionalChain([onAction, 'optionalCall',
|
|
438
|
+
onClick: () => _optionalChain([onAction, 'optionalCall', _2 => _2({
|
|
205
439
|
type: action.type,
|
|
206
440
|
payload: action.payload,
|
|
207
441
|
widgetId: widget.id,
|
|
208
442
|
timestamp: /* @__PURE__ */ new Date()
|
|
209
443
|
})]),
|
|
210
|
-
className: "
|
|
444
|
+
className: "px-3 py-1.5 !text-sm rounded-lg font-medium transition-colors bg-blue-500 !text-white hover:bg-blue-600",
|
|
211
445
|
children: action.label
|
|
212
446
|
},
|
|
213
447
|
idx
|
|
@@ -220,28 +454,36 @@ function Card({ widget, onAction }) {
|
|
|
220
454
|
|
|
221
455
|
function List({ widget, onAction }) {
|
|
222
456
|
const { items } = widget.props;
|
|
223
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
item.
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
457
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "border border-gray-200 dark:border-gray-700 rounded-xl bg-white dark:bg-gray-900 overflow-hidden", children: items.map((item, index) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
458
|
+
"div",
|
|
459
|
+
{
|
|
460
|
+
className: `flex items-center p-4 transition-colors ${index !== items.length - 1 ? "border-b border-gray-200 dark:border-gray-700" : ""} ${!item.backgroundColor ? "hover:bg-gray-50 dark:hover:bg-gray-800" : ""}`,
|
|
461
|
+
style: item.backgroundColor ? { backgroundColor: item.backgroundColor } : void 0,
|
|
462
|
+
children: [
|
|
463
|
+
item.image && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "img", { src: item.image, alt: item.title, className: "w-16 h-16 rounded object-cover" }),
|
|
464
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: `flex-1 ${item.image ? "ml-4" : ""}`, children: [
|
|
465
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h4", { className: "font-semibold !text-gray-900 dark:!text-white", children: item.title }),
|
|
466
|
+
item.subtitle && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "!text-sm !text-gray-600 dark:!text-gray-400", children: item.subtitle }),
|
|
467
|
+
item.description && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "!text-xs !text-gray-500 dark:!text-gray-500 mt-1", children: item.description })
|
|
468
|
+
] }),
|
|
469
|
+
widget.actions && widget.actions.length > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex gap-2", children: widget.actions.map((action, idx) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
470
|
+
"button",
|
|
471
|
+
{
|
|
472
|
+
onClick: () => _optionalChain([onAction, 'optionalCall', _3 => _3({
|
|
473
|
+
type: action.type,
|
|
474
|
+
payload: item.metadata || item,
|
|
475
|
+
widgetId: widget.id,
|
|
476
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
477
|
+
})]),
|
|
478
|
+
className: "px-3 py-1.5 !text-sm rounded-lg font-medium transition-colors bg-blue-500 !text-white hover:bg-blue-600",
|
|
479
|
+
children: action.label
|
|
480
|
+
},
|
|
481
|
+
idx
|
|
482
|
+
)) })
|
|
483
|
+
]
|
|
484
|
+
},
|
|
485
|
+
item.id
|
|
486
|
+
)) });
|
|
245
487
|
}
|
|
246
488
|
|
|
247
489
|
// src/components/Widgets/widget-library/Button.tsx
|
|
@@ -249,15 +491,15 @@ function List({ widget, onAction }) {
|
|
|
249
491
|
function Button({ widget, onAction }) {
|
|
250
492
|
const { label, variant = "primary", disabled = false } = widget.props;
|
|
251
493
|
const variantClasses = {
|
|
252
|
-
primary: "bg-
|
|
253
|
-
secondary: "bg-gray-500 text-white hover:bg-gray-600",
|
|
254
|
-
outline: "border-2 border-
|
|
255
|
-
ghost: "text-
|
|
494
|
+
primary: "bg-blue-500 !text-white hover:bg-blue-600",
|
|
495
|
+
secondary: "bg-gray-500 !text-white hover:bg-gray-600",
|
|
496
|
+
outline: "border-2 border-blue-500 !text-blue-500 hover:bg-blue-50 dark:hover:bg-blue-900",
|
|
497
|
+
ghost: "!text-blue-500 hover:bg-blue-50 dark:hover:bg-blue-900"
|
|
256
498
|
};
|
|
257
499
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
258
500
|
"button",
|
|
259
501
|
{
|
|
260
|
-
onClick: () => _optionalChain([widget, 'access',
|
|
502
|
+
onClick: () => _optionalChain([widget, 'access', _4 => _4.actions, 'optionalAccess', _5 => _5[0]]) && _optionalChain([onAction, 'optionalCall', _6 => _6({
|
|
261
503
|
type: widget.actions[0].type,
|
|
262
504
|
payload: widget.actions[0].payload,
|
|
263
505
|
widgetId: widget.id,
|
|
@@ -306,7 +548,7 @@ function Widgets({
|
|
|
306
548
|
}) {
|
|
307
549
|
_react.useEffect.call(void 0, () => {
|
|
308
550
|
widgets.forEach((widget) => {
|
|
309
|
-
_optionalChain([onWidgetMount, 'optionalCall',
|
|
551
|
+
_optionalChain([onWidgetMount, 'optionalCall', _7 => _7(widget.id)]);
|
|
310
552
|
});
|
|
311
553
|
}, [widgets, onWidgetMount]);
|
|
312
554
|
const layoutClasses = {
|
|
@@ -326,11 +568,20 @@ function Widgets({
|
|
|
326
568
|
|
|
327
569
|
function Message({ message, onAction }) {
|
|
328
570
|
const isUser = message.role === "user";
|
|
329
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
571
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
572
|
+
"div",
|
|
573
|
+
{
|
|
574
|
+
className: cn(
|
|
575
|
+
"max-w-[80%]",
|
|
576
|
+
isUser ? "px-4 py-2.5 rounded-xl bg-gray-100 dark:bg-gray-800 !text-gray-900 dark:!text-gray-100 ml-auto" : "!text-gray-900 dark:!text-gray-100"
|
|
577
|
+
),
|
|
578
|
+
children: [
|
|
579
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "whitespace-pre-wrap !text-sm leading-relaxed", children: message.content }),
|
|
580
|
+
message.widgets && message.widgets.length > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: cn(isUser ? "mt-3" : "mt-2"), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Widgets, { widgets: message.widgets, onAction, layout: "stack" }) }),
|
|
581
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: cn("!text-xs opacity-70", isUser ? "mt-1.5 !text-gray-500 dark:!text-gray-400" : "mt-1 !text-gray-500 dark:!text-gray-400"), suppressHydrationWarning: true, children: message.timestamp.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) })
|
|
582
|
+
]
|
|
583
|
+
}
|
|
584
|
+
);
|
|
334
585
|
}
|
|
335
586
|
|
|
336
587
|
// src/components/Chat/MessageList.tsx
|
|
@@ -342,7 +593,7 @@ function MessageList({ messages, onAction }) {
|
|
|
342
593
|
listRef.current.scrollTop = listRef.current.scrollHeight;
|
|
343
594
|
}
|
|
344
595
|
}, [messages]);
|
|
345
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ref: listRef, className: "
|
|
596
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ref: listRef, className: "flex-1 overflow-y-auto px-4 py-4 space-y-3", children: messages.length === 0 ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex items-center justify-center h-full !text-gray-500 dark:!text-gray-400", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "text-center space-y-2", children: [
|
|
346
597
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-4xl", children: "\u{1F4AC}" }),
|
|
347
598
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { children: "No messages yet. Start a conversation!" })
|
|
348
599
|
] }) }) : messages.map((message) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Message, { message, onAction }, message.id)) });
|
|
@@ -351,9 +602,11 @@ function MessageList({ messages, onAction }) {
|
|
|
351
602
|
// src/components/Chat/Composer.tsx
|
|
352
603
|
|
|
353
604
|
|
|
354
|
-
function Composer({ onSendMessage, placeholder = "Type a message...", disabled = false }) {
|
|
605
|
+
function Composer({ onSendMessage, placeholder = "Type a message...", disabled = false, onFileUpload }) {
|
|
355
606
|
const [text, setText] = _react.useState.call(void 0, "");
|
|
607
|
+
const [showMenu, setShowMenu] = _react.useState.call(void 0, false);
|
|
356
608
|
const textareaRef = _react.useRef.call(void 0, null);
|
|
609
|
+
const fileInputRef = _react.useRef.call(void 0, null);
|
|
357
610
|
const handleKeyDown = (e) => {
|
|
358
611
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
359
612
|
e.preventDefault();
|
|
@@ -374,8 +627,37 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
|
|
|
374
627
|
e.target.style.height = "auto";
|
|
375
628
|
e.target.style.height = `${e.target.scrollHeight}px`;
|
|
376
629
|
};
|
|
377
|
-
|
|
378
|
-
|
|
630
|
+
const handleFileSelect = (e) => {
|
|
631
|
+
if (e.target.files && e.target.files.length > 0) {
|
|
632
|
+
_optionalChain([onFileUpload, 'optionalCall', _8 => _8(e.target.files)]);
|
|
633
|
+
setShowMenu(false);
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "px-4 py-3 bg-white dark:bg-gray-900 relative", children: [
|
|
637
|
+
showMenu && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
638
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "fixed inset-0 z-10", onClick: () => setShowMenu(false) }),
|
|
639
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "absolute bottom-full left-4 mb-2 bg-gray-800 dark:bg-gray-700 rounded-xl shadow-lg overflow-hidden z-20 min-w-[240px]", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
640
|
+
"button",
|
|
641
|
+
{
|
|
642
|
+
onClick: () => _optionalChain([fileInputRef, 'access', _9 => _9.current, 'optionalAccess', _10 => _10.click, 'call', _11 => _11()]),
|
|
643
|
+
className: "w-full flex items-center gap-3 px-4 py-3 hover:bg-gray-700 dark:hover:bg-gray-600 transition-colors !text-white text-left",
|
|
644
|
+
children: [
|
|
645
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M10.5 3.5L5.5 8.5C4.67157 9.32843 4.67157 10.6716 5.5 11.5C6.32843 12.3284 7.67157 12.3284 8.5 11.5L14.5 5.5C15.8807 4.11929 15.8807 1.88071 14.5 0.5C13.1193 -0.880711 10.8807 -0.880711 9.5 0.5L3.5 6.5C1.56846 8.43154 1.56846 11.5685 3.5 13.5C5.43154 15.4315 8.56846 15.4315 10.5 13.5L15.5 8.5", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", transform: "translate(2, 3)" }) }),
|
|
646
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "!text-sm font-medium", children: "Add photos & files" })
|
|
647
|
+
]
|
|
648
|
+
}
|
|
649
|
+
) })
|
|
650
|
+
] }),
|
|
651
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "relative border-2 border-gray-300 dark:border-gray-700 rounded-xl bg-white dark:bg-gray-900 transition-all duration-300 flex items-center px-3 py-2 gap-3", children: [
|
|
652
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
653
|
+
"button",
|
|
654
|
+
{
|
|
655
|
+
onClick: () => setShowMenu(!showMenu),
|
|
656
|
+
className: "w-8 h-8 rounded-lg flex items-center justify-center transition-all flex-shrink-0 !text-gray-700 dark:!text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800",
|
|
657
|
+
title: "More options",
|
|
658
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M10 5v10M5 10h10", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
|
|
659
|
+
}
|
|
660
|
+
),
|
|
379
661
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
380
662
|
"textarea",
|
|
381
663
|
{
|
|
@@ -385,9 +667,9 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
|
|
|
385
667
|
onKeyDown: handleKeyDown,
|
|
386
668
|
placeholder,
|
|
387
669
|
disabled,
|
|
388
|
-
className: "
|
|
670
|
+
className: "flex-1 resize-none bg-transparent border-none focus:outline-none !text-gray-900 dark:!text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 py-1 disabled:opacity-50 disabled:cursor-not-allowed",
|
|
389
671
|
rows: 1,
|
|
390
|
-
style: { maxHeight: "
|
|
672
|
+
style: { maxHeight: "120px" }
|
|
391
673
|
}
|
|
392
674
|
),
|
|
393
675
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
@@ -395,12 +677,23 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
|
|
|
395
677
|
{
|
|
396
678
|
onClick: handleSend,
|
|
397
679
|
disabled: !text.trim() || disabled,
|
|
398
|
-
className: "
|
|
399
|
-
|
|
680
|
+
className: "w-8 h-8 rounded-lg flex items-center justify-center font-bold transition-all flex-shrink-0 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 !text-gray-700 dark:!text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 disabled:opacity-30 disabled:cursor-not-allowed !text-lg",
|
|
681
|
+
title: "Send message",
|
|
682
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M8 3L8 13M8 3L4 7M8 3L12 7", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
|
|
400
683
|
}
|
|
401
684
|
)
|
|
402
685
|
] }),
|
|
403
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
686
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
687
|
+
"input",
|
|
688
|
+
{
|
|
689
|
+
ref: fileInputRef,
|
|
690
|
+
type: "file",
|
|
691
|
+
multiple: true,
|
|
692
|
+
onChange: handleFileSelect,
|
|
693
|
+
className: "hidden",
|
|
694
|
+
accept: "image/*,application/pdf,.doc,.docx,.txt"
|
|
695
|
+
}
|
|
696
|
+
)
|
|
404
697
|
] });
|
|
405
698
|
}
|
|
406
699
|
|
|
@@ -410,9 +703,11 @@ function Chat({
|
|
|
410
703
|
agentId,
|
|
411
704
|
threadId,
|
|
412
705
|
initialMessages = [],
|
|
706
|
+
context,
|
|
413
707
|
onThreadChange,
|
|
414
708
|
onMessageSent,
|
|
415
709
|
onAction,
|
|
710
|
+
onFileUpload,
|
|
416
711
|
placeholder = "Type a message...",
|
|
417
712
|
showHeader = true,
|
|
418
713
|
headerTitle = "Chat",
|
|
@@ -423,7 +718,7 @@ function Chat({
|
|
|
423
718
|
_react.useEffect.call(void 0, () => {
|
|
424
719
|
if (threadId) {
|
|
425
720
|
console.log("Loading thread:", threadId);
|
|
426
|
-
_optionalChain([onThreadChange, 'optionalCall',
|
|
721
|
+
_optionalChain([onThreadChange, 'optionalCall', _12 => _12(threadId)]);
|
|
427
722
|
}
|
|
428
723
|
}, [threadId, onThreadChange]);
|
|
429
724
|
const handleSendMessage = async (text) => {
|
|
@@ -434,7 +729,7 @@ function Chat({
|
|
|
434
729
|
timestamp: /* @__PURE__ */ new Date()
|
|
435
730
|
};
|
|
436
731
|
setMessages((prev) => [...prev, userMessage]);
|
|
437
|
-
_optionalChain([onMessageSent, 'optionalCall',
|
|
732
|
+
_optionalChain([onMessageSent, 'optionalCall', _13 => _13(userMessage)]);
|
|
438
733
|
setIsLoading(true);
|
|
439
734
|
try {
|
|
440
735
|
const response = await generateMockResponse(1e3);
|
|
@@ -445,23 +740,195 @@ function Chat({
|
|
|
445
740
|
setIsLoading(false);
|
|
446
741
|
}
|
|
447
742
|
};
|
|
448
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: cn("
|
|
449
|
-
showHeader && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "
|
|
450
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { className: "text-lg font-semibold text-gray-900 dark
|
|
451
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "p", { className: "text-xs text-gray-500 dark
|
|
743
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: cn("flex flex-col h-full bg-white dark:bg-gray-900", className), children: [
|
|
744
|
+
showHeader && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "px-4 py-3 bg-white dark:bg-gray-900", children: [
|
|
745
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { className: "!text-lg font-semibold !text-gray-900 dark:!text-white", children: headerTitle }),
|
|
746
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "p", { className: "!text-xs !text-gray-500 dark:!text-gray-400", children: [
|
|
452
747
|
"Agent: ",
|
|
453
748
|
agentId
|
|
454
749
|
] })
|
|
455
750
|
] }),
|
|
456
751
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, MessageList, { messages, onAction }),
|
|
457
|
-
isLoading && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "px-4 py-2 text-sm text-gray-500 italic", children: "AI is thinking..." }),
|
|
458
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, Composer, { onSendMessage: handleSendMessage, placeholder, disabled: isLoading })
|
|
752
|
+
isLoading && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "px-4 py-2 !text-sm !text-gray-500 dark:!text-gray-400 italic", children: "AI is thinking..." }),
|
|
753
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, Composer, { onSendMessage: handleSendMessage, placeholder, disabled: isLoading, onFileUpload })
|
|
459
754
|
] });
|
|
460
755
|
}
|
|
461
756
|
|
|
462
757
|
// src/components/Command/Command.tsx
|
|
463
758
|
|
|
464
759
|
|
|
760
|
+
// src/lib/apteva-client.ts
|
|
761
|
+
var DEFAULT_API_URL = "http://localhost:3000/agents";
|
|
762
|
+
var DEFAULT_API_KEY = "agt_894abd5966bc9f1e9f8f17f2a6f6b5e0";
|
|
763
|
+
var AptevaClient = class {
|
|
764
|
+
constructor() {
|
|
765
|
+
__publicField(this, "config");
|
|
766
|
+
this.config = {
|
|
767
|
+
apiUrl: DEFAULT_API_URL,
|
|
768
|
+
apiKey: DEFAULT_API_KEY
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Update client configuration (optional - users can override defaults)
|
|
773
|
+
*/
|
|
774
|
+
configure(config) {
|
|
775
|
+
if (config.apiUrl) this.config.apiUrl = config.apiUrl;
|
|
776
|
+
if (config.apiKey) this.config.apiKey = config.apiKey;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Get current configuration
|
|
780
|
+
*/
|
|
781
|
+
getConfig() {
|
|
782
|
+
return { ...this.config };
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Send a chat message to an agent
|
|
786
|
+
*/
|
|
787
|
+
async chat(request) {
|
|
788
|
+
try {
|
|
789
|
+
console.log("[AptevaClient] Chat request:", {
|
|
790
|
+
agent_id: request.agent_id,
|
|
791
|
+
message: typeof request.message === "string" ? request.message.substring(0, 100) + "..." : "[multi-part message]",
|
|
792
|
+
system: request.system,
|
|
793
|
+
stream: request.stream
|
|
794
|
+
});
|
|
795
|
+
const response = await fetch(`${this.config.apiUrl}/chat`, {
|
|
796
|
+
method: "POST",
|
|
797
|
+
headers: {
|
|
798
|
+
"Content-Type": "application/json",
|
|
799
|
+
"X-API-Key": this.config.apiKey
|
|
800
|
+
},
|
|
801
|
+
body: JSON.stringify(request)
|
|
802
|
+
});
|
|
803
|
+
if (!response.ok) {
|
|
804
|
+
const error = await response.json().catch(() => ({ error: "Request failed" }));
|
|
805
|
+
throw new Error(error.error || `Request failed with status ${response.status}`);
|
|
806
|
+
}
|
|
807
|
+
const data = await response.json();
|
|
808
|
+
return {
|
|
809
|
+
message: data.response || data.message || "",
|
|
810
|
+
thread_id: data.thread_id,
|
|
811
|
+
widgets: data.widgets
|
|
812
|
+
};
|
|
813
|
+
} catch (error) {
|
|
814
|
+
console.error("Chat API error:", error);
|
|
815
|
+
throw error;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* Send a chat message with streaming response
|
|
820
|
+
*/
|
|
821
|
+
async chatStream(request, onChunk, onComplete, onError) {
|
|
822
|
+
try {
|
|
823
|
+
console.log("[AptevaClient] Chat stream request:", {
|
|
824
|
+
agent_id: request.agent_id,
|
|
825
|
+
message: typeof request.message === "string" ? request.message.substring(0, 100) + "..." : "[multi-part message]",
|
|
826
|
+
system: request.system,
|
|
827
|
+
stream: request.stream
|
|
828
|
+
});
|
|
829
|
+
const response = await fetch(`${this.config.apiUrl}/chat`, {
|
|
830
|
+
method: "POST",
|
|
831
|
+
headers: {
|
|
832
|
+
"Content-Type": "application/json",
|
|
833
|
+
"X-API-Key": this.config.apiKey,
|
|
834
|
+
"Accept": "text/event-stream"
|
|
835
|
+
},
|
|
836
|
+
body: JSON.stringify({
|
|
837
|
+
...request,
|
|
838
|
+
stream: true
|
|
839
|
+
})
|
|
840
|
+
});
|
|
841
|
+
if (!response.ok) {
|
|
842
|
+
const error = await response.json().catch(() => ({ error: "Request failed" }));
|
|
843
|
+
throw new Error(error.error || `Request failed with status ${response.status}`);
|
|
844
|
+
}
|
|
845
|
+
const reader = _optionalChain([response, 'access', _14 => _14.body, 'optionalAccess', _15 => _15.getReader, 'call', _16 => _16()]);
|
|
846
|
+
if (!reader) {
|
|
847
|
+
throw new Error("Response body is not readable");
|
|
848
|
+
}
|
|
849
|
+
const decoder = new TextDecoder();
|
|
850
|
+
let buffer = "";
|
|
851
|
+
let threadId = "";
|
|
852
|
+
while (true) {
|
|
853
|
+
const { done, value } = await reader.read();
|
|
854
|
+
if (done) break;
|
|
855
|
+
buffer += decoder.decode(value, { stream: true });
|
|
856
|
+
const lines = buffer.split("\n");
|
|
857
|
+
buffer = lines.pop() || "";
|
|
858
|
+
for (const line of lines) {
|
|
859
|
+
if (!line.trim() || line.startsWith(":")) continue;
|
|
860
|
+
if (line.startsWith("data: ")) {
|
|
861
|
+
const data = line.slice(6);
|
|
862
|
+
if (data === "[DONE]") {
|
|
863
|
+
_optionalChain([onComplete, 'optionalCall', _17 => _17(threadId)]);
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
try {
|
|
867
|
+
const chunk = JSON.parse(data);
|
|
868
|
+
if (chunk.thread_id) {
|
|
869
|
+
threadId = chunk.thread_id;
|
|
870
|
+
}
|
|
871
|
+
if (chunk.type === "token" && chunk.content) {
|
|
872
|
+
onChunk({ type: "token", content: chunk.content });
|
|
873
|
+
} else if (chunk.type === "widget" && chunk.widget) {
|
|
874
|
+
onChunk({ type: "widget", widget: chunk.widget });
|
|
875
|
+
} else if (chunk.type === "complete") {
|
|
876
|
+
onChunk({ type: "complete", thread_id: threadId });
|
|
877
|
+
}
|
|
878
|
+
} catch (e) {
|
|
879
|
+
console.warn("Failed to parse SSE data:", data);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
_optionalChain([onComplete, 'optionalCall', _18 => _18(threadId)]);
|
|
885
|
+
} catch (error) {
|
|
886
|
+
const err = error instanceof Error ? error : new Error("Unknown error");
|
|
887
|
+
_optionalChain([onError, 'optionalCall', _19 => _19(err)]);
|
|
888
|
+
throw err;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Create a new thread
|
|
893
|
+
*/
|
|
894
|
+
async createThread(agentId, metadata) {
|
|
895
|
+
const response = await fetch(`${this.config.apiUrl}/agents/${agentId}/threads`, {
|
|
896
|
+
method: "POST",
|
|
897
|
+
headers: {
|
|
898
|
+
"Content-Type": "application/json",
|
|
899
|
+
"X-API-Key": this.config.apiKey
|
|
900
|
+
},
|
|
901
|
+
body: JSON.stringify({ metadata })
|
|
902
|
+
});
|
|
903
|
+
if (!response.ok) {
|
|
904
|
+
const error = await response.json().catch(() => ({ error: "Request failed" }));
|
|
905
|
+
throw new Error(error.error || `Request failed with status ${response.status}`);
|
|
906
|
+
}
|
|
907
|
+
const data = await response.json();
|
|
908
|
+
return data.thread_id;
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* Get thread messages
|
|
912
|
+
*/
|
|
913
|
+
async getThreadMessages(threadId) {
|
|
914
|
+
const response = await fetch(`${this.config.apiUrl}/threads/${threadId}/messages`, {
|
|
915
|
+
method: "GET",
|
|
916
|
+
headers: {
|
|
917
|
+
"X-API-Key": this.config.apiKey
|
|
918
|
+
}
|
|
919
|
+
});
|
|
920
|
+
if (!response.ok) {
|
|
921
|
+
const error = await response.json().catch(() => ({ error: "Request failed" }));
|
|
922
|
+
throw new Error(error.error || `Request failed with status ${response.status}`);
|
|
923
|
+
}
|
|
924
|
+
const data = await response.json();
|
|
925
|
+
return data.messages;
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
var aptevaClient = new AptevaClient();
|
|
929
|
+
|
|
930
|
+
// src/components/Command/Command.tsx
|
|
931
|
+
|
|
465
932
|
function Command({
|
|
466
933
|
agentId,
|
|
467
934
|
command: initialCommand,
|
|
@@ -471,11 +938,17 @@ function Command({
|
|
|
471
938
|
placeholder = "Enter your command...",
|
|
472
939
|
submitButtonText = "Execute",
|
|
473
940
|
variant = "default",
|
|
941
|
+
useMock = false,
|
|
942
|
+
planMode = false,
|
|
943
|
+
onPlanModeChange,
|
|
944
|
+
enableFileUpload = true,
|
|
474
945
|
onStart,
|
|
475
946
|
onProgress,
|
|
476
947
|
onChunk,
|
|
477
948
|
onComplete,
|
|
478
949
|
onError,
|
|
950
|
+
onFileUpload,
|
|
951
|
+
onAction,
|
|
479
952
|
loadingText = "Processing...",
|
|
480
953
|
showProgress = true,
|
|
481
954
|
enableStreaming = false,
|
|
@@ -488,85 +961,351 @@ function Command({
|
|
|
488
961
|
const [progress, setProgress] = _react.useState.call(void 0, 0);
|
|
489
962
|
const [command, setCommand] = _react.useState.call(void 0, initialCommand || "");
|
|
490
963
|
const [streamedContent, setStreamedContent] = _react.useState.call(void 0, "");
|
|
964
|
+
const [plan, setPlan] = _react.useState.call(void 0, "");
|
|
965
|
+
const [pendingCommand, setPendingCommand] = _react.useState.call(void 0, "");
|
|
966
|
+
const [showPlanDetails, setShowPlanDetails] = _react.useState.call(void 0, false);
|
|
967
|
+
const [uploadedFiles, setUploadedFiles] = _react.useState.call(void 0, []);
|
|
968
|
+
const [showSettingsMenu, setShowSettingsMenu] = _react.useState.call(void 0, false);
|
|
969
|
+
const [internalPlanMode, setInternalPlanMode] = _react.useState.call(void 0, planMode);
|
|
970
|
+
const fileInputRef = _react2.default.useRef(null);
|
|
491
971
|
_react.useEffect.call(void 0, () => {
|
|
492
972
|
if (autoExecute && state === "idle" && command) {
|
|
493
973
|
executeCommand();
|
|
494
974
|
}
|
|
495
975
|
}, [autoExecute]);
|
|
496
|
-
|
|
497
|
-
|
|
976
|
+
_react.useEffect.call(void 0, () => {
|
|
977
|
+
setInternalPlanMode(planMode);
|
|
978
|
+
}, [planMode]);
|
|
979
|
+
_react.useEffect.call(void 0, () => {
|
|
980
|
+
const handleClickOutside = (event) => {
|
|
981
|
+
const target = event.target;
|
|
982
|
+
if (showSettingsMenu && !target.closest(".settings-menu-container")) {
|
|
983
|
+
setShowSettingsMenu(false);
|
|
984
|
+
}
|
|
985
|
+
};
|
|
986
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
987
|
+
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
988
|
+
}, [showSettingsMenu]);
|
|
989
|
+
const executeCommand = async (commandOverride) => {
|
|
990
|
+
const currentCommand = commandOverride || command;
|
|
991
|
+
if (!currentCommand.trim()) {
|
|
498
992
|
setError(new Error("Please enter a command"));
|
|
499
993
|
setState("error");
|
|
500
994
|
return;
|
|
501
995
|
}
|
|
996
|
+
if (internalPlanMode && state !== "plan-pending") {
|
|
997
|
+
setState("loading");
|
|
998
|
+
setError(null);
|
|
999
|
+
setCommand("");
|
|
1000
|
+
if (useMock) {
|
|
1001
|
+
setTimeout(() => {
|
|
1002
|
+
const mockPlan = generateMockPlan(currentCommand);
|
|
1003
|
+
setPlan(mockPlan);
|
|
1004
|
+
setPendingCommand(currentCommand);
|
|
1005
|
+
setState("plan-pending");
|
|
1006
|
+
}, 800);
|
|
1007
|
+
} else {
|
|
1008
|
+
try {
|
|
1009
|
+
let messageContent;
|
|
1010
|
+
if (uploadedFiles.length > 0) {
|
|
1011
|
+
messageContent = [
|
|
1012
|
+
{
|
|
1013
|
+
type: "text",
|
|
1014
|
+
text: currentCommand
|
|
1015
|
+
},
|
|
1016
|
+
...uploadedFiles.map((file) => ({
|
|
1017
|
+
type: file.type,
|
|
1018
|
+
source: {
|
|
1019
|
+
type: "base64",
|
|
1020
|
+
media_type: file.mediaType,
|
|
1021
|
+
data: file.data
|
|
1022
|
+
}
|
|
1023
|
+
}))
|
|
1024
|
+
];
|
|
1025
|
+
} else {
|
|
1026
|
+
messageContent = currentCommand;
|
|
1027
|
+
}
|
|
1028
|
+
let systemMessage = context || "";
|
|
1029
|
+
const planningInstruction = `CRITICAL PLANNING MODE - READ CAREFULLY:
|
|
1030
|
+
|
|
1031
|
+
You are ONLY creating a plan. You are NOT executing anything.
|
|
1032
|
+
|
|
1033
|
+
YOUR TASK: Write a numbered list of steps describing what WOULD be done.
|
|
1034
|
+
DO NOT: Execute any actions, make API calls, access databases, modify data, or perform any operations.
|
|
1035
|
+
DO NOT: Ask questions or clarifications. Make reasonable assumptions.
|
|
1036
|
+
DO: Describe the steps as "Step 1: Would search database...", "Step 2: Would analyze results...", etc.
|
|
1037
|
+
DO: Use default values or best practices if details are missing.
|
|
1038
|
+
|
|
1039
|
+
FORMAT REQUIRED:
|
|
1040
|
+
1. [First action that would be taken]
|
|
1041
|
+
2. [Second action that would be taken]
|
|
1042
|
+
3. [Third action that would be taken]
|
|
1043
|
+
...
|
|
1044
|
+
|
|
1045
|
+
IMPORTANT: This is COMMAND MODE - figure things out yourself. Make intelligent assumptions based on context. ONLY ask questions if something is absolutely impossible to proceed without (e.g., missing required credentials). Otherwise, use sensible defaults and proceed with the plan.
|
|
1046
|
+
|
|
1047
|
+
REMEMBER: This is ONLY a plan. The user will approve it, THEN it will be executed. Right now you are just describing what would happen - NOT doing it.`;
|
|
1048
|
+
systemMessage = systemMessage ? `${systemMessage}
|
|
1049
|
+
|
|
1050
|
+
${planningInstruction}` : planningInstruction;
|
|
1051
|
+
aptevaClient.chat({
|
|
1052
|
+
agent_id: agentId,
|
|
1053
|
+
message: messageContent,
|
|
1054
|
+
stream: false,
|
|
1055
|
+
system: systemMessage
|
|
1056
|
+
}).then((response) => {
|
|
1057
|
+
setPlan(response.message);
|
|
1058
|
+
setPendingCommand(currentCommand);
|
|
1059
|
+
setState("plan-pending");
|
|
1060
|
+
}).catch((err) => {
|
|
1061
|
+
const error2 = err instanceof Error ? err : new Error("Failed to generate plan");
|
|
1062
|
+
setError(error2);
|
|
1063
|
+
setState("error");
|
|
1064
|
+
_optionalChain([onError, 'optionalCall', _20 => _20(error2)]);
|
|
1065
|
+
});
|
|
1066
|
+
} catch (err) {
|
|
1067
|
+
const error2 = err instanceof Error ? err : new Error("Failed to generate plan");
|
|
1068
|
+
setError(error2);
|
|
1069
|
+
setState("error");
|
|
1070
|
+
_optionalChain([onError, 'optionalCall', _21 => _21(error2)]);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
502
1075
|
setState("loading");
|
|
503
1076
|
setError(null);
|
|
504
1077
|
setProgress(0);
|
|
505
1078
|
setStreamedContent("");
|
|
506
|
-
|
|
1079
|
+
setCommand("");
|
|
1080
|
+
setUploadedFiles([]);
|
|
1081
|
+
_optionalChain([onStart, 'optionalCall', _22 => _22()]);
|
|
507
1082
|
try {
|
|
508
|
-
if (
|
|
509
|
-
|
|
510
|
-
"
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
1083
|
+
if (useMock) {
|
|
1084
|
+
if (enableStreaming) {
|
|
1085
|
+
let accumulatedContent = "";
|
|
1086
|
+
generateMockCommandStream(
|
|
1087
|
+
currentCommand,
|
|
1088
|
+
(chunk) => {
|
|
1089
|
+
if (chunk.type === "token" && chunk.content) {
|
|
1090
|
+
accumulatedContent += chunk.content;
|
|
1091
|
+
setStreamedContent(accumulatedContent);
|
|
1092
|
+
_optionalChain([onChunk, 'optionalCall', _23 => _23(chunk.content)]);
|
|
1093
|
+
const estimatedProgress = Math.min(Math.round(accumulatedContent.length / 10), 90);
|
|
1094
|
+
setProgress(estimatedProgress);
|
|
1095
|
+
_optionalChain([onProgress, 'optionalCall', _24 => _24(estimatedProgress)]);
|
|
1096
|
+
} else if (chunk.type === "widget" && chunk.widget) {
|
|
1097
|
+
const widget = chunk.widget;
|
|
1098
|
+
setResult((prev) => ({
|
|
1099
|
+
success: true,
|
|
1100
|
+
data: _optionalChain([prev, 'optionalAccess', _25 => _25.data]) || {},
|
|
1101
|
+
widgets: [..._optionalChain([prev, 'optionalAccess', _26 => _26.widgets]) || [], widget],
|
|
1102
|
+
message: accumulatedContent || "Command executed successfully"
|
|
1103
|
+
}));
|
|
1104
|
+
}
|
|
1105
|
+
},
|
|
1106
|
+
(threadId) => {
|
|
1107
|
+
const result2 = {
|
|
1108
|
+
success: true,
|
|
1109
|
+
data: {
|
|
1110
|
+
summary: accumulatedContent,
|
|
1111
|
+
thread_id: threadId,
|
|
1112
|
+
agentId,
|
|
1113
|
+
context,
|
|
1114
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1115
|
+
},
|
|
1116
|
+
message: accumulatedContent || "Command executed successfully"
|
|
1117
|
+
};
|
|
1118
|
+
setResult(result2);
|
|
1119
|
+
setState("success");
|
|
1120
|
+
setProgress(100);
|
|
1121
|
+
_optionalChain([onComplete, 'optionalCall', _27 => _27(result2)]);
|
|
1122
|
+
},
|
|
1123
|
+
(error2) => {
|
|
1124
|
+
setError(error2);
|
|
1125
|
+
setState("error");
|
|
1126
|
+
_optionalChain([onError, 'optionalCall', _28 => _28(error2)]);
|
|
1127
|
+
}
|
|
1128
|
+
);
|
|
1129
|
+
} else {
|
|
1130
|
+
const progressInterval = setInterval(() => {
|
|
1131
|
+
setProgress((prev) => {
|
|
1132
|
+
const next = Math.min(prev + 10, 90);
|
|
1133
|
+
_optionalChain([onProgress, 'optionalCall', _29 => _29(next)]);
|
|
1134
|
+
return next;
|
|
1135
|
+
});
|
|
1136
|
+
}, 200);
|
|
1137
|
+
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
1138
|
+
clearInterval(progressInterval);
|
|
1139
|
+
const mockResponse = generateMockCommandWithWidgets(currentCommand);
|
|
1140
|
+
const result2 = {
|
|
1141
|
+
success: true,
|
|
1142
|
+
data: {
|
|
1143
|
+
summary: mockResponse.message,
|
|
1144
|
+
thread_id: `mock_thread_${Date.now()}`,
|
|
1145
|
+
agentId,
|
|
1146
|
+
context,
|
|
1147
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1148
|
+
action: mockResponse.action
|
|
1149
|
+
// Include agent action intent
|
|
1150
|
+
},
|
|
1151
|
+
widgets: mockResponse.widgets,
|
|
1152
|
+
message: mockResponse.message
|
|
1153
|
+
};
|
|
1154
|
+
setResult(result2);
|
|
1155
|
+
setState("success");
|
|
1156
|
+
setProgress(100);
|
|
1157
|
+
_optionalChain([onComplete, 'optionalCall', _30 => _30(result2)]);
|
|
525
1158
|
}
|
|
526
|
-
const mockResult = {
|
|
527
|
-
success: true,
|
|
528
|
-
data: {
|
|
529
|
-
summary: `Successfully processed: "${command}"`,
|
|
530
|
-
agentId,
|
|
531
|
-
context,
|
|
532
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
533
|
-
},
|
|
534
|
-
message: "Command executed successfully"
|
|
535
|
-
};
|
|
536
|
-
setResult(mockResult);
|
|
537
|
-
setState("success");
|
|
538
|
-
setProgress(100);
|
|
539
|
-
_optionalChain([onComplete, 'optionalCall', _12 => _12(mockResult)]);
|
|
540
1159
|
} else {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
1160
|
+
if (enableStreaming) {
|
|
1161
|
+
let accumulatedContent = "";
|
|
1162
|
+
let messageContent;
|
|
1163
|
+
if (uploadedFiles.length > 0) {
|
|
1164
|
+
messageContent = [
|
|
1165
|
+
{
|
|
1166
|
+
type: "text",
|
|
1167
|
+
text: currentCommand
|
|
1168
|
+
},
|
|
1169
|
+
...uploadedFiles.map((file) => ({
|
|
1170
|
+
type: file.type,
|
|
1171
|
+
// 'image' or 'document'
|
|
1172
|
+
source: {
|
|
1173
|
+
type: "base64",
|
|
1174
|
+
media_type: file.mediaType,
|
|
1175
|
+
data: file.data
|
|
1176
|
+
}
|
|
1177
|
+
}))
|
|
1178
|
+
];
|
|
1179
|
+
} else {
|
|
1180
|
+
messageContent = currentCommand;
|
|
1181
|
+
}
|
|
1182
|
+
let systemMessage = context || "";
|
|
1183
|
+
let commandInstruction;
|
|
1184
|
+
if (isCompact) {
|
|
1185
|
+
commandInstruction = 'CRITICAL COMMAND MODE: Maximum 10 words per response. Execute immediately, make intelligent assumptions, use defaults when needed. NO questions unless absolutely critical (missing required credentials). State action or result ONLY. Examples: "Searching database for matching records..." or "Found 3 user records in database" or "Task completed successfully". NO greetings, NO explanations, NO clarification requests. Just execute and report.';
|
|
1186
|
+
} else {
|
|
1187
|
+
commandInstruction = `CRITICAL COMMAND MODE: Maximum 10 words per response. Execute the command immediately. Make reasonable assumptions based on context. Use sensible defaults for missing details. DO NOT ask questions unless something is truly impossible without user input (e.g., missing required password). State what you're doing or the result. Examples: "Analyzing customer data from last quarter..." or "Created 5 new database entries successfully" or "Search complete: found 12 matching results". NO greetings, NO filler words, NO clarification requests. Action/result only.`;
|
|
1188
|
+
}
|
|
1189
|
+
systemMessage = systemMessage ? `${systemMessage}
|
|
1190
|
+
|
|
1191
|
+
${commandInstruction}` : commandInstruction;
|
|
1192
|
+
await aptevaClient.chatStream(
|
|
1193
|
+
{
|
|
1194
|
+
agent_id: agentId,
|
|
1195
|
+
message: messageContent,
|
|
1196
|
+
stream: true,
|
|
1197
|
+
...systemMessage && { system: systemMessage }
|
|
1198
|
+
},
|
|
1199
|
+
(chunk) => {
|
|
1200
|
+
if (chunk.type === "token" && chunk.content) {
|
|
1201
|
+
accumulatedContent += chunk.content;
|
|
1202
|
+
setStreamedContent(accumulatedContent);
|
|
1203
|
+
_optionalChain([onChunk, 'optionalCall', _31 => _31(chunk.content)]);
|
|
1204
|
+
const estimatedProgress = Math.min(Math.round(accumulatedContent.length / 10), 90);
|
|
1205
|
+
setProgress(estimatedProgress);
|
|
1206
|
+
_optionalChain([onProgress, 'optionalCall', _32 => _32(estimatedProgress)]);
|
|
1207
|
+
} else if (chunk.type === "widget" && chunk.widget) {
|
|
1208
|
+
const widget = chunk.widget;
|
|
1209
|
+
setResult((prev) => ({
|
|
1210
|
+
success: true,
|
|
1211
|
+
data: _optionalChain([prev, 'optionalAccess', _33 => _33.data]) || {},
|
|
1212
|
+
widgets: [..._optionalChain([prev, 'optionalAccess', _34 => _34.widgets]) || [], widget],
|
|
1213
|
+
message: accumulatedContent || "Command executed successfully"
|
|
1214
|
+
}));
|
|
1215
|
+
}
|
|
1216
|
+
},
|
|
1217
|
+
(threadId) => {
|
|
1218
|
+
const result2 = {
|
|
1219
|
+
success: true,
|
|
1220
|
+
data: {
|
|
1221
|
+
summary: accumulatedContent,
|
|
1222
|
+
thread_id: threadId,
|
|
1223
|
+
agentId,
|
|
1224
|
+
context,
|
|
1225
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1226
|
+
},
|
|
1227
|
+
message: accumulatedContent || "Command executed successfully"
|
|
1228
|
+
};
|
|
1229
|
+
setResult(result2);
|
|
1230
|
+
setState("success");
|
|
1231
|
+
setProgress(100);
|
|
1232
|
+
_optionalChain([onComplete, 'optionalCall', _35 => _35(result2)]);
|
|
1233
|
+
},
|
|
1234
|
+
(error2) => {
|
|
1235
|
+
const err = error2 instanceof Error ? error2 : new Error("Unknown error");
|
|
1236
|
+
setError(err);
|
|
1237
|
+
setState("error");
|
|
1238
|
+
_optionalChain([onError, 'optionalCall', _36 => _36(err)]);
|
|
1239
|
+
}
|
|
1240
|
+
);
|
|
1241
|
+
} else {
|
|
1242
|
+
const progressInterval = setInterval(() => {
|
|
1243
|
+
setProgress((prev) => {
|
|
1244
|
+
const next = Math.min(prev + 10, 90);
|
|
1245
|
+
_optionalChain([onProgress, 'optionalCall', _37 => _37(next)]);
|
|
1246
|
+
return next;
|
|
1247
|
+
});
|
|
1248
|
+
}, 200);
|
|
1249
|
+
let messageContent;
|
|
1250
|
+
if (uploadedFiles.length > 0) {
|
|
1251
|
+
messageContent = [
|
|
1252
|
+
{
|
|
1253
|
+
type: "text",
|
|
1254
|
+
text: currentCommand
|
|
1255
|
+
},
|
|
1256
|
+
...uploadedFiles.map((file) => ({
|
|
1257
|
+
type: file.type,
|
|
1258
|
+
// 'image' or 'document'
|
|
1259
|
+
source: {
|
|
1260
|
+
type: "base64",
|
|
1261
|
+
media_type: file.mediaType,
|
|
1262
|
+
data: file.data
|
|
1263
|
+
}
|
|
1264
|
+
}))
|
|
1265
|
+
];
|
|
1266
|
+
} else {
|
|
1267
|
+
messageContent = currentCommand;
|
|
1268
|
+
}
|
|
1269
|
+
let systemMessage = context || "";
|
|
1270
|
+
let commandInstruction;
|
|
1271
|
+
if (isCompact) {
|
|
1272
|
+
commandInstruction = 'CRITICAL COMMAND MODE: Maximum 10 words per response. Execute immediately, make intelligent assumptions, use defaults when needed. NO questions unless absolutely critical (missing required credentials). State action or result ONLY. Examples: "Searching database for matching records..." or "Found 3 user records in database" or "Task completed successfully". NO greetings, NO explanations, NO clarification requests. Just execute and report.';
|
|
1273
|
+
} else {
|
|
1274
|
+
commandInstruction = `CRITICAL COMMAND MODE: Maximum 10 words per response. Execute the command immediately. Make reasonable assumptions based on context. Use sensible defaults for missing details. DO NOT ask questions unless something is truly impossible without user input (e.g., missing required password). State what you're doing or the result. Examples: "Analyzing customer data from last quarter..." or "Created 5 new database entries successfully" or "Search complete: found 12 matching results". NO greetings, NO filler words, NO clarification requests. Action/result only.`;
|
|
1275
|
+
}
|
|
1276
|
+
systemMessage = systemMessage ? `${systemMessage}
|
|
1277
|
+
|
|
1278
|
+
${commandInstruction}` : commandInstruction;
|
|
1279
|
+
const response = await aptevaClient.chat({
|
|
1280
|
+
agent_id: agentId,
|
|
1281
|
+
message: messageContent,
|
|
1282
|
+
stream: false,
|
|
1283
|
+
...systemMessage && { system: systemMessage }
|
|
546
1284
|
});
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
1285
|
+
clearInterval(progressInterval);
|
|
1286
|
+
const result2 = {
|
|
1287
|
+
success: true,
|
|
1288
|
+
data: {
|
|
1289
|
+
summary: response.message,
|
|
1290
|
+
thread_id: response.thread_id,
|
|
1291
|
+
agentId,
|
|
1292
|
+
context,
|
|
1293
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1294
|
+
},
|
|
1295
|
+
widgets: response.widgets,
|
|
1296
|
+
message: response.message
|
|
1297
|
+
};
|
|
1298
|
+
setResult(result2);
|
|
1299
|
+
setState("success");
|
|
1300
|
+
setProgress(100);
|
|
1301
|
+
_optionalChain([onComplete, 'optionalCall', _38 => _38(result2)]);
|
|
1302
|
+
}
|
|
564
1303
|
}
|
|
565
1304
|
} catch (err) {
|
|
566
1305
|
const error2 = err instanceof Error ? err : new Error("Unknown error");
|
|
567
1306
|
setError(error2);
|
|
568
1307
|
setState("error");
|
|
569
|
-
_optionalChain([onError, 'optionalCall',
|
|
1308
|
+
_optionalChain([onError, 'optionalCall', _39 => _39(error2)]);
|
|
570
1309
|
}
|
|
571
1310
|
};
|
|
572
1311
|
const resetCommand = () => {
|
|
@@ -575,6 +1314,68 @@ function Command({
|
|
|
575
1314
|
setError(null);
|
|
576
1315
|
setProgress(0);
|
|
577
1316
|
setCommand("");
|
|
1317
|
+
setPlan("");
|
|
1318
|
+
setPendingCommand("");
|
|
1319
|
+
setShowPlanDetails(false);
|
|
1320
|
+
setUploadedFiles([]);
|
|
1321
|
+
};
|
|
1322
|
+
const approvePlan = () => {
|
|
1323
|
+
setShowPlanDetails(false);
|
|
1324
|
+
const planToExecute = plan;
|
|
1325
|
+
setPlan("");
|
|
1326
|
+
setPendingCommand("");
|
|
1327
|
+
const executionMessage = `Execute this plan now:
|
|
1328
|
+
|
|
1329
|
+
${planToExecute}`;
|
|
1330
|
+
executeCommand(executionMessage);
|
|
1331
|
+
};
|
|
1332
|
+
const rejectPlan = () => {
|
|
1333
|
+
setCommand(pendingCommand);
|
|
1334
|
+
setPlan("");
|
|
1335
|
+
setPendingCommand("");
|
|
1336
|
+
setShowPlanDetails(false);
|
|
1337
|
+
setState("idle");
|
|
1338
|
+
};
|
|
1339
|
+
const handleFileSelect = async (e) => {
|
|
1340
|
+
if (e.target.files && e.target.files.length > 0) {
|
|
1341
|
+
_optionalChain([onFileUpload, 'optionalCall', _40 => _40(e.target.files)]);
|
|
1342
|
+
const files = [];
|
|
1343
|
+
for (let i = 0; i < e.target.files.length; i++) {
|
|
1344
|
+
const file = e.target.files[i];
|
|
1345
|
+
const reader = new FileReader();
|
|
1346
|
+
await new Promise((resolve) => {
|
|
1347
|
+
reader.onload = (event) => {
|
|
1348
|
+
if (_optionalChain([event, 'access', _41 => _41.target, 'optionalAccess', _42 => _42.result])) {
|
|
1349
|
+
const fullDataUrl = event.target.result;
|
|
1350
|
+
const base64Data = fullDataUrl.split(",")[1];
|
|
1351
|
+
if (file.type.startsWith("image/")) {
|
|
1352
|
+
files.push({
|
|
1353
|
+
type: "image",
|
|
1354
|
+
data: base64Data,
|
|
1355
|
+
mediaType: file.type,
|
|
1356
|
+
preview: fullDataUrl,
|
|
1357
|
+
// Keep full data URL for preview
|
|
1358
|
+
name: file.name
|
|
1359
|
+
});
|
|
1360
|
+
} else if (file.type === "application/pdf" || file.type.startsWith("application/")) {
|
|
1361
|
+
files.push({
|
|
1362
|
+
type: "document",
|
|
1363
|
+
data: base64Data,
|
|
1364
|
+
mediaType: file.type,
|
|
1365
|
+
name: file.name
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
resolve();
|
|
1370
|
+
};
|
|
1371
|
+
reader.readAsDataURL(file);
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
setUploadedFiles((prev) => [...prev, ...files]);
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1377
|
+
const removeFile = (index) => {
|
|
1378
|
+
setUploadedFiles((prev) => prev.filter((_, i) => i !== index));
|
|
578
1379
|
};
|
|
579
1380
|
const isCompact = variant === "compact";
|
|
580
1381
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
@@ -585,6 +1386,7 @@ function Command({
|
|
|
585
1386
|
state === "loading" && "animate-pulse-border",
|
|
586
1387
|
state === "idle" && "border-gray-300 dark:border-gray-700",
|
|
587
1388
|
state === "loading" && "border-blue-500",
|
|
1389
|
+
state === "plan-pending" && "border-blue-400",
|
|
588
1390
|
state === "success" && "border-green-500",
|
|
589
1391
|
state === "error" && "border-red-500",
|
|
590
1392
|
className
|
|
@@ -592,23 +1394,133 @@ function Command({
|
|
|
592
1394
|
style: { minHeight: isCompact ? "auto" : "180px" },
|
|
593
1395
|
children: [
|
|
594
1396
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: cn("flex-1 flex", isCompact ? "flex-row items-center p-3 gap-3" : "flex-col p-4"), children: [
|
|
595
|
-
state === "idle" && allowInput && !isCompact && /* @__PURE__ */ _jsxruntime.
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
e.
|
|
603
|
-
|
|
1397
|
+
state === "idle" && allowInput && !isCompact && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
1398
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1399
|
+
"textarea",
|
|
1400
|
+
{
|
|
1401
|
+
value: command,
|
|
1402
|
+
onChange: (e) => setCommand(e.target.value),
|
|
1403
|
+
onKeyDown: (e) => {
|
|
1404
|
+
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
|
|
1405
|
+
e.preventDefault();
|
|
1406
|
+
executeCommand();
|
|
1407
|
+
}
|
|
1408
|
+
},
|
|
1409
|
+
placeholder,
|
|
1410
|
+
className: "flex-1 w-full resize-none bg-transparent border-none focus:outline-none !text-gray-900 dark:!text-gray-100 placeholder-gray-400 dark:placeholder-gray-500",
|
|
1411
|
+
rows: 6
|
|
1412
|
+
}
|
|
1413
|
+
),
|
|
1414
|
+
uploadedFiles.length > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex flex-wrap gap-2 mt-2", children: uploadedFiles.map((file, index) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "relative group", children: [
|
|
1415
|
+
file.type === "image" ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1416
|
+
"img",
|
|
1417
|
+
{
|
|
1418
|
+
src: file.preview,
|
|
1419
|
+
alt: file.name,
|
|
1420
|
+
className: "w-20 h-20 object-cover rounded-lg border-2 border-gray-300 dark:border-gray-600"
|
|
604
1421
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
1422
|
+
) : /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "w-20 h-20 flex flex-col items-center justify-center rounded-lg border-2 border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-800", children: [
|
|
1423
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-8 h-8 text-gray-500 dark:text-gray-400", fill: "currentColor", viewBox: "0 0 20 20", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { fillRule: "evenodd", d: "M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4zm2 6a1 1 0 011-1h6a1 1 0 110 2H7a1 1 0 01-1-1zm1 3a1 1 0 100 2h6a1 1 0 100-2H7z", clipRule: "evenodd" }) }),
|
|
1424
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-[8px] text-gray-500 dark:text-gray-400 mt-1 px-1 truncate max-w-full", children: file.name.length > 12 ? file.name.slice(0, 12) + "..." : file.name })
|
|
1425
|
+
] }),
|
|
1426
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1427
|
+
"button",
|
|
1428
|
+
{
|
|
1429
|
+
onClick: () => removeFile(index),
|
|
1430
|
+
className: "absolute -top-2 -right-2 w-6 h-6 bg-red-500 hover:bg-red-600 text-white rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",
|
|
1431
|
+
title: `Remove ${file.type}`,
|
|
1432
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-4 h-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) })
|
|
1433
|
+
}
|
|
1434
|
+
)
|
|
1435
|
+
] }, index)) })
|
|
1436
|
+
] }),
|
|
611
1437
|
state === "idle" && allowInput && isCompact && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
1438
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center gap-0.5 flex-shrink-0", children: [
|
|
1439
|
+
enableFileUpload && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1440
|
+
"button",
|
|
1441
|
+
{
|
|
1442
|
+
onClick: () => _optionalChain([fileInputRef, 'access', _43 => _43.current, 'optionalAccess', _44 => _44.click, 'call', _45 => _45()]),
|
|
1443
|
+
className: "w-8 h-8 rounded-lg flex items-center justify-center transition-all flex-shrink-0 !text-gray-500 dark:!text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-800",
|
|
1444
|
+
title: "Attach file",
|
|
1445
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M8.4 2.8L4.4 6.8C3.736 7.464 3.736 8.536 4.4 9.2C5.064 9.864 6.136 9.864 6.8 9.2L11.6 4.4C12.704 3.296 12.704 1.504 11.6 0.4C10.496 -0.704 8.704 -0.704 7.6 0.4L2.8 5.2C1.256 6.744 1.256 9.256 2.8 10.8C4.344 12.344 6.856 12.344 8.4 10.8L12.4 6.8", stroke: "currentColor", strokeWidth: "1.2", strokeLinecap: "round", strokeLinejoin: "round", transform: "translate(1.6, 2.4)" }) })
|
|
1446
|
+
}
|
|
1447
|
+
),
|
|
1448
|
+
planMode && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "relative settings-menu-container", children: [
|
|
1449
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1450
|
+
"button",
|
|
1451
|
+
{
|
|
1452
|
+
onClick: () => setShowSettingsMenu(!showSettingsMenu),
|
|
1453
|
+
className: cn(
|
|
1454
|
+
"w-8 h-8 rounded-lg flex items-center justify-center transition-all flex-shrink-0 hover:bg-gray-100 dark:hover:bg-gray-800",
|
|
1455
|
+
internalPlanMode ? "!text-blue-600 dark:!text-blue-400" : "!text-gray-500 dark:!text-gray-500"
|
|
1456
|
+
),
|
|
1457
|
+
title: "Settings",
|
|
1458
|
+
children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
1459
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "4", y1: "21", x2: "4", y2: "14" }),
|
|
1460
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "4", y1: "10", x2: "4", y2: "3" }),
|
|
1461
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "12", y1: "21", x2: "12", y2: "12" }),
|
|
1462
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "12", y1: "8", x2: "12", y2: "3" }),
|
|
1463
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "20", y1: "21", x2: "20", y2: "16" }),
|
|
1464
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "20", y1: "12", x2: "20", y2: "3" }),
|
|
1465
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "1", y1: "14", x2: "7", y2: "14" }),
|
|
1466
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "9", y1: "8", x2: "15", y2: "8" }),
|
|
1467
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "17", y1: "16", x2: "23", y2: "16" })
|
|
1468
|
+
] })
|
|
1469
|
+
}
|
|
1470
|
+
),
|
|
1471
|
+
showSettingsMenu && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "absolute top-10 left-0 z-50 w-56 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg p-2.5 settings-menu-container", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "label", { className: "flex items-center justify-between cursor-pointer group", children: [
|
|
1472
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center gap-2", children: [
|
|
1473
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-3.5 h-3.5 text-gray-500 dark:text-gray-400", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01" }) }),
|
|
1474
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
|
|
1475
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-xs font-medium text-gray-700 dark:text-gray-300", children: "Plan Mode" }),
|
|
1476
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-[10px] text-gray-500 dark:text-gray-400", children: "Review first" })
|
|
1477
|
+
] })
|
|
1478
|
+
] }),
|
|
1479
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1480
|
+
"button",
|
|
1481
|
+
{
|
|
1482
|
+
onClick: (e) => {
|
|
1483
|
+
e.stopPropagation();
|
|
1484
|
+
setInternalPlanMode(!internalPlanMode);
|
|
1485
|
+
},
|
|
1486
|
+
className: cn(
|
|
1487
|
+
"relative inline-flex h-4 w-8 items-center rounded-full transition-colors",
|
|
1488
|
+
internalPlanMode ? "bg-blue-600" : "bg-gray-300 dark:bg-gray-600"
|
|
1489
|
+
),
|
|
1490
|
+
type: "button",
|
|
1491
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1492
|
+
"span",
|
|
1493
|
+
{
|
|
1494
|
+
className: cn(
|
|
1495
|
+
"inline-block h-3 w-3 transform rounded-full bg-white transition-transform",
|
|
1496
|
+
internalPlanMode ? "translate-x-4.5" : "translate-x-0.5"
|
|
1497
|
+
)
|
|
1498
|
+
}
|
|
1499
|
+
)
|
|
1500
|
+
}
|
|
1501
|
+
)
|
|
1502
|
+
] }) })
|
|
1503
|
+
] })
|
|
1504
|
+
] }),
|
|
1505
|
+
uploadedFiles.length > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex gap-1 flex-shrink-0", children: uploadedFiles.map((file, index) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "relative group", children: [
|
|
1506
|
+
file.type === "image" ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1507
|
+
"img",
|
|
1508
|
+
{
|
|
1509
|
+
src: file.preview,
|
|
1510
|
+
alt: file.name,
|
|
1511
|
+
className: "w-8 h-8 object-cover rounded border border-gray-300 dark:border-gray-600"
|
|
1512
|
+
}
|
|
1513
|
+
) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "w-8 h-8 flex items-center justify-center rounded border border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-800", title: file.name, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-4 h-4 text-gray-500 dark:text-gray-400", fill: "currentColor", viewBox: "0 0 20 20", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { fillRule: "evenodd", d: "M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4zm2 6a1 1 0 011-1h6a1 1 0 110 2H7a1 1 0 01-1-1zm1 3a1 1 0 100 2h6a1 1 0 100-2H7z", clipRule: "evenodd" }) }) }),
|
|
1514
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1515
|
+
"button",
|
|
1516
|
+
{
|
|
1517
|
+
onClick: () => removeFile(index),
|
|
1518
|
+
className: "absolute -top-1 -right-1 w-4 h-4 bg-red-500 hover:bg-red-600 text-white rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",
|
|
1519
|
+
title: "Remove",
|
|
1520
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-2.5 h-2.5", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 3, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" }) })
|
|
1521
|
+
}
|
|
1522
|
+
)
|
|
1523
|
+
] }, index)) }),
|
|
612
1524
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
613
1525
|
"input",
|
|
614
1526
|
{
|
|
@@ -628,7 +1540,7 @@ function Command({
|
|
|
628
1540
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
629
1541
|
"button",
|
|
630
1542
|
{
|
|
631
|
-
onClick: executeCommand,
|
|
1543
|
+
onClick: () => executeCommand(),
|
|
632
1544
|
disabled: !command.trim(),
|
|
633
1545
|
className: cn(
|
|
634
1546
|
"w-8 h-8 rounded-lg flex items-center justify-center font-bold transition-all flex-shrink-0",
|
|
@@ -641,7 +1553,7 @@ function Command({
|
|
|
641
1553
|
!command.trim() && "border-gray-200 dark:border-gray-700 !text-gray-400 dark:!text-gray-600"
|
|
642
1554
|
),
|
|
643
1555
|
title: "Execute",
|
|
644
|
-
children: "
|
|
1556
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M8 3L8 13M8 3L4 7M8 3L12 7", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
|
|
645
1557
|
}
|
|
646
1558
|
)
|
|
647
1559
|
] }),
|
|
@@ -679,16 +1591,74 @@ function Command({
|
|
|
679
1591
|
"!text-lg",
|
|
680
1592
|
"opacity-30 cursor-not-allowed"
|
|
681
1593
|
),
|
|
682
|
-
children: "
|
|
1594
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M8 3L8 13M8 3L4 7M8 3L12 7", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
|
|
683
1595
|
}
|
|
684
1596
|
)
|
|
685
1597
|
] }),
|
|
1598
|
+
state === "plan-pending" && !isCompact && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex-1 flex flex-col", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "mb-4 p-4 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg", children: [
|
|
1599
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-start gap-2 mb-3", children: [
|
|
1600
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-5 h-5 text-blue-600 dark:text-blue-400 mt-0.5 flex-shrink-0", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01" }) }),
|
|
1601
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex-1", children: [
|
|
1602
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { className: "text-sm font-semibold text-blue-800 dark:text-blue-300 mb-1", children: "Proposed Plan" }),
|
|
1603
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-blue-700 dark:text-blue-300 text-sm whitespace-pre-line leading-relaxed", children: plan })
|
|
1604
|
+
] })
|
|
1605
|
+
] }),
|
|
1606
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex gap-2 mt-4", children: [
|
|
1607
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1608
|
+
"button",
|
|
1609
|
+
{
|
|
1610
|
+
onClick: approvePlan,
|
|
1611
|
+
className: "flex-1 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors text-sm font-medium",
|
|
1612
|
+
children: "Approve & Execute"
|
|
1613
|
+
}
|
|
1614
|
+
),
|
|
1615
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1616
|
+
"button",
|
|
1617
|
+
{
|
|
1618
|
+
onClick: rejectPlan,
|
|
1619
|
+
className: "flex-1 px-4 py-2 bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-300 dark:hover:bg-gray-600 transition-colors text-sm font-medium",
|
|
1620
|
+
children: "Modify"
|
|
1621
|
+
}
|
|
1622
|
+
)
|
|
1623
|
+
] })
|
|
1624
|
+
] }) }),
|
|
1625
|
+
state === "plan-pending" && isCompact && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
1626
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
1627
|
+
"button",
|
|
1628
|
+
{
|
|
1629
|
+
onClick: () => setShowPlanDetails(true),
|
|
1630
|
+
className: "flex-1 flex items-center gap-2 px-3 py-2 bg-blue-50 dark:bg-blue-900/30 hover:bg-blue-100 dark:hover:bg-blue-900/40 border border-blue-200 dark:border-blue-800 rounded-lg transition-colors",
|
|
1631
|
+
children: [
|
|
1632
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-4 h-4 text-blue-600 dark:text-blue-400 flex-shrink-0", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01" }) }),
|
|
1633
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-sm font-medium text-blue-700 dark:text-blue-300 truncate flex-1", children: "View Execution Plan" })
|
|
1634
|
+
]
|
|
1635
|
+
}
|
|
1636
|
+
),
|
|
1637
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex gap-2 flex-shrink-0", children: [
|
|
1638
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1639
|
+
"button",
|
|
1640
|
+
{
|
|
1641
|
+
onClick: approvePlan,
|
|
1642
|
+
className: "px-3 py-1.5 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors text-xs font-medium",
|
|
1643
|
+
children: "Approve"
|
|
1644
|
+
}
|
|
1645
|
+
),
|
|
1646
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1647
|
+
"button",
|
|
1648
|
+
{
|
|
1649
|
+
onClick: rejectPlan,
|
|
1650
|
+
className: "px-3 py-1.5 bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-300 dark:hover:bg-gray-600 transition-colors text-xs font-medium",
|
|
1651
|
+
children: "Modify"
|
|
1652
|
+
}
|
|
1653
|
+
)
|
|
1654
|
+
] })
|
|
1655
|
+
] }),
|
|
686
1656
|
state === "error" && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex-1 flex flex-col", children: [
|
|
687
1657
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "mb-4 p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-start gap-2", children: [
|
|
688
1658
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-5 h-5 text-red-600 mt-0.5 flex-shrink-0", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) }),
|
|
689
1659
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
|
|
690
1660
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { className: "text-sm font-semibold text-red-800 dark:text-red-400", children: "Error" }),
|
|
691
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-red-700 dark:text-red-300 text-sm mt-1", children: _optionalChain([error, 'optionalAccess',
|
|
1661
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-red-700 dark:text-red-300 text-sm mt-1", children: _optionalChain([error, 'optionalAccess', _46 => _46.message]) })
|
|
692
1662
|
] })
|
|
693
1663
|
] }) }),
|
|
694
1664
|
allowInput && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
@@ -708,67 +1678,205 @@ function Command({
|
|
|
708
1678
|
}
|
|
709
1679
|
)
|
|
710
1680
|
] }),
|
|
711
|
-
state === "success" && result && !isCompact && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex-1 overflow-auto", children: resultRenderer ? resultRenderer(result.data) : /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
|
|
712
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-start gap-3
|
|
1681
|
+
state === "success" && result && !isCompact && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex-1 overflow-auto", children: resultRenderer ? resultRenderer(result.data) : /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "space-y-4", children: [
|
|
1682
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-start gap-3 p-3 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg", children: [
|
|
713
1683
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-5 h-5 text-green-600 mt-0.5 flex-shrink-0", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" }) }),
|
|
714
1684
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex-1", children: [
|
|
715
1685
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { className: "text-sm font-semibold text-green-800 dark:text-green-400 mb-1", children: "Success" }),
|
|
716
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-green-700 dark:text-green-300 text-sm", children:
|
|
1686
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-green-700 dark:text-green-300 text-sm", children: "Command executed successfully" })
|
|
717
1687
|
] })
|
|
718
1688
|
] }),
|
|
719
|
-
_optionalChain([result, 'access',
|
|
1689
|
+
_optionalChain([result, 'access', _47 => _47.data, 'optionalAccess', _48 => _48.summary]) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-gray-700 dark:text-gray-300 text-sm leading-relaxed whitespace-pre-line", children: result.data.summary }),
|
|
1690
|
+
result.widgets && result.widgets.length > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "space-y-3", children: result.widgets.map((widget) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1691
|
+
WidgetRenderer,
|
|
1692
|
+
{
|
|
1693
|
+
widget,
|
|
1694
|
+
onAction
|
|
1695
|
+
},
|
|
1696
|
+
widget.id
|
|
1697
|
+
)) })
|
|
720
1698
|
] }) }),
|
|
721
1699
|
state === "success" && result && isCompact && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
722
|
-
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
1700
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
1701
|
+
"div",
|
|
1702
|
+
{
|
|
1703
|
+
className: "flex-1 flex items-center gap-2 py-1 cursor-text min-w-0",
|
|
1704
|
+
onClick: () => {
|
|
1705
|
+
setState("idle");
|
|
1706
|
+
setResult(null);
|
|
1707
|
+
},
|
|
1708
|
+
children: [
|
|
1709
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-4 h-4 text-green-600 flex-shrink-0", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" }) }),
|
|
1710
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-green-700 dark:text-green-300 text-sm truncate flex-1 min-w-0", children: resultRenderer ? resultRenderer(result.data) : result.message || "Command executed successfully" })
|
|
1711
|
+
]
|
|
1712
|
+
}
|
|
1713
|
+
),
|
|
726
1714
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
727
1715
|
"button",
|
|
728
1716
|
{
|
|
729
|
-
|
|
1717
|
+
onClick: () => {
|
|
1718
|
+
setState("idle");
|
|
1719
|
+
setResult(null);
|
|
1720
|
+
},
|
|
730
1721
|
className: cn(
|
|
731
1722
|
"w-8 h-8 rounded-lg flex items-center justify-center font-bold transition-all flex-shrink-0",
|
|
732
|
-
"border border-gray-
|
|
1723
|
+
"border border-gray-300 dark:border-gray-600",
|
|
733
1724
|
"bg-white dark:bg-gray-800",
|
|
734
|
-
"!text-gray-
|
|
735
|
-
"
|
|
736
|
-
"
|
|
1725
|
+
"!text-gray-700 dark:!text-gray-300",
|
|
1726
|
+
"hover:bg-gray-50 dark:hover:bg-gray-700",
|
|
1727
|
+
"!text-lg"
|
|
737
1728
|
),
|
|
738
|
-
|
|
1729
|
+
title: "New command",
|
|
1730
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M8 3L8 13M8 3L4 7M8 3L12 7", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
|
|
739
1731
|
}
|
|
740
1732
|
)
|
|
741
1733
|
] })
|
|
742
1734
|
] }),
|
|
743
|
-
!isCompact && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "p-3 flex items-center justify-
|
|
744
|
-
(
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
{
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
1735
|
+
!isCompact && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "p-3 flex items-center justify-between gap-2", children: [
|
|
1736
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex items-center gap-1", children: state === "idle" && allowInput && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
1737
|
+
enableFileUpload && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1738
|
+
"button",
|
|
1739
|
+
{
|
|
1740
|
+
onClick: () => _optionalChain([fileInputRef, 'access', _49 => _49.current, 'optionalAccess', _50 => _50.click, 'call', _51 => _51()]),
|
|
1741
|
+
className: "w-8 h-8 rounded-lg flex items-center justify-center transition-all flex-shrink-0 !text-gray-500 dark:!text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-800",
|
|
1742
|
+
title: "Attach file",
|
|
1743
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M8.4 2.8L4.4 6.8C3.736 7.464 3.736 8.536 4.4 9.2C5.064 9.864 6.136 9.864 6.8 9.2L11.6 4.4C12.704 3.296 12.704 1.504 11.6 0.4C10.496 -0.704 8.704 -0.704 7.6 0.4L2.8 5.2C1.256 6.744 1.256 9.256 2.8 10.8C4.344 12.344 6.856 12.344 8.4 10.8L12.4 6.8", stroke: "currentColor", strokeWidth: "1.2", strokeLinecap: "round", strokeLinejoin: "round", transform: "translate(1.6, 2.4)" }) })
|
|
1744
|
+
}
|
|
1745
|
+
),
|
|
1746
|
+
planMode && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "relative settings-menu-container", children: [
|
|
1747
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1748
|
+
"button",
|
|
1749
|
+
{
|
|
1750
|
+
onClick: () => setShowSettingsMenu(!showSettingsMenu),
|
|
1751
|
+
className: cn(
|
|
1752
|
+
"w-8 h-8 rounded-lg flex items-center justify-center transition-all flex-shrink-0 hover:bg-gray-100 dark:hover:bg-gray-800",
|
|
1753
|
+
internalPlanMode ? "!text-blue-600 dark:!text-blue-400" : "!text-gray-500 dark:!text-gray-500"
|
|
1754
|
+
),
|
|
1755
|
+
title: "Settings",
|
|
1756
|
+
children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
1757
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "4", y1: "21", x2: "4", y2: "14" }),
|
|
1758
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "4", y1: "10", x2: "4", y2: "3" }),
|
|
1759
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "12", y1: "21", x2: "12", y2: "12" }),
|
|
1760
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "12", y1: "8", x2: "12", y2: "3" }),
|
|
1761
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "20", y1: "21", x2: "20", y2: "16" }),
|
|
1762
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "20", y1: "12", x2: "20", y2: "3" }),
|
|
1763
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "1", y1: "14", x2: "7", y2: "14" }),
|
|
1764
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "9", y1: "8", x2: "15", y2: "8" }),
|
|
1765
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "line", { x1: "17", y1: "16", x2: "23", y2: "16" })
|
|
1766
|
+
] })
|
|
1767
|
+
}
|
|
766
1768
|
),
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
1769
|
+
showSettingsMenu && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "absolute top-10 left-0 z-50 w-64 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg p-3 settings-menu-container", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "label", { className: "flex items-center justify-between cursor-pointer group", children: [
|
|
1770
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center gap-2", children: [
|
|
1771
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-4 h-4 text-gray-500 dark:text-gray-400", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01" }) }),
|
|
1772
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
|
|
1773
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-sm font-medium text-gray-700 dark:text-gray-300", children: "Plan Mode" }),
|
|
1774
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-xs text-gray-500 dark:text-gray-400", children: "Review before executing" })
|
|
1775
|
+
] })
|
|
1776
|
+
] }),
|
|
1777
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1778
|
+
"button",
|
|
1779
|
+
{
|
|
1780
|
+
onClick: (e) => {
|
|
1781
|
+
e.stopPropagation();
|
|
1782
|
+
setInternalPlanMode(!internalPlanMode);
|
|
1783
|
+
},
|
|
1784
|
+
className: cn(
|
|
1785
|
+
"relative inline-flex h-5 w-9 items-center rounded-full transition-colors",
|
|
1786
|
+
internalPlanMode ? "bg-blue-600" : "bg-gray-300 dark:bg-gray-600"
|
|
1787
|
+
),
|
|
1788
|
+
type: "button",
|
|
1789
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1790
|
+
"span",
|
|
1791
|
+
{
|
|
1792
|
+
className: cn(
|
|
1793
|
+
"inline-block h-3.5 w-3.5 transform rounded-full bg-white transition-transform",
|
|
1794
|
+
internalPlanMode ? "translate-x-5" : "translate-x-0.5"
|
|
1795
|
+
)
|
|
1796
|
+
}
|
|
1797
|
+
)
|
|
1798
|
+
}
|
|
1799
|
+
)
|
|
1800
|
+
] }) })
|
|
1801
|
+
] })
|
|
1802
|
+
] }) }),
|
|
1803
|
+
!(state === "idle" && allowInput) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", {}),
|
|
1804
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center gap-2", children: [
|
|
1805
|
+
(state === "success" || state === "error") && allowInput && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1806
|
+
"button",
|
|
1807
|
+
{
|
|
1808
|
+
onClick: resetCommand,
|
|
1809
|
+
className: "px-3 py-1.5 text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors",
|
|
1810
|
+
children: "Reset"
|
|
1811
|
+
}
|
|
1812
|
+
),
|
|
1813
|
+
(state === "idle" || state === "error") && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1814
|
+
"button",
|
|
1815
|
+
{
|
|
1816
|
+
onClick: () => executeCommand(),
|
|
1817
|
+
disabled: !command.trim(),
|
|
1818
|
+
className: cn(
|
|
1819
|
+
"w-8 h-8 rounded-lg flex items-center justify-center font-bold transition-all",
|
|
1820
|
+
"border border-gray-300 dark:border-gray-600",
|
|
1821
|
+
"bg-white dark:bg-gray-800",
|
|
1822
|
+
"!text-gray-700 dark:!text-gray-300",
|
|
1823
|
+
"hover:bg-gray-50 dark:hover:bg-gray-700",
|
|
1824
|
+
"disabled:opacity-30 disabled:cursor-not-allowed",
|
|
1825
|
+
"!text-lg",
|
|
1826
|
+
!command.trim() && "border-gray-200 dark:border-gray-700 !text-gray-400 dark:!text-gray-600"
|
|
1827
|
+
),
|
|
1828
|
+
title: state === "error" ? "Retry" : "Execute",
|
|
1829
|
+
children: state === "error" ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M13 8C13 10.7614 10.7614 13 8 13C5.23858 13 3 10.7614 3 8C3 5.23858 5.23858 3 8 3C9.65685 3 11.1257 3.82818 12 5.09091M12 3V5.09091M12 5.09091H9.81818", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M8 3L8 13M8 3L4 7M8 3L12 7", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
|
|
1830
|
+
}
|
|
1831
|
+
)
|
|
1832
|
+
] })
|
|
771
1833
|
] }),
|
|
1834
|
+
showPlanDetails && isCompact && state === "plan-pending" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4", onClick: () => setShowPlanDetails(false), children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "bg-white dark:bg-gray-900 rounded-2xl shadow-2xl max-w-2xl w-full max-h-[80vh] overflow-hidden", onClick: (e) => e.stopPropagation(), children: [
|
|
1835
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center justify-between p-6 border-b border-gray-200 dark:border-gray-700", children: [
|
|
1836
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center gap-3", children: [
|
|
1837
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-6 h-6 text-blue-600 dark:text-blue-400", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01" }) }),
|
|
1838
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { className: "text-xl font-semibold text-gray-900 dark:text-white", children: "Proposed Execution Plan" })
|
|
1839
|
+
] }),
|
|
1840
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1841
|
+
"button",
|
|
1842
|
+
{
|
|
1843
|
+
onClick: () => setShowPlanDetails(false),
|
|
1844
|
+
className: "text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors",
|
|
1845
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-6 h-6", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) })
|
|
1846
|
+
}
|
|
1847
|
+
)
|
|
1848
|
+
] }),
|
|
1849
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "p-6 overflow-y-auto max-h-[calc(80vh-180px)]", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "prose prose-sm dark:prose-invert max-w-none", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-gray-700 dark:text-gray-300 whitespace-pre-line leading-relaxed", children: plan }) }) }),
|
|
1850
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center justify-end gap-3 p-6 border-t border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50", children: [
|
|
1851
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1852
|
+
"button",
|
|
1853
|
+
{
|
|
1854
|
+
onClick: rejectPlan,
|
|
1855
|
+
className: "px-6 py-2.5 bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-300 dark:hover:bg-gray-600 transition-colors font-medium",
|
|
1856
|
+
children: "Modify Command"
|
|
1857
|
+
}
|
|
1858
|
+
),
|
|
1859
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1860
|
+
"button",
|
|
1861
|
+
{
|
|
1862
|
+
onClick: approvePlan,
|
|
1863
|
+
className: "px-6 py-2.5 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors font-medium",
|
|
1864
|
+
children: "Approve & Execute"
|
|
1865
|
+
}
|
|
1866
|
+
)
|
|
1867
|
+
] })
|
|
1868
|
+
] }) }),
|
|
1869
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1870
|
+
"input",
|
|
1871
|
+
{
|
|
1872
|
+
ref: fileInputRef,
|
|
1873
|
+
type: "file",
|
|
1874
|
+
multiple: true,
|
|
1875
|
+
onChange: handleFileSelect,
|
|
1876
|
+
className: "hidden",
|
|
1877
|
+
accept: "image/*,application/pdf,.doc,.docx,.txt"
|
|
1878
|
+
}
|
|
1879
|
+
),
|
|
772
1880
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "style", { dangerouslySetInnerHTML: {
|
|
773
1881
|
__html: `
|
|
774
1882
|
@keyframes pulse-border {
|
|
@@ -796,6 +1904,7 @@ function Prompt({
|
|
|
796
1904
|
agentId,
|
|
797
1905
|
placeholder = "Enter your prompt...",
|
|
798
1906
|
initialValue = "",
|
|
1907
|
+
useMock = true,
|
|
799
1908
|
submitOn = "button",
|
|
800
1909
|
debounceMs = 0,
|
|
801
1910
|
minLength = 0,
|
|
@@ -814,18 +1923,27 @@ function Prompt({
|
|
|
814
1923
|
const newValue = e.target.value;
|
|
815
1924
|
if (!maxLength || newValue.length <= maxLength) {
|
|
816
1925
|
setValue(newValue);
|
|
817
|
-
_optionalChain([onChange, 'optionalCall',
|
|
1926
|
+
_optionalChain([onChange, 'optionalCall', _52 => _52(newValue)]);
|
|
818
1927
|
}
|
|
819
1928
|
};
|
|
820
1929
|
const handleSubmit = async () => {
|
|
821
1930
|
if (value.length < minLength) return;
|
|
822
|
-
_optionalChain([onSubmit, 'optionalCall',
|
|
1931
|
+
_optionalChain([onSubmit, 'optionalCall', _53 => _53(value)]);
|
|
823
1932
|
setIsLoading(true);
|
|
824
1933
|
try {
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
1934
|
+
if (useMock) {
|
|
1935
|
+
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
1936
|
+
const mockResult = `Enhanced version: ${value} [AI-generated content]`;
|
|
1937
|
+
_optionalChain([onResult, 'optionalCall', _54 => _54(mockResult)]);
|
|
1938
|
+
setValue("");
|
|
1939
|
+
} else {
|
|
1940
|
+
const response = await aptevaClient.chat({
|
|
1941
|
+
agent_id: agentId,
|
|
1942
|
+
message: value
|
|
1943
|
+
});
|
|
1944
|
+
_optionalChain([onResult, 'optionalCall', _55 => _55(response.message)]);
|
|
1945
|
+
setValue("");
|
|
1946
|
+
}
|
|
829
1947
|
} catch (error) {
|
|
830
1948
|
console.error("Error processing prompt:", error);
|
|
831
1949
|
} finally {
|
|
@@ -898,6 +2016,7 @@ function Stream({
|
|
|
898
2016
|
prompt,
|
|
899
2017
|
context,
|
|
900
2018
|
autoStart = false,
|
|
2019
|
+
useMock = true,
|
|
901
2020
|
onStart,
|
|
902
2021
|
onChunk,
|
|
903
2022
|
onComplete,
|
|
@@ -917,23 +2036,51 @@ function Stream({
|
|
|
917
2036
|
}, [autoStart]);
|
|
918
2037
|
const startStreaming = async () => {
|
|
919
2038
|
setIsStreaming(true);
|
|
920
|
-
_optionalChain([onStart, 'optionalCall',
|
|
921
|
-
const mockText = "This is a simulated streaming response from the AI agent. In a real implementation, this would stream data from your backend API. The text appears word by word to simulate the streaming effect. You can customize the typing speed and styling based on your needs.";
|
|
2039
|
+
_optionalChain([onStart, 'optionalCall', _56 => _56()]);
|
|
922
2040
|
try {
|
|
923
|
-
|
|
924
|
-
mockText,
|
|
925
|
-
(
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
2041
|
+
if (useMock) {
|
|
2042
|
+
const mockText = "This is a simulated streaming response from the AI agent. In a real implementation, this would stream data from your backend API. The text appears word by word to simulate the streaming effect. You can customize the typing speed and styling based on your needs.";
|
|
2043
|
+
await generateMockStreamingResponse(
|
|
2044
|
+
mockText,
|
|
2045
|
+
(chunk) => {
|
|
2046
|
+
setText((prev) => prev + chunk);
|
|
2047
|
+
_optionalChain([onChunk, 'optionalCall', _57 => _57(chunk)]);
|
|
2048
|
+
},
|
|
2049
|
+
typingSpeed
|
|
2050
|
+
);
|
|
2051
|
+
setIsComplete(true);
|
|
2052
|
+
setIsStreaming(false);
|
|
2053
|
+
_optionalChain([onComplete, 'optionalCall', _58 => _58(text + mockText)]);
|
|
2054
|
+
} else {
|
|
2055
|
+
let accumulatedText = "";
|
|
2056
|
+
await aptevaClient.chatStream(
|
|
2057
|
+
{
|
|
2058
|
+
agent_id: agentId,
|
|
2059
|
+
message: prompt,
|
|
2060
|
+
stream: true
|
|
2061
|
+
},
|
|
2062
|
+
(chunk) => {
|
|
2063
|
+
if (chunk.type === "token" && chunk.content) {
|
|
2064
|
+
accumulatedText += chunk.content;
|
|
2065
|
+
setText(accumulatedText);
|
|
2066
|
+
_optionalChain([onChunk, 'optionalCall', _59 => _59(chunk.content)]);
|
|
2067
|
+
}
|
|
2068
|
+
},
|
|
2069
|
+
() => {
|
|
2070
|
+
setIsComplete(true);
|
|
2071
|
+
setIsStreaming(false);
|
|
2072
|
+
_optionalChain([onComplete, 'optionalCall', _60 => _60(accumulatedText)]);
|
|
2073
|
+
},
|
|
2074
|
+
(error) => {
|
|
2075
|
+
const err = error instanceof Error ? error : new Error("Streaming error");
|
|
2076
|
+
_optionalChain([onError, 'optionalCall', _61 => _61(err)]);
|
|
2077
|
+
setIsStreaming(false);
|
|
2078
|
+
}
|
|
2079
|
+
);
|
|
2080
|
+
}
|
|
934
2081
|
} catch (error) {
|
|
935
2082
|
const err = error instanceof Error ? error : new Error("Streaming error");
|
|
936
|
-
_optionalChain([onError, 'optionalCall',
|
|
2083
|
+
_optionalChain([onError, 'optionalCall', _62 => _62(err)]);
|
|
937
2084
|
setIsStreaming(false);
|
|
938
2085
|
}
|
|
939
2086
|
};
|
|
@@ -1025,7 +2172,7 @@ function ThreadList({
|
|
|
1025
2172
|
}) {
|
|
1026
2173
|
const [searchQuery, setSearchQuery] = _react.useState.call(void 0, "");
|
|
1027
2174
|
const filteredThreads = threads.filter(
|
|
1028
|
-
(thread) => thread.title.toLowerCase().includes(searchQuery.toLowerCase()) || _optionalChain([thread, 'access',
|
|
2175
|
+
(thread) => thread.title.toLowerCase().includes(searchQuery.toLowerCase()) || _optionalChain([thread, 'access', _63 => _63.preview, 'optionalAccess', _64 => _64.toLowerCase, 'call', _65 => _65(), 'access', _66 => _66.includes, 'call', _67 => _67(searchQuery.toLowerCase())])
|
|
1029
2176
|
);
|
|
1030
2177
|
const groupedThreads = groupBy === "date" ? groupThreadsByDate(filteredThreads) : { All: filteredThreads };
|
|
1031
2178
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col h-full", children: [
|
|
@@ -1047,8 +2194,8 @@ function ThreadList({
|
|
|
1047
2194
|
{
|
|
1048
2195
|
thread,
|
|
1049
2196
|
isActive: thread.id === currentThreadId,
|
|
1050
|
-
onSelect: () => _optionalChain([onThreadSelect, 'optionalCall',
|
|
1051
|
-
onDelete: () => _optionalChain([onThreadDelete, 'optionalCall',
|
|
2197
|
+
onSelect: () => _optionalChain([onThreadSelect, 'optionalCall', _68 => _68(thread.id)]),
|
|
2198
|
+
onDelete: () => _optionalChain([onThreadDelete, 'optionalCall', _69 => _69(thread.id)])
|
|
1052
2199
|
},
|
|
1053
2200
|
thread.id
|
|
1054
2201
|
))
|
|
@@ -1110,7 +2257,7 @@ function Threads({
|
|
|
1110
2257
|
threads.slice(0, 5).map((thread) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1111
2258
|
"button",
|
|
1112
2259
|
{
|
|
1113
|
-
onClick: () => _optionalChain([onThreadSelect, 'optionalCall',
|
|
2260
|
+
onClick: () => _optionalChain([onThreadSelect, 'optionalCall', _70 => _70(thread.id)]),
|
|
1114
2261
|
className: cn(
|
|
1115
2262
|
"px-4 py-2 whitespace-nowrap font-medium transition-colors",
|
|
1116
2263
|
thread.id === currentThreadId ? "border-b-2 border-apteva-500 text-apteva-500" : "text-gray-600 hover:text-gray-900"
|
|
@@ -1190,5 +2337,7 @@ function getThemeScript() {
|
|
|
1190
2337
|
|
|
1191
2338
|
|
|
1192
2339
|
|
|
1193
|
-
|
|
2340
|
+
|
|
2341
|
+
|
|
2342
|
+
exports.AptevaClient = AptevaClient; exports.Button = Button; exports.Card = Card; exports.Chat = Chat; exports.Command = Command; exports.List = List; exports.Prompt = Prompt; exports.Stream = Stream; exports.Threads = Threads; exports.Widgets = Widgets; exports.aptevaClient = aptevaClient; exports.cn = cn; exports.getThemeScript = getThemeScript; exports.mockMessages = mockMessages; exports.mockThreads = mockThreads; exports.mockWidgets = mockWidgets;
|
|
1194
2343
|
//# sourceMappingURL=index.js.map
|