@opencode/ai 0.0.0-dev-536 → 0.0.0-dev-544
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 +16 -2
- package/dist/cache-policy.js +15 -3
- package/dist/decision.d.ts +12 -10
- package/dist/decision.js +10 -4
- package/dist/experimental/extraction.d.ts +3 -7
- package/dist/experimental/extraction.js +2 -3
- package/dist/image.d.ts +5 -7
- package/dist/image.js +2 -3
- package/dist/llm.d.ts +3 -6
- package/dist/llm.js +5 -2
- package/dist/loop.js +5 -4
- package/dist/media-model.d.ts +1 -1
- package/dist/media-model.js +1 -1
- package/dist/media.d.ts +9 -0
- package/dist/media.js +37 -2
- package/dist/protocols/anthropic-messages.js +3 -12
- package/dist/protocols/bedrock-converse.js +0 -4
- package/dist/protocols/gemini.js +0 -4
- package/dist/protocols/meta-responses.js +22 -20
- package/dist/protocols/mistral-chat.js +0 -3
- package/dist/protocols/open-responses.d.ts +1 -1
- package/dist/protocols/open-responses.js +4 -6
- package/dist/protocols/openai-chat.d.ts +3 -3
- package/dist/protocols/openai-chat.js +7 -25
- package/dist/protocols/shared.js +11 -9
- package/dist/protocols/utils/responses-compaction.js +3 -3
- package/dist/protocols/utils/tool-stream.d.ts +2 -2
- package/dist/providers/assemblyai.d.ts +1 -1
- package/dist/providers/azure.js +2 -2
- package/dist/providers/cartesia.d.ts +1 -1
- package/dist/providers/deepgram.d.ts +1 -1
- package/dist/providers/elevenlabs.d.ts +1 -1
- package/dist/providers/openai.js +2 -2
- package/dist/providers/opencode.d.ts +2 -2
- package/dist/providers/opencode.js +1 -1
- package/dist/providers/runway.d.ts +1 -1
- package/dist/providers/typesafe-ai.d.ts +2 -2
- package/dist/providers/typesafe-ai.js +1 -1
- package/dist/public.d.ts +3 -3
- package/dist/public.js +1 -1
- package/dist/route/client.d.ts +3 -7
- package/dist/route/client.js +11 -24
- package/dist/route/decision.d.ts +2 -2
- package/dist/route/decision.js +3 -3
- package/dist/route/executor.d.ts +5 -0
- package/dist/route/executor.js +10 -0
- package/dist/route/index.d.ts +1 -1
- package/dist/route/index.js +1 -1
- package/dist/route/media.d.ts +7 -11
- package/dist/route/media.js +22 -26
- package/dist/route/transport/http.js +6 -5
- package/dist/schema/events.d.ts +63 -40
- package/dist/schema/events.js +3 -3
- package/dist/schema/messages.d.ts +181 -32
- package/dist/schema/messages.js +65 -23
- package/dist/schema/options.d.ts +42 -30
- package/dist/schema/options.js +27 -56
- package/dist/speech.d.ts +3 -7
- package/dist/speech.js +1 -3
- package/dist/testing.d.ts +8 -8
- package/dist/tool-history.d.ts +1 -1
- package/dist/tool-history.js +3 -9
- package/dist/transcription.d.ts +3 -8
- package/dist/transcription.js +1 -3
- package/dist/video.d.ts +3 -7
- package/dist/video.js +1 -3
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { Tool } from "@opencode/schema/tool";
|
|
3
|
-
import { CacheHint, type CachePolicy, type GenerationOptions,
|
|
3
|
+
import { type BaseRequest, CacheHint, type CachePolicy, type GenerationOptions, 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>;
|
|
@@ -66,6 +66,11 @@ export declare const MediaPart: Schema.Struct<{
|
|
|
66
66
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
67
67
|
}>;
|
|
68
68
|
export type MediaPart = Schema.Schema.Type<typeof MediaPart>;
|
|
69
|
+
/** A media part as input: `media` may be plain data, with `mediaType` naming its type when the content can't. */
|
|
70
|
+
export type MediaPartInput = Omit<MediaPart, "media"> & {
|
|
71
|
+
readonly media: Media.Input;
|
|
72
|
+
readonly mediaType?: string;
|
|
73
|
+
};
|
|
69
74
|
declare const toolResultValueSchema: Schema.Union<readonly [Schema.Struct<{
|
|
70
75
|
readonly type: Schema.Literal<"json">;
|
|
71
76
|
readonly value: Schema.Unknown;
|
|
@@ -414,9 +419,25 @@ export declare const ContentPart: Schema.toTaggedUnion<"type", readonly [Schema.
|
|
|
414
419
|
readonly previous: Schema.optional<Schema.declare<ReasoningEffort, ReasoningEffort>>;
|
|
415
420
|
}>]>;
|
|
416
421
|
export type ContentPart = Schema.Schema.Type<typeof ContentPart>;
|
|
417
|
-
declare const
|
|
422
|
+
declare const SystemMessage_base: Schema.Class<SystemMessage, Schema.Struct<{
|
|
418
423
|
readonly id: Schema.optional<Schema.String>;
|
|
419
|
-
readonly role: Schema.
|
|
424
|
+
readonly role: Schema.Literal<"system">;
|
|
425
|
+
readonly content: Schema.$Array<Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
426
|
+
readonly type: Schema.Literal<"text">;
|
|
427
|
+
readonly text: Schema.String;
|
|
428
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
429
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
430
|
+
}>, Schema.Struct<{
|
|
431
|
+
readonly type: Schema.Literal<"effort">;
|
|
432
|
+
readonly effort: Schema.optional<Schema.declare<ReasoningEffort, ReasoningEffort>>;
|
|
433
|
+
readonly previous: Schema.optional<Schema.declare<ReasoningEffort, ReasoningEffort>>;
|
|
434
|
+
}>]>>;
|
|
435
|
+
}>, {}>;
|
|
436
|
+
export declare class SystemMessage extends SystemMessage_base {
|
|
437
|
+
}
|
|
438
|
+
declare const UserMessage_base: Schema.Class<UserMessage, Schema.Struct<{
|
|
439
|
+
readonly id: Schema.optional<Schema.String>;
|
|
440
|
+
readonly role: Schema.Literal<"user">;
|
|
420
441
|
readonly content: Schema.$Array<Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
421
442
|
readonly type: Schema.Literal<"text">;
|
|
422
443
|
readonly text: Schema.String;
|
|
@@ -458,6 +479,25 @@ declare const Message_base: Schema.Class<Message, Schema.Struct<{
|
|
|
458
479
|
readonly filename: Schema.optional<Schema.String>;
|
|
459
480
|
readonly cache: Schema.optional<typeof CacheHint>;
|
|
460
481
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
482
|
+
}>]>>;
|
|
483
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
484
|
+
}>, {}>;
|
|
485
|
+
export declare class UserMessage extends UserMessage_base {
|
|
486
|
+
}
|
|
487
|
+
declare const AssistantMessage_base: Schema.Class<AssistantMessage, Schema.Struct<{
|
|
488
|
+
readonly id: Schema.optional<Schema.String>;
|
|
489
|
+
readonly role: Schema.Literal<"assistant">;
|
|
490
|
+
readonly content: Schema.$Array<Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
491
|
+
readonly type: Schema.Literal<"text">;
|
|
492
|
+
readonly text: Schema.String;
|
|
493
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
494
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
495
|
+
}>, Schema.Struct<{
|
|
496
|
+
readonly type: Schema.Literal<"reasoning">;
|
|
497
|
+
readonly text: Schema.String;
|
|
498
|
+
readonly encrypted: Schema.optional<Schema.String>;
|
|
499
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
500
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
461
501
|
}>, Schema.Struct<{
|
|
462
502
|
readonly type: Schema.Literal<"tool-call">;
|
|
463
503
|
readonly id: Schema.String;
|
|
@@ -527,9 +567,39 @@ declare const Message_base: Schema.Class<Message, Schema.Struct<{
|
|
|
527
567
|
readonly resultType?: ToolResultValue["type"];
|
|
528
568
|
}) => ToolResultPart;
|
|
529
569
|
}, Schema.Struct<{
|
|
530
|
-
readonly type: Schema.Literal<"
|
|
531
|
-
readonly
|
|
532
|
-
|
|
570
|
+
readonly type: Schema.Literal<"media">;
|
|
571
|
+
readonly media: Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
|
|
572
|
+
readonly source: Schema.Union<readonly [Schema.Struct<{
|
|
573
|
+
readonly type: Schema.Literal<"bytes">;
|
|
574
|
+
readonly data: Schema.Uint8Array;
|
|
575
|
+
readonly mediaType: Schema.String;
|
|
576
|
+
}>, Schema.Struct<{
|
|
577
|
+
readonly type: Schema.Literal<"base64">;
|
|
578
|
+
readonly data: Schema.String;
|
|
579
|
+
readonly mediaType: Schema.String;
|
|
580
|
+
}>, Schema.Struct<{
|
|
581
|
+
readonly type: Schema.Literal<"url">;
|
|
582
|
+
readonly url: Schema.String;
|
|
583
|
+
readonly mediaType: Schema.optional<Schema.String>;
|
|
584
|
+
readonly expiresAt: Schema.optional<Schema.Number>;
|
|
585
|
+
}>, Schema.Struct<{
|
|
586
|
+
readonly type: Schema.Literal<"ref">;
|
|
587
|
+
readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
|
|
588
|
+
readonly id: Schema.String;
|
|
589
|
+
readonly mediaType: Schema.optional<Schema.String>;
|
|
590
|
+
}>]>;
|
|
591
|
+
readonly info: Schema.optional<Schema.Struct<{
|
|
592
|
+
readonly width: Schema.optional<Schema.Number>;
|
|
593
|
+
readonly height: Schema.optional<Schema.Number>;
|
|
594
|
+
readonly durationSeconds: Schema.optional<Schema.Number>;
|
|
595
|
+
readonly sampleRate: Schema.optional<Schema.Number>;
|
|
596
|
+
readonly channels: Schema.optional<Schema.Number>;
|
|
597
|
+
readonly encoding: Schema.optional<Schema.String>;
|
|
598
|
+
readonly format: Schema.optional<Schema.String>;
|
|
599
|
+
}>>;
|
|
600
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
601
|
+
}>, never, never>;
|
|
602
|
+
readonly filename: Schema.optional<Schema.String>;
|
|
533
603
|
readonly cache: Schema.optional<typeof CacheHint>;
|
|
534
604
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
535
605
|
}>, Schema.refine<{
|
|
@@ -547,41 +617,123 @@ declare const Message_base: Schema.Class<Message, Schema.Struct<{
|
|
|
547
617
|
readonly text: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
548
618
|
}>> & {
|
|
549
619
|
make: (input: Omit<CompactionPart, "type" | "encrypted" | "text"> & CompactionContent) => CompactionPart;
|
|
550
|
-
}
|
|
551
|
-
readonly type: Schema.Literal<"effort">;
|
|
552
|
-
readonly effort: Schema.optional<Schema.declare<ReasoningEffort, ReasoningEffort>>;
|
|
553
|
-
readonly previous: Schema.optional<Schema.declare<ReasoningEffort, ReasoningEffort>>;
|
|
554
|
-
}>]>>;
|
|
620
|
+
}]>>;
|
|
555
621
|
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
556
|
-
readonly native: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
557
622
|
}>, {}>;
|
|
558
|
-
export declare class
|
|
623
|
+
export declare class AssistantMessage extends AssistantMessage_base {
|
|
559
624
|
}
|
|
625
|
+
declare const ToolMessage_base: Schema.Class<ToolMessage, Schema.Struct<{
|
|
626
|
+
readonly id: Schema.optional<Schema.String>;
|
|
627
|
+
readonly role: Schema.Literal<"tool">;
|
|
628
|
+
readonly content: Schema.$Array<Schema.Struct<{
|
|
629
|
+
readonly type: Schema.Literal<"tool-result">;
|
|
630
|
+
readonly id: Schema.String;
|
|
631
|
+
readonly name: Schema.String;
|
|
632
|
+
readonly namespace: Schema.optional<Schema.String>;
|
|
633
|
+
readonly result: Schema.Union<readonly [Schema.Struct<{
|
|
634
|
+
readonly type: Schema.Literal<"json">;
|
|
635
|
+
readonly value: Schema.Unknown;
|
|
636
|
+
}>, Schema.Struct<{
|
|
637
|
+
readonly type: Schema.Literal<"text">;
|
|
638
|
+
readonly value: Schema.Unknown;
|
|
639
|
+
}>, Schema.Struct<{
|
|
640
|
+
readonly type: Schema.Literal<"error">;
|
|
641
|
+
readonly value: Schema.Unknown;
|
|
642
|
+
}>, Schema.Struct<{
|
|
643
|
+
readonly type: Schema.Literal<"content">;
|
|
644
|
+
readonly value: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
645
|
+
readonly type: Schema.Literal<"text">;
|
|
646
|
+
readonly text: Schema.String;
|
|
647
|
+
}>, Schema.Struct<{
|
|
648
|
+
readonly type: Schema.Literal<"file">;
|
|
649
|
+
readonly uri: Schema.String;
|
|
650
|
+
readonly mime: Schema.String;
|
|
651
|
+
readonly name: Schema.optional<Schema.String>;
|
|
652
|
+
}>]>>;
|
|
653
|
+
}>]> & {
|
|
654
|
+
is: <I>(input: I) => input is I & ({
|
|
655
|
+
readonly type: "json";
|
|
656
|
+
readonly value: unknown;
|
|
657
|
+
} | {
|
|
658
|
+
readonly type: "text";
|
|
659
|
+
readonly value: unknown;
|
|
660
|
+
} | {
|
|
661
|
+
readonly type: "error";
|
|
662
|
+
readonly value: unknown;
|
|
663
|
+
} | {
|
|
664
|
+
readonly type: "content";
|
|
665
|
+
readonly value: readonly ({
|
|
666
|
+
readonly type: "text";
|
|
667
|
+
readonly text: string;
|
|
668
|
+
} | {
|
|
669
|
+
readonly type: "file";
|
|
670
|
+
readonly uri: string;
|
|
671
|
+
readonly mime: string;
|
|
672
|
+
readonly name?: string | undefined;
|
|
673
|
+
})[];
|
|
674
|
+
});
|
|
675
|
+
make: (value: unknown, type?: ToolResultValue["type"]) => ToolResultValue;
|
|
676
|
+
};
|
|
677
|
+
readonly providerExecuted: Schema.optional<Schema.Boolean>;
|
|
678
|
+
readonly cache: Schema.optional<typeof CacheHint>;
|
|
679
|
+
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
680
|
+
}> & {
|
|
681
|
+
make: (input: Omit<ToolResultPart, "type" | "result"> & {
|
|
682
|
+
readonly result: unknown;
|
|
683
|
+
readonly resultType?: ToolResultValue["type"];
|
|
684
|
+
}) => ToolResultPart;
|
|
685
|
+
}>;
|
|
686
|
+
}>, {}>;
|
|
687
|
+
export declare class ToolMessage extends ToolMessage_base {
|
|
688
|
+
}
|
|
689
|
+
export type Message = SystemMessage | UserMessage | AssistantMessage | ToolMessage;
|
|
690
|
+
export type ContentPartInput = Exclude<ContentPart, MediaPart> | MediaPartInput;
|
|
560
691
|
export declare namespace Message {
|
|
561
|
-
type ContentInput
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
692
|
+
export type ContentInput<Part extends {
|
|
693
|
+
readonly type: string;
|
|
694
|
+
} = ContentPartInput> = string | Part | ReadonlyArray<Part>;
|
|
695
|
+
export type SystemContentInput = ContentInput<TextPart>;
|
|
696
|
+
export type UserContentInput = ContentInput<TextPart | MediaPartInput>;
|
|
697
|
+
export type AssistantContentInput = ContentInput<Exclude<AssistantMessage["content"][number], MediaPart> | MediaPartInput>;
|
|
698
|
+
type RoleInput<Props, Content> = Omit<Props, "content"> & {
|
|
699
|
+
readonly content: Content;
|
|
565
700
|
};
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
701
|
+
export type SystemInput = RoleInput<ConstructorParameters<typeof SystemMessage>[0], ContentInput<SystemMessage["content"][number]>>;
|
|
702
|
+
export type UserInput = RoleInput<ConstructorParameters<typeof UserMessage>[0], UserContentInput>;
|
|
703
|
+
export type AssistantInput = RoleInput<ConstructorParameters<typeof AssistantMessage>[0], AssistantContentInput>;
|
|
704
|
+
export type ToolInput = RoleInput<ConstructorParameters<typeof ToolMessage>[0], ToolResultPart | ReadonlyArray<ToolResultPart>>;
|
|
705
|
+
export type Input = SystemInput | UserInput | AssistantInput | ToolInput;
|
|
706
|
+
export {};
|
|
707
|
+
}
|
|
708
|
+
declare const text: (value: string) => TextPart;
|
|
709
|
+
declare function contentWithMedia(input: Message.UserContentInput): UserMessage["content"];
|
|
710
|
+
declare function contentWithMedia(input: Message.AssistantContentInput): AssistantMessage["content"];
|
|
711
|
+
declare function contentWithMedia(input: Message.ContentInput): ReadonlyArray<ContentPart>;
|
|
712
|
+
declare function make(input: SystemMessage | Message.SystemInput): SystemMessage;
|
|
713
|
+
declare function make(input: UserMessage | Message.UserInput): UserMessage;
|
|
714
|
+
declare function make(input: AssistantMessage | Message.AssistantInput): AssistantMessage;
|
|
715
|
+
declare function make(input: ToolMessage | Message.ToolInput): ToolMessage;
|
|
716
|
+
declare function make(input: Message | Message.Input): Message;
|
|
717
|
+
export declare const Message: Schema.Union<readonly [typeof SystemMessage, typeof UserMessage, typeof AssistantMessage, typeof ToolMessage]> & {
|
|
718
|
+
text: typeof text;
|
|
719
|
+
media: (media: MediaPartInput["media"], options?: Omit<MediaPartInput, "type" | "media">) => MediaPart;
|
|
720
|
+
content: typeof contentWithMedia;
|
|
721
|
+
make: typeof make;
|
|
722
|
+
user: (input: Message.UserContentInput) => UserMessage;
|
|
723
|
+
assistant: (input: Message.AssistantContentInput) => AssistantMessage;
|
|
572
724
|
/**
|
|
573
725
|
* Add an operator-authored instruction at this chronological point in the
|
|
574
726
|
* conversation. This is distinct from the initial `LLMRequest.system`
|
|
575
727
|
* prompt. Keep raw retrieved, tool, and web content out of privileged system
|
|
576
728
|
* updates; pass that untrusted content through ordinary user/tool channels.
|
|
577
729
|
*/
|
|
578
|
-
|
|
579
|
-
|
|
730
|
+
system: (input: Message.SystemContentInput) => SystemMessage;
|
|
731
|
+
effort: (input: {
|
|
580
732
|
readonly effort?: ReasoningEffort;
|
|
581
733
|
readonly previous?: ReasoningEffort;
|
|
582
|
-
}) =>
|
|
583
|
-
|
|
584
|
-
}
|
|
734
|
+
}) => SystemMessage;
|
|
735
|
+
tool: (result: ToolResultPart | Parameters<typeof ToolResultPart.make>[0]) => ToolMessage;
|
|
736
|
+
};
|
|
585
737
|
/**
|
|
586
738
|
* Raw-text wire encoding for a tool with exactly one required string parameter. Models that accept the format
|
|
587
739
|
* write that parameter's value directly instead of JSON arguments; calls still decode to the normal object input.
|
|
@@ -681,16 +833,13 @@ export declare namespace ToolChoice {
|
|
|
681
833
|
* A normalized text request, the plain object `ai.request(...)` returns. Edit it with a spread, such as
|
|
682
834
|
* `{ ...request, messages: [...request.messages, next] }`, or pass the edited object back to `ai.request`.
|
|
683
835
|
*/
|
|
684
|
-
export interface LLMRequest<Model extends LanguageModel = LanguageModel> {
|
|
836
|
+
export interface LLMRequest<Model extends LanguageModel = LanguageModel> extends BaseRequest<Model, LanguageModelProviderOptions<Model>> {
|
|
685
837
|
readonly id?: string;
|
|
686
|
-
readonly model: Model;
|
|
687
838
|
readonly system: ReadonlyArray<SystemPart>;
|
|
688
839
|
readonly messages: ReadonlyArray<Message>;
|
|
689
840
|
readonly tools: ReadonlyArray<ToolEntry>;
|
|
690
841
|
readonly toolChoice?: ToolChoice;
|
|
691
842
|
readonly generation?: GenerationOptions;
|
|
692
|
-
readonly providerOptions?: LanguageModelProviderOptions<Model>;
|
|
693
|
-
readonly http?: HttpOptions;
|
|
694
843
|
readonly cache?: CachePolicy;
|
|
695
844
|
/** Stable cache affinity for protocols that support provider-managed prompt caching. */
|
|
696
845
|
readonly promptCacheKey?: string;
|
package/dist/schema/messages.js
CHANGED
|
@@ -34,6 +34,10 @@ export const MediaPart = Schema.Struct({
|
|
|
34
34
|
cache: Schema.optional(CacheHint),
|
|
35
35
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
36
36
|
}).annotate({ identifier: "LLM.Content.Media" });
|
|
37
|
+
const mediaPart = (input) => {
|
|
38
|
+
const { mediaType, ...part } = input;
|
|
39
|
+
return { ...part, media: Media.make(input.media, mediaType) };
|
|
40
|
+
};
|
|
37
41
|
const toolResultValueSchema = Schema.Union([
|
|
38
42
|
Schema.Struct({
|
|
39
43
|
type: Schema.Literal("json"),
|
|
@@ -162,39 +166,77 @@ export const ContentPart = Schema.Union([
|
|
|
162
166
|
CompactionPart,
|
|
163
167
|
EffortPart,
|
|
164
168
|
]).pipe(Schema.toTaggedUnion("type"));
|
|
165
|
-
export class
|
|
169
|
+
export class SystemMessage extends Schema.Class("LLM.SystemMessage")({
|
|
166
170
|
id: Schema.optional(Schema.String),
|
|
167
|
-
role:
|
|
168
|
-
content: Schema.Array(
|
|
171
|
+
role: Schema.Literal("system"),
|
|
172
|
+
content: Schema.Array(Schema.Union([TextPart, EffortPart]).pipe(Schema.toTaggedUnion("type"))),
|
|
173
|
+
}) {
|
|
174
|
+
}
|
|
175
|
+
export class UserMessage extends Schema.Class("LLM.UserMessage")({
|
|
176
|
+
id: Schema.optional(Schema.String),
|
|
177
|
+
role: Schema.Literal("user"),
|
|
178
|
+
content: Schema.Array(Schema.Union([TextPart, MediaPart]).pipe(Schema.toTaggedUnion("type"))),
|
|
169
179
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
170
|
-
native: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
171
180
|
}) {
|
|
172
181
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
182
|
+
export class AssistantMessage extends Schema.Class("LLM.AssistantMessage")({
|
|
183
|
+
id: Schema.optional(Schema.String),
|
|
184
|
+
role: Schema.Literal("assistant"),
|
|
185
|
+
content: Schema.Array(Schema.Union([TextPart, ReasoningPart, ToolCallPart, ToolResultPart, MediaPart, CompactionPart]).pipe(Schema.toTaggedUnion("type"))),
|
|
186
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
187
|
+
}) {
|
|
188
|
+
}
|
|
189
|
+
export class ToolMessage extends Schema.Class("LLM.ToolMessage")({
|
|
190
|
+
id: Schema.optional(Schema.String),
|
|
191
|
+
role: Schema.Literal("tool"),
|
|
192
|
+
content: Schema.Array(ToolResultPart),
|
|
193
|
+
}) {
|
|
194
|
+
}
|
|
195
|
+
const messageSchema = Schema.Union([SystemMessage, UserMessage, AssistantMessage, ToolMessage]).pipe(Schema.toTaggedUnion("role"), Schema.annotate({ identifier: "LLM.Message" }));
|
|
196
|
+
const text = (value) => ({ type: "text", text: value });
|
|
197
|
+
const isParts = (input) => Array.isArray(input);
|
|
198
|
+
const content = (input) => (typeof input === "string" ? [text(input)] : isParts(input) ? [...input] : [input]);
|
|
199
|
+
function contentWithMedia(input) {
|
|
200
|
+
return content(input).map((part) => (part.type === "media" ? mediaPart(part) : part));
|
|
201
|
+
}
|
|
202
|
+
function make(input) {
|
|
203
|
+
switch (input.role) {
|
|
204
|
+
case "system":
|
|
205
|
+
return input instanceof SystemMessage ? input : new SystemMessage({ ...input, content: content(input.content) });
|
|
206
|
+
case "user":
|
|
207
|
+
return input instanceof UserMessage
|
|
208
|
+
? input
|
|
209
|
+
: new UserMessage({ ...input, content: contentWithMedia(input.content) });
|
|
210
|
+
case "assistant":
|
|
211
|
+
return input instanceof AssistantMessage
|
|
212
|
+
? input
|
|
213
|
+
: new AssistantMessage({ ...input, content: contentWithMedia(input.content) });
|
|
214
|
+
case "tool":
|
|
215
|
+
return input instanceof ToolMessage
|
|
216
|
+
? input
|
|
217
|
+
: new ToolMessage({ ...input, content: isParts(input.content) ? [...input.content] : [input.content] });
|
|
218
|
+
}
|
|
219
|
+
// Untyped callers can still pass an unknown role; reject it the way the schema does.
|
|
220
|
+
return Schema.decodeUnknownSync(messageSchema)(input);
|
|
221
|
+
}
|
|
222
|
+
export const Message = withStatics(messageSchema, {
|
|
223
|
+
text,
|
|
224
|
+
// Typed through `MediaPartInput` so packages that infer types from `Message` can still emit declarations.
|
|
225
|
+
media: (media, options) => mediaPart({ type: "media", media, ...options }),
|
|
226
|
+
content: contentWithMedia,
|
|
227
|
+
make,
|
|
228
|
+
user: (input) => make({ role: "user", content: input }),
|
|
229
|
+
assistant: (input) => make({ role: "assistant", content: input }),
|
|
188
230
|
/**
|
|
189
231
|
* Add an operator-authored instruction at this chronological point in the
|
|
190
232
|
* conversation. This is distinct from the initial `LLMRequest.system`
|
|
191
233
|
* prompt. Keep raw retrieved, tool, and web content out of privileged system
|
|
192
234
|
* updates; pass that untrusted content through ordinary user/tool channels.
|
|
193
235
|
*/
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
})
|
|
236
|
+
system: (input) => make({ role: "system", content: input }),
|
|
237
|
+
effort: (input) => make({ role: "system", content: [{ type: "effort", effort: input.effort, previous: input.previous }] }),
|
|
238
|
+
tool: (result) => make({ role: "tool", content: ["type" in result ? result : ToolResultPart.make(result)] }),
|
|
239
|
+
});
|
|
198
240
|
/**
|
|
199
241
|
* Raw-text wire encoding for a tool with exactly one required string parameter. Models that accept the format
|
|
200
242
|
* write that parameter's value directly instead of JSON arguments; calls still decode to the normal object input.
|
package/dist/schema/options.d.ts
CHANGED
|
@@ -12,38 +12,53 @@ export declare const mergeProviderOptions: (...items: ReadonlyArray<ProviderOpti
|
|
|
12
12
|
/** Milliseconds for an HTTP timeout, or `false` to disable it. */
|
|
13
13
|
export declare const HttpTimeout: Schema.Union<readonly [Schema.Number, Schema.Literal<false>]>;
|
|
14
14
|
export type HttpTimeout = Schema.Schema.Type<typeof HttpTimeout>;
|
|
15
|
-
/** Applied to `
|
|
15
|
+
/** Applied to `timeout.headers` when a request leaves it unset. */
|
|
16
16
|
export declare const DEFAULT_HTTP_TIMEOUT_MS = 300000;
|
|
17
17
|
/**
|
|
18
|
-
* Applied to `
|
|
18
|
+
* Applied to `timeout.chunk` when a request leaves it unset. Some providers, such as DeepSeek, have specifically asked
|
|
19
19
|
* clients to allow at least 15 minutes, because their models can stream nothing for minutes while they reason.
|
|
20
20
|
*/
|
|
21
21
|
export declare const DEFAULT_CHUNK_TIMEOUT_MS = 900000;
|
|
22
22
|
/** `Content-Encoding` for JSON request bodies; `none` sends plain JSON. */
|
|
23
23
|
export declare const RequestEncoding: Schema.Literals<readonly ["zstd", "gzip", "none"]>;
|
|
24
24
|
export type RequestEncoding = Schema.Schema.Type<typeof RequestEncoding>;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
readonly
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
readonly timeout: Schema.optional<Schema.Union<readonly [Schema.Number, Schema.Literal<false>]>>;
|
|
31
|
-
/** Time allowed for response headers to arrive. */
|
|
32
|
-
readonly headerTimeout: Schema.optional<Schema.Union<readonly [Schema.Number, Schema.Literal<false>]>>;
|
|
33
|
-
/** Time allowed between streamed response chunks once headers have arrived. */
|
|
34
|
-
readonly chunkTimeout: Schema.optional<Schema.Union<readonly [Schema.Number, Schema.Literal<false>]>>;
|
|
25
|
+
/** Rare wire-level overrides. */
|
|
26
|
+
export interface HttpOptions {
|
|
27
|
+
readonly query?: Record<string, string>;
|
|
28
|
+
/** Deep-merged over the provider-native JSON body. */
|
|
29
|
+
readonly body?: Record<string, unknown>;
|
|
35
30
|
/** Compression for JSON request bodies. Only set it for endpoints known to decode it. */
|
|
36
|
-
readonly encoding
|
|
37
|
-
}
|
|
38
|
-
|
|
31
|
+
readonly encoding?: RequestEncoding;
|
|
32
|
+
}
|
|
33
|
+
/** Per-phase time limits in milliseconds. */
|
|
34
|
+
export interface TimeoutConfig {
|
|
35
|
+
/** The whole request, from send until the response completes. Unbounded when unset. */
|
|
36
|
+
readonly total?: HttpTimeout;
|
|
37
|
+
/** Until response headers arrive. */
|
|
38
|
+
readonly headers?: HttpTimeout;
|
|
39
|
+
/** Between streamed response chunks once headers have arrived. */
|
|
40
|
+
readonly chunk?: HttpTimeout;
|
|
41
|
+
}
|
|
42
|
+
/** Milliseconds for the whole request, `false` to disable it, or per-phase limits. */
|
|
43
|
+
export type RequestTimeout = HttpTimeout | TimeoutConfig;
|
|
44
|
+
/** Transport settings shared by requests, models and routes. */
|
|
45
|
+
export interface TransportOptions {
|
|
46
|
+
/** Merged over the provider's headers; these win. */
|
|
47
|
+
readonly headers?: Record<string, string>;
|
|
48
|
+
/** Applied to text requests; media requests do not apply it yet. */
|
|
49
|
+
readonly timeout?: RequestTimeout;
|
|
50
|
+
readonly http?: HttpOptions;
|
|
39
51
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
/** The fields every request shares, whatever its modality. */
|
|
53
|
+
export interface BaseRequest<Model, Options = ProviderOptions> extends TransportOptions {
|
|
54
|
+
readonly model: Model;
|
|
55
|
+
readonly providerOptions?: Options;
|
|
56
|
+
/** Sends this call through `fetch` instead of the client's HTTP executor. */
|
|
57
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
45
58
|
}
|
|
46
|
-
export declare const
|
|
59
|
+
export declare const timeoutConfig: (timeout: RequestTimeout | undefined) => TimeoutConfig;
|
|
60
|
+
/** Merge transport settings; later items win, headers, query and body merge by key. */
|
|
61
|
+
export declare const mergeTransport: (...items: ReadonlyArray<TransportOptions | undefined>) => TransportOptions;
|
|
47
62
|
declare const GenerationOptions_base: Schema.Class<GenerationOptions, Schema.Struct<{
|
|
48
63
|
readonly maxTokens: Schema.optional<Schema.Number>;
|
|
49
64
|
readonly temperature: Schema.optional<Schema.Number>;
|
|
@@ -73,19 +88,16 @@ export type GenerationOptionsFields = {
|
|
|
73
88
|
};
|
|
74
89
|
export type GenerationOptionsInput = GenerationOptions | GenerationOptionsFields;
|
|
75
90
|
export declare const mergeGenerationOptions: (...items: ReadonlyArray<GenerationOptionsInput | undefined>) => GenerationOptions | undefined;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
readonly
|
|
79
|
-
readonly
|
|
80
|
-
}>, {}>;
|
|
81
|
-
export declare class LanguageModelDefaults extends LanguageModelDefaults_base {
|
|
91
|
+
/** Request defaults a selected model applies under each request. */
|
|
92
|
+
export interface LanguageModelDefaults extends TransportOptions {
|
|
93
|
+
readonly generation?: GenerationOptions;
|
|
94
|
+
readonly providerOptions?: ProviderOptions;
|
|
82
95
|
}
|
|
83
96
|
export declare namespace LanguageModelDefaults {
|
|
84
|
-
|
|
97
|
+
interface Input extends TransportOptions {
|
|
85
98
|
readonly generation?: GenerationOptions.Input;
|
|
86
99
|
readonly providerOptions?: ProviderOptions;
|
|
87
|
-
|
|
88
|
-
};
|
|
100
|
+
}
|
|
89
101
|
/** Normalize selected-model request defaults without applying precedence. */
|
|
90
102
|
const make: (input: Input) => LanguageModelDefaults;
|
|
91
103
|
}
|
package/dist/schema/options.js
CHANGED
|
@@ -34,54 +34,35 @@ export const ProviderMetadata = Schema.Record(Schema.String, Schema.Record(Schem
|
|
|
34
34
|
export const mergeProviderOptions = (...items) => mergeJsonRecords(...items);
|
|
35
35
|
/** Milliseconds for an HTTP timeout, or `false` to disable it. */
|
|
36
36
|
export const HttpTimeout = Schema.Union([Schema.Number.check(Schema.isGreaterThan(0)), Schema.Literal(false)]);
|
|
37
|
-
/** Applied to `
|
|
37
|
+
/** Applied to `timeout.headers` when a request leaves it unset. */
|
|
38
38
|
export const DEFAULT_HTTP_TIMEOUT_MS = 300_000;
|
|
39
39
|
/**
|
|
40
|
-
* Applied to `
|
|
40
|
+
* Applied to `timeout.chunk` when a request leaves it unset. Some providers, such as DeepSeek, have specifically asked
|
|
41
41
|
* clients to allow at least 15 minutes, because their models can stream nothing for minutes while they reason.
|
|
42
42
|
*/
|
|
43
43
|
export const DEFAULT_CHUNK_TIMEOUT_MS = 900_000;
|
|
44
44
|
/** `Content-Encoding` for JSON request bodies; `none` sends plain JSON. */
|
|
45
45
|
export const RequestEncoding = Schema.Literals(["zstd", "gzip", "none"]);
|
|
46
|
-
export
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
HttpOptions.make = make;
|
|
67
|
-
})(HttpOptions || (HttpOptions = {}));
|
|
68
|
-
export const mergeHttpOptions = (...items) => {
|
|
69
|
-
const body = mergeJsonRecords(...items.map((item) => item?.body));
|
|
70
|
-
const headers = mergeStringRecords(...items.map((item) => item?.headers));
|
|
71
|
-
const query = mergeStringRecords(...items.map((item) => item?.query));
|
|
72
|
-
const timeout = items.findLast((item) => item?.timeout !== undefined)?.timeout;
|
|
73
|
-
const headerTimeout = items.findLast((item) => item?.headerTimeout !== undefined)?.headerTimeout;
|
|
74
|
-
const chunkTimeout = items.findLast((item) => item?.chunkTimeout !== undefined)?.chunkTimeout;
|
|
75
|
-
const encoding = items.findLast((item) => item?.encoding !== undefined)?.encoding;
|
|
76
|
-
if (!body &&
|
|
77
|
-
!headers &&
|
|
78
|
-
!query &&
|
|
79
|
-
timeout === undefined &&
|
|
80
|
-
headerTimeout === undefined &&
|
|
81
|
-
chunkTimeout === undefined &&
|
|
82
|
-
encoding === undefined)
|
|
83
|
-
return undefined;
|
|
84
|
-
return new HttpOptions({ body, headers, query, timeout, headerTimeout, chunkTimeout, encoding });
|
|
46
|
+
export const timeoutConfig = (timeout) => typeof timeout === "object" ? timeout : { total: timeout };
|
|
47
|
+
const last = (values) => values.findLast((value) => value !== undefined);
|
|
48
|
+
const someDefined = (value) => Object.values(value).some((item) => item !== undefined) ? value : undefined;
|
|
49
|
+
/** Merge transport settings; later items win, headers, query and body merge by key. */
|
|
50
|
+
export const mergeTransport = (...items) => {
|
|
51
|
+
const timeouts = items.map((item) => timeoutConfig(item?.timeout));
|
|
52
|
+
const http = items.map((item) => item?.http);
|
|
53
|
+
return {
|
|
54
|
+
headers: mergeStringRecords(...items.map((item) => item?.headers)),
|
|
55
|
+
timeout: someDefined({
|
|
56
|
+
total: last(timeouts.map((item) => item.total)),
|
|
57
|
+
headers: last(timeouts.map((item) => item.headers)),
|
|
58
|
+
chunk: last(timeouts.map((item) => item.chunk)),
|
|
59
|
+
}),
|
|
60
|
+
http: someDefined({
|
|
61
|
+
query: mergeStringRecords(...http.map((item) => item?.query)),
|
|
62
|
+
body: mergeJsonRecords(...http.map((item) => item?.body)),
|
|
63
|
+
encoding: last(http.map((item) => item?.encoding)),
|
|
64
|
+
}),
|
|
65
|
+
};
|
|
85
66
|
};
|
|
86
67
|
export class GenerationOptions extends Schema.Class("LLM.GenerationOptions")({
|
|
87
68
|
maxTokens: Schema.optional(Schema.Number),
|
|
@@ -112,23 +93,13 @@ export const mergeGenerationOptions = (...items) => {
|
|
|
112
93
|
});
|
|
113
94
|
return Object.values(result).some((value) => value !== undefined) ? result : undefined;
|
|
114
95
|
};
|
|
115
|
-
export
|
|
116
|
-
generation: Schema.optional(GenerationOptions),
|
|
117
|
-
providerOptions: Schema.optional(ProviderOptions),
|
|
118
|
-
http: Schema.optional(HttpOptions),
|
|
119
|
-
}) {
|
|
120
|
-
}
|
|
96
|
+
export var LanguageModelDefaults;
|
|
121
97
|
(function (LanguageModelDefaults) {
|
|
122
98
|
/** Normalize selected-model request defaults without applying precedence. */
|
|
123
|
-
LanguageModelDefaults.make = (input) => {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
generation: input.generation === undefined ? undefined : GenerationOptions.make(input.generation),
|
|
128
|
-
providerOptions: input.providerOptions,
|
|
129
|
-
http: HttpOptions.make(input.http),
|
|
130
|
-
});
|
|
131
|
-
};
|
|
99
|
+
LanguageModelDefaults.make = (input) => ({
|
|
100
|
+
...input,
|
|
101
|
+
generation: input.generation === undefined ? undefined : GenerationOptions.make(input.generation),
|
|
102
|
+
});
|
|
132
103
|
})(LanguageModelDefaults || (LanguageModelDefaults = {}));
|
|
133
104
|
export const ReasoningEfforts = ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
134
105
|
export const ReasoningEffort = Schema.declare((value) => typeof value === "string", { title: "ReasoningEffort" });
|
package/dist/speech.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Effect, Schema, Stream } from "effect";
|
|
|
2
2
|
import { Media } from "./media.js";
|
|
3
3
|
import { MediaModel } from "./media-model.js";
|
|
4
4
|
import { MediaRoute } from "./route/media.js";
|
|
5
|
-
import { AIError,
|
|
5
|
+
import { AIError, type OpenString, type BaseRequest } from "./schema/index.js";
|
|
6
6
|
import { Service } from "./speech-client.js";
|
|
7
7
|
export type SpeechOptions = MediaModel.Options;
|
|
8
8
|
export type SpeechRoute = MediaRoute.AnyRoute<SpeechRequest, SpeechEvent, SpeechResponse>;
|
|
@@ -47,19 +47,15 @@ declare const SpeechRequestSchema: Schema.Struct<{
|
|
|
47
47
|
readonly instructions: Schema.optional<Schema.String>;
|
|
48
48
|
readonly timestamps: Schema.optional<Schema.Boolean>;
|
|
49
49
|
readonly providerOptions: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
50
|
-
readonly http: Schema.optional<typeof HttpOptions>;
|
|
51
50
|
}>;
|
|
52
51
|
/** 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"> & {
|
|
54
|
-
readonly model: Model;
|
|
52
|
+
export type SpeechRequest<Model extends SpeechModel = SpeechModel> = Omit<typeof SpeechRequestSchema.Type, "model" | "providerOptions" | "format"> & BaseRequest<Model, SpeechModelOptions<Model>> & {
|
|
55
53
|
readonly format?: SpeechFormat;
|
|
56
|
-
readonly providerOptions?: SpeechModelOptions<Model>;
|
|
57
54
|
};
|
|
58
55
|
export type SpeechModelOptions<Model> = Model extends SpeechModel<infer Options> ? Options : never;
|
|
59
56
|
/** 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"
|
|
57
|
+
export type SpeechRequestInput<Model extends SpeechModel = SpeechModel> = Omit<SpeechRequest<Model>, "providerOptions"> & {
|
|
61
58
|
readonly providerOptions?: NoInfer<SpeechModelOptions<Model>>;
|
|
62
|
-
readonly http?: HttpOptions.Input;
|
|
63
59
|
};
|
|
64
60
|
declare const SpeechResponse_base: Schema.Class<SpeechResponse, Schema.Struct<{
|
|
65
61
|
/** The complete audio. Headerless PCM carries `info.encoding`, `info.sampleRate`, and `info.channels`. */
|