copilotz 1.0.0-rc.11 → 1.0.0-rc.13

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 (66) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +2 -2
  3. package/package.json +1 -1
  4. package/plugins/access/accounts/actions/model-key.d.ts +5 -0
  5. package/plugins/access/accounts/actions/model-key.js +102 -0
  6. package/plugins/access/accounts/collections/model-key.d.ts +58 -0
  7. package/plugins/access/accounts/collections/model-key.js +17 -0
  8. package/plugins/access/accounts/mod.d.ts +5 -0
  9. package/plugins/access/accounts/mod.js +14 -1
  10. package/plugins/access/accounts/resources/models.js +2 -0
  11. package/plugins/access/accounts/shared/rules.js +1 -1
  12. package/plugins/access/identity/collections/credential.d.ts +1 -1
  13. package/plugins/access/spaces/views/elsewhere.js +2 -5
  14. package/plugins/agents/chat/contract.d.ts +1 -0
  15. package/plugins/agents/chat/contract.js +1 -0
  16. package/plugins/agents/chat/shared/delivery.d.ts +3 -0
  17. package/plugins/agents/chat/shared/delivery.js +4 -3
  18. package/plugins/agents/chat/shared/send.js +24 -18
  19. package/plugins/agents/chat/shared/types.d.ts +2 -0
  20. package/plugins/agents/chat/shared/types.js +3 -0
  21. package/plugins/agents/chat/views/message.d.ts +2 -1
  22. package/plugins/agents/chat/views/message.js +6 -3
  23. package/plugins/agents/chat/views/web/conversation.js +4 -1
  24. package/plugins/agents/chat/views/web/message.js +5 -1
  25. package/plugins/agents/team/views/web/agent-fields.js +3 -4
  26. package/plugins/agents/team/views/web/model-picker.d.ts +19 -0
  27. package/plugins/agents/team/views/web/model-picker.js +195 -0
  28. package/plugins/agents/team/views/web/style.d.ts +2 -2
  29. package/plugins/agents/team/views/web/style.js +48 -1
  30. package/plugins/billing/usage/collections/rollup.d.ts +2 -2
  31. package/plugins/billing/usage/collections/usage.d.ts +2 -2
  32. package/plugins/compute/apps/actions/configure.js +2 -0
  33. package/plugins/compute/cloud/collections/pool-vm.d.ts +1 -1
  34. package/plugins/compute/cloud/mod.d.ts +2 -0
  35. package/plugins/compute/cloud/mod.js +5 -1
  36. package/plugins/compute/cloud/resources/tools.d.ts +3 -0
  37. package/plugins/compute/cloud/resources/tools.js +237 -0
  38. package/plugins/compute/computers/actions/allowed.js +4 -2
  39. package/plugins/compute/computers/actions/approve.js +3 -2
  40. package/plugins/compute/computers/actions/env.js +2 -0
  41. package/plugins/compute/computers/program/version.d.ts +1 -1
  42. package/plugins/compute/computers/program/version.js +1 -1
  43. package/plugins/compute/computers/resources/commands.js +3 -2
  44. package/plugins/compute/computers/resources/downloads.js +1 -1
  45. package/plugins/compute/computers/shared/ask.js +9 -5
  46. package/plugins/compute/computers/shared/settings.d.ts +4 -2
  47. package/plugins/compute/computers/shared/settings.js +2 -0
  48. package/plugins/compute/computers/shared/wake.d.ts +2 -0
  49. package/plugins/compute/computers/shared/where.d.ts +5 -1
  50. package/plugins/compute/computers/shared/where.js +4 -2
  51. package/plugins/compute/computers/views/context.js +5 -1
  52. package/plugins/compute/computers/views/web/asked.js +2 -0
  53. package/plugins/compute/computers/views/web/asks.js +3 -2
  54. package/plugins/interfaces/api/collections/key.d.ts +1 -1
  55. package/plugins/models/actions/offered.d.ts +32 -0
  56. package/plugins/models/actions/offered.js +140 -0
  57. package/plugins/models/contract.d.ts +5 -1
  58. package/plugins/models/mod.d.ts +6 -1
  59. package/plugins/models/mod.js +9 -1
  60. package/plugins/models/shared/catalog.json +9208 -8909
  61. package/plugins/models/shared/choice.d.ts +31 -0
  62. package/plugins/models/shared/choice.js +18 -2
  63. package/plugins/models/shared/generate.d.ts +1 -0
  64. package/plugins/models/shared/generate.js +36 -3
  65. package/runtime/client.js +28 -5
  66. package/runtime/executor.js +2 -2
