@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
|
@@ -116,7 +116,7 @@ describe("SignaturePromptEditorBridge", () => {
|
|
|
116
116
|
describe("when initialLocalConfig is computed", () => {
|
|
117
117
|
it("uses localPromptConfig when present on node data", () => {
|
|
118
118
|
const localConfig: LocalPromptConfig = {
|
|
119
|
-
llm: { model: "gpt-
|
|
119
|
+
llm: { model: "gpt-5-mini" },
|
|
120
120
|
messages: [{ role: "system", content: "You are helpful" }],
|
|
121
121
|
inputs: [{ identifier: "input", type: "str" }],
|
|
122
122
|
outputs: [{ identifier: "output", type: "str" }],
|
|
@@ -128,12 +128,37 @@ describe("SignaturePromptEditorBridge", () => {
|
|
|
128
128
|
expect(mockNodeDataToLocalPromptConfig).not.toHaveBeenCalled();
|
|
129
129
|
});
|
|
130
130
|
|
|
131
|
-
it("
|
|
131
|
+
it("falls back to nodeDataToLocalPromptConfig when node has promptId but no localPromptConfig", () => {
|
|
132
|
+
const fallbackConfig: LocalPromptConfig = {
|
|
133
|
+
llm: { model: "gpt-5-mini" },
|
|
134
|
+
messages: [{ role: "system", content: "You are helpful" }],
|
|
135
|
+
inputs: [{ identifier: "question", type: "str" }],
|
|
136
|
+
outputs: [{ identifier: "answer", type: "str" }],
|
|
137
|
+
};
|
|
138
|
+
mockNodeDataToLocalPromptConfig.mockReturnValue(fallbackConfig);
|
|
139
|
+
|
|
140
|
+
const node = createSignatureNode({
|
|
141
|
+
promptId: "prompt-from-other-project",
|
|
142
|
+
parameters: [
|
|
143
|
+
{ identifier: "llm", type: "llm", value: { model: "gpt-5-mini" } },
|
|
144
|
+
{ identifier: "instructions", type: "str", value: "You are helpful" },
|
|
145
|
+
],
|
|
146
|
+
});
|
|
147
|
+
render(<SignaturePromptEditorBridge node={node} />);
|
|
148
|
+
|
|
149
|
+
// Bridge should provide fallback so the drawer can use it when DB query returns null
|
|
150
|
+
expect(mockNodeDataToLocalPromptConfig).toHaveBeenCalledWith(node.data);
|
|
151
|
+
expect(capturedProps.initialLocalConfig).toBe(fallbackConfig);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("returns undefined when node has promptId but no inline parameters", () => {
|
|
155
|
+
mockNodeDataToLocalPromptConfig.mockReturnValue(undefined);
|
|
156
|
+
|
|
132
157
|
const node = createSignatureNode({ promptId: "prompt-123" });
|
|
133
158
|
render(<SignaturePromptEditorBridge node={node} />);
|
|
134
159
|
|
|
160
|
+
expect(mockNodeDataToLocalPromptConfig).toHaveBeenCalledWith(node.data);
|
|
135
161
|
expect(capturedProps.initialLocalConfig).toBeUndefined();
|
|
136
|
-
expect(mockNodeDataToLocalPromptConfig).not.toHaveBeenCalled();
|
|
137
162
|
});
|
|
138
163
|
|
|
139
164
|
it("falls back to nodeDataToLocalPromptConfig when no promptId and no localPromptConfig", () => {
|
|
@@ -159,7 +184,7 @@ describe("SignaturePromptEditorBridge", () => {
|
|
|
159
184
|
render(<SignaturePromptEditorBridge node={node} />);
|
|
160
185
|
|
|
161
186
|
const config: LocalPromptConfig = {
|
|
162
|
-
llm: { model: "gpt-
|
|
187
|
+
llm: { model: "gpt-5-mini" },
|
|
163
188
|
messages: [],
|
|
164
189
|
inputs: [
|
|
165
190
|
{ identifier: "input", type: "str" },
|
|
@@ -187,7 +212,7 @@ describe("SignaturePromptEditorBridge", () => {
|
|
|
187
212
|
render(<SignaturePromptEditorBridge node={node} />);
|
|
188
213
|
|
|
189
214
|
const config: LocalPromptConfig = {
|
|
190
|
-
llm: { model: "gpt-
|
|
215
|
+
llm: { model: "gpt-5-mini" },
|
|
191
216
|
messages: [],
|
|
192
217
|
inputs: [{ identifier: "input", type: "str" }],
|
|
193
218
|
outputs: [
|
|
@@ -215,7 +240,7 @@ describe("SignaturePromptEditorBridge", () => {
|
|
|
215
240
|
render(<SignaturePromptEditorBridge node={node} />);
|
|
216
241
|
|
|
217
242
|
const config: LocalPromptConfig = {
|
|
218
|
-
llm: { model: "gpt-
|
|
243
|
+
llm: { model: "gpt-5-mini" },
|
|
219
244
|
messages: [],
|
|
220
245
|
inputs: [{ identifier: "input", type: "str" }],
|
|
221
246
|
outputs: [{ identifier: "output", type: "str" }],
|
|
@@ -243,7 +268,7 @@ describe("SignaturePromptEditorBridge", () => {
|
|
|
243
268
|
render(<SignaturePromptEditorBridge node={node} />);
|
|
244
269
|
|
|
245
270
|
const config: LocalPromptConfig = {
|
|
246
|
-
llm: { model: "gpt-
|
|
271
|
+
llm: { model: "gpt-5-mini" },
|
|
247
272
|
messages: [],
|
|
248
273
|
inputs: [{ identifier: "input", type: "str" }],
|
|
249
274
|
outputs: [{ identifier: "output", type: "str" }],
|
|
@@ -279,7 +304,7 @@ describe("SignaturePromptEditorBridge", () => {
|
|
|
279
304
|
render(<SignaturePromptEditorBridge node={node} />);
|
|
280
305
|
|
|
281
306
|
const config: LocalPromptConfig = {
|
|
282
|
-
llm: { model: "gpt-
|
|
307
|
+
llm: { model: "gpt-5-mini" },
|
|
283
308
|
messages: [],
|
|
284
309
|
inputs: [{ identifier: "question", type: "str" }],
|
|
285
310
|
outputs: [{ identifier: "output", type: "str" }],
|
|
@@ -440,7 +465,7 @@ describe("SignaturePromptEditorBridge", () => {
|
|
|
440
465
|
render(<SignaturePromptEditorBridge node={node} />);
|
|
441
466
|
|
|
442
467
|
const config: LocalPromptConfig = {
|
|
443
|
-
llm: { model: "gpt-
|
|
468
|
+
llm: { model: "gpt-5-mini" },
|
|
444
469
|
messages: [{ role: "system", content: "Be helpful" }],
|
|
445
470
|
inputs: [{ identifier: "query", type: "str" }],
|
|
446
471
|
outputs: [{ identifier: "response", type: "str" }],
|
|
@@ -484,7 +509,7 @@ describe("SignaturePromptEditorBridge", () => {
|
|
|
484
509
|
render(<SignaturePromptEditorBridge node={node} />);
|
|
485
510
|
|
|
486
511
|
const config: LocalPromptConfig = {
|
|
487
|
-
llm: { model: "gpt-
|
|
512
|
+
llm: { model: "gpt-5-mini" },
|
|
488
513
|
messages: [],
|
|
489
514
|
inputs: [{ identifier: "input", type: "str" }],
|
|
490
515
|
outputs: [{ identifier: "output", type: "str" }],
|
|
@@ -537,7 +562,7 @@ describe("SignaturePromptEditorBridge", () => {
|
|
|
537
562
|
render(<SignaturePromptEditorBridge node={node} />);
|
|
538
563
|
|
|
539
564
|
const config: LocalPromptConfig = {
|
|
540
|
-
llm: { model: "gpt-
|
|
565
|
+
llm: { model: "gpt-5-mini" },
|
|
541
566
|
messages: [],
|
|
542
567
|
inputs: [
|
|
543
568
|
{ identifier: "input", type: "str" },
|
|
@@ -114,7 +114,7 @@ function BudgetDetailPage() {
|
|
|
114
114
|
the full lifecycle trail stays queryable so operators
|
|
115
115
|
can reconstruct why a budget was archived. */}
|
|
116
116
|
<Link
|
|
117
|
-
href={
|
|
117
|
+
href={`/settings/audit-log?targetKind=budget&targetId=${budget.id}`}
|
|
118
118
|
>
|
|
119
119
|
<Button variant="outline" size="sm">
|
|
120
120
|
<FileClock size={14} /> Audit history
|
|
@@ -140,7 +140,7 @@ function VirtualKeyDetailPage() {
|
|
|
140
140
|
operators forensically investigating a revoked VK
|
|
141
141
|
still need its create/update/rotate/revoke trail. */}
|
|
142
142
|
<Link
|
|
143
|
-
href={
|
|
143
|
+
href={`/settings/audit-log?targetKind=virtual_key&targetId=${vk.id}`}
|
|
144
144
|
>
|
|
145
145
|
<Button variant="outline" size="sm">
|
|
146
146
|
<FileClock size={14} /> Audit history
|
|
@@ -33,8 +33,26 @@ import { InputGroup } from "../../components/ui/input-group";
|
|
|
33
33
|
import { withPermissionGuard } from "../../components/WithPermissionGuard";
|
|
34
34
|
import { useActivePlan } from "../../hooks/useActivePlan";
|
|
35
35
|
import { useOrganizationTeamProject } from "../../hooks/useOrganizationTeamProject";
|
|
36
|
+
import type { EnrichedAuditLog } from "~/server/app-layer/organizations/repositories/organization.repository";
|
|
36
37
|
import { api } from "../../utils/api";
|
|
37
38
|
|
|
39
|
+
// CSV-cell cap for JSON columns (args / before / after). 4 KB is enough
|
|
40
|
+
// to capture typical gateway-shape diffs while staying well under the
|
|
41
|
+
// per-cell limits of common spreadsheet tools (Excel: 32K chars).
|
|
42
|
+
// `slice` counts UTF-16 code units, so the byte size can be up to ~16 KB
|
|
43
|
+
// for fully non-ASCII payloads — acceptable upper bound.
|
|
44
|
+
const CSV_JSON_CAP = 4096;
|
|
45
|
+
|
|
46
|
+
// Stringify + cap a JSON-shaped value for inclusion in a CSV cell.
|
|
47
|
+
// When the JSON exceeds the cap, append an explicit truncation marker so
|
|
48
|
+
// downstream consumers can tell the cell was clipped vs. just empty.
|
|
49
|
+
function truncateJsonForCsv(value: unknown): string {
|
|
50
|
+
if (value == null) return "";
|
|
51
|
+
const s = JSON.stringify(value);
|
|
52
|
+
if (s.length <= CSV_JSON_CAP) return s;
|
|
53
|
+
return `${s.slice(0, CSV_JSON_CAP)}…[truncated ${s.length - CSV_JSON_CAP} chars]`;
|
|
54
|
+
}
|
|
55
|
+
|
|
38
56
|
function AuditLogPage() {
|
|
39
57
|
const { organization, project, organizations } = useOrganizationTeamProject();
|
|
40
58
|
const { isEnterprise, isLoading: isPlanLoading } = useActivePlan();
|
|
@@ -155,28 +173,14 @@ function AuditLogPage() {
|
|
|
155
173
|
<Alert.Content>
|
|
156
174
|
<Alert.Title>Enterprise Feature</Alert.Title>
|
|
157
175
|
<Alert.Description>
|
|
158
|
-
Organisation-wide audit logs
|
|
159
|
-
|
|
176
|
+
Organisation-wide audit logs — including AI Gateway events
|
|
177
|
+
(virtual-key / budget / provider / cache-rule mutations)
|
|
178
|
+
alongside logins, member changes, settings, RBAC, and
|
|
179
|
+
billing — are available on Enterprise plans. Contact sales
|
|
160
180
|
to upgrade.
|
|
161
181
|
</Alert.Description>
|
|
162
182
|
</Alert.Content>
|
|
163
183
|
</Alert.Root>
|
|
164
|
-
{project && (
|
|
165
|
-
<Alert.Root status="success">
|
|
166
|
-
<Alert.Indicator />
|
|
167
|
-
<Alert.Content>
|
|
168
|
-
<Alert.Title>AI Gateway audit is available to you</Alert.Title>
|
|
169
|
-
<Alert.Description>
|
|
170
|
-
Virtual-key, budget, provider, and cache-rule changes are
|
|
171
|
-
logged for every plan.{" "}
|
|
172
|
-
<Link href={`/${project.slug}/gateway/audit`}>
|
|
173
|
-
Open the Gateway audit log
|
|
174
|
-
</Link>
|
|
175
|
-
.
|
|
176
|
-
</Alert.Description>
|
|
177
|
-
</Alert.Content>
|
|
178
|
-
</Alert.Root>
|
|
179
|
-
)}
|
|
180
184
|
<Box width="full">
|
|
181
185
|
<ContactSalesBlock />
|
|
182
186
|
</Box>
|
|
@@ -243,7 +247,11 @@ function AuditLogPage() {
|
|
|
243
247
|
};
|
|
244
248
|
|
|
245
249
|
const totalHits = auditLogsData?.totalCount ?? 0;
|
|
246
|
-
|
|
250
|
+
// Single cast at the source so the rest of the page consumes the proper
|
|
251
|
+
// EnrichedAuditLog union (source / targetKind / before / after) without
|
|
252
|
+
// per-field `as any` casts. tRPC's inference loses the discriminator.
|
|
253
|
+
const auditLogs: EnrichedAuditLog[] =
|
|
254
|
+
(auditLogsData?.auditLogs as EnrichedAuditLog[] | undefined) ?? [];
|
|
247
255
|
|
|
248
256
|
const downloadCSV = async () => {
|
|
249
257
|
if (!organization) return;
|
|
@@ -255,16 +263,25 @@ function AuditLogPage() {
|
|
|
255
263
|
const batchSize = 5000;
|
|
256
264
|
let totalCount = 0;
|
|
257
265
|
|
|
258
|
-
//
|
|
259
|
-
|
|
266
|
+
// Mirror the on-screen table filters exactly so an export from a
|
|
267
|
+
// pre-filtered deep-link (`?targetKind=virtual_key&targetId=…`) does
|
|
268
|
+
// not silently widen to the whole org's audit history.
|
|
269
|
+
const baseFilters = {
|
|
260
270
|
organizationId: organization.id,
|
|
261
271
|
projectId: selectedProjectId ?? undefined,
|
|
262
272
|
userId: searchUserId,
|
|
263
|
-
pageOffset: 0,
|
|
264
|
-
pageSize: batchSize,
|
|
265
273
|
action: actionFilter || undefined,
|
|
266
274
|
startDate: startDate.getTime(),
|
|
267
275
|
endDate: endDate.getTime(),
|
|
276
|
+
targetKind: urlTargetKind || undefined,
|
|
277
|
+
targetId: urlTargetId || undefined,
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
// Fetch first batch to get total count
|
|
281
|
+
const initialBatch = await queryClient.organization.getAuditLogs.fetch({
|
|
282
|
+
...baseFilters,
|
|
283
|
+
pageOffset: 0,
|
|
284
|
+
pageSize: batchSize,
|
|
268
285
|
});
|
|
269
286
|
|
|
270
287
|
allAuditLogs.push(...(initialBatch.auditLogs ?? []));
|
|
@@ -274,14 +291,9 @@ function AuditLogPage() {
|
|
|
274
291
|
// Loop through remaining pages
|
|
275
292
|
while (currentOffset < totalCount) {
|
|
276
293
|
const batch = await queryClient.organization.getAuditLogs.fetch({
|
|
277
|
-
|
|
278
|
-
projectId: selectedProjectId ?? undefined,
|
|
279
|
-
userId: searchUserId,
|
|
294
|
+
...baseFilters,
|
|
280
295
|
pageOffset: currentOffset,
|
|
281
296
|
pageSize: batchSize,
|
|
282
|
-
action: actionFilter || undefined,
|
|
283
|
-
startDate: startDate.getTime(),
|
|
284
|
-
endDate: endDate.getTime(),
|
|
285
297
|
});
|
|
286
298
|
|
|
287
299
|
if (!batch.auditLogs || batch.auditLogs.length === 0) break;
|
|
@@ -290,30 +302,46 @@ function AuditLogPage() {
|
|
|
290
302
|
currentOffset += batchSize;
|
|
291
303
|
}
|
|
292
304
|
|
|
293
|
-
// Define CSV fields
|
|
305
|
+
// Define CSV fields. Source/Target/Before/After mirror the on-screen
|
|
306
|
+
// gateway-shape columns so a downloaded report carries the diffs.
|
|
294
307
|
const fields = [
|
|
295
308
|
"Timestamp",
|
|
309
|
+
"Source",
|
|
296
310
|
"User Name",
|
|
297
311
|
"User Email",
|
|
298
312
|
"Action",
|
|
313
|
+
"Target Kind",
|
|
314
|
+
"Target Id",
|
|
299
315
|
"Project",
|
|
300
316
|
"IP Address",
|
|
301
317
|
"User Agent",
|
|
302
318
|
"Error",
|
|
303
319
|
"Args",
|
|
320
|
+
"Before",
|
|
321
|
+
"After",
|
|
304
322
|
];
|
|
305
323
|
|
|
306
324
|
// Convert audit logs to CSV rows
|
|
307
325
|
const csvData = allAuditLogs.map((log) => [
|
|
308
326
|
new Date(log.createdAt).toISOString(),
|
|
309
|
-
|
|
310
|
-
|
|
327
|
+
log.source ?? "platform",
|
|
328
|
+
log.user?.name ?? "",
|
|
329
|
+
log.user?.email ?? "",
|
|
311
330
|
log.action,
|
|
312
|
-
|
|
331
|
+
log.targetKind ?? "",
|
|
332
|
+
log.targetId ?? "",
|
|
333
|
+
log.project?.name ?? log.projectId ?? "",
|
|
313
334
|
log.ipAddress ?? "",
|
|
314
335
|
log.userAgent ?? "",
|
|
315
336
|
log.error ?? "",
|
|
316
|
-
|
|
337
|
+
// Cap JSON columns so a single oversized diff (large request
|
|
338
|
+
// payload, full provider config) can't blow up the exported
|
|
339
|
+
// file size or break Excel/Sheets row parsing. Truncated cells
|
|
340
|
+
// carry an explicit "…[truncated N chars]" marker so consumers
|
|
341
|
+
// can tell clipped JSON from empty values.
|
|
342
|
+
truncateJsonForCsv(log.args),
|
|
343
|
+
truncateJsonForCsv(log.before),
|
|
344
|
+
truncateJsonForCsv(log.after),
|
|
317
345
|
]);
|
|
318
346
|
|
|
319
347
|
// Generate CSV
|
|
@@ -347,23 +375,22 @@ function AuditLogPage() {
|
|
|
347
375
|
};
|
|
348
376
|
|
|
349
377
|
// Derive a return URL back to the originating detail page when the
|
|
350
|
-
// operator arrived via a
|
|
351
|
-
//
|
|
378
|
+
// operator arrived via a deep-link. Only kinds that have a real
|
|
379
|
+
// `[id]` detail route are mapped — provider_binding and cache_rule
|
|
380
|
+
// are list-only today, so we skip them rather than render a link
|
|
381
|
+
// that 404s.
|
|
352
382
|
const backToResource = (() => {
|
|
353
383
|
if (!urlTargetKind || !urlTargetId || !project?.slug) return null;
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
return null;
|
|
384
|
+
const kindMap: Record<string, { path: string; label: string }> = {
|
|
385
|
+
virtual_key: { path: "gateway/virtual-keys", label: "Virtual key" },
|
|
386
|
+
budget: { path: "gateway/budgets", label: "Budget" },
|
|
387
|
+
};
|
|
388
|
+
const entry = kindMap[urlTargetKind];
|
|
389
|
+
if (!entry) return null;
|
|
390
|
+
return {
|
|
391
|
+
href: `/${project.slug}/${entry.path}/${urlTargetId}`,
|
|
392
|
+
label: entry.label,
|
|
393
|
+
};
|
|
367
394
|
})();
|
|
368
395
|
|
|
369
396
|
return (
|
|
@@ -559,14 +586,10 @@ function AuditLogPage() {
|
|
|
559
586
|
size="sm"
|
|
560
587
|
variant="subtle"
|
|
561
588
|
colorPalette={
|
|
562
|
-
|
|
563
|
-
? "purple"
|
|
564
|
-
: "gray"
|
|
589
|
+
log.source === "gateway" ? "purple" : "gray"
|
|
565
590
|
}
|
|
566
591
|
>
|
|
567
|
-
{
|
|
568
|
-
? "Gateway"
|
|
569
|
-
: "Platform"}
|
|
592
|
+
{log.source === "gateway" ? "Gateway" : "Platform"}
|
|
570
593
|
</Badge>
|
|
571
594
|
</Table.Cell>
|
|
572
595
|
<Table.Cell>
|
|
@@ -591,13 +614,13 @@ function AuditLogPage() {
|
|
|
591
614
|
</Text>
|
|
592
615
|
</Table.Cell>
|
|
593
616
|
<Table.Cell>
|
|
594
|
-
{
|
|
617
|
+
{log.targetKind && log.targetId ? (
|
|
595
618
|
<VStack align="start" gap={0}>
|
|
596
619
|
<Text fontSize="xs" color="fg.muted">
|
|
597
|
-
{
|
|
620
|
+
{log.targetKind}
|
|
598
621
|
</Text>
|
|
599
622
|
<Text fontSize="xs" fontFamily="mono">
|
|
600
|
-
{
|
|
623
|
+
{log.targetId.slice(0, 16)}…
|
|
601
624
|
</Text>
|
|
602
625
|
</VStack>
|
|
603
626
|
) : (
|
|
@@ -669,6 +692,6 @@ function AuditLogPage() {
|
|
|
669
692
|
);
|
|
670
693
|
}
|
|
671
694
|
|
|
672
|
-
export default withPermissionGuard("
|
|
695
|
+
export default withPermissionGuard("auditLog:view", {
|
|
673
696
|
layoutComponent: SettingsLayout,
|
|
674
697
|
})(AuditLogPage);
|
package/langwatch/src/routes.tsx
CHANGED
|
@@ -225,10 +225,6 @@ const routes: RouteObject[] = [
|
|
|
225
225
|
path: "/:project/gateway/usage",
|
|
226
226
|
...page(() => import("./pages/[project]/gateway/usage")),
|
|
227
227
|
},
|
|
228
|
-
{
|
|
229
|
-
path: "/:project/gateway/audit",
|
|
230
|
-
...page(() => import("./pages/[project]/gateway/audit")),
|
|
231
|
-
},
|
|
232
228
|
{
|
|
233
229
|
path: "/:project/gateway/cache-rules",
|
|
234
230
|
...page(() => import("./pages/[project]/gateway/cache-rules")),
|
|
@@ -337,7 +337,11 @@ export class AgentService {
|
|
|
337
337
|
take: 100,
|
|
338
338
|
});
|
|
339
339
|
|
|
340
|
-
const userIds = [
|
|
340
|
+
const userIds = [
|
|
341
|
+
...new Set(
|
|
342
|
+
logs.map((l) => l.userId).filter((id): id is string => !!id),
|
|
343
|
+
),
|
|
344
|
+
];
|
|
341
345
|
const users = await this.prisma.user.findMany({
|
|
342
346
|
where: { id: { in: userIds } },
|
|
343
347
|
select: { id: true, name: true, email: true },
|
|
@@ -349,7 +353,7 @@ export class AgentService {
|
|
|
349
353
|
action: log.action,
|
|
350
354
|
createdAt: log.createdAt,
|
|
351
355
|
args: log.args,
|
|
352
|
-
user: usersById[log.userId] ?? null,
|
|
356
|
+
user: log.userId ? (usersById[log.userId] ?? null) : null,
|
|
353
357
|
}));
|
|
354
358
|
}
|
|
355
359
|
|
|
@@ -414,6 +414,20 @@ describe("RBAC Integration Tests", () => {
|
|
|
414
414
|
expect(result).toBe(true);
|
|
415
415
|
});
|
|
416
416
|
|
|
417
|
+
// Regression coverage for the audit consolidation: the unified
|
|
418
|
+
// /settings/audit-log page is gated on auditLog:view (was
|
|
419
|
+
// gatewayLogs:view + organization:manage pre-consolidation). Legacy
|
|
420
|
+
// admins must keep their access via the same TeamUser fallback path
|
|
421
|
+
// that grants gatewayBudgets:view / gatewayCacheRules:create above.
|
|
422
|
+
it("grants auditLog:view (post-consolidation /settings/audit-log)", async () => {
|
|
423
|
+
const result = await hasOrganizationPermission(
|
|
424
|
+
{ prisma: mockPrisma, session: mockSession },
|
|
425
|
+
"org-123",
|
|
426
|
+
"auditLog:view" as Permission,
|
|
427
|
+
);
|
|
428
|
+
expect(result).toBe(true);
|
|
429
|
+
});
|
|
430
|
+
|
|
417
431
|
it("does NOT grant organization:manage (org-admin-only perm)", async () => {
|
|
418
432
|
const result = await hasOrganizationPermission(
|
|
419
433
|
{ prisma: mockPrisma, session: mockSession },
|
|
@@ -444,6 +458,15 @@ describe("RBAC Integration Tests", () => {
|
|
|
444
458
|
expect(result).toBe(true);
|
|
445
459
|
});
|
|
446
460
|
|
|
461
|
+
it("grants auditLog:view (MEMBER team role includes it)", async () => {
|
|
462
|
+
const result = await hasOrganizationPermission(
|
|
463
|
+
{ prisma: mockPrisma, session: mockSession },
|
|
464
|
+
"org-123",
|
|
465
|
+
"auditLog:view" as Permission,
|
|
466
|
+
);
|
|
467
|
+
expect(result).toBe(true);
|
|
468
|
+
});
|
|
469
|
+
|
|
447
470
|
it("does NOT grant gatewayBudgets:delete (MEMBER cannot delete)", async () => {
|
|
448
471
|
const result = await hasOrganizationPermission(
|
|
449
472
|
{ prisma: mockPrisma, session: mockSession },
|
|
@@ -453,6 +476,36 @@ describe("RBAC Integration Tests", () => {
|
|
|
453
476
|
expect(result).toBe(false);
|
|
454
477
|
});
|
|
455
478
|
});
|
|
479
|
+
|
|
480
|
+
describe("when user has only TeamUser VIEWER role (no RoleBindings, no admin)", () => {
|
|
481
|
+
beforeEach(() => {
|
|
482
|
+
mockPrisma.organizationUser.findFirst.mockResolvedValue({
|
|
483
|
+
role: OrganizationUserRole.MEMBER,
|
|
484
|
+
});
|
|
485
|
+
mockPrisma.roleBinding.findMany.mockResolvedValue([]);
|
|
486
|
+
mockPrisma.teamUser.findMany.mockResolvedValue([
|
|
487
|
+
{ role: TeamUserRole.VIEWER, assignedRoleId: null },
|
|
488
|
+
]);
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
it("grants auditLog:view (VIEWER team role includes it)", async () => {
|
|
492
|
+
const result = await hasOrganizationPermission(
|
|
493
|
+
{ prisma: mockPrisma, session: mockSession },
|
|
494
|
+
"org-123",
|
|
495
|
+
"auditLog:view" as Permission,
|
|
496
|
+
);
|
|
497
|
+
expect(result).toBe(true);
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
it("does NOT grant gatewayBudgets:delete (VIEWER cannot delete)", async () => {
|
|
501
|
+
const result = await hasOrganizationPermission(
|
|
502
|
+
{ prisma: mockPrisma, session: mockSession },
|
|
503
|
+
"org-123",
|
|
504
|
+
"gatewayBudgets:delete" as Permission,
|
|
505
|
+
);
|
|
506
|
+
expect(result).toBe(false);
|
|
507
|
+
});
|
|
508
|
+
});
|
|
456
509
|
});
|
|
457
510
|
|
|
458
511
|
describe("Permission Middleware", () => {
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { OrganizationUserRole, TeamUserRole } from "@prisma/client";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
canView,
|
|
5
|
+
getOrganizationRolePermissions,
|
|
6
|
+
Resources,
|
|
7
|
+
teamRoleHasPermission,
|
|
8
|
+
} from "../rbac";
|
|
9
|
+
import {
|
|
10
|
+
getValidActionsForResource,
|
|
11
|
+
orderedResources,
|
|
12
|
+
} from "../../../utils/permissionsConfig";
|
|
13
|
+
|
|
14
|
+
// Companion to rbac.secrets.test.ts — covers the auditLog:view permission
|
|
15
|
+
// added by the gateway audit consolidation. Verifies the perm is granted
|
|
16
|
+
// to all four team roles (so legacy admins falling back through TeamUser
|
|
17
|
+
// keep their /settings/audit-log access) and exposed in the custom-role
|
|
18
|
+
// permission picker UI as a read-only entry.
|
|
19
|
+
|
|
20
|
+
describe("AuditLog resource in RBAC", () => {
|
|
21
|
+
describe("given the Resources enum", () => {
|
|
22
|
+
it("includes an AUDIT_LOG entry with value 'auditLog'", () => {
|
|
23
|
+
expect(Resources.AUDIT_LOG).toBe("auditLog");
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe("given the ADMIN team role", () => {
|
|
28
|
+
it("includes auditLog:view permission", () => {
|
|
29
|
+
expect(
|
|
30
|
+
teamRoleHasPermission(TeamUserRole.ADMIN, "auditLog:view"),
|
|
31
|
+
).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe("given the MEMBER team role", () => {
|
|
36
|
+
it("includes auditLog:view permission", () => {
|
|
37
|
+
expect(
|
|
38
|
+
teamRoleHasPermission(TeamUserRole.MEMBER, "auditLog:view"),
|
|
39
|
+
).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("given the VIEWER team role", () => {
|
|
44
|
+
it("includes auditLog:view permission", () => {
|
|
45
|
+
expect(
|
|
46
|
+
teamRoleHasPermission(TeamUserRole.VIEWER, "auditLog:view"),
|
|
47
|
+
).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("given the CUSTOM fallback team role", () => {
|
|
52
|
+
it("includes auditLog:view permission", () => {
|
|
53
|
+
expect(
|
|
54
|
+
teamRoleHasPermission(TeamUserRole.CUSTOM, "auditLog:view"),
|
|
55
|
+
).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe("given organization role permissions", () => {
|
|
60
|
+
it("does not include any auditLog permissions on the org-role surface", () => {
|
|
61
|
+
// auditLog:view flows through TeamUser / RoleBindings, not via the
|
|
62
|
+
// OrganizationUser role enum (organization:* perms are the only
|
|
63
|
+
// built-in org-role grants).
|
|
64
|
+
const adminPerms = getOrganizationRolePermissions(
|
|
65
|
+
OrganizationUserRole.ADMIN,
|
|
66
|
+
);
|
|
67
|
+
const memberPerms = getOrganizationRolePermissions(
|
|
68
|
+
OrganizationUserRole.MEMBER,
|
|
69
|
+
);
|
|
70
|
+
expect(adminPerms.filter((p) => p.startsWith("auditLog:"))).toHaveLength(
|
|
71
|
+
0,
|
|
72
|
+
);
|
|
73
|
+
expect(memberPerms.filter((p) => p.startsWith("auditLog:"))).toHaveLength(
|
|
74
|
+
0,
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("given the permissions UI configuration", () => {
|
|
80
|
+
it("includes auditLog in orderedResources", () => {
|
|
81
|
+
expect(orderedResources).toContain(Resources.AUDIT_LOG);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("exposes only :view as a valid action (audit log is read-only)", () => {
|
|
85
|
+
const actions = getValidActionsForResource(Resources.AUDIT_LOG);
|
|
86
|
+
expect(actions).toEqual(["view"]);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe("given the helper functions", () => {
|
|
91
|
+
it("confirms canView returns true for all team roles", () => {
|
|
92
|
+
expect(canView(TeamUserRole.ADMIN, Resources.AUDIT_LOG)).toBe(true);
|
|
93
|
+
expect(canView(TeamUserRole.MEMBER, Resources.AUDIT_LOG)).toBe(true);
|
|
94
|
+
expect(canView(TeamUserRole.VIEWER, Resources.AUDIT_LOG)).toBe(true);
|
|
95
|
+
// CUSTOM is the legacy-fallback bucket — covered explicitly so a
|
|
96
|
+
// regression that only breaks CUSTOM doesn't slip past the suite.
|
|
97
|
+
expect(canView(TeamUserRole.CUSTOM, Resources.AUDIT_LOG)).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -55,11 +55,19 @@ export const Resources = {
|
|
|
55
55
|
SECRETS: "secrets",
|
|
56
56
|
PLAYGROUND: "playground",
|
|
57
57
|
OPS: "ops",
|
|
58
|
+
// Platform audit log — covers both the legacy AuditLog stream AND the
|
|
59
|
+
// gateway-resource rows folded into it by the audit consolidation.
|
|
60
|
+
// Lives outside the gateway permission family because it gates a
|
|
61
|
+
// platform settings page (/settings/audit-log), not a gateway sub-page.
|
|
62
|
+
AUDIT_LOG: "auditLog",
|
|
58
63
|
// AI Gateway resources — see specs/ai-gateway/_shared/contract.md §10
|
|
59
64
|
VIRTUAL_KEYS: "virtualKeys",
|
|
60
65
|
GATEWAY_BUDGETS: "gatewayBudgets",
|
|
61
66
|
GATEWAY_PROVIDERS: "gatewayProviders",
|
|
62
67
|
GATEWAY_GUARDRAILS: "gatewayGuardrails",
|
|
68
|
+
// Deprecated (kept for backwards-compat): pre-consolidation perm that
|
|
69
|
+
// gated /[project]/gateway/audit. The page is gone; auditLog:view is
|
|
70
|
+
// the live permission. Safe to drop in a future breaking-change pass.
|
|
63
71
|
GATEWAY_LOGS: "gatewayLogs",
|
|
64
72
|
GATEWAY_USAGE: "gatewayUsage",
|
|
65
73
|
GATEWAY_CACHE_RULES: "gatewayCacheRules",
|
|
@@ -145,6 +153,7 @@ const TEAM_ROLE_PERMISSIONS: Record<TeamUserRole, Permission[]> = {
|
|
|
145
153
|
"gatewayGuardrails:detach",
|
|
146
154
|
"gatewayGuardrails:manage",
|
|
147
155
|
"gatewayLogs:view",
|
|
156
|
+
"auditLog:view",
|
|
148
157
|
"gatewayUsage:view",
|
|
149
158
|
"gatewayCacheRules:view",
|
|
150
159
|
"gatewayCacheRules:create",
|
|
@@ -200,6 +209,7 @@ const TEAM_ROLE_PERMISSIONS: Record<TeamUserRole, Permission[]> = {
|
|
|
200
209
|
"gatewayProviders:view",
|
|
201
210
|
"gatewayGuardrails:view",
|
|
202
211
|
"gatewayLogs:view",
|
|
212
|
+
"auditLog:view",
|
|
203
213
|
"gatewayUsage:view",
|
|
204
214
|
"gatewayCacheRules:view",
|
|
205
215
|
],
|
|
@@ -232,6 +242,7 @@ const TEAM_ROLE_PERMISSIONS: Record<TeamUserRole, Permission[]> = {
|
|
|
232
242
|
"gatewayProviders:view",
|
|
233
243
|
"gatewayGuardrails:view",
|
|
234
244
|
"gatewayLogs:view",
|
|
245
|
+
"auditLog:view",
|
|
235
246
|
"gatewayUsage:view",
|
|
236
247
|
"gatewayCacheRules:view",
|
|
237
248
|
],
|
|
@@ -265,6 +276,7 @@ const TEAM_ROLE_PERMISSIONS: Record<TeamUserRole, Permission[]> = {
|
|
|
265
276
|
"gatewayProviders:view",
|
|
266
277
|
"gatewayGuardrails:view",
|
|
267
278
|
"gatewayLogs:view",
|
|
279
|
+
"auditLog:view",
|
|
268
280
|
"gatewayUsage:view",
|
|
269
281
|
"gatewayCacheRules:view",
|
|
270
282
|
],
|
|
@@ -51,7 +51,6 @@ import { roleBindingRouter } from "./routers/roleBinding";
|
|
|
51
51
|
import { personalAccessTokenRouter } from "./routers/personalAccessToken";
|
|
52
52
|
import { groupRouter } from "./routers/group";
|
|
53
53
|
import { userRouter } from "./routers/user";
|
|
54
|
-
import { gatewayAuditRouter } from "./routers/gatewayAudit";
|
|
55
54
|
import { gatewayBudgetsRouter } from "./routers/gatewayBudgets";
|
|
56
55
|
import { gatewayCacheRulesRouter } from "./routers/gatewayCacheRules";
|
|
57
56
|
import { gatewayUsageRouter } from "./routers/gatewayUsage";
|
|
@@ -118,7 +117,6 @@ const coreRouters = {
|
|
|
118
117
|
gatewayBudgets: gatewayBudgetsRouter,
|
|
119
118
|
gatewayCacheRules: gatewayCacheRulesRouter,
|
|
120
119
|
gatewayUsage: gatewayUsageRouter,
|
|
121
|
-
gatewayAudit: gatewayAuditRouter,
|
|
122
120
|
};
|
|
123
121
|
|
|
124
122
|
const eeRouters = {
|