@browserbasehq/convex-stagehand 0.0.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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +477 -0
  3. package/dist/client/index.d.ts +258 -0
  4. package/dist/client/index.d.ts.map +1 -0
  5. package/dist/client/index.js +216 -0
  6. package/dist/client/index.js.map +1 -0
  7. package/dist/component/_generated/api.d.ts +36 -0
  8. package/dist/component/_generated/api.d.ts.map +1 -0
  9. package/dist/component/_generated/api.js +31 -0
  10. package/dist/component/_generated/api.js.map +1 -0
  11. package/dist/component/_generated/component.d.ts +24 -0
  12. package/dist/component/_generated/component.d.ts.map +1 -0
  13. package/dist/component/_generated/component.js +11 -0
  14. package/dist/component/_generated/component.js.map +1 -0
  15. package/dist/component/_generated/dataModel.d.ts +15 -0
  16. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  17. package/dist/component/_generated/dataModel.js +11 -0
  18. package/dist/component/_generated/dataModel.js.map +1 -0
  19. package/dist/component/_generated/server.d.ts +121 -0
  20. package/dist/component/_generated/server.d.ts.map +1 -0
  21. package/dist/component/_generated/server.js +78 -0
  22. package/dist/component/_generated/server.js.map +1 -0
  23. package/dist/component/api.d.ts +90 -0
  24. package/dist/component/api.d.ts.map +1 -0
  25. package/dist/component/api.js +112 -0
  26. package/dist/component/api.js.map +1 -0
  27. package/dist/component/convex.config.d.ts +3 -0
  28. package/dist/component/convex.config.d.ts.map +1 -0
  29. package/dist/component/convex.config.js +3 -0
  30. package/dist/component/convex.config.js.map +1 -0
  31. package/dist/component/lib.d.ts +62 -0
  32. package/dist/component/lib.d.ts.map +1 -0
  33. package/dist/component/lib.js +356 -0
  34. package/dist/component/lib.js.map +1 -0
  35. package/dist/component/schema.d.ts +23 -0
  36. package/dist/component/schema.d.ts.map +1 -0
  37. package/dist/component/schema.js +14 -0
  38. package/dist/component/schema.js.map +1 -0
  39. package/dist/test.d.ts +48 -0
  40. package/dist/test.d.ts.map +1 -0
  41. package/dist/test.js +25 -0
  42. package/dist/test.js.map +1 -0
  43. package/package.json +87 -0
  44. package/src/client/index.ts +348 -0
  45. package/src/component/README.md +90 -0
  46. package/src/component/_generated/api.ts +52 -0
  47. package/src/component/_generated/component.ts +26 -0
  48. package/src/component/_generated/dataModel.ts +17 -0
  49. package/src/component/_generated/server.ts +156 -0
  50. package/src/component/api.ts +243 -0
  51. package/src/component/convex.config.ts +3 -0
  52. package/src/component/lib.ts +416 -0
  53. package/src/component/schema.ts +23 -0
  54. package/src/component/tsconfig.json +25 -0
  55. package/src/test.ts +33 -0
