@nyte-ai/host 0.0.18 → 0.0.21
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 +66 -0
- package/dist/chunks/{canvas-preview-rp6fz0w5.js → canvas-preview-2jwbe14k.js} +5 -5
- package/dist/chunks/{canvas-preview-j1tnf51w.js → canvas-preview-3a6tst4d.js} +1 -1
- package/dist/chunks/{canvas-preview-m02v4yy6.js → canvas-preview-55s0y68g.js} +3 -2
- package/dist/chunks/{canvas-preview-xn10d4f8.js → canvas-preview-5ekjx6sw.js} +9 -4
- package/dist/chunks/{canvas-preview-g3qj3y3k.js → canvas-preview-8hr08aeh.js} +13 -3
- package/dist/chunks/{canvas-preview-75db60xy.js → canvas-preview-8xc0vn7v.js} +5 -4
- package/dist/chunks/{canvas-preview-zn2d0k9d.js → canvas-preview-af86jz8t.js} +14 -6
- package/dist/chunks/{canvas-preview-d9wwhbtz.js → canvas-preview-aq5j4p25.js} +1 -1
- package/dist/chunks/{canvas-preview-ewgspmsd.js → canvas-preview-b3r1tna2.js} +1 -1
- package/dist/chunks/canvas-preview-befkjea2.js +60 -0
- package/dist/chunks/canvas-preview-bxnqt8cd.js +103 -0
- package/dist/chunks/{canvas-preview-senpjwep.js → canvas-preview-crmzxxt8.js} +3 -3
- package/dist/chunks/{canvas-preview-ymgz0937.js → canvas-preview-drctegz4.js} +8 -4
- package/dist/chunks/{canvas-preview-yrfz2ak6.js → canvas-preview-e3vnkkc5.js} +6 -6
- package/dist/chunks/canvas-preview-ec2mt7es.js +108 -0
- package/dist/chunks/{canvas-preview-0nrnbt76.js → canvas-preview-eehzfefa.js} +199 -125
- package/dist/chunks/{canvas-preview-5hxat7hh.js → canvas-preview-geg2gckp.js} +8 -6
- package/dist/chunks/{canvas-preview-8xgt67ka.js → canvas-preview-gh7c9831.js} +20 -16
- package/dist/chunks/{canvas-preview-1ta3avah.js → canvas-preview-k2xaz0ym.js} +10 -5
- package/dist/chunks/canvas-preview-kp75gb63.js +141 -0
- package/dist/chunks/{canvas-preview-evh92ywd.js → canvas-preview-mstbvwz3.js} +26 -11
- package/dist/chunks/{canvas-preview-h8hshnff.js → canvas-preview-pkzqg96v.js} +1 -1
- package/dist/chunks/{canvas-preview-ehf3vp31.js → canvas-preview-vm9zdp2t.js} +45 -58
- package/dist/chunks/{canvas-preview-76fwvd6e.js → canvas-preview-w54ymtb3.js} +1 -1
- package/dist/chunks/canvas-preview-y5y6ghaw.js +125 -0
- package/dist/chunks/{canvas-preview-vax9ne4e.js → canvas-preview-y7kq0c8q.js} +22 -11
- package/dist/chunks/{canvas-preview-98aj5p34.js → canvas-preview-ycepb05s.js} +1 -1
- package/dist/src/canvas-preview.js +7 -3
- package/dist/src/deploy/cloudflare/worker.js +1 -1
- package/dist/src/deploy/vercel/server/routes/[...].js +2 -2
- package/dist/src/deploy/vercel/server/utils/host.js +1 -1
- package/dist/src/deploy/vercel/server/workflows/drive.js +3 -3
- package/dist/src/images/exif.d.ts +1 -0
- package/dist/src/images/exif.js +6 -0
- package/dist/src/images/node.d.ts +37 -0
- package/dist/src/images/node.js +12 -0
- package/dist/src/images/photon.d.ts +3 -0
- package/dist/src/images/photon.js +7 -0
- package/dist/src/images/worker.d.ts +1 -0
- package/dist/src/images/worker.js +23 -0
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +23 -22
- package/dist/src/listen-fetch.js +3 -3
- package/dist/src/listen.js +4 -4
- package/dist/src/local/command.d.ts +5 -0
- package/dist/src/local/command.js +6 -2
- package/dist/src/local/files.js +2 -2
- package/dist/src/local/git-watch.d.ts +1 -1
- package/dist/src/local/git-watch.js +1 -1
- package/dist/src/local/git.js +3 -3
- package/dist/src/local/github.js +2 -2
- package/dist/src/local/jobs.d.ts +1 -1
- package/dist/src/local/jobs.js +2 -1
- package/dist/src/local/provider.js +9 -9
- package/dist/src/local/snapshots.js +2 -2
- package/dist/src/local/worktrees.js +2 -2
- package/dist/src/mcp/connect.d.ts +0 -13
- package/dist/src/mcp/connect.js +1 -1
- package/dist/src/mcp/hub.js +2 -2
- package/dist/src/open.d.ts +2 -30
- package/dist/src/open.js +20 -18
- package/dist/src/serve/binding.js +1 -1
- package/dist/src/serve/handler.js +2 -2
- package/dist/src/sqlite.d.ts +2 -1
- package/dist/src/sqlite.js +4 -3
- package/dist/src/store-usage.js +4 -1
- package/dist/src/usage-history.d.ts +54 -0
- package/dist/src/usage-history.js +14 -0
- package/dist/src/usage-service.d.ts +2 -1
- package/dist/src/usage-service.js +7 -3
- package/dist/src/usage-worker.js +8 -4
- package/dist/src/usage.d.ts +150 -27
- package/dist/src/usage.js +12 -2
- package/package.json +16 -8
- package/src/canvas-preview.ts +4 -3
- package/src/images/exif.ts +69 -0
- package/src/images/node.ts +163 -0
- package/src/images/photon.ts +141 -0
- package/src/images/worker.ts +29 -0
- package/src/index.ts +19 -1
- package/src/local/command.ts +64 -12
- package/src/local/files.ts +8 -3
- package/src/local/git-watch.ts +16 -6
- package/src/local/git.ts +7 -2
- package/src/local/github.ts +3 -4
- package/src/local/jobs.ts +55 -69
- package/src/local/snapshots.ts +4 -2
- package/src/local/worktrees.ts +4 -4
- package/src/mcp/connect.ts +1 -14
- package/src/mcp/hub.ts +18 -9
- package/src/open.ts +16 -36
- package/src/serve/binding.ts +4 -3
- package/src/sqlite.ts +46 -9
- package/src/store-usage.ts +5 -2
- package/src/usage-history.ts +219 -0
- package/src/usage-service.ts +12 -3
- package/src/usage.ts +251 -176
- package/dist/chunks/canvas-preview-a3yw0j70.js +0 -72
- package/dist/chunks/canvas-preview-azg56359.js +0 -68
- package/dist/src/store-owner.d.ts +0 -15
- package/dist/src/store-owner.js +0 -9
- package/src/store-owner.ts +0 -98
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
parseNumber2,
|
|
3
|
-
parseText2
|
|
4
|
-
} from "./canvas-preview-69fkk9yn.js";
|
|
5
|
-
|
|
6
|
-
// src/store-owner.ts
|
|
7
|
-
import { resolve } from "node:path";
|
|
8
|
-
import process from "node:process";
|
|
9
|
-
import { DatabaseSync } from "node:sqlite";
|
|
10
|
-
import { SdkError } from "@nyte-ai/schema";
|
|
11
|
-
import { STORE_VERSION } from "@nyte-ai/core/store";
|
|
12
|
-
var CONTEND_MS = 1000;
|
|
13
|
-
var SQLITE_BUSY = 5;
|
|
14
|
-
var claims = new Map;
|
|
15
|
-
|
|
16
|
-
class StoreOwned2 extends SdkError {
|
|
17
|
-
constructor(message) {
|
|
18
|
-
super("unavailable", message);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function claimStore2(path) {
|
|
22
|
-
const key = resolve(path);
|
|
23
|
-
const claim = claims.get(key) ?? { lock: lockStore(key), holders: 0 };
|
|
24
|
-
claims.set(key, claim);
|
|
25
|
-
claim.holders += 1;
|
|
26
|
-
let released = false;
|
|
27
|
-
return () => {
|
|
28
|
-
if (released)
|
|
29
|
-
return;
|
|
30
|
-
released = true;
|
|
31
|
-
claim.holders -= 1;
|
|
32
|
-
if (claim.holders > 0)
|
|
33
|
-
return;
|
|
34
|
-
claims.delete(key);
|
|
35
|
-
claim.lock.close();
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function lockStore(path) {
|
|
39
|
-
const lock = new DatabaseSync(`${path}.owner`, { timeout: CONTEND_MS });
|
|
40
|
-
try {
|
|
41
|
-
reserve(lock, path);
|
|
42
|
-
lock.exec("CREATE TABLE IF NOT EXISTS owner (id INTEGER PRIMARY KEY CHECK (id = 1), pid INTEGER NOT NULL, program TEXT NOT NULL, store INTEGER NOT NULL)");
|
|
43
|
-
lock.prepare("INSERT OR REPLACE INTO owner (id, pid, program, store) VALUES (1, ?, ?, ?)").run(process.pid, process.execPath, STORE_VERSION);
|
|
44
|
-
lock.exec("COMMIT");
|
|
45
|
-
reserve(lock, path);
|
|
46
|
-
} catch (cause) {
|
|
47
|
-
lock.close();
|
|
48
|
-
throw cause;
|
|
49
|
-
}
|
|
50
|
-
return lock;
|
|
51
|
-
}
|
|
52
|
-
function reserve(lock, path) {
|
|
53
|
-
try {
|
|
54
|
-
lock.exec("BEGIN IMMEDIATE");
|
|
55
|
-
} catch (cause) {
|
|
56
|
-
if (!(cause instanceof Error && ("errcode" in cause) && cause.errcode === SQLITE_BUSY))
|
|
57
|
-
throw cause;
|
|
58
|
-
throw new StoreOwned2(`${describeOwner(lock)} has ${path} open. Nyte opens a store in one process at a time; quit that one and try again.`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
function describeOwner(lock) {
|
|
62
|
-
try {
|
|
63
|
-
const row = lock.prepare("SELECT pid, program, store FROM owner WHERE id = 1").get();
|
|
64
|
-
if (row === undefined)
|
|
65
|
-
return "Another Nyte process";
|
|
66
|
-
return `Another Nyte process (pid ${String(parseNumber2(row.pid))}, ${parseText2(row.program)}, store version ${String(parseNumber2(row.store))})`;
|
|
67
|
-
} catch {
|
|
68
|
-
return "Another Nyte process";
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export { StoreOwned2, claimStore2 };
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// src/local/command.ts
|
|
2
|
-
import { spawn } from "node:child_process";
|
|
3
|
-
import { constants } from "node:fs";
|
|
4
|
-
import { access, stat } from "node:fs/promises";
|
|
5
|
-
import { delimiter, isAbsolute, join } from "node:path";
|
|
6
|
-
import { SdkError } from "@nyte-ai/schema";
|
|
7
|
-
import { processEnvironment } from "@nyte-ai/core";
|
|
8
|
-
async function run2(file, args, options) {
|
|
9
|
-
await processEnvironment();
|
|
10
|
-
return new Promise((resolve, reject) => {
|
|
11
|
-
const child = spawn(file, args, {
|
|
12
|
-
cwd: options.cwd,
|
|
13
|
-
env: { ...process.env, ...options.env },
|
|
14
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
15
|
-
windowsHide: true,
|
|
16
|
-
timeout: options.timeoutMs
|
|
17
|
-
});
|
|
18
|
-
const stdout = [];
|
|
19
|
-
const stderr = [];
|
|
20
|
-
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
21
|
-
let size = 0;
|
|
22
|
-
let truncated = false;
|
|
23
|
-
child.on("error", (error) => reject(new SdkError("unavailable", `Cannot run ${file}: ${error.message}`)));
|
|
24
|
-
child.stdout.on("data", (chunk) => {
|
|
25
|
-
if (truncated)
|
|
26
|
-
return;
|
|
27
|
-
size += chunk.byteLength;
|
|
28
|
-
if (size > limit) {
|
|
29
|
-
truncated = true;
|
|
30
|
-
stdout.push(chunk.subarray(0, chunk.byteLength - (size - limit)));
|
|
31
|
-
child.kill("SIGKILL");
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
stdout.push(chunk);
|
|
35
|
-
});
|
|
36
|
-
child.stderr.on("data", (chunk) => stderr.push(chunk));
|
|
37
|
-
child.stdin.on("error", () => {
|
|
38
|
-
return;
|
|
39
|
-
});
|
|
40
|
-
child.on("close", (code) => resolve({
|
|
41
|
-
code,
|
|
42
|
-
stdout: Buffer.concat(stdout),
|
|
43
|
-
stderr: Buffer.concat(stderr).toString("utf8"),
|
|
44
|
-
truncated
|
|
45
|
-
}));
|
|
46
|
-
child.stdin.end(options.input);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
async function findExecutable2(name, directories = []) {
|
|
50
|
-
if (isAbsolute(name))
|
|
51
|
-
return await executable(name) ? name : null;
|
|
52
|
-
await processEnvironment();
|
|
53
|
-
const path = (process.env.PATH ?? "").split(delimiter).filter((entry) => entry !== "");
|
|
54
|
-
const extensions = process.platform === "win32" ? ["", ...(process.env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";")] : [""];
|
|
55
|
-
for (const directory of [...directories, ...path])
|
|
56
|
-
for (const extension of extensions) {
|
|
57
|
-
const candidate = join(directory, `${name}${extension}`);
|
|
58
|
-
if (await executable(candidate))
|
|
59
|
-
return candidate;
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
async function executable(path) {
|
|
64
|
-
const found = await stat(path).catch(() => null);
|
|
65
|
-
return found !== null && found.isFile() && await access(path, constants.X_OK).then(() => true, () => false);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export { run2, findExecutable2 };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { SdkError } from "@nyte-ai/schema";
|
|
2
|
-
/** Another live process owns the store, so this one can't open it; the message names the owner. */
|
|
3
|
-
export declare class StoreOwned extends SdkError {
|
|
4
|
-
constructor(message: string);
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Makes this process the one owner of the file store at `path`, which alone opens,
|
|
8
|
-
* migrates and writes it, and returns what gives the claim up. The claim is a write lock
|
|
9
|
-
* this process holds on `<path>.owner`, a SQLite file whose one row names the owner's pid,
|
|
10
|
-
* program and store version; the operating system drops the lock when the process exits,
|
|
11
|
-
* so a crashed owner leaves no claim to clear. Claims of one path in this process share
|
|
12
|
-
* the lock until the last is given up. Throws `StoreOwned`, an `SdkError("unavailable")`
|
|
13
|
-
* naming the owner, when another process holds the claim.
|
|
14
|
-
*/
|
|
15
|
-
export declare function claimStore(path: string): () => void;
|
package/dist/src/store-owner.js
DELETED
package/src/store-owner.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { resolve } from "node:path";
|
|
2
|
-
import process from "node:process";
|
|
3
|
-
import { DatabaseSync } from "node:sqlite";
|
|
4
|
-
import { SdkError } from "@nyte-ai/schema";
|
|
5
|
-
import { STORE_VERSION } from "@nyte-ai/core/store";
|
|
6
|
-
import { parseNumber, parseText } from "./store-rows.ts";
|
|
7
|
-
|
|
8
|
-
const CONTEND_MS = 1_000;
|
|
9
|
-
|
|
10
|
-
const SQLITE_BUSY = 5;
|
|
11
|
-
|
|
12
|
-
interface Claim {
|
|
13
|
-
readonly lock: DatabaseSync;
|
|
14
|
-
holders: number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const claims = new Map<string, Claim>();
|
|
18
|
-
|
|
19
|
-
/** Another live process owns the store, so this one can't open it; the message names the owner. */
|
|
20
|
-
export class StoreOwned extends SdkError {
|
|
21
|
-
constructor(message: string) {
|
|
22
|
-
super("unavailable", message);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Makes this process the one owner of the file store at `path`, which alone opens,
|
|
28
|
-
* migrates and writes it, and returns what gives the claim up. The claim is a write lock
|
|
29
|
-
* this process holds on `<path>.owner`, a SQLite file whose one row names the owner's pid,
|
|
30
|
-
* program and store version; the operating system drops the lock when the process exits,
|
|
31
|
-
* so a crashed owner leaves no claim to clear. Claims of one path in this process share
|
|
32
|
-
* the lock until the last is given up. Throws `StoreOwned`, an `SdkError("unavailable")`
|
|
33
|
-
* naming the owner, when another process holds the claim.
|
|
34
|
-
*/
|
|
35
|
-
export function claimStore(path: string): () => void {
|
|
36
|
-
const key = resolve(path);
|
|
37
|
-
const claim = claims.get(key) ?? { lock: lockStore(key), holders: 0 };
|
|
38
|
-
claims.set(key, claim);
|
|
39
|
-
claim.holders += 1;
|
|
40
|
-
let released = false;
|
|
41
|
-
|
|
42
|
-
return () => {
|
|
43
|
-
if (released) return;
|
|
44
|
-
released = true;
|
|
45
|
-
claim.holders -= 1;
|
|
46
|
-
|
|
47
|
-
if (claim.holders > 0) return;
|
|
48
|
-
claims.delete(key);
|
|
49
|
-
claim.lock.close();
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function lockStore(path: string): DatabaseSync {
|
|
54
|
-
const lock = new DatabaseSync(`${path}.owner`, { timeout: CONTEND_MS });
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
reserve(lock, path);
|
|
58
|
-
lock.exec(
|
|
59
|
-
"CREATE TABLE IF NOT EXISTS owner (id INTEGER PRIMARY KEY CHECK (id = 1), pid INTEGER NOT NULL, program TEXT NOT NULL, store INTEGER NOT NULL)",
|
|
60
|
-
);
|
|
61
|
-
lock
|
|
62
|
-
.prepare("INSERT OR REPLACE INTO owner (id, pid, program, store) VALUES (1, ?, ?, ?)")
|
|
63
|
-
.run(process.pid, process.execPath, STORE_VERSION);
|
|
64
|
-
lock.exec("COMMIT");
|
|
65
|
-
reserve(lock, path);
|
|
66
|
-
} catch (cause) {
|
|
67
|
-
lock.close();
|
|
68
|
-
|
|
69
|
-
throw cause;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return lock;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function reserve(lock: DatabaseSync, path: string): void {
|
|
76
|
-
try {
|
|
77
|
-
lock.exec("BEGIN IMMEDIATE");
|
|
78
|
-
} catch (cause) {
|
|
79
|
-
if (!(cause instanceof Error && "errcode" in cause && cause.errcode === SQLITE_BUSY))
|
|
80
|
-
throw cause;
|
|
81
|
-
|
|
82
|
-
throw new StoreOwned(
|
|
83
|
-
`${describeOwner(lock)} has ${path} open. Nyte opens a store in one process at a time; quit that one and try again.`,
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function describeOwner(lock: DatabaseSync): string {
|
|
89
|
-
try {
|
|
90
|
-
const row = lock.prepare("SELECT pid, program, store FROM owner WHERE id = 1").get();
|
|
91
|
-
|
|
92
|
-
if (row === undefined) return "Another Nyte process";
|
|
93
|
-
|
|
94
|
-
return `Another Nyte process (pid ${String(parseNumber(row.pid))}, ${parseText(row.program)}, store version ${String(parseNumber(row.store))})`;
|
|
95
|
-
} catch {
|
|
96
|
-
return "Another Nyte process";
|
|
97
|
-
}
|
|
98
|
-
}
|