package/CHANGELOG.md CHANGED
@@ -1,3 +1,39 @@
1
+ ## 1.0.0-rc.13 — 2026-11-01
2
+
3
+ - **Choose an agent's model from the catalog, with your own key.** The agent editor searches every
4
+ provider and model in the models.dev catalog an agent can work with (`models.offered`): those with
5
+ a protocol we speak and an address of their own. An org's owners and admins add a key for a
6
+ provider right there (`modelKey.set`): it's sealed, shows only its end, and its agents' calls to
7
+ that provider use it, over the app's. Those uses are tagged `paid: "own-key"`. The catalog now
8
+ keeps names, release dates, and which models can't call tools or answer in text.
9
+ - **Secrets stay out of the log.** `env.set` and `apps.configure` recorded their input, so a space's
10
+ or an app's secret was kept in plain text in its `action.started` event, sealed field or not. Both
11
+ are unrecorded now. Secrets set before this remain in events already written: rotate them.
12
+ - **Agents manage cloud computers.** `list_computers`, `create_computer` and `manage_computer` (add,
13
+ remove, rename, default, destroy) work in the conversation's space, as the person the agent works
14
+ for, through the same Actions and rules a person has. Nothing asks first except destroying, which
15
+ loses the disk: like publishing, it's asked every time and only "once" allows it. A person's own
16
+ machine isn't an agent's to manage. An agent in a space with no computer is told it can make one.
17
+ - **A query an Action runs knows who asks.** Named queries called from an Action or a transaction
18
+ lost the actor for what they call themselves, so a query asking another Action could fail, or
19
+ answer as though nobody asked.
20
+ - **A read's answer no longer overwrites something newer.** The owner answers a batch of reads once
21
+ its slowest is ready, so a change could be pushed before the answer that didn't include it. The
22
+ client then showed the older answer until the read next changed: on a page's first load (the push
23
+ was dropped) and after a reconnect (the push was overwritten). What's pushed while a read is asked
24
+ for now wins over its answer, and a connection that's been replaced is no longer listened to.
25
+
26
+ ## 1.0.0-rc.12 — 2026-11-01
27
+
28
+ - **An agent can hand work to itself in another space.** "Itself" now means the same agent in the
29
+ same chat: North in Personal and North in Project management are two pieces of work. Whoever a
30
+ space says answers takes what's handed there, even the agent that sent it, instead of being
31
+ skipped for someone else, so a space where only that agent answers can receive work too. It reads
32
+ what it handed over, and the answer back, as input (`You (via delegated "Solo"): …`), not as
33
+ something it said.
34
+ - **Delegated messages name the other space:** "Delegated: Personal" there, "Delegated: Project
35
+ management" back, with an icon of their own.
36
+
1
37
  ## 1.0.0-rc.11 — 2026-10-31
2
38
 
3
39
  - **A routine can run with nobody watching.** What its agent needs a yes for can now be allowed for
package/README.md CHANGED
@@ -22,7 +22,7 @@ bun add copilotz # Bun
22
22
  deno add jsr:@copilotz/copilotz # Deno (or `deno add npm:copilotz`)
23
23
  ```
24
24
 
25
- On Deno, name it `copilotz` in `deno.json` (`"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.11"`),
25
+ On Deno, name it `copilotz` in `deno.json` (`"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.13"`),
26
26
  and the imports below are the same everywhere. Some pieces need a package of their own, installed
27
27
  beside it: `esbuild` to bundle the web host on Node, `@electric-sql/pglite` for PostgreSQL in the
28
28
  process, and `@types/react` for the front ends' types.
@@ -204,7 +204,7 @@ and an app serves it from there by default:
204
204
  import { computerDownloads } from "copilotz/plugins/compute/downloads";
205
205
 
206
206
  plugins: [...plugins, await computerDownloads()], // this Copilotz's release
207
- plugins: [...plugins, await computerDownloads({ dir: "dist/computer/1.0.0-rc.11" })], // its own: /computer/download/
207
+ plugins: [...plugins, await computerDownloads({ dir: "dist/computer/1.0.0-rc.13" })], // its own: /computer/download/
208
208
  plugins: [...plugins, await computerDownloads({ url: "https://downloads.example.com/computer/" })], // or elsewhere
209
209
  ```
210
210
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "copilotz",
3
- "version": "1.0.0-rc.11",
3
+ "version": "1.0.0-rc.13",
4
4
  "description": "Copilotz: one runtime for Node, Deno, Bun, Cloudflare Workers and the browser.",
