@convex-dev/agent 0.1.8-alpha.0 → 0.1.8-alpha.2

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 (82) hide show
  1. package/README.md +2 -0
  2. package/dist/commonjs/client/index.d.ts +65 -51
  3. package/dist/commonjs/client/index.d.ts.map +1 -1
  4. package/dist/commonjs/client/index.js +70 -4
  5. package/dist/commonjs/client/index.js.map +1 -1
  6. package/dist/commonjs/component/_generated/api.d.ts +235 -0
  7. package/dist/commonjs/component/messages.d.ts +361 -155
  8. package/dist/commonjs/component/messages.d.ts.map +1 -1
  9. package/dist/commonjs/component/messages.js +25 -0
  10. package/dist/commonjs/component/messages.js.map +1 -1
  11. package/dist/commonjs/component/schema.d.ts +670 -670
  12. package/dist/commonjs/component/streams.d.ts +65 -18
  13. package/dist/commonjs/component/streams.d.ts.map +1 -1
  14. package/dist/commonjs/component/streams.js +120 -2
  15. package/dist/commonjs/component/streams.js.map +1 -1
  16. package/dist/commonjs/component/threads.d.ts +6 -6
  17. package/dist/commonjs/component/threads.d.ts.map +1 -1
  18. package/dist/commonjs/component/threads.js +9 -0
  19. package/dist/commonjs/component/threads.js.map +1 -1
  20. package/dist/commonjs/component/users.d.ts.map +1 -1
  21. package/dist/commonjs/component/users.js +1 -0
  22. package/dist/commonjs/component/users.js.map +1 -1
  23. package/dist/commonjs/component/vector/index.d.ts +12 -12
  24. package/dist/commonjs/component/vector/index.d.ts.map +1 -1
  25. package/dist/commonjs/component/vector/index.js +4 -0
  26. package/dist/commonjs/component/vector/index.js.map +1 -1
  27. package/dist/commonjs/component/vector/tables.d.ts +6 -6
  28. package/dist/commonjs/react/index.d.ts.map +1 -1
  29. package/dist/commonjs/react/index.js +1 -1
  30. package/dist/commonjs/react/index.js.map +1 -1
  31. package/dist/commonjs/validators.d.ts +161 -161
  32. package/dist/commonjs.tsbuildinfo +1 -1
  33. package/dist/esm/client/index.d.ts +31 -17
  34. package/dist/esm/client/index.d.ts.map +1 -1
  35. package/dist/esm/client/index.js +70 -4
  36. package/dist/esm/client/index.js.map +1 -1
  37. package/dist/esm/component/_generated/api.d.ts +235 -0
  38. package/dist/esm/component/messages.d.ts +233 -27
  39. package/dist/esm/component/messages.d.ts.map +1 -1
  40. package/dist/esm/component/messages.js +25 -0
  41. package/dist/esm/component/messages.js.map +1 -1
  42. package/dist/esm/component/schema.d.ts +48 -48
  43. package/dist/esm/component/streams.d.ts +47 -0
  44. package/dist/esm/component/streams.d.ts.map +1 -1
  45. package/dist/esm/component/streams.js +120 -2
  46. package/dist/esm/component/streams.js.map +1 -1
  47. package/dist/esm/component/threads.d.ts +8 -8
  48. package/dist/esm/component/threads.d.ts.map +1 -1
  49. package/dist/esm/component/threads.js +9 -0
  50. package/dist/esm/component/threads.js.map +1 -1
  51. package/dist/esm/component/users.d.ts.map +1 -1
  52. package/dist/esm/component/users.js +1 -0
  53. package/dist/esm/component/users.js.map +1 -1
  54. package/dist/esm/component/vector/index.d.ts.map +1 -1
  55. package/dist/esm/component/vector/index.js +4 -0
  56. package/dist/esm/component/vector/index.js.map +1 -1
  57. package/dist/esm/react/index.d.ts.map +1 -1
  58. package/dist/esm/react/index.js +1 -1
  59. package/dist/esm/react/index.js.map +1 -1
  60. package/dist/esm/validators.d.ts +19 -19
  61. package/dist/esm.tsbuildinfo +1 -1
  62. package/package.json +4 -5
  63. package/src/client/index.ts +94 -4
  64. package/src/client/setup.test.ts +2 -2
  65. package/src/component/_generated/api.d.ts +235 -0
  66. package/src/component/messages.test.ts +140 -0
  67. package/src/component/messages.ts +30 -0
  68. package/src/component/streams.ts +148 -2
  69. package/src/component/threads.ts +8 -0
  70. package/src/component/users.ts +1 -0
  71. package/src/component/vector/index.ts +4 -0
  72. package/src/react/index.ts +1 -2
  73. package/dist/commonjs/react/usePaginatedQuery.d.ts +0 -241
  74. package/dist/commonjs/react/usePaginatedQuery.d.ts.map +0 -1
  75. package/dist/commonjs/react/usePaginatedQuery.js +0 -627
  76. package/dist/commonjs/react/usePaginatedQuery.js.map +0 -1
  77. package/dist/esm/react/usePaginatedQuery.d.ts +0 -241
  78. package/dist/esm/react/usePaginatedQuery.d.ts.map +0 -1
  79. package/dist/esm/react/usePaginatedQuery.js +0 -627
  80. package/dist/esm/react/usePaginatedQuery.js.map +0 -1
  81. package/react/package.json +0 -5
  82. package/src/react/usePaginatedQuery.ts +0 -901
