@atomic-chat/core 0.17.0 → 0.18.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/dist/app-daemon.js +9 -0
  2. package/dist/app-daemon.js.map +1 -1
  3. package/dist/cli/main.d.ts +1 -1
  4. package/dist/cli/main.js +5 -0
  5. package/dist/cli/main.js.map +1 -1
  6. package/dist/client/control-client.d.ts +10 -1
  7. package/dist/client/control-client.js +15 -0
  8. package/dist/client/control-client.js.map +1 -1
  9. package/dist/cloud/registry.js +1 -0
  10. package/dist/cloud/registry.js.map +1 -1
  11. package/dist/config/paths.d.ts +4 -0
  12. package/dist/config/paths.js +11 -0
  13. package/dist/config/paths.js.map +1 -1
  14. package/dist/contracts/engine-builds.d.ts +1 -1
  15. package/dist/contracts/engine-builds.js +1 -1
  16. package/dist/contracts/engine-builds.js.map +1 -1
  17. package/dist/contracts/engines.d.ts +1 -1
  18. package/dist/contracts/engines.js +2 -0
  19. package/dist/contracts/engines.js.map +1 -1
  20. package/dist/contracts/errors.d.ts +7 -1
  21. package/dist/contracts/errors.js.map +1 -1
  22. package/dist/contracts/events.d.ts +7 -0
  23. package/dist/contracts/foundry-local.d.ts +77 -0
  24. package/dist/contracts/foundry-local.js +17 -0
  25. package/dist/contracts/foundry-local.js.map +1 -0
  26. package/dist/contracts/index.d.ts +1 -0
  27. package/dist/contracts/index.js +1 -0
  28. package/dist/contracts/index.js.map +1 -1
  29. package/dist/contracts/model-yml.d.ts +28 -0
  30. package/dist/contracts/model-yml.js +11 -0
  31. package/dist/contracts/model-yml.js.map +1 -1
  32. package/dist/contracts/session.d.ts +5 -1
  33. package/dist/contracts/session.js.map +1 -1
  34. package/dist/contracts/settings.d.ts +5 -1
  35. package/dist/contracts/settings.js.map +1 -1
  36. package/dist/core/atomic-core.d.ts +1 -1
  37. package/dist/core/create.js +106 -5
  38. package/dist/core/create.js.map +1 -1
  39. package/dist/core/types.d.ts +9 -0
  40. package/dist/core/types.js.map +1 -1
  41. package/dist/diffusion/install.d.ts +0 -4
  42. package/dist/diffusion/install.js +5 -2
  43. package/dist/diffusion/install.js.map +1 -1
  44. package/dist/diffusion/server-process.d.ts +5 -2
  45. package/dist/diffusion/server-process.js +10 -2
  46. package/dist/diffusion/server-process.js.map +1 -1
  47. package/dist/downloads/archive.d.ts +1 -1
  48. package/dist/downloads/archive.js +2 -2
  49. package/dist/downloads/archive.js.map +1 -1
  50. package/dist/engine-builds/engines.d.ts +83 -0
  51. package/dist/engine-builds/engines.js +144 -0
  52. package/dist/engine-builds/engines.js.map +1 -0
  53. package/dist/engine-builds/foundry-local.d.ts +22 -0
  54. package/dist/engine-builds/foundry-local.js +100 -0
  55. package/dist/engine-builds/foundry-local.js.map +1 -0
  56. package/dist/engine-builds/manifest.d.ts +57 -6
  57. package/dist/engine-builds/manifest.js +109 -4
  58. package/dist/engine-builds/manifest.js.map +1 -1
  59. package/dist/engine-builds/order.d.ts +2 -1
  60. package/dist/engine-builds/order.js +11 -4
  61. package/dist/engine-builds/order.js.map +1 -1
  62. package/dist/engine-builds/select.d.ts +27 -0
  63. package/dist/engine-builds/select.js +45 -0
  64. package/dist/engine-builds/select.js.map +1 -1
  65. package/dist/engine-builds/service.d.ts +14 -15
  66. package/dist/engine-builds/service.js +68 -126
  67. package/dist/engine-builds/service.js.map +1 -1
  68. package/dist/engines/service.d.ts +6 -3
  69. package/dist/engines/service.js +6 -3
  70. package/dist/engines/service.js.map +1 -1
  71. package/dist/hardware/index.d.ts +1 -0
  72. package/dist/hardware/index.js +1 -0
  73. package/dist/hardware/index.js.map +1 -1
  74. package/dist/hardware/npu.d.ts +14 -0
  75. package/dist/hardware/npu.js +29 -0
  76. package/dist/hardware/npu.js.map +1 -0
  77. package/dist/integrations/detect.d.ts +2 -0
  78. package/dist/integrations/detect.js +4 -3
  79. package/dist/integrations/detect.js.map +1 -1
  80. package/dist/lock/instance-lock.js +5 -2
  81. package/dist/lock/instance-lock.js.map +1 -1
  82. package/dist/lock/process-identity.d.ts +9 -3
  83. package/dist/lock/process-identity.js +75 -9
  84. package/dist/lock/process-identity.js.map +1 -1
  85. package/dist/router/resolve.d.ts +2 -2
  86. package/dist/router/resolve.js +2 -1
  87. package/dist/router/resolve.js.map +1 -1
  88. package/dist/runtime/foundry-local/accelerators.d.ts +42 -0
  89. package/dist/runtime/foundry-local/accelerators.js +153 -0
  90. package/dist/runtime/foundry-local/accelerators.js.map +1 -0
  91. package/dist/runtime/foundry-local/check.d.ts +19 -0
  92. package/dist/runtime/foundry-local/check.js +69 -0
  93. package/dist/runtime/foundry-local/check.js.map +1 -0
  94. package/dist/runtime/foundry-local/host/args.d.ts +44 -0
  95. package/dist/runtime/foundry-local/host/args.js +109 -0
  96. package/dist/runtime/foundry-local/host/args.js.map +1 -0
  97. package/dist/runtime/foundry-local/host/execution-providers.d.ts +27 -0
  98. package/dist/runtime/foundry-local/host/execution-providers.js +43 -0
  99. package/dist/runtime/foundry-local/host/execution-providers.js.map +1 -0
  100. package/dist/runtime/foundry-local/host/ffi-bun.d.ts +17 -0
  101. package/dist/runtime/foundry-local/host/ffi-bun.js +256 -0
  102. package/dist/runtime/foundry-local/host/ffi-bun.js.map +1 -0
  103. package/dist/runtime/foundry-local/host/library.d.ts +61 -0
  104. package/dist/runtime/foundry-local/host/library.js +17 -0
  105. package/dist/runtime/foundry-local/host/library.js.map +1 -0
  106. package/dist/runtime/foundry-local/host/run.d.ts +54 -0
  107. package/dist/runtime/foundry-local/host/run.js +316 -0
  108. package/dist/runtime/foundry-local/host/run.js.map +1 -0
  109. package/dist/runtime/foundry-local/host-process.d.ts +78 -0
  110. package/dist/runtime/foundry-local/host-process.js +182 -0
  111. package/dist/runtime/foundry-local/host-process.js.map +1 -0
  112. package/dist/runtime/foundry-local/index.d.ts +11 -0
  113. package/dist/runtime/foundry-local/index.js +11 -0
  114. package/dist/runtime/foundry-local/index.js.map +1 -0
  115. package/dist/runtime/foundry-local/model-yml.d.ts +8 -0
  116. package/dist/runtime/foundry-local/model-yml.js +63 -0
  117. package/dist/runtime/foundry-local/model-yml.js.map +1 -0
  118. package/dist/runtime/foundry-local/runtime.d.ts +88 -0
  119. package/dist/runtime/foundry-local/runtime.js +321 -0
  120. package/dist/runtime/foundry-local/runtime.js.map +1 -0
  121. package/dist/runtime/llamacpp/args.d.ts +5 -0
  122. package/dist/runtime/llamacpp/args.js +7 -1
  123. package/dist/runtime/llamacpp/args.js.map +1 -1
  124. package/dist/runtime/llamacpp/errors.d.ts +1 -0
  125. package/dist/runtime/llamacpp/errors.js +10 -0
  126. package/dist/runtime/llamacpp/errors.js.map +1 -1
  127. package/dist/runtime/llamacpp/load-plan.d.ts +5 -0
  128. package/dist/runtime/llamacpp/load-plan.js +8 -0
  129. package/dist/runtime/llamacpp/load-plan.js.map +1 -1
  130. package/dist/runtime/llamacpp/runtime-device.d.ts +8 -0
  131. package/dist/runtime/llamacpp/runtime-device.js +9 -3
  132. package/dist/runtime/llamacpp/runtime-device.js.map +1 -1
  133. package/dist/runtime/llamacpp/runtime.d.ts +6 -1
  134. package/dist/runtime/llamacpp/runtime.js +19 -3
  135. package/dist/runtime/llamacpp/runtime.js.map +1 -1
  136. package/dist/runtime/managed-text/gateway.d.ts +2 -0
  137. package/dist/runtime/managed-text/gateway.js +1 -1
  138. package/dist/runtime/managed-text/gateway.js.map +1 -1
  139. package/dist/runtime/shared/external-sessions.js +1 -0
  140. package/dist/runtime/shared/external-sessions.js.map +1 -1
  141. package/dist/runtime/shared/process.d.ts +13 -1
  142. package/dist/runtime/shared/process.js +21 -12
  143. package/dist/runtime/shared/process.js.map +1 -1
  144. package/dist/server/control/router.js +2 -0
  145. package/dist/server/control/router.js.map +1 -1
  146. package/dist/server/control/routes/foundry-local.d.ts +10 -0
  147. package/dist/server/control/routes/foundry-local.js +42 -0
  148. package/dist/server/control/routes/foundry-local.js.map +1 -0
  149. package/dist/server/control/routes/models.js +3 -1
  150. package/dist/server/control/routes/models.js.map +1 -1
  151. package/dist/server/control/types.d.ts +17 -1
  152. package/dist/server/control/types.js.map +1 -1
  153. package/dist/server/http.js +2 -0
  154. package/dist/server/http.js.map +1 -1
  155. package/dist/server/public/errors.d.ts +1 -0
  156. package/dist/server/public/errors.js +18 -0
  157. package/dist/server/public/errors.js.map +1 -1
  158. package/dist/server/public/listing.js +1 -0
  159. package/dist/server/public/listing.js.map +1 -1
  160. package/dist/settings/schema/foundry-local.json +14 -0
  161. package/dist/settings/schema.js +8 -0
  162. package/dist/settings/schema.js.map +1 -1
  163. package/dist/version.d.ts +1 -1
  164. package/dist/version.js +1 -1
  165. package/package.json +2 -1
  166. package/src/settings/schema/foundry-local.json +14 -0
