@langwatch/server 3.1.0-beta.3 → 3.1.0-beta.5

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 (119) hide show
  1. package/langwatch/ee/admin/ImpersonationBanner.tsx +61 -0
  2. package/langwatch/ee/admin/ImpersonationSwitchBackMenuItem.tsx +30 -0
  3. package/langwatch/ee/admin/__tests__/ImpersonationBanner.integration.test.tsx +82 -0
  4. package/langwatch/ee/admin/__tests__/impersonation.service.unit.test.ts +231 -0
  5. package/langwatch/ee/admin/backoffice/BackofficeTable.tsx +200 -0
  6. package/langwatch/ee/admin/backoffice/__tests__/adminClient.unit.test.ts +147 -0
  7. package/langwatch/ee/admin/backoffice/__tests__/dateInputToISO.unit.test.ts +42 -0
  8. package/langwatch/ee/admin/backoffice/__tests__/userVisibility.unit.test.ts +174 -0
  9. package/langwatch/ee/admin/backoffice/adminClient.ts +114 -0
  10. package/langwatch/ee/admin/backoffice/resources/OrganizationFeaturesView.tsx +373 -0
  11. package/langwatch/ee/admin/backoffice/resources/OrganizationsView.tsx +677 -0
  12. package/langwatch/ee/admin/backoffice/resources/ProjectsView.tsx +647 -0
  13. package/langwatch/ee/admin/backoffice/resources/SubscriptionsView.tsx +628 -0
  14. package/langwatch/ee/admin/backoffice/resources/UsersView.tsx +556 -0
  15. package/langwatch/ee/admin/backoffice/useAdminResource.ts +104 -0
  16. package/langwatch/ee/admin/backoffice/userVisibility.ts +105 -0
  17. package/langwatch/ee/admin/impersonation.service.ts +170 -0
  18. package/langwatch/ee/admin/isAdmin.ts +9 -0
  19. package/langwatch/ee/admin/routes/admin.ts +531 -0
  20. package/langwatch/ee/admin/safeSelects.ts +64 -0
  21. package/langwatch/ee/billing/__tests__/customerService.unit.test.ts +183 -0
  22. package/langwatch/ee/billing/__tests__/growthSeatEvent.unit.test.ts +213 -0
  23. package/langwatch/ee/billing/__tests__/licensePurchaseHandler.unit.test.ts +250 -0
  24. package/langwatch/ee/billing/__tests__/notification.service.unit.test.ts +768 -0
  25. package/langwatch/ee/billing/__tests__/planLimits.unit.test.ts +19 -0
  26. package/langwatch/ee/billing/__tests__/planProvider.unit.test.ts +440 -0
  27. package/langwatch/ee/billing/__tests__/planTypes.unit.test.ts +32 -0
  28. package/langwatch/ee/billing/__tests__/pricing.unit.test.ts +54 -0
  29. package/langwatch/ee/billing/__tests__/seatEventSubscription.unit.test.ts +717 -0
  30. package/langwatch/ee/billing/__tests__/stripe.integration.test.ts +344 -0
  31. package/langwatch/ee/billing/__tests__/stripePrices.types.unit.test.ts +27 -0
  32. package/langwatch/ee/billing/__tests__/stripePricesLoader.unit.test.ts +72 -0
  33. package/langwatch/ee/billing/__tests__/subscription.service.unit.test.ts +730 -0
  34. package/langwatch/ee/billing/__tests__/subscriptionItemCalculator.unit.test.ts +176 -0
  35. package/langwatch/ee/billing/__tests__/usage-limit.service.unit.test.ts +706 -0
  36. package/langwatch/ee/billing/__tests__/usageReportingService.integration.test.ts +421 -0
  37. package/langwatch/ee/billing/__tests__/usageReportingService.unit.test.ts +515 -0
  38. package/langwatch/ee/billing/__tests__/webhookService.unit.test.ts +958 -0
  39. package/langwatch/ee/billing/currencyRouter.ts +18 -0
  40. package/langwatch/ee/billing/errors.ts +129 -0
  41. package/langwatch/ee/billing/index.ts +67 -0
  42. package/langwatch/ee/billing/middleware.ts +17 -0
  43. package/langwatch/ee/billing/notifications/notification.service.ts +651 -0
  44. package/langwatch/ee/billing/notifications/repositories/notification.repository.ts +51 -0
  45. package/langwatch/ee/billing/notifications/types.ts +9 -0
  46. package/langwatch/ee/billing/notifications/usage-limit.service.ts +622 -0
  47. package/langwatch/ee/billing/nurturing/hooks/activityTracking.ts +90 -0
  48. package/langwatch/ee/billing/nurturing/hooks/activityTracking.unit.test.ts +237 -0
  49. package/langwatch/ee/billing/nurturing/hooks/featureAdoption.ts +120 -0
  50. package/langwatch/ee/billing/nurturing/hooks/featureAdoption.unit.test.ts +324 -0
  51. package/langwatch/ee/billing/nurturing/hooks/index.ts +17 -0
  52. package/langwatch/ee/billing/nurturing/hooks/productInterest.ts +68 -0
  53. package/langwatch/ee/billing/nurturing/hooks/productInterest.unit.test.ts +138 -0
  54. package/langwatch/ee/billing/nurturing/hooks/promptCreation.integration.test.ts +288 -0
  55. package/langwatch/ee/billing/nurturing/hooks/promptCreation.ts +131 -0
  56. package/langwatch/ee/billing/nurturing/hooks/promptCreation.unit.test.ts +134 -0
  57. package/langwatch/ee/billing/nurturing/hooks/signupIdentification.ts +101 -0
  58. package/langwatch/ee/billing/nurturing/hooks/signupIdentification.unit.test.ts +317 -0
  59. package/langwatch/ee/billing/nurturing/hooks/subscriptionSync.ts +49 -0
  60. package/langwatch/ee/billing/nurturing/hooks/subscriptionSync.unit.test.ts +170 -0
  61. package/langwatch/ee/billing/nurturing/hooks/userSync.ts +143 -0
  62. package/langwatch/ee/billing/nurturing/hooks/userSync.unit.test.ts +307 -0
  63. package/langwatch/ee/billing/nurturing/nurturing.service.ts +179 -0
  64. package/langwatch/ee/billing/nurturing/nurturing.service.unit.test.ts +266 -0
  65. package/langwatch/ee/billing/nurturing/nurturing.service.wiring.unit.test.ts +109 -0
  66. package/langwatch/ee/billing/nurturing/types.ts +125 -0
  67. package/langwatch/ee/billing/planLimits.ts +190 -0
  68. package/langwatch/ee/billing/planProvider.ts +119 -0
  69. package/langwatch/ee/billing/planTypes.ts +53 -0
  70. package/langwatch/ee/billing/pricing.ts +57 -0
  71. package/langwatch/ee/billing/services/billableEventsQuery.ts +248 -0
  72. package/langwatch/ee/billing/services/customerService.ts +90 -0
  73. package/langwatch/ee/billing/services/licensePurchaseHandler.ts +73 -0
  74. package/langwatch/ee/billing/services/seatEventSubscription.ts +351 -0
  75. package/langwatch/ee/billing/services/seatSyncService.ts +34 -0
  76. package/langwatch/ee/billing/services/subscription.repository.ts +203 -0
  77. package/langwatch/ee/billing/services/subscription.service.ts +549 -0
  78. package/langwatch/ee/billing/services/subscriptionItemCalculator.ts +249 -0
  79. package/langwatch/ee/billing/services/usageReportingService.ts +301 -0
  80. package/langwatch/ee/billing/services/webhookService.ts +858 -0
  81. package/langwatch/ee/billing/stripe/stripeCatalog.json +1781 -0
  82. package/langwatch/ee/billing/stripe/stripeClient.ts +13 -0
  83. package/langwatch/ee/billing/stripe/stripePriceCatalog.ts +70 -0
  84. package/langwatch/ee/billing/stripe/stripePrices.types.ts +118 -0
  85. package/langwatch/ee/billing/subscriptionRouter.ts +202 -0
  86. package/langwatch/ee/billing/types.ts +102 -0
  87. package/langwatch/ee/billing/utils/currency.ts +99 -0
  88. package/langwatch/ee/billing/utils/growthSeatEvent.ts +137 -0
  89. package/langwatch/ee/licensing/__tests__/constants.unit.test.ts +56 -0
  90. package/langwatch/ee/licensing/__tests__/defaults.unit.test.ts +192 -0
  91. package/langwatch/ee/licensing/__tests__/fixtures/testKeys.ts +86 -0
  92. package/langwatch/ee/licensing/__tests__/fixtures/testLicenses.ts +92 -0
  93. package/langwatch/ee/licensing/__tests__/licenseGenerationService.unit.test.ts +232 -0
  94. package/langwatch/ee/licensing/__tests__/licenseHandler.integration.test.ts +419 -0
  95. package/langwatch/ee/licensing/__tests__/planMapping.unit.test.ts +195 -0
  96. package/langwatch/ee/licensing/__tests__/planTemplates.unit.test.ts +193 -0
  97. package/langwatch/ee/licensing/__tests__/signing.unit.test.ts +164 -0
  98. package/langwatch/ee/licensing/__tests__/validation.unit.test.ts +281 -0
  99. package/langwatch/ee/licensing/client.ts +29 -0
  100. package/langwatch/ee/licensing/constants.ts +195 -0
  101. package/langwatch/ee/licensing/defaults.ts +55 -0
  102. package/langwatch/ee/licensing/errors.ts +11 -0
  103. package/langwatch/ee/licensing/index.ts +52 -0
  104. package/langwatch/ee/licensing/licenseGenerationService.ts +87 -0
  105. package/langwatch/ee/licensing/licenseHandler.ts +308 -0
  106. package/langwatch/ee/licensing/planInfo.ts +46 -0
  107. package/langwatch/ee/licensing/planMapping.ts +37 -0
  108. package/langwatch/ee/licensing/planTemplates.ts +109 -0
  109. package/langwatch/ee/licensing/server.ts +43 -0
  110. package/langwatch/ee/licensing/signing.ts +43 -0
  111. package/langwatch/ee/licensing/types.ts +156 -0
  112. package/langwatch/ee/licensing/validation.ts +107 -0
  113. package/langwatch/ee/managed-providers/ManagedModelProviderAlert.tsx +29 -0
  114. package/langwatch/ee/managed-providers/managedBedrockConfig.ts +226 -0
  115. package/langwatch/ee/saas/ExtraFooterComponents.tsx +169 -0
  116. package/langwatch/package.json +1 -1
  117. package/langwatch_nlp/uv.lock +179 -5
  118. package/package.json +1 -1
  119. package/packages/server/dist/cli.cjs +192 -142
