@opencode/ai 2.0.15 → 2.0.16

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 (168) hide show
  1. package/README.md +286 -2
  2. package/dist/generation.d.ts +36 -22
  3. package/dist/generation.js +53 -24
  4. package/dist/image-client.d.ts +14 -7
  5. package/dist/image-client.js +24 -8
  6. package/dist/image.d.ts +398 -47
  7. package/dist/image.js +47 -45
  8. package/dist/index.d.ts +13 -1
  9. package/dist/index.js +9 -0
  10. package/dist/media-model.d.ts +44 -0
  11. package/dist/media-model.js +49 -0
  12. package/dist/media.d.ts +10 -9
  13. package/dist/media.js +9 -10
  14. package/dist/promise.d.ts +428 -8
  15. package/dist/promise.js +40 -3
  16. package/dist/protocols/alibaba-chat.d.ts +12 -0
  17. package/dist/protocols/alibaba-responses.d.ts +2 -2
  18. package/dist/protocols/anthropic-messages.js +1 -2
  19. package/dist/protocols/assemblyai-transcription.d.ts +40 -0
  20. package/dist/protocols/assemblyai-transcription.js +138 -0
  21. package/dist/protocols/bedrock-converse.js +5 -11
  22. package/dist/protocols/bfl-images.d.ts +32 -0
  23. package/dist/protocols/bfl-images.js +153 -0
  24. package/dist/protocols/cartesia-speech.d.ts +127 -0
  25. package/dist/protocols/cartesia-speech.js +126 -0
  26. package/dist/protocols/deepgram-speech.d.ts +119 -0
  27. package/dist/protocols/deepgram-speech.js +92 -0
  28. package/dist/protocols/deepgram-transcription.d.ts +25 -0
  29. package/dist/protocols/deepgram-transcription.js +129 -0
  30. package/dist/protocols/elevenlabs-speech.d.ts +122 -0
  31. package/dist/protocols/elevenlabs-speech.js +115 -0
  32. package/dist/protocols/fal-images.d.ts +24 -0
  33. package/dist/protocols/fal-images.js +114 -0
  34. package/dist/protocols/fal-video.d.ts +29 -0
  35. package/dist/protocols/fal-video.js +88 -0
  36. package/dist/protocols/gemini.d.ts +9 -9
  37. package/dist/protocols/gemini.js +8 -34
  38. package/dist/protocols/google-images.js +2 -14
  39. package/dist/protocols/google-speech.d.ts +130 -0
  40. package/dist/protocols/google-speech.js +84 -0
  41. package/dist/protocols/google-transcription.d.ts +173 -0
  42. package/dist/protocols/google-transcription.js +138 -0
  43. package/dist/protocols/google-video.d.ts +26 -0
  44. package/dist/protocols/google-video.js +158 -0
  45. package/dist/protocols/meta-images.js +2 -9
  46. package/dist/protocols/meta-responses.d.ts +4 -4
  47. package/dist/protocols/meta-responses.js +1 -1
  48. package/dist/protocols/open-responses.d.ts +6 -6
  49. package/dist/protocols/open-responses.js +1 -2
  50. package/dist/protocols/openai-chat.d.ts +84 -0
  51. package/dist/protocols/openai-chat.js +26 -14
  52. package/dist/protocols/openai-compatible-chat.d.ts +12 -0
  53. package/dist/protocols/openai-compatible-responses.d.ts +2 -2
  54. package/dist/protocols/openai-images.d.ts +124 -3
  55. package/dist/protocols/openai-images.js +107 -54
  56. package/dist/protocols/openai-responses.d.ts +15 -15
  57. package/dist/protocols/openai-responses.js +5 -6
  58. package/dist/protocols/openai-speech.d.ts +116 -0
  59. package/dist/protocols/openai-speech.js +98 -0
  60. package/dist/protocols/openai-transcription.d.ts +207 -0
  61. package/dist/protocols/openai-transcription.js +190 -0
  62. package/dist/protocols/replicate-images.d.ts +28 -0
  63. package/dist/protocols/replicate-images.js +133 -0
  64. package/dist/protocols/runway-video.d.ts +38 -0
  65. package/dist/protocols/runway-video.js +146 -0
  66. package/dist/protocols/shared.d.ts +13 -3
  67. package/dist/protocols/shared.js +23 -3
  68. package/dist/protocols/stability-images.d.ts +38 -0
  69. package/dist/protocols/stability-images.js +148 -0
  70. package/dist/protocols/utils/fal-queue.d.ts +28 -0
  71. package/dist/protocols/utils/fal-queue.js +69 -0
  72. package/dist/protocols/utils/gemini-generate-content.d.ts +65 -0
  73. package/dist/protocols/utils/gemini-generate-content.js +65 -0
  74. package/dist/protocols/utils/gemini-json-schema.d.ts +3 -0
  75. package/dist/protocols/utils/gemini-json-schema.js +76 -0
  76. package/dist/protocols/utils/media-input.d.ts +8 -0
  77. package/dist/protocols/utils/media-input.js +18 -0
  78. package/dist/protocols/utils/speech-stream.d.ts +49 -0
  79. package/dist/protocols/utils/speech-stream.js +67 -0
  80. package/dist/protocols/utils/tool-schema.d.ts +2 -2
  81. package/dist/protocols/utils/tool-schema.js +40 -17
  82. package/dist/protocols/xai-images.js +1 -12
  83. package/dist/protocols/xai-responses.d.ts +2 -2
  84. package/dist/protocols/xai-video.d.ts +34 -0
  85. package/dist/protocols/xai-video.js +147 -0
  86. package/dist/protocols/zai-chat.d.ts +13 -1
  87. package/dist/provider-error.js +3 -0
  88. package/dist/providers/alibaba.d.ts +14 -2
  89. package/dist/providers/amazon-bedrock-mantle.d.ts +14 -2
  90. package/dist/providers/assemblyai.d.ts +25 -0
  91. package/dist/providers/assemblyai.js +29 -0
  92. package/dist/providers/azure.d.ts +18 -6
  93. package/dist/providers/baseten.d.ts +24 -0
  94. package/dist/providers/black-forest-labs.d.ts +25 -0
  95. package/dist/providers/black-forest-labs.js +28 -0
  96. package/dist/providers/cartesia.d.ts +24 -0
  97. package/dist/providers/cartesia.js +22 -0
  98. package/dist/providers/cerebras.d.ts +24 -0
  99. package/dist/providers/cloudflare-ai-gateway.d.ts +30 -6
  100. package/dist/providers/cloudflare-workers-ai.d.ts +24 -0
  101. package/dist/providers/deepgram.d.ts +29 -0
  102. package/dist/providers/deepgram.js +31 -0
  103. package/dist/providers/deepinfra.d.ts +24 -0
  104. package/dist/providers/deepseek.d.ts +24 -0
  105. package/dist/providers/elevenlabs.d.ts +24 -0
  106. package/dist/providers/elevenlabs.js +28 -0
  107. package/dist/providers/fal.d.ts +29 -0
  108. package/dist/providers/fal.js +33 -0
  109. package/dist/providers/fireworks.d.ts +24 -0
  110. package/dist/providers/google-vertex-chat.d.ts +12 -0
  111. package/dist/providers/google-vertex-responses.d.ts +2 -2
  112. package/dist/providers/google-vertex.d.ts +3 -3
  113. package/dist/providers/google.d.ts +18 -3
  114. package/dist/providers/google.js +11 -2
  115. package/dist/providers/groq.d.ts +24 -0
  116. package/dist/providers/index.d.ts +9 -0
  117. package/dist/providers/index.js +9 -0
  118. package/dist/providers/meta.d.ts +14 -2
  119. package/dist/providers/minimax.d.ts +14 -2
  120. package/dist/providers/moonshot.d.ts +14 -2
  121. package/dist/providers/moonshot.js +3 -3
  122. package/dist/providers/openai-compatible-responses.d.ts +2 -2
  123. package/dist/providers/openai-compatible.d.ts +12 -0
  124. package/dist/providers/openai.d.ts +25 -3
  125. package/dist/providers/openai.js +10 -1
  126. package/dist/providers/openrouter.d.ts +48 -0
  127. package/dist/providers/replicate.d.ts +25 -0
  128. package/dist/providers/replicate.js +22 -0
  129. package/dist/providers/runway.d.ts +24 -0
  130. package/dist/providers/runway.js +22 -0
  131. package/dist/providers/stability.d.ts +28 -0
  132. package/dist/providers/stability.js +23 -0
  133. package/dist/providers/togetherai.d.ts +24 -0
  134. package/dist/providers/xai.d.ts +17 -0
  135. package/dist/providers/xai.js +5 -2
  136. package/dist/providers/zai-coding-plan.d.ts +15 -3
  137. package/dist/providers/zai.d.ts +13 -1
  138. package/dist/route/auth.d.ts +4 -1
  139. package/dist/route/auth.js +6 -0
  140. package/dist/route/framing.d.ts +5 -1
  141. package/dist/route/framing.js +9 -0
  142. package/dist/route/media-protocol.d.ts +116 -3
  143. package/dist/route/media-protocol.js +60 -4
  144. package/dist/route/media.d.ts +58 -7
  145. package/dist/route/media.js +201 -29
  146. package/dist/schema/events.d.ts +0 -6
  147. package/dist/schema/messages.d.ts +0 -3
  148. package/dist/schema/options.d.ts +4 -3
  149. package/dist/schema/options.js +3 -2
  150. package/dist/speech-client.d.ts +21 -0
  151. package/dist/speech-client.js +25 -0
  152. package/dist/speech.d.ts +1150 -0
  153. package/dist/speech.js +119 -0
  154. package/dist/transcription-client.d.ts +28 -0
  155. package/dist/transcription-client.js +44 -0
  156. package/dist/transcription.d.ts +1504 -0
  157. package/dist/transcription.js +133 -0
  158. package/dist/utils/bytes.d.ts +1 -0
  159. package/dist/utils/bytes.js +10 -0
  160. package/dist/utils/media-type.d.ts +1 -0
  161. package/dist/utils/media-type.js +22 -1
  162. package/dist/video-client.d.ts +28 -0
  163. package/dist/video-client.js +40 -0
  164. package/dist/video.d.ts +1359 -0
  165. package/dist/video.js +119 -0
  166. package/package.json +3 -3
  167. package/dist/protocols/utils/gemini-tool-schema.d.ts +0 -2
  168. package/dist/protocols/utils/gemini-tool-schema.js +0 -103
