@assistant-ui/store 0.0.4 → 0.0.5
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/AssistantIf.d.ts +1 -1
- package/dist/AssistantIf.d.ts.map +1 -1
- package/dist/AssistantIf.js +3 -8
- package/dist/AssistantIf.js.map +1 -1
- package/dist/Derived.d.ts +1 -1
- package/dist/Derived.d.ts.map +1 -1
- package/dist/Derived.js +21 -8
- package/dist/Derived.js.map +1 -1
- package/dist/attachDefaultPeers.d.ts +2 -2
- package/dist/attachDefaultPeers.d.ts.map +1 -1
- package/dist/attachDefaultPeers.js +47 -18
- package/dist/attachDefaultPeers.js.map +1 -1
- package/dist/index.d.ts +14 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -29
- package/dist/index.js.map +1 -1
- package/dist/tapClientList.d.ts +1 -1
- package/dist/tapClientList.d.ts.map +1 -1
- package/dist/tapClientList.js +56 -66
- package/dist/tapClientList.js.map +1 -1
- package/dist/tapClientLookup.d.ts +1 -1
- package/dist/tapClientLookup.d.ts.map +1 -1
- package/dist/tapClientLookup.js +25 -37
- package/dist/tapClientLookup.js.map +1 -1
- package/dist/tapClientResource.d.ts +1 -1
- package/dist/tapClientResource.d.ts.map +1 -1
- package/dist/tapClientResource.js +85 -88
- package/dist/tapClientResource.js.map +1 -1
- package/dist/types/client.d.ts +1 -1
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/client.js +1 -0
- package/dist/types/client.js.map +1 -1
- package/dist/types/events.d.ts +1 -1
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/events.js +6 -10
- package/dist/types/events.js.map +1 -1
- package/dist/useAssistantClient.d.ts +2 -2
- package/dist/useAssistantClient.d.ts.map +1 -1
- package/dist/useAssistantClient.js +118 -194
- package/dist/useAssistantClient.js.map +1 -1
- package/dist/useAssistantEvent.d.ts +1 -1
- package/dist/useAssistantEvent.d.ts.map +1 -1
- package/dist/useAssistantEvent.js +5 -9
- package/dist/useAssistantEvent.js.map +1 -1
- package/dist/useAssistantState.d.ts +1 -1
- package/dist/useAssistantState.d.ts.map +1 -1
- package/dist/useAssistantState.js +24 -19
- package/dist/useAssistantState.js.map +1 -1
- package/dist/utils/BaseProxyHandler.js +43 -38
- package/dist/utils/BaseProxyHandler.js.map +1 -1
- package/dist/utils/NotificationManager.d.ts +3 -3
- package/dist/utils/NotificationManager.d.ts.map +1 -1
- package/dist/utils/NotificationManager.js +76 -77
- package/dist/utils/NotificationManager.js.map +1 -1
- package/dist/utils/StoreResource.d.ts +1 -1
- package/dist/utils/StoreResource.d.ts.map +1 -1
- package/dist/utils/StoreResource.js +5 -16
- package/dist/utils/StoreResource.js.map +1 -1
- package/dist/utils/proxied-assistant-state.d.ts +1 -1
- package/dist/utils/proxied-assistant-state.d.ts.map +1 -1
- package/dist/utils/proxied-assistant-state.js +26 -33
- package/dist/utils/proxied-assistant-state.js.map +1 -1
- package/dist/utils/react-assistant-context.d.ts +1 -1
- package/dist/utils/react-assistant-context.d.ts.map +1 -1
- package/dist/utils/react-assistant-context.js +61 -66
- package/dist/utils/react-assistant-context.js.map +1 -1
- package/dist/utils/splitClients.d.ts +3 -3
- package/dist/utils/splitClients.d.ts.map +1 -1
- package/dist/utils/splitClients.js +48 -31
- package/dist/utils/splitClients.js.map +1 -1
- package/dist/utils/tap-assistant-context.d.ts +3 -3
- package/dist/utils/tap-assistant-context.d.ts.map +1 -1
- package/dist/utils/tap-assistant-context.js +17 -31
- package/dist/utils/tap-assistant-context.js.map +1 -1
- package/dist/utils/tap-client-stack-context.d.ts +1 -1
- package/dist/utils/tap-client-stack-context.d.ts.map +1 -1
- package/dist/utils/tap-client-stack-context.js +24 -26
- package/dist/utils/tap-client-stack-context.js.map +1 -1
- package/package.json +23 -9
|
@@ -1,227 +1,151 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
// src/useAssistantClient.tsx
|
|
4
2
|
import { useResource } from "@assistant-ui/tap/react";
|
|
5
|
-
import {
|
|
6
|
-
resource,
|
|
7
|
-
tapMemo,
|
|
8
|
-
tapResources,
|
|
9
|
-
tapEffectEvent,
|
|
10
|
-
tapInlineResource,
|
|
11
|
-
tapEffect,
|
|
12
|
-
tapRef,
|
|
13
|
-
tapResource
|
|
14
|
-
} from "@assistant-ui/tap";
|
|
3
|
+
import { resource, tapMemo, tapResources, tapEffectEvent, tapInlineResource, tapEffect, tapRef, tapResource, } from "@assistant-ui/tap";
|
|
15
4
|
import { StoreResource } from "./utils/StoreResource.js";
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
createRootAssistantClient
|
|
20
|
-
} from "./utils/react-assistant-context.js";
|
|
21
|
-
import {
|
|
22
|
-
splitClients
|
|
23
|
-
} from "./utils/splitClients.js";
|
|
24
|
-
import {
|
|
25
|
-
normalizeEventSelector
|
|
26
|
-
} from "./types/events.js";
|
|
5
|
+
import { useAssistantContextValue, DefaultAssistantClient, createRootAssistantClient, } from "./utils/react-assistant-context.js";
|
|
6
|
+
import { splitClients, } from "./utils/splitClients.js";
|
|
7
|
+
import { normalizeEventSelector, } from "./types/events.js";
|
|
27
8
|
import { NotificationManager } from "./utils/NotificationManager.js";
|
|
28
9
|
import { withAssistantTapContextProvider } from "./utils/tap-assistant-context.js";
|
|
29
10
|
import { tapClientResource } from "./tapClientResource.js";
|
|
30
11
|
import { getClientIndex } from "./utils/tap-client-stack-context.js";
|
|
31
|
-
import {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} from "./utils/proxied-assistant-state.js";
|
|
35
|
-
var RootClientResource = resource(
|
|
36
|
-
({
|
|
37
|
-
element,
|
|
38
|
-
emit,
|
|
39
|
-
clientRef
|
|
40
|
-
}) => {
|
|
41
|
-
const { methods, state } = withAssistantTapContextProvider(
|
|
42
|
-
{ clientRef, emit },
|
|
43
|
-
() => tapClientResource(element)
|
|
44
|
-
);
|
|
12
|
+
import { PROXIED_ASSISTANT_STATE_SYMBOL, createProxiedAssistantState, } from "./utils/proxied-assistant-state.js";
|
|
13
|
+
const RootClientResource = resource(({ element, emit, clientRef, }) => {
|
|
14
|
+
const { methods, state } = withAssistantTapContextProvider({ clientRef, emit }, () => tapClientResource(element));
|
|
45
15
|
return tapMemo(() => ({ methods }), [state]);
|
|
46
|
-
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
({
|
|
50
|
-
element,
|
|
51
|
-
notifications,
|
|
52
|
-
clientRef
|
|
53
|
-
}) => {
|
|
54
|
-
const store = tapInlineResource(
|
|
55
|
-
StoreResource(
|
|
56
|
-
RootClientResource({ element, emit: notifications.emit, clientRef })
|
|
57
|
-
)
|
|
58
|
-
);
|
|
16
|
+
});
|
|
17
|
+
const RootClientAccessorResource = resource(({ element, notifications, clientRef, }) => {
|
|
18
|
+
const store = tapInlineResource(StoreResource(RootClientResource({ element, emit: notifications.emit, clientRef })));
|
|
59
19
|
tapEffect(() => {
|
|
60
|
-
|
|
20
|
+
return store.subscribe(notifications.notifySubscribers);
|
|
61
21
|
}, [store, notifications]);
|
|
62
22
|
return tapMemo(() => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
23
|
+
const clientFunction = () => store.getState().methods;
|
|
24
|
+
clientFunction.source = "root";
|
|
25
|
+
clientFunction.query = {};
|
|
26
|
+
return clientFunction;
|
|
67
27
|
}, [store]);
|
|
68
|
-
}
|
|
69
|
-
);
|
|
70
|
-
var NoOpRootClientsAccessorsResource = resource(() => {
|
|
71
|
-
return tapMemo(
|
|
72
|
-
() => ({ clients: {}, subscribe: void 0, on: void 0 }),
|
|
73
|
-
[]
|
|
74
|
-
);
|
|
75
28
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}) => {
|
|
29
|
+
const NoOpRootClientsAccessorsResource = resource(() => {
|
|
30
|
+
return tapMemo(() => ({ clients: {}, subscribe: undefined, on: undefined }), []);
|
|
31
|
+
});
|
|
32
|
+
const RootClientsAccessorsResource = resource(({ clients: inputClients, clientRef, }) => {
|
|
81
33
|
const notifications = tapInlineResource(NotificationManager());
|
|
82
|
-
tapEffect(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
);
|
|
86
|
-
const results = tapResources(
|
|
87
|
-
inputClients,
|
|
88
|
-
(element) => RootClientAccessorResource({
|
|
89
|
-
element,
|
|
34
|
+
tapEffect(() => clientRef.parent.subscribe(notifications.notifySubscribers), [clientRef, notifications]);
|
|
35
|
+
const results = tapResources(inputClients, (element) => RootClientAccessorResource({
|
|
36
|
+
element: element,
|
|
90
37
|
notifications,
|
|
91
|
-
clientRef
|
|
92
|
-
|
|
93
|
-
[notifications, clientRef]
|
|
94
|
-
);
|
|
38
|
+
clientRef,
|
|
39
|
+
}), [notifications, clientRef]);
|
|
95
40
|
return tapMemo(() => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
};
|
|
41
|
+
return {
|
|
42
|
+
clients: results,
|
|
43
|
+
subscribe: notifications.subscribe,
|
|
44
|
+
on: function (selector, callback) {
|
|
45
|
+
if (!this) {
|
|
46
|
+
throw new Error("const { on } = useAssistantClient() is not supported. Use aui.on() instead.");
|
|
47
|
+
}
|
|
48
|
+
const { scope, event } = normalizeEventSelector(selector);
|
|
49
|
+
if (scope !== "*") {
|
|
50
|
+
const source = this[scope].source;
|
|
51
|
+
if (source === null) {
|
|
52
|
+
throw new Error(`Scope "${scope}" is not available. Use { scope: "*", event: "${event}" } to listen globally.`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const localUnsub = notifications.on(event, (payload, clientStack) => {
|
|
56
|
+
if (scope === "*") {
|
|
57
|
+
callback(payload);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const scopeClient = this[scope]();
|
|
61
|
+
const index = getClientIndex(scopeClient);
|
|
62
|
+
if (scopeClient === clientStack[index]) {
|
|
63
|
+
callback(payload);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
if (scope !== "*" &&
|
|
67
|
+
clientRef.parent[scope].source === null)
|
|
68
|
+
return localUnsub;
|
|
69
|
+
const parentUnsub = clientRef.parent.on(selector, callback);
|
|
70
|
+
return () => {
|
|
71
|
+
localUnsub();
|
|
72
|
+
parentUnsub();
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
};
|
|
134
76
|
}, [results, notifications, clientRef]);
|
|
135
|
-
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
77
|
+
});
|
|
78
|
+
const getMeta = (props, clientRef, memo) => {
|
|
79
|
+
if ("source" in props && "query" in props)
|
|
80
|
+
return props;
|
|
81
|
+
if (memo.dep === props)
|
|
82
|
+
return memo.meta;
|
|
83
|
+
const meta = props.getMeta(clientRef.current);
|
|
84
|
+
memo.meta = meta;
|
|
85
|
+
memo.dep = props;
|
|
86
|
+
return meta;
|
|
144
87
|
};
|
|
145
|
-
|
|
146
|
-
({
|
|
147
|
-
element,
|
|
148
|
-
clientRef
|
|
149
|
-
}) => {
|
|
88
|
+
const DerivedClientAccessorResource = resource(({ element, clientRef, }) => {
|
|
150
89
|
const get = tapEffectEvent(() => element.props);
|
|
151
90
|
return tapMemo(() => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
91
|
+
const clientFunction = () => get().get(clientRef.current);
|
|
92
|
+
const metaMemo = {};
|
|
93
|
+
Object.defineProperties(clientFunction, {
|
|
94
|
+
source: {
|
|
95
|
+
get: () => getMeta(get(), clientRef, metaMemo).source,
|
|
96
|
+
},
|
|
97
|
+
query: {
|
|
98
|
+
get: () => getMeta(get(), clientRef, metaMemo).query,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
return clientFunction;
|
|
163
102
|
}, [clientRef]);
|
|
164
|
-
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
clientRef
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
clientRef
|
|
176
|
-
}),
|
|
177
|
-
[clientRef]
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
);
|
|
181
|
-
var AssistantClientResource = resource(
|
|
182
|
-
({
|
|
183
|
-
baseClient,
|
|
184
|
-
clients
|
|
185
|
-
}) => {
|
|
103
|
+
});
|
|
104
|
+
const DerivedClientsAccessorsResource = resource(({ clients, clientRef, }) => {
|
|
105
|
+
return tapResources(clients, (element) => DerivedClientAccessorResource({
|
|
106
|
+
element: element,
|
|
107
|
+
clientRef,
|
|
108
|
+
}), [clientRef]);
|
|
109
|
+
});
|
|
110
|
+
/**
|
|
111
|
+
* Resource that creates an extended AssistantClient.
|
|
112
|
+
*/
|
|
113
|
+
export const AssistantClientResource = resource(({ baseClient, clients, }) => {
|
|
186
114
|
const { rootClients, derivedClients } = splitClients(clients, baseClient);
|
|
187
115
|
const clientRef = tapRef({
|
|
188
|
-
|
|
189
|
-
|
|
116
|
+
parent: baseClient,
|
|
117
|
+
current: null,
|
|
190
118
|
}).current;
|
|
191
|
-
const rootFields = tapResource(
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const derivedFields = tapInlineResource(
|
|
195
|
-
DerivedClientsAccessorsResource({ clients: derivedClients, clientRef })
|
|
196
|
-
);
|
|
119
|
+
const rootFields = tapResource(Object.keys(rootClients).length > 0
|
|
120
|
+
? RootClientsAccessorsResource({ clients: rootClients, clientRef })
|
|
121
|
+
: NoOpRootClientsAccessorsResource());
|
|
122
|
+
const derivedFields = tapInlineResource(DerivedClientsAccessorsResource({ clients: derivedClients, clientRef }));
|
|
197
123
|
const client = tapMemo(() => {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
124
|
+
// Swap DefaultAssistantClient -> createRootAssistantClient at root to change error message
|
|
125
|
+
const proto = baseClient === DefaultAssistantClient
|
|
126
|
+
? createRootAssistantClient()
|
|
127
|
+
: baseClient;
|
|
128
|
+
const client = Object.create(proto);
|
|
129
|
+
Object.assign(client, rootFields.clients, derivedFields, {
|
|
130
|
+
subscribe: rootFields.subscribe ?? baseClient.subscribe,
|
|
131
|
+
on: rootFields.on ?? baseClient.on,
|
|
132
|
+
[PROXIED_ASSISTANT_STATE_SYMBOL]: createProxiedAssistantState(client),
|
|
133
|
+
});
|
|
134
|
+
return client;
|
|
206
135
|
}, [baseClient, rootFields, derivedFields]);
|
|
207
136
|
if (clientRef.current === null) {
|
|
208
|
-
|
|
137
|
+
clientRef.current = client;
|
|
209
138
|
}
|
|
210
139
|
tapEffect(() => {
|
|
211
|
-
|
|
140
|
+
clientRef.current = client;
|
|
212
141
|
});
|
|
213
142
|
return client;
|
|
214
|
-
|
|
215
|
-
)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return baseClient;
|
|
143
|
+
});
|
|
144
|
+
export function useAssistantClient(clients) {
|
|
145
|
+
const baseClient = useAssistantContextValue();
|
|
146
|
+
if (clients) {
|
|
147
|
+
return useResource(AssistantClientResource({ baseClient, clients }));
|
|
148
|
+
}
|
|
149
|
+
return baseClient;
|
|
222
150
|
}
|
|
223
|
-
export {
|
|
224
|
-
AssistantClientResource,
|
|
225
|
-
useAssistantClient
|
|
226
|
-
};
|
|
227
151
|
//# sourceMappingURL=useAssistantClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useAssistantClient.tsx"],"sourcesContent":["\"use client\";\n\nimport { useResource } from \"@assistant-ui/tap/react\";\nimport {\n resource,\n tapMemo,\n tapResources,\n tapEffectEvent,\n tapInlineResource,\n tapEffect,\n tapRef,\n tapResource,\n} from \"@assistant-ui/tap\";\nimport type {\n AssistantClient,\n AssistantClientAccessor,\n ClientNames,\n ClientElement,\n ClientMeta,\n} from \"./types/client\";\nimport { Derived, DerivedElement } from \"./Derived\";\nimport { StoreResource } from \"./utils/StoreResource\";\nimport {\n useAssistantContextValue,\n DefaultAssistantClient,\n createRootAssistantClient,\n} from \"./utils/react-assistant-context\";\nimport {\n DerivedClients,\n RootClients,\n splitClients,\n} from \"./utils/splitClients\";\nimport {\n normalizeEventSelector,\n type AssistantEventName,\n type AssistantEventCallback,\n type AssistantEventSelector,\n} from \"./types/events\";\nimport { NotificationManager } from \"./utils/NotificationManager\";\nimport { withAssistantTapContextProvider } from \"./utils/tap-assistant-context\";\nimport { tapClientResource } from \"./tapClientResource\";\nimport { getClientIndex } from \"./utils/tap-client-stack-context\";\nimport {\n PROXIED_ASSISTANT_STATE_SYMBOL,\n createProxiedAssistantState,\n} from \"./utils/proxied-assistant-state\";\n\nconst RootClientResource = resource(\n <K extends ClientNames>({\n element,\n emit,\n clientRef,\n }: {\n element: ClientElement<K>;\n emit: NotificationManager[\"emit\"];\n clientRef: { parent: AssistantClient; current: AssistantClient | null };\n }) => {\n const { methods, state } = withAssistantTapContextProvider(\n { clientRef, emit },\n () => tapClientResource(element),\n );\n return tapMemo(() => ({ methods }), [state]);\n },\n);\n\nconst RootClientAccessorResource = resource(\n <K extends ClientNames>({\n element,\n notifications,\n clientRef,\n }: {\n element: ClientElement<K>;\n notifications: NotificationManager;\n clientRef: { parent: AssistantClient; current: AssistantClient | null };\n }): AssistantClientAccessor<K> => {\n const store = tapInlineResource(\n StoreResource(\n RootClientResource({ element, emit: notifications.emit, clientRef }),\n ),\n );\n\n tapEffect(() => {\n return store.subscribe(notifications.notifySubscribers);\n }, [store, notifications]);\n\n return tapMemo(() => {\n const clientFunction = () => store.getState().methods;\n clientFunction.source = \"root\" as const;\n clientFunction.query = {};\n return clientFunction;\n }, [store]);\n },\n);\n\nconst NoOpRootClientsAccessorsResource = resource(() => {\n return tapMemo(\n () => ({ clients: {}, subscribe: undefined, on: undefined }),\n [],\n );\n});\n\nconst RootClientsAccessorsResource = resource(\n ({\n clients: inputClients,\n clientRef,\n }: {\n clients: RootClients;\n clientRef: { parent: AssistantClient; current: AssistantClient | null };\n }) => {\n const notifications = tapInlineResource(NotificationManager());\n\n tapEffect(\n () => clientRef.parent.subscribe(notifications.notifySubscribers),\n [clientRef, notifications],\n );\n\n const results = tapResources(\n inputClients,\n (element) =>\n RootClientAccessorResource({\n element: element!,\n notifications,\n clientRef,\n }),\n [notifications, clientRef],\n );\n\n return tapMemo(() => {\n return {\n clients: results,\n subscribe: notifications.subscribe,\n on: function <TEvent extends AssistantEventName>(\n this: AssistantClient,\n selector: AssistantEventSelector<TEvent>,\n callback: AssistantEventCallback<TEvent>,\n ) {\n if (!this) {\n throw new Error(\n \"const { on } = useAssistantClient() is not supported. Use aui.on() instead.\",\n );\n }\n\n const { scope, event } = normalizeEventSelector(selector);\n\n if (scope !== \"*\") {\n const source = this[scope as ClientNames].source;\n if (source === null) {\n throw new Error(\n `Scope \"${scope}\" is not available. Use { scope: \"*\", event: \"${event}\" } to listen globally.`,\n );\n }\n }\n\n const localUnsub = notifications.on(event, (payload, clientStack) => {\n if (scope === \"*\") {\n callback(payload);\n return;\n }\n\n const scopeClient = this[scope as ClientNames]();\n const index = getClientIndex(scopeClient);\n if (scopeClient === clientStack[index]) {\n callback(payload);\n }\n });\n if (\n scope !== \"*\" &&\n clientRef.parent[scope as ClientNames].source === null\n )\n return localUnsub;\n\n const parentUnsub = clientRef.parent.on(selector, callback);\n\n return () => {\n localUnsub();\n parentUnsub();\n };\n },\n };\n }, [results, notifications, clientRef]);\n },\n);\n\ntype MetaMemo<K extends ClientNames> = {\n meta?: ClientMeta<K>;\n dep?: unknown;\n};\n\nconst getMeta = <K extends ClientNames>(\n props: Derived.Props<K>,\n clientRef: { parent: AssistantClient; current: AssistantClient | null },\n memo: MetaMemo<K>,\n): ClientMeta<K> => {\n if (\"source\" in props && \"query\" in props) return props;\n if (memo.dep === props) return memo.meta!;\n const meta = props.getMeta(clientRef.current!);\n memo.meta = meta;\n memo.dep = props;\n return meta;\n};\n\nconst DerivedClientAccessorResource = resource(\n <K extends ClientNames>({\n element,\n clientRef,\n }: {\n element: DerivedElement<K>;\n clientRef: { parent: AssistantClient; current: AssistantClient | null };\n }) => {\n const get = tapEffectEvent(() => element.props);\n\n return tapMemo(() => {\n const clientFunction = () => get().get(clientRef.current!);\n const metaMemo = {};\n Object.defineProperties(clientFunction, {\n source: {\n get: () => getMeta(get(), clientRef, metaMemo).source,\n },\n query: {\n get: () => getMeta(get(), clientRef, metaMemo).query,\n },\n });\n return clientFunction;\n }, [clientRef]);\n },\n);\n\nconst DerivedClientsAccessorsResource = resource(\n ({\n clients,\n clientRef,\n }: {\n clients: DerivedClients;\n clientRef: { parent: AssistantClient; current: AssistantClient | null };\n }) => {\n return tapResources(\n clients,\n (element) =>\n DerivedClientAccessorResource({\n element: element!,\n clientRef,\n }),\n [clientRef],\n );\n },\n);\n\n/**\n * Resource that creates an extended AssistantClient.\n */\nexport const AssistantClientResource = resource(\n ({\n baseClient,\n clients,\n }: {\n baseClient: AssistantClient;\n clients: useAssistantClient.Props;\n }): AssistantClient => {\n const { rootClients, derivedClients } = splitClients(clients, baseClient);\n\n const clientRef = tapRef({\n parent: baseClient,\n current: null as AssistantClient | null,\n }).current;\n\n const rootFields = tapResource(\n Object.keys(rootClients).length > 0\n ? RootClientsAccessorsResource({ clients: rootClients, clientRef })\n : NoOpRootClientsAccessorsResource(),\n );\n\n const derivedFields = tapInlineResource(\n DerivedClientsAccessorsResource({ clients: derivedClients, clientRef }),\n );\n\n const client = tapMemo(() => {\n // Swap DefaultAssistantClient -> createRootAssistantClient at root to change error message\n const proto =\n baseClient === DefaultAssistantClient\n ? createRootAssistantClient()\n : baseClient;\n const client = Object.create(proto) as AssistantClient;\n Object.assign(client, rootFields.clients, derivedFields, {\n subscribe: rootFields.subscribe ?? baseClient.subscribe,\n on: rootFields.on ?? baseClient.on,\n [PROXIED_ASSISTANT_STATE_SYMBOL]: createProxiedAssistantState(client),\n });\n return client;\n }, [baseClient, rootFields, derivedFields]);\n\n if (clientRef.current === null) {\n clientRef.current = client;\n }\n\n tapEffect(() => {\n clientRef.current = client;\n });\n\n return client;\n },\n);\n\nexport namespace useAssistantClient {\n export type Props = {\n [K in ClientNames]?: ClientElement<K> | DerivedElement<K>;\n };\n}\n\nexport function useAssistantClient(): AssistantClient;\nexport function useAssistantClient(\n clients: useAssistantClient.Props,\n): AssistantClient;\nexport function useAssistantClient(\n clients?: useAssistantClient.Props,\n): AssistantClient {\n const baseClient = useAssistantContextValue();\n if (clients) {\n return useResource(AssistantClientResource({ baseClient, clients }));\n }\n return baseClient;\n}\n"],"mappings":";;;AAEA,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AASP,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAGE;AAAA,OACK;AACP;AAAA,EACE;AAAA,OAIK;AACP,SAAS,2BAA2B;AACpC,SAAS,uCAAuC;AAChD,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAC/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QAAQ,MAAM;AAE3B,YAAM,QACJ,eAAe,yBACX,0BAA0B,IAC1B;AACN,YAAMA,UAAS,OAAO,OAAO,KAAK;AAClC,aAAO,OAAOA,SAAQ,WAAW,SAAS,eAAe;AAAA,QACvD,WAAW,WAAW,aAAa,WAAW;AAAA,QAC9C,IAAI,WAAW,MAAM,WAAW;AAAA,QAChC,CAAC,8BAA8B,GAAG,4BAA4BA,OAAM;AAAA,MACtE,CAAC;AACD,aAAOA;AAAA,IACT,GAAG,CAAC,YAAY,YAAY,aAAa,CAAC;AAE1C,QAAI,UAAU,YAAY,MAAM;AAC9B,gBAAU,UAAU;AAAA,IACtB;AAEA,cAAU,MAAM;AACd,gBAAU,UAAU;AAAA,IACtB,CAAC;AAED,WAAO;AAAA,EACT;AACF;AAYO,SAAS,mBACd,SACiB;AACjB,QAAM,aAAa,yBAAyB;AAC5C,MAAI,SAAS;AACX,WAAO,YAAY,wBAAwB,EAAE,YAAY,QAAQ,CAAC,CAAC;AAAA,EACrE;AACA,SAAO;AACT;","names":["client"]}
|
|
1
|
+
{"version":3,"file":"useAssistantClient.js","sourceRoot":"","sources":["../src/useAssistantClient.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EACL,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,SAAS,EACT,MAAM,EACN,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAS3B,OAAO,EAAE,aAAa,EAAE,iCAA8B;AACtD,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,yBAAyB,GAC1B,2CAAwC;AACzC,OAAO,EAGL,YAAY,GACb,gCAA6B;AAC9B,OAAO,EACL,sBAAsB,GAIvB,0BAAuB;AACxB,OAAO,EAAE,mBAAmB,EAAE,uCAAoC;AAClE,OAAO,EAAE,+BAA+B,EAAE,yCAAsC;AAChF,OAAO,EAAE,iBAAiB,EA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CAAC,CAAC;IAE5C,IAAI,SAAS,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;QAC/B,SAAS,CAAC,OAAO,GAAG,MAAM,CAAC;IAC7B,CAAC;IAED,SAAS,CAAC,GAAG,EAAE;QACb,SAAS,CAAC,OAAO,GAAG,MAAM,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC,CACF,CAAC;AAYF,MAAM,UAAU,kBAAkB,CAChC,OAAkC;IAElC,MAAM,UAAU,GAAG,wBAAwB,EAAE,CAAC;IAC9C,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,WAAW,CAAC,uBAAuB,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { AssistantEventName, AssistantEventCallback, AssistantEventSelector } from "./types/events";
|
|
1
|
+
import type { AssistantEventName, AssistantEventCallback, AssistantEventSelector } from "./types/events.js";
|
|
2
2
|
export declare const useAssistantEvent: <TEvent extends AssistantEventName>(selector: AssistantEventSelector<TEvent>, callback: AssistantEventCallback<TEvent>) => void;
|
|
3
3
|
//# sourceMappingURL=useAssistantEvent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAssistantEvent.d.ts","sourceRoot":"","sources":["../src/useAssistantEvent.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACvB,
|
|
1
|
+
{"version":3,"file":"useAssistantEvent.d.ts","sourceRoot":"","sources":["../src/useAssistantEvent.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACvB,0BAAuB;AAGxB,eAAO,MAAM,iBAAiB,GAAI,MAAM,SAAS,kBAAkB,EACjE,UAAU,sBAAsB,CAAC,MAAM,CAAC,EACxC,UAAU,sBAAsB,CAAC,MAAM,CAAC,SAOzC,CAAC"}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
// src/useAssistantEvent.ts
|
|
2
1
|
import { useEffect, useEffectEvent } from "react";
|
|
3
2
|
import { useAssistantClient } from "./useAssistantClient.js";
|
|
4
3
|
import { normalizeEventSelector } from "./types/events.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
export {
|
|
12
|
-
useAssistantEvent
|
|
4
|
+
export const useAssistantEvent = (selector, callback) => {
|
|
5
|
+
const aui = useAssistantClient();
|
|
6
|
+
const callbackRef = useEffectEvent(callback);
|
|
7
|
+
const { scope, event } = normalizeEventSelector(selector);
|
|
8
|
+
useEffect(() => aui.on({ scope, event }, callbackRef), [aui, scope, event]);
|
|
13
9
|
};
|
|
14
10
|
//# sourceMappingURL=useAssistantEvent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"useAssistantEvent.js","sourceRoot":"","sources":["../src/useAssistantEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,gCAA6B;AAM1D,OAAO,EAAE,sBAAsB,EAAE,0BAAuB;AAExD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,QAAwC,EACxC,QAAwC,EACxC,EAAE;IACF,MAAM,GAAG,GAAG,kBAAkB,EAAE,CAAC;IACjC,MAAM,WAAW,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAE7C,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IAC1D,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;AAC9E,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAssistantState.d.ts","sourceRoot":"","sources":["../src/useAssistantState.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"useAssistantState.d.ts","sourceRoot":"","sources":["../src/useAssistantState.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,0BAAuB;AAIrD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EACjC,UAAU,CAAC,KAAK,EAAE,cAAc,KAAK,CAAC,KACrC,CAmBF,CAAC"}
|
|
@@ -1,24 +1,29 @@
|
|
|
1
|
-
// src/useAssistantState.tsx
|
|
2
1
|
import { useSyncExternalStore, useDebugValue } from "react";
|
|
3
2
|
import { useAssistantClient } from "./useAssistantClient.js";
|
|
4
3
|
import { getProxiedAssistantState } from "./utils/proxied-assistant-state.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Hook to access a slice of the assistant state with automatic subscription
|
|
6
|
+
*
|
|
7
|
+
* @param selector - Function to select a slice of the state
|
|
8
|
+
* @returns The selected state slice
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const aui = useAssistantClient({
|
|
13
|
+
* foo: RootScope({ ... }),
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* const bar = useAssistantState((state) => state.foo.bar);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const useAssistantState = (selector) => {
|
|
20
|
+
const aui = useAssistantClient();
|
|
21
|
+
const proxiedState = getProxiedAssistantState(aui);
|
|
22
|
+
const slice = useSyncExternalStore(aui.subscribe, () => selector(proxiedState), () => selector(proxiedState));
|
|
23
|
+
if (slice === proxiedState) {
|
|
24
|
+
throw new Error("You tried to return the entire AssistantState. This is not supported due to technical limitations.");
|
|
25
|
+
}
|
|
26
|
+
useDebugValue(slice);
|
|
27
|
+
return slice;
|
|
23
28
|
};
|
|
24
29
|
//# sourceMappingURL=useAssistantState.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"useAssistantState.js","sourceRoot":"","sources":["../src/useAssistantState.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,gCAA6B;AAC1D,OAAO,EAAE,wBAAwB,EAAE,2CAAwC;AAE3E;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,QAAsC,EACnC,EAAE;IACL,MAAM,GAAG,GAAG,kBAAkB,EAAE,CAAC;IACjC,MAAM,YAAY,GAAG,wBAAwB,CAAC,GAAG,CAAC,CAAC;IAEnD,MAAM,KAAK,GAAG,oBAAoB,CAChC,GAAG,CAAC,SAAS,EACb,GAAG,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,EAC5B,GAAG,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,CAC7B,CAAC;IAEF,IAAI,KAAK,KAAK,YAAY,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,oGAAoG,CACrG,CAAC;IACJ,CAAC;IAED,aAAa,CAAC,KAAK,CAAC,CAAC;IAErB,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -1,41 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
writable: false,
|
|
17
|
-
enumerable: true,
|
|
18
|
-
configurable: false
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
set() {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
setPrototypeOf() {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
defineProperty() {
|
|
1
|
+
const INTROSPECTION_PROPS = new Set(["$$typeof", "nodeType", "then"]);
|
|
2
|
+
/**
|
|
3
|
+
* Handles common proxy introspection properties.
|
|
4
|
+
* Returns the appropriate value for toStringTag, toJSON, and props that should return undefined.
|
|
5
|
+
* Returns `false` if the prop should be handled by the subclass.
|
|
6
|
+
*/
|
|
7
|
+
export const handleIntrospectionProp = (prop, name) => {
|
|
8
|
+
if (prop === Symbol.toStringTag)
|
|
9
|
+
return name;
|
|
10
|
+
if (typeof prop === "symbol")
|
|
11
|
+
return undefined;
|
|
12
|
+
if (prop === "toJSON")
|
|
13
|
+
return () => name;
|
|
14
|
+
if (INTROSPECTION_PROPS.has(prop))
|
|
15
|
+
return undefined;
|
|
28
16
|
return false;
|
|
29
|
-
}
|
|
30
|
-
deleteProperty() {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
preventExtensions() {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
export {
|
|
38
|
-
BaseProxyHandler,
|
|
39
|
-
handleIntrospectionProp
|
|
40
17
|
};
|
|
18
|
+
export class BaseProxyHandler {
|
|
19
|
+
getOwnPropertyDescriptor(_, prop) {
|
|
20
|
+
const value = this.get(_, prop);
|
|
21
|
+
if (value === undefined)
|
|
22
|
+
return undefined;
|
|
23
|
+
return {
|
|
24
|
+
value,
|
|
25
|
+
writable: false,
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: false,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
set() {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
setPrototypeOf() {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
defineProperty() {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
deleteProperty() {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
preventExtensions() {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
41
46
|
//# sourceMappingURL=BaseProxyHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"BaseProxyHandler.js","sourceRoot":"","sources":["../../src/utils/BaseProxyHandler.ts"],"names":[],"mappings":"AAAA,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;AAEtE;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,IAAqB,EACrB,IAAY,EACK,EAAE;IACnB,IAAI,IAAI,KAAK,MAAM,CAAC,WAAW;QAAE,OAAO,IAAI,CAAC;IAC7C,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAC/C,IAAI,IAAI,KAAK,QAAQ;QAAE,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC;IACzC,IAAI,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IACpD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,OAAgB,gBAAgB;IAKpC,wBAAwB,CAAC,CAAU,EAAE,IAAqB;QACxD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QAChC,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAC1C,OAAO;YACL,KAAK;YACL,QAAQ,EAAE,KAAK;YACf,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,KAAK;SACpB,CAAC;IACJ,CAAC;IAED,GAAG;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,cAAc;QACZ,OAAO,KAAK,CAAC;IACf,CAAC;IACD,cAAc;QACZ,OAAO,KAAK,CAAC;IACf,CAAC;IACD,cAAc;QACZ,OAAO,KAAK,CAAC;IACf,CAAC;IACD,iBAAiB;QACf,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ClientStack } from "./tap-client-stack-context";
|
|
2
|
-
import type { AssistantEventName, AssistantEventPayload } from "../types/events";
|
|
3
|
-
import { Unsubscribe } from "../types/client";
|
|
1
|
+
import type { ClientStack } from "./tap-client-stack-context.js";
|
|
2
|
+
import type { AssistantEventName, AssistantEventPayload } from "../types/events.js";
|
|
3
|
+
import { Unsubscribe } from "../types/client.js";
|
|
4
4
|
export type NotificationManager = {
|
|
5
5
|
on<TEvent extends AssistantEventName>(event: TEvent, callback: (payload: AssistantEventPayload[TEvent], clientStack: ClientStack) => void): Unsubscribe;
|
|
6
6
|
emit<TEvent extends Exclude<AssistantEventName, "*">>(event: TEvent, payload: AssistantEventPayload[TEvent], clientStack: ClientStack): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationManager.d.ts","sourceRoot":"","sources":["../../src/utils/NotificationManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"NotificationManager.d.ts","sourceRoot":"","sources":["../../src/utils/NotificationManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,sCAAmC;AAC9D,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACtB,2BAAwB;AACzB,OAAO,EAAE,WAAW,EAAE,2BAAwB;AAI9C,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,CAAC,MAAM,SAAS,kBAAkB,EAClC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,CACR,OAAO,EAAE,qBAAqB,CAAC,MAAM,CAAC,EACtC,WAAW,EAAE,WAAW,KACrB,IAAI,GACR,WAAW,CAAC;IACf,IAAI,CAAC,MAAM,SAAS,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,EAClD,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,qBAAqB,CAAC,MAAM,CAAC,EACtC,WAAW,EAAE,WAAW,GACvB,IAAI,CAAC;IACR,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,WAAW,CAAC;IAC7C,iBAAiB,IAAI,IAAI,CAAC;CAC3B,CAAC;AAEF,eAAO,MAAM,mBAAmB,sEAkF9B,CAAC"}
|