@chatbotkit/agent 1.26.2 → 1.26.3

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.
@@ -6,15 +6,42 @@ const promises_1 = require("fs/promises");
6
6
  const zod_1 = require("zod");
7
7
  exports.tools = {
8
8
  read: {
9
- description: 'Read the contents of a file',
9
+ description: 'Read the contents of a file. Supports optional line range to read specific sections.',
10
10
  default: true,
11
11
  input: zod_1.z.object({
12
12
  path: zod_1.z.string().describe('The file path to read'),
13
+ startLine: zod_1.z
14
+ .number()
15
+ .int()
16
+ .min(1)
17
+ .optional()
18
+ .describe('The line number to start reading from (1-indexed)'),
19
+ endLine: zod_1.z
20
+ .number()
21
+ .int()
22
+ .min(1)
23
+ .optional()
24
+ .describe('The line number to end reading at, inclusive (1-indexed)'),
13
25
  }),
14
26
  handler: async (input) => {
15
27
  try {
16
28
  const content = await (0, promises_1.readFile)(input.path, 'utf-8');
17
- return { success: true, content };
29
+ const lines = content.split('\n');
30
+ const totalLines = lines.length;
31
+ const { startLine, endLine } = input;
32
+ if (startLine === undefined && endLine === undefined) {
33
+ return { success: true, content, totalLines };
34
+ }
35
+ const start = startLine !== undefined ? Math.max(0, startLine - 1) : 0;
36
+ const end = endLine !== undefined ? Math.min(totalLines, endLine) : totalLines;
37
+ const outputContent = lines.slice(start, end).join('\n');
38
+ return {
39
+ success: true,
40
+ content: outputContent,
41
+ totalLines,
42
+ startLine: startLine ?? 1,
43
+ endLine: endLine ?? totalLines,
44
+ };
18
45
  }
19
46
  catch (error) {
20
47
  return {
@@ -25,16 +52,64 @@ exports.tools = {
25
52
  },
26
53
  },
27
54
  write: {
28
- description: 'Write content to a file',
55
+ description: 'Write content to a file. Without line parameters, overwrites the entire file. With startLine only, inserts before that line. With startLine and endLine, replaces that range.',
29
56
  default: true,
30
57
  input: zod_1.z.object({
31
58
  path: zod_1.z.string().describe('The file path to write to'),
32
59
  content: zod_1.z.string().describe('The content to write'),
60
+ startLine: zod_1.z
61
+ .number()
62
+ .int()
63
+ .min(1)
64
+ .optional()
65
+ .describe('The line number to start writing at (1-indexed). If only startLine is provided, content is inserted before this line.'),
66
+ endLine: zod_1.z
67
+ .number()
68
+ .int()
69
+ .min(1)
70
+ .optional()
71
+ .describe('The line number to end writing at, inclusive (1-indexed). Used with startLine to replace a range of lines.'),
33
72
  }),
34
73
  handler: async (input) => {
35
74
  try {
36
- await (0, promises_1.writeFile)(input.path, input.content, 'utf-8');
37
- return { success: true };
75
+ const { path, content, startLine, endLine } = input;
76
+ let finalContent;
77
+ if (startLine === undefined && endLine === undefined) {
78
+ finalContent = content;
79
+ }
80
+ else {
81
+ let currentContent = '';
82
+ try {
83
+ currentContent = await (0, promises_1.readFile)(path, 'utf-8');
84
+ }
85
+ catch {
86
+ currentContent = '';
87
+ }
88
+ const lines = currentContent.split('\n');
89
+ const totalLines = lines.length;
90
+ const newLines = content ? content.split('\n') : [];
91
+ if (startLine !== undefined && endLine === undefined) {
92
+ const insertIndex = Math.min(startLine - 1, totalLines);
93
+ lines.splice(insertIndex, 0, ...newLines);
94
+ }
95
+ else if (startLine !== undefined && endLine !== undefined) {
96
+ const start = Math.max(0, startLine - 1);
97
+ const end = Math.min(totalLines, endLine);
98
+ const deleteCount = end - start;
99
+ lines.splice(start, deleteCount, ...newLines);
100
+ }
101
+ else {
102
+ lines.length = 0;
103
+ lines.push(...newLines);
104
+ }
105
+ finalContent = lines.join('\n');
106
+ }
107
+ await (0, promises_1.writeFile)(path, finalContent, 'utf-8');
108
+ return {
109
+ success: true,
110
+ startLine,
111
+ endLine,
112
+ };
38
113
  }
39
114
  catch (error) {
40
115
  return {
package/dist/esm/tools.js CHANGED
@@ -3,15 +3,42 @@ import { readFile, writeFile } from 'fs/promises';
3
3
  import { z } from 'zod';
4
4
  export const tools = {
5
5
  read: {
6
- description: 'Read the contents of a file',
6
+ description: 'Read the contents of a file. Supports optional line range to read specific sections.',
7
7
  default: true,
8
8
  input: z.object({
9
9
  path: z.string().describe('The file path to read'),
10
+ startLine: z
11
+ .number()
12
+ .int()
13
+ .min(1)
14
+ .optional()
15
+ .describe('The line number to start reading from (1-indexed)'),
16
+ endLine: z
17
+ .number()
18
+ .int()
19
+ .min(1)
20
+ .optional()
21
+ .describe('The line number to end reading at, inclusive (1-indexed)'),
10
22
  }),
11
23
  handler: async (input) => {
12
24
  try {
13
25
  const content = await readFile(input.path, 'utf-8');
14
- return { success: true, content };
26
+ const lines = content.split('\n');
27
+ const totalLines = lines.length;
28
+ const { startLine, endLine } = input;
29
+ if (startLine === undefined && endLine === undefined) {
30
+ return { success: true, content, totalLines };
31
+ }
32
+ const start = startLine !== undefined ? Math.max(0, startLine - 1) : 0;
33
+ const end = endLine !== undefined ? Math.min(totalLines, endLine) : totalLines;
34
+ const outputContent = lines.slice(start, end).join('\n');
35
+ return {
36
+ success: true,
37
+ content: outputContent,
38
+ totalLines,
39
+ startLine: startLine ?? 1,
40
+ endLine: endLine ?? totalLines,
41
+ };
15
42
  }
16
43
  catch (error) {
17
44
  return {
@@ -22,16 +49,64 @@ export const tools = {
22
49
  },
23
50
  },
24
51
  write: {
25
- description: 'Write content to a file',
52
+ description: 'Write content to a file. Without line parameters, overwrites the entire file. With startLine only, inserts before that line. With startLine and endLine, replaces that range.',
26
53
  default: true,
27
54
  input: z.object({
28
55
  path: z.string().describe('The file path to write to'),
29
56
  content: z.string().describe('The content to write'),
57
+ startLine: z
58
+ .number()
59
+ .int()
60
+ .min(1)
61
+ .optional()
62
+ .describe('The line number to start writing at (1-indexed). If only startLine is provided, content is inserted before this line.'),
63
+ endLine: z
64
+ .number()
65
+ .int()
66
+ .min(1)
67
+ .optional()
68
+ .describe('The line number to end writing at, inclusive (1-indexed). Used with startLine to replace a range of lines.'),
30
69
  }),
31
70
  handler: async (input) => {
32
71
  try {
33
- await writeFile(input.path, input.content, 'utf-8');
34
- return { success: true };
72
+ const { path, content, startLine, endLine } = input;
73
+ let finalContent;
74
+ if (startLine === undefined && endLine === undefined) {
75
+ finalContent = content;
76
+ }
77
+ else {
78
+ let currentContent = '';
79
+ try {
80
+ currentContent = await readFile(path, 'utf-8');
81
+ }
82
+ catch {
83
+ currentContent = '';
84
+ }
85
+ const lines = currentContent.split('\n');
86
+ const totalLines = lines.length;
87
+ const newLines = content ? content.split('\n') : [];
88
+ if (startLine !== undefined && endLine === undefined) {
89
+ const insertIndex = Math.min(startLine - 1, totalLines);
90
+ lines.splice(insertIndex, 0, ...newLines);
91
+ }
92
+ else if (startLine !== undefined && endLine !== undefined) {
93
+ const start = Math.max(0, startLine - 1);
94
+ const end = Math.min(totalLines, endLine);
95
+ const deleteCount = end - start;
96
+ lines.splice(start, deleteCount, ...newLines);
97
+ }
98
+ else {
99
+ lines.length = 0;
100
+ lines.push(...newLines);
101
+ }
102
+ finalContent = lines.join('\n');
103
+ }
104
+ await writeFile(path, finalContent, 'utf-8');
105
+ return {
106
+ success: true,
107
+ startLine,
108
+ endLine,
109
+ };
35
110
  }
36
111
  catch (error) {
37
112
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatbotkit/agent",
3
- "version": "1.26.2",
3
+ "version": "1.26.3",
4
4
  "description": "ChatBotKit Agent implementation",
5
5
  "license": "ISC",
6
6
  "engines": {
@@ -94,6 +94,23 @@
94
94
  },
95
95
  "./package.json": "./package.json"
96
96
  },
97
+ "types": "./dist/cjs/index.d.ts",
98
+ "dependencies": {
99
+ "tslib": "^2.6.2",
100
+ "zod": "^3.25.76",
101
+ "zod-to-json-schema": "^3.24.6",
102
+ "@chatbotkit/sdk": "1.26.3"
103
+ },
104
+ "devDependencies": {
105
+ "npm-run-all": "^4.1.5",
106
+ "typedoc": "^0.28.14",
107
+ "typedoc-plugin-markdown": "^4.9.0",
108
+ "typedoc-plugin-mdn-links": "^5.0.10",
109
+ "typescript": "^5.9"
110
+ },
111
+ "files": [
112
+ "dist/**"
113
+ ],
97
114
  "scripts": {
98
115
  "build": "run-s build:*",
99
116
  "build:01-cjs": "tsc -p tsconfig.cjs.json",
@@ -112,25 +129,6 @@
112
129
  "clean:node_modules": "rimraf node_modules",
113
130
  "clean:types": "rimraf types",
114
131
  "lint": "eslint .",
115
- "postpack": "node ../../scripts/create-standard-exports.js",
116
- "prepack": "node ../../scripts/create-dist-exports.js",
117
132
  "test": "true"
118
- },
119
- "types": "./dist/cjs/index.d.ts",
120
- "dependencies": {
121
- "@chatbotkit/sdk": "workspace:*",
122
- "tslib": "^2.6.2",
123
- "zod": "^3.25.76",
124
- "zod-to-json-schema": "^3.24.6"
125
- },
126
- "devDependencies": {
127
- "npm-run-all": "^4.1.5",
128
- "typedoc": "^0.28.14",
129
- "typedoc-plugin-markdown": "^4.9.0",
130
- "typedoc-plugin-mdn-links": "^5.0.10",
131
- "typescript": "^5.9"
132
- },
133
- "files": [
134
- "dist/**"
135
- ]
136
- }
133
+ }
134
+ }