copilotz 1.0.0-rc.36 → 1.0.0-rc.37

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 (31) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +1 -1
  3. package/hosts/web/host.js +18 -17
  4. package/hosts/web/session.d.ts +27 -1
  5. package/hosts/web/session.js +34 -0
  6. package/package.json +1 -1
  7. package/plugins/access/email/shared/people.d.ts +2 -1
  8. package/plugins/access/email/shared/people.js +3 -2
  9. package/plugins/access/google/actions/sign-in.js +2 -1
  10. package/plugins/access/identity/actions/person.d.ts +7 -0
  11. package/plugins/access/identity/actions/person.js +38 -2
  12. package/plugins/access/identity/collections/person.d.ts +9 -0
  13. package/plugins/access/identity/collections/person.js +2 -0
  14. package/plugins/access/identity/mod.d.ts +3 -1
  15. package/plugins/access/identity/mod.js +5 -2
  16. package/plugins/agents/chat/views/web/home.js +2 -1
  17. package/plugins/compute/computers/program/version.d.ts +1 -1
  18. package/plugins/compute/computers/program/version.js +1 -1
  19. package/plugins/compute/computers/resources/downloads.js +1 -1
  20. package/plugins/interfaces/web/mod.d.ts +3 -1
  21. package/plugins/interfaces/web/mod.js +3 -1
  22. package/plugins/interfaces/web/shared/style.d.ts +3 -2
  23. package/plugins/interfaces/web/shared/style.js +9 -2
  24. package/plugins/interfaces/web/views/frame.d.ts +4 -2
  25. package/plugins/interfaces/web/views/frame.js +2 -2
  26. package/plugins/interfaces/web/views/me.d.ts +15 -7
  27. package/plugins/interfaces/web/views/me.js +83 -22
  28. package/plugins/interfaces/web/views/shell.js +2 -1
  29. package/plugins/interfaces/web/views/words.d.ts +1 -1
  30. package/plugins/interfaces/web/views/words.js +10 -1
  31. package/runtime/define.d.ts +3 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,33 @@
