@assistant-ui/store 0.2.11 → 0.2.12

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.
Files changed (86) hide show
  1. package/dist/AuiIf.d.ts +19 -15
  2. package/dist/AuiIf.d.ts.map +1 -1
  3. package/dist/AuiIf.js +27 -24
  4. package/dist/AuiIf.js.map +1 -1
  5. package/dist/Derived.d.ts +15 -11
  6. package/dist/Derived.d.ts.map +1 -1
  7. package/dist/Derived.js +24 -20
  8. package/dist/Derived.js.map +1 -1
  9. package/dist/RenderChildrenWithAccessor.d.ts +13 -6
  10. package/dist/RenderChildrenWithAccessor.d.ts.map +1 -1
  11. package/dist/RenderChildrenWithAccessor.js +42 -48
  12. package/dist/RenderChildrenWithAccessor.js.map +1 -1
  13. package/dist/attachTransformScopes.d.ts +11 -10
  14. package/dist/attachTransformScopes.d.ts.map +1 -1
  15. package/dist/attachTransformScopes.js +20 -23
  16. package/dist/attachTransformScopes.js.map +1 -1
  17. package/dist/index.d.ts +15 -16
  18. package/dist/index.js +14 -18
  19. package/dist/tapClientList.d.ts +26 -23
  20. package/dist/tapClientList.d.ts.map +1 -1
  21. package/dist/tapClientList.js +66 -63
  22. package/dist/tapClientList.js.map +1 -1
  23. package/dist/tapClientLookup.d.ts +14 -11
  24. package/dist/tapClientLookup.d.ts.map +1 -1
  25. package/dist/tapClientLookup.js +31 -37
  26. package/dist/tapClientLookup.js.map +1 -1
  27. package/dist/tapClientResource.d.ts +12 -9
  28. package/dist/tapClientResource.d.ts.map +1 -1
  29. package/dist/tapClientResource.js +92 -104
  30. package/dist/tapClientResource.js.map +1 -1
  31. package/dist/types/client.d.ts +50 -42
  32. package/dist/types/client.d.ts.map +1 -1
  33. package/dist/types/client.js +0 -2
  34. package/dist/types/events.d.ts +23 -24
  35. package/dist/types/events.d.ts.map +1 -1
  36. package/dist/types/events.js +13 -6
  37. package/dist/types/events.js.map +1 -1
  38. package/dist/useAui.d.ts +17 -15
  39. package/dist/useAui.d.ts.map +1 -1
  40. package/dist/useAui.js +176 -191
  41. package/dist/useAui.js.map +1 -1
  42. package/dist/useAuiEvent.d.ts +6 -2
  43. package/dist/useAuiEvent.d.ts.map +1 -1
  44. package/dist/useAuiEvent.js +59 -47
  45. package/dist/useAuiEvent.js.map +1 -1
  46. package/dist/useAuiState.d.ts +6 -2
  47. package/dist/useAuiState.d.ts.map +1 -1
  48. package/dist/useAuiState.js +44 -42
  49. package/dist/useAuiState.js.map +1 -1
  50. package/dist/utils/BaseProxyHandler.d.ts +19 -16
  51. package/dist/utils/BaseProxyHandler.d.ts.map +1 -1
  52. package/dist/utils/BaseProxyHandler.js +46 -43
  53. package/dist/utils/BaseProxyHandler.js.map +1 -1
  54. package/dist/utils/NotificationManager.d.ts +13 -9
  55. package/dist/utils/NotificationManager.d.ts.map +1 -1
  56. package/dist/utils/NotificationManager.js +69 -82
  57. package/dist/utils/NotificationManager.js.map +1 -1
  58. package/dist/utils/proxied-assistant-state.d.ts +8 -4
  59. package/dist/utils/proxied-assistant-state.d.ts.map +1 -1
  60. package/dist/utils/proxied-assistant-state.js +28 -26
  61. package/dist/utils/proxied-assistant-state.js.map +1 -1
  62. package/dist/utils/react-assistant-context.d.ts +15 -10
  63. package/dist/utils/react-assistant-context.d.ts.map +1 -1
  64. package/dist/utils/react-assistant-context.js +69 -67
  65. package/dist/utils/react-assistant-context.js.map +1 -1
  66. package/dist/utils/splitClients.d.ts +12 -8
  67. package/dist/utils/splitClients.d.ts.map +1 -1
  68. package/dist/utils/splitClients.js +39 -43
  69. package/dist/utils/splitClients.js.map +1 -1
  70. package/dist/utils/tap-assistant-context.d.ts +17 -14
  71. package/dist/utils/tap-assistant-context.d.ts.map +1 -1
  72. package/dist/utils/tap-assistant-context.js +18 -15
  73. package/dist/utils/tap-assistant-context.js.map +1 -1
  74. package/dist/utils/tap-client-stack-context.d.ts +10 -6
  75. package/dist/utils/tap-client-stack-context.d.ts.map +1 -1
  76. package/dist/utils/tap-client-stack-context.js +22 -19
  77. package/dist/utils/tap-client-stack-context.js.map +1 -1
  78. package/dist/wrapperResource.d.ts +6 -2
  79. package/dist/wrapperResource.d.ts.map +1 -1
  80. package/dist/wrapperResource.js +12 -9
  81. package/dist/wrapperResource.js.map +1 -1
  82. package/package.json +7 -7
  83. package/src/types/client.ts +1 -2
  84. package/dist/index.d.ts.map +0 -1
  85. package/dist/index.js.map +0 -1
  86. package/dist/types/client.js.map +0 -1
package/dist/useAui.js CHANGED
@@ -1,210 +1,195 @@
1
1
  "use client";
