Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions apps/sim/app/api/folders/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { eq } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
import { getSession } from '@/lib/auth'
import { captureServerEvent } from '@/lib/posthog/server'
import { performDeleteFolder } from '@/lib/workflows/orchestration'
import { checkForCircularReference } from '@/lib/workflows/utils'
import { getUserEntityPermissions } from '@/lib/workspaces/permissions/utils'
Expand Down Expand Up @@ -156,6 +157,13 @@ export async function DELETE(
return NextResponse.json({ error: result.error }, { status })
}

captureServerEvent(
session.user.id,
'folder_deleted',
{ workspace_id: existingFolder.workspaceId },
{ groups: { workspace: existingFolder.workspaceId } }
)

return NextResponse.json({
success: true,
deletedItems: result.deletedItems,
Expand Down
8 changes: 8 additions & 0 deletions apps/sim/app/api/folders/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { type NextRequest, NextResponse } from 'next/server'
import { z } from 'zod'
import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log'
import { getSession } from '@/lib/auth'
import { captureServerEvent } from '@/lib/posthog/server'
import { getUserEntityPermissions } from '@/lib/workspaces/permissions/utils'

const logger = createLogger('FoldersAPI')
Expand Down Expand Up @@ -145,6 +146,13 @@ export async function POST(request: NextRequest) {

logger.info('Created new folder:', { id, name, workspaceId, parentId })

captureServerEvent(
session.user.id,
'folder_created',
{ workspace_id: workspaceId },
{ groups: { workspace: workspaceId } }
)

recordAudit({
workspaceId,
actorId: session.user.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
retryDocumentProcessing,
updateDocument,
} from '@/lib/knowledge/documents/service'
import { captureServerEvent } from '@/lib/posthog/server'
import { checkDocumentAccess, checkDocumentWriteAccess } from '@/app/api/knowledge/utils'

const logger = createLogger('DocumentByIdAPI')
Expand Down Expand Up @@ -285,6 +286,14 @@ export async function DELETE(
request: req,
})

const kbWorkspaceId = accessCheck.knowledgeBase?.workspaceId ?? ''
captureServerEvent(
userId,
'knowledge_base_document_deleted',
{ knowledge_base_id: knowledgeBaseId, workspace_id: kbWorkspaceId },
kbWorkspaceId ? { groups: { workspace: kbWorkspaceId } } : undefined
)

return NextResponse.json({
success: true,
data: result,
Expand Down
11 changes: 1 addition & 10 deletions apps/sim/app/api/mothership/chats/[chatId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,7 @@ export async function PATCH(
}
)
}
if (isUnread === false) {
captureServerEvent(
userId,
'task_marked_read',
{ workspace_id: updatedChat.workspaceId },
{
groups: { workspace: updatedChat.workspaceId },
}
)
} else if (isUnread === true) {
if (isUnread === true) {
captureServerEvent(
userId,
'task_marked_unread',
Expand Down
10 changes: 10 additions & 0 deletions apps/sim/app/api/schedules/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { z } from 'zod'
import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log'
import { getSession } from '@/lib/auth'
import { generateRequestId } from '@/lib/core/utils/request'
import { captureServerEvent } from '@/lib/posthog/server'
import { validateCronExpression } from '@/lib/workflows/schedules/utils'
import { authorizeWorkflowByWorkspacePermission } from '@/lib/workflows/utils'
import { verifyWorkspaceMembership } from '@/app/api/workflows/utils'
Expand Down Expand Up @@ -298,6 +299,15 @@ export async function DELETE(
request,
})

if (workspaceId) {
captureServerEvent(
session.user.id,
'scheduled_task_deleted',
{ workspace_id: workspaceId },
{ groups: { workspace: workspaceId } }
)
}

return NextResponse.json({ message: 'Schedule deleted successfully' })
} catch (error) {
logger.error(`[${requestId}] Error deleting schedule`, error)
Expand Down
8 changes: 8 additions & 0 deletions apps/sim/app/api/schedules/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { and, eq, isNull, or } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { getSession } from '@/lib/auth'
import { generateRequestId } from '@/lib/core/utils/request'
import { captureServerEvent } from '@/lib/posthog/server'
import { validateCronExpression } from '@/lib/workflows/schedules/utils'
import { authorizeWorkflowByWorkspacePermission } from '@/lib/workflows/utils'
import { verifyWorkspaceMembership } from '@/app/api/workflows/utils'
Expand Down Expand Up @@ -277,6 +278,13 @@ export async function POST(req: NextRequest) {
lifecycle,
})

captureServerEvent(
session.user.id,
'scheduled_task_created',
{ workspace_id: workspaceId },
{ groups: { workspace: workspaceId } }
)

return NextResponse.json(
{ schedule: { id, status: 'active', cronExpression, nextRunAt } },
{ status: 201 }
Expand Down
1 change: 1 addition & 0 deletions apps/sim/app/workspace/[workspaceId]/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export function Home({ chatId }: HomeProps = {}) {
if (!trimmed && !(fileAttachments && fileAttachments.length > 0)) return

captureEvent(posthogRef.current, 'task_message_sent', {
workspace_id: workspaceId,
has_attachments: !!(fileAttachments && fileAttachments.length > 0),
has_contexts: !!(contexts && contexts.length > 0),
is_new_task: !chatId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use client'

import { memo, useCallback, useMemo, useState } from 'react'
import { memo, useCallback, useMemo, useRef, useState } from 'react'
import { ArrowUp, Bell, Library, MoreHorizontal, RefreshCw } from 'lucide-react'
import { useParams } from 'next/navigation'
import { usePostHog } from 'posthog-js/react'
import { useShallow } from 'zustand/react/shallow'
import {
Button,
Expand All @@ -18,6 +19,7 @@ import { DatePicker } from '@/components/emcn/components/date-picker/date-picker
import { cn } from '@/lib/core/utils/cn'
import { hasActiveFilters } from '@/lib/logs/filters'
import { getTriggerOptions } from '@/lib/logs/get-trigger-options'
import { captureEvent } from '@/lib/posthog/client'
import { type LogStatus, STATUS_CONFIG } from '@/app/workspace/[workspaceId]/logs/utils'
import { getBlock } from '@/blocks/registry'
import { useFolderMap } from '@/hooks/queries/folders'
Expand Down Expand Up @@ -179,6 +181,9 @@ export const LogsToolbar = memo(function LogsToolbar({
}: LogsToolbarProps) {
const params = useParams()
const workspaceId = params.workspaceId as string
const posthog = usePostHog()
const posthogRef = useRef(posthog)
posthogRef.current = posthog

const {
level,
Expand Down Expand Up @@ -258,8 +263,45 @@ export const LogsToolbar = memo(function LogsToolbar({
} else {
setLevel(values.join(','))
}
captureEvent(posthogRef.current, 'logs_filter_applied', {
filter_type: 'status',
workspace_id: workspaceId,
})
},
[setLevel]
[setLevel, workspaceId]
)

const handleWorkflowFilterChange = useCallback(
(values: string[]) => {
setWorkflowIds(values)
captureEvent(posthogRef.current, 'logs_filter_applied', {
filter_type: 'workflow',
workspace_id: workspaceId,
})
},
[setWorkflowIds, workspaceId]
)

const handleFolderFilterChange = useCallback(
(values: string[]) => {
setFolderIds(values)
captureEvent(posthogRef.current, 'logs_filter_applied', {
filter_type: 'folder',
workspace_id: workspaceId,
})
},
[setFolderIds, workspaceId]
)

const handleTriggerFilterChange = useCallback(
(values: string[]) => {
setTriggers(values)
captureEvent(posthogRef.current, 'logs_filter_applied', {
filter_type: 'trigger',
workspace_id: workspaceId,
})
},
[setTriggers, workspaceId]
)

const statusDisplayLabel = useMemo(() => {
Expand Down Expand Up @@ -348,9 +390,13 @@ export const LogsToolbar = memo(function LogsToolbar({
} else {
clearDateRange()
setTimeRange(val as typeof timeRange)
captureEvent(posthogRef.current, 'logs_filter_applied', {
filter_type: 'time',
workspace_id: workspaceId,
})
}
},
[timeRange, setTimeRange, clearDateRange]
[timeRange, setTimeRange, clearDateRange, workspaceId]
)

/**
Expand All @@ -360,8 +406,12 @@ export const LogsToolbar = memo(function LogsToolbar({
(start: string, end: string) => {
setDateRange(start, end)
setDatePickerOpen(false)
captureEvent(posthogRef.current, 'logs_filter_applied', {
filter_type: 'time',
workspace_id: workspaceId,
})
},
[setDateRange]
[setDateRange, workspaceId]
)

/**
Expand Down Expand Up @@ -545,7 +595,7 @@ export const LogsToolbar = memo(function LogsToolbar({
options={workflowOptions}
multiSelect
multiSelectValues={workflowIds}
onMultiSelectChange={setWorkflowIds}
onMultiSelectChange={handleWorkflowFilterChange}
placeholder='All workflows'
overlayContent={
<span className='flex items-center gap-1.5 truncate text-[var(--text-primary)]'>
Expand Down Expand Up @@ -580,7 +630,7 @@ export const LogsToolbar = memo(function LogsToolbar({
options={folderOptions}
multiSelect
multiSelectValues={folderIds}
onMultiSelectChange={setFolderIds}
onMultiSelectChange={handleFolderFilterChange}
placeholder='All folders'
overlayContent={
<span className='truncate text-[var(--text-primary)]'>
Expand All @@ -605,7 +655,7 @@ export const LogsToolbar = memo(function LogsToolbar({
options={triggerOptions}
multiSelect
multiSelectValues={triggers}
onMultiSelectChange={setTriggers}
onMultiSelectChange={handleTriggerFilterChange}
placeholder='All triggers'
overlayContent={
<span className='truncate text-[var(--text-primary)]'>
Expand Down Expand Up @@ -676,7 +726,7 @@ export const LogsToolbar = memo(function LogsToolbar({
options={workflowOptions}
multiSelect
multiSelectValues={workflowIds}
onMultiSelectChange={setWorkflowIds}
onMultiSelectChange={handleWorkflowFilterChange}
placeholder='Workflow'
overlayContent={
<span className='flex items-center gap-1.5 truncate text-[var(--text-primary)]'>
Expand Down Expand Up @@ -707,7 +757,7 @@ export const LogsToolbar = memo(function LogsToolbar({
options={folderOptions}
multiSelect
multiSelectValues={folderIds}
onMultiSelectChange={setFolderIds}
onMultiSelectChange={handleFolderFilterChange}
placeholder='Folder'
overlayContent={
<span className='truncate text-[var(--text-primary)]'>{folderDisplayLabel}</span>
Expand All @@ -726,7 +776,7 @@ export const LogsToolbar = memo(function LogsToolbar({
options={triggerOptions}
multiSelect
multiSelectValues={triggers}
onMultiSelectChange={setTriggers}
onMultiSelectChange={handleTriggerFilterChange}
placeholder='Trigger'
overlayContent={
<span className='truncate text-[var(--text-primary)]'>{triggerDisplayLabel}</span>
Expand Down
Loading
Loading