SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.
JavaScript a2aagentic-aiai-agentsdevtoolsmcp-clientn8n-alternativeno-codeopen-sourceorchestrationsmythosvisual-builder
Fix posthog issues
ali-inkco84e22c6648f2
diff --git a/packages/app/src/builder-ui/components/APIEndpoint.class.ts b/packages/app/src/builder-ui/components/APIEndpoint.class.tsindex b79d34f6..7b99459b 100644--- a/packages/app/src/builder-ui/components/APIEndpoint.class.ts+++ b/packages/app/src/builder-ui/components/APIEndpoint.class.ts@@ -1,8 +1,8 @@+import { PostHog } from '@src/shared/posthog';import { debounce } from 'lodash-es';import { EMBODIMENT_DESCRIPTIONS } from '../../shared/constants/general';import EventEmitter from '../EventEmitter.class';import { openEmbodimentDialog } from '../pages/builder/agent-settings';-import { PostHog } from '../services/posthog';import { confirm } from '../ui/dialogs';import { renderEndpointFormPreviewSidebar } from '../ui/react-injects';import { delay } from '../utils';diff --git a/packages/app/src/builder-ui/components/AgentCard.class.ts b/packages/app/src/builder-ui/components/AgentCard.class.tsindex f00dc54b..20c1984b 100644--- a/packages/app/src/builder-ui/components/AgentCard.class.ts+++ b/packages/app/src/builder-ui/components/AgentCard.class.ts@@ -1,8 +1,8 @@import { TooltipV2 } from '@src/react/shared/components/_legacy/ui/tooltip/tooltipV2';+import { PostHog } from '@src/shared/posthog';import interact from 'interactjs';import jsPlumb from 'jsplumb';import EventEmitter from '../EventEmitter.class';-import { PostHog } from '../services/posthog';import { ComponentProperties, DrawSettingsType, Settings } from '../types/component.types';import { alert, openAgentSettingsRightSidebar } from '../ui/dialogs';import { renderAgentSettingsSidebar } from '../ui/react-injects';@@ -608,7 +608,7 @@ export class AgentCard extends EventEmitter {destroyCanvasContextMenu();e.stopPropagation();- PostHog.track('app_preview_as_chatbot_click');+ PostHog.track('app_preview_as_chatbot_click', {});const embodimentTestButton = document.querySelector('#btn-emb-chatbot-main');const embodimentOpened = document.querySelector(diff --git a/packages/app/src/builder-ui/components/Component.class/index.ts b/packages/app/src/builder-ui/components/Component.class/index.tsindex b1a32afa..c7afa351 100644--- a/packages/app/src/builder-ui/components/Component.class/index.ts+++ b/packages/app/src/builder-ui/components/Component.class/index.ts@@ -11,13 +11,13 @@ import { readFormValues, syncCompositeValues } from '../../ui/form';import { ComponentDocLinks } from '@src/builder-ui/enums/doc-links.enum';import { errorToast, successToast, warningToast } from '@src/shared/components/toast';import { SMYTHOS_DOCS_URL } from '@src/shared/constants/general';+import { PostHog } from '@src/shared/posthog';import { jsonrepair } from 'jsonrepair';import { isEqual } from 'lodash-es';import { TooltipV2 } from '../../../react/shared/components/_legacy/ui/tooltip/tooltipV2';import config, { COMP_NAMES } from '../../config';import { BINARY_INPUT_TYPES } from '../../constants';import { checkWorkflowStatus } from '../../debugger';-import { PostHog } from '../../services/posthog';import { generateTemplateVarBtns } from '../../ui/form/misc';import { renderComponentInputEditor } from '../../ui/react-injects';import { closeTwDialog, editValuesDialog, twEditValuesWithCallback } from '../../ui/tw-dialogs';diff --git a/packages/app/src/builder-ui/components/Component.class/mock-data-handler.ts b/packages/app/src/builder-ui/components/Component.class/mock-data-handler.tsindex 64a68f91..f624e7fe 100644--- a/packages/app/src/builder-ui/components/Component.class/mock-data-handler.ts+++ b/packages/app/src/builder-ui/components/Component.class/mock-data-handler.ts@@ -1,12 +1,12 @@-import { Component } from '../Component.class';-import { twEditValuesWithCallback, closeTwDialog } from '../../ui/tw-dialogs';-import { parseJson } from '../../utils/data.utils';-import { JsonFieldSynchronizer } from '../../lib/JsonFieldSynchronizer.class';-import { JSON_FIELD_CLASS } from '../../constants';-import { PostHog } from '../../services/posthog';+import { PostHog } from '@src/shared/posthog';import { lsCache } from '../../../shared/Cache.class';-import { Workspace } from '../../workspace/Workspace.class';import { MOCK_DATA_CACHE_KEY } from '../../../shared/constants/general';+import { JSON_FIELD_CLASS } from '../../constants';+import { JsonFieldSynchronizer } from '../../lib/JsonFieldSynchronizer.class';+import { closeTwDialog, twEditValuesWithCallback } from '../../ui/tw-dialogs';+import { parseJson } from '../../utils/data.utils';+import { Workspace } from '../../workspace/Workspace.class';+import { Component } from '../Component.class';declare var workspace: Workspace;@@ -210,7 +210,7 @@ export function saveMockOutputs(component: Component) {try {await insertOrUpdateMockData(component.uid, { enabled: true, data: { outputs } });- PostHog.track('app_set_mock_data');+ PostHog.track('app_set_mock_data', {});resolve('saved');} finally {diff --git a/packages/app/src/builder-ui/components/Component.class/settings-editor.ts b/packages/app/src/builder-ui/components/Component.class/settings-editor.tsindex a82a76ad..e1c81ee1 100644--- a/packages/app/src/builder-ui/components/Component.class/settings-editor.ts+++ b/packages/app/src/builder-ui/components/Component.class/settings-editor.ts@@ -1,7 +1,7 @@import { errorToast, successToast } from '@src/shared/components/toast';+import { PostHog } from '@src/shared/posthog';import { Component } from '.';import { FEATURE_FLAGS } from '../../../shared/constants/featureflags';-import { PostHog } from '../../services/posthog';import {closeRightSidebar,confirm,diff --git a/packages/app/src/builder-ui/debugger.ts b/packages/app/src/builder-ui/debugger.tsindex 2bd25e95..af6dc657 100644--- a/packages/app/src/builder-ui/debugger.ts+++ b/packages/app/src/builder-ui/debugger.ts@@ -1,9 +1,9 @@import { errorToast, successToast, warningToast } from '@src/shared/components/toast';+import { PostHog } from '@src/shared/posthog';import interact from 'interactjs';import { jsonrepair } from 'jsonrepair';import { Component } from './components/Component.class';import SmythFile from './lib/SmythFile.class';-import { PostHog } from './services/posthog';import { alert, modalDialog } from './ui/dialogs';import { twModalDialog } from './ui/tw-dialogs';import { delay } from './utils';@@ -578,7 +578,7 @@ export async function runDebug() {runBtn.classList.add('running');isRunning = true;- PostHog.track('app_run_agent');+ PostHog.track('app_run_agent', {});let sessionID;let processComponents = true;diff --git a/packages/app/src/builder-ui/pages/builder/agent-settings.ts b/packages/app/src/builder-ui/pages/builder/agent-settings.tsindex 8199cf04..d6ab6a71 100644--- a/packages/app/src/builder-ui/pages/builder/agent-settings.ts+++ b/packages/app/src/builder-ui/pages/builder/agent-settings.ts@@ -1,12 +1,12 @@import { PRIMARY_BUTTON_STYLE } from '@src/react/shared/constants/style';import { plugins, PluginTarget, PluginType } from '@src/react/shared/plugins/Plugins';import { errorToast, successToast } from '@src/shared/components/toast';+import { PostHog } from '@src/shared/posthog';import { EMBODIMENT_DESCRIPTIONS, SMYTHOS_DOCS_URL } from '../../../shared/constants/general';import { EmbodimentRPCManager } from '../../../shared/services/embodiment_rpc_manager';import { builderStore } from '../../../shared/state_stores/builder/store';import { userSettingKeys } from '../../../shared/userSettingKeys';import { Component } from '../../components/Component.class';-import { PostHog } from '../../services/posthog';import {confirm,createEmbodimentSidebar,diff --git a/packages/app/src/builder-ui/services/posthog.ts b/packages/app/src/builder-ui/services/posthog.tsdeleted file mode 100644index 9195faba..00000000--- a/packages/app/src/builder-ui/services/posthog.ts+++ /dev/null@@ -1,35 +0,0 @@-// PostHogService.ts-import { isProdEnv } from '@src/shared/utils';-import posthog from 'posthog-js';--export class PostHog {- private static isInitialized: boolean = false;-- // Initialize PostHog if not already initialized- static initialize() {- if (!this.isInitialized) {- posthog.init('phc_lxgXwZRs6ySZqrHI4niOdYJlVXJAgMjTOhDau7f7VC3', {- // @TODO: Saad - it may need to go to the .env file- api_host: 'https://us.i.posthog.com',- person_profiles: 'identified_only',- });- this.isInitialized = true; // Set initialized flag- }- }-- // Capture an event using PostHog- static track(eventName: string, properties: Record<string, any> = {}) {- this.initialize(); // Ensure PostHog is initialized before capturing events-- posthog.capture(eventName, properties);- }-- static getFeatureFlag(featureFlagName: string) {- this.initialize(); // Ensure PostHog is initialized before capturing events- if (isProdEnv()) {- return posthog.getFeatureFlag(featureFlagName);- } else {- return posthog.getFeatureFlagPayload(featureFlagName) || false;- }- }-}diff --git a/packages/app/src/builder-ui/ui/dialogs.ts b/packages/app/src/builder-ui/ui/dialogs.tsindex 9dee12e2..0f110e7a 100644--- a/packages/app/src/builder-ui/ui/dialogs.ts+++ b/packages/app/src/builder-ui/ui/dialogs.ts@@ -17,12 +17,12 @@ import {import { createForm, handleTemplateVars, readFormValidation, readFormValues } from './form/';import { errorToast } from '@src/shared/components/toast';+import { PostHog } from '@src/shared/posthog';import yaml from 'js-yaml';import { debounce } from 'lodash-es';import { EMBODIMENT_DESCRIPTIONS } from '../../shared/constants/general';import config from '../config';import { openLLMEmbodiment } from '../pages/builder/llm-embodiment';-import { PostHog } from '../services/posthog';import { smythValidator } from './form/';import { getIconFormEmbTab, rightSidebarTitle } from './right-sidebar-title';diff --git a/packages/app/src/react/app/routes.tsx b/packages/app/src/react/app/routes.tsxindex f2b2167f..a9fc4bb3 100644--- a/packages/app/src/react/app/routes.tsx+++ b/packages/app/src/react/app/routes.tsx@@ -28,7 +28,7 @@ const RoutesWrapper = ({ pages }: { pages: IPageRoute[] }) => {const { subs } = userInfoCtx?.userInfo ?? {};const planNameLower = subs?.plan?.name?.toLowerCase() || '';const isBuilderPlan = planNameLower === PRICING_PLANS_V4.BUILDER.toLowerCase();- const flagValue = PostHog.getFeatureFlagValue(FEATURE_FLAGS.ONBOARDING_CALLS_FOR_BUILDER_PLAN);+ const flagValue = PostHog.getFeatureFlag(FEATURE_FLAGS.ONBOARDING_CALLS_FOR_BUILDER_PLAN);if (isBuilderPlan && typeof flagValue !== 'boolean' && flagValue !== 'variant_1') {useGetBookAnIntroCall({@@ -75,8 +75,8 @@ const RoutesWrapper = ({ pages }: { pages: IPageRoute[] }) => {? avatar.includes('google')? 'google': avatar.includes('github')- ? 'github'- : 'other'+ ? 'github'+ : 'other': 'email',planName,isDefaultPlan,@@ -90,7 +90,8 @@ const RoutesWrapper = ({ pages }: { pages: IPageRoute[] }) => {// Reload feature flags after user identificationPostHog.reloadFeatureFlags();- setTimeout(checkFeatureFlag, 1000);+ // Wait a bit longer for flags to reload before checking features+ setTimeout(checkFeatureFlag, 2000);}}, [userInfoCtx?.userInfo?.user]);@@ -108,8 +109,7 @@ const RoutesWrapper = ({ pages }: { pages: IPageRoute[] }) => {</div>) : userInfoCtx.error && !page.skipAuth ? (<p>Application Error</p>- ) :- (+ ) : (<ComponentWithDocumentTitle>{page.component}</ComponentWithDocumentTitle>);diff --git a/packages/app/src/react/features/builder/components/endpoint-form-preview-sidebar/views/ResponseView.tsx b/packages/app/src/react/features/builder/components/endpoint-form-preview-sidebar/views/ResponseView.tsxindex de981de3..3a26194b 100644--- a/packages/app/src/react/features/builder/components/endpoint-form-preview-sidebar/views/ResponseView.tsx+++ b/packages/app/src/react/features/builder/components/endpoint-form-preview-sidebar/views/ResponseView.tsx@@ -94,7 +94,7 @@ const ResponseView = () => {const getDebugComponent = () => {try {- const featureVariant = PostHog.getFeatureFlagValue(+ const featureVariant = PostHog.getFeatureFlag(FEATURE_FLAGS.TEST_FORM_TRY_DEBUG_BUTTON_EXPERIMENT,) as string;diff --git a/packages/app/src/shared/posthog/index.ts b/packages/app/src/shared/posthog/index.tsindex 10900fe3..3a9efceb 100644--- a/packages/app/src/shared/posthog/index.ts+++ b/packages/app/src/shared/posthog/index.ts@@ -8,7 +8,7 @@ let initialized = false;const lazyInit = () => {if (!initialized) {// can't disable posthog in dev because feature flags depend on it- posthog.init(POSTHOG_CLIENT_KEY, {+ posthog?.init(POSTHOG_CLIENT_KEY, {autocapture: !config.env.IS_DEV,capture_pageview: !config.env.IS_DEV,// debug: config.env.IS_DEV,@@ -38,30 +38,38 @@ export const PostHog = {}},+ // Check if PostHog is fully loaded using the built-in __loaded property+ isLoaded: () => {+ return initialized && posthog?.__loaded;+ },+identify: (userId, properties = {}) => {if (!initialized) lazyInit();- posthog.identify(userId, properties);+ posthog?.identify(userId, properties);},track: (eventName: string, properties: Properties) => {if (!initialized) lazyInit();- posthog.capture(eventName, properties);+ posthog?.capture(eventName, properties);},setUserProperties: (properties) => {if (!initialized) lazyInit();- posthog.people.set(properties);+ posthog?.people.set(properties);},getFeatureFlag: (featureFlag: string) => {- if (!initialized) lazyInit();- return posthog.getFeatureFlagPayload(featureFlag);- },-- getFeatureFlagValue: (featureFlag: string) => {if (!initialized) {lazyInit();}++ // Check if PostHog is fully loaded using the built-in __loaded property+ if (!posthog.__loaded) {+ console.warn(+ `PostHog not fully loaded when checking flag: ${featureFlag}. This may return bootstrap/default values.`,+ );+ }+return posthog.getFeatureFlag(featureFlag);},@@ -69,6 +77,6 @@ export const PostHog = {if (!initialized) {lazyInit();}- posthog.reloadFeatureFlags();+ posthog?.reloadFeatureFlags();},};diff --git a/packages/app/src/shared/state_stores/auth/slices/base.slice.ts b/packages/app/src/shared/state_stores/auth/slices/base.slice.tsindex 1195ff99..26138a49 100644--- a/packages/app/src/shared/state_stores/auth/slices/base.slice.ts+++ b/packages/app/src/shared/state_stores/auth/slices/base.slice.ts@@ -5,11 +5,11 @@ import {getTeamSubs,getUserTeamMembers,} from '@react/features/teams/clients/team-api';-import { PostHog } from '@src/builder-ui/services/posthog';import { getUserInfo } from '@src/react/features/account/clients';import { getUserOnboardingInfo } from '@src/react/features/onboarding/clients';import { getUserSettings } from '@src/react/shared/hooks/useUserSettings';import { IMembershipTeam } from '@src/react/shared/types/entities';+import { PostHog } from '@src/shared/posthog';import { StateCreator } from 'zustand';import { FEATURE_FLAGS } from '../../../constants/featureflags';import { userSettingKeys } from '../../../userSettingKeys';