@tangle-network/agent-app 0.63.75 → 0.63.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/{DesignCanvas-566V5KVC.js → DesignCanvas-DRVL3MWL.js} +3 -3
  2. package/dist/{DesignCanvasEditor-PUO5Y6FB.js → DesignCanvasEditor-5T3MHHFH.js} +4 -4
  3. package/dist/agent-profiles/d1.js +3 -3
  4. package/dist/agent-profiles/index.js +3 -3
  5. package/dist/assistant/index.js +3 -3
  6. package/dist/assistant/index.js.map +1 -1
  7. package/dist/chat-routes/index.js +4 -4
  8. package/dist/{chunk-WYQTPFPI.js → chunk-3ELC7F62.js} +2 -2
  9. package/dist/{chunk-2ACI3WYT.js → chunk-5DXOFO4V.js} +2 -2
  10. package/dist/{chunk-E2JMXA2V.js → chunk-CGBB2AUP.js} +5 -5
  11. package/dist/{chunk-E2JMXA2V.js.map → chunk-CGBB2AUP.js.map} +1 -1
  12. package/dist/{chunk-VKJEH6DG.js → chunk-CI6Z2C4L.js} +2 -2
  13. package/dist/{chunk-6IMNAZR7.js → chunk-DS3FDGVJ.js} +2 -2
  14. package/dist/{chunk-XJ7DC2DI.js → chunk-SK6WU2TI.js} +3 -3
  15. package/dist/{chunk-62BPUU3A.js → chunk-V2BC73KQ.js} +5 -5
  16. package/dist/{chunk-I4CFBLSJ.js → chunk-Y3HRQVAO.js} +10 -10
  17. package/dist/{chunk-KBJZMR4E.js → chunk-Y5WTAHWY.js} +1 -1
  18. package/dist/chunk-Y5WTAHWY.js.map +1 -0
  19. package/dist/{chunk-YQD2RISF.js → chunk-YGMJ6NDY.js} +3 -3
  20. package/dist/{chunk-OBKVNZPH.js → chunk-YL5JDX7K.js} +4 -4
  21. package/dist/{chunk-OBKVNZPH.js.map → chunk-YL5JDX7K.js.map} +1 -1
  22. package/dist/design-canvas-react/index.js +9 -9
  23. package/dist/design-canvas-react/lazy.js +1 -1
  24. package/dist/platform/index.js +8 -8
  25. package/dist/preset-cloudflare/index.js +5 -5
  26. package/dist/public-consultation/index.js +4 -4
  27. package/dist/sandbox/index.js +4 -4
  28. package/dist/settings-react/index.js +64 -31
  29. package/dist/settings-react/index.js.map +1 -1
  30. package/dist/settings-react/members-section.d.ts +15 -5
  31. package/dist/stories/settings/settings-demo.d.ts +4 -1
  32. package/dist/teams/index.js +1 -1
  33. package/dist/teams/invitations-api.d.ts +6 -4
  34. package/dist/teams/invitations-api.js +4 -2
  35. package/dist/teams/invitations-api.js.map +1 -1
  36. package/dist/teams/invitations.d.ts +2 -0
  37. package/dist/teams/members-api.js +2 -2
  38. package/dist/teams-react/components/invitation-detail.d.ts +4 -2
  39. package/dist/teams-react/index.js +2 -2
  40. package/dist/theme/tokens.css +19 -19
  41. package/dist/tools/index.js +4 -4
  42. package/dist/web-react/index.js +7 -7
  43. package/dist/work-product/index.js +2 -2
  44. package/dist/worker-build/index.d.ts +26 -0
  45. package/dist/worker-build/index.js +73 -0
  46. package/dist/worker-build/index.js.map +1 -0
  47. package/package.json +12 -7
  48. package/dist/chunk-KBJZMR4E.js.map +0 -1
  49. /package/dist/{DesignCanvas-566V5KVC.js.map → DesignCanvas-DRVL3MWL.js.map} +0 -0
  50. /package/dist/{DesignCanvasEditor-PUO5Y6FB.js.map → DesignCanvasEditor-5T3MHHFH.js.map} +0 -0
  51. /package/dist/{chunk-WYQTPFPI.js.map → chunk-3ELC7F62.js.map} +0 -0
  52. /package/dist/{chunk-2ACI3WYT.js.map → chunk-5DXOFO4V.js.map} +0 -0
  53. /package/dist/{chunk-VKJEH6DG.js.map → chunk-CI6Z2C4L.js.map} +0 -0
  54. /package/dist/{chunk-6IMNAZR7.js.map → chunk-DS3FDGVJ.js.map} +0 -0
  55. /package/dist/{chunk-XJ7DC2DI.js.map → chunk-SK6WU2TI.js.map} +0 -0
  56. /package/dist/{chunk-62BPUU3A.js.map → chunk-V2BC73KQ.js.map} +0 -0
  57. /package/dist/{chunk-I4CFBLSJ.js.map → chunk-Y3HRQVAO.js.map} +0 -0
  58. /package/dist/{chunk-YQD2RISF.js.map → chunk-YGMJ6NDY.js.map} +0 -0
@@ -5,10 +5,12 @@
5
5
  * named by capability. A role change saves at once and says so in its row;
6
6
  * removing a person or revoking an invitation asks first and stays open on a
7
7
  * refusal. On a narrow card the role picker takes its own full-width line
8
- * under the name.
8
+ * under the name. With `delivery="link"` nothing promises an email: Invite
9
+ * creates a link the server mints and shows it with Copy link.
9
10
  */
10
11
  import { type SettingsListMenuItem } from '@tangle-network/ui/primitives';
11
12
  import { type ReactNode } from 'react';
13
+ import { type InvitationDelivery } from '../teams/invitations.js';
12
14
  import { type WorkspaceRole } from '../teams/roles.js';
13
15
  import type { InvitationView, MemberView } from '../teams-react/contracts.js';
14
16
  import { type MutationOutcome } from '../web-react/async/index.js';
