@assistant-ui/react 0.14.29 → 0.15.1

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 (142) hide show
  1. package/dist/client/ExternalThread.js +4 -3
  2. package/dist/client/ExternalThread.js.map +1 -1
  3. package/dist/client/InMemoryThreadList.js +3 -3
  4. package/dist/client/InMemoryThreadList.js.map +1 -1
  5. package/dist/context/index.d.ts +1 -8
  6. package/dist/context/index.js +1 -8
  7. package/dist/hooks/useToolCallElapsed.js +24 -29
  8. package/dist/hooks/useToolCallElapsed.js.map +1 -1
  9. package/dist/index.d.ts +1 -8
  10. package/dist/index.js +1 -8
  11. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +3 -3
  12. package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
  13. package/dist/mcp-apps/McpAppRenderer.js +1 -1
  14. package/dist/mcp-apps/McpAppRenderer.js.map +1 -1
  15. package/dist/model-context/makeAssistantVisible.js +26 -25
  16. package/dist/model-context/makeAssistantVisible.js.map +1 -1
  17. package/dist/primitives/actionBar/ActionBarExportMarkdown.js +3 -3
  18. package/dist/primitives/actionBar/ActionBarExportMarkdown.js.map +1 -1
  19. package/dist/primitives/attachment/AttachmentRemove.js +3 -3
  20. package/dist/primitives/attachment/AttachmentRemove.js.map +1 -1
  21. package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.js +3 -3
  22. package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.js.map +1 -1
  23. package/dist/primitives/composer/ComposerAddAttachment.js +3 -3
  24. package/dist/primitives/composer/ComposerAddAttachment.js.map +1 -1
  25. package/dist/primitives/composer/ComposerAttachmentDropzone.js +1 -1
  26. package/dist/primitives/composer/ComposerAttachmentDropzone.js.map +1 -1
  27. package/dist/primitives/composer/ComposerInput.js +13 -13
  28. package/dist/primitives/composer/ComposerInput.js.map +1 -1
  29. package/dist/primitives/composer/ComposerQuote.js +1 -1
  30. package/dist/primitives/composer/ComposerQuote.js.map +1 -1
  31. package/dist/primitives/composer/ComposerStopDictation.js +3 -3
  32. package/dist/primitives/composer/ComposerStopDictation.js.map +1 -1
  33. package/dist/primitives/composer/trigger/triggerSelectionResource.d.ts.map +1 -1
  34. package/dist/primitives/composer/trigger/triggerSelectionResource.js +3 -3
  35. package/dist/primitives/composer/trigger/triggerSelectionResource.js.map +1 -1
  36. package/dist/primitives/message/MessagePartsGrouped.d.ts.map +1 -1
  37. package/dist/primitives/message/MessagePartsGrouped.js +67 -89
  38. package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
  39. package/dist/primitives/message/MessageRoot.js +3 -3
  40. package/dist/primitives/message/MessageRoot.js.map +1 -1
  41. package/dist/primitives/queueItem/QueueItemRemove.js +3 -3
  42. package/dist/primitives/queueItem/QueueItemRemove.js.map +1 -1
  43. package/dist/primitives/queueItem/QueueItemSteer.js +3 -3
  44. package/dist/primitives/queueItem/QueueItemSteer.js.map +1 -1
  45. package/dist/primitives/selectionToolbar/SelectionToolbarQuote.js +1 -1
  46. package/dist/primitives/selectionToolbar/SelectionToolbarQuote.js.map +1 -1
  47. package/dist/primitives/suggestion/SuggestionTrigger.js +16 -15
  48. package/dist/primitives/suggestion/SuggestionTrigger.js.map +1 -1
  49. package/dist/unstable/useComposerInput.js +2 -2
  50. package/dist/unstable/useComposerInput.js.map +1 -1
  51. package/dist/unstable/useComposerInputHistory.js +6 -6
  52. package/dist/unstable/useComposerInputHistory.js.map +1 -1
  53. package/dist/unstable/useMentionAdapter.js +1 -1
  54. package/dist/unstable/useMentionAdapter.js.map +1 -1
  55. package/dist/utils/smooth/SmoothContext.js +3 -3
  56. package/dist/utils/smooth/SmoothContext.js.map +1 -1
  57. package/dist/utils/smooth/useSmooth.js +1 -1
  58. package/dist/utils/smooth/useSmooth.js.map +1 -1
  59. package/dist/utils/useToolArgsFieldStatus.d.ts +2 -2
  60. package/package.json +5 -5
  61. package/src/client/ExternalThread.ts +5 -3
  62. package/src/client/InMemoryThreadList.ts +3 -3
  63. package/src/context/index.ts +0 -44
  64. package/src/hooks/useToolCallElapsed.ts +9 -12
  65. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.test.tsx +5 -9
  66. package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts +1 -1
  67. package/src/mcp-apps/McpAppRenderer.tsx +1 -1
  68. package/src/model-context/makeAssistantVisible.test.tsx +1 -1
  69. package/src/model-context/makeAssistantVisible.tsx +1 -1
  70. package/src/primitives/actionBar/ActionBarExportMarkdown.tsx +1 -1
  71. package/src/primitives/attachment/AttachmentRemove.ts +1 -1
  72. package/src/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.ts +1 -1
  73. package/src/primitives/composer/ComposerAddAttachment.test.tsx +2 -2
  74. package/src/primitives/composer/ComposerAddAttachment.ts +1 -1
  75. package/src/primitives/composer/ComposerAttachmentDropzone.test.tsx +2 -2
  76. package/src/primitives/composer/ComposerAttachmentDropzone.tsx +1 -1
  77. package/src/primitives/composer/ComposerInput.test.tsx +7 -7
  78. package/src/primitives/composer/ComposerInput.tsx +13 -13
  79. package/src/primitives/composer/ComposerQuote.tsx +1 -1
  80. package/src/primitives/composer/ComposerStopDictation.ts +1 -1
  81. package/src/primitives/composer/trigger/triggerSelectionResource.ts +7 -9
  82. package/src/primitives/message/MessagePartsGrouped.tsx +6 -8
  83. package/src/primitives/message/MessageRoot.tsx +1 -1
  84. package/src/primitives/queueItem/QueueItemRemove.ts +1 -1
  85. package/src/primitives/queueItem/QueueItemSteer.ts +1 -1
  86. package/src/primitives/selectionToolbar/SelectionToolbarQuote.tsx +1 -1
  87. package/src/primitives/suggestion/SuggestionTrigger.ts +9 -9
  88. package/src/tests/DataRenderers.test.tsx +1 -1
  89. package/src/tests/RemoteThreadListRuntime.deferredProvider.test.tsx +3 -3
  90. package/src/tests/external-thread-attachments.test.tsx +21 -23
  91. package/src/tests/external-thread-branches.test.tsx +10 -10
  92. package/src/tests/external-thread-parity.test.tsx +18 -20
  93. package/src/tests/local-runtime-queue.test.tsx +29 -34
  94. package/src/tests/messagePartSwitchRace.test.tsx +30 -13
  95. package/src/unstable/useComposerInput.test.tsx +2 -2
  96. package/src/unstable/useComposerInput.ts +2 -2
  97. package/src/unstable/useComposerInputHistory.test.tsx +3 -3
  98. package/src/unstable/useComposerInputHistory.ts +6 -6
  99. package/src/unstable/useMentionAdapter.ts +1 -1
  100. package/src/utils/smooth/SmoothContext.tsx +1 -1
  101. package/src/utils/smooth/useSmooth.test.tsx +1 -1
  102. package/src/utils/smooth/useSmooth.ts +1 -1
  103. package/dist/context/react/utils/createStateHookForRuntime.d.ts +0 -34
  104. package/dist/context/react/utils/createStateHookForRuntime.d.ts.map +0 -1
  105. package/dist/context/react/utils/createStateHookForRuntime.js +0 -21
  106. package/dist/context/react/utils/createStateHookForRuntime.js.map +0 -1
  107. package/dist/legacy-runtime/hooks/AssistantContext.d.ts +0 -74
  108. package/dist/legacy-runtime/hooks/AssistantContext.d.ts.map +0 -1
  109. package/dist/legacy-runtime/hooks/AssistantContext.js +0 -29
  110. package/dist/legacy-runtime/hooks/AssistantContext.js.map +0 -1
  111. package/dist/legacy-runtime/hooks/AttachmentContext.d.ts +0 -1007
  112. package/dist/legacy-runtime/hooks/AttachmentContext.d.ts.map +0 -1
  113. package/dist/legacy-runtime/hooks/AttachmentContext.js +0 -47
  114. package/dist/legacy-runtime/hooks/AttachmentContext.js.map +0 -1
  115. package/dist/legacy-runtime/hooks/ComposerContext.d.ts +0 -141
  116. package/dist/legacy-runtime/hooks/ComposerContext.d.ts.map +0 -1
  117. package/dist/legacy-runtime/hooks/ComposerContext.js +0 -65
  118. package/dist/legacy-runtime/hooks/ComposerContext.js.map +0 -1
  119. package/dist/legacy-runtime/hooks/MessageContext.d.ts +0 -155
  120. package/dist/legacy-runtime/hooks/MessageContext.d.ts.map +0 -1
  121. package/dist/legacy-runtime/hooks/MessageContext.js +0 -68
  122. package/dist/legacy-runtime/hooks/MessageContext.js.map +0 -1
  123. package/dist/legacy-runtime/hooks/MessagePartContext.d.ts +0 -44
  124. package/dist/legacy-runtime/hooks/MessagePartContext.d.ts.map +0 -1
  125. package/dist/legacy-runtime/hooks/MessagePartContext.js +0 -26
  126. package/dist/legacy-runtime/hooks/MessagePartContext.js.map +0 -1
  127. package/dist/legacy-runtime/hooks/ThreadContext.d.ts +0 -139
  128. package/dist/legacy-runtime/hooks/ThreadContext.d.ts.map +0 -1
  129. package/dist/legacy-runtime/hooks/ThreadContext.js +0 -84
  130. package/dist/legacy-runtime/hooks/ThreadContext.js.map +0 -1
  131. package/dist/legacy-runtime/hooks/ThreadListItemContext.d.ts +0 -44
  132. package/dist/legacy-runtime/hooks/ThreadListItemContext.d.ts.map +0 -1
  133. package/dist/legacy-runtime/hooks/ThreadListItemContext.js +0 -26
  134. package/dist/legacy-runtime/hooks/ThreadListItemContext.js.map +0 -1
  135. package/src/context/react/utils/createStateHookForRuntime.ts +0 -82
  136. package/src/legacy-runtime/hooks/AssistantContext.ts +0 -67
  137. package/src/legacy-runtime/hooks/AttachmentContext.ts +0 -99
  138. package/src/legacy-runtime/hooks/ComposerContext.ts +0 -131
  139. package/src/legacy-runtime/hooks/MessageContext.ts +0 -127
  140. package/src/legacy-runtime/hooks/MessagePartContext.ts +0 -32
  141. package/src/legacy-runtime/hooks/ThreadContext.ts +0 -120
  142. package/src/legacy-runtime/hooks/ThreadListItemContext.ts +0 -36
