From 5736c3cf4f3b4a523dd12f55a9e702d7344e1ace Mon Sep 17 00:00:00 2001
From: israel <israeliyanda5@gmail.com>
Date: Mon, 13 Apr 2026 01:02:41 +0100
Subject: [PATCH 1/4] refactor(platform): overhaul settings UI with grouped
 layouts and enhanced panels

Restructure governance settings from flat tabs to grouped sections (content & models, policies & limits, security & monitoring). Add provider edit panel with description and default model selection. Enhance MCP server cards with inline edit/delete actions and detail panel menu. Add team detail dialog with member list. Add audit log export functionality. Extract reusable SelectTriggerButton component. Update Tabs component with actions slot and flex layout. Fix password input autocomplete attribute.
---
 examples/providers/openrouter.secrets.json    |   19 +-
 .../app/components/ui/forms/input.test.tsx    |    2 +-
 .../app/components/ui/forms/input.tsx         |    2 +-
 .../app/components/ui/navigation/tabs.tsx     |   42 +-
 .../chat/components/message-bubble.tsx        |    2 +-
 .../account/components/account-form.tsx       |    5 +
 .../audit-logs/components/audit-log-table.tsx |   63 -
 .../governance/components/budget-editor.tsx   |  293 +-
 .../components/default-model-editor.tsx       |  357 +-
 .../components/feature-flags-editor.tsx       |  281 +-
 .../components/model-access-editor.tsx        |  245 +-
 .../governance/components/pii-config.tsx      |   68 +-
 .../components/retention-editor.tsx           |  132 +-
 .../components/select-trigger-button.tsx      |   23 +
 .../components/system-prompt-editor.tsx       |    4 +-
 .../components/upload-policy-editor.tsx       |  148 +-
 .../__tests__/mcp-server-card.test.tsx        |   53 +-
 .../__tests__/mcp-server-panel.test.tsx       |    6 +-
 .../components/mcp-server-card.tsx            |  150 +-
 .../components/mcp-server-form.tsx            |   38 +-
 .../components/mcp-server-panel.tsx           |  160 +-
 .../mcp-servers/components/mcp-servers.tsx    |   94 +-
 .../components/member-add-dialog.tsx          |    1 +
 .../components/member-edit-dialog.tsx         |    1 +
 .../components/provider-edit-panel.tsx        |   77 +-
 .../teams/components/team-detail-dialog.tsx   |  148 +
 .../teams/components/team-row-actions.tsx     |   22 +-
 .../settings/teams/components/teams-table.tsx |   23 +-
 .../teams/hooks/use-teams-table-config.tsx    |   13 +-
 .../dashboard/$id/settings/governance.tsx     |  150 +-
 .../routes/dashboard/$id/settings/logs.tsx    |  143 +-
 .../$id/settings/providers/$providerName.tsx  |  741 +-
 services/platform/convex/_generated/api.d.ts  | 9138 ++++++++++++++++-
 services/platform/messages/de.json            |   13 +-
 services/platform/messages/en.json            |   14 +-
 35 files changed, 11186 insertions(+), 1485 deletions(-)
 create mode 100644 services/platform/app/features/settings/governance/components/select-trigger-button.tsx
 create mode 100644 services/platform/app/features/settings/teams/components/team-detail-dialog.tsx

