copilotz 1.0.0-rc.16 → 1.0.0-rc.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +2 -2
- package/package.json +1 -1
- package/plugins/agents/chat/collections/file.d.ts +2 -0
- package/plugins/agents/chat/collections/file.js +2 -0
- package/plugins/agents/chat/collections/message.d.ts +10 -2
- package/plugins/agents/chat/collections/message.js +9 -3
- package/plugins/agents/chat/contract.d.ts +1 -0
- package/plugins/agents/chat/contract.js +1 -0
- package/plugins/agents/chat/processors/turn.js +5 -1
- package/plugins/agents/chat/shared/delivery.d.ts +2 -0
- package/plugins/agents/chat/shared/delivery.js +4 -1
- package/plugins/agents/chat/shared/lineage.d.ts +24 -5
- package/plugins/agents/chat/shared/lineage.js +55 -21
- package/plugins/agents/chat/views/message.js +5 -5
- package/plugins/agents/chat/views/prompt.js +4 -7
- package/plugins/agents/history/collections/outline.d.ts +51 -4
- package/plugins/agents/history/collections/outline.js +17 -3
- package/plugins/agents/history/mod.d.ts +4 -0
- package/plugins/agents/history/mod.js +4 -0
- package/plugins/agents/history/processors/compact.d.ts +6 -1
- package/plugins/agents/history/processors/compact.js +50 -13
- package/plugins/agents/history/resources/tools.js +11 -5
- package/plugins/agents/history/shared/lines.d.ts +2 -2
- package/plugins/agents/history/shared/lines.js +3 -2
- package/plugins/agents/history/shared/settings.d.ts +5 -1
- package/plugins/agents/history/shared/weight.d.ts +28 -0
- package/plugins/agents/history/shared/weight.js +62 -0
- package/plugins/agents/history/views/history.js +5 -1
- package/plugins/agents/history/views/since.d.ts +6 -3
- package/plugins/agents/history/views/since.js +9 -2
- package/plugins/billing/credits/shared/standing.js +2 -2
- package/plugins/compute/computers/program/version.d.ts +1 -1
- package/plugins/compute/computers/program/version.js +1 -1
- package/plugins/compute/computers/resources/downloads.js +1 -1
- package/plugins/models/adapters/llm/anthropic.js +5 -4
- package/plugins/models/adapters/llm/openai.js +97 -33
- package/plugins/models/shared/generate.js +26 -5
- package/plugins/models/shared/types.d.ts +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
+
## 1.0.0-rc.17 — 2026-11-03
|
|
2
|
+
|
|
3
|
+
- **A model's state goes back with its answers.** What a model returns to be sent back (Anthropic's
|
|
4
|
+
signed thinking, Gemini's thought signatures) was kept on tool steps but dropped on the final
|
|
5
|
+
answer, so the next turn started without it. Answers keep it now, and agents are sent it on
|
|
6
|
+
text-only messages too. A message's `state` is private, like `told`: people's reads and events go
|
|
7
|
+
without it, and an answer handed back to another space doesn't carry it.
|
|
8
|
+
- **OpenAI's reasoning goes back to it.** The Responses adapter asks for a reasoning model's
|
|
9
|
+
reasoning, encrypted (`include: ["reasoning.encrypted_content"]`), keeps it as its answer's state,
|
|
10
|
+
in its place among the answer's text and calls, without ids, and sends it back. Between tool steps
|
|
11
|
+
the model carries on instead of thinking again: on gpt-6.1-sol, a two-turn tool task wrote 42%
|
|
12
|
+
fewer output tokens. A server that refuses `include` is asked again without it, and not asked
|
|
13
|
+
again. Sent back, past reasoning stays in later prompts (a probe: 616 input tokens with it, 48
|
|
14
|
+
without), so a state now says about what it adds (`LlmState.tokens`), and history counts it.
|
|
15
|
+
- **History counts what a prompt really carries.** The history plugin's tail is measured in
|
|
16
|
+
estimated tokens of what an agent is sent for each message: its text, its model's state, text
|
|
17
|
+
files' content, transcripts, images (1,600 each) and PDFs (2,000 a page), and agents' tool steps,
|
|
18
|
+
which leave the tail without a line. `tail` is in tokens now (was bytes), and its default stays
|
|
19
|
+
`[16_000, 48_000]`, so a text-only conversation keeps about four times more whole.
|
|
20
|
+
- Until the tail first cuts, every message is sent: no 50-message cut before anything is
|
|
21
|
+
summarized. That holds for threads whose outline began with them; older ones get chat's window
|
|
22
|
+
until their first cut.
|
|
23
|
+
- The four newest shared messages always stay whole, so a big file stays while it's talked about.
|
|
24
|
+
- A message's line names its files, and `zoom(id, 1)` gives the message as the agent is sent it,
|
|
25
|
+
text files' content included.
|
|
26
|
+
- After a cut, state from before it (thinking bound to how the conversation began) isn't sent
|
|
27
|
+
again; and when a provider refuses a model's own state as stale anyway, the call is tried once
|
|
28
|
+
more without any.
|
|
29
|
+
- Outlines no longer log events.
|
|
30
|
+
- **Without the history plugin,** an agent's window holds 50 to 100 messages and drops 50 at a time
|
|
31
|
+
(was the latest 50, one off every turn), so the prompt cache holds between drops. `lineage`
|
|
32
|
+
(exported) takes `batched`; its `since: ""` now means every message, and its db needs
|
|
33
|
+
`countDocuments`.
|
|
34
|
+
- **Fixed:** lifting a usage waiver gave back nothing for a use recorded in the very millisecond it
|
|
35
|
+
was lifted (a flaky billing test showed it).
|
|
36
|
+
|
|
1
37
|
## 1.0.0-rc.16 — 2026-11-02
|
|
2
38
|
|
|
3
39
|
- **Fixed:** staff by email weren't staff anywhere but going into an org. `org.mine` asked without
|
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.
|
|
25
|
+
On Deno, name it `copilotz` in `deno.json` (`"copilotz": "jsr:@copilotz/copilotz@^1.0.0-rc.17"`),
|
|
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 web host on Node, `@electric-sql/pglite` for PostgreSQL in the
|
|
28
28
|
process, and `@types/react` for the front ends' types.
|
|
@@ -204,7 +204,7 @@ and an app serves it from there by default:
|
|
|
204
204
|
import { computerDownloads } from "copilotz/plugins/compute/downloads";
|
|
205
205
|
|
|
206
206
|
plugins: [...plugins, await computerDownloads()], // this Copilotz's release
|
|
207
|
-
plugins: [...plugins, await computerDownloads({ dir: "dist/computer/1.0.0-rc.
|
|
207
|
+
plugins: [...plugins, await computerDownloads({ dir: "dist/computer/1.0.0-rc.17" })], // its own: /computer/download/
|
|
208
208
|
plugins: [...plugins, await computerDownloads({ url: "https://downloads.example.com/computer/" })], // or elsewhere
|
|
209
209
|
```
|
|
210
210
|
|
package/package.json
CHANGED
|
@@ -138,6 +138,8 @@ export type File = Infer<typeof fileSchema> & {
|
|
|
138
138
|
_id: string;
|
|
139
139
|
};
|
|
140
140
|
/** Media types read as text: what agents get the content of. */
|
|
141
|
+
/** How much of a text file an agent is sent. */
|
|
142
|
+
export declare const FILE_CHARS = 20000;
|
|
141
143
|
export declare const textual: (type: string) => boolean;
|
|
142
144
|
/** A base64 file's content as text. */
|
|
143
145
|
export declare const text: (data: string) => string;
|
|
@@ -43,6 +43,8 @@ export const file = defineCollection({
|
|
|
43
43
|
},
|
|
44
44
|
});
|
|
45
45
|
/** Media types read as text: what agents get the content of. */
|
|
46
|
+
/** How much of a text file an agent is sent. */
|
|
47
|
+
export const FILE_CHARS = 20_000;
|
|
46
48
|
export const textual = (type) => type.startsWith("text/") || /json|xml|yaml|csv|javascript|typescript/.test(type);
|
|
47
49
|
/** A base64 file's content as text. */
|
|
48
50
|
export const text = (data) => new TextDecoder().decode(Uint8Array.from(atob(data), (c) => c.charCodeAt(0)));
|
|
@@ -150,7 +150,11 @@ declare const messageSchema: {
|
|
|
150
150
|
};
|
|
151
151
|
readonly required: readonly ["thread"];
|
|
152
152
|
};
|
|
153
|
-
/**
|
|
153
|
+
/**
|
|
154
|
+
* Its model's state (thinking, signatures) on a step or an answer: sent
|
|
155
|
+
* back to that model in its later calls, this turn's and the next ones'.
|
|
156
|
+
* Only trusted code reads it.
|
|
157
|
+
*/
|
|
154
158
|
readonly state: {
|
|
155
159
|
readonly type: "object";
|
|
156
160
|
};
|
|
@@ -331,7 +335,11 @@ export declare const message: {
|
|
|
331
335
|
};
|
|
332
336
|
readonly required: readonly ["thread"];
|
|
333
337
|
};
|
|
334
|
-
/**
|
|
338
|
+
/**
|
|
339
|
+
* Its model's state (thinking, signatures) on a step or an answer: sent
|
|
340
|
+
* back to that model in its later calls, this turn's and the next ones'.
|
|
341
|
+
* Only trusted code reads it.
|
|
342
|
+
*/
|
|
335
343
|
readonly state: {
|
|
336
344
|
readonly type: "object";
|
|
337
345
|
};
|
|
@@ -84,7 +84,11 @@ const messageSchema = {
|
|
|
84
84
|
properties: { thread: { type: "string" }, in: { type: "string" }, from: { type: "string" } },
|
|
85
85
|
required: ["thread"],
|
|
86
86
|
},
|
|
87
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Its model's state (thinking, signatures) on a step or an answer: sent
|
|
89
|
+
* back to that model in its later calls, this turn's and the next ones'.
|
|
90
|
+
* Only trusted code reads it.
|
|
91
|
+
*/
|
|
88
92
|
state: { type: "object" },
|
|
89
93
|
/**
|
|
90
94
|
* What its sender was told before writing it, at the start of its turn
|
|
@@ -105,7 +109,8 @@ const messageSchema = {
|
|
|
105
109
|
};
|
|
106
110
|
export const message = defineCollection({
|
|
107
111
|
schema: messageSchema,
|
|
108
|
-
|
|
112
|
+
// What it was told and its model's state are the agent's: people's reads and events go without.
|
|
113
|
+
private: ["told", "state"],
|
|
109
114
|
queries: {
|
|
110
115
|
/**
|
|
111
116
|
* Everything in a thread, oldest first, agents' private steps included.
|
|
@@ -141,9 +146,10 @@ export const message = defineCollection({
|
|
|
141
146
|
* sent elsewhere, in place of the messages it sent (its steps show them).
|
|
142
147
|
*/
|
|
143
148
|
visible: async (messages, params, ctx) => {
|
|
149
|
+
// Summarized (another plugin's), from where it says; else a window that moves in batches.
|
|
144
150
|
const recent = await lineage(ctx.db, params.thread, {
|
|
145
151
|
agent: params.agent,
|
|
146
|
-
...(params.since ? { since: params.since } : {}),
|
|
152
|
+
...(params.since !== undefined ? { since: params.since } : { batched: true }),
|
|
147
153
|
});
|
|
148
154
|
const sent = new Set(recent.flatMap((m) => m.from === params.agent
|
|
149
155
|
? (m.toolCalls ?? []).flatMap((c) => c.sent ?? [])
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* `turn.requested`), its Actions (`chat.send`, `chat.stop`, `chat.move`…).
|
|
13
13
|
*/
|
|
14
14
|
export type { File } from "./collections/file.js";
|
|
15
|
+
export { FILE_CHARS, textual } from "./collections/file.js";
|
|
15
16
|
export type { Live, LiveCall } from "./collections/live.js";
|
|
16
17
|
export type { Message } from "./collections/message.js";
|
|
17
18
|
export type { Thread } from "./collections/thread.js";
|
|
@@ -117,7 +117,11 @@ const turn = async (ctx, event) => {
|
|
|
117
117
|
}
|
|
118
118
|
if (!calls.length) {
|
|
119
119
|
await live.settle();
|
|
120
|
-
|
|
120
|
+
// Its answer keeps what it was told, and its state: what it thought goes back with it.
|
|
121
|
+
return await answer(ctx, t, run, text, {
|
|
122
|
+
...(step === first ? { told } : {}),
|
|
123
|
+
...(state ? { state } : {}),
|
|
124
|
+
}, current);
|
|
121
125
|
}
|
|
122
126
|
// Ids derive from the run, so a retry rewrites nothing it already committed.
|
|
123
127
|
const id = `${run}:${step}`;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Delivering a message: the turns it starts and the waits it checks off; and agents' answers. */
|
|
2
2
|
import type { Context, Resources, TransactionScope } from "../../../../runtime/mod.js";
|
|
3
|
+
import type { LlmState } from "../../../models/contract.js";
|
|
3
4
|
import type { Thread } from "../collections/thread.js";
|
|
4
5
|
import { type Told, type Turn } from "./types.js";
|
|
5
6
|
/** Whether a message after `hops` agent messages in a row may still start a turn. */
|
|
@@ -35,6 +36,7 @@ export declare const answer: (ctx: Context, t: Turn, run: string, text: string,
|
|
|
35
36
|
failed?: boolean;
|
|
36
37
|
stopped?: boolean;
|
|
37
38
|
told?: Told[];
|
|
39
|
+
state?: LlmState;
|
|
38
40
|
},
|
|
39
41
|
/** The turn's thread, when it has it already. */
|
|
40
42
|
known?: Pick<Thread, "in">) => Promise<void>;
|
|
@@ -70,6 +70,8 @@ known) => {
|
|
|
70
70
|
...(how.stopped ? { stopped: true } : {}),
|
|
71
71
|
// What it was told this turn, when it's the turn's first message.
|
|
72
72
|
...(how.told?.length ? { told: how.told } : {}),
|
|
73
|
+
// Its model's state (its thinking), for that model's next calls: private, like `told`.
|
|
74
|
+
...(how.state ? { state: how.state } : {}),
|
|
73
75
|
at: now(),
|
|
74
76
|
};
|
|
75
77
|
// Handed over from another space: the answer goes back there too, where its sender waits.
|
|
@@ -86,6 +88,7 @@ known) => {
|
|
|
86
88
|
path: `/thread/${encodeURIComponent(t.thread)}${thread?.in ? `?in=${encodeURIComponent(thread.in)}` : ""}`,
|
|
87
89
|
},
|
|
88
90
|
told: undefined,
|
|
91
|
+
state: undefined,
|
|
89
92
|
}
|
|
90
93
|
: undefined;
|
|
91
94
|
const writer = returned ? ctx.as() : ctx;
|
|
@@ -98,7 +101,7 @@ known) => {
|
|
|
98
101
|
await tx.db.collection("message").insertOne(reply);
|
|
99
102
|
await noted(tx, reply);
|
|
100
103
|
if (returned) {
|
|
101
|
-
const { told: _, ...copy } = returned;
|
|
104
|
+
const { told: _, state: __, ...copy } = returned;
|
|
102
105
|
await tx.db.collection("message").insertOne(copy);
|
|
103
106
|
await noted(tx, copy);
|
|
104
107
|
}
|
|
@@ -2,17 +2,36 @@
|
|
|
2
2
|
import type { Collection } from "../../../../runtime/mod.js";
|
|
3
3
|
import type { Message } from "../collections/message.js";
|
|
4
4
|
type Reads = {
|
|
5
|
-
collection<T>(name: string): Pick<Collection<T>, "find" | "findOne">;
|
|
5
|
+
collection<T>(name: string): Pick<Collection<T>, "find" | "findOne" | "countDocuments">;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* Where an agent's window of a thread starts when nothing summarizes it: it
|
|
9
|
+
* holds from HISTORY to twice that, and drops HISTORY at a time, so between
|
|
10
|
+
* drops each prompt starts as the last one did (and the provider's cache
|
|
11
|
+
* holds it).
|
|
12
|
+
*/
|
|
13
|
+
export declare const windowStart: (total: number) => number;
|
|
14
|
+
/**
|
|
15
|
+
* A thread's messages, oldest first. A fork continues with its parent's, up
|
|
16
|
+
* to the message it started at, and so on up the lineage; nothing is copied.
|
|
17
|
+
* `agent` limits them to what that agent sees: the shared ones and its own
|
|
18
|
+
* private steps. Which of its own:
|
|
19
|
+
*
|
|
20
|
+
* - `since` (where a summarized history turns whole, `""` before it does):
|
|
21
|
+
* every one from then on, and the latest HISTORY of what it inherited;
|
|
22
|
+
* - `batched` (an agent's, unsummarized): the window `windowStart` says, and
|
|
23
|
+
* the latest HISTORY of what it inherited while that window starts at its
|
|
24
|
+
* first message;
|
|
25
|
+
* - else the latest `limit` (HISTORY), through the lineage.
|
|
26
|
+
*
|
|
27
|
+
* Each level is one query the owner keeps cached: of a fixed size (the
|
|
28
|
+
* window is sliced from the latest 2 × HISTORY), so the cache holds one entry
|
|
29
|
+
* per thread and agent, not one per turn.
|
|
12
30
|
*/
|
|
13
31
|
export declare function lineage(db: Reads, id: string, options?: {
|
|
14
32
|
agent?: string;
|
|
15
33
|
limit?: number;
|
|
16
34
|
since?: string;
|
|
35
|
+
batched?: boolean;
|
|
17
36
|
}): Promise<Message[]>;
|
|
18
37
|
export {};
|
|
@@ -1,29 +1,60 @@
|
|
|
1
1
|
import { HISTORY } from "./agents.js";
|
|
2
|
+
/** Only a guard: from `since` on, a summarized history's budget is what bounds them. */
|
|
3
|
+
const WHOLE = 5_000;
|
|
2
4
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Where an agent's window of a thread starts when nothing summarizes it: it
|
|
6
|
+
* holds from HISTORY to twice that, and drops HISTORY at a time, so between
|
|
7
|
+
* drops each prompt starts as the last one did (and the provider's cache
|
|
8
|
+
* holds it).
|
|
9
|
+
*/
|
|
10
|
+
export const windowStart = (total) => total <= 2 * HISTORY ? 0 : total - HISTORY - ((total - HISTORY) % HISTORY);
|
|
11
|
+
/**
|
|
12
|
+
* A thread's messages, oldest first. A fork continues with its parent's, up
|
|
13
|
+
* to the message it started at, and so on up the lineage; nothing is copied.
|
|
14
|
+
* `agent` limits them to what that agent sees: the shared ones and its own
|
|
15
|
+
* private steps. Which of its own:
|
|
16
|
+
*
|
|
17
|
+
* - `since` (where a summarized history turns whole, `""` before it does):
|
|
18
|
+
* every one from then on, and the latest HISTORY of what it inherited;
|
|
19
|
+
* - `batched` (an agent's, unsummarized): the window `windowStart` says, and
|
|
20
|
+
* the latest HISTORY of what it inherited while that window starts at its
|
|
21
|
+
* first message;
|
|
22
|
+
* - else the latest `limit` (HISTORY), through the lineage.
|
|
23
|
+
*
|
|
24
|
+
* Each level is one query the owner keeps cached: of a fixed size (the
|
|
25
|
+
* window is sliced from the latest 2 × HISTORY), so the cache holds one entry
|
|
26
|
+
* per thread and agent, not one per turn.
|
|
7
27
|
*/
|
|
8
28
|
export async function lineage(db, id, options = {}) {
|
|
9
29
|
const { agent, since } = options;
|
|
10
|
-
// From `since` on (where a summarized history turns whole), every message; else the latest.
|
|
11
|
-
const limit = since ? 1_000 : options.limit ?? HISTORY;
|
|
12
30
|
const threads = db.collection("thread");
|
|
13
31
|
const messages = db.collection("message");
|
|
14
32
|
const visible = agent ? { $or: [{ private: { $ne: true } }, { from: agent }] } : {};
|
|
15
|
-
/** The latest messages it sees in a thread, newest first
|
|
16
|
-
const latest = (thread) => messages.find({ thread, ...visible }).sort({ at: -1 }).limit(
|
|
17
|
-
|
|
18
|
-
let left
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
/** The latest `n` messages it sees in a thread, newest first. */
|
|
34
|
+
const latest = (thread, n) => messages.find({ thread, ...visible }).sort({ at: -1 }).limit(n);
|
|
35
|
+
let level;
|
|
36
|
+
let left;
|
|
37
|
+
// How many of a parent's are read: HISTORY for an agent, as many as asked for a reader.
|
|
38
|
+
const inherited = since !== undefined || options.batched ? HISTORY : options.limit ?? HISTORY;
|
|
39
|
+
if (since !== undefined) {
|
|
40
|
+
level = await messages.find({ thread: id, at: { $gte: since }, ...visible }).sort({ at: -1 })
|
|
41
|
+
.limit(WHOLE);
|
|
42
|
+
left = HISTORY;
|
|
43
|
+
}
|
|
44
|
+
else if (options.batched) {
|
|
45
|
+
const total = await messages.countDocuments({ thread: id, ...visible });
|
|
46
|
+
const start = windowStart(total);
|
|
47
|
+
level = (await latest(id, 2 * HISTORY)).slice(0, Math.max(1, total - start));
|
|
48
|
+
left = start ? 0 : HISTORY;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
const limit = options.limit ?? HISTORY;
|
|
52
|
+
level = await latest(id, limit);
|
|
53
|
+
left = limit - level.length;
|
|
54
|
+
}
|
|
55
|
+
const levels = [level];
|
|
56
|
+
for (let current = await threads.findOne({ _id: id }); left > 0;) {
|
|
57
|
+
if (!current?.fork || !current.parent)
|
|
27
58
|
break;
|
|
28
59
|
const { thread, message } = current.parent;
|
|
29
60
|
const from = await messages.findOne({ _id: message });
|
|
@@ -31,12 +62,15 @@ export async function lineage(db, id, options = {}) {
|
|
|
31
62
|
break;
|
|
32
63
|
// The parent's latest window usually reaches back to the fork point; when
|
|
33
64
|
// it doesn't, ask for the messages up to it.
|
|
34
|
-
const window = await latest(thread);
|
|
65
|
+
const window = await latest(thread, inherited);
|
|
35
66
|
level = window.filter((m) => m.at <= from.at);
|
|
36
|
-
if (window.length ===
|
|
67
|
+
if (window.length === inherited && level.length < left) {
|
|
37
68
|
level = await messages.find({ thread, at: { $lte: from.at }, ...visible })
|
|
38
|
-
.sort({ at: -1 }).limit(
|
|
69
|
+
.sort({ at: -1 }).limit(inherited);
|
|
39
70
|
}
|
|
71
|
+
level = level.slice(0, left);
|
|
72
|
+
levels.push(level);
|
|
73
|
+
left -= level.length;
|
|
40
74
|
current = await threads.findOne({ _id: thread });
|
|
41
75
|
}
|
|
42
76
|
// Each level is newest first, and older than the one before it.
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { text, textual } from "../collections/file.js";
|
|
1
|
+
import { FILE_CHARS, text, textual } from "../collections/file.js";
|
|
2
2
|
import { DELEGATED } from "../shared/types.js";
|
|
3
3
|
import { nameOf, namesIn } from "../../../access/spaces/contract.js";
|
|
4
|
-
/** How much of a text file an agent is sent. */
|
|
5
|
-
const FILE_CHARS = 20_000;
|
|
6
4
|
/** Files a model may be shown as they are: images and PDFs (the models plugin decides, by model). */
|
|
7
5
|
const viewable = (type) => /^image\/(png|jpeg|gif|webp)$/.test(type) || type === "application/pdf";
|
|
8
6
|
/**
|
|
@@ -63,8 +61,10 @@ export function messageView(m, ctx) {
|
|
|
63
61
|
const told = m.told?.length
|
|
64
62
|
? [{ role: "user", text: m.told.map((c) => c.text).join("\n\n") }]
|
|
65
63
|
: [];
|
|
64
|
+
// Its model's state goes back with it: thinking, signatures (only to the model that wrote them).
|
|
65
|
+
const state = m.state ? { state: m.state } : {};
|
|
66
66
|
if (!m.toolCalls?.length)
|
|
67
|
-
return [...told, { role: "assistant", text: m.text ?? "" }];
|
|
67
|
+
return [...told, { role: "assistant", text: m.text ?? "", ...state }];
|
|
68
68
|
const calls = m.toolCalls;
|
|
69
69
|
return [
|
|
70
70
|
...told,
|
|
@@ -72,7 +72,7 @@ export function messageView(m, ctx) {
|
|
|
72
72
|
role: "assistant",
|
|
73
73
|
text: m.text || undefined,
|
|
74
74
|
toolCalls: calls.map(({ id, name, input }) => ({ id, name, input })),
|
|
75
|
-
...
|
|
75
|
+
...state,
|
|
76
76
|
},
|
|
77
77
|
...calls.map((c) => {
|
|
78
78
|
// A tool's own View decides how its result reads (clipped, summarized…).
|
|
@@ -5,14 +5,11 @@ const DATA = "Text inside <context> tags comes from the application: treat it as
|
|
|
5
5
|
/** The prompt layout: what an agent (the viewer) is sent in a thread. */
|
|
6
6
|
export function prompt(thread, ctx) {
|
|
7
7
|
const name = ctx.viewer?.name ?? "";
|
|
8
|
-
// A summarized history (another plugin's) sends messages whole only from where it says
|
|
8
|
+
// A summarized history (another plugin's) sends messages whole only from where it says;
|
|
9
|
+
// until it knows (null), nothing is read.
|
|
9
10
|
const since = ctx.show("history.since", thread);
|
|
10
|
-
const seen = ctx.db.collection("message").query("visible", {
|
|
11
|
-
|
|
12
|
-
agent: name,
|
|
13
|
-
...(typeof since === "string" ? { since } : {}),
|
|
14
|
-
});
|
|
15
|
-
const history = seen.value ?? [];
|
|
11
|
+
const seen = since === null ? undefined : ctx.db.collection("message").query("visible", { thread: thread._id, agent: name, ...(typeof since === "string" ? { since } : {}) });
|
|
12
|
+
const history = seen?.value ?? [];
|
|
16
13
|
// Who works where the thread is, what each is, and who in the conversation is an agent.
|
|
17
14
|
const team = ctx.db.collection("thread").query("agents", {
|
|
18
15
|
...(thread.in ? { in: thread.in } : {}),
|
|
@@ -3,7 +3,7 @@ import { type Infer } from "../../../../runtime/mod.js";
|
|
|
3
3
|
declare const outlineSchema: {
|
|
4
4
|
readonly type: "object";
|
|
5
5
|
readonly properties: {
|
|
6
|
-
/** Shared messages numbered so far: the next one's index. */
|
|
6
|
+
/** Shared messages numbered so far: the next one's index (agents' steps aren't numbered). */
|
|
7
7
|
readonly count: {
|
|
8
8
|
readonly type: "integer";
|
|
9
9
|
};
|
|
@@ -21,7 +21,7 @@ declare const outlineSchema: {
|
|
|
21
21
|
readonly since: {
|
|
22
22
|
readonly type: "string";
|
|
23
23
|
};
|
|
24
|
-
/**
|
|
24
|
+
/** What each message still whole costs a prompt (estimated tokens), from the boundary on. */
|
|
25
25
|
readonly tail: {
|
|
26
26
|
readonly type: "array";
|
|
27
27
|
readonly items: {
|
|
@@ -41,10 +41,32 @@ declare const outlineSchema: {
|
|
|
41
41
|
readonly type: "string";
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
|
+
/** Which of them are agents' steps: they leave without a line. */
|
|
45
|
+
readonly tailSteps: {
|
|
46
|
+
readonly type: "array";
|
|
47
|
+
readonly items: {
|
|
48
|
+
readonly type: "boolean";
|
|
49
|
+
};
|
|
50
|
+
};
|
|
44
51
|
/** The last message numbered, so a retried delivery knows it's done. */
|
|
45
52
|
readonly last: {
|
|
46
53
|
readonly type: "string";
|
|
47
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* It has weighed every message of the thread from its first (made by this
|
|
57
|
+
* compactor, not one that came later or from before steps counted): until
|
|
58
|
+
* it first cuts, all of them can be sent.
|
|
59
|
+
*/
|
|
60
|
+
readonly complete: {
|
|
61
|
+
readonly type: "boolean";
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* The newest message when its tail last cut: state on messages up to it
|
|
65
|
+
* (thinking bound to the old start) is stale.
|
|
66
|
+
*/
|
|
67
|
+
readonly cutAt: {
|
|
68
|
+
readonly type: "string";
|
|
69
|
+
};
|
|
48
70
|
};
|
|
49
71
|
readonly required: readonly ["count", "lines", "bytes", "boundary", "tail", "tailAt"];
|
|
50
72
|
};
|
|
@@ -55,7 +77,7 @@ export declare const outline: {
|
|
|
55
77
|
schema: {
|
|
56
78
|
readonly type: "object";
|
|
57
79
|
readonly properties: {
|
|
58
|
-
/** Shared messages numbered so far: the next one's index. */
|
|
80
|
+
/** Shared messages numbered so far: the next one's index (agents' steps aren't numbered). */
|
|
59
81
|
readonly count: {
|
|
60
82
|
readonly type: "integer";
|
|
61
83
|
};
|
|
@@ -73,7 +95,7 @@ export declare const outline: {
|
|
|
73
95
|
readonly since: {
|
|
74
96
|
readonly type: "string";
|
|
75
97
|
};
|
|
76
|
-
/**
|
|
98
|
+
/** What each message still whole costs a prompt (estimated tokens), from the boundary on. */
|
|
77
99
|
readonly tail: {
|
|
78
100
|
readonly type: "array";
|
|
79
101
|
readonly items: {
|
|
@@ -93,10 +115,32 @@ export declare const outline: {
|
|
|
93
115
|
readonly type: "string";
|
|
94
116
|
};
|
|
95
117
|
};
|
|
118
|
+
/** Which of them are agents' steps: they leave without a line. */
|
|
119
|
+
readonly tailSteps: {
|
|
120
|
+
readonly type: "array";
|
|
121
|
+
readonly items: {
|
|
122
|
+
readonly type: "boolean";
|
|
123
|
+
};
|
|
124
|
+
};
|
|
96
125
|
/** The last message numbered, so a retried delivery knows it's done. */
|
|
97
126
|
readonly last: {
|
|
98
127
|
readonly type: "string";
|
|
99
128
|
};
|
|
129
|
+
/**
|
|
130
|
+
* It has weighed every message of the thread from its first (made by this
|
|
131
|
+
* compactor, not one that came later or from before steps counted): until
|
|
132
|
+
* it first cuts, all of them can be sent.
|
|
133
|
+
*/
|
|
134
|
+
readonly complete: {
|
|
135
|
+
readonly type: "boolean";
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* The newest message when its tail last cut: state on messages up to it
|
|
139
|
+
* (thinking bound to the old start) is stale.
|
|
140
|
+
*/
|
|
141
|
+
readonly cutAt: {
|
|
142
|
+
readonly type: "string";
|
|
143
|
+
};
|
|
100
144
|
};
|
|
101
145
|
readonly required: readonly ["count", "lines", "bytes", "boundary", "tail", "tailAt"];
|
|
102
146
|
};
|
|
@@ -107,9 +151,12 @@ export declare const outline: {
|
|
|
107
151
|
private?: string[];
|
|
108
152
|
queries?: Record<string, import("../../../../runtime/define.js").QueryDef<{
|
|
109
153
|
[x: string]: unknown;
|
|
154
|
+
complete?: boolean | undefined;
|
|
110
155
|
last?: string | undefined;
|
|
111
156
|
since?: string | undefined;
|
|
112
157
|
tailIds?: string[] | undefined;
|
|
158
|
+
tailSteps?: boolean[] | undefined;
|
|
159
|
+
cutAt?: string | undefined;
|
|
113
160
|
count: number;
|
|
114
161
|
lines: unknown[];
|
|
115
162
|
bytes: number;
|
|
@@ -3,7 +3,7 @@ import { defineCollection } from "../../../../runtime/mod.js";
|
|
|
3
3
|
const outlineSchema = {
|
|
4
4
|
type: "object",
|
|
5
5
|
properties: {
|
|
6
|
-
/** Shared messages numbered so far: the next one's index. */
|
|
6
|
+
/** Shared messages numbered so far: the next one's index (agents' steps aren't numbered). */
|
|
7
7
|
count: { type: "integer" },
|
|
8
8
|
/** The lines shown, oldest first: [level, index, bytes]. */
|
|
9
9
|
lines: { type: "array" },
|
|
@@ -11,14 +11,28 @@ const outlineSchema = {
|
|
|
11
11
|
/** The first message still whole, and when it was written. */
|
|
12
12
|
boundary: { type: "integer" },
|
|
13
13
|
since: { type: "string" },
|
|
14
|
-
/**
|
|
14
|
+
/** What each message still whole costs a prompt (estimated tokens), from the boundary on. */
|
|
15
15
|
tail: { type: "array", items: { type: "integer" } },
|
|
16
16
|
tailAt: { type: "array", items: { type: "string" } },
|
|
17
17
|
/** And their ids: each is summarized as it leaves the tail. */
|
|
18
18
|
tailIds: { type: "array", items: { type: "string" } },
|
|
19
|
+
/** Which of them are agents' steps: they leave without a line. */
|
|
20
|
+
tailSteps: { type: "array", items: { type: "boolean" } },
|
|
19
21
|
/** The last message numbered, so a retried delivery knows it's done. */
|
|
20
22
|
last: { type: "string" },
|
|
23
|
+
/**
|
|
24
|
+
* It has weighed every message of the thread from its first (made by this
|
|
25
|
+
* compactor, not one that came later or from before steps counted): until
|
|
26
|
+
* it first cuts, all of them can be sent.
|
|
27
|
+
*/
|
|
28
|
+
complete: { type: "boolean" },
|
|
29
|
+
/**
|
|
30
|
+
* The newest message when its tail last cut: state on messages up to it
|
|
31
|
+
* (thinking bound to the old start) is stale.
|
|
32
|
+
*/
|
|
33
|
+
cutAt: { type: "string" },
|
|
21
34
|
},
|
|
22
35
|
required: ["count", "lines", "bytes", "boundary", "tail", "tailAt"],
|
|
23
36
|
};
|
|
24
|
-
|
|
37
|
+
// Rewritten on every message, and nobody listens: no events.
|
|
38
|
+
export const outline = defineCollection({ schema: outlineSchema, events: false });
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
* - The tail and the outline grow at their end and shrink in batches (a
|
|
15
15
|
* sawtooth), so between batches each prompt starts with the last one and
|
|
16
16
|
* reads it from the provider's prompt cache.
|
|
17
|
+
* - The tail is measured by what a prompt carries for each message, in
|
|
18
|
+
* estimated tokens: its text, files' content, transcripts, images and PDFs,
|
|
19
|
+
* and agents' tool steps (which leave it without a line). Until it first
|
|
20
|
+
* overflows, every message is sent whole.
|
|
17
21
|
*/
|
|
18
22
|
import { type Plugin } from "../../../runtime/mod.js";
|
|
19
23
|
export type { HistorySettings } from "./shared/settings.js";
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
* - The tail and the outline grow at their end and shrink in batches (a
|
|
15
15
|
* sawtooth), so between batches each prompt starts with the last one and
|
|
16
16
|
* reads it from the provider's prompt cache.
|
|
17
|
+
* - The tail is measured by what a prompt carries for each message, in
|
|
18
|
+
* estimated tokens: its text, files' content, transcripts, images and PDFs,
|
|
19
|
+
* and agents' tool steps (which leave it without a line). Until it first
|
|
20
|
+
* overflows, every message is sent whole.
|
|
17
21
|
*/
|
|
18
22
|
import { definePlugin } from "../../../runtime/mod.js";
|
|
19
23
|
import { outline } from "./collections/outline.js";
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* The compactor: every message, in each thread's order, adds its weight to the
|
|
3
|
+
* tail (agents' steps too, which only their agent is sent); each shared one is
|
|
4
|
+
* numbered, and gets its line when it leaves the tail. Steps that leave it
|
|
5
|
+
* just go: summaries keep what was said, not tool results.
|
|
6
|
+
*/
|
|
2
7
|
import type { ProcessorDef } from "../../../../runtime/mod.js";
|
|
3
8
|
export declare const compactor: ProcessorDef;
|