@trigger.dev/convex 0.0.1 → 4.8.3

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.
@@ -0,0 +1,139 @@
1
+ import { type GenericMutationCtx } from "convex/server";
2
+ import { type DataModel } from "./server.js";
3
+ import { type Run } from "./shared.js";
4
+ type RunDoc = DataModel["runs"]["document"];
5
+ export declare function toRun(run: RunDoc): Run;
6
+ export declare const trigger: import("convex/server").RegisteredMutation<"public", {
7
+ callback?: string | undefined;
8
+ config: {
9
+ baseUrl: string;
10
+ secretKey: string;
11
+ };
12
+ idempotencyKey?: string | undefined;
13
+ options: {
14
+ concurrencyKey?: string | undefined;
15
+ delay?: string | undefined;
16
+ machine?: string | undefined;
17
+ maxAttempts?: number | undefined;
18
+ maxDuration?: number | undefined;
19
+ metadata?: any;
20
+ queue?: {
21
+ name: string;
22
+ } | undefined;
23
+ tags?: string[] | undefined;
24
+ ttl?: string | undefined;
25
+ };
26
+ payload?: any;
27
+ taskId: string;
28
+ }, Promise<string>>;
29
+ export declare const get: import("convex/server").RegisteredQuery<"public", {
30
+ id: string;
31
+ }, Promise<{
32
+ createdAt: number;
33
+ error?: any;
34
+ id: string;
35
+ idempotencyKey?: string | undefined;
36
+ metadata?: any;
37
+ output?: any;
38
+ outputOmitted?: boolean | undefined;
39
+ outputPresignedUrl?: string | undefined;
40
+ runId?: string | undefined;
41
+ status: string;
42
+ syncError?: string | undefined;
43
+ syncStatus: "active" | "complete" | "paused" | "pending";
44
+ taskId: string;
45
+ updatedAt: number;
46
+ } | null>>;
47
+ export declare const list: import("convex/server").RegisteredQuery<"public", {
48
+ paginationOpts: {
49
+ id?: number;
50
+ endCursor?: string | null;
51
+ maximumRowsRead?: number;
52
+ maximumBytesRead?: number;
53
+ numItems: number;
54
+ cursor: string | null;
55
+ };
56
+ }, Promise<{
57
+ page: Run[];
58
+ isDone: boolean;
59
+ continueCursor: string;
60
+ }>>;
61
+ export declare function scheduleRefresh(ctx: GenericMutationCtx<DataModel>, run: RunDoc): Promise<void>;
62
+ export declare const refresh: import("convex/server").RegisteredMutation<"public", {
63
+ id: string;
64
+ }, Promise<null>>;
65
+ export declare const resume: import("convex/server").RegisteredMutation<"public", {
66
+ config: {
67
+ baseUrl: string;
68
+ secretKey: string;
69
+ };
70
+ id: string;
71
+ }, Promise<null>>;
72
+ export declare const load: import("convex/server").RegisteredQuery<"internal", {
73
+ id: import("convex/values").GenericId<"runs">;
74
+ }, Promise<{
75
+ run: {
76
+ _creationTime: number;
77
+ _id: import("convex/values").GenericId<"runs">;
78
+ callback?: string | undefined;
79
+ checking?: boolean | undefined;
80
+ checks: number;
81
+ error?: any;
82
+ failures: number;
83
+ generation: number;
84
+ idempotencyKey?: string | undefined;
85
+ lastCheckAt?: number | undefined;
86
+ metadata?: any;
87
+ output?: any;
88
+ outputOmitted?: boolean | undefined;
89
+ outputPresignedUrl?: string | undefined;
90
+ refreshRequested?: boolean | undefined;
91
+ runId?: string | undefined;
92
+ status: string;
93
+ syncError?: string | undefined;
94
+ syncStatus: "active" | "complete" | "paused" | "pending";
95
+ taskId: string;
96
+ updatedAt: number;
97
+ };
98
+ request: {
99
+ _creationTime: number;
100
+ _id: import("convex/values").GenericId<"requests">;
101
+ config: {
102
+ baseUrl: string;
103
+ secretKey: string;
104
+ };
105
+ options: {
106
+ concurrencyKey?: string | undefined;
107
+ delay?: string | undefined;
108
+ machine?: string | undefined;
109
+ maxAttempts?: number | undefined;
110
+ maxDuration?: number | undefined;
111
+ metadata?: any;
112
+ queue?: {
113
+ name: string;
114
+ } | undefined;
115
+ tags?: string[] | undefined;
116
+ ttl?: string | undefined;
117
+ };
118
+ payload?: any;
119
+ run: import("convex/values").GenericId<"runs">;
120
+ };
121
+ } | null>>;
122
+ export declare const recordSubmission: import("convex/server").RegisteredMutation<"internal", {
123
+ generation: number;
124
+ id: import("convex/values").GenericId<"runs">;
125
+ runId: string;
126
+ }, Promise<null>>;
127
+ export declare const recordStatus: import("convex/server").RegisteredMutation<"internal", {
128
+ completed: boolean;
129
+ error?: any;
130
+ generation: number;
131
+ id: import("convex/values").GenericId<"runs">;
132
+ metadata?: any;
133
+ output?: any;
134
+ outputOmitted?: boolean | undefined;
135
+ outputPresignedUrl?: string | undefined;
136
+ status: string;
137
+ }, Promise<null>>;
138
+ export declare function pause(ctx: GenericMutationCtx<DataModel>, run: RunDoc, message: string): Promise<void>;
139
+ export {};
@@ -0,0 +1,234 @@
1
+ import { paginationOptsValidator, } from "convex/server";
2
+ import { v } from "convex/values";
3
+ import { internal } from "./api.js";
4
+ import { internalMutation, internalQuery, mutation, query } from "./server.js";
5
+ import { MAX_INLINE_BYTES, MAX_PAGE_BYTES, MIN_REFRESH_INTERVAL_MS, SUBMISSION_WINDOW_MS, vConfig, vRun, vTriggerOptions, } from "./shared.js";
6
+ export function toRun(run) {
7
+ const { _id, _creationTime, generation, checks, failures, callback, checking, refreshRequested, lastCheckAt, ...fields } = run;
8
+ return { id: _id, createdAt: _creationTime, ...fields };
9
+ }
10
+ export const trigger = mutation({
11
+ args: {
12
+ taskId: v.string(),
13
+ payload: v.optional(v.any()),
14
+ options: vTriggerOptions,
15
+ config: vConfig,
16
+ idempotencyKey: v.optional(v.string()),
17
+ callback: v.optional(v.string()),
18
+ },
19
+ returns: v.string(),
20
+ handler: async (ctx, args) => {
21
+ if (!args.taskId.trim())
22
+ throw new Error("taskId is required");
23
+ if (new TextEncoder().encode(JSON.stringify({ payload: args.payload, options: args.options }))
24
+ .byteLength > MAX_INLINE_BYTES) {
25
+ throw new Error("Payload and options must fit within 256 KiB; pass a storage reference for larger inputs");
26
+ }
27
+ if (args.idempotencyKey !== undefined) {
28
+ const existing = await ctx.db
29
+ .query("runs")
30
+ .withIndex("by_key", (q) => q.eq("idempotencyKey", args.idempotencyKey))
31
+ .unique();
32
+ if (existing)
33
+ return existing._id;
34
+ }
35
+ const id = await ctx.db.insert("runs", {
36
+ taskId: args.taskId,
37
+ idempotencyKey: args.idempotencyKey,
38
+ status: "PENDING",
39
+ syncStatus: "pending",
40
+ updatedAt: Date.now(),
41
+ generation: 0,
42
+ checks: 0,
43
+ failures: 0,
44
+ callback: args.callback,
45
+ });
46
+ await ctx.db.insert("requests", {
47
+ run: id,
48
+ payload: args.payload,
49
+ options: args.options,
50
+ config: args.config,
51
+ });
52
+ await ctx.scheduler.runAfter(0, internal.worker.tick, { id, generation: 0 });
53
+ return id;
54
+ },
55
+ });
56
+ export const get = query({
57
+ args: { id: v.string() },
58
+ returns: v.union(vRun, v.null()),
59
+ handler: async (ctx, { id }) => {
60
+ const runId = ctx.db.normalizeId("runs", id);
61
+ const run = runId ? await ctx.db.get("runs", runId) : null;
62
+ return run ? toRun(run) : null;
63
+ },
64
+ });
65
+ export const list = query({
66
+ args: { paginationOpts: paginationOptsValidator },
67
+ returns: v.object({ page: v.array(vRun), isDone: v.boolean(), continueCursor: v.string() }),
68
+ handler: async (ctx, { paginationOpts }) => {
69
+ if (paginationOpts.numItems < 1 || paginationOpts.numItems > 100) {
70
+ throw new Error("Request between 1 and 100 runs per page");
71
+ }
72
+ const result = await ctx.db
73
+ .query("runs")
74
+ .order("desc")
75
+ .paginate({
76
+ ...paginationOpts,
77
+ maximumBytesRead: Math.min(paginationOpts.maximumBytesRead ?? MAX_PAGE_BYTES, MAX_PAGE_BYTES),
78
+ });
79
+ return {
80
+ page: result.page.map(toRun),
81
+ isDone: result.isDone,
82
+ continueCursor: result.continueCursor,
83
+ };
84
+ },
85
+ });
86
+ export async function scheduleRefresh(ctx, run) {
87
+ if (!run.refreshRequested)
88
+ return;
89
+ const delay = run.lastCheckAt === undefined
90
+ ? 0
91
+ : Math.max(0, run.lastCheckAt + MIN_REFRESH_INTERVAL_MS - Date.now());
92
+ await ctx.scheduler.runAfter(delay, internal.worker.tick, {
93
+ id: run._id,
94
+ generation: run.generation,
95
+ });
96
+ }
97
+ export const refresh = mutation({
98
+ args: { id: v.string() },
99
+ returns: v.null(),
100
+ handler: async (ctx, { id }) => {
101
+ const runId = ctx.db.normalizeId("runs", id);
102
+ const run = runId ? await ctx.db.get("runs", runId) : null;
103
+ if (!run)
104
+ throw new Error("Run not found");
105
+ if (!run.runId || run.syncStatus !== "active" || run.refreshRequested)
106
+ return null;
107
+ await ctx.db.patch(run._id, { refreshRequested: true });
108
+ // Preserve the in-flight observation; its result will schedule any requested follow-up.
109
+ if (!run.checking)
110
+ await scheduleRefresh(ctx, { ...run, refreshRequested: true });
111
+ return null;
112
+ },
113
+ });
114
+ export const resume = mutation({
115
+ args: { id: v.string(), config: vConfig },
116
+ returns: v.null(),
117
+ handler: async (ctx, { id, config }) => {
118
+ const runId = ctx.db.normalizeId("runs", id);
119
+ const run = runId ? await ctx.db.get("runs", runId) : null;
120
+ if (!run)
121
+ throw new Error("Run not found");
122
+ if (run.syncStatus !== "paused")
123
+ return null;
124
+ if (!run.runId && Date.now() - run._creationTime >= SUBMISSION_WINDOW_MS) {
125
+ throw new Error("Submission retry window expired; reconcile the run in Trigger before triggering again");
126
+ }
127
+ const request = await ctx.db
128
+ .query("requests")
129
+ .withIndex("by_run", (q) => q.eq("run", run._id))
130
+ .unique();
131
+ if (!request)
132
+ throw new Error("Run request not found");
133
+ await ctx.db.patch("requests", request._id, { config });
134
+ const generation = run.generation + 1;
135
+ await ctx.db.patch("runs", run._id, {
136
+ syncStatus: run.runId ? "active" : "pending",
137
+ syncError: undefined,
138
+ failures: 0,
139
+ checks: 0,
140
+ generation,
141
+ checking: undefined,
142
+ refreshRequested: undefined,
143
+ updatedAt: Date.now(),
144
+ });
145
+ await ctx.scheduler.runAfter(0, internal.worker.tick, { id: run._id, generation });
146
+ return null;
147
+ },
148
+ });
149
+ export const load = internalQuery({
150
+ args: { id: v.id("runs") },
151
+ handler: async (ctx, { id }) => {
152
+ const run = await ctx.db.get("runs", id);
153
+ const request = await ctx.db
154
+ .query("requests")
155
+ .withIndex("by_run", (q) => q.eq("run", id))
156
+ .unique();
157
+ return run && request ? { run, request } : null;
158
+ },
159
+ });
160
+ export const recordSubmission = internalMutation({
161
+ args: { id: v.id("runs"), generation: v.number(), runId: v.string() },
162
+ returns: v.null(),
163
+ handler: async (ctx, args) => {
164
+ const run = await ctx.db.get("runs", args.id);
165
+ if (!run || run.generation !== args.generation || run.syncStatus === "complete")
166
+ return null;
167
+ await ctx.db.patch("runs", args.id, {
168
+ runId: args.runId,
169
+ status: "QUEUED",
170
+ syncStatus: "active",
171
+ syncError: undefined,
172
+ failures: 0,
173
+ checks: 0,
174
+ checking: undefined,
175
+ updatedAt: Date.now(),
176
+ });
177
+ return null;
178
+ },
179
+ });
180
+ export const recordStatus = internalMutation({
181
+ args: {
182
+ id: v.id("runs"),
183
+ generation: v.number(),
184
+ status: v.string(),
185
+ completed: v.boolean(),
186
+ output: v.optional(v.any()),
187
+ outputPresignedUrl: v.optional(v.string()),
188
+ outputOmitted: v.optional(v.boolean()),
189
+ error: v.optional(v.any()),
190
+ metadata: v.optional(v.any()),
191
+ },
192
+ returns: v.null(),
193
+ handler: async (ctx, { id, generation, completed, ...result }) => {
194
+ const run = await ctx.db.get("runs", id);
195
+ if (!run || run.generation !== generation || run.syncStatus === "complete")
196
+ return null;
197
+ const updates = {
198
+ ...result,
199
+ syncStatus: completed ? "complete" : "active",
200
+ syncError: undefined,
201
+ failures: 0,
202
+ checking: undefined,
203
+ refreshRequested: completed ? undefined : run.refreshRequested,
204
+ updatedAt: Date.now(),
205
+ };
206
+ await ctx.db.patch("runs", id, updates);
207
+ if (completed) {
208
+ if (run.callback) {
209
+ await ctx.runMutation(run.callback, {
210
+ run: toRun({ ...run, ...updates }),
211
+ });
212
+ }
213
+ const request = await ctx.db
214
+ .query("requests")
215
+ .withIndex("by_run", (q) => q.eq("run", id))
216
+ .unique();
217
+ if (request)
218
+ await ctx.db.delete("requests", request._id);
219
+ }
220
+ else {
221
+ await scheduleRefresh(ctx, run);
222
+ }
223
+ return null;
224
+ },
225
+ });
226
+ export async function pause(ctx, run, message) {
227
+ await ctx.db.patch("runs", run._id, {
228
+ syncStatus: "paused",
229
+ syncError: message,
230
+ checking: undefined,
231
+ refreshRequested: undefined,
232
+ updatedAt: Date.now(),
233
+ });
234
+ }
@@ -0,0 +1,106 @@
1
+ declare const _default: import("convex/server").SchemaDefinition<{
2
+ runs: import("convex/server").TableDefinition<import("convex/values").VObject<{
3
+ callback?: string | undefined;
4
+ checking?: boolean | undefined;
5
+ checks: number;
6
+ error?: any;
7
+ failures: number;
8
+ generation: number;
9
+ idempotencyKey?: string | undefined;
10
+ lastCheckAt?: number | undefined;
11
+ metadata?: any;
12
+ output?: any;
13
+ outputOmitted?: boolean | undefined;
14
+ outputPresignedUrl?: string | undefined;
15
+ refreshRequested?: boolean | undefined;
16
+ runId?: string | undefined;
17
+ status: string;
18
+ syncError?: string | undefined;
19
+ syncStatus: "active" | "complete" | "paused" | "pending";
20
+ taskId: string;
21
+ updatedAt: number;
22
+ }, {
23
+ taskId: import("convex/values").VString<string, "required">;
24
+ runId: import("convex/values").VString<string | undefined, "optional">;
25
+ idempotencyKey: import("convex/values").VString<string | undefined, "optional">;
26
+ status: import("convex/values").VString<string, "required">;
27
+ syncStatus: import("convex/values").VUnion<"active" | "complete" | "paused" | "pending", [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"active", "required">, import("convex/values").VLiteral<"paused", "required">, import("convex/values").VLiteral<"complete", "required">], "required", never>;
28
+ output: import("convex/values").VAny<any, "optional", string>;
29
+ outputPresignedUrl: import("convex/values").VString<string | undefined, "optional">;
30
+ outputOmitted: import("convex/values").VBoolean<boolean | undefined, "optional">;
31
+ error: import("convex/values").VAny<any, "optional", string>;
32
+ metadata: import("convex/values").VAny<any, "optional", string>;
33
+ syncError: import("convex/values").VString<string | undefined, "optional">;
34
+ updatedAt: import("convex/values").VFloat64<number, "required">;
35
+ generation: import("convex/values").VFloat64<number, "required">;
36
+ checks: import("convex/values").VFloat64<number, "required">;
37
+ failures: import("convex/values").VFloat64<number, "required">;
38
+ checking: import("convex/values").VBoolean<boolean | undefined, "optional">;
39
+ refreshRequested: import("convex/values").VBoolean<boolean | undefined, "optional">;
40
+ lastCheckAt: import("convex/values").VFloat64<number | undefined, "optional">;
41
+ callback: import("convex/values").VString<string | undefined, "optional">;
42
+ }, "required", "callback" | "checking" | "checks" | "error" | "failures" | "generation" | "idempotencyKey" | "lastCheckAt" | "metadata" | "output" | "outputOmitted" | "outputPresignedUrl" | "refreshRequested" | "runId" | "status" | "syncError" | "syncStatus" | "taskId" | "updatedAt" | `error.${string}` | `metadata.${string}` | `output.${string}`>, {
43
+ by_key: ["idempotencyKey", "_creationTime"];
44
+ }, {}, {}>;
45
+ requests: import("convex/server").TableDefinition<import("convex/values").VObject<{
46
+ config: {
47
+ baseUrl: string;
48
+ secretKey: string;
49
+ };
50
+ options: {
51
+ concurrencyKey?: string | undefined;
52
+ delay?: string | undefined;
53
+ machine?: string | undefined;
54
+ maxAttempts?: number | undefined;
55
+ maxDuration?: number | undefined;
56
+ metadata?: any;
57
+ queue?: {
58
+ name: string;
59
+ } | undefined;
60
+ tags?: string[] | undefined;
61
+ ttl?: string | undefined;
62
+ };
63
+ payload?: any;
64
+ run: import("convex/values").GenericId<"runs">;
65
+ }, {
66
+ run: import("convex/values").VId<import("convex/values").GenericId<"runs">, "required">;
67
+ payload: import("convex/values").VAny<any, "optional", string>;
68
+ options: import("convex/values").VObject<{
69
+ concurrencyKey?: string | undefined;
70
+ delay?: string | undefined;
71
+ machine?: string | undefined;
72
+ maxAttempts?: number | undefined;
73
+ maxDuration?: number | undefined;
74
+ metadata?: any;
75
+ queue?: {
76
+ name: string;
77
+ } | undefined;
78
+ tags?: string[] | undefined;
79
+ ttl?: string | undefined;
80
+ }, {
81
+ tags: import("convex/values").VArray<string[] | undefined, import("convex/values").VString<string, "required">, "optional">;
82
+ delay: import("convex/values").VString<string | undefined, "optional">;
83
+ queue: import("convex/values").VObject<{
84
+ name: string;
85
+ } | undefined, {
86
+ name: import("convex/values").VString<string, "required">;
87
+ }, "optional", "name">;
88
+ concurrencyKey: import("convex/values").VString<string | undefined, "optional">;
89
+ machine: import("convex/values").VString<string | undefined, "optional">;
90
+ metadata: import("convex/values").VAny<any, "optional", string>;
91
+ maxAttempts: import("convex/values").VFloat64<number | undefined, "optional">;
92
+ maxDuration: import("convex/values").VFloat64<number | undefined, "optional">;
93
+ ttl: import("convex/values").VString<string | undefined, "optional">;
94
+ }, "required", "concurrencyKey" | "delay" | "machine" | "maxAttempts" | "maxDuration" | "metadata" | "queue" | "queue.name" | "tags" | "ttl" | `metadata.${string}`>;
95
+ config: import("convex/values").VObject<{
96
+ baseUrl: string;
97
+ secretKey: string;
98
+ }, {
99
+ secretKey: import("convex/values").VString<string, "required">;
100
+ baseUrl: import("convex/values").VString<string, "required">;
101
+ }, "required", "baseUrl" | "secretKey">;
102
+ }, "required", "config" | "config.baseUrl" | "config.secretKey" | "options" | "options.concurrencyKey" | "options.delay" | "options.machine" | "options.maxAttempts" | "options.maxDuration" | "options.metadata" | "options.queue" | "options.queue.name" | "options.tags" | "options.ttl" | "payload" | "run" | `options.metadata.${string}` | `payload.${string}`>, {
103
+ by_run: ["run", "_creationTime"];
104
+ }, {}, {}>;
105
+ }, true>;
106
+ export default _default;
@@ -0,0 +1,21 @@
1
+ import { defineSchema, defineTable } from "convex/server";
2
+ import { v } from "convex/values";
3
+ import { runFields, vConfig, vTriggerOptions } from "./shared.js";
4
+ export default defineSchema({
5
+ runs: defineTable({
6
+ ...runFields,
7
+ generation: v.number(),
8
+ checks: v.number(),
9
+ failures: v.number(),
10
+ checking: v.optional(v.boolean()),
11
+ refreshRequested: v.optional(v.boolean()),
12
+ lastCheckAt: v.optional(v.number()),
13
+ callback: v.optional(v.string()),
14
+ }).index("by_key", ["idempotencyKey"]),
15
+ requests: defineTable({
16
+ run: v.id("runs"),
17
+ payload: v.optional(v.any()),
18
+ options: vTriggerOptions,
19
+ config: vConfig,
20
+ }).index("by_run", ["run"]),
21
+ });
@@ -0,0 +1,8 @@
1
+ import { type ActionBuilder, type MutationBuilder, type QueryBuilder, type DataModelFromSchemaDefinition } from "convex/server";
2
+ import type schema from "./schema.js";
3
+ export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
4
+ export declare const mutation: MutationBuilder<DataModel, "public">;
5
+ export declare const query: QueryBuilder<DataModel, "public">;
6
+ export declare const internalMutation: MutationBuilder<DataModel, "internal">;
7
+ export declare const internalQuery: QueryBuilder<DataModel, "internal">;
8
+ export declare const internalAction: ActionBuilder<DataModel, "internal">;
@@ -0,0 +1,6 @@
1
+ import { internalActionGeneric, internalMutationGeneric, internalQueryGeneric, mutationGeneric, queryGeneric, } from "convex/server";
2
+ export const mutation = mutationGeneric;
3
+ export const query = queryGeneric;
4
+ export const internalMutation = internalMutationGeneric;
5
+ export const internalQuery = internalQueryGeneric;
6
+ export const internalAction = internalActionGeneric;
@@ -0,0 +1,92 @@
1
+ import { type Infer } from "convex/values";
2
+ export declare const vTriggerOptions: import("convex/values").VObject<{
3
+ concurrencyKey?: string | undefined;
4
+ delay?: string | undefined;
5
+ machine?: string | undefined;
6
+ maxAttempts?: number | undefined;
7
+ maxDuration?: number | undefined;
8
+ metadata?: any;
9
+ queue?: {
10
+ name: string;
11
+ } | undefined;
12
+ tags?: string[] | undefined;
13
+ ttl?: string | undefined;
14
+ }, {
15
+ tags: import("convex/values").VArray<string[] | undefined, import("convex/values").VString<string, "required">, "optional">;
16
+ delay: import("convex/values").VString<string | undefined, "optional">;
17
+ queue: import("convex/values").VObject<{
18
+ name: string;
19
+ } | undefined, {
20
+ name: import("convex/values").VString<string, "required">;
21
+ }, "optional", "name">;
22
+ concurrencyKey: import("convex/values").VString<string | undefined, "optional">;
23
+ machine: import("convex/values").VString<string | undefined, "optional">;
24
+ metadata: import("convex/values").VAny<any, "optional", string>;
25
+ maxAttempts: import("convex/values").VFloat64<number | undefined, "optional">;
26
+ maxDuration: import("convex/values").VFloat64<number | undefined, "optional">;
27
+ ttl: import("convex/values").VString<string | undefined, "optional">;
28
+ }, "required", "concurrencyKey" | "delay" | "machine" | "maxAttempts" | "maxDuration" | "metadata" | "queue" | "queue.name" | "tags" | "ttl" | `metadata.${string}`>;
29
+ export declare const vConfig: import("convex/values").VObject<{
30
+ baseUrl: string;
31
+ secretKey: string;
32
+ }, {
33
+ secretKey: import("convex/values").VString<string, "required">;
34
+ baseUrl: import("convex/values").VString<string, "required">;
35
+ }, "required", "baseUrl" | "secretKey">;
36
+ export declare const runFields: {
37
+ taskId: import("convex/values").VString<string, "required">;
38
+ runId: import("convex/values").VString<string | undefined, "optional">;
39
+ idempotencyKey: import("convex/values").VString<string | undefined, "optional">;
40
+ status: import("convex/values").VString<string, "required">;
41
+ syncStatus: import("convex/values").VUnion<"active" | "complete" | "paused" | "pending", [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"active", "required">, import("convex/values").VLiteral<"paused", "required">, import("convex/values").VLiteral<"complete", "required">], "required", never>;
42
+ output: import("convex/values").VAny<any, "optional", string>;
43
+ outputPresignedUrl: import("convex/values").VString<string | undefined, "optional">;
44
+ outputOmitted: import("convex/values").VBoolean<boolean | undefined, "optional">;
45
+ error: import("convex/values").VAny<any, "optional", string>;
46
+ metadata: import("convex/values").VAny<any, "optional", string>;
47
+ syncError: import("convex/values").VString<string | undefined, "optional">;
48
+ updatedAt: import("convex/values").VFloat64<number, "required">;
49
+ };
50
+ export declare const vRun: import("convex/values").VObject<{
51
+ createdAt: number;
52
+ error?: any;
53
+ id: string;
54
+ idempotencyKey?: string | undefined;
55
+ metadata?: any;
56
+ output?: any;
57
+ outputOmitted?: boolean | undefined;
58
+ outputPresignedUrl?: string | undefined;
59
+ runId?: string | undefined;
60
+ status: string;
61
+ syncError?: string | undefined;
62
+ syncStatus: "active" | "complete" | "paused" | "pending";
63
+ taskId: string;
64
+ updatedAt: number;
65
+ }, {
66
+ taskId: import("convex/values").VString<string, "required">;
67
+ runId: import("convex/values").VString<string | undefined, "optional">;
68
+ idempotencyKey: import("convex/values").VString<string | undefined, "optional">;
69
+ status: import("convex/values").VString<string, "required">;
70
+ syncStatus: import("convex/values").VUnion<"active" | "complete" | "paused" | "pending", [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"active", "required">, import("convex/values").VLiteral<"paused", "required">, import("convex/values").VLiteral<"complete", "required">], "required", never>;
71
+ output: import("convex/values").VAny<any, "optional", string>;
72
+ outputPresignedUrl: import("convex/values").VString<string | undefined, "optional">;
73
+ outputOmitted: import("convex/values").VBoolean<boolean | undefined, "optional">;
74
+ error: import("convex/values").VAny<any, "optional", string>;
75
+ metadata: import("convex/values").VAny<any, "optional", string>;
76
+ syncError: import("convex/values").VString<string | undefined, "optional">;
77
+ updatedAt: import("convex/values").VFloat64<number, "required">;
78
+ id: import("convex/values").VString<string, "required">;
79
+ createdAt: import("convex/values").VFloat64<number, "required">;
80
+ }, "required", "createdAt" | "error" | "id" | "idempotencyKey" | "metadata" | "output" | "outputOmitted" | "outputPresignedUrl" | "runId" | "status" | "syncError" | "syncStatus" | "taskId" | "updatedAt" | `error.${string}` | `metadata.${string}` | `output.${string}`>;
81
+ export type Run = Infer<typeof vRun>;
82
+ export type TriggerOptions = Infer<typeof vTriggerOptions>;
83
+ export type Config = Infer<typeof vConfig>;
84
+ export declare const REQUEST_TIMEOUT_MS = 10000;
85
+ export declare const MIN_REFRESH_INTERVAL_MS = 5000;
86
+ export declare const WATCHDOG_MARGIN_MS = 5000;
87
+ export declare const MAX_SYNC_FAILURES = 8;
88
+ export declare const SUBMISSION_WINDOW_MS: number;
89
+ export declare const IDEMPOTENCY_TTL = "24h";
90
+ export declare const MAX_INLINE_BYTES: number;
91
+ export declare const MAX_PAGE_BYTES: number;
92
+ export declare function pollDelay(checks: number): number;
@@ -0,0 +1,48 @@
1
+ import { v } from "convex/values";
2
+ export const vTriggerOptions = v.object({
3
+ tags: v.optional(v.array(v.string())),
4
+ delay: v.optional(v.string()),
5
+ queue: v.optional(v.object({ name: v.string() })),
6
+ concurrencyKey: v.optional(v.string()),
7
+ machine: v.optional(v.string()),
8
+ metadata: v.optional(v.any()),
9
+ maxAttempts: v.optional(v.number()),
10
+ maxDuration: v.optional(v.number()),
11
+ ttl: v.optional(v.string()),
12
+ });
13
+ export const vConfig = v.object({
14
+ secretKey: v.string(),
15
+ baseUrl: v.string(),
16
+ });
17
+ export const runFields = {
18
+ taskId: v.string(),
19
+ runId: v.optional(v.string()),
20
+ idempotencyKey: v.optional(v.string()),
21
+ status: v.string(),
22
+ syncStatus: v.union(v.literal("pending"), v.literal("active"), v.literal("paused"), v.literal("complete")),
23
+ output: v.optional(v.any()),
24
+ outputPresignedUrl: v.optional(v.string()),
25
+ outputOmitted: v.optional(v.boolean()),
26
+ error: v.optional(v.any()),
27
+ metadata: v.optional(v.any()),
28
+ syncError: v.optional(v.string()),
29
+ updatedAt: v.number(),
30
+ };
31
+ export const vRun = v.object({
32
+ id: v.string(),
33
+ createdAt: v.number(),
34
+ ...runFields,
35
+ });
36
+ const FIRST_POLL_MS = 15_000;
37
+ const MAX_POLL_MS = 60_000;
38
+ export const REQUEST_TIMEOUT_MS = 10_000;
39
+ export const MIN_REFRESH_INTERVAL_MS = 5_000;
40
+ export const WATCHDOG_MARGIN_MS = 5_000;
41
+ export const MAX_SYNC_FAILURES = 8;
42
+ export const SUBMISSION_WINDOW_MS = 60 * 60 * 1_000;
43
+ export const IDEMPOTENCY_TTL = "24h";
44
+ export const MAX_INLINE_BYTES = 256 * 1_024;
45
+ export const MAX_PAGE_BYTES = 4 * 1_024 * 1_024;
46
+ export function pollDelay(checks) {
47
+ return Math.min(FIRST_POLL_MS * 2 ** Math.min(checks, 4), MAX_POLL_MS);
48
+ }