@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,131 +0,0 @@
1
- "use client";
2
-
3
- import { useAui, useAuiState } from "@assistant-ui/store";
4
- import type { ComposerRuntime } from "../runtime/ComposerRuntime";
5
- import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
6
-
7
- /**
8
- * @deprecated Use {@link useAui} with `aui.composer()` instead. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
9
- *
10
- * Hook to access the ComposerRuntime from the current context.
11
- *
12
- * The ComposerRuntime provides access to composer state and actions for message
13
- * composition, including text input, attachments, and sending functionality.
14
- * This hook automatically resolves to either the message's edit composer or
15
- * the thread's main composer depending on the context.
16
- *
17
- * @param options Configuration options
18
- * @param options.optional Whether the hook should return null if no context is found
19
- * @returns The ComposerRuntime instance, or null if optional is true and no context exists
20
- *
21
- * @example
22
- * ```tsx
23
- * // Before:
24
- * function ComposerActions() {
25
- * const runtime = useComposerRuntime();
26
- * const handleSend = () => {
27
- * if (runtime.getState().canSend) {
28
- * runtime.send();
29
- * }
30
- * };
31
- * const handleCancel = () => {
32
- * if (runtime.getState().canCancel) {
33
- * runtime.cancel();
34
- * }
35
- * };
36
- * return (
37
- * <div>
38
- * <button onClick={handleSend}>Send</button>
39
- * <button onClick={handleCancel}>Cancel</button>
40
- * </div>
41
- * );
42
- * }
43
- *
44
- * // After:
45
- * function ComposerActions() {
46
- * const aui = useAui();
47
- * const canSend = useAuiState((s) => s.composer.canSend);
48
- * const canCancel = useAuiState((s) => s.composer.canCancel);
49
- * const handleSend = () => {
50
- * if (canSend) {
51
- * aui.composer().send();
52
- * }
53
- * };
54
- * const handleCancel = () => {
55
- * if (canCancel) {
56
- * aui.composer().cancel();
57
- * }
58
- * };
59
- * return (
60
- * <div>
61
- * <button onClick={handleSend}>Send</button>
62
- * <button onClick={handleCancel}>Cancel</button>
63
- * </div>
64
- * );
65
- * }
66
- * ```
67
- */
68
- export function useComposerRuntime(options?: {
69
- optional?: false | undefined;
70
- }): ComposerRuntime;
71
- export function useComposerRuntime(options?: {
72
- optional?: boolean | undefined;
73
- }): ComposerRuntime | null;
74
- export function useComposerRuntime(options?: {
75
- optional?: boolean | undefined;
76
- }): ComposerRuntime | null {
77
- const aui = useAui();
78
- const runtime = useAuiState(() =>
79
- aui.composer.source
80
- ? (aui.composer().__internal_getRuntime?.() ?? null)
81
- : null,
82
- );
83
- if (!runtime && !options?.optional) {
84
- throw new Error("ComposerRuntime is not available");
85
- }
86
- return runtime;
87
- }
88
-
89
- /**
90
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.composer)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
91
- *
92
- * Hook to access the current composer state.
93
- *
94
- * This hook provides reactive access to the composer's state, including text content,
95
- * attachments, editing status, and send/cancel capabilities.
96
- *
97
- * @param selector Optional selector function to pick specific state properties
98
- * @returns The selected composer state or the entire composer state if no selector provided
99
- *
100
- * @example
101
- * ```tsx
102
- * // Before:
103
- * function ComposerStatus() {
104
- * const text = useComposer((state) => state.text);
105
- * const canSend = useComposer((state) => state.canSend);
106
- * const attachmentCount = useComposer((state) => state.attachments.length);
107
- * return (
108
- * <div>
109
- * Text: {text.length} chars,
110
- * Attachments: {attachmentCount},
111
- * Can send: {canSend}
112
- * </div>
113
- * );
114
- * }
115
- *
116
- * // After:
117
- * function ComposerStatus() {
118
- * const text = useAuiState((s) => s.composer.text);
119
- * const canSend = useAuiState((s) => s.composer.canSend);
120
- * const attachmentCount = useAuiState((s) => s.composer.attachments.length);
121
- * return (
122
- * <div>
123
- * Text: {text.length} chars,
124
- * Attachments: {attachmentCount},
125
- * Can send: {canSend}
126
- * </div>
127
- * );
128
- * }
129
- * ```
130
- */
131
- export const useComposer = createStateHookForRuntime(useComposerRuntime);
@@ -1,127 +0,0 @@
1
- "use client";
2
-
3
- import type { MessageRuntime } from "../runtime/MessageRuntime";
4
- import { useAui, useAuiState } from "@assistant-ui/store";
5
- import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
6
- import type { EditComposerRuntime } from "@assistant-ui/core";
7
-
8
- /**
9
- * @deprecated Use {@link useAui} with `aui.message()` instead. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
10
- *
11
- * Hook to access the MessageRuntime from the current context.
12
- *
13
- * The MessageRuntime provides access to message-level state and actions,
14
- * including message content, status, editing capabilities, and branching.
15
- *
16
- * @param options Configuration options
17
- * @param options.optional Whether the hook should return null if no context is found
18
- * @returns The MessageRuntime instance, or null if optional is true and no context exists
19
- *
20
- * @example
21
- * ```tsx
22
- * // Before:
23
- * function MessageActions() {
24
- * const runtime = useMessageRuntime();
25
- * const handleReload = () => {
26
- * runtime.reload();
27
- * };
28
- * const handleEdit = () => {
29
- * runtime.startEdit();
30
- * };
31
- * return (
32
- * <div>
33
- * <button onClick={handleReload}>Reload</button>
34
- * <button onClick={handleEdit}>Edit</button>
35
- * </div>
36
- * );
37
- * }
38
- *
39
- * // After:
40
- * function MessageActions() {
41
- * const aui = useAui();
42
- * const handleReload = () => {
43
- * aui.message().reload();
44
- * };
45
- * const handleEdit = () => {
46
- * aui.message().startEdit();
47
- * };
48
- * return (
49
- * <div>
50
- * <button onClick={handleReload}>Reload</button>
51
- * <button onClick={handleEdit}>Edit</button>
52
- * </div>
53
- * );
54
- * }
55
- * ```
56
- */
57
- export function useMessageRuntime(options?: {
58
- optional?: false | undefined;
59
- }): MessageRuntime;
60
- export function useMessageRuntime(options?: {
61
- optional?: boolean | undefined;
62
- }): MessageRuntime | null;
63
- export function useMessageRuntime(options?: {
64
- optional?: boolean | undefined;
65
- }) {
66
- const aui = useAui();
67
- const runtime = useAuiState(() =>
68
- aui.message.source
69
- ? (aui.message().__internal_getRuntime?.() ?? null)
70
- : null,
71
- );
72
- if (!runtime && !options?.optional) {
73
- throw new Error("MessageRuntime is not available");
74
- }
75
- return runtime;
76
- }
77
-
78
- /**
79
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.message)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
80
- *
81
- * Hook to access the current message state.
82
- *
83
- * This hook provides reactive access to the message's state, including content,
84
- * role, status, and other message-level properties.
85
- *
86
- * @param selector Optional selector function to pick specific state properties
87
- * @returns The selected message state or the entire message state if no selector provided
88
- *
89
- * @example
90
- * ```tsx
91
- * // Before:
92
- * function MessageContent() {
93
- * const role = useMessage((state) => state.role);
94
- * const content = useMessage((state) => state.content);
95
- * const isLoading = useMessage((state) => state.status.type === "running");
96
- * return (
97
- * <div className={`message-${role}`}>
98
- * {isLoading ? "Loading..." : content.map(part => part.text).join("")}
99
- * </div>
100
- * );
101
- * }
102
- *
103
- * // After:
104
- * function MessageContent() {
105
- * const role = useAuiState((s) => s.message.role);
106
- * const content = useAuiState((s) => s.message.content);
107
- * const isLoading = useAuiState((s) => s.message.status.type === "running");
108
- * return (
109
- * <div className={`message-${role}`}>
110
- * {isLoading ? "Loading..." : content.map(part => part.text).join("")}
111
- * </div>
112
- * );
113
- * }
114
- * ```
115
- */
116
- export const useMessage = createStateHookForRuntime(useMessageRuntime);
117
-
118
- const useEditComposerRuntime = (opt: {
119
- optional: boolean | undefined;
120
- }): EditComposerRuntime | null => useMessageRuntime(opt)?.composer ?? null;
121
-
122
- /**
123
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.message.composer)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
124
- */
125
- export const useEditComposer = createStateHookForRuntime(
126
- useEditComposerRuntime,
127
- );
@@ -1,32 +0,0 @@
1
- "use client";
2
-
3
- import type { MessagePartRuntime } from "../runtime/MessagePartRuntime";
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.part()` instead. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
9
- */
10
- export function useMessagePartRuntime(options?: {
11
- optional?: false | undefined;
12
- }): MessagePartRuntime;
13
- export function useMessagePartRuntime(options?: {
14
- optional?: boolean | undefined;
15
- }): MessagePartRuntime | null;
16
- export function useMessagePartRuntime(options?: {
17
- optional?: boolean | undefined;
18
- }) {
19
- const aui = useAui();
20
- const runtime = useAuiState(() =>
21
- aui.part.source ? (aui.part().__internal_getRuntime?.() ?? null) : null,
22
- );
23
- if (!runtime && !options?.optional) {
24
- throw new Error("MessagePartRuntime is not available");
25
- }
26
- return runtime;
27
- }
28
-
29
- /**
30
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.part)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
31
- */
32
- export const useMessagePart = createStateHookForRuntime(useMessagePartRuntime);
@@ -1,120 +0,0 @@
1
- "use client";
2
-
3
- import { useState } from "react";
4
- import type { ThreadRuntime } from "../runtime/ThreadRuntime";
5
- import type { ModelContext } from "@assistant-ui/core";
6
- import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
7
- import type { ThreadComposerRuntime } from "@assistant-ui/core";
8
- import { useAui, useAuiEvent, useAuiState } from "@assistant-ui/store";
9
-
10
- /**
11
- * @deprecated Use {@link useAui} with `aui.thread()` instead. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
12
- *
13
- * Hook to access the ThreadRuntime from the current context.
14
- *
15
- * The ThreadRuntime provides access to thread-level state and actions,
16
- * including message management, thread state, and composer functionality.
17
- *
18
- * @param options Configuration options
19
- * @param options.optional Whether the hook should return null if no context is found
20
- * @returns The ThreadRuntime instance, or null if optional is true and no context exists
21
- *
22
- * @example
23
- * ```tsx
24
- * // Before:
25
- * function MyComponent() {
26
- * const runtime = useThreadRuntime();
27
- * const handleSendMessage = (text: string) => {
28
- * runtime.append({ role: "user", content: [{ type: "text", text }] });
29
- * };
30
- * return <button onClick={() => handleSendMessage("Hello!")}>Send</button>;
31
- * }
32
- *
33
- * // After:
34
- * function MyComponent() {
35
- * const aui = useAui();
36
- * const handleSendMessage = (text: string) => {
37
- * aui.thread().append({ role: "user", content: [{ type: "text", text }] });
38
- * };
39
- * return <button onClick={() => handleSendMessage("Hello!")}>Send</button>;
40
- * }
41
- * ```
42
- */
43
- export function useThreadRuntime(options?: {
44
- optional?: false | undefined;
45
- }): ThreadRuntime;
46
- export function useThreadRuntime(options?: {
47
- optional?: boolean | undefined;
48
- }): ThreadRuntime | null;
49
- export function useThreadRuntime(options?: { optional?: boolean | undefined }) {
50
- const aui = useAui();
51
- const runtime = useAuiState(() =>
52
- aui.thread.source ? (aui.thread().__internal_getRuntime?.() ?? null) : null,
53
- );
54
- if (!runtime && !options?.optional) {
55
- throw new Error("ThreadRuntime is not available");
56
- }
57
- return runtime;
58
- }
59
-
60
- /**
61
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.thread)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
62
- *
63
- * Hook to access the current thread state.
64
- *
65
- * This hook provides reactive access to the thread's state, including messages,
66
- * running status, capabilities, and other thread-level properties.
67
- *
68
- * @param selector Optional selector function to pick specific state properties
69
- * @returns The selected thread state or the entire thread state if no selector provided
70
- *
71
- * @example
72
- * ```tsx
73
- * // Before:
74
- * function ThreadStatus() {
75
- * const isRunning = useThread((state) => state.isRunning);
76
- * const messageCount = useThread((state) => state.messages.length);
77
- * return <div>Running: {isRunning}, Messages: {messageCount}</div>;
78
- * }
79
- *
80
- * // After:
81
- * function ThreadStatus() {
82
- * const isRunning = useAuiState((s) => s.thread.isRunning);
83
- * const messageCount = useAuiState((s) => s.thread.messages.length);
84
- * return <div>Running: {isRunning}, Messages: {messageCount}</div>;
85
- * }
86
- * ```
87
- */
88
- export const useThread = createStateHookForRuntime(useThreadRuntime);
89
-
90
- const useThreadComposerRuntime = (opt: {
91
- optional: boolean | undefined;
92
- }): ThreadComposerRuntime | null => useThreadRuntime(opt)?.composer ?? null;
93
-
94
- /**
95
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.thread.composer)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
96
- */
97
- export const useThreadComposer = createStateHookForRuntime(
98
- useThreadComposerRuntime,
99
- );
100
-
101
- /**
102
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.thread.modelContext)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
103
- */
104
- export function useThreadModelContext(options?: {
105
- optional?: false | undefined;
106
- }): ModelContext;
107
- export function useThreadModelContext(options?: {
108
- optional?: boolean | undefined;
109
- }): ModelContext | null;
110
- export function useThreadModelContext(options?: {
111
- optional?: boolean | undefined;
112
- }): ModelContext | null {
113
- const [, rerender] = useState({});
114
-
115
- const runtime = useThreadRuntime(options);
116
- useAuiEvent("thread.modelContextUpdate", () => rerender({}));
117
-
118
- if (!runtime) return null;
119
- return runtime?.getModelContext();
120
- }
@@ -1,36 +0,0 @@
1
- "use client";
2
-
3
- import type { ThreadListItemRuntime } from "../runtime/ThreadListItemRuntime";
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.threadListItem()` instead. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
9
- */
10
- export function useThreadListItemRuntime(options?: {
11
- optional?: false | undefined;
12
- }): ThreadListItemRuntime;
13
- export function useThreadListItemRuntime(options?: {
14
- optional?: boolean | undefined;
15
- }): ThreadListItemRuntime | null;
16
- export function useThreadListItemRuntime(options?: {
17
- optional?: boolean | undefined;
18
- }) {
19
- const aui = useAui();
20
- const runtime = useAuiState(() =>
21
- aui.threadListItem.source
22
- ? (aui.threadListItem().__internal_getRuntime?.() ?? null)
23
- : null,
24
- );
25
- if (!runtime && !options?.optional) {
26
- throw new Error("ThreadListItemRuntime is not available");
27
- }
28
- return runtime;
29
- }
30
-
31
- /**
32
- * @deprecated Use {@link useAuiState}: `useAuiState((s) => s.threadListItem)`. See the {@link https://assistant-ui.com/docs/migrations/v0-12 migration guide}.
33
- */
34
- export const useThreadListItem = createStateHookForRuntime(
35
- useThreadListItemRuntime,
36
- );