@assistant-ui/store 0.1.6 → 0.2.1
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 +9 -10
- package/dist/AuiIf.d.ts.map +1 -1
- package/dist/AuiIf.js.map +1 -1
- package/dist/attachTransformScopes.d.ts +11 -0
- package/dist/attachTransformScopes.d.ts.map +1 -0
- package/dist/attachTransformScopes.js +12 -0
- package/dist/attachTransformScopes.js.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/tapClientList.d.ts +9 -5
- package/dist/tapClientList.d.ts.map +1 -1
- package/dist/tapClientList.js.map +1 -1
- package/dist/tapClientLookup.d.ts +7 -3
- package/dist/tapClientLookup.d.ts.map +1 -1
- package/dist/tapClientLookup.js +2 -2
- package/dist/tapClientLookup.js.map +1 -1
- package/dist/tapClientResource.d.ts +9 -24
- package/dist/tapClientResource.d.ts.map +1 -1
- package/dist/tapClientResource.js +11 -19
- package/dist/tapClientResource.js.map +1 -1
- package/dist/types/client.d.ts +23 -27
- package/dist/types/client.d.ts.map +1 -1
- package/dist/useAui.d.ts.map +1 -1
- package/dist/useAui.js +4 -4
- package/dist/useAui.js.map +1 -1
- package/dist/useAuiState.d.ts +1 -1
- package/dist/useAuiState.d.ts.map +1 -1
- package/dist/useAuiState.js +1 -1
- package/dist/useAuiState.js.map +1 -1
- package/dist/utils/proxied-assistant-state.d.ts.map +1 -1
- package/dist/utils/proxied-assistant-state.js.map +1 -1
- package/dist/utils/splitClients.d.ts.map +1 -1
- package/dist/utils/splitClients.js +25 -55
- package/dist/utils/splitClients.js.map +1 -1
- package/package.json +11 -4
- package/src/__tests__/hooks.test.tsx +126 -0
- package/src/attachTransformScopes.ts +38 -0
- package/src/index.ts +18 -9
- package/src/tapClientList.ts +13 -10
- package/src/tapClientLookup.ts +17 -14
- package/src/tapClientResource.ts +36 -31
- package/src/types/client.ts +41 -47
- package/src/{useAui.tsx → useAui.ts} +5 -6
- package/src/{useAuiState.tsx → useAuiState.ts} +2 -2
- package/src/utils/splitClients.ts +32 -82
- package/dist/attachDefaultPeers.d.ts +0 -56
- package/dist/attachDefaultPeers.d.ts.map +0 -1
- package/dist/attachDefaultPeers.js +0 -51
- package/dist/attachDefaultPeers.js.map +0 -1
- package/src/attachDefaultPeers.ts +0 -78
- /package/src/{AuiIf.tsx → AuiIf.ts} +0 -0
- /package/src/utils/{proxied-assistant-state.tsx → proxied-assistant-state.ts} +0 -0
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { ResourceElement } from "@assistant-ui/tap";
|
|
2
|
-
import type { ClientElement, ClientNames } from "./types/client";
|
|
3
|
-
import type { DerivedElement } from "./Derived";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Symbol used to store default peer clients on a resource.
|
|
7
|
-
*/
|
|
8
|
-
const DEFAULT_PEERS = Symbol("assistant-ui.default-peers");
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Type for resources that have default peers attached.
|
|
12
|
-
*/
|
|
13
|
-
export type ResourceWithDefaultPeers = {
|
|
14
|
-
[DEFAULT_PEERS]?: DefaultPeers;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Default peers configuration - can be either root clients or derived clients.
|
|
19
|
-
*/
|
|
20
|
-
export type DefaultPeers = {
|
|
21
|
-
[K in ClientNames]?: ClientElement<K> | DerivedElement<K>;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Attaches default peer clients to a resource.
|
|
26
|
-
*
|
|
27
|
-
* Default peers are only applied if the scope doesn't exist:
|
|
28
|
-
* - Not defined in parent context
|
|
29
|
-
* - Not provided by user
|
|
30
|
-
* - Not already defined by a previous resource's default peers
|
|
31
|
-
*
|
|
32
|
-
* First definition wins - no overriding is permitted.
|
|
33
|
-
*
|
|
34
|
-
* @param resource - The resource to attach default peers to
|
|
35
|
-
* @param peers - The default peer clients to attach
|
|
36
|
-
* @throws Error if a peer key already exists in the resource's default peers
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```typescript
|
|
40
|
-
* const ThreadListClient = resource(({ ... }) => { ... });
|
|
41
|
-
*
|
|
42
|
-
* attachDefaultPeers(ThreadListClient, {
|
|
43
|
-
* // Derived default peers
|
|
44
|
-
* thread: Derived({ source: "threads", query: { type: "main" }, get: ... }),
|
|
45
|
-
* threadListItem: Derived({ ... }),
|
|
46
|
-
* composer: Derived({ getMeta: ..., get: ... }),
|
|
47
|
-
*
|
|
48
|
-
* // Root default peers
|
|
49
|
-
* tools: Tools({}),
|
|
50
|
-
* modelContext: ModelContext({}),
|
|
51
|
-
* });
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
export function attachDefaultPeers<
|
|
55
|
-
T extends (...args: any[]) => ResourceElement<any>,
|
|
56
|
-
>(resource: T, peers: DefaultPeers): void {
|
|
57
|
-
const resourceWithPeers = resource as T & ResourceWithDefaultPeers;
|
|
58
|
-
const existing = resourceWithPeers[DEFAULT_PEERS] ?? {};
|
|
59
|
-
|
|
60
|
-
for (const key of Object.keys(peers)) {
|
|
61
|
-
if (key in existing) {
|
|
62
|
-
throw new Error(
|
|
63
|
-
`Default peer "${key}" is already attached to this resource`,
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
resourceWithPeers[DEFAULT_PEERS] = { ...existing, ...peers };
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Gets the default peers attached to a resource, if any.
|
|
73
|
-
*/
|
|
74
|
-
export function getDefaultPeers<
|
|
75
|
-
T extends (...args: any[]) => ResourceElement<any>,
|
|
76
|
-
>(resource: T): DefaultPeers | undefined {
|
|
77
|
-
return (resource as T & ResourceWithDefaultPeers)[DEFAULT_PEERS];
|
|
78
|
-
}
|
|
File without changes
|
|
File without changes
|