@assistant-ui/react 0.10.41 → 0.10.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/primitives/composer/ComposerAttachments.d.ts +24 -0
  2. package/dist/primitives/composer/ComposerAttachments.d.ts.map +1 -1
  3. package/dist/primitives/composer/ComposerAttachments.js +14 -13
  4. package/dist/primitives/composer/ComposerAttachments.js.map +1 -1
  5. package/dist/primitives/composer/index.d.ts +1 -0
  6. package/dist/primitives/composer/index.d.ts.map +1 -1
  7. package/dist/primitives/composer/index.js +2 -0
  8. package/dist/primitives/composer/index.js.map +1 -1
  9. package/dist/primitives/message/MessageAttachments.d.ts +24 -0
  10. package/dist/primitives/message/MessageAttachments.d.ts.map +1 -1
  11. package/dist/primitives/message/MessageAttachments.js +14 -13
  12. package/dist/primitives/message/MessageAttachments.js.map +1 -1
  13. package/dist/primitives/message/MessageParts.d.ts +24 -0
  14. package/dist/primitives/message/MessageParts.d.ts.map +1 -1
  15. package/dist/primitives/message/MessageParts.js +16 -15
  16. package/dist/primitives/message/MessageParts.js.map +1 -1
  17. package/dist/primitives/message/index.d.ts +2 -0
  18. package/dist/primitives/message/index.d.ts.map +1 -1
  19. package/dist/primitives/message/index.js +4 -0
  20. package/dist/primitives/message/index.js.map +1 -1
  21. package/dist/primitives/thread/ThreadMessages.d.ts +24 -0
  22. package/dist/primitives/thread/ThreadMessages.d.ts.map +1 -1
  23. package/dist/primitives/thread/ThreadMessages.js +20 -15
  24. package/dist/primitives/thread/ThreadMessages.js.map +1 -1
  25. package/dist/primitives/thread/index.d.ts +1 -0
  26. package/dist/primitives/thread/index.d.ts.map +1 -1
  27. package/dist/primitives/thread/index.js +2 -0
  28. package/dist/primitives/thread/index.js.map +1 -1
  29. package/dist/primitives/threadList/ThreadListItems.d.ts +24 -0
  30. package/dist/primitives/threadList/ThreadListItems.d.ts.map +1 -1
  31. package/dist/primitives/threadList/ThreadListItems.js +15 -18
  32. package/dist/primitives/threadList/ThreadListItems.js.map +1 -1
  33. package/dist/primitives/threadList/index.d.ts +1 -0
  34. package/dist/primitives/threadList/index.d.ts.map +1 -1
  35. package/dist/primitives/threadList/index.js +2 -0
  36. package/dist/primitives/threadList/index.js.map +1 -1
  37. package/dist/tests/setup.js +10 -10
  38. package/dist/tests/setup.js.map +1 -1
  39. package/package.json +9 -9
  40. package/src/primitives/composer/ComposerAttachments.tsx +48 -24
  41. package/src/primitives/composer/index.ts +1 -0
  42. package/src/primitives/message/MessageAttachments.tsx +48 -24
  43. package/src/primitives/message/MessageParts.tsx +53 -33
  44. package/src/primitives/message/index.ts +2 -0
  45. package/src/primitives/thread/ThreadMessages.tsx +47 -27
  46. package/src/primitives/thread/index.ts +1 -0
  47. package/src/primitives/threadList/ThreadListItems.tsx +48 -33
  48. package/src/primitives/threadList/index.ts +1 -0
@@ -9,5 +9,29 @@ export declare namespace ComposerPrimitiveAttachments {
9
9
  } | undefined;
10
10
  };
11
11
  }
12
+ export declare namespace ComposerPrimitiveAttachmentByIndex {
13
+ type Props = {
14
+ index: number;
15
+ components?: ComposerPrimitiveAttachments.Props["components"];
16
+ };
17
+ }
18
+ /**
19
+ * Renders a single attachment at the specified index within the composer.
20
+ *
21
+ * This component provides direct access to render a specific attachment
22
+ * from the composer's attachment list using the provided component configuration.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * <ComposerPrimitive.AttachmentByIndex
27
+ * index={0}
28
+ * components={{
29
+ * Image: MyImageAttachment,
30
+ * Document: MyDocumentAttachment
31
+ * }}
32
+ * />
33
+ * ```
34
+ */
35
+ export declare const ComposerPrimitiveAttachmentByIndex: FC<ComposerPrimitiveAttachmentByIndex.Props>;
12
36
  export declare const ComposerPrimitiveAttachments: FC<ComposerPrimitiveAttachments.Props>;
13
37
  //# sourceMappingURL=ComposerAttachments.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ComposerAttachments.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/ComposerAttachments.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,EAAiB,MAAM,OAAO,CAAC;AAM9D,yBAAiB,4BAA4B,CAAC;IAC5C,KAAY,KAAK,GAAG;QAClB,UAAU,EACN;YACE,KAAK,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YAClC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YACrC,IAAI,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YACjC,UAAU,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;SACxC,GACD,SAAS,CAAC;KACf,CAAC;CACH;AAyDD,eAAO,MAAM,4BAA4B,EAAE,EAAE,CAC3C,4BAA4B,CAAC,KAAK,CAenC,CAAC"}
1
+ {"version":3,"file":"ComposerAttachments.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/ComposerAttachments.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,EAAiB,MAAM,OAAO,CAAC;AAM9D,yBAAiB,4BAA4B,CAAC;IAC5C,KAAY,KAAK,GAAG;QAClB,UAAU,EACN;YACE,KAAK,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YAClC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YACrC,IAAI,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YACjC,UAAU,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;SACxC,GACD,SAAS,CAAC;KACf,CAAC;CACH;AA+BD,yBAAiB,kCAAkC,CAAC;IAClD,KAAY,KAAK,GAAG;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,4BAA4B,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;KAC/D,CAAC;CACH;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kCAAkC,EAAE,EAAE,CAAC,kCAAkC,CAAC,KAAK,CAqBzF,CAAC;AAKJ,eAAO,MAAM,4BAA4B,EAAE,EAAE,CAC3C,4BAA4B,CAAC,KAAK,CAenC,CAAC"}
@@ -27,25 +27,25 @@ var AttachmentComponent = ({ components }) => {
27
27
  if (!Component) return null;
28
28
  return /* @__PURE__ */ jsx(Component, {});
29
29
  };
