toolcraft 0.0.201 → 0.0.202

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/composition.json CHANGED
@@ -113,7 +113,7 @@
113
113
  },
114
114
  {
115
115
  "name": "toolcraft",
116
- "version": "0.0.201",
116
+ "version": "0.0.202",
117
117
  "license": "MIT"
118
118
  },
119
119
  {
@@ -123,7 +123,7 @@
123
123
  },
124
124
  {
125
125
  "name": "toolcraft-schema",
126
- "version": "0.0.201",
126
+ "version": "0.0.202",
127
127
  "license": "MIT"
128
128
  },
129
129
  {
@@ -113,7 +113,7 @@
113
113
  },
114
114
  {
115
115
  "name": "toolcraft",
116
- "version": "0.0.201",
116
+ "version": "0.0.202",
117
117
  "license": "MIT"
118
118
  },
119
119
  {
@@ -123,7 +123,7 @@
123
123
  },
124
124
  {
125
125
  "name": "toolcraft-schema",
126
- "version": "0.0.201",
126
+ "version": "0.0.202",
127
127
  "license": "MIT"
128
128
  },
129
129
  {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  {
10
10
  "name": "toolcraft-schema",
11
- "version": "0.0.201",
11
+ "version": "0.0.202",
12
12
  "license": "MIT"
13
13
  }
14
14
  ]
@@ -6,6 +6,7 @@ import { parseUriTemplate } from "./uri-template.js";
6
6
  import { toContentBlocks } from "./content/convert.js";
7
7
  import { ToolCallAdmission } from "./tool-call-admission.js";
8
8
  import { StdioOutput } from "./stdio-output.js";
9
+ import { StdioInput } from "./stdio-input.js";
9
10
  const PROTOCOL_VERSION = "2025-11-25";
10
11
  const SUPPORTED_PROTOCOL_VERSIONS = new Set(["2025-03-26", "2025-06-18", PROTOCOL_VERSION]);
