@qvac/sdk 0.4.1 → 0.5.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 (179) hide show
  1. package/README.md +328 -200
  2. package/dist/client/api/completion-stream.d.ts +15 -5
  3. package/dist/client/api/completion-stream.js +50 -14
  4. package/dist/client/api/embed.d.ts +17 -3
  5. package/dist/client/api/embed.js +0 -8
  6. package/dist/client/api/get-model-info.d.ts +1 -1
  7. package/dist/client/api/index.d.ts +0 -1
  8. package/dist/client/api/index.js +0 -1
  9. package/dist/client/api/load-model.d.ts +37 -11
  10. package/dist/client/api/load-model.js +29 -117
  11. package/dist/client/api/logging-stream.d.ts +6 -3
  12. package/dist/client/api/logging-stream.js +6 -3
  13. package/dist/client/api/unload-model.js +5 -2
  14. package/dist/client/config-loader/config-utils.d.ts +5 -0
  15. package/dist/client/config-loader/config-utils.js +20 -0
  16. package/dist/client/config-loader/resolve-config.bare.d.ts +9 -0
  17. package/dist/client/config-loader/resolve-config.bare.js +87 -0
  18. package/dist/client/config-loader/resolve-config.expo.d.ts +11 -0
  19. package/dist/client/config-loader/resolve-config.expo.js +62 -0
  20. package/dist/client/config-loader/resolve-config.node.d.ts +9 -0
  21. package/dist/client/config-loader/resolve-config.node.js +118 -0
  22. package/dist/client/init-hooks.d.ts +17 -3
  23. package/dist/client/init-hooks.js +37 -18
  24. package/dist/client/logging-stream-registry.d.ts +1 -1
  25. package/dist/client/logging-stream-registry.js +14 -13
  26. package/dist/client/rpc/bare-client.d.ts +10 -14
  27. package/dist/client/rpc/bare-client.js +28 -2
  28. package/dist/client/rpc/bare-rpc-client.d.ts +1 -1
  29. package/dist/client/rpc/bare-rpc-client.js +16 -13
  30. package/dist/client/rpc/expo-rpc-client.d.ts +2 -2
  31. package/dist/client/rpc/expo-rpc-client.js +15 -12
  32. package/dist/client/rpc/node-rpc-client.d.ts +1 -1
  33. package/dist/client/rpc/node-rpc-client.js +10 -7
  34. package/dist/client/rpc/rpc-client.js +16 -15
  35. package/dist/examples/config/config-path.d.ts +8 -0
  36. package/dist/examples/config/config-path.js +13 -0
  37. package/dist/examples/config-reload.d.ts +2 -0
  38. package/dist/examples/config-reload.js +49 -0
  39. package/dist/examples/download-with-blind-relays.js +20 -20
  40. package/dist/examples/embed-hyperdrive.js +35 -3
  41. package/dist/examples/kv-cache-cleanup.js +1 -1
  42. package/dist/examples/kv-cache-custom-key.js +1 -1
  43. package/dist/examples/kv-cache-example.js +1 -1
  44. package/dist/examples/llamacpp-hyperdrive.js +1 -1
  45. package/dist/examples/llamacpp-sharded.js +1 -1
  46. package/dist/examples/logging-file-transport.d.ts +2 -0
  47. package/dist/examples/{llamacpp-file-logging.js → logging-file-transport.js} +3 -7
  48. package/dist/examples/logging-streaming.d.ts +2 -0
  49. package/dist/examples/logging-streaming.js +75 -0
  50. package/dist/examples/mcp-websearch.d.ts +13 -0
  51. package/dist/examples/mcp-websearch.js +176 -0
  52. package/dist/index.d.ts +4 -4
  53. package/dist/index.js +2 -2
  54. package/dist/logging/addon.d.ts +6 -0
  55. package/dist/logging/addon.js +59 -0
  56. package/dist/logging/base-logger.js +24 -14
  57. package/dist/logging/client-logger.d.ts +3 -0
  58. package/dist/logging/client-logger.js +13 -0
  59. package/dist/logging/index.d.ts +6 -1
  60. package/dist/logging/index.js +6 -1
  61. package/dist/logging/logger.d.ts +0 -2
  62. package/dist/logging/logger.js +0 -3
  63. package/dist/logging/namespaces.d.ts +11 -0
  64. package/dist/logging/namespaces.js +11 -0
  65. package/dist/logging/registry.d.ts +26 -0
  66. package/dist/logging/registry.js +36 -0
  67. package/dist/logging/server-logger.d.ts +3 -0
  68. package/dist/logging/server-logger.js +16 -0
  69. package/dist/logging/stream-logger.d.ts +1 -1
  70. package/dist/logging/stream-logger.js +6 -3
  71. package/dist/logging/types.d.ts +2 -0
  72. package/dist/models/hyperdrive/models.d.ts +789 -51
  73. package/dist/models/hyperdrive/models.js +979 -200
  74. package/dist/schemas/common.d.ts +86 -23
  75. package/dist/schemas/common.js +0 -3
  76. package/dist/schemas/download-asset.d.ts +5 -5
  77. package/dist/schemas/embed.d.ts +3 -3
  78. package/dist/schemas/embed.js +9 -2
  79. package/dist/schemas/get-model-info.d.ts +2 -2
  80. package/dist/schemas/index.d.ts +5 -1
  81. package/dist/schemas/index.js +5 -1
  82. package/dist/schemas/json-schema.d.ts +16 -0
  83. package/dist/schemas/json-schema.js +2 -0
  84. package/dist/schemas/llamacpp-config.d.ts +5 -4
  85. package/dist/schemas/llamacpp-config.js +7 -5
  86. package/dist/schemas/load-model.d.ts +931 -211
  87. package/dist/schemas/load-model.js +7 -1
  88. package/dist/schemas/logging-stream.d.ts +10 -3
  89. package/dist/schemas/logging-stream.js +4 -3
  90. package/dist/schemas/mcp-adapter.d.ts +47 -0
  91. package/dist/schemas/mcp-adapter.js +1 -0
  92. package/dist/schemas/model-src-utils.d.ts +8 -6
  93. package/dist/schemas/model-src-utils.js +8 -3
  94. package/dist/schemas/reload-config.d.ts +344 -0
  95. package/dist/schemas/reload-config.js +42 -0
  96. package/dist/schemas/sdk-config.d.ts +22 -0
  97. package/dist/schemas/sdk-config.js +33 -0
  98. package/dist/schemas/sdk-errors-client.d.ts +4 -0
  99. package/dist/schemas/sdk-errors-client.js +20 -0
  100. package/dist/schemas/sdk-errors-server.d.ts +3 -0
  101. package/dist/schemas/sdk-errors-server.js +15 -0
  102. package/dist/schemas/tools.d.ts +3 -0
  103. package/dist/schemas/translation-config.d.ts +81 -0
  104. package/dist/schemas/translation-config.js +3 -4
  105. package/dist/schemas/whispercpp-config.d.ts +9 -1
  106. package/dist/schemas/whispercpp-config.js +2 -1
  107. package/dist/server/bare/addons/llamacpp/create-model.js +13 -4
  108. package/dist/server/bare/addons/llamacpp/handlers/embed.d.ts +9 -1
  109. package/dist/server/bare/addons/llamacpp/handlers/embed.js +18 -4
  110. package/dist/server/bare/addons/llamacpp/kv-cache-utils.js +6 -4
  111. package/dist/server/bare/addons/load-model.js +10 -4
  112. package/dist/server/bare/addons/unload-model.js +6 -3
  113. package/dist/server/bare/addons/whispercpp/handlers/transcribe-stream.js +56 -37
  114. package/dist/server/bare/delegate-rpc-client.js +12 -10
  115. package/dist/server/bare/hyperswarm.js +7 -5
  116. package/dist/server/bare/rag-hyperdb/rag-manager.js +3 -1
  117. package/dist/server/bare/registry/config-registry.d.ts +13 -4
  118. package/dist/server/bare/registry/config-registry.js +42 -10
  119. package/dist/server/bare/registry/logging-stream-registry.d.ts +24 -7
  120. package/dist/server/bare/registry/logging-stream-registry.js +99 -20
  121. package/dist/server/bare/registry/model-registry.d.ts +3 -0
  122. package/dist/server/bare/registry/model-registry.js +9 -6
  123. package/dist/server/rpc/create-server.js +5 -3
  124. package/dist/server/rpc/handle-request.js +30 -16
  125. package/dist/server/rpc/handlers/cancelHandler.js +3 -1
  126. package/dist/server/rpc/handlers/completion-stream-delegated.js +4 -2
  127. package/dist/server/rpc/handlers/delete-cache.js +3 -1
  128. package/dist/server/rpc/handlers/download-asset.js +3 -1
  129. package/dist/server/rpc/handlers/embed.js +3 -1
  130. package/dist/server/rpc/handlers/index.d.ts +0 -1
  131. package/dist/server/rpc/handlers/index.js +0 -2
  132. package/dist/server/rpc/handlers/load-model/download-manager.js +4 -2
  133. package/dist/server/rpc/handlers/load-model/http.js +20 -18
  134. package/dist/server/rpc/handlers/load-model/hyperdrive.js +21 -19
  135. package/dist/server/rpc/handlers/load-model/resolve.js +7 -5
  136. package/dist/server/rpc/handlers/load-model-delegated.d.ts +2 -2
  137. package/dist/server/rpc/handlers/load-model-delegated.js +10 -8
  138. package/dist/server/rpc/handlers/load-model.js +55 -3
  139. package/dist/server/rpc/handlers/logging-stream.js +4 -4
  140. package/dist/server/rpc/handlers/provideHandler/connection.js +12 -10
  141. package/dist/server/rpc/handlers/provideHandler/handler.js +18 -16
  142. package/dist/server/rpc/handlers/provideHandler/proxy.js +8 -6
  143. package/dist/server/rpc/handlers/rag.js +3 -1
  144. package/dist/server/rpc/handlers/stopProvideHandler.js +3 -1
  145. package/dist/server/rpc/handlers/transcribe-stream.js +3 -1
  146. package/dist/server/rpc/handlers/translate.js +3 -1
  147. package/dist/server/rpc/handlers/unload-model.js +4 -2
  148. package/dist/server/utils/audio/decoder.d.ts +2 -1
  149. package/dist/server/utils/audio/decoder.js +48 -11
  150. package/dist/server/utils/cache.js +7 -5
  151. package/dist/server/utils/config-transform.d.ts +3 -0
  152. package/dist/server/utils/config-transform.js +21 -0
  153. package/dist/server/utils/index.d.ts +1 -0
  154. package/dist/server/utils/index.js +1 -0
  155. package/dist/server/worker.js +41 -16
  156. package/dist/utils/errors-client.d.ts +12 -0
  157. package/dist/utils/errors-client.js +20 -0
  158. package/dist/utils/errors-server.d.ts +9 -0
  159. package/dist/utils/errors-server.js +16 -0
  160. package/dist/utils/getProcessSafe.d.ts +7 -0
  161. package/dist/utils/getProcessSafe.js +17 -0
  162. package/dist/utils/mcp-adapter.d.ts +12 -0
  163. package/dist/utils/mcp-adapter.js +103 -0
  164. package/dist/utils/object.d.ts +2 -0
  165. package/dist/utils/object.js +3 -0
  166. package/dist/utils/runtime.d.ts +30 -0
  167. package/dist/utils/runtime.js +48 -0
  168. package/dist/utils/tool-helpers.d.ts +10 -2
  169. package/dist/utils/tool-helpers.js +24 -11
  170. package/package.json +46 -33
  171. package/dist/client/api/set-config.d.ts +0 -7
  172. package/dist/client/api/set-config.js +0 -20
  173. package/dist/client/config-manager.d.ts +0 -4
  174. package/dist/client/config-manager.js +0 -8
  175. package/dist/examples/llamacpp-file-logging.d.ts +0 -2
  176. package/dist/schemas/set-config.d.ts +0 -21
  177. package/dist/schemas/set-config.js +0 -14
  178. package/dist/server/rpc/handlers/set-config.d.ts +0 -3
  179. package/dist/server/rpc/handlers/set-config.js +0 -18
@@ -1,7 +1,8 @@
1
- import { type CompletionStats, type CompletionClientParams, type ToolCall, type ToolCallEvent, type Tool } from "../../schemas/index";
1
+ import { type CompletionClientParams, type CompletionStats, type McpClientInput, type Tool, type ToolCallEvent, type ToolCallWithCall } from "../../schemas/index";
2
2
  import { type ToolInput } from "../../utils/tool-helpers";
3
3
  type CompletionParams = Omit<CompletionClientParams, "tools"> & {
4
4
  tools?: Tool[] | ToolInput[];
5
+ mcp?: McpClientInput[];
5
6
  };
6
7
  /**
7
8
  * Generates completion from a language model based on conversation history.
@@ -11,6 +12,7 @@ type CompletionParams = Omit<CompletionClientParams, "tools"> & {
11
12
  * @param params.history - Array of conversation messages with role, content, and optional attachments
12
13
  * @param params.stream - Whether to stream tokens (true) or return complete response (false). Defaults to true
13
14
  * @param params.tools - Optional array of tools (can be simple ToolInput with Zod schemas or full Tool objects)
15
+ * @param params.mcp - Optional array of MCP client inputs for tool integration
14
16
  * @param params.kvCache - Optional KV cache configuration. Cache files are organized hierarchically:
15
17
  * - Structure: `{kvCacheKey}/{modelId}/{configHash}.bin`
16
18
  * - The configHash includes model config + system prompt to ensure cache isolation
@@ -19,12 +21,11 @@ type CompletionParams = Omit<CompletionClientParams, "tools"> & {
19
21
  * - `false` or `undefined`: No caching
20
22
  * - ⚡ Performance: When cache exists, only the last message is sent to the model (includes multimodal attachments)
21
23
  * - 🗑️ Cleanup: Use `deleteCache({ kvCacheKey })` to remove cached sessions
22
- * @returns Object with tokenStream generator, toolCallStream generator, text promise, toolCalls promise, and stats promise
24
+ * @returns Object with tokenStream generator, toolCallStream generator, text promise, toolCalls promise (with call() method), and stats promise
23
25
  * @example
24
26
  * ```typescript
25
27
  * import { z } from "zod";
26
28
  *
27
- * // Simple tool definition with Zod
28
29
  * const result = completion({
29
30
  * modelId: "llama-2",
30
31
  * history: [
@@ -36,14 +37,23 @@ type CompletionParams = Omit<CompletionClientParams, "tools"> & {
36
37
  * description: "Get current weather",
37
38
  * parameters: z.object({
38
39
  * city: z.string().describe("City name"),
39
- * country: z.string().describe("Country code").optional(),
40
40
  * }),
41
+ * handler: async (args) => {
42
+ * return { temperature: 22, condition: "sunny" };
43
+ * }
41
44
  * }]
42
45
  * });
43
46
  *
44
47
  * for await (const token of result.tokenStream) {
45
48
  * process.stdout.write(token);
46
49
  * }
50
+ *
51
+ * for (const toolCall of await result.toolCalls) {
52
+ * if (toolCall.invoke) {
53
+ * const toolResult = await toolCall.invoke();
54
+ * console.log(toolResult);
55
+ * }
56
+ * }
47
57
  * ```
48
58
  */