30
- var ComposerAttachmentImpl = ({ components, attachmentIndex }) => {
31
- const composerRuntime = useComposerRuntime();
32
- const runtime = useMemo(
33
- () => composerRuntime.getAttachmentByIndex(attachmentIndex),
34
- [composerRuntime, attachmentIndex]
35
- );
36
- return /* @__PURE__ */ jsx(AttachmentRuntimeProvider, { runtime, children: /* @__PURE__ */ jsx(AttachmentComponent, { components }) });
37
- };
38
- var ComposerAttachment = memo(
39
- ComposerAttachmentImpl,
40
- (prev, next) => prev.attachmentIndex === next.attachmentIndex && prev.components?.Image === next.components?.Image && prev.components?.Document === next.components?.Document && prev.components?.File === next.components?.File && prev.components?.Attachment === next.components?.Attachment
30
+ var ComposerPrimitiveAttachmentByIndex = memo(
31
+ ({ index, components }) => {
32
+ const composerRuntime = useComposerRuntime();
33
+ const runtime = useMemo(
34
+ () => composerRuntime.getAttachmentByIndex(index),
35
+ [composerRuntime, index]
36
+ );
37
+ return /* @__PURE__ */ jsx(AttachmentRuntimeProvider, { runtime, children: /* @__PURE__ */ jsx(AttachmentComponent, { components }) });
38
+ },
39
+ (prev, next) => prev.index === next.index && prev.components?.Image === next.components?.Image && prev.components?.Document === next.components?.Document && prev.components?.File === next.components?.File && prev.components?.Attachment === next.components?.Attachment
41
40
  );
41
+ ComposerPrimitiveAttachmentByIndex.displayName = "ComposerPrimitive.AttachmentByIndex";
42
42
  var ComposerPrimitiveAttachments = ({ components }) => {
43
43
  const attachmentsCount = useComposer((s) => s.attachments.length);
44
44
  const attachmentElements = useMemo(() => {
45
45
  return Array.from({ length: attachmentsCount }, (_, index) => /* @__PURE__ */ jsx(
46
- ComposerAttachment,
46
+ ComposerPrimitiveAttachmentByIndex,
47
47
  {
48
- attachmentIndex: index,
48
+ index,
49
49
  components
50
50
  },
51
51
  index
@@ -55,6 +55,7 @@ var ComposerPrimitiveAttachments = ({ components }) => {
55
55
  };
56
56
  ComposerPrimitiveAttachments.displayName = "ComposerPrimitive.Attachments";
57
57
  export {
58
+ ComposerPrimitiveAttachmentByIndex,
58
59
  ComposerPrimitiveAttachments
59
60
  };
60
61
  //# sourceMappingURL=ComposerAttachments.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/primitives/composer/ComposerAttachments.tsx"],"sourcesContent":["\"use client\";\n\nimport { ComponentType, type FC, memo, useMemo } from \"react\";\nimport { Attachment } from \"../../types\";\nimport { useComposer, useComposerRuntime } from \"../../context\";\nimport { useThreadComposerAttachment } from \"../../context/react/AttachmentContext\";\nimport { AttachmentRuntimeProvider } from \"../../context/providers/AttachmentRuntimeProvider\";\n\nexport namespace ComposerPrimitiveAttachments {\n export type Props = {\n components:\n | {\n Image?: ComponentType | undefined;\n Document?: ComponentType | undefined;\n File?: ComponentType | undefined;\n Attachment?: ComponentType | undefined;\n }\n | undefined;\n };\n}\n\nconst getComponent = (\n components: ComposerPrimitiveAttachments.Props[\"components\"],\n attachment: Attachment,\n) => {\n const type = attachment.type;\n switch (type) {\n case \"image\":\n return components?.Image ?? components?.Attachment;\n case \"document\":\n return components?.Document ?? components?.Attachment;\n case \"file\":\n return components?.File ?? components?.Attachment;\n default:\n const _exhaustiveCheck: never = type;\n throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);\n }\n};\n\nconst AttachmentComponent: FC<{\n components: ComposerPrimitiveAttachments.Props[\"components\"];\n}> = ({ components }) => {\n const Component = useThreadComposerAttachment((a) =>\n getComponent(components, a),\n );\n\n if (!Component) return null;\n return <Component />;\n};\n\nconst ComposerAttachmentImpl: FC<\n ComposerPrimitiveAttachments.Props & { attachmentIndex: number }\n> = ({ components, attachmentIndex }) => {\n const composerRuntime = useComposerRuntime();\n const runtime = useMemo(\n () => composerRuntime.getAttachmentByIndex(attachmentIndex),\n [composerRuntime, attachmentIndex],\n );\n\n return (\n <AttachmentRuntimeProvider runtime={runtime}>\n <AttachmentComponent components={components} />\n </AttachmentRuntimeProvider>\n );\n};\n\nconst ComposerAttachment = memo(\n ComposerAttachmentImpl,\n (prev, next) =>\n prev.attachmentIndex === next.attachmentIndex &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.Document === next.components?.Document &&\n prev.components?.File === next.components?.File &&\n prev.components?.Attachment === next.components?.Attachment,\n);\n\nexport const ComposerPrimitiveAttachments: FC<\n ComposerPrimitiveAttachments.Props\n> = ({ components }) => {\n const attachmentsCount = useComposer((s) => s.attachments.length);\n\n const attachmentElements = useMemo(() => {\n return Array.from({ length: attachmentsCount }, (_, index) => (\n <ComposerAttachment\n key={index}\n attachmentIndex={index}\n components={components}\n />\n ));\n }, [attachmentsCount, components]);\n\n return attachmentElements;\n};\n\nComposerPrimitiveAttachments.displayName = \"ComposerPrimitive.Attachments\";\n"],"mappings":";;;AAEA,SAAiC,MAAM,eAAe;AAEtD,SAAS,aAAa,0BAA0B;AAChD,SAAS,mCAAmC;AAC5C,SAAS,iCAAiC;AAyCjC;AA1BT,IAAM,eAAe,CACnB,YACA,eACG;AACH,QAAM,OAAO,WAAW;AACxB,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO,YAAY,SAAS,YAAY;AAAA,IAC1C,KAAK;AACH,aAAO,YAAY,YAAY,YAAY;AAAA,IAC7C,KAAK;AACH,aAAO,YAAY,QAAQ,YAAY;AAAA,IACzC;AACE,YAAM,mBAA0B;AAChC,YAAM,IAAI,MAAM,4BAA4B,gBAAgB,EAAE;AAAA,EAClE;AACF;AAEA,IAAM,sBAED,CAAC,EAAE,WAAW,MAAM;AACvB,QAAM,YAAY;AAAA,IAA4B,CAAC,MAC7C,aAAa,YAAY,CAAC;AAAA,EAC5B;AAEA,MAAI,CAAC,UAAW,QAAO;AACvB,SAAO,oBAAC,aAAU;AACpB;AAEA,IAAM,yBAEF,CAAC,EAAE,YAAY,gBAAgB,MAAM;AACvC,QAAM,kBAAkB,mBAAmB;AAC3C,QAAM,UAAU;AAAA,IACd,MAAM,gBAAgB,qBAAqB,eAAe;AAAA,IAC1D,CAAC,iBAAiB,eAAe;AAAA,EACnC;AAEA,SACE,oBAAC,6BAA0B,SACzB,8BAAC,uBAAoB,YAAwB,GAC/C;AAEJ;AAEA,IAAM,qBAAqB;AAAA,EACzB;AAAA,EACA,CAAC,MAAM,SACL,KAAK,oBAAoB,KAAK,mBAC9B,KAAK,YAAY,UAAU,KAAK,YAAY,SAC5C,KAAK,YAAY,aAAa,KAAK,YAAY,YAC/C,KAAK,YAAY,SAAS,KAAK,YAAY,QAC3C,KAAK,YAAY,eAAe,KAAK,YAAY;AACrD;AAEO,IAAM,+BAET,CAAC,EAAE,WAAW,MAAM;AACtB,QAAM,mBAAmB,YAAY,CAAC,MAAM,EAAE,YAAY,MAAM;AAEhE,QAAM,qBAAqB,QAAQ,MAAM;AACvC,WAAO,MAAM,KAAK,EAAE,QAAQ,iBAAiB,GAAG,CAAC,GAAG,UAClD;AAAA,MAAC;AAAA;AAAA,QAEC,iBAAiB;AAAA,QACjB;AAAA;AAAA,MAFK;AAAA,IAGP,CACD;AAAA,EACH,GAAG,CAAC,kBAAkB,UAAU,CAAC;AAEjC,SAAO;AACT;AAEA,6BAA6B,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../src/primitives/composer/ComposerAttachments.tsx"],"sourcesContent":["\"use client\";\n\nimport { ComponentType, type FC, memo, useMemo } from \"react\";\nimport { Attachment } from \"../../types\";\nimport { useComposer, useComposerRuntime } from \"../../context\";\nimport { useThreadComposerAttachment } from \"../../context/react/AttachmentContext\";\nimport { AttachmentRuntimeProvider } from \"../../context/providers/AttachmentRuntimeProvider\";\n\nexport namespace ComposerPrimitiveAttachments {\n export type Props = {\n components:\n | {\n Image?: ComponentType | undefined;\n Document?: ComponentType | undefined;\n File?: ComponentType | undefined;\n Attachment?: ComponentType | undefined;\n }\n | undefined;\n };\n}\n\nconst getComponent = (\n components: ComposerPrimitiveAttachments.Props[\"components\"],\n attachment: Attachment,\n) => {\n const type = attachment.type;\n switch (type) {\n case \"image\":\n return components?.Image ?? components?.Attachment;\n case \"document\":\n return components?.Document ?? components?.Attachment;\n case \"file\":\n return components?.File ?? components?.Attachment;\n default:\n const _exhaustiveCheck: never = type;\n throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);\n }\n};\n\nconst AttachmentComponent: FC<{\n components: ComposerPrimitiveAttachments.Props[\"components\"];\n}> = ({ components }) => {\n const Component = useThreadComposerAttachment((a) =>\n getComponent(components, a),\n );\n\n if (!Component) return null;\n return <Component />;\n};\n\nexport namespace ComposerPrimitiveAttachmentByIndex {\n export type Props = {\n index: number;\n components?: ComposerPrimitiveAttachments.Props[\"components\"];\n };\n}\n\n/**\n * Renders a single attachment at the specified index within the composer.\n *\n * This component provides direct access to render a specific attachment\n * from the composer's attachment list using the provided component configuration.\n *\n * @example\n * ```tsx\n * <ComposerPrimitive.AttachmentByIndex\n * index={0}\n * components={{\n * Image: MyImageAttachment,\n * Document: MyDocumentAttachment\n * }}\n * />\n * ```\n */\nexport const ComposerPrimitiveAttachmentByIndex: FC<ComposerPrimitiveAttachmentByIndex.Props> =\n memo(\n ({ index, components }) => {\n const composerRuntime = useComposerRuntime();\n const runtime = useMemo(\n () => composerRuntime.getAttachmentByIndex(index),\n [composerRuntime, index],\n );\n\n return (\n <AttachmentRuntimeProvider runtime={runtime}>\n <AttachmentComponent components={components} />\n </AttachmentRuntimeProvider>\n );\n },\n (prev, next) =>\n prev.index === next.index &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.Document === next.components?.Document &&\n prev.components?.File === next.components?.File &&\n prev.components?.Attachment === next.components?.Attachment,\n );\n\nComposerPrimitiveAttachmentByIndex.displayName =\n \"ComposerPrimitive.AttachmentByIndex\";\n\nexport const ComposerPrimitiveAttachments: FC<\n ComposerPrimitiveAttachments.Props\n> = ({ components }) => {\n const attachmentsCount = useComposer((s) => s.attachments.length);\n\n const attachmentElements = useMemo(() => {\n return Array.from({ length: attachmentsCount }, (_, index) => (\n <ComposerPrimitiveAttachmentByIndex\n key={index}\n index={index}\n components={components}\n />\n ));\n }, [attachmentsCount, components]);\n\n return attachmentElements;\n};\n\nComposerPrimitiveAttachments.displayName = \"ComposerPrimitive.Attachments\";\n"],"mappings":";;;AAEA,SAAiC,MAAM,eAAe;AAEtD,SAAS,aAAa,0BAA0B;AAChD,SAAS,mCAAmC;AAC5C,SAAS,iCAAiC;AAyCjC;AA1BT,IAAM,eAAe,CACnB,YACA,eACG;AACH,QAAM,OAAO,WAAW;AACxB,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO,YAAY,SAAS,YAAY;AAAA,IAC1C,KAAK;AACH,aAAO,YAAY,YAAY,YAAY;AAAA,IAC7C,KAAK;AACH,aAAO,YAAY,QAAQ,YAAY;AAAA,IACzC;AACE,YAAM,mBAA0B;AAChC,YAAM,IAAI,MAAM,4BAA4B,gBAAgB,EAAE;AAAA,EAClE;AACF;AAEA,IAAM,sBAED,CAAC,EAAE,WAAW,MAAM;AACvB,QAAM,YAAY;AAAA,IAA4B,CAAC,MAC7C,aAAa,YAAY,CAAC;AAAA,EAC5B;AAEA,MAAI,CAAC,UAAW,QAAO;AACvB,SAAO,oBAAC,aAAU;AACpB;AA0BO,IAAM,qCACX;AAAA,EACE,CAAC,EAAE,OAAO,WAAW,MAAM;AACzB,UAAM,kBAAkB,mBAAmB;AAC3C,UAAM,UAAU;AAAA,MACd,MAAM,gBAAgB,qBAAqB,KAAK;AAAA,MAChD,CAAC,iBAAiB,KAAK;AAAA,IACzB;AAEA,WACE,oBAAC,6BAA0B,SACzB,8BAAC,uBAAoB,YAAwB,GAC/C;AAAA,EAEJ;AAAA,EACA,CAAC,MAAM,SACL,KAAK,UAAU,KAAK,SACpB,KAAK,YAAY,UAAU,KAAK,YAAY,SAC5C,KAAK,YAAY,aAAa,KAAK,YAAY,YAC/C,KAAK,YAAY,SAAS,KAAK,YAAY,QAC3C,KAAK,YAAY,eAAe,KAAK,YAAY;AACrD;AAEF,mCAAmC,cACjC;AAEK,IAAM,+BAET,CAAC,EAAE,WAAW,MAAM;AACtB,QAAM,mBAAmB,YAAY,CAAC,MAAM,EAAE,YAAY,MAAM;AAEhE,QAAM,qBAAqB,QAAQ,MAAM;AACvC,WAAO,MAAM,KAAK,EAAE,QAAQ,iBAAiB,GAAG,CAAC,GAAG,UAClD;AAAA,MAAC;AAAA;AAAA,QAEC;AAAA,QACA;AAAA;AAAA,MAFK;AAAA,IAGP,CACD;AAAA,EACH,GAAG,CAAC,kBAAkB,UAAU,CAAC;AAEjC,SAAO;AACT;AAEA,6BAA6B,cAAc;","names":[]}
@@ -4,5 +4,6 @@ export { ComposerPrimitiveSend as Send } from "./ComposerSend";
4
4
  export { ComposerPrimitiveCancel as Cancel } from "./ComposerCancel";
5
5
  export { ComposerPrimitiveAddAttachment as AddAttachment } from "./ComposerAddAttachment";
6
6
  export { ComposerPrimitiveAttachments as Attachments } from "./ComposerAttachments";
7
+ export { ComposerPrimitiveAttachmentByIndex as AttachmentByIndex } from "./ComposerAttachments";
7
8
  export { ComposerPrimitiveIf as If } from "./ComposerIf";
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,IAAI,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,sBAAsB,IAAI,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,qBAAqB,IAAI,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,uBAAuB,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,8BAA8B,IAAI,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,EAAE,4BAA4B,IAAI,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,mBAAmB,IAAI,EAAE,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,IAAI,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,sBAAsB,IAAI,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,qBAAqB,IAAI,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,uBAAuB,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,8BAA8B,IAAI,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,EAAE,4BAA4B,IAAI,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,kCAAkC,IAAI,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,mBAAmB,IAAI,EAAE,EAAE,MAAM,cAAc,CAAC"}
@@ -5,9 +5,11 @@ import { ComposerPrimitiveSend } from "./ComposerSend.js";
5
5
  import { ComposerPrimitiveCancel } from "./ComposerCancel.js";
6
6
  import { ComposerPrimitiveAddAttachment } from "./ComposerAddAttachment.js";
7
7
  import { ComposerPrimitiveAttachments } from "./ComposerAttachments.js";
8
+ import { ComposerPrimitiveAttachmentByIndex } from "./ComposerAttachments.js";
8
9
  import { ComposerPrimitiveIf } from "./ComposerIf.js";
9
10
  export {
10
11
  ComposerPrimitiveAddAttachment as AddAttachment,
12
+ ComposerPrimitiveAttachmentByIndex as AttachmentByIndex,
11
13
  ComposerPrimitiveAttachments as Attachments,
12
14
  ComposerPrimitiveCancel as Cancel,
13
15
  ComposerPrimitiveIf as If,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/primitives/composer/index.ts"],"sourcesContent":["export { ComposerPrimitiveRoot as Root } from \"./ComposerRoot\";\nexport { ComposerPrimitiveInput as Input } from \"./ComposerInput\";\nexport { ComposerPrimitiveSend as Send } from \"./ComposerSend\";\nexport { ComposerPrimitiveCancel as Cancel } from \"./ComposerCancel\";\nexport { ComposerPrimitiveAddAttachment as AddAttachment } from \"./ComposerAddAttachment\";\nexport { ComposerPrimitiveAttachments as Attachments } from \"./ComposerAttachments\";\nexport { ComposerPrimitiveIf as If } from \"./ComposerIf\";\n"],"mappings":";AAAA,SAAkC,6BAAY;AAC9C,SAAmC,8BAAa;AAChD,SAAkC,6BAAY;AAC9C,SAAoC,+BAAc;AAClD,SAA2C,sCAAqB;AAChE,SAAyC,oCAAmB;AAC5D,SAAgC,2BAAU;","names":[]}
1
+ {"version":3,"sources":["../../../src/primitives/composer/index.ts"],"sourcesContent":["export { ComposerPrimitiveRoot as Root } from \"./ComposerRoot\";\nexport { ComposerPrimitiveInput as Input } from \"./ComposerInput\";\nexport { ComposerPrimitiveSend as Send } from \"./ComposerSend\";\nexport { ComposerPrimitiveCancel as Cancel } from \"./ComposerCancel\";\nexport { ComposerPrimitiveAddAttachment as AddAttachment } from \"./ComposerAddAttachment\";\nexport { ComposerPrimitiveAttachments as Attachments } from \"./ComposerAttachments\";\nexport { ComposerPrimitiveAttachmentByIndex as AttachmentByIndex } from \"./ComposerAttachments\";\nexport { ComposerPrimitiveIf as If } from \"./ComposerIf\";\n"],"mappings":";AAAA,SAAkC,6BAAY;AAC9C,SAAmC,8BAAa;AAChD,SAAkC,6BAAY;AAC9C,SAAoC,+BAAc;AAClD,SAA2C,sCAAqB;AAChE,SAAyC,oCAAmB;AAC5D,SAA+C,0CAAyB;AACxE,SAAgC,2BAAU;","names":[]}
@@ -9,5 +9,29 @@ export declare namespace MessagePrimitiveAttachments {
9
9
  } | undefined;
10
10
  };
11
11
  }
12
+ export declare namespace MessagePrimitiveAttachmentByIndex {
13
+ type Props = {
14
+ index: number;
15
+ components?: MessagePrimitiveAttachments.Props["components"];
16
+ };
17
+ }
18
+ /**
19
+ * Renders a single attachment at the specified index within the current message.
20
+ *
21
+ * This component provides direct access to render a specific attachment
22
+ * from the message's attachment list using the provided component configuration.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * <MessagePrimitive.AttachmentByIndex
27
+ * index={0}
28
+ * components={{
29
+ * Image: MyImageAttachment,
30
+ * Document: MyDocumentAttachment
31
+ * }}
32
+ * />
33
+ * ```
34
+ */
35
+ export declare const MessagePrimitiveAttachmentByIndex: FC<MessagePrimitiveAttachmentByIndex.Props>;
12
36
  export declare const MessagePrimitiveAttachments: FC<MessagePrimitiveAttachments.Props>;
13
37
  //# sourceMappingURL=MessageAttachments.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MessageAttachments.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageAttachments.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,EAAiB,MAAM,OAAO,CAAC;AAM9D,yBAAiB,2BAA2B,CAAC;IAC3C,KAAY,KAAK,GAAG;QAClB,UAAU,EACN;YACE,KAAK,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YAClC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YACrC,IAAI,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YACjC,UAAU,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;SACxC,GACD,SAAS,CAAC;KACf,CAAC;CACH;AAuDD,eAAO,MAAM,2BAA2B,EAAE,EAAE,CAC1C,2BAA2B,CAAC,KAAK,CAkBlC,CAAC"}
1
+ {"version":3,"file":"MessageAttachments.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageAttachments.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,EAAiB,MAAM,OAAO,CAAC;AAM9D,yBAAiB,2BAA2B,CAAC;IAC3C,KAAY,KAAK,GAAG;QAClB,UAAU,EACN;YACE,KAAK,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YAClC,QAAQ,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YACrC,IAAI,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YACjC,UAAU,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;SACxC,GACD,SAAS,CAAC;KACf,CAAC;CACH;AA6BD,yBAAiB,iCAAiC,CAAC;IACjD,KAAY,KAAK,GAAG;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,2BAA2B,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;KAC9D,CAAC;CACH;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,iCAAiC,EAAE,EAAE,CAAC,iCAAiC,CAAC,KAAK,CAqBvF,CAAC;AAKJ,eAAO,MAAM,2BAA2B,EAAE,EAAE,CAC1C,2BAA2B,CAAC,KAAK,CAkBlC,CAAC"}
@@ -25,18 +25,18 @@ var AttachmentComponent = ({ components }) => {
25
25
  if (!Component) return null;
26
26
  return /* @__PURE__ */ jsx(Component, {});
27
27
  };
28
- var MessageAttachmentImpl = ({ components, attachmentIndex }) => {
29
- const messageRuntime = useMessageRuntime();
30
- const runtime = useMemo(
31
- () => messageRuntime.getAttachmentByIndex(attachmentIndex),
32
- [messageRuntime, attachmentIndex]
33
- );
34
- return /* @__PURE__ */ jsx(AttachmentRuntimeProvider, { runtime, children: /* @__PURE__ */ jsx(AttachmentComponent, { components }) });
35
- };
36
- var MessageAttachment = memo(
37
- MessageAttachmentImpl,
38
- (prev, next) => prev.attachmentIndex === next.attachmentIndex && prev.components?.Image === next.components?.Image && prev.components?.Document === next.components?.Document && prev.components?.File === next.components?.File && prev.components?.Attachment === next.components?.Attachment
28
+ var MessagePrimitiveAttachmentByIndex = memo(
29
+ ({ index, components }) => {
30
+ const messageRuntime = useMessageRuntime();
31
+ const runtime = useMemo(
32
+ () => messageRuntime.getAttachmentByIndex(index),
33
+ [messageRuntime, index]
34
+ );
35
+ return /* @__PURE__ */ jsx(AttachmentRuntimeProvider, { runtime, children: /* @__PURE__ */ jsx(AttachmentComponent, { components }) });
36
+ },
37
+ (prev, next) => prev.index === next.index && prev.components?.Image === next.components?.Image && prev.components?.Document === next.components?.Document && prev.components?.File === next.components?.File && prev.components?.Attachment === next.components?.Attachment
39
38
  );
39
+ MessagePrimitiveAttachmentByIndex.displayName = "MessagePrimitive.AttachmentByIndex";
40
40
  var MessagePrimitiveAttachments = ({ components }) => {
41
41
  const attachmentsCount = useMessage((message) => {
42
42
  if (message.role !== "user") return 0;
@@ -44,9 +44,9 @@ var MessagePrimitiveAttachments = ({ components }) => {
44
44
  });
45
45
  const attachmentElements = useMemo(() => {
46
46
  return Array.from({ length: attachmentsCount }, (_, index) => /* @__PURE__ */ jsx(
47
- MessageAttachment,
47
+ MessagePrimitiveAttachmentByIndex,
48
48
  {
49
- attachmentIndex: index,
49
+ index,
50
50
  components
51
51
  },
52
52
  index
@@ -56,6 +56,7 @@ var MessagePrimitiveAttachments = ({ components }) => {
56
56
  };
57
57
  MessagePrimitiveAttachments.displayName = "MessagePrimitive.Attachments";
58
58
  export {
59
+ MessagePrimitiveAttachmentByIndex,
59
60
  MessagePrimitiveAttachments
60
61
  };
61
62
  //# sourceMappingURL=MessageAttachments.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/primitives/message/MessageAttachments.tsx"],"sourcesContent":["\"use client\";\n\nimport { ComponentType, type FC, memo, useMemo } from \"react\";\nimport { useMessage, useMessageRuntime } from \"../../context\";\nimport { useMessageAttachment } from \"../../context/react/AttachmentContext\";\nimport { AttachmentRuntimeProvider } from \"../../context/providers/AttachmentRuntimeProvider\";\nimport { CompleteAttachment } from \"../../types\";\n\nexport namespace MessagePrimitiveAttachments {\n export type Props = {\n components:\n | {\n Image?: ComponentType | undefined;\n Document?: ComponentType | undefined;\n File?: ComponentType | undefined;\n Attachment?: ComponentType | undefined;\n }\n | undefined;\n };\n}\n\nconst getComponent = (\n components: MessagePrimitiveAttachments.Props[\"components\"],\n attachment: CompleteAttachment,\n) => {\n const type = attachment.type;\n switch (type) {\n case \"image\":\n return components?.Image ?? components?.Attachment;\n case \"document\":\n return components?.Document ?? components?.Attachment;\n case \"file\":\n return components?.File ?? components?.Attachment;\n default:\n const _exhaustiveCheck: never = type;\n throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);\n }\n};\n\nconst AttachmentComponent: FC<{\n components: MessagePrimitiveAttachments.Props[\"components\"];\n}> = ({ components }) => {\n const Component = useMessageAttachment((a) => getComponent(components, a));\n\n if (!Component) return null;\n return <Component />;\n};\n\nconst MessageAttachmentImpl: FC<\n MessagePrimitiveAttachments.Props & { attachmentIndex: number }\n> = ({ components, attachmentIndex }) => {\n const messageRuntime = useMessageRuntime();\n const runtime = useMemo(\n () => messageRuntime.getAttachmentByIndex(attachmentIndex),\n [messageRuntime, attachmentIndex],\n );\n\n return (\n <AttachmentRuntimeProvider runtime={runtime}>\n <AttachmentComponent components={components} />\n </AttachmentRuntimeProvider>\n );\n};\n\nconst MessageAttachment = memo(\n MessageAttachmentImpl,\n (prev, next) =>\n prev.attachmentIndex === next.attachmentIndex &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.Document === next.components?.Document &&\n prev.components?.File === next.components?.File &&\n prev.components?.Attachment === next.components?.Attachment,\n);\n\nexport const MessagePrimitiveAttachments: FC<\n MessagePrimitiveAttachments.Props\n> = ({ components }) => {\n const attachmentsCount = useMessage((message) => {\n if (message.role !== \"user\") return 0;\n return message.attachments.length;\n });\n\n const attachmentElements = useMemo(() => {\n return Array.from({ length: attachmentsCount }, (_, index) => (\n <MessageAttachment\n key={index}\n attachmentIndex={index}\n components={components}\n />\n ));\n }, [attachmentsCount, components]);\n\n return attachmentElements;\n};\n\nMessagePrimitiveAttachments.displayName = \"MessagePrimitive.Attachments\";\n"],"mappings":";;;AAEA,SAAiC,MAAM,eAAe;AACtD,SAAS,YAAY,yBAAyB;AAC9C,SAAS,4BAA4B;AACrC,SAAS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GAAG,CAAC,GAAG,UAClD;AAAA,MAAC;AAAA;AAAA,QAEC,iBAAiB;AAAA,QACjB;AAAA;AAAA,MAFK;AAAA,IAGP,CACD;AAAA,EACH,GAAG,CAAC,kBAAkB,UAAU,CAAC;AAEjC,SAAO;AACT;AAEA,4BAA4B,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../src/primitives/message/MessageAttachments.tsx"],"sourcesContent":["\"use client\";\n\nimport { ComponentType, type FC, memo, useMemo } from \"react\";\nimport { useMessage, useMessageRuntime } from \"../../context\";\nimport { useMessageAttachment } from \"../../context/react/AttachmentContext\";\nimport { AttachmentRuntimeProvider } from \"../../context/providers/AttachmentRuntimeProvider\";\nimport { CompleteAttachment } from \"../../types\";\n\nexport namespace MessagePrimitiveAttachments {\n export type Props = {\n components:\n | {\n Image?: ComponentType | undefined;\n Document?: ComponentType | undefined;\n File?: ComponentType | undefined;\n Attachment?: ComponentType | undefined;\n }\n | undefined;\n };\n}\n\nconst getComponent = (\n components: MessagePrimitiveAttachments.Props[\"components\"],\n attachment: CompleteAttachment,\n) => {\n const type = attachment.type;\n switch (type) {\n case \"image\":\n return components?.Image ?? components?.Attachment;\n case \"document\":\n return components?.Document ?? components?.Attachment;\n case \"file\":\n return components?.File ?? components?.Attachment;\n default:\n const _exhaustiveCheck: never = type;\n throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);\n }\n};\n\nconst AttachmentComponent: FC<{\n components: MessagePrimitiveAttachments.Props[\"components\"];\n}> = ({ components }) => {\n const Component = useMessageAttachment((a) => getComponent(components, a));\n\n if (!Component) return null;\n return <Component />;\n};\n\nexport namespace MessagePrimitiveAttachmentByIndex {\n export type Props = {\n index: number;\n components?: MessagePrimitiveAttachments.Props[\"components\"];\n };\n}\n\n/**\n * Renders a single attachment at the specified index within the current message.\n *\n * This component provides direct access to render a specific attachment\n * from the message's attachment list using the provided component configuration.\n *\n * @example\n * ```tsx\n * <MessagePrimitive.AttachmentByIndex\n * index={0}\n * components={{\n * Image: MyImageAttachment,\n * Document: MyDocumentAttachment\n * }}\n * />\n * ```\n */\nexport const MessagePrimitiveAttachmentByIndex: FC<MessagePrimitiveAttachmentByIndex.Props> =\n memo(\n ({ index, components }) => {\n const messageRuntime = useMessageRuntime();\n const runtime = useMemo(\n () => messageRuntime.getAttachmentByIndex(index),\n [messageRuntime, index],\n );\n\n return (\n <AttachmentRuntimeProvider runtime={runtime}>\n <AttachmentComponent components={components} />\n </AttachmentRuntimeProvider>\n );\n },\n (prev, next) =>\n prev.index === next.index &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.Document === next.components?.Document &&\n prev.components?.File === next.components?.File &&\n prev.components?.Attachment === next.components?.Attachment,\n );\n\nMessagePrimitiveAttachmentByIndex.displayName =\n \"MessagePrimitive.AttachmentByIndex\";\n\nexport const MessagePrimitiveAttachments: FC<\n MessagePrimitiveAttachments.Props\n> = ({ components }) => {\n const attachmentsCount = useMessage((message) => {\n if (message.role !== \"user\") return 0;\n return message.attachments.length;\n });\n\n const attachmentElements = useMemo(() => {\n return Array.from({ length: attachmentsCount }, (_, index) => (\n <MessagePrimitiveAttachmentByIndex\n key={index}\n index={index}\n components={components}\n />\n ));\n }, [attachmentsCount, components]);\n\n return attachmentElements;\n};\n\nMessagePrimitiveAttachments.displayName = \"MessagePrimitive.Attachments\";\n"],"mappings":";;;AAEA,SAAiC,MAAM,eAAe;AACtD,SAAS,YAAY,yBAAyB;AAC9C,SAAS,4BAA4B;AACrC,SAAS,iCAAiC;AAwCjC;AAxBT,IAAM,eAAe,CACnB,YACA,eACG;AACH,QAAM,OAAO,WAAW;AACxB,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO,YAAY,SAAS,YAAY;AAAA,IAC1C,KAAK;AACH,aAAO,YAAY,YAAY,YAAY;AAAA,IAC7C,KAAK;AACH,aAAO,YAAY,QAAQ,YAAY;AAAA,IACzC;AACE,YAAM,mBAA0B;AAChC,YAAM,IAAI,MAAM,4BAA4B,gBAAgB,EAAE;AAAA,EAClE;AACF;AAEA,IAAM,sBAED,CAAC,EAAE,WAAW,MAAM;AACvB,QAAM,YAAY,qBAAqB,CAAC,MAAM,aAAa,YAAY,CAAC,CAAC;AAEzE,MAAI,CAAC,UAAW,QAAO;AACvB,SAAO,oBAAC,aAAU;AACpB;AA0BO,IAAM,oCACX;AAAA,EACE,CAAC,EAAE,OAAO,WAAW,MAAM;AACzB,UAAM,iBAAiB,kBAAkB;AACzC,UAAM,UAAU;AAAA,MACd,MAAM,eAAe,qBAAqB,KAAK;AAAA,MAC/C,CAAC,gBAAgB,KAAK;AAAA,IACxB;AAEA,WACE,oBAAC,6BAA0B,SACzB,8BAAC,uBAAoB,YAAwB,GAC/C;AAAA,EAEJ;AAAA,EACA,CAAC,MAAM,SACL,KAAK,UAAU,KAAK,SACpB,KAAK,YAAY,UAAU,KAAK,YAAY,SAC5C,KAAK,YAAY,aAAa,KAAK,YAAY,YAC/C,KAAK,YAAY,SAAS,KAAK,YAAY,QAC3C,KAAK,YAAY,eAAe,KAAK,YAAY;AACrD;AAEF,kCAAkC,cAChC;AAEK,IAAM,8BAET,CAAC,EAAE,WAAW,MAAM;AACtB,QAAM,mBAAmB,WAAW,CAAC,YAAY;AAC/C,QAAI,QAAQ,SAAS,OAAQ,QAAO;AACpC,WAAO,QAAQ,YAAY;AAAA,EAC7B,CAAC;AAED,QAAM,qBAAqB,QAAQ,MAAM;AACvC,WAAO,MAAM,KAAK,EAAE,QAAQ,iBAAiB,GAAG,CAAC,GAAG,UAClD;AAAA,MAAC;AAAA;AAAA,QAEC;AAAA,QACA;AAAA;AAAA,MAFK;AAAA,IAGP,CACD;AAAA,EACH,GAAG,CAAC,kBAAkB,UAAU,CAAC;AAEjC,SAAO;AACT;AAEA,4BAA4B,cAAc;","names":[]}
@@ -88,6 +88,30 @@ export declare namespace MessagePrimitiveParts {
88
88
  } | undefined;
89
89
  };
90
90
  }
91
+ export declare namespace MessagePrimitivePartByIndex {
92
+ type Props = {
93
+ index: number;
94
+ components: MessagePrimitiveParts.Props["components"];
95
+ };
96
+ }
97
+ /**
98
+ * Renders a single message part at the specified index.
99
+ *
100
+ * This component provides direct access to render a specific message part
101
+ * within the current message context, using the provided component configuration.
102
+ *
103
+ * @example
104
+ * ```tsx
105
+ * <MessagePrimitive.PartByIndex
106
+ * index={0}
107
+ * components={{
108
+ * Text: MyTextComponent,
109
+ * Image: MyImageComponent
110
+ * }}
111
+ * />
112
+ * ```
113
+ */
114
+ export declare const MessagePrimitivePartByIndex: FC<MessagePrimitivePartByIndex.Props>;
91
115
  /**
92
116
  * Renders the parts of a message with support for multiple content types.
93
117
  *
@@ -1 +1 @@
1
- {"version":3,"file":"MessageParts.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageParts.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,EAAE,EAEP,iBAAiB,EAElB,MAAM,OAAO,CAAC;AAcf,OAAO,KAAK,EACV,kCAAkC,EAClC,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,wBAAwB,EACxB,wBAAwB,EACxB,6BAA6B,EAC9B,MAAM,uCAAuC,CAAC;AAoE/C,yBAAiB,qBAAqB,CAAC;IACrC,KAAY,KAAK,GAAG;QAClB;;;;;WAKG;QACH,UAAU,CAAC,EACP;YACE,6CAA6C;YAC7C,KAAK,CAAC,EAAE,yBAAyB,GAAG,SAAS,CAAC;YAC9C,2CAA2C;YAC3C,IAAI,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;YAC5C,mEAAmE;YACnE,SAAS,CAAC,EAAE,6BAA6B,GAAG,SAAS,CAAC;YACtD,6CAA6C;YAC7C,MAAM,CAAC,EAAE,0BAA0B,GAAG,SAAS,CAAC;YAChD,4CAA4C;YAC5C,KAAK,CAAC,EAAE,yBAAyB,GAAG,SAAS,CAAC;YAC9C,2CAA2C;YAC3C,IAAI,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;YAC5C,2DAA2D;YAC3D,cAAc,CAAC,EAAE,kCAAkC,GAAG,SAAS,CAAC;YAChE,4CAA4C;YAC5C,KAAK,CAAC,EACF;gBACE,qDAAqD;gBACrD,OAAO,CAAC,EACJ,MAAM,CAAC,MAAM,EAAE,4BAA4B,GAAG,SAAS,CAAC,GACxD,SAAS,CAAC;gBACd,gDAAgD;gBAChD,QAAQ,CAAC,EAAE,aAAa,CAAC,wBAAwB,CAAC,GAAG,SAAS,CAAC;aAChE,GACD;gBACE,qDAAqD;gBACrD,QAAQ,EAAE,aAAa,CAAC,wBAAwB,CAAC,CAAC;aACnD,GACD,SAAS,CAAC;YAEd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eA+CG;YACH,SAAS,CAAC,EAAE,aAAa,CACvB,iBAAiB,CAAC;gBAAE,UAAU,EAAE,MAAM,CAAC;gBAAC,QAAQ,EAAE,MAAM,CAAA;aAAE,CAAC,CAC5D,CAAC;SACH,GACD,SAAS,CAAC;KACf,CAAC;CACH;AA4JD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,qBAAqB,EAAE,EAAE,CAAC,qBAAqB,CAAC,KAAK,CA8CjE,CAAC"}
1
+ {"version":3,"file":"MessageParts.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageParts.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,EAAE,EAEP,iBAAiB,EAElB,MAAM,OAAO,CAAC;AAcf,OAAO,KAAK,EACV,kCAAkC,EAClC,yBAAyB,EACzB,wBAAwB,EACxB,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,wBAAwB,EACxB,wBAAwB,EACxB,6BAA6B,EAC9B,MAAM,uCAAuC,CAAC;AAoE/C,yBAAiB,qBAAqB,CAAC;IACrC,KAAY,KAAK,GAAG;QAClB;;;;;WAKG;QACH,UAAU,CAAC,EACP;YACE,6CAA6C;YA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MAAM,2BAA2B,EAAE,EAAE,CAAC,2BAA2B,CAAC,KAAK,CAyB3E,CAAC;AAwCJ;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,qBAAqB,EAAE,EAAE,CAAC,qBAAqB,CAAC,KAAK,CA8CjE,CAAC"}
@@ -123,18 +123,18 @@ var MessagePartComponent = ({
123
123
  throw new Error(`Unknown message part type: ${unhandledType}`);
124
124
  }
125
125
  };
126
- var MessagePartImpl = ({ partIndex, components }) => {
127
- const messageRuntime = useMessageRuntime();
128
- const runtime = useMemo(
129
- () => messageRuntime.getMessagePartByIndex(partIndex),
130
- [messageRuntime, partIndex]
131
- );
132
- return /* @__PURE__ */ jsx(MessagePartRuntimeProvider, { runtime, children: /* @__PURE__ */ jsx(MessagePartComponent, { components }) });
133
- };
134
- var MessagePart = memo(
135
- MessagePartImpl,
136
- (prev, next) => prev.partIndex === next.partIndex && prev.components?.Text === next.components?.Text && prev.components?.Reasoning === next.components?.Reasoning && prev.components?.Source === next.components?.Source && prev.components?.Image === next.components?.Image && prev.components?.File === next.components?.File && prev.components?.Unstable_Audio === next.components?.Unstable_Audio && prev.components?.tools === next.components?.tools && prev.components?.ToolGroup === next.components?.ToolGroup
126
+ var MessagePrimitivePartByIndex = memo(
127
+ ({ index, components }) => {
128
+ const messageRuntime = useMessageRuntime();
129
+ const runtime = useMemo(
130
+ () => messageRuntime.getMessagePartByIndex(index),
131
+ [messageRuntime, index]
132
+ );
133
+ return /* @__PURE__ */ jsx(MessagePartRuntimeProvider, { runtime, children: /* @__PURE__ */ jsx(MessagePartComponent, { components }) });
134
+ },
135
+ (prev, next) => prev.index === next.index && prev.components?.Text === next.components?.Text && prev.components?.Reasoning === next.components?.Reasoning && prev.components?.Source === next.components?.Source && prev.components?.Image === next.components?.Image && prev.components?.File === next.components?.File && prev.components?.Unstable_Audio === next.components?.Unstable_Audio && prev.components?.tools === next.components?.tools && prev.components?.ToolGroup === next.components?.ToolGroup
137
136
  );
137
+ MessagePrimitivePartByIndex.displayName = "MessagePrimitive.PartByIndex";
138
138
  var COMPLETE_STATUS = Object.freeze({
139
139
  type: "complete"
140
140
  });
@@ -168,9 +168,9 @@ var MessagePrimitiveParts = ({
168
168
  return messageRanges.map((range) => {
169
169
  if (range.type === "single") {
170
170
  return /* @__PURE__ */ jsx(
171
- MessagePart,
171
+ MessagePrimitivePartByIndex,
172
172
  {
173
- partIndex: range.index,
173
+ index: range.index,
174
174
  components
175
175
  },
176
176
  range.index
@@ -185,9 +185,9 @@ var MessagePrimitiveParts = ({
185
185
  children: Array.from(
186
186
  { length: range.endIndex - range.startIndex + 1 },
187
187
  (_, i) => /* @__PURE__ */ jsx(
188
- MessagePart,
188
+ MessagePrimitivePartByIndex,
189
189
  {
190
- partIndex: range.startIndex + i,
190
+ index: range.startIndex + i,
191
191
  components
192
192
  },
193
193
  i
@@ -203,6 +203,7 @@ var MessagePrimitiveParts = ({
203
203
  };
204
204
  MessagePrimitiveParts.displayName = "MessagePrimitive.Parts";
205
205
  export {
206
+ MessagePrimitivePartByIndex,
206
207
  MessagePrimitiveParts
207
208
  };
208
209
  //# sourceMappingURL=MessageParts.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/primitives/message/MessageParts.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ComponentType,\n type FC,\n memo,\n PropsWithChildren,\n useMemo,\n} from \"react\";\nimport {\n TextMessagePartProvider,\n useMessagePart,\n useMessagePartRuntime,\n useToolUIs,\n} from \"../../context\";\nimport {\n useMessage,\n useMessageRuntime,\n} from \"../../context/react/MessageContext\";\nimport { MessagePartRuntimeProvider } from \"../../context/providers/MessagePartRuntimeProvider\";\nimport { MessagePartPrimitiveText } from \"../messagePart/MessagePartText\";\nimport { MessagePartPrimitiveImage } from \"../messagePart/MessagePartImage\";\nimport type {\n Unstable_AudioMessagePartComponent,\n EmptyMessagePartComponent,\n TextMessagePartComponent,\n ImageMessagePartComponent,\n SourceMessagePartComponent,\n ToolCallMessagePartComponent,\n ToolCallMessagePartProps,\n FileMessagePartComponent,\n ReasoningMessagePartComponent,\n} from \"../../types/MessagePartComponentTypes\";\nimport { MessagePartPrimitiveInProgress } from \"../messagePart/MessagePartInProgress\";\nimport { MessagePartStatus } from \"../../types/AssistantTypes\";\nimport { useShallow } from \"zustand/shallow\";\n\ntype MessagePartRange =\n | { type: \"single\"; index: number }\n | { type: \"toolGroup\"; startIndex: number; endIndex: number };\n\n/**\n * Groups consecutive tool-call message parts into ranges.\n * Always groups tool calls, even if there's only one.\n */\nconst groupMessageParts = (\n messageTypes: readonly string[],\n): MessagePartRange[] => {\n const ranges: MessagePartRange[] = [];\n let currentToolGroupStart = -1;\n\n for (let i = 0; i < messageTypes.length; i++) {\n const type = messageTypes[i];\n\n if (type === \"tool-call\") {\n // Start a new tool group if we haven't started one\n if (currentToolGroupStart === -1) {\n currentToolGroupStart = i;\n }\n } else {\n // End current tool group if it exists\n if (currentToolGroupStart !== -1) {\n ranges.push({\n type: \"toolGroup\",\n startIndex: currentToolGroupStart,\n endIndex: i - 1,\n });\n currentToolGroupStart = -1;\n }\n\n // Add non-tool-call part individually\n ranges.push({ type: \"single\", index: i });\n }\n }\n\n // Handle any remaining tool group at the end\n if (currentToolGroupStart !== -1) {\n ranges.push({\n type: \"toolGroup\",\n startIndex: currentToolGroupStart,\n endIndex: messageTypes.length - 1,\n });\n }\n\n return ranges;\n};\n\nconst useMessagePartsGroups = (): MessagePartRange[] => {\n const messageTypes = useMessage(\n useShallow((m) => m.content.map((c) => c.type)),\n );\n\n return useMemo(() => {\n if (messageTypes.length === 0) {\n return [];\n }\n return groupMessageParts(messageTypes);\n }, [messageTypes]);\n};\n\nexport namespace MessagePrimitiveParts {\n export type Props = {\n /**\n * Component configuration for rendering different types of message content.\n *\n * You can provide custom components for each content type (text, image, file, etc.)\n * and configure tool rendering behavior. If not provided, default components will be used.\n */\n components?:\n | {\n /** Component for rendering empty messages */\n Empty?: EmptyMessagePartComponent | undefined;\n /** Component for rendering text content */\n Text?: TextMessagePartComponent | undefined;\n /** Component for rendering reasoning content (typically hidden) */\n Reasoning?: ReasoningMessagePartComponent | undefined;\n /** Component for rendering source content */\n Source?: SourceMessagePartComponent | undefined;\n /** Component for rendering image content */\n Image?: ImageMessagePartComponent | undefined;\n /** Component for rendering file content */\n File?: FileMessagePartComponent | undefined;\n /** Component for rendering audio content (experimental) */\n Unstable_Audio?: Unstable_AudioMessagePartComponent | undefined;\n /** Configuration for tool call rendering */\n tools?:\n | {\n /** Map of tool names to their specific components */\n by_name?:\n | Record<string, ToolCallMessagePartComponent | undefined>\n | undefined;\n /** Fallback component for unregistered tools */\n Fallback?: ComponentType<ToolCallMessagePartProps> | undefined;\n }\n | {\n /** Override component that handles all tool calls */\n Override: ComponentType<ToolCallMessagePartProps>;\n }\n | undefined;\n\n /**\n * Component for rendering grouped consecutive tool calls.\n *\n * When provided, this component will automatically wrap consecutive tool-call\n * message parts, allowing you to create collapsible sections, custom styling,\n * or other grouped presentations for multiple tool calls.\n *\n * The component receives:\n * - `startIndex`: The index of the first tool call in the group\n * - `endIndex`: The index of the last tool call in the group\n * - `children`: The rendered tool call components\n *\n * @example\n * ```tsx\n * // Collapsible tool group\n * ToolGroup: ({ startIndex, endIndex, children }) => (\n * <details className=\"tool-group\">\n * <summary>\n * {endIndex - startIndex + 1} tool calls\n * </summary>\n * <div className=\"tool-group-content\">\n * {children}\n * </div>\n * </details>\n * )\n * ```\n *\n * @example\n * ```tsx\n * // Custom styled tool group with header\n * ToolGroup: ({ startIndex, endIndex, children }) => (\n * <div className=\"border rounded-lg p-4 my-2\">\n * <div className=\"text-sm text-gray-600 mb-2\">\n * Tool execution #{startIndex + 1}-{endIndex + 1}\n * </div>\n * <div className=\"space-y-2\">\n * {children}\n * </div>\n * </div>\n * )\n * ```\n *\n * @param startIndex - Index of the first tool call in the group\n * @param endIndex - Index of the last tool call in the group\n * @param children - Rendered tool call components to display within the group\n *\n * @deprecated This feature is still experimental and subject to change.\n */\n ToolGroup?: ComponentType<\n PropsWithChildren<{ startIndex: number; endIndex: number }>\n >;\n }\n | undefined;\n };\n}\n\nconst ToolUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: ToolCallMessagePartComponent | undefined;\n} & ToolCallMessagePartProps) => {\n const Render = useToolUIs((s) => s.getToolUI(props.toolName)) ?? Fallback;\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst defaultComponents = {\n Text: () => (\n <p style={{ whiteSpace: \"pre-line\" }}>\n <MessagePartPrimitiveText />\n <MessagePartPrimitiveInProgress>\n <span style={{ fontFamily: \"revert\" }}>{\" \\u25CF\"}</span>\n </MessagePartPrimitiveInProgress>\n </p>\n ),\n Reasoning: () => null,\n Source: () => null,\n Image: () => <MessagePartPrimitiveImage />,\n File: () => null,\n Unstable_Audio: () => null,\n ToolGroup: ({ children }) => children,\n} satisfies MessagePrimitiveParts.Props[\"components\"];\n\ntype MessagePartComponentProps = {\n components: MessagePrimitiveParts.Props[\"components\"];\n};\n\nconst MessagePartComponent: FC<MessagePartComponentProps> = ({\n components: {\n Text = defaultComponents.Text,\n Reasoning = defaultComponents.Reasoning,\n Image = defaultComponents.Image,\n Source = defaultComponents.Source,\n File = defaultComponents.File,\n Unstable_Audio: Audio = defaultComponents.Unstable_Audio,\n tools = {},\n } = {},\n}) => {\n const MessagePartRuntime = useMessagePartRuntime();\n\n const part = useMessagePart();\n\n const type = part.type;\n if (type === \"tool-call\") {\n const addResult = (result: any) => MessagePartRuntime.addToolResult(result);\n if (\"Override\" in tools)\n return <tools.Override {...part} addResult={addResult} />;\n const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;\n return <ToolUIDisplay {...part} Fallback={Tool} addResult={addResult} />;\n }\n\n if (part.status.type === \"requires-action\")\n throw new Error(\"Encountered unexpected requires-action status\");\n\n switch (type) {\n case \"text\":\n return <Text {...part} />;\n\n case \"reasoning\":\n return <Reasoning {...part} />;\n\n case \"source\":\n return <Source {...part} />;\n\n case \"image\":\n // eslint-disable-next-line jsx-a11y/alt-text\n return <Image {...part} />;\n\n case \"file\":\n return <File {...part} />;\n\n case \"audio\":\n return <Audio {...part} />;\n\n default:\n const unhandledType: never = type;\n throw new Error(`Unknown message part type: ${unhandledType}`);\n }\n};\n\ntype MessagePartProps = {\n partIndex: number;\n components: MessagePrimitiveParts.Props[\"components\"];\n};\n\nconst MessagePartImpl: FC<MessagePartProps> = ({ partIndex, components }) => {\n const messageRuntime = useMessageRuntime();\n const runtime = useMemo(\n () => messageRuntime.getMessagePartByIndex(partIndex),\n [messageRuntime, partIndex],\n );\n\n return (\n <MessagePartRuntimeProvider runtime={runtime}>\n <MessagePartComponent components={components} />\n </MessagePartRuntimeProvider>\n );\n};\n\nconst MessagePart = memo(\n MessagePartImpl,\n (prev, next) =>\n prev.partIndex === next.partIndex &&\n prev.components?.Text === next.components?.Text &&\n prev.components?.Reasoning === next.components?.Reasoning &&\n prev.components?.Source === next.components?.Source &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.File === next.components?.File &&\n prev.components?.Unstable_Audio === next.components?.Unstable_Audio &&\n prev.components?.tools === next.components?.tools &&\n prev.components?.ToolGroup === next.components?.ToolGroup,\n);\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nconst EmptyPartFallback: FC<{\n status: MessagePartStatus;\n component: TextMessagePartComponent;\n}> = ({ status, component: Component }) => {\n return (\n <TextMessagePartProvider text=\"\" isRunning={status.type === \"running\"}>\n <Component type=\"text\" text=\"\" status={status} />\n </TextMessagePartProvider>\n );\n};\n\nconst EmptyPartsImpl: FC<MessagePartComponentProps> = ({ components }) => {\n const status =\n useMessage((s) => s.status as MessagePartStatus) ?? COMPLETE_STATUS;\n\n if (components?.Empty) return <components.Empty status={status} />;\n\n return (\n <EmptyPartFallback\n status={status}\n component={components?.Text ?? defaultComponents.Text}\n />\n );\n};\n\nconst EmptyParts = memo(\n EmptyPartsImpl,\n (prev, next) =>\n prev.components?.Empty === next.components?.Empty &&\n prev.components?.Text === next.components?.Text,\n);\n\n/**\n * Renders the parts of a message with support for multiple content types.\n *\n * This component automatically handles different types of message content including\n * text, images, files, tool calls, and more. It provides a flexible component\n * system for customizing how each content type is rendered.\n *\n * @example\n * ```tsx\n * <MessagePrimitive.Parts\n * components={{\n * Text: ({ text }) => <p className=\"message-text\">{text}</p>,\n * Image: ({ image }) => <img src={image} alt=\"Message image\" />,\n * tools: {\n * by_name: {\n * calculator: CalculatorTool,\n * weather: WeatherTool,\n * },\n * Fallback: DefaultToolComponent\n * }\n * }}\n * />\n * ```\n */\nexport const MessagePrimitiveParts: FC<MessagePrimitiveParts.Props> = ({\n components,\n}) => {\n const contentLength = useMessage((s) => s.content.length);\n const messageRanges = useMessagePartsGroups();\n\n const partsElements = useMemo(() => {\n if (contentLength === 0) {\n return <EmptyParts components={components} />;\n }\n\n return messageRanges.map((range) => {\n if (range.type === \"single\") {\n return (\n <MessagePart\n key={range.index}\n partIndex={range.index}\n components={components}\n />\n );\n } else {\n const ToolGroupComponent =\n components!.ToolGroup ?? defaultComponents.ToolGroup;\n return (\n <ToolGroupComponent\n key={range.startIndex}\n startIndex={range.startIndex}\n endIndex={range.endIndex}\n >\n {Array.from(\n { length: range.endIndex - range.startIndex + 1 },\n (_, i) => (\n <MessagePart\n key={i}\n partIndex={range.startIndex + i}\n components={components}\n />\n ),\n )}\n </ToolGroupComponent>\n );\n }\n });\n }, [messageRanges, components, contentLength]);\n\n return <>{partsElements}</>;\n};\n\nMessagePrimitiveParts.displayName = \"MessagePrimitive.Parts\";\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,kCAAkC;AAC3C,SAAS,gCAAgC;AACzC,SAAS,iCAAiC;AAY1C,SAAS,sCAAsC;AAE/C,SAAS,kBAAkB;AAyKlB,SAuNA,U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["../../../src/primitives/message/MessageParts.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ComponentType,\n type FC,\n memo,\n PropsWithChildren,\n useMemo,\n} from \"react\";\nimport {\n TextMessagePartProvider,\n useMessagePart,\n useMessagePartRuntime,\n useToolUIs,\n} from \"../../context\";\nimport {\n useMessage,\n useMessageRuntime,\n} from \"../../context/react/MessageContext\";\nimport { MessagePartRuntimeProvider } from \"../../context/providers/MessagePartRuntimeProvider\";\nimport { MessagePartPrimitiveText } from \"../messagePart/MessagePartText\";\nimport { MessagePartPrimitiveImage } from \"../messagePart/MessagePartImage\";\nimport type {\n Unstable_AudioMessagePartComponent,\n EmptyMessagePartComponent,\n TextMessagePartComponent,\n ImageMessagePartComponent,\n SourceMessagePartComponent,\n ToolCallMessagePartComponent,\n ToolCallMessagePartProps,\n FileMessagePartComponent,\n ReasoningMessagePartComponent,\n} from \"../../types/MessagePartComponentTypes\";\nimport { MessagePartPrimitiveInProgress } from \"../messagePart/MessagePartInProgress\";\nimport { MessagePartStatus } from \"../../types/AssistantTypes\";\nimport { useShallow } from \"zustand/shallow\";\n\ntype MessagePartRange =\n | { type: \"single\"; index: number }\n | { type: \"toolGroup\"; startIndex: number; endIndex: number };\n\n/**\n * Groups consecutive tool-call message parts into ranges.\n * Always groups tool calls, even if there's only one.\n */\nconst groupMessageParts = (\n messageTypes: readonly string[],\n): MessagePartRange[] => {\n const ranges: MessagePartRange[] = [];\n let currentToolGroupStart = -1;\n\n for (let i = 0; i < messageTypes.length; i++) {\n const type = messageTypes[i];\n\n if (type === \"tool-call\") {\n // Start a new tool group if we haven't started one\n if (currentToolGroupStart === -1) {\n currentToolGroupStart = i;\n }\n } else {\n // End current tool group if it exists\n if (currentToolGroupStart !== -1) {\n ranges.push({\n type: \"toolGroup\",\n startIndex: currentToolGroupStart,\n endIndex: i - 1,\n });\n currentToolGroupStart = -1;\n }\n\n // Add non-tool-call part individually\n ranges.push({ type: \"single\", index: i });\n }\n }\n\n // Handle any remaining tool group at the end\n if (currentToolGroupStart !== -1) {\n ranges.push({\n type: \"toolGroup\",\n startIndex: currentToolGroupStart,\n endIndex: messageTypes.length - 1,\n });\n }\n\n return ranges;\n};\n\nconst useMessagePartsGroups = (): MessagePartRange[] => {\n const messageTypes = useMessage(\n useShallow((m) => m.content.map((c) => c.type)),\n );\n\n return useMemo(() => {\n if (messageTypes.length === 0) {\n return [];\n }\n return groupMessageParts(messageTypes);\n }, [messageTypes]);\n};\n\nexport namespace MessagePrimitiveParts {\n export type Props = {\n /**\n * Component configuration for rendering different types of message content.\n *\n * You can provide custom components for each content type (text, image, file, etc.)\n * and configure tool rendering behavior. If not provided, default components will be used.\n */\n components?:\n | {\n /** Component for rendering empty messages */\n Empty?: EmptyMessagePartComponent | undefined;\n /** Component for rendering text content */\n Text?: TextMessagePartComponent | undefined;\n /** Component for rendering reasoning content (typically hidden) */\n Reasoning?: ReasoningMessagePartComponent | undefined;\n /** Component for rendering source content */\n Source?: SourceMessagePartComponent | undefined;\n /** Component for rendering image content */\n Image?: ImageMessagePartComponent | undefined;\n /** Component for rendering file content */\n File?: FileMessagePartComponent | undefined;\n /** Component for rendering audio content (experimental) */\n Unstable_Audio?: Unstable_AudioMessagePartComponent | undefined;\n /** Configuration for tool call rendering */\n tools?:\n | {\n /** Map of tool names to their specific components */\n by_name?:\n | Record<string, ToolCallMessagePartComponent | undefined>\n | undefined;\n /** Fallback component for unregistered tools */\n Fallback?: ComponentType<ToolCallMessagePartProps> | undefined;\n }\n | {\n /** Override component that handles all tool calls */\n Override: ComponentType<ToolCallMessagePartProps>;\n }\n | undefined;\n\n /**\n * Component for rendering grouped consecutive tool calls.\n *\n * When provided, this component will automatically wrap consecutive tool-call\n * message parts, allowing you to create collapsible sections, custom styling,\n * or other grouped presentations for multiple tool calls.\n *\n * The component receives:\n * - `startIndex`: The index of the first tool call in the group\n * - `endIndex`: The index of the last tool call in the group\n * - `children`: The rendered tool call components\n *\n * @example\n * ```tsx\n * // Collapsible tool group\n * ToolGroup: ({ startIndex, endIndex, children }) => (\n * <details className=\"tool-group\">\n * <summary>\n * {endIndex - startIndex + 1} tool calls\n * </summary>\n * <div className=\"tool-group-content\">\n * {children}\n * </div>\n * </details>\n * )\n * ```\n *\n * @example\n * ```tsx\n * // Custom styled tool group with header\n * ToolGroup: ({ startIndex, endIndex, children }) => (\n * <div className=\"border rounded-lg p-4 my-2\">\n * <div className=\"text-sm text-gray-600 mb-2\">\n * Tool execution #{startIndex + 1}-{endIndex + 1}\n * </div>\n * <div className=\"space-y-2\">\n * {children}\n * </div>\n * </div>\n * )\n * ```\n *\n * @param startIndex - Index of the first tool call in the group\n * @param endIndex - Index of the last tool call in the group\n * @param children - Rendered tool call components to display within the group\n *\n * @deprecated This feature is still experimental and subject to change.\n */\n ToolGroup?: ComponentType<\n PropsWithChildren<{ startIndex: number; endIndex: number }>\n >;\n }\n | undefined;\n };\n}\n\nconst ToolUIDisplay = ({\n Fallback,\n ...props\n}: {\n Fallback: ToolCallMessagePartComponent | undefined;\n} & ToolCallMessagePartProps) => {\n const Render = useToolUIs((s) => s.getToolUI(props.toolName)) ?? Fallback;\n if (!Render) return null;\n return <Render {...props} />;\n};\n\nconst defaultComponents = {\n Text: () => (\n <p style={{ whiteSpace: \"pre-line\" }}>\n <MessagePartPrimitiveText />\n <MessagePartPrimitiveInProgress>\n <span style={{ fontFamily: \"revert\" }}>{\" \\u25CF\"}</span>\n </MessagePartPrimitiveInProgress>\n </p>\n ),\n Reasoning: () => null,\n Source: () => null,\n Image: () => <MessagePartPrimitiveImage />,\n File: () => null,\n Unstable_Audio: () => null,\n ToolGroup: ({ children }) => children,\n} satisfies MessagePrimitiveParts.Props[\"components\"];\n\ntype MessagePartComponentProps = {\n components: MessagePrimitiveParts.Props[\"components\"];\n};\n\nconst MessagePartComponent: FC<MessagePartComponentProps> = ({\n components: {\n Text = defaultComponents.Text,\n Reasoning = defaultComponents.Reasoning,\n Image = defaultComponents.Image,\n Source = defaultComponents.Source,\n File = defaultComponents.File,\n Unstable_Audio: Audio = defaultComponents.Unstable_Audio,\n tools = {},\n } = {},\n}) => {\n const MessagePartRuntime = useMessagePartRuntime();\n\n const part = useMessagePart();\n\n const type = part.type;\n if (type === \"tool-call\") {\n const addResult = (result: any) => MessagePartRuntime.addToolResult(result);\n if (\"Override\" in tools)\n return <tools.Override {...part} addResult={addResult} />;\n const Tool = tools.by_name?.[part.toolName] ?? tools.Fallback;\n return <ToolUIDisplay {...part} Fallback={Tool} addResult={addResult} />;\n }\n\n if (part.status.type === \"requires-action\")\n throw new Error(\"Encountered unexpected requires-action status\");\n\n switch (type) {\n case \"text\":\n return <Text {...part} />;\n\n case \"reasoning\":\n return <Reasoning {...part} />;\n\n case \"source\":\n return <Source {...part} />;\n\n case \"image\":\n // eslint-disable-next-line jsx-a11y/alt-text\n return <Image {...part} />;\n\n case \"file\":\n return <File {...part} />;\n\n case \"audio\":\n return <Audio {...part} />;\n\n default:\n const unhandledType: never = type;\n throw new Error(`Unknown message part type: ${unhandledType}`);\n }\n};\n\nexport namespace MessagePrimitivePartByIndex {\n export type Props = {\n index: number;\n components: MessagePrimitiveParts.Props[\"components\"];\n };\n}\n\n/**\n * Renders a single message part at the specified index.\n *\n * This component provides direct access to render a specific message part\n * within the current message context, using the provided component configuration.\n *\n * @example\n * ```tsx\n * <MessagePrimitive.PartByIndex\n * index={0}\n * components={{\n * Text: MyTextComponent,\n * Image: MyImageComponent\n * }}\n * />\n * ```\n */\nexport const MessagePrimitivePartByIndex: FC<MessagePrimitivePartByIndex.Props> =\n memo(\n ({ index, components }) => {\n const messageRuntime = useMessageRuntime();\n const runtime = useMemo(\n () => messageRuntime.getMessagePartByIndex(index),\n [messageRuntime, index],\n );\n\n return (\n <MessagePartRuntimeProvider runtime={runtime}>\n <MessagePartComponent components={components} />\n </MessagePartRuntimeProvider>\n );\n },\n (prev, next) =>\n prev.index === next.index &&\n prev.components?.Text === next.components?.Text &&\n prev.components?.Reasoning === next.components?.Reasoning &&\n prev.components?.Source === next.components?.Source &&\n prev.components?.Image === next.components?.Image &&\n prev.components?.File === next.components?.File &&\n prev.components?.Unstable_Audio === next.components?.Unstable_Audio &&\n prev.components?.tools === next.components?.tools &&\n prev.components?.ToolGroup === next.components?.ToolGroup,\n );\n\nMessagePrimitivePartByIndex.displayName = \"MessagePrimitive.PartByIndex\";\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nconst EmptyPartFallback: FC<{\n status: MessagePartStatus;\n component: TextMessagePartComponent;\n}> = ({ status, component: Component }) => {\n return (\n <TextMessagePartProvider text=\"\" isRunning={status.type === \"running\"}>\n <Component type=\"text\" text=\"\" status={status} />\n </TextMessagePartProvider>\n );\n};\n\nconst EmptyPartsImpl: FC<MessagePartComponentProps> = ({ components }) => {\n const status =\n useMessage((s) => s.status as MessagePartStatus) ?? COMPLETE_STATUS;\n\n if (components?.Empty) return <components.Empty status={status} />;\n\n return (\n <EmptyPartFallback\n status={status}\n component={components?.Text ?? defaultComponents.Text}\n />\n );\n};\n\nconst EmptyParts = memo(\n EmptyPartsImpl,\n (prev, next) =>\n prev.components?.Empty === next.components?.Empty &&\n prev.components?.Text === next.components?.Text,\n);\n\n/**\n * Renders the parts of a message with support for multiple content types.\n *\n * This component automatically handles different types of message content including\n * text, images, files, tool calls, and more. It provides a flexible component\n * system for customizing how each content type is rendered.\n *\n * @example\n * ```tsx\n * <MessagePrimitive.Parts\n * components={{\n * Text: ({ text }) => <p className=\"message-text\">{text}</p>,\n * Image: ({ image }) => <img src={image} alt=\"Message image\" />,\n * tools: {\n * by_name: {\n * calculator: CalculatorTool,\n * weather: WeatherTool,\n * },\n * Fallback: DefaultToolComponent\n * }\n * }}\n * />\n * ```\n */\nexport const MessagePrimitiveParts: FC<MessagePrimitiveParts.Props> = ({\n components,\n}) => {\n const contentLength = useMessage((s) => s.content.length);\n const messageRanges = useMessagePartsGroups();\n\n const partsElements = useMemo(() => {\n if (contentLength === 0) {\n return <EmptyParts components={components} />;\n }\n\n return messageRanges.map((range) => {\n if (range.type === \"single\") {\n return (\n <MessagePrimitivePartByIndex\n key={range.index}\n index={range.index}\n components={components}\n />\n );\n } else {\n const ToolGroupComponent =\n components!.ToolGroup ?? defaultComponents.ToolGroup;\n return (\n <ToolGroupComponent\n key={range.startIndex}\n startIndex={range.startIndex}\n endIndex={range.endIndex}\n >\n {Array.from(\n { length: range.endIndex - range.startIndex + 1 },\n (_, i) => (\n <MessagePrimitivePartByIndex\n key={i}\n index={range.startIndex + i}\n components={components}\n />\n ),\n )}\n </ToolGroupComponent>\n );\n }\n });\n }, [messageRanges, components, contentLength]);\n\n return <>{partsElements}</>;\n};\n\nMessagePrimitiveParts.displayName = \"MessagePrimitive.Parts\";\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,kCAAkC;AAC3C,SAAS,gCAAgC;AACzC,SAAS,iCAAiC;AAY1C,SAAS,sCAAsC;AAE/C,SAAS,kBAAkB;AAyKlB,SA2OA,UA3OA,KAKL,YALK;AA/JT,IAAM,oBAAoB,CACxB,iBACuB;AACvB,QAAM,SAA6B,CAAC;AACpC,MAAI,wBAAwB;AAE5B,WAAS,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;AAC5C,UAAM,OAAO,aAAa,CAAC;AAE3B,QAAI,SAAS,aAAa;AAExB,UAAI,0BAA0B,IAAI;AAChC,gCAAwB;AAAA,MAC1B;AAAA,IACF,OAAO;AAEL,UAAI,0BAA0B,IAAI;AAChC,eAAO,KAAK;AAAA,UACV,MAAM;AAAA,UACN,YAAY;AAAA,UACZ,UAAU,IAAI;AAAA,QAChB,CAAC;AACD,gCAAwB;AAAA,MAC1B;AAGA,aAAO,KAAK,EAAE,MAAM,UAAU,OAAO,EAAE,CAAC;AAAA,IAC1C;AAAA,EACF;AAGA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,YAAwB;AAAA,IAC7C;AAEA,WAAO,cAAc,IAAI,CAAC,UAAU;AAClC,UAAI,MAAM,SAAS,UAAU;AAC3B,eACE;AAAA,UAAC;AAAA;AAAA,YAEC,OAAO,MAAM;AAAA,YACb;AAAA;AAAA,UAFK,MAAM;AAAA,QAGb;AAAA,MAEJ,OAAO;AACL,cAAM,qBACJ,WAAY,aAAa,kBAAkB;AAC7C,eACE;AAAA,UAAC;AAAA;AAAA,YAEC,YAAY,MAAM;AAAA,YAClB,UAAU,MAAM;AAAA,YAEf,gBAAM;AAAA,cACL,EAAE,QAAQ,MAAM,WAAW,MAAM,aAAa,EAAE;AAAA,cAChD,CAAC,GAAG,MACF;AAAA,gBAAC;AAAA;AAAA,kBAEC,OAAO,MAAM,aAAa;AAAA,kBAC1B;AAAA;AAAA,gBAFK;AAAA,cAGP;AAAA,YAEJ;AAAA;AAAA,UAbK,MAAM;AAAA,QAcb;AAAA,MAEJ;AAAA,IACF,CAAC;AAAA,EACH,GAAG,CAAC,eAAe,YAAY,aAAa,CAAC;AAE7C,SAAO,gCAAG,yBAAc;AAC1B;AAEA,sBAAsB,cAAc;","names":[]}
@@ -1,8 +1,10 @@
1
1
  export { MessagePrimitiveRoot as Root } from "./MessageRoot";
2
2
  export { MessagePrimitiveParts as Parts } from "./MessageParts";
3
+ export { MessagePrimitivePartByIndex as PartByIndex } from "./MessageParts";
3
4
  export { MessagePrimitiveParts as Content } from "./MessageParts";
4
5
  export { MessagePrimitiveIf as If } from "./MessageIf";
5
6
  export { MessagePrimitiveAttachments as Attachments } from "./MessageAttachments";
7
+ export { MessagePrimitiveAttachmentByIndex as AttachmentByIndex } from "./MessageAttachments";
6
8
  export { MessagePrimitiveError as Error } from "./MessageError";
7
9
  export { MessagePrimitiveUnstable_PartsGrouped as Unstable_PartsGrouped, MessagePrimitiveUnstable_PartsGroupedByParentId as Unstable_PartsGroupedByParentId, } from "./MessagePartsGrouped";
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,qBAAqB,IAAI,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,qBAAqB,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,kBAAkB,IAAI,EAAE,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,2BAA2B,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,qBAAqB,IAAI,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EACL,qCAAqC,IAAI,qBAAqB,EAC9D,+CAA+C,IAAI,+BAA+B,GACnF,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,qBAAqB,IAAI,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,2BAA2B,IAAI,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,qBAAqB,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,kBAAkB,IAAI,EAAE,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,2BAA2B,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,iCAAiC,IAAI,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9F,OAAO,EAAE,qBAAqB,IAAI,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EACL,qCAAqC,IAAI,qBAAqB,EAC9D,+CAA+C,IAAI,+BAA+B,GACnF,MAAM,uBAAuB,CAAC"}
@@ -1,19 +1,23 @@
1
1
  // src/primitives/message/index.ts
2
2
  import { MessagePrimitiveRoot } from "./MessageRoot.js";
3
3
  import { MessagePrimitiveParts } from "./MessageParts.js";
4
+ import { MessagePrimitivePartByIndex } from "./MessageParts.js";
4
5
  import { MessagePrimitiveParts as MessagePrimitiveParts2 } from "./MessageParts.js";
5
6
  import { MessagePrimitiveIf } from "./MessageIf.js";
6
7
  import { MessagePrimitiveAttachments } from "./MessageAttachments.js";
8
+ import { MessagePrimitiveAttachmentByIndex } from "./MessageAttachments.js";
7
9
  import { MessagePrimitiveError } from "./MessageError.js";
8
10
  import {
9
11
  MessagePrimitiveUnstable_PartsGrouped,
10
12
  MessagePrimitiveUnstable_PartsGroupedByParentId
11
13
  } from "./MessagePartsGrouped.js";
12
14
  export {
15
+ MessagePrimitiveAttachmentByIndex as AttachmentByIndex,
13
16
  MessagePrimitiveAttachments as Attachments,
14
17
  MessagePrimitiveParts2 as Content,
15
18
  MessagePrimitiveError as Error,
16
19
  MessagePrimitiveIf as If,
20
+ MessagePrimitivePartByIndex as PartByIndex,
17
21
  MessagePrimitiveParts as Parts,
18
22
  MessagePrimitiveRoot as Root,
19
23
  MessagePrimitiveUnstable_PartsGrouped as Unstable_PartsGrouped,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/primitives/message/index.ts"],"sourcesContent":["export { MessagePrimitiveRoot as Root } from \"./MessageRoot\";\nexport { MessagePrimitiveParts as Parts } from \"./MessageParts\";\nexport { MessagePrimitiveParts as Content } from \"./MessageParts\";\nexport { MessagePrimitiveIf as If } from \"./MessageIf\";\nexport { MessagePrimitiveAttachments as Attachments } from \"./MessageAttachments\";\nexport { MessagePrimitiveError as Error } from \"./MessageError\";\nexport {\n MessagePrimitiveUnstable_PartsGrouped as Unstable_PartsGrouped,\n MessagePrimitiveUnstable_PartsGroupedByParentId as Unstable_PartsGroupedByParentId,\n} from \"./MessagePartsGrouped\";\n"],"mappings":";AAAA,SAAiC,4BAAY;AAC7C,SAAkC,6BAAa;AAC/C,SAAkC,yBAAzBA,8BAAwC;AACjD,SAA+B,0BAAU;AACzC,SAAwC,mCAAmB;AAC3D,SAAkC,6BAAa;AAC/C;AAAA,EAC2C;AAAA,EACU;AAAA,OAC9C;","names":["MessagePrimitiveParts"]}
1
+ {"version":3,"sources":["../../../src/primitives/message/index.ts"],"sourcesContent":["export { MessagePrimitiveRoot as Root } from \"./MessageRoot\";\nexport { MessagePrimitiveParts as Parts } from \"./MessageParts\";\nexport { MessagePrimitivePartByIndex as PartByIndex } from \"./MessageParts\";\nexport { MessagePrimitiveParts as Content } from \"./MessageParts\";\nexport { MessagePrimitiveIf as If } from \"./MessageIf\";\nexport { MessagePrimitiveAttachments as Attachments } from \"./MessageAttachments\";\nexport { MessagePrimitiveAttachmentByIndex as AttachmentByIndex } from \"./MessageAttachments\";\nexport { MessagePrimitiveError as Error } from \"./MessageError\";\nexport {\n MessagePrimitiveUnstable_PartsGrouped as Unstable_PartsGrouped,\n MessagePrimitiveUnstable_PartsGroupedByParentId as Unstable_PartsGroupedByParentId,\n} from \"./MessagePartsGrouped\";\n"],"mappings":";AAAA,SAAiC,4BAAY;AAC7C,SAAkC,6BAAa;AAC/C,SAAwC,mCAAmB;AAC3D,SAAkC,yBAAzBA,8BAAwC;AACjD,SAA+B,0BAAU;AACzC,SAAwC,mCAAmB;AAC3D,SAA8C,yCAAyB;AACvE,SAAkC,6BAAa;AAC/C;AAAA,EAC2C;AAAA,EACU;AAAA,OAC9C;","names":["MessagePrimitiveParts"]}
@@ -48,6 +48,30 @@ export declare namespace ThreadPrimitiveMessages {
48
48
  };
49
49
  };
50
50
  }
51
+ export declare namespace ThreadPrimitiveMessageByIndex {
52
+ type Props = {
53
+ index: number;
54
+ components: ThreadPrimitiveMessages.Props["components"];
55
+ };
56
+ }
57
+ /**
58
+ * Renders a single message at the specified index in the current thread.
59
+ *
60
+ * This component provides message context for a specific message in the thread
61
+ * and renders it using the provided component configuration.
62
+ *
63
+ * @example
64
+ * ```tsx
65
+ * <ThreadPrimitive.MessageByIndex
66
+ * index={0}
67
+ * components={{
68
+ * UserMessage: MyUserMessage,
69
+ * AssistantMessage: MyAssistantMessage
70
+ * }}
71
+ * />
72
+ * ```
73
+ */
74
+ export declare const ThreadPrimitiveMessageByIndex: FC<ThreadPrimitiveMessageByIndex.Props>;
51
75
  /**
52
76
  * Renders all messages in the current thread using the provided component configuration.
53
77
  *
@@ -1 +1 @@
1
- {"version":3,"file":"ThreadMessages.d.ts","sourceRoot":"","sources":["../../../src/primitives/thread/ThreadMessages.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,EAAE,EAAiB,MAAM,OAAO,CAAC;AAMnE,yBAAiB,uBAAuB,CAAC;IACvC,KAAY,KAAK,GAAG;QAClB;;;;;;;;;WASG;QACH,UAAU,EACN;YACE,iDAAiD;YACjD,OAAO,EAAE,aAAa,CAAC;YACvB,mDAAmD;YACnD,YAAY,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YACzC,6DAA6D;YAC7D,gBAAgB,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YAC7C,kEAAkE;YAClE,qBAAqB,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YAClD,+DAA+D;YAC/D,kBAAkB,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YAC/C,0DAA0D;YAC1D,WAAW,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YACxC,+DAA+D;YAC/D,gBAAgB,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YAC7C,4DAA4D;YAC5D,aAAa,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;SAC3C,GACD;YACE,4DAA4D;YAC5D,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YACpC,mDAAmD;YACnD,YAAY,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;YACzC,6DAA6D;YAC7D,gBAAgB,CAAC,E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