@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.
Files changed (235) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -2
  3. package/THIRD-PARTY-NOTICES.md +800 -0
  4. package/dist/chunks/canvas-preview-0cmbkp2j.js +65 -0
  5. package/dist/chunks/canvas-preview-0nq75h9k.js +7 -0
  6. package/dist/chunks/canvas-preview-0nrnbt76.js +497 -0
  7. package/dist/chunks/canvas-preview-1sq7z9jq.js +17 -0
  8. package/dist/chunks/canvas-preview-1ta3avah.js +56 -0
  9. package/dist/chunks/canvas-preview-2zdyh9ny.js +26 -0
  10. package/dist/chunks/canvas-preview-31w7xm8z.js +34 -0
  11. package/dist/chunks/canvas-preview-4b6sayhg.js +295 -0
  12. package/dist/chunks/canvas-preview-4e0pxa32.js +63 -0
  13. package/dist/chunks/canvas-preview-518dh8by.js +169 -0
  14. package/dist/chunks/canvas-preview-5hxat7hh.js +239 -0
  15. package/dist/chunks/canvas-preview-5mex725c.js +14 -0
  16. package/dist/chunks/canvas-preview-5z63am63.js +295 -0
  17. package/dist/chunks/canvas-preview-65xqjw7f.js +20 -0
  18. package/dist/chunks/canvas-preview-69fkk9yn.js +95 -0
  19. package/dist/chunks/canvas-preview-75db60xy.js +457 -0
  20. package/dist/chunks/canvas-preview-76fwvd6e.js +272 -0
  21. package/dist/chunks/canvas-preview-8xgt67ka.js +598 -0
  22. package/dist/chunks/canvas-preview-98aj5p34.js +176 -0
  23. package/dist/chunks/canvas-preview-9aqczacs.js +73 -0
  24. package/dist/chunks/canvas-preview-a3yw0j70.js +72 -0
  25. package/dist/chunks/canvas-preview-azg56359.js +68 -0
  26. package/dist/chunks/canvas-preview-d9wwhbtz.js +240 -0
  27. package/dist/chunks/canvas-preview-ehf3vp31.js +411 -0
  28. package/dist/chunks/canvas-preview-evh92ywd.js +369 -0
  29. package/dist/chunks/canvas-preview-ewgspmsd.js +81 -0
  30. package/dist/chunks/canvas-preview-g3qj3y3k.js +156 -0
  31. package/dist/chunks/canvas-preview-h8hshnff.js +63 -0
  32. package/dist/chunks/canvas-preview-j1tnf51w.js +36 -0
  33. package/dist/chunks/canvas-preview-kdqgrstc.js +194 -0
  34. package/dist/chunks/canvas-preview-kn7kvbfj.js +12 -0
  35. package/dist/chunks/canvas-preview-m02v4yy6.js +386 -0
  36. package/dist/chunks/canvas-preview-mgcx2b2p.js +271 -0
  37. package/dist/chunks/canvas-preview-rp4x6y1h.js +144 -0
  38. package/dist/chunks/canvas-preview-rp6fz0w5.js +130 -0
  39. package/dist/chunks/canvas-preview-s94ebwf5.js +112 -0
  40. package/dist/chunks/canvas-preview-senpjwep.js +518 -0
  41. package/dist/chunks/canvas-preview-skzwvw4d.js +23 -0
  42. package/dist/chunks/canvas-preview-srgfpdmf.js +60 -0
  43. package/dist/chunks/canvas-preview-tjhabynd.js +252 -0
  44. package/dist/chunks/canvas-preview-vaatfznm.js +189 -0
  45. package/dist/chunks/canvas-preview-vax9ne4e.js +341 -0
  46. package/dist/chunks/canvas-preview-wg80rbc2.js +46 -0
  47. package/dist/chunks/canvas-preview-xn10d4f8.js +608 -0
  48. package/dist/chunks/canvas-preview-yjz0f7n4.js +50 -0
  49. package/dist/chunks/canvas-preview-ymgz0937.js +587 -0
  50. package/dist/chunks/canvas-preview-yrfz2ak6.js +134 -0
  51. package/dist/chunks/canvas-preview-zaaj99wd.js +244 -0
  52. package/dist/chunks/canvas-preview-zn2d0k9d.js +133 -0
  53. package/dist/src/canvas-preview.d.ts +29 -0
  54. package/dist/src/canvas-preview.js +267 -0
  55. package/dist/src/credentials.d.ts +44 -0
  56. package/dist/src/credentials.js +10 -0
  57. package/dist/src/deploy/cloudflare/worker.d.ts +50 -0
  58. package/dist/src/deploy/cloudflare/worker.js +196 -0
  59. package/dist/src/deploy/vercel/nitro.config.d.ts +2 -0
  60. package/dist/src/deploy/vercel/nitro.config.js +30 -0
  61. package/dist/src/deploy/vercel/server/routes/[...].d.ts +2 -0
  62. package/dist/src/deploy/vercel/server/routes/[...].js +18 -0
  63. package/dist/src/deploy/vercel/server/utils/host.d.ts +13 -0
  64. package/dist/src/deploy/vercel/server/utils/host.js +7 -0
  65. package/dist/src/deploy/vercel/server/utils/repair.d.ts +1 -0
  66. package/dist/src/deploy/vercel/server/utils/repair.js +6 -0
  67. package/dist/src/deploy/vercel/server/utils/step.d.ts +10 -0
  68. package/dist/src/deploy/vercel/server/utils/step.js +6 -0
  69. package/dist/src/deploy/vercel/server/workflows/drive.d.ts +14 -0
  70. package/dist/src/deploy/vercel/server/workflows/drive.js +13 -0
  71. package/dist/src/durable-object.d.ts +14 -0
  72. package/dist/src/durable-object.js +231 -0
  73. package/dist/src/hash.d.ts +1 -0
  74. package/dist/src/hash.js +6 -0
  75. package/dist/src/identity-key.d.ts +11 -0
  76. package/dist/src/identity-key.js +9 -0
  77. package/dist/src/identity.d.ts +12 -0
  78. package/dist/src/identity.js +6 -0
  79. package/dist/src/index.d.ts +21 -0
  80. package/dist/src/index.js +120 -0
  81. package/dist/src/key-file.d.ts +1 -0
  82. package/dist/src/key-file.js +7 -0
  83. package/dist/src/listen-fetch.d.ts +8 -0
  84. package/dist/src/listen-fetch.js +9 -0
  85. package/dist/src/listen.d.ts +4 -0
  86. package/dist/src/listen.js +10 -0
  87. package/dist/src/local/command.d.ts +15 -0
  88. package/dist/src/local/command.js +8 -0
  89. package/dist/src/local/feed.d.ts +7 -0
  90. package/dist/src/local/feed.js +6 -0
  91. package/dist/src/local/files.d.ts +18 -0
  92. package/dist/src/local/files.js +13 -0
  93. package/dist/src/local/git-watch.d.ts +15 -0
  94. package/dist/src/local/git-watch.js +7 -0
  95. package/dist/src/local/git.d.ts +5 -0
  96. package/dist/src/local/git.js +13 -0
  97. package/dist/src/local/github.d.ts +30 -0
  98. package/dist/src/local/github.js +9 -0
  99. package/dist/src/local/identity.d.ts +3 -0
  100. package/dist/src/local/identity.js +7 -0
  101. package/dist/src/local/jobs.d.ts +7 -0
  102. package/dist/src/local/jobs.js +6 -0
  103. package/dist/src/local/legacy-trust.d.ts +10 -0
  104. package/dist/src/local/legacy-trust.js +6 -0
  105. package/dist/src/local/patch.d.ts +16 -0
  106. package/dist/src/local/patch.js +17 -0
  107. package/dist/src/local/provider.d.ts +11 -0
  108. package/dist/src/local/provider.js +20 -0
  109. package/dist/src/local/snapshots.d.ts +7 -0
  110. package/dist/src/local/snapshots.js +11 -0
  111. package/dist/src/local/text.d.ts +1 -0
  112. package/dist/src/local/text.js +6 -0
  113. package/dist/src/local/tree.d.ts +50 -0
  114. package/dist/src/local/tree.js +16 -0
  115. package/dist/src/local/workspace-migration.d.ts +2 -0
  116. package/dist/src/local/workspace-migration.js +7 -0
  117. package/dist/src/local/worktrees.d.ts +46 -0
  118. package/dist/src/local/worktrees.js +14 -0
  119. package/dist/src/mcp/config.d.ts +75 -0
  120. package/dist/src/mcp/config.js +12 -0
  121. package/dist/src/mcp/connect.d.ts +28 -0
  122. package/dist/src/mcp/connect.js +9 -0
  123. package/dist/src/mcp/hub.d.ts +19 -0
  124. package/dist/src/mcp/hub.js +11 -0
  125. package/dist/src/mcp/oauth.d.ts +46 -0
  126. package/dist/src/mcp/oauth.js +12 -0
  127. package/dist/src/mcp/tools.d.ts +29 -0
  128. package/dist/src/mcp/tools.js +12 -0
  129. package/dist/src/open.d.ts +42 -0
  130. package/dist/src/open.js +44 -0
  131. package/dist/src/plugins/loader.d.ts +21 -0
  132. package/dist/src/plugins/loader.js +11 -0
  133. package/dist/src/postgres.d.ts +19 -0
  134. package/dist/src/postgres.js +8 -0
  135. package/dist/src/providers.d.ts +16 -0
  136. package/dist/src/providers.js +112 -0
  137. package/dist/src/secrets.d.ts +12 -0
  138. package/dist/src/secrets.js +8 -0
  139. package/dist/src/serve/binding.d.ts +39 -0
  140. package/dist/src/serve/binding.js +6 -0
  141. package/dist/src/serve/handler.d.ts +15 -0
  142. package/dist/src/serve/handler.js +8 -0
  143. package/dist/src/serve/stream-server.d.ts +6 -0
  144. package/dist/src/serve/stream-server.js +6 -0
  145. package/dist/src/session-index.d.ts +11 -0
  146. package/dist/src/session-index.js +11 -0
  147. package/dist/src/shell-env.d.ts +14 -0
  148. package/dist/src/shell-env.js +108 -0
  149. package/dist/src/sqlite-workers.d.ts +6 -0
  150. package/dist/src/sqlite-workers.js +6 -0
  151. package/dist/src/sqlite.d.ts +7 -0
  152. package/dist/src/sqlite.js +10 -0
  153. package/dist/src/store-owner.d.ts +15 -0
  154. package/dist/src/store-owner.js +9 -0
  155. package/dist/src/store-rows.d.ts +13 -0
  156. package/dist/src/store-rows.js +26 -0
  157. package/dist/src/store-usage.d.ts +25 -0
  158. package/dist/src/store-usage.js +16 -0
  159. package/dist/src/usage-scan.d.ts +24 -0
  160. package/dist/src/usage-scan.js +65 -0
  161. package/dist/src/usage-service.d.ts +22 -0
  162. package/dist/src/usage-service.js +12 -0
  163. package/dist/src/usage-summary.d.ts +9 -0
  164. package/dist/src/usage-summary.js +16 -0
  165. package/dist/src/usage-types.d.ts +86 -0
  166. package/dist/src/usage-types.js +0 -0
  167. package/dist/src/usage-worker.d.ts +1 -0
  168. package/dist/src/usage-worker.js +25 -0
  169. package/dist/src/usage.d.ts +72 -0
  170. package/dist/src/usage.js +13 -0
  171. package/package.json +132 -3
  172. package/src/canvas-preview.ts +402 -0
  173. package/src/credentials.ts +294 -0
  174. package/src/deploy/cloudflare/README.md +3 -0
  175. package/src/deploy/cloudflare/worker.ts +306 -0
  176. package/src/deploy/cloudflare/wrangler.jsonc +12 -0
  177. package/src/deploy/vercel/README.md +3 -0
  178. package/src/deploy/vercel/nitro.config.ts +29 -0
  179. package/src/deploy/vercel/server/routes/[...].ts +10 -0
  180. package/src/deploy/vercel/server/utils/host.ts +104 -0
  181. package/src/deploy/vercel/server/utils/repair.ts +35 -0
  182. package/src/deploy/vercel/server/utils/step.ts +25 -0
  183. package/src/deploy/vercel/server/workflows/drive.ts +46 -0
  184. package/src/deploy/vercel/tsconfig.json +9 -0
  185. package/src/deploy/vercel/types/bun.d.ts +2 -0
  186. package/src/durable-object.ts +386 -0
  187. package/src/hash.ts +5 -0
  188. package/src/identity-key.ts +20 -0
  189. package/src/identity.ts +66 -0
  190. package/src/index.ts +21 -0
  191. package/src/key-file.ts +53 -0
  192. package/src/listen-fetch.ts +409 -0
  193. package/src/listen.ts +228 -0
  194. package/src/local/command.ts +109 -0
  195. package/src/local/feed.ts +70 -0
  196. package/src/local/files.ts +812 -0
  197. package/src/local/git-watch.ts +189 -0
  198. package/src/local/git.ts +914 -0
  199. package/src/local/github.ts +692 -0
  200. package/src/local/identity.ts +21 -0
  201. package/src/local/jobs.ts +587 -0
  202. package/src/local/legacy-trust.ts +105 -0
  203. package/src/local/patch.ts +334 -0
  204. package/src/local/provider.ts +184 -0
  205. package/src/local/snapshots.ts +776 -0
  206. package/src/local/text.ts +9 -0
  207. package/src/local/tree.ts +398 -0
  208. package/src/local/workspace-migration.ts +95 -0
  209. package/src/local/worktrees.ts +239 -0
  210. package/src/mcp/config.ts +330 -0
  211. package/src/mcp/connect.ts +105 -0
  212. package/src/mcp/hub.ts +836 -0
  213. package/src/mcp/oauth.ts +436 -0
  214. package/src/mcp/tools.ts +333 -0
  215. package/src/open.ts +469 -0
  216. package/src/plugins/loader.ts +186 -0
  217. package/src/postgres.ts +492 -0
  218. package/src/providers.ts +135 -0
  219. package/src/secrets.ts +31 -0
  220. package/src/serve/binding.ts +628 -0
  221. package/src/serve/handler.ts +362 -0
  222. package/src/serve/stream-server.ts +176 -0
  223. package/src/session-index.ts +99 -0
  224. package/src/shell-env.ts +153 -0
  225. package/src/sqlite-workers.ts +283 -0
  226. package/src/sqlite.ts +528 -0
  227. package/src/store-owner.ts +98 -0
  228. package/src/store-rows.ts +110 -0
  229. package/src/store-usage.ts +344 -0
  230. package/src/usage-scan.ts +81 -0
  231. package/src/usage-service.ts +73 -0
  232. package/src/usage-summary.ts +79 -0
  233. package/src/usage-types.ts +87 -0
  234. package/src/usage-worker.ts +24 -0
  235. package/src/usage.ts +701 -0
