@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.
Files changed (194) hide show
  1. package/README.md +392 -0
  2. package/dist/cache-policy.d.ts +2 -0
  3. package/dist/cache-policy.js +121 -0
  4. package/dist/image-client.d.ts +19 -0
  5. package/dist/image-client.js +19 -0
  6. package/dist/image.d.ts +110 -0
  7. package/dist/image.js +102 -0
  8. package/dist/index.d.ts +18 -0
  9. package/dist/index.js +12 -0
  10. package/dist/llm.d.ts +230 -0
  11. package/dist/llm.js +77 -0
  12. package/dist/protocols/anthropic-messages.d.ts +633 -0
  13. package/dist/protocols/anthropic-messages.js +860 -0
  14. package/dist/protocols/bedrock-converse.d.ts +533 -0
  15. package/dist/protocols/bedrock-converse.js +584 -0
  16. package/dist/protocols/bedrock-event-stream.d.ts +9 -0
  17. package/dist/protocols/bedrock-event-stream.js +73 -0
  18. package/dist/protocols/gemini.d.ts +300 -0
  19. package/dist/protocols/gemini.js +512 -0
  20. package/dist/protocols/google-images.d.ts +30 -0
  21. package/dist/protocols/google-images.js +191 -0
  22. package/dist/protocols/index.d.ts +10 -0
  23. package/dist/protocols/index.js +10 -0
  24. package/dist/protocols/open-responses-channel.d.ts +26 -0
  25. package/dist/protocols/open-responses-channel.js +120 -0
  26. package/dist/protocols/open-responses.d.ts +951 -0
  27. package/dist/protocols/open-responses.js +873 -0
  28. package/dist/protocols/openai-chat.d.ts +795 -0
  29. package/dist/protocols/openai-chat.js +718 -0
  30. package/dist/protocols/openai-compatible-chat.d.ts +107 -0
  31. package/dist/protocols/openai-compatible-chat.js +20 -0
  32. package/dist/protocols/openai-compatible-responses.d.ts +96 -0
  33. package/dist/protocols/openai-compatible-responses.js +17 -0
  34. package/dist/protocols/openai-images.d.ts +32 -0
  35. package/dist/protocols/openai-images.js +188 -0
  36. package/dist/protocols/openai-responses-channel.d.ts +12 -0
  37. package/dist/protocols/openai-responses-channel.js +142 -0
  38. package/dist/protocols/openai-responses.d.ts +596 -0
  39. package/dist/protocols/openai-responses.js +208 -0
  40. package/dist/protocols/shared.d.ts +194 -0
  41. package/dist/protocols/shared.js +238 -0
  42. package/dist/protocols/utils/bedrock-auth.d.ts +21 -0
  43. package/dist/protocols/utils/bedrock-auth.js +43 -0
  44. package/dist/protocols/utils/bedrock-cache.d.ts +15 -0
  45. package/dist/protocols/utils/bedrock-cache.js +29 -0
  46. package/dist/protocols/utils/bedrock-media.d.ts +49 -0
  47. package/dist/protocols/utils/bedrock-media.js +70 -0
  48. package/dist/protocols/utils/cache.d.ts +6 -0
  49. package/dist/protocols/utils/cache.js +8 -0
  50. package/dist/protocols/utils/gemini-tool-schema.d.ts +2 -0
  51. package/dist/protocols/utils/gemini-tool-schema.js +103 -0
  52. package/dist/protocols/utils/image-input.d.ts +21 -0
  53. package/dist/protocols/utils/image-input.js +22 -0
  54. package/dist/protocols/utils/lifecycle.d.ts +20 -0
  55. package/dist/protocols/utils/lifecycle.js +68 -0
  56. package/dist/protocols/utils/open-responses-options.d.ts +21 -0
  57. package/dist/protocols/utils/open-responses-options.js +41 -0
  58. package/dist/protocols/utils/openai-image.d.ts +5 -0
  59. package/dist/protocols/utils/openai-image.js +18 -0
  60. package/dist/protocols/utils/openai-options.d.ts +14 -0
  61. package/dist/protocols/utils/openai-options.js +14 -0
  62. package/dist/protocols/utils/tool-schema.d.ts +8 -0
  63. package/dist/protocols/utils/tool-schema.js +81 -0
  64. package/dist/protocols/utils/tool-stream.d.ts +639 -0
  65. package/dist/protocols/utils/tool-stream.js +141 -0
  66. package/dist/protocols/xai-images.d.ts +26 -0
  67. package/dist/protocols/xai-images.js +111 -0
  68. package/dist/protocols/zai-images.d.ts +22 -0
  69. package/dist/protocols/zai-images.js +84 -0
  70. package/dist/protocols.d.ts +1 -0
  71. package/dist/protocols.js +1 -0
  72. package/dist/provider-error.d.ts +14 -0
  73. package/dist/provider-error.js +130 -0
  74. package/dist/provider-package.d.ts +15 -0
  75. package/dist/provider-package.js +1 -0
  76. package/dist/provider.d.ts +23 -0
  77. package/dist/provider.js +2 -0
  78. package/dist/providers/amazon-bedrock/mantle/chat.d.ts +2 -0
  79. package/dist/providers/amazon-bedrock/mantle/chat.js +1 -0
  80. package/dist/providers/amazon-bedrock/mantle/responses.d.ts +2 -0
  81. package/dist/providers/amazon-bedrock/mantle/responses.js +1 -0
  82. package/dist/providers/amazon-bedrock/mantle.d.ts +2 -0
  83. package/dist/providers/amazon-bedrock/mantle.js +1 -0
  84. package/dist/providers/amazon-bedrock-mantle.d.ts +247 -0
  85. package/dist/providers/amazon-bedrock-mantle.js +68 -0
  86. package/dist/providers/amazon-bedrock.d.ts +172 -0
  87. package/dist/providers/amazon-bedrock.js +41 -0
  88. package/dist/providers/anthropic-compatible.d.ts +218 -0
  89. package/dist/providers/anthropic-compatible.js +45 -0
  90. package/dist/providers/anthropic.d.ts +216 -0
  91. package/dist/providers/anthropic.js +40 -0
  92. package/dist/providers/azure/chat.d.ts +2 -0
  93. package/dist/providers/azure/chat.js +1 -0
  94. package/dist/providers/azure/responses.d.ts +2 -0
  95. package/dist/providers/azure/responses.js +1 -0
  96. package/dist/providers/azure.d.ts +248 -0
  97. package/dist/providers/azure.js +90 -0
  98. package/dist/providers/cloudflare.d.ts +338 -0
  99. package/dist/providers/cloudflare.js +87 -0
  100. package/dist/providers/google-vertex/chat.d.ts +2 -0
  101. package/dist/providers/google-vertex/chat.js +1 -0
  102. package/dist/providers/google-vertex/gemini.d.ts +2 -0
  103. package/dist/providers/google-vertex/gemini.js +1 -0
  104. package/dist/providers/google-vertex/messages.d.ts +2 -0
  105. package/dist/providers/google-vertex/messages.js +1 -0
  106. package/dist/providers/google-vertex/responses.d.ts +2 -0
  107. package/dist/providers/google-vertex/responses.js +1 -0
  108. package/dist/providers/google-vertex-chat.d.ts +131 -0
  109. package/dist/providers/google-vertex-chat.js +50 -0
  110. package/dist/providers/google-vertex-messages.d.ts +215 -0
  111. package/dist/providers/google-vertex-messages.js +75 -0
  112. package/dist/providers/google-vertex-responses.d.ts +122 -0
  113. package/dist/providers/google-vertex-responses.js +51 -0
  114. package/dist/providers/google-vertex-shared.d.ts +22 -0
  115. package/dist/providers/google-vertex-shared.js +61 -0
  116. package/dist/providers/google-vertex.d.ts +115 -0
  117. package/dist/providers/google-vertex.js +64 -0
  118. package/dist/providers/google.d.ts +112 -0
  119. package/dist/providers/google.js +43 -0
  120. package/dist/providers/index.d.ts +18 -0
  121. package/dist/providers/index.js +18 -0
  122. package/dist/providers/open-responses-options.d.ts +16 -0
  123. package/dist/providers/open-responses-options.js +1 -0
  124. package/dist/providers/openai/chat.d.ts +2 -0
  125. package/dist/providers/openai/chat.js +1 -0
  126. package/dist/providers/openai/responses.d.ts +2 -0
  127. package/dist/providers/openai/responses.js +1 -0
  128. package/dist/providers/openai-compatible/responses.d.ts +1 -0
  129. package/dist/providers/openai-compatible/responses.js +1 -0
  130. package/dist/providers/openai-compatible-profile.d.ts +43 -0
  131. package/dist/providers/openai-compatible-profile.js +12 -0
  132. package/dist/providers/openai-compatible-responses.d.ts +120 -0
  133. package/dist/providers/openai-compatible-responses.js +33 -0
  134. package/dist/providers/openai-compatible.d.ts +167 -0
  135. package/dist/providers/openai-compatible.js +55 -0
  136. package/dist/providers/openai-options.d.ts +21 -0
  137. package/dist/providers/openai-options.js +41 -0
  138. package/dist/providers/openai.d.ts +264 -0
  139. package/dist/providers/openai.js +83 -0
  140. package/dist/providers/openrouter.d.ts +537 -0
  141. package/dist/providers/openrouter.js +117 -0
  142. package/dist/providers/xai.d.ts +249 -0
  143. package/dist/providers/xai.js +79 -0
  144. package/dist/providers/zai.d.ts +24 -0
  145. package/dist/providers/zai.js +21 -0
  146. package/dist/providers.d.ts +1 -0
  147. package/dist/providers.js +1 -0
  148. package/dist/route/auth-options.d.ts +34 -0
  149. package/dist/route/auth-options.js +14 -0
  150. package/dist/route/auth.d.ts +51 -0
  151. package/dist/route/auth.js +89 -0
  152. package/dist/route/client.d.ts +348 -0
  153. package/dist/route/client.js +214 -0
  154. package/dist/route/endpoint.d.ts +28 -0
  155. package/dist/route/endpoint.js +21 -0
  156. package/dist/route/executor.d.ts +23 -0
  157. package/dist/route/executor.js +227 -0
  158. package/dist/route/framing.d.ts +23 -0
  159. package/dist/route/framing.js +4 -0
  160. package/dist/route/index.d.ts +16 -0
  161. package/dist/route/index.js +9 -0
  162. package/dist/route/protocol.d.ts +77 -0
  163. package/dist/route/protocol.js +17 -0
  164. package/dist/route/transport/http.d.ts +34 -0
  165. package/dist/route/transport/http.js +63 -0
  166. package/dist/route/transport/index.d.ts +39 -0
  167. package/dist/route/transport/index.js +4 -0
  168. package/dist/route/transport/websocket-channel.d.ts +56 -0
  169. package/dist/route/transport/websocket-channel.js +1 -0
  170. package/dist/route/transport/websocket.d.ts +55 -0
  171. package/dist/route/transport/websocket.js +326 -0
  172. package/dist/route.d.ts +1 -0
  173. package/dist/route.js +1 -0
  174. package/dist/schema/errors.d.ts +159 -0
  175. package/dist/schema/errors.js +155 -0
  176. package/dist/schema/events.d.ts +4587 -0
  177. package/dist/schema/events.js +492 -0
  178. package/dist/schema/ids.d.ts +30 -0
  179. package/dist/schema/ids.js +19 -0
  180. package/dist/schema/index.d.ts +5 -0
  181. package/dist/schema/index.js +5 -0
  182. package/dist/schema/messages.d.ts +402 -0
  183. package/dist/schema/messages.js +244 -0
  184. package/dist/schema/options.d.ts +159 -0
  185. package/dist/schema/options.js +202 -0
  186. package/dist/testing.d.ts +1493 -0
  187. package/dist/testing.js +88 -0
  188. package/dist/tool-runtime.d.ts +15 -0
  189. package/dist/tool-runtime.js +54 -0
  190. package/dist/tool.d.ts +135 -0
  191. package/dist/tool.js +66 -0
  192. package/dist/utils/record.d.ts +2 -0
  193. package/dist/utils/record.js +2 -0
  194. package/package.json +47 -0
