@opencode/ai 0.0.0-dev-20140 → 0.0.0-dev-20142

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 (40) hide show
  1. package/dist/image-client.d.ts +54 -21
  2. package/dist/image-client.js +14 -39
  3. package/dist/image.d.ts +13 -25
  4. package/dist/image.js +2 -13
  5. package/dist/media-client.d.ts +30 -0
  6. package/dist/media-client.js +51 -0
  7. package/dist/media-model.d.ts +9 -8
  8. package/dist/media-model.js +10 -10
  9. package/dist/promise.d.ts +26 -10
  10. package/dist/promise.js +15 -20
  11. package/dist/protocols/cartesia-speech.d.ts +16 -0
  12. package/dist/protocols/deepgram-speech.d.ts +16 -0
  13. package/dist/protocols/elevenlabs-speech.d.ts +16 -0
  14. package/dist/protocols/google-speech.d.ts +16 -0
  15. package/dist/protocols/open-responses.d.ts +3 -0
  16. package/dist/protocols/open-responses.js +2 -5
  17. package/dist/protocols/openai-responses.js +13 -18
  18. package/dist/protocols/openai-speech.d.ts +16 -0
  19. package/dist/protocols/utils/responses-checkpoint.js +3 -7
  20. package/dist/protocols/utils/responses-compaction.d.ts +3 -1
  21. package/dist/protocols/utils/responses-compaction.js +16 -3
  22. package/dist/protocols/xai-responses.js +1 -1
  23. package/dist/providers/openai-options.d.ts +3 -9
  24. package/dist/providers/openai-options.js +4 -7
  25. package/dist/providers/openai.js +1 -1
  26. package/dist/route/media.d.ts +4 -14
  27. package/dist/route/media.js +1 -36
  28. package/dist/speech-client.d.ts +57 -14
  29. package/dist/speech-client.js +15 -20
  30. package/dist/speech.d.ts +176 -19
  31. package/dist/speech.js +11 -6
  32. package/dist/transcription-client.d.ts +73 -21
  33. package/dist/transcription-client.js +7 -39
  34. package/dist/transcription.d.ts +13 -25
  35. package/dist/transcription.js +2 -8
  36. package/dist/video-client.d.ts +50 -21
  37. package/dist/video-client.js +14 -35
  38. package/dist/video.d.ts +14 -22
  39. package/dist/video.js +13 -14
  40. package/package.json +3 -3
@@ -1,30 +1,59 @@
1
- import { Context, Effect, Layer, Stream } from "effect";
2
- import { type AwaitOptions, type Generation } from "./generation.js";
3
- import { RequestExecutor } from "./route/executor.js";
4
- import type { AIError } from "./schema/index.js";
5
- import { type VideoEvent, type VideoModel, type VideoOptions, type VideoRequestFor, type VideoResponse } from "./video.js";
6
- export interface Interface {
7
- readonly start: <Options extends VideoOptions>(request: VideoRequestFor<Options>) => Effect.Effect<Generation<VideoResponse>, AIError>;
8
- readonly resume: <Options extends VideoOptions>(model: VideoModel<Options>, token: unknown) => Effect.Effect<Generation<VideoResponse>, AIError>;
9
- readonly generate: <Options extends VideoOptions>(request: VideoRequestFor<Options>, options?: AwaitOptions) => Effect.Effect<VideoResponse, AIError>;
10
- readonly stream: <Options extends VideoOptions>(request: VideoRequestFor<Options>, options?: AwaitOptions) => Stream.Stream<VideoEvent, AIError>;
11
- }
1
+ import { Context } from "effect";
2
+ import { MediaClient } from "./media-client.js";
3
+ import { type VideoEvent, type VideoRequestFor, type VideoResponse } from "./video.js";
4
+ export type Interface = MediaClient.Interface<VideoRequestFor, VideoEvent, VideoResponse>;
12
5
  declare const VideoClientService_base: Context.ServiceClass<VideoClientService, "@opencode/VideoClient", Interface>;
13
6
  export declare class VideoClientService extends VideoClientService_base {
14
7
  }
15
8
  export declare const Service: typeof VideoClientService;
16
9
  export type Service = VideoClientService;
