@nyte-ai/host 0.0.0-stage → 0.0.19
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 +866 -0
- package/dist/chunks/canvas-preview-0cmbkp2j.js +65 -0
- package/dist/chunks/canvas-preview-0nq75h9k.js +7 -0
- package/dist/chunks/canvas-preview-11nadadc.js +241 -0
- package/dist/chunks/canvas-preview-1sq7z9jq.js +17 -0
- package/dist/chunks/canvas-preview-2jwbe14k.js +130 -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-55s0y68g.js +387 -0
- package/dist/chunks/canvas-preview-5ekjx6sw.js +613 -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-8xc0vn7v.js +458 -0
- package/dist/chunks/canvas-preview-9aqczacs.js +73 -0
- package/dist/chunks/canvas-preview-af86jz8t.js +141 -0
- package/dist/chunks/canvas-preview-aq5j4p25.js +240 -0
- package/dist/chunks/canvas-preview-b2v8wfnz.js +36 -0
- package/dist/chunks/canvas-preview-befkjea2.js +60 -0
- package/dist/chunks/canvas-preview-bxnqt8cd.js +103 -0
- package/dist/chunks/canvas-preview-cawy6vbz.js +352 -0
- package/dist/chunks/canvas-preview-crmzxxt8.js +518 -0
- package/dist/chunks/canvas-preview-drctegz4.js +591 -0
- package/dist/chunks/canvas-preview-e3vnkkc5.js +134 -0
- package/dist/chunks/canvas-preview-ec2mt7es.js +108 -0
- package/dist/chunks/canvas-preview-fxa0rfb0.js +61 -0
- package/dist/chunks/canvas-preview-g5fkjs34.js +598 -0
- package/dist/chunks/canvas-preview-jeddjex8.js +166 -0
- package/dist/chunks/canvas-preview-k1yg4fgp.js +571 -0
- package/dist/chunks/canvas-preview-kdqgrstc.js +194 -0
- package/dist/chunks/canvas-preview-kn7kvbfj.js +12 -0
- package/dist/chunks/canvas-preview-kp75gb63.js +141 -0
- package/dist/chunks/canvas-preview-mgcx2b2p.js +271 -0
- package/dist/chunks/canvas-preview-n2a35zv5.js +81 -0
- package/dist/chunks/canvas-preview-pkzqg96v.js +63 -0
- package/dist/chunks/canvas-preview-rp4x6y1h.js +144 -0
- package/dist/chunks/canvas-preview-s94ebwf5.js +112 -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-tnqe7k0b.js +374 -0
- package/dist/chunks/canvas-preview-vaatfznm.js +189 -0
- package/dist/chunks/canvas-preview-vm9zdp2t.js +398 -0
- package/dist/chunks/canvas-preview-w54ymtb3.js +272 -0
- package/dist/chunks/canvas-preview-wg80rbc2.js +46 -0
- package/dist/chunks/canvas-preview-y5y6ghaw.js +125 -0
- package/dist/chunks/canvas-preview-ycepb05s.js +176 -0
- package/dist/chunks/canvas-preview-yjz0f7n4.js +50 -0
- package/dist/chunks/canvas-preview-zaaj99wd.js +244 -0
- package/dist/src/canvas-preview.d.ts +29 -0
- package/dist/src/canvas-preview.js +271 -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/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 +20 -0
- package/dist/src/index.js +121 -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 +20 -0
- package/dist/src/local/command.js +12 -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 +7 -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 +15 -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 +14 -0
- package/dist/src/open.js +46 -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 +8 -0
- package/dist/src/sqlite.js +11 -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 +19 -0
- package/dist/src/usage-history.d.ts +54 -0
- package/dist/src/usage-history.js +14 -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 +23 -0
- package/dist/src/usage-service.js +16 -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 +29 -0
- package/dist/src/usage.d.ts +195 -0
- package/dist/src/usage.js +23 -0
- package/package.json +140 -3
- package/src/canvas-preview.ts +403 -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/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 +39 -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 +161 -0
- package/src/local/feed.ts +70 -0
- package/src/local/files.ts +817 -0
- package/src/local/git-watch.ts +199 -0
- package/src/local/git.ts +919 -0
- package/src/local/github.ts +691 -0
- package/src/local/identity.ts +21 -0
- package/src/local/jobs.ts +573 -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 +778 -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 +92 -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 +449 -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 +629 -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 +553 -0
- package/src/store-rows.ts +110 -0
- package/src/store-usage.ts +347 -0
- package/src/usage-history.ts +219 -0
- package/src/usage-scan.ts +81 -0
- package/src/usage-service.ts +82 -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 +776 -0
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import {
|
|
2
|
+
credentialStore2
|
|
3
|
+
} from "./canvas-preview-518dh8by.js";
|
|
4
|
+
import {
|
|
5
|
+
readErrorCode2
|
|
6
|
+
} from "./canvas-preview-mgcx2b2p.js";
|
|
7
|
+
import {
|
|
8
|
+
identitySigner2
|
|
9
|
+
} from "./canvas-preview-5mex725c.js";
|
|
10
|
+
import {
|
|
11
|
+
localGitHubAccount2
|
|
12
|
+
} from "./canvas-preview-8xc0vn7v.js";
|
|
13
|
+
import {
|
|
14
|
+
localProvider2
|
|
15
|
+
} from "./canvas-preview-e3vnkkc5.js";
|
|
16
|
+
import {
|
|
17
|
+
importLegacyTrust2
|
|
18
|
+
} from "./canvas-preview-9aqczacs.js";
|
|
19
|
+
import {
|
|
20
|
+
migrateLocalWorkspaceIdentities2
|
|
21
|
+
} from "./canvas-preview-4e0pxa32.js";
|
|
22
|
+
import {
|
|
23
|
+
listen2
|
|
24
|
+
} from "./canvas-preview-ycepb05s.js";
|
|
25
|
+
import {
|
|
26
|
+
nodeImages2
|
|
27
|
+
} from "./canvas-preview-y5y6ghaw.js";
|
|
28
|
+
import {
|
|
29
|
+
createMcpHub2
|
|
30
|
+
} from "./canvas-preview-g5fkjs34.js";
|
|
31
|
+
import {
|
|
32
|
+
loadPluginDirectory2,
|
|
33
|
+
pluginLoader2
|
|
34
|
+
} from "./canvas-preview-s94ebwf5.js";
|
|
35
|
+
import {
|
|
36
|
+
defaultSecrets2
|
|
37
|
+
} from "./canvas-preview-skzwvw4d.js";
|
|
38
|
+
import {
|
|
39
|
+
storePath2,
|
|
40
|
+
sqliteStore2
|
|
41
|
+
} from "./canvas-preview-tnqe7k0b.js";
|
|
42
|
+
import {
|
|
43
|
+
package_default
|
|
44
|
+
} from "./canvas-preview-jeddjex8.js";
|
|
45
|
+
|
|
46
|
+
// src/open.ts
|
|
47
|
+
import { watch } from "node:fs";
|
|
48
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
49
|
+
import { homedir, hostname } from "node:os";
|
|
50
|
+
import { dirname, join } from "node:path";
|
|
51
|
+
import process from "node:process";
|
|
52
|
+
import { defaultProviderAuthContext } from "@nyte-ai/ai/auth/context";
|
|
53
|
+
import { FileModelsStore, nyteProviders } from "@nyte-ai/ai";
|
|
54
|
+
import { createModels } from "@nyte-ai/ai/models";
|
|
55
|
+
import { isJson } from "@nyte-ai/schema";
|
|
56
|
+
import { serial } from "@nyte-ai/schema/serial";
|
|
57
|
+
import { dev, processEnvironment } from "@nyte-ai/core";
|
|
58
|
+
import { composeHost } from "@nyte-ai/core/server";
|
|
59
|
+
import { readModelSelection } from "@nyte-ai/core/store";
|
|
60
|
+
import approvals from "@nyte-ai/plugin/core/approvals";
|
|
61
|
+
import { acpAgents } from "@nyte-ai/plugin/core/acp";
|
|
62
|
+
import bashDescription from "@nyte-ai/plugin/core/bash-description";
|
|
63
|
+
import browserTools from "@nyte-ai/plugin/core/browser-tools";
|
|
64
|
+
import canvas from "@nyte-ai/plugin/core/canvas";
|
|
65
|
+
import { claudeCodeSdk } from "@nyte-ai/plugin/core/claude-code-sdk";
|
|
66
|
+
import codemode from "@nyte-ai/plugin/core/codemode";
|
|
67
|
+
import openaiAstraContext from "@nyte-ai/plugin/core/openai-astra-context";
|
|
68
|
+
import { openaiCompaction } from "@nyte-ai/plugin/core/openai-compaction";
|
|
69
|
+
import question from "@nyte-ai/plugin/core/question";
|
|
70
|
+
import rename from "@nyte-ai/plugin/core/rename";
|
|
71
|
+
import telemetry from "@nyte-ai/plugin/core/telemetry";
|
|
72
|
+
import webSearch from "@nyte-ai/plugin/core/web-search";
|
|
73
|
+
var RELOAD_DEBOUNCE_MS = 250;
|
|
74
|
+
var STORE_POLL_MS = 500;
|
|
75
|
+
async function openHost2(options) {
|
|
76
|
+
const home = options.home ?? homedir();
|
|
77
|
+
const workspace = options.workspace ?? { kind: "local", path: process.cwd() };
|
|
78
|
+
if (options.store !== undefined)
|
|
79
|
+
return composeOpen(options, { home, workspace, store: options.store, owned: null });
|
|
80
|
+
const owned = await defaultStore(home);
|
|
81
|
+
try {
|
|
82
|
+
return await composeOpen(options, { home, workspace, store: owned, owned });
|
|
83
|
+
} catch (cause) {
|
|
84
|
+
await owned.close().catch(() => {
|
|
85
|
+
return;
|
|
86
|
+
});
|
|
87
|
+
throw cause;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async function defaultStore(home) {
|
|
91
|
+
const path = storePath2(home);
|
|
92
|
+
await mkdir(dirname(path), { recursive: true, mode: 448 });
|
|
93
|
+
return sqliteStore2({ path });
|
|
94
|
+
}
|
|
95
|
+
async function composeOpen(options, input) {
|
|
96
|
+
const { home, workspace, store, owned } = input;
|
|
97
|
+
const secrets = options.secrets ?? defaultSecrets2(home);
|
|
98
|
+
const description = hostDescription();
|
|
99
|
+
const given = options.plugins ?? [];
|
|
100
|
+
const usesLocalProvider = !given.some((plugin) => plugin.environment?.kind === "local");
|
|
101
|
+
const claudeCode = claudeCodeSdk();
|
|
102
|
+
const acp = acpAgents();
|
|
103
|
+
const [models, files, settings] = await Promise.all([
|
|
104
|
+
options.models ?? nyteModels({ store, secrets, home, providers: [claudeCode.provider, acp.provider] }),
|
|
105
|
+
filePlugins(home),
|
|
106
|
+
settingsSeed(home),
|
|
107
|
+
usesLocalProvider ? store.open().then(async (connection) => {
|
|
108
|
+
await migrateLocalWorkspaceIdentities2(connection);
|
|
109
|
+
await importLegacyTrust2(connection, home);
|
|
110
|
+
}) : undefined
|
|
111
|
+
]);
|
|
112
|
+
const builtins = [
|
|
113
|
+
approvals,
|
|
114
|
+
question,
|
|
115
|
+
rename,
|
|
116
|
+
bashDescription,
|
|
117
|
+
webSearch,
|
|
118
|
+
codemode,
|
|
119
|
+
openaiCompaction(models),
|
|
120
|
+
openaiAstraContext,
|
|
121
|
+
telemetry,
|
|
122
|
+
canvas,
|
|
123
|
+
claudeCode.plugin,
|
|
124
|
+
acp.plugin
|
|
125
|
+
];
|
|
126
|
+
const plugins = [
|
|
127
|
+
...usesLocalProvider ? [{ id: "local", environment: localProvider2({ home, shell: options.shell }) }] : [],
|
|
128
|
+
...builtins.filter((builtin) => !given.some((plugin) => plugin.id === builtin.id)),
|
|
129
|
+
...given
|
|
130
|
+
];
|
|
131
|
+
let projectDirs = async () => [];
|
|
132
|
+
const host = await composeHost({
|
|
133
|
+
...options,
|
|
134
|
+
store,
|
|
135
|
+
workspace,
|
|
136
|
+
loadPlugins: async (paths) => pluginLoader2([...files.dirs, ...await projectDirs()])(paths),
|
|
137
|
+
models,
|
|
138
|
+
mcp: options.mcp ?? createMcpHub2({ home }),
|
|
139
|
+
github: options.github ?? (usesLocalProvider ? localGitHubAccount2({ home }) : undefined),
|
|
140
|
+
images: options.images ?? nodeImages2(),
|
|
141
|
+
plugins: [...plugins, ...files.plugins],
|
|
142
|
+
pluginSources: files.sources,
|
|
143
|
+
secrets,
|
|
144
|
+
home,
|
|
145
|
+
description,
|
|
146
|
+
...settings.seed === null ? {} : { seed: settings.seed },
|
|
147
|
+
...owned === null ? {} : { poll: STORE_POLL_MS },
|
|
148
|
+
member: {
|
|
149
|
+
label: options.label ?? "nyte",
|
|
150
|
+
pid: process.pid,
|
|
151
|
+
capabilities: given.some((plugin) => plugin.id === browserTools.id) ? [browserTools.id] : []
|
|
152
|
+
},
|
|
153
|
+
revoked: options.onRevoked
|
|
154
|
+
});
|
|
155
|
+
projectDirs = async () => (await host.workspaces.list()).flatMap((entry) => entry.trusted === true && ("path" in entry.target) ? [join(entry.target.path, ".nyte", "plugins")] : []);
|
|
156
|
+
for (const row of files.failed)
|
|
157
|
+
host.server.report(row);
|
|
158
|
+
if (settings.issue !== null)
|
|
159
|
+
host.server.report({
|
|
160
|
+
id: "settings",
|
|
161
|
+
source: "user",
|
|
162
|
+
path: settingsPath(home),
|
|
163
|
+
issues: [settings.issue]
|
|
164
|
+
});
|
|
165
|
+
dev("open", "host", {
|
|
166
|
+
home,
|
|
167
|
+
seedIds: Object.keys(settings.seed?.settings ?? {}).length,
|
|
168
|
+
pluginFiles: files.plugins.length + files.failed.length,
|
|
169
|
+
failedFiles: files.failed.length
|
|
170
|
+
});
|
|
171
|
+
const reported = new Map(host.server.pluginRows().filter((row) => row.path !== null && row.id === row.path).map((row) => [row.id, row]));
|
|
172
|
+
const reload = async () => {
|
|
173
|
+
const next = await filePlugins(home);
|
|
174
|
+
for (const [plugin, source] of next.sources)
|
|
175
|
+
files.sources.set(plugin, source);
|
|
176
|
+
const report = await host.plugins.replace([...plugins, ...next.plugins]);
|
|
177
|
+
const failed = [...next.failed, ...refused(next, report)];
|
|
178
|
+
for (const [id, row] of reported)
|
|
179
|
+
if (!failed.some((row) => row.id === id))
|
|
180
|
+
host.server.report({ ...row, issues: [] });
|
|
181
|
+
for (const row of failed)
|
|
182
|
+
host.server.report(row);
|
|
183
|
+
reported.clear();
|
|
184
|
+
for (const row of failed)
|
|
185
|
+
reported.set(row.id, row);
|
|
186
|
+
for (const plugin of files.sources.keys())
|
|
187
|
+
if (!host.server.loaded(plugin))
|
|
188
|
+
files.sources.delete(plugin);
|
|
189
|
+
dev("open", "plugins reloaded", {
|
|
190
|
+
generation: report.generation,
|
|
191
|
+
pluginFiles: next.plugins.length,
|
|
192
|
+
failedFiles: failed.length
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
const unwatch = watchPlugins(files.dirs, reload);
|
|
196
|
+
const listeners = new Set;
|
|
197
|
+
let identity = null;
|
|
198
|
+
const attach = async (listenOptions) => {
|
|
199
|
+
const listener = await listen2(host, {
|
|
200
|
+
describe: () => description,
|
|
201
|
+
...listenOptions,
|
|
202
|
+
identity: listenOptions.identity ?? await (identity ??= identitySigner2(host.hostId, home))
|
|
203
|
+
});
|
|
204
|
+
listeners.add(listener);
|
|
205
|
+
dev("open", "listen", { address: listener.address });
|
|
206
|
+
return listener;
|
|
207
|
+
};
|
|
208
|
+
let closing = null;
|
|
209
|
+
const close = () => {
|
|
210
|
+
closing ??= (async () => {
|
|
211
|
+
await unwatch();
|
|
212
|
+
for (const listener of listeners)
|
|
213
|
+
await listener.close();
|
|
214
|
+
await host.close();
|
|
215
|
+
await owned?.close();
|
|
216
|
+
})();
|
|
217
|
+
return closing;
|
|
218
|
+
};
|
|
219
|
+
return { ...host, listen: attach, close, [Symbol.asyncDispose]: close };
|
|
220
|
+
}
|
|
221
|
+
async function nyteModels(input) {
|
|
222
|
+
const credentials = credentialStore2(input.store, input.secrets);
|
|
223
|
+
const auth = defaultProviderAuthContext();
|
|
224
|
+
const models = createModels({
|
|
225
|
+
credentials,
|
|
226
|
+
modelsStore: new FileModelsStore(join(input.home, ".nyte", "models-store.json")),
|
|
227
|
+
authContext: {
|
|
228
|
+
...auth,
|
|
229
|
+
env: async (name) => {
|
|
230
|
+
await processEnvironment();
|
|
231
|
+
return auth.env(name);
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
catalog: { url: process.env.NYTE_MODELS_URL }
|
|
235
|
+
});
|
|
236
|
+
for (const provider of [...nyteProviders(), ...input.providers])
|
|
237
|
+
models.setProvider(provider);
|
|
238
|
+
const [stored, selected] = await Promise.all([
|
|
239
|
+
credentials.list(),
|
|
240
|
+
input.store.open().then(readModelSelection)
|
|
241
|
+
]);
|
|
242
|
+
const restored = await models.refresh({
|
|
243
|
+
providers: [
|
|
244
|
+
...new Set([
|
|
245
|
+
...stored.map((row) => row.providerId),
|
|
246
|
+
...input.providers.map((provider) => provider.id),
|
|
247
|
+
...selected === null ? [] : [selected.provider]
|
|
248
|
+
])
|
|
249
|
+
],
|
|
250
|
+
allowNetwork: false
|
|
251
|
+
});
|
|
252
|
+
dev("open", "models restored", {
|
|
253
|
+
providers: stored.length,
|
|
254
|
+
failed: [...restored.errors.keys()]
|
|
255
|
+
});
|
|
256
|
+
return models;
|
|
257
|
+
}
|
|
258
|
+
async function filePlugins(home) {
|
|
259
|
+
const scopes = [{ source: "user", dir: join(home, ".nyte", "plugins") }];
|
|
260
|
+
const plugins = [];
|
|
261
|
+
const sources = new Map;
|
|
262
|
+
const failed = [];
|
|
263
|
+
for (const { source, dir } of scopes) {
|
|
264
|
+
const found = await loadPluginDirectory2(dir);
|
|
265
|
+
for (const { plugin, path } of found.loaded) {
|
|
266
|
+
plugins.push(plugin);
|
|
267
|
+
sources.set(plugin, { source, path });
|
|
268
|
+
}
|
|
269
|
+
for (const { path, issue } of found.failed)
|
|
270
|
+
failed.push({ id: path, source, path, issues: [issue] });
|
|
271
|
+
}
|
|
272
|
+
return { plugins, sources, dirs: scopes.map((scope) => scope.dir), failed };
|
|
273
|
+
}
|
|
274
|
+
function refused(files, report) {
|
|
275
|
+
return report.plugins.flatMap((outcome) => {
|
|
276
|
+
const plugin = files.plugins.find((candidate) => candidate.id === outcome.id);
|
|
277
|
+
const file = plugin === undefined ? undefined : files.sources.get(plugin);
|
|
278
|
+
return outcome.kind === "activated" || file === undefined ? [] : [{ id: file.path, source: file.source, path: file.path, issues: outcome.issues }];
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
function watchPlugins(dirs, reload) {
|
|
282
|
+
let timer = null;
|
|
283
|
+
const reloads = serial();
|
|
284
|
+
const run = () => {
|
|
285
|
+
timer = null;
|
|
286
|
+
reloads.run(reload).catch((error) => dev("open", "plugin reload failed", {
|
|
287
|
+
message: error instanceof Error ? error.message : String(error)
|
|
288
|
+
}));
|
|
289
|
+
};
|
|
290
|
+
const changed = () => {
|
|
291
|
+
if (timer !== null)
|
|
292
|
+
clearTimeout(timer);
|
|
293
|
+
timer = setTimeout(run, RELOAD_DEBOUNCE_MS);
|
|
294
|
+
timer.unref();
|
|
295
|
+
};
|
|
296
|
+
const watchers = dirs.flatMap((dir) => {
|
|
297
|
+
try {
|
|
298
|
+
const watcher = watch(dir, { recursive: true, persistent: false }, changed);
|
|
299
|
+
watcher.on("error", (error) => {
|
|
300
|
+
dev("open", "plugin watch failed", { dir, message: error.message });
|
|
301
|
+
watcher.close();
|
|
302
|
+
});
|
|
303
|
+
dev("open", "plugins watched", { dir });
|
|
304
|
+
return [watcher];
|
|
305
|
+
} catch (error) {
|
|
306
|
+
dev("open", "plugins unwatched", { dir, code: readErrorCode2(error) });
|
|
307
|
+
return [];
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
return async () => {
|
|
311
|
+
for (const watcher of watchers)
|
|
312
|
+
watcher.close();
|
|
313
|
+
if (timer !== null)
|
|
314
|
+
clearTimeout(timer);
|
|
315
|
+
await reloads.settled();
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
async function settingsSeed(home) {
|
|
319
|
+
const path = settingsPath(home);
|
|
320
|
+
const text = await readFile(path, "utf8").catch((error) => readErrorCode2(error) === "ENOENT" ? null : error instanceof Error ? error : new Error(String(error)));
|
|
321
|
+
if (text === null)
|
|
322
|
+
return { seed: null, issue: null };
|
|
323
|
+
if (text instanceof Error)
|
|
324
|
+
return {
|
|
325
|
+
seed: null,
|
|
326
|
+
issue: { severity: "warning", path: [], message: `${path} cannot be read: ${text.message}` }
|
|
327
|
+
};
|
|
328
|
+
let parsed;
|
|
329
|
+
try {
|
|
330
|
+
parsed = JSON.parse(text);
|
|
331
|
+
} catch {
|
|
332
|
+
parsed = undefined;
|
|
333
|
+
}
|
|
334
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
335
|
+
return {
|
|
336
|
+
seed: null,
|
|
337
|
+
issue: { severity: "warning", path: [], message: `${path} is not a JSON object.` }
|
|
338
|
+
};
|
|
339
|
+
const settings = {};
|
|
340
|
+
for (const [id, value] of Object.entries(parsed))
|
|
341
|
+
if (isJson(value))
|
|
342
|
+
settings[id] = value;
|
|
343
|
+
return { seed: { settings, path }, issue: null };
|
|
344
|
+
}
|
|
345
|
+
function hostDescription() {
|
|
346
|
+
return { name: hostname(), platform: process.platform, version: package_default.version };
|
|
347
|
+
}
|
|
348
|
+
function settingsPath(home) {
|
|
349
|
+
return join(home, ".nyte", "settings.json");
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export { openHost2 };
|