@fugood/buttress-server 2.25.0-beta.9 → 2.25.0

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 (42) hide show
  1. package/README.md +338 -19
  2. package/config/sample.toml +9 -0
  3. package/lib/autodiscover/index.d.ts +20 -0
  4. package/lib/autodiscover/sign.d.ts +10 -0
  5. package/lib/autodiscover/types.d.ts +32 -0
  6. package/lib/autodiscover/udp.d.ts +22 -0
  7. package/lib/cli.d.ts +3 -0
  8. package/lib/index.d.ts +29 -0
  9. package/lib/index.mjs +1282 -63
  10. package/lib/package.d.ts +7 -0
  11. package/lib/routes/anthropic-messages.d.ts +55 -0
  12. package/lib/routes/file.d.ts +10 -0
  13. package/lib/routes/index.d.ts +5 -0
  14. package/lib/routes/info.check.d.ts +1 -0
  15. package/lib/routes/info.d.ts +4 -0
  16. package/lib/routes/llm-shared.d.ts +54 -0
  17. package/lib/routes/openai-compat.d.ts +17 -0
  18. package/lib/routes/status.d.ts +4 -0
  19. package/lib/services/common.d.ts +29 -0
  20. package/lib/services/create-llm-service.d.ts +24 -0
  21. package/lib/services/ggml-llm.d.ts +5 -0
  22. package/lib/services/ggml-stt.d.ts +26 -0
  23. package/lib/services/index.d.ts +39 -0
  24. package/lib/services/mlx-llm.d.ts +5 -0
  25. package/lib/services/onnx-stt.d.ts +77 -0
  26. package/lib/services/onnx-tts.d.ts +48 -0
  27. package/lib/types.d.ts +158 -0
  28. package/lib/utils/SessionFileManager.d.ts +16 -0
  29. package/lib/utils/buttressAuth.d.ts +25 -0
  30. package/lib/utils/config.d.ts +21 -0
  31. package/lib/utils/httpAuthGuard.d.ts +1 -0
  32. package/lib/utils/net.d.ts +6 -0
  33. package/lib/utils/router.d.ts +2 -0
  34. package/lib/utils/serialize.d.ts +2 -0
  35. package/lib/utils/serverCaps.d.ts +4 -0
  36. package/lib/utils/sessionGuard.d.ts +33 -0
  37. package/lib/utils/test-caps.d.ts +61 -0
  38. package/lib/utils/workspaceState.d.ts +21 -0
  39. package/package.json +10 -8
  40. package/public/status.html +162 -1
  41. package/lib/chunk-C8PTHxhX.mjs +0 -2
  42. package/lib/index.d.mts +0 -370
