@pwrdrvr/agent-acp 0.12.0 → 0.12.2
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.js +47 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ function sanitizeAcpNotificationLine(line) {
|
|
|
22
22
|
if (!isPlainObject(params)) return line;
|
|
23
23
|
const update = params.update;
|
|
24
24
|
if (!isPlainObject(update)) return line;
|
|
25
|
+
if (update.sessionUpdate === "config_option_update") return "";
|
|
25
26
|
let changed = false;
|
|
26
27
|
for (const key of ["rawInput", "rawOutput"]) {
|
|
27
28
|
if (!(key in update)) continue;
|
|
@@ -48,19 +49,60 @@ function sanitizeInboundStream(source) {
|
|
|
48
49
|
while (nl !== -1) {
|
|
49
50
|
const line = buffer.slice(0, nl);
|
|
50
51
|
buffer = buffer.slice(nl + 1);
|
|
51
|
-
|
|
52
|
+
const sanitized = sanitizeAcpNotificationLine(line);
|
|
53
|
+
if (sanitized.length > 0) controller.enqueue(encoder.encode(sanitized + "\n"));
|
|
52
54
|
nl = buffer.indexOf("\n");
|
|
53
55
|
}
|
|
54
56
|
},
|
|
55
57
|
flush(controller) {
|
|
56
58
|
if (buffer.length > 0) {
|
|
57
|
-
|
|
59
|
+
const sanitized = sanitizeAcpNotificationLine(buffer);
|
|
60
|
+
if (sanitized.length > 0) controller.enqueue(encoder.encode(sanitized));
|
|
58
61
|
buffer = "";
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
})
|
|
62
65
|
);
|
|
63
66
|
}
|
|
67
|
+
function rewriteOutboundAcpLine(line) {
|
|
68
|
+
if (line.trim().length === 0) return line;
|
|
69
|
+
let message;
|
|
70
|
+
try {
|
|
71
|
+
message = JSON.parse(line);
|
|
72
|
+
} catch {
|
|
73
|
+
return line;
|
|
74
|
+
}
|
|
75
|
+
if (!isPlainObject(message) || message.method !== "_session/set_config_option") {
|
|
76
|
+
return line;
|
|
77
|
+
}
|
|
78
|
+
message.method = "session/set_config_option";
|
|
79
|
+
return JSON.stringify(message);
|
|
80
|
+
}
|
|
81
|
+
function rewriteOutboundStream(target) {
|
|
82
|
+
const decoder = new TextDecoder();
|
|
83
|
+
const encoder = new TextEncoder();
|
|
84
|
+
let buffer = "";
|
|
85
|
+
const transform = new TransformStream({
|
|
86
|
+
transform(chunk, controller) {
|
|
87
|
+
buffer += decoder.decode(chunk, { stream: true });
|
|
88
|
+
let nl = buffer.indexOf("\n");
|
|
89
|
+
while (nl !== -1) {
|
|
90
|
+
const line = buffer.slice(0, nl);
|
|
91
|
+
buffer = buffer.slice(nl + 1);
|
|
92
|
+
controller.enqueue(encoder.encode(rewriteOutboundAcpLine(line) + "\n"));
|
|
93
|
+
nl = buffer.indexOf("\n");
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
flush(controller) {
|
|
97
|
+
if (buffer.length > 0) {
|
|
98
|
+
controller.enqueue(encoder.encode(rewriteOutboundAcpLine(buffer)));
|
|
99
|
+
buffer = "";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
void transform.readable.pipeTo(target).catch(() => void 0);
|
|
104
|
+
return transform.writable;
|
|
105
|
+
}
|
|
64
106
|
var AcpConnection = class {
|
|
65
107
|
constructor(options) {
|
|
66
108
|
this.options = options;
|
|
@@ -130,7 +172,9 @@ var AcpConnection = class {
|
|
|
130
172
|
const line = chunk.toString("utf8").trimEnd();
|
|
131
173
|
if (line.length > 0) logger.debug("acp agent stderr", { line });
|
|
132
174
|
});
|
|
133
|
-
const toAgentStdin =
|
|
175
|
+
const toAgentStdin = rewriteOutboundStream(
|
|
176
|
+
Writable.toWeb(child.stdin)
|
|
177
|
+
);
|
|
134
178
|
const fromAgentStdout = sanitizeInboundStream(
|
|
135
179
|
Readable.toWeb(child.stdout)
|
|
136
180
|
);
|