@opencode-ai/ai 0.0.0-bootstrap.0 → 0.0.0-next-15617
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 +176 -1
- package/dist/cache-policy.d.ts +2 -0
- package/dist/cache-policy.js +108 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +9 -0
- package/dist/llm.d.ts +223 -0
- package/dist/llm.js +81 -0
- package/dist/protocols/anthropic-messages.d.ts +503 -0
- package/dist/protocols/anthropic-messages.js +745 -0
- package/dist/protocols/bedrock-converse.d.ts +476 -0
- package/dist/protocols/bedrock-converse.js +526 -0
- package/dist/protocols/bedrock-event-stream.d.ts +9 -0
- package/dist/protocols/bedrock-event-stream.js +64 -0
- package/dist/protocols/gemini.d.ts +220 -0
- package/dist/protocols/gemini.js +420 -0
- package/dist/protocols/google-vertex-anthropic.d.ts +494 -0
- package/dist/protocols/google-vertex-anthropic.js +33 -0
- package/dist/protocols/google-vertex-gemini.d.ts +59 -0
- package/dist/protocols/google-vertex-gemini.js +18 -0
- package/dist/protocols/index.d.ts +9 -0
- package/dist/protocols/index.js +9 -0
- package/dist/protocols/openai-chat.d.ts +391 -0
- package/dist/protocols/openai-chat.js +423 -0
- package/dist/protocols/openai-compatible-chat.d.ts +73 -0
- package/dist/protocols/openai-compatible-chat.js +20 -0
- package/dist/protocols/openai-compatible-responses.d.ts +85 -0
- package/dist/protocols/openai-compatible-responses.js +18 -0
- package/dist/protocols/openai-responses.d.ts +613 -0
- package/dist/protocols/openai-responses.js +828 -0
- package/dist/protocols/shared.d.ts +192 -0
- package/dist/protocols/shared.js +236 -0
- package/dist/protocols/utils/bedrock-auth.d.ts +18 -0
- package/dist/protocols/utils/bedrock-auth.js +41 -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 +68 -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 +83 -0
- package/dist/protocols/utils/lifecycle.d.ts +19 -0
- package/dist/protocols/utils/lifecycle.js +65 -0
- package/dist/protocols/utils/openai-options.d.ts +22 -0
- package/dist/protocols/utils/openai-options.js +64 -0
- package/dist/protocols/utils/tool-schema.d.ts +7 -0
- package/dist/protocols/utils/tool-schema.js +79 -0
- package/dist/protocols/utils/tool-stream.d.ts +155 -0
- package/dist/protocols/utils/tool-stream.js +136 -0
- package/dist/protocols.d.ts +1 -0
- package/dist/protocols.js +1 -0
- package/dist/provider-error.d.ts +13 -0
- package/dist/provider-error.js +122 -0
- package/dist/provider-package.d.ts +13 -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.d.ts +150 -0
- package/dist/providers/amazon-bedrock.js +41 -0
- package/dist/providers/anthropic-compatible.d.ts +183 -0
- package/dist/providers/anthropic-compatible.js +44 -0
- package/dist/providers/anthropic.d.ts +181 -0
- package/dist/providers/anthropic.js +39 -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 +183 -0
- package/dist/providers/azure.js +89 -0
- package/dist/providers/cloudflare.d.ts +232 -0
- package/dist/providers/cloudflare.js +87 -0
- package/dist/providers/github-copilot.d.ts +167 -0
- package/dist/providers/github-copilot.js +47 -0
- package/dist/providers/google-vertex/anthropic.d.ts +2 -0
- package/dist/providers/google-vertex/anthropic.js +1 -0
- package/dist/providers/google-vertex-anthropic.d.ts +181 -0
- package/dist/providers/google-vertex-anthropic.js +46 -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 +93 -0
- package/dist/providers/google-vertex.js +49 -0
- package/dist/providers/google.d.ts +85 -0
- package/dist/providers/google.js +33 -0
- package/dist/providers/index.d.ts +15 -0
- package/dist/providers/index.js +15 -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 +107 -0
- package/dist/providers/openai-compatible-responses.js +33 -0
- package/dist/providers/openai-compatible.d.ts +130 -0
- package/dist/providers/openai-compatible.js +55 -0
- package/dist/providers/openai-options.d.ts +30 -0
- package/dist/providers/openai-options.js +42 -0
- package/dist/providers/openai.d.ts +264 -0
- package/dist/providers/openai.js +62 -0
- package/dist/providers/openrouter.d.ts +321 -0
- package/dist/providers/openrouter.js +65 -0
- package/dist/providers/xai.d.ts +169 -0
- package/dist/providers/xai.js +43 -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 +49 -0
- package/dist/route/auth.js +89 -0
- package/dist/route/client.d.ts +330 -0
- package/dist/route/client.js +211 -0
- package/dist/route/endpoint.d.ts +28 -0
- package/dist/route/endpoint.js +21 -0
- package/dist/route/executor.d.ts +12 -0
- package/dist/route/executor.js +229 -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 +76 -0
- package/dist/route/protocol.js +17 -0
- package/dist/route/transport/http.d.ts +33 -0
- package/dist/route/transport/http.js +98 -0
- package/dist/route/transport/index.d.ts +27 -0
- package/dist/route/transport/index.js +4 -0
- package/dist/route/transport/websocket.d.ts +56 -0
- package/dist/route/transport/websocket.js +181 -0
- package/dist/route.d.ts +1 -0
- package/dist/route.js +1 -0
- package/dist/schema/errors.d.ts +153 -0
- package/dist/schema/errors.js +150 -0
- package/dist/schema/events.d.ts +4292 -0
- package/dist/schema/events.js +482 -0
- package/dist/schema/ids.d.ts +30 -0
- package/dist/schema/ids.js +18 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/messages.d.ts +385 -0
- package/dist/schema/messages.js +246 -0
- package/dist/schema/options.d.ts +143 -0
- package/dist/schema/options.js +195 -0
- package/dist/tool-runtime.d.ts +15 -0
- package/dist/tool-runtime.js +35 -0
- package/dist/tool.d.ts +134 -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 +36 -9
- package/index.js +0 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { AuthOptions } from "../route/auth-options";
|
|
2
|
+
import { ProviderID } from "../schema";
|
|
3
|
+
import * as OpenAIChat from "../protocols/openai-chat";
|
|
4
|
+
import * as OpenAIResponses from "../protocols/openai-responses";
|
|
5
|
+
import { withOpenAIOptions } from "./openai-options";
|
|
6
|
+
export const id = ProviderID.make("openai");
|
|
7
|
+
export const routes = [OpenAIResponses.route, OpenAIResponses.webSocketRoute, OpenAIChat.route];
|
|
8
|
+
const auth = (options) => AuthOptions.bearer(options, "OPENAI_API_KEY");
|
|
9
|
+
const defaults = (input) => {
|
|
10
|
+
const { apiKey: _, auth: _auth, baseURL: _baseURL, queryParams: _queryParams, ...rest } = input;
|
|
11
|
+
return rest;
|
|
12
|
+
};
|
|
13
|
+
const configuredRoute = (route, input) => route.with({
|
|
14
|
+
auth: auth(input),
|
|
15
|
+
endpoint: { baseURL: input.baseURL, query: input.queryParams },
|
|
16
|
+
});
|
|
17
|
+
export const configure = (input = {}) => {
|
|
18
|
+
const responsesRoute = configuredRoute(OpenAIResponses.route, input);
|
|
19
|
+
const responsesWebSocketRoute = configuredRoute(OpenAIResponses.webSocketRoute, input);
|
|
20
|
+
const chatRoute = configuredRoute(OpenAIChat.route, input);
|
|
21
|
+
const modelDefaults = defaults(input);
|
|
22
|
+
const responses = (id) => responsesRoute.with(withOpenAIOptions(id, modelDefaults, { textVerbosity: true })).model({ id });
|
|
23
|
+
const responsesWebSocket = (id) => responsesWebSocketRoute.with(withOpenAIOptions(id, modelDefaults, { textVerbosity: true })).model({ id });
|
|
24
|
+
const chat = (id) => chatRoute.with(withOpenAIOptions(id, modelDefaults)).model({ id });
|
|
25
|
+
return {
|
|
26
|
+
id,
|
|
27
|
+
model: responses,
|
|
28
|
+
responses,
|
|
29
|
+
responsesWebSocket,
|
|
30
|
+
chat,
|
|
31
|
+
configure,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export const provider = configure();
|
|
35
|
+
const config = (settings) => {
|
|
36
|
+
const headers = {
|
|
37
|
+
...(settings.organization === undefined ? {} : { "OpenAI-Organization": settings.organization }),
|
|
38
|
+
...(settings.project === undefined ? {} : { "OpenAI-Project": settings.project }),
|
|
39
|
+
...settings.headers,
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
apiKey: settings.apiKey,
|
|
43
|
+
baseURL: settings.baseURL,
|
|
44
|
+
headers: Object.keys(headers).length === 0 ? undefined : headers,
|
|
45
|
+
http: settings.body === undefined ? undefined : { body: { ...settings.body } },
|
|
46
|
+
limits: settings.limits,
|
|
47
|
+
providerOptions: settings.providerOptions,
|
|
48
|
+
queryParams: settings.queryParams === undefined ? undefined : { ...settings.queryParams },
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export const model = (modelID, settings) => {
|
|
52
|
+
const configured = configure(config(settings));
|
|
53
|
+
if (settings.transport === undefined || settings.transport === "http")
|
|
54
|
+
return configured.responses(modelID);
|
|
55
|
+
if (settings.transport === "websocket")
|
|
56
|
+
return configured.responsesWebSocket(modelID);
|
|
57
|
+
throw new Error(`Unsupported OpenAI Responses transport: ${String(settings.transport)}`);
|
|
58
|
+
};
|
|
59
|
+
export const chatModel = (modelID, settings) => configure(config(settings)).chat(modelID);
|
|
60
|
+
export const responses = provider.responses;
|
|
61
|
+
export const responsesWebSocket = provider.responsesWebSocket;
|
|
62
|
+
export const chat = provider.chat;
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { Route, type RouteDefaultsInput } from "../route/client";
|
|
3
|
+
import { Protocol } from "../route/protocol";
|
|
4
|
+
import { type ProviderAuthOption } from "../route/auth-options";
|
|
5
|
+
import { type ModelID, type ProviderOptions } from "../schema";
|
|
6
|
+
import * as OpenAIChat from "../protocols/openai-chat";
|
|
7
|
+
export declare const profile: {
|
|
8
|
+
readonly provider: "openrouter";
|
|
9
|
+
readonly baseURL: "https://openrouter.ai/api/v1";
|
|
10
|
+
};
|
|
11
|
+
export declare const id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
|
|
12
|
+
export interface OpenRouterOptions {
|
|
13
|
+
readonly [key: string]: unknown;
|
|
14
|
+
readonly usage?: boolean | Record<string, unknown>;
|
|
15
|
+
readonly reasoning?: Record<string, unknown>;
|
|
16
|
+
readonly promptCacheKey?: string;
|
|
17
|
+
}
|
|
18
|
+
export type OpenRouterProviderOptionsInput = ProviderOptions & {
|
|
19
|
+
readonly openrouter?: OpenRouterOptions;
|
|
20
|
+
};
|
|
21
|
+
export type ModelOptions = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
22
|
+
readonly baseURL?: string;
|
|
23
|
+
readonly providerOptions?: OpenRouterProviderOptionsInput;
|
|
24
|
+
};
|
|
25
|
+
declare const OpenRouterBody: Schema.StructWithRest<Schema.Struct<{
|
|
26
|
+
model: Schema.String;
|
|
27
|
+
messages: Schema.$Array<Schema.toTaggedUnion<"role", readonly [Schema.Struct<{
|
|
28
|
+
readonly role: Schema.Literal<"system">;
|
|
29
|
+
readonly content: Schema.String;
|
|
30
|
+
}>, Schema.Struct<{
|
|
31
|
+
readonly role: Schema.Literal<"user">;
|
|
32
|
+
readonly content: Schema.Union<readonly [Schema.String, Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
33
|
+
readonly type: Schema.Literal<"text">;
|
|
34
|
+
readonly text: Schema.String;
|
|
35
|
+
}>, Schema.Struct<{
|
|
36
|
+
readonly type: Schema.Literal<"image_url">;
|
|
37
|
+
readonly image_url: Schema.Struct<{
|
|
38
|
+
readonly url: Schema.String;
|
|
39
|
+
}>;
|
|
40
|
+
}>]>>]>;
|
|
41
|
+
}>, Schema.Struct<{
|
|
42
|
+
readonly role: Schema.Literal<"assistant">;
|
|
43
|
+
readonly content: Schema.NullOr<Schema.String>;
|
|
44
|
+
readonly tool_calls: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
45
|
+
readonly id: Schema.String;
|
|
46
|
+
readonly type: Schema.tag<"function">;
|
|
47
|
+
readonly function: Schema.Struct<{
|
|
48
|
+
readonly name: Schema.String;
|
|
49
|
+
readonly arguments: Schema.String;
|
|
50
|
+
}>;
|
|
51
|
+
}>>>;
|
|
52
|
+
readonly reasoning_content: Schema.optional<Schema.String>;
|
|
53
|
+
}>, Schema.Struct<{
|
|
54
|
+
readonly role: Schema.Literal<"tool">;
|
|
55
|
+
readonly tool_call_id: Schema.String;
|
|
56
|
+
readonly content: Schema.String;
|
|
57
|
+
}>]>>;
|
|
58
|
+
tools: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
59
|
+
readonly type: Schema.tag<"function">;
|
|
60
|
+
readonly function: Schema.Struct<{
|
|
61
|
+
readonly name: Schema.String;
|
|
62
|
+
readonly description: Schema.String;
|
|
63
|
+
readonly parameters: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
64
|
+
}>;
|
|
65
|
+
}>>>;
|
|
66
|
+
tool_choice: Schema.optional<Schema.Union<readonly [Schema.Literals<readonly ["auto", "none", "required"]>, Schema.Struct<{
|
|
67
|
+
readonly type: Schema.tag<"function">;
|
|
68
|
+
readonly function: Schema.Struct<{
|
|
69
|
+
readonly name: Schema.String;
|
|
70
|
+
}>;
|
|
71
|
+
}>]>>;
|
|
72
|
+
stream: Schema.Literal<true>;
|
|
73
|
+
stream_options: Schema.optional<Schema.Struct<{
|
|
74
|
+
readonly include_usage: Schema.Boolean;
|
|
75
|
+
}>>;
|
|
76
|
+
store: Schema.optional<Schema.Boolean>;
|
|
77
|
+
reasoning_effort: Schema.optional<Schema.String>;
|
|
78
|
+
max_tokens: Schema.optional<Schema.Number>;
|
|
79
|
+
temperature: Schema.optional<Schema.Number>;
|
|
80
|
+
top_p: Schema.optional<Schema.Number>;
|
|
81
|
+
frequency_penalty: Schema.optional<Schema.Number>;
|
|
82
|
+
presence_penalty: Schema.optional<Schema.Number>;
|
|
83
|
+
seed: Schema.optional<Schema.Number>;
|
|
84
|
+
stop: Schema.optional<Schema.$Array<Schema.String>>;
|
|
85
|
+
}>, readonly [Schema.$Record<Schema.String, Schema.Any>]>;
|
|
86
|
+
export type OpenRouterBody = Schema.Schema.Type<typeof OpenRouterBody>;
|
|
87
|
+
export declare const protocol: Protocol<{
|
|
88
|
+
readonly [x: string]: any;
|
|
89
|
+
readonly model: string;
|
|
90
|
+
readonly messages: readonly ({
|
|
91
|
+
readonly role: "system";
|
|
92
|
+
readonly content: string;
|
|
93
|
+
} | {
|
|
94
|
+
readonly role: "user";
|
|
95
|
+
readonly content: string | readonly ({
|
|
96
|
+
readonly type: "text";
|
|
97
|
+
readonly text: string;
|
|
98
|
+
} | {
|
|
99
|
+
readonly type: "image_url";
|
|
100
|
+
readonly image_url: {
|
|
101
|
+
readonly url: string;
|
|
102
|
+
};
|
|
103
|
+
})[];
|
|
104
|
+
} | {
|
|
105
|
+
readonly role: "assistant";
|
|
106
|
+
readonly content: string | null;
|
|
107
|
+
readonly tool_calls?: readonly {
|
|
108
|
+
readonly id: string;
|
|
109
|
+
readonly type: "function";
|
|
110
|
+
readonly function: {
|
|
111
|
+
readonly name: string;
|
|
112
|
+
readonly arguments: string;
|
|
113
|
+
};
|
|
114
|
+
}[] | undefined;
|
|
115
|
+
readonly reasoning_content?: string | undefined;
|
|
116
|
+
} | {
|
|
117
|
+
readonly role: "tool";
|
|
118
|
+
readonly tool_call_id: string;
|
|
119
|
+
readonly content: string;
|
|
120
|
+
})[];
|
|
121
|
+
readonly stream: true;
|
|
122
|
+
readonly tools?: readonly {
|
|
123
|
+
readonly type: "function";
|
|
124
|
+
readonly function: {
|
|
125
|
+
readonly name: string;
|
|
126
|
+
readonly description: string;
|
|
127
|
+
readonly parameters: {
|
|
128
|
+
readonly [x: string]: unknown;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
}[] | undefined;
|
|
132
|
+
readonly tool_choice?: "required" | "none" | "auto" | {
|
|
133
|
+
readonly type: "function";
|
|
134
|
+
readonly function: {
|
|
135
|
+
readonly name: string;
|
|
136
|
+
};
|
|
137
|
+
} | undefined;
|
|
138
|
+
readonly stream_options?: {
|
|
139
|
+
readonly include_usage: boolean;
|
|
140
|
+
} | undefined;
|
|
141
|
+
readonly store?: boolean | undefined;
|
|
142
|
+
readonly reasoning_effort?: string | undefined;
|
|
143
|
+
readonly max_tokens?: number | undefined;
|
|
144
|
+
readonly temperature?: number | undefined;
|
|
145
|
+
readonly top_p?: number | undefined;
|
|
146
|
+
readonly frequency_penalty?: number | undefined;
|
|
147
|
+
readonly presence_penalty?: number | undefined;
|
|
148
|
+
readonly seed?: number | undefined;
|
|
149
|
+
readonly stop?: readonly string[] | undefined;
|
|
150
|
+
}, string, {
|
|
151
|
+
readonly choices: readonly {
|
|
152
|
+
readonly delta?: {
|
|
153
|
+
readonly content?: string | null | undefined;
|
|
154
|
+
readonly reasoning_content?: string | null | undefined;
|
|
155
|
+
readonly tool_calls?: readonly {
|
|
156
|
+
readonly index: number;
|
|
157
|
+
readonly id?: string | null | undefined;
|
|
158
|
+
readonly function?: {
|
|
159
|
+
readonly name?: string | null | undefined;
|
|
160
|
+
readonly arguments?: string | null | undefined;
|
|
161
|
+
} | null | undefined;
|
|
162
|
+
}[] | null | undefined;
|
|
163
|
+
} | null | undefined;
|
|
164
|
+
readonly finish_reason?: string | null | undefined;
|
|
165
|
+
}[];
|
|
166
|
+
readonly usage?: {
|
|
167
|
+
readonly prompt_tokens?: number | undefined;
|
|
168
|
+
readonly completion_tokens?: number | undefined;
|
|
169
|
+
readonly total_tokens?: number | undefined;
|
|
170
|
+
readonly prompt_tokens_details?: {
|
|
171
|
+
readonly cached_tokens?: number | undefined;
|
|
172
|
+
} | null | undefined;
|
|
173
|
+
readonly completion_tokens_details?: {
|
|
174
|
+
readonly reasoning_tokens?: number | undefined;
|
|
175
|
+
} | null | undefined;
|
|
176
|
+
} | null | undefined;
|
|
177
|
+
}, OpenAIChat.ParserState>;
|
|
178
|
+
export declare const route: Route<{
|
|
179
|
+
readonly [x: string]: any;
|
|
180
|
+
readonly model: string;
|
|
181
|
+
readonly messages: readonly ({
|
|
182
|
+
readonly role: "system";
|
|
183
|
+
readonly content: string;
|
|
184
|
+
} | {
|
|
185
|
+
readonly role: "user";
|
|
186
|
+
readonly content: string | readonly ({
|
|
187
|
+
readonly type: "text";
|
|
188
|
+
readonly text: string;
|
|
189
|
+
} | {
|
|
190
|
+
readonly type: "image_url";
|
|
191
|
+
readonly image_url: {
|
|
192
|
+
readonly url: string;
|
|
193
|
+
};
|
|
194
|
+
})[];
|
|
195
|
+
} | {
|
|
196
|
+
readonly role: "assistant";
|
|
197
|
+
readonly content: string | null;
|
|
198
|
+
readonly tool_calls?: readonly {
|
|
199
|
+
readonly id: string;
|
|
200
|
+
readonly type: "function";
|
|
201
|
+
readonly function: {
|
|
202
|
+
readonly name: string;
|
|
203
|
+
readonly arguments: string;
|
|
204
|
+
};
|
|
205
|
+
}[] | undefined;
|
|
206
|
+
readonly reasoning_content?: string | undefined;
|
|
207
|
+
} | {
|
|
208
|
+
readonly role: "tool";
|
|
209
|
+
readonly tool_call_id: string;
|
|
210
|
+
readonly content: string;
|
|
211
|
+
})[];
|
|
212
|
+
readonly stream: true;
|
|
213
|
+
readonly tools?: readonly {
|
|
214
|
+
readonly type: "function";
|
|
215
|
+
readonly function: {
|
|
216
|
+
readonly name: string;
|
|
217
|
+
readonly description: string;
|
|
218
|
+
readonly parameters: {
|
|
219
|
+
readonly [x: string]: unknown;
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
}[] | undefined;
|
|
223
|
+
readonly tool_choice?: "required" | "none" | "auto" | {
|
|
224
|
+
readonly type: "function";
|
|
225
|
+
readonly function: {
|
|
226
|
+
readonly name: string;
|
|
227
|
+
};
|
|
228
|
+
} | undefined;
|
|
229
|
+
readonly stream_options?: {
|
|
230
|
+
readonly include_usage: boolean;
|
|
231
|
+
} | undefined;
|
|
232
|
+
readonly store?: boolean | undefined;
|
|
233
|
+
readonly reasoning_effort?: string | undefined;
|
|
234
|
+
readonly max_tokens?: number | undefined;
|
|
235
|
+
readonly temperature?: number | undefined;
|
|
236
|
+
readonly top_p?: number | undefined;
|
|
237
|
+
readonly frequency_penalty?: number | undefined;
|
|
238
|
+
readonly presence_penalty?: number | undefined;
|
|
239
|
+
readonly seed?: number | undefined;
|
|
240
|
+
readonly stop?: readonly string[] | undefined;
|
|
241
|
+
}, import("../route/transport/http").HttpPrepared<string>>;
|
|
242
|
+
export declare const routes: Route<{
|
|
243
|
+
readonly [x: string]: any;
|
|
244
|
+
readonly model: string;
|
|
245
|
+
readonly messages: readonly ({
|
|
246
|
+
readonly role: "system";
|
|
247
|
+
readonly content: string;
|
|
248
|
+
} | {
|
|
249
|
+
readonly role: "user";
|
|
250
|
+
readonly content: string | readonly ({
|
|
251
|
+
readonly type: "text";
|
|
252
|
+
readonly text: string;
|
|
253
|
+
} | {
|
|
254
|
+
readonly type: "image_url";
|
|
255
|
+
readonly image_url: {
|
|
256
|
+
readonly url: string;
|
|
257
|
+
};
|
|
258
|
+
})[];
|
|
259
|
+
} | {
|
|
260
|
+
readonly role: "assistant";
|
|
261
|
+
readonly content: string | null;
|
|
262
|
+
readonly tool_calls?: readonly {
|
|
263
|
+
readonly id: string;
|
|
264
|
+
readonly type: "function";
|
|
265
|
+
readonly function: {
|
|
266
|
+
readonly name: string;
|
|
267
|
+
readonly arguments: string;
|
|
268
|
+
};
|
|
269
|
+
}[] | undefined;
|
|
270
|
+
readonly reasoning_content?: string | undefined;
|
|
271
|
+
} | {
|
|
272
|
+
readonly role: "tool";
|
|
273
|
+
readonly tool_call_id: string;
|
|
274
|
+
readonly content: string;
|
|
275
|
+
})[];
|
|
276
|
+
readonly stream: true;
|
|
277
|
+
readonly tools?: readonly {
|
|
278
|
+
readonly type: "function";
|
|
279
|
+
readonly function: {
|
|
280
|
+
readonly name: string;
|
|
281
|
+
readonly description: string;
|
|
282
|
+
readonly parameters: {
|
|
283
|
+
readonly [x: string]: unknown;
|
|
284
|
+
};
|
|
285
|
+
};
|
|
286
|
+
}[] | undefined;
|
|
287
|
+
readonly tool_choice?: "required" | "none" | "auto" | {
|
|
288
|
+
readonly type: "function";
|
|
289
|
+
readonly function: {
|
|
290
|
+
readonly name: string;
|
|
291
|
+
};
|
|
292
|
+
} | undefined;
|
|
293
|
+
readonly stream_options?: {
|
|
294
|
+
readonly include_usage: boolean;
|
|
295
|
+
} | undefined;
|
|
296
|
+
readonly store?: boolean | undefined;
|
|
297
|
+
readonly reasoning_effort?: string | undefined;
|
|
298
|
+
readonly max_tokens?: number | undefined;
|
|
299
|
+
readonly temperature?: number | undefined;
|
|
300
|
+
readonly top_p?: number | undefined;
|
|
301
|
+
readonly frequency_penalty?: number | undefined;
|
|
302
|
+
readonly presence_penalty?: number | undefined;
|
|
303
|
+
readonly seed?: number | undefined;
|
|
304
|
+
readonly stop?: readonly string[] | undefined;
|
|
305
|
+
}, import("../route/transport/http").HttpPrepared<string>>[];
|
|
306
|
+
export declare const configure: (input?: ModelOptions) => {
|
|
307
|
+
id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
|
|
308
|
+
model: (modelID: string | ModelID) => import("..").Model;
|
|
309
|
+
configure: (input?: ModelOptions) => /*elided*/ any;
|
|
310
|
+
};
|
|
311
|
+
export declare const provider: {
|
|
312
|
+
id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
|
|
313
|
+
model: (modelID: string | ModelID) => import("..").Model;
|
|
314
|
+
configure: (input?: ModelOptions) => {
|
|
315
|
+
id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
|
|
316
|
+
model: (modelID: string | ModelID) => import("..").Model;
|
|
317
|
+
configure: /*elided*/ any;
|
|
318
|
+
};
|
|
319
|
+
};
|
|
320
|
+
export declare const model: (modelID: string | ModelID) => import("..").Model;
|
|
321
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Route } from "../route/client";
|
|
3
|
+
import { Endpoint } from "../route/endpoint";
|
|
4
|
+
import { Framing } from "../route/framing";
|
|
5
|
+
import { Protocol } from "../route/protocol";
|
|
6
|
+
import { AuthOptions } from "../route/auth-options";
|
|
7
|
+
import { ProviderID } from "../schema";
|
|
8
|
+
import * as OpenAICompatibleProfiles from "./openai-compatible-profile";
|
|
9
|
+
import * as OpenAIChat from "../protocols/openai-chat";
|
|
10
|
+
import { isRecord } from "../protocols/shared";
|
|
11
|
+
export const profile = OpenAICompatibleProfiles.profiles.openrouter;
|
|
12
|
+
export const id = ProviderID.make(profile.provider);
|
|
13
|
+
const ADAPTER = "openrouter";
|
|
14
|
+
const OpenRouterBody = Schema.StructWithRest(Schema.Struct(OpenAIChat.bodyFields), [
|
|
15
|
+
Schema.Record(Schema.String, Schema.Any),
|
|
16
|
+
]);
|
|
17
|
+
export const protocol = Protocol.make({
|
|
18
|
+
id: "openrouter-chat",
|
|
19
|
+
body: {
|
|
20
|
+
schema: OpenRouterBody,
|
|
21
|
+
from: (request) => OpenAIChat.protocol.body.from(request).pipe(Effect.map((body) => ({
|
|
22
|
+
...body,
|
|
23
|
+
...bodyOptions(request.providerOptions?.openrouter),
|
|
24
|
+
}))),
|
|
25
|
+
},
|
|
26
|
+
stream: OpenAIChat.protocol.stream,
|
|
27
|
+
});
|
|
28
|
+
const bodyOptions = (input) => {
|
|
29
|
+
const openrouter = isRecord(input) ? input : {};
|
|
30
|
+
return {
|
|
31
|
+
...(openrouter.usage === true
|
|
32
|
+
? { usage: { include: true } }
|
|
33
|
+
: isRecord(openrouter.usage)
|
|
34
|
+
? { usage: openrouter.usage }
|
|
35
|
+
: {}),
|
|
36
|
+
...(isRecord(openrouter.reasoning) ? { reasoning: openrouter.reasoning } : {}),
|
|
37
|
+
...(typeof openrouter.promptCacheKey === "string" ? { prompt_cache_key: openrouter.promptCacheKey } : {}),
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export const route = Route.make({
|
|
41
|
+
id: ADAPTER,
|
|
42
|
+
provider: profile.provider,
|
|
43
|
+
protocol,
|
|
44
|
+
endpoint: Endpoint.path("/chat/completions", { baseURL: profile.baseURL }),
|
|
45
|
+
framing: Framing.sse,
|
|
46
|
+
});
|
|
47
|
+
export const routes = [route];
|
|
48
|
+
const configuredRoute = (input) => {
|
|
49
|
+
const { apiKey: _, auth: _auth, baseURL, ...rest } = input;
|
|
50
|
+
return route.with({
|
|
51
|
+
...rest,
|
|
52
|
+
endpoint: { baseURL: baseURL ?? profile.baseURL },
|
|
53
|
+
auth: AuthOptions.bearer(input, "OPENROUTER_API_KEY"),
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
export const configure = (input = {}) => {
|
|
57
|
+
const route = configuredRoute(input);
|
|
58
|
+
return {
|
|
59
|
+
id,
|
|
60
|
+
model: (modelID) => route.model({ id: modelID }),
|
|
61
|
+
configure,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export const provider = configure();
|
|
65
|
+
export const model = provider.model;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { type ProviderAuthOption } from "../route/auth-options";
|
|
2
|
+
import type { RouteDefaultsInput } from "../route/client";
|
|
3
|
+
import { type ModelID } from "../schema";
|
|
4
|
+
export declare const id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
|
|
5
|
+
export type ModelOptions = RouteDefaultsInput & ProviderAuthOption<"optional"> & {
|
|
6
|
+
readonly baseURL?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const routes: (import("../route").Route<{
|
|
9
|
+
readonly model: string;
|
|
10
|
+
readonly messages: readonly ({
|
|
11
|
+
readonly role: "system";
|
|
12
|
+
readonly content: string;
|
|
13
|
+
} | {
|
|
14
|
+
readonly role: "user";
|
|
15
|
+
readonly content: string | readonly ({
|
|
16
|
+
readonly type: "text";
|
|
17
|
+
readonly text: string;
|
|
18
|
+
} | {
|
|
19
|
+
readonly type: "image_url";
|
|
20
|
+
readonly image_url: {
|
|
21
|
+
readonly url: string;
|
|
22
|
+
};
|
|
23
|
+
})[];
|
|
24
|
+
} | {
|
|
25
|
+
readonly role: "assistant";
|
|
26
|
+
readonly content: string | null;
|
|
27
|
+
readonly tool_calls?: readonly {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly type: "function";
|
|
30
|
+
readonly function: {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly arguments: string;
|
|
33
|
+
};
|
|
34
|
+
}[] | undefined;
|
|
35
|
+
readonly reasoning_content?: string | undefined;
|
|
36
|
+
} | {
|
|
37
|
+
readonly role: "tool";
|
|
38
|
+
readonly tool_call_id: string;
|
|
39
|
+
readonly content: string;
|
|
40
|
+
})[];
|
|
41
|
+
readonly stream: true;
|
|
42
|
+
readonly tools?: readonly {
|
|
43
|
+
readonly type: "function";
|
|
44
|
+
readonly function: {
|
|
45
|
+
readonly name: string;
|
|
46
|
+
readonly description: string;
|
|
47
|
+
readonly parameters: {
|
|
48
|
+
readonly [x: string]: unknown;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
}[] | undefined;
|
|
52
|
+
readonly tool_choice?: "required" | "none" | "auto" | {
|
|
53
|
+
readonly type: "function";
|
|
54
|
+
readonly function: {
|
|
55
|
+
readonly name: string;
|
|
56
|
+
};
|
|
57
|
+
} | undefined;
|
|
58
|
+
readonly stream_options?: {
|
|
59
|
+
readonly include_usage: boolean;
|
|
60
|
+
} | undefined;
|
|
61
|
+
readonly store?: boolean | undefined;
|
|
62
|
+
readonly reasoning_effort?: string | undefined;
|
|
63
|
+
readonly max_tokens?: number | undefined;
|
|
64
|
+
readonly temperature?: number | undefined;
|
|
65
|
+
readonly top_p?: number | undefined;
|
|
66
|
+
readonly frequency_penalty?: number | undefined;
|
|
67
|
+
readonly presence_penalty?: number | undefined;
|
|
68
|
+
readonly seed?: number | undefined;
|
|
69
|
+
readonly stop?: readonly string[] | undefined;
|
|
70
|
+
}, import("../route/transport/http").HttpPrepared<string>> | import("../route").Route<{
|
|
71
|
+
readonly stream: true;
|
|
72
|
+
readonly model: string;
|
|
73
|
+
readonly input: readonly ({
|
|
74
|
+
readonly role: "system";
|
|
75
|
+
readonly content: string;
|
|
76
|
+
} | {
|
|
77
|
+
readonly role: "user";
|
|
78
|
+
readonly content: readonly ({
|
|
79
|
+
readonly type: "input_text";
|
|
80
|
+
readonly text: string;
|
|
81
|
+
} | {
|
|
82
|
+
readonly type: "input_image";
|
|
83
|
+
readonly image_url: string;
|
|
84
|
+
})[];
|
|
85
|
+
} | {
|
|
86
|
+
readonly role: "assistant";
|
|
87
|
+
readonly content: readonly {
|
|
88
|
+
readonly type: "output_text";
|
|
89
|
+
readonly text: string;
|
|
90
|
+
}[];
|
|
91
|
+
} | {
|
|
92
|
+
readonly type: "reasoning";
|
|
93
|
+
readonly summary: readonly {
|
|
94
|
+
readonly type: "summary_text";
|
|
95
|
+
readonly text: string;
|
|
96
|
+
}[];
|
|
97
|
+
readonly id?: string | undefined;
|
|
98
|
+
readonly encrypted_content?: string | null | undefined;
|
|
99
|
+
} | {
|
|
100
|
+
readonly type: "item_reference";
|
|
101
|
+
readonly id: string;
|
|
102
|
+
} | {
|
|
103
|
+
readonly type: "function_call";
|
|
104
|
+
readonly call_id: string;
|
|
105
|
+
readonly name: string;
|
|
106
|
+
readonly arguments: string;
|
|
107
|
+
} | {
|
|
108
|
+
readonly type: "function_call_output";
|
|
109
|
+
readonly call_id: string;
|
|
110
|
+
readonly output: string | readonly ({
|
|
111
|
+
readonly type: "input_text";
|
|
112
|
+
readonly text: string;
|
|
113
|
+
} | {
|
|
114
|
+
readonly type: "input_image";
|
|
115
|
+
readonly image_url: string;
|
|
116
|
+
})[];
|
|
117
|
+
})[];
|
|
118
|
+
readonly instructions?: string | undefined;
|
|
119
|
+
readonly tools?: readonly {
|
|
120
|
+
readonly type: "function";
|
|
121
|
+
readonly name: string;
|
|
122
|
+
readonly description: string;
|
|
123
|
+
readonly parameters: {
|
|
124
|
+
readonly [x: string]: unknown;
|
|
125
|
+
};
|
|
126
|
+
readonly strict?: boolean | undefined;
|
|
127
|
+
}[] | undefined;
|
|
128
|
+
readonly tool_choice?: "required" | "none" | "auto" | {
|
|
129
|
+
readonly type: "function";
|
|
130
|
+
readonly name: string;
|
|
131
|
+
} | undefined;
|
|
132
|
+
readonly store?: boolean | undefined;
|
|
133
|
+
readonly service_tier?: "auto" | "default" | "flex" | "priority" | undefined;
|
|
134
|
+
readonly prompt_cache_key?: string | undefined;
|
|
135
|
+
readonly include?: readonly ("file_search_call.results" | "web_search_call.results" | "web_search_call.action.sources" | "message.input_image.image_url" | "computer_call_output.output.image_url" | "code_interpreter_call.outputs" | "reasoning.encrypted_content" | "message.output_text.logprobs")[] | undefined;
|
|
136
|
+
readonly reasoning?: {
|
|
137
|
+
readonly effort?: string | undefined;
|
|
138
|
+
readonly summary?: "auto" | undefined;
|
|
139
|
+
} | undefined;
|
|
140
|
+
readonly text?: {
|
|
141
|
+
readonly verbosity?: "low" | "medium" | "high" | undefined;
|
|
142
|
+
} | undefined;
|
|
143
|
+
readonly max_output_tokens?: number | undefined;
|
|
144
|
+
readonly temperature?: number | undefined;
|
|
145
|
+
readonly top_p?: number | undefined;
|
|
146
|
+
}, import("../route/transport/http").HttpPrepared<string>>)[];
|
|
147
|
+
export declare const configure: (input?: ModelOptions) => {
|
|
148
|
+
id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
|
|
149
|
+
model: (modelID: string | ModelID) => import("..").Model;
|
|
150
|
+
responses: (modelID: string | ModelID) => import("..").Model;
|
|
151
|
+
chat: (modelID: string | ModelID) => import("..").Model;
|
|
152
|
+
configure: (input?: ModelOptions) => /*elided*/ any;
|
|
153
|
+
};
|
|
154
|
+
export declare const provider: {
|
|
155
|
+
id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
|
|
156
|
+
model: (modelID: string | ModelID) => import("..").Model;
|
|
157
|
+
responses: (modelID: string | ModelID) => import("..").Model;
|
|
158
|
+
chat: (modelID: string | ModelID) => import("..").Model;
|
|
159
|
+
configure: (input?: ModelOptions) => {
|
|
160
|
+
id: string & import("effect/Brand").Brand<"LLM.ProviderID">;
|
|
161
|
+
model: (modelID: string | ModelID) => import("..").Model;
|
|
162
|
+
responses: (modelID: string | ModelID) => import("..").Model;
|
|
163
|
+
chat: (modelID: string | ModelID) => import("..").Model;
|
|
164
|
+
configure: /*elided*/ any;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
export declare const model: (modelID: string | ModelID) => import("..").Model;
|
|
168
|
+
export declare const responses: (modelID: string | ModelID) => import("..").Model;
|
|
169
|
+
export declare const chat: (modelID: string | ModelID) => import("..").Model;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AuthOptions } from "../route/auth-options";
|
|
2
|
+
import { ProviderID } from "../schema";
|
|
3
|
+
import * as OpenAICompatibleProfiles from "./openai-compatible-profile";
|
|
4
|
+
import * as OpenAICompatibleChat from "../protocols/openai-compatible-chat";
|
|
5
|
+
import * as OpenAIResponses from "../protocols/openai-responses";
|
|
6
|
+
export const id = ProviderID.make("xai");
|
|
7
|
+
export const routes = [OpenAIResponses.route, OpenAICompatibleChat.route];
|
|
8
|
+
const auth = (options) => AuthOptions.bearer(options, "XAI_API_KEY");
|
|
9
|
+
const configuredResponsesRoute = (input) => {
|
|
10
|
+
const { apiKey: _, auth: _auth, baseURL, ...rest } = input;
|
|
11
|
+
return OpenAIResponses.route.with({
|
|
12
|
+
...rest,
|
|
13
|
+
provider: id,
|
|
14
|
+
endpoint: { baseURL: baseURL ?? OpenAICompatibleProfiles.profiles.xai.baseURL },
|
|
15
|
+
auth: auth(input),
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
const configuredChatRoute = (input) => {
|
|
19
|
+
const { apiKey: _, auth: _auth, baseURL, ...rest } = input;
|
|
20
|
+
return OpenAICompatibleChat.route.with({
|
|
21
|
+
...rest,
|
|
22
|
+
provider: id,
|
|
23
|
+
endpoint: { baseURL: baseURL ?? OpenAICompatibleProfiles.profiles.xai.baseURL },
|
|
24
|
+
auth: auth(input),
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
export const configure = (input = {}) => {
|
|
28
|
+
const responsesRoute = configuredResponsesRoute(input);
|
|
29
|
+
const chatRoute = configuredChatRoute(input);
|
|
30
|
+
const responses = (modelID) => responsesRoute.model({ id: modelID });
|
|
31
|
+
const chat = (modelID) => chatRoute.model({ id: modelID });
|
|
32
|
+
return {
|
|
33
|
+
id,
|
|
34
|
+
model: responses,
|
|
35
|
+
responses,
|
|
36
|
+
chat,
|
|
37
|
+
configure,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export const provider = configure();
|
|
41
|
+
export const model = provider.model;
|
|
42
|
+
export const responses = provider.responses;
|
|
43
|
+
export const chat = provider.chat;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./providers/index";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./providers/index";
|