@apteva/apteva-kit 0.1.9 → 0.1.11
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 +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +437 -113
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +592 -268
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -564,10 +564,148 @@ function Widgets({
|
|
|
564
564
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: cn(layoutClasses[layout], spacingClasses[spacing], className), children: widgets.map((widget) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, WidgetRenderer, { widget, onAction }, widget.id)) });
|
|
565
565
|
}
|
|
566
566
|
|
|
567
|
+
// src/components/Chat/MarkdownContent.tsx
|
|
568
|
+
|
|
569
|
+
function parseInlineMarkdown(text, keyPrefix = "") {
|
|
570
|
+
const result = [];
|
|
571
|
+
const boldRegex = /(\*\*|__)(.+?)\1/g;
|
|
572
|
+
let lastIndex = 0;
|
|
573
|
+
let match;
|
|
574
|
+
let key = 0;
|
|
575
|
+
while ((match = boldRegex.exec(text)) !== null) {
|
|
576
|
+
if (match.index > lastIndex) {
|
|
577
|
+
result.push(text.slice(lastIndex, match.index));
|
|
578
|
+
}
|
|
579
|
+
result.push(/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "strong", { children: match[2] }, `${keyPrefix}b${key++}`));
|
|
580
|
+
lastIndex = match.index + match[0].length;
|
|
581
|
+
}
|
|
582
|
+
if (lastIndex < text.length) {
|
|
583
|
+
result.push(text.slice(lastIndex));
|
|
584
|
+
}
|
|
585
|
+
return result.length > 0 ? result : [text];
|
|
586
|
+
}
|
|
587
|
+
function parseMarkdown(content) {
|
|
588
|
+
const lines = content.split("\n");
|
|
589
|
+
const result = [];
|
|
590
|
+
let key = 0;
|
|
591
|
+
let i = 0;
|
|
592
|
+
while (i < lines.length) {
|
|
593
|
+
const line = lines[i];
|
|
594
|
+
const h2Match = line.match(/^##\s+(.*)$/);
|
|
595
|
+
if (h2Match) {
|
|
596
|
+
result.push(
|
|
597
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { className: "apteva-md-h2", children: parseInlineMarkdown(h2Match[1], `${key}`) }, `h2${key++}`)
|
|
598
|
+
);
|
|
599
|
+
i++;
|
|
600
|
+
continue;
|
|
601
|
+
}
|
|
602
|
+
const h3Match = line.match(/^###\s+(.*)$/);
|
|
603
|
+
if (h3Match) {
|
|
604
|
+
result.push(
|
|
605
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { className: "apteva-md-h3", children: parseInlineMarkdown(h3Match[1], `${key}`) }, `h3${key++}`)
|
|
606
|
+
);
|
|
607
|
+
i++;
|
|
608
|
+
continue;
|
|
609
|
+
}
|
|
610
|
+
const ulMatch = line.match(/^(\s*)([-*+])\s+(.*)$/);
|
|
611
|
+
if (ulMatch) {
|
|
612
|
+
const listItems = [];
|
|
613
|
+
const indent = ulMatch[1].length;
|
|
614
|
+
while (i < lines.length) {
|
|
615
|
+
const itemMatch = lines[i].match(/^(\s*)([-*+])\s+(.*)$/);
|
|
616
|
+
if (itemMatch && itemMatch[1].length === indent) {
|
|
617
|
+
listItems.push(
|
|
618
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "li", { className: "apteva-md-li", children: parseInlineMarkdown(itemMatch[3], `${key}`) }, `li${key++}`)
|
|
619
|
+
);
|
|
620
|
+
i++;
|
|
621
|
+
} else {
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
result.push(
|
|
626
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "ul", { className: "apteva-md-ul", children: listItems }, `ul${key++}`)
|
|
627
|
+
);
|
|
628
|
+
continue;
|
|
629
|
+
}
|
|
630
|
+
const olMatch = line.match(/^(\s*)(\d+)\.\s+(.*)$/);
|
|
631
|
+
if (olMatch) {
|
|
632
|
+
const listItems = [];
|
|
633
|
+
const indent = olMatch[1].length;
|
|
634
|
+
while (i < lines.length) {
|
|
635
|
+
const itemMatch = lines[i].match(/^(\s*)(\d+)\.\s+(.*)$/);
|
|
636
|
+
if (itemMatch && itemMatch[1].length === indent) {
|
|
637
|
+
listItems.push(
|
|
638
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "li", { className: "apteva-md-li", children: parseInlineMarkdown(itemMatch[3], `${key}`) }, `li${key++}`)
|
|
639
|
+
);
|
|
640
|
+
i++;
|
|
641
|
+
} else {
|
|
642
|
+
break;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
result.push(
|
|
646
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "ol", { className: "apteva-md-ol", children: listItems }, `ol${key++}`)
|
|
647
|
+
);
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
if (line === "") {
|
|
651
|
+
result.push(/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "br", {}, `br${key++}`));
|
|
652
|
+
} else {
|
|
653
|
+
result.push(
|
|
654
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { children: [
|
|
655
|
+
parseInlineMarkdown(line, `${key}`),
|
|
656
|
+
i < lines.length - 1 ? "\n" : ""
|
|
657
|
+
] }, `p${key++}`)
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
i++;
|
|
661
|
+
}
|
|
662
|
+
return result;
|
|
663
|
+
}
|
|
664
|
+
function MarkdownContent({ content, className = "" }) {
|
|
665
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: `apteva-md ${className}`, children: parseMarkdown(content) });
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// src/components/Chat/ToolCall.tsx
|
|
669
|
+
|
|
670
|
+
function ToolCall({ name, status }) {
|
|
671
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center gap-2 py-2 px-3 my-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 text-sm", children: [
|
|
672
|
+
status === "running" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "w-2 h-2 rounded-full bg-blue-500 animate-pulse" }),
|
|
673
|
+
status === "completed" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "w-2 h-2 rounded-full bg-green-500" }),
|
|
674
|
+
status === "error" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "w-2 h-2 rounded-full bg-red-500" }),
|
|
675
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-gray-700 dark:text-gray-300 font-mono", children: name }),
|
|
676
|
+
status === "running" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-gray-500 dark:text-gray-400 ml-auto", children: "Running..." }),
|
|
677
|
+
status === "completed" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-green-600 dark:text-green-400 ml-auto", children: "Completed" }),
|
|
678
|
+
status === "error" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-red-600 dark:text-red-400 ml-auto", children: "Error" })
|
|
679
|
+
] });
|
|
680
|
+
}
|
|
681
|
+
|
|
567
682
|
// src/components/Chat/Message.tsx
|
|
568
683
|
|
|
569
684
|
function Message({ message, onAction }) {
|
|
570
685
|
const isUser = message.role === "user";
|
|
686
|
+
const contentSegments = _optionalChain([message, 'access', _8 => _8.metadata, 'optionalAccess', _9 => _9.content_segments]);
|
|
687
|
+
const renderContent = () => {
|
|
688
|
+
if (isUser) {
|
|
689
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "whitespace-pre-wrap !text-sm leading-relaxed", children: message.content });
|
|
690
|
+
}
|
|
691
|
+
if (contentSegments && contentSegments.length > 0) {
|
|
692
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: contentSegments.map((segment, index) => {
|
|
693
|
+
if (segment.type === "text") {
|
|
694
|
+
return segment.content ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MarkdownContent, { content: segment.content }, `text-${index}`) : null;
|
|
695
|
+
} else if (segment.type === "tool") {
|
|
696
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "my-2", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
697
|
+
ToolCall,
|
|
698
|
+
{
|
|
699
|
+
name: segment.name,
|
|
700
|
+
status: segment.result !== void 0 ? "completed" : "running"
|
|
701
|
+
}
|
|
702
|
+
) }, segment.id);
|
|
703
|
+
}
|
|
704
|
+
return null;
|
|
705
|
+
}) });
|
|
706
|
+
}
|
|
707
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, MarkdownContent, { content: message.content });
|
|
708
|
+
};
|
|
571
709
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
572
710
|
"div",
|
|
573
711
|
{
|
|
@@ -576,7 +714,7 @@ function Message({ message, onAction }) {
|
|
|
576
714
|
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
715
|
),
|
|
578
716
|
children: [
|
|
579
|
-
|
|
717
|
+
renderContent(),
|
|
580
718
|
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
719
|
/* @__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
720
|
]
|
|
@@ -593,7 +731,7 @@ function MessageList({ messages, onAction }) {
|
|
|
593
731
|
listRef.current.scrollTop = listRef.current.scrollHeight;
|
|
594
732
|
}
|
|
595
733
|
}, [messages]);
|
|
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: [
|
|
734
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { ref: listRef, className: "flex-1 overflow-y-auto px-4 py-4 space-y-3 apteva-scrollbar-hidden", 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: [
|
|
597
735
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-4xl", children: "\u{1F4AC}" }),
|
|
598
736
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { children: "No messages yet. Start a conversation!" })
|
|
599
737
|
] }) }) : messages.map((message) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Message, { message, onAction }, message.id)) });
|
|
@@ -629,7 +767,7 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
|
|
|
629
767
|
};
|
|
630
768
|
const handleFileSelect = (e) => {
|
|
631
769
|
if (e.target.files && e.target.files.length > 0) {
|
|
632
|
-
_optionalChain([onFileUpload, 'optionalCall',
|
|
770
|
+
_optionalChain([onFileUpload, 'optionalCall', _10 => _10(e.target.files)]);
|
|
633
771
|
setShowMenu(false);
|
|
634
772
|
}
|
|
635
773
|
};
|
|
@@ -639,7 +777,7 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
|
|
|
639
777
|
/* @__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
778
|
"button",
|
|
641
779
|
{
|
|
642
|
-
onClick: () => _optionalChain([fileInputRef, 'access',
|
|
780
|
+
onClick: () => _optionalChain([fileInputRef, 'access', _11 => _11.current, 'optionalAccess', _12 => _12.click, 'call', _13 => _13()]),
|
|
643
781
|
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
782
|
children: [
|
|
645
783
|
/* @__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)" }) }),
|
|
@@ -697,66 +835,6 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
|
|
|
697
835
|
] });
|
|
698
836
|
}
|
|
699
837
|
|
|
700
|
-
// src/components/Chat/Chat.tsx
|
|
701
|
-
|
|
702
|
-
function Chat({
|
|
703
|
-
agentId,
|
|
704
|
-
threadId,
|
|
705
|
-
initialMessages = [],
|
|
706
|
-
context,
|
|
707
|
-
onThreadChange,
|
|
708
|
-
onMessageSent,
|
|
709
|
-
onAction,
|
|
710
|
-
onFileUpload,
|
|
711
|
-
placeholder = "Type a message...",
|
|
712
|
-
showHeader = true,
|
|
713
|
-
headerTitle = "Chat",
|
|
714
|
-
className
|
|
715
|
-
}) {
|
|
716
|
-
const [messages, setMessages] = _react.useState.call(void 0, initialMessages.length > 0 ? initialMessages : mockMessages);
|
|
717
|
-
const [isLoading, setIsLoading] = _react.useState.call(void 0, false);
|
|
718
|
-
_react.useEffect.call(void 0, () => {
|
|
719
|
-
if (threadId) {
|
|
720
|
-
console.log("Loading thread:", threadId);
|
|
721
|
-
_optionalChain([onThreadChange, 'optionalCall', _12 => _12(threadId)]);
|
|
722
|
-
}
|
|
723
|
-
}, [threadId, onThreadChange]);
|
|
724
|
-
const handleSendMessage = async (text) => {
|
|
725
|
-
const userMessage = {
|
|
726
|
-
id: `msg-${Date.now()}`,
|
|
727
|
-
role: "user",
|
|
728
|
-
content: text,
|
|
729
|
-
timestamp: /* @__PURE__ */ new Date()
|
|
730
|
-
};
|
|
731
|
-
setMessages((prev) => [...prev, userMessage]);
|
|
732
|
-
_optionalChain([onMessageSent, 'optionalCall', _13 => _13(userMessage)]);
|
|
733
|
-
setIsLoading(true);
|
|
734
|
-
try {
|
|
735
|
-
const response = await generateMockResponse(1e3);
|
|
736
|
-
setMessages((prev) => [...prev, response]);
|
|
737
|
-
} catch (error) {
|
|
738
|
-
console.error("Error generating response:", error);
|
|
739
|
-
} finally {
|
|
740
|
-
setIsLoading(false);
|
|
741
|
-
}
|
|
742
|
-
};
|
|
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: [
|
|
747
|
-
"Agent: ",
|
|
748
|
-
agentId
|
|
749
|
-
] })
|
|
750
|
-
] }),
|
|
751
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, MessageList, { messages, onAction }),
|
|
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 })
|
|
754
|
-
] });
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
// src/components/Command/Command.tsx
|
|
758
|
-
|
|
759
|
-
|
|
760
838
|
// src/lib/apteva-client.ts
|
|
761
839
|
var DEFAULT_API_URL = "http://localhost:3000/agents";
|
|
762
840
|
var DEFAULT_API_KEY = "agt_894abd5966bc9f1e9f8f17f2a6f6b5e0";
|
|
@@ -868,15 +946,9 @@ var AptevaClient = class {
|
|
|
868
946
|
if (chunk.thread_id) {
|
|
869
947
|
threadId = chunk.thread_id;
|
|
870
948
|
}
|
|
871
|
-
|
|
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
|
-
}
|
|
949
|
+
onChunk(chunk);
|
|
878
950
|
} catch (e) {
|
|
879
|
-
console.warn("Failed to parse SSE data:", data);
|
|
951
|
+
console.warn("[AptevaClient] Failed to parse SSE data:", data);
|
|
880
952
|
}
|
|
881
953
|
}
|
|
882
954
|
}
|
|
@@ -927,8 +999,260 @@ var AptevaClient = class {
|
|
|
927
999
|
};
|
|
928
1000
|
var aptevaClient = new AptevaClient();
|
|
929
1001
|
|
|
1002
|
+
// src/components/Chat/Chat.tsx
|
|
1003
|
+
|
|
1004
|
+
function Chat({
|
|
1005
|
+
agentId,
|
|
1006
|
+
threadId,
|
|
1007
|
+
initialMessages = [],
|
|
1008
|
+
context,
|
|
1009
|
+
apiUrl,
|
|
1010
|
+
apiKey,
|
|
1011
|
+
useMock = false,
|
|
1012
|
+
onThreadChange,
|
|
1013
|
+
onMessageSent,
|
|
1014
|
+
onAction,
|
|
1015
|
+
onFileUpload,
|
|
1016
|
+
placeholder = "Type a message...",
|
|
1017
|
+
showHeader = true,
|
|
1018
|
+
headerTitle = "Chat",
|
|
1019
|
+
className
|
|
1020
|
+
}) {
|
|
1021
|
+
const [messages, setMessages] = _react.useState.call(void 0, initialMessages);
|
|
1022
|
+
const [isLoading, setIsLoading] = _react.useState.call(void 0, false);
|
|
1023
|
+
const [currentThreadId, setCurrentThreadId] = _react.useState.call(void 0, threadId || null);
|
|
1024
|
+
_react.useEffect.call(void 0, () => {
|
|
1025
|
+
if (apiUrl || apiKey) {
|
|
1026
|
+
aptevaClient.configure({
|
|
1027
|
+
...apiUrl && { apiUrl },
|
|
1028
|
+
...apiKey && { apiKey }
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
}, [apiUrl, apiKey]);
|
|
1032
|
+
_react.useEffect.call(void 0, () => {
|
|
1033
|
+
if (threadId) {
|
|
1034
|
+
console.log("Loading thread:", threadId);
|
|
1035
|
+
_optionalChain([onThreadChange, 'optionalCall', _20 => _20(threadId)]);
|
|
1036
|
+
}
|
|
1037
|
+
}, [threadId, onThreadChange]);
|
|
1038
|
+
const handleSendMessage = async (text) => {
|
|
1039
|
+
const userMessage = {
|
|
1040
|
+
id: `msg-${Date.now()}`,
|
|
1041
|
+
role: "user",
|
|
1042
|
+
content: text,
|
|
1043
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
1044
|
+
};
|
|
1045
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
1046
|
+
_optionalChain([onMessageSent, 'optionalCall', _21 => _21(userMessage)]);
|
|
1047
|
+
setIsLoading(true);
|
|
1048
|
+
try {
|
|
1049
|
+
if (useMock) {
|
|
1050
|
+
const response = await generateMockResponse(1e3);
|
|
1051
|
+
setMessages((prev) => [...prev, response]);
|
|
1052
|
+
} else {
|
|
1053
|
+
let contentSegments = [];
|
|
1054
|
+
let currentTextBuffer = "";
|
|
1055
|
+
let accumulatedWidgets = [];
|
|
1056
|
+
let responseThreadId = currentThreadId;
|
|
1057
|
+
let toolInputBuffer = "";
|
|
1058
|
+
const updateMessage = () => {
|
|
1059
|
+
const segments = [...contentSegments];
|
|
1060
|
+
if (currentTextBuffer) {
|
|
1061
|
+
const lastSegment = segments[segments.length - 1];
|
|
1062
|
+
if (lastSegment && lastSegment.type === "text") {
|
|
1063
|
+
lastSegment.content = currentTextBuffer;
|
|
1064
|
+
} else {
|
|
1065
|
+
segments.push({ type: "text", content: currentTextBuffer });
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
setMessages((prev) => {
|
|
1069
|
+
const lastMessage = prev[prev.length - 1];
|
|
1070
|
+
if (lastMessage && lastMessage.role === "assistant") {
|
|
1071
|
+
return [
|
|
1072
|
+
...prev.slice(0, -1),
|
|
1073
|
+
{
|
|
1074
|
+
...lastMessage,
|
|
1075
|
+
content: currentTextBuffer,
|
|
1076
|
+
widgets: accumulatedWidgets.length > 0 ? accumulatedWidgets : void 0,
|
|
1077
|
+
metadata: {
|
|
1078
|
+
...lastMessage.metadata,
|
|
1079
|
+
content_segments: segments
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
];
|
|
1083
|
+
} else {
|
|
1084
|
+
return [
|
|
1085
|
+
...prev,
|
|
1086
|
+
{
|
|
1087
|
+
id: `msg-${Date.now()}-streaming`,
|
|
1088
|
+
role: "assistant",
|
|
1089
|
+
content: currentTextBuffer,
|
|
1090
|
+
widgets: accumulatedWidgets.length > 0 ? accumulatedWidgets : void 0,
|
|
1091
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
1092
|
+
metadata: {
|
|
1093
|
+
content_segments: segments
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
];
|
|
1097
|
+
}
|
|
1098
|
+
});
|
|
1099
|
+
};
|
|
1100
|
+
await aptevaClient.chatStream(
|
|
1101
|
+
{
|
|
1102
|
+
agent_id: agentId,
|
|
1103
|
+
message: text,
|
|
1104
|
+
stream: true,
|
|
1105
|
+
...currentThreadId && { thread_id: currentThreadId },
|
|
1106
|
+
...context && { system: context }
|
|
1107
|
+
},
|
|
1108
|
+
(chunk) => {
|
|
1109
|
+
switch (chunk.type) {
|
|
1110
|
+
case "start":
|
|
1111
|
+
break;
|
|
1112
|
+
case "thread_id":
|
|
1113
|
+
if (chunk.thread_id) {
|
|
1114
|
+
responseThreadId = chunk.thread_id;
|
|
1115
|
+
if (!currentThreadId) {
|
|
1116
|
+
setCurrentThreadId(chunk.thread_id);
|
|
1117
|
+
_optionalChain([onThreadChange, 'optionalCall', _22 => _22(chunk.thread_id)]);
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
break;
|
|
1121
|
+
case "content":
|
|
1122
|
+
case "token":
|
|
1123
|
+
if (chunk.content) {
|
|
1124
|
+
currentTextBuffer += chunk.content;
|
|
1125
|
+
updateMessage();
|
|
1126
|
+
}
|
|
1127
|
+
break;
|
|
1128
|
+
case "tool_call":
|
|
1129
|
+
if (chunk.tool_id && chunk.tool_name) {
|
|
1130
|
+
if (currentTextBuffer) {
|
|
1131
|
+
contentSegments.push({ type: "text", content: currentTextBuffer });
|
|
1132
|
+
currentTextBuffer = "";
|
|
1133
|
+
}
|
|
1134
|
+
contentSegments.push({
|
|
1135
|
+
type: "tool",
|
|
1136
|
+
id: chunk.tool_id,
|
|
1137
|
+
name: chunk.tool_name
|
|
1138
|
+
});
|
|
1139
|
+
toolInputBuffer = "";
|
|
1140
|
+
updateMessage();
|
|
1141
|
+
}
|
|
1142
|
+
break;
|
|
1143
|
+
case "tool_input_delta":
|
|
1144
|
+
if (chunk.tool_id && chunk.content) {
|
|
1145
|
+
toolInputBuffer += chunk.content;
|
|
1146
|
+
}
|
|
1147
|
+
break;
|
|
1148
|
+
case "tool_use":
|
|
1149
|
+
toolInputBuffer = "";
|
|
1150
|
+
break;
|
|
1151
|
+
case "tool_result":
|
|
1152
|
+
if (chunk.tool_id) {
|
|
1153
|
+
const toolSegment = contentSegments.find(
|
|
1154
|
+
(s) => s.type === "tool" && s.id === chunk.tool_id
|
|
1155
|
+
);
|
|
1156
|
+
if (toolSegment) {
|
|
1157
|
+
toolSegment.result = chunk.content;
|
|
1158
|
+
}
|
|
1159
|
+
updateMessage();
|
|
1160
|
+
}
|
|
1161
|
+
break;
|
|
1162
|
+
case "widget":
|
|
1163
|
+
if (chunk.widget) {
|
|
1164
|
+
accumulatedWidgets.push(chunk.widget);
|
|
1165
|
+
updateMessage();
|
|
1166
|
+
}
|
|
1167
|
+
break;
|
|
1168
|
+
case "stop":
|
|
1169
|
+
break;
|
|
1170
|
+
case "complete":
|
|
1171
|
+
break;
|
|
1172
|
+
case "error":
|
|
1173
|
+
throw new Error(chunk.message || "Stream error");
|
|
1174
|
+
default:
|
|
1175
|
+
break;
|
|
1176
|
+
}
|
|
1177
|
+
},
|
|
1178
|
+
(threadId2) => {
|
|
1179
|
+
if (currentTextBuffer) {
|
|
1180
|
+
const lastSegment = contentSegments[contentSegments.length - 1];
|
|
1181
|
+
if (lastSegment && lastSegment.type === "text") {
|
|
1182
|
+
lastSegment.content = currentTextBuffer;
|
|
1183
|
+
} else {
|
|
1184
|
+
contentSegments.push({ type: "text", content: currentTextBuffer });
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
setMessages((prev) => {
|
|
1188
|
+
const lastMessage = prev[prev.length - 1];
|
|
1189
|
+
if (lastMessage && lastMessage.role === "assistant") {
|
|
1190
|
+
return [
|
|
1191
|
+
...prev.slice(0, -1),
|
|
1192
|
+
{
|
|
1193
|
+
...lastMessage,
|
|
1194
|
+
id: `msg-${Date.now()}`,
|
|
1195
|
+
content: currentTextBuffer || "Response received",
|
|
1196
|
+
widgets: accumulatedWidgets.length > 0 ? accumulatedWidgets : void 0,
|
|
1197
|
+
metadata: {
|
|
1198
|
+
thread_id: threadId2,
|
|
1199
|
+
content_segments: contentSegments
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
];
|
|
1203
|
+
}
|
|
1204
|
+
return prev;
|
|
1205
|
+
});
|
|
1206
|
+
if (threadId2 && threadId2 !== currentThreadId) {
|
|
1207
|
+
setCurrentThreadId(threadId2);
|
|
1208
|
+
_optionalChain([onThreadChange, 'optionalCall', _23 => _23(threadId2)]);
|
|
1209
|
+
}
|
|
1210
|
+
setIsLoading(false);
|
|
1211
|
+
},
|
|
1212
|
+
(error) => {
|
|
1213
|
+
const errorMessage = {
|
|
1214
|
+
id: `msg-${Date.now()}-error`,
|
|
1215
|
+
role: "assistant",
|
|
1216
|
+
content: `Error: ${error.message}`,
|
|
1217
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
1218
|
+
metadata: { error: true }
|
|
1219
|
+
};
|
|
1220
|
+
setMessages((prev) => {
|
|
1221
|
+
const lastMessage = prev[prev.length - 1];
|
|
1222
|
+
if (lastMessage && lastMessage.id.includes("streaming")) {
|
|
1223
|
+
return [...prev.slice(0, -1), errorMessage];
|
|
1224
|
+
}
|
|
1225
|
+
return [...prev, errorMessage];
|
|
1226
|
+
});
|
|
1227
|
+
setIsLoading(false);
|
|
1228
|
+
}
|
|
1229
|
+
);
|
|
1230
|
+
}
|
|
1231
|
+
} catch (error) {
|
|
1232
|
+
console.error("Chat error:", error);
|
|
1233
|
+
const errorMessage = {
|
|
1234
|
+
id: `msg-${Date.now()}-error`,
|
|
1235
|
+
role: "assistant",
|
|
1236
|
+
content: error instanceof Error ? `Error: ${error.message}` : "An error occurred",
|
|
1237
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
1238
|
+
metadata: { error: true }
|
|
1239
|
+
};
|
|
1240
|
+
setMessages((prev) => [...prev, errorMessage]);
|
|
1241
|
+
} finally {
|
|
1242
|
+
setIsLoading(false);
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: cn("flex flex-col h-full bg-white dark:bg-gray-900", className), children: [
|
|
1246
|
+
showHeader && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "px-4 py-3 bg-white dark:bg-gray-900", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { className: "!text-lg font-semibold !text-gray-900 dark:!text-white", children: headerTitle }) }),
|
|
1247
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, MessageList, { messages, onAction }),
|
|
1248
|
+
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..." }),
|
|
1249
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, Composer, { onSendMessage: handleSendMessage, placeholder, disabled: isLoading, onFileUpload })
|
|
1250
|
+
] });
|
|
1251
|
+
}
|
|
1252
|
+
|
|
930
1253
|
// src/components/Command/Command.tsx
|
|
931
1254
|
|
|
1255
|
+
|
|
932
1256
|
function Command({
|
|
933
1257
|
agentId,
|
|
934
1258
|
command: initialCommand,
|
|
@@ -1061,13 +1385,13 @@ ${planningInstruction}` : planningInstruction;
|
|
|
1061
1385
|
const error2 = err instanceof Error ? err : new Error("Failed to generate plan");
|
|
1062
1386
|
setError(error2);
|
|
1063
1387
|
setState("error");
|
|
1064
|
-
_optionalChain([onError, 'optionalCall',
|
|
1388
|
+
_optionalChain([onError, 'optionalCall', _24 => _24(error2)]);
|
|
1065
1389
|
});
|
|
1066
1390
|
} catch (err) {
|
|
1067
1391
|
const error2 = err instanceof Error ? err : new Error("Failed to generate plan");
|
|
1068
1392
|
setError(error2);
|
|
1069
1393
|
setState("error");
|
|
1070
|
-
_optionalChain([onError, 'optionalCall',
|
|
1394
|
+
_optionalChain([onError, 'optionalCall', _25 => _25(error2)]);
|
|
1071
1395
|
}
|
|
1072
1396
|
}
|
|
1073
1397
|
return;
|
|
@@ -1078,7 +1402,7 @@ ${planningInstruction}` : planningInstruction;
|
|
|
1078
1402
|
setStreamedContent("");
|
|
1079
1403
|
setCommand("");
|
|
1080
1404
|
setUploadedFiles([]);
|
|
1081
|
-
_optionalChain([onStart, 'optionalCall',
|
|
1405
|
+
_optionalChain([onStart, 'optionalCall', _26 => _26()]);
|
|
1082
1406
|
try {
|
|
1083
1407
|
if (useMock) {
|
|
1084
1408
|
if (enableStreaming) {
|
|
@@ -1089,16 +1413,16 @@ ${planningInstruction}` : planningInstruction;
|
|
|
1089
1413
|
if (chunk.type === "token" && chunk.content) {
|
|
1090
1414
|
accumulatedContent += chunk.content;
|
|
1091
1415
|
setStreamedContent(accumulatedContent);
|
|
1092
|
-
_optionalChain([onChunk, 'optionalCall',
|
|
1416
|
+
_optionalChain([onChunk, 'optionalCall', _27 => _27(chunk.content)]);
|
|
1093
1417
|
const estimatedProgress = Math.min(Math.round(accumulatedContent.length / 10), 90);
|
|
1094
1418
|
setProgress(estimatedProgress);
|
|
1095
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
1419
|
+
_optionalChain([onProgress, 'optionalCall', _28 => _28(estimatedProgress)]);
|
|
1096
1420
|
} else if (chunk.type === "widget" && chunk.widget) {
|
|
1097
1421
|
const widget = chunk.widget;
|
|
1098
1422
|
setResult((prev) => ({
|
|
1099
1423
|
success: true,
|
|
1100
|
-
data: _optionalChain([prev, 'optionalAccess',
|
|
1101
|
-
widgets: [..._optionalChain([prev, 'optionalAccess',
|
|
1424
|
+
data: _optionalChain([prev, 'optionalAccess', _29 => _29.data]) || {},
|
|
1425
|
+
widgets: [..._optionalChain([prev, 'optionalAccess', _30 => _30.widgets]) || [], widget],
|
|
1102
1426
|
message: accumulatedContent || "Command executed successfully"
|
|
1103
1427
|
}));
|
|
1104
1428
|
}
|
|
@@ -1118,19 +1442,19 @@ ${planningInstruction}` : planningInstruction;
|
|
|
1118
1442
|
setResult(result2);
|
|
1119
1443
|
setState("success");
|
|
1120
1444
|
setProgress(100);
|
|
1121
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
1445
|
+
_optionalChain([onComplete, 'optionalCall', _31 => _31(result2)]);
|
|
1122
1446
|
},
|
|
1123
1447
|
(error2) => {
|
|
1124
1448
|
setError(error2);
|
|
1125
1449
|
setState("error");
|
|
1126
|
-
_optionalChain([onError, 'optionalCall',
|
|
1450
|
+
_optionalChain([onError, 'optionalCall', _32 => _32(error2)]);
|
|
1127
1451
|
}
|
|
1128
1452
|
);
|
|
1129
1453
|
} else {
|
|
1130
1454
|
const progressInterval = setInterval(() => {
|
|
1131
1455
|
setProgress((prev) => {
|
|
1132
1456
|
const next = Math.min(prev + 10, 90);
|
|
1133
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
1457
|
+
_optionalChain([onProgress, 'optionalCall', _33 => _33(next)]);
|
|
1134
1458
|
return next;
|
|
1135
1459
|
});
|
|
1136
1460
|
}, 200);
|
|
@@ -1154,7 +1478,7 @@ ${planningInstruction}` : planningInstruction;
|
|
|
1154
1478
|
setResult(result2);
|
|
1155
1479
|
setState("success");
|
|
1156
1480
|
setProgress(100);
|
|
1157
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
1481
|
+
_optionalChain([onComplete, 'optionalCall', _34 => _34(result2)]);
|
|
1158
1482
|
}
|
|
1159
1483
|
} else {
|
|
1160
1484
|
if (enableStreaming) {
|
|
@@ -1200,16 +1524,16 @@ ${commandInstruction}` : commandInstruction;
|
|
|
1200
1524
|
if (chunk.type === "token" && chunk.content) {
|
|
1201
1525
|
accumulatedContent += chunk.content;
|
|
1202
1526
|
setStreamedContent(accumulatedContent);
|
|
1203
|
-
_optionalChain([onChunk, 'optionalCall',
|
|
1527
|
+
_optionalChain([onChunk, 'optionalCall', _35 => _35(chunk.content)]);
|
|
1204
1528
|
const estimatedProgress = Math.min(Math.round(accumulatedContent.length / 10), 90);
|
|
1205
1529
|
setProgress(estimatedProgress);
|
|
1206
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
1530
|
+
_optionalChain([onProgress, 'optionalCall', _36 => _36(estimatedProgress)]);
|
|
1207
1531
|
} else if (chunk.type === "widget" && chunk.widget) {
|
|
1208
1532
|
const widget = chunk.widget;
|
|
1209
1533
|
setResult((prev) => ({
|
|
1210
1534
|
success: true,
|
|
1211
|
-
data: _optionalChain([prev, 'optionalAccess',
|
|
1212
|
-
widgets: [..._optionalChain([prev, 'optionalAccess',
|
|
1535
|
+
data: _optionalChain([prev, 'optionalAccess', _37 => _37.data]) || {},
|
|
1536
|
+
widgets: [..._optionalChain([prev, 'optionalAccess', _38 => _38.widgets]) || [], widget],
|
|
1213
1537
|
message: accumulatedContent || "Command executed successfully"
|
|
1214
1538
|
}));
|
|
1215
1539
|
}
|
|
@@ -1229,20 +1553,20 @@ ${commandInstruction}` : commandInstruction;
|
|
|
1229
1553
|
setResult(result2);
|
|
1230
1554
|
setState("success");
|
|
1231
1555
|
setProgress(100);
|
|
1232
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
1556
|
+
_optionalChain([onComplete, 'optionalCall', _39 => _39(result2)]);
|
|
1233
1557
|
},
|
|
1234
1558
|
(error2) => {
|
|
1235
1559
|
const err = error2 instanceof Error ? error2 : new Error("Unknown error");
|
|
1236
1560
|
setError(err);
|
|
1237
1561
|
setState("error");
|
|
1238
|
-
_optionalChain([onError, 'optionalCall',
|
|
1562
|
+
_optionalChain([onError, 'optionalCall', _40 => _40(err)]);
|
|
1239
1563
|
}
|
|
1240
1564
|
);
|
|
1241
1565
|
} else {
|
|
1242
1566
|
const progressInterval = setInterval(() => {
|
|
1243
1567
|
setProgress((prev) => {
|
|
1244
1568
|
const next = Math.min(prev + 10, 90);
|
|
1245
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
1569
|
+
_optionalChain([onProgress, 'optionalCall', _41 => _41(next)]);
|
|
1246
1570
|
return next;
|
|
1247
1571
|
});
|
|
1248
1572
|
}, 200);
|
|
@@ -1298,14 +1622,14 @@ ${commandInstruction}` : commandInstruction;
|
|
|
1298
1622
|
setResult(result2);
|
|
1299
1623
|
setState("success");
|
|
1300
1624
|
setProgress(100);
|
|
1301
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
1625
|
+
_optionalChain([onComplete, 'optionalCall', _42 => _42(result2)]);
|
|
1302
1626
|
}
|
|
1303
1627
|
}
|
|
1304
1628
|
} catch (err) {
|
|
1305
1629
|
const error2 = err instanceof Error ? err : new Error("Unknown error");
|
|
1306
1630
|
setError(error2);
|
|
1307
1631
|
setState("error");
|
|
1308
|
-
_optionalChain([onError, 'optionalCall',
|
|
1632
|
+
_optionalChain([onError, 'optionalCall', _43 => _43(error2)]);
|
|
1309
1633
|
}
|
|
1310
1634
|
};
|
|
1311
1635
|
const resetCommand = () => {
|
|
@@ -1338,14 +1662,14 @@ ${planToExecute}`;
|
|
|
1338
1662
|
};
|
|
1339
1663
|
const handleFileSelect = async (e) => {
|
|
1340
1664
|
if (e.target.files && e.target.files.length > 0) {
|
|
1341
|
-
_optionalChain([onFileUpload, 'optionalCall',
|
|
1665
|
+
_optionalChain([onFileUpload, 'optionalCall', _44 => _44(e.target.files)]);
|
|
1342
1666
|
const files = [];
|
|
1343
1667
|
for (let i = 0; i < e.target.files.length; i++) {
|
|
1344
1668
|
const file = e.target.files[i];
|
|
1345
1669
|
const reader = new FileReader();
|
|
1346
1670
|
await new Promise((resolve) => {
|
|
1347
1671
|
reader.onload = (event) => {
|
|
1348
|
-
if (_optionalChain([event, 'access',
|
|
1672
|
+
if (_optionalChain([event, 'access', _45 => _45.target, 'optionalAccess', _46 => _46.result])) {
|
|
1349
1673
|
const fullDataUrl = event.target.result;
|
|
1350
1674
|
const base64Data = fullDataUrl.split(",")[1];
|
|
1351
1675
|
if (file.type.startsWith("image/")) {
|
|
@@ -1439,7 +1763,7 @@ ${planToExecute}`;
|
|
|
1439
1763
|
enableFileUpload && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1440
1764
|
"button",
|
|
1441
1765
|
{
|
|
1442
|
-
onClick: () => _optionalChain([fileInputRef, 'access',
|
|
1766
|
+
onClick: () => _optionalChain([fileInputRef, 'access', _47 => _47.current, 'optionalAccess', _48 => _48.click, 'call', _49 => _49()]),
|
|
1443
1767
|
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
1768
|
title: "Attach file",
|
|
1445
1769
|
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)" }) })
|
|
@@ -1658,7 +1982,7 @@ ${planToExecute}`;
|
|
|
1658
1982
|
/* @__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" }) }),
|
|
1659
1983
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
|
|
1660
1984
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { className: "text-sm font-semibold text-red-800 dark:text-red-400", children: "Error" }),
|
|
1661
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-red-700 dark:text-red-300 text-sm mt-1", children: _optionalChain([error, 'optionalAccess',
|
|
1985
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-red-700 dark:text-red-300 text-sm mt-1", children: _optionalChain([error, 'optionalAccess', _50 => _50.message]) })
|
|
1662
1986
|
] })
|
|
1663
1987
|
] }) }),
|
|
1664
1988
|
allowInput && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
@@ -1686,7 +2010,7 @@ ${planToExecute}`;
|
|
|
1686
2010
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-green-700 dark:text-green-300 text-sm", children: "Command executed successfully" })
|
|
1687
2011
|
] })
|
|
1688
2012
|
] }),
|
|
1689
|
-
_optionalChain([result, 'access',
|
|
2013
|
+
_optionalChain([result, 'access', _51 => _51.data, 'optionalAccess', _52 => _52.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
2014
|
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
2015
|
WidgetRenderer,
|
|
1692
2016
|
{
|
|
@@ -1737,7 +2061,7 @@ ${planToExecute}`;
|
|
|
1737
2061
|
enableFileUpload && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1738
2062
|
"button",
|
|
1739
2063
|
{
|
|
1740
|
-
onClick: () => _optionalChain([fileInputRef, 'access',
|
|
2064
|
+
onClick: () => _optionalChain([fileInputRef, 'access', _53 => _53.current, 'optionalAccess', _54 => _54.click, 'call', _55 => _55()]),
|
|
1741
2065
|
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
2066
|
title: "Attach file",
|
|
1743
2067
|
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)" }) })
|
|
@@ -1923,25 +2247,25 @@ function Prompt({
|
|
|
1923
2247
|
const newValue = e.target.value;
|
|
1924
2248
|
if (!maxLength || newValue.length <= maxLength) {
|
|
1925
2249
|
setValue(newValue);
|
|
1926
|
-
_optionalChain([onChange, 'optionalCall',
|
|
2250
|
+
_optionalChain([onChange, 'optionalCall', _56 => _56(newValue)]);
|
|
1927
2251
|
}
|
|
1928
2252
|
};
|
|
1929
2253
|
const handleSubmit = async () => {
|
|
1930
2254
|
if (value.length < minLength) return;
|
|
1931
|
-
_optionalChain([onSubmit, 'optionalCall',
|
|
2255
|
+
_optionalChain([onSubmit, 'optionalCall', _57 => _57(value)]);
|
|
1932
2256
|
setIsLoading(true);
|
|
1933
2257
|
try {
|
|
1934
2258
|
if (useMock) {
|
|
1935
2259
|
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
1936
2260
|
const mockResult = `Enhanced version: ${value} [AI-generated content]`;
|
|
1937
|
-
_optionalChain([onResult, 'optionalCall',
|
|
2261
|
+
_optionalChain([onResult, 'optionalCall', _58 => _58(mockResult)]);
|
|
1938
2262
|
setValue("");
|
|
1939
2263
|
} else {
|
|
1940
2264
|
const response = await aptevaClient.chat({
|
|
1941
2265
|
agent_id: agentId,
|
|
1942
2266
|
message: value
|
|
1943
2267
|
});
|
|
1944
|
-
_optionalChain([onResult, 'optionalCall',
|
|
2268
|
+
_optionalChain([onResult, 'optionalCall', _59 => _59(response.message)]);
|
|
1945
2269
|
setValue("");
|
|
1946
2270
|
}
|
|
1947
2271
|
} catch (error) {
|
|
@@ -2036,7 +2360,7 @@ function Stream({
|
|
|
2036
2360
|
}, [autoStart]);
|
|
2037
2361
|
const startStreaming = async () => {
|
|
2038
2362
|
setIsStreaming(true);
|
|
2039
|
-
_optionalChain([onStart, 'optionalCall',
|
|
2363
|
+
_optionalChain([onStart, 'optionalCall', _60 => _60()]);
|
|
2040
2364
|
try {
|
|
2041
2365
|
if (useMock) {
|
|
2042
2366
|
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.";
|
|
@@ -2044,13 +2368,13 @@ function Stream({
|
|
|
2044
2368
|
mockText,
|
|
2045
2369
|
(chunk) => {
|
|
2046
2370
|
setText((prev) => prev + chunk);
|
|
2047
|
-
_optionalChain([onChunk, 'optionalCall',
|
|
2371
|
+
_optionalChain([onChunk, 'optionalCall', _61 => _61(chunk)]);
|
|
2048
2372
|
},
|
|
2049
2373
|
typingSpeed
|
|
2050
2374
|
);
|
|
2051
2375
|
setIsComplete(true);
|
|
2052
2376
|
setIsStreaming(false);
|
|
2053
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
2377
|
+
_optionalChain([onComplete, 'optionalCall', _62 => _62(text + mockText)]);
|
|
2054
2378
|
} else {
|
|
2055
2379
|
let accumulatedText = "";
|
|
2056
2380
|
await aptevaClient.chatStream(
|
|
@@ -2063,24 +2387,24 @@ function Stream({
|
|
|
2063
2387
|
if (chunk.type === "token" && chunk.content) {
|
|
2064
2388
|
accumulatedText += chunk.content;
|
|
2065
2389
|
setText(accumulatedText);
|
|
2066
|
-
_optionalChain([onChunk, 'optionalCall',
|
|
2390
|
+
_optionalChain([onChunk, 'optionalCall', _63 => _63(chunk.content)]);
|
|
2067
2391
|
}
|
|
2068
2392
|
},
|
|
2069
2393
|
() => {
|
|
2070
2394
|
setIsComplete(true);
|
|
2071
2395
|
setIsStreaming(false);
|
|
2072
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
2396
|
+
_optionalChain([onComplete, 'optionalCall', _64 => _64(accumulatedText)]);
|
|
2073
2397
|
},
|
|
2074
2398
|
(error) => {
|
|
2075
2399
|
const err = error instanceof Error ? error : new Error("Streaming error");
|
|
2076
|
-
_optionalChain([onError, 'optionalCall',
|
|
2400
|
+
_optionalChain([onError, 'optionalCall', _65 => _65(err)]);
|
|
2077
2401
|
setIsStreaming(false);
|
|
2078
2402
|
}
|
|
2079
2403
|
);
|
|
2080
2404
|
}
|
|
2081
2405
|
} catch (error) {
|
|
2082
2406
|
const err = error instanceof Error ? error : new Error("Streaming error");
|
|
2083
|
-
_optionalChain([onError, 'optionalCall',
|
|
2407
|
+
_optionalChain([onError, 'optionalCall', _66 => _66(err)]);
|
|
2084
2408
|
setIsStreaming(false);
|
|
2085
2409
|
}
|
|
2086
2410
|
};
|
|
@@ -2172,7 +2496,7 @@ function ThreadList({
|
|
|
2172
2496
|
}) {
|
|
2173
2497
|
const [searchQuery, setSearchQuery] = _react.useState.call(void 0, "");
|
|
2174
2498
|
const filteredThreads = threads.filter(
|
|
2175
|
-
(thread) => thread.title.toLowerCase().includes(searchQuery.toLowerCase()) || _optionalChain([thread, 'access',
|
|
2499
|
+
(thread) => thread.title.toLowerCase().includes(searchQuery.toLowerCase()) || _optionalChain([thread, 'access', _67 => _67.preview, 'optionalAccess', _68 => _68.toLowerCase, 'call', _69 => _69(), 'access', _70 => _70.includes, 'call', _71 => _71(searchQuery.toLowerCase())])
|
|
2176
2500
|
);
|
|
2177
2501
|
const groupedThreads = groupBy === "date" ? groupThreadsByDate(filteredThreads) : { All: filteredThreads };
|
|
2178
2502
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col h-full", children: [
|
|
@@ -2194,8 +2518,8 @@ function ThreadList({
|
|
|
2194
2518
|
{
|
|
2195
2519
|
thread,
|
|
2196
2520
|
isActive: thread.id === currentThreadId,
|
|
2197
|
-
onSelect: () => _optionalChain([onThreadSelect, 'optionalCall',
|
|
2198
|
-
onDelete: () => _optionalChain([onThreadDelete, 'optionalCall',
|
|
2521
|
+
onSelect: () => _optionalChain([onThreadSelect, 'optionalCall', _72 => _72(thread.id)]),
|
|
2522
|
+
onDelete: () => _optionalChain([onThreadDelete, 'optionalCall', _73 => _73(thread.id)])
|
|
2199
2523
|
},
|
|
2200
2524
|
thread.id
|
|
2201
2525
|
))
|
|
@@ -2257,7 +2581,7 @@ function Threads({
|
|
|
2257
2581
|
threads.slice(0, 5).map((thread) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
2258
2582
|
"button",
|
|
2259
2583
|
{
|
|
2260
|
-
onClick: () => _optionalChain([onThreadSelect, 'optionalCall',
|
|
2584
|
+
onClick: () => _optionalChain([onThreadSelect, 'optionalCall', _74 => _74(thread.id)]),
|
|
2261
2585
|
className: cn(
|
|
2262
2586
|
"px-4 py-2 whitespace-nowrap font-medium transition-colors",
|
|
2263
2587
|
thread.id === currentThreadId ? "border-b-2 border-apteva-500 text-apteva-500" : "text-gray-600 hover:text-gray-900"
|