gitlab-ai-provider 5.0.0 → 5.1.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 +5 -0
- package/dist/gitlab-ai-provider-5.1.0.tgz +0 -0
- package/dist/index.d.mts +54 -1
- package/dist/index.d.ts +1212 -1296
- package/dist/index.js +173 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +170 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -289,7 +289,8 @@ var GitLabAnthropicLanguageModel = class {
|
|
|
289
289
|
const messages = [];
|
|
290
290
|
for (const message of prompt) {
|
|
291
291
|
if (message.role === "system") {
|
|
292
|
-
systemMessage =
|
|
292
|
+
systemMessage = systemMessage ? `${systemMessage}
|
|
293
|
+
${message.content}` : message.content;
|
|
293
294
|
continue;
|
|
294
295
|
}
|
|
295
296
|
if (message.role === "user") {
|
|
@@ -1505,7 +1506,7 @@ var GitLabOpenAILanguageModel = class {
|
|
|
1505
1506
|
import WebSocket from "isomorphic-ws";
|
|
1506
1507
|
|
|
1507
1508
|
// src/version.ts
|
|
1508
|
-
var VERSION = true ? "
|
|
1509
|
+
var VERSION = true ? "5.0.0" : "0.0.0-dev";
|
|
1509
1510
|
|
|
1510
1511
|
// src/gitlab-workflow-types.ts
|
|
1511
1512
|
var WorkflowType = /* @__PURE__ */ ((WorkflowType2) => {
|
|
@@ -4174,6 +4175,170 @@ function createGitLab(options = {}) {
|
|
|
4174
4175
|
return provider;
|
|
4175
4176
|
}
|
|
4176
4177
|
var gitlab = createGitLab();
|
|
4178
|
+
|
|
4179
|
+
// src/gitlab-model-config.ts
|
|
4180
|
+
import * as fs3 from "fs";
|
|
4181
|
+
import * as path4 from "path";
|
|
4182
|
+
import * as os3 from "os";
|
|
4183
|
+
var DEFAULT_MODELS_YML_URL = "https://gitlab.com/gitlab-org/modelops/applied-ml/code-suggestions/ai-assist/-/raw/main/ai_gateway/model_selection/models.yml";
|
|
4184
|
+
var DEFAULT_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
4185
|
+
var DEFAULT_CONTEXT = 2e5;
|
|
4186
|
+
var DEFAULT_OUTPUT = 64e3;
|
|
4187
|
+
function getCacheFilePath2() {
|
|
4188
|
+
const cacheHome = process.env.XDG_CACHE_HOME || path4.join(os3.homedir(), ".cache");
|
|
4189
|
+
return path4.join(cacheHome, "opencode", "gitlab-model-configs.json");
|
|
4190
|
+
}
|
|
4191
|
+
function readCacheFile() {
|
|
4192
|
+
try {
|
|
4193
|
+
const filePath = getCacheFilePath2();
|
|
4194
|
+
if (!fs3.existsSync(filePath)) return null;
|
|
4195
|
+
const raw = fs3.readFileSync(filePath, "utf-8");
|
|
4196
|
+
return JSON.parse(raw);
|
|
4197
|
+
} catch {
|
|
4198
|
+
return null;
|
|
4199
|
+
}
|
|
4200
|
+
}
|
|
4201
|
+
function writeCacheFile(configs) {
|
|
4202
|
+
try {
|
|
4203
|
+
const filePath = getCacheFilePath2();
|
|
4204
|
+
const dir = path4.dirname(filePath);
|
|
4205
|
+
fs3.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
4206
|
+
const data = {
|
|
4207
|
+
configs: Object.fromEntries(configs),
|
|
4208
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4209
|
+
};
|
|
4210
|
+
fs3.writeFileSync(filePath, JSON.stringify(data, null, 2), { mode: 384 });
|
|
4211
|
+
} catch {
|
|
4212
|
+
}
|
|
4213
|
+
}
|
|
4214
|
+
function loadCacheFile(ttlMs) {
|
|
4215
|
+
const cached = readCacheFile();
|
|
4216
|
+
if (!cached) return null;
|
|
4217
|
+
const writtenAt = new Date(cached.updatedAt).getTime();
|
|
4218
|
+
const age = Date.now() - writtenAt;
|
|
4219
|
+
if (age > ttlMs) return null;
|
|
4220
|
+
return { configs: new Map(Object.entries(cached.configs)), writtenAt };
|
|
4221
|
+
}
|
|
4222
|
+
var GitLabModelConfigRegistry = class {
|
|
4223
|
+
url;
|
|
4224
|
+
ttlMs;
|
|
4225
|
+
fetchFn;
|
|
4226
|
+
memCache = null;
|
|
4227
|
+
memExpiresAt = 0;
|
|
4228
|
+
pending = null;
|
|
4229
|
+
constructor(options) {
|
|
4230
|
+
this.url = options?.url ?? DEFAULT_MODELS_YML_URL;
|
|
4231
|
+
this.ttlMs = options?.ttlMs ?? DEFAULT_TTL_MS;
|
|
4232
|
+
this.fetchFn = options?.fetch ?? fetch;
|
|
4233
|
+
}
|
|
4234
|
+
/**
|
|
4235
|
+
* Get model configs, fetching and caching as needed.
|
|
4236
|
+
* Returns a Map keyed by `gitlab_identifier` (the discovery `ref`).
|
|
4237
|
+
*/
|
|
4238
|
+
async getConfigs() {
|
|
4239
|
+
if (this.memCache && Date.now() < this.memExpiresAt) {
|
|
4240
|
+
return this.memCache;
|
|
4241
|
+
}
|
|
4242
|
+
const fileCached = loadCacheFile(this.ttlMs);
|
|
4243
|
+
if (fileCached) {
|
|
4244
|
+
this.memCache = fileCached.configs;
|
|
4245
|
+
this.memExpiresAt = fileCached.writtenAt + this.ttlMs;
|
|
4246
|
+
return fileCached.configs;
|
|
4247
|
+
}
|
|
4248
|
+
if (this.pending) return this.pending;
|
|
4249
|
+
this.pending = this.fetchConfigs();
|
|
4250
|
+
try {
|
|
4251
|
+
return await this.pending;
|
|
4252
|
+
} finally {
|
|
4253
|
+
this.pending = null;
|
|
4254
|
+
}
|
|
4255
|
+
}
|
|
4256
|
+
/**
|
|
4257
|
+
* Look up config for a single model ref.
|
|
4258
|
+
* Returns defaults if the ref is not found or fetch fails.
|
|
4259
|
+
*/
|
|
4260
|
+
async getConfig(ref) {
|
|
4261
|
+
const configs = await this.getConfigs();
|
|
4262
|
+
return configs.get(ref) ?? { context: DEFAULT_CONTEXT, output: DEFAULT_OUTPUT };
|
|
4263
|
+
}
|
|
4264
|
+
/** Invalidate both in-memory and file caches. */
|
|
4265
|
+
invalidateCache() {
|
|
4266
|
+
this.memCache = null;
|
|
4267
|
+
this.memExpiresAt = 0;
|
|
4268
|
+
try {
|
|
4269
|
+
const filePath = getCacheFilePath2();
|
|
4270
|
+
if (fs3.existsSync(filePath)) {
|
|
4271
|
+
fs3.unlinkSync(filePath);
|
|
4272
|
+
}
|
|
4273
|
+
} catch {
|
|
4274
|
+
}
|
|
4275
|
+
}
|
|
4276
|
+
async fetchConfigs() {
|
|
4277
|
+
try {
|
|
4278
|
+
const res = await this.fetchFn(this.url);
|
|
4279
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
4280
|
+
const text = await res.text();
|
|
4281
|
+
const configs = parseModelsYml(text);
|
|
4282
|
+
this.memCache = configs;
|
|
4283
|
+
this.memExpiresAt = Date.now() + this.ttlMs;
|
|
4284
|
+
writeCacheFile(configs);
|
|
4285
|
+
return configs;
|
|
4286
|
+
} catch {
|
|
4287
|
+
return this.memCache ?? loadCacheFile(Infinity)?.configs ?? /* @__PURE__ */ new Map();
|
|
4288
|
+
}
|
|
4289
|
+
}
|
|
4290
|
+
};
|
|
4291
|
+
function parseModelsYml(text) {
|
|
4292
|
+
const configs = /* @__PURE__ */ new Map();
|
|
4293
|
+
let currentIdentifier = null;
|
|
4294
|
+
let currentContext = 0;
|
|
4295
|
+
let currentOutput = 0;
|
|
4296
|
+
let inParams = false;
|
|
4297
|
+
let paramsIndent = -1;
|
|
4298
|
+
for (const line of text.split("\n")) {
|
|
4299
|
+
const idMatch = line.match(/^\s*gitlab_identifier:\s*"?([^"#\s]+)"?/);
|
|
4300
|
+
if (idMatch) {
|
|
4301
|
+
if (currentIdentifier) {
|
|
4302
|
+
configs.set(currentIdentifier, {
|
|
4303
|
+
context: currentContext || DEFAULT_CONTEXT,
|
|
4304
|
+
output: currentOutput || DEFAULT_OUTPUT
|
|
4305
|
+
});
|
|
4306
|
+
}
|
|
4307
|
+
currentIdentifier = idMatch[1];
|
|
4308
|
+
currentContext = 0;
|
|
4309
|
+
currentOutput = 0;
|
|
4310
|
+
inParams = false;
|
|
4311
|
+
paramsIndent = -1;
|
|
4312
|
+
}
|
|
4313
|
+
const ctxMatch = line.match(/^\s*max_context_tokens:\s*([0-9_]+)/);
|
|
4314
|
+
if (ctxMatch && currentIdentifier) {
|
|
4315
|
+
currentContext = parseInt(ctxMatch[1].replace(/_/g, ""), 10);
|
|
4316
|
+
}
|
|
4317
|
+
if (/^\s*params:\s*$/.test(line)) {
|
|
4318
|
+
inParams = true;
|
|
4319
|
+
paramsIndent = line.match(/^(\s*)/)?.[1].length ?? 0;
|
|
4320
|
+
} else if (inParams && /^\s*\S+:/.test(line)) {
|
|
4321
|
+
const indent = line.match(/^(\s*)/)?.[1].length ?? 0;
|
|
4322
|
+
if (indent <= paramsIndent) {
|
|
4323
|
+
inParams = false;
|
|
4324
|
+
paramsIndent = -1;
|
|
4325
|
+
}
|
|
4326
|
+
}
|
|
4327
|
+
if (inParams) {
|
|
4328
|
+
const maxTokensMatch = line.match(/^\s*max_tokens:\s*([0-9_]+)/);
|
|
4329
|
+
if (maxTokensMatch && currentIdentifier) {
|
|
4330
|
+
currentOutput = parseInt(maxTokensMatch[1].replace(/_/g, ""), 10);
|
|
4331
|
+
}
|
|
4332
|
+
}
|
|
4333
|
+
}
|
|
4334
|
+
if (currentIdentifier) {
|
|
4335
|
+
configs.set(currentIdentifier, {
|
|
4336
|
+
context: currentContext || DEFAULT_CONTEXT,
|
|
4337
|
+
output: currentOutput || DEFAULT_OUTPUT
|
|
4338
|
+
});
|
|
4339
|
+
}
|
|
4340
|
+
return configs;
|
|
4341
|
+
}
|
|
4177
4342
|
export {
|
|
4178
4343
|
AGENT_PRIVILEGES,
|
|
4179
4344
|
BUNDLED_CLIENT_ID,
|
|
@@ -4187,6 +4352,7 @@ export {
|
|
|
4187
4352
|
GitLabDirectAccessClient,
|
|
4188
4353
|
GitLabError,
|
|
4189
4354
|
GitLabModelCache,
|
|
4355
|
+
GitLabModelConfigRegistry,
|
|
4190
4356
|
GitLabModelDiscovery,
|
|
4191
4357
|
GitLabOAuthManager,
|
|
4192
4358
|
GitLabOpenAILanguageModel,
|
|
@@ -4215,6 +4381,7 @@ export {
|
|
|
4215
4381
|
getWorkflowModelRef,
|
|
4216
4382
|
gitlab,
|
|
4217
4383
|
isResponsesApiModel,
|
|
4218
|
-
isWorkflowModel
|
|
4384
|
+
isWorkflowModel,
|
|
4385
|
+
parseModelsYml
|
|
4219
4386
|
};
|
|
4220
4387
|
//# sourceMappingURL=index.mjs.map
|