@fugood/buttress-server 2.25.0-beta.9 → 2.25.1-beta.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.
- package/README.md +506 -35
- package/config/function-samples/README.md +37 -0
- package/config/function-samples/_auth.ts +48 -0
- package/config/function-samples/host-info.ts +25 -0
- package/config/function-samples/summarize-text.ts +55 -0
- package/config/function-samples/text-to-speech.ts +51 -0
- package/config/function-samples/transcribe-media.ts +65 -0
- package/config/sample.toml +25 -0
- package/lib/autodiscover/index.d.ts +20 -0
- package/lib/autodiscover/sign.d.ts +10 -0
- package/lib/autodiscover/types.d.ts +32 -0
- package/lib/autodiscover/udp.d.ts +22 -0
- package/lib/cli.d.ts +3 -0
- package/lib/functions/auth.d.ts +28 -0
- package/lib/functions/config.d.ts +20 -0
- package/lib/functions/constants.d.ts +17 -0
- package/lib/functions/executor.d.ts +27 -0
- package/lib/functions/files.d.ts +29 -0
- package/lib/functions/index.d.ts +50 -0
- package/lib/functions/libs.d.ts +10 -0
- package/lib/functions/loader.d.ts +48 -0
- package/lib/functions/mcp.d.ts +35 -0
- package/lib/functions/registry.d.ts +34 -0
- package/lib/functions/scaffold.d.ts +18 -0
- package/lib/functions/status.d.ts +119 -0
- package/lib/functions/templates.d.ts +14 -0
- package/lib/functions/transpile.d.ts +23 -0
- package/lib/functions/types.d.ts +196 -0
- package/lib/functions/uploads.d.ts +42 -0
- package/lib/functions/watcher.d.ts +34 -0
- package/lib/index.d.ts +36 -0
- package/lib/index.mjs +1539 -64
- package/lib/package.d.ts +7 -0
- package/lib/routes/anthropic-messages.d.ts +55 -0
- package/lib/routes/file.d.ts +10 -0
- package/lib/routes/functions.check.d.ts +13 -0
- package/lib/routes/functions.d.ts +16 -0
- package/lib/routes/generator-cache.d.ts +42 -0
- package/lib/routes/index.d.ts +6 -0
- package/lib/routes/info.check.d.ts +1 -0
- package/lib/routes/info.d.ts +4 -0
- package/lib/routes/llm-shared.d.ts +57 -0
- package/lib/routes/openai-compat.d.ts +17 -0
- package/lib/routes/status.d.ts +4 -0
- package/lib/routes/stt-shared.d.ts +36 -0
- package/lib/routes/tts-shared.d.ts +36 -0
- package/lib/services/common.d.ts +29 -0
- package/lib/services/create-llm-service.d.ts +24 -0
- package/lib/services/create-onnx-init-context.d.ts +10 -0
- package/lib/services/ggml-llm.d.ts +5 -0
- package/lib/services/ggml-stt.d.ts +26 -0
- package/lib/services/index.d.ts +39 -0
- package/lib/services/mlx-llm.d.ts +5 -0
- package/lib/services/onnx-stt.d.ts +77 -0
- package/lib/services/onnx-tts.d.ts +48 -0
- package/lib/types.d.ts +181 -0
- package/lib/utils/SessionFileManager.d.ts +16 -0
- package/lib/utils/buttressAuth.d.ts +25 -0
- package/lib/utils/config.d.ts +21 -0
- package/lib/utils/functionsAuthGuard.d.ts +12 -0
- package/lib/utils/httpAuthGuard.d.ts +1 -0
- package/lib/utils/net.d.ts +6 -0
- package/lib/utils/router.d.ts +2 -0
- package/lib/utils/serialize.d.ts +2 -0
- package/lib/utils/serverCaps.d.ts +4 -0
- package/lib/utils/sessionGuard.d.ts +33 -0
- package/lib/utils/test-caps.d.ts +61 -0
- package/lib/utils/workspaceState.d.ts +21 -0
- package/package.json +21 -8
- package/public/status.html +278 -1
- package/lib/chunk-C8PTHxhX.mjs +0 -2
- package/lib/index.d.mts +0 -370
package/lib/package.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic Messages API endpoints for ggml-llm/mlx-llm (EXPERIMENTAL)
|
|
3
|
+
* Provides /anthropic-messages/v1/messages and /anthropic-messages/v1/messages/count_tokens endpoints
|
|
4
|
+
*
|
|
5
|
+
* Implementation based on llama.cpp PR #17570 and follow-up fixes:
|
|
6
|
+
* - https://github.com/ggml-org/llama.cpp/pull/17570 (initial Anthropic Messages support)
|
|
7
|
+
* - https://github.com/ggml-org/llama.cpp/pull/18551 (signature_delta + persistent block state)
|
|
8
|
+
* - https://github.com/ggml-org/llama.cpp/pull/20120 (preserve thinking blocks in conversion)
|
|
9
|
+
*
|
|
10
|
+
* Enable via TOML config: [anthropic_messages] enabled = true
|
|
11
|
+
*
|
|
12
|
+
* Note: This feature is experimental and may change in future versions.
|
|
13
|
+
*/
|
|
14
|
+
import type { EventStream, Config } from '../types';
|
|
15
|
+
/**
|
|
16
|
+
* Stream an Anthropic Messages SSE response from the backend stream.
|
|
17
|
+
*
|
|
18
|
+
* Anthropic SSE event sequence:
|
|
19
|
+
* message_start
|
|
20
|
+
* [content_block_start (thinking)] if reasoning observed
|
|
21
|
+
* content_block_delta (thinking_delta) ...
|
|
22
|
+
* content_block_delta (signature_delta)
|
|
23
|
+
* content_block_stop
|
|
24
|
+
* [content_block_start (text)] if text observed
|
|
25
|
+
* content_block_delta (text_delta) ...
|
|
26
|
+
* content_block_stop
|
|
27
|
+
* [content_block_start (tool_use)] * for each tool call
|
|
28
|
+
* content_block_delta (input_json_delta) ...
|
|
29
|
+
* content_block_stop
|
|
30
|
+
* message_delta (stop_reason + usage)
|
|
31
|
+
* message_stop
|
|
32
|
+
*/
|
|
33
|
+
export declare function streamAnthropicMessage(completionStream: ReadableStream<EventStream>, messageId: string, modelId: string): AsyncGenerator<{
|
|
34
|
+
readonly event: "content_block_start";
|
|
35
|
+
readonly data: string;
|
|
36
|
+
} | {
|
|
37
|
+
readonly event: "content_block_delta";
|
|
38
|
+
readonly data: string;
|
|
39
|
+
} | {
|
|
40
|
+
readonly event: "message_start";
|
|
41
|
+
readonly data: string;
|
|
42
|
+
} | {
|
|
43
|
+
readonly event: "error";
|
|
44
|
+
readonly data: string;
|
|
45
|
+
} | {
|
|
46
|
+
readonly event: "content_block_stop";
|
|
47
|
+
readonly data: string;
|
|
48
|
+
} | {
|
|
49
|
+
readonly event: "message_delta";
|
|
50
|
+
readonly data: string;
|
|
51
|
+
} | {
|
|
52
|
+
readonly event: "message_stop";
|
|
53
|
+
readonly data: string;
|
|
54
|
+
}, void, unknown>;
|
|
55
|
+
export default function factory({ global: globalConfig }: Config): import("../types").ButtressApp;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const _default: import("elysia").default<any, import("elysia").SingletonBase & {
|
|
2
|
+
store: import("../types").State;
|
|
3
|
+
}, any, any, any, any, {
|
|
4
|
+
derive: any;
|
|
5
|
+
resolve: any;
|
|
6
|
+
schema: any;
|
|
7
|
+
standaloneSchema: any;
|
|
8
|
+
response: {} | {};
|
|
9
|
+
}>;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* End-to-end check for the local function endpoints.
|
|
3
|
+
*
|
|
4
|
+
* Boots a real server on an ephemeral port against a temporary functions
|
|
5
|
+
* directory, then exercises the HTTP list/call/SSE paths and a full MCP
|
|
6
|
+
* initialize → tools/list → tools/call round trip.
|
|
7
|
+
*
|
|
8
|
+
* bun src/routes/functions.check.ts
|
|
9
|
+
*
|
|
10
|
+
* Not a jest test: it needs a real Elysia listener and the native transpiler,
|
|
11
|
+
* neither of which fits the root jest (jsdom + React Native preset) project.
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local function endpoints (EXPERIMENTAL).
|
|
3
|
+
*
|
|
4
|
+
* GET /functions list callable functions
|
|
5
|
+
* POST /functions/:name run one; add ?stream=1 for SSE progress.
|
|
6
|
+
* multipart bodies stage file fields inline and
|
|
7
|
+
* inject their server paths into the input
|
|
8
|
+
* POST /functions/mcp MCP (Streamable HTTP, stateless)
|
|
9
|
+
* GET /functions/files/* download a file a function wrote (context.fileUrl)
|
|
10
|
+
* POST /functions/upload stage an input file for a function call
|
|
11
|
+
*
|
|
12
|
+
* Enable via TOML config: [functions] enabled = true, dir = "./functions"
|
|
13
|
+
*/
|
|
14
|
+
import type { FunctionsService } from '../functions';
|
|
15
|
+
import type { Config } from '../types';
|
|
16
|
+
export default function factory(config: Config, functions: FunctionsService): import("../types").ButtressApp;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Warm-generator cache shared by the sessionless HTTP surfaces (compatibility
|
|
3
|
+
* routes and local functions).
|
|
4
|
+
*
|
|
5
|
+
* Generators are expensive to start (model load + context alloc), so entries
|
|
6
|
+
* are kept warm and reference-counted by in-flight requests: only idle entries
|
|
7
|
+
* (`activeRequests === 0`) are ever evicted, and the map doubles as an LRU
|
|
8
|
+
* because re-inserting on use moves a key to the end.
|
|
9
|
+
*
|
|
10
|
+
* Each caller creates its own cache instance (one per backend family) but the
|
|
11
|
+
* bookkeeping — in-flight de-duplication, retain/release, eviction — lives here.
|
|
12
|
+
*/
|
|
13
|
+
export type GeneratorCacheEntry = {
|
|
14
|
+
id: string;
|
|
15
|
+
type: string;
|
|
16
|
+
config: any;
|
|
17
|
+
repoId: string;
|
|
18
|
+
initialized: boolean;
|
|
19
|
+
activeRequests: number;
|
|
20
|
+
};
|
|
21
|
+
export type ResolvedGeneratorRequest = {
|
|
22
|
+
type: string;
|
|
23
|
+
/** Cache key and model identity for this request. */
|
|
24
|
+
repoId: string;
|
|
25
|
+
mergedConfig: any;
|
|
26
|
+
};
|
|
27
|
+
export type GeneratorCacheOptions = {
|
|
28
|
+
/** Warm entries kept alive; the oldest idle entries are finalized beyond it. */
|
|
29
|
+
max: number;
|
|
30
|
+
/** Pick the configured generator that serves `requestedModel`. */
|
|
31
|
+
resolve: (config: any, requestedModel?: string) => ResolvedGeneratorRequest;
|
|
32
|
+
/** Post-start preparation (typically `initContext`). */
|
|
33
|
+
prepare: (backend: any, entry: GeneratorCacheEntry) => Promise<void>;
|
|
34
|
+
};
|
|
35
|
+
export declare const createGeneratorCache: ({ max, resolve, prepare }: GeneratorCacheOptions) => {
|
|
36
|
+
getOrCreate: (backend: any, config: any, requestedModel: string | undefined, logPrefix: string) => Promise<GeneratorCacheEntry>;
|
|
37
|
+
release: (backend: any, entry: GeneratorCacheEntry | null | undefined, logPrefix: string) => Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
/** Best-effort reader teardown: sources may already be closed or errored. */
|
|
40
|
+
export declare function cancelReaderBestEffort(reader: {
|
|
41
|
+
cancel: () => Promise<unknown>;
|
|
42
|
+
}): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as infoFactory } from './info';
|
|
2
|
+
export { default as file } from './file';
|
|
3
|
+
export { default as status } from './status';
|
|
4
|
+
export { default as openaiCompatFactory } from './openai-compat';
|
|
5
|
+
export { default as anthropicMessagesFactory } from './anthropic-messages';
|
|
6
|
+
export { default as functionsFactory } from './functions';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for LLM-backed sessionless routes (OpenAI / Anthropic
|
|
3
|
+
* compatibility endpoints and local functions).
|
|
4
|
+
*
|
|
5
|
+
* The generator cache is module-scoped so every caller reuses the same warm
|
|
6
|
+
* generator for a given model instead of duplicating contexts.
|
|
7
|
+
*/
|
|
8
|
+
import type { GeneratorCacheEntry } from './generator-cache';
|
|
9
|
+
export type { GeneratorCacheEntry };
|
|
10
|
+
export { cancelReaderBestEffort } from './generator-cache';
|
|
11
|
+
export declare const LLM_TYPES: string[];
|
|
12
|
+
/**
|
|
13
|
+
* Backend options every `messages`-shaped completion needs.
|
|
14
|
+
*
|
|
15
|
+
* Without `jinja` the backend never applies the model's own chat template and
|
|
16
|
+
* the reply degrades into raw-continuation output (`assistant\nassistant\n…`).
|
|
17
|
+
* `reasoning_format` splits a thinking model's `<think>` block out of `content`
|
|
18
|
+
* into `reasoning_content` instead of leaving it inline, and thinking stays off
|
|
19
|
+
* unless the caller asks for it.
|
|
20
|
+
*/
|
|
21
|
+
export declare const CHAT_COMPLETION_DEFAULTS: {
|
|
22
|
+
readonly jinja: true;
|
|
23
|
+
readonly add_generation_prompt: true;
|
|
24
|
+
readonly reasoning_format: 'auto';
|
|
25
|
+
readonly enable_thinking: false;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Get the LLM backend API for a generator type.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getLlmBackend(backend: any, type: string): any;
|
|
31
|
+
export declare function releaseGenerator(backend: any, entry: GeneratorCacheEntry | null | undefined, logPrefix?: string): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Get or create a cached generator for the requested model.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getOrCreateGenerator(backend: any, config: any, requestedModel?: string, logPrefix?: string): Promise<GeneratorCacheEntry>;
|
|
36
|
+
/**
|
|
37
|
+
* Extract token counts from a backend completion result event.
|
|
38
|
+
*
|
|
39
|
+
* The buttress backend reports counts under `timings.prompt_n`,
|
|
40
|
+
* `timings.cache_n`, and `timings.predicted_n` (with `tokens_evaluated`
|
|
41
|
+
* historically mirroring predicted_n on the result root). We tolerate
|
|
42
|
+
* the legacy `prompt_tokens`/`tokens_predicted` field names too in case
|
|
43
|
+
* a future backend variant promotes them to the root.
|
|
44
|
+
*/
|
|
45
|
+
export declare function extractTokenCounts(eventData: Record<string, any>): {
|
|
46
|
+
promptTokens: number;
|
|
47
|
+
cachedTokens: number;
|
|
48
|
+
completionTokens: number;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Extract token usage in OpenAI format from backend event data.
|
|
52
|
+
*/
|
|
53
|
+
export declare function extractUsage(eventData: Record<string, any>): {
|
|
54
|
+
prompt_tokens: number;
|
|
55
|
+
completion_tokens: number;
|
|
56
|
+
total_tokens: number;
|
|
57
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI-compatible API endpoints for ggml-llm (EXPERIMENTAL)
|
|
3
|
+
* Provides /oai-compat/v1/chat/completions and /oai-compat/v1/models endpoints
|
|
4
|
+
*
|
|
5
|
+
* Enable via TOML config: [openai_compat] enabled = true
|
|
6
|
+
*
|
|
7
|
+
* Note: This feature is experimental and may change in future versions.
|
|
8
|
+
*/
|
|
9
|
+
import type { EventStream, Config } from '../types';
|
|
10
|
+
/**
|
|
11
|
+
* Stream an OpenAI-compatible chat completion (SSE) from the backend stream.
|
|
12
|
+
* Mirrors collectChatCompletion (the non-streaming path).
|
|
13
|
+
*/
|
|
14
|
+
export declare function streamChatCompletion(completionStream: ReadableStream<EventStream>, completionId: string, created: number, modelId: string, includeUsage: boolean): AsyncGenerator<{
|
|
15
|
+
readonly data: string;
|
|
16
|
+
}, void, unknown>;
|
|
17
|
+
export default function factory({ global: globalConfig }: Config): import("../types").ButtressApp;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for speech-to-text on the sessionless paths.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors llm-shared: a module-scoped warm-generator cache, reference-counted
|
|
5
|
+
* by in-flight requests. Unlike the LLM path, an unmatched model is an error
|
|
6
|
+
* rather than a repo_id override — STT models are identified by repo *and*
|
|
7
|
+
* filename (several whisper builds live in one repo), so silently substituting
|
|
8
|
+
* one would load the wrong weights.
|
|
9
|
+
*/
|
|
10
|
+
import type { GeneratorCacheEntry } from './generator-cache';
|
|
11
|
+
export declare const STT_TYPES: string[];
|
|
12
|
+
/** Get the STT backend API for a generator type. */
|
|
13
|
+
export declare function getSttBackend(backend: any, type: string): any;
|
|
14
|
+
/** Model identity for an STT generator config: `repo_id` plus `filename`. */
|
|
15
|
+
export declare function sttModelId(generatorConfig: any): string;
|
|
16
|
+
export declare function getOrCreateSttGenerator(backend: any, config: any, requestedModel?: string, logPrefix?: string): Promise<GeneratorCacheEntry>;
|
|
17
|
+
export declare function releaseSttGenerator(backend: any, entry: GeneratorCacheEntry | null | undefined, logPrefix?: string): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Normalize a transcription call result.
|
|
20
|
+
*
|
|
21
|
+
* `ggmlStt.transcribe` resolves a plain object while `onnxStt.transcribe`
|
|
22
|
+
* returns a ReadableStream of progress events — duck-typed here (never
|
|
23
|
+
* `instanceof`, which fails across vm realms) so both shapes collapse to the
|
|
24
|
+
* final result payload.
|
|
25
|
+
*/
|
|
26
|
+
export declare function resolveTranscription(value: any): Promise<any>;
|
|
27
|
+
export type TranscribeRequest = {
|
|
28
|
+
model?: string;
|
|
29
|
+
audioPath?: string;
|
|
30
|
+
audioData?: Uint8Array | Buffer;
|
|
31
|
+
options?: Record<string, any>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Run a transcription against a warm STT generator, releasing it afterwards.
|
|
35
|
+
*/
|
|
36
|
+
export declare function transcribeWith(backend: any, config: any, { model, audioPath, audioData, options }: TranscribeRequest, logPrefix?: string): Promise<any>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for text-to-speech on the sessionless paths.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors stt-shared: a module-scoped warm-generator cache, reference-counted
|
|
5
|
+
* by in-flight requests. Like the STT path, an unmatched model is an error
|
|
6
|
+
* rather than a substitution — synthesizing with the wrong voice is a silent
|
|
7
|
+
* failure the caller cannot detect.
|
|
8
|
+
*/
|
|
9
|
+
import type { GeneratorCacheEntry } from './generator-cache';
|
|
10
|
+
export declare const TTS_TYPES: string[];
|
|
11
|
+
/** Get the TTS backend API for a generator type (only onnx-tts today). */
|
|
12
|
+
export declare function getTtsBackend(backend: any, _type: string): any;
|
|
13
|
+
/** Model identity for a TTS generator config: `repo_id` plus `filename`. */
|
|
14
|
+
export declare function ttsModelId(generatorConfig: any): string;
|
|
15
|
+
export declare function getOrCreateTtsGenerator(backend: any, config: any, requestedModel?: string, logPrefix?: string): Promise<GeneratorCacheEntry>;
|
|
16
|
+
export declare function releaseTtsGenerator(backend: any, entry: GeneratorCacheEntry | null | undefined, logPrefix?: string): Promise<void>;
|
|
17
|
+
export type SynthesizeRequest = {
|
|
18
|
+
model?: string;
|
|
19
|
+
text: string;
|
|
20
|
+
/** Passed to the backend verbatim; `options.speaker` picks a registered voice. */
|
|
21
|
+
options?: Record<string, any>;
|
|
22
|
+
};
|
|
23
|
+
export type SynthesizeBackendResult = {
|
|
24
|
+
cachedId: string;
|
|
25
|
+
/**
|
|
26
|
+
* Path into the TTS output cache. The cache owns this file and may evict it
|
|
27
|
+
* — callers that need the audio beyond the immediate request must copy it.
|
|
28
|
+
*/
|
|
29
|
+
cachedFile: string;
|
|
30
|
+
sampling_rate: number;
|
|
31
|
+
channels: number;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Run a synthesis against a warm TTS generator, releasing it afterwards.
|
|
35
|
+
*/
|
|
36
|
+
export declare function synthesizeWith(backend: any, config: any, { model, text, options }: SynthesizeRequest, logPrefix?: string): Promise<SynthesizeBackendResult>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ServiceContext } from '../types';
|
|
3
|
+
export declare const schemas: {
|
|
4
|
+
getCapabilities: z.ZodTuple<[z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
5
|
+
type: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
6
|
+
config: z.ZodOptional<z.ZodAny>;
|
|
7
|
+
currentClientCapabilities: z.ZodOptional<z.ZodAny>;
|
|
8
|
+
options: z.ZodOptional<z.ZodAny>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
type: string;
|
|
11
|
+
config?: any;
|
|
12
|
+
currentClientCapabilities?: any;
|
|
13
|
+
options?: any;
|
|
14
|
+
}, {
|
|
15
|
+
type?: string | undefined;
|
|
16
|
+
config?: any;
|
|
17
|
+
currentClientCapabilities?: any;
|
|
18
|
+
options?: any;
|
|
19
|
+
}>>>], null>;
|
|
20
|
+
startGenerator: z.ZodTuple<[z.ZodString, z.ZodOptional<z.ZodAny>], null>;
|
|
21
|
+
finalizeGenerator: z.ZodTuple<[z.ZodString], null>;
|
|
22
|
+
};
|
|
23
|
+
export interface Service {
|
|
24
|
+
getCapabilities: (ctx: ServiceContext, ...args: z.infer<typeof schemas.getCapabilities>) => Promise<any>;
|
|
25
|
+
startGenerator: (ctx: ServiceContext, ...args: z.infer<typeof schemas.startGenerator>) => Promise<any>;
|
|
26
|
+
finalizeGenerator: (ctx: ServiceContext, ...args: z.infer<typeof schemas.finalizeGenerator>) => Promise<any>;
|
|
27
|
+
}
|
|
28
|
+
declare const _default: Service;
|
|
29
|
+
export default _default;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ReadableStream } from 'node:stream/web';
|
|
3
|
+
import type { ServiceContext, EventStream, Expand } from '../types';
|
|
4
|
+
export declare const schemas: {
|
|
5
|
+
initContext: z.ZodTuple<[z.ZodString, z.ZodOptional<z.ZodAny>], null>;
|
|
6
|
+
completion: z.ZodTuple<[z.ZodString, z.ZodOptional<z.ZodAny>], null>;
|
|
7
|
+
tokenize: z.ZodTuple<[z.ZodString, z.ZodAny], null>;
|
|
8
|
+
detokenize: z.ZodTuple<[z.ZodString, z.ZodAny], null>;
|
|
9
|
+
applyChatTemplate: z.ZodTuple<[z.ZodString, z.ZodAny], null>;
|
|
10
|
+
releaseContext: z.ZodTuple<[z.ZodString], null>;
|
|
11
|
+
};
|
|
12
|
+
export interface Service {
|
|
13
|
+
initContext: (ctx: ServiceContext, ...args: z.infer<typeof schemas.initContext>) => ReadableStream<Expand<EventStream>>;
|
|
14
|
+
completion: (ctx: ServiceContext, ...args: z.infer<typeof schemas.completion>) => Promise<ReadableStream<Expand<EventStream>>>;
|
|
15
|
+
tokenize: (ctx: ServiceContext, ...args: z.infer<typeof schemas.tokenize>) => Promise<any>;
|
|
16
|
+
detokenize: (ctx: ServiceContext, ...args: z.infer<typeof schemas.detokenize>) => Promise<any>;
|
|
17
|
+
applyChatTemplate: (ctx: ServiceContext, ...args: z.infer<typeof schemas.applyChatTemplate>) => Promise<any>;
|
|
18
|
+
releaseContext: (ctx: ServiceContext, ...args: z.infer<typeof schemas.releaseContext>) => Promise<any>;
|
|
19
|
+
}
|
|
20
|
+
type GetBackend = (backend: any) => any;
|
|
21
|
+
export declare function createInitContext(getBackend: GetBackend): ({ backend, session }: ServiceContext, id: any, property: any) => ReadableStream<EventStream>;
|
|
22
|
+
export declare function createReleaseContext(getBackend: GetBackend, label: string): ({ backend, session }: ServiceContext, id: any, force: any) => Promise<any>;
|
|
23
|
+
export default function createLlmService(getBackend: GetBackend, label: string): Service;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReadableStream } from 'node:stream/web';
|
|
2
|
+
import type { EventStream, ServiceContext } from '../types';
|
|
3
|
+
type InitContextBackend = {
|
|
4
|
+
initContext: (id: string, property: Record<string, unknown> & {
|
|
5
|
+
onProgress: (progress: number) => void;
|
|
6
|
+
}) => Promise<unknown>;
|
|
7
|
+
};
|
|
8
|
+
type GetBackend = (backend: ServiceContext['backend']) => InitContextBackend;
|
|
9
|
+
export default function createOnnxInitContext(getBackend: GetBackend): ({ backend }: ServiceContext, id: string, property: Record<string, unknown> | undefined) => ReadableStream<EventStream>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ServiceContext, EventStream, Expand } from '../types';
|
|
3
|
+
export declare const schemas: {
|
|
4
|
+
initContext: z.ZodTuple<[z.ZodString, z.ZodOptional<z.ZodAny>], null>;
|
|
5
|
+
transcribe: z.ZodTuple<[z.ZodString, z.ZodString, z.ZodOptional<z.ZodAny>], null>;
|
|
6
|
+
transcribeData: z.ZodTuple<[z.ZodString, z.ZodUnion<[z.ZodType<Buffer<ArrayBufferLike>, z.ZodTypeDef, Buffer<ArrayBufferLike>>, z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>]>, z.ZodOptional<z.ZodAny>], null>;
|
|
7
|
+
releaseContext: z.ZodTuple<[z.ZodString], null>;
|
|
8
|
+
};
|
|
9
|
+
export interface Service {
|
|
10
|
+
initContext: (ctx: ServiceContext, ...args: z.infer<typeof schemas.initContext>) => ReadableStream<Expand<EventStream>>;
|
|
11
|
+
transcribe: (ctx: ServiceContext, ...args: z.infer<typeof schemas.transcribe>) => Promise<any>;
|
|
12
|
+
transcribeData: (ctx: ServiceContext, ...args: z.infer<typeof schemas.transcribeData>) => Promise<any>;
|
|
13
|
+
releaseContext: (ctx: ServiceContext, ...args: z.infer<typeof schemas.releaseContext>) => Promise<any>;
|
|
14
|
+
}
|
|
15
|
+
declare const _default: {
|
|
16
|
+
initContext: ({ backend, session }: ServiceContext, id: any, property: any) => import("stream/web").ReadableStream<EventStream>;
|
|
17
|
+
transcribe({ backend, session }: {
|
|
18
|
+
backend: any;
|
|
19
|
+
session: any;
|
|
20
|
+
}, id: any, audioPath: any, options: any): Promise<any>;
|
|
21
|
+
transcribeData({ backend }: {
|
|
22
|
+
backend: any;
|
|
23
|
+
}, id: any, audioData: any, options: any): Promise<any>;
|
|
24
|
+
releaseContext: ({ backend, session }: ServiceContext, id: any, force: any) => Promise<any>;
|
|
25
|
+
};
|
|
26
|
+
export default _default;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ServiceContext } from '../types';
|
|
2
|
+
import type { Service as CommonService } from './common';
|
|
3
|
+
import type { Service as GgmlLlmService } from './ggml-llm';
|
|
4
|
+
import type { Service as GgmlSttService } from './ggml-stt';
|
|
5
|
+
import type { Service as MlxLlmService } from './mlx-llm';
|
|
6
|
+
import type { Service as OnnxSttService } from './onnx-stt';
|
|
7
|
+
import type { Service as OnnxTtsService } from './onnx-tts';
|
|
8
|
+
declare const services: {
|
|
9
|
+
common: CommonService;
|
|
10
|
+
ggmlLlm: GgmlLlmService;
|
|
11
|
+
ggmlStt: {
|
|
12
|
+
initContext: ({ backend, session }: ServiceContext, id: any, property: any) => import("stream/web").ReadableStream<import("../types").EventStream>;
|
|
13
|
+
transcribe({ backend, session }: {
|
|
14
|
+
backend: any;
|
|
15
|
+
session: any;
|
|
16
|
+
}, id: any, audioPath: any, options: any): Promise<any>;
|
|
17
|
+
transcribeData({ backend }: {
|
|
18
|
+
backend: any;
|
|
19
|
+
}, id: any, audioData: any, options: any): Promise<any>;
|
|
20
|
+
releaseContext: ({ backend, session }: ServiceContext, id: any, force: any) => Promise<any>;
|
|
21
|
+
};
|
|
22
|
+
mlxLlm: GgmlLlmService;
|
|
23
|
+
onnxStt: OnnxSttService;
|
|
24
|
+
onnxTts: OnnxTtsService;
|
|
25
|
+
};
|
|
26
|
+
export declare const schemas: Record<string, Record<string, any>>;
|
|
27
|
+
export type StripContext<T> = T extends (ctx: ServiceContext, ...args: infer P) => infer R ? (...args: P) => R : T;
|
|
28
|
+
export type ClientService<S> = {
|
|
29
|
+
[K in keyof S]: StripContext<S[K]>;
|
|
30
|
+
};
|
|
31
|
+
export type Services = {
|
|
32
|
+
common: ClientService<CommonService>;
|
|
33
|
+
ggmlLlm: ClientService<GgmlLlmService>;
|
|
34
|
+
ggmlStt: ClientService<GgmlSttService>;
|
|
35
|
+
mlxLlm: ClientService<MlxLlmService>;
|
|
36
|
+
onnxStt: ClientService<OnnxSttService>;
|
|
37
|
+
onnxTts: ClientService<OnnxTtsService>;
|
|
38
|
+
};
|
|
39
|
+
export default services;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ReadableStream } from 'node:stream/web';
|
|
3
|
+
import type { ServiceContext, EventStream, Expand } from '../types';
|
|
4
|
+
export declare const schemas: {
|
|
5
|
+
initContext: z.ZodTuple<[z.ZodString, z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>], null>;
|
|
6
|
+
transcribe: z.ZodTuple<[z.ZodString, z.ZodObject<{
|
|
7
|
+
audio: z.ZodString;
|
|
8
|
+
options: z.ZodOptional<z.ZodObject<{
|
|
9
|
+
language: z.ZodOptional<z.ZodString>;
|
|
10
|
+
task: z.ZodOptional<z.ZodString>;
|
|
11
|
+
return_timestamps: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"word">]>>;
|
|
12
|
+
chunk_length_s: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
14
|
+
language: z.ZodOptional<z.ZodString>;
|
|
15
|
+
task: z.ZodOptional<z.ZodString>;
|
|
16
|
+
return_timestamps: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"word">]>>;
|
|
17
|
+
chunk_length_s: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
19
|
+
language: z.ZodOptional<z.ZodString>;
|
|
20
|
+
task: z.ZodOptional<z.ZodString>;
|
|
21
|
+
return_timestamps: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"word">]>>;
|
|
22
|
+
chunk_length_s: z.ZodOptional<z.ZodNumber>;
|
|
23
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
audio: string;
|
|
26
|
+
options?: z.objectOutputType<{
|
|
27
|
+
language: z.ZodOptional<z.ZodString>;
|
|
28
|
+
task: z.ZodOptional<z.ZodString>;
|
|
29
|
+
return_timestamps: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"word">]>>;
|
|
30
|
+
chunk_length_s: z.ZodOptional<z.ZodNumber>;
|
|
31
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
32
|
+
}, {
|
|
33
|
+
audio: string;
|
|
34
|
+
options?: z.objectInputType<{
|
|
35
|
+
language: z.ZodOptional<z.ZodString>;
|
|
36
|
+
task: z.ZodOptional<z.ZodString>;
|
|
37
|
+
return_timestamps: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"word">]>>;
|
|
38
|
+
chunk_length_s: z.ZodOptional<z.ZodNumber>;
|
|
39
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
40
|
+
}>], null>;
|
|
41
|
+
transcribeData: z.ZodTuple<[z.ZodString, z.ZodUnion<[z.ZodType<Buffer<ArrayBufferLike>, z.ZodTypeDef, Buffer<ArrayBufferLike>>, z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>]>, z.ZodOptional<z.ZodObject<{
|
|
42
|
+
language: z.ZodOptional<z.ZodString>;
|
|
43
|
+
task: z.ZodOptional<z.ZodString>;
|
|
44
|
+
return_timestamps: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"word">]>>;
|
|
45
|
+
chunk_length_s: z.ZodOptional<z.ZodNumber>;
|
|
46
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
47
|
+
language: z.ZodOptional<z.ZodString>;
|
|
48
|
+
task: z.ZodOptional<z.ZodString>;
|
|
49
|
+
return_timestamps: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"word">]>>;
|
|
50
|
+
chunk_length_s: z.ZodOptional<z.ZodNumber>;
|
|
51
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
52
|
+
language: z.ZodOptional<z.ZodString>;
|
|
53
|
+
task: z.ZodOptional<z.ZodString>;
|
|
54
|
+
return_timestamps: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodLiteral<"word">]>>;
|
|
55
|
+
chunk_length_s: z.ZodOptional<z.ZodNumber>;
|
|
56
|
+
}, z.ZodTypeAny, "passthrough">>>], null>;
|
|
57
|
+
releaseContext: z.ZodTuple<[z.ZodString], null>;
|
|
58
|
+
};
|
|
59
|
+
export interface TranscribeResult {
|
|
60
|
+
text: string;
|
|
61
|
+
chunks?: {
|
|
62
|
+
text: string;
|
|
63
|
+
timestamp?: [number, number | null];
|
|
64
|
+
}[];
|
|
65
|
+
segments?: unknown[];
|
|
66
|
+
}
|
|
67
|
+
export interface Service {
|
|
68
|
+
initContext: (ctx: ServiceContext, ...args: z.infer<typeof schemas.initContext>) => ReadableStream<Expand<EventStream>>;
|
|
69
|
+
transcribe: (ctx: ServiceContext, ...args: z.infer<typeof schemas.transcribe>) => ReadableStream<Expand<EventStream>>;
|
|
70
|
+
transcribeData: (ctx: ServiceContext, ...args: z.infer<typeof schemas.transcribeData>) => Promise<TranscribeResult>;
|
|
71
|
+
releaseContext: (ctx: ServiceContext, ...args: z.infer<typeof schemas.releaseContext>) => Promise<{
|
|
72
|
+
released: boolean;
|
|
73
|
+
alreadyReleased?: boolean;
|
|
74
|
+
}>;
|
|
75
|
+
}
|
|
76
|
+
declare const _default: Service;
|
|
77
|
+
export default _default;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ReadableStream } from 'node:stream/web';
|
|
3
|
+
import type { ServiceContext, EventStream, Expand } from '../types';
|
|
4
|
+
export declare const schemas: {
|
|
5
|
+
initContext: z.ZodTuple<[z.ZodString, z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>], null>;
|
|
6
|
+
addSpeaker: z.ZodTuple<[z.ZodString, z.ZodUnion<[z.ZodType<Float32Array<ArrayBuffer>, z.ZodTypeDef, Float32Array<ArrayBuffer>>, z.ZodRecord<z.ZodString, z.ZodUnknown>]>], null>;
|
|
7
|
+
synthesize: z.ZodTuple<[z.ZodString, z.ZodObject<{
|
|
8
|
+
text: z.ZodString;
|
|
9
|
+
options: z.ZodOptional<z.ZodObject<{
|
|
10
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
11
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
12
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
14
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
15
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
text: string;
|
|
18
|
+
options?: z.objectOutputType<{
|
|
19
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
20
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
21
|
+
}, {
|
|
22
|
+
text: string;
|
|
23
|
+
options?: z.objectInputType<{
|
|
24
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
25
|
+
}, z.ZodTypeAny, "passthrough"> | undefined;
|
|
26
|
+
}>], null>;
|
|
27
|
+
releaseContext: z.ZodTuple<[z.ZodString], null>;
|
|
28
|
+
};
|
|
29
|
+
export interface AddSpeakerResult {
|
|
30
|
+
speakerId: string;
|
|
31
|
+
type: 'embed' | 'config';
|
|
32
|
+
}
|
|
33
|
+
export interface SynthesizeResult {
|
|
34
|
+
filename: string;
|
|
35
|
+
sampling_rate: number;
|
|
36
|
+
channels: number;
|
|
37
|
+
}
|
|
38
|
+
export interface Service {
|
|
39
|
+
initContext: (ctx: ServiceContext, ...args: z.infer<typeof schemas.initContext>) => ReadableStream<Expand<EventStream>>;
|
|
40
|
+
addSpeaker: (ctx: ServiceContext, ...args: z.infer<typeof schemas.addSpeaker>) => Promise<AddSpeakerResult>;
|
|
41
|
+
synthesize: (ctx: ServiceContext, ...args: z.infer<typeof schemas.synthesize>) => Promise<SynthesizeResult>;
|
|
42
|
+
releaseContext: (ctx: ServiceContext, ...args: z.infer<typeof schemas.releaseContext>) => Promise<{
|
|
43
|
+
released: boolean;
|
|
44
|
+
alreadyReleased?: boolean;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
declare const _default: Service;
|
|
48
|
+
export default _default;
|