@vegintech/langchain-react-agent 0.0.16 → 0.0.18

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 CHANGED
@@ -1,41 +1,17 @@
1
1
  import * as react from "react";
2
- import React$1, { CSSProperties, ReactNode } from "react";
2
+ import React$1, { ReactNode } from "react";
3
+ import { ThoughtChainItemProps } from "@ant-design/x";
3
4
  import { Components } from "streamdown";
4
5
  import { BaseNode, InsertPosition, NodeRender, SenderProps, SkillType, SlotConfigType } from "@ant-design/x/es/sender/interface.ts";
5
6
  import { Message } from "@langchain/langgraph-sdk";
6
7
 
7
8
  //#region src/types.d.ts
8
- /** ToolCard 各部件的样式配置 */
9
- interface ToolCardStyles {
10
- /** icon 容器的样式 */
11
- icon?: CSSProperties;
12
- /** prefix 文本的样式 */
13
- prefix?: CSSProperties;
14
- /** content 文本的样式 */
15
- content?: CSSProperties;
16
- }
17
9
  /** ToolCard 组件 Props */
18
- interface ToolCardProps {
19
- /**
20
- * 前缀文本(中文,使用小字体)
21
- */
22
- prefix: string;
23
- /**
24
- * 正文内容(英文/文件名,保持默认大小)
25
- */
26
- content?: string;
27
- /**
28
- * 左侧图标
29
- */
30
- icon: ReactNode;
31
- /**
32
- * 根节点样式
33
- */
34
- style?: CSSProperties;
10
+ interface ToolCardProps extends Omit<ThoughtChainItemProps, "children"> {
35
11
  /**
36
- * 各部件的样式配置,可分别设置 icon、prefix、content 的样式
12
+ * 子组件,会作为 ThoughtChain.Item 的内容
37
13
  */
38
- styles?: ToolCardStyles;
14
+ children?: ReactNode;
39
15
  }
40
16
  /** Interrupt 事件数据结构 */
41
17
  interface InterruptEvent {
@@ -321,4 +297,4 @@ interface MessageContentRendererProps {
321
297
  /** 消息内容渲染组件 - 支持字符串和多模态内容块 */
322
298
  declare const MessageContentRenderer: React$1.FC<MessageContentRendererProps>;
323
299
  //#endregion
324
- export { AgentChat, type AgentChatInputRef, type AgentChatProps, type AgentChatRef, type BackendTool, type ChatMessage, type ContextItem, type EmptyStateConfig, type FrontendTool, type InputConfig, type InterruptConfig, type InterruptEvent, type InterruptManagerProps, type InterruptRenderProps, type MessageConfig, type MessageContent, type MessageContentBlock, MessageContentRenderer, type MessageContentRendererProps, type MessageType, type SenderCustomizationProps, type SenderSlotConfig, type SenderSubmitParams, type ToolCallInput, ToolCard, type ToolCardProps, type ToolCardStyles, type ToolDefinition, type ToolExecutionRecord, type ToolExecutionStatus, type ToolParameterSchema, type ToolRenderProps };
300
+ export { AgentChat, type AgentChatInputRef, type AgentChatProps, type AgentChatRef, type BackendTool, type ChatMessage, type ContextItem, type EmptyStateConfig, type FrontendTool, type InputConfig, type InterruptConfig, type InterruptEvent, type InterruptManagerProps, type InterruptRenderProps, type MessageConfig, type MessageContent, type MessageContentBlock, MessageContentRenderer, type MessageContentRendererProps, type MessageType, type SenderCustomizationProps, type SenderSlotConfig, type SenderSubmitParams, type ToolCallInput, ToolCard, type ToolCardProps, type ToolDefinition, type ToolExecutionRecord, type ToolExecutionStatus, type ToolParameterSchema, type ToolRenderProps };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
2
- import { Actions, Bubble, Sender, Think } from "@ant-design/x";
1
+ import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
2
+ import { Actions, Bubble, Sender, Think, ThoughtChain } from "@ant-design/x";
3
3
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
4
  import { Streamdown } from "streamdown";
5
5
  import { useStream } from "@langchain/langgraph-sdk/react";
@@ -188,14 +188,45 @@ const ContentBlock = ({ block, index, components, securityConfig }) => {
188
188
  }, index);
189
189
  if (block.type === "image_url" && "image_url" in block) {
190
190
  const imageUrl = block.image_url.url;
191
+ const [imageSize, setImageSize] = React.useState(null);
192
+ React.useEffect(() => {
193
+ const img = new Image();
194
+ img.onload = () => {
195
+ setImageSize({
196
+ width: img.naturalWidth,
197
+ height: img.naturalHeight
198
+ });
199
+ };
200
+ img.src = imageUrl;
201
+ }, [imageUrl]);
202
+ const getImageStyle = () => {
203
+ const baseStyle = {
204
+ borderRadius: "8px",
205
+ marginTop: "8px",
206
+ objectFit: "contain"
207
+ };
208
+ if (!imageSize) return {
209
+ ...baseStyle,
210
+ maxWidth: "100%",
211
+ maxHeight: "400px"
212
+ };
213
+ if (imageSize.width / imageSize.height < 1) return {
214
+ ...baseStyle,
215
+ maxHeight: "400px",
216
+ width: "auto",
217
+ height: "auto"
218
+ };
219
+ else return {
220
+ ...baseStyle,
221
+ maxWidth: "100%",
222
+ width: "auto",
223
+ height: "auto"
224
+ };
225
+ };
191
226
  return /* @__PURE__ */ jsx("img", {
192
227
  src: imageUrl,
193
228
  alt: "Message content",
194
- style: {
195
- maxWidth: "100%",
196
- borderRadius: "8px",
197
- marginTop: "8px"
198
- }
229
+ style: getImageStyle()
199
230
  }, index);
200
231
  }
201
232
  return null;
@@ -1364,6 +1395,11 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: external
1364
1395
  onSubmit: stream.submit
1365
1396
  });