11
12
  function compileToolSchema(schema) {
@@ -26,11 +27,13 @@ export function createServer(options) {
26
27
  const maxQueuedToolCalls = options.maxQueuedToolCalls ?? 64;
27
28
  const maxStdioOutputBytes = options.maxStdioOutputBytes ?? 1024 * 1024;
28
29
  const maxPendingStdioMessages = options.maxPendingStdioMessages ?? 128;
30
+ const maxStdioLineBytes = options.maxStdioLineBytes ?? 1024 * 1024;
29
31
  for (const [name, value, minimum] of [
30
32
  ["maxConcurrentToolCalls", maxConcurrentToolCalls, 1],
31
33
  ["maxQueuedToolCalls", maxQueuedToolCalls, 0],
32
34
  ["maxStdioOutputBytes", maxStdioOutputBytes, 1],
33
- ["maxPendingStdioMessages", maxPendingStdioMessages, 1]
35
+ ["maxPendingStdioMessages", maxPendingStdioMessages, 1],
36
+ ["maxStdioLineBytes", maxStdioLineBytes, 1]
34
37
  ]) {
35
38
  if (!Number.isSafeInteger(value) || value < minimum) {
36
39
  throw new Error(`${name} must be a safe integer greater than or equal to ${minimum}.`);
@@ -553,8 +556,9 @@ export function createServer(options) {
553
556
  const output = new StdioOutput(transport.writable, maxStdioOutputBytes, fail, finish);
554
557
  const listener = (notification) => output.write(`${JSON.stringify(notification)}\n`);
555
558
  const session = server.createMessageSession(listener);
559
+ const input = new StdioInput(maxStdioLineBytes);
556
560
  const rl = readline.createInterface({
557
- input: transport.readable,
561
+ input,
558
562
  crlfDelay: Infinity
559
563
  });
560
564
  function fail(error) {
@@ -563,6 +567,8 @@ export function createServer(options) {
563
567
  settled = true;
564
568
  session.close();
565
569
  rl.close();
570
+ transport.readable.unpipe(input);
571
+ input.destroy();
566
572
  transport.readable.pause();
567
573
  transport.readable.off("error", fail);
568
574
  output.abort(error);
@@ -574,11 +580,14 @@ export function createServer(options) {
574
580
  return;
575
581
  settled = true;
576
582
  session.close();
583
+ transport.readable.unpipe(input);
584
+ input.destroy();
577
585
  transport.readable.off("error", fail);
578
586
  output.close();
579
587
  resolve();
580
588
  }
581
589
  transport.readable.on("error", fail);
590
+ input.on("error", fail);
582
591
  rl.on("error", fail);
583
592
  rl.on("line", (line) => {
584
593
  if (settled)
@@ -599,6 +608,7 @@ export function createServer(options) {
599
608
  inputClosed = true;
600
609
  finish();
601
610
  });
611
+ transport.readable.pipe(input);
602
612
  });
603
613
  },
604
614
  async connectSDK(transport) {
@@ -0,0 +1,8 @@
1
+ import { Transform, type TransformCallback } from "node:stream";
2
+ export declare class StdioInput extends Transform {
3
+ private readonly maxLineBytes;
4
+ private lineBytes;
5
+ private trailingHighSurrogate;
6
+ constructor(maxLineBytes: number);
7
+ _transform(chunk: Buffer | string, _encoding: BufferEncoding, callback: TransformCallback): void;
8
+ }
@@ -0,0 +1,45 @@
1
+ import { Transform } from "node:stream";
2
+ export class StdioInput extends Transform {
3
+ maxLineBytes;
4
+ lineBytes = 0;
5
+ trailingHighSurrogate = false;
6
+ constructor(maxLineBytes) {
7
+ super({ decodeStrings: false, readableObjectMode: true });
8
+ this.maxLineBytes = maxLineBytes;
9
+ }
10
+ _transform(chunk, _encoding, callback) {
11
+ const text = typeof chunk === "string";
12
+ if (!text)
13
+ this.trailingHighSurrogate = false;
14
+ let start = 0;
15
+ for (let index = 0; index < chunk.length; index++) {
16
+ const unit = text ? chunk.charCodeAt(index) : chunk[index];
17
+ if (unit === 10 || unit === 13) {
18
+ this.lineBytes = 0;
19
+ this.trailingHighSurrogate = false;
20
+ this.push(text ? chunk.slice(start, index + 1) : chunk.subarray(start, index + 1));
21
+ start = index + 1;
22
+ if (this.destroyed) {
23
+ callback();
24
+ return;
25
+ }
26
+ continue;
27
+ }
28
+ if (text) {
29
+ const lowSurrogate = unit >= 0xdc00 && unit <= 0xdfff;
30
+ this.lineBytes += this.trailingHighSurrogate && lowSurrogate ? 1 : unit <= 0x7f ? 1 : unit <= 0x7ff ? 2 : 3;
31
+ this.trailingHighSurrogate = unit >= 0xd800 && unit <= 0xdbff;
32
+ }
33
+ else {
34
+ this.lineBytes++;
35
+ }
36
+ if (this.lineBytes > this.maxLineBytes) {
37
+ callback(new Error("Stdio input line byte limit exceeded"));
38
+ return;
39
+ }
40
+ }
41
+ if (start < chunk.length)
42
+ this.push(text ? chunk.slice(start) : chunk.subarray(start));
43
+ callback();
44
+ }
45
+ }
@@ -217,6 +217,7 @@ export interface ServerOptions {
217
217
  maxStdioOutputBytes?: number;
218
218
  /** Per-stdio-connection messages awaiting handler/output settlement; defaults to 128. */
219
219
  maxPendingStdioMessages?: number;
220
+ maxStdioLineBytes?: number;
220
221
  validateToolArguments?: boolean;
221
222
  supportNotifications?: boolean;
222
223
  supportResourceSubscriptions?: boolean;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft-schema",
3
- "version": "0.0.201",
3
+ "version": "0.0.202",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft",
3
- "version": "0.0.201",
3
+ "version": "0.0.202",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -158,7 +158,7 @@
158
158
  "yaml"
159
159
  ],
160
160
  "optionalDependencies": {
161
- "toolcraft-schema": "0.0.201",
161
+ "toolcraft-schema": "0.0.202",
162
162
  "toolcraft-design": "*",
163
163
  "@poe-code/frontmatter": "*",
164
164
  "@poe-code/agent-mcp-config": "*",