17
- export declare const start: <Options extends VideoOptions>(request: VideoRequestFor<Options>) => Effect.Effect<Generation<VideoResponse>, AIError, Service>;
18
- export declare const resume: <Options extends VideoOptions>(model: VideoModel<Options>, token: unknown) => Effect.Effect<Generation<VideoResponse>, AIError, Service>;
19
- export declare const generate: <Options extends VideoOptions>(request: VideoRequestFor<Options>, options?: AwaitOptions) => Effect.Effect<VideoResponse, AIError, Service>;
20
- export declare const stream: <Options extends VideoOptions>(request: VideoRequestFor<Options>, options?: AwaitOptions) => Stream.Stream<VideoEvent, AIError, Service>;
21
- export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
22
10
  export declare const VideoClient: {
11
+ readonly layer: import("effect/Layer").Layer<VideoClientService, never, import("./route/executor-service.js").RequestExecutorService>;
12
+ readonly generate: (request: VideoRequestFor, options?: import("./generation.js").AwaitOptions) => import("effect/Effect").Effect<VideoResponse, import("./index.js").AIError, VideoClientService>;
13
+ readonly stream: (request: VideoRequestFor, options?: import("./generation.js").AwaitOptions) => import("effect/Stream").Stream<import("./generation.js").Observation | {
14
+ readonly type: "video";
15
+ readonly index: number;
16
+ readonly video: import("./media.js").Asset;
17
+ } | {
18
+ readonly type: "finish";
19
+ readonly providerMetadata?: {
20
+ readonly [x: string]: {
21
+ readonly [x: string]: unknown;
22
+ };
23
+ } | undefined;
24
+ readonly usage?: {
25
+ readonly type: "tokens";
26
+ readonly input?: number | undefined;
27
+ readonly output?: number | undefined;
28
+ readonly total?: number | undefined;
29
+ readonly details?: {
30
+ readonly [x: string]: unknown;
31
+ } | undefined;
32
+ } | {
33
+ readonly type: "seconds";
34
+ readonly seconds: number;
35
+ } | {
36
+ readonly type: "characters";
37
+ readonly characters: number;
38
+ } | {
39
+ readonly type: "credits";
40
+ readonly credits: number;
41
+ } | {
42
+ readonly type: "compute";
43
+ readonly seconds: number;
44
+ } | undefined;
45
+ readonly notices?: readonly {
46
+ readonly type: "other" | "moderated" | "filtered";
47
+ readonly message: string;
48
+ readonly providerMetadata?: {
49
+ readonly [x: string]: {
50
+ readonly [x: string]: unknown;
51
+ };
52
+ } | undefined;
53
+ }[] | undefined;
54
+ }, import("./index.js").AIError, VideoClientService>;
55
+ readonly start: (request: VideoRequestFor) => import("effect/Effect").Effect<import("./generation.js").Generation<VideoResponse>, import("./index.js").AIError, VideoClientService>;
56
+ readonly resume: (model: import("./video.js").VideoModel<import("./media-model.js").MediaModel.Options>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<VideoResponse>, import("./index.js").AIError, VideoClientService>;
23
57
  readonly Service: typeof VideoClientService;
24
- readonly layer: Layer.Layer<VideoClientService, never, import("./route/executor-service.js").RequestExecutorService>;
25
- readonly start: <Options extends VideoOptions>(request: VideoRequestFor<Options>) => Effect.Effect<Generation<VideoResponse>, AIError, Service>;
26
- readonly resume: <Options extends VideoOptions>(model: VideoModel<Options>, token: unknown) => Effect.Effect<Generation<VideoResponse>, AIError, Service>;
27
- readonly generate: <Options extends VideoOptions>(request: VideoRequestFor<Options>, options?: AwaitOptions) => Effect.Effect<VideoResponse, AIError, Service>;
28
- readonly stream: <Options extends VideoOptions>(request: VideoRequestFor<Options>, options?: AwaitOptions) => Stream.Stream<VideoEvent, AIError, Service>;
29
58
  };
30
59
  export {};
@@ -1,41 +1,20 @@
1
- import { Context, Effect, Layer, Stream } from "effect";
2
- import { resultEvents } from "./generation.js";
3
- import { RequestExecutor } from "./route/executor.js";
4
- import { responseEvents, } from "./video.js";
1
+ import { Context } from "effect";
2
+ import { MediaClient } from "./media-client.js";
3
+ import { VideoOutputEvent, VideoFinishEvent, } from "./video.js";
5
4
  export class VideoClientService extends Context.Service()("@opencode/VideoClient") {
6
5
  }
7
6
  export const Service = VideoClientService;
8
- export const start = (request) => Effect.gen(function* () {
9
- const client = yield* Service;
10
- return yield* client.start(request);
11
- });
12
- export const resume = (model, token) => Effect.gen(function* () {
13
- const client = yield* Service;
14
- return yield* client.resume(model, token);
15
- });
16
- export const generate = (request, options) => Effect.gen(function* () {
17
- const client = yield* Service;
18
- return yield* client.generate(request, options);
19
- });
20
- export const stream = (request, options) => Stream.unwrap(Effect.gen(function* () {
21
- const client = yield* Service;
22
- return client.stream(request, options);
23
- }));
24
- export const layer = Layer.effect(Service, Effect.gen(function* () {
25
- const executor = yield* RequestExecutor.Service;
26
- const start = (request) => request.model.route.start(request, executor.execute);
27
- return Service.of({
28
- start,
29
- resume: (model, token) => model.route.resume(model, token, executor.execute),
30
- generate: (request, options) => start(request).pipe(Effect.flatMap((generation) => generation.await(options))),
31
- stream: (request, options) => Stream.unwrap(start(request).pipe(Effect.map((generation) => resultEvents(generation, responseEvents, options)))),
32
- });
33
- }));
34
7
  export const VideoClient = {
35
8
  Service,
36
- layer,
37
- start,
38
- resume,
39
- generate,
40
- stream,
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
+ notices: response.notices,
16
+ providerMetadata: response.providerMetadata,
17
+ }),
18
+ ],
19
+ }),
41
20
  };
