@posthog/wizard
Version:
The PostHog wizard helps you to configure your project
160 lines • 7 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runFlaskWizardAgent = runFlaskWizardAgent;
const debug_1 = require("../utils/debug");
const agent_runner_1 = require("../lib/agent-runner");
const constants_1 = require("../lib/constants");
const clack_1 = __importDefault(require("../utils/clack"));
const chalk_1 = __importDefault(require("chalk"));
const semver = __importStar(require("semver"));
const utils_1 = require("./utils");
/**
* Flask framework configuration for the universal agent runner
*/
const MINIMUM_FLASK_VERSION = '2.0.0';
const FLASK_AGENT_CONFIG = {
metadata: {
name: 'Flask',
integration: constants_1.Integration.flask,
docsUrl: 'https://posthog.com/docs/libraries/python',
unsupportedVersionDocsUrl: 'https://posthog.com/docs/libraries/python',
gatherContext: async (options) => {
const projectType = await (0, utils_1.getFlaskProjectType)(options);
const appFile = await (0, utils_1.findFlaskAppFile)(options);
return { projectType, appFile };
},
},
detection: {
packageName: 'flask',
packageDisplayName: 'Flask',
usesPackageJson: false,
getVersion: (_packageJson) => {
// For Flask, we don't use package.json. Version is extracted separately
// from requirements.txt or pyproject.toml in the wizard entry point
return undefined;
},
getVersionBucket: utils_1.getFlaskVersionBucket,
},
environment: {
uploadToHosting: false,
getEnvVars: (apiKey, host) => ({
POSTHOG_API_KEY: apiKey,
POSTHOG_HOST: host,
}),
},
analytics: {
getTags: (context) => {
const projectType = context.projectType;
return {
projectType: projectType || 'unknown',
};
},
},
prompts: {
projectTypeDetection: 'This is a Python/Flask project. Look for requirements.txt, pyproject.toml, setup.py, Pipfile, or app.py/wsgi.py to confirm.',
packageInstallation: 'Use pip, poetry, or pipenv based on existing config files (requirements.txt, pyproject.toml, Pipfile). Do not pin the posthog version - just add "posthog" without version constraints.',
getAdditionalContextLines: (context) => {
const projectType = context.projectType;
const projectTypeName = projectType
? (0, utils_1.getFlaskProjectTypeName)(projectType)
: 'unknown';
// Map project type to framework ID for MCP docs resource
const frameworkIdMap = {
[utils_1.FlaskProjectType.STANDARD]: 'flask',
[utils_1.FlaskProjectType.RESTFUL]: 'flask',
[utils_1.FlaskProjectType.RESTX]: 'flask',
[utils_1.FlaskProjectType.SMOREST]: 'flask',
[utils_1.FlaskProjectType.BLUEPRINT]: 'flask',
};
const frameworkId = projectType ? frameworkIdMap[projectType] : 'flask';
const lines = [
`Project type: ${projectTypeName}`,
`Framework docs ID: ${frameworkId} (use posthog://docs/frameworks/${frameworkId} for documentation)`,
];
if (context.appFile) {
lines.push(`App file: ${context.appFile}`);
}
return lines;
},
},
ui: {
successMessage: 'PostHog integration complete',
estimatedDurationMinutes: 5,
getOutroChanges: (context) => {
const projectType = context.projectType;
const projectTypeName = projectType
? (0, utils_1.getFlaskProjectTypeName)(projectType)
: 'Flask';
return [
`Analyzed your ${projectTypeName} project structure`,
`Installed the PostHog Python package`,
`Configured PostHog in your Flask application`,
`Added PostHog initialization with automatic event tracking`,
];
},
getOutroNextSteps: () => [
'Start your Flask development server to see PostHog in action',
'Visit your PostHog dashboard to see incoming events',
'Use posthog.identify() to associate events with users',
],
},
};
/**
* Flask wizard powered by the universal agent runner.
*/
async function runFlaskWizardAgent(options) {
if (options.debug) {
(0, debug_1.enableDebugLogs)();
}
// Check Flask version - agent wizard requires >= 2.0.0
const flaskVersion = await (0, utils_1.getFlaskVersion)(options);
if (flaskVersion) {
const coercedVersion = semver.coerce(flaskVersion);
if (coercedVersion && semver.lt(coercedVersion, MINIMUM_FLASK_VERSION)) {
const docsUrl = FLASK_AGENT_CONFIG.metadata.unsupportedVersionDocsUrl ??
FLASK_AGENT_CONFIG.metadata.docsUrl;
clack_1.default.log.warn(`Sorry: the wizard can't help you with Flask ${flaskVersion}. Upgrade to Flask ${MINIMUM_FLASK_VERSION} or later, or check out the manual setup guide.`);
clack_1.default.log.info(`Setup Flask manually: ${chalk_1.default.cyan(docsUrl)}`);
clack_1.default.outro('PostHog wizard will see you next time!');
return;
}
}
await (0, agent_runner_1.runAgentWizard)(FLASK_AGENT_CONFIG, options);
}
//# sourceMappingURL=flask-wizard-agent.js.map