@opencode/ai 0.0.0-reserved → 2.0.0

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.
Files changed (288) hide show
  1. package/README.md +879 -2
  2. package/dist/cache-policy.d.ts +2 -0
  3. package/dist/cache-policy.js +129 -0
  4. package/dist/image-client.d.ts +19 -0
  5. package/dist/image-client.js +28 -0
  6. package/dist/image.d.ts +110 -0
  7. package/dist/image.js +103 -0
  8. package/dist/index.d.ts +18 -0
  9. package/dist/index.js +12 -0
  10. package/dist/llm.d.ts +252 -0
  11. package/dist/llm.js +74 -0
  12. package/dist/protocols/alibaba-chat.d.ts +225 -0
  13. package/dist/protocols/alibaba-chat.js +75 -0
  14. package/dist/protocols/alibaba-messages.d.ts +350 -0
  15. package/dist/protocols/alibaba-messages.js +40 -0
  16. package/dist/protocols/alibaba-responses.d.ts +255 -0
  17. package/dist/protocols/alibaba-responses.js +80 -0
  18. package/dist/protocols/anthropic-messages.d.ts +980 -0
  19. package/dist/protocols/anthropic-messages.js +1460 -0
  20. package/dist/protocols/bedrock-converse.d.ts +499 -0
  21. package/dist/protocols/bedrock-converse.js +643 -0
  22. package/dist/protocols/bedrock-event-stream.d.ts +9 -0
  23. package/dist/protocols/bedrock-event-stream.js +97 -0
  24. package/dist/protocols/gemini.d.ts +285 -0
  25. package/dist/protocols/gemini.js +671 -0
  26. package/dist/protocols/google-images.d.ts +30 -0
  27. package/dist/protocols/google-images.js +181 -0
  28. package/dist/protocols/index.d.ts +12 -0
  29. package/dist/protocols/index.js +12 -0
  30. package/dist/protocols/meta-images.d.ts +26 -0
  31. package/dist/protocols/meta-images.js +89 -0
  32. package/dist/protocols/meta-messages.d.ts +356 -0
  33. package/dist/protocols/meta-messages.js +41 -0
  34. package/dist/protocols/meta-responses.d.ts +473 -0
  35. package/dist/protocols/meta-responses.js +173 -0
  36. package/dist/protocols/mistral-chat.d.ts +540 -0
  37. package/dist/protocols/mistral-chat.js +624 -0
  38. package/dist/protocols/open-responses-channel.d.ts +25 -0
  39. package/dist/protocols/open-responses-channel.js +141 -0
  40. package/dist/protocols/open-responses-continuation.d.ts +16 -0
  41. package/dist/protocols/open-responses-continuation.js +170 -0
  42. package/dist/protocols/open-responses.d.ts +1715 -0
  43. package/dist/protocols/open-responses.js +1228 -0
  44. package/dist/protocols/openai-chat.d.ts +860 -0
  45. package/dist/protocols/openai-chat.js +966 -0
  46. package/dist/protocols/openai-compatible-chat.d.ts +109 -0
  47. package/dist/protocols/openai-compatible-chat.js +19 -0
  48. package/dist/protocols/openai-compatible-responses.d.ts +172 -0
  49. package/dist/protocols/openai-compatible-responses.js +18 -0
  50. package/dist/protocols/openai-images.d.ts +32 -0
  51. package/dist/protocols/openai-images.js +183 -0
  52. package/dist/protocols/openai-responses.d.ts +1389 -0
  53. package/dist/protocols/openai-responses.js +260 -0
  54. package/dist/protocols/shared.d.ts +193 -0
  55. package/dist/protocols/shared.js +290 -0
  56. package/dist/protocols/utils/bedrock-auth.d.ts +60 -0
  57. package/dist/protocols/utils/bedrock-auth.js +85 -0
  58. package/dist/protocols/utils/bedrock-cache.d.ts +19 -0
  59. package/dist/protocols/utils/bedrock-cache.js +49 -0
  60. package/dist/protocols/utils/bedrock-media.d.ts +55 -0
  61. package/dist/protocols/utils/bedrock-media.js +73 -0
  62. package/dist/protocols/utils/cache.d.ts +6 -0
  63. package/dist/protocols/utils/cache.js +5 -0
  64. package/dist/protocols/utils/gemini-tool-schema.d.ts +2 -0
  65. package/dist/protocols/utils/gemini-tool-schema.js +103 -0
  66. package/dist/protocols/utils/image-input.d.ts +21 -0
  67. package/dist/protocols/utils/image-input.js +20 -0
  68. package/dist/protocols/utils/lifecycle.d.ts +24 -0
  69. package/dist/protocols/utils/lifecycle.js +72 -0
  70. package/dist/protocols/utils/meta-image.d.ts +2 -0
  71. package/dist/protocols/utils/meta-image.js +13 -0
  72. package/dist/protocols/utils/open-responses-options.d.ts +56 -0
  73. package/dist/protocols/utils/open-responses-options.js +61 -0
  74. package/dist/protocols/utils/openai-image.d.ts +5 -0
  75. package/dist/protocols/utils/openai-image.js +18 -0
  76. package/dist/protocols/utils/openai-options.d.ts +16 -0
  77. package/dist/protocols/utils/openai-options.js +14 -0
  78. package/dist/protocols/utils/partial-json-options.d.ts +62 -0
  79. package/dist/protocols/utils/partial-json-options.js +52 -0
  80. package/dist/protocols/utils/partial-json.d.ts +8 -0
  81. package/dist/protocols/utils/partial-json.js +279 -0
  82. package/dist/protocols/utils/responses-checkpoint.d.ts +4 -0
  83. package/dist/protocols/utils/responses-checkpoint.js +107 -0
  84. package/dist/protocols/utils/responses-compaction.d.ts +4 -0
  85. package/dist/protocols/utils/responses-compaction.js +129 -0
  86. package/dist/protocols/utils/responses-hosted-tools.d.ts +26 -0
  87. package/dist/protocols/utils/responses-hosted-tools.js +32 -0
  88. package/dist/protocols/utils/tool-schema.d.ts +8 -0
  89. package/dist/protocols/utils/tool-schema.js +54 -0
  90. package/dist/protocols/utils/tool-stream.d.ts +710 -0
  91. package/dist/protocols/utils/tool-stream.js +155 -0
  92. package/dist/protocols/xai-images.d.ts +26 -0
  93. package/dist/protocols/xai-images.js +106 -0
  94. package/dist/protocols/xai-responses.d.ts +250 -0
  95. package/dist/protocols/xai-responses.js +81 -0
  96. package/dist/protocols/zai-chat.d.ts +202 -0
  97. package/dist/protocols/zai-chat.js +49 -0
  98. package/dist/protocols/zai-images.d.ts +22 -0
  99. package/dist/protocols/zai-images.js +79 -0
  100. package/dist/protocols/zai-messages.d.ts +344 -0
  101. package/dist/protocols/zai-messages.js +27 -0
  102. package/dist/protocols.d.ts +1 -0
  103. package/dist/protocols.js +1 -0
  104. package/dist/provider-error.d.ts +15 -0
  105. package/dist/provider-error.js +125 -0
  106. package/dist/provider-package.d.ts +15 -0
  107. package/dist/provider-package.js +1 -0
  108. package/dist/provider.d.ts +23 -0
  109. package/dist/provider.js +2 -0
  110. package/dist/providers/alibaba/chat.d.ts +1 -0
  111. package/dist/providers/alibaba/chat.js +1 -0
  112. package/dist/providers/alibaba/messages.d.ts +3 -0
  113. package/dist/providers/alibaba/messages.js +1 -0
  114. package/dist/providers/alibaba/responses.d.ts +3 -0
  115. package/dist/providers/alibaba/responses.js +1 -0
  116. package/dist/providers/alibaba.d.ts +711 -0
  117. package/dist/providers/alibaba.js +94 -0
  118. package/dist/providers/amazon-bedrock/mantle/chat.d.ts +2 -0
  119. package/dist/providers/amazon-bedrock/mantle/chat.js +1 -0
  120. package/dist/providers/amazon-bedrock/mantle/responses.d.ts +2 -0
  121. package/dist/providers/amazon-bedrock/mantle/responses.js +1 -0
  122. package/dist/providers/amazon-bedrock/mantle.d.ts +2 -0
  123. package/dist/providers/amazon-bedrock/mantle.js +1 -0
  124. package/dist/providers/amazon-bedrock-mantle.d.ts +313 -0
  125. package/dist/providers/amazon-bedrock-mantle.js +79 -0
  126. package/dist/providers/amazon-bedrock.d.ts +173 -0
  127. package/dist/providers/amazon-bedrock.js +41 -0
  128. package/dist/providers/anthropic-compatible.d.ts +309 -0
  129. package/dist/providers/anthropic-compatible.js +50 -0
  130. package/dist/providers/anthropic.d.ts +307 -0
  131. package/dist/providers/anthropic.js +42 -0
  132. package/dist/providers/azure/chat.d.ts +2 -0
  133. package/dist/providers/azure/chat.js +1 -0
  134. package/dist/providers/azure/responses.d.ts +2 -0
  135. package/dist/providers/azure/responses.js +1 -0
  136. package/dist/providers/azure.d.ts +598 -0
  137. package/dist/providers/azure.js +115 -0
  138. package/dist/providers/baseten.d.ts +228 -0
  139. package/dist/providers/baseten.js +38 -0
  140. package/dist/providers/cerebras.d.ts +227 -0
  141. package/dist/providers/cerebras.js +40 -0
  142. package/dist/providers/cloudflare-ai-gateway.d.ts +237 -0
  143. package/dist/providers/cloudflare-ai-gateway.js +65 -0
  144. package/dist/providers/cloudflare-workers-ai.d.ts +231 -0
  145. package/dist/providers/cloudflare-workers-ai.js +51 -0
  146. package/dist/providers/deepinfra.d.ts +227 -0
  147. package/dist/providers/deepinfra.js +43 -0
  148. package/dist/providers/deepseek.d.ts +228 -0
  149. package/dist/providers/deepseek.js +41 -0
  150. package/dist/providers/fireworks.d.ts +228 -0
  151. package/dist/providers/fireworks.js +38 -0
  152. package/dist/providers/google-vertex/chat.d.ts +2 -0
  153. package/dist/providers/google-vertex/chat.js +1 -0
  154. package/dist/providers/google-vertex/gemini.d.ts +2 -0
  155. package/dist/providers/google-vertex/gemini.js +1 -0
  156. package/dist/providers/google-vertex/messages.d.ts +2 -0
  157. package/dist/providers/google-vertex/messages.js +1 -0
  158. package/dist/providers/google-vertex/responses.d.ts +2 -0
  159. package/dist/providers/google-vertex/responses.js +1 -0
  160. package/dist/providers/google-vertex-chat.d.ts +132 -0
  161. package/dist/providers/google-vertex-chat.js +55 -0
  162. package/dist/providers/google-vertex-messages.d.ts +306 -0
  163. package/dist/providers/google-vertex-messages.js +75 -0
  164. package/dist/providers/google-vertex-responses.d.ts +197 -0
  165. package/dist/providers/google-vertex-responses.js +56 -0
  166. package/dist/providers/google-vertex-shared.d.ts +22 -0
  167. package/dist/providers/google-vertex-shared.js +72 -0
  168. package/dist/providers/google-vertex.d.ts +119 -0
  169. package/dist/providers/google-vertex.js +98 -0
  170. package/dist/providers/google.d.ts +114 -0
  171. package/dist/providers/google.js +42 -0
  172. package/dist/providers/groq.d.ts +314 -0
  173. package/dist/providers/groq.js +81 -0
  174. package/dist/providers/index.d.ts +31 -0
  175. package/dist/providers/index.js +31 -0
  176. package/dist/providers/meta/chat.d.ts +2 -0
  177. package/dist/providers/meta/chat.js +1 -0
  178. package/dist/providers/meta/messages.d.ts +2 -0
  179. package/dist/providers/meta/messages.js +1 -0
  180. package/dist/providers/meta/responses.d.ts +2 -0
  181. package/dist/providers/meta/responses.js +1 -0
  182. package/dist/providers/meta.d.ts +636 -0
  183. package/dist/providers/meta.js +113 -0
  184. package/dist/providers/minimax/chat.d.ts +4 -0
  185. package/dist/providers/minimax/chat.js +8 -0
  186. package/dist/providers/minimax/messages.d.ts +1 -0
  187. package/dist/providers/minimax/messages.js +1 -0
  188. package/dist/providers/minimax/responses.d.ts +4 -0
  189. package/dist/providers/minimax/responses.js +8 -0
  190. package/dist/providers/minimax.d.ts +598 -0
  191. package/dist/providers/minimax.js +89 -0
  192. package/dist/providers/mistral.d.ts +207 -0
  193. package/dist/providers/mistral.js +28 -0
  194. package/dist/providers/moonshot/chat.d.ts +1 -0
  195. package/dist/providers/moonshot/chat.js +1 -0
  196. package/dist/providers/moonshot/messages.d.ts +4 -0
  197. package/dist/providers/moonshot/messages.js +8 -0
  198. package/dist/providers/moonshot/responses.d.ts +4 -0
  199. package/dist/providers/moonshot/responses.js +8 -0
  200. package/dist/providers/moonshot.d.ts +596 -0
  201. package/dist/providers/moonshot.js +90 -0
  202. package/dist/providers/open-responses-options.d.ts +6 -0
  203. package/dist/providers/open-responses-options.js +1 -0
  204. package/dist/providers/openai/chat.d.ts +2 -0
  205. package/dist/providers/openai/chat.js +1 -0
  206. package/dist/providers/openai/responses.d.ts +2 -0
  207. package/dist/providers/openai/responses.js +1 -0
  208. package/dist/providers/openai-compatible/responses.d.ts +1 -0
  209. package/dist/providers/openai-compatible/responses.js +1 -0
  210. package/dist/providers/openai-compatible-responses.d.ts +195 -0
  211. package/dist/providers/openai-compatible-responses.js +32 -0
  212. package/dist/providers/openai-compatible.d.ts +130 -0
  213. package/dist/providers/openai-compatible.js +33 -0
  214. package/dist/providers/openai-options.d.ts +26 -0
  215. package/dist/providers/openai-options.js +41 -0
  216. package/dist/providers/openai.d.ts +404 -0
  217. package/dist/providers/openai.js +82 -0
  218. package/dist/providers/openrouter.d.ts +563 -0
  219. package/dist/providers/openrouter.js +114 -0
  220. package/dist/providers/togetherai.d.ts +227 -0
  221. package/dist/providers/togetherai.js +40 -0
  222. package/dist/providers/xai.d.ts +163 -0
  223. package/dist/providers/xai.js +88 -0
  224. package/dist/providers/zai/chat.d.ts +1 -0
  225. package/dist/providers/zai/chat.js +1 -0
  226. package/dist/providers/zai-coding-plan/chat.d.ts +1 -0
  227. package/dist/providers/zai-coding-plan/chat.js +1 -0
  228. package/dist/providers/zai-coding-plan/messages.d.ts +4 -0
  229. package/dist/providers/zai-coding-plan/messages.js +8 -0
  230. package/dist/providers/zai-coding-plan/responses.d.ts +4 -0
  231. package/dist/providers/zai-coding-plan/responses.js +8 -0
  232. package/dist/providers/zai-coding-plan.d.ts +577 -0
  233. package/dist/providers/zai-coding-plan.js +63 -0
  234. package/dist/providers/zai.d.ts +149 -0
  235. package/dist/providers/zai.js +53 -0
  236. package/dist/providers.d.ts +1 -0
  237. package/dist/providers.js +1 -0
  238. package/dist/route/auth-options.d.ts +34 -0
  239. package/dist/route/auth-options.js +14 -0
  240. package/dist/route/auth.d.ts +51 -0
  241. package/dist/route/auth.js +87 -0
  242. package/dist/route/client.d.ts +430 -0
  243. package/dist/route/client.js +307 -0
  244. package/dist/route/endpoint.d.ts +28 -0
  245. package/dist/route/endpoint.js +21 -0
  246. package/dist/route/executor.d.ts +27 -0
  247. package/dist/route/executor.js +183 -0
  248. package/dist/route/framing.d.ts +29 -0
  249. package/dist/route/framing.js +14 -0
  250. package/dist/route/index.d.ts +16 -0
  251. package/dist/route/index.js +9 -0
  252. package/dist/route/protocol.d.ts +76 -0
  253. package/dist/route/protocol.js +16 -0
  254. package/dist/route/transport/http.d.ts +34 -0
  255. package/dist/route/transport/http.js +68 -0
  256. package/dist/route/transport/index.d.ts +41 -0
  257. package/dist/route/transport/index.js +4 -0
  258. package/dist/route/transport/websocket-channel.d.ts +57 -0
  259. package/dist/route/transport/websocket-channel.js +1 -0
  260. package/dist/route/transport/websocket.d.ts +56 -0
  261. package/dist/route/transport/websocket.js +370 -0
  262. package/dist/route.d.ts +1 -0
  263. package/dist/route.js +1 -0
  264. package/dist/schema/errors.d.ts +170 -0
  265. package/dist/schema/errors.js +131 -0
  266. package/dist/schema/events.d.ts +8123 -0
  267. package/dist/schema/events.js +550 -0
  268. package/dist/schema/ids.d.ts +17 -0
  269. package/dist/schema/ids.js +10 -0
  270. package/dist/schema/index.d.ts +5 -0
  271. package/dist/schema/index.js +5 -0
  272. package/dist/schema/messages.d.ts +646 -0
  273. package/dist/schema/messages.js +301 -0
  274. package/dist/schema/options.d.ts +159 -0
  275. package/dist/schema/options.js +189 -0
  276. package/dist/testing.d.ts +1693 -0
  277. package/dist/testing.js +129 -0
  278. package/dist/tool-history.d.ts +2 -0
  279. package/dist/tool-history.js +84 -0
  280. package/dist/tool-runtime.d.ts +15 -0
  281. package/dist/tool-runtime.js +62 -0
  282. package/dist/tool.d.ts +136 -0
  283. package/dist/tool.js +66 -0
  284. package/dist/utils/record.d.ts +2 -0
  285. package/dist/utils/record.js +2 -0
  286. package/dist/utils/sanitize.d.ts +1 -0
  287. package/dist/utils/sanitize.js +12 -0
  288. package/package.json +43 -10
