@tanstack/ai-anthropic 0.16.7 → 0.17.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.
- package/dist/esm/adapters/text.d.ts +13 -3
- package/dist/esm/adapters/text.js +26 -5
- package/dist/esm/adapters/text.js.map +1 -1
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.js +3 -3
- package/dist/esm/message-types.d.ts +8 -9
- package/dist/esm/model-meta.d.ts +7 -0
- package/dist/esm/model-meta.js +19 -1
- package/dist/esm/model-meta.js.map +1 -1
- package/dist/esm/utils/client.d.ts +17 -0
- package/dist/esm/utils/client.js.map +1 -1
- package/dist/esm/vertex/auth.d.ts +15 -0
- package/dist/esm/vertex/auth.js +30 -0
- package/dist/esm/vertex/auth.js.map +1 -0
- package/dist/esm/vertex/index.d.ts +11 -0
- package/dist/esm/vertex/index.js +18 -0
- package/dist/esm/vertex/index.js.map +1 -0
- package/package.json +15 -3
- package/src/adapters/text.ts +72 -7
- package/src/index.ts +5 -0
- package/src/message-types.ts +10 -8
- package/src/model-meta.ts +22 -0
- package/src/utils/client.ts +21 -0
- package/src/vertex/auth.ts +66 -0
- package/src/vertex/index.ts +29 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { AnthropicVertex } from '@anthropic-ai/vertex-sdk'
|
|
2
|
+
|
|
3
|
+
export class AnthropicVertexAuthError extends Error {
|
|
4
|
+
constructor(message: string) {
|
|
5
|
+
super(message)
|
|
6
|
+
this.name = 'AnthropicVertexAuthError'
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type VertexSdkOptions = NonNullable<
|
|
11
|
+
ConstructorParameters<typeof AnthropicVertex>[0]
|
|
12
|
+
>
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Public Vertex config for Claude. `project` and `location` match the Gemini
|
|
16
|
+
* Vertex factories so one auth object works for both.
|
|
17
|
+
*/
|
|
18
|
+
export type AnthropicVertexConfig = Omit<
|
|
19
|
+
VertexSdkOptions,
|
|
20
|
+
'projectId' | 'region'
|
|
21
|
+
> & {
|
|
22
|
+
project?: string
|
|
23
|
+
location?: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function nonEmpty(value: string | undefined): string | undefined {
|
|
27
|
+
if (value === undefined || value.length === 0) {
|
|
28
|
+
return undefined
|
|
29
|
+
}
|
|
30
|
+
return value
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function readEnv(name: string): string | undefined {
|
|
34
|
+
if (typeof process === 'undefined' || process.env === undefined) {
|
|
35
|
+
return undefined
|
|
36
|
+
}
|
|
37
|
+
return nonEmpty(process.env[name])
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function resolveAnthropicVertexOptions(
|
|
41
|
+
config: AnthropicVertexConfig = {},
|
|
42
|
+
): VertexSdkOptions {
|
|
43
|
+
const { project, location, ...rest } = config
|
|
44
|
+
const projectId =
|
|
45
|
+
nonEmpty(project) ??
|
|
46
|
+
readEnv('GOOGLE_CLOUD_PROJECT') ??
|
|
47
|
+
readEnv('GOOGLE_VERTEX_PROJECT') ??
|
|
48
|
+
readEnv('ANTHROPIC_VERTEX_PROJECT_ID')
|
|
49
|
+
const region =
|
|
50
|
+
nonEmpty(location) ??
|
|
51
|
+
readEnv('GOOGLE_CLOUD_LOCATION') ??
|
|
52
|
+
readEnv('GOOGLE_VERTEX_LOCATION') ??
|
|
53
|
+
readEnv('CLOUD_ML_REGION')
|
|
54
|
+
|
|
55
|
+
if (region === undefined) {
|
|
56
|
+
throw new AnthropicVertexAuthError(
|
|
57
|
+
'Anthropic Vertex needs a location. Pass location on the factory, or set GOOGLE_CLOUD_LOCATION, GOOGLE_VERTEX_LOCATION, or CLOUD_ML_REGION.',
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
...rest,
|
|
63
|
+
projectId: projectId ?? null,
|
|
64
|
+
region,
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AnthropicVertex } from '@anthropic-ai/vertex-sdk'
|
|
2
|
+
import { createAnthropicChatWithClient } from '../adapters/text'
|
|
3
|
+
import { resolveAnthropicVertexOptions } from './auth'
|
|
4
|
+
import type { AnthropicTextAdapter } from '../adapters/text'
|
|
5
|
+
import type { AnthropicVertexChatModel } from '../model-meta'
|
|
6
|
+
import type { AnthropicVertexConfig } from './auth'
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
AnthropicVertexAuthError,
|
|
10
|
+
resolveAnthropicVertexOptions,
|
|
11
|
+
type AnthropicVertexConfig,
|
|
12
|
+
} from './auth'
|
|
13
|
+
export {
|
|
14
|
+
ANTHROPIC_VERTEX_CHAT_MODELS,
|
|
15
|
+
type AnthropicVertexChatModel,
|
|
16
|
+
} from '../model-meta'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates an Anthropic chat adapter that talks to Claude on Vertex AI.
|
|
20
|
+
*
|
|
21
|
+
* Install `@anthropic-ai/vertex-sdk` next to `@tanstack/ai-anthropic`.
|
|
22
|
+
*/
|
|
23
|
+
export function anthropicVertexText<TModel extends AnthropicVertexChatModel>(
|
|
24
|
+
model: TModel,
|
|
25
|
+
config: AnthropicVertexConfig = {},
|
|
26
|
+
): AnthropicTextAdapter<TModel> {
|
|
27
|
+
const client = new AnthropicVertex(resolveAnthropicVertexOptions(config))
|
|
28
|
+
return createAnthropicChatWithClient(model, client)
|
|
29
|
+
}
|