@goondan/openharness-base 0.0.1-alpha3 → 0.0.1-alpha5

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.
Files changed (105) hide show
  1. package/dist/index.d.ts +72 -5
  2. package/dist/index.js +506 -5
  3. package/package.json +11 -33
  4. package/src/__tests__/compaction-summarize.test.ts +234 -0
  5. package/src/__tests__/context-message.test.ts +203 -0
  6. package/src/__tests__/logging.test.ts +200 -0
  7. package/src/__tests__/message-window.test.ts +193 -0
  8. package/src/__tests__/required-tools-guard.test.ts +206 -0
  9. package/src/__tests__/tool-search.test.ts +187 -0
  10. package/src/__tests__/tools.test.ts +332 -0
  11. package/src/extensions/compaction-summarize.ts +58 -0
  12. package/src/extensions/context-message.ts +37 -0
  13. package/src/extensions/logging.ts +42 -0
  14. package/src/extensions/message-window.ts +23 -0
  15. package/src/extensions/required-tools-guard.ts +24 -0
  16. package/src/extensions/tool-search.ts +38 -0
  17. package/src/index.ts +16 -0
  18. package/src/tools/bash.ts +38 -0
  19. package/src/tools/file-system.ts +83 -0
  20. package/src/tools/http-fetch.ts +64 -0
  21. package/src/tools/json-query.ts +71 -0
  22. package/src/tools/text-transform.ts +59 -0
  23. package/src/tools/wait.ts +46 -0
  24. package/tsconfig.json +8 -0
  25. package/vitest.config.ts +7 -0
  26. package/README.md +0 -11
  27. package/dist/extensions/compaction.d.ts +0 -12
  28. package/dist/extensions/compaction.d.ts.map +0 -1
  29. package/dist/extensions/compaction.js +0 -162
  30. package/dist/extensions/compaction.js.map +0 -1
  31. package/dist/extensions/context-message.d.ts +0 -9
  32. package/dist/extensions/context-message.d.ts.map +0 -1
  33. package/dist/extensions/context-message.js +0 -451
  34. package/dist/extensions/context-message.js.map +0 -1
  35. package/dist/extensions/index.d.ts +0 -13
  36. package/dist/extensions/index.d.ts.map +0 -1
  37. package/dist/extensions/index.js +0 -7
  38. package/dist/extensions/index.js.map +0 -1
  39. package/dist/extensions/logging.d.ts +0 -11
  40. package/dist/extensions/logging.d.ts.map +0 -1
  41. package/dist/extensions/logging.js +0 -140
  42. package/dist/extensions/logging.js.map +0 -1
  43. package/dist/extensions/message-integrity.d.ts +0 -8
  44. package/dist/extensions/message-integrity.d.ts.map +0 -1
  45. package/dist/extensions/message-integrity.js +0 -88
  46. package/dist/extensions/message-integrity.js.map +0 -1
  47. package/dist/extensions/message-window.d.ts +0 -7
  48. package/dist/extensions/message-window.d.ts.map +0 -1
  49. package/dist/extensions/message-window.js +0 -60
  50. package/dist/extensions/message-window.js.map +0 -1
  51. package/dist/extensions/required-tools-guard.d.ts +0 -9
  52. package/dist/extensions/required-tools-guard.d.ts.map +0 -1
  53. package/dist/extensions/required-tools-guard.js +0 -74
  54. package/dist/extensions/required-tools-guard.js.map +0 -1
  55. package/dist/extensions/tool-search.d.ts +0 -10
  56. package/dist/extensions/tool-search.d.ts.map +0 -1
  57. package/dist/extensions/tool-search.js +0 -198
  58. package/dist/extensions/tool-search.js.map +0 -1
  59. package/dist/harness.yaml +0 -503
  60. package/dist/index.d.ts.map +0 -1
  61. package/dist/index.js.map +0 -1
  62. package/dist/manifests/base.d.ts +0 -8
  63. package/dist/manifests/base.d.ts.map +0 -1
  64. package/dist/manifests/base.js +0 -352
  65. package/dist/manifests/base.js.map +0 -1
  66. package/dist/manifests/index.d.ts +0 -3
  67. package/dist/manifests/index.d.ts.map +0 -1
  68. package/dist/manifests/index.js +0 -2
  69. package/dist/manifests/index.js.map +0 -1
  70. package/dist/tools/bash.d.ts +0 -8
  71. package/dist/tools/bash.d.ts.map +0 -1
  72. package/dist/tools/bash.js +0 -119
  73. package/dist/tools/bash.js.map +0 -1
  74. package/dist/tools/file-system.d.ts +0 -12
  75. package/dist/tools/file-system.d.ts.map +0 -1
  76. package/dist/tools/file-system.js +0 -117
  77. package/dist/tools/file-system.js.map +0 -1
  78. package/dist/tools/http-fetch.d.ts +0 -8
  79. package/dist/tools/http-fetch.d.ts.map +0 -1
  80. package/dist/tools/http-fetch.js +0 -149
  81. package/dist/tools/http-fetch.js.map +0 -1
  82. package/dist/tools/index.d.ts +0 -7
  83. package/dist/tools/index.d.ts.map +0 -1
  84. package/dist/tools/index.js +0 -7
  85. package/dist/tools/index.js.map +0 -1
  86. package/dist/tools/json-query.d.ts +0 -12
  87. package/dist/tools/json-query.d.ts.map +0 -1
  88. package/dist/tools/json-query.js +0 -176
  89. package/dist/tools/json-query.js.map +0 -1
  90. package/dist/tools/text-transform.d.ts +0 -16
  91. package/dist/tools/text-transform.d.ts.map +0 -1
  92. package/dist/tools/text-transform.js +0 -127
  93. package/dist/tools/text-transform.js.map +0 -1
  94. package/dist/tools/wait.d.ts +0 -6
  95. package/dist/tools/wait.d.ts.map +0 -1
  96. package/dist/tools/wait.js +0 -32
  97. package/dist/tools/wait.js.map +0 -1
  98. package/dist/types.d.ts +0 -4
  99. package/dist/types.d.ts.map +0 -1
  100. package/dist/types.js +0 -6
  101. package/dist/types.js.map +0 -1
  102. package/dist/utils.d.ts +0 -17
  103. package/dist/utils.d.ts.map +0 -1
  104. package/dist/utils.js +0 -155
  105. package/dist/utils.js.map +0 -1
