@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/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export { z } from 'zod';
|
|
3
|
-
import
|
|
4
|
-
import { ToolAnnotations, ToolDefinition, WorkflowStatus, FeedbackValue, AgentInfo, McpHeadersMap, MultimodalContent, AGUIEvent, Message as Message$1, UseAIClientMessage } from '@meetsmore-oss/use-ai-core';
|
|
3
|
+
import { ToolAnnotations, ToolDefinition, WorkflowStatus, FeedbackValue, AgentInfo, MultimodalContent, UseAIForwardedProps, AGUIEvent, Message as Message$1, UseAIClientMessage } from '@meetsmore-oss/use-ai-core';
|
|
5
4
|
export { AgentInfo, ToolAnnotations, ToolDefinition } from '@meetsmore-oss/use-ai-core';
|
|
6
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
7
6
|
import React$1, { ReactNode } from 'react';
|
|
@@ -941,7 +940,6 @@ declare class UseAIClient {
|
|
|
941
940
|
private _tools;
|
|
942
941
|
private _messages;
|
|
943
942
|
private _state;
|
|
944
|
-
private mcpHeadersProvider?;
|
|
945
943
|
private _availableAgents;
|
|
946
944
|
private _defaultAgent;
|
|
947
945
|
private _selectedAgent;
|
|
@@ -982,20 +980,15 @@ declare class UseAIClient {
|
|
|
982
980
|
* @param state - The current state object to provide to the AI
|
|
983
981
|
*/
|
|
984
982
|
updateState(state: unknown): void;
|
|
985
|
-
/**
|
|
986
|
-
* Sets the MCP headers provider.
|
|
987
|
-
* The provider will be called each time a message is sent to get fresh headers.
|
|
988
|
-
*
|
|
989
|
-
* @param provider - Function that returns MCP headers configuration
|
|
990
|
-
*/
|
|
991
|
-
setMcpHeadersProvider(provider: () => McpHeadersMap | Promise<McpHeadersMap>): void;
|
|
992
983
|
/**
|
|
993
984
|
* Sends a user prompt to the AI.
|
|
994
985
|
*
|
|
995
986
|
* @param prompt - The user's prompt/question (text part)
|
|
996
987
|
* @param multimodalContent - Optional multimodal content (text, images, files)
|
|
988
|
+
* @param forwardedProps - Optional props to forward to the server (e.g., telemetryMetadata, mcpHeaders).
|
|
989
|
+
* Internally merged with other forwardedProps.
|
|
997
990
|
*/
|
|
998
|
-
sendPrompt(prompt: string, multimodalContent?: MultimodalContent[]): Promise<void>;
|
|
991
|
+
sendPrompt(prompt: string, multimodalContent?: MultimodalContent[], forwardedProps?: UseAIForwardedProps): Promise<void>;
|
|
999
992
|
/**
|
|
1000
993
|
* Sends the result of a tool execution back to the server.
|
|
1001
994
|
*
|
|
@@ -1162,6 +1155,11 @@ interface SendMessageOptions {
|
|
|
1162
1155
|
openChat?: boolean;
|
|
1163
1156
|
/** Metadata to set on the new chat (only used when newChat: true) */
|
|
1164
1157
|
metadata?: ChatMetadata;
|
|
1158
|
+
/**
|
|
1159
|
+
* Forwarded props for observability and configuration (e.g., telemetryMetadata, mcpHeaders).
|
|
1160
|
+
* This is merged with provider-level forwardedProps (message-level takes precedence).
|
|
1161
|
+
*/
|
|
1162
|
+
forwardedProps?: UseAIForwardedProps;
|
|
1165
1163
|
}
|
|
1166
1164
|
interface UseChatManagementOptions {
|
|
1167
1165
|
/** Chat repository for persistence */
|
|
@@ -1173,7 +1171,7 @@ interface UseChatManagementOptions {
|
|
|
1173
1171
|
/** Setter for messages state (owned by provider) */
|
|
1174
1172
|
setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
|
|
1175
1173
|
/** Callback to send a message (from UseAIProvider) */
|
|
1176
|
-
onSendMessage?: (message: string, attachments?: FileAttachment[]) => Promise<void>;
|
|
1174
|
+
onSendMessage?: (message: string, attachments?: FileAttachment[], forwardedProps?: UseAIForwardedProps) => Promise<void>;
|
|
1177
1175
|
/** Callback to open/close the chat panel */
|
|
1178
1176
|
setOpen?: (open: boolean) => void;
|
|
1179
1177
|
/** Whether the client is connected */
|
|
@@ -1407,33 +1405,41 @@ interface UseAIProviderProps extends UseAIConfig {
|
|
|
1407
1405
|
*/
|
|
1408
1406
|
chatRepository?: ChatRepository;
|
|
1409
1407
|
/**
|
|
1410
|
-
*
|
|
1411
|
-
* Called each
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
1414
|
-
* Patterns can be:
|
|
1415
|
-
* - Constant strings: `https://api.example.com` - Exact match
|
|
1416
|
-
* - Glob patterns: `https://*.meetsmore.com` - Wildcard matching using picomatch
|
|
1408
|
+
* Provider function for forwarded props (telemetry metadata, MCP headers, etc.).
|
|
1409
|
+
* Called before each message is sent. Can be sync or async.
|
|
1410
|
+
* Props from this provider are merged with message-level forwardedProps,
|
|
1411
|
+
* with message-level taking precedence.
|
|
1417
1412
|
*
|
|
1418
1413
|
* @example
|
|
1419
|
-
* ```
|
|
1420
|
-
*
|
|
1421
|
-
*
|
|
1422
|
-
*
|
|
1423
|
-
*
|
|
1424
|
-
*
|
|
1425
|
-
*
|
|
1426
|
-
*
|
|
1427
|
-
*
|
|
1428
|
-
*
|
|
1429
|
-
*
|
|
1430
|
-
*
|
|
1431
|
-
*
|
|
1432
|
-
*
|
|
1433
|
-
*
|
|
1414
|
+
* ```tsx
|
|
1415
|
+
* <UseAIProvider
|
|
1416
|
+
* serverUrl="wss://your-server.com"
|
|
1417
|
+
* forwardedPropsProvider={() => ({
|
|
1418
|
+
* mcpHeaders: {
|
|
1419
|
+
* // Exact match
|
|
1420
|
+
* 'https://api.example.com': {
|
|
1421
|
+
* headers: { 'Authorization': `Bearer ${userToken}` }
|
|
1422
|
+
* },
|
|
1423
|
+
* // Wildcard subdomain
|
|
1424
|
+
* 'https://*.meetsmore.com': {
|
|
1425
|
+
* headers: { 'X-API-Key': apiKey }
|
|
1426
|
+
* },
|
|
1427
|
+
* // Multiple wildcards
|
|
1428
|
+
* '*://*.example.com': {
|
|
1429
|
+
* headers: { 'X-Custom': 'value' }
|
|
1430
|
+
* },
|
|
1431
|
+
* },
|
|
1432
|
+
* telemetryMetadata: {
|
|
1433
|
+
* userId: currentUser.id,
|
|
1434
|
+
* tenantId: tenant.id,
|
|
1435
|
+
* },
|
|
1436
|
+
* })}
|
|
1437
|
+
* >
|
|
1438
|
+
* <App />
|
|
1439
|
+
* </UseAIProvider>
|
|
1434
1440
|
* ```
|
|
1435
1441
|
*/
|
|
1436
|
-
|
|
1442
|
+
forwardedPropsProvider?: () => UseAIForwardedProps | Promise<UseAIForwardedProps>;
|
|
1437
1443
|
/**
|
|
1438
1444
|
* Configuration for file uploads.
|
|
1439
1445
|
* File upload is enabled by default with EmbedFileUploadBackend, 10MB max size,
|
|
@@ -1547,7 +1553,7 @@ interface UseAIProviderProps extends UseAIConfig {
|
|
|
1547
1553
|
* }
|
|
1548
1554
|
* ```
|
|
1549
1555
|
*/
|
|
1550
|
-
declare function UseAIProvider({ serverUrl, children, systemPrompt, CustomButton, CustomChat, chatRepository,
|
|
1556
|
+
declare function UseAIProvider({ serverUrl, children, systemPrompt, CustomButton, CustomChat, chatRepository, forwardedPropsProvider, fileUploadConfig: fileUploadConfigProp, commandRepository, renderChat, theme: customTheme, strings: customStrings, visibleAgentIds, onOpenChange, }: UseAIProviderProps): react_jsx_runtime.JSX.Element;
|
|
1551
1557
|
/**
|
|
1552
1558
|
* Hook to access the UseAI context.
|
|
1553
1559
|
* When used outside a UseAIProvider, returns a no-op context and logs a warning.
|
package/dist/index.js
CHANGED
|
@@ -3072,8 +3072,6 @@ var UseAIClient = class {
|
|
|
3072
3072
|
_tools = [];
|
|
3073
3073
|
_messages = [];
|
|
3074
3074
|
_state = null;
|
|
3075
|
-
// MCP headers provider
|
|
3076
|
-
mcpHeadersProvider;
|
|
3077
3075
|
// Agent selection
|
|
3078
3076
|
_availableAgents = [];
|
|
3079
3077
|
_defaultAgent = null;
|
|
@@ -3232,22 +3230,15 @@ var UseAIClient = class {
|
|
|
3232
3230
|
updateState(state) {
|
|
3233
3231
|
this._state = state;
|
|
3234
3232
|
}
|
|
3235
|
-
/**
|
|
3236
|
-
* Sets the MCP headers provider.
|
|
3237
|
-
* The provider will be called each time a message is sent to get fresh headers.
|
|
3238
|
-
*
|
|
3239
|
-
* @param provider - Function that returns MCP headers configuration
|
|
3240
|
-
*/
|
|
3241
|
-
setMcpHeadersProvider(provider) {
|
|
3242
|
-
this.mcpHeadersProvider = provider;
|
|
3243
|
-
}
|
|
3244
3233
|
/**
|
|
3245
3234
|
* Sends a user prompt to the AI.
|
|
3246
3235
|
*
|
|
3247
3236
|
* @param prompt - The user's prompt/question (text part)
|
|
3248
3237
|
* @param multimodalContent - Optional multimodal content (text, images, files)
|
|
3238
|
+
* @param forwardedProps - Optional props to forward to the server (e.g., telemetryMetadata, mcpHeaders).
|
|
3239
|
+
* Internally merged with other forwardedProps.
|
|
3249
3240
|
*/
|
|
3250
|
-
async sendPrompt(prompt, multimodalContent) {
|
|
3241
|
+
async sendPrompt(prompt, multimodalContent, forwardedProps) {
|
|
3251
3242
|
let messageContent = prompt;
|
|
3252
3243
|
if (multimodalContent && multimodalContent.length > 0) {
|
|
3253
3244
|
messageContent = multimodalContent.map((part) => {
|
|
@@ -3277,14 +3268,6 @@ var UseAIClient = class {
|
|
|
3277
3268
|
// Type cast needed for Message type compatibility
|
|
3278
3269
|
};
|
|
3279
3270
|
this._messages.push(userMessage);
|
|
3280
|
-
let mcpHeaders;
|
|
3281
|
-
if (this.mcpHeadersProvider) {
|
|
3282
|
-
try {
|
|
3283
|
-
mcpHeaders = await this.mcpHeadersProvider();
|
|
3284
|
-
} catch (error) {
|
|
3285
|
-
console.error("[UseAIClient] Failed to get MCP headers:", error);
|
|
3286
|
-
}
|
|
3287
|
-
}
|
|
3288
3271
|
const runInput = {
|
|
3289
3272
|
threadId: this.threadId,
|
|
3290
3273
|
// Use getter to ensure non-null
|
|
@@ -3299,8 +3282,8 @@ var UseAIClient = class {
|
|
|
3299
3282
|
state: this._state,
|
|
3300
3283
|
context: [],
|
|
3301
3284
|
forwardedProps: {
|
|
3302
|
-
...
|
|
3303
|
-
...
|
|
3285
|
+
...this._selectedAgent ? { agent: this._selectedAgent } : {},
|
|
3286
|
+
...forwardedProps || {}
|
|
3304
3287
|
}
|
|
3305
3288
|
};
|
|
3306
3289
|
this.send({
|
|
@@ -4104,7 +4087,7 @@ function useChatManagement({
|
|
|
4104
4087
|
isProcessingQueueRef.current = true;
|
|
4105
4088
|
while (pendingMessagesRef.current.length > 0) {
|
|
4106
4089
|
const { message, options } = pendingMessagesRef.current.shift();
|
|
4107
|
-
const { newChat = false, attachments = [], openChat = true, metadata } = options ?? {};
|
|
4090
|
+
const { newChat = false, attachments = [], openChat = true, metadata, forwardedProps } = options ?? {};
|
|
4108
4091
|
if (newChat) {
|
|
4109
4092
|
await createNewChat({ metadata });
|
|
4110
4093
|
}
|
|
@@ -4126,7 +4109,7 @@ function useChatManagement({
|
|
|
4126
4109
|
};
|
|
4127
4110
|
})
|
|
4128
4111
|
);
|
|
4129
|
-
await onSendMessage(message, fileAttachments.length > 0 ? fileAttachments : void 0);
|
|
4112
|
+
await onSendMessage(message, fileAttachments.length > 0 ? fileAttachments : void 0, forwardedProps);
|
|
4130
4113
|
if (openChat && setOpen) {
|
|
4131
4114
|
setOpen(true);
|
|
4132
4115
|
}
|
|
@@ -4794,7 +4777,7 @@ function UseAIProvider({
|
|
|
4794
4777
|
CustomButton,
|
|
4795
4778
|
CustomChat,
|
|
4796
4779
|
chatRepository,
|
|
4797
|
-
|
|
4780
|
+
forwardedPropsProvider,
|
|
4798
4781
|
fileUploadConfig: fileUploadConfigProp,
|
|
4799
4782
|
commandRepository,
|
|
4800
4783
|
renderChat = true,
|
|
@@ -4845,9 +4828,9 @@ function UseAIProvider({
|
|
|
4845
4828
|
clientRef,
|
|
4846
4829
|
connected
|
|
4847
4830
|
});
|
|
4848
|
-
const stableSendMessage = useCallback11(async (message, attachments) => {
|
|
4831
|
+
const stableSendMessage = useCallback11(async (message, attachments, forwardedProps) => {
|
|
4849
4832
|
if (handleSendMessageRef.current) {
|
|
4850
|
-
await handleSendMessageRef.current(message, attachments);
|
|
4833
|
+
await handleSendMessageRef.current(message, attachments, forwardedProps);
|
|
4851
4834
|
}
|
|
4852
4835
|
}, []);
|
|
4853
4836
|
const toolExecution = useToolExecution({
|
|
@@ -4907,9 +4890,6 @@ function UseAIProvider({
|
|
|
4907
4890
|
useEffect10(() => {
|
|
4908
4891
|
console.log("[UseAIProvider] Initializing client with serverUrl:", serverUrl);
|
|
4909
4892
|
const client = new UseAIClient(serverUrl);
|
|
4910
|
-
if (mcpHeadersProvider) {
|
|
4911
|
-
client.setMcpHeadersProvider(mcpHeadersProvider);
|
|
4912
|
-
}
|
|
4913
4893
|
const unsubscribeConnection = client.onConnectionStateChange((isConnected) => {
|
|
4914
4894
|
console.log("[UseAIProvider] Connection state changed:", isConnected);
|
|
4915
4895
|
setConnected(isConnected);
|
|
@@ -4983,13 +4963,6 @@ function UseAIProvider({
|
|
|
4983
4963
|
client.disconnect();
|
|
4984
4964
|
};
|
|
4985
4965
|
}, [serverUrl]);
|
|
4986
|
-
useEffect10(() => {
|
|
4987
|
-
const client = clientRef.current;
|
|
4988
|
-
if (!client) return;
|
|
4989
|
-
if (mcpHeadersProvider) {
|
|
4990
|
-
client.setMcpHeadersProvider(mcpHeadersProvider);
|
|
4991
|
-
}
|
|
4992
|
-
}, [mcpHeadersProvider]);
|
|
4993
4966
|
const lastRegisteredToolsRef = useRef11("");
|
|
4994
4967
|
useEffect10(() => {
|
|
4995
4968
|
const client = clientRef.current;
|
|
@@ -5009,7 +4982,7 @@ function UseAIProvider({
|
|
|
5009
4982
|
console.error("Failed to register tools:", err);
|
|
5010
4983
|
}
|
|
5011
4984
|
}, [hasTools, aggregatedTools, connected]);
|
|
5012
|
-
const handleSendMessage = useCallback11(async (message, attachments) => {
|
|
4985
|
+
const handleSendMessage = useCallback11(async (message, attachments, messageForwardedProps) => {
|
|
5013
4986
|
if (!clientRef.current) return;
|
|
5014
4987
|
setStreamingText("");
|
|
5015
4988
|
const activatedChatId = activatePendingChat();
|
|
@@ -5063,8 +5036,18 @@ function UseAIProvider({
|
|
|
5063
5036
|
}
|
|
5064
5037
|
setLoading(true);
|
|
5065
5038
|
}
|
|
5066
|
-
|
|
5067
|
-
|
|
5039
|
+
const providerResult = forwardedPropsProvider ? forwardedPropsProvider() : {};
|
|
5040
|
+
const providerProps = providerResult instanceof Promise ? await providerResult : providerResult;
|
|
5041
|
+
const mergedForwardedProps = {
|
|
5042
|
+
...providerProps,
|
|
5043
|
+
...messageForwardedProps
|
|
5044
|
+
};
|
|
5045
|
+
await clientRef.current.sendPrompt(
|
|
5046
|
+
message,
|
|
5047
|
+
multimodalContent,
|
|
5048
|
+
Object.keys(mergedForwardedProps).length > 0 ? mergedForwardedProps : void 0
|
|
5049
|
+
);
|
|
5050
|
+
}, [activatePendingChat, currentChatId, saveUserMessage, fileUploadConfig, getCurrentChat, forwardedPropsProvider]);
|
|
5068
5051
|
handleSendMessageRef.current = handleSendMessage;
|
|
5069
5052
|
const value = {
|
|
5070
5053
|
serverUrl,
|