| 1 | import * as Schema from "effect/Schema"; |
| 2 | import { ThreadId } from "./baseSchemas.ts"; |
| 3 | |
| 4 | export const ScriptProgressSubscribeInput = Schema.Struct({ threadId: ThreadId }); |
| 5 | |
| 6 | export const ScriptProgressSummary = Schema.Array( |
| 7 | Schema.Struct({ |
| 8 | text: Schema.String, |
| 9 | value: Schema.Number, |
| 10 | total: Schema.Number, |
| 11 | detail: Schema.String, |
| 12 | }), |
| 13 | ); |
| 14 | |
| 15 | export const ScriptProgressStream = Schema.Struct({ |
| 16 | id: Schema.String, |
| 17 | pid: Schema.Int, |
| 18 | label: Schema.String, |
| 19 | status: Schema.Literals(["connected", "disconnected"]), |
| 20 | summary: ScriptProgressSummary, |
| 21 | }); |
| 22 | export type ScriptProgressStream = typeof ScriptProgressStream.Type; |
| 23 | |
| 24 | export const ScriptProgressEvent = Schema.Union([ |
| 25 | Schema.Struct({ type: Schema.Literal("snapshot"), streams: Schema.Array(ScriptProgressStream) }), |
| 26 | Schema.Struct({ type: Schema.Literal("upsert"), stream: ScriptProgressStream }), |
| 27 | Schema.Struct({ |
| 28 | type: Schema.Literal("progress"), |
| 29 | id: Schema.String, |
| 30 | event: Schema.Array(Schema.Json), |
| 31 | summary: ScriptProgressSummary, |
| 32 | }), |
| 33 | Schema.Struct({ type: Schema.Literal("remove"), id: Schema.String }), |
| 34 | ]); |
| 35 | export type ScriptProgressEvent = typeof ScriptProgressEvent.Type; |
| 36 | |
| 37 | export class ScriptProgressStreamError extends Schema.TaggedError<ScriptProgressStreamError>()( |
| 38 | "ScriptProgressStreamError", |
| 39 | {}, |
| 40 | ) { |
| 41 | override get message(): string { |
| 42 | return "Progress updates fell behind. Reconnect to refresh them."; |
| 43 | } |
| 44 | } |