@@ -33,11 +35,16 @@ export interface MembersSectionProps {
33
35
  onRemove(input: {
34
36
  memberId: string;
35
37
  }): Promise<MutationOutcome<unknown>>;
36
- /** Adds the Invite action. A refusal (a seat limit, a failed email) stays in the dialog with its sentence. */
38
+ /**
39
+ * Adds the Invite action. A refusal (a seat limit, a failed email) stays in the dialog with its sentence.
40
+ * With `delivery="link"` it resolves with the server's `{ inviteUrl }`, which the card then shows.
41
+ */
37
42
  onInvite?(input: {
38
43
  email: string;
39
44
  role: WorkspaceRole;
40
45
  }): Promise<MutationOutcome<unknown>>;
46
+ /** `link` when the product sends no invitation email and the inviter shares the link. Defaults to `email`. */
47
+ delivery?: InvitationDelivery;
41
48
  /** The plans page. A `plan_limit` refusal on Invite links to it as View plans. */
42
49
  plansHref?: string;
43
50
  /** Renders View plans: pass the router's link, as to `SettingsLayout`. Defaults to a plain anchor. */
@@ -45,14 +52,15 @@ export interface MembersSectionProps {
45
52
  /** More ⋯ items for a member the viewer can manage, such as "Make team owner…". */
46
53
  menuItems?(member: MemberView): SettingsListMenuItem[];
47
54
  }
48
- export declare function MembersSection({ id, title, description, members, currentRole, currentUserId, noun, onChangeRole, onRemove, onInvite, plansHref, LinkComponent, menuItems, }: MembersSectionProps): import("react").JSX.Element;
55
+ export declare function MembersSection({ id, title, description, members, currentRole, currentUserId, noun, onChangeRole, onRemove, onInvite, delivery, plansHref, LinkComponent, menuItems, }: MembersSectionProps): import("react").JSX.Element;
49
56
  export interface InvitationsSectionProps {
50
57
  id?: string;
51
58
  title?: string;
52
59
  invitations: InvitationView[];
53
60
  /** The viewer's effective role: admins copy, resend and revoke. */
54
61
  currentRole: WorkspaceRole;
55
- onResend(input: {
62
+ /** Adds Resend email. A `link` delivery offers none. */
63
+ onResend?(input: {
56
64
  invitationId: string;
57
65
  }): Promise<MutationOutcome<unknown>>;
58
66
  onRevoke(input: {
@@ -62,5 +70,7 @@ export interface InvitationsSectionProps {
62
70
  onCopy?(input: {
63
71
  inviteUrl: string;
64
72
  }): void | Promise<void>;
73
+ /** `link` when the product sends no invitation email: rows never mention email. Defaults to `email`. */
74
+ delivery?: InvitationDelivery;
65
75
  }
66
- export declare function InvitationsSection({ id, title, invitations, currentRole, onResend, onRevoke, onCopy, }: InvitationsSectionProps): import("react").JSX.Element;
76
+ export declare function InvitationsSection({ id, title, invitations, currentRole, onResend, onRevoke, onCopy, delivery, }: InvitationsSectionProps): import("react").JSX.Element;
@@ -4,13 +4,16 @@
4
4
  * or groups its save the way the settings contract says. The story renders it
5
5
  * and `scripts/prove-settings-pages.mjs` drives it in a real browser.
6
6
  */
7
+ import type { InvitationDelivery } from '../../teams/invitations.js';
7
8
  import type { DemoBackend, ViewerRole } from './settings-backend.js';
8
9
  export type DemoSectionId = 'general' | 'agent' | 'notifications' | 'limits' | 'team';
9
10
  export interface SettingsDemoProps {
10
11
  backend: DemoBackend;
11
12
  viewer?: ViewerRole;
12
13
  initialSection?: DemoSectionId;
14
+ /** `link` shows the team cards of a product that emails no invitations. */
15
+ delivery?: InvitationDelivery;
13
16
  /** How long a section's "loader" takes, so the optimistic nav and progress line show. */
14
17
  routeDelayMs?: number;
15
18
  }
16
- export declare function SettingsDemo({ backend: api, viewer, initialSection, routeDelayMs }: SettingsDemoProps): import("react").JSX.Element;
19
+ export declare function SettingsDemo({ backend: api, viewer, initialSection, delivery, routeDelayMs }: SettingsDemoProps): import("react").JSX.Element;
@@ -12,7 +12,7 @@ import {
12
12
  isInvitationEmail,
13
13
  normalizeInvitationEmail,
14
14
  parseInvitationPermission
15
- } from "../chunk-KBJZMR4E.js";
15
+ } from "../chunk-Y5WTAHWY.js";
16
16
  import {
17
17
  ASSIGNABLE_WORKSPACE_ROLES,
18
18
  ORGANIZATION_ROLES,
@@ -13,9 +13,11 @@
13
13
  *
14
14
  * Handlers return a discriminated `InvitationOutcome` (not a `Response`) so the
15
15
  * route adapter maps `{ status }` to its own framework's response. Three seams:
16
- * - `sendInvitationEmail` (REQUIRED) — the app's mail transport. Returns a
16
+ * - `sendInvitationEmail` (OPTIONAL) — the app's mail transport. Returns a
17
17
  * typed outcome; a failed send never blocks invitation creation (emailStatus
18
- * is recorded as 'failed' and the invite link is still returned).
18
+ * is recorded as 'failed' and the invite link is still returned). Without
19
+ * it the product is link-only: nothing is sent, the row stays `not_sent`,
20
+ * and resend is refused.
19
21
  * - `enforceSeat` (OPTIONAL) — billing/seat-limit gate, called at create time
20
22
  * only when the invite would consume a NEW seat. Reused from members-api.
21
23
  * - `memberSyncSeam.add` (OPTIONAL) — fire-and-forget propagation of the new
@@ -73,8 +75,8 @@ export interface InvitationsApiOptions {
73
75
  userTable: TeamParentTable & InvitationUserTable;
74
76
  workspaceTable: TeamParentTable & InvitationWorkspaceTable;
75
77
  access: WorkspaceAccessReader;
76
- /** REQUIRED — the app's mail transport (e.g. Resend + `inviteEmail` from `./email`). */
77
- sendInvitationEmail: SendInvitationEmailSeam;
78
+ /** The app's mail transport (e.g. Resend + `inviteEmail` from `./email`). Leave it out for link-only invitations. */
79
+ sendInvitationEmail?: SendInvitationEmailSeam;
78
80
  /** OPTIONAL — seat-limit gate at create time; mirrors members-api. */
79
81
  enforceSeat?: EnforceSeatSeam;
80
82
  /** OPTIONAL — fire-and-forget member propagation on accept. */
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SeatLimitError,
3
3
  fireMemberSync
4
- } from "../chunk-WYQTPFPI.js";
4
+ } from "../chunk-3ELC7F62.js";
5
5
  import "../chunk-DJ4VJIH5.js";
6
6
  import {
7
7
  INVITATION_EMAIL_HINT,
@@ -11,7 +11,7 @@ import {
11
11
  isInvitationEmail,
12
12
  normalizeInvitationEmail,
13
13
  parseInvitationPermission
14
- } from "../chunk-KBJZMR4E.js";
14
+ } from "../chunk-Y5WTAHWY.js";
15
15
  import {
16
16
  hasWorkspaceRole
17
17
  } from "../chunk-6XIAPIW6.js";
@@ -84,6 +84,7 @@ function createInvitationsApi(opts) {
84
84
  if (!row) return { succeeded: false, status: 404, error: "Invitation not found" };
85
85
  const accessRow = await access.getWorkspaceAccess(row.invitation.workspaceId, input.userId, "admin");
86
86
  if (!accessRow) return { succeeded: false, status: 404, error: "Workspace not found" };
87
+ if (!sendInvitationEmail) return { succeeded: false, status: 409, error: "Invitations here are links. Copy the link and share it instead." };
87
88
  const now = input.now ?? /* @__PURE__ */ new Date();
88
89
  if (row.invitation.status !== "pending") {
89
90
  return { succeeded: false, status: 409, error: "Only pending invitations can be resent" };
@@ -362,6 +363,7 @@ function createInvitationIssuer(access, expirePendingInvitations, getPendingInvi
362
363
  createdAt: now
363
364
  }).returning();
364
365
  const inviteUrl = inviteUrlForToken(input.origin, token);
366
+ if (!sendInvitationEmail) return { succeeded: true, value: { invitation: toInvitationView(created, accountCheck.inviterEmail), inviteUrl } };
365
367
  const emailResult = await sendInvitationEmail({
366
368
  to: email,
367
369
  workspaceName,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/teams/invitations-api.ts"],"sourcesContent":["/**\n * Framework-neutral email-invitation lifecycle for the teams module: create /\n * list / resend / revoke / preview / accept over the dedicated\n * `workspace_invitation` table (from `createWorkspaceInvitationTable`). Lifted out\n * of any one app's route file — each app binds this once to its own db/tables/\n * access and mounts the handlers in its own routes with its own auth.\n *\n * Unlike `members-api` (whose \"invite\" is a pending workspaceMember row, no\n * email), this models the rich lifecycle: a dedicated invitation row with status,\n * 7-day expiry, emailStatus, resend, and revoke. On accept it materializes the\n * `organizationMembers` + `workspaceMembers` rows, so `members-api.listMembers`\n * still surfaces accepted members; pending invites live only here.\n *\n * Handlers return a discriminated `InvitationOutcome` (not a `Response`) so the\n * route adapter maps `{ status }` to its own framework's response. Three seams:\n * - `sendInvitationEmail` (REQUIRED) — the app's mail transport. Returns a\n * typed outcome; a failed send never blocks invitation creation (emailStatus\n * is recorded as 'failed' and the invite link is still returned).\n * - `enforceSeat` (OPTIONAL) — billing/seat-limit gate, called at create time\n * only when the invite would consume a NEW seat. Reused from members-api.\n * - `memberSyncSeam.add` (OPTIONAL) — fire-and-forget propagation of the new\n * member to a sandbox/external system on accept. Fail-soft by contract.\n *\n * Imports `drizzle-orm`, so this is a subpath, never re-exported from root.\n */\n\nimport { fireMemberSync } from './member-sync'\nimport { and, eq, lte, sql } from 'drizzle-orm'\nimport {\n type InvitationEmailStatus,\n type InvitationPermission,\n type InvitationStatus,\n generateInvitationToken,\n getInvitationExpiresAt,\n inviteUrlForToken,\n INVITATION_EMAIL_HINT,\n isInvitationEmail,\n normalizeInvitationEmail,\n parseInvitationPermission,\n} from './invitations'\nimport { type WorkspaceRole, hasWorkspaceRole } from './roles'\nimport { type EnforceSeatSeam, type MemberSyncCallbacks, SeatLimitError } from './members-api'\nimport type { TeamDatabase, WorkspaceAccessReader } from './drizzle/access'\nimport type { TeamParentTable, TeamTables } from './drizzle/schema'\nimport type { WorkspaceInvitationRow, WorkspaceInvitationTables } from './drizzle/invitations-schema'\n\n// Re-export the seams an adopter wires, so a consumer can import everything the\n// invitations API needs from this one subpath.\nexport { SeatLimitError } from './members-api'\nexport type { EnforceSeatSeam, MemberSyncCallbacks } from './members-api'\n\n/** The app's mail transport. Returns a typed outcome; never throws to the API. */\nexport interface SendInvitationEmailInput {\n to: string\n workspaceName: string\n inviterEmail: string\n permission: InvitationPermission\n inviteUrl: string\n expiresAt: Date\n}\n/** Represent the outcome of sending an invitation email with success status and optional error message */\nexport type SendInvitationEmailResult = { succeeded: true } | { succeeded: false; error: string }\n/** Resolve sending an invitation email and return the result asynchronously */\nexport interface SendInvitationEmailSeam {\n (input: SendInvitationEmailInput): Promise<SendInvitationEmailResult>\n}\n\n/** The product's user table, narrowed to the columns the queries read. */\nexport interface InvitationUserTable {\n id: any\n email: any\n emailVerified: any\n}\n\n/** The product's workspace table, narrowed to the columns the queries read. */\nexport interface InvitationWorkspaceTable {\n id: any\n name: any\n organizationId: any\n}\n\n/** Define configuration options required to manage workspace invitations and related data sources */\nexport interface InvitationsApiOptions {\n db: TeamDatabase & { batch?: (statements: [any, ...any[]]) => Promise<any[]> }\n tables: TeamTables\n /** The invitation table from `createWorkspaceInvitationTable`. */\n invitationsTable: WorkspaceInvitationTables\n userTable: TeamParentTable & InvitationUserTable\n workspaceTable: TeamParentTable & InvitationWorkspaceTable\n access: WorkspaceAccessReader\n /** REQUIRED — the app's mail transport (e.g. Resend + `inviteEmail` from `./email`). */\n sendInvitationEmail: SendInvitationEmailSeam\n /** OPTIONAL — seat-limit gate at create time; mirrors members-api. */\n enforceSeat?: EnforceSeatSeam\n /** OPTIONAL — fire-and-forget member propagation on accept. */\n memberSyncSeam?: Pick<MemberSyncCallbacks, 'add'>\n /** Inviter display fallback when the inviter's email is unknown. */\n productDisplayName?: string\n /** Refuse acceptance until the signed-in account's email is verified. Off by\n * default: a valid token for the matching address already proves inbox access\n * (#146). A product that wants verification first turns it on. */\n requireVerifiedEmail?: boolean\n}\n\n/** Represent a workspace invitation with details about inviter, permissions, status, and timestamps */\nexport interface WorkspaceInvitationView {\n id: string\n workspaceId: string\n organizationId: string\n email: string\n invitedByUserId: string\n inviterEmail: string | null\n permissions: InvitationPermission\n token: string\n status: InvitationStatus\n emailStatus: InvitationEmailStatus\n expiresAt: Date\n createdAt: Date\n acceptedAt: Date | null\n revokedAt: Date | null\n lastSentAt: Date | null\n}\n\n/** Describe the structure of an invitation preview with workspace, email, permissions, status, and expiration details */\nexport interface InvitationPreview {\n workspaceId: string\n workspaceName: string\n email: string\n inviterEmail: string | null\n permissions: InvitationPermission\n status: InvitationStatus\n expiresAt: Date\n}\n\n/** Resolve the result of an invitation as success with a value or failure with status and error details */\nexport type InvitationOutcome<T> =\n | { succeeded: true; value: T }\n | { succeeded: false; status: number; error: string }\n\n/**\n * The live fence all three acceptance writes share, evaluated inside one\n * atomic D1 batch. A workspace transfer or revoke between the reads and the\n * batch wins cleanly: there is no membership to repair or runtime access to\n * retract.\n */\nfunction invitationAcceptFence(\n tables: {\n workspaceInvitations: WorkspaceInvitationTables['workspaceInvitations']\n workspaces: InvitationWorkspaceTable\n users: InvitationUserTable\n organizationMembers: TeamTables['organizationMembers']\n workspaceMembers: TeamTables['workspaceMembers']\n },\n fence: {\n token: string\n invitation: WorkspaceInvitationRow\n currentUser: { id: string; emailVerified: boolean | null }\n now: Date\n },\n) {\n const { workspaceInvitations, workspaces, users, organizationMembers, workspaceMembers } = tables\n const { invitation, currentUser, now } = fence\n const input = { token: fence.token }\n return and(\n eq(workspaceInvitations.id, invitation.id),\n eq(workspaceInvitations.token, input.token),\n eq(workspaceInvitations.status, 'pending'),\n eq(workspaceInvitations.organizationId, invitation.organizationId),\n eq(workspaceInvitations.workspaceId, invitation.workspaceId),\n eq(workspaceInvitations.email, invitation.email),\n eq(workspaceInvitations.permissions, invitation.permissions),\n sql`${workspaceInvitations.expiresAt} > ${Math.floor(now.getTime() / 1000)}`,\n sql`exists (select 1 from ${workspaces} where ${workspaces.id} = ${workspaceInvitations.workspaceId}\n and ${workspaces.organizationId} = ${invitation.organizationId})`,\n sql`exists (select 1 from ${users} where ${users.id} = ${currentUser.id}\n and lower(trim(${users.email})) = ${invitation.email}\n and ${users.emailVerified} = ${currentUser.emailVerified ? 1 : 0})`,\n sql`(select count(*) from ${users} where lower(trim(${users.email})) = ${invitation.email}) = 1`,\n sql`not exists (select 1 from ${workspaceMembers} inner join ${organizationMembers}\n on ${organizationMembers.id} = ${workspaceMembers.organizationMemberId}\n where ${workspaceMembers.workspaceId} = ${invitation.workspaceId}\n and ${organizationMembers.organizationId} = ${invitation.organizationId}\n and ${organizationMembers.userId} = ${currentUser.id}\n and ${workspaceMembers.acceptedAt} is null)`,\n sql`not exists (select 1 from ${workspaceMembers} where ${workspaceMembers.inviteToken} = ${invitation.token}\n and (${workspaceMembers.workspaceId} != ${invitation.workspaceId}\n or ${workspaceMembers.organizationMemberId} is null\n or ${workspaceMembers.organizationMemberId} not in (select ${organizationMembers.id} from ${organizationMembers}\n where ${organizationMembers.organizationId} = ${invitation.organizationId}\n and ${organizationMembers.userId} = ${currentUser.id})))`,\n sql`not exists (select 1 from ${organizationMembers}\n where ${organizationMembers.organizationId} = ${invitation.organizationId}\n and ${organizationMembers.userId} = ${currentUser.id}\n and ${organizationMembers.role} in ('owner', 'admin'))`,\n )\n}\n\n/**\n * Build the invitations API bound to one product's db/tables/access/seams.\n * Returns the six lifecycle handlers an app mounts in its routes.\n */\nexport function createInvitationsApi(opts: InvitationsApiOptions) {\n const { db, tables, access, sendInvitationEmail, enforceSeat, memberSyncSeam, requireVerifiedEmail = false } = opts\n const { organizationMembers, workspaceMembers } = tables\n const { workspaceInvitations } = opts.invitationsTable\n const users = opts.userTable\n const workspaces = opts.workspaceTable\n const productDisplayName = opts.productDisplayName ?? 'A workspace admin'\n\n\n\n const { expirePendingInvitations, getPendingInvitation, checkExistingAccountAccess, toInvitationView, getInvitationById, markInvitationExpired, getInvitationByToken, findUsersByNormalizedEmail, getOrganizationMember, getWorkspaceMemberByOrganizationMember } = createInvitationQueries(workspaceInvitations, db, users, organizationMembers, workspaceMembers, workspaces)\n\n const { createInvitation } = createInvitationIssuer(access, expirePendingInvitations, getPendingInvitation, checkExistingAccountAccess, enforceSeat, db, workspaceInvitations, sendInvitationEmail, productDisplayName, toInvitationView)\n\n async function listInvitations(input: {\n workspaceId: string\n userId: string\n origin: string\n now?: Date\n }): Promise<InvitationOutcome<{ invitations: Array<WorkspaceInvitationView & { inviteUrl: string }> }>> {\n const accessRow = await access.getWorkspaceAccess(input.workspaceId, input.userId, 'admin')\n if (!accessRow) return { succeeded: false, status: 404, error: 'Workspace not found' }\n\n await expirePendingInvitations(input.workspaceId, undefined, input.now ?? new Date())\n\n const rows = await db\n .select({ invitation: workspaceInvitations, inviterEmail: users.email })\n .from(workspaceInvitations)\n .leftJoin(users, eq(users.id, workspaceInvitations.invitedByUserId))\n .where(eq(workspaceInvitations.workspaceId, input.workspaceId))\n .orderBy(sql`${workspaceInvitations.createdAt} desc`)\n\n return {\n succeeded: true,\n value: {\n invitations: rows.map((row: { invitation: WorkspaceInvitationRow; inviterEmail: string | null }) => ({\n ...toInvitationView(row.invitation, row.inviterEmail),\n inviteUrl: inviteUrlForToken(input.origin, row.invitation.token),\n })),\n },\n }\n }\n\n async function resendInvitation(input: {\n invitationId: string\n userId: string\n origin: string\n now?: Date\n }): Promise<InvitationOutcome<{ invitation: WorkspaceInvitationView; inviteUrl: string; emailError?: string }>> {\n const row = await getInvitationById(input.invitationId)\n if (!row) return { succeeded: false, status: 404, error: 'Invitation not found' }\n\n const accessRow = await access.getWorkspaceAccess(row.invitation.workspaceId, input.userId, 'admin')\n if (!accessRow) return { succeeded: false, status: 404, error: 'Workspace not found' }\n\n const now = input.now ?? new Date()\n if (row.invitation.status !== 'pending') {\n return { succeeded: false, status: 409, error: 'Only pending invitations can be resent' }\n }\n if (row.invitation.expiresAt <= now) {\n await markInvitationExpired(row.invitation.id)\n return { succeeded: false, status: 409, error: 'Invitation has expired' }\n }\n\n const workspaceName = (accessRow.workspace as { name: string }).name\n const inviteUrl = inviteUrlForToken(input.origin, row.invitation.token)\n const emailResult = await sendInvitationEmail({\n to: row.invitation.email,\n workspaceName,\n inviterEmail: row.inviterEmail ?? productDisplayName,\n permission: row.invitation.permissions,\n inviteUrl,\n expiresAt: row.invitation.expiresAt,\n })\n\n const [updated] = await db.update(workspaceInvitations)\n .set({\n emailStatus: emailResult.succeeded ? 'sent' : 'failed',\n lastSentAt: emailResult.succeeded ? now : row.invitation.lastSentAt,\n })\n .where(eq(workspaceInvitations.id, row.invitation.id))\n .returning()\n\n return {\n succeeded: true,\n value: {\n invitation: toInvitationView(updated!, row.inviterEmail),\n inviteUrl,\n emailError: emailResult.succeeded ? undefined : emailResult.error,\n },\n }\n }\n\n async function revokeInvitation(input: {\n invitationId: string\n userId: string\n now?: Date\n }): Promise<InvitationOutcome<{ invitation: WorkspaceInvitationView }>> {\n const row = await getInvitationById(input.invitationId)\n if (!row) return { succeeded: false, status: 404, error: 'Invitation not found' }\n\n const accessRow = await access.getWorkspaceAccess(row.invitation.workspaceId, input.userId, 'admin')\n if (!accessRow) return { succeeded: false, status: 404, error: 'Workspace not found' }\n if (row.invitation.status !== 'pending') {\n return { succeeded: false, status: 409, error: 'Only pending invitations can be revoked' }\n }\n\n const [updated] = await db.update(workspaceInvitations)\n .set({ status: 'revoked', revokedAt: input.now ?? new Date() })\n .where(and(eq(workspaceInvitations.id, row.invitation.id), eq(workspaceInvitations.status, 'pending')))\n .returning()\n\n // The status read above is advisory. A concurrent accept may win between\n // that read and this update, so the write must be compare-and-set.\n if (!updated) return { succeeded: false, status: 409, error: 'The invitation changed. Reload it before continuing.' }\n\n return { succeeded: true, value: { invitation: toInvitationView(updated!, row.inviterEmail) } }\n }\n\n async function getPreview(token: string, now: Date = new Date()): Promise<InvitationOutcome<InvitationPreview>> {\n const row = await getInvitationByToken(token)\n if (!row) return { succeeded: false, status: 404, error: 'Invitation not found' }\n\n let invitation = row.invitation\n if (invitation.status === 'pending' && invitation.expiresAt <= now) {\n invitation = await markInvitationExpired(invitation.id)\n }\n\n return {\n succeeded: true,\n value: {\n workspaceId: invitation.workspaceId,\n workspaceName: row.workspaceName,\n email: invitation.email,\n inviterEmail: row.inviterEmail,\n permissions: invitation.permissions,\n status: invitation.status,\n expiresAt: invitation.expiresAt,\n },\n }\n }\n\n async function acceptInvitation(input: {\n token: string\n userId: string\n now?: Date\n }): Promise<InvitationOutcome<{ workspaceId: string }>> {\n const now = input.now ?? new Date()\n const row = await getInvitationByToken(input.token)\n if (!row) return { succeeded: false, status: 404, error: 'Invitation not found' }\n\n const invitation = row.invitation\n\n const [currentUser] = await db\n .select({ id: users.id, email: users.email, emailVerified: users.emailVerified })\n .from(users)\n .where(eq(users.id, input.userId))\n .limit(1)\n if (!currentUser) return { succeeded: false, status: 401, error: 'Authentication required' }\n\n if (normalizeInvitationEmail(currentUser.email) !== invitation.email) {\n return { succeeded: false, status: 403, error: 'Sign in with the invited email address to accept this invitation' }\n }\n\n const collisionCheck = await findUsersByNormalizedEmail(invitation.email)\n if (collisionCheck.length > 1) {\n return {\n succeeded: false,\n status: 409,\n error: 'Multiple accounts use this email. Contact support to reconcile before accepting this invitation.',\n }\n }\n\n if (requireVerifiedEmail && !currentUser.emailVerified) {\n return { succeeded: false, status: 403, error: 'Verify your email before accepting this invitation' }\n }\n\n const orgMember = await getOrganizationMember(invitation.organizationId, currentUser.id)\n if (orgMember?.role === 'owner' || orgMember?.role === 'admin') {\n return { succeeded: false, status: 409, error: 'This user already has account-level access.' }\n }\n\n if (invitation.status === 'accepted') {\n const existing = orgMember ? await getWorkspaceMemberByOrganizationMember(invitation.workspaceId, orgMember.id) : null\n if (existing) return { succeeded: true, value: { workspaceId: invitation.workspaceId } }\n return { succeeded: false, status: 409, error: 'Invitation has already been accepted' }\n }\n if (invitation.status === 'expired') return { succeeded: false, status: 409, error: 'Invitation has expired' }\n if (invitation.status === 'revoked') return { succeeded: false, status: 409, error: 'Invitation has been revoked' }\n\n if (invitation.expiresAt <= now) return { succeeded: false, status: 409, error: 'Invitation has expired' }\n if (!db.batch) return { succeeded: false, status: 500, error: 'Atomic invitation acceptance is unavailable' }\n\n const eligible = invitationAcceptFence(\n { workspaceInvitations, workspaces, users, organizationMembers, workspaceMembers },\n { token: input.token, invitation, currentUser, now },\n )\n const eligibleInvitation = sql`exists (select 1 from ${workspaceInvitations} where ${eligible})`\n const timestamp = sql`${Math.floor(now.getTime() / 1000)}`\n const [, insertedMembers, accepted] = await db.batch([\n db.insert(organizationMembers).select(db.select({\n id: sql`lower(hex(randomblob(16)))`.as(organizationMembers.id.name),\n organizationId: sql`${invitation.organizationId}`.as(organizationMembers.organizationId.name),\n userId: sql`${currentUser.id}`.as(organizationMembers.userId.name),\n role: sql`'member'`.as(organizationMembers.role.name),\n createdAt: timestamp.as(organizationMembers.createdAt.name),\n updatedAt: timestamp.as(organizationMembers.updatedAt.name),\n }).from(workspaceInvitations).where(eligible)).onConflictDoNothing({ target: [organizationMembers.organizationId, organizationMembers.userId] }).returning(),\n db.insert(workspaceMembers).select(db.select({\n id: sql`lower(hex(randomblob(16)))`.as(workspaceMembers.id.name),\n workspaceId: sql`${invitation.workspaceId}`.as(workspaceMembers.workspaceId.name),\n organizationMemberId: organizationMembers.id,\n userId: sql`${currentUser.id}`.as(workspaceMembers.userId.name),\n role: sql`${invitation.permissions}`.as(workspaceMembers.role.name),\n invitedBy: sql`null`.as(workspaceMembers.invitedBy.name),\n inviteEmail: sql`${invitation.email}`.as(workspaceMembers.inviteEmail.name),\n inviteToken: sql`${invitation.token}`.as(workspaceMembers.inviteToken.name),\n invitedAt: timestamp.as(workspaceMembers.invitedAt.name),\n acceptedAt: timestamp.as(workspaceMembers.acceptedAt.name),\n }).from(organizationMembers).where(and(\n eq(organizationMembers.organizationId, invitation.organizationId),\n eq(organizationMembers.userId, currentUser.id),\n eligibleInvitation,\n ))).onConflictDoNothing({ target: [workspaceMembers.workspaceId, workspaceMembers.organizationMemberId] }).returning(),\n db.update(workspaceInvitations)\n .set({ status: 'accepted', acceptedAt: now })\n .where(eligible)\n .returning(),\n ])\n if (!accepted.length) {\n return { succeeded: false, status: 409, error: 'The invitation changed. Reload it before continuing.' }\n }\n if (insertedMembers.length && memberSyncSeam?.add) {\n fireMemberSync(() => memberSyncSeam.add!({\n workspaceId: invitation.workspaceId,\n userId: currentUser.id,\n role: invitation.permissions as WorkspaceRole,\n }))\n }\n\n return { succeeded: true, value: { workspaceId: invitation.workspaceId } }\n }\n\n return { createInvitation, listInvitations, resendInvitation, revokeInvitation, getPreview, acceptInvitation }\n}\n\nfunction createInvitationQueries(\n workspaceInvitations: InvitationsApiOptions['invitationsTable']['workspaceInvitations'],\n db: InvitationsApiOptions['db'],\n users: InvitationsApiOptions['userTable'],\n organizationMembers: InvitationsApiOptions['tables']['organizationMembers'],\n workspaceMembers: InvitationsApiOptions['tables']['workspaceMembers'],\n workspaces: InvitationsApiOptions['workspaceTable'],\n) {\n // ── internal query helpers ──\n\n async function expirePendingInvitations(workspaceId: string, email: string | undefined, now: Date) {\n const conditions = [\n eq(workspaceInvitations.workspaceId, workspaceId),\n eq(workspaceInvitations.status, 'pending' as const),\n lte(workspaceInvitations.expiresAt, now),\n ]\n if (email) conditions.push(eq(workspaceInvitations.email, email))\n await db.update(workspaceInvitations).set({ status: 'expired' }).where(and(...conditions))\n }\n\n async function getPendingInvitation(workspaceId: string, email: string) {\n const [invitation] = await db\n .select({ id: workspaceInvitations.id })\n .from(workspaceInvitations)\n .where(and(\n eq(workspaceInvitations.workspaceId, workspaceId),\n eq(workspaceInvitations.email, email),\n eq(workspaceInvitations.status, 'pending' as const),\n ))\n .limit(1)\n return invitation ?? null\n }\n\n async function checkExistingAccountAccess(\n organizationId: string,\n workspaceId: string,\n email: string,\n invitedByUserId: string,\n ): Promise<\n | { succeeded: false; status: number; error: string }\n | { succeeded: true; inviterEmail: string | null; isExistingOrgMember: boolean }\n > {\n const matchingUsers = await findUsersByNormalizedEmail(email)\n const [inviter] = await db\n .select({ email: users.email })\n .from(users)\n .where(eq(users.id, invitedByUserId))\n .limit(1)\n\n if (matchingUsers.length > 1) {\n return {\n succeeded: false,\n status: 409,\n error: 'Multiple accounts use this email. Contact support to reconcile before inviting this user.',\n }\n }\n const existingUser = matchingUsers[0]\n if (!existingUser) return { succeeded: true, inviterEmail: inviter?.email ?? null, isExistingOrgMember: false }\n\n const orgMember = await getOrganizationMember(organizationId, existingUser.id)\n if (orgMember?.role === 'owner' || orgMember?.role === 'admin') {\n return { succeeded: false, status: 409, error: 'This user already has account-level access.' }\n }\n if (orgMember) {\n const workspaceMember = await getWorkspaceMemberByOrganizationMember(workspaceId, orgMember.id)\n if (workspaceMember) return { succeeded: false, status: 409, error: 'User is already a workspace member' }\n }\n\n return { succeeded: true, inviterEmail: inviter?.email ?? null, isExistingOrgMember: Boolean(orgMember) }\n }\n\n async function findUsersByNormalizedEmail(email: string) {\n return db\n .select({ id: users.id, email: users.email, emailVerified: users.emailVerified })\n .from(users)\n .where(sql`lower(${users.email}) = ${email}`)\n }\n\n async function getOrganizationMember(organizationId: string, userId: string) {\n const [member] = await db\n .select()\n .from(organizationMembers)\n .where(and(eq(organizationMembers.organizationId, organizationId), eq(organizationMembers.userId, userId)))\n .limit(1)\n return member ?? null\n }\n\n async function getWorkspaceMemberByOrganizationMember(workspaceId: string, organizationMemberId: string) {\n const [member] = await db\n .select({ id: workspaceMembers.id })\n .from(workspaceMembers)\n .where(and(\n eq(workspaceMembers.workspaceId, workspaceId),\n eq(workspaceMembers.organizationMemberId, organizationMemberId),\n ))\n .limit(1)\n return member ?? null\n }\n\n async function getInvitationById(invitationId: string) {\n const [row] = await db\n .select({ invitation: workspaceInvitations, inviterEmail: users.email })\n .from(workspaceInvitations)\n .leftJoin(users, eq(users.id, workspaceInvitations.invitedByUserId))\n .where(eq(workspaceInvitations.id, invitationId))\n .limit(1)\n return row ?? null\n }\n\n async function getInvitationByToken(token: string) {\n const [row] = await db\n .select({\n invitation: workspaceInvitations,\n workspaceName: workspaces.name,\n inviterEmail: users.email,\n })\n .from(workspaceInvitations)\n .innerJoin(workspaces, eq(workspaces.id, workspaceInvitations.workspaceId))\n .leftJoin(users, eq(users.id, workspaceInvitations.invitedByUserId))\n .where(eq(workspaceInvitations.token, token))\n .limit(1)\n return row ?? null\n }\n\n async function markInvitationExpired(invitationId: string) {\n const [updated] = await db.update(workspaceInvitations)\n .set({ status: 'expired' })\n .where(eq(workspaceInvitations.id, invitationId))\n .returning()\n return updated!\n }\n\n function toInvitationView(invitation: WorkspaceInvitationRow, inviterEmail: string | null): WorkspaceInvitationView {\n return {\n id: invitation.id,\n workspaceId: invitation.workspaceId,\n organizationId: invitation.organizationId,\n email: invitation.email,\n invitedByUserId: invitation.invitedByUserId,\n inviterEmail,\n permissions: invitation.permissions,\n token: invitation.token,\n status: invitation.status,\n emailStatus: invitation.emailStatus,\n expiresAt: invitation.expiresAt,\n createdAt: invitation.createdAt,\n acceptedAt: invitation.acceptedAt,\n revokedAt: invitation.revokedAt,\n lastSentAt: invitation.lastSentAt,\n }\n }\n return { expirePendingInvitations, getPendingInvitation, checkExistingAccountAccess, toInvitationView, getInvitationById, markInvitationExpired, getInvitationByToken, findUsersByNormalizedEmail, getOrganizationMember, getWorkspaceMemberByOrganizationMember }\n}\n\nfunction createInvitationIssuer(\n access: InvitationsApiOptions['access'],\n expirePendingInvitations: ReturnType<typeof createInvitationQueries>['expirePendingInvitations'],\n getPendingInvitation: ReturnType<typeof createInvitationQueries>['getPendingInvitation'],\n checkExistingAccountAccess: ReturnType<typeof createInvitationQueries>['checkExistingAccountAccess'],\n enforceSeat: InvitationsApiOptions['enforceSeat'],\n db: InvitationsApiOptions['db'],\n workspaceInvitations: InvitationsApiOptions['invitationsTable']['workspaceInvitations'],\n sendInvitationEmail: InvitationsApiOptions['sendInvitationEmail'],\n productDisplayName: string,\n toInvitationView: ReturnType<typeof createInvitationQueries>['toInvitationView'],\n) {\n async function createInvitation(input: {\n workspaceId: string\n email: string\n permissions: string | undefined\n invitedByUserId: string\n origin: string\n now?: Date\n }): Promise<InvitationOutcome<{ invitation: WorkspaceInvitationView; inviteUrl: string; emailError?: string }>> {\n const now = input.now ?? new Date()\n const accessRow = await access.getWorkspaceAccess(input.workspaceId, input.invitedByUserId, 'admin')\n if (!accessRow) return { succeeded: false, status: 404, error: 'Workspace not found' }\n\n const permissions = parseInvitationPermission(input.permissions ?? 'editor')\n if (!permissions) return { succeeded: false, status: 400, error: 'Invalid permissions' }\n if (!hasWorkspaceRole(accessRow.role, permissions)) {\n return { succeeded: false, status: 403, error: 'Cannot assign higher permissions than your own' }\n }\n\n const email = normalizeInvitationEmail(input.email)\n if (!email) return { succeeded: false, status: 400, error: 'Missing email' }\n if (!isInvitationEmail(email)) return { succeeded: false, status: 400, error: INVITATION_EMAIL_HINT }\n\n const organizationId = accessRow.organization.id\n const workspaceName = (accessRow.workspace as { name: string }).name\n\n await expirePendingInvitations(input.workspaceId, email, now)\n\n const existingPending = await getPendingInvitation(input.workspaceId, email)\n if (existingPending) return { succeeded: false, status: 409, error: 'A pending invitation already exists for this email' }\n\n const accountCheck = await checkExistingAccountAccess(organizationId, input.workspaceId, email, input.invitedByUserId)\n if (!accountCheck.succeeded) return accountCheck\n\n // Seat gate: only a genuinely NEW seat. The checks above reject re-invites,\n // existing workspace members, and org admins; an existing plain org member is\n // already billable (no new seat), so skip the gate for them — mirrors\n // members-api. The pending row is not inserted yet, so the seam's count\n // reflects current usage and denies the invite that would push OVER the limit\n // (at invite time, not accept time).\n if (enforceSeat && !accountCheck.isExistingOrgMember) {\n try {\n await enforceSeat({ actorId: input.invitedByUserId, organizationId })\n } catch (err) {\n if (err instanceof SeatLimitError) return { succeeded: false, status: err.status, error: err.message }\n throw err\n }\n }\n\n const token = generateInvitationToken()\n const expiresAt = getInvitationExpiresAt(now)\n\n const [created] = await db.insert(workspaceInvitations).values({\n workspaceId: input.workspaceId,\n organizationId,\n email,\n invitedByUserId: input.invitedByUserId,\n permissions,\n token,\n status: 'pending',\n emailStatus: 'not_sent',\n expiresAt,\n createdAt: now,\n }).returning()\n\n const inviteUrl = inviteUrlForToken(input.origin, token)\n const emailResult = await sendInvitationEmail({\n to: email,\n workspaceName,\n inviterEmail: accountCheck.inviterEmail ?? productDisplayName,\n permission: permissions,\n inviteUrl,\n expiresAt,\n })\n\n const emailStatus: InvitationEmailStatus = emailResult.succeeded ? 'sent' : 'failed'\n const [updated] = await db.update(workspaceInvitations)\n .set({ emailStatus, lastSentAt: emailResult.succeeded ? now : null })\n .where(eq(workspaceInvitations.id, created!.id))\n .returning()\n\n return {\n succeeded: true,\n value: {\n invitation: toInvitationView(updated!, accountCheck.inviterEmail),\n inviteUrl,\n emailError: emailResult.succeeded ? undefined : emailResult.error,\n },\n }\n }\n return { createInvitation }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2BA,SAAS,KAAK,IAAI,KAAK,WAAW;AAsHlC,SAAS,sBACP,QAOA,OAMA;AACA,QAAM,EAAE,sBAAsB,YAAY,OAAO,qBAAqB,iBAAiB,IAAI;AAC3F,QAAM,EAAE,YAAY,aAAa,IAAI,IAAI;AACzC,QAAM,QAAQ,EAAE,OAAO,MAAM,MAAM;AACnC,SAAO;AAAA,IACL,GAAG,qBAAqB,IAAI,WAAW,EAAE;AAAA,IACzC,GAAG,qBAAqB,OAAO,MAAM,KAAK;AAAA,IAC1C,GAAG,qBAAqB,QAAQ,SAAS;AAAA,IACzC,GAAG,qBAAqB,gBAAgB,WAAW,cAAc;AAAA,IACjE,GAAG,qBAAqB,aAAa,WAAW,WAAW;AAAA,IAC3D,GAAG,qBAAqB,OAAO,WAAW,KAAK;AAAA,IAC/C,GAAG,qBAAqB,aAAa,WAAW,WAAW;AAAA,IAC3D,MAAM,qBAAqB,SAAS,MAAM,KAAK,MAAM,IAAI,QAAQ,IAAI,GAAI,CAAC;AAAA,IAC1E,4BAA4B,UAAU,UAAU,WAAW,EAAE,MAAM,qBAAqB,WAAW;AAAA,YAC3F,WAAW,cAAc,MAAM,WAAW,cAAc;AAAA,IAChE,4BAA4B,KAAK,UAAU,MAAM,EAAE,MAAM,YAAY,EAAE;AAAA,uBACpD,MAAM,KAAK,QAAQ,WAAW,KAAK;AAAA,YAC9C,MAAM,aAAa,MAAM,YAAY,gBAAgB,IA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;AAAA,MAC9D;AAAA,IACF;AAAA,EACF;AACA,SAAO,EAAE,iBAAiB;AAC5B;","names":[]}
1
+ {"version":3,"sources":["../../src/teams/invitations-api.ts"],"sourcesContent":["/**\n * Framework-neutral email-invitation lifecycle for the teams module: create /\n * list / resend / revoke / preview / accept over the dedicated\n * `workspace_invitation` table (from `createWorkspaceInvitationTable`). Lifted out\n * of any one app's route file — each app binds this once to its own db/tables/\n * access and mounts the handlers in its own routes with its own auth.\n *\n * Unlike `members-api` (whose \"invite\" is a pending workspaceMember row, no\n * email), this models the rich lifecycle: a dedicated invitation row with status,\n * 7-day expiry, emailStatus, resend, and revoke. On accept it materializes the\n * `organizationMembers` + `workspaceMembers` rows, so `members-api.listMembers`\n * still surfaces accepted members; pending invites live only here.\n *\n * Handlers return a discriminated `InvitationOutcome` (not a `Response`) so the\n * route adapter maps `{ status }` to its own framework's response. Three seams:\n * - `sendInvitationEmail` (OPTIONAL) — the app's mail transport. Returns a\n * typed outcome; a failed send never blocks invitation creation (emailStatus\n * is recorded as 'failed' and the invite link is still returned). Without\n * it the product is link-only: nothing is sent, the row stays `not_sent`,\n * and resend is refused.\n * - `enforceSeat` (OPTIONAL) — billing/seat-limit gate, called at create time\n * only when the invite would consume a NEW seat. Reused from members-api.\n * - `memberSyncSeam.add` (OPTIONAL) — fire-and-forget propagation of the new\n * member to a sandbox/external system on accept. Fail-soft by contract.\n *\n * Imports `drizzle-orm`, so this is a subpath, never re-exported from root.\n */\n\nimport { fireMemberSync } from './member-sync'\nimport { and, eq, lte, sql } from 'drizzle-orm'\nimport {\n type InvitationEmailStatus,\n type InvitationPermission,\n type InvitationStatus,\n generateInvitationToken,\n getInvitationExpiresAt,\n inviteUrlForToken,\n INVITATION_EMAIL_HINT,\n isInvitationEmail,\n normalizeInvitationEmail,\n parseInvitationPermission,\n} from './invitations'\nimport { type WorkspaceRole, hasWorkspaceRole } from './roles'\nimport { type EnforceSeatSeam, type MemberSyncCallbacks, SeatLimitError } from './members-api'\nimport type { TeamDatabase, WorkspaceAccessReader } from './drizzle/access'\nimport type { TeamParentTable, TeamTables } from './drizzle/schema'\nimport type { WorkspaceInvitationRow, WorkspaceInvitationTables } from './drizzle/invitations-schema'\n\n// Re-export the seams an adopter wires, so a consumer can import everything the\n// invitations API needs from this one subpath.\nexport { SeatLimitError } from './members-api'\nexport type { EnforceSeatSeam, MemberSyncCallbacks } from './members-api'\n\n/** The app's mail transport. Returns a typed outcome; never throws to the API. */\nexport interface SendInvitationEmailInput {\n to: string\n workspaceName: string\n inviterEmail: string\n permission: InvitationPermission\n inviteUrl: string\n expiresAt: Date\n}\n/** Represent the outcome of sending an invitation email with success status and optional error message */\nexport type SendInvitationEmailResult = { succeeded: true } | { succeeded: false; error: string }\n/** Resolve sending an invitation email and return the result asynchronously */\nexport interface SendInvitationEmailSeam {\n (input: SendInvitationEmailInput): Promise<SendInvitationEmailResult>\n}\n\n/** The product's user table, narrowed to the columns the queries read. */\nexport interface InvitationUserTable {\n id: any\n email: any\n emailVerified: any\n}\n\n/** The product's workspace table, narrowed to the columns the queries read. */\nexport interface InvitationWorkspaceTable {\n id: any\n name: any\n organizationId: any\n}\n\n/** Define configuration options required to manage workspace invitations and related data sources */\nexport interface InvitationsApiOptions {\n db: TeamDatabase & { batch?: (statements: [any, ...any[]]) => Promise<any[]> }\n tables: TeamTables\n /** The invitation table from `createWorkspaceInvitationTable`. */\n invitationsTable: WorkspaceInvitationTables\n userTable: TeamParentTable & InvitationUserTable\n workspaceTable: TeamParentTable & InvitationWorkspaceTable\n access: WorkspaceAccessReader\n /** The app's mail transport (e.g. Resend + `inviteEmail` from `./email`). Leave it out for link-only invitations. */\n sendInvitationEmail?: SendInvitationEmailSeam\n /** OPTIONAL — seat-limit gate at create time; mirrors members-api. */\n enforceSeat?: EnforceSeatSeam\n /** OPTIONAL — fire-and-forget member propagation on accept. */\n memberSyncSeam?: Pick<MemberSyncCallbacks, 'add'>\n /** Inviter display fallback when the inviter's email is unknown. */\n productDisplayName?: string\n /** Refuse acceptance until the signed-in account's email is verified. Off by\n * default: a valid token for the matching address already proves inbox access\n * (#146). A product that wants verification first turns it on. */\n requireVerifiedEmail?: boolean\n}\n\n/** Represent a workspace invitation with details about inviter, permissions, status, and timestamps */\nexport interface WorkspaceInvitationView {\n id: string\n workspaceId: string\n organizationId: string\n email: string\n invitedByUserId: string\n inviterEmail: string | null\n permissions: InvitationPermission\n token: string\n status: InvitationStatus\n emailStatus: InvitationEmailStatus\n expiresAt: Date\n createdAt: Date\n acceptedAt: Date | null\n revokedAt: Date | null\n lastSentAt: Date | null\n}\n\n/** Describe the structure of an invitation preview with workspace, email, permissions, status, and expiration details */\nexport interface InvitationPreview {\n workspaceId: string\n workspaceName: string\n email: string\n inviterEmail: string | null\n permissions: InvitationPermission\n status: InvitationStatus\n expiresAt: Date\n}\n\n/** Resolve the result of an invitation as success with a value or failure with status and error details */\nexport type InvitationOutcome<T> =\n | { succeeded: true; value: T }\n | { succeeded: false; status: number; error: string }\n\n/**\n * The live fence all three acceptance writes share, evaluated inside one\n * atomic D1 batch. A workspace transfer or revoke between the reads and the\n * batch wins cleanly: there is no membership to repair or runtime access to\n * retract.\n */\nfunction invitationAcceptFence(\n tables: {\n workspaceInvitations: WorkspaceInvitationTables['workspaceInvitations']\n workspaces: InvitationWorkspaceTable\n users: InvitationUserTable\n organizationMembers: TeamTables['organizationMembers']\n workspaceMembers: TeamTables['workspaceMembers']\n },\n fence: {\n token: string\n invitation: WorkspaceInvitationRow\n currentUser: { id: string; emailVerified: boolean | null }\n now: Date\n },\n) {\n const { workspaceInvitations, workspaces, users, organizationMembers, workspaceMembers } = tables\n const { invitation, currentUser, now } = fence\n const input = { token: fence.token }\n return and(\n eq(workspaceInvitations.id, invitation.id),\n eq(workspaceInvitations.token, input.token),\n eq(workspaceInvitations.status, 'pending'),\n eq(workspaceInvitations.organizationId, invitation.organizationId),\n eq(workspaceInvitations.workspaceId, invitation.workspaceId),\n eq(workspaceInvitations.email, invitation.email),\n eq(workspaceInvitations.permissions, invitation.permissions),\n sql`${workspaceInvitations.expiresAt} > ${Math.floor(now.getTime() / 1000)}`,\n sql`exists (select 1 from ${workspaces} where ${workspaces.id} = ${workspaceInvitations.workspaceId}\n and ${workspaces.organizationId} = ${invitation.organizationId})`,\n sql`exists (select 1 from ${users} where ${users.id} = ${currentUser.id}\n and lower(trim(${users.email})) = ${invitation.email}\n and ${users.emailVerified} = ${currentUser.emailVerified ? 1 : 0})`,\n sql`(select count(*) from ${users} where lower(trim(${users.email})) = ${invitation.email}) = 1`,\n sql`not exists (select 1 from ${workspaceMembers} inner join ${organizationMembers}\n on ${organizationMembers.id} = ${workspaceMembers.organizationMemberId}\n where ${workspaceMembers.workspaceId} = ${invitation.workspaceId}\n and ${organizationMembers.organizationId} = ${invitation.organizationId}\n and ${organizationMembers.userId} = ${currentUser.id}\n and ${workspaceMembers.acceptedAt} is null)`,\n sql`not exists (select 1 from ${workspaceMembers} where ${workspaceMembers.inviteToken} = ${invitation.token}\n and (${workspaceMembers.workspaceId} != ${invitation.workspaceId}\n or ${workspaceMembers.organizationMemberId} is null\n or ${workspaceMembers.organizationMemberId} not in (select ${organizationMembers.id} from ${organizationMembers}\n where ${organizationMembers.organizationId} = ${invitation.organizationId}\n and ${organizationMembers.userId} = ${currentUser.id})))`,\n sql`not exists (select 1 from ${organizationMembers}\n where ${organizationMembers.organizationId} = ${invitation.organizationId}\n and ${organizationMembers.userId} = ${currentUser.id}\n and ${organizationMembers.role} in ('owner', 'admin'))`,\n )\n}\n\n/**\n * Build the invitations API bound to one product's db/tables/access/seams.\n * Returns the six lifecycle handlers an app mounts in its routes.\n */\nexport function createInvitationsApi(opts: InvitationsApiOptions) {\n const { db, tables, access, sendInvitationEmail, enforceSeat, memberSyncSeam, requireVerifiedEmail = false } = opts\n const { organizationMembers, workspaceMembers } = tables\n const { workspaceInvitations } = opts.invitationsTable\n const users = opts.userTable\n const workspaces = opts.workspaceTable\n const productDisplayName = opts.productDisplayName ?? 'A workspace admin'\n\n\n\n const { expirePendingInvitations, getPendingInvitation, checkExistingAccountAccess, toInvitationView, getInvitationById, markInvitationExpired, getInvitationByToken, findUsersByNormalizedEmail, getOrganizationMember, getWorkspaceMemberByOrganizationMember } = createInvitationQueries(workspaceInvitations, db, users, organizationMembers, workspaceMembers, workspaces)\n\n const { createInvitation } = createInvitationIssuer(access, expirePendingInvitations, getPendingInvitation, checkExistingAccountAccess, enforceSeat, db, workspaceInvitations, sendInvitationEmail, productDisplayName, toInvitationView)\n\n async function listInvitations(input: {\n workspaceId: string\n userId: string\n origin: string\n now?: Date\n }): Promise<InvitationOutcome<{ invitations: Array<WorkspaceInvitationView & { inviteUrl: string }> }>> {\n const accessRow = await access.getWorkspaceAccess(input.workspaceId, input.userId, 'admin')\n if (!accessRow) return { succeeded: false, status: 404, error: 'Workspace not found' }\n\n await expirePendingInvitations(input.workspaceId, undefined, input.now ?? new Date())\n\n const rows = await db\n .select({ invitation: workspaceInvitations, inviterEmail: users.email })\n .from(workspaceInvitations)\n .leftJoin(users, eq(users.id, workspaceInvitations.invitedByUserId))\n .where(eq(workspaceInvitations.workspaceId, input.workspaceId))\n .orderBy(sql`${workspaceInvitations.createdAt} desc`)\n\n return {\n succeeded: true,\n value: {\n invitations: rows.map((row: { invitation: WorkspaceInvitationRow; inviterEmail: string | null }) => ({\n ...toInvitationView(row.invitation, row.inviterEmail),\n inviteUrl: inviteUrlForToken(input.origin, row.invitation.token),\n })),\n },\n }\n }\n\n async function resendInvitation(input: {\n invitationId: string\n userId: string\n origin: string\n now?: Date\n }): Promise<InvitationOutcome<{ invitation: WorkspaceInvitationView; inviteUrl: string; emailError?: string }>> {\n const row = await getInvitationById(input.invitationId)\n if (!row) return { succeeded: false, status: 404, error: 'Invitation not found' }\n\n const accessRow = await access.getWorkspaceAccess(row.invitation.workspaceId, input.userId, 'admin')\n if (!accessRow) return { succeeded: false, status: 404, error: 'Workspace not found' }\n\n if (!sendInvitationEmail) return { succeeded: false, status: 409, error: 'Invitations here are links. Copy the link and share it instead.' }\n const now = input.now ?? new Date()\n if (row.invitation.status !== 'pending') {\n return { succeeded: false, status: 409, error: 'Only pending invitations can be resent' }\n }\n if (row.invitation.expiresAt <= now) {\n await markInvitationExpired(row.invitation.id)\n return { succeeded: false, status: 409, error: 'Invitation has expired' }\n }\n\n const workspaceName = (accessRow.workspace as { name: string }).name\n const inviteUrl = inviteUrlForToken(input.origin, row.invitation.token)\n const emailResult = await sendInvitationEmail({\n to: row.invitation.email,\n workspaceName,\n inviterEmail: row.inviterEmail ?? productDisplayName,\n permission: row.invitation.permissions,\n inviteUrl,\n expiresAt: row.invitation.expiresAt,\n })\n\n const [updated] = await db.update(workspaceInvitations)\n .set({\n emailStatus: emailResult.succeeded ? 'sent' : 'failed',\n lastSentAt: emailResult.succeeded ? now : row.invitation.lastSentAt,\n })\n .where(eq(workspaceInvitations.id, row.invitation.id))\n .returning()\n\n return {\n succeeded: true,\n value: {\n invitation: toInvitationView(updated!, row.inviterEmail),\n inviteUrl,\n emailError: emailResult.succeeded ? undefined : emailResult.error,\n },\n }\n }\n\n async function revokeInvitation(input: {\n invitationId: string\n userId: string\n now?: Date\n }): Promise<InvitationOutcome<{ invitation: WorkspaceInvitationView }>> {\n const row = await getInvitationById(input.invitationId)\n if (!row) return { succeeded: false, status: 404, error: 'Invitation not found' }\n\n const accessRow = await access.getWorkspaceAccess(row.invitation.workspaceId, input.userId, 'admin')\n if (!accessRow) return { succeeded: false, status: 404, error: 'Workspace not found' }\n if (row.invitation.status !== 'pending') {\n return { succeeded: false, status: 409, error: 'Only pending invitations can be revoked' }\n }\n\n const [updated] = await db.update(workspaceInvitations)\n .set({ status: 'revoked', revokedAt: input.now ?? new Date() })\n .where(and(eq(workspaceInvitations.id, row.invitation.id), eq(workspaceInvitations.status, 'pending')))\n .returning()\n\n // The status read above is advisory. A concurrent accept may win between\n // that read and this update, so the write must be compare-and-set.\n if (!updated) return { succeeded: false, status: 409, error: 'The invitation changed. Reload it before continuing.' }\n\n return { succeeded: true, value: { invitation: toInvitationView(updated!, row.inviterEmail) } }\n }\n\n async function getPreview(token: string, now: Date = new Date()): Promise<InvitationOutcome<InvitationPreview>> {\n const row = await getInvitationByToken(token)\n if (!row) return { succeeded: false, status: 404, error: 'Invitation not found' }\n\n let invitation = row.invitation\n if (invitation.status === 'pending' && invitation.expiresAt <= now) {\n invitation = await markInvitationExpired(invitation.id)\n }\n\n return {\n succeeded: true,\n value: {\n workspaceId: invitation.workspaceId,\n workspaceName: row.workspaceName,\n email: invitation.email,\n inviterEmail: row.inviterEmail,\n permissions: invitation.permissions,\n status: invitation.status,\n expiresAt: invitation.expiresAt,\n },\n }\n }\n\n async function acceptInvitation(input: {\n token: string\n userId: string\n now?: Date\n }): Promise<InvitationOutcome<{ workspaceId: string }>> {\n const now = input.now ?? new Date()\n const row = await getInvitationByToken(input.token)\n if (!row) return { succeeded: false, status: 404, error: 'Invitation not found' }\n\n const invitation = row.invitation\n\n const [currentUser] = await db\n .select({ id: users.id, email: users.email, emailVerified: users.emailVerified })\n .from(users)\n .where(eq(users.id, input.userId))\n .limit(1)\n if (!currentUser) return { succeeded: false, status: 401, error: 'Authentication required' }\n\n if (normalizeInvitationEmail(currentUser.email) !== invitation.email) {\n return { succeeded: false, status: 403, error: 'Sign in with the invited email address to accept this invitation' }\n }\n\n const collisionCheck = await findUsersByNormalizedEmail(invitation.email)\n if (collisionCheck.length > 1) {\n return {\n succeeded: false,\n status: 409,\n error: 'Multiple accounts use this email. Contact support to reconcile before accepting this invitation.',\n }\n }\n\n if (requireVerifiedEmail && !currentUser.emailVerified) {\n return { succeeded: false, status: 403, error: 'Verify your email before accepting this invitation' }\n }\n\n const orgMember = await getOrganizationMember(invitation.organizationId, currentUser.id)\n if (orgMember?.role === 'owner' || orgMember?.role === 'admin') {\n return { succeeded: false, status: 409, error: 'This user already has account-level access.' }\n }\n\n if (invitation.status === 'accepted') {\n const existing = orgMember ? await getWorkspaceMemberByOrganizationMember(invitation.workspaceId, orgMember.id) : null\n if (existing) return { succeeded: true, value: { workspaceId: invitation.workspaceId } }\n return { succeeded: false, status: 409, error: 'Invitation has already been accepted' }\n }\n if (invitation.status === 'expired') return { succeeded: false, status: 409, error: 'Invitation has expired' }\n if (invitation.status === 'revoked') return { succeeded: false, status: 409, error: 'Invitation has been revoked' }\n\n if (invitation.expiresAt <= now) return { succeeded: false, status: 409, error: 'Invitation has expired' }\n if (!db.batch) return { succeeded: false, status: 500, error: 'Atomic invitation acceptance is unavailable' }\n\n const eligible = invitationAcceptFence(\n { workspaceInvitations, workspaces, users, organizationMembers, workspaceMembers },\n { token: input.token, invitation, currentUser, now },\n )\n const eligibleInvitation = sql`exists (select 1 from ${workspaceInvitations} where ${eligible})`\n const timestamp = sql`${Math.floor(now.getTime() / 1000)}`\n const [, insertedMembers, accepted] = await db.batch([\n db.insert(organizationMembers).select(db.select({\n id: sql`lower(hex(randomblob(16)))`.as(organizationMembers.id.name),\n organizationId: sql`${invitation.organizationId}`.as(organizationMembers.organizationId.name),\n userId: sql`${currentUser.id}`.as(organizationMembers.userId.name),\n role: sql`'member'`.as(organizationMembers.role.name),\n createdAt: timestamp.as(organizationMembers.createdAt.name),\n updatedAt: timestamp.as(organizationMembers.updatedAt.name),\n }).from(workspaceInvitations).where(eligible)).onConflictDoNothing({ target: [organizationMembers.organizationId, organizationMembers.userId] }).returning(),\n db.insert(workspaceMembers).select(db.select({\n id: sql`lower(hex(randomblob(16)))`.as(workspaceMembers.id.name),\n workspaceId: sql`${invitation.workspaceId}`.as(workspaceMembers.workspaceId.name),\n organizationMemberId: organizationMembers.id,\n userId: sql`${currentUser.id}`.as(workspaceMembers.userId.name),\n role: sql`${invitation.permissions}`.as(workspaceMembers.role.name),\n invitedBy: sql`null`.as(workspaceMembers.invitedBy.name),\n inviteEmail: sql`${invitation.email}`.as(workspaceMembers.inviteEmail.name),\n inviteToken: sql`${invitation.token}`.as(workspaceMembers.inviteToken.name),\n invitedAt: timestamp.as(workspaceMembers.invitedAt.name),\n acceptedAt: timestamp.as(workspaceMembers.acceptedAt.name),\n }).from(organizationMembers).where(and(\n eq(organizationMembers.organizationId, invitation.organizationId),\n eq(organizationMembers.userId, currentUser.id),\n eligibleInvitation,\n ))).onConflictDoNothing({ target: [workspaceMembers.workspaceId, workspaceMembers.organizationMemberId] }).returning(),\n db.update(workspaceInvitations)\n .set({ status: 'accepted', acceptedAt: now })\n .where(eligible)\n .returning(),\n ])\n if (!accepted.length) {\n return { succeeded: false, status: 409, error: 'The invitation changed. Reload it before continuing.' }\n }\n if (insertedMembers.length && memberSyncSeam?.add) {\n fireMemberSync(() => memberSyncSeam.add!({\n workspaceId: invitation.workspaceId,\n userId: currentUser.id,\n role: invitation.permissions as WorkspaceRole,\n }))\n }\n\n return { succeeded: true, value: { workspaceId: invitation.workspaceId } }\n }\n\n return { createInvitation, listInvitations, resendInvitation, revokeInvitation, getPreview, acceptInvitation }\n}\n\nfunction createInvitationQueries(\n workspaceInvitations: InvitationsApiOptions['invitationsTable']['workspaceInvitations'],\n db: InvitationsApiOptions['db'],\n users: InvitationsApiOptions['userTable'],\n organizationMembers: InvitationsApiOptions['tables']['organizationMembers'],\n workspaceMembers: InvitationsApiOptions['tables']['workspaceMembers'],\n workspaces: InvitationsApiOptions['workspaceTable'],\n) {\n // ── internal query helpers ──\n\n async function expirePendingInvitations(workspaceId: string, email: string | undefined, now: Date) {\n const conditions = [\n eq(workspaceInvitations.workspaceId, workspaceId),\n eq(workspaceInvitations.status, 'pending' as const),\n lte(workspaceInvitations.expiresAt, now),\n ]\n if (email) conditions.push(eq(workspaceInvitations.email, email))\n await db.update(workspaceInvitations).set({ status: 'expired' }).where(and(...conditions))\n }\n\n async function getPendingInvitation(workspaceId: string, email: string) {\n const [invitation] = await db\n .select({ id: workspaceInvitations.id })\n .from(workspaceInvitations)\n .where(and(\n eq(workspaceInvitations.workspaceId, workspaceId),\n eq(workspaceInvitations.email, email),\n eq(workspaceInvitations.status, 'pending' as const),\n ))\n .limit(1)\n return invitation ?? null\n }\n\n async function checkExistingAccountAccess(\n organizationId: string,\n workspaceId: string,\n email: string,\n invitedByUserId: string,\n ): Promise<\n | { succeeded: false; status: number; error: string }\n | { succeeded: true; inviterEmail: string | null; isExistingOrgMember: boolean }\n > {\n const matchingUsers = await findUsersByNormalizedEmail(email)\n const [inviter] = await db\n .select({ email: users.email })\n .from(users)\n .where(eq(users.id, invitedByUserId))\n .limit(1)\n\n if (matchingUsers.length > 1) {\n return {\n succeeded: false,\n status: 409,\n error: 'Multiple accounts use this email. Contact support to reconcile before inviting this user.',\n }\n }\n const existingUser = matchingUsers[0]\n if (!existingUser) return { succeeded: true, inviterEmail: inviter?.email ?? null, isExistingOrgMember: false }\n\n const orgMember = await getOrganizationMember(organizationId, existingUser.id)\n if (orgMember?.role === 'owner' || orgMember?.role === 'admin') {\n return { succeeded: false, status: 409, error: 'This user already has account-level access.' }\n }\n if (orgMember) {\n const workspaceMember = await getWorkspaceMemberByOrganizationMember(workspaceId, orgMember.id)\n if (workspaceMember) return { succeeded: false, status: 409, error: 'User is already a workspace member' }\n }\n\n return { succeeded: true, inviterEmail: inviter?.email ?? null, isExistingOrgMember: Boolean(orgMember) }\n }\n\n async function findUsersByNormalizedEmail(email: string) {\n return db\n .select({ id: users.id, email: users.email, emailVerified: users.emailVerified })\n .from(users)\n .where(sql`lower(${users.email}) = ${email}`)\n }\n\n async function getOrganizationMember(organizationId: string, userId: string) {\n const [member] = await db\n .select()\n .from(organizationMembers)\n .where(and(eq(organizationMembers.organizationId, organizationId), eq(organizationMembers.userId, userId)))\n .limit(1)\n return member ?? null\n }\n\n async function getWorkspaceMemberByOrganizationMember(workspaceId: string, organizationMemberId: string) {\n const [member] = await db\n .select({ id: workspaceMembers.id })\n .from(workspaceMembers)\n .where(and(\n eq(workspaceMembers.workspaceId, workspaceId),\n eq(workspaceMembers.organizationMemberId, organizationMemberId),\n ))\n .limit(1)\n return member ?? null\n }\n\n async function getInvitationById(invitationId: string) {\n const [row] = await db\n .select({ invitation: workspaceInvitations, inviterEmail: users.email })\n .from(workspaceInvitations)\n .leftJoin(users, eq(users.id, workspaceInvitations.invitedByUserId))\n .where(eq(workspaceInvitations.id, invitationId))\n .limit(1)\n return row ?? null\n }\n\n async function getInvitationByToken(token: string) {\n const [row] = await db\n .select({\n invitation: workspaceInvitations,\n workspaceName: workspaces.name,\n inviterEmail: users.email,\n })\n .from(workspaceInvitations)\n .innerJoin(workspaces, eq(workspaces.id, workspaceInvitations.workspaceId))\n .leftJoin(users, eq(users.id, workspaceInvitations.invitedByUserId))\n .where(eq(workspaceInvitations.token, token))\n .limit(1)\n return row ?? null\n }\n\n async function markInvitationExpired(invitationId: string) {\n const [updated] = await db.update(workspaceInvitations)\n .set({ status: 'expired' })\n .where(eq(workspaceInvitations.id, invitationId))\n .returning()\n return updated!\n }\n\n function toInvitationView(invitation: WorkspaceInvitationRow, inviterEmail: string | null): WorkspaceInvitationView {\n return {\n id: invitation.id,\n workspaceId: invitation.workspaceId,\n organizationId: invitation.organizationId,\n email: invitation.email,\n invitedByUserId: invitation.invitedByUserId,\n inviterEmail,\n permissions: invitation.permissions,\n token: invitation.token,\n status: invitation.status,\n emailStatus: invitation.emailStatus,\n expiresAt: invitation.expiresAt,\n createdAt: invitation.createdAt,\n acceptedAt: invitation.acceptedAt,\n revokedAt: invitation.revokedAt,\n lastSentAt: invitation.lastSentAt,\n }\n }\n return { expirePendingInvitations, getPendingInvitation, checkExistingAccountAccess, toInvitationView, getInvitationById, markInvitationExpired, getInvitationByToken, findUsersByNormalizedEmail, getOrganizationMember, getWorkspaceMemberByOrganizationMember }\n}\n\nfunction createInvitationIssuer(\n access: InvitationsApiOptions['access'],\n expirePendingInvitations: ReturnType<typeof createInvitationQueries>['expirePendingInvitations'],\n getPendingInvitation: ReturnType<typeof createInvitationQueries>['getPendingInvitation'],\n checkExistingAccountAccess: ReturnType<typeof createInvitationQueries>['checkExistingAccountAccess'],\n enforceSeat: InvitationsApiOptions['enforceSeat'],\n db: InvitationsApiOptions['db'],\n workspaceInvitations: InvitationsApiOptions['invitationsTable']['workspaceInvitations'],\n sendInvitationEmail: InvitationsApiOptions['sendInvitationEmail'],\n productDisplayName: string,\n toInvitationView: ReturnType<typeof createInvitationQueries>['toInvitationView'],\n) {\n async function createInvitation(input: {\n workspaceId: string\n email: string\n permissions: string | undefined\n invitedByUserId: string\n origin: string\n now?: Date\n }): Promise<InvitationOutcome<{ invitation: WorkspaceInvitationView; inviteUrl: string; emailError?: string }>> {\n const now = input.now ?? new Date()\n const accessRow = await access.getWorkspaceAccess(input.workspaceId, input.invitedByUserId, 'admin')\n if (!accessRow) return { succeeded: false, status: 404, error: 'Workspace not found' }\n\n const permissions = parseInvitationPermission(input.permissions ?? 'editor')\n if (!permissions) return { succeeded: false, status: 400, error: 'Invalid permissions' }\n if (!hasWorkspaceRole(accessRow.role, permissions)) {\n return { succeeded: false, status: 403, error: 'Cannot assign higher permissions than your own' }\n }\n\n const email = normalizeInvitationEmail(input.email)\n if (!email) return { succeeded: false, status: 400, error: 'Missing email' }\n if (!isInvitationEmail(email)) return { succeeded: false, status: 400, error: INVITATION_EMAIL_HINT }\n\n const organizationId = accessRow.organization.id\n const workspaceName = (accessRow.workspace as { name: string }).name\n\n await expirePendingInvitations(input.workspaceId, email, now)\n\n const existingPending = await getPendingInvitation(input.workspaceId, email)\n if (existingPending) return { succeeded: false, status: 409, error: 'A pending invitation already exists for this email' }\n\n const accountCheck = await checkExistingAccountAccess(organizationId, input.workspaceId, email, input.invitedByUserId)\n if (!accountCheck.succeeded) return accountCheck\n\n // Seat gate: only a genuinely NEW seat. The checks above reject re-invites,\n // existing workspace members, and org admins; an existing plain org member is\n // already billable (no new seat), so skip the gate for them — mirrors\n // members-api. The pending row is not inserted yet, so the seam's count\n // reflects current usage and denies the invite that would push OVER the limit\n // (at invite time, not accept time).\n if (enforceSeat && !accountCheck.isExistingOrgMember) {\n try {\n await enforceSeat({ actorId: input.invitedByUserId, organizationId })\n } catch (err) {\n if (err instanceof SeatLimitError) return { succeeded: false, status: err.status, error: err.message }\n throw err\n }\n }\n\n const token = generateInvitationToken()\n const expiresAt = getInvitationExpiresAt(now)\n\n const [created] = await db.insert(workspaceInvitations).values({\n workspaceId: input.workspaceId,\n organizationId,\n email,\n invitedByUserId: input.invitedByUserId,\n permissions,\n token,\n status: 'pending',\n emailStatus: 'not_sent',\n expiresAt,\n createdAt: now,\n }).returning()\n\n const inviteUrl = inviteUrlForToken(input.origin, token)\n if (!sendInvitationEmail) return { succeeded: true, value: { invitation: toInvitationView(created!, accountCheck.inviterEmail), inviteUrl } }\n const emailResult = await sendInvitationEmail({\n to: email,\n workspaceName,\n inviterEmail: accountCheck.inviterEmail ?? productDisplayName,\n permission: permissions,\n inviteUrl,\n expiresAt,\n })\n\n const emailStatus: InvitationEmailStatus = emailResult.succeeded ? 'sent' : 'failed'\n const [updated] = await db.update(workspaceInvitations)\n .set({ emailStatus, lastSentAt: emailResult.succeeded ? now : null })\n .where(eq(workspaceInvitations.id, created!.id))\n .returning()\n\n return {\n succeeded: true,\n value: {\n invitation: toInvitationView(updated!, accountCheck.inviterEmail),\n inviteUrl,\n emailError: emailResult.succeeded ? undefined : emailResult.error,\n },\n }\n }\n return { createInvitation }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA6BA,SAAS,KAAK,IAAI,KAAK,WAAW;AAsHlC,SAAS,sBACP,QAOA,OAMA;AACA,QAAM,EAAE,sBAAsB,YAAY,OAAO,qBAAqB,iBAAiB,IAAI;AAC3F,QAAM,EAAE,YAAY,aAAa,IAAI,IAAI;AACzC,QAAM,QAAQ,EAAE,OAAO,MAAM,MAAM;AACnC,SAAO;AAAA,IACL,GAAG,qBAAqB,IAAI,WAAW,EAAE;AAAA,IACzC,GAAG,qBAAqB,OAAO,MAAM,KAAK;AAAA,IAC1C,GAAG,qBAAqB,QAAQ,SAAS;AAAA,IACzC,GAAG,qBAAqB,gBAAgB,WAAW,cAAc;AAAA,IACjE,GAAG,qBAAq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BAAkB,MAAM,QAAQ,KAAK;AACvD,QAAI,CAAC,oBAAqB,QAAO,EAAE,WAAW,MAAM,OAAO,EAAE,YAAY,iBAAiB,SAAU,aAAa,YAAY,GAAG,UAAU,EAAE;AAC5I,UAAM,cAAc,MAAM,oBAAoB;AAAA,MAC5C,IAAI;AAAA,MACJ;AAAA,MACA,cAAc,aAAa,gBAAgB;AAAA,MAC3C,YAAY;AAAA,MACZ;AAAA,MACA;AAAA,IACF,CAAC;AAED,UAAM,cAAqC,YAAY,YAAY,SAAS;AAC5E,UAAM,CAAC,OAAO,IAAI,MAAM,GAAG,OAAO,oBAAoB,EACnD,IAAI,EAAE,aAAa,YAAY,YAAY,YAAY,MAAM,KAAK,CAAC,EACnE,MAAM,GAAG,qBAAqB,IAAI,QAAS,EAAE,CAAC,EAC9C,UAAU;AAEb,WAAO;AAAA,MACL,WAAW;AAAA,MACX,OAAO;AAAA,QACL,YAAY,iBAAiB,SAAU,aAAa,YAAY;AAAA,QAChE;AAAA,QACA,YAAY,YAAY,YAAY,SAAY,YAAY;AAAA,MAC9D;AAAA,IACF;AAAA,EACF;AACA,SAAO,EAAE,iBAAiB;AAC5B;","names":[]}
@@ -11,6 +11,8 @@ export type InvitationPermission = AssignableWorkspaceRole;
11
11
  export type InvitationStatus = 'pending' | 'accepted' | 'expired' | 'revoked';
12
12
  /** Define possible statuses for the sending state of an invitation email */
13
13
  export type InvitationEmailStatus = 'not_sent' | 'sent' | 'failed';
14
+ /** How an invitation reaches the person: `email` sends them the link; `link` sends nothing, and the inviter shares it. */
15
+ export type InvitationDelivery = 'email' | 'link';
14
16
  /** Define the number of days before an invitation expires */
15
17
  export declare const INVITATION_EXPIRY_DAYS = 7;
16
18
  /** Normalize an invitation email by trimming whitespace and converting to lowercase */
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  SeatLimitError,
3
3
  createMembersApi
4
- } from "../chunk-WYQTPFPI.js";
4
+ } from "../chunk-3ELC7F62.js";
5
5
  import "../chunk-DJ4VJIH5.js";
6
- import "../chunk-KBJZMR4E.js";
6
+ import "../chunk-Y5WTAHWY.js";
7
7
  import "../chunk-6XIAPIW6.js";
8
8
  export {
9
9
  SeatLimitError,
@@ -1,8 +1,10 @@
1
1
  /** The line under an invitation's address, shared by `InvitationsPanel` and the settings `InvitationsSection`. */
2
+ import type { InvitationDelivery } from '../../teams/invitations.js';
2
3
  import type { InvitationView } from '../contracts.js';
3
4
  /**
4
5
  * The line under the address: what the invitee can do, then only what is true
5
6
  * of this invitation now. Every status says itself in words, so a past
6
- * invitation reads as joined, expired or revoked without a badge.
7
+ * invitation reads as joined, expired or revoked without a badge. A link-only
8
+ * invitation never mentions email.
7
9
  */
8
- export declare function invitationDetail(invitation: InvitationView): string;
10
+ export declare function invitationDetail(invitation: InvitationView, delivery?: InvitationDelivery): string;
@@ -4,11 +4,11 @@ import {
4
4
  invitationDetail,
5
5
  isCurrentMember,
6
6
  memberRoleLabel
7
- } from "../chunk-OBKVNZPH.js";
7
+ } from "../chunk-YL5JDX7K.js";
8
8
  import {
9
9
  INVITATION_EMAIL_HINT,
10
10
  isInvitationEmail
11
- } from "../chunk-KBJZMR4E.js";
11
+ } from "../chunk-Y5WTAHWY.js";
12
12
  import {
13
13
  hasWorkspaceRole
14
14
  } from "../chunk-6XIAPIW6.js";
@@ -1988,7 +1988,7 @@
1988
1988
  .fw-root .fw-title-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
1989
1989
  .fw-root .fw-title-glyph { display: inline-flex; color: var(--fw-accent); }
1990
1990
  .fw-root .fw-title { font-size: 14px; line-height: 20px; font-weight: 600; letter-spacing: -.005em; white-space: nowrap; }
1991
- .fw-root .fw-state { display: inline-flex; align-items: center; gap: 8px; height: 20px; padding: 0 8px; border-radius: var(--radius-pill); font-size: 12px; font-weight: 600; color: var(--fw-muted); background: var(--fw-well); flex-shrink: 0; }
1991
+ .fw-root .fw-state { display: inline-flex; align-items: center; gap: 8px; height: 20px; padding: 0 8px; border-radius: var(--radius-pill); font-size: 14px; font-weight: 600; color: var(--fw-muted); background: var(--fw-well); flex-shrink: 0; }
1992
1992
  .fw-root .fw-state::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
1993
1993
  .fw-root .fw-state-live { color: var(--fw-accent); background: color-mix(in oklab, var(--fw-accent) 12%, transparent); }
1994
1994
  .fw-root .fw-state-live::before { animation: fw-pulse 1.6s var(--fw-ease) infinite; }
@@ -2008,15 +2008,15 @@
2008
2008
  .fw-root .fw-summary { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); border-bottom: 1px solid var(--fw-border); }
2009
2009
  .fw-root .fw-summary > div { padding: 12px 16px; min-width: 0; }
2010
2010
  .fw-root .fw-summary > div + div { border-left: 1px solid var(--fw-border); }
2011
- .fw-root .fw-summary dt { font-size: 12px; line-height: 16px; color: var(--fw-muted); }
2011
+ .fw-root .fw-summary dt { font-size: 14px; line-height: 18px; color: var(--fw-muted); }
2012
2012
  .fw-root .fw-value { margin-top: 4px; font-size: 18px; line-height: 24px; font-weight: 600; letter-spacing: -.01em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
2013
2013
  .fw-root .fw-has-errors .fw-value { color: var(--fw-failed); }
2014
2014
  /* Axis */
2015
- .fw-root .fw-axis { display: grid; grid-template-columns: var(--fw-label-col) minmax(0, 1fr); height: 32px; color: var(--fw-muted); font-size: 12px; }
2015
+ .fw-root .fw-axis { display: grid; grid-template-columns: var(--fw-label-col) minmax(0, 1fr); height: 32px; color: var(--fw-muted); font-size: 14px; }
2016
2016
  .fw-root .fw-axis-top { border-bottom: 1px solid var(--fw-border); }
2017
2017
  .fw-root .fw-axis-label { position: relative; display: flex; align-items: center; gap: 8px; padding: 0 12px 0 16px; border-right: 1px solid var(--fw-border); min-width: 0; }
2018
2018
  .fw-root .fw-branch-controls { margin-left: auto; display: flex; gap: 4px; }
2019
- .fw-root .fw-text-button { appearance: none; border: 0; background: transparent; height: 24px; padding: 0 8px; border-radius: var(--radius-sm); font-size: 12px; color: var(--fw-muted); cursor: pointer; white-space: nowrap; }
2019
+ .fw-root .fw-text-button { appearance: none; border: 0; background: transparent; height: 24px; padding: 0 8px; border-radius: var(--radius-sm); font-size: 14px; color: var(--fw-muted); cursor: pointer; white-space: nowrap; }
2020
2020
  .fw-root .fw-text-button:hover { background: var(--fw-hover); color: var(--fw-text); }
2021
2021
  .fw-root .fw-resize { position: absolute; top: 0; right: -4px; width: 8px; height: 100%; cursor: col-resize; z-index: 2; }
2022
2022
  .fw-root .fw-resize:hover, .fw-root .fw-resize:focus-visible { background: linear-gradient(90deg, transparent 3px, var(--fw-accent) 3px 5px, transparent 5px); outline: 0; }
@@ -2044,14 +2044,14 @@
2044
2044
  .fw-root .fw-pause { top: 0; bottom: 0; background: color-mix(in oklab, var(--fw-text) 4%, transparent); border-inline: 1px dashed color-mix(in oklab, var(--fw-text) 18%, transparent); }
2045
2045
  .fw-root .fw-pause-mark { bottom: 3px; height: 6px; border-radius: 2px; cursor: help;
2046
2046
  background: repeating-linear-gradient(-45deg, var(--fw-hatch) 0 1px, transparent 1px 4px); box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--fw-text) 18%, transparent); }
2047
- .fw-root .fw-marker-label { position: absolute; top: 2px; left: 3px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 4px; border-radius: var(--radius-tag); font-size: 12px; line-height: 16px; color: var(--fw-marker); background: var(--fw-surface); box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--fw-marker) 40%, transparent); }
2047
+ .fw-root .fw-marker-label { position: absolute; top: 2px; left: 3px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 4px; border-radius: var(--radius-tag); font-size: 14px; line-height: 18px; color: var(--fw-marker); background: var(--fw-surface); box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--fw-marker) 40%, transparent); }
2048
2048
  .fw-root .fw-marker-label-left { left: auto; right: 3px; }
