1+ import opn from 'opn' ;
12import type { WorkflowConfig } from '../workflow-step.js' ;
23import type { WorkflowRun } from '../../agent/agent-runner.js' ;
34import type { WizardSession } from '../../wizard-session.js' ;
@@ -15,8 +16,24 @@ import { analytics } from '../../../utils/analytics.js';
1516import { WIZARD_INTERACTION_EVENT_NAME } from '../../constants.js' ;
1617import { getUI } from '../../../ui/index.js' ;
1718import { getCloudUrlFromRegion } from '../../../utils/urls.js' ;
19+ import { requestDeepLink } from '../../../utils/provisioning.js' ;
20+ import type { CloudRegion } from '../../../utils/types.js' ;
1821import { POSTHOG_INTEGRATION_WORKFLOW } from './steps.js' ;
1922
23+ const DASHBOARD_DEEP_LINK_KEY = 'dashboardDeepLink' ;
24+
25+ function resolveContinueUrl (
26+ sess : WizardSession ,
27+ cloudRegion : CloudRegion | undefined ,
28+ deepLink : unknown ,
29+ ) : string | undefined {
30+ if ( ! sess . signup ) return undefined ;
31+ if ( typeof deepLink === 'string' && deepLink ) return deepLink ;
32+ if ( cloudRegion )
33+ return `${ getCloudUrlFromRegion ( cloudRegion ) } /products?source=wizard` ;
34+ return undefined ;
35+ }
36+
2037export const SETUP_REPORT_FILE = 'posthog-setup-report.md' ;
2138export const EVENT_PLAN_FILE = '.posthog-events.json' ;
2239
@@ -165,17 +182,30 @@ Important: Use the detect_package_manager tool (from the wizard-tools MCP server
165182 } ) ;
166183 }
167184 }
185+
186+ if ( sess . signup ) {
187+ const deepLink = await requestDeepLink (
188+ credentials . accessToken ,
189+ credentials . host ,
190+ ) ;
191+ if ( deepLink ) {
192+ sess . frameworkContext [ DASHBOARD_DEEP_LINK_KEY ] = deepLink ;
193+ if ( process . env . NODE_ENV !== 'test' ) {
194+ opn ( deepLink , { wait : false } ) . catch ( ( ) => {
195+ // opn throws in environments without a browser
196+ } ) ;
197+ }
198+ }
199+ }
168200 } ,
169201
170202 buildOutroData : ( sess , credentials , cloudRegion ) => {
171203 const envVars = config . environment . getEnvVars (
172204 credentials . projectApiKey ,
173205 credentials . host ,
174206 ) ;
175- const continueUrl =
176- sess . signup && cloudRegion
177- ? `${ getCloudUrlFromRegion ( cloudRegion ) } /products?source=wizard`
178- : undefined ;
207+ const deepLink = sess . frameworkContext [ DASHBOARD_DEEP_LINK_KEY ] ;
208+ const continueUrl = resolveContinueUrl ( sess , cloudRegion , deepLink ) ;
179209
180210 const changes = [
181211 ...config . ui . getOutroChanges ( frameworkContext ) ,
0 commit comments