package/dist/video.d.ts CHANGED
@@ -3,21 +3,18 @@ import { Generation, type AwaitOptions } 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";
6
- import type { MediaProtocol } from "./route/media-protocol.js";
7
6
  import { AIError, HttpOptions, type OpenString } from "./schema/index.js";
8
7
  import { Service } from "./video-client.js";
9
- export type VideoOptions = Record<string, unknown>;
10
- export type VideoRoute<Options extends VideoOptions = VideoOptions> = MediaRoute.QueuedRoute<VideoRequestFor<Options>, VideoResponse>;
11
- export declare class VideoModel<Options extends VideoOptions = VideoOptions> extends MediaModel<VideoRoute<Options>, Options> {
8
+ export type VideoOptions = MediaModel.Options;
9
+ export type VideoRoute = MediaRoute.AnyRoute<VideoRequestFor, VideoEvent, VideoResponse>;
10
+ export declare class VideoModel<Options extends VideoOptions = VideoOptions> extends MediaModel<VideoRoute, Options> {
12
11
  protected readonly _VideoModel: void;
13
- static make<Options extends VideoOptions = VideoOptions>(input: MediaModel.Input<VideoRoute<Options>>): VideoModel<Options>;
14
- /** Compose a queued video protocol with its canonical start path into a model for one deployment. */
15
- static fromRoute<Options extends VideoOptions = VideoOptions, Token = unknown>(route: VideoModel.RouteInput<Options, Token>, input: MediaRoute.ModelInput): VideoModel<Options>;
12
+ /** The number of type arguments selects the kind: `<Options>`, `<Options, Frame, State>`, or `<Options, Token>`. */
13
+ static fromRoute<Options extends VideoOptions>(route: MediaModel.InlineRouteInput<VideoRequestFor<Options>, VideoResponse>, input: MediaRoute.ModelInput): VideoModel<Options>;
14
+ static fromRoute<Options extends VideoOptions, Frame, State>(route: MediaModel.StreamRouteInput<VideoRequestFor<Options>, VideoEvent, Frame, State>, input: MediaRoute.ModelInput): VideoModel<Options>;
15
+ static fromRoute<Options extends VideoOptions, Token>(route: MediaModel.QueuedRouteInput<VideoRequestFor<Options>, VideoResponse, Token>, input: MediaRoute.ModelInput): VideoModel<Options>;
16
16
  }
17
- export declare namespace VideoModel {
18
- type RouteInput<Options extends VideoOptions = VideoOptions, Token = unknown> = MediaModel.RouteInput<VideoRequestFor<Options>, MediaProtocol.Queued<VideoRequestFor<Options>, VideoResponse, Token>>;
19
- }
20
- export declare const VideoModelSchema: Schema.declare<VideoModel<VideoOptions>, VideoModel<VideoOptions>>;
17
+ export declare const VideoModelSchema: Schema.declare<VideoModel<MediaModel.Options>, VideoModel<MediaModel.Options>>;
21
18
  export type VideoAspectRatio = Media.AspectRatio;
22
19
  export declare const VideoAspectRatio: Schema.declare<`${number}:${number}`, `${number}:${number}`>;
23
20
  export type VideoResolution = OpenString<"480p" | "720p" | "1080p" | "4k">;
@@ -88,7 +85,7 @@ export declare const VideoFrames: Schema.Struct<{
88
85
  }>;
89
86
  export type VideoFrames = Schema.Schema.Type<typeof VideoFrames>;
90
87
  declare const VideoRequest_base: Schema.Class<VideoRequest, Schema.Struct<{
91
- readonly model: Schema.declare<VideoModel<VideoOptions>, VideoModel<VideoOptions>>;
88
+ readonly model: Schema.declare<VideoModel<MediaModel.Options>, VideoModel<MediaModel.Options>>;
92
89
  readonly prompt: Schema.String;
93
90
  readonly frames: Schema.optional<Schema.Struct<{
94
91
  readonly first: Schema.optional<Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
@@ -1337,23 +1334,18 @@ export declare const VideoEvent: Schema.Union<readonly [Schema.Struct<{
1337
1334
  };
1338
1335
  };
1339
1336
  export type VideoEvent = Schema.Schema.Type<typeof videoEventTagged>;
1340
- /** A completed response expanded into the streaming event shape. */
1341
- export declare const responseEvents: (response: VideoResponse) => ReadonlyArray<VideoEvent>;
1342
1337
  export declare function request<const Model extends VideoModel>(input: VideoRequestInput<Model>): VideoRequestFor<VideoModelOptions<Model>>;
1343
1338
  export declare function request(input: VideoRequest): VideoRequest;
1344
- export declare function start<const Model extends VideoModel>(input: VideoRequestInput<Model>): Effect.Effect<Generation<VideoResponse>, AIError, Service>;
1345
- export declare function start(input: VideoRequest): Effect.Effect<Generation<VideoResponse>, AIError, Service>;
1346
- export declare function generate<const Model extends VideoModel>(input: VideoRequestInput<Model>, options?: AwaitOptions): Effect.Effect<VideoResponse, AIError, Service>;
1347
- export declare function generate(input: VideoRequest, options?: AwaitOptions): Effect.Effect<VideoResponse, AIError, Service>;
1339
+ export declare function start<const Model extends VideoModel>(input: VideoRequest | VideoRequestInput<Model>): Effect.Effect<Generation<VideoResponse>, AIError, Service>;
1340
+ export declare function generate<const Model extends VideoModel>(input: VideoRequest | VideoRequestInput<Model>, options?: AwaitOptions): Effect.Effect<VideoResponse, AIError, Service>;
1348
1341
  /** Rebuild a generation handle from a persisted `Generation.token`, refreshing its status once. */
1349
- export declare const resume: <Options extends VideoOptions>(model: VideoModel<Options>, token: unknown) => Effect.Effect<Generation<VideoResponse>, AIError, Service>;
1350
- export declare function stream<const Model extends VideoModel>(input: VideoRequestInput<Model>, options?: AwaitOptions): Stream.Stream<VideoEvent, AIError, Service>;
1351
- export declare function stream(input: VideoRequest, options?: AwaitOptions): Stream.Stream<VideoEvent, AIError, Service>;
1342
+ export declare const resume: (model: VideoModel, token: unknown) => Effect.Effect<Generation<VideoResponse>, AIError, Service>;
1343
+ export declare function stream<const Model extends VideoModel>(input: VideoRequest | VideoRequestInput<Model>, options?: AwaitOptions): Stream.Stream<VideoEvent, AIError, Service>;
1352
1344
  export declare const Video: {
1353
1345
  readonly request: typeof request;
1354
1346
  readonly start: typeof start;
1355
1347
  readonly generate: typeof generate;
1356
- readonly resume: <Options extends VideoOptions>(model: VideoModel<Options>, token: unknown) => Effect.Effect<Generation<VideoResponse>, AIError, Service>;
1348
+ readonly resume: (model: VideoModel, token: unknown) => Effect.Effect<Generation<VideoResponse>, AIError, Service>;
1357
1349
  readonly stream: typeof stream;
1358
1350
  };
1359
1351
  export {};
package/dist/video.js CHANGED
@@ -6,16 +6,12 @@ import { MediaRoute } from "./route/media.js";
6
6
  import { AIError, HttpOptions, MediaUsage, ProviderMetadata } from "./schema/index.js";
7
7
  import { VideoClient, Service } from "./video-client.js";
8
8
  export class VideoModel extends MediaModel {
9
- static make(input) {
10
- return new VideoModel(input);
11
- }
12
- /** Compose a queued video protocol with its canonical start path into a model for one deployment. */
13
9
  static fromRoute(route, input) {
14
10
  return new VideoModel({
15
11
  id: input.id,
16
12
  provider: route.protocol.provider,
17
13
  http: input.http,
18
- route: composeRoute(MediaRoute.queued, route, input),
14
+ route: composeRoute(route, input, collectResponse),
19
15
  });
20
16
  }
21
17
  }
@@ -81,15 +77,18 @@ export const VideoEvent = Object.assign(videoEventTagged, {
81
77
  finish: videoEventTagged.guards.finish,
82
78
  },
83
79
  });
84
- /** A completed response expanded into the streaming event shape. */
85
- export const responseEvents = (response) => [
86
- ...response.videos.map((video, index) => VideoOutputEvent.make({ index, video })),
87
- VideoFinishEvent.make({
88
- usage: response.usage,
89
- notices: response.notices,
90
- providerMetadata: response.providerMetadata,
91
- }),
92
- ];
80
+ const collectResponse = (events) => {
81
+ const finish = events.find(VideoEvent.is.finish);
82
+ // A streaming video protocol's `finish` emits the terminal event or fails, so a completed stream always has one.
83
+ if (finish === undefined)
84
+ return Effect.die(new Error("The video stream completed without a finish event"));
85
+ return Effect.succeed(new VideoResponse({
86
+ videos: events.filter(VideoEvent.is.video).map((event) => event.video),
87
+ usage: finish.usage,
88
+ notices: finish.notices,
89
+ providerMetadata: finish.providerMetadata,
90
+ }));
91
+ };
93
92
  export function request(input) {
94
93
  if (input instanceof VideoRequest)
95
94
  return input;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "0.0.0-dev-20140",
3
+ "version": "0.0.0-dev-20142",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  "devDependencies": {
35
35
  "@clack/prompts": "1.0.0-alpha.1",
36
36
  "@effect/platform-node": "4.0.0-rc.112",
37
- "@opencode/http-recorder": "0.0.0-dev-20140",
37
+ "@opencode/http-recorder": "0.0.0-dev-20142",
38
38
  "@tsconfig/bun": "1.0.9",
39
39
  "@types/bun": "1.4.0",
40
40
  "@typescript/native-preview": "7.0.0-dev.20251207.1",
@@ -44,7 +44,7 @@
44
44
  "@aws-sdk/credential-providers": "3.1057.0",
45
45
  "@smithy/eventstream-codec": "4.2.14",
46
46
  "@smithy/util-utf8": "4.2.2",
47
- "@opencode/schema": "0.0.0-dev-20140",
47
+ "@opencode/schema": "0.0.0-dev-20142",
48
48
  "aws4fetch": "1.0.20",
49
49
  "effect": "4.0.0-rc.112",
50
50
  "google-auth-library": "10.5.0"