Skip to content

Instantly share code, notes, and snippets.

@DogPawHat
Created December 31, 2025 19:05
Show Gist options
  • Select an option

  • Save DogPawHat/93657dca392e8303b19e59146809617b to your computer and use it in GitHub Desktop.

Select an option

Save DogPawHat/93657dca392e8303b19e59146809617b to your computer and use it in GitHub Desktop.
const mapAgentStatusToAgentResponse = Effect.flatMap(
(response: AgentStatusResponse) =>
Match.value(response).pipe(
Match.when({ status: "completed" }, (mappedResponse) =>
Schema.decodeUnknown(AgentResponseCompleted)({
data: mappedResponse?.data,
expiresAt: mappedResponse?.expiresAt,
}),
),
Match.when({ status: "processing" }, (mappedResponse) =>
Schema.decodeUnknown(AgentResponsePending)({
expiresAt: mappedResponse?.expiresAt,
}),
),
Match.when({ status: "failed" }, (mappedResponse) =>
Effect.gen(function* () {
// Ok, this shit is hilarious.
return yield* yield* Schema.decodeUnknown(AgentResponseFailedError)({
errorMessage: mappedResponse?.error,
expiresAt: mappedResponse?.expiresAt,
});
}),
),
Match.exhaustive,
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment