@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.
- package/LICENSE +21 -0
- package/README.md +251 -0
- package/dist/explorer.js +3 -0
- package/dist/packages/email-template/src/email-template.d.ts +18 -0
- package/dist/packages/email-template/src/email-template.js +74 -0
- package/dist/packages/email-template/src/index.d.ts +1 -0
- package/dist/packages/email-template/src/index.js +1 -0
- package/dist/packages/surface-renderer/src/form-renderer.d.ts +117 -0
- package/dist/packages/surface-renderer/src/form-renderer.js +719 -0
- package/dist/packages/surface-renderer/src/index.d.ts +4 -0
- package/dist/packages/surface-renderer/src/index.js +2 -0
- package/dist/packages/surface-renderer/src/portal-renderer.d.ts +177 -0
- package/dist/packages/surface-renderer/src/portal-renderer.js +1089 -0
- package/dist/packages/surface-renderer/src/workspace-home.d.ts +46 -0
- package/dist/packages/surface-renderer/src/workspace-home.js +345 -0
- package/dist/runtime/agent-types.d.ts +48 -0
- package/dist/runtime/agent-types.js +3 -0
- package/dist/runtime/ai-router.d.ts +32 -0
- package/dist/runtime/ai-router.js +112 -0
- package/dist/runtime/app.d.ts +6 -0
- package/dist/runtime/app.js +399 -0
- package/dist/runtime/chunker.d.ts +6 -0
- package/dist/runtime/chunker.js +30 -0
- package/dist/runtime/context.d.ts +115 -0
- package/dist/runtime/context.js +440 -0
- package/dist/runtime/do/workspace-database.d.ts +10 -0
- package/dist/runtime/do/workspace-database.js +199 -0
- package/dist/runtime/form-types.d.ts +143 -0
- package/dist/runtime/form-types.js +1 -0
- package/dist/runtime/runtime.d.ts +9 -0
- package/dist/runtime/runtime.js +7 -0
- package/dist/runtime/source-types.d.ts +15 -0
- package/dist/runtime/source-types.js +1 -0
- package/dist/runtime/source.d.ts +70 -0
- package/dist/runtime/source.js +21 -0
- package/dist/runtime/sync-runtime.d.ts +10 -0
- package/dist/runtime/sync-runtime.js +185 -0
- package/dist/runtime/types.d.ts +21 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/workflow-entrypoint.d.ts +31 -0
- package/dist/runtime/workflow-entrypoint.js +1297 -0
- package/dist/runtime/workflow.d.ts +285 -0
- package/dist/runtime/workflow.js +1008 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +44116 -0
- package/dist/src/commands/ai-gateway-route.d.ts +24 -0
- package/dist/src/commands/ai-gateway-route.js +192 -0
- package/dist/src/commands/auth.d.ts +1 -0
- package/dist/src/commands/auth.js +42 -0
- package/dist/src/commands/billing.d.ts +6 -0
- package/dist/src/commands/billing.js +76 -0
- package/dist/src/commands/brain.d.ts +1 -0
- package/dist/src/commands/brain.js +194 -0
- package/dist/src/commands/demo.d.ts +12 -0
- package/dist/src/commands/demo.js +147 -0
- package/dist/src/commands/deploy.d.ts +1 -0
- package/dist/src/commands/deploy.js +1052 -0
- package/dist/src/commands/dev.d.ts +14 -0
- package/dist/src/commands/dev.js +2818 -0
- package/dist/src/commands/form.d.ts +8 -0
- package/dist/src/commands/form.js +396 -0
- package/dist/src/commands/init.d.ts +1 -0
- package/dist/src/commands/init.js +139 -0
- package/dist/src/commands/issue.d.ts +7 -0
- package/dist/src/commands/issue.js +191 -0
- package/dist/src/commands/login.d.ts +9 -0
- package/dist/src/commands/login.js +163 -0
- package/dist/src/commands/logs.d.ts +8 -0
- package/dist/src/commands/logs.js +113 -0
- package/dist/src/commands/portal.d.ts +2 -0
- package/dist/src/commands/portal.js +111 -0
- package/dist/src/commands/pull.d.ts +3 -0
- package/dist/src/commands/pull.js +184 -0
- package/dist/src/commands/push.d.ts +4 -0
- package/dist/src/commands/push.js +183 -0
- package/dist/src/commands/run.d.ts +6 -0
- package/dist/src/commands/run.js +91 -0
- package/dist/src/commands/secret.d.ts +7 -0
- package/dist/src/commands/secret.js +105 -0
- package/dist/src/commands/shutdown.d.ts +1 -0
- package/dist/src/commands/shutdown.js +46 -0
- package/dist/src/commands/sql.d.ts +8 -0
- package/dist/src/commands/sql.js +142 -0
- package/dist/src/commands/status.d.ts +5 -0
- package/dist/src/commands/status.js +39 -0
- package/dist/src/commands/sync.d.ts +7 -0
- package/dist/src/commands/sync.js +991 -0
- package/dist/src/commands/usage.d.ts +6 -0
- package/dist/src/commands/usage.js +78 -0
- package/dist/src/commands/webhooks.d.ts +1 -0
- package/dist/src/commands/webhooks.js +102 -0
- package/dist/src/commands/workspace.d.ts +23 -0
- package/dist/src/commands/workspace.js +590 -0
- package/dist/src/connector-migration.d.ts +20 -0
- package/dist/src/connector-migration.js +43 -0
- package/dist/src/connector-parser.d.ts +14 -0
- package/dist/src/connector-parser.js +94 -0
- package/dist/src/connector-service/discover.d.ts +37 -0
- package/dist/src/connector-service/discover.js +79 -0
- package/dist/src/connector-service/gather.d.ts +22 -0
- package/dist/src/connector-service/gather.js +89 -0
- package/dist/src/connector-service/init.d.ts +14 -0
- package/dist/src/connector-service/init.js +109 -0
- package/dist/src/connector-service/scaffold.d.ts +17 -0
- package/dist/src/connector-service/scaffold.js +194 -0
- package/dist/src/connector-service/spec-storage.d.ts +8 -0
- package/dist/src/connector-service/spec-storage.js +48 -0
- package/dist/src/connector-service/types.d.ts +57 -0
- package/dist/src/connector-service/types.js +2 -0
- package/dist/src/connector-service/verify.d.ts +24 -0
- package/dist/src/connector-service/verify.js +575 -0
- package/dist/src/email-template.d.ts +2 -0
- package/dist/src/email-template.js +1 -0
- package/dist/src/manifest.d.ts +31 -0
- package/dist/src/manifest.js +25 -0
- package/dist/src/mug-icon.d.ts +1 -0
- package/dist/src/mug-icon.js +12 -0
- package/dist/src/slack-manifest.d.ts +119 -0
- package/dist/src/slack-manifest.js +163 -0
- package/dist/src/source-migration.d.ts +20 -0
- package/dist/src/source-migration.js +43 -0
- package/dist/src/surface-renderer.d.ts +5 -0
- package/dist/src/surface-renderer.js +3 -0
- package/dist/src/templates.d.ts +3 -0
- package/dist/src/templates.js +48 -0
- package/dist/src/version-check.d.ts +1 -0
- package/dist/src/version-check.js +28 -0
- package/dist/src/workflow-parser.d.ts +95 -0
- package/dist/src/workflow-parser.js +526 -0
- package/dist/worker/src/agent-types.d.ts +27 -0
- package/dist/worker/src/agent-types.js +3 -0
- package/dist/worker/src/source-types.d.ts +14 -0
- package/dist/worker/src/source-types.js +1 -0
- package/package.json +90 -0
- package/src/data/model-capabilities.json +171 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { readFileSync, existsSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import Database from "better-sqlite3";
|
|
4
|
+
import { getAccountToken } from "./login.js";
|
|
5
|
+
const DISPATCH_URL = "https://api.mug.work";
|
|
6
|
+
const DEV_PORTS = [8787, 8788, 8789, 8790, 8791];
|
|
7
|
+
async function tryPort(port, database, sql) {
|
|
8
|
+
try {
|
|
9
|
+
const res = await fetch(`http://localhost:${port}/db/${database}/query`, {
|
|
10
|
+
method: "POST",
|
|
11
|
+
headers: { "Content-Type": "application/json" },
|
|
12
|
+
body: JSON.stringify({ sql }),
|
|
13
|
+
signal: AbortSignal.timeout(2000),
|
|
14
|
+
});
|
|
15
|
+
if (!res.ok)
|
|
16
|
+
return null;
|
|
17
|
+
return await res.json();
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function isReadQuery(sql) {
|
|
24
|
+
const trimmed = sql.trim().toUpperCase();
|
|
25
|
+
return trimmed.startsWith("SELECT") || trimmed.startsWith("PRAGMA") || trimmed.startsWith("EXPLAIN");
|
|
26
|
+
}
|
|
27
|
+
function formatTable(rows) {
|
|
28
|
+
if (rows.length === 0)
|
|
29
|
+
return "(no rows)";
|
|
30
|
+
const cols = Object.keys(rows[0]);
|
|
31
|
+
const widths = cols.map((col) => {
|
|
32
|
+
const values = rows.map((r) => String(r[col] ?? "NULL"));
|
|
33
|
+
return Math.max(col.length, ...values.map((v) => v.length));
|
|
34
|
+
});
|
|
35
|
+
const header = cols.map((c, i) => c.padEnd(widths[i])).join(" ");
|
|
36
|
+
const separator = widths.map((w) => "-".repeat(w)).join(" ");
|
|
37
|
+
const body = rows.map((r) => cols.map((c, i) => String(r[c] ?? "NULL").padEnd(widths[i])).join(" ")).join("\n");
|
|
38
|
+
return `${header}\n${separator}\n${body}\n\n(${rows.length} row${rows.length === 1 ? "" : "s"})`;
|
|
39
|
+
}
|
|
40
|
+
function outputResult(rows, json) {
|
|
41
|
+
if (json) {
|
|
42
|
+
console.log(JSON.stringify(rows, null, 2));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
console.log(formatTable(rows));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function queryLocal(database, sql, opts) {
|
|
49
|
+
const cwd = process.cwd();
|
|
50
|
+
const dbDir = join(cwd, "databases");
|
|
51
|
+
const dbPath = join(dbDir, `${database}.db`);
|
|
52
|
+
if (!isReadQuery(sql)) {
|
|
53
|
+
mkdirSync(dbDir, { recursive: true });
|
|
54
|
+
}
|
|
55
|
+
else if (!existsSync(dbPath)) {
|
|
56
|
+
console.error(`Database not found: databases/${database}.db`);
|
|
57
|
+
console.error(`Run a source sync, use \`mug pull databases/${database}\`, or create it with a write query.`);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
const db = new Database(dbPath);
|
|
61
|
+
try {
|
|
62
|
+
db.pragma("journal_mode = WAL");
|
|
63
|
+
if (isReadQuery(sql)) {
|
|
64
|
+
const rows = db.prepare(sql).all();
|
|
65
|
+
outputResult(rows, opts.json);
|
|
66
|
+
}
|
|
67
|
+
else if (sql.includes(";") && sql.trim().indexOf(";") < sql.trim().length - 1) {
|
|
68
|
+
db.exec(sql);
|
|
69
|
+
console.log("Done.");
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const info = db.prepare(sql).run();
|
|
73
|
+
console.log(`${info.changes} row${info.changes === 1 ? "" : "s"} changed`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
console.error(`SQL error: ${err instanceof Error ? err.message : err}`);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
db.close();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export async function query(database, sql, opts) {
|
|
85
|
+
if (opts.production) {
|
|
86
|
+
const cwd = process.cwd();
|
|
87
|
+
const mugJsonPath = join(cwd, "mug.json");
|
|
88
|
+
if (!existsSync(mugJsonPath)) {
|
|
89
|
+
console.error("No mug.json found. Run `mug init` first.");
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
const config = JSON.parse(readFileSync(mugJsonPath, "utf-8"));
|
|
93
|
+
const workspace = config.name;
|
|
94
|
+
const token = getAccountToken();
|
|
95
|
+
try {
|
|
96
|
+
const res = await fetch(`${DISPATCH_URL}/workspace/${workspace}/query`, {
|
|
97
|
+
method: "POST",
|
|
98
|
+
headers: {
|
|
99
|
+
"Content-Type": "application/json",
|
|
100
|
+
Authorization: `Bearer ${token}`,
|
|
101
|
+
},
|
|
102
|
+
body: JSON.stringify({ database, sql }),
|
|
103
|
+
});
|
|
104
|
+
const data = (await res.json());
|
|
105
|
+
if (data.error) {
|
|
106
|
+
console.error(`Query failed: ${data.error}`);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
outputResult(data.rows ?? [], opts.json);
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
console.error(`Could not reach production: ${err instanceof Error ? err.message : err}`);
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
// --dev flag: route through dev server (old behavior)
|
|
118
|
+
if (opts.dev) {
|
|
119
|
+
const port = opts.port ? parseInt(opts.port) : undefined;
|
|
120
|
+
if (port) {
|
|
121
|
+
const result = await tryPort(port, database, sql);
|
|
122
|
+
if (!result) {
|
|
123
|
+
console.error(`Could not reach dev server on port ${port}`);
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
outputResult(result.rows, opts.json);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
for (const p of DEV_PORTS) {
|
|
130
|
+
const result = await tryPort(p, database, sql);
|
|
131
|
+
if (result) {
|
|
132
|
+
outputResult(result.rows, opts.json);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
console.error(`No dev server found on ports ${DEV_PORTS.join(", ")}. Is \`mug dev\` running?`);
|
|
137
|
+
process.exit(1);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// Default: direct file access to databases/<db>.db
|
|
141
|
+
queryLocal(database, sql, opts);
|
|
142
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
export async function status(workflow, instanceId, opts) {
|
|
15
|
+
const workspace = getWorkspaceName();
|
|
16
|
+
const token = getAccountToken();
|
|
17
|
+
const res = await fetch(`${DISPATCH_URL}/workspace/${workspace}/workflow/${workflow}/${instanceId}`, { headers: { Authorization: `Bearer ${token}` } });
|
|
18
|
+
const data = await res.json();
|
|
19
|
+
if (!res.ok || data.error) {
|
|
20
|
+
console.error(`Failed: ${data.error ?? res.statusText}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
if (opts.json) {
|
|
24
|
+
console.log(JSON.stringify(data, null, 2));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const statusIcon = {
|
|
28
|
+
complete: "+", errored: "x", running: "~", queued: ".", paused: "||",
|
|
29
|
+
};
|
|
30
|
+
const icon = statusIcon[data.status] ?? "?";
|
|
31
|
+
console.log(`[${icon}] ${workflow} — ${data.status}`);
|
|
32
|
+
console.log(` instance: ${data.instanceId}`);
|
|
33
|
+
if (data.output) {
|
|
34
|
+
console.log(`\n${JSON.stringify(data.output, null, 2)}`);
|
|
35
|
+
}
|
|
36
|
+
if (data.error) {
|
|
37
|
+
console.log(`\n Error: ${data.error}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function repairScaffolding(cwd: string): void;
|
|
2
|
+
export declare function syncLocalFiles(cwd: string, config: Record<string, unknown>): Promise<void>;
|
|
3
|
+
export declare function syncLocalDatabases(cwd: string, config: Record<string, unknown>): Promise<void>;
|
|
4
|
+
export declare function ensureSettings(mugJsonPath: string): void;
|
|
5
|
+
export declare function migrateMugJsonSources(mugJsonPath: string): void;
|
|
6
|
+
export declare function syncFrameworkFiles(cwd: string): number;
|
|
7
|
+
export declare function sync(dir?: string): Promise<void>;
|