@assistant-ui/react 0.11.35 → 0.11.37
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.
- package/dist/client/AssistantClient.d.ts +13 -57
- package/dist/client/AssistantClient.d.ts.map +1 -1
- package/dist/client/AssistantClient.js +49 -26
- package/dist/client/AssistantClient.js.map +1 -1
- package/dist/client/ModelContext.d.ts +8 -0
- package/dist/client/ModelContext.d.ts.map +1 -0
- package/dist/client/ModelContext.js +21 -0
- package/dist/client/ModelContext.js.map +1 -0
- package/dist/client/ModelContextClient.d.ts +7 -0
- package/dist/client/ModelContextClient.d.ts.map +1 -0
- package/dist/client/ModelContextClient.js +18 -0
- package/dist/client/ModelContextClient.js.map +1 -0
- package/dist/client/ToolUIClient.d.ts.map +1 -1
- package/dist/client/ToolUIClient.js +45 -3
- package/dist/client/ToolUIClient.js.map +1 -1
- package/dist/client/ToolUIContext.d.ts +4 -0
- package/dist/client/ToolUIContext.d.ts.map +1 -0
- package/dist/client/ToolUIContext.js +20 -0
- package/dist/client/ToolUIContext.js.map +1 -0
- package/dist/client/Tools.d.ts +10 -0
- package/dist/client/Tools.d.ts.map +1 -0
- package/dist/client/Tools.js +55 -0
- package/dist/client/Tools.js.map +1 -0
- package/dist/client/types/ModelContext.d.ts +12 -0
- package/dist/client/types/ModelContext.d.ts.map +1 -0
- package/dist/client/types/ModelContext.js +1 -0
- package/dist/client/types/ModelContext.js.map +1 -0
- package/dist/client/types/ThreadList.d.ts.map +1 -1
- package/dist/client/types/ToolUI.d.ts +12 -1
- package/dist/client/types/ToolUI.d.ts.map +1 -1
- package/dist/client/types/Tools.d.ts +9 -0
- package/dist/client/types/Tools.d.ts.map +1 -0
- package/dist/client/types/Tools.js +1 -0
- package/dist/client/types/Tools.js.map +1 -0
- package/dist/context/providers/AttachmentByIndexProvider.d.ts.map +1 -1
- package/dist/context/providers/AttachmentByIndexProvider.js +20 -24
- package/dist/context/providers/AttachmentByIndexProvider.js.map +1 -1
- package/dist/context/providers/MessageByIndexProvider.d.ts.map +1 -1
- package/dist/context/providers/MessageByIndexProvider.js +27 -29
- package/dist/context/providers/MessageByIndexProvider.js.map +1 -1
- package/dist/context/providers/MessageProvider.d.ts.map +1 -1
- package/dist/context/providers/MessageProvider.js +11 -13
- package/dist/context/providers/MessageProvider.js.map +1 -1
- package/dist/context/providers/PartByIndexProvider.d.ts.map +1 -1
- package/dist/context/providers/PartByIndexProvider.js +11 -13
- package/dist/context/providers/PartByIndexProvider.js.map +1 -1
- package/dist/context/providers/TextMessagePartProvider.d.ts.map +1 -1
- package/dist/context/providers/TextMessagePartProvider.js +11 -13
- package/dist/context/providers/TextMessagePartProvider.js.map +1 -1
- package/dist/context/providers/ThreadListItemProvider.d.ts.map +1 -1
- package/dist/context/providers/ThreadListItemProvider.js +41 -45
- package/dist/context/providers/ThreadListItemProvider.js.map +1 -1
- package/dist/context/react/AssistantApiContext.d.ts +33 -4
- package/dist/context/react/AssistantApiContext.d.ts.map +1 -1
- package/dist/context/react/AssistantApiContext.js +35 -17
- package/dist/context/react/AssistantApiContext.js.map +1 -1
- package/dist/context/react/index.d.ts +1 -1
- package/dist/context/react/index.d.ts.map +1 -1
- package/dist/context/react/index.js +5 -1
- package/dist/context/react/index.js.map +1 -1
- package/dist/legacy-runtime/AssistantRuntimeProvider.d.ts.map +1 -1
- package/dist/legacy-runtime/AssistantRuntimeProvider.js +7 -9
- package/dist/legacy-runtime/AssistantRuntimeProvider.js.map +1 -1
- package/dist/legacy-runtime/RuntimeAdapter.d.ts +7 -0
- package/dist/legacy-runtime/RuntimeAdapter.d.ts.map +1 -0
- package/dist/legacy-runtime/RuntimeAdapter.js +20 -0
- package/dist/legacy-runtime/RuntimeAdapter.js.map +1 -0
- package/dist/legacy-runtime/client/ThreadListRuntimeClient.d.ts +2 -0
- package/dist/legacy-runtime/client/ThreadListRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/ThreadListRuntimeClient.js +6 -2
- package/dist/legacy-runtime/client/ThreadListRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/hooks/AssistantContext.d.ts +14 -1
- package/dist/legacy-runtime/hooks/AssistantContext.d.ts.map +1 -1
- package/dist/legacy-runtime/hooks/AssistantContext.js +1 -1
- package/dist/legacy-runtime/hooks/AssistantContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/AttachmentContext.d.ts +6 -0
- package/dist/legacy-runtime/hooks/AttachmentContext.d.ts.map +1 -1
- package/dist/legacy-runtime/hooks/AttachmentContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/ComposerContext.d.ts +41 -2
- package/dist/legacy-runtime/hooks/ComposerContext.d.ts.map +1 -1
- package/dist/legacy-runtime/hooks/ComposerContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/MessageContext.d.ts +36 -2
- package/dist/legacy-runtime/hooks/MessageContext.d.ts.map +1 -1
- package/dist/legacy-runtime/hooks/MessageContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/MessagePartContext.d.ts +6 -0
- package/dist/legacy-runtime/hooks/MessagePartContext.d.ts.map +1 -1
- package/dist/legacy-runtime/hooks/MessagePartContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/ThreadContext.d.ts +26 -1
- package/dist/legacy-runtime/hooks/ThreadContext.d.ts.map +1 -1
- package/dist/legacy-runtime/hooks/ThreadContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/ThreadListItemContext.d.ts +6 -0
- package/dist/legacy-runtime/hooks/ThreadListItemContext.d.ts.map +1 -1
- package/dist/legacy-runtime/hooks/ThreadListItemContext.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/core/AssistantRuntimeCore.d.ts +1 -0
- package/dist/legacy-runtime/runtime-cores/core/AssistantRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.d.ts +1 -0
- package/dist/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.js +3 -0
- package/dist/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadListRuntimeCore.d.ts +4 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadListRuntimeCore.js +2 -2
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadListRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.js +7 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/auto-status.d.ts +2 -12
- package/dist/legacy-runtime/runtime-cores/external-store/auto-status.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/auto-status.js +45 -15
- package/dist/legacy-runtime/runtime-cores/external-store/auto-status.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts +2 -0
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js +4 -2
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadListRuntimeCore.d.ts +4 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadListRuntimeCore.js +2 -2
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadListRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/utils/MessageRepository.js +1 -1
- package/dist/legacy-runtime/runtime-cores/utils/MessageRepository.js.map +1 -1
- package/dist/model-context/index.d.ts +2 -0
- package/dist/model-context/index.d.ts.map +1 -1
- package/dist/model-context/index.js +6 -0
- package/dist/model-context/index.js.map +1 -1
- package/dist/model-context/makeAssistantVisible.js +1 -1
- package/dist/model-context/makeAssistantVisible.js.map +1 -1
- package/dist/model-context/toolbox.d.ts +28 -0
- package/dist/model-context/toolbox.d.ts.map +1 -0
- package/dist/model-context/toolbox.js +15 -0
- package/dist/model-context/toolbox.js.map +1 -0
- package/dist/model-context/useAssistantInstructions.js +1 -1
- package/dist/model-context/useAssistantInstructions.js.map +1 -1
- package/dist/model-context/useAssistantTool.js +1 -1
- package/dist/model-context/useAssistantTool.js.map +1 -1
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/primitives/index.js +2 -0
- package/dist/primitives/index.js.map +1 -1
- package/dist/primitives/message/MessageParts.d.ts +31 -1
- package/dist/primitives/message/MessageParts.d.ts.map +1 -1
- package/dist/primitives/message/MessageParts.js +68 -25
- package/dist/primitives/message/MessageParts.js.map +1 -1
- package/dist/primitives/message/MessagePartsGrouped.d.ts.map +1 -1
- package/dist/primitives/message/MessagePartsGrouped.js +2 -2
- package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
- package/dist/primitives/reasoning/index.d.ts +2 -0
- package/dist/primitives/reasoning/index.d.ts.map +1 -0
- package/dist/primitives/reasoning/index.js +6 -0
- package/dist/primitives/reasoning/index.js.map +1 -0
- package/dist/primitives/reasoning/useScrollLock.d.ts +29 -0
- package/dist/primitives/reasoning/useScrollLock.d.ts.map +1 -0
- package/dist/primitives/reasoning/useScrollLock.js +50 -0
- package/dist/primitives/reasoning/useScrollLock.js.map +1 -0
- package/dist/tests/setup.js +7 -7
- package/dist/tests/setup.js.map +1 -1
- package/dist/types/MessagePartComponentTypes.d.ts +6 -1
- package/dist/types/MessagePartComponentTypes.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/tap-store/derived-scopes.d.ts +81 -0
- package/dist/utils/tap-store/derived-scopes.d.ts.map +1 -0
- package/dist/utils/tap-store/derived-scopes.js +67 -0
- package/dist/utils/tap-store/derived-scopes.js.map +1 -0
- package/dist/utils/tap-store/index.d.ts +1 -0
- package/dist/utils/tap-store/index.d.ts.map +1 -1
- package/dist/utils/tap-store/index.js +4 -0
- package/dist/utils/tap-store/index.js.map +1 -1
- package/dist/utils/tap-store/tap-api.js +1 -1
- package/dist/utils/tap-store/tap-api.js.map +1 -1
- package/package.json +9 -9
- package/src/client/AssistantClient.ts +64 -38
- package/src/client/ModelContext.ts +28 -0
- package/src/client/ModelContextClient.ts +16 -0
- package/src/client/ToolUIClient.ts +50 -3
- package/src/client/ToolUIContext.ts +22 -0
- package/src/client/Tools.ts +68 -0
- package/src/client/types/ModelContext.ts +15 -0
- package/src/client/types/ThreadList.ts +4 -0
- package/src/client/types/ToolUI.ts +10 -1
- package/src/client/types/Tools.ts +11 -0
- package/src/context/providers/AttachmentByIndexProvider.tsx +21 -25
- package/src/context/providers/MessageByIndexProvider.tsx +31 -33
- package/src/context/providers/MessageProvider.tsx +12 -14
- package/src/context/providers/PartByIndexProvider.tsx +12 -14
- package/src/context/providers/TextMessagePartProvider.tsx +12 -14
- package/src/context/providers/ThreadListItemProvider.tsx +42 -46
- package/src/context/react/AssistantApiContext.tsx +69 -29
- package/src/context/react/index.ts +5 -1
- package/src/legacy-runtime/AssistantRuntimeProvider.tsx +7 -9
- package/src/legacy-runtime/RuntimeAdapter.ts +19 -0
- package/src/legacy-runtime/client/ThreadListRuntimeClient.ts +10 -1
- package/src/legacy-runtime/hooks/AssistantContext.ts +16 -2
- package/src/legacy-runtime/hooks/AttachmentContext.ts +6 -0
- package/src/legacy-runtime/hooks/ComposerContext.ts +41 -2
- package/src/legacy-runtime/hooks/MessageContext.ts +37 -2
- package/src/legacy-runtime/hooks/MessagePartContext.ts +6 -0
- package/src/legacy-runtime/hooks/ThreadContext.ts +27 -1
- package/src/legacy-runtime/hooks/ThreadListItemContext.ts +6 -0
- package/src/legacy-runtime/runtime-cores/core/AssistantRuntimeCore.tsx +1 -0
- package/src/legacy-runtime/runtime-cores/core/BaseAssistantRuntimeCore.tsx +4 -0
- package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadListRuntimeCore.tsx +4 -2
- package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.tsx +7 -1
- package/src/legacy-runtime/runtime-cores/external-store/auto-status.tsx +49 -16
- package/src/legacy-runtime/runtime-cores/external-store/external-message-converter.tsx +4 -0
- package/src/legacy-runtime/runtime-cores/local/LocalThreadListRuntimeCore.tsx +4 -2
- package/src/legacy-runtime/runtime-cores/utils/MessageRepository.tsx +1 -1
- package/src/model-context/index.ts +9 -0
- package/src/model-context/makeAssistantVisible.tsx +1 -1
- package/src/model-context/toolbox.tsx +37 -0
- package/src/model-context/useAssistantInstructions.tsx +1 -1
- package/src/model-context/useAssistantTool.tsx +1 -1
- package/src/primitives/index.ts +1 -0
- package/src/primitives/message/MessageParts.tsx +114 -32
- package/src/primitives/message/MessagePartsGrouped.tsx +3 -2
- package/src/primitives/reasoning/index.ts +1 -0
- package/src/primitives/reasoning/useScrollLock.tsx +86 -0
- package/src/types/MessagePartComponentTypes.tsx +7 -1
- package/src/types/index.ts +2 -0
- package/src/utils/tap-store/derived-scopes.ts +185 -0
- package/src/utils/tap-store/index.ts +9 -0
- package/src/utils/tap-store/tap-api.ts +1 -1
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
useMemo,
|
|
8
8
|
useEffect
|
|
9
9
|
} from "react";
|
|
10
|
+
import { useResource } from "@assistant-ui/tap/react";
|
|
10
11
|
import {
|
|
11
12
|
normalizeEventSelector
|
|
12
13
|
} from "../../types/EventTypes.js";
|
|
@@ -15,6 +16,9 @@ import { DevToolsProviderApi } from "../../devtools/DevToolsHooks.js";
|
|
|
15
16
|
import {
|
|
16
17
|
useAssistantClient
|
|
17
18
|
} from "../../client/AssistantClient.js";
|
|
19
|
+
import {
|
|
20
|
+
DerivedScopes
|
|
21
|
+
} from "../../utils/tap-store/derived-scopes.js";
|
|
18
22
|
import { jsx } from "react/jsx-runtime";
|
|
19
23
|
var createAssistantApiField = (config) => {
|
|
20
24
|
const fn = config.get;
|
|
@@ -39,6 +43,22 @@ var AssistantApiContext = createContext({
|
|
|
39
43
|
throw new Error("ToolUIs is only available inside <AssistantProvider />");
|
|
40
44
|
}
|
|
41
45
|
}),
|
|
46
|
+
tools: createAssistantApiField({
|
|
47
|
+
source: null,
|
|
48
|
+
query: {},
|
|
49
|
+
get: () => {
|
|
50
|
+
throw new Error("Tools is only available inside <AssistantProvider />");
|
|
51
|
+
}
|
|
52
|
+
}),
|
|
53
|
+
modelContext: createAssistantApiField({
|
|
54
|
+
source: null,
|
|
55
|
+
query: {},
|
|
56
|
+
get: () => {
|
|
57
|
+
throw new Error(
|
|
58
|
+
"ModelContext is only available inside <AssistantProvider />"
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}),
|
|
42
62
|
threadListItem: createAssistantApiField({
|
|
43
63
|
source: null,
|
|
44
64
|
query: {},
|
|
@@ -96,21 +116,18 @@ var AssistantApiContext = createContext({
|
|
|
96
116
|
on: (selector) => {
|
|
97
117
|
const { scope } = normalizeEventSelector(selector);
|
|
98
118
|
throw new Error(`Event scope is not available in this component: ${scope}`);
|
|
99
|
-
},
|
|
100
|
-
registerModelContextProvider: () => {
|
|
101
|
-
throw new Error(
|
|
102
|
-
"Registering model context providers is only available inside <AssistantProvider />"
|
|
103
|
-
);
|
|
104
119
|
}
|
|
105
120
|
});
|
|
106
121
|
var useAssistantApiImpl = () => {
|
|
107
122
|
return useContext(AssistantApiContext);
|
|
108
123
|
};
|
|
124
|
+
var useExtendedAssistantApi = (scopes) => {
|
|
125
|
+
const baseApi = useAssistantApiImpl();
|
|
126
|
+
const partialApi = useResource(DerivedScopes(scopes));
|
|
127
|
+
return useMemo(() => extendApi(baseApi, partialApi), [baseApi, partialApi]);
|
|
128
|
+
};
|
|
109
129
|
var useExtendedAssistantApiImpl = (config) => {
|
|
110
|
-
|
|
111
|
-
const api2 = useAssistantClient(config);
|
|
112
|
-
const extendedApi = useMemo(() => extendApi(api, api2), [api, api2]);
|
|
113
|
-
return extendedApi;
|
|
130
|
+
return useAssistantClient(config);
|
|
114
131
|
};
|
|
115
132
|
function useAssistantApi(config) {
|
|
116
133
|
if (config) {
|
|
@@ -152,18 +169,19 @@ var extendApi = (api, api2) => {
|
|
|
152
169
|
flushSync: mergeFns(api.flushSync, api2FlushSync ?? NO_OP_FN)
|
|
153
170
|
};
|
|
154
171
|
};
|
|
155
|
-
var AssistantProvider = ({ api
|
|
156
|
-
const api = useAssistantApi();
|
|
157
|
-
const extendedApi = useMemo(() => extendApi(api, api2), [api, api2]);
|
|
172
|
+
var AssistantProvider = ({ api, children, devToolsVisible = true }) => {
|
|
158
173
|
useEffect(() => {
|
|
159
|
-
if (!devToolsVisible || !
|
|
160
|
-
return DevToolsProviderApi.register(
|
|
161
|
-
}, [
|
|
162
|
-
return /* @__PURE__ */ jsx(AssistantApiContext.Provider, { value:
|
|
174
|
+
if (!devToolsVisible || !api.subscribe) return void 0;
|
|
175
|
+
return DevToolsProviderApi.register(api);
|
|
176
|
+
}, [api, devToolsVisible]);
|
|
177
|
+
return /* @__PURE__ */ jsx(AssistantApiContext.Provider, { value: api, children: /* @__PURE__ */ jsx(ThreadViewportProvider, { children }) });
|
|
163
178
|
};
|
|
164
179
|
export {
|
|
165
180
|
AssistantProvider,
|
|
166
181
|
createAssistantApiField,
|
|
167
|
-
|
|
182
|
+
extendApi,
|
|
183
|
+
useAssistantApi,
|
|
184
|
+
useAssistantApiImpl,
|
|
185
|
+
useExtendedAssistantApi
|
|
168
186
|
};
|
|
169
187
|
//# sourceMappingURL=AssistantApiContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/react/AssistantApiContext.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n FC,\n PropsWithChildren,\n useContext,\n useMemo,\n useEffect,\n} from \"react\";\n\nimport { ToolUIApi, ToolUIState, ToolUIMeta } from \"../../client/types/ToolUI\";\nimport {\n MessageClientApi,\n MessageClientState,\n} from \"../../client/types/Message\";\nimport {\n ThreadListItemClientApi,\n ThreadListItemClientState,\n} from \"../../client/types/ThreadListItem\";\nimport {\n MessagePartClientApi,\n MessagePartClientState,\n} from \"../../client/types/Part\";\nimport { ThreadClientApi, ThreadClientState } from \"../../client/types/Thread\";\nimport {\n ComposerClientApi,\n ComposerClientState,\n} from \"../../client/types/Composer\";\nimport {\n AttachmentClientApi,\n AttachmentClientState,\n} from \"../../client/types/Attachment\";\nimport { Unsubscribe } from \"@assistant-ui/tap\";\nimport { ModelContextProvider } from \"../../model-context\";\nimport { AssistantRuntime } from \"../../legacy-runtime/runtime/AssistantRuntime\";\nimport {\n AssistantEvent,\n AssistantEventCallback,\n AssistantEventSelector,\n normalizeEventSelector,\n} from \"../../types/EventTypes\";\nimport {\n ThreadListClientApi,\n ThreadListClientState,\n} from \"../../client/types/ThreadList\";\nimport { ThreadViewportProvider } from \"../providers/ThreadViewportProvider\";\nimport { DevToolsProviderApi } from \"../../devtools/DevToolsHooks\";\nimport {\n AssistantClientProps,\n useAssistantClient,\n} from \"../../client/AssistantClient\";\n\nexport type AssistantState = {\n readonly threads: ThreadListClientState;\n readonly toolUIs: ToolUIState;\n\n readonly threadListItem: ThreadListItemClientState;\n readonly thread: ThreadClientState;\n readonly composer: ComposerClientState;\n readonly message: MessageClientState;\n readonly part: MessagePartClientState;\n readonly attachment: AttachmentClientState;\n};\n\ntype AssistantApiField<\n TApi,\n TMeta extends { source: string | null; query: any },\n> = (() => TApi) & (TMeta | { source: null; query: Record<string, never> });\n\n// Meta types for each API method\ntype ThreadsMeta = {\n source: \"root\";\n query: Record<string, never>;\n};\n\ntype ThreadListItemMeta = {\n source: \"threads\";\n query:\n | { type: \"index\"; index: number; archived: boolean }\n | { type: \"main\" }\n | { type: \"id\"; id: string };\n};\n\ntype ThreadMeta = {\n source: \"threads\";\n query: { type: \"main\" };\n};\n\ntype ComposerMeta = {\n source: \"message\" | \"thread\";\n query: Record<string, never>;\n};\n\ntype MessageMeta =\n | {\n source: \"thread\";\n query: { type: \"index\"; index: number };\n }\n | {\n source: \"root\";\n query: Record<string, never>;\n };\n\ntype PartMeta = {\n source: \"message\" | \"root\";\n query: { type: \"index\"; index: number } | Record<string, never>;\n};\n\ntype AttachmentMeta = {\n source: \"message\" | \"composer\";\n query: { type: \"index\"; index: number };\n};\n\nexport type AssistantApi = {\n threads: AssistantApiField<ThreadListClientApi, ThreadsMeta>;\n toolUIs: AssistantApiField<ToolUIApi, ToolUIMeta>;\n threadListItem: AssistantApiField<\n ThreadListItemClientApi,\n ThreadListItemMeta\n >;\n thread: AssistantApiField<ThreadClientApi, ThreadMeta>;\n composer: AssistantApiField<ComposerClientApi, ComposerMeta>;\n message: AssistantApiField<MessageClientApi, MessageMeta>;\n part: AssistantApiField<MessagePartClientApi, PartMeta>;\n attachment: AssistantApiField<AttachmentClientApi, AttachmentMeta>;\n\n subscribe(listener: () => void): Unsubscribe;\n flushSync(): void;\n\n on<TEvent extends AssistantEvent>(\n event: AssistantEventSelector<TEvent>,\n callback: AssistantEventCallback<TEvent>,\n ): Unsubscribe;\n\n // temp\n registerModelContextProvider(provider: ModelContextProvider): void;\n /** @internal */\n __internal_getRuntime?(): AssistantRuntime;\n};\n\nexport const createAssistantApiField = <\n TApi,\n TMeta extends { source: any; query: any },\n>(\n config: {\n get: () => TApi;\n } & (TMeta | { source: null; query: Record<string, never> }),\n): AssistantApiField<TApi, TMeta> => {\n const fn = config.get as AssistantApiField<TApi, TMeta>;\n fn.source = config.source;\n fn.query = config.query;\n return fn;\n};\n\nconst NO_OP_FN = () => () => {};\n\nconst AssistantApiContext = createContext<AssistantApi>({\n threads: createAssistantApiField({\n source: null,\n query: {},\n get: () => {\n throw new Error(\"Threads is only available inside <AssistantProvider />\");\n },\n }),\n toolUIs: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\"ToolUIs is only available inside <AssistantProvider />\");\n },\n }),\n threadListItem: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"ThreadListItem is only available inside <AssistantProvider />\",\n );\n },\n }),\n thread: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\"Thread is only available inside <AssistantProvider />\");\n },\n }),\n composer: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"Composer is only available inside <AssistantProvider />\",\n );\n },\n }),\n message: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"Message is only available inside <ThreadPrimitive.Messages />\",\n );\n },\n }),\n part: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"Part is only available inside <MessagePrimitive.Parts />\",\n );\n },\n }),\n attachment: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"Attachment is only available inside <MessagePrimitive.Attachments /> or <ComposerPrimitive.Attachments />\",\n );\n },\n }),\n\n subscribe: NO_OP_FN,\n flushSync: NO_OP_FN,\n on: (selector) => {\n const { scope } = normalizeEventSelector(selector);\n throw new Error(`Event scope is not available in this component: ${scope}`);\n },\n\n registerModelContextProvider: () => {\n throw new Error(\n \"Registering model context providers is only available inside <AssistantProvider />\",\n );\n },\n});\n\nconst useAssistantApiImpl = (): AssistantApi => {\n return useContext(AssistantApiContext);\n};\n\nconst useExtendedAssistantApiImpl = (\n config: AssistantClientProps,\n): AssistantApi => {\n const api = useAssistantApiImpl();\n const api2 = useAssistantClient(config);\n const extendedApi = useMemo(() => extendApi(api, api2), [api, api2]);\n return extendedApi;\n};\n\nexport function useAssistantApi(): AssistantApi;\nexport function useAssistantApi(config: AssistantClientProps): AssistantApi;\nexport function useAssistantApi(config?: AssistantClientProps): AssistantApi {\n if (config) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useExtendedAssistantApiImpl(config);\n } else {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useAssistantApiImpl();\n }\n}\n\nconst mergeFns = <TArgs extends Array<unknown>>(\n fn1: (...args: TArgs) => void,\n fn2: (...args: TArgs) => void,\n) => {\n if (fn1 === NO_OP_FN) return fn2;\n if (fn2 === NO_OP_FN) return fn1;\n\n return (...args: TArgs) => {\n fn1(...args);\n fn2(...args);\n };\n};\n\nconst mergeFnsWithUnsubscribe = <TArgs extends Array<unknown>>(\n fn1: (...args: TArgs) => Unsubscribe,\n fn2: (...args: TArgs) => Unsubscribe,\n) => {\n if (fn1 === NO_OP_FN) return fn2;\n if (fn2 === NO_OP_FN) return fn1;\n\n return (...args: TArgs) => {\n const unsubscribe1 = fn1(...args);\n const unsubscribe2 = fn2(...args);\n\n return () => {\n unsubscribe1();\n unsubscribe2();\n };\n };\n};\n\nconst extendApi = (\n api: AssistantApi,\n api2: Partial<AssistantApi>,\n): AssistantApi => {\n const api2Subscribe = api2.subscribe;\n const api2FlushSync = api2.flushSync;\n return {\n ...api,\n ...api2,\n subscribe: mergeFnsWithUnsubscribe(\n api.subscribe,\n api2Subscribe ?? NO_OP_FN,\n ),\n flushSync: mergeFns(api.flushSync, api2FlushSync ?? NO_OP_FN),\n };\n};\n\nexport const AssistantProvider: FC<\n PropsWithChildren<{ api: Partial<AssistantApi>; devToolsVisible?: boolean }>\n> = ({ api: api2, children, devToolsVisible = true }) => {\n const api = useAssistantApi();\n const extendedApi = useMemo(() => extendApi(api, api2), [api, api2]);\n\n useEffect(() => {\n if (!devToolsVisible || !api2.subscribe) return undefined;\n return DevToolsProviderApi.register(api2);\n }, [api2, devToolsVisible]);\n\n return (\n <AssistantApiContext.Provider value={extendedApi}>\n {/* TODO temporarily allow accessing viewport state from outside the viewport */}\n {/* TODO figure out if this behavior should be deprecated, since it is quite hacky */}\n <ThreadViewportProvider>{children}</ThreadViewportProvider>\n </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;AACF;AAEA,IAAM,0BAA0B,CAC9B,KACA,QACG;AACH,MAAI,QAAQ,SAAU,QAAO;AAC7B,MAAI,QAAQ,SAAU,QAAO;AAE7B,SAAO,IAAI,SAAgB;AACzB,UAAM,eAAe,IAAI,GAAG,IAAI;AAChC,UAAM,eAAe,IAAI,GAAG,IAAI;AAEhC,WAAO,MAAM;AACX,mBAAa;AACb,mBAAa;AAAA,IACf;AAAA,EACF;AACF;AAEA,IAAM,YAAY,CAChB,KACA,SACiB;AACjB,QAAM,gBAAgB,KAAK;AAC3B,QAAM,gBAAgB,KAAK;AAC3B,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,IACH,WAAW;AAAA,MACT,IAAI;AAAA,MACJ,iBAAiB;AAAA,IACnB;AAAA,IACA,WAAW,SAAS,IAAI,WAAW,iBAAiB,QAAQ;AAAA,EAC9D;AACF;AAEO,IAAM,oBAET,CAAC,EAAE,KAAK,MAAM,UAAU,kBAAkB,KAAK,MAAM;AACvD,QAAM,MAAM,gBAAgB;AAC5B,QAAM,cAAc,QAAQ,MAAM,UAAU,KAAK,IAAI,GAAG,CAAC,KAAK,IAAI,CAAC;AAEnE,YAAU,MAAM;AACd,QAAI,CAAC,mBAAmB,CAAC,KAAK,UAAW,QAAO;AAChD,WAAO,oBAAoB,SAAS,IAAI;AAAA,EAC1C,GAAG,CAAC,MAAM,eAAe,CAAC;AAE1B,SACE,oBAAC,oBAAoB,UAApB,EAA6B,OAAO,aAGnC,8BAAC,0BAAwB,UAAS,GACpC;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/context/react/AssistantApiContext.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n FC,\n PropsWithChildren,\n useContext,\n useMemo,\n useEffect,\n} from \"react\";\nimport { useResource } from \"@assistant-ui/tap/react\";\n\nimport { ToolUIApi, ToolUIState, ToolUIMeta } from \"../../client/types/ToolUI\";\nimport {\n MessageClientApi,\n MessageClientState,\n} from \"../../client/types/Message\";\nimport {\n ThreadListItemClientApi,\n ThreadListItemClientState,\n} from \"../../client/types/ThreadListItem\";\nimport {\n MessagePartClientApi,\n MessagePartClientState,\n} from \"../../client/types/Part\";\nimport { ThreadClientApi, ThreadClientState } from \"../../client/types/Thread\";\nimport {\n ComposerClientApi,\n ComposerClientState,\n} from \"../../client/types/Composer\";\nimport {\n AttachmentClientApi,\n AttachmentClientState,\n} from \"../../client/types/Attachment\";\nimport { Unsubscribe } from \"@assistant-ui/tap\";\nimport {\n AssistantEvent,\n AssistantEventCallback,\n AssistantEventSelector,\n normalizeEventSelector,\n} from \"../../types/EventTypes\";\nimport {\n ThreadListClientApi,\n ThreadListClientState,\n} from \"../../client/types/ThreadList\";\nimport { ThreadViewportProvider } from \"../providers/ThreadViewportProvider\";\nimport { DevToolsProviderApi } from \"../../devtools/DevToolsHooks\";\nimport {\n AssistantClientProps,\n useAssistantClient,\n} from \"../../client/AssistantClient\";\nimport { ToolsApi, ToolsMeta } from \"../../client/types/Tools\";\nimport {\n ModelContextApi,\n ModelContextMeta,\n} from \"../../client/types/ModelContext\";\nimport {\n DerivedScopes,\n DerivedScopesInput,\n} from \"../../utils/tap-store/derived-scopes\";\n\nexport type AssistantState = {\n readonly threads: ThreadListClientState;\n readonly toolUIs: ToolUIState;\n\n readonly threadListItem: ThreadListItemClientState;\n readonly thread: ThreadClientState;\n readonly composer: ComposerClientState;\n readonly message: MessageClientState;\n readonly part: MessagePartClientState;\n readonly attachment: AttachmentClientState;\n};\n\nexport type AssistantApiField<\n TApi,\n TMeta extends { source: string | null; query: any },\n> = (() => TApi) & (TMeta | { source: null; query: Record<string, never> });\n\n// Meta types for each API method\ntype ThreadsMeta = {\n source: \"root\";\n query: Record<string, never>;\n};\n\ntype ThreadListItemMeta = {\n source: \"threads\";\n query:\n | { type: \"index\"; index: number; archived: boolean }\n | { type: \"main\" }\n | { type: \"id\"; id: string };\n};\n\ntype ThreadMeta = {\n source: \"threads\";\n query: { type: \"main\" };\n};\n\ntype ComposerMeta = {\n source: \"message\" | \"thread\";\n query: Record<string, never>;\n};\n\ntype MessageMeta =\n | {\n source: \"thread\";\n query: { type: \"index\"; index: number };\n }\n | {\n source: \"root\";\n query: Record<string, never>;\n };\n\ntype PartMeta = {\n source: \"message\" | \"root\";\n query: { type: \"index\"; index: number } | Record<string, never>;\n};\n\ntype AttachmentMeta = {\n source: \"message\" | \"composer\";\n query: { type: \"index\"; index: number };\n};\n\nexport type AssistantApi = {\n threads: AssistantApiField<ThreadListClientApi, ThreadsMeta>;\n toolUIs: AssistantApiField<ToolUIApi, ToolUIMeta>;\n tools: AssistantApiField<ToolsApi, ToolsMeta>;\n modelContext: AssistantApiField<ModelContextApi, ModelContextMeta>;\n threadListItem: AssistantApiField<\n ThreadListItemClientApi,\n ThreadListItemMeta\n >;\n thread: AssistantApiField<ThreadClientApi, ThreadMeta>;\n composer: AssistantApiField<ComposerClientApi, ComposerMeta>;\n message: AssistantApiField<MessageClientApi, MessageMeta>;\n part: AssistantApiField<MessagePartClientApi, PartMeta>;\n attachment: AssistantApiField<AttachmentClientApi, AttachmentMeta>;\n\n subscribe(listener: () => void): Unsubscribe;\n flushSync(): void;\n\n on<TEvent extends AssistantEvent>(\n event: AssistantEventSelector<TEvent>,\n callback: AssistantEventCallback<TEvent>,\n ): Unsubscribe;\n};\n\nexport const createAssistantApiField = <\n TApi,\n TMeta extends { source: any; query: any },\n>(\n config: {\n get: () => TApi;\n } & (TMeta | { source: null; query: Record<string, never> }),\n): AssistantApiField<TApi, TMeta> => {\n const fn = config.get as AssistantApiField<TApi, TMeta>;\n fn.source = config.source;\n fn.query = config.query;\n return fn;\n};\n\nconst NO_OP_FN = () => () => {};\n\nconst AssistantApiContext = createContext<AssistantApi>({\n threads: createAssistantApiField({\n source: null,\n query: {},\n get: () => {\n throw new Error(\"Threads is only available inside <AssistantProvider />\");\n },\n }),\n toolUIs: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\"ToolUIs is only available inside <AssistantProvider />\");\n },\n }),\n tools: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\"Tools is only available inside <AssistantProvider />\");\n },\n }),\n modelContext: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"ModelContext is only available inside <AssistantProvider />\",\n );\n },\n }),\n threadListItem: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"ThreadListItem is only available inside <AssistantProvider />\",\n );\n },\n }),\n thread: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\"Thread is only available inside <AssistantProvider />\");\n },\n }),\n composer: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"Composer is only available inside <AssistantProvider />\",\n );\n },\n }),\n message: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"Message is only available inside <ThreadPrimitive.Messages />\",\n );\n },\n }),\n part: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"Part is only available inside <MessagePrimitive.Parts />\",\n );\n },\n }),\n attachment: createAssistantApiField({\n source: null,\n query: {},\n get: (): never => {\n throw new Error(\n \"Attachment is only available inside <MessagePrimitive.Attachments /> or <ComposerPrimitive.Attachments />\",\n );\n },\n }),\n\n subscribe: NO_OP_FN,\n flushSync: NO_OP_FN,\n on: (selector) => {\n const { scope } = normalizeEventSelector(selector);\n throw new Error(`Event scope is not available in this component: ${scope}`);\n },\n});\n\nexport const useAssistantApiImpl = (): AssistantApi => {\n return useContext(AssistantApiContext);\n};\n\n/**\n * Hook to extend the current AssistantApi with additional derived scope fields and special callbacks.\n * This merges the derived fields with the existing API from context.\n * Fields are automatically memoized based on source and query changes.\n * Special callbacks (on, subscribe, flushSync) use the useEffectEvent pattern to always access latest values.\n *\n * @param scopes - Record of field names to DerivedScope resource elements, plus optional special callbacks\n * @returns The merged AssistantApi\n *\n * @example\n * ```tsx\n * const api = useExtendedAssistantApi({\n * message: DerivedScope({\n * source: \"root\",\n * query: {},\n * get: () => messageApi,\n * }),\n * on: (selector, callback) => {\n * // Custom event filtering logic\n * },\n * });\n * ```\n */\nexport const useExtendedAssistantApi = (\n scopes: DerivedScopesInput,\n): AssistantApi => {\n const baseApi = useAssistantApiImpl();\n const partialApi = useResource(DerivedScopes(scopes));\n return useMemo(() => extendApi(baseApi, partialApi), [baseApi, partialApi]);\n};\n\nconst useExtendedAssistantApiImpl = (\n config: AssistantClientProps,\n): AssistantApi => {\n return useAssistantClient(config);\n};\n\nexport function useAssistantApi(): AssistantApi;\nexport function useAssistantApi(config: AssistantClientProps): AssistantApi;\nexport function useAssistantApi(config?: AssistantClientProps): AssistantApi {\n if (config) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useExtendedAssistantApiImpl(config);\n } else {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useAssistantApiImpl();\n }\n}\n\nconst mergeFns = <TArgs extends Array<unknown>>(\n fn1: (...args: TArgs) => void,\n fn2: (...args: TArgs) => void,\n) => {\n if (fn1 === NO_OP_FN) return fn2;\n if (fn2 === NO_OP_FN) return fn1;\n\n return (...args: TArgs) => {\n fn1(...args);\n fn2(...args);\n };\n};\n\nconst mergeFnsWithUnsubscribe = <TArgs extends Array<unknown>>(\n fn1: (...args: TArgs) => Unsubscribe,\n fn2: (...args: TArgs) => Unsubscribe,\n) => {\n if (fn1 === NO_OP_FN) return fn2;\n if (fn2 === NO_OP_FN) return fn1;\n\n return (...args: TArgs) => {\n const unsubscribe1 = fn1(...args);\n const unsubscribe2 = fn2(...args);\n\n return () => {\n unsubscribe1();\n unsubscribe2();\n };\n };\n};\n\nexport const extendApi = (\n api: AssistantApi,\n api2: Partial<AssistantApi>,\n): AssistantApi => {\n const api2Subscribe = api2.subscribe;\n const api2FlushSync = api2.flushSync;\n return {\n ...api,\n ...api2,\n subscribe: mergeFnsWithUnsubscribe(\n api.subscribe,\n api2Subscribe ?? NO_OP_FN,\n ),\n flushSync: mergeFns(api.flushSync, api2FlushSync ?? NO_OP_FN),\n };\n};\n\nexport const AssistantProvider: FC<\n PropsWithChildren<{ api: AssistantApi; devToolsVisible?: boolean }>\n> = ({ api, children, devToolsVisible = true }) => {\n useEffect(() => {\n if (!devToolsVisible || !api.subscribe) return undefined;\n return DevToolsProviderApi.register(api);\n }, [api, devToolsVisible]);\n\n return (\n <AssistantApiContext.Provider value={api}>\n {/* TODO temporarily allow accessing viewport state from outside the viewport */}\n {/* TODO figure out if this behavior should be deprecated, since it is quite hacky */}\n <ThreadViewportProvider>{children}</ThreadViewportProvider>\n </AssistantApiContext.Provider>\n );\n};\n"],"mappings":";;;AAEA;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAyB5B;AAAA,EAIE;AAAA,OACK;AAKP,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC;AAAA,EAEE;AAAA,OACK;AAMP;AAAA,EACE;AAAA,OAEK;AAoTD;AA7NC,IAAM,0BAA0B,CAIrC,WAGmC;AACnC,QAAM,KAAK,OAAO;AAClB,KAAG,SAAS,OAAO;AACnB,KAAG,QAAQ,OAAO;AAClB,SAAO;AACT;AAEA,IAAM,WAAW,MAAM,MAAM;AAAC;AAE9B,IAAM,sBAAsB,cAA4B;AAAA,EACtD,SAAS,wBAAwB;AAAA,IAC/B,QAAQ;AAAA,IACR,OAAO,CAAC;AAAA,IACR,KAAK,MAAM;AACT,YAAM,IAAI,MAAM,wDAAwD;AAAA,IAC1E;AAAA,EACF,CAAC;AAAA,EACD,SAAS,wBAAwB;AAAA,IAC/B,QAAQ;AAAA,IACR,OAAO,CAAC;AAAA,IACR,KAAK,MAAa;AAChB,YAAM,IAAI,MAAM,wDAAwD;AAAA,IAC1E;AAAA,EACF,CAAC;AAAA,EACD,OAAO,wBAAwB;AAAA,IAC7B,QAAQ;AAAA,IACR,OAAO,CAAC;AAAA,IACR,KAAK,MAAa;AAChB,YAAM,IAAI,MAAM,sDAAs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EAC9D;AACF;AAEO,IAAM,oBAET,CAAC,EAAE,KAAK,UAAU,kBAAkB,KAAK,MAAM;AACjD,YAAU,MAAM;AACd,QAAI,CAAC,mBAAmB,CAAC,IAAI,UAAW,QAAO;AAC/C,WAAO,oBAAoB,SAAS,GAAG;AAAA,EACzC,GAAG,CAAC,KAAK,eAAe,CAAC;AAEzB,SACE,oBAAC,oBAAoB,UAApB,EAA6B,OAAO,KAGnC,8BAAC,0BAAwB,UAAS,GACpC;AAEJ;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { useAssistantApi, type AssistantApi } from "./AssistantApiContext";
|
|
1
|
+
export { useAssistantApi, useExtendedAssistantApi, type AssistantApi, } from "./AssistantApiContext";
|
|
2
2
|
export { useAssistantState } from "./hooks/useAssistantState";
|
|
3
3
|
export { useAssistantEvent } from "./hooks/useAssistantEvent";
|
|
4
4
|
export { useThreadViewport, useThreadViewportStore, } from "./ThreadViewportContext";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/react/index.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/react/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,KAAK,YAAY,GAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,mBAAmB,EACnB,aAAa,GACd,MAAM,6CAA6C,CAAC;AAErD,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,kCAAkC,EAClC,2BAA2B,EAC3B,gCAAgC,EAChC,yBAAyB,EACzB,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EACL,kBAAkB,EAClB,WAAW,GACZ,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,UAAU,GACX,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EACL,qBAAqB,EACrB,cAAc,GACf,MAAM,+CAA+C,CAAC;AAEvD,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EACL,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,kDAAkD,CAAC;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/context/react/index.ts
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
useAssistantApi,
|
|
6
|
+
useExtendedAssistantApi
|
|
7
|
+
} from "./AssistantApiContext.js";
|
|
5
8
|
import { useAssistantState } from "./hooks/useAssistantState.js";
|
|
6
9
|
import { useAssistantEvent } from "./hooks/useAssistantEvent.js";
|
|
7
10
|
import {
|
|
@@ -59,6 +62,7 @@ export {
|
|
|
59
62
|
useEditComposer,
|
|
60
63
|
useEditComposerAttachment,
|
|
61
64
|
useEditComposerAttachmentRuntime,
|
|
65
|
+
useExtendedAssistantApi,
|
|
62
66
|
useMessage,
|
|
63
67
|
useMessageAttachment,
|
|
64
68
|
useMessageAttachmentRuntime,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/context/react/index.ts"],"sourcesContent":["\"use client\";\n// TODO createContextStoreHook does not work well with server-side nextjs bundler\n// use client necessary here for now\n\nexport {
|
|
1
|
+
{"version":3,"sources":["../../../src/context/react/index.ts"],"sourcesContent":["\"use client\";\n// TODO createContextStoreHook does not work well with server-side nextjs bundler\n// use client necessary here for now\n\nexport {\n useAssistantApi,\n useExtendedAssistantApi,\n type AssistantApi,\n} from \"./AssistantApiContext\";\nexport { useAssistantState } from \"./hooks/useAssistantState\";\nexport { useAssistantEvent } from \"./hooks/useAssistantEvent\";\n\nexport {\n useThreadViewport,\n useThreadViewportStore,\n} from \"./ThreadViewportContext\";\n\nexport {\n useAssistantRuntime,\n useThreadList,\n} from \"../../legacy-runtime/hooks/AssistantContext\";\n\nexport {\n useAttachmentRuntime,\n useAttachment,\n useThreadComposerAttachmentRuntime,\n useThreadComposerAttachment,\n useEditComposerAttachmentRuntime,\n useEditComposerAttachment,\n useMessageAttachment,\n useMessageAttachmentRuntime,\n} from \"../../legacy-runtime/hooks/AttachmentContext\";\n\nexport {\n useComposerRuntime,\n useComposer,\n} from \"../../legacy-runtime/hooks/ComposerContext\";\n\nexport {\n useMessageRuntime,\n useEditComposer,\n useMessage,\n} from \"../../legacy-runtime/hooks/MessageContext\";\n\nexport {\n useMessagePartRuntime,\n useMessagePart,\n} from \"../../legacy-runtime/hooks/MessagePartContext\";\n\nexport {\n useThreadRuntime,\n useThread,\n useThreadComposer,\n useThreadModelContext,\n} from \"../../legacy-runtime/hooks/ThreadContext\";\n\nexport {\n useThreadListItemRuntime,\n useThreadListItem,\n} from \"../../legacy-runtime/hooks/ThreadListItemContext\";\n\nexport { AssistantProvider } from \"./AssistantApiContext\";\n"],"mappings":";;;AAIA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,yBAAyB;AAClC,SAAS,yBAAyB;AAElC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,yBAAyB;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantRuntimeProvider.d.ts","sourceRoot":"","sources":["../../src/legacy-runtime/AssistantRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAQ,iBAAiB,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"AssistantRuntimeProvider.d.ts","sourceRoot":"","sources":["../../src/legacy-runtime/AssistantRuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAQ,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAKpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAI9D,yBAAiB,iBAAiB,CAAC;IACjC,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC;;WAEG;QACH,OAAO,EAAE,gBAAgB,CAAC;KAC3B,CAAC,CAAC;CACJ;AAMD,eAAO,MAAM,4BAA4B,EAAE,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAiBpE,CAAC;AAEF,eAAO,MAAM,wBAAwB,+DAAqC,CAAC"}
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
// src/legacy-runtime/AssistantRuntimeProvider.tsx
|
|
4
4
|
import { memo } from "react";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import {
|
|
6
|
+
AssistantProvider,
|
|
7
|
+
useAssistantApi
|
|
8
|
+
} from "../context/react/AssistantApiContext.js";
|
|
9
|
+
import { RuntimeAdapter } from "./RuntimeAdapter.js";
|
|
8
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
11
|
var getRenderComponent = (runtime) => {
|
|
10
12
|
return runtime._core?.RenderComponent;
|
|
@@ -13,12 +15,8 @@ var AssistantRuntimeProviderImpl = ({
|
|
|
13
15
|
children,
|
|
14
16
|
runtime
|
|
15
17
|
}) => {
|
|
16
|
-
const api =
|
|
17
|
-
threads:
|
|
18
|
-
runtime: runtime.threads
|
|
19
|
-
}),
|
|
20
|
-
registerModelContextProvider: runtime.registerModelContextProvider,
|
|
21
|
-
__internal_runtime: runtime
|
|
18
|
+
const api = useAssistantApi({
|
|
19
|
+
threads: RuntimeAdapter(runtime)
|
|
22
20
|
});
|
|
23
21
|
const RenderComponent = getRenderComponent(runtime);
|
|
24
22
|
return /* @__PURE__ */ jsxs(AssistantProvider, { api, children: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/legacy-runtime/AssistantRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport { FC, memo, PropsWithChildren } from \"react\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/legacy-runtime/AssistantRuntimeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport { FC, memo, PropsWithChildren } from \"react\";\nimport {\n AssistantProvider,\n useAssistantApi,\n} from \"../context/react/AssistantApiContext\";\nimport { AssistantRuntime } from \"./runtime/AssistantRuntime\";\nimport { AssistantRuntimeCore } from \"./runtime-cores/core/AssistantRuntimeCore\";\nimport { RuntimeAdapter } from \"./RuntimeAdapter\";\n\nexport namespace AssistantProvider {\n export type Props = PropsWithChildren<{\n /**\n * The runtime to provide to the rest of your app.\n */\n runtime: AssistantRuntime;\n }>;\n}\n\nconst getRenderComponent = (runtime: AssistantRuntime) => {\n return (runtime as { _core?: AssistantRuntimeCore })._core?.RenderComponent;\n};\n\nexport const AssistantRuntimeProviderImpl: FC<AssistantProvider.Props> = ({\n children,\n runtime,\n}) => {\n const api = useAssistantApi({\n threads: RuntimeAdapter(runtime),\n });\n\n const RenderComponent = getRenderComponent(runtime);\n\n return (\n <AssistantProvider api={api}>\n {RenderComponent && <RenderComponent />}\n\n {children}\n </AssistantProvider>\n );\n};\n\nexport const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);\n"],"mappings":";;;AAEA,SAAa,YAA+B;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAGP,SAAS,sBAAsB;AA0B3B,SACsB,KADtB;AAfJ,IAAM,qBAAqB,CAAC,YAA8B;AACxD,SAAQ,QAA6C,OAAO;AAC9D;AAEO,IAAM,+BAA4D,CAAC;AAAA,EACxE;AAAA,EACA;AACF,MAAM;AACJ,QAAM,MAAM,gBAAgB;AAAA,IAC1B,SAAS,eAAe,OAAO;AAAA,EACjC,CAAC;AAED,QAAM,kBAAkB,mBAAmB,OAAO;AAElD,SACE,qBAAC,qBAAkB,KAChB;AAAA,uBAAmB,oBAAC,mBAAgB;AAAA,IAEpC;AAAA,KACH;AAEJ;AAEO,IAAM,2BAA2B,KAAK,4BAA4B;","names":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AssistantRuntime } from "./runtime/AssistantRuntime";
|
|
2
|
+
export declare const RuntimeAdapter: import("@assistant-ui/tap").ResourceElementConstructor<{
|
|
3
|
+
key: string | undefined;
|
|
4
|
+
state: any;
|
|
5
|
+
api: import("../client/types/ThreadList").ThreadListClientApi;
|
|
6
|
+
}, AssistantRuntime>;
|
|
7
|
+
//# sourceMappingURL=RuntimeAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RuntimeAdapter.d.ts","sourceRoot":"","sources":["../../src/legacy-runtime/RuntimeAdapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAInE,eAAO,MAAM,cAAc;;;;oBAazB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/legacy-runtime/RuntimeAdapter.ts
|
|
2
|
+
import { resource, tapEffect, tapInlineResource } from "@assistant-ui/tap";
|
|
3
|
+
import { ThreadListClient } from "./client/ThreadListRuntimeClient.js";
|
|
4
|
+
import { tapModelContext } from "../client/ModelContext.js";
|
|
5
|
+
var RuntimeAdapter = resource((runtime) => {
|
|
6
|
+
const modelContext = tapModelContext();
|
|
7
|
+
tapEffect(() => {
|
|
8
|
+
return runtime.registerModelContextProvider(modelContext);
|
|
9
|
+
}, [runtime, modelContext]);
|
|
10
|
+
return tapInlineResource(
|
|
11
|
+
ThreadListClient({
|
|
12
|
+
runtime: runtime.threads,
|
|
13
|
+
__internal_assistantRuntime: runtime
|
|
14
|
+
})
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
export {
|
|
18
|
+
RuntimeAdapter
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=RuntimeAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/legacy-runtime/RuntimeAdapter.ts"],"sourcesContent":["import { resource, tapEffect, tapInlineResource } from \"@assistant-ui/tap\";\nimport type { AssistantRuntime } from \"./runtime/AssistantRuntime\";\nimport { ThreadListClient } from \"./client/ThreadListRuntimeClient\";\nimport { tapModelContext } from \"../client/ModelContext\";\n\nexport const RuntimeAdapter = resource((runtime: AssistantRuntime) => {\n const modelContext = tapModelContext();\n\n tapEffect(() => {\n return runtime.registerModelContextProvider(modelContext);\n }, [runtime, modelContext]);\n\n return tapInlineResource(\n ThreadListClient({\n runtime: runtime.threads,\n __internal_assistantRuntime: runtime,\n }),\n );\n});\n"],"mappings":";AAAA,SAAS,UAAU,WAAW,yBAAyB;AAEvD,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAEzB,IAAM,iBAAiB,SAAS,CAAC,YAA8B;AACpE,QAAM,eAAe,gBAAgB;AAErC,YAAU,MAAM;AACd,WAAO,QAAQ,6BAA6B,YAAY;AAAA,EAC1D,GAAG,CAAC,SAAS,YAAY,CAAC;AAE1B,SAAO;AAAA,IACL,iBAAiB;AAAA,MACf,SAAS,QAAQ;AAAA,MACjB,6BAA6B;AAAA,IAC/B,CAAC;AAAA,EACH;AACF,CAAC;","names":[]}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { ThreadListRuntime } from "../runtime/ThreadListRuntime";
|
|
2
2
|
import { ThreadListClientApi } from "../../client/types/ThreadList";
|
|
3
|
+
import type { AssistantRuntime } from "../runtime/AssistantRuntime";
|
|
3
4
|
export declare const ThreadListClient: import("@assistant-ui/tap").ResourceElementConstructor<{
|
|
4
5
|
key: string | undefined;
|
|
5
6
|
state: any;
|
|
6
7
|
api: ThreadListClientApi;
|
|
7
8
|
}, {
|
|
8
9
|
runtime: ThreadListRuntime;
|
|
10
|
+
__internal_assistantRuntime: AssistantRuntime;
|
|
9
11
|
}>;
|
|
10
12
|
//# sourceMappingURL=ThreadListRuntimeClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThreadListRuntimeClient.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/client/ThreadListRuntimeClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAKjE,OAAO,EAEL,mBAAmB,EACpB,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"ThreadListRuntimeClient.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/client/ThreadListRuntimeClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAKjE,OAAO,EAEL,mBAAmB,EACpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAgBpE,eAAO,MAAM,gBAAgB;;;;;aAKhB,iBAAiB;iCACG,gBAAgB;EA4DhD,CAAC"}
|
|
@@ -19,7 +19,10 @@ var ThreadListItemClientById = resource(
|
|
|
19
19
|
}
|
|
20
20
|
);
|
|
21
21
|
var ThreadListClient = resource(
|
|
22
|
-
({
|
|
22
|
+
({
|
|
23
|
+
runtime,
|
|
24
|
+
__internal_assistantRuntime
|
|
25
|
+
}) => {
|
|
23
26
|
const runtimeState = tapSubscribable(runtime);
|
|
24
27
|
const main = tapInlineResource(
|
|
25
28
|
ThreadClient({
|
|
@@ -61,7 +64,8 @@ var ThreadListClient = resource(
|
|
|
61
64
|
},
|
|
62
65
|
switchToNewThread: () => {
|
|
63
66
|
runtime.switchToNewThread();
|
|
64
|
-
}
|
|
67
|
+
},
|
|
68
|
+
__internal_getAssistantRuntime: () => __internal_assistantRuntime
|
|
65
69
|
});
|
|
66
70
|
}
|
|
67
71
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/legacy-runtime/client/ThreadListRuntimeClient.ts"],"sourcesContent":["import { tapApi } from \"../../utils/tap-store\";\nimport { resource, tapInlineResource, tapMemo } from \"@assistant-ui/tap\";\nimport { ThreadListRuntime } from \"../runtime/ThreadListRuntime\";\nimport { tapSubscribable } from \"../util-hooks/tapSubscribable\";\nimport { ThreadListItemClient } from \"./ThreadListItemRuntimeClient\";\nimport { ThreadClient } from \"./ThreadRuntimeClient\";\nimport { tapLookupResources } from \"../../client/util-hooks/tapLookupResources\";\nimport {\n ThreadListClientState,\n ThreadListClientApi,\n} from \"../../client/types/ThreadList\";\n\nconst ThreadListItemClientById = resource(\n ({ runtime, id }: { runtime: ThreadListRuntime; id: string }) => {\n const threadListItemRuntime = tapMemo(\n () => runtime.getItemById(id),\n [runtime, id],\n );\n return tapInlineResource(\n ThreadListItemClient({\n runtime: threadListItemRuntime,\n }),\n );\n },\n);\n\nexport const ThreadListClient = resource(\n ({
|
|
1
|
+
{"version":3,"sources":["../../../src/legacy-runtime/client/ThreadListRuntimeClient.ts"],"sourcesContent":["import { tapApi } from \"../../utils/tap-store\";\nimport { resource, tapInlineResource, tapMemo } from \"@assistant-ui/tap\";\nimport { ThreadListRuntime } from \"../runtime/ThreadListRuntime\";\nimport { tapSubscribable } from \"../util-hooks/tapSubscribable\";\nimport { ThreadListItemClient } from \"./ThreadListItemRuntimeClient\";\nimport { ThreadClient } from \"./ThreadRuntimeClient\";\nimport { tapLookupResources } from \"../../client/util-hooks/tapLookupResources\";\nimport {\n ThreadListClientState,\n ThreadListClientApi,\n} from \"../../client/types/ThreadList\";\nimport type { AssistantRuntime } from \"../runtime/AssistantRuntime\";\n\nconst ThreadListItemClientById = resource(\n ({ runtime, id }: { runtime: ThreadListRuntime; id: string }) => {\n const threadListItemRuntime = tapMemo(\n () => runtime.getItemById(id),\n [runtime, id],\n );\n return tapInlineResource(\n ThreadListItemClient({\n runtime: threadListItemRuntime,\n }),\n );\n },\n);\n\nexport const ThreadListClient = resource(\n ({\n runtime,\n __internal_assistantRuntime,\n }: {\n runtime: ThreadListRuntime;\n __internal_assistantRuntime: AssistantRuntime;\n }) => {\n const runtimeState = tapSubscribable(runtime);\n\n const main = tapInlineResource(\n ThreadClient({\n runtime: runtime.main,\n }),\n );\n\n const threadItems = tapLookupResources(\n Object.keys(runtimeState.threadItems).map((id) =>\n ThreadListItemClientById({ runtime, id }, { key: id }),\n ),\n );\n\n const state = tapMemo<ThreadListClientState>(() => {\n return {\n mainThreadId: runtimeState.mainThreadId,\n newThreadId: runtimeState.newThread ?? null,\n isLoading: runtimeState.isLoading,\n threadIds: runtimeState.threads,\n archivedThreadIds: runtimeState.archivedThreads,\n threadItems: threadItems.state,\n\n main: main.state,\n };\n }, [runtimeState, threadItems.state, main.state]);\n\n return tapApi<ThreadListClientApi>({\n getState: () => state,\n\n thread: () => main.api,\n\n item: (threadIdOrOptions) => {\n if (threadIdOrOptions === \"main\") {\n return threadItems.api({ key: state.mainThreadId });\n }\n\n if (\"id\" in threadIdOrOptions) {\n return threadItems.api({ key: threadIdOrOptions.id });\n }\n\n const { index, archived = false } = threadIdOrOptions;\n const id = archived\n ? state.archivedThreadIds[index]!\n : state.threadIds[index]!;\n return threadItems.api({ key: id });\n },\n\n switchToThread: (threadId) => {\n runtime.switchToThread(threadId);\n },\n switchToNewThread: () => {\n runtime.switchToNewThread();\n },\n\n __internal_getAssistantRuntime: () => __internal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AO,YAAY,IAAI,EAAE,KAAK,MAAM,aAAa,CAAC;AAAA,QACpD;AAEA,YAAI,QAAQ,mBAAmB;AAC7B,iBAAO,YAAY,IAAI,EAAE,KAAK,kBAAkB,GAAG,CAAC;AAAA,QACtD;AAEA,cAAM,EAAE,OAAO,WAAW,MAAM,IAAI;AACpC,cAAM,KAAK,WACP,MAAM,kBAAkB,KAAK,IAC7B,MAAM,UAAU,KAAK;AACzB,eAAO,YAAY,IAAI,EAAE,KAAK,GAAG,CAAC;AAAA,MACpC;AAAA,MAEA,gBAAgB,CAAC,aAAa;AAC5B,gBAAQ,eAAe,QAAQ;AAAA,MACjC;AAAA,MACA,mBAAmB,MAAM;AACvB,gBAAQ,kBAAkB;AAAA,MAC5B;AAAA,MAEA,gCAAgC,MAAM;AAAA,IACxC,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AssistantRuntime } from "../runtime/AssistantRuntime";
|
|
2
2
|
/**
|
|
3
|
+
* @deprecated Use `useAssistantApi()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
|
|
4
|
+
*
|
|
3
5
|
* Hook to access the AssistantRuntime from the current context.
|
|
4
6
|
*
|
|
5
7
|
* The AssistantRuntime provides access to the top-level assistant state and actions,
|
|
@@ -11,13 +13,21 @@ import { AssistantRuntime } from "../runtime/AssistantRuntime";
|
|
|
11
13
|
*
|
|
12
14
|
* @example
|
|
13
15
|
* ```tsx
|
|
16
|
+
* // Before:
|
|
14
17
|
* function MyComponent() {
|
|
15
18
|
* const runtime = useAssistantRuntime();
|
|
16
|
-
*
|
|
17
19
|
* const handleNewThread = () => {
|
|
18
20
|
* runtime.switchToNewThread();
|
|
19
21
|
* };
|
|
22
|
+
* return <button onClick={handleNewThread}>New Thread</button>;
|
|
23
|
+
* }
|
|
20
24
|
*
|
|
25
|
+
* // After:
|
|
26
|
+
* function MyComponent() {
|
|
27
|
+
* const api = useAssistantApi();
|
|
28
|
+
* const handleNewThread = () => {
|
|
29
|
+
* api.threads().switchToNewThread();
|
|
30
|
+
* };
|
|
21
31
|
* return <button onClick={handleNewThread}>New Thread</button>;
|
|
22
32
|
* }
|
|
23
33
|
* ```
|
|
@@ -28,6 +38,9 @@ export declare function useAssistantRuntime(options?: {
|
|
|
28
38
|
export declare function useAssistantRuntime(options?: {
|
|
29
39
|
optional?: boolean | undefined;
|
|
30
40
|
}): AssistantRuntime | null;
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Use `useAssistantState(({ threads }) => threads)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
|
|
43
|
+
*/
|
|
31
44
|
export declare const useThreadList: {
|
|
32
45
|
(): import("../runtime").ThreadListState;
|
|
33
46
|
<TSelected>(selector: (state: import("../runtime").ThreadListState) => TSelected): TSelected;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/AssistantContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAI/D
|
|
1
|
+
{"version":3,"file":"AssistantContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/AssistantContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAI/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE;IAC5C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,gBAAgB,CAAC;AACrB,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE;IAC5C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,gBAAgB,GAAG,IAAI,CAAC;AAkB5B;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;CAAkD,CAAC"}
|
|
@@ -5,7 +5,7 @@ import { useAssistantApi } from "../../context/react/AssistantApiContext.js";
|
|
|
5
5
|
import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime.js";
|
|
6
6
|
function useAssistantRuntime(options) {
|
|
7
7
|
const api = useAssistantApi();
|
|
8
|
-
const runtime = api.
|
|
8
|
+
const runtime = api.threads().__internal_getAssistantRuntime?.() ?? null;
|
|
9
9
|
if (!runtime && !options?.optional) {
|
|
10
10
|
throw new Error("AssistantRuntime is not available");
|
|
11
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/legacy-runtime/hooks/AssistantContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useAssistantApi } from \"../../context/react/AssistantApiContext\";\nimport { AssistantRuntime } from \"../runtime/AssistantRuntime\";\nimport type { ThreadListRuntime } from \"../runtime/ThreadListRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\n\n/**\n * Hook to access the AssistantRuntime from the current context.\n *\n * The AssistantRuntime provides access to the top-level assistant state and actions,\n * including thread management, tool registration, and configuration.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The AssistantRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const runtime = useAssistantRuntime();\n
|
|
1
|
+
{"version":3,"sources":["../../../src/legacy-runtime/hooks/AssistantContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useAssistantApi } from \"../../context/react/AssistantApiContext\";\nimport { AssistantRuntime } from \"../runtime/AssistantRuntime\";\nimport type { ThreadListRuntime } from \"../runtime/ThreadListRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\n\n/**\n * @deprecated Use `useAssistantApi()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n *\n * Hook to access the AssistantRuntime from the current context.\n *\n * The AssistantRuntime provides access to the top-level assistant state and actions,\n * including thread management, tool registration, and configuration.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The AssistantRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * // Before:\n * function MyComponent() {\n * const runtime = useAssistantRuntime();\n * const handleNewThread = () => {\n * runtime.switchToNewThread();\n * };\n * return <button onClick={handleNewThread}>New Thread</button>;\n * }\n *\n * // After:\n * function MyComponent() {\n * const api = useAssistantApi();\n * const handleNewThread = () => {\n * api.threads().switchToNewThread();\n * };\n * return <button onClick={handleNewThread}>New Thread</button>;\n * }\n * ```\n */\nexport function useAssistantRuntime(options?: {\n optional?: false | undefined;\n}): AssistantRuntime;\nexport function useAssistantRuntime(options?: {\n optional?: boolean | undefined;\n}): AssistantRuntime | null;\nexport function useAssistantRuntime(options?: {\n optional?: boolean | undefined;\n}) {\n const api = useAssistantApi();\n const runtime = api.threads().__internal_getAssistantRuntime?.() ?? null;\n\n if (!runtime && !options?.optional) {\n throw new Error(\"AssistantRuntime is not available\");\n }\n\n return runtime;\n}\n\nconst useThreadListRuntime = (opt: {\n optional: boolean | undefined;\n}): ThreadListRuntime | null => useAssistantRuntime(opt)?.threads ?? null;\n\n/**\n * @deprecated Use `useAssistantState(({ threads }) => threads)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n */\nexport const useThreadList = createStateHookForRuntime(useThreadListRuntime);\n"],"mappings":";;;AAEA,SAAS,uBAAuB;AAGhC,SAAS,iCAAiC;AAyCnC,SAAS,oBAAoB,SAEjC;AACD,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU,IAAI,QAAQ,EAAE,iCAAiC,KAAK;AAEpE,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AAEA,SAAO;AACT;AAEA,IAAM,uBAAuB,CAAC,QAEE,oBAAoB,GAAG,GAAG,WAAW;AAK9D,IAAM,gBAAgB,0BAA0B,oBAAoB;","names":[]}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { AttachmentRuntime } from "../runtime/AttachmentRuntime";
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Use `useAssistantApi()` with `api.attachment()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
|
|
4
|
+
*/
|
|
2
5
|
export declare function useAttachmentRuntime(options?: {
|
|
3
6
|
optional?: false | undefined;
|
|
4
7
|
}): AttachmentRuntime;
|
|
@@ -23,6 +26,9 @@ export declare function useMessageAttachmentRuntime(options?: {
|
|
|
23
26
|
export declare function useMessageAttachmentRuntime(options?: {
|
|
24
27
|
optional?: boolean | undefined;
|
|
25
28
|
}): AttachmentRuntime<"message"> | null;
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated Use `useAssistantState(({ attachment }) => attachment)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
|
|
31
|
+
*/
|
|
26
32
|
export declare const useAttachment: {
|
|
27
33
|
(): import("../runtime").AttachmentState & {
|
|
28
34
|
source: "thread-composer" | "edit-composer" | "message";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttachmentContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/AttachmentContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAIjE,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE;IAC7C,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,iBAAiB,CAAC;AACtB,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE;IAC7C,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,iBAAiB,GAAG,IAAI,CAAC;AAgB7B,wBAAgB,kCAAkC,CAAC,OAAO,CAAC,EAAE;IAC3D,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;CAC9B,GAAG,iBAAiB,CAAC,iBAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAErC,CAAC;AACF,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAEhC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/legacy-runtime/hooks/AttachmentContext.ts"],"sourcesContent":["\"use client\";\n\nimport { AttachmentRuntime } from \"../runtime/AttachmentRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\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 api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.attachment.source\n ? (api.attachment().__internal_getRuntime?.() ?? null)\n : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"AttachmentRuntime is not available\");\n }\n return runtime;\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":";;;AAGA,SAAS,iCAAiC;AAC1C,SAAS,iBAAiB,yBAAyB;
|
|
1
|
+
{"version":3,"sources":["../../../src/legacy-runtime/hooks/AttachmentContext.ts"],"sourcesContent":["\"use client\";\n\nimport { AttachmentRuntime } from \"../runtime/AttachmentRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\n\n/**\n * @deprecated Use `useAssistantApi()` with `api.attachment()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\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 api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.attachment.source\n ? (api.attachment().__internal_getRuntime?.() ?? null)\n : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"AttachmentRuntime is not available\");\n }\n return runtime;\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\n/**\n * @deprecated Use `useAssistantState(({ attachment }) => attachment)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\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":";;;AAGA,SAAS,iCAAiC;AAC1C,SAAS,iBAAiB,yBAAyB;AAW5C,SAAS,qBAAqB,SAER;AAC3B,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,WAAW,SACV,IAAI,WAAW,EAAE,wBAAwB,KAAK,OAC/C;AAAA,EACN;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AACA,SAAO;AACT;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;AAKO,IAAM,gBAAgB,0BAA0B,oBAAoB;AAEpE,IAAM,8BAA8B;AAAA,EACzC;AACF;AACO,IAAM,4BAA4B;AAAA,EACvC;AACF;AACO,IAAM,uBAAuB;AAAA,EAClC;AACF;","names":[]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ComposerRuntime } from "../runtime/ComposerRuntime";
|
|
2
2
|
/**
|
|
3
|
+
* @deprecated Use `useAssistantApi()` with `api.composer()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
|
|
4
|
+
*
|
|
3
5
|
* Hook to access the ComposerRuntime from the current context.
|
|
4
6
|
*
|
|
5
7
|
* The ComposerRuntime provides access to composer state and actions for message
|
|
@@ -13,21 +15,42 @@ import { ComposerRuntime } from "../runtime/ComposerRuntime";
|
|
|
13
15
|
*
|
|
14
16
|
* @example
|
|
15
17
|
* ```tsx
|
|
18
|
+
* // Before:
|
|
16
19
|
* function ComposerActions() {
|
|
17
20
|
* const runtime = useComposerRuntime();
|
|
18
|
-
*
|
|
19
21
|
* const handleSend = () => {
|
|
20
22
|
* if (runtime.getState().canSend) {
|
|
21
23
|
* runtime.send();
|
|
22
24
|
* }
|
|
23
25
|
* };
|
|
24
|
-
*
|
|
25
26
|
* const handleCancel = () => {
|
|
26
27
|
* if (runtime.getState().canCancel) {
|
|
27
28
|
* runtime.cancel();
|
|
28
29
|
* }
|
|
29
30
|
* };
|
|
31
|
+
* return (
|
|
32
|
+
* <div>
|
|
33
|
+
* <button onClick={handleSend}>Send</button>
|
|
34
|
+
* <button onClick={handleCancel}>Cancel</button>
|
|
35
|
+
* </div>
|
|
36
|
+
* );
|
|
37
|
+
* }
|
|
30
38
|
*
|
|
39
|
+
* // After:
|
|
40
|
+
* function ComposerActions() {
|
|
41
|
+
* const api = useAssistantApi();
|
|
42
|
+
* const canSend = useAssistantState(({ composer }) => composer.canSend);
|
|
43
|
+
* const canCancel = useAssistantState(({ composer }) => composer.canCancel);
|
|
44
|
+
* const handleSend = () => {
|
|
45
|
+
* if (canSend) {
|
|
46
|
+
* api.composer().send();
|
|
47
|
+
* }
|
|
48
|
+
* };
|
|
49
|
+
* const handleCancel = () => {
|
|
50
|
+
* if (canCancel) {
|
|
51
|
+
* api.composer().cancel();
|
|
52
|
+
* }
|
|
53
|
+
* };
|
|
31
54
|
* return (
|
|
32
55
|
* <div>
|
|
33
56
|
* <button onClick={handleSend}>Send</button>
|
|
@@ -44,6 +67,8 @@ export declare function useComposerRuntime(options?: {
|
|
|
44
67
|
optional?: boolean | undefined;
|
|
45
68
|
}): ComposerRuntime | null;
|
|
46
69
|
/**
|
|
70
|
+
* @deprecated Use `useAssistantState(({ composer }) => composer)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12
|
|
71
|
+
*
|
|
47
72
|
* Hook to access the current composer state.
|
|
48
73
|
*
|
|
49
74
|
* This hook provides reactive access to the composer's state, including text content,
|
|
@@ -54,11 +79,25 @@ export declare function useComposerRuntime(options?: {
|
|
|
54
79
|
*
|
|
55
80
|
* @example
|
|
56
81
|
* ```tsx
|
|
82
|
+
* // Before:
|
|
57
83
|
* function ComposerStatus() {
|
|
58
84
|
* const text = useComposer((state) => state.text);
|
|
59
85
|
* const canSend = useComposer((state) => state.canSend);
|
|
60
86
|
* const attachmentCount = useComposer((state) => state.attachments.length);
|
|
87
|
+
* return (
|
|
88
|
+
* <div>
|
|
89
|
+
* Text: {text.length} chars,
|
|
90
|
+
* Attachments: {attachmentCount},
|
|
91
|
+
* Can send: {canSend}
|
|
92
|
+
* </div>
|
|
93
|
+
* );
|
|
94
|
+
* }
|
|
61
95
|
*
|
|
96
|
+
* // After:
|
|
97
|
+
* function ComposerStatus() {
|
|
98
|
+
* const text = useAssistantState(({ composer }) => composer.text);
|
|
99
|
+
* const canSend = useAssistantState(({ composer }) => composer.canSend);
|
|
100
|
+
* const attachmentCount = useAssistantState(({ composer }) => composer.attachments.length);
|
|
62
101
|
* return (
|
|
63
102
|
* <div>
|
|
64
103
|
* Text: {text.length} chars,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComposerContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/ComposerContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG7D
|
|
1
|
+
{"version":3,"file":"ComposerContext.d.ts","sourceRoot":"","sources":["../../../src/legacy-runtime/hooks/ComposerContext.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,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;AAgB3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;CAAgD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/legacy-runtime/hooks/ComposerContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\nimport { ComposerRuntime } from \"../runtime/ComposerRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\n\n/**\n * Hook to access the ComposerRuntime from the current context.\n *\n * The ComposerRuntime provides access to composer state and actions for message\n * composition, including text input, attachments, and sending functionality.\n * This hook automatically resolves to either the message's edit composer or\n * the thread's main composer depending on the context.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The ComposerRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * function ComposerActions() {\n * const runtime = useComposerRuntime();\n
|
|
1
|
+
{"version":3,"sources":["../../../src/legacy-runtime/hooks/ComposerContext.ts"],"sourcesContent":["\"use client\";\n\nimport { useAssistantApi, useAssistantState } from \"../../context/react\";\nimport { ComposerRuntime } from \"../runtime/ComposerRuntime\";\nimport { createStateHookForRuntime } from \"../../context/react/utils/createStateHookForRuntime\";\n\n/**\n * @deprecated Use `useAssistantApi()` with `api.composer()` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n *\n * Hook to access the ComposerRuntime from the current context.\n *\n * The ComposerRuntime provides access to composer state and actions for message\n * composition, including text input, attachments, and sending functionality.\n * This hook automatically resolves to either the message's edit composer or\n * the thread's main composer depending on the context.\n *\n * @param options Configuration options\n * @param options.optional Whether the hook should return null if no context is found\n * @returns The ComposerRuntime instance, or null if optional is true and no context exists\n *\n * @example\n * ```tsx\n * // Before:\n * function ComposerActions() {\n * const runtime = useComposerRuntime();\n * const handleSend = () => {\n * if (runtime.getState().canSend) {\n * runtime.send();\n * }\n * };\n * const handleCancel = () => {\n * if (runtime.getState().canCancel) {\n * runtime.cancel();\n * }\n * };\n * return (\n * <div>\n * <button onClick={handleSend}>Send</button>\n * <button onClick={handleCancel}>Cancel</button>\n * </div>\n * );\n * }\n *\n * // After:\n * function ComposerActions() {\n * const api = useAssistantApi();\n * const canSend = useAssistantState(({ composer }) => composer.canSend);\n * const canCancel = useAssistantState(({ composer }) => composer.canCancel);\n * const handleSend = () => {\n * if (canSend) {\n * api.composer().send();\n * }\n * };\n * const handleCancel = () => {\n * if (canCancel) {\n * api.composer().cancel();\n * }\n * };\n * return (\n * <div>\n * <button onClick={handleSend}>Send</button>\n * <button onClick={handleCancel}>Cancel</button>\n * </div>\n * );\n * }\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 api = useAssistantApi();\n const runtime = useAssistantState(() =>\n api.composer.source\n ? (api.composer().__internal_getRuntime?.() ?? null)\n : null,\n );\n if (!runtime && !options?.optional) {\n throw new Error(\"ComposerRuntime is not available\");\n }\n return runtime;\n}\n\n/**\n * @deprecated Use `useAssistantState(({ composer }) => composer)` instead. See migration guide: https://docs.assistant-ui.com/docs/migrations/v0-12\n *\n * Hook to access the current composer state.\n *\n * This hook provides reactive access to the composer's state, including text content,\n * attachments, editing status, and send/cancel capabilities.\n *\n * @param selector Optional selector function to pick specific state properties\n * @returns The selected composer state or the entire composer state if no selector provided\n *\n * @example\n * ```tsx\n * // Before:\n * function ComposerStatus() {\n * const text = useComposer((state) => state.text);\n * const canSend = useComposer((state) => state.canSend);\n * const attachmentCount = useComposer((state) => state.attachments.length);\n * return (\n * <div>\n * Text: {text.length} chars,\n * Attachments: {attachmentCount},\n * Can send: {canSend}\n * </div>\n * );\n * }\n *\n * // After:\n * function ComposerStatus() {\n * const text = useAssistantState(({ composer }) => composer.text);\n * const canSend = useAssistantState(({ composer }) => composer.canSend);\n * const attachmentCount = useAssistantState(({ composer }) => composer.attachments.length);\n * return (\n * <div>\n * Text: {text.length} chars,\n * Attachments: {attachmentCount},\n * Can send: {canSend}\n * </div>\n * );\n * }\n * ```\n */\nexport const useComposer = createStateHookForRuntime(useComposerRuntime);\n"],"mappings":";;;AAEA,SAAS,iBAAiB,yBAAyB;AAEnD,SAAS,iCAAiC;AAqEnC,SAAS,mBAAmB,SAER;AACzB,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU;AAAA,IAAkB,MAChC,IAAI,SAAS,SACR,IAAI,SAAS,EAAE,wBAAwB,KAAK,OAC7C;AAAA,EACN;AACA,MAAI,CAAC,WAAW,CAAC,SAAS,UAAU;AAClC,UAAM,IAAI,MAAM,kCAAkC;AAAA,EACpD;AACA,SAAO;AACT;AA4CO,IAAM,cAAc,0BAA0B,kBAAkB;","names":[]}
|