package/dist/promise.d.ts CHANGED
@@ -1,13 +1,21 @@
1
1
  import { Effect, Layer } from "effect";
2
- import { ImageModel, ImageRequest, type ImageRequestInput } from "./image.js";
2
+ import type { AwaitOptions, Snapshot } from "./generation.js";
3
+ import { ImageModel, ImageRequest, type ImageOptions, type ImageRequestInput } from "./image.js";
3
4
  import { ImageClient } from "./image-client.js";
4
5
  import { LLMClient } from "./route/client.js";
5
6
  import { RequestExecutor } from "./route/executor.js";
6
7
  import { LanguageModel, LLMRequest } from "./schema/index.js";
7
8
  import type { RequestInput } from "./llm.js";
9
+ import { SpeechModel, SpeechRequest, type SpeechRequestInput } from "./speech.js";
10
+ import { SpeechClient } from "./speech-client.js";
11
+ import { TranscriptionModel, TranscriptionRequest, type TranscriptionOptions, type TranscriptionRequestInput } from "./transcription.js";
12
+ import { TranscriptionClient } from "./transcription-client.js";
13
+ import { VideoModel, VideoRequest, type VideoOptions, type VideoRequestInput } from "./video.js";
14
+ import { VideoClient } from "./video-client.js";
8
15
  /**
9
- * Promise-first entrypoint for scripts and non-Effect callers. One `ManagedRuntime` hosts the LLM and image clients
10
- * over a request executor; every method runs the corresponding Effect API and rethrows `AIError` unchanged.
16
+ * Promise-first entrypoint for scripts and non-Effect callers. One `ManagedRuntime` hosts the LLM, image, video, speech,
17
+ * and transcription clients over a request executor; every method runs the corresponding Effect API and rethrows
18
+ * `AIError` unchanged.
11
19
  */
