@assistant-ui/store 0.2.11 → 0.2.13
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/AuiIf.d.ts +19 -15
- package/dist/AuiIf.d.ts.map +1 -1
- package/dist/AuiIf.js +27 -24
- package/dist/AuiIf.js.map +1 -1
- package/dist/Derived.d.ts +15 -11
- package/dist/Derived.d.ts.map +1 -1
- package/dist/Derived.js +24 -20
- package/dist/Derived.js.map +1 -1
- package/dist/RenderChildrenWithAccessor.d.ts +13 -6
- package/dist/RenderChildrenWithAccessor.d.ts.map +1 -1
- package/dist/RenderChildrenWithAccessor.js +42 -48
- package/dist/RenderChildrenWithAccessor.js.map +1 -1
- package/dist/attachTransformScopes.d.ts +11 -10
- package/dist/attachTransformScopes.d.ts.map +1 -1
- package/dist/attachTransformScopes.js +20 -23
- package/dist/attachTransformScopes.js.map +1 -1
- package/dist/index.d.ts +15 -16
- package/dist/index.js +14 -18
- package/dist/tapClientList.d.ts +26 -23
- package/dist/tapClientList.d.ts.map +1 -1
- package/dist/tapClientList.js +66 -63
- package/dist/tapClientList.js.map +1 -1
- package/dist/tapClientLookup.d.ts +14 -11
- package/dist/tapClientLookup.d.ts.map +1 -1
- package/dist/tapClientLookup.js +31 -37
- package/dist/tapClientLookup.js.map +1 -1
- package/dist/tapClientResource.d.ts +12 -9
- package/dist/tapClientResource.d.ts.map +1 -1
- package/dist/tapClientResource.js +92 -104
- package/dist/tapClientResource.js.map +1 -1
- package/dist/types/client.d.ts +50 -42
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/client.js +0 -2
- package/dist/types/events.d.ts +23 -24
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/events.js +13 -6
- package/dist/types/events.js.map +1 -1
- package/dist/useAui.d.ts +17 -15
- package/dist/useAui.d.ts.map +1 -1
- package/dist/useAui.js +176 -191
- package/dist/useAui.js.map +1 -1
- package/dist/useAuiEvent.d.ts +6 -2
- package/dist/useAuiEvent.d.ts.map +1 -1
- package/dist/useAuiEvent.js +58 -47
- package/dist/useAuiEvent.js.map +1 -1
- package/dist/useAuiState.d.ts +6 -2
- package/dist/useAuiState.d.ts.map +1 -1
- package/dist/useAuiState.js +44 -42
- package/dist/useAuiState.js.map +1 -1
- package/dist/utils/BaseProxyHandler.d.ts +19 -16
- package/dist/utils/BaseProxyHandler.d.ts.map +1 -1
- package/dist/utils/BaseProxyHandler.js +46 -43
- package/dist/utils/BaseProxyHandler.js.map +1 -1
- package/dist/utils/NotificationManager.d.ts +13 -9
- package/dist/utils/NotificationManager.d.ts.map +1 -1
- package/dist/utils/NotificationManager.js +69 -82
- package/dist/utils/NotificationManager.js.map +1 -1
- package/dist/utils/proxied-assistant-state.d.ts +8 -4
- package/dist/utils/proxied-assistant-state.d.ts.map +1 -1
- package/dist/utils/proxied-assistant-state.js +28 -26
- package/dist/utils/proxied-assistant-state.js.map +1 -1
- package/dist/utils/react-assistant-context.d.ts +15 -10
- package/dist/utils/react-assistant-context.d.ts.map +1 -1
- package/dist/utils/react-assistant-context.js +69 -67
- package/dist/utils/react-assistant-context.js.map +1 -1
- package/dist/utils/splitClients.d.ts +12 -8
- package/dist/utils/splitClients.d.ts.map +1 -1
- package/dist/utils/splitClients.js +39 -43
- package/dist/utils/splitClients.js.map +1 -1
- package/dist/utils/tap-assistant-context.d.ts +17 -14
- package/dist/utils/tap-assistant-context.d.ts.map +1 -1
- package/dist/utils/tap-assistant-context.js +18 -15
- package/dist/utils/tap-assistant-context.js.map +1 -1
- package/dist/utils/tap-client-stack-context.d.ts +10 -6
- package/dist/utils/tap-client-stack-context.d.ts.map +1 -1
- package/dist/utils/tap-client-stack-context.js +22 -19
- package/dist/utils/tap-client-stack-context.js.map +1 -1
- package/dist/wrapperResource.d.ts +6 -2
- package/dist/wrapperResource.d.ts.map +1 -1
- package/dist/wrapperResource.js +12 -9
- package/dist/wrapperResource.js.map +1 -1
- package/package.json +7 -7
- package/src/RenderChildrenWithAccessor.tsx +1 -1
- package/src/__tests__/RenderChildrenWithAccessor.test.tsx +0 -1
- package/src/__tests__/hooks.test.tsx +0 -1
- package/src/tapClientLookup.ts +1 -1
- package/src/types/client.ts +1 -3
- package/src/types/events.ts +1 -3
- package/src/useAui.ts +1 -2
- package/src/useAuiEvent.ts +1 -4
- package/src/utils/splitClients.ts +1 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types/client.js.map +0 -1
package/dist/useAuiState.js
CHANGED
|
@@ -1,46 +1,48 @@
|
|
|
1
|
-
import { useSyncExternalStore, useDebugValue } from "react";
|
|
2
|
-
import { useAui } from "./useAui.js";
|
|
3
1
|
import { getProxiedAssistantState } from "./utils/proxied-assistant-state.js";
|
|
2
|
+
import { useAui } from "./useAui.js";
|
|
3
|
+
import { useDebugValue, useSyncExternalStore } from "react";
|
|
4
|
+
//#region src/useAuiState.ts
|
|
4
5
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
useDebugValue(slice);
|
|
44
|
-
return slice;
|
|
6
|
+
* Subscribes to a slice of {@link AssistantState} and re-renders the
|
|
7
|
+
* component whenever that slice changes.
|
|
8
|
+
*
|
|
9
|
+
* The `selector` is called on every store update; its return value is
|
|
10
|
+
* compared by `Object.is`, and the component re-renders only when the
|
|
11
|
+
* selected slice changes. Returning the entire state object is not
|
|
12
|
+
* supported and throws at runtime — select a specific field instead, or
|
|
13
|
+
* compose multiple `useAuiState` calls. Returning a new object or array
|
|
14
|
+
* literal, including spreading `s.thread` into a new object, causes a
|
|
15
|
+
* re-render on every store update; either select primitives or return a
|
|
16
|
+
* memoized reference.
|
|
17
|
+
*
|
|
18
|
+
* @param selector - Pure function that derives a value from the current
|
|
19
|
+
* assistant state. Should be cheap and referentially stable for equal
|
|
20
|
+
* inputs (plain field reads, primitives, or memoized values).
|
|
21
|
+
* @returns The currently selected slice.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* // Disable a button while a run is in flight.
|
|
26
|
+
* const isRunning = useAuiState((s) => s.thread.isRunning);
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* // Prefer multiple selectors over an inline object literal, which would
|
|
32
|
+
* // create a new reference on every render.
|
|
33
|
+
* const text = useAuiState((s) => s.composer.text);
|
|
34
|
+
* const canSend = useAuiState((s) => s.composer.canSend);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
const useAuiState = (selector) => {
|
|
38
|
+
const aui = useAui();
|
|
39
|
+
const proxiedState = getProxiedAssistantState(aui);
|
|
40
|
+
const slice = useSyncExternalStore(aui.subscribe, () => selector(proxiedState), () => selector(proxiedState));
|
|
41
|
+
if (slice === proxiedState) throw new Error("You tried to return the entire AssistantState. This is not supported due to technical limitations.");
|
|
42
|
+
useDebugValue(slice);
|
|
43
|
+
return slice;
|
|
45
44
|
};
|
|
45
|
+
//#endregion
|
|
46
|
+
export { useAuiState };
|
|
47
|
+
|
|
46
48
|
//# sourceMappingURL=useAuiState.js.map
|
package/dist/useAuiState.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuiState.js","
|
|
1
|
+
{"version":3,"file":"useAuiState.js","names":[],"sources":["../src/useAuiState.ts"],"sourcesContent":["import { useSyncExternalStore, useDebugValue } from \"react\";\nimport type { AssistantState } from \"./types/client\";\nimport { useAui } from \"./useAui\";\nimport { getProxiedAssistantState } from \"./utils/proxied-assistant-state\";\n\n/**\n * Subscribes to a slice of {@link AssistantState} and re-renders the\n * component whenever that slice changes.\n *\n * The `selector` is called on every store update; its return value is\n * compared by `Object.is`, and the component re-renders only when the\n * selected slice changes. Returning the entire state object is not\n * supported and throws at runtime — select a specific field instead, or\n * compose multiple `useAuiState` calls. Returning a new object or array\n * literal, including spreading `s.thread` into a new object, causes a\n * re-render on every store update; either select primitives or return a\n * memoized reference.\n *\n * @param selector - Pure function that derives a value from the current\n * assistant state. Should be cheap and referentially stable for equal\n * inputs (plain field reads, primitives, or memoized values).\n * @returns The currently selected slice.\n *\n * @example\n * ```tsx\n * // Disable a button while a run is in flight.\n * const isRunning = useAuiState((s) => s.thread.isRunning);\n * ```\n *\n * @example\n * ```tsx\n * // Prefer multiple selectors over an inline object literal, which would\n * // create a new reference on every render.\n * const text = useAuiState((s) => s.composer.text);\n * const canSend = useAuiState((s) => s.composer.canSend);\n * ```\n */\nexport const useAuiState = <T>(selector: (state: AssistantState) => T): T => {\n const aui = useAui();\n const proxiedState = getProxiedAssistantState(aui);\n\n const slice = useSyncExternalStore(\n aui.subscribe,\n () => selector(proxiedState),\n () => selector(proxiedState),\n );\n\n if (slice === proxiedState) {\n throw new Error(\n \"You tried to return the entire AssistantState. This is not supported due to technical limitations.\",\n );\n }\n\n useDebugValue(slice);\n\n return slice;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,MAAa,eAAkB,aAA8C;CAC3E,MAAM,MAAM,OAAO;CACnB,MAAM,eAAe,yBAAyB,GAAG;CAEjD,MAAM,QAAQ,qBACZ,IAAI,iBACE,SAAS,YAAY,SACrB,SAAS,YAAY,CAC7B;CAEA,IAAI,UAAU,cACZ,MAAM,IAAI,MACR,oGACF;CAGF,cAAc,KAAK;CAEnB,OAAO;AACT"}
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
+
//#region src/utils/BaseProxyHandler.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Handles common proxy introspection properties.
|
|
3
4
|
* Returns the appropriate value for toStringTag, toJSON, and props that should return undefined.
|
|
4
5
|
* Returns `false` if the prop should be handled by the subclass.
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
declare const handleIntrospectionProp: (prop: string | symbol, name: string) => unknown | false;
|
|
8
|
+
declare abstract class BaseProxyHandler implements ProxyHandler<object> {
|
|
9
|
+
abstract get(_: unknown, prop: string | symbol, receiver?: unknown): unknown;
|
|
10
|
+
abstract ownKeys(): ArrayLike<string | symbol>;
|
|
11
|
+
abstract has(_: unknown, prop: string | symbol): boolean;
|
|
12
|
+
getOwnPropertyDescriptor(_: unknown, prop: string | symbol): {
|
|
13
|
+
value: {} | null;
|
|
14
|
+
writable: boolean;
|
|
15
|
+
enumerable: boolean;
|
|
16
|
+
configurable: boolean;
|
|
17
|
+
} | undefined;
|
|
18
|
+
set(): boolean;
|
|
19
|
+
setPrototypeOf(): boolean;
|
|
20
|
+
defineProperty(): boolean;
|
|
21
|
+
deleteProperty(): boolean;
|
|
22
|
+
preventExtensions(): boolean;
|
|
22
23
|
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { BaseProxyHandler, handleIntrospectionProp };
|
|
23
26
|
//# sourceMappingURL=BaseProxyHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseProxyHandler.d.ts","
|
|
1
|
+
{"version":3,"file":"BaseProxyHandler.d.ts","names":[],"sources":["../../src/utils/BaseProxyHandler.ts"],"mappings":";;AAOA;;;;cAAa,uBAAA,GACX,IAAA,mBACA,IAAY;AAAA,uBASQ,gBAAA,YAA4B,YAAY;EAAA,SACnD,GAAA,CAAI,CAAA,WAAY,IAAA,mBAAuB,QAAA;EAAA,SACvC,OAAA,IAAW,SAAA;EAAA,SACX,GAAA,CAAI,CAAA,WAAY,IAAA;EAEzB,wBAAA,CAAyB,CAAA,WAAY,IAAA;;;;;;EAWrC,GAAA;EAGA,cAAA;EAGA,cAAA;EAGA,cAAA;EAGA,iBAAA;AAAA"}
|
|
@@ -1,46 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/utils/BaseProxyHandler.ts
|
|
2
|
+
const INTROSPECTION_PROPS = new Set([
|
|
3
|
+
"$$typeof",
|
|
4
|
+
"nodeType",
|
|
5
|
+
"then"
|
|
6
|
+
]);
|
|
2
7
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return () => name;
|
|
14
|
-
if (INTROSPECTION_PROPS.has(prop))
|
|
15
|
-
return undefined;
|
|
16
|
-
return false;
|
|
8
|
+
* Handles common proxy introspection properties.
|
|
9
|
+
* Returns the appropriate value for toStringTag, toJSON, and props that should return undefined.
|
|
10
|
+
* Returns `false` if the prop should be handled by the subclass.
|
|
11
|
+
*/
|
|
12
|
+
const handleIntrospectionProp = (prop, name) => {
|
|
13
|
+
if (prop === Symbol.toStringTag) return name;
|
|
14
|
+
if (typeof prop === "symbol") return void 0;
|
|
15
|
+
if (prop === "toJSON") return () => name;
|
|
16
|
+
if (INTROSPECTION_PROPS.has(prop)) return void 0;
|
|
17
|
+
return false;
|
|
17
18
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
19
|
+
var BaseProxyHandler = class {
|
|
20
|
+
getOwnPropertyDescriptor(_, prop) {
|
|
21
|
+
const value = this.get(_, prop);
|
|
22
|
+
if (value === void 0) return void 0;
|
|
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
|
+
};
|
|
46
|
+
//#endregion
|
|
47
|
+
export { BaseProxyHandler, handleIntrospectionProp };
|
|
48
|
+
|
|
46
49
|
//# sourceMappingURL=BaseProxyHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseProxyHandler.js","
|
|
1
|
+
{"version":3,"file":"BaseProxyHandler.js","names":[],"sources":["../../src/utils/BaseProxyHandler.ts"],"sourcesContent":["const INTROSPECTION_PROPS = new Set([\"$$typeof\", \"nodeType\", \"then\"]);\n\n/**\n * Handles common proxy introspection properties.\n * Returns the appropriate value for toStringTag, toJSON, and props that should return undefined.\n * Returns `false` if the prop should be handled by the subclass.\n */\nexport const handleIntrospectionProp = (\n prop: string | symbol,\n name: string,\n): unknown | false => {\n if (prop === Symbol.toStringTag) return name;\n if (typeof prop === \"symbol\") return undefined;\n if (prop === \"toJSON\") return () => name;\n if (INTROSPECTION_PROPS.has(prop)) return undefined;\n return false;\n};\n\nexport abstract class BaseProxyHandler implements ProxyHandler<object> {\n abstract get(_: unknown, prop: string | symbol, receiver?: unknown): unknown;\n abstract ownKeys(): ArrayLike<string | symbol>;\n abstract has(_: unknown, prop: string | symbol): boolean;\n\n getOwnPropertyDescriptor(_: unknown, prop: string | symbol) {\n const value = this.get(_, prop);\n if (value === undefined) return undefined;\n return {\n value,\n writable: false,\n enumerable: true,\n configurable: false,\n };\n }\n\n set() {\n return false;\n }\n setPrototypeOf() {\n return false;\n }\n defineProperty() {\n return false;\n }\n deleteProperty() {\n return false;\n }\n preventExtensions(): boolean {\n return false;\n }\n}\n"],"mappings":";AAAA,MAAM,sBAAsB,IAAI,IAAI;CAAC;CAAY;CAAY;AAAM,CAAC;;;;;;AAOpE,MAAa,2BACX,MACA,SACoB;CACpB,IAAI,SAAS,OAAO,aAAa,OAAO;CACxC,IAAI,OAAO,SAAS,UAAU,OAAO,KAAA;CACrC,IAAI,SAAS,UAAU,aAAa;CACpC,IAAI,oBAAoB,IAAI,IAAI,GAAG,OAAO,KAAA;CAC1C,OAAO;AACT;AAEA,IAAsB,mBAAtB,MAAuE;CAKrE,yBAAyB,GAAY,MAAuB;EAC1D,MAAM,QAAQ,KAAK,IAAI,GAAG,IAAI;EAC9B,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;EAChC,OAAO;GACL;GACA,UAAU;GACV,YAAY;GACZ,cAAc;EAChB;CACF;CAEA,MAAM;EACJ,OAAO;CACT;CACA,iBAAiB;EACf,OAAO;CACT;CACA,iBAAiB;EACf,OAAO;CACT;CACA,iBAAiB;EACf,OAAO;CACT;CACA,oBAA6B;EAC3B,OAAO;CACT;AACF"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { AssistantEventName, AssistantEventPayload } from "../types/events.js";
|
|
2
|
+
import { Unsubscribe } from "../types/client.js";
|
|
3
|
+
import { ClientStack } from "./tap-client-stack-context.js";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/NotificationManager.d.ts
|
|
6
|
+
type NotificationManager = {
|
|
7
|
+
on<TEvent extends AssistantEventName>(event: TEvent, callback: (payload: AssistantEventPayload[TEvent], clientStack: ClientStack) => void): Unsubscribe;
|
|
8
|
+
emit<TEvent extends Exclude<AssistantEventName, "*">>(event: TEvent, payload: AssistantEventPayload[TEvent], clientStack: ClientStack): void;
|
|
9
|
+
subscribe(callback: () => void): Unsubscribe;
|
|
10
|
+
notifySubscribers(): void;
|
|
9
11
|
};
|
|
10
|
-
|
|
12
|
+
declare const NotificationManager: () => import("@assistant-ui/tap").ResourceElement<NotificationManager, undefined>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { NotificationManager };
|
|
11
15
|
//# sourceMappingURL=NotificationManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationManager.d.ts","
|
|
1
|
+
{"version":3,"file":"NotificationManager.d.ts","names":[],"sources":["../../src/utils/NotificationManager.ts"],"mappings":";;;;;KAWY,mBAAA;EACV,EAAA,gBAAkB,kBAAA,EAChB,KAAA,EAAO,MAAA,EACP,QAAA,GACE,OAAA,EAAS,qBAAA,CAAsB,MAAA,GAC/B,WAAA,EAAa,WAAA,YAEd,WAAA;EACH,IAAA,gBAAoB,OAAA,CAAQ,kBAAA,QAC1B,KAAA,EAAO,MAAA,EACP,OAAA,EAAS,qBAAA,CAAsB,MAAA,GAC/B,WAAA,EAAa,WAAA;EAEf,SAAA,CAAU,QAAA,eAAuB,WAAA;EACjC,iBAAA;AAAA;AAAA,cAGW,mBAAA,oCAAmB,eAAA,CAAA,mBAAA"}
|
|
@@ -1,84 +1,71 @@
|
|
|
1
|
-
import { resource } from "@assistant-ui/tap";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
subscribe(callback) {
|
|
68
|
-
subscribers.add(callback);
|
|
69
|
-
return () => subscribers.delete(callback);
|
|
70
|
-
},
|
|
71
|
-
notifySubscribers() {
|
|
72
|
-
for (const cb of subscribers) {
|
|
73
|
-
try {
|
|
74
|
-
cb();
|
|
75
|
-
}
|
|
76
|
-
catch (e) {
|
|
77
|
-
console.error("NotificationManager: subscriber callback error", e);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
}, []);
|
|
1
|
+
import { resource, tapConst } from "@assistant-ui/tap";
|
|
2
|
+
//#region src/utils/NotificationManager.ts
|
|
3
|
+
const NotificationManager = resource(() => {
|
|
4
|
+
return tapConst(() => {
|
|
5
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
6
|
+
const wildcardListeners = /* @__PURE__ */ new Set();
|
|
7
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
8
|
+
return {
|
|
9
|
+
on(event, callback) {
|
|
10
|
+
const cb = callback;
|
|
11
|
+
if (event === "*") {
|
|
12
|
+
wildcardListeners.add(cb);
|
|
13
|
+
return () => wildcardListeners.delete(cb);
|
|
14
|
+
}
|
|
15
|
+
let set = listeners.get(event);
|
|
16
|
+
if (!set) {
|
|
17
|
+
set = /* @__PURE__ */ new Set();
|
|
18
|
+
listeners.set(event, set);
|
|
19
|
+
}
|
|
20
|
+
set.add(cb);
|
|
21
|
+
return () => {
|
|
22
|
+
set.delete(cb);
|
|
23
|
+
if (set.size === 0) listeners.delete(event);
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
emit(event, payload, clientStack) {
|
|
27
|
+
const eventListeners = listeners.get(event);
|
|
28
|
+
if (!eventListeners && wildcardListeners.size === 0) return;
|
|
29
|
+
queueMicrotask(() => {
|
|
30
|
+
const errors = [];
|
|
31
|
+
if (eventListeners) for (const cb of eventListeners) try {
|
|
32
|
+
cb(payload, clientStack);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
errors.push(e);
|
|
35
|
+
}
|
|
36
|
+
if (wildcardListeners.size > 0) {
|
|
37
|
+
const wrapped = {
|
|
38
|
+
event,
|
|
39
|
+
payload
|
|
40
|
+
};
|
|
41
|
+
for (const cb of wildcardListeners) try {
|
|
42
|
+
cb(wrapped, clientStack);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
errors.push(e);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (errors.length > 0) if (errors.length === 1) throw errors[0];
|
|
48
|
+
else {
|
|
49
|
+
for (const error of errors) console.error(error);
|
|
50
|
+
throw new AggregateError(errors, "Errors occurred during event emission");
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
subscribe(callback) {
|
|
55
|
+
subscribers.add(callback);
|
|
56
|
+
return () => subscribers.delete(callback);
|
|
57
|
+
},
|
|
58
|
+
notifySubscribers() {
|
|
59
|
+
for (const cb of subscribers) try {
|
|
60
|
+
cb();
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.error("NotificationManager: subscriber callback error", e);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}, []);
|
|
83
67
|
});
|
|
68
|
+
//#endregion
|
|
69
|
+
export { NotificationManager };
|
|
70
|
+
|
|
84
71
|
//# sourceMappingURL=NotificationManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationManager.js","
|
|
1
|
+
{"version":3,"file":"NotificationManager.js","names":[],"sources":["../../src/utils/NotificationManager.ts"],"sourcesContent":["import { resource } from \"@assistant-ui/tap\";\nimport type { ClientStack } from \"./tap-client-stack-context\";\nimport type {\n AssistantEventName,\n AssistantEventPayload,\n} from \"../types/events\";\nimport type { Unsubscribe } from \"../types/client\";\nimport { tapConst } from \"@assistant-ui/tap\";\n\ntype InternalCallback = (payload: unknown, clientStack: ClientStack) => void;\n\nexport type NotificationManager = {\n on<TEvent extends AssistantEventName>(\n event: TEvent,\n callback: (\n payload: AssistantEventPayload[TEvent],\n clientStack: ClientStack,\n ) => void,\n ): Unsubscribe;\n emit<TEvent extends Exclude<AssistantEventName, \"*\">>(\n event: TEvent,\n payload: AssistantEventPayload[TEvent],\n clientStack: ClientStack,\n ): void;\n subscribe(callback: () => void): Unsubscribe;\n notifySubscribers(): void;\n};\n\nexport const NotificationManager = resource((): NotificationManager => {\n return tapConst(() => {\n const listeners = new Map<string, Set<InternalCallback>>();\n const wildcardListeners = new Set<InternalCallback>();\n const subscribers = new Set<() => void>();\n\n return {\n on(event, callback) {\n const cb = callback as InternalCallback;\n if (event === \"*\") {\n wildcardListeners.add(cb);\n return () => wildcardListeners.delete(cb);\n }\n\n let set = listeners.get(event);\n if (!set) {\n set = new Set();\n listeners.set(event, set);\n }\n set.add(cb);\n\n return () => {\n set!.delete(cb);\n if (set!.size === 0) listeners.delete(event);\n };\n },\n\n emit(event, payload, clientStack) {\n const eventListeners = listeners.get(event);\n if (!eventListeners && wildcardListeners.size === 0) return;\n\n queueMicrotask(() => {\n const errors = [];\n if (eventListeners) {\n for (const cb of eventListeners) {\n try {\n cb(payload, clientStack);\n } catch (e) {\n errors.push(e);\n }\n }\n }\n if (wildcardListeners.size > 0) {\n const wrapped = { event, payload };\n for (const cb of wildcardListeners) {\n try {\n cb(wrapped, clientStack);\n } catch (e) {\n errors.push(e);\n }\n }\n }\n\n if (errors.length > 0) {\n if (errors.length === 1) {\n throw errors[0];\n } else {\n for (const error of errors) {\n console.error(error);\n }\n throw new AggregateError(\n errors,\n \"Errors occurred during event emission\",\n );\n }\n }\n });\n },\n\n subscribe(callback) {\n subscribers.add(callback);\n return () => subscribers.delete(callback);\n },\n\n notifySubscribers() {\n for (const cb of subscribers) {\n try {\n cb();\n } catch (e) {\n console.error(\"NotificationManager: subscriber callback error\", e);\n }\n }\n },\n };\n }, []);\n});\n"],"mappings":";;AA4BA,MAAa,sBAAsB,eAAoC;CACrE,OAAO,eAAe;EACpB,MAAM,4BAAY,IAAI,IAAmC;EACzD,MAAM,oCAAoB,IAAI,IAAsB;EACpD,MAAM,8BAAc,IAAI,IAAgB;EAExC,OAAO;GACL,GAAG,OAAO,UAAU;IAClB,MAAM,KAAK;IACX,IAAI,UAAU,KAAK;KACjB,kBAAkB,IAAI,EAAE;KACxB,aAAa,kBAAkB,OAAO,EAAE;IAC1C;IAEA,IAAI,MAAM,UAAU,IAAI,KAAK;IAC7B,IAAI,CAAC,KAAK;KACR,sBAAM,IAAI,IAAI;KACd,UAAU,IAAI,OAAO,GAAG;IAC1B;IACA,IAAI,IAAI,EAAE;IAEV,aAAa;KACX,IAAK,OAAO,EAAE;KACd,IAAI,IAAK,SAAS,GAAG,UAAU,OAAO,KAAK;IAC7C;GACF;GAEA,KAAK,OAAO,SAAS,aAAa;IAChC,MAAM,iBAAiB,UAAU,IAAI,KAAK;IAC1C,IAAI,CAAC,kBAAkB,kBAAkB,SAAS,GAAG;IAErD,qBAAqB;KACnB,MAAM,SAAS,CAAC;KAChB,IAAI,gBACF,KAAK,MAAM,MAAM,gBACf,IAAI;MACF,GAAG,SAAS,WAAW;KACzB,SAAS,GAAG;MACV,OAAO,KAAK,CAAC;KACf;KAGJ,IAAI,kBAAkB,OAAO,GAAG;MAC9B,MAAM,UAAU;OAAE;OAAO;MAAQ;MACjC,KAAK,MAAM,MAAM,mBACf,IAAI;OACF,GAAG,SAAS,WAAW;MACzB,SAAS,GAAG;OACV,OAAO,KAAK,CAAC;MACf;KAEJ;KAEA,IAAI,OAAO,SAAS,GAClB,IAAI,OAAO,WAAW,GACpB,MAAM,OAAO;UACR;MACL,KAAK,MAAM,SAAS,QAClB,QAAQ,MAAM,KAAK;MAErB,MAAM,IAAI,eACR,QACA,uCACF;KACF;IAEJ,CAAC;GACH;GAEA,UAAU,UAAU;IAClB,YAAY,IAAI,QAAQ;IACxB,aAAa,YAAY,OAAO,QAAQ;GAC1C;GAEA,oBAAoB;IAClB,KAAK,MAAM,MAAM,aACf,IAAI;KACF,GAAG;IACL,SAAS,GAAG;KACV,QAAQ,MAAM,kDAAkD,CAAC;IACnE;GAEJ;EACF;CACF,GAAG,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { AssistantClient, AssistantState } from "../types/client.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/proxied-assistant-state.d.ts
|
|
4
|
+
declare const PROXIED_ASSISTANT_STATE_SYMBOL: unique symbol;
|
|
3
5
|
/**
|
|
4
6
|
* Proxied state that lazily accesses scope states
|
|
5
7
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
declare const createProxiedAssistantState: (client: AssistantClient) => AssistantState;
|
|
9
|
+
declare const getProxiedAssistantState: (client: AssistantClient) => AssistantState;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { PROXIED_ASSISTANT_STATE_SYMBOL, createProxiedAssistantState, getProxiedAssistantState };
|
|
8
12
|
//# sourceMappingURL=proxied-assistant-state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxied-assistant-state.d.ts","
|
|
1
|
+
{"version":3,"file":"proxied-assistant-state.d.ts","names":[],"sources":["../../src/utils/proxied-assistant-state.ts"],"mappings":";;;cAKa,8BAAA;;AAAb;;cAWa,2BAAA,GACX,MAAA,EAAQ,eAAA,KACP,cA0BF;AAAA,cAEY,wBAAA,GACX,MAAA,EAAQ,eAAA,KACP,cAIF"}
|
|
@@ -1,34 +1,36 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { getClientState } from "../tapClientResource.js";
|
|
3
2
|
import { BaseProxyHandler, handleIntrospectionProp } from "./BaseProxyHandler.js";
|
|
4
|
-
|
|
3
|
+
import { getClientState } from "../tapClientResource.js";
|
|
4
|
+
//#region src/utils/proxied-assistant-state.ts
|
|
5
|
+
const PROXIED_ASSISTANT_STATE_SYMBOL = Symbol("assistant-ui.store.proxiedAssistantState");
|
|
5
6
|
const isIgnoredKey = (key) => {
|
|
6
|
-
|
|
7
|
+
return key === "on" || key === "subscribe" || typeof key === "symbol";
|
|
7
8
|
};
|
|
8
9
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
return new Proxy({}, new ProxiedAssistantStateProxyHandler());
|
|
10
|
+
* Proxied state that lazily accesses scope states
|
|
11
|
+
*/
|
|
12
|
+
const createProxiedAssistantState = (client) => {
|
|
13
|
+
class ProxiedAssistantStateProxyHandler extends BaseProxyHandler {
|
|
14
|
+
get(_, prop) {
|
|
15
|
+
const introspection = handleIntrospectionProp(prop, "AssistantState");
|
|
16
|
+
if (introspection !== false) return introspection;
|
|
17
|
+
const scope = prop;
|
|
18
|
+
if (isIgnoredKey(scope)) return void 0;
|
|
19
|
+
return getClientState(client[scope]());
|
|
20
|
+
}
|
|
21
|
+
ownKeys() {
|
|
22
|
+
return Object.keys(client).filter((key) => !isIgnoredKey(key));
|
|
23
|
+
}
|
|
24
|
+
has(_, prop) {
|
|
25
|
+
return !isIgnoredKey(prop) && prop in client;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return new Proxy({}, new ProxiedAssistantStateProxyHandler());
|
|
30
29
|
};
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const getProxiedAssistantState = (client) => {
|
|
31
|
+
return client[PROXIED_ASSISTANT_STATE_SYMBOL];
|
|
33
32
|
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { PROXIED_ASSISTANT_STATE_SYMBOL, createProxiedAssistantState, getProxiedAssistantState };
|
|
35
|
+
|
|
34
36
|
//# sourceMappingURL=proxied-assistant-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxied-assistant-state.js","
|
|
1
|
+
{"version":3,"file":"proxied-assistant-state.js","names":[],"sources":["../../src/utils/proxied-assistant-state.ts"],"sourcesContent":["\"use client\";\nimport { getClientState } from \"../tapClientResource\";\nimport type { AssistantClient, AssistantState } from \"../types/client\";\nimport { BaseProxyHandler, handleIntrospectionProp } from \"./BaseProxyHandler\";\n\nexport const PROXIED_ASSISTANT_STATE_SYMBOL = Symbol(\n \"assistant-ui.store.proxiedAssistantState\",\n);\n\nconst isIgnoredKey = (key: string | symbol): key is \"on\" | \"subscribe\" => {\n return key === \"on\" || key === \"subscribe\" || typeof key === \"symbol\";\n};\n\n/**\n * Proxied state that lazily accesses scope states\n */\nexport const createProxiedAssistantState = (\n client: AssistantClient,\n): AssistantState => {\n class ProxiedAssistantStateProxyHandler\n extends BaseProxyHandler\n implements ProxyHandler<AssistantState>\n {\n get(_: unknown, prop: string | symbol) {\n const introspection = handleIntrospectionProp(prop, \"AssistantState\");\n if (introspection !== false) return introspection;\n const scope = prop as keyof AssistantClient;\n if (isIgnoredKey(scope)) return undefined;\n return getClientState(client[scope]());\n }\n\n ownKeys(): ArrayLike<string | symbol> {\n return Object.keys(client).filter((key) => !isIgnoredKey(key));\n }\n\n has(_: unknown, prop: string | symbol): boolean {\n return !isIgnoredKey(prop) && prop in client;\n }\n }\n\n return new Proxy<AssistantState>(\n {} as AssistantState,\n new ProxiedAssistantStateProxyHandler(),\n );\n};\n\nexport const getProxiedAssistantState = (\n client: AssistantClient,\n): AssistantState => {\n return (\n client as unknown as { [PROXIED_ASSISTANT_STATE_SYMBOL]: AssistantState }\n )[PROXIED_ASSISTANT_STATE_SYMBOL];\n};\n"],"mappings":";;;;AAKA,MAAa,iCAAiC,OAC5C,0CACF;AAEA,MAAM,gBAAgB,QAAoD;CACxE,OAAO,QAAQ,QAAQ,QAAQ,eAAe,OAAO,QAAQ;AAC/D;;;;AAKA,MAAa,+BACX,WACmB;CACnB,MAAM,0CACI,iBAEV;EACE,IAAI,GAAY,MAAuB;GACrC,MAAM,gBAAgB,wBAAwB,MAAM,gBAAgB;GACpE,IAAI,kBAAkB,OAAO,OAAO;GACpC,MAAM,QAAQ;GACd,IAAI,aAAa,KAAK,GAAG,OAAO,KAAA;GAChC,OAAO,eAAe,OAAO,OAAO,CAAC;EACvC;EAEA,UAAsC;GACpC,OAAO,OAAO,KAAK,MAAM,EAAE,QAAQ,QAAQ,CAAC,aAAa,GAAG,CAAC;EAC/D;EAEA,IAAI,GAAY,MAAgC;GAC9C,OAAO,CAAC,aAAa,IAAI,KAAK,QAAQ;EACxC;CACF;CAEA,OAAO,IAAI,MACT,CAAC,GACD,IAAI,kCAAkC,CACxC;AACF;AAEA,MAAa,4BACX,WACmB;CACnB,OACE,OACA;AACJ"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { AssistantClient } from "../types/client.js";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/react-assistant-context.d.ts
|
|
3
5
|
/** Default context value - throws "wrap in AuiProvider" error */
|
|
4
|
-
|
|
6
|
+
declare const DefaultAssistantClient: AssistantClient;
|
|
5
7
|
/** Root prototype for created clients - throws "scope not defined" error */
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
declare const createRootAssistantClient: () => AssistantClient;
|
|
9
|
+
declare const useAssistantContextValue: () => AssistantClient;
|
|
8
10
|
/**
|
|
9
11
|
* Supplies an `AssistantClient` to the React tree.
|
|
10
12
|
*
|
|
@@ -26,10 +28,13 @@ export declare const useAssistantContextValue: () => AssistantClient;
|
|
|
26
28
|
* }
|
|
27
29
|
* ```
|
|
28
30
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
declare const AuiProvider: ({
|
|
32
|
+
value,
|
|
33
|
+
children
|
|
34
|
+
}: {
|
|
35
|
+
/** Assistant client to expose to descendants. */value: AssistantClient; /** Subtree that may read from the client. */
|
|
36
|
+
children: React.ReactNode;
|
|
34
37
|
}) => React.ReactElement;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { AuiProvider, DefaultAssistantClient, createRootAssistantClient, useAssistantContextValue };
|
|
35
40
|
//# sourceMappingURL=react-assistant-context.d.ts.map
|