2049
2049
  .fw-root .fw-marker[data-tone="warn"], .fw-root .fw-event[data-tone="warn"] { --fw-marker: var(--fw-amber); }
2050
2050
  /* The event track: one dot per marker on the axis; click or N/P moves the cursor there. */
2051
2051
  .fw-root .fw-event { --fw-marker: var(--fw-muted); position: absolute; bottom: 2px; width: 8px; height: 8px; margin-left: -4px; padding: 0; border: 0; border-radius: 50%; background: var(--fw-marker); box-shadow: 0 0 0 2px var(--fw-surface); cursor: pointer; z-index: 4; left: calc(var(--fw-pad) + (var(--s) - var(--fw-v0)) * var(--fw-k) * 1px); }
2052
2052
  .fw-root .fw-event[data-tone="ok"] { --fw-marker: var(--fw-ok); }
2053
2053
  .fw-root .fw-event[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--fw-surface), 0 0 0 4px var(--fw-marker); }
2054
- .fw-root .fw-event-label { position: absolute; bottom: 14px; z-index: 5; transform: translateX(-50%); left: calc(var(--fw-pad) + (var(--s) - var(--fw-v0)) * var(--fw-k) * 1px); padding: 0 8px; border-radius: var(--radius-tag); background: var(--fw-surface); box-shadow: inset 0 0 0 1px var(--fw-border); color: var(--fw-text); font-size: 12px; line-height: 20px; white-space: nowrap; pointer-events: none; }
2054
+ .fw-root .fw-event-label { position: absolute; bottom: 14px; z-index: 5; transform: translateX(-50%); left: calc(var(--fw-pad) + (var(--s) - var(--fw-v0)) * var(--fw-k) * 1px); padding: 0 8px; border-radius: var(--radius-tag); background: var(--fw-surface); box-shadow: inset 0 0 0 1px var(--fw-border); color: var(--fw-text); font-size: 14px; line-height: 20px; white-space: nowrap; pointer-events: none; }
2055
2055
  .fw-root .fw-event[data-tone="failed"] { --fw-marker: var(--fw-failed); }
2056
2056
  .fw-root .fw-event:hover, .fw-root .fw-event:focus-visible { transform: scale(1.4); outline: 0; }
2057
2057
  .fw-root .fw-cursor { position: absolute; top: 0; bottom: 0; width: 1px; background: color-mix(in oklab, var(--fw-text) 70%, transparent); left: calc(var(--fw-pad) + (var(--fw-t) - var(--fw-v0)) * var(--fw-k) * 1px); }
@@ -2089,7 +2089,7 @@
2089
2089
  .fw-root .fw-detail { color: var(--fw-muted); overflow: hidden; min-width: 0; display: inline-flex; align-items: center; gap: 4px; max-width: 100%; }
2090
2090
  .fw-root .fw-detail-icon { display: inline-flex; }
2091
2091
  .fw-root .fw-detail-icon :is(svg, img) { width: 12px; height: 12px; }
2092
- .fw-root .fw-count { flex-shrink: 0; height: 18px; padding: 0 8px; border-radius: var(--radius-pill); background: var(--fw-well); border: 1px solid var(--fw-border); color: var(--fw-muted); font-size: 12px; line-height: 16px; font-variant-numeric: tabular-nums; }
2092
+ .fw-root .fw-count { flex-shrink: 0; height: 18px; padding: 0 8px; border-radius: var(--radius-pill); background: var(--fw-well); border: 1px solid var(--fw-border); color: var(--fw-muted); font-size: 14px; line-height: 18px; font-variant-numeric: tabular-nums; }
2093
2093
  .fw-root .fw-alert { display: inline-flex; color: var(--fw-failed); flex-shrink: 0; }