12
20
  export interface Options {
13
21
  /** Executor layer; defaults to `RequestExecutor.fetchLayer`. Inject a recorder or middleware here. */
@@ -16,7 +24,15 @@ export interface Options {
16
24
  export interface RunOptions {
17
25
  readonly signal?: AbortSignal;
18
26
  }
19
- export type Services = Layer.Success<typeof LLMClient.layer> | Layer.Success<typeof ImageClient.layer> | RequestExecutor.Service;
27
+ export type Services = Layer.Success<typeof LLMClient.layer> | Layer.Success<typeof ImageClient.layer> | Layer.Success<typeof VideoClient.layer> | Layer.Success<typeof SpeechClient.layer> | Layer.Success<typeof TranscriptionClient.layer> | RequestExecutor.Service;
28
+ /** Promise view of a `Generation`: its snapshot plus `await`, `refresh`, and `cancel` returning promises. */
29
+ export type GenerationHandle<Response> = Snapshot & {
30
+ /** Serializable JSON; pass it back to `resume` from another process. */
31
+ readonly token: unknown;
32
+ readonly await: (options?: AwaitOptions & RunOptions) => Promise<Response>;
33
+ readonly refresh: (options?: RunOptions) => Promise<GenerationHandle<Response>>;
34
+ readonly cancel: (options?: RunOptions) => Promise<void>;
35
+ };
20
36
  export declare const make: (options?: Options) => {
21
37
  run: <A, E>(effect: Effect.Effect<A, E, Services>, options?: RunOptions) => Promise<A>;
22
38
  llm: {
@@ -237,8 +253,20 @@ export declare const make: (options?: Options) => {
237
253
  };
238
254
  image: {
239
255
  request: typeof import("./image.js").request;
240
- generate: <const Model extends ImageModel>(input: ImageRequestInput<Model> | ImageRequest, options?: RunOptions) => Promise<import("./image.js").ImageResponse>;
241
- stream: <const Model extends ImageModel>(input: ImageRequestInput<Model> | ImageRequest, options?: RunOptions) => AsyncIterable<{
256
+ generate: <const Model extends ImageModel>(input: ImageRequestInput<Model> | ImageRequest, options?: AwaitOptions & RunOptions) => Promise<import("./image.js").ImageResponse>;
257
+ stream: <const Model extends ImageModel>(input: ImageRequestInput<Model> | ImageRequest, options?: AwaitOptions & RunOptions) => AsyncIterable<{
258
+ readonly id: string;
259
+ readonly type: "generation-queued";
260
+ readonly position?: number | undefined;
261
+ } | {
262
+ readonly id: string;
263
+ readonly type: "generation-progress";
264
+ readonly progress?: number | undefined;
265
+ } | {
266
+ readonly type: "image-partial";
267
+ readonly index: number;
268
+ readonly image: import("./media.js").Asset;
269
+ } | {
242
270
  readonly type: "image";
243
271
  readonly index: number;
244
272
  readonly image: import("./media.js").Asset;
@@ -280,6 +308,196 @@ export declare const make: (options?: Options) => {
280
308
  } | undefined;
281
309
  }[] | undefined;
282
310
  }>;
311
+ start: <const Model extends ImageModel>(input: ImageRequestInput<Model> | ImageRequest, options?: RunOptions) => Promise<GenerationHandle<import("./image.js").ImageResponse>>;
312
+ resume: <Options extends ImageOptions>(model: ImageModel<Options>, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./image.js").ImageResponse>>;
313
+ };
314
+ video: {
315
+ request: typeof import("./video.js").request;
316
+ start: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
317
+ generate: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: AwaitOptions & RunOptions) => Promise<import("./video.js").VideoResponse>;
318
+ resume: <Options extends VideoOptions>(model: VideoModel<Options>, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
319
+ stream: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: AwaitOptions & RunOptions) => AsyncIterable<{
320
+ readonly id: string;
321
+ readonly type: "generation-queued";
322
+ readonly position?: number | undefined;
323
+ } | {
324
+ readonly id: string;
325
+ readonly type: "generation-progress";
326
+ readonly progress?: number | undefined;
327
+ } | {
328
+ readonly type: "video";
329
+ readonly index: number;
330
+ readonly video: import("./media.js").Asset;
331
+ } | {
332
+ readonly type: "finish";
333
+ readonly providerMetadata?: {
334
+ readonly [x: string]: {
335
+ readonly [x: string]: unknown;
336
+ };
337
+ } | undefined;
338
+ readonly usage?: {
339
+ readonly type: "tokens";
340
+ readonly input?: number | undefined;
341
+ readonly output?: number | undefined;
342
+ readonly total?: number | undefined;
343
+ readonly details?: {
344
+ readonly [x: string]: unknown;
345
+ } | undefined;
346
+ } | {
347
+ readonly type: "seconds";
348
+ readonly seconds: number;
349
+ } | {
350
+ readonly type: "characters";
351
+ readonly characters: number;
352
+ } | {
353
+ readonly type: "credits";
354
+ readonly credits: number;
355
+ } | {
356
+ readonly type: "compute";
357
+ readonly seconds: number;
358
+ } | undefined;
359
+ readonly notices?: readonly {
360
+ readonly type: "other" | "moderated" | "filtered";
361
+ readonly message: string;
362
+ readonly providerMetadata?: {
363
+ readonly [x: string]: {
364
+ readonly [x: string]: unknown;
365
+ };
366
+ } | undefined;
367
+ }[] | undefined;
368
+ }>;
369
+ };
370
+ speech: {
371
+ request: typeof import("./speech.js").request;
372
+ generate: <const Model extends SpeechModel>(input: SpeechRequestInput<Model> | SpeechRequest, options?: RunOptions) => Promise<import("./speech.js").SpeechResponse>;
373
+ stream: <const Model extends SpeechModel>(input: SpeechRequestInput<Model> | SpeechRequest, options?: RunOptions) => AsyncIterable<{
374
+ readonly type: "audio-delta";
375
+ readonly chunk: Uint8Array<ArrayBufferLike>;
376
+ } | {
377
+ readonly type: "timestamps";
378
+ readonly items: readonly {
379
+ readonly text: string;
380
+ readonly startSeconds: number;
381
+ readonly endSeconds: number;
382
+ }[];
383
+ } | {
384
+ readonly type: "finish";
385
+ readonly audio: import("./media.js").Asset;
386
+ readonly providerMetadata?: {
387
+ readonly [x: string]: {
388
+ readonly [x: string]: unknown;
389
+ };
390
+ } | undefined;
391
+ readonly usage?: {
392
+ readonly type: "tokens";
393
+ readonly input?: number | undefined;
394
+ readonly output?: number | undefined;
395
+ readonly total?: number | undefined;
396
+ readonly details?: {
397
+ readonly [x: string]: unknown;
398
+ } | undefined;
399
+ } | {
400
+ readonly type: "seconds";
401
+ readonly seconds: number;
402
+ } | {
403
+ readonly type: "characters";
404
+ readonly characters: number;
405
+ } | {
406
+ readonly type: "credits";
407
+ readonly credits: number;
408
+ } | {
409
+ readonly type: "compute";
410
+ readonly seconds: number;
411
+ } | undefined;
412
+ readonly notices?: readonly {
413
+ readonly type: "other" | "moderated" | "filtered";
414
+ readonly message: string;
415
+ readonly providerMetadata?: {
416
+ readonly [x: string]: {
417
+ readonly [x: string]: unknown;
418
+ };
419
+ } | undefined;
420
+ }[] | undefined;
421
+ }>;
422
+ };
423
+ transcription: {
424
+ request: typeof import("./transcription.js").request;
425
+ generate: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: AwaitOptions & RunOptions) => Promise<import("./transcription.js").TranscriptionResponse>;
426
+ stream: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: AwaitOptions & RunOptions) => AsyncIterable<{
427
+ readonly id: string;
428
+ readonly type: "generation-queued";
429
+ readonly position?: number | undefined;
430
+ } | {
431
+ readonly id: string;
432
+ readonly type: "generation-progress";
433
+ readonly progress?: number | undefined;
434
+ } | {
435
+ readonly type: "text-delta";
436
+ readonly delta: string;
437
+ } | {
438
+ readonly type: "segment";
439
+ readonly segment: {
440
+ readonly text: string;
441
+ readonly startSeconds: number;
442
+ readonly endSeconds: number;
443
+ readonly speaker?: string | undefined;
444
+ };
445
+ } | {
446
+ readonly type: "finish";
447
+ readonly text: string;
448
+ readonly durationSeconds?: number | undefined;
449
+ readonly providerMetadata?: {
450
+ readonly [x: string]: {
451
+ readonly [x: string]: unknown;
452
+ };
453
+ } | undefined;
454
+ readonly usage?: {
455
+ readonly type: "tokens";
456
+ readonly input?: number | undefined;
457
+ readonly output?: number | undefined;
458
+ readonly total?: number | undefined;
459
+ readonly details?: {
460
+ readonly [x: string]: unknown;
461
+ } | undefined;
462
+ } | {
463
+ readonly type: "seconds";
464
+ readonly seconds: number;
465
+ } | {
466
+ readonly type: "characters";
467
+ readonly characters: number;
468
+ } | {
469
+ readonly type: "credits";
470
+ readonly credits: number;
471
+ } | {
472
+ readonly type: "compute";
473
+ readonly seconds: number;
474
+ } | undefined;
475
+ readonly notices?: readonly {
476
+ readonly type: "other" | "moderated" | "filtered";
477
+ readonly message: string;
478
+ readonly providerMetadata?: {
479
+ readonly [x: string]: {
480
+ readonly [x: string]: unknown;
481
+ };
482
+ } | undefined;
483
+ }[] | undefined;
484
+ readonly language?: string | undefined;
485
+ readonly segments?: readonly {
486
+ readonly text: string;
487
+ readonly startSeconds: number;
488
+ readonly endSeconds: number;
489
+ readonly speaker?: string | undefined;
490
+ }[] | undefined;
491
+ readonly words?: readonly {
492
+ readonly text: string;
493
+ readonly startSeconds: number;
494
+ readonly endSeconds: number;
495
+ readonly speaker?: string | undefined;
496
+ readonly confidence?: number | undefined;
497
+ }[] | undefined;
498
+ }>;
499
+ start: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
500
+ resume: <Options extends TranscriptionOptions>(model: TranscriptionModel<Options>, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
283
501
  };
284
502
  dispose: () => Promise<void>;
285
503
  };
@@ -505,8 +723,20 @@ export declare const ai: {
505
723
  };
506
724
  image: {
507
725
  request: typeof import("./image.js").request;
508
- generate: <const Model extends ImageModel>(input: ImageRequestInput<Model> | ImageRequest, options?: RunOptions) => Promise<import("./image.js").ImageResponse>;
509
- stream: <const Model extends ImageModel>(input: ImageRequestInput<Model> | ImageRequest, options?: RunOptions) => AsyncIterable<{
726
+ generate: <const Model extends ImageModel>(input: ImageRequestInput<Model> | ImageRequest, options?: AwaitOptions & RunOptions) => Promise<import("./image.js").ImageResponse>;
727
+ stream: <const Model extends ImageModel>(input: ImageRequestInput<Model> | ImageRequest, options?: AwaitOptions & RunOptions) => AsyncIterable<{
728
+ readonly id: string;
729
+ readonly type: "generation-queued";
730
+ readonly position?: number | undefined;
731
+ } | {
732
+ readonly id: string;
733
+ readonly type: "generation-progress";
734
+ readonly progress?: number | undefined;
735
+ } | {
736
+ readonly type: "image-partial";
737
+ readonly index: number;
738
+ readonly image: import("./media.js").Asset;
739
+ } | {
510
740
  readonly type: "image";
511
741
  readonly index: number;
512
742
  readonly image: import("./media.js").Asset;
@@ -548,6 +778,196 @@ export declare const ai: {
548
778
  } | undefined;
549
779
  }[] | undefined;
550
780
  }>;
781
+ start: <const Model extends ImageModel>(input: ImageRequestInput<Model> | ImageRequest, options?: RunOptions) => Promise<GenerationHandle<import("./image.js").ImageResponse>>;
782
+ resume: <Options extends ImageOptions>(model: ImageModel<Options>, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./image.js").ImageResponse>>;
783
+ };
784
+ video: {
785
+ request: typeof import("./video.js").request;
786
+ start: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
787
+ generate: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: AwaitOptions & RunOptions) => Promise<import("./video.js").VideoResponse>;
788
+ resume: <Options extends VideoOptions>(model: VideoModel<Options>, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
789
+ stream: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: AwaitOptions & RunOptions) => AsyncIterable<{
790
+ readonly id: string;
791
+ readonly type: "generation-queued";
792
+ readonly position?: number | undefined;
793
+ } | {
794
+ readonly id: string;
795
+ readonly type: "generation-progress";
796
+ readonly progress?: number | undefined;
797
+ } | {
798
+ readonly type: "video";
799
+ readonly index: number;
800
+ readonly video: import("./media.js").Asset;
801
+ } | {
802
+ readonly type: "finish";
803
+ readonly providerMetadata?: {
804
+ readonly [x: string]: {
805
+ readonly [x: string]: unknown;
806
+ };
807
+ } | undefined;
808
+ readonly usage?: {
809
+ readonly type: "tokens";
810
+ readonly input?: number | undefined;
811
+ readonly output?: number | undefined;
812
+ readonly total?: number | undefined;
813
+ readonly details?: {
814
+ readonly [x: string]: unknown;
815
+ } | undefined;
816
+ } | {
817
+ readonly type: "seconds";
818
+ readonly seconds: number;
819
+ } | {
820
+ readonly type: "characters";
821
+ readonly characters: number;
822
+ } | {
823
+ readonly type: "credits";
824
+ readonly credits: number;
825
+ } | {
826
+ readonly type: "compute";
827
+ readonly seconds: number;
828
+ } | undefined;
829
+ readonly notices?: readonly {
830
+ readonly type: "other" | "moderated" | "filtered";
831
+ readonly message: string;
832
+ readonly providerMetadata?: {
833
+ readonly [x: string]: {
834
+ readonly [x: string]: unknown;
835
+ };
836
+ } | undefined;
837
+ }[] | undefined;
838
+ }>;
839
+ };
840
+ speech: {
841
+ request: typeof import("./speech.js").request;
842
+ generate: <const Model extends SpeechModel>(input: SpeechRequestInput<Model> | SpeechRequest, options?: RunOptions) => Promise<import("./speech.js").SpeechResponse>;
843
+ stream: <const Model extends SpeechModel>(input: SpeechRequestInput<Model> | SpeechRequest, options?: RunOptions) => AsyncIterable<{
844
+ readonly type: "audio-delta";
845
+ readonly chunk: Uint8Array<ArrayBufferLike>;
846
+ } | {
847
+ readonly type: "timestamps";
848
+ readonly items: readonly {
849
+ readonly text: string;
850
+ readonly startSeconds: number;
851
+ readonly endSeconds: number;
852
+ }[];
853
+ } | {
854
+ readonly type: "finish";
855
+ readonly audio: import("./media.js").Asset;
856
+ readonly providerMetadata?: {
857
+ readonly [x: string]: {
858
+ readonly [x: string]: unknown;
859
+ };
860
+ } | undefined;
861
+ readonly usage?: {
862
+ readonly type: "tokens";
863
+ readonly input?: number | undefined;
864
+ readonly output?: number | undefined;
865
+ readonly total?: number | undefined;
866
+ readonly details?: {
867
+ readonly [x: string]: unknown;
868
+ } | undefined;
869
+ } | {
870
+ readonly type: "seconds";
871
+ readonly seconds: number;
872
+ } | {
873
+ readonly type: "characters";
874
+ readonly characters: number;
875
+ } | {
876
+ readonly type: "credits";
877
+ readonly credits: number;
878
+ } | {
879
+ readonly type: "compute";
880
+ readonly seconds: number;
881
+ } | undefined;
882
+ readonly notices?: readonly {
883
+ readonly type: "other" | "moderated" | "filtered";
884
+ readonly message: string;
885
+ readonly providerMetadata?: {
886
+ readonly [x: string]: {
887
+ readonly [x: string]: unknown;
888
+ };
889
+ } | undefined;
890
+ }[] | undefined;
891
+ }>;
892
+ };
893
+ transcription: {
894
+ request: typeof import("./transcription.js").request;
895
+ generate: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: AwaitOptions & RunOptions) => Promise<import("./transcription.js").TranscriptionResponse>;
896
+ stream: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: AwaitOptions & RunOptions) => AsyncIterable<{
897
+ readonly id: string;
898
+ readonly type: "generation-queued";
899
+ readonly position?: number | undefined;
900
+ } | {
901
+ readonly id: string;
902
+ readonly type: "generation-progress";
903
+ readonly progress?: number | undefined;
904
+ } | {
905
+ readonly type: "text-delta";
906
+ readonly delta: string;
907
+ } | {
908
+ readonly type: "segment";
909
+ readonly segment: {
910
+ readonly text: string;
911
+ readonly startSeconds: number;
912
+ readonly endSeconds: number;
913
+ readonly speaker?: string | undefined;
914
+ };
915
+ } | {
916
+ readonly type: "finish";
917
+ readonly text: string;
918
+ readonly durationSeconds?: number | undefined;
919
+ readonly providerMetadata?: {
920
+ readonly [x: string]: {
921
+ readonly [x: string]: unknown;
922
+ };
923
+ } | undefined;
924
+ readonly usage?: {
925
+ readonly type: "tokens";
926
+ readonly input?: number | undefined;
927
+ readonly output?: number | undefined;
928
+ readonly total?: number | undefined;
929
+ readonly details?: {
930
+ readonly [x: string]: unknown;
931
+ } | undefined;
932
+ } | {
933
+ readonly type: "seconds";
934
+ readonly seconds: number;
935
+ } | {
936
+ readonly type: "characters";
937
+ readonly characters: number;
938
+ } | {
939
+ readonly type: "credits";
940
+ readonly credits: number;
941
+ } | {
942
+ readonly type: "compute";
943
+ readonly seconds: number;
944
+ } | undefined;
945
+ readonly notices?: readonly {
946
+ readonly type: "other" | "moderated" | "filtered";
947
+ readonly message: string;
948
+ readonly providerMetadata?: {
949
+ readonly [x: string]: {
950
+ readonly [x: string]: unknown;
951
+ };
952
+ } | undefined;
953
+ }[] | undefined;
954
+ readonly language?: string | undefined;
955
+ readonly segments?: readonly {
956
+ readonly text: string;
957
+ readonly startSeconds: number;
958
+ readonly endSeconds: number;
959
+ readonly speaker?: string | undefined;
960
+ }[] | undefined;
961
+ readonly words?: readonly {
962
+ readonly text: string;
963
+ readonly startSeconds: number;
964
+ readonly endSeconds: number;
965
+ readonly speaker?: string | undefined;
966
+ readonly confidence?: number | undefined;
967
+ }[] | undefined;
968
+ }>;
969
+ start: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
970
+ resume: <Options extends TranscriptionOptions>(model: TranscriptionModel<Options>, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
551
971
  };
552
972
  dispose: () => Promise<void>;
553
973
  };
