Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/docs/content/docs/integrations/grafana.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,8 @@ Query annotations by time range, dashboard, or tags
| `dashboardUid` | string | No | Dashboard UID to query annotations from \(e.g., abc123def\). Omit to query annotations across the organization. |
| `dashboardId` | number | No | Legacy numeric dashboard ID filter \(prefer dashboardUid\) |
| `panelId` | number | No | Filter by panel ID \(e.g., 1, 2\) |
| `alertId` | number | No | Filter by alert ID |
| `alertId` | number | No | Filter by legacy numeric alert ID |
| `alertUid` | string | No | Filter by alert rule UID \(Grafana 11.6+\) |
| `userId` | number | No | Filter by ID of the user who created the annotation |
| `tags` | string | No | Comma-separated list of tags to filter by |
| `type` | string | No | Filter by type \(alert or annotation\) |
Expand All @@ -490,6 +491,7 @@ Query annotations by time range, dashboard, or tags
| `annotations` | array | List of annotations |
| ↳ `id` | number | Annotation ID |
| ↳ `alertId` | number | Associated alert ID \(0 if not alert-driven\) |
| ↳ `alertUID` | string | UID of the alert rule that created the annotation |
| ↳ `dashboardId` | number | Dashboard ID |
| ↳ `dashboardUID` | string | Dashboard UID |
| ↳ `panelId` | number | Panel ID within the dashboard |
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/integrations/posthog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ Create a new feature flag in PostHog
| `filters` | string | No | Feature flag filters as JSON string |
| `active` | boolean | No | Whether the flag is active \(default: true\) |
| `ensureExperienceContinuity` | boolean | No | Whether to ensure experience continuity \(default: false\) |
| `rolloutPercentage` | number | No | Rollout percentage \(0-100\) |
| `rolloutPercentage` | number | No | Percentage of users \(0-100\) the flag is released to. With Filters, applies to each group that sets no rollout_percentage of its own. |

#### Output

