copilotz 1.0.0-rc.54 → 1.0.0-rc.55

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 (51) hide show
  1. package/AGENTS.md +4 -4
  2. package/CHANGELOG.md +68 -0
  3. package/README.md +2 -2
  4. package/hosts/web/mod.d.ts +1 -1
  5. package/hosts/web/mod.js +1 -1
  6. package/hosts/web/pt-br/chat.js +4 -0
  7. package/hosts/web/words.d.ts +7 -0
  8. package/hosts/web/words.js +10 -0
  9. package/package.json +1 -1
  10. package/plugins/access/accounts/actions/model-key.js +41 -13
  11. package/plugins/access/accounts/collections/model-key.d.ts +22 -4
  12. package/plugins/access/accounts/collections/model-key.js +31 -6
  13. package/plugins/access/accounts/shared/rules.js +5 -4
  14. package/plugins/access/accounts/views/web/accounts.js +3 -1
  15. package/plugins/access/accounts/views/web/own-keys.d.ts +12 -0
  16. package/plugins/access/accounts/views/web/own-keys.js +112 -0
  17. package/plugins/access/accounts/views/web/style.d.ts +1 -1
  18. package/plugins/access/accounts/views/web/style.js +17 -0
  19. package/plugins/access/accounts/web.d.ts +2 -1
  20. package/plugins/access/accounts/web.js +4 -1
  21. package/plugins/access/spaces/shared/agents.d.ts +12 -5
  22. package/plugins/access/spaces/shared/agents.js +19 -2
  23. package/plugins/access/spaces/views/web/agents.js +2 -1
  24. package/plugins/agents/chat/actions/welcomed.d.ts +1 -0
  25. package/plugins/agents/chat/actions/welcomed.js +20 -0
  26. package/plugins/agents/chat/collections/welcome.d.ts +23 -0
  27. package/plugins/agents/chat/collections/welcome.js +27 -0
  28. package/plugins/agents/chat/contract.d.ts +1 -1
  29. package/plugins/agents/chat/mod.js +14 -2
  30. package/plugins/agents/chat/processors/turn.js +6 -4
  31. package/plugins/agents/chat/shared/agents.d.ts +8 -6
  32. package/plugins/agents/chat/shared/agents.js +18 -22
  33. package/plugins/agents/chat/shared/types.d.ts +35 -1
  34. package/plugins/agents/chat/views/web/composer.d.ts +3 -1
  35. package/plugins/agents/chat/views/web/composer.js +4 -1
  36. package/plugins/agents/chat/views/web/conversation.js +1 -1
  37. package/plugins/agents/chat/views/web/home.d.ts +4 -1
  38. package/plugins/agents/chat/views/web/home.js +18 -1
  39. package/plugins/agents/chat/views/web/style.d.ts +1 -1
  40. package/plugins/agents/chat/views/web/style.js +2 -0
  41. package/plugins/agents/chat/views/web/welcome.d.ts +25 -0
  42. package/plugins/agents/chat/views/web/welcome.js +44 -0
  43. package/plugins/agents/chat/views/web/words.d.ts +1 -1
  44. package/plugins/agents/chat/views/web/words.js +5 -0
  45. package/plugins/compute/computers/program/version.d.ts +1 -1
  46. package/plugins/compute/computers/program/version.js +1 -1
  47. package/plugins/compute/computers/program/workloads/search.d.ts +1 -1
  48. package/plugins/compute/computers/resources/downloads.js +1 -1
  49. package/plugins/models/shared/choice.d.ts +4 -1
  50. package/plugins/models/shared/use.d.ts +3 -2
  51. package/plugins/models/shared/use.js +9 -3
package/AGENTS.md CHANGED
@@ -4,7 +4,7 @@ A guide for coding agents (Claude Code, Codex, Cursor, Gemini) building an app w
4
4
  it whole before you write code. The last section is for work on Copilotz itself.
5
5
 
6
6
  It ships in the package (`node_modules/copilotz/AGENTS.md`, and `@copilotz/copilotz` on JSR) and
7
- goes with `copilotz@1.0.0-rc.54`. Every docs page is Markdown at
7
+ goes with `copilotz@1.0.0-rc.55`. Every docs page is Markdown at
8
8
  `https://copilotz.com/docs/<slug>.md`, and https://copilotz.com/llms.txt lists them all. When you're
9
9
  unsure of a name, fetch its page or read the package's types (`node_modules/copilotz/**/*.d.ts`).
10
10
  Don't guess.
@@ -64,12 +64,12 @@ There's no project generator. Set a project up as the docs' courses do, on Node
64
64
  ```sh
65
65
  mkdir my-app && cd my-app
66
66
  npm init -y && npm pkg set type=module
67
- npm install copilotz@1.0.0-rc.54 react@19 react-dom@19
67
+ npm install copilotz@1.0.0-rc.55 react@19 react-dom@19
68
68
  npm install -D typescript @types/node @types/react @types/react-dom esbuild
69
69
  ```
70
70
 
71
71
  Pin the version: npm's `latest` tag still points at an early release candidate. On Deno, run
72
- `deno add jsr:@copilotz/copilotz` and map `"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.54"` in
72
+ `deno add jsr:@copilotz/copilotz` and map `"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.55"` in
73
73
  `deno.json`, so imports read the same.
74
74
 
75
75
  Node runs `.ts` files as they are, so there's no build step. It doesn't run `.tsx`: tests that load
