@assistant-ui/react
Version:
Typescript/React library for AI Chat
30 lines • 996 B
JavaScript
// src/runtimes/edge/streams/toolResultStream.ts
import { z } from "zod";
import { ToolExecutionStream } from "assistant-stream";
function toolResultStream(tools, abortSignal) {
return new ToolExecutionStream(({ toolCallId, toolName, args }) => {
const tool = tools?.[toolName];
if (!tool || !tool.execute) return void 0;
let executeFn = tool.execute;
if (tool.parameters instanceof z.ZodType) {
const result = tool.parameters.safeParse(args);
if (!result.success) {
executeFn = tool.experimental_onSchemaValidationError ?? (() => {
throw "Function parameter validation failed. " + JSON.stringify(result.error.issues);
});
}
}
const getResult = async () => {
const result = await executeFn(args, {
toolCallId,
abortSignal
});
return result === void 0 ? "<no result>" : result;
};
return getResult();
});
}
export {
toolResultStream
};
//# sourceMappingURL=toolResultStream.mjs.map