copilotz 1.0.0-rc.36 → 1.0.0-rc.38

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 (41) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +1 -1
  3. package/hosts/web/host.js +18 -17
  4. package/hosts/web/server.js +3 -1
  5. package/hosts/web/session.d.ts +27 -1
  6. package/hosts/web/session.js +34 -0
  7. package/package.json +1 -1
  8. package/plugins/access/email/shared/people.d.ts +2 -1
  9. package/plugins/access/email/shared/people.js +3 -2
  10. package/plugins/access/google/actions/sign-in.js +2 -1
  11. package/plugins/access/identity/actions/person.d.ts +7 -0
  12. package/plugins/access/identity/actions/person.js +38 -2
  13. package/plugins/access/identity/collections/person.d.ts +9 -0
  14. package/plugins/access/identity/collections/person.js +2 -0
  15. package/plugins/access/identity/mod.d.ts +3 -1
  16. package/plugins/access/identity/mod.js +5 -2
  17. package/plugins/agents/chat/actions/send.js +44 -8
  18. package/plugins/agents/chat/views/web/home.js +2 -1
  19. package/plugins/compute/computers/program/version.d.ts +1 -1
  20. package/plugins/compute/computers/program/version.js +1 -1
  21. package/plugins/compute/computers/resources/downloads.js +1 -1
  22. package/plugins/interfaces/mcp/resources/server.js +75 -24
  23. package/plugins/interfaces/mcp/resources/tools.js +27 -2
  24. package/plugins/interfaces/mcp/shared/settings.d.ts +1 -1
  25. package/plugins/interfaces/mcp/shared/settings.js +3 -2
  26. package/plugins/interfaces/web/mod.d.ts +3 -1
  27. package/plugins/interfaces/web/mod.js +3 -1
  28. package/plugins/interfaces/web/shared/style.d.ts +3 -2
  29. package/plugins/interfaces/web/shared/style.js +9 -2
  30. package/plugins/interfaces/web/views/frame.d.ts +4 -2
  31. package/plugins/interfaces/web/views/frame.js +2 -2
  32. package/plugins/interfaces/web/views/me.d.ts +15 -7
  33. package/plugins/interfaces/web/views/me.js +83 -22
  34. package/plugins/interfaces/web/views/shell.js +2 -1
  35. package/plugins/interfaces/web/views/words.d.ts +1 -1
  36. package/plugins/interfaces/web/views/words.js +10 -1
  37. package/plugins/interfaces/whatsapp/processors/receive.js +9 -17
  38. package/plugins/models/shared/catalog.json +7365 -7365
  39. package/runtime/define.d.ts +12 -2
  40. package/runtime/fetch.d.ts +3 -1
  41. package/runtime/fetch.js +20 -9
