@pwrdrvr/agent-acp 0.12.0 → 0.12.1
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 +42 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -61,6 +61,45 @@ function sanitizeInboundStream(source) {
|
|
|
61
61
|
})
|
|
62
62
|
);
|
|
63
63
|
}
|
|
64
|
+
function rewriteOutboundAcpLine(line) {
|
|
65
|
+
if (line.trim().length === 0) return line;
|
|
66
|
+
let message;
|
|
67
|
+
try {
|
|
68
|
+
message = JSON.parse(line);
|
|
69
|
+
} catch {
|
|
70
|
+
return line;
|
|
71
|
+
}
|
|
72
|
+
if (!isPlainObject(message) || message.method !== "_session/set_config_option") {
|
|
73
|
+
return line;
|
|
74
|
+
}
|
|
75
|
+
message.method = "session/set_config_option";
|
|
76
|
+
return JSON.stringify(message);
|
|
77
|
+
}
|
|
78
|
+
function rewriteOutboundStream(target) {
|
|
79
|
+
const decoder = new TextDecoder();
|
|
80
|
+
const encoder = new TextEncoder();
|
|
81
|
+
let buffer = "";
|
|
82
|
+
const transform = new TransformStream({
|
|
83
|
+
transform(chunk, controller) {
|
|
84
|
+
buffer += decoder.decode(chunk, { stream: true });
|
|
85
|
+
let nl = buffer.indexOf("\n");
|
|
86
|
+
while (nl !== -1) {
|
|
87
|
+
const line = buffer.slice(0, nl);
|
|
88
|
+
buffer = buffer.slice(nl + 1);
|
|
89
|
+
controller.enqueue(encoder.encode(rewriteOutboundAcpLine(line) + "\n"));
|
|
90
|
+
nl = buffer.indexOf("\n");
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
flush(controller) {
|
|
94
|
+
if (buffer.length > 0) {
|
|
95
|
+
controller.enqueue(encoder.encode(rewriteOutboundAcpLine(buffer)));
|
|
96
|
+
buffer = "";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
void transform.readable.pipeTo(target).catch(() => void 0);
|
|
101
|
+
return transform.writable;
|
|
102
|
+
}
|
|
64
103
|
var AcpConnection = class {
|
|
65
104
|
constructor(options) {
|
|
66
105
|
this.options = options;
|
|
@@ -130,7 +169,9 @@ var AcpConnection = class {
|
|
|
130
169
|
const line = chunk.toString("utf8").trimEnd();
|
|
131
170
|
if (line.length > 0) logger.debug("acp agent stderr", { line });
|
|
132
171
|
});
|
|
133
|
-
const toAgentStdin =
|
|
172
|
+
const toAgentStdin = rewriteOutboundStream(
|
|
173
|
+
Writable.toWeb(child.stdin)
|
|
174
|
+
);
|
|
134
175
|
const fromAgentStdout = sanitizeInboundStream(
|
|
135
176
|
Readable.toWeb(child.stdout)
|
|
136
177
|
);
|