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AA6B;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;CAAG;;AACzG,qBAAa,WAAY,SAAQ,iBAA2B;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CAChB,CAAC;CAAG;;AACL,qBAAa,MAAO,SAAQ,YAAsB;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;CAAG;AAEzE,qBAAa,YAAa,SAAQ,KAAK;IACtC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAExB,YAAY,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAI1C;CACD;AAED,qBAAa,aAAc,SAAQ,KAAK;IACvC,cAGC;CACD;AAED,MAAM,MAAM,aAAa,CAAC,MAAM,SAAS,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,IAAI;KAC3E,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,GAAG,CAAA;KAAE,CAAC,KAAK,MAAM;CAC1E,CAAC;AAEF,wBAAgB,UAAU,CAAC,MAAM,SAAS,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,EACzE,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,GACrC,MAAM,CAGR","sourcesContent":["export type Result<TValue, TError> = { ok: true; value: TValue } | { ok: false; error: TError };\n\nexport const Result = {\n\tok<TValue>(value: TValue): Result<TValue, never> {\n\t\treturn { ok: true, value };\n\t},\n\terr<TError>(error: TError): Result<never, TError> {\n\t\treturn { ok: false, error };\n\t},\n\tisOk<TValue, TError>(result: Result<TValue, TError>): result is { ok: true; value: TValue } {\n\t\treturn result.ok;\n\t},\n\tisErr<TValue, TError>(result: Result<TValue, TError>): result is { ok: false; error: TError } {\n\t\treturn !result.ok;\n\t},\n};\n\nexport interface TaggedErrorValue<Tag extends string> extends Error {\n\treadonly _tag: Tag;\n\ttoJSON(): { _tag: Tag; message: string } & Record<string, unknown>;\n}\n\nexport interface TaggedErrorFactory<Tag extends string> {\n\tnew <Props extends { message: string }>(props: Props): TaggedErrorValue<Tag> & Readonly<Props>;\n\tis(value: unknown): value is TaggedErrorValue<Tag>;\n}\n\nexport function TaggedError<Tag extends string>(tag: Tag): TaggedErrorFactory<Tag> {\n\tclass TaggedErrorClass extends Error {\n\t\treadonly _tag = tag;\n\n\t\tconstructor(props: { message: string } & Record<string, unknown>) {\n\t\t\tsuper(props.message);\n\t\t\tthis.name = tag;\n\t\t\tObject.assign(this, props);\n\t\t}\n\n\t\ttoJSON(): { _tag: Tag; message: string } & Record<string, unknown> {\n\t\t\tconst payload: Record<string, unknown> = {};\n\t\t\tfor (const key of Object.keys(this)) {\n\t\t\t\tif (key !== \"_tag\") payload[key] = (this as unknown as Record<string, unknown>)[key];\n\t\t\t}\n\t\t\treturn { _tag: tag, message: this.message, ...payload };\n\t\t}\n\n\t\tstatic is(value: unknown): value is TaggedErrorValue<Tag> {\n\t\t\treturn value instanceof TaggedErrorClass;\n\t\t}\n\t}\n\treturn TaggedErrorClass as unknown as TaggedErrorFactory<Tag>;\n}\n\nexport class LaneBusy extends TaggedError(\"LaneBusy\")<{\n\tlane: string;\n\toperationId: string;\n\toperationKind: \"run\" | \"compaction\" | \"navigation\";\n\tmessage: string;\n}> {}\nexport class OperationMismatch extends TaggedError(\"OperationMismatch\")<{\n\tlane: string;\n\texpectedOperationId: string;\n\tcurrentOperationId?: string;\n\tlastOperationId?: string;\n\tmessage: string;\n}> {}\nexport class NoActiveRun extends TaggedError(\"NoActiveRun\")<{ lane: string; message: string }> {}\nexport class NoActiveOperation extends TaggedError(\"NoActiveOperation\")<{ lane: string; message: string }> {}\nexport class NothingToResume extends TaggedError(\"NothingToResume\")<{ lane: string; message: string }> {}\nexport class NothingToCompact extends TaggedError(\"NothingToCompact\")<{ lane: string; message: string }> {}\nexport class InvalidMessage extends TaggedError(\"InvalidMessage\")<{\n\tlane: string;\n\treason: string;\n\tmessage: string;\n}> {}\nexport class InvalidNavigation extends TaggedError(\"InvalidNavigation\")<{\n\tlane: string;\n\treason: string;\n\tmessage: string;\n}> {}\nexport class UnknownSkill extends TaggedError(\"UnknownSkill\")<{ name: string; message: string }> {}\nexport class UnknownTemplate extends TaggedError(\"UnknownTemplate\")<{ name: string; message: string }> {}\nexport class UnknownTarget extends TaggedError(\"UnknownTarget\")<{ targetId: string; message: string }> {}\nexport class InvalidLane extends TaggedError(\"InvalidLane\")<{\n\tlane: string;\n\treason: string;\n\tmessage: string;\n}> {}\nexport class Closed extends TaggedError(\"Closed\")<{ message: string }> {}\n\nexport class HarnessFault extends Error {\n\treadonly cause: unknown;\n\n\tconstructor(message: string, cause: unknown) {\n\t\tsuper(message);\n\t\tthis.name = \"HarnessFault\";\n\t\tthis.cause = cause;\n\t}\n}\n\nexport class HarnessClosed extends Error {\n\tconstructor() {\n\t\tsuper(\"AgentHarness was closed while the operation was active\");\n\t\tthis.name = \"HarnessClosed\";\n\t}\n}\n\nexport type ErrorMatchers<TError extends TaggedErrorValue<string>, TValue> = {\n\t[Tag in TError[\"_tag\"]]: (error: Extract<TError, { _tag: Tag }>) => TValue;\n};\n\nexport function matchError<TError extends TaggedErrorValue<string>, TValue>(\n\terror: TError,\n\tmatchers: ErrorMatchers<TError, TValue>,\n): TValue {\n\tconst matcher = (matchers as unknown as Record<string, (value: TError) => TValue>)[error._tag];\n\treturn matcher(error);\n}\n"]}