@mugwork/mug 0.1.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 (135) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +251 -0
  3. package/dist/explorer.js +3 -0
  4. package/dist/packages/email-template/src/email-template.d.ts +18 -0
  5. package/dist/packages/email-template/src/email-template.js +74 -0
  6. package/dist/packages/email-template/src/index.d.ts +1 -0
  7. package/dist/packages/email-template/src/index.js +1 -0
  8. package/dist/packages/surface-renderer/src/form-renderer.d.ts +117 -0
  9. package/dist/packages/surface-renderer/src/form-renderer.js +719 -0
  10. package/dist/packages/surface-renderer/src/index.d.ts +4 -0
  11. package/dist/packages/surface-renderer/src/index.js +2 -0
  12. package/dist/packages/surface-renderer/src/portal-renderer.d.ts +177 -0
  13. package/dist/packages/surface-renderer/src/portal-renderer.js +1089 -0
  14. package/dist/packages/surface-renderer/src/workspace-home.d.ts +46 -0
  15. package/dist/packages/surface-renderer/src/workspace-home.js +345 -0
  16. package/dist/runtime/agent-types.d.ts +48 -0
  17. package/dist/runtime/agent-types.js +3 -0
  18. package/dist/runtime/ai-router.d.ts +32 -0
  19. package/dist/runtime/ai-router.js +112 -0
  20. package/dist/runtime/app.d.ts +6 -0
  21. package/dist/runtime/app.js +399 -0
  22. package/dist/runtime/chunker.d.ts +6 -0
  23. package/dist/runtime/chunker.js +30 -0
  24. package/dist/runtime/context.d.ts +115 -0
  25. package/dist/runtime/context.js +440 -0
  26. package/dist/runtime/do/workspace-database.d.ts +10 -0
  27. package/dist/runtime/do/workspace-database.js +199 -0
  28. package/dist/runtime/form-types.d.ts +143 -0
  29. package/dist/runtime/form-types.js +1 -0
  30. package/dist/runtime/runtime.d.ts +9 -0
  31. package/dist/runtime/runtime.js +7 -0
  32. package/dist/runtime/source-types.d.ts +15 -0
  33. package/dist/runtime/source-types.js +1 -0
  34. package/dist/runtime/source.d.ts +70 -0
  35. package/dist/runtime/source.js +21 -0
  36. package/dist/runtime/sync-runtime.d.ts +10 -0
  37. package/dist/runtime/sync-runtime.js +185 -0
  38. package/dist/runtime/types.d.ts +21 -0
  39. package/dist/runtime/types.js +1 -0
  40. package/dist/runtime/workflow-entrypoint.d.ts +31 -0
  41. package/dist/runtime/workflow-entrypoint.js +1297 -0
  42. package/dist/runtime/workflow.d.ts +285 -0
  43. package/dist/runtime/workflow.js +1008 -0
  44. package/dist/src/cli.d.ts +2 -0
  45. package/dist/src/cli.js +44116 -0
  46. package/dist/src/commands/ai-gateway-route.d.ts +24 -0
  47. package/dist/src/commands/ai-gateway-route.js +192 -0
  48. package/dist/src/commands/auth.d.ts +1 -0
  49. package/dist/src/commands/auth.js +42 -0
  50. package/dist/src/commands/billing.d.ts +6 -0
  51. package/dist/src/commands/billing.js +76 -0
  52. package/dist/src/commands/brain.d.ts +1 -0
  53. package/dist/src/commands/brain.js +194 -0
  54. package/dist/src/commands/demo.d.ts +12 -0
  55. package/dist/src/commands/demo.js +147 -0
  56. package/dist/src/commands/deploy.d.ts +1 -0
  57. package/dist/src/commands/deploy.js +1052 -0
  58. package/dist/src/commands/dev.d.ts +14 -0
  59. package/dist/src/commands/dev.js +2818 -0
  60. package/dist/src/commands/form.d.ts +8 -0
  61. package/dist/src/commands/form.js +396 -0
  62. package/dist/src/commands/init.d.ts +1 -0
  63. package/dist/src/commands/init.js +139 -0
  64. package/dist/src/commands/issue.d.ts +7 -0
  65. package/dist/src/commands/issue.js +191 -0
  66. package/dist/src/commands/login.d.ts +9 -0
  67. package/dist/src/commands/login.js +163 -0
  68. package/dist/src/commands/logs.d.ts +8 -0
  69. package/dist/src/commands/logs.js +113 -0
  70. package/dist/src/commands/portal.d.ts +2 -0
  71. package/dist/src/commands/portal.js +111 -0
  72. package/dist/src/commands/pull.d.ts +3 -0
  73. package/dist/src/commands/pull.js +184 -0
  74. package/dist/src/commands/push.d.ts +4 -0
  75. package/dist/src/commands/push.js +183 -0
  76. package/dist/src/commands/run.d.ts +6 -0
  77. package/dist/src/commands/run.js +91 -0
  78. package/dist/src/commands/secret.d.ts +7 -0
  79. package/dist/src/commands/secret.js +105 -0
  80. package/dist/src/commands/shutdown.d.ts +1 -0
  81. package/dist/src/commands/shutdown.js +46 -0
  82. package/dist/src/commands/sql.d.ts +8 -0
  83. package/dist/src/commands/sql.js +142 -0
  84. package/dist/src/commands/status.d.ts +5 -0
  85. package/dist/src/commands/status.js +39 -0
  86. package/dist/src/commands/sync.d.ts +7 -0
  87. package/dist/src/commands/sync.js +991 -0
  88. package/dist/src/commands/usage.d.ts +6 -0
  89. package/dist/src/commands/usage.js +78 -0
  90. package/dist/src/commands/webhooks.d.ts +1 -0
  91. package/dist/src/commands/webhooks.js +102 -0
  92. package/dist/src/commands/workspace.d.ts +23 -0
  93. package/dist/src/commands/workspace.js +590 -0
  94. package/dist/src/connector-migration.d.ts +20 -0
  95. package/dist/src/connector-migration.js +43 -0
  96. package/dist/src/connector-parser.d.ts +14 -0
  97. package/dist/src/connector-parser.js +94 -0
  98. package/dist/src/connector-service/discover.d.ts +37 -0
  99. package/dist/src/connector-service/discover.js +79 -0
  100. package/dist/src/connector-service/gather.d.ts +22 -0
  101. package/dist/src/connector-service/gather.js +89 -0
  102. package/dist/src/connector-service/init.d.ts +14 -0
  103. package/dist/src/connector-service/init.js +109 -0
  104. package/dist/src/connector-service/scaffold.d.ts +17 -0
  105. package/dist/src/connector-service/scaffold.js +194 -0
  106. package/dist/src/connector-service/spec-storage.d.ts +8 -0
  107. package/dist/src/connector-service/spec-storage.js +48 -0
  108. package/dist/src/connector-service/types.d.ts +57 -0
  109. package/dist/src/connector-service/types.js +2 -0
  110. package/dist/src/connector-service/verify.d.ts +24 -0
  111. package/dist/src/connector-service/verify.js +575 -0
  112. package/dist/src/email-template.d.ts +2 -0
  113. package/dist/src/email-template.js +1 -0
  114. package/dist/src/manifest.d.ts +31 -0
  115. package/dist/src/manifest.js +25 -0
  116. package/dist/src/mug-icon.d.ts +1 -0
  117. package/dist/src/mug-icon.js +12 -0
  118. package/dist/src/slack-manifest.d.ts +119 -0
  119. package/dist/src/slack-manifest.js +163 -0
  120. package/dist/src/source-migration.d.ts +20 -0
  121. package/dist/src/source-migration.js +43 -0
  122. package/dist/src/surface-renderer.d.ts +5 -0
  123. package/dist/src/surface-renderer.js +3 -0
  124. package/dist/src/templates.d.ts +3 -0
  125. package/dist/src/templates.js +48 -0
  126. package/dist/src/version-check.d.ts +1 -0
  127. package/dist/src/version-check.js +28 -0
  128. package/dist/src/workflow-parser.d.ts +95 -0
  129. package/dist/src/workflow-parser.js +526 -0
  130. package/dist/worker/src/agent-types.d.ts +27 -0
  131. package/dist/worker/src/agent-types.js +3 -0
  132. package/dist/worker/src/source-types.d.ts +14 -0
  133. package/dist/worker/src/source-types.js +1 -0
  134. package/package.json +90 -0
  135. package/src/data/model-capabilities.json +171 -0