@@ -1,139 +0,0 @@
1
- import { ThreadRuntime } from "../runtime/ThreadRuntime.js";
2
- import { ModelContext } from "@assistant-ui/core";
3
- //#region src/legacy-runtime/hooks/ThreadContext.d.ts
4
- /**
5
- * @deprecated Use {@link useAui} with `aui.thread()` instead. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
6
- *
7
- * Hook to access the ThreadRuntime from the current context.
8
- *
9
- * The ThreadRuntime provides access to thread-level state and actions,
10
- * including message management, thread state, and composer functionality.
11
- *
12
- * @param options Configuration options
13
- * @param options.optional Whether the hook should return null if no context is found
14
- * @returns The ThreadRuntime instance, or null if optional is true and no context exists
15
- *
16
- * @example
17
- * ```tsx
18
- * // Before:
19
- * function MyComponent() {
20
- * const runtime = useThreadRuntime();
21
- * const handleSendMessage = (text: string) => {
22
- * runtime.append({ role: "user", content: [{ type: "text", text }] });
23
- * };
24
- * return <button onClick={() => handleSendMessage("Hello!")}>Send</button>;
25
- * }
26
- *
27
- * // After:
28
- * function MyComponent() {
29
- * const aui = useAui();
30
- * const handleSendMessage = (text: string) => {
31
- * aui.thread().append({ role: "user", content: [{ type: "text", text }] });
32
- * };
33
- * return <button onClick={() => handleSendMessage("Hello!")}>Send</button>;
34
- * }
35
- * ```
36
- */
37
- declare function useThreadRuntime(options?: {
38
- optional?: false | undefined;
39
- }): ThreadRuntime;
40
- declare function useThreadRuntime(options?: {
41
- optional?: boolean | undefined;
42
- }): ThreadRuntime | null;
43
- /**
44
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.thread)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
45
- *
46
- * Hook to access the current thread state.
47
- *
48
- * This hook provides reactive access to the thread's state, including messages,
49
- * running status, capabilities, and other thread-level properties.
50
- *
51
- * @param selector Optional selector function to pick specific state properties
52
- * @returns The selected thread state or the entire thread state if no selector provided
53
- *
54
- * @example
55
- * ```tsx
56
- * // Before:
57
- * function ThreadStatus() {
58
- * const isRunning = useThread((state) => state.isRunning);
59
- * const messageCount = useThread((state) => state.messages.length);
60
- * return <div>Running: {isRunning}, Messages: {messageCount}</div>;
61
- * }
62
- *
63
- * // After:
64
- * function ThreadStatus() {
65
- * const isRunning = useAuiState((s) => s.thread.isRunning);
66
- * const messageCount = useAuiState((s) => s.thread.messages.length);
67
- * return <div>Running: {isRunning}, Messages: {messageCount}</div>;
68
- * }
69
- * ```
70
- */
71
- declare const useThread: {
72
- (): import("@assistant-ui/core").ThreadState;
73
- <TSelected>(selector: (state: import("@assistant-ui/core").ThreadState) => TSelected): TSelected;
74
- <TSelected>(selector: ((state: import("@assistant-ui/core").ThreadState) => TSelected) | undefined): import("@assistant-ui/core").ThreadState | TSelected;
75
- (options: {
76
- optional?: false | undefined;
77
- }): import("@assistant-ui/core").ThreadState;
78
- (options: {
79
- optional?: boolean | undefined;
80
- }): import("@assistant-ui/core").ThreadState | null;
81
- <TSelected>(options: {
82
- optional?: false | undefined;
83
- selector: (state: import("@assistant-ui/core").ThreadState) => TSelected;
84
- }): TSelected;
85
- <TSelected>(options: {
86
- optional?: false | undefined;
87
- selector: ((state: import("@assistant-ui/core").ThreadState) => TSelected) | undefined;
88
- }): import("@assistant-ui/core").ThreadState | TSelected;
89
- <TSelected>(options: {
90
- optional?: boolean | undefined;
91
- selector: (state: import("@assistant-ui/core").ThreadState) => TSelected;
92
- }): TSelected | null;
93
- <TSelected>(options: {
94
- optional?: boolean | undefined;
95
- selector: ((state: import("@assistant-ui/core").ThreadState) => TSelected) | undefined;
96
- }): import("@assistant-ui/core").ThreadState | TSelected | null;
97
- };
98
- /**
99
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.thread.composer)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
100
- */
101
- declare const useThreadComposer: {
102
- (): import("@assistant-ui/core").ThreadComposerState;
103
- <TSelected>(selector: (state: import("@assistant-ui/core").ThreadComposerState) => TSelected): TSelected;
104
- <TSelected>(selector: ((state: import("@assistant-ui/core").ThreadComposerState) => TSelected) | undefined): import("@assistant-ui/core").ThreadComposerState | TSelected;
105
- (options: {
106
- optional?: false | undefined;
107
- }): import("@assistant-ui/core").ThreadComposerState;
108
- (options: {
109
- optional?: boolean | undefined;
110
- }): import("@assistant-ui/core").ThreadComposerState | null;
111
- <TSelected>(options: {
112
- optional?: false | undefined;
113
- selector: (state: import("@assistant-ui/core").ThreadComposerState) => TSelected;
114
- }): TSelected;
115
- <TSelected>(options: {
116
- optional?: false | undefined;
117
- selector: ((state: import("@assistant-ui/core").ThreadComposerState) => TSelected) | undefined;
118
- }): import("@assistant-ui/core").ThreadComposerState | TSelected;
119
- <TSelected>(options: {
120
- optional?: boolean | undefined;
121
- selector: (state: import("@assistant-ui/core").ThreadComposerState) => TSelected;
122
- }): TSelected | null;
123
- <TSelected>(options: {
124
- optional?: boolean | undefined;
125
- selector: ((state: import("@assistant-ui/core").ThreadComposerState) => TSelected) | undefined;
126
- }): import("@assistant-ui/core").ThreadComposerState | TSelected | null;
127
- };
128
- /**
129
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.thread.modelContext)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
130
- */
131
- declare function useThreadModelContext(options?: {
132
- optional?: false | undefined;
133
- }): ModelContext;
134
- declare function useThreadModelContext(options?: {
135
- optional?: boolean | undefined;
136
- }): ModelContext | null;
137
- //#endregion
138
- export { useThread, useThreadComposer, useThreadModelContext, useThreadRuntime };
139
- //# sourceMappingURL=ThreadContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ThreadContext.d.ts","names":[],"sources":["../../../src/legacy-runtime/hooks/ThreadContext.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0CgB,iBAAiB;EAC/B;IACE;iBACY,iBAAiB;EAC/B;IACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAwCS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAOG,sBAAsB;EACpC;IACE;iBACY,sBAAsB;EACpC;IACE"}
@@ -1,84 +0,0 @@
1
- "use client";
2
- import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime.js";
3
- import { useAui, useAuiEvent, useAuiState } from "@assistant-ui/store";
4
- import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
5
- import { useState } from "@assistant-ui/tap/react-shim";
6
- //#region src/legacy-runtime/hooks/ThreadContext.ts
7
- function useThreadRuntime(options) {
8
- const $ = c(2);
9
- const aui = useAui();
10
- let t0;
11
- if ($[0] !== aui) {
12
- t0 = () => aui.thread.source ? aui.thread().__internal_getRuntime?.() ?? null : null;
13
- $[0] = aui;
14
- $[1] = t0;
15
- } else t0 = $[1];
16
- const runtime = useAuiState(t0);
17
- if (!runtime && !options?.optional) throw new Error("ThreadRuntime is not available");
18
- return runtime;
19
- }
20
- /**
21
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.thread)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
22
- *
23
- * Hook to access the current thread state.
24
- *
25
- * This hook provides reactive access to the thread's state, including messages,
26
- * running status, capabilities, and other thread-level properties.
27
- *
28
- * @param selector Optional selector function to pick specific state properties
29
- * @returns The selected thread state or the entire thread state if no selector provided
30
- *
31
- * @example
32
- * ```tsx
33
- * // Before:
34
- * function ThreadStatus() {
35
- * const isRunning = useThread((state) => state.isRunning);
36
- * const messageCount = useThread((state) => state.messages.length);
37
- * return <div>Running: {isRunning}, Messages: {messageCount}</div>;
38
- * }
39
- *
40
- * // After:
41
- * function ThreadStatus() {
42
- * const isRunning = useAuiState((s) => s.thread.isRunning);
43
- * const messageCount = useAuiState((s) => s.thread.messages.length);
44
- * return <div>Running: {isRunning}, Messages: {messageCount}</div>;
45
- * }
46
- * ```
47
- */
48
- const useThread = createStateHookForRuntime(useThreadRuntime);
49
- const useThreadComposerRuntime = (opt) => {
50
- return useThreadRuntime(opt)?.composer ?? null;
51
- };
52
- /**
53
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.thread.composer)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
54
- */
55
- const useThreadComposer = createStateHookForRuntime(useThreadComposerRuntime);
56
- function useThreadModelContext(options) {
57
- const $ = c(5);
58
- let t0;
59
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
60
- t0 = {};
61
- $[0] = t0;
62
- } else t0 = $[0];
63
- const [, rerender] = useState(t0);
64
- const runtime = useThreadRuntime(options);
65
- let t1;
66
- if ($[1] !== rerender) {
67
- t1 = () => rerender({});
68
- $[1] = rerender;
69
- $[2] = t1;
70
- } else t1 = $[2];
71
- useAuiEvent("thread.modelContextUpdate", t1);
72
- if (!runtime) return null;
73
- let t2;
74
- if ($[3] !== runtime) {
75
- t2 = runtime?.getModelContext();
76
- $[3] = runtime;
77
- $[4] = t2;
78
- } else t2 = $[4];
79
- return t2;
80
- }
81
- //#endregion
82
- export { useThread, useThreadComposer, useThreadModelContext, useThreadRuntime };
83
-
84
- //# sourceMappingURL=ThreadContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ThreadContext.js","names":["c","_c","useState","ThreadRuntime","ModelContext","createStateHookForRuntime","ThreadComposerRuntime","useAui","useAuiEvent","useAuiState","useThreadRuntime","options","optional","$","aui","t0","thread","source","__internal_getRuntime","runtime","Error","useThread","useThreadComposerRuntime","opt","composer","useThreadComposer","useThreadModelContext","Symbol","for","rerender","t1","t2","getModelContext"],"sources":["../../../src/legacy-runtime/hooks/ThreadContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useState } from \"react\";\nimport type { ThreadRuntime } from \"../runtime/ThreadRuntime\";\nimport type { ModelContext } from \"@assistant-ui/core\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport type { ThreadComposerRuntime } from \"@assistant-ui/core\";\nimport { useAui, useAuiEvent, useAuiState } from \"@assistant-ui/store\";\n\n/**\n * @deprecated Use {@link useAui} with `aui.thread()` instead. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.\n *\n * Hook to access the ThreadRuntime from the current context.\n *\n * The ThreadRuntime provides access to thread-level state and actions,\n * including message management, thread state, and composer functionality.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The ThreadRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * // Before:\n * function MyComponent() {\n * const runtime = useThreadRuntime();\n * const handleSendMessage = (text: string) => {\n * runtime.append({ role: \"user\", content: [{ type: \"text\", text }] });\n * };\n * return <button onClick={() => handleSendMessage(\"Hello!\")}>Send</button>;\n * }\n *\n * // After:\n * function MyComponent() {\n * const aui = useAui();\n * const handleSendMessage = (text: string) => {\n * aui.thread().append({ role: \"user\", content: [{ type: \"text\", text }] });\n * };\n * return <button onClick={() => handleSendMessage(\"Hello!\")}>Send</button>;\n * }\n * ```\n */\nexport function useThreadRuntime(options?: {\n optional?: false | undefined;\n}): ThreadRuntime;\nexport function useThreadRuntime(options?: {\n optional?: boolean | undefined;\n}): ThreadRuntime | null;\nexport function useThreadRuntime(options?: { optional?: boolean | undefined }) {\n const aui = useAui();\n const runtime = useAuiState(() =>\n aui.thread.source ? (aui.thread().__internal_getRuntime?.() ?? null) : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"ThreadRuntime is not available\");\n }\n return runtime;\n}\n\n/**\n * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.thread)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.\n *\n * Hook to access the current thread state.\n *\n * This hook provides reactive access to the thread's state, including messages,\n * running status, capabilities, and other thread-level properties.\n *\n * @param selector Optional selector function to pick specific state properties\n * @returns The selected thread state or the entire thread state if no selector provided\n *\n * @example\n * ```tsx\n * // Before:\n * function ThreadStatus() {\n * const isRunning = useThread((state) => state.isRunning);\n * const messageCount = useThread((state) => state.messages.length);\n * return <div>Running: {isRunning}, Messages: {messageCount}</div>;\n * }\n *\n * // After:\n * function ThreadStatus() {\n * const isRunning = useAuiState((s) => s.thread.isRunning);\n * const messageCount = useAuiState((s) => s.thread.messages.length);\n * return <div>Running: {isRunning}, Messages: {messageCount}</div>;\n * }\n * ```\n */\nexport const useThread = createStateHookForRuntime(useThreadRuntime);\n\nconst useThreadComposerRuntime = (opt: {\n optional: boolean | undefined;\n}): ThreadComposerRuntime | null => useThreadRuntime(opt)?.composer ?? null;\n\n/**\n * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.thread.composer)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.\n */\nexport const useThreadComposer = createStateHookForRuntime(\n useThreadComposerRuntime,\n);\n\n/**\n * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.thread.modelContext)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.\n */\nexport function useThreadModelContext(options?: {\n optional?: false | undefined;\n}): ModelContext;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null;\nexport function useThreadModelContext(options?: {\n optional?: boolean | undefined;\n}): ModelContext | null {\n const [, rerender] = useState({});\n\n const runtime = useThreadRuntime(options);\n useAuiEvent(\"thread.modelContextUpdate\", () => rerender({}));\n\n if (!runtime) return null;\n return runtime?.getModelContext();\n}\n"],"mappings":";;;;;;AAgDA,SAAOU,iBAAAC,SAAA;CAAA,MAAAE,IAAAZ,EAAA,CAAA;CACL,MAAAa,MAAYP,OAAO;CAAE,IAAAQ;CAAA,IAAAF,EAAA,OAAAC,KAAA;EACOC,WAC1BD,IAAGE,OAAOC,SAAWH,IAAGE,OAAQ,CAAC,CAAAE,wBAAiC,KAA7C,OAArB;EAA2EL,EAAA,KAAAC;EAAAD,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAD7E,MAAAM,UAAgBV,YAAYM,EAE5B;CACA,IAAI,CAACI,WAAD,CAAaR,SAAOC,UACtB,MAAM,IAAIQ,MAAM,gCAAgC;CACjD,OACMD;AAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BhB,MAAaE,YAAYhB,0BAA0BK,gBAAgB;AAEnE,MAAMY,4BAA2BC,QAAA;CAAA,OAEGb,iBAAiBa,GAAa,CAAC,EAAAC,YAA/B;AAAuC;;;;AAK3E,MAAaC,oBAAoBpB,0BAC/BiB,wBACF;AAWA,SAAOI,sBAAAf,SAAA;CAAA,MAAAE,IAAAZ,EAAA,CAAA;CAAA,IAAAc;CAAA,IAAAF,EAAA,OAAAc,OAAAC,IAAA,2BAAA,GAAA;EAGyBb,KAAA,CAAC;EAACF,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAAhC,MAAA,GAAAgB,YAAqB3B,SAASa,EAAE;CAEhC,MAAAI,UAAgBT,iBAAiBC,OAAO;CAAE,IAAAmB;CAAA,IAAAjB,EAAA,OAAAgB,UAAA;EACDC,WAAMD,SAAS,CAAC,CAAC;EAAChB,EAAA,KAAAgB;EAAAhB,EAAA,KAAAiB;CAAA,OAAAA,KAAAjB,EAAA;CAA3DL,YAAY,6BAA6BsB,EAAkB;CAE3D,IAAI,CAACX,SAAO,OAAS;CAAK,IAAAY;CAAA,IAAAlB,EAAA,OAAAM,SAAA;EACnBY,KAAAZ,SAAOa,gBAAkB;EAACnB,EAAA,KAAAM;EAAAN,EAAA,KAAAkB;CAAA,OAAAA,KAAAlB,EAAA;CAAA,OAA1BkB;AAA0B"}
@@ -1,44 +0,0 @@
1
- import { ThreadListItemRuntime } from "../runtime/ThreadListItemRuntime.js";
2
- //#region src/legacy-runtime/hooks/ThreadListItemContext.d.ts
3
- /**
4
- * @deprecated Use {@link useAui} with `aui.threadListItem()` instead. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
5
- */
6
- declare function useThreadListItemRuntime(options?: {
7
- optional?: false | undefined;
8
- }): ThreadListItemRuntime;
9
- declare function useThreadListItemRuntime(options?: {
10
- optional?: boolean | undefined;
11
- }): ThreadListItemRuntime | null;
12
- /**
13
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.threadListItem)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
14
- */
15
- declare const useThreadListItem: {
16
- (): import("@assistant-ui/core").ThreadListItemState;
17
- <TSelected>(selector: (state: import("@assistant-ui/core").ThreadListItemState) => TSelected): TSelected;
18
- <TSelected>(selector: ((state: import("@assistant-ui/core").ThreadListItemState) => TSelected) | undefined): import("@assistant-ui/core").ThreadListItemState | TSelected;
19
- (options: {
20
- optional?: false | undefined;
21
- }): import("@assistant-ui/core").ThreadListItemState;
22
- (options: {
23
- optional?: boolean | undefined;
24
- }): import("@assistant-ui/core").ThreadListItemState | null;
25
- <TSelected>(options: {
26
- optional?: false | undefined;
27
- selector: (state: import("@assistant-ui/core").ThreadListItemState) => TSelected;
28
- }): TSelected;
29
- <TSelected>(options: {
30
- optional?: false | undefined;
31
- selector: ((state: import("@assistant-ui/core").ThreadListItemState) => TSelected) | undefined;
32
- }): import("@assistant-ui/core").ThreadListItemState | TSelected;
33
- <TSelected>(options: {
34
- optional?: boolean | undefined;
35
- selector: (state: import("@assistant-ui/core").ThreadListItemState) => TSelected;
36
- }): TSelected | null;
37
- <TSelected>(options: {
38
- optional?: boolean | undefined;
39
- selector: ((state: import("@assistant-ui/core").ThreadListItemState) => TSelected) | undefined;
40
- }): import("@assistant-ui/core").ThreadListItemState | TSelected | null;
41
- };
42
- //#endregion
43
- export { useThreadListItem, useThreadListItemRuntime };
44
- //# sourceMappingURL=ThreadListItemContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ThreadListItemContext.d.ts","names":[],"sources":["../../../src/legacy-runtime/hooks/ThreadListItemContext.ts"],"mappings":";;;;;iBASgB,yBAAyB;EACvC;IACE;iBACY,yBAAyB;EACvC;IACE;;;;cAmBS"}
@@ -1,26 +0,0 @@
1
- "use client";
2
- import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime.js";
3
- import { useAui, useAuiState } from "@assistant-ui/store";
4
- import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
5
- //#region src/legacy-runtime/hooks/ThreadListItemContext.ts
6
- function useThreadListItemRuntime(options) {
7
- const $ = c(2);
8
- const aui = useAui();
9
- let t0;
10
- if ($[0] !== aui) {
11
- t0 = () => aui.threadListItem.source ? aui.threadListItem().__internal_getRuntime?.() ?? null : null;
12
- $[0] = aui;
13
- $[1] = t0;
14
- } else t0 = $[1];
15
- const runtime = useAuiState(t0);
16
- if (!runtime && !options?.optional) throw new Error("ThreadListItemRuntime is not available");
17
- return runtime;
18
- }
19
- /**
20
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.threadListItem)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
21
- */
22
- const useThreadListItem = createStateHookForRuntime(useThreadListItemRuntime);
23
- //#endregion
24
- export { useThreadListItem, useThreadListItemRuntime };
25
-
26
- //# sourceMappingURL=ThreadListItemContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ThreadListItemContext.js","names":["c","_c","ThreadListItemRuntime","createStateHookForRuntime","useAui","useAuiState","useThreadListItemRuntime","options","optional","$","aui","t0","threadListItem","source","__internal_getRuntime","runtime","Error","useThreadListItem"],"sources":["../../../src/legacy-runtime/hooks/ThreadListItemContext.ts"],"sourcesContent":["\"use client\";\n\nimport type { ThreadListItemRuntime } from \"../runtime/ThreadListItemRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\n\n/**\n * @deprecated Use {@link useAui} with `aui.threadListItem()` instead. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.\n */\nexport function useThreadListItemRuntime(options?: {\n optional?: false | undefined;\n}): ThreadListItemRuntime;\nexport function useThreadListItemRuntime(options?: {\n optional?: boolean | undefined;\n}): ThreadListItemRuntime | null;\nexport function useThreadListItemRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const aui = useAui();\n const runtime = useAuiState(() =>\n aui.threadListItem.source\n ? (aui.threadListItem().__internal_getRuntime?.() ?? null)\n : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"ThreadListItemRuntime is not available\");\n }\n return runtime;\n}\n\n/**\n * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.threadListItem)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.\n */\nexport const useThreadListItem = createStateHookForRuntime(\n useThreadListItemRuntime,\n);\n"],"mappings":";;;;;AAeA,SAAOM,yBAAAC,SAAA;CAAA,MAAAE,IAAAR,EAAA,CAAA;CAGL,MAAAS,MAAYN,OAAO;CAAE,IAAAO;CAAA,IAAAF,EAAA,OAAAC,KAAA;EACOC,WAC1BD,IAAGE,eAAeC,SACbH,IAAGE,eAAgB,CAAC,CAAAE,wBAAiC,KAArD,OADL;EAEQL,EAAA,KAAAC;EAAAD,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAHV,MAAAM,UAAgBV,YAAYM,EAI5B;CACA,IAAI,CAACI,WAAD,CAAaR,SAAOC,UACtB,MAAM,IAAIQ,MAAM,wCAAwC;CACzD,OACMD;AAAO;;;;AAMhB,MAAaE,oBAAoBd,0BAC/BG,wBACF"}
@@ -1,82 +0,0 @@
1
- import {
2
- type SubscribableRuntime,
3
- useRuntimeStateInternal,
4
- } from "./useRuntimeState";
5
-
6
- export function createStateHookForRuntime<TState>(
7
- useRuntime: (options: {
8
- optional: boolean | undefined;
9
- }) => SubscribableRuntime<TState> | null,
10
- ) {
11
- // empty
12
- function useStoreHook(): TState;
13
-
14
- // selector
15
- function useStoreHook<TSelected>(
16
- selector: (state: TState) => TSelected,
17
- ): TSelected;
18
-
19
- // selector?
20
- function useStoreHook<TSelected>(
21
- selector: ((state: TState) => TSelected) | undefined,
22
- ): TSelected | TState;
23
-
24
- // optional=false
25
- function useStoreHook(options: { optional?: false | undefined }): TState;
26
-
27
- // optional?
28
- function useStoreHook(options: {
29
- optional?: boolean | undefined;
30
- }): TState | null;
31
-
32
- // optional=false, selector
33
- function useStoreHook<TSelected>(options: {
34
- optional?: false | undefined;
35
- selector: (state: TState) => TSelected;
36
- }): TSelected;
37
-
38
- // optional=false, selector?
39
- function useStoreHook<TSelected>(options: {
40
- optional?: false | undefined;
41
- selector: ((state: TState) => TSelected) | undefined;
42
- }): TSelected | TState;
43
-
44
- // optional?, selector
45
- function useStoreHook<TSelected>(options: {
46
- optional?: boolean | undefined;
47
- selector: (state: TState) => TSelected;
48
- }): TSelected | null;
49
-
50
- // optional?, selector?
51
- function useStoreHook<TSelected>(options: {
52
- optional?: boolean | undefined;
53
- selector: ((state: TState) => TSelected) | undefined;
54
- }): TSelected | TState | null;
55
-
56
- function useStoreHook<TSelected>(
57
- param?:
58
- | ((state: TState) => TSelected)
59
- | {
60
- optional?: boolean | undefined;
61
- selector?: ((state: TState) => TSelected) | undefined;
62
- },
63
- ): TSelected | TState | null {
64
- let optional = false;
65
- let selector: ((state: TState) => TSelected) | undefined;
66
-
67
- if (typeof param === "function") {
68
- selector = param;
69
- } else if (param) {
70
- optional = !!param.optional;
71
- selector = param.selector;
72
- }
73
-
74
- const store = useRuntime({ optional });
75
- if (!store) return null;
76
-
77
- // it is ok to call useRuntimeStateInternal conditionally because it will never become null if its available
78
- return useRuntimeStateInternal(store, selector);
79
- }
80
-
81
- return useStoreHook;
82
- }
@@ -1,67 +0,0 @@
1
- "use client";
2
-
3
- import { useAui } from "@assistant-ui/store";
4
- import type { AssistantRuntime } from "../runtime/AssistantRuntime";
5
- import type { ThreadListRuntime } from "../runtime/ThreadListRuntime";
6
- import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
7
-
8
- /**
9
- * @deprecated Use {@link useAui} instead. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
10
- *
11
- * Hook to access the AssistantRuntime from the current context.
12
- *
13
- * The AssistantRuntime provides access to the top-level assistant state and actions,
14
- * including thread management, tool registration, and configuration.
15
- *
16
- * @param options Configuration options
17
- * @param options.optional Whether the hook should return null if no context is found
18
- * @returns The AssistantRuntime instance, or null if optional is true and no context exists
19
- *
20
- * @example
21
- * ```tsx
22
- * // Before:
23
- * function MyComponent() {
24
- * const runtime = useAssistantRuntime();
25
- * const handleNewThread = () => {
26
- * runtime.switchToNewThread();
27
- * };
28
- * return <button onClick={handleNewThread}>New Thread</button>;
29
- * }
30
- *
31
- * // After:
32
- * function MyComponent() {
33
- * const aui = useAui();
34
- * const handleNewThread = () => {
35
- * aui.threads().switchToNewThread();
36
- * };
37
- * return <button onClick={handleNewThread}>New Thread</button>;
38
- * }
39
- * ```
40
- */
41
- export function useAssistantRuntime(options?: {
42
- optional?: false | undefined;
43
- }): AssistantRuntime;
44
- export function useAssistantRuntime(options?: {
45
- optional?: boolean | undefined;
46
- }): AssistantRuntime | null;
47
- export function useAssistantRuntime(options?: {
48
- optional?: boolean | undefined;
49
- }) {
50
- const aui = useAui();
51
- const runtime = aui.threads().__internal_getAssistantRuntime?.() ?? null;
52
-
53
- if (!runtime && !options?.optional) {
54
- throw new Error("AssistantRuntime is not available");
55
- }
56
-
57
- return runtime;
58
- }
59
-
60
- const useThreadListRuntime = (opt: {
61
- optional: boolean | undefined;
62
- }): ThreadListRuntime | null => useAssistantRuntime(opt)?.threads ?? null;
63
-
64
- /**
65
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.threads)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
66
- */
67
- export const useThreadList = createStateHookForRuntime(useThreadListRuntime);
@@ -1,99 +0,0 @@
1
- "use client";
2
-
3
- import type { AttachmentRuntime } from "../runtime/AttachmentRuntime";
4
- import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
5
- import { useAui, useAuiState } from "@assistant-ui/store";
6
-
7
- /**
8
- * @deprecated Use {@link useAui} with `aui.attachment()` instead. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
9
- */
10
- export function useAttachmentRuntime(options?: {
11
- optional?: false | undefined;
12
- }): AttachmentRuntime;
13
- export function useAttachmentRuntime(options?: {
14
- optional?: boolean | undefined;
15
- }): AttachmentRuntime | null;
16
- export function useAttachmentRuntime(options?: {
17
- optional?: boolean | undefined;
18
- }): AttachmentRuntime | null {
19
- const aui = useAui();
20
- const runtime = useAuiState(() =>
21
- aui.attachment.source
22
- ? (aui.attachment().__internal_getRuntime?.() ?? null)
23
- : null,
24
- );
25
- if (!runtime && !options?.optional) {
26
- throw new Error("AttachmentRuntime is not available");
27
- }
28
- return runtime;
29
- }
30
-
31
- export function useThreadComposerAttachmentRuntime(options?: {
32
- optional?: false | undefined;
33
- }): AttachmentRuntime<"thread-composer">;
34
- export function useThreadComposerAttachmentRuntime(options?: {
35
- optional?: boolean | undefined;
36
- }): AttachmentRuntime<"thread-composer"> | null;
37
- export function useThreadComposerAttachmentRuntime(options?: {
38
- optional?: boolean | undefined;
39
- }): AttachmentRuntime<"thread-composer"> | null {
40
- const attachmentRuntime = useAttachmentRuntime(options);
41
- if (!attachmentRuntime) return null;
42
- if (attachmentRuntime.source !== "thread-composer")
43
- throw new Error(
44
- "This component must be used within a thread's ComposerPrimitive.Attachments component.",
45
- );
46
- return attachmentRuntime as AttachmentRuntime<"thread-composer">;
47
- }
48
-
49
- export function useEditComposerAttachmentRuntime(options?: {
50
- optional?: false | undefined;
51
- }): AttachmentRuntime<"edit-composer">;
52
- export function useEditComposerAttachmentRuntime(options?: {
53
- optional?: boolean | undefined;
54
- }): AttachmentRuntime<"edit-composer"> | null;
55
- export function useEditComposerAttachmentRuntime(options?: {
56
- optional?: boolean | undefined;
57
- }): AttachmentRuntime<"edit-composer"> | null {
58
- const attachmentRuntime = useAttachmentRuntime(options);
59
- if (!attachmentRuntime) return null;
60
- if (attachmentRuntime.source !== "edit-composer")
61
- throw new Error(
62
- "This component must be used within a message's ComposerPrimitive.Attachments component.",
63
- );
64
-
65
- return attachmentRuntime as AttachmentRuntime<"edit-composer">;
66
- }
67
-
68
- export function useMessageAttachmentRuntime(options?: {
69
- optional?: false | undefined;
70
- }): AttachmentRuntime<"message">;
71
- export function useMessageAttachmentRuntime(options?: {
72
- optional?: boolean | undefined;
73
- }): AttachmentRuntime<"message"> | null;
74
- export function useMessageAttachmentRuntime(options?: {
75
- optional?: boolean | undefined;
76
- }): AttachmentRuntime<"message"> | null {
77
- const attachmentRuntime = useAttachmentRuntime(options);
78
- if (!attachmentRuntime) return null;
79
- if (attachmentRuntime.source !== "message")
80
- throw new Error(
81
- "This component must be used within a MessagePrimitive.Attachments component.",
82
- );
83
- return attachmentRuntime as AttachmentRuntime<"message">;
84
- }
85
-
86
- /**
87
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.attachment)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
88
- */
89
- export const useAttachment = createStateHookForRuntime(useAttachmentRuntime);
90
-
91
- export const useThreadComposerAttachment = createStateHookForRuntime(
92
- useThreadComposerAttachmentRuntime,
93
- );
94
- export const useEditComposerAttachment = createStateHookForRuntime(
95
- useEditComposerAttachmentRuntime,
96
- );
97
- export const useMessageAttachment = createStateHookForRuntime(
98
- useMessageAttachmentRuntime,
99
- );