package/lib/index.d.mts DELETED
@@ -1,370 +0,0 @@
1
-
2
- import { AnyElysia, Elysia } from "elysia";
3
- import { ReadableStream } from "node:stream/web";
4
- import { EventEmitter } from "node:events";
5
-
6
- //#region ../buttress-backend-core/lib/types/caps.d.ts
7
- declare function getCapabilities(type: any, currentClientCapabilities?: any, options?: {}): Promise<any>;
8
- //#endregion
9
- //#region ../buttress-backend-core/lib/types/status.d.ts
10
- /**
11
- * StatusTracker - Manages history with fixed limit using circular buffer pattern
12
- */
13
- declare class StatusTracker {
14
- constructor(maxEntries?: number);
15
- maxEntries: number;
16
- modelLoads: any[];
17
- completions: any[];
18
- transcriptions: any[];
19
- addModelLoad(entry: any): void;
20
- addCompletion(entry: any): void;
21
- addTranscription(entry: any): void;
22
- getModelLoadHistory(): any[];
23
- getCompletionHistory(): any[];
24
- getTranscriptionHistory(): any[];
25
- clear(): void;
26
- }
27
- declare const llmStatusTracker: StatusTracker;
28
- declare const sttStatusTracker: StatusTracker;
29
- declare const statusEmitter: EventEmitter<[never]>;
30
- /**
31
- * Subscribe to all status changes
32
- * @param {Function} callback - Called with { type, entry } on each change
33
- * @returns {Function} Unsubscribe function
34
- */
35
- declare function subscribeToStatus(callback: Function): Function;
36
- /**
37
- * Subscribe with ID for management
38
- * @param {Function} callback
39
- * @returns {{ subscriberId: number, unsubscribe: Function }}
40
- */
41
- declare function subscribeToStatusWithId(callback: Function): {
42
- subscriberId: number;
43
- unsubscribe: Function;
44
- };
45
- //#endregion
46
- //#region ../buttress-backend-core/lib/types/test-caps.d.ts
47
- /**
48
- * Display model capabilities in a Markdown table format
49
- * @param {Object} options - Display options
50
- * @param {Array<string>} options.modelIds - Array of model repository IDs
51
- * @param {Object|null} options.defaultConfig - Default configuration from TOML
52
- * @returns {Promise<void>}
53
- */
54
- declare function showModelsTable({
55
- modelIds,
56
- defaultConfig
57
- }?: {
58
- modelIds: Array<string>;
59
- defaultConfig: any | null;
60
- }): Promise<void>;
61
- /**
62
- * Test ggml-llm capabilities for a backend type with optional model configuration
63
- * @param {Object} options - Test options
64
- * @param {string|null} options.modelId - Model repository ID
65
- * @param {Object|null} options.defaultConfig - Default configuration from TOML
66
- * @returns {Promise<void>}
67
- */
68
- declare function testGgmlLlmCapabilities({
69
- modelId,
70
- defaultConfig
71
- }?: {
72
- modelId: string | null;
73
- defaultConfig: any | null;
74
- }): Promise<void>;
75
- /**
76
- * Display STT model capabilities in a Markdown table format
77
- * @param {Object} options - Display options
78
- * @param {Array<string>} options.modelIds - Array of model IDs (format: repo_id:filename)
79
- * @param {Object|null} options.defaultConfig - Default configuration from TOML
80
- * @returns {Promise<void>}
81
- */
82
- declare function showSttModelsTable({
83
- modelIds,
84
- defaultConfig
85
- }?: {
86
- modelIds: Array<string>;
87
- defaultConfig: any | null;
88
- }): Promise<void>;
89
- /**
90
- * Test ggml-stt capabilities for a backend type with optional model configuration
91
- * @param {Object} options - Test options
92
- * @param {string|null} options.modelId - Model ID (format: repo_id:filename)
93
- * @param {Object|null} options.defaultConfig - Default configuration from TOML
94
- * @returns {Promise<void>}
95
- */
96
- declare function testGgmlSttCapabilities({
97
- modelId,
98
- defaultConfig
99
- }?: {
100
- modelId: string | null;
101
- defaultConfig: any | null;
102
- }): Promise<void>;
103
- declare namespace index_d_exports {
104
- export { finalizeGenerator, generatorRegistry, getCapabilities, getModelIdentifier, ggmlLlm, ggmlStt, globalDownloadManager, mlxLlm, showModelsTable, showSttModelsTable, startGenerator, startModelDownload, status, testGgmlLlmCapabilities, testGgmlSttCapabilities };
105
- }
106
- declare function startGenerator(type: any, config: any): Promise<{
107
- id: any;
108
- info: any;
109
- }>;
110
- declare function finalizeGenerator(id: any): Promise<boolean>;
111
- declare function getModelIdentifier(type: any, config: any): any;
112
- declare namespace ggmlLlm {
113
- function initContext(id: any, property: any): Promise<any>;
114
- function completion(id: any, property: any): Promise<any>;
115
- function tokenize(id: any, property: any): Promise<any>;
116
- function detokenize(id: any, property: any): Promise<any>;
117
- function applyChatTemplate(id: any, property: any): Promise<any>;
118
- function releaseContext(id: any, property: any): Promise<any>;
119
- }
120
- declare namespace ggmlStt {
121
- function initContext(id: any, property: any): Promise<any>;
122
- function transcribe(id: any, property: any): Promise<any>;
123
- function transcribeData(id: any, property: any): Promise<any>;
124
- function releaseContext(id: any, property: any): Promise<any>;
125
- }
126
- declare namespace mlxLlm {
127
- function initContext(id: any, property: any): Promise<any>;
128
- function completion(id: any, property: any): Promise<any>;
129
- function tokenize(id: any, property: any): Promise<any>;
130
- function detokenize(id: any, property: any): Promise<any>;
131
- function applyChatTemplate(id: any, property: any): Promise<any>;
132
- function releaseContext(id: any, property: any): Promise<any>;
133
- }
134
- declare namespace status {
135
- export function getFullStatus(): any;
136
- export function getGgmlLlmStatus(): any;
137
- export function getGgmlSttStatus(): any;
138
- export function getMlxLlmStatus(): any;
139
- export { subscribeToStatus };
140
- export { subscribeToStatusWithId };
141
- export { llmStatusTracker };
142
- export { sttStatusTracker };
143
- export { statusEmitter };
144
- }
145
- declare const generatorRegistry: Map<any, any>;
146
- declare namespace globalDownloadManager {
147
- let downloads: Map<any, any>;
148
- /**
149
- * Get an existing download promise for a model path
150
- * @param {string} localPath - The local path for the model
151
- * @returns {Promise<void>|null} - The download promise or null if not downloading
152
- */
153
- function getDownload(localPath: string): Promise<void> | null;
154
- /**
155
- * Register a download promise for a model path
156
- * @param {string} localPath - The local path for the model
157
- * @param {Promise<void>} downloadPromise - The download promise
158
- */
159
- function setDownload(localPath: string, downloadPromise: Promise<void>): void;
160
- /**
161
- * Remove a download from tracking
162
- * @param {string} localPath - The local path for the model
163
- */
164
- function deleteDownload(localPath: string): void;
165
- /**
166
- * Check if a model is currently being downloaded
167
- * @param {string} localPath - The local path for the model
168
- * @returns {boolean}
169
- */
170
- function isDownloading(localPath: string): boolean;
171
- /**
172
- * Get all active downloads
173
- * @returns {Array<{localPath: string, promise: Promise<void>}>}
174
- */
175
- function getActiveDownloads(): Array<{
176
- localPath: string;
177
- promise: Promise<void>;
178
- }>;
179
- }
180
- /**
181
- * Start downloading a model if download=true in config.
182
- * This function starts the download in the background and returns immediately.
183
- * The download will be tracked by the global download manager so that
184
- * initContext can wait for it if needed.
185
- *
186
- * @param {string} type - The generator type ('ggml-llm' or 'ggml-stt')
187
- * @param {Object} config - The generator configuration
188
- * @param {Object} options - Options for the download
189
- * @param {function} options.onProgress - Progress callback (0-1)
190
- * @param {function} options.onComplete - Called when download completes
191
- * @param {function} options.onError - Called on error
192
- * @returns {Promise<{started: boolean, localPath: string|null, repoId: string|null}>}
193
- */
194
- declare function startModelDownload(type: string, config: any, options?: {
195
- onProgress: Function;
196
- onComplete: Function;
197
- onError: Function;
198
- }): Promise<{
199
- started: boolean;
200
- localPath: string | null;
201
- repoId: string | null;
202
- }>;
203
- //#endregion
204
- //#region src/types.d.ts
205
- type HumanReadableUnit = number | string;
206
- type HumanReadableServerConfig = {
207
- id?: string;
208
- name?: string;
209
- port?: number;
210
- log_level?: 'debug' | 'info' | 'warn' | 'error';
211
- max_body_size?: HumanReadableUnit;
212
- session_timeout?: HumanReadableUnit;
213
- temp_file_dir?: string;
214
- };
215
- type SessionCacheConfig = {
216
- enabled?: boolean;
217
- max_size_bytes?: HumanReadableUnit;
218
- max_entries?: number;
219
- };
220
- type RuntimeConfig = {
221
- cache_dir?: string;
222
- huggingface_token?: string;
223
- session_cache?: SessionCacheConfig;
224
- } & Record<string, any>;
225
- type GeneratorType = 'ggml-llm' | 'ggml-stt' | 'mlx-llm';
226
- type GeneratorConfig = {
227
- type: GeneratorType;
228
- } & Record<string, any>;
229
- type GlobalConfig = {
230
- runtime?: RuntimeConfig;
231
- openai_compat?: {
232
- enabled?: boolean;
233
- cors_allowed_origins?: string | string[];
234
- };
235
- anthropic_messages?: {
236
- enabled?: boolean;
237
- cors_allowed_origins?: string | string[];
238
- };
239
- } & Record<string, any>;
240
- type AutodiscoverConfig = {
241
- udp: {
242
- port?: number;
243
- announcements: {
244
- enabled: boolean;
245
- interval?: number;
246
- };
247
- requests: {
248
- enabled: boolean;
249
- responseDelay?: number;
250
- };
251
- };
252
- http: {
253
- enabled: boolean;
254
- path?: string;
255
- cors?: boolean;
256
- };
257
- mdns?: {
258
- enabled: boolean;
259
- };
260
- };
261
- type HumanReadableConfig = {
262
- autodiscover?: AutodiscoverConfig | boolean;
263
- server?: HumanReadableServerConfig;
264
- generators?: GeneratorConfig[];
265
- } & GlobalConfig;
266
- type ServerConfig = {
267
- id: string;
268
- name: string;
269
- port: number;
270
- log_level?: 'debug' | 'info' | 'warn' | 'error';
271
- max_body_size: number;
272
- session_timeout: number;
273
- temp_file_dir: string;
274
- };
275
- type Config = {
276
- autodiscover: AutodiscoverConfig | null;
277
- server: ServerConfig;
278
- global: GlobalConfig;
279
- generators: GeneratorConfig[];
280
- };
281
- type GeneratorInfo = {
282
- type: GeneratorType; /** Performance score 0–100 from buttress-hardware-guardrails. */
283
- score?: number; /** Whether the host has an accelerator (GPU/Metal/etc) for this backend. */
284
- hasGpu?: boolean; /** Usable memory in bytes for this backend (GPU when present, else CPU). */
285
- usableBytes?: number;
286
- } & Record<string, any>;
287
- type ServerInfo = {
288
- id: string;
289
- name: string;
290
- version: string;
291
- address: string;
292
- port: number;
293
- url: string;
294
- generators: GeneratorInfo[];
295
- authentication: {
296
- required: boolean;
297
- type: string; /** Issuer key id (when type === 'workspace-jwt'). */
298
- kid?: string; /** True when buttress is paired with a workspace. */
299
- bound?: boolean;
300
- }; /** Workspace identity (only present when paired). */
301
- workspace?: {
302
- id: string;
303
- name?: string;
304
- };
305
- };
306
- //#endregion
307
- //#region src/autodiscover/types.d.ts
308
- type GetServerInfoFn = () => ServerInfo;
309
- //#endregion
310
- //#region src/autodiscover/index.d.ts
311
- /**
312
- * Autodiscover service that manages discovery transports.
313
- * Currently supports UDP announcements/responses.
314
- * HTTP discovery is handled by the info route.
315
- */
316
- declare class AutodiscoverService {
317
- private config;
318
- private getServerInfo;
319
- private transports;
320
- private started;
321
- constructor(config: AutodiscoverConfig, getServerInfo: GetServerInfoFn);
322
- start(): Promise<void>;
323
- stop(): Promise<void>;
324
- }
325
- //#endregion
326
- //#region src/utils/config.d.ts
327
- /**
328
- * Process raw user config (HumanReadableConfig) into Config.
329
- * Handles: device defaults, value normalization (bytes/ms), structure splitting.
330
- */
331
- declare const processConfig: (input: HumanReadableConfig | null) => Config;
332
- //#endregion
333
- //#region src/index.d.ts
334
- declare const checkForUpdates: () => Promise<string | null>;
335
- declare const compareVersions: (current: string, latest: string) => boolean;
336
- declare const logUpdateMessage: (latestVersion: string) => void;
337
- declare const checkAndNotifyUpdates: () => Promise<void>;
338
- type Backend = typeof index_d_exports;
339
- interface StartServerOptions {
340
- backend?: Backend;
341
- router?: AnyElysia;
342
- config: Config;
343
- enableOpenAICompat?: boolean;
344
- enableAnthropicMessages?: boolean;
345
- }
346
- declare const createServer: ({
347
- backend,
348
- router,
349
- config,
350
- enableOpenAICompat,
351
- enableAnthropicMessages
352
- }: StartServerOptions) => Promise<{
353
- app: AnyElysia;
354
- config: Config;
355
- }>;
356
- declare const startServer: ({
357
- backend,
358
- router,
359
- config,
360
- enableOpenAICompat,
361
- enableAnthropicMessages
362
- }: StartServerOptions) => Promise<{
363
- app: AnyElysia;
364
- port: number;
365
- openaiEnabled: boolean;
366
- anthropicMessagesEnabled: boolean;
367
- autoDiscover: AutodiscoverService | null;
368
- }>;
369
- //#endregion
370
- export { Backend, StartServerOptions, checkAndNotifyUpdates, checkForUpdates, compareVersions, createServer, logUpdateMessage, processConfig, startModelDownload, startServer };