@chipschat/acp 1.0.19 → 1.0.20

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/README.md CHANGED
@@ -146,6 +146,7 @@ minutes and loaded again with its memory. Fourteen runs, none failed, $0.35, all
146
146
  | Chips | ACP |
147
147
  |---|---|
148
148
  | A message for an agent | `session/prompt` with the room note and who said it (`promptFor`), files saved under `<folder>/chips-files/` |
149
+ | What waited for an agent (Chips ADR 0294) | one prompt once the agent is free, not one each: under the newest message's note, each message that waited said in full, oldest first, then what was said in the room after, to others. A message Chips handed over, and a Not right?, are a prompt of their own. An idle agent starts 150 ms after the first words, so all it is sent at once, as when the bridge comes back, is one prompt |
149
150
  | The room | a session in the agent's folder: `session/new` the first time, `session/load` after a restart or an idle close where the agent offers it |
150
151
  | A room from the + | `claimSpace` under a new key; Chips makes its agent; the first words are its first prompt |
151
152
  | A new agent (Add) | a record and a folder, registered with `madeFor` and the room |
@@ -1,6 +1,6 @@
1
1
  # Third-party notices
2
2
 
3
- `dist/main.js` in @chipschat/acp 1.0.19 carries these packages, bundled in. Each one's
3
+ `dist/main.js` in @chipschat/acp 1.0.20 carries these packages, bundled in. Each one's
4
4
  licence follows.
5
5
 
6
6
  ## @chipschat/harness 1.0.4 (Apache-2.0)
package/dist/main.js CHANGED
@@ -20676,6 +20676,7 @@ var MONTHS = [
20676
20676
  ];
20677
20677
 
20678
20678
  // node_modules/@chipschat/protocol/dist/src/context.js
20679
+ var CONTEXT_BUDGET = { lines: 40, chars: 16e3 };
20679
20680
  var CONTEXT_CEILING = { lines: 200, chars: 32e3 };
20680
20681
  var CONTEXT_HEADING = "Said in this space since you last spoke:";