@@ -0,0 +1,87 @@
1
+ import * as OpenAICompatibleChat from "../protocols/openai-compatible-chat.js";
2
+ import { Auth } from "../route/auth.js";
3
+ import { AuthOptions } from "../route/auth-options.js";
4
+ import { ProviderID } from "../schema/index.js";
5
+ export const aiGatewayID = ProviderID.make("cloudflare-ai-gateway");
6
+ export const workersAIID = ProviderID.make("cloudflare-workers-ai");
7
+ export const aiGatewayAuthEnvVars = ["CLOUDFLARE_API_TOKEN", "CF_AIG_TOKEN"];
8
+ export const workersAIAuthEnvVars = ["CLOUDFLARE_API_KEY", "CLOUDFLARE_WORKERS_AI_TOKEN"];
9
+ export const aiGatewayBaseURL = (input) => {
10
+ if (input.baseURL)
11
+ return input.baseURL;
12
+ if (!input.accountId)
13
+ throw new Error("CloudflareAIGateway.configure requires accountId unless baseURL is supplied");
14
+ return `https://gateway.ai.cloudflare.com/v1/${encodeURIComponent(input.accountId)}/${encodeURIComponent(input.gatewayId?.trim() || "default")}/compat`;
15
+ };
16
+ const aiGatewayAuth = (input) => {
17
+ if ("auth" in input && input.auth)
18
+ return input.auth;
19
+ const gateway = Auth.optional(input.gatewayApiKey, "gatewayApiKey")
20
+ .orElse(Auth.config("CLOUDFLARE_API_TOKEN"))
21
+ .orElse(Auth.config("CF_AIG_TOKEN"))
22
+ .pipe(Auth.bearerHeader("cf-aig-authorization"));
23
+ if (!("apiKey" in input) || input.apiKey === undefined)
24
+ return gateway;
25
+ if (input.gatewayApiKey === undefined)
26
+ return Auth.bearer(input.apiKey);
27
+ return Auth.bearerHeader("cf-aig-authorization", input.gatewayApiKey).andThen(Auth.bearer(input.apiKey));
28
+ };
29
+ export const workersAIBaseURL = (input) => {
30
+ if (input.baseURL)
31
+ return input.baseURL;
32
+ if (!input.accountId)
33
+ throw new Error("CloudflareWorkersAI.configure requires accountId unless baseURL is supplied");
34
+ return `https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(input.accountId)}/ai/v1`;
35
+ };
36
+ const workersAIAuth = (input) => {
37
+ return AuthOptions.bearer(input, workersAIAuthEnvVars);
38
+ };
39
+ export const aiGatewayRoute = OpenAICompatibleChat.route.with({
40
+ id: "cloudflare-ai-gateway",
41
+ provider: aiGatewayID,
42
+ });
43
+ export const workersAIRoute = OpenAICompatibleChat.route.with({
44
+ id: "cloudflare-workers-ai",
45
+ provider: workersAIID,
46
+ });
47
+ export const routes = [aiGatewayRoute, workersAIRoute];
48
+ const aiGatewayDefaults = (options) => {
49
+ const { accountId: _accountId, gatewayId: _gatewayId, apiKey: _apiKey, gatewayApiKey: _gatewayApiKey, baseURL: _baseURL, auth: _auth, ...rest } = options;
50
+ return rest;
51
+ };
52
+ const workersAIDefaults = (options) => {
53
+ const { accountId: _accountId, apiKey: _apiKey, auth: _auth, baseURL: _baseURL, ...rest } = options;
54
+ return rest;
55
+ };
56
+ const configureAIGateway = (options) => {
57
+ const route = aiGatewayRoute.with({
58
+ ...aiGatewayDefaults(options),
59
+ endpoint: { baseURL: aiGatewayBaseURL(options) },
60
+ auth: aiGatewayAuth(options),
61
+ });
62
+ return {
63
+ id: aiGatewayID,
64
+ model: (modelID) => route.model({ id: modelID }),
65
+ configure: configureAIGateway,
66
+ };
67
+ };
68
+ const configureWorkersAI = (options) => {
69
+ const route = workersAIRoute.with({
70
+ ...workersAIDefaults(options),
71
+ endpoint: { baseURL: workersAIBaseURL(options) },
72
+ auth: workersAIAuth(options),
73
+ });
74
+ return {
75
+ id: workersAIID,
76
+ model: (modelID) => route.model({ id: modelID }),
77
+ configure: configureWorkersAI,
78
+ };
79
+ };
80
+ export const CloudflareAIGateway = {
81
+ id: aiGatewayID,
82
+ configure: configureAIGateway,
83
+ };
84
+ export const CloudflareWorkersAI = {
85
+ id: workersAIID,
86
+ configure: configureWorkersAI,
87
+ };
@@ -0,0 +1,2 @@
1
+ export { model } from "../google-vertex-chat.js";
2
+ export type { Settings } from "../google-vertex-chat.js";
@@ -0,0 +1 @@
1
+ export { model } from "../google-vertex-chat.js";
@@ -0,0 +1,2 @@
1
+ export { model } from "../google-vertex.js";
2
+ export type { Settings } from "../google-vertex.js";
@@ -0,0 +1 @@
1
+ export { model } from "../google-vertex.js";
@@ -0,0 +1,2 @@
1
+ export { model } from "../google-vertex-messages.js";
2
+ export type { Settings } from "../google-vertex-messages.js";
@@ -0,0 +1 @@
1
+ export { model } from "../google-vertex-messages.js";
@@ -0,0 +1,2 @@
1
+ export { model } from "../google-vertex-responses.js";
2
+ export type { Settings } from "../google-vertex-responses.js";
@@ -0,0 +1 @@
1
+ export { model } from "../google-vertex-responses.js";
@@ -0,0 +1,131 @@
1
+ import type { ProviderPackage } from "../provider-package.js";
2
+ import type { RouteDefaultsInput } from "../route/client.js";
3
+ import { type ModelID } from "../schema/index.js";
4
+ import { GoogleVertexShared } from "./google-vertex-shared.js";
5
+ import type { OpenAIProviderOptionsInput } from "./openai-options.js";
6
+ export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
7
+ export type Config = RouteDefaultsInput & GoogleVertexShared.OAuthOptions & {
8
+ readonly baseURL?: string;
9
+ readonly location?: string;
10
+ readonly project?: string;
11
+ readonly providerOptions?: OpenAIProviderOptionsInput;
12
+ };
13
+ export interface Settings extends ProviderPackage.Settings {
14
+ readonly accessToken?: string;
15
+ readonly apiKey?: never;
16
+ readonly baseURL?: string;
17
+ readonly location?: string;
18
+ readonly project?: string;
19
+ readonly providerOptions?: OpenAIProviderOptionsInput;
20
+ }
21
+ export declare const routes: import("../route/client.js").Route<{
22
+ readonly model: string;
23
+ readonly messages: readonly ({
24
+ readonly role: "system";
25
+ readonly content: string | readonly ({
26
+ readonly type: "text";
27
+ readonly text: string;
28
+ readonly cache_control?: {
29
+ readonly type: "ephemeral";
30
+ readonly ttl?: string | undefined;
31
+ } | undefined;
32
+ } | {
33
+ readonly type: "image_url";
34
+ readonly image_url: {
35
+ readonly url: string;
36
+ };
37
+ })[];
38
+ } | {
39
+ readonly role: "user";
40
+ readonly content: string | readonly ({
41
+ readonly type: "text";
42
+ readonly text: string;
43
+ readonly cache_control?: {
44
+ readonly type: "ephemeral";
45
+ readonly ttl?: string | undefined;
46
+ } | undefined;
47
+ } | {
48
+ readonly type: "image_url";
49
+ readonly image_url: {
50
+ readonly url: string;
51
+ };
52
+ })[];
53
+ } | {
54
+ readonly [x: string]: unknown;
55
+ readonly content: string | null;
56
+ readonly role: "assistant";
57
+ readonly reasoning?: string | undefined;
58
+ readonly reasoning_content?: string | undefined;
59
+ readonly reasoning_text?: string | undefined;
60
+ readonly cache_control?: {
61
+ readonly type: "ephemeral";
62
+ readonly ttl?: string | undefined;
63
+ } | undefined;
64
+ readonly tool_calls?: readonly {
65
+ readonly id: string;
66
+ readonly type: "function";
67
+ readonly function: {
68
+ readonly name: string;
69
+ readonly arguments: string;
70
+ };
71
+ }[] | undefined;
72
+ readonly reasoning_details?: unknown;
73
+ } | {
74
+ readonly content: string;
75
+ readonly role: "tool";
76
+ readonly tool_call_id: string;
77
+ readonly cache_control?: {
78
+ readonly type: "ephemeral";
79
+ readonly ttl?: string | undefined;
80
+ } | undefined;
81
+ })[];
82
+ readonly stream: true;
83
+ readonly stop?: readonly string[] | undefined;
84
+ readonly max_completion_tokens?: number | undefined;
85
+ readonly max_tokens?: number | undefined;
86
+ readonly tools?: readonly {
87
+ readonly function: {
88
+ readonly name: string;
89
+ readonly description: string;
90
+ readonly parameters: {
91
+ readonly [x: string]: unknown;
92
+ };
93
+ };
94
+ readonly type: "function";
95
+ readonly cache_control?: {
96
+ readonly type: "ephemeral";
97
+ readonly ttl?: string | undefined;
98
+ } | undefined;
99
+ }[] | undefined;
100
+ readonly temperature?: number | undefined;
101
+ readonly seed?: number | undefined;
102
+ readonly tool_choice?: "required" | "none" | "auto" | {
103
+ readonly type: "function";
104
+ readonly function: {
105
+ readonly name: string;
106
+ };
107
+ } | undefined;
108
+ readonly top_p?: number | undefined;
109
+ readonly store?: boolean | undefined;
110
+ readonly stream_options?: {
111
+ readonly include_usage: boolean;
112
+ } | undefined;
113
+ readonly prompt_cache_key?: string | undefined;
114
+ readonly reasoning_effort?: string | undefined;
115
+ readonly frequency_penalty?: number | undefined;
116
+ readonly presence_penalty?: number | undefined;
117
+ }, import("../route/transport/http.js").HttpPrepared<string>>[];
118
+ export declare const configure: (input?: Config) => {
119
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
120
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
121
+ configure: (input?: Config) => /*elided*/ any;
122
+ };
123
+ export declare const provider: {
124
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
125
+ configure: (input?: Config) => {
126
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
127
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<OpenAIProviderOptionsInput>;
128
+ configure: /*elided*/ any;
129
+ };
130
+ };
131
+ export declare const model: ProviderPackage.Definition<Settings, OpenAIProviderOptionsInput>["model"];
@@ -0,0 +1,50 @@
1
+ import { OpenAICompatibleChat } from "../protocols/openai-compatible-chat.js";
2
+ import { ProviderID } from "../schema/index.js";
3
+ import { GoogleVertexShared } from "./google-vertex-shared.js";
4
+ export const id = ProviderID.make("google-vertex");
5
+ const route = OpenAICompatibleChat.route.with({
6
+ id: "google-vertex-chat",
7
+ provider: id,
8
+ });
9
+ export const routes = [route];
10
+ const configuredRoute = (input) => {
11
+ if ("apiKey" in input && input.apiKey !== undefined)
12
+ throw new Error("Google Vertex Chat does not support API keys");
13
+ const { accessToken: _accessToken, auth: _auth, baseURL, location: inputLocation, project: inputProject, ...rest } = input;
14
+ const location = GoogleVertexShared.location(inputLocation, "global");
15
+ const project = GoogleVertexShared.project(inputProject);
16
+ return route.with({
17
+ ...rest,
18
+ endpoint: {
19
+ baseURL: baseURL ??
20
+ `https://aiplatform.googleapis.com/v1/projects/${GoogleVertexShared.requireProject(project)}/locations/${location}/endpoints/openapi`,
21
+ },
22
+ auth: GoogleVertexShared.oauth(input, project),
23
+ });
24
+ };
25
+ export const configure = (input = {}) => {
26
+ const route = configuredRoute(input);
27
+ return {
28
+ id,
29
+ model: (modelID) => route.model({ id: modelID }),
30
+ configure,
31
+ };
32
+ };
33
+ export const provider = {
34
+ id,
35
+ configure,
36
+ };
37
+ export const model = (modelID, settings) => {
38
+ if (settings.apiKey !== undefined)
39
+ throw new Error("Google Vertex Chat does not support API keys");
40
+ return configure({
41
+ accessToken: settings.accessToken,
42
+ baseURL: settings.baseURL,
43
+ headers: settings.headers === undefined ? undefined : { ...settings.headers },
44
+ http: settings.body === undefined ? undefined : { body: { ...settings.body } },
45
+ limits: settings.limits,
46
+ location: settings.location,
47
+ project: settings.project,
48
+ providerOptions: settings.providerOptions,
49
+ }).model(modelID);
50
+ };
@@ -0,0 +1,215 @@
1
+ import type { ProviderPackage } from "../provider-package.js";
2
+ import { AnthropicMessages } from "../protocols/anthropic-messages.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 type AnthropicOptionsInput = AnthropicMessages.OptionsInput;
7
+ export type AnthropicProviderOptionsInput = AnthropicMessages.ProviderOptionsInput;
8
+ export type AnthropicThinkingInput = AnthropicMessages.ThinkingInput;
9
+ export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
10
+ export type Config = RouteDefaultsInput & GoogleVertexShared.OAuthOptions & {
11
+ readonly baseURL?: string;
12
+ readonly location?: string;
13
+ readonly project?: string;
14
+ readonly providerOptions?: AnthropicMessages.ProviderOptionsInput;
15
+ };
16
+ export interface Settings extends ProviderPackage.Settings {
17
+ readonly accessToken?: string;
18
+ readonly apiKey?: never;
19
+ readonly baseURL?: string;
20
+ readonly location?: string;
21
+ readonly project?: string;
22
+ readonly providerOptions?: AnthropicMessages.ProviderOptionsInput;
23
+ }
24
+ export declare const routes: Route<{
25
+ anthropic_version: "vertex-2023-10-16";
26
+ system?: readonly {
27
+ readonly type: "text";
28
+ readonly text: string;
29
+ readonly cache_control?: {
30
+ readonly type: "ephemeral";
31
+ readonly ttl?: "1h" | "5m" | undefined;
32
+ } | undefined;
33
+ }[] | undefined;
34
+ max_tokens: number;
35
+ tools?: readonly {
36
+ readonly description: string;
37
+ readonly name: string;
38
+ readonly input_schema: {
39
+ readonly [x: string]: unknown;
40
+ };
41
+ readonly cache_control?: {
42
+ readonly type: "ephemeral";
43
+ readonly ttl?: "1h" | "5m" | undefined;
44
+ } | undefined;
45
+ }[] | undefined;
46
+ messages: readonly ({
47
+ readonly role: "user";
48
+ readonly content: readonly ({
49
+ readonly type: "text";
50
+ readonly text: string;
51
+ readonly cache_control?: {
52
+ readonly type: "ephemeral";
53
+ readonly ttl?: "1h" | "5m" | undefined;
54
+ } | undefined;
55
+ } | {
56
+ readonly type: "image";
57
+ readonly source: {
58
+ readonly type: "base64";
59
+ readonly media_type: string;
60
+ readonly data: string;
61
+ };
62
+ readonly cache_control?: {
63
+ readonly type: "ephemeral";
64
+ readonly ttl?: "1h" | "5m" | undefined;
65
+ } | undefined;
66
+ } | {
67
+ readonly type: "document";
68
+ readonly source: {
69
+ readonly type: "base64";
70
+ readonly media_type: "application/pdf";
71
+ readonly data: string;
72
+ };
73
+ readonly cache_control?: {
74
+ readonly type: "ephemeral";
75
+ readonly ttl?: "1h" | "5m" | undefined;
76
+ } | undefined;
77
+ } | {
78
+ readonly type: "tool_result";
79
+ readonly content: string | readonly ({
80
+ readonly type: "text";
81
+ readonly text: string;
82
+ readonly cache_control?: {
83
+ readonly type: "ephemeral";
84
+ readonly ttl?: "1h" | "5m" | undefined;
85
+ } | undefined;
86
+ } | {
87
+ readonly type: "image";
88
+ readonly source: {
89
+ readonly type: "base64";
90
+ readonly media_type: string;
91
+ readonly data: string;
92
+ };
93
+ readonly cache_control?: {
94
+ readonly type: "ephemeral";
95
+ readonly ttl?: "1h" | "5m" | undefined;
96
+ } | undefined;
97
+ } | {
98
+ readonly type: "document";
99
+ readonly source: {
100
+ readonly type: "base64";
101
+ readonly media_type: "application/pdf";
102
+ readonly data: string;
103
+ };
104
+ readonly cache_control?: {
105
+ readonly type: "ephemeral";
106
+ readonly ttl?: "1h" | "5m" | undefined;
107
+ } | undefined;
108
+ })[];
109
+ readonly tool_use_id: string;
110
+ readonly cache_control?: {
111
+ readonly type: "ephemeral";
112
+ readonly ttl?: "1h" | "5m" | undefined;
113
+ } | undefined;
114
+ readonly is_error?: boolean | undefined;
115
+ })[];
116
+ } | {
117
+ readonly role: "assistant";
118
+ readonly content: readonly ({
119
+ readonly type: "text";
120
+ readonly text: string;
121
+ readonly cache_control?: {
122
+ readonly type: "ephemeral";
123
+ readonly ttl?: "1h" | "5m" | undefined;
124
+ } | undefined;
125
+ } | {
126
+ readonly id: string;
127
+ readonly type: "tool_use";
128
+ readonly name: string;
129
+ readonly input: unknown;
130
+ readonly cache_control?: {
131
+ readonly type: "ephemeral";
132
+ readonly ttl?: "1h" | "5m" | undefined;
133
+ } | undefined;
134
+ } | {
135
+ readonly id: string;
136
+ readonly type: "server_tool_use";
137
+ readonly name: string;
138
+ readonly input: unknown;
139
+ readonly cache_control?: {
140
+ readonly type: "ephemeral";
141
+ readonly ttl?: "1h" | "5m" | undefined;
142
+ } | undefined;
143
+ } | {
144
+ readonly type: "web_search_tool_result" | "code_execution_tool_result" | "web_fetch_tool_result";
145
+ readonly content: unknown;
146
+ readonly tool_use_id: string;
147
+ readonly cache_control?: {
148
+ readonly type: "ephemeral";
149
+ readonly ttl?: "1h" | "5m" | undefined;
150
+ } | undefined;
151
+ } | {
152
+ readonly type: "thinking";
153
+ readonly thinking: string;
154
+ readonly cache_control?: {
155
+ readonly type: "ephemeral";
156
+ readonly ttl?: "1h" | "5m" | undefined;
157
+ } | undefined;
158
+ readonly signature?: string | undefined;
159
+ } | {
160
+ readonly data: string;
161
+ readonly type: "redacted_thinking";
162
+ readonly cache_control?: {
163
+ readonly type: "ephemeral";
164
+ readonly ttl?: "1h" | "5m" | undefined;
165
+ } | undefined;
166
+ })[];
167
+ } | {
168
+ readonly role: "system";
169
+ readonly content: readonly {
170
+ readonly type: "text";
171
+ readonly text: string;
172
+ readonly cache_control?: {
173
+ readonly type: "ephemeral";
174
+ readonly ttl?: "1h" | "5m" | undefined;
175
+ } | undefined;
176
+ }[];
177
+ })[];
178
+ temperature?: number | undefined;
179
+ stream: true;
180
+ thinking?: {
181
+ readonly type: "enabled";
182
+ readonly budget_tokens: number;
183
+ } | {
184
+ readonly type: "adaptive";
185
+ readonly display?: "summarized" | "omitted" | undefined;
186
+ } | {
187
+ readonly type: "disabled";
188
+ } | undefined;
189
+ tool_choice?: {
190
+ readonly type: "none" | "auto" | "any";
191
+ } | {
192
+ readonly type: "tool";
193
+ readonly name: string;
194
+ } | undefined;
195
+ top_p?: number | undefined;
196
+ top_k?: number | undefined;
197
+ stop_sequences?: readonly string[] | undefined;
198
+ output_config?: {
199
+ readonly effort?: string | undefined;
200
+ } | undefined;
201
+ }, import("../route/transport/http.js").HttpPrepared<string>>[];
202
+ export declare const configure: (input?: Config) => {
203
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
204
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<AnthropicMessages.ProviderOptionsInput>;
205
+ configure: (input?: Config) => /*elided*/ any;
206
+ };
207
+ export declare const provider: {
208
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
209
+ configure: (input?: Config) => {
210
+ id: string & import("effect/Brand").Brand<"AI.ProviderID">;
211
+ model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<AnthropicMessages.ProviderOptionsInput>;
212
+ configure: /*elided*/ any;
213
+ };
214
+ };
215
+ export declare const model: ProviderPackage.Definition<Settings, AnthropicMessages.ProviderOptionsInput>["model"];
@@ -0,0 +1,75 @@
1
+ import { Effect, Schema, Struct } from "effect";
2
+ import { AnthropicMessages } from "../protocols/anthropic-messages.js";
3
+ import { Auth } from "../route/auth.js";
4
+ import { Route } from "../route/client.js";
5
+ import { Endpoint } from "../route/endpoint.js";
6
+ import { Framing } from "../route/framing.js";
7
+ import { Protocol } from "../route/protocol.js";
8
+ import { ProviderID } from "../schema/index.js";
9
+ import { GoogleVertexShared } from "./google-vertex-shared.js";
10
+ const VERSION = "vertex-2023-10-16";
11
+ export const id = ProviderID.make("google-vertex");
12
+ const route = Route.make({
13
+ id: "google-vertex-messages",
14
+ provider: id,
15
+ providerMetadataKey: "anthropic",
16
+ protocol: Protocol.make({
17
+ id: AnthropicMessages.protocol.id,
18
+ body: {
19
+ schema: Schema.Struct({
20
+ ...Struct.omit(AnthropicMessages.AnthropicMessagesBody.fields, ["model"]),
21
+ anthropic_version: Schema.Literal(VERSION),
22
+ }),
23
+ from: (request) => AnthropicMessages.protocol.body.from(request).pipe(Effect.map((body) => ({
24
+ ...Struct.omit(body, ["model"]),
25
+ anthropic_version: VERSION,
26
+ }))),
27
+ },
28
+ stream: AnthropicMessages.protocol.stream,
29
+ }),
30
+ endpoint: Endpoint.path(({ request }) => `/${request.model.id}:streamRawPredict`),
31
+ auth: Auth.none,
32
+ framing: Framing.sse,
33
+ });
34
+ export const routes = [route];
35
+ const configuredRoute = (input) => {
36
+ if ("apiKey" in input && input.apiKey !== undefined)
37
+ throw new Error("Google Vertex Messages does not support API keys");
38
+ const { accessToken: _accessToken, auth: _auth, baseURL, location: inputLocation, project: inputProject, ...rest } = input;
39
+ const location = GoogleVertexShared.location(inputLocation, "global");
40
+ const project = GoogleVertexShared.project(inputProject);
41
+ return route.with({
42
+ ...rest,
43
+ endpoint: {
44
+ baseURL: baseURL ??
45
+ `https://${GoogleVertexShared.host(location)}/v1/projects/${GoogleVertexShared.requireProject(project)}/locations/${location}/publishers/anthropic/models`,
46
+ },
47
+ auth: GoogleVertexShared.oauth(input, project),
48
+ });
49
+ };
50
+ export const configure = (input = {}) => {
51
+ const route = configuredRoute(input);
52
+ return {
53
+ id,
54
+ model: (modelID) => route.model({ id: modelID }),
55
+ configure,
56
+ };
57
+ };
58
+ export const provider = {
59
+ id,
60
+ configure,
61
+ };
62
+ export const model = (modelID, settings) => {
63
+ if (settings.apiKey !== undefined)
64
+ throw new Error("Google Vertex Messages does not support API keys");
65
+ return configure({
66
+ accessToken: settings.accessToken,
67
+ baseURL: settings.baseURL,
68
+ headers: settings.headers === undefined ? undefined : { ...settings.headers },
69
+ http: settings.body === undefined ? undefined : { body: { ...settings.body } },
70
+ limits: settings.limits,
71
+ location: settings.location,
72
+ project: settings.project,
73
+ providerOptions: settings.providerOptions,
74
+ }).model(modelID);
75
+ };