@langwatch/server 3.1.0-beta.19 → 3.1.0-beta.20
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/prisma/migrations/20260425000000_consolidate_gateway_audit_into_audit_log/migration.sql +44 -0
- package/langwatch/prisma/migrations/20260426150000_drop_redundant_audit_log_org_index/migration.sql +25 -0
- package/langwatch/prisma/schema.prisma +34 -41
- package/langwatch/scripts/seed-gateway-dogfood.ts +26 -26
- package/langwatch/src/app/api/gateway-platform/[[...route]]/app.ts +8 -4
- package/langwatch/src/app/api/middleware/trace-limit.ts +10 -0
- package/langwatch/src/components/MainMenu.tsx +4 -15
- package/langwatch/src/components/SettingsLayout.tsx +1 -1
- package/langwatch/src/components/llmPromptConfigs/__tests__/LLMConfigPopover.test.tsx +45 -0
- package/langwatch/src/components/llmPromptConfigs/parameterRegistry.ts +22 -13
- package/langwatch/src/components/prompts/PromptEditorDrawer.tsx +5 -3
- package/langwatch/src/components/settings/AddCustomModelDialog.tsx +7 -6
- package/langwatch/src/evaluations-v3/__tests__/TableDisplay.integration.test.tsx +90 -5
- package/langwatch/src/evaluations-v3/__tests__/TableSettingsMenu.integration.test.tsx +26 -26
- package/langwatch/src/evaluations-v3/components/DatasetSection/TableCell.tsx +2 -10
- package/langwatch/src/evaluations-v3/components/EvaluationsV3Table.tsx +10 -4
- package/langwatch/src/evaluations-v3/components/TableSettingsMenu.tsx +6 -6
- package/langwatch/src/evaluations-v3/components/TargetSection/EvaluatorChip.tsx +19 -11
- package/langwatch/src/evaluations-v3/components/TargetSection/TargetCell.tsx +55 -42
- package/langwatch/src/evaluations-v3/components/TargetSection/TargetHeader.tsx +2 -1
- package/langwatch/src/evaluations-v3/components/TargetSection/__tests__/EvaluatorChip.test.tsx +57 -0
- package/langwatch/src/evaluations-v3/components/TargetSection/__tests__/TargetCell.test.tsx +199 -11
- package/langwatch/src/evaluations-v3/components/VirtualizedTableBody.tsx +1 -1
- package/langwatch/src/evaluations-v3/constants.ts +9 -0
- package/langwatch/src/evaluations-v3/types/__tests__/persistence.test.ts +1 -1
- package/langwatch/src/evaluations-v3/types.ts +13 -1
- package/langwatch/src/evaluations-v3/utils/__tests__/evaluatorEditorCallbacks.test.ts +32 -0
- package/langwatch/src/evaluations-v3/utils/evaluatorEditorCallbacks.ts +36 -5
- package/langwatch/src/optimization_studio/components/datasets/DatasetSelection.tsx +1 -6
- package/langwatch/src/optimization_studio/components/datasets/__tests__/DatasetSelection.integration.test.tsx +194 -0
- package/langwatch/src/optimization_studio/components/drawers/SignaturePromptEditorBridge.tsx +6 -6
- package/langwatch/src/optimization_studio/components/drawers/__tests__/SignaturePromptEditorBridge.integration.test.tsx +36 -11
- package/langwatch/src/pages/[project]/gateway/budgets/[id].tsx +1 -1
- package/langwatch/src/pages/[project]/gateway/virtual-keys/[id].tsx +1 -1
- package/langwatch/src/pages/settings/audit-log.tsx +82 -59
- package/langwatch/src/routes.tsx +0 -4
- package/langwatch/src/server/agents/agent.service.ts +6 -2
- package/langwatch/src/server/api/__tests__/rbac-integration.test.ts +53 -0
- package/langwatch/src/server/api/__tests__/rbac.auditLog.test.ts +100 -0
- package/langwatch/src/server/api/rbac.ts +12 -0
- package/langwatch/src/server/api/root.ts +0 -2
- package/langwatch/src/server/api/routers/organization.ts +1 -1
- package/langwatch/src/server/app-layer/organizations/repositories/organization.prisma.repository.ts +58 -120
- package/langwatch/src/server/app-layer/organizations/repositories/organization.repository.ts +8 -11
- package/langwatch/src/server/evaluators/evaluator.service.ts +6 -2
- package/langwatch/src/server/gateway/__tests__/auditLog.consolidation.integration.test.ts +237 -0
- package/langwatch/src/server/gateway/__tests__/cacheRule.service.unit.test.ts +2 -2
- package/langwatch/src/server/gateway/__tests__/providerCredential.service.unit.test.ts +6 -6
- package/langwatch/src/server/gateway/__tests__/virtualKey.service.unit.test.ts +6 -6
- package/langwatch/src/server/gateway/auditLog.repository.ts +46 -8
- package/langwatch/src/server/gateway/auditSerializer.ts +2 -2
- package/langwatch/src/server/gateway/budget.service.ts +6 -6
- package/langwatch/src/server/gateway/cacheRule.service.ts +5 -5
- package/langwatch/src/server/gateway/providerCredential.service.ts +5 -5
- package/langwatch/src/server/gateway/virtualKey.service.ts +9 -9
- package/langwatch/src/server/pat/__tests__/auth-middleware.unit.test.ts +138 -3
- package/langwatch/src/server/pat/auth-middleware.ts +68 -13
- package/langwatch/src/server/routes/__tests__/otel.unit.test.ts +241 -0
- package/langwatch/src/server/routes/otel.ts +281 -45
- package/langwatch/src/server/scenarios/adapters/__tests__/http-agent.adapter.test.ts +271 -6
- package/langwatch/src/server/scenarios/adapters/http-agent.adapter.ts +43 -35
- package/langwatch/src/server/scenarios/execution/http-template-engine.ts +124 -0
- package/langwatch/src/server/scenarios/execution/serialized-adapters/__tests__/http-agent.adapter.unit.test.ts +180 -0
- package/langwatch/src/server/scenarios/execution/serialized-adapters/http-agent.adapter.ts +26 -30
- package/langwatch/src/tasks/__tests__/migrateCustomModels.unit.test.ts +0 -2
- package/langwatch/src/tasks/migrateCustomModels.ts +1 -1
- package/langwatch/src/utils/__tests__/dbMultiTenancyProtection.unit.test.ts +0 -17
- package/langwatch/src/utils/permissionsConfig.ts +6 -0
- package/langwatch/src/utils/routes.ts +0 -5
- package/package.json +1 -1
- package/packages/server/dist/cli.cjs +39 -70
- package/langwatch/src/pages/[project]/gateway/audit.tsx +0 -606
- package/langwatch/src/server/api/routers/gatewayAudit.ts +0 -109
- package/langwatch/src/server/gateway/__tests__/audit.service.unit.test.ts +0 -156
- package/langwatch/src/server/gateway/audit.service.ts +0 -104
|
@@ -6,26 +6,91 @@ import { cleanup, render, screen, waitFor } from "@testing-library/react";
|
|
|
6
6
|
import userEvent from "@testing-library/user-event";
|
|
7
7
|
import type { ReactNode } from "react";
|
|
8
8
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
9
|
-
import type { TargetConfig } from "../../../types";
|
|
9
|
+
import type { EvaluatorConfig, TargetConfig } from "../../../types";
|
|
10
10
|
import { TargetCellContent } from "../TargetCell";
|
|
11
11
|
|
|
12
|
-
//
|
|
13
|
-
|
|
12
|
+
// Drawer + flow-callback mocks must be vi.hoisted so the vi.mock factory can
|
|
13
|
+
// reference them (vi.mock is hoisted above imports).
|
|
14
|
+
const { mockOpenDrawer, mockSetFlowCallbacks } = vi.hoisted(() => ({
|
|
15
|
+
mockOpenDrawer: vi.fn(),
|
|
16
|
+
mockSetFlowCallbacks: vi.fn(),
|
|
17
|
+
}));
|
|
18
|
+
|
|
14
19
|
vi.mock("~/hooks/useDrawer", () => ({
|
|
15
20
|
useDrawer: () => ({
|
|
16
21
|
openDrawer: mockOpenDrawer,
|
|
17
22
|
}),
|
|
23
|
+
setFlowCallbacks: mockSetFlowCallbacks,
|
|
18
24
|
}));
|
|
19
25
|
|
|
26
|
+
// Mutable state for the store mock — each test seeds what the component will
|
|
27
|
+
// read. `useEvaluationsV3Store` accepts a selector, so the mock must too.
|
|
28
|
+
type StoreMockState = {
|
|
29
|
+
evaluators: EvaluatorConfig[];
|
|
30
|
+
activeDatasetId: string;
|
|
31
|
+
datasets: Array<{
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
columns: Array<{ id: string; name: string; type: string }>;
|
|
35
|
+
}>;
|
|
36
|
+
removeEvaluator: ReturnType<typeof vi.fn>;
|
|
37
|
+
updateEvaluator: ReturnType<typeof vi.fn>;
|
|
38
|
+
setEvaluatorMapping: ReturnType<typeof vi.fn>;
|
|
39
|
+
removeEvaluatorMapping: ReturnType<typeof vi.fn>;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const storeMockState: StoreMockState = {
|
|
43
|
+
evaluators: [],
|
|
44
|
+
activeDatasetId: "dataset-1",
|
|
45
|
+
datasets: [],
|
|
46
|
+
removeEvaluator: vi.fn(),
|
|
47
|
+
updateEvaluator: vi.fn(),
|
|
48
|
+
setEvaluatorMapping: vi.fn(),
|
|
49
|
+
removeEvaluatorMapping: vi.fn(),
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const resetStoreMock = () => {
|
|
53
|
+
storeMockState.evaluators = [];
|
|
54
|
+
storeMockState.activeDatasetId = "dataset-1";
|
|
55
|
+
storeMockState.datasets = [];
|
|
56
|
+
storeMockState.removeEvaluator = vi.fn();
|
|
57
|
+
storeMockState.updateEvaluator = vi.fn();
|
|
58
|
+
storeMockState.setEvaluatorMapping = vi.fn();
|
|
59
|
+
storeMockState.removeEvaluatorMapping = vi.fn();
|
|
60
|
+
};
|
|
61
|
+
|
|
20
62
|
vi.mock("../../../hooks/useEvaluationsV3Store", () => ({
|
|
21
|
-
useEvaluationsV3Store: () =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
63
|
+
useEvaluationsV3Store: (selector?: (state: StoreMockState) => unknown) =>
|
|
64
|
+
selector ? selector(storeMockState) : storeMockState,
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
// Mock mappingValidation so we control which evaluators flag as
|
|
68
|
+
// hasMissingMappings without touching the real DSL logic.
|
|
69
|
+
vi.mock("../../../utils/mappingValidation", () => ({
|
|
70
|
+
evaluatorHasMissingMappings: vi.fn(() => false),
|
|
71
|
+
}));
|
|
72
|
+
|
|
73
|
+
// Replace the chip with a minimal stub that exposes onEdit as a plain button.
|
|
74
|
+
// The real chip wraps onEdit behind a Chakra Menu, which needs user-event
|
|
75
|
+
// gymnastics to open — and the chip has its own test file covering that.
|
|
76
|
+
// Here we only care that TargetCell wires the chip's onEdit to the correct
|
|
77
|
+
// drawer + flowCallbacks payload.
|
|
78
|
+
vi.mock("../EvaluatorChip", () => ({
|
|
79
|
+
EvaluatorChip: ({
|
|
80
|
+
evaluator,
|
|
81
|
+
onEdit,
|
|
82
|
+
}: {
|
|
83
|
+
evaluator: { id: string };
|
|
84
|
+
onEdit: () => void;
|
|
85
|
+
}) => (
|
|
86
|
+
<button
|
|
87
|
+
type="button"
|
|
88
|
+
data-testid={`evaluator-chip-stub-${evaluator.id}`}
|
|
89
|
+
onClick={onEdit}
|
|
90
|
+
>
|
|
91
|
+
chip:{evaluator.id}
|
|
92
|
+
</button>
|
|
93
|
+
),
|
|
29
94
|
}));
|
|
30
95
|
|
|
31
96
|
// Mock name hooks to avoid tRPC queries
|
|
@@ -58,6 +123,7 @@ const generateLongText = (length: number): string => {
|
|
|
58
123
|
describe("TargetCellContent", () => {
|
|
59
124
|
beforeEach(() => {
|
|
60
125
|
vi.clearAllMocks();
|
|
126
|
+
resetStoreMock();
|
|
61
127
|
});
|
|
62
128
|
|
|
63
129
|
afterEach(() => {
|
|
@@ -679,4 +745,126 @@ describe("TargetCellContent", () => {
|
|
|
679
745
|
expect(screen.getByText("Completed output")).toBeInTheDocument();
|
|
680
746
|
});
|
|
681
747
|
});
|
|
748
|
+
|
|
749
|
+
// Regression for issue #3441 fix 1: clicking the evaluator chip's edit
|
|
750
|
+
// path must open the editor drawer with both a mappingsConfig AND an
|
|
751
|
+
// onMappingChange callback registered via setFlowCallbacks. The drawer's
|
|
752
|
+
// render gate is `mappingsConfig && onMappingChange` — if either is
|
|
753
|
+
// missing, the mappings section silently hides and users can't configure
|
|
754
|
+
// variables. Prior regression lived in TargetCell.tsx bypassing the shared
|
|
755
|
+
// createEvaluatorEditorCallbacks helper and omitting onMappingChange.
|
|
756
|
+
describe("when the user clicks an evaluator chip's edit", () => {
|
|
757
|
+
const evaluator: EvaluatorConfig = {
|
|
758
|
+
id: "eval-1",
|
|
759
|
+
evaluatorType: "langevals/exact_match",
|
|
760
|
+
dbEvaluatorId: "db-eval-1",
|
|
761
|
+
mappings: {},
|
|
762
|
+
inputs: [
|
|
763
|
+
{ identifier: "output", type: "str" },
|
|
764
|
+
{ identifier: "expected_output", type: "str" },
|
|
765
|
+
],
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
const targetWithEvaluator = (): TargetConfig => ({
|
|
769
|
+
id: "target-1",
|
|
770
|
+
type: "prompt",
|
|
771
|
+
inputs: [{ identifier: "input", type: "str" }],
|
|
772
|
+
outputs: [{ identifier: "output", type: "str" }],
|
|
773
|
+
mappings: {},
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
const seedStoreWithEvaluatorAndDataset = () => {
|
|
777
|
+
storeMockState.evaluators = [evaluator];
|
|
778
|
+
storeMockState.datasets = [
|
|
779
|
+
{
|
|
780
|
+
id: "dataset-1",
|
|
781
|
+
name: "Test Dataset",
|
|
782
|
+
columns: [
|
|
783
|
+
{ id: "input", name: "input", type: "string" },
|
|
784
|
+
{ id: "expected_output", name: "expected_output", type: "string" },
|
|
785
|
+
],
|
|
786
|
+
},
|
|
787
|
+
];
|
|
788
|
+
};
|
|
789
|
+
|
|
790
|
+
it("registers onMappingChange on the evaluatorEditor flow callbacks", async () => {
|
|
791
|
+
seedStoreWithEvaluatorAndDataset();
|
|
792
|
+
const user = userEvent.setup();
|
|
793
|
+
|
|
794
|
+
render(
|
|
795
|
+
<TargetCellContent
|
|
796
|
+
target={targetWithEvaluator()}
|
|
797
|
+
output="some output"
|
|
798
|
+
evaluatorResults={{}}
|
|
799
|
+
row={0}
|
|
800
|
+
/>,
|
|
801
|
+
{ wrapper: Wrapper },
|
|
802
|
+
);
|
|
803
|
+
|
|
804
|
+
await user.click(screen.getByTestId("evaluator-chip-stub-eval-1"));
|
|
805
|
+
|
|
806
|
+
expect(mockSetFlowCallbacks).toHaveBeenCalledWith(
|
|
807
|
+
"evaluatorEditor",
|
|
808
|
+
expect.objectContaining({
|
|
809
|
+
onMappingChange: expect.any(Function),
|
|
810
|
+
}),
|
|
811
|
+
);
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
it("opens the evaluatorEditor drawer with a mappingsConfig containing availableSources and initialMappings", async () => {
|
|
815
|
+
seedStoreWithEvaluatorAndDataset();
|
|
816
|
+
const user = userEvent.setup();
|
|
817
|
+
|
|
818
|
+
render(
|
|
819
|
+
<TargetCellContent
|
|
820
|
+
target={targetWithEvaluator()}
|
|
821
|
+
output="some output"
|
|
822
|
+
evaluatorResults={{}}
|
|
823
|
+
row={0}
|
|
824
|
+
/>,
|
|
825
|
+
{ wrapper: Wrapper },
|
|
826
|
+
);
|
|
827
|
+
|
|
828
|
+
await user.click(screen.getByTestId("evaluator-chip-stub-eval-1"));
|
|
829
|
+
|
|
830
|
+
await waitFor(() => {
|
|
831
|
+
expect(mockOpenDrawer).toHaveBeenCalledWith(
|
|
832
|
+
"evaluatorEditor",
|
|
833
|
+
expect.objectContaining({
|
|
834
|
+
evaluatorType: "langevals/exact_match",
|
|
835
|
+
mappingsConfig: expect.objectContaining({
|
|
836
|
+
availableSources: expect.any(Array),
|
|
837
|
+
initialMappings: expect.any(Object),
|
|
838
|
+
}),
|
|
839
|
+
}),
|
|
840
|
+
);
|
|
841
|
+
});
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
it("keeps onMappingChange OUT of mappingsConfig (serializable complexProps constraint, see #3087)", async () => {
|
|
845
|
+
seedStoreWithEvaluatorAndDataset();
|
|
846
|
+
const user = userEvent.setup();
|
|
847
|
+
|
|
848
|
+
render(
|
|
849
|
+
<TargetCellContent
|
|
850
|
+
target={targetWithEvaluator()}
|
|
851
|
+
output="some output"
|
|
852
|
+
evaluatorResults={{}}
|
|
853
|
+
row={0}
|
|
854
|
+
/>,
|
|
855
|
+
{ wrapper: Wrapper },
|
|
856
|
+
);
|
|
857
|
+
|
|
858
|
+
await user.click(screen.getByTestId("evaluator-chip-stub-eval-1"));
|
|
859
|
+
|
|
860
|
+
expect(mockOpenDrawer).toHaveBeenCalledWith(
|
|
861
|
+
"evaluatorEditor",
|
|
862
|
+
expect.objectContaining({
|
|
863
|
+
mappingsConfig: expect.not.objectContaining({
|
|
864
|
+
onMappingChange: expect.any(Function),
|
|
865
|
+
}),
|
|
866
|
+
}),
|
|
867
|
+
);
|
|
868
|
+
});
|
|
869
|
+
});
|
|
682
870
|
});
|
|
@@ -58,7 +58,7 @@ export const VirtualizedTableBody = React.memo(function VirtualizedTableBody({
|
|
|
58
58
|
|
|
59
59
|
// Render all rows without virtualization when:
|
|
60
60
|
// - Test mode (disableVirtualization prop)
|
|
61
|
-
// -
|
|
61
|
+
// - Fit mode with <= 100 rows
|
|
62
62
|
if (disableVirtualization || !shouldVirtualize) {
|
|
63
63
|
return (
|
|
64
64
|
<>
|
|
@@ -7,3 +7,12 @@
|
|
|
7
7
|
* Used to calculate table layout and scroll positioning.
|
|
8
8
|
*/
|
|
9
9
|
export const DRAWER_WIDTH = 456;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Hover copy for the "missing variable mappings" alert icon shown on both
|
|
13
|
+
* target headers (TargetHeader.tsx) and evaluator chips (EvaluatorChip.tsx).
|
|
14
|
+
* Keep the two sites in lock-step — clicking the alert jumps the user to the
|
|
15
|
+
* mappings editor in both cases.
|
|
16
|
+
*/
|
|
17
|
+
export const TARGET_MISSING_MAPPING_TOOLTIP =
|
|
18
|
+
"Missing variable mappings - Click to configure";
|
|
@@ -75,7 +75,7 @@ describe("Persistence", () => {
|
|
|
75
75
|
it("excludes transient UI state from persisted state", () => {
|
|
76
76
|
const state = createInitialState();
|
|
77
77
|
state.ui.selectedRows = new Set([0, 1, 2]);
|
|
78
|
-
state.ui.rowHeightMode = "
|
|
78
|
+
state.ui.rowHeightMode = "fit";
|
|
79
79
|
|
|
80
80
|
const persisted = extractPersistedState(state);
|
|
81
81
|
|
|
@@ -355,7 +355,7 @@ export type CellPosition = {
|
|
|
355
355
|
columnId: string;
|
|
356
356
|
};
|
|
357
357
|
|
|
358
|
-
export type RowHeightMode = "compact" | "
|
|
358
|
+
export type RowHeightMode = "compact" | "fit";
|
|
359
359
|
|
|
360
360
|
export type AutosaveState = "idle" | "saving" | "saved" | "error";
|
|
361
361
|
|
|
@@ -583,6 +583,18 @@ export type EvaluationsV3Store = EvaluationsV3State & EvaluationsV3Actions;
|
|
|
583
583
|
export type TableRowData = {
|
|
584
584
|
rowIndex: number;
|
|
585
585
|
dataset: Record<string, string>;
|
|
586
|
+
/**
|
|
587
|
+
* True when the dataset row contains no user-entered values. The table
|
|
588
|
+
* always renders a trailing empty row for Excel-style "click to add,"
|
|
589
|
+
* but that phantom row must not show target outputs or evaluator chips.
|
|
590
|
+
*
|
|
591
|
+
* Required (non-optional) — every TableRowData built by the rowData
|
|
592
|
+
* builder in EvaluationsV3Table.tsx sets this. Was briefly optional during
|
|
593
|
+
* the #3441 sweep because DatasetSection/TableCell.tsx carried a parallel
|
|
594
|
+
* RowData shape without the field; that parallel shape has been unified
|
|
595
|
+
* with this type (#3460 item 5), so the optional can go.
|
|
596
|
+
*/
|
|
597
|
+
isEmpty: boolean;
|
|
586
598
|
targets: Record<
|
|
587
599
|
string,
|
|
588
600
|
{
|
|
@@ -74,6 +74,38 @@ describe("createEvaluatorEditorCallbacks()", () => {
|
|
|
74
74
|
expect(callbacks.onLocalConfigChange).toBeUndefined();
|
|
75
75
|
});
|
|
76
76
|
});
|
|
77
|
+
|
|
78
|
+
describe("when onLocalConfigChange is provided directly", () => {
|
|
79
|
+
it("uses the provided callback verbatim (no target shim)", () => {
|
|
80
|
+
const onLocalConfigChange = vi.fn();
|
|
81
|
+
const callbacks = createEvaluatorEditorCallbacks({
|
|
82
|
+
onLocalConfigChange,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const config: LocalEvaluatorConfig = { name: "Direct" };
|
|
86
|
+
callbacks.onLocalConfigChange?.(config);
|
|
87
|
+
|
|
88
|
+
expect(onLocalConfigChange).toHaveBeenCalledWith(config);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("takes precedence over targetId + updateTarget when both are provided", () => {
|
|
92
|
+
// The direct path wins so callers (e.g. evaluator chip) can persist
|
|
93
|
+
// local config to an evaluator instead of a target without needing
|
|
94
|
+
// to thread a fake targetId through the helper.
|
|
95
|
+
const onLocalConfigChange = vi.fn();
|
|
96
|
+
const updateTarget = vi.fn();
|
|
97
|
+
const callbacks = createEvaluatorEditorCallbacks({
|
|
98
|
+
onLocalConfigChange,
|
|
99
|
+
targetId: "target-1",
|
|
100
|
+
updateTarget,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
callbacks.onLocalConfigChange?.({ name: "Direct wins" });
|
|
104
|
+
|
|
105
|
+
expect(onLocalConfigChange).toHaveBeenCalledWith({ name: "Direct wins" });
|
|
106
|
+
expect(updateTarget).not.toHaveBeenCalled();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
77
109
|
});
|
|
78
110
|
|
|
79
111
|
describe("onMappingChange()", () => {
|
|
@@ -14,12 +14,30 @@ import type { LocalEvaluatorConfig } from "../types";
|
|
|
14
14
|
/**
|
|
15
15
|
* Parameters to create evaluator editor callbacks.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* Two ways to wire `onLocalConfigChange`:
|
|
18
|
+
*
|
|
19
|
+
* 1. **Direct** — pass `onLocalConfigChange` (recommended for sites that
|
|
20
|
+
* don't need the evaluations-v3 target-bound convenience, e.g. an
|
|
21
|
+
* evaluator chip whose local config updates an evaluator, not a target).
|
|
22
|
+
*
|
|
23
|
+
* 2. **Target-bound convenience** — pass `targetId + updateTarget`. The
|
|
24
|
+
* helper synthesizes `onLocalConfigChange` as
|
|
25
|
+
* `(lc) => updateTarget(targetId, { localEvaluatorConfig: lc })`. Used by
|
|
26
|
+
* `useOpenTargetEditor` for the prompt-target / agent-target / evaluator-
|
|
27
|
+
* target editor flows where a real target id exists.
|
|
28
|
+
*
|
|
29
|
+
* If both are provided, the direct `onLocalConfigChange` wins and the
|
|
30
|
+
* target-bound convenience is ignored. Contexts without any local-config
|
|
31
|
+
* persistence (e.g. `OnlineEvaluationDrawer`) omit all three.
|
|
20
32
|
*/
|
|
21
33
|
export type CreateEvaluatorEditorCallbacksParams = {
|
|
34
|
+
/** Direct local-config sink (use this when no target id is available). */
|
|
35
|
+
onLocalConfigChange?: (
|
|
36
|
+
localConfig: LocalEvaluatorConfig | undefined,
|
|
37
|
+
) => void;
|
|
38
|
+
/** Target-bound convenience: requires `updateTarget` to also be provided. */
|
|
22
39
|
targetId?: string;
|
|
40
|
+
/** Target-bound convenience: requires `targetId` to also be provided. */
|
|
23
41
|
updateTarget?: (
|
|
24
42
|
id: string,
|
|
25
43
|
updates: {
|
|
@@ -64,7 +82,17 @@ export type EvaluatorEditorCallbacksForTarget = {
|
|
|
64
82
|
* (durable) rather than embedding them in `mappingsConfig` (ephemeral,
|
|
65
83
|
* cleared on ErrorBoundary remount — see issue #3087).
|
|
66
84
|
*
|
|
67
|
-
* @example
|
|
85
|
+
* @example Direct (TargetCell evaluator chip — local config updates the evaluator, not a target):
|
|
86
|
+
* ```ts
|
|
87
|
+
* setFlowCallbacks("evaluatorEditor",
|
|
88
|
+
* createEvaluatorEditorCallbacks({
|
|
89
|
+
* onLocalConfigChange: (lc) => updateEvaluator(evaluator.id, { localEvaluatorConfig: lc }),
|
|
90
|
+
* onMappingChange,
|
|
91
|
+
* }),
|
|
92
|
+
* );
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @example Target-bound convenience (useOpenTargetEditor — prompt/agent/evaluator-target editors):
|
|
68
96
|
* ```ts
|
|
69
97
|
* setFlowCallbacks("evaluatorEditor",
|
|
70
98
|
* createEvaluatorEditorCallbacks({ targetId, updateTarget, onMappingChange }),
|
|
@@ -79,13 +107,16 @@ export type EvaluatorEditorCallbacksForTarget = {
|
|
|
79
107
|
* ```
|
|
80
108
|
*/
|
|
81
109
|
export const createEvaluatorEditorCallbacks = ({
|
|
110
|
+
onLocalConfigChange,
|
|
82
111
|
targetId,
|
|
83
112
|
updateTarget,
|
|
84
113
|
onMappingChange,
|
|
85
114
|
onSave,
|
|
86
115
|
}: CreateEvaluatorEditorCallbacksParams): EvaluatorEditorCallbacksForTarget => {
|
|
87
116
|
const callbacks: EvaluatorEditorCallbacksForTarget = {};
|
|
88
|
-
if (
|
|
117
|
+
if (onLocalConfigChange) {
|
|
118
|
+
callbacks.onLocalConfigChange = onLocalConfigChange;
|
|
119
|
+
} else if (targetId !== undefined && updateTarget) {
|
|
89
120
|
callbacks.onLocalConfigChange = (localConfig) => {
|
|
90
121
|
updateTarget(targetId, { localEvaluatorConfig: localConfig });
|
|
91
122
|
};
|
|
@@ -50,13 +50,8 @@ export function DatasetSelection({
|
|
|
50
50
|
setIsEditing({ id: datasetId, name });
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
openDrawer("
|
|
53
|
+
openDrawer("addOrEditDataset", {
|
|
54
54
|
onSuccess: handleSuccess,
|
|
55
|
-
onCreateFromScratch: () => {
|
|
56
|
-
openDrawer("addOrEditDataset", {
|
|
57
|
-
onSuccess: handleSuccess,
|
|
58
|
-
});
|
|
59
|
-
},
|
|
60
55
|
});
|
|
61
56
|
}}
|
|
62
57
|
>
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { ChakraProvider, defaultSystem } from "@chakra-ui/react";
|
|
6
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
7
|
+
import userEvent from "@testing-library/user-event";
|
|
8
|
+
import type { ReactNode } from "react";
|
|
9
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
10
|
+
import "@testing-library/jest-dom/vitest";
|
|
11
|
+
|
|
12
|
+
const mockOpenDrawer = vi.fn();
|
|
13
|
+
|
|
14
|
+
vi.mock("~/hooks/useDrawer", () => ({
|
|
15
|
+
useDrawer: () => ({
|
|
16
|
+
openDrawer: mockOpenDrawer,
|
|
17
|
+
}),
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
vi.mock("../../../../hooks/useOrganizationTeamProject", () => ({
|
|
21
|
+
useOrganizationTeamProject: () => ({
|
|
22
|
+
project: { id: "test-project" },
|
|
23
|
+
}),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
vi.mock("../../../../utils/api", () => ({
|
|
27
|
+
api: {
|
|
28
|
+
dataset: {
|
|
29
|
+
getAll: {
|
|
30
|
+
useQuery: () => ({ data: [], isLoading: false }),
|
|
31
|
+
},
|
|
32
|
+
deleteById: {
|
|
33
|
+
useMutation: () => ({ mutate: vi.fn() }),
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
useContext: () => ({
|
|
37
|
+
limits: { getUsage: { invalidate: vi.fn() } },
|
|
38
|
+
licenseEnforcement: { checkLimit: { invalidate: vi.fn() } },
|
|
39
|
+
}),
|
|
40
|
+
},
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
vi.mock("../../../../components/datasets/DatasetPreview", () => ({
|
|
44
|
+
DatasetPreview: () => null,
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
vi.mock("../../../../components/datasets/DatasetTable", () => ({
|
|
48
|
+
DEFAULT_DATASET_NAME: "New Dataset",
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
vi.mock("../../../hooks/useGetDatasetData", () => ({
|
|
52
|
+
useGetDatasetData: () => ({ rows: [], columns: [] }),
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
vi.mock("../../../../hooks/useDeleteDatasetConfirmation", () => ({
|
|
56
|
+
useDeleteDatasetConfirmation: () => ({
|
|
57
|
+
showDeleteDialog: vi.fn(),
|
|
58
|
+
DeleteDialog: () => null,
|
|
59
|
+
}),
|
|
60
|
+
}));
|
|
61
|
+
|
|
62
|
+
vi.mock("../../../../components/ui/toaster", () => ({
|
|
63
|
+
toaster: { create: vi.fn() },
|
|
64
|
+
}));
|
|
65
|
+
|
|
66
|
+
vi.mock("../../../../components/ui/menu", () => ({
|
|
67
|
+
Menu: {
|
|
68
|
+
Root: ({ children }: { children: React.ReactNode }) => children,
|
|
69
|
+
Trigger: ({ children }: { children: React.ReactNode }) => children,
|
|
70
|
+
Content: () => null,
|
|
71
|
+
Item: () => null,
|
|
72
|
+
},
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
import { DatasetSelection } from "../DatasetSelection";
|
|
76
|
+
|
|
77
|
+
function renderWithProviders(ui: ReactNode) {
|
|
78
|
+
return render(
|
|
79
|
+
<ChakraProvider value={defaultSystem}>{ui}</ChakraProvider>,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
describe("DatasetSelection", () => {
|
|
84
|
+
const defaultProps = {
|
|
85
|
+
node: {
|
|
86
|
+
id: "node-1",
|
|
87
|
+
data: { dataset: undefined },
|
|
88
|
+
type: "entry",
|
|
89
|
+
position: { x: 0, y: 0 },
|
|
90
|
+
} as never,
|
|
91
|
+
setIsEditing: vi.fn(),
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
afterEach(() => {
|
|
95
|
+
cleanup();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
beforeEach(() => {
|
|
99
|
+
vi.clearAllMocks();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe("when clicking the New dataset button", () => {
|
|
103
|
+
it("opens addOrEditDataset drawer directly without forcing file upload", async () => {
|
|
104
|
+
const user = userEvent.setup();
|
|
105
|
+
|
|
106
|
+
renderWithProviders(<DatasetSelection {...defaultProps} />);
|
|
107
|
+
|
|
108
|
+
const newDatasetButton = screen.getByRole("button", {
|
|
109
|
+
name: /new dataset/i,
|
|
110
|
+
});
|
|
111
|
+
await user.click(newDatasetButton);
|
|
112
|
+
|
|
113
|
+
expect(mockOpenDrawer).toHaveBeenCalledTimes(1);
|
|
114
|
+
expect(mockOpenDrawer).toHaveBeenCalledWith("addOrEditDataset", {
|
|
115
|
+
onSuccess: expect.any(Function),
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Regression: must NOT open uploadCSV drawer
|
|
119
|
+
expect(mockOpenDrawer).not.toHaveBeenCalledWith(
|
|
120
|
+
"uploadCSV",
|
|
121
|
+
expect.anything(),
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("calls setIsEditing with the created dataset when onSuccess fires", async () => {
|
|
126
|
+
const user = userEvent.setup();
|
|
127
|
+
|
|
128
|
+
renderWithProviders(<DatasetSelection {...defaultProps} />);
|
|
129
|
+
|
|
130
|
+
const newDatasetButton = screen.getByRole("button", {
|
|
131
|
+
name: /new dataset/i,
|
|
132
|
+
});
|
|
133
|
+
await user.click(newDatasetButton);
|
|
134
|
+
|
|
135
|
+
const onSuccess = mockOpenDrawer.mock.calls[0]![1].onSuccess as (
|
|
136
|
+
args: { datasetId: string; name: string },
|
|
137
|
+
) => void;
|
|
138
|
+
onSuccess({ datasetId: "new-ds-42", name: "My New Dataset" });
|
|
139
|
+
|
|
140
|
+
expect(defaultProps.setIsEditing).toHaveBeenCalledWith({
|
|
141
|
+
id: "new-ds-42",
|
|
142
|
+
name: "My New Dataset",
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe("when a dataset already exists on the node", () => {
|
|
148
|
+
it("opens addOrEditDataset drawer, not uploadCSV", async () => {
|
|
149
|
+
const user = userEvent.setup();
|
|
150
|
+
const propsWithDataset = {
|
|
151
|
+
...defaultProps,
|
|
152
|
+
node: {
|
|
153
|
+
id: "node-1",
|
|
154
|
+
type: "entry",
|
|
155
|
+
position: { x: 0, y: 0 },
|
|
156
|
+
data: { dataset: { id: "existing-123", name: "Existing Dataset" } },
|
|
157
|
+
} as never,
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
renderWithProviders(<DatasetSelection {...propsWithDataset} />);
|
|
161
|
+
|
|
162
|
+
const newDatasetButton = screen.getByRole("button", {
|
|
163
|
+
name: /new dataset/i,
|
|
164
|
+
});
|
|
165
|
+
await user.click(newDatasetButton);
|
|
166
|
+
|
|
167
|
+
expect(mockOpenDrawer).toHaveBeenCalledWith("addOrEditDataset", {
|
|
168
|
+
onSuccess: expect.any(Function),
|
|
169
|
+
});
|
|
170
|
+
expect(mockOpenDrawer).not.toHaveBeenCalledWith(
|
|
171
|
+
"uploadCSV",
|
|
172
|
+
expect.anything(),
|
|
173
|
+
);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// @regression #2506
|
|
178
|
+
describe("when any interaction triggers openDrawer", () => {
|
|
179
|
+
it("never passes uploadCSV to openDrawer", async () => {
|
|
180
|
+
const user = userEvent.setup();
|
|
181
|
+
|
|
182
|
+
renderWithProviders(<DatasetSelection {...defaultProps} />);
|
|
183
|
+
|
|
184
|
+
const newDatasetButton = screen.getByRole("button", {
|
|
185
|
+
name: /new dataset/i,
|
|
186
|
+
});
|
|
187
|
+
await user.click(newDatasetButton);
|
|
188
|
+
|
|
189
|
+
for (const call of mockOpenDrawer.mock.calls) {
|
|
190
|
+
expect(call[0]).not.toBe("uploadCSV"); // @regression #2506
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
package/langwatch/src/optimization_studio/components/drawers/SignaturePromptEditorBridge.tsx
CHANGED
|
@@ -191,15 +191,15 @@ export function SignaturePromptEditorBridge({
|
|
|
191
191
|
if (signatureNode.data.localPromptConfig) {
|
|
192
192
|
return signatureNode.data.localPromptConfig;
|
|
193
193
|
}
|
|
194
|
-
//
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
//
|
|
194
|
+
// Fall back to extracting config from inline parameters.
|
|
195
|
+
// When promptId is set and the prompt exists in DB, the drawer will use
|
|
196
|
+
// the DB data and ignore this. When the prompt is NOT found (e.g. after
|
|
197
|
+
// importing a workflow from another project), this provides the fallback
|
|
198
|
+
// so the drawer can display the node's actual inline configuration
|
|
199
|
+
// instead of an empty "New Prompt" form.
|
|
199
200
|
return nodeDataToLocalPromptConfig(signatureNode.data);
|
|
200
201
|
}, [
|
|
201
202
|
signatureNode.data.localPromptConfig,
|
|
202
|
-
signatureNode.data.promptId,
|
|
203
203
|
signatureNode.data,
|
|
204
204
|
]);
|
|
205
205
|
|