1
+ ## 1.0.0-rc.37 — 2026-11-10
2
+
3
+ **Upgrading.** The web shell says nine new words, which an app in another language gives under
4
+ `shell.<key>` (its words test names any it lacks): `yourName` ("Your name"), `addYourName` ("Add
5
+ your name"), `nameAbout` ("How people and agents here see you."), `nameLabel` ("Name"), `nameEmpty`
6
+ ("Leave it empty to go by your email."), `nameNotSaved` ("Your name wasn't saved. {reason}"),
7
+ `nameTryAgain` ("Your name wasn't saved. Try again in a moment."), `cancel` ("Cancel") and `save`
8
+ ("Save").
9
+
10
+ - **A person names themselves** (`person.rename` `{ name }`, identity's). Only a person, for
11
+ themselves, in person: never a contact, a key, an agent or a routine, and there's no one else to
12
+ name. The name is one line (spaces, tabs and breaks in a row are one space), trimmed, 80
13
+ characters at most (said plainly past that); empty, it's cleared, and they have none. It's what
14
+ everyone sees of them: their menu, home's greeting, the people beside them in a space, agents'
15
+ prompts (the spaces plugin's profile follows it, else their email's name, as before).
16
+ - **Sign-ins keep the name a person chose,** or their having none: Google's sign-in, email's, and
17
+ the system's `person.set` (a directory's handoff into an org) no longer set it back. Until a
18
+ person chooses (their record's `named`: when they last did), sign-ins keep their name current as
19
+ before.
20
+ - **The person's menu opens with their name,** "Your name" ("Add your name" with none), in a dialog:
21
+ the field holds it, selected, so typing replaces it; Enter saves; a live preview shows how they'll
22
+ appear; while it saves the field waits; a refusal is said under it and the dialog stays. So the
23
+ menu is always a menu now, with or without front ends' entries.
24
+ - **The new name shows at once, everywhere, without reloading:** in this tab and their others. The
25
+ web host keeps the page's viewer as the person's own record says (it watches it: their name and
26
+ email), and draws again when it changes; Views read it as before (`ctx.viewer.label`).
27
+ - **No name, no id:** with none, the menu shows the person's email (`ctx.viewer.email`, new, from
28
+ identity's `/me`), and home greets them plainly ("Good morning"). An app whose ids aren't names
29
+ (`01JD3X…`) showed the id in both.
30
+
1
31
  ## 1.0.0-rc.36 — 2026-11-10
2
32
 
3
33
  **Upgrading.** Chat has two tools of its own, `list_conversations` and `read_conversation`, for the
package/README.md CHANGED
@@ -162,7 +162,7 @@ OPENAI_API_KEY=sk-… node salon.ts # or bun salon.ts, or deno run -A salon.t
162
162
  ```
163
163
 
164
164
  On Deno, map the name `copilotz` in `deno.json`
165
- (`"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.36"`) so the imports read the same everywhere.
165
+ (`"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.37"`) so the imports read the same everywhere.
166
166
  Copilotz runs on Node, Deno and Bun, and it's built on web standards for Cloudflare Workers and the
167
167
  browser.
168
168
 
package/hosts/web/host.js CHANGED
@@ -8,6 +8,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
8
  * React, each part a component redrawn on its own. Where you are is the address: links are
9
9
  * followed without reloading, back and forward work, two tabs differ. The
10
10
  * connection is kept for `LazyView`, which observes a View on demand.
11
+ * Whom Views are shown to (`ctx.viewer`) is the person, by their name and
12
+ * email (identity's `GET /me`, asked while the ticket is), kept as their own
13
+ * record says: they rename themselves, here or in another tab, and the page
14
+ * draws again with the new name, without reloading.
11
15
  *
12
16
  * The page takes the app's theme from the first (signing in included): the
13
17
  * front ends' `theme` resources merged over the defaults, as CSS variables
@@ -27,7 +31,7 @@ import { createRoot } from "react-dom/client";
27
31
  import { connect } from "../../runtime/client.js";
28
32
  import { registerWorker } from "./install.js";
29
33
  import { Part } from "./part.js";
30
- import { session } from "./session.js";
34
+ import { followViewer, session, viewerOf } from "./session.js";
31
35
  import { SignIn } from "./signin.js";
32
36
  import { inviteOf } from "./signin-email.js";
33
37
  import { signInPageOf } from "./signin-words.js";
@@ -91,13 +95,12 @@ async function ticket() {
91
95
  return undefined;
92
96
  return await answered(response, "couldntConnect");
93
97
  }
94
- /** What the person signed in is shown as: their name (identity's `/me`), else nothing. */
95
- async function nameOf() {
98
+ /** What identity's `/me` says the person signed in is shown as; nothing, for anyone else. */
99
+ async function shownOf() {
96
100
  const response = await fetch(`${config().base ?? ""}/me`).catch(() => undefined);
97
101
  if (!response?.ok)
98
- return undefined;
99
- const me = await response.json().catch(() => null);
100
- return typeof me?.name === "string" && me.name ? me.name : undefined;
102
+ return {};
103
+ return await response.json().catch(() => null) ?? {};
101
104
  }
102
105
  /**
103
106
  * The ways to sign in the app has, by what its routes answer: Google's, with
@@ -155,15 +158,15 @@ export async function web(options) {
155
158
  }
156
159
  if (options.arrive)
157
160
  await arriving(options.arrive);
158
- // Their name, asked while the ticket is: a person's, as they signed in.
159
- const named = options.arrive ? Promise.resolve(undefined) : nameOf();
161
+ // Their name and email, asked while the ticket is: a person's, as they signed in.
162
+ const named = options.arrive ? Promise.resolve({}) : shownOf();
160
163
  const first = await ticket();
161
164
  if (!first) {
162
165
  draw(_jsx(SignIn, { signIn: await waysToSignIn(), page: signInPageOf(options.plugins) }));
163
166
  return undefined;
164
167
  }
165
168
  const person = first.actor.kind === "person";
166
- const name = person ? await named : undefined;
169
+ const me = person ? await named : {};
167
170
  let fresh = first.ticket;
168
171
  const url = options.url ??
169
172
  `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}${config().base ?? ""}/oxian`;
@@ -183,14 +186,9 @@ export async function web(options) {
183
186
  plugins: options.plugins,
184
187
  });
185
188
  await client.ready;
186
- // Who they are (a person by their id; a contact as messages name it), and their name.
187
- const viewer = {
188
- kind: first.actor.kind,
189
- name: person ? first.actor.id : `${first.actor.kind}:${first.actor.id}`,
190
- ...(name ? { label: name } : {}),
191
- };
189
+ // Who they are (a person by their id; a contact as messages name it), their name and email.
192
190
  session.client = client;
193
- session.viewer = viewer;
191
+ session.viewer = viewerOf(first.actor, me);
194
192
  let space = (await options.start?.(client, first.actor))?.space;
195
193
  let shown;
196
194
  const show = () => {
@@ -208,7 +206,7 @@ export async function web(options) {
208
206
  const [kind, ...rest] = location.pathname.split("/").filter(Boolean).map(decodeURIComponent);
209
207
  const here = kind === "space" && rest.length ? rest.join("/") : space;
210
208
  const shell = client.observe("web.shell", where, {
211
- viewer,
209
+ viewer: session.viewer,
212
210
  ...(here ? { actor: { ...first.actor, in: here } } : {}),
213
211
  part: (part, key) => _jsx(Part, { part: part }, key),
214
212
  });
@@ -234,5 +232,8 @@ export async function web(options) {
234
232
  go(link.pathname + link.search);
235
233
  });
236
234
  show();
235
+ // Renamed (here, or in another tab), every View draws again with their name as it is now.
236
+ if (person)
237
+ followViewer(client, first.actor, show);
237
238
  return client;
238
239
  }
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * The page's connection, once `web()` has made it: the client, and whom it
3
- * shows Views to. What `LazyView` observes with.
3
+ * shows Views to. What `LazyView` observes with. A person's viewer is kept as
4
+ * their own record says (`followViewer`): their name, or none, and their
5
+ * email.
4
6
  */
5
7
  import type { Client } from "../../runtime/client.js";
6
8
  import type { Viewer } from "../../runtime/mod.js";
@@ -8,3 +10,27 @@ export declare const session: {
8
10
  client?: Client;
9
11
  viewer?: Viewer;
10
12
  };
13
+ /** What someone signed in is shown as: their name and email, as far as known. */
14
+ export type Shown = {
15
+ name?: unknown;
16
+ email?: unknown;
17
+ };
18
+ /**
19
+ * Whom Views are shown to: a person by their id, with their name and email;
20
+ * a contact as messages name it.
21
+ */
22
+ export declare function viewerOf(actor: {
23
+ kind: string;
24
+ id: string;
25
+ }, shown?: Shown): Viewer;
26
+ /**
27
+ * Keeps the page's viewer (`session.viewer`) as a person's own record says
28
+ * (identity's `person`: their name and email), and says when it changes
29
+ * (`changed`: the page draws again): they renamed themselves, here or in
30
+ * another tab. Its first answer is what the page knew already. It returns
31
+ * how to stop.
32
+ */
33
+ export declare function followViewer(client: Client, person: {
34
+ kind: string;
35
+ id: string;
36
+ }, changed: () => void): () => void;
@@ -1 +1,35 @@
1
1
  export const session = {};
2
+ /**
3
+ * Whom Views are shown to: a person by their id, with their name and email;
4
+ * a contact as messages name it.
5
+ */
6
+ export function viewerOf(actor, shown = {}) {
7
+ const text = (value) => typeof value === "string" && value ? value : undefined;
8
+ const label = text(shown.name);
9
+ const email = text(shown.email);
10
+ return {
11
+ kind: actor.kind,
12
+ name: actor.kind === "person" ? actor.id : `${actor.kind}:${actor.id}`,
13
+ ...(label ? { label } : {}),
14
+ ...(email ? { email } : {}),
15
+ };
16
+ }
17
+ /**
18
+ * Keeps the page's viewer (`session.viewer`) as a person's own record says
19
+ * (identity's `person`: their name and email), and says when it changes
20
+ * (`changed`: the page draws again): they renamed themselves, here or in
21
+ * another tab. Its first answer is what the page knew already. It returns
22
+ * how to stop.
23
+ */
24
+ export function followViewer(client, person, changed) {
25
+ return client.db.collection("person").watch({ _id: person.id }, { projection: { name: 1, email: 1 } }, ([now], error) => {
26
+ if (error || !now)
27
+ return;
28
+ const next = viewerOf(person, now);
29
+ const was = session.viewer;
30
+ if (next.label === was?.label && next.email === was?.email)
31
+ return;
32
+ session.viewer = next;
33
+ changed();
34
+ });
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "copilotz",
3
- "version": "1.0.0-rc.36",
3
+ "version": "1.0.0-rc.37",
4
4
  "description": "Copilotz: one runtime for Node, Deno, Bun, Cloudflare Workers and the browser.",
5
5
  "keywords": [
6
6
  "agents",
@@ -16,7 +16,8 @@ export declare function personFor(ctx: Context, email: string, login: Login | nu
16
16
  /**
17
17
  * Keeps what a sign-in proved about a person: their email (identity's
18
18
  * `person.email`, what invitations find people by), the name they gave when
19
- * they have none, and when they came (`at`, kept from before; an import's).
19
+ * they have none (and never chose one: `person.rename`), and when they came
20
+ * (`at`, kept from before; an import's).
20
21
  */
21
22
  export declare function keepPerson(ctx: Context, person: string, given: {
22
23
  email: string;
@@ -13,7 +13,8 @@ export async function personFor(ctx, email, login, chosen) {
13
13
  /**
14
14
  * Keeps what a sign-in proved about a person: their email (identity's
15
15
  * `person.email`, what invitations find people by), the name they gave when
16
- * they have none, and when they came (`at`, kept from before; an import's).
16
+ * they have none (and never chose one: `person.rename`), and when they came
17
+ * (`at`, kept from before; an import's).
17
18
  */
18
19
  export async function keepPerson(ctx, person, given) {
19
20
  const people = ctx.as().db.collection("person");
@@ -22,7 +23,7 @@ export async function keepPerson(ctx, person, given) {
22
23
  await people.updateOne({ _id: person }, {
23
24
  $set: {
24
25
  email: given.email,
25
- ...(name && !known?.name ? { name } : {}),
26
+ ...(name && !known?.name && !known?.named ? { name } : {}),
26
27
  at: known?.at ?? given.at ?? new Date().toISOString(),
27
28
  },
28
29
  }, { upsert: true });
@@ -30,7 +30,8 @@ export const signInAction = defineAction({
30
30
  $set: {
31
31
  "accounts.google": claims.sub,
32
32
  ...(claims.email ? { email: claims.email } : {}),
33
- ...(claims.name ? { name: claims.name } : {}),
33
+ // A name they chose themselves (`person.rename`) stays.
34
+ ...(claims.name && !known?.named ? { name: claims.name } : {}),
34
35
  ...(claims.picture ? { picture: claims.picture } : {}),
35
36
  at: known?.at ?? new Date().toISOString(),
36
37
  },
@@ -1,2 +1,9 @@
1
1
  export declare const setPerson: import("../../../../runtime/define.js").ActionDef;
2
+ /**
3
+ * `person.rename` `{ name }`: the name a person goes by, which everyone sees
4
+ * (their menu, home's greeting, the people beside them, agents). Theirs
5
+ * alone: always their own, never through a key or an agent. One line (runs
6
+ * of spaces, tabs and breaks are one space), trimmed; empty, they have none.
7
+ */
8
+ export declare const renamePerson: import("../../../../runtime/define.js").ActionDef;
2
9
  export declare const emailOf: import("../../../../runtime/define.js").ActionDef;
@@ -3,8 +3,12 @@
3
3
  * verified about someone (their email, their name), and `person.email` says
4
4
  * the email someone proved, for plugins that match people by it (an
5
5
  * invitation). Both are the system's: a person never sets their own email.
6
+ * Their name is theirs, though (`person.rename`): once they've chosen it (or
7
+ * chosen none), sign-ins keep it as they left it.
6
8
  */
7
- import { defineAction } from "../../../../runtime/mod.js";
9
+ import { defineAction, failure, inPerson } from "../../../../runtime/mod.js";
10
+ /** The longest name someone gives themselves, in characters, once it's one line. */
11
+ const LONGEST = 80;
8
12
  export const setPerson = defineAction({
9
13
  description: "Keeps what a sign-in verified about a person: their email, their name",
10
14
  input: {
@@ -24,7 +28,8 @@ export const setPerson = defineAction({
24
28
  await people.updateOne({ _id: input.person }, {
25
29
  $set: {
26
30
  ...(input.email ? { email: input.email.trim().toLowerCase() } : {}),
27
- ...(input.name ? { name: input.name } : {}),
31
+ // A name they chose themselves stays.
32
+ ...(input.name && !known?.named ? { name: input.name } : {}),
28
33
  ...(input.picture ? { picture: input.picture } : {}),
29
34
  at: known?.at ?? new Date().toISOString(),
30
35
  },
@@ -32,6 +37,37 @@ export const setPerson = defineAction({
32
37
  return { new: !known };
33
38
  },
34
39
  });
40
+ /**
41
+ * `person.rename` `{ name }`: the name a person goes by, which everyone sees
42
+ * (their menu, home's greeting, the people beside them, agents). Theirs
43
+ * alone: always their own, never through a key or an agent. One line (runs
44
+ * of spaces, tabs and breaks are one space), trimmed; empty, they have none.
45
+ */
46
+ export const renamePerson = defineAction({
47
+ description: "Sets the name you go by; an empty one clears it",
48
+ input: {
49
+ type: "object",
50
+ // Room for the spaces around it; the name itself is checked below, in words people read.
51
+ properties: { name: { type: "string", maxLength: 200 } },
52
+ required: ["name"],
53
+ additionalProperties: false,
54
+ },
55
+ allow: inPerson,
56
+ run: async (ctx, input) => {
57
+ const name = input.name.replace(/[\s\p{Cc}]+/gu, " ").trim();
58
+ if ([...name].length > LONGEST) {
59
+ throw failure("invalid", `A name is at most ${LONGEST} characters.`, { public: true });
60
+ }
61
+ const people = ctx.as().db.collection("person");
62
+ const known = await people.findOne({ _id: ctx.actor.id });
63
+ const now = new Date().toISOString();
64
+ await people.updateOne({ _id: ctx.actor.id }, {
65
+ $set: { ...(name ? { name } : {}), named: now, at: known?.at ?? now },
66
+ ...(name ? {} : { $unset: { name: "" } }),
67
+ }, { upsert: true });
68
+ return { name: name || null };
69
+ },
70
+ });
35
71
  export const emailOf = defineAction({
36
72
  description: "The email a person proved when they signed in, if any",
37
73
  input: {
@@ -19,6 +19,10 @@ declare const personSchema: {
19
19
  readonly type: "string";
20
20
  };
21
21
  };
22
+ /** When they last chose their name, or none (`person.rename`): sign-ins leave it so. */
23
+ readonly named: {
24
+ readonly type: "string";
25
+ };
22
26
  readonly at: {
23
27
  readonly type: "string";
24
28
  };
@@ -45,6 +49,10 @@ export declare const person: {
45
49
  readonly type: "string";
46
50
  };
47
51
  };
52
+ /** When they last chose their name, or none (`person.rename`): sign-ins leave it so. */
53
+ readonly named: {
54
+ readonly type: "string";
55
+ };
48
56
  readonly at: {
49
57
  readonly type: "string";
50
58
  };
@@ -61,6 +69,7 @@ export declare const person: {
61
69
  name?: string | undefined;
62
70
  picture?: string | undefined;
63
71
  email?: string | undefined;
72
+ named?: string | undefined;
64
73
  accounts?: {
65
74
  [x: string]: string;
66
75
  } | undefined;
@@ -8,6 +8,8 @@ const personSchema = {
8
8
  picture: { type: "string" },
9
9
  /** Where each sign-in method knows them: `{ google: "1234" }`. */
10
10
  accounts: { type: "object", additionalProperties: { type: "string" } },
11
+ /** When they last chose their name, or none (`person.rename`): sign-ins leave it so. */
12
+ named: { type: "string" },
11
13
  at: { type: "string" },
12
14
  },
13
15
  required: ["at"],
@@ -22,7 +22,9 @@
22
22
  *
23
23
  * A sign-in method keeps what it verified about someone (`person.set`: their
24
24
  * email), and plugins that match people by email ask for it (`person.email`).
25
- * Each person reads only their own: nobody learns who else has an account.
25
+ * A person sets the name they go by themselves (`person.rename`), or clears
26
+ * it; sign-ins then leave it so. Each person reads only their own: nobody
27
+ * learns who else has an account.
26
28
  */
27
29
  import { type Plugin } from "../../../runtime/mod.js";
28
30
  export * from "./contract.js";
@@ -22,10 +22,12 @@
22
22
  *
23
23
  * A sign-in method keeps what it verified about someone (`person.set`: their
24
24
  * email), and plugins that match people by email ask for it (`person.email`).
25
- * Each person reads only their own: nobody learns who else has an account.
25
+ * A person sets the name they go by themselves (`person.rename`), or clears
26
+ * it; sign-ins then leave it so. Each person reads only their own: nobody
27
+ * learns who else has an account.
26
28
  */
27
29
  import { definePlugin, failure } from "../../../runtime/mod.js";
28
- import { emailOf, setPerson } from "./actions/person.js";
30
+ import { emailOf, renamePerson, setPerson } from "./actions/person.js";
29
31
  import { endSession, revokeCredentials, startSession } from "./actions/session.js";
30
32
  import { credential } from "./collections/credential.js";
31
33
  import { person } from "./collections/person.js";
@@ -41,6 +43,7 @@ export const identity = definePlugin({
41
43
  "session.end": endSession,
42
44
  "credential.revoke": revokeCredentials,
43
45
  "person.set": setPerson,
46
+ "person.rename": renamePerson,
44
47
  "person.email": emailOf,
45
48
  },
46
49
  // A request is the person its session cookie proves. The cookie is the host's alone
@@ -18,7 +18,8 @@ export const homeView = (_, ctx) => {
18
18
  const to = String(ctx.hints.query?.to ?? "");
19
19
  const suggestions = Object.values((ctx.resources.suggestions ?? {}))
20
20
  .filter((s) => typeof s === "string");
21
- const name = greeted(ctx.viewer?.label ?? ctx.viewer?.name ?? "");
21
+ // By their name, when they have one: never by their id.
22
+ const name = greeted(ctx.viewer?.label ?? "");
22
23
  const shared = space && space.kind !== "personal";
23
24
  // What other front ends show over the greeting.
24
25
  const tops = Object.values((ctx.resources.home ?? {}))
@@ -1,2 +1,2 @@
1
1
  /** The computer program's version, as `computer.info` and `--version` say it, and its builds are named. */
2
- export declare const VERSION = "1.0.0-rc.36";
2
+ export declare const VERSION = "1.0.0-rc.37";
@@ -1,2 +1,2 @@
1
1
  /** The computer program's version, as `computer.info` and `--version` say it, and its builds are named. */
2
- export const VERSION = "1.0.0-rc.36";
2
+ export const VERSION = "1.0.0-rc.37";
@@ -14,7 +14,7 @@
14
14
  *
15
15
  * ```ts
16
16
  * plugins: [...plugins, await computerDownloads()]
17
- * plugins: [...plugins, await computerDownloads({ dir: "dist/computer/1.0.0-rc.36" })]
17
+ * plugins: [...plugins, await computerDownloads({ dir: "dist/computer/1.0.0-rc.37" })]
18
18
  * plugins: [...plugins, await computerDownloads({ url: "https://downloads.example.com/computer/" })]
19
19
  * ```
20
20
  */
@@ -28,7 +28,9 @@
28
28
  * and 30 for where to go ("Spaces", "Chats"), 40 for making something
29
29
  * ("Create"), 90 for the shell's own ("General": the panel, signing out).
30
30
  *
31
- * Who's signed in has a menu of what front ends put there (the `userMenu`
31
+ * Who's signed in shows by their name (with none, their email; never their
32
+ * id), and has a menu: their name, which they change or clear there
33
+ * (identity's `person.rename`), what front ends put there (the `userMenu`
32
34
  * resource: `{ label, icon?, href, order? }`, pages of the person's own,
33
35
  * such as Connected accounts), then signing out.
34
36
  *
@@ -28,7 +28,9 @@
28
28
  * and 30 for where to go ("Spaces", "Chats"), 40 for making something
29
29
  * ("Create"), 90 for the shell's own ("General": the panel, signing out).
30
30
  *
31
- * Who's signed in has a menu of what front ends put there (the `userMenu`
31
+ * Who's signed in shows by their name (with none, their email; never their
32
+ * id), and has a menu: their name, which they change or clear there
33
+ * (identity's `person.rename`), what front ends put there (the `userMenu`
32
34
  * resource: `{ label, icon?, href, order? }`, pages of the person's own,
33
35
  * such as Connected accounts), then signing out.
34
36
  *
@@ -7,6 +7,7 @@
7
7
  * toolkit's `Page` does); a page that offers the panel, and the panel open,
8
8
  * keep their header's end clear of its button by `--copilotz-inset-end`.
9
9
  * Where a front end fills the `orgs` slot, the top of the sidebar makes room
10
- * for its switcher beside the app's mark; and the user menu.
10
+ * for its switcher beside the app's mark; and the user menu, with the dialog
11
+ * where the person names themselves.
11
12
  */
12
- export declare const STYLE = "\n.copilotz-shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); height: 100dvh;\n overflow: clip; background: var(--background); }\n.copilotz-sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--sidebar);\n color: var(--sidebar-foreground); border-right: 1px solid var(--sidebar-border); }\n.copilotz-sidebar-head { display: flex; align-items: center; justify-content: space-between;\n gap: 8px; padding: 14px 12px 10px 18px; }\n.copilotz-brand { display: inline-flex; align-items: center; margin: -6px -8px; padding: 6px 8px;\n border-radius: var(--radius-md); text-decoration: none; transition: background-color .15s; }\n.copilotz-brand:hover { background: var(--sidebar-accent); }\n.copilotz-find { padding: 0 10px 6px; }\n.copilotz-find .copilotz-nav-icon { color: var(--muted-foreground); }\n.copilotz-find .copilotz-kbd { font-size: 10.5px; }\n.copilotz-sections { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;\n padding: 4px 10px 20px; display: flex; flex-direction: column; gap: 6px; scrollbar-width: thin;\n scrollbar-color: var(--input) transparent; }\n.copilotz-section:empty { display: none; }\n.copilotz-section + .copilotz-section-titled { margin-top: 14px; }\n.copilotz-section > h2 { margin: 0 0 4px; padding: 0 10px; font-family: var(--font-display); font-size: 11.5px;\n font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--muted-foreground); }\n.copilotz-me { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 16px;\n border-top: 1px solid var(--sidebar-border); }\n.copilotz-me-who { flex: 1; min-width: 0; display: grid; line-height: 1.25; }\n.copilotz-me-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.copilotz-me-note { font-size: 12px; color: var(--muted-foreground); }\n.copilotz-stage { position: relative; display: flex; min-width: 0; min-height: 0; }\n.copilotz-main { position: relative; flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0;\n overflow: clip; outline: none; }\n.copilotz-main > * { flex: 1; min-height: 0; }\n.copilotz-main > .copilotz-failed { flex: none; align-self: center; width: min(560px, calc(100% - 32px));\n margin: max(64px, 12vh) 0 0; }\n.copilotz-skip { position: fixed; z-index: 60; top: 10px; left: 10px; transform: translateY(-160%);\n transition: transform .15s; }\n.copilotz-skip:focus-visible { transform: none; }\n.copilotz-shell-empty { display: grid; place-content: center; padding: 32px; }\n\n/* The side panel: its button over the page's top right, and the panel beside it */\n.copilotz-panel-toggle { position: absolute; z-index: 20; top: 11px; right: 12px; color: var(--secondary-foreground); }\n.copilotz-panel { flex: none; display: flex; flex-direction: column; min-height: 0;\n width: clamp(320px, var(--copilotz-panel-width, 420px), 58%); overflow: hidden; background: var(--background);\n animation: copilotz-panel-in .2s ease-out; }\n.copilotz-panel > * { flex: 1; min-height: 0; }\n@keyframes copilotz-panel-in { from { opacity: 0; transform: translateX(14px); } }\n.copilotz-drawer-bottom:has(> .copilotz-panel-sheet) { height: 88dvh; max-height: 88dvh; }\n.copilotz-panel-sheet { position: relative; display: flex; flex-direction: column; overflow: hidden; }\n.copilotz-panel-sheet-head { position: absolute; z-index: 2; inset: 0 0 auto; height: 0; }\n.copilotz-panel-grab { position: absolute; top: 7px; left: 50%; width: 38px; height: 4px; margin-left: -19px;\n border-radius: var(--radius-full); background: var(--input); }\n.copilotz-panel-close { position: absolute; top: 17px; right: 10px; }\n.copilotz-panel-sheet-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden;\n padding-top: 8px; --copilotz-inset-end: 52px; }\n.copilotz-panel-sheet-body > * { flex: 1; min-height: 0; }\n\n@media (max-width: 760px) {\n .copilotz-shell { grid-template-columns: minmax(0, 1fr); --copilotz-inset: 56px; }\n .copilotz-sidebar { border-right: 0; }\n .copilotz-shell-menu { position: absolute; z-index: 20; top: 10px; left: 10px; color: var(--secondary-foreground); }\n .copilotz-panel-toggle { top: 10px; right: 10px; }\n}\n\n/* Where the app serves many orgs: the orgs slot's switcher, beside the app's mark */\n.copilotz-sidebar-head[data-orgs] { gap: 4px; padding: 12px 10px 8px 10px; }\n.copilotz-brand-mark { flex: none; margin: 0; padding: 8px; color: var(--sidebar-foreground); }\n\n/* The user menu */\n.copilotz-me-menu { padding: 8px; }\n.copilotz-me-button { display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0; padding: 6px 8px;\n border: 0; border-radius: var(--radius-md); background: transparent; color: inherit; text-align: left;\n cursor: pointer; transition: background-color .12s; }\n.copilotz-me-button:hover, .copilotz-me-button[aria-expanded=true] { background: var(--sidebar-accent); }\n.copilotz-me-chevron { flex: none; color: var(--muted-foreground); }\n";
13
+ export declare const STYLE = "\n.copilotz-shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); height: 100dvh;\n overflow: clip; background: var(--background); }\n.copilotz-sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--sidebar);\n color: var(--sidebar-foreground); border-right: 1px solid var(--sidebar-border); }\n.copilotz-sidebar-head { display: flex; align-items: center; justify-content: space-between;\n gap: 8px; padding: 14px 12px 10px 18px; }\n.copilotz-brand { display: inline-flex; align-items: center; margin: -6px -8px; padding: 6px 8px;\n border-radius: var(--radius-md); text-decoration: none; transition: background-color .15s; }\n.copilotz-brand:hover { background: var(--sidebar-accent); }\n.copilotz-find { padding: 0 10px 6px; }\n.copilotz-find .copilotz-nav-icon { color: var(--muted-foreground); }\n.copilotz-find .copilotz-kbd { font-size: 10.5px; }\n.copilotz-sections { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;\n padding: 4px 10px 20px; display: flex; flex-direction: column; gap: 6px; scrollbar-width: thin;\n scrollbar-color: var(--input) transparent; }\n.copilotz-section:empty { display: none; }\n.copilotz-section + .copilotz-section-titled { margin-top: 14px; }\n.copilotz-section > h2 { margin: 0 0 4px; padding: 0 10px; font-family: var(--font-display); font-size: 11.5px;\n font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--muted-foreground); }\n.copilotz-me { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 16px;\n border-top: 1px solid var(--sidebar-border); }\n.copilotz-me-who { flex: 1; min-width: 0; display: grid; line-height: 1.25; }\n.copilotz-me-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.copilotz-me-note { font-size: 12px; color: var(--muted-foreground); overflow: hidden; text-overflow: ellipsis;\n white-space: nowrap; }\n.copilotz-stage { position: relative; display: flex; min-width: 0; min-height: 0; }\n.copilotz-main { position: relative; flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0;\n overflow: clip; outline: none; }\n.copilotz-main > * { flex: 1; min-height: 0; }\n.copilotz-main > .copilotz-failed { flex: none; align-self: center; width: min(560px, calc(100% - 32px));\n margin: max(64px, 12vh) 0 0; }\n.copilotz-skip { position: fixed; z-index: 60; top: 10px; left: 10px; transform: translateY(-160%);\n transition: transform .15s; }\n.copilotz-skip:focus-visible { transform: none; }\n.copilotz-shell-empty { display: grid; place-content: center; padding: 32px; }\n\n/* The side panel: its button over the page's top right, and the panel beside it */\n.copilotz-panel-toggle { position: absolute; z-index: 20; top: 11px; right: 12px; color: var(--secondary-foreground); }\n.copilotz-panel { flex: none; display: flex; flex-direction: column; min-height: 0;\n width: clamp(320px, var(--copilotz-panel-width, 420px), 58%); overflow: hidden; background: var(--background);\n animation: copilotz-panel-in .2s ease-out; }\n.copilotz-panel > * { flex: 1; min-height: 0; }\n@keyframes copilotz-panel-in { from { opacity: 0; transform: translateX(14px); } }\n.copilotz-drawer-bottom:has(> .copilotz-panel-sheet) { height: 88dvh; max-height: 88dvh; }\n.copilotz-panel-sheet { position: relative; display: flex; flex-direction: column; overflow: hidden; }\n.copilotz-panel-sheet-head { position: absolute; z-index: 2; inset: 0 0 auto; height: 0; }\n.copilotz-panel-grab { position: absolute; top: 7px; left: 50%; width: 38px; height: 4px; margin-left: -19px;\n border-radius: var(--radius-full); background: var(--input); }\n.copilotz-panel-close { position: absolute; top: 17px; right: 10px; }\n.copilotz-panel-sheet-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden;\n padding-top: 8px; --copilotz-inset-end: 52px; }\n.copilotz-panel-sheet-body > * { flex: 1; min-height: 0; }\n\n@media (max-width: 760px) {\n .copilotz-shell { grid-template-columns: minmax(0, 1fr); --copilotz-inset: 56px; }\n .copilotz-sidebar { border-right: 0; }\n .copilotz-shell-menu { position: absolute; z-index: 20; top: 10px; left: 10px; color: var(--secondary-foreground); }\n .copilotz-panel-toggle { top: 10px; right: 10px; }\n}\n\n/* Where the app serves many orgs: the orgs slot's switcher, beside the app's mark */\n.copilotz-sidebar-head[data-orgs] { gap: 4px; padding: 12px 10px 8px 10px; }\n.copilotz-brand-mark { flex: none; margin: 0; padding: 8px; color: var(--sidebar-foreground); }\n\n/* The user menu */\n.copilotz-me-menu { padding: 8px; }\n.copilotz-me-button { display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0; padding: 6px 8px;\n border: 0; border-radius: var(--radius-md); background: transparent; color: inherit; text-align: left;\n cursor: pointer; transition: background-color .12s; }\n.copilotz-me-button:hover, .copilotz-me-button[aria-expanded=true] { background: var(--sidebar-accent); }\n.copilotz-me-chevron { flex: none; color: var(--muted-foreground); }\n/* Their name, in a dialog: how they'll show, over the field */\n.copilotz-me-form { display: grid; gap: 16px; }\n.copilotz-me-preview { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 10px 12px;\n border: 1px solid var(--sidebar-border); border-radius: var(--radius-lg); background: var(--sidebar);\n color: var(--sidebar-foreground); }\n";
@@ -7,7 +7,8 @@
7
7
  * toolkit's `Page` does); a page that offers the panel, and the panel open,
8
8
  * keep their header's end clear of its button by `--copilotz-inset-end`.
9
9
  * Where a front end fills the `orgs` slot, the top of the sidebar makes room
10
- * for its switcher beside the app's mark; and the user menu.
10
+ * for its switcher beside the app's mark; and the user menu, with the dialog
11
+ * where the person names themselves.
11
12
  */
12
13
  export const STYLE = `
13
14
  .copilotz-shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); height: 100dvh;
