create-ailk 0.36.0 → 0.37.0

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 (94) hide show
  1. package/component-catalog.json +40 -1
  2. package/component-catalog.md +7 -5
  3. package/dist/surfaces.js +60 -19
  4. package/dist/update.d.ts +19 -1
  5. package/dist/update.js +293 -35
  6. package/package.json +3 -3
  7. package/templates/.env.example +17 -0
  8. package/templates/apps/api/.env.example +38 -0
  9. package/templates/apps/api/CLAUDE.md +3 -0
  10. package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -0
  11. package/templates/apps/mcp/CLAUDE.md +1 -1
  12. package/templates/apps/web/CLAUDE.md +28 -1
  13. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +179 -0
  14. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +22 -2
  15. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +9 -2
  16. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +240 -76
  17. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +242 -28
  18. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +369 -196
  19. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +26 -1
  20. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +17 -6
  21. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +51 -12
  22. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +17 -2
  23. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +153 -2
  24. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +206 -23
  25. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +150 -188
  26. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +235 -177
  27. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +63 -0
  28. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -3
  29. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +340 -0
  30. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +7 -5
  31. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +19 -3
  32. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -4
  33. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +161 -0
  34. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +426 -0
  35. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +76 -0
  36. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +139 -0
  37. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +92 -24
  38. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +32 -1
  39. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +76 -3
  40. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +290 -41
  41. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +109 -11
  42. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +43 -44
  43. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +99 -0
  44. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +123 -0
  45. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +309 -113
  46. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +192 -65
  47. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +52 -7
  48. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +36 -0
  49. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +70 -2
  50. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +42 -0
  51. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +55 -58
  52. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +2 -1
  53. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +73 -0
  54. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +12 -9
  55. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +18 -4
  56. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +20 -2
  57. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +43 -0
  58. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +125 -0
  59. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +88 -0
  60. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +31 -0
  61. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +3 -2
  62. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +33 -8
  63. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +31 -52
  64. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +44 -4
  65. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +69 -49
  66. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +173 -0
  67. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +42 -4
  68. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +102 -0
  69. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +147 -137
  70. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +258 -0
  71. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +18 -21
  72. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +34 -6
  73. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +37 -7
  74. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
  75. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +8 -5
  76. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +3 -2
  77. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +86 -0
  78. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +368 -0
  79. package/templates/apps/web/app/api/auth/hub/password/return.ts +86 -0
  80. package/templates/apps/web/app/api/auth/hub/password/route.ts +171 -0
  81. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +263 -0
  82. package/templates/apps/web/app/api/hub-session/password/return/route.ts +69 -0
  83. package/templates/apps/web/app/api/hub-session/password/route.ts +106 -0
  84. package/templates/apps/web/lib/__tests__/account-config.test.ts +129 -1
  85. package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +33 -0
  86. package/templates/apps/web/lib/account-config.ts +132 -8
  87. package/templates/apps/web/lib/auth-routes.ts +11 -6
  88. package/templates/apps/web/lib/offerings-pricing.ts +4 -1
  89. package/templates/apps/web/messages/en.json +156 -80
  90. package/versions.json +48 -48
  91. package/templates/apps/web/app/[locale]/(authed)/account/components/schedule-service.tsx +0 -276
  92. package/templates/apps/web/app/[locale]/(authed)/account/components/send-message.tsx +0 -128
  93. package/templates/apps/web/app/[locale]/(authed)/account/settings/__tests__/theme-modes.test.ts +0 -42
  94. package/templates/apps/web/app/[locale]/(authed)/account/settings/theme-modes.ts +0 -40
@@ -7,15 +7,25 @@
7
7
  * shape. Renders the shared
8
8
  * `AccountSettings` composition (@working-theory/templates/account, spec
9
9
  * 8339 D4) — the same General form the Admin renders — through the client
10
- * adapter `GeneralSettings` (`profile-form.tsx`). Below the form:
10
+ * adapter `GeneralSettings` (`profile-form.tsx`). Below the form, each a
11
+ * card of the pane (#11167 — the pane draws every direct child as one):
11
12
  *
12
- * - the contact details (`AccountContactDetails`, #8435 D13) — only on the
13
- * member path, seeded from `member.contact` and saved by `saveContact`;
13
+ * - the contact details (`ContactDetails` over `AccountContactDetails`,
14
+ * #8435 D13) — only on the member path, seeded from `member.contact` and
15
+ * saved by `saveContact`, which also derives the account name from the
16
+ * first and last names (#11167 ruling 5 — the member General renders no
17
+ * Name field);
14
18
  * - the phone step (`PhoneVerification`, #11106 D9) — on a hub only: the
15
19
  * person sets and verifies their own number, read from their Better Auth
16
20
  * session; a build without the phone plugin shows the not-available line;
17
21
  * - any section a module contributes (`accountSettingsSections`);
18
- * - `BillingAnchor`, which forwards a `#billing` fragment to Billing.
22
+ * - `BillingAnchor`, which forwards a `#billing` fragment to Billing — it
23
+ * renders nothing, so it sits beside the composition, not in a card.
24
+ *
25
+ * Color mode renders on every site (#11167 ruling 3, as on the Admin); the
26
+ * one-palette gate of #7430 is gone. The Photo and the person's name come
27
+ * from `loadProfileSource` (D3) — on the member path the photo is the hub's
28
+ * (#11167 ruling 4).
19
29
  *
20
30
  * Sign-in moved to Security, cookie settings moved to Notifications then to
21
31
  * Privacy (#8339 C6), and Request account deletion moved to Privacy (#8438
@@ -27,12 +37,11 @@
27
37
 
28
38
  import { member } from "@working-theory/api-client";
29
39
  import {
30
- AccountContactDetails,
31
40
  AccountSettingsFrame,
32
41
  AccountSettingsPane,
33
42
  type AccountContact,
34
43
  } from "@working-theory/templates/account";
35
- import { Separator, Text } from "@working-theory/ui/primitives";
44
+ import { Text } from "@working-theory/ui/primitives";
36
45
  import type { Metadata } from "next";
37
46
  import { headers } from "next/headers";
38
47
  import { getTranslations } from "next-intl/server";
@@ -41,11 +50,10 @@ import type { ReactElement } from "react";
41
50
  import { accountSettingsSections } from "../../../../../lib/account-config";
42
51
  import { readPhoneStep, TOPOLOGY } from "../../../../../lib/topology.generated";
43
52
  import { accountSession } from "../account-data";
44
- import { siteThemeModeCount } from "../settings/theme-modes";
45
53
  import { memberSettingsFrame, SettingsSection, type Translate } from "../settings-frame";
46
54
 
47
55
  import { BillingAnchor } from "./billing-anchor";
48
- import { saveContact } from "./contact-actions";
56
+ import { ContactDetails } from "./contact-details";
49
57
  import { PhoneVerification, type PhoneVerificationLabels } from "./phone-verification";
50
58
  import { GeneralSettings } from "./profile-form";
51
59
  import { loadProfileSource } from "./profile-source";
@@ -128,48 +136,40 @@ export default async function AccountGeneralPage({ params }: Props): Promise<Rea
128
136
  }
129
137
 
130
138
  return (
131
- <GeneralSettings
132
- frame={memberSettingsFrame(locale, t as unknown as Translate, "general")}
133
- user={{ name: ctx.user.name ?? "", email: ctx.user.email, image: source.image }}
134
- labels={{
135
- title: t("settings.general.title"),
136
- lead: t("settings.general.lead"),
137
- colorMode: t("settings.general.colorMode"),
138
- light: t("settings.general.light"),
139
- auto: t("settings.general.auto"),
140
- dark: t("settings.general.dark"),
141
- emailLabel: t("settings.general.email"),
142
- nameLabel: t("settings.general.name"),
143
- photoLabel: t("settings.general.photo"),
144
- photoHint: t("settings.general.photoHint"),
145
- photoPlaceholder: t("settings.general.photoPlaceholder"),
146
- saveButton: t("settings.general.save"),
147
- saving: t("settings.general.saving"),
148
- saved: t("settings.general.saved"),
149
- saveError: t("settings.general.saveError"),
150
- nameRequired: t("settings.general.nameRequired"),
151
- photoInvalid: t("settings.general.photoInvalid"),
152
- unverified: t("settings.general.unverified"),
153
- unavailable: t("settings.general.unavailable"),
154
- }}
155
- colorMode={
156
- siteThemeModeCount() > 1
157
- ? { cookieName: process.env.NEXT_PUBLIC_THEME_COOKIE_NAME ?? "ailk-theme" }
158
- : null
159
- }
160
- via={source.via}
161
- >
162
- {contactRead ? (
163
- <>
164
- <Separator />
139
+ <>
140
+ <GeneralSettings
141
+ frame={memberSettingsFrame(locale, t as unknown as Translate, "general")}
142
+ user={{ name: ctx.user.name ?? "", email: ctx.user.email, image: source.image }}
143
+ labels={{
144
+ title: t("settings.general.title"),
145
+ lead: t("settings.general.lead"),
146
+ colorMode: t("settings.general.colorMode"),
147
+ light: t("settings.general.light"),
148
+ auto: t("settings.general.auto"),
149
+ dark: t("settings.general.dark"),
150
+ emailLabel: t("settings.general.email"),
151
+ nameLabel: t("settings.general.name"),
152
+ photoLabel: t("settings.general.photo"),
153
+ photoPlaceholder: t("settings.general.photoPlaceholder"),
154
+ saveButton: t("settings.general.save"),
155
+ saving: t("settings.general.saving"),
156
+ saved: t("settings.general.saved"),
157
+ saveError: t("settings.general.saveError"),
158
+ nameRequired: t("settings.general.nameRequired"),
159
+ photoInvalid: t("settings.general.photoInvalid"),
160
+ unverified: t("settings.general.unverified"),
161
+ unavailable: t("settings.general.unavailable"),
162
+ }}
163
+ colorMode={{ cookieName: process.env.NEXT_PUBLIC_THEME_COOKIE_NAME ?? "ailk-theme" }}
164
+ via={source.via}
165
+ >
166
+ {contactRead ? (
165
167
  <div data-testid="account-contact-section">
166
168
  {contactRead.ok ? (
167
- <AccountContactDetails
169
+ <ContactDetails
168
170
  contact={contactRead.contact}
169
- onSave={saveContact}
170
171
  labels={{
171
172
  title: t("settings.general.contact.title"),
172
- lead: t("settings.general.contact.lead"),
173
173
  givenName: t("settings.general.contact.givenName"),
174
174
  familyName: t("settings.general.contact.familyName"),
175
175
  telephone: t("settings.general.contact.telephone"),
@@ -197,25 +197,22 @@ export default async function AccountGeneralPage({ params }: Props): Promise<Rea
197
197
  </span>
198
198
  )}
199
199
  </div>
200
- </>
201
- ) : null}
202
- {phoneStep ? (
203
- <>
204
- <Separator />
200
+ ) : null}
201
+ {phoneStep ? (
205
202
  <PhoneVerification
206
203
  available={phoneStep.available}
207
204
  emailVerified={ctx.user.emailVerified}
208
205
  phone={phoneStep.phone}
209
206
  labels={phoneLabels}
210
207
  />
211
- </>
212
- ) : null}
213
- {accountSettingsSections.map((section) => (
214
- <SettingsSection key={section.id} id={section.id} title={ctx.t(section.title)}>
215
- {section.render(ctx)}
216
- </SettingsSection>
217
- ))}
208
+ ) : null}
209
+ {accountSettingsSections.map((section) => (
210
+ <SettingsSection key={section.id} id={section.id} title={ctx.t(section.title)}>
211
+ {section.render(ctx)}
212
+ </SettingsSection>
213
+ ))}
214
+ </GeneralSettings>
218
215
  <BillingAnchor locale={locale} />
219
- </GeneralSettings>
216
+ </>
220
217
  );
221
218
  }
@@ -197,7 +197,8 @@ export function PhoneVerification({
197
197
 
198
198
  return (
199
199
  <section className="flex flex-col gap-3" data-testid="account-phone-section" aria-labelledby="account-phone-title">
200
- <Heading level={3} visual={4} id="account-phone-title">
200
+ {/* A level-2 heading: one group of the pane, beside Contact details (#11167 ruling 11). */}
201
+ <Heading level={2} visual={4} id="account-phone-title">
201
202
  {labels.title}
202
203
  </Heading>
203
204
  <Text as="p" variant="body-sm" tone="muted">
@@ -0,0 +1,73 @@
1
+ "use server";
2
+
3
+ /**
4
+ * general/photo-actions.ts — User settings › General's photo write on the
5
+ * member path (#11167 ruling 5).
6
+ *
7
+ * The member General renders no Name field: the account name follows the
8
+ * contact's first and last names (`contact-actions.ts`), so the profile form
9
+ * saves the photo alone — `member.updateProfile({ image })`, `PATCH
10
+ * /v1/member/profile` with no `name` key, so a person who has not set a name
11
+ * yet can still set their photo. `null` (or a blank link) clears it. The
12
+ * session is not re-sealed: a hub session carries no photo (`profile-source.ts`
13
+ * reads it from the member API instead).
14
+ *
15
+ * It sends `forwardedCookieInit()`'s init, as `profile-actions.ts`'s
16
+ * `saveProfile` does, and maps the same refusals: `photo` (`400
17
+ * link_not_https`), `unverified` (`403`), `unavailable` (`404`, `503`), else
18
+ * `failed`. Logs carry a status or `err.name` only — never a link.
19
+ *
20
+ * Not a `*.actions.ts` file and no `*Action`-suffixed export: the write has no
21
+ * MCP twin by decision (8170's header), and apps/mcp's parity test reads that
22
+ * suffix.
23
+ */
24
+
25
+ import { member } from "@working-theory/api-client";
26
+
27
+ import { forwardedCookieInit } from "../../../../../lib/server-api";
28
+
29
+ /** PII-safe error identity for logs (the `profile-actions.ts` idiom: `err.name` only). */
30
+ function errorName(err: unknown): string {
31
+ return err instanceof Error ? err.name : "unknown";
32
+ }
33
+
34
+ /** The `error.code` of a member write's refusal body, when it has one. */
35
+ function errorCode(body: unknown): string | null {
36
+ if (typeof body !== "object" || body === null) return null;
37
+ const error = (body as { error?: unknown }).error;
38
+ if (typeof error !== "object" || error === null) return null;
39
+ const code = (error as { code?: unknown }).code;
40
+ return typeof code === "string" ? code : null;
41
+ }
42
+
43
+ export type SavePhotoResult =
44
+ | { ok: true; image: string | null }
45
+ | { ok: false; reason: "photo" | "unverified" | "unavailable" | "failed" };
46
+
47
+ /** Saves the member's photo alone: `null` or a blank link clears it. */
48
+ export async function savePhoto(
49
+ image: string | null,
50
+ ): Promise<SavePhotoResult> {
51
+ // Action input is untrusted: anything but a string or null is refused,
52
+ // never read as "clear the photo".
53
+ if (image !== null && typeof image !== "string")
54
+ return { ok: false, reason: "photo" };
55
+ try {
56
+ const res = await member.updateProfile(
57
+ { image: image?.trim() || null },
58
+ await forwardedCookieInit(),
59
+ );
60
+ if (res.ok) return { ok: true, image: res.body.image };
61
+ console.error(`[photo-actions] savePhoto status=${res.status}`);
62
+ if (res.status === 400 && errorCode(res.body) === "link_not_https") {
63
+ return { ok: false, reason: "photo" };
64
+ }
65
+ if (res.status === 403) return { ok: false, reason: "unverified" };
66
+ if (res.status === 404 || res.status === 503)
67
+ return { ok: false, reason: "unavailable" };
68
+ return { ok: false, reason: "failed" };
69
+ } catch (err) {
70
+ console.error(`[photo-actions] savePhoto errName=${errorName(err)}`);
71
+ return { ok: false, reason: "failed" };
72
+ }
73
+ }
@@ -10,9 +10,10 @@
10
10
  * this file supplies `profile` and `onSave` from `via` (General's
11
11
  * `loadProfileSource`, D3):
12
12
  *
13
- * - `member` — `saveProfile` (`PATCH /v1/member/profile`, D6). `image` is
14
- * sent only when the photo field changed (an untouched field never
15
- * clears a photo, 8232 D4/D6); a refusal keeps both fields as typed.
13
+ * - `member` — no Name field (#11167 ruling 5: the account name follows
14
+ * the contact's first and last names, `contact-actions.ts`), so the form
15
+ * saves the photo alone through `savePhoto` (`PATCH /v1/member/profile`
16
+ * with `image` only); a refusal keeps the field as typed.
16
17
  * - `session` — a build with no member API: the name saves through
17
18
  * Better Auth's own `updateUser`, and no photo field shows
18
19
  * (`profile="name-only"`).
@@ -33,7 +34,7 @@ import { createAuthClient } from "better-auth/react";
33
34
  import { useRouter } from "next/navigation";
34
35
  import type { ReactElement, ReactNode } from "react";
35
36
 
36
- import { saveProfile } from "../profile-actions";
37
+ import { savePhoto } from "./photo-actions";
37
38
 
38
39
  const authClient = createAuthClient();
39
40
 
@@ -75,18 +76,19 @@ export function GeneralSettings({
75
76
  router.refresh();
76
77
  return { ok: true };
77
78
  }
78
- const res = await saveProfile(imageChanged ? { name, image } : { name });
79
+ // The member path saves the photo alone; `name` is the account's as it
80
+ // stands and never written here. Only a changed photo reaches here (Save
81
+ // is disabled otherwise), so the untouched-field rule (8232 D4/D6) holds.
82
+ if (!imageChanged) return { ok: true };
83
+ const res = await savePhoto(image);
79
84
  if (!res.ok) {
80
85
  if (res.reason === "photo") return { ok: false, field: "photo", message: labels.photoInvalid };
81
- if (res.reason === "required") return { ok: false, field: "name", message: labels.nameRequired };
82
86
  if (res.reason === "unverified") return { ok: false, message: labels.unverified };
83
87
  if (res.reason === "unavailable") return { ok: false, message: labels.unavailable };
84
88
  return { ok: false, message: labels.saveError };
85
89
  }
86
90
  router.refresh();
87
- // exactOptionalPropertyTypes: omit `name` entirely rather than set it to
88
- // `undefined` — AccountSaveResult's `name?: string` has no `undefined` value.
89
- return { ok: true, image: res.image, ...(res.name !== null ? { name: res.name } : {}) };
91
+ return { ok: true, image: res.image };
90
92
  }
91
93
 
92
94
  return (
@@ -96,6 +98,7 @@ export function GeneralSettings({
96
98
  labels={labels}
97
99
  colorMode={colorMode}
98
100
  profile={via === "member" ? "editable" : via === "session" ? "name-only" : "read-only"}
101
+ nameField={via !== "member"}
99
102
  {...(via === "none" ? {} : { onSave })}
100
103
  >
101
104
  {children}
@@ -23,9 +23,12 @@
23
23
  * A 404 is a module-presence test, as `read()` in `lib/account-config.ts`
24
24
  * already makes; this file names no topology constant itself.
25
25
  *
26
- * `image` — the session's photo, which Better Auth's session carries at run
27
- * time though the generated `SiteSession` type does not declare it. A hub
28
- * session carries none (C5), so on a spoke the form starts empty.
26
+ * `image` — on the `member` path, the photo the member API holds for the
27
+ * caller's own row (`GET /v1/member/profile`, #11167): a spoke's hub session
28
+ * carries no photo, and this is how the Admin's Google photo reaches the
29
+ * spoke's General. A failed or refused read falls back to the session's photo,
30
+ * which Better Auth's session carries at run time though the generated
31
+ * `SiteSession` type does not declare it (a hub session carries none, C5).
29
32
  */
30
33
 
31
34
  import { member } from "@working-theory/api-client";
@@ -59,6 +62,16 @@ async function memberApiAnswers(ctx: AccountContext): Promise<boolean> {
59
62
  }
60
63
  }
61
64
 
65
+ /** The caller's stored photo, or `null` when the read fails or holds none. */
66
+ async function memberImage(ctx: AccountContext): Promise<string | null> {
67
+ try {
68
+ const res = await member.profile(ctx.init);
69
+ return res.ok ? res.body.image?.trim() || null : null;
70
+ } catch {
71
+ return null;
72
+ }
73
+ }
74
+
62
75
  export const loadProfileSource = cache(async (ctx: AccountContext): Promise<ProfileSource> => {
63
76
  // The photo is optional: a failed session read starts the field empty
64
77
  // rather than failing the page.
@@ -69,5 +82,6 @@ export const loadProfileSource = cache(async (ctx: AccountContext): Promise<Prof
69
82
  .catch(() => null),
70
83
  ]);
71
84
  const via = answers ? "member" : signInMethod().kind === "site" ? "session" : "none";
72
- return { via, image: sessionImage(session) };
85
+ const image = (via === "member" ? await memberImage(ctx) : null) ?? sessionImage(session);
86
+ return { via, image };
73
87
  });
@@ -12,6 +12,9 @@
12
12
  * #11007 — a conversation kind (`accountChatKinds`: a message) renders
13
13
  * through the frame's chat layout — RecordHeader over the message as a
14
14
  * start-side bubble; every other kind keeps the stacked head and fields.
15
+ * #11152 — such a kind's item also links to the member thread page
16
+ * (`../../thread`, Open conversation), first among its actions: the whole
17
+ * exchange, with the composer, is one step away from any one message.
15
18
  *
16
19
  * An unknown kind, or an id the kind did not load, is a not-found — never an
17
20
  * empty frame. A failed read is not a not-found: it renders an error with
@@ -82,6 +85,21 @@ export default async function AccountInboxItemPage({ params }: Props): Promise<R
82
85
  if (!item) notFound();
83
86
 
84
87
  const detail = kind.renderDetail(item, session.ctx);
88
+ const chat = accountChatKinds.has(kind.kind);
89
+ // #11152 — a conversation kind's item opens the thread; the kind's own actions follow.
90
+ const actions = [
91
+ ...(chat
92
+ ? [
93
+ {
94
+ key: "thread",
95
+ label: t("thread.open"),
96
+ variant: "outline" as const,
97
+ href: localeHref(locale, "/account/inbox/thread"),
98
+ },
99
+ ]
100
+ : []),
101
+ ...(detail.actions ?? []),
102
+ ];
85
103
 
86
104
  return (
87
105
  <InboxItemFrame
@@ -90,9 +108,9 @@ export default async function AccountInboxItemPage({ params }: Props): Promise<R
90
108
  title={item.title}
91
109
  lead={detail.lead}
92
110
  status={detail.status}
93
- {...(detail.actions ? { actions: detail.actions } : {})}
111
+ {...(actions.length > 0 ? { actions } : {})}
94
112
  fields={detail.fields}
95
- {...(accountChatKinds.has(kind.kind) ? { layout: "chat" as const } : {})}
113
+ {...(chat ? { layout: "chat" as const } : {})}
96
114
  testIdPrefix="account-item"
97
115
  >
98
116
  {detail.body}
@@ -0,0 +1,43 @@
1
+ "use client"; // binds the shared composer to the member write and the route refresh
2
+
3
+ /**
4
+ * MemberThreadComposer — the member thread page's composer (#11152): the
5
+ * shared `ThreadComposer` (`@working-theory/templates/account`, the control
6
+ * the Admin's inbox thread shares) bound to `postThreadMessage` and to the
7
+ * router. A sent message refreshes the route, so the page's Server
8
+ * Components read the thread again and the new bubble appears with no
9
+ * reload (the New menu's own idiom after a post); a refusal shows the plain
10
+ * line its code maps to, with the body kept. Only strings cross to the
11
+ * client: the labels and the refusal lines, never the session.
12
+ */
13
+
14
+ import { ThreadComposer, type ThreadComposerLabels } from "@working-theory/templates/account";
15
+ import { MESSAGE_BODY_MAX } from "@working-theory/validation";
16
+ import { useRouter } from "next/navigation";
17
+ import type { ReactElement } from "react";
18
+
19
+ import type { NewActionErrorCode } from "../../new-actions";
20
+
21
+ import { postThreadMessage } from "./thread-write";
22
+
23
+ export interface MemberThreadComposerProps {
24
+ labels: ThreadComposerLabels;
25
+ /** Each refusal code's plain line (`new.errors.*`). */
26
+ errors: Record<NewActionErrorCode, string>;
27
+ }
28
+
29
+ export function MemberThreadComposer({ labels, errors }: MemberThreadComposerProps): ReactElement {
30
+ const router = useRouter();
31
+ return (
32
+ <ThreadComposer
33
+ labels={labels}
34
+ maxLength={MESSAGE_BODY_MAX}
35
+ send={async (body) => {
36
+ const state = await postThreadMessage(body);
37
+ if (state.kind === "success") return { kind: "sent" };
38
+ return { kind: "refused", message: errors[state.kind === "error" ? state.code : "failed"] };
39
+ }}
40
+ onSent={() => router.refresh()}
41
+ />
42
+ );
43
+ }
@@ -0,0 +1,125 @@
1
+ /**
2
+ * /[locale]/account/inbox/thread — the member's conversation with the
3
+ * workspace (#11152; operator ruling 2026-11-08).
4
+ *
5
+ * RSC, inside the account layout's SignedInShell (the rail keeps Inbox
6
+ * selected under /account/inbox/…). The Admin reads a client's exchange as
7
+ * one per-person thread page; the member gets the same page shape, through
8
+ * the same shared pieces (`@working-theory/templates/account`): the Record
9
+ * frame — `InboxItemFrame layout="chat"`, its `RecordHeader` titled
10
+ * Messages with the back link to the Inbox's Messages tab — over every
11
+ * message between this person and the workspace, OLDEST FIRST, each the
12
+ * bubble its own Inbox kind renders (`renderDetail`: the provider's messages
13
+ * on the start side, the member's own sent requests and messages on the
14
+ * end), a message's own actions (a file's Download, Open onboarding) under
15
+ * its bubble, and the shared `ThreadComposer` pinned at the foot
16
+ * (`member-thread-composer.tsx`): one field, Send, the existing member
17
+ * message write. The New menu's Send message navigates here (#11152 AC-1);
18
+ * the lightbox it opened is retired. One stream per (person, workspace):
19
+ * `thread-data.ts` records the decision.
20
+ *
21
+ * An empty thread reads the empty line above the composer; a kind's failed
22
+ * read renders the error row with Retry above what did load (D12's
23
+ * posture); signed out is a not-found (the layout's gate renders in the
24
+ * page's place).
25
+ */
26
+
27
+ import { InboxItemFrame, type InboxItemAction } from "@working-theory/templates/account";
28
+ import { localeHref } from "@working-theory/ui";
29
+ import { Button, Link, Text } from "@working-theory/ui/primitives";
30
+ import type { Metadata } from "next";
31
+ import { notFound } from "next/navigation";
32
+ import { getTranslations } from "next-intl/server";
33
+ import type { ReactElement } from "react";
34
+
35
+ import { accountSession } from "../../account-data";
36
+ import { ErrorRow } from "../../error-row";
37
+ import { newActionErrorLabels } from "../../new-popups";
38
+
39
+ import { MemberThreadComposer } from "./member-thread-composer";
40
+ import { loadThread } from "./thread-data";
41
+
42
+ interface Props {
43
+ params: Promise<{ locale: string }>;
44
+ }
45
+
46
+ export async function generateMetadata({ params }: Props): Promise<Metadata> {
47
+ const { locale } = await params;
48
+ const t = await getTranslations({ locale, namespace: "account" });
49
+ return { title: t("thread.title") };
50
+ }
51
+
52
+ /** A bubble's own action, as a small link under it; an RSC detail carries `href` actions only. */
53
+ function EntryAction({ action }: { action: InboxItemAction }): ReactElement | null {
54
+ if (action.href === undefined) return null;
55
+ return (
56
+ <Button asChild variant={action.variant} size="thin">
57
+ <Link href={action.href} variant="bare" data-testid={`account-thread-action-${action.key}`}>
58
+ {action.label}
59
+ </Link>
60
+ </Button>
61
+ );
62
+ }
63
+
64
+ export default async function AccountThreadPage({ params }: Props): Promise<ReactElement> {
65
+ const { locale } = await params;
66
+ const t = await getTranslations({ locale, namespace: "account" });
67
+ const session = await accountSession(locale);
68
+ if (!session) notFound();
69
+
70
+ const { entries, failed } = await loadThread(session.ctx);
71
+ // The refusal lines the composer shows, keyed on `sendMessage`'s codes — the popups' own map.
72
+ const errors = newActionErrorLabels(session.ctx.t);
73
+
74
+ return (
75
+ <InboxItemFrame
76
+ layout="chat"
77
+ back={{ href: localeHref(locale, "/account?tab=messages"), label: t("inbox.back") }}
78
+ caption={t("thread.title")}
79
+ title={t("thread.title")}
80
+ testIdPrefix="account-thread"
81
+ composer={
82
+ <MemberThreadComposer
83
+ labels={{
84
+ label: t("thread.composer.label"),
85
+ body: t("thread.composer.body"),
86
+ placeholder: t("thread.composer.placeholder"),
87
+ send: t("thread.composer.send"),
88
+ sending: t("thread.composer.sending"),
89
+ sent: t("thread.composer.sent"),
90
+ needsContent: t("thread.composer.needsContent"),
91
+ failed: t("new.errors.failed"),
92
+ }}
93
+ errors={errors}
94
+ />
95
+ }
96
+ >
97
+ {failed ? <ErrorRow message={t("thread.error")} retryLabel={t("inbox.retry")} /> : null}
98
+ {!failed && entries.length === 0 ? (
99
+ <Text as="p" variant="body-sm" tone="muted" data-testid="account-thread-empty">
100
+ {t("thread.empty")}
101
+ </Text>
102
+ ) : null}
103
+ {entries.map(({ kind, item }) => {
104
+ const detail = kind.renderDetail(item, session.ctx);
105
+ return (
106
+ <div
107
+ key={`${kind.kind}:${item.id}`}
108
+ className="flex flex-col gap-2"
109
+ data-testid="account-thread-entry"
110
+ data-kind={kind.kind}
111
+ >
112
+ {detail.body}
113
+ {detail.actions && detail.actions.length > 0 ? (
114
+ <div className="flex flex-wrap gap-2">
115
+ {detail.actions.map((action) => (
116
+ <EntryAction key={action.key} action={action} />
117
+ ))}
118
+ </div>
119
+ ) : null}
120
+ </div>
121
+ );
122
+ })}
123
+ </InboxItemFrame>
124
+ );
125
+ }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * thread-data.ts — the member thread page's reads (#11152).
3
+ *
4
+ * The thread is every message between the signed-in person and this
5
+ * workspace: the conversation kinds of `lib/account-config.ts`
6
+ * (`accountChatKinds`) — the provider's messages (`message`,
7
+ * `GET /v1/member/messages`) and the person's own sent requests and messages
8
+ * (`request`, `GET /v1/member/requests`) — merged and sorted OLDEST FIRST,
9
+ * the Admin thread's order, each entry keeping the kind that loaded it so
10
+ * the page renders the same bubble the item page shows. A kind's rejected
11
+ * read sets `failed` (D12: the page shows the error row above what did
12
+ * load, never a silently partial thread); a 404 is already `[]` inside the
13
+ * kind's own `load`.
14
+ *
15
+ * One stream per (person, workspace) — the design decision this page rests
16
+ * on (issue #11152, operator question of 2026-11-08, recorded here because
17
+ * the issue carries no spec): the data model keys every message on exactly
18
+ * that pair (`Interaction` rows on the person's `Person` in this workspace;
19
+ * the member reads above resolve the pair from the credential), and the
20
+ * Admin's thread page is one stream per person. A second stream would need
21
+ * a new subject entity on both sides — a thread id stamped on each
22
+ * `Interaction`, a member read and write that take it, an Admin thread list
23
+ * and page keyed on it — and is not this page's.
24
+ *
25
+ * `threadSubject` — the member composer has one field, no Subject (#11007's
26
+ * composer shape), yet `POST /v1/member/messages` requires one: the subject
27
+ * is cut from the body's first non-blank line, whitespace collapsed and
28
+ * clipped to the server's cap. A blank body yields `""`, which the server
29
+ * refuses — the composer never posts a blank body.
30
+ */
31
+
32
+ import type {
33
+ AccountContext,
34
+ AccountInboxItem,
35
+ AccountInboxKind,
36
+ } from "@working-theory/templates/account";
37
+ import { MESSAGE_SUBJECT_MAX } from "@working-theory/validation";
38
+
39
+ import { accountChatKinds, accountInboxKinds } from "../../../../../../lib/account-config";
40
+ import { logReadFailure } from "../../account-data";
41
+
42
+ /** One loaded message with the kind it came from — what a bubble is built from. */
43
+ export interface ThreadEntry {
44
+ kind: AccountInboxKind;
45
+ item: AccountInboxItem;
46
+ }
47
+
48
+ export interface LoadedThread {
49
+ /** Oldest first. */
50
+ entries: ThreadEntry[];
51
+ /** True when a kind's read rejected (D12). */
52
+ failed: boolean;
53
+ }
54
+
55
+ /** The conversation kinds, in the config's order. */
56
+ const threadKinds = accountInboxKinds.filter((kind) => accountChatKinds.has(kind.kind));
57
+
58
+ // Both conversation kinds set `at` from the row's `createdAt`; the `""`
59
+ // fallback (an entry with no time sorts first) is `account-data.ts`'s idiom,
60
+ // kept so a kind that omitted it would still render rather than throw.
61
+ const oldestFirst = (a: ThreadEntry, b: ThreadEntry): number =>
62
+ (a.item.at ?? "").localeCompare(b.item.at ?? "");
63
+
64
+ /** Every conversation kind's items, oldest first. A rejected kind sets `failed`. */
65
+ export async function loadThread(ctx: AccountContext): Promise<LoadedThread> {
66
+ const settled = await Promise.allSettled(
67
+ threadKinds.map(async (kind) => (await kind.load(ctx)).map((item) => ({ kind, item }))),
68
+ );
69
+ settled.forEach((r, i) => {
70
+ if (r.status === "rejected") logReadFailure(`thread:${threadKinds[i]!.kind}`, r.reason);
71
+ });
72
+ return {
73
+ entries: settled
74
+ .flatMap((r) => (r.status === "fulfilled" ? r.value : []))
75
+ .sort(oldestFirst),
76
+ failed: settled.some((r) => r.status === "rejected"),
77
+ };
78
+ }
79
+
80
+ /** The subject the member write needs, cut from the body's first non-blank line. */
81
+ export function threadSubject(body: string): string {
82
+ const line =
83
+ body
84
+ .split(/\r?\n/)
85
+ .map((part) => part.replace(/\s+/g, " ").trim())
86
+ .find((part) => part !== "") ?? "";
87
+ return line.slice(0, MESSAGE_SUBJECT_MAX);
88
+ }