@chrysb/alphaclaw 0.3.5-beta.1 → 0.4.1-beta.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.
Files changed (68) hide show
  1. package/bin/alphaclaw.js +1 -31
  2. package/lib/public/assets/icons/google_icon.svg +8 -0
  3. package/lib/public/css/explorer.css +53 -0
  4. package/lib/public/css/shell.css +21 -19
  5. package/lib/public/css/theme.css +17 -0
  6. package/lib/public/js/app.js +205 -109
  7. package/lib/public/js/components/credentials-modal.js +36 -8
  8. package/lib/public/js/components/file-tree.js +212 -22
  9. package/lib/public/js/components/file-viewer/editor-surface.js +5 -0
  10. package/lib/public/js/components/file-viewer/index.js +47 -6
  11. package/lib/public/js/components/file-viewer/markdown-split-view.js +2 -0
  12. package/lib/public/js/components/file-viewer/status-banners.js +11 -6
  13. package/lib/public/js/components/file-viewer/toolbar.js +56 -1
  14. package/lib/public/js/components/file-viewer/use-editor-selection-restore.js +6 -0
  15. package/lib/public/js/components/file-viewer/use-file-diff.js +11 -0
  16. package/lib/public/js/components/file-viewer/use-file-loader.js +12 -2
  17. package/lib/public/js/components/file-viewer/use-file-viewer.js +142 -15
  18. package/lib/public/js/components/google/account-row.js +131 -0
  19. package/lib/public/js/components/google/add-account-modal.js +93 -0
  20. package/lib/public/js/components/google/gmail-setup-wizard.js +450 -0
  21. package/lib/public/js/components/google/gmail-watch-toggle.js +81 -0
  22. package/lib/public/js/components/google/index.js +553 -0
  23. package/lib/public/js/components/google/use-gmail-watch.js +140 -0
  24. package/lib/public/js/components/google/use-google-accounts.js +41 -0
  25. package/lib/public/js/components/icons.js +26 -0
  26. package/lib/public/js/components/scope-picker.js +1 -1
  27. package/lib/public/js/components/sidebar-git-panel.js +48 -20
  28. package/lib/public/js/components/sidebar.js +93 -75
  29. package/lib/public/js/components/toast.js +11 -7
  30. package/lib/public/js/components/usage-tab/constants.js +31 -0
  31. package/lib/public/js/components/usage-tab/formatters.js +24 -0
  32. package/lib/public/js/components/usage-tab/index.js +72 -0
  33. package/lib/public/js/components/usage-tab/overview-section.js +147 -0
  34. package/lib/public/js/components/usage-tab/sessions-section.js +175 -0
  35. package/lib/public/js/components/usage-tab/use-usage-tab.js +241 -0
  36. package/lib/public/js/components/webhooks.js +182 -129
  37. package/lib/public/js/lib/api.js +178 -9
  38. package/lib/public/js/lib/browse-file-policies.js +29 -11
  39. package/lib/public/js/lib/format.js +71 -0
  40. package/lib/public/js/lib/syntax-highlighters/index.js +6 -5
  41. package/lib/public/shared/browse-file-policies.json +13 -0
  42. package/lib/server/constants.js +47 -7
  43. package/lib/server/gmail-push.js +109 -0
  44. package/lib/server/gmail-serve.js +254 -0
  45. package/lib/server/gmail-watch.js +725 -0
  46. package/lib/server/google-state.js +317 -0
  47. package/lib/server/helpers.js +17 -11
  48. package/lib/server/internal-files-migration.js +31 -3
  49. package/lib/server/onboarding/github.js +21 -2
  50. package/lib/server/onboarding/index.js +1 -3
  51. package/lib/server/onboarding/openclaw.js +3 -0
  52. package/lib/server/onboarding/workspace.js +40 -0
  53. package/lib/server/routes/browse/index.js +90 -2
  54. package/lib/server/routes/gmail.js +128 -0
  55. package/lib/server/routes/google.js +433 -213
  56. package/lib/server/routes/system.js +107 -0
  57. package/lib/server/routes/usage.js +29 -2
  58. package/lib/server/routes/webhooks.js +52 -17
  59. package/lib/server/usage-db.js +283 -15
  60. package/lib/server/watchdog.js +66 -0
  61. package/lib/server/webhook-middleware.js +99 -1
  62. package/lib/server/webhooks.js +214 -65
  63. package/lib/server.js +27 -0
  64. package/lib/setup/gitignore +6 -0
  65. package/lib/setup/hourly-git-sync.sh +29 -2
  66. package/package.json +1 -1
  67. package/lib/public/js/components/google.js +0 -228
  68. package/lib/public/js/components/usage-tab.js +0 -531
