@chatroomcp/chatroom 0.1.3
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/LICENSE +202 -0
- package/README.md +50 -0
- package/assets/chatroom.svg +15 -0
- package/chatroom.config.example.json +24 -0
- package/dist/app/application.d.ts +18 -0
- package/dist/app/application.js +63 -0
- package/dist/app/event-bus.d.ts +23 -0
- package/dist/app/event-bus.js +12 -0
- package/dist/app/external-access-registry.d.ts +18 -0
- package/dist/app/external-access-registry.js +48 -0
- package/dist/app/lifecycle.d.ts +12 -0
- package/dist/app/lifecycle.js +41 -0
- package/dist/auth/auth-service.d.ts +88 -0
- package/dist/auth/auth-service.js +222 -0
- package/dist/auth/ingress-policy.d.ts +21 -0
- package/dist/auth/ingress-policy.js +57 -0
- package/dist/auth/passkey-service.d.ts +39 -0
- package/dist/auth/passkey-service.js +145 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +10 -0
- package/dist/cli/run-cli.d.ts +1 -0
- package/dist/cli/run-cli.js +42 -0
- package/dist/config/load-config.d.ts +7 -0
- package/dist/config/load-config.js +182 -0
- package/dist/config/platform-paths.d.ts +6 -0
- package/dist/config/platform-paths.js +34 -0
- package/dist/config/types.d.ts +25 -0
- package/dist/config/types.js +1 -0
- package/dist/core/auth/passkey-repository.d.ts +18 -0
- package/dist/core/auth/passkey-repository.js +1 -0
- package/dist/core/auth/repository.d.ts +59 -0
- package/dist/core/auth/repository.js +7 -0
- package/dist/core/auth/session-repository.d.ts +6 -0
- package/dist/core/auth/session-repository.js +1 -0
- package/dist/core/errors/chatroom-error.d.ts +23 -0
- package/dist/core/errors/chatroom-error.js +46 -0
- package/dist/core/operations/bounded-value.d.ts +6 -0
- package/dist/core/operations/bounded-value.js +41 -0
- package/dist/core/operations/redactor.d.ts +4 -0
- package/dist/core/operations/redactor.js +65 -0
- package/dist/core/operations/repository.d.ts +19 -0
- package/dist/core/operations/repository.js +1 -0
- package/dist/core/operations/types.d.ts +31 -0
- package/dist/core/operations/types.js +9 -0
- package/dist/core/runtime/child-environment.d.ts +1 -0
- package/dist/core/runtime/child-environment.js +39 -0
- package/dist/core/runtime/command-runner.d.ts +15 -0
- package/dist/core/runtime/command-runner.js +39 -0
- package/dist/core/runtime/identity.d.ts +2 -0
- package/dist/core/runtime/identity.js +9 -0
- package/dist/infrastructure/database/app-database.d.ts +6 -0
- package/dist/infrastructure/database/app-database.js +104 -0
- package/dist/infrastructure/database/oauth-repository.d.ts +20 -0
- package/dist/infrastructure/database/oauth-repository.js +140 -0
- package/dist/infrastructure/database/operation-repository.d.ts +16 -0
- package/dist/infrastructure/database/operation-repository.js +129 -0
- package/dist/infrastructure/database/passkey-repository.d.ts +11 -0
- package/dist/infrastructure/database/passkey-repository.js +57 -0
- package/dist/infrastructure/database/web-session-repository.d.ts +10 -0
- package/dist/infrastructure/database/web-session-repository.js +26 -0
- package/dist/infrastructure/http/http-server.d.ts +26 -0
- package/dist/infrastructure/http/http-server.js +166 -0
- package/dist/mcp/server/create-mcp-server.d.ts +3 -0
- package/dist/mcp/server/create-mcp-server.js +16 -0
- package/dist/mcp/server/tool-support.d.ts +105 -0
- package/dist/mcp/server/tool-support.js +124 -0
- package/dist/operations/operation-log.d.ts +23 -0
- package/dist/operations/operation-log.js +103 -0
- package/dist/plugins/cloud/api-client.d.ts +56 -0
- package/dist/plugins/cloud/api-client.js +122 -0
- package/dist/plugins/cloud/controller.d.ts +48 -0
- package/dist/plugins/cloud/controller.js +282 -0
- package/dist/plugins/cloud/device-proof.d.ts +9 -0
- package/dist/plugins/cloud/device-proof.js +17 -0
- package/dist/plugins/cloud/plugin.d.ts +4 -0
- package/dist/plugins/cloud/plugin.js +17 -0
- package/dist/plugins/cloud/state-store.d.ts +7 -0
- package/dist/plugins/cloud/state-store.js +74 -0
- package/dist/plugins/cloud/tunnel-client.d.ts +36 -0
- package/dist/plugins/cloud/tunnel-client.js +293 -0
- package/dist/plugins/cloud/types.d.ts +70 -0
- package/dist/plugins/cloud/types.js +32 -0
- package/dist/plugins/plugin-manager.d.ts +11 -0
- package/dist/plugins/plugin-manager.js +24 -0
- package/dist/plugins/process/backend.d.ts +19 -0
- package/dist/plugins/process/backend.js +1 -0
- package/dist/plugins/process/head-tail-buffer.d.ts +18 -0
- package/dist/plugins/process/head-tail-buffer.js +49 -0
- package/dist/plugins/process/infrastructure/pipe-process-backend.d.ts +8 -0
- package/dist/plugins/process/infrastructure/pipe-process-backend.js +61 -0
- package/dist/plugins/process/infrastructure/pty-process-backend.d.ts +8 -0
- package/dist/plugins/process/infrastructure/pty-process-backend.js +50 -0
- package/dist/plugins/process/mcp.d.ts +4 -0
- package/dist/plugins/process/mcp.js +69 -0
- package/dist/plugins/process/plugin.d.ts +4 -0
- package/dist/plugins/process/plugin.js +28 -0
- package/dist/plugins/process/process-supervisor.d.ts +36 -0
- package/dist/plugins/process/process-supervisor.js +232 -0
- package/dist/plugins/process/types.d.ts +34 -0
- package/dist/plugins/process/types.js +1 -0
- package/dist/plugins/types.d.ts +32 -0
- package/dist/plugins/types.js +17 -0
- package/dist/plugins/web/api-types.d.ts +10 -0
- package/dist/plugins/web/api-types.js +1 -0
- package/dist/plugins/web/http/api-router.d.ts +13 -0
- package/dist/plugins/web/http/api-router.js +146 -0
- package/dist/plugins/web/http/cloud-api-router.d.ts +4 -0
- package/dist/plugins/web/http/cloud-api-router.js +41 -0
- package/dist/plugins/web/http/process-api-router.d.ts +3 -0
- package/dist/plugins/web/http/process-api-router.js +16 -0
- package/dist/plugins/web/http/workspace-api-router.d.ts +3 -0
- package/dist/plugins/web/http/workspace-api-router.js +82 -0
- package/dist/plugins/web/plugin.d.ts +8 -0
- package/dist/plugins/web/plugin.js +17 -0
- package/dist/plugins/web/runtime.d.ts +36 -0
- package/dist/plugins/web/runtime.js +66 -0
- package/dist/plugins/workspace/domain/filesystem.d.ts +25 -0
- package/dist/plugins/workspace/domain/filesystem.js +1 -0
- package/dist/plugins/workspace/domain/git.d.ts +7 -0
- package/dist/plugins/workspace/domain/git.js +1 -0
- package/dist/plugins/workspace/domain/repository.d.ts +16 -0
- package/dist/plugins/workspace/domain/repository.js +1 -0
- package/dist/plugins/workspace/domain/review.d.ts +28 -0
- package/dist/plugins/workspace/domain/review.js +1 -0
- package/dist/plugins/workspace/domain/workspace.d.ts +23 -0
- package/dist/plugins/workspace/domain/workspace.js +1 -0
- package/dist/plugins/workspace/git/git-command-runner.d.ts +6 -0
- package/dist/plugins/workspace/git/git-command-runner.js +15 -0
- package/dist/plugins/workspace/git/git-service.d.ts +14 -0
- package/dist/plugins/workspace/git/git-service.js +107 -0
- package/dist/plugins/workspace/git/git-snapshot-service.d.ts +33 -0
- package/dist/plugins/workspace/git/git-snapshot-service.js +352 -0
- package/dist/plugins/workspace/infrastructure/workspace-fs.d.ts +38 -0
- package/dist/plugins/workspace/infrastructure/workspace-fs.js +340 -0
- package/dist/plugins/workspace/infrastructure/workspace-repository.d.ts +12 -0
- package/dist/plugins/workspace/infrastructure/workspace-repository.js +51 -0
- package/dist/plugins/workspace/mcp.d.ts +4 -0
- package/dist/plugins/workspace/mcp.js +168 -0
- package/dist/plugins/workspace/plugin.d.ts +10 -0
- package/dist/plugins/workspace/plugin.js +37 -0
- package/dist/plugins/workspace/workspace-helpers.d.ts +9 -0
- package/dist/plugins/workspace/workspace-helpers.js +67 -0
- package/dist/plugins/workspace/workspace-service.d.ts +46 -0
- package/dist/plugins/workspace/workspace-service.js +339 -0
- package/dist/plugins/workspace/worktree-review-service.d.ts +16 -0
- package/dist/plugins/workspace/worktree-review-service.js +51 -0
- package/dist/presentation/http/http-utils.d.ts +7 -0
- package/dist/presentation/http/http-utils.js +47 -0
- package/dist/presentation/http/oauth-router.d.ts +5 -0
- package/dist/presentation/http/oauth-router.js +163 -0
- package/dist/web/assets/chatroom-B5p-5n3y.svg +15 -0
- package/dist/web/assets/index-BF_mWl1D.js +26 -0
- package/dist/web/assets/index-JPZut9tc.css +1 -0
- package/dist/web/assets/materialdesignicons-webfont-B7mPwVP_.ttf +0 -0
- package/dist/web/assets/materialdesignicons-webfont-CSr8KVlo.eot +0 -0
- package/dist/web/assets/materialdesignicons-webfont-Dp5v-WZN.woff2 +0 -0
- package/dist/web/assets/materialdesignicons-webfont-PXm3-2wK.woff +0 -0
- package/dist/web/index.html +19 -0
- package/package.json +77 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/** OAuth and owner-session HTTP routes backed by AuthService rather than protocol-specific persistence logic. */
|
|
2
|
+
import { Router } from "express";
|
|
3
|
+
import { asChatRoomError, ChatRoomError, } from "../../core/errors/chatroom-error.js";
|
|
4
|
+
import { escapeHtml, requireString } from "./http-utils.js";
|
|
5
|
+
export function createOAuthRouter(auth, ingress) {
|
|
6
|
+
const router = Router();
|
|
7
|
+
router.get("/.well-known/oauth-authorization-server", (req, res) => res.json(auth.authorizationServerMetadata(ingress.mcpBaseUrl(req))));
|
|
8
|
+
router.get("/.well-known/oauth-protected-resource", (req, res) => res.json(auth.protectedResourceMetadata(ingress.mcpBaseUrl(req))));
|
|
9
|
+
router.get("/.well-known/oauth-protected-resource/mcp", (req, res) => res.json(auth.protectedResourceMetadata(ingress.mcpBaseUrl(req))));
|
|
10
|
+
router.post("/oauth/register", (req, res) => {
|
|
11
|
+
const body = req.body;
|
|
12
|
+
const name = typeof body.client_name === "string" ? body.client_name : "MCP Client";
|
|
13
|
+
const redirects = Array.isArray(body.redirect_uris)
|
|
14
|
+
? body.redirect_uris.filter((value) => typeof value === "string")
|
|
15
|
+
: [];
|
|
16
|
+
res.status(201).json(auth.registerClient(name, redirects));
|
|
17
|
+
});
|
|
18
|
+
router.get("/oauth/authorize", (req, res) => {
|
|
19
|
+
const request = authorizationRequest(req.query);
|
|
20
|
+
if (req.query.response_type !== "code")
|
|
21
|
+
throw new ChatRoomError("INVALID_INPUT", "Only response_type=code is supported");
|
|
22
|
+
auth.validateAuthorizationRequest(request);
|
|
23
|
+
res.type("html").send(authorizationPage(request));
|
|
24
|
+
});
|
|
25
|
+
router.post("/oauth/authorize", (req, res) => {
|
|
26
|
+
const body = req.body;
|
|
27
|
+
const request = authorizationRequest(body);
|
|
28
|
+
const code = auth.approveAuthorization(request, requireString(body.owner_token, "owner_token"));
|
|
29
|
+
const redirect = new URL(request.redirectUri);
|
|
30
|
+
redirect.searchParams.set("code", code);
|
|
31
|
+
if (request.state)
|
|
32
|
+
redirect.searchParams.set("state", request.state);
|
|
33
|
+
res.redirect(303, redirect.toString());
|
|
34
|
+
});
|
|
35
|
+
router.post("/oauth/token", (req, res) => {
|
|
36
|
+
const body = req.body;
|
|
37
|
+
let result;
|
|
38
|
+
if (body.grant_type === "authorization_code") {
|
|
39
|
+
result = auth.exchangeCode({
|
|
40
|
+
code: requireString(body.code, "code"),
|
|
41
|
+
clientId: requireString(body.client_id, "client_id"),
|
|
42
|
+
redirectUri: requireString(body.redirect_uri, "redirect_uri"),
|
|
43
|
+
codeVerifier: requireString(body.code_verifier, "code_verifier"),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else if (body.grant_type === "refresh_token") {
|
|
47
|
+
result = auth.exchangeRefreshToken({
|
|
48
|
+
refreshToken: requireString(body.refresh_token, "refresh_token"),
|
|
49
|
+
...(typeof body.client_id === "string"
|
|
50
|
+
? { clientId: body.client_id }
|
|
51
|
+
: {}),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
throw new ChatRoomError("INVALID_INPUT", "Unsupported OAuth grant_type");
|
|
56
|
+
}
|
|
57
|
+
res.setHeader("Cache-Control", "no-store");
|
|
58
|
+
res.json(result);
|
|
59
|
+
});
|
|
60
|
+
router.post("/oauth/revoke", (req, res) => {
|
|
61
|
+
const body = req.body;
|
|
62
|
+
const token = typeof body.token === "string" ? body.token : "";
|
|
63
|
+
if (token)
|
|
64
|
+
auth.revoke(token);
|
|
65
|
+
res.status(200).end();
|
|
66
|
+
});
|
|
67
|
+
router.use(oauthErrorMiddleware());
|
|
68
|
+
return router;
|
|
69
|
+
}
|
|
70
|
+
function oauthErrorMiddleware() {
|
|
71
|
+
return (error, req, res, _next) => {
|
|
72
|
+
const normalized = asChatRoomError(error);
|
|
73
|
+
let code = "invalid_request";
|
|
74
|
+
if (req.path === "/oauth/token" && normalized.code === "FORBIDDEN")
|
|
75
|
+
code = "invalid_grant";
|
|
76
|
+
else if (req.path === "/oauth/register" &&
|
|
77
|
+
/redirect/i.test(normalized.message))
|
|
78
|
+
code = "invalid_redirect_uri";
|
|
79
|
+
else if (normalized.code === "FORBIDDEN")
|
|
80
|
+
code = "access_denied";
|
|
81
|
+
res.setHeader("Cache-Control", "no-store");
|
|
82
|
+
res
|
|
83
|
+
.status(400)
|
|
84
|
+
.json({ error: code, error_description: normalized.message });
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function authorizationRequest(value) {
|
|
88
|
+
const state = typeof value.state === "string" ? value.state : undefined;
|
|
89
|
+
const scopes = typeof value.scope === "string" && value.scope.trim()
|
|
90
|
+
? [...new Set(value.scope.trim().split(/\s+/))]
|
|
91
|
+
: ["mcp"];
|
|
92
|
+
return {
|
|
93
|
+
clientId: requireString(value.client_id, "client_id"),
|
|
94
|
+
redirectUri: requireString(value.redirect_uri, "redirect_uri"),
|
|
95
|
+
codeChallenge: requireString(value.code_challenge, "code_challenge"),
|
|
96
|
+
codeChallengeMethod: requireString(value.code_challenge_method, "code_challenge_method"),
|
|
97
|
+
scopes,
|
|
98
|
+
...(state ? { state } : {}),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function authorizationPage(request) {
|
|
102
|
+
const hidden = (name, value) => `<input type="hidden" name="${name}" value="${escapeHtml(value)}">`;
|
|
103
|
+
const fields = [
|
|
104
|
+
hidden("client_id", request.clientId),
|
|
105
|
+
hidden("redirect_uri", request.redirectUri),
|
|
106
|
+
hidden("code_challenge", request.codeChallenge),
|
|
107
|
+
hidden("code_challenge_method", request.codeChallengeMethod),
|
|
108
|
+
hidden("scope", request.scopes.join(" ")),
|
|
109
|
+
request.state ? hidden("state", request.state) : "",
|
|
110
|
+
].join("");
|
|
111
|
+
return `<!doctype html>
|
|
112
|
+
<html>
|
|
113
|
+
<head>
|
|
114
|
+
<meta charset="utf-8">
|
|
115
|
+
<meta name="viewport" content="width=device-width">
|
|
116
|
+
<title>Authorize ChatRoom</title>
|
|
117
|
+
<style>
|
|
118
|
+
body { font: 15px system-ui; margin: 0; background: #0b0d10; color: #edf1f5; display: grid; place-items: center; min-height: 100vh; }
|
|
119
|
+
.card {
|
|
120
|
+
width: min(440px, calc(100% - 32px));
|
|
121
|
+
background: #14181d;
|
|
122
|
+
border: 1px solid #2a3038;
|
|
123
|
+
border-radius: 14px;
|
|
124
|
+
padding: 24px;
|
|
125
|
+
box-sizing: border-box;
|
|
126
|
+
}
|
|
127
|
+
h1 { font-size: 20px; margin: 0 0 8px; }
|
|
128
|
+
p { color: #aeb8c4; line-height: 1.5; }
|
|
129
|
+
label { display: block; font-size: 12px; color: #aeb8c4; margin: 18px 0 7px; }
|
|
130
|
+
input[type=password] {
|
|
131
|
+
width: 100%;
|
|
132
|
+
box-sizing: border-box;
|
|
133
|
+
background: #0c0f13;
|
|
134
|
+
color: white;
|
|
135
|
+
border: 1px solid #39414b;
|
|
136
|
+
border-radius: 8px;
|
|
137
|
+
padding: 10px;
|
|
138
|
+
}
|
|
139
|
+
button {
|
|
140
|
+
margin-top: 16px;
|
|
141
|
+
width: 100%;
|
|
142
|
+
border: 0;
|
|
143
|
+
border-radius: 8px;
|
|
144
|
+
padding: 10px;
|
|
145
|
+
background: #edf1f5;
|
|
146
|
+
color: #111;
|
|
147
|
+
font-weight: 650;
|
|
148
|
+
cursor: pointer;
|
|
149
|
+
}
|
|
150
|
+
</style>
|
|
151
|
+
</head>
|
|
152
|
+
<body>
|
|
153
|
+
<form class="card" method="post" action="/oauth/authorize">
|
|
154
|
+
<h1>Authorize MCP client</h1>
|
|
155
|
+
<p>Approve this client to access ChatRoom through the MCP endpoint.</p>
|
|
156
|
+
${fields}
|
|
157
|
+
<label for="owner_token">Owner token</label>
|
|
158
|
+
<input id="owner_token" name="owner_token" type="password" autocomplete="current-password" required>
|
|
159
|
+
<button type="submit">Authorize</button>
|
|
160
|
+
</form>
|
|
161
|
+
</body>
|
|
162
|
+
</html>`;
|
|
163
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="48" height="48">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="grad3" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
4
|
+
<stop offset="0%" stop-color="#4F46E5" />
|
|
5
|
+
<stop offset="100%" stop-color="#0EA5E9" />
|
|
6
|
+
</linearGradient>
|
|
7
|
+
</defs>
|
|
8
|
+
<circle cx="24" cy="24" r="22" fill="#F8FAFC" />
|
|
9
|
+
<path d="M 16 34 L 16 22 Q 16 16 24 16 Q 32 16 32 22 L 32 34 Z" fill="url(#grad3)" opacity="0.1" />
|
|
10
|
+
<path d="M 12 22 L 36 22" stroke="url(#grad3)" stroke-width="3" stroke-linecap="round" />
|
|
11
|
+
<circle cx="19" cy="28" r="3" fill="url(#grad3)" />
|
|
12
|
+
<circle cx="28" cy="28" r="3" fill="url(#grad3)" />
|
|
13
|
+
<path d="M 33 26 Q 36 28 33 32" stroke="url(#grad3)" stroke-width="2.5" stroke-linecap="round" fill="none" />
|
|
14
|
+
<path d="M 36 23 Q 40 28 36 34" stroke="url(#grad3)" stroke-width="2" stroke-linecap="round" fill="none" opacity="0.6" />
|
|
15
|
+
</svg>
|