mirror of
https://github.com/Heretek-AI/opencode.git
synced 2026-11-22 08:59:26 -10:00
Move effect/unstable/* imports to their top-level entry points (effect/unstable/httpapi becomes effect/http-api), migrate Encoding helpers to effect/encoding Base64 and Base64Url, rename Schema.isStartsWith to Schema.isStartingWith, import Arbitrary from effect, and update the HttpApi codegen templates, regenerated clients, and documentation.
40 lines
1.6 KiB
TypeScript
40 lines
1.6 KiB
TypeScript
// Generated by @opencode/httpapi-codegen. Do not edit.
|
|
import { Effect, Schema, Stream } from "effect"
|
|
import { Sse } from "effect/encoding"
|
|
import { HttpClientError } from "effect/http"
|
|
import { HttpApiClient, HttpApiEndpoint, HttpApiGroup, HttpApiSchema } from "effect/http-api"
|
|
import { ClientError } from "./client-error.js"
|
|
|
|
const EndpointSubscribeSuccessData = Schema.Struct({ type: Schema.String })
|
|
|
|
const EndpointSubscribeSuccessError = Schema.Never
|
|
|
|
export const GroupEvent = HttpApiGroup.make("event", { topLevel: false }).add(
|
|
HttpApiEndpoint.make("GET")("subscribe", "/event", {
|
|
success: HttpApiSchema.StreamSse({
|
|
data: EndpointSubscribeSuccessData,
|
|
error: EndpointSubscribeSuccessError,
|
|
contentType: "text/event-stream",
|
|
}).pipe(HttpApiSchema.status(202)),
|
|
}),
|
|
)
|
|
|
|
type RawGroup = HttpApiClient.Client.Group<typeof GroupEvent, never, never>
|
|
|
|
const EndpointSubscribeDeclaredError = Schema.Union([EndpointSubscribeSuccessError])
|
|
const mapEndpointSubscribeError = (error: unknown) =>
|
|
HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error)
|
|
? new ClientError({ cause: error })
|
|
: Schema.is(EndpointSubscribeDeclaredError)(error)
|
|
? error
|
|
: new ClientError({ cause: error })
|
|
const EndpointSubscribe = (raw: RawGroup) => () =>
|
|
Stream.unwrap(
|
|
raw["subscribe"]({}).pipe(
|
|
Effect.mapError(mapEndpointSubscribeError),
|
|
Effect.map((stream) => stream.pipe(Stream.mapError(mapEndpointSubscribeError))),
|
|
),
|
|
)
|
|
|
|
export const adaptGroupEvent = (raw: RawGroup) => ({ subscribe: EndpointSubscribe(raw) })
|