@gitlab/gitlab-ai-provider 3.1.0 → 3.1.2
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 +49 -30
- package/dist/gitlab-gitlab-ai-provider-3.1.2.tgz +0 -0
- package/dist/index.d.mts +138 -86
- package/dist/index.d.ts +138 -86
- package/dist/index.js +74 -1225
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -1219
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/gitlab-gitlab-ai-provider-3.1.0.tgz +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## <small>3.1.2 (2026-01-18)</small>
|
|
6
|
+
|
|
7
|
+
- fix: removed API tools and added new env variable ([a64ef6d](https://gitlab.com/gitlab-org/editor-extensions/gitlab-ai-provider/commit/a64ef6d))
|
|
8
|
+
|
|
9
|
+
## <small>3.1.1 (2026-01-14)</small>
|
|
10
|
+
|
|
11
|
+
- fix: use models mapping for Anthropic ([7b876ec](https://gitlab.com/gitlab-org/editor-extensions/gitlab-ai-provider/commit/7b876ec))
|
|
12
|
+
|
|
5
13
|
## 3.1.0 (2026-01-13)
|
|
6
14
|
|
|
7
15
|
- feat: improve npm metadata for better discoverability ([fc3795c](https://gitlab.com/gitlab-org/editor-extensions/gitlab-ai-provider/commit/fc3795c))
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ A comprehensive TypeScript provider for integrating GitLab Duo AI capabilities w
|
|
|
7
7
|
- **🤖 Agentic Chat**: Native tool calling support via GitLab's Anthropic proxy
|
|
8
8
|
- **🔐 Multiple Authentication**: Support for OAuth, Personal Access Tokens, and OpenCode auth
|
|
9
9
|
- **🌐 Self-Hosted Support**: Works with both GitLab.com and self-hosted instances
|
|
10
|
-
-
|
|
10
|
+
- **🔧 Tool Support**: Native tool calling via Vercel AI SDK
|
|
11
11
|
- **🔍 Project Detection**: Automatic GitLab project detection from git remotes
|
|
12
12
|
- **💾 Smart Caching**: Project and token caching for optimal performance
|
|
13
13
|
- **🎯 Type-Safe**: Complete TypeScript definitions with Zod validation
|
|
@@ -75,6 +75,46 @@ const { text } = await generateText({
|
|
|
75
75
|
});
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
+
### Model Variants
|
|
79
|
+
|
|
80
|
+
The provider automatically maps specific model IDs to their corresponding Anthropic models:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { createGitLab } from '@gitlab/gitlab-ai-provider';
|
|
84
|
+
import { generateText } from 'ai';
|
|
85
|
+
|
|
86
|
+
const gitlab = createGitLab({
|
|
87
|
+
apiKey: process.env.GITLAB_TOKEN,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Use Claude Opus 4.5
|
|
91
|
+
const opusModel = gitlab.agenticChat('duo-chat-opus-4-5');
|
|
92
|
+
// Automatically uses: claude-opus-4-5-20251101
|
|
93
|
+
|
|
94
|
+
// Use Claude Sonnet 4.5
|
|
95
|
+
const sonnetModel = gitlab.agenticChat('duo-chat-sonnet-4-5');
|
|
96
|
+
// Automatically uses: claude-sonnet-4-5-20250929
|
|
97
|
+
|
|
98
|
+
// Use Claude Haiku 4.5
|
|
99
|
+
const haikuModel = gitlab.agenticChat('duo-chat-haiku-4-5');
|
|
100
|
+
// Automatically uses: claude-haiku-4-5-20251001
|
|
101
|
+
|
|
102
|
+
// You can still override with explicit anthropicModel option
|
|
103
|
+
const customModel = gitlab.agenticChat('duo-chat-opus-4-5', {
|
|
104
|
+
anthropicModel: 'claude-sonnet-4-5-20250929', // Override mapping
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Available Model Mappings:**
|
|
109
|
+
|
|
110
|
+
| Model ID | Anthropic Model |
|
|
111
|
+
| --------------------- | ---------------------------- |
|
|
112
|
+
| `duo-chat-opus-4-5` | `claude-opus-4-5-20251101` |
|
|
113
|
+
| `duo-chat-sonnet-4-5` | `claude-sonnet-4-5-20250929` |
|
|
114
|
+
| `duo-chat-haiku-4-5` | `claude-haiku-4-5-20251001` |
|
|
115
|
+
|
|
116
|
+
For unmapped model IDs, the provider defaults to `claude-sonnet-4-5-20250929`.
|
|
117
|
+
|
|
78
118
|
### Agentic Chat with Feature Flags
|
|
79
119
|
|
|
80
120
|
You can pass feature flags to enable experimental features in GitLab's Anthropic proxy:
|
|
@@ -184,33 +224,6 @@ Provides native tool calling through GitLab's Anthropic proxy.
|
|
|
184
224
|
- Direct access token management
|
|
185
225
|
- Supports all Anthropic tool calling features
|
|
186
226
|
|
|
187
|
-
### Tool Executors
|
|
188
|
-
|
|
189
|
-
#### AnthropicToolExecutor
|
|
190
|
-
|
|
191
|
-
Executes local file system and command tools:
|
|
192
|
-
|
|
193
|
-
- `list_dir` - List directory contents
|
|
194
|
-
- `read_file` - Read file contents
|
|
195
|
-
- `write_file` - Write to files
|
|
196
|
-
- `edit_file` - Edit file with find/replace
|
|
197
|
-
- `find_files` - Find files by pattern
|
|
198
|
-
- `mkdir` - Create directories
|
|
199
|
-
- `grep` - Search file contents
|
|
200
|
-
- `run_command` - Execute shell commands
|
|
201
|
-
- `run_git_command` - Execute git commands
|
|
202
|
-
|
|
203
|
-
#### GitLabApiToolExecutor
|
|
204
|
-
|
|
205
|
-
Executes GitLab API operations:
|
|
206
|
-
|
|
207
|
-
- Merge Requests: get, list, changes, discussions, notes
|
|
208
|
-
- Issues: get, list, notes
|
|
209
|
-
- Pipelines: list, get, jobs, logs
|
|
210
|
-
- Repository: files, commits, branches
|
|
211
|
-
- Search: global and project search
|
|
212
|
-
- Projects: get, members
|
|
213
|
-
|
|
214
227
|
### Supporting Utilities
|
|
215
228
|
|
|
216
229
|
#### GitLabProjectDetector
|
|
@@ -281,9 +294,17 @@ interface GitLabProviderSettings {
|
|
|
281
294
|
name?: string; // Provider name prefix
|
|
282
295
|
headers?: Record<string, string>; // Custom headers
|
|
283
296
|
fetch?: typeof fetch; // Custom fetch implementation
|
|
297
|
+
aiGatewayUrl?: string; // AI Gateway URL (default: 'https://cloud.gitlab.com')
|
|
284
298
|
}
|
|
285
299
|
```
|
|
286
300
|
|
|
301
|
+
### Environment Variables
|
|
302
|
+
|
|
303
|
+
| Variable | Description | Default |
|
|
304
|
+
| ----------------------- | ------------------------------------------- | -------------------------- |
|
|
305
|
+
| `GITLAB_TOKEN` | GitLab Personal Access Token or OAuth token | - |
|
|
306
|
+
| `GITLAB_AI_GATEWAY_URL` | AI Gateway URL for Anthropic proxy | `https://cloud.gitlab.com` |
|
|
307
|
+
|
|
287
308
|
### Agentic Chat Options
|
|
288
309
|
|
|
289
310
|
```typescript
|
|
@@ -352,8 +373,6 @@ gitlab-ai-provider/
|
|
|
352
373
|
│ ├── gitlab-oauth-types.ts # OAuth types
|
|
353
374
|
│ ├── gitlab-project-detector.ts # Project detection
|
|
354
375
|
│ ├── gitlab-project-cache.ts # Project caching
|
|
355
|
-
│ ├── gitlab-anthropic-tools.ts # Anthropic tool executor
|
|
356
|
-
│ ├── gitlab-api-tools.ts # GitLab API tool executor
|
|
357
376
|
│ ├── gitlab-api-types.ts # API types
|
|
358
377
|
│ ├── gitlab-error.ts # Error handling
|
|
359
378
|
│ └── gitlab-workflow-debug.ts # Debug logging
|
|
Binary file
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2StreamPart } from '@ai-sdk/provider';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { Tool } from '@anthropic-ai/sdk/resources/messages';
|
|
4
3
|
|
|
5
4
|
interface GitLabAgenticConfig {
|
|
6
5
|
provider: string;
|
|
@@ -29,6 +28,12 @@ interface GitLabAgenticConfig {
|
|
|
29
28
|
featureFlags?: {
|
|
30
29
|
DuoAgentPlatformNext: true;
|
|
31
30
|
} & Record<string, boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* AI Gateway URL for the Anthropic proxy.
|
|
33
|
+
* Can also be set via GITLAB_AI_GATEWAY_URL environment variable.
|
|
34
|
+
* @default 'https://cloud.gitlab.com'
|
|
35
|
+
*/
|
|
36
|
+
aiGatewayUrl?: string;
|
|
32
37
|
}
|
|
33
38
|
/**
|
|
34
39
|
* GitLab Agentic Language Model
|
|
@@ -95,6 +100,24 @@ interface GitLabProvider {
|
|
|
95
100
|
readonly specificationVersion: 'v2';
|
|
96
101
|
languageModel(modelId: string): LanguageModelV2;
|
|
97
102
|
chat(modelId: string): LanguageModelV2;
|
|
103
|
+
/**
|
|
104
|
+
* Create an agentic chat model with tool calling support
|
|
105
|
+
*
|
|
106
|
+
* @param modelId - GitLab model identifier. Some IDs automatically map to specific Anthropic models.
|
|
107
|
+
* @param options - Configuration options for the agentic model
|
|
108
|
+
* @returns A language model with native tool calling support via Anthropic
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* // Automatic model mapping
|
|
112
|
+
* const model = gitlab.agenticChat('duo-chat-opus-4-5');
|
|
113
|
+
* // Uses claude-opus-4-5-20251101
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* // Explicit model override
|
|
117
|
+
* const model = gitlab.agenticChat('duo-chat', {
|
|
118
|
+
* anthropicModel: 'claude-sonnet-4-5-20250929'
|
|
119
|
+
* });
|
|
120
|
+
*/
|
|
98
121
|
agenticChat(modelId: string, options?: GitLabAgenticOptions): GitLabAgenticLanguageModel;
|
|
99
122
|
textEmbeddingModel(modelId: string): never;
|
|
100
123
|
imageModel(modelId: string): never;
|
|
@@ -102,7 +125,24 @@ interface GitLabProvider {
|
|
|
102
125
|
interface GitLabAgenticOptions {
|
|
103
126
|
/**
|
|
104
127
|
* The Anthropic model to use
|
|
105
|
-
*
|
|
128
|
+
*
|
|
129
|
+
* If not specified, automatically maps from the model ID:
|
|
130
|
+
* - 'duo-chat-opus-4-5' → 'claude-opus-4-5-20251101'
|
|
131
|
+
* - 'duo-chat-sonnet-4-5' → 'claude-sonnet-4-5-20250929'
|
|
132
|
+
* - 'duo-chat-haiku-4-5' → 'claude-haiku-4-5-20251001'
|
|
133
|
+
*
|
|
134
|
+
* For unmapped model IDs, defaults to 'claude-sonnet-4-5-20250929'
|
|
135
|
+
*
|
|
136
|
+
* @default Automatically mapped from model ID, or 'claude-sonnet-4-5-20250929'
|
|
137
|
+
* @example
|
|
138
|
+
* // Use automatic mapping
|
|
139
|
+
* const model = gitlab.agenticChat('duo-chat-opus-4-5');
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* // Override with explicit model
|
|
143
|
+
* const model = gitlab.agenticChat('duo-chat-opus-4-5', {
|
|
144
|
+
* anthropicModel: 'claude-sonnet-4-5-20250929'
|
|
145
|
+
* });
|
|
106
146
|
*/
|
|
107
147
|
anthropicModel?: string;
|
|
108
148
|
/**
|
|
@@ -154,6 +194,12 @@ interface GitLabProviderSettings {
|
|
|
154
194
|
* Default feature flags to pass to the GitLab API for all agentic chat models
|
|
155
195
|
*/
|
|
156
196
|
featureFlags?: Record<string, boolean>;
|
|
197
|
+
/**
|
|
198
|
+
* AI Gateway URL for the Anthropic proxy.
|
|
199
|
+
* Can also be set via GITLAB_AI_GATEWAY_URL environment variable.
|
|
200
|
+
* @default 'https://cloud.gitlab.com'
|
|
201
|
+
*/
|
|
202
|
+
aiGatewayUrl?: string;
|
|
157
203
|
}
|
|
158
204
|
declare function createGitLab(options?: GitLabProviderSettings): GitLabProvider;
|
|
159
205
|
/**
|
|
@@ -168,6 +214,33 @@ declare function createGitLab(options?: GitLabProviderSettings): GitLabProvider;
|
|
|
168
214
|
*/
|
|
169
215
|
declare const gitlab: GitLabProvider;
|
|
170
216
|
|
|
217
|
+
/**
|
|
218
|
+
* Maps GitLab model IDs to their corresponding Anthropic model identifiers.
|
|
219
|
+
*
|
|
220
|
+
* This mapping allows users to specify model variants by model ID without
|
|
221
|
+
* needing to manually configure the anthropicModel option.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* const model = gitlab.agenticChat('duo-chat-opus-4-5');
|
|
225
|
+
* // Automatically uses 'claude-opus-4-5-20251101'
|
|
226
|
+
*/
|
|
227
|
+
declare const MODEL_ID_TO_ANTHROPIC_MODEL: Record<string, string>;
|
|
228
|
+
/**
|
|
229
|
+
* Gets the Anthropic model identifier for a given GitLab model ID.
|
|
230
|
+
*
|
|
231
|
+
* @param modelId - The GitLab model ID (e.g., 'duo-chat-opus-4-5')
|
|
232
|
+
* @returns The Anthropic model identifier, or undefined if no mapping exists
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* getAnthropicModelForModelId('duo-chat-opus-4-5')
|
|
236
|
+
* // Returns: 'claude-opus-4-5-20251101'
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* getAnthropicModelForModelId('duo-chat')
|
|
240
|
+
* // Returns: undefined (uses default)
|
|
241
|
+
*/
|
|
242
|
+
declare function getAnthropicModelForModelId(modelId: string): string | undefined;
|
|
243
|
+
|
|
171
244
|
interface GitLabErrorOptions {
|
|
172
245
|
message: string;
|
|
173
246
|
statusCode?: number;
|
|
@@ -309,89 +382,6 @@ declare class GitLabOAuthManager {
|
|
|
309
382
|
private createExpiresTimestamp;
|
|
310
383
|
}
|
|
311
384
|
|
|
312
|
-
/**
|
|
313
|
-
* Tool definitions for Anthropic Claude
|
|
314
|
-
*/
|
|
315
|
-
declare const ANTHROPIC_TOOLS: Tool[];
|
|
316
|
-
interface ToolResult {
|
|
317
|
-
result: string;
|
|
318
|
-
error?: string;
|
|
319
|
-
}
|
|
320
|
-
interface ToolInput {
|
|
321
|
-
[key: string]: unknown;
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Tool executor for local file and command operations
|
|
325
|
-
*/
|
|
326
|
-
declare class AnthropicToolExecutor {
|
|
327
|
-
private readonly workingDirectory;
|
|
328
|
-
constructor(workingDirectory: string);
|
|
329
|
-
/**
|
|
330
|
-
* Execute a tool by name with given input
|
|
331
|
-
*/
|
|
332
|
-
execute(toolName: string, input: ToolInput): Promise<ToolResult>;
|
|
333
|
-
private resolvePath;
|
|
334
|
-
private listDir;
|
|
335
|
-
private readFile;
|
|
336
|
-
private writeFile;
|
|
337
|
-
private editFile;
|
|
338
|
-
private findFiles;
|
|
339
|
-
private mkdir;
|
|
340
|
-
private grep;
|
|
341
|
-
private runCommand;
|
|
342
|
-
private runGitCommand;
|
|
343
|
-
private executeCommand;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* GitLab API tools for interacting with GitLab resources
|
|
348
|
-
* These tools allow the AI to access merge requests, issues, pipelines, etc.
|
|
349
|
-
*/
|
|
350
|
-
declare const GITLAB_API_TOOLS: Tool[];
|
|
351
|
-
interface GitLabApiToolsConfig {
|
|
352
|
-
instanceUrl: string;
|
|
353
|
-
token: string;
|
|
354
|
-
fetch?: typeof fetch;
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Executor for GitLab API tools
|
|
358
|
-
*/
|
|
359
|
-
declare class GitLabApiToolExecutor {
|
|
360
|
-
private readonly config;
|
|
361
|
-
constructor(config: GitLabApiToolsConfig);
|
|
362
|
-
private get headers();
|
|
363
|
-
private fetchApi;
|
|
364
|
-
private encodeProjectId;
|
|
365
|
-
/**
|
|
366
|
-
* Execute a GitLab API tool by name
|
|
367
|
-
*/
|
|
368
|
-
execute(toolName: string, input: ToolInput): Promise<ToolResult>;
|
|
369
|
-
private getMergeRequest;
|
|
370
|
-
private listMergeRequests;
|
|
371
|
-
private getMrChanges;
|
|
372
|
-
private listMrDiscussions;
|
|
373
|
-
private createMrNote;
|
|
374
|
-
private getIssue;
|
|
375
|
-
private listIssues;
|
|
376
|
-
private createIssueNote;
|
|
377
|
-
private listPipelines;
|
|
378
|
-
private getPipeline;
|
|
379
|
-
private listPipelineJobs;
|
|
380
|
-
private getJobLog;
|
|
381
|
-
private retryJob;
|
|
382
|
-
private getFile;
|
|
383
|
-
private listCommits;
|
|
384
|
-
private getCommitDiff;
|
|
385
|
-
private listBranches;
|
|
386
|
-
private search;
|
|
387
|
-
private getProject;
|
|
388
|
-
private listProjectMembers;
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* Check if a tool name is a GitLab API tool
|
|
392
|
-
*/
|
|
393
|
-
declare function isGitLabApiTool(toolName: string): boolean;
|
|
394
|
-
|
|
395
385
|
/**
|
|
396
386
|
* Simple in-memory cache for GitLab project information
|
|
397
387
|
* Used to avoid repeated API calls when detecting projects from git remotes
|
|
@@ -522,4 +512,66 @@ declare class GitLabProjectDetector {
|
|
|
522
512
|
getCache(): GitLabProjectCache;
|
|
523
513
|
}
|
|
524
514
|
|
|
525
|
-
|
|
515
|
+
/**
|
|
516
|
+
* Response from /api/v4/ai/third_party_agents/direct_access
|
|
517
|
+
*/
|
|
518
|
+
declare const directAccessTokenSchema: z.ZodObject<{
|
|
519
|
+
headers: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
520
|
+
token: z.ZodString;
|
|
521
|
+
}, "strip", z.ZodTypeAny, {
|
|
522
|
+
headers?: Record<string, string>;
|
|
523
|
+
token?: string;
|
|
524
|
+
}, {
|
|
525
|
+
headers?: Record<string, string>;
|
|
526
|
+
token?: string;
|
|
527
|
+
}>;
|
|
528
|
+
type DirectAccessToken = z.infer<typeof directAccessTokenSchema>;
|
|
529
|
+
declare const DEFAULT_AI_GATEWAY_URL = "https://cloud.gitlab.com";
|
|
530
|
+
interface GitLabDirectAccessConfig {
|
|
531
|
+
instanceUrl: string;
|
|
532
|
+
getHeaders: () => Record<string, string>;
|
|
533
|
+
fetch?: typeof fetch;
|
|
534
|
+
/**
|
|
535
|
+
* Optional callback to refresh the API key when a 401 error occurs.
|
|
536
|
+
* Should clear cached credentials and re-fetch from auth provider.
|
|
537
|
+
*/
|
|
538
|
+
refreshApiKey?: () => Promise<void>;
|
|
539
|
+
/**
|
|
540
|
+
* Feature flags to pass to the GitLab API
|
|
541
|
+
*/
|
|
542
|
+
featureFlags?: Record<string, boolean>;
|
|
543
|
+
/**
|
|
544
|
+
* AI Gateway URL for the Anthropic proxy.
|
|
545
|
+
* Can also be set via GITLAB_AI_GATEWAY_URL environment variable.
|
|
546
|
+
* @default 'https://cloud.gitlab.com'
|
|
547
|
+
*/
|
|
548
|
+
aiGatewayUrl?: string;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Client for GitLab's third-party agents direct access API.
|
|
552
|
+
* This allows routing requests through GitLab's proxy to Anthropic.
|
|
553
|
+
*/
|
|
554
|
+
declare class GitLabDirectAccessClient {
|
|
555
|
+
private readonly config;
|
|
556
|
+
private readonly fetchFn;
|
|
557
|
+
private readonly aiGatewayUrl;
|
|
558
|
+
private cachedToken;
|
|
559
|
+
private tokenExpiresAt;
|
|
560
|
+
constructor(config: GitLabDirectAccessConfig);
|
|
561
|
+
/**
|
|
562
|
+
* Get a direct access token for the Anthropic proxy.
|
|
563
|
+
* Tokens are cached for 25 minutes (they expire after 30 minutes).
|
|
564
|
+
* @param forceRefresh - If true, ignores the cache and fetches a new token
|
|
565
|
+
*/
|
|
566
|
+
getDirectAccessToken(forceRefresh?: boolean): Promise<DirectAccessToken>;
|
|
567
|
+
/**
|
|
568
|
+
* Get the Anthropic proxy base URL
|
|
569
|
+
*/
|
|
570
|
+
getAnthropicProxyUrl(): string;
|
|
571
|
+
/**
|
|
572
|
+
* Invalidate the cached token
|
|
573
|
+
*/
|
|
574
|
+
invalidateToken(): void;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
export { BUNDLED_CLIENT_ID, DEFAULT_AI_GATEWAY_URL, type DirectAccessToken, GITLAB_COM_URL, type GitLabAgenticConfig, GitLabAgenticLanguageModel, type GitLabAgenticOptions, GitLabDirectAccessClient, type GitLabDirectAccessConfig, GitLabError, type GitLabErrorOptions, GitLabOAuthManager, type GitLabOAuthTokenResponse, type GitLabOAuthTokens, type GitLabProject, GitLabProjectCache, GitLabProjectDetector, type GitLabProjectDetectorConfig, type GitLabProvider, type GitLabProviderSettings, MODEL_ID_TO_ANTHROPIC_MODEL, OAUTH_SCOPES, type OpenCodeAuth, type OpenCodeAuthApi, type OpenCodeAuthOAuth, TOKEN_EXPIRY_SKEW_MS, createGitLab, getAnthropicModelForModelId, gitlab };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2Content, LanguageModelV2FinishReason, LanguageModelV2Usage, LanguageModelV2CallWarning, LanguageModelV2StreamPart } from '@ai-sdk/provider';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { Tool } from '@anthropic-ai/sdk/resources/messages';
|
|
4
3
|
|
|
5
4
|
interface GitLabAgenticConfig {
|
|
6
5
|
provider: string;
|
|
@@ -29,6 +28,12 @@ interface GitLabAgenticConfig {
|
|
|
29
28
|
featureFlags?: {
|
|
30
29
|
DuoAgentPlatformNext: true;
|
|
31
30
|
} & Record<string, boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* AI Gateway URL for the Anthropic proxy.
|
|
33
|
+
* Can also be set via GITLAB_AI_GATEWAY_URL environment variable.
|
|
34
|
+
* @default 'https://cloud.gitlab.com'
|
|
35
|
+
*/
|
|
36
|
+
aiGatewayUrl?: string;
|
|
32
37
|
}
|
|
33
38
|
/**
|
|
34
39
|
* GitLab Agentic Language Model
|
|
@@ -95,6 +100,24 @@ interface GitLabProvider {
|
|
|
95
100
|
readonly specificationVersion: 'v2';
|
|
96
101
|
languageModel(modelId: string): LanguageModelV2;
|
|
97
102
|
chat(modelId: string): LanguageModelV2;
|
|
103
|
+
/**
|
|
104
|
+
* Create an agentic chat model with tool calling support
|
|
105
|
+
*
|
|
106
|
+
* @param modelId - GitLab model identifier. Some IDs automatically map to specific Anthropic models.
|
|
107
|
+
* @param options - Configuration options for the agentic model
|
|
108
|
+
* @returns A language model with native tool calling support via Anthropic
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* // Automatic model mapping
|
|
112
|
+
* const model = gitlab.agenticChat('duo-chat-opus-4-5');
|
|
113
|
+
* // Uses claude-opus-4-5-20251101
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* // Explicit model override
|
|
117
|
+
* const model = gitlab.agenticChat('duo-chat', {
|
|
118
|
+
* anthropicModel: 'claude-sonnet-4-5-20250929'
|
|
119
|
+
* });
|
|
120
|
+
*/
|
|
98
121
|
agenticChat(modelId: string, options?: GitLabAgenticOptions): GitLabAgenticLanguageModel;
|
|
99
122
|
textEmbeddingModel(modelId: string): never;
|
|
100
123
|
imageModel(modelId: string): never;
|
|
@@ -102,7 +125,24 @@ interface GitLabProvider {
|
|
|
102
125
|
interface GitLabAgenticOptions {
|
|
103
126
|
/**
|
|
104
127
|
* The Anthropic model to use
|
|
105
|
-
*
|
|
128
|
+
*
|
|
129
|
+
* If not specified, automatically maps from the model ID:
|
|
130
|
+
* - 'duo-chat-opus-4-5' → 'claude-opus-4-5-20251101'
|
|
131
|
+
* - 'duo-chat-sonnet-4-5' → 'claude-sonnet-4-5-20250929'
|
|
132
|
+
* - 'duo-chat-haiku-4-5' → 'claude-haiku-4-5-20251001'
|
|
133
|
+
*
|
|
134
|
+
* For unmapped model IDs, defaults to 'claude-sonnet-4-5-20250929'
|
|
135
|
+
*
|
|
136
|
+
* @default Automatically mapped from model ID, or 'claude-sonnet-4-5-20250929'
|
|
137
|
+
* @example
|
|
138
|
+
* // Use automatic mapping
|
|
139
|
+
* const model = gitlab.agenticChat('duo-chat-opus-4-5');
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* // Override with explicit model
|
|
143
|
+
* const model = gitlab.agenticChat('duo-chat-opus-4-5', {
|
|
144
|
+
* anthropicModel: 'claude-sonnet-4-5-20250929'
|
|
145
|
+
* });
|
|
106
146
|
*/
|
|
107
147
|
anthropicModel?: string;
|
|
108
148
|
/**
|
|
@@ -154,6 +194,12 @@ interface GitLabProviderSettings {
|
|
|
154
194
|
* Default feature flags to pass to the GitLab API for all agentic chat models
|
|
155
195
|
*/
|
|
156
196
|
featureFlags?: Record<string, boolean>;
|
|
197
|
+
/**
|
|
198
|
+
* AI Gateway URL for the Anthropic proxy.
|
|
199
|
+
* Can also be set via GITLAB_AI_GATEWAY_URL environment variable.
|
|
200
|
+
* @default 'https://cloud.gitlab.com'
|
|
201
|
+
*/
|
|
202
|
+
aiGatewayUrl?: string;
|
|
157
203
|
}
|
|
158
204
|
declare function createGitLab(options?: GitLabProviderSettings): GitLabProvider;
|
|
159
205
|
/**
|
|
@@ -168,6 +214,33 @@ declare function createGitLab(options?: GitLabProviderSettings): GitLabProvider;
|
|
|
168
214
|
*/
|
|
169
215
|
declare const gitlab: GitLabProvider;
|
|
170
216
|
|
|
217
|
+
/**
|
|
218
|
+
* Maps GitLab model IDs to their corresponding Anthropic model identifiers.
|
|
219
|
+
*
|
|
220
|
+
* This mapping allows users to specify model variants by model ID without
|
|
221
|
+
* needing to manually configure the anthropicModel option.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* const model = gitlab.agenticChat('duo-chat-opus-4-5');
|
|
225
|
+
* // Automatically uses 'claude-opus-4-5-20251101'
|
|
226
|
+
*/
|
|
227
|
+
declare const MODEL_ID_TO_ANTHROPIC_MODEL: Record<string, string>;
|
|
228
|
+
/**
|
|
229
|
+
* Gets the Anthropic model identifier for a given GitLab model ID.
|
|
230
|
+
*
|
|
231
|
+
* @param modelId - The GitLab model ID (e.g., 'duo-chat-opus-4-5')
|
|
232
|
+
* @returns The Anthropic model identifier, or undefined if no mapping exists
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* getAnthropicModelForModelId('duo-chat-opus-4-5')
|
|
236
|
+
* // Returns: 'claude-opus-4-5-20251101'
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* getAnthropicModelForModelId('duo-chat')
|
|
240
|
+
* // Returns: undefined (uses default)
|
|
241
|
+
*/
|
|
242
|
+
declare function getAnthropicModelForModelId(modelId: string): string | undefined;
|
|
243
|
+
|
|
171
244
|
interface GitLabErrorOptions {
|
|
172
245
|
message: string;
|
|
173
246
|
statusCode?: number;
|
|
@@ -309,89 +382,6 @@ declare class GitLabOAuthManager {
|
|
|
309
382
|
private createExpiresTimestamp;
|
|
310
383
|
}
|
|
311
384
|
|
|
312
|
-
/**
|
|
313
|
-
* Tool definitions for Anthropic Claude
|
|
314
|
-
*/
|
|
315
|
-
declare const ANTHROPIC_TOOLS: Tool[];
|
|
316
|
-
interface ToolResult {
|
|
317
|
-
result: string;
|
|
318
|
-
error?: string;
|
|
319
|
-
}
|
|
320
|
-
interface ToolInput {
|
|
321
|
-
[key: string]: unknown;
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Tool executor for local file and command operations
|
|
325
|
-
*/
|
|
326
|
-
declare class AnthropicToolExecutor {
|
|
327
|
-
private readonly workingDirectory;
|
|
328
|
-
constructor(workingDirectory: string);
|
|
329
|
-
/**
|
|
330
|
-
* Execute a tool by name with given input
|
|
331
|
-
*/
|
|
332
|
-
execute(toolName: string, input: ToolInput): Promise<ToolResult>;
|
|
333
|
-
private resolvePath;
|
|
334
|
-
private listDir;
|
|
335
|
-
private readFile;
|
|
336
|
-
private writeFile;
|
|
337
|
-
private editFile;
|
|
338
|
-
private findFiles;
|
|
339
|
-
private mkdir;
|
|
340
|
-
private grep;
|
|
341
|
-
private runCommand;
|
|
342
|
-
private runGitCommand;
|
|
343
|
-
private executeCommand;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* GitLab API tools for interacting with GitLab resources
|
|
348
|
-
* These tools allow the AI to access merge requests, issues, pipelines, etc.
|
|
349
|
-
*/
|
|
350
|
-
declare const GITLAB_API_TOOLS: Tool[];
|
|
351
|
-
interface GitLabApiToolsConfig {
|
|
352
|
-
instanceUrl: string;
|
|
353
|
-
token: string;
|
|
354
|
-
fetch?: typeof fetch;
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Executor for GitLab API tools
|
|
358
|
-
*/
|
|
359
|
-
declare class GitLabApiToolExecutor {
|
|
360
|
-
private readonly config;
|
|
361
|
-
constructor(config: GitLabApiToolsConfig);
|
|
362
|
-
private get headers();
|
|
363
|
-
private fetchApi;
|
|
364
|
-
private encodeProjectId;
|
|
365
|
-
/**
|
|
366
|
-
* Execute a GitLab API tool by name
|
|
367
|
-
*/
|
|
368
|
-
execute(toolName: string, input: ToolInput): Promise<ToolResult>;
|
|
369
|
-
private getMergeRequest;
|
|
370
|
-
private listMergeRequests;
|
|
371
|
-
private getMrChanges;
|
|
372
|
-
private listMrDiscussions;
|
|
373
|
-
private createMrNote;
|
|
374
|
-
private getIssue;
|
|
375
|
-
private listIssues;
|
|
376
|
-
private createIssueNote;
|
|
377
|
-
private listPipelines;
|
|
378
|
-
private getPipeline;
|
|
379
|
-
private listPipelineJobs;
|
|
380
|
-
private getJobLog;
|
|
381
|
-
private retryJob;
|
|
382
|
-
private getFile;
|
|
383
|
-
private listCommits;
|
|
384
|
-
private getCommitDiff;
|
|
385
|
-
private listBranches;
|
|
386
|
-
private search;
|
|
387
|
-
private getProject;
|
|
388
|
-
private listProjectMembers;
|
|
389
|
-
}
|
|
390
|
-
/**
|
|
391
|
-
* Check if a tool name is a GitLab API tool
|
|
392
|
-
*/
|
|
393
|
-
declare function isGitLabApiTool(toolName: string): boolean;
|
|
394
|
-
|
|
395
385
|
/**
|
|
396
386
|
* Simple in-memory cache for GitLab project information
|
|
397
387
|
* Used to avoid repeated API calls when detecting projects from git remotes
|
|
@@ -522,4 +512,66 @@ declare class GitLabProjectDetector {
|
|
|
522
512
|
getCache(): GitLabProjectCache;
|
|
523
513
|
}
|
|
524
514
|
|
|
525
|
-
|
|
515
|
+
/**
|
|
516
|
+
* Response from /api/v4/ai/third_party_agents/direct_access
|
|
517
|
+
*/
|
|
518
|
+
declare const directAccessTokenSchema: z.ZodObject<{
|
|
519
|
+
headers: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
520
|
+
token: z.ZodString;
|
|
521
|
+
}, "strip", z.ZodTypeAny, {
|
|
522
|
+
headers?: Record<string, string>;
|
|
523
|
+
token?: string;
|
|
524
|
+
}, {
|
|
525
|
+
headers?: Record<string, string>;
|
|
526
|
+
token?: string;
|
|
527
|
+
}>;
|
|
528
|
+
type DirectAccessToken = z.infer<typeof directAccessTokenSchema>;
|
|
529
|
+
declare const DEFAULT_AI_GATEWAY_URL = "https://cloud.gitlab.com";
|
|
530
|
+
interface GitLabDirectAccessConfig {
|
|
531
|
+
instanceUrl: string;
|
|
532
|
+
getHeaders: () => Record<string, string>;
|
|
533
|
+
fetch?: typeof fetch;
|
|
534
|
+
/**
|
|
535
|
+
* Optional callback to refresh the API key when a 401 error occurs.
|
|
536
|
+
* Should clear cached credentials and re-fetch from auth provider.
|
|
537
|
+
*/
|
|
538
|
+
refreshApiKey?: () => Promise<void>;
|
|
539
|
+
/**
|
|
540
|
+
* Feature flags to pass to the GitLab API
|
|
541
|
+
*/
|
|
542
|
+
featureFlags?: Record<string, boolean>;
|
|
543
|
+
/**
|
|
544
|
+
* AI Gateway URL for the Anthropic proxy.
|
|
545
|
+
* Can also be set via GITLAB_AI_GATEWAY_URL environment variable.
|
|
546
|
+
* @default 'https://cloud.gitlab.com'
|
|
547
|
+
*/
|
|
548
|
+
aiGatewayUrl?: string;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Client for GitLab's third-party agents direct access API.
|
|
552
|
+
* This allows routing requests through GitLab's proxy to Anthropic.
|
|
553
|
+
*/
|
|
554
|
+
declare class GitLabDirectAccessClient {
|
|
555
|
+
private readonly config;
|
|
556
|
+
private readonly fetchFn;
|
|
557
|
+
private readonly aiGatewayUrl;
|
|
558
|
+
private cachedToken;
|
|
559
|
+
private tokenExpiresAt;
|
|
560
|
+
constructor(config: GitLabDirectAccessConfig);
|
|
561
|
+
/**
|
|
562
|
+
* Get a direct access token for the Anthropic proxy.
|
|
563
|
+
* Tokens are cached for 25 minutes (they expire after 30 minutes).
|
|
564
|
+
* @param forceRefresh - If true, ignores the cache and fetches a new token
|
|
565
|
+
*/
|
|
566
|
+
getDirectAccessToken(forceRefresh?: boolean): Promise<DirectAccessToken>;
|
|
567
|
+
/**
|
|
568
|
+
* Get the Anthropic proxy base URL
|
|
569
|
+
*/
|
|
570
|
+
getAnthropicProxyUrl(): string;
|
|
571
|
+
/**
|
|
572
|
+
* Invalidate the cached token
|
|
573
|
+
*/
|
|
574
|
+
invalidateToken(): void;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
export { BUNDLED_CLIENT_ID, DEFAULT_AI_GATEWAY_URL, type DirectAccessToken, GITLAB_COM_URL, type GitLabAgenticConfig, GitLabAgenticLanguageModel, type GitLabAgenticOptions, GitLabDirectAccessClient, type GitLabDirectAccessConfig, GitLabError, type GitLabErrorOptions, GitLabOAuthManager, type GitLabOAuthTokenResponse, type GitLabOAuthTokens, type GitLabProject, GitLabProjectCache, GitLabProjectDetector, type GitLabProjectDetectorConfig, type GitLabProvider, type GitLabProviderSettings, MODEL_ID_TO_ANTHROPIC_MODEL, OAUTH_SCOPES, type OpenCodeAuth, type OpenCodeAuthApi, type OpenCodeAuthOAuth, TOKEN_EXPIRY_SKEW_MS, createGitLab, getAnthropicModelForModelId, gitlab };
|