@opencode/ai 2.2.1 → 2.2.3

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 (55) hide show
  1. package/README.md +92 -76
  2. package/dist/decision.d.ts +0 -1
  3. package/dist/effect.d.ts +2 -14
  4. package/dist/effect.js +1 -10
  5. package/dist/experimental/testing.d.ts +3 -0
  6. package/dist/experimental/testing.js +3 -0
  7. package/dist/experimental.d.ts +12 -0
  8. package/dist/experimental.js +9 -0
  9. package/dist/image.d.ts +1 -0
  10. package/dist/index.d.ts +340 -336
  11. package/dist/index.js +43 -41
  12. package/dist/llm.d.ts +2 -2
  13. package/dist/llm.js +19 -29
  14. package/dist/protocols/alibaba-responses.d.ts +2 -2
  15. package/dist/protocols/assemblyai-transcription.js +3 -3
  16. package/dist/protocols/meta-responses.d.ts +4 -4
  17. package/dist/protocols/open-responses.d.ts +18 -18
  18. package/dist/protocols/open-responses.js +4 -2
  19. package/dist/protocols/openai-compatible-responses.d.ts +2 -2
  20. package/dist/protocols/openai-responses.d.ts +12 -12
  21. package/dist/protocols/runway-video.js +2 -2
  22. package/dist/protocols/xai-responses.d.ts +2 -2
  23. package/dist/protocols/xai-video.js +2 -2
  24. package/dist/providers/alibaba.d.ts +2 -2
  25. package/dist/providers/amazon-bedrock-mantle.d.ts +2 -2
  26. package/dist/providers/azure.d.ts +4 -4
  27. package/dist/providers/cloudflare-ai-gateway.d.ts +4 -4
  28. package/dist/providers/digitalocean.d.ts +2 -2
  29. package/dist/providers/google-vertex-responses.d.ts +2 -2
  30. package/dist/providers/meta.d.ts +2 -2
  31. package/dist/providers/minimax.d.ts +2 -2
  32. package/dist/providers/moonshot.d.ts +2 -2
  33. package/dist/providers/openai-compatible-responses.d.ts +2 -2
  34. package/dist/providers/openai.d.ts +2 -2
  35. package/dist/providers/openrouter/responses.d.ts +1 -2
  36. package/dist/providers/openrouter.d.ts +36 -23
  37. package/dist/providers/openrouter.js +29 -10
  38. package/dist/providers/venice.d.ts +2 -2
  39. package/dist/providers/zai-coding-plan.d.ts +2 -2
  40. package/dist/route/client.d.ts +3 -0
  41. package/dist/route/client.js +5 -4
  42. package/dist/route/media-protocol.d.ts +2 -3
  43. package/dist/route/media-protocol.js +2 -6
  44. package/dist/schema/errors.d.ts +6 -0
  45. package/dist/schema/errors.js +8 -0
  46. package/dist/schema/events.d.ts +4 -0
  47. package/dist/schema/events.js +4 -0
  48. package/dist/speech.d.ts +1 -0
  49. package/dist/testing.d.ts +1 -4
  50. package/dist/testing.js +4 -12
  51. package/dist/tool.d.ts +40 -73
  52. package/dist/tool.js +27 -18
  53. package/dist/transcription.d.ts +1 -0
  54. package/dist/video.d.ts +1 -0
  55. package/package.json +9 -5
package/dist/index.d.ts CHANGED
@@ -5,13 +5,13 @@ import type { AwaitOptions, Event, Snapshot } from "./generation.js";
5
5
  import { type ImageModel, type ImageRequest, type ImageRequestInput } from "./image.js";
6
6
  import { LLM } from "./effect.js";
7
7
  import { Media } from "./media.js";
8
- import { type CheckpointRequest, type CompactionRequest, type EndpointCompactOptions, type TriggerCompactOptions } from "./route/client.js";
8
+ import { type CheckpointRequest, type CompactionRequest, type EndpointCompactOptions, type StreamOptions, type TriggerCompactOptions } from "./route/client.js";
9
9
  import { RequestExecutor } from "./route/executor.js";
10
10
  import { LanguageModel, type CompactionCheckpointResponse, type CompactionResponse, type LLMRequest } from "./schema/index.js";
11
11
  import type { GenerateObjectDynamicOptions, GenerateObjectOptions, GenerateObjectResponse, LoopInput, RequestInput } from "./llm.js";
12
12
  import { type SpeechModel, type SpeechRequest, type SpeechRequestInput } from "./speech.js";
13
13
  import { type TranscriptionModel, type TranscriptionRequest, type TranscriptionRequestInput } from "./transcription.js";
14
- import { Tool, type FreeformOption, type ToolExecuteContext, type ToolSchema } from "./tool.js";
14
+ import type { NoExecute, ToolExecuteContext, ToolOptions, ToolSchema } from "./tool.js";
15
15
  import { type VideoModel, type VideoRequest, type VideoRequestInput } from "./video.js";
16
16
  /**
17
17
  * Promise-first entrypoint for scripts and non-Effect callers. One `ManagedRuntime` hosts the LLM, image, video, speech,
@@ -33,6 +33,8 @@ export type Services = AIClient.Services;
33
33
  * new handle rather than updating this one.
34
34
  */
