@gitlab/gitlab-ai-provider 3.1.3 → 3.3.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/CHANGELOG.md +8 -0
- package/README.md +117 -29
- package/dist/gitlab-gitlab-ai-provider-3.3.0.tgz +0 -0
- package/dist/index.d.mts +113 -46
- package/dist/index.d.ts +113 -46
- package/dist/index.js +792 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +782 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
- package/dist/gitlab-gitlab-ai-provider-3.1.3.tgz +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2StreamPart } from '@ai-sdk/provider';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
|
-
interface
|
|
4
|
+
interface GitLabAnthropicConfig {
|
|
5
5
|
provider: string;
|
|
6
6
|
instanceUrl: string;
|
|
7
7
|
getHeaders: () => Record<string, string>;
|
|
@@ -36,20 +36,20 @@ interface GitLabAgenticConfig {
|
|
|
36
36
|
aiGatewayUrl?: string;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
|
-
* GitLab
|
|
39
|
+
* GitLab Anthropic Language Model
|
|
40
40
|
*
|
|
41
41
|
* This model uses GitLab's Anthropic proxy to provide native tool calling support
|
|
42
42
|
* for the duo-chat model. It connects to Claude through GitLab's cloud proxy
|
|
43
43
|
* at https://cloud.gitlab.com/ai/v1/proxy/anthropic/
|
|
44
44
|
*/
|
|
45
|
-
declare class
|
|
45
|
+
declare class GitLabAnthropicLanguageModel implements LanguageModelV2 {
|
|
46
46
|
readonly specificationVersion: "v2";
|
|
47
47
|
readonly modelId: string;
|
|
48
48
|
readonly supportedUrls: Record<string, RegExp[]>;
|
|
49
49
|
private readonly config;
|
|
50
50
|
private readonly directAccessClient;
|
|
51
51
|
private anthropicClient;
|
|
52
|
-
constructor(modelId: string, config:
|
|
52
|
+
constructor(modelId: string, config: GitLabAnthropicConfig);
|
|
53
53
|
get provider(): string;
|
|
54
54
|
/**
|
|
55
55
|
* Get or create an Anthropic client with valid credentials
|
|
@@ -118,33 +118,33 @@ interface GitLabProvider {
|
|
|
118
118
|
* anthropicModel: 'claude-sonnet-4-5-20250929'
|
|
119
119
|
* });
|
|
120
120
|
*/
|
|
121
|
-
agenticChat(modelId: string, options?: GitLabAgenticOptions):
|
|
121
|
+
agenticChat(modelId: string, options?: GitLabAgenticOptions): GitLabAnthropicLanguageModel;
|
|
122
122
|
textEmbeddingModel(modelId: string): never;
|
|
123
123
|
imageModel(modelId: string): never;
|
|
124
124
|
}
|
|
125
125
|
interface GitLabAgenticOptions {
|
|
126
126
|
/**
|
|
127
|
-
*
|
|
127
|
+
* Override the provider-specific model (optional).
|
|
128
|
+
* Must be a valid model for the detected provider.
|
|
128
129
|
*
|
|
129
|
-
*
|
|
130
|
-
* - '
|
|
131
|
-
* - '
|
|
132
|
-
* - '
|
|
130
|
+
* For Anthropic models:
|
|
131
|
+
* - 'claude-opus-4-5-20251101'
|
|
132
|
+
* - 'claude-sonnet-4-5-20250929'
|
|
133
|
+
* - 'claude-haiku-4-5-20251001'
|
|
133
134
|
*
|
|
134
|
-
* For
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* const model = gitlab.agenticChat('duo-chat-opus-4-5');
|
|
135
|
+
* For OpenAI models:
|
|
136
|
+
* - 'gpt-5.1-2025-11-13'
|
|
137
|
+
* - 'gpt-5-mini-2025-08-07'
|
|
138
|
+
* - 'gpt-5-codex'
|
|
139
|
+
* - 'gpt-5.2-codex'
|
|
140
140
|
*
|
|
141
141
|
* @example
|
|
142
142
|
* // Override with explicit model
|
|
143
143
|
* const model = gitlab.agenticChat('duo-chat-opus-4-5', {
|
|
144
|
-
*
|
|
144
|
+
* providerModel: 'claude-sonnet-4-5-20250929'
|
|
145
145
|
* });
|
|
146
146
|
*/
|
|
147
|
-
|
|
147
|
+
providerModel?: string;
|
|
148
148
|
/**
|
|
149
149
|
* Maximum tokens to generate
|
|
150
150
|
* @default 8192
|
|
@@ -214,32 +214,93 @@ declare function createGitLab(options?: GitLabProviderSettings): GitLabProvider;
|
|
|
214
214
|
*/
|
|
215
215
|
declare const gitlab: GitLabProvider;
|
|
216
216
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
217
|
+
interface GitLabOpenAIConfig {
|
|
218
|
+
provider: string;
|
|
219
|
+
instanceUrl: string;
|
|
220
|
+
getHeaders: () => Record<string, string>;
|
|
221
|
+
fetch?: typeof fetch;
|
|
222
|
+
refreshApiKey?: () => Promise<void>;
|
|
223
|
+
openaiModel?: string;
|
|
224
|
+
maxTokens?: number;
|
|
225
|
+
featureFlags?: {
|
|
226
|
+
DuoAgentPlatformNext: true;
|
|
227
|
+
} & Record<string, boolean>;
|
|
228
|
+
aiGatewayUrl?: string;
|
|
229
|
+
/** Whether to use the Responses API instead of Chat Completions API */
|
|
230
|
+
useResponsesApi?: boolean;
|
|
231
|
+
}
|
|
232
|
+
declare class GitLabOpenAILanguageModel implements LanguageModelV2 {
|
|
233
|
+
readonly specificationVersion: "v2";
|
|
234
|
+
readonly modelId: string;
|
|
235
|
+
readonly supportedUrls: Record<string, RegExp[]>;
|
|
236
|
+
private readonly config;
|
|
237
|
+
private readonly directAccessClient;
|
|
238
|
+
private readonly useResponsesApi;
|
|
239
|
+
private openaiClient;
|
|
240
|
+
constructor(modelId: string, config: GitLabOpenAIConfig);
|
|
241
|
+
get provider(): string;
|
|
242
|
+
private getOpenAIClient;
|
|
243
|
+
private isTokenError;
|
|
244
|
+
private convertTools;
|
|
245
|
+
private convertToolChoice;
|
|
246
|
+
private convertPrompt;
|
|
247
|
+
private convertFinishReason;
|
|
248
|
+
/**
|
|
249
|
+
* Convert tools to Responses API format
|
|
250
|
+
*/
|
|
251
|
+
private convertToolsForResponses;
|
|
252
|
+
/**
|
|
253
|
+
* Convert prompt to Responses API input format
|
|
254
|
+
*/
|
|
255
|
+
private convertPromptForResponses;
|
|
256
|
+
/**
|
|
257
|
+
* Extract system instructions from prompt
|
|
258
|
+
*/
|
|
259
|
+
private extractSystemInstructions;
|
|
260
|
+
/**
|
|
261
|
+
* Convert Responses API status to finish reason
|
|
262
|
+
* Note: Responses API returns 'completed' even when making tool calls,
|
|
263
|
+
* so we need to check the content for tool calls separately.
|
|
264
|
+
*/
|
|
265
|
+
private convertResponsesStatus;
|
|
266
|
+
doGenerate(options: LanguageModelV2CallOptions): Promise<{
|
|
267
|
+
content: LanguageModelV2Content[];
|
|
268
|
+
finishReason: LanguageModelV2FinishReason;
|
|
269
|
+
usage: LanguageModelV2Usage;
|
|
270
|
+
warnings: LanguageModelV2CallWarning[];
|
|
271
|
+
}>;
|
|
272
|
+
private doGenerateWithChatApi;
|
|
273
|
+
private doGenerateWithResponsesApi;
|
|
274
|
+
doStream(options: LanguageModelV2CallOptions): Promise<{
|
|
275
|
+
stream: ReadableStream<LanguageModelV2StreamPart>;
|
|
276
|
+
request?: {
|
|
277
|
+
body?: unknown;
|
|
278
|
+
};
|
|
279
|
+
response?: {
|
|
280
|
+
headers?: Record<string, string>;
|
|
281
|
+
};
|
|
282
|
+
}>;
|
|
283
|
+
private doStreamWithChatApi;
|
|
284
|
+
private doStreamWithResponsesApi;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
type ModelProvider = 'anthropic' | 'openai';
|
|
288
|
+
type OpenAIApiType = 'chat' | 'responses';
|
|
289
|
+
interface ModelMapping {
|
|
290
|
+
provider: ModelProvider;
|
|
291
|
+
model: string;
|
|
292
|
+
/** For OpenAI models, which API to use: 'chat' for /v1/chat/completions, 'responses' for /v1/responses */
|
|
293
|
+
openaiApiType?: OpenAIApiType;
|
|
294
|
+
}
|
|
295
|
+
declare const MODEL_MAPPINGS: Record<string, ModelMapping>;
|
|
296
|
+
declare function getModelMapping(modelId: string): ModelMapping | undefined;
|
|
297
|
+
declare function getProviderForModelId(modelId: string): ModelProvider | undefined;
|
|
298
|
+
declare function getValidModelsForProvider(provider: ModelProvider): string[];
|
|
242
299
|
declare function getAnthropicModelForModelId(modelId: string): string | undefined;
|
|
300
|
+
declare function getOpenAIModelForModelId(modelId: string): string | undefined;
|
|
301
|
+
declare function getOpenAIApiType(modelId: string): OpenAIApiType;
|
|
302
|
+
declare function isResponsesApiModel(modelId: string): boolean;
|
|
303
|
+
declare const MODEL_ID_TO_ANTHROPIC_MODEL: Record<string, string>;
|
|
243
304
|
|
|
244
305
|
interface GitLabErrorOptions {
|
|
245
306
|
message: string;
|
|
@@ -265,15 +326,15 @@ declare const gitlabOAuthTokenResponseSchema: z.ZodObject<{
|
|
|
265
326
|
expires_in: z.ZodNumber;
|
|
266
327
|
created_at: z.ZodNumber;
|
|
267
328
|
}, "strip", z.ZodTypeAny, {
|
|
329
|
+
created_at?: number;
|
|
268
330
|
access_token?: string;
|
|
269
331
|
refresh_token?: string;
|
|
270
332
|
expires_in?: number;
|
|
271
|
-
created_at?: number;
|
|
272
333
|
}, {
|
|
334
|
+
created_at?: number;
|
|
273
335
|
access_token?: string;
|
|
274
336
|
refresh_token?: string;
|
|
275
337
|
expires_in?: number;
|
|
276
|
-
created_at?: number;
|
|
277
338
|
}>;
|
|
278
339
|
type GitLabOAuthTokenResponse = z.infer<typeof gitlabOAuthTokenResponseSchema>;
|
|
279
340
|
|
|
@@ -568,10 +629,16 @@ declare class GitLabDirectAccessClient {
|
|
|
568
629
|
* Get the Anthropic proxy base URL
|
|
569
630
|
*/
|
|
570
631
|
getAnthropicProxyUrl(): string;
|
|
632
|
+
/**
|
|
633
|
+
* Get the OpenAI proxy base URL
|
|
634
|
+
* Note: The OpenAI SDK expects a base URL like https://api.openai.com/v1
|
|
635
|
+
* and appends paths like /chat/completions. So we need /v1 at the end.
|
|
636
|
+
*/
|
|
637
|
+
getOpenAIProxyUrl(): string;
|
|
571
638
|
/**
|
|
572
639
|
* Invalidate the cached token
|
|
573
640
|
*/
|
|
574
641
|
invalidateToken(): void;
|
|
575
642
|
}
|
|
576
643
|
|
|
577
|
-
export { BUNDLED_CLIENT_ID, DEFAULT_AI_GATEWAY_URL, type DirectAccessToken, GITLAB_COM_URL, type
|
|
644
|
+
export { BUNDLED_CLIENT_ID, DEFAULT_AI_GATEWAY_URL, type DirectAccessToken, GITLAB_COM_URL, type GitLabAgenticOptions, type GitLabAnthropicConfig, GitLabAnthropicLanguageModel, GitLabDirectAccessClient, type GitLabDirectAccessConfig, GitLabError, type GitLabErrorOptions, GitLabOAuthManager, type GitLabOAuthTokenResponse, type GitLabOAuthTokens, type GitLabOpenAIConfig, GitLabOpenAILanguageModel, type GitLabProject, GitLabProjectCache, GitLabProjectDetector, type GitLabProjectDetectorConfig, type GitLabProvider, type GitLabProviderSettings, MODEL_ID_TO_ANTHROPIC_MODEL, MODEL_MAPPINGS, type ModelMapping, type ModelProvider, OAUTH_SCOPES, type OpenAIApiType, type OpenCodeAuth, type OpenCodeAuthApi, type OpenCodeAuthOAuth, TOKEN_EXPIRY_SKEW_MS, createGitLab, getAnthropicModelForModelId, getModelMapping, getOpenAIApiType, getOpenAIModelForModelId, getProviderForModelId, getValidModelsForProvider, gitlab, isResponsesApiModel };
|