package/dist/promise.js CHANGED
@@ -5,6 +5,12 @@ import { LLM } from "./index.js";
5
5
  import { LLMClient } from "./route/client.js";
6
6
  import { RequestExecutor } from "./route/executor.js";
7
7
  import { LanguageModel, LLMRequest } from "./schema/index.js";
8
+ import { Speech, SpeechModel, SpeechRequest } from "./speech.js";
9
+ import { SpeechClient } from "./speech-client.js";
10
+ import { Transcription, TranscriptionModel, TranscriptionRequest, } from "./transcription.js";
11
+ import { TranscriptionClient } from "./transcription-client.js";
12
+ import { Video, VideoModel, VideoRequest } from "./video.js";
13
+ import { VideoClient } from "./video-client.js";
8
14
  const abortEffect = (signal) => signal === undefined
9
15
  ? Effect.never
10
16
  : Effect.callback((resume) => {
@@ -17,13 +23,23 @@ const abortEffect = (signal) => signal === undefined
17
23
  return Effect.sync(() => signal.removeEventListener("abort", onAbort));
18
24
  });
19
25
  export const make = (options = {}) => {
20
- const runtime = ManagedRuntime.make(Layer.mergeAll(LLMClient.layer, ImageClient.layer).pipe(Layer.provideMerge(options.layer ?? RequestExecutor.fetchLayer)));
26
+ const runtime = ManagedRuntime.make(Layer.mergeAll(LLMClient.layer, ImageClient.layer, VideoClient.layer, SpeechClient.layer, TranscriptionClient.layer).pipe(Layer.provideMerge(options.layer ?? RequestExecutor.fetchLayer)));
21
27
  /** Run any package Effect (for example `asset.bytes()`) inside this runtime. */
22
28
  const run = (effect, options) => runtime.runPromise(effect, { signal: options?.signal });
23
29
  const iterate = (stream, options) => Stream.toAsyncIterable(Stream.unwrap(runtime.contextEffect.pipe(Effect.map((context) => stream.pipe(Stream.interruptWhen(abortEffect(options?.signal)), Stream.provideContext(context))))));
30
+ const handle = (generation) => ({
31
+ ...generation.snapshot,
32
+ token: generation.token,
33
+ await: (options) => run(generation.await({ poll: options?.poll }), options),
34
+ refresh: (options) => run(generation.refresh(), options).then(handle),
35
+ cancel: (options) => run(generation.cancel(), options),
36
+ });
24
37
  // The typed `generate`/`stream` overloads take a concrete input or a request, not the union; normalize once here.
25
38
  const llmRequest = (input) => (input instanceof LLMRequest ? input : LLM.request(input));
26
39
  const imageRequest = (input) => input instanceof ImageRequest ? input : Image.request(input);
40
+ const videoRequest = (input) => input instanceof VideoRequest ? input : Video.request(input);
41
+ const speechRequest = (input) => input instanceof SpeechRequest ? input : Speech.request(input);
42
+ const transcriptionRequest = (input) => input instanceof TranscriptionRequest ? input : Transcription.request(input);
27
43
  return {
28
44
  run,
29
45
  llm: {
@@ -33,8 +49,29 @@ export const make = (options = {}) => {
33
49
  },
34
50
  image: {
35
51
  request: Image.request,
36
- generate: (input, options) => run(Image.generate(imageRequest(input)), options),
37
- stream: (input, options) => iterate(Image.stream(imageRequest(input)), options),
52
+ generate: (input, options) => run(Image.generate(imageRequest(input), { poll: options?.poll }), options),
53
+ stream: (input, options) => iterate(Image.stream(imageRequest(input), { poll: options?.poll }), options),
54
+ start: (input, options) => run(Image.start(imageRequest(input)), options).then(handle),
55
+ resume: (model, token, options) => run(Image.resume(model, token), options).then(handle),
56
+ },
57
+ video: {
58
+ request: Video.request,
59
+ start: (input, options) => run(Video.start(videoRequest(input)), options).then(handle),
60
+ generate: (input, options) => run(Video.generate(videoRequest(input), { poll: options?.poll }), options),
61
+ resume: (model, token, options) => run(Video.resume(model, token), options).then(handle),
62
+ stream: (input, options) => iterate(Video.stream(videoRequest(input), { poll: options?.poll }), options),
63
+ },
64
+ speech: {
65
+ request: Speech.request,
66
+ generate: (input, options) => run(Speech.generate(speechRequest(input)), options),
67
+ stream: (input, options) => iterate(Speech.stream(speechRequest(input)), options),
68
+ },
69
+ transcription: {
70
+ request: Transcription.request,
71
+ generate: (input, options) => run(Transcription.generate(transcriptionRequest(input), { poll: options?.poll }), options),
72
+ stream: (input, options) => iterate(Transcription.stream(transcriptionRequest(input), { poll: options?.poll }), options),
73
+ start: (input, options) => run(Transcription.start(transcriptionRequest(input)), options).then(handle),
74
+ resume: (model, token, options) => run(Transcription.resume(model, token), options).then(handle),
38
75
  },
39
76
  dispose: () => runtime.dispose(),
40
77
  };
@@ -50,6 +50,12 @@ export declare const protocol: Protocol<{
50
50
  readonly image_url: {
51
51
  readonly url: string;
52
52
  };
53
+ } | {
54
+ readonly type: "file";
55
+ readonly file: {
56
+ readonly filename: string;
57
+ readonly file_data: string;
58
+ };
53
59
  })[];
54
60
  } | {
55
61
  readonly role: "user";
@@ -65,6 +71,12 @@ export declare const protocol: Protocol<{
65
71
  readonly image_url: {
66
72
  readonly url: string;
67
73
  };
74
+ } | {
75
+ readonly type: "file";
76
+ readonly file: {
77
+ readonly filename: string;
78
+ readonly file_data: string;
79
+ };
68
80
  })[];
