@opencode/ai 0.0.0-dev-465 → 0.0.0-dev-468
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.
- package/README.md +27 -16
- package/dist/cache-policy.d.ts +1 -1
- package/dist/cache-policy.js +2 -2
- package/dist/decision-client.d.ts +3 -3
- package/dist/decision.d.ts +13 -120
- package/dist/decision.js +17 -13
- package/dist/effect.d.ts +8 -6
- package/dist/effect.js +4 -3
- package/dist/effort-updates.d.ts +1 -1
- package/dist/effort-updates.js +2 -2
- package/dist/experimental/cloudflare-run-extraction.d.ts +7 -3
- package/dist/experimental/cloudflare-run-extraction.js +4 -1
- package/dist/experimental/extraction.d.ts +12 -38
- package/dist/experimental/extraction.js +13 -11
- package/dist/experimental.d.ts +8 -8
- package/dist/experimental.js +4 -4
- package/dist/image-client.d.ts +11 -5
- package/dist/image-client.js +1 -1
- package/dist/image.d.ts +21 -62
- package/dist/image.js +16 -13
- package/dist/index.d.ts +20 -14
- package/dist/index.js +6 -3
- package/dist/llm.d.ts +60 -25
- package/dist/llm.js +126 -38
- package/dist/protocols/alibaba-images.d.ts +2 -2
- package/dist/protocols/alibaba-messages.js +3 -3
- package/dist/protocols/anthropic-messages.d.ts +1 -1
- package/dist/protocols/anthropic-messages.js +4 -3
- package/dist/protocols/assemblyai-transcription.d.ts +2 -2
- package/dist/protocols/cartesia-speech.d.ts +2 -2
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
- package/dist/protocols/deepgram-speech.d.ts +2 -2
- package/dist/protocols/deepgram-transcription.d.ts +2 -2
- package/dist/protocols/elevenlabs-speech.d.ts +2 -2
- package/dist/protocols/elevenlabs-transcription.d.ts +2 -2
- package/dist/protocols/gemini.js +2 -8
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-speech.d.ts +2 -2
- package/dist/protocols/google-transcription.d.ts +2 -2
- package/dist/protocols/google-video.d.ts +2 -2
- package/dist/protocols/meta-images.d.ts +2 -2
- package/dist/protocols/meta-responses.js +4 -3
- package/dist/protocols/minimax-images.d.ts +2 -2
- package/dist/protocols/open-responses.d.ts +1 -21
- package/dist/protocols/openai-chat.d.ts +1 -21
- package/dist/protocols/openai-chat.js +7 -9
- package/dist/protocols/openai-decisions.js +1 -1
- package/dist/protocols/openai-images.d.ts +2 -2
- package/dist/protocols/openai-responses.js +0 -1
- package/dist/protocols/openai-speech.d.ts +2 -2
- package/dist/protocols/openai-transcription.d.ts +2 -2
- package/dist/protocols/runway-video.d.ts +2 -2
- package/dist/protocols/shared.d.ts +1 -1
- package/dist/protocols/shared.js +2 -2
- package/dist/protocols/system-one.d.ts +4 -4
- package/dist/protocols/utils/responses-checkpoint.js +1 -1
- package/dist/protocols/utils/responses-compaction.d.ts +1 -1
- package/dist/protocols/utils/responses-compaction.js +4 -3
- package/dist/protocols/utils/tool-stream.d.ts +3 -63
- package/dist/protocols/xai-images.d.ts +2 -2
- package/dist/protocols/xai-video.d.ts +2 -2
- package/dist/protocols/zai-images.d.ts +2 -2
- package/dist/protocols/zai-messages.js +3 -3
- package/dist/provider-error.js +4 -4
- package/dist/providers/vercel-ai-gateway.js +4 -3
- package/dist/route/client.d.ts +43 -19
- package/dist/route/client.js +30 -18
- package/dist/route/decision.d.ts +6 -6
- package/dist/schema/errors.d.ts +1 -2
- package/dist/schema/errors.js +1 -2
- package/dist/schema/events.d.ts +61 -769
- package/dist/schema/events.js +3 -30
- package/dist/schema/messages.d.ts +20 -92
- package/dist/schema/messages.js +1 -52
- package/dist/speech-client.d.ts +5 -5
- package/dist/speech.d.ts +17 -19
- package/dist/speech.js +16 -12
- package/dist/testing.d.ts +8 -168
- package/dist/tool-runtime.js +12 -30
- package/dist/transcription-client.d.ts +5 -5
- package/dist/transcription.d.ts +17 -19
- package/dist/transcription.js +16 -12
- package/dist/video-client.d.ts +5 -5
- package/dist/video-client.js +1 -1
- package/dist/video.d.ts +18 -20
- package/dist/video.js +16 -12
- package/package.json +3 -3
package/dist/schema/events.js
CHANGED
|
@@ -3,7 +3,6 @@ import { LLM } from "@opencode/schema/llm";
|
|
|
3
3
|
import { ContentBlockID, ToolCallID } from "./ids.js";
|
|
4
4
|
import { Message, CompactionPart, ToolCallPart, ToolOutput, ToolResultPart, ToolResultValue, } from "./messages.js";
|
|
5
5
|
import { ProviderMetadata } from "./options.js";
|
|
6
|
-
import { ProviderFailureClassification } from "./errors.js";
|
|
7
6
|
import { Media } from "../media.js";
|
|
8
7
|
export const FinishReason = LLM.FinishReason;
|
|
9
8
|
/**
|
|
@@ -209,15 +208,6 @@ export const ToolResult = Schema.Struct({
|
|
|
209
208
|
providerExecuted: Schema.optional(Schema.Boolean),
|
|
210
209
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
211
210
|
}).annotate({ identifier: "LLM.Event.ToolResult" });
|
|
212
|
-
export const ToolError = Schema.Struct({
|
|
213
|
-
type: Schema.tag("tool-error"),
|
|
214
|
-
id: ToolCallID,
|
|
215
|
-
name: Schema.String,
|
|
216
|
-
namespace: Schema.optional(Schema.String),
|
|
217
|
-
message: Schema.String,
|
|
218
|
-
error: Schema.optional(Schema.Defect()),
|
|
219
|
-
providerMetadata: Schema.optional(ProviderMetadata),
|
|
220
|
-
}).annotate({ identifier: "LLM.Event.ToolError" });
|
|
221
211
|
export const FinishReasonDetails = Schema.Struct({
|
|
222
212
|
normalized: FinishReason,
|
|
223
213
|
raw: Schema.optional(Schema.String),
|
|
@@ -237,6 +227,8 @@ export const Finish = Schema.Struct({
|
|
|
237
227
|
type: Schema.tag("finish"),
|
|
238
228
|
reason: FinishReasonDetails,
|
|
239
229
|
usage: Schema.optional(Usage),
|
|
230
|
+
/** The final assistant message, set by `ai.stream` and `ai.loop`. */
|
|
231
|
+
message: Schema.optional(Message),
|
|
240
232
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
241
233
|
}).annotate({ identifier: "LLM.Event.Finish" });
|
|
242
234
|
/** A generated media asset (image, audio, …) emitted by the model as first-class output rather than a tool result. */
|
|
@@ -245,12 +237,6 @@ export const MediaEvent = Schema.Struct({
|
|
|
245
237
|
media: Media.AssetSchema,
|
|
246
238
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
247
239
|
}).annotate({ identifier: "LLM.Event.Media" });
|
|
248
|
-
export const ProviderErrorEvent = Schema.Struct({
|
|
249
|
-
type: Schema.tag("provider-error"),
|
|
250
|
-
message: Schema.String,
|
|
251
|
-
classification: Schema.optional(ProviderFailureClassification),
|
|
252
|
-
providerMetadata: Schema.optional(ProviderMetadata),
|
|
253
|
-
}).annotate({ identifier: "LLM.Event.ProviderError" });
|
|
254
240
|
/** One provider frame as received, emitted before the events parsed from it when the request sets `includeRaw`. */
|
|
255
241
|
export const RawEvent = Schema.Struct({
|
|
256
242
|
type: Schema.tag("raw"),
|
|
@@ -271,11 +257,9 @@ const llmEventTagged = Schema.Union([
|
|
|
271
257
|
ToolInputError,
|
|
272
258
|
ToolCall,
|
|
273
259
|
ToolResult,
|
|
274
|
-
ToolError,
|
|
275
260
|
MediaEvent,
|
|
276
261
|
StepFinish,
|
|
277
262
|
Finish,
|
|
278
|
-
ProviderErrorEvent,
|
|
279
263
|
RawEvent,
|
|
280
264
|
]).pipe(Schema.toTaggedUnion("type"));
|
|
281
265
|
const contentBlockID = (value) => ContentBlockID.make(value);
|
|
@@ -304,7 +288,6 @@ export const LLMEvent = Object.assign(llmEventTagged, {
|
|
|
304
288
|
id: toolCallID(input.id),
|
|
305
289
|
output: input.output === undefined ? undefined : ToolOutput.make(input.output.structured, input.output.content),
|
|
306
290
|
}),
|
|
307
|
-
toolError: (input) => ToolError.make({ ...input, id: toolCallID(input.id) }),
|
|
308
291
|
media: MediaEvent.make,
|
|
309
292
|
stepFinish: (input) => StepFinish.make({
|
|
310
293
|
...input,
|
|
@@ -314,7 +297,6 @@ export const LLMEvent = Object.assign(llmEventTagged, {
|
|
|
314
297
|
...input,
|
|
315
298
|
usage: input.usage === undefined ? undefined : Usage.from(input.usage),
|
|
316
299
|
}),
|
|
317
|
-
providerError: ProviderErrorEvent.make,
|
|
318
300
|
raw: RawEvent.make,
|
|
319
301
|
is: {
|
|
320
302
|
compaction: llmEventTagged.guards.compaction,
|
|
@@ -331,11 +313,9 @@ export const LLMEvent = Object.assign(llmEventTagged, {
|
|
|
331
313
|
toolInputError: llmEventTagged.guards["tool-input-error"],
|
|
332
314
|
toolCall: llmEventTagged.guards["tool-call"],
|
|
333
315
|
toolResult: llmEventTagged.guards["tool-result"],
|
|
334
|
-
toolError: llmEventTagged.guards["tool-error"],
|
|
335
316
|
media: llmEventTagged.guards.media,
|
|
336
317
|
stepFinish: llmEventTagged.guards["step-finish"],
|
|
337
318
|
finish: llmEventTagged.guards.finish,
|
|
338
|
-
providerError: llmEventTagged.guards["provider-error"],
|
|
339
319
|
raw: llmEventTagged.guards.raw,
|
|
340
320
|
},
|
|
341
321
|
});
|
|
@@ -377,13 +357,6 @@ const appendEvent = (state, event) => {
|
|
|
377
357
|
finishReason: event.reason,
|
|
378
358
|
};
|
|
379
359
|
}
|
|
380
|
-
if (LLMEvent.is.providerError(event)) {
|
|
381
|
-
return {
|
|
382
|
-
...state,
|
|
383
|
-
events,
|
|
384
|
-
finishReason: state.finishReason ?? { normalized: "error" },
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
360
|
return {
|
|
388
361
|
...state,
|
|
389
362
|
events,
|
|
@@ -585,7 +558,7 @@ export class LLMResponse extends Schema.Class("LLM.Response")({
|
|
|
585
558
|
LLMResponse.empty = emptyResponseState;
|
|
586
559
|
/** Purely fold one provider-neutral event into the attempt assembly state. */
|
|
587
560
|
LLMResponse.reduce = reduceResponseState;
|
|
588
|
-
/** Return a completed response only after
|
|
561
|
+
/** Return a completed response only after the terminal finish. */
|
|
589
562
|
LLMResponse.complete = (state) => state.finishReason === undefined
|
|
590
563
|
? undefined
|
|
591
564
|
: new LLMResponse({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { Tool } from "@opencode/schema/tool";
|
|
3
|
-
import { CacheHint, GenerationOptions, HttpOptions, JsonSchema, type LanguageModel, ReasoningEffort } from "./options.js";
|
|
3
|
+
import { CacheHint, type CachePolicy, type GenerationOptions, type HttpOptions, JsonSchema, type LanguageModel, type LanguageModelProviderOptions, ReasoningEffort } from "./options.js";
|
|
4
4
|
import { Media } from "../media.js";
|
|
5
5
|
export declare const MessageRole: Schema.Literals<readonly ["system", "user", "assistant", "tool"]>;
|
|
6
6
|
export type MessageRole = Schema.Schema.Type<typeof MessageRole>;
|
|
@@ -695,97 +695,25 @@ export declare namespace ToolChoice {
|
|
|
695
695
|
/** Normalize ergonomic tool-choice inputs into the canonical `ToolChoice` class. */
|
|
696
696
|
const make: (input: Input) => ToolChoice;
|
|
697
697
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
}, import("../route.js").CompactionOperations | undefined>>;
|
|
705
|
-
readonly system: Schema.$Array<Schema.Struct<{
|
|
706
|
-
readonly type: Schema.Literal<"text">;
|
|
707
|
-
readonly text: Schema.String;
|
|
708
|
-
readonly cache: Schema.optional<typeof CacheHint>;
|
|
709
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
710
|
-
}> & {
|
|
711
|
-
make: typeof makeSystemPart;
|
|
712
|
-
content: (input?: string | SystemPart | ReadonlyArray<SystemPart>) => any[];
|
|
713
|
-
}>;
|
|
714
|
-
readonly messages: Schema.$Array<typeof Message>;
|
|
715
|
-
readonly tools: Schema.$Array<Schema.Codec<ToolEntry, ToolEntry, never, never> & {
|
|
716
|
-
readonly make: (input: ToolEntryInput) => ToolEntry;
|
|
717
|
-
}>;
|
|
718
|
-
readonly toolChoice: Schema.optional<typeof ToolChoice>;
|
|
719
|
-
readonly generation: Schema.optional<typeof GenerationOptions>;
|
|
720
|
-
readonly providerOptions: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
721
|
-
readonly http: Schema.optional<typeof HttpOptions>;
|
|
722
|
-
readonly cache: Schema.optional<Schema.Union<readonly [Schema.Literal<"auto">, Schema.Literal<"none">, Schema.Struct<{
|
|
723
|
-
readonly tools: Schema.optional<Schema.Boolean>;
|
|
724
|
-
readonly system: Schema.optional<Schema.Boolean>;
|
|
725
|
-
readonly messages: Schema.optional<Schema.Union<readonly [Schema.Literal<"latest-user-message">, Schema.Literal<"latest-assistant">, Schema.Struct<{
|
|
726
|
-
readonly tail: Schema.Natural;
|
|
727
|
-
}>]>>;
|
|
728
|
-
readonly ttl: Schema.optional<Schema.TemplateLiteral<readonly [Schema.Number, Schema.Literals<readonly ["ms", "s", "m", "h", "d"]>]>>;
|
|
729
|
-
}>]>>;
|
|
730
|
-
readonly promptCacheKey: Schema.optional<Schema.String>;
|
|
731
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
732
|
-
/** Emit a `raw` event with each provider frame before the events parsed from it. */
|
|
733
|
-
readonly includeRaw: Schema.optional<Schema.Boolean>;
|
|
734
|
-
}>;
|
|
735
|
-
declare const LLMRequest_base: Schema.Class<LLMRequest<LanguageModel<{
|
|
736
|
-
readonly [x: string]: unknown;
|
|
737
|
-
}, import("../route.js").CompactionOperations | undefined>>, Schema.Struct<{
|
|
738
|
-
readonly id: Schema.optional<Schema.String>;
|
|
739
|
-
readonly model: Schema.declare<LanguageModel<{
|
|
740
|
-
readonly [x: string]: unknown;
|
|
741
|
-
}, import("../route.js").CompactionOperations | undefined>, LanguageModel<{
|
|
742
|
-
readonly [x: string]: unknown;
|
|
743
|
-
}, import("../route.js").CompactionOperations | undefined>>;
|
|
744
|
-
readonly system: Schema.$Array<Schema.Struct<{
|
|
745
|
-
readonly type: Schema.Literal<"text">;
|
|
746
|
-
readonly text: Schema.String;
|
|
747
|
-
readonly cache: Schema.optional<typeof CacheHint>;
|
|
748
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
749
|
-
}> & {
|
|
750
|
-
make: typeof makeSystemPart;
|
|
751
|
-
content: (input?: string | SystemPart | ReadonlyArray<SystemPart>) => any[];
|
|
752
|
-
}>;
|
|
753
|
-
readonly messages: Schema.$Array<typeof Message>;
|
|
754
|
-
readonly tools: Schema.$Array<Schema.Codec<ToolEntry, ToolEntry, never, never> & {
|
|
755
|
-
readonly make: (input: ToolEntryInput) => ToolEntry;
|
|
756
|
-
}>;
|
|
757
|
-
readonly toolChoice: Schema.optional<typeof ToolChoice>;
|
|
758
|
-
readonly generation: Schema.optional<typeof GenerationOptions>;
|
|
759
|
-
readonly providerOptions: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
760
|
-
readonly http: Schema.optional<typeof HttpOptions>;
|
|
761
|
-
readonly cache: Schema.optional<Schema.Union<readonly [Schema.Literal<"auto">, Schema.Literal<"none">, Schema.Struct<{
|
|
762
|
-
readonly tools: Schema.optional<Schema.Boolean>;
|
|
763
|
-
readonly system: Schema.optional<Schema.Boolean>;
|
|
764
|
-
readonly messages: Schema.optional<Schema.Union<readonly [Schema.Literal<"latest-user-message">, Schema.Literal<"latest-assistant">, Schema.Struct<{
|
|
765
|
-
readonly tail: Schema.Natural;
|
|
766
|
-
}>]>>;
|
|
767
|
-
readonly ttl: Schema.optional<Schema.TemplateLiteral<readonly [Schema.Number, Schema.Literals<readonly ["ms", "s", "m", "h", "d"]>]>>;
|
|
768
|
-
}>]>>;
|
|
769
|
-
readonly promptCacheKey: Schema.optional<Schema.String>;
|
|
770
|
-
readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
771
|
-
/** Emit a `raw` event with each provider frame before the events parsed from it. */
|
|
772
|
-
readonly includeRaw: Schema.optional<Schema.Boolean>;
|
|
773
|
-
}>, {}>;
|
|
774
|
-
export declare class LLMRequest<Model extends LanguageModel = LanguageModel> extends LLMRequest_base {
|
|
698
|
+
/**
|
|
699
|
+
* A normalized text request, the plain object `ai.request(...)` returns. Edit it with a spread, such as
|
|
700
|
+
* `{ ...request, messages: [...request.messages, next] }`, or pass the edited object back to `ai.request`.
|
|
701
|
+
*/
|
|
702
|
+
export interface LLMRequest<Model extends LanguageModel = LanguageModel> {
|
|
703
|
+
readonly id?: string;
|
|
775
704
|
readonly model: Model;
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
function update(request: LLMRequest, patch: Partial<Input>): LLMRequest;
|
|
705
|
+
readonly system: ReadonlyArray<SystemPart>;
|
|
706
|
+
readonly messages: ReadonlyArray<Message>;
|
|
707
|
+
readonly tools: ReadonlyArray<ToolEntry>;
|
|
708
|
+
readonly toolChoice?: ToolChoice;
|
|
709
|
+
readonly generation?: GenerationOptions;
|
|
710
|
+
readonly providerOptions?: LanguageModelProviderOptions<Model>;
|
|
711
|
+
readonly http?: HttpOptions;
|
|
712
|
+
readonly cache?: CachePolicy;
|
|
713
|
+
/** Stable cache affinity for protocols that support provider-managed prompt caching. */
|
|
714
|
+
readonly promptCacheKey?: string;
|
|
715
|
+
readonly metadata?: Record<string, unknown>;
|
|
716
|
+
/** Emit a `raw` event with each provider frame before the events parsed from it. */
|
|
717
|
+
readonly includeRaw?: boolean;
|
|
790
718
|
}
|
|
791
719
|
export {};
|
package/dist/schema/messages.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Option, Schema } from "effect";
|
|
2
2
|
import { withStatics } from "@opencode/schema/schema";
|
|
3
3
|
import { Tool } from "@opencode/schema/tool";
|
|
4
|
-
import { CacheHint,
|
|
4
|
+
import { CacheHint, JsonSchema, ProviderMetadata, ReasoningEffort, } from "./options.js";
|
|
5
5
|
import { ProviderID } from "./ids.js";
|
|
6
6
|
import { Media } from "../media.js";
|
|
7
7
|
import { Json } from "../utils/json.js";
|
|
@@ -279,54 +279,3 @@ export class ToolChoice extends Schema.Class("LLM.ToolChoice")({
|
|
|
279
279
|
return new ToolChoice(input);
|
|
280
280
|
};
|
|
281
281
|
})(ToolChoice || (ToolChoice = {}));
|
|
282
|
-
const requestSchema = Schema.Struct({
|
|
283
|
-
id: Schema.optional(Schema.String),
|
|
284
|
-
model: LanguageModelSchema,
|
|
285
|
-
system: Schema.Array(SystemPart),
|
|
286
|
-
messages: Schema.Array(Message),
|
|
287
|
-
tools: Schema.Array(ToolEntry),
|
|
288
|
-
toolChoice: Schema.optional(ToolChoice),
|
|
289
|
-
generation: Schema.optional(GenerationOptions),
|
|
290
|
-
providerOptions: Schema.optional(ProviderOptions),
|
|
291
|
-
http: Schema.optional(HttpOptions),
|
|
292
|
-
cache: Schema.optional(CachePolicy),
|
|
293
|
-
// Stable cache affinity for protocols that support provider-managed prompt caching.
|
|
294
|
-
promptCacheKey: Schema.optional(Schema.String),
|
|
295
|
-
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
296
|
-
/** Emit a `raw` event with each provider frame before the events parsed from it. */
|
|
297
|
-
includeRaw: Schema.optional(Schema.Boolean),
|
|
298
|
-
});
|
|
299
|
-
export class LLMRequest extends Schema.Class("LLM.Request")(requestSchema.fields) {
|
|
300
|
-
// Preserve model inference instead of inheriting the schema's erased constructor signature.
|
|
301
|
-
// oxlint-disable-next-line no-useless-constructor
|
|
302
|
-
constructor(input) {
|
|
303
|
-
super(input);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
(function (LLMRequest) {
|
|
307
|
-
LLMRequest.input = (request) => ({
|
|
308
|
-
id: request.id,
|
|
309
|
-
model: request.model,
|
|
310
|
-
system: request.system,
|
|
311
|
-
messages: request.messages,
|
|
312
|
-
tools: request.tools,
|
|
313
|
-
toolChoice: request.toolChoice,
|
|
314
|
-
generation: request.generation,
|
|
315
|
-
providerOptions: request.providerOptions,
|
|
316
|
-
http: request.http,
|
|
317
|
-
cache: request.cache,
|
|
318
|
-
promptCacheKey: request.promptCacheKey,
|
|
319
|
-
metadata: request.metadata,
|
|
320
|
-
includeRaw: request.includeRaw,
|
|
321
|
-
});
|
|
322
|
-
function update(request, patch) {
|
|
323
|
-
if (Object.keys(patch).length === 0)
|
|
324
|
-
return request;
|
|
325
|
-
return new LLMRequest({
|
|
326
|
-
...LLMRequest.input(request),
|
|
327
|
-
...patch,
|
|
328
|
-
model: patch.model ?? request.model,
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
LLMRequest.update = update;
|
|
332
|
-
})(LLMRequest || (LLMRequest = {}));
|
package/dist/speech-client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context } from "effect";
|
|
2
2
|
import { MediaClient } from "./media-client.js";
|
|
3
|
-
import { type SpeechEvent, type
|
|
4
|
-
export type Interface = MediaClient.Interface<
|
|
3
|
+
import { type SpeechEvent, type SpeechRequest, type SpeechResponse } from "./speech.js";
|
|
4
|
+
export type Interface = MediaClient.Interface<SpeechRequest, SpeechEvent, SpeechResponse>;
|
|
5
5
|
declare const SpeechClientService_base: Context.ServiceClass<SpeechClientService, "@opencode/SpeechClient", Interface>;
|
|
6
6
|
export declare class SpeechClientService extends SpeechClientService_base {
|
|
7
7
|
}
|
|
@@ -57,8 +57,8 @@ export declare const SpeechClient: {
|
|
|
57
57
|
} | undefined;
|
|
58
58
|
})[];
|
|
59
59
|
readonly layer: import("effect/Layer").Layer<SpeechClientService, never, import("./route.js").RequestExecutorService>;
|
|
60
|
-
readonly generate: (request:
|
|
61
|
-
readonly stream: (request:
|
|
60
|
+
readonly generate: (request: SpeechRequest, options?: import("./generation.js").AwaitOptions) => import("effect/Effect").Effect<SpeechResponse, import("./effect.js").AIError, SpeechClientService>;
|
|
61
|
+
readonly stream: (request: SpeechRequest, options?: import("./generation.js").AwaitOptions) => import("effect/Stream").Stream<{
|
|
62
62
|
readonly type: "audio-delta";
|
|
63
63
|
readonly chunk: Uint8Array<ArrayBufferLike>;
|
|
64
64
|
} | {
|
|
@@ -98,7 +98,7 @@ export declare const SpeechClient: {
|
|
|
98
98
|
};
|
|
99
99
|
} | undefined;
|
|
100
100
|
} | import("./generation.js").Observation, import("./effect.js").AIError, SpeechClientService>;
|
|
101
|
-
readonly start: (request:
|
|
101
|
+
readonly start: (request: SpeechRequest) => import("effect/Effect").Effect<import("./generation.js").Generation<SpeechResponse>, import("./effect.js").AIError, SpeechClientService>;
|
|
102
102
|
readonly resume: (model: import("./speech.js").SpeechModel<{
|
|
103
103
|
readonly [x: string]: unknown;
|
|
104
104
|
}>, token: unknown) => import("effect/Effect").Effect<import("./generation.js").Generation<SpeechResponse>, import("./effect.js").AIError, SpeechClientService>;
|
package/dist/speech.d.ts
CHANGED
|
@@ -5,13 +5,13 @@ import { MediaRoute } from "./route/media.js";
|
|
|
5
5
|
import { AIError, HttpOptions, type OpenString } from "./schema/index.js";
|
|
6
6
|
import { Service } from "./speech-client.js";
|
|
7
7
|
export type SpeechOptions = MediaModel.Options;
|
|
8
|
-
export type SpeechRoute = MediaRoute.AnyRoute<
|
|
8
|
+
export type SpeechRoute = MediaRoute.AnyRoute<SpeechRequest, SpeechEvent, SpeechResponse>;
|
|
9
9
|
export declare class SpeechModel<Options extends SpeechOptions = SpeechOptions> extends MediaModel<SpeechRoute, Options> {
|
|
10
10
|
protected readonly _SpeechModel: void;
|
|
11
11
|
/** The number of type arguments selects the kind: `<Options>`, `<Options, Frame, State>`, or `<Options, Token>`. */
|
|
12
|
-
static fromRoute<Options extends SpeechOptions>(route: MediaModel.InlineRouteInput<
|
|
13
|
-
static fromRoute<Options extends SpeechOptions, Frame, State>(route: MediaModel.StreamRouteInput<
|
|
14
|
-
static fromRoute<Options extends SpeechOptions, Token>(route: MediaModel.QueuedRouteInput<
|
|
12
|
+
static fromRoute<Options extends SpeechOptions>(route: MediaModel.InlineRouteInput<SpeechRequest<SpeechModel<Options>>, SpeechResponse>, input: MediaRoute.ModelInput): SpeechModel<Options>;
|
|
13
|
+
static fromRoute<Options extends SpeechOptions, Frame, State>(route: MediaModel.StreamRouteInput<SpeechRequest<SpeechModel<Options>>, SpeechEvent, Frame, State>, input: MediaRoute.ModelInput): SpeechModel<Options>;
|
|
14
|
+
static fromRoute<Options extends SpeechOptions, Token>(route: MediaModel.QueuedRouteInput<SpeechRequest<SpeechModel<Options>>, SpeechResponse, Token>, input: MediaRoute.ModelInput): SpeechModel<Options>;
|
|
15
15
|
}
|
|
16
16
|
export declare const SpeechModelSchema: Schema.declare<SpeechModel<{
|
|
17
17
|
readonly [x: string]: unknown;
|
|
@@ -31,7 +31,7 @@ export declare const SpeechTimestamp: Schema.Struct<{
|
|
|
31
31
|
readonly endSeconds: Schema.Number;
|
|
32
32
|
}>;
|
|
33
33
|
export type SpeechTimestamp = Schema.Schema.Type<typeof SpeechTimestamp>;
|
|
34
|
-
declare const
|
|
34
|
+
declare const SpeechRequestSchema: Schema.Struct<{
|
|
35
35
|
readonly model: Schema.declare<SpeechModel<{
|
|
36
36
|
readonly [x: string]: unknown;
|
|
37
37
|
}>, SpeechModel<{
|
|
@@ -48,18 +48,16 @@ declare const SpeechRequest_base: Schema.Class<SpeechRequest, Schema.Struct<{
|
|
|
48
48
|
readonly timestamps: Schema.optional<Schema.Boolean>;
|
|
49
49
|
readonly providerOptions: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
50
50
|
readonly http: Schema.optional<typeof HttpOptions>;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
export type SpeechRequestFor<Options extends SpeechOptions = SpeechOptions> = Omit<SpeechRequest, "model" | "providerOptions"> & {
|
|
56
|
-
readonly model: SpeechModel<Options>;
|
|
57
|
-
readonly providerOptions?: Options;
|
|
58
|
-
};
|
|
59
|
-
export type SpeechModelOptions<Model> = Model extends SpeechModel<infer Options> ? Options : never;
|
|
60
|
-
export type SpeechRequestInput<Model extends SpeechModel = SpeechModel> = Omit<ConstructorParameters<typeof SpeechRequest>[0], "model" | "providerOptions" | "http" | "format"> & {
|
|
51
|
+
}>;
|
|
52
|
+
/** A normalized speech request, the plain object `Speech.request(...)` returns. */
|
|
53
|
+
export type SpeechRequest<Model extends SpeechModel = SpeechModel> = Omit<typeof SpeechRequestSchema.Type, "model" | "providerOptions" | "format"> & {
|
|
61
54
|
readonly model: Model;
|
|
62
55
|
readonly format?: SpeechFormat;
|
|
56
|
+
readonly providerOptions?: SpeechModelOptions<Model>;
|
|
57
|
+
};
|
|
58
|
+
export type SpeechModelOptions<Model> = Model extends SpeechModel<infer Options> ? Options : never;
|
|
59
|
+
/** Input accepted by `Speech.request` and the calls; a `SpeechRequest` is also a valid input. */
|
|
60
|
+
export type SpeechRequestInput<Model extends SpeechModel = SpeechModel> = Omit<SpeechRequest<Model>, "providerOptions" | "http"> & {
|
|
63
61
|
readonly providerOptions?: NoInfer<SpeechModelOptions<Model>>;
|
|
64
62
|
readonly http?: HttpOptions.Input;
|
|
65
63
|
};
|
|
@@ -1201,10 +1199,10 @@ export declare const SpeechEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
1201
1199
|
};
|
|
1202
1200
|
};
|
|
1203
1201
|
export type SpeechEvent = Schema.Schema.Type<typeof speechEventTagged>;
|
|
1204
|
-
|
|
1205
|
-
export declare
|
|
1206
|
-
export declare function generate<const Model extends SpeechModel>(input:
|
|
1207
|
-
export declare function stream<const Model extends SpeechModel>(input:
|
|
1202
|
+
/** Normalize speech request input into a plain `SpeechRequest`. */
|
|
1203
|
+
export declare const request: <const Model extends SpeechModel>(input: SpeechRequestInput<Model>) => SpeechRequest<Model>;
|
|
1204
|
+
export declare function generate<const Model extends SpeechModel>(input: SpeechRequestInput<Model>): Effect.Effect<SpeechResponse, AIError, Service>;
|
|
1205
|
+
export declare function stream<const Model extends SpeechModel>(input: SpeechRequestInput<Model>): Stream.Stream<SpeechEvent, AIError, Service>;
|
|
1208
1206
|
export declare const Speech: {
|
|
1209
1207
|
readonly request: typeof request;
|
|
1210
1208
|
readonly generate: typeof generate;
|
package/dist/speech.js
CHANGED
|
@@ -32,7 +32,7 @@ export const SpeechTimestamp = Schema.Struct({
|
|
|
32
32
|
startSeconds: Schema.Number,
|
|
33
33
|
endSeconds: Schema.Number,
|
|
34
34
|
}).annotate({ identifier: "Speech.Timestamp" });
|
|
35
|
-
|
|
35
|
+
const SpeechRequestSchema = Schema.Struct({
|
|
36
36
|
model: SpeechModelSchema,
|
|
37
37
|
text: Schema.String,
|
|
38
38
|
voice: Schema.optional(SpeechVoice),
|
|
@@ -43,8 +43,7 @@ export class SpeechRequest extends Schema.Class("Speech.Request")({
|
|
|
43
43
|
timestamps: Schema.optional(Schema.Boolean),
|
|
44
44
|
providerOptions: Schema.optional(ProviderOptions),
|
|
45
45
|
http: Schema.optional(HttpOptions),
|
|
46
|
-
})
|
|
47
|
-
}
|
|
46
|
+
});
|
|
48
47
|
// ---------------------------------------------------------------------------
|
|
49
48
|
// Response and events
|
|
50
49
|
// ---------------------------------------------------------------------------
|
|
@@ -100,15 +99,20 @@ const collectResponse = (events) => {
|
|
|
100
99
|
providerMetadata: finish.providerMetadata,
|
|
101
100
|
}));
|
|
102
101
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
const
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
// Request-shaped call API
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
/** Normalize speech request input into a plain `SpeechRequest`. */
|
|
106
|
+
export const request = (input) => ({
|
|
107
|
+
...input,
|
|
108
|
+
http: HttpOptions.make(input.http),
|
|
109
|
+
});
|
|
110
|
+
const validate = Schema.decodeUnknownSync(SpeechRequestSchema);
|
|
111
|
+
const requestEffect = (input) => tryRequest(() => {
|
|
112
|
+
const normalized = request(input);
|
|
113
|
+
validate(normalized);
|
|
114
|
+
return normalized;
|
|
115
|
+
});
|
|
112
116
|
export function generate(input) {
|
|
113
117
|
return requestEffect(input).pipe(Effect.flatMap((request) => SpeechClient.generate(request)));
|
|
114
118
|
}
|