-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathupdate_user.ts
More file actions
105 lines (96 loc) · 2.84 KB
/
Copy pathupdate_user.ts
File metadata and controls
105 lines (96 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import type { GitLabUpdateUserParams, GitLabUserResponse } from '@/tools/gitlab/types'
import { getGitLabApiBase } from '@/tools/gitlab/utils'
import type { ToolConfig } from '@/tools/types'
export const gitlabUpdateUserTool: ToolConfig<GitLabUpdateUserParams, GitLabUserResponse> = {
id: 'gitlab_update_user',
name: 'GitLab Update User',
description:
'Modify an existing GitLab user. Requires an administrator token with admin_mode on the instance.',
version: '1.0.0',
params: {
accessToken: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'GitLab admin Personal Access Token (admin_mode)',
},
host: {
type: 'string',
required: false,
visibility: 'user-only',
description: 'Self-managed GitLab host (e.g. gitlab.example.com). Defaults to gitlab.com.',
},
userId: {
type: 'number',
required: true,
visibility: 'user-or-llm',
description: 'The ID of the user to modify',
},
email: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description:
"The user's new email address (GitLab only allows changing to one of the user's existing verified secondary emails)",
},
username: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: "The user's new username",
},
name: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: "The user's new display name",
},
admin: {
type: 'boolean',
required: false,
visibility: 'user-or-llm',
description: 'Whether the user is an administrator',
},
},
request: {
url: (params) => `${getGitLabApiBase(params.host)}/users/${params.userId}`,
method: 'PUT',
headers: (params) => ({
'Content-Type': 'application/json',
'PRIVATE-TOKEN': params.accessToken,
}),
body: (params) => {
const body: Record<string, unknown> = {}
if (params.email) body.email = params.email
if (params.username) body.username = params.username
if (params.name) body.name = params.name
// Strict boolean check: an untouched block switch serializes as `null`,
// which must not be sent (GitLab would treat it as a demotion).
if (typeof params.admin === 'boolean') body.admin = params.admin
return body
},
},
transformResponse: async (response) => {
if (!response.ok) {
const errorText = await response.text()
return {
success: false,
error: `GitLab API error: ${response.status} ${errorText}`,
output: {},
}
}
const user = await response.json()
return {
success: true,
output: {
user,
},
}
},
outputs: {
user: {
type: 'object',
description: 'The updated user',
},
},
}