@parall/cli 1.66.0 → 1.68.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/dist/commands/agents.d.ts +2 -0
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/apps-db.d.ts +8 -0
- package/dist/commands/apps-db.d.ts.map +1 -0
- package/dist/commands/apps-db.js +17 -0
- package/dist/commands/apps-publish.d.ts +23 -0
- package/dist/commands/apps-publish.d.ts.map +1 -0
- package/dist/commands/apps-publish.js +288 -0
- package/dist/commands/apps-scaffold.d.ts +9 -0
- package/dist/commands/apps-scaffold.d.ts.map +1 -0
- package/dist/commands/apps-scaffold.js +379 -0
- package/dist/commands/apps.d.ts +12 -0
- package/dist/commands/apps.d.ts.map +1 -0
- package/dist/commands/apps.js +172 -0
- package/dist/commands/clip.d.ts.map +1 -1
- package/dist/commands/clip.js +55 -10
- package/dist/commands/db-plane.d.ts +41 -0
- package/dist/commands/db-plane.d.ts.map +1 -0
- package/dist/commands/db-plane.js +237 -0
- package/dist/commands/dbs.d.ts +16 -0
- package/dist/commands/dbs.d.ts.map +1 -0
- package/dist/commands/dbs.js +147 -0
- package/dist/commands/triggers.d.ts +14 -1
- package/dist/commands/triggers.d.ts.map +1 -1
- package/dist/commands/triggers.js +64 -0
- package/dist/commands/watch.d.ts +1 -1
- package/dist/commands/watch.d.ts.map +1 -1
- package/dist/commands/watch.js +21 -11
- package/dist/commands/wiki-changesets.d.ts +3 -0
- package/dist/commands/wiki-changesets.d.ts.map +1 -0
- package/dist/commands/wiki-changesets.js +176 -0
- package/dist/commands/wiki.d.ts.map +1 -1
- package/dist/commands/wiki.js +4 -173
- package/dist/index.js +20 -16
- package/dist/lib/wiki-tool-definition.d.ts +23 -0
- package/dist/lib/wiki-tool-definition.d.ts.map +1 -0
- package/dist/lib/wiki-tool-definition.js +17 -0
- package/dist/lib/wiki-tools.d.ts +2 -24
- package/dist/lib/wiki-tools.d.ts.map +1 -1
- package/dist/lib/wiki-tools.js +11 -16
- package/package.json +6 -4
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import { createServer } from 'node:http';
|
|
3
|
+
import { extname, join, normalize, resolve, sep } from 'node:path';
|
|
4
|
+
import { printError } from '../lib/output.js';
|
|
5
|
+
/** `parall app init` (the fixed scaffold, design §7.4 v1) and `parall app
|
|
6
|
+
* dev` (a local host page speaking the same bridge shell, for自测 by eye).
|
|
7
|
+
* The scaffold is Vite + React + TS with the bridge shell wired; Tailwind /
|
|
8
|
+
* shadcn presets arrive with the authoring-skill slice. The shell is
|
|
9
|
+
* vendored into the scaffold (src/parall.ts) until @parall/miniapp-sdk is
|
|
10
|
+
* on npm; it is the same code, @parall/miniapp-sdk stays the SSOT. */
|
|
11
|
+
export function registerAppScaffoldCommands(app) {
|
|
12
|
+
app
|
|
13
|
+
.command('init')
|
|
14
|
+
.description('Scaffold a new Mini App project (Vite + React + TS, bridge shell wired)')
|
|
15
|
+
.argument('<dir>', 'Directory to create (must be empty or absent)')
|
|
16
|
+
.action(async (dir) => {
|
|
17
|
+
try {
|
|
18
|
+
const out = resolve(dir);
|
|
19
|
+
await fs.mkdir(out, { recursive: true });
|
|
20
|
+
if ((await fs.readdir(out)).length > 0) {
|
|
21
|
+
throw new Error(`${out} is not empty`);
|
|
22
|
+
}
|
|
23
|
+
const name = out.split(sep).pop() ?? 'mini-app';
|
|
24
|
+
for (const [rel, content] of scaffoldFiles(name)) {
|
|
25
|
+
const target = join(out, rel);
|
|
26
|
+
await fs.mkdir(resolve(target, '..'), { recursive: true });
|
|
27
|
+
await fs.writeFile(target, content);
|
|
28
|
+
}
|
|
29
|
+
console.error([
|
|
30
|
+
`Scaffolded ${name} in ${out}`,
|
|
31
|
+
'',
|
|
32
|
+
'Next steps:',
|
|
33
|
+
` cd ${dir} && pnpm install && pnpm build`,
|
|
34
|
+
` parall app create --name "${name}"`,
|
|
35
|
+
` parall app publish dist --app <app_…> --source .`,
|
|
36
|
+
` parall app dev --dist dist # look at it locally first`,
|
|
37
|
+
].join('\n'));
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
printError(err);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
app
|
|
44
|
+
.command('dev')
|
|
45
|
+
.description('Serve a built bundle under a local host page that speaks the bridge shell')
|
|
46
|
+
.option('--dist <dir>', 'The built bundle directory', 'dist')
|
|
47
|
+
.option('--port <n>', 'Port to listen on', '5180')
|
|
48
|
+
.action(async (opts) => {
|
|
49
|
+
try {
|
|
50
|
+
const dist = resolve(opts.dist);
|
|
51
|
+
await fs.access(join(dist, 'index.html'));
|
|
52
|
+
const port = Number(opts.port);
|
|
53
|
+
const server = createServer((req, res) => {
|
|
54
|
+
void handleDevRequest(dist, req.url ?? '/', res);
|
|
55
|
+
});
|
|
56
|
+
// Loopback only: this serves the app's build directory and must not
|
|
57
|
+
// be reachable from the local network. A bind failure (port in use)
|
|
58
|
+
// arrives as an 'error' event, not a throw — it has to reach the
|
|
59
|
+
// catch below instead of crashing the CLI.
|
|
60
|
+
await new Promise((resolveListen, rejectListen) => {
|
|
61
|
+
server.once('error', rejectListen);
|
|
62
|
+
server.listen(port, '127.0.0.1', () => {
|
|
63
|
+
server.off('error', rejectListen);
|
|
64
|
+
resolveListen();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
console.error(`Mini App dev host: http://127.0.0.1:${port}/ (serving ${dist})`);
|
|
68
|
+
console.error('The host page answers parall.ready() with a local dev viewer; Ctrl-C to stop.');
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
printError(err);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const devContentTypes = {
|
|
76
|
+
'.html': 'text/html; charset=utf-8',
|
|
77
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
78
|
+
'.mjs': 'text/javascript; charset=utf-8',
|
|
79
|
+
'.css': 'text/css; charset=utf-8',
|
|
80
|
+
'.json': 'application/json',
|
|
81
|
+
'.svg': 'image/svg+xml',
|
|
82
|
+
'.png': 'image/png',
|
|
83
|
+
'.jpg': 'image/jpeg',
|
|
84
|
+
'.ico': 'image/x-icon',
|
|
85
|
+
'.map': 'application/json',
|
|
86
|
+
'.woff2': 'font/woff2',
|
|
87
|
+
};
|
|
88
|
+
async function handleDevRequest(dist, url, res) {
|
|
89
|
+
try {
|
|
90
|
+
const pathname = decodeURIComponent(new URL(url, 'http://localhost').pathname);
|
|
91
|
+
if (pathname === '/' || pathname === '/index.html') {
|
|
92
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
93
|
+
res.end(devHostPage());
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (pathname.startsWith('/app/')) {
|
|
97
|
+
const rel = normalize(pathname.slice('/app/'.length));
|
|
98
|
+
if (rel.startsWith('..') || rel.includes(`..${sep}`)) {
|
|
99
|
+
res.writeHead(404).end();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const file = join(dist, rel === '' || rel === '.' ? 'index.html' : rel);
|
|
103
|
+
const body = await fs.readFile(file);
|
|
104
|
+
res.writeHead(200, {
|
|
105
|
+
'Content-Type': devContentTypes[extname(file).toLowerCase()] ?? 'application/octet-stream',
|
|
106
|
+
});
|
|
107
|
+
res.end(body);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
res.writeHead(404).end('not found');
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
res.writeHead(404).end('not found');
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** The local host page: the host side of the bridge shell — answers ready
|
|
117
|
+
* with a dev viewer, relays resize, logs everything else. The same
|
|
118
|
+
* request/response protocol the real hosts speak (§6.3, shell subset). */
|
|
119
|
+
function devHostPage() {
|
|
120
|
+
return `<!doctype html>
|
|
121
|
+
<html>
|
|
122
|
+
<head><meta charset="utf-8"><title>Mini App dev host</title>
|
|
123
|
+
<style>body{margin:0;font-family:system-ui}header{padding:8px 12px;background:#111;color:#eee;font-size:13px}iframe{border:0;width:100%;height:calc(100vh - 37px)}</style>
|
|
124
|
+
</head>
|
|
125
|
+
<body>
|
|
126
|
+
<header>parall app dev — local host (bridge shell: ready / resize / route.changed)</header>
|
|
127
|
+
<iframe id="app" sandbox="allow-scripts allow-same-origin allow-downloads" src="/app/index.html"></iframe>
|
|
128
|
+
<script>
|
|
129
|
+
const frame = document.getElementById('app');
|
|
130
|
+
window.addEventListener('message', (event) => {
|
|
131
|
+
if (event.source !== frame.contentWindow) return;
|
|
132
|
+
const msg = event.data;
|
|
133
|
+
if (!msg || msg.parall !== 'v1' || typeof msg.id !== 'number') return;
|
|
134
|
+
if (msg.method === 'ready') {
|
|
135
|
+
frame.contentWindow.postMessage({ parall: 'v1', id: msg.id, result: {
|
|
136
|
+
viewer: { id: 'usr_dev', display_name: 'Dev Viewer', is_agent: false },
|
|
137
|
+
app: { id: 'app_dev', name: 'local dev', version_seq: 0 },
|
|
138
|
+
route: location.hash.slice(1) || '',
|
|
139
|
+
}}, '*');
|
|
140
|
+
} else if (msg.method === 'resize') {
|
|
141
|
+
frame.contentWindow.postMessage({ parall: 'v1', id: msg.id, result: {} }, '*');
|
|
142
|
+
} else {
|
|
143
|
+
frame.contentWindow.postMessage({ parall: 'v1', id: msg.id, error: { code: 'NOT_GRANTED', message: msg.method + ' is not part of the shell bridge' } }, '*');
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
</script>
|
|
147
|
+
</body>
|
|
148
|
+
</html>`;
|
|
149
|
+
}
|
|
150
|
+
function scaffoldFiles(name) {
|
|
151
|
+
return [
|
|
152
|
+
[
|
|
153
|
+
'package.json',
|
|
154
|
+
`${JSON.stringify({
|
|
155
|
+
name,
|
|
156
|
+
private: true,
|
|
157
|
+
type: 'module',
|
|
158
|
+
scripts: { dev: 'vite', build: 'vite build' },
|
|
159
|
+
dependencies: { react: '^19.1.0', 'react-dom': '^19.1.0' },
|
|
160
|
+
devDependencies: {
|
|
161
|
+
'@types/react': '^19.1.2',
|
|
162
|
+
'@types/react-dom': '^19.1.2',
|
|
163
|
+
'@vitejs/plugin-react': '^4.4.1',
|
|
164
|
+
typescript: '^5.8.3',
|
|
165
|
+
vite: '^6.3.5',
|
|
166
|
+
},
|
|
167
|
+
}, null, 2)}\n`,
|
|
168
|
+
],
|
|
169
|
+
[
|
|
170
|
+
'vite.config.ts',
|
|
171
|
+
`import react from '@vitejs/plugin-react';
|
|
172
|
+
import { defineConfig } from 'vite';
|
|
173
|
+
|
|
174
|
+
// Everything must land inside the bundle: the app origin's CSP only allows
|
|
175
|
+
// 'self' for scripts, styles and fonts (no CDN imports, no external URLs).
|
|
176
|
+
export default defineConfig({
|
|
177
|
+
plugins: [react()],
|
|
178
|
+
base: './',
|
|
179
|
+
build: { outDir: 'dist' },
|
|
180
|
+
});
|
|
181
|
+
`,
|
|
182
|
+
],
|
|
183
|
+
[
|
|
184
|
+
'tsconfig.json',
|
|
185
|
+
`${JSON.stringify({
|
|
186
|
+
compilerOptions: {
|
|
187
|
+
target: 'ES2022',
|
|
188
|
+
module: 'ES2022',
|
|
189
|
+
moduleResolution: 'bundler',
|
|
190
|
+
jsx: 'react-jsx',
|
|
191
|
+
lib: ['ES2022', 'DOM'],
|
|
192
|
+
strict: true,
|
|
193
|
+
noEmit: true,
|
|
194
|
+
skipLibCheck: true,
|
|
195
|
+
},
|
|
196
|
+
include: ['src'],
|
|
197
|
+
}, null, 2)}\n`,
|
|
198
|
+
],
|
|
199
|
+
[
|
|
200
|
+
'index.html',
|
|
201
|
+
`<!doctype html>
|
|
202
|
+
<html lang="en">
|
|
203
|
+
<head>
|
|
204
|
+
<meta charset="UTF-8" />
|
|
205
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
206
|
+
<title>${name}</title>
|
|
207
|
+
</head>
|
|
208
|
+
<body>
|
|
209
|
+
<div id="root"></div>
|
|
210
|
+
<script type="module" src="./src/main.tsx"></script>
|
|
211
|
+
</body>
|
|
212
|
+
</html>
|
|
213
|
+
`,
|
|
214
|
+
],
|
|
215
|
+
[
|
|
216
|
+
'public/manifest.json',
|
|
217
|
+
`${JSON.stringify({ entry: 'index.html', sdk_version: '0.1.0', capabilities: [] }, null, 2)}\n`,
|
|
218
|
+
],
|
|
219
|
+
[
|
|
220
|
+
'src/main.tsx',
|
|
221
|
+
`import { StrictMode } from 'react';
|
|
222
|
+
import { createRoot } from 'react-dom/client';
|
|
223
|
+
import { App } from './App';
|
|
224
|
+
|
|
225
|
+
createRoot(document.getElementById('root') as HTMLElement).render(
|
|
226
|
+
<StrictMode>
|
|
227
|
+
<App />
|
|
228
|
+
</StrictMode>,
|
|
229
|
+
);
|
|
230
|
+
`,
|
|
231
|
+
],
|
|
232
|
+
[
|
|
233
|
+
'src/App.tsx',
|
|
234
|
+
`import { useEffect, useState } from 'react';
|
|
235
|
+
import { parall, type ReadyResult } from './parall';
|
|
236
|
+
|
|
237
|
+
export function App() {
|
|
238
|
+
const [host, setHost] = useState<ReadyResult | null>(null);
|
|
239
|
+
const [error, setError] = useState<string | null>(null);
|
|
240
|
+
useEffect(() => {
|
|
241
|
+
parall
|
|
242
|
+
.ready()
|
|
243
|
+
.then(setHost)
|
|
244
|
+
.catch((err: Error) => setError(err.message));
|
|
245
|
+
}, []);
|
|
246
|
+
return (
|
|
247
|
+
<main style={{ fontFamily: 'system-ui', padding: 24 }}>
|
|
248
|
+
<h1>${name}</h1>
|
|
249
|
+
{host ? (
|
|
250
|
+
<p>
|
|
251
|
+
Hello, {host.viewer.display_name} — you are looking at version {host.app.version_seq} of{' '}
|
|
252
|
+
{host.app.name}.
|
|
253
|
+
</p>
|
|
254
|
+
) : error ? (
|
|
255
|
+
<p>Bridge error: {error}</p>
|
|
256
|
+
) : (
|
|
257
|
+
<p>Waiting for the host…</p>
|
|
258
|
+
)}
|
|
259
|
+
</main>
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
`,
|
|
263
|
+
],
|
|
264
|
+
['src/parall.ts', vendoredShell()],
|
|
265
|
+
[
|
|
266
|
+
'AGENTS.md',
|
|
267
|
+
`# ${name} — Mini App 约定
|
|
268
|
+
|
|
269
|
+
- 这是一个 Parall Mini App:纯静态 bundle,所有脚本 / 样式 / 字体都必须打进 dist(app origin 的 CSP 只放 'self',任何外部 URL 引用会在 publish 验收时被拒)。
|
|
270
|
+
- \`public/manifest.json\` 随构建进入 dist 根部;entry 固定 index.html。
|
|
271
|
+
- 数据能力尚未开放:\`src/parall.ts\` 只有宿主握手(ready / resize / 事件),没有 db / files / clip 方法——成员的数据操作面(action)由平台另行设计。
|
|
272
|
+
- 流程:\`pnpm build\` → \`parall app publish dist --app <app_…> --source .\` → 在 Parall 里打开;先 \`parall app dev --dist dist\` 本地看一眼。
|
|
273
|
+
- \`src/parall.ts\` 是 @parall/miniapp-sdk 的 vendored 副本(npm 发布前);不要在里面加能力。
|
|
274
|
+
`,
|
|
275
|
+
],
|
|
276
|
+
['.gitignore', 'node_modules\ndist\n'],
|
|
277
|
+
];
|
|
278
|
+
}
|
|
279
|
+
/** The vendored bridge shell — byte-wise the same logic as
|
|
280
|
+
* @parall/miniapp-sdk/src/index.ts (kept small on purpose). */
|
|
281
|
+
function vendoredShell() {
|
|
282
|
+
return `// Vendored copy of @parall/miniapp-sdk (bridge SHELL: ready / resize /
|
|
283
|
+
// events; deliberately no data APIs). Replace with the npm package once it
|
|
284
|
+
// ships; do not add capabilities here.
|
|
285
|
+
|
|
286
|
+
export interface ViewerSummary {
|
|
287
|
+
id: string;
|
|
288
|
+
display_name: string;
|
|
289
|
+
is_agent: boolean;
|
|
290
|
+
role?: string;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export interface AppSummary {
|
|
294
|
+
id: string;
|
|
295
|
+
name: string;
|
|
296
|
+
version_seq: number;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export interface ReadyResult {
|
|
300
|
+
viewer: ViewerSummary;
|
|
301
|
+
app: AppSummary;
|
|
302
|
+
route: string;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export type HostEvent =
|
|
306
|
+
| { event: 'route.changed'; data: { route: string } }
|
|
307
|
+
| { event: 'viewer.changed'; data: { viewer: ViewerSummary } };
|
|
308
|
+
|
|
309
|
+
type Pending = { resolve: (v: unknown) => void; reject: (e: Error) => void; timer: ReturnType<typeof setTimeout> };
|
|
310
|
+
|
|
311
|
+
const PROTOCOL = 'v1';
|
|
312
|
+
|
|
313
|
+
class MiniAppBridge {
|
|
314
|
+
private nextId = 1;
|
|
315
|
+
private pending = new Map<number, Pending>();
|
|
316
|
+
private listeners = new Set<(e: HostEvent) => void>();
|
|
317
|
+
private hostOrigin: string | null = null;
|
|
318
|
+
private started = false;
|
|
319
|
+
|
|
320
|
+
private start(): void {
|
|
321
|
+
if (this.started) return;
|
|
322
|
+
this.started = true;
|
|
323
|
+
window.addEventListener('message', (event: MessageEvent) => {
|
|
324
|
+
if (event.source !== window.parent) return;
|
|
325
|
+
if (this.hostOrigin !== null && event.origin !== this.hostOrigin) return;
|
|
326
|
+
const msg = event.data as Record<string, unknown> | null;
|
|
327
|
+
if (!msg || msg.parall !== PROTOCOL) return;
|
|
328
|
+
if (typeof msg.id === 'number') {
|
|
329
|
+
const pending = this.pending.get(msg.id);
|
|
330
|
+
if (!pending) return;
|
|
331
|
+
this.pending.delete(msg.id);
|
|
332
|
+
clearTimeout(pending.timer);
|
|
333
|
+
if (this.hostOrigin === null) this.hostOrigin = event.origin;
|
|
334
|
+
if (msg.error) {
|
|
335
|
+
const err = msg.error as { code: string; message: string };
|
|
336
|
+
pending.reject(Object.assign(new Error(err.message), { code: err.code }));
|
|
337
|
+
} else {
|
|
338
|
+
pending.resolve(msg.result);
|
|
339
|
+
}
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
if (typeof msg.event === 'string') {
|
|
343
|
+
for (const fn of this.listeners) fn(msg as unknown as HostEvent);
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
private call<T>(method: string, params?: unknown): Promise<T> {
|
|
349
|
+
this.start();
|
|
350
|
+
const id = this.nextId++;
|
|
351
|
+
return new Promise<T>((resolve, reject) => {
|
|
352
|
+
const timer = setTimeout(() => {
|
|
353
|
+
if (this.pending.delete(id)) {
|
|
354
|
+
reject(Object.assign(new Error(method + ' timed out waiting for the host'), { code: 'HOST_TIMEOUT' }));
|
|
355
|
+
}
|
|
356
|
+
}, 10_000);
|
|
357
|
+
this.pending.set(id, { resolve: resolve as (v: unknown) => void, reject, timer });
|
|
358
|
+
window.parent.postMessage({ parall: PROTOCOL, id, method, params }, '*');
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
ready(): Promise<ReadyResult> {
|
|
363
|
+
return this.call<ReadyResult>('ready');
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
resize(height: number): void {
|
|
367
|
+
void this.call('resize', { height }).catch(() => {});
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
onEvent(fn: (e: HostEvent) => void): () => void {
|
|
371
|
+
this.start();
|
|
372
|
+
this.listeners.add(fn);
|
|
373
|
+
return () => this.listeners.delete(fn);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export const parall = new MiniAppBridge();
|
|
378
|
+
`;
|
|
379
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
/** Mini App entity: an agent-authored app of the organization, attached to
|
|
3
|
+
* a Database (docs/engineering-design/mini-app-design.md). Every org member
|
|
4
|
+
* opens every app; its authors manage it. This file manages the entity and
|
|
5
|
+
* its author roster; `app db …` (apps-db.ts) is the app alias of the data
|
|
6
|
+
* plane, `parall db …` (dbs.ts) the Database itself; publish / versions /
|
|
7
|
+
* rollback / pull live in apps-publish.ts and the scaffold + local dev host
|
|
8
|
+
* in apps-scaffold.ts. Every command answers 404 while the deployment has
|
|
9
|
+
* cap:mini-apps off and 403 MINI_APPS_UNAVAILABLE for an org without the
|
|
10
|
+
* mini-apps flag. */
|
|
11
|
+
export declare function registerAppCommands(program: Command): void;
|
|
12
|
+
//# sourceMappingURL=apps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apps.d.ts","sourceRoot":"","sources":["../../src/commands/apps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOzC;;;;;;;;qBAQqB;AACrB,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,QA0KnD"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { resolveCredentials } from '../lib/client.js';
|
|
2
|
+
import { printError, printJson, printRefHint, stripPrllScheme } from '../lib/output.js';
|
|
3
|
+
import { registerAppDBCommands } from './apps-db.js';
|
|
4
|
+
import { registerAppPublishCommands } from './apps-publish.js';
|
|
5
|
+
import { registerAppScaffoldCommands } from './apps-scaffold.js';
|
|
6
|
+
/** Mini App entity: an agent-authored app of the organization, attached to
|
|
7
|
+
* a Database (docs/engineering-design/mini-app-design.md). Every org member
|
|
8
|
+
* opens every app; its authors manage it. This file manages the entity and
|
|
9
|
+
* its author roster; `app db …` (apps-db.ts) is the app alias of the data
|
|
10
|
+
* plane, `parall db …` (dbs.ts) the Database itself; publish / versions /
|
|
11
|
+
* rollback / pull live in apps-publish.ts and the scaffold + local dev host
|
|
12
|
+
* in apps-scaffold.ts. Every command answers 404 while the deployment has
|
|
13
|
+
* cap:mini-apps off and 403 MINI_APPS_UNAVAILABLE for an org without the
|
|
14
|
+
* mini-apps flag. */
|
|
15
|
+
export function registerAppCommands(program) {
|
|
16
|
+
const app = program
|
|
17
|
+
.command('app')
|
|
18
|
+
.description('Manage Mini Apps (agent-authored apps over a Database)');
|
|
19
|
+
registerAppDBCommands(app);
|
|
20
|
+
registerAppPublishCommands(app);
|
|
21
|
+
registerAppScaffoldCommands(app);
|
|
22
|
+
app
|
|
23
|
+
.command('list')
|
|
24
|
+
.description("List the organization's Mini Apps")
|
|
25
|
+
.option('--project <projectId>', 'Deprecated and ignored: apps belong to the organization')
|
|
26
|
+
.option('--include-archived', 'Include archived apps')
|
|
27
|
+
.action(async (opts) => {
|
|
28
|
+
try {
|
|
29
|
+
const { client, orgId } = resolveCredentials();
|
|
30
|
+
const result = await client.getMiniApps(orgId, {
|
|
31
|
+
include_archived: Boolean(opts.includeArchived),
|
|
32
|
+
});
|
|
33
|
+
printJson(result);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
printError(err);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
app
|
|
40
|
+
.command('get')
|
|
41
|
+
.description('Get a Mini App by ID')
|
|
42
|
+
.argument('<appId>', 'App ID (app_… or prll://app_…)')
|
|
43
|
+
.action(async (appId) => {
|
|
44
|
+
try {
|
|
45
|
+
const { client, orgId } = resolveCredentials();
|
|
46
|
+
printJson(await client.getMiniApp(orgId, stripPrllScheme(appId)));
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
printError(err);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
app
|
|
53
|
+
.command('create')
|
|
54
|
+
.description('Create a Mini App in the organization; you become its author')
|
|
55
|
+
.option('--project <projectId>', 'Deprecated and ignored: apps belong to the organization')
|
|
56
|
+
.requiredOption('--name <name>', 'App name')
|
|
57
|
+
.option('--slug <slug>', 'URL slug (lowercase kebab-case; derived from the name when omitted)')
|
|
58
|
+
.option('--description <text>', 'App description')
|
|
59
|
+
.option('--database <dbId>', 'Attach to an existing Database of the organization (adb_…; author of one of its apps or org owner/admin); default: create one named after the app')
|
|
60
|
+
.action(async (opts) => {
|
|
61
|
+
try {
|
|
62
|
+
const { client, orgId } = resolveCredentials();
|
|
63
|
+
const data = { name: opts.name };
|
|
64
|
+
if (opts.slug)
|
|
65
|
+
data.slug = opts.slug;
|
|
66
|
+
if (opts.description)
|
|
67
|
+
data.description = opts.description;
|
|
68
|
+
if (opts.database)
|
|
69
|
+
data.database_id = stripPrllScheme(opts.database);
|
|
70
|
+
const result = await client.createMiniApp(orgId, data);
|
|
71
|
+
printJson(result);
|
|
72
|
+
printRefHint(result.id);
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
printError(err);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
app
|
|
79
|
+
.command('update')
|
|
80
|
+
.description("Rename a Mini App or change its description (the app's author or an org owner/admin)")
|
|
81
|
+
.argument('<appId>', 'App ID')
|
|
82
|
+
.option('--name <name>', 'New name')
|
|
83
|
+
.option('--description <text>', 'New description (empty string clears)')
|
|
84
|
+
.action(async (appId, opts) => {
|
|
85
|
+
try {
|
|
86
|
+
const { client, orgId } = resolveCredentials();
|
|
87
|
+
const data = {};
|
|
88
|
+
if (opts.name !== undefined)
|
|
89
|
+
data.name = opts.name;
|
|
90
|
+
if (opts.description !== undefined)
|
|
91
|
+
data.description = opts.description;
|
|
92
|
+
if (Object.keys(data).length === 0) {
|
|
93
|
+
throw new Error('Nothing to update: pass at least one of --name, --description (data settings live on the Database: `parall db update`)');
|
|
94
|
+
}
|
|
95
|
+
printJson(await client.updateMiniApp(orgId, stripPrllScheme(appId), data));
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
printError(err);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
app
|
|
102
|
+
.command('archive')
|
|
103
|
+
.description("Archive a Mini App (the app's author or an org owner/admin); data and versions are kept")
|
|
104
|
+
.argument('<appId>', 'App ID')
|
|
105
|
+
.action(async (appId) => {
|
|
106
|
+
try {
|
|
107
|
+
const { client, orgId } = resolveCredentials();
|
|
108
|
+
printJson(await client.archiveMiniApp(orgId, stripPrllScheme(appId)));
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
printError(err);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
app
|
|
115
|
+
.command('restore')
|
|
116
|
+
.description("Restore an archived Mini App (the app's author or an org owner/admin)")
|
|
117
|
+
.argument('<appId>', 'App ID')
|
|
118
|
+
.action(async (appId) => {
|
|
119
|
+
try {
|
|
120
|
+
const { client, orgId } = resolveCredentials();
|
|
121
|
+
printJson(await client.restoreMiniApp(orgId, stripPrllScheme(appId)));
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
printError(err);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
const authors = app
|
|
128
|
+
.command('authors')
|
|
129
|
+
.description('Manage who manages the app: publish, roll back, rename, archive, authors');
|
|
130
|
+
authors
|
|
131
|
+
.command('list')
|
|
132
|
+
.description('List the authors of a Mini App')
|
|
133
|
+
.argument('<appId>', 'App ID')
|
|
134
|
+
.action(async (appId) => {
|
|
135
|
+
try {
|
|
136
|
+
const { client, orgId } = resolveCredentials();
|
|
137
|
+
printJson(await client.getMiniAppAuthors(orgId, stripPrllScheme(appId)));
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
printError(err);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
authors
|
|
144
|
+
.command('add')
|
|
145
|
+
.description("Add an author (the app's author or an org owner/admin); the user must be a member of the organization")
|
|
146
|
+
.argument('<appId>', 'App ID')
|
|
147
|
+
.argument('<userId>', 'User or agent ID (usr_…)')
|
|
148
|
+
.action(async (appId, userId) => {
|
|
149
|
+
try {
|
|
150
|
+
const { client, orgId } = resolveCredentials();
|
|
151
|
+
printJson(await client.addMiniAppAuthor(orgId, stripPrllScheme(appId), stripPrllScheme(userId)));
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
printError(err);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
authors
|
|
158
|
+
.command('remove')
|
|
159
|
+
.description("Remove an author (the app's author or an org owner/admin); the creator cannot be removed")
|
|
160
|
+
.argument('<appId>', 'App ID')
|
|
161
|
+
.argument('<userId>', 'User or agent ID (usr_…)')
|
|
162
|
+
.action(async (appId, userId) => {
|
|
163
|
+
try {
|
|
164
|
+
const { client, orgId } = resolveCredentials();
|
|
165
|
+
await client.removeMiniAppAuthor(orgId, stripPrllScheme(appId), stripPrllScheme(userId));
|
|
166
|
+
console.error(`Removed ${stripPrllScheme(userId)} from the authors of ${stripPrllScheme(appId)}`);
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
printError(err);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clip.d.ts","sourceRoot":"","sources":["../../src/commands/clip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsMpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"clip.d.ts","sourceRoot":"","sources":["../../src/commands/clip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsMpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,QAmmBpD"}
|
package/dist/commands/clip.js
CHANGED
|
@@ -561,37 +561,82 @@ export function registerClipCommands(program) {
|
|
|
561
561
|
.command('publish')
|
|
562
562
|
.description('Publish a clip directory (manifest.json or site.json + its top-level .js files) into the org registry. Re-publishing an existing name is author-only and replaces the file set; "visibility": "public" additionally submits the version for platform review before it can spread cross-org')
|
|
563
563
|
.argument('<directory>', 'Clip source directory')
|
|
564
|
-
.
|
|
564
|
+
.option('--icon <path>', 'Image file to upload as the clip icon (PNG/JPEG/WebP/GIF, max 5 MiB)')
|
|
565
|
+
.action(async (directory, opts) => {
|
|
565
566
|
try {
|
|
566
567
|
const { client, orgId } = resolveCredentials();
|
|
567
568
|
const { manifest, files, directoryName } = collectPublishSource(directory);
|
|
568
|
-
// Same request derivation as the Edge CLI (`parall-clip publish`):
|
|
569
|
-
// manifest fields win, directory name / 0.0.1 / private fill the gaps.
|
|
570
|
-
// Send the TRIMMED values — name is the org-wide upsert key, so
|
|
571
|
-
// `" google "` must not mint an entry distinct from `google`.
|
|
572
569
|
const manifestName = typeof manifest.name === 'string' ? manifest.name.trim() : '';
|
|
573
570
|
const manifestVersion = typeof manifest.version === 'string' ? manifest.version.trim() : '';
|
|
571
|
+
const clipName = manifestName !== '' ? manifestName : directoryName;
|
|
572
|
+
let iconBlob;
|
|
573
|
+
if (opts?.icon) {
|
|
574
|
+
const { readFileSync, statSync } = await import('node:fs');
|
|
575
|
+
const { resolve } = await import('node:path');
|
|
576
|
+
const iconPath = resolve(opts.icon);
|
|
577
|
+
try {
|
|
578
|
+
const stat = statSync(iconPath);
|
|
579
|
+
if (!stat.isFile())
|
|
580
|
+
throw new Error('not a regular file');
|
|
581
|
+
}
|
|
582
|
+
catch {
|
|
583
|
+
printError(new Error(`--icon path is not a readable file: ${opts.icon}`));
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
const ext = iconPath.split('.').pop()?.toLowerCase();
|
|
587
|
+
const mimeMap = {
|
|
588
|
+
png: 'image/png',
|
|
589
|
+
jpg: 'image/jpeg',
|
|
590
|
+
jpeg: 'image/jpeg',
|
|
591
|
+
webp: 'image/webp',
|
|
592
|
+
gif: 'image/gif',
|
|
593
|
+
};
|
|
594
|
+
const mime = (ext && mimeMap[ext]) || 'application/octet-stream';
|
|
595
|
+
iconBlob = new File([readFileSync(iconPath)], `icon.${ext || 'png'}`, { type: mime });
|
|
596
|
+
}
|
|
597
|
+
// For existing clips, upload icon BEFORE publish so createPendingVersion
|
|
598
|
+
// snapshots the updated icon_url. For new clips, icon upload must follow
|
|
599
|
+
// publish (the clip entry doesn't exist yet).
|
|
600
|
+
let existingClipId;
|
|
601
|
+
if (iconBlob) {
|
|
602
|
+
const existing = await client
|
|
603
|
+
.resolveRegistryClip(orgId, orgId, clipName)
|
|
604
|
+
.catch((err) => {
|
|
605
|
+
if (err.status === 404)
|
|
606
|
+
return null;
|
|
607
|
+
throw err;
|
|
608
|
+
});
|
|
609
|
+
if (existing) {
|
|
610
|
+
existingClipId = existing.id;
|
|
611
|
+
await client.uploadClipIcon(orgId, existingClipId, iconBlob);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
574
614
|
const entry = await client.publishRegistryClip(orgId, {
|
|
575
|
-
name:
|
|
615
|
+
name: clipName,
|
|
576
616
|
description: typeof manifest.description === 'string' ? manifest.description : undefined,
|
|
577
617
|
version: manifestVersion !== '' ? manifestVersion : '0.0.1',
|
|
578
618
|
visibility: manifest.visibility === 'public' ? 'public' : 'private',
|
|
579
619
|
manifest: buildPublishedManifest(manifest),
|
|
580
620
|
files,
|
|
581
621
|
});
|
|
622
|
+
// New clip: upload icon after publish (clip now exists).
|
|
623
|
+
if (iconBlob && !existingClipId) {
|
|
624
|
+
await client.uploadClipIcon(orgId, entry.id, iconBlob);
|
|
625
|
+
if (entry.review_status === 'pending') {
|
|
626
|
+
console.error(`Icon uploaded. Note: the icon is not included in this version's review snapshot (first publish). ` +
|
|
627
|
+
`Re-publish to include it in the next version.`);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
582
630
|
printJson({
|
|
583
631
|
id: entry.id,
|
|
584
632
|
name: entry.name,
|
|
585
633
|
version: entry.version ?? null,
|
|
586
634
|
visibility: entry.visibility,
|
|
587
635
|
files: Object.keys(files).sort(),
|
|
588
|
-
|
|
636
|
+
...(entry.icon_url ? { icon_url: entry.icon_url } : {}),
|
|
589
637
|
...(entry.review_status ? { review_status: entry.review_status } : {}),
|
|
590
638
|
});
|
|
591
639
|
if (entry.review_status === 'pending') {
|
|
592
|
-
// stderr, keeping stdout parseable — same convention as printRefHint.
|
|
593
|
-
// A public publish is NOT cross-org visible until platform review
|
|
594
|
-
// approves; tell the publisher where to watch that state.
|
|
595
640
|
console.error(`Review pending: this clip stays invisible to other orgs until platform review approves it (your own org can use it immediately). ` +
|
|
596
641
|
`Check status with \`parall clip info ${entry.name}\` (review_status / review_note) ` +
|
|
597
642
|
`or GET /api/v1/orgs/${orgId}/clip-registry/${entry.id}.`);
|