@langwatch/server 3.1.0-beta.3 → 3.1.0-beta.5

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.
Files changed (119) hide show
  1. package/langwatch/ee/admin/ImpersonationBanner.tsx +61 -0
  2. package/langwatch/ee/admin/ImpersonationSwitchBackMenuItem.tsx +30 -0
  3. package/langwatch/ee/admin/__tests__/ImpersonationBanner.integration.test.tsx +82 -0
  4. package/langwatch/ee/admin/__tests__/impersonation.service.unit.test.ts +231 -0
  5. package/langwatch/ee/admin/backoffice/BackofficeTable.tsx +200 -0
  6. package/langwatch/ee/admin/backoffice/__tests__/adminClient.unit.test.ts +147 -0
  7. package/langwatch/ee/admin/backoffice/__tests__/dateInputToISO.unit.test.ts +42 -0
  8. package/langwatch/ee/admin/backoffice/__tests__/userVisibility.unit.test.ts +174 -0
  9. package/langwatch/ee/admin/backoffice/adminClient.ts +114 -0
  10. package/langwatch/ee/admin/backoffice/resources/OrganizationFeaturesView.tsx +373 -0
  11. package/langwatch/ee/admin/backoffice/resources/OrganizationsView.tsx +677 -0
  12. package/langwatch/ee/admin/backoffice/resources/ProjectsView.tsx +647 -0
  13. package/langwatch/ee/admin/backoffice/resources/SubscriptionsView.tsx +628 -0
  14. package/langwatch/ee/admin/backoffice/resources/UsersView.tsx +556 -0
  15. package/langwatch/ee/admin/backoffice/useAdminResource.ts +104 -0
  16. package/langwatch/ee/admin/backoffice/userVisibility.ts +105 -0
  17. package/langwatch/ee/admin/impersonation.service.ts +170 -0
  18. package/langwatch/ee/admin/isAdmin.ts +9 -0
  19. package/langwatch/ee/admin/routes/admin.ts +531 -0
  20. package/langwatch/ee/admin/safeSelects.ts +64 -0
  21. package/langwatch/ee/billing/__tests__/customerService.unit.test.ts +183 -0
  22. package/langwatch/ee/billing/__tests__/growthSeatEvent.unit.test.ts +213 -0
  23. package/langwatch/ee/billing/__tests__/licensePurchaseHandler.unit.test.ts +250 -0
  24. package/langwatch/ee/billing/__tests__/notification.service.unit.test.ts +768 -0
  25. package/langwatch/ee/billing/__tests__/planLimits.unit.test.ts +19 -0
  26. package/langwatch/ee/billing/__tests__/planProvider.unit.test.ts +440 -0
  27. package/langwatch/ee/billing/__tests__/planTypes.unit.test.ts +32 -0
  28. package/langwatch/ee/billing/__tests__/pricing.unit.test.ts +54 -0
  29. package/langwatch/ee/billing/__tests__/seatEventSubscription.unit.test.ts +717 -0
  30. package/langwatch/ee/billing/__tests__/stripe.integration.test.ts +344 -0
  31. package/langwatch/ee/billing/__tests__/stripePrices.types.unit.test.ts +27 -0
  32. package/langwatch/ee/billing/__tests__/stripePricesLoader.unit.test.ts +72 -0
  33. package/langwatch/ee/billing/__tests__/subscription.service.unit.test.ts +730 -0
  34. package/langwatch/ee/billing/__tests__/subscriptionItemCalculator.unit.test.ts +176 -0
  35. package/langwatch/ee/billing/__tests__/usage-limit.service.unit.test.ts +706 -0
  36. package/langwatch/ee/billing/__tests__/usageReportingService.integration.test.ts +421 -0
  37. package/langwatch/ee/billing/__tests__/usageReportingService.unit.test.ts +515 -0
  38. package/langwatch/ee/billing/__tests__/webhookService.unit.test.ts +958 -0
  39. package/langwatch/ee/billing/currencyRouter.ts +18 -0
  40. package/langwatch/ee/billing/errors.ts +129 -0
  41. package/langwatch/ee/billing/index.ts +67 -0
  42. package/langwatch/ee/billing/middleware.ts +17 -0
  43. package/langwatch/ee/billing/notifications/notification.service.ts +651 -0
  44. package/langwatch/ee/billing/notifications/repositories/notification.repository.ts +51 -0
  45. package/langwatch/ee/billing/notifications/types.ts +9 -0
  46. package/langwatch/ee/billing/notifications/usage-limit.service.ts +622 -0
  47. package/langwatch/ee/billing/nurturing/hooks/activityTracking.ts +90 -0
  48. package/langwatch/ee/billing/nurturing/hooks/activityTracking.unit.test.ts +237 -0
  49. package/langwatch/ee/billing/nurturing/hooks/featureAdoption.ts +120 -0
  50. package/langwatch/ee/billing/nurturing/hooks/featureAdoption.unit.test.ts +324 -0
  51. package/langwatch/ee/billing/nurturing/hooks/index.ts +17 -0
  52. package/langwatch/ee/billing/nurturing/hooks/productInterest.ts +68 -0
  53. package/langwatch/ee/billing/nurturing/hooks/productInterest.unit.test.ts +138 -0
  54. package/langwatch/ee/billing/nurturing/hooks/promptCreation.integration.test.ts +288 -0
  55. package/langwatch/ee/billing/nurturing/hooks/promptCreation.ts +131 -0
  56. package/langwatch/ee/billing/nurturing/hooks/promptCreation.unit.test.ts +134 -0
  57. package/langwatch/ee/billing/nurturing/hooks/signupIdentification.ts +101 -0
  58. package/langwatch/ee/billing/nurturing/hooks/signupIdentification.unit.test.ts +317 -0
  59. package/langwatch/ee/billing/nurturing/hooks/subscriptionSync.ts +49 -0
  60. package/langwatch/ee/billing/nurturing/hooks/subscriptionSync.unit.test.ts +170 -0
  61. package/langwatch/ee/billing/nurturing/hooks/userSync.ts +143 -0
  62. package/langwatch/ee/billing/nurturing/hooks/userSync.unit.test.ts +307 -0
  63. package/langwatch/ee/billing/nurturing/nurturing.service.ts +179 -0
  64. package/langwatch/ee/billing/nurturing/nurturing.service.unit.test.ts +266 -0
  65. package/langwatch/ee/billing/nurturing/nurturing.service.wiring.unit.test.ts +109 -0
  66. package/langwatch/ee/billing/nurturing/types.ts +125 -0
  67. package/langwatch/ee/billing/planLimits.ts +190 -0
  68. package/langwatch/ee/billing/planProvider.ts +119 -0
  69. package/langwatch/ee/billing/planTypes.ts +53 -0
  70. package/langwatch/ee/billing/pricing.ts +57 -0
  71. package/langwatch/ee/billing/services/billableEventsQuery.ts +248 -0
  72. package/langwatch/ee/billing/services/customerService.ts +90 -0
  73. package/langwatch/ee/billing/services/licensePurchaseHandler.ts +73 -0
  74. package/langwatch/ee/billing/services/seatEventSubscription.ts +351 -0
  75. package/langwatch/ee/billing/services/seatSyncService.ts +34 -0
  76. package/langwatch/ee/billing/services/subscription.repository.ts +203 -0
  77. package/langwatch/ee/billing/services/subscription.service.ts +549 -0
  78. package/langwatch/ee/billing/services/subscriptionItemCalculator.ts +249 -0
  79. package/langwatch/ee/billing/services/usageReportingService.ts +301 -0
  80. package/langwatch/ee/billing/services/webhookService.ts +858 -0
  81. package/langwatch/ee/billing/stripe/stripeCatalog.json +1781 -0
  82. package/langwatch/ee/billing/stripe/stripeClient.ts +13 -0
  83. package/langwatch/ee/billing/stripe/stripePriceCatalog.ts +70 -0
  84. package/langwatch/ee/billing/stripe/stripePrices.types.ts +118 -0
  85. package/langwatch/ee/billing/subscriptionRouter.ts +202 -0
  86. package/langwatch/ee/billing/types.ts +102 -0
  87. package/langwatch/ee/billing/utils/currency.ts +99 -0
  88. package/langwatch/ee/billing/utils/growthSeatEvent.ts +137 -0
  89. package/langwatch/ee/licensing/__tests__/constants.unit.test.ts +56 -0
  90. package/langwatch/ee/licensing/__tests__/defaults.unit.test.ts +192 -0
  91. package/langwatch/ee/licensing/__tests__/fixtures/testKeys.ts +86 -0
  92. package/langwatch/ee/licensing/__tests__/fixtures/testLicenses.ts +92 -0
  93. package/langwatch/ee/licensing/__tests__/licenseGenerationService.unit.test.ts +232 -0
  94. package/langwatch/ee/licensing/__tests__/licenseHandler.integration.test.ts +419 -0
  95. package/langwatch/ee/licensing/__tests__/planMapping.unit.test.ts +195 -0
  96. package/langwatch/ee/licensing/__tests__/planTemplates.unit.test.ts +193 -0
  97. package/langwatch/ee/licensing/__tests__/signing.unit.test.ts +164 -0
  98. package/langwatch/ee/licensing/__tests__/validation.unit.test.ts +281 -0
  99. package/langwatch/ee/licensing/client.ts +29 -0
  100. package/langwatch/ee/licensing/constants.ts +195 -0
  101. package/langwatch/ee/licensing/defaults.ts +55 -0
  102. package/langwatch/ee/licensing/errors.ts +11 -0
  103. package/langwatch/ee/licensing/index.ts +52 -0
  104. package/langwatch/ee/licensing/licenseGenerationService.ts +87 -0
  105. package/langwatch/ee/licensing/licenseHandler.ts +308 -0
  106. package/langwatch/ee/licensing/planInfo.ts +46 -0
  107. package/langwatch/ee/licensing/planMapping.ts +37 -0
  108. package/langwatch/ee/licensing/planTemplates.ts +109 -0
  109. package/langwatch/ee/licensing/server.ts +43 -0
  110. package/langwatch/ee/licensing/signing.ts +43 -0
  111. package/langwatch/ee/licensing/types.ts +156 -0
  112. package/langwatch/ee/licensing/validation.ts +107 -0
  113. package/langwatch/ee/managed-providers/ManagedModelProviderAlert.tsx +29 -0
  114. package/langwatch/ee/managed-providers/managedBedrockConfig.ts +226 -0
  115. package/langwatch/ee/saas/ExtraFooterComponents.tsx +169 -0
  116. package/langwatch/package.json +1 -1
  117. package/langwatch_nlp/uv.lock +179 -5
  118. package/package.json +1 -1
  119. package/packages/server/dist/cli.cjs +192 -142