@@ -19071,6 +19071,37 @@ var init_cli_truncate = __esm({
19071
19071
  }
19072
19072
  });
19073
19073
 
19074
+ // src/shared/paths.ts
19075
+ var import_node_os7, import_node_path6, root, paths;
19076
+ var init_paths = __esm({
19077
+ "src/shared/paths.ts"() {
19078
+ "use strict";
19079
+ import_node_os7 = require("node:os");
19080
+ import_node_path6 = require("node:path");
19081
+ root = process.env.LANGWATCH_HOME?.length ? process.env.LANGWATCH_HOME : (0, import_node_path6.join)((0, import_node_os7.homedir)(), ".langwatch");
19082
+ paths = {
19083
+ root,
19084
+ bin: (0, import_node_path6.join)(root, "bin"),
19085
+ // The @langwatch/server tree (langwatch/, langwatch_nlp/, langevals/,
19086
+ // python-sdk/, etc.) is relocated here on first run. tsx 4.x bypasses
19087
+ // tsconfig path-alias resolution for any source file whose parent path
19088
+ // includes "/node_modules/" (its guard against transpiling 3rd-party
19089
+ // deps), and npx unpacks INTO node_modules — so we have to move the app
19090
+ // out before pnpm scripts that depend on `~/...` aliases can work.
19091
+ app: (0, import_node_path6.join)(root, "app"),
19092
+ data: (0, import_node_path6.join)(root, "data"),
19093
+ redisData: (0, import_node_path6.join)(root, "data", "redis"),
19094
+ postgresData: (0, import_node_path6.join)(root, "data", "postgres"),
19095
+ clickhouseData: (0, import_node_path6.join)(root, "data", "clickhouse"),
19096
+ logs: (0, import_node_path6.join)(root, "logs"),
19097
+ pidFile: (0, import_node_path6.join)(root, "run", "langwatch.pid"),
19098
+ lockFile: (0, import_node_path6.join)(root, "run", "langwatch.lock"),
19099
+ envFile: (0, import_node_path6.join)(root, ".env"),
19100
+ installManifest: (0, import_node_path6.join)(root, "install-manifest.json")
19101
+ };
19102
+ }
19103
+ });
19104
+
19074
19105
  // ../../node_modules/.pnpm/tar@7.5.13/node_modules/tar/dist/esm/index.min.js
