@cuylabs/agent-core 0.4.0 → 0.5.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/README.md +57 -8
- package/dist/builder-RcTZuYnO.d.ts +34 -0
- package/dist/capabilities/index.d.ts +97 -0
- package/dist/capabilities/index.js +46 -0
- package/dist/chunk-6TDTQJ4P.js +116 -0
- package/dist/chunk-7MUFEN4K.js +559 -0
- package/dist/chunk-BDBZ3SLK.js +745 -0
- package/dist/chunk-DWYX7ASF.js +26 -0
- package/dist/chunk-FG4MD5MU.js +54 -0
- package/dist/chunk-IMGQOTU2.js +2019 -0
- package/dist/chunk-IVUJDISU.js +556 -0
- package/dist/chunk-LRHOS4ZN.js +584 -0
- package/dist/chunk-OTUGSCED.js +691 -0
- package/dist/chunk-P6YF7USR.js +182 -0
- package/dist/chunk-QAQADS4X.js +258 -0
- package/dist/chunk-QWFMX226.js +879 -0
- package/dist/{chunk-6VKLWNRE.js → chunk-SDSBEQXG.js} +1 -132
- package/dist/chunk-VBWWUHWI.js +724 -0
- package/dist/chunk-VEKUXUVF.js +41 -0
- package/dist/chunk-X635CM2F.js +305 -0
- package/dist/chunk-YUUJK53A.js +91 -0
- package/dist/chunk-ZXAKHMWH.js +283 -0
- package/dist/config-D2xeGEHK.d.ts +52 -0
- package/dist/context/index.d.ts +259 -0
- package/dist/context/index.js +26 -0
- package/dist/identifiers-BLUxFqV_.d.ts +12 -0
- package/dist/index-p0kOsVsE.d.ts +1067 -0
- package/dist/index-tmhaADz5.d.ts +198 -0
- package/dist/index.d.ts +210 -5736
- package/dist/index.js +2126 -7766
- package/dist/mcp/index.d.ts +26 -0
- package/dist/mcp/index.js +14 -0
- package/dist/messages-BYWGn8TY.d.ts +110 -0
- package/dist/middleware/index.d.ts +7 -0
- package/dist/middleware/index.js +12 -0
- package/dist/models/index.d.ts +33 -0
- package/dist/models/index.js +12 -0
- package/dist/network-D76DS5ot.d.ts +5 -0
- package/dist/prompt/index.d.ts +224 -0
- package/dist/prompt/index.js +45 -0
- package/dist/reasoning/index.d.ts +71 -0
- package/dist/reasoning/index.js +47 -0
- package/dist/registry-CuRWWtcT.d.ts +164 -0
- package/dist/resolver-DOfZ-xuk.d.ts +254 -0
- package/dist/runner-C7aMP_x3.d.ts +596 -0
- package/dist/runtime/index.d.ts +357 -0
- package/dist/runtime/index.js +64 -0
- package/dist/session-manager-Uawm2Le7.d.ts +274 -0
- package/dist/skill/index.d.ts +103 -0
- package/dist/skill/index.js +39 -0
- package/dist/storage/index.d.ts +167 -0
- package/dist/storage/index.js +50 -0
- package/dist/sub-agent/index.d.ts +14 -0
- package/dist/sub-agent/index.js +15 -0
- package/dist/tool/index.d.ts +173 -1
- package/dist/tool/index.js +12 -3
- package/dist/tool-DYp6-cC3.d.ts +239 -0
- package/dist/tool-pFAnJc5Y.d.ts +419 -0
- package/dist/tracker-DClqYqTj.d.ts +96 -0
- package/dist/tracking/index.d.ts +109 -0
- package/dist/tracking/index.js +20 -0
- package/dist/types-CQaXbRsS.d.ts +47 -0
- package/dist/types-MM1JoX5T.d.ts +810 -0
- package/dist/types-VQgymC1N.d.ts +156 -0
- package/package.json +89 -5
- package/dist/index-BlSTfS-W.d.ts +0 -470
|
@@ -1,126 +1,3 @@
|
|
|
1
|
-
// src/tool/tool.ts
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
// src/tool/truncation.ts
|
|
5
|
-
import * as fs from "fs/promises";
|
|
6
|
-
import * as path from "path";
|
|
7
|
-
import * as os from "os";
|
|
8
|
-
import * as crypto from "crypto";
|
|
9
|
-
var MAX_LINES = 2e3;
|
|
10
|
-
var MAX_BYTES = 1e5;
|
|
11
|
-
var TRUNCATE_DIR = path.join(os.tmpdir(), "cuylabs-agent-outputs");
|
|
12
|
-
var TRUNCATE_GLOB = path.join(TRUNCATE_DIR, "*");
|
|
13
|
-
function truncateOutput(output, options = {}) {
|
|
14
|
-
const maxLines = options.maxLines ?? MAX_LINES;
|
|
15
|
-
const maxBytes = options.maxBytes ?? MAX_BYTES;
|
|
16
|
-
const lines = output.split("\n");
|
|
17
|
-
const bytes = Buffer.byteLength(output, "utf-8");
|
|
18
|
-
if (lines.length <= maxLines && bytes <= maxBytes) {
|
|
19
|
-
return {
|
|
20
|
-
content: output,
|
|
21
|
-
truncated: false
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
const hash = crypto.createHash("sha256").update(output).digest("hex").slice(0, 16);
|
|
25
|
-
const outputPath = path.join(TRUNCATE_DIR, `output-${hash}.txt`);
|
|
26
|
-
fs.mkdir(TRUNCATE_DIR, { recursive: true }).then(() => fs.writeFile(outputPath, output, "utf-8")).catch(() => {
|
|
27
|
-
});
|
|
28
|
-
let truncated;
|
|
29
|
-
if (lines.length > maxLines) {
|
|
30
|
-
const keepLines = Math.floor(maxLines / 2);
|
|
31
|
-
const firstPart = lines.slice(0, keepLines);
|
|
32
|
-
const lastPart = lines.slice(-keepLines);
|
|
33
|
-
const omitted = lines.length - keepLines * 2;
|
|
34
|
-
truncated = [
|
|
35
|
-
...firstPart,
|
|
36
|
-
`
|
|
37
|
-
... (${omitted} lines omitted, full output saved to ${outputPath}) ...
|
|
38
|
-
`,
|
|
39
|
-
...lastPart
|
|
40
|
-
].join("\n");
|
|
41
|
-
} else {
|
|
42
|
-
const keepBytes = Math.floor(maxBytes / 2);
|
|
43
|
-
const start = output.slice(0, keepBytes);
|
|
44
|
-
const end = output.slice(-keepBytes);
|
|
45
|
-
const omittedBytes = bytes - keepBytes * 2;
|
|
46
|
-
truncated = `${start}
|
|
47
|
-
... (${omittedBytes} bytes omitted, full output saved to ${outputPath}) ...
|
|
48
|
-
${end}`;
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
content: truncated,
|
|
52
|
-
truncated: true,
|
|
53
|
-
outputPath
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
function formatSize(bytes) {
|
|
57
|
-
if (bytes < 1024) return `${bytes} B`;
|
|
58
|
-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
59
|
-
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// src/tool/tool.ts
|
|
63
|
-
var Tool;
|
|
64
|
-
((Tool2) => {
|
|
65
|
-
function define(id, init) {
|
|
66
|
-
return {
|
|
67
|
-
id,
|
|
68
|
-
init: async (initCtx) => {
|
|
69
|
-
const toolInfo = typeof init === "function" ? await init(initCtx) : init;
|
|
70
|
-
const originalExecute = toolInfo.execute;
|
|
71
|
-
toolInfo.execute = async (params, ctx) => {
|
|
72
|
-
try {
|
|
73
|
-
toolInfo.parameters.parse(params);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
if (error instanceof z.ZodError && toolInfo.formatValidationError) {
|
|
76
|
-
throw new Error(toolInfo.formatValidationError(error), { cause: error });
|
|
77
|
-
}
|
|
78
|
-
throw new Error(
|
|
79
|
-
`The ${id} tool was called with invalid arguments: ${error}.
|
|
80
|
-
Please rewrite the input so it satisfies the expected schema.`,
|
|
81
|
-
{ cause: error }
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
const result = await originalExecute(params, ctx);
|
|
85
|
-
if (result.metadata.truncated !== void 0) {
|
|
86
|
-
return result;
|
|
87
|
-
}
|
|
88
|
-
const truncated = truncateOutput(result.output);
|
|
89
|
-
return {
|
|
90
|
-
...result,
|
|
91
|
-
output: truncated.content,
|
|
92
|
-
metadata: {
|
|
93
|
-
...result.metadata,
|
|
94
|
-
truncated: truncated.truncated,
|
|
95
|
-
...truncated.truncated && { outputPath: truncated.outputPath }
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
return toolInfo;
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
Tool2.define = define;
|
|
104
|
-
function defineSimple(id, config) {
|
|
105
|
-
return define(id, config);
|
|
106
|
-
}
|
|
107
|
-
Tool2.defineSimple = defineSimple;
|
|
108
|
-
})(Tool || (Tool = {}));
|
|
109
|
-
function defineTool(definition) {
|
|
110
|
-
return Tool.define(definition.id, {
|
|
111
|
-
description: definition.description,
|
|
112
|
-
parameters: definition.parameters,
|
|
113
|
-
execute: async (params, ctx) => {
|
|
114
|
-
const result = await definition.execute(params, ctx);
|
|
115
|
-
return {
|
|
116
|
-
title: result.title,
|
|
117
|
-
output: result.output,
|
|
118
|
-
metadata: result.metadata ?? {}
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
1
|
// src/tool/registry.ts
|
|
125
2
|
var ToolRegistry = class {
|
|
126
3
|
tools = /* @__PURE__ */ new Map();
|
|
@@ -237,7 +114,7 @@ var ToolRegistry = class {
|
|
|
237
114
|
includes.push(token);
|
|
238
115
|
}
|
|
239
116
|
}
|
|
240
|
-
|
|
117
|
+
const result = /* @__PURE__ */ new Map();
|
|
241
118
|
if (includes.length === 0 && excludes.length > 0) {
|
|
242
119
|
for (const [id, tool] of this.tools) {
|
|
243
120
|
result.set(id, tool);
|
|
@@ -275,14 +152,6 @@ var ToolRegistry = class {
|
|
|
275
152
|
var defaultRegistry = new ToolRegistry();
|
|
276
153
|
|
|
277
154
|
export {
|
|
278
|
-
MAX_LINES,
|
|
279
|
-
MAX_BYTES,
|
|
280
|
-
TRUNCATE_DIR,
|
|
281
|
-
TRUNCATE_GLOB,
|
|
282
|
-
truncateOutput,
|
|
283
|
-
formatSize,
|
|
284
|
-
Tool,
|
|
285
|
-
defineTool,
|
|
286
155
|
ToolRegistry,
|
|
287
156
|
defaultRegistry
|
|
288
157
|
};
|