@opencode/ai 2.2.7 → 2.3.0

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.
Files changed (90) hide show
  1. package/README.md +114 -96
  2. package/dist/effect.d.ts +8 -7
  3. package/dist/effect.js +2 -1
  4. package/dist/experimental.d.ts +0 -4
  5. package/dist/experimental.js +0 -3
  6. package/dist/image-client.d.ts +1 -1
  7. package/dist/image-client.js +2 -6
  8. package/dist/index.d.ts +11 -48
  9. package/dist/index.js +30 -13
  10. package/dist/media-model.d.ts +2 -0
  11. package/dist/media-model.js +3 -1
  12. package/dist/media.d.ts +9 -3
  13. package/dist/media.js +27 -7
  14. package/dist/protocols/google-decisions.d.ts +13 -0
  15. package/dist/protocols/google-decisions.js +133 -0
  16. package/dist/protocols/google-interactions-video.d.ts +43 -0
  17. package/dist/protocols/google-interactions-video.js +186 -0
  18. package/dist/protocols/google-interactions.d.ts +14 -1
  19. package/dist/protocols/google-interactions.js +1 -1
  20. package/dist/protocols/index.d.ts +1 -0
  21. package/dist/protocols/index.js +1 -0
  22. package/dist/protocols/minimax-video.d.ts +54 -0
  23. package/dist/protocols/minimax-video.js +292 -0
  24. package/dist/protocols/openrouter-video.d.ts +41 -0
  25. package/dist/protocols/openrouter-video.js +138 -0
  26. package/dist/protocols/seedance-video.d.ts +50 -0
  27. package/dist/protocols/seedance-video.js +216 -0
  28. package/dist/protocols/system-one.d.ts +45 -1
  29. package/dist/protocols/system-one.js +42 -7
  30. package/dist/protocols/utils/responses-compaction.js +1 -1
  31. package/dist/protocols/xai-video.d.ts +8 -2
  32. package/dist/protocols/xai-video.js +20 -15
  33. package/dist/provider-error.js +7 -1
  34. package/dist/providers/byteplus/videos.d.ts +2 -0
  35. package/dist/providers/byteplus/videos.js +1 -0
  36. package/dist/providers/byteplus.d.ts +26 -0
  37. package/dist/providers/byteplus.js +21 -0
  38. package/dist/providers/google/decisions.d.ts +2 -0
  39. package/dist/providers/google/decisions.js +1 -0
  40. package/dist/providers/google/videos.d.ts +2 -0
  41. package/dist/providers/google/videos.js +1 -0
  42. package/dist/providers/google.d.ts +11 -4
  43. package/dist/providers/google.js +13 -3
  44. package/dist/providers/index.d.ts +2 -1
  45. package/dist/providers/index.js +2 -1
  46. package/dist/providers/minimax/videos.d.ts +3 -0
  47. package/dist/providers/minimax/videos.js +1 -0
  48. package/dist/providers/minimax.d.ts +6 -1
  49. package/dist/providers/minimax.js +10 -1
  50. package/dist/providers/openai-compatible/decisions.d.ts +2 -0
  51. package/dist/providers/openai-compatible/decisions.js +1 -0
  52. package/dist/providers/openai-compatible.d.ts +2 -0
  53. package/dist/providers/openai-compatible.js +14 -0
  54. package/dist/providers/openrouter/videos.d.ts +2 -0
  55. package/dist/providers/openrouter/videos.js +1 -0
  56. package/dist/providers/openrouter.d.ts +5 -0
  57. package/dist/providers/openrouter.js +8 -0
  58. package/dist/providers/volcengine/videos.d.ts +2 -0
  59. package/dist/providers/volcengine/videos.js +1 -0
  60. package/dist/providers/volcengine.d.ts +26 -0
  61. package/dist/providers/volcengine.js +21 -0
  62. package/dist/public.d.ts +2 -0
  63. package/dist/public.js +1 -0
  64. package/dist/route/executor-service.d.ts +6 -0
  65. package/dist/route/executor-service.js +7 -0
  66. package/dist/route/executor.d.ts +7 -1
  67. package/dist/route/executor.js +7 -2
  68. package/dist/route/media-protocol.d.ts +12 -11
  69. package/dist/route/media.d.ts +2 -0
  70. package/dist/route/media.js +31 -22
  71. package/dist/route/transport/http.js +1 -1
  72. package/dist/schema/messages.d.ts +1 -1
  73. package/dist/schema/messages.js +1 -5
  74. package/dist/schema/options.d.ts +8 -0
  75. package/dist/schema/options.js +1 -0
  76. package/dist/speech-client.d.ts +1 -1
  77. package/dist/speech-client.js +4 -4
  78. package/dist/transcription-client.d.ts +1 -1
  79. package/dist/transcription-client.js +1 -2
  80. package/dist/video-client.d.ts +16 -84
  81. package/dist/video-client.js +28 -13
  82. package/dist/video.d.ts +56 -1072
  83. package/dist/video.js +28 -65
  84. package/package.json +55 -7
  85. package/dist/protocols/google-video.d.ts +0 -26
  86. package/dist/protocols/google-video.js +0 -146
  87. package/dist/protocols/runway-video.d.ts +0 -38
  88. package/dist/protocols/runway-video.js +0 -141
  89. package/dist/providers/runway.d.ts +0 -20
  90. package/dist/providers/runway.js +0 -17
