@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.
Files changed (159) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +50 -0
  3. package/assets/chatroom.svg +15 -0
  4. package/chatroom.config.example.json +24 -0
  5. package/dist/app/application.d.ts +18 -0
  6. package/dist/app/application.js +63 -0
  7. package/dist/app/event-bus.d.ts +23 -0
  8. package/dist/app/event-bus.js +12 -0
  9. package/dist/app/external-access-registry.d.ts +18 -0
  10. package/dist/app/external-access-registry.js +48 -0
  11. package/dist/app/lifecycle.d.ts +12 -0
  12. package/dist/app/lifecycle.js +41 -0
  13. package/dist/auth/auth-service.d.ts +88 -0
  14. package/dist/auth/auth-service.js +222 -0
  15. package/dist/auth/ingress-policy.d.ts +21 -0
  16. package/dist/auth/ingress-policy.js +57 -0
  17. package/dist/auth/passkey-service.d.ts +39 -0
  18. package/dist/auth/passkey-service.js +145 -0
  19. package/dist/cli/index.d.ts +2 -0
  20. package/dist/cli/index.js +10 -0
  21. package/dist/cli/run-cli.d.ts +1 -0
  22. package/dist/cli/run-cli.js +42 -0
  23. package/dist/config/load-config.d.ts +7 -0
  24. package/dist/config/load-config.js +182 -0
  25. package/dist/config/platform-paths.d.ts +6 -0
  26. package/dist/config/platform-paths.js +34 -0
  27. package/dist/config/types.d.ts +25 -0
  28. package/dist/config/types.js +1 -0
  29. package/dist/core/auth/passkey-repository.d.ts +18 -0
  30. package/dist/core/auth/passkey-repository.js +1 -0
  31. package/dist/core/auth/repository.d.ts +59 -0
  32. package/dist/core/auth/repository.js +7 -0
  33. package/dist/core/auth/session-repository.d.ts +6 -0
  34. package/dist/core/auth/session-repository.js +1 -0
  35. package/dist/core/errors/chatroom-error.d.ts +23 -0
  36. package/dist/core/errors/chatroom-error.js +46 -0
  37. package/dist/core/operations/bounded-value.d.ts +6 -0
  38. package/dist/core/operations/bounded-value.js +41 -0
  39. package/dist/core/operations/redactor.d.ts +4 -0
  40. package/dist/core/operations/redactor.js +65 -0
  41. package/dist/core/operations/repository.d.ts +19 -0
  42. package/dist/core/operations/repository.js +1 -0
  43. package/dist/core/operations/types.d.ts +31 -0
  44. package/dist/core/operations/types.js +9 -0
  45. package/dist/core/runtime/child-environment.d.ts +1 -0
  46. package/dist/core/runtime/child-environment.js +39 -0
  47. package/dist/core/runtime/command-runner.d.ts +15 -0
  48. package/dist/core/runtime/command-runner.js +39 -0
  49. package/dist/core/runtime/identity.d.ts +2 -0
  50. package/dist/core/runtime/identity.js +9 -0
  51. package/dist/infrastructure/database/app-database.d.ts +6 -0
  52. package/dist/infrastructure/database/app-database.js +104 -0
  53. package/dist/infrastructure/database/oauth-repository.d.ts +20 -0
  54. package/dist/infrastructure/database/oauth-repository.js +140 -0
  55. package/dist/infrastructure/database/operation-repository.d.ts +16 -0
  56. package/dist/infrastructure/database/operation-repository.js +129 -0
  57. package/dist/infrastructure/database/passkey-repository.d.ts +11 -0
  58. package/dist/infrastructure/database/passkey-repository.js +57 -0
  59. package/dist/infrastructure/database/web-session-repository.d.ts +10 -0
  60. package/dist/infrastructure/database/web-session-repository.js +26 -0
  61. package/dist/infrastructure/http/http-server.d.ts +26 -0
  62. package/dist/infrastructure/http/http-server.js +166 -0
  63. package/dist/mcp/server/create-mcp-server.d.ts +3 -0
  64. package/dist/mcp/server/create-mcp-server.js +16 -0
  65. package/dist/mcp/server/tool-support.d.ts +105 -0
  66. package/dist/mcp/server/tool-support.js +124 -0
  67. package/dist/operations/operation-log.d.ts +23 -0
  68. package/dist/operations/operation-log.js +103 -0
  69. package/dist/plugins/cloud/api-client.d.ts +56 -0
  70. package/dist/plugins/cloud/api-client.js +122 -0
  71. package/dist/plugins/cloud/controller.d.ts +48 -0
  72. package/dist/plugins/cloud/controller.js +282 -0
  73. package/dist/plugins/cloud/device-proof.d.ts +9 -0
  74. package/dist/plugins/cloud/device-proof.js +17 -0
  75. package/dist/plugins/cloud/plugin.d.ts +4 -0
  76. package/dist/plugins/cloud/plugin.js +17 -0
  77. package/dist/plugins/cloud/state-store.d.ts +7 -0
  78. package/dist/plugins/cloud/state-store.js +74 -0
  79. package/dist/plugins/cloud/tunnel-client.d.ts +36 -0
  80. package/dist/plugins/cloud/tunnel-client.js +293 -0
  81. package/dist/plugins/cloud/types.d.ts +70 -0
  82. package/dist/plugins/cloud/types.js +32 -0
  83. package/dist/plugins/plugin-manager.d.ts +11 -0
  84. package/dist/plugins/plugin-manager.js +24 -0
  85. package/dist/plugins/process/backend.d.ts +19 -0
  86. package/dist/plugins/process/backend.js +1 -0
  87. package/dist/plugins/process/head-tail-buffer.d.ts +18 -0
  88. package/dist/plugins/process/head-tail-buffer.js +49 -0
  89. package/dist/plugins/process/infrastructure/pipe-process-backend.d.ts +8 -0
  90. package/dist/plugins/process/infrastructure/pipe-process-backend.js +61 -0
  91. package/dist/plugins/process/infrastructure/pty-process-backend.d.ts +8 -0
  92. package/dist/plugins/process/infrastructure/pty-process-backend.js +50 -0
  93. package/dist/plugins/process/mcp.d.ts +4 -0
  94. package/dist/plugins/process/mcp.js +69 -0
  95. package/dist/plugins/process/plugin.d.ts +4 -0
  96. package/dist/plugins/process/plugin.js +28 -0
  97. package/dist/plugins/process/process-supervisor.d.ts +36 -0
  98. package/dist/plugins/process/process-supervisor.js +232 -0
  99. package/dist/plugins/process/types.d.ts +34 -0
  100. package/dist/plugins/process/types.js +1 -0
  101. package/dist/plugins/types.d.ts +32 -0
  102. package/dist/plugins/types.js +17 -0
  103. package/dist/plugins/web/api-types.d.ts +10 -0
  104. package/dist/plugins/web/api-types.js +1 -0
  105. package/dist/plugins/web/http/api-router.d.ts +13 -0
  106. package/dist/plugins/web/http/api-router.js +146 -0
  107. package/dist/plugins/web/http/cloud-api-router.d.ts +4 -0
  108. package/dist/plugins/web/http/cloud-api-router.js +41 -0
  109. package/dist/plugins/web/http/process-api-router.d.ts +3 -0
  110. package/dist/plugins/web/http/process-api-router.js +16 -0
  111. package/dist/plugins/web/http/workspace-api-router.d.ts +3 -0
  112. package/dist/plugins/web/http/workspace-api-router.js +82 -0
  113. package/dist/plugins/web/plugin.d.ts +8 -0
  114. package/dist/plugins/web/plugin.js +17 -0
  115. package/dist/plugins/web/runtime.d.ts +36 -0
  116. package/dist/plugins/web/runtime.js +66 -0
  117. package/dist/plugins/workspace/domain/filesystem.d.ts +25 -0
  118. package/dist/plugins/workspace/domain/filesystem.js +1 -0
  119. package/dist/plugins/workspace/domain/git.d.ts +7 -0
  120. package/dist/plugins/workspace/domain/git.js +1 -0
  121. package/dist/plugins/workspace/domain/repository.d.ts +16 -0
  122. package/dist/plugins/workspace/domain/repository.js +1 -0
  123. package/dist/plugins/workspace/domain/review.d.ts +28 -0
  124. package/dist/plugins/workspace/domain/review.js +1 -0
  125. package/dist/plugins/workspace/domain/workspace.d.ts +23 -0
  126. package/dist/plugins/workspace/domain/workspace.js +1 -0
  127. package/dist/plugins/workspace/git/git-command-runner.d.ts +6 -0
  128. package/dist/plugins/workspace/git/git-command-runner.js +15 -0
  129. package/dist/plugins/workspace/git/git-service.d.ts +14 -0
  130. package/dist/plugins/workspace/git/git-service.js +107 -0
  131. package/dist/plugins/workspace/git/git-snapshot-service.d.ts +33 -0
  132. package/dist/plugins/workspace/git/git-snapshot-service.js +352 -0
  133. package/dist/plugins/workspace/infrastructure/workspace-fs.d.ts +38 -0
  134. package/dist/plugins/workspace/infrastructure/workspace-fs.js +340 -0
  135. package/dist/plugins/workspace/infrastructure/workspace-repository.d.ts +12 -0
  136. package/dist/plugins/workspace/infrastructure/workspace-repository.js +51 -0
  137. package/dist/plugins/workspace/mcp.d.ts +4 -0
  138. package/dist/plugins/workspace/mcp.js +168 -0
  139. package/dist/plugins/workspace/plugin.d.ts +10 -0
  140. package/dist/plugins/workspace/plugin.js +37 -0
  141. package/dist/plugins/workspace/workspace-helpers.d.ts +9 -0
  142. package/dist/plugins/workspace/workspace-helpers.js +67 -0
  143. package/dist/plugins/workspace/workspace-service.d.ts +46 -0
  144. package/dist/plugins/workspace/workspace-service.js +339 -0
  145. package/dist/plugins/workspace/worktree-review-service.d.ts +16 -0
  146. package/dist/plugins/workspace/worktree-review-service.js +51 -0
  147. package/dist/presentation/http/http-utils.d.ts +7 -0
  148. package/dist/presentation/http/http-utils.js +47 -0
  149. package/dist/presentation/http/oauth-router.d.ts +5 -0
  150. package/dist/presentation/http/oauth-router.js +163 -0
  151. package/dist/web/assets/chatroom-B5p-5n3y.svg +15 -0
  152. package/dist/web/assets/index-BF_mWl1D.js +26 -0
  153. package/dist/web/assets/index-JPZut9tc.css +1 -0
  154. package/dist/web/assets/materialdesignicons-webfont-B7mPwVP_.ttf +0 -0
  155. package/dist/web/assets/materialdesignicons-webfont-CSr8KVlo.eot +0 -0
  156. package/dist/web/assets/materialdesignicons-webfont-Dp5v-WZN.woff2 +0 -0
  157. package/dist/web/assets/materialdesignicons-webfont-PXm3-2wK.woff +0 -0
  158. package/dist/web/index.html +19 -0
  159. 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>