@vivix-labs/studio-workbench 1.0.0-beta.6 → 1.0.0-beta.9
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/assets/crop-5JXWHIPN.svg +6 -0
- package/dist/assets/trim-LQMHHN2M.svg +9 -0
- package/dist/assets/welcome-add-HS6LIH63.svg +5 -0
- package/dist/assets/welcome-close-NOBXBZOT.svg +5 -0
- package/dist/assets/welcome-product-ad-YRPDJRAH.png +0 -0
- package/dist/assets/welcome-short-drama-YDTZHBGK.png +0 -0
- package/dist/client.bundle.js +1366 -962
- package/dist/client.css +597 -109
- package/dist/server.js +261 -39
- package/package.json +23 -23
- package/presets/table.json +4 -4
- package/presets/user-base.json +9 -9
- package/skills/SKILL.md +4 -3
- package/skills/scripts/initialize-home.mjs +155 -119
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
import { execFile, spawn } from 'node:child_process';
|
|
2
|
-
import { mkdir, readFile,
|
|
2
|
+
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
|
-
import { basename, dirname, join, resolve
|
|
5
|
-
import {
|
|
6
|
-
import { promisify } from 'node:util';
|
|
4
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
5
|
+
import { parseArgs, promisify } from 'node:util';
|
|
7
6
|
|
|
8
7
|
const exec = promisify(execFile);
|
|
9
|
-
const
|
|
10
|
-
|
|
8
|
+
const { values } = parseArgs({
|
|
9
|
+
options: {
|
|
10
|
+
help: { type: 'boolean' },
|
|
11
|
+
'no-open': { type: 'boolean' },
|
|
12
|
+
sample: { type: 'string' },
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
if (values.help) {
|
|
11
16
|
console.log(
|
|
12
|
-
'Usage: node initialize-home.mjs [--no-open] [--
|
|
17
|
+
'Usage: node initialize-home.mjs [--no-open] [--sample out-of-steps|cobalt-headphones]\nUse VIVIX_STUDIO_CLI to select a CLI executable or built JS entry.',
|
|
13
18
|
);
|
|
14
19
|
process.exit(0);
|
|
15
20
|
}
|
|
16
|
-
if (args.some((arg) => !['--no-open', '--add-cobalt'].includes(arg)))
|
|
17
|
-
throw Error('Unknown option. Use --help.');
|
|
18
21
|
const executable = process.env.VIVIX_STUDIO_CLI || 'vivix-studio';
|
|
19
22
|
const js = /\.[cm]?js$/.test(executable);
|
|
20
23
|
const command = js ? process.execPath : executable;
|
|
21
24
|
const prefix = js ? [resolve(executable)] : [];
|
|
22
|
-
const root =
|
|
25
|
+
const root = process.env.XDG_CONFIG_HOME
|
|
26
|
+
? join(process.env.XDG_CONFIG_HOME, 'vivix-studio')
|
|
27
|
+
: join(homedir(), '.vivix-studio');
|
|
23
28
|
const userPackage = JSON.parse(
|
|
24
29
|
await readFile(new URL('../../package.json', import.meta.url), 'utf8'),
|
|
25
30
|
);
|
|
26
31
|
const userPreset = `${userPackage.name}@${userPackage.version}:user-base`;
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
{ id: 'cobalt-headphones', preset: adsPreset, skill: 'vivix-cobalt-example' },
|
|
34
|
-
];
|
|
32
|
+
const samples = {
|
|
33
|
+
'out-of-steps': { package: '@vivix-labs/short-drama-workbench', presetId: 'short-drama' },
|
|
34
|
+
'cobalt-headphones': { package: '@vivix-labs/ads-workbench', presetId: 'ads' },
|
|
35
|
+
};
|
|
36
|
+
const sample = values.sample;
|
|
37
|
+
if (sample !== undefined && !Object.hasOwn(samples, sample)) throw Error('Unknown sample.');
|
|
35
38
|
const access =
|
|
36
39
|
'project.content.read,project.content.write,official.request,events.publish,events.subscribe';
|
|
37
40
|
const homeState = join(root, 'home-initialization.json');
|
|
@@ -43,20 +46,6 @@ const save = async () => {
|
|
|
43
46
|
await rename(homeState + '.tmp', homeState);
|
|
44
47
|
};
|
|
45
48
|
|
|
46
|
-
async function linkedSeed(project, skill, packageName, version) {
|
|
47
|
-
const links = join(project.root, '.agents', 'skills');
|
|
48
|
-
const pluginRoot = await realpath(join(root, 'plugins'));
|
|
49
|
-
for (const entry of await readdir(links, { withFileTypes: true })) {
|
|
50
|
-
if (!entry.isSymbolicLink()) continue;
|
|
51
|
-
const target = await realpath(join(links, entry.name)).catch(() => null);
|
|
52
|
-
if (!target?.startsWith(pluginRoot + sep) || basename(target) !== skill) continue;
|
|
53
|
-
const pkg = await read(join(target, '..', '..', 'package.json'));
|
|
54
|
-
if (pkg.name === packageName && pkg.version === version)
|
|
55
|
-
return join(target, 'scripts', 'initialize.mjs');
|
|
56
|
-
}
|
|
57
|
-
throw Error('Cannot find the installed seed Skill: ' + skill);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
49
|
async function cli(...arguments_) {
|
|
61
50
|
let stdout;
|
|
62
51
|
try {
|
|
@@ -79,12 +68,19 @@ function interrupt(signal) {
|
|
|
79
68
|
}
|
|
80
69
|
function runSeed(path, project) {
|
|
81
70
|
return new Promise((done, reject) => {
|
|
82
|
-
child = spawn(process.execPath, [path, '--project', project, '--apply'], {
|
|
71
|
+
child = spawn(process.execPath, [path, '--project', project, '--apply'], {
|
|
72
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
73
|
+
});
|
|
74
|
+
let failure = '';
|
|
75
|
+
child.stderr.setEncoding('utf8').on('data', (chunk) => {
|
|
76
|
+
failure = (failure + chunk).slice(-4096);
|
|
77
|
+
});
|
|
83
78
|
child.on('error', reject);
|
|
84
79
|
child.on('close', (code) => {
|
|
85
80
|
child = undefined;
|
|
86
81
|
if (code === 0) done();
|
|
87
|
-
else
|
|
82
|
+
else
|
|
83
|
+
reject(Error(failure.trim() || 'Example import stopped. Rerun initialization to resume.'));
|
|
88
84
|
});
|
|
89
85
|
});
|
|
90
86
|
}
|
|
@@ -92,6 +88,51 @@ function assertRunning() {
|
|
|
92
88
|
if (stopped) throw Error('Initialization stopped. Rerun it to resume.');
|
|
93
89
|
}
|
|
94
90
|
|
|
91
|
+
async function warmDramaWorkbenches() {
|
|
92
|
+
const { stdout } = await exec(command, [...prefix, 'preset', '--help']);
|
|
93
|
+
if (!stdout.includes('warm-client')) return;
|
|
94
|
+
const name = samples['out-of-steps'].package;
|
|
95
|
+
const version = userPackage.vivixStudio.runtimePlugins[name];
|
|
96
|
+
for (const id of ['out-of-steps', 'short-drama'])
|
|
97
|
+
await cli('preset', 'warm-client', `${name}@${version}:${id}`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function configureDramaChat(projectId) {
|
|
101
|
+
// Trial setup can enable chat before the on-demand drama project exists.
|
|
102
|
+
const user = await cli('plugin', 'list', '--scope', 'user');
|
|
103
|
+
const chat = user.instances.find(
|
|
104
|
+
(item) =>
|
|
105
|
+
item.id === 'chat-components' &&
|
|
106
|
+
item.package === '@vivix-labs/chat-components' &&
|
|
107
|
+
item.state === 'ready',
|
|
108
|
+
);
|
|
109
|
+
if (!chat) return;
|
|
110
|
+
const project = await cli('plugin', 'list', '--project', projectId);
|
|
111
|
+
if (project.instances.some((item) => item.id === chat.id)) return;
|
|
112
|
+
const config = join(lock, 'chat-components.json');
|
|
113
|
+
await writeFile(
|
|
114
|
+
config,
|
|
115
|
+
JSON.stringify({
|
|
116
|
+
targets: { character: { instanceId: 'authoring', operationId: 'characters.receiveCard' } },
|
|
117
|
+
}),
|
|
118
|
+
{ mode: 0o600 },
|
|
119
|
+
);
|
|
120
|
+
await cli(
|
|
121
|
+
'plugin',
|
|
122
|
+
'enable',
|
|
123
|
+
chat.package,
|
|
124
|
+
'--version',
|
|
125
|
+
chat.version,
|
|
126
|
+
'--project',
|
|
127
|
+
projectId,
|
|
128
|
+
'--instance',
|
|
129
|
+
chat.id,
|
|
130
|
+
'--config',
|
|
131
|
+
config,
|
|
132
|
+
'--trust',
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
95
136
|
await mkdir(dirname(homeState), { recursive: true, mode: 0o700 });
|
|
96
137
|
try {
|
|
97
138
|
await mkdir(lock, { mode: 0o700 });
|
|
@@ -112,79 +153,77 @@ try {
|
|
|
112
153
|
} catch (error) {
|
|
113
154
|
if (error.code !== 'ENOENT') throw error;
|
|
114
155
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (
|
|
134
|
-
!drama ||
|
|
135
|
-
!presets.some(
|
|
136
|
-
(item) =>
|
|
137
|
-
item.package === adsPackage && item.version === adsVersion && item.presetId === 'ads',
|
|
138
|
-
) ||
|
|
139
|
-
!['user-base'].every((presetId) =>
|
|
140
|
-
presets.some(
|
|
141
|
-
(item) =>
|
|
142
|
-
item.package === userPackage.name &&
|
|
143
|
-
item.version === userPackage.version &&
|
|
144
|
-
item.presetId === presetId,
|
|
145
|
-
),
|
|
146
|
-
)
|
|
147
|
-
)
|
|
148
|
-
throw Error(
|
|
149
|
-
'Install the matching Home, Short Drama and Advertising preset packages before initializing Home.',
|
|
156
|
+
if (!state.workspace) {
|
|
157
|
+
const user = await cli('plugin', 'list', '--scope', 'user');
|
|
158
|
+
if (user.instances.length) {
|
|
159
|
+
const installed = user.instances.find((item) => item.id === 'workbench');
|
|
160
|
+
if (installed?.package !== userPackage.name || installed.version !== userPackage.version)
|
|
161
|
+
throw Error(
|
|
162
|
+
'This profile already has a different user workbench. Use a fresh profile for first setup.',
|
|
163
|
+
);
|
|
164
|
+
} else {
|
|
165
|
+
await cli(
|
|
166
|
+
'preset',
|
|
167
|
+
'apply',
|
|
168
|
+
userPreset,
|
|
169
|
+
'--scope',
|
|
170
|
+
'user',
|
|
171
|
+
'--trust',
|
|
172
|
+
'--allow-access',
|
|
173
|
+
access,
|
|
150
174
|
);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
175
|
+
}
|
|
176
|
+
state.workspace = true;
|
|
177
|
+
await save();
|
|
178
|
+
}
|
|
179
|
+
if (sample) {
|
|
180
|
+
assertRunning();
|
|
181
|
+
const directory = join(root, 'projects', 'studio-home-examples', sample);
|
|
182
|
+
const { projects } = await cli('project', 'list');
|
|
183
|
+
let receipt = state.projects[sample];
|
|
184
|
+
if (!receipt && sample === 'out-of-steps') {
|
|
185
|
+
// Match the browser creation receipt, so CLI and Welcome share the prepared project.
|
|
186
|
+
const requestId = '66067767-ff7a-4c73-9cd2-debde07b6ea2';
|
|
187
|
+
for (const project of projects) {
|
|
188
|
+
if (!project.available || basename(project.root) !== `project-${requestId}`) continue;
|
|
189
|
+
const created = await read(join(project.root, '.vivix/workbench-create.json')).catch(
|
|
190
|
+
(error) => {
|
|
191
|
+
if (error.code !== 'ENOENT') throw error;
|
|
192
|
+
return undefined;
|
|
193
|
+
},
|
|
169
194
|
);
|
|
195
|
+
if (created?.requestId !== requestId || !created.preset.endsWith(':out-of-steps')) continue;
|
|
196
|
+
await read(join(project.root, '.vivix/out-of-steps.initialized.json'));
|
|
197
|
+
receipt = state.projects[sample] = {
|
|
198
|
+
directory: project.root,
|
|
199
|
+
preset: created.preset,
|
|
200
|
+
projectId: project.id,
|
|
201
|
+
complete: true,
|
|
202
|
+
};
|
|
203
|
+
await save();
|
|
170
204
|
}
|
|
171
|
-
state.workspace = true;
|
|
172
|
-
await save();
|
|
173
205
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
|
|
206
|
+
if (!receipt?.complete) {
|
|
207
|
+
const spec = samples[sample];
|
|
208
|
+
const samplePreset = `${spec.package}@${userPackage.vivixStudio.runtimePlugins[spec.package]}:${spec.presetId}`;
|
|
209
|
+
const { presets } = await cli('preset', 'list');
|
|
210
|
+
const preparedPreset = samplePreset.replace(/:short-drama$/, ':out-of-steps');
|
|
211
|
+
const hasPrepared =
|
|
212
|
+
sample === 'out-of-steps' &&
|
|
213
|
+
presets.some(
|
|
214
|
+
(item) => `${item.package}@${item.version}:${item.presetId}` === preparedPreset,
|
|
215
|
+
);
|
|
216
|
+
const preset = receipt?.preset ?? (hasPrepared ? preparedPreset : samplePreset);
|
|
217
|
+
const installed = presets.find(
|
|
218
|
+
(item) => `${item.package}@${item.version}:${item.presetId}` === samplePreset,
|
|
219
|
+
);
|
|
220
|
+
if (!installed) throw Error('Install the matching workbench plugin to load this sample.');
|
|
181
221
|
if (!receipt) {
|
|
182
222
|
if (projects.some((item) => item.root === directory))
|
|
183
223
|
throw Error('The example directory is already registered: ' + directory);
|
|
184
|
-
receipt = state.projects[
|
|
224
|
+
receipt = state.projects[sample] = { directory, preset };
|
|
185
225
|
await save();
|
|
186
226
|
}
|
|
187
|
-
if (receipt.complete) continue;
|
|
188
227
|
if (!receipt.projectId) {
|
|
189
228
|
const registered = projects.find(
|
|
190
229
|
(item) => item.root === receipt.directory && item.available,
|
|
@@ -194,7 +233,7 @@ try {
|
|
|
194
233
|
(await cli(
|
|
195
234
|
'project',
|
|
196
235
|
'init',
|
|
197
|
-
|
|
236
|
+
sample,
|
|
198
237
|
'--directory',
|
|
199
238
|
receipt.directory,
|
|
200
239
|
'--preset',
|
|
@@ -207,32 +246,29 @@ try {
|
|
|
207
246
|
await save();
|
|
208
247
|
}
|
|
209
248
|
assertRunning();
|
|
210
|
-
|
|
211
|
-
(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
project,
|
|
220
|
-
spec.skill,
|
|
221
|
-
drama.package,
|
|
222
|
-
receipt.preset.split('@').at(-1).split(':')[0],
|
|
223
|
-
);
|
|
224
|
-
await runSeed(seed, project.id);
|
|
249
|
+
if (receipt.preset.endsWith(':out-of-steps')) {
|
|
250
|
+
await read(join(receipt.directory, '.vivix/out-of-steps.initialized.json'));
|
|
251
|
+
} else {
|
|
252
|
+
await runSeed(
|
|
253
|
+
join(installed.packageRoot, 'samples', sample, 'scripts/initialize.mjs'),
|
|
254
|
+
receipt.projectId,
|
|
255
|
+
);
|
|
256
|
+
if (sample === 'out-of-steps') await configureDramaChat(receipt.projectId);
|
|
257
|
+
}
|
|
225
258
|
receipt.complete = true;
|
|
226
259
|
await save();
|
|
227
260
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
261
|
+
const project = (await cli('project', 'list')).projects.find(
|
|
262
|
+
(item) => item.id === receipt.projectId && item.available,
|
|
263
|
+
);
|
|
264
|
+
if (!project) throw Error('The sample project is unavailable: ' + receipt.projectId);
|
|
265
|
+
console.log(JSON.stringify({ ok: true, project }));
|
|
266
|
+
} else if (values['no-open']) {
|
|
267
|
+
await warmDramaWorkbenches();
|
|
233
268
|
const { workbenchUrl } = await cli('project', 'open', '--scope', 'user', '--no-open');
|
|
234
269
|
console.log(JSON.stringify({ ok: true, projects: state.projects, workbenchUrl }));
|
|
235
270
|
} else {
|
|
271
|
+
await warmDramaWorkbenches();
|
|
236
272
|
await exec(command, [...prefix, 'project', 'open', '--scope', 'user']);
|
|
237
273
|
}
|
|
238
274
|
} catch (error) {
|