@@ -0,0 +1,647 @@
1
+ import {
2
+ Badge,
3
+ Box,
4
+ Button,
5
+ Field,
6
+ Heading,
7
+ HStack,
8
+ Input,
9
+ NativeSelect,
10
+ Separator,
11
+ Spacer,
12
+ Table,
13
+ Text,
14
+ VStack,
15
+ } from "@chakra-ui/react";
16
+ import {
17
+ PIIRedactionLevel,
18
+ ProjectSensitiveDataVisibilityLevel,
19
+ } from "@prisma/client";
20
+ import { MoreVertical, Pencil } from "lucide-react";
21
+ import { useEffect, useRef, useState } from "react";
22
+ import { useDebounce } from "use-debounce";
23
+ import { useRouter } from "~/utils/compat/next-router";
24
+ import { Drawer } from "~/components/ui/drawer";
25
+ import { Menu } from "~/components/ui/menu";
26
+ import { Switch } from "~/components/ui/switch";
27
+ import { toaster } from "~/components/ui/toaster";
28
+ import {
29
+ BackofficeTable,
30
+ EmptyCell,
31
+ formatDate,
32
+ } from "../BackofficeTable";
33
+ import {
34
+ useAdminList,
35
+ useAdminUpdate,
36
+ } from "../useAdminResource";
37
+
38
+ /**
39
+ * Read-facing Project shape — does NOT include s3Endpoint / s3AccessKeyId /
40
+ * s3SecretAccessKey / s3Bucket. Project-level S3 overrides are credentials
41
+ * and the admin Hono route strips them from every list / getOne response
42
+ * (see ee/admin/safeSelects.ts). The edit drawer accepts new values,
43
+ * write-only.
44
+ */
45
+ interface AdminProject {
46
+ id: string;
47
+ name: string;
48
+ slug: string;
49
+ apiKey: string;
50
+ teamId: string;
51
+ language: string | null;
52
+ framework: string | null;
53
+ firstMessage: boolean;
54
+ integrated: boolean;
55
+ userLinkTemplate: string | null;
56
+ piiRedactionLevel: PIIRedactionLevel;
57
+ capturedInputVisibility: ProjectSensitiveDataVisibilityLevel;
58
+ capturedOutputVisibility: ProjectSensitiveDataVisibilityLevel;
59
+ traceSharingEnabled: boolean;
60
+ defaultModel: string | null;
61
+ topicClusteringModel: string | null;
62
+ embeddingsModel: string | null;
63
+ archivedAt: string | null;
64
+ createdAt: string;
65
+ }
66
+
67
+ const PAGE_SIZE = 25;
68
+
69
+ export default function ProjectsView() {
70
+ const router = useRouter();
71
+ // Deep-link support: /ops/backoffice/projects?q=<projectId> — seed the
72
+ // search input once from the URL so chips on the Users table drop the user
73
+ // straight onto the matching row.
74
+ const initialQueryRef = useRef<string>(
75
+ typeof router.query.q === "string" ? router.query.q : "",
76
+ );
77
+ const [page, setPage] = useState(1);
78
+ const [search, setSearch] = useState(initialQueryRef.current);
79
+ const [debouncedSearch] = useDebounce(search, 300);
80
+ const [editing, setEditing] = useState<AdminProject | null>(null);
81
+
82
+ const list = useAdminList<AdminProject>("project", {
83
+ pagination: { page, perPage: PAGE_SIZE },
84
+ sort: { field: "createdAt", order: "DESC" },
85
+ filter: debouncedSearch ? { query: debouncedSearch } : {},
86
+ });
87
+
88
+ return (
89
+ <>
90
+ <BackofficeTable
91
+ title="Projects"
92
+ searchValue={search}
93
+ onSearchChange={(v) => {
94
+ setSearch(v);
95
+ setPage(1);
96
+ }}
97
+ searchPlaceholder="Search by ID, name, or slug"
98
+ isLoading={list.isLoading}
99
+ isFetching={list.isFetching}
100
+ error={list.error}
101
+ pagination={{
102
+ page,
103
+ perPage: PAGE_SIZE,
104
+ total: list.data?.total ?? 0,
105
+ onPageChange: setPage,
106
+ }}
107
+ >
108
+ <Table.Root variant="line" size="md" width="full">
109
+ <Table.Header>
110
+ <Table.Row>
111
+ <Table.ColumnHeader>ID</Table.ColumnHeader>
112
+ <Table.ColumnHeader>Name</Table.ColumnHeader>
113
+ <Table.ColumnHeader>Slug</Table.ColumnHeader>
114
+ <Table.ColumnHeader>Language</Table.ColumnHeader>
115
+ <Table.ColumnHeader>Framework</Table.ColumnHeader>
116
+ <Table.ColumnHeader>PII</Table.ColumnHeader>
117
+ <Table.ColumnHeader>Status</Table.ColumnHeader>
118
+ <Table.ColumnHeader>Created</Table.ColumnHeader>
119
+ <Table.ColumnHeader width="60px" textAlign="right" />
120
+ </Table.Row>
121
+ </Table.Header>
122
+ <Table.Body>
123
+ {list.data?.data.length === 0 && (
124
+ <Table.Row>
125
+ <Table.Cell colSpan={9}>
126
+ <Text color="fg.muted" textAlign="center" paddingY={6}>
127
+ No projects match your search.
128
+ </Text>
129
+ </Table.Cell>
130
+ </Table.Row>
131
+ )}
132
+ {list.data?.data.map((project) => (
133
+ <Table.Row key={project.id}>
134
+ <Table.Cell fontSize="xs" color="fg.muted">
135
+ {project.id}
136
+ </Table.Cell>
137
+ <Table.Cell>{project.name}</Table.Cell>
138
+ <Table.Cell>{project.slug}</Table.Cell>
139
+ <Table.Cell>{project.language ?? <EmptyCell />}</Table.Cell>
140
+ <Table.Cell>{project.framework ?? <EmptyCell />}</Table.Cell>
141
+ <Table.Cell>
142
+ <Badge size="sm" variant="subtle">
143
+ {project.piiRedactionLevel}
144
+ </Badge>
145
+ </Table.Cell>
146
+ <Table.Cell>
147
+ {project.archivedAt ? (
148
+ <Badge size="sm" colorPalette="gray">
149
+ Archived
150
+ </Badge>
151
+ ) : project.integrated ? (
152
+ <Badge size="sm" colorPalette="green">
153
+ Integrated
154
+ </Badge>
155
+ ) : (
156
+ <Badge size="sm" colorPalette="yellow">
157
+ Pending
158
+ </Badge>
159
+ )}
160
+ </Table.Cell>
161
+ <Table.Cell>{formatDate(project.createdAt)}</Table.Cell>
162
+ <Table.Cell textAlign="right">
163
+ <Box
164
+ width="full"
165
+ height="full"
166
+ display="flex"
167
+ justifyContent="end"
168
+ >
169
+ <Menu.Root>
170
+ <Menu.Trigger>
171
+ <MoreVertical size={16} />
172
+ </Menu.Trigger>
173
+ <Menu.Content>
174
+ <Menu.Item
175
+ value="edit"
176
+ onClick={() => setEditing(project)}
177
+ >
178
+ <Pencil size={16} />
179
+ Edit
180
+ </Menu.Item>
181
+ </Menu.Content>
182
+ </Menu.Root>
183
+ </Box>
184
+ </Table.Cell>
185
+ </Table.Row>
186
+ ))}
187
+ </Table.Body>
188
+ </Table.Root>
189
+ </BackofficeTable>
190
+
191
+ <ProjectEditDrawer
192
+ project={editing}
193
+ onClose={() => setEditing(null)}
194
+ />
195
+ </>
196
+ );
197
+ }
198
+
199
+ interface FormState {
200
+ name: string;
201
+ slug: string;
202
+ language: string;
203
+ framework: string;
204
+ firstMessage: boolean;
205
+ integrated: boolean;
206
+ userLinkTemplate: string;
207
+ piiRedactionLevel: PIIRedactionLevel;
208
+ capturedInputVisibility: ProjectSensitiveDataVisibilityLevel;
209
+ capturedOutputVisibility: ProjectSensitiveDataVisibilityLevel;
210
+ traceSharingEnabled: boolean;
211
+ defaultModel: string;
212
+ topicClusteringModel: string;
213
+ embeddingsModel: string;
214
+ s3Endpoint: string;
215
+ s3AccessKeyId: string;
216
+ s3SecretAccessKey: string;
217
+ s3Bucket: string;
218
+ archive: boolean;
219
+ }
220
+
221
+ function nullIfEmpty(raw: string): string | null {
222
+ return raw.trim() === "" ? null : raw;
223
+ }
224
+
225
+ function ProjectEditDrawer({
226
+ project,
227
+ onClose,
228
+ }: {
229
+ project: AdminProject | null;
230
+ onClose: () => void;
231
+ }) {
232
+ const update = useAdminUpdate<AdminProject>("project");
233
+ const [form, setForm] = useState<FormState | null>(null);
234
+
235
+ useEffect(() => {
236
+ if (!project) return;
237
+ setForm({
238
+ name: project.name,
239
+ slug: project.slug,
240
+ language: project.language ?? "",
241
+ framework: project.framework ?? "",
242
+ firstMessage: !!project.firstMessage,
243
+ integrated: !!project.integrated,
244
+ userLinkTemplate: project.userLinkTemplate ?? "",
245
+ piiRedactionLevel: project.piiRedactionLevel,
246
+ capturedInputVisibility: project.capturedInputVisibility,
247
+ capturedOutputVisibility: project.capturedOutputVisibility,
248
+ traceSharingEnabled: !!project.traceSharingEnabled,
249
+ defaultModel: project.defaultModel ?? "",
250
+ topicClusteringModel: project.topicClusteringModel ?? "",
251
+ embeddingsModel: project.embeddingsModel ?? "",
252
+ // S3 credentials are write-only: the server strips them from
253
+ // read payloads (ee/admin/safeSelects.ts), so the form always
254
+ // starts empty. Typing a value replaces the stored secret;
255
+ // leaving it blank keeps the current one untouched.
256
+ s3Endpoint: "",
257
+ s3AccessKeyId: "",
258
+ s3SecretAccessKey: "",
259
+ s3Bucket: "",
260
+ archive: !!project.archivedAt,
261
+ });
262
+ }, [project]);
263
+
264
+ const setField = <K extends keyof FormState>(key: K, value: FormState[K]) =>
265
+ setForm((prev) => (prev ? { ...prev, [key]: value } : prev));
266
+
267
+ const handleSave = () => {
268
+ if (!project || !form) return;
269
+ const data: Record<string, unknown> = {};
270
+
271
+ if (form.name !== project.name) data.name = form.name;
272
+ if (form.slug !== project.slug) data.slug = form.slug;
273
+ if (form.language !== (project.language ?? ""))
274
+ data.language = form.language;
275
+ if (form.framework !== (project.framework ?? ""))
276
+ data.framework = form.framework;
277
+ if (form.firstMessage !== !!project.firstMessage)
278
+ data.firstMessage = form.firstMessage;
279
+ if (form.integrated !== !!project.integrated)
280
+ data.integrated = form.integrated;
281
+ if (form.userLinkTemplate !== (project.userLinkTemplate ?? ""))
282
+ data.userLinkTemplate = nullIfEmpty(form.userLinkTemplate);
283
+ if (form.piiRedactionLevel !== project.piiRedactionLevel)
284
+ data.piiRedactionLevel = form.piiRedactionLevel;
285
+ if (form.capturedInputVisibility !== project.capturedInputVisibility)
286
+ data.capturedInputVisibility = form.capturedInputVisibility;
287
+ if (form.capturedOutputVisibility !== project.capturedOutputVisibility)
288
+ data.capturedOutputVisibility = form.capturedOutputVisibility;
289
+ if (form.traceSharingEnabled !== !!project.traceSharingEnabled)
290
+ data.traceSharingEnabled = form.traceSharingEnabled;
291
+ if (form.defaultModel !== (project.defaultModel ?? ""))
292
+ data.defaultModel = nullIfEmpty(form.defaultModel);
293
+ if (form.topicClusteringModel !== (project.topicClusteringModel ?? ""))
294
+ data.topicClusteringModel = nullIfEmpty(form.topicClusteringModel);
295
+ if (form.embeddingsModel !== (project.embeddingsModel ?? ""))
296
+ data.embeddingsModel = nullIfEmpty(form.embeddingsModel);
297
+ // Write-only credentials — only forward fields the user typed into;
298
+ // an empty input means "leave the stored secret alone". Nothing we
299
+ // received from the server can be compared against because the
300
+ // server never sends these fields back.
301
+ if (form.s3Endpoint.trim() !== "") data.s3Endpoint = form.s3Endpoint;
302
+ if (form.s3AccessKeyId.trim() !== "")
303
+ data.s3AccessKeyId = form.s3AccessKeyId;
304
+ if (form.s3SecretAccessKey.trim() !== "")
305
+ data.s3SecretAccessKey = form.s3SecretAccessKey;
306
+ if (form.s3Bucket.trim() !== "") data.s3Bucket = form.s3Bucket;
307
+ const currentlyArchived = !!project.archivedAt;
308
+ if (form.archive !== currentlyArchived) {
309
+ data.archivedAt = form.archive
310
+ ? new Date().toISOString()
311
+ : null;
312
+ }
313
+
314
+ if (Object.keys(data).length === 0) {
315
+ onClose();
316
+ return;
317
+ }
318
+ update.mutate(
319
+ { id: project.id, data },
320
+ {
321
+ onSuccess: () => {
322
+ toaster.create({
323
+ title: "Project updated",
324
+ type: "success",
325
+ duration: 3000,
326
+ meta: { closable: true },
327
+ });
328
+ onClose();
329
+ },
330
+ onError: (err) =>
331
+ toaster.create({
332
+ title: "Update failed",
333
+ description: err.message,
334
+ type: "error",
335
+ duration: 5000,
336
+ meta: { closable: true },
337
+ }),
338
+ },
339
+ );
340
+ };
341
+
342
+ return (
343
+ <Drawer.Root
344
+ open={!!project}
345
+ onOpenChange={({ open }) => {
346
+ if (!open) onClose();
347
+ }}
348
+ size="md"
349
+ >
350
+ <Drawer.Content>
351
+ <Drawer.Header>
352
+ <Drawer.Title>Edit Project</Drawer.Title>
353
+ </Drawer.Header>
354
+ <Drawer.CloseTrigger />
355
+ <Drawer.Body>
356
+ {project && form && (
357
+ <VStack gap={4} align="stretch">
358
+ <SectionHeading>Identity</SectionHeading>
359
+ <Field.Root>
360
+ <Field.Label>Name</Field.Label>
361
+ <Input
362
+ value={form.name}
363
+ onChange={(e) => setField("name", e.target.value)}
364
+ />
365
+ </Field.Root>
366
+ <Field.Root>
367
+ <Field.Label>Slug</Field.Label>
368
+ <Input
369
+ value={form.slug}
370
+ onChange={(e) => setField("slug", e.target.value)}
371
+ />
372
+ <Field.HelperText>
373
+ URL-safe identifier. Changing this can break existing links.
374
+ </Field.HelperText>
375
+ </Field.Root>
376
+ <HStack gap={3}>
377
+ <Field.Root>
378
+ <Field.Label>Language</Field.Label>
379
+ <Input
380
+ value={form.language}
381
+ onChange={(e) => setField("language", e.target.value)}
382
+ />
383
+ </Field.Root>
384
+ <Field.Root>
385
+ <Field.Label>Framework</Field.Label>
386
+ <Input
387
+ value={form.framework}
388
+ onChange={(e) => setField("framework", e.target.value)}
389
+ />
390
+ </Field.Root>
391
+ </HStack>
392
+
393
+ <SectionHeading>Onboarding flags</SectionHeading>
394
+ <ToggleRow
395
+ label="First message received"
396
+ hint="Flipped by the collector on the first ingested trace."
397
+ checked={form.firstMessage}
398
+ onChange={(v) => setField("firstMessage", v)}
399
+ />
400
+ <ToggleRow
401
+ label="Integrated"
402
+ hint="Tenant-visible ‘setup complete’ state."
403
+ checked={form.integrated}
404
+ onChange={(v) => setField("integrated", v)}
405
+ />
406
+
407
+ <SectionHeading>Privacy</SectionHeading>
408
+ <Field.Root>
409
+ <Field.Label>PII redaction level</Field.Label>
410
+ <EnumSelect
411
+ value={form.piiRedactionLevel}
412
+ options={Object.values(PIIRedactionLevel)}
413
+ onChange={(v) =>
414
+ setField("piiRedactionLevel", v as PIIRedactionLevel)
415
+ }
416
+ />
417
+ </Field.Root>
418
+ <Field.Root>
419
+ <Field.Label>Captured input visibility</Field.Label>
420
+ <EnumSelect
421
+ value={form.capturedInputVisibility}
422
+ options={Object.values(ProjectSensitiveDataVisibilityLevel)}
423
+ onChange={(v) =>
424
+ setField(
425
+ "capturedInputVisibility",
426
+ v as ProjectSensitiveDataVisibilityLevel,
427
+ )
428
+ }
429
+ />
430
+ </Field.Root>
431
+ <Field.Root>
432
+ <Field.Label>Captured output visibility</Field.Label>
433
+ <EnumSelect
434
+ value={form.capturedOutputVisibility}
435
+ options={Object.values(ProjectSensitiveDataVisibilityLevel)}
436
+ onChange={(v) =>
437
+ setField(
438
+ "capturedOutputVisibility",
439
+ v as ProjectSensitiveDataVisibilityLevel,
440
+ )
441
+ }
442
+ />
443
+ </Field.Root>
444
+ <ToggleRow
445
+ label="Trace sharing enabled"
446
+ hint="Allow operators to generate public share links for traces."
447
+ checked={form.traceSharingEnabled}
448
+ onChange={(v) => setField("traceSharingEnabled", v)}
449
+ />
450
+
451
+ <SectionHeading>Integrations</SectionHeading>
452
+ <Field.Root>
453
+ <Field.Label>User link template</Field.Label>
454
+ <Input
455
+ value={form.userLinkTemplate}
456
+ onChange={(e) =>
457
+ setField("userLinkTemplate", e.target.value)
458
+ }
459
+ placeholder="e.g. https://app.acme.com/users/{{userId}}"
460
+ />
461
+ </Field.Root>
462
+ <Field.Root>
463
+ <Field.Label>Default model</Field.Label>
464
+ <Input
465
+ value={form.defaultModel}
466
+ onChange={(e) => setField("defaultModel", e.target.value)}
467
+ placeholder="e.g. openai/gpt-5-mini"
468
+ />
469
+ </Field.Root>
470
+ <Field.Root>
471
+ <Field.Label>Topic clustering model</Field.Label>
472
+ <Input
473
+ value={form.topicClusteringModel}
474
+ onChange={(e) =>
475
+ setField("topicClusteringModel", e.target.value)
476
+ }
477
+ />
478
+ </Field.Root>
479
+ <Field.Root>
480
+ <Field.Label>Embeddings model</Field.Label>
481
+ <Input
482
+ value={form.embeddingsModel}
483
+ onChange={(e) => setField("embeddingsModel", e.target.value)}
484
+ />
485
+ </Field.Root>
486
+
487
+ <SectionHeading>Project S3</SectionHeading>
488
+ <Text fontSize="xs" color="fg.muted">
489
+ Credentials below are write-only — the server never reads them
490
+ back. Leave blank to keep the stored value; type to replace.
491
+ </Text>
492
+ <Field.Root>
493
+ <Field.Label>Endpoint</Field.Label>
494
+ <Input
495
+ type="url"
496
+ value={form.s3Endpoint}
497
+ onChange={(e) => setField("s3Endpoint", e.target.value)}
498
+ placeholder="Leave blank to keep current"
499
+ />
500
+ </Field.Root>
501
+ <Field.Root>
502
+ <Field.Label>Bucket</Field.Label>
503
+ <Input
504
+ value={form.s3Bucket}
505
+ onChange={(e) => setField("s3Bucket", e.target.value)}
506
+ placeholder="Leave blank to keep current"
507
+ />
508
+ </Field.Root>
509
+ <Field.Root>
510
+ <Field.Label>Access key ID</Field.Label>
511
+ <Input
512
+ type="password"
513
+ value={form.s3AccessKeyId}
514
+ onChange={(e) => setField("s3AccessKeyId", e.target.value)}
515
+ placeholder="Leave blank to keep current"
516
+ autoComplete="new-password"
517
+ />
518
+ </Field.Root>
519
+ <Field.Root>
520
+ <Field.Label>Secret access key</Field.Label>
521
+ <Input
522
+ type="password"
523
+ value={form.s3SecretAccessKey}
524
+ onChange={(e) =>
525
+ setField("s3SecretAccessKey", e.target.value)
526
+ }
527
+ placeholder="Leave blank to keep current"
528
+ autoComplete="new-password"
529
+ />
530
+ </Field.Root>
531
+
532
+ <SectionHeading>Lifecycle</SectionHeading>
533
+ <ToggleRow
534
+ label="Archived"
535
+ hint="Hides the project from the UI and stops it from accruing limits."
536
+ checked={form.archive}
537
+ onChange={(v) => setField("archive", v)}
538
+ />
539
+
540
+ <Separator my={2} />
541
+ <VStack align="start" gap={0}>
542
+ <Text fontSize="xs" color="fg.muted">
543
+ Project ID: {project.id}
544
+ </Text>
545
+ <Text fontSize="xs" color="fg.muted">
546
+ Team: {project.teamId}
547
+ </Text>
548
+ <Text fontSize="xs" color="fg.muted">
549
+ API key: {project.apiKey}
550
+ </Text>
551
+ {project.archivedAt && (
552
+ <Text fontSize="xs" color="fg.muted">
553
+ Archived at: {formatDate(project.archivedAt)}
554
+ </Text>
555
+ )}
556
+ </VStack>
557
+ </VStack>
558
+ )}
559
+ </Drawer.Body>
560
+ <Drawer.Footer>
561
+ <HStack width="full">
562
+ <Spacer />
563
+ <Button variant="ghost" onClick={onClose}>
564
+ Cancel
565
+ </Button>
566
+ <Button loading={update.isPending} onClick={handleSave}>
567
+ Save
568
+ </Button>
569
+ </HStack>
570
+ </Drawer.Footer>
571
+ </Drawer.Content>
572
+ </Drawer.Root>
573
+ );
574
+ }
575
+
576
+ function SectionHeading({ children }: { children: React.ReactNode }) {
577
+ return (
578
+ <Heading
579
+ as="h3"
580
+ size="xs"
581
+ color="fg.muted"
582
+ textTransform="uppercase"
583
+ letterSpacing="wider"
584
+ pt={2}
585
+ >
586
+ {children}
587
+ </Heading>
588
+ );
589
+ }
590
+
591
+ function EnumSelect({
592
+ value,
593
+ options,
594
+ onChange,
595
+ }: {
596
+ value: string;
597
+ options: readonly string[];
598
+ onChange: (value: string) => void;
599
+ }) {
600
+ return (
601
+ <NativeSelect.Root size="sm" width="full">
602
+ <NativeSelect.Field
603
+ value={value}
604
+ onChange={(e) => onChange(e.target.value)}
605
+ >
606
+ {options.map((opt) => (
607
+ <option key={opt} value={opt}>
608
+ {opt}
609
+ </option>
610
+ ))}
611
+ </NativeSelect.Field>
612
+ <NativeSelect.Indicator />
613
+ </NativeSelect.Root>
614
+ );
615
+ }
616
+
617
+ function ToggleRow({
618
+ label,
619
+ hint,
620
+ checked,
621
+ onChange,
622
+ }: {
623
+ label: string;
624
+ hint?: string;
625
+ checked: boolean;
626
+ onChange: (v: boolean) => void;
627
+ }) {
628
+ return (
629
+ <Field.Root>
630
+ <HStack width="full">
631
+ <VStack align="start" gap={0}>
632
+ <Field.Label>{label}</Field.Label>
633
+ {hint && (
634
+ <Text fontSize="xs" color="fg.muted">
635
+ {hint}
636
+ </Text>
637
+ )}
638
+ </VStack>
639
+ <Spacer />
640
+ <Switch
641
+ checked={checked}
642
+ onCheckedChange={(e) => onChange(e.checked)}
643
+ />
644
+ </HStack>
645
+ </Field.Root>
646
+ );
647
+ }