@@ -110,7 +110,7 @@ line `@AGENTS.md` (Claude Code reads `CLAUDE.md`, and follows the import). Keep
110
110
  ```markdown
111
111
  # AGENTS.md
112
112
 
113
- This app runs on Copilotz (copilotz@1.0.0-rc.54). Read node_modules/copilotz/AGENTS.md first;
113
+ This app runs on Copilotz (copilotz@1.0.0-rc.55). Read node_modules/copilotz/AGENTS.md first;
114
114
  https://copilotz.com/llms.txt lists the docs, as Markdown.
115
115
 
116
116
  - `npm test` runs every test offline, with a scripted model: run it after each change.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,71 @@
1
+ ## 1.0.0-rc.55 — 2026-11-18
2
+
3
+ What an app's first minutes ask of Copilotz: a welcome, a team people can shape, models chosen by
4
+ budget rather than agent by agent, and keys of a person's own.
5
+
6
+ **Breaking, in small ways:**
7
+
8
+ - **Tiers are templates; agents hold no model where tiers apply.** Each agent does a kind of work
9
+ (one of the app's: a tier's keys, titled by the new `tierKinds` resource; or the org's own), and
10
+ the tier in force gives that kind its model chain. Agents people make do a kind too (`like`), no
11
+ longer keeping a model of their own. `tiers.pick` and per-agent picks (`modelChoice.custom`) are
12
+ gone: an org changes a tier's chain for a kind (`tiers.save`), for every agent of that kind. With
13
+ no tier chosen anywhere, the app's first applies.
14
+ - **`modelChoice.offered` answers by kind of work**: each tier's `kinds` (in place of `agents`),
15
+ `kinds` with the app's agents of each, `removed`, and `now` as `{ tier, by }`. `modelChoice.agent`
16
+ answers an agent's kind, the tier in force and its chain. The page prices a typical **message**
17
+ where the app measured one (`typicalMessage`), else a reply.
18
+ - **`agentsNamed` asks `agentSources` first**: a source's answer for one of the app's agents is an
19
+ org's own version of it, over the app's.
20
+
21
+ **Which tier, and an org's own tiers:**
22
+
23
+ - **Every conversation runs on a tier**, the first that applies: the conversation's, the person's
24
+ own default for new chats, the space's, the org's, the plan's (`tiers.choose { thread }`,
25
+ `{ mine }`, `{ space }`, `{}`). Chat passes the conversation to `agentModel`.
26
+ - **An org's tiers:** its version of one of the app's (a kind's chain, its name), new ones made from
27
+ another (`tiers.save`), the app's taken away and put back (`tiers.remove`, `tiers.restore`), kinds
28
+ of work of its own based on the app's (`tiers.kind`), and a cap on what its members choose
29
+ (`tiers.cap`). A chain set by hand keeps the `maxTokens` and `effort` of the one it replaces.
30
+ - **A typical message, measured** (`typicalMessage`: each agent's calls and tokens per message) and
31
+ **what the plan gives** (`planCredits`, credits' new `billing.credits`): the tiers say what a
32
+ message comes to, and how far the credits go. A ChatGPT-plan entry is priced at the next that
33
+ costs something.
34
+ - **On the web:** the org's Agents page (tier cards with each kind's model and fallbacks, Customize,
35
+ New tier, the members' cap, and on Free how much faster a heavier tier spends), a tier picker
36
+ beside the send button (chat's new `composerControls`), a space's default tier, and `tiers.setup`,
37
+ a short choice for a new org. Every word is the app's (`tiers.<key>`).
38
+
39
+ **The org's team** (`@copilotz/team`):
40
+
41
+ - **Every org starts with the app's agents; its owners and admins shape them.** Changing one keeps
42
+ the org's version under its name (`agent.update`); `agent.delete` takes it off the team (it leaves
43
+ every space, joins no new one), `agent.restore` puts it back, `agent.reset` drops the org's
44
+ changes. An agent made for the org (`in: "*"`) works in every space and joins new ones. Spaces
45
+ seat the org's team as they're made.
46
+ - **Making an agent starts from what it should do:** `agent.sketch` drafts its name, emoji,
47
+ description, instructions and kind of work in one quick call (the app's `cheap` model), for the
48
+ person to check; the form asks for a kind of work instead of a model where tiers apply.
49
+ - **An agent proposes one** (`propose_agent`): its person is asked as chat asks for everything, and
50
+ it's made only on their yes, where they could have made it themselves.
51
+
52
+ **A welcome, and keys of one's own:**
53
+
54
+ - **Chat's `welcome`:** steps an app and its front ends add (a View each, with roles and kinds of
55
+ org), shown once per person per org over home, in a dialog; `/?welcome=1` shows it again
56
+ (`chat.welcomed`, `welcome.seen`). Credits adds a plan step for a new team org (`billing.setup`),
57
+ whose payment page comes back to the welcome (`billing.checkout`'s new `back`).
58
+ - **A person's own API keys** (`modelKey.set { mine }`): any provider a key can be brought for; a
59
+ model call for them uses theirs, then the org's, then the app's. The Connected accounts page lists
60
+ them, and says where the org's tiers use each provider's models.
61
+
62
+ **Words:**
63
+
64
+ - **`sayText`** (`copilotz/web/words`): text the app's data holds, in the app's words where it gives
65
+ them under `text.` and the English (a tier's description, a kind of work, an agent's description);
66
+ else as it is. The tiers' and team's pages say them so.
67
+ - **The tiers' prices follow the page's language** ("2,3¢" in Portuguese).
68
+
1
69
  ## 1.0.0-rc.54 — 2026-11-17
2
70
 
3
71
  What a business app's screens still asked of the toolkit and of e-mail, and the docs that show a
package/README.md CHANGED
@@ -152,7 +152,7 @@ ana sees: Tue 10:00, Wed 15:00
152
152
  ```sh
153
153
  npm install copilotz@next # Node 24+ (npm, pnpm, yarn)
154
154
  bun add copilotz@next # Bun
155
- deno add jsr:@copilotz/copilotz@^1.0.0-rc.54 # Deno 2.9+ (or `deno add npm:copilotz@next`)
155
+ deno add jsr:@copilotz/copilotz@^1.0.0-rc.55 # Deno 2.9+ (or `deno add npm:copilotz@next`)
156
156
  ```
157
157
 
158
158
  Until 1.0, the release candidates are on npm's `next` tag, and a plain `npm install copilotz` or
@@ -166,7 +166,7 @@ OPENAI_API_KEY=sk-… node salon.ts # or bun salon.ts, or deno run -A salon.t
166
166
  ```
167
167
 
168
168
  On Deno, map the name `copilotz` in `deno.json`
