@meetsmore-oss/use-ai-client 1.8.0 → 1.9.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 +57 -23
- package/dist/bundled.js.map +1 -1
- package/dist/index.d.ts +48 -6
- package/dist/index.js +57 -23
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/bundled.js
CHANGED
|
@@ -11539,7 +11539,8 @@ function ToolApprovalDialog({
|
|
|
11539
11539
|
const [showDetails, setShowDetails] = useState4(false);
|
|
11540
11540
|
const displayName = annotations?.title || toolCallName;
|
|
11541
11541
|
const isBatch = toolCount > 1;
|
|
11542
|
-
const
|
|
11542
|
+
const runtimeMessage = pendingTools.find((t) => t.message)?.message;
|
|
11543
|
+
const message = runtimeMessage ? runtimeMessage : isBatch ? strings.toolApproval.batchMessage?.replace("{count}", String(toolCount)) ?? `${toolCount} actions are waiting for your approval` : strings.toolApproval.message.replace("{toolName}", displayName);
|
|
11543
11544
|
const getToolDisplayName = (tool) => tool.annotations?.title || tool.toolCallName;
|
|
11544
11545
|
return /* @__PURE__ */ jsxs7(
|
|
11545
11546
|
"div",
|
|
@@ -35134,7 +35135,8 @@ function defineTool(description, schemaOrFn, fnOrOptions, options) {
|
|
|
35134
35135
|
let actualFn;
|
|
35135
35136
|
let actualOptions;
|
|
35136
35137
|
if (isNoParamFunction) {
|
|
35137
|
-
|
|
35138
|
+
const noParamFn = schemaOrFn;
|
|
35139
|
+
actualFn = (_input, ctx) => noParamFn(ctx);
|
|
35138
35140
|
actualOptions = fnOrOptions || {};
|
|
35139
35141
|
} else {
|
|
35140
35142
|
actualFn = fnOrOptions;
|
|
@@ -35168,21 +35170,21 @@ function defineTool(description, schemaOrFn, fnOrOptions, options) {
|
|
|
35168
35170
|
}
|
|
35169
35171
|
return toolDef;
|
|
35170
35172
|
},
|
|
35171
|
-
async _execute(input) {
|
|
35173
|
+
async _execute(input, ctx) {
|
|
35172
35174
|
const validated = this._zodSchema.parse(input);
|
|
35173
|
-
return await actualFn(validated);
|
|
35175
|
+
return await actualFn(validated, ctx);
|
|
35174
35176
|
}
|
|
35175
35177
|
};
|
|
35176
35178
|
}
|
|
35177
35179
|
function convertToolsToDefinitions(tools) {
|
|
35178
35180
|
return Object.entries(tools).map(([name, tool]) => tool._toToolDefinition(name));
|
|
35179
35181
|
}
|
|
35180
|
-
async function executeDefinedTool(tools, toolName, input) {
|
|
35182
|
+
async function executeDefinedTool(tools, toolName, input, ctx) {
|
|
35181
35183
|
const tool = tools[toolName];
|
|
35182
35184
|
if (!tool) {
|
|
35183
35185
|
throw new Error(`Tool "${toolName}" not found`);
|
|
35184
35186
|
}
|
|
35185
|
-
return await tool._execute(input);
|
|
35187
|
+
return await tool._execute(input, ctx);
|
|
35186
35188
|
}
|
|
35187
35189
|
|
|
35188
35190
|
// src/providers/chatRepository/LocalStorageChatRepository.ts
|
|
@@ -35873,6 +35875,7 @@ function useToolSystem({
|
|
|
35873
35875
|
const waitersRef = useRef7(/* @__PURE__ */ new Map());
|
|
35874
35876
|
const [pendingApprovals, setPendingApprovals] = useState9([]);
|
|
35875
35877
|
const pendingApprovalToolCallsRef = useRef7(/* @__PURE__ */ new Map());
|
|
35878
|
+
const runtimeApprovalResolversRef = useRef7(/* @__PURE__ */ new Map());
|
|
35876
35879
|
const registerTools = useCallback7((id, tools, options) => {
|
|
35877
35880
|
const existingTools = toolRegistryRef.current.get(id);
|
|
35878
35881
|
toolRegistryRef.current.set(id, tools);
|
|
@@ -35982,7 +35985,9 @@ function useToolSystem({
|
|
|
35982
35985
|
toolCallId: event.toolCallId,
|
|
35983
35986
|
toolCallName: event.toolCallName,
|
|
35984
35987
|
toolCallArgs: event.toolCallArgs,
|
|
35985
|
-
annotations: event.annotations
|
|
35988
|
+
annotations: event.annotations,
|
|
35989
|
+
message: event.message,
|
|
35990
|
+
metadata: event.metadata
|
|
35986
35991
|
}
|
|
35987
35992
|
]);
|
|
35988
35993
|
}, []);
|
|
@@ -35995,8 +36000,26 @@ function useToolSystem({
|
|
|
35995
36000
|
try {
|
|
35996
36001
|
const ownerId = toolOwnershipRef.current.get(name);
|
|
35997
36002
|
console.log(`[useToolSystem] Tool "${name}" owned by component:`, ownerId);
|
|
36003
|
+
const ctx = {
|
|
36004
|
+
requestApproval: ({ message, metadata }) => {
|
|
36005
|
+
return new Promise((resolve) => {
|
|
36006
|
+
const approvalId = `${toolCallId}-runtime-${Date.now()}`;
|
|
36007
|
+
runtimeApprovalResolversRef.current.set(approvalId, resolve);
|
|
36008
|
+
setPendingApprovals((prev) => [
|
|
36009
|
+
...prev,
|
|
36010
|
+
{
|
|
36011
|
+
toolCallId: approvalId,
|
|
36012
|
+
toolCallName: name,
|
|
36013
|
+
toolCallArgs: input || {},
|
|
36014
|
+
message,
|
|
36015
|
+
metadata
|
|
36016
|
+
}
|
|
36017
|
+
]);
|
|
36018
|
+
});
|
|
36019
|
+
}
|
|
36020
|
+
};
|
|
35998
36021
|
console.log("[useToolSystem] Executing tool...");
|
|
35999
|
-
const result = await executeDefinedTool(aggregatedToolsRef.current, name, input);
|
|
36022
|
+
const result = await executeDefinedTool(aggregatedToolsRef.current, name, input, ctx);
|
|
36000
36023
|
const isErrorResult = result && typeof result === "object" && ("error" in result || result.success === false);
|
|
36001
36024
|
const ownerIsInvisible = ownerId ? isInvisible(ownerId) : false;
|
|
36002
36025
|
if (ownerId && !isErrorResult && !ownerIsInvisible) {
|
|
@@ -36041,24 +36064,32 @@ function useToolSystem({
|
|
|
36041
36064
|
if (!clientRef.current) return;
|
|
36042
36065
|
console.log("[useToolSystem] Approving all tool calls:", pendingApprovals.length);
|
|
36043
36066
|
const pendingTools = [...pendingApprovals];
|
|
36044
|
-
for (const pending of pendingTools) {
|
|
36045
|
-
clientRef.current.sendToolApprovalResponse(pending.toolCallId, true);
|
|
36046
|
-
}
|
|
36047
36067
|
setPendingApprovals([]);
|
|
36048
|
-
for (const
|
|
36049
|
-
|
|
36068
|
+
for (const pending of pendingTools) {
|
|
36069
|
+
const runtimeResolver = runtimeApprovalResolversRef.current.get(pending.toolCallId);
|
|
36070
|
+
if (runtimeResolver) {
|
|
36071
|
+
runtimeApprovalResolversRef.current.delete(pending.toolCallId);
|
|
36072
|
+
runtimeResolver({ approved: true });
|
|
36073
|
+
} else {
|
|
36074
|
+
clientRef.current.sendToolApprovalResponse(pending.toolCallId, true);
|
|
36075
|
+
await executePendingToolAfterApproval(pending.toolCallId);
|
|
36076
|
+
}
|
|
36050
36077
|
}
|
|
36051
36078
|
}, [clientRef, pendingApprovals, executePendingToolAfterApproval]);
|
|
36052
36079
|
const rejectAll = useCallback7((reason) => {
|
|
36053
36080
|
if (!clientRef.current) return;
|
|
36054
36081
|
console.log("[useToolSystem] Rejecting all tool calls:", pendingApprovals.length, reason);
|
|
36055
36082
|
const pendingTools = [...pendingApprovals];
|
|
36056
|
-
for (const pending of pendingTools) {
|
|
36057
|
-
clientRef.current.sendToolApprovalResponse(pending.toolCallId, false, reason);
|
|
36058
|
-
}
|
|
36059
36083
|
setPendingApprovals([]);
|
|
36060
|
-
for (const
|
|
36061
|
-
|
|
36084
|
+
for (const pending of pendingTools) {
|
|
36085
|
+
const runtimeResolver = runtimeApprovalResolversRef.current.get(pending.toolCallId);
|
|
36086
|
+
if (runtimeResolver) {
|
|
36087
|
+
runtimeApprovalResolversRef.current.delete(pending.toolCallId);
|
|
36088
|
+
runtimeResolver({ approved: false, reason });
|
|
36089
|
+
} else {
|
|
36090
|
+
clientRef.current.sendToolApprovalResponse(pending.toolCallId, false, reason);
|
|
36091
|
+
pendingApprovalToolCallsRef.current.delete(pending.toolCallId);
|
|
36092
|
+
}
|
|
36062
36093
|
}
|
|
36063
36094
|
}, [clientRef, pendingApprovals]);
|
|
36064
36095
|
return {
|
|
@@ -36850,19 +36881,19 @@ function useStableTools(tools) {
|
|
|
36850
36881
|
return stableToolsRef.current;
|
|
36851
36882
|
}
|
|
36852
36883
|
function createStableToolWrapper(name, tool, latestToolsRef) {
|
|
36853
|
-
const stableHandler = (input) => {
|
|
36884
|
+
const stableHandler = (input, ctx) => {
|
|
36854
36885
|
const currentTool = latestToolsRef.current[name];
|
|
36855
36886
|
if (!currentTool) {
|
|
36856
36887
|
throw new Error(`Tool "${name}" no longer exists`);
|
|
36857
36888
|
}
|
|
36858
|
-
return currentTool.fn(input);
|
|
36889
|
+
return currentTool.fn(input, ctx);
|
|
36859
36890
|
};
|
|
36860
|
-
const stableExecute = async (input) => {
|
|
36891
|
+
const stableExecute = async (input, ctx) => {
|
|
36861
36892
|
const currentTool = latestToolsRef.current[name];
|
|
36862
36893
|
if (!currentTool) {
|
|
36863
36894
|
throw new Error(`Tool "${name}" no longer exists`);
|
|
36864
36895
|
}
|
|
36865
|
-
return await currentTool._execute(input);
|
|
36896
|
+
return await currentTool._execute(input, ctx);
|
|
36866
36897
|
};
|
|
36867
36898
|
return {
|
|
36868
36899
|
description: tool.description,
|
|
@@ -37068,7 +37099,10 @@ function useAIWorkflow(runner, workflowId) {
|
|
|
37068
37099
|
console.log(`[useAIWorkflow] Executing tool: ${toolName}`, toolArgs);
|
|
37069
37100
|
console.log(`[useAIWorkflow] Available tools:`, Object.keys(currentWorkflow.tools));
|
|
37070
37101
|
try {
|
|
37071
|
-
const
|
|
37102
|
+
const noopCtx = {
|
|
37103
|
+
requestApproval: async () => ({ approved: true })
|
|
37104
|
+
};
|
|
37105
|
+
const result = await executeDefinedTool(currentWorkflow.tools, toolName, toolArgs, noopCtx);
|
|
37072
37106
|
currentWorkflow.toolCalls.push({
|
|
37073
37107
|
toolName,
|
|
37074
37108
|
args: toolArgs,
|