@caupulican/pi-agent-core 0.81.41 → 0.81.43
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/dist/agent-loop.d.ts +23 -2
- package/dist/agent-loop.d.ts.map +1 -1
- package/dist/agent-loop.js +189 -42
- package/dist/agent-loop.js.map +1 -1
- package/dist/agent.d.ts +15 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +9 -38
- package/dist/agent.js.map +1 -1
- package/dist/compaction/branch-summarization.d.ts +1 -1
- package/dist/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/compaction/branch-summarization.js +3 -13
- package/dist/compaction/branch-summarization.js.map +1 -1
- package/dist/compaction/compaction.d.ts +6 -3
- package/dist/compaction/compaction.d.ts.map +1 -1
- package/dist/compaction/compaction.js +40 -68
- package/dist/compaction/compaction.js.map +1 -1
- package/dist/compaction/extraction.d.ts.map +1 -1
- package/dist/compaction/extraction.js +1 -6
- package/dist/compaction/extraction.js.map +1 -1
- package/dist/compaction/index.d.ts.map +1 -1
- package/dist/compaction/loop.d.ts.map +1 -1
- package/dist/compaction/loop.js.map +1 -1
- package/dist/compaction/token-budget.d.ts.map +1 -1
- package/dist/compaction/token-budget.js +7 -5
- package/dist/compaction/token-budget.js.map +1 -1
- package/dist/compaction/utils.d.ts +5 -0
- package/dist/compaction/utils.d.ts.map +1 -1
- package/dist/compaction/utils.js +20 -0
- package/dist/compaction/utils.js.map +1 -1
- package/dist/compaction/verification.d.ts.map +1 -1
- package/dist/compaction/verification.js +6 -5
- package/dist/compaction/verification.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js.map +1 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/proxy.d.ts +3 -2
- package/dist/proxy.d.ts.map +1 -1
- package/dist/proxy.js +88 -56
- package/dist/proxy.js.map +1 -1
- package/dist/reliability/classifier.d.ts.map +1 -1
- package/dist/reliability/classifier.js.map +1 -1
- package/dist/reliability/index.d.ts.map +1 -1
- package/dist/reliability/node.d.ts.map +1 -1
- package/dist/reliability/process-tree.d.ts.map +1 -1
- package/dist/reliability/process-tree.js.map +1 -1
- package/dist/reliability/provider-signatures.d.ts.map +1 -1
- package/dist/reliability/retry-controller.d.ts +1 -1
- package/dist/reliability/retry-controller.d.ts.map +1 -1
- package/dist/reliability/retry-controller.js +2 -7
- package/dist/reliability/retry-controller.js.map +1 -1
- package/dist/reliability/retry.d.ts.map +1 -1
- package/dist/reliability/retry.js.map +1 -1
- package/dist/reliability/watchdogs.d.ts.map +1 -1
- package/dist/reliability/watchdogs.js +24 -41
- package/dist/reliability/watchdogs.js.map +1 -1
- package/dist/session/message-retention.d.ts.map +1 -1
- package/dist/session/message-retention.js.map +1 -1
- package/dist/session/session-manager.d.ts +1 -1
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +12 -22
- package/dist/session/session-manager.js.map +1 -1
- package/dist/tool-failure-memory.d.ts +6 -0
- package/dist/tool-failure-memory.d.ts.map +1 -1
- package/dist/tool-failure-memory.js +78 -20
- package/dist/tool-failure-memory.js.map +1 -1
- package/dist/types.d.ts +73 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/usage.d.ts +3 -2
- package/dist/usage.d.ts.map +1 -1
- package/dist/usage.js +2 -10
- package/dist/usage.js.map +1 -1
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/shell-output.d.ts.map +1 -1
- package/dist/utils/shell-output.js.map +1 -1
- package/dist/utils/streaming-content.d.ts +23 -0
- package/dist/utils/streaming-content.d.ts.map +1 -0
- package/dist/utils/streaming-content.js +52 -0
- package/dist/utils/streaming-content.js.map +1 -0
- package/dist/utils/truncate.d.ts.map +1 -1
- package/dist/utils/truncate.js +55 -80
- package/dist/utils/truncate.js.map +1 -1
- package/dist/uuid.d.ts +1 -1
- package/dist/uuid.d.ts.map +1 -1
- package/dist/uuid.js +1 -1
- package/dist/uuid.js.map +1 -1
- package/package.json +6 -6
- package/dist/utils/streaming-lines.d.ts +0 -20
- package/dist/utils/streaming-lines.d.ts.map +0 -1
- package/dist/utils/streaming-lines.js +0 -79
- package/dist/utils/streaming-lines.js.map +0 -1
package/dist/uuid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uuid.js","sourceRoot":"","sources":["../src/uuid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"uuid.js","sourceRoot":"","sources":["../src/uuid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { uuidv7 } from \"@caupulican/pi-ai/uuid\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caupulican/pi-agent-core",
|
|
3
|
-
"version": "0.81.
|
|
3
|
+
"version": "0.81.43",
|
|
4
4
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
],
|
|
27
27
|
"scripts": {
|
|
28
28
|
"clean": "shx rm -rf dist",
|
|
29
|
-
"build": "node ../../scripts/
|
|
29
|
+
"build": "node ../../scripts/run-tsc.mjs -p tsconfig.build.json",
|
|
30
30
|
"test": "vitest --run",
|
|
31
31
|
"test:harness": "vitest --run --config vitest.harness.config.ts",
|
|
32
32
|
"coverage:harness": "vitest --run --config vitest.harness.config.ts --coverage",
|
|
33
33
|
"prepublishOnly": "npm run clean && npm run build"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@caupulican/pi-ai": "^0.81.
|
|
36
|
+
"@caupulican/pi-ai": "^0.81.43",
|
|
37
37
|
"ignore": "7.0.5",
|
|
38
38
|
"typebox": "1.1.38",
|
|
39
39
|
"yaml": "2.9.0"
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/node": "24.12.4",
|
|
60
|
-
"@vitest/coverage-v8": "3.2.
|
|
61
|
-
"typescript": "
|
|
62
|
-
"vitest": "3.2.
|
|
60
|
+
"@vitest/coverage-v8": "3.2.7",
|
|
61
|
+
"typescript": "7.0.2",
|
|
62
|
+
"vitest": "3.2.7"
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/** Incremental line decoder that joins a fragmented line only once, when it completes. */
|
|
2
|
-
export declare class StreamingLineDecoder {
|
|
3
|
-
private readonly maxLineChars;
|
|
4
|
-
private readonly overflow;
|
|
5
|
-
private readonly lineEndings;
|
|
6
|
-
private parts;
|
|
7
|
-
private length;
|
|
8
|
-
private skipLeadingLf;
|
|
9
|
-
private skippingOversizedLine;
|
|
10
|
-
constructor(maxLineChars: number, options?: {
|
|
11
|
-
overflow?: "throw" | "skip";
|
|
12
|
-
lineEndings?: "lf" | "any";
|
|
13
|
-
});
|
|
14
|
-
push(text: string): string[];
|
|
15
|
-
finish(): string | undefined;
|
|
16
|
-
private append;
|
|
17
|
-
private takeLine;
|
|
18
|
-
private resetLine;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=streaming-lines.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"streaming-lines.d.ts","sourceRoot":"","sources":["../../src/utils/streaming-lines.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,qBAAa,oBAAoB;IAChC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmB;IAC5C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;IAC3C,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,qBAAqB,CAAS;IAEtC,YAAY,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,IAAI,GAAG,KAAK,CAAA;KAAE,EAItG;IAED,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAqB3B;IAED,MAAM,IAAI,MAAM,GAAG,SAAS,CAQ3B;IAED,OAAO,CAAC,MAAM;IAed,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,SAAS;CAKjB","sourcesContent":["/** Incremental line decoder that joins a fragmented line only once, when it completes. */\nexport class StreamingLineDecoder {\n\tprivate readonly maxLineChars: number;\n\tprivate readonly overflow: \"throw\" | \"skip\";\n\tprivate readonly lineEndings: \"lf\" | \"any\";\n\tprivate parts: string[] = [];\n\tprivate length = 0;\n\tprivate skipLeadingLf = false;\n\tprivate skippingOversizedLine = false;\n\n\tconstructor(maxLineChars: number, options?: { overflow?: \"throw\" | \"skip\"; lineEndings?: \"lf\" | \"any\" }) {\n\t\tthis.maxLineChars = maxLineChars;\n\t\tthis.overflow = options?.overflow ?? \"throw\";\n\t\tthis.lineEndings = options?.lineEndings ?? \"any\";\n\t}\n\n\tpush(text: string): string[] {\n\t\tconst lines: string[] = [];\n\t\tlet start = 0;\n\t\tif (this.skipLeadingLf) {\n\t\t\tthis.skipLeadingLf = false;\n\t\t\tif (text.startsWith(\"\\n\")) start = 1;\n\t\t}\n\t\tfor (let index = start; index < text.length; index++) {\n\t\t\tconst char = text[index];\n\t\t\tif (char !== \"\\n\" && (this.lineEndings === \"lf\" || char !== \"\\r\")) continue;\n\t\t\tthis.append(text.slice(start, index));\n\t\t\tif (this.skippingOversizedLine) this.resetLine();\n\t\t\telse lines.push(this.takeLine());\n\t\t\tif (char === \"\\r\") {\n\t\t\t\tif (text[index + 1] === \"\\n\") index++;\n\t\t\t\telse if (index + 1 === text.length) this.skipLeadingLf = true;\n\t\t\t}\n\t\t\tstart = index + 1;\n\t\t}\n\t\tthis.append(text.slice(start));\n\t\treturn lines;\n\t}\n\n\tfinish(): string | undefined {\n\t\tthis.skipLeadingLf = false;\n\t\tif (this.skippingOversizedLine) {\n\t\t\tthis.resetLine();\n\t\t\treturn undefined;\n\t\t}\n\t\tif (this.length === 0 && this.parts.length === 0) return undefined;\n\t\treturn this.takeLine();\n\t}\n\n\tprivate append(part: string): void {\n\t\tif (part.length === 0 || this.skippingOversizedLine) return;\n\t\tthis.length += part.length;\n\t\tif (this.length > this.maxLineChars) {\n\t\t\tif (this.overflow === \"throw\") {\n\t\t\t\tthrow new Error(`Stream exceeded the ${this.maxLineChars} character line limit`);\n\t\t\t}\n\t\t\tthis.parts = [];\n\t\t\tthis.length = 0;\n\t\t\tthis.skippingOversizedLine = true;\n\t\t\treturn;\n\t\t}\n\t\tthis.parts.push(part);\n\t}\n\n\tprivate takeLine(): string {\n\t\tconst line = this.parts.length === 0 ? \"\" : this.parts.length === 1 ? this.parts[0] : this.parts.join(\"\");\n\t\tthis.resetLine();\n\t\treturn line;\n\t}\n\n\tprivate resetLine(): void {\n\t\tthis.parts = [];\n\t\tthis.length = 0;\n\t\tthis.skippingOversizedLine = false;\n\t}\n}\n"]}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/** Incremental line decoder that joins a fragmented line only once, when it completes. */
|
|
2
|
-
export class StreamingLineDecoder {
|
|
3
|
-
maxLineChars;
|
|
4
|
-
overflow;
|
|
5
|
-
lineEndings;
|
|
6
|
-
parts = [];
|
|
7
|
-
length = 0;
|
|
8
|
-
skipLeadingLf = false;
|
|
9
|
-
skippingOversizedLine = false;
|
|
10
|
-
constructor(maxLineChars, options) {
|
|
11
|
-
this.maxLineChars = maxLineChars;
|
|
12
|
-
this.overflow = options?.overflow ?? "throw";
|
|
13
|
-
this.lineEndings = options?.lineEndings ?? "any";
|
|
14
|
-
}
|
|
15
|
-
push(text) {
|
|
16
|
-
const lines = [];
|
|
17
|
-
let start = 0;
|
|
18
|
-
if (this.skipLeadingLf) {
|
|
19
|
-
this.skipLeadingLf = false;
|
|
20
|
-
if (text.startsWith("\n"))
|
|
21
|
-
start = 1;
|
|
22
|
-
}
|
|
23
|
-
for (let index = start; index < text.length; index++) {
|
|
24
|
-
const char = text[index];
|
|
25
|
-
if (char !== "\n" && (this.lineEndings === "lf" || char !== "\r"))
|
|
26
|
-
continue;
|
|
27
|
-
this.append(text.slice(start, index));
|
|
28
|
-
if (this.skippingOversizedLine)
|
|
29
|
-
this.resetLine();
|
|
30
|
-
else
|
|
31
|
-
lines.push(this.takeLine());
|
|
32
|
-
if (char === "\r") {
|
|
33
|
-
if (text[index + 1] === "\n")
|
|
34
|
-
index++;
|
|
35
|
-
else if (index + 1 === text.length)
|
|
36
|
-
this.skipLeadingLf = true;
|
|
37
|
-
}
|
|
38
|
-
start = index + 1;
|
|
39
|
-
}
|
|
40
|
-
this.append(text.slice(start));
|
|
41
|
-
return lines;
|
|
42
|
-
}
|
|
43
|
-
finish() {
|
|
44
|
-
this.skipLeadingLf = false;
|
|
45
|
-
if (this.skippingOversizedLine) {
|
|
46
|
-
this.resetLine();
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
if (this.length === 0 && this.parts.length === 0)
|
|
50
|
-
return undefined;
|
|
51
|
-
return this.takeLine();
|
|
52
|
-
}
|
|
53
|
-
append(part) {
|
|
54
|
-
if (part.length === 0 || this.skippingOversizedLine)
|
|
55
|
-
return;
|
|
56
|
-
this.length += part.length;
|
|
57
|
-
if (this.length > this.maxLineChars) {
|
|
58
|
-
if (this.overflow === "throw") {
|
|
59
|
-
throw new Error(`Stream exceeded the ${this.maxLineChars} character line limit`);
|
|
60
|
-
}
|
|
61
|
-
this.parts = [];
|
|
62
|
-
this.length = 0;
|
|
63
|
-
this.skippingOversizedLine = true;
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
this.parts.push(part);
|
|
67
|
-
}
|
|
68
|
-
takeLine() {
|
|
69
|
-
const line = this.parts.length === 0 ? "" : this.parts.length === 1 ? this.parts[0] : this.parts.join("");
|
|
70
|
-
this.resetLine();
|
|
71
|
-
return line;
|
|
72
|
-
}
|
|
73
|
-
resetLine() {
|
|
74
|
-
this.parts = [];
|
|
75
|
-
this.length = 0;
|
|
76
|
-
this.skippingOversizedLine = false;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=streaming-lines.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"streaming-lines.js","sourceRoot":"","sources":["../../src/utils/streaming-lines.ts"],"names":[],"mappings":"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","sourcesContent":["/** Incremental line decoder that joins a fragmented line only once, when it completes. */\nexport class StreamingLineDecoder {\n\tprivate readonly maxLineChars: number;\n\tprivate readonly overflow: \"throw\" | \"skip\";\n\tprivate readonly lineEndings: \"lf\" | \"any\";\n\tprivate parts: string[] = [];\n\tprivate length = 0;\n\tprivate skipLeadingLf = false;\n\tprivate skippingOversizedLine = false;\n\n\tconstructor(maxLineChars: number, options?: { overflow?: \"throw\" | \"skip\"; lineEndings?: \"lf\" | \"any\" }) {\n\t\tthis.maxLineChars = maxLineChars;\n\t\tthis.overflow = options?.overflow ?? \"throw\";\n\t\tthis.lineEndings = options?.lineEndings ?? \"any\";\n\t}\n\n\tpush(text: string): string[] {\n\t\tconst lines: string[] = [];\n\t\tlet start = 0;\n\t\tif (this.skipLeadingLf) {\n\t\t\tthis.skipLeadingLf = false;\n\t\t\tif (text.startsWith(\"\\n\")) start = 1;\n\t\t}\n\t\tfor (let index = start; index < text.length; index++) {\n\t\t\tconst char = text[index];\n\t\t\tif (char !== \"\\n\" && (this.lineEndings === \"lf\" || char !== \"\\r\")) continue;\n\t\t\tthis.append(text.slice(start, index));\n\t\t\tif (this.skippingOversizedLine) this.resetLine();\n\t\t\telse lines.push(this.takeLine());\n\t\t\tif (char === \"\\r\") {\n\t\t\t\tif (text[index + 1] === \"\\n\") index++;\n\t\t\t\telse if (index + 1 === text.length) this.skipLeadingLf = true;\n\t\t\t}\n\t\t\tstart = index + 1;\n\t\t}\n\t\tthis.append(text.slice(start));\n\t\treturn lines;\n\t}\n\n\tfinish(): string | undefined {\n\t\tthis.skipLeadingLf = false;\n\t\tif (this.skippingOversizedLine) {\n\t\t\tthis.resetLine();\n\t\t\treturn undefined;\n\t\t}\n\t\tif (this.length === 0 && this.parts.length === 0) return undefined;\n\t\treturn this.takeLine();\n\t}\n\n\tprivate append(part: string): void {\n\t\tif (part.length === 0 || this.skippingOversizedLine) return;\n\t\tthis.length += part.length;\n\t\tif (this.length > this.maxLineChars) {\n\t\t\tif (this.overflow === \"throw\") {\n\t\t\t\tthrow new Error(`Stream exceeded the ${this.maxLineChars} character line limit`);\n\t\t\t}\n\t\t\tthis.parts = [];\n\t\t\tthis.length = 0;\n\t\t\tthis.skippingOversizedLine = true;\n\t\t\treturn;\n\t\t}\n\t\tthis.parts.push(part);\n\t}\n\n\tprivate takeLine(): string {\n\t\tconst line = this.parts.length === 0 ? \"\" : this.parts.length === 1 ? this.parts[0] : this.parts.join(\"\");\n\t\tthis.resetLine();\n\t\treturn line;\n\t}\n\n\tprivate resetLine(): void {\n\t\tthis.parts = [];\n\t\tthis.length = 0;\n\t\tthis.skippingOversizedLine = false;\n\t}\n}\n"]}
|