@assistant-ui/core 0.1.9 → 0.1.10
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/adapters/index.d.ts +3 -0
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +1 -0
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/voice.d.ts +49 -0
- package/dist/adapters/voice.d.ts.map +1 -0
- package/dist/adapters/voice.js +109 -0
- package/dist/adapters/voice.js.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/model-context/types.d.ts +4 -0
- package/dist/model-context/types.d.ts.map +1 -1
- package/dist/model-context/types.js.map +1 -1
- package/dist/react/client/Interactables.d.ts.map +1 -1
- package/dist/react/client/Interactables.js +155 -65
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/interactable-model-context.d.ts +8 -0
- package/dist/react/client/interactable-model-context.d.ts.map +1 -0
- package/dist/react/client/interactable-model-context.js +62 -0
- package/dist/react/client/interactable-model-context.js.map +1 -0
- package/dist/react/index.d.ts +6 -3
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +5 -2
- package/dist/react/index.js.map +1 -1
- package/dist/react/model-context/useAssistantContext.d.ts +4 -0
- package/dist/react/model-context/useAssistantContext.d.ts.map +1 -0
- package/dist/react/model-context/useAssistantContext.js +18 -0
- package/dist/react/model-context/useAssistantContext.js.map +1 -0
- package/dist/react/model-context/useAssistantInteractable.d.ts +18 -0
- package/dist/react/model-context/useAssistantInteractable.d.ts.map +1 -0
- package/dist/react/model-context/useAssistantInteractable.js +31 -0
- package/dist/react/model-context/useAssistantInteractable.js.map +1 -0
- package/dist/react/model-context/useInteractableState.d.ts +15 -0
- package/dist/react/model-context/useInteractableState.d.ts.map +1 -0
- package/dist/react/model-context/useInteractableState.js +36 -0
- package/dist/react/model-context/useInteractableState.js.map +1 -0
- package/dist/react/model-context/useToolArgsStatus.d.ts +8 -0
- package/dist/react/model-context/useToolArgsStatus.d.ts.map +1 -0
- package/dist/react/model-context/useToolArgsStatus.js +31 -0
- package/dist/react/model-context/useToolArgsStatus.js.map +1 -0
- package/dist/react/primitive-hooks/useVoice.d.ts +10 -0
- package/dist/react/primitive-hooks/useVoice.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useVoice.js +28 -0
- package/dist/react/primitive-hooks/useVoice.js.map +1 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +14 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +14 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/useLocalRuntime.d.ts +1 -0
- package/dist/react/runtimes/useLocalRuntime.d.ts.map +1 -1
- package/dist/react/types/scopes/interactables.d.ts +17 -0
- package/dist/react/types/scopes/interactables.d.ts.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts +21 -1
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-runtime.js +25 -0
- package/dist/runtime/api/thread-runtime.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts +24 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js +205 -1
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts +14 -0
- package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-adapter.d.ts +2 -0
- package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +2 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js +3 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/local/local-runtime-options.d.ts +2 -0
- package/dist/runtimes/local/local-runtime-options.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts +2 -0
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +6 -0
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts +8 -0
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js +15 -6
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.js +17 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js +7 -8
- package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
- package/dist/store/scopes/thread.d.ts +9 -9
- package/dist/store/scopes/thread.d.ts.map +1 -1
- package/dist/types/message.d.ts +1 -0
- package/dist/types/message.d.ts.map +1 -1
- package/package.json +9 -15
- package/src/adapters/index.ts +5 -0
- package/src/adapters/voice.ts +166 -0
- package/src/index.ts +10 -0
- package/src/model-context/types.ts +5 -0
- package/src/react/client/Interactables.ts +221 -122
- package/src/react/client/interactable-model-context.ts +83 -0
- package/src/react/index.ts +19 -8
- package/src/react/model-context/useAssistantContext.ts +22 -0
- package/src/react/model-context/useAssistantInteractable.ts +47 -0
- package/src/react/model-context/useInteractableState.ts +63 -0
- package/src/react/model-context/useToolArgsStatus.ts +51 -0
- package/src/react/primitive-hooks/useVoice.ts +41 -0
- package/src/react/types/scopes/interactables.ts +22 -0
- package/src/runtime/api/thread-runtime.ts +41 -0
- package/src/runtime/base/base-thread-runtime-core.ts +243 -2
- package/src/runtime/interfaces/thread-runtime-core.ts +17 -0
- package/src/runtimes/external-store/external-store-adapter.ts +2 -0
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +3 -1
- package/src/runtimes/local/local-runtime-options.ts +2 -0
- package/src/runtimes/local/local-thread-runtime-core.ts +7 -0
- package/src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts +20 -6
- package/src/runtimes/remote-thread-list/empty-thread-core.ts +22 -1
- package/src/store/runtime-clients/thread-runtime-client.ts +7 -8
- package/src/store/scopes/thread.ts +9 -8
- package/src/types/message.ts +1 -0
- package/dist/react/model-context/makeInteractable.d.ts +0 -10
- package/dist/react/model-context/makeInteractable.d.ts.map +0 -1
- package/dist/react/model-context/makeInteractable.js +0 -10
- package/dist/react/model-context/makeInteractable.js.map +0 -1
- package/dist/react/model-context/useInteractable.d.ts +0 -16
- package/dist/react/model-context/useInteractable.d.ts.map +0 -1
- package/dist/react/model-context/useInteractable.js +0 -36
- package/dist/react/model-context/useInteractable.js.map +0 -1
- package/src/react/model-context/makeInteractable.ts +0 -21
- package/src/react/model-context/useInteractable.ts +0 -73
|
@@ -34,7 +34,6 @@ export class ReadonlyThreadRuntimeCore
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
getBranches(messageId: string) {
|
|
37
|
-
// no branching in readonly threads
|
|
38
37
|
const idx = this._messages.findIndex((m) => m.id === messageId);
|
|
39
38
|
if (idx === -1) return [];
|
|
40
39
|
return [messageId];
|
|
@@ -56,9 +55,7 @@ export class ReadonlyThreadRuntimeCore
|
|
|
56
55
|
throw READONLY_THREAD_ERROR;
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
cancelRun(): void {
|
|
60
|
-
// noop - nothing to cancel
|
|
61
|
-
}
|
|
58
|
+
cancelRun(): void {}
|
|
62
59
|
|
|
63
60
|
addToolResult(): void {
|
|
64
61
|
throw READONLY_THREAD_ERROR;
|
|
@@ -72,8 +69,23 @@ export class ReadonlyThreadRuntimeCore
|
|
|
72
69
|
throw READONLY_THREAD_ERROR;
|
|
73
70
|
}
|
|
74
71
|
|
|
75
|
-
stopSpeaking(): void {
|
|
76
|
-
|
|
72
|
+
stopSpeaking(): void {}
|
|
73
|
+
|
|
74
|
+
connectVoice(): void {
|
|
75
|
+
throw READONLY_THREAD_ERROR;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
disconnectVoice(): void {}
|
|
79
|
+
|
|
80
|
+
getVoiceVolume = () => 0;
|
|
81
|
+
subscribeVoiceVolume = (): Unsubscribe => () => {};
|
|
82
|
+
|
|
83
|
+
muteVoice(): void {
|
|
84
|
+
throw READONLY_THREAD_ERROR;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
unmuteVoice(): void {
|
|
88
|
+
throw READONLY_THREAD_ERROR;
|
|
77
89
|
}
|
|
78
90
|
|
|
79
91
|
submitFeedback(): void {
|
|
@@ -179,6 +191,7 @@ export class ReadonlyThreadRuntimeCore
|
|
|
179
191
|
}
|
|
180
192
|
|
|
181
193
|
speech = undefined;
|
|
194
|
+
voice = undefined;
|
|
182
195
|
|
|
183
196
|
capabilities = {
|
|
184
197
|
switchToBranch: false,
|
|
@@ -189,6 +202,7 @@ export class ReadonlyThreadRuntimeCore
|
|
|
189
202
|
unstable_copy: false,
|
|
190
203
|
speech: false,
|
|
191
204
|
dictation: false,
|
|
205
|
+
voice: false,
|
|
192
206
|
attachments: false,
|
|
193
207
|
feedback: false,
|
|
194
208
|
queue: false,
|
|
@@ -48,6 +48,25 @@ export const EMPTY_THREAD_CORE: ThreadRuntimeCore = {
|
|
|
48
48
|
throw EMPTY_THREAD_ERROR;
|
|
49
49
|
},
|
|
50
50
|
|
|
51
|
+
connectVoice() {
|
|
52
|
+
throw EMPTY_THREAD_ERROR;
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
disconnectVoice() {
|
|
56
|
+
throw EMPTY_THREAD_ERROR;
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
getVoiceVolume: () => 0,
|
|
60
|
+
subscribeVoiceVolume: () => () => {},
|
|
61
|
+
|
|
62
|
+
muteVoice() {
|
|
63
|
+
throw EMPTY_THREAD_ERROR;
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
unmuteVoice() {
|
|
67
|
+
throw EMPTY_THREAD_ERROR;
|
|
68
|
+
},
|
|
69
|
+
|
|
51
70
|
submitFeedback() {
|
|
52
71
|
throw EMPTY_THREAD_ERROR;
|
|
53
72
|
},
|
|
@@ -72,7 +91,7 @@ export const EMPTY_THREAD_CORE: ThreadRuntimeCore = {
|
|
|
72
91
|
attachments: [],
|
|
73
92
|
attachmentAccept: "*",
|
|
74
93
|
|
|
75
|
-
async addAttachment(
|
|
94
|
+
async addAttachment() {
|
|
76
95
|
throw EMPTY_THREAD_ERROR;
|
|
77
96
|
},
|
|
78
97
|
|
|
@@ -153,6 +172,7 @@ export const EMPTY_THREAD_CORE: ThreadRuntimeCore = {
|
|
|
153
172
|
},
|
|
154
173
|
|
|
155
174
|
speech: undefined,
|
|
175
|
+
voice: undefined,
|
|
156
176
|
|
|
157
177
|
capabilities: {
|
|
158
178
|
switchToBranch: false,
|
|
@@ -163,6 +183,7 @@ export const EMPTY_THREAD_CORE: ThreadRuntimeCore = {
|
|
|
163
183
|
unstable_copy: false,
|
|
164
184
|
speech: false,
|
|
165
185
|
dictation: false,
|
|
186
|
+
voice: false,
|
|
166
187
|
attachments: false,
|
|
167
188
|
feedback: false,
|
|
168
189
|
queue: false,
|
|
@@ -44,11 +44,9 @@ export const ThreadClient = resource(
|
|
|
44
44
|
const runtimeState = tapSubscribable(runtime);
|
|
45
45
|
const emit = tapAssistantEmit();
|
|
46
46
|
|
|
47
|
-
// Bind thread events to event manager
|
|
48
47
|
tapEffect(() => {
|
|
49
48
|
const unsubscribers: Unsubscribe[] = [];
|
|
50
49
|
|
|
51
|
-
// Subscribe to thread events
|
|
52
50
|
const threadEvents: ThreadRuntimeEventType[] = [
|
|
53
51
|
"runStart",
|
|
54
52
|
"runEnd",
|
|
@@ -105,6 +103,7 @@ export const ThreadClient = resource(
|
|
|
105
103
|
suggestions: runtimeState.suggestions,
|
|
106
104
|
extras: runtimeState.extras,
|
|
107
105
|
speech: runtimeState.speech,
|
|
106
|
+
voice: runtimeState.voice,
|
|
108
107
|
|
|
109
108
|
composer: composer.state,
|
|
110
109
|
messages: messages.state,
|
|
@@ -124,12 +123,12 @@ export const ThreadClient = resource(
|
|
|
124
123
|
import: runtime.import,
|
|
125
124
|
reset: runtime.reset,
|
|
126
125
|
stopSpeaking: runtime.stopSpeaking,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
126
|
+
connectVoice: runtime.connectVoice,
|
|
127
|
+
disconnectVoice: runtime.disconnectVoice,
|
|
128
|
+
getVoiceVolume: runtime.getVoiceVolume,
|
|
129
|
+
subscribeVoiceVolume: runtime.subscribeVoiceVolume,
|
|
130
|
+
muteVoice: runtime.muteVoice,
|
|
131
|
+
unmuteVoice: runtime.unmuteVoice,
|
|
133
132
|
message: (selector) => {
|
|
134
133
|
if ("id" in selector) {
|
|
135
134
|
return messages.get({ key: selector.id });
|
|
@@ -2,9 +2,11 @@ import type { ReadonlyJSONValue } from "assistant-stream/utils";
|
|
|
2
2
|
import type {
|
|
3
3
|
RuntimeCapabilities,
|
|
4
4
|
SpeechState,
|
|
5
|
+
VoiceSessionState,
|
|
5
6
|
ThreadSuggestion,
|
|
6
7
|
} from "../../runtime/interfaces/thread-runtime-core";
|
|
7
8
|
import type { ExportedMessageRepository } from "../../runtime/utils/message-repository";
|
|
9
|
+
import type { Unsubscribe } from "../../types/unsubscribe";
|
|
8
10
|
import type { ThreadMessageLike } from "../../runtime/utils/thread-message-like";
|
|
9
11
|
import type {
|
|
10
12
|
CreateAppendMessage,
|
|
@@ -56,6 +58,7 @@ export type ThreadState = {
|
|
|
56
58
|
readonly extras: unknown;
|
|
57
59
|
/** @deprecated This API is still under active development and might change without notice. */
|
|
58
60
|
readonly speech: SpeechState | undefined;
|
|
61
|
+
readonly voice: VoiceSessionState | undefined;
|
|
59
62
|
readonly composer: ComposerState;
|
|
60
63
|
};
|
|
61
64
|
|
|
@@ -112,14 +115,12 @@ export type ThreadMethods = {
|
|
|
112
115
|
message(selector: { id: string } | { index: number }): MessageMethods;
|
|
113
116
|
/** @deprecated This API is still under active development and might change without notice. */
|
|
114
117
|
stopSpeaking(): void;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
*/
|
|
122
|
-
stopVoice(): Promise<void>;
|
|
118
|
+
connectVoice(): void;
|
|
119
|
+
disconnectVoice(): void;
|
|
120
|
+
getVoiceVolume(): number;
|
|
121
|
+
subscribeVoiceVolume(callback: () => void): Unsubscribe;
|
|
122
|
+
muteVoice(): void;
|
|
123
|
+
unmuteVoice(): void;
|
|
123
124
|
__internal_getRuntime?(): ThreadRuntime;
|
|
124
125
|
};
|
|
125
126
|
|
package/src/types/message.ts
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { FC } from "react";
|
|
2
|
-
import { type UseInteractableConfig } from "./useInteractable.js";
|
|
3
|
-
export type InteractableConfig<TState> = UseInteractableConfig<TState> & {
|
|
4
|
-
name: string;
|
|
5
|
-
};
|
|
6
|
-
export type AssistantInteractable = FC & {
|
|
7
|
-
unstable_interactable: InteractableConfig<any>;
|
|
8
|
-
};
|
|
9
|
-
export declare const makeInteractable: <TState>(config: InteractableConfig<TState>) => AssistantInteractable;
|
|
10
|
-
//# sourceMappingURL=makeInteractable.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"makeInteractable.d.ts","sourceRoot":"","sources":["../../../src/react/model-context/makeInteractable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAmB,KAAK,qBAAqB,EAAE,6BAA0B;AAEhF,MAAM,MAAM,kBAAkB,CAAC,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,GAAG;IACvE,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,EAAE,GAAG;IACvC,qBAAqB,EAAE,kBAAkB,CAAC,GAAG,CAAC,CAAC;CAChD,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,MAAM,EACrC,QAAQ,kBAAkB,CAAC,MAAM,CAAC,0BAQnC,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { useInteractable } from "./useInteractable.js";
|
|
2
|
-
export const makeInteractable = (config) => {
|
|
3
|
-
const Interactable = () => {
|
|
4
|
-
useInteractable(config.name, config);
|
|
5
|
-
return null;
|
|
6
|
-
};
|
|
7
|
-
Interactable.unstable_interactable = config;
|
|
8
|
-
return Interactable;
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=makeInteractable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"makeInteractable.js","sourceRoot":"","sources":["../../../src/react/model-context/makeInteractable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAA8B,6BAA0B;AAUhF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,MAAkC,EAClC,EAAE;IACF,MAAM,YAAY,GAA0B,GAAG,EAAE;QAC/C,eAAe,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IACF,YAAY,CAAC,qBAAqB,GAAG,MAAM,CAAC;IAC5C,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { InteractableStateSchema } from "../types/scopes/interactables.js";
|
|
2
|
-
export type UseInteractableConfig<TState> = {
|
|
3
|
-
description: string;
|
|
4
|
-
stateSchema: InteractableStateSchema;
|
|
5
|
-
initialState: TState;
|
|
6
|
-
id?: string;
|
|
7
|
-
selected?: boolean;
|
|
8
|
-
};
|
|
9
|
-
type StateUpdater<TState> = TState | ((prev: TState) => TState);
|
|
10
|
-
export type UseInteractableMetadata = {
|
|
11
|
-
id: string;
|
|
12
|
-
setSelected: (selected: boolean) => void;
|
|
13
|
-
};
|
|
14
|
-
export declare const useInteractable: <TState>(name: string, config: UseInteractableConfig<TState>) => [TState, (updater: StateUpdater<TState>) => void, UseInteractableMetadata];
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=useInteractable.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useInteractable.d.ts","sourceRoot":"","sources":["../../../src/react/model-context/useInteractable.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,yCAAsC;AAE7E,MAAM,MAAM,qBAAqB,CAAC,MAAM,IAAI;IAC1C,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,uBAAuB,CAAC;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,KAAK,YAAY,CAAC,MAAM,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;AAEhE,MAAM,MAAM,uBAAuB,GAAG;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1C,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,MAAM,EACpC,MAAM,MAAM,EACZ,QAAQ,qBAAqB,CAAC,MAAM,CAAC,KACpC,CACD,MAAM,EACN,CAAC,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,KAAK,IAAI,EACvC,uBAAuB,CA+CxB,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { useEffect, useCallback, useId, useRef } from "react";
|
|
2
|
-
import { useAui, useAuiState } from "@assistant-ui/store";
|
|
3
|
-
export const useInteractable = (name, config) => {
|
|
4
|
-
const aui = useAui();
|
|
5
|
-
const autoId = useId().replace(/[^a-zA-Z0-9]/g, "");
|
|
6
|
-
const id = config.id ?? autoId;
|
|
7
|
-
const stateSchemaRef = useRef(config.stateSchema);
|
|
8
|
-
stateSchemaRef.current = config.stateSchema;
|
|
9
|
-
const initialStateRef = useRef(config.initialState);
|
|
10
|
-
initialStateRef.current = config.initialState;
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
return aui.interactables().register({
|
|
13
|
-
id,
|
|
14
|
-
name,
|
|
15
|
-
description: config.description,
|
|
16
|
-
stateSchema: stateSchemaRef.current,
|
|
17
|
-
initialState: initialStateRef.current,
|
|
18
|
-
selected: config.selected,
|
|
19
|
-
});
|
|
20
|
-
}, [aui, id, name, config.description, config.selected]);
|
|
21
|
-
const state = useAuiState((s) => s.interactables.definitions[id]?.state) ??
|
|
22
|
-
config.initialState;
|
|
23
|
-
const setState = useCallback((updater) => {
|
|
24
|
-
aui.interactables().setState(id, (prev) => {
|
|
25
|
-
if (typeof updater === "function") {
|
|
26
|
-
return updater(prev);
|
|
27
|
-
}
|
|
28
|
-
return updater;
|
|
29
|
-
});
|
|
30
|
-
}, [aui, id]);
|
|
31
|
-
const setSelected = useCallback((selected) => {
|
|
32
|
-
aui.interactables().setSelected(id, selected);
|
|
33
|
-
}, [aui, id]);
|
|
34
|
-
return [state, setState, { id, setSelected }];
|
|
35
|
-
};
|
|
36
|
-
//# sourceMappingURL=useInteractable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useInteractable.js","sourceRoot":"","sources":["../../../src/react/model-context/useInteractable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAkB1D,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,IAAY,EACZ,MAAqC,EAKrC,EAAE;IACF,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;IAErB,MAAM,MAAM,GAAG,KAAK,EAAE,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;IACpD,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC;IAE/B,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAClD,cAAc,CAAC,OAAO,GAAG,MAAM,CAAC,WAAW,CAAC;IAC5C,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACpD,eAAe,CAAC,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC;IAE9C,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,GAAG,CAAC,aAAa,EAAE,CAAC,QAAQ,CAAC;YAClC,EAAE;YACF,IAAI;YACJ,WAAW,EAAE,MAAM,CAAC,WAAW;YAC/B,WAAW,EAAE,cAAc,CAAC,OAAO;YACnC,YAAY,EAAE,eAAe,CAAC,OAAO;YACrC,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEzD,MAAM,KAAK,GACR,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,KAAK,CAAY;QACtE,MAAM,CAAC,YAAY,CAAC;IAEtB,MAAM,QAAQ,GAAG,WAAW,CAC1B,CAAC,OAA6B,EAAE,EAAE;QAChC,GAAG,CAAC,aAAa,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;YACxC,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;gBAClC,OAAQ,OAAoC,CAAC,IAAc,CAAC,CAAC;YAC/D,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC,EACD,CAAC,GAAG,EAAE,EAAE,CAAC,CACV,CAAC;IAEF,MAAM,WAAW,GAAG,WAAW,CAC7B,CAAC,QAAiB,EAAE,EAAE;QACpB,GAAG,CAAC,aAAa,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;IAChD,CAAC,EACD,CAAC,GAAG,EAAE,EAAE,CAAC,CACV,CAAC;IAEF,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;AAChD,CAAC,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { FC } from "react";
|
|
2
|
-
import { useInteractable, type UseInteractableConfig } from "./useInteractable";
|
|
3
|
-
|
|
4
|
-
export type InteractableConfig<TState> = UseInteractableConfig<TState> & {
|
|
5
|
-
name: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type AssistantInteractable = FC & {
|
|
9
|
-
unstable_interactable: InteractableConfig<any>;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const makeInteractable = <TState>(
|
|
13
|
-
config: InteractableConfig<TState>,
|
|
14
|
-
) => {
|
|
15
|
-
const Interactable: AssistantInteractable = () => {
|
|
16
|
-
useInteractable(config.name, config);
|
|
17
|
-
return null;
|
|
18
|
-
};
|
|
19
|
-
Interactable.unstable_interactable = config;
|
|
20
|
-
return Interactable;
|
|
21
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { useEffect, useCallback, useId, useRef } from "react";
|
|
2
|
-
import { useAui, useAuiState } from "@assistant-ui/store";
|
|
3
|
-
import type { InteractableStateSchema } from "../types/scopes/interactables";
|
|
4
|
-
|
|
5
|
-
export type UseInteractableConfig<TState> = {
|
|
6
|
-
description: string;
|
|
7
|
-
stateSchema: InteractableStateSchema;
|
|
8
|
-
initialState: TState;
|
|
9
|
-
id?: string;
|
|
10
|
-
selected?: boolean;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
type StateUpdater<TState> = TState | ((prev: TState) => TState);
|
|
14
|
-
|
|
15
|
-
export type UseInteractableMetadata = {
|
|
16
|
-
id: string;
|
|
17
|
-
setSelected: (selected: boolean) => void;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const useInteractable = <TState>(
|
|
21
|
-
name: string,
|
|
22
|
-
config: UseInteractableConfig<TState>,
|
|
23
|
-
): [
|
|
24
|
-
TState,
|
|
25
|
-
(updater: StateUpdater<TState>) => void,
|
|
26
|
-
UseInteractableMetadata,
|
|
27
|
-
] => {
|
|
28
|
-
const aui = useAui();
|
|
29
|
-
|
|
30
|
-
const autoId = useId().replace(/[^a-zA-Z0-9]/g, "");
|
|
31
|
-
const id = config.id ?? autoId;
|
|
32
|
-
|
|
33
|
-
const stateSchemaRef = useRef(config.stateSchema);
|
|
34
|
-
stateSchemaRef.current = config.stateSchema;
|
|
35
|
-
const initialStateRef = useRef(config.initialState);
|
|
36
|
-
initialStateRef.current = config.initialState;
|
|
37
|
-
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
return aui.interactables().register({
|
|
40
|
-
id,
|
|
41
|
-
name,
|
|
42
|
-
description: config.description,
|
|
43
|
-
stateSchema: stateSchemaRef.current,
|
|
44
|
-
initialState: initialStateRef.current,
|
|
45
|
-
selected: config.selected,
|
|
46
|
-
});
|
|
47
|
-
}, [aui, id, name, config.description, config.selected]);
|
|
48
|
-
|
|
49
|
-
const state =
|
|
50
|
-
(useAuiState((s) => s.interactables.definitions[id]?.state) as TState) ??
|
|
51
|
-
config.initialState;
|
|
52
|
-
|
|
53
|
-
const setState = useCallback(
|
|
54
|
-
(updater: StateUpdater<TState>) => {
|
|
55
|
-
aui.interactables().setState(id, (prev) => {
|
|
56
|
-
if (typeof updater === "function") {
|
|
57
|
-
return (updater as (prev: TState) => TState)(prev as TState);
|
|
58
|
-
}
|
|
59
|
-
return updater;
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
[aui, id],
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
const setSelected = useCallback(
|
|
66
|
-
(selected: boolean) => {
|
|
67
|
-
aui.interactables().setSelected(id, selected);
|
|
68
|
-
},
|
|
69
|
-
[aui, id],
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
return [state, setState, { id, setSelected }];
|
|
73
|
-
};
|