@@ -33,7 +34,8 @@ export const STYLE = `
33
34
  border-top: 1px solid var(--sidebar-border); }
34
35
  .copilotz-me-who { flex: 1; min-width: 0; display: grid; line-height: 1.25; }
35
36
  .copilotz-me-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
36
- .copilotz-me-note { font-size: 12px; color: var(--muted-foreground); }
37
+ .copilotz-me-note { font-size: 12px; color: var(--muted-foreground); overflow: hidden; text-overflow: ellipsis;
38
+ white-space: nowrap; }
37
39
  .copilotz-stage { position: relative; display: flex; min-width: 0; min-height: 0; }
38
40
  .copilotz-main { position: relative; flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0;
39
41
  overflow: clip; outline: none; }
@@ -80,4 +82,9 @@ export const STYLE = `
80
82
  cursor: pointer; transition: background-color .12s; }
81
83
  .copilotz-me-button:hover, .copilotz-me-button[aria-expanded=true] { background: var(--sidebar-accent); }
82
84
  .copilotz-me-chevron { flex: none; color: var(--muted-foreground); }
85
+ /* Their name, in a dialog: how they'll show, over the field */
86
+ .copilotz-me-form { display: grid; gap: 16px; }
87
+ .copilotz-me-preview { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 10px 12px;
88
+ border: 1px solid var(--sidebar-border); border-radius: var(--radius-lg); background: var(--sidebar);
89
+ color: var(--sidebar-foreground); }
83
90
  `;
@@ -29,7 +29,7 @@ export type Orgs = {
29
29
  overlay?: ReactNode;
30
30
  use?: OrgsSlot["use"];
31
31
  };
32
- export declare function Frame({ path, brand, viewer, label, sidebar, menu, call, panel, palette, orgs, children }: {
32
+ export declare function Frame({ path, brand, viewer, label, email, sidebar, menu, call, panel, palette, orgs, children }: {
33
33
  /** Where the page is: going elsewhere closes the drawer, and the panel's sheet. */
34
34
  path: string;
35
35
  /** The app's name, which its logo says (or shows). */
@@ -38,10 +38,12 @@ export declare function Frame({ path, brand, viewer, label, sidebar, menu, call,
38
38
  viewer: string;
39
39
  /** What the viewer is shown as, when not their id (their name). */
40
40
  label?: string;
41
+ /** The viewer's email, where the host knows it. */
42
+ email?: string;
41
43
  sidebar: ReactNode;
42
44
  /** What front ends put in the person's menu (the `userMenu` resource). */
43
45
  menu: UserMenuEntry[];
44
- /** How the shell calls Actions (given to the `orgs` slot's hook). */
46
+ /** How the shell calls Actions (the person naming themselves; the `orgs` slot's hook). */
45
47
  call: Call;
46
48
  /** The side panel, when the page offers it. */
47
49
  panel?: Offered;
@@ -38,7 +38,7 @@ const phone = {
38
38
  },
39
39
  matches: () => matchMedia(PHONE).matches,
40
40
  };
41
- export function Frame({ path, brand, viewer, label, sidebar, menu, call, panel, palette, orgs, children }) {
41
+ export function Frame({ path, brand, viewer, label, email, sidebar, menu, call, panel, palette, orgs, children }) {
42
42
  // Drawn on a server (a test), it is not a phone.
43
43
  const narrow = useSyncExternalStore(phone.subscribe, phone.matches, () => false);
44
44
  const [open, setOpen] = useState(false);
@@ -102,7 +102,7 @@ export function Frame({ path, brand, viewer, label, sidebar, menu, call, panel,
102
102
  : (_jsx("a", { className: "copilotz-brand", href: "/", children: _jsx(Logo, { variant: "full", name: brand, size: 32 }) })), narrow
103
103
  ? _jsx(IconButton, { icon: "close", label: say("closeSidebar"), onClick: () => setOpen(false) })
104
104
  : null] }), _jsx("div", { className: "copilotz-find", children: _jsx(NavItem, { quiet: true, icon: "search", onClick: find, end: narrow ? null : _jsx(Kbd, { children: shortcutOf(mac) }), title: say("searchTitle", { shortcut: shortcutOf(mac) }), children: say("search") }) }), _jsx("nav", { className: "copilotz-sections", "aria-label": say("spacesAndChats"), children: sidebar }), viewer
105
- ? (_jsx(Me, { name: label ?? viewer, email: shown?.email, menu: [...menu, ...(shown?.menu ?? [])] }))
105
+ ? (_jsx(Me, { ...(label ? { name: label } : {}), email: shown?.email ?? email, menu: [...menu, ...(shown?.menu ?? [])], call: call }))
106
106
  : null] }));
107
107
  return (_jsxs("div", { className: "copilotz-shell", children: [_jsx("style", { href: "web-shell", precedence: "copilotz", children: STYLE }), _jsx(Button, { className: "copilotz-skip", onClick: () => document.getElementById("copilotz-main")?.focus(), children: say("skipToContent") }), narrow
108
108
  ? (_jsx(Drawer, { open: open, onClose: () => setOpen(false), label: say("sidebar"), className: "copilotz-sidebar", children: content }))
@@ -1,15 +1,23 @@
1
1
  /**
2
- * Who's signed in, at the foot of the sidebar, and their menu: what front
3
- * ends put there (the `userMenu` resource: `{ label, icon?, href, order? }`,
4
- * Connected accounts, say), then what the `orgs` slot lists where the app
5
- * serves many orgs (the org's settings; every org, for staff), then signing
6
- * out (of every org). With nothing in it, signing out is a button of its own.
2
+ * Who's signed in, at the foot of the sidebar, and their menu. They show by
3
+ * their name; with none, by their email; never by their id. The menu opens
4
+ * with their name, which they change or clear there (`person.rename`, in a
5
+ * dialog), then what front ends put there (the `userMenu` resource:
6
+ * `{ label, icon?, href, order? }`, Connected accounts, say), then what the
7
+ * `orgs` slot lists where the app serves many orgs (the org's settings;
8
+ * every org, for staff), then signing out (of every org). The name they give
9
+ * shows at once, wherever they're shown: the host follows their record.
7
10
  */
8
11
  import { type ReactNode } from "react";
9
12
  import type { UserMenuEntry } from "../shared/menu.js";
10
- export declare function Me({ name, email, menu }: {
11
- name: string;
13
+ type Call = <R = unknown>(action: string, input?: unknown) => Promise<R>;
14
+ export declare function Me({ name, email, menu, call }: {
15
+ /** Their name, when they have one. */
16
+ name?: string;
12
17
  email?: string | null;
13
18
  /** What front ends put in the menu, in their order (and the `orgs` slot's, after). */
14
19
  menu?: UserMenuEntry[];
20
+ /** How the shell calls Actions: their name is changed with it. */
21
+ call: Call;
15
22
  }): ReactNode;
23
+ export {};
@@ -1,28 +1,89 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  /**
3
- * Who's signed in, at the foot of the sidebar, and their menu: what front
4
- * ends put there (the `userMenu` resource: `{ label, icon?, href, order? }`,
5
- * Connected accounts, say), then what the `orgs` slot lists where the app
6
- * serves many orgs (the org's settings; every org, for staff), then signing
7
- * out (of every org). With nothing in it, signing out is a button of its own.
3
+ * Who's signed in, at the foot of the sidebar, and their menu. They show by
4
+ * their name; with none, by their email; never by their id. The menu opens
5
+ * with their name, which they change or clear there (`person.rename`, in a
6
+ * dialog), then what front ends put there (the `userMenu` resource:
7
+ * `{ label, icon?, href, order? }`, Connected accounts, say), then what the
8
+ * `orgs` slot lists where the app serves many orgs (the org's settings;
9
+ * every org, for staff), then signing out (of every org). The name they give
10
+ * shows at once, wherever they're shown: the host follows their record.
8
11
  */
9
- import { useState } from "react";
10
- import { Avatar, Icon, IconButton, Menu, signOut, } from "../../../../hosts/web/mod.js";
12
+ import { useEffect, useId, useRef, useState } from "react";
13
+ import { Avatar, Button, Dialog, Field, Icon, Input, Menu, message, signOut, } from "../../../../hosts/web/mod.js";
14
+ import { isPublic } from "../../../../runtime/mod.js";
11
15
  import { say } from "./words.js";
12
- export function Me({ name, email, menu = [] }) {
13
- const [leaving, setLeaving] = useState(false);
14
- const leave = () => {
15
- setLeaving(true);
16
- void signOut();
16
+ /** The longest name someone gives themselves, as `person.rename` takes it. */
17
+ const LONGEST = 80;
18
+ /** A name as it's kept: one line, trimmed. */
19
+ const tidy = (name) => name.replace(/[\s\p{Cc}]+/gu, " ").trim();
20
+ export function Me({ name, email, menu = [], call }) {
21
+ const [naming, setNaming] = useState(false);
22
+ // Each opening starts again from their name as it is.
23
+ const [opened, setOpened] = useState(0);
24
+ const items = [
25
+ {
26
+ label: name ? say("yourName") : say("addYourName"),
27
+ icon: "pencil",
28
+ onSelect: () => {
29
+ setOpened((n) => n + 1);
30
+ setNaming(true);
31
+ },
32
+ },
33
+ ...menu.map(({ label, icon, href }) => ({ label, href, ...(icon ? { icon } : {}) })),
34
+ "separator",
35
+ { label: say("signOut"), icon: "signout", onSelect: () => void signOut() },
36
+ ];
37
+ return (_jsxs("div", { className: "copilotz-me copilotz-me-menu", children: [_jsx(Menu, { label: say("yourAccount"), side: "top", items: items, trigger: (props) => (_jsxs("button", { type: "button", ...props, className: "copilotz-me-button", children: [_jsx(Who, { name: name, email: email }), _jsx(Icon, { name: "selector", size: 15, className: "copilotz-me-chevron" })] })) }), _jsx(NameDialog, { open: naming, name: name, email: email, call: call, onClose: () => setNaming(false) }, opened)] }));
38
+ }
39
+ /** Them as the menu shows them: a face, their name (else their email), and a note under it. */
40
+ function Who({ name, email }) {
41
+ const shown = name || email || "";
42
+ return (_jsxs(_Fragment, { children: [_jsx(Avatar, { name: shown, size: 32 }), _jsxs("span", { className: "copilotz-me-who", children: [_jsx("span", { className: "copilotz-me-name", children: shown || say("yourAccount") }), _jsx("span", { className: "copilotz-me-note", children: name && email && email !== name ? email : say("signedIn") })] })] }));
43
+ }
44
+ /**
45
+ * Their name, to change: the field starts with it, selected, so typing
46
+ * replaces it; Enter saves. Empty, it's cleared, and they go by their email.
47
+ * What they'll look like shows above as they type. While it saves the field
48
+ * waits; what went wrong is said under it, and it stays open to try again.
49
+ */
50
+ function NameDialog({ open, name, email, call, onClose }) {
51
+ const [draft, setDraft] = useState(name ?? "");
52
+ const [busy, setBusy] = useState(false);
53
+ const [error, setError] = useState();
54
+ const field = useRef(null);
55
+ const form = useId();
56
+ // Opened, the dialog has put focus in the field: what's there is selected.
57
+ useEffect(() => {
58
+ if (open)
59
+ field.current?.select();
60
+ }, [open]);
61
+ const next = tidy(draft);
62
+ const save = async () => {
63
+ if (busy)
64
+ return;
65
+ if (next === (name ?? ""))
66
+ return onClose();
67
+ setBusy(true);
68
+ setError(undefined);
69
+ try {
70
+ await call("person.rename", { name: next });
71
+ onClose();
72
+ }
73
+ catch (e) {
74
+ // A refusal meant to be read says why; anything else (the connection), to try again.
75
+ setError(isPublic(e) ? say("nameNotSaved", { reason: message(e) }) : say("nameTryAgain"));
76
+ field.current?.focus();
77
+ }
78
+ finally {
79
+ setBusy(false);
80
+ }
17
81
  };
18
- const own = menu.map(({ label, icon, href }) => ({
19
- label,
20
- href,
21
- ...(icon ? { icon } : {}),
22
- }));
23
- const who = (_jsxs(_Fragment, { children: [_jsx(Avatar, { name: name, size: 32 }), _jsxs("span", { className: "copilotz-me-who", children: [_jsx("span", { className: "copilotz-me-name", children: name }), _jsx("span", { className: "copilotz-me-note", children: email && email !== name ? email : say("signedIn") })] })] }));
24
- if (!own.length) {
25
- return (_jsxs("div", { className: "copilotz-me", children: [who, _jsx(IconButton, { icon: "signout", label: say("signOut"), loading: leaving, onClick: leave })] }));
26
- }
27
- return (_jsx("div", { className: "copilotz-me copilotz-me-menu", children: _jsx(Menu, { label: say("yourAccount"), side: "top", items: [...own, "separator", { label: say("signOut"), icon: "signout", onSelect: leave }], trigger: (props) => (_jsxs("button", { type: "button", ...props, className: "copilotz-me-button", children: [who, _jsx(Icon, { name: "selector", size: 15, className: "copilotz-me-chevron" })] })) }) }));
82
+ return (_jsx(Dialog, { open: open, onClose: onClose, size: "sm", title: name ? say("yourName") : say("addYourName"), description: say("nameAbout"), footer: _jsxs(_Fragment, { children: [_jsx(Button, { onClick: onClose, disabled: busy, children: say("cancel") }), _jsx(Button, { type: "submit", form: form, variant: "primary", loading: busy, children: say("save") })] }), children: _jsxs("form", { id: form, className: "copilotz-me-form", onSubmit: (event) => {
83
+ event.preventDefault();
84
+ void save();
85
+ }, children: [_jsx("div", { className: "copilotz-me-preview", "aria-hidden": "true", children: _jsx(Who, { name: next, email: email }) }), _jsx(Field, { label: say("nameLabel"), error: error, ...(email ? { hint: say("nameEmpty") } : {}), children: (control) => (_jsx(Input, { ...control, ref: field, value: draft, maxLength: LONGEST, autoComplete: "name", autoCapitalize: "words", spellCheck: false, readOnly: busy, onChange: (event) => {
86
+ setDraft(event.target.value);
87
+ setError(undefined);
88
+ } })) })] }) }));
28
89
  }
@@ -30,7 +30,8 @@ export const shellView = (where, ctx) => {
30
30
  const around = { ...hints, path: where.path };
31
31
  const viewer = ctx.viewer?.name ?? "";
32
32
  const label = ctx.viewer?.label;
33
- return (_jsx(Frame, { path: where.path + (where.space ?? ""), brand: app, viewer: viewer, ...(label ? { label } : {}), palette: {
33
+ const email = ctx.viewer?.email;
34
+ return (_jsx(Frame, { path: where.path + (where.space ?? ""), brand: app, viewer: viewer, ...(label ? { label } : {}), ...(email ? { email } : {}), palette: {
34
35
  sources: sourcesOf(ctx.resources.palette),
35
36
  hints: {
36
37
  ...hints,
@@ -1 +1 @@
1
- export declare const say: import("../../../../hosts/web/words.js").Say<"close" | "search" | "panel" | "sidebar" | "goHome" | "nothingHere" | "general" | "signOut" | "keysPanel" | "homeOf" | "closeSidebar" | "openSidebar" | "searchTitle" | "spacesAndChats" | "skipToContent" | "panelWidth" | "showPanel" | "hidePanel" | "showPanelTitled" | "hidePanelTitled" | "signedIn" | "yourAccount" | "nothingOpens" | "nothingToShow" | "nothingToShowAbout" | "roleOwner" | "roleOwnerLets" | "roleAdmin" | "roleAdminLets" | "roleMember" | "roleMemberLets" | "roleGuest" | "roleGuestLets">;
1
+ export declare const say: import("../../../../hosts/web/words.js").Say<"cancel" | "close" | "search" | "panel" | "sidebar" | "save" | "goHome" | "nothingHere" | "general" | "signOut" | "keysPanel" | "homeOf" | "closeSidebar" | "openSidebar" | "searchTitle" | "spacesAndChats" | "skipToContent" | "panelWidth" | "showPanel" | "hidePanel" | "showPanelTitled" | "hidePanelTitled" | "signedIn" | "yourAccount" | "yourName" | "addYourName" | "nameAbout" | "nameLabel" | "nameEmpty" | "nameNotSaved" | "nameTryAgain" | "nothingOpens" | "nothingToShow" | "nothingToShowAbout" | "roleOwner" | "roleOwnerLets" | "roleAdmin" | "roleAdminLets" | "roleMember" | "roleMemberLets" | "roleGuest" | "roleGuestLets">;
@@ -25,9 +25,18 @@ export const say = defineWords("shell", {
25
25
  hidePanel: "Hide the panel",
26
26
  showPanelTitled: "Show the {title} panel",
27
27
  hidePanelTitled: "Hide the {title} panel",
28
- // The account menu (me.tsx)
28
+ // The account menu (me.tsx), and naming yourself there
29
29
  signedIn: "Signed in",
30
30
  yourAccount: "Your account",
31
+ yourName: "Your name",
32
+ addYourName: "Add your name",
33
+ nameAbout: "How people and agents here see you.",
34
+ nameLabel: "Name",
35
+ nameEmpty: "Leave it empty to go by your email.",
36
+ nameNotSaved: "Your name wasn't saved. {reason}",
37
+ nameTryAgain: "Your name wasn't saved. Try again in a moment.",
38
+ cancel: "Cancel",
39
+ save: "Save",
31
40
  // An address with nothing to show (shell.tsx, default.tsx)
32
41
  nothingHere: "Nothing here",
33
42
  nothingOpens: "This address doesn't open anything.",
@@ -223,12 +223,14 @@ export type ViewDef = (item: any, ctx: ViewContext<any>) => unknown;
223
223
  /**
224
224
  * Who looks: a View renders relative to it (your own messages, your bubbles).
225
225
  * `name` is who they are (a person's id); `label` what they're shown as, when
226
- * it isn't that (a person's own name, as they signed in).
226
+ * it isn't that (a person's own name); `email`, where the host knows it, the
227
+ * address they signed in with (what shows them when they have no name).
227
228
  */
228
229
  export type Viewer = {
229
230
  name: string;
230
231
  kind?: string;
231
232
  label?: string;
233
+ email?: string;
232
234
  };
233
235
  export type RenderOptions = {
234
236
  viewer?: Viewer;