Expand Down
10 changes: 10 additions & 0 deletions apps/sim/blocks/blocks/grafana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,14 @@ Return ONLY the annotation text - no explanations, no quotes, no extra text.`,
mode: 'advanced',
condition: { field: 'operation', value: 'grafana_list_annotations' },
},
{
id: 'alertUid',
title: 'Alert Rule UID',
type: 'short-input',
placeholder: 'Filter by alert rule UID',
mode: 'advanced',
condition: { field: 'operation', value: 'grafana_list_annotations' },
},
{
id: 'userId',
title: 'User ID',
Expand Down Expand Up @@ -1178,6 +1186,7 @@ Return ONLY the JSON object - no explanations, no markdown, no extra text.`,
if (params.annotationType) result.type = params.annotationType
if (params.panelId) result.panelId = Number(params.panelId)
if (params.alertId) result.alertId = Number(params.alertId)
if (params.alertUid) result.alertUid = params.alertUid
if (params.userId) result.userId = Number(params.userId)
if (params.from) result.from = Number(params.from)
if (params.to) result.to = Number(params.to)
Expand Down Expand Up @@ -1290,6 +1299,7 @@ Return ONLY the JSON object - no explanations, no markdown, no extra text.`,
from: { type: 'number', description: 'Filter from time' },
to: { type: 'number', description: 'Filter to time' },
alertId: { type: 'number', description: 'Filter annotations by alert ID' },
alertUid: { type: 'string', description: 'Filter annotations by alert rule UID' },
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
userId: { type: 'number', description: 'Filter annotations by creator user ID' },
annotationType: {
type: 'string',
Expand Down
10 changes: 8 additions & 2 deletions apps/sim/blocks/blocks/posthog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PosthogIcon } from '@/components/icons'
import type { BlockConfig, BlockMeta } from '@/blocks/types'
import { AuthMode, IntegrationType } from '@/blocks/types'
import { mapperOperation } from '@/blocks/utils'

/** Cohort membership definition, whichever of the three forms the user filled. */
const COHORT_DEFINITION_FIELD = ['filters', 'query', 'groups'] as const
Expand Down Expand Up @@ -1560,11 +1561,16 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,

return params.operation as string
},
params: (params) => {
params: (params, context) => {
const result: Record<string, unknown> = {}
if (params.limit) result.limit = Number(params.limit)
if (params.offset) result.offset = Number(params.offset)
if (params.rolloutPercentage) result.rolloutPercentage = Number(params.rolloutPercentage)
if (
params.rolloutPercentage &&
mapperOperation(params, context) !== 'posthog_create_feature_flag'
) {
result.rolloutPercentage = Number(params.rolloutPercentage)
}
if (params.responsesLimit) result.responsesLimit = Number(params.responsesLimit)

return result
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/tools/generated/tool-metadata.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/sim/tools/generated/tool-outputs.ts

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions apps/sim/tools/grafana/create_dashboard.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { describe, expect, it } from 'vitest'
import { createDashboardTool } from '@/tools/grafana/create_dashboard'
import type { GrafanaCreateDashboardParams } from '@/tools/grafana/types'

const baseParams: GrafanaCreateDashboardParams = {
apiKey: 'test-key',
baseUrl: 'https://grafana.example.com',
title: 'Service overview',
}

const buildBody = (params: GrafanaCreateDashboardParams) => {
const body = createDashboardTool.request.body
if (!body) throw new Error('create dashboard has no request body')
return body(params) as { dashboard: { panels: unknown } }
}

describe('grafana create dashboard panels', () => {
it('refuses invalid panels JSON instead of creating an empty dashboard', () => {
expect(() => buildBody({ ...baseParams, panels: '[{"type": "timeseries"' })).toThrow(
'Invalid JSON for panels parameter'
)
})

it('creates an empty dashboard for blank panels', () => {
expect(buildBody({ ...baseParams, panels: ' ' }).dashboard.panels).toEqual([])
})

it('refuses panels JSON that is not an array', () => {
expect(() => buildBody({ ...baseParams, panels: '{"type": "timeseries"}' })).toThrow(
'panels must be a JSON array'
)
})

it('sends panels a block reference already resolved to an array', () => {
const panels = [{ type: 'timeseries', title: 'Latency' }]
const body = buildBody({ ...baseParams, panels: panels as unknown as string })
expect(body.dashboard.panels).toEqual(panels)
})
})
14 changes: 9 additions & 5 deletions apps/sim/tools/grafana/create_dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,19 @@ export const createDashboardTool: ToolConfig<
refresh: params.refresh || '',
}

if (params.panels) {
let panels: unknown = params.panels || []
if (typeof panels === 'string' && !panels.trim()) panels = []
if (typeof panels === 'string') {
try {
dashboard.panels = JSON.parse(params.panels)
panels = JSON.parse(panels)
} catch {
dashboard.panels = []
throw new Error('Invalid JSON for panels parameter')
}
} else {
dashboard.panels = []
}
if (!Array.isArray(panels)) {
throw new Error('panels must be a JSON array of panel objects')
}
dashboard.panels = panels

const body: Record<string, any> = {
dashboard,
Expand Down
15 changes: 14 additions & 1 deletion apps/sim/tools/grafana/list_annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ export const listAnnotationsTool: ToolConfig<
type: 'number',
required: false,
visibility: 'user-or-llm',
description: 'Filter by alert ID',
description: 'Filter by legacy numeric alert ID',
},
alertUid: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Filter by alert rule UID (Grafana 11.6+)',
},
userId: {
type: 'number',
Expand Down Expand Up @@ -108,6 +114,7 @@ export const listAnnotationsTool: ToolConfig<
if (params.dashboardId) searchParams.set('dashboardId', String(params.dashboardId))
if (params.panelId) searchParams.set('panelId', String(params.panelId))
if (params.alertId) searchParams.set('alertId', String(params.alertId))
if (params.alertUid?.trim()) searchParams.set('alertUID', params.alertUid.trim())
if (params.userId) searchParams.set('userId', String(params.userId))
if (params.tags) {
params.tags.split(',').forEach((t) => searchParams.append('tags', t.trim()))
Expand Down Expand Up @@ -141,6 +148,7 @@ export const listAnnotationsTool: ToolConfig<
annotations: rawAnnotations.map((a: Record<string, unknown>) => ({
id: (a.id as number) ?? null,
alertId: (a.alertId as number) ?? null,
alertUID: (a.alertUID as string) ?? null,
dashboardId: (a.dashboardId as number) ?? null,
dashboardUID: (a.dashboardUID as string) ?? null,
panelId: (a.panelId as number) ?? null,
Expand Down Expand Up @@ -168,6 +176,11 @@ export const listAnnotationsTool: ToolConfig<
properties: {
id: { type: 'number', description: 'Annotation ID' },
alertId: { type: 'number', description: 'Associated alert ID (0 if not alert-driven)' },
alertUID: {
type: 'string',
description: 'UID of the alert rule that created the annotation',
optional: true,
},
dashboardId: { type: 'number', description: 'Dashboard ID', optional: true },
dashboardUID: { type: 'string', description: 'Dashboard UID', optional: true },
panelId: { type: 'number', description: 'Panel ID within the dashboard', optional: true },
Expand Down
2 changes: 2 additions & 0 deletions apps/sim/tools/grafana/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ export interface GrafanaCreateAnnotationParams extends GrafanaBaseParams {
interface GrafanaAnnotation {
id: number | null
alertId: number | null
alertUID: string | null
dashboardId: number | null
dashboardUID: string | null
panelId: number | null
Expand Down Expand Up @@ -339,6 +340,7 @@ export interface GrafanaListAnnotationsParams extends GrafanaBaseParams {
dashboardUid?: string
panelId?: number
alertId?: number
alertUid?: string
userId?: number
tags?: string
type?: string
Expand Down
12 changes: 9 additions & 3 deletions apps/sim/tools/posthog/create_experiment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getErrorMessage } from '@sim/utils/errors'
import { getPostHogAppBaseUrl } from '@/tools/posthog/utils'
import type { ToolConfig } from '@/tools/types'
import type { ToolConfig, ToolResponse } from '@/tools/types'

interface CreateExperimentParams {
projectId: string
Expand Down Expand Up @@ -35,7 +35,10 @@ interface CreateExperimentResponse {
experiment: Experiment
}

export const createExperimentTool: ToolConfig<CreateExperimentParams, CreateExperimentResponse> = {
export const createExperimentTool: ToolConfig<
CreateExperimentParams,
ToolResponse & { output: CreateExperimentResponse }
> = {
id: 'posthog_create_experiment',
name: 'PostHog Create Experiment',
description: 'Create a new experiment in PostHog',
Expand Down Expand Up @@ -164,7 +167,10 @@ export const createExperimentTool: ToolConfig<CreateExperimentParams, CreateExpe
const data = await response.json()

return {
experiment: data,
success: true,
output: {
experiment: data,
},
}
},

Expand Down
Loading
Loading