@langwatch/server 3.1.0-beta.15 → 3.1.0-beta.17

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;
@@ -1,4 +1,5 @@
1
1
  import logging
2
+ import os
2
3
  import time
3
4
  from typing import Optional, cast
4
5
  import dspy
@@ -67,7 +68,10 @@ async def execute_evaluation(
67
68
  module = Module(run_evaluations=True)
68
69
  module.prevent_crashes()
69
70
 
70
- langwatch.setup(workflow.api_key)
71
+ langwatch.setup(
72
+ api_key=workflow.api_key,
73
+ endpoint_url=os.environ.get("LANGWATCH_ENDPOINT"),
74
+ )
71
75
 
72
76
  origin = event.origin or "evaluation"
73
77
 
@@ -1,3 +1,4 @@
1
+ import os
1
2
  from typing import AsyncGenerator
2
3
 
3
4
 
@@ -46,7 +47,10 @@ async def execute_event(
46
47
  case "is_alive":
47
48
  yield IsAliveResponse()
48
49
  case "execute_component":
49
- langwatch.setup(api_key=event.payload.workflow.api_key)
50
+ langwatch.setup(
51
+ api_key=event.payload.workflow.api_key,
52
+ endpoint_url=os.environ.get("LANGWATCH_ENDPOINT"),
53
+ )
50
54
  try:
51
55
  async for event_ in execute_component(event.payload):
52
56
  yield event_
@@ -60,7 +64,10 @@ async def execute_event(
60
64
  error=_error_repr(e),
61
65
  )
62
66
  case "execute_flow":
63
- langwatch.setup(api_key=event.payload.workflow.api_key)
67
+ langwatch.setup(
68
+ api_key=event.payload.workflow.api_key,
69
+ endpoint_url=os.environ.get("LANGWATCH_ENDPOINT"),
70
+ )
64
71
  try:
65
72
  async for event_ in execute_flow(event.payload, queue):
66
73
  yield event_
@@ -70,7 +77,10 @@ async def execute_event(
70
77
  traceback.print_exc()
71
78
  yield Error(payload=ErrorPayload(message=_error_repr(e)))
72
79
  case "execute_evaluation":
73
- client = langwatch.setup(api_key=event.payload.workflow.api_key)
80
+ client = langwatch.setup(
81
+ api_key=event.payload.workflow.api_key,
82
+ endpoint_url=os.environ.get("LANGWATCH_ENDPOINT"),
83
+ )
74
84
  client.disable_sending = True
75
85
  try:
76
86
  async for event_ in execute_evaluation(event.payload, queue):
@@ -78,7 +88,10 @@ async def execute_event(
78
88
  except Exception as e:
79
89
  yield Error(payload=ErrorPayload(message=_error_repr(e)))
80
90
  case "execute_optimization":
81
- client = langwatch.setup(api_key=event.payload.workflow.api_key)
91
+ client = langwatch.setup(
92
+ api_key=event.payload.workflow.api_key,
93
+ endpoint_url=os.environ.get("LANGWATCH_ENDPOINT"),
94
+ )
82
95
  client.disable_sending = True
83
96
  try:
84
97
  async for event_ in execute_optimization(event.payload, queue):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langwatch/server",
3
- "version": "3.1.0-beta.15",
3
+ "version": "3.1.0-beta.17",
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",
@@ -22210,9 +22210,42 @@ function scaffoldEnvFile(input) {
22210
22210
  return { written: false, path: input.path };
22211
22211
  }
22212
22212
  (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 });
22213
+ const secretsPath = (0, import_node_path22.join)((0, import_node_path22.dirname)(input.path), "secrets.json");
22214
+ const persistedSecrets = readPersistedSecrets(secretsPath);
22215
+ const overlay = { ...input.overrides, ...persistedSecrets };
22216
+ const body = buildEnv({ ...input, overrides: overlay });
22217
+ (0, import_node_fs20.writeFileSync)(input.path, body, { mode: 384 });
22218
+ writePersistedSecrets(secretsPath, body);
22214
22219
  return { written: true, path: input.path };
22215
22220
  }
22221
+ function readPersistedSecrets(path6) {
22222
+ if (!(0, import_node_fs20.existsSync)(path6)) return {};
22223
+ try {
22224
+ const raw = (0, import_node_fs20.readFileSync)(path6, "utf8");
22225
+ const parsed = JSON.parse(raw);
22226
+ const out = {};
22227
+ for (const key of PERSISTENT_SECRET_KEYS) {
22228
+ const v2 = parsed[key];
22229
+ if (typeof v2 === "string" && v2.length > 0) out[key] = v2;
22230
+ }
22231
+ return out;
22232
+ } catch {
22233
+ return {};
22234
+ }
22235
+ }
22236
+ function writePersistedSecrets(path6, envBody) {
22237
+ const found = {};
22238
+ for (const line of envBody.split("\n")) {
22239
+ const m2 = line.match(/^([^=]+)=(.*)$/);
22240
+ if (!m2) continue;
22241
+ const [, key, value] = m2;
22242
+ if (PERSISTENT_SECRET_KEYS.includes(key)) {
22243
+ found[key] = value;
22244
+ }
22245
+ }
22246
+ if (Object.keys(found).length === 0) return;
22247
+ (0, import_node_fs20.writeFileSync)(path6, JSON.stringify(found, null, 2), { mode: 384 });
22248
+ }
22216
22249
  function captureUserEnv(env3 = process.env) {
22217
22250
  const out = {};
22218
22251
  for (const key of PASSTHROUGH_ENV_KEYS) {
@@ -22221,13 +22254,21 @@ function captureUserEnv(env3 = process.env) {
22221
22254
  }
22222
22255
  return out;
22223
22256
  }
22224
- var import_node_crypto4, import_node_fs20, import_node_path22, hex, b64, PASSTHROUGH_ENV_KEYS;
22257
+ var import_node_crypto4, import_node_fs20, import_node_path22, PERSISTENT_SECRET_KEYS, hex, b64, PASSTHROUGH_ENV_KEYS;
22225
22258
  var init_env = __esm({
22226
22259
  "src/shared/env.ts"() {
22227
22260
  "use strict";
22228
22261
  import_node_crypto4 = require("node:crypto");
22229
22262
  import_node_fs20 = require("node:fs");
22230
22263
  import_node_path22 = require("node:path");
22264
+ PERSISTENT_SECRET_KEYS = [
22265
+ "NEXTAUTH_SECRET",
22266
+ "CREDENTIALS_SECRET",
22267
+ "API_TOKEN_JWT_SECRET",
22268
+ "LW_VIRTUAL_KEY_PEPPER",
22269
+ "LW_GATEWAY_INTERNAL_SECRET",
22270
+ "LW_GATEWAY_JWT_SECRET"
22271
+ ];
22231
22272
  hex = (bytes) => (0, import_node_crypto4.randomBytes)(bytes).toString("hex");
22232
22273
  b64 = (bytes) => (0, import_node_crypto4.randomBytes)(bytes).toString("base64");
22233
22274
  PASSTHROUGH_ENV_KEYS = [
@@ -23350,16 +23391,17 @@ async function syncVenvs(ctx, bus) {
23350
23391
  specs.map(async (spec) => {
23351
23392
  const venvDir = sp.venv(spec.name);
23352
23393
  const hashFile = (0, import_node_path33.join)(venvDir, ".lock-hash");
23353
- const expected = hashFileSafely(spec.lockFile);
23394
+ const expected = `${hashFileSafely(spec.lockFile)}|extras=${(spec.extras ?? []).slice().sort().join(",")}`;
23354
23395
  if ((0, import_node_fs31.existsSync)(venvDir) && readFileSafely(hashFile) === expected) return;
23355
23396
  bus.emit({ type: "starting", service: `prepare:${spec.name}` });
23356
23397
  const start = Date.now();
23357
23398
  (0, import_node_fs31.mkdirSync)(venvDir, { recursive: true });
23399
+ const extraArgs = (spec.extras ?? []).flatMap((e) => ["--extra", e]);
23358
23400
  await execAndPipe(
23359
23401
  bus,
23360
23402
  `prepare:${spec.name}`,
23361
23403
  uvBin,
23362
- ["sync", "--project", spec.projectDir],
23404
+ ["sync", "--project", spec.projectDir, ...extraArgs],
23363
23405
  {
23364
23406
  env: {
23365
23407
  ...process.env,
@@ -23383,7 +23425,22 @@ function resolveVenvSpecs() {
23383
23425
  {
23384
23426
  name: "langevals",
23385
23427
  projectDir: (0, import_node_path33.join)(root2, "langevals"),
23386
- lockFile: (0, import_node_path33.join)(root2, "langevals", "uv.lock")
23428
+ lockFile: (0, import_node_path33.join)(root2, "langevals", "uv.lock"),
23429
+ // langevals's evaluator routes (ROUGE Score, exact match, llm-as-judge,
23430
+ // etc.) live in subpackages declared as optional dependencies in
23431
+ // langevals/pyproject.toml: langevals-ragas, langevals-openai,
23432
+ // langevals-langevals, langevals-azure, langevals-lingua,
23433
+ // langevals-presidio, langevals-legacy. Each is a separate `langevals_*`
23434
+ // distribution; server.py auto-registers FastAPI routes for any
23435
+ // `langevals_*` package found via importlib.metadata.distributions().
23436
+ // Without --extra all, only langevals + langevals-core get installed
23437
+ // and `/openapi.json` reports just `/healthcheck` and `/` — every
23438
+ // evaluator request 404s, langwatch app's runEvaluation throws
23439
+ // `404 {"detail":"Not Found"}`, and the experiments workbench column
23440
+ // shows 'Internal error' for every row. We install all extras so the
23441
+ // evaluator dispatch from langwatch_nlp + the legacy-eval REST route
23442
+ // can reach a real evaluator implementation.
23443
+ extras: ["all"]
23387
23444
  }
23388
23445
  ];
23389
23446
  }
@@ -26909,7 +26966,7 @@ var placeholderRuntime = {
26909
26966
  };
26910
26967
 
26911
26968
  // src/cli.ts
26912
- var VERSION = true ? "3.1.0-beta.15" : "0.0.0-dev";
26969
+ var VERSION = true ? "3.1.0-beta.17" : "0.0.0-dev";
26913
26970
  async function loadRuntime() {
26914
26971
  try {
26915
26972
  const real = await Promise.resolve().then(() => (init_runtime(), runtime_exports));
@@ -212,10 +212,21 @@ class Client(LangWatchClientProtocol):
212
212
 
213
213
  if endpoint_url is not None:
214
214
  Client._endpoint_url = endpoint_url
215
- elif not Client._endpoint_url:
216
- Client._endpoint_url = (
217
- os.getenv("LANGWATCH_ENDPOINT") or "https://app.langwatch.ai"
218
- )
215
+ else:
216
+ # Always re-read LANGWATCH_ENDPOINT from env on every setup()
217
+ # call. The previous "pin once on first init" behavior caused
218
+ # Client._endpoint_url to stick at the default (https://app.langwatch.ai)
219
+ # whenever some code path called setup() before the host env had
220
+ # LANGWATCH_ENDPOINT set — most commonly dspy's ProcessPool
221
+ # worker init order, which made every self-host evaluator
222
+ # callback 401 against the cloud API. Re-reading per-call costs
223
+ # one os.getenv lookup; the explicit endpoint_url path above
224
+ # still wins.
225
+ env_endpoint = os.getenv("LANGWATCH_ENDPOINT")
226
+ if env_endpoint:
227
+ Client._endpoint_url = env_endpoint
228
+ elif not Client._endpoint_url:
229
+ Client._endpoint_url = "https://app.langwatch.ai"
219
230
 
220
231
  if debug is not None:
221
232
  Client._debug = debug