Skip to content

Commit 80bd276

Browse files
committed
fix(grafana): list annotations outputs
1 parent dc4e5d3 commit 80bd276

File tree

2 files changed

+45
-33
lines changed

2 files changed

+45
-33
lines changed

apps/sim/tools/grafana/list_annotations.ts

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -110,32 +110,34 @@ 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+
// Optional fields - only included if they exist in the response
134+
...(a.alertId !== undefined && { alertId: a.alertId }),
135+
...(a.alertName !== undefined && { alertName: a.alertName }),
136+
...(a.panelId !== undefined && { panelId: a.panelId }),
137+
...(a.userId !== undefined && { userId: a.userId }),
138+
...(a.newState !== undefined && { newState: a.newState }),
139+
...(a.prevState !== undefined && { prevState: a.prevState }),
140+
})),
139141
},
140142
}
141143
},
@@ -148,12 +150,21 @@ export const listAnnotationsTool: ToolConfig<
148150
type: 'object',
149151
properties: {
150152
id: { type: 'number', description: 'Annotation ID' },
151-
text: { type: 'string', description: 'Annotation text' },
152-
tags: { type: 'array', description: 'Annotation tags' },
153+
dashboardId: { type: 'number', description: 'Dashboard ID' },
154+
dashboardUID: { type: 'string', description: 'Dashboard UID' },
155+
created: { type: 'number', description: 'Creation timestamp in epoch ms' },
156+
updated: { type: 'number', description: 'Last update timestamp in epoch ms' },
153157
time: { type: 'number', description: 'Start time in epoch ms' },
154158
timeEnd: { type: 'number', description: 'End time in epoch ms' },
155-
dashboardUID: { type: 'string', description: 'Dashboard UID' },
156-
panelId: { type: 'number', description: 'Panel ID' },
159+
text: { type: 'string', description: 'Annotation text' },
160+
tags: { type: 'array', items: { type: 'string' }, description: 'Annotation tags' },
161+
login: { type: 'string', description: 'Login of the user who created the annotation' },
162+
email: { type: 'string', description: 'Email of the user who created the annotation' },
163+
avatarUrl: { type: 'string', description: 'Avatar URL of the user' },
164+
data: {
165+
type: 'json',
166+
description: 'Additional annotation data object from Grafana',
167+
},
157168
},
158169
},
159170
},

apps/sim/tools/grafana/types.ts

Lines changed: 7 additions & 6 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
@@ -285,6 +279,13 @@ export interface GrafanaAnnotation {
285279
email: string
286280
avatarUrl: string
287281
data: any
282+
// Optional fields - only present for alert annotations or specific cases
283+
alertId?: number
284+
alertName?: string
285+
panelId?: number
286+
userId?: number
287+
newState?: string
288+
prevState?: string
288289
}
289290

290291
export interface GrafanaCreateAnnotationResponse extends ToolResponse {

0 commit comments

Comments
 (0)