@@ -0,0 +1,348 @@
1
+ /**
2
+ * Stagehand Client
3
+ *
4
+ * Type-safe wrapper for the Stagehand Convex component.
5
+ * Uses Zod schemas for extraction typing.
6
+ */
7
+
8
+ import { zodToJsonSchema } from "zod-to-json-schema";
9
+ import type { z } from "zod";
10
+ import type {
11
+ GenericActionCtx,
12
+ } from "convex/server";
13
+
14
+ // Re-export component type
15
+ export type { ComponentApi } from "../component/_generated/component.js";
16
+ import type { ComponentApi } from "../component/_generated/component.js";
17
+
18
+ type ActionCtx = GenericActionCtx<any>;
19
+
20
+ export interface StagehandConfig {
21
+ browserbaseApiKey: string;
22
+ browserbaseProjectId: string;
23
+ modelApiKey: string;
24
+ modelName?: string;
25
+ }
26
+
27
+ export interface SessionInfo {
28
+ sessionId: string;
29
+ browserbaseSessionId?: string;
30
+ cdpUrl?: string;
31
+ }
32
+
33
+ export interface StartSessionOptions {
34
+ timeout?: number;
35
+ waitUntil?: "load" | "domcontentloaded" | "networkidle";
36
+ domSettleTimeoutMs?: number;
37
+ selfHeal?: boolean;
38
+ systemPrompt?: string;
39
+ }
40
+
41
+ export interface ExtractOptions {
42
+ timeout?: number;
43
+ waitUntil?: "load" | "domcontentloaded" | "networkidle";
44
+ }
45
+
46
+ export interface ActOptions {
47
+ timeout?: number;
48
+ waitUntil?: "load" | "domcontentloaded" | "networkidle";
49
+ }
50
+
51
+ export interface ObserveOptions {
52
+ timeout?: number;
53
+ waitUntil?: "load" | "domcontentloaded" | "networkidle";
54
+ }
55
+
56
+ export interface AgentOptions {
57
+ cua?: boolean;
58
+ maxSteps?: number;
59
+ systemPrompt?: string;
60
+ timeout?: number;
61
+ waitUntil?: "load" | "domcontentloaded" | "networkidle";
62
+ }
63
+
64
+ export interface ObservedAction {
65
+ description: string;
66
+ selector: string;
67
+ method: string;
68
+ arguments?: string[];
69
+ }
70
+
71
+ export interface ActResult {
72
+ success: boolean;
73
+ message: string;
74
+ actionDescription: string;
75
+ }
76
+
77
+ export interface AgentAction {
78
+ type: string;
79
+ action?: string;
80
+ reasoning?: string;
81
+ timeMs?: number;
82
+ }
83
+
84
+ export interface AgentResult {
85
+ actions: AgentAction[];
86
+ completed: boolean;
87
+ message: string;
88
+ success: boolean;
89
+ }
90
+
91
+ /**
92
+ * Stagehand client for AI-powered browser automation.
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * import { Stagehand } from "convex-stagehand";
97
+ * import { components } from "./_generated/api";
98
+ *
99
+ * const stagehand = new Stagehand(components.stagehand, {
100
+ * browserbaseApiKey: process.env.BROWSERBASE_API_KEY!,
101
+ * browserbaseProjectId: process.env.BROWSERBASE_PROJECT_ID!,
102
+ * modelApiKey: process.env.MODEL_API_KEY!,
103
+ * });
104
+ *
105
+ * export const scrape = action({
106
+ * handler: async (ctx) => {
107
+ * return await stagehand.extract(ctx, {
108
+ * url: "https://example.com",
109
+ * instruction: "Extract all product names",
110
+ * schema: z.object({ products: z.array(z.string()) }),
111
+ * });
112
+ * },
113
+ * });
114
+ * ```
115
+ */
116
+ export class Stagehand {
117
+ constructor(
118
+ private component: ComponentApi,
119
+ private config: StagehandConfig,
120
+ ) {}
121
+
122
+ /**
123
+ * Start a new browser session.
124
+ * Returns session info including cdpUrl for direct Playwright/Puppeteer connection.
125
+ *
126
+ * @param ctx - Convex action context
127
+ * @param args - Session parameters
128
+ * @returns Session info with sessionId, browserbaseSessionId, and cdpUrl
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const session = await stagehand.startSession(ctx, {
133
+ * url: "https://example.com",
134
+ * });
135
+ * // Use session.sessionId with other operations
136
+ * // Or connect Playwright: puppeteer.connect({ browserWSEndpoint: session.cdpUrl })
137
+ * ```
138
+ */
139
+ async startSession(
140
+ ctx: ActionCtx,
141
+ args: {
142
+ url: string;
143
+ browserbaseSessionId?: string;
144
+ options?: StartSessionOptions;
145
+ },
146
+ ): Promise<SessionInfo> {
147
+ return ctx.runAction(this.component.lib.startSession as any, {
148
+ ...this.config,
149
+ url: args.url,
150
+ browserbaseSessionId: args.browserbaseSessionId,
151
+ options: args.options,
152
+ });
153
+ }
154
+
155
+ /**
156
+ * End a browser session.
157
+ *
158
+ * @param ctx - Convex action context
159
+ * @param args - Session to end
160
+ * @returns Success status
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * await stagehand.endSession(ctx, { sessionId: session.sessionId });
165
+ * ```
166
+ */
167
+ async endSession(
168
+ ctx: ActionCtx,
169
+ args: {
170
+ sessionId: string;
171
+ },
172
+ ): Promise<{ success: boolean }> {
173
+ return ctx.runAction(this.component.lib.endSession as any, {
174
+ ...this.config,
175
+ sessionId: args.sessionId,
176
+ });
177
+ }
178
+
179
+ /**
180
+ * Extract structured data from a web page using AI.
181
+ *
182
+ * @param ctx - Convex action context
183
+ * @param args - Extraction parameters
184
+ * @returns Extracted data matching the provided schema
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * // Without session (creates and destroys its own)
189
+ * const data = await stagehand.extract(ctx, {
190
+ * url: "https://news.ycombinator.com",
191
+ * instruction: "Extract the top 5 stories with title and score",
192
+ * schema: z.object({
193
+ * stories: z.array(z.object({
194
+ * title: z.string(),
195
+ * score: z.string(),
196
+ * }))
197
+ * }),
198
+ * });
199
+ *
200
+ * // With existing session (reuses session)
201
+ * const data = await stagehand.extract(ctx, {
202
+ * sessionId: session.sessionId,
203
+ * instruction: "Extract the top 5 stories",
204
+ * schema: z.object({ ... }),
205
+ * });
206
+ * ```
207
+ */
208
+ async extract<T extends z.ZodType>(
209
+ ctx: ActionCtx,
210
+ args: {
211
+ sessionId?: string;
212
+ url?: string;
213
+ instruction: string;
214
+ schema: T;
215
+ options?: ExtractOptions;
216
+ },
217
+ ): Promise<z.infer<T>> {
218
+ const jsonSchema: any = zodToJsonSchema(args.schema);
219
+ // Remove $schema field as it's reserved in Convex
220
+ delete jsonSchema.$schema;
221
+ return ctx.runAction(this.component.lib.extract as any, {
222
+ ...this.config,
223
+ sessionId: args.sessionId,
224
+ url: args.url,
225
+ instruction: args.instruction,
226
+ schema: jsonSchema,
227
+ options: args.options,
228
+ });
229
+ }
230
+
231
+ /**
232
+ * Execute a browser action using natural language.
233
+ *
234
+ * @param ctx - Convex action context
235
+ * @param args - Action parameters
236
+ * @returns Result of the action
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * // Without session
241
+ * const result = await stagehand.act(ctx, {
242
+ * url: "https://example.com/login",
243
+ * action: "Click the login button",
244
+ * });
245
+ *
246
+ * // With existing session
247
+ * const result = await stagehand.act(ctx, {
248
+ * sessionId: session.sessionId,
249
+ * action: "Click the submit button",
250
+ * });
251
+ * ```
252
+ */
253
+ async act(
254
+ ctx: ActionCtx,
255
+ args: {
256
+ sessionId?: string;
257
+ url?: string;
258
+ action: string;
259
+ options?: ActOptions;
260
+ },
261
+ ): Promise<ActResult> {
262
+ return ctx.runAction(this.component.lib.act as any, {
263
+ ...this.config,
264
+ sessionId: args.sessionId,
265
+ url: args.url,
266
+ action: args.action,
267
+ options: args.options,
268
+ });
269
+ }
270
+
271
+ /**
272
+ * Find available actions on a web page.
273
+ *
274
+ * @param ctx - Convex action context
275
+ * @param args - Observe parameters
276
+ * @returns List of available actions
277
+ *
278
+ * @example
279
+ * ```typescript
280
+ * const actions = await stagehand.observe(ctx, {
281
+ * url: "https://example.com",
282
+ * instruction: "Find all navigation links",
283
+ * });
284
+ * ```
285
+ */
286
+ async observe(
287
+ ctx: ActionCtx,
288
+ args: {
289
+ sessionId?: string;
290
+ url?: string;
291
+ instruction: string;
292
+ options?: ObserveOptions;
293
+ },
294
+ ): Promise<ObservedAction[]> {
295
+ return ctx.runAction(this.component.lib.observe as any, {
296
+ ...this.config,
297
+ sessionId: args.sessionId,
298
+ url: args.url,
299
+ instruction: args.instruction,
300
+ options: args.options,
301
+ });
302
+ }
303
+
304
+ /**
305
+ * Execute autonomous multi-step browser automation using an AI agent.
306
+ * The agent interprets the instruction and decides what actions to take.
307
+ *
308
+ * @param ctx - Convex action context
309
+ * @param args - Agent parameters
310
+ * @returns Agent execution result with actions taken
311
+ *
312
+ * @example
313
+ * ```typescript
314
+ * // Agent creates its own session
315
+ * const result = await stagehand.agent(ctx, {
316
+ * url: "https://google.com",
317
+ * instruction: "Search for 'convex database' and extract the top 3 results",
318
+ * options: { maxSteps: 10 },
319
+ * });
320
+ *
321
+ * // Agent with existing session
322
+ * const result = await stagehand.agent(ctx, {
323
+ * sessionId: session.sessionId,
324
+ * instruction: "Fill out the form and submit",
325
+ * options: { maxSteps: 5 },
326
+ * });
327
+ * ```
328
+ */
329
+ async agent(
330
+ ctx: ActionCtx,
331
+ args: {
332
+ sessionId?: string;
333
+ url?: string;
334
+ instruction: string;
335
+ options?: AgentOptions;
336
+ },
337
+ ): Promise<AgentResult> {
338
+ return ctx.runAction(this.component.lib.agent as any, {
339
+ ...this.config,
340
+ sessionId: args.sessionId,
341
+ url: args.url,
342
+ instruction: args.instruction,
343
+ options: args.options,
344
+ });
345
+ }
346
+ }
347
+
348
+ export default Stagehand;
@@ -0,0 +1,90 @@
1
+ # Welcome to your Convex functions directory!
2
+
3
+ Write your Convex functions here.
4
+ See https://docs.convex.dev/functions for more.
5
+
6
+ A query function that takes two arguments looks like:
7
+
8
+ ```ts
9
+ // convex/myFunctions.ts
10
+ import { query } from "./_generated/server";
11
+ import { v } from "convex/values";
12
+
13
+ export const myQueryFunction = query({
14
+ // Validators for arguments.
15
+ args: {
16
+ first: v.number(),
17
+ second: v.string(),
18
+ },
19
+
20
+ // Function implementation.
21
+ handler: async (ctx, args) => {
22
+ // Read the database as many times as you need here.
23
+ // See https://docs.convex.dev/database/reading-data.
24
+ const documents = await ctx.db.query("tablename").collect();
25
+
26
+ // Arguments passed from the client are properties of the args object.
27
+ console.log(args.first, args.second);
28
+
29
+ // Write arbitrary JavaScript here: filter, aggregate, build derived data,
30
+ // remove non-public properties, or create new objects.
31
+ return documents;
32
+ },
33
+ });
34
+ ```
35
+
36
+ Using this query function in a React component looks like:
37
+
38
+ ```ts
39
+ const data = useQuery(api.myFunctions.myQueryFunction, {
40
+ first: 10,
41
+ second: "hello",
42
+ });
43
+ ```
44
+
45
+ A mutation function looks like:
46
+
47
+ ```ts
48
+ // convex/myFunctions.ts
49
+ import { mutation } from "./_generated/server";
50
+ import { v } from "convex/values";
51
+
52
+ export const myMutationFunction = mutation({
53
+ // Validators for arguments.
54
+ args: {
55
+ first: v.string(),
56
+ second: v.string(),
57
+ },
58
+
59
+ // Function implementation.
60
+ handler: async (ctx, args) => {
61
+ // Insert or modify documents in the database here.
62
+ // Mutations can also read from the database like queries.
63
+ // See https://docs.convex.dev/database/writing-data.
64
+ const message = { body: args.first, author: args.second };
65
+ const id = await ctx.db.insert("messages", message);
66
+
67
+ // Optionally, return a value from your mutation.
68
+ return await ctx.db.get("messages", id);
69
+ },
70
+ });
71
+ ```
72
+
73
+ Using this mutation function in a React component looks like:
74
+
75
+ ```ts
76
+ const mutation = useMutation(api.myFunctions.myMutationFunction);
77
+ function handleButtonPress() {
78
+ // fire and forget, the most common way to use mutations
79
+ mutation({ first: "Hello!", second: "me" });
80
+ // OR
81
+ // use the result once the mutation has completed
82
+ mutation({ first: "Hello!", second: "me" }).then((result) =>
83
+ console.log(result),
84
+ );
85
+ }
86
+ ```
87
+
88
+ Use the Convex CLI to push your functions to a deployment. See everything
89
+ the Convex CLI can do by running `npx convex -h` in your project root
90
+ directory. To learn more, launch the docs with `npx convex docs`.
@@ -0,0 +1,52 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated `api` utility.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type * as api_ from "../api.js";
12
+ import type * as lib from "../lib.js";
13
+
14
+ import type {
15
+ ApiFromModules,
16
+ FilterApi,
17
+ FunctionReference,
18
+ } from "convex/server";
19
+ import { anyApi, componentsGeneric } from "convex/server";
20
+
21
+ const fullApi: ApiFromModules<{
22
+ api: typeof api_;
23
+ lib: typeof lib;
24
+ }> = anyApi as any;
25
+
26
+ /**
27
+ * A utility for referencing Convex functions in your app's public API.
28
+ *
29
+ * Usage:
30
+ * ```js
31
+ * const myFunctionReference = api.myModule.myFunction;
32
+ * ```
33
+ */
34
+ export const api: FilterApi<
35
+ typeof fullApi,
36
+ FunctionReference<any, "public">
37
+ > = anyApi as any;
38
+
39
+ /**
40
+ * A utility for referencing Convex functions in your app's internal API.
41
+ *
42
+ * Usage:
43
+ * ```js
44
+ * const myFunctionReference = internal.myModule.myFunction;
45
+ * ```
46
+ */
47
+ export const internal: FilterApi<
48
+ typeof fullApi,
49
+ FunctionReference<any, "internal">
50
+ > = anyApi as any;
51
+
52
+ export const components = componentsGeneric() as unknown as {};
@@ -0,0 +1,26 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated component type.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type { FunctionReference } from "convex/server";
12
+
13
+ /**
14
+ * Component API type for the Stagehand component.
15
+ * Used by the client to call component actions.
16
+ */
17
+ export type ComponentApi = {
18
+ lib: {
19
+ startSession: FunctionReference<"action", "public", any, any>;
20
+ endSession: FunctionReference<"action", "public", any, any>;
21
+ extract: FunctionReference<"action", "public", any, any>;
22
+ act: FunctionReference<"action", "public", any, any>;
23
+ observe: FunctionReference<"action", "public", any, any>;
24
+ agent: FunctionReference<"action", "public", any, any>;
25
+ };
26
+ };
@@ -0,0 +1,17 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated data model types.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type { DataModelFromSchemaDefinition } from "convex/server";
12
+ import type schema from "../schema.js";
13
+
14
+ /**
15
+ * The type of a document stored in Convex.
16
+ */
17
+ export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
@@ -0,0 +1,156 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated utilities for implementing server-side Convex query and mutation functions.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type {
12
+ ActionBuilder,
13
+ HttpActionBuilder,
14
+ MutationBuilder,
15
+ QueryBuilder,
16
+ GenericActionCtx,
17
+ GenericMutationCtx,
18
+ GenericQueryCtx,
19
+ GenericDatabaseReader,
20
+ GenericDatabaseWriter,
21
+ } from "convex/server";
22
+ import {
23
+ actionGeneric,
24
+ httpActionGeneric,
25
+ queryGeneric,
26
+ mutationGeneric,
27
+ internalActionGeneric,
28
+ internalMutationGeneric,
29
+ internalQueryGeneric,
30
+ } from "convex/server";
31
+ import type { DataModel } from "./dataModel.js";
32
+
33
+ /**
34
+ * Define a query in this Convex app's public API.
35
+ *
36
+ * This function will be allowed to read your Convex database and will be accessible from the client.
37
+ *
38
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
39
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
40
+ */
41
+ export const query: QueryBuilder<DataModel, "public"> = queryGeneric;
42
+
43
+ /**
44
+ * Define a query that is only accessible from other Convex functions (but not from the client).
45
+ *
46
+ * This function will be allowed to read from your Convex database. It will not be accessible from the client.
47
+ *
48
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
49
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
50
+ */
51
+ export const internalQuery: QueryBuilder<DataModel, "internal"> =
52
+ internalQueryGeneric;
53
+
54
+ /**
55
+ * Define a mutation in this Convex app's public API.
56
+ *
57
+ * This function will be allowed to modify your Convex database and will be accessible from the client.
58
+ *
59
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
60
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
61
+ */
62
+ export const mutation: MutationBuilder<DataModel, "public"> = mutationGeneric;
63
+
64
+ /**
65
+ * Define a mutation that is only accessible from other Convex functions (but not from the client).
66
+ *
67
+ * This function will be allowed to modify your Convex database. It will not be accessible from the client.
68
+ *
69
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
70
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
71
+ */
72
+ export const internalMutation: MutationBuilder<DataModel, "internal"> =
73
+ internalMutationGeneric;
74
+
75
+ /**
76
+ * Define an action in this Convex app's public API.
77
+ *
78
+ * An action is a function which can execute any JavaScript code, including non-deterministic
79
+ * code and code with side-effects, like calling third-party services.
80
+ * They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
81
+ * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
82
+ *
83
+ * @param func - The action. It receives an {@link ActionCtx} as its first argument.
84
+ * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
85
+ */
86
+ export const action: ActionBuilder<DataModel, "public"> = actionGeneric;
87
+
88
+ /**
89
+ * Define an action that is only accessible from other Convex functions (but not from the client).
90
+ *
91
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument.
92
+ * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
93
+ */
94
+ export const internalAction: ActionBuilder<DataModel, "internal"> =
95
+ internalActionGeneric;
96
+
97
+ /**
98
+ * Define an HTTP action.
99
+ *
100
+ * The wrapped function will be used to respond to HTTP requests received
101
+ * by a Convex deployment if the requests matches the path and method where
102
+ * this action is routed. Be sure to route your httpAction in `convex/http.js`.
103
+ *
104
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument
105
+ * and a Fetch API `Request` object as its second.
106
+ * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
107
+ */
108
+ export const httpAction: HttpActionBuilder = httpActionGeneric;
109
+
110
+ /**
111
+ * A set of services for use within Convex query functions.
112
+ *
113
+ * The query context is passed as the first argument to any Convex query
114
+ * function run on the server.
115
+ *
116
+ * If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.
117
+ */
118
+ export type QueryCtx = GenericQueryCtx<DataModel>;
119
+
120
+ /**
121
+ * A set of services for use within Convex mutation functions.
122
+ *
123
+ * The mutation context is passed as the first argument to any Convex mutation
124
+ * function run on the server.
125
+ *
126
+ * If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.
127
+ */
128
+ export type MutationCtx = GenericMutationCtx<DataModel>;
129
+
130
+ /**
131
+ * A set of services for use within Convex action functions.
132
+ *
133
+ * The action context is passed as the first argument to any Convex action
134
+ * function run on the server.
135
+ */
136
+ export type ActionCtx = GenericActionCtx<DataModel>;
137
+
138
+ /**
139
+ * An interface to read from the database within Convex query functions.
140
+ *
141
+ * The two entry points are {@link DatabaseReader.get}, which fetches a single
142
+ * document by its {@link Id}, or {@link DatabaseReader.query}, which starts
143
+ * building a query.
144
+ */
145
+ export type DatabaseReader = GenericDatabaseReader<DataModel>;
146
+
147
+ /**
148
+ * An interface to read from and write to the database within Convex mutation
149
+ * functions.
150
+ *
151
+ * Convex guarantees that all writes within a single mutation are
152
+ * executed atomically, so you never have to worry about partial writes leaving
153
+ * your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
154
+ * for the guarantees Convex provides your functions.
155
+ */
156
+ export type DatabaseWriter = GenericDatabaseWriter<DataModel>;