tidewave 0.5.1 → 0.5.2

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.
@@ -20137,7 +20137,7 @@ Defaults to 30000 (30 seconds).`),
20137
20137
  });
20138
20138
 
20139
20139
  // package.json
20140
- var name = "tidewave", version = "0.5.1", package_default;
20140
+ var name = "tidewave", version = "0.5.2", package_default;
20141
20141
  var init_package = __esm(() => {
20142
20142
  package_default = {
20143
20143
  name,
@@ -20195,7 +20195,7 @@ var init_package = __esm(() => {
20195
20195
  ],
20196
20196
  scripts: {
20197
20197
  dist: "bun run clean && bun run build:js && bun run build:types",
20198
- "build:js": "bun build --outdir dist --root src --external commander --external chalk --external typescript --external child_process --external module --external @opentelemetry/api --external @opentelemetry/api-logs --external @opentelemetry/core --external @opentelemetry/resources --external @opentelemetry/sdk-logs --external @opentelemetry/sdk-trace-base --external @opentelemetry/sdk-trace-node --external @opentelemetry/semantic-conventions src/next-js/handler.ts src/next-js/instrumentation.ts src/vite-plugin.ts src/evaluation/eval_worker.ts src/cli/index.ts --target node",
20198
+ "build:js": "bun build --outdir dist --root src --external typescript --external child_process --external module --external @opentelemetry/api --external @opentelemetry/sdk-logs --external @opentelemetry/sdk-trace-base src/next-js/handler.ts src/next-js/instrumentation.ts src/vite-plugin.ts src/evaluation/eval_worker.ts src/cli/index.ts --target node",
20199
20199
  "build:types": "tsc -p tsconfig.declarations.json",
20200
20200
  dev: "bun run src/cli/index.ts",
20201
20201
  test: "bun test",
@@ -20215,7 +20215,9 @@ var init_package = __esm(() => {
20215
20215
  },
20216
20216
  devDependencies: {
20217
20217
  "@eslint/js": "^9.16.0",
20218
- "@opentelemetry/sdk-trace-node": "^2.1.0",
20218
+ "@opentelemetry/api": "^1.9.0",
20219
+ "@opentelemetry/sdk-logs": "^0.206.0",
20220
+ "@opentelemetry/sdk-trace-base": "^2.1.0",
20219
20221
  "@types/body-parser": "^1.19.6",
20220
20222
  "@types/bun": "latest",
20221
20223
  "@types/connect": "^3.4.38",
@@ -20225,8 +20227,8 @@ var init_package = __esm(() => {
20225
20227
  "@vercel/otel": "^2.0.1",
20226
20228
  "@vitest/ui": "^3.2.4",
20227
20229
  "bun-types": "latest",
20228
- commander: "^12.1.0",
20229
20230
  chalk: "^5.3.0",
20231
+ commander: "^12.1.0",
20230
20232
  eslint: "^9.16.0",
20231
20233
  globals: "^15.14.0",
20232
20234
  next: "^15.5.3",
@@ -20248,6 +20250,8 @@ var init_package = __esm(() => {
20248
20250
  });
20249
20251
 
20250
20252
  // src/core.ts
20253
+ import path from "path";
20254
+ import fs from "fs/promises";
20251
20255
  function isResolveError(result) {
20252
20256
  return result != null && "success" in result && result.success === false;
20253
20257
  }
@@ -20272,10 +20276,25 @@ function createExtractError(code, message, details) {
20272
20276
  }
20273
20277
  };
20274
20278
  }
20279
+ async function getProjectName(defaultName = "app") {
20280
+ if (typeof process === "undefined" || !process.cwd) {
20281
+ return defaultName;
20282
+ }
20283
+ const rootDir = process.cwd();
20284
+ const packageJsonPath = path.join(rootDir, "package.json");
20285
+ try {
20286
+ const packageJson = await fs.readFile(packageJsonPath, "utf8");
20287
+ const { name: name2 } = JSON.parse(packageJson);
20288
+ return name2 || defaultName;
20289
+ } catch {
20290
+ return defaultName;
20291
+ }
20292
+ }
20293
+ var init_core = () => {};
20275
20294
 
20276
20295
  // src/resolution/module-resolver.ts
20277
20296
  import ts from "typescript";
20278
- import path from "node:path";
20297
+ import path2 from "node:path";
20279
20298
  function loadTsConfig(prefix) {
20280
20299
  const projectPath = prefix || process.cwd();
20281
20300
  const configPath = ts.findConfigFile(projectPath, ts.sys.fileExists, "tsconfig.json");
@@ -20295,7 +20314,7 @@ function loadTsConfig(prefix) {
20295
20314
  if (configPath) {
20296
20315
  const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
20297
20316
  if (configFile.config) {
20298
- const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath));
20317
+ const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path2.dirname(configPath));
20299
20318
  compilerOptions = { ...compilerOptions, ...parsedConfig.options };
20300
20319
  rootNames = parsedConfig.fileNames;
20301
20320
  }
@@ -20307,7 +20326,7 @@ function loadTsConfig(prefix) {
20307
20326
  }
20308
20327
  function resolveModule(moduleName, compilerOptions) {
20309
20328
  if (moduleName.startsWith("./") || moduleName.startsWith("../") || moduleName.includes(".") && !moduleName.includes("/")) {
20310
- const absolutePath = path.resolve(moduleName);
20329
+ const absolutePath = path2.resolve(moduleName);
20311
20330
  if (ts.sys.fileExists(absolutePath)) {
20312
20331
  const dedicatedProgram = ts.createProgram([absolutePath], compilerOptions);
20313
20332
  const sourceFile = dedicatedProgram.getSourceFile(absolutePath);
@@ -20316,7 +20335,7 @@ function resolveModule(moduleName, compilerOptions) {
20316
20335
  }
20317
20336
  }
20318
20337
  }
20319
- const moduleResolver = ts.resolveModuleName(moduleName, path.resolve("./index.ts"), compilerOptions, ts.sys);
20338
+ const moduleResolver = ts.resolveModuleName(moduleName, path2.resolve("./index.ts"), compilerOptions, ts.sys);
20320
20339
  if (moduleResolver.resolvedModule) {
20321
20340
  const { resolvedFileName } = moduleResolver.resolvedModule;
20322
20341
  const dedicatedProgram = ts.createProgram([resolvedFileName], compilerOptions);
@@ -20376,11 +20395,13 @@ function resolveNodeBuiltin(moduleName, compilerOptions) {
20376
20395
  }
20377
20396
  return resolveError(moduleName, process.cwd());
20378
20397
  }
20379
- var init_module_resolver = () => {};
20398
+ var init_module_resolver = __esm(() => {
20399
+ init_core();
20400
+ });
20380
20401
 
20381
20402
  // src/resolution/utils.ts
20382
20403
  import ts2 from "typescript";
20383
- import path2 from "node:path";
20404
+ import path3 from "node:path";
20384
20405
  function getLocation(symbol) {
20385
20406
  if (symbol.valueDeclaration) {
20386
20407
  const sourceFile = symbol.valueDeclaration.getSourceFile();
@@ -20388,7 +20409,7 @@ function getLocation(symbol) {
20388
20409
  let { fileName } = sourceFile;
20389
20410
  const cwd = process.cwd();
20390
20411
  if (fileName.startsWith(cwd)) {
20391
- fileName = path2.relative(cwd, fileName);
20412
+ fileName = path3.relative(cwd, fileName);
20392
20413
  }
20393
20414
  return `${fileName}:${line + 1}:${character + 1}`;
20394
20415
  }
@@ -20401,7 +20422,7 @@ function getLocation(symbol) {
20401
20422
  let fileName = sourceFile?.fileName;
20402
20423
  const cwd = process.cwd();
20403
20424
  if (fileName?.startsWith(cwd)) {
20404
- fileName = path2.relative(cwd, fileName);
20425
+ fileName = path3.relative(cwd, fileName);
20405
20426
  }
20406
20427
  return `${fileName}:${line + 1}:${character + 1}`;
20407
20428
  }
@@ -20748,13 +20769,14 @@ function getSymbolInfo(checker, symbol, member, isStatic) {
20748
20769
  };
20749
20770
  }
20750
20771
  var init_symbol_finder = __esm(() => {
20772
+ init_core();
20751
20773
  init_utils();
20752
20774
  init_formatters();
20753
20775
  });
20754
20776
 
20755
20777
  // src/resolution/index.ts
20756
20778
  import ts5 from "typescript";
20757
- import path3 from "node:path";
20779
+ import path4 from "node:path";
20758
20780
  function parseModulePath(modulePath) {
20759
20781
  let module;
20760
20782
  let symbolPath;
@@ -20959,12 +20981,12 @@ async function getSourceLocation(reference) {
20959
20981
  }
20960
20982
  const moduleName = reference;
20961
20983
  if (moduleName.startsWith("./") || moduleName.startsWith("../")) {
20962
- const absolutePath = path3.resolve(moduleName);
20984
+ const absolutePath = path4.resolve(moduleName);
20963
20985
  if (ts5.sys.fileExists(absolutePath)) {
20964
20986
  const cwd = process.cwd();
20965
20987
  let finalPath;
20966
20988
  if (absolutePath.startsWith(cwd)) {
20967
- const relativePath = path3.relative(cwd, absolutePath);
20989
+ const relativePath = path4.relative(cwd, absolutePath);
20968
20990
  finalPath = relativePath.startsWith("..") ? absolutePath : relativePath;
20969
20991
  } else {
20970
20992
  finalPath = absolutePath;
@@ -20973,13 +20995,13 @@ async function getSourceLocation(reference) {
20973
20995
  }
20974
20996
  }
20975
20997
  const config = loadTsConfig(options.prefix);
20976
- const moduleResolver = ts5.resolveModuleName(moduleName, path3.resolve("./index.ts"), config.options, ts5.sys);
20998
+ const moduleResolver = ts5.resolveModuleName(moduleName, path4.resolve("./index.ts"), config.options, ts5.sys);
20977
20999
  if (moduleResolver.resolvedModule) {
20978
21000
  const { resolvedFileName } = moduleResolver.resolvedModule;
20979
21001
  const cwd = process.cwd();
20980
21002
  let finalPath;
20981
21003
  if (resolvedFileName.startsWith(cwd)) {
20982
- const relativePath = path3.relative(cwd, resolvedFileName);
21004
+ const relativePath = path4.relative(cwd, resolvedFileName);
20983
21005
  finalPath = relativePath.startsWith("..") ? resolvedFileName : relativePath;
20984
21006
  } else {
20985
21007
  finalPath = resolvedFileName;
@@ -20989,6 +21011,7 @@ async function getSourceLocation(reference) {
20989
21011
  return resolveError(moduleName, process.cwd());
20990
21012
  }
20991
21013
  var init_resolution = __esm(() => {
21014
+ init_core();
20992
21015
  init_module_resolver();
20993
21016
  init_symbol_finder();
20994
21017
  init_formatters();
@@ -21216,9 +21239,9 @@ async function handleGetSourcePath({ reference }) {
21216
21239
  isError: true
21217
21240
  };
21218
21241
  }
21219
- const { path: path4, format } = sourceResult;
21242
+ const { path: path5, format } = sourceResult;
21220
21243
  return {
21221
- content: [{ type: "text", text: `${path4}(${format})` }],
21244
+ content: [{ type: "text", text: `${path5}(${format})` }],
21222
21245
  isError: false
21223
21246
  };
21224
21247
  }
@@ -21278,6 +21301,7 @@ var init_mcp2 = __esm(() => {
21278
21301
  init_mcp();
21279
21302
  init_tools();
21280
21303
  init_package();
21304
+ init_core();
21281
21305
  init_src();
21282
21306
  init_circular_buffer();
21283
21307
  ({
@@ -21434,6 +21458,91 @@ var init_shell = __esm(() => {
21434
21458
  init_http();
21435
21459
  });
21436
21460
 
21461
+ // src/http/handlers/html.ts
21462
+ function createHandleHtml(config) {
21463
+ return async function handleHtml(req, res, next) {
21464
+ const url = req.url || "/";
21465
+ const [pathname] = url.split("?");
21466
+ if (pathname !== "" && pathname !== "/" && pathname !== "/tidewave") {
21467
+ return next();
21468
+ }
21469
+ try {
21470
+ const clientUrl = config.clientUrl || "https://tidewave.ai";
21471
+ const tidewaveConfig = {
21472
+ project_name: config.projectName || "app",
21473
+ framework_type: config.framework || "unknown",
21474
+ tidewave_version: package_default.version,
21475
+ team: config.team || {}
21476
+ };
21477
+ res.statusCode = 200;
21478
+ res.setHeader("Content-Type", "text/html");
21479
+ res.end(`
21480
+ <html>
21481
+ <head>
21482
+ <meta charset="UTF-8" />
21483
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
21484
+ <meta name="tidewave:config" content="${escapeHtml(JSON.stringify(tidewaveConfig))}" />
21485
+ <script type="module" src="${clientUrl}/tc/tc.js"></script>
21486
+ </head>
21487
+ <body></body>
21488
+ </html>
21489
+ `);
21490
+ } catch (err) {
21491
+ console.error(`[Tidewave] Failed to serve HTML: ${err}`);
21492
+ if (!res.headersSent) {
21493
+ res.statusCode = 500;
21494
+ res.setHeader("Content-Type", "text/html");
21495
+ res.end("<html><body>Internal server error</body></html>");
21496
+ }
21497
+ next(err);
21498
+ }
21499
+ };
21500
+ }
21501
+ function escapeHtml(text) {
21502
+ const map2 = {
21503
+ "&": "&amp;",
21504
+ "<": "&lt;",
21505
+ ">": "&gt;",
21506
+ '"': "&quot;",
21507
+ "'": "&#039;"
21508
+ };
21509
+ return text.replace(/[&<>"']/g, (match) => map2[match]);
21510
+ }
21511
+ var init_html = __esm(() => {
21512
+ init_package();
21513
+ });
21514
+
21515
+ // src/http/handlers/config.ts
21516
+ function createHandleConfig(config) {
21517
+ return async function handleConfig(_req, res, next) {
21518
+ try {
21519
+ const tidewaveConfig = {
21520
+ project_name: config.projectName || "app",
21521
+ framework_type: config.framework || "unknown",
21522
+ tidewave_version: package_default.version,
21523
+ team: config.team || {}
21524
+ };
21525
+ res.statusCode = 200;
21526
+ res.setHeader("Content-Type", "application/json");
21527
+ res.end(JSON.stringify(tidewaveConfig));
21528
+ } catch (err) {
21529
+ console.error(`[Tidewave] Failed to serve config: ${err}`);
21530
+ if (!res.headersSent) {
21531
+ res.statusCode = 500;
21532
+ res.setHeader("Content-Type", "application/json");
21533
+ res.end(JSON.stringify({
21534
+ error: "Internal server error",
21535
+ message: err instanceof Error ? err.message : String(err)
21536
+ }));
21537
+ }
21538
+ next(err);
21539
+ }
21540
+ };
21541
+ }
21542
+ var init_config = __esm(() => {
21543
+ init_package();
21544
+ });
21545
+
21437
21546
  // node_modules/ms/index.js
21438
21547
  var require_ms3 = __commonJS((exports, module) => {
21439
21548
  var s = 1000;
@@ -31861,11 +31970,11 @@ var require_mime_types = __commonJS((exports) => {
31861
31970
  }
31862
31971
  return exts[0];
31863
31972
  }
31864
- function lookup(path4) {
31865
- if (!path4 || typeof path4 !== "string") {
31973
+ function lookup(path5) {
31974
+ if (!path5 || typeof path5 !== "string") {
31866
31975
  return false;
31867
31976
  }
31868
- var extension2 = extname("x." + path4).toLowerCase().slice(1);
31977
+ var extension2 = extname("x." + path5).toLowerCase().slice(1);
31869
31978
  if (!extension2) {
31870
31979
  return false;
31871
31980
  }
@@ -34666,18 +34775,27 @@ var exports_http = {};
34666
34775
  __export(exports_http, {
34667
34776
  serve: () => serve,
34668
34777
  methodNotAllowed: () => methodNotAllowed,
34778
+ getHandlers: () => getHandlers,
34669
34779
  configureServer: () => configureServer,
34670
34780
  checkSecurity: () => checkSecurity,
34671
- HANDLERS: () => HANDLERS,
34672
34781
  ENDPOINT: () => ENDPOINT
34673
34782
  });
34674
34783
  import http from "node:http";
34784
+ function getHandlers(config) {
34785
+ return {
34786
+ "": createHandleHtml(config),
34787
+ config: createHandleConfig(config),
34788
+ mcp: handleMcp,
34789
+ shell: handleShell
34790
+ };
34791
+ }
34675
34792
  function configureServer(server = import_connect.default(), config = DEFAULT_OPTIONS) {
34676
34793
  const securityChecker = checkSecurity(config);
34677
34794
  server.use(`${ENDPOINT}`, securityChecker);
34678
34795
  server.use(`${ENDPOINT}`, import_body_parser.default.json());
34679
- for (const [path4, handler] of Object.entries(HANDLERS)) {
34680
- server.use(ENDPOINT + "/" + path4, handler);
34796
+ const handlers = getHandlers(config);
34797
+ for (const [path5, handler] of Object.entries(handlers)) {
34798
+ server.use(ENDPOINT + "/" + path5, handler);
34681
34799
  }
34682
34800
  return server;
34683
34801
  }
@@ -34699,11 +34817,13 @@ function methodNotAllowed(res) {
34699
34817
  res.end();
34700
34818
  return;
34701
34819
  }
34702
- var import_connect, import_body_parser, ENDPOINT = "/tidewave", DEFAULT_PORT = 5001, DEFAULT_OPTIONS, HANDLERS;
34820
+ var import_connect, import_body_parser, ENDPOINT = "/tidewave", DEFAULT_PORT = 5001, DEFAULT_OPTIONS;
34703
34821
  var init_http = __esm(() => {
34704
34822
  import_connect = __toESM(require_connect(), 1);
34705
34823
  init_mcp3();
34706
34824
  init_shell();
34825
+ init_html();
34826
+ init_config();
34707
34827
  import_body_parser = __toESM(require_body_parser(), 1);
34708
34828
  DEFAULT_OPTIONS = {
34709
34829
  allowRemoteAccess: false,
@@ -34711,10 +34831,6 @@ var init_http = __esm(() => {
34711
34831
  port: 5001,
34712
34832
  host: "localhost"
34713
34833
  };
34714
- HANDLERS = {
34715
- mcp: handleMcp,
34716
- shell: handleShell
34717
- };
34718
34834
  });
34719
34835
 
34720
34836
  // src/logger/tidewave-span-processor.ts
@@ -34736,8 +34852,8 @@ class TidewaveSpanProcessor {
34736
34852
  const httpUrl = span.attributes["http.url"];
34737
34853
  const httpTarget = span.attributes["http.target"];
34738
34854
  const httpStatusCode = span.attributes["http.status_code"];
34739
- const path4 = route || httpTarget || httpUrl || "unknown";
34740
- if (typeof path4 === "string" && path4.startsWith("/tidewave")) {
34855
+ const path5 = route || httpTarget || httpUrl || "unknown";
34856
+ if (typeof path5 === "string" && path5.startsWith("/tidewave")) {
34741
34857
  return;
34742
34858
  }
34743
34859
  const durationMs = this.calculateDuration(span);
@@ -34746,7 +34862,7 @@ class TidewaveSpanProcessor {
34746
34862
  if (spanType === "BaseServer.handleRequest") {
34747
34863
  const method = httpMethod || "UNKNOWN";
34748
34864
  const status = httpStatusCode || "unknown";
34749
- message = `${method} ${path4} ${status} ${durationMs.toFixed(2)}ms`;
34865
+ message = `${method} ${path5} ${status} ${durationMs.toFixed(2)}ms`;
34750
34866
  if (typeof httpStatusCode === "number") {
34751
34867
  if (httpStatusCode >= 500)
34752
34868
  severity = "ERROR";
@@ -34877,6 +34993,7 @@ var init_instrumentation = __esm(() => {
34877
34993
 
34878
34994
  // src/vite-plugin.ts
34879
34995
  init_http();
34996
+ init_core();
34880
34997
  init_instrumentation();
34881
34998
  var DEFAULT_CONFIG = {
34882
34999
  port: 5173,
@@ -34902,7 +35019,9 @@ async function tidewaveServer(server, config = DEFAULT_CONFIG) {
34902
35019
  console.error(`[Tidewave] should have both host and port configured, got: host: ${host} port: ${port}`);
34903
35020
  return;
34904
35021
  }
34905
- server.middlewares = configureServer(server.middlewares, config);
35022
+ config.framework = "vite";
35023
+ config.projectName = config.projectName || await getProjectName("vite_app");
35024
+ configureServer(server.middlewares, config);
34906
35025
  }
34907
35026
  export {
34908
35027
  tidewave as default
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tidewave",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Tidewave for JavaScript/Next.js",
5
5
  "keywords": [
6
6
  "typescript",
@@ -54,7 +54,7 @@
54
54
  ],
55
55
  "scripts": {
56
56
  "dist": "bun run clean && bun run build:js && bun run build:types",
57
- "build:js": "bun build --outdir dist --root src --external commander --external chalk --external typescript --external child_process --external module --external @opentelemetry/api --external @opentelemetry/api-logs --external @opentelemetry/core --external @opentelemetry/resources --external @opentelemetry/sdk-logs --external @opentelemetry/sdk-trace-base --external @opentelemetry/sdk-trace-node --external @opentelemetry/semantic-conventions src/next-js/handler.ts src/next-js/instrumentation.ts src/vite-plugin.ts src/evaluation/eval_worker.ts src/cli/index.ts --target node",
57
+ "build:js": "bun build --outdir dist --root src --external typescript --external child_process --external module --external @opentelemetry/api --external @opentelemetry/sdk-logs --external @opentelemetry/sdk-trace-base src/next-js/handler.ts src/next-js/instrumentation.ts src/vite-plugin.ts src/evaluation/eval_worker.ts src/cli/index.ts --target node",
58
58
  "build:types": "tsc -p tsconfig.declarations.json",
59
59
  "dev": "bun run src/cli/index.ts",
60
60
  "test": "bun test",
@@ -74,7 +74,9 @@
74
74
  },
75
75
  "devDependencies": {
76
76
  "@eslint/js": "^9.16.0",
77
- "@opentelemetry/sdk-trace-node": "^2.1.0",
77
+ "@opentelemetry/api": "^1.9.0",
78
+ "@opentelemetry/sdk-logs": "^0.206.0",
79
+ "@opentelemetry/sdk-trace-base": "^2.1.0",
78
80
  "@types/body-parser": "^1.19.6",
79
81
  "@types/bun": "latest",
80
82
  "@types/connect": "^3.4.38",
@@ -84,8 +86,8 @@
84
86
  "@vercel/otel": "^2.0.1",
85
87
  "@vitest/ui": "^3.2.4",
86
88
  "bun-types": "latest",
87
- "commander": "^12.1.0",
88
89
  "chalk": "^5.3.0",
90
+ "commander": "^12.1.0",
89
91
  "eslint": "^9.16.0",
90
92
  "globals": "^15.14.0",
91
93
  "next": "^15.5.3",