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.js
CHANGED
|
@@ -41,6 +41,7 @@ __export(index_exports, {
|
|
|
41
41
|
GitLabDirectAccessClient: () => GitLabDirectAccessClient,
|
|
42
42
|
GitLabError: () => GitLabError,
|
|
43
43
|
GitLabModelCache: () => GitLabModelCache,
|
|
44
|
+
GitLabModelConfigRegistry: () => GitLabModelConfigRegistry,
|
|
44
45
|
GitLabModelDiscovery: () => GitLabModelDiscovery,
|
|
45
46
|
GitLabOAuthManager: () => GitLabOAuthManager,
|
|
46
47
|
GitLabOpenAILanguageModel: () => GitLabOpenAILanguageModel,
|
|
@@ -69,7 +70,8 @@ __export(index_exports, {
|
|
|
69
70
|
getWorkflowModelRef: () => getWorkflowModelRef,
|
|
70
71
|
gitlab: () => gitlab,
|
|
71
72
|
isResponsesApiModel: () => isResponsesApiModel,
|
|
72
|
-
isWorkflowModel: () => isWorkflowModel
|
|
73
|
+
isWorkflowModel: () => isWorkflowModel,
|
|
74
|
+
parseModelsYml: () => parseModelsYml
|
|
73
75
|
});
|
|
74
76
|
module.exports = __toCommonJS(index_exports);
|
|
75
77
|
|
|
@@ -357,7 +359,8 @@ var GitLabAnthropicLanguageModel = class {
|
|
|
357
359
|
const messages = [];
|
|
358
360
|
for (const message of prompt) {
|
|
359
361
|
if (message.role === "system") {
|
|
360
|
-
systemMessage =
|
|
362
|
+
systemMessage = systemMessage ? `${systemMessage}
|
|
363
|
+
${message.content}` : message.content;
|
|
361
364
|
continue;
|
|
362
365
|
}
|
|
363
366
|
if (message.role === "user") {
|
|
@@ -1573,7 +1576,7 @@ var GitLabOpenAILanguageModel = class {
|
|
|
1573
1576
|
var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
|
|
1574
1577
|
|
|
1575
1578
|
// src/version.ts
|
|
1576
|
-
var VERSION = true ? "
|
|
1579
|
+
var VERSION = true ? "5.0.0" : "0.0.0-dev";
|
|
1577
1580
|
|
|
1578
1581
|
// src/gitlab-workflow-types.ts
|
|
1579
1582
|
var WorkflowType = /* @__PURE__ */ ((WorkflowType2) => {
|
|
@@ -4242,6 +4245,170 @@ function createGitLab(options = {}) {
|
|
|
4242
4245
|
return provider;
|
|
4243
4246
|
}
|
|
4244
4247
|
var gitlab = createGitLab();
|
|
4248
|
+
|
|
4249
|
+
// src/gitlab-model-config.ts
|
|
4250
|
+
var fs3 = __toESM(require("fs"));
|
|
4251
|
+
var path4 = __toESM(require("path"));
|
|
4252
|
+
var os3 = __toESM(require("os"));
|
|
4253
|
+
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";
|
|
4254
|
+
var DEFAULT_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
4255
|
+
var DEFAULT_CONTEXT = 2e5;
|
|
4256
|
+
var DEFAULT_OUTPUT = 64e3;
|
|
4257
|
+
function getCacheFilePath2() {
|
|
4258
|
+
const cacheHome = process.env.XDG_CACHE_HOME || path4.join(os3.homedir(), ".cache");
|
|
4259
|
+
return path4.join(cacheHome, "opencode", "gitlab-model-configs.json");
|
|
4260
|
+
}
|
|
4261
|
+
function readCacheFile() {
|
|
4262
|
+
try {
|
|
4263
|
+
const filePath = getCacheFilePath2();
|
|
4264
|
+
if (!fs3.existsSync(filePath)) return null;
|
|
4265
|
+
const raw = fs3.readFileSync(filePath, "utf-8");
|
|
4266
|
+
return JSON.parse(raw);
|
|
4267
|
+
} catch {
|
|
4268
|
+
return null;
|
|
4269
|
+
}
|
|
4270
|
+
}
|
|
4271
|
+
function writeCacheFile(configs) {
|
|
4272
|
+
try {
|
|
4273
|
+
const filePath = getCacheFilePath2();
|
|
4274
|
+
const dir = path4.dirname(filePath);
|
|
4275
|
+
fs3.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
4276
|
+
const data = {
|
|
4277
|
+
configs: Object.fromEntries(configs),
|
|
4278
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4279
|
+
};
|
|
4280
|
+
fs3.writeFileSync(filePath, JSON.stringify(data, null, 2), { mode: 384 });
|
|
4281
|
+
} catch {
|
|
4282
|
+
}
|
|
4283
|
+
}
|
|
4284
|
+
function loadCacheFile(ttlMs) {
|
|
4285
|
+
const cached = readCacheFile();
|
|
4286
|
+
if (!cached) return null;
|
|
4287
|
+
const writtenAt = new Date(cached.updatedAt).getTime();
|
|
4288
|
+
const age = Date.now() - writtenAt;
|
|
4289
|
+
if (age > ttlMs) return null;
|
|
4290
|
+
return { configs: new Map(Object.entries(cached.configs)), writtenAt };
|
|
4291
|
+
}
|
|
4292
|
+
var GitLabModelConfigRegistry = class {
|
|
4293
|
+
url;
|
|
4294
|
+
ttlMs;
|
|
4295
|
+
fetchFn;
|
|
4296
|
+
memCache = null;
|
|
4297
|
+
memExpiresAt = 0;
|
|
4298
|
+
pending = null;
|
|
4299
|
+
constructor(options) {
|
|
4300
|
+
this.url = options?.url ?? DEFAULT_MODELS_YML_URL;
|
|
4301
|
+
this.ttlMs = options?.ttlMs ?? DEFAULT_TTL_MS;
|
|
4302
|
+
this.fetchFn = options?.fetch ?? fetch;
|
|
4303
|
+
}
|
|
4304
|
+
/**
|
|
4305
|
+
* Get model configs, fetching and caching as needed.
|
|
4306
|
+
* Returns a Map keyed by `gitlab_identifier` (the discovery `ref`).
|
|
4307
|
+
*/
|
|
4308
|
+
async getConfigs() {
|
|
4309
|
+
if (this.memCache && Date.now() < this.memExpiresAt) {
|
|
4310
|
+
return this.memCache;
|
|
4311
|
+
}
|
|
4312
|
+
const fileCached = loadCacheFile(this.ttlMs);
|
|
4313
|
+
if (fileCached) {
|
|
4314
|
+
this.memCache = fileCached.configs;
|
|
4315
|
+
this.memExpiresAt = fileCached.writtenAt + this.ttlMs;
|
|
4316
|
+
return fileCached.configs;
|
|
4317
|
+
}
|
|
4318
|
+
if (this.pending) return this.pending;
|
|
4319
|
+
this.pending = this.fetchConfigs();
|
|
4320
|
+
try {
|
|
4321
|
+
return await this.pending;
|
|
4322
|
+
} finally {
|
|
4323
|
+
this.pending = null;
|
|
4324
|
+
}
|
|
4325
|
+
}
|
|
4326
|
+
/**
|
|
4327
|
+
* Look up config for a single model ref.
|
|
4328
|
+
* Returns defaults if the ref is not found or fetch fails.
|
|
4329
|
+
*/
|
|
4330
|
+
async getConfig(ref) {
|
|
4331
|
+
const configs = await this.getConfigs();
|
|
4332
|
+
return configs.get(ref) ?? { context: DEFAULT_CONTEXT, output: DEFAULT_OUTPUT };
|
|
4333
|
+
}
|
|
4334
|
+
/** Invalidate both in-memory and file caches. */
|
|
4335
|
+
invalidateCache() {
|
|
4336
|
+
this.memCache = null;
|
|
4337
|
+
this.memExpiresAt = 0;
|
|
4338
|
+
try {
|
|
4339
|
+
const filePath = getCacheFilePath2();
|
|
4340
|
+
if (fs3.existsSync(filePath)) {
|
|
4341
|
+
fs3.unlinkSync(filePath);
|
|
4342
|
+
}
|
|
4343
|
+
} catch {
|
|
4344
|
+
}
|
|
4345
|
+
}
|
|
4346
|
+
async fetchConfigs() {
|
|
4347
|
+
try {
|
|
4348
|
+
const res = await this.fetchFn(this.url);
|
|
4349
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
4350
|
+
const text = await res.text();
|
|
4351
|
+
const configs = parseModelsYml(text);
|
|
4352
|
+
this.memCache = configs;
|
|
4353
|
+
this.memExpiresAt = Date.now() + this.ttlMs;
|
|
4354
|
+
writeCacheFile(configs);
|
|
4355
|
+
return configs;
|
|
4356
|
+
} catch {
|
|
4357
|
+
return this.memCache ?? loadCacheFile(Infinity)?.configs ?? /* @__PURE__ */ new Map();
|
|
4358
|
+
}
|
|
4359
|
+
}
|
|
4360
|
+
};
|
|
4361
|
+
function parseModelsYml(text) {
|
|
4362
|
+
const configs = /* @__PURE__ */ new Map();
|
|
4363
|
+
let currentIdentifier = null;
|
|
4364
|
+
let currentContext = 0;
|
|
4365
|
+
let currentOutput = 0;
|
|
4366
|
+
let inParams = false;
|
|
4367
|
+
let paramsIndent = -1;
|
|
4368
|
+
for (const line of text.split("\n")) {
|
|
4369
|
+
const idMatch = line.match(/^\s*gitlab_identifier:\s*"?([^"#\s]+)"?/);
|
|
4370
|
+
if (idMatch) {
|
|
4371
|
+
if (currentIdentifier) {
|
|
4372
|
+
configs.set(currentIdentifier, {
|
|
4373
|
+
context: currentContext || DEFAULT_CONTEXT,
|
|
4374
|
+
output: currentOutput || DEFAULT_OUTPUT
|
|
4375
|
+
});
|
|
4376
|
+
}
|
|
4377
|
+
currentIdentifier = idMatch[1];
|
|
4378
|
+
currentContext = 0;
|
|
4379
|
+
currentOutput = 0;
|
|
4380
|
+
inParams = false;
|
|
4381
|
+
paramsIndent = -1;
|
|
4382
|
+
}
|
|
4383
|
+
const ctxMatch = line.match(/^\s*max_context_tokens:\s*([0-9_]+)/);
|
|
4384
|
+
if (ctxMatch && currentIdentifier) {
|
|
4385
|
+
currentContext = parseInt(ctxMatch[1].replace(/_/g, ""), 10);
|
|
4386
|
+
}
|
|
4387
|
+
if (/^\s*params:\s*$/.test(line)) {
|
|
4388
|
+
inParams = true;
|
|
4389
|
+
paramsIndent = line.match(/^(\s*)/)?.[1].length ?? 0;
|
|
4390
|
+
} else if (inParams && /^\s*\S+:/.test(line)) {
|
|
4391
|
+
const indent = line.match(/^(\s*)/)?.[1].length ?? 0;
|
|
4392
|
+
if (indent <= paramsIndent) {
|
|
4393
|
+
inParams = false;
|
|
4394
|
+
paramsIndent = -1;
|
|
4395
|
+
}
|
|
4396
|
+
}
|
|
4397
|
+
if (inParams) {
|
|
4398
|
+
const maxTokensMatch = line.match(/^\s*max_tokens:\s*([0-9_]+)/);
|
|
4399
|
+
if (maxTokensMatch && currentIdentifier) {
|
|
4400
|
+
currentOutput = parseInt(maxTokensMatch[1].replace(/_/g, ""), 10);
|
|
4401
|
+
}
|
|
4402
|
+
}
|
|
4403
|
+
}
|
|
4404
|
+
if (currentIdentifier) {
|
|
4405
|
+
configs.set(currentIdentifier, {
|
|
4406
|
+
context: currentContext || DEFAULT_CONTEXT,
|
|
4407
|
+
output: currentOutput || DEFAULT_OUTPUT
|
|
4408
|
+
});
|
|
4409
|
+
}
|
|
4410
|
+
return configs;
|
|
4411
|
+
}
|
|
4245
4412
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4246
4413
|
0 && (module.exports = {
|
|
4247
4414
|
AGENT_PRIVILEGES,
|
|
@@ -4256,6 +4423,7 @@ var gitlab = createGitLab();
|
|
|
4256
4423
|
GitLabDirectAccessClient,
|
|
4257
4424
|
GitLabError,
|
|
4258
4425
|
GitLabModelCache,
|
|
4426
|
+
GitLabModelConfigRegistry,
|
|
4259
4427
|
GitLabModelDiscovery,
|
|
4260
4428
|
GitLabOAuthManager,
|
|
4261
4429
|
GitLabOpenAILanguageModel,
|
|
@@ -4284,6 +4452,7 @@ var gitlab = createGitLab();
|
|
|
4284
4452
|
getWorkflowModelRef,
|
|
4285
4453
|
gitlab,
|
|
4286
4454
|
isResponsesApiModel,
|
|
4287
|
-
isWorkflowModel
|
|
4455
|
+
isWorkflowModel,
|
|
4456
|
+
parseModelsYml
|
|
4288
4457
|
});
|
|
4289
4458
|
//# sourceMappingURL=index.js.map
|