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

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.
@@ -16,6 +16,14 @@ export type DeepgramSpeechOptions = {
16
16
  } & Record<string, unknown>;
17
17
  export type Request = SpeechRequestFor<DeepgramSpeechOptions>;
18
18
  export declare const protocol: MediaProtocol.Streamed<Request, {
19
+ readonly id: string;
20
+ readonly type: "generation-queued";
21
+ readonly position?: number | undefined;
22
+ } | {
23
+ readonly id: string;
24
+ readonly type: "generation-progress";
25
+ readonly progress?: number | undefined;
26
+ } | {
19
27
  readonly type: "audio-delta";
20
28
  readonly chunk: Uint8Array<ArrayBufferLike>;
21
29
  } | {
@@ -67,6 +75,14 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
67
75
  export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<DeepgramSpeechOptions>;
68
76
  export declare const DeepgramSpeech: {
69
77
  readonly protocol: MediaProtocol.Streamed<Request, {
78
+ readonly id: string;
79
+ readonly type: "generation-queued";
80
+ readonly position?: number | undefined;
81
+ } | {
82
+ readonly id: string;
83
+ readonly type: "generation-progress";
84
+ readonly progress?: number | undefined;
85
+ } | {
70
86
  readonly type: "audio-delta";
71
87
  readonly chunk: Uint8Array<ArrayBufferLike>;
72
88
  } | {
@@ -19,6 +19,14 @@ export type ElevenLabsSpeechOptions = {
19
19
  } & Record<string, unknown>;
20
20
  export type Request = SpeechRequestFor<ElevenLabsSpeechOptions>;
21
21
  export declare const protocol: MediaProtocol.Streamed<Request, {
22
+ readonly id: string;
23
+ readonly type: "generation-queued";
24
+ readonly position?: number | undefined;
25
+ } | {
26
+ readonly id: string;
27
+ readonly type: "generation-progress";
28
+ readonly progress?: number | undefined;
29
+ } | {
22
30
  readonly type: "audio-delta";
23
31
  readonly chunk: Uint8Array<ArrayBufferLike>;
24
32
  } | {
@@ -70,6 +78,14 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
70
78
  export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<ElevenLabsSpeechOptions>;
71
79
  export declare const ElevenLabsSpeech: {
72
80
  readonly protocol: MediaProtocol.Streamed<Request, {
81
+ readonly id: string;
82
+ readonly type: "generation-queued";
83
+ readonly position?: number | undefined;
84
+ } | {
85
+ readonly id: string;
86
+ readonly type: "generation-progress";
87
+ readonly progress?: number | undefined;
88
+ } | {
73
89
  readonly type: "audio-delta";
74
90
  readonly chunk: Uint8Array<ArrayBufferLike>;
75
91
  } | {
@@ -26,6 +26,14 @@ interface State extends SpeechStream.Audio, GeminiGenerateContent.Metadata {
26
26
  readonly mimeType?: string;
27
27
  }
28
28
  export declare const protocol: MediaProtocol.Streamed<Request, {
29
+ readonly id: string;
30
+ readonly type: "generation-queued";
31
+ readonly position?: number | undefined;
32
+ } | {
33
+ readonly id: string;
34
+ readonly type: "generation-progress";
35
+ readonly progress?: number | undefined;
36
+ } | {
29
37
  readonly type: "audio-delta";
30
38
  readonly chunk: Uint8Array<ArrayBufferLike>;
31
39
  } | {
@@ -77,6 +85,14 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
77
85
  export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<GoogleSpeechOptions>;
78
86
  export declare const GoogleSpeech: {
79
87
  readonly protocol: MediaProtocol.Streamed<Request, {
88
+ readonly id: string;
89
+ readonly type: "generation-queued";
90
+ readonly position?: number | undefined;
91
+ } | {
92
+ readonly id: string;
93
+ readonly type: "generation-progress";
94
+ readonly progress?: number | undefined;
95
+ } | {
80
96
  readonly type: "audio-delta";
81
97
  readonly chunk: Uint8Array<ArrayBufferLike>;
82
98
  } | {
@@ -16,6 +16,14 @@ interface State extends SpeechStream.Audio {
16
16
  readonly usage?: MediaUsage;
17
17
  }
18
18
  export declare const protocol: MediaProtocol.Streamed<Request, {
19
+ readonly id: string;
20
+ readonly type: "generation-queued";
21
+ readonly position?: number | undefined;
22
+ } | {
23
+ readonly id: string;
24
+ readonly type: "generation-progress";
25
+ readonly progress?: number | undefined;
26
+ } | {
19
27
  readonly type: "audio-delta";
20
28
  readonly chunk: Uint8Array<ArrayBufferLike>;
21
29
  } | {
@@ -67,6 +75,14 @@ export declare const protocol: MediaProtocol.Streamed<Request, {
67
75
  export declare const model: (input: MediaRoute.ModelInput) => SpeechModel<OpenAISpeechOptions>;
68
76
  export declare const OpenAISpeech: {
69
77
  readonly protocol: MediaProtocol.Streamed<Request, {
78
+ readonly id: string;
79
+ readonly type: "generation-queued";
80
+ readonly position?: number | undefined;
81
+ } | {
82
+ readonly id: string;
83
+ readonly type: "generation-progress";
84
+ readonly progress?: number | undefined;
85
+ } | {
70
86
  readonly type: "audio-delta";
71
87
  readonly chunk: Uint8Array<ArrayBufferLike>;
72
88
  } | {
@@ -3,7 +3,7 @@ import { Auth } from "./auth.js";
3
3
  import { Endpoint } from "./endpoint.js";
4
4
  import { type Interface } from "./executor-service.js";
5
5
  import { MediaProtocol } from "./media-protocol.js";
6
- import { Generation, type AwaitOptions, type Observation } from "../generation.js";
6
+ import { Generation } from "../generation.js";
7
7
  import { AIError, HttpOptions, ProviderID } from "../schema/index.js";
8
8
  export type Execute = Interface["execute"];
9
9
  /** The minimum a media request must carry for the route to build a transport request. */
@@ -30,7 +30,7 @@ export declare const deployment: (input: {
30
30
  readonly http?: HttpOptions.Input;
31
31
  }, auth: Auth.Definition) => Omit<ModelInput, "id">;
32
32
  /** One request, one response. */
33
- export interface Route<Request extends MediaRequest, Response> {
33
+ export interface InlineRoute<Request extends MediaRequest, Response> {
34
34
  readonly kind: "inline";
35
35
  readonly id: string;
36
36
  readonly provider: ProviderID;
@@ -56,7 +56,7 @@ export interface StreamRoute<Request extends MediaRequest, Event, Response> {
56
56
  readonly stream: (request: Request, execute: Execute) => Stream.Stream<Event, AIError>;
57
57
  readonly generate: (request: Request, execute: Execute) => Effect.Effect<Response, AIError>;
58
58
  }
59
- export type AnyRoute<Request extends MediaRequest, Event, Response> = Route<Request, Response> | StreamRoute<Request, Event, Response> | QueuedRoute<Request, Response>;
59
+ export type AnyRoute<Request extends MediaRequest, Event, Response> = InlineRoute<Request, Response> | StreamRoute<Request, Event, Response> | QueuedRoute<Request, Response>;
60
60
  export interface Composition<Request extends MediaRequest> {
61
61
  readonly endpoint: Endpoint.Definition<MediaProtocol.Body, Request>;
62
62
  readonly auth: Auth.Definition;
@@ -79,7 +79,7 @@ export interface StreamInput<Request extends MediaRequest, Event, Response, Fram
79
79
  * rejection, URL and query rendering, auth headers, JSON, multipart, or binary encoding, and handing responses back
80
80
  * to the protocol.
81
81
  */
82
- export declare const inline: <Request extends MediaRequest, Response>(input: InlineInput<Request, Response>) => Route<Request, Response>;
82
+ export declare const inline: <Request extends MediaRequest, Response>(input: InlineInput<Request, Response>) => InlineRoute<Request, Response>;
83
83
  /**
84
84
  * Compose a queued media protocol the same way, adding `start`/`resume` handles whose polls reuse the route's auth,
85
85
  * deployment headers, and (for `start`) the request's `http` overlay. The token is decoded once at the boundary and
@@ -88,14 +88,4 @@ export declare const inline: <Request extends MediaRequest, Response>(input: Inl
88
88
  export declare const queued: <Request extends MediaRequest, Response, Token>(input: QueuedInput<Request, Response, Token>) => QueuedRoute<Request, Response>;
89
89
  /** Compose a streaming media protocol; `generate` runs the same stream in `generate` mode and folds it with `collect`. */
90
90
  export declare const stream: <Request extends MediaRequest, Event, Response, Frame, State>(input: StreamInput<Request, Event, Response, Frame, State>) => StreamRoute<Request, Event, Response>;
91
- export declare const dispatch: <Event, Response>(input: {
92
- readonly modality: string;
93
- readonly execute: Execute;
94
- readonly responseEvents: (response: Response) => ReadonlyArray<Event>;
95
- }) => {
96
- start: <Request extends MediaRequest>(route: AnyRoute<Request, Event, Response>, request: Request) => Effect.Effect<Generation<Response>, AIError, never>;
97
- resume: <Request extends MediaRequest>(route: AnyRoute<Request, Event, Response>, model: MediaRequest["model"], token: unknown) => Effect.Effect<Generation<Response>, AIError, never>;
98
- generate: <Request extends MediaRequest>(route: AnyRoute<Request, Event, Response>, request: Request, options?: AwaitOptions) => Effect.Effect<Response, AIError, never>;
99
- stream: <Request extends MediaRequest>(route: AnyRoute<Request, Event, Response>, request: Request, options?: AwaitOptions) => Stream.Stream<Event | Observation, AIError>;
100
- };
101
91
  export * as MediaRoute from "./media.js";
@@ -5,7 +5,7 @@ import { Endpoint } from "./endpoint.js";
5
5
  import { RequestExecutorService } from "./executor-service.js";
6
6
  import { RequestExecutor } from "./executor.js";
7
7
  import { MediaProtocol } from "./media-protocol.js";
8
- import { Generation, resultEvents } from "../generation.js";
8
+ import { Generation } from "../generation.js";
9
9
  import { AIError, AIErrorReason, HttpOptions, InvalidRequestError, ProviderID, UnsupportedOperationError, mergeHttpOptions, } from "../schema/index.js";
10
10
  import { encodeJson } from "../utils/json.js";
11
11
  import { sanitizeSurrogates } from "../utils/sanitize.js";
@@ -112,41 +112,6 @@ export const stream = (input) => {
112
112
  generate: (request, execute) => events(request, execute, "generate").pipe(Stream.runCollect, Effect.flatMap(input.collect)),
113
113
  };
114
114
  };
115
- export const dispatch = (input) => {
116
- const notQueued = (route, operation) => new AIError({
117
- reason: new UnsupportedOperationError({
118
- operation: `${input.modality}.${operation}`,
119
- provider: route.provider,
120
- route: route.id,
121
- message: `${route.provider}/${route.id} is not a queued route; use generate or stream`,
122
- }),
123
- });
124
- const start = (route, request) => {
125
- if (route.kind !== "queued")
126
- return Effect.fail(notQueued(route, "start"));
127
- return route.start(request, input.execute);
128
- };
129
- return {
130
- start,
131
- resume: (route, model, token) => {
132
- if (route.kind !== "queued")
133
- return Effect.fail(notQueued(route, "resume"));
134
- return route.resume(model, token, input.execute);
135
- },
136
- generate: (route, request, options) => {
137
- if (route.kind !== "queued")
138
- return route.generate(request, input.execute);
139
- return start(route, request).pipe(Effect.flatMap((generation) => generation.await(options)));
140
- },
141
- stream: (route, request, options) => {
142
- if (route.kind === "stream")
143
- return route.stream(request, input.execute);
144
- if (route.kind === "queued")
145
- return Stream.unwrap(start(route, request).pipe(Effect.map((generation) => resultEvents(generation, input.responseEvents, options))));
146
- return Stream.fromIterableEffect(Effect.map(route.generate(request, input.execute), input.responseEvents));
147
- },
148
- };
149
- };
150
115
  // ---------------------------------------------------------------------------
151
116
  // Transport plumbing shared by every kind
152
117
  // ---------------------------------------------------------------------------
@@ -1,23 +1,66 @@
1
- import { Context, Effect, Layer, Stream } from "effect";
2
- import { RequestExecutor } from "./route/executor.js";
3
- import type { AIError } from "./schema/index.js";
4
- import type { SpeechEvent, SpeechOptions, SpeechRequestFor, SpeechResponse } from "./speech.js";
5
- export interface Interface {
6
- readonly generate: <Options extends SpeechOptions>(request: SpeechRequestFor<Options>) => Effect.Effect<SpeechResponse, AIError>;
7
- readonly stream: <Options extends SpeechOptions>(request: SpeechRequestFor<Options>) => Stream.Stream<SpeechEvent, AIError>;
8
- }
1
+ import { Context } from "effect";
2
+ import { MediaClient } from "./media-client.js";
3
+ import { type SpeechEvent, type SpeechRequestFor, type SpeechResponse } from "./speech.js";
4
+ export type Interface = MediaClient.Interface<SpeechRequestFor, SpeechEvent, SpeechResponse>;
9
5
  declare const SpeechClientService_base: Context.ServiceClass<SpeechClientService, "@opencode/SpeechClient", Interface>;
10
6
  export declare class SpeechClientService extends SpeechClientService_base {
11
7
  }
12
8
  export declare const Service: typeof SpeechClientService;
13
9
  export type Service = SpeechClientService;
14
- export declare const generate: <Options extends SpeechOptions>(request: SpeechRequestFor<Options>) => Effect.Effect<SpeechResponse, AIError, Service>;
15
- export declare const stream: <Options extends SpeechOptions>(request: SpeechRequestFor<Options>) => Stream.Stream<SpeechEvent, AIError, Service>;
16
- export declare const layer: Layer.Layer<Service, never, RequestExecutor.Service>;
17
10
  export declare const SpeechClient: {
11
+ readonly layer: import("effect/Layer").Layer<SpeechClientService, never, import("./route/executor-service.js").RequestExecutorService>;
12
+ readonly generate: (request: SpeechRequestFor, options?: import("./generation.js").AwaitOptions) => import("effect/Effect").Effect<SpeechResponse, import("./index.js").AIError, SpeechClientService>;
13
+ readonly stream: (request: SpeechRequestFor, options?: import("./generation.js").AwaitOptions) => import("effect/Stream").Stream<import("./generation.js").Observation | {
14
+ readonly type: "audio-delta";
15
+ readonly chunk: Uint8Array<ArrayBufferLike>;
16
+ } | {
17
+ readonly type: "timestamps";
18
+ readonly items: readonly {
19
+ readonly text: string;
20
+ readonly startSeconds: number;
21
+ readonly endSeconds: number;
22
+ }[];
23
+ } | {
24
+ readonly type: "finish";
25
+ readonly audio: import("./media.js").Asset;
26
+ readonly providerMetadata?: {
27
+ readonly [x: string]: {
28
+ readonly [x: string]: unknown;
29
+ };
30
+ } | undefined;
31
+ readonly usage?: {
32
+ readonly type: "tokens";
33
+ readonly input?: number | undefined;
34
+ readonly output?: number | undefined;
35
+ readonly total?: number | undefined;
36
+ readonly details?: {
37
+ readonly [x: string]: unknown;
38
+ } | undefined;
39
+ } | {
40
+ readonly type: "seconds";
41
+ readonly seconds: number;
42
+ } | {
43
+ readonly type: "characters";
44
+ readonly characters: number;
45
+ } | {
46
+ readonly type: "credits";
47
+ readonly credits: number;
48
+ } | {
49
+ readonly type: "compute";
50
+ readonly seconds: number;
51
+ } | undefined;
52
+ readonly notices?: readonly {
53
+ readonly type: "other" | "moderated" | "filtered";
54
+ readonly message: string;
55
+ readonly providerMetadata?: {
56
+ readonly [x: string]: {
57
+ readonly [x: string]: unknown;
58
+ };
59
+ } | undefined;
60
+ }[] | undefined;
61
+ }, import("./index.js").AIError, SpeechClientService>;
62
+ readonly start: (request: SpeechRequestFor) => import("effect/Effect").Effect<import("./generation.js").Generation<SpeechResponse>, import("./index.js").AIError, SpeechClientService>;
63
+ readonly resume: (model: import("./speech.js").SpeechModel<import("./media-model.js").MediaModel.Options>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<SpeechResponse>, import("./index.js").AIError, SpeechClientService>;
18
64
  readonly Service: typeof SpeechClientService;
19
- readonly layer: Layer.Layer<SpeechClientService, never, import("./route/executor-service.js").RequestExecutorService>;
20
- readonly generate: <Options extends SpeechOptions>(request: SpeechRequestFor<Options>) => Effect.Effect<SpeechResponse, AIError, Service>;
21
- readonly stream: <Options extends SpeechOptions>(request: SpeechRequestFor<Options>) => Stream.Stream<SpeechEvent, AIError, Service>;
22
65
  };
23
66
  export {};
@@ -1,26 +1,21 @@
1
- import { Context, Effect, Layer, Stream } from "effect";
2
- import { RequestExecutor } from "./route/executor.js";
1
+ import { Context } from "effect";
2
+ import { MediaClient } from "./media-client.js";
3
+ import { SpeechTimestampsEvent, SpeechFinishEvent, } from "./speech.js";
3
4
  export class SpeechClientService extends Context.Service()("@opencode/SpeechClient") {
4
5
  }
5
6
  export const Service = SpeechClientService;
6
- export const generate = (request) => Effect.gen(function* () {
7
- const client = yield* Service;
8
- return yield* client.generate(request);
9
- });
10
- export const stream = (request) => Stream.unwrap(Effect.gen(function* () {
11
- const client = yield* Service;
12
- return client.stream(request);
13
- }));
14
- export const layer = Layer.effect(Service, Effect.gen(function* () {
15
- const executor = yield* RequestExecutor.Service;
16
- return Service.of({
17
- generate: (request) => request.model.route.generate(request, executor.execute),
18
- stream: (request) => request.model.route.stream(request, executor.execute),
19
- });
20
- }));
21
7
  export const SpeechClient = {
22
8
  Service,
23
- layer,
24
- generate,
25
- stream,
9
+ ...MediaClient.make(Service, {
10
+ modality: "speech",
11
+ responseEvents: (response) => [
12
+ ...(response.timestamps === undefined ? [] : [SpeechTimestampsEvent.make({ items: response.timestamps })]),
13
+ SpeechFinishEvent.make({
14
+ audio: response.audio,
15
+ usage: response.usage,
16
+ notices: response.notices,
17
+ providerMetadata: response.providerMetadata,
18
+ }),
19
+ ],
20
+ }),
26
21
  };