19075
19106
  var index_min_exports = {};
19076
19107
  __export(index_min_exports, {
@@ -22297,7 +22328,7 @@ function servicePaths(p2) {
22297
22328
  };
22298
22329
  }
22299
22330
  var import_node_path23;
22300
- var init_paths = __esm({
22331
+ var init_paths2 = __esm({
22301
22332
  "src/services/paths.ts"() {
22302
22333
  "use strict";
22303
22334
  import_node_path23 = require("node:path");
@@ -22433,11 +22464,77 @@ var init_aigateway = __esm({
22433
22464
  "src/services/aigateway.ts"() {
22434
22465
  "use strict";
22435
22466
  init_health();
22436
- init_paths();
22467
+ init_paths2();
22437
22468
  init_spawn();
22438
22469
  }
22439
22470
  });
22440
22471
 
22472
+ // src/services/app-dir.ts
22473
+ function locatePackageSource() {
22474
+ const candidate = (0, import_node_path25.join)(__dirname, "..", "..", "..");
22475
+ if ((0, import_node_fs22.existsSync)((0, import_node_path25.join)(candidate, "langwatch", "package.json"))) {
22476
+ return candidate;
22477
+ }
22478
+ return null;
22479
+ }
22480
+ function isUnderNodeModules(p2) {
22481
+ return p2.split(/[\\/]/).includes("node_modules");
22482
+ }
22483
+ async function ensureAppDir(ctx, bus) {
22484
+ const src = locatePackageSource();
22485
+ if (!src) throw new Error("could not locate @langwatch/server package source");
22486
+ if (!isUnderNodeModules(src)) return;
22487
+ const dst = ctx.paths.app;
22488
+ const versionMarker = (0, import_node_path25.join)(dst, ".installed-version");
22489
+ if ((0, import_node_fs22.existsSync)(versionMarker)) {
22490
+ const installed = (0, import_node_fs22.readFileSync)(versionMarker, "utf8").trim();
22491
+ if (installed === ctx.version) return;
22492
+ }
22493
+ bus.emit({ type: "starting", service: "app:relocate" });
22494
+ const start = Date.now();
22495
+ (0, import_node_fs22.mkdirSync)(dst, { recursive: true });
22496
+ const rsyncProbe = await execa("which", ["rsync"], { reject: false });
22497
+ if (rsyncProbe.exitCode === 0) {
22498
+ await execa(
22499
+ "rsync",
22500
+ [
22501
+ "-a",
22502
+ "--delete",
22503
+ "--exclude=node_modules",
22504
+ "--exclude=.installed-version",
22505
+ "--exclude=.git",
22506
+ `${src}/`,
22507
+ `${dst}/`
22508
+ ],
22509
+ { stdio: "pipe" }
22510
+ );
22511
+ } else {
22512
+ await execa("sh", ["-c", `tar -cf - --exclude=node_modules --exclude=.git -C "${src}" . | tar -xf - -C "${dst}"`]);
22513
+ }
22514
+ (0, import_node_fs22.writeFileSync)(versionMarker, ctx.version);
22515
+ bus.emit({ type: "healthy", service: "app:relocate", durationMs: Date.now() - start });
22516
+ }
22517
+ function appRoot() {
22518
+ if ((0, import_node_fs22.existsSync)((0, import_node_path25.join)(paths.app, ".installed-version"))) {
22519
+ return paths.app;
22520
+ }
22521
+ const src = locatePackageSource();
22522
+ if (!src) throw new Error("@langwatch/server tree not found (neither relocated nor in source layout)");
22523
+ return src;
22524
+ }
22525
+ var import_node_fs22, import_node_path25, import_node_url4, __dirname;
22526
+ var init_app_dir = __esm({
22527
+ "src/services/app-dir.ts"() {
22528
+ "use strict";
22529
+ init_execa();
22530
+ import_node_fs22 = require("node:fs");
22531
+ import_node_path25 = require("node:path");
22532
+ import_node_url4 = require("node:url");
22533
+ init_paths();
22534
+ __dirname = (0, import_node_path25.dirname)((0, import_node_url4.fileURLToPath)(__cli_url));
22535
+ }
22536
+ });
22537
+
22441
22538
  // src/services/clickhouse.ts
22442
22539
  async function startClickhouse(ctx, bus) {
22443
22540
  bus.emit({ type: "starting", service: "clickhouse" });
@@ -22445,8 +22542,8 @@ async function startClickhouse(ctx, bus) {
22445
22542
  const resolvedPath = ctx.predeps.clickhouse?.resolvedPath;
22446
22543
  if (!resolvedPath) throw new Error("clickhouse predep not resolved \u2014 run install first");
22447
22544
  const sp = servicePaths(ctx.paths);
22448
- const configFile = (0, import_node_path25.join)(sp.clickhouseConfigDir, "config.xml");
22449
- if (!(0, import_node_fs22.existsSync)(configFile)) writeClickhouseConfig(configFile, ctx);
22545
+ const configFile = (0, import_node_path26.join)(sp.clickhouseConfigDir, "config.xml");
22546
+ if (!(0, import_node_fs23.existsSync)(configFile)) writeClickhouseConfig(configFile, ctx);
22450
22547
  const handle = supervise({
22451
22548
  spec: {
22452
22549
  name: "clickhouse",
@@ -22485,13 +22582,13 @@ async function ensureDatabase(ctx) {
22485
22582
  function writeClickhouseConfig(path6, ctx) {
22486
22583
  const dataDir = ctx.paths.clickhouseData;
22487
22584
  const logsDir = ctx.paths.logs;
22488
- const tmpDir = (0, import_node_path25.join)(dataDir, "tmp");
22489
- const userFiles = (0, import_node_path25.join)(dataDir, "user_files");
22490
- (0, import_node_fs22.mkdirSync)(ctx.paths.clickhouseData, { recursive: true });
22491
- (0, import_node_fs22.mkdirSync)(tmpDir, { recursive: true });
22492
- (0, import_node_fs22.mkdirSync)(userFiles, { recursive: true });
22493
- (0, import_node_fs22.mkdirSync)(logsDir, { recursive: true });
22494
- (0, import_node_fs22.mkdirSync)(path6.replace(/\/[^/]+$/, ""), { recursive: true });
22585
+ const tmpDir = (0, import_node_path26.join)(dataDir, "tmp");
22586
+ const userFiles = (0, import_node_path26.join)(dataDir, "user_files");
22587
+ (0, import_node_fs23.mkdirSync)(ctx.paths.clickhouseData, { recursive: true });
22588
+ (0, import_node_fs23.mkdirSync)(tmpDir, { recursive: true });
22589
+ (0, import_node_fs23.mkdirSync)(userFiles, { recursive: true });
22590
+ (0, import_node_fs23.mkdirSync)(logsDir, { recursive: true });
22591
+ (0, import_node_fs23.mkdirSync)(path6.replace(/\/[^/]+$/, ""), { recursive: true });
22495
22592
  const xml = `<?xml version="1.0"?>
22496
22593
  <clickhouse>
22497
22594
  <listen_host>127.0.0.1</listen_host>
@@ -22525,16 +22622,16 @@ function writeClickhouseConfig(path6, ctx) {
22525
22622
  <quotas><default/></quotas>
22526
22623
  </clickhouse>
22527
22624
  `;
22528
- (0, import_node_fs22.writeFileSync)(path6, xml);
22625
+ (0, import_node_fs23.writeFileSync)(path6, xml);
22529
22626
  }
22530
- var import_node_fs22, import_node_path25, DB_NAME;
22627
+ var import_node_fs23, import_node_path26, DB_NAME;
22531
22628
  var init_clickhouse = __esm({
22532
22629
  "src/services/clickhouse.ts"() {
22533
22630
  "use strict";
22534
- import_node_fs22 = require("node:fs");
22535
- import_node_path25 = require("node:path");
22631
+ import_node_fs23 = require("node:fs");
22632
+ import_node_path26 = require("node:path");
22536
22633
  init_health();
22537
- init_paths();
22634
+ init_paths2();
22538
22635
  init_spawn();
22539
22636
  DB_NAME = "langwatch";
22540
22637
  }
@@ -22553,9 +22650,9 @@ var init_env2 = __esm({
22553
22650
 
22554
22651
  // src/services/env-file.ts
22555
22652
  function readEnvFile(path6) {
22556
- if (!(0, import_node_fs23.existsSync)(path6)) return {};
22653
+ if (!(0, import_node_fs24.existsSync)(path6)) return {};
22557
22654
  const out = {};
22558
- for (const rawLine of (0, import_node_fs23.readFileSync)(path6, "utf8").split(/\r?\n/)) {
22655
+ for (const rawLine of (0, import_node_fs24.readFileSync)(path6, "utf8").split(/\r?\n/)) {
22559
22656
  const line = rawLine.trim();
22560
22657
  if (!line || line.startsWith("#")) continue;
22561
22658
  const eq = line.indexOf("=");
@@ -22569,11 +22666,11 @@ function readEnvFile(path6) {
22569
22666
  }
22570
22667
  return out;
22571
22668
  }
22572
- var import_node_fs23;
22669
+ var import_node_fs24;
22573
22670
  var init_env_file = __esm({
22574
22671
  "src/services/env-file.ts"() {
22575
22672
  "use strict";
22576
- import_node_fs23 = require("node:fs");
22673
+ import_node_fs24 = require("node:fs");
22577
22674
  }
22578
22675
  });
22579
22676
 
@@ -22642,7 +22739,7 @@ async function startLangevals(ctx, bus, envFromFile) {
22642
22739
  projectDir,
22643
22740
  "--no-sync",
22644
22741
  "python",
22645
- (0, import_node_path26.join)("langevals", "server.py")
22742
+ (0, import_node_path27.join)("langevals", "server.py")
22646
22743
  ],
22647
22744
  env: {
22648
22745
  ...process.env,
@@ -22668,24 +22765,19 @@ async function startLangevals(ctx, bus, envFromFile) {
22668
22765
  return handle;
22669
22766
  }
22670
22767
  function locateProject(name) {
22671
- const candidates = [
22672
- (0, import_node_path26.join)(__dirname, "..", "..", "..", "..", name),
22673
- (0, import_node_path26.join)(__dirname, "..", "..", "..", name),
22674
- (0, import_node_path26.join)(process.cwd(), name)
22675
- ];
22676
- return candidates.find((p2) => (0, import_node_fs24.existsSync)((0, import_node_path26.join)(p2, "pyproject.toml"))) ?? null;
22768
+ const dir = (0, import_node_path27.join)(appRoot(), name);
22769
+ return (0, import_node_fs25.existsSync)((0, import_node_path27.join)(dir, "pyproject.toml")) ? dir : null;
22677
22770
  }
22678
- var import_node_fs24, import_node_path26, import_node_url4, __dirname;
22771
+ var import_node_fs25, import_node_path27;
22679
22772
  var init_langevals = __esm({
22680
22773
  "src/services/langevals.ts"() {
22681
22774
  "use strict";
22682
- import_node_fs24 = require("node:fs");
22683
- import_node_path26 = require("node:path");
22684
- import_node_url4 = require("node:url");
22775
+ import_node_fs25 = require("node:fs");
22776
+ import_node_path27 = require("node:path");
22777
+ init_app_dir();
22685
22778
  init_health();
22686
- init_paths();
22779
+ init_paths2();
22687
22780
  init_spawn();
22688
- __dirname = (0, import_node_path26.dirname)((0, import_node_url4.fileURLToPath)(__cli_url));
22689
22781
  }
22690
22782
  });
22691
22783
 
@@ -22693,16 +22785,16 @@ var init_langevals = __esm({
22693
22785
  async function ensureLangwatchDeps(ctx, bus) {
22694
22786
  const langwatchDir = locateLangwatchDir();
22695
22787
  if (!langwatchDir) throw new Error("langwatch app dir not found");
22696
- const nodeModulesPath = (0, import_node_path27.join)(langwatchDir, "node_modules");
22697
- const distPath = (0, import_node_path27.join)(langwatchDir, "dist");
22698
- if ((0, import_node_fs25.existsSync)(nodeModulesPath) && (0, import_node_fs25.existsSync)((0, import_node_path27.join)(nodeModulesPath, ".prisma")) && (0, import_node_fs25.existsSync)((0, import_node_path27.join)(distPath, "client"))) {
22788
+ const nodeModulesPath = (0, import_node_path28.join)(langwatchDir, "node_modules");
22789
+ const distPath = (0, import_node_path28.join)(langwatchDir, "dist");
22790
+ if ((0, import_node_fs26.existsSync)(nodeModulesPath) && (0, import_node_fs26.existsSync)((0, import_node_path28.join)(nodeModulesPath, ".prisma")) && (0, import_node_fs26.existsSync)((0, import_node_path28.join)(distPath, "client"))) {
22699
22791
  return;
22700
22792
  }
22701
22793
  bus.emit({ type: "starting", service: "pnpm:langwatch" });
22702
22794
  const start = Date.now();
22703
22795
  const pnpm = await resolvePnpm();
22704
- const distAlreadyBuilt = (0, import_node_fs25.existsSync)((0, import_node_path27.join)(distPath, "client"));
22705
- if (!(0, import_node_fs25.existsSync)(nodeModulesPath)) {
22796
+ const distAlreadyBuilt = (0, import_node_fs26.existsSync)((0, import_node_path28.join)(distPath, "client"));
22797
+ if (!(0, import_node_fs26.existsSync)(nodeModulesPath)) {
22706
22798
  await execa(pnpm.command, [...pnpm.args, "-C", langwatchDir, "install", "--prod=false", "--frozen-lockfile"], {
22707
22799
  stdio: "inherit"
22708
22800
  });
@@ -22731,30 +22823,17 @@ async function resolvePnpm() {
22731
22823
  throw new Error("pnpm not found on PATH and corepack is unavailable");
22732
22824
  }
22733
22825
  function locateLangwatchDir() {
22734
- const candidates = [
22735
- (0, import_node_path27.join)(__dirname2, "..", "..", "..", "langwatch"),
22736
- (0, import_node_path27.join)(process.cwd(), "langwatch")
22737
- ];
22738
- for (const p2 of candidates) {
22739
- const pkgPath = (0, import_node_path27.join)(p2, "package.json");
22740
- if (!(0, import_node_fs25.existsSync)(pkgPath)) continue;
22741
- try {
22742
- const pkg = JSON.parse((0, import_node_fs25.readFileSync)(pkgPath, "utf8"));
22743
- if (pkg.name === "langwatch") return p2;
22744
- } catch {
22745
- }
22746
- }
22747
- return null;
22826
+ const dir = (0, import_node_path28.join)(appRoot(), "langwatch");
22827
+ return (0, import_node_fs26.existsSync)((0, import_node_path28.join)(dir, "package.json")) ? dir : null;
22748
22828
  }
22749
- var import_node_fs25, import_node_path27, import_node_url5, __dirname2;
22829
+ var import_node_fs26, import_node_path28;
22750
22830
  var init_node_deps = __esm({
22751
22831
  "src/services/node-deps.ts"() {
22752
22832
  "use strict";
22753
22833
  init_execa();
22754
- import_node_fs25 = require("node:fs");
22755
- import_node_path27 = require("node:path");
22756
- import_node_url5 = require("node:url");
22757
- __dirname2 = (0, import_node_path27.dirname)((0, import_node_url5.fileURLToPath)(__cli_url));
22834
+ import_node_fs26 = require("node:fs");
22835
+ import_node_path28 = require("node:path");
22836
+ init_app_dir();
22758
22837
  }
22759
22838
  });
22760
22839
 
@@ -22801,23 +22880,23 @@ async function startLangwatch(ctx, bus, envFromFile) {
22801
22880
  return handle;
22802
22881
  }
22803
22882
  async function ensureNodeModules(langwatchDir, bus) {
22804
- if ((0, import_node_fs26.existsSync)((0, import_node_path28.join)(langwatchDir, "node_modules"))) return;
22883
+ if ((0, import_node_fs27.existsSync)((0, import_node_path29.join)(langwatchDir, "node_modules"))) return;
22805
22884
  bus.emit({ type: "log", service: "langwatch", stream: "stdout", line: "installing node_modules (one-time setup)..." });
22806
22885
  await execa("pnpm", ["install", "--prod=false", "--frozen-lockfile"], {
22807
22886
  cwd: langwatchDir,
22808
22887
  stdio: "inherit"
22809
22888
  });
22810
22889
  }
22811
- var import_node_fs26, import_node_path28;
22890
+ var import_node_fs27, import_node_path29;
22812
22891
  var init_langwatch = __esm({
22813
22892
  "src/services/langwatch.ts"() {
22814
22893
  "use strict";
22815
22894
  init_execa();
22816
- import_node_fs26 = require("node:fs");
22817
- import_node_path28 = require("node:path");
22895
+ import_node_fs27 = require("node:fs");
22896
+ import_node_path29 = require("node:path");
22818
22897
  init_health();
22819
22898
  init_node_deps();
22820
- init_paths();
22899
+ init_paths2();
22821
22900
  init_spawn();
22822
22901
  }
22823
22902
  });
@@ -22873,24 +22952,19 @@ async function startLangwatchNlp(ctx, bus, envFromFile) {
22873
22952
  return handle;
22874
22953
  }
22875
22954
  function locateProject2(name) {
22876
- const candidates = [
22877
- (0, import_node_path29.join)(__dirname3, "..", "..", "..", "..", name),
22878
- (0, import_node_path29.join)(__dirname3, "..", "..", "..", name),
22879
- (0, import_node_path29.join)(process.cwd(), name)
22880
- ];
22881
- return candidates.find((p2) => (0, import_node_fs27.existsSync)((0, import_node_path29.join)(p2, "pyproject.toml"))) ?? null;
22955
+ const dir = (0, import_node_path30.join)(appRoot(), name);
22956
+ return (0, import_node_fs28.existsSync)((0, import_node_path30.join)(dir, "pyproject.toml")) ? dir : null;
22882
22957
  }
22883
- var import_node_fs27, import_node_path29, import_node_url6, __dirname3;
22958
+ var import_node_fs28, import_node_path30;
22884
22959
  var init_langwatch_nlp = __esm({
22885
22960
  "src/services/langwatch-nlp.ts"() {
22886
22961
  "use strict";
22887
- import_node_fs27 = require("node:fs");
22888
- import_node_path29 = require("node:path");
22889
- import_node_url6 = require("node:url");
22962
+ import_node_fs28 = require("node:fs");
22963
+ import_node_path30 = require("node:path");
22964
+ init_app_dir();
22890
22965
  init_health();
22891
- init_paths();
22966
+ init_paths2();
22892
22967
  init_spawn();
22893
- __dirname3 = (0, import_node_path29.dirname)((0, import_node_url6.fileURLToPath)(__cli_url));
22894
22968
  }
22895
22969
  });
22896
22970
 
@@ -22932,13 +23006,13 @@ var init_migrate = __esm({
22932
23006
 
22933
23007
  // src/services/postgres.ts
22934
23008
  function postgresLayout(postgresBinPath) {
22935
- const binDir = (0, import_node_path30.dirname)(postgresBinPath);
23009
+ const binDir = (0, import_node_path31.dirname)(postgresBinPath);
22936
23010
  return {
22937
23011
  postgresBin: postgresBinPath,
22938
- initdb: (0, import_node_path30.join)(binDir, "initdb"),
22939
- pgCtl: (0, import_node_path30.join)(binDir, "pg_ctl"),
22940
- psql: (0, import_node_path30.join)(binDir, "psql"),
22941
- createdb: (0, import_node_path30.join)(binDir, "createdb")
23012
+ initdb: (0, import_node_path31.join)(binDir, "initdb"),
23013
+ pgCtl: (0, import_node_path31.join)(binDir, "pg_ctl"),
23014
+ psql: (0, import_node_path31.join)(binDir, "psql"),
23015
+ createdb: (0, import_node_path31.join)(binDir, "createdb")
22942
23016
  };
22943
23017
  }
22944
23018
  async function startPostgres(ctx, bus) {
@@ -22949,7 +23023,7 @@ async function startPostgres(ctx, bus) {
22949
23023
  const layout = postgresLayout(resolvedPath);
22950
23024
  const dataDir = ctx.paths.postgresData;
22951
23025
  const sp = servicePaths(ctx.paths);
22952
- if (!(0, import_node_fs28.existsSync)((0, import_node_path30.join)(dataDir, "PG_VERSION"))) {
23026
+ if (!(0, import_node_fs29.existsSync)((0, import_node_path31.join)(dataDir, "PG_VERSION"))) {
22953
23027
  await initdb(layout, dataDir);
22954
23028
  }
22955
23029
  const handle = supervise({
@@ -22964,7 +23038,7 @@ async function startPostgres(ctx, bus) {
22964
23038
  "-h",
22965
23039
  "127.0.0.1",
22966
23040
  "-c",
22967
- "unix_socket_directories=" + (0, import_node_path30.dirname)(sp.pid("postgres")),
23041
+ "unix_socket_directories=" + (0, import_node_path31.dirname)(sp.pid("postgres")),
22968
23042
  "-c",
22969
23043
  "log_destination=stderr",
22970
23044
  "-c",
@@ -22998,7 +23072,7 @@ async function startPostgres(ctx, bus) {
22998
23072
  return handle;
22999
23073
  }
23000
23074
  async function initdb(layout, dataDir) {
23001
- (0, import_node_fs28.mkdirSync)(dataDir, { recursive: true });
23075
+ (0, import_node_fs29.mkdirSync)(dataDir, { recursive: true });
23002
23076
  await execa(
23003
23077
  layout.initdb,
23004
23078
  [
@@ -23067,15 +23141,15 @@ async function ensureDatabase2(layout, port) {
23067
23141
  { stdio: "ignore" }
23068
23142
  );
23069
23143
  }
23070
- var import_node_fs28, import_node_path30, DB_USER, DB_NAME2;
23144
+ var import_node_fs29, import_node_path31, DB_USER, DB_NAME2;
23071
23145
  var init_postgres = __esm({
23072
23146
  "src/services/postgres.ts"() {
23073
23147
  "use strict";
23074
23148
  init_execa();
23075
- import_node_fs28 = require("node:fs");
23076
- import_node_path30 = require("node:path");
23149
+ import_node_fs29 = require("node:fs");
23150
+ import_node_path31 = require("node:path");
23077
23151
  init_health();
23078
- init_paths();
23152
+ init_paths2();
23079
23153
  init_spawn();
23080
23154
  DB_USER = "langwatch";
23081
23155
  DB_NAME2 = "langwatch_db";
@@ -23090,7 +23164,7 @@ async function startRedis(ctx, bus) {
23090
23164
  if (!resolvedPath) throw new Error("redis predep not resolved \u2014 run install first");
23091
23165
  const sp = servicePaths(ctx.paths);
23092
23166
  const conf = sp.redisConf;
23093
- if (!(0, import_node_fs29.existsSync)(conf)) writeRedisConf(conf, ctx.ports.redis, ctx.paths.redisData);
23167
+ if (!(0, import_node_fs30.existsSync)(conf)) writeRedisConf(conf, ctx.ports.redis, ctx.paths.redisData);
23094
23168
  const handle = supervise({
23095
23169
  spec: {
23096
23170
  name: "redis",
@@ -23119,8 +23193,8 @@ async function startRedis(ctx, bus) {
23119
23193
  return handle;
23120
23194
  }
23121
23195
  function writeRedisConf(path6, port, dataDir) {
23122
- (0, import_node_fs29.mkdirSync)((0, import_node_path31.dirname)(path6), { recursive: true });
23123
- (0, import_node_fs29.mkdirSync)(dataDir, { recursive: true });
23196
+ (0, import_node_fs30.mkdirSync)((0, import_node_path32.dirname)(path6), { recursive: true });
23197
+ (0, import_node_fs30.mkdirSync)(dataDir, { recursive: true });
23124
23198
  const lines = [
23125
23199
  `port ${port}`,
23126
23200
  "bind 127.0.0.1",
@@ -23134,16 +23208,16 @@ function writeRedisConf(path6, port, dataDir) {
23134
23208
  "maxmemory-policy allkeys-lru",
23135
23209
  ""
23136
23210
  ];
23137
- (0, import_node_fs29.writeFileSync)(path6, lines.join("\n"));
23211
+ (0, import_node_fs30.writeFileSync)(path6, lines.join("\n"));
23138
23212
  }
23139
- var import_node_fs29, import_node_path31;
23213
+ var import_node_fs30, import_node_path32;
23140
23214
  var init_redis = __esm({
23141
23215
  "src/services/redis.ts"() {
23142
23216
  "use strict";
23143
- import_node_fs29 = require("node:fs");
23144
- import_node_path31 = require("node:path");
23217
+ import_node_fs30 = require("node:fs");
23218
+ import_node_path32 = require("node:path");
23145
23219
  init_health();
23146
- init_paths();
23220
+ init_paths2();
23147
23221
  init_spawn();
23148
23222
  }
23149
23223
  });
@@ -23157,12 +23231,12 @@ async function syncVenvs(ctx, bus) {
23157
23231
  await Promise.all(
23158
23232
  specs.map(async (spec) => {
23159
23233
  const venvDir = sp.venv(spec.name);
23160
- const hashFile = (0, import_node_path32.join)(venvDir, ".lock-hash");
23234
+ const hashFile = (0, import_node_path33.join)(venvDir, ".lock-hash");
23161
23235
  const expected = hashFileSafely(spec.lockFile);
23162
- if ((0, import_node_fs30.existsSync)(venvDir) && readFileSafely(hashFile) === expected) return;
23236
+ if ((0, import_node_fs31.existsSync)(venvDir) && readFileSafely(hashFile) === expected) return;
23163
23237
  bus.emit({ type: "starting", service: `uv:${spec.name}` });
23164
23238
  const start = Date.now();
23165
- (0, import_node_fs30.mkdirSync)(venvDir, { recursive: true });
23239
+ (0, import_node_fs31.mkdirSync)(venvDir, { recursive: true });
23166
23240
  await execa(
23167
23241
  uvBin,
23168
23242
  ["sync", "--project", spec.projectDir],
@@ -23174,55 +23248,44 @@ async function syncVenvs(ctx, bus) {
23174
23248
  stdio: "inherit"
23175
23249
  }
23176
23250
  );
23177
- (0, import_node_fs30.writeFileSync)(hashFile, expected);
23251
+ (0, import_node_fs31.writeFileSync)(hashFile, expected);
23178
23252
  bus.emit({ type: "healthy", service: `uv:${spec.name}`, durationMs: Date.now() - start });
23179
23253
  })
23180
23254
  );
23181
23255
  }
23182
23256
  function resolveVenvSpecs() {
23183
- const root2 = locateMonorepoRoot();
23257
+ const root2 = appRoot();
23184
23258
  return [
23185
23259
  {
23186
23260
  name: "langwatch_nlp",
23187
- projectDir: (0, import_node_path32.join)(root2, "langwatch_nlp"),
23188
- lockFile: (0, import_node_path32.join)(root2, "langwatch_nlp", "uv.lock")
23261
+ projectDir: (0, import_node_path33.join)(root2, "langwatch_nlp"),
23262
+ lockFile: (0, import_node_path33.join)(root2, "langwatch_nlp", "uv.lock")
23189
23263
  },
23190
23264
  {
23191
23265
  name: "langevals",
23192
- projectDir: (0, import_node_path32.join)(root2, "langevals"),
23193
- lockFile: (0, import_node_path32.join)(root2, "langevals", "uv.lock")
23266
+ projectDir: (0, import_node_path33.join)(root2, "langevals"),
23267
+ lockFile: (0, import_node_path33.join)(root2, "langevals", "uv.lock")
23194
23268
  }
23195
23269
  ];
23196
23270
  }
23197
- function locateMonorepoRoot() {
23198
- const candidates = [
23199
- (0, import_node_path32.join)(__dirname4, "..", "..", "..", ".."),
23200
- (0, import_node_path32.join)(__dirname4, "..", "..", ".."),
23201
- process.cwd()
23202
- ];
23203
- const fallback = candidates[0];
23204
- if (!fallback) throw new Error("monorepo root candidates list is empty (impossible)");
23205
- return candidates.find((p2) => (0, import_node_fs30.existsSync)((0, import_node_path32.join)(p2, "langwatch_nlp", "uv.lock"))) ?? fallback;
23206
- }
23207
23271
  function hashFileSafely(file) {
23208
- if (!(0, import_node_fs30.existsSync)(file)) return "missing";
23209
- return (0, import_node_crypto5.createHash)("sha256").update((0, import_node_fs30.readFileSync)(file)).digest("hex");
23272
+ if (!(0, import_node_fs31.existsSync)(file)) return "missing";
23273
+ return (0, import_node_crypto5.createHash)("sha256").update((0, import_node_fs31.readFileSync)(file)).digest("hex");
23210
23274
  }
23211
23275
  function readFileSafely(file) {
23212
- if (!(0, import_node_fs30.existsSync)(file)) return null;
23213
- return (0, import_node_fs30.readFileSync)(file, "utf8").trim();
23276
+ if (!(0, import_node_fs31.existsSync)(file)) return null;
23277
+ return (0, import_node_fs31.readFileSync)(file, "utf8").trim();
23214
23278
  }
23215
- var import_node_fs30, import_node_crypto5, import_node_path32, import_node_url7, __dirname4;
23279
+ var import_node_fs31, import_node_crypto5, import_node_path33;
23216
23280
  var init_venvs = __esm({
23217
23281
  "src/services/venvs.ts"() {
23218
23282
  "use strict";
23219
23283
  init_execa();
23220
- import_node_fs30 = require("node:fs");
23284
+ import_node_fs31 = require("node:fs");
23221
23285
  import_node_crypto5 = require("node:crypto");
23222
- import_node_path32 = require("node:path");
23223
- import_node_url7 = require("node:url");
23224
- init_paths();
23225
- __dirname4 = (0, import_node_path32.dirname)((0, import_node_url7.fileURLToPath)(__cli_url));
23286
+ import_node_path33 = require("node:path");
23287
+ init_app_dir();
23288
+ init_paths2();
23226
23289
  }
23227
23290
  });
23228
23291
 
@@ -23255,6 +23318,7 @@ var init_runtime = __esm({
23255
23318
  "src/services/runtime.ts"() {
23256
23319
  "use strict";
23257
23320
  init_aigateway();
23321
+ init_app_dir();
23258
23322
  init_clickhouse();
23259
23323
  init_env2();
23260
23324
  init_env_file();
@@ -23274,6 +23338,7 @@ var init_runtime = __esm({
23274
23338
  },
23275
23339
  async installServices(ctx) {
23276
23340
  const bus = busFor(ctx);
23341
+ await ensureAppDir(ctx, bus);
23277
23342
  await Promise.all([
23278
23343
  syncVenvs(ctx, bus),
23279
23344
  ensureLangwatchDeps(ctx, bus)
@@ -25861,24 +25926,7 @@ var Listr = class {
25861
25926
  // src/predeps/runner.ts
25862
25927
  var import_node_fs19 = require("node:fs");
25863
25928
  var import_prompts = __toESM(require_prompts3(), 1);
25864
-
25865
- // src/shared/paths.ts
25866
- var import_node_os7 = require("node:os");
25867
- var import_node_path6 = require("node:path");
25868
- var root = process.env.LANGWATCH_HOME?.length ? process.env.LANGWATCH_HOME : (0, import_node_path6.join)((0, import_node_os7.homedir)(), ".langwatch");
25869
- var paths = {
25870
- root,
25871
- bin: (0, import_node_path6.join)(root, "bin"),
25872
- data: (0, import_node_path6.join)(root, "data"),
25873
- redisData: (0, import_node_path6.join)(root, "data", "redis"),
25874
- postgresData: (0, import_node_path6.join)(root, "data", "postgres"),
25875
- clickhouseData: (0, import_node_path6.join)(root, "data", "clickhouse"),
25876
- logs: (0, import_node_path6.join)(root, "logs"),
25877
- pidFile: (0, import_node_path6.join)(root, "run", "langwatch.pid"),
25878
- lockFile: (0, import_node_path6.join)(root, "run", "langwatch.lock"),
25879
- envFile: (0, import_node_path6.join)(root, ".env"),
25880
- installManifest: (0, import_node_path6.join)(root, "install-manifest.json")
25881
- };
25929
+ init_paths();
25882
25930
 
25883
25931
  // src/predeps/aigateway.ts
25884
25932
  init_execa();
@@ -26482,6 +26530,7 @@ function collectResult(predeps, detection, installResults) {
26482
26530
  }
26483
26531
 
26484
26532
  // src/predeps/detect-only.ts
26533
+ init_paths();
26485
26534
  async function inspectPredeps({ version }) {
26486
26535
  const predeps = predepRegistry({ version });
26487
26536
  const rows = [];
@@ -26566,6 +26615,7 @@ function printConflicts(report) {
26566
26615
  }
26567
26616
 
26568
26617
  // src/cli.ts
26618
+ init_paths();
26569
26619
  init_ports();
26570
26620
  init_env();
26571
26621
 
@@ -26586,7 +26636,7 @@ var placeholderRuntime = {
26586
26636
  };
26587
26637
 
26588
26638
  // src/cli.ts
26589
- var VERSION = true ? "3.1.0-beta.3" : "0.0.0-dev";
26639
+ var VERSION = true ? "3.1.0-beta.5" : "0.0.0-dev";
26590
26640
  async function loadRuntime() {
26591
26641
  try {
26592
26642
  const real = await Promise.resolve().then(() => (init_runtime(), runtime_exports));