-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathget_job_log.ts
More file actions
88 lines (80 loc) · 2.36 KB
/
Copy pathget_job_log.ts
File metadata and controls
88 lines (80 loc) · 2.36 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
import { truncate } from '@sim/utils/string'
import type { GitLabGetJobLogParams, GitLabGetJobLogResponse } from '@/tools/gitlab/types'
import { getGitLabApiBase } from '@/tools/gitlab/utils'
import type { ToolConfig } from '@/tools/types'
/**
* Job traces can reach ~100 MB on gitlab.com (more on self-managed); cap what
* is returned into the workflow payload so a huge trace cannot blow up the
* execution log. 200k characters comfortably covers failure diagnosis.
*/
const MAX_LOG_CHARS = 200_000
export const gitlabGetJobLogTool: ToolConfig<GitLabGetJobLogParams, GitLabGetJobLogResponse> = {
id: 'gitlab_get_job_log',
name: 'GitLab Get Job Log',
description: 'Get the log (trace) of a GitLab job',
version: '1.0.0',
params: {
accessToken: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'GitLab Personal Access Token',
},
host: {
type: 'string',
required: false,
visibility: 'user-only',
description: 'Self-managed GitLab host (e.g. gitlab.example.com). Defaults to gitlab.com.',
},
projectId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Project ID or path (e.g. mygroup/myproject)',
},
jobId: {
type: 'number',
required: true,
visibility: 'user-or-llm',
description: 'Job ID',
},
},
request: {
url: (params) => {
const encodedId = encodeURIComponent(String(params.projectId).trim())
return `${getGitLabApiBase(params.host)}/projects/${encodedId}/jobs/${params.jobId}/trace`
},
method: 'GET',
headers: (params) => ({
'PRIVATE-TOKEN': params.accessToken,
}),
},
transformResponse: async (response) => {
if (!response.ok) {
const errorText = await response.text()
return {
success: false,
error: `GitLab API error: ${response.status} ${errorText}`,
output: {},
}
}
const fullLog = await response.text()
return {
success: true,
output: {
log: truncate(fullLog, MAX_LOG_CHARS),
truncated: fullLog.length > MAX_LOG_CHARS,
},
}
},
outputs: {
log: {
type: 'string',
description: 'The job log (trace) output, truncated to 200k characters',
},
truncated: {
type: 'boolean',
description: 'Whether the log was truncated',
},
},
}