Skip to content

Commit d6ec115

Browse files
v0.6.29: login improvements, posthog telemetry (#4026)
* feat(posthog): Add tracking on mothership abort (#4023) Co-authored-by: Theodore Li <theo@sim.ai> * fix(login): fix captcha headers for manual login (#4025) * fix(signup): fix turnstile key loading * fix(login): fix captcha header passing * Catch user already exists, remove login form captcha
1 parent 3f508e4 commit d6ec115

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

apps/sim/app/(auth)/signup/signup-form.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,8 @@ function SignupFormContent({
270270
name: sanitizedName,
271271
},
272272
{
273-
fetchOptions: {
274-
headers: {
275-
...(token ? { 'x-captcha-response': token } : {}),
276-
},
273+
headers: {
274+
...(token ? { 'x-captcha-response': token } : {}),
277275
},
278276
onError: (ctx) => {
279277
logger.error('Signup error:', ctx.error)
@@ -282,10 +280,7 @@ function SignupFormContent({
282280
let errorCode = 'unknown'
283281
if (ctx.error.code?.includes('USER_ALREADY_EXISTS')) {
284282
errorCode = 'user_already_exists'
285-
errorMessage.push(
286-
'An account with this email already exists. Please sign in instead.'
287-
)
288-
setEmailError(errorMessage[0])
283+
setEmailError('An account with this email already exists. Please sign in instead.')
289284
} else if (
290285
ctx.error.code?.includes('BAD_REQUEST') ||
291286
ctx.error.message?.includes('Email and password sign up is not enabled')

apps/sim/app/workspace/[workspaceId]/home/home.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@ export function Home({ chatId }: HomeProps = {}) {
223223
posthogRef.current = posthog
224224
}, [posthog])
225225

226+
const handleStopGeneration = useCallback(() => {
227+
captureEvent(posthogRef.current, 'task_generation_aborted', {
228+
workspace_id: workspaceId,
229+
view: 'mothership',
230+
})
231+
stopGeneration()
232+
}, [stopGeneration, workspaceId])
233+
226234
const handleSubmit = useCallback(
227235
(text: string, fileAttachments?: FileAttachmentForApi[], contexts?: ChatContext[]) => {
228236
const trimmed = text.trim()
@@ -334,7 +342,7 @@ export function Home({ chatId }: HomeProps = {}) {
334342
defaultValue={initialPrompt}
335343
onSubmit={handleSubmit}
336344
isSending={isSending}
337-
onStopGeneration={stopGeneration}
345+
onStopGeneration={handleStopGeneration}
338346
userId={session?.user?.id}
339347
onContextAdd={handleContextAdd}
340348
/>
@@ -359,7 +367,7 @@ export function Home({ chatId }: HomeProps = {}) {
359367
isSending={isSending}
360368
isReconnecting={isReconnecting}
361369
onSubmit={handleSubmit}
362-
onStopGeneration={stopGeneration}
370+
onStopGeneration={handleStopGeneration}
363371
messageQueue={messageQueue}
364372
onRemoveQueuedMessage={removeFromQueue}
365373
onSendQueuedMessage={sendNow}

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { memo, useCallback, useEffect, useRef, useState } from 'react'
44
import { createLogger } from '@sim/logger'
55
import { History, Plus, Square } from 'lucide-react'
66
import { useParams, useRouter } from 'next/navigation'
7+
import { usePostHog } from 'posthog-js/react'
78
import { useShallow } from 'zustand/react/shallow'
89
import {
910
BubbleChatClose,
@@ -33,6 +34,7 @@ import {
3334
import { Lock, Unlock, Upload } from '@/components/emcn/icons'
3435
import { VariableIcon } from '@/components/icons'
3536
import { useSession } from '@/lib/auth/auth-client'
37+
import { captureEvent } from '@/lib/posthog/client'
3638
import { generateWorkflowJson } from '@/lib/workflows/operations/import-export'
3739
import { ConversationListItem } from '@/app/workspace/[workspaceId]/components'
3840
import { MothershipChat } from '@/app/workspace/[workspaceId]/home/components'
@@ -101,6 +103,9 @@ export const Panel = memo(function Panel({ workspaceId: propWorkspaceId }: Panel
101103
const params = useParams()
102104
const workspaceId = propWorkspaceId ?? (params.workspaceId as string)
103105

106+
const posthog = usePostHog()
107+
const posthogRef = useRef(posthog)
108+
104109
const panelRef = useRef<HTMLElement>(null)
105110
const fileInputRef = useRef<HTMLInputElement>(null)
106111
const { activeTab, setActiveTab, panelWidth, _hasHydrated, setHasHydrated } = usePanelStore(
@@ -264,6 +269,10 @@ export const Panel = memo(function Panel({ workspaceId: propWorkspaceId }: Panel
264269
loadCopilotChats()
265270
}, [loadCopilotChats])
266271

272+
useEffect(() => {
273+
posthogRef.current = posthog
274+
}, [posthog])
275+
267276
const handleCopilotSelectChat = useCallback((chat: { id: string; title: string | null }) => {
268277
setCopilotChatId(chat.id)
269278
setCopilotChatTitle(chat.title)
@@ -394,6 +403,14 @@ export const Panel = memo(function Panel({ workspaceId: propWorkspaceId }: Panel
394403
[copilotEditQueuedMessage]
395404
)
396405

406+
const handleCopilotStopGeneration = useCallback(() => {
407+
captureEvent(posthogRef.current, 'task_generation_aborted', {
408+
workspace_id: workspaceId,
409+
view: 'copilot',
410+
})
411+
copilotStopGeneration()
412+
}, [copilotStopGeneration, workspaceId])
413+
397414
const handleCopilotSubmit = useCallback(
398415
(text: string, fileAttachments?: FileAttachmentForApi[], contexts?: ChatContext[]) => {
399416
const trimmed = text.trim()
@@ -833,7 +850,7 @@ export const Panel = memo(function Panel({ workspaceId: propWorkspaceId }: Panel
833850
isSending={copilotIsSending}
834851
isReconnecting={copilotIsReconnecting}
835852
onSubmit={handleCopilotSubmit}
836-
onStopGeneration={copilotStopGeneration}
853+
onStopGeneration={handleCopilotStopGeneration}
837854
messageQueue={copilotMessageQueue}
838855
onRemoveQueuedMessage={copilotRemoveFromQueue}
839856
onSendQueuedMessage={copilotSendNow}

apps/sim/lib/posthog/events.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ export interface PostHogEventMap {
378378
workspace_id: string
379379
}
380380

381+
task_generation_aborted: {
382+
workspace_id: string
383+
view: 'mothership' | 'copilot'
384+
}
385+
381386
task_message_sent: {
382387
workspace_id: string
383388
has_attachments: boolean

0 commit comments

Comments
 (0)