@vegintech/langchain-react-agent 0.0.5 → 0.0.6
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 +11 -11
- 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
|
@@ -740,7 +740,7 @@ function injectStyles() {
|
|
|
740
740
|
//#endregion
|
|
741
741
|
//#region src/components/AgentChat.tsx
|
|
742
742
|
injectStyles();
|
|
743
|
-
const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: externalThreadId, onThreadIdChange, className = "", tools, contexts, messageConfig, inputConfig, onError, interruptConfig }, ref) => {
|
|
743
|
+
const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: externalThreadId, onThreadIdChange, className = "", tools, contexts, messageConfig, inputConfig, onError, interruptConfig, agentState, onAgentStateChange }, ref) => {
|
|
744
744
|
const [internalThreadId, setInternalThreadId] = useState(externalThreadId);
|
|
745
745
|
useEffect(() => {
|
|
746
746
|
setInternalThreadId(externalThreadId);
|
|
@@ -768,6 +768,9 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: external
|
|
|
768
768
|
onError?.(err);
|
|
769
769
|
}
|
|
770
770
|
});
|
|
771
|
+
useEffect(() => {
|
|
772
|
+
if (stream.values && onAgentStateChange) onAgentStateChange(stream.values);
|
|
773
|
+
}, [stream.values, onAgentStateChange]);
|
|
771
774
|
const { renderInterrupt: interruptRender } = useInterrupt({
|
|
772
775
|
interrupt: stream.interrupt,
|
|
773
776
|
config: interruptConfig,
|
|
@@ -787,10 +790,10 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: external
|
|
|
787
790
|
return next;
|
|
788
791
|
});
|
|
789
792
|
}, []);
|
|
790
|
-
const submitToStream = useCallback(async (submitMessages
|
|
793
|
+
const submitToStream = useCallback(async (submitMessages) => {
|
|
791
794
|
await stream.submit({
|
|
795
|
+
...agentState,
|
|
792
796
|
messages: submitMessages,
|
|
793
|
-
...extraState,
|
|
794
797
|
agentkit: {
|
|
795
798
|
actions: tools,
|
|
796
799
|
context: contexts
|
|
@@ -808,7 +811,8 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: external
|
|
|
808
811
|
}, [
|
|
809
812
|
stream,
|
|
810
813
|
tools,
|
|
811
|
-
contexts
|
|
814
|
+
contexts,
|
|
815
|
+
agentState
|
|
812
816
|
]);
|
|
813
817
|
const handleToolResult = useCallback((callId, name, result) => {
|
|
814
818
|
submitToStream([{
|
|
@@ -820,12 +824,8 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: external
|
|
|
820
824
|
}, [submitToStream]);
|
|
821
825
|
const handleSend = useCallback(async (params) => {
|
|
822
826
|
let messages = [];
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
const { messages: resultMessages, ...rest } = await onPreSend(params);
|
|
826
|
-
messages = resultMessages.filter((m) => m != null);
|
|
827
|
-
extraState = rest;
|
|
828
|
-
} else {
|
|
827
|
+
if (onPreSend && params.message.trim()) messages = (await onPreSend(params)).messages.filter((m) => m != null);
|
|
828
|
+
else {
|
|
829
829
|
if (!params.message.trim()) return;
|
|
830
830
|
messages = [{
|
|
831
831
|
type: "human",
|
|
@@ -833,7 +833,7 @@ const AgentChat = forwardRef(({ apiUrl, assistantId, headers, threadId: external
|
|
|
833
833
|
}];
|
|
834
834
|
}
|
|
835
835
|
if (messages.length === 0) return;
|
|
836
|
-
await submitToStream(messages
|
|
836
|
+
await submitToStream(messages);
|
|
837
837
|
}, [onPreSend, submitToStream]);
|
|
838
838
|
const handleStop = useCallback(async () => {
|
|
839
839
|
await stream.stop();
|