2094
2094
  .fw-root .fw-alert svg { width: 13px; height: 13px; }
2095
2095
  .fw-root .fw-spinner { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid color-mix(in oklab, var(--fw-accent) 30%, transparent); border-top-color: var(--fw-accent); animation: fw-spin .8s linear infinite; flex-shrink: 0; }
@@ -2098,13 +2098,13 @@
2098
2098
  .fw-root .fw-view-agents .fw-names { flex-direction: column; align-items: flex-start; gap: 0; }
2099
2099
  .fw-root .fw-view-agents .fw-span-name { font-weight: 600; line-height: 18px; }
2100
2100
  /* One 16 px line that wraps its last parts out of sight: when the line is full a count drops whole, never "48 …". */
2101
- .fw-root .fw-view-agents .fw-subtitle { display: flex; align-items: center; column-gap: 4px; height: 16px; overflow: hidden; max-width: 100%; min-width: 0; color: var(--fw-muted); font-size: 12px; line-height: 16px; }
2101
+ .fw-root .fw-view-agents .fw-subtitle { display: flex; align-items: center; column-gap: 4px; height: 18px; overflow: hidden; max-width: 100%; min-width: 0; color: var(--fw-muted); font-size: 14px; line-height: 18px; }
2102
2102
  .fw-root .fw-view-agents .fw-subtitle-extra { flex: none; white-space: nowrap; }
