@opencode/ai 2.2.7 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +164 -99
- package/dist/cache-policy.js +4 -2
- package/dist/effect.d.ts +11 -8
- package/dist/effect.js +2 -1
- package/dist/experimental.d.ts +0 -4
- package/dist/experimental.js +0 -3
- package/dist/generation.d.ts +10 -10
- package/dist/generation.js +8 -14
- package/dist/image-client.d.ts +56 -59
- package/dist/image-client.js +47 -12
- package/dist/image.d.ts +36 -95
- package/dist/image.js +11 -14
- package/dist/index.d.ts +31 -68
- package/dist/index.js +54 -30
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +10 -1
- package/dist/media-client.d.ts +18 -6
- package/dist/media-client.js +42 -37
- package/dist/media-model.d.ts +2 -0
- package/dist/media-model.js +3 -1
- package/dist/media.d.ts +26 -4
- package/dist/media.js +52 -11
- package/dist/protocols/alibaba-messages.d.ts +24 -2
- package/dist/protocols/alibaba-responses.d.ts +26 -0
- package/dist/protocols/anthropic-messages.d.ts +70 -6
- package/dist/protocols/anthropic-messages.js +74 -9
- package/dist/protocols/assemblyai-transcription.js +7 -6
- package/dist/protocols/cartesia-speech.d.ts +0 -8
- package/dist/protocols/deepgram-speech.d.ts +0 -8
- package/dist/protocols/elevenlabs-speech.d.ts +0 -8
- package/dist/protocols/google-decisions.d.ts +13 -0
- package/dist/protocols/google-decisions.js +133 -0
- package/dist/protocols/google-interactions-video.d.ts +38 -0
- package/dist/protocols/google-interactions-video.js +185 -0
- package/dist/protocols/google-interactions.d.ts +14 -1
- package/dist/protocols/google-interactions.js +1 -1
- package/dist/protocols/google-speech.d.ts +0 -8
- package/dist/protocols/google-transcription.d.ts +0 -8
- package/dist/protocols/index.d.ts +1 -0
- package/dist/protocols/index.js +1 -0
- package/dist/protocols/meta-messages.d.ts +24 -2
- package/dist/protocols/meta-responses.d.ts +52 -0
- package/dist/protocols/minimax-video.d.ts +45 -0
- package/dist/protocols/minimax-video.js +290 -0
- package/dist/protocols/open-responses.d.ts +250 -24
- package/dist/protocols/open-responses.js +40 -24
- package/dist/protocols/openai-chat.js +7 -3
- package/dist/protocols/openai-compatible-responses.d.ts +26 -0
- package/dist/protocols/openai-freeform.d.ts +1 -1
- package/dist/protocols/openai-freeform.js +9 -5
- package/dist/protocols/openai-images.d.ts +0 -8
- package/dist/protocols/openai-responses.d.ts +153 -0
- package/dist/protocols/openai-responses.js +68 -7
- package/dist/protocols/openai-speech.d.ts +0 -8
- package/dist/protocols/openai-transcription.d.ts +0 -8
- package/dist/protocols/openrouter-video.d.ts +36 -0
- package/dist/protocols/openrouter-video.js +139 -0
- package/dist/protocols/seedance-video.d.ts +45 -0
- package/dist/protocols/seedance-video.js +217 -0
- package/dist/protocols/system-one.d.ts +45 -1
- package/dist/protocols/system-one.js +42 -7
- package/dist/protocols/utils/gateway-protocol.js +1 -0
- package/dist/protocols/utils/responses-compaction.js +8 -4
- package/dist/protocols/xai-responses.d.ts +26 -0
- package/dist/protocols/xai-video.d.ts +12 -11
- package/dist/protocols/xai-video.js +33 -24
- package/dist/protocols/zai-messages.d.ts +24 -2
- package/dist/provider-error.js +7 -1
- package/dist/providers/alibaba.d.ts +50 -2
- package/dist/providers/amazon-bedrock-mantle.d.ts +50 -2
- package/dist/providers/anthropic-compatible.d.ts +24 -2
- package/dist/providers/anthropic.d.ts +24 -2
- package/dist/providers/azure.d.ts +76 -2
- package/dist/providers/byteplus/videos.d.ts +2 -0
- package/dist/providers/byteplus/videos.js +1 -0
- package/dist/providers/byteplus.d.ts +26 -0
- package/dist/providers/byteplus.js +21 -0
- package/dist/providers/cloudflare-ai-gateway.d.ts +100 -4
- package/dist/providers/digitalocean.d.ts +26 -0
- package/dist/providers/google/decisions.d.ts +2 -0
- package/dist/providers/google/decisions.js +1 -0
- package/dist/providers/google/videos.d.ts +2 -0
- package/dist/providers/google/videos.js +1 -0
- package/dist/providers/google-vertex-messages.d.ts +24 -2
- package/dist/providers/google-vertex-messages.js +1 -0
- package/dist/providers/google-vertex-responses.d.ts +26 -0
- package/dist/providers/google.d.ts +11 -4
- package/dist/providers/google.js +16 -3
- package/dist/providers/index.d.ts +2 -1
- package/dist/providers/index.js +2 -1
- package/dist/providers/meta.d.ts +50 -2
- package/dist/providers/minimax/videos.d.ts +3 -0
- package/dist/providers/minimax/videos.js +1 -0
- package/dist/providers/minimax.d.ts +56 -3
- package/dist/providers/minimax.js +10 -1
- package/dist/providers/moonshot.d.ts +50 -2
- package/dist/providers/openai-compatible/decisions.d.ts +2 -0
- package/dist/providers/openai-compatible/decisions.js +1 -0
- package/dist/providers/openai-compatible-responses.d.ts +26 -0
- package/dist/providers/openai-compatible.d.ts +2 -0
- package/dist/providers/openai-compatible.js +14 -0
- package/dist/providers/openai.d.ts +26 -0
- package/dist/providers/openrouter/videos.d.ts +2 -0
- package/dist/providers/openrouter/videos.js +1 -0
- package/dist/providers/openrouter.d.ts +31 -0
- package/dist/providers/openrouter.js +8 -0
- package/dist/providers/venice.d.ts +26 -0
- package/dist/providers/volcengine/videos.d.ts +2 -0
- package/dist/providers/volcengine/videos.js +1 -0
- package/dist/providers/volcengine.d.ts +26 -0
- package/dist/providers/volcengine.js +21 -0
- package/dist/providers/xai/videos.d.ts +2 -0
- package/dist/providers/xai/videos.js +1 -0
- package/dist/providers/xai.d.ts +4 -3
- package/dist/providers/xai.js +5 -1
- package/dist/providers/zai-coding-plan.d.ts +50 -2
- package/dist/public.d.ts +7 -4
- package/dist/public.js +2 -1
- package/dist/route/client.d.ts +2 -0
- package/dist/route/client.js +5 -1
- package/dist/route/executor-service.d.ts +20 -1
- package/dist/route/executor-service.js +35 -1
- package/dist/route/executor.d.ts +11 -2
- package/dist/route/executor.js +25 -5
- package/dist/route/media-protocol.d.ts +21 -15
- package/dist/route/media-protocol.js +11 -4
- package/dist/route/media.d.ts +2 -0
- package/dist/route/media.js +40 -22
- package/dist/route/protocol.d.ts +3 -0
- package/dist/route/transport/http.js +1 -1
- package/dist/schema/events.d.ts +5 -0
- package/dist/schema/messages.d.ts +25 -2
- package/dist/schema/messages.js +27 -7
- package/dist/schema/options.d.ts +18 -2
- package/dist/schema/options.js +1 -0
- package/dist/speech-client.d.ts +6 -6
- package/dist/speech-client.js +4 -4
- package/dist/speech.d.ts +7 -88
- package/dist/speech.js +1 -3
- package/dist/tool-updates.d.ts +34 -0
- package/dist/tool-updates.js +93 -0
- package/dist/tool.d.ts +6 -1
- package/dist/tool.js +1 -1
- package/dist/transcription-client.d.ts +6 -6
- package/dist/transcription-client.js +1 -2
- package/dist/transcription.d.ts +7 -88
- package/dist/transcription.js +1 -3
- package/dist/video-client.d.ts +16 -84
- package/dist/video-client.js +30 -13
- package/dist/video.d.ts +54 -1126
- package/dist/video.js +29 -65
- package/package.json +59 -7
- package/dist/protocols/google-video.d.ts +0 -26
- package/dist/protocols/google-video.js +0 -146
- package/dist/protocols/runway-video.d.ts +0 -38
- package/dist/protocols/runway-video.js +0 -141
- package/dist/providers/runway.d.ts +0 -20
- package/dist/providers/runway.js +0 -17
package/dist/image-client.d.ts
CHANGED
|
@@ -1,65 +1,61 @@
|
|
|
1
|
-
import { Context } from "effect";
|
|
1
|
+
import { Context, Effect, Layer, Stream } from "effect";
|
|
2
|
+
import type { AwaitOptions } from "./generation.js";
|
|
2
3
|
import { MediaClient } from "./media-client.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
4
|
+
import { RequestExecutor } from "./route/executor.js";
|
|
5
|
+
import { AIError } from "./schema/index.js";
|
|
6
|
+
import type { ImageEvent, ImageJob, ImageModel, ImageRequest, ImageResponse, ImageStatus } from "./image.js";
|
|
7
|
+
/** `start`, `status`, `result` and `cancel` fail with `UnsupportedOperation` on inline and stream routes. */
|
|
8
|
+
export interface Interface extends Pick<MediaClient.Interface<ImageRequest, ImageEvent, ImageResponse>, "generate" | "stream"> {
|
|
9
|
+
readonly start: (request: ImageRequest) => Effect.Effect<ImageJob, AIError>;
|
|
10
|
+
readonly status: (model: ImageModel, id: string) => Effect.Effect<ImageStatus, AIError>;
|
|
11
|
+
readonly result: (model: ImageModel, id: string) => Effect.Effect<ImageResponse, AIError>;
|
|
12
|
+
readonly cancel: (model: ImageModel, id: string) => Effect.Effect<void, AIError>;
|
|
13
|
+
}
|
|
5
14
|
declare const ImageClientService_base: Context.ServiceClass<ImageClientService, "@opencode/ImageClient", Interface>;
|
|
6
15
|
export declare class ImageClientService extends ImageClientService_base {
|
|
7
16
|
}
|
|
8
17
|
export declare const Service: typeof ImageClientService;
|
|
9
18
|
export type Service = ImageClientService;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
declare const responseEvents: (response: ImageResponse) => ({
|
|
20
|
+
type: "image";
|
|
21
|
+
index: number;
|
|
22
|
+
image: import("./media.js").Asset;
|
|
23
|
+
} | {
|
|
24
|
+
type: "finish";
|
|
25
|
+
usage: {
|
|
26
|
+
readonly type: "seconds";
|
|
27
|
+
readonly seconds: number;
|
|
15
28
|
} | {
|
|
16
|
-
readonly type: "
|
|
17
|
-
readonly
|
|
18
|
-
readonly image: import("./media.js").Asset;
|
|
29
|
+
readonly type: "characters";
|
|
30
|
+
readonly characters: number;
|
|
19
31
|
} | {
|
|
20
|
-
readonly type: "
|
|
21
|
-
readonly
|
|
22
|
-
readonly position?: number | undefined;
|
|
32
|
+
readonly type: "credits";
|
|
33
|
+
readonly credits: number;
|
|
23
34
|
} | {
|
|
24
|
-
readonly type: "
|
|
25
|
-
readonly
|
|
26
|
-
readonly progress?: number | undefined;
|
|
35
|
+
readonly type: "compute";
|
|
36
|
+
readonly seconds: number;
|
|
27
37
|
} | {
|
|
28
|
-
readonly type: "
|
|
29
|
-
readonly
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
readonly
|
|
34
|
-
readonly characters: number;
|
|
35
|
-
} | {
|
|
36
|
-
readonly type: "credits";
|
|
37
|
-
readonly credits: number;
|
|
38
|
-
} | {
|
|
39
|
-
readonly type: "compute";
|
|
40
|
-
readonly seconds: number;
|
|
41
|
-
} | {
|
|
42
|
-
readonly type: "tokens";
|
|
43
|
-
readonly input?: number | undefined;
|
|
44
|
-
readonly output?: number | undefined;
|
|
45
|
-
readonly total?: number | undefined;
|
|
46
|
-
readonly details?: {
|
|
47
|
-
readonly [x: string]: unknown;
|
|
48
|
-
} | undefined;
|
|
49
|
-
} | undefined;
|
|
50
|
-
readonly providerMetadata?: {
|
|
51
|
-
readonly [x: string]: {
|
|
52
|
-
readonly [x: string]: unknown;
|
|
53
|
-
};
|
|
38
|
+
readonly type: "tokens";
|
|
39
|
+
readonly input?: number | undefined;
|
|
40
|
+
readonly output?: number | undefined;
|
|
41
|
+
readonly total?: number | undefined;
|
|
42
|
+
readonly details?: {
|
|
43
|
+
readonly [x: string]: unknown;
|
|
54
44
|
} | undefined;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
45
|
+
} | undefined;
|
|
46
|
+
providerMetadata: {
|
|
47
|
+
readonly [x: string]: {
|
|
48
|
+
readonly [x: string]: unknown;
|
|
49
|
+
};
|
|
50
|
+
} | undefined;
|
|
51
|
+
})[];
|
|
52
|
+
export declare const layer: Layer.Layer<ImageClientService, never, RequestExecutor.RequestExecutorService>;
|
|
53
|
+
export declare const ImageClient: {
|
|
54
|
+
readonly Service: typeof ImageClientService;
|
|
55
|
+
readonly layer: Layer.Layer<ImageClientService, never, RequestExecutor.RequestExecutorService>;
|
|
56
|
+
readonly responseEvents: typeof responseEvents;
|
|
57
|
+
readonly generate: (request: ImageRequest, options?: AwaitOptions) => Effect.Effect<ImageResponse, AIError, ImageClientService>;
|
|
58
|
+
readonly stream: (request: ImageRequest, options?: AwaitOptions) => Stream.Stream<{
|
|
63
59
|
readonly type: "image-partial";
|
|
64
60
|
readonly index: number;
|
|
65
61
|
readonly image: import("./media.js").Asset;
|
|
@@ -67,6 +63,10 @@ export declare const ImageClient: {
|
|
|
67
63
|
readonly type: "image";
|
|
68
64
|
readonly index: number;
|
|
69
65
|
readonly image: import("./media.js").Asset;
|
|
66
|
+
} | {
|
|
67
|
+
readonly type: "generation-progress";
|
|
68
|
+
readonly id: string;
|
|
69
|
+
readonly progress?: number | undefined;
|
|
70
70
|
} | {
|
|
71
71
|
readonly type: "finish";
|
|
72
72
|
readonly usage?: {
|
|
@@ -95,13 +95,10 @@ export declare const ImageClient: {
|
|
|
95
95
|
readonly [x: string]: unknown;
|
|
96
96
|
};
|
|
97
97
|
} | undefined;
|
|
98
|
-
}
|
|
99
|
-
readonly start: (request: ImageRequest
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
readonly
|
|
103
|
-
readonly [x: string]: unknown;
|
|
104
|
-
}>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<ImageResponse>, import("./public.js").AIError, ImageClientService>;
|
|
105
|
-
readonly Service: typeof ImageClientService;
|
|
98
|
+
}, AIError, ImageClientService>;
|
|
99
|
+
readonly start: (request: ImageRequest) => Effect.Effect<ImageJob, AIError, ImageClientService>;
|
|
100
|
+
readonly status: (model: ImageModel, id: string) => Effect.Effect<ImageStatus, AIError, ImageClientService>;
|
|
101
|
+
readonly result: (model: ImageModel, id: string) => Effect.Effect<ImageResponse, AIError, ImageClientService>;
|
|
102
|
+
readonly cancel: (model: ImageModel, id: string) => Effect.Effect<void, AIError, ImageClientService>;
|
|
106
103
|
};
|
|
107
104
|
export {};
|
package/dist/image-client.js
CHANGED
|
@@ -1,19 +1,54 @@
|
|
|
1
|
-
import { Context } from "effect";
|
|
1
|
+
import { Context, Effect, Layer, Schema, Stream } from "effect";
|
|
2
2
|
import { MediaClient } from "./media-client.js";
|
|
3
|
-
import {
|
|
3
|
+
import { RequestExecutor } from "./route/executor.js";
|
|
4
|
+
import { AIError, UnsupportedOperationError } from "./schema/index.js";
|
|
4
5
|
export class ImageClientService extends Context.Service()("@opencode/ImageClient") {
|
|
5
6
|
}
|
|
6
7
|
export const Service = ImageClientService;
|
|
8
|
+
const responseEvents = (response) => [
|
|
9
|
+
...response.images.map((image, index) => ({ type: "image", index, image })),
|
|
10
|
+
{ type: "finish", usage: response.usage, providerMetadata: response.providerMetadata },
|
|
11
|
+
];
|
|
12
|
+
// A queued image route whose token isn't a string is a programmer defect, not a provider error.
|
|
13
|
+
const decodeID = (token) => Schema.decodeUnknownEffect(Schema.String)(token).pipe(Effect.orDie);
|
|
14
|
+
export const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
15
|
+
const executor = yield* RequestExecutor.Service;
|
|
16
|
+
const media = MediaClient.operations(executor.execute, {
|
|
17
|
+
modality: "image",
|
|
18
|
+
responseEvents,
|
|
19
|
+
});
|
|
20
|
+
const attach = (model, id, operation) => {
|
|
21
|
+
if (model.route.kind !== "queued")
|
|
22
|
+
return Effect.fail(MediaClient.notQueued("image", model.route, operation));
|
|
23
|
+
return model.route.attach(model, id, executor.execute);
|
|
24
|
+
};
|
|
25
|
+
return Service.of({
|
|
26
|
+
generate: media.generate,
|
|
27
|
+
stream: media.stream,
|
|
28
|
+
start: (request) => media.start(request).pipe(
|
|
29
|
+
// The token, not the snapshot id, is what `status` and `result` decode; `ImageModel.fromRoute` makes it a string.
|
|
30
|
+
Effect.flatMap((generation) => decodeID(generation.token)), Effect.map((id) => ({ id }))),
|
|
31
|
+
status: (model, id) => attach(model, id, "status").pipe(Effect.flatMap((route) => route.status), Effect.map((snapshot) => ({ status: snapshot.status, reason: snapshot.reason, progress: snapshot.progress }))),
|
|
32
|
+
result: (model, id) => attach(model, id, "result").pipe(Effect.flatMap((route) => route.result)),
|
|
33
|
+
cancel: (model, id) => attach(model, id, "cancel").pipe(Effect.flatMap((route) => route.cancel ??
|
|
34
|
+
Effect.fail(new AIError({
|
|
35
|
+
reason: new UnsupportedOperationError({
|
|
36
|
+
operation: "image.cancel",
|
|
37
|
+
provider: model.provider,
|
|
38
|
+
route: model.route.id,
|
|
39
|
+
message: `${model.provider}/${model.route.id} has no way to cancel an image generation`,
|
|
40
|
+
}),
|
|
41
|
+
})))),
|
|
42
|
+
});
|
|
43
|
+
}));
|
|
7
44
|
export const ImageClient = {
|
|
8
45
|
Service,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
],
|
|
18
|
-
}),
|
|
46
|
+
layer,
|
|
47
|
+
responseEvents,
|
|
48
|
+
generate: (request, options) => Service.use((client) => client.generate(request, options)),
|
|
49
|
+
stream: (request, options) => Stream.unwrap(Service.useSync((client) => client.stream(request, options))),
|
|
50
|
+
start: (request) => Service.use((client) => client.start(request)),
|
|
51
|
+
status: (model, id) => Service.use((client) => client.status(model, id)),
|
|
52
|
+
result: (model, id) => Service.use((client) => client.result(model, id)),
|
|
53
|
+
cancel: (model, id) => Service.use((client) => client.cancel(model, id)),
|
|
19
54
|
};
|
package/dist/image.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema, Stream } from "effect";
|
|
2
|
-
import {
|
|
2
|
+
import { type AwaitOptions, type Reason, type Status } from "./generation.js";
|
|
3
3
|
import { Media } from "./media.js";
|
|
4
4
|
import { MediaModel } from "./media-model.js";
|
|
5
5
|
import { MediaRoute } from "./route/media.js";
|
|
@@ -9,10 +9,13 @@ export type ImageOptions = MediaModel.Options;
|
|
|
9
9
|
export type ImageRoute = MediaRoute.AnyRoute<ImageRequest, ImageEvent, ImageResponse>;
|
|
10
10
|
export declare class ImageModel<Options extends ImageOptions = ImageOptions> extends MediaModel<ImageRoute, Options> {
|
|
11
11
|
protected readonly _ImageModel: void;
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* The number of type arguments selects the kind: `<Options>` for inline or queued, `<Options, Frame, State>` for
|
|
14
|
+
* stream. A queued route's token is the provider's job ID, so `ImageJob.id` is exactly what `status` and `result` take.
|
|
15
|
+
*/
|
|
13
16
|
static fromRoute<Options extends ImageOptions>(route: MediaModel.InlineRouteInput<ImageRequest<ImageModel<Options>>, ImageResponse>, input: MediaRoute.ModelInput): ImageModel<Options>;
|
|
14
17
|
static fromRoute<Options extends ImageOptions, Frame, State>(route: MediaModel.StreamRouteInput<ImageRequest<ImageModel<Options>>, ImageEvent, Frame, State>, input: MediaRoute.ModelInput): ImageModel<Options>;
|
|
15
|
-
static fromRoute<Options extends ImageOptions
|
|
18
|
+
static fromRoute<Options extends ImageOptions>(route: MediaModel.QueuedRouteInput<ImageRequest<ImageModel<Options>>, ImageResponse, string>, input: MediaRoute.ModelInput): ImageModel<Options>;
|
|
16
19
|
}
|
|
17
20
|
export declare const ImageModelSchema: Schema.declare<ImageModel<{
|
|
18
21
|
readonly [x: string]: unknown;
|
|
@@ -39,6 +42,18 @@ export type ImageRequestInput<Model extends ImageModel = ImageModel> = Omit<Imag
|
|
|
39
42
|
readonly images?: ReadonlyArray<Media.Input>;
|
|
40
43
|
readonly providerOptions?: NoInfer<ImageModelOptions<Model>>;
|
|
41
44
|
};
|
|
45
|
+
/** A submitted generation on a queued route. Store `id` with the model to read the job later, from any process. */
|
|
46
|
+
export interface ImageJob {
|
|
47
|
+
/** The provider's job ID. */
|
|
48
|
+
readonly id: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ImageStatus {
|
|
51
|
+
readonly status: Status;
|
|
52
|
+
/** Set when `status` is `error`. */
|
|
53
|
+
readonly reason?: Reason;
|
|
54
|
+
/** 0..1, only when the provider reports progress. */
|
|
55
|
+
readonly progress?: number;
|
|
56
|
+
}
|
|
42
57
|
declare const ImageResponse_base: Schema.Class<ImageResponse, Schema.Struct<{
|
|
43
58
|
readonly images: Schema.$Array<Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
|
|
44
59
|
readonly source: Schema.Union<readonly [Schema.Struct<{
|
|
@@ -189,10 +204,6 @@ export declare const ImageFinishEvent: Schema.Struct<{
|
|
|
189
204
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
190
205
|
}>;
|
|
191
206
|
declare const imageEventTagged: Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
192
|
-
readonly type: Schema.tag<"generation-queued">;
|
|
193
|
-
readonly id: Schema.String;
|
|
194
|
-
readonly position: Schema.optional<Schema.Number>;
|
|
195
|
-
}>, Schema.Struct<{
|
|
196
207
|
readonly type: Schema.tag<"generation-progress">;
|
|
197
208
|
readonly id: Schema.String;
|
|
198
209
|
readonly progress: Schema.optional<Schema.Number>;
|
|
@@ -288,10 +299,6 @@ declare const imageEventTagged: Schema.toTaggedUnion<"type", readonly [Schema.St
|
|
|
288
299
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
289
300
|
}>]>;
|
|
290
301
|
export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
291
|
-
readonly type: Schema.tag<"generation-queued">;
|
|
292
|
-
readonly id: Schema.String;
|
|
293
|
-
readonly position: Schema.optional<Schema.Number>;
|
|
294
|
-
}>, Schema.Struct<{
|
|
295
302
|
readonly type: Schema.tag<"generation-progress">;
|
|
296
303
|
readonly id: Schema.String;
|
|
297
304
|
readonly progress: Schema.optional<Schema.Number>;
|
|
@@ -387,7 +394,7 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
387
394
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
388
395
|
}>]> & {
|
|
389
396
|
readonly tag: "type";
|
|
390
|
-
readonly discriminants: readonly ["generation-
|
|
397
|
+
readonly discriminants: readonly ["generation-progress", "image-partial", "image", "finish"];
|
|
391
398
|
readonly cases: {
|
|
392
399
|
finish: Schema.Struct<{
|
|
393
400
|
readonly type: Schema.tag<"finish">;
|
|
@@ -417,11 +424,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
417
424
|
readonly id: Schema.String;
|
|
418
425
|
readonly progress: Schema.optional<Schema.Number>;
|
|
419
426
|
}>;
|
|
420
|
-
"generation-queued": Schema.Struct<{
|
|
421
|
-
readonly type: Schema.tag<"generation-queued">;
|
|
422
|
-
readonly id: Schema.String;
|
|
423
|
-
readonly position: Schema.optional<Schema.Number>;
|
|
424
|
-
}>;
|
|
425
427
|
image: Schema.Struct<{
|
|
426
428
|
readonly type: Schema.tag<"image">;
|
|
427
429
|
readonly index: Schema.Number;
|
|
@@ -501,10 +503,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
501
503
|
readonly type: "image";
|
|
502
504
|
readonly index: number;
|
|
503
505
|
readonly image: Media.Asset;
|
|
504
|
-
} | {
|
|
505
|
-
readonly type: "generation-queued";
|
|
506
|
-
readonly id: string;
|
|
507
|
-
readonly position?: number | undefined;
|
|
508
506
|
} | {
|
|
509
507
|
readonly type: "generation-progress";
|
|
510
508
|
readonly id: string;
|
|
@@ -549,12 +547,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
549
547
|
readonly image: Media.Asset;
|
|
550
548
|
}, {
|
|
551
549
|
readonly type: Keys;
|
|
552
|
-
}> | Extract<{
|
|
553
|
-
readonly type: "generation-queued";
|
|
554
|
-
readonly id: string;
|
|
555
|
-
readonly position?: number | undefined;
|
|
556
|
-
}, {
|
|
557
|
-
readonly type: Keys;
|
|
558
550
|
}> | Extract<{
|
|
559
551
|
readonly type: "generation-progress";
|
|
560
552
|
readonly id: string;
|
|
@@ -627,11 +619,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
627
619
|
readonly id: string;
|
|
628
620
|
readonly progress?: number | undefined;
|
|
629
621
|
};
|
|
630
|
-
"generation-queued": (u: unknown) => u is {
|
|
631
|
-
readonly type: "generation-queued";
|
|
632
|
-
readonly id: string;
|
|
633
|
-
readonly position?: number | undefined;
|
|
634
|
-
};
|
|
635
622
|
image: (u: unknown) => u is {
|
|
636
623
|
readonly type: "image";
|
|
637
624
|
readonly index: number;
|
|
@@ -644,7 +631,7 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
644
631
|
};
|
|
645
632
|
};
|
|
646
633
|
readonly match: {
|
|
647
|
-
<Handlers extends { [K in "finish" | "generation-progress" | "
|
|
634
|
+
<Handlers extends { [K in "finish" | "generation-progress" | "image" | "image-partial"]: (value: {
|
|
648
635
|
readonly finish: Schema.Struct<{
|
|
649
636
|
readonly type: Schema.tag<"finish">;
|
|
650
637
|
readonly usage: Schema.optional<Schema.Union<readonly [Schema.Struct<{
|
|
@@ -673,11 +660,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
673
660
|
readonly id: Schema.String;
|
|
674
661
|
readonly progress: Schema.optional<Schema.Number>;
|
|
675
662
|
}>;
|
|
676
|
-
readonly "generation-queued": Schema.Struct<{
|
|
677
|
-
readonly type: Schema.tag<"generation-queued">;
|
|
678
|
-
readonly id: Schema.String;
|
|
679
|
-
readonly position: Schema.optional<Schema.Number>;
|
|
680
|
-
}>;
|
|
681
663
|
readonly image: Schema.Struct<{
|
|
682
664
|
readonly type: Schema.tag<"image">;
|
|
683
665
|
readonly index: Schema.Number;
|
|
@@ -756,10 +738,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
756
738
|
readonly type: "image";
|
|
757
739
|
readonly index: number;
|
|
758
740
|
readonly image: Media.Asset;
|
|
759
|
-
} | {
|
|
760
|
-
readonly type: "generation-queued";
|
|
761
|
-
readonly id: string;
|
|
762
|
-
readonly position?: number | undefined;
|
|
763
741
|
} | {
|
|
764
742
|
readonly type: "generation-progress";
|
|
765
743
|
readonly id: string;
|
|
@@ -792,8 +770,8 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
792
770
|
readonly [x: string]: unknown;
|
|
793
771
|
};
|
|
794
772
|
} | undefined;
|
|
795
|
-
}, cases: Handlers): import("effect/Unify").Unify<ReturnType<Handlers["finish" | "generation-progress" | "
|
|
796
|
-
<Handlers extends { [K in "finish" | "generation-progress" | "
|
|
773
|
+
}, cases: Handlers): import("effect/Unify").Unify<ReturnType<Handlers["finish" | "generation-progress" | "image" | "image-partial"]>>;
|
|
774
|
+
<Handlers extends { [K in "finish" | "generation-progress" | "image" | "image-partial"]: (value: {
|
|
797
775
|
readonly finish: Schema.Struct<{
|
|
798
776
|
readonly type: Schema.tag<"finish">;
|
|
799
777
|
readonly usage: Schema.optional<Schema.Union<readonly [Schema.Struct<{
|
|
@@ -822,11 +800,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
822
800
|
readonly id: Schema.String;
|
|
823
801
|
readonly progress: Schema.optional<Schema.Number>;
|
|
824
802
|
}>;
|
|
825
|
-
readonly "generation-queued": Schema.Struct<{
|
|
826
|
-
readonly type: Schema.tag<"generation-queued">;
|
|
827
|
-
readonly id: Schema.String;
|
|
828
|
-
readonly position: Schema.optional<Schema.Number>;
|
|
829
|
-
}>;
|
|
830
803
|
readonly image: Schema.Struct<{
|
|
831
804
|
readonly type: Schema.tag<"image">;
|
|
832
805
|
readonly index: Schema.Number;
|
|
@@ -905,10 +878,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
905
878
|
readonly type: "image";
|
|
906
879
|
readonly index: number;
|
|
907
880
|
readonly image: Media.Asset;
|
|
908
|
-
} | {
|
|
909
|
-
readonly type: "generation-queued";
|
|
910
|
-
readonly id: string;
|
|
911
|
-
readonly position?: number | undefined;
|
|
912
881
|
} | {
|
|
913
882
|
readonly type: "generation-progress";
|
|
914
883
|
readonly id: string;
|
|
@@ -941,7 +910,7 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
941
910
|
readonly [x: string]: unknown;
|
|
942
911
|
};
|
|
943
912
|
} | undefined;
|
|
944
|
-
}) => import("effect/Unify").Unify<ReturnType<Handlers["finish" | "generation-progress" | "
|
|
913
|
+
}) => import("effect/Unify").Unify<ReturnType<Handlers["finish" | "generation-progress" | "image" | "image-partial"]>>;
|
|
945
914
|
};
|
|
946
915
|
readonly matchOrElse: {
|
|
947
916
|
<Handlers, OrElse>(value: {
|
|
@@ -952,10 +921,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
952
921
|
readonly type: "image";
|
|
953
922
|
readonly index: number;
|
|
954
923
|
readonly image: Media.Asset;
|
|
955
|
-
} | {
|
|
956
|
-
readonly type: "generation-queued";
|
|
957
|
-
readonly id: string;
|
|
958
|
-
readonly position?: number | undefined;
|
|
959
924
|
} | {
|
|
960
925
|
readonly type: "generation-progress";
|
|
961
926
|
readonly id: string;
|
|
@@ -1023,11 +988,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1023
988
|
readonly id: string;
|
|
1024
989
|
readonly progress?: number | undefined;
|
|
1025
990
|
}) => any) | undefined;
|
|
1026
|
-
readonly "generation-queued"?: ((value: {
|
|
1027
|
-
readonly type: "generation-queued";
|
|
1028
|
-
readonly id: string;
|
|
1029
|
-
readonly position?: number | undefined;
|
|
1030
|
-
}) => any) | undefined;
|
|
1031
991
|
readonly image?: ((value: {
|
|
1032
992
|
readonly type: "image";
|
|
1033
993
|
readonly index: number;
|
|
@@ -1038,7 +998,7 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1038
998
|
readonly index: number;
|
|
1039
999
|
readonly image: Media.Asset;
|
|
1040
1000
|
}) => any) | undefined;
|
|
1041
|
-
} & (Exclude<keyof Handlers, "finish" | "generation-progress" | "
|
|
1001
|
+
} & (Exclude<keyof Handlers, "finish" | "generation-progress" | "image" | "image-partial"> extends never ? unknown : never), orElse: OrElse & ((value: Exclude<{
|
|
1042
1002
|
readonly type: "image-partial";
|
|
1043
1003
|
readonly index: number;
|
|
1044
1004
|
readonly image: Media.Asset;
|
|
@@ -1050,12 +1010,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1050
1010
|
readonly image: Media.Asset;
|
|
1051
1011
|
}, {
|
|
1052
1012
|
readonly type: keyof Handlers;
|
|
1053
|
-
}> | Exclude<{
|
|
1054
|
-
readonly type: "generation-queued";
|
|
1055
|
-
readonly id: string;
|
|
1056
|
-
readonly position?: number | undefined;
|
|
1057
|
-
}, {
|
|
1058
|
-
readonly type: keyof Handlers;
|
|
1059
1013
|
}> | Exclude<{
|
|
1060
1014
|
readonly type: "generation-progress";
|
|
1061
1015
|
readonly id: string;
|
|
@@ -1128,11 +1082,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1128
1082
|
readonly id: string;
|
|
1129
1083
|
readonly progress?: number | undefined;
|
|
1130
1084
|
}) => any) | undefined;
|
|
1131
|
-
readonly "generation-queued"?: ((value: {
|
|
1132
|
-
readonly type: "generation-queued";
|
|
1133
|
-
readonly id: string;
|
|
1134
|
-
readonly position?: number | undefined;
|
|
1135
|
-
}) => any) | undefined;
|
|
1136
1085
|
readonly image?: ((value: {
|
|
1137
1086
|
readonly type: "image";
|
|
1138
1087
|
readonly index: number;
|
|
@@ -1143,7 +1092,7 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1143
1092
|
readonly index: number;
|
|
1144
1093
|
readonly image: Media.Asset;
|
|
1145
1094
|
}) => any) | undefined;
|
|
1146
|
-
} & (Exclude<keyof Handlers, "finish" | "generation-progress" | "
|
|
1095
|
+
} & (Exclude<keyof Handlers, "finish" | "generation-progress" | "image" | "image-partial"> extends never ? unknown : never), orElse: OrElse & ((value: Exclude<{
|
|
1147
1096
|
readonly type: "image-partial";
|
|
1148
1097
|
readonly index: number;
|
|
1149
1098
|
readonly image: Media.Asset;
|
|
@@ -1155,12 +1104,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1155
1104
|
readonly image: Media.Asset;
|
|
1156
1105
|
}, {
|
|
1157
1106
|
readonly type: keyof Handlers;
|
|
1158
|
-
}> | Exclude<{
|
|
1159
|
-
readonly type: "generation-queued";
|
|
1160
|
-
readonly id: string;
|
|
1161
|
-
readonly position?: number | undefined;
|
|
1162
|
-
}, {
|
|
1163
|
-
readonly type: keyof Handlers;
|
|
1164
1107
|
}> | Exclude<{
|
|
1165
1108
|
readonly type: "generation-progress";
|
|
1166
1109
|
readonly id: string;
|
|
@@ -1205,10 +1148,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1205
1148
|
readonly type: "image";
|
|
1206
1149
|
readonly index: number;
|
|
1207
1150
|
readonly image: Media.Asset;
|
|
1208
|
-
} | {
|
|
1209
|
-
readonly type: "generation-queued";
|
|
1210
|
-
readonly id: string;
|
|
1211
|
-
readonly position?: number | undefined;
|
|
1212
1151
|
} | {
|
|
1213
1152
|
readonly type: "generation-progress";
|
|
1214
1153
|
readonly id: string;
|
|
@@ -1245,11 +1184,6 @@ export declare const ImageEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1245
1184
|
};
|
|
1246
1185
|
} & {
|
|
1247
1186
|
is: {
|
|
1248
|
-
generationQueued: (u: unknown) => u is {
|
|
1249
|
-
readonly type: "generation-queued";
|
|
1250
|
-
readonly id: string;
|
|
1251
|
-
readonly position?: number | undefined;
|
|
1252
|
-
};
|
|
1253
1187
|
generationProgress: (u: unknown) => u is {
|
|
1254
1188
|
readonly type: "generation-progress";
|
|
1255
1189
|
readonly id: string;
|
|
@@ -1301,14 +1235,21 @@ export type ImageEvent = Schema.Schema.Type<typeof imageEventTagged>;
|
|
|
1301
1235
|
export declare const request: <const Model extends ImageModel>(input: ImageRequestInput<Model>) => ImageRequest<Model>;
|
|
1302
1236
|
export declare function generate<const Model extends ImageModel>(input: ImageRequestInput<Model>, options?: AwaitOptions): Effect.Effect<ImageResponse, AIError, Service>;
|
|
1303
1237
|
export declare function stream<const Model extends ImageModel>(input: ImageRequestInput<Model>, options?: AwaitOptions): Stream.Stream<ImageEvent, AIError, Service>;
|
|
1304
|
-
/** Inline and
|
|
1305
|
-
export declare function start<const Model extends ImageModel>(input: ImageRequestInput<Model>): Effect.Effect<
|
|
1306
|
-
|
|
1238
|
+
/** Submit a generation and return at once; nothing polls. Inline and stream routes fail with `UnsupportedOperation`. */
|
|
1239
|
+
export declare function start<const Model extends ImageModel>(input: ImageRequestInput<Model>): Effect.Effect<ImageJob, AIError, Service>;
|
|
1240
|
+
/** One status read for a job ID. */
|
|
1241
|
+
export declare const status: (model: ImageModel, id: string) => Effect.Effect<ImageStatus, AIError, Service>;
|
|
1242
|
+
/** The finished images; fails while the job is still running, or with the provider's reason when it failed. */
|
|
1243
|
+
export declare const result: (model: ImageModel, id: string) => Effect.Effect<ImageResponse, AIError, Service>;
|
|
1244
|
+
/** Ask the provider to stop the job; fails with `UnsupportedOperation` when the provider has no cancel call. */
|
|
1245
|
+
export declare const cancel: (model: ImageModel, id: string) => Effect.Effect<void, AIError, Service>;
|
|
1307
1246
|
export declare const Image: {
|
|
1308
1247
|
readonly request: typeof request;
|
|
1309
1248
|
readonly generate: typeof generate;
|
|
1310
1249
|
readonly stream: typeof stream;
|
|
1311
1250
|
readonly start: typeof start;
|
|
1312
|
-
readonly
|
|
1251
|
+
readonly status: typeof status;
|
|
1252
|
+
readonly result: typeof result;
|
|
1253
|
+
readonly cancel: typeof cancel;
|
|
1313
1254
|
};
|
|
1314
1255
|
export {};
|
package/dist/image.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema, Stream } from "effect";
|
|
2
|
-
import {
|
|
2
|
+
import { ProgressEvent } from "./generation.js";
|
|
3
3
|
import { Media } from "./media.js";
|
|
4
4
|
import { MediaModel, composeRoute, tryRequest } from "./media-model.js";
|
|
5
5
|
import { MediaRoute } from "./route/media.js";
|
|
@@ -29,9 +29,6 @@ const ImageRequestSchema = Schema.Struct({
|
|
|
29
29
|
resolution: Schema.optional(Schema.String),
|
|
30
30
|
providerOptions: Schema.optional(ProviderOptions),
|
|
31
31
|
});
|
|
32
|
-
// ---------------------------------------------------------------------------
|
|
33
|
-
// Response and events
|
|
34
|
-
// ---------------------------------------------------------------------------
|
|
35
32
|
export class ImageResponse extends Schema.Class("Image.Response")({
|
|
36
33
|
images: Schema.Array(Media.AssetSchema),
|
|
37
34
|
usage: Schema.optional(MediaUsage),
|
|
@@ -54,16 +51,9 @@ export const ImageFinishEvent = Schema.Struct({
|
|
|
54
51
|
usage: Schema.optional(MediaUsage),
|
|
55
52
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
56
53
|
}).annotate({ identifier: "Image.Event.Finish" });
|
|
57
|
-
const imageEventTagged = Schema.Union([
|
|
58
|
-
QueuedEvent,
|
|
59
|
-
ProgressEvent,
|
|
60
|
-
ImagePartialEvent,
|
|
61
|
-
ImageOutputEvent,
|
|
62
|
-
ImageFinishEvent,
|
|
63
|
-
]).pipe(Schema.toTaggedUnion("type"));
|
|
54
|
+
const imageEventTagged = Schema.Union([ProgressEvent, ImagePartialEvent, ImageOutputEvent, ImageFinishEvent]).pipe(Schema.toTaggedUnion("type"));
|
|
64
55
|
export const ImageEvent = Object.assign(imageEventTagged, {
|
|
65
56
|
is: {
|
|
66
|
-
generationQueued: imageEventTagged.guards["generation-queued"],
|
|
67
57
|
generationProgress: imageEventTagged.guards["generation-progress"],
|
|
68
58
|
imagePartial: imageEventTagged.guards["image-partial"],
|
|
69
59
|
image: imageEventTagged.guards.image,
|
|
@@ -104,11 +94,18 @@ export function stream(input, options) {
|
|
|
104
94
|
export function start(input) {
|
|
105
95
|
return requestEffect(input).pipe(Effect.flatMap((request) => ImageClient.start(request)));
|
|
106
96
|
}
|
|
107
|
-
|
|
97
|
+
/** One status read for a job ID. */
|
|
98
|
+
export const status = (model, id) => ImageClient.status(model, id);
|
|
99
|
+
/** The finished images; fails while the job is still running, or with the provider's reason when it failed. */
|
|
100
|
+
export const result = (model, id) => ImageClient.result(model, id);
|
|
101
|
+
/** Ask the provider to stop the job; fails with `UnsupportedOperation` when the provider has no cancel call. */
|
|
102
|
+
export const cancel = (model, id) => ImageClient.cancel(model, id);
|
|
108
103
|
export const Image = {
|
|
109
104
|
request,
|
|
110
105
|
generate,
|
|
111
106
|
stream,
|
|
112
107
|
start,
|
|
113
|
-
|
|
108
|
+
status,
|
|
109
|
+
result,
|
|
110
|
+
cancel,
|
|
114
111
|
};
|