opencode-gitlab-duo-agentic 0.1.20 → 0.1.22

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.
Files changed (2) hide show
  1. package/dist/index.js +21 -25
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -319,13 +319,23 @@ function toModelsConfig(available) {
319
319
  }
320
320
 
321
321
  // src/plugin/hooks.ts
322
- var UTILITY_AGENTS = /* @__PURE__ */ new Set(["title", "compaction", "summary"]);
323
322
  async function createPluginHooks(input) {
324
323
  return {
325
324
  config: async (config) => applyRuntimeConfig(config, input.directory),
325
+ "chat.message": async ({ sessionID }, { parts }) => {
326
+ const text2 = parts.filter((p) => p.type === "text" && !("synthetic" in p && p.synthetic)).map((p) => "text" in p ? p.text : "").join(" ").trim();
327
+ if (!text2) return;
328
+ const title = text2.length > 100 ? text2.slice(0, 97) + "..." : text2;
329
+ const url = new URL(`/session/${encodeURIComponent(sessionID)}`, input.serverUrl);
330
+ await fetch(url, {
331
+ method: "PATCH",
332
+ headers: { "content-type": "application/json" },
333
+ body: JSON.stringify({ title })
334
+ }).catch(() => {
335
+ });
336
+ },
326
337
  "chat.params": async (context, output) => {
327
338
  if (!isGitLabProvider(context.model)) return;
328
- if (isUtilityAgent(context.agent)) return;
329
339
  output.options = {
330
340
  ...output.options,
331
341
  workflowSessionID: context.sessionID
@@ -333,7 +343,6 @@ async function createPluginHooks(input) {
333
343
  },
334
344
  "chat.headers": async (context, output) => {
335
345
  if (!isGitLabProvider(context.model)) return;
336
- if (isUtilityAgent(context.agent)) return;
337
346
  output.headers = {
338
347
  ...output.headers,
339
348
  "x-opencode-session": context.sessionID
@@ -341,12 +350,6 @@ async function createPluginHooks(input) {
341
350
  }
342
351
  };
343
352
  }
344
- function isUtilityAgent(agent) {
345
- if (typeof agent === "string") return UTILITY_AGENTS.has(agent);
346
- if (agent && typeof agent === "object" && "name" in agent && typeof agent.name === "string")
347
- return UTILITY_AGENTS.has(agent.name);
348
- return false;
349
- }
350
353
  function isGitLabProvider(model) {
351
354
  if (model.api?.npm === "opencode-gitlab-duo-agentic") return true;
352
355
  if (model.providerID === "gitlab" && model.api?.npm !== "@gitlab/gitlab-ai-provider") return true;
@@ -737,9 +740,11 @@ var DuoWorkflowModel = class {
737
740
  this.#client = client;
738
741
  }
739
742
  async doGenerate(options) {
743
+ const sessionID = readSessionID(options);
744
+ if (!sessionID) throw new Error("missing workflow session ID");
740
745
  const goal = extractGoal(options.prompt);
741
746
  if (!goal) throw new Error("missing user message content");
742
- const session = this.#resolveSession(options);
747
+ const session = this.#resolveSession(sessionID);
743
748
  const chunks = [];
744
749
  for await (const item of session.runTurn(goal, options.abortSignal)) {
745
750
  if (item.type === "text-delta") chunks.push(item.value);
@@ -761,9 +766,11 @@ var DuoWorkflowModel = class {
761
766
  };
762
767
  }
763
768
  async doStream(options) {
769
+ const sessionID = readSessionID(options);
770
+ if (!sessionID) throw new Error("missing workflow session ID");
764
771
  const goal = extractGoal(options.prompt);
765
772
  if (!goal) throw new Error("missing user message content");
766
- const session = this.#resolveSession(options);
773
+ const session = this.#resolveSession(sessionID);
767
774
  const textId = randomUUID2();
768
775
  return {
769
776
  stream: new ReadableStream({
@@ -832,8 +839,7 @@ var DuoWorkflowModel = class {
832
839
  }
833
840
  };
834
841
  }
835
- #resolveSession(options) {
836
- const sessionID = readSessionID(options);
842
+ #resolveSession(sessionID) {
837
843
  const key = `${this.#client.instanceUrl}::${this.modelId}::${sessionID}`;
838
844
  const existing = sessions.get(key);
839
845
  if (existing) return existing;
@@ -842,16 +848,12 @@ var DuoWorkflowModel = class {
842
848
  return created;
843
849
  }
844
850
  };
845
- var UTILITY_PREFIXES = [
846
- "Generate a title for this conversation",
847
- "Summarize the following conversation"
848
- ];
849
851
  function extractGoal(prompt) {
850
852
  for (let i = prompt.length - 1; i >= 0; i--) {
851
853
  const message = prompt[i];
852
854
  if (message.role !== "user") continue;
853
855
  const content = Array.isArray(message.content) ? message.content : [];
854
- const text2 = content.filter((part) => part.type === "text").map((part) => stripSystemReminders(part.text)).filter((t) => t && !UTILITY_PREFIXES.some((p) => t.startsWith(p))).join("\n").trim();
856
+ const text2 = content.filter((part) => part.type === "text").map((part) => stripSystemReminders(part.text)).filter(Boolean).join("\n").trim();
855
857
  if (text2) return text2;
856
858
  }
857
859
  return "";
@@ -873,19 +875,13 @@ function readSessionID(options) {
873
875
  for (const [key, value] of Object.entries(headers)) {
874
876
  if (key.toLowerCase() === "x-opencode-session" && value?.trim()) return value.trim();
875
877
  }
876
- return "default";
878
+ return void 0;
877
879
  }
878
880
  function readProviderBlock(options) {
879
881
  const block = options.providerOptions?.[PROVIDER_ID];
880
882
  if (block && typeof block === "object" && !Array.isArray(block)) {
881
883
  return block;
882
884
  }
883
- if (!options.providerOptions) return void 0;
884
- for (const value of Object.values(options.providerOptions)) {
885
- if (value && typeof value === "object" && !Array.isArray(value)) {
886
- return value;
887
- }
888
- }
889
885
  return void 0;
890
886
  }
891
887
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-gitlab-duo-agentic",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "OpenCode plugin and provider for GitLab Duo Agentic workflows",
5
5
  "license": "MIT",
6
6
  "type": "module",