copilotz 1.0.0-rc.35 → 1.0.0-rc.36
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.
- package/CHANGELOG.md +27 -0
- package/README.md +1 -1
- package/package.json +1 -1
- package/plugins/access/spaces/shared/labels.d.ts +7 -0
- package/plugins/access/spaces/shared/labels.js +6 -1
- package/plugins/access/spaces/shared/reach.d.ts +8 -0
- package/plugins/access/spaces/shared/reach.js +23 -5
- package/plugins/access/spaces/views/elsewhere.d.ts +3 -2
- package/plugins/access/spaces/views/elsewhere.js +5 -3
- package/plugins/agents/chat/contract.d.ts +5 -0
- package/plugins/agents/chat/contract.js +5 -0
- package/plugins/agents/chat/mod.d.ts +4 -0
- package/plugins/agents/chat/mod.js +7 -0
- package/plugins/agents/chat/resources/tools.d.ts +3 -0
- package/plugins/agents/chat/resources/tools.js +112 -0
- package/plugins/agents/chat/shared/send.js +83 -6
- package/plugins/agents/chat/shared/where.d.ts +20 -0
- package/plugins/agents/chat/shared/where.js +18 -0
- package/plugins/agents/routines/resources/tools.js +37 -19
- package/plugins/compute/computers/program/version.d.ts +1 -1
- package/plugins/compute/computers/program/version.js +1 -1
- package/plugins/compute/computers/resources/downloads.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
## 1.0.0-rc.36 — 2026-11-10
|
|
2
|
+
|
|
3
|
+
**Upgrading.** Chat has two tools of its own, `list_conversations` and `read_conversation`, for the
|
|
4
|
+
agents that list them in their `tools`. An app that made its own tools under those names drops them
|
|
5
|
+
and lists chat's, which do the same and take a space. A Personal space's agents now write elsewhere
|
|
6
|
+
for their person without labels from there (below): an app that relied on that refusal says so in
|
|
7
|
+
its own rules.
|
|
8
|
+
|
|
9
|
+
- **Agents work under the authority of whoever asked** ([design](design/work.md), "Authority"). In a
|
|
10
|
+
person's own Personal space, where only they read the answers, their agents reach every space they
|
|
11
|
+
do, and now act there too. That makes the Personal chat a chief of staff:
|
|
12
|
+
- **Tools take a space** (`in`, its id, which the `elsewhere` context lists): `list_conversations`
|
|
13
|
+
and `read_conversation` (new, chat's own), boards (`list_boards`, `read_board`, `create_board`,
|
|
14
|
+
`create_card`, `update_card`, `move_card`), documents (`list_documents`, `read_document`,
|
|
15
|
+
`write_document`, `append_document`, `edit_document`), routines (`schedule_routine`,
|
|
16
|
+
`list_routines`, `cancel_routine`: a routine kept elsewhere starts a new conversation there each
|
|
17
|
+
run) and `recall`, as before. From a shared space they work only there and in what it draws on,
|
|
18
|
+
and say so (`workIn`, in the agents' contract, for apps' tools).
|
|
19
|
+
- **`send_message` takes `thread`:** a conversation that's there already, in this space or any
|
|
20
|
+
other the person can write in. Who answers there gets it (`to`, or the conversation's own
|
|
21
|
+
agent), it says where it came from, and the answer comes back, as a hand-over's does.
|
|
22
|
+
- **What they write elsewhere is the person's:** work for someone from their own Personal space
|
|
23
|
+
takes no labels from there (`labels.write`, `ownPersonal`). Before, everything an agent wrote
|
|
24
|
+
from Personal into a space others see was refused (`needs_share`), even a card the person asked
|
|
25
|
+
for. What's written in the Personal space itself keeps its marks (its conversation may move),
|
|
26
|
+
and labels guard shared spaces and contacts' chats as before.
|
|
27
|
+
|
|
1
28
|
## 1.0.0-rc.35 — 2026-11-09
|
|
2
29
|
|
|
3
30
|
**Fixed: a retried call's nested calls.** A call run again under its id (a retry after a failure or
|
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.
|
|
165
|
+
(`"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.36"`) 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/package.json
CHANGED
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
* to choose to show it there. Documents that are members (agents people
|
|
11
11
|
* make, contacts) carry nothing: they're meant for whoever they work with.
|
|
12
12
|
*
|
|
13
|
+
* What's written elsewhere for someone from their own Personal space carries
|
|
14
|
+
* nothing either: only they see what's said there, and what their agents do
|
|
15
|
+
* there for them, anywhere they may, is theirs, as if they'd done it (an
|
|
16
|
+
* assistant they asked in private), for whoever sees where it goes. The record
|
|
17
|
+
* says who did it, for whom, and from where. What's written in the Personal
|
|
18
|
+
* space itself keeps its marks, for the day its conversation moves.
|
|
19
|
+
*
|
|
13
20
|
* A document that may be shared on its own (a chat: other collections'
|
|
14
21
|
* documents are its parts) labels as itself, and so do its parts (a chat's
|
|
15
22
|
* messages), so a write into one shared with someone outside its space (a
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { docKey, homeOf, reachOf } from "./reach.js";
|
|
1
|
+
import { docKey, homeOf, ownPersonal, reachOf } from "./reach.js";
|
|
2
2
|
import { nameOf, namesOf, PROFILE } from "./names.js";
|
|
3
3
|
/** The `shared` resource; an entry is a collection's own key, never what objects inherit. */
|
|
4
4
|
const sharedOf = (ctx) => (ctx.resources.shared ?? {});
|
|
@@ -92,6 +92,11 @@ export const labels = {
|
|
|
92
92
|
const foreign = [...found];
|
|
93
93
|
if (!foreign.length)
|
|
94
94
|
return doc;
|
|
95
|
+
// Done elsewhere for someone from their own Personal space: theirs, as if they'd written it,
|
|
96
|
+
// for whoever sees where it goes (on the record as who did it, for them, from there). What's
|
|
97
|
+
// written in Personal itself keeps its marks: the conversation may move.
|
|
98
|
+
if (space !== actor.in && await ownPersonal(actor, ctx))
|
|
99
|
+
return doc;
|
|
95
100
|
// Where it works (`in`): an agent writing elsewhere what not everyone there can see is refused.
|
|
96
101
|
const elsewhere = typeof actor.in === "string" && actor.in !== space;
|
|
97
102
|
if (actor.kind === "agent" && (elsewhere || !shared.labels)) {
|
|
@@ -89,6 +89,14 @@ export declare function reachOf(actor: Actor, ctx: ReadContext): Promise<Reach>;
|
|
|
89
89
|
* isn't narrowed, so it's the same on every page).
|
|
90
90
|
*/
|
|
91
91
|
export declare function reachKey(actor: Actor): string;
|
|
92
|
+
/**
|
|
93
|
+
* Whether an actor's work is done for someone from their own Personal space
|
|
94
|
+
* (an agent's working for them there, a routine of theirs kept there): theirs,
|
|
95
|
+
* as if they'd done it, wherever it writes (see labels.ts). Only they see what's
|
|
96
|
+
* said there, so what they asked for there is theirs to have done anywhere they
|
|
97
|
+
* may.
|
|
98
|
+
*/
|
|
99
|
+
export declare function ownPersonal(actor: Actor, ctx: ReadContext): Promise<boolean>;
|
|
92
100
|
/**
|
|
93
101
|
* The space a document shared on its own lives in, by its key (`thread:t1`):
|
|
94
102
|
* its shared collection's field says. Undefined for anything else.
|
|
@@ -170,12 +170,8 @@ async function reaching(actor, ctx) {
|
|
|
170
170
|
* there.
|
|
171
171
|
*/
|
|
172
172
|
async function narrowed(reach, space, principal, ctx) {
|
|
173
|
-
|
|
174
|
-
_id: space,
|
|
175
|
-
});
|
|
176
|
-
if (found?.kind === PERSONAL && principal.kind === "person" && found.owner === principal.id) {
|
|
173
|
+
if (await personalOf(space, principal, ctx))
|
|
177
174
|
return reach;
|
|
178
|
-
}
|
|
179
175
|
const drawn = await reachOf({ kind: "space", id: space }, ctx);
|
|
180
176
|
const all = new Set(ALL);
|
|
181
177
|
const within = new Map();
|
|
@@ -192,6 +188,28 @@ async function narrowed(reach, space, principal, ctx) {
|
|
|
192
188
|
}
|
|
193
189
|
return within;
|
|
194
190
|
}
|
|
191
|
+
/** Whether `space` is `principal`'s own Personal space, which nobody else sees. */
|
|
192
|
+
async function personalOf(space, principal, ctx) {
|
|
193
|
+
if (principal.kind !== "person")
|
|
194
|
+
return false;
|
|
195
|
+
const found = await ctx.db.collection("space").findOne({
|
|
196
|
+
_id: space,
|
|
197
|
+
});
|
|
198
|
+
return found?.kind === PERSONAL && found.owner === principal.id;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Whether an actor's work is done for someone from their own Personal space
|
|
202
|
+
* (an agent's working for them there, a routine of theirs kept there): theirs,
|
|
203
|
+
* as if they'd done it, wherever it writes (see labels.ts). Only they see what's
|
|
204
|
+
* said there, so what they asked for there is theirs to have done anywhere they
|
|
205
|
+
* may.
|
|
206
|
+
*/
|
|
207
|
+
export async function ownPersonal(actor, ctx) {
|
|
208
|
+
const where = whereOf(actor);
|
|
209
|
+
if (where === undefined || !narrows(actor))
|
|
210
|
+
return false;
|
|
211
|
+
return await personalOf(where, worksFor(actor) ?? actor, ctx);
|
|
212
|
+
}
|
|
195
213
|
/** Whom an actor works for: an agent, whoever it acts for (`for`); a key, the person whose it is. */
|
|
196
214
|
const worksFor = (actor) => actor.for ??
|
|
197
215
|
(keyOf(actor) !== undefined ? { kind: "person", id: actor.id } : undefined);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Elsewhere, for agents (the chat plugin's `elsewhere` context, each turn):
|
|
3
|
-
* the other spaces an agent can
|
|
4
|
-
* knows where to look (a tool given a space,
|
|
3
|
+
* the other spaces an agent can work in for the person it works for, so it
|
|
4
|
+
* knows where to look and act (a tool given a space, `in`: chats, boards,
|
|
5
|
+
* documents, routines, `recall`; a chat there, send_message's `thread`)
|
|
5
6
|
* when what it needs isn't here, and the spaces it can hand work to, with who
|
|
6
7
|
* answers there. An agent reaches only where it works and what that draws on
|
|
7
8
|
* (design/work.md), so the other spaces it can read are listed only in its
|
|
@@ -33,9 +33,11 @@ export const elsewhereView = (thread, ctx) => {
|
|
|
33
33
|
return [
|
|
34
34
|
...(others.length
|
|
35
35
|
? [
|
|
36
|
-
`Other spaces you can
|
|
37
|
-
`
|
|
38
|
-
`
|
|
36
|
+
`Other spaces you can work in for ${who}, as they can: tools that take a space ` +
|
|
37
|
+
`(\`in\`) read and change what's there (list_conversations and read_conversation, boards, documents, ` +
|
|
38
|
+
`routines, recall), and send_message's \`thread\` says something in a chat there, ` +
|
|
39
|
+
`whose answer comes back here. What you read in one marks your answer: here, only ` +
|
|
40
|
+
`those who can see that space read it, until ${who} shares it.`,
|
|
39
41
|
...others.slice(0, LISTED).map(line),
|
|
40
42
|
...(others.length > LISTED ? [`- and ${others.length - LISTED} more`] : []),
|
|
41
43
|
]
|
|
@@ -29,6 +29,11 @@ export { tool } from "./shared/types.js";
|
|
|
29
29
|
*/
|
|
30
30
|
export { runTool, type ToolAt, type ToolRun, toolText } from "./shared/tools.js";
|
|
31
31
|
export { type Origin, originKey, originOf } from "./shared/origin.js";
|
|
32
|
+
/**
|
|
33
|
+
* Where a tool works: the space its call names (`in`), when the agent's work
|
|
34
|
+
* reaches it, else where its conversation is; or, in words, why it can't.
|
|
35
|
+
*/
|
|
36
|
+
export { workIn, type WorkVerb } from "./shared/where.js";
|
|
32
37
|
export type { AgentModel, AgentSource, Roster, RosterSource, Team } from "./shared/agents.js";
|
|
33
38
|
export { CONTACT_TEXT, MEDIA_TYPE, MEDIA_TYPE_LENGTH } from "./actions/send.js";
|
|
34
39
|
export type { ContactSend } from "./shared/contact-send.js";
|
|
@@ -8,6 +8,11 @@ export { tool } from "./shared/types.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export { runTool, toolText } from "./shared/tools.js";
|
|
10
10
|
export { originKey, originOf } from "./shared/origin.js";
|
|
11
|
+
/**
|
|
12
|
+
* Where a tool works: the space its call names (`in`), when the agent's work
|
|
13
|
+
* reaches it, else where its conversation is; or, in words, why it can't.
|
|
14
|
+
*/
|
|
15
|
+
export { workIn } from "./shared/where.js";
|
|
11
16
|
export { CONTACT_TEXT, MEDIA_TYPE, MEDIA_TYPE_LENGTH } from "./actions/send.js";
|
|
12
17
|
/**
|
|
13
18
|
* The app's agents (`agentsOf`), who of them answer new conversations
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
* - An agent that sent messages expecting replies stops, leaving a `wait`
|
|
14
14
|
* document. Each reply checks itself off; the last one resumes the agent
|
|
15
15
|
* with every reply in its history. Waiting holds nothing open.
|
|
16
|
+
* - Agents read other conversations (`list_conversations`, `read_conversation`)
|
|
17
|
+
* and say something in one that's there already (send_message's `thread`):
|
|
18
|
+
* in their space, or, from their person's Personal space, in any space the
|
|
19
|
+
* person reaches, as that person may (design/work.md, "Authority").
|
|
16
20
|
* - People are reached the same way: a question to a person waits until they
|
|
17
21
|
* reply to it. So does a tool that needs a person's answer to go on (a yes
|
|
18
22
|
* to run a command, `ctx.ask`): its turn waits with the step's other
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
* - An agent that sent messages expecting replies stops, leaving a `wait`
|
|
14
14
|
* document. Each reply checks itself off; the last one resumes the agent
|
|
15
15
|
* with every reply in its history. Waiting holds nothing open.
|
|
16
|
+
* - Agents read other conversations (`list_conversations`, `read_conversation`)
|
|
17
|
+
* and say something in one that's there already (send_message's `thread`):
|
|
18
|
+
* in their space, or, from their person's Personal space, in any space the
|
|
19
|
+
* person reaches, as that person may (design/work.md, "Authority").
|
|
16
20
|
* - People are reached the same way: a question to a person waits until they
|
|
17
21
|
* reply to it. So does a tool that needs a person's answer to go on (a yes
|
|
18
22
|
* to run a command, `ctx.ask`): its turn waits with the step's other
|
|
@@ -111,6 +115,7 @@ import { historyView } from "./views/history.js";
|
|
|
111
115
|
import { messageView } from "./views/message.js";
|
|
112
116
|
import { participants } from "./views/participants.js";
|
|
113
117
|
import { prompt } from "./views/prompt.js";
|
|
118
|
+
import { chatTools } from "./resources/tools.js";
|
|
114
119
|
export * from "./contract.js";
|
|
115
120
|
export { lineage } from "./shared/lineage.js";
|
|
116
121
|
/** Chat's collections, changed only through its Actions. */
|
|
@@ -162,6 +167,8 @@ export const chat = definePlugin({
|
|
|
162
167
|
// Files uploaded to send that no message sent within a day go.
|
|
163
168
|
schedules: { "chat.prune": { every: "1h", call: "chat.prune", input: {} } },
|
|
164
169
|
resources: {
|
|
170
|
+
// Agents' own: the latest chats where they work (or another space they reach), and reading one.
|
|
171
|
+
tools: chatTools,
|
|
165
172
|
// Conversations by title on Usage.
|
|
166
173
|
usageNames: { thread: { tag: "tags.thread", collection: "thread", field: "title" } },
|
|
167
174
|
// With the access plugin, chats live in spaces, and what's in a chat comes with it when it's
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { tool } from "../shared/types.js";
|
|
2
|
+
import { workIn } from "../shared/where.js";
|
|
3
|
+
import { idsIn, nameOf, namesFor, withNames } from "../../../access/spaces/contract.js";
|
|
4
|
+
/** At most `most` characters of `text`, on one line. */
|
|
5
|
+
const gist = (text, most = 140) => {
|
|
6
|
+
const flat = (text ?? "").replace(/\s+/g, " ").trim();
|
|
7
|
+
return flat.length > most ? `${flat.slice(0, most - 1).trimEnd()}…` : flat;
|
|
8
|
+
};
|
|
9
|
+
/** "2026-10-29 21:04" from an ISO time. */
|
|
10
|
+
const when = (at) => at ? at.slice(0, 16).replace("T", " ") : "";
|
|
11
|
+
/** Whom messages name, for `namesFor`: who wrote them, to whom, and ids in what they say. */
|
|
12
|
+
const namedIn = (messages) => messages.flatMap((m) => [m.from, ...(m.to ?? []), ...idsIn(m.text ?? "")]);
|
|
13
|
+
/**
|
|
14
|
+
* A message as a line of a transcript: when, who to whom, what it says and
|
|
15
|
+
* carries; people by `names` (in what it says too).
|
|
16
|
+
*/
|
|
17
|
+
function line(m, names = {}) {
|
|
18
|
+
const to = m.to?.length ? ` → ${m.to.map((who) => nameOf(who, names)).join(", ")}` : "";
|
|
19
|
+
const files = m.files?.length
|
|
20
|
+
? ` [${m.files.map((f) => f.transcript ? `voice: ${gist(f.transcript, 400)}` : f.name).join("; ")}]`
|
|
21
|
+
: "";
|
|
22
|
+
const text = withNames((m.text ?? "").trim(), names);
|
|
23
|
+
return `[${when(m.at)}] ${nameOf(m.from, names)}${to}: ${text}${files}`;
|
|
24
|
+
}
|
|
25
|
+
const IN = {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "Another space, by its id (your context lists them).",
|
|
28
|
+
};
|
|
29
|
+
const listConversations = tool({
|
|
30
|
+
title: "List conversations",
|
|
31
|
+
annotations: { readOnly: true },
|
|
32
|
+
description: "List the other conversations in this space, latest first: each one's id, how " +
|
|
33
|
+
"it opened, where it is now, and how many messages it has. Read one with read_conversation " +
|
|
34
|
+
"before asking people to repeat what they said there; say something in one with " +
|
|
35
|
+
"send_message's thread. In another space you can read, give in (its id).",
|
|
36
|
+
input: {
|
|
37
|
+
type: "object",
|
|
38
|
+
properties: {
|
|
39
|
+
limit: { type: "integer", minimum: 1, maximum: 50, description: "How many (default 20)." },
|
|
40
|
+
in: IN,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
run: async ({ limit, in: there }, ctx) => {
|
|
44
|
+
const where = await workIn(ctx, there);
|
|
45
|
+
if (typeof where === "string")
|
|
46
|
+
return where;
|
|
47
|
+
const recent = await ctx.db.collection("thread").query("recent", {
|
|
48
|
+
in: where.in,
|
|
49
|
+
limit: (limit ?? 20) + 1,
|
|
50
|
+
});
|
|
51
|
+
const others = recent.filter((t) => t._id !== ctx.thread).slice(0, limit ?? 20);
|
|
52
|
+
if (!others.length) {
|
|
53
|
+
return `No other conversations in ${where.in === ctx.in ? "this" : "that"} space yet.`;
|
|
54
|
+
}
|
|
55
|
+
// What they open and end with, people by name (an id an agent wrote, too).
|
|
56
|
+
const names = await namesFor(ctx, others.flatMap((t) => [...idsIn(t.first ?? ""), ...idsIn(t.last ?? "")]));
|
|
57
|
+
const said = (text) => gist(text && withNames(text, names));
|
|
58
|
+
return others.map((t) => [
|
|
59
|
+
`- ${t._id}${t.title ? ` “${gist(t.title, 80)}”` : ""} · ${t.messages ?? 0} messages · ` +
|
|
60
|
+
`last ${when(t.at)}`,
|
|
61
|
+
` opened: ${said(t.first) || "(nothing to read)"}`,
|
|
62
|
+
...(t.last && t.latest !== t.opened ? [` latest: ${said(t.last)}`] : []),
|
|
63
|
+
].join("\n")).join("\n");
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
const readConversation = tool({
|
|
67
|
+
title: "Read a conversation",
|
|
68
|
+
annotations: { readOnly: true },
|
|
69
|
+
description: "Read what was said in another conversation (by its id, from " +
|
|
70
|
+
"list_conversations): its messages, oldest first, the latest `limit` of them, or those " +
|
|
71
|
+
"before `before` (a time from a previous read) to go further back. In this space, or " +
|
|
72
|
+
"another you can read.",
|
|
73
|
+
input: {
|
|
74
|
+
type: "object",
|
|
75
|
+
properties: {
|
|
76
|
+
conversation: { type: "string", description: "Its id." },
|
|
77
|
+
limit: { type: "integer", minimum: 1, maximum: 100, description: "How many (default 30)." },
|
|
78
|
+
before: { type: "string", description: "Only messages before this time (ISO)." },
|
|
79
|
+
},
|
|
80
|
+
required: ["conversation"],
|
|
81
|
+
},
|
|
82
|
+
run: async ({ conversation, limit, before }, ctx) => {
|
|
83
|
+
const thread = await ctx.db.collection("thread").findOne({ _id: conversation });
|
|
84
|
+
// Here, or in a space its work reaches (and says so when it doesn't).
|
|
85
|
+
const where = thread?.in ? await workIn(ctx, thread.in) : undefined;
|
|
86
|
+
if (!thread || !where)
|
|
87
|
+
return `No conversation "${conversation}" that you can read.`;
|
|
88
|
+
if (typeof where === "string")
|
|
89
|
+
return where;
|
|
90
|
+
const most = limit ?? 30;
|
|
91
|
+
const found = await ctx.db.collection("message").find({
|
|
92
|
+
thread: conversation,
|
|
93
|
+
private: { $ne: true },
|
|
94
|
+
...(before ? { at: { $lt: before } } : {}),
|
|
95
|
+
}, { sort: { at: -1 }, limit: most + 1 });
|
|
96
|
+
const shown = found.slice(0, most).reverse();
|
|
97
|
+
if (!shown.length)
|
|
98
|
+
return before ? "Nothing before that." : "Nothing said there yet.";
|
|
99
|
+
const more = found.length > most
|
|
100
|
+
? `\n(earlier messages: read again with before: "${shown[0].at}")`
|
|
101
|
+
: "";
|
|
102
|
+
const title = thread.title ? ` “${gist(thread.title, 80)}”` : "";
|
|
103
|
+
const elsewhere = where.in === ctx.in ? "" : ` (in space ${where.in})`;
|
|
104
|
+
const names = await namesFor(ctx, namedIn(shown));
|
|
105
|
+
return `Conversation ${conversation}${title}${elsewhere}:\n${shown.map((m) => line(m, names)).join("\n")}${more}`;
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
/** Chat's own tools for agents, by name. */
|
|
109
|
+
export const chatTools = {
|
|
110
|
+
list_conversations: listConversations,
|
|
111
|
+
read_conversation: readConversation,
|
|
112
|
+
};
|
|
@@ -37,13 +37,8 @@ async function handOver(ctx, t, step, id, input, space, where) {
|
|
|
37
37
|
const at = now();
|
|
38
38
|
const fresh = `${id}:thread`;
|
|
39
39
|
const chat = `/thread/${encodeURIComponent(fresh)}?in=${encodeURIComponent(space)}`;
|
|
40
|
-
const from = `/thread/${encodeURIComponent(t.thread)}${where ? `?in=${encodeURIComponent(where)}` : ""}`;
|
|
41
40
|
// Each end says which space the other is.
|
|
42
|
-
const
|
|
43
|
-
const called = async (id) => {
|
|
44
|
-
const found = id ? await spaces.findOne({ _id: id }) : null;
|
|
45
|
-
return found?.kind === "personal" ? "Personal" : found?.name ?? "another space";
|
|
46
|
-
};
|
|
41
|
+
const { called, from } = ends(as, t, where);
|
|
47
42
|
return {
|
|
48
43
|
output: `Sent to ${to} in a new chat in that space (${chat})${input.expectReply === false ? "." : "; you'll have the reply before you continue."}`,
|
|
49
44
|
across: true,
|
|
@@ -70,12 +65,89 @@ async function handOver(ctx, t, step, id, input, space, where) {
|
|
|
70
65
|
},
|
|
71
66
|
};
|
|
72
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Sends to a chat that's there already (`thread`): another of this space's, or
|
|
70
|
+
* one in another space, for the same person, who must be able to write there.
|
|
71
|
+
* Who answers is the agent named, if it answers there, else the chat's own;
|
|
72
|
+
* the answer comes back to the chat it was sent from (`back`), as a hand-over's
|
|
73
|
+
* does, and the message there says where it came from.
|
|
74
|
+
*/
|
|
75
|
+
async function toChat(ctx, t, id, input, thread, where) {
|
|
76
|
+
const fail = (why) => ({ output: `Not sent: ${why}` });
|
|
77
|
+
const principal = principalOf(ctx.actor);
|
|
78
|
+
if (!principal)
|
|
79
|
+
return fail("you aren't working for anyone who could write there.");
|
|
80
|
+
// The chat as its person reaches it, wherever they are: the agent may work here only.
|
|
81
|
+
const as = ctx.as({ ...principal, in: undefined });
|
|
82
|
+
const chat = await as.db.collection("thread").findOne({ _id: thread });
|
|
83
|
+
if (!chat)
|
|
84
|
+
return fail(`there's no chat "${thread}" the person you work for can read.`);
|
|
85
|
+
const space = typeof input.space === "string" ? input.space : undefined;
|
|
86
|
+
if (space && chat.in && space !== chat.in) {
|
|
87
|
+
return fail(`that chat is in another space ("${chat.in}"), not "${space}".`);
|
|
88
|
+
}
|
|
89
|
+
if (chat.in) {
|
|
90
|
+
const can = await as.call("space.can", { space: chat.in, verb: "write" })
|
|
91
|
+
.then((r) => r.can, () => false);
|
|
92
|
+
if (!can)
|
|
93
|
+
return fail("the person you work for can't write in that chat's space.");
|
|
94
|
+
}
|
|
95
|
+
const roster = await rosterOf(as, chat.in);
|
|
96
|
+
const own = (chat.agents ?? []).filter((name) => roster.open || roster.here.includes(name));
|
|
97
|
+
const to = String(input.to ?? "") || own[0] || roster.default[0] || roster.here[0];
|
|
98
|
+
if (!to)
|
|
99
|
+
return fail("no agent answers in that chat.");
|
|
100
|
+
if (to === t.agent && chat.in === where)
|
|
101
|
+
return fail("you can't message yourself here.");
|
|
102
|
+
if (!roster.open && !roster.here.includes(to)) {
|
|
103
|
+
return fail(`nobody called "${to}" answers there. You can message: ${roster.here.join(", ")}.`);
|
|
104
|
+
}
|
|
105
|
+
if (!starts(ctx, t.hops + 1)) {
|
|
106
|
+
return fail(`this conversation reached its limit of ${settingsOf(ctx).maxHops} agent messages in a row.`);
|
|
107
|
+
}
|
|
108
|
+
const text = String(input.text ?? "");
|
|
109
|
+
if (!text)
|
|
110
|
+
return fail("the message is empty.");
|
|
111
|
+
const { called, from } = ends(as, t, where);
|
|
112
|
+
const title = chat.title ? `"${chat.title.slice(0, 80)}"` : "that chat";
|
|
113
|
+
return {
|
|
114
|
+
output: `Sent to ${to} in ${title} (/thread/${encodeURIComponent(thread)}${chat.in ? `?in=${encodeURIComponent(chat.in)}` : ""})${input.expectReply === false ? "." : "; you'll have the reply before you continue."}`,
|
|
115
|
+
across: true,
|
|
116
|
+
message: {
|
|
117
|
+
_id: id,
|
|
118
|
+
thread,
|
|
119
|
+
...(chat.in ? { in: chat.in } : {}),
|
|
120
|
+
from: t.agent,
|
|
121
|
+
to: [to],
|
|
122
|
+
text,
|
|
123
|
+
hops: t.hops + 1,
|
|
124
|
+
via: { kind: DELEGATED, name: (await called(where)).slice(0, 120), path: from },
|
|
125
|
+
back: { thread: t.thread, ...(where ? { in: where } : {}), from: await called(chat.in) },
|
|
126
|
+
...(input.expectReply === false ? { expectReply: false } : {}),
|
|
127
|
+
at: now(),
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** What each end of a message sent elsewhere calls the other: a space's name, and the chat's path. */
|
|
132
|
+
function ends(as, t, where) {
|
|
133
|
+
const spaces = as.db.collection("space");
|
|
134
|
+
const called = async (id) => {
|
|
135
|
+
const found = id ? await spaces.findOne({ _id: id }) : null;
|
|
136
|
+
return found?.kind === "personal" ? "Personal" : found?.name ?? "another space";
|
|
137
|
+
};
|
|
138
|
+
const from = `/thread/${encodeURIComponent(t.thread)}${where ? `?in=${encodeURIComponent(where)}` : ""}`;
|
|
139
|
+
return { called, from };
|
|
140
|
+
}
|
|
73
141
|
/** Checks a `send_message` call and builds what it writes; nothing is written yet. */
|
|
74
142
|
export const prepare = async (ctx, t, step, id, input,
|
|
75
143
|
/** Who answers where the thread is: only they are messaged as agents (any, when it's open). */
|
|
76
144
|
here, known,
|
|
77
145
|
/** The space the turn's thread is in: what it writes goes there too. */
|
|
78
146
|
where) => {
|
|
147
|
+
// A chat that's there already, other than this one: wherever it is.
|
|
148
|
+
const chat = typeof input.thread === "string" && input.thread.trim() ? input.thread : undefined;
|
|
149
|
+
if (chat && chat !== t.thread)
|
|
150
|
+
return await toChat(ctx, t, id, input, chat, where);
|
|
79
151
|
const space = typeof input.space === "string" ? input.space : undefined;
|
|
80
152
|
if (space && space !== where)
|
|
81
153
|
return await handOver(ctx, t, step, id, input, space, where);
|
|
@@ -161,6 +233,10 @@ export function sendTool(others, people) {
|
|
|
161
233
|
"in: thread (here, for everyone), subthread (a side conversation hanging from your " +
|
|
162
234
|
"message, where the recipient also sees this conversation so far), new_thread (a " +
|
|
163
235
|
"separate conversation that starts from your message alone).",
|
|
236
|
+
"thread: a conversation that's there already, by its id (list_conversations lists them): another of " +
|
|
237
|
+
"this space's, or one in another space where the person you work for can write. Who " +
|
|
238
|
+
"answers there gets it (to, or the chat's own agent), it says where it came from, and " +
|
|
239
|
+
"the answer comes back here. Say everything needed: this conversation doesn't go along.",
|
|
164
240
|
"space: to hand work that belongs to another space to who answers there, the id of one " +
|
|
165
241
|
"your context lists: a new chat opens there, which its members see. to is optional, and " +
|
|
166
242
|
"that may be you: you then work there as anyone there would, with that space's memories " +
|
|
@@ -175,6 +251,7 @@ export function sendTool(others, people) {
|
|
|
175
251
|
to: { type: "string", description: "One agent or person, by name." },
|
|
176
252
|
text: { type: "string" },
|
|
177
253
|
in: { type: "string", enum: ["thread", "subthread", "new_thread"] },
|
|
254
|
+
thread: { type: "string", description: "A chat that's there already, by its id." },
|
|
178
255
|
space: { type: "string", description: "Another space's id, to hand work to its agents." },
|
|
179
256
|
expectReply: { type: "boolean", description: "False for a message that needs no answer." },
|
|
180
257
|
},
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a tool works: the space its call names (`in`, a space's id), when the
|
|
3
|
+
* agent's work reaches it, else where its conversation is. An agent reaches
|
|
4
|
+
* other spaces from its person's Personal space, all they reach; anywhere
|
|
5
|
+
* else, only where it works and what that draws on (design/work.md). The
|
|
6
|
+
* rules hold either way: this only says so in words a model can act on,
|
|
7
|
+
* instead of an empty answer.
|
|
8
|
+
*/
|
|
9
|
+
import type { Context } from "../../../../runtime/mod.js";
|
|
10
|
+
/** What a tool may do in a space: read it, or write in it (add to it, change what's there). */
|
|
11
|
+
export type WorkVerb = "read" | "write";
|
|
12
|
+
/**
|
|
13
|
+
* `{ in }`: where the tool works, the space named or its conversation's. A
|
|
14
|
+
* string: why it can't, for the tool to return as it is.
|
|
15
|
+
*/
|
|
16
|
+
export declare function workIn(ctx: Context & {
|
|
17
|
+
in?: string;
|
|
18
|
+
}, named: unknown, verb?: WorkVerb): Promise<{
|
|
19
|
+
in: string;
|
|
20
|
+
} | string>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `{ in }`: where the tool works, the space named or its conversation's. A
|
|
3
|
+
* string: why it can't, for the tool to return as it is.
|
|
4
|
+
*/
|
|
5
|
+
export async function workIn(ctx, named, verb = "read") {
|
|
6
|
+
const here = ctx.in;
|
|
7
|
+
if (typeof named !== "string" || !named.trim() || named === here) {
|
|
8
|
+
return here ? { in: here } : "This conversation isn't in a space.";
|
|
9
|
+
}
|
|
10
|
+
const can = await ctx.call("space.can", { space: named, verb })
|
|
11
|
+
.then((answer) => answer.can, () => false);
|
|
12
|
+
if (can)
|
|
13
|
+
return { in: named };
|
|
14
|
+
return `You can't ${verb === "read" ? "read" : "change anything in"} the space "${named}" ` +
|
|
15
|
+
"from this conversation. From your person's Personal space you reach every space they " +
|
|
16
|
+
"do; from any other, only that space and what it draws on. To have work done elsewhere, " +
|
|
17
|
+
"send it to whoever answers there (send_message's space or thread).";
|
|
18
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { personOf } from "../../../../runtime/mod.js";
|
|
2
|
-
import { tool } from "../../chat/contract.js";
|
|
2
|
+
import { tool, workIn, } from "../../chat/contract.js";
|
|
3
3
|
import { chatTitle, routinePath } from "../shared/routines.js";
|
|
4
4
|
import { describe, moment, oftenPerDay, scheduleSchema, } from "../shared/schedule.js";
|
|
5
5
|
import { nameOf, namesFor } from "../../../access/spaces/contract.js";
|
|
@@ -11,17 +11,29 @@ const offer = (_agent, thread, ctx) => {
|
|
|
11
11
|
return !!spaces?.find((s) => s._id === thread.in)?.can?.includes("write");
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
* Where the
|
|
15
|
-
* person's, and runs as them: made as them
|
|
14
|
+
* Where the routine is (here, or `there`: another space the agent's work reaches) and the person
|
|
15
|
+
* it works for, or why there are none. A routine is its person's, and runs as them: made as them
|
|
16
|
+
* (`ctx.as` keeps where the work is).
|
|
16
17
|
*/
|
|
17
|
-
function whereFor(ctx) {
|
|
18
|
+
async function whereFor(ctx, there, verb = "write") {
|
|
18
19
|
const person = personOf(ctx.actor);
|
|
19
20
|
if (!person)
|
|
20
21
|
return { missing: "Routines are a person's, and you aren't working for one here." };
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const at = await workIn(ctx, there, verb);
|
|
23
|
+
if (typeof at === "string")
|
|
24
|
+
return { missing: at };
|
|
25
|
+
return {
|
|
26
|
+
person,
|
|
27
|
+
space: at.in,
|
|
28
|
+
here: at.in === ctx.in,
|
|
29
|
+
as: ctx.as({ kind: "person", id: person }),
|
|
30
|
+
};
|
|
24
31
|
}
|
|
32
|
+
/** Each tool works here, or in another space its work reaches. */
|
|
33
|
+
const IN = {
|
|
34
|
+
type: "string",
|
|
35
|
+
description: "Another space, by its id (your context lists them).",
|
|
36
|
+
};
|
|
25
37
|
/** A routine, as an agent reads it: one line, with its id (who made it by name). */
|
|
26
38
|
const line = (r, names = {}) => {
|
|
27
39
|
const zone = "timezone" in r.schedule ? r.schedule.timezone : "UTC";
|
|
@@ -52,7 +64,8 @@ const scheduleRoutine = tool({
|
|
|
52
64
|
"when the time matters and you don't); without one, it's UTC. Where it posts: by default " +
|
|
53
65
|
"back in this chat (reminders, monitoring, anything that reads as one thread). Use post " +
|
|
54
66
|
'"new" when each run is its own piece of work to open later (a daily analysis), and give ' +
|
|
55
|
-
"chat_name. Tell them what you set up, and where it posts."
|
|
67
|
+
"chat_name. Tell them what you set up, and where it posts. In another space you can work " +
|
|
68
|
+
"in, give in (its id): a routine there starts a new chat there each run.",
|
|
56
69
|
input: {
|
|
57
70
|
type: "object",
|
|
58
71
|
properties: {
|
|
@@ -69,6 +82,7 @@ const scheduleRoutine = tool({
|
|
|
69
82
|
enum: ["new", "same"],
|
|
70
83
|
description: "same (default): always this chat; new: a new chat each run.",
|
|
71
84
|
},
|
|
85
|
+
in: IN,
|
|
72
86
|
chat_name: {
|
|
73
87
|
type: "string",
|
|
74
88
|
maxLength: 120,
|
|
@@ -79,9 +93,11 @@ const scheduleRoutine = tool({
|
|
|
79
93
|
required: ["text", "schedule"],
|
|
80
94
|
},
|
|
81
95
|
run: async (input, ctx) => {
|
|
82
|
-
const where = whereFor(ctx);
|
|
96
|
+
const where = await whereFor(ctx, input.in);
|
|
83
97
|
if ("missing" in where)
|
|
84
98
|
return where.missing;
|
|
99
|
+
// A routine elsewhere can't post in this chat, which isn't there: a new chat there each run.
|
|
100
|
+
const fresh = input.post === "new" || !where.here;
|
|
85
101
|
try {
|
|
86
102
|
const made = await where.as.call("routine.create", {
|
|
87
103
|
in: where.space,
|
|
@@ -89,7 +105,7 @@ const scheduleRoutine = tool({
|
|
|
89
105
|
text: input.text,
|
|
90
106
|
agent: input.agent ?? ctx.agent,
|
|
91
107
|
schedule: input.schedule,
|
|
92
|
-
...(
|
|
108
|
+
...(fresh
|
|
93
109
|
? {
|
|
94
110
|
post: "new",
|
|
95
111
|
...(typeof input.chat_name === "string" ? { chatName: input.chat_name } : {}),
|
|
@@ -115,10 +131,11 @@ const scheduleRoutine = tool({
|
|
|
115
131
|
});
|
|
116
132
|
const listRoutines = tool({
|
|
117
133
|
offer,
|
|
118
|
-
description: "The routines in this space: what each sends, to whom, when it runs next."
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
134
|
+
description: "The routines in this space: what each sends, to whom, when it runs next. In " +
|
|
135
|
+
"another space you can read, give in (its id).",
|
|
136
|
+
input: { type: "object", properties: { in: IN } },
|
|
137
|
+
run: async (input, ctx) => {
|
|
138
|
+
const where = await whereFor(ctx, input.in, "read");
|
|
122
139
|
if ("missing" in where)
|
|
123
140
|
return where.missing;
|
|
124
141
|
const found = await where.as.db.collection("routine").query("list", {
|
|
@@ -133,14 +150,15 @@ const listRoutines = tool({
|
|
|
133
150
|
const cancelRoutine = tool({
|
|
134
151
|
offer,
|
|
135
152
|
description: "Delete one of this space's routines, by its [id] (from list_routines) or its " +
|
|
136
|
-
"name. Only its maker or a manager here may; the chats it posted in stay."
|
|
153
|
+
"name. Only its maker or a manager here may; the chats it posted in stay. In another " +
|
|
154
|
+
"space, give in (its id).",
|
|
137
155
|
input: {
|
|
138
156
|
type: "object",
|
|
139
|
-
properties: { routine: { type: "string", minLength: 1 } },
|
|
157
|
+
properties: { routine: { type: "string", minLength: 1 }, in: IN },
|
|
140
158
|
required: ["routine"],
|
|
141
159
|
},
|
|
142
|
-
run: async ({ routine }, ctx) => {
|
|
143
|
-
const where = whereFor(ctx);
|
|
160
|
+
run: async ({ routine, in: there }, ctx) => {
|
|
161
|
+
const where = await whereFor(ctx, there);
|
|
144
162
|
if ("missing" in where)
|
|
145
163
|
return where.missing;
|
|
146
164
|
const here = await where.as.db.collection("routine").find({ in: where.space });
|
|
@@ -168,7 +186,7 @@ const nameChat = tool({
|
|
|
168
186
|
required: ["name"],
|
|
169
187
|
},
|
|
170
188
|
run: async ({ name }, ctx) => {
|
|
171
|
-
const where = whereFor(ctx);
|
|
189
|
+
const where = await whereFor(ctx);
|
|
172
190
|
if ("missing" in where)
|
|
173
191
|
return where.missing;
|
|
174
192
|
const title = String(name).replace(/\s+/g, " ").trim().slice(0, 120);
|
|
@@ -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.
|
|
2
|
+
export declare const VERSION = "1.0.0-rc.36";
|
|
@@ -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.
|
|
2
|
+
export const VERSION = "1.0.0-rc.36";
|
|
@@ -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.
|
|
17
|
+
* plugins: [...plugins, await computerDownloads({ dir: "dist/computer/1.0.0-rc.36" })]
|
|
18
18
|
* plugins: [...plugins, await computerDownloads({ url: "https://downloads.example.com/computer/" })]
|
|
19
19
|
* ```
|
|
20
20
|
*/
|