dsh-artifact-studio 0.7.1 → 0.7.3
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/THIRD_PARTY_NOTICES.md +3 -2
- package/assets/canvas.engine.js +1 -1
- package/client.canvas.js +1 -1
- package/client.doc.js +79 -67
- package/client.js +3 -3
- package/dist/host/lib/rpc.js +0 -11
- package/dist/host/lib/service.js +0 -19
- package/dist/host/lib/skill.js +10 -2
- package/dist/host/lib/store.js +0 -48
- package/dist/host/lib/tools.js +2 -17
- package/package.json +3 -1
- package/dist/host/lib/editor-leases.js +0 -63
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { ArtifactError } from './errors.js';
|
|
2
|
-
import fs from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { assertWithin, withLock } from './fsutil.js';
|
|
5
|
-
export async function acquireEditor(key, token, check) {
|
|
6
|
-
await withLock(key, async () => {
|
|
7
|
-
await check();
|
|
8
|
-
if (!/^[a-zA-Z0-9-]{1,100}$/.test(token))
|
|
9
|
-
throw new ArtifactError('artifact/bad-request', 'Invalid editor token.');
|
|
10
|
-
const leaseDir = path.join(key, '.editors');
|
|
11
|
-
await assertWithin(key, leaseDir);
|
|
12
|
-
await fs.mkdir(leaseDir, { recursive: true });
|
|
13
|
-
const artifactDirectory = await fs.open(key, 'r');
|
|
14
|
-
try {
|
|
15
|
-
await artifactDirectory.sync();
|
|
16
|
-
}
|
|
17
|
-
finally {
|
|
18
|
-
await artifactDirectory.close();
|
|
19
|
-
}
|
|
20
|
-
const marker = path.join(leaseDir, token);
|
|
21
|
-
await assertWithin(key, marker);
|
|
22
|
-
const handle = await fs.open(marker, 'a', 0o600);
|
|
23
|
-
try {
|
|
24
|
-
await handle.sync();
|
|
25
|
-
}
|
|
26
|
-
finally {
|
|
27
|
-
await handle.close();
|
|
28
|
-
}
|
|
29
|
-
const directory = await fs.open(leaseDir, 'r');
|
|
30
|
-
try {
|
|
31
|
-
await directory.sync();
|
|
32
|
-
}
|
|
33
|
-
finally {
|
|
34
|
-
await directory.close();
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
export async function releaseEditor(key, token) {
|
|
39
|
-
await withLock(key, async () => {
|
|
40
|
-
if (!/^[a-zA-Z0-9-]{1,100}$/.test(token))
|
|
41
|
-
throw new ArtifactError('artifact/bad-request', 'Invalid editor token.');
|
|
42
|
-
const marker = path.join(key, '.editors', token);
|
|
43
|
-
await assertWithin(key, marker);
|
|
44
|
-
await fs.rm(marker, { force: true });
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
/** Call only while holding the same artifact lock as acquireEditor. */
|
|
48
|
-
export async function assertNoEditors(key, ownToken) {
|
|
49
|
-
const directory = path.join(key, '.editors');
|
|
50
|
-
await assertWithin(key, directory);
|
|
51
|
-
let holders;
|
|
52
|
-
try {
|
|
53
|
-
holders = await fs.readdir(directory);
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
if (!(error instanceof Error) || !('code' in error) || error.code !== 'ENOENT')
|
|
57
|
-
throw error;
|
|
58
|
-
holders = [];
|
|
59
|
-
}
|
|
60
|
-
if ((ownToken !== undefined && !holders.includes(ownToken)) || holders.some(token => token !== ownToken)) {
|
|
61
|
-
throw new ArtifactError('artifact/editor-open', 'Close all open editors for this artifact before moving it.');
|
|
62
|
-
}
|
|
63
|
-
}
|