1366
1397
  const [toolExecutions, setToolExecutions] = useState(/* @__PURE__ */ new Map());
1398
+ const hasToolExecuting = useMemo(() => {
1399
+ for (const record of toolExecutions.values()) if (record.status === "running" || record.status === "pending") return true;
1400
+ return false;
1401
+ }, [toolExecutions]);
1402
+ const isLoading = stream.isLoading || hasToolExecuting;
1367
1403
  const { messages, toolResults } = useMemo(() => {
1368
1404
  return processMessages(stream.messages);
1369
1405
  }, [stream.messages]);
@@ -1462,7 +1498,7 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: external
1462
1498
  ref: chatInputRef,
1463
1499
  onSend: handleSend,
1464
1500
  onStop: handleStop,
1465
- isLoading: stream.isLoading,
1501
+ isLoading,
1466
1502
  className: "agent-chat-input",
1467
1503
  ...chatInputConfig
1468
1504
  }),
@@ -1481,41 +1517,15 @@ AgentChat.displayName = "AgentChat";
1481
1517
  * ToolCard 组件 - 用于展示工具调用结果
1482
1518
  * 样式:圆角矩形框,左侧 icon,label 分两行显示(prefix 小字体,content 默认字体)
1483
1519
  */
1484
- const ToolCard = ({ prefix, content, icon, style, styles }) => {
1485
- return /* @__PURE__ */ jsxs("div", {
1520
+ const ToolCard = ({ children, style, ...rest }) => {
1521
+ return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(ThoughtChain.Item, {
1522
+ variant: "text",
1523
+ ...rest,
1486
1524
  style: {
1487
- display: "inline-flex",
1488
- alignItems: "center",
1489
- gap: 8,
1490
- borderRadius: 8,
1491
- fontSize: 13,
1525
+ paddingLeft: 0,
1492
1526
  ...style
1493
- },
1494
- children: [/* @__PURE__ */ jsx("span", {
1495
- style: {
1496
- display: "flex",
1497
- alignItems: "center",
1498
- ...styles?.icon
1499
- },
1500
- children: icon
1501
- }), /* @__PURE__ */ jsxs("span", {
1502
- style: {
1503
- display: "flex",
1504
- alignItems: "center",
1505
- gap: 4
1506
- },
1507
- children: [/* @__PURE__ */ jsx("span", {
1508
- style: {
1509
- fontSize: 12,
1510
- ...styles?.prefix
1511
- },
1512
- children: prefix
1513
- }), /* @__PURE__ */ jsx("span", {
1514
- style: { ...styles?.content },
1515
- children: content
1516
- })]
1517
- })]
1518
- });
1527
+ }
1528
+ }), children] });
1519
1529
  };
1520
1530
  //#endregion
1521
1531
  export { AgentChat, MessageContentRenderer, ToolCard };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vegintech/langchain-react-agent",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "LangChain Agent UI component library for React",
5
5
  "license": "MIT",
6
6
  "files": [