opencode-gitlab-duo-agentic 0.1.8 → 0.1.9

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 +105 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,5 +1,109 @@
1
+ // src/constants.ts
2
+ var PROVIDER_ID = "gitlab";
3
+ var DEFAULT_INSTANCE_URL = "https://gitlab.com";
4
+
5
+ // src/gitlab.ts
6
+ function text(value) {
7
+ if (typeof value !== "string") return void 0;
8
+ const trimmed = value.trim();
9
+ return trimmed.length > 0 ? trimmed : void 0;
10
+ }
11
+ function instanceFromEnv() {
12
+ return process.env.GITLAB_INSTANCE_URL ?? process.env.GITLAB_URL ?? process.env.GITLAB_BASE_URL;
13
+ }
14
+ function normalizeInstanceUrl(value) {
15
+ const raw = text(value) ?? DEFAULT_INSTANCE_URL;
16
+ const withProtocol = /^https?:\/\//i.test(raw) ? raw : `https://${raw}`;
17
+ try {
18
+ const url = new URL(withProtocol);
19
+ return `${url.protocol}//${url.host}`;
20
+ } catch {
21
+ return DEFAULT_INSTANCE_URL;
22
+ }
23
+ }
24
+ async function validateToken(instanceUrl, token) {
25
+ const response = await fetch(`${instanceUrl}/api/v4/user`, {
26
+ headers: {
27
+ Authorization: `Bearer ${token}`
28
+ }
29
+ }).catch(() => void 0);
30
+ return !!response?.ok;
31
+ }
32
+ async function persistInstanceUrl(input, instanceUrl) {
33
+ await input.client.config.update({
34
+ query: {
35
+ directory: input.directory
36
+ },
37
+ body: {
38
+ provider: {
39
+ [PROVIDER_ID]: {
40
+ options: {
41
+ instanceUrl
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }).catch(() => void 0);
47
+ }
48
+ function applyGitLabConfig(config) {
49
+ config.provider ??= {};
50
+ const current = config.provider[PROVIDER_ID] ?? {};
51
+ const options = current.options ?? {};
52
+ const instanceUrl = normalizeInstanceUrl(options.instanceUrl ?? instanceFromEnv());
53
+ config.provider[PROVIDER_ID] = {
54
+ ...current,
55
+ options: {
56
+ ...options,
57
+ instanceUrl
58
+ }
59
+ };
60
+ }
61
+ function createGitLabAuthHook(input) {
62
+ return {
63
+ provider: PROVIDER_ID,
64
+ methods: [
65
+ {
66
+ type: "api",
67
+ label: "GitLab Personal Access Token",
68
+ prompts: [
69
+ {
70
+ type: "text",
71
+ key: "instanceUrl",
72
+ message: "GitLab instance URL",
73
+ placeholder: "https://gitlab.com",
74
+ validate: (value) => text(value) ? void 0 : "Instance URL is required"
75
+ },
76
+ {
77
+ type: "text",
78
+ key: "token",
79
+ message: "GitLab token",
80
+ placeholder: "glpat-...",
81
+ validate: (value) => text(value) ? void 0 : "Token is required"
82
+ }
83
+ ],
84
+ authorize: async (inputs = {}) => {
85
+ const token = text(inputs.token);
86
+ if (!token) return { type: "failed" };
87
+ const instanceUrl = normalizeInstanceUrl(inputs.instanceUrl ?? instanceFromEnv());
88
+ const valid = await validateToken(instanceUrl, token);
89
+ if (!valid) return { type: "failed" };
90
+ process.env.GITLAB_INSTANCE_URL = instanceUrl;
91
+ await persistInstanceUrl(input, instanceUrl);
92
+ return {
93
+ type: "success",
94
+ key: token
95
+ };
96
+ }
97
+ }
98
+ ]
99
+ };
100
+ }
101
+
1
102
  // src/index.ts
2
- var GitLabDuoAgenticPlugin = async () => ({});
103
+ var GitLabDuoAgenticPlugin = async (input) => ({
104
+ config: async (config) => applyGitLabConfig(config),
105
+ auth: createGitLabAuthHook(input)
106
+ });
3
107
  var src_default = GitLabDuoAgenticPlugin;
4
108
  export {
5
109
  GitLabDuoAgenticPlugin,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-gitlab-duo-agentic",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "OpenCode plugin and provider for GitLab Duo Agentic workflows",
5
5
  "license": "MIT",
6
6
  "type": "module",