@nyte-ai/host 0.0.0-stage → 0.0.18
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 +6 -2
- package/THIRD-PARTY-NOTICES.md +800 -0
- package/dist/chunks/canvas-preview-0cmbkp2j.js +65 -0
- package/dist/chunks/canvas-preview-0nq75h9k.js +7 -0
- package/dist/chunks/canvas-preview-0nrnbt76.js +497 -0
- package/dist/chunks/canvas-preview-1sq7z9jq.js +17 -0
- package/dist/chunks/canvas-preview-1ta3avah.js +56 -0
- package/dist/chunks/canvas-preview-2zdyh9ny.js +26 -0
- package/dist/chunks/canvas-preview-31w7xm8z.js +34 -0
- package/dist/chunks/canvas-preview-4b6sayhg.js +295 -0
- package/dist/chunks/canvas-preview-4e0pxa32.js +63 -0
- package/dist/chunks/canvas-preview-518dh8by.js +169 -0
- package/dist/chunks/canvas-preview-5hxat7hh.js +239 -0
- package/dist/chunks/canvas-preview-5mex725c.js +14 -0
- package/dist/chunks/canvas-preview-5z63am63.js +295 -0
- package/dist/chunks/canvas-preview-65xqjw7f.js +20 -0
- package/dist/chunks/canvas-preview-69fkk9yn.js +95 -0
- package/dist/chunks/canvas-preview-75db60xy.js +457 -0
- package/dist/chunks/canvas-preview-76fwvd6e.js +272 -0
- package/dist/chunks/canvas-preview-8xgt67ka.js +598 -0
- package/dist/chunks/canvas-preview-98aj5p34.js +176 -0
- package/dist/chunks/canvas-preview-9aqczacs.js +73 -0
- package/dist/chunks/canvas-preview-a3yw0j70.js +72 -0
- package/dist/chunks/canvas-preview-azg56359.js +68 -0
- package/dist/chunks/canvas-preview-d9wwhbtz.js +240 -0
- package/dist/chunks/canvas-preview-ehf3vp31.js +411 -0
- package/dist/chunks/canvas-preview-evh92ywd.js +369 -0
- package/dist/chunks/canvas-preview-ewgspmsd.js +81 -0
- package/dist/chunks/canvas-preview-g3qj3y3k.js +156 -0
- package/dist/chunks/canvas-preview-h8hshnff.js +63 -0
- package/dist/chunks/canvas-preview-j1tnf51w.js +36 -0
- package/dist/chunks/canvas-preview-kdqgrstc.js +194 -0
- package/dist/chunks/canvas-preview-kn7kvbfj.js +12 -0
- package/dist/chunks/canvas-preview-m02v4yy6.js +386 -0
- package/dist/chunks/canvas-preview-mgcx2b2p.js +271 -0
- package/dist/chunks/canvas-preview-rp4x6y1h.js +144 -0
- package/dist/chunks/canvas-preview-rp6fz0w5.js +130 -0
- package/dist/chunks/canvas-preview-s94ebwf5.js +112 -0
- package/dist/chunks/canvas-preview-senpjwep.js +518 -0
- package/dist/chunks/canvas-preview-skzwvw4d.js +23 -0
- package/dist/chunks/canvas-preview-srgfpdmf.js +60 -0
- package/dist/chunks/canvas-preview-tjhabynd.js +252 -0
- package/dist/chunks/canvas-preview-vaatfznm.js +189 -0
- package/dist/chunks/canvas-preview-vax9ne4e.js +341 -0
- package/dist/chunks/canvas-preview-wg80rbc2.js +46 -0
- package/dist/chunks/canvas-preview-xn10d4f8.js +608 -0
- package/dist/chunks/canvas-preview-yjz0f7n4.js +50 -0
- package/dist/chunks/canvas-preview-ymgz0937.js +587 -0
- package/dist/chunks/canvas-preview-yrfz2ak6.js +134 -0
- package/dist/chunks/canvas-preview-zaaj99wd.js +244 -0
- package/dist/chunks/canvas-preview-zn2d0k9d.js +133 -0
- package/dist/src/canvas-preview.d.ts +29 -0
- package/dist/src/canvas-preview.js +267 -0
- package/dist/src/credentials.d.ts +44 -0
- package/dist/src/credentials.js +10 -0
- package/dist/src/deploy/cloudflare/worker.d.ts +50 -0
- package/dist/src/deploy/cloudflare/worker.js +196 -0
- package/dist/src/deploy/vercel/nitro.config.d.ts +2 -0
- package/dist/src/deploy/vercel/nitro.config.js +30 -0
- package/dist/src/deploy/vercel/server/routes/[...].d.ts +2 -0
- package/dist/src/deploy/vercel/server/routes/[...].js +18 -0
- package/dist/src/deploy/vercel/server/utils/host.d.ts +13 -0
- package/dist/src/deploy/vercel/server/utils/host.js +7 -0
- package/dist/src/deploy/vercel/server/utils/repair.d.ts +1 -0
- package/dist/src/deploy/vercel/server/utils/repair.js +6 -0
- package/dist/src/deploy/vercel/server/utils/step.d.ts +10 -0
- package/dist/src/deploy/vercel/server/utils/step.js +6 -0
- package/dist/src/deploy/vercel/server/workflows/drive.d.ts +14 -0
- package/dist/src/deploy/vercel/server/workflows/drive.js +13 -0
- package/dist/src/durable-object.d.ts +14 -0
- package/dist/src/durable-object.js +231 -0
- package/dist/src/hash.d.ts +1 -0
- package/dist/src/hash.js +6 -0
- package/dist/src/identity-key.d.ts +11 -0
- package/dist/src/identity-key.js +9 -0
- package/dist/src/identity.d.ts +12 -0
- package/dist/src/identity.js +6 -0
- package/dist/src/index.d.ts +21 -0
- package/dist/src/index.js +120 -0
- package/dist/src/key-file.d.ts +1 -0
- package/dist/src/key-file.js +7 -0
- package/dist/src/listen-fetch.d.ts +8 -0
- package/dist/src/listen-fetch.js +9 -0
- package/dist/src/listen.d.ts +4 -0
- package/dist/src/listen.js +10 -0
- package/dist/src/local/command.d.ts +15 -0
- package/dist/src/local/command.js +8 -0
- package/dist/src/local/feed.d.ts +7 -0
- package/dist/src/local/feed.js +6 -0
- package/dist/src/local/files.d.ts +18 -0
- package/dist/src/local/files.js +13 -0
- package/dist/src/local/git-watch.d.ts +15 -0
- package/dist/src/local/git-watch.js +7 -0
- package/dist/src/local/git.d.ts +5 -0
- package/dist/src/local/git.js +13 -0
- package/dist/src/local/github.d.ts +30 -0
- package/dist/src/local/github.js +9 -0
- package/dist/src/local/identity.d.ts +3 -0
- package/dist/src/local/identity.js +7 -0
- package/dist/src/local/jobs.d.ts +7 -0
- package/dist/src/local/jobs.js +6 -0
- package/dist/src/local/legacy-trust.d.ts +10 -0
- package/dist/src/local/legacy-trust.js +6 -0
- package/dist/src/local/patch.d.ts +16 -0
- package/dist/src/local/patch.js +17 -0
- package/dist/src/local/provider.d.ts +11 -0
- package/dist/src/local/provider.js +20 -0
- package/dist/src/local/snapshots.d.ts +7 -0
- package/dist/src/local/snapshots.js +11 -0
- package/dist/src/local/text.d.ts +1 -0
- package/dist/src/local/text.js +6 -0
- package/dist/src/local/tree.d.ts +50 -0
- package/dist/src/local/tree.js +16 -0
- package/dist/src/local/workspace-migration.d.ts +2 -0
- package/dist/src/local/workspace-migration.js +7 -0
- package/dist/src/local/worktrees.d.ts +46 -0
- package/dist/src/local/worktrees.js +14 -0
- package/dist/src/mcp/config.d.ts +75 -0
- package/dist/src/mcp/config.js +12 -0
- package/dist/src/mcp/connect.d.ts +28 -0
- package/dist/src/mcp/connect.js +9 -0
- package/dist/src/mcp/hub.d.ts +19 -0
- package/dist/src/mcp/hub.js +11 -0
- package/dist/src/mcp/oauth.d.ts +46 -0
- package/dist/src/mcp/oauth.js +12 -0
- package/dist/src/mcp/tools.d.ts +29 -0
- package/dist/src/mcp/tools.js +12 -0
- package/dist/src/open.d.ts +42 -0
- package/dist/src/open.js +44 -0
- package/dist/src/plugins/loader.d.ts +21 -0
- package/dist/src/plugins/loader.js +11 -0
- package/dist/src/postgres.d.ts +19 -0
- package/dist/src/postgres.js +8 -0
- package/dist/src/providers.d.ts +16 -0
- package/dist/src/providers.js +112 -0
- package/dist/src/secrets.d.ts +12 -0
- package/dist/src/secrets.js +8 -0
- package/dist/src/serve/binding.d.ts +39 -0
- package/dist/src/serve/binding.js +6 -0
- package/dist/src/serve/handler.d.ts +15 -0
- package/dist/src/serve/handler.js +8 -0
- package/dist/src/serve/stream-server.d.ts +6 -0
- package/dist/src/serve/stream-server.js +6 -0
- package/dist/src/session-index.d.ts +11 -0
- package/dist/src/session-index.js +11 -0
- package/dist/src/shell-env.d.ts +14 -0
- package/dist/src/shell-env.js +108 -0
- package/dist/src/sqlite-workers.d.ts +6 -0
- package/dist/src/sqlite-workers.js +6 -0
- package/dist/src/sqlite.d.ts +7 -0
- package/dist/src/sqlite.js +10 -0
- package/dist/src/store-owner.d.ts +15 -0
- package/dist/src/store-owner.js +9 -0
- package/dist/src/store-rows.d.ts +13 -0
- package/dist/src/store-rows.js +26 -0
- package/dist/src/store-usage.d.ts +25 -0
- package/dist/src/store-usage.js +16 -0
- package/dist/src/usage-scan.d.ts +24 -0
- package/dist/src/usage-scan.js +65 -0
- package/dist/src/usage-service.d.ts +22 -0
- package/dist/src/usage-service.js +12 -0
- package/dist/src/usage-summary.d.ts +9 -0
- package/dist/src/usage-summary.js +16 -0
- package/dist/src/usage-types.d.ts +86 -0
- package/dist/src/usage-types.js +0 -0
- package/dist/src/usage-worker.d.ts +1 -0
- package/dist/src/usage-worker.js +25 -0
- package/dist/src/usage.d.ts +72 -0
- package/dist/src/usage.js +13 -0
- package/package.json +132 -3
- package/src/canvas-preview.ts +402 -0
- package/src/credentials.ts +294 -0
- package/src/deploy/cloudflare/README.md +3 -0
- package/src/deploy/cloudflare/worker.ts +306 -0
- package/src/deploy/cloudflare/wrangler.jsonc +12 -0
- package/src/deploy/vercel/README.md +3 -0
- package/src/deploy/vercel/nitro.config.ts +29 -0
- package/src/deploy/vercel/server/routes/[...].ts +10 -0
- package/src/deploy/vercel/server/utils/host.ts +104 -0
- package/src/deploy/vercel/server/utils/repair.ts +35 -0
- package/src/deploy/vercel/server/utils/step.ts +25 -0
- package/src/deploy/vercel/server/workflows/drive.ts +46 -0
- package/src/deploy/vercel/tsconfig.json +9 -0
- package/src/deploy/vercel/types/bun.d.ts +2 -0
- package/src/durable-object.ts +386 -0
- package/src/hash.ts +5 -0
- package/src/identity-key.ts +20 -0
- package/src/identity.ts +66 -0
- package/src/index.ts +21 -0
- package/src/key-file.ts +53 -0
- package/src/listen-fetch.ts +409 -0
- package/src/listen.ts +228 -0
- package/src/local/command.ts +109 -0
- package/src/local/feed.ts +70 -0
- package/src/local/files.ts +812 -0
- package/src/local/git-watch.ts +189 -0
- package/src/local/git.ts +914 -0
- package/src/local/github.ts +692 -0
- package/src/local/identity.ts +21 -0
- package/src/local/jobs.ts +587 -0
- package/src/local/legacy-trust.ts +105 -0
- package/src/local/patch.ts +334 -0
- package/src/local/provider.ts +184 -0
- package/src/local/snapshots.ts +776 -0
- package/src/local/text.ts +9 -0
- package/src/local/tree.ts +398 -0
- package/src/local/workspace-migration.ts +95 -0
- package/src/local/worktrees.ts +239 -0
- package/src/mcp/config.ts +330 -0
- package/src/mcp/connect.ts +105 -0
- package/src/mcp/hub.ts +836 -0
- package/src/mcp/oauth.ts +436 -0
- package/src/mcp/tools.ts +333 -0
- package/src/open.ts +469 -0
- package/src/plugins/loader.ts +186 -0
- package/src/postgres.ts +492 -0
- package/src/providers.ts +135 -0
- package/src/secrets.ts +31 -0
- package/src/serve/binding.ts +628 -0
- package/src/serve/handler.ts +362 -0
- package/src/serve/stream-server.ts +176 -0
- package/src/session-index.ts +99 -0
- package/src/shell-env.ts +153 -0
- package/src/sqlite-workers.ts +283 -0
- package/src/sqlite.ts +528 -0
- package/src/store-owner.ts +98 -0
- package/src/store-rows.ts +110 -0
- package/src/store-usage.ts +344 -0
- package/src/usage-scan.ts +81 -0
- package/src/usage-service.ts +73 -0
- package/src/usage-summary.ts +79 -0
- package/src/usage-types.ts +87 -0
- package/src/usage-worker.ts +24 -0
- package/src/usage.ts +701 -0
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import {
|
|
2
|
+
prefixEnd2,
|
|
3
|
+
mintRevision2,
|
|
4
|
+
decodeEvent2,
|
|
5
|
+
parseNumber2,
|
|
6
|
+
parseText2,
|
|
7
|
+
parseRef2,
|
|
8
|
+
parseStoredRecord2,
|
|
9
|
+
parseStoredObject2,
|
|
10
|
+
loggedRow2,
|
|
11
|
+
collect2,
|
|
12
|
+
memoryReader2
|
|
13
|
+
} from "./canvas-preview-69fkk9yn.js";
|
|
14
|
+
import {
|
|
15
|
+
sqliteWorkers2
|
|
16
|
+
} from "./canvas-preview-zaaj99wd.js";
|
|
17
|
+
import {
|
|
18
|
+
sessionIndexChanges2,
|
|
19
|
+
sqlSessionIndex2
|
|
20
|
+
} from "./canvas-preview-0cmbkp2j.js";
|
|
21
|
+
import {
|
|
22
|
+
claimStore2
|
|
23
|
+
} from "./canvas-preview-a3yw0j70.js";
|
|
24
|
+
|
|
25
|
+
// src/sqlite.ts
|
|
26
|
+
import { mkdirSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
27
|
+
import { dirname, join } from "node:path";
|
|
28
|
+
import { DatabaseSync } from "node:sqlite";
|
|
29
|
+
import { asSeq } from "@nyte-ai/schema";
|
|
30
|
+
import { dev } from "@nyte-ai/core";
|
|
31
|
+
import {
|
|
32
|
+
admits,
|
|
33
|
+
fenceNames,
|
|
34
|
+
assertStoreVersion,
|
|
35
|
+
blobId,
|
|
36
|
+
decodeObject,
|
|
37
|
+
collectSessionEvents,
|
|
38
|
+
migrateStore,
|
|
39
|
+
objectId,
|
|
40
|
+
sessionIndexRef,
|
|
41
|
+
parseSessionRef
|
|
42
|
+
} from "@nyte-ai/core/store";
|
|
43
|
+
var BUSY_TIMEOUT_MS = 5000;
|
|
44
|
+
var BACKUPS_KEPT = 3;
|
|
45
|
+
var PUT_BODY = "INSERT INTO objects (id, body) VALUES (?, ?) ON CONFLICT (id) DO UPDATE SET body = excluded.body WHERE objects.body IS NULL";
|
|
46
|
+
function sqliteStore2(input) {
|
|
47
|
+
let database = null;
|
|
48
|
+
let opening = null;
|
|
49
|
+
let closing = null;
|
|
50
|
+
let workers = null;
|
|
51
|
+
let release = null;
|
|
52
|
+
const open = async () => {
|
|
53
|
+
const claim = "path" in input ? claimStore2(input.path) : null;
|
|
54
|
+
let created;
|
|
55
|
+
try {
|
|
56
|
+
created = new DatabaseSync("path" in input ? input.path : ":memory:", {
|
|
57
|
+
timeout: BUSY_TIMEOUT_MS
|
|
58
|
+
});
|
|
59
|
+
if ("path" in input)
|
|
60
|
+
created.exec("PRAGMA journal_mode = WAL");
|
|
61
|
+
created.exec("PRAGMA synchronous = NORMAL");
|
|
62
|
+
created.exec("PRAGMA checkpoint_fullfsync = ON");
|
|
63
|
+
created.exec("PRAGMA journal_size_limit = 33554432");
|
|
64
|
+
await migrateStore(sqliteTarget(created, "path" in input ? input.path : null));
|
|
65
|
+
created.exec("PRAGMA optimize = 0x10012");
|
|
66
|
+
} catch (error) {
|
|
67
|
+
created?.close();
|
|
68
|
+
claim?.();
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
database = created;
|
|
72
|
+
release = claim;
|
|
73
|
+
workers = "path" in input ? sqliteWorkers2(created, input.path) : null;
|
|
74
|
+
return connect(created, workers);
|
|
75
|
+
};
|
|
76
|
+
const connection = () => {
|
|
77
|
+
if (closing !== null)
|
|
78
|
+
return closing.then(connection);
|
|
79
|
+
opening ??= open().catch((error) => {
|
|
80
|
+
opening = null;
|
|
81
|
+
throw error;
|
|
82
|
+
});
|
|
83
|
+
return opening;
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
open: connection,
|
|
87
|
+
close() {
|
|
88
|
+
closing ??= (async () => {
|
|
89
|
+
await opening?.catch(() => {
|
|
90
|
+
return;
|
|
91
|
+
});
|
|
92
|
+
await workers?.close();
|
|
93
|
+
database?.close();
|
|
94
|
+
release?.();
|
|
95
|
+
workers = null;
|
|
96
|
+
database = null;
|
|
97
|
+
release = null;
|
|
98
|
+
opening = null;
|
|
99
|
+
})().finally(() => {
|
|
100
|
+
closing = null;
|
|
101
|
+
});
|
|
102
|
+
return closing;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function hasTable(database, name) {
|
|
107
|
+
return database.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(name) !== undefined;
|
|
108
|
+
}
|
|
109
|
+
function storedVersion(database) {
|
|
110
|
+
if (!hasTable(database, "store_meta"))
|
|
111
|
+
return 0;
|
|
112
|
+
const row = database.prepare("SELECT version FROM store_meta WHERE id = 1").get();
|
|
113
|
+
return row === undefined ? 0 : parseNumber2(row.version);
|
|
114
|
+
}
|
|
115
|
+
function sqliteTarget(database, path) {
|
|
116
|
+
const target = {
|
|
117
|
+
dialect: "sqlite",
|
|
118
|
+
async stamp() {
|
|
119
|
+
return {
|
|
120
|
+
version: storedVersion(database),
|
|
121
|
+
empty: !hasTable(database, "refs") || database.prepare("SELECT 1 FROM refs LIMIT 1").get() === undefined
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
async records() {
|
|
125
|
+
return database.prepare("SELECT refs.name, refs.target, refs.revision, objects.body FROM refs JOIN objects ON objects.id = refs.target WHERE objects.body IS NOT NULL").all().map(parseStoredRecord2);
|
|
126
|
+
},
|
|
127
|
+
async* objects(kind) {
|
|
128
|
+
yield* database.prepare("SELECT id, body FROM objects WHERE body IS NOT NULL AND instr(body, ?) > 0").all(`"kind":${JSON.stringify(kind)}`).map(parseStoredObject2);
|
|
129
|
+
},
|
|
130
|
+
async* logs() {
|
|
131
|
+
if (!hasTable(database, "log"))
|
|
132
|
+
return;
|
|
133
|
+
const read = database.prepare("SELECT seq, event FROM log WHERE session = ? ORDER BY seq");
|
|
134
|
+
for (const row of database.prepare("SELECT DISTINCT session FROM log").all()) {
|
|
135
|
+
const session = parseText2(row.session);
|
|
136
|
+
if (session !== null)
|
|
137
|
+
yield { session, events: read.all(session).map(loggedRow2) };
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
async commit(change) {
|
|
141
|
+
database.exec("BEGIN IMMEDIATE");
|
|
142
|
+
try {
|
|
143
|
+
if (storedVersion(database) !== change.from) {
|
|
144
|
+
database.exec("ROLLBACK");
|
|
145
|
+
return "moved";
|
|
146
|
+
}
|
|
147
|
+
for (const statement of change.sql)
|
|
148
|
+
database.exec(statement);
|
|
149
|
+
const putBody = database.prepare(PUT_BODY);
|
|
150
|
+
const repoint = database.prepare("UPDATE refs SET target = ?, revision = ? WHERE name = ? AND revision = ?");
|
|
151
|
+
for (const moved of change.repoints) {
|
|
152
|
+
write(database, putBody, moved.id, moved.body);
|
|
153
|
+
if (Number(repoint.run(moved.id, mintRevision2(), moved.name, moved.expect).changes) === 0) {
|
|
154
|
+
database.exec("ROLLBACK");
|
|
155
|
+
return "conflict";
|
|
156
|
+
}
|
|
157
|
+
updateSessionIndex(database, moved.name, moved.id, mintRevision2());
|
|
158
|
+
}
|
|
159
|
+
const create = database.prepare("INSERT INTO refs (name, target, revision) VALUES (?, ?, ?) ON CONFLICT (name) DO NOTHING");
|
|
160
|
+
for (const created of change.creates) {
|
|
161
|
+
write(database, putBody, created.target, created.body);
|
|
162
|
+
const revision = mintRevision2();
|
|
163
|
+
if (Number(create.run(created.name, created.target, revision).changes) > 0)
|
|
164
|
+
updateSessionIndex(database, created.name, created.target, revision);
|
|
165
|
+
}
|
|
166
|
+
const relog = database.prepare("UPDATE log SET event = ? WHERE session = ? AND seq = ? AND event = ?");
|
|
167
|
+
for (const row of change.relogs) {
|
|
168
|
+
if (Number(relog.run(row.event, row.session, row.seq, row.expect).changes) === 0) {
|
|
169
|
+
database.exec("ROLLBACK");
|
|
170
|
+
return "conflict";
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (change.reindexSessions)
|
|
174
|
+
for (const row of database.prepare("SELECT name, target, revision FROM refs").all()) {
|
|
175
|
+
const ref = parseRef2(row);
|
|
176
|
+
updateSessionIndex(database, ref.name, ref.target, ref.revision);
|
|
177
|
+
}
|
|
178
|
+
database.prepare("INSERT INTO store_meta (id, version) VALUES (1, ?) ON CONFLICT (id) DO UPDATE SET version = excluded.version").run(change.to);
|
|
179
|
+
database.exec("COMMIT");
|
|
180
|
+
return "committed";
|
|
181
|
+
} catch (error) {
|
|
182
|
+
if (database.isTransaction)
|
|
183
|
+
database.exec("ROLLBACK");
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
if (path === null)
|
|
189
|
+
return target;
|
|
190
|
+
return {
|
|
191
|
+
...target,
|
|
192
|
+
backup: async (from, to, names, log) => backup(database, path, from, to, names, log)
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function backup(database, path, from, to, names, log) {
|
|
196
|
+
const folder = join(dirname(path), "backups");
|
|
197
|
+
mkdirSync(folder, { recursive: true, mode: 448 });
|
|
198
|
+
const at = new Date().toISOString().replaceAll(":", "-");
|
|
199
|
+
const read = database.prepare("SELECT name, target, revision FROM refs WHERE name = ?");
|
|
200
|
+
const rows = names.flatMap((name) => {
|
|
201
|
+
const row = read.get(name);
|
|
202
|
+
return row === undefined ? [] : [parseRef2(row)];
|
|
203
|
+
});
|
|
204
|
+
writeFileSync(join(folder, `store-${at}-${process.pid}-${crypto.randomUUID()}-v${from}-v${to}.json`), JSON.stringify({
|
|
205
|
+
refs: rows,
|
|
206
|
+
log: log.map((row) => ({ session: row.session, seq: row.seq, event: row.expect }))
|
|
207
|
+
}), { mode: 384 });
|
|
208
|
+
const copies = readdirSync(folder).filter((file) => /^store-.+-v\d+-v\d+\.(?:db|json)$/u.test(file)).sort();
|
|
209
|
+
for (const file of copies.slice(0, -BACKUPS_KEPT))
|
|
210
|
+
rmSync(join(folder, file), { force: true });
|
|
211
|
+
}
|
|
212
|
+
function connect(database, workers) {
|
|
213
|
+
const putBody = database.prepare(PUT_BODY);
|
|
214
|
+
const putBytes = database.prepare("INSERT INTO objects (id, bytes) VALUES (?, ?) ON CONFLICT (id) DO UPDATE SET bytes = excluded.bytes WHERE objects.bytes IS NULL");
|
|
215
|
+
const getBody = database.prepare("SELECT body FROM objects WHERE id = ?");
|
|
216
|
+
const getBytes = database.prepare("SELECT bytes FROM objects WHERE id = ?");
|
|
217
|
+
const getRef = database.prepare("SELECT name, target, revision FROM refs WHERE name = ?");
|
|
218
|
+
const listFrom = database.prepare("SELECT name, target, revision FROM refs WHERE name >= ? ORDER BY name");
|
|
219
|
+
const listRange = database.prepare("SELECT name, target, revision FROM refs WHERE name >= ? AND name < ? ORDER BY name");
|
|
220
|
+
const putRef = database.prepare("INSERT INTO refs (name, target, revision) VALUES (?, ?, ?) ON CONFLICT (name) DO UPDATE SET target = excluded.target, revision = excluded.revision");
|
|
221
|
+
const deleteRef = database.prepare("DELETE FROM refs WHERE name = ?");
|
|
222
|
+
const append = database.prepare("INSERT INTO log (session, seq, at, event) VALUES (?, ?, ?, ?)");
|
|
223
|
+
const readLog = database.prepare("SELECT seq, at, event FROM log WHERE session = ? AND seq > ? ORDER BY seq LIMIT ?");
|
|
224
|
+
const readTail = database.prepare("SELECT MAX(seq) AS tail FROM log WHERE session = ?");
|
|
225
|
+
const readCheckpoint = database.prepare("SELECT seq, body FROM fold_checkpoints WHERE session = ?");
|
|
226
|
+
const writeCheckpoint = database.prepare("INSERT INTO fold_checkpoints (session, seq, body) VALUES (?, ?, ?) ON CONFLICT (session) DO UPDATE SET seq = excluded.seq, body = excluded.body WHERE excluded.seq >= fold_checkpoints.seq");
|
|
227
|
+
const readGap = database.prepare("SELECT COUNT(*) AS events, COALESCE(SUM(LENGTH(CAST(event AS BLOB))), 0) AS bytes FROM log WHERE session = ? AND seq > ?");
|
|
228
|
+
const readVersion = database.prepare("SELECT version FROM store_meta WHERE id = 1");
|
|
229
|
+
const readDataVersion = database.prepare("PRAGMA data_version");
|
|
230
|
+
const read = async (statement, ...params) => await workers?.read(statement.sourceSQL, params) ?? statement.all(...params);
|
|
231
|
+
const tail = (session) => {
|
|
232
|
+
const row = readTail.get(session);
|
|
233
|
+
return asSeq(row?.tail === null || row?.tail === undefined ? 0 : parseNumber2(row.tail));
|
|
234
|
+
};
|
|
235
|
+
const ref = (name) => {
|
|
236
|
+
const row = getRef.get(name);
|
|
237
|
+
return row === undefined ? null : parseRef2(row);
|
|
238
|
+
};
|
|
239
|
+
return {
|
|
240
|
+
commitMark: async () => parseNumber2(readDataVersion.get()?.data_version),
|
|
241
|
+
sessions: sqlSessionIndex2(async (text, values) => await workers?.read(text, values) ?? database.prepare(text).all(...values)),
|
|
242
|
+
objects: {
|
|
243
|
+
async put(object) {
|
|
244
|
+
const id = await objectId(object);
|
|
245
|
+
write(database, putBody, id, JSON.stringify(object));
|
|
246
|
+
workers?.check();
|
|
247
|
+
return id;
|
|
248
|
+
},
|
|
249
|
+
async get(id) {
|
|
250
|
+
const body = parseText2(getBody.get(id)?.body);
|
|
251
|
+
return body === null ? null : decodeObject(body);
|
|
252
|
+
},
|
|
253
|
+
async putBlob(bytes) {
|
|
254
|
+
const joined = await collect2(bytes);
|
|
255
|
+
const id = await blobId(joined);
|
|
256
|
+
write(database, putBytes, id, joined);
|
|
257
|
+
workers?.check();
|
|
258
|
+
return id;
|
|
259
|
+
},
|
|
260
|
+
async blob(id) {
|
|
261
|
+
const bytes = getBytes.get(id)?.bytes;
|
|
262
|
+
return bytes instanceof Uint8Array ? memoryReader2(bytes) : null;
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
refs: {
|
|
266
|
+
get: async (name) => ref(name),
|
|
267
|
+
async list(prefix) {
|
|
268
|
+
const end = prefixEnd2(prefix);
|
|
269
|
+
const rows = end === null ? await read(listFrom, prefix) : await read(listRange, prefix, end);
|
|
270
|
+
return rows.map(parseRef2);
|
|
271
|
+
},
|
|
272
|
+
async set(updates) {
|
|
273
|
+
const logged = collectSessionEvents(updates);
|
|
274
|
+
const waiting = performance.now();
|
|
275
|
+
database.exec("BEGIN IMMEDIATE");
|
|
276
|
+
const acquired = performance.now();
|
|
277
|
+
try {
|
|
278
|
+
assertStoreVersion(parseNumber2(readVersion.get()?.version ?? 0));
|
|
279
|
+
const before = new Map;
|
|
280
|
+
for (const update of updates)
|
|
281
|
+
if (!before.has(update.name))
|
|
282
|
+
before.set(update.name, ref(update.name) ?? undefined);
|
|
283
|
+
const fenced = fenceNames(updates).find((name) => ref(name) === null);
|
|
284
|
+
if (fenced !== undefined) {
|
|
285
|
+
database.exec("ROLLBACK");
|
|
286
|
+
return { kind: "fenced", name: fenced };
|
|
287
|
+
}
|
|
288
|
+
const stale = updates.find((update) => !admits(update, before.get(update.name)));
|
|
289
|
+
if (stale !== undefined) {
|
|
290
|
+
database.exec("ROLLBACK");
|
|
291
|
+
return {
|
|
292
|
+
kind: "stale",
|
|
293
|
+
name: stale.name,
|
|
294
|
+
revision: before.get(stale.name)?.revision ?? null
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
const touched = new Map;
|
|
298
|
+
const revisions = updates.map((update) => {
|
|
299
|
+
const revision = mintRevision2();
|
|
300
|
+
if (update.target === null)
|
|
301
|
+
deleteRef.run(update.name);
|
|
302
|
+
else
|
|
303
|
+
putRef.run(update.name, update.target, revision);
|
|
304
|
+
updateSessionIndex(database, update.name, update.target, revision);
|
|
305
|
+
const session = parseSessionRef(update.name);
|
|
306
|
+
if (session !== null)
|
|
307
|
+
touched.set(session, revision);
|
|
308
|
+
return revision;
|
|
309
|
+
});
|
|
310
|
+
for (const [session, version] of touched)
|
|
311
|
+
database.prepare("UPDATE session_index SET version = ? WHERE session = ?").run(version, session);
|
|
312
|
+
const at = Date.now();
|
|
313
|
+
const tails = new Map;
|
|
314
|
+
const appended = logged.map(({ session, event }) => {
|
|
315
|
+
const seq = (tails.get(session) ?? tail(session)) + 1;
|
|
316
|
+
tails.set(session, seq);
|
|
317
|
+
write(database, append, session, seq, at, JSON.stringify(event));
|
|
318
|
+
return asSeq(seq);
|
|
319
|
+
});
|
|
320
|
+
database.exec("COMMIT");
|
|
321
|
+
workers?.check();
|
|
322
|
+
return { kind: "set", logged: appended, at, revisions };
|
|
323
|
+
} catch (error) {
|
|
324
|
+
if (database.isTransaction)
|
|
325
|
+
database.exec("ROLLBACK");
|
|
326
|
+
throw error;
|
|
327
|
+
} finally {
|
|
328
|
+
dev("sqlite", "transaction", {
|
|
329
|
+
connection: "writer",
|
|
330
|
+
lockWaitMs: acquired - waiting,
|
|
331
|
+
executionMs: performance.now() - acquired
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
async log(session, after, limit) {
|
|
336
|
+
return (await read(readLog, session, after, limit)).map((row) => decodeEvent2(parseNumber2(row.seq), parseNumber2(row.at), parseText2(row.event) ?? ""));
|
|
337
|
+
},
|
|
338
|
+
tail: async (session) => tail(session)
|
|
339
|
+
},
|
|
340
|
+
checkpoints: {
|
|
341
|
+
async read(session) {
|
|
342
|
+
const [row] = await read(readCheckpoint, session);
|
|
343
|
+
const body = parseText2(row?.body);
|
|
344
|
+
return row === undefined || body === null ? null : { seq: asSeq(parseNumber2(row.seq)), body };
|
|
345
|
+
},
|
|
346
|
+
async write(session, checkpoint) {
|
|
347
|
+
write(database, writeCheckpoint, session, checkpoint.seq, checkpoint.body);
|
|
348
|
+
workers?.check();
|
|
349
|
+
},
|
|
350
|
+
async gap(session, after) {
|
|
351
|
+
const [row] = await read(readGap, session, after);
|
|
352
|
+
return { events: parseNumber2(row?.events ?? 0), bytes: parseNumber2(row?.bytes ?? 0) };
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
function updateSessionIndex(database, name, target, revision) {
|
|
358
|
+
if (sessionIndexRef(name) === null)
|
|
359
|
+
return;
|
|
360
|
+
const body = target === null ? null : parseText2(database.prepare("SELECT body FROM objects WHERE id = ?").get(target)?.body);
|
|
361
|
+
for (const change of sessionIndexChanges2(name, body === null ? null : decodeObject(body), revision))
|
|
362
|
+
database.prepare(change.text).run(...change.values);
|
|
363
|
+
}
|
|
364
|
+
function write(database, statement, ...params) {
|
|
365
|
+
const size = params.reduce((total, value) => total + (typeof value === "string" ? value.length : ArrayBuffer.isView(value) ? value.byteLength : 0), 0);
|
|
366
|
+
return (size > 64 * 1024 ? database.prepare(statement.sourceSQL) : statement).run(...params);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export { sqliteStore2 };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
answerRepair2
|
|
3
|
+
} from "./canvas-preview-2zdyh9ny.js";
|
|
4
|
+
import {
|
|
5
|
+
package_default
|
|
6
|
+
} from "./canvas-preview-g3qj3y3k.js";
|
|
7
|
+
|
|
8
|
+
// src/deploy/vercel/server/utils/host.ts
|
|
9
|
+
import process from "node:process";
|
|
10
|
+
import { createModels } from "@nyte-ai/ai/models";
|
|
11
|
+
import { SdkError } from "@nyte-ai/schema";
|
|
12
|
+
import { composeHost } from "@nyte-ai/core/server";
|
|
13
|
+
import { postgresStore } from "@nyte-ai/host";
|
|
14
|
+
import { credentialStore } from "@nyte-ai/host/credentials";
|
|
15
|
+
import { seedSigner } from "@nyte-ai/host/identity";
|
|
16
|
+
import { listenFetch } from "@nyte-ai/host/listen-fetch";
|
|
17
|
+
import { sandboxProvider } from "@nyte-ai/host/providers";
|
|
18
|
+
var PAGE = 100;
|
|
19
|
+
var boot = async () => {
|
|
20
|
+
throw new SdkError("unavailable", "Supply a boot over your sandbox SDK in server/utils/host.ts.");
|
|
21
|
+
};
|
|
22
|
+
var building = null;
|
|
23
|
+
function vercelHost2(dispatch) {
|
|
24
|
+
const built = building ??= build(dispatch);
|
|
25
|
+
built.catch(() => {
|
|
26
|
+
if (building === built)
|
|
27
|
+
building = null;
|
|
28
|
+
});
|
|
29
|
+
return built;
|
|
30
|
+
}
|
|
31
|
+
async function build(dispatch) {
|
|
32
|
+
const connectionString = process.env.DATABASE_URL;
|
|
33
|
+
if (connectionString === undefined || connectionString === "")
|
|
34
|
+
throw new SdkError("unavailable", "Set DATABASE_URL to the Postgres database the host keeps.");
|
|
35
|
+
const identityKey = process.env.NYTE_IDENTITY_KEY;
|
|
36
|
+
const store = postgresStore({ connectionString });
|
|
37
|
+
const secrets = secretsFrom(process.env.NYTE_SECRET_KEY);
|
|
38
|
+
const description = { name: "nyte-host", platform: "vercel", version: package_default.version };
|
|
39
|
+
const host = await composeHost({
|
|
40
|
+
store,
|
|
41
|
+
models: createModels({ credentials: credentialStore(store, secrets) }),
|
|
42
|
+
plugins: [{ id: "sandbox", environment: sandboxProvider({ boot }) }],
|
|
43
|
+
workspace: { kind: "sandbox", locator: { name: process.env.NYTE_SANDBOX ?? "nyte" } },
|
|
44
|
+
execution: { kind: "dispatch", dispatch },
|
|
45
|
+
poll: 1000,
|
|
46
|
+
secrets,
|
|
47
|
+
home: null,
|
|
48
|
+
description
|
|
49
|
+
});
|
|
50
|
+
const repair = async () => {
|
|
51
|
+
let cursor;
|
|
52
|
+
do {
|
|
53
|
+
const page = await host.execution.repair({ cursor, limit: PAGE });
|
|
54
|
+
cursor = page.next ?? undefined;
|
|
55
|
+
} while (cursor !== undefined);
|
|
56
|
+
};
|
|
57
|
+
const listener = await listenFetch(host, {
|
|
58
|
+
transport: { kind: "fetch" },
|
|
59
|
+
auth: { kind: "token", token: process.env.NYTE_TOKEN ?? "" },
|
|
60
|
+
execution: { kind: "admit-only" },
|
|
61
|
+
describe: () => description,
|
|
62
|
+
...identityKey === undefined || identityKey === "" ? {} : { identity: await seedSigner(host.hostId, Uint8Array.fromBase64(identityKey)) },
|
|
63
|
+
before: (request) => answerRepair2(request, process.env.CRON_SECRET, repair)
|
|
64
|
+
}).catch(async (error) => {
|
|
65
|
+
await host.close();
|
|
66
|
+
throw error;
|
|
67
|
+
});
|
|
68
|
+
return { host, listener };
|
|
69
|
+
}
|
|
70
|
+
function secretsFrom(key) {
|
|
71
|
+
if (key === undefined || key === "")
|
|
72
|
+
return {
|
|
73
|
+
key: async () => {
|
|
74
|
+
throw new SdkError("unavailable", "Set NYTE_SECRET_KEY to a base64 32-byte key.");
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const bytes = new Uint8Array(Buffer.from(key, "base64"));
|
|
78
|
+
return { key: async () => bytes };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { vercelHost2 };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// package.json
|
|
2
|
+
var package_default = {
|
|
3
|
+
name: "@nyte-ai/host",
|
|
4
|
+
version: "0.0.18",
|
|
5
|
+
private: false,
|
|
6
|
+
license: "MIT",
|
|
7
|
+
repository: {
|
|
8
|
+
type: "git",
|
|
9
|
+
url: "git+https://github.com/interfaces-lab/nyte.git",
|
|
10
|
+
directory: "packages/host"
|
|
11
|
+
},
|
|
12
|
+
files: [
|
|
13
|
+
"dist",
|
|
14
|
+
"src",
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"THIRD-PARTY-NOTICES.md"
|
|
17
|
+
],
|
|
18
|
+
type: "module",
|
|
19
|
+
exports: {
|
|
20
|
+
".": "./src/index.ts",
|
|
21
|
+
"./canvas-preview": "./src/canvas-preview.ts",
|
|
22
|
+
"./credentials": "./src/credentials.ts",
|
|
23
|
+
"./durable-object": "./src/durable-object.ts",
|
|
24
|
+
"./identity": "./src/identity.ts",
|
|
25
|
+
"./listen-fetch": "./src/listen-fetch.ts",
|
|
26
|
+
"./providers": "./src/providers.ts",
|
|
27
|
+
"./secrets": "./src/secrets.ts",
|
|
28
|
+
"./shell-env": "./src/shell-env.ts",
|
|
29
|
+
"./usage": "./src/usage.ts",
|
|
30
|
+
"./store-usage": "./src/store-usage.ts",
|
|
31
|
+
"./usage-service": "./src/usage-service.ts",
|
|
32
|
+
"./usage-scan": "./src/usage-scan.ts",
|
|
33
|
+
"./usage-worker": "./src/usage-worker.ts",
|
|
34
|
+
"./deploy/cloudflare": "./src/deploy/cloudflare/worker.ts",
|
|
35
|
+
"./deploy/vercel": "./src/deploy/vercel/nitro.config.ts"
|
|
36
|
+
},
|
|
37
|
+
publishConfig: {
|
|
38
|
+
exports: {
|
|
39
|
+
".": {
|
|
40
|
+
types: "./dist/src/index.d.ts",
|
|
41
|
+
import: "./dist/src/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./canvas-preview": {
|
|
44
|
+
types: "./dist/src/canvas-preview.d.ts",
|
|
45
|
+
import: "./dist/src/canvas-preview.js"
|
|
46
|
+
},
|
|
47
|
+
"./credentials": {
|
|
48
|
+
types: "./dist/src/credentials.d.ts",
|
|
49
|
+
import: "./dist/src/credentials.js"
|
|
50
|
+
},
|
|
51
|
+
"./durable-object": {
|
|
52
|
+
types: "./dist/src/durable-object.d.ts",
|
|
53
|
+
import: "./dist/src/durable-object.js"
|
|
54
|
+
},
|
|
55
|
+
"./identity": {
|
|
56
|
+
types: "./dist/src/identity.d.ts",
|
|
57
|
+
import: "./dist/src/identity.js"
|
|
58
|
+
},
|
|
59
|
+
"./listen-fetch": {
|
|
60
|
+
types: "./dist/src/listen-fetch.d.ts",
|
|
61
|
+
import: "./dist/src/listen-fetch.js"
|
|
62
|
+
},
|
|
63
|
+
"./providers": {
|
|
64
|
+
types: "./dist/src/providers.d.ts",
|
|
65
|
+
import: "./dist/src/providers.js"
|
|
66
|
+
},
|
|
67
|
+
"./secrets": {
|
|
68
|
+
types: "./dist/src/secrets.d.ts",
|
|
69
|
+
import: "./dist/src/secrets.js"
|
|
70
|
+
},
|
|
71
|
+
"./shell-env": {
|
|
72
|
+
types: "./dist/src/shell-env.d.ts",
|
|
73
|
+
import: "./dist/src/shell-env.js"
|
|
74
|
+
},
|
|
75
|
+
"./usage": {
|
|
76
|
+
types: "./dist/src/usage.d.ts",
|
|
77
|
+
import: "./dist/src/usage.js"
|
|
78
|
+
},
|
|
79
|
+
"./store-usage": {
|
|
80
|
+
types: "./dist/src/store-usage.d.ts",
|
|
81
|
+
import: "./dist/src/store-usage.js"
|
|
82
|
+
},
|
|
83
|
+
"./usage-service": {
|
|
84
|
+
types: "./dist/src/usage-service.d.ts",
|
|
85
|
+
import: "./dist/src/usage-service.js"
|
|
86
|
+
},
|
|
87
|
+
"./usage-scan": {
|
|
88
|
+
types: "./dist/src/usage-scan.d.ts",
|
|
89
|
+
import: "./dist/src/usage-scan.js"
|
|
90
|
+
},
|
|
91
|
+
"./usage-worker": {
|
|
92
|
+
types: "./dist/src/usage-worker.d.ts",
|
|
93
|
+
import: "./dist/src/usage-worker.js"
|
|
94
|
+
},
|
|
95
|
+
"./deploy/cloudflare": {
|
|
96
|
+
types: "./dist/src/deploy/cloudflare/worker.d.ts",
|
|
97
|
+
import: "./dist/src/deploy/cloudflare/worker.js"
|
|
98
|
+
},
|
|
99
|
+
"./deploy/vercel": {
|
|
100
|
+
types: "./dist/src/deploy/vercel/nitro.config.d.ts",
|
|
101
|
+
import: "./dist/src/deploy/vercel/nitro.config.js"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
access: "public",
|
|
105
|
+
provenance: true
|
|
106
|
+
},
|
|
107
|
+
scripts: {
|
|
108
|
+
clean: "rm -rf node_modules .turbo",
|
|
109
|
+
typecheck: "tsgo --noEmit && tsgo --noEmit -p src/deploy/vercel",
|
|
110
|
+
test: "vitest --run",
|
|
111
|
+
"check:store": "node scripts/check-store.ts",
|
|
112
|
+
"compact:store": "node scripts/compact-store.ts",
|
|
113
|
+
"build:package": "bun ../../scripts/sdk-packages.mjs build host"
|
|
114
|
+
},
|
|
115
|
+
dependencies: {
|
|
116
|
+
"@earendil-works/pi-mcp": "1.3.0",
|
|
117
|
+
"@lydell/node-pty": "1.2.0-beta.15",
|
|
118
|
+
"@nyte-ai/ai": "workspace:*",
|
|
119
|
+
"@nyte-ai/core": "workspace:*",
|
|
120
|
+
"@nyte-ai/plugin": "workspace:*",
|
|
121
|
+
"@nyte-ai/protocol": "workspace:*",
|
|
122
|
+
"@nyte-ai/schema": "workspace:*",
|
|
123
|
+
fflate: "0.8.3",
|
|
124
|
+
ignore: "7.0.9",
|
|
125
|
+
pg: "8.23.0",
|
|
126
|
+
typebox: "1.3.36"
|
|
127
|
+
},
|
|
128
|
+
devDependencies: {
|
|
129
|
+
"@electric-sql/pglite": "0.5.8",
|
|
130
|
+
"@nyte-ai/canvas": "workspace:*",
|
|
131
|
+
"@types/node": "^26.6.5",
|
|
132
|
+
"@types/pg": "8.23.1",
|
|
133
|
+
"fast-check": "4.10.2",
|
|
134
|
+
nitro: "3.0.260903-beta",
|
|
135
|
+
typescript: "6.0.3",
|
|
136
|
+
vitest: "^5.0.5",
|
|
137
|
+
workflow: "4.8.8"
|
|
138
|
+
},
|
|
139
|
+
peerDependencies: {
|
|
140
|
+
nitro: "3.0.260903-beta",
|
|
141
|
+
workflow: "4.8.8"
|
|
142
|
+
},
|
|
143
|
+
peerDependenciesMeta: {
|
|
144
|
+
nitro: {
|
|
145
|
+
optional: true
|
|
146
|
+
},
|
|
147
|
+
workflow: {
|
|
148
|
+
optional: true
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
engines: {
|
|
152
|
+
node: ">=26.4.0"
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export { package_default };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
oauthKey2,
|
|
3
|
+
oauthStore2,
|
|
4
|
+
createAuthProvider2
|
|
5
|
+
} from "./canvas-preview-5z63am63.js";
|
|
6
|
+
|
|
7
|
+
// src/mcp/connect.ts
|
|
8
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
9
|
+
import process from "node:process";
|
|
10
|
+
import { StdioTransport, StreamableHttpTransport } from "@earendil-works/pi-mcp";
|
|
11
|
+
var connectServer2 = (entry, context) => {
|
|
12
|
+
const { transport } = entry;
|
|
13
|
+
if (transport.kind === "stdio") {
|
|
14
|
+
const base = context.workspace.root ?? context.home;
|
|
15
|
+
const cwd = transport.cwd === null ? base : home(transport.cwd, context.home);
|
|
16
|
+
return new StdioTransport({
|
|
17
|
+
command: home(transport.command, context.home),
|
|
18
|
+
args: transport.args.map((arg) => home(arg, context.home)),
|
|
19
|
+
env: expand(transport.env, entry.name),
|
|
20
|
+
cwd: isAbsolute(cwd) ? cwd : resolve(base, cwd),
|
|
21
|
+
stderr: "pipe"
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const headers = expand(transport.headers, entry.name);
|
|
25
|
+
if (Object.keys(headers).some((name) => name.toLowerCase() === "authorization"))
|
|
26
|
+
return new StreamableHttpTransport({ url: transport.url, headers });
|
|
27
|
+
return new StreamableHttpTransport({
|
|
28
|
+
url: transport.url,
|
|
29
|
+
headers,
|
|
30
|
+
authProvider: createAuthProvider2({
|
|
31
|
+
serverUrl: transport.url,
|
|
32
|
+
store: oauthStore2(context.secrets, oauthKey2(entry.name, transport.url)),
|
|
33
|
+
settings: () => oauthSettings2(transport.oauth, entry.name),
|
|
34
|
+
onChallenge: context.challenged
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
function oauthSettings2(config, server) {
|
|
39
|
+
const { clientSecret, authServerMetadataUrl, ...rest } = config;
|
|
40
|
+
return {
|
|
41
|
+
...rest,
|
|
42
|
+
...clientSecret === undefined ? {} : { clientSecret: expand({ clientSecret }, server).clientSecret },
|
|
43
|
+
...authServerMetadataUrl === undefined ? {} : { authServerMetadataUrl: new URL(authServerMetadataUrl) }
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function home(path, directory) {
|
|
47
|
+
if (path === "~")
|
|
48
|
+
return directory;
|
|
49
|
+
return path.startsWith("~/") ? join(directory, path.slice(2)) : path;
|
|
50
|
+
}
|
|
51
|
+
function expand(values, server) {
|
|
52
|
+
return Object.fromEntries(Object.entries(values).map(([key, value]) => [
|
|
53
|
+
key,
|
|
54
|
+
value.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (_match, name) => {
|
|
55
|
+
const found = process.env[name];
|
|
56
|
+
if (found === undefined)
|
|
57
|
+
throw new Error(`${server} needs the environment variable ${name}. Set it where Nyte runs, then restart Nyte (for the CLI, \`nyte service stop\`).`);
|
|
58
|
+
return found;
|
|
59
|
+
})
|
|
60
|
+
]));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { connectServer2, oauthSettings2 };
|