opencode-gitlab-duo-agentic 0.1.11 → 0.1.13
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.js +13 -92
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// src/constants.ts
|
|
2
|
-
var PROVIDER_ID = "gitlab
|
|
2
|
+
var PROVIDER_ID = "gitlab";
|
|
3
3
|
var MODEL_ID = "duo-agentic";
|
|
4
4
|
var DEFAULT_INSTANCE_URL = "https://gitlab.com";
|
|
5
|
-
var
|
|
6
|
-
var NOT_IMPLEMENTED_MESSAGE = "gitlab-duo-agentic is configured, but the Duo Workflow runtime is not implemented yet.";
|
|
5
|
+
var NOT_IMPLEMENTED_MESSAGE = "GitLab Duo Agentic fallback model is configured, but the Duo Workflow runtime is not implemented yet.";
|
|
7
6
|
|
|
8
7
|
// src/utils/url.ts
|
|
9
8
|
function text(value) {
|
|
@@ -25,109 +24,32 @@ function normalizeInstanceUrl(value) {
|
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
// src/plugin/auth.ts
|
|
29
|
-
function encodeAuthKey(value) {
|
|
30
|
-
const payload = Buffer.from(JSON.stringify(value), "utf8").toString("base64url");
|
|
31
|
-
return `${AUTH_KEY_PREFIX}${payload}`;
|
|
32
|
-
}
|
|
33
|
-
function decodeAuthKey(key) {
|
|
34
|
-
if (!key.startsWith(AUTH_KEY_PREFIX)) {
|
|
35
|
-
return { token: key };
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
const payload = key.slice(AUTH_KEY_PREFIX.length);
|
|
39
|
-
const parsed = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
40
|
-
return {
|
|
41
|
-
token: text(parsed.token),
|
|
42
|
-
instanceUrl: text(parsed.instanceUrl)
|
|
43
|
-
};
|
|
44
|
-
} catch {
|
|
45
|
-
return { token: key };
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async function validateToken(instanceUrl, token) {
|
|
49
|
-
const response = await fetch(`${instanceUrl}/api/v4/user`, {
|
|
50
|
-
headers: {
|
|
51
|
-
Authorization: `Bearer ${token}`
|
|
52
|
-
}
|
|
53
|
-
}).catch(() => void 0);
|
|
54
|
-
return !!response?.ok;
|
|
55
|
-
}
|
|
56
|
-
function createAuthHook() {
|
|
57
|
-
return {
|
|
58
|
-
provider: PROVIDER_ID,
|
|
59
|
-
loader: async (getAuth, provider) => {
|
|
60
|
-
const auth = await getAuth();
|
|
61
|
-
const decoded = auth?.type === "api" ? decodeAuthKey(auth.key) : {};
|
|
62
|
-
const options = provider.options ?? {};
|
|
63
|
-
const instanceUrl = normalizeInstanceUrl(decoded.instanceUrl ?? options.instanceUrl ?? envInstanceUrl());
|
|
64
|
-
if (!decoded.token) {
|
|
65
|
-
return {
|
|
66
|
-
instanceUrl
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
apiKey: decoded.token,
|
|
71
|
-
instanceUrl
|
|
72
|
-
};
|
|
73
|
-
},
|
|
74
|
-
methods: [
|
|
75
|
-
{
|
|
76
|
-
type: "api",
|
|
77
|
-
label: "GitLab Personal Access Token",
|
|
78
|
-
prompts: [
|
|
79
|
-
{
|
|
80
|
-
type: "text",
|
|
81
|
-
key: "instanceUrl",
|
|
82
|
-
message: "GitLab instance URL",
|
|
83
|
-
placeholder: "https://gitlab.com",
|
|
84
|
-
validate: (value) => text(value) ? void 0 : "Instance URL is required"
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
type: "text",
|
|
88
|
-
key: "token",
|
|
89
|
-
message: "GitLab token",
|
|
90
|
-
placeholder: "glpat-...",
|
|
91
|
-
validate: (value) => text(value) ? void 0 : "Token is required"
|
|
92
|
-
}
|
|
93
|
-
],
|
|
94
|
-
authorize: async (inputs = {}) => {
|
|
95
|
-
const token = text(inputs.token);
|
|
96
|
-
if (!token) return { type: "failed" };
|
|
97
|
-
const instanceUrl = normalizeInstanceUrl(inputs.instanceUrl ?? envInstanceUrl());
|
|
98
|
-
const valid = await validateToken(instanceUrl, token);
|
|
99
|
-
if (!valid) return { type: "failed" };
|
|
100
|
-
return {
|
|
101
|
-
type: "success",
|
|
102
|
-
key: encodeAuthKey({ token, instanceUrl })
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
]
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
27
|
// src/plugin/config.ts
|
|
111
28
|
function applyRuntimeConfig(config, moduleUrl) {
|
|
112
29
|
config.provider ??= {};
|
|
113
30
|
const current = config.provider[PROVIDER_ID] ?? {};
|
|
114
31
|
const options = current.options ?? {};
|
|
115
32
|
const models = current.models ?? {};
|
|
33
|
+
const fallbackModel2 = {
|
|
34
|
+
[MODEL_ID]: {
|
|
35
|
+
id: MODEL_ID,
|
|
36
|
+
name: "GitLab Duo Agentic (fallback)"
|
|
37
|
+
}
|
|
38
|
+
};
|
|
116
39
|
const instanceUrl = normalizeInstanceUrl(options.instanceUrl ?? envInstanceUrl());
|
|
117
40
|
config.provider[PROVIDER_ID] = {
|
|
118
41
|
...current,
|
|
119
42
|
name: current.name ?? "GitLab Duo Agentic",
|
|
120
43
|
npm: current.npm ?? moduleUrl,
|
|
121
44
|
env: current.env ?? ["GITLAB_TOKEN", "GITLAB_INSTANCE_URL"],
|
|
45
|
+
whitelist: [MODEL_ID],
|
|
122
46
|
options: {
|
|
123
47
|
...options,
|
|
124
48
|
instanceUrl
|
|
125
49
|
},
|
|
126
|
-
models:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
name: "GitLab Duo Agentic (fallback)"
|
|
130
|
-
}
|
|
50
|
+
models: {
|
|
51
|
+
...fallbackModel2,
|
|
52
|
+
...models
|
|
131
53
|
}
|
|
132
54
|
};
|
|
133
55
|
if (Array.isArray(config.disabled_providers)) {
|
|
@@ -141,8 +63,7 @@ function applyRuntimeConfig(config, moduleUrl) {
|
|
|
141
63
|
// src/plugin/hooks.ts
|
|
142
64
|
async function createPluginHooks(_input, moduleUrl) {
|
|
143
65
|
return {
|
|
144
|
-
config: async (config) => applyRuntimeConfig(config, moduleUrl)
|
|
145
|
-
auth: createAuthHook()
|
|
66
|
+
config: async (config) => applyRuntimeConfig(config, moduleUrl)
|
|
146
67
|
};
|
|
147
68
|
}
|
|
148
69
|
|