2103
2103
  /* Only the tail wraps, so the first part is always on its line and shrinks with an ellipsis; later parts wrap out of sight. */
2104
- .fw-root .fw-view-agents .fw-subtitle-tail { display: flex; flex-wrap: wrap; column-gap: 4px; height: 16px; overflow: hidden; min-width: 0; flex: 0 1 auto; }
2104
+ .fw-root .fw-view-agents .fw-subtitle-tail { display: flex; flex-wrap: wrap; column-gap: 4px; height: 18px; overflow: hidden; min-width: 0; flex: 0 1 auto; }
2105
2105
  .fw-root .fw-view-agents .fw-subtitle-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
2106
2106
  .fw-root .fw-view-agents .fw-detail-icon { flex: none; width: 16px; height: 16px; align-items: center; justify-content: center; overflow: hidden; }
2107
- .fw-root .fw-view-agents .fw-detail { font-size: 12px; line-height: 16px; }
2107
+ .fw-root .fw-view-agents .fw-detail { font-size: 14px; line-height: 18px; }
2108
2108
  .fw-root .fw-agent-dot { flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--line, var(--fw-muted)); }
2109
2109
  /* The dot is outcome only (critique P0 #3): an agent with no recorded outcome gets a hollow ring, never its lane hue. */
2110
2110
  .fw-root .fw-row:not([data-outcome]) .fw-agent-dot:not([data-outcome]) { background: transparent; box-shadow: inset 0 0 0 1.5px var(--fw-muted); }
