@apteva/apteva-kit 0.1.101 → 0.1.104
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/LICENSE +38 -0
- package/README.md +18 -1
- package/dist/index.d.mts +258 -4
- package/dist/index.d.ts +258 -4
- package/dist/index.js +1158 -154
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1507 -503
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +6 -2
package/dist/index.js
CHANGED
|
@@ -797,6 +797,347 @@ Widgets: @ui:type[{json}] - MUST use square brackets []. Example: @ui:list[{"ite
|
|
|
797
797
|
`;
|
|
798
798
|
}
|
|
799
799
|
|
|
800
|
+
// src/utils/interface-parser.ts
|
|
801
|
+
function findMatchingBracket2(text, startIndex) {
|
|
802
|
+
const openChar = text[startIndex];
|
|
803
|
+
const closeChar = openChar === "[" ? "]" : "}";
|
|
804
|
+
let depth = 0;
|
|
805
|
+
let inString = false;
|
|
806
|
+
let escapeNext = false;
|
|
807
|
+
for (let i = startIndex; i < text.length; i++) {
|
|
808
|
+
const char = text[i];
|
|
809
|
+
if (escapeNext) {
|
|
810
|
+
escapeNext = false;
|
|
811
|
+
continue;
|
|
812
|
+
}
|
|
813
|
+
if (char === "\\" && inString) {
|
|
814
|
+
escapeNext = true;
|
|
815
|
+
continue;
|
|
816
|
+
}
|
|
817
|
+
if (char === '"') {
|
|
818
|
+
inString = !inString;
|
|
819
|
+
continue;
|
|
820
|
+
}
|
|
821
|
+
if (inString) continue;
|
|
822
|
+
if (char === openChar || char === (openChar === "[" ? "{" : "[")) {
|
|
823
|
+
if (char === openChar) depth++;
|
|
824
|
+
} else if (char === closeChar || char === (closeChar === "]" ? "}" : "]")) {
|
|
825
|
+
if (char === closeChar) {
|
|
826
|
+
depth--;
|
|
827
|
+
if (depth === 0) return i;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return -1;
|
|
832
|
+
}
|
|
833
|
+
function parseInterfaceFromText(text) {
|
|
834
|
+
const marker = "@interface[";
|
|
835
|
+
const idx = text.indexOf(marker);
|
|
836
|
+
if (idx === -1) return null;
|
|
837
|
+
const bracketStart = idx + marker.length - 1;
|
|
838
|
+
const bracketEnd = findMatchingBracket2(text, bracketStart);
|
|
839
|
+
if (bracketEnd === -1) return null;
|
|
840
|
+
const jsonContent = text.slice(bracketStart + 1, bracketEnd);
|
|
841
|
+
try {
|
|
842
|
+
const parsed = JSON.parse(jsonContent);
|
|
843
|
+
if (!parsed.root || !parsed.root.id) return null;
|
|
844
|
+
return {
|
|
845
|
+
version: parsed.version || 1,
|
|
846
|
+
root: parsed.root
|
|
847
|
+
};
|
|
848
|
+
} catch (e2) {
|
|
849
|
+
return null;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
function parseUpdatesFromText(text) {
|
|
853
|
+
const updates = [];
|
|
854
|
+
const marker = "@update[";
|
|
855
|
+
let searchFrom = 0;
|
|
856
|
+
while (true) {
|
|
857
|
+
const idx = text.indexOf(marker, searchFrom);
|
|
858
|
+
if (idx === -1) break;
|
|
859
|
+
const bracketStart = idx + marker.length - 1;
|
|
860
|
+
const bracketEnd = findMatchingBracket2(text, bracketStart);
|
|
861
|
+
if (bracketEnd === -1) break;
|
|
862
|
+
const jsonContent = text.slice(bracketStart + 1, bracketEnd);
|
|
863
|
+
try {
|
|
864
|
+
const parsed = JSON.parse(jsonContent);
|
|
865
|
+
if (Array.isArray(parsed)) {
|
|
866
|
+
updates.push(...parsed);
|
|
867
|
+
} else if (parsed.op && parsed.target) {
|
|
868
|
+
updates.push(parsed);
|
|
869
|
+
}
|
|
870
|
+
} catch (e3) {
|
|
871
|
+
}
|
|
872
|
+
searchFrom = bracketEnd + 1;
|
|
873
|
+
}
|
|
874
|
+
return updates;
|
|
875
|
+
}
|
|
876
|
+
function containsInterface(text) {
|
|
877
|
+
return text.includes("@interface[") || text.includes("@update[");
|
|
878
|
+
}
|
|
879
|
+
function stripInterface(text) {
|
|
880
|
+
let result = text;
|
|
881
|
+
const ifacePattern = /@interface\[/g;
|
|
882
|
+
let match;
|
|
883
|
+
while ((match = ifacePattern.exec(result)) !== null) {
|
|
884
|
+
const bracketStart = match.index + match[0].length - 1;
|
|
885
|
+
const bracketEnd = findMatchingBracket2(result, bracketStart);
|
|
886
|
+
if (bracketEnd === -1) break;
|
|
887
|
+
result = result.slice(0, match.index) + result.slice(bracketEnd + 1);
|
|
888
|
+
ifacePattern.lastIndex = match.index;
|
|
889
|
+
}
|
|
890
|
+
const updatePattern = /@update\[/g;
|
|
891
|
+
while ((match = updatePattern.exec(result)) !== null) {
|
|
892
|
+
const bracketStart = match.index + match[0].length - 1;
|
|
893
|
+
const bracketEnd = findMatchingBracket2(result, bracketStart);
|
|
894
|
+
if (bracketEnd === -1) break;
|
|
895
|
+
result = result.slice(0, match.index) + result.slice(bracketEnd + 1);
|
|
896
|
+
updatePattern.lastIndex = match.index;
|
|
897
|
+
}
|
|
898
|
+
return result.replace(/\s+/g, " ").trim();
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
// src/utils/interface-context.ts
|
|
902
|
+
function generateInterfaceContext() {
|
|
903
|
+
return `## Auto Interface Mode
|
|
904
|
+
|
|
905
|
+
You generate full page interfaces as JSON. When asked for a dashboard, form, or any UI, respond with an @interface block.
|
|
906
|
+
|
|
907
|
+
### CRITICAL FORMAT RULES
|
|
908
|
+
1. Wrap your JSON in: @interface[{...}]
|
|
909
|
+
2. Every node MUST have: "type", "id", and "props" (an object)
|
|
910
|
+
3. Widget properties go INSIDE "props", NOT at the top level
|
|
911
|
+
4. The "type" field is the ACTUAL widget name (e.g. "form", "kpi", "table") \u2014 NEVER use "widget" as a type
|
|
912
|
+
5. Layout nodes use type: "layout" with a "layout" field for the layout kind
|
|
913
|
+
|
|
914
|
+
### Node structure
|
|
915
|
+
|
|
916
|
+
Layout node:
|
|
917
|
+
{"type": "layout", "id": "unique-id", "layout": "page|row|stack|columns|sidebar|tabs", "props": {...}, "children": [...]}
|
|
918
|
+
|
|
919
|
+
Widget node:
|
|
920
|
+
{"type": "kpi|text_block|form|table|chart|list|card|spacer|button_group|image", "id": "unique-id", "props": {...}}
|
|
921
|
+
|
|
922
|
+
### Layout types and their props
|
|
923
|
+
- page: { title?, padding?: "none"|"sm"|"md"|"lg", maxWidth?: "sm"|"md"|"lg"|"xl"|"full" }
|
|
924
|
+
- row: { columns?: number[] (e.g. [1,2] for 1/3+2/3), gap?: "none"|"sm"|"md"|"lg" }
|
|
925
|
+
- stack: { gap?: "none"|"sm"|"md"|"lg", align?: "left"|"center"|"right"|"stretch" }
|
|
926
|
+
- columns: { count?: number, gap?: "none"|"sm"|"md"|"lg" }
|
|
927
|
+
- sidebar: { side?: "left"|"right", width?: string }
|
|
928
|
+
- tabs: { labels: string[], defaultTab?: number }
|
|
929
|
+
|
|
930
|
+
### Widget types and their props
|
|
931
|
+
- kpi: { label: string, value: string, change?: string, trend?: "up"|"down"|"flat" }
|
|
932
|
+
- text_block: { content: string (markdown), variant?: "heading"|"body"|"caption" }
|
|
933
|
+
- spacer: { height?: "sm"|"md"|"lg", variant?: "line"|"space" }
|
|
934
|
+
- card: { title: string, description?: string, image?: string, footer?: string }
|
|
935
|
+
- list: { items: [{ id: string, title: string, subtitle?: string }] }
|
|
936
|
+
- table: { columns: [{ key: string, label: string }], rows: [{ key: value, ... }], striped?: boolean, compact?: boolean }
|
|
937
|
+
- chart: { chartType: "line"|"bar"|"pie", title?: string, data: { labels: string[], datasets: [{ label: string, data: number[] }] } }
|
|
938
|
+
- form: { title?: string, fields: [{ name: string, type: "text"|"email"|"select"|"textarea"|"checkbox", label: string, required?: boolean, placeholder?: string, options?: [{ label: string, value: string }] }] }
|
|
939
|
+
- button_group: { buttons: [{ id: string, label: string, variant?: string }] }
|
|
940
|
+
- image: { src: string, alt: string, caption?: string }
|
|
941
|
+
|
|
942
|
+
### CORRECT example
|
|
943
|
+
|
|
944
|
+
@interface[{"version":1,"root":{"type":"layout","id":"root","layout":"page","props":{"title":"My Form"},"children":[{"type":"text_block","id":"t1","props":{"content":"Fill out the form below","variant":"body"}},{"type":"form","id":"f1","props":{"fields":[{"name":"name","type":"text","label":"Name","required":true},{"name":"email","type":"email","label":"Email"}]}},{"type":"button_group","id":"b1","props":{"buttons":[{"id":"submit","label":"Submit"}]}}]}}]
|
|
945
|
+
|
|
946
|
+
### WRONG (do NOT do these)
|
|
947
|
+
- {"type": "widget", "props": {"widget": "form"}} \u2014 WRONG, type must be "form" directly
|
|
948
|
+
- {"type": "text_block", "content": "hello"} \u2014 WRONG, content must be inside props
|
|
949
|
+
- {"type": "text_block", "props": {"style": "heading"}} \u2014 WRONG, use "variant" not "style"
|
|
950
|
+
|
|
951
|
+
### Guidelines
|
|
952
|
+
- Always use unique IDs for every node
|
|
953
|
+
- Organize content logically: KPIs in a row, charts with supporting lists, etc.
|
|
954
|
+
- Use text_block for descriptions and headings within layouts
|
|
955
|
+
- Use spacer with variant "line" to separate sections
|
|
956
|
+
- You can include normal text before/after the @interface block
|
|
957
|
+
- For updates use: @update[{"op": "update", "target": "widget-id", "props": {"key": "new-value"}}]`;
|
|
958
|
+
}
|
|
959
|
+
function generateCompactInterfaceContext() {
|
|
960
|
+
return `Generate a UI interface as JSON wrapped in @interface[{...}].
|
|
961
|
+
|
|
962
|
+
STRICT FORMAT \u2014 every node needs "type", "id", and "props" (object):
|
|
963
|
+
- Layout: {"type":"layout","id":"x","layout":"page|row|stack|tabs","props":{...},"children":[...]}
|
|
964
|
+
- Widget: {"type":"kpi|text_block|form|table|chart|list|card|spacer|button_group|image","id":"x","props":{...}}
|
|
965
|
+
|
|
966
|
+
NEVER use type:"widget". The type IS the widget name. All widget properties go INSIDE "props".
|
|
967
|
+
|
|
968
|
+
Widget props:
|
|
969
|
+
- kpi: {label,value,change?,trend?}
|
|
970
|
+
- text_block: {content,variant?:"heading"|"body"|"caption"}
|
|
971
|
+
- form: {fields:[{name,type,label,required?,placeholder?}]}
|
|
972
|
+
- table: {columns:[{key,label}],rows:[{...}]}
|
|
973
|
+
- chart: {chartType:"line"|"bar"|"pie",data:{labels,datasets:[{label,data}]}}
|
|
974
|
+
- list: {items:[{id,title,subtitle?}]}
|
|
975
|
+
- button_group: {buttons:[{id,label}]}
|
|
976
|
+
|
|
977
|
+
Row props: {columns:[1,2]} means 1/3+2/3. Page props: {title:"..."}.
|
|
978
|
+
|
|
979
|
+
Example: @interface[{"version":1,"root":{"type":"layout","id":"root","layout":"page","props":{"title":"Form"},"children":[{"type":"form","id":"f1","props":{"fields":[{"name":"name","type":"text","label":"Name"}]}}]}}]`;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
// src/utils/interface-operations.ts
|
|
983
|
+
function findNode(root, id) {
|
|
984
|
+
if (root.id === id) return root;
|
|
985
|
+
if (root.children) {
|
|
986
|
+
for (const child of root.children) {
|
|
987
|
+
const found = findNode(child, id);
|
|
988
|
+
if (found) return found;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
return null;
|
|
992
|
+
}
|
|
993
|
+
function replaceNode(root, targetId, newNode) {
|
|
994
|
+
if (root.id === targetId) return newNode;
|
|
995
|
+
if (!root.children) return root;
|
|
996
|
+
const newChildren = root.children.map((child) => replaceNode(child, targetId, newNode));
|
|
997
|
+
if (newChildren.every((child, i) => child === root.children[i])) return root;
|
|
998
|
+
return { ...root, children: newChildren };
|
|
999
|
+
}
|
|
1000
|
+
function updateNodeProps(root, targetId, props) {
|
|
1001
|
+
if (root.id === targetId) {
|
|
1002
|
+
return { ...root, props: { ...root.props, ...props } };
|
|
1003
|
+
}
|
|
1004
|
+
if (!root.children) return root;
|
|
1005
|
+
const newChildren = root.children.map((child) => updateNodeProps(child, targetId, props));
|
|
1006
|
+
if (newChildren.every((child, i) => child === root.children[i])) return root;
|
|
1007
|
+
return { ...root, children: newChildren };
|
|
1008
|
+
}
|
|
1009
|
+
function removeNode(root, targetId) {
|
|
1010
|
+
if (root.id === targetId) return null;
|
|
1011
|
+
if (!root.children) return root;
|
|
1012
|
+
const newChildren = root.children.map((child) => removeNode(child, targetId)).filter((child) => child !== null);
|
|
1013
|
+
if (newChildren.length === root.children.length && newChildren.every((child, i) => child === root.children[i])) return root;
|
|
1014
|
+
return { ...root, children: newChildren };
|
|
1015
|
+
}
|
|
1016
|
+
function appendNode(root, targetId, newNode) {
|
|
1017
|
+
if (root.id === targetId) {
|
|
1018
|
+
return { ...root, children: [...root.children || [], newNode] };
|
|
1019
|
+
}
|
|
1020
|
+
if (!root.children) return root;
|
|
1021
|
+
const newChildren = root.children.map((child) => appendNode(child, targetId, newNode));
|
|
1022
|
+
if (newChildren.every((child, i) => child === root.children[i])) return root;
|
|
1023
|
+
return { ...root, children: newChildren };
|
|
1024
|
+
}
|
|
1025
|
+
function prependNode(root, targetId, newNode) {
|
|
1026
|
+
if (root.id === targetId) {
|
|
1027
|
+
return { ...root, children: [newNode, ...root.children || []] };
|
|
1028
|
+
}
|
|
1029
|
+
if (!root.children) return root;
|
|
1030
|
+
const newChildren = root.children.map((child) => prependNode(child, targetId, newNode));
|
|
1031
|
+
if (newChildren.every((child, i) => child === root.children[i])) return root;
|
|
1032
|
+
return { ...root, children: newChildren };
|
|
1033
|
+
}
|
|
1034
|
+
function applyUpdate(spec, update) {
|
|
1035
|
+
let newRoot = spec.root;
|
|
1036
|
+
switch (update.op) {
|
|
1037
|
+
case "replace":
|
|
1038
|
+
if (!update.node) return spec;
|
|
1039
|
+
newRoot = replaceNode(spec.root, update.target, update.node);
|
|
1040
|
+
break;
|
|
1041
|
+
case "update":
|
|
1042
|
+
if (!update.props) return spec;
|
|
1043
|
+
newRoot = updateNodeProps(spec.root, update.target, update.props);
|
|
1044
|
+
break;
|
|
1045
|
+
case "remove":
|
|
1046
|
+
newRoot = removeNode(spec.root, update.target);
|
|
1047
|
+
if (!newRoot) return spec;
|
|
1048
|
+
break;
|
|
1049
|
+
case "append":
|
|
1050
|
+
if (!update.node) return spec;
|
|
1051
|
+
newRoot = appendNode(spec.root, update.target, update.node);
|
|
1052
|
+
break;
|
|
1053
|
+
case "prepend":
|
|
1054
|
+
if (!update.node) return spec;
|
|
1055
|
+
newRoot = prependNode(spec.root, update.target, update.node);
|
|
1056
|
+
break;
|
|
1057
|
+
default:
|
|
1058
|
+
return spec;
|
|
1059
|
+
}
|
|
1060
|
+
if (newRoot === spec.root) return spec;
|
|
1061
|
+
return { ...spec, root: newRoot };
|
|
1062
|
+
}
|
|
1063
|
+
function applyUpdates(spec, updates) {
|
|
1064
|
+
return updates.reduce((s, update) => applyUpdate(s, update), spec);
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
// src/utils/message-converter.ts
|
|
1068
|
+
function convertApiMessages(apiMessages) {
|
|
1069
|
+
const result = [];
|
|
1070
|
+
let lastAssistantSegments = null;
|
|
1071
|
+
for (let i = 0; i < apiMessages.length; i++) {
|
|
1072
|
+
const msg = apiMessages[i];
|
|
1073
|
+
const timestamp = msg.created_at || msg.timestamp ? new Date(msg.created_at || msg.timestamp) : /* @__PURE__ */ new Date();
|
|
1074
|
+
if (typeof msg.content === "string") {
|
|
1075
|
+
const message = {
|
|
1076
|
+
id: msg.id || `thread-msg-${i}`,
|
|
1077
|
+
role: msg.role,
|
|
1078
|
+
content: msg.content,
|
|
1079
|
+
timestamp
|
|
1080
|
+
};
|
|
1081
|
+
result.push(message);
|
|
1082
|
+
lastAssistantSegments = null;
|
|
1083
|
+
} else if (Array.isArray(msg.content)) {
|
|
1084
|
+
if (msg.role === "assistant") {
|
|
1085
|
+
const segments = [];
|
|
1086
|
+
let textContent = "";
|
|
1087
|
+
for (const block of msg.content) {
|
|
1088
|
+
if (block.type === "text" && block.text) {
|
|
1089
|
+
segments.push({ type: "text", content: block.text });
|
|
1090
|
+
textContent += block.text;
|
|
1091
|
+
} else if (block.type === "tool_use") {
|
|
1092
|
+
segments.push({
|
|
1093
|
+
type: "tool",
|
|
1094
|
+
id: block.id || `tool-${i}-${segments.length}`,
|
|
1095
|
+
name: block.name || "unknown",
|
|
1096
|
+
status: "completed"
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
const message = {
|
|
1101
|
+
id: msg.id || `thread-msg-${i}`,
|
|
1102
|
+
role: "assistant",
|
|
1103
|
+
content: textContent,
|
|
1104
|
+
timestamp,
|
|
1105
|
+
metadata: segments.length > 0 ? { content_segments: segments } : void 0
|
|
1106
|
+
};
|
|
1107
|
+
result.push(message);
|
|
1108
|
+
lastAssistantSegments = segments;
|
|
1109
|
+
} else if (msg.role === "user") {
|
|
1110
|
+
const hasToolResults = msg.content.some((b) => b.type === "tool_result");
|
|
1111
|
+
if (hasToolResults && lastAssistantSegments) {
|
|
1112
|
+
for (const block of msg.content) {
|
|
1113
|
+
if (block.type === "tool_result" && block.tool_use_id) {
|
|
1114
|
+
const toolSegment = lastAssistantSegments.find(
|
|
1115
|
+
(s) => s.type === "tool" && s.id === block.tool_use_id
|
|
1116
|
+
);
|
|
1117
|
+
if (toolSegment && toolSegment.type === "tool") {
|
|
1118
|
+
toolSegment.result = typeof block.content === "string" ? block.content : Array.isArray(block.content) ? block.content.map((c) => c.text || "").join("") : void 0;
|
|
1119
|
+
toolSegment.status = block.is_error ? "error" : "completed";
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
} else {
|
|
1124
|
+
const textContent = msg.content.filter((b) => b.type === "text").map((b) => b.text || "").join("");
|
|
1125
|
+
if (textContent) {
|
|
1126
|
+
result.push({
|
|
1127
|
+
id: msg.id || `thread-msg-${i}`,
|
|
1128
|
+
role: "user",
|
|
1129
|
+
content: textContent,
|
|
1130
|
+
timestamp
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
lastAssistantSegments = null;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
return result;
|
|
1139
|
+
}
|
|
1140
|
+
|
|
800
1141
|
// src/components/Widgets/Widgets.tsx
|
|
801
1142
|
|
|
802
1143
|
|
|
@@ -1436,6 +1777,141 @@ function Flow({ widget }) {
|
|
|
1436
1777
|
] });
|
|
1437
1778
|
}
|
|
1438
1779
|
|
|
1780
|
+
// src/components/Widgets/widget-library/Kpi.tsx
|
|
1781
|
+
|
|
1782
|
+
var trendIcons = {
|
|
1783
|
+
up: { symbol: "\u2191", color: "text-emerald-500" },
|
|
1784
|
+
down: { symbol: "\u2193", color: "text-red-500" },
|
|
1785
|
+
flat: { symbol: "\u2192", color: "text-neutral-400" }
|
|
1786
|
+
};
|
|
1787
|
+
function Kpi({ widget, onAction }) {
|
|
1788
|
+
const { label = "", value = "", change, trend } = widget.props || {};
|
|
1789
|
+
const trendInfo = trend ? trendIcons[trend] : null;
|
|
1790
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "border border-neutral-200 dark:border-neutral-700 rounded-xl bg-white dark:bg-neutral-900 p-5", children: [
|
|
1791
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "!text-sm font-medium !text-neutral-500 dark:!text-neutral-400 mb-1", children: label }),
|
|
1792
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-end gap-2", children: [
|
|
1793
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "!text-2xl font-bold !text-neutral-900 dark:!text-white", children: value }),
|
|
1794
|
+
change && trendInfo && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: `flex items-center gap-0.5 !text-sm font-medium ${trendInfo.color} mb-0.5`, children: [
|
|
1795
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: trendInfo.symbol }),
|
|
1796
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: change })
|
|
1797
|
+
] }),
|
|
1798
|
+
change && !trendInfo && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "!text-sm font-medium !text-neutral-400 mb-0.5", children: change })
|
|
1799
|
+
] }),
|
|
1800
|
+
widget.actions && widget.actions.length > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex gap-2 mt-3 pt-3 border-t border-neutral-200 dark:border-neutral-700", children: widget.actions.map((action, idx) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1801
|
+
"button",
|
|
1802
|
+
{
|
|
1803
|
+
onClick: () => _optionalChain([onAction, 'optionalCall', _32 => _32({
|
|
1804
|
+
type: action.type,
|
|
1805
|
+
payload: action.payload,
|
|
1806
|
+
widgetId: widget.id,
|
|
1807
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
1808
|
+
})]),
|
|
1809
|
+
className: "px-2 py-1 !text-xs rounded font-medium transition-colors bg-neutral-100 dark:bg-neutral-800 !text-neutral-600 dark:!text-neutral-300 hover:bg-neutral-200 dark:hover:bg-neutral-700",
|
|
1810
|
+
children: action.label
|
|
1811
|
+
},
|
|
1812
|
+
idx
|
|
1813
|
+
)) })
|
|
1814
|
+
] });
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
// src/components/Widgets/widget-library/TextBlock.tsx
|
|
1818
|
+
|
|
1819
|
+
function TextBlock({ widget }) {
|
|
1820
|
+
const { content = "", variant = "body" } = widget.props || {};
|
|
1821
|
+
const variantClasses = {
|
|
1822
|
+
heading: "!text-xl font-bold !text-neutral-900 dark:!text-white",
|
|
1823
|
+
body: "!text-sm !text-neutral-700 dark:!text-neutral-300 leading-relaxed",
|
|
1824
|
+
caption: "!text-xs !text-neutral-500 dark:!text-neutral-400"
|
|
1825
|
+
};
|
|
1826
|
+
const renderMarkdown = (text) => {
|
|
1827
|
+
const lines = text.split("\n");
|
|
1828
|
+
const elements = [];
|
|
1829
|
+
let i = 0;
|
|
1830
|
+
while (i < lines.length) {
|
|
1831
|
+
const line = lines[i];
|
|
1832
|
+
if (line.startsWith("### ")) {
|
|
1833
|
+
elements.push(
|
|
1834
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { className: "!text-base font-semibold !text-neutral-900 dark:!text-white mt-3 mb-1", children: renderInline(line.slice(4)) }, i)
|
|
1835
|
+
);
|
|
1836
|
+
} else if (line.startsWith("## ")) {
|
|
1837
|
+
elements.push(
|
|
1838
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { className: "!text-lg font-bold !text-neutral-900 dark:!text-white mt-4 mb-1", children: renderInline(line.slice(3)) }, i)
|
|
1839
|
+
);
|
|
1840
|
+
} else if (/^[-*+]\s/.test(line)) {
|
|
1841
|
+
const listItems = [];
|
|
1842
|
+
while (i < lines.length && /^[-*+]\s/.test(lines[i])) {
|
|
1843
|
+
listItems.push(
|
|
1844
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "li", { className: "ml-4 list-disc", children: renderInline(lines[i].slice(2)) }, i)
|
|
1845
|
+
);
|
|
1846
|
+
i++;
|
|
1847
|
+
}
|
|
1848
|
+
elements.push(/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "ul", { className: "my-1 space-y-0.5", children: listItems }, `list-${i}`));
|
|
1849
|
+
continue;
|
|
1850
|
+
} else if (line.trim() === "") {
|
|
1851
|
+
elements.push(/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "h-2" }, i));
|
|
1852
|
+
} else {
|
|
1853
|
+
elements.push(/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "my-0.5", children: renderInline(line) }, i));
|
|
1854
|
+
}
|
|
1855
|
+
i++;
|
|
1856
|
+
}
|
|
1857
|
+
return elements;
|
|
1858
|
+
};
|
|
1859
|
+
const renderInline = (text) => {
|
|
1860
|
+
const parts = [];
|
|
1861
|
+
let remaining = text;
|
|
1862
|
+
let key = 0;
|
|
1863
|
+
while (remaining.length > 0) {
|
|
1864
|
+
const boldMatch = remaining.match(/\*\*(.+?)\*\*/);
|
|
1865
|
+
const codeMatch = remaining.match(/`(.+?)`/);
|
|
1866
|
+
const linkMatch = remaining.match(/\[(.+?)\]\((.+?)\)/);
|
|
1867
|
+
const matches = [
|
|
1868
|
+
boldMatch ? { type: "bold", index: boldMatch.index, match: boldMatch } : null,
|
|
1869
|
+
codeMatch ? { type: "code", index: codeMatch.index, match: codeMatch } : null,
|
|
1870
|
+
linkMatch ? { type: "link", index: linkMatch.index, match: linkMatch } : null
|
|
1871
|
+
].filter(Boolean).sort((a, b) => a.index - b.index);
|
|
1872
|
+
if (matches.length === 0) {
|
|
1873
|
+
parts.push(remaining);
|
|
1874
|
+
break;
|
|
1875
|
+
}
|
|
1876
|
+
const first = matches[0];
|
|
1877
|
+
if (first.index > 0) {
|
|
1878
|
+
parts.push(remaining.slice(0, first.index));
|
|
1879
|
+
}
|
|
1880
|
+
if (first.type === "bold") {
|
|
1881
|
+
parts.push(/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "strong", { className: "font-semibold", children: first.match[1] }, key++));
|
|
1882
|
+
remaining = remaining.slice(first.index + first.match[0].length);
|
|
1883
|
+
} else if (first.type === "code") {
|
|
1884
|
+
parts.push(
|
|
1885
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "code", { className: "px-1 py-0.5 bg-neutral-100 dark:bg-neutral-800 rounded text-xs font-mono", children: first.match[1] }, key++)
|
|
1886
|
+
);
|
|
1887
|
+
remaining = remaining.slice(first.index + first.match[0].length);
|
|
1888
|
+
} else if (first.type === "link") {
|
|
1889
|
+
parts.push(
|
|
1890
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "a", { href: first.match[2], className: "text-blue-500 hover:underline", target: "_blank", rel: "noopener noreferrer", children: first.match[1] }, key++)
|
|
1891
|
+
);
|
|
1892
|
+
remaining = remaining.slice(first.index + first.match[0].length);
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
return parts.length === 1 ? parts[0] : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: parts });
|
|
1896
|
+
};
|
|
1897
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: variantClasses[variant] || variantClasses.body, children: renderMarkdown(content) });
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
// src/components/Widgets/widget-library/Spacer.tsx
|
|
1901
|
+
|
|
1902
|
+
var heightClasses = {
|
|
1903
|
+
sm: "h-2",
|
|
1904
|
+
md: "h-4",
|
|
1905
|
+
lg: "h-8"
|
|
1906
|
+
};
|
|
1907
|
+
function Spacer({ widget }) {
|
|
1908
|
+
const { height = "md", variant = "space" } = widget.props || {};
|
|
1909
|
+
if (variant === "line") {
|
|
1910
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: heightClasses[height] || heightClasses.md + " flex items-center", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "hr", { className: "w-full border-neutral-200 dark:border-neutral-700" }) });
|
|
1911
|
+
}
|
|
1912
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: heightClasses[height] || heightClasses.md });
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1439
1915
|
// src/components/Widgets/WidgetRenderer.tsx
|
|
1440
1916
|
|
|
1441
1917
|
function WidgetRenderer({ widget, onAction }) {
|
|
@@ -1457,6 +1933,12 @@ function WidgetRenderer({ widget, onAction }) {
|
|
|
1457
1933
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Image, { widget });
|
|
1458
1934
|
case "flow":
|
|
1459
1935
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Flow, { widget });
|
|
1936
|
+
case "kpi":
|
|
1937
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Kpi, { widget, onAction });
|
|
1938
|
+
case "text_block":
|
|
1939
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TextBlock, { widget });
|
|
1940
|
+
case "spacer":
|
|
1941
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Spacer, { widget });
|
|
1460
1942
|
default:
|
|
1461
1943
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "p-4 border border-yellow-300 bg-yellow-50 rounded-lg", children: [
|
|
1462
1944
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "p", { className: "text-sm text-yellow-800", children: [
|
|
@@ -1483,7 +1965,7 @@ function Widgets({
|
|
|
1483
1965
|
}) {
|
|
1484
1966
|
_react.useEffect.call(void 0, () => {
|
|
1485
1967
|
widgets.forEach((widget) => {
|
|
1486
|
-
_optionalChain([onWidgetMount, 'optionalCall',
|
|
1968
|
+
_optionalChain([onWidgetMount, 'optionalCall', _33 => _33(widget.id)]);
|
|
1487
1969
|
});
|
|
1488
1970
|
}, [widgets, onWidgetMount]);
|
|
1489
1971
|
const layoutClasses = {
|
|
@@ -1809,8 +2291,8 @@ function ToolCall({ name, status, isReceiving = false, inputLength = 0, streamOu
|
|
|
1809
2291
|
|
|
1810
2292
|
function Message({ message, onAction, enableWidgets, onWidgetRender }) {
|
|
1811
2293
|
const isUser = message.role === "user";
|
|
1812
|
-
const contentSegments = _optionalChain([message, 'access',
|
|
1813
|
-
const isStreaming = _optionalChain([message, 'access',
|
|
2294
|
+
const contentSegments = _optionalChain([message, 'access', _34 => _34.metadata, 'optionalAccess', _35 => _35.content_segments]);
|
|
2295
|
+
const isStreaming = _optionalChain([message, 'access', _36 => _36.metadata, 'optionalAccess', _37 => _37.isStreaming]) === true;
|
|
1814
2296
|
const hasContent = message.content || contentSegments && contentSegments.length > 0;
|
|
1815
2297
|
const reportedWidgetsRef = _react.useRef.call(void 0, /* @__PURE__ */ new Set());
|
|
1816
2298
|
const parsedWidgets = _react.useMemo.call(void 0, () => {
|
|
@@ -1890,7 +2372,7 @@ function Message({ message, onAction, enableWidgets, onWidgetRender }) {
|
|
|
1890
2372
|
}
|
|
1891
2373
|
return elements.length > 0 ? elements : null;
|
|
1892
2374
|
};
|
|
1893
|
-
const attachments = _optionalChain([message, 'access',
|
|
2375
|
+
const attachments = _optionalChain([message, 'access', _38 => _38.metadata, 'optionalAccess', _39 => _39.attachments]) || [];
|
|
1894
2376
|
const hasAttachments = attachments.length > 0;
|
|
1895
2377
|
const renderAttachments = () => {
|
|
1896
2378
|
if (!hasAttachments) return null;
|
|
@@ -2061,15 +2543,6 @@ var DefaultIcon = () => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { cl
|
|
|
2061
2543
|
d: "M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"
|
|
2062
2544
|
}
|
|
2063
2545
|
) });
|
|
2064
|
-
var TerminalIcon = () => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-12 h-12 sm:w-16 sm:h-16", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
2065
|
-
"path",
|
|
2066
|
-
{
|
|
2067
|
-
strokeLinecap: "round",
|
|
2068
|
-
strokeLinejoin: "round",
|
|
2069
|
-
strokeWidth: 1.5,
|
|
2070
|
-
d: "M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
|
|
2071
|
-
}
|
|
2072
|
-
) });
|
|
2073
2546
|
var ArrowIcon = () => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M13 7l5 5m0 0l-5 5m5-5H6" }) });
|
|
2074
2547
|
function WelcomeScreen({
|
|
2075
2548
|
title,
|
|
@@ -2080,7 +2553,6 @@ function WelcomeScreen({
|
|
|
2080
2553
|
chatVariant = "default",
|
|
2081
2554
|
onPromptClick
|
|
2082
2555
|
}) {
|
|
2083
|
-
const WelcomeIcon = chatVariant === "terminal" ? TerminalIcon : DefaultIcon;
|
|
2084
2556
|
const normalizedPrompts = (prompts || []).map(
|
|
2085
2557
|
(p) => typeof p === "string" ? { text: p } : p
|
|
2086
2558
|
);
|
|
@@ -2088,7 +2560,7 @@ function WelcomeScreen({
|
|
|
2088
2560
|
const hasHeader = title || subtitle || icon;
|
|
2089
2561
|
if (!hasHeader && !hasPrompts) {
|
|
2090
2562
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex items-center justify-center h-full !text-neutral-500 dark:!text-neutral-400", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "text-center space-y-2", children: [
|
|
2091
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex justify-center", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
2563
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex justify-center", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, DefaultIcon, {}) }),
|
|
2092
2564
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-sm", children: "No messages yet. Start a conversation!" })
|
|
2093
2565
|
] }) });
|
|
2094
2566
|
}
|
|
@@ -2125,7 +2597,7 @@ function WelcomeScreen({
|
|
|
2125
2597
|
}
|
|
2126
2598
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col items-center justify-center h-full px-4 py-6 sm:py-8", children: [
|
|
2127
2599
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "text-center mb-6 sm:mb-8 max-w-md", children: [
|
|
2128
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "mb-4 !text-neutral-400 dark:!text-neutral-500 flex justify-center", children: icon || /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
2600
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "mb-4 !text-neutral-400 dark:!text-neutral-500 flex justify-center", children: icon || /* @__PURE__ */ _jsxruntime.jsx.call(void 0, DefaultIcon, {}) }),
|
|
2129
2601
|
title && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h1", { className: "text-xl sm:text-2xl font-semibold !text-neutral-900 dark:!text-white mb-2", children: title }),
|
|
2130
2602
|
subtitle && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-sm sm:text-base !text-neutral-500 dark:!text-neutral-400", children: subtitle })
|
|
2131
2603
|
] }),
|
|
@@ -2321,7 +2793,7 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
|
|
|
2321
2793
|
setFileError(errors.join(", "));
|
|
2322
2794
|
setTimeout(() => setFileError(null), 5e3);
|
|
2323
2795
|
}
|
|
2324
|
-
_optionalChain([onFileUpload, 'optionalCall',
|
|
2796
|
+
_optionalChain([onFileUpload, 'optionalCall', _40 => _40(e.target.files)]);
|
|
2325
2797
|
setShowMenu(false);
|
|
2326
2798
|
e.target.value = "";
|
|
2327
2799
|
}
|
|
@@ -2345,33 +2817,26 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
|
|
|
2345
2817
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" }) });
|
|
2346
2818
|
};
|
|
2347
2819
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "px-4 py-3 relative", children: [
|
|
2348
|
-
fileError && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "
|
|
2349
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", {
|
|
2820
|
+
fileError && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-file-error", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-file-error-content", children: [
|
|
2821
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", 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" }) }),
|
|
2350
2822
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: fileError })
|
|
2351
2823
|
] }) }),
|
|
2352
|
-
pendingFiles.length > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "
|
|
2353
|
-
"div",
|
|
2354
|
-
{
|
|
2355
|
-
|
|
2356
|
-
children:
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-3 h-3", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) })
|
|
2369
|
-
}
|
|
2370
|
-
)
|
|
2371
|
-
]
|
|
2372
|
-
},
|
|
2373
|
-
index
|
|
2374
|
-
)) }),
|
|
2824
|
+
pendingFiles.length > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-file-preview", children: pendingFiles.map((pf, index) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-file-item", children: [
|
|
2825
|
+
pf.preview ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "img", { src: pf.preview, alt: pf.file.name, className: "apteva-file-thumb" }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-file-icon", children: getFileIcon(pf.file.type) }),
|
|
2826
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-file-info", children: [
|
|
2827
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-file-name", children: pf.file.name }),
|
|
2828
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-file-size", children: formatFileSize(pf.file.size) })
|
|
2829
|
+
] }),
|
|
2830
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
2831
|
+
"button",
|
|
2832
|
+
{
|
|
2833
|
+
onClick: () => removeFile(index),
|
|
2834
|
+
className: "apteva-file-remove",
|
|
2835
|
+
title: "Remove file",
|
|
2836
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) })
|
|
2837
|
+
}
|
|
2838
|
+
)
|
|
2839
|
+
] }, index)) }),
|
|
2375
2840
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
2376
2841
|
"div",
|
|
2377
2842
|
{
|
|
@@ -2400,15 +2865,15 @@ function Composer({ onSendMessage, placeholder = "Type a message...", disabled =
|
|
|
2400
2865
|
{
|
|
2401
2866
|
className: "apteva-composer-menu fixed bg-neutral-800 dark:bg-neutral-800 rounded-xl shadow-lg overflow-hidden z-[9999] min-w-[200px]",
|
|
2402
2867
|
style: {
|
|
2403
|
-
left: _nullishCoalesce(_optionalChain([menuButtonRef, 'access',
|
|
2404
|
-
bottom: window.innerHeight - (_nullishCoalesce(_optionalChain([menuButtonRef, 'access',
|
|
2868
|
+
left: _nullishCoalesce(_optionalChain([menuButtonRef, 'access', _41 => _41.current, 'optionalAccess', _42 => _42.getBoundingClientRect, 'call', _43 => _43(), 'access', _44 => _44.left]), () => ( 0)),
|
|
2869
|
+
bottom: window.innerHeight - (_nullishCoalesce(_optionalChain([menuButtonRef, 'access', _45 => _45.current, 'optionalAccess', _46 => _46.getBoundingClientRect, 'call', _47 => _47(), 'access', _48 => _48.top]), () => ( 0))) + 8
|
|
2405
2870
|
},
|
|
2406
2871
|
children: [
|
|
2407
2872
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
2408
2873
|
"button",
|
|
2409
2874
|
{
|
|
2410
2875
|
onClick: () => {
|
|
2411
|
-
_optionalChain([fileInputRef, 'access',
|
|
2876
|
+
_optionalChain([fileInputRef, 'access', _49 => _49.current, 'optionalAccess', _50 => _50.click, 'call', _51 => _51()]);
|
|
2412
2877
|
setShowMenu(false);
|
|
2413
2878
|
},
|
|
2414
2879
|
className: "w-full flex items-center gap-3 px-4 py-3 hover:bg-neutral-700 dark:hover:bg-neutral-700 transition-colors !text-white text-left",
|
|
@@ -2529,8 +2994,8 @@ function CommandComposer({
|
|
|
2529
2994
|
}
|
|
2530
2995
|
};
|
|
2531
2996
|
const handleNewCommand = () => {
|
|
2532
|
-
_optionalChain([onReset, 'optionalCall',
|
|
2533
|
-
_optionalChain([inputRef, 'access',
|
|
2997
|
+
_optionalChain([onReset, 'optionalCall', _52 => _52()]);
|
|
2998
|
+
_optionalChain([inputRef, 'access', _53 => _53.current, 'optionalAccess', _54 => _54.focus, 'call', _55 => _55()]);
|
|
2534
2999
|
};
|
|
2535
3000
|
const handleInputChange = (value) => {
|
|
2536
3001
|
setInput(value);
|
|
@@ -2609,8 +3074,8 @@ function CommandComposer({
|
|
|
2609
3074
|
const isShowingResult = state !== "idle";
|
|
2610
3075
|
const { text: displayContent, isToolCall } = getDisplayContent();
|
|
2611
3076
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "w-full relative", children: [
|
|
2612
|
-
fileError && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "
|
|
2613
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", {
|
|
3077
|
+
fileError && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-file-error", style: { top: "-3rem", bottom: "auto" }, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-file-error-content", children: [
|
|
3078
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", 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" }) }),
|
|
2614
3079
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: fileError })
|
|
2615
3080
|
] }) }),
|
|
2616
3081
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
@@ -2644,15 +3109,15 @@ function CommandComposer({
|
|
|
2644
3109
|
{
|
|
2645
3110
|
className: "apteva-composer-menu fixed bg-neutral-800 dark:bg-neutral-800 rounded-xl shadow-lg overflow-hidden z-[9999] min-w-[200px]",
|
|
2646
3111
|
style: {
|
|
2647
|
-
left: _nullishCoalesce(_optionalChain([menuButtonRef, 'access',
|
|
2648
|
-
top: (_nullishCoalesce(_optionalChain([menuButtonRef, 'access',
|
|
3112
|
+
left: _nullishCoalesce(_optionalChain([menuButtonRef, 'access', _56 => _56.current, 'optionalAccess', _57 => _57.getBoundingClientRect, 'call', _58 => _58(), 'access', _59 => _59.left]), () => ( 0)),
|
|
3113
|
+
top: (_nullishCoalesce(_optionalChain([menuButtonRef, 'access', _60 => _60.current, 'optionalAccess', _61 => _61.getBoundingClientRect, 'call', _62 => _62(), 'access', _63 => _63.bottom]), () => ( 0))) + 8
|
|
2649
3114
|
},
|
|
2650
3115
|
children: [
|
|
2651
3116
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
2652
3117
|
"button",
|
|
2653
3118
|
{
|
|
2654
3119
|
onClick: () => {
|
|
2655
|
-
_optionalChain([fileInputRef, 'access',
|
|
3120
|
+
_optionalChain([fileInputRef, 'access', _64 => _64.current, 'optionalAccess', _65 => _65.click, 'call', _66 => _66()]);
|
|
2656
3121
|
setShowMenu(false);
|
|
2657
3122
|
},
|
|
2658
3123
|
className: "w-full flex items-center gap-3 px-4 py-3 hover:bg-neutral-700 dark:hover:bg-neutral-700 transition-colors !text-white text-left",
|
|
@@ -2684,26 +3149,18 @@ function CommandComposer({
|
|
|
2684
3149
|
state === "loading" && !toolName && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "w-4 h-4 border-2 border-blue-200 border-t-blue-500 rounded-full animate-spin" }),
|
|
2685
3150
|
state === "loading" && toolName && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "w-2 h-2 rounded-full bg-blue-500 animate-pulse" })
|
|
2686
3151
|
] }),
|
|
2687
|
-
pendingFiles.length > 0 && state === "idle" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "
|
|
2688
|
-
"
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
title: "Remove",
|
|
2700
|
-
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { className: "w-3 h-3 text-white", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) })
|
|
2701
|
-
}
|
|
2702
|
-
)
|
|
2703
|
-
]
|
|
2704
|
-
},
|
|
2705
|
-
index
|
|
2706
|
-
)) }),
|
|
3152
|
+
pendingFiles.length > 0 && state === "idle" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-file-badges", children: pendingFiles.map((pf, index) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "apteva-file-badge", title: pf.file.name, children: [
|
|
3153
|
+
pf.preview ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "img", { src: pf.preview, alt: pf.file.name, className: "apteva-file-badge-img" }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "apteva-file-badge-icon", children: getFileIcon(pf.file.type) }),
|
|
3154
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
3155
|
+
"button",
|
|
3156
|
+
{
|
|
3157
|
+
onClick: () => removeFile(index),
|
|
3158
|
+
className: "apteva-file-badge-remove",
|
|
3159
|
+
title: "Remove",
|
|
3160
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) })
|
|
3161
|
+
}
|
|
3162
|
+
)
|
|
3163
|
+
] }, index)) }),
|
|
2707
3164
|
state === "idle" ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
2708
3165
|
"textarea",
|
|
2709
3166
|
{
|
|
@@ -2809,22 +3266,20 @@ function CommandComposer({
|
|
|
2809
3266
|
}
|
|
2810
3267
|
|
|
2811
3268
|
// src/lib/apteva-client.ts
|
|
2812
|
-
var DEFAULT_API_URL = "http://91.99.200.48:3000/agents";
|
|
2813
|
-
var DEFAULT_API_KEY = "agt_894abd5966bc9f1e9f8f17f2a6f6b5e0";
|
|
2814
3269
|
var AptevaClient = class {
|
|
2815
|
-
constructor() {
|
|
3270
|
+
constructor(config) {
|
|
2816
3271
|
__publicField(this, "config");
|
|
2817
3272
|
this.config = {
|
|
2818
|
-
apiUrl:
|
|
2819
|
-
apiKey:
|
|
3273
|
+
apiUrl: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _67 => _67.apiUrl]), () => ( "")),
|
|
3274
|
+
apiKey: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _68 => _68.apiKey]), () => ( ""))
|
|
2820
3275
|
};
|
|
2821
3276
|
}
|
|
2822
3277
|
/**
|
|
2823
3278
|
* Update client configuration (optional - users can override defaults)
|
|
2824
3279
|
*/
|
|
2825
3280
|
configure(config) {
|
|
2826
|
-
if (config.apiUrl) this.config.apiUrl = config.apiUrl;
|
|
2827
|
-
if (config.apiKey) this.config.apiKey = config.apiKey;
|
|
3281
|
+
if (config.apiUrl !== void 0) this.config.apiUrl = config.apiUrl;
|
|
3282
|
+
if (config.apiKey !== void 0) this.config.apiKey = config.apiKey;
|
|
2828
3283
|
}
|
|
2829
3284
|
/**
|
|
2830
3285
|
* Get current configuration
|
|
@@ -2893,7 +3348,7 @@ var AptevaClient = class {
|
|
|
2893
3348
|
const error = await response.json().catch(() => ({ error: "Request failed" }));
|
|
2894
3349
|
throw new Error(error.error || `Request failed with status ${response.status}`);
|
|
2895
3350
|
}
|
|
2896
|
-
const reader = _optionalChain([response, 'access',
|
|
3351
|
+
const reader = _optionalChain([response, 'access', _69 => _69.body, 'optionalAccess', _70 => _70.getReader, 'call', _71 => _71()]);
|
|
2897
3352
|
if (!reader) {
|
|
2898
3353
|
throw new Error("Response body is not readable");
|
|
2899
3354
|
}
|
|
@@ -2911,7 +3366,7 @@ var AptevaClient = class {
|
|
|
2911
3366
|
if (line.startsWith("data: ")) {
|
|
2912
3367
|
const data = line.slice(6);
|
|
2913
3368
|
if (data === "[DONE]") {
|
|
2914
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
3369
|
+
_optionalChain([onComplete, 'optionalCall', _72 => _72(threadId)]);
|
|
2915
3370
|
return;
|
|
2916
3371
|
}
|
|
2917
3372
|
try {
|
|
@@ -2926,10 +3381,10 @@ var AptevaClient = class {
|
|
|
2926
3381
|
}
|
|
2927
3382
|
}
|
|
2928
3383
|
}
|
|
2929
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
3384
|
+
_optionalChain([onComplete, 'optionalCall', _73 => _73(threadId)]);
|
|
2930
3385
|
} catch (error) {
|
|
2931
3386
|
const err = error instanceof Error ? error : new Error("Unknown error");
|
|
2932
|
-
_optionalChain([onError, 'optionalCall',
|
|
3387
|
+
_optionalChain([onError, 'optionalCall', _74 => _74(err)]);
|
|
2933
3388
|
throw err;
|
|
2934
3389
|
}
|
|
2935
3390
|
}
|
|
@@ -3034,6 +3489,7 @@ var Chat = _react.forwardRef.call(void 0, function Chat2({
|
|
|
3034
3489
|
placeholder,
|
|
3035
3490
|
showHeader = true,
|
|
3036
3491
|
headerTitle = "Chat",
|
|
3492
|
+
onHeaderBack,
|
|
3037
3493
|
// Widget detection
|
|
3038
3494
|
enableWidgets = false,
|
|
3039
3495
|
availableWidgets,
|
|
@@ -3090,7 +3546,7 @@ ${widgetContext}` : widgetContext;
|
|
|
3090
3546
|
}, [apiUrl, apiKey]);
|
|
3091
3547
|
_react.useEffect.call(void 0, () => {
|
|
3092
3548
|
if (threadId) {
|
|
3093
|
-
_optionalChain([onThreadChange, 'optionalCall',
|
|
3549
|
+
_optionalChain([onThreadChange, 'optionalCall', _75 => _75(threadId)]);
|
|
3094
3550
|
}
|
|
3095
3551
|
}, [threadId, onThreadChange]);
|
|
3096
3552
|
_react.useEffect.call(void 0, () => {
|
|
@@ -3108,7 +3564,7 @@ ${widgetContext}` : widgetContext;
|
|
|
3108
3564
|
}, [showSettingsMenu]);
|
|
3109
3565
|
const handleModeChange = (newMode) => {
|
|
3110
3566
|
setMode(newMode);
|
|
3111
|
-
_optionalChain([onModeChange, 'optionalCall',
|
|
3567
|
+
_optionalChain([onModeChange, 'optionalCall', _76 => _76(newMode)]);
|
|
3112
3568
|
if (newMode === "command") {
|
|
3113
3569
|
setCommandState("idle");
|
|
3114
3570
|
setCommandResult(null);
|
|
@@ -3133,7 +3589,7 @@ ${widgetContext}` : widgetContext;
|
|
|
3133
3589
|
metadata: hasFiles ? { attachments } : void 0
|
|
3134
3590
|
};
|
|
3135
3591
|
setMessages((prev) => [...prev, userMessage]);
|
|
3136
|
-
_optionalChain([onMessageSent, 'optionalCall',
|
|
3592
|
+
_optionalChain([onMessageSent, 'optionalCall', _77 => _77(userMessage)]);
|
|
3137
3593
|
}
|
|
3138
3594
|
setIsLoading(true);
|
|
3139
3595
|
try {
|
|
@@ -3148,7 +3604,7 @@ ${widgetContext}` : widgetContext;
|
|
|
3148
3604
|
let responseThreadId = currentThreadId;
|
|
3149
3605
|
const toolInputBuffers = {};
|
|
3150
3606
|
const receivingTimeouts = {};
|
|
3151
|
-
const streamingMessageId = `msg-${Date.now()}`;
|
|
3607
|
+
const streamingMessageId = `msg-${Date.now()}-res`;
|
|
3152
3608
|
const updateMessage = () => {
|
|
3153
3609
|
const segments = [...contentSegments];
|
|
3154
3610
|
if (currentTextBuffer) {
|
|
@@ -3201,7 +3657,7 @@ ${widgetContext}` : widgetContext;
|
|
|
3201
3657
|
responseThreadId = chunk.thread_id;
|
|
3202
3658
|
if (!currentThreadId) {
|
|
3203
3659
|
setCurrentThreadId(chunk.thread_id);
|
|
3204
|
-
_optionalChain([onThreadChange, 'optionalCall',
|
|
3660
|
+
_optionalChain([onThreadChange, 'optionalCall', _78 => _78(chunk.thread_id)]);
|
|
3205
3661
|
}
|
|
3206
3662
|
}
|
|
3207
3663
|
break;
|
|
@@ -3227,7 +3683,7 @@ ${widgetContext}` : widgetContext;
|
|
|
3227
3683
|
contentSegments.push({ type: "tool", id: chunk.tool_id, name: displayName, status: "preparing" });
|
|
3228
3684
|
toolInputBuffers[chunk.tool_id] = "";
|
|
3229
3685
|
setChatToolName(displayName);
|
|
3230
|
-
_optionalChain([onToolCall, 'optionalCall',
|
|
3686
|
+
_optionalChain([onToolCall, 'optionalCall', _79 => _79(chunk.tool_name, chunk.tool_id)]);
|
|
3231
3687
|
updateMessage();
|
|
3232
3688
|
}
|
|
3233
3689
|
break;
|
|
@@ -3287,7 +3743,7 @@ ${widgetContext}` : widgetContext;
|
|
|
3287
3743
|
toolSegment.result = chunk.content;
|
|
3288
3744
|
toolSegment.status = "completed";
|
|
3289
3745
|
toolSegment.isReceiving = false;
|
|
3290
|
-
_optionalChain([onToolResult, 'optionalCall',
|
|
3746
|
+
_optionalChain([onToolResult, 'optionalCall', _80 => _80(toolSegment.name, chunk.content)]);
|
|
3291
3747
|
}
|
|
3292
3748
|
setChatToolName(null);
|
|
3293
3749
|
updateMessage();
|
|
@@ -3330,7 +3786,7 @@ ${widgetContext}` : widgetContext;
|
|
|
3330
3786
|
});
|
|
3331
3787
|
if (threadId2 && threadId2 !== currentThreadId) {
|
|
3332
3788
|
setCurrentThreadId(threadId2);
|
|
3333
|
-
_optionalChain([onThreadChange, 'optionalCall',
|
|
3789
|
+
_optionalChain([onThreadChange, 'optionalCall', _81 => _81(threadId2)]);
|
|
3334
3790
|
}
|
|
3335
3791
|
setIsLoading(false);
|
|
3336
3792
|
setCurrentRequestId(null);
|
|
@@ -3354,7 +3810,7 @@ ${widgetContext}` : widgetContext;
|
|
|
3354
3810
|
setIsLoading(false);
|
|
3355
3811
|
setCurrentRequestId(null);
|
|
3356
3812
|
setChatToolName(null);
|
|
3357
|
-
_optionalChain([onError, 'optionalCall',
|
|
3813
|
+
_optionalChain([onError, 'optionalCall', _82 => _82(error)]);
|
|
3358
3814
|
}
|
|
3359
3815
|
);
|
|
3360
3816
|
}
|
|
@@ -3367,7 +3823,7 @@ ${widgetContext}` : widgetContext;
|
|
|
3367
3823
|
metadata: { error: true }
|
|
3368
3824
|
};
|
|
3369
3825
|
setMessages((prev) => [...prev, errorMessage]);
|
|
3370
|
-
_optionalChain([onError, 'optionalCall',
|
|
3826
|
+
_optionalChain([onError, 'optionalCall', _83 => _83(error instanceof Error ? error : new Error("Unknown error"))]);
|
|
3371
3827
|
} finally {
|
|
3372
3828
|
setIsLoading(false);
|
|
3373
3829
|
}
|
|
@@ -3413,7 +3869,7 @@ ${planningInstruction}` : planningInstruction;
|
|
|
3413
3869
|
const error = err instanceof Error ? err : new Error("Failed to generate plan");
|
|
3414
3870
|
setCommandError(error);
|
|
3415
3871
|
setCommandState("error");
|
|
3416
|
-
_optionalChain([onError, 'optionalCall',
|
|
3872
|
+
_optionalChain([onError, 'optionalCall', _84 => _84(error)]);
|
|
3417
3873
|
}
|
|
3418
3874
|
}
|
|
3419
3875
|
return;
|
|
@@ -3446,12 +3902,12 @@ ${planningInstruction}` : planningInstruction;
|
|
|
3446
3902
|
setCommandResult(result);
|
|
3447
3903
|
setCommandState("success");
|
|
3448
3904
|
setProgress(100);
|
|
3449
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
3905
|
+
_optionalChain([onComplete, 'optionalCall', _85 => _85(result)]);
|
|
3450
3906
|
},
|
|
3451
3907
|
(error) => {
|
|
3452
3908
|
setCommandError(error);
|
|
3453
3909
|
setCommandState("error");
|
|
3454
|
-
_optionalChain([onError, 'optionalCall',
|
|
3910
|
+
_optionalChain([onError, 'optionalCall', _86 => _86(error)]);
|
|
3455
3911
|
}
|
|
3456
3912
|
);
|
|
3457
3913
|
} else {
|
|
@@ -3464,7 +3920,7 @@ ${planningInstruction}` : planningInstruction;
|
|
|
3464
3920
|
setCommandResult(result);
|
|
3465
3921
|
setCommandState("success");
|
|
3466
3922
|
setProgress(100);
|
|
3467
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
3923
|
+
_optionalChain([onComplete, 'optionalCall', _87 => _87(result)]);
|
|
3468
3924
|
}
|
|
3469
3925
|
} else {
|
|
3470
3926
|
const 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.`;
|
|
@@ -3494,16 +3950,16 @@ ${commandInstruction}` : commandInstruction;
|
|
|
3494
3950
|
const displayName = chunk.tool_display_name || chunk.tool_name;
|
|
3495
3951
|
lastToolName = chunk.tool_name;
|
|
3496
3952
|
setCurrentToolName(displayName);
|
|
3497
|
-
_optionalChain([onToolCall, 'optionalCall',
|
|
3953
|
+
_optionalChain([onToolCall, 'optionalCall', _88 => _88(chunk.tool_name, chunk.tool_id || "")]);
|
|
3498
3954
|
accumulatedContent = "";
|
|
3499
3955
|
setStreamedContent("");
|
|
3500
3956
|
} else if (chunk.type === "tool_result") {
|
|
3501
|
-
_optionalChain([onToolResult, 'optionalCall',
|
|
3957
|
+
_optionalChain([onToolResult, 'optionalCall', _89 => _89(lastToolName, chunk.content)]);
|
|
3502
3958
|
setCurrentToolName(null);
|
|
3503
3959
|
} else if (chunk.type === "thread_id" && chunk.thread_id) {
|
|
3504
3960
|
if (!currentThreadId) {
|
|
3505
3961
|
setCurrentThreadId(chunk.thread_id);
|
|
3506
|
-
_optionalChain([onThreadChange, 'optionalCall',
|
|
3962
|
+
_optionalChain([onThreadChange, 'optionalCall', _90 => _90(chunk.thread_id)]);
|
|
3507
3963
|
}
|
|
3508
3964
|
} else if (chunk.type === "request_id" && chunk.request_id) {
|
|
3509
3965
|
setCurrentRequestId(chunk.request_id);
|
|
@@ -3519,13 +3975,13 @@ ${commandInstruction}` : commandInstruction;
|
|
|
3519
3975
|
setCommandState("success");
|
|
3520
3976
|
setProgress(100);
|
|
3521
3977
|
setCurrentRequestId(null);
|
|
3522
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
3978
|
+
_optionalChain([onComplete, 'optionalCall', _91 => _91(result)]);
|
|
3523
3979
|
},
|
|
3524
3980
|
(error) => {
|
|
3525
3981
|
setCommandError(error);
|
|
3526
3982
|
setCommandState("error");
|
|
3527
3983
|
setCurrentRequestId(null);
|
|
3528
|
-
_optionalChain([onError, 'optionalCall',
|
|
3984
|
+
_optionalChain([onError, 'optionalCall', _92 => _92(error)]);
|
|
3529
3985
|
}
|
|
3530
3986
|
);
|
|
3531
3987
|
} else {
|
|
@@ -3545,14 +4001,14 @@ ${commandInstruction}` : commandInstruction;
|
|
|
3545
4001
|
setCommandResult(result);
|
|
3546
4002
|
setCommandState("success");
|
|
3547
4003
|
setProgress(100);
|
|
3548
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
4004
|
+
_optionalChain([onComplete, 'optionalCall', _93 => _93(result)]);
|
|
3549
4005
|
}
|
|
3550
4006
|
}
|
|
3551
4007
|
} catch (err) {
|
|
3552
4008
|
const error = err instanceof Error ? err : new Error("Unknown error");
|
|
3553
4009
|
setCommandError(error);
|
|
3554
4010
|
setCommandState("error");
|
|
3555
|
-
_optionalChain([onError, 'optionalCall',
|
|
4011
|
+
_optionalChain([onError, 'optionalCall', _94 => _94(error)]);
|
|
3556
4012
|
}
|
|
3557
4013
|
};
|
|
3558
4014
|
const resetCommand = () => {
|
|
@@ -3600,12 +4056,15 @@ ${planToExecute}`;
|
|
|
3600
4056
|
};
|
|
3601
4057
|
const isCompact = commandVariant === "compact";
|
|
3602
4058
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: cn("apteva-chat flex flex-col h-full", variant !== "default" && `apteva-chat-${variant}`, className), children: [
|
|
3603
|
-
showHeader && mode === "chat" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-chat-header px-4 py-3
|
|
3604
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "
|
|
3605
|
-
/* @__PURE__ */ _jsxruntime.
|
|
3606
|
-
"apteva-chat-
|
|
3607
|
-
|
|
3608
|
-
|
|
4059
|
+
showHeader && mode === "chat" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-chat-header px-4 py-3", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { style: { display: "flex", alignItems: "center", gap: "0.5rem" }, children: [
|
|
4060
|
+
onHeaderBack && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "button", { onClick: onHeaderBack, className: "apteva-chat-back", style: { flexShrink: 0 }, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "path", { d: "M10 12L6 8l4-4" }) }) }),
|
|
4061
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
|
|
4062
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "apteva-chat-title", children: headerTitle }),
|
|
4063
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: cn(
|
|
4064
|
+
"apteva-chat-status",
|
|
4065
|
+
isLoading ? chatToolName ? "apteva-chat-status-tool" : "apteva-chat-status-thinking" : "apteva-chat-status-ready"
|
|
4066
|
+
), children: isLoading ? chatToolName ? `Using ${chatToolName}...` : "Thinking..." : "Ready" })
|
|
4067
|
+
] })
|
|
3609
4068
|
] }) }),
|
|
3610
4069
|
mode === "chat" && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
3611
4070
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
@@ -3645,8 +4104,8 @@ ${planToExecute}`;
|
|
|
3645
4104
|
executeCommand(text, files);
|
|
3646
4105
|
},
|
|
3647
4106
|
state: commandState,
|
|
3648
|
-
response: _optionalChain([commandResult, 'optionalAccess',
|
|
3649
|
-
error: _optionalChain([commandError, 'optionalAccess',
|
|
4107
|
+
response: _optionalChain([commandResult, 'optionalAccess', _95 => _95.data, 'optionalAccess', _96 => _96.summary]) || _optionalChain([commandResult, 'optionalAccess', _97 => _97.message]),
|
|
4108
|
+
error: _optionalChain([commandError, 'optionalAccess', _98 => _98.message]),
|
|
3650
4109
|
plan,
|
|
3651
4110
|
streamedContent,
|
|
3652
4111
|
toolName: currentToolName,
|
|
@@ -3814,13 +4273,13 @@ ${planningInstruction}` : planningInstruction;
|
|
|
3814
4273
|
const error2 = err instanceof Error ? err : new Error("Failed to generate plan");
|
|
3815
4274
|
setError(error2);
|
|
3816
4275
|
setState("error");
|
|
3817
|
-
_optionalChain([onError, 'optionalCall',
|
|
4276
|
+
_optionalChain([onError, 'optionalCall', _99 => _99(error2)]);
|
|
3818
4277
|
});
|
|
3819
4278
|
} catch (err) {
|
|
3820
4279
|
const error2 = err instanceof Error ? err : new Error("Failed to generate plan");
|
|
3821
4280
|
setError(error2);
|
|
3822
4281
|
setState("error");
|
|
3823
|
-
_optionalChain([onError, 'optionalCall',
|
|
4282
|
+
_optionalChain([onError, 'optionalCall', _100 => _100(error2)]);
|
|
3824
4283
|
}
|
|
3825
4284
|
}
|
|
3826
4285
|
return;
|
|
@@ -3831,7 +4290,7 @@ ${planningInstruction}` : planningInstruction;
|
|
|
3831
4290
|
setStreamedContent("");
|
|
3832
4291
|
setCommand("");
|
|
3833
4292
|
setUploadedFiles([]);
|
|
3834
|
-
_optionalChain([onStart, 'optionalCall',
|
|
4293
|
+
_optionalChain([onStart, 'optionalCall', _101 => _101()]);
|
|
3835
4294
|
try {
|
|
3836
4295
|
if (useMock) {
|
|
3837
4296
|
if (enableStreaming) {
|
|
@@ -3842,16 +4301,16 @@ ${planningInstruction}` : planningInstruction;
|
|
|
3842
4301
|
if (chunk.type === "token" && chunk.content) {
|
|
3843
4302
|
accumulatedContent += chunk.content;
|
|
3844
4303
|
setStreamedContent(accumulatedContent);
|
|
3845
|
-
_optionalChain([onChunk, 'optionalCall',
|
|
4304
|
+
_optionalChain([onChunk, 'optionalCall', _102 => _102(chunk.content)]);
|
|
3846
4305
|
const estimatedProgress = Math.min(Math.round(accumulatedContent.length / 10), 90);
|
|
3847
4306
|
setProgress(estimatedProgress);
|
|
3848
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
4307
|
+
_optionalChain([onProgress, 'optionalCall', _103 => _103(estimatedProgress)]);
|
|
3849
4308
|
} else if (chunk.type === "widget" && chunk.widget) {
|
|
3850
4309
|
const widget = chunk.widget;
|
|
3851
4310
|
setResult((prev) => ({
|
|
3852
4311
|
success: true,
|
|
3853
|
-
data: _optionalChain([prev, 'optionalAccess',
|
|
3854
|
-
widgets: [..._optionalChain([prev, 'optionalAccess',
|
|
4312
|
+
data: _optionalChain([prev, 'optionalAccess', _104 => _104.data]) || {},
|
|
4313
|
+
widgets: [..._optionalChain([prev, 'optionalAccess', _105 => _105.widgets]) || [], widget],
|
|
3855
4314
|
message: accumulatedContent || "Command executed successfully"
|
|
3856
4315
|
}));
|
|
3857
4316
|
}
|
|
@@ -3871,19 +4330,19 @@ ${planningInstruction}` : planningInstruction;
|
|
|
3871
4330
|
setResult(result2);
|
|
3872
4331
|
setState("success");
|
|
3873
4332
|
setProgress(100);
|
|
3874
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
4333
|
+
_optionalChain([onComplete, 'optionalCall', _106 => _106(result2)]);
|
|
3875
4334
|
},
|
|
3876
4335
|
(error2) => {
|
|
3877
4336
|
setError(error2);
|
|
3878
4337
|
setState("error");
|
|
3879
|
-
_optionalChain([onError, 'optionalCall',
|
|
4338
|
+
_optionalChain([onError, 'optionalCall', _107 => _107(error2)]);
|
|
3880
4339
|
}
|
|
3881
4340
|
);
|
|
3882
4341
|
} else {
|
|
3883
4342
|
const progressInterval = setInterval(() => {
|
|
3884
4343
|
setProgress((prev) => {
|
|
3885
4344
|
const next = Math.min(prev + 10, 90);
|
|
3886
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
4345
|
+
_optionalChain([onProgress, 'optionalCall', _108 => _108(next)]);
|
|
3887
4346
|
return next;
|
|
3888
4347
|
});
|
|
3889
4348
|
}, 200);
|
|
@@ -3907,7 +4366,7 @@ ${planningInstruction}` : planningInstruction;
|
|
|
3907
4366
|
setResult(result2);
|
|
3908
4367
|
setState("success");
|
|
3909
4368
|
setProgress(100);
|
|
3910
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
4369
|
+
_optionalChain([onComplete, 'optionalCall', _109 => _109(result2)]);
|
|
3911
4370
|
}
|
|
3912
4371
|
} else {
|
|
3913
4372
|
if (enableStreaming) {
|
|
@@ -3953,16 +4412,16 @@ ${commandInstruction}` : commandInstruction;
|
|
|
3953
4412
|
if (chunk.type === "token" && chunk.content) {
|
|
3954
4413
|
accumulatedContent += chunk.content;
|
|
3955
4414
|
setStreamedContent(accumulatedContent);
|
|
3956
|
-
_optionalChain([onChunk, 'optionalCall',
|
|
4415
|
+
_optionalChain([onChunk, 'optionalCall', _110 => _110(chunk.content)]);
|
|
3957
4416
|
const estimatedProgress = Math.min(Math.round(accumulatedContent.length / 10), 90);
|
|
3958
4417
|
setProgress(estimatedProgress);
|
|
3959
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
4418
|
+
_optionalChain([onProgress, 'optionalCall', _111 => _111(estimatedProgress)]);
|
|
3960
4419
|
} else if (chunk.type === "widget" && chunk.widget) {
|
|
3961
4420
|
const widget = chunk.widget;
|
|
3962
4421
|
setResult((prev) => ({
|
|
3963
4422
|
success: true,
|
|
3964
|
-
data: _optionalChain([prev, 'optionalAccess',
|
|
3965
|
-
widgets: [..._optionalChain([prev, 'optionalAccess',
|
|
4423
|
+
data: _optionalChain([prev, 'optionalAccess', _112 => _112.data]) || {},
|
|
4424
|
+
widgets: [..._optionalChain([prev, 'optionalAccess', _113 => _113.widgets]) || [], widget],
|
|
3966
4425
|
message: accumulatedContent || "Command executed successfully"
|
|
3967
4426
|
}));
|
|
3968
4427
|
}
|
|
@@ -3982,20 +4441,20 @@ ${commandInstruction}` : commandInstruction;
|
|
|
3982
4441
|
setResult(result2);
|
|
3983
4442
|
setState("success");
|
|
3984
4443
|
setProgress(100);
|
|
3985
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
4444
|
+
_optionalChain([onComplete, 'optionalCall', _114 => _114(result2)]);
|
|
3986
4445
|
},
|
|
3987
4446
|
(error2) => {
|
|
3988
4447
|
const err = error2 instanceof Error ? error2 : new Error("Unknown error");
|
|
3989
4448
|
setError(err);
|
|
3990
4449
|
setState("error");
|
|
3991
|
-
_optionalChain([onError, 'optionalCall',
|
|
4450
|
+
_optionalChain([onError, 'optionalCall', _115 => _115(err)]);
|
|
3992
4451
|
}
|
|
3993
4452
|
);
|
|
3994
4453
|
} else {
|
|
3995
4454
|
const progressInterval = setInterval(() => {
|
|
3996
4455
|
setProgress((prev) => {
|
|
3997
4456
|
const next = Math.min(prev + 10, 90);
|
|
3998
|
-
_optionalChain([onProgress, 'optionalCall',
|
|
4457
|
+
_optionalChain([onProgress, 'optionalCall', _116 => _116(next)]);
|
|
3999
4458
|
return next;
|
|
4000
4459
|
});
|
|
4001
4460
|
}, 200);
|
|
@@ -4051,14 +4510,14 @@ ${commandInstruction}` : commandInstruction;
|
|
|
4051
4510
|
setResult(result2);
|
|
4052
4511
|
setState("success");
|
|
4053
4512
|
setProgress(100);
|
|
4054
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
4513
|
+
_optionalChain([onComplete, 'optionalCall', _117 => _117(result2)]);
|
|
4055
4514
|
}
|
|
4056
4515
|
}
|
|
4057
4516
|
} catch (err) {
|
|
4058
4517
|
const error2 = err instanceof Error ? err : new Error("Unknown error");
|
|
4059
4518
|
setError(error2);
|
|
4060
4519
|
setState("error");
|
|
4061
|
-
_optionalChain([onError, 'optionalCall',
|
|
4520
|
+
_optionalChain([onError, 'optionalCall', _118 => _118(error2)]);
|
|
4062
4521
|
}
|
|
4063
4522
|
};
|
|
4064
4523
|
const resetCommand = () => {
|
|
@@ -4091,14 +4550,14 @@ ${planToExecute}`;
|
|
|
4091
4550
|
};
|
|
4092
4551
|
const handleFileSelect = async (e) => {
|
|
4093
4552
|
if (e.target.files && e.target.files.length > 0) {
|
|
4094
|
-
_optionalChain([onFileUpload, 'optionalCall',
|
|
4553
|
+
_optionalChain([onFileUpload, 'optionalCall', _119 => _119(e.target.files)]);
|
|
4095
4554
|
const files = [];
|
|
4096
4555
|
for (let i = 0; i < e.target.files.length; i++) {
|
|
4097
4556
|
const file = e.target.files[i];
|
|
4098
4557
|
const reader = new FileReader();
|
|
4099
4558
|
await new Promise((resolve) => {
|
|
4100
4559
|
reader.onload = (event) => {
|
|
4101
|
-
if (_optionalChain([event, 'access',
|
|
4560
|
+
if (_optionalChain([event, 'access', _120 => _120.target, 'optionalAccess', _121 => _121.result])) {
|
|
4102
4561
|
const fullDataUrl = event.target.result;
|
|
4103
4562
|
const base64Data = fullDataUrl.split(",")[1];
|
|
4104
4563
|
if (file.type.startsWith("image/")) {
|
|
@@ -4192,7 +4651,7 @@ ${planToExecute}`;
|
|
|
4192
4651
|
enableFileUpload && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
4193
4652
|
"button",
|
|
4194
4653
|
{
|
|
4195
|
-
onClick: () => _optionalChain([fileInputRef, 'access',
|
|
4654
|
+
onClick: () => _optionalChain([fileInputRef, 'access', _122 => _122.current, 'optionalAccess', _123 => _123.click, 'call', _124 => _124()]),
|
|
4196
4655
|
className: "w-8 h-8 rounded-lg flex items-center justify-center transition-all flex-shrink-0 !text-neutral-500 dark:!text-neutral-500 hover:bg-neutral-100 dark:hover:bg-neutral-800",
|
|
4197
4656
|
title: "Attach file",
|
|
4198
4657
|
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)" }) })
|
|
@@ -4411,7 +4870,7 @@ ${planToExecute}`;
|
|
|
4411
4870
|
/* @__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" }) }),
|
|
4412
4871
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
|
|
4413
4872
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h3", { className: "text-sm font-semibold text-red-800 dark:text-red-400", children: "Error" }),
|
|
4414
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-red-700 dark:text-red-300 text-sm mt-1", children: _optionalChain([error, 'optionalAccess',
|
|
4873
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-red-700 dark:text-red-300 text-sm mt-1", children: _optionalChain([error, 'optionalAccess', _125 => _125.message]) })
|
|
4415
4874
|
] })
|
|
4416
4875
|
] }) }),
|
|
4417
4876
|
allowInput && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
@@ -4439,7 +4898,7 @@ ${planToExecute}`;
|
|
|
4439
4898
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-green-700 dark:text-green-300 text-sm", children: "Command executed successfully" })
|
|
4440
4899
|
] })
|
|
4441
4900
|
] }),
|
|
4442
|
-
_optionalChain([result, 'access',
|
|
4901
|
+
_optionalChain([result, 'access', _126 => _126.data, 'optionalAccess', _127 => _127.summary]) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "text-neutral-700 dark:text-neutral-300 text-sm leading-relaxed whitespace-pre-line", children: result.data.summary }),
|
|
4443
4902
|
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,
|
|
4444
4903
|
WidgetRenderer,
|
|
4445
4904
|
{
|
|
@@ -4490,7 +4949,7 @@ ${planToExecute}`;
|
|
|
4490
4949
|
enableFileUpload && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
4491
4950
|
"button",
|
|
4492
4951
|
{
|
|
4493
|
-
onClick: () => _optionalChain([fileInputRef, 'access',
|
|
4952
|
+
onClick: () => _optionalChain([fileInputRef, 'access', _128 => _128.current, 'optionalAccess', _129 => _129.click, 'call', _130 => _130()]),
|
|
4494
4953
|
className: "w-8 h-8 rounded-lg flex items-center justify-center transition-all flex-shrink-0 !text-neutral-500 dark:!text-neutral-500 hover:bg-neutral-100 dark:hover:bg-neutral-800",
|
|
4495
4954
|
title: "Attach file",
|
|
4496
4955
|
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)" }) })
|
|
@@ -4676,25 +5135,25 @@ function Prompt({
|
|
|
4676
5135
|
const newValue = e.target.value;
|
|
4677
5136
|
if (!maxLength || newValue.length <= maxLength) {
|
|
4678
5137
|
setValue(newValue);
|
|
4679
|
-
_optionalChain([onChange, 'optionalCall',
|
|
5138
|
+
_optionalChain([onChange, 'optionalCall', _131 => _131(newValue)]);
|
|
4680
5139
|
}
|
|
4681
5140
|
};
|
|
4682
5141
|
const handleSubmit = async () => {
|
|
4683
5142
|
if (value.length < minLength) return;
|
|
4684
|
-
_optionalChain([onSubmit, 'optionalCall',
|
|
5143
|
+
_optionalChain([onSubmit, 'optionalCall', _132 => _132(value)]);
|
|
4685
5144
|
setIsLoading(true);
|
|
4686
5145
|
try {
|
|
4687
5146
|
if (useMock) {
|
|
4688
5147
|
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
4689
5148
|
const mockResult = `Enhanced version: ${value} [AI-generated content]`;
|
|
4690
|
-
_optionalChain([onResult, 'optionalCall',
|
|
5149
|
+
_optionalChain([onResult, 'optionalCall', _133 => _133(mockResult)]);
|
|
4691
5150
|
setValue("");
|
|
4692
5151
|
} else {
|
|
4693
5152
|
const response = await aptevaClient.chat({
|
|
4694
5153
|
agent_id: agentId,
|
|
4695
5154
|
message: value
|
|
4696
5155
|
});
|
|
4697
|
-
_optionalChain([onResult, 'optionalCall',
|
|
5156
|
+
_optionalChain([onResult, 'optionalCall', _134 => _134(response.message)]);
|
|
4698
5157
|
setValue("");
|
|
4699
5158
|
}
|
|
4700
5159
|
} catch (error) {
|
|
@@ -4789,7 +5248,7 @@ function Stream({
|
|
|
4789
5248
|
}, [autoStart]);
|
|
4790
5249
|
const startStreaming = async () => {
|
|
4791
5250
|
setIsStreaming(true);
|
|
4792
|
-
_optionalChain([onStart, 'optionalCall',
|
|
5251
|
+
_optionalChain([onStart, 'optionalCall', _135 => _135()]);
|
|
4793
5252
|
try {
|
|
4794
5253
|
if (useMock) {
|
|
4795
5254
|
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.";
|
|
@@ -4797,13 +5256,13 @@ function Stream({
|
|
|
4797
5256
|
mockText,
|
|
4798
5257
|
(chunk) => {
|
|
4799
5258
|
setText((prev) => prev + chunk);
|
|
4800
|
-
_optionalChain([onChunk, 'optionalCall',
|
|
5259
|
+
_optionalChain([onChunk, 'optionalCall', _136 => _136(chunk)]);
|
|
4801
5260
|
},
|
|
4802
5261
|
typingSpeed
|
|
4803
5262
|
);
|
|
4804
5263
|
setIsComplete(true);
|
|
4805
5264
|
setIsStreaming(false);
|
|
4806
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
5265
|
+
_optionalChain([onComplete, 'optionalCall', _137 => _137(text + mockText)]);
|
|
4807
5266
|
} else {
|
|
4808
5267
|
let accumulatedText = "";
|
|
4809
5268
|
await aptevaClient.chatStream(
|
|
@@ -4816,24 +5275,24 @@ function Stream({
|
|
|
4816
5275
|
if (chunk.type === "token" && chunk.content) {
|
|
4817
5276
|
accumulatedText += chunk.content;
|
|
4818
5277
|
setText(accumulatedText);
|
|
4819
|
-
_optionalChain([onChunk, 'optionalCall',
|
|
5278
|
+
_optionalChain([onChunk, 'optionalCall', _138 => _138(chunk.content)]);
|
|
4820
5279
|
}
|
|
4821
5280
|
},
|
|
4822
5281
|
() => {
|
|
4823
5282
|
setIsComplete(true);
|
|
4824
5283
|
setIsStreaming(false);
|
|
4825
|
-
_optionalChain([onComplete, 'optionalCall',
|
|
5284
|
+
_optionalChain([onComplete, 'optionalCall', _139 => _139(accumulatedText)]);
|
|
4826
5285
|
},
|
|
4827
5286
|
(error) => {
|
|
4828
5287
|
const err = error instanceof Error ? error : new Error("Streaming error");
|
|
4829
|
-
_optionalChain([onError, 'optionalCall',
|
|
5288
|
+
_optionalChain([onError, 'optionalCall', _140 => _140(err)]);
|
|
4830
5289
|
setIsStreaming(false);
|
|
4831
5290
|
}
|
|
4832
5291
|
);
|
|
4833
5292
|
}
|
|
4834
5293
|
} catch (error) {
|
|
4835
5294
|
const err = error instanceof Error ? error : new Error("Streaming error");
|
|
4836
|
-
_optionalChain([onError, 'optionalCall',
|
|
5295
|
+
_optionalChain([onError, 'optionalCall', _141 => _141(err)]);
|
|
4837
5296
|
setIsStreaming(false);
|
|
4838
5297
|
}
|
|
4839
5298
|
};
|
|
@@ -4925,7 +5384,7 @@ function ThreadList({
|
|
|
4925
5384
|
}) {
|
|
4926
5385
|
const [searchQuery, setSearchQuery] = _react.useState.call(void 0, "");
|
|
4927
5386
|
const filteredThreads = threads.filter(
|
|
4928
|
-
(thread) => thread.title.toLowerCase().includes(searchQuery.toLowerCase()) || _optionalChain([thread, 'access',
|
|
5387
|
+
(thread) => thread.title.toLowerCase().includes(searchQuery.toLowerCase()) || _optionalChain([thread, 'access', _142 => _142.preview, 'optionalAccess', _143 => _143.toLowerCase, 'call', _144 => _144(), 'access', _145 => _145.includes, 'call', _146 => _146(searchQuery.toLowerCase())])
|
|
4929
5388
|
);
|
|
4930
5389
|
const groupedThreads = groupBy === "date" ? groupThreadsByDate(filteredThreads) : { All: filteredThreads };
|
|
4931
5390
|
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col h-full", children: [
|
|
@@ -4947,8 +5406,8 @@ function ThreadList({
|
|
|
4947
5406
|
{
|
|
4948
5407
|
thread,
|
|
4949
5408
|
isActive: thread.id === currentThreadId,
|
|
4950
|
-
onSelect: () => _optionalChain([onThreadSelect, 'optionalCall',
|
|
4951
|
-
onDelete: () => _optionalChain([onThreadDelete, 'optionalCall',
|
|
5409
|
+
onSelect: () => _optionalChain([onThreadSelect, 'optionalCall', _147 => _147(thread.id)]),
|
|
5410
|
+
onDelete: () => _optionalChain([onThreadDelete, 'optionalCall', _148 => _148(thread.id)])
|
|
4952
5411
|
},
|
|
4953
5412
|
thread.id
|
|
4954
5413
|
))
|
|
@@ -5010,7 +5469,7 @@ function Threads({
|
|
|
5010
5469
|
threads.slice(0, 5).map((thread) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
5011
5470
|
"button",
|
|
5012
5471
|
{
|
|
5013
|
-
onClick: () => _optionalChain([onThreadSelect, 'optionalCall',
|
|
5472
|
+
onClick: () => _optionalChain([onThreadSelect, 'optionalCall', _149 => _149(thread.id)]),
|
|
5014
5473
|
className: cn(
|
|
5015
5474
|
"px-4 py-2 whitespace-nowrap font-medium transition-colors",
|
|
5016
5475
|
thread.id === currentThreadId ? "border-b-2 border-apteva-500 text-apteva-500" : "text-neutral-600 hover:text-neutral-900"
|
|
@@ -5052,6 +5511,418 @@ function Threads({
|
|
|
5052
5511
|
] });
|
|
5053
5512
|
}
|
|
5054
5513
|
|
|
5514
|
+
// src/components/AutoInterface/AutoInterface.tsx
|
|
5515
|
+
|
|
5516
|
+
|
|
5517
|
+
// src/components/AutoInterface/LayoutRenderer.tsx
|
|
5518
|
+
|
|
5519
|
+
|
|
5520
|
+
var gapClasses = {
|
|
5521
|
+
none: "gap-0",
|
|
5522
|
+
sm: "gap-2",
|
|
5523
|
+
md: "gap-4",
|
|
5524
|
+
lg: "gap-6"
|
|
5525
|
+
};
|
|
5526
|
+
var paddingClasses = {
|
|
5527
|
+
none: "p-0",
|
|
5528
|
+
sm: "p-2",
|
|
5529
|
+
md: "p-4",
|
|
5530
|
+
lg: "p-6"
|
|
5531
|
+
};
|
|
5532
|
+
var maxWidthClasses = {
|
|
5533
|
+
sm: "max-w-2xl",
|
|
5534
|
+
md: "max-w-4xl",
|
|
5535
|
+
lg: "max-w-6xl",
|
|
5536
|
+
xl: "max-w-7xl",
|
|
5537
|
+
full: "max-w-full"
|
|
5538
|
+
};
|
|
5539
|
+
function LayoutRenderer({ node, onAction, renderNode }) {
|
|
5540
|
+
const children = node.children || [];
|
|
5541
|
+
switch (node.layout) {
|
|
5542
|
+
case "page":
|
|
5543
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, PageLayout, { node, renderNode });
|
|
5544
|
+
case "row":
|
|
5545
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, RowLayout, { node, renderNode });
|
|
5546
|
+
case "columns":
|
|
5547
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ColumnsLayout, { node, renderNode });
|
|
5548
|
+
case "stack":
|
|
5549
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, StackLayout, { node, renderNode });
|
|
5550
|
+
case "sidebar":
|
|
5551
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SidebarLayout, { node, renderNode });
|
|
5552
|
+
case "tabs":
|
|
5553
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TabsLayout, { node, renderNode });
|
|
5554
|
+
default:
|
|
5555
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "space-y-4", children: children.map((child) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: renderNode(child) }, child.id)) });
|
|
5556
|
+
}
|
|
5557
|
+
}
|
|
5558
|
+
function PageLayout({ node, renderNode }) {
|
|
5559
|
+
const { title, padding = "md", maxWidth = "xl" } = node.props || {};
|
|
5560
|
+
const children = node.children || [];
|
|
5561
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: cn("w-full mx-auto", paddingClasses[padding], maxWidthClasses[maxWidth]), children: [
|
|
5562
|
+
title && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h1", { className: "!text-2xl font-bold !text-neutral-900 dark:!text-white mb-6", children: title }),
|
|
5563
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "space-y-6", children: children.map((child) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: renderNode(child) }, child.id)) })
|
|
5564
|
+
] });
|
|
5565
|
+
}
|
|
5566
|
+
function RowLayout({ node, renderNode }) {
|
|
5567
|
+
const { columns, gap = "md", align = "stretch" } = node.props || {};
|
|
5568
|
+
const children = node.children || [];
|
|
5569
|
+
const templateColumns = columns ? columns.map((c) => `${c}fr`).join(" ") : `repeat(${children.length}, 1fr)`;
|
|
5570
|
+
const alignClasses = {
|
|
5571
|
+
start: "items-start",
|
|
5572
|
+
center: "items-center",
|
|
5573
|
+
end: "items-end",
|
|
5574
|
+
stretch: "items-stretch"
|
|
5575
|
+
};
|
|
5576
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
5577
|
+
"div",
|
|
5578
|
+
{
|
|
5579
|
+
className: cn("grid", gapClasses[gap], alignClasses[align]),
|
|
5580
|
+
style: { gridTemplateColumns: templateColumns },
|
|
5581
|
+
children: children.map((child) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: renderNode(child) }, child.id))
|
|
5582
|
+
}
|
|
5583
|
+
);
|
|
5584
|
+
}
|
|
5585
|
+
function ColumnsLayout({ node, renderNode }) {
|
|
5586
|
+
const { count, gap = "md" } = node.props || {};
|
|
5587
|
+
const children = node.children || [];
|
|
5588
|
+
const colCount = count || children.length;
|
|
5589
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
5590
|
+
"div",
|
|
5591
|
+
{
|
|
5592
|
+
className: cn("grid", gapClasses[gap]),
|
|
5593
|
+
style: { gridTemplateColumns: `repeat(${colCount}, 1fr)` },
|
|
5594
|
+
children: children.map((child) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: renderNode(child) }, child.id))
|
|
5595
|
+
}
|
|
5596
|
+
);
|
|
5597
|
+
}
|
|
5598
|
+
function StackLayout({ node, renderNode }) {
|
|
5599
|
+
const { gap = "md", align = "stretch" } = node.props || {};
|
|
5600
|
+
const children = node.children || [];
|
|
5601
|
+
const alignClasses = {
|
|
5602
|
+
left: "items-start",
|
|
5603
|
+
center: "items-center",
|
|
5604
|
+
right: "items-end",
|
|
5605
|
+
stretch: "items-stretch"
|
|
5606
|
+
};
|
|
5607
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: cn("flex flex-col", gapClasses[gap], alignClasses[align]), children: children.map((child) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: renderNode(child) }, child.id)) });
|
|
5608
|
+
}
|
|
5609
|
+
function SidebarLayout({ node, renderNode }) {
|
|
5610
|
+
const { side = "left", width = "280px" } = node.props || {};
|
|
5611
|
+
const children = node.children || [];
|
|
5612
|
+
const [sidebarChild, ...mainChildren] = side === "left" ? children : [...children].reverse();
|
|
5613
|
+
if (!sidebarChild) return null;
|
|
5614
|
+
const sidebar = /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
5615
|
+
"div",
|
|
5616
|
+
{
|
|
5617
|
+
className: "flex-shrink-0 overflow-y-auto border-neutral-200 dark:border-neutral-700",
|
|
5618
|
+
style: { width },
|
|
5619
|
+
children: renderNode(sidebarChild)
|
|
5620
|
+
}
|
|
5621
|
+
);
|
|
5622
|
+
const main = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex-1 overflow-y-auto min-w-0", children: mainChildren.map((child) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: renderNode(child) }, child.id)) });
|
|
5623
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex h-full gap-4", children: side === "left" ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
5624
|
+
sidebar,
|
|
5625
|
+
main
|
|
5626
|
+
] }) : /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
5627
|
+
main,
|
|
5628
|
+
sidebar
|
|
5629
|
+
] }) });
|
|
5630
|
+
}
|
|
5631
|
+
function TabsLayout({ node, renderNode }) {
|
|
5632
|
+
const { labels = [], defaultTab = 0 } = node.props || {};
|
|
5633
|
+
const children = node.children || [];
|
|
5634
|
+
const [activeTab, setActiveTab] = _react.useState.call(void 0, defaultTab);
|
|
5635
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
|
|
5636
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex border-b border-neutral-200 dark:border-neutral-700 mb-4", children: labels.map((label, idx) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
5637
|
+
"button",
|
|
5638
|
+
{
|
|
5639
|
+
onClick: () => setActiveTab(idx),
|
|
5640
|
+
className: cn(
|
|
5641
|
+
"px-4 py-2 !text-sm font-medium transition-colors border-b-2 -mb-px",
|
|
5642
|
+
activeTab === idx ? "border-blue-500 !text-blue-600 dark:!text-blue-400" : "border-transparent !text-neutral-500 hover:!text-neutral-700 dark:hover:!text-neutral-300"
|
|
5643
|
+
),
|
|
5644
|
+
children: label
|
|
5645
|
+
},
|
|
5646
|
+
idx
|
|
5647
|
+
)) }),
|
|
5648
|
+
children[activeTab] && renderNode(children[activeTab])
|
|
5649
|
+
] });
|
|
5650
|
+
}
|
|
5651
|
+
|
|
5652
|
+
// src/components/AutoInterface/InterfaceRenderer.tsx
|
|
5653
|
+
|
|
5654
|
+
var STRUCTURAL_KEYS = /* @__PURE__ */ new Set(["type", "id", "layout", "props", "children", "actions", "metadata", "isStreaming"]);
|
|
5655
|
+
function normalizeNode(n) {
|
|
5656
|
+
let node = { ...n };
|
|
5657
|
+
if (node.type === "widget" && _optionalChain([node, 'access', _150 => _150.props, 'optionalAccess', _151 => _151.widget])) {
|
|
5658
|
+
node.type = node.props.widget;
|
|
5659
|
+
const { widget: _, ...rest } = node.props;
|
|
5660
|
+
node.props = rest;
|
|
5661
|
+
}
|
|
5662
|
+
const explicit = node.props || {};
|
|
5663
|
+
const extra = {};
|
|
5664
|
+
for (const key of Object.keys(node)) {
|
|
5665
|
+
if (!STRUCTURAL_KEYS.has(key)) {
|
|
5666
|
+
extra[key] = node[key];
|
|
5667
|
+
}
|
|
5668
|
+
}
|
|
5669
|
+
node.props = { ...extra, ...explicit };
|
|
5670
|
+
if (node.props.style && !node.props.variant) {
|
|
5671
|
+
node.props.variant = node.props.style;
|
|
5672
|
+
delete node.props.style;
|
|
5673
|
+
}
|
|
5674
|
+
if (node.children) {
|
|
5675
|
+
node.children = node.children.map(normalizeNode);
|
|
5676
|
+
}
|
|
5677
|
+
return node;
|
|
5678
|
+
}
|
|
5679
|
+
function InterfaceRenderer({ node, onAction }) {
|
|
5680
|
+
const renderNode = (rawNode) => {
|
|
5681
|
+
const n = normalizeNode(rawNode);
|
|
5682
|
+
if (n.type === "layout" && n.layout) {
|
|
5683
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
5684
|
+
LayoutRenderer,
|
|
5685
|
+
{
|
|
5686
|
+
node: n,
|
|
5687
|
+
onAction,
|
|
5688
|
+
renderNode
|
|
5689
|
+
},
|
|
5690
|
+
n.id
|
|
5691
|
+
);
|
|
5692
|
+
}
|
|
5693
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
5694
|
+
WidgetRenderer,
|
|
5695
|
+
{
|
|
5696
|
+
widget: {
|
|
5697
|
+
type: n.type,
|
|
5698
|
+
id: n.id,
|
|
5699
|
+
props: n.props || {},
|
|
5700
|
+
actions: n.actions,
|
|
5701
|
+
metadata: n.metadata,
|
|
5702
|
+
isStreaming: n.isStreaming
|
|
5703
|
+
},
|
|
5704
|
+
onAction
|
|
5705
|
+
},
|
|
5706
|
+
n.id
|
|
5707
|
+
);
|
|
5708
|
+
};
|
|
5709
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: renderNode(node) });
|
|
5710
|
+
}
|
|
5711
|
+
|
|
5712
|
+
// src/components/AutoInterface/InterfaceSkeleton.tsx
|
|
5713
|
+
|
|
5714
|
+
function InterfaceSkeleton({ className }) {
|
|
5715
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: cn("animate-pulse space-y-6 p-6", className), children: [
|
|
5716
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "h-7 bg-neutral-200 dark:bg-neutral-700 rounded w-1/3" }),
|
|
5717
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "grid grid-cols-4 gap-4", children: [1, 2, 3, 4].map((i) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "border border-neutral-200 dark:border-neutral-700 rounded-xl p-5 space-y-2", children: [
|
|
5718
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "h-4 bg-neutral-200 dark:bg-neutral-700 rounded w-2/3" }),
|
|
5719
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "h-8 bg-neutral-200 dark:bg-neutral-700 rounded w-1/2" })
|
|
5720
|
+
] }, i)) }),
|
|
5721
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "grid grid-cols-3 gap-4", children: [
|
|
5722
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "col-span-2 border border-neutral-200 dark:border-neutral-700 rounded-xl p-5 space-y-3", children: [
|
|
5723
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "h-4 bg-neutral-200 dark:bg-neutral-700 rounded w-1/4" }),
|
|
5724
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "h-40 bg-neutral-200 dark:bg-neutral-700 rounded" })
|
|
5725
|
+
] }),
|
|
5726
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "border border-neutral-200 dark:border-neutral-700 rounded-xl p-5 space-y-3", children: [
|
|
5727
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "h-4 bg-neutral-200 dark:bg-neutral-700 rounded w-1/2" }),
|
|
5728
|
+
[1, 2, 3].map((i) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "h-10 bg-neutral-200 dark:bg-neutral-700 rounded" }, i))
|
|
5729
|
+
] })
|
|
5730
|
+
] })
|
|
5731
|
+
] });
|
|
5732
|
+
}
|
|
5733
|
+
|
|
5734
|
+
// src/components/AutoInterface/AutoInterface.tsx
|
|
5735
|
+
|
|
5736
|
+
async function generateInitialInterface(apiUrl, apiKey, agentId, prompt) {
|
|
5737
|
+
const systemContext = generateCompactInterfaceContext();
|
|
5738
|
+
const message = `${systemContext}
|
|
5739
|
+
|
|
5740
|
+
Generate an interface for: ${prompt}`;
|
|
5741
|
+
const headers = { "Content-Type": "application/json" };
|
|
5742
|
+
if (apiKey) headers["X-API-Key"] = apiKey;
|
|
5743
|
+
const response = await fetch(`${apiUrl}/chat`, {
|
|
5744
|
+
method: "POST",
|
|
5745
|
+
headers,
|
|
5746
|
+
body: JSON.stringify({
|
|
5747
|
+
agent_id: agentId,
|
|
5748
|
+
message,
|
|
5749
|
+
stream: false
|
|
5750
|
+
})
|
|
5751
|
+
});
|
|
5752
|
+
if (!response.ok) {
|
|
5753
|
+
const err = await response.json().catch(() => ({ error: "Request failed" }));
|
|
5754
|
+
throw new Error(err.error || `Request failed with status ${response.status}`);
|
|
5755
|
+
}
|
|
5756
|
+
const data = await response.json();
|
|
5757
|
+
const text = data.response || data.message || "";
|
|
5758
|
+
console.log("[AutoInterface] Raw API response:", data);
|
|
5759
|
+
console.log("[AutoInterface] Extracted text (" + text.length + " chars):", text.substring(0, 500));
|
|
5760
|
+
const spec = parseInterfaceFromText(text);
|
|
5761
|
+
console.log("[AutoInterface] Parsed spec:", spec ? "OK" : "null", spec ? JSON.stringify(spec).substring(0, 300) + "..." : "");
|
|
5762
|
+
return { spec, threadId: data.thread_id || null };
|
|
5763
|
+
}
|
|
5764
|
+
function AutoInterface({
|
|
5765
|
+
agentId,
|
|
5766
|
+
threadId,
|
|
5767
|
+
initialPrompt,
|
|
5768
|
+
initialInterface,
|
|
5769
|
+
context,
|
|
5770
|
+
apiUrl,
|
|
5771
|
+
apiKey,
|
|
5772
|
+
onInterfaceChange,
|
|
5773
|
+
onAction,
|
|
5774
|
+
onThreadChange,
|
|
5775
|
+
onError,
|
|
5776
|
+
chatPosition = "right",
|
|
5777
|
+
chatWidth = "380px",
|
|
5778
|
+
chatCollapsible = true,
|
|
5779
|
+
chatPlaceholder = "Ask the AI to generate or update the interface...",
|
|
5780
|
+
chatWelcomeTitle = "Auto Interface",
|
|
5781
|
+
useMock,
|
|
5782
|
+
theme,
|
|
5783
|
+
className
|
|
5784
|
+
}) {
|
|
5785
|
+
const [interfaceSpec, setInterfaceSpec] = _react.useState.call(void 0, initialInterface || null);
|
|
5786
|
+
const [isGenerating, setIsGenerating] = _react.useState.call(void 0, false);
|
|
5787
|
+
const [chatCollapsed, setChatCollapsed] = _react.useState.call(void 0, false);
|
|
5788
|
+
const chatRef = _react.useRef.call(void 0, null);
|
|
5789
|
+
const systemContext = [
|
|
5790
|
+
generateInterfaceContext(),
|
|
5791
|
+
context || ""
|
|
5792
|
+
].filter(Boolean).join("\n\n");
|
|
5793
|
+
const updateInterface = _react.useCallback.call(void 0, (newSpec) => {
|
|
5794
|
+
setInterfaceSpec(newSpec);
|
|
5795
|
+
_optionalChain([onInterfaceChange, 'optionalCall', _152 => _152(newSpec)]);
|
|
5796
|
+
}, [onInterfaceChange]);
|
|
5797
|
+
const handleAction = _react.useCallback.call(void 0, (action) => {
|
|
5798
|
+
_optionalChain([onAction, 'optionalCall', _153 => _153(action)]);
|
|
5799
|
+
if (chatRef.current) {
|
|
5800
|
+
chatRef.current.sendMessage(
|
|
5801
|
+
`[Action: ${action.type} on widget ${action.widgetId || "unknown"}. Payload: ${JSON.stringify(action.payload)}]`
|
|
5802
|
+
);
|
|
5803
|
+
}
|
|
5804
|
+
}, [onAction]);
|
|
5805
|
+
const handleMessageComplete = _react.useCallback.call(void 0, (result) => {
|
|
5806
|
+
if (!_optionalChain([result, 'optionalAccess', _154 => _154.data])) return;
|
|
5807
|
+
const text = typeof result.data === "string" ? result.data : result.data.message || "";
|
|
5808
|
+
console.log("[AutoInterface] Chat message complete, text (" + text.length + " chars):", text.substring(0, 300));
|
|
5809
|
+
const parsed = parseInterfaceFromText(text);
|
|
5810
|
+
if (parsed) {
|
|
5811
|
+
console.log("[AutoInterface] Parsed full interface from chat");
|
|
5812
|
+
updateInterface(parsed);
|
|
5813
|
+
setIsGenerating(false);
|
|
5814
|
+
return;
|
|
5815
|
+
}
|
|
5816
|
+
const updates = parseUpdatesFromText(text);
|
|
5817
|
+
if (updates.length > 0 && interfaceSpec) {
|
|
5818
|
+
console.log("[AutoInterface] Parsed", updates.length, "updates from chat");
|
|
5819
|
+
const newSpec = applyUpdates(interfaceSpec, updates);
|
|
5820
|
+
updateInterface(newSpec);
|
|
5821
|
+
} else {
|
|
5822
|
+
console.log("[AutoInterface] No interface or updates found in chat message");
|
|
5823
|
+
}
|
|
5824
|
+
setIsGenerating(false);
|
|
5825
|
+
}, [interfaceSpec, updateInterface]);
|
|
5826
|
+
_react.useEffect.call(void 0, () => {
|
|
5827
|
+
if (!initialPrompt || initialInterface || useMock) return;
|
|
5828
|
+
if (!apiUrl) return;
|
|
5829
|
+
let cancelled = false;
|
|
5830
|
+
setIsGenerating(true);
|
|
5831
|
+
console.log("[AutoInterface] Generating initial interface for prompt:", initialPrompt);
|
|
5832
|
+
console.log("[AutoInterface] API URL:", apiUrl, "| Agent:", agentId);
|
|
5833
|
+
generateInitialInterface(apiUrl, apiKey, agentId, initialPrompt).then(({ spec, threadId: threadId2 }) => {
|
|
5834
|
+
if (cancelled) return;
|
|
5835
|
+
console.log("[AutoInterface] Generation complete. Spec:", spec ? "parsed OK" : "null", "| Thread:", threadId2);
|
|
5836
|
+
if (spec) {
|
|
5837
|
+
console.log("[AutoInterface] Setting interface with", JSON.stringify(spec).length, "bytes");
|
|
5838
|
+
updateInterface(spec);
|
|
5839
|
+
} else {
|
|
5840
|
+
console.warn("[AutoInterface] Agent did not return a parseable @interface block");
|
|
5841
|
+
}
|
|
5842
|
+
setIsGenerating(false);
|
|
5843
|
+
}).catch((err) => {
|
|
5844
|
+
if (cancelled) return;
|
|
5845
|
+
console.error("[AutoInterface] Initial generation failed:", err);
|
|
5846
|
+
_optionalChain([onError, 'optionalCall', _155 => _155(err instanceof Error ? err : new Error(String(err)))]);
|
|
5847
|
+
setIsGenerating(false);
|
|
5848
|
+
});
|
|
5849
|
+
return () => {
|
|
5850
|
+
cancelled = true;
|
|
5851
|
+
};
|
|
5852
|
+
}, [initialPrompt]);
|
|
5853
|
+
const hasInterface = interfaceSpec !== null;
|
|
5854
|
+
const showSkeleton = isGenerating && !hasInterface;
|
|
5855
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: cn(
|
|
5856
|
+
"flex h-full bg-neutral-50 dark:bg-black",
|
|
5857
|
+
chatPosition === "bottom" ? "flex-col" : "flex-row",
|
|
5858
|
+
className
|
|
5859
|
+
), children: [
|
|
5860
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: cn(
|
|
5861
|
+
"flex-1 overflow-y-auto min-w-0",
|
|
5862
|
+
hasInterface || showSkeleton ? "" : "hidden"
|
|
5863
|
+
), children: [
|
|
5864
|
+
showSkeleton && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, InterfaceSkeleton, {}),
|
|
5865
|
+
hasInterface && interfaceSpec && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "p-4", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
5866
|
+
InterfaceRenderer,
|
|
5867
|
+
{
|
|
5868
|
+
node: interfaceSpec.root,
|
|
5869
|
+
onAction: handleAction
|
|
5870
|
+
}
|
|
5871
|
+
) })
|
|
5872
|
+
] }),
|
|
5873
|
+
chatCollapsible && hasInterface && chatPosition === "right" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
5874
|
+
"button",
|
|
5875
|
+
{
|
|
5876
|
+
onClick: () => setChatCollapsed(!chatCollapsed),
|
|
5877
|
+
className: "flex-shrink-0 w-6 flex items-center justify-center border-l border-neutral-200 dark:border-neutral-700 bg-neutral-100 dark:bg-neutral-800 hover:bg-neutral-200 dark:hover:bg-neutral-700 transition-colors",
|
|
5878
|
+
title: chatCollapsed ? "Show chat" : "Hide chat",
|
|
5879
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "!text-xs !text-neutral-500 dark:!text-neutral-400", children: chatCollapsed ? "\u25C0" : "\u25B6" })
|
|
5880
|
+
}
|
|
5881
|
+
),
|
|
5882
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
5883
|
+
"div",
|
|
5884
|
+
{
|
|
5885
|
+
className: cn(
|
|
5886
|
+
"flex-shrink-0 border-neutral-200 dark:border-neutral-700",
|
|
5887
|
+
chatPosition === "right" ? "border-l" : "border-t",
|
|
5888
|
+
chatCollapsed && "hidden",
|
|
5889
|
+
// When no interface is generated yet, chat takes full width
|
|
5890
|
+
!hasInterface && !showSkeleton && "flex-1"
|
|
5891
|
+
),
|
|
5892
|
+
style: hasInterface || showSkeleton ? chatPosition === "right" ? { width: chatWidth } : { height: "300px" } : void 0,
|
|
5893
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
5894
|
+
Chat,
|
|
5895
|
+
{
|
|
5896
|
+
ref: chatRef,
|
|
5897
|
+
agentId,
|
|
5898
|
+
threadId,
|
|
5899
|
+
apiUrl,
|
|
5900
|
+
apiKey,
|
|
5901
|
+
useMock,
|
|
5902
|
+
context: systemContext,
|
|
5903
|
+
placeholder: chatPlaceholder,
|
|
5904
|
+
welcomeTitle: chatWelcomeTitle,
|
|
5905
|
+
welcomeSubtitle: "Describe the interface you want to create",
|
|
5906
|
+
enableStreaming: true,
|
|
5907
|
+
enableWidgets: true,
|
|
5908
|
+
showHeader: true,
|
|
5909
|
+
headerTitle: "Chat",
|
|
5910
|
+
onThreadChange,
|
|
5911
|
+
onComplete: handleMessageComplete,
|
|
5912
|
+
onError,
|
|
5913
|
+
className: "h-full",
|
|
5914
|
+
suggestedPrompts: !hasInterface ? [
|
|
5915
|
+
"Show me a sales dashboard",
|
|
5916
|
+
"Create a user management panel",
|
|
5917
|
+
"Build a project overview page"
|
|
5918
|
+
] : void 0
|
|
5919
|
+
}
|
|
5920
|
+
)
|
|
5921
|
+
}
|
|
5922
|
+
)
|
|
5923
|
+
] });
|
|
5924
|
+
}
|
|
5925
|
+
|
|
5055
5926
|
// src/utils/theme-script.ts
|
|
5056
5927
|
var themeScript = `
|
|
5057
5928
|
(function() {
|
|
@@ -5076,6 +5947,139 @@ function getThemeScript() {
|
|
|
5076
5947
|
return themeScript;
|
|
5077
5948
|
}
|
|
5078
5949
|
|
|
5950
|
+
// src/hooks/useInterfaceState.ts
|
|
5951
|
+
|
|
5952
|
+
function useInterfaceState(initialSpec) {
|
|
5953
|
+
const [spec, setSpec] = _react.useState.call(void 0, initialSpec || null);
|
|
5954
|
+
const [isStreaming, setIsStreaming] = _react.useState.call(void 0, false);
|
|
5955
|
+
const setInterface = _react.useCallback.call(void 0, (newSpec) => {
|
|
5956
|
+
setSpec(newSpec);
|
|
5957
|
+
}, []);
|
|
5958
|
+
const clearInterface = _react.useCallback.call(void 0, () => {
|
|
5959
|
+
setSpec(null);
|
|
5960
|
+
}, []);
|
|
5961
|
+
const applyInterfaceUpdate = _react.useCallback.call(void 0, (update) => {
|
|
5962
|
+
setSpec((prev) => {
|
|
5963
|
+
if (!prev) return prev;
|
|
5964
|
+
return applyUpdate(prev, update);
|
|
5965
|
+
});
|
|
5966
|
+
}, []);
|
|
5967
|
+
const applyInterfaceUpdates = _react.useCallback.call(void 0, (updates) => {
|
|
5968
|
+
setSpec((prev) => {
|
|
5969
|
+
if (!prev) return prev;
|
|
5970
|
+
return applyUpdates(prev, updates);
|
|
5971
|
+
});
|
|
5972
|
+
}, []);
|
|
5973
|
+
const getNode = _react.useCallback.call(void 0, (id) => {
|
|
5974
|
+
if (!spec) return null;
|
|
5975
|
+
return findNode(spec.root, id);
|
|
5976
|
+
}, [spec]);
|
|
5977
|
+
return {
|
|
5978
|
+
spec,
|
|
5979
|
+
isStreaming,
|
|
5980
|
+
setInterface,
|
|
5981
|
+
clearInterface,
|
|
5982
|
+
applyInterfaceUpdate,
|
|
5983
|
+
applyInterfaceUpdates,
|
|
5984
|
+
setIsStreaming,
|
|
5985
|
+
getNode
|
|
5986
|
+
};
|
|
5987
|
+
}
|
|
5988
|
+
|
|
5989
|
+
// src/hooks/useInterfaceAI.ts
|
|
5990
|
+
|
|
5991
|
+
function useInterfaceAI({
|
|
5992
|
+
agentId,
|
|
5993
|
+
apiUrl,
|
|
5994
|
+
apiKey,
|
|
5995
|
+
context,
|
|
5996
|
+
onInterface,
|
|
5997
|
+
onUpdates,
|
|
5998
|
+
onError,
|
|
5999
|
+
onStreamStart,
|
|
6000
|
+
onStreamEnd
|
|
6001
|
+
}) {
|
|
6002
|
+
const threadIdRef = _react.useRef.call(void 0, null);
|
|
6003
|
+
const accumulatedTextRef = _react.useRef.call(void 0, "");
|
|
6004
|
+
if (apiUrl || apiKey) {
|
|
6005
|
+
aptevaClient.configure({
|
|
6006
|
+
...apiUrl && { apiUrl },
|
|
6007
|
+
...apiKey && { apiKey }
|
|
6008
|
+
});
|
|
6009
|
+
}
|
|
6010
|
+
const sendMessage = _react.useCallback.call(void 0, async (message) => {
|
|
6011
|
+
accumulatedTextRef.current = "";
|
|
6012
|
+
_optionalChain([onStreamStart, 'optionalCall', _156 => _156()]);
|
|
6013
|
+
const systemPrompt = [
|
|
6014
|
+
generateInterfaceContext(),
|
|
6015
|
+
context || ""
|
|
6016
|
+
].filter(Boolean).join("\n\n");
|
|
6017
|
+
try {
|
|
6018
|
+
await aptevaClient.chatStream(
|
|
6019
|
+
{
|
|
6020
|
+
agent_id: agentId,
|
|
6021
|
+
message,
|
|
6022
|
+
thread_id: threadIdRef.current || void 0,
|
|
6023
|
+
stream: true,
|
|
6024
|
+
system: systemPrompt
|
|
6025
|
+
},
|
|
6026
|
+
// onChunk
|
|
6027
|
+
(chunk) => {
|
|
6028
|
+
if (chunk.thread_id) {
|
|
6029
|
+
threadIdRef.current = chunk.thread_id;
|
|
6030
|
+
}
|
|
6031
|
+
if (chunk.type === "content" || chunk.type === "token") {
|
|
6032
|
+
accumulatedTextRef.current += chunk.content || "";
|
|
6033
|
+
const parsed = parseInterfaceFromText(accumulatedTextRef.current);
|
|
6034
|
+
if (parsed) {
|
|
6035
|
+
_optionalChain([onInterface, 'optionalCall', _157 => _157(parsed)]);
|
|
6036
|
+
}
|
|
6037
|
+
const updates = parseUpdatesFromText(accumulatedTextRef.current);
|
|
6038
|
+
if (updates.length > 0) {
|
|
6039
|
+
_optionalChain([onUpdates, 'optionalCall', _158 => _158(updates)]);
|
|
6040
|
+
}
|
|
6041
|
+
}
|
|
6042
|
+
},
|
|
6043
|
+
// onComplete
|
|
6044
|
+
() => {
|
|
6045
|
+
_optionalChain([onStreamEnd, 'optionalCall', _159 => _159()]);
|
|
6046
|
+
},
|
|
6047
|
+
// onError
|
|
6048
|
+
(error) => {
|
|
6049
|
+
_optionalChain([onError, 'optionalCall', _160 => _160(error)]);
|
|
6050
|
+
_optionalChain([onStreamEnd, 'optionalCall', _161 => _161()]);
|
|
6051
|
+
}
|
|
6052
|
+
);
|
|
6053
|
+
} catch (error) {
|
|
6054
|
+
_optionalChain([onError, 'optionalCall', _162 => _162(error instanceof Error ? error : new Error("Unknown error"))]);
|
|
6055
|
+
_optionalChain([onStreamEnd, 'optionalCall', _163 => _163()]);
|
|
6056
|
+
}
|
|
6057
|
+
}, [agentId, context, onInterface, onUpdates, onError, onStreamStart, onStreamEnd]);
|
|
6058
|
+
return {
|
|
6059
|
+
sendMessage,
|
|
6060
|
+
threadId: threadIdRef.current
|
|
6061
|
+
};
|
|
6062
|
+
}
|
|
6063
|
+
|
|
6064
|
+
|
|
6065
|
+
|
|
6066
|
+
|
|
6067
|
+
|
|
6068
|
+
|
|
6069
|
+
|
|
6070
|
+
|
|
6071
|
+
|
|
6072
|
+
|
|
6073
|
+
|
|
6074
|
+
|
|
6075
|
+
|
|
6076
|
+
|
|
6077
|
+
|
|
6078
|
+
|
|
6079
|
+
|
|
6080
|
+
|
|
6081
|
+
|
|
6082
|
+
|
|
5079
6083
|
|
|
5080
6084
|
|
|
5081
6085
|
|
|
@@ -5092,5 +6096,5 @@ function getThemeScript() {
|
|
|
5092
6096
|
|
|
5093
6097
|
|
|
5094
6098
|
|
|
5095
|
-
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;
|
|
6099
|
+
exports.AptevaClient = AptevaClient; exports.AutoInterface = AutoInterface; exports.Button = Button; exports.Card = Card; exports.Chat = Chat; exports.Command = Command; exports.InterfaceRenderer = InterfaceRenderer; exports.InterfaceSkeleton = InterfaceSkeleton; exports.Kpi = Kpi; exports.LayoutRenderer = LayoutRenderer; exports.List = List; exports.Prompt = Prompt; exports.Spacer = Spacer; exports.Stream = Stream; exports.TextBlock = TextBlock; exports.Threads = Threads; exports.Widgets = Widgets; exports.applyUpdate = applyUpdate; exports.applyUpdates = applyUpdates; exports.aptevaClient = aptevaClient; exports.cn = cn; exports.containsInterface = containsInterface; exports.convertApiMessages = convertApiMessages; exports.findNode = findNode; exports.generateCompactInterfaceContext = generateCompactInterfaceContext; exports.generateInterfaceContext = generateInterfaceContext; exports.getThemeScript = getThemeScript; exports.mockMessages = mockMessages; exports.mockThreads = mockThreads; exports.mockWidgets = mockWidgets; exports.parseInterfaceFromText = parseInterfaceFromText; exports.parseUpdatesFromText = parseUpdatesFromText; exports.stripInterface = stripInterface; exports.useInterfaceAI = useInterfaceAI; exports.useInterfaceState = useInterfaceState;
|
|
5096
6100
|
//# sourceMappingURL=index.js.map
|