@assistant-ui/react 0.11.5 → 0.11.6
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.map +1 -1
- package/dist/client/AssistantClient.js +1 -2
- package/dist/client/AssistantClient.js.map +1 -1
- package/dist/client/ToolUIClient.d.ts +3 -2
- package/dist/client/ToolUIClient.d.ts.map +1 -1
- package/dist/client/ToolUIClient.js +1 -5
- package/dist/client/ToolUIClient.js.map +1 -1
- package/dist/context/providers/AttachmentProvider.js +3 -3
- package/dist/context/providers/AttachmentProvider.js.map +1 -1
- package/dist/context/providers/MessageProvider.js +2 -2
- package/dist/context/providers/MessageProvider.js.map +1 -1
- package/dist/context/providers/PartProvider.js +2 -2
- package/dist/context/providers/PartProvider.js.map +1 -1
- package/dist/context/providers/TextMessagePartProvider.d.ts.map +1 -1
- package/dist/context/providers/TextMessagePartProvider.js +6 -7
- package/dist/context/providers/TextMessagePartProvider.js.map +1 -1
- package/dist/context/providers/ThreadListItemProvider.js +3 -3
- package/dist/context/providers/ThreadListItemProvider.js.map +1 -1
- package/dist/context/react/AssistantApiContext.d.ts +1 -1
- package/dist/context/react/AssistantApiContext.d.ts.map +1 -1
- package/dist/context/react/AssistantApiContext.js +4 -3
- package/dist/context/react/AssistantApiContext.js.map +1 -1
- package/dist/context/react/index.d.ts +1 -0
- package/dist/context/react/index.d.ts.map +1 -1
- package/dist/context/react/index.js +2 -0
- 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 +1 -5
- package/dist/legacy-runtime/AssistantRuntimeProvider.js.map +1 -1
- package/dist/legacy-runtime/client/AttachmentRuntimeClient.d.ts +2 -4
- package/dist/legacy-runtime/client/AttachmentRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/AttachmentRuntimeClient.js +10 -10
- package/dist/legacy-runtime/client/AttachmentRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/client/ComposerRuntimeClient.d.ts +3 -2
- package/dist/legacy-runtime/client/ComposerRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/ComposerRuntimeClient.js +1 -5
- package/dist/legacy-runtime/client/ComposerRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/client/MessagePartRuntimeClient.d.ts +1 -1
- package/dist/legacy-runtime/client/MessagePartRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/MessagePartRuntimeClient.js +10 -10
- package/dist/legacy-runtime/client/MessagePartRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/client/MessageRuntimeClient.d.ts +3 -3
- package/dist/legacy-runtime/client/MessageRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/MessageRuntimeClient.js +31 -31
- package/dist/legacy-runtime/client/MessageRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/client/ThreadListItemRuntimeClient.d.ts +2 -2
- package/dist/legacy-runtime/client/ThreadListItemRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/ThreadListItemRuntimeClient.js +17 -17
- package/dist/legacy-runtime/client/ThreadListItemRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/client/ThreadListRuntimeClient.d.ts +3 -2
- package/dist/legacy-runtime/client/ThreadListRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/ThreadListRuntimeClient.js +1 -5
- package/dist/legacy-runtime/client/ThreadListRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/client/ThreadRuntimeClient.d.ts +3 -2
- package/dist/legacy-runtime/client/ThreadRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/ThreadRuntimeClient.js +1 -5
- package/dist/legacy-runtime/client/ThreadRuntimeClient.js.map +1 -1
- package/dist/utils/tap-store/tap-api.d.ts +9 -1
- package/dist/utils/tap-store/tap-api.d.ts.map +1 -1
- package/dist/utils/tap-store/tap-api.js +12 -2
- package/dist/utils/tap-store/tap-api.js.map +1 -1
- package/package.json +1 -1
- package/src/client/AssistantClient.ts +1 -4
- package/src/client/ToolUIClient.ts +1 -6
- package/src/context/providers/AttachmentProvider.tsx +3 -3
- package/src/context/providers/MessageProvider.tsx +2 -2
- package/src/context/providers/PartProvider.tsx +2 -2
- package/src/context/providers/TextMessagePartProvider.tsx +5 -7
- package/src/context/providers/ThreadListItemProvider.tsx +3 -3
- package/src/context/react/AssistantApiContext.tsx +7 -2
- package/src/context/react/index.ts +2 -0
- package/src/legacy-runtime/AssistantRuntimeProvider.tsx +1 -15
- package/src/legacy-runtime/client/AttachmentRuntimeClient.ts +10 -11
- package/src/legacy-runtime/client/ComposerRuntimeClient.ts +1 -6
- package/src/legacy-runtime/client/MessagePartRuntimeClient.ts +13 -14
- package/src/legacy-runtime/client/MessageRuntimeClient.ts +35 -36
- package/src/legacy-runtime/client/ThreadListItemRuntimeClient.ts +17 -18
- package/src/legacy-runtime/client/ThreadListRuntimeClient.ts +1 -6
- package/src/legacy-runtime/client/ThreadRuntimeClient.ts +1 -6
- package/src/utils/tap-store/tap-api.ts +19 -2
@@ -3,7 +3,7 @@
|
|
3
3
|
import { useMemo, type FC, type PropsWithChildren } from "react";
|
4
4
|
import {
|
5
5
|
AssistantApi,
|
6
|
-
|
6
|
+
AssistantProvider,
|
7
7
|
useAssistantApi,
|
8
8
|
createAssistantApiField,
|
9
9
|
} from "../react/AssistantApiContext";
|
@@ -24,5 +24,5 @@ export const PartByIndexProvider: FC<
|
|
24
24
|
} satisfies Partial<AssistantApi>;
|
25
25
|
}, [api, index]);
|
26
26
|
|
27
|
-
return <
|
27
|
+
return <AssistantProvider api={api2}>{children}</AssistantProvider>;
|
28
28
|
};
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
import { useMemo, type FC, type PropsWithChildren } from "react";
|
4
4
|
import {
|
5
|
-
|
5
|
+
AssistantProvider,
|
6
6
|
AssistantApi,
|
7
7
|
createAssistantApiField,
|
8
8
|
} from "../react/AssistantApiContext";
|
@@ -25,15 +25,13 @@ const TextMessagePartClient = resource(
|
|
25
25
|
[text, isRunning],
|
26
26
|
);
|
27
27
|
|
28
|
-
|
28
|
+
return tapApi<MessagePartClientApi>({
|
29
29
|
getState: () => state,
|
30
30
|
addToolResult: () => {
|
31
31
|
throw new Error("Not supported");
|
32
32
|
},
|
33
33
|
__internal_getRuntime: () => null,
|
34
34
|
});
|
35
|
-
|
36
|
-
return api;
|
37
35
|
},
|
38
36
|
);
|
39
37
|
|
@@ -51,12 +49,12 @@ export const TextMessagePartProvider: FC<
|
|
51
49
|
part: createAssistantApiField({
|
52
50
|
source: "root",
|
53
51
|
query: {},
|
54
|
-
get: () => store.getState(),
|
52
|
+
get: () => store.getState().api,
|
55
53
|
}),
|
56
54
|
subscribe: store.subscribe,
|
57
|
-
|
55
|
+
flushSync: store.flushSync,
|
58
56
|
} satisfies Partial<AssistantApi>;
|
59
57
|
}, [store]);
|
60
58
|
|
61
|
-
return <
|
59
|
+
return <AssistantProvider api={api}>{children}</AssistantProvider>;
|
62
60
|
};
|
@@ -3,7 +3,7 @@
|
|
3
3
|
import { useMemo, type FC, type PropsWithChildren } from "react";
|
4
4
|
import {
|
5
5
|
AssistantApi,
|
6
|
-
|
6
|
+
AssistantProvider,
|
7
7
|
useAssistantApi,
|
8
8
|
createAssistantApiField,
|
9
9
|
} from "../react/AssistantApiContext";
|
@@ -42,7 +42,7 @@ export const ThreadListItemByIndexProvider: FC<
|
|
42
42
|
} satisfies Partial<AssistantApi>;
|
43
43
|
}, [api, index, archived]);
|
44
44
|
|
45
|
-
return <
|
45
|
+
return <AssistantProvider api={api2}>{children}</AssistantProvider>;
|
46
46
|
};
|
47
47
|
|
48
48
|
export const ThreadListItemByIdProvider: FC<
|
@@ -73,5 +73,5 @@ export const ThreadListItemByIdProvider: FC<
|
|
73
73
|
} satisfies Partial<AssistantApi>;
|
74
74
|
}, [api, id]);
|
75
75
|
|
76
|
-
return <
|
76
|
+
return <AssistantProvider api={api2}>{children}</AssistantProvider>;
|
77
77
|
};
|
@@ -43,6 +43,7 @@ import {
|
|
43
43
|
ThreadListClientApi,
|
44
44
|
ThreadListClientState,
|
45
45
|
} from "../../client/types/ThreadList";
|
46
|
+
import { ThreadViewportProvider } from "../providers/ThreadViewportProvider";
|
46
47
|
|
47
48
|
export type AssistantState = {
|
48
49
|
readonly threads: ThreadListClientState;
|
@@ -280,13 +281,17 @@ const extendApi = (
|
|
280
281
|
};
|
281
282
|
};
|
282
283
|
|
283
|
-
export const
|
284
|
+
export const AssistantProvider: FC<
|
284
285
|
PropsWithChildren<{ api: Partial<AssistantApi> }>
|
285
286
|
> = ({ api: api2, children }) => {
|
286
287
|
const api = useAssistantApi();
|
287
288
|
const extendedApi = useMemo(() => extendApi(api, api2), [api, api2]);
|
288
289
|
|
289
290
|
return (
|
290
|
-
<AssistantApiContext value={extendedApi}>
|
291
|
+
<AssistantApiContext value={extendedApi}>
|
292
|
+
{/* TODO temporarily allow accessing viewport state from outside the viewport */}
|
293
|
+
{/* TODO figure out if this behavior should be deprecated, since it is quite hacky */}
|
294
|
+
<ThreadViewportProvider>{children}</ThreadViewportProvider>
|
295
|
+
</AssistantApiContext>
|
291
296
|
);
|
292
297
|
};
|
@@ -1,12 +1,10 @@
|
|
1
1
|
"use client";
|
2
2
|
|
3
3
|
import { FC, memo, PropsWithChildren } from "react";
|
4
|
-
import {
|
4
|
+
import { AssistantProvider } from "../context/react/AssistantApiContext";
|
5
5
|
import { AssistantRuntime } from "./runtime/AssistantRuntime";
|
6
6
|
import { AssistantRuntimeCore } from "./runtime-cores/core/AssistantRuntimeCore";
|
7
7
|
import { useAssistantClient } from "../client/AssistantClient";
|
8
|
-
|
9
|
-
import { ThreadViewportProvider } from "../context/providers/ThreadViewportProvider";
|
10
8
|
import { ThreadListClient } from "./client/ThreadListRuntimeClient";
|
11
9
|
|
12
10
|
export namespace AssistantProvider {
|
@@ -46,15 +44,3 @@ export const AssistantRuntimeProviderImpl: FC<AssistantProvider.Props> = ({
|
|
46
44
|
};
|
47
45
|
|
48
46
|
export const AssistantRuntimeProvider = memo(AssistantRuntimeProviderImpl);
|
49
|
-
|
50
|
-
const AssistantProvider: FC<
|
51
|
-
PropsWithChildren<{ api: ReturnType<typeof useAssistantClient> }>
|
52
|
-
> = ({ children, api }) => {
|
53
|
-
return (
|
54
|
-
<AssistantApiProvider api={api}>
|
55
|
-
{/* TODO temporarily allow accessing viewport state from outside the viewport */}
|
56
|
-
{/* TODO figure out if this behavior should be deprecated, since it is quite hacky */}
|
57
|
-
<ThreadViewportProvider>{children}</ThreadViewportProvider>
|
58
|
-
</AssistantApiProvider>
|
59
|
-
);
|
60
|
-
};
|
@@ -7,16 +7,15 @@ import { tapSubscribable } from "../util-hooks/tapSubscribable";
|
|
7
7
|
export const AttachmentRuntimeClient = resource(
|
8
8
|
({ runtime }: { runtime: AttachmentRuntime }) => {
|
9
9
|
const state = tapSubscribable(runtime);
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
};
|
10
|
+
return tapApi<AttachmentClientApi>(
|
11
|
+
{
|
12
|
+
getState: () => state,
|
13
|
+
remove: runtime.remove,
|
14
|
+
__internal_getRuntime: () => runtime,
|
15
|
+
},
|
16
|
+
{
|
17
|
+
key: state.id,
|
18
|
+
},
|
19
|
+
);
|
21
20
|
},
|
22
21
|
);
|
@@ -98,7 +98,7 @@ export const ComposerClient = resource(
|
|
98
98
|
};
|
99
99
|
}, [runtimeState, attachments.state]);
|
100
100
|
|
101
|
-
|
101
|
+
return tapApi<ComposerClientApi>({
|
102
102
|
getState: () => state,
|
103
103
|
|
104
104
|
setText: runtime.setText,
|
@@ -126,10 +126,5 @@ export const ComposerClient = resource(
|
|
126
126
|
|
127
127
|
__internal_getRuntime: () => runtime,
|
128
128
|
});
|
129
|
-
|
130
|
-
return {
|
131
|
-
state,
|
132
|
-
api,
|
133
|
-
};
|
134
129
|
},
|
135
130
|
);
|
@@ -7,21 +7,20 @@ export const MessagePartClient = resource(
|
|
7
7
|
({ runtime }: { runtime: MessagePartRuntime }) => {
|
8
8
|
const runtimeState = tapSubscribable(runtime);
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
return tapApi<MessagePartClientApi>(
|
11
|
+
{
|
12
|
+
getState: () => runtimeState,
|
12
13
|
|
13
|
-
|
14
|
+
addToolResult: (result) => runtime.addToolResult(result),
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
api,
|
25
|
-
};
|
16
|
+
__internal_getRuntime: () => runtime,
|
17
|
+
},
|
18
|
+
{
|
19
|
+
key:
|
20
|
+
runtimeState.type === "tool-call"
|
21
|
+
? "toolCallId-" + runtimeState.toolCallId
|
22
|
+
: undefined,
|
23
|
+
},
|
24
|
+
);
|
26
25
|
},
|
27
26
|
);
|
@@ -99,44 +99,43 @@ export const MessageClient = resource(
|
|
99
99
|
isHoveringState,
|
100
100
|
]);
|
101
101
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
attachment: (selector) => {
|
123
|
-
if ("id" in selector) {
|
124
|
-
return attachments.api({ key: selector.id });
|
125
|
-
} else {
|
126
|
-
return attachments.api(selector);
|
127
|
-
}
|
128
|
-
},
|
102
|
+
return tapApi<MessageClientApi>(
|
103
|
+
{
|
104
|
+
getState: () => state,
|
105
|
+
|
106
|
+
composer: composer.api,
|
107
|
+
|
108
|
+
reload: (config) => runtime.reload(config),
|
109
|
+
speak: () => runtime.speak(),
|
110
|
+
stopSpeaking: () => runtime.stopSpeaking(),
|
111
|
+
submitFeedback: (feedback) => runtime.submitFeedback(feedback),
|
112
|
+
switchToBranch: (options) => runtime.switchToBranch(options),
|
113
|
+
getCopyText: () => runtime.unstable_getCopyText(),
|
114
|
+
|
115
|
+
part: (selector) => {
|
116
|
+
if ("index" in selector) {
|
117
|
+
return parts.api({ index: selector.index });
|
118
|
+
} else {
|
119
|
+
return parts.api({ key: "toolCallId-" + selector.toolCallId });
|
120
|
+
}
|
121
|
+
},
|
129
122
|
|
130
|
-
|
131
|
-
|
123
|
+
attachment: (selector) => {
|
124
|
+
if ("id" in selector) {
|
125
|
+
return attachments.api({ key: selector.id });
|
126
|
+
} else {
|
127
|
+
return attachments.api(selector);
|
128
|
+
}
|
129
|
+
},
|
132
130
|
|
133
|
-
|
134
|
-
|
131
|
+
setIsCopied,
|
132
|
+
setIsHovering,
|
135
133
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
134
|
+
__internal_getRuntime: () => runtime,
|
135
|
+
},
|
136
|
+
{
|
137
|
+
key: runtimeState.id,
|
138
|
+
},
|
139
|
+
);
|
141
140
|
},
|
142
141
|
);
|
@@ -38,23 +38,22 @@ export const ThreadListItemClient = resource(
|
|
38
38
|
};
|
39
39
|
}, [runtime, events]);
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
};
|
41
|
+
return tapApi<ThreadListItemClientApi>(
|
42
|
+
{
|
43
|
+
getState: () => runtimeState,
|
44
|
+
switchTo: runtime.switchTo,
|
45
|
+
rename: runtime.rename,
|
46
|
+
archive: runtime.archive,
|
47
|
+
unarchive: runtime.unarchive,
|
48
|
+
delete: runtime.delete,
|
49
|
+
generateTitle: runtime.generateTitle,
|
50
|
+
initialize: runtime.initialize,
|
51
|
+
detach: runtime.detach,
|
52
|
+
__internal_getRuntime: () => runtime,
|
53
|
+
},
|
54
|
+
{
|
55
|
+
key: runtimeState.id,
|
56
|
+
},
|
57
|
+
);
|
59
58
|
},
|
60
59
|
);
|
@@ -53,7 +53,7 @@ export const ThreadListClient = resource(
|
|
53
53
|
};
|
54
54
|
}, [runtimeState, threadItems.state, main.state]);
|
55
55
|
|
56
|
-
|
56
|
+
return tapApi<ThreadListClientApi>({
|
57
57
|
getState: () => state,
|
58
58
|
|
59
59
|
thread: () => main.api,
|
@@ -81,10 +81,5 @@ export const ThreadListClient = resource(
|
|
81
81
|
runtime.switchToNewThread();
|
82
82
|
},
|
83
83
|
});
|
84
|
-
|
85
|
-
return {
|
86
|
-
state,
|
87
|
-
api,
|
88
|
-
};
|
89
84
|
},
|
90
85
|
);
|
@@ -111,7 +111,7 @@ export const ThreadClient = resource(
|
|
111
111
|
};
|
112
112
|
}, [runtimeState, messages, composer.state]);
|
113
113
|
|
114
|
-
|
114
|
+
return tapApi<ThreadClientApi>({
|
115
115
|
getState: () => state,
|
116
116
|
|
117
117
|
composer: composer.api,
|
@@ -136,10 +136,5 @@ export const ThreadClient = resource(
|
|
136
136
|
|
137
137
|
__internal_getRuntime: () => runtime,
|
138
138
|
});
|
139
|
-
|
140
|
-
return {
|
141
|
-
state,
|
142
|
-
api,
|
143
|
-
};
|
144
139
|
},
|
145
140
|
);
|
@@ -34,15 +34,32 @@ class ReadonlyApiHandler<TApi extends ApiObject> implements ProxyHandler<TApi> {
|
|
34
34
|
}
|
35
35
|
}
|
36
36
|
|
37
|
-
export const tapApi = <TApi extends ApiObject
|
37
|
+
export const tapApi = <TApi extends ApiObject & { getState: () => any }>(
|
38
|
+
api: TApi,
|
39
|
+
options?: {
|
40
|
+
key?: string | undefined;
|
41
|
+
},
|
42
|
+
) => {
|
38
43
|
const ref = tapRef(() => api);
|
39
44
|
tapEffect(() => {
|
40
45
|
ref.current = api;
|
41
46
|
});
|
42
47
|
|
43
|
-
|
48
|
+
const apiProxy = tapMemo(
|
44
49
|
() =>
|
45
50
|
new Proxy<TApi>({} as TApi, new ReadonlyApiHandler(() => ref.current)),
|
46
51
|
[],
|
47
52
|
);
|
53
|
+
|
54
|
+
const key = options?.key;
|
55
|
+
const state = api.getState();
|
56
|
+
|
57
|
+
return tapMemo(
|
58
|
+
() => ({
|
59
|
+
key,
|
60
|
+
state,
|
61
|
+
api: apiProxy,
|
62
|
+
}),
|
63
|
+
[state, key],
|
64
|
+
);
|
48
65
|
};
|