@assistant-ui/store 0.2.9 → 0.2.11
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/README.md +36 -65
- package/dist/AuiIf.d.ts +31 -0
- package/dist/AuiIf.d.ts.map +1 -1
- package/dist/AuiIf.js +22 -0
- package/dist/AuiIf.js.map +1 -1
- package/dist/Derived.d.ts +1 -3
- package/dist/Derived.d.ts.map +1 -1
- package/dist/RenderChildrenWithAccessor.d.ts.map +1 -1
- package/dist/RenderChildrenWithAccessor.js +11 -7
- package/dist/RenderChildrenWithAccessor.js.map +1 -1
- package/dist/useAui.d.ts +59 -0
- package/dist/useAui.d.ts.map +1 -1
- package/dist/useAui.js +39 -21
- package/dist/useAui.js.map +1 -1
- package/dist/useAuiEvent.d.ts +41 -0
- package/dist/useAuiEvent.d.ts.map +1 -1
- package/dist/useAuiEvent.js +41 -0
- package/dist/useAuiEvent.js.map +1 -1
- package/dist/useAuiState.d.ts +25 -8
- package/dist/useAuiState.d.ts.map +1 -1
- package/dist/useAuiState.js +25 -8
- package/dist/useAuiState.js.map +1 -1
- package/dist/utils/react-assistant-context.d.ts +18 -5
- package/dist/utils/react-assistant-context.d.ts.map +1 -1
- package/dist/utils/react-assistant-context.js +16 -5
- package/dist/utils/react-assistant-context.js.map +1 -1
- package/dist/utils/splitClients.d.ts.map +1 -1
- package/dist/utils/splitClients.js.map +1 -1
- package/package.json +5 -5
- package/src/AuiIf.ts +35 -1
- package/src/Derived.ts +1 -1
- package/src/RenderChildrenWithAccessor.tsx +10 -8
- package/src/__tests__/RenderChildrenWithAccessor.test.tsx +136 -0
- package/src/useAui.ts +101 -32
- package/src/useAuiEvent.ts +41 -0
- package/src/useAuiState.ts +25 -8
- package/src/utils/react-assistant-context.tsx +18 -5
- package/src/utils/splitClients.ts +4 -2
package/README.md
CHANGED
|
@@ -1,30 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@assistant-ui/store`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@assistant-ui/store)
|
|
4
|
+
[](https://github.com/assistant-ui/assistant-ui)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
Tap-based state container with React Context integration. Bridges `@assistant-ui/tap` resources into React via `useAui`, `useAuiState`, and `<AuiProvider>`.
|
|
7
|
+
|
|
8
|
+
`store` powers the runtime layer of assistant-ui. Most users do not install it directly; reach for `@assistant-ui/react` instead.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @assistant-ui/store @assistant-ui/tap
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
6
17
|
|
|
7
18
|
```typescript
|
|
8
19
|
import { resource, tapState } from "@assistant-ui/tap";
|
|
9
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
useAui,
|
|
22
|
+
useAuiState,
|
|
23
|
+
AuiProvider,
|
|
24
|
+
type ClientOutput,
|
|
25
|
+
} from "@assistant-ui/store";
|
|
10
26
|
|
|
11
|
-
// 1. Define client type
|
|
12
27
|
declare module "@assistant-ui/store" {
|
|
13
28
|
interface ScopeRegistry {
|
|
14
|
-
counter: {
|
|
29
|
+
counter: {
|
|
30
|
+
methods: {
|
|
31
|
+
getState: () => { count: number };
|
|
32
|
+
increment: () => void;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
15
35
|
}
|
|
16
36
|
}
|
|
17
37
|
|
|
18
|
-
// 2. Create resource
|
|
19
38
|
const CounterClient = resource((): ClientOutput<"counter"> => {
|
|
20
39
|
const [state, setState] = tapState({ count: 0 });
|
|
21
|
-
return {
|
|
40
|
+
return {
|
|
41
|
+
getState: () => state,
|
|
42
|
+
increment: () => setState({ count: state.count + 1 }),
|
|
43
|
+
};
|
|
22
44
|
});
|
|
23
45
|
|
|
24
|
-
// 3. Use in React
|
|
25
46
|
function App() {
|
|
26
47
|
const aui = useAui({ counter: CounterClient() });
|
|
27
|
-
return
|
|
48
|
+
return (
|
|
49
|
+
<AuiProvider value={aui}>
|
|
50
|
+
<Counter />
|
|
51
|
+
</AuiProvider>
|
|
52
|
+
);
|
|
28
53
|
}
|
|
29
54
|
|
|
30
55
|
function Counter() {
|
|
@@ -34,58 +59,4 @@ function Counter() {
|
|
|
34
59
|
}
|
|
35
60
|
```
|
|
36
61
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
**Clients**: Named state containers registered via module augmentation.
|
|
40
|
-
```typescript
|
|
41
|
-
declare module "@assistant-ui/store" {
|
|
42
|
-
interface ScopeRegistry {
|
|
43
|
-
myClient: {
|
|
44
|
-
methods: MyMethods; // must include getState(): MyState
|
|
45
|
-
meta?: { source: "parent"; query: { id: string } };
|
|
46
|
-
events?: { "myClient.updated": { id: string } };
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
**Derived Clients**: Access nested clients from parents.
|
|
53
|
-
```typescript
|
|
54
|
-
useAui({
|
|
55
|
-
item: Derived({ source: "list", query: { index: 0 }, get: (aui) => aui.list().item({ index: 0 }) }),
|
|
56
|
-
});
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
**Events**:
|
|
60
|
-
```typescript
|
|
61
|
-
const emit = tapAssistantEmit();
|
|
62
|
-
emit("myClient.updated", { id: "123" });
|
|
63
|
-
|
|
64
|
-
useAuiEvent("myClient.updated", (p) => console.log(p.id));
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## API
|
|
68
|
-
|
|
69
|
-
| Hook/Component | Description |
|
|
70
|
-
|----------------|-------------|
|
|
71
|
-
| `useAui()` | Get client from context |
|
|
72
|
-
| `useAui(clients)` | Create/extend client |
|
|
73
|
-
| `useAuiState(selector)` | Subscribe to state |
|
|
74
|
-
| `useAuiEvent(event, cb)` | Subscribe to events |
|
|
75
|
-
| `AuiProvider` | Provide client to tree |
|
|
76
|
-
| `AuiIf` | Conditional rendering |
|
|
77
|
-
|
|
78
|
-
| Tap Utility | Description |
|
|
79
|
-
|-------------|-------------|
|
|
80
|
-
| `tapAssistantClientRef()` | Access client ref in resources |
|
|
81
|
-
| `tapAssistantEmit()` | Emit events from resources |
|
|
82
|
-
| `tapClientResource(element)` | Wrap resource for event scoping (1:1 mappings) |
|
|
83
|
-
| `tapClientLookup(map, fn, deps)` | Lookup by `{index}` or `{key}` |
|
|
84
|
-
| `tapClientList(config)` | Dynamic list with add/remove |
|
|
85
|
-
| `attachTransformScopes(resource, fn)` | Attach scope transform |
|
|
86
|
-
|
|
87
|
-
| Type | Description |
|
|
88
|
-
|------|-------------|
|
|
89
|
-
| `ClientOutput<K>` | Resource return type (methods object) |
|
|
90
|
-
| `ScopeRegistry` | Module augmentation interface |
|
|
91
|
-
| `AssistantClient` | Full client type |
|
|
62
|
+
Full API reference (clients, derived clients, events, `tapClientLookup`, `tapClientList`) at [assistant-ui.com/tap/docs/store/quickstart](https://www.assistant-ui.com/tap/docs/store/quickstart).
|
package/dist/AuiIf.d.ts
CHANGED
|
@@ -1,10 +1,41 @@
|
|
|
1
1
|
import type { FC, PropsWithChildren } from "react";
|
|
2
2
|
import type { AssistantState } from "./types/client.js";
|
|
3
3
|
export declare namespace AuiIf {
|
|
4
|
+
/** Props for `AuiIf`. */
|
|
4
5
|
type Props = PropsWithChildren<{
|
|
6
|
+
/**
|
|
7
|
+
* Selector that decides whether to render `children`. Children render
|
|
8
|
+
* when this returns `true` and unmount when it returns `false`.
|
|
9
|
+
*/
|
|
5
10
|
condition: AuiIf.Condition;
|
|
6
11
|
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Selector passed to `AuiIf`. Receives the assistant state and must
|
|
14
|
+
* return a boolean.
|
|
15
|
+
*/
|
|
7
16
|
type Condition = (state: AssistantState) => boolean;
|
|
8
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Conditionally renders children based on a slice of assistant state.
|
|
20
|
+
*
|
|
21
|
+
* A thin wrapper around {@link useAuiState} that renders its children
|
|
22
|
+
* when `condition` returns `true` and unmounts them when it returns
|
|
23
|
+
* `false`. Keeps render logic declarative without mounting unused
|
|
24
|
+
* subtrees.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* <AuiIf condition={(s) => s.thread.isRunning}>
|
|
29
|
+
* <CancelButton />
|
|
30
|
+
* </AuiIf>
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* <AuiIf condition={(s) => s.thread.messages.length === 0}>
|
|
36
|
+
* <EmptyState />
|
|
37
|
+
* </AuiIf>
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
9
40
|
export declare const AuiIf: FC<AuiIf.Props>;
|
|
10
41
|
//# sourceMappingURL=AuiIf.d.ts.map
|
package/dist/AuiIf.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuiIf.d.ts","sourceRoot":"","sources":["../src/AuiIf.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,0BAAuB;AAErD,yBAAiB,KAAK,CAAC;IACrB,KAAY,KAAK,GAAG,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"AuiIf.d.ts","sourceRoot":"","sources":["../src/AuiIf.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,0BAAuB;AAErD,yBAAiB,KAAK,CAAC;IACrB,yBAAyB;IACzB,KAAY,KAAK,GAAG,iBAAiB,CAAC;QACpC;;;WAGG;QACH,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC;KAC5B,CAAC,CAAC;IAEH;;;OAGG;IACH,KAAY,SAAS,GAAG,CAAC,KAAK,EAAE,cAAc,KAAK,OAAO,CAAC;CAC5D;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAGjC,CAAC"}
|
package/dist/AuiIf.js
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useAuiState } from "./useAuiState.js";
|
|
3
|
+
/**
|
|
4
|
+
* Conditionally renders children based on a slice of assistant state.
|
|
5
|
+
*
|
|
6
|
+
* A thin wrapper around {@link useAuiState} that renders its children
|
|
7
|
+
* when `condition` returns `true` and unmounts them when it returns
|
|
8
|
+
* `false`. Keeps render logic declarative without mounting unused
|
|
9
|
+
* subtrees.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <AuiIf condition={(s) => s.thread.isRunning}>
|
|
14
|
+
* <CancelButton />
|
|
15
|
+
* </AuiIf>
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* <AuiIf condition={(s) => s.thread.messages.length === 0}>
|
|
21
|
+
* <EmptyState />
|
|
22
|
+
* </AuiIf>
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
3
25
|
export const AuiIf = ({ children, condition }) => {
|
|
4
26
|
const result = useAuiState(condition);
|
|
5
27
|
return result ? children : null;
|
package/dist/AuiIf.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuiIf.js","sourceRoot":"","sources":["../src/AuiIf.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAGb,OAAO,EAAE,WAAW,EAAE,yBAAsB;
|
|
1
|
+
{"version":3,"file":"AuiIf.js","sourceRoot":"","sources":["../src/AuiIf.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAGb,OAAO,EAAE,WAAW,EAAE,yBAAsB;AAoB5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,KAAK,GAAoB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;IAChE,MAAM,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;AAClC,CAAC,CAAC;AAEF,KAAK,CAAC,WAAW,GAAG,OAAO,CAAC"}
|
package/dist/Derived.d.ts
CHANGED
|
@@ -27,8 +27,6 @@ export declare namespace Derived {
|
|
|
27
27
|
*/
|
|
28
28
|
type Props<K extends ClientNames> = {
|
|
29
29
|
get: (client: AssistantClient) => ReturnType<AssistantClientAccessor<K>>;
|
|
30
|
-
} &
|
|
31
|
-
getMeta: (client: AssistantClient) => ClientMeta<K>;
|
|
32
|
-
});
|
|
30
|
+
} & ClientMeta<K>;
|
|
33
31
|
}
|
|
34
32
|
//# sourceMappingURL=Derived.d.ts.map
|
package/dist/Derived.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Derived.d.ts","sourceRoot":"","sources":["../src/Derived.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,uBAAuB,EACvB,UAAU,EACX,0BAAuB;AAExB;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,OAAO,GACjB,CAAC,SAAS,WAAW,qEAGvB,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,WAAW,IAAI,eAAe,CACjE,IAAI,EACJ,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CACjB,CAAC;AAEF,yBAAiB,OAAO,CAAC;IACvB;;OAEG;IACH,KAAY,KAAK,CAAC,CAAC,SAAS,WAAW,IAAI;QACzC,GAAG,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,UAAU,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC;KAC1E,GAAG,
|
|
1
|
+
{"version":3,"file":"Derived.d.ts","sourceRoot":"","sources":["../src/Derived.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,uBAAuB,EACvB,UAAU,EACX,0BAAuB;AAExB;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,OAAO,GACjB,CAAC,SAAS,WAAW,qEAGvB,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,WAAW,IAAI,eAAe,CACjE,IAAI,EACJ,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CACjB,CAAC;AAEF,yBAAiB,OAAO,CAAC;IACvB;;OAEG;IACH,KAAY,KAAK,CAAC,CAAC,SAAS,WAAW,IAAI;QACzC,GAAG,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,UAAU,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC;KAC1E,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;CACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderChildrenWithAccessor.d.ts","sourceRoot":"","sources":["../src/RenderChildrenWithAccessor.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,OAAO,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,0BAAuB;AAItD,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAClC,cAAc,CAAC,GAAG,EAAE,eAAe,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"RenderChildrenWithAccessor.d.ts","sourceRoot":"","sources":["../src/RenderChildrenWithAccessor.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,OAAO,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,0BAAuB;AAItD,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAClC,cAAc,CAAC,GAAG,EAAE,eAAe,KAAK,CAAC,YAoB1C,CAAC;AAIF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,EAC5C,YAAY,EACZ,QAAQ,GACT,EAAE;IACD,YAAY,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,CAAC,CAAC;IAC1C,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,SAAS,CAAC;CAC3C,GAAG,SAAS,CAGZ"}
|
|
@@ -4,16 +4,20 @@ import { useAuiState } from "./useAuiState.js";
|
|
|
4
4
|
import { useAui } from "./useAui.js";
|
|
5
5
|
export const useGetItemAccessor = (getItemState) => {
|
|
6
6
|
const aui = useAui();
|
|
7
|
-
//
|
|
8
|
-
|
|
7
|
+
// Track access with a dedicated flag:
|
|
8
|
+
// useSyncExternalStore may call getSnapshot() after commit (tearing checks),
|
|
9
|
+
// which would re-cache the current state and mask later real updates.
|
|
10
|
+
// Use the current state as the pre-access snapshot so the post-commit check
|
|
11
|
+
// matches getItemState(aui) and doesn't schedule an unnecessary re-render.
|
|
12
|
+
const accessedRef = useRef(false);
|
|
13
|
+
const currentValue = accessedRef.current ? null : getItemState(aui);
|
|
9
14
|
useAuiState(() => {
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return cacheRef.current;
|
|
15
|
+
if (!accessedRef.current)
|
|
16
|
+
return currentValue;
|
|
17
|
+
return getItemState(aui);
|
|
14
18
|
});
|
|
15
19
|
return () => {
|
|
16
|
-
|
|
20
|
+
accessedRef.current = true;
|
|
17
21
|
return getItemState(aui);
|
|
18
22
|
};
|
|
19
23
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderChildrenWithAccessor.js","sourceRoot":"","sources":["../src/RenderChildrenWithAccessor.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAkB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AcG;AACH,MAAM,UAAU,0BAA0B,CAAI,EAC5C,YAAY,EACZ,QAAQ,GAIT;IACC,MAAM,OAAO,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC;IACjD,OAAO,4BAA4B,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,4BAA4B,GAAG,CAAC,IAAe,EAAE,EAAE;IACvD,MAAM,EAAE,GACN,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3E,MAAM,UAAU,GAAG,EAAE,EAAE,IAAI,CAAC;IAC5B,MAAM,SAAS,GAAG,EAAE,EAAE,GAAG,CAAC;IAC1B,MAAM,WAAW,GACf,OAAO,EAAE,EAAE,KAAK,KAAK,QAAQ;QAC7B,EAAE,CAAC,KAAK,IAAI,IAAI;QAChB,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC;QACnC,CAAC,CAAC,YAAY;QACd,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC;IAEhB,OAAO;IACL,wEAAwE;IACxE,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,IAAI,IAAI,CAChE,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/useAui.d.ts
CHANGED
|
@@ -15,8 +15,67 @@ export declare namespace useAui {
|
|
|
15
15
|
[K in ClientNames]?: ClientElement<K> | DerivedElement<K>;
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Returns the current `AssistantClient` from context.
|
|
20
|
+
*
|
|
21
|
+
* Read the client supplied by the nearest {@link AuiProvider} or
|
|
22
|
+
* {@link AssistantRuntimeProvider}, then access a scope on it —
|
|
23
|
+
* `aui.thread()`, `aui.composer()`, `aui.message()`, and so on. Pair
|
|
24
|
+
* with {@link useAuiState} to read reactive state and {@link useAuiEvent}
|
|
25
|
+
* to subscribe to events. The returned client also exposes lower-level
|
|
26
|
+
* methods such as `aui.on(...)` and `aui.subscribe(...)`; prefer
|
|
27
|
+
* `useAuiEvent` for React event subscriptions.
|
|
28
|
+
*
|
|
29
|
+
* Rendered outside a provider, the returned client's scope accessors
|
|
30
|
+
* throw a descriptive error whenever they are called.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* const aui = useAui();
|
|
35
|
+
*
|
|
36
|
+
* const onSend = () => aui.composer().send();
|
|
37
|
+
* const onCancel = () => aui.thread().cancelRun();
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```tsx
|
|
42
|
+
* // Combine with useAuiState to drive disabled state.
|
|
43
|
+
* const aui = useAui();
|
|
44
|
+
* const isRunning = useAuiState((s) => s.thread.isRunning);
|
|
45
|
+
*
|
|
46
|
+
* return (
|
|
47
|
+
* <button disabled={isRunning} onClick={() => aui.composer().send()}>
|
|
48
|
+
* Send
|
|
49
|
+
* </button>
|
|
50
|
+
* );
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
18
53
|
export declare function useAui(): AssistantClient;
|
|
54
|
+
/**
|
|
55
|
+
* Extends the parent `AssistantClient` with additional scopes.
|
|
56
|
+
*
|
|
57
|
+
* Advanced overload used when building primitives or providers — for example,
|
|
58
|
+
* when a custom provider needs to register a `message`, `part`, or other scope
|
|
59
|
+
* onto the client visible to its descendants. Application code rarely reaches
|
|
60
|
+
* for this; use {@link useAui} with no arguments to read the existing client.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```tsx
|
|
64
|
+
* const aui = useAui({
|
|
65
|
+
* message: Derived({
|
|
66
|
+
* source: "thread",
|
|
67
|
+
* query: { index: 0 },
|
|
68
|
+
* get: (aui) => aui.thread().message({ index: 0 }),
|
|
69
|
+
* }),
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* const role = useAuiState((s) => s.message.role);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
19
75
|
export declare function useAui(clients: useAui.Props): AssistantClient;
|
|
76
|
+
/**
|
|
77
|
+
* Extends an explicit parent `AssistantClient` with additional scopes.
|
|
78
|
+
*/
|
|
20
79
|
export declare function useAui(clients: useAui.Props, config: {
|
|
21
80
|
parent: null | AssistantClient;
|
|
22
81
|
}): AssistantClient;
|
package/dist/useAui.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAui.d.ts","sourceRoot":"","sources":["../src/useAui.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useAui.d.ts","sourceRoot":"","sources":["../src/useAui.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,eAAe,EAEf,WAAW,EACX,aAAa,EAEd,0BAAuB;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAkB;AAsRhD;;GAEG;AACH,eAAO,MAAM,uBAAuB;YAKxB,eAAe;aACd,MAAM,CAAC,KAAK;;YADb,eAAe;aACd,MAAM,CAAC,KAAK;EAwDxB,CAAC;AAEF,yBAAiB,MAAM,CAAC;IACtB,KAAY,KAAK,GAAG;SACjB,CAAC,IAAI,WAAW,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC;KAC1D,CAAC;CACH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,MAAM,IAAI,eAAe,CAAC;AAC1C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,GAAG,eAAe,CAAC;AAC/D;;GAEG;AACH,wBAAgB,MAAM,CACpB,OAAO,EAAE,MAAM,CAAC,KAAK,EACrB,MAAM,EAAE;IAAE,MAAM,EAAE,IAAI,GAAG,eAAe,CAAA;CAAE,GACzC,eAAe,CAAC"}
|
package/dist/useAui.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useResource } from "@assistant-ui/tap/react";
|
|
3
|
-
import { resource, tapMemo, tapResources,
|
|
3
|
+
import { resource, tapMemo, tapResources, tapEffect, tapRef, tapResource, withKey, tapResourceRoot, } from "@assistant-ui/tap";
|
|
4
4
|
import { useAssistantContextValue, DefaultAssistantClient, createRootAssistantClient, } from "./utils/react-assistant-context.js";
|
|
5
5
|
import { tapSplitClients, } from "./utils/splitClients.js";
|
|
6
6
|
import { normalizeEventSelector, } from "./types/events.js";
|
|
@@ -95,27 +95,24 @@ const RootClientsAccessorsResource = resource(({ clients: inputClients, clientRe
|
|
|
95
95
|
};
|
|
96
96
|
}, [results, notifications, clientRef]);
|
|
97
97
|
});
|
|
98
|
-
const getMeta = (props, clientRef, memo) => {
|
|
99
|
-
if ("source" in props && "query" in props)
|
|
100
|
-
return props;
|
|
101
|
-
if (memo.dep === props)
|
|
102
|
-
return memo.meta;
|
|
103
|
-
const meta = props.getMeta(clientRef.current);
|
|
104
|
-
memo.meta = meta;
|
|
105
|
-
memo.dep = props;
|
|
106
|
-
return meta;
|
|
107
|
-
};
|
|
108
98
|
const DerivedClientAccessorResource = resource(({ element, clientRef, name, }) => {
|
|
109
|
-
|
|
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;
|
|
110
108
|
return tapMemo(() => {
|
|
111
|
-
const clientFunction = () =>
|
|
112
|
-
const metaMemo = {};
|
|
109
|
+
const clientFunction = () => propsRef.current.get(clientRef.current);
|
|
113
110
|
Object.defineProperties(clientFunction, {
|
|
114
111
|
source: {
|
|
115
|
-
|
|
112
|
+
value: propsRef.current.source,
|
|
116
113
|
},
|
|
117
114
|
query: {
|
|
118
|
-
|
|
115
|
+
value: propsRef.current.query,
|
|
119
116
|
},
|
|
120
117
|
name: {
|
|
121
118
|
value: name,
|
|
@@ -125,12 +122,33 @@ const DerivedClientAccessorResource = resource(({ element, clientRef, name, }) =
|
|
|
125
122
|
return clientFunction;
|
|
126
123
|
}, [clientRef, name]);
|
|
127
124
|
});
|
|
125
|
+
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}`;
|
|
141
|
+
};
|
|
128
142
|
const DerivedClientsAccessorsResource = resource(({ clients, clientRef, }) => {
|
|
129
|
-
return tapShallowMemoArray(tapResources(() => Object.keys(clients).map((key) =>
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
name
|
|
133
|
-
|
|
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]));
|
|
134
152
|
});
|
|
135
153
|
/**
|
|
136
154
|
* Resource that creates an extended AssistantClient.
|
package/dist/useAui.js.map
CHANGED
|
@@ -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,
|
|
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;AACzC,OAAO,EAGL,eAAe,GAChB,gCAA6B;AAC9B,OAAO,EACL,sBAAsB,GAIvB,0BAAuB;AACxB,OAAO,EAAE,mBAAmB,EAAE,uCAAoC;AAClE,OAAO,EAAE,+BAA+B,EAAE,yCAAsC;AAChF,OAAO,EAAE,iBAAiB,EAAE,+BAA4B;AACxD,OAAO,EAAE,cAAc,EAAE,4CAAyC;AAClE,OAAO,EACL,8BAA8B,EAC9B,2BAA2B,GAC5B,2CAAwC;AAEzC,MAAM,mBAAmB,GAAG,CAAI,KAAmB,EAAE,EAAE;IACrD,wEAAwE;IACxE,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,QAAQ,CACjC,CAAwB,EACtB,OAAO,EACP,IAAI,EACJ,SAAS,GAKV,EAAE,EAAE;IACH,MAAM,EAAE,OAAO,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,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"}
|
package/dist/useAuiEvent.d.ts
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
1
|
import type { AssistantEventName, AssistantEventCallback, AssistantEventSelector } from "./types/events.js";
|
|
2
|
+
/**
|
|
3
|
+
* Subscribes to an assistant event for the lifetime of the component.
|
|
4
|
+
*
|
|
5
|
+
* The subscription is established on mount and re-established whenever the
|
|
6
|
+
* scope or event name changes. The `callback` is wrapped in an effect-event
|
|
7
|
+
* shim, so the latest closure is invoked on each emission — you do not
|
|
8
|
+
* need to memoize it.
|
|
9
|
+
*
|
|
10
|
+
* @param selector - Either a dotted event name like
|
|
11
|
+
* `"thread.modelContextUpdate"` or an object `{ scope, event }`. Use
|
|
12
|
+
* `scope: "*"` to subscribe at the root client and receive emissions
|
|
13
|
+
* from any descendant scope, regardless of which one is in React
|
|
14
|
+
* context.
|
|
15
|
+
* @param callback - Invoked with the event payload. The most recent
|
|
16
|
+
* reference is always called. Return values are ignored, async callbacks
|
|
17
|
+
* are not awaited, and the callback cannot be called during render.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* // React to transient model-context changes.
|
|
22
|
+
* useAuiEvent("thread.modelContextUpdate", ({ threadId }) => {
|
|
23
|
+
* analytics.track("model_context_update", { threadId });
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* // React to thread switches.
|
|
30
|
+
* useAuiEvent("threadListItem.switchedTo", () => {
|
|
31
|
+
* resetLocalState();
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* // Listen from the root client rather than the current React context.
|
|
38
|
+
* useAuiEvent({ scope: "*", event: "thread.modelContextUpdate" }, (payload) => {
|
|
39
|
+
* analytics.track("model_context_update", payload);
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
2
43
|
export declare const useAuiEvent: <TEvent extends AssistantEventName>(selector: AssistantEventSelector<TEvent>, callback: AssistantEventCallback<TEvent>) => void;
|
|
3
44
|
//# 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,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","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"}
|
package/dist/useAuiEvent.js
CHANGED
|
@@ -2,6 +2,47 @@ import { useEffect } from "react";
|
|
|
2
2
|
import { useEffectEvent } from "use-effect-event";
|
|
3
3
|
import { useAui } from "./useAui.js";
|
|
4
4
|
import { normalizeEventSelector } from "./types/events.js";
|
|
5
|
+
/**
|
|
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
|
+
*/
|
|
5
46
|
export const useAuiEvent = (selector, callback) => {
|
|
6
47
|
const aui = useAui();
|
|
7
48
|
const callbackRef = useEffectEvent(callback);
|
package/dist/useAuiEvent.js.map
CHANGED
|
@@ -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,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","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"}
|
package/dist/useAuiState.d.ts
CHANGED
|
@@ -1,17 +1,34 @@
|
|
|
1
1
|
import type { AssistantState } from "./types/client.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Subscribes to a slice of {@link AssistantState} and re-renders the
|
|
4
|
+
* component whenever that slice changes.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* The `selector` is called on every store update; its return value is
|
|
7
|
+
* compared by `Object.is`, and the component re-renders only when the
|
|
8
|
+
* selected slice changes. Returning the entire state object is not
|
|
9
|
+
* supported and throws at runtime — select a specific field instead, or
|
|
10
|
+
* compose multiple `useAuiState` calls. Returning a new object or array
|
|
11
|
+
* literal, including spreading `s.thread` into a new object, causes a
|
|
12
|
+
* re-render on every store update; either select primitives or return a
|
|
13
|
+
* memoized reference.
|
|
14
|
+
*
|
|
15
|
+
* @param selector - Pure function that derives a value from the current
|
|
16
|
+
* assistant state. Should be cheap and referentially stable for equal
|
|
17
|
+
* inputs (plain field reads, primitives, or memoized values).
|
|
18
|
+
* @returns The currently selected slice.
|
|
7
19
|
*
|
|
8
20
|
* @example
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
21
|
+
* ```tsx
|
|
22
|
+
* // Disable a button while a run is in flight.
|
|
23
|
+
* const isRunning = useAuiState((s) => s.thread.isRunning);
|
|
24
|
+
* ```
|
|
13
25
|
*
|
|
14
|
-
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* // Prefer multiple selectors over an inline object literal, which would
|
|
29
|
+
* // create a new reference on every render.
|
|
30
|
+
* const text = useAuiState((s) => s.composer.text);
|
|
31
|
+
* const canSend = useAuiState((s) => s.composer.canSend);
|
|
15
32
|
* ```
|
|
16
33
|
*/
|
|
17
34
|
export declare const useAuiState: <T>(selector: (state: AssistantState) => T) => T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuiState.d.ts","sourceRoot":"","sources":["../src/useAuiState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,0BAAuB;AAIrD
|
|
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"}
|