@vegintech/langchain-react-agent 0.0.5 → 0.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/dist/index.d.mts +5 -3
- package/dist/index.mjs +12 -37
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -68,15 +68,13 @@ interface SenderSubmitParams {
|
|
|
68
68
|
slotConfig?: SenderSlotConfig;
|
|
69
69
|
skillData?: SkillType;
|
|
70
70
|
}
|
|
71
|
-
/** onPreSend
|
|
71
|
+
/** onPreSend 钩子返回值:只返回消息数组 */
|
|
72
72
|
interface PreSendResult {
|
|
73
73
|
/** 要发送的消息数组 */
|
|
74
74
|
messages: Array<{
|
|
75
75
|
type: string;
|
|
76
76
|
content: string;
|
|
77
77
|
}>;
|
|
78
|
-
/** 其他任意字段会作为额外参数一起 submit */
|
|
79
|
-
[x: string]: unknown;
|
|
80
78
|
}
|
|
81
79
|
/** Sender 组件的可定制参数 */
|
|
82
80
|
interface SenderCustomizationProps {
|
|
@@ -222,6 +220,10 @@ interface AgentChatProps {
|
|
|
222
220
|
inputConfig?: InputConfig;
|
|
223
221
|
onError?: (error: Error) => void;
|
|
224
222
|
interruptConfig?: InterruptConfig;
|
|
223
|
+
/** Agent 状态值 */
|
|
224
|
+
agentState?: Record<string, unknown>;
|
|
225
|
+
/** Agent 状态变化回调 */
|
|
226
|
+
onAgentStateChange?: (state: Record<string, unknown>) => void;
|
|
225
227
|
}
|
|
226
228
|
/** AgentChat 组件对外暴露的方法 */
|
|
227
229
|
interface AgentChatRef {
|
package/dist/index.mjs
CHANGED
|
@@ -208,22 +208,6 @@ const CustomParagraph = (props) => {
|
|
|
208
208
|
const { node, ...rest } = props;
|
|
209
209
|
return /* @__PURE__ */ jsx("span", { ...rest });
|
|
210
210
|
};
|
|
211
|
-
const renderMarkdown = (content, customComponents, securityConfig) => {
|
|
212
|
-
return /* @__PURE__ */ jsx(Streamdown, {
|
|
213
|
-
components: {
|
|
214
|
-
p: CustomParagraph,
|
|
215
|
-
...customComponents
|
|
216
|
-
},
|
|
217
|
-
allowedTags: securityConfig?.allowedTags,
|
|
218
|
-
literalTagContent: securityConfig?.literalTagContent,
|
|
219
|
-
controls: { table: {
|
|
220
|
-
copy: false,
|
|
221
|
-
download: false,
|
|
222
|
-
fullscreen: false
|
|
223
|
-
} },
|
|
224
|
-
children: content ?? ""
|
|
225
|
-
});
|
|
226
|
-
};
|
|
227
211
|
const renderMessageContent = (message, isLastMessage, isLoading, tools, toolExecutions, components, securityConfig) => {
|
|
228
212
|
const hasToolCalls = message.toolCalls && message.toolCalls.length > 0;
|
|
229
213
|
const shouldBlink = isLastMessage && isLoading && !message.content && message.toolCalls?.length == 0;
|
|
@@ -267,19 +251,10 @@ const renderMessageContent = (message, isLastMessage, isLoading, tools, toolExec
|
|
|
267
251
|
}, message.id);
|
|
268
252
|
};
|
|
269
253
|
const toBubbleItem = (message, isLastMessage, isLoading, tools, toolExecutions, components, securityConfig) => {
|
|
270
|
-
const hasReasoning = !!message.reasoningContent;
|
|
271
|
-
const hasToolCalls = message.toolCalls && message.toolCalls.length > 0;
|
|
272
|
-
if (hasReasoning || hasToolCalls) return {
|
|
273
|
-
key: message.id,
|
|
274
|
-
role: message.type === "human" ? "user" : "ai",
|
|
275
|
-
content: renderMessageContent(message, isLastMessage, isLoading, tools, toolExecutions, components, securityConfig),
|
|
276
|
-
placement: message.type === "human" ? "end" : "start"
|
|
277
|
-
};
|
|
278
254
|
return {
|
|
279
255
|
key: message.id,
|
|
280
256
|
role: message.type === "human" ? "user" : "ai",
|
|
281
|
-
content: message
|
|
282
|
-
contentRender: (content) => renderMarkdown(content, components, securityConfig),
|
|
257
|
+
content: renderMessageContent(message, isLastMessage, isLoading, tools, toolExecutions, components, securityConfig),
|
|
283
258
|
placement: message.type === "human" ? "end" : "start"
|
|
284
259
|
};
|
|
285
260
|
};
|
|
@@ -740,7 +715,7 @@ function injectStyles() {
|
|
|
740
715
|
//#endregion
|
|
741
716
|
//#region src/components/AgentChat.tsx
|
|
742
717
|
injectStyles();
|
|
743
|
-
const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: externalThreadId, onThreadIdChange, className = "", tools, contexts, messageConfig, inputConfig, onError, interruptConfig }, ref) => {
|
|
718
|
+
const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: externalThreadId, onThreadIdChange, className = "", tools, contexts, messageConfig, inputConfig, onError, interruptConfig, agentState, onAgentStateChange }, ref) => {
|
|
744
719
|
const [internalThreadId, setInternalThreadId] = useState(externalThreadId);
|
|
745
720
|
useEffect(() => {
|
|
746
721
|
setInternalThreadId(externalThreadId);
|
|
@@ -768,6 +743,9 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: external
|
|
|
768
743
|
onError?.(err);
|
|
769
744
|
}
|
|
770
745
|
});
|
|
746
|
+
useEffect(() => {
|
|
747
|
+
if (stream.values && onAgentStateChange) onAgentStateChange(stream.values);
|
|
748
|
+
}, [stream.values, onAgentStateChange]);
|
|
771
749
|
const { renderInterrupt: interruptRender } = useInterrupt({
|
|
772
750
|
interrupt: stream.interrupt,
|
|
773
751
|
config: interruptConfig,
|
|
@@ -787,10 +765,10 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: external
|
|
|
787
765
|
return next;
|
|
788
766
|
});
|
|
789
767
|
}, []);
|
|
790
|
-
const submitToStream = useCallback(async (submitMessages
|
|
768
|
+
const submitToStream = useCallback(async (submitMessages) => {
|
|
791
769
|
await stream.submit({
|
|
770
|
+
...agentState,
|
|
792
771
|
messages: submitMessages,
|
|
793
|
-
...extraState,
|
|
794
772
|
agentkit: {
|
|
795
773
|
actions: tools,
|
|
796
774
|
context: contexts
|
|
@@ -808,7 +786,8 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: external
|
|
|
808
786
|
}, [
|
|
809
787
|
stream,
|
|
810
788
|
tools,
|
|
811
|
-
contexts
|
|
789
|
+
contexts,
|
|
790
|
+
agentState
|
|
812
791
|
]);
|
|
813
792
|
const handleToolResult = useCallback((callId, name, result) => {
|
|
814
793
|
submitToStream([{
|
|
@@ -820,12 +799,8 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: external
|
|
|
820
799
|
}, [submitToStream]);
|
|
821
800
|
const handleSend = useCallback(async (params) => {
|
|
822
801
|
let messages = [];
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
const { messages: resultMessages, ...rest } = await onPreSend(params);
|
|
826
|
-
messages = resultMessages.filter((m) => m != null);
|
|
827
|
-
extraState = rest;
|
|
828
|
-
} else {
|
|
802
|
+
if (onPreSend && params.message.trim()) messages = (await onPreSend(params)).messages.filter((m) => m != null);
|
|
803
|
+
else {
|
|
829
804
|
if (!params.message.trim()) return;
|
|
830
805
|
messages = [{
|
|
831
806
|
type: "human",
|
|
@@ -833,7 +808,7 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: external
|
|
|
833
808
|
}];
|
|
834
809
|
}
|
|
835
810
|
if (messages.length === 0) return;
|
|
836
|
-
await submitToStream(messages
|
|
811
|
+
await submitToStream(messages);
|
|
837
812
|
}, [onPreSend, submitToStream]);
|
|
838
813
|
const handleStop = useCallback(async () => {
|
|
839
814
|
await stream.stop();
|