Skip to content

Commit 048c067

Browse files
committed
fix(integrations): validate grafana, posthog
1 parent 4fdef1e commit 048c067

27 files changed

Lines changed: 680 additions & 498 deletions

‎apps/docs/content/docs/integrations/grafana.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,8 @@ Query annotations by time range, dashboard, or tags
477477
| `dashboardUid` | string | No | Dashboard UID to query annotations from \(e.g., abc123def\). Omit to query annotations across the organization. |
478478
| `dashboardId` | number | No | Legacy numeric dashboard ID filter \(prefer dashboardUid\) |
479479
| `panelId` | number | No | Filter by panel ID \(e.g., 1, 2\) |
480-
| `alertId` | number | No | Filter by alert ID |
480+
| `alertId` | number | No | Filter by legacy numeric alert ID |
481+
| `alertUid` | string | No | Filter by alert rule UID \(Grafana 11.6+\) |
481482
| `userId` | number | No | Filter by ID of the user who created the annotation |
482483
| `tags` | string | No | Comma-separated list of tags to filter by |
483484
| `type` | string | No | Filter by type \(alert or annotation\) |
@@ -490,6 +491,7 @@ Query annotations by time range, dashboard, or tags
490491
| `annotations` | array | List of annotations |
491492
| ↳ `id` | number | Annotation ID |
492493
| ↳ `alertId` | number | Associated alert ID \(0 if not alert-driven\) |
494+
| ↳ `alertUID` | string | UID of the alert rule that created the annotation |
493495
| ↳ `dashboardId` | number | Dashboard ID |
494496
| ↳ `dashboardUID` | string | Dashboard UID |
495497
| ↳ `panelId` | number | Panel ID within the dashboard |

‎apps/docs/content/docs/integrations/posthog.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ Create a new feature flag in PostHog
822822
| `filters` | string | No | Feature flag filters as JSON string |
823823
| `active` | boolean | No | Whether the flag is active \(default: true\) |
824824
| `ensureExperienceContinuity` | boolean | No | Whether to ensure experience continuity \(default: false\) |
825-
| `rolloutPercentage` | number | No | Rollout percentage \(0-100\) |
825+
| `rolloutPercentage` | number | No | Percentage of users \(0-100\) the flag is released to. Ignored when Filters is set; put rollout_percentage in its groups instead. |
826826

827827
#### Output
828828

‎apps/sim/blocks/blocks/grafana.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,14 @@ Return ONLY the annotation text - no explanations, no quotes, no extra text.`,
725725
mode: 'advanced',
726726
condition: { field: 'operation', value: 'grafana_list_annotations' },
727727
},
728+
{
729+
id: 'alertUid',
730+
title: 'Alert Rule UID',
731+
type: 'short-input',
732+
placeholder: 'Filter by alert rule UID',
733+
mode: 'advanced',
734+
condition: { field: 'operation', value: 'grafana_list_annotations' },
735+
},
728736
{
729737
id: 'userId',
730738
title: 'User ID',
@@ -1290,6 +1298,7 @@ Return ONLY the JSON object - no explanations, no markdown, no extra text.`,
12901298
from: { type: 'number', description: 'Filter from time' },
12911299
to: { type: 'number', description: 'Filter to time' },
12921300
alertId: { type: 'number', description: 'Filter annotations by alert ID' },
1301+
alertUid: { type: 'string', description: 'Filter annotations by alert rule UID' },
12931302
userId: { type: 'number', description: 'Filter annotations by creator user ID' },
12941303
annotationType: {
12951304
type: 'string',

‎apps/sim/tools/generated/tool-metadata.ts‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎apps/sim/tools/generated/tool-outputs.ts‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { createDashboardTool } from '@/tools/grafana/create_dashboard'
3+
import type { GrafanaCreateDashboardParams } from '@/tools/grafana/types'
4+
5+
const baseParams: GrafanaCreateDashboardParams = {
6+
apiKey: 'test-key',
7+
baseUrl: 'https://grafana.example.com',
8+
title: 'Service overview',
9+
}
10+
11+
const buildBody = (params: GrafanaCreateDashboardParams) => {
12+
const body = createDashboardTool.request.body
13+
if (!body) throw new Error('create dashboard has no request body')
14+
return body(params) as { dashboard: { panels: unknown } }
15+
}
16+
17+
describe('grafana create dashboard panels', () => {
18+
it('refuses invalid panels JSON instead of creating an empty dashboard', () => {
19+
expect(() => buildBody({ ...baseParams, panels: '[{"type": "timeseries"' })).toThrow(
20+
'Invalid JSON for panels parameter'
21+
)
22+
})
23+
24+
it('sends panels a tool call already passed as an array', () => {
25+
const panels = [{ type: 'timeseries', title: 'Latency' }]
26+
const body = buildBody({ ...baseParams, panels: panels as unknown as string })
27+
expect(body.dashboard.panels).toEqual(panels)
28+
})
29+
})

‎apps/sim/tools/grafana/create_dashboard.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,16 @@ export const createDashboardTool: ToolConfig<
112112
refresh: params.refresh || '',
113113
}
114114