@@ -0,0 +1,72 @@
1
+ import { Effect, Redacted } from "effect";
2
+ import { Auth, MissingCredentialError } from "../route/auth.js";
3
+ import { ProviderConfigurationError, ProviderID } from "../schema/index.js";
4
+ const SCOPE = "https://www.googleapis.com/auth/cloud-platform";
5
+ const id = ProviderID.make("google-vertex");
6
+ export const project = (value) => value ??
7
+ process.env.GOOGLE_VERTEX_PROJECT ??
8
+ process.env.GOOGLE_CLOUD_PROJECT ??
9
+ process.env.GCP_PROJECT ??
10
+ process.env.GCLOUD_PROJECT;
11
+ export const location = (value, fallback) => value ??
12
+ process.env.GOOGLE_VERTEX_LOCATION ??
13
+ process.env.GOOGLE_CLOUD_LOCATION ??
14
+ process.env.VERTEX_LOCATION ??
15
+ fallback;
16
+ export const host = (location) => {
17
+ if (location === "global")
18
+ return "aiplatform.googleapis.com";
19
+ // Jurisdictional multi-regions use Regional Endpoint Platform domains.
20
+ if (location === "eu" || location === "us")
21
+ return `aiplatform.${location}.rep.googleapis.com`;
22
+ return `${location}-aiplatform.googleapis.com`;
23
+ };
24
+ export const requireProject = (value) => {
25
+ if (value)
26
+ return value;
27
+ throw new ProviderConfigurationError({
28
+ provider: id,
29
+ message: "Google Vertex requires a project when baseURL is not configured",
30
+ });
31
+ };
32
+ export const apiKey = (input) => {
33
+ if (input.apiKey !== undefined && (input.accessToken !== undefined || input.auth !== undefined))
34
+ throw new ProviderConfigurationError({
35
+ provider: id,
36
+ message: "Google Vertex apiKey cannot be combined with accessToken or auth",
37
+ });
38
+ if (input.accessToken !== undefined || input.auth !== undefined)
39
+ return undefined;
40
+ return input.apiKey ?? process.env.GOOGLE_VERTEX_API_KEY;
41
+ };
42
+ const adc = (project) => {
43
+ let client;
44
+ const loadClient = () => {
45
+ if (client)
46
+ return client;
47
+ client = import("google-auth-library").then(({ GoogleAuth }) => new GoogleAuth({ projectId: project, scopes: [SCOPE] }).getClient());
48
+ return client;
49
+ };
50
+ return Auth.effect(Effect.tryPromise({
51
+ try: async () => {
52
+ const token = await (await loadClient()).getAccessToken();
53
+ if (!token.token)
54
+ throw new Error("Google ADC returned an empty access token");
55
+ return Redacted.make(token.token);
56
+ },
57
+ catch: () => new MissingCredentialError("Google Application Default Credentials"),
58
+ })).bearer();
59
+ };
60
+ export const oauth = (input, project) => {
61
+ if (input.accessToken !== undefined && input.auth !== undefined)
62
+ throw new ProviderConfigurationError({
63
+ provider: id,
64
+ message: "Google Vertex accessToken cannot be combined with auth",
65
+ });
66
+ if (input.auth)
67
+ return input.auth;
68
+ if (input.accessToken !== undefined)
69
+ return Auth.bearer(input.accessToken);
70
+ return adc(project);
71
+ };
72
+ export * as GoogleVertexShared from "./google-vertex-shared.js";
@@ -0,0 +1,119 @@
1
+ import type { ProviderPackage } from "../provider-package.js";
2
+ import { Gemini } from "../protocols/gemini.js";
3
+ import { Route, type RouteDefaultsInput } from "../route/client.js";
4
+ import { type ModelID } from "../schema/index.js";
5
+ import { GoogleVertexShared } from "./google-vertex-shared.js";
6
+ export interface GeminiOptionsInput extends Gemini.OptionsInput {
7
+ readonly labels?: Readonly<Record<string, string>>;
8
+ }
9
+ export type GeminiProviderOptionsInput = GeminiOptionsInput;
10
+ export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
11
+ export type Config = RouteDefaultsInput & GoogleVertexShared.ApiKeyOptions & {
12
+ readonly baseURL?: string;
13
+ readonly location?: string;
14
+ readonly project?: string;
15
+ readonly providerOptions?: GeminiProviderOptionsInput;
16
+ };
17
+ export type Settings = ProviderPackage.Settings & GeminiProviderOptionsInput & ({
18
+ readonly accessToken?: string;
19
+ readonly apiKey?: never;
20
+ } | {
21
+ readonly accessToken?: never;
22
+ readonly apiKey?: string;
23
+ }) & {
24
+ readonly baseURL?: string;
25
+ readonly location?: string;
26
+ readonly project?: string;
27
+ };
28
+ export declare const routes: Route<{
29
+ readonly contents: readonly {
30
+ readonly parts?: readonly ({
31
+ readonly inlineData: {
32
+ readonly mimeType: string;
33
+ readonly data: string;
34
+ };
35
+ } | {
36
+ readonly text: string;
37
+ readonly thought?: boolean | null | undefined;
38
+ readonly thoughtSignature?: string | null | undefined;
39
+ } | {
40
+ readonly functionCall: {
41
+ readonly name: string;
42
+ readonly id?: string | null | undefined;
43
+ readonly args?: unknown;
44
+ };
45
+ readonly thoughtSignature?: string | null | undefined;
46
+ } | {
47
+ readonly functionResponse: {
48
+ readonly name: string;
49
+ readonly response: unknown;
50
+ readonly id?: string | undefined;
51
+ readonly parts?: readonly {
52
+ readonly inlineData: {
53
+ readonly mimeType: string;
54
+ readonly data: string;
55
+ };
56
+ }[] | undefined;
57
+ };
58
+ })[] | null | undefined;
59
+ readonly role?: "model" | "user" | null | undefined;
60
+ }[];
61
+ readonly tools?: readonly {
62
+ readonly functionDeclarations: readonly {
63
+ readonly description: string;
64
+ readonly name: string;
65
+ readonly parameters?: {
66
+ readonly [x: string]: unknown;
67
+ } | undefined;
68
+ }[];
69
+ }[] | undefined;
70
+ readonly serviceTier?: string | undefined;
71
+ readonly toolConfig?: {
72
+ readonly functionCallingConfig: {
73
+ readonly mode: "AUTO" | "NONE" | "ANY";
74
+ readonly allowedFunctionNames?: readonly string[] | undefined;
75
+ };
76
+ } | undefined;
77
+ readonly cachedContent?: string | undefined;
78
+ readonly safetySettings?: readonly {
79
+ readonly category: string;
80
+ readonly threshold: string;
81
+ }[] | undefined;
82
+ readonly labels?: {
83
+ readonly [x: string]: string;
84
+ } | undefined;
85
+ readonly systemInstruction?: {
86
+ readonly parts: readonly {
87
+ readonly text: string;
88
+ }[];
89
+ } | undefined;
90
+ readonly generationConfig?: {
91
+ readonly temperature?: number | undefined;
92
+ readonly topP?: number | undefined;
93
+ readonly topK?: number | undefined;
94
+ readonly frequencyPenalty?: number | undefined;
95
+ readonly presencePenalty?: number | undefined;
96
+ readonly seed?: number | undefined;
97
+ readonly stopSequences?: readonly string[] | undefined;
98
+ readonly thinkingConfig?: {
99
+ readonly thinkingBudget?: number | undefined;
100
+ readonly includeThoughts?: boolean | undefined;
101
+ readonly thinkingLevel?: string | undefined;
102
+ } | undefined;
103
+ readonly maxOutputTokens?: number | undefined;
104
+ } | undefined;
105
+ }, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>[];
106
+ export declare const configure: (input?: Config) => {
107
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
108
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<GeminiOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
109
+ configure: (input?: Config) => /*elided*/ any;
110
+ };
111
+ export declare const provider: {
112
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
113
+ configure: (input?: Config) => {
114
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
115
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<GeminiOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
116
+ configure: /*elided*/ any;
117
+ };
118
+ };
119
+ export declare const model: ProviderPackage.Definition<Settings, GeminiProviderOptionsInput>["model"];
@@ -0,0 +1,98 @@
1
+ import { Effect } from "effect";
2
+ import { Gemini } from "../protocols/gemini.js";
3
+ import { ProviderShared } from "../protocols/shared.js";
4
+ import { Auth } from "../route/auth.js";
5
+ import { Route } from "../route/client.js";
6
+ import { Endpoint } from "../route/endpoint.js";
7
+ import { Framing } from "../route/framing.js";
8
+ import { ProviderConfigurationError, ProviderID } from "../schema/index.js";
9
+ import { GoogleVertexShared } from "./google-vertex-shared.js";
10
+ export const id = ProviderID.make("google-vertex");
11
+ const fromRequest = Effect.fn("GoogleVertex.fromRequest")(function* (request) {
12
+ const body = yield* Gemini.protocol.body.from(request);
13
+ // Vertex's native REST schema rejects `id` on FunctionCall/FunctionResponse parts with HTTP 400,
14
+ // unlike AI Studio, so history minted there cannot be lowered verbatim.
15
+ const contents = body.contents.map((content) => ({
16
+ ...content,
17
+ parts: (content.parts ?? []).map((part) => {
18
+ if ("functionCall" in part)
19
+ return { ...part, functionCall: { ...part.functionCall, id: undefined } };
20
+ if ("functionResponse" in part)
21
+ return { ...part, functionResponse: { ...part.functionResponse, id: undefined } };
22
+ return part;
23
+ }),
24
+ }));
25
+ const value = request.providerOptions?.labels;
26
+ const labels = ProviderShared.isRecord(value)
27
+ ? Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string"))
28
+ : undefined;
29
+ return { ...body, contents, labels };
30
+ });
31
+ const protocol = {
32
+ ...Gemini.protocol,
33
+ body: {
34
+ ...Gemini.protocol.body,
35
+ from: fromRequest,
36
+ },
37
+ };
38
+ const route = Route.make({
39
+ id: "google-vertex-gemini",
40
+ provider: id,
41
+ providerMetadataKey: "vertex",
42
+ protocol,
43
+ endpoint: Endpoint.path(({ request }) => {
44
+ const model = String(request.model.id);
45
+ return `/${model.startsWith("endpoints/") ? model : `models/${model}`}:streamGenerateContent?alt=sse`;
46
+ }),
47
+ auth: Auth.none,
48
+ framing: Framing.sse,
49
+ });
50
+ export const routes = [route];
51
+ const configuredRoute = (input, modelID) => {
52
+ const { accessToken: _accessToken, apiKey: _apiKey, auth: _auth, baseURL, location: inputLocation, project: inputProject, ...rest } = input;
53
+ const apiKey = GoogleVertexShared.apiKey(input);
54
+ const endpointModel = String(modelID).startsWith("endpoints/");
55
+ if (apiKey !== undefined && endpointModel)
56
+ throw new ProviderConfigurationError({
57
+ provider: id,
58
+ message: "Google Vertex tuned models do not support Express Mode API keys",
59
+ });
60
+ const location = GoogleVertexShared.location(inputLocation, "us-central1");
61
+ const project = GoogleVertexShared.project(inputProject);
62
+ const endpoint = baseURL ??
63
+ (apiKey
64
+ ? "https://aiplatform.googleapis.com/v1/publishers/google"
65
+ : `https://${GoogleVertexShared.host(location)}/v1beta1/projects/${GoogleVertexShared.requireProject(project)}/locations/${location}${endpointModel ? "" : "/publishers/google"}`);
66
+ return route.with({
67
+ ...rest,
68
+ endpoint: { baseURL: endpoint },
69
+ auth: apiKey === undefined ? GoogleVertexShared.oauth(input, project) : Auth.header("x-goog-api-key", apiKey),
70
+ });
71
+ };
72
+ export const configure = (input = {}) => {
73
+ return {
74
+ id,
75
+ model: (modelID) => configuredRoute(input, modelID).model({ id: modelID }),
76
+ configure,
77
+ };
78
+ };
79
+ export const provider = {
80
+ id,
81
+ configure,
82
+ };
83
+ export const model = (modelID, { accessToken, apiKey, baseURL, body, headers, location, project, ...providerOptions }) => {
84
+ if (apiKey !== undefined && accessToken !== undefined)
85
+ throw new ProviderConfigurationError({
86
+ provider: id,
87
+ message: "Google Vertex apiKey cannot be combined with accessToken or auth",
88
+ });
89
+ return configure({
90
+ ...(apiKey === undefined ? { accessToken: accessToken } : { apiKey: apiKey }),
91
+ baseURL,
92
+ headers: headers === undefined ? undefined : { ...headers },
93
+ http: body === undefined ? undefined : { body: { ...body } },
94
+ location,
95
+ project,
96
+ providerOptions,
97
+ }).model(modelID);
98
+ };
@@ -0,0 +1,114 @@
1
+ import type { RouteDefaultsInput } from "../route/client.js";
2
+ import type { ProviderAuthOption } from "../route/auth-options.js";
3
+ import type { ProviderPackage } from "../provider-package.js";
4
+ import { type ModelID } from "../schema/index.js";
5
+ import { Gemini } from "../protocols/gemini.js";
6
+ export type { GoogleImageOptions } from "../protocols/google-images.js";
7
+ export type GeminiOptionsInput = Gemini.OptionsInput;
8
+ export type GeminiProviderOptionsInput = Gemini.ProviderOptionsInput;
9
+ export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
10
+ export declare const routes: import("../route/client.js").Route<{
11
+ readonly contents: readonly {
12
+ readonly parts?: readonly ({
13
+ readonly inlineData: {
14
+ readonly mimeType: string;
15
+ readonly data: string;
16
+ };
17
+ } | {
18
+ readonly text: string;
19
+ readonly thought?: boolean | null | undefined;
20
+ readonly thoughtSignature?: string | null | undefined;
21
+ } | {
22
+ readonly functionCall: {
23
+ readonly name: string;
24
+ readonly id?: string | null | undefined;
25
+ readonly args?: unknown;
26
+ };
27
+ readonly thoughtSignature?: string | null | undefined;
28
+ } | {
29
+ readonly functionResponse: {
30
+ readonly name: string;
31
+ readonly response: unknown;
32
+ readonly id?: string | undefined;
33
+ readonly parts?: readonly {
34
+ readonly inlineData: {
35
+ readonly mimeType: string;
36
+ readonly data: string;
37
+ };
38
+ }[] | undefined;
39
+ };
40
+ })[] | null | undefined;
41
+ readonly role?: "model" | "user" | null | undefined;
42
+ }[];
43
+ readonly tools?: readonly {
44
+ readonly functionDeclarations: readonly {
45
+ readonly description: string;
46
+ readonly name: string;
47
+ readonly parameters?: {
48
+ readonly [x: string]: unknown;
49
+ } | undefined;
50
+ }[];
51
+ }[] | undefined;
52
+ readonly serviceTier?: string | undefined;
53
+ readonly toolConfig?: {
54
+ readonly functionCallingConfig: {
55
+ readonly mode: "AUTO" | "NONE" | "ANY";
56
+ readonly allowedFunctionNames?: readonly string[] | undefined;
57
+ };
58
+ } | undefined;
59
+ readonly cachedContent?: string | undefined;
60
+ readonly safetySettings?: readonly {
61
+ readonly category: string;
62
+ readonly threshold: string;
63
+ }[] | undefined;
64
+ readonly labels?: {
65
+ readonly [x: string]: string;
66
+ } | undefined;
67
+ readonly systemInstruction?: {
68
+ readonly parts: readonly {
69
+ readonly text: string;
70
+ }[];
71
+ } | undefined;
72
+ readonly generationConfig?: {
73
+ readonly temperature?: number | undefined;
74
+ readonly topP?: number | undefined;
75
+ readonly topK?: number | undefined;
76
+ readonly frequencyPenalty?: number | undefined;
77
+ readonly presencePenalty?: number | undefined;
78
+ readonly seed?: number | undefined;
79
+ readonly stopSequences?: readonly string[] | undefined;
80
+ readonly thinkingConfig?: {
81
+ readonly thinkingBudget?: number | undefined;
82
+ readonly includeThoughts?: boolean | undefined;
83
+ readonly thinkingLevel?: string | undefined;
84
+ } | undefined;
85
+ readonly maxOutputTokens?: number | undefined;
86
+ } | undefined;
87
+ }, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>[];
88
+ export type Config = RouteDefaultsInput & ProviderAuthOption<"optional"> & {
89
+ readonly baseURL?: string;
90
+ readonly providerOptions?: Gemini.ProviderOptionsInput;
91
+ };
92
+ export type Settings = ProviderPackage.Settings & Gemini.ProviderOptionsInput & {
93
+ readonly apiKey?: string;
94
+ readonly baseURL?: string;
95
+ };
96
+ export declare const configure: (input?: Config) => {
97
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
98
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<Gemini.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
99
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/google-images.js").GoogleImageOptions>;
100
+ configure: (input?: Config) => /*elided*/ any;
101
+ };
102
+ export declare const provider: {
103
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
104
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<Gemini.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
105
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/google-images.js").GoogleImageOptions>;
106
+ configure: (input?: Config) => {
107
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
108
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<Gemini.OptionsInput, import("../route/client.js").CompactionOperations | undefined>;
109
+ image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/google-images.js").GoogleImageOptions>;
110
+ configure: /*elided*/ any;
111
+ };
112
+ };
113
+ export declare const model: ProviderPackage.Definition<Settings, Gemini.ProviderOptionsInput>["model"];
114
+ export declare const image: (modelID: string | ModelID) => import("../image.js").ImageModel<import("../protocols/google-images.js").GoogleImageOptions>;
@@ -0,0 +1,42 @@
1
+ import { Auth } from "../route/auth.js";
2
+ import { HttpOptions, ProviderID, mergeHttpOptions } from "../schema/index.js";
3
+ import { Gemini } from "../protocols/gemini.js";
4
+ import { GoogleImages } from "../protocols/google-images.js";
5
+ export const id = ProviderID.make("google");
6
+ export const routes = [Gemini.route];
7
+ const auth = (options) => {
8
+ if ("auth" in options && options.auth)
9
+ return options.auth;
10
+ return Auth.optional("apiKey" in options ? options.apiKey : undefined, "apiKey")
11
+ .orElse(Auth.config("GOOGLE_GENERATIVE_AI_API_KEY"))
12
+ .pipe(Auth.header("x-goog-api-key"));
13
+ };
14
+ const configuredRoute = (input) => {
15
+ const { apiKey: _, auth: _auth, baseURL, ...rest } = input;
16
+ return Gemini.route.with({ ...rest, endpoint: { baseURL }, auth: auth(input) });
17
+ };
18
+ export const configure = (input = {}) => {
19
+ const route = configuredRoute(input);
20
+ const image = (modelID) => GoogleImages.model({
21
+ id: modelID,
22
+ auth: auth(input),
23
+ baseURL: input.baseURL,
24
+ headers: input.headers,
25
+ http: mergeHttpOptions(input.http === undefined ? undefined : HttpOptions.make(input.http)),
26
+ });
27
+ return {
28
+ id,
29
+ model: (modelID) => route.model({ id: modelID }),
30
+ image,
31
+ configure,
32
+ };
33
+ };
34
+ export const provider = configure();
35
+ export const model = (modelID, { apiKey, baseURL, body, headers, ...providerOptions }) => configure({
36
+ apiKey,
37
+ baseURL,
38
+ headers: headers === undefined ? undefined : { ...headers },
39
+ http: body === undefined ? undefined : { body: { ...body } },
40
+ providerOptions,
41
+ }).model(modelID);
42
+ export const image = provider.image;