@@ -0,0 +1,6 @@
1
+ interface UsageOptions {
2
+ json?: boolean;
3
+ period?: string;
4
+ }
5
+ export declare function usage(opts: UsageOptions): Promise<void>;
6
+ export {};
@@ -0,0 +1,78 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { getAccountToken } from "./login.js";
4
+ const DISPATCH_URL = "https://api.mug.work";
5
+ function getWorkspaceName() {
6
+ const cwd = process.cwd();
7
+ const mugJsonPath = join(cwd, "mug.json");
8
+ if (!existsSync(mugJsonPath)) {
9
+ console.error("No mug.json found. Run `mug init` first.");
10
+ process.exit(1);
11
+ }
12
+ return JSON.parse(readFileSync(mugJsonPath, "utf-8")).name;
13
+ }
14
+ const DIMENSION_LABELS = {
15
+ operations: { label: "Operations", unit: "", format: (n) => n.toLocaleString() },
16
+ records: { label: "Database records", unit: "", format: (n) => n.toLocaleString() },
17
+ storage_bytes: { label: "File storage", unit: "", format: formatBytes },
18
+ email: { label: "Email sends", unit: "", format: (n) => n.toLocaleString() },
19
+ sms: { label: "SMS sends", unit: "", format: (n) => n.toLocaleString() },
20
+ ai_credits: { label: "AI credits", unit: "", format: (n) => n.toLocaleString() },
21
+ };
22
+ function formatBytes(bytes) {
23
+ if (bytes === 0)
24
+ return "0 B";
25
+ const units = ["B", "KB", "MB", "GB", "TB"];
26
+ const i = Math.floor(Math.log(bytes) / Math.log(1000));
27
+ return `${(bytes / Math.pow(1000, i)).toFixed(i > 0 ? 1 : 0)} ${units[i]}`;
28
+ }
29
+ function bar(pct, width = 20) {
30
+ const filled = Math.min(width, Math.round((pct / 100) * width));
31
+ const empty = width - filled;
32
+ const color = pct >= 100 ? "\x1b[31m" : pct >= 80 ? "\x1b[33m" : "\x1b[32m";
33
+ return `${color}${"█".repeat(filled)}${"░".repeat(empty)}\x1b[0m`;
34
+ }
35
+ export async function usage(opts) {
36
+ const workspace = getWorkspaceName();
37
+ const token = getAccountToken();
38
+ const url = opts.period
39
+ ? `${DISPATCH_URL}/workspace/${workspace}/usage?period=${opts.period}`
40
+ : `${DISPATCH_URL}/workspace/${workspace}/usage`;
41
+ const res = await fetch(url, {
42
+ headers: { Authorization: `Bearer ${token}` },
43
+ });
44
+ const data = await res.json();
45
+ if (!res.ok || data.error) {
46
+ console.error(`Failed: ${data.error ?? res.statusText}`);
47
+ process.exit(1);
48
+ }
49
+ if (opts.json) {
50
+ console.log(JSON.stringify(data, null, 2));
51
+ return;
52
+ }
53
+ const tierLabel = data.tier.charAt(0).toUpperCase() + data.tier.slice(1);
54
+ console.log(`\n ${workspace} — ${tierLabel} tier — ${data.period}\n`);
55
+ if (data.overage_packs > 0 || data.carry_packs > 0) {
56
+ const total = data.overage_packs + data.carry_packs;
57
+ console.log(` Overage packs: ${data.overage_packs} purchased + ${data.carry_packs} carried = ${total} total\n`);
58
+ }
59
+ const dims = data.dimensions ?? {};
60
+ for (const [key, info] of Object.entries(DIMENSION_LABELS)) {
61
+ const d = dims[key];
62
+ if (!d)
63
+ continue;
64
+ const fmt = info.format;
65
+ const pct = d.base_limit > 0 ? Math.round((d.used / d.base_limit) * 100) : 0;
66
+ const limitStr = key === "storage_bytes" ? formatBytes(d.limit) : d.limit.toLocaleString();
67
+ console.log(` ${info.label.padEnd(18)} ${bar(pct)} ${String(pct).padStart(3)}% ${fmt(d.used)} / ${limitStr}`);
68
+ }
69
+ if (data.ai_detail && data.ai_detail.length > 0) {
70
+ console.log("\n AI model breakdown (last 30 days):");
71
+ for (const m of data.ai_detail) {
72
+ const reqs = Number(m.request_count);
73
+ const tokens = Number(m.total_tokens);
74
+ console.log(` ${m.model}: ${reqs} requests, ${tokens.toLocaleString()} tokens`);
75
+ }
76
+ }
77
+ console.log("");
78
+ }
@@ -0,0 +1 @@
1
+ export declare function webhooksCommand(): Promise<void>;
@@ -0,0 +1,102 @@
1
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { parseWorkflowSteps } from "../workflow-parser.js";
4
+ export async function webhooksCommand() {
5
+ const cwd = process.cwd();
6
+ const mugJsonPath = join(cwd, "mug.json");
7
+ if (!existsSync(mugJsonPath)) {
8
+ console.error("No mug.json found. Run `mug init` first.");
9
+ process.exit(1);
10
+ }
11
+ const config = JSON.parse(readFileSync(mugJsonPath, "utf-8"));
12
+ const name = config.name;
13
+ let tunnelUrl;
14
+ const pidPath = join(cwd, ".mug", "dev.pid");
15
+ if (existsSync(pidPath)) {
16
+ try {
17
+ const pidData = JSON.parse(readFileSync(pidPath, "utf-8"));
18
+ tunnelUrl = pidData.tunnelUrl;
19
+ }
20
+ catch { }
21
+ }
22
+ const wfDir = join(cwd, "src", "workflows");
23
+ if (!existsSync(wfDir)) {
24
+ console.log("No workflows found (src/workflows/ does not exist).");
25
+ return;
26
+ }
27
+ const files = readdirSync(wfDir).filter((f) => f.endsWith(".ts") || f.endsWith(".js"));
28
+ if (files.length === 0) {
29
+ console.log("No workflow files found in src/workflows/.");
30
+ return;
31
+ }
32
+ let hasWebhooks = false;
33
+ let hasInbound = false;
34
+ let hasTriggers = false;
35
+ const webhooks = [];
36
+ const inbounds = [];
37
+ const triggers = [];
38
+ for (const f of files) {
39
+ try {
40
+ const source = readFileSync(join(wfDir, f), "utf-8");
41
+ const wfName = f.replace(/\.(ts|js)$/, "");
42
+ const parsed = parseWorkflowSteps(source, wfName, f);
43
+ if (parsed.webhook) {
44
+ hasWebhooks = true;
45
+ const auth = typeof parsed.webhook === "object" ? parsed.webhook.auth : "none";
46
+ const base = tunnelUrl ? `${tunnelUrl}/hook/${parsed.name}` : `https://api.mug.work/hook/${name}/${parsed.name}`;
47
+ webhooks.push({ name: parsed.name, auth, url: base });
48
+ }
49
+ if (parsed.inbound) {
50
+ hasInbound = true;
51
+ const url = tunnelUrl
52
+ ? `${tunnelUrl}/inbound/${parsed.inbound}`
53
+ : `https://api.mug.work/inbound/${parsed.inbound}/${name}`;
54
+ inbounds.push({ channel: parsed.inbound, workflow: parsed.name, url });
55
+ }
56
+ if (parsed.trigger?.source) {
57
+ hasTriggers = true;
58
+ triggers.push({
59
+ name: parsed.name,
60
+ source: parsed.trigger.source,
61
+ table: parsed.trigger.table ?? "*",
62
+ on: parsed.trigger.on ?? "change",
63
+ });
64
+ }
65
+ }
66
+ catch { }
67
+ }
68
+ if (!hasWebhooks && !hasInbound && !hasTriggers) {
69
+ console.log("No webhooks, inbound routes, or event triggers found in workflow files.");
70
+ return;
71
+ }
72
+ if (webhooks.length > 0) {
73
+ console.log("Webhooks:");
74
+ for (const wh of webhooks) {
75
+ console.log(` ${wh.name} (auth: ${wh.auth})`);
76
+ console.log(` POST ${wh.url}`);
77
+ }
78
+ }
79
+ if (inbounds.length > 0) {
80
+ if (hasWebhooks)
81
+ console.log();
82
+ console.log("Inbound channels:");
83
+ for (const ib of inbounds) {
84
+ console.log(` ${ib.channel} → ${ib.workflow}`);
85
+ console.log(` POST ${ib.url}`);
86
+ }
87
+ }
88
+ if (triggers.length > 0) {
89
+ if (hasWebhooks || hasInbound)
90
+ console.log();
91
+ console.log("Event triggers:");
92
+ for (const t of triggers) {
93
+ console.log(` ${t.name} — ${t.source}/${t.table} on ${t.on}`);
94
+ }
95
+ }
96
+ if (tunnelUrl) {
97
+ console.log(`\n (URLs use active tunnel: ${tunnelUrl})`);
98
+ }
99
+ else if (!existsSync(pidPath)) {
100
+ console.log(`\n (Production URLs shown — run \`mug dev --tunnel\` for local testing URLs)`);
101
+ }
102
+ }
@@ -0,0 +1,23 @@
1
+ export declare function createWorkspace(name: string, opts: {
2
+ subdomain?: string;
3
+ tier?: string;
4
+ }): Promise<void>;
5
+ export declare function workspaceStatus(): Promise<void>;
6
+ export declare function workspacePlan(): Promise<void>;
7
+ export declare function workspaceInvite(email: string): Promise<void>;
8
+ export declare function workspaceTransfer(email: string): Promise<void>;
9
+ export declare function workspaceRemove(email: string): Promise<void>;
10
+ export declare function workspaceArchive(): Promise<void>;
11
+ export declare function workspaceRestore(): Promise<void>;
12
+ export declare function workspaceDelete(): Promise<void>;
13
+ export declare function workspaceExport(opts: {
14
+ categories?: string;
15
+ all?: boolean;
16
+ }): Promise<void>;
17
+ export declare function accountInvites(): Promise<void>;
18
+ export declare function accountAccept(inviteId: string): Promise<void>;
19
+ export declare function accountDecline(inviteId: string): Promise<void>;
20
+ export declare function workspaceCancelInvite(inviteId: string): Promise<void>;
21
+ export declare function accountChangeEmail(newEmail: string): Promise<void>;
22
+ export declare function workspaceMembers(): Promise<void>;
23
+ export declare function workspaceCheckSubdomain(subdomain: string): Promise<void>;