@codelia/runtime 0.1.39 → 0.1.40
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/index.cjs +22 -57
- package/dist/index.js +22 -57
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -4745,7 +4745,7 @@ var import_node_fs13 = require("fs");
|
|
|
4745
4745
|
var import_core10 = require("@codelia/core");
|
|
4746
4746
|
var import_zod9 = require("zod");
|
|
4747
4747
|
var DEFAULT_READ_LIMIT = 2e3;
|
|
4748
|
-
var DEFAULT_MAX_LINE_LENGTH =
|
|
4748
|
+
var DEFAULT_MAX_LINE_LENGTH = 1e3;
|
|
4749
4749
|
var DEFAULT_MAX_BYTES = 64 * 1024;
|
|
4750
4750
|
var parsePositiveIntEnv = (key, fallback) => {
|
|
4751
4751
|
const raw = process.env[key];
|
|
@@ -4787,34 +4787,20 @@ var clipLineToByteBudget = (line, maxBytes) => {
|
|
|
4787
4787
|
}
|
|
4788
4788
|
return `${clipUtf8ToBytes(line, maxBytes - suffixBytes)}${suffix}`;
|
|
4789
4789
|
};
|
|
4790
|
-
var
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
var buildSingleLineByteCapError = (options) => [
|
|
4798
|
-
`TOO_LARGE_TO_READ: requested line ${options.lineNumber} exceeds per-call byte limit (${MAX_BYTES} bytes).`,
|
|
4799
|
-
`file_path=${options.filePath} line_number=${options.lineNumber}`,
|
|
4800
|
-
"Offset-based pagination cannot continue within one physical line.",
|
|
4801
|
-
"Use read_line for char-based paging or retry with allow_truncate=true.",
|
|
4802
|
-
`read_line({"file_path":"${options.filePath}","line_number":${options.lineNumber},"char_offset":0,"char_limit":10000})`
|
|
4803
|
-
].join("\n").trim();
|
|
4804
|
-
var buildLineTooLongError = (options) => [
|
|
4805
|
-
`LINE_TOO_LONG: line ${options.lineNumber} has ${options.lineLength} chars (max ${MAX_LINE_LENGTH}).`,
|
|
4806
|
-
`file_path=${options.filePath}`,
|
|
4807
|
-
"Use read_line for char-based paging or retry with allow_truncate=true.",
|
|
4808
|
-
`read_line({"file_path":"${options.filePath}","line_number":${options.lineNumber},"char_offset":0,"char_limit":10000})`
|
|
4809
|
-
].join("\n").trim();
|
|
4790
|
+
var buildTruncatedLinesSummary = (lineNumbers) => {
|
|
4791
|
+
if (lineNumbers.length === 0) return null;
|
|
4792
|
+
if (lineNumbers.length > 3) {
|
|
4793
|
+
return "[truncated lines: many]";
|
|
4794
|
+
}
|
|
4795
|
+
return `[truncated lines: ${lineNumbers.join(", ")}]`;
|
|
4796
|
+
};
|
|
4810
4797
|
var createReadTool = (sandboxKey) => (0, import_core10.defineTool)({
|
|
4811
4798
|
name: "read",
|
|
4812
4799
|
description: "Read a text file with optional 0-based line offset and line limit.",
|
|
4813
4800
|
input: import_zod9.z.object({
|
|
4814
4801
|
file_path: import_zod9.z.string().describe("File path under the sandbox root."),
|
|
4815
4802
|
offset: import_zod9.z.number().int().nonnegative().optional().describe("0-based start line. Default 0."),
|
|
4816
|
-
limit: import_zod9.z.number().int().positive().optional().describe("Max lines to read. Default 2000.")
|
|
4817
|
-
allow_truncate: import_zod9.z.boolean().optional().describe("Allow truncation when output is too large. Default false.")
|
|
4803
|
+
limit: import_zod9.z.number().int().positive().optional().describe("Max lines to read. Default 2000.")
|
|
4818
4804
|
}),
|
|
4819
4805
|
execute: async (input, ctx) => {
|
|
4820
4806
|
let resolved;
|
|
@@ -4840,27 +4826,19 @@ var createReadTool = (sandboxKey) => (0, import_core10.defineTool)({
|
|
|
4840
4826
|
}
|
|
4841
4827
|
const offset = input.offset ?? 0;
|
|
4842
4828
|
const limit = input.limit ?? DEFAULT_READ_LIMIT;
|
|
4843
|
-
const allowTruncate = input.allow_truncate ?? false;
|
|
4844
4829
|
if (offset >= lines.length) {
|
|
4845
4830
|
return `Offset exceeds output length: ${input.file_path}`;
|
|
4846
4831
|
}
|
|
4847
4832
|
const outputLines = [];
|
|
4848
4833
|
let bytes = 0;
|
|
4849
4834
|
let truncatedByBytes = false;
|
|
4850
|
-
|
|
4835
|
+
const truncatedLineNumbers = [];
|
|
4851
4836
|
let firstClippedLineNumber = null;
|
|
4852
4837
|
for (let index = offset; index < Math.min(lines.length, offset + limit); index += 1) {
|
|
4853
4838
|
const originalLine = lines[index] ?? "";
|
|
4854
|
-
|
|
4855
|
-
return buildLineTooLongError({
|
|
4856
|
-
filePath: input.file_path,
|
|
4857
|
-
lineNumber: index + 1,
|
|
4858
|
-
lineLength: originalLine.length
|
|
4859
|
-
});
|
|
4860
|
-
}
|
|
4861
|
-
const line = allowTruncate ? clipLongLine(originalLine) : originalLine;
|
|
4839
|
+
const line = clipLongLine(originalLine);
|
|
4862
4840
|
if (line.length !== originalLine.length) {
|
|
4863
|
-
|
|
4841
|
+
truncatedLineNumbers.push(index + 1);
|
|
4864
4842
|
if (firstClippedLineNumber === null) {
|
|
4865
4843
|
firstClippedLineNumber = index + 1;
|
|
4866
4844
|
}
|
|
@@ -4868,20 +4846,6 @@ var createReadTool = (sandboxKey) => (0, import_core10.defineTool)({
|
|
|
4868
4846
|
const numberedLine = `${String(index + 1).padStart(5, " ")} ${line}`;
|
|
4869
4847
|
const size = Buffer.byteLength(numberedLine, "utf8") + (outputLines.length > 0 ? 1 : 0);
|
|
4870
4848
|
if (bytes + size > MAX_BYTES) {
|
|
4871
|
-
if (!allowTruncate) {
|
|
4872
|
-
if (outputLines.length === 0) {
|
|
4873
|
-
return buildSingleLineByteCapError({
|
|
4874
|
-
filePath: input.file_path,
|
|
4875
|
-
lineNumber: index + 1
|
|
4876
|
-
});
|
|
4877
|
-
}
|
|
4878
|
-
return buildTooLargeToReadError({
|
|
4879
|
-
filePath: input.file_path,
|
|
4880
|
-
offset,
|
|
4881
|
-
limit,
|
|
4882
|
-
nextOffset: Math.max(offset + outputLines.length, offset + 1)
|
|
4883
|
-
});
|
|
4884
|
-
}
|
|
4885
4849
|
if (outputLines.length === 0) {
|
|
4886
4850
|
const prefix = `${String(index + 1).padStart(5, " ")} `;
|
|
4887
4851
|
const budget = MAX_BYTES - Buffer.byteLength(prefix, "utf8");
|
|
@@ -4892,7 +4856,7 @@ var createReadTool = (sandboxKey) => (0, import_core10.defineTool)({
|
|
|
4892
4856
|
`${prefix}${clippedByBytes}`,
|
|
4893
4857
|
"utf8"
|
|
4894
4858
|
);
|
|
4895
|
-
|
|
4859
|
+
truncatedLineNumbers.push(index + 1);
|
|
4896
4860
|
if (firstClippedLineNumber === null) {
|
|
4897
4861
|
firstClippedLineNumber = index + 1;
|
|
4898
4862
|
}
|
|
@@ -4911,17 +4875,20 @@ var createReadTool = (sandboxKey) => (0, import_core10.defineTool)({
|
|
|
4911
4875
|
const hasMoreLines = lines.length > lastReadLine;
|
|
4912
4876
|
let output = numbered.join("\n");
|
|
4913
4877
|
if (truncatedByBytes || hasMoreLines) {
|
|
4914
|
-
const reason = truncatedByBytes ? `
|
|
4878
|
+
const reason = truncatedByBytes ? `[output truncated at ${MAX_BYTES} bytes]` : "Output has more lines.";
|
|
4915
4879
|
output += `
|
|
4916
4880
|
|
|
4917
4881
|
${reason} Use offset to read beyond line ${lastReadLine}.`;
|
|
4918
4882
|
}
|
|
4919
|
-
|
|
4883
|
+
const truncatedLinesSummary = buildTruncatedLinesSummary(
|
|
4884
|
+
Array.from(new Set(truncatedLineNumbers))
|
|
4885
|
+
);
|
|
4886
|
+
if (truncatedLinesSummary) {
|
|
4920
4887
|
output += `
|
|
4921
4888
|
|
|
4922
|
-
|
|
4889
|
+
${truncatedLinesSummary}`;
|
|
4923
4890
|
}
|
|
4924
|
-
if (
|
|
4891
|
+
if (firstClippedLineNumber !== null) {
|
|
4925
4892
|
output += `
|
|
4926
4893
|
|
|
4927
4894
|
For full long-line content, use read_line({"file_path":"${input.file_path}","line_number":${firstClippedLineNumber},"char_offset":0,"char_limit":10000}).`;
|
|
@@ -5538,8 +5505,7 @@ var createToolOutputCacheTool = (store) => (0, import_core16.defineTool)({
|
|
|
5538
5505
|
input: import_zod15.z.object({
|
|
5539
5506
|
ref_id: import_zod15.z.string().describe("Tool output reference ID."),
|
|
5540
5507
|
offset: import_zod15.z.number().int().nonnegative().optional().describe("Optional 0-based line offset."),
|
|
5541
|
-
limit: import_zod15.z.number().int().positive().optional().describe("Optional max number of lines to return.")
|
|
5542
|
-
allow_truncate: import_zod15.z.boolean().optional().describe("Allow truncation when output is too large. Default false.")
|
|
5508
|
+
limit: import_zod15.z.number().int().positive().optional().describe("Optional max number of lines to return.")
|
|
5543
5509
|
}),
|
|
5544
5510
|
execute: async (input) => {
|
|
5545
5511
|
if (!store.read) {
|
|
@@ -5548,8 +5514,7 @@ var createToolOutputCacheTool = (store) => (0, import_core16.defineTool)({
|
|
|
5548
5514
|
try {
|
|
5549
5515
|
return await store.read(input.ref_id, {
|
|
5550
5516
|
offset: input.offset,
|
|
5551
|
-
limit: input.limit
|
|
5552
|
-
allow_truncate: input.allow_truncate
|
|
5517
|
+
limit: input.limit
|
|
5553
5518
|
});
|
|
5554
5519
|
} catch (error) {
|
|
5555
5520
|
return `Error reading tool output cache: ${String(error)}`;
|
package/dist/index.js
CHANGED
|
@@ -4745,7 +4745,7 @@ import { promises as fs13 } from "fs";
|
|
|
4745
4745
|
import { defineTool as defineTool8 } from "@codelia/core";
|
|
4746
4746
|
import { z as z9 } from "zod";
|
|
4747
4747
|
var DEFAULT_READ_LIMIT = 2e3;
|
|
4748
|
-
var DEFAULT_MAX_LINE_LENGTH =
|
|
4748
|
+
var DEFAULT_MAX_LINE_LENGTH = 1e3;
|
|
4749
4749
|
var DEFAULT_MAX_BYTES = 64 * 1024;
|
|
4750
4750
|
var parsePositiveIntEnv = (key, fallback) => {
|
|
4751
4751
|
const raw = process.env[key];
|
|
@@ -4787,34 +4787,20 @@ var clipLineToByteBudget = (line, maxBytes) => {
|
|
|
4787
4787
|
}
|
|
4788
4788
|
return `${clipUtf8ToBytes(line, maxBytes - suffixBytes)}${suffix}`;
|
|
4789
4789
|
};
|
|
4790
|
-
var
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
var buildSingleLineByteCapError = (options) => [
|
|
4798
|
-
`TOO_LARGE_TO_READ: requested line ${options.lineNumber} exceeds per-call byte limit (${MAX_BYTES} bytes).`,
|
|
4799
|
-
`file_path=${options.filePath} line_number=${options.lineNumber}`,
|
|
4800
|
-
"Offset-based pagination cannot continue within one physical line.",
|
|
4801
|
-
"Use read_line for char-based paging or retry with allow_truncate=true.",
|
|
4802
|
-
`read_line({"file_path":"${options.filePath}","line_number":${options.lineNumber},"char_offset":0,"char_limit":10000})`
|
|
4803
|
-
].join("\n").trim();
|
|
4804
|
-
var buildLineTooLongError = (options) => [
|
|
4805
|
-
`LINE_TOO_LONG: line ${options.lineNumber} has ${options.lineLength} chars (max ${MAX_LINE_LENGTH}).`,
|
|
4806
|
-
`file_path=${options.filePath}`,
|
|
4807
|
-
"Use read_line for char-based paging or retry with allow_truncate=true.",
|
|
4808
|
-
`read_line({"file_path":"${options.filePath}","line_number":${options.lineNumber},"char_offset":0,"char_limit":10000})`
|
|
4809
|
-
].join("\n").trim();
|
|
4790
|
+
var buildTruncatedLinesSummary = (lineNumbers) => {
|
|
4791
|
+
if (lineNumbers.length === 0) return null;
|
|
4792
|
+
if (lineNumbers.length > 3) {
|
|
4793
|
+
return "[truncated lines: many]";
|
|
4794
|
+
}
|
|
4795
|
+
return `[truncated lines: ${lineNumbers.join(", ")}]`;
|
|
4796
|
+
};
|
|
4810
4797
|
var createReadTool = (sandboxKey) => defineTool8({
|
|
4811
4798
|
name: "read",
|
|
4812
4799
|
description: "Read a text file with optional 0-based line offset and line limit.",
|
|
4813
4800
|
input: z9.object({
|
|
4814
4801
|
file_path: z9.string().describe("File path under the sandbox root."),
|
|
4815
4802
|
offset: z9.number().int().nonnegative().optional().describe("0-based start line. Default 0."),
|
|
4816
|
-
limit: z9.number().int().positive().optional().describe("Max lines to read. Default 2000.")
|
|
4817
|
-
allow_truncate: z9.boolean().optional().describe("Allow truncation when output is too large. Default false.")
|
|
4803
|
+
limit: z9.number().int().positive().optional().describe("Max lines to read. Default 2000.")
|
|
4818
4804
|
}),
|
|
4819
4805
|
execute: async (input, ctx) => {
|
|
4820
4806
|
let resolved;
|
|
@@ -4840,27 +4826,19 @@ var createReadTool = (sandboxKey) => defineTool8({
|
|
|
4840
4826
|
}
|
|
4841
4827
|
const offset = input.offset ?? 0;
|
|
4842
4828
|
const limit = input.limit ?? DEFAULT_READ_LIMIT;
|
|
4843
|
-
const allowTruncate = input.allow_truncate ?? false;
|
|
4844
4829
|
if (offset >= lines.length) {
|
|
4845
4830
|
return `Offset exceeds output length: ${input.file_path}`;
|
|
4846
4831
|
}
|
|
4847
4832
|
const outputLines = [];
|
|
4848
4833
|
let bytes = 0;
|
|
4849
4834
|
let truncatedByBytes = false;
|
|
4850
|
-
|
|
4835
|
+
const truncatedLineNumbers = [];
|
|
4851
4836
|
let firstClippedLineNumber = null;
|
|
4852
4837
|
for (let index = offset; index < Math.min(lines.length, offset + limit); index += 1) {
|
|
4853
4838
|
const originalLine = lines[index] ?? "";
|
|
4854
|
-
|
|
4855
|
-
return buildLineTooLongError({
|
|
4856
|
-
filePath: input.file_path,
|
|
4857
|
-
lineNumber: index + 1,
|
|
4858
|
-
lineLength: originalLine.length
|
|
4859
|
-
});
|
|
4860
|
-
}
|
|
4861
|
-
const line = allowTruncate ? clipLongLine(originalLine) : originalLine;
|
|
4839
|
+
const line = clipLongLine(originalLine);
|
|
4862
4840
|
if (line.length !== originalLine.length) {
|
|
4863
|
-
|
|
4841
|
+
truncatedLineNumbers.push(index + 1);
|
|
4864
4842
|
if (firstClippedLineNumber === null) {
|
|
4865
4843
|
firstClippedLineNumber = index + 1;
|
|
4866
4844
|
}
|
|
@@ -4868,20 +4846,6 @@ var createReadTool = (sandboxKey) => defineTool8({
|
|
|
4868
4846
|
const numberedLine = `${String(index + 1).padStart(5, " ")} ${line}`;
|
|
4869
4847
|
const size = Buffer.byteLength(numberedLine, "utf8") + (outputLines.length > 0 ? 1 : 0);
|
|
4870
4848
|
if (bytes + size > MAX_BYTES) {
|
|
4871
|
-
if (!allowTruncate) {
|
|
4872
|
-
if (outputLines.length === 0) {
|
|
4873
|
-
return buildSingleLineByteCapError({
|
|
4874
|
-
filePath: input.file_path,
|
|
4875
|
-
lineNumber: index + 1
|
|
4876
|
-
});
|
|
4877
|
-
}
|
|
4878
|
-
return buildTooLargeToReadError({
|
|
4879
|
-
filePath: input.file_path,
|
|
4880
|
-
offset,
|
|
4881
|
-
limit,
|
|
4882
|
-
nextOffset: Math.max(offset + outputLines.length, offset + 1)
|
|
4883
|
-
});
|
|
4884
|
-
}
|
|
4885
4849
|
if (outputLines.length === 0) {
|
|
4886
4850
|
const prefix = `${String(index + 1).padStart(5, " ")} `;
|
|
4887
4851
|
const budget = MAX_BYTES - Buffer.byteLength(prefix, "utf8");
|
|
@@ -4892,7 +4856,7 @@ var createReadTool = (sandboxKey) => defineTool8({
|
|
|
4892
4856
|
`${prefix}${clippedByBytes}`,
|
|
4893
4857
|
"utf8"
|
|
4894
4858
|
);
|
|
4895
|
-
|
|
4859
|
+
truncatedLineNumbers.push(index + 1);
|
|
4896
4860
|
if (firstClippedLineNumber === null) {
|
|
4897
4861
|
firstClippedLineNumber = index + 1;
|
|
4898
4862
|
}
|
|
@@ -4911,17 +4875,20 @@ var createReadTool = (sandboxKey) => defineTool8({
|
|
|
4911
4875
|
const hasMoreLines = lines.length > lastReadLine;
|
|
4912
4876
|
let output = numbered.join("\n");
|
|
4913
4877
|
if (truncatedByBytes || hasMoreLines) {
|
|
4914
|
-
const reason = truncatedByBytes ? `
|
|
4878
|
+
const reason = truncatedByBytes ? `[output truncated at ${MAX_BYTES} bytes]` : "Output has more lines.";
|
|
4915
4879
|
output += `
|
|
4916
4880
|
|
|
4917
4881
|
${reason} Use offset to read beyond line ${lastReadLine}.`;
|
|
4918
4882
|
}
|
|
4919
|
-
|
|
4883
|
+
const truncatedLinesSummary = buildTruncatedLinesSummary(
|
|
4884
|
+
Array.from(new Set(truncatedLineNumbers))
|
|
4885
|
+
);
|
|
4886
|
+
if (truncatedLinesSummary) {
|
|
4920
4887
|
output += `
|
|
4921
4888
|
|
|
4922
|
-
|
|
4889
|
+
${truncatedLinesSummary}`;
|
|
4923
4890
|
}
|
|
4924
|
-
if (
|
|
4891
|
+
if (firstClippedLineNumber !== null) {
|
|
4925
4892
|
output += `
|
|
4926
4893
|
|
|
4927
4894
|
For full long-line content, use read_line({"file_path":"${input.file_path}","line_number":${firstClippedLineNumber},"char_offset":0,"char_limit":10000}).`;
|
|
@@ -5538,8 +5505,7 @@ var createToolOutputCacheTool = (store) => defineTool14({
|
|
|
5538
5505
|
input: z15.object({
|
|
5539
5506
|
ref_id: z15.string().describe("Tool output reference ID."),
|
|
5540
5507
|
offset: z15.number().int().nonnegative().optional().describe("Optional 0-based line offset."),
|
|
5541
|
-
limit: z15.number().int().positive().optional().describe("Optional max number of lines to return.")
|
|
5542
|
-
allow_truncate: z15.boolean().optional().describe("Allow truncation when output is too large. Default false.")
|
|
5508
|
+
limit: z15.number().int().positive().optional().describe("Optional max number of lines to return.")
|
|
5543
5509
|
}),
|
|
5544
5510
|
execute: async (input) => {
|
|
5545
5511
|
if (!store.read) {
|
|
@@ -5548,8 +5514,7 @@ var createToolOutputCacheTool = (store) => defineTool14({
|
|
|
5548
5514
|
try {
|
|
5549
5515
|
return await store.read(input.ref_id, {
|
|
5550
5516
|
offset: input.offset,
|
|
5551
|
-
limit: input.limit
|
|
5552
|
-
allow_truncate: input.allow_truncate
|
|
5517
|
+
limit: input.limit
|
|
5553
5518
|
});
|
|
5554
5519
|
} catch (error) {
|
|
5555
5520
|
return `Error reading tool output cache: ${String(error)}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codelia/runtime",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.40",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20 <25"
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
"typecheck": "tsc --noEmit"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@codelia/config": "0.1.
|
|
27
|
-
"@codelia/config-loader": "0.1.
|
|
28
|
-
"@codelia/core": "0.1.
|
|
29
|
-
"@codelia/logger": "0.1.
|
|
30
|
-
"@codelia/model-metadata": "0.1.
|
|
31
|
-
"@codelia/protocol": "0.1.
|
|
32
|
-
"@codelia/shared-types": "0.1.
|
|
33
|
-
"@codelia/storage": "0.1.
|
|
26
|
+
"@codelia/config": "0.1.40",
|
|
27
|
+
"@codelia/config-loader": "0.1.40",
|
|
28
|
+
"@codelia/core": "0.1.40",
|
|
29
|
+
"@codelia/logger": "0.1.40",
|
|
30
|
+
"@codelia/model-metadata": "0.1.40",
|
|
31
|
+
"@codelia/protocol": "0.1.40",
|
|
32
|
+
"@codelia/shared-types": "0.1.40",
|
|
33
|
+
"@codelia/storage": "0.1.40",
|
|
34
34
|
"eventsource-parser": "^3.0.6",
|
|
35
35
|
"oauth4webapi": "^3.8.4",
|
|
36
36
|
"zod": "^4.3.5"
|