@assistant-ui/react 0.7.46 → 0.7.47

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 (209) hide show
  1. package/dist/api/AssistantRuntime.d.ts +1 -0
  2. package/dist/api/AssistantRuntime.d.ts.map +1 -1
  3. package/dist/api/AssistantRuntime.js +5 -0
  4. package/dist/api/AssistantRuntime.js.map +1 -1
  5. package/dist/api/AssistantRuntime.mjs +5 -0
  6. package/dist/api/AssistantRuntime.mjs.map +1 -1
  7. package/dist/api/AttachmentRuntime.d.ts +1 -0
  8. package/dist/api/AttachmentRuntime.d.ts.map +1 -1
  9. package/dist/api/AttachmentRuntime.js +5 -0
  10. package/dist/api/AttachmentRuntime.js.map +1 -1
  11. package/dist/api/AttachmentRuntime.mjs +5 -0
  12. package/dist/api/AttachmentRuntime.mjs.map +1 -1
  13. package/dist/api/ComposerRuntime.d.ts +2 -0
  14. package/dist/api/ComposerRuntime.d.ts.map +1 -1
  15. package/dist/api/ComposerRuntime.js +19 -0
  16. package/dist/api/ComposerRuntime.js.map +1 -1
  17. package/dist/api/ComposerRuntime.mjs +19 -0
  18. package/dist/api/ComposerRuntime.mjs.map +1 -1
  19. package/dist/api/ContentPartRuntime.d.ts +1 -0
  20. package/dist/api/ContentPartRuntime.d.ts.map +1 -1
  21. package/dist/api/ContentPartRuntime.js +5 -0
  22. package/dist/api/ContentPartRuntime.js.map +1 -1
  23. package/dist/api/ContentPartRuntime.mjs +5 -0
  24. package/dist/api/ContentPartRuntime.mjs.map +1 -1
  25. package/dist/api/MessageRuntime.d.ts +1 -0
  26. package/dist/api/MessageRuntime.d.ts.map +1 -1
  27. package/dist/api/MessageRuntime.js +13 -0
  28. package/dist/api/MessageRuntime.js.map +1 -1
  29. package/dist/api/MessageRuntime.mjs +13 -0
  30. package/dist/api/MessageRuntime.mjs.map +1 -1
  31. package/dist/api/ThreadListItemRuntime.d.ts +1 -0
  32. package/dist/api/ThreadListItemRuntime.d.ts.map +1 -1
  33. package/dist/api/ThreadListItemRuntime.js +11 -0
  34. package/dist/api/ThreadListItemRuntime.js.map +1 -1
  35. package/dist/api/ThreadListItemRuntime.mjs +11 -0
  36. package/dist/api/ThreadListItemRuntime.mjs.map +1 -1
  37. package/dist/api/ThreadListRuntime.d.ts +1 -0
  38. package/dist/api/ThreadListRuntime.d.ts.map +1 -1
  39. package/dist/api/ThreadListRuntime.js +10 -0
  40. package/dist/api/ThreadListRuntime.js.map +1 -1
  41. package/dist/api/ThreadListRuntime.mjs +10 -0
  42. package/dist/api/ThreadListRuntime.mjs.map +1 -1
  43. package/dist/api/ThreadRuntime.d.ts +1 -1
  44. package/dist/api/ThreadRuntime.d.ts.map +1 -1
  45. package/dist/api/ThreadRuntime.js +14 -3
  46. package/dist/api/ThreadRuntime.js.map +1 -1
  47. package/dist/api/ThreadRuntime.mjs +14 -3
  48. package/dist/api/ThreadRuntime.mjs.map +1 -1
  49. package/dist/context/providers/AssistantRuntimeProvider.d.ts.map +1 -1
  50. package/dist/context/providers/AssistantRuntimeProvider.js +5 -14
  51. package/dist/context/providers/AssistantRuntimeProvider.js.map +1 -1
  52. package/dist/context/providers/AssistantRuntimeProvider.mjs +5 -14
  53. package/dist/context/providers/AssistantRuntimeProvider.mjs.map +1 -1
  54. package/dist/context/providers/AttachmentRuntimeProvider.d.ts.map +1 -1
  55. package/dist/context/providers/AttachmentRuntimeProvider.js +5 -16
  56. package/dist/context/providers/AttachmentRuntimeProvider.js.map +1 -1
  57. package/dist/context/providers/AttachmentRuntimeProvider.mjs +6 -21
  58. package/dist/context/providers/AttachmentRuntimeProvider.mjs.map +1 -1
  59. package/dist/context/providers/ContentPartRuntimeProvider.d.ts +0 -1
  60. package/dist/context/providers/ContentPartRuntimeProvider.d.ts.map +1 -1
  61. package/dist/context/providers/ContentPartRuntimeProvider.js +5 -15
  62. package/dist/context/providers/ContentPartRuntimeProvider.js.map +1 -1
  63. package/dist/context/providers/ContentPartRuntimeProvider.mjs +4 -13
  64. package/dist/context/providers/ContentPartRuntimeProvider.mjs.map +1 -1
  65. package/dist/context/providers/MessageRuntimeProvider.d.ts.map +1 -1
  66. package/dist/context/providers/MessageRuntimeProvider.js +3 -22
  67. package/dist/context/providers/MessageRuntimeProvider.js.map +1 -1
  68. package/dist/context/providers/MessageRuntimeProvider.mjs +3 -22
  69. package/dist/context/providers/MessageRuntimeProvider.mjs.map +1 -1
  70. package/dist/context/providers/TextContentPartProvider.d.ts.map +1 -1
  71. package/dist/context/providers/TextContentPartProvider.js +13 -12
  72. package/dist/context/providers/TextContentPartProvider.js.map +1 -1
  73. package/dist/context/providers/TextContentPartProvider.mjs +13 -12
  74. package/dist/context/providers/TextContentPartProvider.mjs.map +1 -1
  75. package/dist/context/providers/ThreadListItemRuntimeProvider.d.ts +0 -1
  76. package/dist/context/providers/ThreadListItemRuntimeProvider.d.ts.map +1 -1
  77. package/dist/context/providers/ThreadListItemRuntimeProvider.js +5 -15
  78. package/dist/context/providers/ThreadListItemRuntimeProvider.js.map +1 -1
  79. package/dist/context/providers/ThreadListItemRuntimeProvider.mjs +4 -13
  80. package/dist/context/providers/ThreadListItemRuntimeProvider.mjs.map +1 -1
  81. package/dist/context/providers/ThreadRuntimeProvider.d.ts.map +1 -1
  82. package/dist/context/providers/ThreadRuntimeProvider.js +5 -24
  83. package/dist/context/providers/ThreadRuntimeProvider.js.map +1 -1
  84. package/dist/context/providers/ThreadRuntimeProvider.mjs +6 -25
  85. package/dist/context/providers/ThreadRuntimeProvider.mjs.map +1 -1
  86. package/dist/context/react/AssistantContext.d.ts +26 -17
  87. package/dist/context/react/AssistantContext.d.ts.map +1 -1
  88. package/dist/context/react/AssistantContext.js +3 -4
  89. package/dist/context/react/AssistantContext.js.map +1 -1
  90. package/dist/context/react/AssistantContext.mjs +3 -4
  91. package/dist/context/react/AssistantContext.mjs.map +1 -1
  92. package/dist/context/react/AttachmentContext.d.ts +558 -30
  93. package/dist/context/react/AttachmentContext.d.ts.map +1 -1
  94. package/dist/context/react/AttachmentContext.js +32 -52
  95. package/dist/context/react/AttachmentContext.js.map +1 -1
  96. package/dist/context/react/AttachmentContext.mjs +33 -52
  97. package/dist/context/react/AttachmentContext.mjs.map +1 -1
  98. package/dist/context/react/ComposerContext.d.ts +28 -19
  99. package/dist/context/react/ComposerContext.d.ts.map +1 -1
  100. package/dist/context/react/ComposerContext.js +2 -19
  101. package/dist/context/react/ComposerContext.js.map +1 -1
  102. package/dist/context/react/ComposerContext.mjs +4 -20
  103. package/dist/context/react/ComposerContext.mjs.map +1 -1
  104. package/dist/context/react/ContentPartContext.d.ts +22 -16
  105. package/dist/context/react/ContentPartContext.d.ts.map +1 -1
  106. package/dist/context/react/ContentPartContext.js +2 -7
  107. package/dist/context/react/ContentPartContext.js.map +1 -1
  108. package/dist/context/react/ContentPartContext.mjs +2 -6
  109. package/dist/context/react/ContentPartContext.mjs.map +1 -1
  110. package/dist/context/react/MessageContext.d.ts +49 -29
  111. package/dist/context/react/MessageContext.d.ts.map +1 -1
  112. package/dist/context/react/MessageContext.js +5 -9
  113. package/dist/context/react/MessageContext.js.map +1 -1
  114. package/dist/context/react/MessageContext.mjs +5 -8
  115. package/dist/context/react/MessageContext.mjs.map +1 -1
  116. package/dist/context/react/ThreadContext.d.ts +44 -24
  117. package/dist/context/react/ThreadContext.d.ts.map +1 -1
  118. package/dist/context/react/ThreadContext.js +5 -9
  119. package/dist/context/react/ThreadContext.js.map +1 -1
  120. package/dist/context/react/ThreadContext.mjs +5 -8
  121. package/dist/context/react/ThreadContext.mjs.map +1 -1
  122. package/dist/context/react/ThreadListItemContext.d.ts +22 -16
  123. package/dist/context/react/ThreadListItemContext.d.ts.map +1 -1
  124. package/dist/context/react/ThreadListItemContext.js +3 -6
  125. package/dist/context/react/ThreadListItemContext.js.map +1 -1
  126. package/dist/context/react/ThreadListItemContext.mjs +3 -5
  127. package/dist/context/react/ThreadListItemContext.mjs.map +1 -1
  128. package/dist/context/react/index.d.ts +1 -0
  129. package/dist/context/react/index.d.ts.map +1 -1
  130. package/dist/context/react/index.js +3 -0
  131. package/dist/context/react/index.js.map +1 -1
  132. package/dist/context/react/index.mjs +2 -0
  133. package/dist/context/react/index.mjs.map +1 -1
  134. package/dist/context/react/utils/createContextHook.d.ts +3 -8
  135. package/dist/context/react/utils/createContextHook.d.ts.map +1 -1
  136. package/dist/context/react/utils/createContextHook.js.map +1 -1
  137. package/dist/context/react/utils/createContextHook.mjs.map +1 -1
  138. package/dist/context/react/utils/createStateHookForRuntime.d.ts +31 -0
  139. package/dist/context/react/utils/createStateHookForRuntime.d.ts.map +1 -0
  140. package/dist/context/react/utils/createStateHookForRuntime.js +47 -0
  141. package/dist/context/react/utils/createStateHookForRuntime.js.map +1 -0
  142. package/dist/context/react/utils/createStateHookForRuntime.mjs +24 -0
  143. package/dist/context/react/utils/createStateHookForRuntime.mjs.map +1 -0
  144. package/dist/context/react/utils/ensureBinding.d.ts +2 -0
  145. package/dist/context/react/utils/ensureBinding.d.ts.map +1 -0
  146. package/dist/context/react/utils/ensureBinding.js +36 -0
  147. package/dist/context/react/utils/ensureBinding.js.map +1 -0
  148. package/dist/context/react/utils/ensureBinding.mjs +11 -0
  149. package/dist/context/react/utils/ensureBinding.mjs.map +1 -0
  150. package/dist/context/react/utils/useRuntimeState.d.ts +10 -0
  151. package/dist/context/react/utils/useRuntimeState.d.ts.map +1 -0
  152. package/dist/context/react/utils/useRuntimeState.js +48 -0
  153. package/dist/context/react/utils/useRuntimeState.js.map +1 -0
  154. package/dist/context/react/utils/useRuntimeState.mjs +22 -0
  155. package/dist/context/react/utils/useRuntimeState.mjs.map +1 -0
  156. package/dist/runtimes/adapters/attachment/AttachmentAdapter.d.ts +1 -1
  157. package/dist/runtimes/adapters/attachment/AttachmentAdapter.d.ts.map +1 -1
  158. package/dist/runtimes/adapters/attachment/AttachmentAdapter.js.map +1 -1
  159. package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.d.ts +1 -1
  160. package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.d.ts.map +1 -1
  161. package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.js +1 -1
  162. package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.js.map +1 -1
  163. package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.mjs +1 -1
  164. package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.mjs.map +1 -1
  165. package/dist/runtimes/adapters/thread-history/ThreadHistoryAdapter.d.ts.map +1 -1
  166. package/dist/runtimes/adapters/thread-history/ThreadHistoryAdapter.js.map +1 -1
  167. package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts.map +1 -1
  168. package/dist/runtimes/composer/BaseComposerRuntimeCore.js +22 -2
  169. package/dist/runtimes/composer/BaseComposerRuntimeCore.js.map +1 -1
  170. package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs +22 -2
  171. package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs.map +1 -1
  172. package/dist/runtimes/local/useLocalRuntime.d.ts.map +1 -1
  173. package/dist/runtimes/local/useLocalRuntime.js +4 -0
  174. package/dist/runtimes/local/useLocalRuntime.js.map +1 -1
  175. package/dist/runtimes/local/useLocalRuntime.mjs +4 -0
  176. package/dist/runtimes/local/useLocalRuntime.mjs.map +1 -1
  177. package/package.json +3 -3
  178. package/src/api/AssistantRuntime.ts +7 -0
  179. package/src/api/AttachmentRuntime.ts +6 -0
  180. package/src/api/ComposerRuntime.ts +21 -0
  181. package/src/api/ContentPartRuntime.ts +6 -0
  182. package/src/api/MessageRuntime.ts +15 -0
  183. package/src/api/ThreadListItemRuntime.ts +12 -0
  184. package/src/api/ThreadListRuntime.ts +11 -0
  185. package/src/api/ThreadRuntime.ts +15 -4
  186. package/src/context/providers/AssistantRuntimeProvider.tsx +5 -17
  187. package/src/context/providers/AttachmentRuntimeProvider.tsx +6 -24
  188. package/src/context/providers/ContentPartRuntimeProvider.tsx +4 -14
  189. package/src/context/providers/MessageRuntimeProvider.tsx +5 -31
  190. package/src/context/providers/TextContentPartProvider.tsx +26 -22
  191. package/src/context/providers/ThreadListItemRuntimeProvider.tsx +3 -14
  192. package/src/context/providers/ThreadRuntimeProvider.tsx +7 -33
  193. package/src/context/react/AssistantContext.ts +7 -7
  194. package/src/context/react/AttachmentContext.ts +45 -136
  195. package/src/context/react/ComposerContext.ts +6 -29
  196. package/src/context/react/ContentPartContext.ts +3 -8
  197. package/src/context/react/MessageContext.ts +10 -13
  198. package/src/context/react/ThreadContext.ts +9 -12
  199. package/src/context/react/ThreadListItemContext.ts +4 -7
  200. package/src/context/react/index.ts +2 -0
  201. package/src/context/react/utils/createContextHook.ts +1 -3
  202. package/src/context/react/utils/createStateHookForRuntime.ts +80 -0
  203. package/src/context/react/utils/ensureBinding.ts +45 -0
  204. package/src/context/react/utils/useRuntimeState.ts +43 -0
  205. package/src/runtimes/adapters/attachment/AttachmentAdapter.ts +3 -1
  206. package/src/runtimes/adapters/attachment/CompositeAttachmentAdapter.ts +1 -1
  207. package/src/runtimes/adapters/thread-history/ThreadHistoryAdapter.ts +1 -0
  208. package/src/runtimes/composer/BaseComposerRuntimeCore.tsx +24 -2
  209. package/src/runtimes/local/useLocalRuntime.tsx +5 -0