169
- (`"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.54"`) so the imports read the same everywhere.
169
+ (`"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.55"`) so the imports read the same everywhere.
170
170
  Copilotz runs on Node 24+, Deno 2.9+ and Bun, and it's built on web standards for Cloudflare Workers
171
171
  and the browser.
172
172
 
@@ -11,7 +11,7 @@
11
11
  */
12
12
  export { go, signOut, web, type WebOptions, type Where, type Who } from "./host.js";
13
13
  export { appBase } from "./base.js";
14
- export { type Blanks, defineWords, fill, formatDate, formatDateTime, formatList, formatNumber, formatTime, knownWords, lang, type Phrase, type Say, setWords, type Words, wordsOf, } from "./words.js";
14
+ export { type Blanks, defineWords, fill, formatDate, formatDateTime, formatList, formatNumber, formatTime, knownWords, lang, type Phrase, type Say, sayText, setWords, type Words, wordsOf, } from "./words.js";
15
15
  export { message, node, Part } from "./part.js";
16
16
  export { display, type DisplayMode, openLink, remind, surface, tell, useRefresh, } from "./surface.js";
17
17
  export { LazyView } from "./lazy.js";
package/hosts/web/mod.js CHANGED
@@ -12,7 +12,7 @@
12
12
  export { go, signOut, web } from "./host.js";
13
13
  export { appBase } from "./base.js";
14
14
  // The words every front end says, by key: the app's `words` resource over the English.
15
- export { defineWords, fill, formatDate, formatDateTime, formatList, formatNumber, formatTime, knownWords, lang, setWords, wordsOf, } from "./words.js";
15
+ export { defineWords, fill, formatDate, formatDateTime, formatList, formatNumber, formatTime, knownWords, lang, sayText, setWords, wordsOf, } from "./words.js";
16
16
  export { message, node, Part } from "./part.js";
17
17
  // Where Views are drawn (the page, or a widget in an outside assistant), and what a widget asks of
18
18
  // its host: no-ops on the page.
