@assistant-ui/react 0.5.86 → 0.5.88

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.mjs CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  toLanguageModelMessages,
11
11
  toLanguageModelTools,
12
12
  toolResultStream
13
- } from "./chunk-TWIMAOZR.mjs";
13
+ } from "./chunk-CKNRD26B.mjs";
14
14
  import {
15
15
  __export
16
16
  } from "./chunk-BJPOCE4O.mjs";
@@ -437,6 +437,62 @@ function useComposerRuntime(options) {
437
437
  return messageRuntime ? messageRuntime.composer : threadRuntime?.composer ?? null;
438
438
  }
439
439
 
440
+ // src/context/react/AttachmentContext.ts
441
+ import { createContext as createContext5, useContext as useContext2 } from "react";
442
+ var AttachmentContext = createContext5(
443
+ null
444
+ );
445
+ function useAttachmentContext(options) {
446
+ const context = useContext2(AttachmentContext);
447
+ if (!options?.optional && !context)
448
+ throw new Error(
449
+ "This component must be used within a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component."
450
+ );
451
+ return context;
452
+ }
453
+ function useThreadComposerAttachmentContext(options) {
454
+ const context = useAttachmentContext(options);
455
+ if (!context) return null;
456
+ if (context.source !== "thread-composer")
457
+ throw new Error(
458
+ "This component must be used within a thread's ComposerPrimitive.Attachments component."
459
+ );
460
+ return context;
461
+ }
462
+ function useEditComposerAttachmentContext(options) {
463
+ const context = useAttachmentContext(options);
464
+ if (!context) return null;
465
+ if (context.source !== "edit-composer")
466
+ throw new Error(
467
+ "This component must be used within a messages's ComposerPrimitive.Attachments component."
468
+ );
469
+ return context;
470
+ }
471
+ function useMessageAttachmentContext(options) {
472
+ const context = useAttachmentContext(options);
473
+ if (!context) return null;
474
+ if (context.source !== "message")
475
+ throw new Error(
476
+ "This component must be used within a MessagePrimitive.Attachments component."
477
+ );
478
+ return context;
479
+ }
480
+ function useAttachmentRuntime(options) {
481
+ const attachmentRuntime = useAttachmentContext(options);
482
+ if (!attachmentRuntime) return null;
483
+ return attachmentRuntime.useAttachmentRuntime();
484
+ }
485
+ var { useAttachment } = createContextStoreHook(
486
+ useAttachmentContext,
487
+ "useAttachment"
488
+ );
489
+ var { useAttachment: useThreadComposerAttachment } = createContextStoreHook(useThreadComposerAttachmentContext, "useAttachment");
490
+ var { useAttachment: useEditComposerAttachment } = createContextStoreHook(useEditComposerAttachmentContext, "useAttachment");
491
+ var { useAttachment: useMessageAttachment } = createContextStoreHook(
492
+ useMessageAttachmentContext,
493
+ "useAttachment"
494
+ );
495
+
440
496
  // src/hooks/useAppendMessage.tsx
441
497
  import { useCallback } from "react";
442
498
  var useAppendMessage = () => {
@@ -1244,64 +1300,6 @@ AttachmentPrimitiveRoot.displayName = "AttachmentPrimitive.Root";
1244
1300
 
1245
1301
  // src/primitives/attachment/AttachmentThumb.tsx
1246
1302
  import { forwardRef as forwardRef11 } from "react";
1247
-
1248
- // src/context/react/AttachmentContext.ts
1249
- import { createContext as createContext5, useContext as useContext2 } from "react";
1250
- var AttachmentContext = createContext5(
1251
- null
1252
- );
1253
- function useAttachmentContext(options) {
1254
- const context = useContext2(AttachmentContext);
1255
- if (!options?.optional && !context)
1256
- throw new Error(
1257
- "This component must be used within a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component."
1258
- );
1259
- return context;
1260
- }
1261
- function useThreadComposerAttachmentContext(options) {
1262
- const context = useAttachmentContext(options);
1263
- if (!context) return null;
1264
- if (context.source !== "thread-composer")
1265
- throw new Error(
1266
- "This component must be used within a thread's ComposerPrimitive.Attachments component."
1267
- );
1268
- return context;
1269
- }
1270
- function useEditComposerAttachmentContext(options) {
1271
- const context = useAttachmentContext(options);
1272
- if (!context) return null;
1273
- if (context.source !== "edit-composer")
1274
- throw new Error(
1275
- "This component must be used within a messages's ComposerPrimitive.Attachments component."
1276
- );
1277
- return context;
1278
- }
1279
- function useMessageAttachmentContext(options) {
1280
- const context = useAttachmentContext(options);
1281
- if (!context) return null;
1282
- if (context.source !== "message")
1283
- throw new Error(
1284
- "This component must be used within a MessagePrimitive.Attachments component."
1285
- );
1286
- return context;
1287
- }
1288
- function useAttachmentRuntime(options) {
1289
- const attachmentRuntime = useAttachmentContext(options);
1290
- if (!attachmentRuntime) return null;
1291
- return attachmentRuntime.useAttachmentRuntime();
1292
- }
1293
- var { useAttachment } = createContextStoreHook(
1294
- useAttachmentContext,
1295
- "useAttachment"
1296
- );
1297
- var { useAttachment: useThreadComposerAttachment } = createContextStoreHook(useThreadComposerAttachmentContext, "useAttachment");
1298
- var { useAttachment: useEditComposerAttachment } = createContextStoreHook(useEditComposerAttachmentContext, "useAttachment");
1299
- var { useAttachment: useMessageAttachment } = createContextStoreHook(
1300
- useMessageAttachmentContext,
1301
- "useAttachment"
1302
- );
1303
-
1304
- // src/primitives/attachment/AttachmentThumb.tsx
1305
1303
  import { Primitive as Primitive8 } from "@radix-ui/react-primitive";
1306
1304
  import { jsxs } from "react/jsx-runtime";
1307
1305
  var AttachmentPrimitiveThumb = forwardRef11((props, ref) => {
@@ -4179,6 +4177,7 @@ function assistantDecoderStream() {
4179
4177
  }
4180
4178
  case "9" /* ToolCall */: {
4181
4179
  const { toolCallId, toolName, args } = value;
4180
+ toolCallNames.set(toolCallId, toolName);
4182
4181
  const argsText = JSON.stringify(args);
4183
4182
  controller.enqueue({
4184
4183
  type: "tool-call-delta",
@@ -6729,6 +6728,8 @@ export {
6729
6728
  useAssistantRuntimeStore,
6730
6729
  useAssistantTool,
6731
6730
  useAssistantToolUI,
6731
+ useAttachment,
6732
+ useAttachmentRuntime,
6732
6733
  useBranchPickerCount,
6733
6734
  useBranchPickerNext,
6734
6735
  useBranchPickerNumber,