49
59
  export declare function completion(params: CompletionParams): {
@@ -51,7 +61,7 @@ export declare function completion(params: CompletionParams): {
51
61
  toolCallStream: AsyncGenerator<ToolCallEvent>;
52
62
  stats: Promise<CompletionStats | undefined>;
53
63
  text: Promise<string>;
54
- toolCalls: Promise<ToolCall[]>;
64
+ toolCalls: Promise<ToolCallWithCall[]>;
55
65
  };
56
66
  export {};
57
67
  //# sourceMappingURL=completion-stream.d.ts.map
@@ -1,6 +1,9 @@
1
- import { completionStreamResponseSchema, } from "../../schemas/index.js";
2
1
  import { stream as streamRpc } from "../rpc/rpc-client.js";
3
- import { validateTools } from "../../utils/tool-helpers.js";
2
+ import { getClientLogger } from "../../logging/index.js";
3
+ import { completionStreamResponseSchema, } from "../../schemas/index.js";
4
+ import { getMcpToolsWithHandlers } from "../../utils/mcp-adapter.js";
5
+ import { attachHandlersToToolCalls, validateTools, } from "../../utils/tool-helpers.js";
6
+ const logger = getClientLogger();
4
7
  /**
5
8
  * Generates completion from a language model based on conversation history.
6
9
  *
@@ -9,6 +12,7 @@ import { validateTools } from "../../utils/tool-helpers.js";
9
12
  * @param params.history - Array of conversation messages with role, content, and optional attachments
10
13
  * @param params.stream - Whether to stream tokens (true) or return complete response (false). Defaults to true
11
14
  * @param params.tools - Optional array of tools (can be simple ToolInput with Zod schemas or full Tool objects)
15
+ * @param params.mcp - Optional array of MCP client inputs for tool integration
12
16
  * @param params.kvCache - Optional KV cache configuration. Cache files are organized hierarchically:
13
17
  * - Structure: `{kvCacheKey}/{modelId}/{configHash}.bin`
14
18
  * - The configHash includes model config + system prompt to ensure cache isolation
@@ -17,12 +21,11 @@ import { validateTools } from "../../utils/tool-helpers.js";
17
21
  * - `false` or `undefined`: No caching
18
22
  * - ⚡ Performance: When cache exists, only the last message is sent to the model (includes multimodal attachments)
19
23
  * - 🗑️ Cleanup: Use `deleteCache({ kvCacheKey })` to remove cached sessions
20
- * @returns Object with tokenStream generator, toolCallStream generator, text promise, toolCalls promise, and stats promise
24
+ * @returns Object with tokenStream generator, toolCallStream generator, text promise, toolCalls promise (with call() method), and stats promise
21
25
  * @example
22
26
  * ```typescript
23
27
  * import { z } from "zod";
24
28
  *
25
- * // Simple tool definition with Zod
26
29
  * const result = completion({
27
30
  * modelId: "llama-2",
28
31
  * history: [
@@ -34,24 +37,26 @@ import { validateTools } from "../../utils/tool-helpers.js";
34
37
  * description: "Get current weather",
35
38
  * parameters: z.object({
36
39
  * city: z.string().describe("City name"),
37
- * country: z.string().describe("Country code").optional(),
38
40
  * }),
41
+ * handler: async (args) => {
42
+ * return { temperature: 22, condition: "sunny" };
43
+ * }
39
44
  * }]
40
45
  * });
41
46
  *
42
47
  * for await (const token of result.tokenStream) {
43
48
  * process.stdout.write(token);
44
49
  * }
50
+ *
51
+ * for (const toolCall of await result.toolCalls) {
52
+ * if (toolCall.invoke) {
53
+ * const toolResult = await toolCall.invoke();
54
+ * console.log(toolResult);
55
+ * }
56
+ * }
45
57
  * ```
46
58
  */
47
59
  export function completion(params) {
48
- const tools = params.tools ? validateTools(params.tools) : undefined;
49
- const request = {
50
- type: "completionStream",
51
- ...params,
52
- tools,
53
- stream: params.stream ?? true,
54
- };
55
60
  let stats;
56
61
  let statsResolver = () => { };
57
62
  let statsRejecter = () => { };
@@ -68,7 +73,6 @@ export function completion(params) {
68
73
  toolCallsRejecter = reject;
69
74
  });
70
75
  toolCallsPromise.catch(() => { });
71
- const responses = streamRpc(request);
72
76
  const tokenQueue = [];
73
77
  const toolEventQueue = [];
74
78
  let tokenDone = false;
@@ -79,6 +83,37 @@ export function completion(params) {
79
83
  let streamError = null;
80
84
  const processResponses = async () => {
81
85
  try {
86
+ let allTools = [];
87
+ const allHandlers = new Map();
88
+ if (params.tools) {
89
+ const { tools, handlers } = validateTools(params.tools);
90
+ allTools = tools;
91
+ for (const [name, handler] of handlers) {
92
+ if (allHandlers.has(name)) {
93
+ logger.warn(`Duplicate tool handler for "${name}", overwriting`);
94
+ }
95
+ allHandlers.set(name, handler);
96
+ }
97
+ }
98
+ if (params.mcp && params.mcp.length > 0) {
99
+ const { tools: mcpTools, handlers: mcpHandlers } = await getMcpToolsWithHandlers(params.mcp);
100
+ allTools = [...mcpTools, ...allTools];
101
+ for (const [name, handler] of mcpHandlers) {
102
+ if (allHandlers.has(name)) {
103
+ logger.warn(`Duplicate tool handler for "${name}", overwriting`);
104
+ }
105
+ allHandlers.set(name, handler);
106
+ }
107
+ }
108
+ const request = {
109
+ type: "completionStream",
110
+ modelId: params.modelId,
111
+ history: params.history,
112
+ kvCache: params.kvCache,
113
+ tools: allTools.length > 0 ? allTools : undefined,
114
+ stream: params.stream ?? true,
115
+ };
116
+ const responses = streamRpc(request);
82
117
  for await (const response of responses) {
83
118
  if (response &&
84
119
  typeof response === "object" &&
@@ -109,7 +144,8 @@ export function completion(params) {
109
144
  }
110
145
  stats = streamResponse.stats;
111
146
  statsResolver(stats);
112
- toolCallsArray = streamResponse.toolCalls || [];
147
+ const rawToolCalls = streamResponse.toolCalls || [];
148
+ toolCallsArray = attachHandlersToToolCalls(rawToolCalls, allHandlers);
113
149
  toolCallsResolver(toolCallsArray);
114
150
  tokenDone = true;
115
151
  toolDone = true;
@@ -1,11 +1,25 @@
1
- import { type EmbedParams } from "../../schemas/index";
2
1
  /**
3
- * Generates embeddings for a given text using a specified model.
2
+ * Generates embeddings for a single text using a specified model.
4
3
  *
5
4
  * @param params - The parameters for the embedding
6
5
  * @param params.modelId - The identifier of the embedding model to use
7
6
  * @param params.text - The input text to embed
8
7
  * @throws {QvacErrorBase} When the response type is invalid or when the embedding fails
9
8
  */
10
- export declare function embed(params: EmbedParams): Promise<number[]>;
9
+ export declare function embed(params: {
10
+ modelId: string;
11
+ text: string;
12
+ }): Promise<number[]>;
13
+ /**
14
+ * Generates embeddings for multiple texts using a specified model.
15
+ *
16
+ * @param params - The parameters for the embedding
17
+ * @param params.modelId - The identifier of the embedding model to use
18
+ * @param params.text - The input texts to embed
19
+ * @throws {QvacErrorBase} When the response type is invalid or when the embedding fails
20
+ */
21
+ export declare function embed(params: {
22
+ modelId: string;
23
+ text: string[];
24
+ }): Promise<number[][]>;
11
25
  //# sourceMappingURL=embed.d.ts.map
@@ -1,14 +1,6 @@
1
1
  import { send } from "../rpc/rpc-client.js";
2
2
  import {} from "../../schemas/index.js";
3
3
  import { InvalidResponseError, EmbedFailedError } from "../../utils/errors-client.js";
4
- /**
5
- * Generates embeddings for a given text using a specified model.
6
- *
7
- * @param params - The parameters for the embedding
8
- * @param params.modelId - The identifier of the embedding model to use
9
- * @param params.text - The input text to embed
10
- * @throws {QvacErrorBase} When the response type is invalid or when the embedding fails
11
- */
12
4
  export async function embed(params) {
13
5
  const request = {
14
6
  type: "embed",
@@ -6,7 +6,7 @@ export declare const getModelInfo: (params: GetModelInfoParams) => Promise<{
6
6
  hyperbeeKey: string;
7
7
  expectedSize: number;
8
8
  sha256Checksum: string;
9
- addon: "llm" | "whisper" | "embeddings" | "nmt" | "vad" | "tts";
9
+ addon: "llm" | "whisper" | "embeddings" | "nmt" | "tts" | "vad";
10
10
  isCached: boolean;
11
11
  isLoaded: boolean;
12
12
  cacheFiles: {
@@ -13,6 +13,5 @@ export { startQVACProvider } from "./provide";
13
13
  export { stopQVACProvider } from "./stop-provider";
14
14
  export { ragSaveEmbeddings, ragSearch, ragDeleteEmbeddings } from "./rag";
15
15
  export { textToSpeech } from "./text-to-speech";
16
- export { setConfig } from "./set-config";
17
16
  export { getModelInfo } from "./get-model-info";
18
17
  //# sourceMappingURL=index.d.ts.map
@@ -13,5 +13,4 @@ export { startQVACProvider } from "./provide.js";
13
13
  export { stopQVACProvider } from "./stop-provider.js";
14
14
  export { ragSaveEmbeddings, ragSearch, ragDeleteEmbeddings } from "./rag.js";
15
15
  export { textToSpeech } from "./text-to-speech.js";
16
- export { setConfig } from "./set-config.js";
17
16
  export { getModelInfo } from "./get-model-info.js";
@@ -1,23 +1,21 @@
1
- import { type Logger } from "../../logging/index";
2
- import { type LoadModelOptions as BaseLoadModelOptions } from "../../schemas/index";
3
- export type LoadModelOptions = BaseLoadModelOptions & {
4
- logger?: Logger;
5
- };
1
+ import { type LoadModelOptions, type ReloadConfigOptions } from "../../schemas/index";
6
2
  /**
7
3
  * Loads a machine learning model from a local path, remote URL, or Hyperdrive key.
8
4
  *
9
- * This function supports three model types: LLM (Large Language Model), Whisper (speech recognition),
10
- * and embeddings. It can handle both local file paths and Hyperdrive URLs (pear://).
5
+ * This function supports multiple model types: LLM (Large Language Model), Whisper (speech recognition),
6
+ * embeddings, NMT (translation), and TTS. It can handle both local file paths and Hyperdrive URLs (pear://).
11
7
  *
12
8
  * When `onProgress` is provided, the function uses streaming to provide real-time download progress.
13
9
  * Otherwise, it uses a simple request-response pattern for faster execution.
14
10
  *
15
11
  * @param options - An object that defines all configuration parameters required for loading the model, including:
16
12
  * - modelSrc: The location from which the model weights are fetched (local path, remote URL, or Hyperdrive URL)
17
- * - modelType: The type of model ("llm", "whisper", "embeddings", or "nmt")
13
+ * - modelType: The type of model ("llm", "whisper", "embeddings", "nmt", or "tts")
18
14
  * - modelConfig: Model-specific configuration options
19
15
  * - projectionModelSrc: (LLM only) Projection model source for multimodal models
20
16
  * - vadModelSrc: (Whisper only) VAD model source for voice activity detection
17
+ * - onProgress: Callback for download progress updates
18
+ * - logger: Logger instance for model operation logs
21
19
  *
22
20
  * @returns Promise that resolves to the model ID (either the provided modelSrc or a generated ID)
23
21
  *
@@ -89,10 +87,38 @@ export type LoadModelOptions = BaseLoadModelOptions & {
89
87
  * modelType: "llm",
90
88
  * logger // Pass logger in options
91
89
  * });
92
- *
93
- * // Now any logs from the model operations will appear in your logger automatically
94
- * // No need to manually manage logging streams!
95
90
  * ```
96
91
  */
97
92
  export declare function loadModel(options: LoadModelOptions): Promise<string>;
93
+ /**
94
+ * Hot-reloads configuration on an already loaded model.
95
+ *
96
+ * @param options - Configuration for reloading config on an existing model:
97
+ * - modelId: The ID of an existing loaded model
98
+ * - modelType: The type of model (must match the loaded model)
99
+ * - modelConfig: New configuration to apply
100
+ *
101
+ * @returns Promise that resolves to the model ID
102
+ *
103
+ * @throws {QvacErrorBase} When model reload fails, with details in the error message
104
+ * @throws {QvacErrorBase} When receiving an invalid response type from the server
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * // Load new model
109
+ * const modelId = await loadModel({
110
+ * modelSrc: "pear://<hyperdrive-key>/whisper-tiny.gguf",
111
+ * modelType: "whisper",
112
+ * modelConfig: { language: "en" },
113
+ * });
114
+ *
115
+ * // Later, update the config without reloading the model
116
+ * await loadModel({
117
+ * modelId,
118
+ * modelType: "whisper",
119
+ * modelConfig: { language: "es" },
120
+ * });
121
+ * ```
122
+ */
123
+ export declare function loadModel(options: ReloadConfigOptions): Promise<string>;
98
124
  //# sourceMappingURL=load-model.d.ts.map
@@ -1,107 +1,21 @@
1
1
  import { send, stream } from "../rpc/rpc-client.js";
2
- import {} from "../../logging/index.js";
3
2
  import { startLoggingStreamForModel } from "../logging-stream-registry.js";
4
- import { loadModelOptionsToRequestSchema, } from "../../schemas/index.js";
3
+ import { loadModelOptionsToRequestSchema, reloadConfigOptionsToRequestSchema, } from "../../schemas/index.js";
5
4
  import { ModelLoadFailedError, StreamEndedError, InvalidResponseError, } from "../../utils/errors-client.js";
6
- /**
7
- * Loads a machine learning model from a local path, remote URL, or Hyperdrive key.
8
- *
9
- * This function supports three model types: LLM (Large Language Model), Whisper (speech recognition),
10
- * and embeddings. It can handle both local file paths and Hyperdrive URLs (pear://).
11
- *
12
- * When `onProgress` is provided, the function uses streaming to provide real-time download progress.
13
- * Otherwise, it uses a simple request-response pattern for faster execution.
14
- *
15
- * @param options - An object that defines all configuration parameters required for loading the model, including:
16
- * - modelSrc: The location from which the model weights are fetched (local path, remote URL, or Hyperdrive URL)
17
- * - modelType: The type of model ("llm", "whisper", "embeddings", or "nmt")
18
- * - modelConfig: Model-specific configuration options
19
- * - projectionModelSrc: (LLM only) Projection model source for multimodal models
20
- * - vadModelSrc: (Whisper only) VAD model source for voice activity detection
21
- *
22
- * @returns Promise that resolves to the model ID (either the provided modelSrc or a generated ID)
23
- *
24
- * @throws {QvacErrorBase} When model loading fails, with details in the error message
25
- * @throws {QvacErrorBase} When streaming ends unexpectedly (only when using onProgress)
26
- * @throws {QvacErrorBase} When receiving an invalid response type from the server
27
- *
28
- * @example
29
- * ```typescript
30
- * // Local file path - absolute path
31
- * const localModelId = await loadModel({
32
- * modelSrc: "/home/user/models/llama-7b.gguf",
33
- * modelType: "llm",
34
- * modelConfig: { contextSize: 2048 }
35
- * });
36
- *
37
- * // Local file path - relative path
38
- * const relativeModelId = await loadModel({
39
- * modelSrc: "./models/whisper-base.gguf",
40
- * modelType: "whisper"
41
- * });
42
- *
43
- * // Hyperdrive URL with key and path
44
- * const hyperdriveId = await loadModel({
45
- * modelSrc: "pear://<hyperdrive-key>/llama-7b.gguf",
46
- * modelType: "llm",
47
- * modelConfig: { contextSize: 2048 }
48
- * });
49
- *
50
- * // Remote HTTP/HTTPS URL with progress tracking
51
- * const remoteId = await loadModel({
52
- * modelSrc: "https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q4_K_M.gguf",
53
- * modelType: "llm",
54
- * onProgress: (progress) => {
55
- * console.log(`Downloaded: ${progress.percentage}%`);
56
- * }
57
- * });
58
- *
59
- * // Multimodal model with projection
60
- * const multimodalId = await loadModel({
61
- * modelSrc: "https://huggingface.co/.../main-model.gguf",
62
- * modelType: "llm",
63
- * projectionModelSrc: "https://huggingface.co/.../projection-model.gguf",
64
- * modelConfig: { ctx_size: 512 },
65
- * onProgress: (progress) => {
66
- * console.log(`Loading: ${progress.percentage}%`);
67
- * }
68
- * });
69
- *
70
- * // Whisper with VAD model
71
- * const whisperId = await loadModel({
72
- * modelSrc: "https://huggingface.co/.../whisper-model.gguf",
73
- * modelType: "whisper",
74
- * vadModelSrc: "https://huggingface.co/.../vad-model.bin",
75
- * modelConfig: {
76
- * mode: "caption",
77
- * output_format: "plaintext",
78
- * min_seconds: 2,
79
- * max_seconds: 6
80
- * }
81
- * });
82
- *
83
- * // Load with automatic logging - logs from the model will be forwarded to your logger
84
- * import { getLogger } from "../../logging/index.js";
85
- * const logger = getLogger("my-app");
86
- *
87
- * const modelId = await loadModel({
88
- * modelSrc: "/path/to/model.gguf",
89
- * modelType: "llm",
90
- * logger // Pass logger in options
91
- * });
92
- *
93
- * // Now any logs from the model operations will appear in your logger automatically
94
- * // No need to manually manage logging streams!
95
- * ```
96
- */
5
+ import { getClientLogger } from "../../logging/index.js";
6
+ const logger = getClientLogger();
97
7
  export async function loadModel(options) {
98
- const { logger } = options;
99
- const request = loadModelOptionsToRequestSchema.parse(options);
100
- if (options.onProgress) {
8
+ const isReloadConfig = "modelId" in options && !("modelSrc" in options);
9
+ const request = isReloadConfig
10
+ ? reloadConfigOptionsToRequestSchema.parse(options)
11
+ : loadModelOptionsToRequestSchema.parse(options);
12
+ const modelLogger = isReloadConfig ? undefined : options.logger;
13
+ const onProgress = isReloadConfig ? undefined : options.onProgress;
14
+ if (onProgress) {
101
15
  // Use streaming for progress updates
102
16
  for await (const response of stream(request)) {
103
17
  if (response.type === "modelProgress") {
104
- options.onProgress(response);
18
+ onProgress(response);
105
19
  }
106
20
  else if (response.type === "loadModel") {
107
21
  if (!response.success) {
@@ -109,12 +23,12 @@ export async function loadModel(options) {
109
23
  }
110
24
  const modelId = response.modelId;
111
25
  // Start logging stream in the background if logger is provided, catch to avoid failing the entire loadModel operation
112
- if (logger) {
26
+ if (modelLogger) {
113
27
  try {
114
- startLoggingStreamForModel(modelId, logger);
28
+ startLoggingStreamForModel(modelId, modelLogger);
115
29
  }
116
30
  catch (error) {
117
- console.warn(`Failed to start logging stream for model ${modelId}:`, error);
31
+ logger.warn(`Failed to start logging stream for model ${modelId}:`, error);
118
32
  }
119
33
  }
120
34
  return modelId;
@@ -122,24 +36,22 @@ export async function loadModel(options) {
122
36
  }
123
37
  throw new StreamEndedError();
124
38
  }
125
- else {
126
- // Use regular send for simple loading
127
- const response = await send(request);
128
- if (response.type !== "loadModel") {
129
- throw new InvalidResponseError("loadModel");
130
- }
131
- if (!response.success) {
132
- throw new ModelLoadFailedError(response.error);
39
+ // Use regular send for simple loading
40
+ const response = await send(request);
41
+ if (response.type !== "loadModel") {
42
+ throw new InvalidResponseError("loadModel");
43
+ }
44
+ if (!response.success) {
45
+ throw new ModelLoadFailedError(response.error);
46
+ }
47
+ const modelId = response.modelId;
48
+ if (modelLogger) {
49
+ try {
50
+ startLoggingStreamForModel(modelId, modelLogger);
133
51
  }
134
- const modelId = response.modelId;
135
- if (logger) {
136
- try {
137
- startLoggingStreamForModel(modelId, logger);
138
- }
139
- catch (error) {
140
- console.warn(`Failed to start logging stream for model ${modelId}:`, error);
141
- }
52
+ catch (error) {
53
+ logger.warn(`Failed to start logging stream for model ${modelId}:`, error);
142
54
  }
143
- return modelId;
144
55
  }
56
+ return modelId;
145
57
  }
@@ -1,16 +1,19 @@
1
1
  import type { LoggingStreamResponse, LoggingParams } from "../../schemas/logging-stream";
2
2
  /**
3
- * Opens a logging stream for a specific model to receive real-time logs.
3
+ * Opens a logging stream to receive real-time logs.
4
4
  *
5
5
  * @param params - The arguments for the logging stream
6
- * @param params.modelId - The unique identifier of the model to stream logs for
6
+ * @param params.id - The unique identifier to stream logs for
7
7
  * @returns AsyncGenerator yielding logging stream responses
8
8
  * @throws {QvacErrorBase} When the response type is invalid or when the stream fails
9
9
  *
10
10
  * @example
11
11
  * ```typescript
12
12
  * // Open a logging stream for a model
13
- * const logStream = loggingStream({ modelId: 'my-model-id' });
13
+ * const logStream = loggingStream({ id: 'my-model-id' });
14
+ *
15
+ * // Or stream SDK server logs
16
+ * const sdkLogs = loggingStream({ id: SDK_LOG_ID });
14
17
  *
15
18
  * for await (const logMessage of logStream) {
16
19
  * console.log(`[${logMessage.level}] ${logMessage.namespace}: ${logMessage.message}`);
@@ -1,17 +1,20 @@
1
1
  import { stream } from "../rpc/rpc-client.js";
2
2
  import { InvalidResponseError } from "../../utils/errors-client.js";
3
3
  /**
4
- * Opens a logging stream for a specific model to receive real-time logs.
4
+ * Opens a logging stream to receive real-time logs.
5
5
  *
6
6
  * @param params - The arguments for the logging stream
7
- * @param params.modelId - The unique identifier of the model to stream logs for
7
+ * @param params.id - The unique identifier to stream logs for
8
8
  * @returns AsyncGenerator yielding logging stream responses
9
9
  * @throws {QvacErrorBase} When the response type is invalid or when the stream fails
10
10
  *
11
11
  * @example
12
12
  * ```typescript
13
13
  * // Open a logging stream for a model
14
- * const logStream = loggingStream({ modelId: 'my-model-id' });
14
+ * const logStream = loggingStream({ id: 'my-model-id' });
15
+ *
16
+ * // Or stream SDK server logs
17
+ * const sdkLogs = loggingStream({ id: SDK_LOG_ID });
15
18
  *
16
19
  * for await (const logMessage of logStream) {
17
20
  * console.log(`[${logMessage.level}] ${logMessage.namespace}: ${logMessage.message}`);
@@ -2,6 +2,8 @@ import {} from "../../schemas/index.js";
2
2
  import { send, close } from "../rpc/rpc-client.js";
3
3
  import { stopLoggingStreamForModel } from "../logging-stream-registry.js";
4
4
  import { InvalidResponseError, ModelUnloadFailedError, } from "../../utils/errors-client.js";
5
+ import { getClientLogger } from "../../logging/index.js";
6
+ const logger = getClientLogger();
5
7
  /**
6
8
  * Unloads a previously loaded model from the server.
7
9
  *
@@ -29,8 +31,9 @@ export async function unloadModel(params) {
29
31
  }
30
32
  stopLoggingStreamForModel(params.modelId);
31
33
  // Auto-close when no models remain AND no providers are active
32
- if (!response.hasActiveModels && !response.hasActiveProviders) {
33
- console.log("🧹 No models or providers active, automatically closing RPC connection...");
34
+ if (response.hasActiveModels === false &&
35
+ response.hasActiveProviders === false) {
36
+ logger.info("🧹 No models or providers active, automatically closing RPC connection...");
34
37
  await close();
35
38
  }
36
39
  }
@@ -0,0 +1,5 @@
1
+ import { type QvacConfig } from "../../schemas/index";
2
+ export type { QvacConfig };
3
+ export declare function validateConfig(config: unknown): QvacConfig;
4
+ export declare function parseJsonConfig(content: string, filePath: string): unknown;
5
+ //# sourceMappingURL=config-utils.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { qvacConfigSchema } from "../../schemas/index.js";
2
+ import { ConfigValidationFailedError } from "../../utils/errors-client.js";
3
+ export function validateConfig(config) {
4
+ const result = qvacConfigSchema.safeParse(config);
5
+ if (!result.success) {
6
+ const errors = result.error.issues
7
+ .map((e) => `${String(e.path.join("."))}: ${e.message}`)
8
+ .join(", ");
9
+ throw new ConfigValidationFailedError(errors);
10
+ }
11
+ return result.data;
12
+ }
13
+ export function parseJsonConfig(content, filePath) {
14
+ try {
15
+ return JSON.parse(content);
16
+ }
17
+ catch {
18
+ throw new ConfigValidationFailedError(`Invalid JSON in config file: ${filePath}`);
19
+ }
20
+ }
@@ -0,0 +1,9 @@
1
+ import { type QvacConfig } from "./config-utils";
2
+ /**
3
+ * Resolution order for Bare:
4
+ * 1. QVAC_CONFIG_PATH environment variable
5
+ * 2. Config file in project root (qvac.config.ts, qvac.config.js, qvac.config.json)
6
+ * 3. SDK defaults
7
+ */
8
+ export declare function resolveConfig(): Promise<QvacConfig | undefined>;
9
+ //# sourceMappingURL=resolve-config.bare.d.ts.map