@assistant-ui/react 0.11.49 → 0.11.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/client/AssistantClient.d.ts.map +1 -1
  2. package/dist/client/AssistantClient.js +1 -2
  3. package/dist/client/AssistantClient.js.map +1 -1
  4. package/dist/client/ModelContextClient.d.ts +1 -1
  5. package/dist/client/ThreadMessageClient.d.ts.map +1 -1
  6. package/dist/client/ThreadMessageClient.js +8 -9
  7. package/dist/client/ThreadMessageClient.js.map +1 -1
  8. package/dist/client/util-hooks/tapLookupResources.d.ts +2 -2
  9. package/dist/client/util-hooks/tapLookupResources.d.ts.map +1 -1
  10. package/dist/client/util-hooks/tapLookupResources.js +13 -4
  11. package/dist/client/util-hooks/tapLookupResources.js.map +1 -1
  12. package/dist/context/providers/MessageProvider.d.ts.map +1 -1
  13. package/dist/context/providers/MessageProvider.js +1 -2
  14. package/dist/context/providers/MessageProvider.js.map +1 -1
  15. package/dist/context/providers/TextMessagePartProvider.d.ts.map +1 -1
  16. package/dist/context/providers/TextMessagePartProvider.js +1 -2
  17. package/dist/context/providers/TextMessagePartProvider.js.map +1 -1
  18. package/dist/context/react/AssistantApiContext.d.ts +1 -2
  19. package/dist/context/react/AssistantApiContext.d.ts.map +1 -1
  20. package/dist/context/react/AssistantApiContext.js +1 -12
  21. package/dist/context/react/AssistantApiContext.js.map +1 -1
  22. package/dist/legacy-runtime/client/ComposerRuntimeClient.d.ts.map +1 -1
  23. package/dist/legacy-runtime/client/ComposerRuntimeClient.js +4 -6
  24. package/dist/legacy-runtime/client/ComposerRuntimeClient.js.map +1 -1
  25. package/dist/legacy-runtime/client/EventManagerRuntimeClient.d.ts +1 -1
  26. package/dist/legacy-runtime/client/MessageRuntimeClient.d.ts.map +1 -1
  27. package/dist/legacy-runtime/client/MessageRuntimeClient.js +8 -6
  28. package/dist/legacy-runtime/client/MessageRuntimeClient.js.map +1 -1
  29. package/dist/legacy-runtime/client/ThreadListRuntimeClient.d.ts.map +1 -1
  30. package/dist/legacy-runtime/client/ThreadListRuntimeClient.js +4 -3
  31. package/dist/legacy-runtime/client/ThreadListRuntimeClient.js.map +1 -1
  32. package/dist/legacy-runtime/client/ThreadRuntimeClient.d.ts.map +1 -1
  33. package/dist/legacy-runtime/client/ThreadRuntimeClient.js +4 -6
  34. package/dist/legacy-runtime/client/ThreadRuntimeClient.js.map +1 -1
  35. package/dist/primitives/composer/ComposerInput.d.ts.map +1 -1
  36. package/dist/primitives/composer/ComposerInput.js +4 -2
  37. package/dist/primitives/composer/ComposerInput.js.map +1 -1
  38. package/dist/tests/setup.js +7 -7
  39. package/dist/tests/setup.js.map +1 -1
  40. package/dist/utils/tap-store/derived-scopes.d.ts +3 -10
  41. package/dist/utils/tap-store/derived-scopes.d.ts.map +1 -1
  42. package/dist/utils/tap-store/derived-scopes.js +14 -20
  43. package/dist/utils/tap-store/derived-scopes.js.map +1 -1
  44. package/dist/utils/tap-store/index.d.ts +1 -1
  45. package/dist/utils/tap-store/index.d.ts.map +1 -1
  46. package/dist/utils/tap-store/index.js.map +1 -1
  47. package/dist/utils/tap-store/store.d.ts +1 -7
  48. package/dist/utils/tap-store/store.d.ts.map +1 -1
  49. package/dist/utils/tap-store/store.js +2 -2
  50. package/dist/utils/tap-store/store.js.map +1 -1
  51. package/dist/utils/tap-store/tap-api.d.ts.map +1 -1
  52. package/dist/utils/tap-store/tap-api.js +13 -7
  53. package/dist/utils/tap-store/tap-api.js.map +1 -1
  54. package/package.json +5 -5
  55. package/src/client/AssistantClient.ts +0 -1
  56. package/src/client/ThreadMessageClient.tsx +10 -9
  57. package/src/client/util-hooks/tapLookupResources.ts +26 -11
  58. package/src/context/providers/MessageProvider.tsx +0 -1
  59. package/src/context/providers/TextMessagePartProvider.tsx +0 -1
  60. package/src/context/react/AssistantApiContext.tsx +1 -18
  61. package/src/legacy-runtime/client/ComposerRuntimeClient.ts +4 -6
  62. package/src/legacy-runtime/client/MessageRuntimeClient.ts +10 -6
  63. package/src/legacy-runtime/client/ThreadListRuntimeClient.ts +4 -3
  64. package/src/legacy-runtime/client/ThreadRuntimeClient.ts +4 -6
  65. package/src/primitives/composer/ComposerInput.tsx +4 -2
  66. package/src/utils/tap-store/derived-scopes.ts +17 -28
  67. package/src/utils/tap-store/index.ts +1 -2
  68. package/src/utils/tap-store/store.ts +2 -7
  69. package/src/utils/tap-store/tap-api.ts +12 -7