@@ -2167,7 +2167,7 @@
2167
2167
  .fw-root [data-outcome="failed"], .fw-root [data-outcome="failed"] [data-tone] { --tone: var(--fw-failed); }
2168
2168
  .fw-root [data-outcome="warn"], .fw-root [data-outcome="warn"] [data-tone] { --tone: var(--fw-amber); }
2169
2169
  .fw-root [data-outcome="neutral"], .fw-root [data-outcome="neutral"] [data-tone] { --tone: var(--fw-muted); }
2170
- .fw-root .fw-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 8px 0 0; padding: 0; list-style: none; color: var(--fw-muted); font-size: 12px; line-height: 16px; }
2170
+ .fw-root .fw-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 8px 0 0; padding: 0; list-style: none; color: var(--fw-muted); font-size: 14px; line-height: 18px; }
2171
2171
  .fw-root .fw-legend li { display: inline-flex; align-items: center; gap: 8px; }
2172
2172
  .fw-root .fw-legends { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 24px; margin-top: 8px; }
2173
2173
  .fw-root .fw-legends .fw-legend { margin: 0; }
@@ -2202,7 +2202,7 @@
2202
2202
  .fw-root.fw-fill-agent .fw-view-agents :is(.fw-seg-tool, .fw-seg-failed) { background: light-dark(oklch(from var(--tone) 0.80 min(c, 0.10) h), oklch(from var(--tone) 0.64 min(c, 0.10) h)); box-shadow: none; }
