@posthog/wizard 1.19.0 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/src/lib/agent-interface.d.ts +36 -1
  2. package/dist/src/lib/agent-interface.js +119 -4
  3. package/dist/src/lib/agent-interface.js.map +1 -1
  4. package/dist/src/lib/agent-runner.d.ts +7 -0
  5. package/dist/src/lib/agent-runner.js +201 -0
  6. package/dist/src/lib/agent-runner.js.map +1 -0
  7. package/dist/src/lib/constants.d.ts +1 -0
  8. package/dist/src/lib/constants.js +2 -1
  9. package/dist/src/lib/constants.js.map +1 -1
  10. package/dist/src/lib/framework-config.d.ts +95 -0
  11. package/dist/src/lib/framework-config.js +3 -0
  12. package/dist/src/lib/framework-config.js.map +1 -0
  13. package/dist/src/nextjs/nextjs-wizard-agent.d.ts +1 -1
  14. package/dist/src/nextjs/nextjs-wizard-agent.js +69 -133
  15. package/dist/src/nextjs/nextjs-wizard-agent.js.map +1 -1
  16. package/dist/src/steps/add-mcp-server-to-clients/MCPClient.d.ts +2 -7
  17. package/dist/src/steps/add-mcp-server-to-clients/MCPClient.js.map +1 -1
  18. package/dist/src/steps/add-mcp-server-to-clients/clients/claude-code.d.ts +33 -7
  19. package/dist/src/steps/add-mcp-server-to-clients/clients/claude-code.js +2 -47
  20. package/dist/src/steps/add-mcp-server-to-clients/clients/claude-code.js.map +1 -1
  21. package/dist/src/steps/add-mcp-server-to-clients/clients/claude.d.ts +33 -6
  22. package/dist/src/steps/add-mcp-server-to-clients/clients/codex.d.ts +33 -6
  23. package/dist/src/steps/add-mcp-server-to-clients/clients/cursor.d.ts +35 -7
  24. package/dist/src/steps/add-mcp-server-to-clients/clients/cursor.js +4 -1
  25. package/dist/src/steps/add-mcp-server-to-clients/clients/cursor.js.map +1 -1
  26. package/dist/src/steps/add-mcp-server-to-clients/clients/visual-studio-code.d.ts +47 -7
  27. package/dist/src/steps/add-mcp-server-to-clients/clients/visual-studio-code.js +25 -5
  28. package/dist/src/steps/add-mcp-server-to-clients/clients/visual-studio-code.js.map +1 -1
  29. package/dist/src/steps/add-mcp-server-to-clients/clients/zed.d.ts +47 -16
  30. package/dist/src/steps/add-mcp-server-to-clients/clients/zed.js +22 -11
  31. package/dist/src/steps/add-mcp-server-to-clients/clients/zed.js.map +1 -1
  32. package/dist/src/steps/add-mcp-server-to-clients/defaults.d.ts +40 -6
  33. package/dist/src/steps/add-mcp-server-to-clients/defaults.js +29 -8
  34. package/dist/src/steps/add-mcp-server-to-clients/defaults.js.map +1 -1
  35. package/dist/src/utils/__tests__/analytics.test.js +11 -10
  36. package/dist/src/utils/__tests__/analytics.test.js.map +1 -1
  37. package/dist/src/utils/analytics.js +1 -1
  38. package/dist/src/utils/analytics.js.map +1 -1
  39. package/dist/src/utils/oauth.js +42 -4
  40. package/dist/src/utils/oauth.js.map +1 -1
  41. package/package.json +2 -2
@@ -5,12 +5,43 @@
5
5
  import clack from '../utils/clack';
6
6
  import type { WizardOptions } from '../utils/types';
7
7
  type Agent = any;
8
+ export declare const AgentSignals: {
9
+ /** Signal emitted when the agent reports progress to the user */
10
+ readonly STATUS: "[STATUS]";
11
+ /** Signal emitted when the agent cannot access the PostHog MCP server */
12
+ readonly ERROR_MCP_MISSING: "[ERROR-MCP-MISSING]";
13
+ /** Signal emitted when the agent cannot access the setup resource */
14
+ readonly ERROR_RESOURCE_MISSING: "[ERROR-RESOURCE-MISSING]";
15
+ };
16
+ export type AgentSignal = (typeof AgentSignals)[keyof typeof AgentSignals];
17
+ /**
18
+ * Error types that can be returned from agent execution.
19
+ * These correspond to the error signals that the agent emits.
20
+ */
21
+ export declare enum AgentErrorType {
22
+ /** Agent could not access the PostHog MCP server */
23
+ MCP_MISSING = "WIZARD_MCP_MISSING",
24
+ /** Agent could not access the setup resource */
25
+ RESOURCE_MISSING = "WIZARD_RESOURCE_MISSING"
26
+ }
8
27
  export type AgentConfig = {
9
28
  workingDirectory: string;
10
29
  posthogMcpUrl: string;
11
30
  posthogApiKey: string;
12
31
  debug?: boolean;
13
32
  };
33
+ /**
34
+ * Permission hook that allows only safe package manager commands.
35
+ * This prevents the agent from running arbitrary shell commands.
36
+ */
37
+ export declare function wizardCanUseTool(toolName: string, input: {
38
+ command?: string;
39
+ }): {
40
+ behavior: 'allow';
41
+ } | {
42
+ behavior: 'deny';
43
+ message: string;
44
+ };
14
45
  /**
15
46
  * Initialize a PostHog Agent instance with the provided configuration
16
47
  */
@@ -18,11 +49,15 @@ export declare function initializeAgent(config: AgentConfig, options: WizardOpti
18
49
  /**
19
50
  * Execute an agent with the provided prompt and options
20
51
  * Handles the full lifecycle: spinner, execution, error handling
52
+ *
53
+ * @returns An object containing any error detected in the agent's output
21
54
  */
22
55
  export declare function runAgent(agent: Agent, prompt: string, options: WizardOptions, spinner: ReturnType<typeof clack.spinner>, config?: {
23
56
  estimatedDurationMinutes?: number;
24
57
  spinnerMessage?: string;
25
58
  successMessage?: string;
26
59
  errorMessage?: string;
27
- }): Promise<void>;
60
+ }): Promise<{
61
+ error?: AgentErrorType;
62
+ }>;
28
63
  export {};
@@ -7,6 +7,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  return (mod && mod.__esModule) ? mod : { "default": mod };
8
8
  };
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.AgentErrorType = exports.AgentSignals = void 0;
11
+ exports.wizardCanUseTool = wizardCanUseTool;
10
12
  exports.initializeAgent = initializeAgent;
11
13
  exports.runAgent = runAgent;
12
14
  const clack_1 = __importDefault(require("../utils/clack"));
@@ -29,6 +31,77 @@ const EventType = {
29
31
  ERROR: 'error',
30
32
  DONE: 'done',
31
33
  };
34
+ /**
35
+ * Content types for agent messages and blocks
36
+ */
37
+ const ContentType = {
38
+ TEXT: 'text',
39
+ ASSISTANT: 'assistant',
40
+ };
41
+ exports.AgentSignals = {
42
+ /** Signal emitted when the agent reports progress to the user */
43
+ STATUS: '[STATUS]',
44
+ /** Signal emitted when the agent cannot access the PostHog MCP server */
45
+ ERROR_MCP_MISSING: '[ERROR-MCP-MISSING]',
46
+ /** Signal emitted when the agent cannot access the setup resource */
47
+ ERROR_RESOURCE_MISSING: '[ERROR-RESOURCE-MISSING]',
48
+ };
49
+ /**
50
+ * Error types that can be returned from agent execution.
51
+ * These correspond to the error signals that the agent emits.
52
+ */
53
+ var AgentErrorType;
54
+ (function (AgentErrorType) {
55
+ /** Agent could not access the PostHog MCP server */
56
+ AgentErrorType["MCP_MISSING"] = "WIZARD_MCP_MISSING";
57
+ /** Agent could not access the setup resource */
58
+ AgentErrorType["RESOURCE_MISSING"] = "WIZARD_RESOURCE_MISSING";
59
+ })(AgentErrorType || (exports.AgentErrorType = AgentErrorType = {}));
60
+ /**
61
+ * Allowed bash command prefixes for the wizard agent.
62
+ * These are package manager commands needed for PostHog installation.
63
+ */
64
+ const ALLOWED_BASH_PREFIXES = [
65
+ // Package installation
66
+ 'npm install',
67
+ 'npm ci',
68
+ 'pnpm install',
69
+ 'pnpm add',
70
+ 'bun install',
71
+ 'bun add',
72
+ 'yarn add',
73
+ 'yarn install',
74
+ ];
75
+ /**
76
+ * Permission hook that allows only safe package manager commands.
77
+ * This prevents the agent from running arbitrary shell commands.
78
+ */
79
+ function wizardCanUseTool(toolName, input) {
80
+ // Allow all non-Bash tools
81
+ if (toolName !== 'Bash') {
82
+ return { behavior: 'allow' };
83
+ }
84
+ const command = (input.command ?? '').trim();
85
+ // Block commands with shell operators (chaining, subshells, etc.)
86
+ if (/[;&|`$()]/.test(command)) {
87
+ (0, debug_1.debug)(`Denying bash command with shell operators: ${command}`);
88
+ return {
89
+ behavior: 'deny',
90
+ message: `Bash command not allowed. Chained commands are not permitted.`,
91
+ };
92
+ }
93
+ // Check if command starts with any allowed prefix
94
+ const isAllowed = ALLOWED_BASH_PREFIXES.some((prefix) => command.startsWith(prefix));
95
+ if (isAllowed) {
96
+ (0, debug_1.debug)(`Allowing bash command: ${command}`);
97
+ return { behavior: 'allow' };
98
+ }
99
+ (0, debug_1.debug)(`Denying bash command: ${command}`);
100
+ return {
101
+ behavior: 'deny',
102
+ message: `Bash command not allowed. Only package manager commands (npm/pnpm/bun/yarn install) are permitted.`,
103
+ };
104
+ }
32
105
  /**
33
106
  * Initialize a PostHog Agent instance with the provided configuration
34
107
  */
@@ -74,15 +147,16 @@ function handleAgentEvent(event, options, spinner) {
74
147
  // Only show [STATUS] events to the user - everything else goes to debug log
75
148
  switch (event.type) {
76
149
  case EventType.RAW_SDK_EVENT:
77
- if (event.sdkMessage?.type === 'assistant') {
150
+ if (event.sdkMessage?.type === ContentType.ASSISTANT) {
78
151
  const message = event.sdkMessage.message;
79
152
  if (message?.content && Array.isArray(message.content)) {
80
153
  const textContent = message.content
81
- .filter((block) => block.type === 'text')
154
+ .filter((block) => block.type === ContentType.TEXT)
82
155
  .map((block) => block.text)
83
156
  .join('\n');
84
157
  // Check if the text contains a [STATUS] marker
85
- const statusMatch = textContent.match(/^.*\[STATUS\]\s*(.+?)$/m);
158
+ const statusRegex = new RegExp(`^.*${exports.AgentSignals.STATUS.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*(.+?)$`, 'm');
159
+ const statusMatch = textContent.match(statusRegex);
86
160
  if (statusMatch) {
87
161
  // Stop spinner, log the status step, restart spinner
88
162
  // This creates the progress list as the agent proceeds
@@ -145,6 +219,8 @@ function handleAgentEvent(event, options, spinner) {
145
219
  /**
146
220
  * Execute an agent with the provided prompt and options
147
221
  * Handles the full lifecycle: spinner, execution, error handling
222
+ *
223
+ * @returns An object containing any error detected in the agent's output
148
224
  */
149
225
  async function runAgent(agent, prompt, options, spinner, config) {
150
226
  const { estimatedDurationMinutes = 8, spinnerMessage = 'Customizing your PostHog setup...', successMessage = 'PostHog integration complete', errorMessage = 'Integration failed', } = config ?? {};
@@ -152,11 +228,26 @@ async function runAgent(agent, prompt, options, spinner, config) {
152
228
  clack_1.default.log.step(`This whole process should take about ${estimatedDurationMinutes} minutes including error checking and fixes.\n\nGrab some coffee!`);
153
229
  spinner.start(spinnerMessage);
154
230
  try {
155
- await agent.run(prompt, {
231
+ const result = await agent.run(prompt, {
156
232
  repositoryPath: options.installDir,
157
233
  permissionMode: PermissionMode.ACCEPT_EDITS,
234
+ queryOverrides: {
235
+ model: 'claude-opus-4-5-20251101',
236
+ canUseTool: wizardCanUseTool,
237
+ },
158
238
  });
239
+ // Check for error markers in the agent's output
240
+ const outputText = extractTextFromResults(result.results);
241
+ if (outputText.includes(exports.AgentSignals.ERROR_MCP_MISSING)) {
242
+ spinner.stop('Agent could not access PostHog MCP');
243
+ return { error: AgentErrorType.MCP_MISSING };
244
+ }
245
+ if (outputText.includes(exports.AgentSignals.ERROR_RESOURCE_MISSING)) {
246
+ spinner.stop('Agent could not access setup resource');
247
+ return { error: AgentErrorType.RESOURCE_MISSING };
248
+ }
159
249
  spinner.stop(successMessage);
250
+ return {};
160
251
  }
161
252
  catch (error) {
162
253
  spinner.stop(errorMessage);
@@ -165,4 +256,28 @@ async function runAgent(agent, prompt, options, spinner, config) {
165
256
  throw error;
166
257
  }
167
258
  }
259
+ /**
260
+ * Extract text content from agent execution results
261
+ */
262
+ function extractTextFromResults(results) {
263
+ const textParts = [];
264
+ for (const result of results) {
265
+ // Handle assistant messages with content blocks
266
+ if (result?.type === ContentType.ASSISTANT && result.message?.content) {
267
+ const content = result.message.content;
268
+ if (Array.isArray(content)) {
269
+ for (const block of content) {
270
+ if (block.type === ContentType.TEXT && block.text) {
271
+ textParts.push(block.text);
272
+ }
273
+ }
274
+ }
275
+ }
276
+ // Handle direct text content
277
+ if (typeof result === 'string') {
278
+ textParts.push(result);
279
+ }
280
+ }
281
+ return textParts.join('\n');
282
+ }
168
283
  //# sourceMappingURL=agent-interface.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-interface.js","sourceRoot":"","sources":["../../../src/lib/agent-interface.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAyCH,0CAoCC;AAoGD,4BAsCC;AArND,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AG,mCAAmC,EACpD,cAAc,GAAG,8BAA8B,EAC/C,YAAY,GAAG,oBAAoB,GACpC,GAAG,MAAM,IAAI,EAAE,CAAC;IACjB,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,cAAc,EAAE,CAAC;IAElD,eAAK,CAAC,GAAG,CAAC,IAAI,CACZ,wCAAwC,wBAAwB,mEAAmE,CACpI,CAAC;IAEF,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAE9B,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE;YACtB,cAAc,EAAE,OAAO,CAAC,UAAU;YAClC,cAAc,EAAE,cAAc,CAAC,YAAY;SAC5C,CAAC,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC3B,eAAK,CAAC,GAAG,CAAC,KAAK,CAAC,UAAW,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QACtD,IAAA,aAAK,EAAC,aAAa,EAAE,KAAK,CAAC,CAAC;QAC5B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["/**\n * Shared agent interface for PostHog wizards\n * Provides common agent initialization and event handling\n */\n\nimport clack from '../utils/clack';\nimport { debug } from '../utils/debug';\nimport type { WizardOptions } from '../utils/types';\nimport { analytics } from '../utils/analytics';\nimport { WIZARD_INTERACTION_EVENT_NAME } from './constants';\n\nlet _agentModule: any = null;\nasync function getAgentModule(): Promise<any> {\n if (!_agentModule) {\n _agentModule = await import('@posthog/agent');\n }\n return _agentModule;\n}\n\n// Using `any` because typed imports from ESM modules require import attributes\n// syntax which prettier cannot parse. See PR discussion for details.\ntype Agent = any;\ntype AgentEvent = any;\n\n// TODO: Remove these if/when posthog/agent exports an enum for events\nconst EventType = {\n RAW_SDK_EVENT: 'raw_sdk_event',\n TOKEN: 'token',\n TOOL_CALL: 'tool_call',\n TOOL_RESULT: 'tool_result',\n ERROR: 'error',\n DONE: 'done',\n} as const;\n\nexport type AgentConfig = {\n workingDirectory: string;\n posthogMcpUrl: string;\n posthogApiKey: string;\n debug?: boolean;\n};\n\n/**\n * Initialize a PostHog Agent instance with the provided configuration\n */\nexport async function initializeAgent(\n config: AgentConfig,\n options: WizardOptions,\n spinner: ReturnType<typeof clack.spinner>,\n): Promise<Agent> {\n clack.log.step('Initializing PostHog agent...');\n\n try {\n const { Agent } = await getAgentModule();\n\n const agentConfig = {\n workingDirectory: config.workingDirectory,\n posthogMcpUrl: config.posthogMcpUrl,\n posthogApiKey: config.posthogApiKey,\n onEvent: (event: AgentEvent) => {\n handleAgentEvent(event, options, spinner);\n },\n debug: config.debug ?? false,\n };\n\n if (options.debug) {\n debug('Agent config:', {\n workingDirectory: agentConfig.workingDirectory,\n posthogMcpUrl: agentConfig.posthogMcpUrl,\n posthogApiKeyPresent: !!agentConfig.posthogApiKey,\n });\n }\n\n const agent = new Agent(agentConfig);\n clack.log.success(\"Agent initialized. Let's get cooking!\");\n return agent;\n } catch (error) {\n clack.log.error(`Failed to initialize agent: ${(error as Error).message}`);\n debug('Agent initialization error:', error);\n throw error;\n }\n}\n\n/**\n * Handle agent events and provide user feedback\n * This function processes events from the agent SDK and provides appropriate\n * user feedback through the CLI spinner and logging\n */\nfunction handleAgentEvent(\n event: AgentEvent,\n options: WizardOptions,\n spinner: ReturnType<typeof clack.spinner>,\n): void {\n if (options.debug) {\n debug(`Event type: ${event.type}`, JSON.stringify(event, null, 2));\n }\n\n // Only show [STATUS] events to the user - everything else goes to debug log\n switch (event.type) {\n case EventType.RAW_SDK_EVENT:\n if (event.sdkMessage?.type === 'assistant') {\n const message = event.sdkMessage.message;\n if (message?.content && Array.isArray(message.content)) {\n const textContent = message.content\n .filter((block: any) => block.type === 'text')\n .map((block: any) => block.text)\n .join('\\n');\n\n // Check if the text contains a [STATUS] marker\n const statusMatch = textContent.match(/^.*\\[STATUS\\]\\s*(.+?)$/m);\n if (statusMatch) {\n // Stop spinner, log the status step, restart spinner\n // This creates the progress list as the agent proceeds\n spinner.stop(statusMatch[1].trim());\n spinner.start('Integrating PostHog...');\n }\n }\n }\n break;\n\n case EventType.TOKEN:\n if (options.debug) {\n debug(event.content);\n }\n break;\n\n case EventType.TOOL_CALL:\n if (options.debug) {\n debug(`Tool: ${event.toolName}`);\n debug(' Args:', JSON.stringify(event.args, null, 2));\n }\n break;\n\n case EventType.TOOL_RESULT:\n if (options.debug) {\n debug(`✅ ${event.toolName} completed`);\n const resultStr: string =\n typeof event.result === 'string'\n ? event.result\n : JSON.stringify(event.result, null, 2);\n const truncated =\n resultStr.length > 500\n ? `${resultStr.substring(0, 500)}...`\n : resultStr;\n debug(' Result:', truncated);\n }\n break;\n\n case EventType.ERROR:\n // Always show errors to user\n clack.log.error(`Error: ${event.message}`);\n if (options.debug && event.error) {\n debug('Error details:', event.error);\n }\n if (event.error instanceof Error) {\n analytics.captureException(event.error, {\n event_type: event.type,\n message: event.message,\n });\n }\n break;\n\n case EventType.DONE:\n if (event.durationMs) {\n if (options.debug) {\n debug(`Completed in ${Math.round(event.durationMs / 1000)}s`);\n }\n analytics.capture(WIZARD_INTERACTION_EVENT_NAME, {\n action: 'agent integration completed',\n duration_ms: event.durationMs,\n duration_seconds: Math.round(event.durationMs / 1000),\n });\n }\n break;\n }\n}\n\n/**\n * Execute an agent with the provided prompt and options\n * Handles the full lifecycle: spinner, execution, error handling\n */\nexport async function runAgent(\n agent: Agent,\n prompt: string,\n options: WizardOptions,\n spinner: ReturnType<typeof clack.spinner>,\n config?: {\n estimatedDurationMinutes?: number;\n spinnerMessage?: string;\n successMessage?: string;\n errorMessage?: string;\n },\n): Promise<void> {\n const {\n estimatedDurationMinutes = 8,\n spinnerMessage = 'Customizing your PostHog setup...',\n successMessage = 'PostHog integration complete',\n errorMessage = 'Integration failed',\n } = config ?? {};\n const { PermissionMode } = await getAgentModule();\n\n clack.log.step(\n `This whole process should take about ${estimatedDurationMinutes} minutes including error checking and fixes.\\n\\nGrab some coffee!`,\n );\n\n spinner.start(spinnerMessage);\n\n try {\n await agent.run(prompt, {\n repositoryPath: options.installDir,\n permissionMode: PermissionMode.ACCEPT_EDITS,\n });\n spinner.stop(successMessage);\n } catch (error) {\n spinner.stop(errorMessage);\n clack.log.error(`Error: ${(error as Error).message}`);\n debug('Full error:', error);\n throw error;\n }\n}\n"]}
1
+ {"version":3,"file":"agent-interface.js","sourceRoot":"","sources":["../../../src/lib/agent-interface.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAwFH,4CAkCC;AAKD,0CAoCC;AA6GD,4BAyDC;AAvUD,2DAAmC;AACnC,0CAAuC;AAEvC,kDAA+C;AAC/C,2CAA4D;AAE5D,IAAI,YAAY,GAAQ,IAAI,CAAC;AAC7B,KAAK,UAAU,cAAc;IAC3B,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAOD,sEAAsE;AACtE,MAAM,SAAS,GAAG;IAChB,aAAa,EAAE,eAAe;IAC9B,KAAK,EAAE,OAAO;IACd,SAAS,EAAE,WAAW;IACtB,WAAW,EAAE,aAAa;IAC1B,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;CACJ,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,WAAW;CACd,CAAC;AAEE,QAAA,YAAY,GAAG;IAC1B,iEAAiE;IACjE,MAAM,EAAE,UAAU;IAClB,yEAAyE;IACzE,iBAAiB,EAAE,qBAAqB;IACxC,qEAAqE;IACrE,sBAAsB,EAAE,0BAA0B;CAC1C,CAAC;AAIX;;;GAGG;AACH,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,oDAAoD;IACpD,oDAAkC,CAAA;IAClC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AC,OAAO,EAAE,OAAO,EAAE,CAAC;YACtE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC;YACvC,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC3B,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;oBAC5B,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;wBAClD,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBAC7B,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,6BAA6B;QAC7B,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["/**\n * Shared agent interface for PostHog wizards\n * Provides common agent initialization and event handling\n */\n\nimport clack from '../utils/clack';\nimport { debug } from '../utils/debug';\nimport type { WizardOptions } from '../utils/types';\nimport { analytics } from '../utils/analytics';\nimport { WIZARD_INTERACTION_EVENT_NAME } from './constants';\n\nlet _agentModule: any = null;\nasync function getAgentModule(): Promise<any> {\n if (!_agentModule) {\n _agentModule = await import('@posthog/agent');\n }\n return _agentModule;\n}\n\n// Using `any` because typed imports from ESM modules require import attributes\n// syntax which prettier cannot parse. See PR discussion for details.\ntype Agent = any;\ntype AgentEvent = any;\n\n// TODO: Remove these if/when posthog/agent exports an enum for events\nconst EventType = {\n RAW_SDK_EVENT: 'raw_sdk_event',\n TOKEN: 'token',\n TOOL_CALL: 'tool_call',\n TOOL_RESULT: 'tool_result',\n ERROR: 'error',\n DONE: 'done',\n} as const;\n\n/**\n * Content types for agent messages and blocks\n */\nconst ContentType = {\n TEXT: 'text',\n ASSISTANT: 'assistant',\n} as const;\n\nexport const AgentSignals = {\n /** Signal emitted when the agent reports progress to the user */\n STATUS: '[STATUS]',\n /** Signal emitted when the agent cannot access the PostHog MCP server */\n ERROR_MCP_MISSING: '[ERROR-MCP-MISSING]',\n /** Signal emitted when the agent cannot access the setup resource */\n ERROR_RESOURCE_MISSING: '[ERROR-RESOURCE-MISSING]',\n} as const;\n\nexport type AgentSignal = (typeof AgentSignals)[keyof typeof AgentSignals];\n\n/**\n * Error types that can be returned from agent execution.\n * These correspond to the error signals that the agent emits.\n */\nexport enum AgentErrorType {\n /** Agent could not access the PostHog MCP server */\n MCP_MISSING = 'WIZARD_MCP_MISSING',\n /** Agent could not access the setup resource */\n RESOURCE_MISSING = 'WIZARD_RESOURCE_MISSING',\n}\n\nexport type AgentConfig = {\n workingDirectory: string;\n posthogMcpUrl: string;\n posthogApiKey: string;\n debug?: boolean;\n};\n\n/**\n * Allowed bash command prefixes for the wizard agent.\n * These are package manager commands needed for PostHog installation.\n */\nconst ALLOWED_BASH_PREFIXES = [\n // Package installation\n 'npm install',\n 'npm ci',\n 'pnpm install',\n 'pnpm add',\n 'bun install',\n 'bun add',\n 'yarn add',\n 'yarn install',\n];\n\n/**\n * Permission hook that allows only safe package manager commands.\n * This prevents the agent from running arbitrary shell commands.\n */\nexport function wizardCanUseTool(\n toolName: string,\n input: { command?: string },\n): { behavior: 'allow' } | { behavior: 'deny'; message: string } {\n // Allow all non-Bash tools\n if (toolName !== 'Bash') {\n return { behavior: 'allow' };\n }\n\n const command = (input.command ?? '').trim();\n // Block commands with shell operators (chaining, subshells, etc.)\n if (/[;&|`$()]/.test(command)) {\n debug(`Denying bash command with shell operators: ${command}`);\n return {\n behavior: 'deny',\n message: `Bash command not allowed. Chained commands are not permitted.`,\n };\n }\n\n // Check if command starts with any allowed prefix\n const isAllowed = ALLOWED_BASH_PREFIXES.some((prefix) =>\n command.startsWith(prefix),\n );\n\n if (isAllowed) {\n debug(`Allowing bash command: ${command}`);\n return { behavior: 'allow' };\n }\n\n debug(`Denying bash command: ${command}`);\n return {\n behavior: 'deny',\n message: `Bash command not allowed. Only package manager commands (npm/pnpm/bun/yarn install) are permitted.`,\n };\n}\n\n/**\n * Initialize a PostHog Agent instance with the provided configuration\n */\nexport async function initializeAgent(\n config: AgentConfig,\n options: WizardOptions,\n spinner: ReturnType<typeof clack.spinner>,\n): Promise<Agent> {\n clack.log.step('Initializing PostHog agent...');\n\n try {\n const { Agent } = await getAgentModule();\n\n const agentConfig = {\n workingDirectory: config.workingDirectory,\n posthogMcpUrl: config.posthogMcpUrl,\n posthogApiKey: config.posthogApiKey,\n onEvent: (event: AgentEvent) => {\n handleAgentEvent(event, options, spinner);\n },\n debug: config.debug ?? false,\n };\n\n if (options.debug) {\n debug('Agent config:', {\n workingDirectory: agentConfig.workingDirectory,\n posthogMcpUrl: agentConfig.posthogMcpUrl,\n posthogApiKeyPresent: !!agentConfig.posthogApiKey,\n });\n }\n\n const agent = new Agent(agentConfig);\n clack.log.success(\"Agent initialized. Let's get cooking!\");\n return agent;\n } catch (error) {\n clack.log.error(`Failed to initialize agent: ${(error as Error).message}`);\n debug('Agent initialization error:', error);\n throw error;\n }\n}\n\n/**\n * Handle agent events and provide user feedback\n * This function processes events from the agent SDK and provides appropriate\n * user feedback through the CLI spinner and logging\n */\nfunction handleAgentEvent(\n event: AgentEvent,\n options: WizardOptions,\n spinner: ReturnType<typeof clack.spinner>,\n): void {\n if (options.debug) {\n debug(`Event type: ${event.type}`, JSON.stringify(event, null, 2));\n }\n\n // Only show [STATUS] events to the user - everything else goes to debug log\n switch (event.type) {\n case EventType.RAW_SDK_EVENT:\n if (event.sdkMessage?.type === ContentType.ASSISTANT) {\n const message = event.sdkMessage.message;\n if (message?.content && Array.isArray(message.content)) {\n const textContent = message.content\n .filter((block: any) => block.type === ContentType.TEXT)\n .map((block: any) => block.text)\n .join('\\n');\n\n // Check if the text contains a [STATUS] marker\n const statusRegex = new RegExp(\n `^.*${AgentSignals.STATUS.replace(\n /[.*+?^${}()|[\\]\\\\]/g,\n '\\\\$&',\n )}\\\\s*(.+?)$`,\n 'm',\n );\n const statusMatch = textContent.match(statusRegex);\n if (statusMatch) {\n // Stop spinner, log the status step, restart spinner\n // This creates the progress list as the agent proceeds\n spinner.stop(statusMatch[1].trim());\n spinner.start('Integrating PostHog...');\n }\n }\n }\n break;\n\n case EventType.TOKEN:\n if (options.debug) {\n debug(event.content);\n }\n break;\n\n case EventType.TOOL_CALL:\n if (options.debug) {\n debug(`Tool: ${event.toolName}`);\n debug(' Args:', JSON.stringify(event.args, null, 2));\n }\n break;\n\n case EventType.TOOL_RESULT:\n if (options.debug) {\n debug(`✅ ${event.toolName} completed`);\n const resultStr: string =\n typeof event.result === 'string'\n ? event.result\n : JSON.stringify(event.result, null, 2);\n const truncated =\n resultStr.length > 500\n ? `${resultStr.substring(0, 500)}...`\n : resultStr;\n debug(' Result:', truncated);\n }\n break;\n\n case EventType.ERROR:\n // Always show errors to user\n clack.log.error(`Error: ${event.message}`);\n if (options.debug && event.error) {\n debug('Error details:', event.error);\n }\n if (event.error instanceof Error) {\n analytics.captureException(event.error, {\n event_type: event.type,\n message: event.message,\n });\n }\n break;\n\n case EventType.DONE:\n if (event.durationMs) {\n if (options.debug) {\n debug(`Completed in ${Math.round(event.durationMs / 1000)}s`);\n }\n analytics.capture(WIZARD_INTERACTION_EVENT_NAME, {\n action: 'agent integration completed',\n duration_ms: event.durationMs,\n duration_seconds: Math.round(event.durationMs / 1000),\n });\n }\n break;\n }\n}\n\n/**\n * Execute an agent with the provided prompt and options\n * Handles the full lifecycle: spinner, execution, error handling\n *\n * @returns An object containing any error detected in the agent's output\n */\nexport async function runAgent(\n agent: Agent,\n prompt: string,\n options: WizardOptions,\n spinner: ReturnType<typeof clack.spinner>,\n config?: {\n estimatedDurationMinutes?: number;\n spinnerMessage?: string;\n successMessage?: string;\n errorMessage?: string;\n },\n): Promise<{ error?: AgentErrorType }> {\n const {\n estimatedDurationMinutes = 8,\n spinnerMessage = 'Customizing your PostHog setup...',\n successMessage = 'PostHog integration complete',\n errorMessage = 'Integration failed',\n } = config ?? {};\n const { PermissionMode } = await getAgentModule();\n\n clack.log.step(\n `This whole process should take about ${estimatedDurationMinutes} minutes including error checking and fixes.\\n\\nGrab some coffee!`,\n );\n\n spinner.start(spinnerMessage);\n\n try {\n const result = await agent.run(prompt, {\n repositoryPath: options.installDir,\n permissionMode: PermissionMode.ACCEPT_EDITS,\n queryOverrides: {\n model: 'claude-opus-4-5-20251101',\n canUseTool: wizardCanUseTool,\n },\n });\n\n // Check for error markers in the agent's output\n const outputText = extractTextFromResults(result.results);\n\n if (outputText.includes(AgentSignals.ERROR_MCP_MISSING)) {\n spinner.stop('Agent could not access PostHog MCP');\n return { error: AgentErrorType.MCP_MISSING };\n }\n\n if (outputText.includes(AgentSignals.ERROR_RESOURCE_MISSING)) {\n spinner.stop('Agent could not access setup resource');\n return { error: AgentErrorType.RESOURCE_MISSING };\n }\n\n spinner.stop(successMessage);\n return {};\n } catch (error) {\n spinner.stop(errorMessage);\n clack.log.error(`Error: ${(error as Error).message}`);\n debug('Full error:', error);\n throw error;\n }\n}\n\n/**\n * Extract text content from agent execution results\n */\nfunction extractTextFromResults(results: any[]): string {\n const textParts: string[] = [];\n\n for (const result of results) {\n // Handle assistant messages with content blocks\n if (result?.type === ContentType.ASSISTANT && result.message?.content) {\n const content = result.message.content;\n if (Array.isArray(content)) {\n for (const block of content) {\n if (block.type === ContentType.TEXT && block.text) {\n textParts.push(block.text);\n }\n }\n }\n }\n\n // Handle direct text content\n if (typeof result === 'string') {\n textParts.push(result);\n }\n }\n\n return textParts.join('\\n');\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import type { FrameworkConfig } from './framework-config';
2
+ import type { WizardOptions } from '../utils/types';
3
+ /**
4
+ * Universal agent-powered wizard runner.
5
+ * Handles the complete flow for any framework using PostHog MCP integration.
6
+ */
7
+ export declare function runAgentWizard(config: FrameworkConfig, options: WizardOptions): Promise<void>;
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runAgentWizard = runAgentWizard;
7
+ const clack_utils_1 = require("../utils/clack-utils");
8
+ const analytics_1 = require("../utils/analytics");
9
+ const constants_1 = require("./constants");
10
+ const clack_1 = __importDefault(require("../utils/clack"));
11
+ const agent_interface_1 = require("./agent-interface");
12
+ const urls_1 = require("../utils/urls");
13
+ const chalk_1 = __importDefault(require("chalk"));
14
+ const steps_1 = require("../steps");
15
+ /**
16
+ * Universal agent-powered wizard runner.
17
+ * Handles the complete flow for any framework using PostHog MCP integration.
18
+ */
19
+ async function runAgentWizard(config, options) {
20
+ // Setup phase
21
+ (0, clack_utils_1.printWelcome)({ wizardName: config.ui.welcomeMessage });
22
+ clack_1.default.log.info(`🧙 The wizard has chosen you to try the next-generation agent integration for ${config.metadata.name}.\n\nStand by for the good stuff, and let me know how it goes:\n\ndanilo@posthog.com`);
23
+ const aiConsent = await (0, clack_utils_1.askForAIConsent)(options);
24
+ if (!aiConsent) {
25
+ await (0, clack_utils_1.abort)(config.metadata.abortMessage, 0);
26
+ }
27
+ const cloudRegion = options.cloudRegion ?? (await (0, clack_utils_1.askForCloudRegion)());
28
+ const typeScriptDetected = (0, clack_utils_1.isUsingTypeScript)(options);
29
+ await (0, clack_utils_1.confirmContinueIfNoOrDirtyGitRepo)(options);
30
+ // Framework detection and version
31
+ const packageJson = await (0, clack_utils_1.getPackageDotJson)(options);
32
+ await (0, clack_utils_1.ensurePackageIsInstalled)(packageJson, config.detection.packageName, config.detection.packageDisplayName);
33
+ const frameworkVersion = config.detection.getVersion(packageJson);
34
+ // Set analytics tags for framework version
35
+ if (frameworkVersion && config.detection.getVersionBucket) {
36
+ const versionBucket = config.detection.getVersionBucket(frameworkVersion);
37
+ analytics_1.analytics.setTag(`${config.metadata.integration}-version`, versionBucket);
38
+ }
39
+ analytics_1.analytics.capture(constants_1.WIZARD_INTERACTION_EVENT_NAME, {
40
+ action: 'started agent integration',
41
+ integration: config.metadata.integration,
42
+ });
43
+ // Get PostHog credentials
44
+ const { projectApiKey, host, accessToken } = await (0, clack_utils_1.getOrAskForProjectData)({
45
+ ...options,
46
+ cloudRegion,
47
+ });
48
+ // Gather framework-specific context (e.g., Next.js router, React Native platform)
49
+ const frameworkContext = config.metadata.gatherContext
50
+ ? await config.metadata.gatherContext(options)
51
+ : {};
52
+ // Set analytics tags from framework context
53
+ const contextTags = config.analytics.getTags(frameworkContext);
54
+ Object.entries(contextTags).forEach(([key, value]) => {
55
+ analytics_1.analytics.setTag(key, value);
56
+ });
57
+ // Build integration prompt
58
+ const integrationPrompt = buildIntegrationPrompt(config, {
59
+ frameworkVersion: frameworkVersion || 'latest',
60
+ typescript: typeScriptDetected,
61
+ projectApiKey,
62
+ host,
63
+ }, frameworkContext);
64
+ // Initialize and run agent
65
+ const spinner = clack_1.default.spinner();
66
+ const agent = await (0, agent_interface_1.initializeAgent)({
67
+ workingDirectory: options.installDir,
68
+ posthogMcpUrl: 'https://mcp.posthog.com/mcp',
69
+ posthogApiKey: accessToken,
70
+ debug: false,
71
+ }, options, spinner);
72
+ const agentResult = await (0, agent_interface_1.runAgent)(agent, integrationPrompt, options, spinner, {
73
+ estimatedDurationMinutes: config.ui.estimatedDurationMinutes,
74
+ spinnerMessage: config.ui.spinnerMessage,
75
+ successMessage: config.ui.successMessage,
76
+ errorMessage: 'Integration failed',
77
+ });
78
+ // Handle error cases detected in agent output
79
+ if (agentResult.error === agent_interface_1.AgentErrorType.MCP_MISSING) {
80
+ analytics_1.analytics.captureException(new Error('Agent could not access PostHog MCP server'), {
81
+ integration: config.metadata.integration,
82
+ error_type: agent_interface_1.AgentErrorType.MCP_MISSING,
83
+ signal: agent_interface_1.AgentSignals.ERROR_MCP_MISSING,
84
+ });
85
+ const errorMessage = `
86
+ ${chalk_1.default.red('❌ Could not access the PostHog MCP server')}
87
+
88
+ The wizard was unable to connect to the PostHog MCP server.
89
+ This could be due to a network issue or a configuration problem.
90
+
91
+ Please try again, or set up ${config.metadata.name} manually by following our documentation:
92
+ ${chalk_1.default.cyan(config.metadata.docsUrl)}`;
93
+ clack_1.default.outro(errorMessage);
94
+ await analytics_1.analytics.shutdown('error');
95
+ process.exit(1);
96
+ }
97
+ if (agentResult.error === agent_interface_1.AgentErrorType.RESOURCE_MISSING) {
98
+ analytics_1.analytics.captureException(new Error('Agent could not access setup resource'), {
99
+ integration: config.metadata.integration,
100
+ error_type: agent_interface_1.AgentErrorType.RESOURCE_MISSING,
101
+ signal: agent_interface_1.AgentSignals.ERROR_RESOURCE_MISSING,
102
+ });
103
+ const errorMessage = `
104
+ ${chalk_1.default.red('❌ Could not access the setup resource')}
105
+
106
+ The wizard could not access the setup resource. This may indicate a version mismatch or a temporary service issue.
107
+
108
+ Please try again, or set up ${config.metadata.name} manually by following our documentation:
109
+ ${chalk_1.default.cyan(config.metadata.docsUrl)}`;
110
+ clack_1.default.outro(errorMessage);
111
+ await analytics_1.analytics.shutdown('error');
112
+ process.exit(1);
113
+ }
114
+ // Build environment variables from OAuth credentials
115
+ const envVars = config.environment.getEnvVars(projectApiKey, host);
116
+ // Upload environment variables to hosting providers (if configured)
117
+ let uploadedEnvVars = [];
118
+ if (config.environment.uploadToHosting) {
119
+ uploadedEnvVars = await (0, steps_1.uploadEnvironmentVariablesStep)(envVars, {
120
+ integration: config.metadata.integration,
121
+ options,
122
+ });
123
+ }
124
+ // Add MCP server to clients
125
+ await (0, steps_1.addMCPServerToClientsStep)({
126
+ cloudRegion,
127
+ integration: config.metadata.integration,
128
+ });
129
+ // Build outro message
130
+ const continueUrl = options.signup
131
+ ? `${(0, urls_1.getCloudUrlFromRegion)(cloudRegion)}/products?source=wizard`
132
+ : undefined;
133
+ const changes = [
134
+ ...config.ui.getOutroChanges(frameworkContext),
135
+ Object.keys(envVars).length > 0
136
+ ? `Added environment variables to .env file`
137
+ : '',
138
+ uploadedEnvVars.length > 0
139
+ ? `Uploaded environment variables to your hosting provider`
140
+ : '',
141
+ ].filter(Boolean);
142
+ const nextSteps = [
143
+ ...config.ui.getOutroNextSteps(frameworkContext),
144
+ uploadedEnvVars.length === 0 && config.environment.uploadToHosting
145
+ ? `Upload your Project API key to your hosting provider`
146
+ : '',
147
+ ].filter(Boolean);
148
+ const outroMessage = `
149
+ ${chalk_1.default.green('Successfully installed PostHog!')}
150
+
151
+ ${chalk_1.default.cyan('What the agent did:')}
152
+ ${changes.map((change) => `• ${change}`).join('\n')}
153
+
154
+ ${chalk_1.default.yellow('Next steps:')}
155
+ ${nextSteps.map((step) => `• ${step}`).join('\n')}
156
+
157
+ Learn more: ${chalk_1.default.cyan(config.metadata.docsUrl)}
158
+ ${continueUrl ? `\nContinue onboarding: ${chalk_1.default.cyan(continueUrl)}\n` : ``}
159
+ ${chalk_1.default.dim('Note: This wizard uses an LLM agent to analyze and modify your project. Please review the changes made.')}
160
+
161
+ ${chalk_1.default.dim(`How did this work for you? Drop me a line: danilo@posthog.com`)}`;
162
+ clack_1.default.outro(outroMessage);
163
+ await analytics_1.analytics.shutdown('success');
164
+ }
165
+ /**
166
+ * Build the integration prompt for the agent.
167
+ * Uses shared base prompt with optional framework-specific addendum.
168
+ */
169
+ function buildIntegrationPrompt(config, context, frameworkContext) {
170
+ const additionalLines = config.prompts.getAdditionalContextLines
171
+ ? config.prompts.getAdditionalContextLines(frameworkContext)
172
+ : [];
173
+ const additionalContext = additionalLines.length > 0
174
+ ? '\n' + additionalLines.map((line) => `- ${line}`).join('\n')
175
+ : '';
176
+ return `You have access to the PostHog MCP server which provides an integration resource to integrate PostHog into this ${config.metadata.name} project.
177
+
178
+ Project context:
179
+ - Framework: ${config.metadata.name} ${context.frameworkVersion}
180
+ - TypeScript: ${context.typescript ? 'Yes' : 'No'}
181
+ - PostHog API Key: ${context.projectApiKey}
182
+ - PostHog Host: ${context.host}${additionalContext}
183
+
184
+ Instructions:
185
+ 1. Call the PostHog MCP's resource for setup: posthog://workflows/basic-integration/begin
186
+ 2. Follow all instructions provided
187
+ 3. Set up environment variables for PostHog in a .env file with the API key and host provided above, using the appropriate naming convention for ${config.metadata.name}. Make sure to use these environment variables in the code files you create instead of hardcoding the API key and host.
188
+
189
+ The PostHog MCP will provide specific integration code and instructions. Please follow them carefully. Be sure to look for lockfiles to determine the appropriate package manager to use when installing PostHog. Do not manually edit the package.json file.
190
+
191
+ Before beginning, confirm that you can access the PostHog MCP. If the PostHog MCP is not accessible, emit the following string:
192
+
193
+ ${agent_interface_1.AgentSignals.ERROR_MCP_MISSING} Could not access the PostHog MCP.
194
+
195
+ If the PostHog MCP is accessible, attempt to access the setup resource. If the setup resource is not accessible, emit the following string:
196
+
197
+ ${agent_interface_1.AgentSignals.ERROR_RESOURCE_MISSING} Could not access the setup resource.
198
+
199
+ `;
200
+ }
201
+ //# sourceMappingURL=agent-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-runner.js","sourceRoot":"","sources":["../../../src/lib/agent-runner.ts"],"names":[],"mappings":";;;;;AAiCA,wCAiNC;AAhPD,sDAU8B;AAC9B,kDAA+C;AAC/C,2CAA4D;AAC5D,2DAAmC;AACnC,uDAK2B;AAC3B,wCAAsD;AACtD,kDAA0B;AAC1B,oCAGkB;AAElB;;;GAGG;AACI,KAAK,UAAU,cAAc,CAClC,MAAuB,EACvB,OAAsB;IAEtB,cAAc;IACd,IAAA,0BAAY,EAAC,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;IAEvD,eAAK,CAAC,GAAG,CAAC,IAAI,CACZ,iFAAiF,MAAM,CAAC,QAAQ,CAAC,IAAI,sFAAsF,CAC5L,CAAC;IAEF,MAAM,SAAS,GAAG,MAAM,IAAA,6BAAe,EAAC,OAAO,CAAC,CAAC;IACjD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAA,mBAAK,EAAC,MAAM,CAAC,QAAQ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;eAGa,MAAM,CAAC,QAAQ,CAAC,IAAI,IAAI,OAAO,CAAC,gBAAgB;gBAC/C,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;qBAC5B,OAAO,CAAC,aAAa;kBACxB,OAAO,CAAC,IAAI,GAAG,iBAAiB;;;;;mJAM9C,MAAM,CAAC,QAAQ,CAAC,IAClB;;;;;;EAMA,8BAAY,CAAC,iBAAiB;;;;EAI9B,8BAAY,CAAC,sBAAsB;;CAEpC,CAAC;AACF,CAAC","sourcesContent":["import type { FrameworkConfig } from './framework-config';\nimport type { WizardOptions } from '../utils/types';\nimport {\n abort,\n askForAIConsent,\n confirmContinueIfNoOrDirtyGitRepo,\n ensurePackageIsInstalled,\n getOrAskForProjectData,\n getPackageDotJson,\n isUsingTypeScript,\n printWelcome,\n askForCloudRegion,\n} from '../utils/clack-utils';\nimport { analytics } from '../utils/analytics';\nimport { WIZARD_INTERACTION_EVENT_NAME } from './constants';\nimport clack from '../utils/clack';\nimport {\n initializeAgent,\n runAgent,\n AgentSignals,\n AgentErrorType,\n} from './agent-interface';\nimport { getCloudUrlFromRegion } from '../utils/urls';\nimport chalk from 'chalk';\nimport {\n addMCPServerToClientsStep,\n uploadEnvironmentVariablesStep,\n} from '../steps';\n\n/**\n * Universal agent-powered wizard runner.\n * Handles the complete flow for any framework using PostHog MCP integration.\n */\nexport async function runAgentWizard(\n config: FrameworkConfig,\n options: WizardOptions,\n): Promise<void> {\n // Setup phase\n printWelcome({ wizardName: config.ui.welcomeMessage });\n\n clack.log.info(\n `🧙 The wizard has chosen you to try the next-generation agent integration for ${config.metadata.name}.\\n\\nStand by for the good stuff, and let me know how it goes:\\n\\ndanilo@posthog.com`,\n );\n\n const aiConsent = await askForAIConsent(options);\n if (!aiConsent) {\n await abort(config.metadata.abortMessage, 0);\n }\n\n const cloudRegion = options.cloudRegion ?? (await askForCloudRegion());\n const typeScriptDetected = isUsingTypeScript(options);\n\n await confirmContinueIfNoOrDirtyGitRepo(options);\n\n // Framework detection and version\n const packageJson = await getPackageDotJson(options);\n await ensurePackageIsInstalled(\n packageJson,\n config.detection.packageName,\n config.detection.packageDisplayName,\n );\n\n const frameworkVersion = config.detection.getVersion(packageJson);\n\n // Set analytics tags for framework version\n if (frameworkVersion && config.detection.getVersionBucket) {\n const versionBucket = config.detection.getVersionBucket(frameworkVersion);\n analytics.setTag(`${config.metadata.integration}-version`, versionBucket);\n }\n\n analytics.capture(WIZARD_INTERACTION_EVENT_NAME, {\n action: 'started agent integration',\n integration: config.metadata.integration,\n });\n\n // Get PostHog credentials\n const { projectApiKey, host, accessToken } = await getOrAskForProjectData({\n ...options,\n cloudRegion,\n });\n\n // Gather framework-specific context (e.g., Next.js router, React Native platform)\n const frameworkContext = config.metadata.gatherContext\n ? await config.metadata.gatherContext(options)\n : {};\n\n // Set analytics tags from framework context\n const contextTags = config.analytics.getTags(frameworkContext);\n Object.entries(contextTags).forEach(([key, value]) => {\n analytics.setTag(key, value);\n });\n\n // Build integration prompt\n const integrationPrompt = buildIntegrationPrompt(\n config,\n {\n frameworkVersion: frameworkVersion || 'latest',\n typescript: typeScriptDetected,\n projectApiKey,\n host,\n },\n frameworkContext,\n );\n\n // Initialize and run agent\n const spinner = clack.spinner();\n const agent = await initializeAgent(\n {\n workingDirectory: options.installDir,\n posthogMcpUrl: 'https://mcp.posthog.com/mcp',\n posthogApiKey: accessToken,\n debug: false,\n },\n options,\n spinner,\n );\n\n const agentResult = await runAgent(\n agent,\n integrationPrompt,\n options,\n spinner,\n {\n estimatedDurationMinutes: config.ui.estimatedDurationMinutes,\n spinnerMessage: config.ui.spinnerMessage,\n successMessage: config.ui.successMessage,\n errorMessage: 'Integration failed',\n },\n );\n\n // Handle error cases detected in agent output\n if (agentResult.error === AgentErrorType.MCP_MISSING) {\n analytics.captureException(\n new Error('Agent could not access PostHog MCP server'),\n {\n integration: config.metadata.integration,\n error_type: AgentErrorType.MCP_MISSING,\n signal: AgentSignals.ERROR_MCP_MISSING,\n },\n );\n\n const errorMessage = `\n${chalk.red('❌ Could not access the PostHog MCP server')}\n\nThe wizard was unable to connect to the PostHog MCP server.\nThis could be due to a network issue or a configuration problem.\n\nPlease try again, or set up ${\n config.metadata.name\n } manually by following our documentation:\n${chalk.cyan(config.metadata.docsUrl)}`;\n\n clack.outro(errorMessage);\n await analytics.shutdown('error');\n process.exit(1);\n }\n\n if (agentResult.error === AgentErrorType.RESOURCE_MISSING) {\n analytics.captureException(\n new Error('Agent could not access setup resource'),\n {\n integration: config.metadata.integration,\n error_type: AgentErrorType.RESOURCE_MISSING,\n signal: AgentSignals.ERROR_RESOURCE_MISSING,\n },\n );\n\n const errorMessage = `\n${chalk.red('❌ Could not access the setup resource')}\n\nThe wizard could not access the setup resource. This may indicate a version mismatch or a temporary service issue.\n\nPlease try again, or set up ${\n config.metadata.name\n } manually by following our documentation:\n${chalk.cyan(config.metadata.docsUrl)}`;\n\n clack.outro(errorMessage);\n await analytics.shutdown('error');\n process.exit(1);\n }\n\n // Build environment variables from OAuth credentials\n const envVars = config.environment.getEnvVars(projectApiKey, host);\n\n // Upload environment variables to hosting providers (if configured)\n let uploadedEnvVars: string[] = [];\n if (config.environment.uploadToHosting) {\n uploadedEnvVars = await uploadEnvironmentVariablesStep(envVars, {\n integration: config.metadata.integration,\n options,\n });\n }\n\n // Add MCP server to clients\n await addMCPServerToClientsStep({\n cloudRegion,\n integration: config.metadata.integration,\n });\n\n // Build outro message\n const continueUrl = options.signup\n ? `${getCloudUrlFromRegion(cloudRegion)}/products?source=wizard`\n : undefined;\n\n const changes = [\n ...config.ui.getOutroChanges(frameworkContext),\n Object.keys(envVars).length > 0\n ? `Added environment variables to .env file`\n : '',\n uploadedEnvVars.length > 0\n ? `Uploaded environment variables to your hosting provider`\n : '',\n ].filter(Boolean);\n\n const nextSteps = [\n ...config.ui.getOutroNextSteps(frameworkContext),\n uploadedEnvVars.length === 0 && config.environment.uploadToHosting\n ? `Upload your Project API key to your hosting provider`\n : '',\n ].filter(Boolean);\n\n const outroMessage = `\n${chalk.green('Successfully installed PostHog!')}\n\n${chalk.cyan('What the agent did:')}\n${changes.map((change) => `• ${change}`).join('\\n')}\n\n${chalk.yellow('Next steps:')}\n${nextSteps.map((step) => `• ${step}`).join('\\n')}\n\nLearn more: ${chalk.cyan(config.metadata.docsUrl)}\n${continueUrl ? `\\nContinue onboarding: ${chalk.cyan(continueUrl)}\\n` : ``}\n${chalk.dim(\n 'Note: This wizard uses an LLM agent to analyze and modify your project. Please review the changes made.',\n)}\n\n${chalk.dim(`How did this work for you? Drop me a line: danilo@posthog.com`)}`;\n\n clack.outro(outroMessage);\n\n await analytics.shutdown('success');\n}\n\n/**\n * Build the integration prompt for the agent.\n * Uses shared base prompt with optional framework-specific addendum.\n */\nfunction buildIntegrationPrompt(\n config: FrameworkConfig,\n context: {\n frameworkVersion: string;\n typescript: boolean;\n projectApiKey: string;\n host: string;\n },\n frameworkContext: Record<string, any>,\n): string {\n const additionalLines = config.prompts.getAdditionalContextLines\n ? config.prompts.getAdditionalContextLines(frameworkContext)\n : [];\n\n const additionalContext =\n additionalLines.length > 0\n ? '\\n' + additionalLines.map((line) => `- ${line}`).join('\\n')\n : '';\n\n return `You have access to the PostHog MCP server which provides an integration resource to integrate PostHog into this ${\n config.metadata.name\n } project.\n\nProject context:\n- Framework: ${config.metadata.name} ${context.frameworkVersion}\n- TypeScript: ${context.typescript ? 'Yes' : 'No'}\n- PostHog API Key: ${context.projectApiKey}\n- PostHog Host: ${context.host}${additionalContext}\n\nInstructions:\n1. Call the PostHog MCP's resource for setup: posthog://workflows/basic-integration/begin\n2. Follow all instructions provided\n3. Set up environment variables for PostHog in a .env file with the API key and host provided above, using the appropriate naming convention for ${\n config.metadata.name\n }. Make sure to use these environment variables in the code files you create instead of hardcoding the API key and host.\n\nThe PostHog MCP will provide specific integration code and instructions. Please follow them carefully. Be sure to look for lockfiles to determine the appropriate package manager to use when installing PostHog. Do not manually edit the package.json file.\n\nBefore beginning, confirm that you can access the PostHog MCP. If the PostHog MCP is not accessible, emit the following string:\n\n${AgentSignals.ERROR_MCP_MISSING} Could not access the PostHog MCP.\n\nIf the PostHog MCP is accessible, attempt to access the setup resource. If the setup resource is not accessible, emit the following string:\n\n${AgentSignals.ERROR_RESOURCE_MISSING} Could not access the setup resource.\n\n`;\n}\n"]}
@@ -29,6 +29,7 @@ export declare const ISSUES_URL = "https://github.com/posthog/wizard/issues";
29
29
  export declare const DEFAULT_HOST_URL: string;
30
30
  export declare const ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = "sTMFPsFhdP1Ssg";
31
31
  export declare const ANALYTICS_HOST_URL = "https://internal-j.posthog.com";
32
+ export declare const ANALYTICS_TEAM_TAG = "docs-and-wizard";
32
33
  export declare const DUMMY_PROJECT_API_KEY = "_YOUR_POSTHOG_PROJECT_API_KEY_";
33
34
  export declare const POSTHOG_US_CLIENT_ID = "c4Rdw8DIxgtQfA80IiSnGKlNX8QN00cFWF00QQhM";
34
35
  export declare const POSTHOG_EU_CLIENT_ID = "bx2C5sZRN03TkdjraCcetvQFPGH6N2Y9vRLkcKEy";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WIZARD_INTERACTION_EVENT_NAME = exports.OAUTH_PORT = exports.POSTHOG_DEV_CLIENT_ID = exports.POSTHOG_EU_CLIENT_ID = exports.POSTHOG_US_CLIENT_ID = exports.DUMMY_PROJECT_API_KEY = exports.ANALYTICS_HOST_URL = exports.ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = exports.DEFAULT_HOST_URL = exports.ISSUES_URL = exports.DEFAULT_URL = exports.DEBUG = exports.IS_DEV = exports.WizardVariant = exports.FeatureFlagDefinition = exports.Integration = void 0;
3
+ exports.WIZARD_INTERACTION_EVENT_NAME = exports.OAUTH_PORT = exports.POSTHOG_DEV_CLIENT_ID = exports.POSTHOG_EU_CLIENT_ID = exports.POSTHOG_US_CLIENT_ID = exports.DUMMY_PROJECT_API_KEY = exports.ANALYTICS_TEAM_TAG = exports.ANALYTICS_HOST_URL = exports.ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = exports.DEFAULT_HOST_URL = exports.ISSUES_URL = exports.DEFAULT_URL = exports.DEBUG = exports.IS_DEV = exports.WizardVariant = exports.FeatureFlagDefinition = exports.Integration = void 0;
4
4
  exports.getIntegrationDescription = getIntegrationDescription;
5
5
  exports.getIntegrationChoices = getIntegrationChoices;
6
6
  var Integration;
@@ -53,6 +53,7 @@ exports.DEFAULT_HOST_URL = exports.IS_DEV
53
53
  : 'https://us.i.posthog.com';
54
54
  exports.ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = 'sTMFPsFhdP1Ssg';
55
55
  exports.ANALYTICS_HOST_URL = 'https://internal-j.posthog.com';
56
+ exports.ANALYTICS_TEAM_TAG = 'docs-and-wizard';
56
57
  exports.DUMMY_PROJECT_API_KEY = '_YOUR_POSTHOG_PROJECT_API_KEY_';
57
58
  exports.POSTHOG_US_CLIENT_ID = 'c4Rdw8DIxgtQfA80IiSnGKlNX8QN00cFWF00QQhM';
58
59
  exports.POSTHOG_EU_CLIENT_ID = 'bx2C5sZRN03TkdjraCcetvQFPGH6N2Y9vRLkcKEy';
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":";;;AAiBA,8DAeC;AAOD,sDAKC;AA5CD,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,8BAAe,CAAA;IACf,gCAAiB,CAAA;IACjB,2CAA4B,CAAA;IAC5B,8BAAe,CAAA;AACjB,CAAC,EANW,WAAW,2BAAX,WAAW,QAMtB;AAED,IAAY,qBAEX;AAFD,WAAY,qBAAqB;IAC/B,kDAAyB,CAAA;AAC3B,CAAC,EAFW,qBAAqB,qCAArB,qBAAqB,QAEhC;AAED,IAAY,aAGX;AAH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,qBAAqB,GAAG,gCAAgC,CAAC;AAEzD,QAAA,oBAAoB,GAAG,0CAA0C,CAAC;AAClE,QAAA,oBAAoB,GAAG,0CAA0C,CAAC;AAClE,QAAA,qBAAqB,GAAG,0CAA0C,CAAC;AACnE,QAAA,UAAU,GAAG,IAAI,CAAC;AAElB,QAAA,6BAA6B,GAAG,oBAAoB,CAAC","sourcesContent":["export enum Integration {\n nextjs = 'nextjs',\n react = 'react',\n svelte = 'svelte',\n reactNative = 'react-native',\n astro = 'astro',\n}\n\nexport enum FeatureFlagDefinition {\n NextV2 = 'wizard-next-v2',\n}\n\nexport enum WizardVariant {\n Legacy = 'legacy',\n Agent = 'agent',\n}\n\nexport function getIntegrationDescription(type: string): string {\n switch (type) {\n case Integration.nextjs:\n return 'Next.js';\n case Integration.react:\n return 'React';\n case Integration.reactNative:\n return 'React Native';\n case Integration.svelte:\n return 'Svelte';\n case Integration.astro:\n return 'Astro';\n default:\n throw new Error(`Unknown integration ${type}`);\n }\n}\n\ntype IntegrationChoice = {\n name: string;\n value: string;\n};\n\nexport function getIntegrationChoices(): IntegrationChoice[] {\n return Object.keys(Integration).map((type: string) => ({\n name: getIntegrationDescription(type),\n value: type,\n }));\n}\n\nexport interface Args {\n debug: boolean;\n integration: Integration;\n}\n\nexport const IS_DEV = ['test', 'development'].includes(\n process.env.NODE_ENV ?? '',\n);\n\nexport const DEBUG = false;\n\nexport const DEFAULT_URL = IS_DEV\n ? 'http://localhost:8010'\n : 'https://us.posthog.com';\nexport const ISSUES_URL = 'https://github.com/posthog/wizard/issues';\nexport const DEFAULT_HOST_URL = IS_DEV\n ? 'http://localhost:8010'\n : 'https://us.i.posthog.com';\nexport const ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = 'sTMFPsFhdP1Ssg';\nexport const ANALYTICS_HOST_URL = 'https://internal-j.posthog.com';\nexport const DUMMY_PROJECT_API_KEY = '_YOUR_POSTHOG_PROJECT_API_KEY_';\n\nexport const POSTHOG_US_CLIENT_ID = 'c4Rdw8DIxgtQfA80IiSnGKlNX8QN00cFWF00QQhM';\nexport const POSTHOG_EU_CLIENT_ID = 'bx2C5sZRN03TkdjraCcetvQFPGH6N2Y9vRLkcKEy';\nexport const POSTHOG_DEV_CLIENT_ID = 'DC5uRLVbGI02YQ82grxgnK6Qn12SXWpCqdPb60oZ';\nexport const OAUTH_PORT = 8239;\n\nexport const WIZARD_INTERACTION_EVENT_NAME = 'wizard interaction';\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":";;;AAiBA,8DAeC;AAOD,sDAKC;AA5CD,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,8BAAe,CAAA;IACf,gCAAiB,CAAA;IACjB,2CAA4B,CAAA;IAC5B,8BAAe,CAAA;AACjB,CAAC,EANW,WAAW,2BAAX,WAAW,QAMtB;AAED,IAAY,qBAEX;AAFD,WAAY,qBAAqB;IAC/B,kDAAyB,CAAA;AAC3B,CAAC,EAFW,qBAAqB,qCAArB,qBAAqB,QAEhC;AAED,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,kCAAiB,CAAA;IACjB,gCAAe,CAAA;AACjB,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB;AAED,SAAgB,yBAAyB,CAAC,IAAY;IACpD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,WAAW,CAAC,MAAM;YACrB,OAAO,SAAS,CAAC;QACnB,KAAK,WAAW,CAAC,KAAK;YACpB,OAAO,OAAO,CAAC;QACjB,KAAK,WAAW,CAAC,WAAW;YAC1B,OAAO,cAAc,CAAC;QACxB,KAAK,WAAW,CAAC,MAAM;YACrB,OAAO,QAAQ,CAAC;QAClB,KAAK,WAAW,CAAC,KAAK;YACpB,OAAO,OAAO,CAAC;QACjB;YACE,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;AACH,CAAC;AAOD,SAAgB,qBAAqB;IACnC,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC;QACrD,IAAI,EAAE,yBAAyB,CAAC,IAAI,CAAC;QACrC,KAAK,EAAE,IAAI;KACZ,CAAC,CAAC,CAAC;AACN,CAAC;AAOY,QAAA,MAAM,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,QAAQ,CACpD,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAC3B,CAAC;AAEW,QAAA,KAAK,GAAG,KAAK,CAAC;AAEd,QAAA,WAAW,GAAG,cAAM;IAC/B,CAAC,CAAC,uBAAuB;IACzB,CAAC,CAAC,wBAAwB,CAAC;AAChB,QAAA,UAAU,GAAG,0CAA0C,CAAC;AACxD,QAAA,gBAAgB,GAAG,cAAM;IACpC,CAAC,CAAC,uBAAuB;IACzB,CAAC,CAAC,0BAA0B,CAAC;AAClB,QAAA,0CAA0C,GAAG,gBAAgB,CAAC;AAC9D,QAAA,kBAAkB,GAAG,gCAAgC,CAAC;AACtD,QAAA,kBAAkB,GAAG,iBAAiB,CAAC;AACvC,QAAA,qBAAqB,GAAG,gCAAgC,CAAC;AAEzD,QAAA,oBAAoB,GAAG,0CAA0C,CAAC;AAClE,QAAA,oBAAoB,GAAG,0CAA0C,CAAC;AAClE,QAAA,qBAAqB,GAAG,0CAA0C,CAAC;AACnE,QAAA,UAAU,GAAG,IAAI,CAAC;AAElB,QAAA,6BAA6B,GAAG,oBAAoB,CAAC","sourcesContent":["export enum Integration {\n nextjs = 'nextjs',\n react = 'react',\n svelte = 'svelte',\n reactNative = 'react-native',\n astro = 'astro',\n}\n\nexport enum FeatureFlagDefinition {\n NextV2 = 'wizard-next-v2',\n}\n\nexport enum WizardVariant {\n Legacy = 'legacy',\n Agent = 'agent',\n}\n\nexport function getIntegrationDescription(type: string): string {\n switch (type) {\n case Integration.nextjs:\n return 'Next.js';\n case Integration.react:\n return 'React';\n case Integration.reactNative:\n return 'React Native';\n case Integration.svelte:\n return 'Svelte';\n case Integration.astro:\n return 'Astro';\n default:\n throw new Error(`Unknown integration ${type}`);\n }\n}\n\ntype IntegrationChoice = {\n name: string;\n value: string;\n};\n\nexport function getIntegrationChoices(): IntegrationChoice[] {\n return Object.keys(Integration).map((type: string) => ({\n name: getIntegrationDescription(type),\n value: type,\n }));\n}\n\nexport interface Args {\n debug: boolean;\n integration: Integration;\n}\n\nexport const IS_DEV = ['test', 'development'].includes(\n process.env.NODE_ENV ?? '',\n);\n\nexport const DEBUG = false;\n\nexport const DEFAULT_URL = IS_DEV\n ? 'http://localhost:8010'\n : 'https://us.posthog.com';\nexport const ISSUES_URL = 'https://github.com/posthog/wizard/issues';\nexport const DEFAULT_HOST_URL = IS_DEV\n ? 'http://localhost:8010'\n : 'https://us.i.posthog.com';\nexport const ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = 'sTMFPsFhdP1Ssg';\nexport const ANALYTICS_HOST_URL = 'https://internal-j.posthog.com';\nexport const ANALYTICS_TEAM_TAG = 'docs-and-wizard';\nexport const DUMMY_PROJECT_API_KEY = '_YOUR_POSTHOG_PROJECT_API_KEY_';\n\nexport const POSTHOG_US_CLIENT_ID = 'c4Rdw8DIxgtQfA80IiSnGKlNX8QN00cFWF00QQhM';\nexport const POSTHOG_EU_CLIENT_ID = 'bx2C5sZRN03TkdjraCcetvQFPGH6N2Y9vRLkcKEy';\nexport const POSTHOG_DEV_CLIENT_ID = 'DC5uRLVbGI02YQ82grxgnK6Qn12SXWpCqdPb60oZ';\nexport const OAUTH_PORT = 8239;\n\nexport const WIZARD_INTERACTION_EVENT_NAME = 'wizard interaction';\n"]}