The Coline App SDK: apps, tools, file types and surfaces that run inside Coline workspaces, and public websites with Coline Sites. TypeScript, with an in-memory test workspace. MIT.
| 5 | * Background jobs: durable work that outlives the request that started it. |
| 6 | * |
| 7 | * A job is enqueued from any app context (`coline.jobs.enqueue`) and runs |
| 8 | * on Coline's job workers with the principal that enqueued it — the |
| 9 | * invoking user, or the app itself for schedules, events, and endpoints. |
| 10 | * Attempts retry with exponential backoff; work longer than one attempt's |
| 11 | * timeout continues by checkpointing state or returning `continueWith`. |
| 12 | * The declared `effect` is the job's runtime capability ceiling, exactly |
| 13 | * like a tool's. |
| 14 | */ |
| 15 |
| 16 | export const jobNameSchema = z |
| 17 | .string() |
| 18 | .trim() |
| 19 | .regex(/^[a-z][a-z0-9_-]*$/, "Job names are lowercase identifiers.") |
| 20 | .max(80); |
| 21 |
| 22 | export const MAX_JOB_TIMEOUT_SECONDS = 900; |
| 23 |
| 24 | export const appJobDefinitionSchema = z.strictObject({ |
| 25 | name: jobNameSchema, |
| 26 | description: z.string().trim().max(500).optional(), |
| 27 | effect: toolEffectSchema.default("write"), |
| 28 | /** Wall-clock budget for one attempt. */ |
| 29 | timeoutSeconds: z.number().int().min(1).max(MAX_JOB_TIMEOUT_SECONDS).default(300), |
| 30 | /** Attempts before the run is dead-lettered. */ |
| 31 | maxAttempts: z.number().int().min(1).max(20).default(5), |
| 32 | /** Concurrent runs of this job per install. */ |
| 33 | concurrency: z.number().int().min(1).max(20).default(4), |
| 34 | }); |
| 35 | export type AppJobDefinition = z.infer<typeof appJobDefinitionSchema>; |
| 36 | export type AppJobDefinitionInput = z.input<typeof appJobDefinitionSchema>; |
| 37 |
| 38 | export const appJobsSchema = z |
| 39 | .array(appJobDefinitionSchema) |
| 40 | .max(50) |
| 41 | .default([]) |
| 42 | .refine( |
| 43 | (jobs) => new Set(jobs.map((job) => job.name)).size === jobs.length, |
| 44 | "Job names must be unique.", |
| 45 | ); |
| 46 |