@celljs/ta-rooms 4.23.0 → 4.24.0
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/extension/index.mjs +75 -11
- package/host/index.mjs +418 -97
- package/package.json +4 -4
- package/web/index.js +332 -44
package/extension/index.mjs
CHANGED
|
@@ -519,10 +519,12 @@ var STALE_MS = 10 * 60 * 1000;
|
|
|
519
519
|
var HOURLY = 30;
|
|
520
520
|
var LOG_MAX = 300;
|
|
521
521
|
var ASK_MS = 24 * 60 * 60 * 1000;
|
|
522
|
-
var CONTEXT_LINES = 20;
|
|
523
522
|
var TASK_MS = 60 * 60 * 1000;
|
|
524
523
|
var TASKS_KEPT = 50;
|
|
525
|
-
var
|
|
524
|
+
var CONTEXT_CHARS = 6000;
|
|
525
|
+
var CONTEXT_LINES = 40;
|
|
526
|
+
var MERGE_GAP_MS = 60000;
|
|
527
|
+
var ROOM_TOOLS = ["room_state", "room_set_state", "room_history", "ask_permission"];
|
|
526
528
|
var CAPABILITY_TOOLS = {
|
|
527
529
|
files: ["read", "edit", "write", "grep", "find", "ls"],
|
|
528
530
|
commands: ["bash"]
|
|
@@ -678,21 +680,69 @@ var DoubleUtil;
|
|
|
678
680
|
}
|
|
679
681
|
DoubleUtil.permits = permits;
|
|
680
682
|
function prompt(input) {
|
|
681
|
-
const
|
|
682
|
-
const
|
|
683
|
-
const
|
|
683
|
+
const describe = input.describe ?? ((line) => RelayRoomChatUtil.preview(line, "[picture]"));
|
|
684
|
+
const said = (line) => `${DoubleUtil.quote(input.nameOf(line))}${line.double ? " (double)" : ""}: ${DoubleUtil.quote(describe(line))}`;
|
|
685
|
+
const asked = [...input.earlier ?? [], input.line];
|
|
686
|
+
const { before, cut: cut2, again } = window(input.lines, asked[0], said, input.window);
|
|
687
|
+
const answered2 = input.line.re && !before.some((each) => each.id === input.line.re) ? input.lines.find((each) => each.id === input.line.re) : undefined;
|
|
688
|
+
const readable = answered2 && !(input.window?.since !== undefined && answered2.at < input.window.since);
|
|
684
689
|
return [
|
|
685
690
|
input.permits,
|
|
686
691
|
`<room_request room="${DoubleUtil.quote(input.title)}" from="${DoubleUtil.quote(input.asker.name)}"${input.asker.guest ? ' guest="true"' : ""}>`,
|
|
687
|
-
...before.length ? ["The chat before it:", ...before.map(said), ""] : [],
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
692
|
+
...before.length ? [again ? "Said since you last read the chat:" : "The chat before it:", ...before.map(said), ""] : [],
|
|
693
|
+
...cut2 ? ["(Earlier lines are not shown: room_history finds them.)", ""] : [],
|
|
694
|
+
...readable && answered2 ? [`It answers this line: ${said(answered2)}`, ""] : [],
|
|
695
|
+
`${DoubleUtil.quote(input.asker.name)} asks you${asked.length > 1 ? ", in several lines one after another" : ""}:`,
|
|
696
|
+
...asked.map((line) => DoubleUtil.quote(describe(line))),
|
|
697
|
+
...asked.some((line) => line.images?.length) ? ["(Its pictures are attached, as far as they came.)"] : [],
|
|
691
698
|
"</room_request>"
|
|
692
699
|
].join(`
|
|
693
700
|
`);
|
|
694
701
|
}
|
|
695
702
|
DoubleUtil.prompt = prompt;
|
|
703
|
+
function window(lines, line, said, options = {}) {
|
|
704
|
+
const index = lines.findIndex((each) => each.id === line.id);
|
|
705
|
+
const end = index < 0 ? lines.length : index;
|
|
706
|
+
const seenAt = options.seen ? lines.findIndex((each) => each.id === options.seen) : -1;
|
|
707
|
+
const before = [];
|
|
708
|
+
let chars = 0;
|
|
709
|
+
let at = end - 1;
|
|
710
|
+
for (;at > seenAt && at >= 0; at--) {
|
|
711
|
+
const each = lines[at];
|
|
712
|
+
if (options.since !== undefined && each.at < options.since) {
|
|
713
|
+
break;
|
|
714
|
+
}
|
|
715
|
+
const size = said(each).length;
|
|
716
|
+
if (before.length >= CONTEXT_LINES || before.length && chars + size > CONTEXT_CHARS) {
|
|
717
|
+
break;
|
|
718
|
+
}
|
|
719
|
+
before.unshift(each);
|
|
720
|
+
chars += size;
|
|
721
|
+
}
|
|
722
|
+
const older = at > seenAt && at >= 0 && (options.since === undefined || lines[at].at >= options.since);
|
|
723
|
+
return { before, cut: older, again: seenAt >= 0 };
|
|
724
|
+
}
|
|
725
|
+
DoubleUtil.window = window;
|
|
726
|
+
function bursts(asking2) {
|
|
727
|
+
const groups = [];
|
|
728
|
+
const kind = (each) => `${each.line.from}|${each.agent?.id ?? ""}|${each.call ? "call" : "ask"}`;
|
|
729
|
+
for (const each of asking2) {
|
|
730
|
+
const group = groups.at(-1);
|
|
731
|
+
const last = group?.at(-1);
|
|
732
|
+
if (group && last && !each.line.task && !last.line.task && kind(last) === kind(each) && each.line.at - last.line.at <= MERGE_GAP_MS) {
|
|
733
|
+
group.push(each);
|
|
734
|
+
} else {
|
|
735
|
+
groups.push([each]);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return groups;
|
|
739
|
+
}
|
|
740
|
+
DoubleUtil.bursts = bursts;
|
|
741
|
+
function describeNote(count, wanted) {
|
|
742
|
+
const ids = wanted.map((at) => `p${at + 1}`).join(", ");
|
|
743
|
+
return `[Ta] ${count} picture(s) are attached, p1 to p${count} in order. After your reply, on lines of their own, write <pictures>, then for each of ${ids} a line "pN: what it shows, in one sentence, with any words in it", then </pictures>. Ta keeps that for later and takes it out of what is said.`;
|
|
744
|
+
}
|
|
745
|
+
DoubleUtil.describeNote = describeNote;
|
|
696
746
|
function taskNote(me, name) {
|
|
697
747
|
return `[Ta] This is a task ${name} handed you, not a question: do it, as far as you may, then reply with what came of it, short. If it needs something ${me} has not let you do, call ask_permission and reply what you need: the task waits, and goes on by itself once ${me} lets you.`;
|
|
698
748
|
}
|
|
@@ -744,14 +794,28 @@ var DOUBLE_TOOLS = [
|
|
|
744
794
|
label: "Room state",
|
|
745
795
|
description: "Reads the shared state of the room you are answering in (what its game or app keeps), by key: all of it, or the keys that start with prefix.",
|
|
746
796
|
parameters: { type: "object", properties: { prefix: { type: "string" } } },
|
|
747
|
-
run: (doubles, params, file) => doubles.
|
|
797
|
+
run: (doubles, params, file) => doubles.context.state(file, typeof params.prefix === "string" ? params.prefix : undefined)
|
|
748
798
|
},
|
|
749
799
|
{
|
|
750
800
|
name: "room_set_state",
|
|
751
801
|
label: "Set room state",
|
|
752
802
|
description: "Sets a key of the shared state of the room you are answering in, as its game or app keeps it (null clears it). Say things in your reply, not here.",
|
|
753
803
|
parameters: { type: "object", properties: { key: { type: "string" }, value: {} }, required: ["key", "value"] },
|
|
754
|
-
run: (doubles, params, file) => doubles.
|
|
804
|
+
run: (doubles, params, file) => doubles.context.setState(file, String(params.key ?? ""), params.value)
|
|
805
|
+
},
|
|
806
|
+
{
|
|
807
|
+
name: "room_history",
|
|
808
|
+
label: "Room history",
|
|
809
|
+
description: 'Finds what was said earlier in the room you are answering in, further back than the chat you were given: lines with every word of query (two languages if unsure: "发布 release"), or the latest without one; before a line (its #id) to read further back. This room alone.',
|
|
810
|
+
parameters: {
|
|
811
|
+
type: "object",
|
|
812
|
+
properties: {
|
|
813
|
+
query: { type: "string" },
|
|
814
|
+
before: { type: "string", description: "The #id of a line, without #: what was said before it." },
|
|
815
|
+
limit: { type: "number", description: "Lines at most, 20 by default, 50 at most." }
|
|
816
|
+
}
|
|
817
|
+
},
|
|
818
|
+
run: (doubles, params, file) => doubles.context.history(file, params)
|
|
755
819
|
},
|
|
756
820
|
{
|
|
757
821
|
name: "ask_permission",
|