@@ -0,0 +1,341 @@
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-75db60xy.js";
13
+ import {
14
+ localProvider2
15
+ } from "./canvas-preview-yrfz2ak6.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-98aj5p34.js";
25
+ import {
26
+ createMcpHub2
27
+ } from "./canvas-preview-8xgt67ka.js";
28
+ import {
29
+ loadPluginDirectory2,
30
+ pluginLoader2
31
+ } from "./canvas-preview-s94ebwf5.js";
32
+ import {
33
+ defaultSecrets2
34
+ } from "./canvas-preview-skzwvw4d.js";
35
+ import {
36
+ sqliteStore2
37
+ } from "./canvas-preview-evh92ywd.js";
38
+ import {
39
+ package_default
40
+ } from "./canvas-preview-g3qj3y3k.js";
41
+
42
+ // src/open.ts
43
+ import { watch } from "node:fs";
44
+ import { mkdir, readFile } from "node:fs/promises";
45
+ import { homedir, hostname } from "node:os";
46
+ import { join } from "node:path";
47
+ import process from "node:process";
48
+ import { defaultProviderAuthContext } from "@nyte-ai/ai/auth/context";
49
+ import { FileModelsStore, nyteProviders } from "@nyte-ai/ai";
50
+ import { createModels } from "@nyte-ai/ai/models";
51
+ import { isJson } from "@nyte-ai/schema";
52
+ import { serial } from "@nyte-ai/schema/serial";
53
+ import { dev, processEnvironment } from "@nyte-ai/core";
54
+ import { composeHost } from "@nyte-ai/core/server";
55
+ import { readModelSelection } from "@nyte-ai/core/store";
56
+ import approvals from "@nyte-ai/plugin/core/approvals";
57
+ import { acpAgents } from "@nyte-ai/plugin/core/acp";
58
+ import bashDescription from "@nyte-ai/plugin/core/bash-description";
59
+ import browserTools from "@nyte-ai/plugin/core/browser-tools";
60
+ import canvas from "@nyte-ai/plugin/core/canvas";
61
+ import { claudeCodeSdk } from "@nyte-ai/plugin/core/claude-code-sdk";
62
+ import codemode from "@nyte-ai/plugin/core/codemode";
63
+ import openaiAstraContext from "@nyte-ai/plugin/core/openai-astra-context";
64
+ import { openaiCompaction } from "@nyte-ai/plugin/core/openai-compaction";
65
+ import question from "@nyte-ai/plugin/core/question";
66
+ import rename from "@nyte-ai/plugin/core/rename";
67
+ import telemetry from "@nyte-ai/plugin/core/telemetry";
68
+ import webSearch from "@nyte-ai/plugin/core/web-search";
69
+ var RELOAD_DEBOUNCE_MS = 250;
70
+ var STORE_POLL_MS = 500;
71
+ async function openHost2(options) {
72
+ const home = options.home ?? homedir();
73
+ const workspace = options.workspace ?? { kind: "local", path: process.cwd() };
74
+ if (options.store !== undefined)
75
+ return composeOpen(options, { home, workspace, store: options.store, owned: null });
76
+ const owned = await defaultStore(home);
77
+ try {
78
+ return await composeOpen(options, { home, workspace, store: owned, owned });
79
+ } catch (cause) {
80
+ await owned.close().catch(() => {
81
+ return;
82
+ });
83
+ throw cause;
84
+ }
85
+ }
86
+ async function defaultStore(home) {
87
+ await mkdir(join(home, ".nyte"), { recursive: true, mode: 448 });
88
+ return sqliteStore2({ path: join(home, ".nyte", "nyte.db") });
89
+ }
90
+ async function composeOpen(options, input) {
91
+ const { home, workspace, store, owned } = input;
92
+ const secrets = options.secrets ?? defaultSecrets2(home);
93
+ const description = hostDescription();
94
+ const given = options.plugins ?? [];
95
+ const usesLocalProvider = !given.some((plugin) => plugin.environment?.kind === "local");
96
+ const claudeCode = claudeCodeSdk();
97
+ const acp = acpAgents();
98
+ const [models, files, settings] = await Promise.all([
99
+ options.models ?? nyteModels({ store, secrets, home, providers: [claudeCode.provider, acp.provider] }),
100
+ filePlugins(home),
101
+ settingsSeed(home),
102
+ usesLocalProvider ? store.open().then(async (connection) => {
103
+ await migrateLocalWorkspaceIdentities2(connection);
104
+ await importLegacyTrust2(connection, home);
105
+ }) : undefined
106
+ ]);
107
+ const builtins = [
108
+ approvals,
109
+ question,
110
+ rename,
111
+ bashDescription,
112
+ webSearch,
113
+ codemode,
114
+ openaiCompaction(models),
115
+ openaiAstraContext,
116
+ telemetry,
117
+ canvas,
118
+ browserTools,
119
+ claudeCode.plugin,
120
+ acp.plugin
121
+ ];
122
+ const plugins = [
123
+ ...usesLocalProvider ? [{ id: "local", environment: localProvider2({ home, shell: options.shell }) }] : [],
124
+ ...builtins.filter((builtin) => !given.some((plugin) => plugin.id === builtin.id)),
125
+ ...given
126
+ ];
127
+ let projectDirs = async () => [];
128
+ const host = await composeHost({
129
+ ...options,
130
+ store,
131
+ workspace,
132
+ loadPlugins: async (paths) => pluginLoader2([...files.dirs, ...await projectDirs()])(paths),
133
+ models,
134
+ mcp: options.mcp ?? createMcpHub2({ home }),
135
+ github: options.github ?? (usesLocalProvider ? localGitHubAccount2({ home }) : undefined),
136
+ plugins: [...plugins, ...files.plugins],
137
+ pluginSources: files.sources,
138
+ secrets,
139
+ home,
140
+ description,
141
+ ...settings.seed === null ? {} : { seed: settings.seed },
142
+ ...owned === null ? {} : { poll: STORE_POLL_MS }
143
+ });
144
+ projectDirs = async () => (await host.workspaces.list()).flatMap((entry) => entry.trusted === true && ("path" in entry.target) ? [join(entry.target.path, ".nyte", "plugins")] : []);
145
+ for (const row of files.failed)
146
+ host.server.report(row);
147
+ if (settings.issue !== null)
148
+ host.server.report({
149
+ id: "settings",
150
+ source: "user",
151
+ path: settingsPath(home),
152
+ issues: [settings.issue]
153
+ });
154
+ dev("open", "host", {
155
+ home,
156
+ seedIds: Object.keys(settings.seed?.settings ?? {}).length,
157
+ pluginFiles: files.plugins.length + files.failed.length,
158
+ failedFiles: files.failed.length
159
+ });
160
+ const reported = new Map(host.server.pluginRows().filter((row) => row.path !== null && row.id === row.path).map((row) => [row.id, row]));
161
+ const reload = async () => {
162
+ const next = await filePlugins(home);
163
+ for (const [plugin, source] of next.sources)
164
+ files.sources.set(plugin, source);
165
+ const report = await host.plugins.replace([...plugins, ...next.plugins]);
166
+ const failed = [...next.failed, ...refused(next, report)];
167
+ for (const [id, row] of reported)
168
+ if (!failed.some((row) => row.id === id))
169
+ host.server.report({ ...row, issues: [] });
170
+ for (const row of failed)
171
+ host.server.report(row);
172
+ reported.clear();
173
+ for (const row of failed)
174
+ reported.set(row.id, row);
175
+ for (const plugin of files.sources.keys())
176
+ if (!host.server.loaded(plugin))
177
+ files.sources.delete(plugin);
178
+ dev("open", "plugins reloaded", {
179
+ generation: report.generation,
180
+ pluginFiles: next.plugins.length,
181
+ failedFiles: failed.length
182
+ });
183
+ };
184
+ const unwatch = watchPlugins(files.dirs, reload);
185
+ const listeners = new Set;
186
+ let identity = null;
187
+ const attach = async (listenOptions) => {
188
+ const listener = await listen2(host, {
189
+ describe: () => description,
190
+ ...listenOptions,
191
+ identity: listenOptions.identity ?? await (identity ??= identitySigner2(host.hostId, home))
192
+ });
193
+ listeners.add(listener);
194
+ dev("open", "listen", { address: listener.address });
195
+ return listener;
196
+ };
197
+ let closing = null;
198
+ const close = () => {
199
+ closing ??= (async () => {
200
+ await unwatch();
201
+ for (const listener of listeners)
202
+ await listener.close();
203
+ await host.close();
204
+ await owned?.close();
205
+ })();
206
+ return closing;
207
+ };
208
+ return { ...host, listen: attach, close, [Symbol.asyncDispose]: close };
209
+ }
210
+ async function nyteModels(input) {
211
+ const credentials = credentialStore2(input.store, input.secrets);
212
+ const auth = defaultProviderAuthContext();
213
+ const models = createModels({
214
+ credentials,
215
+ modelsStore: new FileModelsStore(join(input.home, ".nyte", "models-store.json")),
216
+ authContext: {
217
+ ...auth,
218
+ env: async (name) => {
219
+ await processEnvironment();
220
+ return auth.env(name);
221
+ }
222
+ },
223
+ catalog: { url: process.env.NYTE_MODELS_URL }
224
+ });
225
+ for (const provider of [...nyteProviders(), ...input.providers])
226
+ models.setProvider(provider);
227
+ const [stored, selected] = await Promise.all([
228
+ credentials.list(),
229
+ input.store.open().then(readModelSelection)
230
+ ]);
231
+ const restored = await models.refresh({
232
+ providers: [
233
+ ...new Set([
234
+ ...stored.map((row) => row.providerId),
235
+ ...input.providers.map((provider) => provider.id),
236
+ ...selected === null ? [] : [selected.provider]
237
+ ])
238
+ ],
239
+ allowNetwork: false
240
+ });
241
+ dev("open", "models restored", {
242
+ providers: stored.length,
243
+ failed: [...restored.errors.keys()]
244
+ });
245
+ return models;
246
+ }
247
+ async function filePlugins(home) {
248
+ const scopes = [{ source: "user", dir: join(home, ".nyte", "plugins") }];
249
+ const plugins = [];
250
+ const sources = new Map;
251
+ const failed = [];
252
+ for (const { source, dir } of scopes) {
253
+ const found = await loadPluginDirectory2(dir);
254
+ for (const { plugin, path } of found.loaded) {
255
+ plugins.push(plugin);
256
+ sources.set(plugin, { source, path });
257
+ }
258
+ for (const { path, issue } of found.failed)
259
+ failed.push({ id: path, source, path, issues: [issue] });
260
+ }
261
+ return { plugins, sources, dirs: scopes.map((scope) => scope.dir), failed };
262
+ }
263
+ function refused(files, report) {
264
+ return report.plugins.flatMap((outcome) => {
265
+ const plugin = files.plugins.find((candidate) => candidate.id === outcome.id);
266
+ const file = plugin === undefined ? undefined : files.sources.get(plugin);
267
+ return outcome.kind === "activated" || file === undefined ? [] : [{ id: file.path, source: file.source, path: file.path, issues: outcome.issues }];
268
+ });
269
+ }
270
+ function watchPlugins(dirs, reload) {
271
+ let timer = null;
272
+ const reloads = serial();
273
+ const run = () => {
274
+ timer = null;
275
+ reloads.run(reload).catch((error) => dev("open", "plugin reload failed", {
276
+ message: error instanceof Error ? error.message : String(error)
277
+ }));
278
+ };
279
+ const changed = () => {
280
+ if (timer !== null)
281
+ clearTimeout(timer);
282
+ timer = setTimeout(run, RELOAD_DEBOUNCE_MS);
283
+ timer.unref();
284
+ };
285
+ const watchers = dirs.flatMap((dir) => {
286
+ try {
287
+ const watcher = watch(dir, { recursive: true, persistent: false }, changed);
288
+ watcher.on("error", (error) => {
289
+ dev("open", "plugin watch failed", { dir, message: error.message });
290
+ watcher.close();
291
+ });
292
+ dev("open", "plugins watched", { dir });
293
+ return [watcher];
294
+ } catch (error) {
295
+ dev("open", "plugins unwatched", { dir, code: readErrorCode2(error) });
296
+ return [];
297
+ }
298
+ });
299
+ return async () => {
300
+ for (const watcher of watchers)
301
+ watcher.close();
302
+ if (timer !== null)
303
+ clearTimeout(timer);
304
+ await reloads.settled();
305
+ };
306
+ }
307
+ async function settingsSeed(home) {
308
+ const path = settingsPath(home);
309
+ const text = await readFile(path, "utf8").catch((error) => readErrorCode2(error) === "ENOENT" ? null : error instanceof Error ? error : new Error(String(error)));
310
+ if (text === null)
311
+ return { seed: null, issue: null };
312
+ if (text instanceof Error)
313
+ return {
314
+ seed: null,
315
+ issue: { severity: "warning", path: [], message: `${path} cannot be read: ${text.message}` }
316
+ };
317
+ let parsed;
318
+ try {
319
+ parsed = JSON.parse(text);
320
+ } catch {
321
+ parsed = undefined;
322
+ }
323
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
324
+ return {
325
+ seed: null,
326
+ issue: { severity: "warning", path: [], message: `${path} is not a JSON object.` }
327
+ };
328
+ const settings = {};
329
+ for (const [id, value] of Object.entries(parsed))
330
+ if (isJson(value))
331
+ settings[id] = value;
332
+ return { seed: { settings, path }, issue: null };
333
+ }
334
+ function hostDescription() {
335
+ return { name: hostname(), platform: process.platform, version: package_default.version };
336
+ }
337
+ function settingsPath(home) {
338
+ return join(home, ".nyte", "settings.json");
339
+ }
340
+
341
+ export { openHost2 };
@@ -0,0 +1,46 @@
1
+ import {
2
+ readErrorCode2
3
+ } from "./canvas-preview-mgcx2b2p.js";
4
+
5
+ // src/key-file.ts
6
+ import { link, mkdir, open, readFile, unlink } from "node:fs/promises";
7
+ import { dirname } from "node:path";
8
+ import { SdkError } from "@nyte-ai/schema";
9
+ async function readKeyFile2(path, name) {
10
+ const bytes = await readFile(path).then((stored) => new Uint8Array(stored), (error) => {
11
+ if (readErrorCode2(error) === "ENOENT")
12
+ return mintKeyFile(path);
13
+ throw error;
14
+ }).catch((error) => {
15
+ throw new SdkError("unavailable", `The ${name} at ${path} cannot be read: ${error instanceof Error ? error.message : String(error)}`);
16
+ });
17
+ if (bytes.length !== 32)
18
+ throw new SdkError("invalid", `The ${name} at ${path} is ${bytes.length} bytes, not 32.`);
19
+ return bytes;
20
+ }
21
+ async function mintKeyFile(path) {
22
+ await mkdir(dirname(path), { recursive: true, mode: 448 });
23
+ const bytes = crypto.getRandomValues(new Uint8Array(32));
24
+ const temp = `${path}.${crypto.randomUUID()}`;
25
+ const file = await open(temp, "wx", 384);
26
+ try {
27
+ await file.writeFile(bytes);
28
+ await file.sync();
29
+ } finally {
30
+ await file.close();
31
+ }
32
+ try {
33
+ await link(temp, path);
34
+ return bytes;
35
+ } catch (error) {
36
+ if (readErrorCode2(error) !== "EEXIST")
37
+ throw error;
38
+ return new Uint8Array(await readFile(path));
39
+ } finally {
40
+ await unlink(temp).catch(() => {
41
+ return;
42
+ });
43
+ }
44
+ }
45
+
46
+ export { readKeyFile2 };