35
35
  export type GenerationHandle<Response> = Snapshot & {
36
+ readonly snapshot: Snapshot;
37
+ readonly terminal: boolean;
36
38
  /** Serializable JSON; pass it back to `resume` from another process. */
37
39
  readonly token: unknown;
38
40
  readonly await: (options?: AwaitOptions & RunOptions) => Promise<Response>;
@@ -56,8 +58,8 @@ export declare const make: <R = never>(options?: Options<R>) => {
56
58
  write: (asset: Media.Asset, path: string, options?: RunOptions) => Promise<void>;
57
59
  llm: {
58
60
  request: typeof LLM.request;
59
- generate: <const Model extends LanguageModel>(input: RequestInput<Model> | LLMRequest, options?: RunOptions) => Promise<import("./effect.js").LLMResponse>;
60
- stream: <const Model extends LanguageModel>(input: RequestInput<Model> | LLMRequest, options?: RunOptions) => AsyncIterable<{
61
+ generate: <const Model extends LanguageModel>(input: RequestInput<Model> | LLMRequest, options?: StreamOptions & RunOptions) => Promise<import("./effect.js").LLMResponse>;
62
+ stream: <const Model extends LanguageModel>(input: RequestInput<Model> | LLMRequest, options?: StreamOptions & RunOptions) => AsyncIterable<{
61
63
  readonly type: "step-start";
62
64
  readonly index: number;
63
65
  } | {
@@ -277,7 +279,7 @@ export declare const make: <R = never>(options?: Options<R>) => {
277
279
  readonly encrypted?: never;
278
280
  }))>;
279
281
  /** Stream model calls, running their tool calls, until the model stops calling tools or `until` is true. */
280
- loop: <const Model extends LanguageModel>(input: LoopInput<Model>, options?: RunOptions) => AsyncIterable<{
282
+ loop: <const Model extends LanguageModel>(input: LoopInput<Model>, options?: StreamOptions & RunOptions) => AsyncIterable<{
281
283
  readonly type: "step-start";
282
284
  readonly index: number;
283
285
  } | {
@@ -506,6 +508,7 @@ export declare const make: <R = never>(options?: Options<R>) => {
506
508
  (request: CheckpointRequest, options: TriggerCompactOptions & RunOptions): Promise<CompactionCheckpointResponse>;
507
509
  (request: CompactionRequest, options?: EndpointCompactOptions & RunOptions): Promise<CompactionResponse>;
508
510
  };
511
+ canCompact: typeof import("./route/client.js").canCompact;
509
512
  };
510
513
  image: {
511
514
  request: typeof import("./image.js").request;
@@ -558,194 +561,189 @@ export declare const make: <R = never>(options?: Options<R>) => {
558
561
  start: <const Model extends ImageModel>(input: ImageRequestInput<Model> | ImageRequest, options?: RunOptions) => Promise<GenerationHandle<import("./image.js").ImageResponse>>;
559
562
  resume: (model: ImageModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./image.js").ImageResponse>>;
560
563
  };
561
- video: {
562
- request: typeof import("./video.js").request;
563
- start: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
564
- generate: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: AwaitOptions & RunOptions) => Promise<import("./video.js").VideoResponse>;
565
- resume: (model: VideoModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
566
- stream: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: AwaitOptions & RunOptions) => AsyncIterable<{
567
- readonly type: "video";
568
- readonly index: number;
569
- readonly video: Media.Asset;
570
- } | {
571
- readonly type: "generation-queued";
572
- readonly id: string;
573
- readonly position?: number | undefined;
574
- } | {
575
- readonly type: "generation-progress";
576
- readonly id: string;
577
- readonly progress?: number | undefined;
578
- } | {
579
- readonly type: "finish";
580
- readonly usage?: {
581
- readonly type: "seconds";
582
- readonly seconds: number;
564
+ decision: {
565
+ request: typeof import("./decision.js").request;
566
+ generate: <const Model extends DecisionModel, const Questions extends DecisionQuestions>(input: DecisionRequestInput<Model, Questions>, options?: RunOptions) => Promise<import("./decision.js").DecisionResponseFor<Questions>>;
567
+ };
568
+ /** Experimental: may change without compatibility guarantees. */
569
+ experimental: {
570
+ speech: {
571
+ request: typeof import("./speech.js").request;
572
+ generate: <const Model extends SpeechModel>(input: SpeechRequestInput<Model> | SpeechRequest, options?: RunOptions) => Promise<import("./speech.js").SpeechResponse>;
573
+ stream: <const Model extends SpeechModel>(input: SpeechRequestInput<Model> | SpeechRequest, options?: RunOptions) => AsyncIterable<{
574
+ readonly type: "audio-delta";
575
+ readonly chunk: Uint8Array<ArrayBufferLike>;
583
576
  } | {
584
- readonly type: "characters";
585
- readonly characters: number;
577
+ readonly type: "timestamps";
578
+ readonly items: readonly {
579
+ readonly text: string;
580
+ readonly startSeconds: number;
581
+ readonly endSeconds: number;
582
+ }[];
586
583
  } | {
587
- readonly type: "credits";
588
- readonly credits: number;
584
+ readonly type: "generation-queued";
585
+ readonly id: string;
586
+ readonly position?: number | undefined;
589
587
  } | {
590
- readonly type: "compute";
591
- readonly seconds: number;
588
+ readonly type: "generation-progress";
589
+ readonly id: string;
590
+ readonly progress?: number | undefined;
592
591
  } | {
593
- readonly type: "tokens";
594
- readonly input?: number | undefined;
595
- readonly output?: number | undefined;
596
- readonly total?: number | undefined;
597
- readonly details?: {
598
- readonly [x: string]: unknown;
592
+ readonly type: "finish";
593
+ readonly audio: Media.Asset;
594
+ readonly usage?: {
595
+ readonly type: "seconds";
596
+ readonly seconds: number;
597
+ } | {
598
+ readonly type: "characters";
599
+ readonly characters: number;
600
+ } | {
601
+ readonly type: "credits";
602
+ readonly credits: number;
603
+ } | {
604
+ readonly type: "compute";
605
+ readonly seconds: number;
606
+ } | {
607
+ readonly type: "tokens";
608
+ readonly input?: number | undefined;
609
+ readonly output?: number | undefined;
610
+ readonly total?: number | undefined;
611
+ readonly details?: {
612
+ readonly [x: string]: unknown;
613
+ } | undefined;
599
614
  } | undefined;
600
- } | undefined;
601
- readonly providerMetadata?: {
602
- readonly [x: string]: {
603
- readonly [x: string]: unknown;
604
- };
605
- } | undefined;
606
- }>;
607
- };
608
- speech: {
609
- request: typeof import("./speech.js").request;
610
- generate: <const Model extends SpeechModel>(input: SpeechRequestInput<Model> | SpeechRequest, options?: RunOptions) => Promise<import("./speech.js").SpeechResponse>;
611
- stream: <const Model extends SpeechModel>(input: SpeechRequestInput<Model> | SpeechRequest, options?: RunOptions) => AsyncIterable<{
612
- readonly type: "audio-delta";
613
- readonly chunk: Uint8Array<ArrayBufferLike>;
614
- } | {
615
- readonly type: "timestamps";
616
- readonly items: readonly {
617
- readonly text: string;
618
- readonly startSeconds: number;
619
- readonly endSeconds: number;
620
- }[];
621
- } | {
622
- readonly type: "generation-queued";
623
- readonly id: string;
624
- readonly position?: number | undefined;
625
- } | {
626
- readonly type: "generation-progress";
627
- readonly id: string;
628
- readonly progress?: number | undefined;
629
- } | {
630
- readonly type: "finish";
631
- readonly audio: Media.Asset;
632
- readonly usage?: {
633
- readonly type: "seconds";
634
- readonly seconds: number;
615
+ readonly providerMetadata?: {
616
+ readonly [x: string]: {
617
+ readonly [x: string]: unknown;
618
+ };
619
+ } | undefined;
620
+ }>;
621
+ };
622
+ transcription: {
623
+ request: typeof import("./transcription.js").request;
624
+ generate: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: AwaitOptions & RunOptions) => Promise<import("./transcription.js").TranscriptionResponse>;
625
+ stream: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: AwaitOptions & RunOptions) => AsyncIterable<{
626
+ readonly type: "text-delta";
627
+ readonly delta: string;
635
628
  } | {
636
- readonly type: "characters";
637
- readonly characters: number;
629
+ readonly type: "segment";
630
+ readonly segment: {
631
+ readonly text: string;
632
+ readonly startSeconds: number;
633
+ readonly endSeconds: number;
634
+ readonly speaker?: string | undefined;
635
+ };
638
636
  } | {
639
- readonly type: "credits";
640
- readonly credits: number;
637
+ readonly type: "generation-queued";
638
+ readonly id: string;
639
+ readonly position?: number | undefined;
641
640
  } | {
642
- readonly type: "compute";
643
- readonly seconds: number;
641
+ readonly type: "generation-progress";
642
+ readonly id: string;
643
+ readonly progress?: number | undefined;
644
644
  } | {
645
- readonly type: "tokens";
646
- readonly input?: number | undefined;
647
- readonly output?: number | undefined;
648
- readonly total?: number | undefined;
649
- readonly details?: {
650
- readonly [x: string]: unknown;
651
- } | undefined;
652
- } | undefined;
653
- readonly providerMetadata?: {
654
- readonly [x: string]: {
655
- readonly [x: string]: unknown;
656
- };
657
- } | undefined;
658
- }>;
659
- };
660
- transcription: {
661
- request: typeof import("./transcription.js").request;
662
- generate: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: AwaitOptions & RunOptions) => Promise<import("./transcription.js").TranscriptionResponse>;
663
- stream: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: AwaitOptions & RunOptions) => AsyncIterable<{
664
- readonly type: "text-delta";
665
- readonly delta: string;
666
- } | {
667
- readonly type: "segment";
668
- readonly segment: {
669
645
  readonly text: string;
670
- readonly startSeconds: number;
671
- readonly endSeconds: number;
672
- readonly speaker?: string | undefined;
673
- };
674
- } | {
675
- readonly type: "generation-queued";
676
- readonly id: string;
677
- readonly position?: number | undefined;
678
- } | {
679
- readonly type: "generation-progress";
680
- readonly id: string;
681
- readonly progress?: number | undefined;
682
- } | {
683
- readonly text: string;
684
- readonly segments?: readonly {
685
- readonly text: string;
686
- readonly startSeconds: number;
687
- readonly endSeconds: number;
688
- readonly speaker?: string | undefined;
689
- }[] | undefined;
690
- readonly words?: readonly {
691
- readonly text: string;
692
- readonly startSeconds: number;
693
- readonly endSeconds: number;
694
- readonly speaker?: string | undefined;
695
- readonly confidence?: number | undefined;
696
- }[] | undefined;
697
- readonly language?: string | undefined;
698
- readonly durationSeconds?: number | undefined;
699
- readonly usage?: {
700
- readonly type: "seconds";
701
- readonly seconds: number;
702
- } | {
703
- readonly type: "characters";
704
- readonly characters: number;
646
+ readonly segments?: readonly {
647
+ readonly text: string;
648
+ readonly startSeconds: number;
649
+ readonly endSeconds: number;
650
+ readonly speaker?: string | undefined;
651
+ }[] | undefined;
652
+ readonly words?: readonly {
653
+ readonly text: string;
654
+ readonly startSeconds: number;
655
+ readonly endSeconds: number;
656
+ readonly speaker?: string | undefined;
657
+ readonly confidence?: number | undefined;
658
+ }[] | undefined;
659
+ readonly language?: string | undefined;
660
+ readonly durationSeconds?: number | undefined;
661
+ readonly usage?: {
662
+ readonly type: "seconds";
663
+ readonly seconds: number;
664
+ } | {
665
+ readonly type: "characters";
666
+ readonly characters: number;
667
+ } | {
668
+ readonly type: "credits";
669
+ readonly credits: number;
670
+ } | {
671
+ readonly type: "compute";
672
+ readonly seconds: number;
673
+ } | {
674
+ readonly type: "tokens";
675
+ readonly input?: number | undefined;
676
+ readonly output?: number | undefined;
677
+ readonly total?: number | undefined;
678
+ readonly details?: {
679
+ readonly [x: string]: unknown;
680
+ } | undefined;
681
+ } | undefined;
682
+ readonly providerMetadata?: {
683
+ readonly [x: string]: {
684
+ readonly [x: string]: unknown;
685
+ };
686
+ } | undefined;
687
+ readonly type: "finish";
688
+ }>;
689
+ start: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
690
+ resume: (model: TranscriptionModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
691
+ };
692
+ video: {
693
+ request: typeof import("./video.js").request;
694
+ start: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
695
+ generate: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: AwaitOptions & RunOptions) => Promise<import("./video.js").VideoResponse>;
696
+ resume: (model: VideoModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
697
+ stream: <const Model extends VideoModel>(input: VideoRequestInput<Model> | VideoRequest, options?: AwaitOptions & RunOptions) => AsyncIterable<{
698
+ readonly type: "video";
699
+ readonly index: number;
700
+ readonly video: Media.Asset;
705
701
  } | {
706
- readonly type: "credits";
707
- readonly credits: number;
702
+ readonly type: "generation-queued";
703
+ readonly id: string;
704
+ readonly position?: number | undefined;
708
705
  } | {
709
- readonly type: "compute";
710
- readonly seconds: number;
706
+ readonly type: "generation-progress";
707
+ readonly id: string;
708
+ readonly progress?: number | undefined;
711
709
  } | {
712
- readonly type: "tokens";
713
- readonly input?: number | undefined;
714
- readonly output?: number | undefined;
715
- readonly total?: number | undefined;
716
- readonly details?: {
717
- readonly [x: string]: unknown;
710
+ readonly type: "finish";
711
+ readonly usage?: {
712
+ readonly type: "seconds";
713
+ readonly seconds: number;
714
+ } | {
715
+ readonly type: "characters";
716
+ readonly characters: number;
717
+ } | {
718
+ readonly type: "credits";
719
+ readonly credits: number;
720
+ } | {
721
+ readonly type: "compute";
722
+ readonly seconds: number;
723
+ } | {
724
+ readonly type: "tokens";
725
+ readonly input?: number | undefined;
726
+ readonly output?: number | undefined;
727
+ readonly total?: number | undefined;
728
+ readonly details?: {
729
+ readonly [x: string]: unknown;
730
+ } | undefined;
718
731
  } | undefined;
719
- } | undefined;
720
- readonly providerMetadata?: {
721
- readonly [x: string]: {
722
- readonly [x: string]: unknown;
723
- };
724
- } | undefined;
725
- readonly type: "finish";
726
- }>;
727
- start: <const Model extends TranscriptionModel>(input: TranscriptionRequestInput<Model> | TranscriptionRequest, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
728
- resume: (model: TranscriptionModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
729
- };
730
- decision: {
731
- request: typeof import("./decision.js").request;
732
- generate: <const Model extends DecisionModel, const Questions extends DecisionQuestions>(input: DecisionRequestInput<Model, Questions>, options?: RunOptions) => Promise<import("./decision.js").DecisionResponseFor<Questions>>;
732
+ readonly providerMetadata?: {
733
+ readonly [x: string]: {
734
+ readonly [x: string]: unknown;
735
+ };
736
+ } | undefined;
737
+ }>;
738
+ };
733
739
  };
734
740
  dispose: () => Promise<void>;
735
741
  };
736
742
  export type Client<R = never> = ReturnType<typeof make<R>>;
737
- /**
738
- * Promise counterpart of `Tool.make` for `ai.llm.loop`. A throw or rejection becomes the error result the model sees, the
739
- * returned value is sent unvalidated (`undefined` as `null`), and `signal` aborts when the loop is interrupted.
740
- */
741
- export declare const tool: <Parameters extends ToolSchema<any>>(config: {
742
- readonly description: string;
743
- readonly parameters: Parameters;
744
- readonly freeform?: FreeformOption<Parameters>;
745
- readonly execute: (params: Schema.Schema.Type<Parameters>, context: Partial<ToolExecuteContext> & {
746
- readonly signal: AbortSignal;
747
- }) => unknown;
748
- }) => Tool.ExecutableTool<Parameters, Schema.Unknown>;
743
+ /** `tool` from `@opencode/ai/effect`, with an `execute` that returns a value or a Promise and throws to fail. */
744
+ export declare const tool: <Parameters extends ToolSchema<any> = typeof Schema.Unknown, Success extends ToolSchema<any> = typeof Schema.Unknown, Result extends Schema.Schema.Type<Success> | PromiseLike<Schema.Schema.Type<Success>> | NoExecute = NoExecute>(config: ToolOptions<Parameters, Success, (params: Schema.Schema.Type<Parameters>, context: Partial<ToolExecuteContext> & {
745
+ signal: AbortSignal;
746
+ }) => Result>) => 0 extends 1 & Result ? import("./tool.js").ExecutableTool<Parameters, Success> : [Result, NoExecute] extends [NoExecute, Result] ? import("./tool.js").Tool<Parameters, Success> : import("./tool.js").ExecutableTool<Parameters, Success>;
749
747
  /** Default client over `RequestExecutor.fetchLayer` for scripts; the runtime builds its layer on first use. */
750
748
  export declare const ai: {
751
749
  run: <A, E>(effect: Effect.Effect<A, E, import("./image-client.js").ImageClientService | import("./effect.js").LLMClientService | RequestExecutor.RequestExecutorService | import("./decision-client.js").Service | import("./speech-client.js").SpeechClientService | import("./transcription-client.js").TranscriptionClientService | import("./video-client.js").VideoClientService>, options?: RunOptions) => Promise<A>;
@@ -762,10 +760,10 @@ export declare const ai: {
762
760
  request: typeof LLM.request;
763
761
  generate: <const Model extends LanguageModel>(input: LLMRequest<LanguageModel<{
764
762
  readonly [x: string]: unknown;
765
- }, import("./route/client.js").CompactionOperations | undefined>> | RequestInput<Model>, options?: RunOptions) => Promise<import("./effect.js").LLMResponse>;
763
+ }, import("./route/client.js").CompactionOperations | undefined>> | RequestInput<Model>, options?: StreamOptions & RunOptions) => Promise<import("./effect.js").LLMResponse>;
766
764
  stream: <const Model extends LanguageModel>(input: LLMRequest<LanguageModel<{
767
765
  readonly [x: string]: unknown;
768
- }, import("./route/client.js").CompactionOperations | undefined>> | RequestInput<Model>, options?: RunOptions) => AsyncIterable<{
766
+ }, import("./route/client.js").CompactionOperations | undefined>> | RequestInput<Model>, options?: StreamOptions & RunOptions) => AsyncIterable<{
769
767
  readonly type: "step-start";
770
768
  readonly index: number;
771
769
  } | {
@@ -985,7 +983,7 @@ export declare const ai: {
985
983
  readonly encrypted?: never;
986
984
  }))>;
987
985
  /** Stream model calls, running their tool calls, until the model stops calling tools or `until` is true. */
988
- loop: <const Model extends LanguageModel>(input: LoopInput<Model>, options?: RunOptions) => AsyncIterable<{
986
+ loop: <const Model extends LanguageModel>(input: LoopInput<Model>, options?: StreamOptions & RunOptions) => AsyncIterable<{
989
987
  readonly type: "step-start";
990
988
  readonly index: number;
991
989
  } | {
@@ -1214,6 +1212,7 @@ export declare const ai: {
1214
1212
  (request: CheckpointRequest, options: TriggerCompactOptions & RunOptions): Promise<CompactionCheckpointResponse>;
1215
1213
  (request: CompactionRequest, options?: EndpointCompactOptions & RunOptions): Promise<CompactionResponse>;
1216
1214
  };
1215
+ canCompact: typeof import("./route/client.js").canCompact;
1217
1216
  };
1218
1217
  image: {
1219
1218
  request: typeof import("./image.js").request;
@@ -1266,179 +1265,184 @@ export declare const ai: {
1266
1265
  start: <const Model extends ImageModel>(input: ImageRequest | ImageRequestInput<Model>, options?: RunOptions) => Promise<GenerationHandle<import("./image.js").ImageResponse>>;
1267
1266
  resume: (model: ImageModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./image.js").ImageResponse>>;
1268
1267
  };
1269
- video: {
1270
- request: typeof import("./video.js").request;
1271
- start: <const Model extends VideoModel>(input: VideoRequest | VideoRequestInput<Model>, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
1272
- generate: <const Model extends VideoModel>(input: VideoRequest | VideoRequestInput<Model>, options?: AwaitOptions & RunOptions) => Promise<import("./video.js").VideoResponse>;
1273
- resume: (model: VideoModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
1274
- stream: <const Model extends VideoModel>(input: VideoRequest | VideoRequestInput<Model>, options?: AwaitOptions & RunOptions) => AsyncIterable<{
1275
- readonly type: "video";
1276
- readonly index: number;
1277
- readonly video: Media.Asset;
1278
- } | {
1279
- readonly type: "generation-queued";
1280
- readonly id: string;
1281
- readonly position?: number | undefined;
1282
- } | {
1283
- readonly type: "generation-progress";
1284
- readonly id: string;
1285
- readonly progress?: number | undefined;
1286
- } | {
1287
- readonly type: "finish";
1288
- readonly usage?: {
1289
- readonly type: "seconds";
1290
- readonly seconds: number;
1268
+ decision: {
1269
+ request: typeof import("./decision.js").request;
1270
+ generate: <const Model extends DecisionModel, const Questions extends DecisionQuestions>(input: DecisionRequestInput<Model, Questions>, options?: RunOptions) => Promise<import("./decision.js").DecisionResponseFor<Questions>>;
1271
+ };
1272
+ /** Experimental: may change without compatibility guarantees. */
1273
+ experimental: {
1274
+ speech: {
1275
+ request: typeof import("./speech.js").request;
1276
+ generate: <const Model extends SpeechModel>(input: SpeechRequest | SpeechRequestInput<Model>, options?: RunOptions) => Promise<import("./speech.js").SpeechResponse>;
1277
+ stream: <const Model extends SpeechModel>(input: SpeechRequest | SpeechRequestInput<Model>, options?: RunOptions) => AsyncIterable<{
1278
+ readonly type: "audio-delta";
1279
+ readonly chunk: Uint8Array<ArrayBufferLike>;
1291
1280
  } | {
1292
- readonly type: "characters";
1293
- readonly characters: number;
1281
+ readonly type: "timestamps";
1282
+ readonly items: readonly {
1283
+ readonly text: string;
1284
+ readonly startSeconds: number;
1285
+ readonly endSeconds: number;
1286
+ }[];
1294
1287
  } | {
1295
- readonly type: "credits";
1296
- readonly credits: number;
1288
+ readonly type: "generation-queued";
1289
+ readonly id: string;
1290
+ readonly position?: number | undefined;
1297
1291
  } | {
1298
- readonly type: "compute";
1299
- readonly seconds: number;
1292
+ readonly type: "generation-progress";
1293
+ readonly id: string;
1294
+ readonly progress?: number | undefined;
1300
1295
  } | {
1301
- readonly type: "tokens";
1302
- readonly input?: number | undefined;
1303
- readonly output?: number | undefined;
1304
- readonly total?: number | undefined;
1305
- readonly details?: {
1306
- readonly [x: string]: unknown;
1296
+ readonly type: "finish";
1297
+ readonly audio: Media.Asset;
1298
+ readonly usage?: {
1299
+ readonly type: "seconds";
1300
+ readonly seconds: number;
1301
+ } | {
1302
+ readonly type: "characters";
1303
+ readonly characters: number;
1304
+ } | {
1305
+ readonly type: "credits";
1306
+ readonly credits: number;
1307
+ } | {
1308
+ readonly type: "compute";
1309
+ readonly seconds: number;
1310
+ } | {
1311
+ readonly type: "tokens";
1312
+ readonly input?: number | undefined;
1313
+ readonly output?: number | undefined;
1314
+ readonly total?: number | undefined;
1315
+ readonly details?: {
1316
+ readonly [x: string]: unknown;
1317
+ } | undefined;
1307
1318
  } | undefined;
1308
- } | undefined;
1309
- readonly providerMetadata?: {
1310
- readonly [x: string]: {
1311
- readonly [x: string]: unknown;
1312
- };
1313
- } | undefined;
1314
- }>;
1315
- };
1316
- speech: {
1317
- request: typeof import("./speech.js").request;
1318
- generate: <const Model extends SpeechModel>(input: SpeechRequest | SpeechRequestInput<Model>, options?: RunOptions) => Promise<import("./speech.js").SpeechResponse>;
1319
- stream: <const Model extends SpeechModel>(input: SpeechRequest | SpeechRequestInput<Model>, options?: RunOptions) => AsyncIterable<{
1320
- readonly type: "audio-delta";
1321
- readonly chunk: Uint8Array<ArrayBufferLike>;
1322
- } | {
1323
- readonly type: "timestamps";
1324
- readonly items: readonly {
1325
- readonly text: string;
1326
- readonly startSeconds: number;
1327
- readonly endSeconds: number;
1328
- }[];
1329
- } | {
1330
- readonly type: "generation-queued";
1331
- readonly id: string;
1332
- readonly position?: number | undefined;
1333
- } | {
1334
- readonly type: "generation-progress";
1335
- readonly id: string;
1336
- readonly progress?: number | undefined;
1337
- } | {
1338
- readonly type: "finish";
1339
- readonly audio: Media.Asset;
1340
- readonly usage?: {
1341
- readonly type: "seconds";
1342
- readonly seconds: number;
1319
+ readonly providerMetadata?: {
1320
+ readonly [x: string]: {
1321
+ readonly [x: string]: unknown;
1322
+ };
1323
+ } | undefined;
1324
+ }>;
1325
+ };
1326
+ transcription: {
1327
+ request: typeof import("./transcription.js").request;
1328
+ generate: <const Model extends TranscriptionModel>(input: TranscriptionRequest | TranscriptionRequestInput<Model>, options?: AwaitOptions & RunOptions) => Promise<import("./transcription.js").TranscriptionResponse>;
1329
+ stream: <const Model extends TranscriptionModel>(input: TranscriptionRequest | TranscriptionRequestInput<Model>, options?: AwaitOptions & RunOptions) => AsyncIterable<{
1330
+ readonly type: "text-delta";
1331
+ readonly delta: string;
1343
1332
  } | {
1344
- readonly type: "characters";
1345
- readonly characters: number;
1333
+ readonly type: "segment";
1334
+ readonly segment: {
1335
+ readonly text: string;
1336
+ readonly startSeconds: number;
1337
+ readonly endSeconds: number;
1338
+ readonly speaker?: string | undefined;
1339
+ };
1346
1340
  } | {
1347
- readonly type: "credits";
1348
- readonly credits: number;
1341
+ readonly type: "generation-queued";
1342
+ readonly id: string;
1343
+ readonly position?: number | undefined;
1349
1344
  } | {
1350
- readonly type: "compute";
1351
- readonly seconds: number;
1345
+ readonly type: "generation-progress";
1346
+ readonly id: string;
1347
+ readonly progress?: number | undefined;
1352
1348
  } | {
1353
- readonly type: "tokens";
1354
- readonly input?: number | undefined;
1355
- readonly output?: number | undefined;
1356
- readonly total?: number | undefined;
1357
- readonly details?: {
1358
- readonly [x: string]: unknown;
1359
- } | undefined;
1360
- } | undefined;
1361
- readonly providerMetadata?: {
1362
- readonly [x: string]: {
1363
- readonly [x: string]: unknown;
1364
- };
1365
- } | undefined;
1366
- }>;
1367
- };
1368
- transcription: {
1369
- request: typeof import("./transcription.js").request;
1370
- generate: <const Model extends TranscriptionModel>(input: TranscriptionRequest | TranscriptionRequestInput<Model>, options?: AwaitOptions & RunOptions) => Promise<import("./transcription.js").TranscriptionResponse>;
1371
- stream: <const Model extends TranscriptionModel>(input: TranscriptionRequest | TranscriptionRequestInput<Model>, options?: AwaitOptions & RunOptions) => AsyncIterable<{
1372
- readonly type: "text-delta";
1373
- readonly delta: string;
1374
- } | {
1375
- readonly type: "segment";
1376
- readonly segment: {
1377
1349
  readonly text: string;
1378
- readonly startSeconds: number;
1379
- readonly endSeconds: number;
1380
- readonly speaker?: string | undefined;
1381
- };
1382
- } | {
1383
- readonly type: "generation-queued";
1384
- readonly id: string;
1385
- readonly position?: number | undefined;
1386
- } | {
1387
- readonly type: "generation-progress";
1388
- readonly id: string;
1389
- readonly progress?: number | undefined;
1390
- } | {
1391
- readonly text: string;
1392
- readonly segments?: readonly {
1393
- readonly text: string;
1394
- readonly startSeconds: number;
1395
- readonly endSeconds: number;
1396
- readonly speaker?: string | undefined;
1397
- }[] | undefined;
1398
- readonly words?: readonly {
1399
- readonly text: string;
1400
- readonly startSeconds: number;
1401
- readonly endSeconds: number;
1402
- readonly speaker?: string | undefined;
1403
- readonly confidence?: number | undefined;
1404
- }[] | undefined;
1405
- readonly language?: string | undefined;
1406
- readonly durationSeconds?: number | undefined;
1407
- readonly usage?: {
1408
- readonly type: "seconds";
1409
- readonly seconds: number;
1410
- } | {
1411
- readonly type: "characters";
1412
- readonly characters: number;
1350
+ readonly segments?: readonly {
1351
+ readonly text: string;
1352
+ readonly startSeconds: number;
1353
+ readonly endSeconds: number;
1354
+ readonly speaker?: string | undefined;
1355
+ }[] | undefined;
1356
+ readonly words?: readonly {
1357
+ readonly text: string;
1358
+ readonly startSeconds: number;
1359
+ readonly endSeconds: number;
1360
+ readonly speaker?: string | undefined;
1361
+ readonly confidence?: number | undefined;
1362
+ }[] | undefined;
1363
+ readonly language?: string | undefined;
1364
+ readonly durationSeconds?: number | undefined;
1365
+ readonly usage?: {
1366
+ readonly type: "seconds";
1367
+ readonly seconds: number;
1368
+ } | {
1369
+ readonly type: "characters";
1370
+ readonly characters: number;
1371
+ } | {
1372
+ readonly type: "credits";
1373
+ readonly credits: number;
1374
+ } | {
1375
+ readonly type: "compute";
1376
+ readonly seconds: number;
1377
+ } | {
1378
+ readonly type: "tokens";
1379
+ readonly input?: number | undefined;
1380
+ readonly output?: number | undefined;
1381
+ readonly total?: number | undefined;
1382
+ readonly details?: {
1383
+ readonly [x: string]: unknown;
1384
+ } | undefined;
1385
+ } | undefined;
1386
+ readonly providerMetadata?: {
1387
+ readonly [x: string]: {
1388
+ readonly [x: string]: unknown;
1389
+ };
1390
+ } | undefined;
1391
+ readonly type: "finish";
1392
+ }>;
1393
+ start: <const Model extends TranscriptionModel>(input: TranscriptionRequest | TranscriptionRequestInput<Model>, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
1394
+ resume: (model: TranscriptionModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
1395
+ };
1396
+ video: {
1397
+ request: typeof import("./video.js").request;
1398
+ start: <const Model extends VideoModel>(input: VideoRequest | VideoRequestInput<Model>, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
1399
+ generate: <const Model extends VideoModel>(input: VideoRequest | VideoRequestInput<Model>, options?: AwaitOptions & RunOptions) => Promise<import("./video.js").VideoResponse>;
1400
+ resume: (model: VideoModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./video.js").VideoResponse>>;
1401
+ stream: <const Model extends VideoModel>(input: VideoRequest | VideoRequestInput<Model>, options?: AwaitOptions & RunOptions) => AsyncIterable<{
1402
+ readonly type: "video";
1403
+ readonly index: number;
1404
+ readonly video: Media.Asset;
1413
1405
  } | {
1414
- readonly type: "credits";
1415
- readonly credits: number;
1406
+ readonly type: "generation-queued";
1407
+ readonly id: string;
1408
+ readonly position?: number | undefined;
1416
1409
  } | {
1417
- readonly type: "compute";
1418
- readonly seconds: number;
1410
+ readonly type: "generation-progress";
1411
+ readonly id: string;
1412
+ readonly progress?: number | undefined;
1419
1413
  } | {
1420
- readonly type: "tokens";
1421
- readonly input?: number | undefined;
1422
- readonly output?: number | undefined;
1423
- readonly total?: number | undefined;
1424
- readonly details?: {
1425
- readonly [x: string]: unknown;
1414
+ readonly type: "finish";
1415
+ readonly usage?: {
1416
+ readonly type: "seconds";
1417
+ readonly seconds: number;
1418
+ } | {
1419
+ readonly type: "characters";
1420
+ readonly characters: number;
1421
+ } | {
1422
+ readonly type: "credits";
1423
+ readonly credits: number;
1424
+ } | {
1425
+ readonly type: "compute";
1426
+ readonly seconds: number;
1427
+ } | {
1428
+ readonly type: "tokens";
1429
+ readonly input?: number | undefined;
1430
+ readonly output?: number | undefined;
1431
+ readonly total?: number | undefined;
1432
+ readonly details?: {
1433
+ readonly [x: string]: unknown;
1434
+ } | undefined;
1426
1435
  } | undefined;
1427
- } | undefined;
1428
- readonly providerMetadata?: {
1429
- readonly [x: string]: {
1430
- readonly [x: string]: unknown;
1431
- };
1432
- } | undefined;
1433
- readonly type: "finish";
1434
- }>;
1435
- start: <const Model extends TranscriptionModel>(input: TranscriptionRequest | TranscriptionRequestInput<Model>, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
1436
- resume: (model: TranscriptionModel, token: unknown, options?: RunOptions) => Promise<GenerationHandle<import("./transcription.js").TranscriptionResponse>>;
1437
- };
1438
- decision: {
1439
- request: typeof import("./decision.js").request;
1440
- generate: <const Model extends DecisionModel, const Questions extends DecisionQuestions>(input: DecisionRequestInput<Model, Questions>, options?: RunOptions) => Promise<import("./decision.js").DecisionResponseFor<Questions>>;
1436
+ readonly providerMetadata?: {
1437
+ readonly [x: string]: {
1438
+ readonly [x: string]: unknown;
1439
+ };
1440
+ } | undefined;
1441
+ }>;
1442
+ };
1441
1443
  };
1442
1444
  dispose: () => Promise<void>;
1443
1445
  };
1446
+ export { AIError } from "./schema/index.js";
1444
1447
  export * as AI from "./index.js";
1448
+ export type { ExecutableTool, Tool, ToolOptions, Tools } from "./tool.js";