@chipschat/acp 1.0.18 → 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 +4 -2
- package/dist/THIRD-PARTY-NOTICES.md +1 -1
- package/dist/main.js +252 -22
- package/package.json +1 -1
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 |
|
|
@@ -159,9 +160,10 @@ minutes and loaded again with its memory. Fourteen runs, none failed, $0.35, all
|
|
|
159
160
|
| The reply | `agent_message_chunk`s gathered into one message; `NO_REPLY` alone is the turn passed |
|
|
160
161
|
| Files in the reply | each `MEDIA:<path>` line of the reply sent as an upload with its words, only from the agent's folder (`sendAnswer`); the post says why one could not go |
|
|
161
162
|
| Approval card | `session/request_permission`, asked in the agent's own words where the call has a `description` (Claude Code's commands: "Syntax-check game.js? `node --check game.js`"), else "Allow it to" and the call's title; allowed always picks `allow_always`, except for a command, which picks `allow_once` since Chips remembers it by how each part starts (Chips ADR 0239); no picks `reject_once`; Stop answers `cancelled`; the card hears how the call went |
|
|
162
|
-
| Question card | `elicitation/create` form of up to four choice or yes/no fields; anything else is declined |
|
|
163
|
+
| Question card | `elicitation/create` form of up to four choice or yes/no fields; anything else is declined; Stop answers `cancel` |
|
|
163
164
|
| Stop | `session/cancel` |
|
|
164
|
-
|
|
|
165
|
+
| Pause (Chips ADR 0293) | each run says `pausable: true` as it starts; Pause is `session/cancel` with the run kept and nothing posted, and Resume the next prompt of the same session: "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.", then anything steered meanwhile. A Pause before a prompt holds it; one while an approval or question card waits stops nothing, and the answer reaches the agent on Resume |
|
|
166
|
+
| Steer | the next prompt of the same run, after `session/cancel` when it interrupts; the words it was cut off in are dropped, so the reply is one answer |
|
|
165
167
|
| Not right? (Chips ADR 0200) | a `correction`, or an older device's 👎: one more turn of the agent who said the reply (by its id in the room's lines), in that room's session, quoting its reply and what was wrong; the run is *Looking again: …*; a 👍 or any other reaction is nothing, and each is answered once |
|
|
166
168
|
| Restart | the agent's process stopped and run again |
|
|
167
169
|
| Trouble | the agent not running; it is run again after 2 s, longer each time it fails to start |
|
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" };
|
|
@@ -27179,6 +27258,20 @@ var MOST_RESPAWN_MS = 6e4;
|
|
|
27179
27258
|
var IDLE_MS = 30 * 6e4;
|
|
27180
27259
|
var ANSWERED = 500;
|
|
27181
27260
|
var QUOTED = 1500;
|
|
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
|
+
}
|
|
27182
27275
|
var Bridge = class {
|
|
27183
27276
|
constructor(options) {
|
|
27184
27277
|
this.options = options;
|
|
@@ -27200,6 +27293,8 @@ var Bridge = class {
|
|
|
27200
27293
|
/** What Chips asks waits for the agents to be known: they are read at start. */
|
|
27201
27294
|
known;
|
|
27202
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();
|
|
27203
27298
|
/** Records are made one at a time, so two never take the same folder. */
|
|
27204
27299
|
making = Promise.resolve();
|
|
27205
27300
|
/** The feedback already answered, oldest first. */
|
|
@@ -27233,7 +27328,11 @@ var Bridge = class {
|
|
|
27233
27328
|
const after = (what, then) => {
|
|
27234
27329
|
void this.known.then(then).catch((error62) => this.log(`${what} went wrong: ${messageOf(error62)}`));
|
|
27235
27330
|
};
|
|
27236
|
-
|
|
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)));
|
|
27237
27336
|
chips2.on("agent.asked", (asked) => after("a new agent", () => this.make(asked)));
|
|
27238
27337
|
chips2.on("agent.fork", (fork) => after("a copy", () => this.copy(fork)));
|
|
27239
27338
|
chips2.on("feedback", (feedback2) => after("a second look", () => this.lookAgain(feedback2)));
|
|
@@ -27262,6 +27361,7 @@ var Bridge = class {
|
|
|
27262
27361
|
this.process.stopping = true;
|
|
27263
27362
|
this.process.client?.close();
|
|
27264
27363
|
clearInterval(this.sweeper);
|
|
27364
|
+
for (const room of this.rooms.values()) clearTimeout(room.gathering);
|
|
27265
27365
|
for (const timer of this.windowTimers.values()) clearTimeout(timer);
|
|
27266
27366
|
this.windowTimers.clear();
|
|
27267
27367
|
}
|
|
@@ -27489,8 +27589,8 @@ var Bridge = class {
|
|
|
27489
27589
|
for: [agent.agentId]
|
|
27490
27590
|
};
|
|
27491
27591
|
const room = this.roomOf(record2, spaceId);
|
|
27492
|
-
room.queue.push({ message, speakerId: agent.agentId });
|
|
27493
|
-
|
|
27592
|
+
room.queue.push({ message, speakerId: agent.agentId, since: [] });
|
|
27593
|
+
this.soon(room);
|
|
27494
27594
|
}
|
|
27495
27595
|
/** Who said a room's first words, from the room's lines. */
|
|
27496
27596
|
async whoSaid(asked) {
|
|
@@ -27658,19 +27758,53 @@ var Bridge = class {
|
|
|
27658
27758
|
}
|
|
27659
27759
|
}
|
|
27660
27760
|
// ------------------------------------------------------------------ what is said to it
|
|
27661
|
-
/**
|
|
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
|
+
*/
|
|
27662
27765
|
async hear(message, again2) {
|
|
27663
27766
|
const spaceId = message.space_id;
|
|
27664
27767
|
if (spaceId === void 0) return;
|
|
27665
27768
|
const harnessId = this.options.chips.harnessId;
|
|
27769
|
+
const takes = /* @__PURE__ */ new Set();
|
|
27666
27770
|
for (const taker of message.for ?? [harnessId]) {
|
|
27667
27771
|
const record2 = taker === harnessId ? await this.inRoom(spaceId) : await this.recordOf(taker);
|
|
27668
27772
|
if (record2 === void 0) continue;
|
|
27669
27773
|
const room = this.roomOf(record2, spaceId);
|
|
27670
|
-
|
|
27671
|
-
void
|
|
27774
|
+
takes.add(room);
|
|
27775
|
+
room.queue.push({ message, speakerId: taker === harnessId ? void 0 : taker, again: again2, since: [] });
|
|
27776
|
+
this.soon(room);
|
|
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 });
|
|
27672
27795
|
}
|
|
27673
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);
|
|
27807
|
+
}
|
|
27674
27808
|
/**
|
|
27675
27809
|
* A person said a reply of one of its agents wasn't right (Chips ADR 0200): a correction, or an
|
|
27676
27810
|
* older device's 👎. The agent who said it, found by the reply's id in the room's lines, looks
|
|
@@ -27712,7 +27846,7 @@ var Bridge = class {
|
|
|
27712
27846
|
const id2 = `${record2.key}|${spaceId}`;
|
|
27713
27847
|
let room = this.rooms.get(id2);
|
|
27714
27848
|
if (room === void 0) {
|
|
27715
|
-
room = { record: record2, spaceId, queue: [], busy: false, usedAt: Date.now() };
|
|
27849
|
+
room = { record: record2, spaceId, queue: [], busy: false, usedAt: Date.now(), answered: [] };
|
|
27716
27850
|
this.rooms.set(id2, room);
|
|
27717
27851
|
}
|
|
27718
27852
|
return room;
|
|
@@ -27735,11 +27869,11 @@ var Bridge = class {
|
|
|
27735
27869
|
}
|
|
27736
27870
|
return;
|
|
27737
27871
|
}
|
|
27738
|
-
const
|
|
27739
|
-
if (
|
|
27872
|
+
const waiting = nextTurn(room.queue);
|
|
27873
|
+
if (waiting.length === 0) return;
|
|
27740
27874
|
room.busy = true;
|
|
27741
27875
|
try {
|
|
27742
|
-
await this.turn(room,
|
|
27876
|
+
await this.turn(room, waiting);
|
|
27743
27877
|
} catch (error62) {
|
|
27744
27878
|
this.log(`a turn of ${room.record.name} went wrong: ${String(error62)}`);
|
|
27745
27879
|
} finally {
|
|
@@ -27751,7 +27885,13 @@ var Bridge = class {
|
|
|
27751
27885
|
void this.pump(room);
|
|
27752
27886
|
}
|
|
27753
27887
|
}
|
|
27754
|
-
|
|
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);
|
|
27755
27895
|
const { record: record2, spaceId } = room;
|
|
27756
27896
|
const { kind: kind2 } = this.options;
|
|
27757
27897
|
const speaker = speakerId === void 0 ? this.options.chips : this.options.chips.as(speakerId);
|
|
@@ -27766,6 +27906,10 @@ var Bridge = class {
|
|
|
27766
27906
|
thought: "",
|
|
27767
27907
|
next: [],
|
|
27768
27908
|
cancelled: false,
|
|
27909
|
+
prompting: false,
|
|
27910
|
+
stopping: false,
|
|
27911
|
+
pausing: false,
|
|
27912
|
+
asking: 0,
|
|
27769
27913
|
saidAt: 0,
|
|
27770
27914
|
gaugeAt: 0,
|
|
27771
27915
|
steps: /* @__PURE__ */ new Map(),
|
|
@@ -27774,14 +27918,27 @@ var Bridge = class {
|
|
|
27774
27918
|
folds: 0
|
|
27775
27919
|
};
|
|
27776
27920
|
room.turn = turn;
|
|
27921
|
+
this.sayPausable(run2, speakerId);
|
|
27922
|
+
const interrupt = () => {
|
|
27923
|
+
if (!turn.prompting || turn.stopping) return;
|
|
27924
|
+
turn.stopping = true;
|
|
27925
|
+
this.process.client?.cancel(turn.sessionId);
|
|
27926
|
+
};
|
|
27777
27927
|
run2.on("cancel", () => {
|
|
27778
27928
|
turn.cancelled = true;
|
|
27779
|
-
|
|
27929
|
+
interrupt();
|
|
27780
27930
|
});
|
|
27781
27931
|
run2.on("steer", (steer) => {
|
|
27782
27932
|
turn.next.push(`${steer.from?.display_name ?? "The person"} adds: ${steer.text}`);
|
|
27783
|
-
if (steer.mode === "interrupt"
|
|
27933
|
+
if (steer.mode === "interrupt") interrupt();
|
|
27784
27934
|
});
|
|
27935
|
+
run2.on("pause", () => {
|
|
27936
|
+
this.log(`${record2.name} paused in ${spaceId}`);
|
|
27937
|
+
if (turn.asking > 0 || !turn.prompting) return;
|
|
27938
|
+
turn.pausing = true;
|
|
27939
|
+
interrupt();
|
|
27940
|
+
});
|
|
27941
|
+
run2.on("resume", () => this.log(`${record2.name} resumed in ${spaceId}`));
|
|
27785
27942
|
const client = await this.running();
|
|
27786
27943
|
if (client === void 0) {
|
|
27787
27944
|
if (!run2.over) await run2.fail({ error: `${kind2.name} isn't running right now.`, retryable: true });
|
|
@@ -27803,28 +27960,78 @@ var Bridge = class {
|
|
|
27803
27960
|
project
|
|
27804
27961
|
};
|
|
27805
27962
|
const rules = rulesFor(message, asked);
|
|
27806
|
-
let words4 =
|
|
27807
|
-
|
|
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));
|
|
27808
27972
|
if (files.length > 0) words4 = `${words4}
|
|
27809
27973
|
|
|
27810
27974
|
${files.join("\n")}`;
|
|
27811
|
-
if (
|
|
27975
|
+
if (earlier.length > 0) this.log(`${record2.name} takes ${waiting.length} messages that waited in ${spaceId} as one turn`);
|
|
27976
|
+
if (!await this.unpaused(turn)) return;
|
|
27812
27977
|
this.rules.told(sessionId, rules);
|
|
27813
27978
|
let stop2 = "end_turn";
|
|
27814
|
-
|
|
27979
|
+
let prompt = words4;
|
|
27980
|
+
while (prompt !== void 0) {
|
|
27981
|
+
if (!await this.unpaused(turn)) return;
|
|
27982
|
+
turn.prompting = true;
|
|
27983
|
+
turn.stopping = false;
|
|
27815
27984
|
try {
|
|
27816
27985
|
stop2 = await client.prompt(sessionId, [{ type: "text", text: prompt }]);
|
|
27817
27986
|
} catch (error62) {
|
|
27987
|
+
turn.prompting = false;
|
|
27818
27988
|
this.rules.forget(sessionId);
|
|
27819
27989
|
if (!run2.over) await run2.fail({ error: this.failure(record2, error62), retryable: true });
|
|
27820
27990
|
return;
|
|
27821
27991
|
}
|
|
27992
|
+
turn.prompting = false;
|
|
27993
|
+
if (prompt === words4) keepAnswered(room.answered, [...earlier, message]);
|
|
27822
27994
|
if (turn.cancelled) return;
|
|
27823
|
-
|
|
27995
|
+
const paused = turn.pausing;
|
|
27996
|
+
turn.pausing = false;
|
|
27997
|
+
if (!await this.unpaused(turn)) return;
|
|
27998
|
+
if (stop2 === "cancelled" && (paused || turn.next.length > 0)) {
|
|
27999
|
+
turn.reply = "";
|
|
28000
|
+
prompt = paused ? [CARRY_ON, ...turn.next.splice(0)].join("\n\n") : turn.next.shift();
|
|
28001
|
+
continue;
|
|
28002
|
+
}
|
|
27824
28003
|
if (stop2 !== "end_turn" && stop2 !== "cancelled") break;
|
|
28004
|
+
prompt = turn.next.shift();
|
|
27825
28005
|
}
|
|
27826
28006
|
await this.finish(room, turn, stop2);
|
|
27827
28007
|
}
|
|
28008
|
+
/**
|
|
28009
|
+
* Once the run isn't paused (Chips ADR 0293): true to go on, false when it was stopped, before or
|
|
28010
|
+
* while it waited, which ends the turn with nothing more said, as a Stop does.
|
|
28011
|
+
*/
|
|
28012
|
+
async unpaused(turn) {
|
|
28013
|
+
if (turn.run.paused) await turn.run.whenRunning();
|
|
28014
|
+
return !turn.cancelled && !turn.run.over;
|
|
28015
|
+
}
|
|
28016
|
+
/**
|
|
28017
|
+
* That the run can pause (Chips ADR 0293), said once as it starts on a status of "Thinking…".
|
|
28018
|
+
* The SDK this is built on, 1.0.4, has no word for it in `run.status()`, so it goes on the
|
|
28019
|
+
* connection in the run's own envelope, as one of its agents' when it is theirs. A server from
|
|
28020
|
+
* before drops the word, and a send that fails costs the turn nothing.
|
|
28021
|
+
*/
|
|
28022
|
+
sayPausable(run2, speakerId) {
|
|
28023
|
+
const envelope2 = {
|
|
28024
|
+
space_id: run2.spaceId,
|
|
28025
|
+
run_id: run2.id,
|
|
28026
|
+
...speakerId === void 0 ? {} : { actor: { kind: "agent", id: speakerId } }
|
|
28027
|
+
};
|
|
28028
|
+
const unsaid = (error62) => this.log(`couldn't say run ${run2.id} can pause: ${messageOf(error62)}`);
|
|
28029
|
+
try {
|
|
28030
|
+
void this.options.chips.send("run.status", envelope2, { phase: "thinking", verb_phrase: "Thinking\u2026", pausable: true }).catch(unsaid);
|
|
28031
|
+
} catch (error62) {
|
|
28032
|
+
unsaid(error62);
|
|
28033
|
+
}
|
|
28034
|
+
}
|
|
27828
28035
|
/**
|
|
27829
28036
|
* The room's session: the one it had, loaded once, or a new one, in the agent's folder, put on
|
|
27830
28037
|
* the agent's model. One a change from Chips made stale is closed and loaded again first, so the
|
|
@@ -28608,6 +28815,7 @@ ${files.join("\n")}`;
|
|
|
28608
28815
|
const turn = this.turnOf(String(params["sessionId"]));
|
|
28609
28816
|
const options = Array.isArray(params["options"]) ? params["options"] : [];
|
|
28610
28817
|
if (turn === void 0) return { outcome: { outcome: "cancelled" } };
|
|
28818
|
+
if (turn.pausing) return { outcome: { outcome: "cancelled" } };
|
|
28611
28819
|
const call = params["toolCall"] ?? {};
|
|
28612
28820
|
const kind2 = toolOf(call) ?? "other";
|
|
28613
28821
|
const title2 = typeof call["title"] === "string" ? call["title"] : `use ${kind2}`;
|
|
@@ -28620,8 +28828,7 @@ ${files.join("\n")}`;
|
|
|
28620
28828
|
...input2 === void 0 ? {} : { preview: { format: "json", body: JSON.stringify(input2, null, 2).slice(0, 2e5) } },
|
|
28621
28829
|
...call["toolCallId"] === void 0 ? {} : { stepId: String(call["toolCallId"]) }
|
|
28622
28830
|
});
|
|
28623
|
-
const
|
|
28624
|
-
const decision = await Promise.race([asked, stopped2]);
|
|
28831
|
+
const decision = await this.answerOf(turn, asked);
|
|
28625
28832
|
if (decision === void 0) return { outcome: { outcome: "cancelled" } };
|
|
28626
28833
|
const chosen = optionFor(decision, options, carriesCommand(input2));
|
|
28627
28834
|
if (decision.allowed && chosen !== void 0 && call["toolCallId"] !== void 0) {
|
|
@@ -28641,8 +28848,10 @@ ${files.join("\n")}`;
|
|
|
28641
28848
|
if (turn === void 0 || questions.length === 0 || questions.length > 4 || questions.some((q) => q === void 0)) {
|
|
28642
28849
|
return { action: "decline" };
|
|
28643
28850
|
}
|
|
28644
|
-
|
|
28645
|
-
|
|
28851
|
+
if (turn.pausing) return { action: "cancel" };
|
|
28852
|
+
const asked = turn.run.question({ questions });
|
|
28853
|
+
const answer = await this.answerOf(turn, asked);
|
|
28854
|
+
if (answer === void 0 || answer.timedOut) return { action: "cancel" };
|
|
28646
28855
|
const content = {};
|
|
28647
28856
|
for (const [id2, field] of properties) {
|
|
28648
28857
|
const value = answer.answers[id2]?.values[0];
|
|
@@ -28651,6 +28860,26 @@ ${files.join("\n")}`;
|
|
|
28651
28860
|
}
|
|
28652
28861
|
return { action: "accept", content };
|
|
28653
28862
|
}
|
|
28863
|
+
/**
|
|
28864
|
+
* A person's answer to what the agent asked, once the agent may have it: one given while the run
|
|
28865
|
+
* is paused waits for Resume (Chips ADR 0293), and a Stop, before the answer or while it waits,
|
|
28866
|
+
* leaves none. While an ask waits, a Pause stops nothing.
|
|
28867
|
+
*/
|
|
28868
|
+
async answerOf(turn, asked) {
|
|
28869
|
+
let off = () => void 0;
|
|
28870
|
+
const stopped2 = new Promise((resolve5) => {
|
|
28871
|
+
off = turn.run.on("cancel", () => resolve5(void 0));
|
|
28872
|
+
});
|
|
28873
|
+
turn.asking += 1;
|
|
28874
|
+
try {
|
|
28875
|
+
const answer = await Promise.race([asked, stopped2]);
|
|
28876
|
+
if (answer === void 0) return void 0;
|
|
28877
|
+
return await this.unpaused(turn) ? answer : void 0;
|
|
28878
|
+
} finally {
|
|
28879
|
+
off();
|
|
28880
|
+
turn.asking -= 1;
|
|
28881
|
+
}
|
|
28882
|
+
}
|
|
28654
28883
|
};
|
|
28655
28884
|
function settingsFor(kind2, bridge2) {
|
|
28656
28885
|
const active = () => {
|
|
@@ -28836,6 +29065,7 @@ function keepIfAsked(label2, url2, names, log2, before = () => void 0) {
|
|
|
28836
29065
|
1
|
|
28837
29066
|
);
|
|
28838
29067
|
}
|
|
29068
|
+
if (kept2.state !== "off" && kept2.state !== "unsupported") return;
|
|
28839
29069
|
log2(
|
|
28840
29070
|
kept2.state === "off" ? "Keeping it running is off here (CHIPS_KEEP=off): it runs here, while this terminal is open." : "Nothing on this machine can keep it running (launchd, systemd): it runs here, while this terminal is open."
|
|
28841
29071
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chipschat/acp",
|
|
3
|
-
"version": "1.0.
|
|
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": {
|