package/CHANGELOG.md CHANGED
@@ -1,3 +1,57 @@
1
+ ## 1.0.0-rc.38 — 2026-11-10
2
+
3
+ - **MCP 2026-07-28 cacheable results, widget read schemas, cross-origin MCP lines, and
4
+ `/.well-known/`:**
5
+ - `resources/list`, `resources/templates/list` and `resources/read` now include `ttlMs` and
6
+ `cacheScope` on MCP `2026-07-28` (`CacheableResult`), and handshake versions (`2025-11-25` and
7
+ earlier) omit them on `tools/list` and resource results where `CacheableResult` does not exist.
8
+ - Widget tool inputs (`_reads` and `copilotz_read`'s `reads`) now declare their `items` object
9
+ schema so strict MCP clients accept `tools/list` when widgets are enabled.
10
+ - Stateless routes (`Route.crossOrigin`) enforce their own `Origin` rules without reading session
11
+ cookies, so an MCP line's `origins` (including `"*"`) answers browser preflights (`OPTIONS`) and
12
+ cross-origin `POST`s with CORS headers while keeping no-browser-origin (`403`) as the default.
13
+ - `webPage`'s `/*` catch-all leaves `/.well-known/*` as `404` when no plugin serves a route there,
14
+ instead of answering discovery probes with the HTML page.
15
+ - **A person's next message answers the question an agent waits on them for,** as the web says it
16
+ does ("Waiting on your answer: your next message replies"). `chat.send` finds it when a message
17
+ names none (`replyTo`): the newest question to its sender in that chat that an agent still waits
18
+ on; else one asked of them elsewhere by an agent whose turn waits in that chat, so what they tell
19
+ it there resumes that turn instead of starting a second one beside it. Never for a message sent
20
+ for them (`via`: a routine's), nor to an agent it doesn't go to (`to`, `@mentions`). Until now
21
+ only WhatsApp found it (its own lookup is gone; a quoted message still names what it answers): on
22
+ the web, an answer in the chat an agent opened to ask went to nobody, and the asking turn, with
23
+ whatever waited on it (an answer to hand back to another space), never resumed.
24
+
25
+ ## 1.0.0-rc.37 — 2026-11-10
26
+
27
+ **Upgrading.** The web shell says nine new words, which an app in another language gives under
28
+ `shell.<key>` (its words test names any it lacks): `yourName` ("Your name"), `addYourName` ("Add
29
+ your name"), `nameAbout` ("How people and agents here see you."), `nameLabel` ("Name"), `nameEmpty`
30
+ ("Leave it empty to go by your email."), `nameNotSaved` ("Your name wasn't saved. {reason}"),
31
+ `nameTryAgain` ("Your name wasn't saved. Try again in a moment."), `cancel` ("Cancel") and `save`
32
+ ("Save").
33
+
34
+ - **A person names themselves** (`person.rename` `{ name }`, identity's). Only a person, for
35
+ themselves, in person: never a contact, a key, an agent or a routine, and there's no one else to
36
+ name. The name is one line (spaces, tabs and breaks in a row are one space), trimmed, 80
37
+ characters at most (said plainly past that); empty, it's cleared, and they have none. It's what
38
+ everyone sees of them: their menu, home's greeting, the people beside them in a space, agents'
39
+ prompts (the spaces plugin's profile follows it, else their email's name, as before).
40
+ - **Sign-ins keep the name a person chose,** or their having none: Google's sign-in, email's, and
41
+ the system's `person.set` (a directory's handoff into an org) no longer set it back. Until a
42
+ person chooses (their record's `named`: when they last did), sign-ins keep their name current as
43
+ before.
44
+ - **The person's menu opens with their name,** "Your name" ("Add your name" with none), in a dialog:
45
+ the field holds it, selected, so typing replaces it; Enter saves; a live preview shows how they'll
46
+ appear; while it saves the field waits; a refusal is said under it and the dialog stays. So the
47
+ menu is always a menu now, with or without front ends' entries.
48
+ - **The new name shows at once, everywhere, without reloading:** in this tab and their others. The
49
+ web host keeps the page's viewer as the person's own record says (it watches it: their name and
50
+ email), and draws again when it changes; Views read it as before (`ctx.viewer.label`).
51
+ - **No name, no id:** with none, the menu shows the person's email (`ctx.viewer.email`, new, from
52
+ identity's `/me`), and home greets them plainly ("Good morning"). An app whose ids aren't names
53
+ (`01JD3X…`) showed the id in both.
54
+
1
55
  ## 1.0.0-rc.36 — 2026-11-10
2
56
 
3
57
  **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.38"`) 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
  }
@@ -258,7 +258,9 @@ export const webPage = definePlugin({
258
258
  });
259
259
  },
260
260
  "/*": async (request, { runtime }) => {
261
- if (request.method !== "GET" || !navigating(request)) {
261
+ const path = new URL(request.url).pathname;
262
+ if (request.method !== "GET" || !navigating(request) ||
263
+ path === "/.well-known" || path.startsWith("/.well-known/")) {
262
264
  return json({ error: "Not found" }, 404);
263
265
  }
264
266
  const served = of(runtime);
@@ -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.38",
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
@@ -7,8 +7,11 @@
7
7
  * said, agents read it later, and none answers it (what someone did on a
8
8
  * page beside the chat). A contact's goes to the sender of what it replies
9
9
  * to, else the thread's agents: never whom it names, though it too may say
10
- * something to nobody (`to: []`). It replies only to a message of the same conversation that its
11
- * sender reads. Only agents answering in
10
+ * something to nobody (`to: []`). It replies to the message it names (`replyTo`), one of the
11
+ * same conversation that its sender reads; naming none, to the question an agent still waits
12
+ * on its sender for (`awaited`: asked here, else asked elsewhere by an agent whose turn waits
13
+ * here), so a page need not say what its next message answers; never when sent for the person
14
+ * (`via`), nor to an agent it doesn't go to. Only agents answering in
12
15
  * its space answer there: naming one that doesn't fails (`not_here`). Its
13
16
  * files are the sender's own uploads (`chat.attach`), named by id: a call
14
17
  * carries no file's content, so a message of ten large ones goes as quickly
@@ -70,6 +73,33 @@ async function mentionsIn(ctx, text, thread, roster, members) {
70
73
  }
71
74
  return mentions(text, named);
72
75
  }
76
+ /**
77
+ * The question a message naming none answers: the newest one an agent still
78
+ * waits on its sender for, asked in this conversation; else asked of them
79
+ * elsewhere by an agent whose turn waits here (what they tell it here is their
80
+ * answer, and resumes that turn, not a second one). Only an agent the message
81
+ * goes to, when it names any (`to`, `@mentions`). Questions here are read as
82
+ * the sender, as they read them; waits, and what a wait here asked elsewhere
83
+ * (only its id is used), as the system: they're the agents' own.
84
+ */
85
+ async function awaited(ctx, thread, sender, named) {
86
+ const system = ctx.as();
87
+ const waits = system.db.collection("wait");
88
+ const asked = await ctx.db.collection("message").find({ thread, to: sender, replyTo: { $exists: false }, expectReply: { $ne: false } }, { sort: { at: -1 }, limit: 5 });
89
+ for (const question of asked) {
90
+ if (named && !named.includes(question.from))
91
+ continue;
92
+ if (await waits.findOne({ waitingFor: question._id }))
93
+ return question;
94
+ }
95
+ const open = (await waits.find({ thread, "waitingFor.0": { $exists: true } }))
96
+ .filter((w) => !named || named.includes(w.agent));
97
+ const ids = open.flatMap((w) => w.waitingFor);
98
+ if (!ids.length)
99
+ return null;
100
+ const [elsewhere] = await system.db.collection("message").find({ _id: { $in: ids }, to: sender, from: { $in: open.map((w) => w.agent) } }, { sort: { at: -1 }, limit: 1 });
101
+ return elsewhere ?? null;
102
+ }
73
103
  /** Who a message is from, pinned to whoever sends it: a person by id, a contact as `contact:<id>`. */
74
104
  const fromOf = (actor) => actor?.kind === "person"
75
105
  ? actor.id
@@ -185,15 +215,21 @@ export const sendAction = defineAction({
185
215
  const named = input.thread ?? allowed.thread;
186
216
  const threadId = named ?? crypto.randomUUID();
187
217
  const existing = named ? await threads.findOne({ _id: threadId }) : null;
188
- // What it answers: a message the sender reads, in this conversation (else it answers nothing).
189
- const found = input.replyTo
190
- ? await ctx.db.collection("message").findOne({ _id: input.replyTo })
191
- : null;
192
- const replied = found?.thread === threadId ? found : null;
218
+ const from = fromOf(ctx.actor) ?? input.from ?? "user";
193
219
  const where = existing ? existing.in : input.in;
194
220
  const roster = await rosterOf(ctx, where);
195
221
  const members = existing ? existing.agents ?? [] : roster.default;
196
222
  const mentioned = contact ? [] : await mentionsIn(ctx, said, threadId, roster, members);
223
+ // What it answers: the message it names, one the sender reads in this conversation; naming
224
+ // none, the question an agent waits on its sender for (not when sent for them: a routine's).
225
+ const found = input.replyTo
226
+ ? await ctx.db.collection("message").findOne({ _id: input.replyTo })
227
+ : null;
228
+ const replied = input.replyTo
229
+ ? found?.thread === threadId ? found : null
230
+ : existing && !input.via && !nobody
231
+ ? await awaited(ctx, threadId, from, contact ? undefined : input.to ?? (mentioned.length ? mentioned : undefined))
232
+ : null;
197
233
  const asked = (contact ? (nobody ? [] : undefined) : input.to) ??
198
234
  (mentioned.length ? mentioned : replied ? [replied.from] : members);
199
235
  // Agents answer only where they work: one named that doesn't is refused; one gone, left out.
@@ -264,7 +300,7 @@ export const sendAction = defineAction({
264
300
  }
265
301
  : {}),
266
302
  thread: threadId,
267
- from: fromOf(ctx.actor) ?? input.from ?? "user",
303
+ from,
268
304
  ...(where ? { in: where } : {}),
269
305
  to: [...to],
270
306
  text: said,
@@ -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.38";
@@ -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.38";
@@ -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.38" })]
18
18
  * plugins: [...plugins, await computerDownloads({ url: "https://downloads.example.com/computer/" })]
19
19
  * ```
20
20
  */