@@ -1,241 +0,0 @@
1
- import type { OptimisticLocalStore } from "convex/browser";
2
- import type { FunctionReturnType, PaginationOptions, PaginationResult } from "convex/server";
3
- import { type Value } from "convex/values";
4
- import { type FunctionArgs, type FunctionReference } from "convex/server";
5
- import type { BetterOmit, Expand } from "convex/server";
6
- /**
7
- * A {@link server.FunctionReference} that is usable with {@link usePaginatedQuery}.
8
- *
9
- * This function reference must:
10
- * - Refer to a public query
11
- * - Have an argument named "paginationOpts" of type {@link server.PaginationOptions}
12
- * - Have a return type of {@link server.PaginationResult}.
13
- *
14
- * @public
15
- */
16
- export type PaginatedQueryReference = FunctionReference<"query", "public", {
17
- paginationOpts: PaginationOptions;
18
- }, PaginationResult<any>>;
19
- /**
20
- * This is a clone of the `usePaginatedQuery` hook from `convex-helpers`.
21
- * The difference is that we lazily pin the end cursor on loading a new page.
22
- * This will be standard behavior in a future version of `convex/react`, but
23
- * for now it allows the agent to have correct behavior when loading a new page
24
- * where new items are still coming in.
25
- */
26
- export declare function usePaginatedQuery<Query extends PaginatedQueryReference>(query: Query, args: PaginatedQueryArgs<Query> | "skip", options: {
27
- initialNumItems: number;
28
- }): UsePaginatedQueryReturnType<Query>;
29
- /**
30
- * Reset pagination id for tests only, so tests know what it is.
31
- */
32
- export declare function resetPaginationId(): void;
33
- /**
34
- * The result of calling the {@link usePaginatedQuery} hook.
35
- *
36
- * This includes:
37
- * - `results` - An array of the currently loaded results.
38
- * - `isLoading` - Whether the hook is currently loading results.
39
- * - `status` - The status of the pagination. The possible statuses are:
40
- * - "LoadingFirstPage": The hook is loading the first page of results.
41
- * - "CanLoadMore": This query may have more items to fetch. Call `loadMore` to
42
- * fetch another page.
43
- * - "LoadingMore": We're currently loading another page of results.
44
- * - "Exhausted": We've paginated to the end of the list.
45
- * - `loadMore(n)` A callback to fetch more results. This will only fetch more
46
- * results if the status is "CanLoadMore".
47
- *
48
- * @public
49
- */
50
- export type UsePaginatedQueryResult<Item> = {
51
- results: Item[];
52
- loadMore: (numItems: number) => void;
53
- } & ({
54
- status: "LoadingFirstPage";
55
- isLoading: true;
56
- } | {
57
- status: "CanLoadMore";
58
- isLoading: false;
59
- } | {
60
- status: "LoadingMore";
61
- isLoading: true;
62
- } | {
63
- status: "Exhausted";
64
- isLoading: false;
65
- });
66
- /**
67
- * The possible pagination statuses in {@link UsePaginatedQueryResult}.
68
- *
69
- * This is a union of string literal types.
70
- * @public
71
- */
72
- export type PaginationStatus = UsePaginatedQueryResult<any>["status"];
73
- /**
74
- * Given a {@link PaginatedQueryReference}, get the type of the arguments
75
- * object for the query, excluding the `paginationOpts` argument.
76
- *
77
- * @public
78
- */
79
- export type PaginatedQueryArgs<Query extends PaginatedQueryReference> = Expand<BetterOmit<FunctionArgs<Query>, "paginationOpts">>;
80
- /**
81
- * Given a {@link PaginatedQueryReference}, get the type of the item being
82
- * paginated over.
83
- * @public
84
- */
85
- export type PaginatedQueryItem<Query extends PaginatedQueryReference> = FunctionReturnType<Query>["page"][number];
86
- /**
87
- * The return type of {@link usePaginatedQuery}.
88
- *
89
- * @public
90
- */
91
- export type UsePaginatedQueryReturnType<Query extends PaginatedQueryReference> = UsePaginatedQueryResult<PaginatedQueryItem<Query>>;
92
- /**
93
- * Optimistically update the values in a paginated list.
94
- *
95
- * This optimistic update is designed to be used to update data loaded with
96
- * {@link usePaginatedQuery}. It updates the list by applying
97
- * `updateValue` to each element of the list across all of the loaded pages.
98
- *
99
- * This will only apply to queries with a matching names and arguments.
100
- *
101
- * Example usage:
102
- * ```ts
103
- * const myMutation = useMutation(api.myModule.myMutation)
104
- * .withOptimisticUpdate((localStore, mutationArg) => {
105
- *
106
- * // Optimistically update the document with ID `mutationArg`
107
- * // to have an additional property.
108
- *
109
- * optimisticallyUpdateValueInPaginatedQuery(
110
- * localStore,
111
- * api.myModule.paginatedQuery
112
- * {},
113
- * currentValue => {
114
- * if (mutationArg === currentValue._id) {
115
- * return {
116
- * ...currentValue,
117
- * "newProperty": "newValue",
118
- * };
119
- * }
120
- * return currentValue;
121
- * }
122
- * );
123
- *
124
- * });
125
- * ```
126
- *
127
- * @param localStore - An {@link OptimisticLocalStore} to update.
128
- * @param query - A {@link FunctionReference} for the paginated query to update.
129
- * @param args - The arguments object to the query function, excluding the
130
- * `paginationOpts` property.
131
- * @param updateValue - A function to produce the new values.
132
- *
133
- * @public
134
- */
135
- export declare function optimisticallyUpdateValueInPaginatedQuery<Query extends PaginatedQueryReference>(localStore: OptimisticLocalStore, query: Query, args: PaginatedQueryArgs<Query>, updateValue: (currentValue: PaginatedQueryItem<Query>) => PaginatedQueryItem<Query>): void;
136
- /**
137
- * Updates a paginated query to insert an element at the top of the list.
138
- *
139
- * This is regardless of the sort order, so if the list is in descending order,
140
- * the inserted element will be treated as the "biggest" element, but if it's
141
- * ascending, it'll be treated as the "smallest".
142
- *
143
- * Example:
144
- * ```ts
145
- * const createTask = useMutation(api.tasks.create)
146
- * .withOptimisticUpdate((localStore, mutationArgs) => {
147
- * insertAtTop({
148
- * paginatedQuery: api.tasks.list,
149
- * argsToMatch: { listId: mutationArgs.listId },
150
- * localQueryStore: localStore,
151
- * item: { _id: crypto.randomUUID() as Id<"tasks">, title: mutationArgs.title, completed: false },
152
- * });
153
- * });
154
- * ```
155
- *
156
- * @param options.paginatedQuery - A function reference to the paginated query.
157
- * @param options.argsToMatch - Optional arguments that must be in each relevant paginated query.
158
- * This is useful if you use the same query function with different arguments to load
159
- * different lists.
160
- * @param options.localQueryStore
161
- * @param options.item The item to insert.
162
- * @returns
163
- */
164
- export declare function insertAtTop<Query extends PaginatedQueryReference>(options: {
165
- paginatedQuery: Query;
166
- argsToMatch?: Partial<PaginatedQueryArgs<Query>>;
167
- localQueryStore: OptimisticLocalStore;
168
- item: PaginatedQueryItem<Query>;
169
- }): void;
170
- /**
171
- * Updates a paginated query to insert an element at the bottom of the list.
172
- *
173
- * This is regardless of the sort order, so if the list is in descending order,
174
- * the inserted element will be treated as the "smallest" element, but if it's
175
- * ascending, it'll be treated as the "biggest".
176
- *
177
- * This only has an effect if the last page is loaded, since otherwise it would result
178
- * in the element being inserted at the end of whatever is loaded (which is the middle of the list)
179
- * and then popping out once the optimistic update is over.
180
- *
181
- * @param options.paginatedQuery - A function reference to the paginated query.
182
- * @param options.argsToMatch - Optional arguments that must be in each relevant paginated query.
183
- * This is useful if you use the same query function with different arguments to load
184
- * different lists.
185
- * @param options.localQueryStore
186
- * @param options.element The element to insert.
187
- * @returns
188
- */
189
- export declare function insertAtBottomIfLoaded<Query extends PaginatedQueryReference>(options: {
190
- paginatedQuery: Query;
191
- argsToMatch?: Partial<PaginatedQueryArgs<Query>>;
192
- localQueryStore: OptimisticLocalStore;
193
- item: PaginatedQueryItem<Query>;
194
- }): void;
195
- /**
196
- * This is a helper function for inserting an item at a specific position in a paginated query.
197
- *
198
- * You must provide the sortOrder and a function for deriving the sort key (an array of values) from an item in the list.
199
- *
200
- * This will only work if the server query uses the same sort order and sort key as the optimistic update.
201
- *
202
- * Example:
203
- * ```ts
204
- * const createTask = useMutation(api.tasks.create)
205
- * .withOptimisticUpdate((localStore, mutationArgs) => {
206
- * insertAtPosition({
207
- * paginatedQuery: api.tasks.listByPriority,
208
- * argsToMatch: { listId: mutationArgs.listId },
209
- * sortOrder: "asc",
210
- * sortKeyFromItem: (item) => [item.priority, item._creationTime],
211
- * localQueryStore: localStore,
212
- * item: {
213
- * _id: crypto.randomUUID() as Id<"tasks">,
214
- * _creationTime: Date.now(),
215
- * title: mutationArgs.title,
216
- * completed: false,
217
- * priority: mutationArgs.priority,
218
- * },
219
- * });
220
- * });
221
- * ```
222
- * @param options.paginatedQuery - A function reference to the paginated query.
223
- * @param options.argsToMatch - Optional arguments that must be in each relevant paginated query.
224
- * This is useful if you use the same query function with different arguments to load
225
- * different lists.
226
- * @param options.sortOrder - The sort order of the paginated query ("asc" or "desc").
227
- * @param options.sortKeyFromItem - A function for deriving the sort key (an array of values) from an element in the list.
228
- * Including a tie-breaker field like `_creationTime` is recommended.
229
- * @param options.localQueryStore
230
- * @param options.item - The item to insert.
231
- * @returns
232
- */
233
- export declare function insertAtPosition<Query extends PaginatedQueryReference>(options: {
234
- paginatedQuery: Query;
235
- argsToMatch?: Partial<PaginatedQueryArgs<Query>>;
236
- sortOrder: "asc" | "desc";
237
- sortKeyFromItem: (element: PaginatedQueryItem<Query>) => Value | Value[];
238
- localQueryStore: OptimisticLocalStore;
239
- item: PaginatedQueryItem<Query>;
240
- }): void;
241
- //# sourceMappingURL=usePaginatedQuery.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"usePaginatedQuery.d.ts","sourceRoot":"","sources":["../../../src/react/usePaginatedQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EAEjB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAIL,KAAK,KAAK,EACX,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,iBAAiB,EAEvB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAMxD;;;;;;;;;GASG;AACH,MAAM,MAAM,uBAAuB,GAAG,iBAAiB,CACrD,OAAO,EACP,QAAQ,EACR;IAAE,cAAc,EAAE,iBAAiB,CAAA;CAAE,EACrC,gBAAgB,CAAC,GAAG,CAAC,CACtB,CAAC;AAyFF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,SAAS,uBAAu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