@opencode-ai/ai 0.0.0-beta-17492
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 +392 -0
- package/dist/cache-policy.d.ts +2 -0
- package/dist/cache-policy.js +121 -0
- package/dist/image-client.d.ts +19 -0
- package/dist/image-client.js +19 -0
- package/dist/image.d.ts +110 -0
- package/dist/image.js +102 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +12 -0
- package/dist/llm.d.ts +230 -0
- package/dist/llm.js +77 -0
- package/dist/protocols/anthropic-messages.d.ts +633 -0
- package/dist/protocols/anthropic-messages.js +860 -0
- package/dist/protocols/bedrock-converse.d.ts +533 -0
- package/dist/protocols/bedrock-converse.js +584 -0
- package/dist/protocols/bedrock-event-stream.d.ts +9 -0
- package/dist/protocols/bedrock-event-stream.js +73 -0
- package/dist/protocols/gemini.d.ts +300 -0
- package/dist/protocols/gemini.js +512 -0
- package/dist/protocols/google-images.d.ts +30 -0
- package/dist/protocols/google-images.js +191 -0
- package/dist/protocols/index.d.ts +10 -0
- package/dist/protocols/index.js +10 -0
- package/dist/protocols/open-responses-channel.d.ts +26 -0
- package/dist/protocols/open-responses-channel.js +120 -0
- package/dist/protocols/open-responses.d.ts +951 -0
- package/dist/protocols/open-responses.js +873 -0
- package/dist/protocols/openai-chat.d.ts +795 -0
- package/dist/protocols/openai-chat.js +718 -0
- package/dist/protocols/openai-compatible-chat.d.ts +107 -0
- package/dist/protocols/openai-compatible-chat.js +20 -0
- package/dist/protocols/openai-compatible-responses.d.ts +96 -0
- package/dist/protocols/openai-compatible-responses.js +17 -0
- package/dist/protocols/openai-images.d.ts +32 -0
- package/dist/protocols/openai-images.js +188 -0
- package/dist/protocols/openai-responses-channel.d.ts +12 -0
- package/dist/protocols/openai-responses-channel.js +142 -0
- package/dist/protocols/openai-responses.d.ts +596 -0
- package/dist/protocols/openai-responses.js +208 -0
- package/dist/protocols/shared.d.ts +194 -0
- package/dist/protocols/shared.js +238 -0
- package/dist/protocols/utils/bedrock-auth.d.ts +21 -0
- package/dist/protocols/utils/bedrock-auth.js +43 -0
- package/dist/protocols/utils/bedrock-cache.d.ts +15 -0
- package/dist/protocols/utils/bedrock-cache.js +29 -0
- package/dist/protocols/utils/bedrock-media.d.ts +49 -0
- package/dist/protocols/utils/bedrock-media.js +70 -0
- package/dist/protocols/utils/cache.d.ts +6 -0
- package/dist/protocols/utils/cache.js +8 -0
- package/dist/protocols/utils/gemini-tool-schema.d.ts +2 -0
- package/dist/protocols/utils/gemini-tool-schema.js +103 -0
- package/dist/protocols/utils/image-input.d.ts +21 -0
- package/dist/protocols/utils/image-input.js +22 -0
- package/dist/protocols/utils/lifecycle.d.ts +20 -0
- package/dist/protocols/utils/lifecycle.js +68 -0
- package/dist/protocols/utils/open-responses-options.d.ts +21 -0
- package/dist/protocols/utils/open-responses-options.js +41 -0
- package/dist/protocols/utils/openai-image.d.ts +5 -0
- package/dist/protocols/utils/openai-image.js +18 -0
- package/dist/protocols/utils/openai-options.d.ts +14 -0
- package/dist/protocols/utils/openai-options.js +14 -0
- package/dist/protocols/utils/tool-schema.d.ts +8 -0
- package/dist/protocols/utils/tool-schema.js +81 -0
- package/dist/protocols/utils/tool-stream.d.ts +639 -0
- package/dist/protocols/utils/tool-stream.js +141 -0
- package/dist/protocols/xai-images.d.ts +26 -0
- package/dist/protocols/xai-images.js +111 -0
- package/dist/protocols/zai-images.d.ts +22 -0
- package/dist/protocols/zai-images.js +84 -0
- package/dist/protocols.d.ts +1 -0
- package/dist/protocols.js +1 -0
- package/dist/provider-error.d.ts +14 -0
- package/dist/provider-error.js +130 -0
- package/dist/provider-package.d.ts +15 -0
- package/dist/provider-package.js +1 -0
- package/dist/provider.d.ts +23 -0
- package/dist/provider.js +2 -0
- package/dist/providers/amazon-bedrock/mantle/chat.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle/chat.js +1 -0
- package/dist/providers/amazon-bedrock/mantle/responses.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle/responses.js +1 -0
- package/dist/providers/amazon-bedrock/mantle.d.ts +2 -0
- package/dist/providers/amazon-bedrock/mantle.js +1 -0
- package/dist/providers/amazon-bedrock-mantle.d.ts +247 -0
- package/dist/providers/amazon-bedrock-mantle.js +68 -0
- package/dist/providers/amazon-bedrock.d.ts +172 -0
- package/dist/providers/amazon-bedrock.js +41 -0
- package/dist/providers/anthropic-compatible.d.ts +218 -0
- package/dist/providers/anthropic-compatible.js +45 -0
- package/dist/providers/anthropic.d.ts +216 -0
- package/dist/providers/anthropic.js +40 -0
- package/dist/providers/azure/chat.d.ts +2 -0
- package/dist/providers/azure/chat.js +1 -0
- package/dist/providers/azure/responses.d.ts +2 -0
- package/dist/providers/azure/responses.js +1 -0
- package/dist/providers/azure.d.ts +248 -0
- package/dist/providers/azure.js +90 -0
- package/dist/providers/cloudflare.d.ts +338 -0
- package/dist/providers/cloudflare.js +87 -0
- package/dist/providers/google-vertex/chat.d.ts +2 -0
- package/dist/providers/google-vertex/chat.js +1 -0
- package/dist/providers/google-vertex/gemini.d.ts +2 -0
- package/dist/providers/google-vertex/gemini.js +1 -0
- package/dist/providers/google-vertex/messages.d.ts +2 -0
- package/dist/providers/google-vertex/messages.js +1 -0
- package/dist/providers/google-vertex/responses.d.ts +2 -0
- package/dist/providers/google-vertex/responses.js +1 -0
- package/dist/providers/google-vertex-chat.d.ts +131 -0
- package/dist/providers/google-vertex-chat.js +50 -0
- package/dist/providers/google-vertex-messages.d.ts +215 -0
- package/dist/providers/google-vertex-messages.js +75 -0
- package/dist/providers/google-vertex-responses.d.ts +122 -0
- package/dist/providers/google-vertex-responses.js +51 -0
- package/dist/providers/google-vertex-shared.d.ts +22 -0
- package/dist/providers/google-vertex-shared.js +61 -0
- package/dist/providers/google-vertex.d.ts +115 -0
- package/dist/providers/google-vertex.js +64 -0
- package/dist/providers/google.d.ts +112 -0
- package/dist/providers/google.js +43 -0
- package/dist/providers/index.d.ts +18 -0
- package/dist/providers/index.js +18 -0
- package/dist/providers/open-responses-options.d.ts +16 -0
- package/dist/providers/open-responses-options.js +1 -0
- package/dist/providers/openai/chat.d.ts +2 -0
- package/dist/providers/openai/chat.js +1 -0
- package/dist/providers/openai/responses.d.ts +2 -0
- package/dist/providers/openai/responses.js +1 -0
- package/dist/providers/openai-compatible/responses.d.ts +1 -0
- package/dist/providers/openai-compatible/responses.js +1 -0
- package/dist/providers/openai-compatible-profile.d.ts +43 -0
- package/dist/providers/openai-compatible-profile.js +12 -0
- package/dist/providers/openai-compatible-responses.d.ts +120 -0
- package/dist/providers/openai-compatible-responses.js +33 -0
- package/dist/providers/openai-compatible.d.ts +167 -0
- package/dist/providers/openai-compatible.js +55 -0
- package/dist/providers/openai-options.d.ts +21 -0
- package/dist/providers/openai-options.js +41 -0
- package/dist/providers/openai.d.ts +264 -0
- package/dist/providers/openai.js +83 -0
- package/dist/providers/openrouter.d.ts +537 -0
- package/dist/providers/openrouter.js +117 -0
- package/dist/providers/xai.d.ts +249 -0
- package/dist/providers/xai.js +79 -0
- package/dist/providers/zai.d.ts +24 -0
- package/dist/providers/zai.js +21 -0
- package/dist/providers.d.ts +1 -0
- package/dist/providers.js +1 -0
- package/dist/route/auth-options.d.ts +34 -0
- package/dist/route/auth-options.js +14 -0
- package/dist/route/auth.d.ts +51 -0
- package/dist/route/auth.js +89 -0
- package/dist/route/client.d.ts +348 -0
- package/dist/route/client.js +214 -0
- package/dist/route/endpoint.d.ts +28 -0
- package/dist/route/endpoint.js +21 -0
- package/dist/route/executor.d.ts +23 -0
- package/dist/route/executor.js +227 -0
- package/dist/route/framing.d.ts +23 -0
- package/dist/route/framing.js +4 -0
- package/dist/route/index.d.ts +16 -0
- package/dist/route/index.js +9 -0
- package/dist/route/protocol.d.ts +77 -0
- package/dist/route/protocol.js +17 -0
- package/dist/route/transport/http.d.ts +34 -0
- package/dist/route/transport/http.js +63 -0
- package/dist/route/transport/index.d.ts +39 -0
- package/dist/route/transport/index.js +4 -0
- package/dist/route/transport/websocket-channel.d.ts +56 -0
- package/dist/route/transport/websocket-channel.js +1 -0
- package/dist/route/transport/websocket.d.ts +55 -0
- package/dist/route/transport/websocket.js +326 -0
- package/dist/route.d.ts +1 -0
- package/dist/route.js +1 -0
- package/dist/schema/errors.d.ts +159 -0
- package/dist/schema/errors.js +155 -0
- package/dist/schema/events.d.ts +4587 -0
- package/dist/schema/events.js +492 -0
- package/dist/schema/ids.d.ts +30 -0
- package/dist/schema/ids.js +19 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/messages.d.ts +402 -0
- package/dist/schema/messages.js +244 -0
- package/dist/schema/options.d.ts +159 -0
- package/dist/schema/options.js +202 -0
- package/dist/testing.d.ts +1493 -0
- package/dist/testing.js +88 -0
- package/dist/tool-runtime.d.ts +15 -0
- package/dist/tool-runtime.js +54 -0
- package/dist/tool.d.ts +135 -0
- package/dist/tool.js +66 -0
- package/dist/utils/record.d.ts +2 -0
- package/dist/utils/record.js +2 -0
- package/package.json +47 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { ModelID, ProviderID } from "./ids.js";
|
|
3
|
+
import type { AnyRoute } from "../route/client.js";
|
|
4
|
+
export declare const mergeJsonRecords: (...items: ReadonlyArray<Record<string, unknown> | undefined>) => Record<string, unknown> | undefined;
|
|
5
|
+
export declare const ProviderOptions: Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
6
|
+
export type ProviderOptions = Schema.Schema.Type<typeof ProviderOptions>;
|
|
7
|
+
export declare const mergeProviderOptions: (...items: ReadonlyArray<ProviderOptions | undefined>) => ProviderOptions | undefined;
|
|
8
|
+
declare const HttpOptions_base: Schema.Class<HttpOptions, Schema.Struct<{
|
|
9
|
+
readonly body: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
10
|
+
readonly headers: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
|
|
11
|
+
readonly query: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
|
|
12
|
+
}>, {}>;
|
|
13
|
+
export declare class HttpOptions extends HttpOptions_base {
|
|
14
|
+
}
|
|
15
|
+
export declare namespace HttpOptions {
|
|
16
|
+
type Input = HttpOptions | ConstructorParameters<typeof HttpOptions>[0];
|
|
17
|
+
/** Normalize HTTP option input into the canonical `HttpOptions` class. */
|
|
18
|
+
const make: (input: Input) => HttpOptions;
|
|
19
|
+
}
|
|
20
|
+
export declare const mergeHttpOptions: (...items: ReadonlyArray<HttpOptions | undefined>) => HttpOptions | undefined;
|
|
21
|
+
declare const GenerationOptions_base: Schema.Class<GenerationOptions, Schema.Struct<{
|
|
22
|
+
readonly maxTokens: Schema.optional<Schema.Number>;
|
|
23
|
+
readonly temperature: Schema.optional<Schema.Number>;
|
|
24
|
+
readonly topP: Schema.optional<Schema.Number>;
|
|
25
|
+
readonly topK: Schema.optional<Schema.Number>;
|
|
26
|
+
readonly frequencyPenalty: Schema.optional<Schema.Number>;
|
|
27
|
+
readonly presencePenalty: Schema.optional<Schema.Number>;
|
|
28
|
+
readonly seed: Schema.optional<Schema.Number>;
|
|
29
|
+
readonly stop: Schema.optional<Schema.$Array<Schema.String>>;
|
|
30
|
+
}>, {}>;
|
|
31
|
+
export declare class GenerationOptions extends GenerationOptions_base {
|
|
32
|
+
}
|
|
33
|
+
export declare namespace GenerationOptions {
|
|
34
|
+
type Input = GenerationOptions | ConstructorParameters<typeof GenerationOptions>[0];
|
|
35
|
+
/** Normalize generation option input into the canonical `GenerationOptions` class. */
|
|
36
|
+
const make: (input?: Input) => GenerationOptions;
|
|
37
|
+
}
|
|
38
|
+
export type GenerationOptionsFields = {
|
|
39
|
+
readonly maxTokens?: number;
|
|
40
|
+
readonly temperature?: number;
|
|
41
|
+
readonly topP?: number;
|
|
42
|
+
readonly topK?: number;
|
|
43
|
+
readonly frequencyPenalty?: number;
|
|
44
|
+
readonly presencePenalty?: number;
|
|
45
|
+
readonly seed?: number;
|
|
46
|
+
readonly stop?: ReadonlyArray<string>;
|
|
47
|
+
};
|
|
48
|
+
export type GenerationOptionsInput = GenerationOptions | GenerationOptionsFields;
|
|
49
|
+
export declare const mergeGenerationOptions: (...items: ReadonlyArray<GenerationOptionsInput | undefined>) => GenerationOptions | undefined;
|
|
50
|
+
declare const LanguageModelLimits_base: Schema.Class<LanguageModelLimits, Schema.Struct<{
|
|
51
|
+
readonly context: Schema.optional<Schema.Number>;
|
|
52
|
+
readonly input: Schema.optional<Schema.Number>;
|
|
53
|
+
readonly output: Schema.optional<Schema.Number>;
|
|
54
|
+
}>, {}>;
|
|
55
|
+
export declare class LanguageModelLimits extends LanguageModelLimits_base {
|
|
56
|
+
}
|
|
57
|
+
export declare namespace LanguageModelLimits {
|
|
58
|
+
type Input = LanguageModelLimits | ConstructorParameters<typeof LanguageModelLimits>[0];
|
|
59
|
+
/** Normalize model limit input into the canonical `LanguageModelLimits` class. */
|
|
60
|
+
const make: (input: Input | undefined) => LanguageModelLimits;
|
|
61
|
+
}
|
|
62
|
+
declare const LanguageModelDefaults_base: Schema.Class<LanguageModelDefaults, Schema.Struct<{
|
|
63
|
+
readonly limits: Schema.optional<typeof LanguageModelLimits>;
|
|
64
|
+
readonly generation: Schema.optional<typeof GenerationOptions>;
|
|
65
|
+
readonly providerOptions: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
66
|
+
readonly http: Schema.optional<typeof HttpOptions>;
|
|
67
|
+
}>, {}>;
|
|
68
|
+
export declare class LanguageModelDefaults extends LanguageModelDefaults_base {
|
|
69
|
+
}
|
|
70
|
+
export declare namespace LanguageModelDefaults {
|
|
71
|
+
type Input = LanguageModelDefaults | {
|
|
72
|
+
readonly limits?: LanguageModelLimits.Input;
|
|
73
|
+
readonly generation?: GenerationOptions.Input;
|
|
74
|
+
readonly providerOptions?: ProviderOptions;
|
|
75
|
+
readonly http?: HttpOptions.Input;
|
|
76
|
+
};
|
|
77
|
+
/** Normalize selected-model request defaults without applying precedence. */
|
|
78
|
+
const make: (input: Input) => LanguageModelDefaults;
|
|
79
|
+
}
|
|
80
|
+
export declare const LanguageModelToolSchemaCompatibility: Schema.Literals<readonly ["gemini", "moonshot"]>;
|
|
81
|
+
export type LanguageModelToolSchemaCompatibility = Schema.Schema.Type<typeof LanguageModelToolSchemaCompatibility>;
|
|
82
|
+
export declare const LanguageModelMaxTokensFieldCompatibility: Schema.Literals<readonly ["max_completion_tokens", "max_tokens"]>;
|
|
83
|
+
export type LanguageModelMaxTokensFieldCompatibility = Schema.Schema.Type<typeof LanguageModelMaxTokensFieldCompatibility>;
|
|
84
|
+
declare const LanguageModelCompatibility_base: Schema.Class<LanguageModelCompatibility, Schema.Struct<{
|
|
85
|
+
readonly toolSchema: Schema.optional<Schema.Literals<readonly ["gemini", "moonshot"]>>;
|
|
86
|
+
readonly reasoningField: Schema.optional<Schema.String>;
|
|
87
|
+
readonly maxTokensField: Schema.optional<Schema.Literals<readonly ["max_completion_tokens", "max_tokens"]>>;
|
|
88
|
+
readonly requireFinishReason: Schema.optional<Schema.Boolean>;
|
|
89
|
+
}>, {}>;
|
|
90
|
+
export declare class LanguageModelCompatibility extends LanguageModelCompatibility_base {
|
|
91
|
+
}
|
|
92
|
+
export declare namespace LanguageModelCompatibility {
|
|
93
|
+
type Input = LanguageModelCompatibility | ConstructorParameters<typeof LanguageModelCompatibility>[0];
|
|
94
|
+
/** Normalize model/upstream compatibility metadata without projecting requests. */
|
|
95
|
+
const make: (input: Input) => LanguageModelCompatibility;
|
|
96
|
+
}
|
|
97
|
+
export declare class LanguageModel<Options extends ProviderOptions = ProviderOptions> {
|
|
98
|
+
protected readonly _ProviderOptions: Options;
|
|
99
|
+
readonly id: ModelID;
|
|
100
|
+
readonly provider: ProviderID;
|
|
101
|
+
readonly route: AnyRoute;
|
|
102
|
+
readonly defaults?: LanguageModelDefaults;
|
|
103
|
+
readonly compatibility?: LanguageModelCompatibility;
|
|
104
|
+
constructor(input: LanguageModel.ConstructorInput);
|
|
105
|
+
static make<Options extends ProviderOptions = ProviderOptions>(input: LanguageModel.Input): LanguageModel<Options>;
|
|
106
|
+
static input<Options extends ProviderOptions>(model: LanguageModel<Options>): LanguageModel.ConstructorInput;
|
|
107
|
+
static update<Options extends ProviderOptions>(model: LanguageModel<Options>, patch: Partial<LanguageModel.Input>): LanguageModel<Options>;
|
|
108
|
+
}
|
|
109
|
+
export declare namespace LanguageModel {
|
|
110
|
+
type ConstructorInput = {
|
|
111
|
+
readonly id: ModelID;
|
|
112
|
+
readonly provider: ProviderID;
|
|
113
|
+
readonly route: AnyRoute;
|
|
114
|
+
readonly defaults?: LanguageModelDefaults;
|
|
115
|
+
readonly compatibility?: LanguageModelCompatibility;
|
|
116
|
+
};
|
|
117
|
+
type Input = Omit<ConstructorInput, "id" | "provider" | "defaults" | "compatibility"> & {
|
|
118
|
+
readonly id: string | ModelID;
|
|
119
|
+
readonly provider: string | ProviderID;
|
|
120
|
+
readonly defaults?: LanguageModelDefaults.Input;
|
|
121
|
+
readonly compatibility?: LanguageModelCompatibility.Input;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export type LanguageModelInput = LanguageModel.Input;
|
|
125
|
+
export type LanguageModelProviderOptions<SelectedModel> = SelectedModel extends LanguageModel<infer Options> ? Options : never;
|
|
126
|
+
export declare const LanguageModelSchema: Schema.declare<LanguageModel<{
|
|
127
|
+
readonly [x: string]: {
|
|
128
|
+
readonly [x: string]: unknown;
|
|
129
|
+
};
|
|
130
|
+
}>, LanguageModel<{
|
|
131
|
+
readonly [x: string]: {
|
|
132
|
+
readonly [x: string]: unknown;
|
|
133
|
+
};
|
|
134
|
+
}>>;
|
|
135
|
+
declare const CacheHint_base: Schema.Class<CacheHint, Schema.Struct<{
|
|
136
|
+
readonly type: Schema.Literals<readonly ["ephemeral", "persistent"]>;
|
|
137
|
+
readonly ttlSeconds: Schema.optional<Schema.Number>;
|
|
138
|
+
}>, {}>;
|
|
139
|
+
export declare class CacheHint extends CacheHint_base {
|
|
140
|
+
}
|
|
141
|
+
export declare const CachePolicyObject: Schema.Struct<{
|
|
142
|
+
readonly tools: Schema.optional<Schema.Boolean>;
|
|
143
|
+
readonly system: Schema.optional<Schema.Boolean>;
|
|
144
|
+
readonly messages: Schema.optional<Schema.Union<readonly [Schema.Literal<"latest-user-message">, Schema.Literal<"latest-assistant">, Schema.Struct<{
|
|
145
|
+
readonly tail: Schema.Number;
|
|
146
|
+
}>]>>;
|
|
147
|
+
readonly ttlSeconds: Schema.optional<Schema.Number>;
|
|
148
|
+
}>;
|
|
149
|
+
export type CachePolicyObject = Schema.Schema.Type<typeof CachePolicyObject>;
|
|
150
|
+
export declare const CachePolicy: Schema.Union<readonly [Schema.Literal<"auto">, Schema.Literal<"none">, Schema.Struct<{
|
|
151
|
+
readonly tools: Schema.optional<Schema.Boolean>;
|
|
152
|
+
readonly system: Schema.optional<Schema.Boolean>;
|
|
153
|
+
readonly messages: Schema.optional<Schema.Union<readonly [Schema.Literal<"latest-user-message">, Schema.Literal<"latest-assistant">, Schema.Struct<{
|
|
154
|
+
readonly tail: Schema.Number;
|
|
155
|
+
}>]>>;
|
|
156
|
+
readonly ttlSeconds: Schema.optional<Schema.Number>;
|
|
157
|
+
}>]>;
|
|
158
|
+
export type CachePolicy = Schema.Schema.Type<typeof CachePolicy>;
|
|
159
|
+
export {};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { JsonSchema, ModelID, ProviderID } from "./ids.js";
|
|
3
|
+
import { isRecord } from "../utils/record.js";
|
|
4
|
+
export const mergeJsonRecords = (...items) => {
|
|
5
|
+
const defined = items.filter((item) => item !== undefined);
|
|
6
|
+
if (defined.length === 0)
|
|
7
|
+
return undefined;
|
|
8
|
+
if (defined.length === 1 && Object.values(defined[0]).every((value) => value !== undefined))
|
|
9
|
+
return defined[0];
|
|
10
|
+
const result = {};
|
|
11
|
+
for (const item of defined) {
|
|
12
|
+
for (const [key, value] of Object.entries(item)) {
|
|
13
|
+
if (value === undefined)
|
|
14
|
+
continue;
|
|
15
|
+
result[key] = isRecord(result[key]) && isRecord(value) ? mergeJsonRecords(result[key], value) : value;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return Object.keys(result).length === 0 ? undefined : result;
|
|
19
|
+
};
|
|
20
|
+
const mergeStringRecords = (...items) => {
|
|
21
|
+
const defined = items.filter((item) => item !== undefined);
|
|
22
|
+
if (defined.length === 0)
|
|
23
|
+
return undefined;
|
|
24
|
+
if (defined.length === 1)
|
|
25
|
+
return defined[0];
|
|
26
|
+
const result = Object.fromEntries(defined.flatMap((item) => Object.entries(item).filter((entry) => entry[1] !== undefined)));
|
|
27
|
+
return Object.keys(result).length === 0 ? undefined : result;
|
|
28
|
+
};
|
|
29
|
+
export const ProviderOptions = Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.Unknown));
|
|
30
|
+
export const mergeProviderOptions = (...items) => {
|
|
31
|
+
const result = {};
|
|
32
|
+
for (const item of items) {
|
|
33
|
+
if (!item)
|
|
34
|
+
continue;
|
|
35
|
+
for (const [provider, options] of Object.entries(item)) {
|
|
36
|
+
const merged = mergeJsonRecords(result[provider], options);
|
|
37
|
+
if (merged)
|
|
38
|
+
result[provider] = merged;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return Object.keys(result).length === 0 ? undefined : result;
|
|
42
|
+
};
|
|
43
|
+
export class HttpOptions extends Schema.Class("AI.HttpOptions")({
|
|
44
|
+
body: Schema.optional(JsonSchema),
|
|
45
|
+
headers: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
46
|
+
query: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
47
|
+
}) {
|
|
48
|
+
}
|
|
49
|
+
(function (HttpOptions) {
|
|
50
|
+
/** Normalize HTTP option input into the canonical `HttpOptions` class. */
|
|
51
|
+
HttpOptions.make = (input) => (input instanceof HttpOptions ? input : new HttpOptions(input));
|
|
52
|
+
})(HttpOptions || (HttpOptions = {}));
|
|
53
|
+
export const mergeHttpOptions = (...items) => {
|
|
54
|
+
const body = mergeJsonRecords(...items.map((item) => item?.body));
|
|
55
|
+
const headers = mergeStringRecords(...items.map((item) => item?.headers));
|
|
56
|
+
const query = mergeStringRecords(...items.map((item) => item?.query));
|
|
57
|
+
if (!body && !headers && !query)
|
|
58
|
+
return undefined;
|
|
59
|
+
return new HttpOptions({ body, headers, query });
|
|
60
|
+
};
|
|
61
|
+
export class GenerationOptions extends Schema.Class("LLM.GenerationOptions")({
|
|
62
|
+
maxTokens: Schema.optional(Schema.Number),
|
|
63
|
+
temperature: Schema.optional(Schema.Number),
|
|
64
|
+
topP: Schema.optional(Schema.Number),
|
|
65
|
+
topK: Schema.optional(Schema.Number),
|
|
66
|
+
frequencyPenalty: Schema.optional(Schema.Number),
|
|
67
|
+
presencePenalty: Schema.optional(Schema.Number),
|
|
68
|
+
seed: Schema.optional(Schema.Number),
|
|
69
|
+
stop: Schema.optional(Schema.Array(Schema.String)),
|
|
70
|
+
}) {
|
|
71
|
+
}
|
|
72
|
+
(function (GenerationOptions) {
|
|
73
|
+
/** Normalize generation option input into the canonical `GenerationOptions` class. */
|
|
74
|
+
GenerationOptions.make = (input = {}) => (input instanceof GenerationOptions ? input : new GenerationOptions(input));
|
|
75
|
+
})(GenerationOptions || (GenerationOptions = {}));
|
|
76
|
+
const latestGeneration = (items, key) => items.findLast((item) => item?.[key] !== undefined)?.[key];
|
|
77
|
+
export const mergeGenerationOptions = (...items) => {
|
|
78
|
+
const result = new GenerationOptions({
|
|
79
|
+
maxTokens: latestGeneration(items, "maxTokens"),
|
|
80
|
+
temperature: latestGeneration(items, "temperature"),
|
|
81
|
+
topP: latestGeneration(items, "topP"),
|
|
82
|
+
topK: latestGeneration(items, "topK"),
|
|
83
|
+
frequencyPenalty: latestGeneration(items, "frequencyPenalty"),
|
|
84
|
+
presencePenalty: latestGeneration(items, "presencePenalty"),
|
|
85
|
+
seed: latestGeneration(items, "seed"),
|
|
86
|
+
stop: latestGeneration(items, "stop"),
|
|
87
|
+
});
|
|
88
|
+
return Object.values(result).some((value) => value !== undefined) ? result : undefined;
|
|
89
|
+
};
|
|
90
|
+
export class LanguageModelLimits extends Schema.Class("LLM.LanguageModelLimits")({
|
|
91
|
+
context: Schema.optional(Schema.Number),
|
|
92
|
+
input: Schema.optional(Schema.Number),
|
|
93
|
+
output: Schema.optional(Schema.Number),
|
|
94
|
+
}) {
|
|
95
|
+
}
|
|
96
|
+
(function (LanguageModelLimits) {
|
|
97
|
+
/** Normalize model limit input into the canonical `LanguageModelLimits` class. */
|
|
98
|
+
LanguageModelLimits.make = (input) => input instanceof LanguageModelLimits ? input : new LanguageModelLimits(input ?? {});
|
|
99
|
+
})(LanguageModelLimits || (LanguageModelLimits = {}));
|
|
100
|
+
export class LanguageModelDefaults extends Schema.Class("LLM.LanguageModelDefaults")({
|
|
101
|
+
limits: Schema.optional(LanguageModelLimits),
|
|
102
|
+
generation: Schema.optional(GenerationOptions),
|
|
103
|
+
providerOptions: Schema.optional(ProviderOptions),
|
|
104
|
+
http: Schema.optional(HttpOptions),
|
|
105
|
+
}) {
|
|
106
|
+
}
|
|
107
|
+
(function (LanguageModelDefaults) {
|
|
108
|
+
/** Normalize selected-model request defaults without applying precedence. */
|
|
109
|
+
LanguageModelDefaults.make = (input) => {
|
|
110
|
+
if (input instanceof LanguageModelDefaults)
|
|
111
|
+
return input;
|
|
112
|
+
return new LanguageModelDefaults({
|
|
113
|
+
limits: input.limits === undefined ? undefined : LanguageModelLimits.make(input.limits),
|
|
114
|
+
generation: input.generation === undefined ? undefined : GenerationOptions.make(input.generation),
|
|
115
|
+
providerOptions: input.providerOptions,
|
|
116
|
+
http: input.http === undefined ? undefined : HttpOptions.make(input.http),
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
})(LanguageModelDefaults || (LanguageModelDefaults = {}));
|
|
120
|
+
export const LanguageModelToolSchemaCompatibility = Schema.Literals(["gemini", "moonshot"]);
|
|
121
|
+
export const LanguageModelMaxTokensFieldCompatibility = Schema.Literals(["max_completion_tokens", "max_tokens"]);
|
|
122
|
+
export class LanguageModelCompatibility extends Schema.Class("LLM.LanguageModelCompatibility")({
|
|
123
|
+
toolSchema: Schema.optional(LanguageModelToolSchemaCompatibility),
|
|
124
|
+
reasoningField: Schema.optional(Schema.String),
|
|
125
|
+
maxTokensField: Schema.optional(LanguageModelMaxTokensFieldCompatibility),
|
|
126
|
+
requireFinishReason: Schema.optional(Schema.Boolean),
|
|
127
|
+
}) {
|
|
128
|
+
}
|
|
129
|
+
(function (LanguageModelCompatibility) {
|
|
130
|
+
/** Normalize model/upstream compatibility metadata without projecting requests. */
|
|
131
|
+
LanguageModelCompatibility.make = (input) => input instanceof LanguageModelCompatibility ? input : new LanguageModelCompatibility(input);
|
|
132
|
+
})(LanguageModelCompatibility || (LanguageModelCompatibility = {}));
|
|
133
|
+
export class LanguageModel {
|
|
134
|
+
id;
|
|
135
|
+
provider;
|
|
136
|
+
route;
|
|
137
|
+
defaults;
|
|
138
|
+
compatibility;
|
|
139
|
+
constructor(input) {
|
|
140
|
+
this.id = input.id;
|
|
141
|
+
this.provider = input.provider;
|
|
142
|
+
this.route = input.route;
|
|
143
|
+
this.defaults = input.defaults;
|
|
144
|
+
this.compatibility = input.compatibility;
|
|
145
|
+
}
|
|
146
|
+
static make(input) {
|
|
147
|
+
return new LanguageModel({
|
|
148
|
+
id: ModelID.make(input.id),
|
|
149
|
+
provider: ProviderID.make(input.provider),
|
|
150
|
+
route: input.route,
|
|
151
|
+
defaults: input.defaults === undefined ? undefined : LanguageModelDefaults.make(input.defaults),
|
|
152
|
+
compatibility: input.compatibility === undefined ? undefined : LanguageModelCompatibility.make(input.compatibility),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
static input(model) {
|
|
156
|
+
return {
|
|
157
|
+
id: model.id,
|
|
158
|
+
provider: model.provider,
|
|
159
|
+
route: model.route,
|
|
160
|
+
defaults: model.defaults,
|
|
161
|
+
compatibility: model.compatibility,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
static update(model, patch) {
|
|
165
|
+
if (Object.keys(patch).length === 0)
|
|
166
|
+
return model;
|
|
167
|
+
return LanguageModel.make({
|
|
168
|
+
...LanguageModel.input(model),
|
|
169
|
+
...patch,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
export const LanguageModelSchema = Schema.declare((value) => value instanceof LanguageModel, {
|
|
174
|
+
expected: "LLM.LanguageModel",
|
|
175
|
+
});
|
|
176
|
+
export class CacheHint extends Schema.Class("LLM.CacheHint")({
|
|
177
|
+
type: Schema.Literals(["ephemeral", "persistent"]),
|
|
178
|
+
ttlSeconds: Schema.optional(Schema.Number),
|
|
179
|
+
}) {
|
|
180
|
+
}
|
|
181
|
+
// Auto-placement policy for prompt caching. The protocol-neutral lowering step
|
|
182
|
+
// reads this and injects `CacheHint`s at the configured boundaries; the
|
|
183
|
+
// per-protocol body builders then translate those hints into wire markers as
|
|
184
|
+
// usual. `"auto"` is the recommended default for agent loops — it places
|
|
185
|
+
// breakpoints at the last tool definition, the first and last distinct system
|
|
186
|
+
// parts, and the conversation tail. The rolling message breakpoint keeps a
|
|
187
|
+
// prior cache entry within Anthropic/Bedrock's 20-block lookback during long
|
|
188
|
+
// tool loops.
|
|
189
|
+
//
|
|
190
|
+
// Pass `"none"` to opt out entirely (the legacy behavior). Pass the granular
|
|
191
|
+
// object form to override individual choices.
|
|
192
|
+
export const CachePolicyObject = Schema.Struct({
|
|
193
|
+
tools: Schema.optional(Schema.Boolean),
|
|
194
|
+
system: Schema.optional(Schema.Boolean),
|
|
195
|
+
messages: Schema.optional(Schema.Union([
|
|
196
|
+
Schema.Literal("latest-user-message"),
|
|
197
|
+
Schema.Literal("latest-assistant"),
|
|
198
|
+
Schema.Struct({ tail: Schema.Number }),
|
|
199
|
+
])),
|
|
200
|
+
ttlSeconds: Schema.optional(Schema.Number),
|
|
201
|
+
});
|
|
202
|
+
export const CachePolicy = Schema.Union([Schema.Literal("auto"), Schema.Literal("none"), CachePolicyObject]);
|