Skip to content

Commit 169dd4a

Browse files
fix(grafana): tool outputs (#2565)
* fix(grafana): list annotations outputs * fix more grafana tools
1 parent dc4e5d3 commit 169dd4a

File tree

3 files changed

+31
-36
lines changed

3 files changed

+31
-36
lines changed

apps/sim/tools/grafana/list_annotations.ts

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -110,32 +110,27 @@ export const listAnnotationsTool: ToolConfig<
110110
transformResponse: async (response: Response) => {
111111
const data = await response.json()
112112

113+
// Handle potential nested array structure
114+
const rawAnnotations = Array.isArray(data) ? data.flat() : []
115+
113116
return {
114117
success: true,
115118
output: {
116-
annotations: Array.isArray(data)
117-
? data.map((a: any) => ({
118-
id: a.id,
119-
alertId: a.alertId,
120-
alertName: a.alertName,
121-
dashboardId: a.dashboardId,
122-
dashboardUID: a.dashboardUID,
123-
panelId: a.panelId,
124-
userId: a.userId,
125-
newState: a.newState,
126-
prevState: a.prevState,
127-
created: a.created,
128-
updated: a.updated,
129-
time: a.time,
130-
timeEnd: a.timeEnd,
131-
text: a.text,
132-
tags: a.tags || [],
133-
login: a.login,
134-
email: a.email,
135-
avatarUrl: a.avatarUrl,
136-
data: a.data,
137-
}))
138-
: [],
119+
annotations: rawAnnotations.map((a: any) => ({
120+
id: a.id,
121+
dashboardId: a.dashboardId,
122+
dashboardUID: a.dashboardUID,
123+
created: a.created,
124+
updated: a.updated,
125+
time: a.time,
126+
timeEnd: a.timeEnd,
127+
text: a.text,
128+
tags: a.tags || [],
129+
login: a.login,
130+
email: a.email,
131+
avatarUrl: a.avatarUrl,
132+
data: a.data || {},
133+
})),
139134
},
140135
}
141136
},
@@ -148,12 +143,21 @@ export const listAnnotationsTool: ToolConfig<
148143
type: 'object',
149144
properties: {
150145
id: { type: 'number', description: 'Annotation ID' },
151-
text: { type: 'string', description: 'Annotation text' },
152-
tags: { type: 'array', description: 'Annotation tags' },
146+
dashboardId: { type: 'number', description: 'Dashboard ID' },
147+
dashboardUID: { type: 'string', description: 'Dashboard UID' },
148+
created: { type: 'number', description: 'Creation timestamp in epoch ms' },
149+
updated: { type: 'number', description: 'Last update timestamp in epoch ms' },
153150
time: { type: 'number', description: 'Start time in epoch ms' },
154151
timeEnd: { type: 'number', description: 'End time in epoch ms' },
155-
dashboardUID: { type: 'string', description: 'Dashboard UID' },
156-
panelId: { type: 'number', description: 'Panel ID' },
152+
text: { type: 'string', description: 'Annotation text' },
153+
tags: { type: 'array', items: { type: 'string' }, description: 'Annotation tags' },
154+
login: { type: 'string', description: 'Login of the user who created the annotation' },
155+
email: { type: 'string', description: 'Email of the user who created the annotation' },
156+
avatarUrl: { type: 'string', description: 'Avatar URL of the user' },
157+
data: {
158+
type: 'json',
159+
description: 'Additional annotation data object from Grafana',
160+
},
157161
},
158162
},
159163
},

apps/sim/tools/grafana/list_folders.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ export const listFoldersTool: ToolConfig<GrafanaListFoldersParams, GrafanaListFo
7575
id: f.id,
7676
uid: f.uid,
7777
title: f.title,
78-
url: f.url,
7978
hasAcl: f.hasAcl || false,
8079
canSave: f.canSave || false,
8180
canEdit: f.canEdit || false,
@@ -102,7 +101,6 @@ export const listFoldersTool: ToolConfig<GrafanaListFoldersParams, GrafanaListFo
102101
id: { type: 'number', description: 'Folder ID' },
103102
uid: { type: 'string', description: 'Folder UID' },
104103
title: { type: 'string', description: 'Folder title' },
105-
url: { type: 'string', description: 'Folder URL path' },
106104
hasAcl: { type: 'boolean', description: 'Whether the folder has custom ACL permissions' },
107105
canSave: { type: 'boolean', description: 'Whether the current user can save the folder' },
108106
canEdit: { type: 'boolean', description: 'Whether the current user can edit the folder' },

apps/sim/tools/grafana/types.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,8 @@ export interface GrafanaCreateAnnotationParams extends GrafanaBaseParams {
267267

268268
export interface GrafanaAnnotation {
269269
id: number
270-
alertId: number
271-
alertName: string
272270
dashboardId: number
273271
dashboardUID: string
274-
panelId: number
275-
userId: number
276-
newState: string
277-
prevState: string
278272
created: number
279273
updated: number
280274
time: number
@@ -380,7 +374,6 @@ export interface GrafanaFolder {
380374
id: number
381375
uid: string
382376
title: string
383-
url: string
384377
hasAcl: boolean
385378
canSave: boolean
386379
canEdit: boolean

0 commit comments

Comments
 (0)