20681
20682
  var contextBudget = external_exports.object({
@@ -26992,6 +26993,84 @@ var ContextFiles = class {
26992
26993
  }
26993
26994
  };
26994
26995
 
26996
+ // src/fold.ts
26997
+ var GATHER_MS = 150;
26998
+ function folds(message) {
26999
+ return message.handed !== true;
27000
+ }
27001
+ function keepAnswered(answered, messages) {
27002
+ answered.push(...messages.map((each) => each.message_id));
27003
+ answered.splice(0, Math.max(0, answered.length - CONTEXT_BUDGET.lines));
27004
+ }
27005
+ function keepHeard(since, heard) {
27006
+ since.push(heard);
27007
+ if (since.length > CONTEXT_BUDGET.lines) since.shift();
27008
+ }
27009
+ function lineOfHeard(heard) {
27010
+ const files = heard.attachments ?? [];
27011
+ const said = files.flatMap((file3) => file3.transcript === void 0 ? [] : [file3.transcript]);
27012
+ return {
27013
+ seq: 1,
27014
+ at: "",
27015
+ kind: "said",
27016
+ from: {
27017
+ id: heard.from.participant_id,
27018
+ kind: heard.from.kind,
27019
+ name: heard.from.display_name,
27020
+ ...heard.from.workspace_role === void 0 ? {} : { workspace_role: heard.from.workspace_role }
27021
+ },
27022
+ text: heard.text,
27023
+ ...said.length === 0 ? {} : { transcript: said.join(" ") },
27024
+ ...files.length === 0 ? {} : { files: files.map((file3) => file3.filename) },
27025
+ ...heard.held === true ? { held: true } : {}
27026
+ };
27027
+ }
27028
+ function sinceOf(since, earlier) {
27029
+ const newest = since.slice(-CONTEXT_BUDGET.lines);
27030
+ if (newest.length === 0) return void 0;
27031
+ const those = earlier.length === 0 ? "that message" : "those messages";
27032
+ return [`Said in this space after ${those}, to others:`, ...newest.map((each) => renderLine(lineOfHeard(each)))].join("\n");
27033
+ }
27034
+ function waitedWords(count) {
27035
+ return `${count} messages for you waited while you were working or away. They follow, oldest first. Answer them together in one reply, and where a later one changes or settles an earlier one, go by the later.`;
27036
+ }
27037
+ function saidOf(message, options, taker) {
27038
+ const who2 = options.sayWho === false ? "" : `${withRole(message.from.display_name, message.from)}: `;
27039
+ const files = (message.attachments ?? []).map(renderAttachment);
27040
+ const replying = renderReplyingTo(message.replying_to, {
27041
+ sender: {
27042
+ id: message.from.participant_id,
27043
+ name: message.from.display_name,
27044
+ kind: message.from.kind,
27045
+ workspace_role: message.from.workspace_role
27046
+ },
27047
+ taker,
27048
+ at: message.ts,
27049
+ zone: options.zone
27050
+ });
27051
+ return [replying, [`${who2}${message.text}`, ...files].join("\n")];
27052
+ }
27053
+ function contextOf(message, earlier, answered) {
27054
+ const { context } = message;
27055
+ const waited = /* @__PURE__ */ new Set([...earlier.map((each) => each.message_id), ...answered]);
27056
+ if (context === void 0 || waited.size === 0) return context;
27057
+ return { ...context, lines: context.lines.filter((line) => line.message_id === void 0 || !waited.has(line.message_id)) };
27058
+ }
27059
+ function promptForAll(message, options = {}) {
27060
+ const { earlier = [], since = [], answered = [], ...rest } = options;
27061
+ if (earlier.length === 0 && since.length === 0 && answered.length === 0) return promptFor(message, rest);
27062
+ const taker = rest.taker ?? (message.for?.length === 1 ? message.for[0] : void 0);
27063
+ const text = [
27064
+ earlier.length === 0 ? void 0 : waitedWords(earlier.length + 1),
27065
+ ...earlier.flatMap((each) => saidOf(each, rest, taker)),
27066
+ ...saidOf(message, rest, taker),
27067
+ sinceOf(since, earlier)
27068
+ ].filter((part) => part !== void 0 && part !== "").join("\n\n");
27069
+ const { attachments: _files, replying_to: _reply, ...bare } = message;
27070
+ const one = { ...bare, text, context: contextOf(message, earlier, answered) };
27071
+ return promptFor(one, { ...rest, sayWho: false });
27072
+ }
27073
+
26995
27074
  // src/models.ts
26996
27075
  var SETTINGS_LEVEL = "default";
26997
27076
  var LEVEL_WORDS = { xhigh: "Extra high" };
@@ -27180,6 +27259,19 @@ var IDLE_MS = 30 * 6e4;
27180
27259
  var ANSWERED = 500;
27181
27260
  var QUOTED = 1500;
27182
27261
  var CARRY_ON = "You were paused partway through this. Carry on from where you stopped. Nothing you wrote before the pause reached the room, so write your whole reply.";
27262
+ function shares(asked) {
27263
+ return asked.again === void 0 && folds(asked.message);
27264
+ }
27265
+ function nextTurn(queue) {
27266
+ const first = queue.shift();
27267
+ if (first === void 0) return [];
27268
+ const taken = [first];
27269
+ if (!shares(first)) return taken;
27270
+ while (queue[0] !== void 0 && shares(queue[0]) && queue[0].speakerId === first.speakerId) {
27271
+ taken.push(queue.shift());
27272
+ }
27273
+ return taken;
27274
+ }
27183
27275
  var Bridge = class {
27184
27276
  constructor(options) {
27185
27277
  this.options = options;
@@ -27201,6 +27293,8 @@ var Bridge = class {
27201
27293
  /** What Chips asks waits for the agents to be known: they are read at start. */
27202
27294
  known;
27203
27295
  knew = () => void 0;
27296
+ /** What is said in the rooms is taken in the order it came: a message, then what was overheard after it. */
27297
+ arriving = Promise.resolve();
27204
27298
  /** Records are made one at a time, so two never take the same folder. */
27205
27299
  making = Promise.resolve();
27206
27300
  /** The feedback already answered, oldest first. */
@@ -27234,7 +27328,11 @@ var Bridge = class {
27234
27328
  const after = (what, then) => {
27235
27329
  void this.known.then(then).catch((error62) => this.log(`${what} went wrong: ${messageOf(error62)}`));
27236
27330
  };
27237
- chips2.on("message.new", (message) => after("a message", () => this.hear(message)));
27331
+ const inOrder = (what, then) => {
27332
+ this.arriving = this.arriving.then(() => this.known).then(then).catch((error62) => this.log(`${what} went wrong: ${messageOf(error62)}`));
27333
+ };
27334
+ chips2.on("message.new", (message) => inOrder("a message", () => this.hear(message)));
27335
+ chips2.on("message.overheard", (message) => inOrder("words overheard", async () => this.overheard(message)));
27238
27336
  chips2.on("agent.asked", (asked) => after("a new agent", () => this.make(asked)));
27239
27337
  chips2.on("agent.fork", (fork) => after("a copy", () => this.copy(fork)));
27240
27338
  chips2.on("feedback", (feedback2) => after("a second look", () => this.lookAgain(feedback2)));
@@ -27263,6 +27361,7 @@ var Bridge = class {
27263
27361
  this.process.stopping = true;
27264
27362
  this.process.client?.close();
27265
27363
  clearInterval(this.sweeper);
27364
+ for (const room of this.rooms.values()) clearTimeout(room.gathering);
27266
27365
  for (const timer of this.windowTimers.values()) clearTimeout(timer);
27267
27366
  this.windowTimers.clear();
27268
27367
  }
@@ -27490,8 +27589,8 @@ var Bridge = class {
27490
27589
  for: [agent.agentId]
27491
27590
  };
27492
27591
  const room = this.roomOf(record2, spaceId);
27493
- room.queue.push({ message, speakerId: agent.agentId });
27494
- void this.pump(room);
27592
+ room.queue.push({ message, speakerId: agent.agentId, since: [] });
27593
+ this.soon(room);
27495
27594
  }
27496
27595
  /** Who said a room's first words, from the room's lines. */
27497
27596
  async whoSaid(asked) {
@@ -27659,18 +27758,52 @@ var Bridge = class {
27659
27758
  }
27660
27759
  }
27661
27760
  // ------------------------------------------------------------------ what is said to it
27662
- /** A message for some of its agents: each takes a turn in its room, one after another there. */
27761
+ /**
27762
+ * A message for some of its agents: each takes it in its room, one turn at a time there. It waits
27763
+ * while a turn is going, and is in the next with whatever else waits (Chips ADR 0294).
27764
+ */
27663
27765
  async hear(message, again2) {
27664
27766
  const spaceId = message.space_id;
27665
27767
  if (spaceId === void 0) return;
27666
27768
  const harnessId = this.options.chips.harnessId;
27769
+ const takes = /* @__PURE__ */ new Set();
27667
27770
  for (const taker of message.for ?? [harnessId]) {
27668
27771
  const record2 = taker === harnessId ? await this.inRoom(spaceId) : await this.recordOf(taker);
27669
27772
  if (record2 === void 0) continue;
27670
27773
  const room = this.roomOf(record2, spaceId);
27671
- room.queue.push({ message, speakerId: taker === harnessId ? void 0 : taker, again: again2 });
27672
- void this.pump(room);
27774
+ takes.add(room);
27775
+ room.queue.push({ message, speakerId: taker === harnessId ? void 0 : taker, again: again2, since: [] });
27776
+ this.soon(room);
27673
27777
  }
27778
+ if (again2 === void 0) this.saidToOthers(spaceId, message, takes);
27779
+ }
27780
+ /**
27781
+ * Words said in a room to others (Chips ADR 0294): kept where a message waits for one of its
27782
+ * agents there, as said after the newest of them, and told to the turn that takes it. Chips
27783
+ * hands a turn what was said before its message; this is what is said while the message waits.
27784
+ */
27785
+ overheard(message) {
27786
+ if (message.space_id !== void 0) this.saidToOthers(message.space_id, message, /* @__PURE__ */ new Set());
27787
+ }
27788
+ /** Kept by each of its agents in the room with a message waiting, but those it is for, and the one who said it. */
27789
+ saidToOthers(spaceId, said, takes) {
27790
+ for (const room of this.rooms.values()) {
27791
+ const newest = room.queue.at(-1);
27792
+ if (newest === void 0 || room.spaceId !== spaceId || takes.has(room)) continue;
27793
+ if (said.from.participant_id === room.record.agentId) continue;
27794
+ keepHeard(newest.since, { from: said.from, text: said.text, attachments: said.attachments, held: said.held });
27795
+ }
27796
+ }
27797
+ /**
27798
+ * An idle agent starts in a moment, not at once (Chips ADR 0294): a bridge that comes back is
27799
+ * sent all it missed together, and what waits when a turn starts is one turn.
27800
+ */
27801
+ soon(room) {
27802
+ if (room.busy || room.gathering !== void 0) return;
27803
+ room.gathering = setTimeout(() => {
27804
+ room.gathering = void 0;
27805
+ void this.pump(room);
27806
+ }, this.options.gatherMs ?? GATHER_MS);
27674
27807
  }
27675
27808
  /**
27676
27809
  * A person said a reply of one of its agents wasn't right (Chips ADR 0200): a correction, or an
@@ -27713,7 +27846,7 @@ var Bridge = class {
27713
27846
  const id2 = `${record2.key}|${spaceId}`;
27714
27847
  let room = this.rooms.get(id2);
27715
27848
  if (room === void 0) {
27716
- room = { record: record2, spaceId, queue: [], busy: false, usedAt: Date.now() };
27849
+ room = { record: record2, spaceId, queue: [], busy: false, usedAt: Date.now(), answered: [] };
27717
27850
  this.rooms.set(id2, room);
27718
27851
  }
27719
27852
  return room;
@@ -27736,11 +27869,11 @@ var Bridge = class {
27736
27869
  }
27737
27870
  return;
27738
27871
  }
27739
- const asked = room.queue.shift();
27740
- if (asked === void 0) return;
27872
+ const waiting = nextTurn(room.queue);
27873
+ if (waiting.length === 0) return;
27741
27874
  room.busy = true;
27742
27875
  try {
27743
- await this.turn(room, asked);
27876
+ await this.turn(room, waiting);
27744
27877
  } catch (error62) {
27745
27878
  this.log(`a turn of ${room.record.name} went wrong: ${String(error62)}`);
27746
27879
  } finally {
@@ -27752,7 +27885,13 @@ var Bridge = class {
27752
27885
  void this.pump(room);
27753
27886
  }
27754
27887
  }
27755
- async turn(room, { message, speakerId, again: again2 }) {
27888
+ /**
27889
+ * One turn on what waited (Chips ADR 0294): the newest message's, whose note and lines it is
27890
+ * handed, with those that waited ahead of it said in full, and what was said after to others.
27891
+ */
27892
+ async turn(room, waiting) {
27893
+ const { message, speakerId, again: again2, since } = waiting.at(-1);
27894
+ const earlier = waiting.slice(0, -1).map((each) => each.message);
27756
27895
  const { record: record2, spaceId } = room;
27757
27896
  const { kind: kind2 } = this.options;
27758
27897
  const speaker = speakerId === void 0 ? this.options.chips : this.options.chips.as(speakerId);
@@ -27821,11 +27960,19 @@ var Bridge = class {
27821
27960
  project
27822
27961
  };
27823
27962
  const rules = rulesFor(message, asked);
27824
- let words4 = promptFor(message, { ...asked, rulesHeld: this.rules.holds(sessionId, rules) });
27825
- const files = await this.filesFor(record2, message);
27963
+ let words4 = promptForAll(message, {
27964
+ ...asked,
27965
+ rulesHeld: this.rules.holds(sessionId, rules),
27966
+ earlier,
27967
+ since,
27968
+ answered: room.answered
27969
+ });
27970
+ const files = [];
27971
+ for (const each of [...earlier, message]) files.push(...await this.filesFor(record2, each));
27826
27972
  if (files.length > 0) words4 = `${words4}
27827
27973
 
27828
27974
  ${files.join("\n")}`;
27975
+ if (earlier.length > 0) this.log(`${record2.name} takes ${waiting.length} messages that waited in ${spaceId} as one turn`);
27829
27976
  if (!await this.unpaused(turn)) return;
27830
27977
  this.rules.told(sessionId, rules);
27831
27978
  let stop2 = "end_turn";
@@ -27843,6 +27990,7 @@ ${files.join("\n")}`;
27843
27990
  return;
27844
27991
  }
27845
27992
  turn.prompting = false;
27993
+ if (prompt === words4) keepAnswered(room.answered, [...earlier, message]);
27846
27994
  if (turn.cancelled) return;
27847
27995
  const paused = turn.pausing;
27848
27996
  turn.pausing = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chipschat/acp",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "An agent that speaks the Agent Client Protocol, as a Chips harness of its kind: agents made from Chips, each in a folder of its own, each room a session.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {