usetraceforge-cli 0.1.6 → 0.1.8

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.
@@ -50,19 +50,24 @@ export async function runGeminiAgent(apiKey, endpoint) {
50
50
  s.message("Agent: Analyzing architecture with Gemini...");
51
51
  try {
52
52
  const genAI = new GoogleGenerativeAI(geminiKey);
53
- const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
53
+ // Use gemini-pro as a safe fallback since 1.5-flash threw a 404 on your key
54
+ const model = genAI.getGenerativeModel({ model: "gemini/gemini-3.1-flash-lite" });
54
55
  const prompt = `
55
56
  I am trying to install an SDK called "usetraceforge".
56
57
  I have the following files in my project:
57
58
 
58
59
  ${folderStructure}
59
60
 
60
- Please tell me EXACTLY how to configure TraceForge for my framework.
61
- If this is Next.js 15, tell me to create 'instrumentation.ts'.
62
- If this is Express, tell me to add 'TraceForge.expressErrorHandler()'.
63
- Keep your answer very short, professional, and provide the exact code snippets I need to copy and paste.
64
- The API Key they should use is: ${apiKey}
65
- The Endpoint is: ${endpoint}
61
+ Here is the documentation for usetraceforge:
62
+ - Next.js 15+ Server: Create 'instrumentation.ts' (or 'src/instrumentation.ts') exporting 'register' and 'onRequestError(err, request)' which calls 'TraceForge.captureException(err, { tags: { route: request.url } })'.
63
+ - Next.js Client: Wrap your app with '<TraceForgeProvider>' from 'usetraceforge/react'.
64
+ - Express: Call 'app.use(TraceForge.expressErrorHandler())' AFTER all routes but BEFORE custom error handlers.
65
+ - Initialization: You must always call 'TraceForge.init({ apiKey, endpoint })' as early as possible.
66
+
67
+ The user's API Key is: ${apiKey}
68
+ The user's Endpoint is: ${endpoint}
69
+
70
+ Based on the folder structure above, tell the developer exactly which files they need to edit and provide the exact code snippets they need to copy and paste to configure TraceForge. Be concise, accurate, and professional.
66
71
  `;
67
72
  const result = await model.generateContent(prompt);
68
73
  const response = result.response;
@@ -2,6 +2,7 @@ import fs from "fs";
2
2
  import path from "path";
3
3
  import { spinner } from "@clack/prompts";
4
4
  import chalk from "chalk";
5
+ import { Project, SyntaxKind } from "ts-morph";
5
6
  export async function installNextJs(apiKey, endpoint) {
6
7
  const s = spinner();
7
8
  s.start("Agent: Configuring Next.js Instrumentation...");
@@ -43,6 +44,48 @@ export function onRequestError(err: any, request: any) {
43
44
  else {
44
45
  console.log(chalk.yellow(`\nAgent: instrumentation.ts already exists. Please manually add TraceForge.`));
45
46
  }
47
+ // 3. Layout AST Injection (Client-side Provider)
48
+ const project = new Project();
49
+ const layoutPaths = [
50
+ path.resolve(process.cwd(), "app/layout.tsx"),
51
+ path.resolve(process.cwd(), "src/app/layout.tsx"),
52
+ ];
53
+ let targetLayout = null;
54
+ for (const p of layoutPaths) {
55
+ if (fs.existsSync(p)) {
56
+ targetLayout = p;
57
+ break;
58
+ }
59
+ }
60
+ if (targetLayout) {
61
+ const sourceFile = project.addSourceFileAtPath(targetLayout);
62
+ if (!sourceFile.getFullText().includes("TraceForgeProvider")) {
63
+ sourceFile.addImportDeclaration({
64
+ namedImports: ["TraceForgeProvider"],
65
+ moduleSpecifier: "usetraceforge/react"
66
+ });
67
+ // Find body tag
68
+ const jsxElements = sourceFile.getDescendantsOfKind(SyntaxKind.JsxElement);
69
+ let bodyTag = jsxElements.find(el => el.getOpeningElement().getTagNameNode().getText() === "body");
70
+ if (bodyTag) {
71
+ const childrenText = bodyTag.getJsxChildren().map(c => c.getText()).join("");
72
+ const opening = bodyTag.getOpeningElement().getText();
73
+ const closing = bodyTag.getClosingElement().getText();
74
+ bodyTag.replaceWithText(`${opening}\n <TraceForgeProvider>\n ${childrenText}\n </TraceForgeProvider>\n ${closing}`);
75
+ sourceFile.saveSync();
76
+ console.log(chalk.green(`\nAgent: Injected <TraceForgeProvider> into ${targetLayout.replace(process.cwd(), "")}`));
77
+ }
78
+ else {
79
+ console.log(chalk.yellow("\nAgent: Could not find <body> tag in layout.tsx. Please add <TraceForgeProvider> manually."));
80
+ }
81
+ }
82
+ else {
83
+ console.log(chalk.blue(`\nAgent: <TraceForgeProvider> already exists in layout.tsx`));
84
+ }
85
+ }
86
+ else {
87
+ console.log(chalk.yellow("\nAgent: Could not find layout.tsx. Please add <TraceForgeProvider> manually."));
88
+ }
46
89
  s.stop(chalk.green("Agent: Next.js configuration complete!"));
47
90
  }
48
91
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "usetraceforge-cli",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "TraceForge CLI Wizard for 2-click installations",
5
5
  "bin": {
6
6
  "traceforge": "./dist/index.js"