@@ -0,0 +1,128 @@
1
+ const { createGmailWatchService } = require("../gmail-watch");
2
+ const { createGmailPushHandler } = require("../gmail-push");
3
+
4
+ const registerGmailRoutes = ({
5
+ app,
6
+ fs,
7
+ constants,
8
+ gogCmd,
9
+ getBaseUrl,
10
+ readGoogleCredentials,
11
+ readEnvFile,
12
+ writeEnvFile,
13
+ reloadEnv,
14
+ restartRequiredState,
15
+ }) => {
16
+ const getRestartSnapshot = async () => {
17
+ try {
18
+ return (await restartRequiredState?.getSnapshot?.()) || {
19
+ restartRequired: false,
20
+ };
21
+ } catch {
22
+ return { restartRequired: false };
23
+ }
24
+ };
25
+
26
+ const gmailWatchService = createGmailWatchService({
27
+ fs,
28
+ constants,
29
+ gogCmd,
30
+ getBaseUrl,
31
+ readGoogleCredentials,
32
+ readEnvFile,
33
+ writeEnvFile,
34
+ reloadEnv,
35
+ restartRequiredState,
36
+ });
37
+
38
+ app.get("/api/gmail/config", (req, res) => {
39
+ try {
40
+ const data = gmailWatchService.getConfig({ req });
41
+ res.json(data);
42
+ } catch (err) {
43
+ res.status(400).json({ ok: false, error: err.message });
44
+ }
45
+ });
46
+
47
+ app.post("/api/gmail/config", (req, res) => {
48
+ try {
49
+ const data = gmailWatchService.saveClientConfig({
50
+ req,
51
+ body: req.body || {},
52
+ });
53
+ res.json(data);
54
+ } catch (err) {
55
+ res.status(400).json({ ok: false, error: err.message });
56
+ }
57
+ });
58
+
59
+ app.post("/api/gmail/watch/start", async (req, res) => {
60
+ try {
61
+ const accountId = String(req.body?.accountId || "").trim();
62
+ if (!accountId) return res.status(400).json({ ok: false, error: "accountId is required" });
63
+ const result = await gmailWatchService.startWatch({ accountId, req });
64
+ const snapshot = await getRestartSnapshot();
65
+ return res.json({
66
+ ...result,
67
+ restartRequired: Boolean(snapshot?.restartRequired),
68
+ });
69
+ } catch (err) {
70
+ return res.status(400).json({ ok: false, error: err.message });
71
+ }
72
+ });
73
+
74
+ app.post("/api/gmail/watch/stop", async (req, res) => {
75
+ try {
76
+ const accountId = String(req.body?.accountId || "").trim();
77
+ if (!accountId) return res.status(400).json({ ok: false, error: "accountId is required" });
78
+ const result = await gmailWatchService.stopWatch({ accountId });
79
+ return res.json(result);
80
+ } catch (err) {
81
+ return res.status(400).json({ ok: false, error: err.message });
82
+ }
83
+ });
84
+
85
+ app.post("/api/gmail/watch/renew", async (req, res) => {
86
+ try {
87
+ const accountId = String(req.body?.accountId || "").trim();
88
+ const force = Boolean(req.body?.force ?? true);
89
+ const result = await gmailWatchService.renewWatch({ accountId, force });
90
+ return res.json(result);
91
+ } catch (err) {
92
+ return res.status(400).json({ ok: false, error: err.message });
93
+ }
94
+ });
95
+
96
+ app.get("/api/gmail/watch/status", (req, res) => {
97
+ try {
98
+ const accountId = String(req.query?.accountId || "").trim();
99
+ const config = gmailWatchService.getConfig({ req });
100
+ const accountStatus = accountId
101
+ ? config.accounts.find((account) => account.accountId === accountId) || null
102
+ : null;
103
+ if (accountId && !accountStatus) {
104
+ return res.status(404).json({ ok: false, error: "Account status not found" });
105
+ }
106
+ return res.json({
107
+ ok: true,
108
+ account: accountStatus,
109
+ accounts: accountId ? undefined : config.accounts,
110
+ });
111
+ } catch (err) {
112
+ return res.status(400).json({ ok: false, error: err.message });
113
+ }
114
+ });
115
+
116
+ const pushHandler = createGmailPushHandler({
117
+ resolvePushToken: () => gmailWatchService.resolvePushToken(),
118
+ resolveTargetByEmail: (email) => gmailWatchService.getTargetByEmail(email),
119
+ markPushReceived: (payload) => gmailWatchService.markPushReceived(payload),
120
+ });
121
+ app.post("/gmail-pubsub", pushHandler);
122
+
123
+ return gmailWatchService;
124
+ };
125
+
126
+ module.exports = {
127
+ registerGmailRoutes,
128
+ };