feat: add async Sprite job manager with progress polling
- Add SpriteJobManager and job RPCs (start/get/list) for connect, launch, create, and sync operations - Time-box status RPC with 5s remote timeout and lazy remote fetching - Cache remote sprites, raw token, and host/agent lists to avoid redundant API calls - Harden sprite host exec timeouts, JSON parsing, and npm install with --no-audit --no-fund - UI: poll active jobs with phase updates in workers screen - Reduce token exchange and OpenBao request timeout to 8s
This commit is contained in:
1 parent
32c02cb3cd
commit
36d88ef168
8 files changed
+1142
-186
No files matched your search
@@ -97,6 +97,68 @@ export const OpenBaoStatusSchema = z.object({
|
||||
|
||||
export type OpenBaoStatus = z.output<typeof OpenBaoStatusSchema>;
|
||||
|
||||
export const SpriteJobKindSchema = z.enum([
|
||||
"connect_host",
|
||||
"launch_agent",
|
||||
"create_sprite",
|
||||
"sync_workspace",
|
||||
]);
|
||||
|
||||
export type SpriteJobKind = z.output<typeof SpriteJobKindSchema>;
|
||||
|
||||
export const SpriteJobStatusSchema = z.enum(["running", "succeeded", "failed"]);
|
||||
|
||||
export type SpriteJobStatus = z.output<typeof SpriteJobStatusSchema>;
|
||||
|
||||
export const SpriteJobResultSchema = z.discriminatedUnion("kind", [
|
||||
z.object({
|
||||
kind: z.literal("connect_host"),
|
||||
spriteName: z.string(),
|
||||
serverId: z.string(),
|
||||
registrationId: z.string(),
|
||||
remoteDir: z.string(),
|
||||
syncedFiles: z.number().optional(),
|
||||
}),
|
||||
z.object({
|
||||
kind: z.literal("launch_agent"),
|
||||
agentId: z.string(),
|
||||
serverId: z.string(),
|
||||
spriteName: z.string(),
|
||||
provider: z.string(),
|
||||
remoteDir: z.string(),
|
||||
syncedFiles: z.number().optional(),
|
||||
}),
|
||||
z.object({
|
||||
kind: z.literal("create_sprite"),
|
||||
sprite: SpriteSummarySchema,
|
||||
syncedFiles: z.number().optional(),
|
||||
}),
|
||||
z.object({
|
||||
kind: z.literal("sync_workspace"),
|
||||
spriteName: z.string(),
|
||||
fileCount: z.number(),
|
||||
bytes: z.number(),
|
||||
remoteDir: z.string(),
|
||||
}),
|
||||
]);
|
||||
|
||||
export type SpriteJobResult = z.output<typeof SpriteJobResultSchema>;
|
||||
|
||||
export const SpriteJobSchema = z.object({
|
||||
jobId: z.string(),
|
||||
kind: SpriteJobKindSchema,
|
||||
spriteName: z.string().nullable(),
|
||||
status: SpriteJobStatusSchema,
|
||||
phase: z.string(),
|
||||
startedAt: z.string(),
|
||||
updatedAt: z.string(),
|
||||
finishedAt: z.string().nullable(),
|
||||
error: z.string().nullable(),
|
||||
result: SpriteJobResultSchema.nullable(),
|
||||
});
|
||||
|
||||
export type SpriteJob = z.output<typeof SpriteJobSchema>;
|
||||
|
||||
export const testConnectionRpc = defineRpc({
|
||||
name: "sprites.test",
|
||||
input: z.object({}),
|
||||
@@ -152,6 +214,25 @@ export const ensureSpriteHostRpc = defineRpc({
|
||||
]),
|
||||
});
|
||||
|
||||
export const startConnectHostRpc = defineRpc({
|
||||
name: "sprites.host.connect.start",
|
||||
input: z.object({
|
||||
spriteName: z.string().optional(),
|
||||
syncLocalPath: z.string().optional(),
|
||||
remoteDir: z.string().optional(),
|
||||
}),
|
||||
output: z.discriminatedUnion("ok", [
|
||||
z.object({
|
||||
ok: z.literal(true),
|
||||
job: SpriteJobSchema,
|
||||
}),
|
||||
z.object({
|
||||
ok: z.literal(false),
|
||||
error: z.string(),
|
||||
}),
|
||||
]),
|
||||
});
|
||||
|
||||
export const launchSpriteAgentRpc = defineRpc({
|
||||
name: "sprites.agent.launch",
|
||||
input: z.object({
|
||||
@@ -179,6 +260,94 @@ export const launchSpriteAgentRpc = defineRpc({
|
||||
]),
|
||||
});
|
||||
|
||||
export const startLaunchAgentRpc = defineRpc({
|
||||
name: "sprites.agent.launch.start",
|
||||
input: z.object({
|
||||
spriteName: z.string().optional(),
|
||||
title: z.string().optional(),
|
||||
prompt: z.string().optional(),
|
||||
syncLocalPath: z.string().optional(),
|
||||
remoteDir: z.string().optional(),
|
||||
provider: z.string().optional(),
|
||||
}),
|
||||
output: z.discriminatedUnion("ok", [
|
||||
z.object({
|
||||
ok: z.literal(true),
|
||||
job: SpriteJobSchema,
|
||||
}),
|
||||
z.object({
|
||||
ok: z.literal(false),
|
||||
error: z.string(),
|
||||
}),
|
||||
]),
|
||||
});
|
||||
|
||||
export const startCreateSpriteRpc = defineRpc({
|
||||
name: "sprites.create.start",
|
||||
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),
|
||||
job: SpriteJobSchema,
|
||||
}),
|
||||
z.object({
|
||||
ok: z.literal(false),
|
||||
error: z.string(),
|
||||
}),
|
||||
]),
|
||||
});
|
||||
|
||||
export const startSyncWorkspaceRpc = defineRpc({
|
||||
name: "sprites.sync.start",
|
||||
input: z.object({
|
||||
spriteName: z.string(),
|
||||
localPath: z.string(),
|
||||
remoteDir: z.string().optional(),
|
||||
}),
|
||||
output: z.discriminatedUnion("ok", [
|
||||
z.object({
|
||||
ok: z.literal(true),
|
||||
job: SpriteJobSchema,
|
||||
}),
|
||||
z.object({
|
||||
ok: z.literal(false),
|
||||
error: z.string(),
|
||||
}),
|
||||
]),
|
||||
});
|
||||
|
||||
export const getSpriteJobRpc = defineRpc({
|
||||
name: "sprites.job.get",
|
||||
input: z.object({
|
||||
jobId: z.string(),
|
||||
}),
|
||||
output: z.discriminatedUnion("ok", [
|
||||
z.object({
|
||||
ok: z.literal(true),
|
||||
job: SpriteJobSchema,
|
||||
}),
|
||||
z.object({
|
||||
ok: z.literal(false),
|
||||
error: z.string(),
|
||||
}),
|
||||
]),
|
||||
});
|
||||
|
||||
export const listSpriteJobsRpc = defineRpc({
|
||||
name: "sprites.jobs.list",
|
||||
input: z.object({}),
|
||||
output: z.object({
|
||||
jobs: z.array(SpriteJobSchema),
|
||||
}),
|
||||
});
|
||||
|
||||
export const spriteAgentActionRpc = defineRpc({
|
||||
name: "sprites.agent.action",
|
||||
input: z.object({
|
||||
|
||||
Reference in new issue
Block a user