@langwatch/server 3.1.0-beta.16 → 3.1.0-beta.18

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.
@@ -257,7 +257,13 @@ export class ModelProviderRepository {
257
257
  * Decrypts customKeys after reading from the database.
258
258
  * Handles the migration transition where some rows may still have plaintext JSON objects.
259
259
  *
260
- * @returns Decrypted object, or null if input is null/undefined.
260
+ * @returns Decrypted object, or null if input is null/undefined or undecryptable.
261
+ *
262
+ * Undecryptable rows (typically: CREDENTIALS_SECRET rotated since the row
263
+ * was written) used to throw and crash the whole `getAllForProject` query —
264
+ * blocking the entire UI behind a 500 response. We now log a warning and
265
+ * return null so the provider is treated as keyless, the user can re-enter
266
+ * keys, and the rest of the providers list still loads.
261
267
  */
262
268
  private decryptCustomKeys(
263
269
  customKeys: unknown,
@@ -271,8 +277,16 @@ export class ModelProviderRepository {
271
277
 
272
278
  // Encrypted string: decrypt and parse
273
279
  if (typeof customKeys === "string") {
274
- const decrypted = decrypt(customKeys);
275
- return JSON.parse(decrypted) as Record<string, unknown>;
280
+ try {
281
+ const decrypted = decrypt(customKeys);
282
+ return JSON.parse(decrypted) as Record<string, unknown>;
283
+ } catch (err) {
284
+ console.warn(
285
+ "[ModelProviderRepository] dropping unreadable customKeys (likely CREDENTIALS_SECRET rotated since row was written):",
286
+ err instanceof Error ? err.message : String(err),
287
+ );
288
+ return null;
289
+ }
276
290
  }
277
291
 
278
292
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langwatch/server",
3
- "version": "3.1.0-beta.16",
3
+ "version": "3.1.0-beta.18",
4
4
  "description": "Run LangWatch locally with one command — `npx @langwatch/server`. Bundles the Next.js control plane, Python NLP service, evaluators, and the Go AI gateway with embedded postgres, redis, and clickhouse.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://langwatch.ai",
@@ -22206,13 +22206,49 @@ function buildEnv({ ports, baseHost, overrides = {} }) {
22206
22206
  return lines.join("\n") + "\n";
22207
22207
  }
22208
22208
  function scaffoldEnvFile(input) {
22209
+ const secretsPath = (0, import_node_path22.join)((0, import_node_path22.dirname)(input.path), "secrets.json");
22209
22210
  if ((0, import_node_fs20.existsSync)(input.path)) {
22211
+ if (!(0, import_node_fs20.existsSync)(secretsPath)) {
22212
+ writePersistedSecrets(secretsPath, (0, import_node_fs20.readFileSync)(input.path, "utf8"));
22213
+ }
22210
22214
  return { written: false, path: input.path };
22211
22215
  }
22212
22216
  (0, import_node_fs20.mkdirSync)((0, import_node_path22.dirname)(input.path), { recursive: true });
22213
- (0, import_node_fs20.writeFileSync)(input.path, buildEnv(input), { mode: 384 });
22217
+ const persistedSecrets = readPersistedSecrets(secretsPath);
22218
+ const overlay = { ...input.overrides, ...persistedSecrets };
22219
+ const body = buildEnv({ ...input, overrides: overlay });
22220
+ (0, import_node_fs20.writeFileSync)(input.path, body, { mode: 384 });
22221
+ writePersistedSecrets(secretsPath, body);
22214
22222
  return { written: true, path: input.path };
22215
22223
  }
22224
+ function readPersistedSecrets(path6) {
22225
+ if (!(0, import_node_fs20.existsSync)(path6)) return {};
22226
+ try {
22227
+ const raw = (0, import_node_fs20.readFileSync)(path6, "utf8");
22228
+ const parsed = JSON.parse(raw);
22229
+ const out = {};
22230
+ for (const key of PERSISTENT_SECRET_KEYS) {
22231
+ const v2 = parsed[key];
22232
+ if (typeof v2 === "string" && v2.length > 0) out[key] = v2;
22233
+ }
22234
+ return out;
22235
+ } catch {
22236
+ return {};
22237
+ }
22238
+ }
22239
+ function writePersistedSecrets(path6, envBody) {
22240
+ const found = {};
22241
+ for (const line of envBody.split("\n")) {
22242
+ const m2 = line.match(/^([^=]+)=(.*)$/);
22243
+ if (!m2) continue;
22244
+ const [, key, value] = m2;
22245
+ if (PERSISTENT_SECRET_KEYS.includes(key)) {
22246
+ found[key] = value;
22247
+ }
22248
+ }
22249
+ if (Object.keys(found).length === 0) return;
22250
+ (0, import_node_fs20.writeFileSync)(path6, JSON.stringify(found, null, 2), { mode: 384 });
22251
+ }
22216
22252
  function captureUserEnv(env3 = process.env) {
22217
22253
  const out = {};
22218
22254
  for (const key of PASSTHROUGH_ENV_KEYS) {
@@ -22221,13 +22257,21 @@ function captureUserEnv(env3 = process.env) {
22221
22257
  }
22222
22258
  return out;
22223
22259
  }
22224
- var import_node_crypto4, import_node_fs20, import_node_path22, hex, b64, PASSTHROUGH_ENV_KEYS;
22260
+ var import_node_crypto4, import_node_fs20, import_node_path22, PERSISTENT_SECRET_KEYS, hex, b64, PASSTHROUGH_ENV_KEYS;
22225
22261
  var init_env = __esm({
22226
22262
  "src/shared/env.ts"() {
22227
22263
  "use strict";
22228
22264
  import_node_crypto4 = require("node:crypto");
22229
22265
  import_node_fs20 = require("node:fs");
22230
22266
  import_node_path22 = require("node:path");
22267
+ PERSISTENT_SECRET_KEYS = [
22268
+ "NEXTAUTH_SECRET",
22269
+ "CREDENTIALS_SECRET",
22270
+ "API_TOKEN_JWT_SECRET",
22271
+ "LW_VIRTUAL_KEY_PEPPER",
22272
+ "LW_GATEWAY_INTERNAL_SECRET",
22273
+ "LW_GATEWAY_JWT_SECRET"
22274
+ ];
22231
22275
  hex = (bytes) => (0, import_node_crypto4.randomBytes)(bytes).toString("hex");
22232
22276
  b64 = (bytes) => (0, import_node_crypto4.randomBytes)(bytes).toString("base64");
22233
22277
  PASSTHROUGH_ENV_KEYS = [
@@ -23350,16 +23394,17 @@ async function syncVenvs(ctx, bus) {
23350
23394
  specs.map(async (spec) => {
23351
23395
  const venvDir = sp.venv(spec.name);
23352
23396
  const hashFile = (0, import_node_path33.join)(venvDir, ".lock-hash");
23353
- const expected = hashFileSafely(spec.lockFile);
23397
+ const expected = `${hashFileSafely(spec.lockFile)}|extras=${(spec.extras ?? []).slice().sort().join(",")}`;
23354
23398
  if ((0, import_node_fs31.existsSync)(venvDir) && readFileSafely(hashFile) === expected) return;
23355
23399
  bus.emit({ type: "starting", service: `prepare:${spec.name}` });
23356
23400
  const start = Date.now();
23357
23401
  (0, import_node_fs31.mkdirSync)(venvDir, { recursive: true });
23402
+ const extraArgs = (spec.extras ?? []).flatMap((e) => ["--extra", e]);
23358
23403
  await execAndPipe(
23359
23404
  bus,
23360
23405
  `prepare:${spec.name}`,
23361
23406
  uvBin,
23362
- ["sync", "--project", spec.projectDir],
23407
+ ["sync", "--project", spec.projectDir, ...extraArgs],
23363
23408
  {
23364
23409
  env: {
23365
23410
  ...process.env,
@@ -23383,7 +23428,22 @@ function resolveVenvSpecs() {
23383
23428
  {
23384
23429
  name: "langevals",
23385
23430
  projectDir: (0, import_node_path33.join)(root2, "langevals"),
23386
- lockFile: (0, import_node_path33.join)(root2, "langevals", "uv.lock")
23431
+ lockFile: (0, import_node_path33.join)(root2, "langevals", "uv.lock"),
23432
+ // langevals's evaluator routes (ROUGE Score, exact match, llm-as-judge,
23433
+ // etc.) live in subpackages declared as optional dependencies in
23434
+ // langevals/pyproject.toml: langevals-ragas, langevals-openai,
23435
+ // langevals-langevals, langevals-azure, langevals-lingua,
23436
+ // langevals-presidio, langevals-legacy. Each is a separate `langevals_*`
23437
+ // distribution; server.py auto-registers FastAPI routes for any
23438
+ // `langevals_*` package found via importlib.metadata.distributions().
23439
+ // Without --extra all, only langevals + langevals-core get installed
23440
+ // and `/openapi.json` reports just `/healthcheck` and `/` — every
23441
+ // evaluator request 404s, langwatch app's runEvaluation throws
23442
+ // `404 {"detail":"Not Found"}`, and the experiments workbench column
23443
+ // shows 'Internal error' for every row. We install all extras so the
23444
+ // evaluator dispatch from langwatch_nlp + the legacy-eval REST route
23445
+ // can reach a real evaluator implementation.
23446
+ extras: ["all"]
23387
23447
  }
23388
23448
  ];
23389
23449
  }
@@ -26909,7 +26969,7 @@ var placeholderRuntime = {
26909
26969
  };
26910
26970
 
26911
26971
  // src/cli.ts
26912
- var VERSION = true ? "3.1.0-beta.16" : "0.0.0-dev";
26972
+ var VERSION = true ? "3.1.0-beta.18" : "0.0.0-dev";
26913
26973
  async function loadRuntime() {
26914
26974
  try {
26915
26975
  const real = await Promise.resolve().then(() => (init_runtime(), runtime_exports));