@assistant-ui/react
Version:
Typescript/React library for AI Chat
55 lines (54 loc) • 2.1 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/runtimes/edge/streams/toolResultStream.ts
var toolResultStream_exports = {};
__export(toolResultStream_exports, {
toolResultStream: () => toolResultStream
});
module.exports = __toCommonJS(toolResultStream_exports);
var import_zod = require("zod");
var import_assistant_stream = require("assistant-stream");
function toolResultStream(tools, abortSignal) {
return new import_assistant_stream.ToolExecutionStream(({ toolCallId, toolName, args }) => {
const tool = tools?.[toolName];
if (!tool || !tool.execute) return void 0;
let executeFn = tool.execute;
if (tool.parameters instanceof import_zod.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();
});
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
toolResultStream
});
//# sourceMappingURL=toolResultStream.js.map
;