@ai-sdk/vercel 2.0.16 → 2.0.17

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @ai-sdk/vercel
2
2
 
3
+ ## 2.0.17
4
+
5
+ ### Patch Changes
6
+
7
+ - 8dc54db: chore: add src folders to package bundle
8
+ - Updated dependencies [8dc54db]
9
+ - @ai-sdk/openai-compatible@2.0.17
10
+
3
11
  ## 2.0.16
4
12
 
5
13
  ### Patch Changes
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ var import_openai_compatible = require("@ai-sdk/openai-compatible");
32
32
  var import_provider_utils = require("@ai-sdk/provider-utils");
33
33
 
34
34
  // src/version.ts
35
- var VERSION = true ? "2.0.16" : "0.0.0-test";
35
+ var VERSION = true ? "2.0.17" : "0.0.0-test";
36
36
 
37
37
  // src/vercel-provider.ts
38
38
  function createVercel(options = {}) {
package/dist/index.mjs CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  } from "@ai-sdk/provider-utils";
11
11
 
12
12
  // src/version.ts
13
- var VERSION = true ? "2.0.16" : "0.0.0-test";
13
+ var VERSION = true ? "2.0.17" : "0.0.0-test";
14
14
 
15
15
  // src/vercel-provider.ts
16
16
  function createVercel(options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/vercel",
3
- "version": "2.0.16",
3
+ "version": "2.0.17",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -8,6 +8,7 @@
8
8
  "types": "./dist/index.d.ts",
9
9
  "files": [
10
10
  "dist/**/*",
11
+ "src",
11
12
  "CHANGELOG.md",
12
13
  "README.md"
13
14
  ],
@@ -20,7 +21,7 @@
20
21
  }
21
22
  },
