UNPKG

@assistant-ui/react

Version:

Typescript/React library for AI Chat

72 lines (71 loc) 2.56 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/api/ContentPartRuntime.ts var ContentPartRuntime_exports = {}; __export(ContentPartRuntime_exports, { ContentPartRuntimeImpl: () => ContentPartRuntimeImpl }); module.exports = __toCommonJS(ContentPartRuntime_exports); var ContentPartRuntimeImpl = class { constructor(contentBinding, messageApi, threadApi) { this.contentBinding = contentBinding; this.messageApi = messageApi; this.threadApi = threadApi; } get path() { return this.contentBinding.path; } __internal_bindMethods() { this.addToolResult = this.addToolResult.bind(this); this.getState = this.getState.bind(this); this.subscribe = this.subscribe.bind(this); } getState() { return this.contentBinding.getState(); } addToolResult(result) { const state = this.contentBinding.getState(); if (!state) throw new Error("Content part is not available"); if (state.type !== "tool-call") throw new Error("Tried to add tool result to non-tool content part"); if (!this.messageApi) throw new Error( "Message API is not available. This is likely a bug in assistant-ui." ); if (!this.threadApi) throw new Error("Thread API is not available"); const message = this.messageApi.getState(); if (!message) throw new Error("Message is not available"); const toolName = state.toolName; const toolCallId = state.toolCallId; this.threadApi.getState().addToolResult({ messageId: message.id, toolName, toolCallId, result }); } subscribe(callback) { return this.contentBinding.subscribe(callback); } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { ContentPartRuntimeImpl }); //# sourceMappingURL=ContentPartRuntime.js.map