5
5
  "keywords": [
6
6
  "agents",
@@ -0,0 +1,5 @@
1
+ export declare const modelKeySet: import("../../../../runtime/define.js").ActionDef;
2
+ export declare const modelKeyRemove: import("../../../../runtime/define.js").ActionDef;
3
+ export declare const modelKeyMay: import("../../../../runtime/define.js").ActionDef;
4
+ export declare const modelKeyList: import("../../../../runtime/define.js").ActionDef;
5
+ export declare const modelKeyOpen: import("../../../../runtime/define.js").ActionDef;
@@ -0,0 +1,102 @@
1
+ /**
2
+ * An org's own keys for model providers (see collections/model-key.ts), as the
3
+ * models plugin's `modelKeys` resource names them. Its owners and admins change
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`.
7
+ *
8
+ * All unrecorded: a key is in no event, as its input or its answer.
9
+ */
10
+ import { defineAction, forbidden, inPerson, invalid, people, } from "../../../../runtime/mod.js";
11
+ import { runsOrg } from "../../spaces/contract.js";
12
+ import { seal, unseal } from "../shared/seal.js";
13
+ import { settingsOf } from "../shared/settings.js";
14
+ 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}`;
17
+ /** Whether whoever asks runs the org: only they change its keys. */
18
+ const runs = (ctx) => ctx.call("org.me", {})
19
+ .then((me) => !!me.staff || runsOrg(me.role ?? null), () => false);
20
+ const SHOW = 4;
21
+ /** A long key's last characters, to tell it apart; a short one shows nothing of itself. */
22
+ const hintOf = (key) => key.length >= 16 ? `••••${key.slice(-SHOW)}` : "••••";
23
+ export const modelKeySet = defineAction({
24
+ description: "Adds or replaces the org's own key for a model provider",
25
+ record: false,
26
+ input: {
27
+ type: "object",
28
+ properties: {
29
+ provider: { type: "string" },
30
+ key: { type: "string", minLength: 1, maxLength: 4096 },
31
+ },
32
+ required: ["provider", "key"],
33
+ additionalProperties: false,
34
+ },
35
+ allow: inPerson,
36
+ run: async (ctx, input) => {
37
+ if (!await runs(ctx))
38
+ throw forbidden("Only the org's owners and admins change its keys.");
39
+ if (!await ctx.call("models.keyable", { provider: input.provider })) {
40
+ throw invalid(`A key can't be added for "${input.provider}".`);
41
+ }
42
+ const key = input.key.trim();
43
+ if (!key || /\s/.test(key))
44
+ throw invalid("That doesn't look like a key.");
45
+ const sealed = await seal(settingsOf(ctx).key, boundTo(ctx, input.provider), {
46
+ access: key,
47
+ account: input.provider,
48
+ });
49
+ 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 });
51
+ return { provider: input.provider, hint };
52
+ },
53
+ });
54
+ export const modelKeyRemove = defineAction({
55
+ description: "Removes the org's own key for a model provider",
56
+ record: false,
57
+ input: {
58
+ type: "object",
59
+ properties: { provider: { type: "string" } },
60
+ required: ["provider"],
61
+ additionalProperties: false,
62
+ },
63
+ allow: inPerson,
64
+ run: async (ctx, input) => {
65
+ if (!await runs(ctx))
66
+ throw forbidden("Only the org's owners and admins change its keys.");
67
+ await keysOf(ctx).deleteOne({ _id: input.provider });
68
+ return { removed: true };
69
+ },
70
+ });
71
+ export const modelKeyMay = defineAction({
72
+ description: "Whether you may change the org's keys for model providers",
73
+ record: false,
74
+ input: { type: "object", additionalProperties: false },
75
+ allow: people,
76
+ run: async (ctx) => ({ set: await runs(ctx) }),
77
+ });
78
+ // No `allow`: only the system (a model call, the models plugin) asks these.
79
+ export const modelKeyList = defineAction({
80
+ record: false,
81
+ input: { type: "object", additionalProperties: false },
82
+ run: async (ctx) => (await keysOf(ctx).find({})).map((k) => ({
83
+ provider: k._id,
84
+ ...(k.hint ? { hint: k.hint } : {}),
85
+ })),
86
+ });
87
+ export const modelKeyOpen = defineAction({
88
+ record: false,
89
+ input: {
90
+ type: "object",
91
+ properties: { provider: { type: "string" } },
92
+ required: ["provider"],
93
+ additionalProperties: false,
94
+ },
95
+ run: async (ctx, input) => {
96
+ const found = await keysOf(ctx).findOne({ _id: input.provider });
97
+ if (!found)
98
+ return null;
99
+ const { access } = await unseal(settingsOf(ctx).key, boundTo(ctx, input.provider), found.sealed);
100
+ return access;
101
+ },
102
+ });
@@ -0,0 +1,58 @@
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.
6
+ */
7
+ import { type Infer } from "../../../../runtime/mod.js";
8
+ declare const modelKeySchema: {
9
+ readonly type: "object";
10
+ readonly properties: {
11
+ readonly hint: {
12
+ readonly type: "string";
13
+ };
14
+ readonly by: {
15
+ readonly type: "string";
16
+ };
17
+ readonly at: {
18
+ readonly type: "string";
19
+ };
20
+ };
21
+ readonly required: readonly ["by", "at"];
22
+ };
23
+ export declare const modelKey: {
24
+ schema: {
25
+ readonly type: "object";
26
+ readonly properties: {
27
+ readonly hint: {
28
+ readonly type: "string";
29
+ };
30
+ readonly by: {
31
+ readonly type: "string";
32
+ };
33
+ readonly at: {
34
+ readonly type: "string";
35
+ };
36
+ };
37
+ readonly required: readonly ["by", "at"];
38
+ };
39
+ events?: boolean;
40
+ records?: boolean;
41
+ durable?: false;
42
+ indexes?: string[][];
43
+ private?: string[];
44
+ queries?: Record<string, import("../../../../runtime/define.js").QueryDef<{
45
+ [x: string]: unknown;
46
+ hint?: string | undefined;
47
+ at: string;
48
+ by: string;
49
+ } & {
50
+ _id: string;
51
+ }>> | undefined;
52
+ vectors?: string[];
53
+ };
54
+ export type ModelKeyDoc = Infer<typeof modelKeySchema> & {
55
+ _id: string;
56
+ sealed: unknown;
57
+ };
58
+ export {};
@@ -0,0 +1,17 @@
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.
6
+ */
7
+ import { defineCollection } from "../../../../runtime/mod.js";
8
+ const modelKeySchema = {
9
+ type: "object",
10
+ properties: {
11
+ hint: { type: "string" },
12
+ by: { type: "string" },
13
+ at: { type: "string" },
14
+ },
15
+ required: ["by", "at"],
16
+ };
17
+ export const modelKey = defineCollection({ schema: modelKeySchema, private: ["sealed"] });
@@ -31,6 +31,11 @@
31
31
  * (resources/models.ts); without a connection the call fails
