opencode-gitlab-duo-agentic 0.2.17 → 0.2.20

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 +70 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -905,6 +905,25 @@ var WorkflowSession = class {
905
905
  }
906
906
  });
907
907
  }
908
+ /**
909
+ * Send an HTTP response back to DWS on the existing connection.
910
+ * Used for gitlab_api_request which requires httpResponse (not plainTextResponse).
911
+ */
912
+ sendHttpResult(requestId, statusCode, headers, body, error) {
913
+ dlog(`sendHttpResult: reqId=${requestId} status=${statusCode} body=${body.length}b error=${error ?? "none"} socket=${!!this.#socket}`);
914
+ if (!this.#socket) throw new Error("Not connected");
915
+ this.#socket.send({
916
+ actionResponse: {
917
+ requestID: requestId,
918
+ httpResponse: {
919
+ statusCode,
920
+ headers,
921
+ body,
922
+ error: error ?? ""
923
+ }
924
+ }
925
+ });
926
+ }
908
927
  /**
909
928
  * Wait for the next event from the session.
910
929
  * Returns null when the stream is closed (turn complete or connection lost).
@@ -948,6 +967,12 @@ var WorkflowSession = class {
948
967
  return;
949
968
  }
950
969
  const toolAction = action;
970
+ if (toolAction.runHTTPRequest && toolAction.requestID) {
971
+ dlog(`standalone: httpRequest ${toolAction.runHTTPRequest.method} ${toolAction.runHTTPRequest.path} reqId=${toolAction.requestID}`);
972
+ this.#executeHttpRequest(toolAction.requestID, toolAction.runHTTPRequest).catch(() => {
973
+ });
974
+ return;
975
+ }
951
976
  const mapped = mapActionToToolRequest(toolAction);
952
977
  if (mapped) {
953
978
  dlog(`standalone: ${mapped.toolName} reqId=${mapped.requestId} args=${JSON.stringify(mapped.args).slice(0, 200)}`);
@@ -962,6 +987,42 @@ var WorkflowSession = class {
962
987
  }
963
988
  }
964
989
  // ---------------------------------------------------------------------------
990
+ // Private: HTTP request handling (gitlab_api_request)
991
+ // ---------------------------------------------------------------------------
992
+ /**
993
+ * Execute a GitLab API request directly and send the response as httpResponse.
994
+ * DWS is the only action that expects httpResponse instead of plainTextResponse.
995
+ * Runs async in the background (fire-and-forget from #handleAction).
996
+ */
997
+ async #executeHttpRequest(requestId, request2) {
998
+ try {
999
+ const url = `${this.#client.instanceUrl}/api/v4/${request2.path}`;
1000
+ dlog(`httpRequest: ${request2.method} ${request2.path} reqId=${requestId}`);
1001
+ const init = {
1002
+ method: request2.method,
1003
+ headers: {
1004
+ "authorization": `Bearer ${this.#client.token}`,
1005
+ "content-type": "application/json"
1006
+ }
1007
+ };
1008
+ if (request2.body) {
1009
+ init.body = request2.body;
1010
+ }
1011
+ const response = await fetch(url, init);
1012
+ const body = await response.text();
1013
+ const headers = {};
1014
+ response.headers.forEach((value, key) => {
1015
+ headers[key] = value;
1016
+ });
1017
+ dlog(`httpRequest: ${request2.method} ${request2.path} \u2192 ${response.status} body=${body.length}b`);
1018
+ this.sendHttpResult(requestId, response.status, headers, body);
1019
+ } catch (error) {
1020
+ const message = error instanceof Error ? error.message : String(error);
1021
+ dlog(`httpRequest: ERROR ${request2.method} ${request2.path} \u2192 ${message}`);
1022
+ this.sendHttpResult(requestId, 0, {}, "", message);
1023
+ }
1024
+ }
1025
+ // ---------------------------------------------------------------------------
965
1026
  // Private: connection management
966
1027
  // ---------------------------------------------------------------------------
967
1028
  /**
@@ -1193,10 +1254,7 @@ function mapDuoToolRequest(toolName, args) {
1193
1254
  switch (toolName) {
1194
1255
  case "list_dir": {
1195
1256
  const directory = asString2(args.directory) ?? ".";
1196
- return {
1197
- toolName: "bash",
1198
- args: { command: `ls -la ${shellQuote(directory)}`, description: "List directory contents", workdir: "." }
1199
- };
1257
+ return { toolName: "read", args: { filePath: directory } };
1200
1258
  }
1201
1259
  case "read_file": {
1202
1260
  const filePath = asString2(args.file_path) ?? asString2(args.filepath) ?? asString2(args.filePath) ?? asString2(args.path);
@@ -1511,8 +1569,13 @@ var DuoWorkflowModel = class {
1511
1569
  model.#sentToolCallIds.add(result.toolCallId);
1512
1570
  model.#pendingToolRequests.delete(result.toolCallId);
1513
1571
  if (group.collected.size === group.subIds.length) {
1514
- const aggregated = group.subIds.map((id) => group.collected.get(id) ?? "").join("\n");
1515
- session.sendToolResult(originalId, aggregated);
1572
+ const result2 = {};
1573
+ for (let i = 0; i < group.subIds.length; i++) {
1574
+ const label = group.labels[i] || `file_${i}`;
1575
+ const value = group.collected.get(group.subIds[i]) ?? "";
1576
+ result2[label] = { content: value };
1577
+ }
1578
+ session.sendToolResult(originalId, JSON.stringify(result2));
1516
1579
  model.#multiCallGroups.delete(originalId);
1517
1580
  model.#pendingToolRequests.delete(originalId);
1518
1581
  sentToolResults = true;
@@ -1603,6 +1666,7 @@ var DuoWorkflowModel = class {
1603
1666
  const subIds = mapped.map((_, i) => `${event.requestId}_sub_${i}`);
1604
1667
  model.#multiCallGroups.set(event.requestId, {
1605
1668
  subIds,
1669
+ labels: mapped.map((m) => String(m.args.filePath ?? m.args.path ?? "")),
1606
1670
  collected: /* @__PURE__ */ new Map()
1607
1671
  });
1608
1672
  model.#pendingToolRequests.set(event.requestId, {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-gitlab-duo-agentic",
3
- "version": "0.2.17",
3
+ "version": "0.2.20",
4
4
  "description": "OpenCode plugin and provider for GitLab Duo Agentic workflows",
5
5
  "license": "MIT",
6
6
  "type": "module",