@apteva/apteva-kit 0.1.32 → 0.1.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +91 -70
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
|
|
6
6
|
// src/components/Chat/Chat.tsx
|
|
7
|
-
import { useState as useState3, useEffect as useEffect4, useRef as useRef5, useMemo as useMemo2 } from "react";
|
|
7
|
+
import { useState as useState3, useEffect as useEffect4, useRef as useRef5, useMemo as useMemo2, forwardRef, useImperativeHandle } from "react";
|
|
8
8
|
|
|
9
9
|
// src/components/Chat/MessageList.tsx
|
|
10
10
|
import { useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
@@ -2256,7 +2256,7 @@ var aptevaClient = new AptevaClient();
|
|
|
2256
2256
|
|
|
2257
2257
|
// src/components/Chat/Chat.tsx
|
|
2258
2258
|
import { Fragment as Fragment4, jsx as jsx16, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
2259
|
-
|
|
2259
|
+
var Chat = forwardRef(function Chat2({
|
|
2260
2260
|
agentId,
|
|
2261
2261
|
threadId,
|
|
2262
2262
|
initialMessages = [],
|
|
@@ -2288,6 +2288,7 @@ function Chat({
|
|
|
2288
2288
|
onFileUpload,
|
|
2289
2289
|
onComplete,
|
|
2290
2290
|
onError,
|
|
2291
|
+
onToolCall,
|
|
2291
2292
|
onToolResult,
|
|
2292
2293
|
// UI
|
|
2293
2294
|
placeholder,
|
|
@@ -2299,7 +2300,7 @@ function Chat({
|
|
|
2299
2300
|
compactWidgetContext = false,
|
|
2300
2301
|
onWidgetRender,
|
|
2301
2302
|
className
|
|
2302
|
-
}) {
|
|
2303
|
+
}, ref) {
|
|
2303
2304
|
const [messages, setMessages] = useState3(initialMessages);
|
|
2304
2305
|
const [isLoading, setIsLoading] = useState3(false);
|
|
2305
2306
|
const [currentThreadId, setCurrentThreadId] = useState3(threadId || null);
|
|
@@ -2318,6 +2319,21 @@ function Chat({
|
|
|
2318
2319
|
const [internalPlanMode, setInternalPlanMode] = useState3(planMode);
|
|
2319
2320
|
const [showSettingsMenu, setShowSettingsMenu] = useState3(false);
|
|
2320
2321
|
const fileInputRef = useRef5(null);
|
|
2322
|
+
const handleSendMessageRef = useRef5(null);
|
|
2323
|
+
useImperativeHandle(ref, () => ({
|
|
2324
|
+
sendMessage: async (text) => {
|
|
2325
|
+
if (handleSendMessageRef.current) {
|
|
2326
|
+
await handleSendMessageRef.current(text);
|
|
2327
|
+
}
|
|
2328
|
+
},
|
|
2329
|
+
sendSystemMessage: async (text) => {
|
|
2330
|
+
if (handleSendMessageRef.current) {
|
|
2331
|
+
await handleSendMessageRef.current(text, void 0, true);
|
|
2332
|
+
}
|
|
2333
|
+
},
|
|
2334
|
+
getMessages: () => messages,
|
|
2335
|
+
clearMessages: () => setMessages([])
|
|
2336
|
+
}), [messages]);
|
|
2321
2337
|
const effectiveContext = useMemo2(() => {
|
|
2322
2338
|
if (!enableWidgets) return context;
|
|
2323
2339
|
const widgetContext = compactWidgetContext ? generateCompactWidgetContext(availableWidgets) : generateWidgetContext(availableWidgets);
|
|
@@ -2360,19 +2376,21 @@ ${widgetContext}` : widgetContext;
|
|
|
2360
2376
|
}
|
|
2361
2377
|
};
|
|
2362
2378
|
const defaultPlaceholder = mode === "chat" ? "Type a message..." : "Enter your command...";
|
|
2363
|
-
const handleSendMessage = async (text, files) => {
|
|
2379
|
+
const handleSendMessage = async (text, files, isSystem) => {
|
|
2364
2380
|
const hasFiles = files && files.length > 0;
|
|
2365
2381
|
const fileNames = hasFiles ? files.map((f) => f.name) : [];
|
|
2366
2382
|
const displayContent = hasFiles ? `${text}${text ? "\n" : ""}[Attached: ${fileNames.join(", ")}]` : text;
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2383
|
+
if (!isSystem) {
|
|
2384
|
+
const userMessage = {
|
|
2385
|
+
id: `msg-${Date.now()}`,
|
|
2386
|
+
role: "user",
|
|
2387
|
+
content: displayContent,
|
|
2388
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
2389
|
+
metadata: hasFiles ? { attachments: fileNames } : void 0
|
|
2390
|
+
};
|
|
2391
|
+
setMessages((prev) => [...prev, userMessage]);
|
|
2392
|
+
onMessageSent?.(userMessage);
|
|
2393
|
+
}
|
|
2376
2394
|
setIsLoading(true);
|
|
2377
2395
|
try {
|
|
2378
2396
|
const messagePayload = await buildMessageWithAttachments(text, files);
|
|
@@ -2463,6 +2481,7 @@ ${widgetContext}` : widgetContext;
|
|
|
2463
2481
|
contentSegments.push({ type: "tool", id: chunk.tool_id, name: chunk.tool_name });
|
|
2464
2482
|
toolInputBuffer = "";
|
|
2465
2483
|
setChatToolName(chunk.tool_name);
|
|
2484
|
+
onToolCall?.(chunk.tool_name, chunk.tool_id);
|
|
2466
2485
|
updateMessage();
|
|
2467
2486
|
}
|
|
2468
2487
|
break;
|
|
@@ -2561,6 +2580,7 @@ ${widgetContext}` : widgetContext;
|
|
|
2561
2580
|
setIsLoading(false);
|
|
2562
2581
|
}
|
|
2563
2582
|
};
|
|
2583
|
+
handleSendMessageRef.current = handleSendMessage;
|
|
2564
2584
|
const executeCommand = async (commandOverride, files) => {
|
|
2565
2585
|
const currentCommand = commandOverride || commandInput;
|
|
2566
2586
|
if (!currentCommand.trim() && (!files || files.length === 0)) {
|
|
@@ -2681,6 +2701,7 @@ ${commandInstruction}` : commandInstruction;
|
|
|
2681
2701
|
} else if (chunk.type === "tool_call" && chunk.tool_name) {
|
|
2682
2702
|
lastToolName = chunk.tool_name;
|
|
2683
2703
|
setCurrentToolName(chunk.tool_name);
|
|
2704
|
+
onToolCall?.(chunk.tool_name, chunk.tool_id || "");
|
|
2684
2705
|
accumulatedContent = "";
|
|
2685
2706
|
setStreamedContent("");
|
|
2686
2707
|
} else if (chunk.type === "tool_result") {
|
|
@@ -2858,7 +2879,7 @@ ${planToExecute}`;
|
|
|
2858
2879
|
`
|
|
2859
2880
|
} })
|
|
2860
2881
|
] });
|
|
2861
|
-
}
|
|
2882
|
+
});
|
|
2862
2883
|
|
|
2863
2884
|
// src/components/Chat/CommandOutput.tsx
|
|
2864
2885
|
import { useState as useState4 } from "react";
|