diff --git a/examples/providers/openrouter.secrets.json b/examples/providers/openrouter.secrets.json
index e58ac25c9c..e7b0ebbddc 100644
--- a/examples/providers/openrouter.secrets.json
+++ b/examples/providers/openrouter.secrets.json
@@ -1,20 +1,15 @@
 {
-	"apiKey": "ENC[AES256_GCM,data:MJKxyEKDQFk2Y+E3R7eK13LwIxO9FQ6TxAYc93NlRc56As9XMaLTx0CNfM82MyoHyQCduKgCf3a8RK9r2bWVgo8NnVnd2YzGOA==,iv:OqTfslCeZbiYkEQqAI/Jj0NLuJW1h0hdZPus8Sel3cU=,tag:yaBSdC8+gmPdEcfLmECXOg==,type:str]",
+	"apiKey": "ENC[AES256_GCM,data:Os9IU5ZlUhe7QWMhqrhsVIFNKVD2FzszIkHGOb9l8Oa8z57AZUek+XK7qM//OyY60sMQQjVkbnygU7175lgO05lXlWRLqWiksA==,iv:2rpxkfK022BbwBCDwhu2YvlbF+HXv+KPaLPu6dQWX/k=,tag:gqMQcSCc9Q2wGJaer5V3jw==,type:str]",
 	"sops": {
-		"kms": null,
-		"gcp_kms": null,
-		"azure_kv": null,
-		"hc_vault": null,
 		"age": [
 			{
-				"recipient": "age1xsc5y9x0dref9kd6fwv2356pw2zl5s7gp5v6jam9h4q7mv6fm9aqumvqhj",
-				"enc": "-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBPYnV2WjVHR3ZFSGRlYmxR\ncnUybXVRcWNrVFkrMVlnTkZ1bFhNRmk3WjBVCmtSZ2RsbFZCdWY5dk94RlhhU1dN\nQnZnejFvYW4vVTBOUWVBUHJRaEovQmcKLS0tIENlVUJmTjFDcXZjWjV4RitnZHlv\nN09UeFo5Y2xnZXRwQ3RabEc2QVgyckUK7u0Avecl9B628T56Np6gGxQ1+yCSRjXa\n8HBlTjMa4g1OR8d4isfZ9VE+lETdNaVlultd9F1GWEvgv/p7WxpeUg==\n-----END AGE ENCRYPTED FILE-----\n"
+				"recipient": "age18ylfcfvf9we4rc5hpza6n9tvhwuw55jfun9wdpd5uhux5rs3qf4q95y2y4",
+				"enc": "-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSByUU1FMndnUDAzeTZySW1x\nMFJwNEhuYXF4UlZZWGRQaS85SjNkbmVpMG44CjVhTEh4c1BNZ1VXZXN3R2cxeFBt\nVjB6Sm5BOXc1NFdCcGMzS1BEWDJHeWMKLS0tIEFUekUrOHFmMSsraFdMOVU4d3FJ\nTzdwWWtiNytmTVNRQW5MTExRVEk3MmcKHmSVxvF3Nz/yMGZ3lFY+oDcryUdoOT7/\nmxnY/U4ZX3sCkLphYdUVuAA6nqstfzVn57X1ND8vqaFXPn2lhVc00Q==\n-----END AGE ENCRYPTED FILE-----\n"
 			}
 		],
-		"lastmodified": "2026-04-05T11:39:10Z",
-		"mac": "ENC[AES256_GCM,data:2OYyLhDFsCM/spi9pp6bUXwuShtuqumEv7brGMrcRMdziaX8tQTnEL8Kcd774ne3BFDg+sfAnX2SH7e66qUxXd1qMXJWNN96lkjStc422rilpXWvq29RDKjatuAf7qSZoF0rWFNK9sAeQ0J+6bHytQ5FT3DXnS0SoXozMxCvz3A=,iv:8fx48QGvx8Nudqo1ByyWnPsebKn6BpAHQzw5rvj7zdg=,tag:21dyPzSJgJNpnStSvxs+yA==,type:str]",
-		"pgp": null,
+		"lastmodified": "2026-04-12T18:34:34Z",
+		"mac": "ENC[AES256_GCM,data:dTQzeY02n+I8wUXpfhlHBAQ8EZgMmPo1lMKZFtvbyEl9VWgYc9Q9+Bde0g6hmpXJNKqNx4VNhiQV6NFl0oyQQNpaN6yAu9Ka1gs64eymLUwuiBigSvSoiBOoICGaHx9rNhdgu55vU3xCGpp1C4lwGdj6lpKYJ7Pefdc0ZS1rnLo=,iv:ZBoTH20q8nPOp5H11WQiiH/VrKMao2RcaBiu9TeSVx4=,tag:HiqFbmIQMpO5Id0S7ls6Gw==,type:str]",
 		"unencrypted_suffix": "_unencrypted",
-		"version": "3.9.4"
+		"version": "3.12.2"
 	}
-}
\ No newline at end of file
+}
diff --git a/services/platform/app/components/ui/forms/input.test.tsx b/services/platform/app/components/ui/forms/input.test.tsx
index bfda670d55..dd1e97d2fa 100644
--- a/services/platform/app/components/ui/forms/input.test.tsx
+++ b/services/platform/app/components/ui/forms/input.test.tsx
@@ -188,7 +188,7 @@ describe('Input', () => {
     it('sets autocomplete for password', () => {
       render(<Input type="password" label="Password" />);
       const input = screen.getByLabelText('Password');
-      expect(input).toHaveAttribute('autocomplete', 'current-password');
+      expect(input).toHaveAttribute('autocomplete', 'off');
     });
 
     it('allows custom autocomplete', () => {
diff --git a/services/platform/app/components/ui/forms/input.tsx b/services/platform/app/components/ui/forms/input.tsx
index ad7a89dac1..9b26207dc6 100644
--- a/services/platform/app/components/ui/forms/input.tsx
+++ b/services/platform/app/components/ui/forms/input.tsx
@@ -82,7 +82,7 @@ export const Input = forwardRef<HTMLInputElement, BaseProps>(
     const [showShake, setShowShake] = useState(false);
     const inputType = isPassword ? (show ? 'text' : 'password') : type;
     const resolvedAutoComplete =
-      autoComplete ?? (isPassword ? 'current-password' : undefined);
+      autoComplete ?? (isPassword ? 'off' : undefined);
     const hasError = !!errorMessage;
     const showInvalid = hasError || !!isInvalid;
     const describedBy =
diff --git a/services/platform/app/components/ui/navigation/tabs.tsx b/services/platform/app/components/ui/navigation/tabs.tsx
index 8251587864..1806dad77e 100644
--- a/services/platform/app/components/ui/navigation/tabs.tsx
+++ b/services/platform/app/components/ui/navigation/tabs.tsx
@@ -19,6 +19,8 @@ interface TabsProps {
   onValueChange?: (value: string) => void;
   className?: string;
   listClassName?: string;
+  /** Optional actions rendered to the right of the tab list */
+  actions?: ReactNode;
 }
 
 export function Tabs({
@@ -28,6 +30,7 @@ export function Tabs({
   onValueChange,
   className,
   listClassName,
+  actions,
 }: TabsProps) {
   return (
     <TabsPrimitive.Root
@@ -36,30 +39,33 @@ export function Tabs({
       onValueChange={onValueChange}
       className={className}
     >
-      <TabsPrimitive.List
-        className={cn(
-          'scrollbar-hide inline-flex items-center overflow-x-auto bg-muted p-1 text-muted-foreground rounded-lg',
-          listClassName,
-        )}
-      >
-        {items.map((item) => (
-          <TabsPrimitive.Trigger
-            key={item.value}
-            value={item.value}
-            disabled={item.disabled}
-            className="ring-offset-background focus-visible:ring-ring data-[state=active]:bg-background data-[state=active]:text-foreground inline-flex items-center justify-center rounded-md px-3 py-1.5 text-sm font-medium whitespace-nowrap transition-all focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm"
-          >
-            {item.label}
-          </TabsPrimitive.Trigger>
-        ))}
-      </TabsPrimitive.List>
+      <div className="flex items-center justify-between gap-4">
+        <TabsPrimitive.List
+          className={cn(
+            'scrollbar-hide inline-flex items-center overflow-x-auto bg-muted p-1 text-muted-foreground rounded-lg',
+            listClassName,
+          )}
+        >
+          {items.map((item) => (
+            <TabsPrimitive.Trigger
+              key={item.value}
+              value={item.value}
+              disabled={item.disabled}
+              className="ring-offset-background focus-visible:ring-ring data-[state=active]:bg-background data-[state=active]:text-foreground inline-flex items-center justify-center rounded-md px-3 py-1.5 text-sm font-medium whitespace-nowrap transition-all focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm"
+            >
+              {item.label}
+            </TabsPrimitive.Trigger>
+          ))}
+        </TabsPrimitive.List>
+        {actions && <div className="shrink-0">{actions}</div>}
+      </div>
       {items.map(
         (item) =>
           item.content && (
             <TabsPrimitive.Content
               key={item.value}
               value={item.value}
-              className="ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none"
+              className="ring-offset-background focus-visible:ring-ring mt-2 flex min-h-0 flex-1 flex-col focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none"
             >
               {item.content}
             </TabsPrimitive.Content>
diff --git a/services/platform/app/features/chat/components/message-bubble.tsx b/services/platform/app/features/chat/components/message-bubble.tsx
index 4df3a3446b..71a84e5797 100644
--- a/services/platform/app/features/chat/components/message-bubble.tsx
+++ b/services/platform/app/features/chat/components/message-bubble.tsx
@@ -419,7 +419,7 @@ function MessageBubbleComponent({
           </div>
         )}
         {!isUser && !isAssistantStreaming && !!displayContent && (
-          <div className="flex items-center pt-2">
+          <div className="flex items-start pt-2">
             <Tooltip
               content={isCopied ? t('actions.copied') : t('actions.copy')}
               side="bottom"
diff --git a/services/platform/app/features/settings/account/components/account-form.tsx b/services/platform/app/features/settings/account/components/account-form.tsx
index 20b8328644..7c8d30c628 100644
--- a/services/platform/app/features/settings/account/components/account-form.tsx
+++ b/services/platform/app/features/settings/account/components/account-form.tsx
@@ -270,6 +270,7 @@ function ChangePasswordDialog({ open, onOpenChange }: PasswordDialogProps) {
       <Input
         id="current-password"
         type="password"
+        autoComplete="current-password"
         label={tAuth('changePassword.currentPassword')}
         placeholder={tAuth('changePassword.placeholder.current')}
         disabled={isSubmitting}
@@ -281,6 +282,7 @@ function ChangePasswordDialog({ open, onOpenChange }: PasswordDialogProps) {
         <Input
           id="new-password"
           type="password"
+          autoComplete="new-password"
           label={tAuth('changePassword.newPassword')}
           placeholder={tAuth('changePassword.placeholder.new')}
           disabled={isSubmitting}
@@ -298,6 +300,7 @@ function ChangePasswordDialog({ open, onOpenChange }: PasswordDialogProps) {
       <Input
         id="confirm-password"
         type="password"
+        autoComplete="new-password"
         label={tAuth('changePassword.confirmPassword')}
         placeholder={tAuth('changePassword.placeholder.confirm')}
         disabled={isSubmitting}
@@ -398,6 +401,7 @@ function SetPasswordDialog({ open, onOpenChange }: PasswordDialogProps) {
         <Input
           id="new-password"
           type="password"
+          autoComplete="new-password"
           label={tAuth('setPassword.newPassword')}
           placeholder={tAuth('changePassword.placeholder.new')}
           disabled={isSubmitting}
@@ -415,6 +419,7 @@ function SetPasswordDialog({ open, onOpenChange }: PasswordDialogProps) {
       <Input
         id="confirm-password"
         type="password"
+        autoComplete="new-password"
         label={tAuth('setPassword.confirmPassword')}
         placeholder={tAuth('changePassword.placeholder.confirm')}
         disabled={isSubmitting}
diff --git a/services/platform/app/features/settings/audit-logs/components/audit-log-table.tsx b/services/platform/app/features/settings/audit-logs/components/audit-log-table.tsx
index 59e579b963..5c4d92f143 100644
--- a/services/platform/app/features/settings/audit-logs/components/audit-log-table.tsx
+++ b/services/platform/app/features/settings/audit-logs/components/audit-log-table.tsx
@@ -7,13 +7,9 @@ import { useCallback, useMemo, useState } from 'react';
 import { DataTable } from '@/app/components/ui/data-table/data-table';
 import { Dialog } from '@/app/components/ui/dialog/dialog';
 import { Stack } from '@/app/components/ui/layout/layout';
-import { Button } from '@/app/components/ui/primitives/button';
 import { Text } from '@/app/components/ui/typography/text';
-import { useConvexAction } from '@/app/hooks/use-convex-action';
 import { useFormatDate } from '@/app/hooks/use-format-date';
 import { useListPage } from '@/app/hooks/use-list-page';
-import { useToast } from '@/app/hooks/use-toast';
-import { api } from '@/convex/_generated/api';
 import type { Doc } from '@/convex/_generated/dataModel';
 import { useT } from '@/lib/i18n/client';
 import { cn } from '@/lib/utils/cn';
@@ -26,7 +22,6 @@ interface AuditLogTableProps {
   organizationId: string;
   paginatedResult: UsePaginatedQueryResult<AuditLog>;
   category?: string;
-  isAdmin?: boolean;
   userEmailMap?: Map<string, string>;
 }
 
@@ -34,13 +29,11 @@ export function AuditLogTable({
   organizationId,
   paginatedResult,
   category,
-  isAdmin: isAdminUser = false,
   userEmailMap,
 }: AuditLogTableProps) {
   const navigate = useNavigate();
   const { formatDate } = useFormatDate();
   const { t } = useT('settings');
-  const { toast } = useToast();
   const [selectedLog, setSelectedLog] = useState<AuditLog | null>(null);
 
   const resolveEmail = useCallback(
@@ -53,35 +46,6 @@ export function AuditLogTable({
     resolveEmail,
   });
 
-  const exportAction = useConvexAction(api.audit_logs.actions.requestExport, {
-    onSuccess: (data) => {
-      if (data.url) {
-        window.open(data.url, '_blank', 'noopener,noreferrer');
-      }
-      toast({
-        title: t('logs.audit.export.complete'),
-        description: data.fileName,
-      });
-    },
-    onError: () => {
-      toast({
-        title: t('logs.audit.export.error'),
-        variant: 'destructive',
-      });
-    },
-  });
-
-  const handleExport = useCallback(
-    (format: 'csv' | 'json') => {
-      exportAction.mutate({
-        organizationId,
-        format,
-        filter: category ? { category } : undefined,
-      });
-    },
-    [organizationId, category, exportAction],
-  );
-
   const handleCategoryChange = useCallback(
     (values: string[]) => {
       void navigate({
@@ -146,33 +110,6 @@ export function AuditLogTable({
 
   return (
     <>
-      {isAdminUser && (
-        <div className="mb-4 flex items-center gap-2">
-          <Button
-            variant="secondary"
-            size="sm"
-            onClick={() => handleExport('csv')}
-            disabled={exportAction.isPending}
-            aria-label={t('logs.audit.export.csvLabel')}
-          >
-            {exportAction.isPending
-              ? t('logs.audit.export.inProgress')
-              : t('logs.audit.export.csv')}
-          </Button>
-          <Button
-            variant="secondary"
-            size="sm"
-            onClick={() => handleExport('json')}
-            disabled={exportAction.isPending}
-            aria-label={t('logs.audit.export.jsonLabel')}
-          >
-            {exportAction.isPending
-              ? t('logs.audit.export.inProgress')
-              : t('logs.audit.export.json')}
-          </Button>
-        </div>
-      )}
-
       <DataTable
         columns={columns}
         caption={t('logs.audit.tableCaption')}
diff --git a/services/platform/app/features/settings/governance/components/budget-editor.tsx b/services/platform/app/features/settings/governance/components/budget-editor.tsx
index fc9073a0f0..54e1bc2764 100644
--- a/services/platform/app/features/settings/governance/components/budget-editor.tsx
+++ b/services/platform/app/features/settings/governance/components/budget-editor.tsx
@@ -22,10 +22,12 @@ import {
   type BudgetConfig,
   type BudgetRule,
 } from '@/lib/shared/schemas/governance';
+import { cn } from '@/lib/utils/cn';
 import { isRecord } from '@/lib/utils/type-guards';
 
 import { useUpsertGovernancePolicy } from '../hooks/mutations';
 import { useGovernancePolicy } from '../hooks/queries';
+import { SelectTriggerButton } from './select-trigger-button';
 
 interface BudgetEditorProps {
   organizationId: string;
@@ -176,20 +178,15 @@ function RuleDialog({
                 emptyText={t('budgets.noUsersFound')}
                 aria-label={t('budgets.selectUserAriaLabel')}
                 trigger={
-                  <button
-                    type="button"
+                  <SelectTriggerButton
                     disabled={cannotManage}
-                    className="border-input ring-offset-background flex h-8 w-full items-center justify-between rounded-md border bg-transparent px-3 text-sm disabled:cursor-not-allowed disabled:opacity-50"
+                    hasValue={!!draft.scopeId}
                   >
-                    <span
-                      className={draft.scopeId ? '' : 'text-muted-foreground'}
-                    >
-                      {draft.scopeId
-                        ? (memberOptions.find((o) => o.value === draft.scopeId)
-                            ?.label ?? draft.scopeId)
-                        : t('budgets.selectUser')}
-                    </span>
-                  </button>
+                    {draft.scopeId
+                      ? (memberOptions.find((o) => o.value === draft.scopeId)
+                          ?.label ?? draft.scopeId)
+                      : t('budgets.selectUser')}
+                  </SelectTriggerButton>
                 }
               />
             </div>
@@ -208,20 +205,15 @@ function RuleDialog({
                 emptyText={t('budgets.noTeamsFound')}
                 aria-label={t('budgets.selectTeamAriaLabel')}
                 trigger={
-                  <button
-                    type="button"
+                  <SelectTriggerButton
                     disabled={cannotManage}
-                    className="border-input ring-offset-background flex h-8 w-full items-center justify-between rounded-md border bg-transparent px-3 text-sm disabled:cursor-not-allowed disabled:opacity-50"
+                    hasValue={!!draft.scopeId}
                   >
-                    <span
-                      className={draft.scopeId ? '' : 'text-muted-foreground'}
-                    >
-                      {draft.scopeId
-                        ? (teamOptions.find((o) => o.value === draft.scopeId)
-                            ?.label ?? draft.scopeId)
-                        : t('budgets.selectTeam')}
-                    </span>
-                  </button>
+                    {draft.scopeId
+                      ? (teamOptions.find((o) => o.value === draft.scopeId)
+                          ?.label ?? draft.scopeId)
+                      : t('budgets.selectTeam')}
+                  </SelectTriggerButton>
                 }
               />
             </div>
@@ -506,132 +498,139 @@ export function BudgetEditor({ organizationId }: BudgetEditorProps) {
         />
       }
     >
-      <Stack gap={6}>
-        <Text variant="muted" className="text-xs">
-          {t('budgets.overrideHint')}
-        </Text>
-
-        <Stack gap={3}>
-          {rules.length > 0 ? (
-            <div className="overflow-x-auto">
-              <table className="w-full text-sm">
-                <caption className="sr-only">{t('budgets.title')}</caption>
-                <thead>
-                  <tr className="border-border border-b">
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-left font-medium"
-                    >
-                      {t('budgets.scope')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-left font-medium"
-                    >
-                      {t('budgets.target')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-left font-medium"
-                    >
-                      {t('budgets.period')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-right font-medium"
-                    >
-                      {t('budgets.tokenLimit')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-right font-medium"
-                    >
-                      {t('budgets.maxCost')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-right font-medium"
-                    >
-                      {t('budgets.maxRequests')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-right font-medium"
-                    >
-                      {t('budgets.actions')}
-                    </th>
-                  </tr>
-                </thead>
-                <tbody>
-                  {rules.map((rule, index) => (
-                    <tr key={index} className="border-border border-b">
-                      <td className="px-3 py-2 capitalize">{rule.scope}</td>
-                      <td className="px-3 py-2">{resolveTarget(rule)}</td>
-                      <td className="px-3 py-2 capitalize">{rule.period}</td>
-                      <td className="px-3 py-2 text-right">
-                        {rule.maxTokens != null
-                          ? rule.maxTokens.toLocaleString()
-                          : '\u2014'}
-                      </td>
-                      <td className="px-3 py-2 text-right">
-                        {rule.maxCostCents != null
-                          ? formatCost(rule.maxCostCents)
-                          : '\u2014'}
-                      </td>
-                      <td className="px-3 py-2 text-right">
-                        {rule.maxRequests != null
-                          ? rule.maxRequests.toLocaleString()
-                          : '\u2014'}
-                      </td>
-                      <td className="px-3 py-2 text-right">
-                        <HStack gap={1} justify="end">
-                          <Button
-                            variant="ghost"
-                            size="icon"
-                            onClick={() => openEditDialog(index)}
-                            disabled={cannotManage}
-                            aria-label={t('budgets.editRuleAriaLabel', {
-                              index: index + 1,
-                            })}
-                          >
-                            <Pencil className="size-4" />
-                          </Button>
-                          <Button
-                            variant="ghost"
-                            size="icon"
-                            onClick={() => removeRule(index)}
-                            disabled={cannotManage}
-                            aria-label={t('budgets.removeRuleAriaLabel', {
-                              index: index + 1,
-                            })}
-                          >
-                            <Trash2 className="size-4" />
-                          </Button>
-                        </HStack>
-                      </td>
+      <div
+        className={cn(
+          'transition-opacity duration-200',
+          !enabled && 'pointer-events-none opacity-50',
+        )}
+      >
+        <Stack gap={6}>
+          <Text variant="muted" className="text-xs">
+            {t('budgets.overrideHint')}
+          </Text>
+
+          <Stack gap={3}>
+            {rules.length > 0 ? (
+              <div className="overflow-x-auto">
+                <table className="w-full text-sm">
+                  <caption className="sr-only">{t('budgets.title')}</caption>
+                  <thead>
+                    <tr className="border-border border-b">
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-left font-medium"
+                      >
+                        {t('budgets.scope')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-left font-medium"
+                      >
+                        {t('budgets.target')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-left font-medium"
+                      >
+                        {t('budgets.period')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-right font-medium"
+                      >
+                        {t('budgets.tokenLimit')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-right font-medium"
+                      >
+                        {t('budgets.maxCost')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-right font-medium"
+                      >
+                        {t('budgets.maxRequests')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-right font-medium"
+                      >
+                        {t('budgets.actions')}
+                      </th>
                     </tr>
-                  ))}
-                </tbody>
-              </table>
-            </div>
-          ) : (
-            <Text variant="muted" className="text-sm">
-              {t('budgets.noRules')}
-            </Text>
-          )}
+                  </thead>
+                  <tbody>
+                    {rules.map((rule, index) => (
+                      <tr key={index} className="border-border border-b">
+                        <td className="px-3 py-2 capitalize">{rule.scope}</td>
+                        <td className="px-3 py-2">{resolveTarget(rule)}</td>
+                        <td className="px-3 py-2 capitalize">{rule.period}</td>
+                        <td className="px-3 py-2 text-right">
+                          {rule.maxTokens != null
+                            ? rule.maxTokens.toLocaleString()
+                            : '\u2014'}
+                        </td>
+                        <td className="px-3 py-2 text-right">
+                          {rule.maxCostCents != null
+                            ? formatCost(rule.maxCostCents)
+                            : '\u2014'}
+                        </td>
+                        <td className="px-3 py-2 text-right">
+                          {rule.maxRequests != null
+                            ? rule.maxRequests.toLocaleString()
+                            : '\u2014'}
+                        </td>
+                        <td className="px-3 py-2 text-right">
+                          <HStack gap={1} justify="end">
+                            <Button
+                              variant="ghost"
+                              size="icon"
+                              onClick={() => openEditDialog(index)}
+                              disabled={cannotManage}
+                              aria-label={t('budgets.editRuleAriaLabel', {
+                                index: index + 1,
+                              })}
+                            >
+                              <Pencil className="size-4" />
+                            </Button>
+                            <Button
+                              variant="ghost"
+                              size="icon"
+                              onClick={() => removeRule(index)}
+                              disabled={cannotManage}
+                              aria-label={t('budgets.removeRuleAriaLabel', {
+                                index: index + 1,
+                              })}
+                            >
+                              <Trash2 className="size-4" />
+                            </Button>
+                          </HStack>
+                        </td>
+                      </tr>
+                    ))}
+                  </tbody>
+                </table>
+              </div>
+            ) : (
+              <Text variant="muted" className="text-sm">
+                {t('budgets.noRules')}
+              </Text>
+            )}
 
-          <Button
-            variant="secondary"
-            size="sm"
-            onClick={openAddDialog}
-            disabled={cannotManage}
-            className="self-start"
-          >
-            <Plus className="mr-1.5 size-4" />
-            {t('budgets.addRule')}
-          </Button>
+            <Button
+              variant="secondary"
+              size="sm"
+              onClick={openAddDialog}
+              disabled={cannotManage}
+              className="self-start"
+            >
+              <Plus className="mr-1.5 size-4" />
+              {t('budgets.addRule')}
+            </Button>
+          </Stack>
         </Stack>
-      </Stack>
+      </div>
 
       <RuleDialog
         open={dialogOpen}
diff --git a/services/platform/app/features/settings/governance/components/default-model-editor.tsx b/services/platform/app/features/settings/governance/components/default-model-editor.tsx
index be275c476e..50c669eb63 100644
--- a/services/platform/app/features/settings/governance/components/default-model-editor.tsx
+++ b/services/platform/app/features/settings/governance/components/default-model-editor.tsx
@@ -21,10 +21,12 @@ import {
   type DefaultModelsConfig,
   type DefaultModelRule,
 } from '@/lib/shared/schemas/governance';
+import { cn } from '@/lib/utils/cn';
 import { isRecord } from '@/lib/utils/type-guards';
 
 import { useUpsertGovernancePolicy } from '../hooks/mutations';
 import { useGovernancePolicy } from '../hooks/queries';
+import { SelectTriggerButton } from './select-trigger-button';
 
 interface DefaultModelEditorProps {
   organizationId: string;
@@ -163,8 +165,8 @@ function RuleDialog({
       submitText={t('defaultModels.confirm')}
     >
       <Stack gap={4}>
-        <HStack gap={3} wrap>
-          <div className="w-40">
+        <HStack gap={3} align="end">
+          <div className="flex-1">
             <Select
               label={t('defaultModels.scope')}
               options={SCOPE_OPTIONS}
@@ -180,7 +182,7 @@ function RuleDialog({
           </div>
 
           {draft.scope === 'role' && (
-            <div className="w-40">
+            <div className="flex-1">
               <Select
                 label={t('defaultModels.role')}
                 options={ROLE_OPTIONS}
@@ -193,7 +195,7 @@ function RuleDialog({
           )}
 
           {draft.scope === 'team' && (
-            <div className="w-56">
+            <div className="flex-1">
               <Text className="mb-1 text-xs font-medium">
                 {t('defaultModels.target')}
               </Text>
@@ -205,90 +207,70 @@ function RuleDialog({
                 emptyText={t('defaultModels.noTeamsFound')}
                 aria-label={t('defaultModels.target')}
                 trigger={
-                  <button
-                    type="button"
+                  <SelectTriggerButton
                     disabled={cannotManage}
-                    className="border-input ring-offset-background flex h-8 w-full items-center justify-between rounded-md border bg-transparent px-3 text-sm disabled:cursor-not-allowed disabled:opacity-50"
+                    hasValue={!!draft.scopeId}
                   >
-                    <span
-                      className={draft.scopeId ? '' : 'text-muted-foreground'}
-                    >
-                      {draft.scopeId
-                        ? (teamOptions.find((o) => o.value === draft.scopeId)
-                            ?.label ?? draft.scopeId)
-                        : t('defaultModels.selectTeam')}
-                    </span>
-                  </button>
+                    {draft.scopeId
+                      ? (teamOptions.find((o) => o.value === draft.scopeId)
+                          ?.label ?? draft.scopeId)
+                      : t('defaultModels.selectTeam')}
+                  </SelectTriggerButton>
                 }
               />
             </div>
           )}
         </HStack>
 
-        <HStack gap={3} wrap>
-          <div className="w-56">
-            <Text className="mb-1 text-xs font-medium">
-              {t('defaultModels.provider')}
-            </Text>
-            <SearchableSelect
-              value={draft.providerName || null}
-              onValueChange={(value) => updateDraft({ providerName: value })}
-              options={providerOptions}
-              searchPlaceholder={t('defaultModels.searchProviders')}
-              emptyText={t('defaultModels.noProvidersFound')}
-              aria-label={t('defaultModels.provider')}
-              trigger={
-                <button
-                  type="button"
-                  disabled={cannotManage}
-                  className="border-input ring-offset-background flex h-8 w-full items-center justify-between rounded-md border bg-transparent px-3 text-sm disabled:cursor-not-allowed disabled:opacity-50"
-                >
-                  <span
-                    className={
-                      draft.providerName ? '' : 'text-muted-foreground'
-                    }
-                  >
-                    {draft.providerName
-                      ? (providerOptions.find(
-                          (o) => o.value === draft.providerName,
-                        )?.label ?? draft.providerName)
-                      : t('defaultModels.selectProvider')}
-                  </span>
-                </button>
-              }
-            />
-          </div>
-
-          <div className="w-56">
-            <Text className="mb-1 text-xs font-medium">
-              {t('defaultModels.model')}
-            </Text>
-            <SearchableSelect
-              value={draft.modelId || null}
-              onValueChange={(value) => updateDraft({ modelId: value })}
-              options={modelOptions}
-              searchPlaceholder={t('defaultModels.searchModels')}
-              emptyText={t('defaultModels.noModelsFound')}
-              aria-label={t('defaultModels.model')}
-              trigger={
-                <button
-                  type="button"
-                  disabled={cannotManage || !draft.providerName}
-                  className="border-input ring-offset-background flex h-8 w-full items-center justify-between rounded-md border bg-transparent px-3 text-sm disabled:cursor-not-allowed disabled:opacity-50"
-                >
-                  <span
-                    className={draft.modelId ? '' : 'text-muted-foreground'}
-                  >
-                    {draft.modelId
-                      ? (modelOptions.find((o) => o.value === draft.modelId)
-                          ?.label ?? draft.modelId)
-                      : t('defaultModels.selectModel')}
-                  </span>
-                </button>
-              }
-            />
-          </div>
-        </HStack>
+        <div>
+          <Text className="mb-1 text-xs font-medium">
+            {t('defaultModels.provider')}
+          </Text>
+          <SearchableSelect
+            value={draft.providerName || null}
+            onValueChange={(value) => updateDraft({ providerName: value })}
+            options={providerOptions}
+            searchPlaceholder={t('defaultModels.searchProviders')}
+            emptyText={t('defaultModels.noProvidersFound')}
+            aria-label={t('defaultModels.provider')}
+            trigger={
+              <SelectTriggerButton
+                disabled={cannotManage}
+                hasValue={!!draft.providerName}
+              >
+                {draft.providerName
+                  ? (providerOptions.find((o) => o.value === draft.providerName)
+                      ?.label ?? draft.providerName)
+                  : t('defaultModels.selectProvider')}
+              </SelectTriggerButton>
+            }
+          />
+        </div>
+
+        <div>
+          <Text className="mb-1 text-xs font-medium">
+            {t('defaultModels.model')}
+          </Text>
+          <SearchableSelect
+            value={draft.modelId || null}
+            onValueChange={(value) => updateDraft({ modelId: value })}
+            options={modelOptions}
+            searchPlaceholder={t('defaultModels.searchModels')}
+            emptyText={t('defaultModels.noModelsFound')}
+            aria-label={t('defaultModels.model')}
+            trigger={
+              <SelectTriggerButton
+                disabled={cannotManage || !draft.providerName}
+                hasValue={!!draft.modelId}
+              >
+                {draft.modelId
+                  ? (modelOptions.find((o) => o.value === draft.modelId)
+                      ?.label ?? draft.modelId)
+                  : t('defaultModels.selectModel')}
+              </SelectTriggerButton>
+            }
+          />
+        </div>
       </Stack>
     </FormDialog>
   );
@@ -415,7 +397,15 @@ export function DefaultModelEditor({
     (rule: DefaultModelRule) => {
       let newRules: DefaultModelRule[];
       if (editingIndex === null) {
-        newRules = [...rules, rule];
+        // Replace any existing rule with the same scope+target instead of duplicating
+        const existingIndex = rules.findIndex(
+          (r) => r.scope === rule.scope && r.scopeId === rule.scopeId,
+        );
+        if (existingIndex !== -1) {
+          newRules = rules.map((r, i) => (i === existingIndex ? rule : r));
+        } else {
+          newRules = [...rules, rule];
+        }
       } else {
         newRules = rules.map((r, i) => (i === editingIndex ? rule : r));
       }
@@ -436,7 +426,11 @@ export function DefaultModelEditor({
           );
         }
         case 'role':
-          return rule.scopeId ?? '\u2014';
+          return (
+            ROLE_OPTIONS.find((o) => o.value === rule.scopeId)?.label ??
+            rule.scopeId ??
+            '\u2014'
+          );
         case 'default':
           return t('defaultModels.allUsers');
         default:
@@ -483,104 +477,113 @@ export function DefaultModelEditor({
         />
       }
     >
-      <Stack gap={6}>
-        <Stack gap={3}>
-          {rules.length > 0 ? (
-            <div className="overflow-x-auto">
-              <table className="w-full text-sm">
-                <caption className="sr-only">
-                  {t('defaultModels.title')}
-                </caption>
-                <thead>
-                  <tr className="border-border border-b">
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-left font-medium"
-                    >
-                      {t('defaultModels.scope')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-left font-medium"
-                    >
-                      {t('defaultModels.target')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-left font-medium"
-                    >
-                      {t('defaultModels.provider')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-left font-medium"
-                    >
-                      {t('defaultModels.model')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-right font-medium"
-                    >
-                      {t('defaultModels.actions')}
-                    </th>
-                  </tr>
-                </thead>
-                <tbody>
-                  {rules.map((rule, index) => (
-                    <tr key={index} className="border-border border-b">
-                      <td className="px-3 py-2 capitalize">{rule.scope}</td>
-                      <td className="px-3 py-2">{resolveTarget(rule)}</td>
-                      <td className="px-3 py-2">{resolveProviderName(rule)}</td>
-                      <td className="px-3 py-2">{resolveModelName(rule)}</td>
-                      <td className="px-3 py-2 text-right">
-                        <HStack gap={1} justify="end">
-                          <Button
-                            variant="ghost"
-                            size="icon"
-                            onClick={() => openEditDialog(index)}
-                            disabled={cannotManage}
-                            aria-label={t('defaultModels.editRule', {
-                              index: index + 1,
-                            })}
-                          >
-                            <Pencil className="size-4" />
-                          </Button>
-                          <Button
-                            variant="ghost"
-                            size="icon"
-                            onClick={() => removeRule(index)}
-                            disabled={cannotManage}
-                            aria-label={t('defaultModels.removeRule', {
-                              index: index + 1,
-                            })}
-                          >
-                            <Trash2 className="size-4" />
-                          </Button>
-                        </HStack>
-                      </td>
+      <div
+        className={cn(
+          'transition-opacity duration-200',
+          !enabled && 'pointer-events-none opacity-50',
+        )}
+      >
+        <Stack gap={6}>
+          <Stack gap={3}>
+            {rules.length > 0 ? (
+              <div className="overflow-x-auto">
+                <table className="w-full text-sm">
+                  <caption className="sr-only">
+                    {t('defaultModels.title')}
+                  </caption>
+                  <thead>
+                    <tr className="border-border border-b">
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-left font-medium"
+                      >
+                        {t('defaultModels.scope')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-left font-medium"
+                      >
+                        {t('defaultModels.target')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-left font-medium"
+                      >
+                        {t('defaultModels.provider')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-left font-medium"
+                      >
+                        {t('defaultModels.model')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-right font-medium"
+                      >
+                        {t('defaultModels.actions')}
+                      </th>
                     </tr>
-                  ))}
-                </tbody>
-              </table>
-            </div>
-          ) : (
-            <Text variant="muted" className="text-sm">
-              {t('defaultModels.noRules')}
-            </Text>
-          )}
+                  </thead>
+                  <tbody>
+                    {rules.map((rule, index) => (
+                      <tr key={index} className="border-border border-b">
+                        <td className="px-3 py-2 capitalize">{rule.scope}</td>
+                        <td className="px-3 py-2">{resolveTarget(rule)}</td>
+                        <td className="px-3 py-2">
+                          {resolveProviderName(rule)}
+                        </td>
+                        <td className="px-3 py-2">{resolveModelName(rule)}</td>
+                        <td className="px-3 py-2 text-right">
+                          <HStack gap={1} justify="end">
+                            <Button
+                              variant="ghost"
+                              size="icon"
+                              onClick={() => openEditDialog(index)}
+                              disabled={cannotManage}
+                              aria-label={t('defaultModels.editRule', {
+                                index: index + 1,
+                              })}
+                            >
+                              <Pencil className="size-4" />
+                            </Button>
+                            <Button
+                              variant="ghost"
+                              size="icon"
+                              onClick={() => removeRule(index)}
+                              disabled={cannotManage}
+                              aria-label={t('defaultModels.removeRule', {
+                                index: index + 1,
+                              })}
+                            >
+                              <Trash2 className="size-4" />
+                            </Button>
+                          </HStack>
+                        </td>
+                      </tr>
+                    ))}
+                  </tbody>
+                </table>
+              </div>
+            ) : (
+              <Text variant="muted" className="text-sm">
+                {t('defaultModels.noRules')}
+              </Text>
+            )}
 
-          <Button
-            variant="secondary"
-            size="sm"
-            onClick={openAddDialog}
-            disabled={cannotManage}
-            className="self-start"
-          >
-            <Plus className="mr-1.5 size-4" />
-            {t('defaultModels.addRule')}
-          </Button>
+            <Button
+              variant="secondary"
+              size="sm"
+              onClick={openAddDialog}
+              disabled={cannotManage}
+              className="self-start"
+            >
+              <Plus className="mr-1.5 size-4" />
+              {t('defaultModels.addRule')}
+            </Button>
+          </Stack>
         </Stack>
-      </Stack>
+      </div>
 
       <RuleDialog
         open={dialogOpen}
diff --git a/services/platform/app/features/settings/governance/components/feature-flags-editor.tsx b/services/platform/app/features/settings/governance/components/feature-flags-editor.tsx
index 7df3a68930..e30cf96d03 100644
--- a/services/platform/app/features/settings/governance/components/feature-flags-editor.tsx
+++ b/services/platform/app/features/settings/governance/components/feature-flags-editor.tsx
@@ -23,11 +23,13 @@ import {
   type FeatureFlagsConfig,
   type FeatureFlagRule,
 } from '@/lib/shared/schemas/governance';
+import { cn } from '@/lib/utils/cn';
 import { formatNumber } from '@/lib/utils/format/number';
 import { isRecord } from '@/lib/utils/type-guards';
 
 import { useUpsertGovernancePolicy } from '../hooks/mutations';
 import { useGovernancePolicy } from '../hooks/queries';
+import { SelectTriggerButton } from './select-trigger-button';
 
 interface FeatureFlagsEditorProps {
   organizationId: string;
@@ -191,20 +193,15 @@ function RuleDialog({
                 emptyText={t('featureFlags.noUsersFound')}
                 aria-label={t('featureFlags.selectUser')}
                 trigger={
-                  <button
-                    type="button"
+                  <SelectTriggerButton
                     disabled={cannotManage}
-                    className="border-input ring-offset-background flex h-8 w-full items-center justify-between rounded-md border bg-transparent px-3 text-sm disabled:cursor-not-allowed disabled:opacity-50"
+                    hasValue={!!draft.scopeId}
                   >
-                    <span
-                      className={draft.scopeId ? '' : 'text-muted-foreground'}
-                    >
-                      {draft.scopeId
-                        ? (memberOptions.find((o) => o.value === draft.scopeId)
-                            ?.label ?? draft.scopeId)
-                        : t('featureFlags.selectUser')}
-                    </span>
-                  </button>
+                    {draft.scopeId
+                      ? (memberOptions.find((o) => o.value === draft.scopeId)
+                          ?.label ?? draft.scopeId)
+                      : t('featureFlags.selectUser')}
+                  </SelectTriggerButton>
                 }
               />
             </div>
@@ -223,20 +220,15 @@ function RuleDialog({
                 emptyText={t('featureFlags.noTeamsFound')}
                 aria-label={t('featureFlags.selectTeam')}
                 trigger={
-                  <button
-                    type="button"
+                  <SelectTriggerButton
                     disabled={cannotManage}
-                    className="border-input ring-offset-background flex h-8 w-full items-center justify-between rounded-md border bg-transparent px-3 text-sm disabled:cursor-not-allowed disabled:opacity-50"
+                    hasValue={!!draft.scopeId}
                   >
-                    <span
-                      className={draft.scopeId ? '' : 'text-muted-foreground'}
-                    >
-                      {draft.scopeId
-                        ? (teamOptions.find((o) => o.value === draft.scopeId)
-                            ?.label ?? draft.scopeId)
-                        : t('featureFlags.selectTeam')}
-                    </span>
-                  </button>
+                    {draft.scopeId
+                      ? (teamOptions.find((o) => o.value === draft.scopeId)
+                          ?.label ?? draft.scopeId)
+                      : t('featureFlags.selectTeam')}
+                  </SelectTriggerButton>
                 }
               />
             </div>
@@ -481,125 +473,134 @@ export function FeatureFlagsEditor({
         />
       }
     >
-      <Stack gap={6}>
-        <Stack gap={3}>
-          {rules.length > 0 ? (
-            <div className="overflow-x-auto">
-              <table
-                className="w-full text-sm"
-                aria-label={t('featureFlags.title')}
-              >
-                <caption className="sr-only">{t('featureFlags.title')}</caption>
-                <thead>
-                  <tr className="border-border border-b">
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-left font-medium"
-                    >
-                      {t('featureFlags.scope')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-left font-medium"
-                    >
-                      {t('featureFlags.target')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-center font-medium"
-                    >
-                      {t('featureFlags.webSearch')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-center font-medium"
-                    >
-                      {t('featureFlags.codeExecution')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-center font-medium"
-                    >
-                      {t('featureFlags.fileUpload')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-right font-medium"
-                    >
-                      {t('featureFlags.maxContextTokens')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-right font-medium"
-                    >
-                      {t('featureFlags.actions')}
-                    </th>
-                  </tr>
-                </thead>
-                <tbody>
-                  {rules.map((rule, index) => (
-                    <tr key={index} className="border-border border-b">
-                      <td className="px-3 py-2 capitalize">{rule.scope}</td>
-                      <td className="px-3 py-2">{resolveTarget(rule)}</td>
-                      <td className="px-3 py-2 text-center">
-                        {rule.webSearch === false ? '\u2718' : '\u2714'}
-                      </td>
-                      <td className="px-3 py-2 text-center">
-                        {rule.codeExecution === false ? '\u2718' : '\u2714'}
-                      </td>
-                      <td className="px-3 py-2 text-center">
-                        {rule.fileUpload === false ? '\u2718' : '\u2714'}
-                      </td>
-                      <td className="px-3 py-2 text-right">
-                        {rule.maxContextTokens != null
-                          ? formatNumber(rule.maxContextTokens)
-                          : '\u2014'}
-                      </td>
-                      <td className="px-3 py-2 text-right">
-                        <HStack gap={1} justify="end">
-                          <Button
-                            variant="ghost"
-                            size="icon"
-                            onClick={() => openEditDialog(index)}
-                            disabled={cannotManage}
-                            aria-label={`${t('featureFlags.editRule')} ${index + 1}`}
-                          >
-                            <Pencil className="size-4" />
-                          </Button>
-                          <Button
-                            variant="ghost"
-                            size="icon"
-                            onClick={() => removeRule(index)}
-                            disabled={cannotManage}
-                            aria-label={`${t('featureFlags.deleteRule')} ${index + 1}`}
-                          >
-                            <Trash2 className="size-4" />
-                          </Button>
-                        </HStack>
-                      </td>
+      <div
+        className={cn(
+          'transition-opacity duration-200',
+          !enabled && 'pointer-events-none opacity-50',
+        )}
+      >
+        <Stack gap={6}>
+          <Stack gap={3}>
+            {rules.length > 0 ? (
+              <div className="overflow-x-auto">
+                <table
+                  className="w-full text-sm"
+                  aria-label={t('featureFlags.title')}
+                >
+                  <caption className="sr-only">
+                    {t('featureFlags.title')}
+                  </caption>
+                  <thead>
+                    <tr className="border-border border-b">
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-left font-medium"
+                      >
+                        {t('featureFlags.scope')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-left font-medium"
+                      >
+                        {t('featureFlags.target')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-center font-medium"
+                      >
+                        {t('featureFlags.webSearch')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-center font-medium"
+                      >
+                        {t('featureFlags.codeExecution')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-center font-medium"
+                      >
+                        {t('featureFlags.fileUpload')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-right font-medium"
+                      >
+                        {t('featureFlags.maxContextTokens')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-right font-medium"
+                      >
+                        {t('featureFlags.actions')}
+                      </th>
                     </tr>
-                  ))}
-                </tbody>
-              </table>
-            </div>
-          ) : (
-            <Text variant="muted" className="text-sm">
-              {t('featureFlags.noRules')}
-            </Text>
-          )}
+                  </thead>
+                  <tbody>
+                    {rules.map((rule, index) => (
+                      <tr key={index} className="border-border border-b">
+                        <td className="px-3 py-2 capitalize">{rule.scope}</td>
+                        <td className="px-3 py-2">{resolveTarget(rule)}</td>
+                        <td className="px-3 py-2 text-center">
+                          {rule.webSearch === false ? '\u2718' : '\u2714'}
+                        </td>
+                        <td className="px-3 py-2 text-center">
+                          {rule.codeExecution === false ? '\u2718' : '\u2714'}
+                        </td>
+                        <td className="px-3 py-2 text-center">
+                          {rule.fileUpload === false ? '\u2718' : '\u2714'}
+                        </td>
+                        <td className="px-3 py-2 text-right">
+                          {rule.maxContextTokens != null
+                            ? formatNumber(rule.maxContextTokens)
+                            : '\u2014'}
+                        </td>
+                        <td className="px-3 py-2 text-right">
+                          <HStack gap={1} justify="end">
+                            <Button
+                              variant="ghost"
+                              size="icon"
+                              onClick={() => openEditDialog(index)}
+                              disabled={cannotManage}
+                              aria-label={`${t('featureFlags.editRule')} ${index + 1}`}
+                            >
+                              <Pencil className="size-4" />
+                            </Button>
+                            <Button
+                              variant="ghost"
+                              size="icon"
+                              onClick={() => removeRule(index)}
+                              disabled={cannotManage}
+                              aria-label={`${t('featureFlags.deleteRule')} ${index + 1}`}
+                            >
+                              <Trash2 className="size-4" />
+                            </Button>
+                          </HStack>
+                        </td>
+                      </tr>
+                    ))}
+                  </tbody>
+                </table>
+              </div>
+            ) : (
+              <Text variant="muted" className="text-sm">
+                {t('featureFlags.noRules')}
+              </Text>
+            )}
 
-          <Button
-            variant="secondary"
-            size="sm"
-            onClick={openAddDialog}
-            disabled={cannotManage}
-            className="self-start"
-          >
-            <Plus className="mr-1.5 size-4" />
-            {t('featureFlags.addRule')}
-          </Button>
+            <Button
+              variant="secondary"
+              size="sm"
+              onClick={openAddDialog}
+              disabled={cannotManage}
+              className="self-start"
+            >
+              <Plus className="mr-1.5 size-4" />
+              {t('featureFlags.addRule')}
+            </Button>
+          </Stack>
         </Stack>
-      </Stack>
+      </div>
 
       <RuleDialog
         open={dialogOpen}
diff --git a/services/platform/app/features/settings/governance/components/model-access-editor.tsx b/services/platform/app/features/settings/governance/components/model-access-editor.tsx
index 556efc8a9d..62a1022809 100644
--- a/services/platform/app/features/settings/governance/components/model-access-editor.tsx
+++ b/services/platform/app/features/settings/governance/components/model-access-editor.tsx
@@ -23,10 +23,12 @@ import {
   type ModelAccessConfig,
   type ModelAccessRule,
 } from '@/lib/shared/schemas/governance';
+import { cn } from '@/lib/utils/cn';
 import { isRecord } from '@/lib/utils/type-guards';
 
 import { useUpsertGovernancePolicy } from '../hooks/mutations';
 import { useGovernancePolicy } from '../hooks/queries';
+import { SelectTriggerButton } from './select-trigger-button';
 
 interface ModelAccessEditorProps {
   organizationId: string;
@@ -180,20 +182,15 @@ function RuleDialog({
                 emptyText={t('modelAccess.noUsersFound')}
                 aria-label={t('modelAccess.selectUser')}
                 trigger={
-                  <button
-                    type="button"
+                  <SelectTriggerButton
                     disabled={cannotManage}
-                    className="border-input ring-offset-background flex h-8 w-full items-center justify-between rounded-md border bg-transparent px-3 text-sm disabled:cursor-not-allowed disabled:opacity-50"
+                    hasValue={!!draft.scopeId}
                   >
-                    <span
-                      className={draft.scopeId ? '' : 'text-muted-foreground'}
-                    >
-                      {draft.scopeId
-                        ? (memberOptions.find((o) => o.value === draft.scopeId)
-                            ?.label ?? draft.scopeId)
-                        : t('modelAccess.selectUser')}
-                    </span>
-                  </button>
+                    {draft.scopeId
+                      ? (memberOptions.find((o) => o.value === draft.scopeId)
+                          ?.label ?? draft.scopeId)
+                      : t('modelAccess.selectUser')}
+                  </SelectTriggerButton>
                 }
               />
             </div>
@@ -212,20 +209,15 @@ function RuleDialog({
                 emptyText={t('modelAccess.noTeamsFound')}
                 aria-label={t('modelAccess.selectTeam')}
                 trigger={
-                  <button
-                    type="button"
+                  <SelectTriggerButton
                     disabled={cannotManage}
-                    className="border-input ring-offset-background flex h-8 w-full items-center justify-between rounded-md border bg-transparent px-3 text-sm disabled:cursor-not-allowed disabled:opacity-50"
+                    hasValue={!!draft.scopeId}
                   >
-                    <span
-                      className={draft.scopeId ? '' : 'text-muted-foreground'}
-                    >
-                      {draft.scopeId
-                        ? (teamOptions.find((o) => o.value === draft.scopeId)
-                            ?.label ?? draft.scopeId)
-                        : t('modelAccess.selectTeam')}
-                    </span>
-                  </button>
+                    {draft.scopeId
+                      ? (teamOptions.find((o) => o.value === draft.scopeId)
+                          ?.label ?? draft.scopeId)
+                      : t('modelAccess.selectTeam')}
+                  </SelectTriggerButton>
                 }
               />
             </div>
@@ -454,9 +446,22 @@ export function ModelAccessEditor({ organizationId }: ModelAccessEditorProps) {
     <PageSection
       title={t('modelAccess.title')}
       description={t('modelAccess.description')}
+      action={
+        <Switch
+          label={t('modelAccess.enabled')}
+          checked={enabled}
+          onCheckedChange={handleToggleEnabled}
+          disabled={cannotManage || upsertMutation.isPending}
+        />
+      }
     >
-      <Stack gap={6}>
-        <HStack gap={3} align="center" justify="between">
+      <div
+        className={cn(
+          'transition-opacity duration-200',
+          !enabled && 'pointer-events-none opacity-50',
+        )}
+      >
+        <Stack gap={6}>
           <HStack gap={2} align="center">
             <Text className="text-sm font-medium">{t('modelAccess.mode')}</Text>
             <div className="w-36">
@@ -469,106 +474,102 @@ export function ModelAccessEditor({ organizationId }: ModelAccessEditorProps) {
               />
             </div>
           </HStack>
-          <Switch
-            label={t('modelAccess.enabled')}
-            checked={enabled}
-            onCheckedChange={handleToggleEnabled}
-            disabled={cannotManage || upsertMutation.isPending}
-          />
-        </HStack>
-        <Stack gap={3}>
-          {rules.length > 0 ? (
-            <div className="overflow-x-auto">
-              <table
-                className="w-full text-sm"
-                aria-label={t('modelAccess.title')}
-              >
-                <caption className="sr-only">{t('modelAccess.title')}</caption>
-                <thead>
-                  <tr className="border-border border-b">
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-left font-medium"
-                    >
-                      {t('modelAccess.scope')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-left font-medium"
-                    >
-                      {t('modelAccess.target')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-left font-medium"
-                    >
-                      {mode === 'allowlist'
-                        ? t('modelAccess.allowedModels')
-                        : t('modelAccess.blockedModels')}
-                    </th>
-                    <th
-                      scope="col"
-                      className="text-muted-foreground px-3 py-2 text-right font-medium"
-                    >
-                      {t('modelAccess.actions')}
-                    </th>
-                  </tr>
-                </thead>
-                <tbody>
-                  {rules.map((rule, index) => (
-                    <tr key={index} className="border-border border-b">
-                      <td className="px-3 py-2 capitalize">{rule.scope}</td>
-                      <td className="px-3 py-2">{resolveTarget(rule)}</td>
-                      <td className="px-3 py-2">
+          <Stack gap={3}>
+            {rules.length > 0 ? (
+              <div className="overflow-x-auto">
+                <table
+                  className="w-full text-sm"
+                  aria-label={t('modelAccess.title')}
+                >
+                  <caption className="sr-only">
+                    {t('modelAccess.title')}
+                  </caption>
+                  <thead>
+                    <tr className="border-border border-b">
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-left font-medium"
+                      >
+                        {t('modelAccess.scope')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-left font-medium"
+                      >
+                        {t('modelAccess.target')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-left font-medium"
+                      >
                         {mode === 'allowlist'
-                          ? resolveModelNames(rule.allowedModels)
-                          : resolveModelNames(rule.blockedModels ?? [])}
-                      </td>
-                      <td className="px-3 py-2 text-right">
-                        <HStack gap={1} justify="end">
-                          <Button
-                            variant="ghost"
-                            size="icon"
-                            onClick={() => openEditDialog(index)}
-                            disabled={cannotManage}
-                            aria-label={t('modelAccess.editRule')}
-                          >
-                            <Pencil className="size-4" />
-                          </Button>
-                          <Button
-                            variant="ghost"
-                            size="icon"
-                            onClick={() => removeRule(index)}
-                            disabled={cannotManage}
-                            aria-label={t('modelAccess.deleteRule')}
-                          >
-                            <Trash2 className="size-4" />
-                          </Button>
-                        </HStack>
-                      </td>
+                          ? t('modelAccess.allowedModels')
+                          : t('modelAccess.blockedModels')}
+                      </th>
+                      <th
+                        scope="col"
+                        className="text-muted-foreground px-3 py-2 text-right font-medium"
+                      >
+                        {t('modelAccess.actions')}
+                      </th>
                     </tr>
-                  ))}
-                </tbody>
-              </table>
-            </div>
-          ) : (
-            <Text variant="muted" className="text-sm">
-              {t('modelAccess.noRules')}
-            </Text>
-          )}
+                  </thead>
+                  <tbody>
+                    {rules.map((rule, index) => (
+                      <tr key={index} className="border-border border-b">
+                        <td className="px-3 py-2 capitalize">{rule.scope}</td>
+                        <td className="px-3 py-2">{resolveTarget(rule)}</td>
+                        <td className="px-3 py-2">
+                          {mode === 'allowlist'
+                            ? resolveModelNames(rule.allowedModels)
+                            : resolveModelNames(rule.blockedModels ?? [])}
+                        </td>
+                        <td className="px-3 py-2 text-right">
+                          <HStack gap={1} justify="end">
+                            <Button
+                              variant="ghost"
+                              size="icon"
+                              onClick={() => openEditDialog(index)}
+                              disabled={cannotManage}
+                              aria-label={t('modelAccess.editRule')}
+                            >
+                              <Pencil className="size-4" />
+                            </Button>
+                            <Button
+                              variant="ghost"
+                              size="icon"
+                              onClick={() => removeRule(index)}
+                              disabled={cannotManage}
+                              aria-label={t('modelAccess.deleteRule')}
+                            >
+                              <Trash2 className="size-4" />
+                            </Button>
+                          </HStack>
+                        </td>
+                      </tr>
+                    ))}
+                  </tbody>
+                </table>
+              </div>
+            ) : (
+              <Text variant="muted" className="text-sm">
+                {t('modelAccess.noRules')}
+              </Text>
+            )}
 
-          <Button
-            variant="secondary"
-            size="sm"
-            onClick={openAddDialog}
-            disabled={cannotManage}
-            className="self-start"
-          >
-            <Plus className="mr-1.5 size-4" />
-            {t('modelAccess.addRule')}
-          </Button>
+            <Button
+              variant="secondary"
+              size="sm"
+              onClick={openAddDialog}
+              disabled={cannotManage}
+              className="self-start"
+            >
+              <Plus className="mr-1.5 size-4" />
+              {t('modelAccess.addRule')}
+            </Button>
+          </Stack>
         </Stack>
-      </Stack>
+      </div>
 
       {dialogOpen && (
         <RuleDialog
diff --git a/services/platform/app/features/settings/governance/components/pii-config.tsx b/services/platform/app/features/settings/governance/components/pii-config.tsx
index ea4f1dfcb7..ce42bb4d4b 100644
--- a/services/platform/app/features/settings/governance/components/pii-config.tsx
+++ b/services/platform/app/features/settings/governance/components/pii-config.tsx
@@ -1,17 +1,18 @@
 'use client';
 
 import { ShieldCheck } from 'lucide-react';
-import { useCallback, useState } from 'react';
+import { useCallback, useEffect, useState } from 'react';
 
 import { Alert } from '@/app/components/ui/feedback/alert';
 import { Badge } from '@/app/components/ui/feedback/badge';
-import { Spinner } from '@/app/components/ui/feedback/spinner';
 import { FormSection } from '@/app/components/ui/forms/form-section';
 import { Input } from '@/app/components/ui/forms/input';
 import { Select } from '@/app/components/ui/forms/select';
 import { Switch } from '@/app/components/ui/forms/switch';
 import { Textarea } from '@/app/components/ui/forms/textarea';
+import { PageSection } from '@/app/components/ui/layout/page-section';
 import { Button } from '@/app/components/ui/primitives/button';
+import { useAbility } from '@/app/hooks/use-ability';
 import { useToast } from '@/app/hooks/use-toast';
 import { detectPii } from '@/convex/governance/pii/pii_detector';
 import {
@@ -39,6 +40,7 @@ export function PiiConfig({ organizationId }: PiiConfigProps) {
   const { t } = useT('governance');
   const { t: tCommon } = useT('common');
   const { toast } = useToast();
+  const ability = useAbility();
 
   const { data: policy, isLoading } = usePiiConfig(organizationId);
   const upsertMutation = useUpsertPiiConfig();
@@ -56,18 +58,20 @@ export function PiiConfig({ organizationId }: PiiConfigProps) {
   const [testResults, setTestResults] = useState<ReturnType<
     typeof detectPii
   > | null>(null);
-  const [initialized, setInitialized] = useState(false);
 
-  // Sync from server data once loaded
-  if (policy && !initialized) {
-    setEnabled(policy.enabled ?? false);
-    setMode(policy.config?.mode ?? 'mask');
-    setEnabledPatterns(
-      new Set<string>(policy.config?.enabledPatterns ?? PATTERN_NAMES),
-    );
-    setCustomPatterns(policy.config?.customPatterns ?? []);
-    setInitialized(true);
-  }
+  const cannotManage = ability.cannot('write', 'orgSettings');
+
+  // Sync from server data
+  useEffect(() => {
+    if (policy) {
+      setEnabled(policy.enabled ?? false);
+      setMode(policy.config?.mode ?? 'mask');
+      setEnabledPatterns(
+        new Set<string>(policy.config?.enabledPatterns ?? PATTERN_NAMES),
+      );
+      setCustomPatterns(policy.config?.customPatterns ?? []);
+    }
+  }, [policy]);
 
   const saveConfig = useCallback(
     async (overrides: {
@@ -88,8 +92,10 @@ export function PiiConfig({ organizationId }: PiiConfigProps) {
       try {
         await upsertMutation.mutateAsync(resolved);
         toast({ title: t('pii.saved'), variant: 'success' });
-      } catch {
-        toast({ title: t('pii.saveFailed'), variant: 'destructive' });
+      } catch (error: unknown) {
+        const message =
+          error instanceof Error ? error.message : t('pii.saveFailed');
+        toast({ title: message, variant: 'destructive' });
       }
     },
     [
@@ -197,11 +203,7 @@ export function PiiConfig({ organizationId }: PiiConfigProps) {
   }, [testText, enabledPatterns, customPatterns]);
 
   if (isLoading) {
-    return (
-      <div className="flex items-center justify-center py-12">
-        <Spinner aria-label={tCommon('actions.loading')} />
-      </div>
-    );
+    return null;
   }
 
   const modeOptions = [
@@ -210,24 +212,27 @@ export function PiiConfig({ organizationId }: PiiConfigProps) {
   ];
 
   return (
-    <div className="flex max-w-2xl flex-col gap-6">
-      <FormSection label={t('pii.title')} description={t('pii.description')}>
+    <PageSection
+      title={t('pii.title')}
+      description={t('pii.description')}
+      action={
         <Switch
           label={t('pii.enableLabel')}
-          description={t('pii.enableDescription')}
           checked={enabled}
           onCheckedChange={handleEnabledChange}
+          disabled={cannotManage || upsertMutation.isPending}
         />
-      </FormSection>
-
+      }
+    >
       {enabled && (
-        <>
+        <div className="flex flex-col gap-6">
           <FormSection label={t('pii.modeLabel')}>
             <Select
               label={t('pii.modeLabel')}
               options={modeOptions}
               value={mode}
               onValueChange={handleModeChange}
+              disabled={cannotManage}
             />
           </FormSection>
 
@@ -245,6 +250,7 @@ export function PiiConfig({ organizationId }: PiiConfigProps) {
                   onCheckedChange={(checked) =>
                     handlePatternToggle(pattern.name, checked)
                   }
+                  disabled={cannotManage}
                 />
               ))}
             </div>
@@ -270,6 +276,7 @@ export function PiiConfig({ organizationId }: PiiConfigProps) {
                   variant="destructive"
                   size="sm"
                   onClick={() => handleRemoveCustomPattern(index)}
+                  disabled={cannotManage}
                 >
                   {tCommon('actions.delete')}
                 </Button>
@@ -284,6 +291,7 @@ export function PiiConfig({ organizationId }: PiiConfigProps) {
                     handleEditingPatternChange('name', e.target.value)
                   }
                   placeholder={t('pii.customPatternNamePlaceholder')}
+                  disabled={cannotManage}
                 />
                 <Input
                   label={t('pii.customPatternRegex')}
@@ -292,6 +300,7 @@ export function PiiConfig({ organizationId }: PiiConfigProps) {
                     handleEditingPatternChange('regex', e.target.value)
                   }
                   placeholder={t('pii.customPatternRegexPlaceholder')}
+                  disabled={cannotManage}
                 />
                 <Input
                   label={t('pii.customPatternReplacement')}
@@ -300,6 +309,7 @@ export function PiiConfig({ organizationId }: PiiConfigProps) {
                     handleEditingPatternChange('replacement', e.target.value)
                   }
                   placeholder={t('pii.customPatternReplacementPlaceholder')}
+                  disabled={cannotManage}
                 />
                 <div className="flex gap-2">
                   <Button
@@ -307,6 +317,7 @@ export function PiiConfig({ organizationId }: PiiConfigProps) {
                     size="sm"
                     onClick={handleSaveCustomPattern}
                     disabled={
+                      cannotManage ||
                       !editingPattern.name ||
                       !editingPattern.regex ||
                       !editingPattern.replacement
@@ -331,6 +342,7 @@ export function PiiConfig({ organizationId }: PiiConfigProps) {
                 variant="secondary"
                 size="sm"
                 onClick={handleAddCustomPattern}
+                disabled={cannotManage}
               >
                 {t('pii.addCustomPattern')}
               </Button>
@@ -382,8 +394,8 @@ export function PiiConfig({ organizationId }: PiiConfigProps) {
               <Alert icon={ShieldCheck} title={t('pii.testNoResults')} />
             )}
           </FormSection>
-        </>
+        </div>
       )}
-    </div>
+    </PageSection>
   );
 }
diff --git a/services/platform/app/features/settings/governance/components/retention-editor.tsx b/services/platform/app/features/settings/governance/components/retention-editor.tsx
index d28dbe459d..213677cd13 100644
--- a/services/platform/app/features/settings/governance/components/retention-editor.tsx
+++ b/services/platform/app/features/settings/governance/components/retention-editor.tsx
@@ -14,6 +14,7 @@ import {
   retentionPolicyConfigSchema,
   type RetentionPolicyConfig,
 } from '@/lib/shared/schemas/governance';
+import { cn } from '@/lib/utils/cn';
 import { isRecord } from '@/lib/utils/type-guards';
 
 import { useUpsertGovernancePolicy } from '../hooks/mutations';
@@ -125,23 +126,30 @@ export function RetentionEditor({ organizationId }: RetentionEditorProps) {
           />
         }
       >
-        <div className="max-w-xs">
-          <Input
-            label="Retention Days"
-            type="number"
-            value={retentionDays}
-            onChange={(e) =>
-              setRetentionDays(e.target.value ? Number(e.target.value) : 0)
-            }
-            onBlur={() => void saveConfig({ retentionDays })}
-            disabled={cannotManage || !enabled}
-            size="sm"
-            placeholder="e.g. 90"
-            min={0}
-          />
-          <Text className="text-muted-foreground mt-1 text-xs">
-            Documents older than this will be deleted.
-          </Text>
+        <div
+          className={cn(
+            'transition-opacity duration-200',
+            !enabled && 'pointer-events-none opacity-50',
+          )}
+        >
+          <div className="max-w-xs">
+            <Input
+              label="Retention Days"
+              type="number"
+              value={retentionDays}
+              onChange={(e) =>
+                setRetentionDays(e.target.value ? Number(e.target.value) : 0)
+              }
+              onBlur={() => void saveConfig({ retentionDays })}
+              disabled={cannotManage || !enabled}
+              size="sm"
+              placeholder="e.g. 90"
+              min={0}
+            />
+            <Text className="text-muted-foreground mt-1 text-xs">
+              Documents older than this will be deleted.
+            </Text>
+          </div>
         </div>
       </PageSection>
 
@@ -160,25 +168,32 @@ export function RetentionEditor({ organizationId }: RetentionEditorProps) {
           />
         }
       >
-        <div className="max-w-xs">
-          <Input
-            label="Retention Hours"
-            type="number"
-            value={userTempRetentionHours}
-            onChange={(e) =>
-              setUserTempRetentionHours(
-                e.target.value ? Number(e.target.value) : 0,
-              )
-            }
-            onBlur={() => void saveConfig({ userTempRetentionHours })}
-            disabled={cannotManage || !userTempEnabled}
-            size="sm"
-            placeholder="e.g. 24"
-            min={0}
-          />
-          <Text className="text-muted-foreground mt-1 text-xs">
-            Temporary files older than this will be deleted.
-          </Text>
+        <div
+          className={cn(
+            'transition-opacity duration-200',
+            !userTempEnabled && 'pointer-events-none opacity-50',
+          )}
+        >
+          <div className="max-w-xs">
+            <Input
+              label="Retention Hours"
+              type="number"
+              value={userTempRetentionHours}
+              onChange={(e) =>
+                setUserTempRetentionHours(
+                  e.target.value ? Number(e.target.value) : 0,
+                )
+              }
+              onBlur={() => void saveConfig({ userTempRetentionHours })}
+              disabled={cannotManage || !userTempEnabled}
+              size="sm"
+              placeholder="e.g. 24"
+              min={0}
+            />
+            <Text className="text-muted-foreground mt-1 text-xs">
+              Temporary files older than this will be deleted.
+            </Text>
+          </div>
         </div>
       </PageSection>
 
@@ -197,25 +212,32 @@ export function RetentionEditor({ organizationId }: RetentionEditorProps) {
           />
         }
       >
-        <div className="max-w-xs">
-          <Input
-            label="Retention Hours"
-            type="number"
-            value={agentTempRetentionHours}
-            onChange={(e) =>
-              setAgentTempRetentionHours(
-                e.target.value ? Number(e.target.value) : 0,
-              )
-            }
-            onBlur={() => void saveConfig({ agentTempRetentionHours })}
-            disabled={cannotManage || !agentTempEnabled}
-            size="sm"
-            placeholder="e.g. 24"
-            min={0}
-          />
-          <Text className="text-muted-foreground mt-1 text-xs">
-            Temporary files older than this will be deleted.
-          </Text>
+        <div
+          className={cn(
+            'transition-opacity duration-200',
+            !agentTempEnabled && 'pointer-events-none opacity-50',
+          )}
+        >
+          <div className="max-w-xs">
+            <Input
+              label="Retention Hours"
+              type="number"
+              value={agentTempRetentionHours}
+              onChange={(e) =>
+                setAgentTempRetentionHours(
+                  e.target.value ? Number(e.target.value) : 0,
+                )
+              }
+              onBlur={() => void saveConfig({ agentTempRetentionHours })}
+              disabled={cannotManage || !agentTempEnabled}
+              size="sm"
+              placeholder="e.g. 24"
+              min={0}
+            />
+            <Text className="text-muted-foreground mt-1 text-xs">
+              Temporary files older than this will be deleted.
+            </Text>
+          </div>
         </div>
       </PageSection>
     </Stack>
diff --git a/services/platform/app/features/settings/governance/components/select-trigger-button.tsx b/services/platform/app/features/settings/governance/components/select-trigger-button.tsx
new file mode 100644
index 0000000000..bfa9a7a1e2
--- /dev/null
+++ b/services/platform/app/features/settings/governance/components/select-trigger-button.tsx
@@ -0,0 +1,23 @@
+import { type ButtonHTMLAttributes, forwardRef } from 'react';
+
+interface SelectTriggerButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
+  hasValue: boolean;
+}
+
+export const SelectTriggerButton = forwardRef<
+  HTMLButtonElement,
+  SelectTriggerButtonProps
+>(function SelectTriggerButton({ hasValue, children, ...props }, ref) {
+  return (
+    <button
+      ref={ref}
+      type="button"
+      {...props}
+      className="ring-1 ring-border bg-input flex h-8 w-full items-center justify-between rounded-md px-3 text-sm disabled:cursor-not-allowed disabled:opacity-50"
+    >
+      <span className={hasValue ? '' : 'text-muted-foreground'}>
+        {children}
+      </span>
+    </button>
+  );
+});
diff --git a/services/platform/app/features/settings/governance/components/system-prompt-editor.tsx b/services/platform/app/features/settings/governance/components/system-prompt-editor.tsx
index a19430290a..c75e37c649 100644
--- a/services/platform/app/features/settings/governance/components/system-prompt-editor.tsx
+++ b/services/platform/app/features/settings/governance/components/system-prompt-editor.tsx
@@ -115,7 +115,7 @@ export function SystemPromptEditor({
             value={prefix}
             onChange={(e) => setPrefix(e.target.value)}
             placeholder={t('systemPrompt.prefixPlaceholder')}
-            rows={6}
+            rows={4}
             aria-label={t('systemPrompt.prefixLabel')}
             errorMessage={
               prefixOverLimit ? t('systemPrompt.charLimitExceeded') : undefined
@@ -137,7 +137,7 @@ export function SystemPromptEditor({
             value={suffix}
             onChange={(e) => setSuffix(e.target.value)}
             placeholder={t('systemPrompt.suffixPlaceholder')}
-            rows={6}
+            rows={4}
             aria-label={t('systemPrompt.suffixLabel')}
             errorMessage={
               suffixOverLimit ? t('systemPrompt.charLimitExceeded') : undefined
diff --git a/services/platform/app/features/settings/governance/components/upload-policy-editor.tsx b/services/platform/app/features/settings/governance/components/upload-policy-editor.tsx
index a21b17b29f..32983cc695 100644
--- a/services/platform/app/features/settings/governance/components/upload-policy-editor.tsx
+++ b/services/platform/app/features/settings/governance/components/upload-policy-editor.tsx
@@ -15,6 +15,7 @@ import {
   uploadPolicyConfigSchema,
   type UploadPolicyConfig,
 } from '@/lib/shared/schemas/governance';
+import { cn } from '@/lib/utils/cn';
 import { isRecord } from '@/lib/utils/type-guards';
 
 import { useUpsertGovernancePolicy } from '../hooks/mutations';
@@ -164,77 +165,84 @@ export function UploadPolicyEditor({
           </Text>
         )}
 
-        <Stack gap={4}>
-          <div>
-            <Input
-              label={t('uploadPolicy.allowedExtensions')}
-              value={allowedExtensions}
-              onChange={(e) => setAllowedExtensions(e.target.value)}
-              placeholder={t('uploadPolicy.extensionPlaceholder')}
-              disabled={cannotManage || !enabled}
-              size="sm"
-            />
-          </div>
-
-          <div>
-            <Input
-              label={t('uploadPolicy.blockedExtensions')}
-              value={blockedExtensions}
-              onChange={(e) => setBlockedExtensions(e.target.value)}
-              placeholder={t('uploadPolicy.extensionPlaceholder')}
-              disabled={cannotManage || !enabled}
-              size="sm"
-            />
-          </div>
-
-          <div>
-            <Input
-              label={t('uploadPolicy.allowedMimeTypes')}
-              value={allowedMimeTypes}
-              onChange={(e) => setAllowedMimeTypes(e.target.value)}
-              placeholder={t('uploadPolicy.mimeTypePlaceholder')}
-              disabled={cannotManage || !enabled}
-              size="sm"
-            />
-          </div>
-
-          <div>
-            <Input
-              label={`${t('uploadPolicy.maxFileSize')} (${t('uploadPolicy.mbUnit')})`}
-              type="number"
-              value={maxFileSizeMB}
-              onChange={(e) => setMaxFileSizeMB(e.target.value)}
-              disabled={cannotManage || !enabled}
-              size="sm"
-              min={0}
-              step={1}
-            />
-          </div>
-
-          <div>
-            <Input
-              label={`${t('uploadPolicy.maxVolumePerUser')} (${t('uploadPolicy.gbUnit')})`}
-              type="number"
-              value={maxVolumeGB}
-              onChange={(e) => setMaxVolumeGB(e.target.value)}
-              disabled={cannotManage || !enabled}
-              size="sm"
-              min={0}
-              step={0.1}
-            />
-          </div>
-        </Stack>
-
-        <Button
-          onClick={handleSave}
-          disabled={cannotManage || upsertMutation.isPending}
-          size="sm"
-          className="self-start"
+        <div
+          className={cn(
+            'flex flex-col gap-6 transition-opacity duration-200',
+            !enabled && 'pointer-events-none opacity-50',
+          )}
         >
-          {upsertMutation.isPending
-            ? t('systemPrompt.saving')
-            : t('systemPrompt.save')}
-        </Button>
+          <Stack gap={4}>
+            <div>
+              <Input
+                label={t('uploadPolicy.allowedExtensions')}
+                value={allowedExtensions}
+                onChange={(e) => setAllowedExtensions(e.target.value)}
+                placeholder={t('uploadPolicy.extensionPlaceholder')}
+                disabled={cannotManage || !enabled}
+                size="sm"
+              />
+            </div>
+
+            <div>
+              <Input
+                label={t('uploadPolicy.blockedExtensions')}
+                value={blockedExtensions}
+                onChange={(e) => setBlockedExtensions(e.target.value)}
+                placeholder={t('uploadPolicy.extensionPlaceholder')}
+                disabled={cannotManage || !enabled}
+                size="sm"
+              />
+            </div>
+
+            <div>
+              <Input
+                label={t('uploadPolicy.allowedMimeTypes')}
+                value={allowedMimeTypes}
+                onChange={(e) => setAllowedMimeTypes(e.target.value)}
+                placeholder={t('uploadPolicy.mimeTypePlaceholder')}
+                disabled={cannotManage || !enabled}
+                size="sm"
+              />
+            </div>
+
+            <div>
+              <Input
+                label={`${t('uploadPolicy.maxFileSize')} (${t('uploadPolicy.mbUnit')})`}
+                type="number"
+                value={maxFileSizeMB}
+                onChange={(e) => setMaxFileSizeMB(e.target.value)}
+                disabled={cannotManage || !enabled}
+                size="sm"
+                min={0}
+                step={1}
+              />
+            </div>
+
+            <div>
+              <Input
+                label={`${t('uploadPolicy.maxVolumePerUser')} (${t('uploadPolicy.gbUnit')})`}
+                type="number"
+                value={maxVolumeGB}
+                onChange={(e) => setMaxVolumeGB(e.target.value)}
+                disabled={cannotManage || !enabled}
+                size="sm"
+                min={0}
+                step={0.1}
+              />
+            </div>
+          </Stack>
+
+          <Button
+            onClick={handleSave}
+            disabled={cannotManage || upsertMutation.isPending}
+            size="sm"
+            className="self-start"
+          >
+            {upsertMutation.isPending
+              ? t('systemPrompt.saving')
+              : t('systemPrompt.save')}
+          </Button>
+        </div>
       </Stack>
     </PageSection>
   );
diff --git a/services/platform/app/features/settings/mcp-servers/components/__tests__/mcp-server-card.test.tsx b/services/platform/app/features/settings/mcp-servers/components/__tests__/mcp-server-card.test.tsx
index dd18273a89..856c8cef14 100644
--- a/services/platform/app/features/settings/mcp-servers/components/__tests__/mcp-server-card.test.tsx
+++ b/services/platform/app/features/settings/mcp-servers/components/__tests__/mcp-server-card.test.tsx
@@ -27,17 +27,38 @@ function makeServer(
 
 describe('McpServerCard', () => {
   it('renders server display name', () => {
-    render(<McpServerCard server={makeServer()} onClick={vi.fn()} />);
+    render(
+      <McpServerCard
+        server={makeServer()}
+        onClick={vi.fn()}
+        onEdit={vi.fn()}
+        onDelete={vi.fn()}
+      />,
+    );
     expect(screen.getByText('Test Server')).toBeInTheDocument();
   });
 
   it('renders description', () => {
-    render(<McpServerCard server={makeServer()} onClick={vi.fn()} />);
+    render(
+      <McpServerCard
+        server={makeServer()}
+        onClick={vi.fn()}
+        onEdit={vi.fn()}
+        onDelete={vi.fn()}
+      />,
+    );
     expect(screen.getByText('A test MCP server')).toBeInTheDocument();
   });
 
   it('renders tool count', () => {
-    render(<McpServerCard server={makeServer()} onClick={vi.fn()} />);
+    render(
+      <McpServerCard
+        server={makeServer()}
+        onClick={vi.fn()}
+        onEdit={vi.fn()}
+        onDelete={vi.fn()}
+      />,
+    );
     expect(screen.getByText('1 tool')).toBeInTheDocument();
   });
 
@@ -51,6 +72,8 @@ describe('McpServerCard', () => {
           ],
         })}
         onClick={vi.fn()}
+        onEdit={vi.fn()}
+        onDelete={vi.fn()}
       />,
     );
     expect(screen.getByText('2 tools')).toBeInTheDocument();
@@ -59,7 +82,12 @@ describe('McpServerCard', () => {
   it('calls onClick when clicked', async () => {
     const onClick = vi.fn();
     const { user } = render(
-      <McpServerCard server={makeServer()} onClick={onClick} />,
+      <McpServerCard
+        server={makeServer()}
+        onClick={onClick}
+        onEdit={vi.fn()}
+        onDelete={vi.fn()}
+      />,
     );
     await user.click(screen.getByRole('button'));
     expect(onClick).toHaveBeenCalledTimes(1);
@@ -70,6 +98,8 @@ describe('McpServerCard', () => {
       <McpServerCard
         server={makeServer({ status: 'active' })}
         onClick={vi.fn()}
+        onEdit={vi.fn()}
+        onDelete={vi.fn()}
       />,
     );
     expect(screen.getByText('Connected')).toBeInTheDocument();
@@ -80,6 +110,8 @@ describe('McpServerCard', () => {
       <McpServerCard
         server={makeServer({ status: 'inactive' })}
         onClick={vi.fn()}
+        onEdit={vi.fn()}
+        onDelete={vi.fn()}
       />,
     );
     expect(screen.getByText('Disconnected')).toBeInTheDocument();
@@ -90,6 +122,8 @@ describe('McpServerCard', () => {
       <McpServerCard
         server={makeServer({ status: 'error' })}
         onClick={vi.fn()}
+        onEdit={vi.fn()}
+        onDelete={vi.fn()}
       />,
     );
     expect(screen.getByText('Error')).toBeInTheDocument();
@@ -98,7 +132,12 @@ describe('McpServerCard', () => {
   describe('accessibility', () => {
     it('passes axe audit for active server', async () => {
       const { container } = render(
-        <McpServerCard server={makeServer()} onClick={vi.fn()} />,
+        <McpServerCard
+          server={makeServer()}
+          onClick={vi.fn()}
+          onEdit={vi.fn()}
+          onDelete={vi.fn()}
+        />,
       );
       await checkAccessibility(container);
     });
@@ -108,6 +147,8 @@ describe('McpServerCard', () => {
         <McpServerCard
           server={makeServer({ status: 'inactive' })}
           onClick={vi.fn()}
+          onEdit={vi.fn()}
+          onDelete={vi.fn()}
         />,
       );
       await checkAccessibility(container);
@@ -118,6 +159,8 @@ describe('McpServerCard', () => {
         <McpServerCard
           server={makeServer({ status: 'error' })}
           onClick={vi.fn()}
+          onEdit={vi.fn()}
+          onDelete={vi.fn()}
         />,
       );
       await checkAccessibility(container);
diff --git a/services/platform/app/features/settings/mcp-servers/components/__tests__/mcp-server-panel.test.tsx b/services/platform/app/features/settings/mcp-servers/components/__tests__/mcp-server-panel.test.tsx
index 53f6cbec11..14b410e7b3 100644
--- a/services/platform/app/features/settings/mcp-servers/components/__tests__/mcp-server-panel.test.tsx
+++ b/services/platform/app/features/settings/mcp-servers/components/__tests__/mcp-server-panel.test.tsx
@@ -135,7 +135,7 @@ describe('McpServerPanel', () => {
     expect(screen.getByText('https://example.com/mcp')).toBeInTheDocument();
   });
 
-  it('renders delete button', () => {
+  it('renders actions menu with edit and delete', () => {
     render(
       <McpServerPanel
         open
@@ -145,7 +145,9 @@ describe('McpServerPanel', () => {
         onUpdated={vi.fn()}
       />,
     );
-    expect(screen.getByRole('button', { name: /delete/i })).toBeInTheDocument();
+    expect(
+      screen.getByRole('button', { name: /actions menu/i }),
+    ).toBeInTheDocument();
   });
 
   describe('accessibility', () => {
diff --git a/services/platform/app/features/settings/mcp-servers/components/mcp-server-card.tsx b/services/platform/app/features/settings/mcp-servers/components/mcp-server-card.tsx
index 076368b5e5..3c92d98292 100644
--- a/services/platform/app/features/settings/mcp-servers/components/mcp-server-card.tsx
+++ b/services/platform/app/features/settings/mcp-servers/components/mcp-server-card.tsx
@@ -1,10 +1,16 @@
 'use client';
 
-import { Server, Wrench } from 'lucide-react';
+import { Ellipsis, Pencil, Server, Trash2, Wrench } from 'lucide-react';
+import { useMemo } from 'react';
 
 import { Badge } from '@/app/components/ui/feedback/badge';
 import { Card } from '@/app/components/ui/layout/card';
 import { Center, HStack, Stack } from '@/app/components/ui/layout/layout';
+import {
+  DropdownMenu,
+  type DropdownMenuGroup,
+} from '@/app/components/ui/overlays/dropdown-menu';
+import { IconButton } from '@/app/components/ui/primitives/icon-button';
 import { Heading } from '@/app/components/ui/typography/heading';
 import { Text } from '@/app/components/ui/typography/text';
 import { useT } from '@/lib/i18n/client';
@@ -14,6 +20,8 @@ import type { McpServerListItem } from './types';
 interface McpServerCardProps {
   server: McpServerListItem;
   onClick: () => void;
+  onEdit: () => void;
+  onDelete: () => void;
 }
 
 function StatusBadge({ status }: { status: string }) {
@@ -37,62 +45,108 @@ function TransportBadge({ type }: { type: string }) {
   return <Badge variant="blue">{label}</Badge>;
 }
 
-export function McpServerCard({ server, onClick }: McpServerCardProps) {
+export function McpServerCard({
+  server,
+  onClick,
+  onEdit,
+  onDelete,
+}: McpServerCardProps) {
   const { t } = useT('mcpServers');
+  const { t: tCommon } = useT('common');
   const toolCount = server.discoveredTools?.length ?? 0;
 
+  const menuItems = useMemo<DropdownMenuGroup[]>(
+    () => [
+      [
+        {
+          type: 'item' as const,
+          label: t('editServer'),
+          icon: Pencil,
+          onClick: onEdit,
+        },
+      ],
+      [
+        {
+          type: 'item' as const,
+          label: t('deleteServer'),
+          icon: Trash2,
+          onClick: onDelete,
+          destructive: true,
+        },
+      ],
+    ],
+    [t, onEdit, onDelete],
+  );
+
   return (
     <Card
       className="hover:border-primary/50 cursor-pointer transition-colors"
       contentClassName="p-0"
     >
-      <button
-        type="button"
-        onClick={onClick}
-        className="w-full p-5 text-left outline-none"
-      >
-        <Stack gap={3}>
-          <HStack justify="between" align="start">
-            <Center className="border-border size-11 rounded-lg border">
-              <Server className="text-muted-foreground size-6" />
-            </Center>
-            <StatusBadge status={server.status} />
-          </HStack>
-          <Stack gap={1}>
-            <Heading
-              level={3}
-              size="base"
-              tracking="tight"
-              className="leading-none"
-            >
-              {server.displayName}
-            </Heading>
-            {server.description && (
-              <Text variant="muted" className="line-clamp-2 leading-[1.43]">
-                {server.description}
-              </Text>
-            )}
-          </Stack>
-          <HStack gap={2} align="center">
-            <TransportBadge type={server.transportType} />
-            {server.authType !== 'none' && (
-              <Badge variant="outline">
-                {server.authType === 'api_key'
-                  ? t('form.apiKey')
-                  : t('form.oauth2')}
-              </Badge>
-            )}
-            {toolCount > 0 && (
-              <HStack gap={1} align="center">
-                <Wrench className="text-muted-foreground size-3.5" />
-                <Text variant="muted" className="text-xs">
-                  {toolCount} {toolCount === 1 ? 'tool' : 'tools'}
+      <div className="relative">
+        <div className="absolute bottom-5 right-5 z-10">
+          <DropdownMenu
+            trigger={
+              <IconButton
+                icon={Ellipsis}
+                aria-label={tCommon('aria.actionsMenu')}
+                variant="ghost"
+                className="size-8"
+                onClick={(e) => e.stopPropagation()}
+              />
+            }
+            items={menuItems}
+            align="end"
+          />
+        </div>
+        <button
+          type="button"
+          onClick={onClick}
+          className="w-full p-5 text-left outline-none"
+        >
+          <Stack gap={3}>
+            <HStack justify="between" align="start">
+              <Center className="border-border size-11 rounded-lg border">
+                <Server className="text-muted-foreground size-6" />
+              </Center>
+              <StatusBadge status={server.status} />
+            </HStack>
+            <Stack gap={1}>
+              <Heading
+                level={3}
+                size="base"
+                tracking="tight"
+                className="leading-none"
+              >
+                {server.displayName}
+              </Heading>
+              {server.description && (
+                <Text variant="muted" className="line-clamp-2 leading-[1.43]">
+                  {server.description}
                 </Text>
-              </HStack>
-            )}
-          </HStack>
-        </Stack>
-      </button>
+              )}
+            </Stack>
+            <HStack gap={2} align="center">
+              <TransportBadge type={server.transportType} />
+              {server.authType !== 'none' && (
+                <Badge variant="outline">
+                  {server.authType === 'api_key'
+                    ? t('form.apiKey')
+                    : t('form.oauth2')}
+                </Badge>
+              )}
+              {toolCount > 0 && (
+                <HStack gap={1} align="center">
+                  <Wrench className="text-muted-foreground size-3.5" />
+                  <Text variant="muted" className="text-xs">
+                    {toolCount} {toolCount === 1 ? 'tool' : 'tools'}
+                  </Text>
+                </HStack>
+              )}
+            </HStack>
+          </Stack>
+        </button>
+      </div>
     </Card>
   );
 }
diff --git a/services/platform/app/features/settings/mcp-servers/components/mcp-server-form.tsx b/services/platform/app/features/settings/mcp-servers/components/mcp-server-form.tsx
index a36a56795d..b2ba9f049e 100644
--- a/services/platform/app/features/settings/mcp-servers/components/mcp-server-form.tsx
+++ b/services/platform/app/features/settings/mcp-servers/components/mcp-server-form.tsx
@@ -17,6 +17,10 @@ interface McpServerFormProps {
   isSubmitting?: boolean;
   onSubmit: (data: McpServerFormData) => void;
   onCancel?: () => void;
+  /** HTML id for the form element — allows external submit buttons via form attribute */
+  formId?: string;
+  /** Hide the built-in action buttons (Cancel / Save) when rendering them externally */
+  hideActions?: boolean;
 }
 
 export interface McpServerFormData {
@@ -94,6 +98,8 @@ export function McpServerForm({
   isSubmitting,
   onSubmit,
   onCancel,
+  formId,
+  hideActions,
 }: McpServerFormProps) {
   const { t } = useT('mcpServers');
 
@@ -258,7 +264,7 @@ export function McpServerForm({
   );
 
   return (
-    <form onSubmit={handleSubmit} noValidate>
+    <form id={formId} onSubmit={handleSubmit} noValidate>
       <Stack gap={6}>
         <FormSection label={t('form.connectionSection')}>
           <Input
@@ -409,21 +415,23 @@ export function McpServerForm({
           )}
         </FormSection>
 
-        <div className="flex justify-end gap-3">
-          {onCancel && (
-            <Button
-              type="button"
-              variant="secondary"
-              onClick={onCancel}
-              disabled={isSubmitting}
-            >
-              {t('form.cancel')}
+        {!hideActions && (
+          <div className="flex justify-end gap-3">
+            {onCancel && (
+              <Button
+                type="button"
+                variant="secondary"
+                onClick={onCancel}
+                disabled={isSubmitting}
+              >
+                {t('form.cancel')}
+              </Button>
+            )}
+            <Button type="submit" disabled={isSubmitting}>
+              {isSubmitting ? t('form.saving') : t('form.save')}
             </Button>
-          )}
-          <Button type="submit" disabled={isSubmitting}>
-            {isSubmitting ? t('form.saving') : t('form.save')}
-          </Button>
-        </div>
+          </div>
+        )}
       </Stack>
     </form>
   );
diff --git a/services/platform/app/features/settings/mcp-servers/components/mcp-server-panel.tsx b/services/platform/app/features/settings/mcp-servers/components/mcp-server-panel.tsx
index f76235df12..553260a7a0 100644
--- a/services/platform/app/features/settings/mcp-servers/components/mcp-server-panel.tsx
+++ b/services/platform/app/features/settings/mcp-servers/components/mcp-server-panel.tsx
@@ -1,12 +1,25 @@
 'use client';
 
 import { useAction } from 'convex/react';
-import { CheckCircle2, Loader2, ShieldAlert, Wrench, X } from 'lucide-react';
-import { useCallback, useState } from 'react';
+import {
+  CheckCircle2,
+  Ellipsis,
+  Loader2,
+  Pencil,
+  ShieldAlert,
+  Trash2,
+  Wrench,
+  X,
+} from 'lucide-react';
+import { useCallback, useMemo, useState } from 'react';
 
 import { DeleteDialog } from '@/app/components/ui/dialog/delete-dialog';
 import { Badge } from '@/app/components/ui/feedback/badge';
 import { HStack, Stack } from '@/app/components/ui/layout/layout';
+import {
+  DropdownMenu,
+  type DropdownMenuGroup,
+} from '@/app/components/ui/overlays/dropdown-menu';
 import { Sheet } from '@/app/components/ui/overlays/sheet';
 import { Button } from '@/app/components/ui/primitives/button';
 import { IconButton } from '@/app/components/ui/primitives/icon-button';
@@ -26,6 +39,7 @@ interface McpServerPanelProps {
   server: McpServerListItem;
   onDeleted: () => void;
   onUpdated: () => void;
+  initialEditing?: boolean;
 }
 
 export function McpServerPanel({
@@ -34,6 +48,7 @@ export function McpServerPanel({
   server,
   onDeleted,
   onUpdated,
+  initialEditing = false,
 }: McpServerPanelProps) {
   const { t } = useT('mcpServers');
   const { t: tCommon } = useT('common');
@@ -48,7 +63,7 @@ export function McpServerPanel({
   );
 
   const [isTesting, setIsTesting] = useState(false);
-  const [isEditing, setIsEditing] = useState(false);
+  const [isEditing, setIsEditing] = useState(initialEditing);
   const [isSubmitting, setIsSubmitting] = useState(false);
   const [isDeleting, setIsDeleting] = useState(false);
   const [confirmDelete, setConfirmDelete] = useState(false);
@@ -147,6 +162,31 @@ export function McpServerPanel({
 
   const discoveredTools = server.discoveredTools ?? [];
 
+  const menuItems = useMemo<DropdownMenuGroup[]>(
+    () => [
+      [
+        {
+          type: 'item' as const,
+          label: t('editServer'),
+          icon: Pencil,
+          onClick: () => setIsEditing(true),
+          disabled: isTesting || isDeleting,
+        },
+      ],
+      [
+        {
+          type: 'item' as const,
+          label: t('deleteServer'),
+          icon: Trash2,
+          onClick: () => setConfirmDelete(true),
+          destructive: true,
+          disabled: isTesting || isDeleting,
+        },
+      ],
+    ],
+    [t, isTesting, isDeleting],
+  );
+
   return (
     <>
       <Sheet
@@ -165,21 +205,38 @@ export function McpServerPanel({
           <Text variant="label" className="text-base font-semibold">
             {isEditing ? t('editServer') : server.displayName}
           </Text>
-          <IconButton
-            icon={X}
-            aria-label={tCommon('aria.close')}
-            variant="ghost"
-            onClick={() => onOpenChange(false)}
-          />
+          <HStack gap={1}>
+            {!isEditing && (
+              <DropdownMenu
+                trigger={
+                  <IconButton
+                    icon={Ellipsis}
+                    aria-label={tCommon('aria.actionsMenu')}
+                    variant="ghost"
+                    disabled={isTesting || isDeleting}
+                  />
+                }
+                items={menuItems}
+                align="end"
+              />
+            )}
+            <IconButton
+              icon={X}
+              aria-label={tCommon('aria.close')}
+              variant="ghost"
+              onClick={() => onOpenChange(false)}
+            />
+          </HStack>
         </HStack>
 
         <div className="flex-1 overflow-y-auto p-4 sm:px-6 sm:py-5">
           {isEditing ? (
             <McpServerForm
+              formId="edit-mcp-server"
+              hideActions
               server={server}
               isSubmitting={isSubmitting}
               onSubmit={handleUpdate}
-              onCancel={() => setIsEditing(false)}
             />
           ) : (
             <Stack gap={6}>
@@ -320,51 +377,50 @@ export function McpServerPanel({
           )}
         </div>
 
-        {!isEditing && (
-          <div className="border-border shrink-0 border-t p-4 sm:px-6 sm:py-4">
-            <Stack gap={3}>
-              <HStack justify="between" align="center">
-                <Button
-                  variant="secondary"
-                  onClick={handleToggleStatus}
-                  disabled={isTesting || isDeleting}
-                >
-                  {server.status === 'active' ? t('deactivate') : t('activate')}
-                </Button>
-                <HStack gap={2}>
-                  <Button
-                    variant="secondary"
-                    onClick={() => setIsEditing(true)}
-                    disabled={isTesting || isDeleting}
-                  >
-                    {t('editServer')}
-                  </Button>
-                  <Button
-                    onClick={handleTestConnection}
-                    disabled={isTesting || isDeleting}
-                  >
-                    {isTesting ? (
-                      <>
-                        <Loader2 className="mr-2 size-4 animate-spin" />
-                        {t('testing')}
-                      </>
-                    ) : (
-                      t('testConnection')
-                    )}
-                  </Button>
-                </HStack>
-              </HStack>
-              <button
+        <div className="border-border shrink-0 border-t p-4 sm:px-6 sm:py-4">
+          {isEditing ? (
+            <div className="flex justify-end gap-3">
+              <Button
                 type="button"
-                onClick={() => setConfirmDelete(true)}
+                variant="secondary"
+                onClick={() => setIsEditing(false)}
+                disabled={isSubmitting}
+              >
+                {t('form.cancel')}
+              </Button>
+              <Button
+                type="submit"
+                form="edit-mcp-server"
+                disabled={isSubmitting}
+              >
+                {isSubmitting ? t('form.saving') : t('form.save')}
+              </Button>
+            </div>
+          ) : (
+            <HStack justify="between" align="center">
+              <Button
+                variant="secondary"
+                onClick={handleToggleStatus}
                 disabled={isTesting || isDeleting}
-                className="text-destructive hover:text-destructive/80 flex items-center gap-1.5 text-sm font-medium transition-colors disabled:opacity-50"
               >
-                {t('deleteServer')}
-              </button>
-            </Stack>
-          </div>
-        )}
+                {server.status === 'active' ? t('deactivate') : t('activate')}
+              </Button>
+              <Button
+                onClick={handleTestConnection}
+                disabled={isTesting || isDeleting}
+              >
+                {isTesting ? (
+                  <>
+                    <Loader2 className="mr-2 size-4 animate-spin" />
+                    {t('testing')}
+                  </>
+                ) : (
+                  t('testConnection')
+                )}
+              </Button>
+            </HStack>
+          )}
+        </div>
       </Sheet>
 
       <DeleteDialog
diff --git a/services/platform/app/features/settings/mcp-servers/components/mcp-servers.tsx b/services/platform/app/features/settings/mcp-servers/components/mcp-servers.tsx
index b5444522c8..6eb891c777 100644
--- a/services/platform/app/features/settings/mcp-servers/components/mcp-servers.tsx
+++ b/services/platform/app/features/settings/mcp-servers/components/mcp-servers.tsx
@@ -1,17 +1,20 @@
 'use client';
 
 import { useAction } from 'convex/react';
-import { Plus, Server } from 'lucide-react';
+import { Plus, Server, X } from 'lucide-react';
 import { useCallback, useState } from 'react';
 
+import { DeleteDialog } from '@/app/components/ui/dialog/delete-dialog';
 import { EmptyState } from '@/app/components/ui/feedback/empty-state';
 import { Grid, HStack, Stack } from '@/app/components/ui/layout/layout';
 import { Sheet } from '@/app/components/ui/overlays/sheet';
 import { Button } from '@/app/components/ui/primitives/button';
+import { IconButton } from '@/app/components/ui/primitives/icon-button';
 import { Heading } from '@/app/components/ui/typography/heading';
 import { Text } from '@/app/components/ui/typography/text';
 import { toast } from '@/app/hooks/use-toast';
 import { api } from '@/convex/_generated/api';
+import type { Id } from '@/convex/_generated/dataModel';
 import { useT } from '@/lib/i18n/client';
 
 import { useMcpServers } from '../hooks/use-mcp-servers';
@@ -26,13 +29,20 @@ interface McpServersProps {
 
 export function McpServers({ organizationId }: McpServersProps) {
   const { t } = useT('mcpServers');
+  const { t: tCommon } = useT('common');
 
   const { data: servers, refetch } = useMcpServers(organizationId);
   const createAction = useAction(api.mcp_servers.public_mutations.create);
+  const removeAction = useAction(api.mcp_servers.public_mutations.remove);
 
   const [addDialogOpen, setAddDialogOpen] = useState(false);
   const [isCreating, setIsCreating] = useState(false);
   const [selectedServerId, setSelectedServerId] = useState<string | null>(null);
+  const [openInEditMode, setOpenInEditMode] = useState(false);
+  const [deleteServer, setDeleteServer] = useState<McpServerListItem | null>(
+    null,
+  );
+  const [isDeleting, setIsDeleting] = useState(false);
 
   const handleCreate = useCallback(
     async (data: McpServerFormData) => {
@@ -64,9 +74,33 @@ export function McpServers({ organizationId }: McpServersProps) {
   );
 
   const handleCardClick = useCallback((server: McpServerListItem) => {
+    setOpenInEditMode(false);
+    setSelectedServerId(server._id);
+  }, []);
+
+  const handleCardEdit = useCallback((server: McpServerListItem) => {
+    setOpenInEditMode(true);
     setSelectedServerId(server._id);
   }, []);
 
+  const handleDelete = useCallback(async () => {
+    if (!deleteServer) return;
+    setIsDeleting(true);
+    try {
+      await removeAction({
+        // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- server._id is a string at runtime; Convex actions require branded Id type
+        id: deleteServer._id as Id<'mcpServers'>,
+      });
+      toast({ title: t('deleted'), variant: 'success' });
+      setDeleteServer(null);
+      void refetch();
+    } catch {
+      toast({ title: t('error'), variant: 'destructive' });
+    } finally {
+      setIsDeleting(false);
+    }
+  }, [removeAction, deleteServer, t, refetch]);
+
   // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Convex query returns loosely typed data; shape matches McpServerListItem from queries.ts
   const serverList = (servers ?? []) as McpServerListItem[];
 
@@ -97,6 +131,8 @@ export function McpServers({ organizationId }: McpServersProps) {
               key={server._id}
               server={server}
               onClick={() => handleCardClick(server)}
+              onEdit={() => handleCardEdit(server)}
+              onDelete={() => setDeleteServer(server)}
             />
           ))}
         </Grid>
@@ -113,13 +149,45 @@ export function McpServers({ organizationId }: McpServersProps) {
         onOpenChange={setAddDialogOpen}
         title={t('addServer')}
         size="md"
-        className="p-6"
+        hideClose
+        className="flex flex-col gap-0 p-0"
       >
-        <McpServerForm
-          isSubmitting={isCreating}
-          onSubmit={handleCreate}
-          onCancel={() => setAddDialogOpen(false)}
-        />
+        <HStack
+          justify="between"
+          align="center"
+          className="border-border shrink-0 border-b p-4 sm:px-6 sm:py-4"
+        >
+          <Text variant="label" className="text-base font-semibold">
+            {t('addServer')}
+          </Text>
+          <IconButton
+            icon={X}
+            aria-label={tCommon('aria.close')}
+            variant="ghost"
+            onClick={() => setAddDialogOpen(false)}
+          />
+        </HStack>
+        <div className="flex-1 overflow-y-auto p-4 sm:px-6 sm:py-5">
+          <McpServerForm
+            formId="add-mcp-server"
+            hideActions
+            isSubmitting={isCreating}
+            onSubmit={handleCreate}
+          />
+        </div>
+        <div className="border-border flex shrink-0 justify-end gap-3 border-t p-4 sm:px-6 sm:py-4">
+          <Button
+            type="button"
+            variant="secondary"
+            onClick={() => setAddDialogOpen(false)}
+            disabled={isCreating}
+          >
+            {t('form.cancel')}
+          </Button>
+          <Button type="submit" form="add-mcp-server" disabled={isCreating}>
+            {isCreating ? t('form.saving') : t('form.save')}
+          </Button>
+        </div>
       </Sheet>
 
       {selectedServer && (
@@ -129,6 +197,7 @@ export function McpServers({ organizationId }: McpServersProps) {
             if (!open) setSelectedServerId(null);
           }}
           server={selectedServer}
+          initialEditing={openInEditMode}
           onDeleted={() => {
             setSelectedServerId(null);
             void refetch();
@@ -136,6 +205,17 @@ export function McpServers({ organizationId }: McpServersProps) {
           onUpdated={() => void refetch()}
         />
       )}
+
+      <DeleteDialog
+        open={!!deleteServer}
+        onOpenChange={(open) => {
+          if (!open) setDeleteServer(null);
+        }}
+        title={t('deleteServer')}
+        description={t('deleteConfirmation')}
+        isDeleting={isDeleting}
+        onDelete={handleDelete}
+      />
     </Stack>
   );
 }
diff --git a/services/platform/app/features/settings/organization/components/member-add-dialog.tsx b/services/platform/app/features/settings/organization/components/member-add-dialog.tsx
index 947985a291..4d9c2bc823 100644
--- a/services/platform/app/features/settings/organization/components/member-add-dialog.tsx
+++ b/services/platform/app/features/settings/organization/components/member-add-dialog.tsx
@@ -182,6 +182,7 @@ export function AddMemberDialog({
           <Input
             id="password"
             type="password"
+            autoComplete="new-password"
             label={tSettings('form.password')}
             placeholder={tSettings('form.passwordPlaceholder')}
             description={tSettings('form.forgotPassword')}
diff --git a/services/platform/app/features/settings/organization/components/member-edit-dialog.tsx b/services/platform/app/features/settings/organization/components/member-edit-dialog.tsx
index af90c16a0b..1cba4887fd 100644
--- a/services/platform/app/features/settings/organization/components/member-edit-dialog.tsx
+++ b/services/platform/app/features/settings/organization/components/member-edit-dialog.tsx
@@ -262,6 +262,7 @@ export function EditMemberDialog({
             <Input
               id="password"
               type="password"
+              autoComplete="new-password"
               label={t('form.password')}
               placeholder={t('organization.enterNewPassword')}
               {...register('password')}
diff --git a/services/platform/app/features/settings/providers/components/provider-edit-panel.tsx b/services/platform/app/features/settings/providers/components/provider-edit-panel.tsx
index 734501c654..21886ceddd 100644
--- a/services/platform/app/features/settings/providers/components/provider-edit-panel.tsx
+++ b/services/platform/app/features/settings/providers/components/provider-edit-panel.tsx
@@ -4,6 +4,8 @@ import { Loader2, X } from 'lucide-react';
 import { useCallback, useEffect, useState } from 'react';
 
 import { Input } from '@/app/components/ui/forms/input';
+import { Select } from '@/app/components/ui/forms/select';
+import { Textarea } from '@/app/components/ui/forms/textarea';
 import { HStack, Stack } from '@/app/components/ui/layout/layout';
 import { Sheet } from '@/app/components/ui/overlays/sheet';
 import { Button } from '@/app/components/ui/primitives/button';
@@ -15,6 +17,8 @@ import { useT } from '@/lib/i18n/client';
 import { useSaveProvider } from '../hooks/mutations';
 import { useReadProvider } from '../hooks/queries';
 
+const NONE_VALUE = '__none__';
+
 interface ProviderEditPanelProps {
   open: boolean;
   onOpenChange: (open: boolean) => void;
@@ -34,7 +38,9 @@ export function ProviderEditPanel({
   const [form, setForm] = useState({
     name: '',
     displayName: '',
+    description: '',
     baseUrl: '',
+    defaults: {} as Record<string, string>,
   });
 
   useEffect(() => {
@@ -42,7 +48,9 @@ export function ProviderEditPanel({
       setForm({
         name: providerName,
         displayName: data.config.displayName,
+        description: data.config.description ?? '',
         baseUrl: data.config.baseUrl,
+        defaults: { ...data.config.defaults },
       });
     }
   }, [data, providerName]);
@@ -51,6 +59,9 @@ export function ProviderEditPanel({
     async (e: React.FormEvent) => {
       e.preventDefault();
       if (!data?.ok) return;
+      const cleanedDefaults = Object.fromEntries(
+        Object.entries(form.defaults).filter(([, v]) => v && v !== NONE_VALUE),
+      );
       try {
         await saveProvider({
           orgSlug: 'default',
@@ -58,7 +69,12 @@ export function ProviderEditPanel({
           config: {
             ...data.config,
             displayName: form.displayName,
+            description: form.description || undefined,
             baseUrl: form.baseUrl,
+            defaults:
+              Object.keys(cleanedDefaults).length > 0
+                ? cleanedDefaults
+                : undefined,
           },
         });
         toast({ title: t('providers.saved'), variant: 'success' });
@@ -78,7 +94,14 @@ export function ProviderEditPanel({
   const isDirty =
     data?.ok &&
     (form.displayName !== data.config.displayName ||
-      form.baseUrl !== data.config.baseUrl);
+      form.description !== (data.config.description ?? '') ||
+      form.baseUrl !== data.config.baseUrl ||
+      form.defaults.chat !== (data.config.defaults?.chat ?? NONE_VALUE) ||
+      form.defaults.vision !== (data.config.defaults?.vision ?? NONE_VALUE) ||
+      form.defaults.embedding !==
+        (data.config.defaults?.embedding ?? NONE_VALUE));
+
+  const models = data?.ok ? data.config.models : [];
 
   return (
     <Sheet
@@ -127,6 +150,16 @@ export function ProviderEditPanel({
               placeholder={t('providers.displayNamePlaceholder')}
             />
 
+            <Textarea
+              label={t('providers.description_field')}
+              value={form.description}
+              onChange={(e) =>
+                setForm((f) => ({ ...f, description: e.target.value }))
+              }
+              placeholder={t('providers.descriptionPlaceholder')}
+              rows={3}
+            />
+
             <Input
               label={t('providers.baseUrl')}
               value={form.baseUrl}
@@ -135,6 +168,48 @@ export function ProviderEditPanel({
               }
               placeholder={t('providers.baseUrlPlaceholder')}
             />
+
+            <div className="border-border border-t pt-4">
+              <Text className="mb-3 text-sm font-semibold">
+                {t('providers.defaultModels')}
+              </Text>
+              <Stack gap={4}>
+                {(['chat', 'vision', 'embedding'] as const).map((tag) => {
+                  const modelsWithTag = models.filter((m) =>
+                    (m.tags as readonly string[]).includes(tag),
+                  );
+                  return (
+                    <Select
+                      key={tag}
+                      label={
+                        tag === 'chat'
+                          ? t('providers.tagChat')
+                          : tag === 'vision'
+                            ? t('providers.tagVision')
+                            : t('providers.tagEmbedding')
+                      }
+                      options={[
+                        {
+                          value: NONE_VALUE,
+                          label: t('providers.defaultNone'),
+                        },
+                        ...modelsWithTag.map((m) => ({
+                          value: m.id,
+                          label: m.displayName,
+                        })),
+                      ]}
+                      value={form.defaults[tag] ?? NONE_VALUE}
+                      onValueChange={(value) =>
+                        setForm((f) => ({
+                          ...f,
+                          defaults: { ...f.defaults, [tag]: value },
+                        }))
+                      }
+                    />
+                  );
+                })}
+              </Stack>
+            </div>
           </Stack>
         </div>
 
diff --git a/services/platform/app/features/settings/teams/components/team-detail-dialog.tsx b/services/platform/app/features/settings/teams/components/team-detail-dialog.tsx
new file mode 100644
index 0000000000..97ed035664
--- /dev/null
+++ b/services/platform/app/features/settings/teams/components/team-detail-dialog.tsx
@@ -0,0 +1,148 @@
+'use client';
+
+import { Pencil, Users } from 'lucide-react';
+import { useState } from 'react';
+
+import { Dialog } from '@/app/components/ui/dialog/dialog';
+import { Badge } from '@/app/components/ui/feedback/badge';
+import { Skeleton } from '@/app/components/ui/feedback/skeleton';
+import { HStack, Stack } from '@/app/components/ui/layout/layout';
+import { Button } from '@/app/components/ui/primitives/button';
+import { Text } from '@/app/components/ui/typography/text';
+import { useT } from '@/lib/i18n/client';
+
+import { useTeamMembers, type Team } from '../hooks/queries';
+import { TeamEditDialog } from './team-edit-dialog';
+
+interface TeamDetailMember {
+  _id: string;
+  userId: string;
+  displayName?: string;
+  email?: string;
+  role: string;
+}
+
+interface TeamDetailDialogProps {
+  team: Team;
+  organizationId: string;
+  open: boolean;
+  onOpenChange: (open: boolean) => void;
+}
+
+function TeamDetailDialogContent({
+  team,
+  organizationId,
+  open,
+  onOpenChange,
+}: TeamDetailDialogProps) {
+  const { t: tSettings } = useT('settings');
+  const { t: tCommon } = useT('common');
+  const { teamMembers, isLoading } = useTeamMembers(team.id);
+  const [editOpen, setEditOpen] = useState(false);
+
+  const memberCount = teamMembers?.length ?? 0;
+
+  return (
+    <>
+      <Dialog
+        open={open}
+        onOpenChange={onOpenChange}
+        title={team.name}
+        description={
+          isLoading
+            ? undefined
+            : tSettings('teams.memberCount', { count: memberCount })
+        }
+        size="md"
+        footer={
+          <HStack gap={2} justify="end">
+            <Button variant="secondary" onClick={() => onOpenChange(false)}>
+              {tCommon('actions.cancel')}
+            </Button>
+            <Button onClick={() => setEditOpen(true)}>
+              <Pencil className="mr-1.5 size-3.5" />
+              {tCommon('actions.edit')}
+            </Button>
+          </HStack>
+        }
+      >
+        <Stack gap={4}>
+          <Text variant="label" className="text-sm">
+            {tSettings('teams.manageMembers')}
+          </Text>
+
+          {isLoading ? (
+            <Stack gap={3}>
+              {Array.from({ length: 3 }).map((_, i) => (
+                <HStack key={i} gap={3} align="center">
+                  <Skeleton className="size-8 shrink-0 rounded-full" />
+                  <Stack gap={1} className="flex-1">
+                    <Skeleton className="h-3.5 w-32" />
+                    <Skeleton className="h-3 w-48" />
+                  </Stack>
+                </HStack>
+              ))}
+            </Stack>
+          ) : !teamMembers || teamMembers.length === 0 ? (
+            <div className="flex flex-col items-center justify-center gap-2 py-6">
+              <Users className="text-muted-foreground size-8" />
+              <Text variant="muted" className="text-sm">
+                {tSettings('teams.noTeamMembers')}
+              </Text>
+            </div>
+          ) : (
+            <div className="border-border overflow-hidden rounded-lg border">
+              {teamMembers.map((member: TeamDetailMember, index: number) => (
+                <div
+                  key={member._id}
+                  className={`flex items-center gap-3 px-3 py-2.5 ${
+                    index < teamMembers.length - 1
+                      ? 'border-border border-b'
+                      : ''
+                  }`}
+                >
+                  <div className="bg-muted flex size-8 shrink-0 items-center justify-center rounded-full">
+                    <Text className="text-muted-foreground text-xs font-medium">
+                      {(member.displayName || member.email || '?')
+                        .charAt(0)
+                        .toUpperCase()}
+                    </Text>
+                  </div>
+                  <Stack gap={0} className="min-w-0 flex-1">
+                    <Text className="truncate text-sm font-medium">
+                      {member.displayName ||
+                        member.email ||
+                        tSettings('teams.unknownMember')}
+                    </Text>
+                    {member.email &&
+                      member.displayName &&
+                      member.displayName !== member.email && (
+                        <Text variant="muted" className="truncate text-xs">
+                          {member.email}
+                        </Text>
+                      )}
+                  </Stack>
+                  <Badge variant="outline" className="shrink-0 capitalize">
+                    {member.role}
+                  </Badge>
+                </div>
+              ))}
+            </div>
+          )}
+        </Stack>
+      </Dialog>
+
+      <TeamEditDialog
+        open={editOpen}
+        onOpenChange={setEditOpen}
+        team={team}
+        organizationId={organizationId}
+      />
+    </>
+  );
+}
+
+export function TeamDetailDialog(props: TeamDetailDialogProps) {
+  if (!props.open) return null;
+  return <TeamDetailDialogContent {...props} />;
+}
diff --git a/services/platform/app/features/settings/teams/components/team-row-actions.tsx b/services/platform/app/features/settings/teams/components/team-row-actions.tsx
index 342dd4b6ea..b7e878032f 100644
--- a/services/platform/app/features/settings/teams/components/team-row-actions.tsx
+++ b/services/platform/app/features/settings/teams/components/team-row-actions.tsx
@@ -1,6 +1,6 @@
 'use client';
 
-import { Pencil, Trash2 } from 'lucide-react';
+import { Eye, Pencil, Trash2 } from 'lucide-react';
 import { useCallback, useMemo, useState } from 'react';
 
 import {
@@ -16,9 +16,14 @@ import { TeamEditDialog } from './team-edit-dialog';
 interface TeamRowActionsProps {
   team: Team;
   organizationId: string;
+  onView?: () => void;
 }
 
-export function TeamRowActions({ team, organizationId }: TeamRowActionsProps) {
+export function TeamRowActions({
+  team,
+  organizationId,
+  onView,
+}: TeamRowActionsProps) {
   const { t: tCommon } = useT('common');
   const dialogs = useEntityRowDialogs(['edit', 'delete']);
   const [isDeleted, setIsDeleted] = useState(false);
@@ -27,6 +32,17 @@ export function TeamRowActions({ team, organizationId }: TeamRowActionsProps) {
 
   const actions = useMemo(
     () => [
+      ...(onView
+        ? [
+            {
+              key: 'view',
+              label: tCommon('actions.view'),
+              icon: Eye,
+              onClick: onView,
+              disabled: isDeleted,
+            },
+          ]
+        : []),
       {
         key: 'edit',
         label: tCommon('actions.edit'),
@@ -43,7 +59,7 @@ export function TeamRowActions({ team, organizationId }: TeamRowActionsProps) {
         disabled: isDeleted,
       },
     ],
-    [tCommon, dialogs.open, isDeleted],
+    [tCommon, dialogs.open, isDeleted, onView],
   );
 
   return (
diff --git a/services/platform/app/features/settings/teams/components/teams-table.tsx b/services/platform/app/features/settings/teams/components/teams-table.tsx
index 13907f241c..fafc4f08ca 100644
--- a/services/platform/app/features/settings/teams/components/teams-table.tsx
+++ b/services/platform/app/features/settings/teams/components/teams-table.tsx
@@ -1,6 +1,7 @@
 'use client';
 
 import { Users } from 'lucide-react';
+import { useCallback, useState } from 'react';
 
 import { DataTable } from '@/app/components/ui/data-table/data-table';
 import { useListPage } from '@/app/hooks/use-list-page';
@@ -8,6 +9,7 @@ import { useT } from '@/lib/i18n/client';
 
 import type { Team } from '../hooks/queries';
 import { useTeamsTableConfig } from '../hooks/use-teams-table-config';
+import { TeamDetailDialog } from './team-detail-dialog';
 import { TeamsActionMenu } from './teams-action-menu';
 
 interface TeamsTableProps {
@@ -18,8 +20,14 @@ interface TeamsTableProps {
 export function TeamsTable({ teams, organizationId }: TeamsTableProps) {
   const { t: tEmpty } = useT('emptyStates');
   const { t: tSettings } = useT('settings');
+  const [selectedTeam, setSelectedTeam] = useState<Team | null>(null);
+
+  const handleViewTeam = useCallback((team: Team) => {
+    setSelectedTeam(team);
+  }, []);
+
   const { columns, searchPlaceholder, stickyLayout, pageSize } =
-    useTeamsTableConfig(organizationId);
+    useTeamsTableConfig(organizationId, handleViewTeam);
 
   const list = useListPage<Team>({
     dataSource: { type: 'query', data: teams },
@@ -48,8 +56,21 @@ export function TeamsTable({ teams, organizationId }: TeamsTableProps) {
           title: tEmpty('teams.title'),
           description: tEmpty('teams.description'),
         }}
+        onRowClick={(row) => setSelectedTeam(row.original)}
+        clickableRows
         {...list.tableProps}
       />
+
+      {selectedTeam && (
+        <TeamDetailDialog
+          team={selectedTeam}
+          organizationId={organizationId}
+          open={!!selectedTeam}
+          onOpenChange={(open) => {
+            if (!open) setSelectedTeam(null);
+          }}
+        />
+      )}
     </div>
   );
 }
diff --git a/services/platform/app/features/settings/teams/hooks/use-teams-table-config.tsx b/services/platform/app/features/settings/teams/hooks/use-teams-table-config.tsx
index 5c8b39be1d..abf87f43e8 100644
--- a/services/platform/app/features/settings/teams/hooks/use-teams-table-config.tsx
+++ b/services/platform/app/features/settings/teams/hooks/use-teams-table-config.tsx
@@ -17,7 +17,10 @@ interface TeamsTableConfig {
   infiniteScroll: boolean;
 }
 
-export function useTeamsTableConfig(organizationId: string): TeamsTableConfig {
+export function useTeamsTableConfig(
+  organizationId: string,
+  onViewTeam?: (team: Team) => void,
+): TeamsTableConfig {
   const { t: tSettings } = useT('settings');
 
   const columns = useMemo<ColumnDef<Team>[]>(
@@ -36,11 +39,15 @@ export function useTeamsTableConfig(organizationId: string): TeamsTableConfig {
         size: 44,
         meta: { isAction: true },
         cell: ({ row }) => (
-          <TeamRowActions team={row.original} organizationId={organizationId} />
+          <TeamRowActions
+            team={row.original}
+            organizationId={organizationId}
+            onView={onViewTeam ? () => onViewTeam(row.original) : undefined}
+          />
         ),
       },
     ],
-    [tSettings, organizationId],
+    [tSettings, organizationId, onViewTeam],
   );
 
   return {
diff --git a/services/platform/app/routes/dashboard/$id/settings/governance.tsx b/services/platform/app/routes/dashboard/$id/settings/governance.tsx
index 20d8370cfa..8c68267b14 100644
--- a/services/platform/app/routes/dashboard/$id/settings/governance.tsx
+++ b/services/platform/app/routes/dashboard/$id/settings/governance.tsx
@@ -1,9 +1,8 @@
 import { createFileRoute, useNavigate } from '@tanstack/react-router';
-import { useMemo } from 'react';
+import { type ReactNode, useMemo } from 'react';
 import { z } from 'zod';
 
 import { AccessDenied } from '@/app/components/layout/access-denied';
-import { Tabs } from '@/app/components/ui/navigation/tabs';
 import { BudgetEditor } from '@/app/features/settings/governance/components/budget-editor';
 import { FeatureFlagsEditor } from '@/app/features/settings/governance/components/feature-flags-editor';
 import { ModelAccessEditor } from '@/app/features/settings/governance/components/model-access-editor';
@@ -13,6 +12,7 @@ import { SystemPromptEditor } from '@/app/features/settings/governance/component
 import { UsageDashboard } from '@/app/features/settings/governance/components/usage-dashboard';
 import { useAbility, useAbilityLoading } from '@/app/hooks/use-ability';
 import { useT } from '@/lib/i18n/client';
+import { cn } from '@/lib/utils/cn';
 import { lazyComponent } from '@/lib/utils/lazy-component';
 import { seo } from '@/lib/utils/seo';
 
@@ -28,8 +28,15 @@ const UploadPolicyEditor = lazyComponent(() =>
   ),
 );
 
+const GROUPS = [
+  'content-models',
+  'policies-limits',
+  'security-monitoring',
+] as const;
+type GroupKey = (typeof GROUPS)[number];
+
 const searchSchema = z.object({
-  tab: z.string().optional(),
+  group: z.enum(GROUPS).optional(),
 });
 
 export const Route = createFileRoute('/dashboard/$id/settings/governance')({
@@ -40,6 +47,12 @@ export const Route = createFileRoute('/dashboard/$id/settings/governance')({
   component: GovernanceSettingsPage,
 });
 
+interface GroupConfig {
+  key: GroupKey;
+  label: string;
+  sections: ReactNode[];
+}
+
 function GovernanceSettingsPage() {
   const { id: organizationId } = Route.useParams();
   const search = Route.useSearch();
@@ -50,67 +63,65 @@ function GovernanceSettingsPage() {
   const ability = useAbility();
   const abilityLoading = useAbilityLoading();
 
-  const activeTab = search.tab ?? 'system-prompt';
-
-  const handleTabChange = (tab: string) => {
-    void navigate({
-      from: Route.fullPath,
-      search: { ...search, tab },
-      replace: true,
-    });
-  };
-
-  const tabItems = useMemo(
+  const groups: GroupConfig[] = useMemo(
     () => [
       {
-        value: 'system-prompt',
-        label: t('tabs.systemPrompt'),
-        content: <SystemPromptEditor organizationId={organizationId} />,
-      },
-      {
-        value: 'budgets',
-        label: t('tabs.budgets'),
-        content: <BudgetEditor organizationId={organizationId} />,
+        key: 'content-models',
+        label: t('groups.contentAndModels'),
+        sections: [
+          <SystemPromptEditor
+            key="system-prompt"
+            organizationId={organizationId}
+          />,
+          <DefaultModelEditor
+            key="default-models"
+            organizationId={organizationId}
+          />,
+          <ModelAccessEditor
+            key="model-access"
+            organizationId={organizationId}
+          />,
+        ],
       },
       {
-        value: 'default-models',
-        label: t('defaultModels.title'),
-        content: <DefaultModelEditor organizationId={organizationId} />,
+        key: 'policies-limits',
+        label: t('groups.policiesAndLimits'),
+        sections: [
+          <BudgetEditor key="budgets" organizationId={organizationId} />,
+          <UploadPolicyEditor
+            key="upload-policy"
+            organizationId={organizationId}
+          />,
+          <RetentionEditor key="retention" organizationId={organizationId} />,
+          <FeatureFlagsEditor
+            key="feature-controls"
+            organizationId={organizationId}
+          />,
+        ],
       },
       {
-        value: 'upload-policy',
-        label: t('uploadPolicy.title'),
-        content: <UploadPolicyEditor organizationId={organizationId} />,
-      },
-      {
-        value: 'retention',
-        label: 'Retention',
-        content: <RetentionEditor organizationId={organizationId} />,
-      },
-      {
-        value: 'feature-controls',
-        label: t('tabs.featureControls'),
-        content: <FeatureFlagsEditor organizationId={organizationId} />,
-      },
-      {
-        value: 'model-access',
-        label: t('tabs.modelAccess'),
-        content: <ModelAccessEditor organizationId={organizationId} />,
-      },
-      {
-        value: 'usage',
-        label: t('tabs.usage'),
-        content: <UsageDashboard organizationId={organizationId} />,
-      },
-      {
-        value: 'pii',
-        label: t('tabs.pii'),
-        content: <PiiConfig organizationId={organizationId} />,
+        key: 'security-monitoring',
+        label: t('groups.securityAndMonitoring'),
+        sections: [
+          <PiiConfig key="pii" organizationId={organizationId} />,
+          <UsageDashboard key="usage" organizationId={organizationId} />,
+        ],
       },
     ],
     [organizationId, t],
   );
 
+  const activeGroup = search.group ?? 'content-models';
+  const currentGroup = groups.find((g) => g.key === activeGroup) ?? groups[0];
+
+  const handleGroupChange = (group: GroupKey) => {
+    void navigate({
+      from: Route.fullPath,
+      search: { group },
+      replace: true,
+    });
+  };
+
   if (abilityLoading) {
     return null;
   }
@@ -120,12 +131,33 @@ function GovernanceSettingsPage() {
   }
 
   return (
-    <div className="flex flex-col gap-4">
-      <Tabs
-        items={tabItems}
-        value={activeTab}
-        onValueChange={handleTabChange}
-      />
+    <div className="flex gap-6">
+      <nav className="sticky top-30 flex w-[16rem] shrink-0 flex-col gap-1 self-start">
+        {groups.map((group) => (
+          <button
+            key={group.key}
+            type="button"
+            onClick={() => handleGroupChange(group.key)}
+            className={cn(
+              'rounded-md px-3 py-2 text-left text-sm font-medium transition-colors',
+              activeGroup === group.key
+                ? 'bg-muted text-foreground'
+                : 'text-muted-foreground hover:bg-muted/50 hover:text-foreground',
+            )}
+          >
+            {group.label}
+          </button>
+        ))}
+      </nav>
+      <div className="min-w-0 flex-1">
+        <div className="divide-border flex flex-col divide-y">
+          {currentGroup.sections.map((section, i) => (
+            <div key={i} className={cn(i > 0 && 'pt-8', 'pb-8')}>
+              {section}
+            </div>
+          ))}
+        </div>
+      </div>
     </div>
   );
 }
diff --git a/services/platform/app/routes/dashboard/$id/settings/logs.tsx b/services/platform/app/routes/dashboard/$id/settings/logs.tsx
index 795bdf0a59..d4701dfcff 100644
--- a/services/platform/app/routes/dashboard/$id/settings/logs.tsx
+++ b/services/platform/app/routes/dashboard/$id/settings/logs.tsx
@@ -1,17 +1,18 @@
 import { createFileRoute } from '@tanstack/react-router';
-import { useMemo } from 'react';
+import { useCallback, useMemo } from 'react';
 import { z } from 'zod';
 
 import { AccessDenied } from '@/app/components/layout/access-denied';
-import { Card } from '@/app/components/ui/layout/card';
-import { Stack } from '@/app/components/ui/layout/layout';
 import { Tabs } from '@/app/components/ui/navigation/tabs';
+import { Button } from '@/app/components/ui/primitives/button';
 import { Text } from '@/app/components/ui/typography/text';
 import { AuditLogTable } from '@/app/features/settings/audit-logs/components/audit-log-table';
 import { useListAuditLogsPaginated } from '@/app/features/settings/audit-logs/hooks/queries';
 import { useAbility } from '@/app/hooks/use-ability';
+import { useConvexAction } from '@/app/hooks/use-convex-action';
 import { useConvexQuery } from '@/app/hooks/use-convex-query';
 import { useCurrentMemberContext } from '@/app/hooks/use-current-member-context';
+import { useToast } from '@/app/hooks/use-toast';
 import { api } from '@/convex/_generated/api';
 import { useT } from '@/lib/i18n/client';
 import { seo } from '@/lib/utils/seo';
@@ -56,51 +57,105 @@ function LogsPage() {
     return map;
   }, [membersQuery.data]);
 
+  const { toast } = useToast();
+
+  const exportAction = useConvexAction(api.audit_logs.actions.requestExport, {
+    onSuccess: (data) => {
+      if (data.url) {
+        window.open(data.url, '_blank', 'noopener,noreferrer');
+      }
+      toast({
+        title: t('logs.audit.export.complete'),
+        description: data.fileName,
+      });
+    },
+    onError: () => {
+      toast({
+        title: t('logs.audit.export.error'),
+        variant: 'destructive',
+      });
+    },
+  });
+
+  const handleExport = useCallback(
+    (format: 'csv' | 'json') => {
+      exportAction.mutate({
+        organizationId,
+        format,
+        filter: search.category ? { category: search.category } : undefined,
+      });
+    },
+    [organizationId, search.category, exportAction],
+  );
+
   if (ability.cannot('read', 'orgSettings')) {
     return <AccessDenied message={tAccess('organization')} />;
   }
 
   return (
-    <Stack gap={4}>
-      <Tabs
-        defaultValue="audit"
-        className="space-y-4"
-        items={[
-          {
-            value: 'audit',
-            label: t('logs.auditLogs'),
-            content: (
-              <Card title={t('logs.auditLogs')}>
-                <AuditLogTable
-                  organizationId={organizationId}
-                  paginatedResult={paginatedResult}
-                  category={search.category}
-                  isAdmin={isAdminUser}
-                  userEmailMap={userEmailMap}
-                />
-              </Card>
-            ),
-          },
-          {
-            value: 'activity',
-            label: t('logs.activityLogs'),
-            content: (
-              <Card title={t('logs.activityLogs')}>
-                <Text variant="muted">{t('logs.activityDescription')}</Text>
-              </Card>
-            ),
-          },
-          {
-            value: 'errors',
-            label: t('logs.errorLogs'),
-            content: (
-              <Card title={t('logs.errorLogs')}>
-                <Text variant="muted">{t('logs.errorDescription')}</Text>
-              </Card>
-            ),
-          },
-        ]}
-      />
-    </Stack>
+    <Tabs
+      defaultValue="audit"
+      className="flex min-h-0 flex-1 flex-col"
+      actions={
+        isAdminUser ? (
+          <div className="flex items-center gap-2">
+            <Button
+              variant="secondary"
+              size="sm"
+              onClick={() => handleExport('csv')}
+              disabled={exportAction.isPending}
+              aria-label={t('logs.audit.export.csvLabel')}
+            >
+              {exportAction.isPending
+                ? t('logs.audit.export.inProgress')
+                : t('logs.audit.export.csv')}
+            </Button>
+            <Button
+              variant="secondary"
+              size="sm"
+              onClick={() => handleExport('json')}
+              disabled={exportAction.isPending}
+              aria-label={t('logs.audit.export.jsonLabel')}
+            >
+              {exportAction.isPending
+                ? t('logs.audit.export.inProgress')
+                : t('logs.audit.export.json')}
+            </Button>
+          </div>
+        ) : undefined
+      }
+      items={[
+        {
+          value: 'audit',
+          label: t('logs.auditLogs'),
+          content: (
+            <AuditLogTable
+              organizationId={organizationId}
+              paginatedResult={paginatedResult}
+              category={search.category}
+              userEmailMap={userEmailMap}
+            />
+          ),
+        },
+        {
+          value: 'activity',
+          label: t('logs.activityLogs'),
+          content: (
+            <Text variant="muted" className="text-sm">
+              {t('logs.activityComingSoon')}
+            </Text>
+          ),
+        },
+        {
+          value: 'errors',
+          label: t('logs.errorLogs'),
+          content: (
+            <Text variant="muted" className="text-sm">
+              {t('logs.errorComingSoon')}
+            </Text>
+          ),
+        },
+      ]}
+    />
   );
 }
diff --git a/services/platform/app/routes/dashboard/$id/settings/providers/$providerName.tsx b/services/platform/app/routes/dashboard/$id/settings/providers/$providerName.tsx
index 0851db52da..2474802433 100644
--- a/services/platform/app/routes/dashboard/$id/settings/providers/$providerName.tsx
+++ b/services/platform/app/routes/dashboard/$id/settings/providers/$providerName.tsx
@@ -1,5 +1,5 @@
 import { createFileRoute, Link } from '@tanstack/react-router';
-import { ChevronRight, Pencil, Trash2 } from 'lucide-react';
+import { ChevronRight, Loader2, Pencil, Trash2, X } from 'lucide-react';
 import { useCallback, useState } from 'react';
 
 import {
@@ -11,18 +11,18 @@ import {
   TableRow,
 } from '@/app/components/ui/data-display/table';
 import { ConfirmDialog } from '@/app/components/ui/dialog/confirm-dialog';
-import { FormDialog } from '@/app/components/ui/dialog/form-dialog';
 import { Badge } from '@/app/components/ui/feedback/badge';
 import { Skeleton } from '@/app/components/ui/feedback/skeleton';
 import { Checkbox } from '@/app/components/ui/forms/checkbox';
 import { Input } from '@/app/components/ui/forms/input';
-import { Select } from '@/app/components/ui/forms/select';
 import { Textarea } from '@/app/components/ui/forms/textarea';
 import { Card } from '@/app/components/ui/layout/card';
 import { HStack, Stack } from '@/app/components/ui/layout/layout';
+import { Sheet } from '@/app/components/ui/overlays/sheet';
 import { Button } from '@/app/components/ui/primitives/button';
 import { IconButton } from '@/app/components/ui/primitives/icon-button';
 import { Text } from '@/app/components/ui/typography/text';
+import { ProviderEditPanel } from '@/app/features/settings/providers/components/provider-edit-panel';
 import { useSaveProviderSecret } from '@/app/features/settings/providers/hooks/mutations';
 import {
   useHasProviderSecret,
@@ -162,9 +162,8 @@ function ProviderDetailContent({
         </Text>
       </HStack>
 
-      <GeneralSection />
+      <GeneralSection providerName={providerName} />
       <ApiKeySection providerName={providerName} />
-      <DefaultModelsSection />
       <ModelsSection
         providerName={providerName}
         maskedModelKeys={maskedModelKeys}
@@ -194,40 +193,19 @@ function InfoRow({
   );
 }
 
-function GeneralSection() {
+function GeneralSection({ providerName }: { providerName: string }) {
   const { t } = useT('settings');
-  const { config, saveConfig, isSaving } = useProviderConfig();
-  const [dialogOpen, setDialogOpen] = useState(false);
-  const [form, setForm] = useState({
-    displayName: '',
-    description: '',
-    baseUrl: '',
-  });
-
-  const openDialog = useCallback(() => {
-    setForm({
-      displayName: config.displayName,
-      description: config.description ?? '',
-      baseUrl: config.baseUrl,
-    });
-    setDialogOpen(true);
-  }, [config]);
+  const { config } = useProviderConfig();
+  const [panelOpen, setPanelOpen] = useState(false);
 
-  const handleSubmit = useCallback(
-    async (e: React.FormEvent) => {
-      e.preventDefault();
-      try {
-        await saveConfig({
-          displayName: form.displayName,
-          description: form.description || undefined,
-          baseUrl: form.baseUrl,
-        });
-        setDialogOpen(false);
-      } catch {
-        toast({ title: t('providers.saveFailed'), variant: 'destructive' });
-      }
+  const modelDisplayName = useCallback(
+    (modelId: string | undefined) => {
+      if (!modelId) return '—';
+      return (
+        config.models.find((m) => m.id === modelId)?.displayName ?? modelId
+      );
     },
-    [form, saveConfig, t],
+    [config.models],
   );
 
   return (
@@ -239,7 +217,7 @@ function GeneralSection() {
           </Text>
           <button
             type="button"
-            onClick={openDialog}
+            onClick={() => setPanelOpen(true)}
             className="text-muted-foreground hover:text-foreground flex items-center gap-1.5 text-[13px] font-medium"
           >
             <Pencil className="size-3.5" />
@@ -257,53 +235,56 @@ function GeneralSection() {
         </Stack>
       </Card>
 
-      <FormDialog
-        open={dialogOpen}
-        onOpenChange={setDialogOpen}
-        title={t('providers.editGeneral')}
-        onSubmit={handleSubmit}
-        isSubmitting={isSaving}
-        isDirty={
-          form.displayName !== config.displayName ||
-          form.description !== (config.description ?? '') ||
-          form.baseUrl !== config.baseUrl
-        }
-      >
-        <Stack gap={4}>
-          <Input
-            label={t('providers.displayName')}
-            value={form.displayName}
-            onChange={(e) =>
-              setForm((f) => ({ ...f, displayName: e.target.value }))
-            }
-            placeholder={t('providers.displayNamePlaceholder')}
-            autoFocus
-          />
-          <Textarea
-            label={t('providers.description_field')}
-            value={form.description}
-            onChange={(e) =>
-              setForm((f) => ({ ...f, description: e.target.value }))
-            }
-            placeholder={t('providers.descriptionPlaceholder')}
-            rows={3}
-          />
-          <Input
-            label={t('providers.baseUrl')}
-            value={form.baseUrl}
-            onChange={(e) =>
-              setForm((f) => ({ ...f, baseUrl: e.target.value }))
-            }
-            placeholder={t('providers.baseUrlPlaceholder')}
-          />
+      <Card contentClassName="p-5">
+        <HStack justify="between" align="start" className="border-b pb-4">
+          <Stack gap={1}>
+            <Text className="text-sm font-semibold">
+              {t('providers.defaultModels')}
+            </Text>
+            <Text className="text-muted-foreground text-[13px]">
+              {t('providers.defaultModelsDescription')}
+            </Text>
+          </Stack>
+          <button
+            type="button"
+            onClick={() => setPanelOpen(true)}
+            className="text-muted-foreground hover:text-foreground flex shrink-0 items-center gap-1.5 text-[13px] font-medium"
+          >
+            <Pencil className="size-3.5" />
+            {t('providers.editGeneral')}
+          </button>
+        </HStack>
+        <Stack className="divide-y">
+          <InfoRow label={t('providers.tagChat')}>
+            <Text className="text-sm font-medium">
+              {modelDisplayName(config.defaults?.chat)}
+            </Text>
+          </InfoRow>
+          <InfoRow label={t('providers.tagVision')}>
+            <Text className="text-sm font-medium">
+              {modelDisplayName(config.defaults?.vision)}
+            </Text>
+          </InfoRow>
+          <InfoRow label={t('providers.tagEmbedding')}>
+            <Text className="text-sm font-medium">
+              {modelDisplayName(config.defaults?.embedding)}
+            </Text>
+          </InfoRow>
         </Stack>
-      </FormDialog>
+      </Card>
+
+      <ProviderEditPanel
+        open={panelOpen}
+        onOpenChange={setPanelOpen}
+        providerName={providerName}
+      />
     </>
   );
 }
 
 function ApiKeySection({ providerName }: { providerName: string }) {
   const { t } = useT('settings');
+  const { t: tCommon } = useT('common');
   const { data: maskedKey } = useHasProviderSecret('default', providerName);
   const hasSecret = maskedKey != null;
   const saveSecret = useSaveProviderSecret();
@@ -372,7 +353,7 @@ function ApiKeySection({ providerName }: { providerName: string }) {
         </HStack>
       </Card>
 
-      <FormDialog
+      <Sheet
         open={dialogOpen}
         onOpenChange={(open) => {
           setDialogOpen(open);
@@ -381,27 +362,71 @@ function ApiKeySection({ providerName }: { providerName: string }) {
         title={
           hasSecret ? t('providers.replaceApiKey') : t('providers.addApiKey')
         }
-        description={
-          hasSecret
-            ? t('providers.replaceApiKeyDescription', {
-                maskedKey: maskedKey ?? '',
-              })
-            : undefined
-        }
-        onSubmit={handleSaveKey}
-        isSubmitting={saving}
-        isDirty={apiKey.trim().length > 0}
-        submitText={t('providers.saveKey')}
-        submittingText={t('providers.saving')}
+        size="md"
+        hideClose
+        className="flex flex-col gap-0 p-0"
       >
-        <Input
-          type="password"
-          placeholder={t('providers.apiKeyEnter')}
-          value={apiKey}
-          onChange={(e) => setApiKey(e.target.value)}
-          autoFocus
-        />
-      </FormDialog>
+        <HStack
+          justify="between"
+          align="center"
+          className="border-border shrink-0 border-b p-4 sm:px-6 sm:py-4"
+        >
+          <Text variant="label" className="text-base font-semibold">
+            {hasSecret
+              ? t('providers.replaceApiKey')
+              : t('providers.addApiKey')}
+          </Text>
+          <IconButton
+            icon={X}
+            aria-label={tCommon('aria.close')}
+            variant="ghost"
+            onClick={() => {
+              setDialogOpen(false);
+              setApiKey('');
+            }}
+          />
+        </HStack>
+
+        <form onSubmit={handleSaveKey} className="flex min-h-0 flex-1 flex-col">
+          <div className="flex-1 overflow-y-auto p-4 sm:px-6 sm:py-5">
+            <Stack gap={4}>
+              {hasSecret && (
+                <Text className="text-muted-foreground text-sm">
+                  {t('providers.replaceApiKeyDescription', {
+                    maskedKey: maskedKey ?? '',
+                  })}
+                </Text>
+              )}
+              <Input
+                type="password"
+                label={t('providers.apiKey')}
+                placeholder={t('providers.apiKeyEnter')}
+                value={apiKey}
+                onChange={(e) => setApiKey(e.target.value)}
+                autoFocus
+              />
+            </Stack>
+          </div>
+
+          <div className="border-border shrink-0 border-t p-4 sm:px-6 sm:py-4">
+            <HStack justify="end" align="center">
+              <Button
+                type="submit"
+                disabled={saving || apiKey.trim().length === 0}
+              >
+                {saving ? (
+                  <>
+                    <Loader2 className="mr-2 size-4 animate-spin" />
+                    {t('providers.saving')}
+                  </>
+                ) : (
+                  t('providers.saveKey')
+                )}
+              </Button>
+            </HStack>
+          </div>
+        </form>
+      </Sheet>
     </>
   );
 }
@@ -438,6 +463,7 @@ function ModelsSection({
   maskedModelKeys: Record<string, string>;
 }) {
   const { t } = useT('settings');
+  const { t: tCommon } = useT('common');
   const { config, saveConfig, isSaving } = useProviderConfig();
   const saveSecret = useSaveProviderSecret();
   const [dialogOpen, setDialogOpen] = useState(false);
@@ -678,7 +704,7 @@ function ModelsSection({
         </div>
       </Stack>
 
-      <FormDialog
+      <Sheet
         open={dialogOpen}
         onOpenChange={(open) => {
           setDialogOpen(open);
@@ -689,191 +715,241 @@ function ModelsSection({
             ? t('providers.editModel')
             : t('providers.addModel')
         }
-        onSubmit={handleSubmitModel}
-        isSubmitting={isSaving || savingSecret}
-        isDirty={
-          form.id.trim().length > 0 &&
-          form.displayName.trim().length > 0 &&
-          (editingIndex == null ||
-            modelKeyAction === 'remove' ||
-            JSON.stringify(form) !== JSON.stringify(initialForm))
-        }
-        submitText={
-          editingIndex != null ? t('providers.save') : t('providers.addModel')
-        }
-        large
-        className="sm:max-w-lg"
+        size="md"
+        hideClose
+        className="flex flex-col gap-0 p-0"
       >
-        <Stack gap={4}>
-          <Input
-            label={t('providers.modelId')}
-            value={form.id}
-            onChange={(e) => setForm((f) => ({ ...f, id: e.target.value }))}
-            placeholder={t('providers.modelIdPlaceholder')}
-            autoFocus
-          />
-          <Input
-            label={t('providers.displayName')}
-            value={form.displayName}
-            onChange={(e) =>
-              setForm((f) => ({ ...f, displayName: e.target.value }))
-            }
-            placeholder={t('providers.modelDisplayNamePlaceholder')}
-          />
-          <Textarea
-            label={t('providers.description_field')}
-            value={form.description}
-            onChange={(e) =>
-              setForm((f) => ({ ...f, description: e.target.value }))
-            }
-            placeholder={t('providers.modelDescriptionPlaceholder')}
-            rows={2}
+        <HStack
+          justify="between"
+          align="center"
+          className="border-border shrink-0 border-b p-4 sm:px-6 sm:py-4"
+        >
+          <Text variant="label" className="text-base font-semibold">
+            {editingIndex != null
+              ? t('providers.editModel')
+              : t('providers.addModel')}
+          </Text>
+          <IconButton
+            icon={X}
+            aria-label={tCommon('aria.close')}
+            variant="ghost"
+            onClick={() => {
+              setDialogOpen(false);
+              setForm(EMPTY_MODEL_FORM);
+            }}
           />
-          <HStack gap={4} align="center" className="flex-wrap">
-            {(['chat', 'vision', 'embedding'] as const).map((tag) => (
-              <label key={tag} className="flex items-center gap-1.5 text-sm">
-                <Checkbox
-                  checked={form.tags.includes(tag)}
-                  onCheckedChange={(checked) => {
+        </HStack>
+
+        <form
+          onSubmit={handleSubmitModel}
+          className="flex min-h-0 flex-1 flex-col"
+        >
+          <div className="flex-1 overflow-y-auto p-4 sm:px-6 sm:py-5">
+            <Stack gap={4}>
+              <Input
+                label={t('providers.modelId')}
+                value={form.id}
+                onChange={(e) => setForm((f) => ({ ...f, id: e.target.value }))}
+                placeholder={t('providers.modelIdPlaceholder')}
+                autoFocus
+              />
+              <Input
+                label={t('providers.displayName')}
+                value={form.displayName}
+                onChange={(e) =>
+                  setForm((f) => ({ ...f, displayName: e.target.value }))
+                }
+                placeholder={t('providers.modelDisplayNamePlaceholder')}
+              />
+              <Textarea
+                label={t('providers.description_field')}
+                value={form.description}
+                onChange={(e) =>
+                  setForm((f) => ({ ...f, description: e.target.value }))
+                }
+                placeholder={t('providers.modelDescriptionPlaceholder')}
+                rows={2}
+              />
+              <HStack gap={4} align="center" className="flex-wrap">
+                {(['chat', 'vision', 'embedding'] as const).map((tag) => (
+                  <label
+                    key={tag}
+                    className="flex items-center gap-1.5 text-sm"
+                  >
+                    <Checkbox
+                      checked={form.tags.includes(tag)}
+                      onCheckedChange={(checked) => {
+                        setForm((f) => ({
+                          ...f,
+                          tags: checked
+                            ? [...f.tags, tag]
+                            : f.tags.filter((v) => v !== tag),
+                        }));
+                      }}
+                    />
+                    {tag === 'chat'
+                      ? t('providers.tagChat')
+                      : tag === 'vision'
+                        ? t('providers.tagVision')
+                        : tag === 'embedding'
+                          ? t('providers.tagEmbedding')
+                          : tag}
+                  </label>
+                ))}
+              </HStack>
+              {form.tags.includes('embedding') && (
+                <Input
+                  label={t('providers.dimensions')}
+                  type="number"
+                  value={form.dimensions}
+                  onChange={(e) =>
+                    setForm((f) => ({ ...f, dimensions: e.target.value }))
+                  }
+                  placeholder="e.g., 1536"
+                />
+              )}
+              <HStack gap={3}>
+                <Input
+                  label="Input cost (USD / 1M tokens)"
+                  type="number"
+                  value={form.inputCostPerMillion}
+                  onChange={(e) =>
                     setForm((f) => ({
                       ...f,
-                      tags: checked
-                        ? [...f.tags, tag]
-                        : f.tags.filter((v) => v !== tag),
-                    }));
-                  }}
+                      inputCostPerMillion: e.target.value,
+                    }))
+                  }
+                  placeholder="e.g., 2.50"
+                  min={0}
+                  step={0.01}
+                />
+                <Input
+                  label="Output cost (USD / 1M tokens)"
+                  type="number"
+                  value={form.outputCostPerMillion}
+                  onChange={(e) =>
+                    setForm((f) => ({
+                      ...f,
+                      outputCostPerMillion: e.target.value,
+                    }))
+                  }
+                  placeholder="e.g., 10.00"
+                  min={0}
+                  step={0.01}
                 />
-                {tag === 'chat'
-                  ? t('providers.tagChat')
-                  : tag === 'vision'
-                    ? t('providers.tagVision')
-                    : tag === 'embedding'
-                      ? t('providers.tagEmbedding')
-                      : tag}
-              </label>
-            ))}
-          </HStack>
-          {form.tags.includes('embedding') && (
-            <Input
-              label={t('providers.dimensions')}
-              type="number"
-              value={form.dimensions}
-              onChange={(e) =>
-                setForm((f) => ({ ...f, dimensions: e.target.value }))
-              }
-              placeholder="e.g., 1536"
-            />
-          )}
-          <HStack gap={3}>
-            <Input
-              label="Input cost (USD / 1M tokens)"
-              type="number"
-              value={form.inputCostPerMillion}
-              onChange={(e) =>
-                setForm((f) => ({
-                  ...f,
-                  inputCostPerMillion: e.target.value,
-                }))
-              }
-              placeholder="e.g., 2.50"
-              min={0}
-              step={0.01}
-            />
-            <Input
-              label="Output cost (USD / 1M tokens)"
-              type="number"
-              value={form.outputCostPerMillion}
-              onChange={(e) =>
-                setForm((f) => ({
-                  ...f,
-                  outputCostPerMillion: e.target.value,
-                }))
-              }
-              placeholder="e.g., 10.00"
-              min={0}
-              step={0.01}
-            />
-          </HStack>
-          <Text className="text-muted-foreground text-xs">
-            {t('providers.costHelp')}
-          </Text>
-          <Input
-            label={t('providers.modelBaseUrl')}
-            value={form.baseUrl}
-            onChange={(e) =>
-              setForm((f) => ({ ...f, baseUrl: e.target.value }))
-            }
-            placeholder={t('providers.modelBaseUrlPlaceholder')}
-          />
-          <Text className="text-muted-foreground text-xs">
-            {t('providers.modelBaseUrlHelp')}
-          </Text>
-          {maskedModelKeys[form.id] && modelKeyAction === 'none' ? (
-            <HStack gap={2} align="center" className="flex-wrap">
-              <Badge variant="green" dot>
-                {t('providers.modelApiKeyConfigured')}
-              </Badge>
-              <Text className="text-muted-foreground font-mono text-sm">
-                {maskedModelKeys[form.id]}
-              </Text>
-              <HStack gap={3}>
-                <button
-                  type="button"
-                  onClick={() => setModelKeyAction('replace')}
-                  className="text-muted-foreground hover:text-foreground text-xs font-medium"
-                >
-                  {t('providers.editKey')}
-                </button>
-                <button
-                  type="button"
-                  onClick={() => setModelKeyAction('remove')}
-                  className="text-muted-foreground hover:text-destructive text-xs font-medium"
-                >
-                  {t('providers.deleteModelApiKey')}
-                </button>
               </HStack>
-            </HStack>
-          ) : maskedModelKeys[form.id] && modelKeyAction === 'remove' ? (
-            <HStack gap={2} align="center">
-              <Badge variant="outline">
-                {t('providers.modelApiKeyNotConfigured')}
-              </Badge>
-              <button
-                type="button"
-                onClick={() => setModelKeyAction('none')}
-                className="text-muted-foreground hover:text-foreground text-xs font-medium"
-              >
-                {t('providers.undoRemoveKey')}
-              </button>
-            </HStack>
-          ) : (
-            <>
-              {modelKeyAction === 'replace' && (
-                <HStack gap={2} align="center">
+              <Text className="text-muted-foreground text-xs">
+                {t('providers.costHelp')}
+              </Text>
+              <Input
+                label={t('providers.modelBaseUrl')}
+                value={form.baseUrl}
+                onChange={(e) =>
+                  setForm((f) => ({ ...f, baseUrl: e.target.value }))
+                }
+                placeholder={t('providers.modelBaseUrlPlaceholder')}
+              />
+              <Text className="text-muted-foreground text-xs">
+                {t('providers.modelBaseUrlHelp')}
+              </Text>
+              {maskedModelKeys[form.id] && modelKeyAction === 'none' ? (
+                <HStack gap={2} align="center" className="flex-wrap">
                   <Badge variant="green" dot>
                     {t('providers.modelApiKeyConfigured')}
                   </Badge>
                   <Text className="text-muted-foreground font-mono text-sm">
                     {maskedModelKeys[form.id]}
                   </Text>
+                  <HStack gap={3}>
+                    <button
+                      type="button"
+                      onClick={() => setModelKeyAction('replace')}
+                      className="text-muted-foreground hover:text-foreground text-xs font-medium"
+                    >
+                      {t('providers.editKey')}
+                    </button>
+                    <button
+                      type="button"
+                      onClick={() => setModelKeyAction('remove')}
+                      className="text-muted-foreground hover:text-destructive text-xs font-medium"
+                    >
+                      {t('providers.deleteModelApiKey')}
+                    </button>
+                  </HStack>
+                </HStack>
+              ) : maskedModelKeys[form.id] && modelKeyAction === 'remove' ? (
+                <HStack gap={2} align="center">
+                  <Badge variant="outline">
+                    {t('providers.modelApiKeyNotConfigured')}
+                  </Badge>
+                  <button
+                    type="button"
+                    onClick={() => setModelKeyAction('none')}
+                    className="text-muted-foreground hover:text-foreground text-xs font-medium"
+                  >
+                    {t('providers.undoRemoveKey')}
+                  </button>
                 </HStack>
+              ) : (
+                <>
+                  {modelKeyAction === 'replace' && (
+                    <HStack gap={2} align="center">
+                      <Badge variant="green" dot>
+                        {t('providers.modelApiKeyConfigured')}
+                      </Badge>
+                      <Text className="text-muted-foreground font-mono text-sm">
+                        {maskedModelKeys[form.id]}
+                      </Text>
+                    </HStack>
+                  )}
+                  <Input
+                    label={t('providers.modelApiKey')}
+                    type="password"
+                    value={form.apiKey}
+                    onChange={(e) =>
+                      setForm((f) => ({ ...f, apiKey: e.target.value }))
+                    }
+                    placeholder={t('providers.modelApiKeyPlaceholder')}
+                  />
+                  <Text className="text-muted-foreground text-xs">
+                    {t('providers.modelApiKeyHelp')}
+                  </Text>
+                </>
               )}
-              <Input
-                label={t('providers.modelApiKey')}
-                type="password"
-                value={form.apiKey}
-                onChange={(e) =>
-                  setForm((f) => ({ ...f, apiKey: e.target.value }))
+            </Stack>
+          </div>
+
+          <div className="border-border shrink-0 border-t p-4 sm:px-6 sm:py-4">
+            <HStack justify="end" align="center">
+              <Button
+                type="submit"
+                disabled={
+                  isSaving ||
+                  savingSecret ||
+                  !(
+                    form.id.trim().length > 0 &&
+                    form.displayName.trim().length > 0 &&
+                    (editingIndex == null ||
+                      modelKeyAction === 'remove' ||
+                      JSON.stringify(form) !== JSON.stringify(initialForm))
+                  )
                 }
-                placeholder={t('providers.modelApiKeyPlaceholder')}
-              />
-              <Text className="text-muted-foreground text-xs">
-                {t('providers.modelApiKeyHelp')}
-              </Text>
-            </>
-          )}
-        </Stack>
-      </FormDialog>
+              >
+                {isSaving || savingSecret ? (
+                  <>
+                    <Loader2 className="mr-2 size-4 animate-spin" />
+                    {t('providers.saving')}
+                  </>
+                ) : editingIndex != null ? (
+                  t('providers.save')
+                ) : (
+                  t('providers.addModel')
+                )}
+              </Button>
+            </HStack>
+          </div>
+        </form>
+      </Sheet>
 
       <ConfirmDialog
         open={deleteIndex != null}
@@ -896,130 +972,3 @@ function ModelsSection({
     </>
   );
 }
-
-const NONE_VALUE = '__none__';
-
-function DefaultModelsSection() {
-  const { t } = useT('settings');
-  const { config, saveConfig } = useProviderConfig();
-  const [dialogOpen, setDialogOpen] = useState(false);
-  const [form, setForm] = useState<Record<string, string>>({});
-
-  const modelDisplayName = useCallback(
-    (modelId: string | undefined) => {
-      if (!modelId) return '—';
-      return (
-        config.models.find((m) => m.id === modelId)?.displayName ?? modelId
-      );
-    },
-    [config.models],
-  );
-
-  const openDialog = useCallback(() => {
-    setForm({ ...config.defaults });
-    setDialogOpen(true);
-  }, [config.defaults]);
-
-  const handleSubmit = useCallback(
-    async (e: React.FormEvent) => {
-      e.preventDefault();
-      const cleaned = Object.fromEntries(
-        Object.entries(form).filter(([, v]) => v && v !== NONE_VALUE),
-      );
-      try {
-        await saveConfig({
-          defaults: Object.keys(cleaned).length > 0 ? cleaned : undefined,
-        });
-        setDialogOpen(false);
-      } catch {
-        toast({ title: t('providers.saveFailed'), variant: 'destructive' });
-      }
-    },
-    [form, saveConfig, t],
-  );
-
-  return (
-    <>
-      <Card contentClassName="p-5">
-        <HStack justify="between" align="start" className="border-b pb-4">
-          <Stack gap={1}>
-            <Text className="text-sm font-semibold">
-              {t('providers.defaultModels')}
-            </Text>
-            <Text className="text-muted-foreground text-[13px]">
-              {t('providers.defaultModelsDescription')}
-            </Text>
-          </Stack>
-          <button
-            type="button"
-            onClick={openDialog}
-            className="text-muted-foreground hover:text-foreground flex shrink-0 items-center gap-1.5 text-[13px] font-medium"
-          >
-            <Pencil className="size-3.5" />
-            {t('providers.editGeneral')}
-          </button>
-        </HStack>
-        <Stack className="divide-y">
-          <InfoRow label={t('providers.tagChat')}>
-            <Text className="text-sm font-medium">
-              {modelDisplayName(config.defaults?.chat)}
-            </Text>
-          </InfoRow>
-          <InfoRow label={t('providers.tagVision')}>
-            <Text className="text-sm font-medium">
-              {modelDisplayName(config.defaults?.vision)}
-            </Text>
-          </InfoRow>
-          <InfoRow label={t('providers.tagEmbedding')}>
-            <Text className="text-sm font-medium">
-              {modelDisplayName(config.defaults?.embedding)}
-            </Text>
-          </InfoRow>
-        </Stack>
-      </Card>
-
-      <FormDialog
-        open={dialogOpen}
-        onOpenChange={setDialogOpen}
-        title={t('providers.defaultModels')}
-        onSubmit={handleSubmit}
-        isDirty={
-          form.chat !== (config.defaults?.chat ?? NONE_VALUE) ||
-          form.vision !== (config.defaults?.vision ?? NONE_VALUE) ||
-          form.embedding !== (config.defaults?.embedding ?? NONE_VALUE)
-        }
-      >
-        <Stack gap={4}>
-          {(['chat', 'vision', 'embedding'] as const).map((tag) => {
-            const modelsWithTag = config.models.filter((m) =>
-              (m.tags as readonly string[]).includes(tag),
-            );
-            return (
-              <Select
-                key={tag}
-                label={
-                  tag === 'chat'
-                    ? t('providers.tagChat')
-                    : tag === 'vision'
-                      ? t('providers.tagVision')
-                      : t('providers.tagEmbedding')
-                }
-                options={[
-                  { value: NONE_VALUE, label: t('providers.defaultNone') },
-                  ...modelsWithTag.map((m) => ({
-                    value: m.id,
-                    label: m.displayName,
-                  })),
-                ]}
-                value={form[tag] ?? NONE_VALUE}
-                onValueChange={(value) =>
-                  setForm((f) => ({ ...f, [tag]: value }))
-                }
-              />
-            );
-          })}
-        </Stack>
-      </FormDialog>
-    </>
-  );
-}
diff --git a/services/platform/convex/_generated/api.d.ts b/services/platform/convex/_generated/api.d.ts
index 7aa8d1adee..fd6ac10542 100644
--- a/services/platform/convex/_generated/api.d.ts
+++ b/services/platform/convex/_generated/api.d.ts
@@ -1903,13 +1903,9133 @@ export declare const internal: FilterApi<
 >;
 
 export declare const components: {
-  betterAuth: import("../betterAuth/_generated/component.js").ComponentApi<"betterAuth">;
-  workflow: import("@convex-dev/workflow/_generated/component.js").ComponentApi<"workflow">;
-  workflow_1: import("@convex-dev/workflow/_generated/component.js").ComponentApi<"workflow_1">;
-  workflow_2: import("@convex-dev/workflow/_generated/component.js").ComponentApi<"workflow_2">;
-  workflow_3: import("@convex-dev/workflow/_generated/component.js").ComponentApi<"workflow_3">;
-  agent: import("@convex-dev/agent/_generated/component.js").ComponentApi<"agent">;
-  rateLimiter: import("@convex-dev/rate-limiter/_generated/component.js").ComponentApi<"rateLimiter">;
-  actionCache: import("@convex-dev/action-cache/_generated/component.js").ComponentApi<"actionCache">;
-  persistentTextStreaming: import("@convex-dev/persistent-text-streaming/_generated/component.js").ComponentApi<"persistentTextStreaming">;
+  betterAuth: {
+    adapter: {
+      create: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          input:
+            | {
+                data: {
+                  createdAt: number;
+                  email: string;
+                  emailVerified: boolean;
+                  image?: null | string;
+                  name: string;
+                  updatedAt: number;
+                  userId?: null | string;
+                };
+                model: "user";
+              }
+            | {
+                data: {
+                  activeOrganizationId?: null | string;
+                  activeTeamId?: null | string;
+                  createdAt: number;
+                  expiresAt: number;
+                  ipAddress?: null | string;
+                  token: string;
+                  trustedRole?: null | string;
+                  trustedTeams?: null | string;
+                  updatedAt: number;
+                  userAgent?: null | string;
+                  userId: string;
+                };
+                model: "session";
+              }
+            | {
+                data: {
+                  accessToken?: null | string;
+                  accessTokenExpiresAt?: null | number;
+                  accountId: string;
+                  createdAt: number;
+                  idToken?: null | string;
+                  password?: null | string;
+                  providerId: string;
+                  refreshToken?: null | string;
+                  refreshTokenExpiresAt?: null | number;
+                  scope?: null | string;
+                  updatedAt: number;
+                  userId: string;
+                };
+                model: "account";
+              }
+            | {
+                data: {
+                  createdAt: number;
+                  expiresAt: number;
+                  identifier: string;
+                  updatedAt: number;
+                  value: string;
+                };
+                model: "verification";
+              }
+            | {
+                data: {
+                  createdAt: number;
+                  expiresAt?: null | number;
+                  privateKey: string;
+                  publicKey: string;
+                };
+                model: "jwks";
+              }
+            | {
+                data: {
+                  createdAt: number;
+                  logo?: null | string;
+                  metadata?: null | string;
+                  name: string;
+                  slug: string;
+                };
+                model: "organization";
+              }
+            | {
+                data: {
+                  createdAt: number;
+                  name: string;
+                  organizationId: string;
+                  updatedAt?: null | number;
+                };
+                model: "team";
+              }
+            | {
+                data: {
+                  createdAt?: null | number;
+                  teamId: string;
+                  userId: string;
+                };
+                model: "teamMember";
+              }
+            | {
+                data: {
+                  createdAt: number;
+                  organizationId: string;
+                  role: string;
+                  userId: string;
+                };
+                model: "member";
+              }
+            | {
+                data: {
+                  createdAt: number;
+                  email: string;
+                  expiresAt: number;
+                  inviterId: string;
+                  organizationId: string;
+                  role?: null | string;
+                  status: string;
+                  teamId?: null | string;
+                };
+                model: "invitation";
+              }
+            | {
+                data: {
+                  createdAt: number;
+                  enabled?: null | boolean;
+                  expiresAt?: null | number;
+                  key: string;
+                  lastRefillAt?: null | number;
+                  lastRequest?: null | number;
+                  metadata?: null | string;
+                  name?: null | string;
+                  permissions?: null | string;
+                  prefix?: null | string;
+                  rateLimitEnabled?: null | boolean;
+                  rateLimitMax?: null | number;
+                  rateLimitTimeWindow?: null | number;
+                  refillAmount?: null | number;
+                  refillInterval?: null | number;
+                  remaining?: null | number;
+                  requestCount?: null | number;
+                  start?: null | string;
+                  updatedAt: number;
+                  userId: string;
+                };
+                model: "apikey";
+              };
+          onCreateHandle?: string;
+          select?: Array<string>;
+        },
+        any
+      >;
+      deleteMany: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          input:
+            | {
+                model: "user";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "name"
+                    | "email"
+                    | "emailVerified"
+                    | "image"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "userId"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "session";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "expiresAt"
+                    | "token"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "ipAddress"
+                    | "userAgent"
+                    | "userId"
+                    | "activeOrganizationId"
+                    | "activeTeamId"
+                    | "trustedRole"
+                    | "trustedTeams"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "account";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "accountId"
+                    | "providerId"
+                    | "userId"
+                    | "accessToken"
+                    | "refreshToken"
+                    | "idToken"
+                    | "accessTokenExpiresAt"
+                    | "refreshTokenExpiresAt"
+                    | "scope"
+                    | "password"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "verification";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "identifier"
+                    | "value"
+                    | "expiresAt"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "jwks";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "publicKey"
+                    | "privateKey"
+                    | "createdAt"
+                    | "expiresAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "organization";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "name"
+                    | "slug"
+                    | "logo"
+                    | "createdAt"
+                    | "metadata"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "team";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "name"
+                    | "organizationId"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "teamMember";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field: "teamId" | "userId" | "createdAt" | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "member";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "organizationId"
+                    | "userId"
+                    | "role"
+                    | "createdAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "invitation";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "organizationId"
+                    | "email"
+                    | "role"
+                    | "teamId"
+                    | "status"
+                    | "expiresAt"
+                    | "createdAt"
+                    | "inviterId"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "apikey";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "name"
+                    | "start"
+                    | "prefix"
+                    | "key"
+                    | "userId"
+                    | "refillInterval"
+                    | "refillAmount"
+                    | "lastRefillAt"
+                    | "enabled"
+                    | "rateLimitEnabled"
+                    | "rateLimitTimeWindow"
+                    | "rateLimitMax"
+                    | "requestCount"
+                    | "remaining"
+                    | "lastRequest"
+                    | "expiresAt"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "permissions"
+                    | "metadata"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              };
+          onDeleteHandle?: string;
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+        },
+        any
+      >;
+      deleteOne: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          input:
+            | {
+                model: "user";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "name"
+                    | "email"
+                    | "emailVerified"
+                    | "image"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "userId"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "session";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "expiresAt"
+                    | "token"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "ipAddress"
+                    | "userAgent"
+                    | "userId"
+                    | "activeOrganizationId"
+                    | "activeTeamId"
+                    | "trustedRole"
+                    | "trustedTeams"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "account";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "accountId"
+                    | "providerId"
+                    | "userId"
+                    | "accessToken"
+                    | "refreshToken"
+                    | "idToken"
+                    | "accessTokenExpiresAt"
+                    | "refreshTokenExpiresAt"
+                    | "scope"
+                    | "password"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "verification";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "identifier"
+                    | "value"
+                    | "expiresAt"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "jwks";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "publicKey"
+                    | "privateKey"
+                    | "createdAt"
+                    | "expiresAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "organization";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "name"
+                    | "slug"
+                    | "logo"
+                    | "createdAt"
+                    | "metadata"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "team";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "name"
+                    | "organizationId"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "teamMember";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field: "teamId" | "userId" | "createdAt" | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "member";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "organizationId"
+                    | "userId"
+                    | "role"
+                    | "createdAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "invitation";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "organizationId"
+                    | "email"
+                    | "role"
+                    | "teamId"
+                    | "status"
+                    | "expiresAt"
+                    | "createdAt"
+                    | "inviterId"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "apikey";
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "name"
+                    | "start"
+                    | "prefix"
+                    | "key"
+                    | "userId"
+                    | "refillInterval"
+                    | "refillAmount"
+                    | "lastRefillAt"
+                    | "enabled"
+                    | "rateLimitEnabled"
+                    | "rateLimitTimeWindow"
+                    | "rateLimitMax"
+                    | "requestCount"
+                    | "remaining"
+                    | "lastRequest"
+                    | "expiresAt"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "permissions"
+                    | "metadata"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              };
+          onDeleteHandle?: string;
+        },
+        any
+      >;
+      findMany: FunctionReference<
+        "query",
+        "internal",
+        {
+          join?: any;
+          limit?: number;
+          model:
+            | "user"
+            | "session"
+            | "account"
+            | "verification"
+            | "jwks"
+            | "organization"
+            | "team"
+            | "teamMember"
+            | "member"
+            | "invitation"
+            | "apikey";
+          offset?: number;
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+          select?: Array<string>;
+          sortBy?: { direction: "asc" | "desc"; field: string };
+          where?: Array<{
+            connector?: "AND" | "OR";
+            field: string;
+            operator?:
+              | "lt"
+              | "lte"
+              | "gt"
+              | "gte"
+              | "eq"
+              | "in"
+              | "not_in"
+              | "ne"
+              | "contains"
+              | "starts_with"
+              | "ends_with";
+            value:
+              | string
+              | number
+              | boolean
+              | Array<string>
+              | Array<number>
+              | null;
+          }>;
+        },
+        any
+      >;
+      findOne: FunctionReference<
+        "query",
+        "internal",
+        {
+          join?: any;
+          model:
+            | "user"
+            | "session"
+            | "account"
+            | "verification"
+            | "jwks"
+            | "organization"
+            | "team"
+            | "teamMember"
+            | "member"
+            | "invitation"
+            | "apikey";
+          select?: Array<string>;
+          where?: Array<{
+            connector?: "AND" | "OR";
+            field: string;
+            operator?:
+              | "lt"
+              | "lte"
+              | "gt"
+              | "gte"
+              | "eq"
+              | "in"
+              | "not_in"
+              | "ne"
+              | "contains"
+              | "starts_with"
+              | "ends_with";
+            value:
+              | string
+              | number
+              | boolean
+              | Array<string>
+              | Array<number>
+              | null;
+          }>;
+        },
+        any
+      >;
+      updateMany: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          input:
+            | {
+                model: "user";
+                update: {
+                  createdAt?: number;
+                  email?: string;
+                  emailVerified?: boolean;
+                  image?: null | string;
+                  name?: string;
+                  updatedAt?: number;
+                  userId?: null | string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "name"
+                    | "email"
+                    | "emailVerified"
+                    | "image"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "userId"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "session";
+                update: {
+                  activeOrganizationId?: null | string;
+                  activeTeamId?: null | string;
+                  createdAt?: number;
+                  expiresAt?: number;
+                  ipAddress?: null | string;
+                  token?: string;
+                  trustedRole?: null | string;
+                  trustedTeams?: null | string;
+                  updatedAt?: number;
+                  userAgent?: null | string;
+                  userId?: string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "expiresAt"
+                    | "token"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "ipAddress"
+                    | "userAgent"
+                    | "userId"
+                    | "activeOrganizationId"
+                    | "activeTeamId"
+                    | "trustedRole"
+                    | "trustedTeams"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "account";
+                update: {
+                  accessToken?: null | string;
+                  accessTokenExpiresAt?: null | number;
+                  accountId?: string;
+                  createdAt?: number;
+                  idToken?: null | string;
+                  password?: null | string;
+                  providerId?: string;
+                  refreshToken?: null | string;
+                  refreshTokenExpiresAt?: null | number;
+                  scope?: null | string;
+                  updatedAt?: number;
+                  userId?: string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "accountId"
+                    | "providerId"
+                    | "userId"
+                    | "accessToken"
+                    | "refreshToken"
+                    | "idToken"
+                    | "accessTokenExpiresAt"
+                    | "refreshTokenExpiresAt"
+                    | "scope"
+                    | "password"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "verification";
+                update: {
+                  createdAt?: number;
+                  expiresAt?: number;
+                  identifier?: string;
+                  updatedAt?: number;
+                  value?: string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "identifier"
+                    | "value"
+                    | "expiresAt"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "jwks";
+                update: {
+                  createdAt?: number;
+                  expiresAt?: null | number;
+                  privateKey?: string;
+                  publicKey?: string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "publicKey"
+                    | "privateKey"
+                    | "createdAt"
+                    | "expiresAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "organization";
+                update: {
+                  createdAt?: number;
+                  logo?: null | string;
+                  metadata?: null | string;
+                  name?: string;
+                  slug?: string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "name"
+                    | "slug"
+                    | "logo"
+                    | "createdAt"
+                    | "metadata"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "team";
+                update: {
+                  createdAt?: number;
+                  name?: string;
+                  organizationId?: string;
+                  updatedAt?: null | number;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "name"
+                    | "organizationId"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "teamMember";
+                update: {
+                  createdAt?: null | number;
+                  teamId?: string;
+                  userId?: string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field: "teamId" | "userId" | "createdAt" | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "member";
+                update: {
+                  createdAt?: number;
+                  organizationId?: string;
+                  role?: string;
+                  userId?: string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "organizationId"
+                    | "userId"
+                    | "role"
+                    | "createdAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "invitation";
+                update: {
+                  createdAt?: number;
+                  email?: string;
+                  expiresAt?: number;
+                  inviterId?: string;
+                  organizationId?: string;
+                  role?: null | string;
+                  status?: string;
+                  teamId?: null | string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "organizationId"
+                    | "email"
+                    | "role"
+                    | "teamId"
+                    | "status"
+                    | "expiresAt"
+                    | "createdAt"
+                    | "inviterId"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "apikey";
+                update: {
+                  createdAt?: number;
+                  enabled?: null | boolean;
+                  expiresAt?: null | number;
+                  key?: string;
+                  lastRefillAt?: null | number;
+                  lastRequest?: null | number;
+                  metadata?: null | string;
+                  name?: null | string;
+                  permissions?: null | string;
+                  prefix?: null | string;
+                  rateLimitEnabled?: null | boolean;
+                  rateLimitMax?: null | number;
+                  rateLimitTimeWindow?: null | number;
+                  refillAmount?: null | number;
+                  refillInterval?: null | number;
+                  remaining?: null | number;
+                  requestCount?: null | number;
+                  start?: null | string;
+                  updatedAt?: number;
+                  userId?: string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "name"
+                    | "start"
+                    | "prefix"
+                    | "key"
+                    | "userId"
+                    | "refillInterval"
+                    | "refillAmount"
+                    | "lastRefillAt"
+                    | "enabled"
+                    | "rateLimitEnabled"
+                    | "rateLimitTimeWindow"
+                    | "rateLimitMax"
+                    | "requestCount"
+                    | "remaining"
+                    | "lastRequest"
+                    | "expiresAt"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "permissions"
+                    | "metadata"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              };
+          onUpdateHandle?: string;
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+        },
+        any
+      >;
+      updateOne: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          input:
+            | {
+                model: "user";
+                update: {
+                  createdAt?: number;
+                  email?: string;
+                  emailVerified?: boolean;
+                  image?: null | string;
+                  name?: string;
+                  updatedAt?: number;
+                  userId?: null | string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "name"
+                    | "email"
+                    | "emailVerified"
+                    | "image"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "userId"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "session";
+                update: {
+                  activeOrganizationId?: null | string;
+                  activeTeamId?: null | string;
+                  createdAt?: number;
+                  expiresAt?: number;
+                  ipAddress?: null | string;
+                  token?: string;
+                  trustedRole?: null | string;
+                  trustedTeams?: null | string;
+                  updatedAt?: number;
+                  userAgent?: null | string;
+                  userId?: string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "expiresAt"
+                    | "token"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "ipAddress"
+                    | "userAgent"
+                    | "userId"
+                    | "activeOrganizationId"
+                    | "activeTeamId"
+                    | "trustedRole"
+                    | "trustedTeams"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "account";
+                update: {
+                  accessToken?: null | string;
+                  accessTokenExpiresAt?: null | number;
+                  accountId?: string;
+                  createdAt?: number;
+                  idToken?: null | string;
+                  password?: null | string;
+                  providerId?: string;
+                  refreshToken?: null | string;
+                  refreshTokenExpiresAt?: null | number;
+                  scope?: null | string;
+                  updatedAt?: number;
+                  userId?: string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "accountId"
+                    | "providerId"
+                    | "userId"
+                    | "accessToken"
+                    | "refreshToken"
+                    | "idToken"
+                    | "accessTokenExpiresAt"
+                    | "refreshTokenExpiresAt"
+                    | "scope"
+                    | "password"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "verification";
+                update: {
+                  createdAt?: number;
+                  expiresAt?: number;
+                  identifier?: string;
+                  updatedAt?: number;
+                  value?: string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "identifier"
+                    | "value"
+                    | "expiresAt"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "jwks";
+                update: {
+                  createdAt?: number;
+                  expiresAt?: null | number;
+                  privateKey?: string;
+                  publicKey?: string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "publicKey"
+                    | "privateKey"
+                    | "createdAt"
+                    | "expiresAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "organization";
+                update: {
+                  createdAt?: number;
+                  logo?: null | string;
+                  metadata?: null | string;
+                  name?: string;
+                  slug?: string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "name"
+                    | "slug"
+                    | "logo"
+                    | "createdAt"
+                    | "metadata"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "team";
+                update: {
+                  createdAt?: number;
+                  name?: string;
+                  organizationId?: string;
+                  updatedAt?: null | number;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "name"
+                    | "organizationId"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "teamMember";
+                update: {
+                  createdAt?: null | number;
+                  teamId?: string;
+                  userId?: string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field: "teamId" | "userId" | "createdAt" | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "member";
+                update: {
+                  createdAt?: number;
+                  organizationId?: string;
+                  role?: string;
+                  userId?: string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "organizationId"
+                    | "userId"
+                    | "role"
+                    | "createdAt"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "invitation";
+                update: {
+                  createdAt?: number;
+                  email?: string;
+                  expiresAt?: number;
+                  inviterId?: string;
+                  organizationId?: string;
+                  role?: null | string;
+                  status?: string;
+                  teamId?: null | string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "organizationId"
+                    | "email"
+                    | "role"
+                    | "teamId"
+                    | "status"
+                    | "expiresAt"
+                    | "createdAt"
+                    | "inviterId"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              }
+            | {
+                model: "apikey";
+                update: {
+                  createdAt?: number;
+                  enabled?: null | boolean;
+                  expiresAt?: null | number;
+                  key?: string;
+                  lastRefillAt?: null | number;
+                  lastRequest?: null | number;
+                  metadata?: null | string;
+                  name?: null | string;
+                  permissions?: null | string;
+                  prefix?: null | string;
+                  rateLimitEnabled?: null | boolean;
+                  rateLimitMax?: null | number;
+                  rateLimitTimeWindow?: null | number;
+                  refillAmount?: null | number;
+                  refillInterval?: null | number;
+                  remaining?: null | number;
+                  requestCount?: null | number;
+                  start?: null | string;
+                  updatedAt?: number;
+                  userId?: string;
+                };
+                where?: Array<{
+                  connector?: "AND" | "OR";
+                  field:
+                    | "name"
+                    | "start"
+                    | "prefix"
+                    | "key"
+                    | "userId"
+                    | "refillInterval"
+                    | "refillAmount"
+                    | "lastRefillAt"
+                    | "enabled"
+                    | "rateLimitEnabled"
+                    | "rateLimitTimeWindow"
+                    | "rateLimitMax"
+                    | "requestCount"
+                    | "remaining"
+                    | "lastRequest"
+                    | "expiresAt"
+                    | "createdAt"
+                    | "updatedAt"
+                    | "permissions"
+                    | "metadata"
+                    | "_id";
+                  operator?:
+                    | "lt"
+                    | "lte"
+                    | "gt"
+                    | "gte"
+                    | "eq"
+                    | "in"
+                    | "not_in"
+                    | "ne"
+                    | "contains"
+                    | "starts_with"
+                    | "ends_with";
+                  value:
+                    | string
+                    | number
+                    | boolean
+                    | Array<string>
+                    | Array<number>
+                    | null;
+                }>;
+              };
+          onUpdateHandle?: string;
+        },
+        any
+      >;
+    };
+  };
+  workflow: {
+    event: {
+      create: FunctionReference<
+        "mutation",
+        "internal",
+        { name: string; workflowId: string },
+        string
+      >;
+      send: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          eventId?: string;
+          name?: string;
+          result:
+            | { kind: "success"; returnValue: any }
+            | { error: string; kind: "failed" }
+            | { kind: "canceled" };
+          workflowId?: string;
+          workpoolOptions?: {
+            defaultRetryBehavior?: {
+              base: number;
+              initialBackoffMs: number;
+              maxAttempts: number;
+            };
+            logLevel?: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
+            maxParallelism?: number;
+            retryActionsByDefault?: boolean;
+          };
+        },
+        string
+      >;
+    };
+    journal: {
+      load: FunctionReference<
+        "query",
+        "internal",
+        { shortCircuit?: boolean; workflowId: string },
+        {
+          blocked?: boolean;
+          journalEntries: Array<{
+            _creationTime: number;
+            _id: string;
+            step:
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  functionType: "query" | "mutation" | "action";
+                  handle: string;
+                  inProgress: boolean;
+                  kind?: "function";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  handle: string;
+                  inProgress: boolean;
+                  kind: "workflow";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workflowId?: string;
+                }
+              | {
+                  args: { eventId?: string };
+                  argsSize: number;
+                  completedAt?: number;
+                  eventId?: string;
+                  inProgress: boolean;
+                  kind: "event";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  inProgress: boolean;
+                  kind: "sleep";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                };
+            stepNumber: number;
+            workflowId: string;
+          }>;
+          logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
+          ok: boolean;
+          workflow: {
+            _creationTime: number;
+            _id: string;
+            args: any;
+            generationNumber: number;
+            logLevel?: any;
+            name?: string;
+            onComplete?: { context?: any; fnHandle: string };
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            startedAt?: any;
+            state?: any;
+            workflowHandle: string;
+          };
+        }
+      >;
+      startSteps: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          generationNumber: number;
+          steps: Array<{
+            retry?:
+              | boolean
+              | { base: number; initialBackoffMs: number; maxAttempts: number };
+            schedulerOptions?: { runAt?: number } | { runAfter?: number };
+            step:
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  functionType: "query" | "mutation" | "action";
+                  handle: string;
+                  inProgress: boolean;
+                  kind?: "function";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  handle: string;
+                  inProgress: boolean;
+                  kind: "workflow";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workflowId?: string;
+                }
+              | {
+                  args: { eventId?: string };
+                  argsSize: number;
+                  completedAt?: number;
+                  eventId?: string;
+                  inProgress: boolean;
+                  kind: "event";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  inProgress: boolean;
+                  kind: "sleep";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                };
+          }>;
+          workflowId: string;
+          workpoolOptions?: {
+            defaultRetryBehavior?: {
+              base: number;
+              initialBackoffMs: number;
+              maxAttempts: number;
+            };
+            logLevel?: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
+            maxParallelism?: number;
+            retryActionsByDefault?: boolean;
+          };
+        },
+        Array<{
+          _creationTime: number;
+          _id: string;
+          step:
+            | {
+                args: any;
+                argsSize: number;
+                completedAt?: number;
+                functionType: "query" | "mutation" | "action";
+                handle: string;
+                inProgress: boolean;
+                kind?: "function";
+                name: string;
+                runResult?:
+                  | { kind: "success"; returnValue: any }
+                  | { error: string; kind: "failed" }
+                  | { kind: "canceled" };
+                startedAt: number;
+                workId?: string;
+              }
+            | {
+                args: any;
+                argsSize: number;
+                completedAt?: number;
+                handle: string;
+                inProgress: boolean;
+                kind: "workflow";
+                name: string;
+                runResult?:
+                  | { kind: "success"; returnValue: any }
+                  | { error: string; kind: "failed" }
+                  | { kind: "canceled" };
+                startedAt: number;
+                workflowId?: string;
+              }
+            | {
+                args: { eventId?: string };
+                argsSize: number;
+                completedAt?: number;
+                eventId?: string;
+                inProgress: boolean;
+                kind: "event";
+                name: string;
+                runResult?:
+                  | { kind: "success"; returnValue: any }
+                  | { error: string; kind: "failed" }
+                  | { kind: "canceled" };
+                startedAt: number;
+              }
+            | {
+                args: any;
+                argsSize: number;
+                completedAt?: number;
+                inProgress: boolean;
+                kind: "sleep";
+                name: string;
+                runResult?:
+                  | { kind: "success"; returnValue: any }
+                  | { error: string; kind: "failed" }
+                  | { kind: "canceled" };
+                startedAt: number;
+                workId?: string;
+              };
+          stepNumber: number;
+          workflowId: string;
+        }>
+      >;
+    };
+    workflow: {
+      cancel: FunctionReference<
+        "mutation",
+        "internal",
+        { workflowId: string },
+        null
+      >;
+      cleanup: FunctionReference<
+        "mutation",
+        "internal",
+        { force?: boolean; workflowId: string },
+        boolean
+      >;
+      complete: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          generationNumber: number;
+          runResult:
+            | { kind: "success"; returnValue: any }
+            | { error: string; kind: "failed" }
+            | { kind: "canceled" };
+          workflowId: string;
+        },
+        null
+      >;
+      create: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          maxParallelism?: number;
+          onComplete?: { context?: any; fnHandle: string };
+          startAsync?: boolean;
+          workflowArgs: any;
+          workflowHandle: string;
+          workflowName: string;
+        },
+        string
+      >;
+      getStatus: FunctionReference<
+        "query",
+        "internal",
+        { workflowId: string },
+        {
+          inProgress: Array<{
+            _creationTime: number;
+            _id: string;
+            step:
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  functionType: "query" | "mutation" | "action";
+                  handle: string;
+                  inProgress: boolean;
+                  kind?: "function";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  handle: string;
+                  inProgress: boolean;
+                  kind: "workflow";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workflowId?: string;
+                }
+              | {
+                  args: { eventId?: string };
+                  argsSize: number;
+                  completedAt?: number;
+                  eventId?: string;
+                  inProgress: boolean;
+                  kind: "event";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  inProgress: boolean;
+                  kind: "sleep";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                };
+            stepNumber: number;
+            workflowId: string;
+          }>;
+          logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
+          workflow: {
+            _creationTime: number;
+            _id: string;
+            args: any;
+            generationNumber: number;
+            logLevel?: any;
+            name?: string;
+            onComplete?: { context?: any; fnHandle: string };
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            startedAt?: any;
+            state?: any;
+            workflowHandle: string;
+          };
+        }
+      >;
+      list: FunctionReference<
+        "query",
+        "internal",
+        {
+          order: "asc" | "desc";
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+        },
+        {
+          continueCursor: string;
+          isDone: boolean;
+          page: Array<{
+            args: any;
+            context?: any;
+            name?: string;
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            workflowId: string;
+          }>;
+          pageStatus?: "SplitRecommended" | "SplitRequired" | null;
+          splitCursor?: string | null;
+        }
+      >;
+      listByName: FunctionReference<
+        "query",
+        "internal",
+        {
+          name: string;
+          order: "asc" | "desc";
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+        },
+        {
+          continueCursor: string;
+          isDone: boolean;
+          page: Array<{
+            args: any;
+            context?: any;
+            name?: string;
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            workflowId: string;
+          }>;
+          pageStatus?: "SplitRecommended" | "SplitRequired" | null;
+          splitCursor?: string | null;
+        }
+      >;
+      listSteps: FunctionReference<
+        "query",
+        "internal",
+        {
+          order: "asc" | "desc";
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+          workflowId: string;
+        },
+        {
+          continueCursor: string;
+          isDone: boolean;
+          page: Array<{
+            args: any;
+            completedAt?: number;
+            eventId?: string;
+            kind: "function" | "workflow" | "event" | "sleep";
+            name: string;
+            nestedWorkflowId?: string;
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            startedAt: number;
+            stepId: string;
+            stepNumber: number;
+            workId?: string;
+            workflowId: string;
+          }>;
+          pageStatus?: "SplitRecommended" | "SplitRequired" | null;
+          splitCursor?: string | null;
+        }
+      >;
+      restart: FunctionReference<
+        "mutation",
+        "internal",
+        { from?: number | string; startAsync?: boolean; workflowId: string },
+        null
+      >;
+    };
+  };
+  workflow_1: {
+    event: {
+      create: FunctionReference<
+        "mutation",
+        "internal",
+        { name: string; workflowId: string },
+        string
+      >;
+      send: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          eventId?: string;
+          name?: string;
+          result:
+            | { kind: "success"; returnValue: any }
+            | { error: string; kind: "failed" }
+            | { kind: "canceled" };
+          workflowId?: string;
+          workpoolOptions?: {
+            defaultRetryBehavior?: {
+              base: number;
+              initialBackoffMs: number;
+              maxAttempts: number;
+            };
+            logLevel?: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
+            maxParallelism?: number;
+            retryActionsByDefault?: boolean;
+          };
+        },
+        string
+      >;
+    };
+    journal: {
+      load: FunctionReference<
+        "query",
+        "internal",
+        { shortCircuit?: boolean; workflowId: string },
+        {
+          blocked?: boolean;
+          journalEntries: Array<{
+            _creationTime: number;
+            _id: string;
+            step:
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  functionType: "query" | "mutation" | "action";
+                  handle: string;
+                  inProgress: boolean;
+                  kind?: "function";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  handle: string;
+                  inProgress: boolean;
+                  kind: "workflow";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workflowId?: string;
+                }
+              | {
+                  args: { eventId?: string };
+                  argsSize: number;
+                  completedAt?: number;
+                  eventId?: string;
+                  inProgress: boolean;
+                  kind: "event";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  inProgress: boolean;
+                  kind: "sleep";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                };
+            stepNumber: number;
+            workflowId: string;
+          }>;
+          logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
+          ok: boolean;
+          workflow: {
+            _creationTime: number;
+            _id: string;
+            args: any;
+            generationNumber: number;
+            logLevel?: any;
+            name?: string;
+            onComplete?: { context?: any; fnHandle: string };
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            startedAt?: any;
+            state?: any;
+            workflowHandle: string;
+          };
+        }
+      >;
+      startSteps: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          generationNumber: number;
+          steps: Array<{
+            retry?:
+              | boolean
+              | { base: number; initialBackoffMs: number; maxAttempts: number };
+            schedulerOptions?: { runAt?: number } | { runAfter?: number };
+            step:
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  functionType: "query" | "mutation" | "action";
+                  handle: string;
+                  inProgress: boolean;
+                  kind?: "function";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  handle: string;
+                  inProgress: boolean;
+                  kind: "workflow";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workflowId?: string;
+                }
+              | {
+                  args: { eventId?: string };
+                  argsSize: number;
+                  completedAt?: number;
+                  eventId?: string;
+                  inProgress: boolean;
+                  kind: "event";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  inProgress: boolean;
+                  kind: "sleep";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                };
+          }>;
+          workflowId: string;
+          workpoolOptions?: {
+            defaultRetryBehavior?: {
+              base: number;
+              initialBackoffMs: number;
+              maxAttempts: number;
+            };
+            logLevel?: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
+            maxParallelism?: number;
+            retryActionsByDefault?: boolean;
+          };
+        },
+        Array<{
+          _creationTime: number;
+          _id: string;
+          step:
+            | {
+                args: any;
+                argsSize: number;
+                completedAt?: number;
+                functionType: "query" | "mutation" | "action";
+                handle: string;
+                inProgress: boolean;
+                kind?: "function";
+                name: string;
+                runResult?:
+                  | { kind: "success"; returnValue: any }
+                  | { error: string; kind: "failed" }
+                  | { kind: "canceled" };
+                startedAt: number;
+                workId?: string;
+              }
+            | {
+                args: any;
+                argsSize: number;
+                completedAt?: number;
+                handle: string;
+                inProgress: boolean;
+                kind: "workflow";
+                name: string;
+                runResult?:
+                  | { kind: "success"; returnValue: any }
+                  | { error: string; kind: "failed" }
+                  | { kind: "canceled" };
+                startedAt: number;
+                workflowId?: string;
+              }
+            | {
+                args: { eventId?: string };
+                argsSize: number;
+                completedAt?: number;
+                eventId?: string;
+                inProgress: boolean;
+                kind: "event";
+                name: string;
+                runResult?:
+                  | { kind: "success"; returnValue: any }
+                  | { error: string; kind: "failed" }
+                  | { kind: "canceled" };
+                startedAt: number;
+              }
+            | {
+                args: any;
+                argsSize: number;
+                completedAt?: number;
+                inProgress: boolean;
+                kind: "sleep";
+                name: string;
+                runResult?:
+                  | { kind: "success"; returnValue: any }
+                  | { error: string; kind: "failed" }
+                  | { kind: "canceled" };
+                startedAt: number;
+                workId?: string;
+              };
+          stepNumber: number;
+          workflowId: string;
+        }>
+      >;
+    };
+    workflow: {
+      cancel: FunctionReference<
+        "mutation",
+        "internal",
+        { workflowId: string },
+        null
+      >;
+      cleanup: FunctionReference<
+        "mutation",
+        "internal",
+        { force?: boolean; workflowId: string },
+        boolean
+      >;
+      complete: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          generationNumber: number;
+          runResult:
+            | { kind: "success"; returnValue: any }
+            | { error: string; kind: "failed" }
+            | { kind: "canceled" };
+          workflowId: string;
+        },
+        null
+      >;
+      create: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          maxParallelism?: number;
+          onComplete?: { context?: any; fnHandle: string };
+          startAsync?: boolean;
+          workflowArgs: any;
+          workflowHandle: string;
+          workflowName: string;
+        },
+        string
+      >;
+      getStatus: FunctionReference<
+        "query",
+        "internal",
+        { workflowId: string },
+        {
+          inProgress: Array<{
+            _creationTime: number;
+            _id: string;
+            step:
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  functionType: "query" | "mutation" | "action";
+                  handle: string;
+                  inProgress: boolean;
+                  kind?: "function";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  handle: string;
+                  inProgress: boolean;
+                  kind: "workflow";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workflowId?: string;
+                }
+              | {
+                  args: { eventId?: string };
+                  argsSize: number;
+                  completedAt?: number;
+                  eventId?: string;
+                  inProgress: boolean;
+                  kind: "event";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  inProgress: boolean;
+                  kind: "sleep";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                };
+            stepNumber: number;
+            workflowId: string;
+          }>;
+          logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
+          workflow: {
+            _creationTime: number;
+            _id: string;
+            args: any;
+            generationNumber: number;
+            logLevel?: any;
+            name?: string;
+            onComplete?: { context?: any; fnHandle: string };
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            startedAt?: any;
+            state?: any;
+            workflowHandle: string;
+          };
+        }
+      >;
+      list: FunctionReference<
+        "query",
+        "internal",
+        {
+          order: "asc" | "desc";
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+        },
+        {
+          continueCursor: string;
+          isDone: boolean;
+          page: Array<{
+            args: any;
+            context?: any;
+            name?: string;
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            workflowId: string;
+          }>;
+          pageStatus?: "SplitRecommended" | "SplitRequired" | null;
+          splitCursor?: string | null;
+        }
+      >;
+      listByName: FunctionReference<
+        "query",
+        "internal",
+        {
+          name: string;
+          order: "asc" | "desc";
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+        },
+        {
+          continueCursor: string;
+          isDone: boolean;
+          page: Array<{
+            args: any;
+            context?: any;
+            name?: string;
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            workflowId: string;
+          }>;
+          pageStatus?: "SplitRecommended" | "SplitRequired" | null;
+          splitCursor?: string | null;
+        }
+      >;
+      listSteps: FunctionReference<
+        "query",
+        "internal",
+        {
+          order: "asc" | "desc";
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+          workflowId: string;
+        },
+        {
+          continueCursor: string;
+          isDone: boolean;
+          page: Array<{
+            args: any;
+            completedAt?: number;
+            eventId?: string;
+            kind: "function" | "workflow" | "event" | "sleep";
+            name: string;
+            nestedWorkflowId?: string;
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            startedAt: number;
+            stepId: string;
+            stepNumber: number;
+            workId?: string;
+            workflowId: string;
+          }>;
+          pageStatus?: "SplitRecommended" | "SplitRequired" | null;
+          splitCursor?: string | null;
+        }
+      >;
+      restart: FunctionReference<
+        "mutation",
+        "internal",
+        { from?: number | string; startAsync?: boolean; workflowId: string },
+        null
+      >;
+    };
+  };
+  workflow_2: {
+    event: {
+      create: FunctionReference<
+        "mutation",
+        "internal",
+        { name: string; workflowId: string },
+        string
+      >;
+      send: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          eventId?: string;
+          name?: string;
+          result:
+            | { kind: "success"; returnValue: any }
+            | { error: string; kind: "failed" }
+            | { kind: "canceled" };
+          workflowId?: string;
+          workpoolOptions?: {
+            defaultRetryBehavior?: {
+              base: number;
+              initialBackoffMs: number;
+              maxAttempts: number;
+            };
+            logLevel?: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
+            maxParallelism?: number;
+            retryActionsByDefault?: boolean;
+          };
+        },
+        string
+      >;
+    };
+    journal: {
+      load: FunctionReference<
+        "query",
+        "internal",
+        { shortCircuit?: boolean; workflowId: string },
+        {
+          blocked?: boolean;
+          journalEntries: Array<{
+            _creationTime: number;
+            _id: string;
+            step:
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  functionType: "query" | "mutation" | "action";
+                  handle: string;
+                  inProgress: boolean;
+                  kind?: "function";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  handle: string;
+                  inProgress: boolean;
+                  kind: "workflow";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workflowId?: string;
+                }
+              | {
+                  args: { eventId?: string };
+                  argsSize: number;
+                  completedAt?: number;
+                  eventId?: string;
+                  inProgress: boolean;
+                  kind: "event";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  inProgress: boolean;
+                  kind: "sleep";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                };
+            stepNumber: number;
+            workflowId: string;
+          }>;
+          logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
+          ok: boolean;
+          workflow: {
+            _creationTime: number;
+            _id: string;
+            args: any;
+            generationNumber: number;
+            logLevel?: any;
+            name?: string;
+            onComplete?: { context?: any; fnHandle: string };
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            startedAt?: any;
+            state?: any;
+            workflowHandle: string;
+          };
+        }
+      >;
+      startSteps: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          generationNumber: number;
+          steps: Array<{
+            retry?:
+              | boolean
+              | { base: number; initialBackoffMs: number; maxAttempts: number };
+            schedulerOptions?: { runAt?: number } | { runAfter?: number };
+            step:
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  functionType: "query" | "mutation" | "action";
+                  handle: string;
+                  inProgress: boolean;
+                  kind?: "function";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  handle: string;
+                  inProgress: boolean;
+                  kind: "workflow";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workflowId?: string;
+                }
+              | {
+                  args: { eventId?: string };
+                  argsSize: number;
+                  completedAt?: number;
+                  eventId?: string;
+                  inProgress: boolean;
+                  kind: "event";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  inProgress: boolean;
+                  kind: "sleep";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                };
+          }>;
+          workflowId: string;
+          workpoolOptions?: {
+            defaultRetryBehavior?: {
+              base: number;
+              initialBackoffMs: number;
+              maxAttempts: number;
+            };
+            logLevel?: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
+            maxParallelism?: number;
+            retryActionsByDefault?: boolean;
+          };
+        },
+        Array<{
+          _creationTime: number;
+          _id: string;
+          step:
+            | {
+                args: any;
+                argsSize: number;
+                completedAt?: number;
+                functionType: "query" | "mutation" | "action";
+                handle: string;
+                inProgress: boolean;
+                kind?: "function";
+                name: string;
+                runResult?:
+                  | { kind: "success"; returnValue: any }
+                  | { error: string; kind: "failed" }
+                  | { kind: "canceled" };
+                startedAt: number;
+                workId?: string;
+              }
+            | {
+                args: any;
+                argsSize: number;
+                completedAt?: number;
+                handle: string;
+                inProgress: boolean;
+                kind: "workflow";
+                name: string;
+                runResult?:
+                  | { kind: "success"; returnValue: any }
+                  | { error: string; kind: "failed" }
+                  | { kind: "canceled" };
+                startedAt: number;
+                workflowId?: string;
+              }
+            | {
+                args: { eventId?: string };
+                argsSize: number;
+                completedAt?: number;
+                eventId?: string;
+                inProgress: boolean;
+                kind: "event";
+                name: string;
+                runResult?:
+                  | { kind: "success"; returnValue: any }
+                  | { error: string; kind: "failed" }
+                  | { kind: "canceled" };
+                startedAt: number;
+              }
+            | {
+                args: any;
+                argsSize: number;
+                completedAt?: number;
+                inProgress: boolean;
+                kind: "sleep";
+                name: string;
+                runResult?:
+                  | { kind: "success"; returnValue: any }
+                  | { error: string; kind: "failed" }
+                  | { kind: "canceled" };
+                startedAt: number;
+                workId?: string;
+              };
+          stepNumber: number;
+          workflowId: string;
+        }>
+      >;
+    };
+    workflow: {
+      cancel: FunctionReference<
+        "mutation",
+        "internal",
+        { workflowId: string },
+        null
+      >;
+      cleanup: FunctionReference<
+        "mutation",
+        "internal",
+        { force?: boolean; workflowId: string },
+        boolean
+      >;
+      complete: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          generationNumber: number;
+          runResult:
+            | { kind: "success"; returnValue: any }
+            | { error: string; kind: "failed" }
+            | { kind: "canceled" };
+          workflowId: string;
+        },
+        null
+      >;
+      create: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          maxParallelism?: number;
+          onComplete?: { context?: any; fnHandle: string };
+          startAsync?: boolean;
+          workflowArgs: any;
+          workflowHandle: string;
+          workflowName: string;
+        },
+        string
+      >;
+      getStatus: FunctionReference<
+        "query",
+        "internal",
+        { workflowId: string },
+        {
+          inProgress: Array<{
+            _creationTime: number;
+            _id: string;
+            step:
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  functionType: "query" | "mutation" | "action";
+                  handle: string;
+                  inProgress: boolean;
+                  kind?: "function";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  handle: string;
+                  inProgress: boolean;
+                  kind: "workflow";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workflowId?: string;
+                }
+              | {
+                  args: { eventId?: string };
+                  argsSize: number;
+                  completedAt?: number;
+                  eventId?: string;
+                  inProgress: boolean;
+                  kind: "event";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  inProgress: boolean;
+                  kind: "sleep";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                };
+            stepNumber: number;
+            workflowId: string;
+          }>;
+          logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
+          workflow: {
+            _creationTime: number;
+            _id: string;
+            args: any;
+            generationNumber: number;
+            logLevel?: any;
+            name?: string;
+            onComplete?: { context?: any; fnHandle: string };
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            startedAt?: any;
+            state?: any;
+            workflowHandle: string;
+          };
+        }
+      >;
+      list: FunctionReference<
+        "query",
+        "internal",
+        {
+          order: "asc" | "desc";
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+        },
+        {
+          continueCursor: string;
+          isDone: boolean;
+          page: Array<{
+            args: any;
+            context?: any;
+            name?: string;
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            workflowId: string;
+          }>;
+          pageStatus?: "SplitRecommended" | "SplitRequired" | null;
+          splitCursor?: string | null;
+        }
+      >;
+      listByName: FunctionReference<
+        "query",
+        "internal",
+        {
+          name: string;
+          order: "asc" | "desc";
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+        },
+        {
+          continueCursor: string;
+          isDone: boolean;
+          page: Array<{
+            args: any;
+            context?: any;
+            name?: string;
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            workflowId: string;
+          }>;
+          pageStatus?: "SplitRecommended" | "SplitRequired" | null;
+          splitCursor?: string | null;
+        }
+      >;
+      listSteps: FunctionReference<
+        "query",
+        "internal",
+        {
+          order: "asc" | "desc";
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+          workflowId: string;
+        },
+        {
+          continueCursor: string;
+          isDone: boolean;
+          page: Array<{
+            args: any;
+            completedAt?: number;
+            eventId?: string;
+            kind: "function" | "workflow" | "event" | "sleep";
+            name: string;
+            nestedWorkflowId?: string;
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            startedAt: number;
+            stepId: string;
+            stepNumber: number;
+            workId?: string;
+            workflowId: string;
+          }>;
+          pageStatus?: "SplitRecommended" | "SplitRequired" | null;
+          splitCursor?: string | null;
+        }
+      >;
+      restart: FunctionReference<
+        "mutation",
+        "internal",
+        { from?: number | string; startAsync?: boolean; workflowId: string },
+        null
+      >;
+    };
+  };
+  workflow_3: {
+    event: {
+      create: FunctionReference<
+        "mutation",
+        "internal",
+        { name: string; workflowId: string },
+        string
+      >;
+      send: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          eventId?: string;
+          name?: string;
+          result:
+            | { kind: "success"; returnValue: any }
+            | { error: string; kind: "failed" }
+            | { kind: "canceled" };
+          workflowId?: string;
+          workpoolOptions?: {
+            defaultRetryBehavior?: {
+              base: number;
+              initialBackoffMs: number;
+              maxAttempts: number;
+            };
+            logLevel?: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
+            maxParallelism?: number;
+            retryActionsByDefault?: boolean;
+          };
+        },
+        string
+      >;
+    };
+    journal: {
+      load: FunctionReference<
+        "query",
+        "internal",
+        { shortCircuit?: boolean; workflowId: string },
+        {
+          blocked?: boolean;
+          journalEntries: Array<{
+            _creationTime: number;
+            _id: string;
+            step:
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  functionType: "query" | "mutation" | "action";
+                  handle: string;
+                  inProgress: boolean;
+                  kind?: "function";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  handle: string;
+                  inProgress: boolean;
+                  kind: "workflow";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workflowId?: string;
+                }
+              | {
+                  args: { eventId?: string };
+                  argsSize: number;
+                  completedAt?: number;
+                  eventId?: string;
+                  inProgress: boolean;
+                  kind: "event";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  inProgress: boolean;
+                  kind: "sleep";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                };
+            stepNumber: number;
+            workflowId: string;
+          }>;
+          logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
+          ok: boolean;
+          workflow: {
+            _creationTime: number;
+            _id: string;
+            args: any;
+            generationNumber: number;
+            logLevel?: any;
+            name?: string;
+            onComplete?: { context?: any; fnHandle: string };
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            startedAt?: any;
+            state?: any;
+            workflowHandle: string;
+          };
+        }
+      >;
+      startSteps: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          generationNumber: number;
+          steps: Array<{
+            retry?:
+              | boolean
+              | { base: number; initialBackoffMs: number; maxAttempts: number };
+            schedulerOptions?: { runAt?: number } | { runAfter?: number };
+            step:
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  functionType: "query" | "mutation" | "action";
+                  handle: string;
+                  inProgress: boolean;
+                  kind?: "function";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  handle: string;
+                  inProgress: boolean;
+                  kind: "workflow";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workflowId?: string;
+                }
+              | {
+                  args: { eventId?: string };
+                  argsSize: number;
+                  completedAt?: number;
+                  eventId?: string;
+                  inProgress: boolean;
+                  kind: "event";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  inProgress: boolean;
+                  kind: "sleep";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                };
+          }>;
+          workflowId: string;
+          workpoolOptions?: {
+            defaultRetryBehavior?: {
+              base: number;
+              initialBackoffMs: number;
+              maxAttempts: number;
+            };
+            logLevel?: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
+            maxParallelism?: number;
+            retryActionsByDefault?: boolean;
+          };
+        },
+        Array<{
+          _creationTime: number;
+          _id: string;
+          step:
+            | {
+                args: any;
+                argsSize: number;
+                completedAt?: number;
+                functionType: "query" | "mutation" | "action";
+                handle: string;
+                inProgress: boolean;
+                kind?: "function";
+                name: string;
+                runResult?:
+                  | { kind: "success"; returnValue: any }
+                  | { error: string; kind: "failed" }
+                  | { kind: "canceled" };
+                startedAt: number;
+                workId?: string;
+              }
+            | {
+                args: any;
+                argsSize: number;
+                completedAt?: number;
+                handle: string;
+                inProgress: boolean;
+                kind: "workflow";
+                name: string;
+                runResult?:
+                  | { kind: "success"; returnValue: any }
+                  | { error: string; kind: "failed" }
+                  | { kind: "canceled" };
+                startedAt: number;
+                workflowId?: string;
+              }
+            | {
+                args: { eventId?: string };
+                argsSize: number;
+                completedAt?: number;
+                eventId?: string;
+                inProgress: boolean;
+                kind: "event";
+                name: string;
+                runResult?:
+                  | { kind: "success"; returnValue: any }
+                  | { error: string; kind: "failed" }
+                  | { kind: "canceled" };
+                startedAt: number;
+              }
+            | {
+                args: any;
+                argsSize: number;
+                completedAt?: number;
+                inProgress: boolean;
+                kind: "sleep";
+                name: string;
+                runResult?:
+                  | { kind: "success"; returnValue: any }
+                  | { error: string; kind: "failed" }
+                  | { kind: "canceled" };
+                startedAt: number;
+                workId?: string;
+              };
+          stepNumber: number;
+          workflowId: string;
+        }>
+      >;
+    };
+    workflow: {
+      cancel: FunctionReference<
+        "mutation",
+        "internal",
+        { workflowId: string },
+        null
+      >;
+      cleanup: FunctionReference<
+        "mutation",
+        "internal",
+        { force?: boolean; workflowId: string },
+        boolean
+      >;
+      complete: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          generationNumber: number;
+          runResult:
+            | { kind: "success"; returnValue: any }
+            | { error: string; kind: "failed" }
+            | { kind: "canceled" };
+          workflowId: string;
+        },
+        null
+      >;
+      create: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          maxParallelism?: number;
+          onComplete?: { context?: any; fnHandle: string };
+          startAsync?: boolean;
+          workflowArgs: any;
+          workflowHandle: string;
+          workflowName: string;
+        },
+        string
+      >;
+      getStatus: FunctionReference<
+        "query",
+        "internal",
+        { workflowId: string },
+        {
+          inProgress: Array<{
+            _creationTime: number;
+            _id: string;
+            step:
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  functionType: "query" | "mutation" | "action";
+                  handle: string;
+                  inProgress: boolean;
+                  kind?: "function";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  handle: string;
+                  inProgress: boolean;
+                  kind: "workflow";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workflowId?: string;
+                }
+              | {
+                  args: { eventId?: string };
+                  argsSize: number;
+                  completedAt?: number;
+                  eventId?: string;
+                  inProgress: boolean;
+                  kind: "event";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                }
+              | {
+                  args: any;
+                  argsSize: number;
+                  completedAt?: number;
+                  inProgress: boolean;
+                  kind: "sleep";
+                  name: string;
+                  runResult?:
+                    | { kind: "success"; returnValue: any }
+                    | { error: string; kind: "failed" }
+                    | { kind: "canceled" };
+                  startedAt: number;
+                  workId?: string;
+                };
+            stepNumber: number;
+            workflowId: string;
+          }>;
+          logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
+          workflow: {
+            _creationTime: number;
+            _id: string;
+            args: any;
+            generationNumber: number;
+            logLevel?: any;
+            name?: string;
+            onComplete?: { context?: any; fnHandle: string };
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            startedAt?: any;
+            state?: any;
+            workflowHandle: string;
+          };
+        }
+      >;
+      list: FunctionReference<
+        "query",
+        "internal",
+        {
+          order: "asc" | "desc";
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+        },
+        {
+          continueCursor: string;
+          isDone: boolean;
+          page: Array<{
+            args: any;
+            context?: any;
+            name?: string;
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            workflowId: string;
+          }>;
+          pageStatus?: "SplitRecommended" | "SplitRequired" | null;
+          splitCursor?: string | null;
+        }
+      >;
+      listByName: FunctionReference<
+        "query",
+        "internal",
+        {
+          name: string;
+          order: "asc" | "desc";
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+        },
+        {
+          continueCursor: string;
+          isDone: boolean;
+          page: Array<{
+            args: any;
+            context?: any;
+            name?: string;
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            workflowId: string;
+          }>;
+          pageStatus?: "SplitRecommended" | "SplitRequired" | null;
+          splitCursor?: string | null;
+        }
+      >;
+      listSteps: FunctionReference<
+        "query",
+        "internal",
+        {
+          order: "asc" | "desc";
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+          workflowId: string;
+        },
+        {
+          continueCursor: string;
+          isDone: boolean;
+          page: Array<{
+            args: any;
+            completedAt?: number;
+            eventId?: string;
+            kind: "function" | "workflow" | "event" | "sleep";
+            name: string;
+            nestedWorkflowId?: string;
+            runResult?:
+              | { kind: "success"; returnValue: any }
+              | { error: string; kind: "failed" }
+              | { kind: "canceled" };
+            startedAt: number;
+            stepId: string;
+            stepNumber: number;
+            workId?: string;
+            workflowId: string;
+          }>;
+          pageStatus?: "SplitRecommended" | "SplitRequired" | null;
+          splitCursor?: string | null;
+        }
+      >;
+      restart: FunctionReference<
+        "mutation",
+        "internal",
+        { from?: number | string; startAsync?: boolean; workflowId: string },
+        null
+      >;
+    };
+  };
+  agent: {
+    apiKeys: {
+      destroy: FunctionReference<
+        "mutation",
+        "internal",
+        { apiKey?: string; name?: string },
+        | "missing"
+        | "deleted"
+        | "name mismatch"
+        | "must provide either apiKey or name"
+      >;
+      issue: FunctionReference<
+        "mutation",
+        "internal",
+        { name?: string },
+        string
+      >;
+      validate: FunctionReference<
+        "query",
+        "internal",
+        { apiKey: string },
+        boolean
+      >;
+    };
+    files: {
+      addFile: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          filename?: string;
+          hash: string;
+          mediaType?: string;
+          mimeType?: string;
+          storageId: string;
+        },
+        { fileId: string; storageId: string }
+      >;
+      copyFile: FunctionReference<
+        "mutation",
+        "internal",
+        { fileId: string },
+        null
+      >;
+      deleteFiles: FunctionReference<
+        "mutation",
+        "internal",
+        { fileIds: Array<string>; force?: boolean },
+        Array<string>
+      >;
+      get: FunctionReference<
+        "query",
+        "internal",
+        { fileId: string },
+        null | {
+          _creationTime: number;
+          _id: string;
+          filename?: string;
+          hash: string;
+          lastTouchedAt: number;
+          mediaType?: string;
+          mimeType?: string;
+          refcount: number;
+          storageId: string;
+        }
+      >;
+      getFilesToDelete: FunctionReference<
+        "query",
+        "internal",
+        {
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+        },
+        {
+          continueCursor: string;
+          isDone: boolean;
+          page: Array<{
+            _creationTime: number;
+            _id: string;
+            filename?: string;
+            hash: string;
+            lastTouchedAt: number;
+            mediaType?: string;
+            mimeType?: string;
+            refcount: number;
+            storageId: string;
+          }>;
+        }
+      >;
+      useExistingFile: FunctionReference<
+        "mutation",
+        "internal",
+        { filename?: string; hash: string },
+        null | { fileId: string; storageId: string }
+      >;
+    };
+    messages: {
+      addMessages: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          agentName?: string;
+          embeddings?: {
+            dimension:
+              | 128
+              | 256
+              | 512
+              | 768
+              | 1024
+              | 1408
+              | 1536
+              | 2048
+              | 3072
+              | 4096;
+            model: string;
+            vectors: Array<Array<number> | null>;
+          };
+          failPendingSteps?: boolean;
+          finishStreamId?: string;
+          hideFromUserIdSearch?: boolean;
+          messages: Array<{
+            error?: string;
+            fileIds?: Array<string>;
+            finishReason?:
+              | "stop"
+              | "length"
+              | "content-filter"
+              | "tool-calls"
+              | "error"
+              | "other"
+              | "unknown";
+            message:
+              | {
+                  content:
+                    | string
+                    | Array<
+                        | {
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            text: string;
+                            type: "text";
+                          }
+                        | {
+                            image: string | ArrayBuffer;
+                            mediaType?: string;
+                            mimeType?: string;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "image";
+                          }
+                        | {
+                            data: string | ArrayBuffer;
+                            filename?: string;
+                            mediaType?: string;
+                            mimeType?: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "file";
+                          }
+                      >;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  role: "user";
+                }
+              | {
+                  content:
+                    | string
+                    | Array<
+                        | {
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            text: string;
+                            type: "text";
+                          }
+                        | {
+                            data: string | ArrayBuffer;
+                            filename?: string;
+                            mediaType?: string;
+                            mimeType?: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "file";
+                          }
+                        | {
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            signature?: string;
+                            text: string;
+                            type: "reasoning";
+                          }
+                        | {
+                            data: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "redacted-reasoning";
+                          }
+                        | {
+                            args?: any;
+                            input: any;
+                            providerExecuted?: boolean;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            toolCallId: string;
+                            toolName: string;
+                            type: "tool-call";
+                          }
+                        | {
+                            args: any;
+                            input?: any;
+                            providerExecuted?: boolean;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            toolCallId: string;
+                            toolName: string;
+                            type: "tool-call";
+                          }
+                        | {
+                            args?: any;
+                            experimental_content?: Array<
+                              | { text: string; type: "text" }
+                              | {
+                                  data: string;
+                                  mimeType?: string;
+                                  type: "image";
+                                }
+                            >;
+                            isError?: boolean;
+                            output?:
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "text";
+                                  value: string;
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "json";
+                                  value: any;
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "error-text";
+                                  value: string;
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "error-json";
+                                  value: any;
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  reason?: string;
+                                  type: "execution-denied";
+                                }
+                              | {
+                                  type: "content";
+                                  value: Array<
+                                    | {
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        text: string;
+                                        type: "text";
+                                      }
+                                    | {
+                                        data: string;
+                                        mediaType: string;
+                                        type: "media";
+                                      }
+                                    | {
+                                        data: string;
+                                        filename?: string;
+                                        mediaType: string;
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "file-data";
+                                      }
+                                    | {
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "file-url";
+                                        url: string;
+                                      }
+                                    | {
+                                        fileId: string | Record<string, string>;
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "file-id";
+                                      }
+                                    | {
+                                        data: string;
+                                        mediaType: string;
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "image-data";
+                                      }
+                                    | {
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "image-url";
+                                        url: string;
+                                      }
+                                    | {
+                                        fileId: string | Record<string, string>;
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "image-file-id";
+                                      }
+                                    | {
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "custom";
+                                      }
+                                  >;
+                                };
+                            providerExecuted?: boolean;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            result?: any;
+                            toolCallId: string;
+                            toolName: string;
+                            type: "tool-result";
+                          }
+                        | {
+                            id: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            sourceType: "url";
+                            title?: string;
+                            type: "source";
+                            url: string;
+                          }
+                        | {
+                            filename?: string;
+                            id: string;
+                            mediaType: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            sourceType: "document";
+                            title: string;
+                            type: "source";
+                          }
+                        | {
+                            approvalId: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            toolCallId: string;
+                            type: "tool-approval-request";
+                          }
+                      >;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  role: "assistant";
+                }
+              | {
+                  content: Array<
+                    | {
+                        args?: any;
+                        experimental_content?: Array<
+                          | { text: string; type: "text" }
+                          | { data: string; mimeType?: string; type: "image" }
+                        >;
+                        isError?: boolean;
+                        output?:
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              type: "text";
+                              value: string;
+                            }
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              type: "json";
+                              value: any;
+                            }
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              type: "error-text";
+                              value: string;
+                            }
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              type: "error-json";
+                              value: any;
+                            }
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              reason?: string;
+                              type: "execution-denied";
+                            }
+                          | {
+                              type: "content";
+                              value: Array<
+                                | {
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    text: string;
+                                    type: "text";
+                                  }
+                                | {
+                                    data: string;
+                                    mediaType: string;
+                                    type: "media";
+                                  }
+                                | {
+                                    data: string;
+                                    filename?: string;
+                                    mediaType: string;
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "file-data";
+                                  }
+                                | {
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "file-url";
+                                    url: string;
+                                  }
+                                | {
+                                    fileId: string | Record<string, string>;
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "file-id";
+                                  }
+                                | {
+                                    data: string;
+                                    mediaType: string;
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "image-data";
+                                  }
+                                | {
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "image-url";
+                                    url: string;
+                                  }
+                                | {
+                                    fileId: string | Record<string, string>;
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "image-file-id";
+                                  }
+                                | {
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "custom";
+                                  }
+                              >;
+                            };
+                        providerExecuted?: boolean;
+                        providerMetadata?: Record<string, Record<string, any>>;
+                        providerOptions?: Record<string, Record<string, any>>;
+                        result?: any;
+                        toolCallId: string;
+                        toolName: string;
+                        type: "tool-result";
+                      }
+                    | {
+                        approvalId: string;
+                        approved: boolean;
+                        providerExecuted?: boolean;
+                        providerMetadata?: Record<string, Record<string, any>>;
+                        providerOptions?: Record<string, Record<string, any>>;
+                        reason?: string;
+                        type: "tool-approval-response";
+                      }
+                  >;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  role: "tool";
+                }
+              | {
+                  content: string;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  role: "system";
+                };
+            model?: string;
+            provider?: string;
+            providerMetadata?: Record<string, Record<string, any>>;
+            reasoning?: string;
+            reasoningDetails?: Array<
+              | {
+                  providerMetadata?: Record<string, Record<string, any>>;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  signature?: string;
+                  text: string;
+                  type: "reasoning";
+                }
+              | { signature?: string; text: string; type: "text" }
+              | { data: string; type: "redacted" }
+            >;
+            sources?: Array<
+              | {
+                  id: string;
+                  providerMetadata?: Record<string, Record<string, any>>;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  sourceType: "url";
+                  title?: string;
+                  type?: "source";
+                  url: string;
+                }
+              | {
+                  filename?: string;
+                  id: string;
+                  mediaType: string;
+                  providerMetadata?: Record<string, Record<string, any>>;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  sourceType: "document";
+                  title: string;
+                  type: "source";
+                }
+            >;
+            status?: "pending" | "success" | "failed";
+            text?: string;
+            usage?: {
+              cachedInputTokens?: number;
+              completionTokens: number;
+              promptTokens: number;
+              reasoningTokens?: number;
+              totalTokens: number;
+            };
+            warnings?: Array<
+              | {
+                  details?: string;
+                  setting: string;
+                  type: "unsupported-setting";
+                }
+              | { details?: string; tool: any; type: "unsupported-tool" }
+              | { message: string; type: "other" }
+            >;
+          }>;
+          pendingMessageId?: string;
+          promptMessageId?: string;
+          threadId: string;
+          userId?: string;
+        },
+        {
+          messages: Array<{
+            _creationTime: number;
+            _id: string;
+            agentName?: string;
+            embeddingId?: string;
+            error?: string;
+            fileIds?: Array<string>;
+            finishReason?:
+              | "stop"
+              | "length"
+              | "content-filter"
+              | "tool-calls"
+              | "error"
+              | "other"
+              | "unknown";
+            id?: string;
+            message?:
+              | {
+                  content:
+                    | string
+                    | Array<
+                        | {
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            text: string;
+                            type: "text";
+                          }
+                        | {
+                            image: string | ArrayBuffer;
+                            mediaType?: string;
+                            mimeType?: string;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "image";
+                          }
+                        | {
+                            data: string | ArrayBuffer;
+                            filename?: string;
+                            mediaType?: string;
+                            mimeType?: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "file";
+                          }
+                      >;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  role: "user";
+                }
+              | {
+                  content:
+                    | string
+                    | Array<
+                        | {
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            text: string;
+                            type: "text";
+                          }
+                        | {
+                            data: string | ArrayBuffer;
+                            filename?: string;
+                            mediaType?: string;
+                            mimeType?: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "file";
+                          }
+                        | {
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            signature?: string;
+                            text: string;
+                            type: "reasoning";
+                          }
+                        | {
+                            data: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "redacted-reasoning";
+                          }
+                        | {
+                            args?: any;
+                            input: any;
+                            providerExecuted?: boolean;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            toolCallId: string;
+                            toolName: string;
+                            type: "tool-call";
+                          }
+                        | {
+                            args: any;
+                            input?: any;
+                            providerExecuted?: boolean;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            toolCallId: string;
+                            toolName: string;
+                            type: "tool-call";
+                          }
+                        | {
+                            args?: any;
+                            experimental_content?: Array<
+                              | { text: string; type: "text" }
+                              | {
+                                  data: string;
+                                  mimeType?: string;
+                                  type: "image";
+                                }
+                            >;
+                            isError?: boolean;
+                            output?:
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "text";
+                                  value: string;
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "json";
+                                  value: any;
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "error-text";
+                                  value: string;
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "error-json";
+                                  value: any;
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  reason?: string;
+                                  type: "execution-denied";
+                                }
+                              | {
+                                  type: "content";
+                                  value: Array<
+                                    | {
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        text: string;
+                                        type: "text";
+                                      }
+                                    | {
+                                        data: string;
+                                        mediaType: string;
+                                        type: "media";
+                                      }
+                                    | {
+                                        data: string;
+                                        filename?: string;
+                                        mediaType: string;
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "file-data";
+                                      }
+                                    | {
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "file-url";
+                                        url: string;
+                                      }
+                                    | {
+                                        fileId: string | Record<string, string>;
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "file-id";
+                                      }
+                                    | {
+                                        data: string;
+                                        mediaType: string;
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "image-data";
+                                      }
+                                    | {
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "image-url";
+                                        url: string;
+                                      }
+                                    | {
+                                        fileId: string | Record<string, string>;
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "image-file-id";
+                                      }
+                                    | {
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "custom";
+                                      }
+                                  >;
+                                };
+                            providerExecuted?: boolean;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            result?: any;
+                            toolCallId: string;
+                            toolName: string;
+                            type: "tool-result";
+                          }
+                        | {
+                            id: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            sourceType: "url";
+                            title?: string;
+                            type: "source";
+                            url: string;
+                          }
+                        | {
+                            filename?: string;
+                            id: string;
+                            mediaType: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            sourceType: "document";
+                            title: string;
+                            type: "source";
+                          }
+                        | {
+                            approvalId: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            toolCallId: string;
+                            type: "tool-approval-request";
+                          }
+                      >;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  role: "assistant";
+                }
+              | {
+                  content: Array<
+                    | {
+                        args?: any;
+                        experimental_content?: Array<
+                          | { text: string; type: "text" }
+                          | { data: string; mimeType?: string; type: "image" }
+                        >;
+                        isError?: boolean;
+                        output?:
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              type: "text";
+                              value: string;
+                            }
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              type: "json";
+                              value: any;
+                            }
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              type: "error-text";
+                              value: string;
+                            }
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              type: "error-json";
+                              value: any;
+                            }
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              reason?: string;
+                              type: "execution-denied";
+                            }
+                          | {
+                              type: "content";
+                              value: Array<
+                                | {
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    text: string;
+                                    type: "text";
+                                  }
+                                | {
+                                    data: string;
+                                    mediaType: string;
+                                    type: "media";
+                                  }
+                                | {
+                                    data: string;
+                                    filename?: string;
+                                    mediaType: string;
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "file-data";
+                                  }
+                                | {
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "file-url";
+                                    url: string;
+                                  }
+                                | {
+                                    fileId: string | Record<string, string>;
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "file-id";
+                                  }
+                                | {
+                                    data: string;
+                                    mediaType: string;
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "image-data";
+                                  }
+                                | {
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "image-url";
+                                    url: string;
+                                  }
+                                | {
+                                    fileId: string | Record<string, string>;
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "image-file-id";
+                                  }
+                                | {
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "custom";
+                                  }
+                              >;
+                            };
+                        providerExecuted?: boolean;
+                        providerMetadata?: Record<string, Record<string, any>>;
+                        providerOptions?: Record<string, Record<string, any>>;
+                        result?: any;
+                        toolCallId: string;
+                        toolName: string;
+                        type: "tool-result";
+                      }
+                    | {
+                        approvalId: string;
+                        approved: boolean;
+                        providerExecuted?: boolean;
+                        providerMetadata?: Record<string, Record<string, any>>;
+                        providerOptions?: Record<string, Record<string, any>>;
+                        reason?: string;
+                        type: "tool-approval-response";
+                      }
+                  >;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  role: "tool";
+                }
+              | {
+                  content: string;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  role: "system";
+                };
+            model?: string;
+            order: number;
+            provider?: string;
+            providerMetadata?: Record<string, Record<string, any>>;
+            providerOptions?: Record<string, Record<string, any>>;
+            reasoning?: string;
+            reasoningDetails?: Array<
+              | {
+                  providerMetadata?: Record<string, Record<string, any>>;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  signature?: string;
+                  text: string;
+                  type: "reasoning";
+                }
+              | { signature?: string; text: string; type: "text" }
+              | { data: string; type: "redacted" }
+            >;
+            sources?: Array<
+              | {
+                  id: string;
+                  providerMetadata?: Record<string, Record<string, any>>;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  sourceType: "url";
+                  title?: string;
+                  type?: "source";
+                  url: string;
+                }
+              | {
+                  filename?: string;
+                  id: string;
+                  mediaType: string;
+                  providerMetadata?: Record<string, Record<string, any>>;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  sourceType: "document";
+                  title: string;
+                  type: "source";
+                }
+            >;
+            status: "pending" | "success" | "failed";
+            stepOrder: number;
+            text?: string;
+            threadId: string;
+            tool: boolean;
+            usage?: {
+              cachedInputTokens?: number;
+              completionTokens: number;
+              promptTokens: number;
+              reasoningTokens?: number;
+              totalTokens: number;
+            };
+            userId?: string;
+            warnings?: Array<
+              | {
+                  details?: string;
+                  setting: string;
+                  type: "unsupported-setting";
+                }
+              | { details?: string; tool: any; type: "unsupported-tool" }
+              | { message: string; type: "other" }
+            >;
+          }>;
+        }
+      >;
+      cloneThread: FunctionReference<
+        "action",
+        "internal",
+        {
+          batchSize?: number;
+          copyUserIdForVectorSearch?: boolean;
+          excludeToolMessages?: boolean;
+          insertAtOrder?: number;
+          limit?: number;
+          sourceThreadId: string;
+          statuses?: Array<"pending" | "success" | "failed">;
+          targetThreadId: string;
+          upToAndIncludingMessageId?: string;
+        },
+        number
+      >;
+      deleteByIds: FunctionReference<
+        "mutation",
+        "internal",
+        { messageIds: Array<string> },
+        Array<string>
+      >;
+      deleteByOrder: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          endOrder: number;
+          endStepOrder?: number;
+          startOrder: number;
+          startStepOrder?: number;
+          threadId: string;
+        },
+        { isDone: boolean; lastOrder?: number; lastStepOrder?: number }
+      >;
+      finalizeMessage: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          messageId: string;
+          result: { status: "success" } | { error: string; status: "failed" };
+        },
+        null
+      >;
+      getMessagesByIds: FunctionReference<
+        "query",
+        "internal",
+        { messageIds: Array<string> },
+        Array<null | {
+          _creationTime: number;
+          _id: string;
+          agentName?: string;
+          embeddingId?: string;
+          error?: string;
+          fileIds?: Array<string>;
+          finishReason?:
+            | "stop"
+            | "length"
+            | "content-filter"
+            | "tool-calls"
+            | "error"
+            | "other"
+            | "unknown";
+          id?: string;
+          message?:
+            | {
+                content:
+                  | string
+                  | Array<
+                      | {
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          text: string;
+                          type: "text";
+                        }
+                      | {
+                          image: string | ArrayBuffer;
+                          mediaType?: string;
+                          mimeType?: string;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          type: "image";
+                        }
+                      | {
+                          data: string | ArrayBuffer;
+                          filename?: string;
+                          mediaType?: string;
+                          mimeType?: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          type: "file";
+                        }
+                    >;
+                providerOptions?: Record<string, Record<string, any>>;
+                role: "user";
+              }
+            | {
+                content:
+                  | string
+                  | Array<
+                      | {
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          text: string;
+                          type: "text";
+                        }
+                      | {
+                          data: string | ArrayBuffer;
+                          filename?: string;
+                          mediaType?: string;
+                          mimeType?: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          type: "file";
+                        }
+                      | {
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          signature?: string;
+                          text: string;
+                          type: "reasoning";
+                        }
+                      | {
+                          data: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          type: "redacted-reasoning";
+                        }
+                      | {
+                          args?: any;
+                          input: any;
+                          providerExecuted?: boolean;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          toolCallId: string;
+                          toolName: string;
+                          type: "tool-call";
+                        }
+                      | {
+                          args: any;
+                          input?: any;
+                          providerExecuted?: boolean;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          toolCallId: string;
+                          toolName: string;
+                          type: "tool-call";
+                        }
+                      | {
+                          args?: any;
+                          experimental_content?: Array<
+                            | { text: string; type: "text" }
+                            | { data: string; mimeType?: string; type: "image" }
+                          >;
+                          isError?: boolean;
+                          output?:
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                type: "text";
+                                value: string;
+                              }
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                type: "json";
+                                value: any;
+                              }
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                type: "error-text";
+                                value: string;
+                              }
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                type: "error-json";
+                                value: any;
+                              }
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                reason?: string;
+                                type: "execution-denied";
+                              }
+                            | {
+                                type: "content";
+                                value: Array<
+                                  | {
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      text: string;
+                                      type: "text";
+                                    }
+                                  | {
+                                      data: string;
+                                      mediaType: string;
+                                      type: "media";
+                                    }
+                                  | {
+                                      data: string;
+                                      filename?: string;
+                                      mediaType: string;
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "file-data";
+                                    }
+                                  | {
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "file-url";
+                                      url: string;
+                                    }
+                                  | {
+                                      fileId: string | Record<string, string>;
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "file-id";
+                                    }
+                                  | {
+                                      data: string;
+                                      mediaType: string;
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "image-data";
+                                    }
+                                  | {
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "image-url";
+                                      url: string;
+                                    }
+                                  | {
+                                      fileId: string | Record<string, string>;
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "image-file-id";
+                                    }
+                                  | {
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "custom";
+                                    }
+                                >;
+                              };
+                          providerExecuted?: boolean;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          result?: any;
+                          toolCallId: string;
+                          toolName: string;
+                          type: "tool-result";
+                        }
+                      | {
+                          id: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          sourceType: "url";
+                          title?: string;
+                          type: "source";
+                          url: string;
+                        }
+                      | {
+                          filename?: string;
+                          id: string;
+                          mediaType: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          sourceType: "document";
+                          title: string;
+                          type: "source";
+                        }
+                      | {
+                          approvalId: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          toolCallId: string;
+                          type: "tool-approval-request";
+                        }
+                    >;
+                providerOptions?: Record<string, Record<string, any>>;
+                role: "assistant";
+              }
+            | {
+                content: Array<
+                  | {
+                      args?: any;
+                      experimental_content?: Array<
+                        | { text: string; type: "text" }
+                        | { data: string; mimeType?: string; type: "image" }
+                      >;
+                      isError?: boolean;
+                      output?:
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "text";
+                            value: string;
+                          }
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "json";
+                            value: any;
+                          }
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "error-text";
+                            value: string;
+                          }
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "error-json";
+                            value: any;
+                          }
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            reason?: string;
+                            type: "execution-denied";
+                          }
+                        | {
+                            type: "content";
+                            value: Array<
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  text: string;
+                                  type: "text";
+                                }
+                              | {
+                                  data: string;
+                                  mediaType: string;
+                                  type: "media";
+                                }
+                              | {
+                                  data: string;
+                                  filename?: string;
+                                  mediaType: string;
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "file-data";
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "file-url";
+                                  url: string;
+                                }
+                              | {
+                                  fileId: string | Record<string, string>;
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "file-id";
+                                }
+                              | {
+                                  data: string;
+                                  mediaType: string;
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "image-data";
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "image-url";
+                                  url: string;
+                                }
+                              | {
+                                  fileId: string | Record<string, string>;
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "image-file-id";
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "custom";
+                                }
+                            >;
+                          };
+                      providerExecuted?: boolean;
+                      providerMetadata?: Record<string, Record<string, any>>;
+                      providerOptions?: Record<string, Record<string, any>>;
+                      result?: any;
+                      toolCallId: string;
+                      toolName: string;
+                      type: "tool-result";
+                    }
+                  | {
+                      approvalId: string;
+                      approved: boolean;
+                      providerExecuted?: boolean;
+                      providerMetadata?: Record<string, Record<string, any>>;
+                      providerOptions?: Record<string, Record<string, any>>;
+                      reason?: string;
+                      type: "tool-approval-response";
+                    }
+                >;
+                providerOptions?: Record<string, Record<string, any>>;
+                role: "tool";
+              }
+            | {
+                content: string;
+                providerOptions?: Record<string, Record<string, any>>;
+                role: "system";
+              };
+          model?: string;
+          order: number;
+          provider?: string;
+          providerMetadata?: Record<string, Record<string, any>>;
+          providerOptions?: Record<string, Record<string, any>>;
+          reasoning?: string;
+          reasoningDetails?: Array<
+            | {
+                providerMetadata?: Record<string, Record<string, any>>;
+                providerOptions?: Record<string, Record<string, any>>;
+                signature?: string;
+                text: string;
+                type: "reasoning";
+              }
+            | { signature?: string; text: string; type: "text" }
+            | { data: string; type: "redacted" }
+          >;
+          sources?: Array<
+            | {
+                id: string;
+                providerMetadata?: Record<string, Record<string, any>>;
+                providerOptions?: Record<string, Record<string, any>>;
+                sourceType: "url";
+                title?: string;
+                type?: "source";
+                url: string;
+              }
+            | {
+                filename?: string;
+                id: string;
+                mediaType: string;
+                providerMetadata?: Record<string, Record<string, any>>;
+                providerOptions?: Record<string, Record<string, any>>;
+                sourceType: "document";
+                title: string;
+                type: "source";
+              }
+          >;
+          status: "pending" | "success" | "failed";
+          stepOrder: number;
+          text?: string;
+          threadId: string;
+          tool: boolean;
+          usage?: {
+            cachedInputTokens?: number;
+            completionTokens: number;
+            promptTokens: number;
+            reasoningTokens?: number;
+            totalTokens: number;
+          };
+          userId?: string;
+          warnings?: Array<
+            | { details?: string; setting: string; type: "unsupported-setting" }
+            | { details?: string; tool: any; type: "unsupported-tool" }
+            | { message: string; type: "other" }
+          >;
+        }>
+      >;
+      getMessageSearchFields: FunctionReference<
+        "query",
+        "internal",
+        { messageId: string },
+        { embedding?: Array<number>; embeddingModel?: string; text?: string }
+      >;
+      listMessagesByThreadId: FunctionReference<
+        "query",
+        "internal",
+        {
+          excludeToolMessages?: boolean;
+          order: "asc" | "desc";
+          paginationOpts?: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+          statuses?: Array<"pending" | "success" | "failed">;
+          threadId: string;
+          upToAndIncludingMessageId?: string;
+        },
+        {
+          continueCursor: string;
+          isDone: boolean;
+          page: Array<{
+            _creationTime: number;
+            _id: string;
+            agentName?: string;
+            embeddingId?: string;
+            error?: string;
+            fileIds?: Array<string>;
+            finishReason?:
+              | "stop"
+              | "length"
+              | "content-filter"
+              | "tool-calls"
+              | "error"
+              | "other"
+              | "unknown";
+            id?: string;
+            message?:
+              | {
+                  content:
+                    | string
+                    | Array<
+                        | {
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            text: string;
+                            type: "text";
+                          }
+                        | {
+                            image: string | ArrayBuffer;
+                            mediaType?: string;
+                            mimeType?: string;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "image";
+                          }
+                        | {
+                            data: string | ArrayBuffer;
+                            filename?: string;
+                            mediaType?: string;
+                            mimeType?: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "file";
+                          }
+                      >;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  role: "user";
+                }
+              | {
+                  content:
+                    | string
+                    | Array<
+                        | {
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            text: string;
+                            type: "text";
+                          }
+                        | {
+                            data: string | ArrayBuffer;
+                            filename?: string;
+                            mediaType?: string;
+                            mimeType?: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "file";
+                          }
+                        | {
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            signature?: string;
+                            text: string;
+                            type: "reasoning";
+                          }
+                        | {
+                            data: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "redacted-reasoning";
+                          }
+                        | {
+                            args?: any;
+                            input: any;
+                            providerExecuted?: boolean;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            toolCallId: string;
+                            toolName: string;
+                            type: "tool-call";
+                          }
+                        | {
+                            args: any;
+                            input?: any;
+                            providerExecuted?: boolean;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            toolCallId: string;
+                            toolName: string;
+                            type: "tool-call";
+                          }
+                        | {
+                            args?: any;
+                            experimental_content?: Array<
+                              | { text: string; type: "text" }
+                              | {
+                                  data: string;
+                                  mimeType?: string;
+                                  type: "image";
+                                }
+                            >;
+                            isError?: boolean;
+                            output?:
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "text";
+                                  value: string;
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "json";
+                                  value: any;
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "error-text";
+                                  value: string;
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "error-json";
+                                  value: any;
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  reason?: string;
+                                  type: "execution-denied";
+                                }
+                              | {
+                                  type: "content";
+                                  value: Array<
+                                    | {
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        text: string;
+                                        type: "text";
+                                      }
+                                    | {
+                                        data: string;
+                                        mediaType: string;
+                                        type: "media";
+                                      }
+                                    | {
+                                        data: string;
+                                        filename?: string;
+                                        mediaType: string;
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "file-data";
+                                      }
+                                    | {
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "file-url";
+                                        url: string;
+                                      }
+                                    | {
+                                        fileId: string | Record<string, string>;
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "file-id";
+                                      }
+                                    | {
+                                        data: string;
+                                        mediaType: string;
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "image-data";
+                                      }
+                                    | {
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "image-url";
+                                        url: string;
+                                      }
+                                    | {
+                                        fileId: string | Record<string, string>;
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "image-file-id";
+                                      }
+                                    | {
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "custom";
+                                      }
+                                  >;
+                                };
+                            providerExecuted?: boolean;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            result?: any;
+                            toolCallId: string;
+                            toolName: string;
+                            type: "tool-result";
+                          }
+                        | {
+                            id: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            sourceType: "url";
+                            title?: string;
+                            type: "source";
+                            url: string;
+                          }
+                        | {
+                            filename?: string;
+                            id: string;
+                            mediaType: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            sourceType: "document";
+                            title: string;
+                            type: "source";
+                          }
+                        | {
+                            approvalId: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            toolCallId: string;
+                            type: "tool-approval-request";
+                          }
+                      >;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  role: "assistant";
+                }
+              | {
+                  content: Array<
+                    | {
+                        args?: any;
+                        experimental_content?: Array<
+                          | { text: string; type: "text" }
+                          | { data: string; mimeType?: string; type: "image" }
+                        >;
+                        isError?: boolean;
+                        output?:
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              type: "text";
+                              value: string;
+                            }
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              type: "json";
+                              value: any;
+                            }
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              type: "error-text";
+                              value: string;
+                            }
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              type: "error-json";
+                              value: any;
+                            }
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              reason?: string;
+                              type: "execution-denied";
+                            }
+                          | {
+                              type: "content";
+                              value: Array<
+                                | {
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    text: string;
+                                    type: "text";
+                                  }
+                                | {
+                                    data: string;
+                                    mediaType: string;
+                                    type: "media";
+                                  }
+                                | {
+                                    data: string;
+                                    filename?: string;
+                                    mediaType: string;
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "file-data";
+                                  }
+                                | {
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "file-url";
+                                    url: string;
+                                  }
+                                | {
+                                    fileId: string | Record<string, string>;
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "file-id";
+                                  }
+                                | {
+                                    data: string;
+                                    mediaType: string;
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "image-data";
+                                  }
+                                | {
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "image-url";
+                                    url: string;
+                                  }
+                                | {
+                                    fileId: string | Record<string, string>;
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "image-file-id";
+                                  }
+                                | {
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "custom";
+                                  }
+                              >;
+                            };
+                        providerExecuted?: boolean;
+                        providerMetadata?: Record<string, Record<string, any>>;
+                        providerOptions?: Record<string, Record<string, any>>;
+                        result?: any;
+                        toolCallId: string;
+                        toolName: string;
+                        type: "tool-result";
+                      }
+                    | {
+                        approvalId: string;
+                        approved: boolean;
+                        providerExecuted?: boolean;
+                        providerMetadata?: Record<string, Record<string, any>>;
+                        providerOptions?: Record<string, Record<string, any>>;
+                        reason?: string;
+                        type: "tool-approval-response";
+                      }
+                  >;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  role: "tool";
+                }
+              | {
+                  content: string;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  role: "system";
+                };
+            model?: string;
+            order: number;
+            provider?: string;
+            providerMetadata?: Record<string, Record<string, any>>;
+            providerOptions?: Record<string, Record<string, any>>;
+            reasoning?: string;
+            reasoningDetails?: Array<
+              | {
+                  providerMetadata?: Record<string, Record<string, any>>;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  signature?: string;
+                  text: string;
+                  type: "reasoning";
+                }
+              | { signature?: string; text: string; type: "text" }
+              | { data: string; type: "redacted" }
+            >;
+            sources?: Array<
+              | {
+                  id: string;
+                  providerMetadata?: Record<string, Record<string, any>>;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  sourceType: "url";
+                  title?: string;
+                  type?: "source";
+                  url: string;
+                }
+              | {
+                  filename?: string;
+                  id: string;
+                  mediaType: string;
+                  providerMetadata?: Record<string, Record<string, any>>;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  sourceType: "document";
+                  title: string;
+                  type: "source";
+                }
+            >;
+            status: "pending" | "success" | "failed";
+            stepOrder: number;
+            text?: string;
+            threadId: string;
+            tool: boolean;
+            usage?: {
+              cachedInputTokens?: number;
+              completionTokens: number;
+              promptTokens: number;
+              reasoningTokens?: number;
+              totalTokens: number;
+            };
+            userId?: string;
+            warnings?: Array<
+              | {
+                  details?: string;
+                  setting: string;
+                  type: "unsupported-setting";
+                }
+              | { details?: string; tool: any; type: "unsupported-tool" }
+              | { message: string; type: "other" }
+            >;
+          }>;
+          pageStatus?: "SplitRecommended" | "SplitRequired" | null;
+          splitCursor?: string | null;
+        }
+      >;
+      searchMessages: FunctionReference<
+        "action",
+        "internal",
+        {
+          embedding?: Array<number>;
+          embeddingModel?: string;
+          limit: number;
+          messageRange?: { after: number; before: number };
+          searchAllMessagesForUserId?: string;
+          targetMessageId?: string;
+          text?: string;
+          textSearch?: boolean;
+          threadId?: string;
+          vectorScoreThreshold?: number;
+          vectorSearch?: boolean;
+        },
+        Array<{
+          _creationTime: number;
+          _id: string;
+          agentName?: string;
+          embeddingId?: string;
+          error?: string;
+          fileIds?: Array<string>;
+          finishReason?:
+            | "stop"
+            | "length"
+            | "content-filter"
+            | "tool-calls"
+            | "error"
+            | "other"
+            | "unknown";
+          id?: string;
+          message?:
+            | {
+                content:
+                  | string
+                  | Array<
+                      | {
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          text: string;
+                          type: "text";
+                        }
+                      | {
+                          image: string | ArrayBuffer;
+                          mediaType?: string;
+                          mimeType?: string;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          type: "image";
+                        }
+                      | {
+                          data: string | ArrayBuffer;
+                          filename?: string;
+                          mediaType?: string;
+                          mimeType?: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          type: "file";
+                        }
+                    >;
+                providerOptions?: Record<string, Record<string, any>>;
+                role: "user";
+              }
+            | {
+                content:
+                  | string
+                  | Array<
+                      | {
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          text: string;
+                          type: "text";
+                        }
+                      | {
+                          data: string | ArrayBuffer;
+                          filename?: string;
+                          mediaType?: string;
+                          mimeType?: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          type: "file";
+                        }
+                      | {
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          signature?: string;
+                          text: string;
+                          type: "reasoning";
+                        }
+                      | {
+                          data: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          type: "redacted-reasoning";
+                        }
+                      | {
+                          args?: any;
+                          input: any;
+                          providerExecuted?: boolean;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          toolCallId: string;
+                          toolName: string;
+                          type: "tool-call";
+                        }
+                      | {
+                          args: any;
+                          input?: any;
+                          providerExecuted?: boolean;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          toolCallId: string;
+                          toolName: string;
+                          type: "tool-call";
+                        }
+                      | {
+                          args?: any;
+                          experimental_content?: Array<
+                            | { text: string; type: "text" }
+                            | { data: string; mimeType?: string; type: "image" }
+                          >;
+                          isError?: boolean;
+                          output?:
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                type: "text";
+                                value: string;
+                              }
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                type: "json";
+                                value: any;
+                              }
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                type: "error-text";
+                                value: string;
+                              }
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                type: "error-json";
+                                value: any;
+                              }
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                reason?: string;
+                                type: "execution-denied";
+                              }
+                            | {
+                                type: "content";
+                                value: Array<
+                                  | {
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      text: string;
+                                      type: "text";
+                                    }
+                                  | {
+                                      data: string;
+                                      mediaType: string;
+                                      type: "media";
+                                    }
+                                  | {
+                                      data: string;
+                                      filename?: string;
+                                      mediaType: string;
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "file-data";
+                                    }
+                                  | {
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "file-url";
+                                      url: string;
+                                    }
+                                  | {
+                                      fileId: string | Record<string, string>;
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "file-id";
+                                    }
+                                  | {
+                                      data: string;
+                                      mediaType: string;
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "image-data";
+                                    }
+                                  | {
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "image-url";
+                                      url: string;
+                                    }
+                                  | {
+                                      fileId: string | Record<string, string>;
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "image-file-id";
+                                    }
+                                  | {
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "custom";
+                                    }
+                                >;
+                              };
+                          providerExecuted?: boolean;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          result?: any;
+                          toolCallId: string;
+                          toolName: string;
+                          type: "tool-result";
+                        }
+                      | {
+                          id: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          sourceType: "url";
+                          title?: string;
+                          type: "source";
+                          url: string;
+                        }
+                      | {
+                          filename?: string;
+                          id: string;
+                          mediaType: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          sourceType: "document";
+                          title: string;
+                          type: "source";
+                        }
+                      | {
+                          approvalId: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          toolCallId: string;
+                          type: "tool-approval-request";
+                        }
+                    >;
+                providerOptions?: Record<string, Record<string, any>>;
+                role: "assistant";
+              }
+            | {
+                content: Array<
+                  | {
+                      args?: any;
+                      experimental_content?: Array<
+                        | { text: string; type: "text" }
+                        | { data: string; mimeType?: string; type: "image" }
+                      >;
+                      isError?: boolean;
+                      output?:
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "text";
+                            value: string;
+                          }
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "json";
+                            value: any;
+                          }
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "error-text";
+                            value: string;
+                          }
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "error-json";
+                            value: any;
+                          }
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            reason?: string;
+                            type: "execution-denied";
+                          }
+                        | {
+                            type: "content";
+                            value: Array<
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  text: string;
+                                  type: "text";
+                                }
+                              | {
+                                  data: string;
+                                  mediaType: string;
+                                  type: "media";
+                                }
+                              | {
+                                  data: string;
+                                  filename?: string;
+                                  mediaType: string;
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "file-data";
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "file-url";
+                                  url: string;
+                                }
+                              | {
+                                  fileId: string | Record<string, string>;
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "file-id";
+                                }
+                              | {
+                                  data: string;
+                                  mediaType: string;
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "image-data";
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "image-url";
+                                  url: string;
+                                }
+                              | {
+                                  fileId: string | Record<string, string>;
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "image-file-id";
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "custom";
+                                }
+                            >;
+                          };
+                      providerExecuted?: boolean;
+                      providerMetadata?: Record<string, Record<string, any>>;
+                      providerOptions?: Record<string, Record<string, any>>;
+                      result?: any;
+                      toolCallId: string;
+                      toolName: string;
+                      type: "tool-result";
+                    }
+                  | {
+                      approvalId: string;
+                      approved: boolean;
+                      providerExecuted?: boolean;
+                      providerMetadata?: Record<string, Record<string, any>>;
+                      providerOptions?: Record<string, Record<string, any>>;
+                      reason?: string;
+                      type: "tool-approval-response";
+                    }
+                >;
+                providerOptions?: Record<string, Record<string, any>>;
+                role: "tool";
+              }
+            | {
+                content: string;
+                providerOptions?: Record<string, Record<string, any>>;
+                role: "system";
+              };
+          model?: string;
+          order: number;
+          provider?: string;
+          providerMetadata?: Record<string, Record<string, any>>;
+          providerOptions?: Record<string, Record<string, any>>;
+          reasoning?: string;
+          reasoningDetails?: Array<
+            | {
+                providerMetadata?: Record<string, Record<string, any>>;
+                providerOptions?: Record<string, Record<string, any>>;
+                signature?: string;
+                text: string;
+                type: "reasoning";
+              }
+            | { signature?: string; text: string; type: "text" }
+            | { data: string; type: "redacted" }
+          >;
+          sources?: Array<
+            | {
+                id: string;
+                providerMetadata?: Record<string, Record<string, any>>;
+                providerOptions?: Record<string, Record<string, any>>;
+                sourceType: "url";
+                title?: string;
+                type?: "source";
+                url: string;
+              }
+            | {
+                filename?: string;
+                id: string;
+                mediaType: string;
+                providerMetadata?: Record<string, Record<string, any>>;
+                providerOptions?: Record<string, Record<string, any>>;
+                sourceType: "document";
+                title: string;
+                type: "source";
+              }
+          >;
+          status: "pending" | "success" | "failed";
+          stepOrder: number;
+          text?: string;
+          threadId: string;
+          tool: boolean;
+          usage?: {
+            cachedInputTokens?: number;
+            completionTokens: number;
+            promptTokens: number;
+            reasoningTokens?: number;
+            totalTokens: number;
+          };
+          userId?: string;
+          warnings?: Array<
+            | { details?: string; setting: string; type: "unsupported-setting" }
+            | { details?: string; tool: any; type: "unsupported-tool" }
+            | { message: string; type: "other" }
+          >;
+        }>
+      >;
+      textSearch: FunctionReference<
+        "query",
+        "internal",
+        {
+          limit: number;
+          searchAllMessagesForUserId?: string;
+          targetMessageId?: string;
+          text?: string;
+          threadId?: string;
+        },
+        Array<{
+          _creationTime: number;
+          _id: string;
+          agentName?: string;
+          embeddingId?: string;
+          error?: string;
+          fileIds?: Array<string>;
+          finishReason?:
+            | "stop"
+            | "length"
+            | "content-filter"
+            | "tool-calls"
+            | "error"
+            | "other"
+            | "unknown";
+          id?: string;
+          message?:
+            | {
+                content:
+                  | string
+                  | Array<
+                      | {
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          text: string;
+                          type: "text";
+                        }
+                      | {
+                          image: string | ArrayBuffer;
+                          mediaType?: string;
+                          mimeType?: string;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          type: "image";
+                        }
+                      | {
+                          data: string | ArrayBuffer;
+                          filename?: string;
+                          mediaType?: string;
+                          mimeType?: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          type: "file";
+                        }
+                    >;
+                providerOptions?: Record<string, Record<string, any>>;
+                role: "user";
+              }
+            | {
+                content:
+                  | string
+                  | Array<
+                      | {
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          text: string;
+                          type: "text";
+                        }
+                      | {
+                          data: string | ArrayBuffer;
+                          filename?: string;
+                          mediaType?: string;
+                          mimeType?: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          type: "file";
+                        }
+                      | {
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          signature?: string;
+                          text: string;
+                          type: "reasoning";
+                        }
+                      | {
+                          data: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          type: "redacted-reasoning";
+                        }
+                      | {
+                          args?: any;
+                          input: any;
+                          providerExecuted?: boolean;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          toolCallId: string;
+                          toolName: string;
+                          type: "tool-call";
+                        }
+                      | {
+                          args: any;
+                          input?: any;
+                          providerExecuted?: boolean;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          toolCallId: string;
+                          toolName: string;
+                          type: "tool-call";
+                        }
+                      | {
+                          args?: any;
+                          experimental_content?: Array<
+                            | { text: string; type: "text" }
+                            | { data: string; mimeType?: string; type: "image" }
+                          >;
+                          isError?: boolean;
+                          output?:
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                type: "text";
+                                value: string;
+                              }
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                type: "json";
+                                value: any;
+                              }
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                type: "error-text";
+                                value: string;
+                              }
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                type: "error-json";
+                                value: any;
+                              }
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                reason?: string;
+                                type: "execution-denied";
+                              }
+                            | {
+                                type: "content";
+                                value: Array<
+                                  | {
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      text: string;
+                                      type: "text";
+                                    }
+                                  | {
+                                      data: string;
+                                      mediaType: string;
+                                      type: "media";
+                                    }
+                                  | {
+                                      data: string;
+                                      filename?: string;
+                                      mediaType: string;
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "file-data";
+                                    }
+                                  | {
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "file-url";
+                                      url: string;
+                                    }
+                                  | {
+                                      fileId: string | Record<string, string>;
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "file-id";
+                                    }
+                                  | {
+                                      data: string;
+                                      mediaType: string;
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "image-data";
+                                    }
+                                  | {
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "image-url";
+                                      url: string;
+                                    }
+                                  | {
+                                      fileId: string | Record<string, string>;
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "image-file-id";
+                                    }
+                                  | {
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "custom";
+                                    }
+                                >;
+                              };
+                          providerExecuted?: boolean;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          result?: any;
+                          toolCallId: string;
+                          toolName: string;
+                          type: "tool-result";
+                        }
+                      | {
+                          id: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          sourceType: "url";
+                          title?: string;
+                          type: "source";
+                          url: string;
+                        }
+                      | {
+                          filename?: string;
+                          id: string;
+                          mediaType: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          sourceType: "document";
+                          title: string;
+                          type: "source";
+                        }
+                      | {
+                          approvalId: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          toolCallId: string;
+                          type: "tool-approval-request";
+                        }
+                    >;
+                providerOptions?: Record<string, Record<string, any>>;
+                role: "assistant";
+              }
+            | {
+                content: Array<
+                  | {
+                      args?: any;
+                      experimental_content?: Array<
+                        | { text: string; type: "text" }
+                        | { data: string; mimeType?: string; type: "image" }
+                      >;
+                      isError?: boolean;
+                      output?:
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "text";
+                            value: string;
+                          }
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "json";
+                            value: any;
+                          }
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "error-text";
+                            value: string;
+                          }
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "error-json";
+                            value: any;
+                          }
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            reason?: string;
+                            type: "execution-denied";
+                          }
+                        | {
+                            type: "content";
+                            value: Array<
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  text: string;
+                                  type: "text";
+                                }
+                              | {
+                                  data: string;
+                                  mediaType: string;
+                                  type: "media";
+                                }
+                              | {
+                                  data: string;
+                                  filename?: string;
+                                  mediaType: string;
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "file-data";
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "file-url";
+                                  url: string;
+                                }
+                              | {
+                                  fileId: string | Record<string, string>;
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "file-id";
+                                }
+                              | {
+                                  data: string;
+                                  mediaType: string;
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "image-data";
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "image-url";
+                                  url: string;
+                                }
+                              | {
+                                  fileId: string | Record<string, string>;
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "image-file-id";
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "custom";
+                                }
+                            >;
+                          };
+                      providerExecuted?: boolean;
+                      providerMetadata?: Record<string, Record<string, any>>;
+                      providerOptions?: Record<string, Record<string, any>>;
+                      result?: any;
+                      toolCallId: string;
+                      toolName: string;
+                      type: "tool-result";
+                    }
+                  | {
+                      approvalId: string;
+                      approved: boolean;
+                      providerExecuted?: boolean;
+                      providerMetadata?: Record<string, Record<string, any>>;
+                      providerOptions?: Record<string, Record<string, any>>;
+                      reason?: string;
+                      type: "tool-approval-response";
+                    }
+                >;
+                providerOptions?: Record<string, Record<string, any>>;
+                role: "tool";
+              }
+            | {
+                content: string;
+                providerOptions?: Record<string, Record<string, any>>;
+                role: "system";
+              };
+          model?: string;
+          order: number;
+          provider?: string;
+          providerMetadata?: Record<string, Record<string, any>>;
+          providerOptions?: Record<string, Record<string, any>>;
+          reasoning?: string;
+          reasoningDetails?: Array<
+            | {
+                providerMetadata?: Record<string, Record<string, any>>;
+                providerOptions?: Record<string, Record<string, any>>;
+                signature?: string;
+                text: string;
+                type: "reasoning";
+              }
+            | { signature?: string; text: string; type: "text" }
+            | { data: string; type: "redacted" }
+          >;
+          sources?: Array<
+            | {
+                id: string;
+                providerMetadata?: Record<string, Record<string, any>>;
+                providerOptions?: Record<string, Record<string, any>>;
+                sourceType: "url";
+                title?: string;
+                type?: "source";
+                url: string;
+              }
+            | {
+                filename?: string;
+                id: string;
+                mediaType: string;
+                providerMetadata?: Record<string, Record<string, any>>;
+                providerOptions?: Record<string, Record<string, any>>;
+                sourceType: "document";
+                title: string;
+                type: "source";
+              }
+          >;
+          status: "pending" | "success" | "failed";
+          stepOrder: number;
+          text?: string;
+          threadId: string;
+          tool: boolean;
+          usage?: {
+            cachedInputTokens?: number;
+            completionTokens: number;
+            promptTokens: number;
+            reasoningTokens?: number;
+            totalTokens: number;
+          };
+          userId?: string;
+          warnings?: Array<
+            | { details?: string; setting: string; type: "unsupported-setting" }
+            | { details?: string; tool: any; type: "unsupported-tool" }
+            | { message: string; type: "other" }
+          >;
+        }>
+      >;
+      updateMessage: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          messageId: string;
+          patch: {
+            error?: string;
+            fileIds?: Array<string>;
+            finishReason?:
+              | "stop"
+              | "length"
+              | "content-filter"
+              | "tool-calls"
+              | "error"
+              | "other"
+              | "unknown";
+            message?:
+              | {
+                  content:
+                    | string
+                    | Array<
+                        | {
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            text: string;
+                            type: "text";
+                          }
+                        | {
+                            image: string | ArrayBuffer;
+                            mediaType?: string;
+                            mimeType?: string;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "image";
+                          }
+                        | {
+                            data: string | ArrayBuffer;
+                            filename?: string;
+                            mediaType?: string;
+                            mimeType?: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "file";
+                          }
+                      >;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  role: "user";
+                }
+              | {
+                  content:
+                    | string
+                    | Array<
+                        | {
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            text: string;
+                            type: "text";
+                          }
+                        | {
+                            data: string | ArrayBuffer;
+                            filename?: string;
+                            mediaType?: string;
+                            mimeType?: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "file";
+                          }
+                        | {
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            signature?: string;
+                            text: string;
+                            type: "reasoning";
+                          }
+                        | {
+                            data: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "redacted-reasoning";
+                          }
+                        | {
+                            args?: any;
+                            input: any;
+                            providerExecuted?: boolean;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            toolCallId: string;
+                            toolName: string;
+                            type: "tool-call";
+                          }
+                        | {
+                            args: any;
+                            input?: any;
+                            providerExecuted?: boolean;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            toolCallId: string;
+                            toolName: string;
+                            type: "tool-call";
+                          }
+                        | {
+                            args?: any;
+                            experimental_content?: Array<
+                              | { text: string; type: "text" }
+                              | {
+                                  data: string;
+                                  mimeType?: string;
+                                  type: "image";
+                                }
+                            >;
+                            isError?: boolean;
+                            output?:
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "text";
+                                  value: string;
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "json";
+                                  value: any;
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "error-text";
+                                  value: string;
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "error-json";
+                                  value: any;
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  reason?: string;
+                                  type: "execution-denied";
+                                }
+                              | {
+                                  type: "content";
+                                  value: Array<
+                                    | {
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        text: string;
+                                        type: "text";
+                                      }
+                                    | {
+                                        data: string;
+                                        mediaType: string;
+                                        type: "media";
+                                      }
+                                    | {
+                                        data: string;
+                                        filename?: string;
+                                        mediaType: string;
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "file-data";
+                                      }
+                                    | {
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "file-url";
+                                        url: string;
+                                      }
+                                    | {
+                                        fileId: string | Record<string, string>;
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "file-id";
+                                      }
+                                    | {
+                                        data: string;
+                                        mediaType: string;
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "image-data";
+                                      }
+                                    | {
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "image-url";
+                                        url: string;
+                                      }
+                                    | {
+                                        fileId: string | Record<string, string>;
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "image-file-id";
+                                      }
+                                    | {
+                                        providerOptions?: Record<
+                                          string,
+                                          Record<string, any>
+                                        >;
+                                        type: "custom";
+                                      }
+                                  >;
+                                };
+                            providerExecuted?: boolean;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            result?: any;
+                            toolCallId: string;
+                            toolName: string;
+                            type: "tool-result";
+                          }
+                        | {
+                            id: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            sourceType: "url";
+                            title?: string;
+                            type: "source";
+                            url: string;
+                          }
+                        | {
+                            filename?: string;
+                            id: string;
+                            mediaType: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            sourceType: "document";
+                            title: string;
+                            type: "source";
+                          }
+                        | {
+                            approvalId: string;
+                            providerMetadata?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            toolCallId: string;
+                            type: "tool-approval-request";
+                          }
+                      >;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  role: "assistant";
+                }
+              | {
+                  content: Array<
+                    | {
+                        args?: any;
+                        experimental_content?: Array<
+                          | { text: string; type: "text" }
+                          | { data: string; mimeType?: string; type: "image" }
+                        >;
+                        isError?: boolean;
+                        output?:
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              type: "text";
+                              value: string;
+                            }
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              type: "json";
+                              value: any;
+                            }
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              type: "error-text";
+                              value: string;
+                            }
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              type: "error-json";
+                              value: any;
+                            }
+                          | {
+                              providerOptions?: Record<
+                                string,
+                                Record<string, any>
+                              >;
+                              reason?: string;
+                              type: "execution-denied";
+                            }
+                          | {
+                              type: "content";
+                              value: Array<
+                                | {
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    text: string;
+                                    type: "text";
+                                  }
+                                | {
+                                    data: string;
+                                    mediaType: string;
+                                    type: "media";
+                                  }
+                                | {
+                                    data: string;
+                                    filename?: string;
+                                    mediaType: string;
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "file-data";
+                                  }
+                                | {
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "file-url";
+                                    url: string;
+                                  }
+                                | {
+                                    fileId: string | Record<string, string>;
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "file-id";
+                                  }
+                                | {
+                                    data: string;
+                                    mediaType: string;
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "image-data";
+                                  }
+                                | {
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "image-url";
+                                    url: string;
+                                  }
+                                | {
+                                    fileId: string | Record<string, string>;
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "image-file-id";
+                                  }
+                                | {
+                                    providerOptions?: Record<
+                                      string,
+                                      Record<string, any>
+                                    >;
+                                    type: "custom";
+                                  }
+                              >;
+                            };
+                        providerExecuted?: boolean;
+                        providerMetadata?: Record<string, Record<string, any>>;
+                        providerOptions?: Record<string, Record<string, any>>;
+                        result?: any;
+                        toolCallId: string;
+                        toolName: string;
+                        type: "tool-result";
+                      }
+                    | {
+                        approvalId: string;
+                        approved: boolean;
+                        providerExecuted?: boolean;
+                        providerMetadata?: Record<string, Record<string, any>>;
+                        providerOptions?: Record<string, Record<string, any>>;
+                        reason?: string;
+                        type: "tool-approval-response";
+                      }
+                  >;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  role: "tool";
+                }
+              | {
+                  content: string;
+                  providerOptions?: Record<string, Record<string, any>>;
+                  role: "system";
+                };
+            model?: string;
+            provider?: string;
+            providerOptions?: Record<string, Record<string, any>>;
+            status?: "pending" | "success" | "failed";
+          };
+        },
+        {
+          _creationTime: number;
+          _id: string;
+          agentName?: string;
+          embeddingId?: string;
+          error?: string;
+          fileIds?: Array<string>;
+          finishReason?:
+            | "stop"
+            | "length"
+            | "content-filter"
+            | "tool-calls"
+            | "error"
+            | "other"
+            | "unknown";
+          id?: string;
+          message?:
+            | {
+                content:
+                  | string
+                  | Array<
+                      | {
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          text: string;
+                          type: "text";
+                        }
+                      | {
+                          image: string | ArrayBuffer;
+                          mediaType?: string;
+                          mimeType?: string;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          type: "image";
+                        }
+                      | {
+                          data: string | ArrayBuffer;
+                          filename?: string;
+                          mediaType?: string;
+                          mimeType?: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          type: "file";
+                        }
+                    >;
+                providerOptions?: Record<string, Record<string, any>>;
+                role: "user";
+              }
+            | {
+                content:
+                  | string
+                  | Array<
+                      | {
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          text: string;
+                          type: "text";
+                        }
+                      | {
+                          data: string | ArrayBuffer;
+                          filename?: string;
+                          mediaType?: string;
+                          mimeType?: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          type: "file";
+                        }
+                      | {
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          signature?: string;
+                          text: string;
+                          type: "reasoning";
+                        }
+                      | {
+                          data: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          type: "redacted-reasoning";
+                        }
+                      | {
+                          args?: any;
+                          input: any;
+                          providerExecuted?: boolean;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          toolCallId: string;
+                          toolName: string;
+                          type: "tool-call";
+                        }
+                      | {
+                          args: any;
+                          input?: any;
+                          providerExecuted?: boolean;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          toolCallId: string;
+                          toolName: string;
+                          type: "tool-call";
+                        }
+                      | {
+                          args?: any;
+                          experimental_content?: Array<
+                            | { text: string; type: "text" }
+                            | { data: string; mimeType?: string; type: "image" }
+                          >;
+                          isError?: boolean;
+                          output?:
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                type: "text";
+                                value: string;
+                              }
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                type: "json";
+                                value: any;
+                              }
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                type: "error-text";
+                                value: string;
+                              }
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                type: "error-json";
+                                value: any;
+                              }
+                            | {
+                                providerOptions?: Record<
+                                  string,
+                                  Record<string, any>
+                                >;
+                                reason?: string;
+                                type: "execution-denied";
+                              }
+                            | {
+                                type: "content";
+                                value: Array<
+                                  | {
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      text: string;
+                                      type: "text";
+                                    }
+                                  | {
+                                      data: string;
+                                      mediaType: string;
+                                      type: "media";
+                                    }
+                                  | {
+                                      data: string;
+                                      filename?: string;
+                                      mediaType: string;
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "file-data";
+                                    }
+                                  | {
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "file-url";
+                                      url: string;
+                                    }
+                                  | {
+                                      fileId: string | Record<string, string>;
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "file-id";
+                                    }
+                                  | {
+                                      data: string;
+                                      mediaType: string;
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "image-data";
+                                    }
+                                  | {
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "image-url";
+                                      url: string;
+                                    }
+                                  | {
+                                      fileId: string | Record<string, string>;
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "image-file-id";
+                                    }
+                                  | {
+                                      providerOptions?: Record<
+                                        string,
+                                        Record<string, any>
+                                      >;
+                                      type: "custom";
+                                    }
+                                >;
+                              };
+                          providerExecuted?: boolean;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          result?: any;
+                          toolCallId: string;
+                          toolName: string;
+                          type: "tool-result";
+                        }
+                      | {
+                          id: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          sourceType: "url";
+                          title?: string;
+                          type: "source";
+                          url: string;
+                        }
+                      | {
+                          filename?: string;
+                          id: string;
+                          mediaType: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          sourceType: "document";
+                          title: string;
+                          type: "source";
+                        }
+                      | {
+                          approvalId: string;
+                          providerMetadata?: Record<
+                            string,
+                            Record<string, any>
+                          >;
+                          providerOptions?: Record<string, Record<string, any>>;
+                          toolCallId: string;
+                          type: "tool-approval-request";
+                        }
+                    >;
+                providerOptions?: Record<string, Record<string, any>>;
+                role: "assistant";
+              }
+            | {
+                content: Array<
+                  | {
+                      args?: any;
+                      experimental_content?: Array<
+                        | { text: string; type: "text" }
+                        | { data: string; mimeType?: string; type: "image" }
+                      >;
+                      isError?: boolean;
+                      output?:
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "text";
+                            value: string;
+                          }
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "json";
+                            value: any;
+                          }
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "error-text";
+                            value: string;
+                          }
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            type: "error-json";
+                            value: any;
+                          }
+                        | {
+                            providerOptions?: Record<
+                              string,
+                              Record<string, any>
+                            >;
+                            reason?: string;
+                            type: "execution-denied";
+                          }
+                        | {
+                            type: "content";
+                            value: Array<
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  text: string;
+                                  type: "text";
+                                }
+                              | {
+                                  data: string;
+                                  mediaType: string;
+                                  type: "media";
+                                }
+                              | {
+                                  data: string;
+                                  filename?: string;
+                                  mediaType: string;
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "file-data";
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "file-url";
+                                  url: string;
+                                }
+                              | {
+                                  fileId: string | Record<string, string>;
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "file-id";
+                                }
+                              | {
+                                  data: string;
+                                  mediaType: string;
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "image-data";
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "image-url";
+                                  url: string;
+                                }
+                              | {
+                                  fileId: string | Record<string, string>;
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "image-file-id";
+                                }
+                              | {
+                                  providerOptions?: Record<
+                                    string,
+                                    Record<string, any>
+                                  >;
+                                  type: "custom";
+                                }
+                            >;
+                          };
+                      providerExecuted?: boolean;
+                      providerMetadata?: Record<string, Record<string, any>>;
+                      providerOptions?: Record<string, Record<string, any>>;
+                      result?: any;
+                      toolCallId: string;
+                      toolName: string;
+                      type: "tool-result";
+                    }
+                  | {
+                      approvalId: string;
+                      approved: boolean;
+                      providerExecuted?: boolean;
+                      providerMetadata?: Record<string, Record<string, any>>;
+                      providerOptions?: Record<string, Record<string, any>>;
+                      reason?: string;
+                      type: "tool-approval-response";
+                    }
+                >;
+                providerOptions?: Record<string, Record<string, any>>;
+                role: "tool";
+              }
+            | {
+                content: string;
+                providerOptions?: Record<string, Record<string, any>>;
+                role: "system";
+              };
+          model?: string;
+          order: number;
+          provider?: string;
+          providerMetadata?: Record<string, Record<string, any>>;
+          providerOptions?: Record<string, Record<string, any>>;
+          reasoning?: string;
+          reasoningDetails?: Array<
+            | {
+                providerMetadata?: Record<string, Record<string, any>>;
+                providerOptions?: Record<string, Record<string, any>>;
+                signature?: string;
+                text: string;
+                type: "reasoning";
+              }
+            | { signature?: string; text: string; type: "text" }
+            | { data: string; type: "redacted" }
+          >;
+          sources?: Array<
+            | {
+                id: string;
+                providerMetadata?: Record<string, Record<string, any>>;
+                providerOptions?: Record<string, Record<string, any>>;
+                sourceType: "url";
+                title?: string;
+                type?: "source";
+                url: string;
+              }
+            | {
+                filename?: string;
+                id: string;
+                mediaType: string;
+                providerMetadata?: Record<string, Record<string, any>>;
+                providerOptions?: Record<string, Record<string, any>>;
+                sourceType: "document";
+                title: string;
+                type: "source";
+              }
+          >;
+          status: "pending" | "success" | "failed";
+          stepOrder: number;
+          text?: string;
+          threadId: string;
+          tool: boolean;
+          usage?: {
+            cachedInputTokens?: number;
+            completionTokens: number;
+            promptTokens: number;
+            reasoningTokens?: number;
+            totalTokens: number;
+          };
+          userId?: string;
+          warnings?: Array<
+            | { details?: string; setting: string; type: "unsupported-setting" }
+            | { details?: string; tool: any; type: "unsupported-tool" }
+            | { message: string; type: "other" }
+          >;
+        }
+      >;
+    };
+    streams: {
+      abort: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          finalDelta?: {
+            end: number;
+            parts: Array<any>;
+            start: number;
+            streamId: string;
+          };
+          reason: string;
+          streamId: string;
+        },
+        boolean
+      >;
+      abortByOrder: FunctionReference<
+        "mutation",
+        "internal",
+        { order: number; reason: string; threadId: string },
+        boolean
+      >;
+      addDelta: FunctionReference<
+        "mutation",
+        "internal",
+        { end: number; parts: Array<any>; start: number; streamId: string },
+        boolean
+      >;
+      create: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          agentName?: string;
+          format?: "UIMessageChunk" | "TextStreamPart";
+          model?: string;
+          order: number;
+          provider?: string;
+          providerOptions?: Record<string, Record<string, any>>;
+          stepOrder: number;
+          threadId: string;
+          userId?: string;
+        },
+        string
+      >;
+      deleteAllStreamsForThreadIdAsync: FunctionReference<
+        "mutation",
+        "internal",
+        { deltaCursor?: string; streamOrder?: number; threadId: string },
+        { deltaCursor?: string; isDone: boolean; streamOrder?: number }
+      >;
+      deleteAllStreamsForThreadIdSync: FunctionReference<
+        "action",
+        "internal",
+        { threadId: string },
+        null
+      >;
+      deleteStreamAsync: FunctionReference<
+        "mutation",
+        "internal",
+        { cursor?: string; streamId: string },
+        null
+      >;
+      deleteStreamSync: FunctionReference<
+        "mutation",
+        "internal",
+        { streamId: string },
+        null
+      >;
+      finish: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          finalDelta?: {
+            end: number;
+            parts: Array<any>;
+            start: number;
+            streamId: string;
+          };
+          streamId: string;
+        },
+        null
+      >;
+      heartbeat: FunctionReference<
+        "mutation",
+        "internal",
+        { streamId: string },
+        null
+      >;
+      list: FunctionReference<
+        "query",
+        "internal",
+        {
+          startOrder?: number;
+          statuses?: Array<"streaming" | "finished" | "aborted">;
+          threadId: string;
+        },
+        Array<{
+          agentName?: string;
+          format?: "UIMessageChunk" | "TextStreamPart";
+          model?: string;
+          order: number;
+          provider?: string;
+          providerOptions?: Record<string, Record<string, any>>;
+          status: "streaming" | "finished" | "aborted";
+          stepOrder: number;
+          streamId: string;
+          userId?: string;
+        }>
+      >;
+      listDeltas: FunctionReference<
+        "query",
+        "internal",
+        {
+          cursors: Array<{ cursor: number; streamId: string }>;
+          threadId: string;
+        },
+        Array<{
+          end: number;
+          parts: Array<any>;
+          start: number;
+          streamId: string;
+        }>
+      >;
+    };
+    threads: {
+      createThread: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          defaultSystemPrompt?: string;
+          parentThreadIds?: Array<string>;
+          summary?: string;
+          title?: string;
+          userId?: string;
+        },
+        {
+          _creationTime: number;
+          _id: string;
+          status: "active" | "archived";
+          summary?: string;
+          title?: string;
+          userId?: string;
+        }
+      >;
+      deleteAllForThreadIdAsync: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          cursor?: string;
+          deltaCursor?: string;
+          limit?: number;
+          messagesDone?: boolean;
+          streamOrder?: number;
+          streamsDone?: boolean;
+          threadId: string;
+        },
+        { isDone: boolean }
+      >;
+      deleteAllForThreadIdSync: FunctionReference<
+        "action",
+        "internal",
+        { limit?: number; threadId: string },
+        null
+      >;
+      getThread: FunctionReference<
+        "query",
+        "internal",
+        { threadId: string },
+        {
+          _creationTime: number;
+          _id: string;
+          status: "active" | "archived";
+          summary?: string;
+          title?: string;
+          userId?: string;
+        } | null
+      >;
+      listThreadsByUserId: FunctionReference<
+        "query",
+        "internal",
+        {
+          order?: "asc" | "desc";
+          paginationOpts?: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+          userId?: string;
+        },
+        {
+          continueCursor: string;
+          isDone: boolean;
+          page: Array<{
+            _creationTime: number;
+            _id: string;
+            status: "active" | "archived";
+            summary?: string;
+            title?: string;
+            userId?: string;
+          }>;
+          pageStatus?: "SplitRecommended" | "SplitRequired" | null;
+          splitCursor?: string | null;
+        }
+      >;
+      searchThreadTitles: FunctionReference<
+        "query",
+        "internal",
+        { limit: number; query: string; userId?: string | null },
+        Array<{
+          _creationTime: number;
+          _id: string;
+          status: "active" | "archived";
+          summary?: string;
+          title?: string;
+          userId?: string;
+        }>
+      >;
+      updateThread: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          patch: {
+            status?: "active" | "archived";
+            summary?: string;
+            title?: string;
+            userId?: string;
+          };
+          threadId: string;
+        },
+        {
+          _creationTime: number;
+          _id: string;
+          status: "active" | "archived";
+          summary?: string;
+          title?: string;
+          userId?: string;
+        }
+      >;
+    };
+    users: {
+      deleteAllForUserId: FunctionReference<
+        "action",
+        "internal",
+        { userId: string },
+        null
+      >;
+      deleteAllForUserIdAsync: FunctionReference<
+        "mutation",
+        "internal",
+        { userId: string },
+        boolean
+      >;
+      listUsersWithThreads: FunctionReference<
+        "query",
+        "internal",
+        {
+          paginationOpts: {
+            cursor: string | null;
+            endCursor?: string | null;
+            id?: number;
+            maximumBytesRead?: number;
+            maximumRowsRead?: number;
+            numItems: number;
+          };
+        },
+        {
+          continueCursor: string;
+          isDone: boolean;
+          page: Array<string>;
+          pageStatus?: "SplitRecommended" | "SplitRequired" | null;
+          splitCursor?: string | null;
+        }
+      >;
+    };
+    vector: {
+      index: {
+        deleteBatch: FunctionReference<
+          "mutation",
+          "internal",
+          {
+            ids: Array<
+              | string
+              | string
+              | string
+              | string
+              | string
+              | string
+              | string
+              | string
+              | string
+              | string
+            >;
+          },
+          null
+        >;
+        deleteBatchForThread: FunctionReference<
+          "mutation",
+          "internal",
+          {
+            cursor?: string;
+            limit: number;
+            model: string;
+            threadId: string;
+            vectorDimension:
+              | 128
+              | 256
+              | 512
+              | 768
+              | 1024
+              | 1408
+              | 1536
+              | 2048
+              | 3072
+              | 4096;
+          },
+          { continueCursor: string; isDone: boolean }
+        >;
+        insertBatch: FunctionReference<
+          "mutation",
+          "internal",
+          {
+            vectorDimension:
+              | 128
+              | 256
+              | 512
+              | 768
+              | 1024
+              | 1408
+              | 1536
+              | 2048
+              | 3072
+              | 4096;
+            vectors: Array<{
+              messageId?: string;
+              model: string;
+              table: string;
+              threadId?: string;
+              userId?: string;
+              vector: Array<number>;
+            }>;
+          },
+          Array<
+            | string
+            | string
+            | string
+            | string
+            | string
+            | string
+            | string
+            | string
+            | string
+            | string
+          >
+        >;
+        paginate: FunctionReference<
+          "query",
+          "internal",
+          {
+            cursor?: string;
+            limit: number;
+            table?: string;
+            targetModel: string;
+            vectorDimension:
+              | 128
+              | 256
+              | 512
+              | 768
+              | 1024
+              | 1408
+              | 1536
+              | 2048
+              | 3072
+              | 4096;
+          },
+          {
+            continueCursor: string;
+            ids: Array<
+              | string
+              | string
+              | string
+              | string
+              | string
+              | string
+              | string
+              | string
+              | string
+              | string
+            >;
+            isDone: boolean;
+          }
+        >;
+        updateBatch: FunctionReference<
+          "mutation",
+          "internal",
+          {
+            vectors: Array<{
+              id:
+                | string
+                | string
+                | string
+                | string
+                | string
+                | string
+                | string
+                | string
+                | string
+                | string;
+              model: string;
+              vector: Array<number>;
+            }>;
+          },
+          null
+        >;
+      };
+    };
+  };
+  rateLimiter: {
+    lib: {
+      checkRateLimit: FunctionReference<
+        "query",
+        "internal",
+        {
+          config:
+            | {
+                capacity?: number;
+                kind: "token bucket";
+                maxReserved?: number;
+                period: number;
+                rate: number;
+                shards?: number;
+                start?: null;
+              }
+            | {
+                capacity?: number;
+                kind: "fixed window";
+                maxReserved?: number;
+                period: number;
+                rate: number;
+                shards?: number;
+                start?: number;
+              };
+          count?: number;
+          key?: string;
+          name: string;
+          reserve?: boolean;
+          throws?: boolean;
+        },
+        { ok: true; retryAfter?: number } | { ok: false; retryAfter: number }
+      >;
+      clearAll: FunctionReference<
+        "mutation",
+        "internal",
+        { before?: number },
+        null
+      >;
+      getServerTime: FunctionReference<"mutation", "internal", {}, number>;
+      getValue: FunctionReference<
+        "query",
+        "internal",
+        {
+          config:
+            | {
+                capacity?: number;
+                kind: "token bucket";
+                maxReserved?: number;
+                period: number;
+                rate: number;
+                shards?: number;
+                start?: null;
+              }
+            | {
+                capacity?: number;
+                kind: "fixed window";
+                maxReserved?: number;
+                period: number;
+                rate: number;
+                shards?: number;
+                start?: number;
+              };
+          key?: string;
+          name: string;
+          sampleShards?: number;
+        },
+        {
+          config:
+            | {
+                capacity?: number;
+                kind: "token bucket";
+                maxReserved?: number;
+                period: number;
+                rate: number;
+                shards?: number;
+                start?: null;
+              }
+            | {
+                capacity?: number;
+                kind: "fixed window";
+                maxReserved?: number;
+                period: number;
+                rate: number;
+                shards?: number;
+                start?: number;
+              };
+          shard: number;
+          ts: number;
+          value: number;
+        }
+      >;
+      rateLimit: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          config:
+            | {
+                capacity?: number;
+                kind: "token bucket";
+                maxReserved?: number;
+                period: number;
+                rate: number;
+                shards?: number;
+                start?: null;
+              }
+            | {
+                capacity?: number;
+                kind: "fixed window";
+                maxReserved?: number;
+                period: number;
+                rate: number;
+                shards?: number;
+                start?: number;
+              };
+          count?: number;
+          key?: string;
+          name: string;
+          reserve?: boolean;
+          throws?: boolean;
+        },
+        { ok: true; retryAfter?: number } | { ok: false; retryAfter: number }
+      >;
+      resetRateLimit: FunctionReference<
+        "mutation",
+        "internal",
+        { key?: string; name: string },
+        null
+      >;
+    };
+    time: {
+      getServerTime: FunctionReference<"mutation", "internal", {}, number>;
+    };
+  };
+  actionCache: {
+    crons: {
+      purge: FunctionReference<
+        "mutation",
+        "internal",
+        { expiresAt?: number },
+        null
+      >;
+    };
+    lib: {
+      get: FunctionReference<
+        "query",
+        "internal",
+        { args: any; name: string; ttl: number | null },
+        { kind: "hit"; value: any } | { expiredEntry?: string; kind: "miss" }
+      >;
+      put: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          args: any;
+          expiredEntry?: string;
+          name: string;
+          ttl: number | null;
+          value: any;
+        },
+        { cacheHit: boolean; deletedExpiredEntry: boolean }
+      >;
+      remove: FunctionReference<
+        "mutation",
+        "internal",
+        { args: any; name: string },
+        null
+      >;
+      removeAll: FunctionReference<
+        "mutation",
+        "internal",
+        { batchSize?: number; before?: number; name?: string },
+        null
+      >;
+    };
+  };
+  persistentTextStreaming: {
+    lib: {
+      addChunk: FunctionReference<
+        "mutation",
+        "internal",
+        { final: boolean; streamId: string; text: string },
+        any
+      >;
+      createStream: FunctionReference<"mutation", "internal", {}, any>;
+      deleteStream: FunctionReference<
+        "mutation",
+        "internal",
+        { streamId: string },
+        null
+      >;
+      getStreamStatus: FunctionReference<
+        "query",
+        "internal",
+        { streamId: string },
+        "pending" | "streaming" | "done" | "error" | "timeout"
+      >;
+      getStreamText: FunctionReference<
+        "query",
+        "internal",
+        { streamId: string },
+        {
+          status: "pending" | "streaming" | "done" | "error" | "timeout";
+          text: string;
+        }
+      >;
+      setStreamStatus: FunctionReference<
+        "mutation",
+        "internal",
+        {
+          status: "pending" | "streaming" | "done" | "error" | "timeout";
+          streamId: string;
+        },
+        any
+      >;
+    };
+  };
 };
diff --git a/services/platform/messages/de.json b/services/platform/messages/de.json
index 9036193f9d..977ef77d98 100644
--- a/services/platform/messages/de.json
+++ b/services/platform/messages/de.json
@@ -1632,8 +1632,11 @@
       "auditLogs": "Audit-Protokolle",
       "activityLogs": "Aktivitätsprotokolle",
       "errorLogs": "Fehlerprotokolle",
+      "auditDescription": "Alle Aktionen in Ihrer Organisation nachverfolgen.",
       "activityDescription": "Systemaktivität und Audit-Protokolle anzeigen.",
+      "activityComingSoon": "Aktivitätsprotokolle sind bald verfügbar.",
       "errorDescription": "Systemfehler und Warnungen anzeigen.",
+      "errorComingSoon": "Fehlerprotokolle sind bald verfügbar.",
       "audit": {
         "tableCaption": "Audit-Protokoll-Datentabelle",
         "emptyTitle": "Keine Audit-Protokolle",
@@ -3724,7 +3727,15 @@
       "systemPrompt": "System-Prompt",
       "budgets": "Budgets",
       "featureControls": "Funktionskontrolle",
-      "usage": "Nutzung"
+      "usage": "Nutzung",
+      "pii": "PII-Schutz",
+      "modelAccess": "Modellzugriff",
+      "retention": "Aufbewahrung"
+    },
+    "groups": {
+      "contentAndModels": "Inhalte & Modelle",
+      "policiesAndLimits": "Richtlinien & Limits",
+      "securityAndMonitoring": "Sicherheit & Überwachung"
     },
     "featureFlags": {
       "title": "Funktionskontrolle",
diff --git a/services/platform/messages/en.json b/services/platform/messages/en.json
index 5ebe7e5beb..0ee4c1329d 100644
--- a/services/platform/messages/en.json
+++ b/services/platform/messages/en.json
@@ -681,7 +681,8 @@
       "saveChanges": "Save changes",
       "loadingMembers": "Loading...",
       "unknownMember": "Unknown",
-      "memberChecklistHint": "A member can be part of multiple teams. If no one is selected, you will be added automatically."
+      "memberChecklistHint": "A member can be part of multiple teams. If no one is selected, you will be added automatically.",
+      "teamDetails": "Team details"
     },
     "agents": {
       "title": "Agents",
@@ -1636,8 +1637,11 @@
       "auditLogs": "Audit logs",
       "activityLogs": "Activity logs",
       "errorLogs": "Error logs",
+      "auditDescription": "Track all actions performed across your organization.",
       "activityDescription": "View system activity and audit logs.",
+      "activityComingSoon": "Activity logs are coming soon.",
       "errorDescription": "View system errors and warnings.",
+      "errorComingSoon": "Error logs are coming soon.",
       "audit": {
         "tableCaption": "Audit logs data table",
         "emptyTitle": "No audit logs",
@@ -3962,7 +3966,13 @@
       "usage": "Usage",
       "pii": "PII protection",
       "featureControls": "Feature controls",
-      "modelAccess": "Model access"
+      "modelAccess": "Model access",
+      "retention": "Retention"
+    },
+    "groups": {
+      "contentAndModels": "Content & Models",
+      "policiesAndLimits": "Policies & Limits",
+      "securityAndMonitoring": "Security & Monitoring"
     },
     "modelAccess": {
       "title": "Model access",

From 62053de7eac2e46e257f96916500c4a2f6418b3f Mon Sep 17 00:00:00 2001
From: israel <israeliyanda5@gmail.com>
Date: Mon, 13 Apr 2026 01:04:45 +0100
Subject: [PATCH 2/4] style(platform): fix class ordering in
 select-trigger-button and mcp-server-card

---
 .../settings/governance/components/select-trigger-button.tsx    | 2 +-
 .../settings/mcp-servers/components/mcp-server-card.tsx         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/services/platform/app/features/settings/governance/components/select-trigger-button.tsx b/services/platform/app/features/settings/governance/components/select-trigger-button.tsx
index bfa9a7a1e2..a1f411d517 100644
--- a/services/platform/app/features/settings/governance/components/select-trigger-button.tsx
+++ b/services/platform/app/features/settings/governance/components/select-trigger-button.tsx
@@ -13,7 +13,7 @@ export const SelectTriggerButton = forwardRef<
       ref={ref}
       type="button"
       {...props}
-      className="ring-1 ring-border bg-input flex h-8 w-full items-center justify-between rounded-md px-3 text-sm disabled:cursor-not-allowed disabled:opacity-50"
+      className="ring-border bg-input flex h-8 w-full items-center justify-between rounded-md px-3 text-sm ring-1 disabled:cursor-not-allowed disabled:opacity-50"
     >
       <span className={hasValue ? '' : 'text-muted-foreground'}>
         {children}
diff --git a/services/platform/app/features/settings/mcp-servers/components/mcp-server-card.tsx b/services/platform/app/features/settings/mcp-servers/components/mcp-server-card.tsx
index 3c92d98292..805e742acd 100644
--- a/services/platform/app/features/settings/mcp-servers/components/mcp-server-card.tsx
+++ b/services/platform/app/features/settings/mcp-servers/components/mcp-server-card.tsx
@@ -84,7 +84,7 @@ export function McpServerCard({
       contentClassName="p-0"
     >
       <div className="relative">
-        <div className="absolute bottom-5 right-5 z-10">
+        <div className="absolute right-5 bottom-5 z-10">
           <DropdownMenu
             trigger={
               <IconButton

From c1c5b1a640834442a61f13cd90baaf1ec824ec41 Mon Sep 17 00:00:00 2001
From: israel <israeliyanda5@gmail.com>
Date: Mon, 13 Apr 2026 01:18:01 +0100
Subject: [PATCH 3/4] fix(platform): fix mcp-server-card test selector and
 pii-config infinite update loop

---
 .../settings/governance/components/pii-config.tsx         | 8 +++++---
 .../components/__tests__/mcp-server-card.test.tsx         | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/services/platform/app/features/settings/governance/components/pii-config.tsx b/services/platform/app/features/settings/governance/components/pii-config.tsx
index ce42bb4d4b..8a42c485f4 100644
--- a/services/platform/app/features/settings/governance/components/pii-config.tsx
+++ b/services/platform/app/features/settings/governance/components/pii-config.tsx
@@ -1,7 +1,7 @@
 'use client';
 
 import { ShieldCheck } from 'lucide-react';
-import { useCallback, useEffect, useState } from 'react';
+import { useCallback, useEffect, useRef, useState } from 'react';
 
 import { Alert } from '@/app/components/ui/feedback/alert';
 import { Badge } from '@/app/components/ui/feedback/badge';
@@ -60,10 +60,12 @@ export function PiiConfig({ organizationId }: PiiConfigProps) {
   > | null>(null);
 
   const cannotManage = ability.cannot('write', 'orgSettings');
+  const initialized = useRef(false);
 
-  // Sync from server data
+  // Sync from server data once loaded
   useEffect(() => {
-    if (policy) {
+    if (policy && !initialized.current) {
+      initialized.current = true;
       setEnabled(policy.enabled ?? false);
       setMode(policy.config?.mode ?? 'mask');
       setEnabledPatterns(
diff --git a/services/platform/app/features/settings/mcp-servers/components/__tests__/mcp-server-card.test.tsx b/services/platform/app/features/settings/mcp-servers/components/__tests__/mcp-server-card.test.tsx
index 856c8cef14..c45737ece8 100644
--- a/services/platform/app/features/settings/mcp-servers/components/__tests__/mcp-server-card.test.tsx
+++ b/services/platform/app/features/settings/mcp-servers/components/__tests__/mcp-server-card.test.tsx
@@ -89,7 +89,7 @@ describe('McpServerCard', () => {
         onDelete={vi.fn()}
       />,
     );
-    await user.click(screen.getByRole('button'));
+    await user.click(screen.getByText('Test Server'));
     expect(onClick).toHaveBeenCalledTimes(1);
   });
 

From 6eba4ab917aa54d67d0e6d34d3e1898d767275fb Mon Sep 17 00:00:00 2001
From: israel <israeliyanda5@gmail.com>
Date: Mon, 13 Apr 2026 01:39:47 +0100
Subject: [PATCH 4/4] docs: add governance settings section and update
 provider/audit log docs

---
 docs/providers.md |  2 +-
 docs/settings.md  | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/docs/providers.md b/docs/providers.md
index 002eb91110..43155d4135 100644
--- a/docs/providers.md
+++ b/docs/providers.md
@@ -12,7 +12,7 @@ Tale connects to AI models through **providers** — OpenAI-compatible API endpo
 Providers are managed in **Settings > Providers** in the management UI. Admins can:
 
 - **Add a provider** with a name, display name, base URL, API key, and one or more models
-- **Edit a provider** to update its configuration or add/remove models
+- **Edit a provider** to update its display name, description, base URL, and default models. The description is shown in the provider list to help users understand what the provider is for. Default models let you pre-select which model is used for chat, vision, and embedding when users pick this provider.
 - **Delete a provider** to remove it entirely
 
 Each model definition includes an ID (must match the model name expected by the API), a display name, and one or more tags (`chat`, `vision`, `embedding`) that control where the model appears in the platform.
diff --git a/docs/settings.md b/docs/settings.md
index b41403859d..a1fd0f54d4 100644
--- a/docs/settings.md
+++ b/docs/settings.md
@@ -66,6 +66,30 @@ Customize the look of the platform for your organization. Admin only. Available
 
 Available to all users. Change your password here. If you signed up via SSO, you can also set a regular password from this page to enable direct login.
 
+## Governance
+
+Admin only. Configure organization-wide AI policies and controls. The governance page is organized into three groups accessible from a left-hand navigation:
+
+### Content & Models
+
+- **System Prompt**: set a global system prompt prepended to every AI conversation in the organization.
+- **Default Models**: choose the default chat, vision, and embedding models used when users don't pick one explicitly.
+- **Model Access**: control which models are available to specific teams or users.
+
+### Policies & Limits
+
+- **Budgets**: set spending limits per user, team, or the entire organization with configurable periods and thresholds.
+- **Upload Policy**: restrict file uploads by type, size, or count.
+- **Retention**: configure how long conversations and files are kept before automatic deletion.
+- **Feature Controls**: toggle platform features (e.g., file uploads, web search, image generation) on or off organization-wide.
+
+### Security & Monitoring
+
+- **PII Detection**: enable automatic detection and masking (or blocking) of personally identifiable information in messages. Supports built-in patterns and custom regex rules.
+- **Usage Dashboard**: view token consumption, cost breakdowns, and usage trends across the organization.
+
 ## Audit logs
 
 Admin only. A time-ordered record of significant actions taken in the organization. Categories include authentication events, member changes, data operations, integration updates, workflow publications, security events, and admin actions. Useful for compliance and troubleshooting.
+
+Admins can export audit logs as **CSV** or **JSON** using the export buttons above the log table. Exports respect the currently active category filter.
