@assistant-ui/store 0.1.6 → 0.2.0
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 +1 -1
- package/dist/AuiIf.d.ts.map +1 -1
- package/dist/AuiIf.js.map +1 -1
- package/dist/index.d.ts +3 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -10
- package/dist/index.js.map +1 -1
- package/dist/scope-registry-forward.d.ts +6 -0
- package/dist/scope-registry-forward.d.ts.map +1 -0
- package/dist/scope-registry-forward.js +2 -0
- package/dist/scope-registry-forward.js.map +1 -0
- package/dist/scope-registry.d.ts +17 -0
- package/dist/scope-registry.d.ts.map +1 -0
- package/dist/scope-registry.js +2 -0
- package/dist/scope-registry.js.map +1 -0
- package/dist/useAui.d.ts +3 -5
- package/dist/useAui.d.ts.map +1 -1
- package/dist/useAui.js +6 -11
- package/dist/useAui.js.map +1 -1
- package/dist/useAuiEvent.d.ts +1 -1
- package/dist/useAuiEvent.d.ts.map +1 -1
- package/dist/useAuiEvent.js +1 -1
- package/dist/useAuiEvent.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/react-assistant-context.d.ts +1 -1
- package/dist/utils/react-assistant-context.d.ts.map +1 -1
- package/dist/utils/react-assistant-context.js +1 -2
- package/dist/utils/react-assistant-context.js.map +1 -1
- package/package.json +10 -3
- package/src/{AuiIf.tsx → AuiIf.ts} +1 -1
- package/src/__tests__/hooks.test.tsx +126 -0
- package/src/index.ts +25 -32
- package/src/scope-registry-forward.ts +6 -0
- package/src/scope-registry.ts +15 -0
- package/src/{useAui.tsx → useAui.ts} +24 -27
- package/src/useAuiEvent.ts +2 -2
- package/src/{useAuiState.tsx → useAuiState.ts} +3 -3
- package/src/utils/react-assistant-context.tsx +7 -3
- package/dist/Derived.d.ts +0 -34
- package/dist/Derived.d.ts.map +0 -1
- package/dist/Derived.js +0 -24
- package/dist/Derived.js.map +0 -1
- 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/dist/tapClientList.d.ts +0 -24
- package/dist/tapClientList.d.ts.map +0 -1
- package/dist/tapClientList.js +0 -68
- package/dist/tapClientList.js.map +0 -1
- package/dist/tapClientLookup.d.ts +0 -11
- package/dist/tapClientLookup.d.ts.map +0 -1
- package/dist/tapClientLookup.js +0 -42
- package/dist/tapClientLookup.js.map +0 -1
- package/dist/tapClientResource.d.ts +0 -28
- package/dist/tapClientResource.d.ts.map +0 -1
- package/dist/tapClientResource.js +0 -122
- package/dist/tapClientResource.js.map +0 -1
- package/dist/types/client.d.ts +0 -119
- package/dist/types/client.d.ts.map +0 -1
- package/dist/types/client.js +0 -2
- package/dist/types/client.js.map +0 -1
- package/dist/types/events.d.ts +0 -33
- package/dist/types/events.d.ts.map +0 -1
- package/dist/types/events.js +0 -8
- package/dist/types/events.js.map +0 -1
- package/dist/utils/BaseProxyHandler.d.ts +0 -23
- package/dist/utils/BaseProxyHandler.d.ts.map +0 -1
- package/dist/utils/BaseProxyHandler.js +0 -46
- package/dist/utils/BaseProxyHandler.js.map +0 -1
- package/dist/utils/NotificationManager.d.ts +0 -11
- package/dist/utils/NotificationManager.d.ts.map +0 -1
- package/dist/utils/NotificationManager.js +0 -84
- package/dist/utils/NotificationManager.js.map +0 -1
- package/dist/utils/proxied-assistant-state.d.ts +0 -8
- package/dist/utils/proxied-assistant-state.d.ts.map +0 -1
- package/dist/utils/proxied-assistant-state.js +0 -34
- package/dist/utils/proxied-assistant-state.js.map +0 -1
- package/dist/utils/splitClients.d.ts +0 -10
- package/dist/utils/splitClients.d.ts.map +0 -1
- package/dist/utils/splitClients.js +0 -83
- package/dist/utils/splitClients.js.map +0 -1
- package/dist/utils/tap-assistant-context.d.ts +0 -19
- package/dist/utils/tap-assistant-context.d.ts.map +0 -1
- package/dist/utils/tap-assistant-context.js +0 -23
- package/dist/utils/tap-assistant-context.js.map +0 -1
- package/dist/utils/tap-client-stack-context.d.ts +0 -23
- package/dist/utils/tap-client-stack-context.d.ts.map +0 -1
- package/dist/utils/tap-client-stack-context.js +0 -28
- package/dist/utils/tap-client-stack-context.js.map +0 -1
- package/dist/wrapperResource.d.ts +0 -3
- package/dist/wrapperResource.d.ts.map +0 -1
- package/dist/wrapperResource.js +0 -11
- package/dist/wrapperResource.js.map +0 -1
- package/src/Derived.ts +0 -46
- package/src/attachDefaultPeers.ts +0 -78
- package/src/tapClientList.ts +0 -118
- package/src/tapClientLookup.ts +0 -76
- package/src/tapClientResource.ts +0 -182
- package/src/types/client.ts +0 -186
- package/src/types/events.ts +0 -77
- package/src/utils/BaseProxyHandler.ts +0 -50
- package/src/utils/NotificationManager.ts +0 -114
- package/src/utils/proxied-assistant-state.tsx +0 -53
- package/src/utils/splitClients.ts +0 -130
- package/src/utils/tap-assistant-context.ts +0 -58
- package/src/utils/tap-client-stack-context.ts +0 -51
- package/src/wrapperResource.ts +0 -17
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { Derived } from "../Derived.js";
|
|
2
|
-
import { getDefaultPeers } from "../attachDefaultPeers.js";
|
|
3
|
-
import { tapMemo } from "@assistant-ui/tap";
|
|
4
|
-
/**
|
|
5
|
-
* Splits a clients object into root clients and derived clients.
|
|
6
|
-
*
|
|
7
|
-
* @param clients - The clients input object to split
|
|
8
|
-
* @returns An object with { rootClients, derivedClients }
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* const clients = {
|
|
13
|
-
* foo: RootClient({ ... }),
|
|
14
|
-
* bar: Derived({ ... }),
|
|
15
|
-
* };
|
|
16
|
-
*
|
|
17
|
-
* const { rootClients, derivedClients } = splitClients(clients);
|
|
18
|
-
* // rootClients = { foo: ... }
|
|
19
|
-
* // derivedClients = { bar: ... }
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
function splitClients(clients, baseClient) {
|
|
23
|
-
const rootClients = {};
|
|
24
|
-
const derivedClients = {};
|
|
25
|
-
for (const [key, clientElement] of Object.entries(clients)) {
|
|
26
|
-
if (clientElement.type === Derived) {
|
|
27
|
-
derivedClients[key] = clientElement;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
rootClients[key] = clientElement;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
// Recursively gather all default peers, flattening nested ones
|
|
34
|
-
const gatherDefaultPeers = (clientElement, visited = new Set()) => {
|
|
35
|
-
// Prevent infinite loops
|
|
36
|
-
if (visited.has(clientElement))
|
|
37
|
-
return [];
|
|
38
|
-
visited.add(clientElement);
|
|
39
|
-
const defaultPeers = getDefaultPeers(clientElement.type);
|
|
40
|
-
if (!defaultPeers)
|
|
41
|
-
return [];
|
|
42
|
-
const result = [];
|
|
43
|
-
for (const [key, peerElement] of Object.entries(defaultPeers)) {
|
|
44
|
-
result.push([key, peerElement]);
|
|
45
|
-
// If this peer is a root client with its own default peers, recursively gather them
|
|
46
|
-
if (peerElement.type !== (Derived)) {
|
|
47
|
-
const nestedPeers = gatherDefaultPeers(peerElement, visited);
|
|
48
|
-
result.push(...nestedPeers);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return result;
|
|
52
|
-
};
|
|
53
|
-
// Apply flattened default peers for each root client
|
|
54
|
-
for (const [_clientKey, clientElement] of Object.entries(rootClients)) {
|
|
55
|
-
const allPeers = gatherDefaultPeers(clientElement);
|
|
56
|
-
for (const [key, peerElement] of allPeers) {
|
|
57
|
-
// Skip if already exists (first wins)
|
|
58
|
-
if (key in rootClients ||
|
|
59
|
-
key in derivedClients ||
|
|
60
|
-
baseClient[key].source !== null)
|
|
61
|
-
continue;
|
|
62
|
-
if (peerElement.type === (Derived)) {
|
|
63
|
-
derivedClients[key] = peerElement;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
rootClients[key] = peerElement;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return { rootClients, derivedClients };
|
|
71
|
-
}
|
|
72
|
-
const tapShallowMemoObject = (object) => {
|
|
73
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: shallow memo
|
|
74
|
-
return tapMemo(() => object, [...Object.entries(object).flat()]);
|
|
75
|
-
};
|
|
76
|
-
export const tapSplitClients = (clients, baseClient) => {
|
|
77
|
-
const { rootClients, derivedClients } = splitClients(clients, baseClient);
|
|
78
|
-
return {
|
|
79
|
-
rootClients: tapShallowMemoObject(rootClients),
|
|
80
|
-
derivedClients: tapShallowMemoObject(derivedClients),
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
//# sourceMappingURL=splitClients.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"splitClients.js","sourceRoot":"","sources":["../../src/utils/splitClients.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { AssistantEventName, AssistantEventPayload } from "../types/events.js";
|
|
2
|
-
import type { AssistantClient } from "../types/client.js";
|
|
3
|
-
import { type ClientStack } from "./tap-client-stack-context.js";
|
|
4
|
-
type EmitFn = <TEvent extends Exclude<AssistantEventName, "*">>(event: TEvent, payload: AssistantEventPayload[TEvent], clientStack: ClientStack) => void;
|
|
5
|
-
export type AssistantTapContextValue = {
|
|
6
|
-
clientRef: {
|
|
7
|
-
parent: AssistantClient;
|
|
8
|
-
current: AssistantClient | null;
|
|
9
|
-
};
|
|
10
|
-
emit: EmitFn;
|
|
11
|
-
};
|
|
12
|
-
export declare const withAssistantTapContextProvider: <TResult>(value: AssistantTapContextValue, fn: () => TResult) => TResult;
|
|
13
|
-
export declare const tapAssistantClientRef: () => {
|
|
14
|
-
parent: AssistantClient;
|
|
15
|
-
current: AssistantClient | null;
|
|
16
|
-
};
|
|
17
|
-
export declare const tapAssistantEmit: () => <TEvent extends Exclude<AssistantEventName, "*">>(event: TEvent, payload: AssistantEventPayload[TEvent]) => void;
|
|
18
|
-
export {};
|
|
19
|
-
//# sourceMappingURL=tap-assistant-context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tap-assistant-context.d.ts","sourceRoot":"","sources":["../../src/utils/tap-assistant-context.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACtB,2BAAwB;AACzB,OAAO,KAAK,EAAE,eAAe,EAAE,2BAAwB;AACvD,OAAO,EAAkB,KAAK,WAAW,EAAE,sCAAmC;AAE9E,KAAK,MAAM,GAAG,CAAC,MAAM,SAAS,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,EAC5D,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,qBAAqB,CAAC,MAAM,CAAC,EACtC,WAAW,EAAE,WAAW,KACrB,IAAI,CAAC;AAEV,MAAM,MAAM,wBAAwB,GAAG;IACrC,SAAS,EAAE;QAAE,MAAM,EAAE,eAAe,CAAC;QAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAAA;KAAE,CAAC;IACxE,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAKF,eAAO,MAAM,+BAA+B,GAAI,OAAO,EACrD,OAAO,wBAAwB,EAC/B,IAAI,MAAM,OAAO,YAGlB,CAAC;AASF,eAAO,MAAM,qBAAqB;YArBX,eAAe;aAAW,eAAe,GAAG,IAAI;CAuBtE,CAAC;AAEF,eAAO,MAAM,gBAAgB,SAKxB,MAAM,SAAS,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,SACvC,MAAM,WACJ,qBAAqB,CAAC,MAAM,CAAC,SAK3C,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { createResourceContext, tap, withContextProvider, tapEffectEvent, } from "@assistant-ui/tap";
|
|
2
|
-
import { tapClientStack } from "./tap-client-stack-context.js";
|
|
3
|
-
const AssistantTapContext = createResourceContext(null);
|
|
4
|
-
export const withAssistantTapContextProvider = (value, fn) => {
|
|
5
|
-
return withContextProvider(AssistantTapContext, value, fn);
|
|
6
|
-
};
|
|
7
|
-
const tapAssistantTapContext = () => {
|
|
8
|
-
const ctx = tap(AssistantTapContext);
|
|
9
|
-
if (!ctx)
|
|
10
|
-
throw new Error("AssistantTapContext is not available");
|
|
11
|
-
return ctx;
|
|
12
|
-
};
|
|
13
|
-
export const tapAssistantClientRef = () => {
|
|
14
|
-
return tapAssistantTapContext().clientRef;
|
|
15
|
-
};
|
|
16
|
-
export const tapAssistantEmit = () => {
|
|
17
|
-
const { emit } = tapAssistantTapContext();
|
|
18
|
-
const clientStack = tapClientStack();
|
|
19
|
-
return tapEffectEvent((event, payload) => {
|
|
20
|
-
emit(event, payload, clientStack);
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=tap-assistant-context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tap-assistant-context.js","sourceRoot":"","sources":["../../src/utils/tap-assistant-context.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,GAAG,EACH,mBAAmB,EACnB,cAAc,GACf,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EAAE,cAAc,EAAoB,sCAAmC;AAa9E,MAAM,mBAAmB,GACvB,qBAAqB,CAAkC,IAAI,CAAC,CAAC;AAE/D,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAC7C,KAA+B,EAC/B,EAAiB,EACjB,EAAE;IACF,OAAO,mBAAmB,CAAC,mBAAmB,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;AAC7D,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,GAAG,EAAE;IAClC,MAAM,GAAG,GAAG,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACrC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAElE,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACxC,OAAO,sBAAsB,EAAE,CAAC,SAAS,CAAC;AAC5C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,MAAM,EAAE,IAAI,EAAE,GAAG,sBAAsB,EAAE,CAAC;IAC1C,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IAErC,OAAO,cAAc,CACnB,CACE,KAAa,EACb,OAAsC,EACtC,EAAE;QACF,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;IACpC,CAAC,CACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { ClientMethods } from "../types/client.js";
|
|
2
|
-
/**
|
|
3
|
-
* Symbol used to get the client index from a ClientProxy.
|
|
4
|
-
*/
|
|
5
|
-
export declare const SYMBOL_CLIENT_INDEX: unique symbol;
|
|
6
|
-
/**
|
|
7
|
-
* Get the index of a client (its position in the client stack when created).
|
|
8
|
-
*/
|
|
9
|
-
export declare const getClientIndex: (client: ClientMethods) => number;
|
|
10
|
-
/**
|
|
11
|
-
* The client stack - an array of clients representing the current hierarchy.
|
|
12
|
-
*/
|
|
13
|
-
export type ClientStack = readonly ClientMethods[];
|
|
14
|
-
/**
|
|
15
|
-
* Get the current client stack inside a tap resource.
|
|
16
|
-
*/
|
|
17
|
-
export declare const tapClientStack: () => ClientStack;
|
|
18
|
-
/**
|
|
19
|
-
* Execute a callback with a client pushed onto the stack.
|
|
20
|
-
* The stack is duplicated, not mutated.
|
|
21
|
-
*/
|
|
22
|
-
export declare const tapWithClientStack: <T>(client: ClientMethods, callback: () => T) => T;
|
|
23
|
-
//# sourceMappingURL=tap-client-stack-context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tap-client-stack-context.d.ts","sourceRoot":"","sources":["../../src/utils/tap-client-stack-context.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,2BAAwB;AAErD;;GAEG;AACH,eAAO,MAAM,mBAAmB,eAA2C,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,aAAa,KAAG,MAItD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,SAAS,aAAa,EAAE,CAAC;AAInD;;GAEG;AACH,eAAO,MAAM,cAAc,QAAO,WAEjC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAClC,QAAQ,aAAa,EACrB,UAAU,MAAM,CAAC,KAChB,CAOF,CAAC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { createResourceContext, tap, withContextProvider, tapMemo, } from "@assistant-ui/tap";
|
|
2
|
-
/**
|
|
3
|
-
* Symbol used to get the client index from a ClientProxy.
|
|
4
|
-
*/
|
|
5
|
-
export const SYMBOL_CLIENT_INDEX = Symbol("assistant-ui.store.clientIndex");
|
|
6
|
-
/**
|
|
7
|
-
* Get the index of a client (its position in the client stack when created).
|
|
8
|
-
*/
|
|
9
|
-
export const getClientIndex = (client) => {
|
|
10
|
-
return client[SYMBOL_CLIENT_INDEX];
|
|
11
|
-
};
|
|
12
|
-
const ClientStackContext = createResourceContext([]);
|
|
13
|
-
/**
|
|
14
|
-
* Get the current client stack inside a tap resource.
|
|
15
|
-
*/
|
|
16
|
-
export const tapClientStack = () => {
|
|
17
|
-
return tap(ClientStackContext);
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Execute a callback with a client pushed onto the stack.
|
|
21
|
-
* The stack is duplicated, not mutated.
|
|
22
|
-
*/
|
|
23
|
-
export const tapWithClientStack = (client, callback) => {
|
|
24
|
-
const currentStack = tapClientStack();
|
|
25
|
-
const newStack = tapMemo(() => [...currentStack, client], [currentStack, client]);
|
|
26
|
-
return withContextProvider(ClientStackContext, newStack, callback);
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=tap-client-stack-context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tap-client-stack-context.js","sourceRoot":"","sources":["../../src/utils/tap-client-stack-context.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,GAAG,EACH,mBAAmB,EACnB,OAAO,GACR,MAAM,mBAAmB,CAAC;AAG3B;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,gCAAgC,CAAC,CAAC;AAE5E;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAqB,EAAU,EAAE;IAC9D,OAAQ,MAAuD,CAC7D,mBAAmB,CACpB,CAAC;AACJ,CAAC,CAAC;AAOF,MAAM,kBAAkB,GAAG,qBAAqB,CAAc,EAAE,CAAC,CAAC;AAElE;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,GAAgB,EAAE;IAC9C,OAAO,GAAG,CAAC,kBAAkB,CAAC,CAAC;AACjC,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,MAAqB,EACrB,QAAiB,EACd,EAAE;IACL,MAAM,YAAY,GAAG,cAAc,EAAE,CAAC;IACtC,MAAM,QAAQ,GAAG,OAAO,CACtB,GAAG,EAAE,CAAC,CAAC,GAAG,YAAY,EAAE,MAAM,CAAC,EAC/B,CAAC,YAAY,EAAE,MAAM,CAAC,CACvB,CAAC;IACF,OAAO,mBAAmB,CAAC,kBAAkB,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACrE,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrapperResource.d.ts","sourceRoot":"","sources":["../src/wrapperResource.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,QAAQ,EAGT,MAAM,mBAAmB,CAAC;AAE3B,eAAO,MAAM,eAAe,GAAI,CAAC,EAAE,CAAC,EAClC,IAAI,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC,KACnC,QAAQ,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAOhC,CAAC"}
|
package/dist/wrapperResource.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { resource, withKey, } from "@assistant-ui/tap";
|
|
2
|
-
export const wrapperResource = (fn) => {
|
|
3
|
-
const res = resource(fn);
|
|
4
|
-
return (props) => {
|
|
5
|
-
const el = res(props);
|
|
6
|
-
if (props.key === undefined)
|
|
7
|
-
return el;
|
|
8
|
-
return withKey(props.key, el);
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=wrapperResource.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrapperResource.js","sourceRoot":"","sources":["../src/wrapperResource.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,QAAQ,EACR,OAAO,GACR,MAAM,mBAAmB,CAAC;AAE3B,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,EAAoC,EACH,EAAE;IACnC,MAAM,GAAG,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACzB,OAAO,CAAC,KAAyB,EAAE,EAAE;QACnC,MAAM,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;QACtB,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS;YAAE,OAAO,EAAE,CAAC;QACvC,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
package/src/Derived.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { resource, ResourceElement } from "@assistant-ui/tap";
|
|
2
|
-
import type {
|
|
3
|
-
AssistantClient,
|
|
4
|
-
ClientNames,
|
|
5
|
-
AssistantClientAccessor,
|
|
6
|
-
ClientMeta,
|
|
7
|
-
} from "./types/client";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Creates a derived client field that references a client from a parent scope.
|
|
11
|
-
* The get callback always calls the most recent version (useEffectEvent pattern).
|
|
12
|
-
*
|
|
13
|
-
* IMPORTANT: The `get` callback must return a client that was created via
|
|
14
|
-
* `tapClientResource` (or `tapClientLookup`/`tapClientList` which use it internally).
|
|
15
|
-
* This is required for event scoping to work correctly.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* const aui = useAui({
|
|
20
|
-
* message: Derived({
|
|
21
|
-
* source: "thread",
|
|
22
|
-
* query: { index: 0 },
|
|
23
|
-
* get: (aui) => aui.thread().message({ index: 0 }),
|
|
24
|
-
* }),
|
|
25
|
-
* });
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export const Derived = resource(
|
|
29
|
-
<K extends ClientNames>(_config: Derived.Props<K>): null => {
|
|
30
|
-
return null;
|
|
31
|
-
},
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
export type DerivedElement<K extends ClientNames> = ResourceElement<
|
|
35
|
-
null,
|
|
36
|
-
Derived.Props<K>
|
|
37
|
-
>;
|
|
38
|
-
|
|
39
|
-
export namespace Derived {
|
|
40
|
-
/**
|
|
41
|
-
* Props passed to a derived client resource element.
|
|
42
|
-
*/
|
|
43
|
-
export type Props<K extends ClientNames> = {
|
|
44
|
-
get: (client: AssistantClient) => ReturnType<AssistantClientAccessor<K>>;
|
|
45
|
-
} & (ClientMeta<K> | { getMeta: (client: AssistantClient) => ClientMeta<K> });
|
|
46
|
-
}
|
|
@@ -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
|
-
}
|
package/src/tapClientList.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { tapConst, tapState, withKey } from "@assistant-ui/tap";
|
|
2
|
-
import type { ContravariantResource } from "@assistant-ui/tap";
|
|
3
|
-
import { tapClientLookup } from "./tapClientLookup";
|
|
4
|
-
import type { ClientMethods, ClientOutputOf } from "./types/client";
|
|
5
|
-
|
|
6
|
-
type DataHandle<TData> = { data: TData | undefined; hasData: boolean };
|
|
7
|
-
|
|
8
|
-
const createProps = <TData>(
|
|
9
|
-
key: string,
|
|
10
|
-
data: DataHandle<TData>,
|
|
11
|
-
remove: () => void,
|
|
12
|
-
): tapClientList.ResourceProps<TData> => {
|
|
13
|
-
return {
|
|
14
|
-
key,
|
|
15
|
-
getInitialData: () => {
|
|
16
|
-
if (!data.hasData) {
|
|
17
|
-
throw new Error(
|
|
18
|
-
"getInitialData may only be called during initial render",
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
return data.data!;
|
|
22
|
-
},
|
|
23
|
-
remove,
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const tapClientList = <TData, TState, TMethods extends ClientMethods>(
|
|
28
|
-
props: tapClientList.Props<TData, TState, TMethods>,
|
|
29
|
-
): {
|
|
30
|
-
state: TState[];
|
|
31
|
-
get: (lookup: { index: number } | { key: string }) => TMethods;
|
|
32
|
-
add: (initialData: TData) => void;
|
|
33
|
-
} => {
|
|
34
|
-
const { initialValues, getKey, resource: Resource } = props;
|
|
35
|
-
|
|
36
|
-
type Props = tapClientList.ResourceProps<TData>;
|
|
37
|
-
|
|
38
|
-
const initialDataHandles: DataHandle<TData>[] = tapConst(() => [], []);
|
|
39
|
-
|
|
40
|
-
const [items, setItems] = tapState<Record<string, Props>>(() => {
|
|
41
|
-
const entries: [string, Props][] = [];
|
|
42
|
-
for (const data of initialValues) {
|
|
43
|
-
const key = getKey(data);
|
|
44
|
-
const handle = { data, hasData: true };
|
|
45
|
-
entries.push([
|
|
46
|
-
key,
|
|
47
|
-
createProps(key, handle, () => {
|
|
48
|
-
setItems((items) => {
|
|
49
|
-
const newItems = { ...items };
|
|
50
|
-
delete newItems[key];
|
|
51
|
-
return newItems;
|
|
52
|
-
});
|
|
53
|
-
}),
|
|
54
|
-
]);
|
|
55
|
-
initialDataHandles.push(handle);
|
|
56
|
-
}
|
|
57
|
-
return Object.fromEntries(entries);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const lookup = tapClientLookup<TState, TMethods>(
|
|
61
|
-
() =>
|
|
62
|
-
Object.values(items).map((props) => withKey(props.key, Resource(props))),
|
|
63
|
-
[items, Resource],
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
initialDataHandles.forEach((handle) => {
|
|
67
|
-
handle.data = undefined;
|
|
68
|
-
handle.hasData = false;
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const add = (data: TData) => {
|
|
72
|
-
const key = getKey(data);
|
|
73
|
-
setItems((items) => {
|
|
74
|
-
if (key in items) {
|
|
75
|
-
throw new Error(
|
|
76
|
-
`Tried to add item with a key ${key} that already exists`,
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const handle = { data, hasData: true };
|
|
81
|
-
initialDataHandles.push(handle);
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
...items,
|
|
85
|
-
[key]: createProps(key, handle, () => {
|
|
86
|
-
setItems((items) => {
|
|
87
|
-
const newItems = { ...items };
|
|
88
|
-
delete newItems[key];
|
|
89
|
-
return newItems;
|
|
90
|
-
});
|
|
91
|
-
}),
|
|
92
|
-
};
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
state: lookup.state,
|
|
98
|
-
get: lookup.get,
|
|
99
|
-
add,
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export namespace tapClientList {
|
|
104
|
-
export type ResourceProps<TData> = {
|
|
105
|
-
key: string;
|
|
106
|
-
getInitialData: () => TData;
|
|
107
|
-
remove: () => void;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export type Props<TData, TState, TMethods extends ClientMethods> = {
|
|
111
|
-
initialValues: TData[];
|
|
112
|
-
getKey: (data: TData) => string;
|
|
113
|
-
resource: ContravariantResource<
|
|
114
|
-
ClientOutputOf<TState, TMethods>,
|
|
115
|
-
ResourceProps<TData>
|
|
116
|
-
>;
|
|
117
|
-
};
|
|
118
|
-
}
|
package/src/tapClientLookup.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
tapInlineResource,
|
|
3
|
-
tapMemo,
|
|
4
|
-
tapResources,
|
|
5
|
-
type ResourceElement,
|
|
6
|
-
} from "@assistant-ui/tap";
|
|
7
|
-
import type { ClientMethods, ClientOutputOf } from "./types/client";
|
|
8
|
-
import { ClientResource } from "./tapClientResource";
|
|
9
|
-
import { wrapperResource } from "./wrapperResource";
|
|
10
|
-
|
|
11
|
-
const ClientResourceWithKey = wrapperResource(
|
|
12
|
-
<TState, TMethods extends ClientMethods>(
|
|
13
|
-
el: ResourceElement<ClientOutputOf<TState, TMethods>>,
|
|
14
|
-
) => {
|
|
15
|
-
if (el.key === undefined) {
|
|
16
|
-
throw new Error("tapClientResource: Element has no key");
|
|
17
|
-
}
|
|
18
|
-
return tapInlineResource(ClientResource(el)) as ClientOutputOf<
|
|
19
|
-
TState,
|
|
20
|
-
TMethods
|
|
21
|
-
> & { key: string | number };
|
|
22
|
-
},
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
export function tapClientLookup<TState, TMethods extends ClientMethods>(
|
|
26
|
-
getElements: () => readonly ResourceElement<
|
|
27
|
-
ClientOutputOf<TState, TMethods>
|
|
28
|
-
>[],
|
|
29
|
-
getElementsDeps: readonly unknown[],
|
|
30
|
-
): {
|
|
31
|
-
state: TState[];
|
|
32
|
-
get: (lookup: { index: number } | { key: string }) => TMethods;
|
|
33
|
-
} {
|
|
34
|
-
const resources = tapResources(
|
|
35
|
-
() => getElements().map((el) => ClientResourceWithKey(el)),
|
|
36
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: getElementsDeps is passed through from caller
|
|
37
|
-
getElementsDeps,
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
const keys = tapMemo(() => Object.keys(resources), [resources]);
|
|
41
|
-
|
|
42
|
-
// For arrays, track element key -> index mapping
|
|
43
|
-
const keyToIndex = tapMemo(() => {
|
|
44
|
-
return resources.reduce(
|
|
45
|
-
(acc, resource, index) => {
|
|
46
|
-
acc[resource.key] = index;
|
|
47
|
-
return acc;
|
|
48
|
-
},
|
|
49
|
-
{} as Record<string, number>,
|
|
50
|
-
);
|
|
51
|
-
}, [resources]);
|
|
52
|
-
|
|
53
|
-
const state = tapMemo(() => {
|
|
54
|
-
return resources.map((r) => r.state);
|
|
55
|
-
}, [resources]);
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
state,
|
|
59
|
-
get: (lookup: { index: number } | { key: string }) => {
|
|
60
|
-
if ("index" in lookup) {
|
|
61
|
-
if (lookup.index < 0 || lookup.index >= keys.length) {
|
|
62
|
-
throw new Error(
|
|
63
|
-
`tapClientLookup: Index ${lookup.index} out of bounds (length: ${keys.length})`,
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
return resources[lookup.index]!.methods;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const index = keyToIndex[lookup.key];
|
|
70
|
-
if (index === undefined) {
|
|
71
|
-
throw new Error(`tapClientLookup: Key "${lookup.key}" not found`);
|
|
72
|
-
}
|
|
73
|
-
return resources[index]!.methods;
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
}
|