@xandreed/plugin-memory-digest 0.8.0-next.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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +11 -0
- package/dist/plugin.adapter.d.ts +34 -0
- package/dist/plugin.adapter.js +43 -0
- package/package.json +29 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Xand Reed
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { digestPrompt, keysOf, MemoryDigestConfig, memoryDigestDefaults, MemoryDigestLive, memoryDigestPlugin, outcomeOf, UTILITY_DIGESTER, default, } from "./plugin.adapter.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Layer, Schema } from "effect";
|
|
2
|
+
import { HarnessError, ResultDigester, UtilityLlm } from "@xandreed/core";
|
|
3
|
+
import type { DigestOutcome, DigestTask } from "@xandreed/core";
|
|
4
|
+
export declare const MemoryDigestConfig: Schema.Struct<{
|
|
5
|
+
/** The digester's source text is clipped to this many characters. */
|
|
6
|
+
readonly maxSourceChars: Schema.Int;
|
|
7
|
+
}>;
|
|
8
|
+
export type MemoryDigestConfig = typeof MemoryDigestConfig.Type;
|
|
9
|
+
export declare const memoryDigestDefaults: MemoryDigestConfig;
|
|
10
|
+
export declare const UTILITY_DIGESTER: {
|
|
11
|
+
readonly id: "utility-digest";
|
|
12
|
+
readonly version: "1";
|
|
13
|
+
};
|
|
14
|
+
/** The digest prompt: the tool's own instructions, the user message, then the result. */
|
|
15
|
+
export declare const digestPrompt: (task: DigestTask, maxSourceChars: number) => string;
|
|
16
|
+
/** Keys the reply names, in reply order, restricted to the task's items. */
|
|
17
|
+
export declare const keysOf: (task: DigestTask, reply: string) => ReadonlyArray<string>;
|
|
18
|
+
export declare const outcomeOf: (task: DigestTask, reply: string) => DigestOutcome;
|
|
19
|
+
/**
|
|
20
|
+
* Runs tools' digest prompts on the turn's UtilityLlm, so digests are
|
|
21
|
+
* budgeted with the turn. Session scope: it is built per turn from the
|
|
22
|
+
* turn's services. The memory strategy decides when to digest; the tool
|
|
23
|
+
* decides how; this plugin only asks.
|
|
24
|
+
*/
|
|
25
|
+
export declare const memoryDigestPlugin: import("@xandreed/core").TypedPlugin<{
|
|
26
|
+
readonly maxSourceChars: number;
|
|
27
|
+
}, {
|
|
28
|
+
readonly maxSourceChars: number;
|
|
29
|
+
}, ResultDigester, never, UtilityLlm>;
|
|
30
|
+
/** The digester as a typed layer, built per turn: provides ResultDigester; requires the turn's UtilityLlm. */
|
|
31
|
+
export declare const MemoryDigestLive: (options?: Partial<{
|
|
32
|
+
readonly maxSourceChars: number;
|
|
33
|
+
}> | undefined) => Layer.Layer<ResultDigester, HarnessError, UtilityLlm>;
|
|
34
|
+
export default memoryDigestPlugin;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Effect, Layer, Option, Schema } from "effect";
|
|
2
|
+
import { definePlugin, HarnessError, ResultDigester, UtilityLlm } from "@xandreed/core";
|
|
3
|
+
export const MemoryDigestConfig = Schema.Struct({
|
|
4
|
+
maxSourceChars: Schema.Int.pipe(Schema.check(Schema.isBetween({ minimum: 1000, maximum: 400000 })))
|
|
5
|
+
}), memoryDigestDefaults = { maxSourceChars: 48000 }, UTILITY_DIGESTER = { id: "utility-digest", version: "1" };
|
|
6
|
+
const clip = (text, max) => text.length <= max ? text : `${text.slice(0, max)}\u2026`;
|
|
7
|
+
export const digestPrompt = (task, maxSourceChars) => task.mode === "select" ? [
|
|
8
|
+
task.instructions,
|
|
9
|
+
`Request: ${task.userMessage.text}`,
|
|
10
|
+
"Items:",
|
|
11
|
+
...task.items.map((item) => `[${item.key}] ${clip(item.text, Math.max(200, Math.floor(maxSourceChars / Math.max(1, task.items.length))))}`),
|
|
12
|
+
"Reply with the keys of the items to keep, one per line, and nothing else."
|
|
13
|
+
].join(`
|
|
14
|
+
|
|
15
|
+
`) : [
|
|
16
|
+
task.instructions,
|
|
17
|
+
`Request: ${task.userMessage.text}`,
|
|
18
|
+
`Result:
|
|
19
|
+
${clip(task.source, maxSourceChars)}`,
|
|
20
|
+
"Reply with the summary only."
|
|
21
|
+
].join(`
|
|
22
|
+
|
|
23
|
+
`), keysOf = (task, reply) => {
|
|
24
|
+
const known = new Set(task.items.map((item) => item.key)), named = reply.split(`
|
|
25
|
+
`).map((line) => line.trim().replace(/^[-*\d.)\s]+/, "").replace(/^\[(.*)\]$/, "$1").trim());
|
|
26
|
+
return [...new Set(named.filter((key) => known.has(key)))];
|
|
27
|
+
}, outcomeOf = (task, reply) => task.mode === "select" ? { keep: keysOf(task, reply), summary: Option.none() } : { keep: [], summary: reply.trim().length === 0 ? Option.none() : Option.some(reply.trim()) }, memoryDigestPlugin = definePlugin({
|
|
28
|
+
id: "@xandreed/plugin-memory-digest",
|
|
29
|
+
version: "0.8.0-next.0",
|
|
30
|
+
scope: "session",
|
|
31
|
+
config: MemoryDigestConfig,
|
|
32
|
+
defaults: memoryDigestDefaults,
|
|
33
|
+
requires: [UtilityLlm],
|
|
34
|
+
provides: [ResultDigester],
|
|
35
|
+
layer: (config) => Layer.effect(ResultDigester, Effect.gen(function* () {
|
|
36
|
+
const utility = yield* UtilityLlm;
|
|
37
|
+
return ResultDigester.of({
|
|
38
|
+
...UTILITY_DIGESTER,
|
|
39
|
+
digest: (task) => utility.complete(digestPrompt(task, config.maxSourceChars)).pipe(Effect.map((completion) => outcomeOf(task, completion.text)), Effect.mapError((error) => new HarnessError({ code: "memory.digest", message: `${task.tool}: ${error.message}` })))
|
|
40
|
+
});
|
|
41
|
+
}))
|
|
42
|
+
}), MemoryDigestLive = memoryDigestPlugin.live;
|
|
43
|
+
export default memoryDigestPlugin;
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xandreed/plugin-memory-digest",
|
|
3
|
+
"version": "0.8.0-next.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"default": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@xandreed/core": "0.8.0-next.0",
|
|
14
|
+
"effect": "4.0.0-rc.118"
|
|
15
|
+
},
|
|
16
|
+
"private": false,
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"skills",
|
|
21
|
+
"profiles",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"bun": ">=1.3.0"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT"
|
|
29
|
+
}
|