2
- import { useResource } from "@assistant-ui/tap/react";
3
- import { resource, tapMemo, tapResources, tapEffect, tapRef, tapResource, withKey, tapResourceRoot, } from "@assistant-ui/tap";
4
- import { useAssistantContextValue, DefaultAssistantClient, createRootAssistantClient, } from "./utils/react-assistant-context.js";
5
- import { tapSplitClients, } from "./utils/splitClients.js";
6
- import { normalizeEventSelector, } from "./types/events.js";
2
+ import { getClientIndex } from "./utils/tap-client-stack-context.js";
3
+ import { tapClientResource } from "./tapClientResource.js";
4
+ import { PROXIED_ASSISTANT_STATE_SYMBOL, createProxiedAssistantState } from "./utils/proxied-assistant-state.js";
5
+ import { DefaultAssistantClient, createRootAssistantClient, useAssistantContextValue } from "./utils/react-assistant-context.js";
6
+ import { tapSplitClients } from "./utils/splitClients.js";
7
+ import { normalizeEventSelector } from "./types/events.js";
7
8
  import { NotificationManager } from "./utils/NotificationManager.js";
8
9
  import { withAssistantTapContextProvider } from "./utils/tap-assistant-context.js";
9
- import { tapClientResource } from "./tapClientResource.js";
10
- import { getClientIndex } from "./utils/tap-client-stack-context.js";
11
- import { PROXIED_ASSISTANT_STATE_SYMBOL, createProxiedAssistantState, } from "./utils/proxied-assistant-state.js";
10
+ import { useResource } from "@assistant-ui/tap/react";
11
+ import { resource, tapEffect, tapMemo, tapRef, tapResource, tapResourceRoot, tapResources, withKey } from "@assistant-ui/tap";
12
+ //#region src/useAui.ts
12
13
  const tapShallowMemoArray = (array) => {
13
- // biome-ignore lint/correctness/useExhaustiveDependencies: shallow memo
14
- return tapMemo(() => array, array);
14
+ return tapMemo(() => array, array);
15
15
  };
16
- const RootClientResource = resource(({ element, emit, clientRef, }) => {
17
- const { methods, state } = withAssistantTapContextProvider({ clientRef, emit }, () => tapClientResource(element));
18
- return tapMemo(() => ({ state, methods }), [methods, state]);
16
+ const RootClientResource = resource(({ element, emit, clientRef }) => {
17
+ const { methods, state } = withAssistantTapContextProvider({
18
+ clientRef,
19
+ emit
20
+ }, () => tapClientResource(element));
21
+ return tapMemo(() => ({
22
+ state,
23
+ methods
24
+ }), [methods, state]);
19
25
  });
20
- const RootClientAccessorResource = resource(({ element, notifications, clientRef, name, }) => {
21
- const store = tapResourceRoot(RootClientResource({ element, emit: notifications.emit, clientRef }));
22
- tapEffect(() => {
23
- return store.subscribe(notifications.notifySubscribers);
24
- }, [store, notifications]);
25
- return tapMemo(() => {
26
- const clientFunction = () => store.getValue().methods;
27
- Object.defineProperties(clientFunction, {
28
- source: {
29
- value: "root",
30
- writable: false,
31
- },
32
- query: {
33
- value: {},
34
- writable: false,
35
- },
36
- name: {
37
- value: name,
38
- configurable: true,
39
- },
40
- });
41
- return clientFunction;
42
- }, [store, name]);
26
+ const RootClientAccessorResource = resource(({ element, notifications, clientRef, name }) => {
27
+ const store = tapResourceRoot(RootClientResource({
28
+ element,
29
+ emit: notifications.emit,
30
+ clientRef
31
+ }));
32
+ tapEffect(() => {
33
+ return store.subscribe(notifications.notifySubscribers);
34
+ }, [store, notifications]);
35
+ return tapMemo(() => {
36
+ const clientFunction = () => store.getValue().methods;
37
+ Object.defineProperties(clientFunction, {
38
+ source: {
39
+ value: "root",
40
+ writable: false
41
+ },
42
+ query: {
43
+ value: {},
44
+ writable: false
45
+ },
46
+ name: {
47
+ value: name,
48
+ configurable: true
49
+ }
50
+ });
51
+ return clientFunction;
52
+ }, [store, name]);
43
53
  });
44
54
  const NoOpRootClientsAccessorsResource = resource(() => {
45
- return tapMemo(() => ({
46
- clients: [],
47
- subscribe: undefined,
48
- on: undefined,
49
- }), []);
55
+ return tapMemo(() => ({
56
+ clients: [],
57
+ subscribe: void 0,
58
+ on: void 0
59
+ }), []);
50
60
  });
51
- const RootClientsAccessorsResource = resource(({ clients: inputClients, clientRef, }) => {
52
- const notifications = tapResource(NotificationManager());
53
- tapEffect(() => clientRef.parent.subscribe(notifications.notifySubscribers), [clientRef, notifications]);
54
- const results = tapShallowMemoArray(tapResources(() => Object.keys(inputClients).map((key) => withKey(key, RootClientAccessorResource({
55
- element: inputClients[key],
56
- notifications,
57
- clientRef,
58
- name: key,
59
- }))), [inputClients, notifications, clientRef]));
60
- return tapMemo(() => {
61
- return {
62
- clients: results,
63
- subscribe: notifications.subscribe,
64
- on: function (selector, callback) {
65
- if (!this) {
66
- throw new Error("const { on } = useAui() is not supported. Use aui.on() instead.");
67
- }
68
- const { scope, event } = normalizeEventSelector(selector);
69
- if (scope !== "*") {
70
- const source = this[scope].source;
71
- if (source === null) {
72
- throw new Error(`Scope "${scope}" is not available. Use { scope: "*", event: "${event}" } to listen globally.`);
73
- }
74
- }
75
- const localUnsub = notifications.on(event, (payload, clientStack) => {
76
- if (scope === "*") {
77
- callback(payload);
78
- return;
79
- }
80
- const scopeClient = this[scope]();
81
- const index = getClientIndex(scopeClient);
82
- if (scopeClient === clientStack[index]) {
83
- callback(payload);
84
- }
85
- });
86
- if (scope !== "*" &&
87
- clientRef.parent[scope].source === null)
88
- return localUnsub;
89
- const parentUnsub = clientRef.parent.on(selector, callback);
90
- return () => {
91
- localUnsub();
92
- parentUnsub();
93
- };
94
- },
95
- };
96
- }, [results, notifications, clientRef]);
61
+ const RootClientsAccessorsResource = resource(({ clients: inputClients, clientRef }) => {
62
+ const notifications = tapResource(NotificationManager());
63
+ tapEffect(() => clientRef.parent.subscribe(notifications.notifySubscribers), [clientRef, notifications]);
64
+ const results = tapShallowMemoArray(tapResources(() => Object.keys(inputClients).map((key) => withKey(key, RootClientAccessorResource({
65
+ element: inputClients[key],
66
+ notifications,
67
+ clientRef,
68
+ name: key
69
+ }))), [
70
+ inputClients,
71
+ notifications,
72
+ clientRef
73
+ ]));
74
+ return tapMemo(() => {
75
+ return {
76
+ clients: results,
77
+ subscribe: notifications.subscribe,
78
+ on: function(selector, callback) {
79
+ if (!this) throw new Error("const { on } = useAui() is not supported. Use aui.on() instead.");
80
+ const { scope, event } = normalizeEventSelector(selector);
81
+ if (scope !== "*") {
82
+ if (this[scope].source === null) throw new Error(`Scope "${scope}" is not available. Use { scope: "*", event: "${event}" } to listen globally.`);
83
+ }
84
+ const localUnsub = notifications.on(event, (payload, clientStack) => {
85
+ if (scope === "*") {
86
+ callback(payload);
87
+ return;
88
+ }
89
+ const scopeClient = this[scope]();
90
+ if (scopeClient === clientStack[getClientIndex(scopeClient)]) callback(payload);
91
+ });
92
+ if (scope !== "*" && clientRef.parent[scope].source === null) return localUnsub;
93
+ const parentUnsub = clientRef.parent.on(selector, callback);
94
+ return () => {
95
+ localUnsub();
96
+ parentUnsub();
97
+ };
98
+ }
99
+ };
100
+ }, [
101
+ results,
102
+ notifications,
103
+ clientRef
104
+ ]);
97
105
  });
98
- const DerivedClientAccessorResource = resource(({ element, clientRef, name, }) => {
99
- // Track the latest props on a ref updated in render. The fiber is
100
- // keyed on the scope's meta by DerivedClientsAccessorsResource, so
101
- // source/query are stable for this fiber's lifetime and the only
102
- // value that can change between renders for the same fiber is the
103
- // identity of the `get` closure. Routing reads through the ref
104
- // avoids the one-commit lag that the previous `tapEffectEvent`
105
- // path imposed.
106
- const propsRef = tapRef(element.props);
107
- propsRef.current = element.props;
108
- return tapMemo(() => {
109
- const clientFunction = () => propsRef.current.get(clientRef.current);
110
- Object.defineProperties(clientFunction, {
111
- source: {
112
- value: propsRef.current.source,
113
- },
114
- query: {
115
- value: propsRef.current.query,
116
- },
117
- name: {
118
- value: name,
119
- configurable: true,
120
- },
121
- });
122
- return clientFunction;
123
- }, [clientRef, name]);
106
+ const DerivedClientAccessorResource = resource(({ element, clientRef, name }) => {
107
+ const propsRef = tapRef(element.props);
108
+ propsRef.current = element.props;
109
+ return tapMemo(() => {
110
+ const clientFunction = () => propsRef.current.get(clientRef.current);
111
+ Object.defineProperties(clientFunction, {
112
+ source: { value: propsRef.current.source },
113
+ query: { value: propsRef.current.query },
114
+ name: {
115
+ value: name,
116
+ configurable: true
117
+ }
118
+ });
119
+ return clientFunction;
120
+ }, [clientRef, name]);
124
121
  });
125
122
  const serializeMeta = (name, meta) => {
126
- // Sort top-level keys so {a, b} and {b, a} hash to the same fiber
127
- // identity, and guard JSON.stringify against unusual values (BigInt,
128
- // circular refs) so render never throws here.
129
- let queryKey;
130
- try {
131
- const sorted = {};
132
- for (const k of Object.keys(meta.query).sort()) {
133
- sorted[k] = meta.query[k];
134
- }
135
- queryKey = JSON.stringify(sorted);
136
- }
137
- catch {
138
- queryKey = String(meta.query);
139
- }
140
- return `${name}::${meta.source}::${queryKey}`;
123
+ let queryKey;
124
+ try {
125
+ const sorted = {};
126
+ for (const k of Object.keys(meta.query).sort()) sorted[k] = meta.query[k];
127
+ queryKey = JSON.stringify(sorted);
128
+ } catch {
129
+ queryKey = String(meta.query);
130
+ }
131
+ return `${name}::${meta.source}::${queryKey}`;
141
132
  };
142
- const DerivedClientsAccessorsResource = resource(({ clients, clientRef, }) => {
143
- return tapShallowMemoArray(tapResources(() => Object.keys(clients).map((key) => {
144
- const name = key;
145
- const element = clients[name];
146
- return withKey(serializeMeta(name, element.props), DerivedClientAccessorResource({
147
- element,
148
- clientRef,
149
- name,
150
- }));
151
- }), [clients, clientRef]));
133
+ const DerivedClientsAccessorsResource = resource(({ clients, clientRef }) => {
134
+ return tapShallowMemoArray(tapResources(() => Object.keys(clients).map((key) => {
135
+ const name = key;
136
+ const element = clients[name];
137
+ return withKey(serializeMeta(name, element.props), DerivedClientAccessorResource({
138
+ element,
139
+ clientRef,
140
+ name
141
+ }));
142
+ }), [clients, clientRef]));
152
143
  });
153
144
  /**
154
- * Resource that creates an extended AssistantClient.
155
- */
156
- export const AssistantClientResource = resource(({ parent, clients, }) => {
157
- const { rootClients, derivedClients } = tapSplitClients(clients, parent);
158
- const clientRef = tapRef({
159
- parent: parent,
160
- current: null,
161
- }).current;
162
- tapEffect(() => {
163
- // if (clientRef.current && clientRef.current !== client)
164
- // throw new Error("clientRef.current !== client");
165
- clientRef.current = client;
166
- });
167
- const rootFields = tapResource(Object.keys(rootClients).length > 0
168
- ? RootClientsAccessorsResource({ clients: rootClients, clientRef })
169
- : NoOpRootClientsAccessorsResource());
170
- const derivedFields = tapResource(DerivedClientsAccessorsResource({ clients: derivedClients, clientRef }));
171
- const client = tapMemo(() => {
172
- // Swap DefaultAssistantClient -> createRootAssistantClient at root to change error message
173
- const proto = parent === DefaultAssistantClient
174
- ? createRootAssistantClient()
175
- : parent;
176
- const client = Object.create(proto);
177
- Object.assign(client, {
178
- subscribe: rootFields.subscribe ?? parent.subscribe,
179
- on: rootFields.on ?? parent.on,
180
- [PROXIED_ASSISTANT_STATE_SYMBOL]: createProxiedAssistantState(client),
181
- });
182
- for (const field of rootFields.clients) {
183
- client[field.name] = field;
184
- }
185
- for (const field of derivedFields) {
186
- client[field.name] = field;
187
- }
188
- return client;
189
- }, [parent, rootFields, derivedFields]);
190
- if (clientRef.current === null) {
191
- clientRef.current = client;
192
- }
193
- return client;
145
+ * Resource that creates an extended AssistantClient.
146
+ */
147
+ const AssistantClientResource = resource(({ parent, clients }) => {
148
+ const { rootClients, derivedClients } = tapSplitClients(clients, parent);
149
+ const clientRef = tapRef({
150
+ parent,
151
+ current: null
152
+ }).current;
153
+ tapEffect(() => {
154
+ clientRef.current = client;
155
+ });
156
+ const rootFields = tapResource(Object.keys(rootClients).length > 0 ? RootClientsAccessorsResource({
157
+ clients: rootClients,
158
+ clientRef
159
+ }) : NoOpRootClientsAccessorsResource());
160
+ const derivedFields = tapResource(DerivedClientsAccessorsResource({
161
+ clients: derivedClients,
162
+ clientRef
163
+ }));
164
+ const client = tapMemo(() => {
165
+ const proto = parent === DefaultAssistantClient ? createRootAssistantClient() : parent;
166
+ const client = Object.create(proto);
167
+ Object.assign(client, {
168
+ subscribe: rootFields.subscribe ?? parent.subscribe,
169
+ on: rootFields.on ?? parent.on,
170
+ [PROXIED_ASSISTANT_STATE_SYMBOL]: createProxiedAssistantState(client)
171
+ });
172
+ for (const field of rootFields.clients) client[field.name] = field;
173
+ for (const field of derivedFields) client[field.name] = field;
174
+ return client;
175
+ }, [
176
+ parent,
177
+ rootFields,
178
+ derivedFields
179
+ ]);
180
+ if (clientRef.current === null) clientRef.current = client;
181
+ return client;
194
182
  });
195
183
  /** @deprecated This API is highly experimental and may be changed in a minor release */
196
- export function useAui(clients, { parent } = {
197
- parent: useAssistantContextValue(),
198
- }) {
199
- if (clients) {
200
- // biome-ignore lint/correctness/useHookAtTopLevel: intentional conditional/nested hook usage
201
- return useResource(AssistantClientResource({
202
- parent: parent ?? DefaultAssistantClient,
203
- clients,
204
- }));
205
- }
206
- if (parent === null)
207
- throw new Error("received null parent, this usage is not allowed");
208
- return parent;
184
+ function useAui(clients, { parent } = { parent: useAssistantContextValue() }) {
185
+ if (clients) return useResource(AssistantClientResource({
186
+ parent: parent ?? DefaultAssistantClient,
187
+ clients
188
+ }));
189
+ if (parent === null) throw new Error("received null parent, this usage is not allowed");
190
+ return parent;
209
191
  }
192
+ //#endregion
193
+ export { AssistantClientResource, useAui };
194
+
210
195
  //# sourceMappingURL=useAui.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAui.js","sourceRoot":"","sources":["../src/useAui.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EACL,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,SAAS,EACT,MAAM,EACN,WAAW,EACX,OAAO,EACP,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAS3B,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,yBAAyB,GAC1B,2CAAwC;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AAE;YAC9B,CAAC,8BAA8B,CAAC,EAAE,2BAA2B,CAAC,MAAM,CAAC;SACtE,CAAC,CAAC;QAEH,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;YACtC,MAAc,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QACtC,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,aAAa,EAAE,CAAC;YACjC,MAAc,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QACtC,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC;IAExC,IAAI,SAAS,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;QAC/B,SAAS,CAAC,OAAO,GAAG,MAAM,CAAC;IAC7B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CACF,CAAC;AAyEF,wFAAwF;AACxF,MAAM,UAAU,MAAM,CACpB,OAAsB,EACtB,EAAE,MAAM,KAAyC;IAC/C,MAAM,EAAE,wBAAwB,EAAE;CACnC;IAED,IAAI,OAAO,EAAE,CAAC;QACZ,6FAA6F;QAC7F,OAAO,WAAW,CAChB,uBAAuB,CAAC;YACtB,MAAM,EAAE,MAAM,IAAI,sBAAsB;YACxC,OAAO;SACR,CAAC,CACH,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,KAAK,IAAI;QACjB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,OAAO,MAAM,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"useAui.js","names":[],"sources":["../src/useAui.ts"],"sourcesContent":["\"use client\";\n\nimport { useResource } from \"@assistant-ui/tap/react\";\nimport {\n resource,\n tapMemo,\n tapResources,\n tapEffect,\n tapRef,\n tapResource,\n withKey,\n tapResourceRoot,\n} from \"@assistant-ui/tap\";\nimport type {\n AssistantClient,\n AssistantClientAccessor,\n ClientNames,\n ClientElement,\n ClientMeta,\n} from \"./types/client\";\nimport type { DerivedElement } from \"./Derived\";\nimport {\n useAssistantContextValue,\n DefaultAssistantClient,\n createRootAssistantClient,\n} from \"./utils/react-assistant-context\";\nimport {\n type DerivedClients,\n type RootClients,\n tapSplitClients,\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 tapShallowMemoArray = <T>(array: readonly T[]) => {\n // biome-ignore lint/correctness/useExhaustiveDependencies: shallow memo\n return tapMemo(() => array, array);\n};\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(() => ({ state, methods }), [methods, state]);\n },\n);\n\nconst RootClientAccessorResource = resource(\n <K extends ClientNames>({\n element,\n notifications,\n clientRef,\n name,\n }: {\n element: ClientElement<K>;\n notifications: NotificationManager;\n clientRef: { parent: AssistantClient; current: AssistantClient | null };\n name: K;\n }): AssistantClientAccessor<K> => {\n const store = tapResourceRoot(\n RootClientResource({ element, emit: notifications.emit, clientRef }),\n );\n\n tapEffect(() => {\n return store.subscribe(notifications.notifySubscribers);\n }, [store, notifications]);\n\n return tapMemo(() => {\n const clientFunction = () => store.getValue().methods;\n Object.defineProperties(clientFunction, {\n source: {\n value: \"root\" as const,\n writable: false,\n },\n query: {\n value: {} as Record<string, never>,\n writable: false,\n },\n name: {\n value: name,\n configurable: true,\n },\n });\n return clientFunction as AssistantClientAccessor<K>;\n }, [store, name]);\n },\n);\n\nconst NoOpRootClientsAccessorsResource = resource(() => {\n return tapMemo(\n () => ({\n clients: [] as AssistantClientAccessor<ClientNames>[],\n subscribe: undefined,\n on: undefined,\n }),\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 = tapResource(NotificationManager());\n\n tapEffect(\n () => clientRef.parent.subscribe(notifications.notifySubscribers),\n [clientRef, notifications],\n );\n\n const results = tapShallowMemoArray(\n tapResources(\n () =>\n Object.keys(inputClients).map((key) =>\n withKey(\n key,\n RootClientAccessorResource({\n element: inputClients[key as keyof typeof inputClients]!,\n notifications,\n clientRef,\n name: key as keyof typeof inputClients,\n }),\n ),\n ),\n [inputClients, notifications, clientRef],\n ),\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 } = useAui() 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\nconst DerivedClientAccessorResource = resource(\n <K extends ClientNames>({\n element,\n clientRef,\n name,\n }: {\n element: DerivedElement<K>;\n clientRef: { parent: AssistantClient; current: AssistantClient | null };\n name: K;\n }) => {\n // Track the latest props on a ref updated in render. The fiber is\n // keyed on the scope's meta by DerivedClientsAccessorsResource, so\n // source/query are stable for this fiber's lifetime and the only\n // value that can change between renders for the same fiber is the\n // identity of the `get` closure. Routing reads through the ref\n // avoids the one-commit lag that the previous `tapEffectEvent`\n // path imposed.\n const propsRef = tapRef(element.props);\n propsRef.current = element.props;\n\n return tapMemo(() => {\n const clientFunction = () => propsRef.current.get(clientRef.current!);\n Object.defineProperties(clientFunction, {\n source: {\n value: propsRef.current.source,\n },\n query: {\n value: propsRef.current.query,\n },\n name: {\n value: name,\n configurable: true,\n },\n });\n return clientFunction as AssistantClientAccessor<K>;\n }, [clientRef, name]);\n },\n);\n\nconst serializeMeta = <K extends ClientNames>(\n name: K,\n meta: ClientMeta<K>,\n): string => {\n // Sort top-level keys so {a, b} and {b, a} hash to the same fiber\n // identity, and guard JSON.stringify against unusual values (BigInt,\n // circular refs) so render never throws here.\n let queryKey: string;\n try {\n const sorted: Record<string, unknown> = {};\n for (const k of Object.keys(meta.query as object).sort()) {\n sorted[k] = (meta.query as Record<string, unknown>)[k];\n }\n queryKey = JSON.stringify(sorted);\n } catch {\n queryKey = String(meta.query);\n }\n return `${name}::${meta.source}::${queryKey}`;\n};\n\nconst DerivedClientsAccessorsResource = resource(\n ({\n clients,\n clientRef,\n }: {\n clients: DerivedClients;\n clientRef: { parent: AssistantClient; current: AssistantClient | null };\n }) => {\n return tapShallowMemoArray(\n tapResources(\n () =>\n Object.keys(clients).map((key) => {\n const name = key as keyof typeof clients;\n const element = clients[name]!;\n return withKey(\n serializeMeta(name, element.props),\n DerivedClientAccessorResource({\n element,\n clientRef,\n name,\n }),\n );\n }),\n [clients, clientRef],\n ),\n );\n },\n);\n\n/**\n * Resource that creates an extended AssistantClient.\n */\nexport const AssistantClientResource = resource(\n ({\n parent,\n clients,\n }: {\n parent: AssistantClient;\n clients: useAui.Props;\n }): AssistantClient => {\n const { rootClients, derivedClients } = tapSplitClients(clients, parent);\n\n const clientRef = tapRef({\n parent: parent,\n current: null as AssistantClient | null,\n }).current;\n\n tapEffect(() => {\n // if (clientRef.current && clientRef.current !== client)\n // throw new Error(\"clientRef.current !== client\");\n\n clientRef.current = client;\n });\n\n const rootFields = tapResource(\n Object.keys(rootClients).length > 0\n ? RootClientsAccessorsResource({ clients: rootClients, clientRef })\n : NoOpRootClientsAccessorsResource(),\n );\n\n const derivedFields = tapResource(\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 parent === DefaultAssistantClient\n ? createRootAssistantClient()\n : parent;\n\n const client = Object.create(proto) as AssistantClient;\n Object.assign(client, {\n subscribe: rootFields.subscribe ?? parent.subscribe,\n on: rootFields.on ?? parent.on,\n [PROXIED_ASSISTANT_STATE_SYMBOL]: createProxiedAssistantState(client),\n });\n\n for (const field of rootFields.clients) {\n (client as any)[field.name] = field;\n }\n for (const field of derivedFields) {\n (client as any)[field.name] = field;\n }\n\n return client;\n }, [parent, rootFields, derivedFields]);\n\n if (clientRef.current === null) {\n clientRef.current = client;\n }\n\n return client;\n },\n);\n\nexport namespace useAui {\n export type Props = {\n [K in ClientNames]?: ClientElement<K> | DerivedElement<K>;\n };\n}\n\n/**\n * Returns the current `AssistantClient` from context.\n *\n * Read the client supplied by the nearest {@link AuiProvider} or\n * {@link AssistantRuntimeProvider}, then access a scope on it —\n * `aui.thread()`, `aui.composer()`, `aui.message()`, and so on. Pair\n * with {@link useAuiState} to read reactive state and {@link useAuiEvent}\n * to subscribe to events. The returned client also exposes lower-level\n * methods such as `aui.on(...)` and `aui.subscribe(...)`; prefer\n * `useAuiEvent` for React event subscriptions.\n *\n * Rendered outside a provider, the returned client's scope accessors\n * throw a descriptive error whenever they are called.\n *\n * @example\n * ```tsx\n * const aui = useAui();\n *\n * const onSend = () => aui.composer().send();\n * const onCancel = () => aui.thread().cancelRun();\n * ```\n *\n * @example\n * ```tsx\n * // Combine with useAuiState to drive disabled state.\n * const aui = useAui();\n * const isRunning = useAuiState((s) => s.thread.isRunning);\n *\n * return (\n * <button disabled={isRunning} onClick={() => aui.composer().send()}>\n * Send\n * </button>\n * );\n * ```\n */\nexport function useAui(): AssistantClient;\n/**\n * Extends the parent `AssistantClient` with additional scopes.\n *\n * Advanced overload used when building primitives or providers — for example,\n * when a custom provider needs to register a `message`, `part`, or other scope\n * onto the client visible to its descendants. Application code rarely reaches\n * for this; use {@link useAui} with no arguments to read the existing client.\n *\n * @example\n * ```tsx\n * const aui = useAui({\n * message: Derived({\n * source: \"thread\",\n * query: { index: 0 },\n * get: (aui) => aui.thread().message({ index: 0 }),\n * }),\n * });\n *\n * const role = useAuiState((s) => s.message.role);\n * ```\n */\nexport function useAui(clients: useAui.Props): AssistantClient;\n/**\n * Extends an explicit parent `AssistantClient` with additional scopes.\n */\nexport function useAui(\n clients: useAui.Props,\n config: { parent: null | AssistantClient },\n): AssistantClient;\n/** @deprecated This API is highly experimental and may be changed in a minor release */\nexport function useAui(\n clients?: useAui.Props,\n { parent }: { parent: null | AssistantClient } = {\n parent: useAssistantContextValue(),\n },\n): AssistantClient {\n if (clients) {\n // biome-ignore lint/correctness/useHookAtTopLevel: intentional conditional/nested hook usage\n return useResource(\n AssistantClientResource({\n parent: parent ?? DefaultAssistantClient,\n clients,\n }),\n );\n }\n if (parent === null)\n throw new Error(\"received null parent, this usage is not allowed\");\n return parent;\n}\n"],"mappings":";;;;;;;;;;;;AA8CA,MAAM,uBAA0B,UAAwB;CAEtD,OAAO,cAAc,OAAO,KAAK;AACnC;AAEA,MAAM,qBAAqB,UACD,EACtB,SACA,MACA,gBAKI;CACJ,MAAM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OACd,SACA,EAAE,WAA+C,EAC/C,QAAQ,yBAAyB,EACnC,GACiB;CACjB,IAAI,SAEF,OAAO,YACL,wBAAwB;EACtB,QAAQ,UAAU;EAClB;CACF,CAAC,CACH;CAEF,IAAI,WAAW,MACb,MAAM,IAAI,MAAM,iDAAiD;CACnE,OAAO;AACT"}
@@ -1,4 +1,6 @@
1
- import type { AssistantEventName, AssistantEventCallback, AssistantEventSelector } from "./types/events.js";
1
+ import { AssistantEventCallback, AssistantEventName, AssistantEventSelector } from "./types/events.js";
2
+
3
+ //#region src/useAuiEvent.d.ts
2
4
  /**
3
5
  * Subscribes to an assistant event for the lifetime of the component.
4
6
  *
@@ -40,5 +42,7 @@ import type { AssistantEventName, AssistantEventCallback, AssistantEventSelector
40
42
  * });
41
43
  * ```
42
44
  */
43
- export declare const useAuiEvent: <TEvent extends AssistantEventName>(selector: AssistantEventSelector<TEvent>, callback: AssistantEventCallback<TEvent>) => void;
45
+ declare const useAuiEvent: <TEvent extends AssistantEventName>(selector: AssistantEventSelector<TEvent>, callback: AssistantEventCallback<TEvent>) => void;
46
+ //#endregion
47
+ export { useAuiEvent };
44
48
  //# sourceMappingURL=useAuiEvent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAuiEvent.d.ts","sourceRoot":"","sources":["../src/useAuiEvent.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACvB,0BAAuB;AAGxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,SAAS,kBAAkB,EAC3D,UAAU,sBAAsB,CAAC,MAAM,CAAC,EACxC,UAAU,sBAAsB,CAAC,MAAM,CAAC,SAUzC,CAAC"}
1
+ {"version":3,"file":"useAuiEvent.d.ts","names":[],"sources":["../src/useAuiEvent.ts"],"mappings":";;;;;AAmDA;;;;;;;;;;;;;;;;;;;AAE0C;;;;;;;;;;;;;;;;;;;;cAF7B,WAAA,kBAA8B,kBAAA,EACzC,QAAA,EAAU,sBAAA,CAAuB,MAAA,GACjC,QAAA,EAAU,sBAAA,CAAuB,MAAA"}
@@ -1,52 +1,64 @@
1
+ import { normalizeEventSelector } from "./types/events.js";
2
+ import { useAui } from "./useAui.js";
1
3
  import { useEffect } from "react";
2
4
  import { useEffectEvent } from "use-effect-event";
3
- import { useAui } from "./useAui.js";
4
- import { normalizeEventSelector } from "./types/events.js";
5
+ //#region src/useAuiEvent.ts
5
6
  /**
6
- * Subscribes to an assistant event for the lifetime of the component.
7
- *
8
- * The subscription is established on mount and re-established whenever the
9
- * scope or event name changes. The `callback` is wrapped in an effect-event
10
- * shim, so the latest closure is invoked on each emission — you do not
11
- * need to memoize it.
12
- *
13
- * @param selector - Either a dotted event name like
14
- * `"thread.modelContextUpdate"` or an object `{ scope, event }`. Use
15
- * `scope: "*"` to subscribe at the root client and receive emissions
16
- * from any descendant scope, regardless of which one is in React
17
- * context.
18
- * @param callback - Invoked with the event payload. The most recent
19
- * reference is always called. Return values are ignored, async callbacks
20
- * are not awaited, and the callback cannot be called during render.
21
- *
22
- * @example
23
- * ```tsx
24
- * // React to transient model-context changes.
25
- * useAuiEvent("thread.modelContextUpdate", ({ threadId }) => {
26
- * analytics.track("model_context_update", { threadId });
27
- * });
28
- * ```
29
- *
30
- * @example
31
- * ```tsx
32
- * // React to thread switches.
33
- * useAuiEvent("threadListItem.switchedTo", () => {
34
- * resetLocalState();
35
- * });
36
- * ```
37
- *
38
- * @example
39
- * ```tsx
40
- * // Listen from the root client rather than the current React context.
41
- * useAuiEvent({ scope: "*", event: "thread.modelContextUpdate" }, (payload) => {
42
- * analytics.track("model_context_update", payload);
43
- * });
44
- * ```
45
- */
46
- export const useAuiEvent = (selector, callback) => {
47
- const aui = useAui();
48
- const callbackRef = useEffectEvent(callback);
49
- const { scope, event } = normalizeEventSelector(selector);
50
- useEffect(() => aui.on({ scope, event }, callbackRef), [aui, scope, event, callbackRef]);
7
+ * Subscribes to an assistant event for the lifetime of the component.
8
+ *
9
+ * The subscription is established on mount and re-established whenever the
10
+ * scope or event name changes. The `callback` is wrapped in an effect-event
11
+ * shim, so the latest closure is invoked on each emission — you do not
12
+ * need to memoize it.
13
+ *
14
+ * @param selector - Either a dotted event name like
15
+ * `"thread.modelContextUpdate"` or an object `{ scope, event }`. Use
16
+ * `scope: "*"` to subscribe at the root client and receive emissions
17
+ * from any descendant scope, regardless of which one is in React
18
+ * context.
19
+ * @param callback - Invoked with the event payload. The most recent
20
+ * reference is always called. Return values are ignored, async callbacks
21
+ * are not awaited, and the callback cannot be called during render.
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * // React to transient model-context changes.
26
+ * useAuiEvent("thread.modelContextUpdate", ({ threadId }) => {
27
+ * analytics.track("model_context_update", { threadId });
28
+ * });
29
+ * ```
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * // React to thread switches.
34
+ * useAuiEvent("threadListItem.switchedTo", () => {
35
+ * resetLocalState();
36
+ * });
37
+ * ```
38
+ *
39
+ * @example
40
+ * ```tsx
41
+ * // Listen from the root client rather than the current React context.
42
+ * useAuiEvent({ scope: "*", event: "thread.modelContextUpdate" }, (payload) => {
43
+ * analytics.track("model_context_update", payload);
44
+ * });
45
+ * ```
46
+ */
47
+ const useAuiEvent = (selector, callback) => {
48
+ const aui = useAui();
49
+ const callbackRef = useEffectEvent(callback);
50
+ const { scope, event } = normalizeEventSelector(selector);
51
+ useEffect(() => aui.on({
52
+ scope,
53
+ event
54
+ }, callbackRef), [
55
+ aui,
56
+ scope,
57
+ event,
58
+ callbackRef
59
+ ]);
51
60
  };
61
+ //#endregion
62
+ export { useAuiEvent };
63
+
52
64
  //# sourceMappingURL=useAuiEvent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAuiEvent.js","sourceRoot":"","sources":["../src/useAuiEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,oBAAiB;AAMlC,OAAO,EAAE,sBAAsB,EAAE,0BAAuB;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,QAAwC,EACxC,QAAwC,EACxC,EAAE;IACF,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;IACrB,MAAM,WAAW,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAE7C,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IAC1D,SAAS,CACP,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,WAAW,CAAC,EAC3C,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,CAAC,CACjC,CAAC;AACJ,CAAC,CAAC"}
1
+ {"version":3,"file":"useAuiEvent.js","names":[],"sources":["../src/useAuiEvent.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useEffectEvent } from \"use-effect-event\";\nimport { useAui } from \"./useAui\";\nimport type {\n AssistantEventName,\n AssistantEventCallback,\n AssistantEventSelector,\n} from \"./types/events\";\nimport { normalizeEventSelector } from \"./types/events\";\n\n/**\n * Subscribes to an assistant event for the lifetime of the component.\n *\n * The subscription is established on mount and re-established whenever the\n * scope or event name changes. The `callback` is wrapped in an effect-event\n * shim, so the latest closure is invoked on each emission — you do not\n * need to memoize it.\n *\n * @param selector - Either a dotted event name like\n * `\"thread.modelContextUpdate\"` or an object `{ scope, event }`. Use\n * `scope: \"*\"` to subscribe at the root client and receive emissions\n * from any descendant scope, regardless of which one is in React\n * context.\n * @param callback - Invoked with the event payload. The most recent\n * reference is always called. Return values are ignored, async callbacks\n * are not awaited, and the callback cannot be called during render.\n *\n * @example\n * ```tsx\n * // React to transient model-context changes.\n * useAuiEvent(\"thread.modelContextUpdate\", ({ threadId }) => {\n * analytics.track(\"model_context_update\", { threadId });\n * });\n * ```\n *\n * @example\n * ```tsx\n * // React to thread switches.\n * useAuiEvent(\"threadListItem.switchedTo\", () => {\n * resetLocalState();\n * });\n * ```\n *\n * @example\n * ```tsx\n * // Listen from the root client rather than the current React context.\n * useAuiEvent({ scope: \"*\", event: \"thread.modelContextUpdate\" }, (payload) => {\n * analytics.track(\"model_context_update\", payload);\n * });\n * ```\n */\nexport const useAuiEvent = <TEvent extends AssistantEventName>(\n selector: AssistantEventSelector<TEvent>,\n callback: AssistantEventCallback<TEvent>,\n) => {\n const aui = useAui();\n const callbackRef = useEffectEvent(callback);\n\n const { scope, event } = normalizeEventSelector(selector);\n useEffect(\n () => aui.on({ scope, event }, callbackRef),\n [aui, scope, event, callbackRef],\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDA,MAAa,eACX,UACA,aACG;CACH,MAAM,MAAM,OAAO;CACnB,MAAM,cAAc,eAAe,QAAQ;CAE3C,MAAM,EAAE,OAAO,UAAU,uBAAuB,QAAQ;CACxD,gBACQ,IAAI,GAAG;EAAE;EAAO;CAAM,GAAG,WAAW,GAC1C;EAAC;EAAK;EAAO;EAAO;CAAW,CACjC;AACF"}
@@ -1,4 +1,6 @@
1
- import type { AssistantState } from "./types/client.js";
1
+ import { AssistantState } from "./types/client.js";
2
+
3
+ //#region src/useAuiState.d.ts
2
4
  /**
3
5
  * Subscribes to a slice of {@link AssistantState} and re-renders the
4
6
  * component whenever that slice changes.
@@ -31,5 +33,7 @@ import type { AssistantState } from "./types/client.js";
31
33
  * const canSend = useAuiState((s) => s.composer.canSend);
32
34
  * ```
33
35
  */
34
- export declare const useAuiState: <T>(selector: (state: AssistantState) => T) => T;
36
+ declare const useAuiState: <T>(selector: (state: AssistantState) => T) => T;
37
+ //#endregion
38
+ export { useAuiState };
35
39
  //# sourceMappingURL=useAuiState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAuiState.d.ts","sourceRoot":"","sources":["../src/useAuiState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,0BAAuB;AAIrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,UAAU,CAAC,KAAK,EAAE,cAAc,KAAK,CAAC,KAAG,CAmBvE,CAAC"}
1
+ {"version":3,"file":"useAuiState.d.ts","names":[],"sources":["../src/useAuiState.ts"],"mappings":";;;;;AAqCA;;;;;;;;;;;;;;;AAmBC;;;;;;;;;;;;;;;cAnBY,WAAA,MAAkB,QAAA,GAAW,KAAA,EAAO,cAAA,KAAmB,CAAA,KAAI,CAAA"}