2203
2203
  /* A failed turn is still the agent's work: it keeps the agent's hue, and the red cross on the ending turn says it failed. */
2204
2204
  .fw-root.fw-fill-agent .fw-view-agents .fw-seg-failed { box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--fw-failed) 55%, transparent); }
2205
- .fw-root .fw-view-agents .fw-seg { container-type: inline-size; justify-content: flex-start; font-size: 12px; line-height: 16px; white-space: nowrap; color: var(--fw-seg-ink); }
2205
+ .fw-root .fw-view-agents .fw-seg { container-type: inline-size; justify-content: flex-start; font-size: 14px; line-height: 18px; white-space: nowrap; color: var(--fw-seg-ink); }
2206
2206
  /* Label ink holds 4.5:1 on its fill: page-light on the dark light-theme model step (L 0.50), page-dark on every other step
2207
2207
  (light tool 0.80, dark pastels 0.82 and 0.64). */
2208
2208
  .fw-root .fw-view-agents .fw-seg-model { --fw-seg-ink: light-dark(var(--fw-surface), hsl(var(--hsl-background))); }
@@ -2232,9 +2232,9 @@
2232
2232
  .fw-root .fw-end { z-index: 2; display: inline-flex; align-items: center; gap: 8px; top: calc(50% + var(--fw-bar-shift) - var(--fw-bar-h) / 2); height: var(--fw-bar-h);
2233
2233
  left: min(calc(var(--x0) + max(var(--w), 3px) + 4px), calc(100% - var(--fw-end-w, 0px) - 4px)); padding: 0 4px; border-radius: var(--radius-tag);
2234
2234
  background: linear-gradient(var(--fw-tint, transparent) 0 0), var(--fw-surface); white-space: nowrap; pointer-events: none; }
2235
- .fw-root .fw-duration { font-size: 12px; color: var(--fw-muted); font-variant-numeric: tabular-nums; }
2235
+ .fw-root .fw-duration { font-size: 14px; color: var(--fw-muted); font-variant-numeric: tabular-nums; }
2236
2236
  .fw-root .fw-k-failed ~ .fw-end .fw-duration { color: var(--fw-failed); }
2237
- .fw-root .fw-badge { height: 18px; padding: 0 8px; border-radius: var(--radius-pill); font-size: 12px; line-height: 16px; font-weight: 600; color: var(--fw-amber); background: color-mix(in oklab, var(--fw-amber) 13%, transparent); border: 1px solid color-mix(in oklab, var(--fw-amber) 28%, transparent); }
2237
+ .fw-root .fw-badge { height: 18px; padding: 0 8px; border-radius: var(--radius-pill); font-size: 14px; line-height: 18px; font-weight: 600; color: var(--fw-amber); background: color-mix(in oklab, var(--fw-amber) 13%, transparent); border: 1px solid color-mix(in oklab, var(--fw-amber) 28%, transparent); }
2238
2238
  /* Handoff elbows: 1.5 px stroke, 6 px radius, a 5 px dot where the handoff leaves its sender. */
2239
2239
  /* Under the rows (which follow it), so end labels and badges always sit above the connectors. */
2240
2240
  .fw-root .fw-links { position: absolute; top: 0; bottom: 0; left: var(--fw-label-col); right: 0; overflow: hidden; pointer-events: none; z-index: 0; }
@@ -2266,13 +2266,13 @@
2266
2266
  /* A hover card never covers the next mark: only a pinned card (a dialog) takes the pointer. */
2267
2267
  .fw-root .fw-card[role="tooltip"] { pointer-events: none; }
2268
2268
  .fw-root .fw-card-above .fw-card { transform: translateY(-100%); animation-name: fw-arrive-above; }
2269
- .fw-root .fw-card-agent { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 12px; font-weight: 600; }
2269
+ .fw-root .fw-card-agent { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 14px; font-weight: 600; }
2270
2270
  .fw-root .fw-card-agent .fw-agent-dot { align-self: center; }
2271
2271
  .fw-root .fw-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
2272
2272
  .fw-root .fw-card-head .fw-icon-tile { flex-basis: 28px; width: 28px; height: 28px; border-radius: var(--radius-md); }
2273
2273
  .fw-root .fw-card-head .fw-icon-tile :is(svg, img) { width: 16px; height: 16px; }
2274
2274
  .fw-root .fw-card-name { flex: 1; min-width: 0; font-size: 14px; line-height: 20px; font-weight: 600; overflow-wrap: anywhere; }
2275
- .fw-root .fw-pill { flex-shrink: 0; height: 20px; padding: 0 8px; border-radius: var(--radius-pill); font-size: 12px; line-height: 20px; font-weight: 600; }
2275
+ .fw-root .fw-pill { flex-shrink: 0; height: 20px; padding: 0 8px; border-radius: var(--radius-pill); font-size: 14px; line-height: 20px; font-weight: 600; }
2276
2276
  .fw-root .fw-pill-done { color: var(--fw-ok); background: color-mix(in oklab, var(--fw-ok) 13%, transparent); }
2277
2277
  .fw-root .fw-pill-running { color: var(--fw-accent); background: color-mix(in oklab, var(--fw-accent) 13%, transparent); }
2278
2278
  .fw-root .fw-pill-failed { color: var(--fw-failed); background: color-mix(in oklab, var(--fw-failed) 13%, transparent); }
@@ -2280,9 +2280,9 @@
2280
2280
  .fw-root .fw-icon-button:hover:not(:disabled) { background: var(--fw-hover); color: var(--fw-text); }
2281
2281
  .fw-root .fw-card-close { width: 20px; height: 20px; margin-right: -4px; }
2282
2282
  /* The card's table: label and value on one line each, every value with its unit; a tool breakdown sits under its total. */
2283
- .fw-root .fw-card-table { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; padding-top: 8px; border-top: 1px solid var(--fw-border); font-size: 12px; line-height: 16px; }
2283
+ .fw-root .fw-card-table { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; padding-top: 8px; border-top: 1px solid var(--fw-border); font-size: 14px; line-height: 18px; }
2284
2284
  .fw-root .fw-card-table > div { display: contents; }
2285
- .fw-root .fw-card-table dt, .fw-root .fw-card-label { font-size: 12px; line-height: 16px; color: var(--fw-muted); }
2285
+ .fw-root .fw-card-table dt, .fw-root .fw-card-label { font-size: 14px; line-height: 18px; color: var(--fw-muted); }
2286
2286
  .fw-root .fw-card-table dd { min-width: 0; font-weight: 500; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
2287
2287
  /* A value of several parts wraps between parts, never inside one ("4.0M" / "cached"). */
2288
2288
  .fw-root .fw-card-parts { display: flex; flex-wrap: wrap; column-gap: 4px; }
@@ -2296,7 +2296,7 @@
2296
2296
  .fw-root .fw-card-compact .fw-card-agent { font-size: 14px; line-height: 20px; }
2297
2297
  .fw-root .fw-card-who { min-width: 0; flex: 1; overflow: hidden; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
2298
2298
  .fw-root .fw-pill-outcome { color: var(--line); background: color-mix(in oklab, var(--tone) 16%, transparent); box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--tone) 35%, transparent); }
2299
- .fw-root .fw-card-step { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--fw-border); color: var(--fw-muted); font-size: 12px; line-height: 16px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
2299
+ .fw-root .fw-card-step { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--fw-border); color: var(--fw-muted); font-size: 14px; line-height: 18px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
2300
2300
  .fw-root .fw-card-result { margin-top: 8px; font-size: 14px; line-height: 20px; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
2301
2301
  .fw-root .fw-card-text p { margin-top: 4px; color: var(--fw-text); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
2302
2302
  /* Playback */
@@ -5,7 +5,7 @@ import {
5
5
  outcomeStatus,
6
6
  resolveToolCapabilities,
7
7
  restrictTaxonomy
8
- } from "../chunk-XJ7DC2DI.js";
8
+ } from "../chunk-SK6WU2TI.js";
9
9
  import {
10
10
  DEFAULT_APP_TOOL_PATHS,
11
11
  DEFAULT_HEADER_NAMES,
@@ -24,7 +24,7 @@ import {
24
24
  verifyCapabilityToken,
25
25
  verifyExpiringCapabilityToken
26
26
  } from "../chunk-O7UX55EU.js";
27
- import "../chunk-VKJEH6DG.js";
27
+ import "../chunk-CI6Z2C4L.js";
28
28
  import "../chunk-S5SRJJQG.js";
29
29
  import {
30
30
  APP_TOOL_NAMES,
@@ -33,9 +33,9 @@ import {
33
33
  defineAppTool,
34
34
  findCustomTool,
35
35
  isAppToolName
36
- } from "../chunk-6IMNAZR7.js";
36
+ } from "../chunk-DS3FDGVJ.js";
37
37
  import "../chunk-UGWQLQDS.js";
38
- import "../chunk-E2JMXA2V.js";
38
+ import "../chunk-CGBB2AUP.js";
39
39
  import {
40
40
  ToolInputError
41
41
  } from "../chunk-F4XBNR5L.js";