@@ -0,0 +1,109 @@
1
+ /**
2
+ * The arguments of the hidden `foundry-host` mode (openspec change `add-foundry-local`, task 5.1).
3
+ * Core is the only caller, so the parse is strict: anything unknown is a bug on core's side.
4
+ *
5
+ * foundry-host probe --lib <build> --app-data <dir> --logs <dir> [--prepared <ep>]…
6
+ * foundry-host prepare --lib <build> --app-data <dir> --logs <dir> [<ep>…]
7
+ * foundry-host serve --lib <build> --app-data <dir> --logs <dir> --model <dir> --ep <ep>
8
+ * --port <p> --cache <dir> --id <name>:<version> [--tools]
9
+ * [--reasoning-start <s> --reasoning-end <s>] [--context-length <n>]
10
+ */
11
+ import { parseArgs } from 'node:util';
12
+ import { FOUNDRY_LOCAL_EXECUTION_PROVIDERS } from '../../../contracts/index.js';
13
+ export class FoundryHostUsageError extends Error {
14
+ constructor(message) {
15
+ super(message);
16
+ this.name = 'FoundryHostUsageError';
17
+ }
18
+ }
19
+ const COMMON_OPTIONS = {
20
+ 'lib': { type: 'string' },
21
+ 'app-data': { type: 'string' },
22
+ 'logs': { type: 'string' },
23
+ };
24
+ const required = (values, key) => {
25
+ const value = values[key];
26
+ if (typeof value !== 'string' || value === '')
27
+ throw new FoundryHostUsageError(`--${key} is required`);
28
+ return value;
29
+ };
30
+ function common(values) {
31
+ return {
32
+ lib: required(values, 'lib'),
33
+ appData: required(values, 'app-data'),
34
+ logs: required(values, 'logs'),
35
+ };
36
+ }
37
+ export function parseFoundryHostArgs(argv) {
38
+ const [mode, ...rest] = argv;
39
+ try {
40
+ if (mode === 'probe') {
41
+ const { values } = parseArgs({
42
+ args: rest,
43
+ options: { ...COMMON_OPTIONS, prepared: { type: 'string', multiple: true } },
44
+ strict: true,
45
+ });
46
+ return { mode, ...common(values), prepared: values.prepared ?? [] };
47
+ }
48
+ if (mode === 'prepare') {
49
+ const { values, positionals } = parseArgs({
50
+ args: rest,
51
+ options: COMMON_OPTIONS,
52
+ strict: true,
53
+ allowPositionals: true,
54
+ });
55
+ return { mode, ...common(values), accelerators: positionals };
56
+ }
57
+ if (mode === 'serve') {
58
+ const { values } = parseArgs({
59
+ args: rest,
60
+ options: {
61
+ ...COMMON_OPTIONS,
62
+ 'model': { type: 'string' },
63
+ 'ep': { type: 'string' },
64
+ 'port': { type: 'string' },
65
+ 'cache': { type: 'string' },
66
+ 'id': { type: 'string' },
67
+ 'tools': { type: 'boolean' },
68
+ 'reasoning-start': { type: 'string' },
69
+ 'reasoning-end': { type: 'string' },
70
+ 'context-length': { type: 'string' },
71
+ },
72
+ strict: true,
73
+ });
74
+ const ep = required(values, 'ep');
75
+ if (!FOUNDRY_LOCAL_EXECUTION_PROVIDERS.some((known) => known === ep))
76
+ throw new FoundryHostUsageError(`--ep ${ep} is not an accelerator this host runs`);
77
+ const port = Number(required(values, 'port'));
78
+ if (!Number.isInteger(port) || port < 1 || port > 65535)
79
+ throw new FoundryHostUsageError(`--port ${values.port} is not a port`);
80
+ const id = required(values, 'id');
81
+ if (!/^[^:\s]+:\d+$/.test(id))
82
+ throw new FoundryHostUsageError(`--id ${id} is not <name>:<version>`);
83
+ const context = values['context-length'];
84
+ const contextLength = context === undefined ? undefined : Number(context);
85
+ if (contextLength !== undefined && (!Number.isSafeInteger(contextLength) || contextLength < 1))
86
+ throw new FoundryHostUsageError(`--context-length ${context} is not a positive whole number`);
87
+ return {
88
+ mode,
89
+ ...common(values),
90
+ model: required(values, 'model'),
91
+ ep: ep,
92
+ port,
93
+ cache: required(values, 'cache'),
94
+ id,
95
+ tools: values.tools === true,
96
+ ...(values['reasoning-start'] !== undefined ? { reasoningStart: values['reasoning-start'] } : {}),
97
+ ...(values['reasoning-end'] !== undefined ? { reasoningEnd: values['reasoning-end'] } : {}),
98
+ ...(contextLength !== undefined ? { contextLength } : {}),
99
+ };
100
+ }
101
+ }
102
+ catch (error) {
103
+ if (error instanceof FoundryHostUsageError)
104
+ throw error;
105
+ throw new FoundryHostUsageError(error instanceof Error ? error.message : String(error));
106
+ }
107
+ throw new FoundryHostUsageError(`foundry-host: unknown mode ${JSON.stringify(mode ?? '')} (probe, prepare, serve)`);
108
+ }
109
+ //# sourceMappingURL=args.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.js","sourceRoot":"","sources":["../../../../src/runtime/foundry-local/host/args.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAA;AAiC/E,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAA;IACrC,CAAC;CACF;AAED,MAAM,cAAc,GAAG;IACrB,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;IACzB,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;IAC9B,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;CAClB,CAAA;AAEV,MAAM,QAAQ,GAAG,CAAC,MAA+B,EAAE,GAAW,EAAU,EAAE;IACxE,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;IACzB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE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YAAE,MAAM,KAAK,CAAA;QACvD,MAAM,IAAI,qBAAqB,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IACzF,CAAC;IACD,MAAM,IAAI,qBAAqB,CAC7B,8BAA8B,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE,CAAC,0BAA0B,CACnF,CAAA;AACH,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The three spellings of each accelerator (spike findings 6 and 14): conf and `model.yml` say `webgpu`,
3
+ * the library's EP registration and `Manager_GetDiscoverableEps` say `WebGpuExecutionProvider` (ONNX
4
+ * Runtime's name), and `RegisterModel` metadata wants `WebGPUExecutionProvider` (the catalog's name) —
5
+ * `Load` refuses the ORT spelling with "unknown execution provider for local model".
6
+ */
7
+ import type { FoundryLocalExecutionProvider } from '../../../contracts/index.js';
8
+ interface ExecutionProviderNames {
9
+ short: FoundryLocalExecutionProvider;
10
+ /** What the variant runs on; OpenVINO serves Intel GPUs and NPUs alike (finding: offered without an NPU). */
11
+ device: 'cpu' | 'gpu' | 'npu' | 'gpu/npu';
12
+ /** `Manager_DownloadAndRegisterEps` / discoverable name; `null` for the CPU, which is always there. */
13
+ register: string | null;
14
+ /** `execution_provider` in `RegisterModel` metadata. */
15
+ metadata: string;
16
+ }
17
+ export declare const EXECUTION_PROVIDERS: readonly ExecutionProviderNames[];
18
+ export declare function executionProvider(short: FoundryLocalExecutionProvider): ExecutionProviderNames;
19
+ /**
20
+ * What the probe says about one discoverable accelerator. One this core does not run variants on
21
+ * (`NvTensorRTRTXExecutionProvider`, design non-goal) keeps its name with `execution_provider: null`.
22
+ */
23
+ export declare function describeDiscoverable(name: string): {
24
+ execution_provider: FoundryLocalExecutionProvider | null;
25
+ device: string;
26
+ };
27
+ export {};
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The three spellings of each accelerator (spike findings 6 and 14): conf and `model.yml` say `webgpu`,
3
+ * the library's EP registration and `Manager_GetDiscoverableEps` say `WebGpuExecutionProvider` (ONNX
4
+ * Runtime's name), and `RegisterModel` metadata wants `WebGPUExecutionProvider` (the catalog's name) —
5
+ * `Load` refuses the ORT spelling with "unknown execution provider for local model".
6
+ */
7
+ export const EXECUTION_PROVIDERS = [
8
+ { short: 'cpu', device: 'cpu', register: null, metadata: 'CPUExecutionProvider' },
9
+ { short: 'cuda', device: 'gpu', register: 'CUDAExecutionProvider', metadata: 'CUDAExecutionProvider' },
10
+ {
11
+ short: 'webgpu',
12
+ device: 'gpu',
13
+ register: 'WebGpuExecutionProvider',
14
+ metadata: 'WebGPUExecutionProvider',
15
+ },
16
+ {
17
+ short: 'openvino',
18
+ device: 'gpu/npu',
19
+ register: 'OpenVINOExecutionProvider',
20
+ metadata: 'OpenVINOExecutionProvider',
21
+ },
22
+ { short: 'qnn', device: 'npu', register: 'QNNExecutionProvider', metadata: 'QNNExecutionProvider' },
23
+ {
24
+ short: 'vitisai',
25
+ device: 'npu',
26
+ register: 'VitisAIExecutionProvider',
27
+ metadata: 'VitisAIExecutionProvider',
28
+ },
29
+ ];
30
+ export function executionProvider(short) {
31
+ return EXECUTION_PROVIDERS.find((ep) => ep.short === short);
32
+ }
33
+ /**
34
+ * What the probe says about one discoverable accelerator. One this core does not run variants on
35
+ * (`NvTensorRTRTXExecutionProvider`, design non-goal) keeps its name with `execution_provider: null`.
36
+ */
37
+ export function describeDiscoverable(name) {
38
+ const known = EXECUTION_PROVIDERS.find((ep) => ep.register === name);
39
+ if (known)
40
+ return { execution_provider: known.short, device: known.device };
41
+ return { execution_provider: null, device: /TensorRT|Cuda|Gpu|DML/i.test(name) ? 'gpu' : 'unknown' };
42
+ }
43
+ //# sourceMappingURL=execution-providers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-providers.js","sourceRoot":"","sources":["../../../../src/runtime/foundry-local/host/execution-providers.ts"],"names":[],"mappings":"AAAA;;;;;GAK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AE,MAAM,EAAE,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,EAAE,CAAA;AACtG,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * `FoundryLibrary` over `bun:ffi` — the only file in `src/` that may import `bun:*` (operator decision
3
+ * Q2 of change `add-foundry-local`; allow-listed in `scripts/check-runtime-agnostic.mjs`). It is
4
+ * imported dynamically by the `foundry-host` mode alone, so the npm package still loads under Node.
5
+ *
6
+ * The library exports three symbols; everything else is a table of function pointers (`flApi` and its
7
+ * sub-APIs), read here by index. Indices follow `foundry_local_c.h` of C API version 2: tables only
8
+ * ever grow at the end, so a library that grants version 2 keeps these positions.
9
+ *
10
+ * Proven by the spike (rulings S1, S2): progress callbacks must not be `threadsafe` — the native caller
11
+ * would wait on a JS thread it itself blocks and read a non-zero return as "cancel"; on Windows the
12
+ * library's DLL dependencies are found only after `SetDllDirectoryW(<lib>)`.
13
+ */
14
+ import type { LoadFoundryLibrary } from './library.js';
15
+ /** The `FOUNDRY_LOCAL_API_VERSION` these bindings are written against. */
16
+ export declare const BOUND_C_API_VERSION = 2;
17
+ export declare const loadBunFoundryLibrary: LoadFoundryLibrary;
@@ -0,0 +1,256 @@
1
+ /**
2
+ * `FoundryLibrary` over `bun:ffi` — the only file in `src/` that may import `bun:*` (operator decision
3
+ * Q2 of change `add-foundry-local`; allow-listed in `scripts/check-runtime-agnostic.mjs`). It is
4
+ * imported dynamically by the `foundry-host` mode alone, so the npm package still loads under Node.
5
+ *
6
+ * The library exports three symbols; everything else is a table of function pointers (`flApi` and its
7
+ * sub-APIs), read here by index. Indices follow `foundry_local_c.h` of C API version 2: tables only
8
+ * ever grow at the end, so a library that grants version 2 keeps these positions.
9
+ *
10
+ * Proven by the spike (rulings S1, S2): progress callbacks must not be `threadsafe` — the native caller
11
+ * would wait on a JS thread it itself blocks and read a non-zero return as "cancel"; on Windows the
12
+ * library's DLL dependencies are found only after `SetDllDirectoryW(<lib>)`.
13
+ */
14
+ import { CFunction, CString, dlopen, FFIType, JSCallback, ptr, read } from 'bun:ffi';
15
+ import { existsSync } from 'node:fs';
16
+ import { join } from 'node:path';
17
+ import { FoundryLibraryError } from './library.js';
18
+ /** The `FOUNDRY_LOCAL_API_VERSION` these bindings are written against. */
19
+ export const BOUND_C_API_VERSION = 2;
20
+ const POINTER = 8;
21
+ const CATALOG_LOCAL = 1;
22
+ /** `flEpInfo`: u32 version, padding, `const char* name` at 8, `bool is_registered` at 16. */
23
+ const EP_INFO_SIZE = 24;
24
+ const LIBRARY_FILE = {
25
+ win32: 'foundry_local.dll',
26
+ darwin: 'libfoundry_local.dylib',
27
+ linux: 'libfoundry_local.so',
28
+ };
29
+ /** Root table (`flApi`) indices. */
30
+ const API = {
31
+ statusGetErrorCode: 2,
32
+ statusGetErrorMessage: 3,
33
+ statusRelease: 1,
34
+ managerCreate: 4,
35
+ managerRelease: 5,
36
+ webServiceStart: 7,
37
+ webServiceUrls: 8,
38
+ getCatalogApi: 10,
39
+ getConfigurationApi: 11,
40
+ getModelApi: 14,
41
+ createKeyValuePairs: 15,
42
+ addKeyValuePair: 16,
43
+ keyValuePairsRelease: 20,
44
+ getDiscoverableEps: 24,
45
+ downloadAndRegisterEps: 25,
46
+ managerShutdown: 27,
47
+ getCatalogByType: 29,
48
+ };
49
+ const CONFIG = {
50
+ create: 0,
51
+ release: 1,
52
+ setAppDataDir: 3,
53
+ setLogsDir: 4,
54
+ setModelCacheDir: 5,
55
+ addWebServiceEndpoint: 8,
56
+ setAdditionalOptions: 10,
57
+ };
58
+ const CATALOG = { registerModel: 8 };
59
+ const MODEL = {
60
+ getInfo: 0,
61
+ load: 6,
62
+ unload: 7,
63
+ infoGetExecutionProvider: 17,
64
+ createModelInfo: 23,
65
+ releaseModelInfo: 24,
66
+ infoSetStringProperty: 25,
67
+ infoSetIntProperty: 26,
68
+ };
69
+ const T = FFIType;
70
+ const cstr = (value) => Buffer.from(`${value}\0`, 'utf8');
71
+ const outPointer = () => new BigUint64Array(1);
72
+ const deref = (out) => Number(out[0]);
73
+ export const loadBunFoundryLibrary = async (libDir) => {
74
+ const file = LIBRARY_FILE[process.platform];
75
+ if (!file)
76
+ throw new FoundryLibraryError('load', 0, `Foundry Local has no library for ${process.platform}`);
77
+ const path = join(libDir, file);
78
+ if (!existsSync(path))
79
+ throw new FoundryLibraryError('load', 0, `${path} not found: no ${file} in this build`);
80
+ if (process.platform === 'win32') {
81
+ // The loader does not search the DLL's own folder for onnxruntime.dll and its siblings (error 126).
82
+ const kernel32 = dlopen('kernel32.dll', { SetDllDirectoryW: { args: [T.ptr], returns: T.i32 } });
83
+ kernel32.symbols.SetDllDirectoryW(ptr(Buffer.from(`${libDir}\0`, 'utf16le')));
84
+ }
85
+ const library = dlopen(path, {
86
+ FoundryLocalGetApi: { args: [T.u32], returns: T.ptr },
87
+ FoundryLocalGetVersionString: { args: [], returns: T.cstring },
88
+ });
89
+ const version = String(library.symbols.FoundryLocalGetVersionString());
90
+ const api = library.symbols.FoundryLocalGetApi(BOUND_C_API_VERSION);
91
+ if (!api)
92
+ throw new FoundryLibraryError('FoundryLocalGetApi', 0, `Foundry Local ${version} does not provide C API version ${BOUND_C_API_VERSION}`);
93
+ return bindLibrary(api, version);
94
+ };
95
+ function bindLibrary(api, version) {
96
+ const fn = (table, index, args, returns) => CFunction({ ptr: read.ptr(table, index * POINTER), args, returns });
97
+ const statusCode = fn(api, API.statusGetErrorCode, [T.ptr], T.i32);
98
+ const statusMessage = fn(api, API.statusGetErrorMessage, [T.ptr], T.cstring);
99
+ const statusRelease = fn(api, API.statusRelease, [T.ptr], T.void);
100
+ /** A non-null `flStatus*` is an error: read it, free it, throw it. */
101
+ const check = (status, operation) => {
102
+ if (!status)
103
+ return;
104
+ const code = Number(statusCode(status));
105
+ const message = String(statusMessage(status));
106
+ statusRelease(status);
107
+ throw new FoundryLibraryError(operation, code, message);
108
+ };
109
+ const call = (f, operation, ...args) => check(f(...args), operation);
110
+ const configApi = fn(api, API.getConfigurationApi, [], T.ptr)();
111
+ const catalogApi = fn(api, API.getCatalogApi, [], T.ptr)();
112
+ const modelApi = fn(api, API.getModelApi, [], T.ptr)();
113
+ const f = {
114
+ configCreate: fn(configApi, CONFIG.create, [T.ptr, T.ptr], T.ptr),
115
+ configRelease: fn(configApi, CONFIG.release, [T.ptr], T.void),
116
+ setAppDataDir: fn(configApi, CONFIG.setAppDataDir, [T.ptr, T.ptr], T.ptr),
117
+ setLogsDir: fn(configApi, CONFIG.setLogsDir, [T.ptr, T.ptr], T.ptr),
118
+ setModelCacheDir: fn(configApi, CONFIG.setModelCacheDir, [T.ptr, T.ptr], T.ptr),
119
+ addWebServiceEndpoint: fn(configApi, CONFIG.addWebServiceEndpoint, [T.ptr, T.ptr], T.ptr),
120
+ setAdditionalOptions: fn(configApi, CONFIG.setAdditionalOptions, [T.ptr, T.ptr], T.ptr),
121
+ kvCreate: fn(api, API.createKeyValuePairs, [T.ptr], T.void),
122
+ kvAdd: fn(api, API.addKeyValuePair, [T.ptr, T.ptr, T.ptr], T.void),
123
+ kvRelease: fn(api, API.keyValuePairsRelease, [T.ptr], T.void),
124
+ managerCreate: fn(api, API.managerCreate, [T.ptr, T.ptr], T.ptr),
125
+ managerRelease: fn(api, API.managerRelease, [T.ptr], T.void),
126
+ managerShutdown: fn(api, API.managerShutdown, [T.ptr], T.ptr),
127
+ getDiscoverableEps: fn(api, API.getDiscoverableEps, [T.ptr, T.ptr, T.ptr], T.ptr),
128
+ downloadAndRegisterEps: fn(api, API.downloadAndRegisterEps, [T.ptr, T.ptr, T.u64, T.ptr, T.ptr], T.ptr),
129
+ getCatalogByType: fn(api, API.getCatalogByType, [T.ptr, T.i32, T.ptr], T.ptr),
130
+ webServiceStart: fn(api, API.webServiceStart, [T.ptr], T.ptr),
131
+ webServiceUrls: fn(api, API.webServiceUrls, [T.ptr, T.ptr, T.ptr], T.ptr),
132
+ registerModel: fn(catalogApi, CATALOG.registerModel, [T.ptr, T.ptr, T.ptr, T.ptr, T.ptr], T.ptr),
133
+ modelGetInfo: fn(modelApi, MODEL.getInfo, [T.ptr, T.ptr], T.ptr),
134
+ modelLoad: fn(modelApi, MODEL.load, [T.ptr], T.ptr),
135
+ modelUnload: fn(modelApi, MODEL.unload, [T.ptr], T.ptr),
136
+ infoGetExecutionProvider: fn(modelApi, MODEL.infoGetExecutionProvider, [T.ptr], T.cstring),
137
+ createModelInfo: fn(modelApi, MODEL.createModelInfo, [T.ptr], T.ptr),
138
+ releaseModelInfo: fn(modelApi, MODEL.releaseModelInfo, [T.ptr], T.void),
139
+ infoSetString: fn(modelApi, MODEL.infoSetStringProperty, [T.ptr, T.ptr, T.ptr], T.ptr),
140
+ infoSetInt: fn(modelApi, MODEL.infoSetIntProperty, [T.ptr, T.ptr, T.i64], T.ptr),
141
+ };
142
+ function createManager(config) {
143
+ const configOut = outPointer();
144
+ call(f.configCreate, 'Configuration_Create', ptr(cstr(config.appName)), ptr(configOut));
145
+ const cfg = deref(configOut);
146
+ let manager;
147
+ try {
148
+ call(f.setAppDataDir, 'SetAppDataDir', cfg, ptr(cstr(config.appDataDir)));
149
+ call(f.setLogsDir, 'SetLogsDir', cfg, ptr(cstr(config.logsDir)));
150
+ call(f.setModelCacheDir, 'SetModelCacheDir', cfg, ptr(cstr(config.modelCacheDir)));
151
+ for (const endpoint of config.webServiceEndpoints)
152
+ call(f.addWebServiceEndpoint, 'AddWebServiceEndpoint', cfg, ptr(cstr(endpoint)));
153
+ const kvOut = outPointer();
154
+ f.kvCreate(ptr(kvOut));
155
+ const kv = deref(kvOut);
156
+ for (const [key, value] of Object.entries(config.additionalOptions))
157
+ f.kvAdd(kv, ptr(cstr(key)), ptr(cstr(value)));
158
+ try {
159
+ call(f.setAdditionalOptions, 'SetAdditionalOptions', cfg, kv);
160
+ }
161
+ finally {
162
+ f.kvRelease(kv);
163
+ }
164
+ const managerOut = outPointer();
165
+ call(f.managerCreate, 'Manager_Create', cfg, ptr(managerOut));
166
+ manager = deref(managerOut);
167
+ }
168
+ finally {
169
+ f.configRelease(cfg);
170
+ }
171
+ return bindManager(manager);
172
+ }
173
+ function bindManager(manager) {
174
+ return {
175
+ discoverableEps() {
176
+ const epsOut = outPointer();
177
+ const countOut = outPointer();
178
+ call(f.getDiscoverableEps, 'Manager_GetDiscoverableEps', manager, ptr(epsOut), ptr(countOut));
179
+ const base = deref(epsOut);
180
+ const eps = [];
181
+ for (let i = 0; i < Number(countOut[0]); i++) {
182
+ const at = i * EP_INFO_SIZE;
183
+ eps.push({
184
+ name: new CString(read.ptr(base, at + 8)).toString(),
185
+ registered: read.u8(base, at + 16) !== 0,
186
+ });
187
+ }
188
+ return eps;
189
+ },
190
+ downloadAndRegisterEps(names, onProgress) {
191
+ const strings = names.map(cstr);
192
+ const array = new BigUint64Array(strings.map((s) => BigInt(ptr(s))));
193
+ // Not threadsafe: the library calls back on the calling thread, synchronously (spike S1, S2).
194
+ const callback = onProgress
195
+ ? new JSCallback((name, percent) => {
196
+ onProgress(new CString(name).toString(), percent);
197
+ return 0;
198
+ }, { args: [T.ptr, T.f32, T.ptr], returns: T.i32 })
199
+ : null;
200
+ try {
201
+ call(f.downloadAndRegisterEps, 'Manager_DownloadAndRegisterEps', manager, names.length > 0 ? ptr(array) : null, names.length, callback ? callback.ptr : null, null);
202
+ }
203
+ finally {
204
+ callback?.close();
205
+ }
206
+ },
207
+ registerLocalModel(path, id, metadata) {
208
+ const catalogOut = outPointer();
209
+ call(f.getCatalogByType, 'Manager_GetCatalogByType', manager, CATALOG_LOCAL, ptr(catalogOut));
210
+ const infoOut = outPointer();
211
+ call(f.createModelInfo, 'CreateModelInfo', ptr(infoOut));
212
+ const info = deref(infoOut);
213
+ const modelOut = outPointer();
214
+ try {
215
+ for (const [key, value] of Object.entries(metadata.strings))
216
+ call(f.infoSetString, `Info_SetStringProperty(${key})`, info, ptr(cstr(key)), ptr(cstr(value)));
217
+ for (const [key, value] of Object.entries(metadata.ints))
218
+ call(f.infoSetInt, `Info_SetIntProperty(${key})`, info, ptr(cstr(key)), BigInt(value));
219
+ call(f.registerModel, 'RegisterModel', deref(catalogOut), ptr(cstr(path)), ptr(cstr(id)), info, ptr(modelOut));
220
+ }
221
+ finally {
222
+ f.releaseModelInfo(info);
223
+ }
224
+ return bindModel(deref(modelOut));
225
+ },
226
+ webServiceStart() {
227
+ call(f.webServiceStart, 'Manager_WebServiceStart', manager);
228
+ const urlsOut = outPointer();
229
+ const countOut = outPointer();
230
+ call(f.webServiceUrls, 'Manager_WebServiceUrls', manager, ptr(urlsOut), ptr(countOut));
231
+ const urls = [];
232
+ for (let i = 0; i < Number(countOut[0]); i++)
233
+ urls.push(new CString(read.ptr(deref(urlsOut), i * POINTER)).toString());
234
+ return urls;
235
+ },
236
+ shutdown: () => call(f.managerShutdown, 'Manager_Shutdown', manager),
237
+ release: () => {
238
+ f.managerRelease(manager);
239
+ },
240
+ };
241
+ }
242
+ function bindModel(model) {
243
+ return {
244
+ load: () => call(f.modelLoad, 'Model_Load', model),
245
+ unload: () => call(f.modelUnload, 'Model_Unload', model),
246
+ executionProvider() {
247
+ const infoOut = outPointer();
248
+ call(f.modelGetInfo, 'Model_GetInfo', model, ptr(infoOut));
249
+ const ep = f.infoGetExecutionProvider(deref(infoOut));
250
+ return ep ? String(ep) : null;
251
+ },
252
+ };
253
+ }
254
+ return { version, cApiVersion: BOUND_C_API_VERSION, createManager };
255
+ }
256
+ //# sourceMappingURL=ffi-bun.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ffi-bun.js","sourceRoot":"","sources":["../../../../src/runtime/foundry-local/host/ffi-bun.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAEpF,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,O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GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;gBAC1E,OAAO,IAAI,CAAA;YACb,CAAC;YACD,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,EAAE,kBAAkB,EAAE,OAAO,CAAC;YACpE,OAAO,EAAE,GAAG,EAAE;gBACZ,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;YAC3B,CAAC;SACF,CAAA;IACH,CAAC;IAED,SAAS,SAAS,CAAC,KAAc;QAC/B,OAAO;YACL,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC;YAClD,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE,cAAc,EAAE,KAAK,CAAC;YACxD,iBAAiB;gBACf,MAAM,OAAO,GAAG,UAAU,EAAE,CAAA;gBAC5B,IAAI,CAAC,CAAC,CAAC,YAAY,EAAE,eAAe,EAAE,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;gBAC1D,MAAM,EAAE,GAAG,CAAC,CAAC,wBAAwB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAA;gBACrD,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;YAC/B,CAAC;SACF,CAAA;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,aAAa,EAAE,CAAA;AACrE,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The part of Foundry Local's C API (`foundry_local_c.h`, `FOUNDRY_LOCAL_API_VERSION` 2) the host
3
+ * uses, as an interface. `ffi-bun.ts` implements it over `bun:ffi`; the protocol tests (tasks 5.2,
4
+ * 5.3) run the host against a fake one. Every call is synchronous and may block, like the C API.
5
+ */
6
+ /** A non-null `flStatus*`: the library's error code and message. */
7
+ export declare class FoundryLibraryError extends Error {
8
+ readonly operation: string;
9
+ readonly libraryCode: number;
10
+ constructor(operation: string, libraryCode: number, message: string);
11
+ }
12
+ export interface FoundryManagerConfig {
13
+ appName: string;
14
+ appDataDir: string;
15
+ logsDir: string;
16
+ modelCacheDir: string;
17
+ /** `http://127.0.0.1:<port>` for `serve`; none otherwise. */
18
+ webServiceEndpoints: string[];
19
+ /** `SetAdditionalOptions`, e.g. `DisableNonessentialTelemetry`. */
20
+ additionalOptions: Record<string, string>;
21
+ }
22
+ export interface DiscoverableEp {
23
+ name: string;
24
+ /** Registered in this process; says nothing about a previous process (spike finding 18). */
25
+ registered: boolean;
26
+ }
27
+ export interface ModelMetadata {
28
+ strings: Record<string, string>;
29
+ ints: Record<string, number>;
30
+ }
31
+ export interface FoundryModel {
32
+ load(): void;
33
+ unload(): void;
34
+ /** The model's execution provider as the library holds it; `null` when unset. */
35
+ executionProvider(): string | null;
36
+ }
37
+ export interface FoundryManager {
38
+ discoverableEps(): DiscoverableEp[];
39
+ /**
40
+ * `Manager_DownloadAndRegisterEps`, blocking. `onProgress` is called on the calling thread for
41
+ * CDN accelerators (spike findings 2, 15). Windows ML ones may call it from a thread of their own
42
+ * on a first install, where the plain callback cannot run: pass it only for CDN accelerators. A
43
+ * per-EP failure is not an error — read `discoverableEps()` afterwards.
44
+ */
45
+ downloadAndRegisterEps(names: string[], onProgress?: (ep: string, percent: number) => void): void;
46
+ /** `RegisterModel` in the local catalog; files are not copied. */
47
+ registerLocalModel(path: string, id: string, metadata: ModelMetadata): FoundryModel;
48
+ /** Start the built-in server; the bound URLs. */
49
+ webServiceStart(): string[];
50
+ shutdown(): void;
51
+ release(): void;
52
+ }
53
+ export interface FoundryLibrary {
54
+ /** `FoundryLocalGetVersionString`. */
55
+ version: string;
56
+ /** The C API version the table was requested at. */
57
+ cApiVersion: number;
58
+ createManager(config: FoundryManagerConfig): FoundryManager;
59
+ }
60
+ /** Opens the library of one build (`<build>/lib`); throws when it does not load or speaks another C API. */
61
+ export type LoadFoundryLibrary = (libDir: string) => Promise<FoundryLibrary>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The part of Foundry Local's C API (`foundry_local_c.h`, `FOUNDRY_LOCAL_API_VERSION` 2) the host
3
+ * uses, as an interface. `ffi-bun.ts` implements it over `bun:ffi`; the protocol tests (tasks 5.2,
4
+ * 5.3) run the host against a fake one. Every call is synchronous and may block, like the C API.
5
+ */
6
+ /** A non-null `flStatus*`: the library's error code and message. */
7
+ export class FoundryLibraryError extends Error {
8
+ operation;
9
+ libraryCode;
10
+ constructor(operation, libraryCode, message) {
11
+ super(`${operation}: ${message}`);
12
+ this.operation = operation;
13
+ this.libraryCode = libraryCode;
14
+ this.name = 'FoundryLibraryError';
15
+ }
16
+ }
17
+ //# sourceMappingURL=library.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"library.js","sourceRoot":"","sources":["../../../../src/runtime/foundry-local/host/library.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,oEAAoE;AACpE,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAEjC;IACA;IAFX,YACW,SAAiB,EACjB,WAAmB,EAC5B,OAAe;QAEf,KAAK,CAAC,GAAG,SAAS,KAAK,OAAO,EAAE,CAAC,CAAA;QAJxB,cAAS,GAAT,SAAS,CAAQ;QACjB,gBAAW,GAAX,WAAW,CAAQ;QAI5B,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The hidden `foundry-host` mode of the core binaries (openspec change `add-foundry-local`, design D1):
3
+ * one process per model or command, so a crash of Microsoft's native library never takes the core
4
+ * down. Core starts it with `process.execPath`; nothing else should.
5
+ *
6
+ * Exit codes: 0 done; 2 usage (a bug on core's side); 3 the library does not load or speaks another
7
+ * C API; 4 a library call failed. Errors go to stderr as one line each; stdout carries JSON lines only.
8
+ */
9
+ import type { LoadFoundryLibrary } from './library.js';
10
+ export interface FoundryHostDeps {
11
+ stdout: (line: string) => void;
12
+ stderr: (line: string) => void;
13
+ loadLibrary: LoadFoundryLibrary;
14
+ /**
15
+ * What the library's log gained since the previous call (the first call: since the host started).
16
+ * The C API reports no per-accelerator failure (spike finding 11); its log does.
17
+ */
18
+ readLogTail?: (logsDir: string) => Promise<string>;
19
+ /**
20
+ * Starts watching for core's stop: SIGTERM, SIGINT or stdin closed (Windows has no SIGTERM). Made
21
+ * before the model loads, so a stop sent right after the readiness line is never missed.
22
+ */
23
+ watchStop?: () => StopWatch;
24
+ /** Deletes the host's catalog cache at exit. */
25
+ removeDir?: (path: string) => Promise<void>;
26
+ }
27
+ export interface StopWatch {
28
+ stopped: Promise<void>;
29
+ /** Let go of the signals and of stdin, so nothing keeps the process alive after the host is done. */
30
+ dispose(): void;
31
+ }
32
+ /** SIGTERM, SIGINT or the end of stdin, whichever comes first. */
33
+ export declare function watchStopSignals(): StopWatch;
34
+ /** Where the built-in server serves models registered in the local catalog (spike finding 7). */
35
+ export declare const LOCAL_CATALOG_BASE_PATH = "/catalogs/local";
36
+ /** Reads what `foundry_local_<date>.log` files under `logsDir` gained since the reader was made. */
37
+ export declare function logTailReader(): (logsDir: string) => Promise<string>;
38
+ /**
39
+ * The library's own words for why `name` was not registered: the last warning or error that names the
40
+ * accelerator or its family (`cuda` for `CUDAExecutionProvider`), not the generic summary line.
41
+ */
42
+ export declare function failureReason(log: string, name: string): string | null;
43
+ /** Line-oriented output over a stream-oriented CLI io: one JSON or error line per call. */
44
+ export declare function lineIo(io: {
45
+ stdout: (text: string) => void;
46
+ stderr: (text: string) => void;
47
+ }): Pick<FoundryHostDeps, 'stdout' | 'stderr'>;
48
+ /** The name the library reports itself under (telemetry, logs). */
49
+ export declare const FOUNDRY_HOST_APP_NAME = "atomic-chat";
50
+ /** `<build>/lib` when the build has one (release archives do), else the folder itself. */
51
+ export declare function libraryDir(build: string, exists?: (path: string) => boolean): string;
52
+ /** Opens the library through `bun:ffi`; under Node this mode cannot run, and says so. */
53
+ export declare const loadLibraryWithBun: LoadFoundryLibrary;
54
+ export declare function runFoundryHost(argv: readonly string[], deps: FoundryHostDeps): Promise<number>;