UNPKG

@assistant-ui/react

Version:

Typescript/React library for AI Chat

58 lines (57 loc) 2.59 kB
"use strict"; 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/dangerous-in-browser/DangerousInBrowserAdapter.ts var DangerousInBrowserAdapter_exports = {}; __export(DangerousInBrowserAdapter_exports, { DangerousInBrowserAdapter: () => DangerousInBrowserAdapter }); module.exports = __toCommonJS(DangerousInBrowserAdapter_exports); var import_toCoreMessages = require("../edge/converters/toCoreMessages.js"); var import_toLanguageModelTools = require("../edge/converters/toLanguageModelTools.js"); var import_toolResultStream = require("../edge/streams/toolResultStream.js"); var import_EdgeModelAdapter = require("../edge/EdgeModelAdapter.js"); var import_createEdgeRuntimeAPI = require("../edge/createEdgeRuntimeAPI.js"); var import_assistant_stream = require("assistant-stream"); var DangerousInBrowserAdapter = class { constructor(options) { this.options = options; } async *run({ messages, abortSignal, context }) { const res = await (0, import_createEdgeRuntimeAPI.getEdgeRuntimeStream)({ options: this.options, abortSignal, requestData: { system: context.system, messages: (0, import_toCoreMessages.toCoreMessages)(messages), tools: context.tools ? (0, import_toLanguageModelTools.toLanguageModelTools)(context.tools) : [], ...context.callSettings, ...context.config } }); const stream = res.pipeThrough((0, import_toolResultStream.toolResultStream)(context.tools, abortSignal)).pipeThrough(new import_assistant_stream.AssistantMessageAccumulator()); for await (const update of (0, import_EdgeModelAdapter.asAsyncIterable)(stream)) { yield update; } } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { DangerousInBrowserAdapter }); //# sourceMappingURL=DangerousInBrowserAdapter.js.map