32
32
  * `account_missing`, and a list of models moves on. Its uses are metered
33
33
  * as the person's plan's (`paid: "subscription"`), at no cost to the app.
34
+ * - **An org's own keys for model providers** (`modelKey`, the models
35
+ * plugin's `modelKeys` resource): its owners and admins add one (`modelKey.set`)
36
+ * for any provider that can take one; each is sealed as tokens are, kept per
37
+ * org and shows only its last characters; its agents' calls to that provider
38
+ * use it (`modelKey.open`, trusted code only), over the app's.
34
39
  * - `account.changed` says when an account is connected, lost or
35
40
  * disconnected: the audit trail, with nothing secret in it.
36
41
  *
@@ -31,6 +31,11 @@
31
31
  * (resources/models.ts); without a connection the call fails
32
32
  * `account_missing`, and a list of models moves on. Its uses are metered
33
33
  * as the person's plan's (`paid: "subscription"`), at no cost to the app.
34
+ * - **An org's own keys for model providers** (`modelKey`, the models
35
+ * plugin's `modelKeys` resource): its owners and admins add one (`modelKey.set`)
36
+ * for any provider that can take one; each is sealed as tokens are, kept per
37
+ * org and shows only its last characters; its agents' calls to that provider
38
+ * use it (`modelKey.open`, trusted code only), over the app's.
34
39
  * - `account.changed` says when an account is connected, lost or
35
40
  * disconnected: the audit trail, with nothing secret in it.
36
41
  *
@@ -53,6 +58,8 @@ import { refreshAction } from "./actions/refresh.js";
53
58
  import { tokenAction } from "./actions/token.js";
54
59
  import { account } from "./collections/account.js";
55
60
  import { accountFlow } from "./collections/flow.js";
61
+ import { modelKey } from "./collections/model-key.js";
62
+ import { modelKeyList, modelKeyMay, modelKeyOpen, modelKeyRemove, modelKeySet, } from "./actions/model-key.js";
56
63
  import { changed } from "./events/changed.js";
57
64
  import { chatgpt } from "./resources/chatgpt.js";
58
65
  import { chatgptCost, chatgptModels } from "./resources/models.js";
@@ -73,7 +80,7 @@ const sendable = (address) => {
73
80
  };