@@ -40,7 +40,7 @@ type AssistantApiFieldNames = {
40
40
  /**
41
41
  * Configuration for a derived scope field - infers types from the actual values provided
42
42
  */
43
- export type DerivedScopeConfig<TSource extends string | null, TQuery, TApi> = {
43
+ export type DerivedConfig<TSource extends string | null, TQuery, TApi> = {
44
44
  source: TSource;
45
45
  query: TQuery;
46
46
  get: () => TApi;
@@ -59,18 +59,12 @@ export type OnCallbackFn = <TEvent extends AssistantEvent>(
59
59
  */
60
60
  export type SubscribeCallbackFn = (listener: () => void) => Unsubscribe;
61
61
 
62
- /**
63
- * Type for the special `flushSync` callback function
64
- */
65
- export type FlushSyncCallbackFn = () => void;
66
-
67
62
  /**
68
63
  * Type for special non-field functions in AssistantApi
69
64
  */
70
65
  export type SpecialCallbacks = {
71
66
  on?: OnCallbackFn;
72
67
  subscribe?: SubscribeCallbackFn;
73
- flushSync?: FlushSyncCallbackFn;
74
68
  };
75
69
 
76
70
  /**
@@ -98,7 +92,7 @@ export type DerivedScopesInput = {
98
92
  */
99
93
  export const DerivedScope = resource(
100
94
  <TSource extends string | null, TQuery, TApi>(
101
- config: DerivedScopeConfig<TSource, TQuery, TApi>,
95
+ config: DerivedConfig<TSource, TQuery, TApi>,
102
96
  ): AssistantApiField<
103
97
  TApi,
104
98
  {
@@ -144,32 +138,28 @@ const ScopeFieldWithNameResource = resource(
144
138
  */
145
139
  export const DerivedScopes = resource(
146
140
  (scopes: DerivedScopesInput): Partial<AssistantApi> => {
147
- const { on, subscribe, flushSync, ...scopeFields } = scopes;
148
- const callbacksRef = tapRef({ on, subscribe, flushSync });
141
+ const { on, subscribe, ...scopeFields } = scopes;
142
+ const callbacksRef = tapRef({ on, subscribe });
149
143
  tapEffect(() => {
150
- callbacksRef.current = { on, subscribe, flushSync };
144
+ callbacksRef.current = { on, subscribe };
151
145
  });
152
146
 
153
147
  const results = tapResources(
154
- Object.entries(scopeFields).map(([fieldName, scopeElement]) =>
155
- ScopeFieldWithNameResource(
156
- {
157
- fieldName,
158
- scopeElement: scopeElement as ReturnType<typeof DerivedScope>,
159
- },
160
- { key: fieldName },
161
- ),
162
- ),
148
+ scopeFields as Record<string, ReturnType<typeof DerivedScope>>,
149
+ (scopeElement, fieldName) =>
150
+ ScopeFieldWithNameResource({
151
+ fieldName,
152
+ scopeElement,
153
+ }),
154
+ [],
163
155
  );
164
156
 
165
157
  return tapMemo(() => {
166
- const result = Object.fromEntries(results) as Partial<AssistantApi>;
158
+ const result = Object.fromEntries(
159
+ Object.values(results),
160
+ ) as Partial<AssistantApi>;
167
161
 
168
- const {
169
- on: onCb,
170
- subscribe: subCb,
171
- flushSync: flushCb,
172
- } = callbacksRef.current;
162
+ const { on: onCb, subscribe: subCb } = callbacksRef.current;
173
163
 
174
164
  if (onCb) {
175
165
  result.on = <TEvent extends AssistantEvent>(
@@ -178,9 +168,8 @@ export const DerivedScopes = resource(
178
168
  ) => onCb(selector, callback);
179
169
  }
180
170
  if (subCb) result.subscribe = (listener) => subCb(listener);
181
- if (flushCb) result.flushSync = () => flushCb();
182
171
 
183
172
  return result;
184
- }, [...results]);
173
+ }, [results]);
185
174
  },
186
175
  );
@@ -2,10 +2,9 @@ export { type Store, asStore } from "./store";
2
2
  export { tapApi, type ApiObject } from "./tap-api";
3
3
  export {
4
4
  DerivedScope,
5
- type DerivedScopeConfig,
5
+ type DerivedConfig,
6
6
  type OnCallbackFn,
7
7
  type SubscribeCallbackFn,
8
- type FlushSyncCallbackFn,
9
8
  type SpecialCallbacks,
10
9
  type DerivedScopesInput,
11
10
  } from "./derived-scopes";
@@ -17,22 +17,17 @@ export interface Store<TState> {
17
17
  * Subscribe to the store.
18
18
  */
19
19
  subscribe(listener: () => void): Unsubscribe;
20
-
21
- /**
22
- * Synchronously flush all the updates to the store.
23
- */
24
- flushSync(): void;
25
20
  }
26
21
 
27
22
  export const asStore = resource(
28
23
  <TState, TProps>(element: ResourceElement<TState, TProps>): Store<TState> => {
29
24
  const resource = tapMemo(
30
- () => createResource(element, true),
25
+ () => createResource(element, { mount: false }),
31
26
  [element.type],
32
27
  );
33
28
 
34
29
  tapEffect(() => {
35
- resource.updateInput(element.props);
30
+ resource.render(element);
36
31
  });
37
32
 
38
33
  return resource;
@@ -5,33 +5,39 @@ export interface ApiObject {
5
5
  }
6
6
 
7
7
  class ReadonlyApiHandler<TApi extends ApiObject> implements ProxyHandler<TApi> {
8
- constructor(private readonly getApi: () => TApi) {}
8
+ constructor(private readonly ref: tapRef.RefObject<TApi>) {}
9
9
 
10
10
  get(_: unknown, prop: string | symbol) {
11
- return this.getApi()[prop as keyof TApi];
11
+ return this.ref.current[prop as keyof TApi];
12
12
  }
13
13
 
14
14
  ownKeys(): ArrayLike<string | symbol> {
15
- return Object.keys(this.getApi() as object);
15
+ return Object.keys(this.ref.current as object);
16
16
  }
17
17
 
18
18
  has(_: unknown, prop: string | symbol) {
19
- return prop in (this.getApi() as object);
19
+ return prop in (this.ref.current as object);
20
20
  }
21
21
 
22
22
  getOwnPropertyDescriptor(_: unknown, prop: string | symbol) {
23
- return Object.getOwnPropertyDescriptor(this.getApi(), prop);
23
+ return Object.getOwnPropertyDescriptor(this.ref.current, prop);
24
24
  }
25
25
 
26
26
  set() {
27
27
  return false;
28
28
  }
29
+ setPrototypeOf() {
30
+ return false;
31
+ }
29
32
  defineProperty() {
30
33
  return false;
31
34
  }
32
35
  deleteProperty() {
33
36
  return false;
34
37
  }
38
+ preventExtensions(): boolean {
39
+ return false;
40
+ }
35
41
  }
36
42
 
37
43
  export const tapApi = <TApi extends ApiObject & { getState: () => any }>(
@@ -46,8 +52,7 @@ export const tapApi = <TApi extends ApiObject & { getState: () => any }>(
46
52
  });
47
53
 
48
54
  const apiProxy = tapMemo(
49
- () =>
50
- new Proxy<TApi>({} as TApi, new ReadonlyApiHandler(() => ref.current)),
55
+ () => new Proxy<TApi>({} as TApi, new ReadonlyApiHandler(ref)),
51
56
  [],
52
57
  );
53
58