22
23
  "dependencies": {
23
- "@ai-sdk/openai-compatible": "2.0.16",
24
+ "@ai-sdk/openai-compatible": "2.0.17",
24
25
  "@ai-sdk/provider": "3.0.4",
25
26
  "@ai-sdk/provider-utils": "4.0.8"
26
27
  },
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { createVercel, vercel } from './vercel-provider';
2
+ export type { VercelProvider, VercelProviderSettings } from './vercel-provider';
3
+ export type { OpenAICompatibleErrorData as VercelErrorData } from '@ai-sdk/openai-compatible';
4
+ export { VERSION } from './version';
@@ -0,0 +1,6 @@
1
+ // https://v0.dev/docs/v0-model-api
2
+ export type VercelChatModelId =
3
+ | 'v0-1.0-md'
4
+ | 'v0-1.5-md'
5
+ | 'v0-1.5-lg'
6
+ | (string & {});
@@ -0,0 +1,102 @@
1
+ import { createVercel } from './vercel-provider';
2
+ import { OpenAICompatibleChatLanguageModel } from '@ai-sdk/openai-compatible';
3
+ import { LanguageModelV3 } from '@ai-sdk/provider';
4
+ import { loadApiKey } from '@ai-sdk/provider-utils';
5
+ import { describe, it, expect, vi, beforeEach, Mock } from 'vitest';
6
+
7
+ const OpenAICompatibleChatLanguageModelMock =
8
+ OpenAICompatibleChatLanguageModel as unknown as Mock;
9
+
10
+ vi.mock('@ai-sdk/openai-compatible', () => ({
11
+ OpenAICompatibleChatLanguageModel: vi.fn(),
12
+ OpenAICompatibleCompletionLanguageModel: vi.fn(),
13
+ }));
14
+
15
+ vi.mock('@ai-sdk/provider-utils', async () => {
16
+ const actual = await vi.importActual('@ai-sdk/provider-utils');
17
+ return {
18
+ ...actual,
19
+ loadApiKey: vi.fn().mockReturnValue('mock-api-key'),
20
+ withoutTrailingSlash: vi.fn(url => url),
21
+ };
22
+ });
23
+
24
+ vi.mock('./vercel-image-model', () => ({
25
+ VercelImageModel: vi.fn(),
26
+ }));
27
+
28
+ describe('VercelProvider', () => {
29
+ let mockLanguageModel: LanguageModelV3;
30
+
31
+ beforeEach(() => {
32
+ mockLanguageModel = {
33
+ // Add any required methods for LanguageModelV1
34
+ } as LanguageModelV3;
35
+
36
+ // Reset mocks
37
+ vi.clearAllMocks();
38
+ });
39
+
40
+ describe('createVercel', () => {
41
+ it('should create a VercelProvider instance with default options', () => {
42
+ const provider = createVercel();
43
+ provider('model-id');
44
+
45
+ // Use the mocked version
46
+ const constructorCall =
47
+ OpenAICompatibleChatLanguageModelMock.mock.calls[0];
48
+ const config = constructorCall[1];
49
+ config.headers();
50
+
51
+ expect(loadApiKey).toHaveBeenCalledWith({
52
+ apiKey: undefined,
53
+ environmentVariableName: 'VERCEL_API_KEY',
54
+ description: 'Vercel',
55
+ });
56
+ });
57
+
58
+ it('should create a VercelProvider instance with custom options', () => {
59
+ const options = {
60
+ apiKey: 'custom-key',
61
+ baseURL: 'https://custom.url',
62
+ headers: { 'Custom-Header': 'value' },
63
+ };
64
+ const provider = createVercel(options);
65
+ provider('model-id');
66
+
67
+ const constructorCall =
68
+ OpenAICompatibleChatLanguageModelMock.mock.calls[0];
69
+ const config = constructorCall[1];
70
+ config.headers();
71
+
72
+ expect(loadApiKey).toHaveBeenCalledWith({
73
+ apiKey: 'custom-key',
74
+ environmentVariableName: 'VERCEL_API_KEY',
75
+ description: 'Vercel',
76
+ });
77
+ });
78
+
79
+ it('should return a chat model when called as a function', () => {
80
+ const provider = createVercel();
81
+ const modelId = 'foo-model-id';
82
+
83
+ const model = provider(modelId);
84
+ expect(model).toBeInstanceOf(OpenAICompatibleChatLanguageModel);
85
+ });
86
+ });
87
+
88
+ it('should construct a language model with correct configuration', () => {
89
+ const provider = createVercel();
90
+ const modelId = 'vercel-chat-model';
91
+
92
+ const model = provider.languageModel(modelId);
93
+
94
+ expect(model).toBeInstanceOf(OpenAICompatibleChatLanguageModel);
95
+ expect(OpenAICompatibleChatLanguageModelMock).toHaveBeenCalledWith(
96
+ modelId,
97
+ expect.objectContaining({
98
+ provider: 'vercel.chat',
99
+ }),
100
+ );
101
+ });
102
+ });
@@ -0,0 +1,107 @@
1
+ import {
2
+ LanguageModelV3,
3
+ NoSuchModelError,
4
+ ProviderV3,
5
+ } from '@ai-sdk/provider';
6
+ import { OpenAICompatibleChatLanguageModel } from '@ai-sdk/openai-compatible';
7
+ import {
8
+ FetchFunction,
9
+ loadApiKey,
10
+ withoutTrailingSlash,
11
+ withUserAgentSuffix,
12
+ } from '@ai-sdk/provider-utils';
13
+ import { VercelChatModelId } from './vercel-chat-options';
14
+ import { VERSION } from './version';
15
+
16
+ export interface VercelProviderSettings {
17
+ /**
18
+ Vercel API key.
19
+ */
20
+ apiKey?: string;
21
+ /**
22
+ Base URL for the API calls.
23
+ */
24
+ baseURL?: string;
25
+ /**
26
+ Custom headers to include in the requests.
27
+ */
28
+ headers?: Record<string, string>;
29
+ /**
30
+ Custom fetch implementation. You can use it as a middleware to intercept requests,
31
+ or to provide a custom fetch implementation for e.g. testing.
32
+ */
33
+ fetch?: FetchFunction;
34
+ }
35
+
36
+ export interface VercelProvider extends ProviderV3 {
37
+ /**
38
+ Creates a model for text generation.
39
+ */
40
+ (modelId: VercelChatModelId): LanguageModelV3;
41
+
42
+ /**
43
+ Creates a language model for text generation.
44
+ */
45
+ languageModel(modelId: VercelChatModelId): LanguageModelV3;
46
+
47
+ /**
48
+ * @deprecated Use `embeddingModel` instead.
49
+ */
50
+ textEmbeddingModel(modelId: string): never;
51
+ }
52
+
53
+ export function createVercel(
54
+ options: VercelProviderSettings = {},
55
+ ): VercelProvider {
56
+ const baseURL = withoutTrailingSlash(
57
+ options.baseURL ?? 'https://api.v0.dev/v1',
58
+ );
59
+ const getHeaders = () =>
60
+ withUserAgentSuffix(
61
+ {
62
+ Authorization: `Bearer ${loadApiKey({
63
+ apiKey: options.apiKey,
64
+ environmentVariableName: 'VERCEL_API_KEY',
65
+ description: 'Vercel',
66
+ })}`,
67
+ ...options.headers,
68
+ },
69
+ `ai-sdk/vercel/${VERSION}`,
70
+ );
71
+
72
+ interface CommonModelConfig {
73
+ provider: string;
74
+ url: ({ path }: { path: string }) => string;
75
+ headers: () => Record<string, string>;
76
+ fetch?: FetchFunction;
77
+ }
78
+
79
+ const getCommonModelConfig = (modelType: string): CommonModelConfig => ({
80
+ provider: `vercel.${modelType}`,
81
+ url: ({ path }) => `${baseURL}${path}`,
82
+ headers: getHeaders,
83
+ fetch: options.fetch,
84
+ });
85
+
86
+ const createChatModel = (modelId: VercelChatModelId) => {
87
+ return new OpenAICompatibleChatLanguageModel(modelId, {
88
+ ...getCommonModelConfig('chat'),
89
+ });
90
+ };
91
+
92
+ const provider = (modelId: VercelChatModelId) => createChatModel(modelId);
93
+
94
+ provider.specificationVersion = 'v3' as const;
95
+ provider.languageModel = createChatModel;
96
+ provider.embeddingModel = (modelId: string) => {
97
+ throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });
98
+ };
99
+ provider.textEmbeddingModel = provider.embeddingModel;
100
+ provider.imageModel = (modelId: string) => {
101
+ throw new NoSuchModelError({ modelId, modelType: 'imageModel' });
102
+ };
103
+
104
+ return provider;
105
+ }
106
+
107
+ export const vercel = createVercel();
package/src/version.ts ADDED
@@ -0,0 +1,6 @@
1
+ // Version string of this package injected at build time.
2
+ declare const __PACKAGE_VERSION__: string | undefined;
3
+ export const VERSION: string =
4
+ typeof __PACKAGE_VERSION__ !== 'undefined'
5
+ ? __PACKAGE_VERSION__
6
+ : '0.0.0-test';