74
81
  export const accounts = definePlugin({
75
82
  name: "accounts",
76
- collections: { account, accountFlow },
83
+ collections: { account, accountFlow, modelKey },
77
84
  actions: {
78
85
  "account.connect": connectAction,
79
86
  "account.complete": completeAction,
@@ -81,6 +88,11 @@ export const accounts = definePlugin({
81
88
  "account.disconnect": disconnectAction,
82
89
  "account.refresh": refreshAction,
83
90
  "account.token": tokenAction,
91
+ "modelKey.set": modelKeySet,
92
+ "modelKey.remove": modelKeyRemove,
93
+ "modelKey.may": modelKeyMay,
94
+ "modelKey.list": modelKeyList,
95
+ "modelKey.open": modelKeyOpen,
84
96
  },
85
97
  events: { "account.changed": changed },
86
98
  guard: rules,
@@ -88,6 +100,7 @@ export const accounts = definePlugin({
88
100
  accounts: {},
89
101
  accountProviders: { chatgpt },
90
102
  provider: { chatgpt: chatgptModels },
103
+ modelKeys: { open: "modelKey.open", list: "modelKey.list", may: "modelKey.may" },
91
104
  cost: { "chatgpt/*": chatgptCost },
92
105
  routes: { accounts: { path: CALLBACK, action: "account.callback", methods: ["GET"] } },
93
106
  },
@@ -6,6 +6,8 @@ export const accountHeaders = (provider) => async ({ call }) => {
6
6
  return (await call("account.token", { provider })).headers;
7
7
  };
8
8
  export const chatgptModels = {
9
+ title: "ChatGPT plan",
10
+ note: "Runs on the plan of whoever asks: each person connects their own.",
9
11
  adapter: "openai",
10
12
  catalog: "openai",
11
13
  baseURL: "https://chatgpt.com/backend-api/codex",
@@ -1,6 +1,6 @@
1
1
  const NOBODY = { _id: { $in: [] } };
2
2
  export const rules = (actor, { collection }) => collection === "account"
3
3
  ? actor.kind === "person" ? { person: actor.id } : NOBODY
4
- : collection === "accountFlow"
4
+ : collection === "accountFlow" || collection === "modelKey"
5
5
  ? NOBODY
6
6
  : undefined;
@@ -78,8 +78,8 @@ export declare const credential: {
78
78
  queries?: Record<string, import("../../../../runtime/define.js").QueryDef<{
79
79
  [x: string]: unknown;
80
80
  name?: string | undefined;
81
- staff?: boolean | undefined;
82
81
  hint?: string | undefined;
82
+ staff?: boolean | undefined;
83
83
  expires?: string | undefined;
84
84
  at: string;
85
85
  kind: "key" | "session";
@@ -22,10 +22,7 @@ export const elsewhereView = (thread, ctx) => {
22
22
  const others = spaces.filter((s) => !near.has(s._id) && !s.archived)
23
23
  .sort((a, b) => Number(b.kind === "personal") - Number(a.kind === "personal"));
24
24
  const hands = (agent[name]?.tools ?? []).includes(SEND)
25
- ? handoffs.flatMap((s) => {
26
- const there = s.agents.filter((a) => a !== name);
27
- return s._id !== thread.in && there.length ? [{ ...s, agents: there }] : [];
28
- })
25
+ ? handoffs.filter((s) => s._id !== thread.in && s.agents.length)
29
26
  : [];
30
27
  if (!others.length && !hands.length)
31
28
  return undefined;
@@ -47,7 +44,7 @@ export const elsewhereView = (thread, ctx) => {
47
44
  ? [
48
45
  `Spaces you can hand work to for ${who}, with send_message's \`space\`, when it belongs ` +
49
46
  `to their team:`,
50
- ...hands.slice(0, LISTED).map((s) => `- ${s.kind === "personal" ? "Personal" : s.name} [space: ${s._id}]: ${s.agents.join(", ")}`),
47
+ ...hands.slice(0, LISTED).map((s) => `- ${s.kind === "personal" ? "Personal" : s.name} [space: ${s._id}]: ${s.agents.map((a) => a === name ? `${a} (you, working there)` : a).join(", ")}`),
51
48
  ]
52
49
  : []),
53
50
  ].join("\n");
@@ -18,6 +18,7 @@ export type { Thread } from "./collections/thread.js";
18
18
  export type { Wait } from "./collections/wait.js";
19
19
  export type { Agent, ChatSettings, ContextEntry, ConversationView, HomeView, Offer, Prompt, RefusalView, ShownCall, Step, Tool, ToolContext, ToolViews, Turn, } from "./shared/types.js";
20
20
  export { tool } from "./shared/types.js";
21
+ export { principalOf } from "./shared/send.js";
21
22
  export { type Origin, originKey, originOf } from "./shared/origin.js";
22
23
  export type { AgentSource, Roster, RosterSource, Team } from "./shared/agents.js";
23
24
  /**
@@ -1,4 +1,5 @@
1
1
  export { tool } from "./shared/types.js";
2
+ export { principalOf } from "./shared/send.js";
2
3
  export { originKey, originOf } from "./shared/origin.js";
3
4
  /**
4
5
  * The app's agents (`agentsOf`), who of them answer new conversations
@@ -18,6 +18,9 @@ export declare const delivery: (ctx: Context, m: {
18
18
  to: string[];
19
19
  replyTo?: string;
20
20
  hops: number;
21
+ via?: {
22
+ kind: string;
23
+ };
21
24
  },
22
25
  /** Where the turns it starts run: its thread, or the subthread hanging from it. */
23
26
  where?: string,
@@ -1,6 +1,6 @@
1
1
  import { agentsNamed, NO_ANSWER, now } from "./agents.js";
2
2
  import { noted } from "./summary.js";
3
- import { settingsOf } from "./types.js";
3
+ import { DELEGATED, settingsOf } from "./types.js";
4
4
  /** Whether a message after `hops` agent messages in a row may still start a turn. */
5
5
  export const starts = (ctx, hops) => {
6
6
  const { maxHops } = settingsOf(ctx);
@@ -20,7 +20,8 @@ start = true) => {
20
20
  const waits = ctx.db.collection("wait");
21
21
  const steps = [];
22
22
  for (const name of m.to) {
23
- if (!agents[name] || name === m.from)
23
+ // An agent doesn't start itself, where it is; handed between spaces, it's other work.
24
+ if (!agents[name] || (name === m.from && m.via?.kind !== DELEGATED))
24
25
  continue;
25
26
  // An agent's open waits: one query per agent, which the owner keeps cached.
26
27
  const waiting = m.replyTo
@@ -80,7 +81,7 @@ known) => {
80
81
  ...(back.in ? { in: back.in } : {}),
81
82
  to: [trigger.from],
82
83
  via: {
83
- kind: "delegated",
84
+ kind: DELEGATED,
84
85
  name: (back.from ?? "Another space").slice(0, 120),
85
86
  path: `/thread/${encodeURIComponent(t.thread)}${thread?.in ? `?in=${encodeURIComponent(thread.in)}` : ""}`,
86
87
  },
@@ -1,6 +1,6 @@
1
1
  import { agentsNamed, now, rosterOf, SEND } from "./agents.js";
2
2
  import { starts } from "./delivery.js";
3
- import { settingsOf } from "./types.js";
3
+ import { DELEGATED, settingsOf } from "./types.js";
4
4
  /** Whom work is for: the person found along `for` and `via`, carrying any limit or origin of theirs. */
5
5
  export function principalOf(actor) {
6
6
  for (let a = actor, hops = 0; a && hops < 4; hops++) {
@@ -12,9 +12,10 @@ export function principalOf(actor) {
12
12
  }
13
13
  /**
14
14
  * Hands work to an agent of another space, in a new chat there that its members
15
- * see, for the same person, who must be able to write there. The agent need
16
- * not work there itself: its person sends it. The answer comes back to the chat
17
- * it was sent from (`back`).
15
+ * see, for the same person, who must be able to write there. The sender need
16
+ * not work there; and it may be who answers there, which is other work than
17
+ * this, in another chat. The answer comes back to the chat it was sent from
18
+ * (`back`).
18
19
  */
19
20
  async function handOver(ctx, t, step, id, input, space, where) {
20
21
  const fail = (why) => ({ output: `Not sent: ${why}` });
@@ -27,12 +28,11 @@ async function handOver(ctx, t, step, id, input, space, where) {
27
28
  if (!can)
28
29
  return fail(`the person you work for can't write in the space "${space}".`);
29
30
  const roster = await rosterOf(as, space);
30
- const others = roster.here.filter((name) => name !== t.agent);
31
- const to = String(input.to ?? "") || roster.default.find((name) => name !== t.agent) || others[0];
31
+ const to = String(input.to ?? "") || roster.default[0] || roster.here[0];
32
32
  if (!to)
33
- return fail("no other agent answers in that space.");
34
- if (!others.includes(to)) {
35
- return fail(`nobody called "${to}" answers there. You can message: ${others.join(", ")}.`);
33
+ return fail("no agent answers in that space.");
34
+ if (!roster.here.includes(to)) {
35
+ return fail(`nobody called "${to}" answers there. You can message: ${roster.here.join(", ")}.`);
36
36
  }
37
37
  if (!starts(ctx, t.hops + 1)) {
38
38
  return fail(`this conversation reached its limit of ${settingsOf(ctx).maxHops} agent messages in a row.`);
@@ -44,10 +44,12 @@ async function handOver(ctx, t, step, id, input, space, where) {
44
44
  const fresh = `${id}:thread`;
45
45
  const chat = `/thread/${encodeURIComponent(fresh)}?in=${encodeURIComponent(space)}`;
46
46
  const from = `/thread/${encodeURIComponent(t.thread)}${where ? `?in=${encodeURIComponent(where)}` : ""}`;
47
- const named = (await agentsNamed(ctx, [t.agent]))[t.agent]?.name || t.agent;
48
- // What the chat it comes back to calls where it went.
49
- const called = (await as.db.collection("space").findOne({ _id: space }))?.name ??
50
- "another space";
47
+ // Each end says which space the other is.
48
+ const spaces = as.db.collection("space");
49
+ const called = async (id) => {
50
+ const found = id ? await spaces.findOne({ _id: id }) : null;
51
+ return found?.kind === "personal" ? "Personal" : found?.name ?? "another space";
52
+ };
51
53
  return {
52
54
  output: `Sent to ${to} in a new chat in that space (${chat})${input.expectReply === false ? "." : "; you'll have the reply before you continue."}`,
53
55
  across: true,
@@ -59,8 +61,8 @@ async function handOver(ctx, t, step, id, input, space, where) {
59
61
  to: [to],
60
62
  text,
61
63
  hops: t.hops + 1,
62
- via: { kind: "delegated", name: named, path: from },
63
- back: { thread: t.thread, ...(where ? { in: where } : {}), from: called },
64
+ via: { kind: DELEGATED, name: (await called(where)).slice(0, 120), path: from },
65
+ back: { thread: t.thread, ...(where ? { in: where } : {}), from: await called(space) },
64
66
  ...(input.expectReply === false ? { expectReply: false } : {}),
65
67
  at,
66
68
  },
@@ -83,6 +85,8 @@ where) => {
83
85
  const space = typeof input.space === "string" ? input.space : undefined;
84
86
  if (space && space !== where)
85
87
  return await handOver(ctx, t, step, id, input, space, where);
88
+ if (space && !input.to)
89
+ return { output: "Not sent: you're working in that space already." };
86
90
  const team = await here();
87
91
  const to = String(input.to ?? "");
88
92
  const agents = team.open && !team.agents[to]
@@ -163,9 +167,11 @@ export function sendTool(others, people) {
163
167
  "in: thread (here, for everyone), subthread (a side conversation hanging from your " +
164
168
  "message, where the recipient also sees this conversation so far), new_thread (a " +
165
169
  "separate conversation that starts from your message alone).",
166
- "space: to hand work to another space's agents, the id of one your context lists: a new " +
167
- "chat opens there, which its members see, and to is optional (who answers there). Say " +
168
- "everything they need: they don't see this conversation, and whoever is there can read it.",
170
+ "space: to hand work that belongs to another space to who answers there, the id of one " +
171
+ "your context lists: a new chat opens there, which its members see. to is optional, and " +
172
+ "that may be you: you then work there as anyone there would, with that space's memories " +
173
+ "and tools. Either way, say everything needed: this conversation doesn't go along, and " +
174
+ "whoever is there can read it. Don't hand work back where it came from: answer it.",
169
175
  ...(agents.length ? ["Agents:", ...agents] : []),
170
176
  ...(people.length ? [`People: ${people.join(", ")}`] : []),
171
177
  ].join("\n"),
@@ -41,6 +41,8 @@ export type Tool<I = Record<string, unknown>> = {
41
41
  /** Whom a tool is offered to: everyone, these agents, or decided per agent and thread. */
42
42
  export type Offer = true | string[] | ((agent: string, thread: Thread, ctx: ViewContext) => boolean);
43
43
  /** What a tool's code reaches: the runtime, and whose turn it runs in. */
44
+ /** A message's `via` when it's handed from one space to another, either way. */
45
+ export declare const DELEGATED = "delegated";
44
46
  export type ToolContext = Context & {
45
47
  /** The agent calling it, the thread it works in, and the message it answers. */
46
48
  agent: string;
@@ -1,3 +1,6 @@
1
+ /** What a tool's code reaches: the runtime, and whose turn it runs in. */
2
+ /** A message's `via` when it's handed from one space to another, either way. */
3
+ export const DELEGATED = "delegated";
1
4
  /** A tool whose `run` input type comes from its JSON Schema. */
2
5
  export const tool = (def) => def;
3
6
  /** Chat's settings, as configured. */
@@ -3,6 +3,7 @@ import type { LlmMessage } from "../../../models/contract.js";
3
3
  import type { Message } from "../collections/message.js";
4
4
  /**
5
5
  * A message as the viewing agent sees it: its own as its turns (after what it
6
- * was told then), others' as labelled input.
6
+ * was told then), others' as labelled input. So is what it handed between
7
+ * spaces itself: that was other work, in another chat, not this turn's.
7
8
  */
8
9
  export declare function messageView(m: Message, ctx: ViewContext): LlmMessage[];
@@ -1,4 +1,5 @@
1
1
  import { text, textual } from "../collections/file.js";
2
+ import { DELEGATED } from "../shared/types.js";
2
3
  import { nameOf, namesIn } from "../../../access/spaces/contract.js";
3
4
  /** How much of a text file an agent is sent. */
4
5
  const FILE_CHARS = 20_000;
@@ -37,11 +38,13 @@ function attached(m, ctx) {
37
38
  }
38
39
  /**
39
40
  * A message as the viewing agent sees it: its own as its turns (after what it
40
- * was told then), others' as labelled input.
41
+ * was told then), others' as labelled input. So is what it handed between
42
+ * spaces itself: that was other work, in another chat, not this turn's.
41
43
  */
42
44
  export function messageView(m, ctx) {
43
45
  const me = ctx.viewer?.name;
44
- if (m.from !== me) {
46
+ const handed = m.via?.kind === DELEGATED;
47
+ if (m.from !== me || handed) {
45
48
  // People by name (an agent's own name is as it is).
46
49
  const names = namesIn(ctx, [m.from, ...m.to]);
47
50
  const to = !me || m.to.includes(me) || !m.to.length
@@ -52,7 +55,7 @@ export function messageView(m, ctx) {
52
55
  const via = m.via ? ` (via ${m.via.kind} "${m.via.name}")` : "";
53
56
  return [{
54
57
  role: "user",
55
- text: `${nameOf(m.from, names)}${via}${to}: ${m.text ?? ""}${notes}`,
58
+ text: `${m.from === me ? "You" : nameOf(m.from, names)}${via}${to}: ${m.text ?? ""}${notes}`,
56
59
  ...(files.length ? { files } : {}),
57
60
  }];
58
61
  }
@@ -10,6 +10,7 @@ import { Transcript } from "./transcript.js";
10
10
  import { waitingOn } from "./waiting.js";
11
11
  import { byAgent, names } from "./who.js";
12
12
  import { nameOf, namesIn } from "../../../../access/spaces/contract.js";
13
+ import { DELEGATED } from "../../shared/types.js";
13
14
  /** Messages this close after the one before, from the same author, go under its name. */
14
15
  const GROUP_MS = 5 * 60_000;
15
16
  export const conversationView = (t, ctx) => {
@@ -100,8 +101,10 @@ export const conversationView = (t, ctx) => {
100
101
  const before = said[i - 1];
101
102
  // Yours, while an agent it's to finishes an earlier one: it waits its turn.
102
103
  const queued = m.from === me && !byAgent(m) ? waitingOn(m, live, said) : [];
104
+ // What's handed between spaces stands apart, or an agent's hand-off and answer read as one.
103
105
  const follows = !!before && before.from === m.from && before.thread === m.thread &&
104
- !before.failed && Date.parse(m.at) - Date.parse(before.at) < GROUP_MS;
106
+ !before.failed && before.via?.kind !== DELEGATED && m.via?.kind !== DELEGATED &&
107
+ Date.parse(m.at) - Date.parse(before.at) < GROUP_MS;
105
108
  return ctx.show("message", m, {
106
109
  thread: t._id,
107
110
  who: shown,
@@ -37,7 +37,11 @@ export const messageView = (m, ctx) => {
37
37
  ? (_jsxs("header", { className: "msg-head msg-head-again", children: [addressees, aside ? _jsx(Badge, { children: "side thread" }) : null] }))
38
38
  : null)
39
39
  : head, m.via
40
- ? (_jsxs(Chip, { size: "sm", icon: "refresh", className: "msg-via", ...(m.via.path ? { href: m.via.path } : {}), children: [m.via.kind[0].toUpperCase() + m.via.kind.slice(1), ": ", m.via.name] }))
40
+ ? (_jsxs(Chip, { size: "sm", icon: m.via.kind === "routine"
41
+ ? "refresh"
42
+ : m.via.kind === "answer"
43
+ ? "check"
44
+ : "share", className: "msg-via", ...(m.via.path ? { href: m.via.path } : {}), children: [m.via.kind[0].toUpperCase() + m.via.kind.slice(1), ": ", m.via.name] }))
41
45
  : null, m.toolCalls
42
46
  ? (_jsx(Steps, { calls: m.toolCalls, text: m.text, me: me, named: named, shown: m.toolCalls.map((c) => toolView(ctx, c, m.thread)) }))
43
47
  : agent