@wrongstack/acp 0.287.0 → 0.289.0
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/agent/wrongstack-acp-agent.d.ts +7 -0
- package/dist/agent/wrongstack-acp-agent.d.ts.map +1 -1
- package/dist/agent.js +62 -18
- package/dist/agent.js.map +2 -2
- package/dist/client/acp-session.d.ts +17 -0
- package/dist/client/acp-session.d.ts.map +1 -1
- package/dist/client/file-server.d.ts +27 -5
- package/dist/client/file-server.d.ts.map +1 -1
- package/dist/client/terminal-server.d.ts +15 -0
- package/dist/client/terminal-server.d.ts.map +1 -1
- package/dist/client.js +189 -25
- package/dist/client.js.map +3 -3
- package/dist/index.js +279 -44
- package/dist/index.js.map +3 -3
- package/dist/integration/acp-subagent-runner.d.ts.map +1 -1
- package/dist/registry/acp-registry-fetch.d.ts.map +1 -1
- package/dist/registry/agents.catalog.d.ts.map +1 -1
- package/dist/registry/ensemble-registry.d.ts +1 -1
- package/dist/registry/ensemble-registry.d.ts.map +1 -1
- package/dist/sdk.js +278 -44
- package/dist/sdk.js.map +3 -3
- package/dist/wrongstack-acp-agent.js +62 -18
- package/dist/wrongstack-acp-agent.js.map +2 -2
- package/package.json +2 -2
|
@@ -833,7 +833,21 @@ var WrongStackACPServer = class {
|
|
|
833
833
|
async startHttp(port) {
|
|
834
834
|
const host = this.options.host ?? "127.0.0.1";
|
|
835
835
|
const handler = this.handler;
|
|
836
|
+
const authToken = this.options.authToken;
|
|
837
|
+
let httpChain = Promise.resolve();
|
|
836
838
|
this.httpServer = createServer(async (req, res) => {
|
|
839
|
+
if (authToken) {
|
|
840
|
+
const url = new URL(req.url ?? "/", `http://${host}:${port}`);
|
|
841
|
+
const queryToken = url.searchParams.get("token");
|
|
842
|
+
const authHeader = req.headers["authorization"];
|
|
843
|
+
const bearerToken = Array.isArray(authHeader) ? authHeader[0]?.replace(/^Bearer\s+/i, "") : authHeader?.replace(/^Bearer\s+/i, "");
|
|
844
|
+
const supplied = queryToken ?? bearerToken ?? "";
|
|
845
|
+
if (supplied !== authToken) {
|
|
846
|
+
res.writeHead(401, { "Content-Type": "application/json" });
|
|
847
|
+
res.end(JSON.stringify({ error: { code: -32001, message: "Unauthorized" } }));
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
837
851
|
const selfOrigin = `http://${host}:${port}`;
|
|
838
852
|
const reqOrigin = Array.isArray(req.headers.origin) ? req.headers.origin[0] : req.headers.origin;
|
|
839
853
|
if (reqOrigin && reqOrigin !== selfOrigin) {
|
|
@@ -843,7 +857,7 @@ var WrongStackACPServer = class {
|
|
|
843
857
|
}
|
|
844
858
|
if (reqOrigin) res.setHeader("Access-Control-Allow-Origin", reqOrigin);
|
|
845
859
|
res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
|
|
846
|
-
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Mcp-Session-Id");
|
|
860
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Mcp-Session-Id, Authorization");
|
|
847
861
|
if (req.method === "OPTIONS") {
|
|
848
862
|
res.writeHead(204);
|
|
849
863
|
res.end();
|
|
@@ -854,10 +868,23 @@ var WrongStackACPServer = class {
|
|
|
854
868
|
res.end(JSON.stringify({ error: "method not allowed" }));
|
|
855
869
|
return;
|
|
856
870
|
}
|
|
871
|
+
const MAX_HTTP_BODY = 10 * 1024 * 1024;
|
|
857
872
|
let body = "";
|
|
873
|
+
let bodyBytes = 0;
|
|
874
|
+
let tooLarge = false;
|
|
858
875
|
for await (const chunk of req) {
|
|
876
|
+
bodyBytes += chunk.length;
|
|
877
|
+
if (bodyBytes > MAX_HTTP_BODY) {
|
|
878
|
+
tooLarge = true;
|
|
879
|
+
break;
|
|
880
|
+
}
|
|
859
881
|
body += chunk;
|
|
860
882
|
}
|
|
883
|
+
if (tooLarge) {
|
|
884
|
+
res.writeHead(413, { "Content-Type": "application/json" });
|
|
885
|
+
res.end(JSON.stringify({ error: { code: -32700, message: "Request body too large" } }));
|
|
886
|
+
return;
|
|
887
|
+
}
|
|
861
888
|
let msg;
|
|
862
889
|
try {
|
|
863
890
|
msg = JSON.parse(body);
|
|
@@ -866,26 +893,43 @@ var WrongStackACPServer = class {
|
|
|
866
893
|
res.end(JSON.stringify({ error: { code: -32700, message: "Parse error" } }));
|
|
867
894
|
return;
|
|
868
895
|
}
|
|
869
|
-
const
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
response = m;
|
|
875
|
-
} else if (m.method === "session/update") {
|
|
876
|
-
notifications.push(m.params);
|
|
877
|
-
} else {
|
|
878
|
-
notifications.push(m);
|
|
896
|
+
const isNotification = typeof msg === "object" && msg !== null && msg.id === void 0 && typeof msg.method === "string";
|
|
897
|
+
if (isNotification) {
|
|
898
|
+
try {
|
|
899
|
+
await handler.handleMessage(msg);
|
|
900
|
+
} catch {
|
|
879
901
|
}
|
|
880
|
-
|
|
902
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
903
|
+
res.end(JSON.stringify({ notifications: [] }));
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
const requestPromise = httpChain.then(async () => {
|
|
907
|
+
const notifications = [];
|
|
908
|
+
let response = null;
|
|
909
|
+
const originalSend = this.transport.send.bind(this.transport);
|
|
910
|
+
this.transport.send = async (m) => {
|
|
911
|
+
if (m.id !== void 0 && (m.result !== void 0 || m.error !== void 0)) {
|
|
912
|
+
response = m;
|
|
913
|
+
} else if (m.method === "session/update") {
|
|
914
|
+
notifications.push(m.params);
|
|
915
|
+
} else {
|
|
916
|
+
notifications.push(m);
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
try {
|
|
920
|
+
await handler.handleMessage(msg);
|
|
921
|
+
} finally {
|
|
922
|
+
this.transport.send = originalSend;
|
|
923
|
+
}
|
|
924
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
925
|
+
const responseBody = response !== null ? { ...response, notifications } : { notifications };
|
|
926
|
+
res.end(JSON.stringify(responseBody));
|
|
927
|
+
});
|
|
928
|
+
httpChain = requestPromise.catch(() => void 0);
|
|
881
929
|
try {
|
|
882
|
-
await
|
|
883
|
-
}
|
|
884
|
-
this.transport.send = originalSend;
|
|
930
|
+
await requestPromise;
|
|
931
|
+
} catch {
|
|
885
932
|
}
|
|
886
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
887
|
-
const responseBody = response !== null ? { ...response, notifications } : { notifications };
|
|
888
|
-
res.end(JSON.stringify(responseBody));
|
|
889
933
|
});
|
|
890
934
|
return new Promise((resolve) => {
|
|
891
935
|
this.httpServer.listen(port, host, () => {
|