115-
if (params.panels) {
115+
if (!params.panels) {
116+
dashboard.panels = []
117+
} else if (typeof params.panels === 'string') {
116118
try {
117119
dashboard.panels = JSON.parse(params.panels)
118120
} catch {
119-
dashboard.panels = []
121+
throw new Error('Invalid JSON for panels parameter')
120122
}
121123
} else {
122-
dashboard.panels = []
124+
dashboard.panels = params.panels
123125
}
124126

125127
const body: Record<string, any> = {

‎apps/sim/tools/grafana/list_annotations.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@ export const listAnnotationsTool: ToolConfig<
6969
type: 'number',
7070
required: false,
7171
visibility: 'user-or-llm',
72-
description: 'Filter by alert ID',
72+
description: 'Filter by legacy numeric alert ID',
73+
},
74+
alertUid: {
75+
type: 'string',
76+
required: false,
77+
visibility: 'user-or-llm',
78+
description: 'Filter by alert rule UID (Grafana 11.6+)',
7379
},
7480
userId: {
7581
type: 'number',
@@ -108,6 +114,7 @@ export const listAnnotationsTool: ToolConfig<
108114
if (params.dashboardId) searchParams.set('dashboardId', String(params.dashboardId))
109115
if (params.panelId) searchParams.set('panelId', String(params.panelId))
110116
if (params.alertId) searchParams.set('alertId', String(params.alertId))
117+
if (params.alertUid?.trim()) searchParams.set('alertUID', params.alertUid.trim())
111118
if (params.userId) searchParams.set('userId', String(params.userId))
112119
if (params.tags) {
113120
params.tags.split(',').forEach((t) => searchParams.append('tags', t.trim()))
@@ -141,6 +148,7 @@ export const listAnnotationsTool: ToolConfig<
141148
annotations: rawAnnotations.map((a: Record<string, unknown>) => ({
142149
id: (a.id as number) ?? null,
143150
alertId: (a.alertId as number) ?? null,
151+
alertUID: (a.alertUID as string) ?? null,
144152
dashboardId: (a.dashboardId as number) ?? null,
145153
dashboardUID: (a.dashboardUID as string) ?? null,
146154
panelId: (a.panelId as number) ?? null,
@@ -168,6 +176,11 @@ export const listAnnotationsTool: ToolConfig<
168176
properties: {
169177
id: { type: 'number', description: 'Annotation ID' },
170178
alertId: { type: 'number', description: 'Associated alert ID (0 if not alert-driven)' },
179+
alertUID: {
180+
type: 'string',
181+
description: 'UID of the alert rule that created the annotation',
182+
optional: true,
183+
},
171184
dashboardId: { type: 'number', description: 'Dashboard ID', optional: true },
172185
dashboardUID: { type: 'string', description: 'Dashboard UID', optional: true },
173186
panelId: { type: 'number', description: 'Panel ID within the dashboard', optional: true },

‎apps/sim/tools/grafana/types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ export interface GrafanaCreateAnnotationParams extends GrafanaBaseParams {
310310
interface GrafanaAnnotation {
311311
id: number | null
312312
alertId: number | null
313+
alertUID: string | null
313314
dashboardId: number | null
314315
dashboardUID: string | null
315316
panelId: number | null
@@ -339,6 +340,7 @@ export interface GrafanaListAnnotationsParams extends GrafanaBaseParams {
339340
dashboardUid?: string
340341
panelId?: number
341342
alertId?: number
343+
alertUid?: string
342344
userId?: number
343345
tags?: string
344346
type?: string

‎apps/sim/tools/posthog/create_experiment.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getErrorMessage } from '@sim/utils/errors'
22
import { getPostHogAppBaseUrl } from '@/tools/posthog/utils'
3-
import type { ToolConfig } from '@/tools/types'
3+
import type { ToolConfig, ToolResponse } from '@/tools/types'
44

55
interface CreateExperimentParams {
66
projectId: string
@@ -35,7 +35,10 @@ interface CreateExperimentResponse {
3535
experiment: Experiment
3636
}
3737

38-
export const createExperimentTool: ToolConfig<CreateExperimentParams, CreateExperimentResponse> = {
38+
export const createExperimentTool: ToolConfig<
39+
CreateExperimentParams,
40+
ToolResponse & { output: CreateExperimentResponse }
41+
> = {
3942
id: 'posthog_create_experiment',
4043
name: 'PostHog Create Experiment',
4144
description: 'Create a new experiment in PostHog',
@@ -164,7 +167,10 @@ export const createExperimentTool: ToolConfig<CreateExperimentParams, CreateExpe
164167
const data = await response.json()
165168

166169
return {
167-
experiment: data,
170+
success: true,
171+
output: {
172+
experiment: data,
173+
},
168174
}
169175
},
170176

0 commit comments

Comments
 (0)