gitlab-ai-provider 6.2.1 → 6.4.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 +12 -0
- package/dist/gitlab-ai-provider-6.4.0.tgz +0 -0
- package/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +85 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/gitlab-ai-provider-6.2.1.tgz +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1582,7 +1582,7 @@ var GitLabOpenAILanguageModel = class {
|
|
|
1582
1582
|
import WebSocket from "isomorphic-ws";
|
|
1583
1583
|
|
|
1584
1584
|
// src/version.ts
|
|
1585
|
-
var VERSION = true ? "6.
|
|
1585
|
+
var VERSION = true ? "6.3.0" : "0.0.0-dev";
|
|
1586
1586
|
|
|
1587
1587
|
// src/gitlab-workflow-types.ts
|
|
1588
1588
|
var WorkflowType = /* @__PURE__ */ ((WorkflowType2) => {
|
|
@@ -1766,6 +1766,12 @@ var GitLabWorkflowClient = class {
|
|
|
1766
1766
|
if (options.modelRef && options.modelRef !== "default") {
|
|
1767
1767
|
url.searchParams.set("user_selected_model_identifier", options.modelRef);
|
|
1768
1768
|
}
|
|
1769
|
+
if (options.aiCatalogItemVersionId) {
|
|
1770
|
+
url.searchParams.set("ai_catalog_item_version_id", String(options.aiCatalogItemVersionId));
|
|
1771
|
+
}
|
|
1772
|
+
if (options.workflowDefinition) {
|
|
1773
|
+
url.searchParams.set("workflow_definition", options.workflowDefinition);
|
|
1774
|
+
}
|
|
1769
1775
|
return url.toString();
|
|
1770
1776
|
}
|
|
1771
1777
|
buildWebSocketHeaders(options) {
|
|
@@ -2975,14 +2981,12 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
2975
2981
|
// Cached detected project path
|
|
2976
2982
|
detectedProjectPath = null;
|
|
2977
2983
|
// Workflow ID persisted across turns for multi-turn conversations.
|
|
2978
|
-
//
|
|
2979
|
-
//
|
|
2984
|
+
// Per-session workflow state. Keyed by opencode sessionID (x-opencode-session header).
|
|
2985
|
+
// Each opencode session gets its own DWS workflow, reused across turns within that session.
|
|
2986
|
+
sessionWorkflows = /* @__PURE__ */ new Map();
|
|
2987
|
+
// Fallback for callers that don't pass x-opencode-session (e.g. direct SDK use).
|
|
2980
2988
|
currentWorkflowId = null;
|
|
2981
|
-
// Track which workflowDefinition/flowConfig the current workflow was created with.
|
|
2982
|
-
// When the agent changes, reset the workflow so a new one is created correctly.
|
|
2983
2989
|
currentWorkflowDefinition = null;
|
|
2984
|
-
// Persisted across turns so that cumulative DWS chat logs don't re-emit
|
|
2985
|
-
// messages that were already streamed in a previous doStream() call.
|
|
2986
2990
|
persistedAgentEmitted = /* @__PURE__ */ new Map();
|
|
2987
2991
|
// Track all active stream clients so stopWorkflow() can stop them all.
|
|
2988
2992
|
activeClients = /* @__PURE__ */ new Set();
|
|
@@ -3044,6 +3048,11 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3044
3048
|
* Updated when the user chooses "always" in the approval prompt.
|
|
3045
3049
|
*/
|
|
3046
3050
|
sessionPreapprovedTools = [];
|
|
3051
|
+
/**
|
|
3052
|
+
* The opencode session ID. Set per-stream by the host to key per-session
|
|
3053
|
+
* DWS workflows. Different sessions get different DWS workflows.
|
|
3054
|
+
*/
|
|
3055
|
+
sessionID = "";
|
|
3047
3056
|
/**
|
|
3048
3057
|
* Set the approval handler callback.
|
|
3049
3058
|
* Called when DWS requires tool call approval. Host (e.g., opencode) wires this
|
|
@@ -3273,9 +3282,14 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3273
3282
|
* Reset the workflow state, forcing a new workflow to be created on the
|
|
3274
3283
|
* next doStream() call. Call this when starting a new conversation.
|
|
3275
3284
|
*/
|
|
3276
|
-
resetWorkflow() {
|
|
3277
|
-
|
|
3278
|
-
|
|
3285
|
+
resetWorkflow(sessionKey) {
|
|
3286
|
+
if (sessionKey) {
|
|
3287
|
+
this.sessionWorkflows.delete(sessionKey);
|
|
3288
|
+
} else {
|
|
3289
|
+
this.sessionWorkflows.clear();
|
|
3290
|
+
this.currentWorkflowId = null;
|
|
3291
|
+
this.persistedAgentEmitted.clear();
|
|
3292
|
+
}
|
|
3279
3293
|
}
|
|
3280
3294
|
/**
|
|
3281
3295
|
* Get the current workflow ID (if any).
|
|
@@ -3374,12 +3388,21 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3374
3388
|
);
|
|
3375
3389
|
const projectId = await this.resolveProjectId();
|
|
3376
3390
|
const effectiveDefinition = callFlowConfig ?? callWorkflowDefinition ?? DEFAULT_WORKFLOW_DEFINITION;
|
|
3377
|
-
|
|
3391
|
+
const sessionKey = this.sessionID;
|
|
3392
|
+
let sess = this.sessionWorkflows.get(sessionKey);
|
|
3393
|
+
if (sess && sess.workflowDefinition !== effectiveDefinition) {
|
|
3394
|
+
this.sessionWorkflows.delete(sessionKey);
|
|
3395
|
+
sess = void 0;
|
|
3396
|
+
}
|
|
3397
|
+
const useLegacy = sessionKey === "";
|
|
3398
|
+
if (useLegacy && this.currentWorkflowId && this.currentWorkflowDefinition !== effectiveDefinition) {
|
|
3378
3399
|
this.currentWorkflowId = null;
|
|
3379
3400
|
this.currentWorkflowDefinition = null;
|
|
3380
3401
|
}
|
|
3381
3402
|
let workflowId;
|
|
3382
|
-
if (
|
|
3403
|
+
if (sess) {
|
|
3404
|
+
workflowId = sess.workflowId;
|
|
3405
|
+
} else if (useLegacy && this.currentWorkflowId) {
|
|
3383
3406
|
workflowId = this.currentWorkflowId;
|
|
3384
3407
|
} else {
|
|
3385
3408
|
workflowId = await this.tokenClient.createWorkflow(goal, {
|
|
@@ -3389,8 +3412,17 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3389
3412
|
agentPrivileges: this.workflowOptions.agentPrivileges,
|
|
3390
3413
|
aiCatalogItemVersionId: callAiCatalogItemVersionId
|
|
3391
3414
|
});
|
|
3392
|
-
|
|
3393
|
-
|
|
3415
|
+
if (useLegacy) {
|
|
3416
|
+
this.currentWorkflowId = workflowId;
|
|
3417
|
+
this.currentWorkflowDefinition = effectiveDefinition;
|
|
3418
|
+
} else {
|
|
3419
|
+
this.sessionWorkflows.set(sessionKey, {
|
|
3420
|
+
workflowId,
|
|
3421
|
+
workflowDefinition: effectiveDefinition,
|
|
3422
|
+
agentEmitted: /* @__PURE__ */ new Map()
|
|
3423
|
+
});
|
|
3424
|
+
sess = this.sessionWorkflows.get(sessionKey);
|
|
3425
|
+
}
|
|
3394
3426
|
}
|
|
3395
3427
|
const wsClient = new GitLabWorkflowClient();
|
|
3396
3428
|
this.activeClients.add(wsClient);
|
|
@@ -3403,10 +3435,11 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3403
3435
|
approvalPending: false,
|
|
3404
3436
|
deferredClose: null,
|
|
3405
3437
|
activeTextBlockId: null,
|
|
3406
|
-
agentMessageEmitted: new Map(this.persistedAgentEmitted),
|
|
3438
|
+
agentMessageEmitted: new Map(sess?.agentEmitted ?? this.persistedAgentEmitted),
|
|
3407
3439
|
currentAgentMessageId: "",
|
|
3408
3440
|
activeClient: wsClient,
|
|
3409
|
-
processedRequestIDs: /* @__PURE__ */ new Set()
|
|
3441
|
+
processedRequestIDs: /* @__PURE__ */ new Set(),
|
|
3442
|
+
sessionKey
|
|
3410
3443
|
};
|
|
3411
3444
|
for (const msg of options.prompt) {
|
|
3412
3445
|
if (msg.role === "system") {
|
|
@@ -3430,7 +3463,9 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3430
3463
|
headers: this.config.getHeaders(),
|
|
3431
3464
|
projectId: this.workflowOptions.projectId,
|
|
3432
3465
|
namespaceId: this.workflowOptions.namespaceId,
|
|
3433
|
-
rootNamespaceId: this.workflowOptions.rootNamespaceId
|
|
3466
|
+
rootNamespaceId: this.workflowOptions.rootNamespaceId,
|
|
3467
|
+
aiCatalogItemVersionId: callAiCatalogItemVersionId,
|
|
3468
|
+
workflowDefinition: callWorkflowDefinition ?? this.workflowOptions.workflowDefinition
|
|
3434
3469
|
},
|
|
3435
3470
|
(event) => {
|
|
3436
3471
|
this.handleWorkflowEvent(
|
|
@@ -3441,7 +3476,11 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3441
3476
|
toolExecutor,
|
|
3442
3477
|
() => `text-${textBlockCounter++}`,
|
|
3443
3478
|
availableToolNames,
|
|
3444
|
-
startReq
|
|
3479
|
+
startReq,
|
|
3480
|
+
{
|
|
3481
|
+
aiCatalogItemVersionId: callAiCatalogItemVersionId,
|
|
3482
|
+
workflowDefinition: callWorkflowDefinition ?? this.workflowOptions.workflowDefinition
|
|
3483
|
+
}
|
|
3445
3484
|
);
|
|
3446
3485
|
}
|
|
3447
3486
|
);
|
|
@@ -3517,7 +3556,13 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3517
3556
|
wsClient.close();
|
|
3518
3557
|
this.activeClients.delete(wsClient);
|
|
3519
3558
|
ss.activeClient = null;
|
|
3520
|
-
|
|
3559
|
+
if (!ss.streamClosed) {
|
|
3560
|
+
if (ss.sessionKey) {
|
|
3561
|
+
this.sessionWorkflows.delete(ss.sessionKey);
|
|
3562
|
+
} else {
|
|
3563
|
+
this.currentWorkflowId = null;
|
|
3564
|
+
}
|
|
3565
|
+
}
|
|
3521
3566
|
}
|
|
3522
3567
|
});
|
|
3523
3568
|
return {
|
|
@@ -3530,7 +3575,7 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3530
3575
|
// ---------------------------------------------------------------------------
|
|
3531
3576
|
// Event handling
|
|
3532
3577
|
// ---------------------------------------------------------------------------
|
|
3533
|
-
handleWorkflowEvent(ss, event, controller, wsClient, toolExecutor, nextTextId, availableToolNames, startReq) {
|
|
3578
|
+
handleWorkflowEvent(ss, event, controller, wsClient, toolExecutor, nextTextId, availableToolNames, startReq, wsExtras) {
|
|
3534
3579
|
if (ss.streamClosed) {
|
|
3535
3580
|
return;
|
|
3536
3581
|
}
|
|
@@ -3640,8 +3685,9 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3640
3685
|
controller,
|
|
3641
3686
|
toolExecutor,
|
|
3642
3687
|
nextTextId,
|
|
3643
|
-
availableToolNames
|
|
3644
|
-
|
|
3688
|
+
availableToolNames,
|
|
3689
|
+
wsExtras
|
|
3690
|
+
).catch((_err) => {
|
|
3645
3691
|
ss.approvalPending = false;
|
|
3646
3692
|
if (ss.deferredClose) {
|
|
3647
3693
|
const close = ss.deferredClose;
|
|
@@ -3667,7 +3713,7 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3667
3713
|
});
|
|
3668
3714
|
ss.streamClosed = true;
|
|
3669
3715
|
controller.close();
|
|
3670
|
-
this.cleanupClient(ss);
|
|
3716
|
+
this.cleanupClient(ss, false);
|
|
3671
3717
|
};
|
|
3672
3718
|
if (ss.pendingToolCount > 0 || ss.approvalPending) {
|
|
3673
3719
|
ss.deferredClose = doCompleteClose;
|
|
@@ -3725,7 +3771,7 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3725
3771
|
});
|
|
3726
3772
|
ss.streamClosed = true;
|
|
3727
3773
|
controller.close();
|
|
3728
|
-
this.cleanupClient(ss);
|
|
3774
|
+
this.cleanupClient(ss, false);
|
|
3729
3775
|
}
|
|
3730
3776
|
};
|
|
3731
3777
|
if (ss.pendingToolCount > 0 || ss.approvalPending) {
|
|
@@ -3794,7 +3840,8 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3794
3840
|
});
|
|
3795
3841
|
ss.streamedOutputChars += delta.length;
|
|
3796
3842
|
ss.agentMessageEmitted.set(msgId, content.length);
|
|
3797
|
-
this.
|
|
3843
|
+
const target = this.sessionWorkflows.get(ss.sessionKey)?.agentEmitted ?? this.persistedAgentEmitted;
|
|
3844
|
+
target.set(msgId, content.length);
|
|
3798
3845
|
ss.currentAgentMessageId = msgId;
|
|
3799
3846
|
}
|
|
3800
3847
|
}
|
|
@@ -3900,11 +3947,15 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3900
3947
|
ss.activeClient = null;
|
|
3901
3948
|
}
|
|
3902
3949
|
if (clearWorkflow) {
|
|
3903
|
-
|
|
3904
|
-
|
|
3950
|
+
if (ss.sessionKey) {
|
|
3951
|
+
this.sessionWorkflows.delete(ss.sessionKey);
|
|
3952
|
+
} else {
|
|
3953
|
+
this.currentWorkflowId = null;
|
|
3954
|
+
this.persistedAgentEmitted.clear();
|
|
3955
|
+
}
|
|
3905
3956
|
}
|
|
3906
3957
|
}
|
|
3907
|
-
async approveAndResume(ss, tools, startReq, controller, toolExecutor, nextTextId, availableToolNames) {
|
|
3958
|
+
async approveAndResume(ss, tools, startReq, controller, toolExecutor, nextTextId, availableToolNames, wsExtras) {
|
|
3908
3959
|
const handler = this.workflowOptions.approvalHandler;
|
|
3909
3960
|
if (!handler || !startReq) {
|
|
3910
3961
|
ss.approvalPending = false;
|
|
@@ -3924,6 +3975,7 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3924
3975
|
return;
|
|
3925
3976
|
}
|
|
3926
3977
|
ss.approvalPending = false;
|
|
3978
|
+
ss.deferredClose = null;
|
|
3927
3979
|
this.cleanupClient(ss, false);
|
|
3928
3980
|
const approval = decision.approved ? { approval: { tool_name: tools[0]?.name, tool_args_json: tools[0]?.args } } : { rejection: { message: decision.message ?? "User rejected" } };
|
|
3929
3981
|
const newStartReq = {
|
|
@@ -3943,7 +3995,9 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3943
3995
|
headers: this.config.getHeaders(),
|
|
3944
3996
|
projectId: this.workflowOptions.projectId,
|
|
3945
3997
|
namespaceId: this.workflowOptions.namespaceId,
|
|
3946
|
-
rootNamespaceId: this.workflowOptions.rootNamespaceId
|
|
3998
|
+
rootNamespaceId: this.workflowOptions.rootNamespaceId,
|
|
3999
|
+
aiCatalogItemVersionId: wsExtras?.aiCatalogItemVersionId,
|
|
4000
|
+
workflowDefinition: wsExtras?.workflowDefinition
|
|
3947
4001
|
},
|
|
3948
4002
|
(event) => this.handleWorkflowEvent(
|
|
3949
4003
|
ss,
|
|
@@ -3953,7 +4007,8 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
|
|
|
3953
4007
|
toolExecutor,
|
|
3954
4008
|
nextTextId,
|
|
3955
4009
|
availableToolNames,
|
|
3956
|
-
newStartReq
|
|
4010
|
+
newStartReq,
|
|
4011
|
+
wsExtras
|
|
3957
4012
|
)
|
|
3958
4013
|
);
|
|
3959
4014
|
newClient.sendStartRequest(newStartReq);
|