@@ -23,7 +23,6 @@ var AttachmentContext_exports = {};
23
23
  __export(AttachmentContext_exports, {
24
24
  AttachmentContext: () => AttachmentContext,
25
25
  useAttachment: () => useAttachment,
26
- useAttachmentContext: () => useAttachmentContext,
27
26
  useAttachmentRuntime: () => useAttachmentRuntime,
28
27
  useEditComposerAttachment: () => useEditComposerAttachment,
29
28
  useEditComposerAttachmentRuntime: () => useEditComposerAttachmentRuntime,
@@ -34,80 +33,61 @@ __export(AttachmentContext_exports, {
34
33
  });
35
34
  module.exports = __toCommonJS(AttachmentContext_exports);
36
35
  var import_react = require("react");
37
- var import_createContextStoreHook = require("./utils/createContextStoreHook.js");
36
+ var import_createContextHook = require("./utils/createContextHook.js");
37
+ var import_createStateHookForRuntime = require("./utils/createStateHookForRuntime.js");
38
38
  var AttachmentContext = (0, import_react.createContext)(
39
39
  null
40
40
  );
41
- function useAttachmentContext(options) {
42
- const context = (0, import_react.useContext)(AttachmentContext);
43
- if (!options?.optional && !context)
44
- throw new Error(
45
- "This component must be used within a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component."
46
- );
47
- return context;
48
- }
49
- function useThreadComposerAttachmentContext(options) {
50
- const context = useAttachmentContext(options);
51
- if (!context) return null;
52
- if (context.source !== "thread-composer")
53
- throw new Error(
54
- "This component must be used within a thread's ComposerPrimitive.Attachments component."
55
- );
56
- return context;
57
- }
58
- function useEditComposerAttachmentContext(options) {
59
- const context = useAttachmentContext(options);
60
- if (!context) return null;
61
- if (context.source !== "edit-composer")
62
- throw new Error(
63
- "This component must be used within a messages's ComposerPrimitive.Attachments component."
64
- );
65
- return context;
66
- }
67
- function useMessageAttachmentContext(options) {
68
- const context = useAttachmentContext(options);
69
- if (!context) return null;
70
- if (context.source !== "message")
71
- throw new Error(
72
- "This component must be used within a MessagePrimitive.Attachments component."
73
- );
74
- return context;
75
- }
41
+ var useAttachmentContext = (0, import_createContextHook.createContextHook)(
42
+ AttachmentContext,
43
+ "a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component"
44
+ );
76
45
  function useAttachmentRuntime(options) {
77
46
  const attachmentRuntime = useAttachmentContext(options);
78
47
  if (!attachmentRuntime) return null;
79
48
  return attachmentRuntime.useAttachmentRuntime();
80
49
  }
81
50
  function useThreadComposerAttachmentRuntime(options) {
82
- const attachmentRuntime = useThreadComposerAttachmentContext(options);
51
+ const attachmentRuntime = useAttachmentRuntime(options);
83
52
  if (!attachmentRuntime) return null;
84
- return attachmentRuntime.useAttachmentRuntime();
53
+ if (attachmentRuntime.source !== "thread-composer")
54
+ throw new Error(
55
+ "This component must be used within a thread's ComposerPrimitive.Attachments component."
56
+ );
57
+ return attachmentRuntime;
85
58
  }
86
59
  function useEditComposerAttachmentRuntime(options) {
87
- const attachmentRuntime = useEditComposerAttachmentContext(options);
60
+ const attachmentRuntime = useAttachmentRuntime(options);
88
61
  if (!attachmentRuntime) return null;
89
- return attachmentRuntime.useAttachmentRuntime();
62
+ if (attachmentRuntime.source !== "edit-composer")
63
+ throw new Error(
64
+ "This component must be used within a message's ComposerPrimitive.Attachments component."
65
+ );
66
+ return attachmentRuntime;
90
67
  }
91
68
  function useMessageAttachmentRuntime(options) {
92
- const attachmentRuntime = useMessageAttachmentContext(options);
69
+ const attachmentRuntime = useAttachmentRuntime(options);
93
70
  if (!attachmentRuntime) return null;
94
- return attachmentRuntime.useAttachmentRuntime();
71
+ if (attachmentRuntime.source !== "message")
72
+ throw new Error(
73
+ "This component must be used within a MessagePrimitive.Attachments component."
74
+ );
75
+ return attachmentRuntime;
95
76
  }
96
- var { useAttachment } = (0, import_createContextStoreHook.createContextStoreHook)(
97
- useAttachmentContext,
98
- "useAttachment"
77
+ var useAttachment = (0, import_createStateHookForRuntime.createStateHookForRuntime)(useAttachmentRuntime);
78
+ var useThreadComposerAttachment = (0, import_createStateHookForRuntime.createStateHookForRuntime)(
79
+ useThreadComposerAttachmentRuntime
80
+ );
81
+ var useEditComposerAttachment = (0, import_createStateHookForRuntime.createStateHookForRuntime)(
82
+ useEditComposerAttachmentRuntime
99
83
  );
100
- var { useAttachment: useThreadComposerAttachment } = (0, import_createContextStoreHook.createContextStoreHook)(useThreadComposerAttachmentContext, "useAttachment");
101
- var { useAttachment: useEditComposerAttachment } = (0, import_createContextStoreHook.createContextStoreHook)(useEditComposerAttachmentContext, "useAttachment");
102
- var { useAttachment: useMessageAttachment } = (0, import_createContextStoreHook.createContextStoreHook)(
103
- useMessageAttachmentContext,
104
- "useAttachment"
84
+ var useMessageAttachment = (0, import_createStateHookForRuntime.createStateHookForRuntime)(
85
+ useMessageAttachmentRuntime
105
86
  );
106
87
  // Annotate the CommonJS export names for ESM import in node:
107
88
  0 && (module.exports = {
108
89
  AttachmentContext,
109
90
  useAttachment,
110
- useAttachmentContext,
111
91
  useAttachmentRuntime,
112
92
  useEditComposerAttachment,
113
93
  useEditComposerAttachmentRuntime,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/react/AttachmentContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext, useContext } from \"react\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { createContextStoreHook } from \"./utils/createContextStoreHook\";\nimport {\n AttachmentRuntime,\n AttachmentState,\n} from \"../../api/AttachmentRuntime\";\nimport { UseBoundStore } from \"zustand\";\n\nexport type AttachmentContextValue = {\n source: \"thread-composer\" | \"edit-composer\" | \"message\";\n useAttachment: UseBoundStore<ReadonlyStore<AttachmentState>>;\n useAttachmentRuntime: UseBoundStore<ReadonlyStore<AttachmentRuntime>>;\n};\n\ntype ThreadComposerAttachmentContextValue = {\n source: \"thread-composer\";\n useAttachment: UseBoundStore<\n ReadonlyStore<AttachmentState & { source: \"thread-composer\" }>\n >;\n useAttachmentRuntime: UseBoundStore<\n ReadonlyStore<AttachmentRuntime & { type: \"thread-composer\" }>\n >;\n};\ntype EditComposerAttachmentContextValue = {\n source: \"edit-composer\";\n useAttachment: UseBoundStore<\n ReadonlyStore<AttachmentState & { source: \"edit-composer\" }>\n >;\n useAttachmentRuntime: UseBoundStore<\n ReadonlyStore<AttachmentRuntime & { type: \"edit-composer\" }>\n >;\n};\n\ntype MessageAttachmentContextValue = {\n source: \"message\";\n useAttachment: UseBoundStore<\n ReadonlyStore<AttachmentState & { source: \"message\" }>\n >;\n useAttachmentRuntime: UseBoundStore<\n ReadonlyStore<AttachmentRuntime & { type: \"message\" }>\n >;\n};\n\nexport const AttachmentContext = createContext<AttachmentContextValue | null>(\n null,\n);\n\nexport function useAttachmentContext(options?: {\n optional?: false | undefined;\n}): AttachmentContextValue;\nexport function useAttachmentContext(options?: {\n optional?: boolean | undefined;\n}): AttachmentContextValue | null;\nexport function useAttachmentContext(options?: {\n optional?: boolean | undefined;\n}) {\n const context = useContext(AttachmentContext);\n if (!options?.optional && !context)\n throw new Error(\n \"This component must be used within a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component.\",\n );\n\n return context;\n}\n\nfunction useThreadComposerAttachmentContext(options?: {\n optional?: false | undefined;\n}): ThreadComposerAttachmentContextValue;\nfunction useThreadComposerAttachmentContext(options?: {\n optional?: boolean | undefined;\n}): ThreadComposerAttachmentContextValue | null;\nfunction useThreadComposerAttachmentContext(options?: {\n optional?: boolean | undefined;\n}): ThreadComposerAttachmentContextValue | null {\n const context = useAttachmentContext(options);\n if (!context) return null;\n if (context.source !== \"thread-composer\")\n throw new Error(\n \"This component must be used within a thread's ComposerPrimitive.Attachments component.\",\n );\n return context as ThreadComposerAttachmentContextValue;\n}\n\nfunction useEditComposerAttachmentContext(options?: {\n optional?: false | undefined;\n}): EditComposerAttachmentContextValue;\nfunction useEditComposerAttachmentContext(options?: {\n optional?: boolean | undefined;\n}): EditComposerAttachmentContextValue | null;\nfunction useEditComposerAttachmentContext(options?: {\n optional?: boolean | undefined;\n}): EditComposerAttachmentContextValue | null {\n const context = useAttachmentContext(options);\n if (!context) return null;\n if (context.source !== \"edit-composer\")\n throw new Error(\n \"This component must be used within a messages's ComposerPrimitive.Attachments component.\",\n );\n return context as EditComposerAttachmentContextValue;\n}\n\nfunction useMessageAttachmentContext(options?: {\n optional?: false | undefined;\n}): MessageAttachmentContextValue;\nfunction useMessageAttachmentContext(options?: {\n optional?: boolean | undefined;\n}): MessageAttachmentContextValue | null;\nfunction useMessageAttachmentContext(options?: {\n optional?: boolean | undefined;\n}): MessageAttachmentContextValue | null {\n const context = useAttachmentContext(options);\n if (!context) return null;\n if (context.source !== \"message\")\n throw new Error(\n \"This component must be used within a MessagePrimitive.Attachments component.\",\n );\n return context as MessageAttachmentContextValue;\n}\n\nexport function useAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime;\nexport function useAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null;\nexport function useAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null {\n const attachmentRuntime = useAttachmentContext(options);\n if (!attachmentRuntime) return null;\n return attachmentRuntime.useAttachmentRuntime();\n}\n\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime;\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null;\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null {\n const attachmentRuntime = useThreadComposerAttachmentContext(options);\n if (!attachmentRuntime) return null;\n return attachmentRuntime.useAttachmentRuntime();\n}\n\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime;\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null;\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null {\n const attachmentRuntime = useEditComposerAttachmentContext(options);\n if (!attachmentRuntime) return null;\n return attachmentRuntime.useAttachmentRuntime();\n}\n\nexport function useMessageAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime;\nexport function useMessageAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null;\nexport function useMessageAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null {\n const attachmentRuntime = useMessageAttachmentContext(options);\n if (!attachmentRuntime) return null;\n return attachmentRuntime.useAttachmentRuntime();\n}\n\nexport const { useAttachment } = createContextStoreHook(\n useAttachmentContext,\n \"useAttachment\",\n);\n\nexport const { useAttachment: useThreadComposerAttachment } =\n createContextStoreHook(useThreadComposerAttachmentContext, \"useAttachment\");\n\nexport const { useAttachment: useEditComposerAttachment } =\n createContextStoreHook(useEditComposerAttachmentContext, \"useAttachment\");\n\nexport const { useAttachment: useMessageAttachment } = createContextStoreHook(\n useMessageAttachmentContext,\n \"useAttachment\",\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0C;AAE1C,oCAAuC;AA0ChC,IAAM,wBAAoB;AAAA,EAC/B;AACF;AAQO,SAAS,qBAAqB,SAElC;AACD,QAAM,cAAU,yBAAW,iBAAiB;AAC5C,MAAI,CAAC,SAAS,YAAY,CAAC;AACzB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEF,SAAO;AACT;AAQA,SAAS,mCAAmC,SAEI;AAC9C,QAAM,UAAU,qBAAqB,OAAO;AAC5C,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI,QAAQ,WAAW;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;AAQA,SAAS,iCAAiC,SAEI;AAC5C,QAAM,UAAU,qBAAqB,OAAO;AAC5C,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI,QAAQ,WAAW;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;AAQA,SAAS,4BAA4B,SAEI;AACvC,QAAM,UAAU,qBAAqB,OAAO;AAC5C,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI,QAAQ,WAAW;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;AAQO,SAAS,qBAAqB,SAER;AAC3B,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,SAAO,kBAAkB,qBAAqB;AAChD;AAQO,SAAS,mCAAmC,SAEtB;AAC3B,QAAM,oBAAoB,mCAAmC,OAAO;AACpE,MAAI,CAAC,kBAAmB,QAAO;AAC/B,SAAO,kBAAkB,qBAAqB;AAChD;AAQO,SAAS,iCAAiC,SAEpB;AAC3B,QAAM,oBAAoB,iCAAiC,OAAO;AAClE,MAAI,CAAC,kBAAmB,QAAO;AAC/B,SAAO,kBAAkB,qBAAqB;AAChD;AAQO,SAAS,4BAA4B,SAEf;AAC3B,QAAM,oBAAoB,4BAA4B,OAAO;AAC7D,MAAI,CAAC,kBAAmB,QAAO;AAC/B,SAAO,kBAAkB,qBAAqB;AAChD;AAEO,IAAM,EAAE,cAAc,QAAI;AAAA,EAC/B;AAAA,EACA;AACF;AAEO,IAAM,EAAE,eAAe,4BAA4B,QACxD,sDAAuB,oCAAoC,eAAe;AAErE,IAAM,EAAE,eAAe,0BAA0B,QACtD,sDAAuB,kCAAkC,eAAe;AAEnE,IAAM,EAAE,eAAe,qBAAqB,QAAI;AAAA,EACrD;AAAA,EACA;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/react/AttachmentContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { AttachmentRuntime } from \"../../api/AttachmentRuntime\";\nimport { UseBoundStore } from \"zustand\";\nimport { createContextHook } from \"./utils/createContextHook\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\n\nexport type AttachmentContextValue = {\n useAttachmentRuntime: UseBoundStore<ReadonlyStore<AttachmentRuntime>>;\n};\n\nexport const AttachmentContext = createContext<AttachmentContextValue | null>(\n null,\n);\n\nconst useAttachmentContext = createContextHook(\n AttachmentContext,\n \"a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component\",\n);\n\nexport function useAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime;\nexport function useAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null;\nexport function useAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null {\n const attachmentRuntime = useAttachmentContext(options);\n if (!attachmentRuntime) return null;\n return attachmentRuntime.useAttachmentRuntime();\n}\n\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime<\"thread-composer\">;\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"thread-composer\"> | null;\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"thread-composer\"> | null {\n const attachmentRuntime = useAttachmentRuntime(options);\n if (!attachmentRuntime) return null;\n if (attachmentRuntime.source !== \"thread-composer\")\n throw new Error(\n \"This component must be used within a thread's ComposerPrimitive.Attachments component.\",\n );\n return attachmentRuntime as AttachmentRuntime<\"thread-composer\">;\n}\n\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime<\"edit-composer\">;\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"edit-composer\"> | null;\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"edit-composer\"> | null {\n const attachmentRuntime = useAttachmentRuntime(options);\n if (!attachmentRuntime) return null;\n if (attachmentRuntime.source !== \"edit-composer\")\n throw new Error(\n \"This component must be used within a message's ComposerPrimitive.Attachments component.\",\n );\n\n return attachmentRuntime as AttachmentRuntime<\"edit-composer\">;\n}\n\nexport function useMessageAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime<\"message\">;\nexport function useMessageAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"message\"> | null;\nexport function useMessageAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"message\"> | null {\n const attachmentRuntime = useAttachmentRuntime(options);\n if (!attachmentRuntime) return null;\n if (attachmentRuntime.source !== \"message\")\n throw new Error(\n \"This component must be used within a MessagePrimitive.Attachments component.\",\n );\n return attachmentRuntime as AttachmentRuntime<\"message\">;\n}\n\nexport const useAttachment = createStateHookForRuntime(useAttachmentRuntime);\n\nexport const useThreadComposerAttachment = createStateHookForRuntime(\n useThreadComposerAttachmentRuntime,\n);\nexport const useEditComposerAttachment = createStateHookForRuntime(\n useEditComposerAttachmentRuntime,\n);\nexport const useMessageAttachment = createStateHookForRuntime(\n useMessageAttachmentRuntime,\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA8B;AAI9B,+BAAkC;AAClC,uCAA0C;AAMnC,IAAM,wBAAoB;AAAA,EAC/B;AACF;AAEA,IAAM,2BAAuB;AAAA,EAC3B;AAAA,EACA;AACF;AAQO,SAAS,qBAAqB,SAER;AAC3B,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,SAAO,kBAAkB,qBAAqB;AAChD;AAQO,SAAS,mCAAmC,SAEH;AAC9C,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,MAAI,kBAAkB,WAAW;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;AAQO,SAAS,iCAAiC,SAEH;AAC5C,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,MAAI,kBAAkB,WAAW;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEF,SAAO;AACT;AAQO,SAAS,4BAA4B,SAEJ;AACtC,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,MAAI,kBAAkB,WAAW;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;AAEO,IAAM,oBAAgB,4DAA0B,oBAAoB;AAEpE,IAAM,kCAA8B;AAAA,EACzC;AACF;AACO,IAAM,gCAA4B;AAAA,EACvC;AACF;AACO,IAAM,2BAAuB;AAAA,EAClC;AACF;","names":[]}
@@ -1,80 +1,61 @@
1
1
  "use client";
2
2
 
3
3
  // src/context/react/AttachmentContext.ts
4
- import { createContext, useContext } from "react";
5
- import { createContextStoreHook } from "./utils/createContextStoreHook.mjs";
4
+ import { createContext } from "react";
5
+ import { createContextHook } from "./utils/createContextHook.mjs";
6
+ import { createStateHookForRuntime } from "./utils/createStateHookForRuntime.mjs";
6
7
  var AttachmentContext = createContext(
7
8
  null
8
9
  );
9
- function useAttachmentContext(options) {
10
- const context = useContext(AttachmentContext);
11
- if (!options?.optional && !context)
12
- throw new Error(
13
- "This component must be used within a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component."
14
- );
15
- return context;
16
- }
17
- function useThreadComposerAttachmentContext(options) {
18
- const context = useAttachmentContext(options);
19
- if (!context) return null;
20
- if (context.source !== "thread-composer")
21
- throw new Error(
22
- "This component must be used within a thread's ComposerPrimitive.Attachments component."
23
- );
24
- return context;
25
- }
26
- function useEditComposerAttachmentContext(options) {
27
- const context = useAttachmentContext(options);
28
- if (!context) return null;
29
- if (context.source !== "edit-composer")
30
- throw new Error(
31
- "This component must be used within a messages's ComposerPrimitive.Attachments component."
32
- );
33
- return context;
34
- }
35
- function useMessageAttachmentContext(options) {
36
- const context = useAttachmentContext(options);
37
- if (!context) return null;
38
- if (context.source !== "message")
39
- throw new Error(
40
- "This component must be used within a MessagePrimitive.Attachments component."
41
- );
42
- return context;
43
- }
10
+ var useAttachmentContext = createContextHook(
11
+ AttachmentContext,
12
+ "a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component"
13
+ );
44
14
  function useAttachmentRuntime(options) {
45
15
  const attachmentRuntime = useAttachmentContext(options);
46
16
  if (!attachmentRuntime) return null;
47
17
  return attachmentRuntime.useAttachmentRuntime();
48
18
  }
49
19
  function useThreadComposerAttachmentRuntime(options) {
50
- const attachmentRuntime = useThreadComposerAttachmentContext(options);
20
+ const attachmentRuntime = useAttachmentRuntime(options);
51
21
  if (!attachmentRuntime) return null;
52
- return attachmentRuntime.useAttachmentRuntime();
22
+ if (attachmentRuntime.source !== "thread-composer")
23
+ throw new Error(
24
+ "This component must be used within a thread's ComposerPrimitive.Attachments component."
25
+ );
26
+ return attachmentRuntime;
53
27
  }
54
28
  function useEditComposerAttachmentRuntime(options) {
55
- const attachmentRuntime = useEditComposerAttachmentContext(options);
29
+ const attachmentRuntime = useAttachmentRuntime(options);
56
30
  if (!attachmentRuntime) return null;
57
- return attachmentRuntime.useAttachmentRuntime();
31
+ if (attachmentRuntime.source !== "edit-composer")
32
+ throw new Error(
33
+ "This component must be used within a message's ComposerPrimitive.Attachments component."
34
+ );
35
+ return attachmentRuntime;
58
36
  }
59
37
  function useMessageAttachmentRuntime(options) {
60
- const attachmentRuntime = useMessageAttachmentContext(options);
38
+ const attachmentRuntime = useAttachmentRuntime(options);
61
39
  if (!attachmentRuntime) return null;
62
- return attachmentRuntime.useAttachmentRuntime();
40
+ if (attachmentRuntime.source !== "message")
41
+ throw new Error(
42
+ "This component must be used within a MessagePrimitive.Attachments component."
43
+ );
44
+ return attachmentRuntime;
63
45
  }
64
- var { useAttachment } = createContextStoreHook(
65
- useAttachmentContext,
66
- "useAttachment"
46
+ var useAttachment = createStateHookForRuntime(useAttachmentRuntime);
47
+ var useThreadComposerAttachment = createStateHookForRuntime(
48
+ useThreadComposerAttachmentRuntime
49
+ );
50
+ var useEditComposerAttachment = createStateHookForRuntime(
51
+ useEditComposerAttachmentRuntime
67
52
  );
68
- var { useAttachment: useThreadComposerAttachment } = createContextStoreHook(useThreadComposerAttachmentContext, "useAttachment");
69
- var { useAttachment: useEditComposerAttachment } = createContextStoreHook(useEditComposerAttachmentContext, "useAttachment");
70
- var { useAttachment: useMessageAttachment } = createContextStoreHook(
71
- useMessageAttachmentContext,
72
- "useAttachment"
53
+ var useMessageAttachment = createStateHookForRuntime(
54
+ useMessageAttachmentRuntime
73
55
  );
74
56
  export {
75
57
  AttachmentContext,
76
58
  useAttachment,
77
- useAttachmentContext,
78
59
  useAttachmentRuntime,
79
60
  useEditComposerAttachment,
80
61
  useEditComposerAttachmentRuntime,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/react/AttachmentContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext, useContext } from \"react\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { createContextStoreHook } from \"./utils/createContextStoreHook\";\nimport {\n AttachmentRuntime,\n AttachmentState,\n} from \"../../api/AttachmentRuntime\";\nimport { UseBoundStore } from \"zustand\";\n\nexport type AttachmentContextValue = {\n source: \"thread-composer\" | \"edit-composer\" | \"message\";\n useAttachment: UseBoundStore<ReadonlyStore<AttachmentState>>;\n useAttachmentRuntime: UseBoundStore<ReadonlyStore<AttachmentRuntime>>;\n};\n\ntype ThreadComposerAttachmentContextValue = {\n source: \"thread-composer\";\n useAttachment: UseBoundStore<\n ReadonlyStore<AttachmentState & { source: \"thread-composer\" }>\n >;\n useAttachmentRuntime: UseBoundStore<\n ReadonlyStore<AttachmentRuntime & { type: \"thread-composer\" }>\n >;\n};\ntype EditComposerAttachmentContextValue = {\n source: \"edit-composer\";\n useAttachment: UseBoundStore<\n ReadonlyStore<AttachmentState & { source: \"edit-composer\" }>\n >;\n useAttachmentRuntime: UseBoundStore<\n ReadonlyStore<AttachmentRuntime & { type: \"edit-composer\" }>\n >;\n};\n\ntype MessageAttachmentContextValue = {\n source: \"message\";\n useAttachment: UseBoundStore<\n ReadonlyStore<AttachmentState & { source: \"message\" }>\n >;\n useAttachmentRuntime: UseBoundStore<\n ReadonlyStore<AttachmentRuntime & { type: \"message\" }>\n >;\n};\n\nexport const AttachmentContext = createContext<AttachmentContextValue | null>(\n null,\n);\n\nexport function useAttachmentContext(options?: {\n optional?: false | undefined;\n}): AttachmentContextValue;\nexport function useAttachmentContext(options?: {\n optional?: boolean | undefined;\n}): AttachmentContextValue | null;\nexport function useAttachmentContext(options?: {\n optional?: boolean | undefined;\n}) {\n const context = useContext(AttachmentContext);\n if (!options?.optional && !context)\n throw new Error(\n \"This component must be used within a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component.\",\n );\n\n return context;\n}\n\nfunction useThreadComposerAttachmentContext(options?: {\n optional?: false | undefined;\n}): ThreadComposerAttachmentContextValue;\nfunction useThreadComposerAttachmentContext(options?: {\n optional?: boolean | undefined;\n}): ThreadComposerAttachmentContextValue | null;\nfunction useThreadComposerAttachmentContext(options?: {\n optional?: boolean | undefined;\n}): ThreadComposerAttachmentContextValue | null {\n const context = useAttachmentContext(options);\n if (!context) return null;\n if (context.source !== \"thread-composer\")\n throw new Error(\n \"This component must be used within a thread's ComposerPrimitive.Attachments component.\",\n );\n return context as ThreadComposerAttachmentContextValue;\n}\n\nfunction useEditComposerAttachmentContext(options?: {\n optional?: false | undefined;\n}): EditComposerAttachmentContextValue;\nfunction useEditComposerAttachmentContext(options?: {\n optional?: boolean | undefined;\n}): EditComposerAttachmentContextValue | null;\nfunction useEditComposerAttachmentContext(options?: {\n optional?: boolean | undefined;\n}): EditComposerAttachmentContextValue | null {\n const context = useAttachmentContext(options);\n if (!context) return null;\n if (context.source !== \"edit-composer\")\n throw new Error(\n \"This component must be used within a messages's ComposerPrimitive.Attachments component.\",\n );\n return context as EditComposerAttachmentContextValue;\n}\n\nfunction useMessageAttachmentContext(options?: {\n optional?: false | undefined;\n}): MessageAttachmentContextValue;\nfunction useMessageAttachmentContext(options?: {\n optional?: boolean | undefined;\n}): MessageAttachmentContextValue | null;\nfunction useMessageAttachmentContext(options?: {\n optional?: boolean | undefined;\n}): MessageAttachmentContextValue | null {\n const context = useAttachmentContext(options);\n if (!context) return null;\n if (context.source !== \"message\")\n throw new Error(\n \"This component must be used within a MessagePrimitive.Attachments component.\",\n );\n return context as MessageAttachmentContextValue;\n}\n\nexport function useAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime;\nexport function useAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null;\nexport function useAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null {\n const attachmentRuntime = useAttachmentContext(options);\n if (!attachmentRuntime) return null;\n return attachmentRuntime.useAttachmentRuntime();\n}\n\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime;\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null;\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null {\n const attachmentRuntime = useThreadComposerAttachmentContext(options);\n if (!attachmentRuntime) return null;\n return attachmentRuntime.useAttachmentRuntime();\n}\n\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime;\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null;\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null {\n const attachmentRuntime = useEditComposerAttachmentContext(options);\n if (!attachmentRuntime) return null;\n return attachmentRuntime.useAttachmentRuntime();\n}\n\nexport function useMessageAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime;\nexport function useMessageAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null;\nexport function useMessageAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null {\n const attachmentRuntime = useMessageAttachmentContext(options);\n if (!attachmentRuntime) return null;\n return attachmentRuntime.useAttachmentRuntime();\n}\n\nexport const { useAttachment } = createContextStoreHook(\n useAttachmentContext,\n \"useAttachment\",\n);\n\nexport const { useAttachment: useThreadComposerAttachment } =\n createContextStoreHook(useThreadComposerAttachmentContext, \"useAttachment\");\n\nexport const { useAttachment: useEditComposerAttachment } =\n createContextStoreHook(useEditComposerAttachmentContext, \"useAttachment\");\n\nexport const { useAttachment: useMessageAttachment } = createContextStoreHook(\n useMessageAttachmentContext,\n \"useAttachment\",\n);\n"],"mappings":";;;AAEA,SAAS,eAAe,kBAAkB;AAE1C,SAAS,8BAA8B;AA0ChC,IAAM,oBAAoB;AAAA,EAC/B;AACF;AAQO,SAAS,qBAAqB,SAElC;AACD,QAAM,UAAU,WAAW,iBAAiB;AAC5C,MAAI,CAAC,SAAS,YAAY,CAAC;AACzB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEF,SAAO;AACT;AAQA,SAAS,mCAAmC,SAEI;AAC9C,QAAM,UAAU,qBAAqB,OAAO;AAC5C,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI,QAAQ,WAAW;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;AAQA,SAAS,iCAAiC,SAEI;AAC5C,QAAM,UAAU,qBAAqB,OAAO;AAC5C,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI,QAAQ,WAAW;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;AAQA,SAAS,4BAA4B,SAEI;AACvC,QAAM,UAAU,qBAAqB,OAAO;AAC5C,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI,QAAQ,WAAW;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;AAQO,SAAS,qBAAqB,SAER;AAC3B,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,SAAO,kBAAkB,qBAAqB;AAChD;AAQO,SAAS,mCAAmC,SAEtB;AAC3B,QAAM,oBAAoB,mCAAmC,OAAO;AACpE,MAAI,CAAC,kBAAmB,QAAO;AAC/B,SAAO,kBAAkB,qBAAqB;AAChD;AAQO,SAAS,iCAAiC,SAEpB;AAC3B,QAAM,oBAAoB,iCAAiC,OAAO;AAClE,MAAI,CAAC,kBAAmB,QAAO;AAC/B,SAAO,kBAAkB,qBAAqB;AAChD;AAQO,SAAS,4BAA4B,SAEf;AAC3B,QAAM,oBAAoB,4BAA4B,OAAO;AAC7D,MAAI,CAAC,kBAAmB,QAAO;AAC/B,SAAO,kBAAkB,qBAAqB;AAChD;AAEO,IAAM,EAAE,cAAc,IAAI;AAAA,EAC/B;AAAA,EACA;AACF;AAEO,IAAM,EAAE,eAAe,4BAA4B,IACxD,uBAAuB,oCAAoC,eAAe;AAErE,IAAM,EAAE,eAAe,0BAA0B,IACtD,uBAAuB,kCAAkC,eAAe;AAEnE,IAAM,EAAE,eAAe,qBAAqB,IAAI;AAAA,EACrD;AAAA,EACA;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/react/AttachmentContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { AttachmentRuntime } from \"../../api/AttachmentRuntime\";\nimport { UseBoundStore } from \"zustand\";\nimport { createContextHook } from \"./utils/createContextHook\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\n\nexport type AttachmentContextValue = {\n useAttachmentRuntime: UseBoundStore<ReadonlyStore<AttachmentRuntime>>;\n};\n\nexport const AttachmentContext = createContext<AttachmentContextValue | null>(\n null,\n);\n\nconst useAttachmentContext = createContextHook(\n AttachmentContext,\n \"a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component\",\n);\n\nexport function useAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime;\nexport function useAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null;\nexport function useAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime | null {\n const attachmentRuntime = useAttachmentContext(options);\n if (!attachmentRuntime) return null;\n return attachmentRuntime.useAttachmentRuntime();\n}\n\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime<\"thread-composer\">;\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"thread-composer\"> | null;\nexport function useThreadComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"thread-composer\"> | null {\n const attachmentRuntime = useAttachmentRuntime(options);\n if (!attachmentRuntime) return null;\n if (attachmentRuntime.source !== \"thread-composer\")\n throw new Error(\n \"This component must be used within a thread's ComposerPrimitive.Attachments component.\",\n );\n return attachmentRuntime as AttachmentRuntime<\"thread-composer\">;\n}\n\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime<\"edit-composer\">;\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"edit-composer\"> | null;\nexport function useEditComposerAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"edit-composer\"> | null {\n const attachmentRuntime = useAttachmentRuntime(options);\n if (!attachmentRuntime) return null;\n if (attachmentRuntime.source !== \"edit-composer\")\n throw new Error(\n \"This component must be used within a message's ComposerPrimitive.Attachments component.\",\n );\n\n return attachmentRuntime as AttachmentRuntime<\"edit-composer\">;\n}\n\nexport function useMessageAttachmentRuntime(options?: {\n optional?: false | undefined;\n}): AttachmentRuntime<\"message\">;\nexport function useMessageAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"message\"> | null;\nexport function useMessageAttachmentRuntime(options?: {\n optional?: boolean | undefined;\n}): AttachmentRuntime<\"message\"> | null {\n const attachmentRuntime = useAttachmentRuntime(options);\n if (!attachmentRuntime) return null;\n if (attachmentRuntime.source !== \"message\")\n throw new Error(\n \"This component must be used within a MessagePrimitive.Attachments component.\",\n );\n return attachmentRuntime as AttachmentRuntime<\"message\">;\n}\n\nexport const useAttachment = createStateHookForRuntime(useAttachmentRuntime);\n\nexport const useThreadComposerAttachment = createStateHookForRuntime(\n useThreadComposerAttachmentRuntime,\n);\nexport const useEditComposerAttachment = createStateHookForRuntime(\n useEditComposerAttachmentRuntime,\n);\nexport const useMessageAttachment = createStateHookForRuntime(\n useMessageAttachmentRuntime,\n);\n"],"mappings":";;;AAEA,SAAS,qBAAqB;AAI9B,SAAS,yBAAyB;AAClC,SAAS,iCAAiC;AAMnC,IAAM,oBAAoB;AAAA,EAC/B;AACF;AAEA,IAAM,uBAAuB;AAAA,EAC3B;AAAA,EACA;AACF;AAQO,SAAS,qBAAqB,SAER;AAC3B,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,SAAO,kBAAkB,qBAAqB;AAChD;AAQO,SAAS,mCAAmC,SAEH;AAC9C,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,MAAI,kBAAkB,WAAW;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;AAQO,SAAS,iCAAiC,SAEH;AAC5C,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,MAAI,kBAAkB,WAAW;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAEF,SAAO;AACT;AAQO,SAAS,4BAA4B,SAEJ;AACtC,QAAM,oBAAoB,qBAAqB,OAAO;AACtD,MAAI,CAAC,kBAAmB,QAAO;AAC/B,MAAI,kBAAkB,WAAW;AAC/B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AACF,SAAO;AACT;AAEO,IAAM,gBAAgB,0BAA0B,oBAAoB;AAEpE,IAAM,8BAA8B;AAAA,EACzC;AACF;AACO,IAAM,4BAA4B;AAAA,EACvC;AACF;AACO,IAAM,uBAAuB;AAAA,EAClC;AACF;","names":[]}
@@ -1,26 +1,35 @@
1
- import { ReadonlyStore } from "../ReadonlyStore";
2
- import { ComposerRuntime, ComposerState } from "../../api/ComposerRuntime";
3
- import { UseBoundStore } from "zustand";
4
- export type ComposerContextValue = {
5
- useComposer: UseBoundStore<ReadonlyStore<ComposerState>>;
6
- type: "edit" | "new";
7
- };
8
- export declare const useComposerContext: () => ComposerContextValue;
9
- export declare const useComposer: {
10
- (): ComposerState;
11
- <TSelected>(selector: (state: ComposerState) => TSelected): TSelected;
12
- (options: {
13
- optional: true;
14
- }): ComposerState | null;
15
- <TSelected>(options: {
16
- optional: true;
17
- selector?: (state: ComposerState) => TSelected;
18
- }): TSelected | null;
19
- };
1
+ import { ComposerRuntime } from "../../api/ComposerRuntime";
20
2
  export declare function useComposerRuntime(options?: {
21
3
  optional?: false | undefined;
22
4
  }): ComposerRuntime;
23
5
  export declare function useComposerRuntime(options?: {
24
6
  optional?: boolean | undefined;
25
7
  }): ComposerRuntime | null;
8
+ export declare const useComposer: {
9
+ (): import("../..").ComposerState;
10
+ <TSelected>(selector: (state: import("../..").ComposerState) => TSelected): TSelected;
11
+ <TSelected>(selector: ((state: import("../..").ComposerState) => TSelected) | undefined): import("../..").ComposerState | TSelected;
12
+ (options: {
13
+ optional?: false | undefined;
14
+ }): import("../..").ComposerState;
15
+ (options: {
16
+ optional?: boolean | undefined;
17
+ }): import("../..").ComposerState | null;
18
+ <TSelected>(options: {
19
+ optional?: false | undefined;
20
+ selector: (state: import("../..").ComposerState) => TSelected;
21
+ }): TSelected;
22
+ <TSelected>(options: {
23
+ optional?: false | undefined;
24
+ selector: ((state: import("../..").ComposerState) => TSelected) | undefined;
25
+ }): import("../..").ComposerState | TSelected;
26
+ <TSelected>(options: {
27
+ optional?: boolean | undefined;
28
+ selector: (state: import("../..").ComposerState) => TSelected;
29
+ }): TSelected | null;
30
+ <TSelected>(options: {
31
+ optional?: boolean | undefined;
32
+ selector: ((state: import("../..").ComposerState) => TSelected) | undefined;
33
+ }): import("../..").ComposerState | TSelected | null;
34
+ };
26
35
  //# sourceMappingURL=ComposerContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ComposerContext.d.ts","sourceRoot":"","sources":["../../../src/context/react/ComposerContext.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,MAAM,oBAAoB,GAAG;IACjC,WAAW,EAAE,aAAa,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC;IACzD,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,kBAAkB,QAAO,oBAUrC,CAAC;AAEF,eAAO,MAAQ,WAAW;;;;;;;;;;CAGzB,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE;IAC3C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,eAAe,CAAC;AACpB,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE;IAC3C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,eAAe,GAAG,IAAI,CAAC"}
1
+ {"version":3,"file":"ComposerContext.d.ts","sourceRoot":"","sources":["../../../src/context/react/ComposerContext.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAG5D,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE;IAC3C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,eAAe,CAAC;AACpB,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE;IAC3C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,eAAe,GAAG,IAAI,CAAC;AAW3B,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;CAAgD,CAAC"}
@@ -22,38 +22,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  var ComposerContext_exports = {};
23
23
  __export(ComposerContext_exports, {
24
24
  useComposer: () => useComposer,
25
- useComposerContext: () => useComposerContext,
26
25
  useComposerRuntime: () => useComposerRuntime
27
26
  });
28
27
  module.exports = __toCommonJS(ComposerContext_exports);
29
- var import_react = require("react");
30
28
  var import_MessageContext = require("./MessageContext.js");
31
29
  var import_ThreadContext = require("./ThreadContext.js");
32
- var import_createContextStoreHook = require("./utils/createContextStoreHook.js");
33
- var useComposerContext = () => {
34
- const { useComposer: useThreadComposer } = (0, import_ThreadContext.useThreadContext)();
35
- const { useEditComposer } = (0, import_MessageContext.useMessageContext)({ optional: true }) ?? {};
36
- return (0, import_react.useMemo)(
37
- () => ({
38
- useComposer: useEditComposer ?? useThreadComposer,
39
- type: useEditComposer ? "edit" : "new"
40
- }),
41
- [useEditComposer, useThreadComposer]
42
- );
43
- };
44
- var { useComposer } = (0, import_createContextStoreHook.createContextStoreHook)(
45
- useComposerContext,
46
- "useComposer"
47
- );
30
+ var import_createStateHookForRuntime = require("./utils/createStateHookForRuntime.js");
48
31
  function useComposerRuntime(options) {
49
32
  const messageRuntime = (0, import_MessageContext.useMessageRuntime)({ optional: true });
50
33
  const threadRuntime = (0, import_ThreadContext.useThreadRuntime)(options);
51
34
  return messageRuntime ? messageRuntime.composer : threadRuntime?.composer ?? null;
52
35
  }
36
+ var useComposer = (0, import_createStateHookForRuntime.createStateHookForRuntime)(useComposerRuntime);
53
37
  // Annotate the CommonJS export names for ESM import in node:
54
38
  0 && (module.exports = {
55
39
  useComposer,
56
- useComposerContext,
57
40
  useComposerRuntime
58
41
  });
59
42
  //# sourceMappingURL=ComposerContext.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/react/ComposerContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useMemo } from \"react\";\nimport { useMessageContext, useMessageRuntime } from \"./MessageContext\";\nimport { useThreadContext, useThreadRuntime } from \"./ThreadContext\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { createContextStoreHook } from \"./utils/createContextStoreHook\";\nimport { ComposerRuntime, ComposerState } from \"../../api/ComposerRuntime\";\nimport { UseBoundStore } from \"zustand\";\n\nexport type ComposerContextValue = {\n useComposer: UseBoundStore<ReadonlyStore<ComposerState>>;\n type: \"edit\" | \"new\";\n};\n\nexport const useComposerContext = (): ComposerContextValue => {\n const { useComposer: useThreadComposer } = useThreadContext();\n const { useEditComposer } = useMessageContext({ optional: true }) ?? {};\n return useMemo(\n () => ({\n useComposer: useEditComposer ?? useThreadComposer,\n type: useEditComposer ? (\"edit\" as const) : (\"new\" as const),\n }),\n [useEditComposer, useThreadComposer],\n );\n};\n\nexport const { useComposer } = createContextStoreHook(\n useComposerContext,\n \"useComposer\",\n);\n\nexport function useComposerRuntime(options?: {\n optional?: false | undefined;\n}): ComposerRuntime;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null {\n const messageRuntime = useMessageRuntime({ optional: true });\n const threadRuntime = useThreadRuntime(options);\n return messageRuntime\n ? messageRuntime.composer\n : (threadRuntime?.composer ?? null);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAwB;AACxB,4BAAqD;AACrD,2BAAmD;AAEnD,oCAAuC;AAShC,IAAM,qBAAqB,MAA4B;AAC5D,QAAM,EAAE,aAAa,kBAAkB,QAAI,uCAAiB;AAC5D,QAAM,EAAE,gBAAgB,QAAI,yCAAkB,EAAE,UAAU,KAAK,CAAC,KAAK,CAAC;AACtE,aAAO;AAAA,IACL,OAAO;AAAA,MACL,aAAa,mBAAmB;AAAA,MAChC,MAAM,kBAAmB,SAAoB;AAAA,IAC/C;AAAA,IACA,CAAC,iBAAiB,iBAAiB;AAAA,EACrC;AACF;AAEO,IAAM,EAAE,YAAY,QAAI;AAAA,EAC7B;AAAA,EACA;AACF;AAQO,SAAS,mBAAmB,SAER;AACzB,QAAM,qBAAiB,yCAAkB,EAAE,UAAU,KAAK,CAAC;AAC3D,QAAM,oBAAgB,uCAAiB,OAAO;AAC9C,SAAO,iBACH,eAAe,WACd,eAAe,YAAY;AAClC;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/react/ComposerContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useMessageRuntime } from \"./MessageContext\";\nimport { useThreadRuntime } from \"./ThreadContext\";\nimport { ComposerRuntime } from \"../../api/ComposerRuntime\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\n\nexport function useComposerRuntime(options?: {\n optional?: false | undefined;\n}): ComposerRuntime;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null {\n const messageRuntime = useMessageRuntime({ optional: true });\n const threadRuntime = useThreadRuntime(options);\n return messageRuntime\n ? messageRuntime.composer\n : (threadRuntime?.composer ?? null);\n}\n\nexport const useComposer = createStateHookForRuntime(useComposerRuntime);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,4BAAkC;AAClC,2BAAiC;AAEjC,uCAA0C;AAQnC,SAAS,mBAAmB,SAER;AACzB,QAAM,qBAAiB,yCAAkB,EAAE,UAAU,KAAK,CAAC;AAC3D,QAAM,oBAAgB,uCAAiB,OAAO;AAC9C,SAAO,iBACH,eAAe,WACd,eAAe,YAAY;AAClC;AAEO,IAAM,kBAAc,4DAA0B,kBAAkB;","names":[]}
@@ -1,33 +1,17 @@
1
1
  "use client";
2
2
 
3
3
  // src/context/react/ComposerContext.ts
4
- import { useMemo } from "react";
5
- import { useMessageContext, useMessageRuntime } from "./MessageContext.mjs";
6
- import { useThreadContext, useThreadRuntime } from "./ThreadContext.mjs";
7
- import { createContextStoreHook } from "./utils/createContextStoreHook.mjs";
8
- var useComposerContext = () => {
9
- const { useComposer: useThreadComposer } = useThreadContext();
10
- const { useEditComposer } = useMessageContext({ optional: true }) ?? {};
11
- return useMemo(
12
- () => ({
13
- useComposer: useEditComposer ?? useThreadComposer,
14
- type: useEditComposer ? "edit" : "new"
15
- }),
16
- [useEditComposer, useThreadComposer]
17
- );
18
- };
19
- var { useComposer } = createContextStoreHook(
20
- useComposerContext,
21
- "useComposer"
22
- );
4
+ import { useMessageRuntime } from "./MessageContext.mjs";
5
+ import { useThreadRuntime } from "./ThreadContext.mjs";
6
+ import { createStateHookForRuntime } from "./utils/createStateHookForRuntime.mjs";
23
7
  function useComposerRuntime(options) {
24
8
  const messageRuntime = useMessageRuntime({ optional: true });
25
9
  const threadRuntime = useThreadRuntime(options);
26
10
  return messageRuntime ? messageRuntime.composer : threadRuntime?.composer ?? null;
27
11
  }
12
+ var useComposer = createStateHookForRuntime(useComposerRuntime);
28
13
  export {
29
14
  useComposer,
30
- useComposerContext,
31
15
  useComposerRuntime
32
16
  };
33
17
  //# sourceMappingURL=ComposerContext.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/react/ComposerContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useMemo } from \"react\";\nimport { useMessageContext, useMessageRuntime } from \"./MessageContext\";\nimport { useThreadContext, useThreadRuntime } from \"./ThreadContext\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { createContextStoreHook } from \"./utils/createContextStoreHook\";\nimport { ComposerRuntime, ComposerState } from \"../../api/ComposerRuntime\";\nimport { UseBoundStore } from \"zustand\";\n\nexport type ComposerContextValue = {\n useComposer: UseBoundStore<ReadonlyStore<ComposerState>>;\n type: \"edit\" | \"new\";\n};\n\nexport const useComposerContext = (): ComposerContextValue => {\n const { useComposer: useThreadComposer } = useThreadContext();\n const { useEditComposer } = useMessageContext({ optional: true }) ?? {};\n return useMemo(\n () => ({\n useComposer: useEditComposer ?? useThreadComposer,\n type: useEditComposer ? (\"edit\" as const) : (\"new\" as const),\n }),\n [useEditComposer, useThreadComposer],\n );\n};\n\nexport const { useComposer } = createContextStoreHook(\n useComposerContext,\n \"useComposer\",\n);\n\nexport function useComposerRuntime(options?: {\n optional?: false | undefined;\n}): ComposerRuntime;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null {\n const messageRuntime = useMessageRuntime({ optional: true });\n const threadRuntime = useThreadRuntime(options);\n return messageRuntime\n ? messageRuntime.composer\n : (threadRuntime?.composer ?? null);\n}\n"],"mappings":";;;AAEA,SAAS,eAAe;AACxB,SAAS,mBAAmB,yBAAyB;AACrD,SAAS,kBAAkB,wBAAwB;AAEnD,SAAS,8BAA8B;AAShC,IAAM,qBAAqB,MAA4B;AAC5D,QAAM,EAAE,aAAa,kBAAkB,IAAI,iBAAiB;AAC5D,QAAM,EAAE,gBAAgB,IAAI,kBAAkB,EAAE,UAAU,KAAK,CAAC,KAAK,CAAC;AACtE,SAAO;AAAA,IACL,OAAO;AAAA,MACL,aAAa,mBAAmB;AAAA,MAChC,MAAM,kBAAmB,SAAoB;AAAA,IAC/C;AAAA,IACA,CAAC,iBAAiB,iBAAiB;AAAA,EACrC;AACF;AAEO,IAAM,EAAE,YAAY,IAAI;AAAA,EAC7B;AAAA,EACA;AACF;AAQO,SAAS,mBAAmB,SAER;AACzB,QAAM,iBAAiB,kBAAkB,EAAE,UAAU,KAAK,CAAC;AAC3D,QAAM,gBAAgB,iBAAiB,OAAO;AAC9C,SAAO,iBACH,eAAe,WACd,eAAe,YAAY;AAClC;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/react/ComposerContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useMessageRuntime } from \"./MessageContext\";\nimport { useThreadRuntime } from \"./ThreadContext\";\nimport { ComposerRuntime } from \"../../api/ComposerRuntime\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\n\nexport function useComposerRuntime(options?: {\n optional?: false | undefined;\n}): ComposerRuntime;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null;\nexport function useComposerRuntime(options?: {\n optional?: boolean | undefined;\n}): ComposerRuntime | null {\n const messageRuntime = useMessageRuntime({ optional: true });\n const threadRuntime = useThreadRuntime(options);\n return messageRuntime\n ? messageRuntime.composer\n : (threadRuntime?.composer ?? null);\n}\n\nexport const useComposer = createStateHookForRuntime(useComposerRuntime);\n"],"mappings":";;;AAEA,SAAS,yBAAyB;AAClC,SAAS,wBAAwB;AAEjC,SAAS,iCAAiC;AAQnC,SAAS,mBAAmB,SAER;AACzB,QAAM,iBAAiB,kBAAkB,EAAE,UAAU,KAAK,CAAC;AAC3D,QAAM,gBAAgB,iBAAiB,OAAO;AAC9C,SAAO,iBACH,eAAe,WACd,eAAe,YAAY;AAClC;AAEO,IAAM,cAAc,0BAA0B,kBAAkB;","names":[]}
@@ -1,20 +1,10 @@
1
1
  import { ReadonlyStore } from "../ReadonlyStore";
2
2
  import { UseBoundStore } from "zustand";
3
3
  import { ContentPartRuntime } from "../../api/ContentPartRuntime";
4
- import { ContentPartState } from "../../api/ContentPartRuntime";
5
4
  export type ContentPartContextValue = {
6
5
  useContentPartRuntime: UseBoundStore<ReadonlyStore<ContentPartRuntime>>;
7
- useContentPart: UseBoundStore<ReadonlyStore<ContentPartState>>;
8
6
  };
9
7
  export declare const ContentPartContext: import("react").Context<ContentPartContextValue | null>;
10
- export declare const useContentPartContext: {
11
- (options?: {
12
- optional?: false | undefined;
13
- } | undefined): ContentPartContextValue;
14
- (options?: {
15
- optional?: boolean | undefined;
16
- } | undefined): ContentPartContextValue | null;
17
- };
18
8
  export declare function useContentPartRuntime(options?: {
19
9
  optional?: false | undefined;
20
10
  }): ContentPartRuntime;
@@ -22,14 +12,30 @@ export declare function useContentPartRuntime(options?: {
22
12
  optional?: boolean | undefined;
23
13
  }): ContentPartRuntime | null;
24
14
  export declare const useContentPart: {
25
- (): ContentPartState;
26
- <TSelected>(selector: (state: ContentPartState) => TSelected): TSelected;
15
+ (): import("../..").ContentPartState;
16
+ <TSelected>(selector: (state: import("../..").ContentPartState) => TSelected): TSelected;
17
+ <TSelected>(selector: ((state: import("../..").ContentPartState) => TSelected) | undefined): import("../..").ContentPartState | TSelected;
27
18
  (options: {
28
- optional: true;
29
- }): ContentPartState | null;
19
+ optional?: false | undefined;
20
+ }): import("../..").ContentPartState;
21
+ (options: {
22
+ optional?: boolean | undefined;
23
+ }): import("../..").ContentPartState | null;
30
24
  <TSelected>(options: {
31
- optional: true;
32
- selector?: (state: ContentPartState) => TSelected;
25
+ optional?: false | undefined;
26
+ selector: (state: import("../..").ContentPartState) => TSelected;
27
+ }): TSelected;
28
+ <TSelected>(options: {
29
+ optional?: false | undefined;
30
+ selector: ((state: import("../..").ContentPartState) => TSelected) | undefined;
31
+ }): import("../..").ContentPartState | TSelected;
32
+ <TSelected>(options: {
33
+ optional?: boolean | undefined;
34
+ selector: (state: import("../..").ContentPartState) => TSelected;
33
35
  }): TSelected | null;
36
+ <TSelected>(options: {
37
+ optional?: boolean | undefined;
38
+ selector: ((state: import("../..").ContentPartState) => TSelected) | undefined;
39
+ }): import("../..").ContentPartState | TSelected | null;
34
40
  };
35
41
  //# sourceMappingURL=ContentPartContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContentPartContext.d.ts","sourceRoot":"","sources":["../../../src/context/react/ContentPartContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,MAAM,MAAM,uBAAuB,GAAG;IACpC,qBAAqB,EAAE,aAAa,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAAC;IACxE,cAAc,EAAE,aAAa,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC;CAChE,CAAC;AAEF,eAAO,MAAM,kBAAkB,yDAE9B,CAAC;AAEF,eAAO,MAAM,qBAAqB;;;;;;;CAGjC,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,kBAAkB,CAAC;AACvB,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,kBAAkB,GAAG,IAAI,CAAC;AAS9B,eAAO,MAAQ,cAAc;;;;;;;;;;CAG5B,CAAC"}
1
+ {"version":3,"file":"ContentPartContext.d.ts","sourceRoot":"","sources":["../../../src/context/react/ContentPartContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGlE,MAAM,MAAM,uBAAuB,GAAG;IACpC,qBAAqB,EAAE,aAAa,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAAC;CACzE,CAAC;AAEF,eAAO,MAAM,kBAAkB,yDAE9B,CAAC;AAOF,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,kBAAkB,CAAC;AACvB,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAC9C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,kBAAkB,GAAG,IAAI,CAAC;AAS9B,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;CAAmD,CAAC"}
@@ -23,13 +23,12 @@ var ContentPartContext_exports = {};
23
23
  __export(ContentPartContext_exports, {
24
24
  ContentPartContext: () => ContentPartContext,
25
25
  useContentPart: () => useContentPart,
26
- useContentPartContext: () => useContentPartContext,
27
26
  useContentPartRuntime: () => useContentPartRuntime
28
27
  });
29
28
  module.exports = __toCommonJS(ContentPartContext_exports);
30
29
  var import_react = require("react");
31
- var import_createContextStoreHook = require("./utils/createContextStoreHook.js");
32
30
  var import_createContextHook = require("./utils/createContextHook.js");
31
+ var import_createStateHookForRuntime = require("./utils/createStateHookForRuntime.js");
33
32
  var ContentPartContext = (0, import_react.createContext)(
34
33
  null
35
34
  );
@@ -42,15 +41,11 @@ function useContentPartRuntime(options) {
42
41
  if (!context) return null;
43
42
  return context.useContentPartRuntime();
44
43
  }
45
- var { useContentPart } = (0, import_createContextStoreHook.createContextStoreHook)(
46
- useContentPartContext,
47
- "useContentPart"
48
- );
44
+ var useContentPart = (0, import_createStateHookForRuntime.createStateHookForRuntime)(useContentPartRuntime);
49
45
  // Annotate the CommonJS export names for ESM import in node:
50
46
  0 && (module.exports = {
51
47
  ContentPartContext,
52
48
  useContentPart,
53
- useContentPartContext,
54
49
  useContentPartRuntime
55
50
  });
56
51
  //# sourceMappingURL=ContentPartContext.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/react/ContentPartContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { createContextStoreHook } from \"./utils/createContextStoreHook\";\nimport { createContextHook } from \"./utils/createContextHook\";\nimport { UseBoundStore } from \"zustand\";\nimport { ContentPartRuntime } from \"../../api/ContentPartRuntime\";\nimport { ContentPartState } from \"../../api/ContentPartRuntime\";\n\nexport type ContentPartContextValue = {\n useContentPartRuntime: UseBoundStore<ReadonlyStore<ContentPartRuntime>>;\n useContentPart: UseBoundStore<ReadonlyStore<ContentPartState>>;\n};\n\nexport const ContentPartContext = createContext<ContentPartContextValue | null>(\n null,\n);\n\nexport const useContentPartContext = createContextHook(\n ContentPartContext,\n \"a component passed to <MessagePrimitive.Content components={...}>\",\n);\n\nexport function useContentPartRuntime(options?: {\n optional?: false | undefined;\n}): ContentPartRuntime;\nexport function useContentPartRuntime(options?: {\n optional?: boolean | undefined;\n}): ContentPartRuntime | null;\nexport function useContentPartRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const context = useContentPartContext(options);\n if (!context) return null;\n return context.useContentPartRuntime();\n}\n\nexport const { useContentPart } = createContextStoreHook(\n useContentPartContext,\n \"useContentPart\",\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA8B;AAE9B,oCAAuC;AACvC,+BAAkC;AAU3B,IAAM,yBAAqB;AAAA,EAChC;AACF;AAEO,IAAM,4BAAwB;AAAA,EACnC;AAAA,EACA;AACF;AAQO,SAAS,sBAAsB,SAEnC;AACD,QAAM,UAAU,sBAAsB,OAAO;AAC7C,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ,sBAAsB;AACvC;AAEO,IAAM,EAAE,eAAe,QAAI;AAAA,EAChC;AAAA,EACA;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/context/react/ContentPartContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\nimport { ReadonlyStore } from \"../ReadonlyStore\";\nimport { createContextHook } from \"./utils/createContextHook\";\nimport { UseBoundStore } from \"zustand\";\nimport { ContentPartRuntime } from \"../../api/ContentPartRuntime\";\nimport { createStateHookForRuntime } from \"./utils/createStateHookForRuntime\";\n\nexport type ContentPartContextValue = {\n useContentPartRuntime: UseBoundStore<ReadonlyStore<ContentPartRuntime>>;\n};\n\nexport const ContentPartContext = createContext<ContentPartContextValue | null>(\n null,\n);\n\nconst useContentPartContext = createContextHook(\n ContentPartContext,\n \"a component passed to <MessagePrimitive.Content components={...}>\",\n);\n\nexport function useContentPartRuntime(options?: {\n optional?: false | undefined;\n}): ContentPartRuntime;\nexport function useContentPartRuntime(options?: {\n optional?: boolean | undefined;\n}): ContentPartRuntime | null;\nexport function useContentPartRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const context = useContentPartContext(options);\n if (!context) return null;\n return context.useContentPartRuntime();\n}\n\nexport const useContentPart = createStateHookForRuntime(useContentPartRuntime);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA8B;AAE9B,+BAAkC;AAGlC,uCAA0C;AAMnC,IAAM,yBAAqB;AAAA,EAChC;AACF;AAEA,IAAM,4BAAwB;AAAA,EAC5B;AAAA,EACA;AACF;AAQO,SAAS,sBAAsB,SAEnC;AACD,QAAM,UAAU,sBAAsB,OAAO;AAC7C,MAAI,CAAC,QAAS,QAAO;AACrB,SAAO,QAAQ,sBAAsB;AACvC;AAEO,IAAM,qBAAiB,4DAA0B,qBAAqB;","names":[]}
@@ -2,8 +2,8 @@
2
2
 
3
3
  // src/context/react/ContentPartContext.ts
4
4
  import { createContext } from "react";
5
- import { createContextStoreHook } from "./utils/createContextStoreHook.mjs";
6
5
  import { createContextHook } from "./utils/createContextHook.mjs";
6
+ import { createStateHookForRuntime } from "./utils/createStateHookForRuntime.mjs";
7
7
  var ContentPartContext = createContext(
8
8
  null
9
9
  );
@@ -16,14 +16,10 @@ function useContentPartRuntime(options) {
16
16
  if (!context) return null;
17
17
  return context.useContentPartRuntime();
18
18
  }
19
- var { useContentPart } = createContextStoreHook(
20
- useContentPartContext,
21
- "useContentPart"
22
- );
19
+ var useContentPart = createStateHookForRuntime(useContentPartRuntime);
23
20
  export {
24
21
  ContentPartContext,
25
22
  useContentPart,
26
- useContentPartContext,
27
23
  useContentPartRuntime
28
24
  };
29
25
  //# sourceMappingURL=ContentPartContext.mjs.map