|
| 1 | +import { z } from "../framework"; |
| 2 | + |
| 3 | +import { FailedAPIOperationSchema } from "./common"; |
| 4 | +import { ProjectIdSchema } from "./projects/common"; |
| 5 | +import { ComputeServerIdSchema } from "./compute/common"; |
| 6 | + |
| 7 | +// OpenAPI spec |
| 8 | +// |
| 9 | +export const ExecInputSchema = z |
| 10 | + .object({ |
| 11 | + project_id: ProjectIdSchema, |
| 12 | + compute_server_id: ComputeServerIdSchema.describe( |
| 13 | + `If provided, the desired shell command will be run on the compute server whose id |
| 14 | + is specified in this field (if available).`, |
| 15 | + ).optional(), |
| 16 | + filesystem: z |
| 17 | + .boolean() |
| 18 | + .optional() |
| 19 | + .describe( |
| 20 | + `If \`true\`, this shell command runs in the fileserver container on the compute |
| 21 | + server; otherwise, it runs on the main compute container.`, |
| 22 | + ), |
| 23 | + path: z |
| 24 | + .string() |
| 25 | + .optional() |
| 26 | + .describe( |
| 27 | + "Path to working directory in which the shell command should be executed.", |
| 28 | + ), |
| 29 | + command: z.string().describe("The shell command to execute."), |
| 30 | + args: z |
| 31 | + .array(z.string()) |
| 32 | + .optional() |
| 33 | + .describe("An array of arguments to pass to the shell command."), |
| 34 | + timeout: z |
| 35 | + .number() |
| 36 | + .min(0) |
| 37 | + .default(60) |
| 38 | + .optional() |
| 39 | + .describe("Number of seconds before this shell command times out."), |
| 40 | + max_output: z |
| 41 | + .number() |
| 42 | + .min(0) |
| 43 | + .optional() |
| 44 | + .describe("Maximum number of bytes to return from shell command output."), |
| 45 | + bash: z |
| 46 | + .boolean() |
| 47 | + .optional() |
| 48 | + .describe( |
| 49 | + `If \`true\`, this command runs in a \`bash\` shell. To do so, the provided shell |
| 50 | + command is written to a file and then executed via the \`bash\` command.`, |
| 51 | + ), |
| 52 | + aggregate: z |
| 53 | + .union([ |
| 54 | + z.number(), |
| 55 | + z.string(), |
| 56 | + z.object({ value: z.union([z.string(), z.number()]) }), |
| 57 | + ]) |
| 58 | + .optional() |
| 59 | + .describe( |
| 60 | + `If provided, this shell command is aggregated as in |
| 61 | + \`src/packages/backend/aggregate.js\`. This parameter allows one to specify |
| 62 | + multiple callbacks to be executed against the output of the same command |
| 63 | + (given identical arguments) within a 60-second window.`, |
| 64 | + ), |
| 65 | + err_on_exit: z |
| 66 | + .boolean() |
| 67 | + .optional() |
| 68 | + .describe( |
| 69 | + `When \`true\`, this call will throw an error whenever the provided shell command |
| 70 | + exits with a non-zero exit code.`, |
| 71 | + ), |
| 72 | + env: z |
| 73 | + .record(z.string(), z.string()) |
| 74 | + .optional() |
| 75 | + .describe( |
| 76 | + "Environment variables to be passed to the shell command upon execution.", |
| 77 | + ), |
| 78 | + }) |
| 79 | + .describe("Perform arbitrary shell commands in a compute server or project."); |
| 80 | + |
| 81 | +export const ExecOutputSchema = z.union([ |
| 82 | + FailedAPIOperationSchema, |
| 83 | + z.any().describe("Output of executed command."), |
| 84 | +]); |
| 85 | + |
| 86 | +export type ExecInput = z.infer<typeof ExecInputSchema>; |
| 87 | +export type ExecOutput = z.infer<typeof ExecOutputSchema>; |
0 commit comments