acp-websocket-transport 0.1.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/examples/client.d.ts +9 -0
- package/dist/examples/client.d.ts.map +1 -0
- package/dist/examples/client.js +51 -0
- package/dist/examples/client.js.map +1 -0
- package/dist/examples/echo-agent.d.ts +14 -0
- package/dist/examples/echo-agent.d.ts.map +1 -0
- package/dist/examples/echo-agent.js +67 -0
- package/dist/examples/echo-agent.js.map +1 -0
- package/dist/examples/server.d.ts +11 -0
- package/dist/examples/server.d.ts.map +1 -0
- package/dist/examples/server.js +36 -0
- package/dist/examples/server.js.map +1 -0
- package/dist/src/auth.d.ts +110 -0
- package/dist/src/auth.d.ts.map +1 -0
- package/dist/src/auth.js +135 -0
- package/dist/src/auth.js.map +1 -0
- package/dist/src/client.d.ts +109 -0
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/client.js +125 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/index.d.ts +58 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +59 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/server.d.ts +117 -0
- package/dist/src/server.d.ts.map +1 -0
- package/dist/src/server.js +203 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/transport.d.ts +24 -0
- package/dist/src/transport.d.ts.map +1 -0
- package/dist/src/transport.js +120 -0
- package/dist/src/transport.js.map +1 -0
- package/dist/tests/auth.test.d.ts +2 -0
- package/dist/tests/auth.test.d.ts.map +1 -0
- package/dist/tests/auth.test.js +115 -0
- package/dist/tests/auth.test.js.map +1 -0
- package/dist/tests/client.test.d.ts +2 -0
- package/dist/tests/client.test.d.ts.map +1 -0
- package/dist/tests/client.test.js +121 -0
- package/dist/tests/client.test.js.map +1 -0
- package/dist/tests/e2e.test.d.ts +8 -0
- package/dist/tests/e2e.test.d.ts.map +1 -0
- package/dist/tests/e2e.test.js +130 -0
- package/dist/tests/e2e.test.js.map +1 -0
- package/dist/tests/server.test.d.ts +2 -0
- package/dist/tests/server.test.d.ts.map +1 -0
- package/dist/tests/server.test.js +173 -0
- package/dist/tests/server.test.js.map +1 -0
- package/dist/tests/transport.test.d.ts +2 -0
- package/dist/tests/transport.test.d.ts.map +1 -0
- package/dist/tests/transport.test.js +137 -0
- package/dist/tests/transport.test.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../examples/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: connect to the ACP WebSocket server with the client library.
|
|
3
|
+
*
|
|
4
|
+
* Usage (start the server first):
|
|
5
|
+
* node dist/examples/server.js
|
|
6
|
+
* node dist/examples/client.js
|
|
7
|
+
*/
|
|
8
|
+
import { createClientConnection } from "../src/index.js";
|
|
9
|
+
const { connection, close } = await createClientConnection("ws://localhost:3000", {
|
|
10
|
+
// Optional: supply auth credentials
|
|
11
|
+
// ...withBearerToken("my-secret-token"),
|
|
12
|
+
toClient: (_agent) => ({
|
|
13
|
+
sessionUpdate: async (params) => {
|
|
14
|
+
const { update } = params;
|
|
15
|
+
if ("content" in update &&
|
|
16
|
+
update.content != null &&
|
|
17
|
+
!Array.isArray(update.content) &&
|
|
18
|
+
update.content.type === "text" &&
|
|
19
|
+
"text" in update.content) {
|
|
20
|
+
console.log(`[agent] ${update.content.text}`);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
requestPermission: async () => ({
|
|
24
|
+
outcome: "allow_once",
|
|
25
|
+
}),
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
// ── ACP handshake ─────────────────────────────────────────────────────────────
|
|
29
|
+
const initResult = await connection.initialize({
|
|
30
|
+
protocolVersion: 0,
|
|
31
|
+
clientInfo: { name: "example-client", version: "0.1.0" },
|
|
32
|
+
clientCapabilities: {},
|
|
33
|
+
});
|
|
34
|
+
console.log(`Connected to agent: ${initResult.agentInfo?.name} v${initResult.agentInfo?.version}`);
|
|
35
|
+
// ── Create a session ──────────────────────────────────────────────────────────
|
|
36
|
+
const session = await connection.newSession({
|
|
37
|
+
cwd: process.cwd(),
|
|
38
|
+
mcpServers: [],
|
|
39
|
+
});
|
|
40
|
+
console.log(`Session created: ${session.sessionId}`);
|
|
41
|
+
// ── Send a prompt ─────────────────────────────────────────────────────────────
|
|
42
|
+
console.log(`Sending prompt…`);
|
|
43
|
+
const result = await connection.prompt({
|
|
44
|
+
sessionId: session.sessionId,
|
|
45
|
+
prompt: [{ type: "text", text: "Hello from the example client!" }],
|
|
46
|
+
});
|
|
47
|
+
console.log(`Turn ended with stopReason: ${result.stopReason}`);
|
|
48
|
+
// ── Cleanup ───────────────────────────────────────────────────────────────────
|
|
49
|
+
close();
|
|
50
|
+
console.log("Connection closed.");
|
|
51
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../examples/client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAGzD,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,MAAM,sBAAsB,CACxD,qBAAqB,EACrB;IACE,oCAAoC;IACpC,yCAAyC;IAEzC,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACrB,aAAa,EAAE,KAAK,EAAE,MAA2B,EAAE,EAAE;YACnD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;YAC1B,IACE,SAAS,IAAI,MAAM;gBACnB,MAAM,CAAC,OAAO,IAAI,IAAI;gBACtB,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;gBAC9B,MAAM,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM;gBAC9B,MAAM,IAAI,MAAM,C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CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal ACP echo agent for testing and examples.
|
|
3
|
+
*
|
|
4
|
+
* Communicates over stdio using the ndJsonStream transport (newline-delimited JSON).
|
|
5
|
+
* Responds to `session/prompt` requests by echoing the last text block back to the
|
|
6
|
+
* client prefixed with "Echo: ".
|
|
7
|
+
*
|
|
8
|
+
* Usage (as a standalone process):
|
|
9
|
+
* node dist/examples/echo-agent.js
|
|
10
|
+
*
|
|
11
|
+
* The WebSocketACPServer example starts this as a subprocess for each connection.
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=echo-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"echo-agent.d.ts","sourceRoot":"","sources":["../../examples/echo-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal ACP echo agent for testing and examples.
|
|
3
|
+
*
|
|
4
|
+
* Communicates over stdio using the ndJsonStream transport (newline-delimited JSON).
|
|
5
|
+
* Responds to `session/prompt` requests by echoing the last text block back to the
|
|
6
|
+
* client prefixed with "Echo: ".
|
|
7
|
+
*
|
|
8
|
+
* Usage (as a standalone process):
|
|
9
|
+
* node dist/examples/echo-agent.js
|
|
10
|
+
*
|
|
11
|
+
* The WebSocketACPServer example starts this as a subprocess for each connection.
|
|
12
|
+
*/
|
|
13
|
+
import { Readable, Writable } from "node:stream";
|
|
14
|
+
import { AgentSideConnection, ndJsonStream } from "@agentclientprotocol/sdk";
|
|
15
|
+
// ─── stdio stream setup ───────────────────────────────────────────────────────
|
|
16
|
+
// Use the static Readable.toWeb / Writable.toWeb methods (Node.js 17+)
|
|
17
|
+
const stdinReadable = Readable.toWeb(process.stdin);
|
|
18
|
+
const stdoutWritable = Writable.toWeb(process.stdout);
|
|
19
|
+
const stream = ndJsonStream(stdoutWritable, stdinReadable);
|
|
20
|
+
// ─── Agent implementation ─────────────────────────────────────────────────────
|
|
21
|
+
const _connection = new AgentSideConnection((conn) => ({
|
|
22
|
+
initialize(params) {
|
|
23
|
+
return Promise.resolve({
|
|
24
|
+
protocolVersion: params.protocolVersion,
|
|
25
|
+
agentInfo: {
|
|
26
|
+
name: "echo-agent",
|
|
27
|
+
version: "0.1.0",
|
|
28
|
+
},
|
|
29
|
+
agentCapabilities: {},
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
newSession(_params) {
|
|
33
|
+
return Promise.resolve({
|
|
34
|
+
sessionId: crypto.randomUUID(),
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
authenticate(_params) {
|
|
38
|
+
// No authentication required by this agent
|
|
39
|
+
return Promise.resolve();
|
|
40
|
+
},
|
|
41
|
+
cancel(_params) {
|
|
42
|
+
// No ongoing work to cancel in this simple echo agent
|
|
43
|
+
return Promise.resolve();
|
|
44
|
+
},
|
|
45
|
+
async prompt(params) {
|
|
46
|
+
// Find the last text block in the prompt and echo it
|
|
47
|
+
const textBlock = [...params.prompt]
|
|
48
|
+
.reverse()
|
|
49
|
+
.find((block) => block.type === "text");
|
|
50
|
+
const inputText = textBlock?.text ?? "(no text)";
|
|
51
|
+
// Send a session update notification with the echoed text
|
|
52
|
+
await conn.sessionUpdate({
|
|
53
|
+
sessionId: params.sessionId,
|
|
54
|
+
update: {
|
|
55
|
+
sessionUpdate: "agent_message_chunk",
|
|
56
|
+
content: {
|
|
57
|
+
type: "text",
|
|
58
|
+
text: `Echo: ${inputText}`,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
return { stopReason: "end_turn" };
|
|
63
|
+
},
|
|
64
|
+
}), stream);
|
|
65
|
+
// Keep the process alive until the connection stream closes
|
|
66
|
+
// (AgentSideConnection manages the stream lifecycle internally)
|
|
67
|
+
//# sourceMappingURL=echo-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|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C;aACjC,OAAO,EAAE;aACT,IAAI,CACH,CAAC,KAAK,EAAsE,EAAE,CAC5E,KAAK,CAAC,IAAI,KAAK,MAAM,CACxB,CAAC;QAEJ,MAAM,SAAS,GAAG,SAAS,EAAE,IAAI,IAAI,WAAW,CAAC;QAEjD,0DAA0D;QAC1D,MAAM,IAAI,CAAC,aAAa,CAAC;YACvB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,MAAM,EAAE;gBACN,aAAa,EAAE,qBAAqB;gBACpC,OAAO,EAAE;oBACP,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,SAAS,SAAS,EAAE;iBAC3B;aACF;SACF,CAAC,CAAC;QAEH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC;IACpC,CAAC;CACF,CAAC,EACF,MAAM,CACP,CAAC;AAEF,4DAA4D;AAC5D,gEAAgE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../examples/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: start the ACP WebSocket server.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* node dist/examples/server.js
|
|
6
|
+
*
|
|
7
|
+
* Then run the client example in a separate terminal:
|
|
8
|
+
* node dist/examples/client.js
|
|
9
|
+
*/
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
import { WebSocketACPServer } from "../src/index.js";
|
|
13
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const echoAgentPath = join(__dirname, "echo-agent.js");
|
|
15
|
+
const server = new WebSocketACPServer({
|
|
16
|
+
port: 3000,
|
|
17
|
+
command: "node",
|
|
18
|
+
args: [echoAgentPath],
|
|
19
|
+
// Optional: enable bearer token authentication
|
|
20
|
+
// verifyClient: bearerAuth(["my-secret-token"]),
|
|
21
|
+
onError: (err, ctx) => {
|
|
22
|
+
console.error(`[server error / ${ctx}]`, err.message);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
await server.listening();
|
|
26
|
+
console.log(`ACP WebSocket server listening on ws://localhost:3000`);
|
|
27
|
+
console.log("Press Ctrl-C to stop.");
|
|
28
|
+
// Graceful shutdown
|
|
29
|
+
for (const signal of ["SIGTERM", "SIGINT"]) {
|
|
30
|
+
process.once(signal, async () => {
|
|
31
|
+
console.log(`\nReceived ${signal} — shutting down…`);
|
|
32
|
+
await server.close();
|
|
33
|
+
process.exit(0);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../examples/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAc,MAAM,iBAAiB,CAAC;AAEjE,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC1D,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;AAEvD,MAAM,MAAM,GAAG,IAAI,kBAAkB,CAAC;IACpC,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,MAAM;IACf,IAAI,EAAE,CAAC,aAAa,CAAC;IAErB,+CAA+C;IAC/C,iDAAiD;IAEjD,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACpB,OAAO,CAAC,KAAK,CAAC,mBAAmB,GAAG,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACxD,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,MAAM,CAAC,SAAS,EAAE,CAAC;AACzB,OAAO,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;AACrE,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAErC,oBAAoB;AACpB,KAAK,MAAM,MAAM,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAU,EAAE,CAAC;IACpD,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE;QAC9B,OAAO,CAAC,GAAG,CAAC,cAAc,MAAM,mBAAmB,CAAC,CAAC;QACrD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication helpers for the ACP WebSocket server.
|
|
3
|
+
*
|
|
4
|
+
* WebSocket connections begin with an HTTP Upgrade request, so standard HTTP
|
|
5
|
+
* authentication mechanisms (Bearer token, Basic auth, API key headers) can be
|
|
6
|
+
* applied directly at the handshake stage — before the WebSocket is established.
|
|
7
|
+
*
|
|
8
|
+
* The `ws` library exposes a `verifyClient` callback that receives the HTTP
|
|
9
|
+
* Upgrade request and can accept or reject the connection. This module provides
|
|
10
|
+
* the {@link VerifyClientFn} type and a set of built-in factory functions for
|
|
11
|
+
* common authentication schemes.
|
|
12
|
+
*
|
|
13
|
+
* @example Bearer token
|
|
14
|
+
* ```ts
|
|
15
|
+
* const server = new WebSocketACPServer({
|
|
16
|
+
* port: 3000,
|
|
17
|
+
* command: "my-agent",
|
|
18
|
+
* verifyClient: bearerAuth(["secret-token-alice", "secret-token-bob"]),
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example Custom async validator (e.g. database lookup)
|
|
23
|
+
* ```ts
|
|
24
|
+
* const server = new WebSocketACPServer({
|
|
25
|
+
* port: 3000,
|
|
26
|
+
* command: "my-agent",
|
|
27
|
+
* verifyClient: async ({ req }) => {
|
|
28
|
+
* const token = req.headers["authorization"]?.split(" ")[1] ?? "";
|
|
29
|
+
* return await db.tokens.isValid(token);
|
|
30
|
+
* },
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
import type { IncomingMessage } from "node:http";
|
|
35
|
+
/**
|
|
36
|
+
* Information about the incoming WebSocket upgrade request,
|
|
37
|
+
* as provided by the `ws` library's `verifyClient` callback.
|
|
38
|
+
*/
|
|
39
|
+
export interface VerifyClientInfo {
|
|
40
|
+
/** The raw Node.js HTTP request for the WebSocket upgrade */
|
|
41
|
+
req: IncomingMessage;
|
|
42
|
+
/** Value of the `Origin` header, or an empty string if absent */
|
|
43
|
+
origin: string;
|
|
44
|
+
/** Whether the connection was made over TLS (i.e. `wss://`) */
|
|
45
|
+
secure: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Authentication callback for the WebSocket server.
|
|
49
|
+
*
|
|
50
|
+
* Return (or resolve) `true` to allow the connection, `false` to reject it
|
|
51
|
+
* with HTTP 401 Unauthorized. Rejecting with a custom status code is possible
|
|
52
|
+
* via the lower-level `ws` `verifyClient` API; this interface keeps things simple.
|
|
53
|
+
*
|
|
54
|
+
* May be synchronous or asynchronous.
|
|
55
|
+
*/
|
|
56
|
+
export type VerifyClientFn = (info: VerifyClientInfo) => boolean | Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Bearer token authentication.
|
|
59
|
+
*
|
|
60
|
+
* Accepts connections whose `Authorization` header matches
|
|
61
|
+
* `Bearer <token>` for any token in `validTokens`.
|
|
62
|
+
*
|
|
63
|
+
* @param validTokens - Iterable of accepted token strings
|
|
64
|
+
*/
|
|
65
|
+
export declare function bearerAuth(validTokens: Iterable<string>): VerifyClientFn;
|
|
66
|
+
/**
|
|
67
|
+
* HTTP Basic authentication.
|
|
68
|
+
*
|
|
69
|
+
* Accepts connections whose `Authorization: Basic <base64(user:pass)>` header
|
|
70
|
+
* matches an entry in `credentials`.
|
|
71
|
+
*
|
|
72
|
+
* ⚠️ Always use TLS (`wss://`) in production — Basic auth credentials are only
|
|
73
|
+
* base64-encoded, not encrypted.
|
|
74
|
+
*
|
|
75
|
+
* @param credentials - Map of `{ username: password }`
|
|
76
|
+
*/
|
|
77
|
+
export declare function basicAuth(credentials: Record<string, string>): VerifyClientFn;
|
|
78
|
+
/**
|
|
79
|
+
* API key authentication via an arbitrary HTTP header.
|
|
80
|
+
*
|
|
81
|
+
* Accepts connections that include a matching `<header>: <key>` in their
|
|
82
|
+
* upgrade request. Header name matching is case-insensitive (HTTP spec).
|
|
83
|
+
*
|
|
84
|
+
* @param header - Header name (e.g. `"x-api-key"`)
|
|
85
|
+
* @param validKeys - Iterable of accepted key strings
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* verifyClient: apiKeyAuth("x-api-key", ["key1", "key2"])
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function apiKeyAuth(header: string, validKeys: Iterable<string>): VerifyClientFn;
|
|
93
|
+
/**
|
|
94
|
+
* Combines multiple {@link VerifyClientFn}s with OR semantics.
|
|
95
|
+
*
|
|
96
|
+
* The connection is accepted if **any** of the provided verifiers returns `true`.
|
|
97
|
+
* Useful when the server supports multiple authentication methods simultaneously.
|
|
98
|
+
*
|
|
99
|
+
* @param verifiers - One or more VerifyClientFn instances
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* verifyClient: anyAuth(
|
|
104
|
+
* bearerAuth(["service-token"]),
|
|
105
|
+
* apiKeyAuth("x-api-key", ["ui-key"]),
|
|
106
|
+
* )
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export declare function anyAuth(...verifiers: VerifyClientFn[]): VerifyClientFn;
|
|
110
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAIjD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,6DAA6D;IAC7D,GAAG,EAAE,eAAe,CAAC;IACrB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,GAAG,CAC3B,IAAI,EAAE,gBAAgB,KACnB,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAIhC;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,cAAc,CAUxE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CACvB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,cAAc,CAgBhB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,GAC1B,cAAc,CAQhB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,GAAG,SAAS,EAAE,cAAc,EAAE,GAAG,cAAc,CAOtE"}
|
package/dist/src/auth.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication helpers for the ACP WebSocket server.
|
|
3
|
+
*
|
|
4
|
+
* WebSocket connections begin with an HTTP Upgrade request, so standard HTTP
|
|
5
|
+
* authentication mechanisms (Bearer token, Basic auth, API key headers) can be
|
|
6
|
+
* applied directly at the handshake stage — before the WebSocket is established.
|
|
7
|
+
*
|
|
8
|
+
* The `ws` library exposes a `verifyClient` callback that receives the HTTP
|
|
9
|
+
* Upgrade request and can accept or reject the connection. This module provides
|
|
10
|
+
* the {@link VerifyClientFn} type and a set of built-in factory functions for
|
|
11
|
+
* common authentication schemes.
|
|
12
|
+
*
|
|
13
|
+
* @example Bearer token
|
|
14
|
+
* ```ts
|
|
15
|
+
* const server = new WebSocketACPServer({
|
|
16
|
+
* port: 3000,
|
|
17
|
+
* command: "my-agent",
|
|
18
|
+
* verifyClient: bearerAuth(["secret-token-alice", "secret-token-bob"]),
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example Custom async validator (e.g. database lookup)
|
|
23
|
+
* ```ts
|
|
24
|
+
* const server = new WebSocketACPServer({
|
|
25
|
+
* port: 3000,
|
|
26
|
+
* command: "my-agent",
|
|
27
|
+
* verifyClient: async ({ req }) => {
|
|
28
|
+
* const token = req.headers["authorization"]?.split(" ")[1] ?? "";
|
|
29
|
+
* return await db.tokens.isValid(token);
|
|
30
|
+
* },
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
// ─── Built-in helpers ─────────────────────────────────────────────────────────
|
|
35
|
+
/**
|
|
36
|
+
* Bearer token authentication.
|
|
37
|
+
*
|
|
38
|
+
* Accepts connections whose `Authorization` header matches
|
|
39
|
+
* `Bearer <token>` for any token in `validTokens`.
|
|
40
|
+
*
|
|
41
|
+
* @param validTokens - Iterable of accepted token strings
|
|
42
|
+
*/
|
|
43
|
+
export function bearerAuth(validTokens) {
|
|
44
|
+
const tokens = new Set(validTokens);
|
|
45
|
+
return ({ req }) => {
|
|
46
|
+
const auth = req.headers["authorization"] ?? "";
|
|
47
|
+
const spaceIdx = auth.indexOf(" ");
|
|
48
|
+
if (spaceIdx === -1)
|
|
49
|
+
return false;
|
|
50
|
+
const scheme = auth.slice(0, spaceIdx).toLowerCase();
|
|
51
|
+
const token = auth.slice(spaceIdx + 1);
|
|
52
|
+
return scheme === "bearer" && tokens.has(token);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* HTTP Basic authentication.
|
|
57
|
+
*
|
|
58
|
+
* Accepts connections whose `Authorization: Basic <base64(user:pass)>` header
|
|
59
|
+
* matches an entry in `credentials`.
|
|
60
|
+
*
|
|
61
|
+
* ⚠️ Always use TLS (`wss://`) in production — Basic auth credentials are only
|
|
62
|
+
* base64-encoded, not encrypted.
|
|
63
|
+
*
|
|
64
|
+
* @param credentials - Map of `{ username: password }`
|
|
65
|
+
*/
|
|
66
|
+
export function basicAuth(credentials) {
|
|
67
|
+
return ({ req }) => {
|
|
68
|
+
const auth = req.headers["authorization"] ?? "";
|
|
69
|
+
const spaceIdx = auth.indexOf(" ");
|
|
70
|
+
if (spaceIdx === -1)
|
|
71
|
+
return false;
|
|
72
|
+
const scheme = auth.slice(0, spaceIdx).toLowerCase();
|
|
73
|
+
if (scheme !== "basic")
|
|
74
|
+
return false;
|
|
75
|
+
const encoded = auth.slice(spaceIdx + 1);
|
|
76
|
+
const decoded = Buffer.from(encoded, "base64").toString("utf8");
|
|
77
|
+
const colonIdx = decoded.indexOf(":");
|
|
78
|
+
if (colonIdx === -1)
|
|
79
|
+
return false;
|
|
80
|
+
const user = decoded.slice(0, colonIdx);
|
|
81
|
+
const pass = decoded.slice(colonIdx + 1);
|
|
82
|
+
return Object.prototype.hasOwnProperty.call(credentials, user) &&
|
|
83
|
+
credentials[user] === pass;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* API key authentication via an arbitrary HTTP header.
|
|
88
|
+
*
|
|
89
|
+
* Accepts connections that include a matching `<header>: <key>` in their
|
|
90
|
+
* upgrade request. Header name matching is case-insensitive (HTTP spec).
|
|
91
|
+
*
|
|
92
|
+
* @param header - Header name (e.g. `"x-api-key"`)
|
|
93
|
+
* @param validKeys - Iterable of accepted key strings
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* verifyClient: apiKeyAuth("x-api-key", ["key1", "key2"])
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export function apiKeyAuth(header, validKeys) {
|
|
101
|
+
const keys = new Set(validKeys);
|
|
102
|
+
const normalizedHeader = header.toLowerCase();
|
|
103
|
+
return ({ req }) => {
|
|
104
|
+
const value = req.headers[normalizedHeader];
|
|
105
|
+
if (typeof value !== "string")
|
|
106
|
+
return false;
|
|
107
|
+
return keys.has(value);
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Combines multiple {@link VerifyClientFn}s with OR semantics.
|
|
112
|
+
*
|
|
113
|
+
* The connection is accepted if **any** of the provided verifiers returns `true`.
|
|
114
|
+
* Useful when the server supports multiple authentication methods simultaneously.
|
|
115
|
+
*
|
|
116
|
+
* @param verifiers - One or more VerifyClientFn instances
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* verifyClient: anyAuth(
|
|
121
|
+
* bearerAuth(["service-token"]),
|
|
122
|
+
* apiKeyAuth("x-api-key", ["ui-key"]),
|
|
123
|
+
* )
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export function anyAuth(...verifiers) {
|
|
127
|
+
return async (info) => {
|
|
128
|
+
for (const verifier of verifiers) {
|
|
129
|
+
if (await verifier(info))
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAgCH,iFAAiF;AAEjF;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,WAA6B;IACtD,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;IACpC,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
|
|
3
|
+
*
|
|
4
|
+
* Provides a high-level `createClientConnection` function that opens a WebSocket
|
|
5
|
+
* to an {@link WebSocketACPServer} (or any ACP-over-WebSocket server) and returns
|
|
6
|
+
* a fully initialized `ClientSideConnection` from `@agentclientprotocol/sdk`.
|
|
7
|
+
*
|
|
8
|
+
* Authentication helpers (`withBearerToken`, `withBasicAuth`, `withApiKey`) generate
|
|
9
|
+
* the `wsOptions` fragment needed to pass credentials during the HTTP upgrade handshake.
|
|
10
|
+
*
|
|
11
|
+
* @example Bearer token
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { createClientConnection, withBearerToken } from "acp-websocket-transport";
|
|
14
|
+
*
|
|
15
|
+
* const { connection, close } = await createClientConnection(
|
|
16
|
+
* "ws://localhost:3000",
|
|
17
|
+
* {
|
|
18
|
+
* ...withBearerToken("my-secret"),
|
|
19
|
+
* toClient: (agent) => ({
|
|
20
|
+
* sessionUpdate: async (params) => { console.log(params); },
|
|
21
|
+
* requestPermission: async () => ({ outcome: "allow_once" }),
|
|
22
|
+
* }),
|
|
23
|
+
* }
|
|
24
|
+
* );
|
|
25
|
+
*
|
|
26
|
+
* const init = await connection.initialize({ protocolVersion: 0, clientCapabilities: {} });
|
|
27
|
+
* console.log(init.agentInfo);
|
|
28
|
+
* close();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
import WebSocket from "ws";
|
|
32
|
+
import { ClientSideConnection } from "@agentclientprotocol/sdk";
|
|
33
|
+
import type { Stream } from "@agentclientprotocol/sdk";
|
|
34
|
+
/** Factory function type accepted by `ClientSideConnection`. */
|
|
35
|
+
type ToClientFactory = ConstructorParameters<typeof ClientSideConnection>[0];
|
|
36
|
+
/**
|
|
37
|
+
* Options for {@link createClientConnection}.
|
|
38
|
+
*/
|
|
39
|
+
export interface ClientConnectionOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Factory that creates the `Client` handler for incoming agent requests
|
|
42
|
+
* (e.g. `session/update` notifications, `session/request_permission`).
|
|
43
|
+
*
|
|
44
|
+
* If omitted, a no-op handler is used — suitable for fire-and-forget or
|
|
45
|
+
* when the caller only needs to make outgoing requests.
|
|
46
|
+
*/
|
|
47
|
+
toClient?: ToClientFactory;
|
|
48
|
+
/**
|
|
49
|
+
* WebSocket subprotocols to negotiate during the upgrade handshake.
|
|
50
|
+
*/
|
|
51
|
+
protocols?: string | string[];
|
|
52
|
+
/**
|
|
53
|
+
* Additional options passed directly to the `ws` WebSocket constructor.
|
|
54
|
+
* Use this to set custom headers (e.g. authentication) or TLS options.
|
|
55
|
+
*
|
|
56
|
+
* @see {@link withBearerToken}, {@link withBasicAuth}, {@link withApiKey}
|
|
57
|
+
*/
|
|
58
|
+
wsOptions?: WebSocket.ClientOptions;
|
|
59
|
+
/**
|
|
60
|
+
* Milliseconds to wait for the WebSocket connection to open.
|
|
61
|
+
* @default 10000
|
|
62
|
+
*/
|
|
63
|
+
connectTimeout?: number;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The result of {@link createClientConnection}.
|
|
67
|
+
*/
|
|
68
|
+
export interface ClientConnection {
|
|
69
|
+
/** The ACP `ClientSideConnection` — use this to call agent methods. */
|
|
70
|
+
connection: ClientSideConnection;
|
|
71
|
+
/** The underlying bidirectional stream (rarely needed directly). */
|
|
72
|
+
stream: Stream;
|
|
73
|
+
/** Closes the WebSocket and tears down the connection. */
|
|
74
|
+
close: () => void;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Opens a WebSocket connection to an ACP server and returns a
|
|
78
|
+
* `ClientSideConnection` ready for use.
|
|
79
|
+
*
|
|
80
|
+
* @param url WebSocket URL of the ACP server (e.g. `"ws://localhost:3000"`)
|
|
81
|
+
* @param options Optional configuration (auth headers, client handler, timeout)
|
|
82
|
+
* @throws If the WebSocket fails to open within `connectTimeout` ms
|
|
83
|
+
*/
|
|
84
|
+
export declare function createClientConnection(url: string | URL, options?: ClientConnectionOptions): Promise<ClientConnection>;
|
|
85
|
+
/**
|
|
86
|
+
* Returns the `wsOptions` fragment needed to authenticate with a Bearer token.
|
|
87
|
+
*
|
|
88
|
+
* Spread this into the options passed to {@link createClientConnection}:
|
|
89
|
+
* ```ts
|
|
90
|
+
* await createClientConnection(url, { ...withBearerToken("tok"), toClient });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function withBearerToken(token: string): Pick<ClientConnectionOptions, "wsOptions">;
|
|
94
|
+
/**
|
|
95
|
+
* Returns the `wsOptions` fragment needed for HTTP Basic authentication.
|
|
96
|
+
*
|
|
97
|
+
* ⚠️ Use TLS (`wss://`) in production — credentials are only base64-encoded.
|
|
98
|
+
*/
|
|
99
|
+
export declare function withBasicAuth(username: string, password: string): Pick<ClientConnectionOptions, "wsOptions">;
|
|
100
|
+
/**
|
|
101
|
+
* Returns the `wsOptions` fragment needed to authenticate via an arbitrary
|
|
102
|
+
* HTTP header (e.g. an API key).
|
|
103
|
+
*
|
|
104
|
+
* @param header Header name (e.g. `"x-api-key"`)
|
|
105
|
+
* @param key The key value
|
|
106
|
+
*/
|
|
107
|
+
export declare function withApiKey(header: string, key: string): Pick<ClientConnectionOptions, "wsOptions">;
|
|
108
|
+
export {};
|
|
109
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAKvD,gEAAgE;AAChE,KAAK,eAAe,GAAG,qBAAqB,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7E;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;;;OAMG;IACH,QAAQ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