69
81
  } | {
70
82
  readonly [x: string]: unknown;
@@ -77,8 +77,8 @@ export declare const protocol: Protocol<{
77
77
  } | {
78
78
  readonly type: "input_file";
79
79
  readonly filename: string;
80
- readonly detail?: string | undefined;
81
80
  readonly file_data?: string | undefined;
81
+ readonly detail?: string | undefined;
82
82
  readonly file_url?: string | undefined;
83
83
  } | {
84
84
  readonly type: "input_text";
@@ -114,8 +114,8 @@ export declare const protocol: Protocol<{
114
114
  } | {
115
115
  readonly type: "input_file";
116
116
  readonly filename: string;
117
- readonly detail?: string | undefined;
118
117
  readonly file_data?: string | undefined;
118
+ readonly detail?: string | undefined;
119
119
  readonly file_url?: string | undefined;
120
120
  } | {
121
121
  readonly type: "input_text";
@@ -897,7 +897,6 @@ const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (reques
897
897
  const format = outputConfig?.format ?? undefined;
898
898
  const updates = resolveEffortUpdates(request, options.effort ?? outputConfig?.effort ?? undefined);
899
899
  const generation = request.generation;
900
- const toolSchemaCompatibility = request.model.compatibility?.toolSchema;
901
900
  // Allocate the 4-breakpoint budget in invalidation order: tools → system →
902
901
  // messages. Tools live highest in the cache hierarchy, so when callers
903
902
  // over-mark we keep their tool hints and shed the message-tail ones first.
@@ -905,7 +904,7 @@ const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (reques
905
904
  const flattened = ProviderShared.flattenToolRequest(updates.request);
906
905
  const tools = flattened.tools.length === 0
907
906
  ? undefined
908
- : flattened.tools.map((tool) => lowerTool(breakpoints, tool, ToolSchemaProjection.modelCompatibility(tool.inputSchema, toolSchemaCompatibility)));
907
+ : flattened.tools.map((tool) => lowerTool(breakpoints, tool, ToolSchemaProjection.modelCompatibility(tool.inputSchema, request.model)));
909
908
  // Anthropic rejects tool_choice when tools are absent; "none" is only meaningful with tools present.
910
909
  const toolChoice = tools === undefined || !request.toolChoice ? undefined : yield* lowerToolChoice(request.toolChoice);
911
910
  const systemParts = request.system.filter((part) => part.text.length > 0);
@@ -0,0 +1,40 @@
1
+ import { Schema } from "effect";
2
+ import { MediaProtocol } from "../route/media-protocol.js";
3
+ import { MediaRoute } from "../route/media.js";
4
+ import { TranscriptionModel, TranscriptionResponse, type TranscriptionRequestFor } from "../transcription.js";
5
+ export declare const DEFAULT_BASE_URL = "https://api.assemblyai.com";
6
+ export declare const PATH = "/v2/transcript";
7
+ export declare const UPLOAD_PATH = "/v2/upload";
8
+ export type AssemblyAITranscriptionOptions = {
9
+ readonly keyterms_prompt?: ReadonlyArray<string>;
10
+ readonly punctuate?: boolean;
11
+ readonly format_text?: boolean;
12
+ readonly disfluencies?: boolean;
13
+ readonly filter_profanity?: boolean;
14
+ readonly temperature?: number;
15
+ readonly speaker_options?: {
16
+ readonly min_speakers_expected?: number;
17
+ readonly max_speakers_expected?: number;
18
+ };
19
+ readonly language_detection_options?: {
20
+ readonly expected_languages?: ReadonlyArray<string>;
21
+ readonly fallback_language?: string;
22
+ readonly code_switching?: boolean;
23
+ };
24
+ readonly speech_models?: ReadonlyArray<"universal-3-5-pro" | "universal-2" | (string & {})>;
25
+ } & Record<string, unknown>;
26
+ export type Request = TranscriptionRequestFor<AssemblyAITranscriptionOptions>;
27
+ export declare const Token: Schema.Struct<{
28
+ readonly transcriptID: Schema.String;
29
+ }>;
30
+ export type Token = Schema.Schema.Type<typeof Token>;
31
+ export declare const protocol: MediaProtocol.Queued<Request, TranscriptionResponse, {
32
+ readonly transcriptID: string;
33
+ }>;
34
+ export declare const model: (input: MediaRoute.ModelInput) => TranscriptionModel<AssemblyAITranscriptionOptions>;
35
+ export declare const AssemblyAITranscription: {
36
+ readonly protocol: MediaProtocol.Queued<Request, TranscriptionResponse, {
37
+ readonly transcriptID: string;
38
+ }>;
39
+ readonly model: (input: MediaRoute.ModelInput) => TranscriptionModel<AssemblyAITranscriptionOptions>;
40
+ };