@vegintech/langchain-react-agent 0.0.16 → 0.0.17

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.
Files changed (2) hide show
  1. package/dist/index.mjs +43 -7
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
1
+ import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
2
2
  import { Actions, Bubble, Sender, Think } from "@ant-design/x";
3
3
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
4
  import { Streamdown } from "streamdown";
@@ -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
  }),
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.17",
4
4
  "description": "LangChain Agent UI component library for React",
5
5
  "license": "MIT",
6
6
  "files": [