feat: add fly-sprites-workers Paseo plugin
This commit is contained in:
commit
0c4027ebe5
15 files changed
+7446
No files matched your search
@@ -0,0 +1,238 @@
|
||||
import { defineRpc, defineSubscription } from "@getpaseo/plugin";
|
||||
import { z } from "zod";
|
||||
|
||||
export const SpriteSummarySchema = z.object({
|
||||
name: z.string(),
|
||||
id: z.string().optional(),
|
||||
status: z.string(),
|
||||
organization: z.string().optional(),
|
||||
primaryRegion: z.string().optional(),
|
||||
url: z.string().optional(),
|
||||
createdAt: z.string().optional(),
|
||||
updatedAt: z.string().optional(),
|
||||
});
|
||||
|
||||
export type SpriteSummary = z.output<typeof SpriteSummarySchema>;
|
||||
|
||||
export const WorkerStatusSchema = z.enum(["starting", "running", "completed", "failed", "stopped"]);
|
||||
|
||||
export const WorkerSummarySchema = z.object({
|
||||
workerId: z.string(),
|
||||
spriteName: z.string(),
|
||||
command: z.string(),
|
||||
cwd: z.string(),
|
||||
status: WorkerStatusSchema,
|
||||
exitCode: z.number().nullable(),
|
||||
error: z.string().nullable(),
|
||||
startedAt: z.string(),
|
||||
endedAt: z.string().nullable(),
|
||||
outputTail: z.string(),
|
||||
outputBytes: z.number(),
|
||||
});
|
||||
|
||||
export type WorkerSummary = z.output<typeof WorkerSummarySchema>;
|
||||
|
||||
export const CheckpointSummarySchema = z.object({
|
||||
id: z.string(),
|
||||
comment: z.string().optional(),
|
||||
createdAt: z.string(),
|
||||
isAuto: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export type CheckpointSummary = z.output<typeof CheckpointSummarySchema>;
|
||||
|
||||
export const testConnectionRpc = defineRpc({
|
||||
name: "sprites.test",
|
||||
input: z.object({}),
|
||||
output: z.discriminatedUnion("ok", [
|
||||
z.object({
|
||||
ok: z.literal(true),
|
||||
spriteCount: z.number(),
|
||||
source: z.enum(["settings", "env"]),
|
||||
}),
|
||||
z.object({
|
||||
ok: z.literal(false),
|
||||
error: z.string(),
|
||||
}),
|
||||
]),
|
||||
});
|
||||
|
||||
export const statusRpc = defineRpc({
|
||||
name: "sprites.status",
|
||||
input: z.object({
|
||||
includeRemote: z.boolean().optional(),
|
||||
}),
|
||||
output: z.object({
|
||||
configured: z.boolean(),
|
||||
tokenSource: z.enum(["settings", "env", "none"]),
|
||||
remoteError: z.string().nullable(),
|
||||
sprites: z.array(SpriteSummarySchema),
|
||||
workers: z.array(WorkerSummarySchema),
|
||||
}),
|
||||
});
|
||||
|
||||
export const createSpriteRpc = defineRpc({
|
||||
name: "sprites.create",
|
||||
input: z.object({
|
||||
name: z.string().optional(),
|
||||
region: z.string().optional(),
|
||||
ramMB: z.number().int().positive().optional(),
|
||||
cpus: z.number().int().positive().optional(),
|
||||
syncLocalPath: z.string().optional(),
|
||||
remoteDir: z.string().optional(),
|
||||
}),
|
||||
output: z.discriminatedUnion("ok", [
|
||||
z.object({
|
||||
ok: z.literal(true),
|
||||
sprite: SpriteSummarySchema,
|
||||
syncedFiles: z.number().optional(),
|
||||
}),
|
||||
z.object({
|
||||
ok: z.literal(false),
|
||||
error: z.string(),
|
||||
}),
|
||||
]),
|
||||
});
|
||||
|
||||
export const syncWorkspaceRpc = defineRpc({
|
||||
name: "sprites.sync",
|
||||
input: z.object({
|
||||
spriteName: z.string(),
|
||||
localPath: z.string(),
|
||||
remoteDir: z.string().optional(),
|
||||
}),
|
||||
output: z.discriminatedUnion("ok", [
|
||||
z.object({
|
||||
ok: z.literal(true),
|
||||
fileCount: z.number(),
|
||||
bytes: z.number(),
|
||||
remoteDir: z.string(),
|
||||
}),
|
||||
z.object({
|
||||
ok: z.literal(false),
|
||||
error: z.string(),
|
||||
}),
|
||||
]),
|
||||
});
|
||||
|
||||
export const spawnWorkerRpc = defineRpc({
|
||||
name: "sprites.worker.spawn",
|
||||
input: z.object({
|
||||
spriteName: z.string().optional(),
|
||||
command: z.string(),
|
||||
cwd: z.string().optional(),
|
||||
syncLocalPath: z.string().optional(),
|
||||
maxRunAfterDisconnect: z.string().optional(),
|
||||
}),
|
||||
output: z.discriminatedUnion("ok", [
|
||||
z.object({
|
||||
ok: z.literal(true),
|
||||
worker: WorkerSummarySchema,
|
||||
}),
|
||||
z.object({
|
||||
ok: z.literal(false),
|
||||
error: z.string(),
|
||||
}),
|
||||
]),
|
||||
});
|
||||
|
||||
export const stopWorkerRpc = defineRpc({
|
||||
name: "sprites.worker.stop",
|
||||
input: z.object({
|
||||
workerId: z.string(),
|
||||
}),
|
||||
output: z.object({
|
||||
ok: z.boolean(),
|
||||
error: z.string().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const workerLogsRpc = defineRpc({
|
||||
name: "sprites.worker.logs",
|
||||
input: z.object({
|
||||
workerId: z.string(),
|
||||
}),
|
||||
output: z.discriminatedUnion("ok", [
|
||||
z.object({
|
||||
ok: z.literal(true),
|
||||
worker: WorkerSummarySchema,
|
||||
output: z.string(),
|
||||
}),
|
||||
z.object({
|
||||
ok: z.literal(false),
|
||||
error: z.string(),
|
||||
}),
|
||||
]),
|
||||
});
|
||||
|
||||
export const destroySpriteRpc = defineRpc({
|
||||
name: "sprites.destroy",
|
||||
input: z.object({
|
||||
spriteName: z.string(),
|
||||
}),
|
||||
output: z.object({
|
||||
ok: z.boolean(),
|
||||
error: z.string().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
export const listCheckpointsRpc = defineRpc({
|
||||
name: "sprites.checkpoint.list",
|
||||
input: z.object({
|
||||
spriteName: z.string(),
|
||||
}),
|
||||
output: z.discriminatedUnion("ok", [
|
||||
z.object({
|
||||
ok: z.literal(true),
|
||||
checkpoints: z.array(CheckpointSummarySchema),
|
||||
}),
|
||||
z.object({
|
||||
ok: z.literal(false),
|
||||
error: z.string(),
|
||||
}),
|
||||
]),
|
||||
});
|
||||
|
||||
export const createCheckpointRpc = defineRpc({
|
||||
name: "sprites.checkpoint.create",
|
||||
input: z.object({
|
||||
spriteName: z.string(),
|
||||
comment: z.string().optional(),
|
||||
}),
|
||||
output: z.discriminatedUnion("ok", [
|
||||
z.object({
|
||||
ok: z.literal(true),
|
||||
messages: z.array(z.string()),
|
||||
}),
|
||||
z.object({
|
||||
ok: z.literal(false),
|
||||
error: z.string(),
|
||||
}),
|
||||
]),
|
||||
});
|
||||
|
||||
export const restoreCheckpointRpc = defineRpc({
|
||||
name: "sprites.checkpoint.restore",
|
||||
input: z.object({
|
||||
spriteName: z.string(),
|
||||
checkpointId: z.string(),
|
||||
}),
|
||||
output: z.discriminatedUnion("ok", [
|
||||
z.object({
|
||||
ok: z.literal(true),
|
||||
messages: z.array(z.string()),
|
||||
}),
|
||||
z.object({
|
||||
ok: z.literal(false),
|
||||
error: z.string(),
|
||||
}),
|
||||
]),
|
||||
});
|
||||
|
||||
export const watchWorkersSub = defineSubscription({
|
||||
name: "sprites.watch",
|
||||
input: z.object({}),
|
||||
event: z.object({
|
||||
workers: z.array(WorkerSummarySchema),
|
||||
}),
|
||||
});
|
||||
Reference in new issue
Block a user