@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
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { resource, tapState, tapEffect } from "@assistant-ui/tap";
|
|
2
|
+
import { tapApi } from "../utils/tap-store";
|
|
3
|
+
import { tapModelContext } from "./ModelContext";
|
|
4
|
+
import { tapToolUI } from "./ToolUIContext";
|
|
5
|
+
import { ToolsState, ToolsApi } from "./types/Tools";
|
|
6
|
+
import type { Tool } from "assistant-stream";
|
|
7
|
+
import {
|
|
8
|
+
type Toolkit,
|
|
9
|
+
FallbackSymbol,
|
|
10
|
+
LayoutSymbol,
|
|
11
|
+
} from "../model-context/toolbox";
|
|
12
|
+
|
|
13
|
+
export const Tools = resource(({ toolkit }: { toolkit?: Toolkit }) => {
|
|
14
|
+
const [state] = tapState<ToolsState>(() => ({}));
|
|
15
|
+
|
|
16
|
+
const modelContext = tapModelContext();
|
|
17
|
+
const toolUI = tapToolUI();
|
|
18
|
+
|
|
19
|
+
tapEffect(() => {
|
|
20
|
+
if (!toolkit) return;
|
|
21
|
+
const unsubscribes: (() => void)[] = [];
|
|
22
|
+
|
|
23
|
+
// Register fallback UI
|
|
24
|
+
const fallback = toolkit[FallbackSymbol];
|
|
25
|
+
if (fallback?.render) {
|
|
26
|
+
unsubscribes.push(toolUI.setFallbackToolUI(fallback.render));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Register layout
|
|
30
|
+
const layout = toolkit[LayoutSymbol];
|
|
31
|
+
if (layout?.render) {
|
|
32
|
+
unsubscribes.push(toolUI.setToolUILayout(layout.render));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Register tool UIs (exclude symbols)
|
|
36
|
+
for (const [toolName, tool] of Object.entries(toolkit)) {
|
|
37
|
+
if (tool.render) {
|
|
38
|
+
unsubscribes.push(toolUI.setToolUI(toolName, tool.render));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Register tools with model context (exclude symbols)
|
|
43
|
+
const toolsWithoutRender = Object.entries(toolkit).reduce(
|
|
44
|
+
(acc, [name, tool]) => {
|
|
45
|
+
const { render, ...rest } = tool;
|
|
46
|
+
acc[name] = rest;
|
|
47
|
+
return acc;
|
|
48
|
+
},
|
|
49
|
+
{} as Record<string, Tool<any, any>>,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const modelContextProvider = {
|
|
53
|
+
getModelContext: () => ({
|
|
54
|
+
tools: toolsWithoutRender,
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
unsubscribes.push(modelContext.register(modelContextProvider));
|
|
59
|
+
|
|
60
|
+
return () => {
|
|
61
|
+
unsubscribes.forEach((fn) => fn());
|
|
62
|
+
};
|
|
63
|
+
}, [toolkit, modelContext, toolUI]);
|
|
64
|
+
|
|
65
|
+
return tapApi<ToolsApi>({
|
|
66
|
+
getState: () => state,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Unsubscribe } from "@assistant-ui/tap";
|
|
2
|
+
import type { ModelContextProvider } from "../../model-context/ModelContextTypes";
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
5
|
+
export type ModelContextState = {};
|
|
6
|
+
|
|
7
|
+
export type ModelContextApi = ModelContextProvider & {
|
|
8
|
+
getState(): ModelContextState;
|
|
9
|
+
register: (provider: ModelContextProvider) => Unsubscribe;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type ModelContextMeta = {
|
|
13
|
+
source: "root";
|
|
14
|
+
query: Record<string, never>;
|
|
15
|
+
};
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
ThreadListItemClientApi,
|
|
4
4
|
} from "./ThreadListItem";
|
|
5
5
|
import { ThreadClientApi, ThreadClientState } from "./Thread";
|
|
6
|
+
import type { AssistantRuntime } from "../../legacy-runtime/runtime/AssistantRuntime";
|
|
6
7
|
|
|
7
8
|
export type ThreadListClientState = {
|
|
8
9
|
readonly mainThreadId: string;
|
|
@@ -29,4 +30,7 @@ export type ThreadListClientApi = {
|
|
|
29
30
|
): ThreadListItemClientApi;
|
|
30
31
|
|
|
31
32
|
thread(selector: "main"): ThreadClientApi;
|
|
33
|
+
|
|
34
|
+
/** @internal */
|
|
35
|
+
__internal_getAssistantRuntime?(): AssistantRuntime;
|
|
32
36
|
};
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { Unsubscribe } from "@assistant-ui/tap";
|
|
2
|
+
import type { ComponentType, ReactNode } from "react";
|
|
2
3
|
import { ToolCallMessagePartComponent } from "../../types";
|
|
3
4
|
|
|
4
|
-
export type ToolUIState =
|
|
5
|
+
export type ToolUIState = {
|
|
6
|
+
tools: Record<string, ToolCallMessagePartComponent[]>;
|
|
7
|
+
fallback: ToolCallMessagePartComponent[];
|
|
8
|
+
layout: ComponentType<{ children: ReactNode }>[];
|
|
9
|
+
};
|
|
5
10
|
|
|
6
11
|
export type ToolUIApi = {
|
|
7
12
|
getState(): ToolUIState;
|
|
@@ -10,6 +15,10 @@ export type ToolUIApi = {
|
|
|
10
15
|
toolName: string,
|
|
11
16
|
render: ToolCallMessagePartComponent,
|
|
12
17
|
): Unsubscribe;
|
|
18
|
+
|
|
19
|
+
setFallbackToolUI(render: ToolCallMessagePartComponent): Unsubscribe;
|
|
20
|
+
|
|
21
|
+
setToolUILayout(render: ComponentType<{ children: ReactNode }>): Unsubscribe;
|
|
13
22
|
};
|
|
14
23
|
|
|
15
24
|
export type ToolUIMeta = {
|
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { type FC, type PropsWithChildren } from "react";
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
AssistantApi,
|
|
7
6
|
AssistantProvider,
|
|
8
7
|
useAssistantApi,
|
|
9
|
-
|
|
8
|
+
useExtendedAssistantApi,
|
|
10
9
|
} from "../react/AssistantApiContext";
|
|
10
|
+
import { DerivedScope } from "../../utils/tap-store/derived-scopes";
|
|
11
11
|
|
|
12
12
|
export const MessageAttachmentByIndexProvider: FC<
|
|
13
13
|
PropsWithChildren<{
|
|
14
14
|
index: number;
|
|
15
15
|
}>
|
|
16
16
|
> = ({ index, children }) => {
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} satisfies Partial<AssistantApi>;
|
|
26
|
-
}, [api, index]);
|
|
17
|
+
const baseApi = useAssistantApi();
|
|
18
|
+
const api = useExtendedAssistantApi({
|
|
19
|
+
attachment: DerivedScope({
|
|
20
|
+
source: "message",
|
|
21
|
+
query: { type: "index", index },
|
|
22
|
+
get: () => baseApi.message().attachment({ index }),
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
27
25
|
|
|
28
|
-
return <AssistantProvider api={
|
|
26
|
+
return <AssistantProvider api={api}>{children}</AssistantProvider>;
|
|
29
27
|
};
|
|
30
28
|
|
|
31
29
|
export const ComposerAttachmentByIndexProvider: FC<
|
|
@@ -33,16 +31,14 @@ export const ComposerAttachmentByIndexProvider: FC<
|
|
|
33
31
|
index: number;
|
|
34
32
|
}>
|
|
35
33
|
> = ({ index, children }) => {
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} satisfies Partial<AssistantApi>;
|
|
45
|
-
}, [api, index]);
|
|
34
|
+
const baseApi = useAssistantApi();
|
|
35
|
+
const api = useExtendedAssistantApi({
|
|
36
|
+
attachment: DerivedScope({
|
|
37
|
+
source: "composer",
|
|
38
|
+
query: { type: "index", index },
|
|
39
|
+
get: () => baseApi.composer().attachment({ index }),
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
46
42
|
|
|
47
|
-
return <AssistantProvider api={
|
|
43
|
+
return <AssistantProvider api={api}>{children}</AssistantProvider>;
|
|
48
44
|
};
|
|
@@ -1,52 +1,50 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { type FC, type PropsWithChildren } from "react";
|
|
4
4
|
import {
|
|
5
|
-
AssistantApi,
|
|
6
5
|
AssistantProvider,
|
|
7
6
|
useAssistantApi,
|
|
8
|
-
|
|
7
|
+
useExtendedAssistantApi,
|
|
9
8
|
} from "../react/AssistantApiContext";
|
|
10
9
|
import {
|
|
11
10
|
checkEventScope,
|
|
12
11
|
normalizeEventSelector,
|
|
13
12
|
} from "../../types/EventTypes";
|
|
13
|
+
import { DerivedScope } from "../../utils/tap-store/derived-scopes";
|
|
14
14
|
|
|
15
15
|
export const MessageByIndexProvider: FC<
|
|
16
16
|
PropsWithChildren<{
|
|
17
17
|
index: number;
|
|
18
18
|
}>
|
|
19
19
|
> = ({ index, children }) => {
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
)
|
|
40
|
-
return api.on(selector, callback);
|
|
20
|
+
const baseApi = useAssistantApi();
|
|
21
|
+
const api = useExtendedAssistantApi({
|
|
22
|
+
message: DerivedScope({
|
|
23
|
+
source: "thread",
|
|
24
|
+
query: { type: "index", index },
|
|
25
|
+
get: () => baseApi.thread().message({ index }),
|
|
26
|
+
}),
|
|
27
|
+
composer: DerivedScope({
|
|
28
|
+
source: "message",
|
|
29
|
+
query: {},
|
|
30
|
+
get: () => baseApi.thread().message({ index }).composer,
|
|
31
|
+
}),
|
|
32
|
+
on(selector, callback) {
|
|
33
|
+
const getMessage = () => baseApi.thread().message({ index });
|
|
34
|
+
const { event, scope } = normalizeEventSelector(selector);
|
|
35
|
+
if (
|
|
36
|
+
!checkEventScope("composer", scope, event) &&
|
|
37
|
+
!checkEventScope("message", scope, event)
|
|
38
|
+
)
|
|
39
|
+
return baseApi.on(selector, callback);
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}, [api, index]);
|
|
41
|
+
return baseApi.on({ scope: "thread", event }, (e) => {
|
|
42
|
+
if (e.messageId === getMessage().getState().id) {
|
|
43
|
+
callback(e);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
});
|
|
50
48
|
|
|
51
|
-
return <AssistantProvider api={
|
|
49
|
+
return <AssistantProvider api={api}>{children}</AssistantProvider>;
|
|
52
50
|
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { type FC, type PropsWithChildren } from "react";
|
|
4
4
|
import {
|
|
5
5
|
AssistantProvider,
|
|
6
|
-
|
|
7
|
-
createAssistantApiField,
|
|
6
|
+
useExtendedAssistantApi,
|
|
8
7
|
} from "../react/AssistantApiContext";
|
|
9
8
|
import { useResource } from "@assistant-ui/tap/react";
|
|
10
9
|
import { asStore } from "../../utils/tap-store";
|
|
@@ -12,22 +11,21 @@ import {
|
|
|
12
11
|
ThreadMessageClientProps,
|
|
13
12
|
ThreadMessageClient,
|
|
14
13
|
} from "../../client/ThreadMessageClient";
|
|
14
|
+
import { DerivedScope } from "../../utils/tap-store/derived-scopes";
|
|
15
15
|
|
|
16
16
|
export const MessageProvider: FC<
|
|
17
17
|
PropsWithChildren<ThreadMessageClientProps>
|
|
18
18
|
> = ({ children, ...props }) => {
|
|
19
19
|
const store = useResource(asStore(ThreadMessageClient(props)));
|
|
20
|
-
const api =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
} satisfies Partial<AssistantApi>;
|
|
30
|
-
}, [store]);
|
|
20
|
+
const api = useExtendedAssistantApi({
|
|
21
|
+
message: DerivedScope({
|
|
22
|
+
source: "root",
|
|
23
|
+
query: {},
|
|
24
|
+
get: () => store.getState().api,
|
|
25
|
+
}),
|
|
26
|
+
subscribe: store.subscribe,
|
|
27
|
+
flushSync: store.flushSync,
|
|
28
|
+
});
|
|
31
29
|
|
|
32
30
|
return <AssistantProvider api={api}>{children}</AssistantProvider>;
|
|
33
31
|
};
|
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { type FC, type PropsWithChildren } from "react";
|
|
4
4
|
import {
|
|
5
|
-
AssistantApi,
|
|
6
5
|
AssistantProvider,
|
|
7
6
|
useAssistantApi,
|
|
8
|
-
|
|
7
|
+
useExtendedAssistantApi,
|
|
9
8
|
} from "../react/AssistantApiContext";
|
|
9
|
+
import { DerivedScope } from "../../utils/tap-store/derived-scopes";
|
|
10
10
|
|
|
11
11
|
export const PartByIndexProvider: FC<
|
|
12
12
|
PropsWithChildren<{
|
|
13
13
|
index: number;
|
|
14
14
|
}>
|
|
15
15
|
> = ({ index, children }) => {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} satisfies Partial<AssistantApi>;
|
|
25
|
-
}, [api, index]);
|
|
16
|
+
const baseApi = useAssistantApi();
|
|
17
|
+
const api = useExtendedAssistantApi({
|
|
18
|
+
part: DerivedScope({
|
|
19
|
+
source: "message",
|
|
20
|
+
query: { type: "index", index },
|
|
21
|
+
get: () => baseApi.message().part({ index }),
|
|
22
|
+
}),
|
|
23
|
+
});
|
|
26
24
|
|
|
27
|
-
return <AssistantProvider api={
|
|
25
|
+
return <AssistantProvider api={api}>{children}</AssistantProvider>;
|
|
28
26
|
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { type FC, type PropsWithChildren } from "react";
|
|
4
4
|
import {
|
|
5
5
|
AssistantProvider,
|
|
6
|
-
|
|
7
|
-
createAssistantApiField,
|
|
6
|
+
useExtendedAssistantApi,
|
|
8
7
|
} from "../react/AssistantApiContext";
|
|
9
8
|
import {
|
|
10
9
|
MessagePartClientApi,
|
|
@@ -13,6 +12,7 @@ import {
|
|
|
13
12
|
import { resource, tapMemo } from "@assistant-ui/tap";
|
|
14
13
|
import { useResource } from "@assistant-ui/tap/react";
|
|
15
14
|
import { asStore, tapApi } from "../../utils/tap-store";
|
|
15
|
+
import { DerivedScope } from "../../utils/tap-store/derived-scopes";
|
|
16
16
|
|
|
17
17
|
const TextMessagePartClient = resource(
|
|
18
18
|
({ text, isRunning }: { text: string; isRunning: boolean }) => {
|
|
@@ -46,17 +46,15 @@ export const TextMessagePartProvider: FC<
|
|
|
46
46
|
const store = useResource(
|
|
47
47
|
asStore(TextMessagePartClient({ text, isRunning })),
|
|
48
48
|
);
|
|
49
|
-
const api =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
} satisfies Partial<AssistantApi>;
|
|
59
|
-
}, [store]);
|
|
49
|
+
const api = useExtendedAssistantApi({
|
|
50
|
+
part: DerivedScope({
|
|
51
|
+
source: "root",
|
|
52
|
+
query: {},
|
|
53
|
+
get: () => store.getState().api,
|
|
54
|
+
}),
|
|
55
|
+
subscribe: store.subscribe,
|
|
56
|
+
flushSync: store.flushSync,
|
|
57
|
+
});
|
|
60
58
|
|
|
61
59
|
return <AssistantProvider api={api}>{children}</AssistantProvider>;
|
|
62
60
|
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { type FC, type PropsWithChildren } from "react";
|
|
4
4
|
import {
|
|
5
|
-
AssistantApi,
|
|
6
5
|
AssistantProvider,
|
|
7
6
|
useAssistantApi,
|
|
8
|
-
|
|
7
|
+
useExtendedAssistantApi,
|
|
9
8
|
} from "../react/AssistantApiContext";
|
|
10
9
|
import {
|
|
11
10
|
checkEventScope,
|
|
12
11
|
normalizeEventSelector,
|
|
13
12
|
} from "../../types/EventTypes";
|
|
13
|
+
import { DerivedScope } from "../../utils/tap-store/derived-scopes";
|
|
14
14
|
|
|
15
15
|
export const ThreadListItemByIndexProvider: FC<
|
|
16
16
|
PropsWithChildren<{
|
|
@@ -18,31 +18,29 @@ export const ThreadListItemByIndexProvider: FC<
|
|
|
18
18
|
archived: boolean;
|
|
19
19
|
}>
|
|
20
20
|
> = ({ index, archived, children }) => {
|
|
21
|
-
const
|
|
21
|
+
const baseApi = useAssistantApi();
|
|
22
22
|
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return api.on(selector, callback);
|
|
23
|
+
const api = useExtendedAssistantApi({
|
|
24
|
+
threadListItem: DerivedScope({
|
|
25
|
+
source: "threads",
|
|
26
|
+
query: { type: "index", index, archived },
|
|
27
|
+
get: () => baseApi.threads().item({ index, archived }),
|
|
28
|
+
}),
|
|
29
|
+
on(selector, callback) {
|
|
30
|
+
const getItem = () => baseApi.threads().item({ index, archived });
|
|
31
|
+
const { event, scope } = normalizeEventSelector(selector);
|
|
32
|
+
if (!checkEventScope("thread-list-item", scope, event))
|
|
33
|
+
return baseApi.on(selector, callback);
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}, [api, index, archived]);
|
|
35
|
+
return baseApi.on({ scope: "*", event }, (e) => {
|
|
36
|
+
if (e.threadId === getItem().getState().id) {
|
|
37
|
+
callback(e);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
});
|
|
44
42
|
|
|
45
|
-
return <AssistantProvider api={
|
|
43
|
+
return <AssistantProvider api={api}>{children}</AssistantProvider>;
|
|
46
44
|
};
|
|
47
45
|
|
|
48
46
|
export const ThreadListItemByIdProvider: FC<
|
|
@@ -50,28 +48,26 @@ export const ThreadListItemByIdProvider: FC<
|
|
|
50
48
|
id: string;
|
|
51
49
|
}>
|
|
52
50
|
> = ({ id, children }) => {
|
|
53
|
-
const
|
|
51
|
+
const baseApi = useAssistantApi();
|
|
54
52
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return api.on(selector, callback);
|
|
53
|
+
const api = useExtendedAssistantApi({
|
|
54
|
+
threadListItem: DerivedScope({
|
|
55
|
+
source: "threads",
|
|
56
|
+
query: { type: "id", id },
|
|
57
|
+
get: () => baseApi.threads().item({ id }),
|
|
58
|
+
}),
|
|
59
|
+
on(selector, callback) {
|
|
60
|
+
const getItem = () => baseApi.threads().item({ id });
|
|
61
|
+
const { event, scope } = normalizeEventSelector(selector);
|
|
62
|
+
if (!checkEventScope("thread-list-item", scope, event))
|
|
63
|
+
return baseApi.on(selector, callback);
|
|
67
64
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}, [api, id]);
|
|
65
|
+
return baseApi.on({ scope: "*", event }, (e) => {
|
|
66
|
+
if (e.threadId !== getItem().getState().id) return;
|
|
67
|
+
callback(e);
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
});
|
|
75
71
|
|
|
76
|
-
return <AssistantProvider api={
|
|
72
|
+
return <AssistantProvider api={api}>{children}</AssistantProvider>;
|
|
77
73
|
};
|