@assistant-ui/react
Version:
React components for AI chat.
64 lines (63 loc) • 2.32 kB
JavaScript
"use client";
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/local/useLocalRuntime.tsx
var useLocalRuntime_exports = {};
__export(useLocalRuntime_exports, {
useLocalRuntime: () => useLocalRuntime
});
module.exports = __toCommonJS(useLocalRuntime_exports);
var import_react = require("react");
var import_LocalRuntimeCore = require("./LocalRuntimeCore.cjs");
var import_AssistantRuntime = require("../../api/AssistantRuntime.cjs");
var import_internal = require("../../internal.cjs");
var LocalRuntimeImpl = class _LocalRuntimeImpl extends import_AssistantRuntime.AssistantRuntimeImpl {
constructor(core, thread) {
super(core, thread);
this.core = core;
}
reset(options) {
this.core.reset(options);
}
static create(_core) {
return new _LocalRuntimeImpl(
_core,
import_AssistantRuntime.AssistantRuntimeImpl.createMainThreadRuntime(_core, import_internal.ThreadRuntimeImpl)
);
}
};
var useLocalRuntime = (adapter, { initialMessages, ...options } = {}) => {
const opt = {
...options,
adapters: {
...options.adapters,
chatModel: adapter
}
};
const [runtime] = (0, import_react.useState)(() => new import_LocalRuntimeCore.LocalRuntimeCore(opt, initialMessages));
(0, import_react.useEffect)(() => {
runtime.setOptions(opt);
});
return (0, import_react.useMemo)(() => LocalRuntimeImpl.create(runtime), [runtime]);
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
useLocalRuntime
});
//# sourceMappingURL=useLocalRuntime.js.map
;