opencode-gitlab-duo-agentic 0.1.20 → 0.1.23

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 +23 -21
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -319,10 +319,21 @@ 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
339
  if (isUtilityAgent(context.agent)) return;
@@ -341,11 +352,9 @@ async function createPluginHooks(input) {
341
352
  }
342
353
  };
343
354
  }
355
+ var UTILITY_AGENTS = /* @__PURE__ */ new Set(["title", "compaction"]);
344
356
  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;
357
+ return UTILITY_AGENTS.has(agent.name);
349
358
  }
350
359
  function isGitLabProvider(model) {
351
360
  if (model.api?.npm === "opencode-gitlab-duo-agentic") return true;
@@ -737,9 +746,11 @@ var DuoWorkflowModel = class {
737
746
  this.#client = client;
738
747
  }
739
748
  async doGenerate(options) {
749
+ const sessionID = readSessionID(options);
750
+ if (!sessionID) throw new Error("missing workflow session ID");
740
751
  const goal = extractGoal(options.prompt);
741
752
  if (!goal) throw new Error("missing user message content");
742
- const session = this.#resolveSession(options);
753
+ const session = this.#resolveSession(sessionID);
743
754
  const chunks = [];
744
755
  for await (const item of session.runTurn(goal, options.abortSignal)) {
745
756
  if (item.type === "text-delta") chunks.push(item.value);
@@ -761,9 +772,11 @@ var DuoWorkflowModel = class {
761
772
  };
762
773
  }
763
774
  async doStream(options) {
775
+ const sessionID = readSessionID(options);
776
+ if (!sessionID) throw new Error("missing workflow session ID");
764
777
  const goal = extractGoal(options.prompt);
765
778
  if (!goal) throw new Error("missing user message content");
766
- const session = this.#resolveSession(options);
779
+ const session = this.#resolveSession(sessionID);
767
780
  const textId = randomUUID2();
768
781
  return {
769
782
  stream: new ReadableStream({
@@ -832,8 +845,7 @@ var DuoWorkflowModel = class {
832
845
  }
833
846
  };
834
847
  }
835
- #resolveSession(options) {
836
- const sessionID = readSessionID(options);
848
+ #resolveSession(sessionID) {
837
849
  const key = `${this.#client.instanceUrl}::${this.modelId}::${sessionID}`;
838
850
  const existing = sessions.get(key);
839
851
  if (existing) return existing;
@@ -842,16 +854,12 @@ var DuoWorkflowModel = class {
842
854
  return created;
843
855
  }
844
856
  };
845
- var UTILITY_PREFIXES = [
846
- "Generate a title for this conversation",
847
- "Summarize the following conversation"
848
- ];
849
857
  function extractGoal(prompt) {
850
858
  for (let i = prompt.length - 1; i >= 0; i--) {
851
859
  const message = prompt[i];
852
860
  if (message.role !== "user") continue;
853
861
  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();
862
+ const text2 = content.filter((part) => part.type === "text").map((part) => stripSystemReminders(part.text)).filter(Boolean).join("\n").trim();
855
863
  if (text2) return text2;
856
864
  }
857
865
  return "";
@@ -873,19 +881,13 @@ function readSessionID(options) {
873
881
  for (const [key, value] of Object.entries(headers)) {
874
882
  if (key.toLowerCase() === "x-opencode-session" && value?.trim()) return value.trim();
875
883
  }
876
- return "default";
884
+ return void 0;
877
885
  }
878
886
  function readProviderBlock(options) {
879
887
  const block = options.providerOptions?.[PROVIDER_ID];
880
888
  if (block && typeof block === "object" && !Array.isArray(block)) {
881
889
  return block;
882
890
  }
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
891
  return void 0;
890
892
  }
891
893
 
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.23",
4
4
  "description": "OpenCode plugin and provider for GitLab Duo Agentic workflows",
5
5
  "license": "MIT",
6
6
  "type": "module",