@langwatch/server 3.1.0-beta.22 → 3.1.0-beta.23
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.
- package/langwatch/dist/client/assets/_not-found-COI3ShsR.js +1 -0
- package/langwatch/dist/client/assets/{index-TNQ6uyis.js → index-BEjGS0kI.js} +3 -3
- package/langwatch/dist/client/index.html +1 -1
- package/langwatch/dist/scenario-child-process.js +20 -10
- package/langwatch/package.json +2 -2
- package/langwatch/pnpm-lock.yaml +329 -328
- package/langwatch/src/app/api/workflows/post_event/__tests__/post-event-routing.test.ts +8 -0
- package/langwatch/src/hooks/usePostHog.ts +11 -0
- package/langwatch/src/server/nlpgo/nlpgoFetch.ts +14 -1
- package/langwatch_nlp/langwatch_nlp/studio/execute/execute_component.py +25 -1
- package/langwatch_nlp/langwatch_nlp/studio/parser.py +121 -16
- package/langwatch_nlp/tests/studio/test_parse.py +198 -0
- package/mcp-server/pnpm-lock.yaml +15 -21
- package/package.json +1 -1
- package/packages/server/dist/cli.cjs +12 -1
- package/langwatch/dist/client/assets/_not-found-DDh108-i.js +0 -1
|
@@ -34,6 +34,14 @@ vi.mock("../../../../../server/featureFlag/featureFlag.service", () => ({
|
|
|
34
34
|
},
|
|
35
35
|
}));
|
|
36
36
|
|
|
37
|
+
// `isNlpGoEnabled` resolves the project's organization via Prisma. Unit
|
|
38
|
+
// shards have no DB, so the live import throws PrismaClientInitializationError
|
|
39
|
+
// before the FF mock above is ever consulted. Stub the gate directly to
|
|
40
|
+
// keep this a pure routing test.
|
|
41
|
+
vi.mock("../../../../../server/nlpgo/nlpgoFetch", () => ({
|
|
42
|
+
isNlpGoEnabled: vi.fn().mockResolvedValue(true),
|
|
43
|
+
}));
|
|
44
|
+
|
|
37
45
|
vi.mock("../../../../../optimization_studio/server/addEnvs", async () => {
|
|
38
46
|
const actual = await vi.importActual<
|
|
39
47
|
typeof import("../../../../../optimization_studio/server/addEnvs")
|
|
@@ -32,6 +32,17 @@ export function usePostHog() {
|
|
|
32
32
|
recordCrossOriginIframes: true,
|
|
33
33
|
},
|
|
34
34
|
loaded: (posthog) => {
|
|
35
|
+
// Explicitly expose `window.posthog` so the PostHog toolbar
|
|
36
|
+
// (launched from the PostHog dashboard's "Toolbar" button)
|
|
37
|
+
// can attach in any environment, not just development. The
|
|
38
|
+
// posthog-js library sets this internally on most builds, but
|
|
39
|
+
// bundlers and strict-mode wrappers can sometimes strip the
|
|
40
|
+
// implicit global; the assignment is best-effort and has no
|
|
41
|
+
// downside in environments where it's already set.
|
|
42
|
+
if (typeof window !== "undefined") {
|
|
43
|
+
(window as unknown as { posthog: typeof posthog }).posthog =
|
|
44
|
+
posthog;
|
|
45
|
+
}
|
|
35
46
|
if (publicEnv.data?.NODE_ENV === "development") posthog.debug();
|
|
36
47
|
},
|
|
37
48
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { featureFlagService } from "../featureFlag/featureFlag.service";
|
|
2
|
+
import { resolveOrganizationId } from "../organizations/resolveOrganizationId";
|
|
2
3
|
import { lambdaFetch } from "../../utils/lambdaFetch";
|
|
3
4
|
import { getProjectLambdaArn } from "../../optimization_studio/server/lambda";
|
|
4
5
|
|
|
@@ -103,13 +104,25 @@ export async function nlpgoFetch<T = unknown>(
|
|
|
103
104
|
* - the studio UI to hide the (now-defunct) Optimize button
|
|
104
105
|
* - the optimize REST endpoint to return 410
|
|
105
106
|
* - tRPC procedures that want to surface the engine choice to the UI
|
|
107
|
+
*
|
|
108
|
+
* If `organizationId` isn't supplied, we look it up from the project so
|
|
109
|
+
* PostHog rules that target the `organization_id` person property
|
|
110
|
+
* (org-level rollouts) match correctly. Caught when an org-level enable
|
|
111
|
+
* in PostHog wasn't reaching projects under that org because every call
|
|
112
|
+
* site passed only `projectId` — PostHog's `release_nlp_go_engine_enabled`
|
|
113
|
+
* rule can't match `organization_id` if we never send it.
|
|
114
|
+
*
|
|
115
|
+
* `resolveOrganizationId` has its own 10-minute TTL cache and silently
|
|
116
|
+
* returns undefined for orphan projects, so this stays fast and safe.
|
|
106
117
|
*/
|
|
107
118
|
export async function isNlpGoEnabled(
|
|
108
119
|
opts: Pick<NLPGOFetchOptions, "projectId" | "organizationId">,
|
|
109
120
|
): Promise<boolean> {
|
|
121
|
+
const organizationId =
|
|
122
|
+
opts.organizationId ?? (await resolveOrganizationId(opts.projectId));
|
|
110
123
|
return featureFlagService.isEnabled(NLP_GO_FLAG, opts.projectId, false, {
|
|
111
124
|
projectId: opts.projectId,
|
|
112
|
-
organizationId
|
|
125
|
+
organizationId,
|
|
113
126
|
});
|
|
114
127
|
}
|
|
115
128
|
|
|
@@ -70,7 +70,31 @@ async def execute_component(event: ExecuteComponentPayload):
|
|
|
70
70
|
forward_inputs = event.inputs
|
|
71
71
|
else:
|
|
72
72
|
forward_inputs = autoparse_fields(node.data.inputs or [], event.inputs) # type: ignore
|
|
73
|
-
|
|
73
|
+
# PR #3543 back-compat: the parser accepts plain classes
|
|
74
|
+
# with `forward(...)` only (no __call__ and no dspy.Module
|
|
75
|
+
# base). Such classes aren't directly callable —
|
|
76
|
+
# `dspy.asyncify(instance)(...)` would TypeError. Fall back
|
|
77
|
+
# to `instance.forward` when `instance` isn't callable;
|
|
78
|
+
# mirrors the priority-3 path in the Go runner
|
|
79
|
+
# (services/nlpgo/.../codeblock/runner.py). dspy.Module
|
|
80
|
+
# subclasses always have __call__ so they hit the fast
|
|
81
|
+
# path unchanged.
|
|
82
|
+
#
|
|
83
|
+
# `callable(invoke_target)` covers both legs of the failure
|
|
84
|
+
# surface: missing-attribute (`getattr` default = None,
|
|
85
|
+
# `callable(None)` is False) AND non-callable-attribute
|
|
86
|
+
# (e.g. a string class attribute named `forward`). Either
|
|
87
|
+
# case raises a typed error here so the operator sees a
|
|
88
|
+
# message naming the class instead of asyncify's
|
|
89
|
+
# less-informative 'object is not callable'.
|
|
90
|
+
invoke_target = instance if callable(instance) else getattr(instance, "forward", None)
|
|
91
|
+
if not callable(invoke_target):
|
|
92
|
+
raise TypeError(
|
|
93
|
+
f"Class '{class_name}' for component {node.data.name} "
|
|
94
|
+
f"has no callable entrypoint. Define __call__(self, ...) "
|
|
95
|
+
f"or forward(self, ...) on the class."
|
|
96
|
+
)
|
|
97
|
+
result = await dspy.asyncify(invoke_target)(
|
|
74
98
|
**forward_inputs
|
|
75
99
|
)
|
|
76
100
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import ast
|
|
1
2
|
from contextlib import contextmanager, redirect_stdout
|
|
2
3
|
import copy
|
|
3
4
|
import io
|
|
@@ -194,6 +195,112 @@ def _assert_signature_field_types_are_mapped(node: Node) -> None:
|
|
|
194
195
|
)
|
|
195
196
|
|
|
196
197
|
|
|
198
|
+
def _is_dspy_module_base(base: ast.expr) -> bool:
|
|
199
|
+
"""True if ``base`` is the AST node ``dspy.Module``.
|
|
200
|
+
|
|
201
|
+
Used by _resolve_code_class_name to detect the legacy preferred
|
|
202
|
+
shape via AST instead of regex — regex over raw source can match
|
|
203
|
+
`class Fake:` inside a comment or docstring and pick the wrong
|
|
204
|
+
name; AST sees only real class declarations.
|
|
205
|
+
"""
|
|
206
|
+
return (
|
|
207
|
+
isinstance(base, ast.Attribute)
|
|
208
|
+
and isinstance(base.value, ast.Name)
|
|
209
|
+
and base.value.id == "dspy"
|
|
210
|
+
and base.attr == "Module"
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def _top_level_class_defs(code: str) -> list[ast.ClassDef]:
|
|
215
|
+
"""Return top-level ``ast.ClassDef`` nodes in user-supplied code.
|
|
216
|
+
|
|
217
|
+
Returns an empty list on syntax errors so the caller can surface
|
|
218
|
+
a clean "no class definition found" error rather than letting
|
|
219
|
+
SyntaxError propagate from this discovery step (the user code
|
|
220
|
+
will be black-formatted later anyway, which is where actual
|
|
221
|
+
syntax errors get reported with a nicer message).
|
|
222
|
+
|
|
223
|
+
Top-level only: nested classes inside an entry class don't count
|
|
224
|
+
as candidates — the legacy regex behavior was effectively the
|
|
225
|
+
same (it picked whatever ``class X:`` line came first), and
|
|
226
|
+
customer fixtures consistently put the entry class at the top.
|
|
227
|
+
"""
|
|
228
|
+
try:
|
|
229
|
+
tree = ast.parse(code)
|
|
230
|
+
except SyntaxError:
|
|
231
|
+
return []
|
|
232
|
+
return [node for node in tree.body if isinstance(node, ast.ClassDef)]
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def _resolve_code_class_name(
|
|
236
|
+
code: str, node_name: str | None, kind: str = "component"
|
|
237
|
+
) -> str:
|
|
238
|
+
"""Pick the user-defined class to instantiate from ``code``.
|
|
239
|
+
|
|
240
|
+
Resolution order matches the **class-based** shapes the Go runtime
|
|
241
|
+
accepts (services/nlpgo/app/engine/blocks/codeblock/runner.py), so
|
|
242
|
+
the same customer code runs identically on FF=on and FF=off:
|
|
243
|
+
|
|
244
|
+
1. ``class X(dspy.Module):`` (or any class whose bases include
|
|
245
|
+
``dspy.Module``) — preferred (legacy default; the dspy.Module
|
|
246
|
+
wrapper provides cost-tracing + tracking).
|
|
247
|
+
2. ``class X:`` matching the node's display name (after
|
|
248
|
+
normalization to a class identifier) — picks the right class
|
|
249
|
+
when the user defines helpers alongside the entry class.
|
|
250
|
+
3. First top-level ``class X:`` declaration in the file.
|
|
251
|
+
|
|
252
|
+
The Go runtime ALSO accepts a fourth shape — a top-level ``def
|
|
253
|
+
execute(**inputs)`` callable with no enclosing class — but that
|
|
254
|
+
shape is intentionally NOT supported on the Python side. This
|
|
255
|
+
parser is a class-name extractor (the resolved name is later passed
|
|
256
|
+
to ``getattr(module, class_name)``); a top-level function has no
|
|
257
|
+
class to extract. Source with a top-level ``execute`` and no class
|
|
258
|
+
raises a clear ValueError listing the supported shapes. If parity
|
|
259
|
+
is ever needed, swap the resolver for an importer-then-inspect flow
|
|
260
|
+
similar to the Go runner.
|
|
261
|
+
|
|
262
|
+
Method-level shape within the chosen class (``__call__`` vs
|
|
263
|
+
``forward`` vs neither) is NOT inspected here because the source
|
|
264
|
+
is not yet imported. The downstream invoker
|
|
265
|
+
(``execute_component.py`` / ``execute_flow.py``) handles the
|
|
266
|
+
dispatch — ``execute_component`` falls back from ``instance(...)``
|
|
267
|
+
to ``instance.forward(...)`` for plain forward-only classes; see
|
|
268
|
+
the import-time fallback in those modules.
|
|
269
|
+
|
|
270
|
+
AST-based discovery (not regex over raw source) so commented-out
|
|
271
|
+
or docstring text like ``class Fake:`` can't false-match. Anchors
|
|
272
|
+
PR #3483's per-shape contract back-compat for FF=off so customers
|
|
273
|
+
using the new ``class X: def __call__(...)`` template don't error
|
|
274
|
+
before the FF rolls to them.
|
|
275
|
+
"""
|
|
276
|
+
class_defs = _top_level_class_defs(code)
|
|
277
|
+
|
|
278
|
+
# Priority 1: any class with `dspy.Module` in its bases (handles
|
|
279
|
+
# both the strict `class X(dspy.Module):` and the multi-base
|
|
280
|
+
# `class X(dspy.Module, SomeMixin):` cases).
|
|
281
|
+
for cls in class_defs:
|
|
282
|
+
if any(_is_dspy_module_base(base) for base in cls.bases):
|
|
283
|
+
return cls.name
|
|
284
|
+
|
|
285
|
+
if not class_defs:
|
|
286
|
+
raise ValueError(
|
|
287
|
+
f"Could not find a class definition for {kind} {node_name}. "
|
|
288
|
+
f"Supported shapes: dspy.Module subclass, class with __call__, "
|
|
289
|
+
f"or class with forward()."
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
# Priority 2: name-disambiguation against the (normalized) node
|
|
293
|
+
# name when multiple candidate classes exist.
|
|
294
|
+
if node_name:
|
|
295
|
+
target = normalize_name_to_class_name(node_name)
|
|
296
|
+
for cls in class_defs:
|
|
297
|
+
if cls.name == target:
|
|
298
|
+
return cls.name
|
|
299
|
+
|
|
300
|
+
# Priority 3: first top-level class declaration.
|
|
301
|
+
return class_defs[0].name
|
|
302
|
+
|
|
303
|
+
|
|
197
304
|
def parse_component(
|
|
198
305
|
node: Node, workflow: Workflow, standalone=False, format=False, debug_level=0
|
|
199
306
|
) -> Tuple[str, str, Dict[str, Any]]:
|
|
@@ -280,14 +387,7 @@ def parse_component(
|
|
|
280
387
|
f"Code node has no source content for component {node.data.name}"
|
|
281
388
|
)
|
|
282
389
|
|
|
283
|
-
|
|
284
|
-
match = re.search(pattern, code)
|
|
285
|
-
if not match:
|
|
286
|
-
raise ValueError(
|
|
287
|
-
f"Could not find a class that inherits from dspy.Module for component {node.data.name}"
|
|
288
|
-
)
|
|
289
|
-
|
|
290
|
-
class_name = match.group(1)
|
|
390
|
+
class_name = _resolve_code_class_name(code, node.data.name)
|
|
291
391
|
try:
|
|
292
392
|
code = black.format_str(code, mode=black.Mode())
|
|
293
393
|
except Exception as e:
|
|
@@ -366,13 +466,9 @@ def parse_component(
|
|
|
366
466
|
raise ValueError(
|
|
367
467
|
f"Code not specified for agent {node.data.name}"
|
|
368
468
|
)
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
raise ValueError(
|
|
373
|
-
f"Could not find a class that inherits from dspy.Module for agent {node.data.name}"
|
|
374
|
-
)
|
|
375
|
-
class_name = match_result.group(1)
|
|
469
|
+
class_name = _resolve_code_class_name(
|
|
470
|
+
code, node.data.name, kind="agent"
|
|
471
|
+
)
|
|
376
472
|
try:
|
|
377
473
|
code = black.format_str(code, mode=black.Mode())
|
|
378
474
|
except Exception as e:
|
|
@@ -403,7 +499,16 @@ def parse_component(
|
|
|
403
499
|
@contextmanager
|
|
404
500
|
def materialized_component_class(
|
|
405
501
|
component_code: str, class_name: str
|
|
406
|
-
) -> Generator[Type[
|
|
502
|
+
) -> Generator[Type[Any], None, None]:
|
|
503
|
+
"""Materialize a user-defined class from ``component_code`` and yield it.
|
|
504
|
+
|
|
505
|
+
Return type is ``Type[Any]`` (was ``Type[dspy.Module]``) because the
|
|
506
|
+
Code node now also accepts plain ``class X: def __call__(...)`` and
|
|
507
|
+
``class X: def forward(...)`` shapes — the caller uses Python's
|
|
508
|
+
normal ``instance(**inputs)`` invocation, which dispatches to
|
|
509
|
+
``__call__`` if defined and otherwise hits whatever Module subclass
|
|
510
|
+
the legacy dspy path expects.
|
|
511
|
+
"""
|
|
407
512
|
temp_folder = tempfile.mkdtemp()
|
|
408
513
|
sys.path.insert(0, temp_folder)
|
|
409
514
|
|
|
@@ -306,3 +306,201 @@ class TestParseComponentEntryAndEndNodes:
|
|
|
306
306
|
|
|
307
307
|
with pytest.raises(ValueError, match="End nodes cannot be executed as standalone components"):
|
|
308
308
|
parse_component(node, basic_workflow)
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
class TestCodeNodeClassResolutionShapes:
|
|
312
|
+
"""Pin back-compat for the FF=off (legacy Python) Code node runtime.
|
|
313
|
+
|
|
314
|
+
PR #3483 shipped a new Studio default template (`class Code: def
|
|
315
|
+
__call__(self, ...): ...` — no `dspy.Module` inheritance). The Go
|
|
316
|
+
runtime's runner.py was updated to resolve __call__ / forward /
|
|
317
|
+
dspy.Module / top-level execute, but the Python parser only matched
|
|
318
|
+
`class X(dspy.Module):`. Result: customers still on the legacy
|
|
319
|
+
Python NLP path (FF=off) would hit
|
|
320
|
+
Could not find a class that inherits from dspy.Module for component Code
|
|
321
|
+
when running the new template.
|
|
322
|
+
|
|
323
|
+
These tests pin the resolution order in
|
|
324
|
+
`_resolve_code_class_name` so the Python side accepts the same
|
|
325
|
+
shapes the Go side does:
|
|
326
|
+
1. `class X(dspy.Module):` (legacy default — preferred)
|
|
327
|
+
2. `class X:` matching the node's normalized name
|
|
328
|
+
3. First `class X:` declaration (single-class file)
|
|
329
|
+
4. No class → clear error message listing supported shapes.
|
|
330
|
+
"""
|
|
331
|
+
|
|
332
|
+
def _make_code_node(self, code: str, name: str = "Code") -> CodeNode:
|
|
333
|
+
return CodeNode(
|
|
334
|
+
id="code_node",
|
|
335
|
+
data=Code(
|
|
336
|
+
name=name,
|
|
337
|
+
cls=name,
|
|
338
|
+
parameters=[
|
|
339
|
+
Field(
|
|
340
|
+
identifier="code",
|
|
341
|
+
type=FieldType.str,
|
|
342
|
+
optional=None,
|
|
343
|
+
value=code,
|
|
344
|
+
desc=None,
|
|
345
|
+
),
|
|
346
|
+
],
|
|
347
|
+
),
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
def test_class_with_dunder_call_only_no_dspy_inheritance(self):
|
|
351
|
+
"""The new default template — class with __call__, no dspy.Module."""
|
|
352
|
+
node = self._make_code_node(
|
|
353
|
+
"""
|
|
354
|
+
class Code:
|
|
355
|
+
def __call__(self, input: str):
|
|
356
|
+
return {"output": "Hello world!"}
|
|
357
|
+
"""
|
|
358
|
+
)
|
|
359
|
+
code, class_name, _ = parse_component(node, basic_workflow)
|
|
360
|
+
assert class_name == "Code"
|
|
361
|
+
with materialized_component_class(code, class_name) as Module:
|
|
362
|
+
instance = Module()
|
|
363
|
+
assert instance(input="anything") == {"output": "Hello world!"}
|
|
364
|
+
|
|
365
|
+
def test_class_with_forward_only_no_dspy_inheritance(self):
|
|
366
|
+
"""`forward()` shape without dspy.Module — must also work."""
|
|
367
|
+
node = self._make_code_node(
|
|
368
|
+
"""
|
|
369
|
+
class Code:
|
|
370
|
+
def forward(self, **kwargs):
|
|
371
|
+
return {"output": kwargs.get("input", "")}
|
|
372
|
+
"""
|
|
373
|
+
)
|
|
374
|
+
code, class_name, _ = parse_component(node, basic_workflow)
|
|
375
|
+
assert class_name == "Code"
|
|
376
|
+
with materialized_component_class(code, class_name) as Module:
|
|
377
|
+
instance = Module()
|
|
378
|
+
assert instance.forward(input="x") == {"output": "x"}
|
|
379
|
+
|
|
380
|
+
def test_legacy_dspy_module_subclass_still_resolves_first(self):
|
|
381
|
+
"""Existing customer code keeps working — back-compat anchor."""
|
|
382
|
+
node = self._make_code_node(
|
|
383
|
+
"""
|
|
384
|
+
import dspy
|
|
385
|
+
|
|
386
|
+
class Code(dspy.Module):
|
|
387
|
+
def forward(self, **kwargs):
|
|
388
|
+
return {"output": "legacy"}
|
|
389
|
+
""",
|
|
390
|
+
name="Code",
|
|
391
|
+
)
|
|
392
|
+
code, class_name, _ = parse_component(node, basic_workflow)
|
|
393
|
+
assert class_name == "Code"
|
|
394
|
+
with materialized_component_class(code, class_name) as Module:
|
|
395
|
+
assert issubclass(Module, dspy.Module)
|
|
396
|
+
|
|
397
|
+
def test_dspy_module_wins_over_helper_classes_above_it(self):
|
|
398
|
+
"""When the user defines helpers, the dspy.Module class is picked."""
|
|
399
|
+
node = self._make_code_node(
|
|
400
|
+
"""
|
|
401
|
+
import dspy
|
|
402
|
+
|
|
403
|
+
class Helper:
|
|
404
|
+
def __call__(self, x):
|
|
405
|
+
return x
|
|
406
|
+
|
|
407
|
+
class Code(dspy.Module):
|
|
408
|
+
def forward(self, **kwargs):
|
|
409
|
+
return {"output": "main"}
|
|
410
|
+
"""
|
|
411
|
+
)
|
|
412
|
+
_, class_name, _ = parse_component(node, basic_workflow)
|
|
413
|
+
# Despite Helper appearing first, the dspy.Module subclass wins.
|
|
414
|
+
assert class_name == "Code"
|
|
415
|
+
|
|
416
|
+
def test_node_name_disambiguates_when_no_dspy_inheritance(self):
|
|
417
|
+
"""Multiple bare classes — pick the one matching the node name."""
|
|
418
|
+
node = self._make_code_node(
|
|
419
|
+
"""
|
|
420
|
+
class Helper:
|
|
421
|
+
pass
|
|
422
|
+
|
|
423
|
+
class Code:
|
|
424
|
+
def __call__(self, input: str):
|
|
425
|
+
return {"output": "main"}
|
|
426
|
+
""",
|
|
427
|
+
name="Code",
|
|
428
|
+
)
|
|
429
|
+
_, class_name, _ = parse_component(node, basic_workflow)
|
|
430
|
+
assert class_name == "Code"
|
|
431
|
+
|
|
432
|
+
def test_no_class_in_code_raises_clear_error(self):
|
|
433
|
+
"""Helpful error replaces the misleading 'must inherit dspy.Module'.
|
|
434
|
+
|
|
435
|
+
Note: the Go runner accepts a top-level ``def execute(...)`` shape;
|
|
436
|
+
the Python parser intentionally does not (it's a class-name
|
|
437
|
+
extractor, not an instance resolver — see _resolve_code_class_name
|
|
438
|
+
docstring). The resulting message must point users at the
|
|
439
|
+
supported shapes so they convert their function into a class.
|
|
440
|
+
"""
|
|
441
|
+
node = self._make_code_node(
|
|
442
|
+
"""
|
|
443
|
+
def execute(input: str):
|
|
444
|
+
return {"output": "no class"}
|
|
445
|
+
"""
|
|
446
|
+
)
|
|
447
|
+
with pytest.raises(
|
|
448
|
+
ValueError,
|
|
449
|
+
match=r"Could not find a class definition.*Supported shapes",
|
|
450
|
+
):
|
|
451
|
+
parse_component(node, basic_workflow)
|
|
452
|
+
|
|
453
|
+
def test_class_with_multi_line_base_list_resolves(self):
|
|
454
|
+
"""Edge case Sarah flagged in #3543 review.
|
|
455
|
+
|
|
456
|
+
The class-declaration regex uses ``[^)]*`` for the base list,
|
|
457
|
+
which (unlike ``.``) matches newlines without re.DOTALL. So a
|
|
458
|
+
multi-line base list — common when the user pulls in mixins —
|
|
459
|
+
still resolves the class name correctly without falling through
|
|
460
|
+
to the no-class branch.
|
|
461
|
+
"""
|
|
462
|
+
node = self._make_code_node(
|
|
463
|
+
"""
|
|
464
|
+
import dspy
|
|
465
|
+
|
|
466
|
+
class Mixin:
|
|
467
|
+
pass
|
|
468
|
+
|
|
469
|
+
class Code(
|
|
470
|
+
dspy.Module,
|
|
471
|
+
Mixin,
|
|
472
|
+
):
|
|
473
|
+
def forward(self, **kwargs):
|
|
474
|
+
return {"output": "multi-base"}
|
|
475
|
+
"""
|
|
476
|
+
)
|
|
477
|
+
_, class_name, _ = parse_component(node, basic_workflow)
|
|
478
|
+
# AST-based discovery resolves dspy.Module-as-base correctly
|
|
479
|
+
# even with additional bases (the priority-1 path matches any
|
|
480
|
+
# class with dspy.Module among its bases, not only sole-base).
|
|
481
|
+
assert class_name == "Code"
|
|
482
|
+
|
|
483
|
+
def test_class_in_comment_or_docstring_is_not_picked(self):
|
|
484
|
+
"""CodeRabbit-flagged regression on #3543.
|
|
485
|
+
|
|
486
|
+
Regex-based discovery would happily pick `class Fake:` if it
|
|
487
|
+
appeared inside a string or comment, then fail at
|
|
488
|
+
`getattr(module, 'Fake')` with a confusing AttributeError. The
|
|
489
|
+
AST-based discovery only sees real top-level class declarations,
|
|
490
|
+
so the disguised class names are ignored.
|
|
491
|
+
"""
|
|
492
|
+
node = self._make_code_node(
|
|
493
|
+
'''
|
|
494
|
+
"""Module docstring with class Fake: nope, not a real class."""
|
|
495
|
+
|
|
496
|
+
# class Hidden: this is just a comment
|
|
497
|
+
SAMPLE = "class Decoy:\\n pass"
|
|
498
|
+
|
|
499
|
+
class Code:
|
|
500
|
+
def __call__(self, input: str):
|
|
501
|
+
return {"output": "real"}
|
|
502
|
+
''',
|
|
503
|
+
name="Code",
|
|
504
|
+
)
|
|
505
|
+
_, class_name, _ = parse_component(node, basic_workflow)
|
|
506
|
+
assert class_name == "Code"
|
|
@@ -31,7 +31,7 @@ importers:
|
|
|
31
31
|
version: 1.1.0
|
|
32
32
|
vitest:
|
|
33
33
|
specifier: ^3.2.4
|
|
34
|
-
version: 3.2.4(@types/debug@4.1.
|
|
34
|
+
version: 3.2.4(@types/debug@4.1.13)(@types/node@16.18.126)(tsx@4.20.5)(yaml@2.8.3)
|
|
35
35
|
yargs:
|
|
36
36
|
specifier: ^17.7.2
|
|
37
37
|
version: 17.7.2
|
|
@@ -53,10 +53,10 @@ importers:
|
|
|
53
53
|
version: 9.39.2
|
|
54
54
|
'@langwatch/scenario':
|
|
55
55
|
specifier: ^0.4.6
|
|
56
|
-
version: 0.4.10(
|
|
56
|
+
version: 0.4.10(325f2ac55009fad6e2acd26ed8f33b8a)
|
|
57
57
|
'@types/debug':
|
|
58
58
|
specifier: ^4.1.12
|
|
59
|
-
version: 4.1.
|
|
59
|
+
version: 4.1.13
|
|
60
60
|
'@types/eslint__js':
|
|
61
61
|
specifier: ^8.42.3
|
|
62
62
|
version: 8.42.3
|
|
@@ -77,7 +77,7 @@ importers:
|
|
|
77
77
|
version: 6.0.116(zod@4.3.6)
|
|
78
78
|
dotenv:
|
|
79
79
|
specifier: ^17.2.2
|
|
80
|
-
version: 17.
|
|
80
|
+
version: 17.4.2
|
|
81
81
|
esbuild:
|
|
82
82
|
specifier: ^0.25.0
|
|
83
83
|
version: 0.25.0
|
|
@@ -1340,8 +1340,8 @@ packages:
|
|
|
1340
1340
|
'@types/connect@3.4.38':
|
|
1341
1341
|
resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==}
|
|
1342
1342
|
|
|
1343
|
-
'@types/debug@4.1.
|
|
1344
|
-
resolution: {integrity: sha512-
|
|
1343
|
+
'@types/debug@4.1.13':
|
|
1344
|
+
resolution: {integrity: sha512-KSVgmQmzMwPlmtljOomayoR89W4FynCAi3E8PPs7vmDVPe84hT+vGPKkJfThkmXs0x0jAaa9U8uW8bbfyS2fWw==}
|
|
1345
1345
|
|
|
1346
1346
|
'@types/deep-eql@4.0.2':
|
|
1347
1347
|
resolution: {integrity: sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==}
|
|
@@ -1814,12 +1814,8 @@ packages:
|
|
|
1814
1814
|
resolution: {integrity: sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==}
|
|
1815
1815
|
engines: {node: '>= 0.8'}
|
|
1816
1816
|
|
|
1817
|
-
dotenv@17.
|
|
1818
|
-
resolution: {integrity: sha512-
|
|
1819
|
-
engines: {node: '>=12'}
|
|
1820
|
-
|
|
1821
|
-
dotenv@17.4.1:
|
|
1822
|
-
resolution: {integrity: sha512-k8DaKGP6r1G30Lx8V4+pCsLzKr8vLmV2paqEj1Y55GdAgJuIqpRp5FfajGF8KtwMxCz9qJc6wUIJnm053d/WCw==}
|
|
1817
|
+
dotenv@17.4.2:
|
|
1818
|
+
resolution: {integrity: sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw==}
|
|
1823
1819
|
engines: {node: '>=12'}
|
|
1824
1820
|
|
|
1825
1821
|
dunder-proto@1.0.1:
|
|
@@ -3482,7 +3478,7 @@ snapshots:
|
|
|
3482
3478
|
'@langchain/core': 0.3.80(@opentelemetry/api@1.9.1)(@opentelemetry/exporter-trace-otlp-proto@0.215.0(@opentelemetry/api@1.9.1))(@opentelemetry/sdk-trace-base@2.7.0(@opentelemetry/api@1.9.1))(openai@6.34.0(ws@8.20.0)(zod@4.3.6))
|
|
3483
3479
|
js-tiktoken: 1.0.21
|
|
3484
3480
|
|
|
3485
|
-
'@langwatch/scenario@0.4.10(
|
|
3481
|
+
'@langwatch/scenario@0.4.10(325f2ac55009fad6e2acd26ed8f33b8a)':
|
|
3486
3482
|
dependencies:
|
|
3487
3483
|
'@ag-ui/core': 0.0.28
|
|
3488
3484
|
'@ai-sdk/openai': 3.0.52(zod@3.25.76)
|
|
@@ -3493,7 +3489,7 @@ snapshots:
|
|
|
3493
3489
|
langwatch: 0.16.1(7c67c605ee5bfbd7a8d8f9918c809a56)
|
|
3494
3490
|
open: 11.0.0
|
|
3495
3491
|
rxjs: 7.8.2
|
|
3496
|
-
vitest: 3.2.4(@types/debug@4.1.
|
|
3492
|
+
vitest: 3.2.4(@types/debug@4.1.13)(@types/node@16.18.126)(tsx@4.20.5)(yaml@2.8.3)
|
|
3497
3493
|
xksuid: 0.0.4
|
|
3498
3494
|
zod: 3.25.76
|
|
3499
3495
|
transitivePeerDependencies:
|
|
@@ -4333,7 +4329,7 @@ snapshots:
|
|
|
4333
4329
|
dependencies:
|
|
4334
4330
|
'@types/node': 16.18.126
|
|
4335
4331
|
|
|
4336
|
-
'@types/debug@4.1.
|
|
4332
|
+
'@types/debug@4.1.13':
|
|
4337
4333
|
dependencies:
|
|
4338
4334
|
'@types/ms': 2.1.0
|
|
4339
4335
|
|
|
@@ -4801,9 +4797,7 @@ snapshots:
|
|
|
4801
4797
|
|
|
4802
4798
|
depd@2.0.0: {}
|
|
4803
4799
|
|
|
4804
|
-
dotenv@17.
|
|
4805
|
-
|
|
4806
|
-
dotenv@17.4.1: {}
|
|
4800
|
+
dotenv@17.4.2: {}
|
|
4807
4801
|
|
|
4808
4802
|
dunder-proto@1.0.1:
|
|
4809
4803
|
dependencies:
|
|
@@ -5287,7 +5281,7 @@ snapshots:
|
|
|
5287
5281
|
'@types/prompts': 2.4.9
|
|
5288
5282
|
chalk: 4.1.2
|
|
5289
5283
|
commander: 12.1.0
|
|
5290
|
-
dotenv: 17.4.
|
|
5284
|
+
dotenv: 17.4.2
|
|
5291
5285
|
js-yaml: 4.1.1
|
|
5292
5286
|
langchain: 0.3.37(@langchain/core@0.3.80(@opentelemetry/api@1.9.1)(@opentelemetry/exporter-trace-otlp-proto@0.215.0(@opentelemetry/api@1.9.1))(@opentelemetry/sdk-trace-base@2.7.0(@opentelemetry/api@1.9.1))(openai@6.34.0(ws@8.20.0)(zod@4.3.6)))(@opentelemetry/api@1.9.1)(@opentelemetry/exporter-trace-otlp-proto@0.215.0(@opentelemetry/api@1.9.1))(@opentelemetry/sdk-trace-base@2.7.0(@opentelemetry/api@1.9.1))(openai@6.34.0(ws@8.20.0)(zod@4.3.6))(ws@8.20.0)
|
|
5293
5287
|
liquidjs: 10.25.5
|
|
@@ -5968,7 +5962,7 @@ snapshots:
|
|
|
5968
5962
|
tsx: 4.20.5
|
|
5969
5963
|
yaml: 2.8.3
|
|
5970
5964
|
|
|
5971
|
-
vitest@3.2.4(@types/debug@4.1.
|
|
5965
|
+
vitest@3.2.4(@types/debug@4.1.13)(@types/node@16.18.126)(tsx@4.20.5)(yaml@2.8.3):
|
|
5972
5966
|
dependencies:
|
|
5973
5967
|
'@types/chai': 5.2.2
|
|
5974
5968
|
'@vitest/expect': 3.2.4
|
|
@@ -5994,7 +5988,7 @@ snapshots:
|
|
|
5994
5988
|
vite-node: 3.2.4(@types/node@16.18.126)(tsx@4.20.5)(yaml@2.8.3)
|
|
5995
5989
|
why-is-node-running: 2.3.0
|
|
5996
5990
|
optionalDependencies:
|
|
5997
|
-
'@types/debug': 4.1.
|
|
5991
|
+
'@types/debug': 4.1.13
|
|
5998
5992
|
'@types/node': 16.18.126
|
|
5999
5993
|
transitivePeerDependencies:
|
|
6000
5994
|
- jiti
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langwatch/server",
|
|
3
|
-
"version": "3.1.0-beta.
|
|
3
|
+
"version": "3.1.0-beta.23",
|
|
4
4
|
"description": "Run LangWatch locally with one command — `npx @langwatch/server`. Complete LangWatch stack: observability, evaluations, AI gateway, agent simulations.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://langwatch.ai",
|
|
@@ -23110,6 +23110,17 @@ async function startNlpgo(ctx, bus, envFromFile) {
|
|
|
23110
23110
|
// agent-workflow callbacks. /api/* routes terminate inside the
|
|
23111
23111
|
// langwatch process.
|
|
23112
23112
|
NLPGO_ENGINE_LANGWATCH_BASE_URL: `http://127.0.0.1:${ctx.ports.langwatch}`,
|
|
23113
|
+
// OTel exporter target — nlpgo's configureNLPGoOTel reads this
|
|
23114
|
+
// (preferred) or OTEL_OTLP_ENDPOINT (fallback) and appends
|
|
23115
|
+
// /api/otel/v1/traces. With MultiTenant=true (hardcoded in
|
|
23116
|
+
// nlpgo's deps.go), the per-tenant tenant_router pulls
|
|
23117
|
+
// workflow.api_key from the request context and authenticates
|
|
23118
|
+
// each batch as the right project — no static auth header
|
|
23119
|
+
// needed from this side. envFromFile already carries this var
|
|
23120
|
+
// (see shared/env.ts), but we set it explicitly here so an
|
|
23121
|
+
// older ~/.langwatch/.env that pre-dates the variable still
|
|
23122
|
+
// gets the right value at boot.
|
|
23123
|
+
LANGWATCH_ENDPOINT: `http://127.0.0.1:${ctx.ports.langwatch}`,
|
|
23113
23124
|
LOG_FORMAT: "pretty"
|
|
23114
23125
|
}
|
|
23115
23126
|
},
|
|
@@ -27000,7 +27011,7 @@ var placeholderRuntime = {
|
|
|
27000
27011
|
};
|
|
27001
27012
|
|
|
27002
27013
|
// src/cli.ts
|
|
27003
|
-
var VERSION = true ? "3.1.0-beta.
|
|
27014
|
+
var VERSION = true ? "3.1.0-beta.23" : "0.0.0-dev";
|
|
27004
27015
|
async function loadRuntime() {
|
|
27005
27016
|
try {
|
|
27006
27017
|
const real = await Promise.resolve().then(() => (init_runtime(), runtime_exports));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./index-TNQ6uyis.js";export{e as default};
|