@blade-hq/agent-react 2610.0.6 → 2610.0.7
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/README.md
CHANGED
|
@@ -33,6 +33,8 @@ export function App() {
|
|
|
33
33
|
- 不传 `sessionId` 自动创建新会话;未登录时 `ChatView` 自己渲染登录按钮(弹窗授权,见 agent-client 的 `client.auth.login()`)。
|
|
34
34
|
- 同一 `BladeProvider` 下可以放多个 `ChatView`,各自独立会话、互不干扰。
|
|
35
35
|
|
|
36
|
+
智能体会话的输入框提供「添加附件」按钮。选中的文件会上传到当前会话工作区,发送时随消息附上文件路径。
|
|
37
|
+
|
|
36
38
|
## BladeProvider
|
|
37
39
|
|
|
38
40
|
只负责 client 级共享(一条 Socket 连接、一份鉴权),不含任何全局状态。
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
1
2
|
interface Props {
|
|
2
3
|
/** 受控输入内容(由 ChatView 持有,便于 attach/insertText 注入)。 */
|
|
3
4
|
value: string;
|
|
@@ -28,11 +29,13 @@ interface Props {
|
|
|
28
29
|
toolbarClassName?: string;
|
|
29
30
|
queueKey?: string;
|
|
30
31
|
hasAttachments?: boolean;
|
|
32
|
+
attachmentPicker?: ReactNode;
|
|
33
|
+
attachmentsBlocked?: boolean;
|
|
31
34
|
}
|
|
32
35
|
/**
|
|
33
36
|
* 轻量聊天输入框:textarea(Enter 发送 / Shift+Enter 换行)+ 发送/停止按钮。
|
|
34
37
|
* 不含第一方版本的富文本编辑、@ 补全、技能菜单、语音输入与模型选择。
|
|
35
38
|
* 内容受控,session.attach() / insertText() 通过 ChatView 注入到这里。
|
|
36
39
|
*/
|
|
37
|
-
export declare function ChatInput({ value, onValueChange, onSend, onStop, isStreaming, isStopping, queueWhileRunning, mergesWithPanelAbove, placeholder, className, innerClassName, textareaClassName, toolbarClassName, queueKey, hasAttachments, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
40
|
+
export declare function ChatInput({ value, onValueChange, onSend, onStop, isStreaming, isStopping, queueWhileRunning, mergesWithPanelAbove, placeholder, className, innerClassName, textareaClassName, toolbarClassName, queueKey, hasAttachments, attachmentPicker, attachmentsBlocked, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
38
41
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AskUserAnswerData, ChatMessage, ConnectionStatus, PostChatFollowup } from "@blade-hq/agent-client";
|
|
1
|
+
import type { AskUserAnswerData, BladeClient, ChatMessage, ConnectionStatus, PostChatFollowup } from "@blade-hq/agent-client";
|
|
2
2
|
import { type ReactNode } from "react";
|
|
3
3
|
import type { TurnNavigationSource } from "../hooks/use-turn-navigation";
|
|
4
4
|
import type { ToolCallRenderer } from "./ToolCallBlock";
|
|
@@ -146,7 +146,8 @@ interface ChatSurfaceProps extends ChatPresentationProps {
|
|
|
146
146
|
inputText: string;
|
|
147
147
|
onInputChange: (value: string) => void;
|
|
148
148
|
onSuggestion?: (value: string) => void;
|
|
149
|
-
onSend: (text: string) => Promise<boolean>;
|
|
149
|
+
onSend: (text: string, hasAttachments?: boolean) => Promise<boolean>;
|
|
150
|
+
uploadFiles?: BladeClient["sessions"]["uploadFiles"];
|
|
150
151
|
onStop: () => void;
|
|
151
152
|
sessionStatus?: string;
|
|
152
153
|
askAnswers?: Record<string, AskUserAnswerData>;
|
|
@@ -195,5 +196,5 @@ interface ChatSurfaceProps extends ChatPresentationProps {
|
|
|
195
196
|
* 这里的 DOM 结构受 tests/chat-view-compat.test.tsx 的快照保护——接入方拿
|
|
196
197
|
* .blade-chat-* 类名写了自己的样式,结构一动他们的页面就歪。
|
|
197
198
|
*/
|
|
198
|
-
export declare function ChatSurface({ theme, classNames, renderers, slots, placeholder, connection, errorMessage, messages, postChatFollowup, isStreaming, isStopping, inputText, onInputChange, onSuggestion, onSend, onStop, sessionStatus, askAnswers, onAnswer, sessionId, isViewer, resultFeedbackByEntry, onResultFeedbackSaved, onFollowupInteraction, beforeInput, queuePanel, queuePanelVisible, showPlanUpdates, planRevealRevision, historyPaging, turnNavigation, banner, onRevealingChange, isReplay, }: ChatSurfaceProps): import("react/jsx-runtime").JSX.Element;
|
|
199
|
+
export declare function ChatSurface({ theme, classNames, renderers, slots, placeholder, connection, errorMessage, messages, postChatFollowup, isStreaming, isStopping, inputText, onInputChange, onSuggestion, onSend, uploadFiles, onStop, sessionStatus, askAnswers, onAnswer, sessionId, isViewer, resultFeedbackByEntry, onResultFeedbackSaved, onFollowupInteraction, beforeInput, queuePanel, queuePanelVisible, showPlanUpdates, planRevealRevision, historyPaging, turnNavigation, banner, onRevealingChange, isReplay, }: ChatSurfaceProps): import("react/jsx-runtime").JSX.Element;
|
|
199
200
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1550,7 +1550,7 @@ var require_react_is_development = __commonJS({
|
|
|
1550
1550
|
var ContextProvider = REACT_PROVIDER_TYPE;
|
|
1551
1551
|
var Element2 = REACT_ELEMENT_TYPE;
|
|
1552
1552
|
var ForwardRef = REACT_FORWARD_REF_TYPE;
|
|
1553
|
-
var
|
|
1553
|
+
var Fragment13 = REACT_FRAGMENT_TYPE;
|
|
1554
1554
|
var Lazy = REACT_LAZY_TYPE;
|
|
1555
1555
|
var Memo = REACT_MEMO_TYPE;
|
|
1556
1556
|
var Portal3 = REACT_PORTAL_TYPE;
|
|
@@ -1618,7 +1618,7 @@ var require_react_is_development = __commonJS({
|
|
|
1618
1618
|
exports.ContextProvider = ContextProvider;
|
|
1619
1619
|
exports.Element = Element2;
|
|
1620
1620
|
exports.ForwardRef = ForwardRef;
|
|
1621
|
-
exports.Fragment =
|
|
1621
|
+
exports.Fragment = Fragment13;
|
|
1622
1622
|
exports.Lazy = Lazy;
|
|
1623
1623
|
exports.Memo = Memo;
|
|
1624
1624
|
exports.Portal = Portal3;
|
|
@@ -3315,6 +3315,18 @@ var Minimize2 = createLucideIcon("Minimize2", [
|
|
|
3315
3315
|
["line", { x1: "3", x2: "10", y1: "21", y2: "14", key: "1atl0r" }]
|
|
3316
3316
|
]);
|
|
3317
3317
|
|
|
3318
|
+
// ../../node_modules/.pnpm/lucide-react@0.468.0_react@19.2.4/node_modules/lucide-react/dist/esm/icons/paperclip.js
|
|
3319
|
+
var Paperclip = createLucideIcon("Paperclip", [
|
|
3320
|
+
["path", { d: "M13.234 20.252 21 12.3", key: "1cbrk9" }],
|
|
3321
|
+
[
|
|
3322
|
+
"path",
|
|
3323
|
+
{
|
|
3324
|
+
d: "m16 6-8.414 8.586a2 2 0 0 0 0 2.828 2 2 0 0 0 2.828 0l8.414-8.586a4 4 0 0 0 0-5.656 4 4 0 0 0-5.656 0l-8.415 8.585a6 6 0 1 0 8.486 8.486",
|
|
3325
|
+
key: "1pkts6"
|
|
3326
|
+
}
|
|
3327
|
+
]
|
|
3328
|
+
]);
|
|
3329
|
+
|
|
3318
3330
|
// ../../node_modules/.pnpm/lucide-react@0.468.0_react@19.2.4/node_modules/lucide-react/dist/esm/icons/pencil.js
|
|
3319
3331
|
var Pencil = createLucideIcon("Pencil", [
|
|
3320
3332
|
[
|
|
@@ -3449,7 +3461,7 @@ var X = createLucideIcon("X", [
|
|
|
3449
3461
|
]);
|
|
3450
3462
|
|
|
3451
3463
|
// src/components/AgentChat.tsx
|
|
3452
|
-
import { useCallback as useCallback30, useEffect as useEffect28, useMemo as useMemo18, useRef as
|
|
3464
|
+
import { useCallback as useCallback30, useEffect as useEffect28, useMemo as useMemo18, useRef as useRef31, useState as useState37 } from "react";
|
|
3453
3465
|
|
|
3454
3466
|
// src/components/SessionPluginSelector.tsx
|
|
3455
3467
|
import { useEffect as useEffect15, useState as useState20 } from "react";
|
|
@@ -21007,8 +21019,8 @@ function CurrentPlanPanel({
|
|
|
21007
21019
|
}
|
|
21008
21020
|
|
|
21009
21021
|
// src/components/ChatSurface.tsx
|
|
21010
|
-
import { chatErrorForDisplay as chatErrorForDisplay2 } from "@blade-hq/agent-client";
|
|
21011
|
-
import { useMemo as useMemo17, useState as useState36 } from "react";
|
|
21022
|
+
import { buildMessageContent, chatErrorForDisplay as chatErrorForDisplay2, getTextContent as getTextContent4 } from "@blade-hq/agent-client";
|
|
21023
|
+
import { useMemo as useMemo17, useRef as useRef30, useState as useState36 } from "react";
|
|
21012
21024
|
|
|
21013
21025
|
// src/lib/random-id.ts
|
|
21014
21026
|
function randomId() {
|
|
@@ -46244,7 +46256,9 @@ function ChatInput({
|
|
|
46244
46256
|
textareaClassName,
|
|
46245
46257
|
toolbarClassName,
|
|
46246
46258
|
queueKey,
|
|
46247
|
-
hasAttachments = false
|
|
46259
|
+
hasAttachments = false,
|
|
46260
|
+
attachmentPicker,
|
|
46261
|
+
attachmentsBlocked = false
|
|
46248
46262
|
}) {
|
|
46249
46263
|
const trimmed = value.trim();
|
|
46250
46264
|
const latestValue = useRef19(value);
|
|
@@ -46252,7 +46266,7 @@ function ChatInput({
|
|
|
46252
46266
|
const sending = useRef19(false);
|
|
46253
46267
|
const [isSending2, setIsSending] = useState25(false);
|
|
46254
46268
|
void queueKey;
|
|
46255
|
-
const canSend = !isSending2 && (trimmed.length > 0 || hasAttachments) && (!isStreaming || queueWhileRunning && !hasAttachments && !isStopping);
|
|
46269
|
+
const canSend = !isSending2 && !attachmentsBlocked && (trimmed.length > 0 || hasAttachments) && (!isStreaming || queueWhileRunning && !hasAttachments && !isStopping);
|
|
46256
46270
|
const handleSend = async () => {
|
|
46257
46271
|
if (!canSend || sending.current) return;
|
|
46258
46272
|
sending.current = true;
|
|
@@ -46321,21 +46335,24 @@ function ChatInput({
|
|
|
46321
46335
|
)
|
|
46322
46336
|
}
|
|
46323
46337
|
),
|
|
46324
|
-
/* @__PURE__ */
|
|
46325
|
-
|
|
46326
|
-
|
|
46327
|
-
|
|
46328
|
-
|
|
46329
|
-
|
|
46330
|
-
|
|
46331
|
-
|
|
46332
|
-
|
|
46333
|
-
|
|
46334
|
-
|
|
46335
|
-
|
|
46336
|
-
|
|
46337
|
-
|
|
46338
|
-
|
|
46338
|
+
/* @__PURE__ */ jsxs11("div", { part: "input-toolbar", className: cn("blade-chat-input-toolbar flex shrink-0 items-center gap-2", toolbarClassName), children: [
|
|
46339
|
+
attachmentPicker,
|
|
46340
|
+
isStreaming ? /* @__PURE__ */ jsxs11(Fragment5, { children: [
|
|
46341
|
+
queueWhileRunning ? /* @__PURE__ */ jsx14("button", { type: "button", onClick: handleSend, disabled: !canSend, "aria-label": "\u52A0\u5165\u6392\u961F", title: "\u52A0\u5165\u6392\u961F", className: "flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-[hsl(var(--primary))] text-[hsl(var(--primary-foreground))] disabled:opacity-40", children: /* @__PURE__ */ jsx14(ArrowUp, { size: 15 }) }) : null,
|
|
46342
|
+
/* @__PURE__ */ jsx14("button", { type: "button", onClick: onStop, disabled: isStopping, "aria-label": isStopping ? "\u6B63\u5728\u505C\u6B62" : "\u505C\u6B62\u56DE\u590D", title: isStopping ? "\u6B63\u5728\u505C\u6B62" : "\u505C\u6B62\u56DE\u590D", className: "flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-[hsl(var(--muted))] text-[hsl(var(--foreground))] transition-opacity hover:opacity-90 disabled:opacity-60", children: isStopping ? /* @__PURE__ */ jsx14(LoaderCircle, { size: 14, className: "animate-spin" }) : /* @__PURE__ */ jsx14(Square, { size: 12, fill: "currentColor" }) })
|
|
46343
|
+
] }) : /* @__PURE__ */ jsx14(
|
|
46344
|
+
"button",
|
|
46345
|
+
{
|
|
46346
|
+
type: "button",
|
|
46347
|
+
onClick: handleSend,
|
|
46348
|
+
disabled: !canSend,
|
|
46349
|
+
"aria-label": "\u53D1\u9001\u6D88\u606F",
|
|
46350
|
+
title: "\u53D1\u9001\u6D88\u606F",
|
|
46351
|
+
className: "flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-[hsl(var(--primary))] text-[hsl(var(--primary-foreground))] transition-opacity hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-40",
|
|
46352
|
+
children: /* @__PURE__ */ jsx14(ArrowUp, { size: 15 })
|
|
46353
|
+
}
|
|
46354
|
+
)
|
|
46355
|
+
] })
|
|
46339
46356
|
]
|
|
46340
46357
|
}
|
|
46341
46358
|
)
|
|
@@ -46947,7 +46964,11 @@ import {
|
|
|
46947
46964
|
getTextContent as getTextContent2,
|
|
46948
46965
|
normalizeMessageContent as normalizeMessageContent2
|
|
46949
46966
|
} from "@blade-hq/agent-client";
|
|
46950
|
-
import { useEffect as useEffect25, useRef as useRef27, useState as useState33 } from "react";
|
|
46967
|
+
import { useContext as useContext6, useEffect as useEffect25, useRef as useRef27, useState as useState33 } from "react";
|
|
46968
|
+
|
|
46969
|
+
// src/components/ExecutionProcessContext.ts
|
|
46970
|
+
import { createContext as createContext6 } from "react";
|
|
46971
|
+
var KeepToolStepsOpenContext = createContext6(false);
|
|
46951
46972
|
|
|
46952
46973
|
// src/components/AgentTaskCard.tsx
|
|
46953
46974
|
import { useEffect as useEffect22, useState as useState29 } from "react";
|
|
@@ -56038,6 +56059,29 @@ var MARKDOWN_COMPONENTS = {
|
|
|
56038
56059
|
a: ExternalAnchor
|
|
56039
56060
|
};
|
|
56040
56061
|
function MarkdownContent({ children, className, mode, sessionId }) {
|
|
56062
|
+
const client = useOptionalBladeClient();
|
|
56063
|
+
const components = useMemo14(() => {
|
|
56064
|
+
if (!client || !sessionId) return MARKDOWN_COMPONENTS;
|
|
56065
|
+
return {
|
|
56066
|
+
...MARKDOWN_COMPONENTS,
|
|
56067
|
+
a: (anchorProps) => {
|
|
56068
|
+
const href = anchorProps.href ?? "";
|
|
56069
|
+
const path2 = href.split(/[?#]/, 1)[0];
|
|
56070
|
+
if (!/\.docx$/i.test(path2) || /^(?:[a-z][a-z0-9+.-]*:|[\/#])|\\|(?:^|\/)\.\.(?:\/|$)|%2e|%2f|%5c/i.test(path2)) {
|
|
56071
|
+
return /* @__PURE__ */ jsx20(ExternalAnchor, { ...anchorProps });
|
|
56072
|
+
}
|
|
56073
|
+
let filename = path2.replace(/^\.\//, "");
|
|
56074
|
+
try {
|
|
56075
|
+
filename = decodeURIComponent(filename);
|
|
56076
|
+
} catch {
|
|
56077
|
+
}
|
|
56078
|
+
const fileUrl = client.buildAuthedUrl(
|
|
56079
|
+
`/api/sessions/${encodeURIComponent(sessionId)}/files/${encodeURIComponent(filename)}`
|
|
56080
|
+
);
|
|
56081
|
+
return /* @__PURE__ */ jsx20("a", { ...anchorProps, href: fileUrl, download: true });
|
|
56082
|
+
}
|
|
56083
|
+
};
|
|
56084
|
+
}, [client, sessionId]);
|
|
56041
56085
|
const resolvedChildren = useMemo14(() => {
|
|
56042
56086
|
return normalizeAdjacentUrlFormatting(stripSystemReminders(children));
|
|
56043
56087
|
}, [children]);
|
|
@@ -56046,7 +56090,7 @@ function MarkdownContent({ children, className, mode, sessionId }) {
|
|
|
56046
56090
|
{
|
|
56047
56091
|
className: cn("blade-chat-markdown break-words", className),
|
|
56048
56092
|
mode: mode ?? "static",
|
|
56049
|
-
components
|
|
56093
|
+
components,
|
|
56050
56094
|
sessionId,
|
|
56051
56095
|
children: resolvedChildren
|
|
56052
56096
|
},
|
|
@@ -56978,8 +57022,16 @@ function AssistantTurnBlock({
|
|
|
56978
57022
|
(toolCall) => formatToolName(toolCall.name) !== "AskUserQuestion" && !shouldHideToolCall(finalMessage, toolCall)
|
|
56979
57023
|
)
|
|
56980
57024
|
) : [];
|
|
56981
|
-
const
|
|
56982
|
-
|
|
57025
|
+
const keepToolStepsOpen = useContext6(KeepToolStepsOpenContext);
|
|
57026
|
+
const hasToolSteps = messages.some(
|
|
57027
|
+
(message) => (message.tool_calls ?? []).some(
|
|
57028
|
+
(toolCall) => formatToolName(toolCall.name) !== "AskUserQuestion" && !shouldHideToolCall(message, toolCall)
|
|
57029
|
+
)
|
|
57030
|
+
);
|
|
57031
|
+
const hasExecutionProcess = hasToolSteps || messages.some(
|
|
57032
|
+
(message) => message.reasoning || (message.tool_calls ?? []).some(
|
|
57033
|
+
(toolCall) => formatToolName(toolCall.name) === "AskUserQuestion"
|
|
57034
|
+
)
|
|
56983
57035
|
);
|
|
56984
57036
|
const latestReasoningIndex = isStreaming ? findLatestReasoningMessageIndex(messages) : -1;
|
|
56985
57037
|
const hasActionableToolCall = messages.some(
|
|
@@ -56996,15 +57048,18 @@ function AssistantTurnBlock({
|
|
|
56996
57048
|
const [displayMode, setDisplayMode] = useState33(
|
|
56997
57049
|
() => isStreaming || hasActionableToolCall ? "detail" : "compact"
|
|
56998
57050
|
);
|
|
56999
|
-
const
|
|
57051
|
+
const [selectedDisplayMode, setSelectedDisplayMode] = useState33();
|
|
57000
57052
|
const wasStreamingRef = useRef27(isStreaming);
|
|
57001
57053
|
useEffect25(() => {
|
|
57002
|
-
if (wasStreamingRef.current && !isStreaming &&
|
|
57054
|
+
if (wasStreamingRef.current && !isStreaming && selectedDisplayMode === void 0) {
|
|
57003
57055
|
setDisplayMode(hasActionableToolCall ? "detail" : "compact");
|
|
57004
57056
|
}
|
|
57005
57057
|
wasStreamingRef.current = isStreaming;
|
|
57006
|
-
}, [hasActionableToolCall, isStreaming]);
|
|
57007
|
-
const effectiveMode = resolveTurnDisplayMode({
|
|
57058
|
+
}, [hasActionableToolCall, isStreaming, selectedDisplayMode]);
|
|
57059
|
+
const effectiveMode = resolveTurnDisplayMode({
|
|
57060
|
+
isStreaming,
|
|
57061
|
+
displayMode: selectedDisplayMode ?? (keepToolStepsOpen && hasToolSteps ? "detail" : displayMode)
|
|
57062
|
+
});
|
|
57008
57063
|
const client = useOptionalBladeClient();
|
|
57009
57064
|
const clockNow = isStreaming ? sessionId ? getServerTime(client) : Date.now() : null;
|
|
57010
57065
|
const executionDurationMs = getExecutionDurationMs({
|
|
@@ -57084,10 +57139,7 @@ function AssistantTurnBlock({
|
|
|
57084
57139
|
"button",
|
|
57085
57140
|
{
|
|
57086
57141
|
type: "button",
|
|
57087
|
-
onClick: () =>
|
|
57088
|
-
userSelectedDisplayModeRef.current = true;
|
|
57089
|
-
setDisplayMode(displayMode === "detail" ? "compact" : "detail");
|
|
57090
|
-
},
|
|
57142
|
+
onClick: () => setSelectedDisplayMode(effectiveMode === "detail" ? "compact" : "detail"),
|
|
57091
57143
|
"aria-expanded": effectiveMode === "detail",
|
|
57092
57144
|
"aria-label": effectiveMode === "detail" ? "\u6536\u8D77\u6267\u884C\u8FC7\u7A0B" : "\u5C55\u5F00\u6267\u884C\u8FC7\u7A0B",
|
|
57093
57145
|
"data-testid": "assistant-execution-summary",
|
|
@@ -58539,7 +58591,7 @@ function StopAutoScrollBridge({ stopRef }) {
|
|
|
58539
58591
|
}
|
|
58540
58592
|
|
|
58541
58593
|
// src/components/ChatSurface.tsx
|
|
58542
|
-
import { jsx as jsx31, jsxs as jsxs25 } from "react/jsx-runtime";
|
|
58594
|
+
import { Fragment as Fragment9, jsx as jsx31, jsxs as jsxs25 } from "react/jsx-runtime";
|
|
58543
58595
|
function themeAttr(theme) {
|
|
58544
58596
|
return theme === "dark" ? "dark" : void 0;
|
|
58545
58597
|
}
|
|
@@ -58559,6 +58611,7 @@ function ChatSurface({
|
|
|
58559
58611
|
onInputChange,
|
|
58560
58612
|
onSuggestion,
|
|
58561
58613
|
onSend,
|
|
58614
|
+
uploadFiles,
|
|
58562
58615
|
onStop,
|
|
58563
58616
|
sessionStatus,
|
|
58564
58617
|
askAnswers,
|
|
@@ -58581,13 +58634,44 @@ function ChatSurface({
|
|
|
58581
58634
|
}) {
|
|
58582
58635
|
const [pending, setPending] = useState36([]);
|
|
58583
58636
|
const currentPending = pending.filter((item) => item.sessionId === sessionId);
|
|
58637
|
+
const [pendingFiles, setPendingFiles] = useState36([]);
|
|
58638
|
+
const selection = useRef30(null);
|
|
58639
|
+
const currentFiles = pendingFiles.filter((item) => item.sessionId === sessionId);
|
|
58640
|
+
const attachmentsBlocked = currentFiles.some((file2) => !file2.path);
|
|
58641
|
+
const hasAttachments = currentPending.length > 0 || currentFiles.length > 0;
|
|
58642
|
+
async function addFiles(files) {
|
|
58643
|
+
if (!sessionId || !uploadFiles || isViewer || files.length === 0) return;
|
|
58644
|
+
const entries = files.map((file2) => ({ id: randomId(), sessionId, name: file2.name }));
|
|
58645
|
+
const indices = new Map(entries.map((item, index3) => [item.id, index3]));
|
|
58646
|
+
setPendingFiles((items) => [...items, ...entries]);
|
|
58647
|
+
try {
|
|
58648
|
+
const result = await uploadFiles(sessionId, ".", files);
|
|
58649
|
+
const outcomes = new Map(result.results?.map((item) => [item.index, item]));
|
|
58650
|
+
setPendingFiles((items) => items.map((item) => {
|
|
58651
|
+
const index3 = indices.get(item.id);
|
|
58652
|
+
if (index3 === void 0) return item;
|
|
58653
|
+
const outcome = outcomes.get(index3);
|
|
58654
|
+
return outcome?.path ? { ...item, path: outcome.path } : { ...item, error: outcome?.error || "\u4E0A\u4F20\u5931\u8D25\uFF0C\u8BF7\u79FB\u9664\u540E\u91CD\u65B0\u9009\u62E9" };
|
|
58655
|
+
}));
|
|
58656
|
+
} catch {
|
|
58657
|
+
setPendingFiles((items) => items.map((item) => indices.has(item.id) ? { ...item, error: "\u4E0A\u4F20\u5931\u8D25\uFF0C\u8BF7\u79FB\u9664\u540E\u91CD\u65B0\u9009\u62E9" } : item));
|
|
58658
|
+
}
|
|
58659
|
+
}
|
|
58584
58660
|
const sendWithApps = async (text4) => {
|
|
58661
|
+
if (attachmentsBlocked) return false;
|
|
58585
58662
|
const content3 = [...currentPending.map((item) => `[${item.label}]
|
|
58586
58663
|
${item.content}`), text4].filter(Boolean).join("\n\n");
|
|
58587
|
-
const
|
|
58664
|
+
const message = getTextContent4(buildMessageContent(content3, currentFiles.map((file2) => ({
|
|
58665
|
+
kind: "file",
|
|
58666
|
+
name: file2.name,
|
|
58667
|
+
uploadedPath: file2.path
|
|
58668
|
+
}))));
|
|
58669
|
+
const accepted = currentFiles.length > 0 ? await onSend(message, true) : await onSend(message);
|
|
58588
58670
|
if (accepted) {
|
|
58589
58671
|
const sent = new Set(currentPending.map((item) => item.id));
|
|
58590
58672
|
setPending((items) => items.filter((item) => !sent.has(item.id)));
|
|
58673
|
+
const sentFiles = new Set(currentFiles.map((item) => item.id));
|
|
58674
|
+
setPendingFiles((items) => items.filter((item) => !sentFiles.has(item.id)));
|
|
58591
58675
|
}
|
|
58592
58676
|
return accepted;
|
|
58593
58677
|
};
|
|
@@ -58661,7 +58745,7 @@ ${item.content}`), text4].filter(Boolean).join("\n\n");
|
|
|
58661
58745
|
}
|
|
58662
58746
|
) : null,
|
|
58663
58747
|
beforeInput,
|
|
58664
|
-
/* @__PURE__ */ jsx31(QueuePanelAdjacencyContext.Provider, { value:
|
|
58748
|
+
/* @__PURE__ */ jsx31(QueuePanelAdjacencyContext.Provider, { value: !hasAttachments, children: queuePanel }),
|
|
58665
58749
|
currentPending.map((item) => /* @__PURE__ */ jsxs25("div", { style: { display: "flex", gap: 8, padding: "8px 16px" }, children: [
|
|
58666
58750
|
/* @__PURE__ */ jsxs25("details", { style: { flex: 1, minWidth: 0 }, children: [
|
|
58667
58751
|
/* @__PURE__ */ jsx31("summary", { children: item.label }),
|
|
@@ -58669,18 +58753,61 @@ ${item.content}`), text4].filter(Boolean).join("\n\n");
|
|
|
58669
58753
|
] }),
|
|
58670
58754
|
/* @__PURE__ */ jsx31("button", { type: "button", "aria-label": "\u79FB\u9664\u5F85\u53D1\u9001\u5185\u5BB9", title: "\u79FB\u9664", onClick: () => setPending((items) => items.filter((other) => other.id !== item.id)), children: /* @__PURE__ */ jsx31(X, { size: 16 }) })
|
|
58671
58755
|
] }, item.id)),
|
|
58756
|
+
currentFiles.length > 0 && /* @__PURE__ */ jsx31("ul", { "aria-label": "\u5F85\u53D1\u9001\u9644\u4EF6", className: "flex flex-wrap gap-2 px-4 pb-2", children: currentFiles.map((file2) => /* @__PURE__ */ jsxs25("li", { className: "flex min-w-0 items-center gap-2 rounded-md bg-[hsl(var(--muted))] px-2 py-1 text-xs", children: [
|
|
58757
|
+
/* @__PURE__ */ jsx31(Paperclip, { size: 13, "aria-hidden": "true" }),
|
|
58758
|
+
/* @__PURE__ */ jsx31("span", { className: "truncate", title: file2.name, children: file2.name }),
|
|
58759
|
+
file2.error ? /* @__PURE__ */ jsx31("span", { role: "alert", children: file2.error }) : !file2.path ? /* @__PURE__ */ jsx31("span", { role: "status", children: "\u4E0A\u4F20\u4E2D\u2026" }) : null,
|
|
58760
|
+
/* @__PURE__ */ jsx31(
|
|
58761
|
+
"button",
|
|
58762
|
+
{
|
|
58763
|
+
type: "button",
|
|
58764
|
+
"aria-label": `\u79FB\u9664\u9644\u4EF6 ${file2.name}`,
|
|
58765
|
+
onClick: () => setPendingFiles((items) => items.filter((item) => item.id !== file2.id)),
|
|
58766
|
+
children: /* @__PURE__ */ jsx31(X, { size: 14, "aria-hidden": "true" })
|
|
58767
|
+
}
|
|
58768
|
+
)
|
|
58769
|
+
] }, file2.id)) }),
|
|
58672
58770
|
/* @__PURE__ */ jsx31(
|
|
58673
58771
|
ChatInput,
|
|
58674
58772
|
{
|
|
58675
58773
|
value: inputText,
|
|
58676
58774
|
onValueChange: onInputChange,
|
|
58677
58775
|
onSend: sendWithApps,
|
|
58678
|
-
hasAttachments
|
|
58776
|
+
hasAttachments,
|
|
58777
|
+
attachmentsBlocked,
|
|
58778
|
+
attachmentPicker: uploadFiles && sessionId && !isViewer ? /* @__PURE__ */ jsxs25(Fragment9, { children: [
|
|
58779
|
+
/* @__PURE__ */ jsx31(
|
|
58780
|
+
"input",
|
|
58781
|
+
{
|
|
58782
|
+
ref: selection,
|
|
58783
|
+
type: "file",
|
|
58784
|
+
multiple: true,
|
|
58785
|
+
hidden: true,
|
|
58786
|
+
"aria-label": "\u9009\u62E9\u9644\u4EF6",
|
|
58787
|
+
onChange: (event) => {
|
|
58788
|
+
const files = Array.from(event.currentTarget.files ?? []);
|
|
58789
|
+
event.currentTarget.value = "";
|
|
58790
|
+
void addFiles(files);
|
|
58791
|
+
}
|
|
58792
|
+
}
|
|
58793
|
+
),
|
|
58794
|
+
/* @__PURE__ */ jsx31(
|
|
58795
|
+
"button",
|
|
58796
|
+
{
|
|
58797
|
+
type: "button",
|
|
58798
|
+
"aria-label": "\u6DFB\u52A0\u9644\u4EF6",
|
|
58799
|
+
title: "\u6DFB\u52A0\u9644\u4EF6",
|
|
58800
|
+
onClick: () => selection.current?.click(),
|
|
58801
|
+
className: "flex h-8 w-8 shrink-0 items-center justify-center rounded-md hover:bg-[hsl(var(--muted))]",
|
|
58802
|
+
children: /* @__PURE__ */ jsx31(Paperclip, { size: 16, "aria-hidden": "true" })
|
|
58803
|
+
}
|
|
58804
|
+
)
|
|
58805
|
+
] }) : void 0,
|
|
58679
58806
|
onStop,
|
|
58680
58807
|
isStreaming,
|
|
58681
58808
|
isStopping,
|
|
58682
58809
|
queueWhileRunning: queuePanel != null,
|
|
58683
|
-
mergesWithPanelAbove: (queuePanelVisible ?? queuePanel != null) &&
|
|
58810
|
+
mergesWithPanelAbove: (queuePanelVisible ?? queuePanel != null) && !hasAttachments,
|
|
58684
58811
|
placeholder,
|
|
58685
58812
|
queueKey: sessionId,
|
|
58686
58813
|
className: classNames?.chatInput,
|
|
@@ -58696,7 +58823,7 @@ ${item.content}`), text4].filter(Boolean).join("\n\n");
|
|
|
58696
58823
|
}
|
|
58697
58824
|
|
|
58698
58825
|
// src/components/AgentChat.tsx
|
|
58699
|
-
import { Fragment as
|
|
58826
|
+
import { Fragment as Fragment10, jsx as jsx32, jsxs as jsxs26 } from "react/jsx-runtime";
|
|
58700
58827
|
function isUnauthorizedError(error61) {
|
|
58701
58828
|
return error61 instanceof BladeApiError2 && error61.status === 401;
|
|
58702
58829
|
}
|
|
@@ -58806,8 +58933,8 @@ function ChatSessionView({
|
|
|
58806
58933
|
const resolvedSessionId = session?.sessionId;
|
|
58807
58934
|
const isViewer = state?.viewerRole === "viewer";
|
|
58808
58935
|
const canUseQueue = !isViewer;
|
|
58809
|
-
const onSessionReadyRef =
|
|
58810
|
-
const readySessionRef =
|
|
58936
|
+
const onSessionReadyRef = useRef31(onSessionReady);
|
|
58937
|
+
const readySessionRef = useRef31(null);
|
|
58811
58938
|
const hasOnSessionReady = onSessionReady !== void 0;
|
|
58812
58939
|
useEffect28(() => {
|
|
58813
58940
|
onSessionReadyRef.current = onSessionReady;
|
|
@@ -58892,11 +59019,11 @@ ${content3}`);
|
|
|
58892
59019
|
const isStopping = stopRequested && isStreaming;
|
|
58893
59020
|
const connectError = error61 && !isUnauthorizedError(error61) ? error61.message || "\u8FDE\u63A5\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5" : null;
|
|
58894
59021
|
const errorMessage = connectError ?? state?.errorMessage ?? replay.error?.message ?? null;
|
|
58895
|
-
const handleSend = (text4) => {
|
|
59022
|
+
const handleSend = (text4, hasAttachments = false) => {
|
|
58896
59023
|
setStopRequested(false);
|
|
58897
59024
|
return session?.send(text4, {
|
|
58898
59025
|
mode: state?.mode ?? void 0,
|
|
58899
|
-
queueWhenRunning: canUseQueue
|
|
59026
|
+
queueWhenRunning: canUseQueue && !hasAttachments
|
|
58900
59027
|
}) ?? Promise.resolve(false);
|
|
58901
59028
|
};
|
|
58902
59029
|
const handleStop = () => {
|
|
@@ -58954,7 +59081,7 @@ ${content3}`);
|
|
|
58954
59081
|
slots,
|
|
58955
59082
|
placeholder,
|
|
58956
59083
|
connection: state?.connection ?? "connecting",
|
|
58957
|
-
banner: /* @__PURE__ */ jsxs26(
|
|
59084
|
+
banner: /* @__PURE__ */ jsxs26(Fragment10, { children: [
|
|
58958
59085
|
resolvedSessionId && !isViewer && (sessionPluginControls ? sessionPluginControls(resolvedSessionId) : /* @__PURE__ */ jsx32(SessionPluginSelector, { client, sessionId: resolvedSessionId })),
|
|
58959
59086
|
/* @__PURE__ */ jsx32(
|
|
58960
59087
|
ReplayBar,
|
|
@@ -59034,6 +59161,7 @@ ${content3}`);
|
|
|
59034
59161
|
onInputChange: setInputText,
|
|
59035
59162
|
onSuggestion: setInputText,
|
|
59036
59163
|
onSend: handleSend,
|
|
59164
|
+
uploadFiles: session && !session.isStatic ? ((id, dir, files) => client.sessions.uploadFiles(id, dir, files)) : void 0,
|
|
59037
59165
|
onStop: handleStop,
|
|
59038
59166
|
sessionStatus: state?.status ?? void 0,
|
|
59039
59167
|
askAnswers: state?.askAnswers,
|
|
@@ -59271,7 +59399,7 @@ function ChatView(props) {
|
|
|
59271
59399
|
}
|
|
59272
59400
|
|
|
59273
59401
|
// src/components/ConnectorPanel.tsx
|
|
59274
|
-
import { useCallback as useCallback31, useEffect as useEffect30, useMemo as useMemo20, useRef as
|
|
59402
|
+
import { useCallback as useCallback31, useEffect as useEffect30, useMemo as useMemo20, useRef as useRef32, useState as useState40 } from "react";
|
|
59275
59403
|
|
|
59276
59404
|
// src/components/connector-panel-types.ts
|
|
59277
59405
|
function selectionFromItem(item) {
|
|
@@ -59293,7 +59421,7 @@ function triggerSummary(items) {
|
|
|
59293
59421
|
}
|
|
59294
59422
|
|
|
59295
59423
|
// src/components/ConnectorPanel.tsx
|
|
59296
|
-
import { Fragment as
|
|
59424
|
+
import { Fragment as Fragment11, jsx as jsx36, jsxs as jsxs28 } from "react/jsx-runtime";
|
|
59297
59425
|
function PanelDivider() {
|
|
59298
59426
|
return /* @__PURE__ */ jsx36("div", { className: "my-1 border-[hsl(var(--border))] border-t" });
|
|
59299
59427
|
}
|
|
@@ -59371,9 +59499,9 @@ function ConnectorPanel({
|
|
|
59371
59499
|
() => items.filter((item) => item.active),
|
|
59372
59500
|
[items]
|
|
59373
59501
|
);
|
|
59374
|
-
const onSelectedChangeRef =
|
|
59502
|
+
const onSelectedChangeRef = useRef32(onSelectedChange);
|
|
59375
59503
|
onSelectedChangeRef.current = onSelectedChange;
|
|
59376
|
-
const latestSelected =
|
|
59504
|
+
const latestSelected = useRef32(selectedItems);
|
|
59377
59505
|
latestSelected.current = selectedItems;
|
|
59378
59506
|
const reportSelected = useCallback31(() => {
|
|
59379
59507
|
onSelectedChangeRef.current?.(latestSelected.current);
|
|
@@ -59395,11 +59523,11 @@ function ConnectorPanel({
|
|
|
59395
59523
|
}
|
|
59396
59524
|
)
|
|
59397
59525
|
] }),
|
|
59398
|
-
visibleSections.includes("computers") && renderComputerSection ? /* @__PURE__ */ jsxs28(
|
|
59526
|
+
visibleSections.includes("computers") && renderComputerSection ? /* @__PURE__ */ jsxs28(Fragment11, { children: [
|
|
59399
59527
|
/* @__PURE__ */ jsx36(PanelTitle, { children: "\u7535\u8111" }),
|
|
59400
59528
|
renderComputerSection(query)
|
|
59401
59529
|
] }) : null,
|
|
59402
|
-
visibleSections.includes("plugins") ? /* @__PURE__ */ jsxs28(
|
|
59530
|
+
visibleSections.includes("plugins") ? /* @__PURE__ */ jsxs28(Fragment11, { children: [
|
|
59403
59531
|
/* @__PURE__ */ jsx36(PanelDivider, {}),
|
|
59404
59532
|
/* @__PURE__ */ jsx36(PanelTitle, { children: "\u63D2\u4EF6" }),
|
|
59405
59533
|
!sessionId ? (
|
|
@@ -59442,12 +59570,12 @@ function ConnectorPanel({
|
|
|
59442
59570
|
}
|
|
59443
59571
|
)
|
|
59444
59572
|
] }) : null,
|
|
59445
|
-
visibleSections.includes("accounts") && renderExternalAccounts ? /* @__PURE__ */ jsxs28(
|
|
59573
|
+
visibleSections.includes("accounts") && renderExternalAccounts ? /* @__PURE__ */ jsxs28(Fragment11, { children: [
|
|
59446
59574
|
/* @__PURE__ */ jsx36(PanelDivider, {}),
|
|
59447
59575
|
/* @__PURE__ */ jsx36(PanelTitle, { children: "\u5916\u90E8\u8D26\u53F7" }),
|
|
59448
59576
|
renderExternalAccounts(query)
|
|
59449
59577
|
] }) : null,
|
|
59450
|
-
renderFooterActions ? /* @__PURE__ */ jsxs28(
|
|
59578
|
+
renderFooterActions ? /* @__PURE__ */ jsxs28(Fragment11, { children: [
|
|
59451
59579
|
/* @__PURE__ */ jsx36(PanelDivider, {}),
|
|
59452
59580
|
renderFooterActions()
|
|
59453
59581
|
] }) : null
|
|
@@ -59593,7 +59721,7 @@ function ContextGroupCard({ contexts, className }) {
|
|
|
59593
59721
|
}
|
|
59594
59722
|
|
|
59595
59723
|
// src/components/SessionMemoryToggle.tsx
|
|
59596
|
-
import { useCallback as useCallback32, useEffect as useEffect31, useRef as
|
|
59724
|
+
import { useCallback as useCallback32, useEffect as useEffect31, useRef as useRef33, useState as useState41, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
59597
59725
|
import { jsx as jsx39, jsxs as jsxs31 } from "react/jsx-runtime";
|
|
59598
59726
|
var saveStates = /* @__PURE__ */ new WeakMap();
|
|
59599
59727
|
function getSaveState(client, sessionId) {
|
|
@@ -59652,7 +59780,7 @@ function SessionMemoryToggle({
|
|
|
59652
59780
|
getSaving
|
|
59653
59781
|
);
|
|
59654
59782
|
const [draftEnabled, setDraftEnabled] = useState41(enabled);
|
|
59655
|
-
const activeSessionIdRef =
|
|
59783
|
+
const activeSessionIdRef = useRef33(sessionId);
|
|
59656
59784
|
activeSessionIdRef.current = sessionId;
|
|
59657
59785
|
useEffect31(() => {
|
|
59658
59786
|
setDraftEnabled(enabled);
|
|
@@ -63630,6 +63758,7 @@ lucide-react/dist/esm/icons/menu.js:
|
|
|
63630
63758
|
lucide-react/dist/esm/icons/message-square-more.js:
|
|
63631
63759
|
lucide-react/dist/esm/icons/message-square.js:
|
|
63632
63760
|
lucide-react/dist/esm/icons/minimize-2.js:
|
|
63761
|
+
lucide-react/dist/esm/icons/paperclip.js:
|
|
63633
63762
|
lucide-react/dist/esm/icons/pencil.js:
|
|
63634
63763
|
lucide-react/dist/esm/icons/play.js:
|
|
63635
63764
|
lucide-react/dist/esm/icons/plus.js:
|