@tanstack/ai-vercel-gateway 0.0.1
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/LICENSE +21 -0
- package/README.md +37 -0
- package/dist/esm/adapters/embedding.d.ts +21 -0
- package/dist/esm/adapters/embedding.js +73 -0
- package/dist/esm/adapters/embedding.js.map +1 -0
- package/dist/esm/adapters/factory.d.ts +16 -0
- package/dist/esm/adapters/factory.js +28 -0
- package/dist/esm/adapters/factory.js.map +1 -0
- package/dist/esm/adapters/image.d.ts +22 -0
- package/dist/esm/adapters/image.js +87 -0
- package/dist/esm/adapters/image.js.map +1 -0
- package/dist/esm/adapters/responses-text.d.ts +26 -0
- package/dist/esm/adapters/responses-text.js +38 -0
- package/dist/esm/adapters/responses-text.js.map +1 -0
- package/dist/esm/adapters/summarize.d.ts +9 -0
- package/dist/esm/adapters/summarize.js +17 -0
- package/dist/esm/adapters/summarize.js.map +1 -0
- package/dist/esm/adapters/text.d.ts +60 -0
- package/dist/esm/adapters/text.js +29 -0
- package/dist/esm/adapters/text.js.map +1 -0
- package/dist/esm/embedding/embedding-provider-options.d.ts +5 -0
- package/dist/esm/image/image-provider-options.d.ts +7 -0
- package/dist/esm/index.d.ts +17 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/message-types.d.ts +44 -0
- package/dist/esm/model-meta.d.ts +493 -0
- package/dist/esm/model-meta.js +351 -0
- package/dist/esm/model-meta.js.map +1 -0
- package/dist/esm/text/responses-provider-options.d.ts +3 -0
- package/dist/esm/text/text-provider-options.d.ts +40 -0
- package/dist/esm/tools/function-tool.d.ts +16 -0
- package/dist/esm/tools/function-tool.js +30 -0
- package/dist/esm/tools/function-tool.js.map +1 -0
- package/dist/esm/tools/index.d.ts +2 -0
- package/dist/esm/tools/index.js +3 -0
- package/dist/esm/tools/tool-converter.d.ts +7 -0
- package/dist/esm/tools/tool-converter.js +15 -0
- package/dist/esm/tools/tool-converter.js.map +1 -0
- package/dist/esm/utils/client.d.ts +8 -0
- package/dist/esm/utils/client.js +29 -0
- package/dist/esm/utils/client.js.map +1 -0
- package/dist/esm/utils/map-gateway-options.d.ts +4 -0
- package/dist/esm/utils/map-gateway-options.js +14 -0
- package/dist/esm/utils/map-gateway-options.js.map +1 -0
- package/package.json +73 -0
- package/src/adapters/embedding.ts +122 -0
- package/src/adapters/factory.ts +81 -0
- package/src/adapters/image.ts +156 -0
- package/src/adapters/responses-text.ts +99 -0
- package/src/adapters/summarize.ts +44 -0
- package/src/adapters/text.ts +68 -0
- package/src/embedding/embedding-provider-options.ts +6 -0
- package/src/image/image-provider-options.ts +13 -0
- package/src/index.ts +78 -0
- package/src/message-types.ts +45 -0
- package/src/model-meta.ts +2512 -0
- package/src/text/responses-provider-options.ts +10 -0
- package/src/text/text-provider-options.ts +47 -0
- package/src/tools/function-tool.ts +46 -0
- package/src/tools/index.ts +5 -0
- package/src/tools/tool-converter.ts +15 -0
- package/src/utils/client.ts +40 -0
- package/src/utils/map-gateway-options.ts +15 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import OpenAI from 'openai'
|
|
2
|
+
import { OpenAIBaseResponsesTextAdapter } from '@tanstack/openai-base'
|
|
3
|
+
import {
|
|
4
|
+
getVercelGatewayApiKeyFromEnv,
|
|
5
|
+
withVercelGatewayDefaults,
|
|
6
|
+
} from '../utils/client'
|
|
7
|
+
import { mapGatewayModelOptions } from '../utils/map-gateway-options'
|
|
8
|
+
import type { Modality, TextOptions } from '@tanstack/ai'
|
|
9
|
+
import type { ResponseCreateParams } from 'openai/resources/responses/responses'
|
|
10
|
+
import type {
|
|
11
|
+
VERCEL_GATEWAY_CHAT_MODELS,
|
|
12
|
+
VercelGatewayChatModelToolCapabilitiesByName,
|
|
13
|
+
ResolveInputModalities,
|
|
14
|
+
ResolveProviderOptions,
|
|
15
|
+
} from '../model-meta'
|
|
16
|
+
import type { VercelGatewayMessageMetadataByModality } from '../message-types'
|
|
17
|
+
import type { ExternalResponsesProviderOptions } from '../text/responses-provider-options'
|
|
18
|
+
import type { VercelGatewayClientConfig } from '../utils/client'
|
|
19
|
+
|
|
20
|
+
export interface VercelGatewayResponsesTextConfig extends VercelGatewayClientConfig {}
|
|
21
|
+
|
|
22
|
+
export type VercelGatewayResponsesTextProviderOptions =
|
|
23
|
+
ExternalResponsesProviderOptions
|
|
24
|
+
|
|
25
|
+
type ResolveToolCapabilities<TModel extends string> =
|
|
26
|
+
TModel extends keyof VercelGatewayChatModelToolCapabilitiesByName
|
|
27
|
+
? NonNullable<VercelGatewayChatModelToolCapabilitiesByName[TModel]>
|
|
28
|
+
: readonly []
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Vercel AI Gateway Responses text adapter.
|
|
32
|
+
*
|
|
33
|
+
* Talks to the public OpenAI-compatible Responses API at
|
|
34
|
+
* `https://ai-gateway.vercel.sh/v1`.
|
|
35
|
+
*/
|
|
36
|
+
export class VercelGatewayResponsesTextAdapter<
|
|
37
|
+
TModel extends (typeof VERCEL_GATEWAY_CHAT_MODELS)[number],
|
|
38
|
+
TProviderOptions extends Record<string, any> = ResolveProviderOptions<TModel>,
|
|
39
|
+
TInputModalities extends ReadonlyArray<Modality> =
|
|
40
|
+
ResolveInputModalities<TModel>,
|
|
41
|
+
TToolCapabilities extends ReadonlyArray<string> =
|
|
42
|
+
ResolveToolCapabilities<TModel>,
|
|
43
|
+
> extends OpenAIBaseResponsesTextAdapter<
|
|
44
|
+
TModel,
|
|
45
|
+
TProviderOptions,
|
|
46
|
+
TInputModalities,
|
|
47
|
+
VercelGatewayMessageMetadataByModality,
|
|
48
|
+
TToolCapabilities
|
|
49
|
+
> {
|
|
50
|
+
override readonly kind = 'text' as const
|
|
51
|
+
override readonly name = 'vercel-gateway' as const
|
|
52
|
+
|
|
53
|
+
constructor(config: VercelGatewayResponsesTextConfig, model: TModel) {
|
|
54
|
+
super(
|
|
55
|
+
model,
|
|
56
|
+
'vercel-gateway',
|
|
57
|
+
new OpenAI(withVercelGatewayDefaults(config)),
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected override mapOptionsToRequest(
|
|
62
|
+
options: TextOptions<TProviderOptions>,
|
|
63
|
+
): Omit<ResponseCreateParams, 'stream'> {
|
|
64
|
+
const request = super.mapOptionsToRequest({
|
|
65
|
+
...options,
|
|
66
|
+
modelOptions: mapGatewayModelOptions(
|
|
67
|
+
options.modelOptions as Record<string, unknown> | undefined,
|
|
68
|
+
) as TProviderOptions,
|
|
69
|
+
})
|
|
70
|
+
const { gateway: _gateway, ...rest } = request as typeof request & {
|
|
71
|
+
gateway?: unknown
|
|
72
|
+
}
|
|
73
|
+
void _gateway
|
|
74
|
+
return rest
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function createVercelGatewayResponsesText<
|
|
79
|
+
TModel extends (typeof VERCEL_GATEWAY_CHAT_MODELS)[number],
|
|
80
|
+
>(
|
|
81
|
+
model: TModel,
|
|
82
|
+
apiKey: string,
|
|
83
|
+
config?: Omit<VercelGatewayResponsesTextConfig, 'apiKey'>,
|
|
84
|
+
): VercelGatewayResponsesTextAdapter<TModel> {
|
|
85
|
+
return new VercelGatewayResponsesTextAdapter({ apiKey, ...config }, model)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function vercelGatewayResponsesText<
|
|
89
|
+
TModel extends (typeof VERCEL_GATEWAY_CHAT_MODELS)[number],
|
|
90
|
+
>(
|
|
91
|
+
model: TModel,
|
|
92
|
+
config?: Omit<VercelGatewayResponsesTextConfig, 'apiKey'>,
|
|
93
|
+
): VercelGatewayResponsesTextAdapter<TModel> {
|
|
94
|
+
return createVercelGatewayResponsesText(
|
|
95
|
+
model,
|
|
96
|
+
getVercelGatewayApiKeyFromEnv(),
|
|
97
|
+
config,
|
|
98
|
+
)
|
|
99
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ChatStreamSummarizeAdapter } from '@tanstack/ai/adapters'
|
|
2
|
+
import { getVercelGatewayApiKeyFromEnv } from '../utils/client'
|
|
3
|
+
import { VercelGatewayTextAdapter } from './text'
|
|
4
|
+
import type { InferTextProviderOptions } from '@tanstack/ai/adapters'
|
|
5
|
+
import type { VERCEL_GATEWAY_CHAT_MODELS } from '../model-meta'
|
|
6
|
+
import type { VercelGatewayClientConfig } from '../utils/client'
|
|
7
|
+
|
|
8
|
+
export interface VercelGatewaySummarizeConfig extends VercelGatewayClientConfig {}
|
|
9
|
+
|
|
10
|
+
export type VercelGatewaySummarizeModel =
|
|
11
|
+
(typeof VERCEL_GATEWAY_CHAT_MODELS)[number]
|
|
12
|
+
|
|
13
|
+
export function createVercelGatewaySummarize<
|
|
14
|
+
TModel extends VercelGatewaySummarizeModel,
|
|
15
|
+
>(
|
|
16
|
+
model: TModel,
|
|
17
|
+
apiKey: string,
|
|
18
|
+
config?: Omit<VercelGatewaySummarizeConfig, 'apiKey'>,
|
|
19
|
+
): ChatStreamSummarizeAdapter<
|
|
20
|
+
TModel,
|
|
21
|
+
InferTextProviderOptions<VercelGatewayTextAdapter<TModel>>
|
|
22
|
+
> {
|
|
23
|
+
return new ChatStreamSummarizeAdapter(
|
|
24
|
+
new VercelGatewayTextAdapter({ apiKey, ...config }, model),
|
|
25
|
+
model,
|
|
26
|
+
'vercel-gateway',
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function vercelGatewaySummarize<
|
|
31
|
+
TModel extends VercelGatewaySummarizeModel,
|
|
32
|
+
>(
|
|
33
|
+
model: TModel,
|
|
34
|
+
config?: Omit<VercelGatewaySummarizeConfig, 'apiKey'>,
|
|
35
|
+
): ChatStreamSummarizeAdapter<
|
|
36
|
+
TModel,
|
|
37
|
+
InferTextProviderOptions<VercelGatewayTextAdapter<TModel>>
|
|
38
|
+
> {
|
|
39
|
+
return createVercelGatewaySummarize(
|
|
40
|
+
model,
|
|
41
|
+
getVercelGatewayApiKeyFromEnv(),
|
|
42
|
+
config,
|
|
43
|
+
)
|
|
44
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import OpenAI from 'openai'
|
|
2
|
+
import { OpenAIBaseChatCompletionsTextAdapter } from '@tanstack/openai-base'
|
|
3
|
+
import { withVercelGatewayDefaults } from '../utils/client'
|
|
4
|
+
import { mapGatewayModelOptions } from '../utils/map-gateway-options'
|
|
5
|
+
import type { Modality, TextOptions } from '@tanstack/ai'
|
|
6
|
+
import type {
|
|
7
|
+
VERCEL_GATEWAY_CHAT_MODELS,
|
|
8
|
+
VercelGatewayChatModelToolCapabilitiesByName,
|
|
9
|
+
ResolveInputModalities,
|
|
10
|
+
ResolveProviderOptions,
|
|
11
|
+
} from '../model-meta'
|
|
12
|
+
import type { VercelGatewayMessageMetadataByModality } from '../message-types'
|
|
13
|
+
import type { VercelGatewayClientConfig } from '../utils/client'
|
|
14
|
+
|
|
15
|
+
type ResolveToolCapabilities<TModel extends string> =
|
|
16
|
+
TModel extends keyof VercelGatewayChatModelToolCapabilitiesByName
|
|
17
|
+
? NonNullable<VercelGatewayChatModelToolCapabilitiesByName[TModel]>
|
|
18
|
+
: readonly []
|
|
19
|
+
|
|
20
|
+
export interface VercelGatewayTextConfig extends VercelGatewayClientConfig {}
|
|
21
|
+
|
|
22
|
+
export type { ExternalTextProviderOptions as VercelGatewayTextProviderOptions } from '../text/text-provider-options'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Vercel AI Gateway text adapter.
|
|
26
|
+
*
|
|
27
|
+
* Talks to the public OpenAI-compatible Chat Completions API at
|
|
28
|
+
* `https://ai-gateway.vercel.sh/v1`.
|
|
29
|
+
*/
|
|
30
|
+
export class VercelGatewayTextAdapter<
|
|
31
|
+
TModel extends (typeof VERCEL_GATEWAY_CHAT_MODELS)[number],
|
|
32
|
+
TProviderOptions extends Record<string, any> = ResolveProviderOptions<TModel>,
|
|
33
|
+
TInputModalities extends ReadonlyArray<Modality> =
|
|
34
|
+
ResolveInputModalities<TModel>,
|
|
35
|
+
TToolCapabilities extends ReadonlyArray<string> =
|
|
36
|
+
ResolveToolCapabilities<TModel>,
|
|
37
|
+
> extends OpenAIBaseChatCompletionsTextAdapter<
|
|
38
|
+
TModel,
|
|
39
|
+
TProviderOptions,
|
|
40
|
+
TInputModalities,
|
|
41
|
+
VercelGatewayMessageMetadataByModality,
|
|
42
|
+
TToolCapabilities
|
|
43
|
+
> {
|
|
44
|
+
override readonly kind = 'text' as const
|
|
45
|
+
override readonly name = 'vercel-gateway' as const
|
|
46
|
+
|
|
47
|
+
constructor(config: VercelGatewayTextConfig, model: TModel) {
|
|
48
|
+
super(
|
|
49
|
+
model,
|
|
50
|
+
'vercel-gateway',
|
|
51
|
+
new OpenAI(withVercelGatewayDefaults(config)),
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
protected override mapOptionsToRequest(options: TextOptions) {
|
|
56
|
+
const request = super.mapOptionsToRequest({
|
|
57
|
+
...options,
|
|
58
|
+
modelOptions: mapGatewayModelOptions(
|
|
59
|
+
options.modelOptions as Record<string, unknown> | undefined,
|
|
60
|
+
) as TextOptions['modelOptions'],
|
|
61
|
+
})
|
|
62
|
+
const { gateway: _gateway, ...rest } = request as typeof request & {
|
|
63
|
+
gateway?: unknown
|
|
64
|
+
}
|
|
65
|
+
void _gateway
|
|
66
|
+
return rest
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { VercelGatewayRoutingOptions } from '../text/text-provider-options'
|
|
2
|
+
|
|
3
|
+
export interface VercelGatewayImageProviderOptions {
|
|
4
|
+
quality?: 'standard' | 'hd'
|
|
5
|
+
style?: 'vivid' | 'natural'
|
|
6
|
+
gateway?: VercelGatewayRoutingOptions
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type VercelGatewayImageSize =
|
|
10
|
+
| '1024x1024'
|
|
11
|
+
| '1536x1024'
|
|
12
|
+
| '1024x1536'
|
|
13
|
+
| 'auto'
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @tanstack/ai-vercel-gateway
|
|
3
|
+
*
|
|
4
|
+
* Vercel AI Gateway adapter for TanStack AI.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
VercelGatewayTextAdapter,
|
|
9
|
+
type VercelGatewayTextConfig,
|
|
10
|
+
type VercelGatewayTextProviderOptions,
|
|
11
|
+
} from './adapters/text'
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
createVercelGatewayText,
|
|
15
|
+
vercelGatewayText,
|
|
16
|
+
type VercelGatewayTextApi,
|
|
17
|
+
type VercelGatewayResponsesApiConfig,
|
|
18
|
+
type VercelGatewayChatApiConfig,
|
|
19
|
+
} from './adapters/factory'
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
VercelGatewayResponsesTextAdapter,
|
|
23
|
+
createVercelGatewayResponsesText,
|
|
24
|
+
vercelGatewayResponsesText,
|
|
25
|
+
type VercelGatewayResponsesTextConfig,
|
|
26
|
+
type VercelGatewayResponsesTextProviderOptions,
|
|
27
|
+
} from './adapters/responses-text'
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
createVercelGatewaySummarize,
|
|
31
|
+
vercelGatewaySummarize,
|
|
32
|
+
type VercelGatewaySummarizeConfig,
|
|
33
|
+
type VercelGatewaySummarizeModel,
|
|
34
|
+
} from './adapters/summarize'
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
VercelGatewayEmbeddingAdapter,
|
|
38
|
+
createVercelGatewayEmbedding,
|
|
39
|
+
vercelGatewayEmbedding,
|
|
40
|
+
type VercelGatewayEmbeddingConfig,
|
|
41
|
+
} from './adapters/embedding'
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
VercelGatewayImageAdapter,
|
|
45
|
+
createVercelGatewayImage,
|
|
46
|
+
vercelGatewayImage,
|
|
47
|
+
type VercelGatewayImageConfig,
|
|
48
|
+
} from './adapters/image'
|
|
49
|
+
|
|
50
|
+
export type { VercelGatewayEmbeddingProviderOptions } from './embedding/embedding-provider-options'
|
|
51
|
+
export type { VercelGatewayImageProviderOptions } from './image/image-provider-options'
|
|
52
|
+
export type {
|
|
53
|
+
VercelGatewayBaseOptions,
|
|
54
|
+
VercelGatewayCommonOptions,
|
|
55
|
+
VercelGatewayRoutingOptions,
|
|
56
|
+
} from './text/text-provider-options'
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
VERCEL_GATEWAY_CHAT_MODELS,
|
|
60
|
+
VERCEL_GATEWAY_EMBEDDING_MODELS,
|
|
61
|
+
VERCEL_GATEWAY_IMAGE_MODELS,
|
|
62
|
+
VERCEL_GATEWAY_MODEL_TAGS,
|
|
63
|
+
VERCEL_GATEWAY_PROVIDERS,
|
|
64
|
+
} from './model-meta'
|
|
65
|
+
export type {
|
|
66
|
+
VercelGatewayChatModel,
|
|
67
|
+
VercelGatewayChatModelProviderOptionsByName,
|
|
68
|
+
VercelGatewayEmbeddingModel,
|
|
69
|
+
VercelGatewayImageModel,
|
|
70
|
+
VercelGatewayModelInputModalitiesByName,
|
|
71
|
+
VercelGatewayModelTag,
|
|
72
|
+
VercelGatewayProvider,
|
|
73
|
+
} from './model-meta'
|
|
74
|
+
|
|
75
|
+
export {
|
|
76
|
+
getVercelGatewayApiKeyFromEnv,
|
|
77
|
+
type VercelGatewayClientConfig,
|
|
78
|
+
} from './utils/client'
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata for Vercel AI Gateway document content parts.
|
|
3
|
+
*/
|
|
4
|
+
export interface VercelGatewayDocumentMetadata {}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Metadata for Vercel AI Gateway text content parts.
|
|
8
|
+
*/
|
|
9
|
+
export interface VercelGatewayTextMetadata {}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Metadata for Vercel AI Gateway image content parts.
|
|
13
|
+
*/
|
|
14
|
+
export interface VercelGatewayImageMetadata {
|
|
15
|
+
/**
|
|
16
|
+
* Specifies the detail level of the image.
|
|
17
|
+
* - 'auto': Let the model decide based on image size and content
|
|
18
|
+
* - 'low': Use low resolution processing (faster, cheaper, less detail)
|
|
19
|
+
* - 'high': Use high resolution processing (slower, more expensive, more detail)
|
|
20
|
+
*
|
|
21
|
+
* @default 'auto'
|
|
22
|
+
*/
|
|
23
|
+
detail?: 'auto' | 'low' | 'high'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Metadata for Vercel AI Gateway audio content parts.
|
|
28
|
+
*/
|
|
29
|
+
export interface VercelGatewayAudioMetadata {}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Metadata for Vercel AI Gateway video content parts.
|
|
33
|
+
*/
|
|
34
|
+
export interface VercelGatewayVideoMetadata {}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Map of modality types to their Vercel AI Gateway metadata types.
|
|
38
|
+
*/
|
|
39
|
+
export interface VercelGatewayMessageMetadataByModality {
|
|
40
|
+
text: VercelGatewayTextMetadata
|
|
41
|
+
image: VercelGatewayImageMetadata
|
|
42
|
+
audio: VercelGatewayAudioMetadata
|
|
43
|
+
video: VercelGatewayVideoMetadata
|
|
44
|
+
document: VercelGatewayDocumentMetadata
|
|
45
|
+
}
|