@ash-cloud/ash-ui 0.2.4 → 0.2.5
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.cjs +44 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +44 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3666,6 +3666,8 @@ function useAgentChat(options) {
|
|
|
3666
3666
|
onSessionEnd,
|
|
3667
3667
|
onError,
|
|
3668
3668
|
onSandboxLog,
|
|
3669
|
+
canUseTool,
|
|
3670
|
+
resolveToolPermission,
|
|
3669
3671
|
onReconnect,
|
|
3670
3672
|
maxReconnectAttempts = 3,
|
|
3671
3673
|
reconnectBaseDelay = 1e3,
|
|
@@ -3699,6 +3701,23 @@ function useAgentChat(options) {
|
|
|
3699
3701
|
const emitStreamingEntries = react.useCallback((newEntries) => {
|
|
3700
3702
|
setStreamingEntries([...newEntries]);
|
|
3701
3703
|
}, []);
|
|
3704
|
+
const handleToolPermission = react.useCallback(async (event) => {
|
|
3705
|
+
if (event.type !== "tool_permission") return;
|
|
3706
|
+
if (!canUseTool) return;
|
|
3707
|
+
if (!event.requestId || !event.sessionId || !event.toolName) return;
|
|
3708
|
+
const request = {
|
|
3709
|
+
requestId: event.requestId,
|
|
3710
|
+
sessionId: event.sessionId,
|
|
3711
|
+
toolName: event.toolName,
|
|
3712
|
+
input: event.input
|
|
3713
|
+
};
|
|
3714
|
+
const allow = await canUseTool(request);
|
|
3715
|
+
if (!resolveToolPermission) {
|
|
3716
|
+
console.warn("[useAgentChat] resolveToolPermission not provided for tool permission response");
|
|
3717
|
+
return;
|
|
3718
|
+
}
|
|
3719
|
+
await resolveToolPermission(request, allow);
|
|
3720
|
+
}, [canUseTool, resolveToolPermission]);
|
|
3702
3721
|
const createTextEntry = react.useCallback((id, content) => ({
|
|
3703
3722
|
id,
|
|
3704
3723
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -3857,6 +3876,7 @@ function useAgentChat(options) {
|
|
|
3857
3876
|
for await (const event of stream) {
|
|
3858
3877
|
if (controller.signal.aborted) break;
|
|
3859
3878
|
eventCountRef.current++;
|
|
3879
|
+
await handleToolPermission(event);
|
|
3860
3880
|
localStreamingEntries = processEvent(event, localStreamingEntries);
|
|
3861
3881
|
emitStreamingEntries(localStreamingEntries);
|
|
3862
3882
|
if (event.type === "complete" || event.type === "session_end" || event.type === "error") {
|
|
@@ -3890,7 +3910,7 @@ function useAgentChat(options) {
|
|
|
3890
3910
|
}
|
|
3891
3911
|
return false;
|
|
3892
3912
|
}
|
|
3893
|
-
}, [subscribeToSession, maxReconnectAttempts, reconnectBaseDelay, onReconnect, processEvent, emitStreamingEntries]);
|
|
3913
|
+
}, [subscribeToSession, maxReconnectAttempts, reconnectBaseDelay, onReconnect, processEvent, emitStreamingEntries, handleToolPermission]);
|
|
3894
3914
|
const send = react.useCallback(async (prompt) => {
|
|
3895
3915
|
if (isStreaming) return;
|
|
3896
3916
|
let finalPrompt = prompt;
|
|
@@ -3969,6 +3989,7 @@ function useAgentChat(options) {
|
|
|
3969
3989
|
console.error("[useAgentChat] onEvent error:", err);
|
|
3970
3990
|
}
|
|
3971
3991
|
}
|
|
3992
|
+
await handleToolPermission(event);
|
|
3972
3993
|
let processedEvent = event;
|
|
3973
3994
|
if (middleware?.length) {
|
|
3974
3995
|
processedEvent = await applyEventMiddleware(middleware, event);
|
|
@@ -4018,7 +4039,7 @@ function useAgentChat(options) {
|
|
|
4018
4039
|
abortControllerRef.current = null;
|
|
4019
4040
|
resetStreamingState();
|
|
4020
4041
|
}
|
|
4021
|
-
}, [isStreaming, sessionId, historyEntries, streamingEntries, createStream, subscribeToSession, processEvent, emitStreamingEntries, resetStreamingState, onError, attemptReconnect, onBeforeSend, onEvent, middleware]);
|
|
4042
|
+
}, [isStreaming, sessionId, historyEntries, streamingEntries, createStream, subscribeToSession, processEvent, emitStreamingEntries, resetStreamingState, onError, attemptReconnect, onBeforeSend, onEvent, middleware, handleToolPermission]);
|
|
4022
4043
|
const stop = react.useCallback(() => {
|
|
4023
4044
|
reconnectAttemptsRef.current = maxReconnectAttempts + 1;
|
|
4024
4045
|
setIsReconnecting(false);
|
|
@@ -4069,6 +4090,8 @@ function useChat(options) {
|
|
|
4069
4090
|
initialSessionId,
|
|
4070
4091
|
initialMessages = [],
|
|
4071
4092
|
onToolCall,
|
|
4093
|
+
canUseTool,
|
|
4094
|
+
resolveToolPermission,
|
|
4072
4095
|
onFinish,
|
|
4073
4096
|
onError,
|
|
4074
4097
|
onSessionStart,
|
|
@@ -4103,6 +4126,23 @@ function useChat(options) {
|
|
|
4103
4126
|
return prev;
|
|
4104
4127
|
});
|
|
4105
4128
|
}, []);
|
|
4129
|
+
const handleToolPermission = react.useCallback(async (event) => {
|
|
4130
|
+
if (event.type !== "tool_permission") return;
|
|
4131
|
+
if (!canUseTool) return;
|
|
4132
|
+
if (!event.requestId || !event.sessionId || !event.toolName) return;
|
|
4133
|
+
const request = {
|
|
4134
|
+
requestId: event.requestId,
|
|
4135
|
+
sessionId: event.sessionId,
|
|
4136
|
+
toolName: event.toolName,
|
|
4137
|
+
input: event.input
|
|
4138
|
+
};
|
|
4139
|
+
const allow = await canUseTool(request);
|
|
4140
|
+
if (!resolveToolPermission) {
|
|
4141
|
+
console.warn("[useChat] resolveToolPermission not provided for tool permission response");
|
|
4142
|
+
return;
|
|
4143
|
+
}
|
|
4144
|
+
await resolveToolPermission(request, allow);
|
|
4145
|
+
}, [canUseTool, resolveToolPermission]);
|
|
4106
4146
|
const processEvent = react.useCallback((event) => {
|
|
4107
4147
|
switch (event.type) {
|
|
4108
4148
|
case "session_start":
|
|
@@ -4222,6 +4262,7 @@ function useChat(options) {
|
|
|
4222
4262
|
const stream = createStream(finalPrompt, sessionIdRef.current || void 0, streamOptions);
|
|
4223
4263
|
for await (const event of stream) {
|
|
4224
4264
|
if (controller.signal.aborted) break;
|
|
4265
|
+
await handleToolPermission(event);
|
|
4225
4266
|
let processedEvent = event;
|
|
4226
4267
|
if (middleware?.length) {
|
|
4227
4268
|
processedEvent = await applyEventMiddleware(middleware, event);
|
|
@@ -4251,7 +4292,7 @@ function useChat(options) {
|
|
|
4251
4292
|
abortControllerRef.current = null;
|
|
4252
4293
|
currentAssistantMessageRef.current = null;
|
|
4253
4294
|
}
|
|
4254
|
-
}, [isLoading, createStream, processEvent, middleware, onError]);
|
|
4295
|
+
}, [isLoading, createStream, processEvent, middleware, onError, handleToolPermission]);
|
|
4255
4296
|
const stop = react.useCallback(() => {
|
|
4256
4297
|
reconnectAttemptsRef.current = maxReconnectAttempts + 1;
|
|
4257
4298
|
setIsReconnecting(false);
|