@vegintech/langchain-react-agent 0.0.15 → 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 +45 -14
  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;
@@ -1332,7 +1363,7 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: external
1332
1363
  useEffect(() => {
1333
1364
  setInternalThreadId(externalThreadId);
1334
1365
  }, [externalThreadId]);
1335
- const { footer, skill, slotConfig, header, prefix, onPreSend, placeholder } = inputConfig || {};
1366
+ const { onPreSend, ...chatInputConfig } = inputConfig || {};
1336
1367
  const chatInputRef = useRef(null);
1337
1368
  useImperativeHandle(ref, () => ({
1338
1369
  input: chatInputRef.current,
@@ -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,14 +1498,9 @@ 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
- footer,
1468
- skill,
1469
- slotConfig,
1470
- header,
1471
- prefix,
1472
- placeholder
1503
+ ...chatInputConfig
1473
1504
  }),
1474
1505
  /* @__PURE__ */ jsx(DebugPanel, {
1475
1506
  messages: stream.messages,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vegintech/langchain-react-agent",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "LangChain Agent UI component library for React",
5
5
  "license": "MIT",
6
6
  "files": [