@@ -46,6 +46,8 @@ export interface QueuedRoute<Request extends MediaRequest, Response> {
46
46
  readonly start: (request: Request, execute: Execute) => Effect.Effect<Generation<Response>, AIError>;
47
47
  /** Rebuild a handle from a persisted `Generation.token`; fails typed when the token is not this route's. */
48
48
  readonly resume: (model: MediaRequest["model"], token: unknown, execute: Execute) => Effect.Effect<Generation<Response>, AIError>;
49
+ /** The status, result and cancel operations for a persisted token, without reading its status first. */
50
+ readonly attach: (model: MediaRequest["model"], token: unknown, execute: Execute) => Effect.Effect<Generation<Response>["route"], AIError>;
49
51
  }
50
52
  /** One request whose response parses into events; `generate` runs the same stream and collects it. */
51
53
  export interface StreamRoute<Request extends MediaRequest, Event, Response> {
@@ -4,7 +4,7 @@ import { Auth } from "./auth.js";
4
4
  import { Endpoint } from "./endpoint.js";
5
5
  import { RequestExecutor } from "./executor.js";
6
6
  import { MediaProtocol } from "./media-protocol.js";
7
- import { Generation, isTerminal } from "../generation.js";
7
+ import { Generation } from "../generation.js";
8
8
  import { isRetryable } from "../provider-error.js";
9
9
  import { AIError, AIErrorReason, InvalidRequestError, ProviderID, UnsupportedOperationError, mergeProviderOptions, mergeTransport, } from "../schema/index.js";
10
10
  import { encodeJson } from "../utils/json.js";
@@ -57,18 +57,16 @@ export const queued = (input) => {
57
57
  const generationRoute = (token, exchange, execute) => {
58
58
  // Only the GET exchange retries: a decoded terminal failure (`output.ended`) can be a `ProviderInternal` too, and
59
59
  // re-reading it would spin until the caller's deadline.
60
- const poll = (operation) => transport.call("GET", operation.path(token), exchange, execute).pipe(Effect.retry({ schedule: READ_RETRY, while: isRetryable }), Effect.flatMap((sent) => operation.decode(sent.response, { token, auth: sent.auth })));
60
+ const get = (path) => transport.call("GET", path, exchange, execute).pipe(Effect.retry({ schedule: READ_RETRY, while: isRetryable }), Effect.map((sent) => sent.response));
61
+ const poll = (operation) => get(operation.path(token)).pipe(Effect.flatMap((response) => operation.decode(response, { token, get, headers: (url) => transport.headers(url, exchange) })));
61
62
  const status = poll(protocol.status);
62
63
  const cancel = protocol.cancel;
63
- const send = cancel === undefined
64
- ? undefined
65
- : transport.call(cancel.method, cancel.path(token), exchange, execute).pipe(Effect.asVoid);
66
64
  return {
67
65
  status,
68
66
  result: poll(protocol.result),
69
- cancel: send !== undefined && cancel?.activeOnly
70
- ? status.pipe(Effect.flatMap((snapshot) => (isTerminal(snapshot.status) ? Effect.void : send)))
71
- : send,
67
+ cancel: cancel === undefined
68
+ ? undefined
69
+ : transport.call(cancel.method, cancel.path(token), exchange, execute).pipe(Effect.asVoid),
72
70
  };
73
71
  };
74
72
  const start = Effect.fn("MediaRoute.start")(function* (request, execute) {
@@ -77,17 +75,19 @@ export const queued = (input) => {
77
75
  const route = generationRoute(started.token, submitted.exchange, execute);
78
76
  return new Generation(route, encodeToken(started.token), started.snapshot);
79
77
  });
78
+ const decode = (raw) => decodeToken(raw).pipe(Effect.mapError((cause) => new AIError({
79
+ reason: new InvalidRequestError({
80
+ message: `${protocol.id} cannot resume a generation from this token`,
81
+ cause,
82
+ }),
83
+ })));
84
+ const attach = (model, raw, execute) => decode(raw).pipe(Effect.map((token) => generationRoute(token, transport.exchange(model), execute)));
80
85
  const resume = Effect.fn("MediaRoute.resume")(function* (model, raw, execute) {
81
- const token = yield* decodeToken(raw).pipe(Effect.mapError((cause) => new AIError({
82
- reason: new InvalidRequestError({
83
- message: `${protocol.id} cannot resume a generation from this token`,
84
- cause,
85
- }),
86
- })));
86
+ const token = yield* decode(raw);
87
87
  const route = generationRoute(token, transport.exchange(model), execute);
88
88
  return new Generation(route, encodeToken(token), yield* route.status);
89
89
  });
90
- return { kind: "queued", id: protocol.id, provider: protocol.provider, protocol: protocol.id, start, resume };
90
+ return { kind: "queued", id: protocol.id, provider: protocol.provider, protocol: protocol.id, start, resume, attach };
91
91
  };
92
92
  /** Compose a streaming media protocol; `generate` runs the same stream in `generate` mode and folds it with `collect`. */
93
93
  export const stream = (input) => {
@@ -129,7 +129,6 @@ export const stream = (input) => {
129
129
  const makeTransport = (input) => {
130
130
  const authorize = Auth.toEffect(input.auth);
131
131
  const baseURL = (path) => new URL(`${Endpoint.trimBaseUrl(input.endpoint.baseURL ?? "")}${path}`);
132
- /** `auth` is only what `Auth` added or changed, never untouched deployment headers. */
133
132
  const send = Effect.fn("MediaRoute.send")(function* (call, fetch, execute) {
134
133
  const encoded = encode(call.body, call.headers);
135
134
  const url = call.url.toString();
@@ -140,11 +139,8 @@ const makeTransport = (input) => {
140
139
  body: encoded.text,
141
140
  headers: encoded.headers,
142
141
  });
143
- const response = yield* execute(encoded.apply(HttpClientRequest.make(call.method)(url).pipe(HttpClientRequest.setHeaders(headers))), RequestExecutor.withFetch(fetch));
144
- return {
145
- response,
146
- auth: Object.fromEntries(Object.entries(headers).filter(([key, value]) => encoded.headers[key] !== value)),
147
- };
142
+ const response = yield* RequestExecutor.withTls(execute, call.request.http?.tls)(encoded.apply(HttpClientRequest.make(call.method)(url).pipe(HttpClientRequest.setHeaders(headers))), RequestExecutor.withFetch(fetch));
143
+ return { response };
148
144
  });
149
145
  return {
150
146
  /** Route and model overlays; `start` additionally merges the request's own. */
@@ -158,7 +154,7 @@ const makeTransport = (input) => {
158
154
  const headers = Headers.fromInput(merged);
159
155
  const prepared = protocol.prepare === undefined
160
156
  ? request
161
- : yield* protocol.prepare(request, (path, body) => send({ method: "POST", url: baseURL(path), headers, request, body }, request.fetch, execute).pipe(Effect.map((sent) => sent.response)));
157
+ : yield* protocol.prepare(request, (path, body) => send({ method: "POST", url: baseURL(path), headers, request: { ...request, http }, body }, request.fetch, execute).pipe(Effect.map((sent) => sent.response)));
162
158
  // Sanitize after merging so model-level overlays are covered; the model value is restored, not sanitized.
163
159
  const resolved = {
164
160
  ...sanitizeSurrogates({ ...prepared, headers: merged, http, providerOptions }),
@@ -169,6 +165,19 @@ const makeTransport = (input) => {
169
165
  const sent = yield* send({ method: "POST", url, headers, request: resolved, body }, request.fetch, execute);
170
166
  return { response: sent.response, context: { request: resolved, body }, exchange };
171
167
  }),
168
+ /**
169
+ * The headers a follow-up GET of `url` sends, for result URLs that only download with the same credentials. A URL
170
+ * on another origin than the route's base URL gets none, so credentials never leave the provider's host.
171
+ */
172
+ headers: (url, exchange) => URL.canParse(url) && new URL(url).origin === baseURL("").origin
173
+ ? authorize({
174
+ request: { http: exchange.http },
175
+ method: "GET",
176
+ url,
177
+ body: "",
178
+ headers: Headers.fromInput(exchange.headers),
179
+ }).pipe(Effect.map((headers) => ({ ...headers })))
180
+ : Effect.succeed({}),
172
181
  /** Bodiless follow-up call (status, result, cancel) with the same auth and headers as `submit`. */
173
182
  call: (method, path, exchange, execute) => {
174
183
  // Provider-issued absolute URLs are used as-is; everything else resolves against the base.
@@ -66,7 +66,7 @@ export const httpJson = (input) => ({
66
66
  const limits = timeoutConfig(request.timeout);
67
67
  // Unlike the header and chunk limits, the whole-request budget has no default.
68
68
  const total = limits.total ? Duration.millis(limits.total) : Duration.infinity;
69
- const response = yield* runtime.http.execute(prepared.request, prepared.middleware).pipe(Effect.timeoutOrElse({
69
+ const response = yield* RequestExecutor.withTls(runtime.http.execute, request.http?.tls)(prepared.request, prepared.middleware).pipe(Effect.timeoutOrElse({
70
70
  duration: Duration.min(timeoutDuration(limits.headers), total),
71
71
  orElse: () => timeout("request", "Timed out waiting for response headers"),
72
72
  }));
@@ -747,7 +747,7 @@ export declare const Freeform: Schema.Union<readonly [Schema.Struct<{
747
747
  readonly type: Schema.Literal<"lark">;
748
748
  readonly grammar: Schema.String;
749
749
  }>]>;
750
- export type Freeform = Schema.Schema.Type<typeof Freeform>;
750
+ export type Freeform = Tool.Freeform;
751
751
  declare const toolDefinitionFields: {
752
752
  name: Schema.String;
753
753
  description: Schema.String;
@@ -241,11 +241,7 @@ export const Message = withStatics(messageSchema, {
241
241
  * Raw-text wire encoding for a tool with exactly one required string parameter. Models that accept the format
242
242
  * write that parameter's value directly instead of JSON arguments; calls still decode to the normal object input.
243
243
  */
244
- export const Freeform = Schema.Union([
245
- Schema.Struct({ type: Schema.Literal("text") }),
246
- Schema.Struct({ type: Schema.Literal("regex"), pattern: Schema.String }),
247
- Schema.Struct({ type: Schema.Literal("lark"), grammar: Schema.String }),
248
- ]).annotate({ identifier: "LLM.Freeform" });
244
+ export const Freeform = Tool.Freeform;
249
245
  const toolDefinitionFields = {
250
246
  name: Schema.String,
251
247
  description: Schema.String,
@@ -29,6 +29,14 @@ export interface HttpOptions {
29
29
  readonly body?: Record<string, unknown>;
30
30
  /** Compression for JSON request bodies. Only set it for endpoints known to decode it. */
31
31
  readonly encoding?: RequestEncoding;
32
+ /** Client certificate presented to HTTPS endpoints that request one (mutual TLS). */
33
+ readonly tls?: ClientTls;
34
+ }
35
+ /** PEM client certificate and private key, with the passphrase of an encrypted key. */
36
+ export interface ClientTls {
37
+ readonly cert: string;
38
+ readonly key: string;
39
+ readonly passphrase?: string;
32
40
  }
33
41
  /** Per-phase time limits in milliseconds. */
34
42
  export interface TimeoutConfig {
@@ -61,6 +61,7 @@ export const mergeTransport = (...items) => {
61
61
  query: mergeStringRecords(...http.map((item) => item?.query)),
62
62
  body: mergeJsonRecords(...http.map((item) => item?.body)),
63
63
  encoding: last(http.map((item) => item?.encoding)),
64
+ tls: last(http.map((item) => item?.tls)),
64
65
  }),
65
66
  };
66
67
  };
@@ -1,6 +1,6 @@
1
1
  import { Context } from "effect";
2
2
  import { MediaClient } from "./media-client.js";
3
- import { type SpeechEvent, type SpeechRequest, type SpeechResponse } from "./speech.js";
3
+ import type { SpeechEvent, SpeechRequest, SpeechResponse } from "./speech.js";
4
4
  export type Interface = MediaClient.Interface<SpeechRequest, SpeechEvent, SpeechResponse>;
5
5
  declare const SpeechClientService_base: Context.ServiceClass<SpeechClientService, "@opencode/SpeechClient", Interface>;
6
6
  export declare class SpeechClientService extends SpeechClientService_base {
@@ -1,6 +1,5 @@
1
1
  import { Context } from "effect";
2
2
  import { MediaClient } from "./media-client.js";
3
- import { SpeechTimestampsEvent, SpeechFinishEvent, } from "./speech.js";
4
3
  export class SpeechClientService extends Context.Service()("@opencode/SpeechClient") {
5
4
  }
6
5
  export const Service = SpeechClientService;
@@ -9,12 +8,13 @@ export const SpeechClient = {
9
8
  ...MediaClient.make(Service, {
10
9
  modality: "speech",
11
10
  responseEvents: (response) => [
12
- ...(response.timestamps === undefined ? [] : [SpeechTimestampsEvent.make({ items: response.timestamps })]),
13
- SpeechFinishEvent.make({
11
+ ...(response.timestamps === undefined ? [] : [{ type: "timestamps", items: response.timestamps }]),
12
+ {
13
+ type: "finish",
14
14
  audio: response.audio,
15
15
  usage: response.usage,
16
16
  providerMetadata: response.providerMetadata,
17
- }),
17
+ },
18
18
  ],
19
19
  }),
20
20
  };
@@ -1,6 +1,6 @@
1
1
  import { Context } from "effect";
2
2
  import { MediaClient } from "./media-client.js";
3
- import { type TranscriptionEvent, type TranscriptionRequest, type TranscriptionResponse } from "./transcription.js";
3
+ import type { TranscriptionEvent, TranscriptionRequest, TranscriptionResponse } from "./transcription.js";
4
4
  export type Interface = MediaClient.Interface<TranscriptionRequest, TranscriptionEvent, TranscriptionResponse>;
5
5
  declare const TranscriptionClientService_base: Context.ServiceClass<TranscriptionClientService, "@opencode/TranscriptionClient", Interface>;
6
6
  export declare class TranscriptionClientService extends TranscriptionClientService_base {
@@ -1,6 +1,5 @@
1
1
  import { Context } from "effect";
2
2
  import { MediaClient } from "./media-client.js";
3
- import { TranscriptionFinishEvent, } from "./transcription.js";
4
3
  export class TranscriptionClientService extends Context.Service()("@opencode/TranscriptionClient") {
5
4
  }
6
5
  export const Service = TranscriptionClientService;
@@ -8,6 +7,6 @@ export const TranscriptionClient = {
8
7
  Service,
9
8
  ...MediaClient.make(Service, {
10
9
  modality: "transcription",
11
- responseEvents: (response) => [TranscriptionFinishEvent.make({ ...response })],
10
+ responseEvents: (response) => [{ type: "finish", ...response }],
12
11
  }),
13
12
  };
@@ -1,93 +1,25 @@
1
- import { Context } from "effect";
2
- import { MediaClient } from "./media-client.js";
3
- import { type VideoEvent, type VideoRequest, type VideoResponse } from "./video.js";
4
- export type Interface = MediaClient.Interface<VideoRequest, VideoEvent, VideoResponse>;
1
+ import { Context, Effect, Layer } from "effect";
2
+ import { RequestExecutor } from "./route/executor.js";
3
+ import { AIError } from "./schema/index.js";
4
+ import type { VideoJob, VideoModel, VideoRequest, VideoResponse, VideoStatus } from "./video.js";
5
+ export interface Interface {
6
+ readonly start: (request: VideoRequest) => Effect.Effect<VideoJob, AIError>;
7
+ readonly status: (model: VideoModel, token: unknown) => Effect.Effect<VideoStatus, AIError>;
8
+ readonly result: (model: VideoModel, token: unknown) => Effect.Effect<VideoResponse, AIError>;
9
+ readonly cancel: (model: VideoModel, token: unknown) => Effect.Effect<void, AIError>;
10
+ }
5
11
  declare const VideoClientService_base: Context.ServiceClass<VideoClientService, "@opencode/VideoClient", Interface>;
6
12
  export declare class VideoClientService extends VideoClientService_base {
7
13
  }
8
14
  export declare const Service: typeof VideoClientService;
9
15
  export type Service = VideoClientService;
16
+ export declare const layer: Layer.Layer<VideoClientService, never, RequestExecutor.RequestExecutorService>;
10
17
  export declare const VideoClient: {
11
- readonly responseEvents: (response: VideoResponse) => readonly ({
12
- readonly type: "video";
13
- readonly index: number;
14
- readonly video: import("./media.js").Asset;
15
- } | {
16
- readonly type: "generation-queued";
17
- readonly id: string;
18
- readonly position?: number | undefined;
19
- } | {
20
- readonly type: "generation-progress";
21
- readonly id: string;
22
- readonly progress?: number | undefined;
23
- } | {
24
- readonly type: "finish";
25
- readonly usage?: {
26
- readonly type: "seconds";
27
- readonly seconds: number;
28
- } | {
29
- readonly type: "characters";
30
- readonly characters: number;
31
- } | {
32
- readonly type: "credits";
33
- readonly credits: number;
34
- } | {
35
- readonly type: "compute";
36
- readonly seconds: number;
37
- } | {
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;
44
- } | undefined;
45
- } | undefined;
46
- readonly providerMetadata?: {
47
- readonly [x: string]: {
48
- readonly [x: string]: unknown;
49
- };
50
- } | undefined;
51
- })[];
52
- readonly layer: import("effect/Layer").Layer<VideoClientService, never, import("./route.js").RequestExecutorService>;
53
- readonly generate: (request: VideoRequest, options?: import("./generation.js").AwaitOptions) => import("effect/Effect").Effect<VideoResponse, import("./public.js").AIError, VideoClientService>;
54
- readonly stream: (request: VideoRequest, options?: import("./generation.js").AwaitOptions) => import("effect/Stream").Stream<{
55
- readonly type: "video";
56
- readonly index: number;
57
- readonly video: import("./media.js").Asset;
58
- } | {
59
- readonly type: "finish";
60
- readonly usage?: {
61
- readonly type: "seconds";
62
- readonly seconds: number;
63
- } | {
64
- readonly type: "characters";
65
- readonly characters: number;
66
- } | {
67
- readonly type: "credits";
68
- readonly credits: number;
69
- } | {
70
- readonly type: "compute";
71
- readonly seconds: number;
72
- } | {
73
- readonly type: "tokens";
74
- readonly input?: number | undefined;
75
- readonly output?: number | undefined;
76
- readonly total?: number | undefined;
77
- readonly details?: {
78
- readonly [x: string]: unknown;
79
- } | undefined;
80
- } | undefined;
81
- readonly providerMetadata?: {
82
- readonly [x: string]: {
83
- readonly [x: string]: unknown;
84
- };
85
- } | undefined;
86
- } | import("./generation.js").Observation, import("./public.js").AIError, VideoClientService>;
87
- readonly start: (request: VideoRequest) => import("effect/Effect").Effect<import("./generation.js").Generation<VideoResponse>, import("./public.js").AIError, VideoClientService>;
88
- readonly resume: (model: import("./video.js").VideoModel<{
89
- readonly [x: string]: unknown;
90
- }>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<VideoResponse>, import("./public.js").AIError, VideoClientService>;
91
18
  readonly Service: typeof VideoClientService;
19
+ readonly layer: Layer.Layer<VideoClientService, never, RequestExecutor.RequestExecutorService>;
20
+ readonly start: (request: VideoRequest) => Effect.Effect<VideoJob, AIError, VideoClientService>;
21
+ readonly status: (model: VideoModel, token: unknown) => Effect.Effect<VideoStatus, AIError, VideoClientService>;
22
+ readonly result: (model: VideoModel, token: unknown) => Effect.Effect<VideoResponse, AIError, VideoClientService>;
23
+ readonly cancel: (model: VideoModel, token: unknown) => Effect.Effect<void, AIError, VideoClientService>;
92
24
  };
93
25
  export {};
@@ -1,19 +1,34 @@
1
- import { Context } from "effect";
2
- import { MediaClient } from "./media-client.js";
3
- import { VideoOutputEvent, VideoFinishEvent } from "./video.js";
1
+ import { Context, Effect, Layer } from "effect";
2
+ import { RequestExecutor } from "./route/executor.js";
3
+ import { AIError, UnsupportedOperationError } from "./schema/index.js";
4
4
  export class VideoClientService extends Context.Service()("@opencode/VideoClient") {
5
5
  }
6
6
  export const Service = VideoClientService;
7
+ export const layer = Layer.effect(Service, Effect.gen(function* () {
8
+ const executor = yield* RequestExecutor.Service;
9
+ const attach = (model, token) => model.route.attach(model, token, executor.execute);
10
+ return Service.of({
11
+ start: (request) => request.model.route
12
+ .start(request, executor.execute)
13
+ .pipe(Effect.map((generation) => ({ id: generation.id, token: generation.token }))),
14
+ status: (model, token) => attach(model, token).pipe(Effect.flatMap((route) => route.status), Effect.map((snapshot) => ({ status: snapshot.status, progress: snapshot.progress }))),
15
+ result: (model, token) => attach(model, token).pipe(Effect.flatMap((route) => route.result)),
16
+ cancel: (model, token) => attach(model, token).pipe(Effect.flatMap((route) => route.cancel ??
17
+ Effect.fail(new AIError({
18
+ reason: new UnsupportedOperationError({
19
+ operation: "video.cancel",
20
+ provider: model.provider,
21
+ route: model.route.id,
22
+ message: `${model.provider}/${model.route.id} has no way to cancel a video generation`,
23
+ }),
24
+ })))),
25
+ });
26
+ }));
7
27
  export const VideoClient = {
8
28
  Service,
9
- ...MediaClient.make(Service, {
10
- modality: "video",
11
- responseEvents: (response) => [
12
- ...response.videos.map((video, index) => VideoOutputEvent.make({ index, video })),
13
- VideoFinishEvent.make({
14
- usage: response.usage,
15
- providerMetadata: response.providerMetadata,
16
- }),
17
- ],
18
- }),
29
+ layer,
30
+ start: (request) => Service.use((client) => client.start(request)),
31
+ status: (model, token) => Service.use((client) => client.status(model, token)),
32
+ result: (model, token) => Service.use((client) => client.result(model, token)),
33
+ cancel: (model, token) => Service.use((client) => client.cancel(model, token)),
19
34
  };