@meetsmore-oss/use-ai-client 1.6.0 → 1.7.0
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/bundled.js +23 -40
- package/dist/bundled.js.map +1 -1
- package/dist/index.d.ts +42 -36
- package/dist/index.js +23 -40
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/bundled.js
CHANGED
|
@@ -20817,8 +20817,6 @@ var UseAIClient = class {
|
|
|
20817
20817
|
_tools = [];
|
|
20818
20818
|
_messages = [];
|
|
20819
20819
|
_state = null;
|
|
20820
|
-
// MCP headers provider
|
|
20821
|
-
mcpHeadersProvider;
|
|
20822
20820
|
// Agent selection
|
|
20823
20821
|
_availableAgents = [];
|
|
20824
20822
|
_defaultAgent = null;
|
|
@@ -20977,22 +20975,15 @@ var UseAIClient = class {
|
|
|
20977
20975
|
updateState(state) {
|
|
20978
20976
|
this._state = state;
|
|
20979
20977
|
}
|
|
20980
|
-
/**
|
|
20981
|
-
* Sets the MCP headers provider.
|
|
20982
|
-
* The provider will be called each time a message is sent to get fresh headers.
|
|
20983
|
-
*
|
|
20984
|
-
* @param provider - Function that returns MCP headers configuration
|
|
20985
|
-
*/
|
|
20986
|
-
setMcpHeadersProvider(provider) {
|
|
20987
|
-
this.mcpHeadersProvider = provider;
|
|
20988
|
-
}
|
|
20989
20978
|
/**
|
|
20990
20979
|
* Sends a user prompt to the AI.
|
|
20991
20980
|
*
|
|
20992
20981
|
* @param prompt - The user's prompt/question (text part)
|
|
20993
20982
|
* @param multimodalContent - Optional multimodal content (text, images, files)
|
|
20983
|
+
* @param forwardedProps - Optional props to forward to the server (e.g., telemetryMetadata, mcpHeaders).
|
|
20984
|
+
* Internally merged with other forwardedProps.
|
|
20994
20985
|
*/
|
|
20995
|
-
async sendPrompt(prompt, multimodalContent) {
|
|
20986
|
+
async sendPrompt(prompt, multimodalContent, forwardedProps) {
|
|
20996
20987
|
let messageContent = prompt;
|
|
20997
20988
|
if (multimodalContent && multimodalContent.length > 0) {
|
|
20998
20989
|
messageContent = multimodalContent.map((part) => {
|
|
@@ -21022,14 +21013,6 @@ var UseAIClient = class {
|
|
|
21022
21013
|
// Type cast needed for Message type compatibility
|
|
21023
21014
|
};
|
|
21024
21015
|
this._messages.push(userMessage);
|
|
21025
|
-
let mcpHeaders;
|
|
21026
|
-
if (this.mcpHeadersProvider) {
|
|
21027
|
-
try {
|
|
21028
|
-
mcpHeaders = await this.mcpHeadersProvider();
|
|
21029
|
-
} catch (error48) {
|
|
21030
|
-
console.error("[UseAIClient] Failed to get MCP headers:", error48);
|
|
21031
|
-
}
|
|
21032
|
-
}
|
|
21033
21016
|
const runInput = {
|
|
21034
21017
|
threadId: this.threadId,
|
|
21035
21018
|
// Use getter to ensure non-null
|
|
@@ -21044,8 +21027,8 @@ var UseAIClient = class {
|
|
|
21044
21027
|
state: this._state,
|
|
21045
21028
|
context: [],
|
|
21046
21029
|
forwardedProps: {
|
|
21047
|
-
...
|
|
21048
|
-
...
|
|
21030
|
+
...this._selectedAgent ? { agent: this._selectedAgent } : {},
|
|
21031
|
+
...forwardedProps || {}
|
|
21049
21032
|
}
|
|
21050
21033
|
};
|
|
21051
21034
|
this.send({
|
|
@@ -35616,7 +35599,7 @@ function useChatManagement({
|
|
|
35616
35599
|
isProcessingQueueRef.current = true;
|
|
35617
35600
|
while (pendingMessagesRef.current.length > 0) {
|
|
35618
35601
|
const { message, options } = pendingMessagesRef.current.shift();
|
|
35619
|
-
const { newChat = false, attachments = [], openChat = true, metadata } = options ?? {};
|
|
35602
|
+
const { newChat = false, attachments = [], openChat = true, metadata, forwardedProps } = options ?? {};
|
|
35620
35603
|
if (newChat) {
|
|
35621
35604
|
await createNewChat({ metadata });
|
|
35622
35605
|
}
|
|
@@ -35638,7 +35621,7 @@ function useChatManagement({
|
|
|
35638
35621
|
};
|
|
35639
35622
|
})
|
|
35640
35623
|
);
|
|
35641
|
-
await onSendMessage(message, fileAttachments.length > 0 ? fileAttachments : void 0);
|
|
35624
|
+
await onSendMessage(message, fileAttachments.length > 0 ? fileAttachments : void 0, forwardedProps);
|
|
35642
35625
|
if (openChat && setOpen) {
|
|
35643
35626
|
setOpen(true);
|
|
35644
35627
|
}
|
|
@@ -36306,7 +36289,7 @@ function UseAIProvider({
|
|
|
36306
36289
|
CustomButton,
|
|
36307
36290
|
CustomChat,
|
|
36308
36291
|
chatRepository,
|
|
36309
|
-
|
|
36292
|
+
forwardedPropsProvider,
|
|
36310
36293
|
fileUploadConfig: fileUploadConfigProp,
|
|
36311
36294
|
commandRepository,
|
|
36312
36295
|
renderChat = true,
|
|
@@ -36357,9 +36340,9 @@ function UseAIProvider({
|
|
|
36357
36340
|
clientRef,
|
|
36358
36341
|
connected
|
|
36359
36342
|
});
|
|
36360
|
-
const stableSendMessage = useCallback11(async (message, attachments) => {
|
|
36343
|
+
const stableSendMessage = useCallback11(async (message, attachments, forwardedProps) => {
|
|
36361
36344
|
if (handleSendMessageRef.current) {
|
|
36362
|
-
await handleSendMessageRef.current(message, attachments);
|
|
36345
|
+
await handleSendMessageRef.current(message, attachments, forwardedProps);
|
|
36363
36346
|
}
|
|
36364
36347
|
}, []);
|
|
36365
36348
|
const toolExecution = useToolExecution({
|
|
@@ -36419,9 +36402,6 @@ function UseAIProvider({
|
|
|
36419
36402
|
useEffect10(() => {
|
|
36420
36403
|
console.log("[UseAIProvider] Initializing client with serverUrl:", serverUrl);
|
|
36421
36404
|
const client = new UseAIClient(serverUrl);
|
|
36422
|
-
if (mcpHeadersProvider) {
|
|
36423
|
-
client.setMcpHeadersProvider(mcpHeadersProvider);
|
|
36424
|
-
}
|
|
36425
36405
|
const unsubscribeConnection = client.onConnectionStateChange((isConnected) => {
|
|
36426
36406
|
console.log("[UseAIProvider] Connection state changed:", isConnected);
|
|
36427
36407
|
setConnected(isConnected);
|
|
@@ -36495,13 +36475,6 @@ function UseAIProvider({
|
|
|
36495
36475
|
client.disconnect();
|
|
36496
36476
|
};
|
|
36497
36477
|
}, [serverUrl]);
|
|
36498
|
-
useEffect10(() => {
|
|
36499
|
-
const client = clientRef.current;
|
|
36500
|
-
if (!client) return;
|
|
36501
|
-
if (mcpHeadersProvider) {
|
|
36502
|
-
client.setMcpHeadersProvider(mcpHeadersProvider);
|
|
36503
|
-
}
|
|
36504
|
-
}, [mcpHeadersProvider]);
|
|
36505
36478
|
const lastRegisteredToolsRef = useRef11("");
|
|
36506
36479
|
useEffect10(() => {
|
|
36507
36480
|
const client = clientRef.current;
|
|
@@ -36521,7 +36494,7 @@ function UseAIProvider({
|
|
|
36521
36494
|
console.error("Failed to register tools:", err);
|
|
36522
36495
|
}
|
|
36523
36496
|
}, [hasTools, aggregatedTools, connected]);
|
|
36524
|
-
const handleSendMessage = useCallback11(async (message, attachments) => {
|
|
36497
|
+
const handleSendMessage = useCallback11(async (message, attachments, messageForwardedProps) => {
|
|
36525
36498
|
if (!clientRef.current) return;
|
|
36526
36499
|
setStreamingText("");
|
|
36527
36500
|
const activatedChatId = activatePendingChat();
|
|
@@ -36575,8 +36548,18 @@ function UseAIProvider({
|
|
|
36575
36548
|
}
|
|
36576
36549
|
setLoading(true);
|
|
36577
36550
|
}
|
|
36578
|
-
|
|
36579
|
-
|
|
36551
|
+
const providerResult = forwardedPropsProvider ? forwardedPropsProvider() : {};
|
|
36552
|
+
const providerProps = providerResult instanceof Promise ? await providerResult : providerResult;
|
|
36553
|
+
const mergedForwardedProps = {
|
|
36554
|
+
...providerProps,
|
|
36555
|
+
...messageForwardedProps
|
|
36556
|
+
};
|
|
36557
|
+
await clientRef.current.sendPrompt(
|
|
36558
|
+
message,
|
|
36559
|
+
multimodalContent,
|
|
36560
|
+
Object.keys(mergedForwardedProps).length > 0 ? mergedForwardedProps : void 0
|
|
36561
|
+
);
|
|
36562
|
+
}, [activatePendingChat, currentChatId, saveUserMessage, fileUploadConfig, getCurrentChat, forwardedPropsProvider]);
|
|
36580
36563
|
handleSendMessageRef.current = handleSendMessage;
|
|
36581
36564
|
const value2 = {
|
|
36582
36565
|
serverUrl,
|