copilotz 1.0.0-rc.28 → 1.0.0-rc.29

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 (30) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +2 -2
  3. package/package.json +1 -1
  4. package/plugins/agents/chat/collections/intent.d.ts +59 -0
  5. package/plugins/agents/chat/collections/intent.js +21 -0
  6. package/plugins/agents/chat/collections/wait.d.ts +12 -3
  7. package/plugins/agents/chat/collections/wait.js +4 -2
  8. package/plugins/agents/chat/mod.d.ts +5 -1
  9. package/plugins/agents/chat/mod.js +5 -1
  10. package/plugins/agents/chat/processors/turn.js +79 -9
  11. package/plugins/agents/chat/shared/types.d.ts +36 -4
  12. package/plugins/agents/chat/views/web/conversation.js +1 -1
  13. package/plugins/agents/chat/views/web/over.d.ts +5 -2
  14. package/plugins/agents/chat/views/web/over.js +10 -3
  15. package/plugins/compute/computers/actions/approve.js +34 -5
  16. package/plugins/compute/computers/actions/forget.js +13 -1
  17. package/plugins/compute/computers/collections/approval.d.ts +25 -1
  18. package/plugins/compute/computers/collections/approval.js +10 -2
  19. package/plugins/compute/computers/mod.d.ts +2 -1
  20. package/plugins/compute/computers/mod.js +2 -1
  21. package/plugins/compute/computers/program/version.d.ts +1 -1
  22. package/plugins/compute/computers/program/version.js +1 -1
  23. package/plugins/compute/computers/resources/downloads.js +1 -1
  24. package/plugins/compute/computers/shared/ask.d.ts +11 -3
  25. package/plugins/compute/computers/shared/ask.js +67 -17
  26. package/plugins/compute/computers/shared/grants.d.ts +9 -3
  27. package/plugins/compute/computers/shared/grants.js +21 -6
  28. package/plugins/compute/computers/views/context.js +4 -2
  29. package/plugins/compute/computers/views/web/asks.d.ts +4 -3
  30. package/plugins/compute/computers/views/web/asks.js +10 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 1.0.0-rc.29 — 2026-11-07