@@ -161,6 +161,10 @@ export const chat = {
161
161
  "chat.notFoundTitle": "Conversa não encontrada",
162
162
  "chat.notInSpace": "Você não está neste espaço",
163
163
  "chat.notInSpaceBody": "As conversas daqui são para os membros. Escolha um dos seus espaços para começar uma, ou peça a alguém daqui para convidar você.",
164
+ "chat.welcomeStep": "{at} de {count}",
165
+ "chat.welcomeBack": "Voltar",
166
+ "chat.welcomeNext": "Próximo",
167
+ "chat.welcomeDone": "Começar",
164
168
  "chat.notYourSpaceTitle": "Este espaço não é seu",
165
169
  "chat.ofMinutes": {
166
170
  one: ", de no máximo {count} minuto",
@@ -60,6 +60,13 @@ export declare const fill: (text: string, blanks: Blanks) => string;
60
60
  export declare function wordsOf(plugins: Plugins): Words;
61
61
  /** Sets the words the page says (`web` does, from its plugins); returns how to put back what was. */
62
62
  export declare function setWords(words: Words): () => void;
63
+ /**
64
+ * Text the app's data holds, in the app's words when it gives them: what the server sends as the
65
+ * app declared it (a tier's description, a kind of work's title, an agent's description). The
66
+ * app gives them under `text.` and the English as it is (`"text.Quick answers.": "Respostas
67
+ * rápidas."`); text it gives none for (one an org wrote) shows as it is.
68
+ */
69
+ export declare function sayText(text: string): string;
63
70
  /** Every key Copilotz's front ends define (those loaded), with its English. */
64
71
  export declare const knownWords: () => Record<string, Phrase>;
65
72
  /** The page's language (its `<html lang>`), English unless said. */
@@ -98,6 +98,16 @@ export function setWords(words) {
98
98
  given = before;
99
99
  };
100
100
  }
101
+ /**
102
+ * Text the app's data holds, in the app's words when it gives them: what the server sends as the
103
+ * app declared it (a tier's description, a kind of work's title, an agent's description). The
104
+ * app gives them under `text.` and the English as it is (`"text.Quick answers.": "Respostas
105
+ * rápidas."`); text it gives none for (one an org wrote) shows as it is.
106
+ */
107
+ export function sayText(text) {
108
+ const phrase = given[`text.${text}`];
109
+ return phrase === undefined ? text : render(phrase);
110
+ }
101
111
  /** Every key Copilotz's front ends define (those loaded), with its English. */
102
112
  export const knownWords = () => Object.fromEntries(english);
103
113
  /** The page's language (its `<html lang>`), English unless said. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "copilotz",
3
- "version": "1.0.0-rc.54",
3
+ "version": "1.0.0-rc.55",
4
4
  "description": "The open-source runtime that makes your app usable by people, your own agents and their assistants.",
5
5
  "keywords": [
6
6
  "agents",
@@ -2,8 +2,14 @@
2
2
  * An org's own keys for model providers (see collections/model-key.ts), as the
3
3
  * models plugin's `modelKeys` resource names them. Its owners and admins change
4
4
  * them, in person: `modelKey.set` `{ provider, key }` and `modelKey.remove`
5
- * `{ provider }`; `modelKey.may` says whether the person asking can. For
6
- * trusted code only: `modelKey.list` (nothing secret) and `modelKey.open`.
5
+ * `{ provider }`; `modelKey.may` says whether the person asking can.
6
+ *
7
+ * A person's own (`mine`): any person keeps keys of their own the same way
8
+ * (`modelKey.set { provider, key, mine: true }`, `modelKey.remove { …, mine }`),
9
+ * listed to them alone (`modelKey.mine`); a model call for them (made by them,
10
+ * or an agent working for them) uses theirs first, then the org's, then the
11
+ * app's. For trusted code only: `modelKey.list` (the org's, nothing secret)
12
+ * and `modelKey.open` `{ provider, person? }`.
7
13
  *
8
14
  * All unrecorded: a key is in no event, as its input or its answer.
9
15
  */
@@ -12,8 +18,10 @@ import { runsOrg } from "../../spaces/contract.js";
12
18
  import { seal, unseal } from "../shared/seal.js";
13
19
  import { settingsOf } from "../shared/settings.js";
14
20
  const keysOf = (ctx) => ctx.as().db.collection("modelKey");
15
- /** What a sealed key is bound to, so it can't be moved to another provider or org. */
16
- const boundTo = (ctx, provider) => `modelKey:${ctx.resources.org?.id ?? ""}:${provider}`;
21
+ /** What a sealed key is bound to, so it can't be moved to another provider, org or person. */
22
+ const boundTo = (ctx, provider, person) => `modelKey:${ctx.resources.org?.id ?? ""}:${person ? `person:${person}:` : ""}${provider}`;
23
+ /** Where a person's own key for a provider is kept. */
24
+ const ownId = (person, provider) => `person:${person}:${provider}`;
17
25
  /** Whether whoever asks runs the org: only they change its keys. */
18
26
  const runs = (ctx) => ctx.call("org.me", {})
19
27
  .then((me) => !!me.staff || runsOrg(me.role ?? null), () => false);
@@ -21,33 +29,45 @@ const SHOW = 4;
21
29
  /** A long key's last characters, to tell it apart; a short one shows nothing of itself. */
22
30
  const hintOf = (key) => key.length >= 16 ? `••••${key.slice(-SHOW)}` : "••••";
23
31
  export const modelKeySet = defineAction({
24
- description: "Adds or replaces the org's own key for a model provider",
32
+ description: "Adds or replaces a key for a model provider: the org's, or your own (mine)",
25
33
  record: false,
26
34
  input: {
27
35
  type: "object",
28
36
  properties: {
29
37
  provider: { type: "string" },
30
38
  key: { type: "string", minLength: 1, maxLength: 4096 },
39
+ /** Your own, used when agents work for you; else the org's. */
40
+ mine: { type: "boolean" },
31
41
  },
32
42
  required: ["provider", "key"],
33
43
  additionalProperties: false,
34
44
  },
35
45
  allow: inPerson,
36
46
  run: async (ctx, input) => {
37
- if (!await runs(ctx))
47
+ const person = input.mine ? ctx.actor.id : undefined;
48
+ if (!person && !await runs(ctx)) {
38
49
  throw forbidden("Only the org's owners and admins change its keys.");
50
+ }
39
51
  if (!await ctx.call("models.keyable", { provider: input.provider })) {
40
52
  throw invalid(`A key can't be added for "${input.provider}".`);
41
53
  }
42
54
  const key = input.key.trim();
43
55
  if (!key || /\s/.test(key))
44
56
  throw invalid("That doesn't look like a key.");
45
- const sealed = await seal(settingsOf(ctx).key, boundTo(ctx, input.provider), {
57
+ const sealed = await seal(settingsOf(ctx).key, boundTo(ctx, input.provider, person), {
46
58
  access: key,
47
59
  account: input.provider,
48
60
  });
49
61
  const hint = hintOf(key);
50
- await keysOf(ctx).updateOne({ _id: input.provider }, { $set: { sealed, hint, by: ctx.actor.id, at: new Date().toISOString() } }, { upsert: true });
62
+ await keysOf(ctx).updateOne({ _id: person ? ownId(person, input.provider) : input.provider }, {
63
+ $set: {
64
+ sealed,
65
+ hint,
66
+ by: ctx.actor.id,
67
+ ...(person ? { person, provider: input.provider } : {}),
68
+ at: new Date().toISOString(),
69
+ },
70
+ }, { upsert: true });
51
71
  return { provider: input.provider, hint };
52
72
  },
53
73
  });
@@ -56,12 +76,16 @@ export const modelKeyRemove = defineAction({
56
76
  record: false,
57
77
  input: {
58
78
  type: "object",
59
- properties: { provider: { type: "string" } },
79
+ properties: { provider: { type: "string" }, mine: { type: "boolean" } },
60
80
  required: ["provider"],
61
81
  additionalProperties: false,
62
82
  },
63
83
  allow: inPerson,
64
84
  run: async (ctx, input) => {
85
+ if (input.mine) {
86
+ await keysOf(ctx).deleteOne({ _id: ownId(ctx.actor.id, input.provider) });
87
+ return { removed: true };
88
+ }
65
89
  if (!await runs(ctx))
66
90
  throw forbidden("Only the org's owners and admins change its keys.");
67
91
  await keysOf(ctx).deleteOne({ _id: input.provider });
@@ -79,7 +103,7 @@ export const modelKeyMay = defineAction({
79
103
  export const modelKeyList = defineAction({
80
104
  record: false,
81
105
  input: { type: "object", additionalProperties: false },
82
- run: async (ctx) => (await keysOf(ctx).find({})).map((k) => ({
106
+ run: async (ctx) => (await keysOf(ctx).find({ person: { $exists: false } })).map((k) => ({
83
107
  provider: k._id,
84
108
  ...(k.hint ? { hint: k.hint } : {}),
85
109
  })),
@@ -88,15 +112,19 @@ export const modelKeyOpen = defineAction({
88
112
  record: false,
89
113
  input: {
90
114
  type: "object",
91
- properties: { provider: { type: "string" } },
115
+ properties: { provider: { type: "string" }, person: { type: "string" } },
92
116
  required: ["provider"],
93
117
  additionalProperties: false,
94
118
  },
95
119
  run: async (ctx, input) => {
96
- const found = await keysOf(ctx).findOne({ _id: input.provider });
120
+ // The person's own first, then the org's.
121
+ const own = input.person
122
+ ? await keysOf(ctx).findOne({ _id: ownId(input.person, input.provider) })
123
+ : null;
124
+ const found = own ?? await keysOf(ctx).findOne({ _id: input.provider });
97
125
  if (!found)
98
126
  return null;
99
- const { access } = await unseal(settingsOf(ctx).key, boundTo(ctx, input.provider), found.sealed);
127
+ const { access } = await unseal(settingsOf(ctx).key, boundTo(ctx, input.provider, own ? input.person : undefined), found.sealed);
100
128
  return access;
101
129
  },
102
130
  });
@@ -1,8 +1,10 @@
1
1
  /**
2
- * An org's own key for a model provider (`_id`, the provider's id): sealed, in
3
- * a private field, as an account's tokens are, with its last characters to tell
4
- * it apart. Nobody reads the collection: `modelKey.list` says what's kept, and
5
- * `modelKey.open` opens one for a model call.
2
+ * An org's own key for a model provider (`_id`, the provider's id), or a
3
+ * person's own (`person:<id>:<provider>`, with `person` and `provider`):
4
+ * sealed, in a private field, as an account's tokens are, with its last
5
+ * characters to tell it apart. Nobody reads the collection: `modelKey.list`
6
+ * says what the org keeps, the query `mine` what the person asking keeps
7
+ * (never the key), and `modelKey.open` opens one for a model call.
6
8
  */
7
9
  import { type Infer } from "../../../../runtime/mod.js";
8
10
  declare const modelKeySchema: {
@@ -11,6 +13,13 @@ declare const modelKeySchema: {
11
13
  readonly hint: {
12
14
  readonly type: "string";
13
15
  };
16
+ /** A person's own: whose, and for which provider. */
17
+ readonly person: {
18
+ readonly type: "string";
19
+ };
20
+ readonly provider: {
21
+ readonly type: "string";
22
+ };
14
23
  readonly by: {
15
24
  readonly type: "string";
16
25
  };
@@ -27,6 +36,13 @@ export declare const modelKey: {
27
36
  readonly hint: {
28
37
  readonly type: "string";
29
38
  };
39
+ /** A person's own: whose, and for which provider. */
40
+ readonly person: {
41
+ readonly type: "string";
42
+ };
43
+ readonly provider: {
44
+ readonly type: "string";
45
+ };
30
46
  readonly by: {
31
47
  readonly type: "string";
32
48
  };
@@ -43,6 +59,8 @@ export declare const modelKey: {
43
59
  private?: string[];
44
60
  queries?: Record<string, import("../../../../runtime/define.js").QueryDef<{
45
61
  [x: string]: unknown;
62
+ person?: string | undefined;
63
+ provider?: string | undefined;
46
64
  hint?: string | undefined;
47
65
  at: string;
48
66
  by: string;
@@ -1,17 +1,42 @@
1
1
  /**
2
- * An org's own key for a model provider (`_id`, the provider's id): sealed, in
3
- * a private field, as an account's tokens are, with its last characters to tell
4
- * it apart. Nobody reads the collection: `modelKey.list` says what's kept, and
5
- * `modelKey.open` opens one for a model call.
2
+ * An org's own key for a model provider (`_id`, the provider's id), or a
3
+ * person's own (`person:<id>:<provider>`, with `person` and `provider`):
4
+ * sealed, in a private field, as an account's tokens are, with its last
5
+ * characters to tell it apart. Nobody reads the collection: `modelKey.list`
6
+ * says what the org keeps, the query `mine` what the person asking keeps
7
+ * (never the key), and `modelKey.open` opens one for a model call.
6
8
  */
7
- import { defineCollection } from "../../../../runtime/mod.js";
9
+ import { defineCollection, people, personOf } from "../../../../runtime/mod.js";
8
10
  const modelKeySchema = {
9
11
  type: "object",
10
12
  properties: {
11
13
  hint: { type: "string" },
14
+ /** A person's own: whose, and for which provider. */
15
+ person: { type: "string" },
16
+ provider: { type: "string" },
12
17
  by: { type: "string" },
13
18
  at: { type: "string" },
14
19
  },
15
20
  required: ["by", "at"],
16
21
  };
17
- export const modelKey = defineCollection({ schema: modelKeySchema, private: ["sealed"] });
22
+ export const modelKey = defineCollection({
23
+ schema: modelKeySchema,
24
+ private: ["sealed"],
25
+ queries: {
26
+ /** `mine` `{}`: the person's own keys: each provider, and its last characters. */
27
+ mine: {
28
+ allow: people,
29
+ run: async (keys, _, ctx) => {
30
+ const person = personOf(ctx.actor);
31
+ if (!person)
32
+ return [];
33
+ const found = await keys.find({ person });
34
+ return found.map((k) => ({
35
+ provider: k.provider ?? k._id,
36
+ ...(k.hint ? { hint: k.hint } : {}),
37
+ at: k.at,
38
+ }));
39
+ },
40
+ },
41
+ },
42
+ });
@@ -10,12 +10,13 @@
10
10
  import { failure } from "../../../../runtime/mod.js";
11
11
  const NOBODY = { _id: { $in: [] } };
12
12
  export const rules = (actor, { collection, access, direct }) => {
13
- if (collection === "account" && direct && access === "write") {
14
- throw failure("forbidden", "Accounts change through their Actions.", { public: true });
13
+ if ((collection === "account" || collection === "modelKey") && direct && access === "write") {
14
+ throw failure("forbidden", "Accounts and keys change through their Actions.", { public: true });
15
15
  }
16
- return collection === "account"
16
+ // A person reads their own accounts, and their own keys (never a key itself: it's private).
17
+ return collection === "account" || collection === "modelKey"
17
18
  ? actor.kind === "person" ? { person: actor.id } : NOBODY
18
- : collection === "accountFlow" || collection === "modelKey"
19
+ : collection === "accountFlow"
19
20
  ? NOBODY
20
21
  : undefined;
21
22
  };
@@ -27,7 +27,9 @@ export const accountsView = (_, ctx) => {
27
27
  if (!providers || !accounts) {
28
28
  return (_jsxs(Page, { title: TITLE, description: ABOUT, icon: "lock", density: density, children: [_jsx(Title, { text: TITLE }), style, _jsx("div", { className: "account-skeleton", "aria-busy": "true", children: _jsx(Skeleton, { height: 112, radius: "xl" }) })] }));
29
29
  }
30
- return (_jsxs(Page, { title: TITLE, description: ABOUT, icon: "lock", density: density, children: [_jsx(Title, { text: TITLE }), style, _jsx(AccountsBody, { providers: providers, accounts: accounts, query: query, call: ctx.call })] }));
30
+ // The person's own API keys, below their accounts (`accounts.keys`).
31
+ const keys = ctx.show("accounts.keys", {});
32
+ return (_jsxs(Page, { title: TITLE, description: ABOUT, icon: "lock", density: density, children: [_jsx(Title, { text: TITLE }), style, _jsx(AccountsBody, { providers: providers, accounts: accounts, query: query, call: ctx.call }), keys] }));
31
33
  };
32
34
  function AccountsBody({ providers, accounts, query, call }) {
33
35
  const asked = providers.some((p) => p.name === query.connect) ? query.connect : undefined;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The person's own API keys, on the Connected accounts page: for any provider
3
+ * a key can be brought for, theirs alone (`modelKey.set { mine }`): agents
4
+ * working for them use it for that provider's models, before the org's key and
5
+ * the app's, and the org isn't charged for those calls. Each key shows its
6
+ * last characters, and where the org's tiers use that provider's models
7
+ * ("Used for Decides and Checks on Everyday"), or that none does yet, so a key
8
+ * that would sit unused says so. Removing one is in place.
9
+ */
10
+ import { type ReactNode } from "react";
11
+ import type { ViewContext } from "../../../../../runtime/mod.js";
12
+ export declare const ownKeysView: (_: unknown, ctx: ViewContext<ReactNode>) => ReactNode;
@@ -0,0 +1,112 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The person's own API keys, on the Connected accounts page: for any provider
4
+ * a key can be brought for, theirs alone (`modelKey.set { mine }`): agents
5
+ * working for them use it for that provider's models, before the org's key and
6
+ * the app's, and the org isn't charged for those calls. Each key shows its
7
+ * last characters, and where the org's tiers use that provider's models
8
+ * ("Used for Decides and Checks on Everyday"), or that none does yet, so a key
9
+ * that would sit unused says so. Removing one is in place.
10
+ */
11
+ import { useState } from "react";
12
+ import { Button, Card, Field, Input, message, Notice, Select, Skeleton, } from "../../../../../hosts/web/mod.js";
13
+ export const ownKeysView = (_, ctx) => {
14
+ const mine = ctx.db.collection("modelKey").query("mine", {}).value;
15
+ // Where the tiers use each provider (their front end says where to read them: `agentKinds`).
16
+ const asked = !!ctx.resources.agentKinds?.query;
17
+ const tiers = asked
18
+ ? ctx.db.collection("modelChoice").query("offered", {}).value
19
+ : undefined;
20
+ if (!mine || (asked && !tiers))
21
+ return _jsx(Skeleton, { height: 120, radius: "xl" });
22
+ return _jsx(OwnKeys, { mine: mine, tiers: tiers, call: ctx.call });
23
+ };
24
+ /** Where the org's default tier uses a provider's models: "Decides and Checks on Everyday". */
25
+ function usedFor(tiers, provider) {
26
+ if (!tiers?.now)
27
+ return undefined;
28
+ const tier = tiers.tiers.find((t) => t.name === tiers.now.tier);
29
+ if (!tier)
30
+ return undefined;
31
+ const ours = (id) => id.startsWith(`${provider}/`);
32
+ const kinds = tier.kinds.filter((k) => ours(k.model.id) || (k.model.fallbacks ?? []).some((f) => ours(f.id))).map((k) => tiers.kinds.find((t) => t.kind === k.kind)?.title ?? k.kind);
33
+ if (!kinds.length)
34
+ return undefined;
35
+ const list = kinds.length === 1
36
+ ? kinds[0]
37
+ : `${kinds.slice(0, -1).join(", ")} and ${kinds.at(-1)}`;
38
+ return `Used for ${list} on ${tier.title}`;
39
+ }
40
+ function OwnKeys({ mine, tiers, call }) {
41
+ const [providers, setProviders] = useState();
42
+ const [adding, setAdding] = useState(false);
43
+ const [provider, setProvider] = useState("");
44
+ const [key, setKey] = useState("");
45
+ const [busy, setBusy] = useState();
46
+ const [error, setError] = useState();
47
+ const nameOf = (id) => providers?.find((p) => p.id === id)?.name ?? id;
48
+ const open = async () => {
49
+ setAdding(true);
50
+ setError(undefined);
51
+ if (providers)
52
+ return;
53
+ try {
54
+ const listed = await call("models.offered", {});
55
+ const keyed = listed.providers.filter((p) => p.keyed);
56
+ setProviders(keyed);
57
+ setProvider(keyed[0]?.id ?? "");
58
+ }
59
+ catch (e) {
60
+ setError(message(e));
61
+ }
62
+ };
63
+ const save = async () => {
64
+ if (!provider || key.trim().length < 8)
65
+ return;
66
+ setBusy("save");
67
+ setError(undefined);
68
+ try {
69
+ await call("modelKey.set", { provider, key: key.trim(), mine: true });
70
+ setKey("");
71
+ setAdding(false);
72
+ }
73
+ catch (e) {
74
+ setError(message(e));
75
+ }
76
+ finally {
77
+ setBusy(undefined);
78
+ }
79
+ };
80
+ const remove = async (id) => {
81
+ setBusy(id);
82
+ setError(undefined);
83
+ try {
84
+ await call("modelKey.remove", { provider: id, mine: true });
85
+ }
86
+ catch (e) {
87
+ setError(message(e));
88
+ }
89
+ finally {
90
+ setBusy(undefined);
91
+ }
92
+ };
93
+ return (_jsxs(Card, { as: "section", className: "own-keys", "aria-labelledby": "own-keys", children: [_jsxs("header", { className: "own-keys-head", children: [_jsxs("div", { children: [_jsx("h2", { id: "own-keys", children: "Your own API keys" }), _jsx("p", { children: "Agents working for you use your key for that provider's models, before your org's. Your org isn't charged for those calls, and nobody else can use it." })] }), adding
94
+ ? null
95
+ : (_jsx(Button, { size: "sm", variant: "secondary", icon: "plus", onClick: () => void open(), children: "Add a key" }))] }), error ? _jsx(Notice, { tone: "destructive", role: "alert", children: error }) : null, mine.length
96
+ ? (_jsx("ul", { className: "own-keys-list", children: mine.map((k) => {
97
+ const used = usedFor(tiers, k.provider);
98
+ return (_jsxs("li", { children: [_jsxs("div", { className: "own-keys-text", children: [_jsx("b", { children: nameOf(k.provider) }), _jsx("span", { className: "own-keys-hint", children: k.hint ?? "••••" }), _jsx("span", { className: "own-keys-used", "data-unused": used ? undefined : true, children: used ?? (tiers
99
+ ? "No tier your org uses runs this provider's models yet."
100
+ : "Used for this provider's models.") })] }), _jsx(Button, { size: "sm", variant: "ghost", loading: busy === k.provider, onClick: () => void remove(k.provider), children: "Remove" })] }, k.provider));
101
+ }) }))
102
+ : adding
103
+ ? null
104
+ : _jsx("p", { className: "own-keys-none", children: "No keys of your own." }), adding
105
+ ? (_jsxs("form", { className: "own-keys-add", onSubmit: (e) => {
106
+ e.preventDefault();
107
+ void save();
108
+ }, children: [_jsx(Field, { label: "Provider", children: (control) => providers
109
+ ? (_jsx(Select, { ...control, value: provider, onChange: (e) => setProvider(e.target.value), children: providers.map((p) => _jsx("option", { value: p.id, children: p.name }, p.id)) }))
110
+ : _jsx(Skeleton, { height: 36 }) }), _jsx(Field, { label: "API key", hint: "Kept sealed; only its last characters are ever shown.", children: (control) => (_jsx(Input, { ...control, type: "password", autoComplete: "off", value: key, onChange: (e) => setKey(e.target.value), placeholder: "sk-\u2026" })) }), _jsxs("div", { className: "own-keys-end", children: [_jsx(Button, { variant: "ghost", onClick: () => setAdding(false), children: "Cancel" }), _jsx(Button, { type: "submit", variant: "primary", loading: busy === "save", disabled: !provider || key.trim().length < 8, children: "Save key" })] })] }))
111
+ : null] }));
112
+ }
@@ -3,4 +3,4 @@
3
3
  * providers, each a card (who the account is, beneath), connecting in a
4
4
  * dialog of steps, and the quiet line over a chat's composer.
5
5
  */
6
- export declare const STYLE = "\n.accounts { display: grid; gap: 14px; }\n.accounts-list { list-style: none; display: grid; gap: 12px; margin: 0; padding: 0; }\n.accounts-foot { display: flex; align-items: flex-start; gap: 8px; margin: 6px 2px 0; color: var(--muted-foreground);\n font-size: 13px; line-height: 1.5; }\n.accounts-foot .copilotz-icon { flex: none; margin-top: 2px; }\n\n.account { overflow: hidden; }\n.account-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 4px 14px;\n padding: 18px 18px 16px; }\n.account-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: var(--radius-lg);\n background: var(--primary-soft); color: var(--primary-text); }\n.account-titles { min-width: 0; }\n.account-title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0;\n font-family: var(--font-display); font-size: 16.5px; font-weight: 650; letter-spacing: -.01em; line-height: 1.3; }\n.account-allows { margin: 3px 0 0; color: var(--muted-foreground); font-size: 14px; line-height: 1.5; }\n.account-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }\n.account-who { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--border);\n background: color-mix(in oklab, var(--muted) 45%, var(--card)); }\n.account-who-text { flex: 1; min-width: 0; display: grid; gap: 1px; }\n.account-label { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }\n.account-facts { color: var(--muted-foreground); font-size: 13px; }\n.account-problem { margin: 0 18px 16px; }\n.account-skeleton { display: grid; gap: 12px; }\n@container copilotz-page (max-width: 560px) {\n .account-head { grid-template-columns: auto minmax(0, 1fr); padding: 16px 16px 14px; }\n .account-actions { grid-column: 1 / -1; justify-content: flex-start; margin-top: 10px; }\n .account-who { padding: 12px 16px; }\n .account-problem { margin: 0 16px 14px; }\n}\n\n.accounts-steps { list-style: none; display: grid; gap: 18px; margin: 4px 0 0; padding: 0; }\n.accounts-step { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 12px; }\n.accounts-step-number { display: grid; place-items: center; width: 26px; height: 26px; border-radius: var(--radius-full);\n background: var(--muted); color: var(--secondary-foreground); font-size: 13px; font-weight: 650;\n transition: background-color .2s, color .2s; }\n.accounts-step-done .accounts-step-number { background: var(--success-soft); color: var(--success-text); }\n.accounts-step-body { display: grid; gap: 10px; min-width: 0; padding-top: 2px; }\n.accounts-step-body > p { margin: 0; line-height: 1.55; }\n.accounts-step-body code { font-size: .9em; overflow-wrap: anywhere; }\n.accounts-step-later { opacity: .62; transition: opacity .2s; }\n.accounts-sign-in { justify-self: start; }\n.accounts-say { margin: 0; line-height: 1.55; }\n.accounts-quiet { margin: 0; color: var(--muted-foreground); font-size: 13px; line-height: 1.5; }\n.accounts-intro { margin: 0 0 18px; }\n.accounts-done { display: flex; align-items: center; gap: 14px; padding: 6px 0 2px; }\n.accounts-done-icon { display: grid; place-items: center; flex: none; width: 46px; height: 46px;\n border-radius: var(--radius-full); background: var(--success-soft); color: var(--success-text); }\n.accounts-done-title { margin: 0; font-size: 16px; font-weight: 650; }\n.accounts-done-who { margin: 2px 0 0; color: var(--muted-foreground); font-size: 13.5px; overflow-wrap: anywhere; }\n.accounts-done-next { margin: 14px 0 0; line-height: 1.55; }\n\n.accounts-uses { display: flex; justify-content: flex-end; margin: 0 8px -4px; font-size: 12.5px; line-height: 1.4; }\n.accounts-uses a { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 3px 9px;\n border-radius: var(--radius-full); color: var(--muted-foreground); text-decoration: none;\n transition: background-color .15s, color .15s; }\n.accounts-uses a:hover { background: var(--accent); color: var(--accent-foreground); }\n.accounts-uses span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.accounts-uses-plan .copilotz-icon { flex: none; color: var(--primary-text); }\n.accounts-uses-reconnect a { color: var(--warning-text); }\n";
6
+ export declare const STYLE = "\n.accounts { display: grid; gap: 14px; }\n.accounts-list { list-style: none; display: grid; gap: 12px; margin: 0; padding: 0; }\n.accounts-foot { display: flex; align-items: flex-start; gap: 8px; margin: 6px 2px 0; color: var(--muted-foreground);\n font-size: 13px; line-height: 1.5; }\n.accounts-foot .copilotz-icon { flex: none; margin-top: 2px; }\n\n.account { overflow: hidden; }\n.account-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 4px 14px;\n padding: 18px 18px 16px; }\n.account-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: var(--radius-lg);\n background: var(--primary-soft); color: var(--primary-text); }\n.account-titles { min-width: 0; }\n.account-title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0;\n font-family: var(--font-display); font-size: 16.5px; font-weight: 650; letter-spacing: -.01em; line-height: 1.3; }\n.account-allows { margin: 3px 0 0; color: var(--muted-foreground); font-size: 14px; line-height: 1.5; }\n.account-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }\n.account-who { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--border);\n background: color-mix(in oklab, var(--muted) 45%, var(--card)); }\n.account-who-text { flex: 1; min-width: 0; display: grid; gap: 1px; }\n.account-label { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }\n.account-facts { color: var(--muted-foreground); font-size: 13px; }\n.account-problem { margin: 0 18px 16px; }\n.account-skeleton { display: grid; gap: 12px; }\n@container copilotz-page (max-width: 560px) {\n .account-head { grid-template-columns: auto minmax(0, 1fr); padding: 16px 16px 14px; }\n .account-actions { grid-column: 1 / -1; justify-content: flex-start; margin-top: 10px; }\n .account-who { padding: 12px 16px; }\n .account-problem { margin: 0 16px 14px; }\n}\n\n.accounts-steps { list-style: none; display: grid; gap: 18px; margin: 4px 0 0; padding: 0; }\n.accounts-step { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 12px; }\n.accounts-step-number { display: grid; place-items: center; width: 26px; height: 26px; border-radius: var(--radius-full);\n background: var(--muted); color: var(--secondary-foreground); font-size: 13px; font-weight: 650;\n transition: background-color .2s, color .2s; }\n.accounts-step-done .accounts-step-number { background: var(--success-soft); color: var(--success-text); }\n.accounts-step-body { display: grid; gap: 10px; min-width: 0; padding-top: 2px; }\n.accounts-step-body > p { margin: 0; line-height: 1.55; }\n.accounts-step-body code { font-size: .9em; overflow-wrap: anywhere; }\n.accounts-step-later { opacity: .62; transition: opacity .2s; }\n.accounts-sign-in { justify-self: start; }\n.accounts-say { margin: 0; line-height: 1.55; }\n.accounts-quiet { margin: 0; color: var(--muted-foreground); font-size: 13px; line-height: 1.5; }\n.accounts-intro { margin: 0 0 18px; }\n.accounts-done { display: flex; align-items: center; gap: 14px; padding: 6px 0 2px; }\n.accounts-done-icon { display: grid; place-items: center; flex: none; width: 46px; height: 46px;\n border-radius: var(--radius-full); background: var(--success-soft); color: var(--success-text); }\n.accounts-done-title { margin: 0; font-size: 16px; font-weight: 650; }\n.accounts-done-who { margin: 2px 0 0; color: var(--muted-foreground); font-size: 13.5px; overflow-wrap: anywhere; }\n.accounts-done-next { margin: 14px 0 0; line-height: 1.55; }\n\n.accounts-uses { display: flex; justify-content: flex-end; margin: 0 8px -4px; font-size: 12.5px; line-height: 1.4; }\n.accounts-uses a { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 3px 9px;\n border-radius: var(--radius-full); color: var(--muted-foreground); text-decoration: none;\n transition: background-color .15s, color .15s; }\n.accounts-uses a:hover { background: var(--accent); color: var(--accent-foreground); }\n.accounts-uses span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.accounts-uses-plan .copilotz-icon { flex: none; color: var(--primary-text); }\n.accounts-uses-reconnect a { color: var(--warning-text); }\n\n/* The person's own API keys */\n.own-keys { display: grid; gap: 12px; margin-top: 16px; padding: 16px 18px; }\n.own-keys-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 8px 12px; }\n.own-keys-head h2 { margin: 0; font-size: 15px; font-weight: 650; }\n.own-keys-head p { max-width: 62ch; margin: 3px 0 0; color: var(--muted-foreground); font-size: 13px; line-height: 1.45; }\n.own-keys-list { display: grid; margin: 0; padding: 0; list-style: none; }\n.own-keys-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; }\n.own-keys-list li + li { border-top: 1px solid var(--border); }\n.own-keys-text { flex: 1; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; min-width: 0; font-size: 14px; }\n.own-keys-hint { color: var(--muted-foreground); font-family: var(--font-mono); font-size: 12.5px; }\n.own-keys-used { flex-basis: 100%; color: var(--success-text, var(--muted-foreground)); font-size: 12.5px; }\n.own-keys-used[data-unused] { color: var(--warning-text, var(--muted-foreground)); }\n.own-keys-none { margin: 0; color: var(--muted-foreground); font-size: 13px; }\n.own-keys-add { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 12px; }\n.own-keys-end { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; }\n@media (max-width: 560px) { .own-keys-add { grid-template-columns: minmax(0, 1fr); } }\n";