gitlab-ai-provider 6.1.1 → 6.2.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/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.1.0" : "0.0.0-dev";
1585
+ var VERSION = true ? "6.1.1" : "0.0.0-dev";
1586
1586
 
1587
1587
  // src/gitlab-workflow-types.ts
1588
1588
  var WorkflowType = /* @__PURE__ */ ((WorkflowType2) => {
@@ -2335,7 +2335,10 @@ var GitLabWorkflowTokenClient = class {
2335
2335
  workflow_definition: options?.workflowDefinition ?? DEFAULT_WORKFLOW_DEFINITION,
2336
2336
  agent_privileges: options?.agentPrivileges ?? DEFAULT_AGENT_PRIVILEGES,
2337
2337
  environment: options?.environment ?? WORKFLOW_ENVIRONMENT,
2338
- allow_agent_to_request_user: options?.allowAgentToRequestUser ?? true
2338
+ allow_agent_to_request_user: options?.allowAgentToRequestUser ?? true,
2339
+ ...options?.aiCatalogItemVersionId !== void 0 && {
2340
+ ai_catalog_item_version_id: options.aiCatalogItemVersionId
2341
+ }
2339
2342
  };
2340
2343
  try {
2341
2344
  const response = await this.fetchFn(url, {
@@ -2975,6 +2978,9 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
2975
2978
  // When DWS sends INPUT_REQUIRED, the workflow stays alive server-side.
2976
2979
  // On the next doStream() call we reuse this ID (skip createWorkflow).
2977
2980
  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
+ currentWorkflowDefinition = null;
2978
2984
  // Persisted across turns so that cumulative DWS chat logs don't re-emit
2979
2985
  // messages that were already streamed in a previous doStream() call.
2980
2986
  persistedAgentEmitted = /* @__PURE__ */ new Map();
@@ -3357,11 +3363,21 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
3357
3363
  const additionalContext = this.buildAdditionalContext(options.prompt);
3358
3364
  const toolExecutor = this.toolExecutor ?? null;
3359
3365
  const availableToolNames = new Set(options.tools?.map((t) => t.name) ?? []);
3366
+ const gitlabProviderOptions = options.providerOptions?.["gitlab"];
3367
+ const callWorkflowDefinition = gitlabProviderOptions?.workflowDefinition ?? this.workflowOptions.workflowDefinition;
3368
+ const callFlowConfig = gitlabProviderOptions?.flowConfig ?? void 0;
3369
+ const callFlowConfigSchemaVersion = gitlabProviderOptions?.flowConfigSchemaVersion ?? void 0;
3370
+ const callAiCatalogItemVersionId = gitlabProviderOptions?.aiCatalogItemVersionId ?? void 0;
3360
3371
  await this.tokenClient.getToken(
3361
- this.workflowOptions.workflowDefinition ?? DEFAULT_WORKFLOW_DEFINITION,
3372
+ callWorkflowDefinition ?? DEFAULT_WORKFLOW_DEFINITION,
3362
3373
  this.workflowOptions.rootNamespaceId
3363
3374
  );
3364
3375
  const projectId = await this.resolveProjectId();
3376
+ const effectiveDefinition = callFlowConfig ?? callWorkflowDefinition ?? DEFAULT_WORKFLOW_DEFINITION;
3377
+ if (this.currentWorkflowId && this.currentWorkflowDefinition !== effectiveDefinition) {
3378
+ this.currentWorkflowId = null;
3379
+ this.currentWorkflowDefinition = null;
3380
+ }
3365
3381
  let workflowId;
3366
3382
  if (this.currentWorkflowId) {
3367
3383
  workflowId = this.currentWorkflowId;
@@ -3369,10 +3385,12 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
3369
3385
  workflowId = await this.tokenClient.createWorkflow(goal, {
3370
3386
  projectId,
3371
3387
  namespaceId: this.workflowOptions.namespaceId,
3372
- workflowDefinition: this.workflowOptions.workflowDefinition,
3373
- agentPrivileges: this.workflowOptions.agentPrivileges
3388
+ workflowDefinition: callWorkflowDefinition,
3389
+ agentPrivileges: this.workflowOptions.agentPrivileges,
3390
+ aiCatalogItemVersionId: callAiCatalogItemVersionId
3374
3391
  });
3375
3392
  this.currentWorkflowId = workflowId;
3393
+ this.currentWorkflowDefinition = effectiveDefinition;
3376
3394
  }
3377
3395
  const wsClient = new GitLabWorkflowClient();
3378
3396
  this.activeClients.add(wsClient);
@@ -3427,7 +3445,7 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
3427
3445
  );
3428
3446
  }
3429
3447
  );
3430
- const workflowDef = this.workflowOptions.workflowDefinition ?? DEFAULT_WORKFLOW_DEFINITION;
3448
+ const workflowDef = callWorkflowDefinition ?? DEFAULT_WORKFLOW_DEFINITION;
3431
3449
  const capabilities = this.workflowOptions.clientCapabilities ?? DEFAULT_CLIENT_CAPABILITIES;
3432
3450
  const workflowMetadata = await this.buildWorkflowMetadata();
3433
3451
  const metadataStr = JSON.stringify(workflowMetadata);
@@ -3456,15 +3474,17 @@ var GitLabWorkflowLanguageModel = class _GitLabWorkflowLanguageModel {
3456
3474
  mcpTools: trimmed.mcpTools,
3457
3475
  preapproved_tools: trimmedPreapproved
3458
3476
  };
3459
- if (this.workflowOptions.flowConfig) {
3460
- startReq.flowConfig = this.workflowOptions.flowConfig;
3477
+ const resolvedFlowConfig = callFlowConfig ?? this.workflowOptions.flowConfig;
3478
+ const resolvedFlowConfigSchemaVersion = callFlowConfigSchemaVersion ?? this.workflowOptions.flowConfigSchemaVersion;
3479
+ if (resolvedFlowConfig) {
3480
+ startReq.flowConfig = resolvedFlowConfig;
3461
3481
  } else if (this.workflowOptions.systemPrompt) {
3462
3482
  startReq.flowConfig = {
3463
3483
  prompts: [{ prompt_template: { system: this.workflowOptions.systemPrompt } }]
3464
3484
  };
3465
3485
  }
3466
- if (this.workflowOptions.flowConfigSchemaVersion) {
3467
- startReq.flowConfigSchemaVersion = this.workflowOptions.flowConfigSchemaVersion;
3486
+ if (resolvedFlowConfigSchemaVersion) {
3487
+ startReq.flowConfigSchemaVersion = resolvedFlowConfigSchemaVersion;
3468
3488
  } else if (startReq.flowConfig) {
3469
3489
  startReq.flowConfigSchemaVersion = "v1";
3470
3490
  }