4
+
5
+ - **An agent waiting on your yes waits within its turn.** A command, job or file write that needs a
6
+ person's OK used to end the agent's turn ("Waiting for ana's yes…"). The turn's answer went to
7
+ whoever had asked it, and the yes then started a new turn that answered the person. So when one
8
+ agent asked another, and that one needed a yes, the first got "I'm waiting on your yes" as its
9
+ answer and the real answer went to the person. Now the turn pauses, as it does for the messages it
10
+ sends. The call asks its person a question: the agent's message to them, answered on the approval
11
+ card. The answer is a reply to that question, and the same turn goes on. The call runs again as
12
+ itself, in a step after the answer, so the agent reads its question, the answer, then what the
13
+ command did, and its answer goes to whoever started the turn. Several asks in one step wait
14
+ together, and the turn goes on once, when the last is answered: what was allowed runs, and what
15
+ wasn't says no. A yes in this conversation, or always, answers the agent's other asks it covers,
16
+ and their turns go on too. A reply typed to the question isn't a yes: the call doesn't run, and
17
+ says what they said. A card asked in a side thread shows in its conversation too ("in a side
18
+ thread"). A card answered before its step is written is refused (`busy`, "answer in a moment");
19
+ the card shows only once the step is written anyway. Forgetting a computer tells a turn waiting on
20
+ it no. A model outside (MCP) still gets "Waiting for…" and asks again later, as before.
21
+ - **Tools can wait for a person** (`ToolContext.ask`, in chat's contract). In a turn, a tool asks
22
+ `{ to, text }` and gets the question's id; the turn waits for a reply to it (a message with that
23
+ `replyTo`), then runs the call again with `answer` (who answered, and what they said). The
24
+ question is written with the step. Steps record it (`Step.asked`), as they record what they sent
25
+ (`sent`). The `conversation` resource's Views get the conversation's side threads too (hint
26
+ `side`).
27
+
3
28
  ## 1.0.0-rc.28 — 2026-11-07
4
29
 
5
30
  - **A deploy hands over instead of fencing** (`serve` in `copilotz/web/node`, `lease` in
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.28"`),
25
+ On Deno, name it `copilotz` in `deno.json` (`"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.29"`),
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 page's code on Node (`bundle`), `@electric-sql/pglite` for
28
28
  PostgreSQL in the process, and `@types/react` for the front ends' types.
@@ -631,7 +631,7 @@ and an app serves it from there by default:
631
631
  import { computerDownloads } from "copilotz/plugins/compute/downloads";
632
632
 
633
633
  plugins: [...plugins, await computerDownloads()], // this Copilotz's release
634
- plugins: [...plugins, await computerDownloads({ dir: "dist/computer/1.0.0-rc.28" })], // its own: /computer/download/
634
+ plugins: [...plugins, await computerDownloads({ dir: "dist/computer/1.0.0-rc.29" })], // its own: /computer/download/
635
635
  plugins: [...plugins, await computerDownloads({ url: "https://downloads.example.com/computer/" })], // or elsewhere
636
636
  ```
637
637
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "copilotz",
3
- "version": "1.0.0-rc.28",
3
+ "version": "1.0.0-rc.29",
4
4
  "description": "Copilotz: one runtime for Node, Deno, Bun, Cloudflare Workers and the browser.",
5
5
  "keywords": [
6
6
  "agents",
@@ -64,6 +64,41 @@ export declare const intent: {
64
64
  readonly type: "string";
65
65
  };
66
66
  };
67
+ /** The question a call asked as it ran (`ToolContext.ask`), by its place in `calls`. */
68
+ readonly asks: {
69
+ readonly type: "object";
70
+ readonly additionalProperties: {
71
+ readonly type: "object";
72
+ readonly properties: {
73
+ readonly to: {
74
+ readonly type: "string";
75
+ };
76
+ readonly text: {
77
+ readonly type: "string";
78
+ };
79
+ };
80
+ readonly required: readonly ["to", "text"];
81
+ };
82
+ };
83
+ /**
84
+ * Calls run again once their questions were answered, by place in `calls`:
85
+ * the call's own id (it runs as itself) and the question it asked.
86
+ */
87
+ readonly again: {
88
+ readonly type: "object";
89
+ readonly additionalProperties: {
90
+ readonly type: "object";
91
+ readonly properties: {
92
+ readonly call: {
93
+ readonly type: "string";
94
+ };
95
+ readonly question: {
96
+ readonly type: "string";
97
+ };
98
+ };
99
+ readonly required: readonly ["call", "question"];
100
+ };
101
+ };
67
102
  readonly at: {
68
103
  readonly type: "string";
69
104
  };
@@ -86,6 +121,20 @@ export declare const intent: {
86
121
  name: string;
87
122
  text: string;
88
123
  }[] | undefined;
124
+ asks?: {
125
+ [x: string]: {
126
+ [x: string]: unknown;
127
+ to: string;
128
+ text: string;
129
+ };
130
+ } | undefined;
131
+ again?: {
132
+ [x: string]: {
133
+ [x: string]: unknown;
134
+ call: string;
135
+ question: string;
136
+ };
137
+ } | undefined;
89
138
  at: string;
90
139
  thread: string;
91
140
  agent: string;
@@ -116,8 +165,18 @@ export type Intent = {
116
165
  told?: Told[];
117
166
  calls: ToolCall[];
118
167
  outputs: Record<string, string>;
168
+ asks?: Record<string, Question>;
169
+ again?: Record<string, {
170
+ call: string;
171
+ question: string;
172
+ }>;
119
173
  at: string;
120
174
  };
175
+ /** What a tool asks someone, its call waiting for their answer (`ToolContext.ask`). */
176
+ export type Question = {
177
+ to: string;
178
+ text: string;
179
+ };
121
180
  /** What a call that never returned says, in the step a turn keeps when it ends without it. */
122
181
  export declare const CUT_SHORT: string;
123
182
  /** What a message that was never sent says there. */
@@ -40,6 +40,27 @@ const intentSchema = {
40
40
  },
41
41
  /** What each call returned, by its place in `calls`. */
42
42
  outputs: { type: "object", additionalProperties: { type: "string" } },
43
+ /** The question a call asked as it ran (`ToolContext.ask`), by its place in `calls`. */
44
+ asks: {
45
+ type: "object",
46
+ additionalProperties: {
47
+ type: "object",
48
+ properties: { to: { type: "string" }, text: { type: "string" } },
49
+ required: ["to", "text"],
50
+ },
51
+ },
52
+ /**
53
+ * Calls run again once their questions were answered, by place in `calls`:
54
+ * the call's own id (it runs as itself) and the question it asked.
55
+ */
56
+ again: {
57
+ type: "object",
58
+ additionalProperties: {
59
+ type: "object",
60
+ properties: { call: { type: "string" }, question: { type: "string" } },
61
+ required: ["call", "question"],
62
+ },
63
+ },
43
64
  at: { type: "string" },
44
65
  },
45
66
  required: ["thread", "agent", "step", "calls", "outputs", "at"],
@@ -1,4 +1,4 @@
1
- /** Waits: an agent paused until every message it sent has a reply. */
1
+ /** Waits: an agent paused until every message it sent, and every question its tools asked, has a reply. */
2
2
  import { type Infer } from "../../../../runtime/mod.js";
3
3
  declare const waitSchema: {
4
4
  readonly type: "object";
@@ -16,7 +16,7 @@ declare const waitSchema: {
16
16
  readonly hops: {
17
17
  readonly type: "integer";
18
18
  };
19
- /** Messages still without a reply. Empty: the agent resumes. */
19
+ /** Messages still without a reply (its own and its tools' questions). Empty: the agent resumes. */
20
20
  readonly waitingFor: {
21
21
  readonly type: "array";
22
22
  readonly items: {
@@ -29,6 +29,10 @@ declare const waitSchema: {
29
29
  readonly type: "string";
30
30
  };
31
31
  };
32
+ /** The step that asked questions: its asked calls run again once they're answered. */
33
+ readonly step: {
34
+ readonly type: "string";
35
+ };
32
36
  readonly at: {
33
37
  readonly type: "string";
34
38
  };
@@ -52,7 +56,7 @@ export declare const wait: {
52
56
  readonly hops: {
53
57
  readonly type: "integer";
54
58
  };
55
- /** Messages still without a reply. Empty: the agent resumes. */
59
+ /** Messages still without a reply (its own and its tools' questions). Empty: the agent resumes. */
56
60
  readonly waitingFor: {
57
61
  readonly type: "array";
58
62
  readonly items: {
@@ -65,6 +69,10 @@ export declare const wait: {
65
69
  readonly type: "string";
66
70
  };
67
71
  };
72
+ /** The step that asked questions: its asked calls run again once they're answered. */
73
+ readonly step: {
74
+ readonly type: "string";
75
+ };
68
76
  readonly at: {
69
77
  readonly type: "string";
70
78
  };
@@ -78,6 +86,7 @@ export declare const wait: {
78
86
  private?: string[];
79
87
  queries?: Record<string, import("../../../../runtime/define.js").QueryDef<{
80
88
  [x: string]: unknown;
89
+ step?: string | undefined;
81
90
  at: string;
82
91
  hops: number;
83
92
  thread: string;
@@ -1,4 +1,4 @@
1
- /** Waits: an agent paused until every message it sent has a reply. */
1
+ /** Waits: an agent paused until every message it sent, and every question its tools asked, has a reply. */
2
2
  import { defineCollection } from "../../../../runtime/mod.js";
3
3
  const names = { type: "array", items: { type: "string" } };
4
4
  const waitSchema = {
@@ -9,9 +9,11 @@ const waitSchema = {
9
9
  /** What the agent's turn answers, so it can answer once resumed. */
10
10
  trigger: { type: "string" },
11
11
  hops: { type: "integer" },
12
- /** Messages still without a reply. Empty: the agent resumes. */
12
+ /** Messages still without a reply (its own and its tools' questions). Empty: the agent resumes. */
13
13
  waitingFor: names,
14
14
  received: names,
15
+ /** The step that asked questions: its asked calls run again once they're answered. */
16
+ step: { type: "string" },
15
17
  at: { type: "string" },
16
18
  },
17
19
  required: ["agent", "thread", "trigger", "hops", "waitingFor", "received", "at"],
@@ -14,7 +14,11 @@
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
16
  * - People are reached the same way: a question to a person waits until they
17
- * reply to it.
17
+ * reply to it. So does a tool that needs a person's answer to go on (a yes
18
+ * to run a command, `ctx.ask`): its turn waits with the step's other
19
+ * messages, and resumes with that call run again, as itself, after the
20
+ * answer. An agent another one asked still answers it, whatever it waited
21
+ * on meanwhile.
18
22
  * - What an agent is writing shows as it comes: a `live` document per running
19
23
  * turn, kept in memory, swapped for the step or reply it became in one commit.
20
24
  * - A step's tool calls are written (an `intent`) before any of them runs, and
@@ -14,7 +14,11 @@
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
16
  * - People are reached the same way: a question to a person waits until they
17
- * reply to it.
17
+ * reply to it. So does a tool that needs a person's answer to go on (a yes
18
+ * to run a command, `ctx.ask`): its turn waits with the step's other
19
+ * messages, and resumes with that call run again, as itself, after the
20
+ * answer. An agent another one asked still answers it, whatever it waited
21
+ * on meanwhile.
18
22
  * - What an agent is writing shows as it comes: a `live` document per running
19
23
  * turn, kept in memory, swapped for the step or reply it became in one commit.
20
24
  * - A step's tool calls are written (an `intent`) before any of them runs, and
@@ -79,6 +79,13 @@ const turn = async (ctx, event) => {
79
79
  if (taking?.step === step)
80
80
  open = taking;
81
81
  }
82
+ // Resumed once the questions its tools asked were answered: the calls that asked run again
83
+ // first, as themselves, in a step of their own after the answers.
84
+ let fresh = false;
85
+ if (event.type === "wait.updated" && t.step && step === 0 && !open) {
86
+ open = await again(ctx, t, run);
87
+ fresh = !!open;
88
+ }
82
89
  // What it is sent is the thread's llm View: its instructions, the
83
90
  // conversation, and what contexts add.
84
91
  const viewer = { kind: "agent", name: t.agent };
@@ -192,11 +199,17 @@ const turn = async (ctx, event) => {
192
199
  // The step's calls run together, each in a branch of its own, so a retry
193
200
  // finds what each one called whatever order they started in. Their
194
201
  // results keep the model's order.
202
+ // What its calls ask as they run (a person's yes), each its own question: those of a call
203
+ // that returned before a retry are on its intent.
204
+ const asks = { ...resumed?.asks };
205
+ const questionOf = (i) => `${id}:${i}:question`;
195
206
  const ran = await Promise.all(calls.map(async (call, i) => {
196
207
  live.call({ id: call.id, name: call.name, input: call.input });
197
208
  let output;
198
209
  let send;
199
210
  const returned = resumed?.outputs[i];
211
+ // A call run again once its question was answered: as itself, told the answer.
212
+ const answering = resumed?.again?.[i];
200
213
  if (messaging && call.name === SEND) {
201
214
  send = await prepare(ctx, t, id, `${id}:${i}`, call.input, here, known, current.in);
202
215
  output = send.output;
@@ -212,18 +225,29 @@ const turn = async (ctx, event) => {
212
225
  agent: t.agent,
213
226
  thread: t.thread,
214
227
  trigger: t.trigger,
215
- callId: `${id}:${i}`,
228
+ callId: answering?.call ?? `${id}:${i}`,
216
229
  // Only a call that was written and never returned may have run already.
217
- retry: !!resumed,
230
+ retry: !!resumed && !(fresh && answering),
231
+ ask: (question) => {
232
+ asks[i] = { to: question.to, text: question.text };
233
+ return questionOf(i);
234
+ },
235
+ ...(answering ? { answer: await answerTo(ctx, answering.question) } : {}),
218
236
  })).output
219
237
  : `Error: Unknown tool "${call.name}"`;
220
- // What it returned is on record at once: a retry won't run it again. If
238
+ // What it returned (and asked) is on record at once: a retry won't run it again. If
221
239
  // that write fails, a retry runs it again, as itself.
222
- await intents.updateOne({ _id: run }, { $set: { [`outputs.${i}`]: output } })
223
- .catch(() => { });
240
+ await intents.updateOne({ _id: run }, {
241
+ $set: { [`outputs.${i}`]: output, ...(asks[i] ? { [`asks.${i}`]: asks[i] } : {}) },
242
+ }).catch(() => { });
224
243
  }
225
244
  live.result(call.id, output);
226
- const made = { ...call, output, ...(send?.message ? { sent: send.message._id } : {}) };
245
+ const made = {
246
+ ...call,
247
+ output,
248
+ ...(send?.message ? { sent: send.message._id } : {}),
249
+ ...(asks[i] ? { asked: questionOf(i) } : {}),
250
+ };
227
251
  return { made, send };
228
252
  }));
229
253
  const done = ran.map((r) => r.made);
@@ -238,10 +262,23 @@ const turn = async (ctx, event) => {
238
262
  // As later turns will see it, through its tool's View.
239
263
  conversation.push({ role: "tool", toolCallId: c.id, text: await toolText(ctx, c, viewer) });
240
264
  }
241
- // The step, what it sent and what it waits for commit together, so no
265
+ // What its tools asked: each the agent's message to whom it asks, a reply to which they wait for.
266
+ const questions = Object.entries(asks).map(([i, q]) => ({
267
+ _id: questionOf(Number(i)),
268
+ thread: t.thread,
269
+ ...(current.in ? { in: current.in } : {}),
270
+ from: t.agent,
271
+ to: [q.to],
272
+ text: q.text,
273
+ hops: t.hops + 1,
274
+ at: now(),
275
+ }));
276
+ // The step, what it sent and asked, and what it waits for commit together, so no
242
277
  // reply can arrive before the wait it checks off.
243
- const waitingFor = sends.filter((s) => s.message.expectReply !== false)
244
- .map((s) => s.message._id);
278
+ const waitingFor = [
279
+ ...sends.filter((s) => s.message.expectReply !== false).map((s) => s.message._id),
280
+ ...questions.map((q) => q._id),
281
+ ];
245
282
  // Handing work to another space is trusted code's: the agent doesn't work there.
246
283
  const writer = sends.some((s) => s.across) ? ctx.as() : ctx;
247
284
  const deliveries = await Promise.all(sends.map((s) => delivery(writer, s.message, s.message.subthread)));
@@ -279,6 +316,10 @@ const turn = async (ctx, event) => {
279
316
  await tx.db.collection("message").insertOne(send.message);
280
317
  await deliveries[i](tx);
281
318
  }
319
+ for (const question of questions) {
320
+ await noted(tx, question);
321
+ await tx.db.collection("message").insertOne(question);
322
+ }
282
323
  if (waitingFor.length) {
283
324
  await tx.db.collection("wait").insertOne({
284
325
  _id: `${run}:wait`,
@@ -288,6 +329,7 @@ const turn = async (ctx, event) => {
288
329
  hops: t.hops,
289
330
  waitingFor,
290
331
  received: [],
332
+ ...(questions.length ? { step: id } : {}),
291
333
  at: now(),
292
334
  });
293
335
  }
@@ -310,6 +352,34 @@ async function answered(ctx, t) {
310
352
  return !!trigger && !!latest?.knew && latest.knew >= trigger.at &&
311
353
  latest.to.includes(trigger.from);
312
354
  }
355
+ /**
356
+ * The step a turn resumes with once the questions its tools asked were
357
+ * answered: each call that asked, run again as itself (its own `callId`),
358
+ * after the answers; nothing of the paused step is rewritten. None when the
359
+ * step asked nothing.
360
+ */
361
+ async function again(ctx, t, run) {
362
+ const paused = await ctx.db.collection("message").findOne({ _id: t.step });
363
+ const asked = (paused?.toolCalls ?? []).flatMap((c, i) => c.asked ? [{ ...c, call: `${t.step}:${i}` }] : []);
364
+ if (!asked.length)
365
+ return null;
366
+ const intent = {
367
+ thread: t.thread,
368
+ agent: t.agent,
369
+ step: 0,
370
+ calls: asked.map(({ id, name, input }) => ({ id: `${id}:answered`, name, input })),
371
+ outputs: {},
372
+ again: Object.fromEntries(asked.map((c, i) => [i, { call: c.call, question: c.asked }])),
373
+ at: now(),
374
+ };
375
+ await ctx.db.collection("intent").replaceOne({ _id: run }, intent, { upsert: true });
376
+ return intent;
377
+ }
378
+ /** The answer to a question a tool asked: who answered, and what they said. */
379
+ async function answerTo(ctx, question) {
380
+ const [reply] = await ctx.db.collection("message").find({ replyTo: question }, { sort: { at: 1 }, limit: 1 });
381
+ return { from: reply?.from ?? "", text: reply?.text ?? "" };
382
+ }
313
383
  /** What a written step's model said, said again: what it wrote, its state and its calls. */
314
384
  async function* replay(intent) {
315
385
  if (intent.text)
@@ -95,6 +95,27 @@ export type ToolContext = Context & {
95
95
  * call never ran before.
96
96
  */
97
97
  callId: string;
98
+ /**
99
+ * In an agent's turn: a question this call can't go on without (a person's
100
+ * yes), to `to`. It's written with the call's step, as the agent's message
101
+ * to them, and the turn waits for its reply as it does for the messages it
102
+ * sends, other questions and messages of the step too. Then the call runs
103
+ * again, as itself, in a step of its own after the answer, with `answer`;
104
+ * what it returns then is what the agent reads. It returns the question's
105
+ * id: what an answer replies to (`chat.send`'s `replyTo`). Asked again in
106
+ * the same call, it's the same question. Absent where no turn waits (a
107
+ * model outside, over MCP): there, a tool says in its output what it waits
108
+ * for.
109
+ */
110
+ ask?: (question: {
111
+ to: string;
112
+ text: string;
113
+ }) => string;
114
+ /** On a call run again once its question was answered: who answered, and what they said. */
115
+ answer?: {
116
+ from: string;
117
+ text: string;
118
+ };
98
119
  };
99
120
  /** A tool whose `run` input type comes from its JSON Schema. */
100
121
  export declare const tool: <const S extends JSONSchema>(def: {
@@ -125,16 +146,21 @@ export type ChatSettings = {
125
146
  */
126
147
  transcriber?: ModelRef;
127
148
  };
128
- /** A tool call in an agent's step, with what it returned. */
149
+ /**
150
+ * A tool call in an agent's step, with what it returned: the message it sent
151
+ * (`send_message`'s), or the question it asked and waited on (`ToolContext.ask`).
152
+ */
129
153
  export type Step = ToolCall & {
130
154
  output: string;
131
155
  sent?: string;
156
+ asked?: string;
132
157
  };
133
158
  /**
134
159
  * A `conversation` resource: a View that a conversation shows on the web,
135
- * over where you type, with hints `{ thread, in, working, busy }` (the
136
- * thread, its space, whether an agent's turn is running there, and whose):
137
- * something to answer there, such as an agent waiting on your OK. `busy`
160
+ * over where you type, with hints `{ thread, in, side, working, busy }` (the
161
+ * thread, its space, its side threads, whether an agent's turn is running
162
+ * there, and whose): something to answer there, such as an agent waiting on
163
+ * your OK, here or in a side thread. `busy`
138
164
  * lists the agents with a turn step live in the thread or its subthreads,
139
165
  * each kept 600 ms after its last one ends (a turn's steps come about 50 ms
140
166
  * apart), and `working` is whether there are any; so a View that waits for
@@ -196,11 +222,17 @@ export type ShownCall = {
196
222
  output?: string;
197
223
  };
198
224
  /** What starts or resumes an agent's turn. */
225
+ /**
226
+ * A turn: its thread, its agent, the message it answers and how many agent
227
+ * messages in a row led to it. Resumed from a wait whose step asked
228
+ * questions, `step` is that step's message: its asked calls run again first.
229
+ */
199
230
  export type Turn = {
200
231
  thread: string;
201
232
  agent: string;
202
233
  trigger: string;
203
234
  hops: number;
235
+ step?: string;
204
236
  };
205
237
  /**
206
238
  * What an agent is sent: its tools, then the zones the prompt cache wants
@@ -118,7 +118,7 @@ export const conversationView = (t, ctx) => {
118
118
  ...(queued.length ? { queued } : {}),
119
119
  });
120
120
  }), live.map((l) => ctx.show("web.live", l, { thread: t._id, who }))] }), over.length
121
- ? (_jsx("div", { className: "chat-asks", children: _jsx(Over, { entries: over, thread: t._id, space: thread.in, live: working }) }))
121
+ ? (_jsx("div", { className: "chat-asks", children: _jsx(Over, { entries: over, thread: t._id, space: thread.in, side: subthreads, live: working }) }))
122
122
  : null, _jsx(Composer, { send: async (text, files, options) => {
123
123
  await ctx.call("chat.send", {
124
124
  thread: t._id,
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * What other front ends show over where you type (chat's `conversation`
3
- * resource): their Views, each with hints `{ thread, in, working, busy }`.
3
+ * resource): their Views, each with hints `{ thread, in, side, working, busy }`
4
+ * (`side`: the conversation's side threads, whose asks show here too).
4
5
  * `busy` is the agents whose turns run in the conversation (or its
5
6
  * subthreads), each held 600 ms after its last step ends, and `working`
6
7
  * whether there are any; so what waits for an agent's turn to be over (its
@@ -10,10 +11,12 @@
10
11
  */
11
12
  import { type ReactNode } from "react";
12
13
  import type { ConversationView } from "../../shared/types.js";
13
- export declare function Over({ entries, thread, space, live }: {
14
+ export declare function Over({ entries, thread, space, side, live }: {
14
15
  entries: ConversationView[];
15
16
  thread: string;
16
17
  space?: string;
18
+ /** The conversation's side threads. */
19
+ side?: string[];
17
20
  /** The agents with a turn step live here now. */
18
21
  live: string[];
19
22
  }): ReactNode;
@@ -1,7 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  /**
3
3
  * What other front ends show over where you type (chat's `conversation`
4
- * resource): their Views, each with hints `{ thread, in, working, busy }`.
4
+ * resource): their Views, each with hints `{ thread, in, side, working, busy }`
5
+ * (`side`: the conversation's side threads, whose asks show here too).
5
6
  * `busy` is the agents whose turns run in the conversation (or its
6
7
  * subthreads), each held 600 ms after its last step ends, and `working`
7
8
  * whether there are any; so what waits for an agent's turn to be over (its
@@ -12,10 +13,16 @@ import { jsx as _jsx } from "react/jsx-runtime";
12
13
  import { useEffect, useState, useSyncExternalStore } from "react";
13
14
  import { LazyView } from "../../../../../hosts/web/mod.js";
14
15
  import { held } from "./held.js";
15
- export function Over({ entries, thread, space, live }) {
16
+ export function Over({ entries, thread, space, side = [], live }) {
16
17
  const [hold] = useState(() => held(undefined, live));
17
18
  useEffect(() => hold.set(live), [live.join("\n")]);
18
19
  useEffect(() => () => hold.stop(), []);
19
20
  const busy = useSyncExternalStore(hold.subscribe, hold.get);
20
- return entries.map((entry) => (_jsx(LazyView, { kind: entry.view, item: {}, hints: { thread, ...(space ? { in: space } : {}), working: busy.length > 0, busy }, fallback: null }, entry.view)));
21
+ return entries.map((entry) => (_jsx(LazyView, { kind: entry.view, item: {}, hints: {
22
+ thread,
23
+ ...(space ? { in: space } : {}),
24
+ side,
25
+ working: busy.length > 0,
26
+ busy,
27
+ }, fallback: null }, entry.view)));
21
28
  }
@@ -1,12 +1,16 @@
1
1
  /**
2
2
  * A person answers what an agent waits on them for: yes this once, yes in
3
3
  * this conversation, yes for the routine that set it going, yes always, or
4
- * no. Their answer goes into the conversation as theirs, to the agent, which
5
- * carries on from it (still as part of that routine's run). Publishing is
6
- * asked every time: it can only be allowed once.
4
+ * no. Their answer goes into the conversation as theirs, to the agent: a
5
+ * reply to its question, so the turn that asked carries on (still as part
6
+ * of that routine's run). A yes in this conversation, or always, answers the
7
+ * agent's other requests it covers too, each turn waiting on them carrying
8
+ * on. Publishing is asked every time: it can only be allowed once. Asked as
9
+ * an agent's step ran, it's answered once that step is written (the card
10
+ * shows then): a moment before, it's refused (`busy`).
7
11
  */
8
- import { defineAction, inPerson, invalid } from "../../../../runtime/mod.js";
9
- import { letOrigin, told } from "../shared/grants.js";
12
+ import { defineAction, failure, inPerson, invalid } from "../../../../runtime/mod.js";
13
+ import { asking, letOrigin, told } from "../shared/grants.js";
10
14
  import { onlyOnce } from "../shared/settings.js";
11
15
  const SAID = {
12
16
  once: "Yes, this once",
@@ -34,6 +38,11 @@ export const approveAction = defineAction({
34
38
  if (onlyOnce(asked.work) && input.answer !== "once" && input.answer !== "deny") {
35
39
  throw invalid("This is asked every time: allow it once, or not.");
36
40
  }
41
+ if (!await asking(ctx, asked)) {
42
+ throw failure("busy", "It's still finishing what it was doing: answer in a moment.", {
43
+ public: true,
44
+ });
45
+ }
37
46
  if (input.answer === "origin") {
38
47
  if (!asked.origin)
39
48
  throw invalid("Nothing set this going to allow it for.");
@@ -61,6 +70,26 @@ export const approveAction = defineAction({
61
70
  });
62
71
  }
63
72
  await told(ctx, asked, `${SAID[input.answer]}: ${asked.detail}`);
73
+ // What else of this agent's waits on the same kind of work that this yes covers: answered too.
74
+ if (input.answer === "thread" || input.answer === "always") {
75
+ const covered = await ctx.db.collection("approval").find({
76
+ owner: asked.owner,
77
+ desk: asked.desk,
78
+ agent: asked.agent,
79
+ work: asked.work,
80
+ status: "pending",
81
+ question: { $exists: true },
82
+ ...(input.answer === "thread" ? { thread: asked.thread } : {}),
83
+ });
84
+ for (const other of covered) {
85
+ // One whose step isn't written yet is answered on its own card, by this yes already.
86
+ if (other._id === asked._id || !await asking(ctx, other))
87
+ continue;
88
+ const { modifiedCount } = await ctx.db.collection("approval").updateOne({ _id: other._id, status: "pending" }, { $set: { status: "allowed", grant: input.answer, decided: now } });
89
+ if (modifiedCount)
90
+ await told(ctx, other, `${SAID[input.answer]}: ${other.detail}`);
91
+ }
92
+ }
64
93
  return { answered: true };
65
94
  },
66
95
  });
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * Forgets one of the person's computers: it can't connect again (its program
3
3
  * forgets it at its next try), every space it's in loses it, and what
4
- * agents waited on it for, and what they were let do there, go with it. Its files stay
4
+ * agents waited on it for (a turn waiting is told no, and goes on), and what
5
+ * they were let do there, go with it. Its files stay
5
6
  * where they are, on the machine.
6
7
  */
7
8
  import { defineAction, people } from "../../../../runtime/mod.js";
9
+ import { asking, told } from "../shared/grants.js";
8
10
  export const forgetAction = defineAction({
9
11
  description: "Forgets one of your computers",
10
12
  input: {
@@ -19,6 +21,16 @@ export const forgetAction = defineAction({
19
21
  if (deletedCount) {
20
22
  // Its desks too, in every space it's in: the system's to remove.
21
23
  await ctx.as().db.collection("desk").deleteMany({ computer: input.computer });
24
+ // A turn waiting on it is told no, and carries on without it.
25
+ const waiting = await ctx.as().db.collection("approval").find({
26
+ computer: input.computer,
27
+ status: "pending",
28
+ question: { $exists: true },
29
+ });
30
+ for (const asked of waiting) {
31
+ if (await asking(ctx, asked))
32
+ await told(ctx, asked, `No: ${asked.detail}`);
33
+ }
22
34
  await ctx.as().db.collection("approval").deleteMany({ computer: input.computer });
23
35
  await ctx.as().db.collection("grant").deleteMany({ computer: input.computer });
24
36
  }
@@ -3,7 +3,9 @@
3
3
  * for: a command, a job, a file write. Who answers (`owner`): the person the
4
4
  * agent works for (`for`), or the computer's owner when its desk says so;
5
5
  * they answer with `computer.approve`: yes once, yes for the conversation,
6
- * yes for the routine that set it going (`origin`), yes always, or no.
6
+ * yes for the routine that set it going (`origin`), yes always, or no. Asked
7
+ * in an agent's turn, it's that call's own (`call`), and the turn waits for
8
+ * the answer to its question.
7
9
  */
8
10
  import { type Infer } from "../../../../runtime/mod.js";
9
11
  declare const approvalSchema: {
@@ -71,6 +73,16 @@ declare const approvalSchema: {
71
73
  };
72
74
  readonly required: readonly ["kind", "id", "name", "rev"];
73
75
  };
76
+ /**
77
+ * Asked in an agent's turn: the call that asked (its `callId`: it runs again as itself once
78
+ * answered), and its question, the agent's message the answer replies to.
79
+ */
80
+ readonly call: {
81
+ readonly type: "string";
82
+ };
83
+ readonly question: {
84
+ readonly type: "string";
85
+ };
74
86
  readonly status: {
75
87
  readonly type: "string";
76
88
  readonly enum: readonly ["pending", "allowed", "denied"];
@@ -155,6 +167,16 @@ export declare const approval: {
155
167
  };
156
168
  readonly required: readonly ["kind", "id", "name", "rev"];
157
169
  };
170
+ /**
171
+ * Asked in an agent's turn: the call that asked (its `callId`: it runs again as itself once
172
+ * answered), and its question, the agent's message the answer replies to.
173
+ */
174
+ readonly call: {
175
+ readonly type: "string";
176
+ };
177
+ readonly question: {
178
+ readonly type: "string";
179
+ };
158
180
  readonly status: {
159
181
  readonly type: "string";
160
182
  readonly enum: readonly ["pending", "allowed", "denied"];
@@ -181,6 +203,7 @@ export declare const approval: {
181
203
  queries?: Record<string, import("../../../../runtime/define.js").QueryDef<{
182
204
  [x: string]: unknown;
183
205
  name?: string | undefined;
206
+ call?: string | undefined;
184
207
  origin?: {
185
208
  [x: string]: unknown;
186
209
  path?: string | undefined;
@@ -190,6 +213,7 @@ export declare const approval: {
190
213
  rev: number;
191
214
  } | undefined;
192
215
  in?: string | undefined;
216
+ question?: string | undefined;
193
217
  preview?: string | undefined;
194
218
  grant?: "origin" | "once" | "thread" | "always" | undefined;
195
219
  decided?: string | undefined;
@@ -3,7 +3,9 @@
3
3
  * for: a command, a job, a file write. Who answers (`owner`): the person the
4
4
  * agent works for (`for`), or the computer's owner when its desk says so;
5
5
  * they answer with `computer.approve`: yes once, yes for the conversation,
6
- * yes for the routine that set it going (`origin`), yes always, or no.
6
+ * yes for the routine that set it going (`origin`), yes always, or no. Asked
7
+ * in an agent's turn, it's that call's own (`call`), and the turn waits for
8
+ * the answer to its question.
7
9
  */
8
10
  import { defineCollection, people } from "../../../../runtime/mod.js";
9
11
  const approvalSchema = {
@@ -39,6 +41,12 @@ const approvalSchema = {
39
41
  },
40
42
  required: ["kind", "id", "name", "rev"],
41
43
  },
44
+ /**
45
+ * Asked in an agent's turn: the call that asked (its `callId`: it runs again as itself once
46
+ * answered), and its question, the agent's message the answer replies to.
47
+ */
48
+ call: { type: "string" },
49
+ question: { type: "string" },
42
50
  status: { type: "string", enum: ["pending", "allowed", "denied"] },
43
51
  /** How far a yes goes. */
44
52
  grant: { type: "string", enum: ["once", "thread", "origin", "always"] },
@@ -60,7 +68,7 @@ const approvalSchema = {
60
68
  };
61
69
  export const approval = defineCollection({
62
70
  schema: approvalSchema,
63
- indexes: [["owner", "status"], ["thread", "at"]],
71
+ indexes: [["owner", "status"], ["thread", "at"], ["call"]],
64
72
  queries: {
65
73
  /** What agents wait on the asker for, oldest first. */
66
74
  pending: {
@@ -7,7 +7,8 @@
7
7
  * and browser, so they never tread on each other. Running commands, starting
8
8
  * jobs and writing files wait for a yes (once, for the conversation, or
9
9
  * always): from the person the agent works for, or the computer's owner when
10
- * they keep that to themselves. What a job serves gets an address of its own
10
+ * they keep that to themselves. The agent's turn waits for it, and goes on
11
+ * once it's answered, the call running then. What a job serves gets an address of its own
11
12
  * for the space's members (`computer.preview`, the `preview` tool), once the
12
13
  * app names a domain for previews (`computers: { previews }`: see
13
14
  * resources/previews.ts). A space's environment (variables and secrets, its
@@ -7,7 +7,8 @@
7
7
  * and browser, so they never tread on each other. Running commands, starting
8
8
  * jobs and writing files wait for a yes (once, for the conversation, or
9
9
  * always): from the person the agent works for, or the computer's owner when
10
- * they keep that to themselves. What a job serves gets an address of its own
10
+ * they keep that to themselves. The agent's turn waits for it, and goes on
11
+ * once it's answered, the call running then. What a job serves gets an address of its own
11
12
  * for the space's members (`computer.preview`, the `preview` tool), once the
12
13
  * app names a domain for previews (`computers: { previews }`: see
13
14
  * resources/previews.ts). A space's environment (variables and secrets, its
@@ -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.28";
2
+ export declare const VERSION = "1.0.0-rc.29";
@@ -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.28";
2
+ export const VERSION = "1.0.0-rc.29";
@@ -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.28" })]
17
+ * plugins: [...plugins, await computerDownloads({ dir: "dist/computer/1.0.0-rc.29" })]
18
18
  * plugins: [...plugins, await computerDownloads({ url: "https://downloads.example.com/computer/" })]
19
19
  * ```
20
20
  */
@@ -4,10 +4,11 @@
4
4
  * (`owner`: the person it works for, or the computer's owner) let it do:
5
5
  * always, in this conversation, whenever the routine that set it going runs,
6
6
  * or this once, used up now. Otherwise they're asked (an approval, waiting),
7
- * and the agent is told to wait for them. Publishing reaches outside the
7
+ * and the agent waits for them. Publishing reaches outside the
8
8
  * computer: it's asked every time, and only a yes to that one covers it.
9
9
  */
10
10
  import type { Context } from "../../../../runtime/mod.js";
11
+ import type { ToolContext } from "../../../agents/chat/contract.js";
11
12
  import { type Asked } from "./settings.js";
12
13
  export type Ask = {
13
14
  /** Who answers. */
@@ -28,5 +29,12 @@ export type Ask = {
28
29
  /** What its computer asks about, when it says (the desk's `approve`); else the settings'. */
29
30
  approve?: Asked[];
30
31
  };
31
- /** True: go ahead. A string: what the agent is told instead (it waits for its person). */
32
- export declare function allowed(ctx: Context, ask: Ask): Promise<true | string>;
32
+ /**
33
+ * True: go ahead. A string: what the agent is told instead. In an agent's
34
+ * turn (`ask`), a call that needs a yes asks its person (a question to `for`,
35
+ * its own request, by its `callId`) and the turn waits for the answer; run
36
+ * again once answered, it goes ahead if this call was allowed, or says no.
37
+ * Elsewhere (a model outside), it says what it waits for: one request for
38
+ * the same thing, however often it's asked.
39
+ */
40
+ export declare function allowed(ctx: Context & Partial<Pick<ToolContext, "callId" | "ask" | "answer">>, ask: Ask): Promise<true | string>;
@@ -1,7 +1,14 @@
1
1
  import { onlyOnce, settingsOf } from "./settings.js";
2
2
  import { nameOf, namesFor } from "../../../access/spaces/contract.js";
3
3
  import { originKey, originOf } from "../../../agents/chat/contract.js";
4
- /** True: go ahead. A string: what the agent is told instead (it waits for its person). */
4
+ /**
5
+ * True: go ahead. A string: what the agent is told instead. In an agent's
6
+ * turn (`ask`), a call that needs a yes asks its person (a question to `for`,
7
+ * its own request, by its `callId`) and the turn waits for the answer; run
8
+ * again once answered, it goes ahead if this call was allowed, or says no.
9
+ * Elsewhere (a model outside), it says what it waits for: one request for
10
+ * the same thing, however often it's asked.
11
+ */
5
12
  export async function allowed(ctx, ask) {
6
13
  const approve = ask.approve ?? settingsOf(ctx).approve;
7
14
  if (!onlyOnce(ask.work) && !approve.includes(ask.work))
@@ -9,7 +16,22 @@ export async function allowed(ctx, ask) {
9
16
  const origin = originOf(ctx.actor);
10
17
  const system = ctx.as();
11
18
  const grants = system.db.collection("grant");
12
- const found = await grants.findOne({
19
+ const approvals = system.db.collection("approval");
20
+ const turn = ctx.ask && ctx.callId ? { ask: ctx.ask, call: ctx.callId } : undefined;
21
+ // This call's own request, answered: a yes lets it go (a yes once is used up by it).
22
+ const mine = turn ? await approvals.findOne({ call: turn.call }) : null;
23
+ if (mine?.status === "allowed") {
24
+ await grants.deleteOne({
25
+ desk: ask.desk,
26
+ owner: ask.owner,
27
+ agent: ask.agent,
28
+ work: ask.work,
29
+ once: ask.detail,
30
+ thread: ask.thread,
31
+ });
32
+ return true;
33
+ }
34
+ const found = mine?.status === "denied" ? null : await grants.findOne({
13
35
  desk: ask.desk,
14
36
  owner: ask.owner,
15
37
  agent: ask.agent,
@@ -26,7 +48,49 @@ export async function allowed(ctx, ask) {
26
48
  await grants.deleteOne({ _id: found._id });
27
49
  return true;
28
50
  }
29
- const approvals = system.db.collection("approval");
51
+ const what = {
52
+ terminal: "run this",
53
+ jobs: "start this job",
54
+ writes: "change this file",
55
+ publish: "publish this as an app",
56
+ destroy: "destroy",
57
+ }[ask.work];
58
+ // People by name.
59
+ const names = await namesFor(ctx, [ask.owner, ask.for, ...(ctx.answer ? [ctx.answer.from] : [])]);
60
+ const owner = nameOf(ask.owner, names);
61
+ const doingOn = (whose) => ask.work === "destroy"
62
+ ? `destroy ${whose} computer for good, with its files`
63
+ : `${what} on ${whose} computer`;
64
+ const doing = doingOn(ask.owner === ask.for ? "their" : `${owner}'s`);
65
+ if (mine?.status === "denied")
66
+ return `No: ${owner} said no to ${doing}: ${ask.detail}`;
67
+ if (turn) {
68
+ if (mine && ctx.answer) {
69
+ // Answered, but not with a yes (a reply typed to the question): it doesn't run.
70
+ await approvals.deleteOne({ call: turn.call, status: "pending" });
71
+ return `Not run: ${nameOf(ctx.answer.from, names)} answered "${ctx.answer.text}", ` +
72
+ `without allowing you to ${doing}: ${ask.detail}`;
73
+ }
74
+ // Asked as itself: what it asks, the person sees as the agent's question, and answers on its
75
+ // card; the turn waits for that answer.
76
+ const question = turn.ask({
77
+ to: ask.for,
78
+ text: `May I ${doingOn(ask.owner === ask.for ? "your" : `${owner}'s`)}?${ask.owner === ask.for ? "" : ` ${owner} answers.`}\n${ask.detail}`,
79
+ });
80
+ if (mine)
81
+ await approvals.updateOne({ call: turn.call }, { $set: { question } });
82
+ else {
83
+ await approvals.insertOne({
84
+ ...ask,
85
+ ...(origin ? { origin } : {}),
86
+ call: turn.call,
87
+ question,
88
+ status: "pending",
89
+ at: new Date().toISOString(),
90
+ });
91
+ }
92
+ return `Waiting for ${owner}'s yes to ${doing}: ${ask.detail}`;
93
+ }
30
94
  const waiting = await approvals.findOne({
31
95
  desk: ask.desk,
32
96
  owner: ask.owner,
@@ -44,20 +108,6 @@ export async function allowed(ctx, ask) {
44
108
  at: new Date().toISOString(),
45
109
  });
46
110
  }
47
- const what = {
48
- terminal: "run this",
49
- jobs: "start this job",
50
- writes: "change this file",
51
- publish: "publish this as an app",
52
- destroy: "destroy",
53
- }[ask.work];
54
- // People by name.
55
- const names = await namesFor(ctx, [ask.owner, ask.for]);
56
- const owner = nameOf(ask.owner, names);
57
- const whose = ask.owner === ask.for ? "their" : `${owner}'s`;
58
- const doing = ask.work === "destroy"
59
- ? `destroy ${whose} computer for good, with its files`
60
- : `${what} on ${whose} computer`;
61
111
  return `Waiting for ${owner}'s yes to ${doing}: ${ask.detail}\n` +
62
112
  `${ask.owner === ask.for ? "They see" : `${owner}, whose computer it is, sees`} your ` +
63
113
  "request where they talk with you, and answers there (" +
@@ -18,9 +18,15 @@ export type Letting = {
18
18
  /** What a person's answer says in the conversation, for this kind of thing. */
19
19
  export declare const saidFor: (origin: Pick<Origin, "kind">) => string;
20
20
  /**
21
- * The answer, in the conversation, as part of what set it going. Its next turn
22
- * is for whom the agent was working: where the computer's owner answered, the
23
- * message is that person's, saying who did.
21
+ * The answer, in the conversation, as part of what set it going: a reply to
22
+ * the agent's question, when its turn waits on it (it goes on from there).
23
+ * It's for whom the agent was working: where the computer's owner answered,
24
+ * the message is that person's, saying who did.
24
25
  */
25
26
  export declare function told(ctx: Context, asked: Approval, text: string): Promise<void>;
27
+ /**
28
+ * Whether what was asked can be answered now: asked in an agent's turn, its
29
+ * question is written (the step that asked it is); asked elsewhere, always.
30
+ */
31
+ export declare function asking(ctx: Context, asked: Approval): Promise<boolean>;
26
32
  export declare function letOrigin(ctx: Context, l: Letting): Promise<void>;
@@ -3,9 +3,10 @@ import { originKey } from "../../../agents/chat/contract.js";
3
3
  /** What a person's answer says in the conversation, for this kind of thing. */
4
4
  export const saidFor = (origin) => `Yes, for this ${origin.kind}`;
5
5
  /**
6
- * The answer, in the conversation, as part of what set it going. Its next turn
7
- * is for whom the agent was working: where the computer's owner answered, the
8
- * message is that person's, saying who did.
6
+ * The answer, in the conversation, as part of what set it going: a reply to
7
+ * the agent's question, when its turn waits on it (it goes on from there).
8
+ * It's for whom the agent was working: where the computer's owner answered,
9
+ * the message is that person's, saying who did.
9
10
  */
10
11
  export async function told(ctx, asked, text) {
11
12
  const me = ctx.actor.id;
@@ -16,7 +17,21 @@ export async function told(ctx, asked, text) {
16
17
  const answered = asked.for === me
17
18
  ? {}
18
19
  : { via: { kind: "answer", name: nameOf(me, await namesFor(ctx, [me])).slice(0, 120) } };
19
- await by.call("chat.send", { thread: asked.thread, to: [asked.agent], text, ...answered });
20
+ await by.call("chat.send", {
21
+ thread: asked.thread,
22
+ to: [asked.agent],
23
+ text,
24
+ ...(asked.question ? { replyTo: asked.question } : {}),
25
+ ...answered,
26
+ });
27
+ }
28
+ /**
29
+ * Whether what was asked can be answered now: asked in an agent's turn, its
30
+ * question is written (the step that asked it is); asked elsewhere, always.
31
+ */
32
+ export async function asking(ctx, asked) {
33
+ return !asked.question ||
34
+ !!await ctx.as().db.collection("message").findOne({ _id: asked.question });
20
35
  }
21
36
  export async function letOrigin(ctx, l) {
22
37
  const now = new Date().toISOString();
@@ -38,9 +53,9 @@ export async function letOrigin(ctx, l) {
38
53
  const approvals = ctx.db.collection("approval");
39
54
  const waiting = await approvals.find({ ...scope, status: "pending" });
40
55
  for (const asked of waiting) {
41
- if (!asked.origin || originKey(asked.origin) !== key || asked.origin.rev !== l.origin.rev) {
56
+ if (!asked.origin || originKey(asked.origin) !== key || asked.origin.rev !== l.origin.rev ||
57
+ !await asking(ctx, asked))
42
58
  continue;
43
- }
44
59
  await approvals.updateOne({ _id: asked._id }, {
45
60
  $set: { status: "allowed", grant: "origin", decided: now },
46
61
  });
@@ -69,7 +69,8 @@ export const contextViews = {
69
69
  ? [
70
70
  "Where a yes is needed, the tool asks, and you wait. They see your request where " +
71
71
  "they talk with you and answer there (on the web, a card in the conversation; in " +
72
- "the terminal, a line above where they type, answered with /approve). Reading " +
72
+ "the terminal, a line above where they type, answered with /approve). Once they " +
73
+ "answer, it runs, and you go on with what it returned (or their no). Reading " +
73
74
  "files, listing and searching need no yes.",
74
75
  ]
75
76
  : []),
@@ -111,7 +112,8 @@ export const contextViews = {
111
112
  `Before you ${asked.join(", ")}, ${answerer} says yes: the tool asks them, and you ` +
112
113
  `wait. They see your request where they talk with you and answer there (on the ` +
113
114
  `web, a card in the conversation; in the terminal, a line above where they type, ` +
114
- `answered with /approve). Reading files, listing and searching need no yes.`,
115
+ `answered with /approve). Once they answer, it runs, and you go on with what it ` +
116
+ `returned (or their no). Reading files, listing and searching need no yes.`,
115
117
  ]
116
118
  : []),
117
119
  ...environment(ctx, thread.in),
@@ -1,7 +1,8 @@
1
1
  /**
2
- * What agents wait on you for in this conversation (kind `computer.asks`,
3
- * shown over where you type: chat's `conversation` resource, with hints
4
- * `{ thread, working }`): a card each, "assistant wants to run `npm test`"
2
+ * What agents wait on you for in this conversation and its side threads
3
+ * (kind `computer.asks`, shown over where you type: chat's `conversation`
4
+ * resource, with hints `{ thread, side, busy }`; one from a side thread says
5
+ * so): a card each, "assistant wants to run `npm test`"
5
6
  * on which computer, with Allow once · Allow in this conversation · Always
6
7
  * allow · Deny (`computer.approve`, whose answer goes into the
7
8
  * conversation, and the agent carries on). What a routine's run asks can also
@@ -1,8 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  /**
3
- * What agents wait on you for in this conversation (kind `computer.asks`,
4
- * shown over where you type: chat's `conversation` resource, with hints
5
- * `{ thread, working }`): a card each, "assistant wants to run `npm test`"
3
+ * What agents wait on you for in this conversation and its side threads
4
+ * (kind `computer.asks`, shown over where you type: chat's `conversation`
5
+ * resource, with hints `{ thread, side, busy }`; one from a side thread says
6
+ * so): a card each, "assistant wants to run `npm test`"
6
7
  * on which computer, with Allow once · Allow in this conversation · Always
7
8
  * allow · Deny (`computer.approve`, whose answer goes into the
8
9
  * conversation, and the agent carries on). What a routine's run asks can also
@@ -33,17 +34,19 @@ export const asksView = (_, ctx) => {
33
34
  const pending = ctx.db.collection("approval").query("pending", {}).value ?? [];
34
35
  // While an agent is still writing, its explanation comes first; another's work doesn't hold it.
35
36
  const busy = Array.isArray(ctx.hints.busy) ? ctx.hints.busy : [];
36
- const here = pending.filter((a) => a.thread === thread && !busy.includes(a.agent));
37
+ // Asked here, or in one of its side threads: answered here all the same.
38
+ const side = Array.isArray(ctx.hints.side) ? ctx.hints.side : [];
39
+ const here = pending.filter((a) => (a.thread === thread || side.includes(a.thread)) && !busy.includes(a.agent));
37
40
  if (!thread || !here.length)
38
41
  return null;
39
42
  const agents = agentsShown(ctx, here.map((a) => a.agent));
40
43
  if (!agents)
41
44
  return null;
42
45
  return (_jsxs("div", { className: "asks", role: "region", "aria-label": "Waiting on you", children: [_jsx("style", { href: "computers-web", precedence: "copilotz", children: STYLE }), here.map((a) => {
43
- return (_jsx(Ask, { approval: { ...a, agent: agents[a.agent]?.name || a.agent }, computer: a.name, call: ctx.call }, a._id));
46
+ return (_jsx(Ask, { approval: { ...a, agent: agents[a.agent]?.name || a.agent }, computer: a.name, aside: a.thread !== thread, call: ctx.call }, a._id));
44
47
  })] }));
45
48
  };
46
- function Ask({ approval: a, computer, call }) {
49
+ function Ask({ approval: a, computer, aside, call }) {
47
50
  const [busy, setBusy] = useState();
48
51
  const [error, setError] = useState();
49
52
  const { wants, what, verb } = asked(a);
@@ -61,7 +64,7 @@ function Ask({ approval: a, computer, call }) {
61
64
  }
62
65
  };
63
66
  const allow = (said, label, variant) => (_jsx(Tooltip, { text: reach(said, a, computer), children: _jsx(Button, { size: "sm", variant: variant, loading: busy === said, disabled: !!busy, onClick: () => void answer(said), children: label }) }));
64
- return (_jsxs(Card, { as: "article", padding: "none", className: "ask", "aria-label": sentence(a), children: [_jsx("span", { className: "ask-icon", "aria-hidden": "true", children: _jsx(Icon, { name: ICONS[a.work] ?? "tool", size: 16 }) }), _jsxs("div", { className: "ask-main", children: [_jsxs("p", { className: "ask-head", children: [_jsx("b", { children: a.agent }), " ", wants, _jsxs("span", { className: "ask-where", children: [computer ? _jsxs(_Fragment, { children: ["on ", computer, " \u00B7"] }) : null, _jsx(Time, { at: a.at })] })] }), a.work === "publish" ? _jsx(Publish, { approval: a }) : a.work === "writes" && preview
67
+ return (_jsxs(Card, { as: "article", padding: "none", className: "ask", "aria-label": sentence(a), children: [_jsx("span", { className: "ask-icon", "aria-hidden": "true", children: _jsx(Icon, { name: ICONS[a.work] ?? "tool", size: 16 }) }), _jsxs("div", { className: "ask-main", children: [_jsxs("p", { className: "ask-head", children: [_jsx("b", { children: a.agent }), " ", wants, _jsxs("span", { className: "ask-where", children: [computer ? _jsxs(_Fragment, { children: ["on ", computer, " \u00B7"] }) : null, aside ? _jsx(_Fragment, { children: "in a side thread \u00B7" }) : null, _jsx(Time, { at: a.at })] })] }), a.work === "publish" ? _jsx(Publish, { approval: a }) : a.work === "writes" && preview
65
68
  ? (_jsx(CodeBlock, { className: "ask-what ask-preview", title: _jsx("code", { children: what }), code: previewOf(preview, verb), height: 8, label: `What it will write in ${what}` }))
66
69
  : (_jsx(CodeBlock, { className: "ask-what", code: a.work === "writes" ? what : [{ text: "$ ", tone: "muted" }, { text: what }], height: 6, copy: what, label: a.work === "writes" ? "The file" : "The command" })), _jsxs("div", { className: "ask-answers", children: [allow("once", "Allow once", "primary"), a.origin && !onlyOnce(a.work)
67
70
  ? allow("origin", `Allow for this ${a.origin.kind}`, "outline")