@@ -0,0 +1,83 @@
1
+ import { readFile, writeFile, readdir } from "node:fs/promises";
2
+ import type { ToolDefinition, JsonObject, ToolContext } from "@goondan/openharness-types";
3
+
4
+ export function FileReadTool(): ToolDefinition {
5
+ return {
6
+ name: "file_read",
7
+ description: "Read the contents of a file.",
8
+ parameters: {
9
+ type: "object",
10
+ properties: {
11
+ path: { type: "string", description: "Absolute or relative path to the file to read." },
12
+ encoding: {
13
+ type: "string",
14
+ enum: ["utf8", "base64"],
15
+ description: "File encoding. Defaults to utf8.",
16
+ },
17
+ },
18
+ required: ["path"],
19
+ },
20
+ async handler(args: JsonObject, _ctx: ToolContext) {
21
+ const filePath = args["path"] as string;
22
+ const encoding = (args["encoding"] as BufferEncoding | undefined) ?? "utf8";
23
+ try {
24
+ const content = await readFile(filePath, { encoding });
25
+ return { type: "text", text: content };
26
+ } catch (err) {
27
+ return { type: "error", error: (err as Error).message };
28
+ }
29
+ },
30
+ };
31
+ }
32
+
33
+ export function FileWriteTool(): ToolDefinition {
34
+ return {
35
+ name: "file_write",
36
+ description: "Write content to a file, creating or overwriting it.",
37
+ parameters: {
38
+ type: "object",
39
+ properties: {
40
+ path: { type: "string", description: "Absolute or relative path to the file to write." },
41
+ content: { type: "string", description: "The content to write to the file." },
42
+ },
43
+ required: ["path", "content"],
44
+ },
45
+ async handler(args: JsonObject, _ctx: ToolContext) {
46
+ const filePath = args["path"] as string;
47
+ const content = args["content"] as string;
48
+ try {
49
+ await writeFile(filePath, content, "utf8");
50
+ return { type: "text", text: `File written: ${filePath}` };
51
+ } catch (err) {
52
+ return { type: "error", error: (err as Error).message };
53
+ }
54
+ },
55
+ };
56
+ }
57
+
58
+ export function FileListTool(): ToolDefinition {
59
+ return {
60
+ name: "file_list",
61
+ description: "List files and directories in a given directory.",
62
+ parameters: {
63
+ type: "object",
64
+ properties: {
65
+ path: { type: "string", description: "Absolute or relative path to the directory to list." },
66
+ },
67
+ required: ["path"],
68
+ },
69
+ async handler(args: JsonObject, _ctx: ToolContext) {
70
+ const dirPath = args["path"] as string;
71
+ try {
72
+ const entries = await readdir(dirPath, { withFileTypes: true });
73
+ const result = entries.map((e) => ({
74
+ name: e.name,
75
+ type: e.isDirectory() ? "directory" : "file",
76
+ }));
77
+ return { type: "json", data: result };
78
+ } catch (err) {
79
+ return { type: "error", error: (err as Error).message };
80
+ }
81
+ },
82
+ };
83
+ }
@@ -0,0 +1,64 @@
1
+ import type { ToolDefinition, JsonObject, ToolContext, JsonValue } from "@goondan/openharness-types";
2
+
3
+ export function HttpFetchTool(): ToolDefinition {
4
+ return {
5
+ name: "http_fetch",
6
+ description: "Perform an HTTP request and return the response.",
7
+ parameters: {
8
+ type: "object",
9
+ properties: {
10
+ url: { type: "string", description: "The URL to fetch." },
11
+ method: {
12
+ type: "string",
13
+ enum: ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"],
14
+ description: "HTTP method. Defaults to GET.",
15
+ },
16
+ headers: {
17
+ type: "object",
18
+ additionalProperties: { type: "string" },
19
+ description: "Optional request headers.",
20
+ },
21
+ body: { type: "string", description: "Optional request body." },
22
+ },
23
+ required: ["url"],
24
+ },
25
+ async handler(args: JsonObject, _ctx: ToolContext) {
26
+ const url = args["url"] as string;
27
+ const method = (args["method"] as string | undefined) ?? "GET";
28
+ const headers = (args["headers"] as Record<string, string> | undefined) ?? {};
29
+ const body = args["body"] as string | undefined;
30
+
31
+ try {
32
+ const response = await fetch(url, {
33
+ method,
34
+ headers,
35
+ body: body !== undefined ? body : undefined,
36
+ });
37
+
38
+ const responseHeaders: Record<string, string> = {};
39
+ response.headers.forEach((value, key) => {
40
+ responseHeaders[key] = value;
41
+ });
42
+
43
+ let responseBody: unknown;
44
+ const contentType = response.headers.get("content-type") ?? "";
45
+ if (contentType.includes("application/json")) {
46
+ responseBody = await response.json();
47
+ } else {
48
+ responseBody = await response.text();
49
+ }
50
+
51
+ return {
52
+ type: "json",
53
+ data: {
54
+ status: response.status,
55
+ headers: responseHeaders,
56
+ body: responseBody as JsonValue,
57
+ },
58
+ };
59
+ } catch (err) {
60
+ return { type: "error", error: (err as Error).message };
61
+ }
62
+ },
63
+ };
64
+ }
@@ -0,0 +1,71 @@
1
+ import type { ToolDefinition, JsonObject, ToolContext, JsonValue } from "@goondan/openharness-types";
2
+
3
+ /**
4
+ * Simple JSONPath-like query supporting dot and bracket notation.
5
+ * Supported path format: $.key.nested[0].field
6
+ * The leading `$` is optional.
7
+ */
8
+ function jsonQuery(data: unknown, path: string): unknown {
9
+ // Normalize: strip leading `$` or `$.`
10
+ let normalized = path.trim();
11
+ if (normalized.startsWith("$.")) {
12
+ normalized = normalized.slice(2);
13
+ } else if (normalized === "$") {
14
+ return data;
15
+ } else if (normalized.startsWith("$")) {
16
+ normalized = normalized.slice(1);
17
+ }
18
+
19
+ if (normalized === "" || normalized === ".") {
20
+ return data;
21
+ }
22
+
23
+ // Tokenize path into segments
24
+ const segments: Array<string | number> = [];
25
+ // Replace bracket notation [0] with .0
26
+ const normalized2 = normalized.replace(/\[(\d+)\]/g, ".$1").replace(/\[['"](.+?)['"]\]/g, ".$1");
27
+ for (const part of normalized2.split(".")) {
28
+ if (part === "") continue;
29
+ const num = Number(part);
30
+ segments.push(Number.isInteger(num) && String(num) === part ? num : part);
31
+ }
32
+
33
+ let current: unknown = data;
34
+ for (const segment of segments) {
35
+ if (current === null || current === undefined) return undefined;
36
+ if (typeof current === "object") {
37
+ current = (current as Record<string | number, unknown>)[segment];
38
+ } else {
39
+ return undefined;
40
+ }
41
+ }
42
+ return current;
43
+ }
44
+
45
+ export function JsonQueryTool(): ToolDefinition {
46
+ return {
47
+ name: "json_query",
48
+ description: "Query JSON data using a simple JSONPath-like path expression.",
49
+ parameters: {
50
+ type: "object",
51
+ properties: {
52
+ data: { description: "The JSON data to query." },
53
+ path: {
54
+ type: "string",
55
+ description: "JSONPath-like path, e.g. $.key.nested[0].field",
56
+ },
57
+ },
58
+ required: ["data", "path"],
59
+ },
60
+ async handler(args: JsonObject, _ctx: ToolContext) {
61
+ const data = args["data"];
62
+ const path = args["path"] as string;
63
+ try {
64
+ const result = jsonQuery(data, path);
65
+ return { type: "json", data: result as JsonValue };
66
+ } catch (err) {
67
+ return { type: "error", error: (err as Error).message };
68
+ }
69
+ },
70
+ };
71
+ }
@@ -0,0 +1,59 @@
1
+ import type { ToolDefinition, JsonObject, ToolContext } from "@goondan/openharness-types";
2
+
3
+ type Operation = "uppercase" | "lowercase" | "trim" | "split" | "replace";
4
+
5
+ export function TextTransformTool(): ToolDefinition {
6
+ return {
7
+ name: "text_transform",
8
+ description: "Apply a transformation operation to a text string.",
9
+ parameters: {
10
+ type: "object",
11
+ properties: {
12
+ text: { type: "string", description: "The input text to transform." },
13
+ operation: {
14
+ type: "string",
15
+ enum: ["uppercase", "lowercase", "trim", "split", "replace"],
16
+ description: "The transformation to apply.",
17
+ },
18
+ options: {
19
+ type: "object",
20
+ properties: {
21
+ delimiter: { type: "string", description: "Delimiter for split operation." },
22
+ find: { type: "string", description: "String to find for replace operation." },
23
+ replacement: { type: "string", description: "Replacement string for replace operation." },
24
+ },
25
+ },
26
+ },
27
+ required: ["text", "operation"],
28
+ },
29
+ async handler(args: JsonObject, _ctx: ToolContext) {
30
+ const text = args["text"] as string;
31
+ const operation = args["operation"] as Operation;
32
+ const options = (args["options"] as Record<string, string> | undefined) ?? {};
33
+
34
+ try {
35
+ switch (operation) {
36
+ case "uppercase":
37
+ return { type: "text", text: text.toUpperCase() };
38
+ case "lowercase":
39
+ return { type: "text", text: text.toLowerCase() };
40
+ case "trim":
41
+ return { type: "text", text: text.trim() };
42
+ case "split": {
43
+ const delimiter = options["delimiter"] ?? " ";
44
+ return { type: "json", data: text.split(delimiter) };
45
+ }
46
+ case "replace": {
47
+ const find = options["find"] ?? "";
48
+ const replacement = options["replacement"] ?? "";
49
+ return { type: "text", text: text.split(find).join(replacement) };
50
+ }
51
+ default:
52
+ return { type: "error", error: `Unknown operation: ${operation}` };
53
+ }
54
+ } catch (err) {
55
+ return { type: "error", error: (err as Error).message };
56
+ }
57
+ },
58
+ };
59
+ }
@@ -0,0 +1,46 @@
1
+ import type { ToolDefinition, JsonObject, ToolContext } from "@goondan/openharness-types";
2
+
3
+ export interface WaitToolConfig {
4
+ maxMs?: number;
5
+ }
6
+
7
+ export function WaitTool(config: WaitToolConfig = {}): ToolDefinition {
8
+ const { maxMs = 60_000 } = config;
9
+
10
+ return {
11
+ name: "wait",
12
+ description: "Wait for a specified number of milliseconds before continuing.",
13
+ parameters: {
14
+ type: "object",
15
+ properties: {
16
+ ms: {
17
+ type: "number",
18
+ description: "Number of milliseconds to wait.",
19
+ minimum: 0,
20
+ },
21
+ },
22
+ required: ["ms"],
23
+ },
24
+ async handler(args: JsonObject, ctx: ToolContext) {
25
+ const requestedMs = args["ms"] as number;
26
+ const ms = Math.min(requestedMs, maxMs);
27
+
28
+ await new Promise<void>((resolve, reject) => {
29
+ const timer = setTimeout(resolve, ms);
30
+
31
+ if (ctx.abortSignal.aborted) {
32
+ clearTimeout(timer);
33
+ reject(new Error("Aborted"));
34
+ return;
35
+ }
36
+
37
+ ctx.abortSignal.addEventListener("abort", () => {
38
+ clearTimeout(timer);
39
+ reject(new Error("Aborted"));
40
+ });
41
+ });
42
+
43
+ return { type: "text", text: `Waited ${ms}ms` };
44
+ },
45
+ };
46
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "rootDir": "src"
6
+ },
7
+ "include": ["src"]
8
+ }
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ include: ["src/**/*.test.ts"],
6
+ },
7
+ });
package/README.md DELETED
@@ -1,11 +0,0 @@
1
- # @goondan/openharness-base
2
-
3
- OpenHarness에 바로 붙일 수 있는 reference tool, extension, manifest 번들을 제공합니다.
4
-
5
- ## Install
6
-
7
- ```bash
8
- npm install @goondan/openharness-base
9
- ```
10
-
11
- manifest 산출물과 기본 확장 정책은 [`packages/base/AGENTS.md`](./AGENTS.md)를 참고하세요.
@@ -1,12 +0,0 @@
1
- import type { ExtensionApi } from '../types.js';
2
- export interface CompactionExtensionConfig {
3
- maxMessages?: number;
4
- maxCharacters?: number;
5
- retainLastMessages?: number;
6
- mode?: 'remove' | 'truncate';
7
- appendSummary?: boolean;
8
- summaryPrefix?: string;
9
- }
10
- export declare function registerCompactionExtension(api: ExtensionApi, config?: CompactionExtensionConfig): void;
11
- export declare function register(api: ExtensionApi, config?: CompactionExtensionConfig): void;
12
- //# sourceMappingURL=compaction.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compaction.d.ts","sourceRoot":"","sources":["../../src/extensions/compaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EAIb,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,yBAAyB;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;IAC7B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAwKD,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,YAAY,EACjB,MAAM,CAAC,EAAE,yBAAyB,GACjC,IAAI,CA6BN;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,yBAAyB,GAAG,IAAI,CAEpF"}
@@ -1,162 +0,0 @@
1
- import { createId, estimateMessageLength } from '../utils.js';
2
- import { normalizeRemovalTargets } from './message-integrity.js';
3
- const DEFAULT_CONFIG = {
4
- maxMessages: 40,
5
- maxCharacters: 12_000,
6
- retainLastMessages: 8,
7
- mode: 'remove',
8
- appendSummary: true,
9
- summaryPrefix: '[message-compaction]',
10
- };
11
- function isPinned(message) {
12
- return message.metadata.pinned === true;
13
- }
14
- function createSummaryMessage(config, result) {
15
- const summaryText = `${config.summaryPrefix} mode=${result.mode} removed=${result.removedCount} chars=${result.removedCharacters}`;
16
- return {
17
- id: createId('msg'),
18
- data: {
19
- role: 'user',
20
- content: summaryText,
21
- },
22
- metadata: {
23
- 'compaction.summary': true,
24
- 'compaction.mode': result.mode,
25
- 'compaction.removedCount': result.removedCount,
26
- 'compaction.removedCharacters': result.removedCharacters,
27
- },
28
- createdAt: new Date(),
29
- source: {
30
- type: 'extension',
31
- extensionName: 'message-compaction',
32
- },
33
- };
34
- }
35
- function emitEvents(ctx, events) {
36
- for (const event of events) {
37
- ctx.emitMessageEvent(event);
38
- }
39
- }
40
- function compactByRemoval(messages, config) {
41
- const candidateRemovedIds = new Set();
42
- const protectedIds = new Set();
43
- const keepFrom = Math.max(0, messages.length - config.retainLastMessages);
44
- for (let index = keepFrom; index < messages.length; index += 1) {
45
- const protectedMessage = messages[index];
46
- if (!protectedMessage) {
47
- continue;
48
- }
49
- protectedIds.add(protectedMessage.id);
50
- }
51
- let remainingCount = messages.length;
52
- let remainingCharacters = messages.reduce((sum, message) => sum + estimateMessageLength(message), 0);
53
- for (const message of messages) {
54
- const overMessageLimit = remainingCount > config.maxMessages;
55
- const overCharacterLimit = remainingCharacters > config.maxCharacters;
56
- if (!overMessageLimit && !overCharacterLimit) {
57
- break;
58
- }
59
- if (protectedIds.has(message.id) || isPinned(message)) {
60
- continue;
61
- }
62
- const messageSize = estimateMessageLength(message);
63
- remainingCount -= 1;
64
- remainingCharacters -= messageSize;
65
- candidateRemovedIds.add(message.id);
66
- }
67
- const finalRemovedIds = normalizeRemovalTargets(messages, candidateRemovedIds);
68
- const events = [];
69
- let finalRemainingCount = 0;
70
- let finalRemainingCharacters = 0;
71
- let finalRemovedCount = 0;
72
- let finalRemovedCharacters = 0;
73
- for (const message of messages) {
74
- const messageSize = estimateMessageLength(message);
75
- if (finalRemovedIds.has(message.id)) {
76
- finalRemovedCount += 1;
77
- finalRemovedCharacters += messageSize;
78
- events.push({
79
- type: 'remove',
80
- targetId: message.id,
81
- });
82
- continue;
83
- }
84
- finalRemainingCount += 1;
85
- finalRemainingCharacters += messageSize;
86
- }
87
- const overflow = finalRemainingCount > config.maxMessages || finalRemainingCharacters > config.maxCharacters;
88
- return {
89
- events,
90
- result: {
91
- mode: 'remove',
92
- removedCount: finalRemovedCount,
93
- removedCharacters: finalRemovedCharacters,
94
- },
95
- overflow,
96
- };
97
- }
98
- function compactByTruncate() {
99
- return {
100
- events: [{ type: 'truncate' }],
101
- result: {
102
- mode: 'truncate',
103
- removedCount: 0,
104
- removedCharacters: 0,
105
- },
106
- };
107
- }
108
- function shouldCompact(messages, config) {
109
- if (messages.length > config.maxMessages) {
110
- return true;
111
- }
112
- const totalCharacters = messages.reduce((sum, message) => sum + estimateMessageLength(message), 0);
113
- return totalCharacters > config.maxCharacters;
114
- }
115
- function mergeConfig(config) {
116
- return {
117
- maxMessages: config?.maxMessages ?? DEFAULT_CONFIG.maxMessages,
118
- maxCharacters: config?.maxCharacters ?? DEFAULT_CONFIG.maxCharacters,
119
- retainLastMessages: config?.retainLastMessages ?? DEFAULT_CONFIG.retainLastMessages,
120
- mode: config?.mode ?? DEFAULT_CONFIG.mode,
121
- appendSummary: config?.appendSummary ?? DEFAULT_CONFIG.appendSummary,
122
- summaryPrefix: config?.summaryPrefix ?? DEFAULT_CONFIG.summaryPrefix,
123
- };
124
- }
125
- function maybeAppendSummary(events, config, result) {
126
- if (!config.appendSummary) {
127
- return;
128
- }
129
- events.push({
130
- type: 'append',
131
- message: createSummaryMessage(config, result),
132
- });
133
- }
134
- export function registerCompactionExtension(api, config) {
135
- const settings = mergeConfig(config);
136
- api.pipeline.register('turn', async (ctx) => {
137
- const messages = ctx.conversationState.nextMessages;
138
- if (!shouldCompact(messages, settings)) {
139
- return ctx.next();
140
- }
141
- if (settings.mode === 'truncate') {
142
- const { events, result } = compactByTruncate();
143
- maybeAppendSummary(events, settings, result);
144
- emitEvents(ctx, events);
145
- return ctx.next();
146
- }
147
- const removal = compactByRemoval(messages, settings);
148
- if (removal.overflow) {
149
- const truncate = compactByTruncate();
150
- maybeAppendSummary(truncate.events, settings, truncate.result);
151
- emitEvents(ctx, truncate.events);
152
- return ctx.next();
153
- }
154
- maybeAppendSummary(removal.events, settings, removal.result);
155
- emitEvents(ctx, removal.events);
156
- return ctx.next();
157
- });
158
- }
159
- export function register(api, config) {
160
- registerCompactionExtension(api, config);
161
- }
162
- //# sourceMappingURL=compaction.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compaction.js","sourceRoot":"","sources":["../../src/extensions/compaction.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,w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AgentPrompt?: boolean;
4
- includeInboundContext?: boolean;
5
- includeRouteSummary?: boolean;
6
- includeInboundInput?: boolean;
7
- }
8
- export declare function register(api: ExtensionApi, rawConfig?: unknown): void;
9
- //# sourceMappingURL=context-message.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-message.d.ts","sourceRoot":"","sources":["../../src/extensions/context-message.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAA6E,MAAM,aAAa,CAAC;AAmC3H,MAAM,WAAW,6BAA6B;IAC5C,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAgiBD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,YAAY,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAOrE"}