@assistant-ui/react
Version:
Typescript/React library for AI Chat
99 lines (98 loc) • 4.11 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/context/react/AttachmentContext.ts
var AttachmentContext_exports = {};
__export(AttachmentContext_exports, {
AttachmentContext: () => AttachmentContext,
useAttachment: () => useAttachment,
useAttachmentRuntime: () => useAttachmentRuntime,
useEditComposerAttachment: () => useEditComposerAttachment,
useEditComposerAttachmentRuntime: () => useEditComposerAttachmentRuntime,
useMessageAttachment: () => useMessageAttachment,
useMessageAttachmentRuntime: () => useMessageAttachmentRuntime,
useThreadComposerAttachment: () => useThreadComposerAttachment,
useThreadComposerAttachmentRuntime: () => useThreadComposerAttachmentRuntime
});
module.exports = __toCommonJS(AttachmentContext_exports);
var import_react = require("react");
var import_createContextHook = require("./utils/createContextHook.js");
var import_createStateHookForRuntime = require("./utils/createStateHookForRuntime.js");
var AttachmentContext = (0, import_react.createContext)(
null
);
var useAttachmentContext = (0, import_createContextHook.createContextHook)(
AttachmentContext,
"a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component"
);
function useAttachmentRuntime(options) {
const attachmentRuntime = useAttachmentContext(options);
if (!attachmentRuntime) return null;
return attachmentRuntime.useAttachmentRuntime();
}
function useThreadComposerAttachmentRuntime(options) {
const attachmentRuntime = useAttachmentRuntime(options);
if (!attachmentRuntime) return null;
if (attachmentRuntime.source !== "thread-composer")
throw new Error(
"This component must be used within a thread's ComposerPrimitive.Attachments component."
);
return attachmentRuntime;
}
function useEditComposerAttachmentRuntime(options) {
const attachmentRuntime = useAttachmentRuntime(options);
if (!attachmentRuntime) return null;
if (attachmentRuntime.source !== "edit-composer")
throw new Error(
"This component must be used within a message's ComposerPrimitive.Attachments component."
);
return attachmentRuntime;
}
function useMessageAttachmentRuntime(options) {
const attachmentRuntime = useAttachmentRuntime(options);
if (!attachmentRuntime) return null;
if (attachmentRuntime.source !== "message")
throw new Error(
"This component must be used within a MessagePrimitive.Attachments component."
);
return attachmentRuntime;
}
var useAttachment = (0, import_createStateHookForRuntime.createStateHookForRuntime)(useAttachmentRuntime);
var useThreadComposerAttachment = (0, import_createStateHookForRuntime.createStateHookForRuntime)(
useThreadComposerAttachmentRuntime
);
var useEditComposerAttachment = (0, import_createStateHookForRuntime.createStateHookForRuntime)(
useEditComposerAttachmentRuntime
);
var useMessageAttachment = (0, import_createStateHookForRuntime.createStateHookForRuntime)(
useMessageAttachmentRuntime
);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
AttachmentContext,
useAttachment,
useAttachmentRuntime,
useEditComposerAttachment,
useEditComposerAttachmentRuntime,
useMessageAttachment,
useMessageAttachmentRuntime,
useThreadComposerAttachment,
useThreadComposerAttachmentRuntime
});
//# sourceMappingURL=AttachmentContext.js.map